Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
tsoc
openmm
Commits
b3176be4
Commit
b3176be4
authored
Jun 24, 2020
by
Charlles Abreu
Browse files
Elimination of setPeriodic method in tabulated functions
parent
ab67382e
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
39 additions
and
24 deletions
+39
-24
openmmapi/include/openmm/TabulatedFunction.h
openmmapi/include/openmm/TabulatedFunction.h
+0
-6
openmmapi/src/TabulatedFunction.cpp
openmmapi/src/TabulatedFunction.cpp
+0
-4
serialization/tests/TestSerializeTabulatedFunctions.cpp
serialization/tests/TestSerializeTabulatedFunctions.cpp
+22
-9
tests/TestCustomNonbondedForce.h
tests/TestCustomNonbondedForce.h
+17
-5
No files found.
openmmapi/include/openmm/TabulatedFunction.h
View file @
b3176be4
...
...
@@ -68,12 +68,6 @@ public:
*
*/
bool
getPeriodic
()
const
;
/**
* Set the periodicity status for the tabulated function.
*
* @param periodic whether the function is periodic with period L = max - min
*/
void
setPeriodic
(
bool
periodic
);
protected:
bool
periodic
;
};
...
...
openmmapi/src/TabulatedFunction.cpp
View file @
b3176be4
...
...
@@ -39,10 +39,6 @@ bool TabulatedFunction::getPeriodic() const {
return
periodic
;
}
void
TabulatedFunction
::
setPeriodic
(
bool
periodic
)
{
this
->
periodic
=
periodic
;
}
Continuous1DFunction
::
Continuous1DFunction
(
const
vector
<
double
>&
values
,
double
min
,
double
max
,
bool
periodic
)
{
this
->
periodic
=
periodic
;
setFunctionParameters
(
values
,
min
,
max
);
...
...
serialization/tests/TestSerializeTabulatedFunctions.cpp
View file @
b3176be4
...
...
@@ -63,22 +63,35 @@ void testContinuous1DFunction() {
ASSERT_EQUAL
(
values
.
size
(),
values2
.
size
());
for
(
int
j
=
0
;
j
<
(
int
)
values
.
size
();
j
++
)
ASSERT_EQUAL
(
values
[
j
],
values2
[
j
]);
}
void
testPeriodicContinuous1DFunction
()
{
// Create a function.
double
min
=
0.5
,
max
=
1.5
;
vector
<
double
>
values
(
60
);
for
(
int
i
=
0
;
i
<
(
int
)
values
.
size
()
-
1
;
i
++
)
values
[
i
]
=
sin
((
double
)
i
);
values
[
values
.
size
()
-
1
]
=
values
[
0
];
Continuous1DFunction
function
(
values
,
min
,
max
,
true
);
// Serialize and then deserialize it.
// Same test with periodic function:
stringstream
buffer
;
XmlSerializer
::
serialize
<
Continuous1DFunction
>
(
&
function
,
"Function"
,
buffer
);
Continuous1DFunction
*
copy
=
XmlSerializer
::
deserialize
<
Continuous1DFunction
>
(
buffer
);
// Compare the two forces to see if they are identical.
values
.
push_back
(
values
[
0
]);
function
.
setPeriodic
(
true
);
function
.
setFunctionParameters
(
values
,
min
,
max
);
stringstream
newBuffer
;
XmlSerializer
::
serialize
<
Continuous1DFunction
>
(
&
function
,
"Function"
,
newBuffer
);
Continuous1DFunction
*
newCopy
=
XmlSerializer
::
deserialize
<
Continuous1DFunction
>
(
newBuffer
);
newCopy
->
getFunctionParameters
(
values2
,
min2
,
max2
);
double
min2
,
max2
;
vector
<
double
>
values2
;
copy
->
getFunctionParameters
(
values2
,
min2
,
max2
);
ASSERT_EQUAL
(
min
,
min2
);
ASSERT_EQUAL
(
max
,
max2
);
ASSERT_EQUAL
(
values
.
size
(),
values2
.
size
());
for
(
int
j
=
0
;
j
<
(
int
)
values
.
size
();
j
++
)
ASSERT_EQUAL
(
values
[
j
],
values2
[
j
]);
}
void
testContinuous2DFunction
()
{
...
...
tests/TestCustomNonbondedForce.h
View file @
b3176be4
...
...
@@ -355,14 +355,26 @@ void testContinuous1DFunction() {
double
energy
=
(
x
<
1.0
||
x
>
6.0
?
0.0
:
sin
(
x
-
1.0
))
+
1.0
;
ASSERT_EQUAL_TOL
(
energy
,
state
.
getPotentialEnergy
(),
1e-4
);
}
}
void
testPeriodicContinuous1DFunction
()
{
System
system
;
system
.
addParticle
(
1.0
);
system
.
addParticle
(
1.0
);
VerletIntegrator
integrator
(
0.01
);
CustomNonbondedForce
*
forceField
=
new
CustomNonbondedForce
(
"fn(r)+1"
);
forceField
->
addParticle
(
vector
<
double
>
());
forceField
->
addParticle
(
vector
<
double
>
());
vector
<
double
>
table
;
double
twoPi
=
8.0
*
atan
(
1.0
);
for
(
int
i
=
0
;
i
<
20
;
i
++
)
table
[
i
]
=
sin
(
i
*
twoPi
/
20.0
);
table
[
20
]
=
table
[
0
];
continuous1DFunction
->
setFunctionParameters
(
table
,
1.0
,
twoPi
+
1.0
);
continuous1DFunction
->
setPeriodic
(
true
);
context
.
reinitialize
();
table
.
push_back
(
sin
(
i
*
twoPi
/
20.0
));
table
.
push_back
(
table
[
0
]);
Continuous1DFunction
*
continuous1DFunction
=
new
Continuous1DFunction
(
table
,
1.0
,
twoPi
+
1.0
);
forceField
->
addTabulatedFunction
(
"fn"
,
continuous1DFunction
);
system
.
addForce
(
forceField
);
Context
context
(
system
,
integrator
,
platform
);
vector
<
Vec3
>
positions
(
2
);
positions
[
0
]
=
Vec3
(
0
,
0
,
0
);
for
(
int
i
=
1
;
i
<
30
;
i
++
)
{
double
x
=
(
7.0
/
30.0
)
*
i
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment