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
d51ef9e6
Unverified
Commit
d51ef9e6
authored
Apr 27, 2020
by
peastman
Committed by
GitHub
Apr 27, 2020
Browse files
Merge pull request #2654 from peastman/compound
CompoundIntegrator handles checkpoints correctly
parents
5109ce60
8cd52036
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
57 additions
and
3 deletions
+57
-3
openmmapi/include/openmm/CompoundIntegrator.h
openmmapi/include/openmm/CompoundIntegrator.h
+11
-1
openmmapi/src/CompoundIntegrator.cpp
openmmapi/src/CompoundIntegrator.cpp
+13
-1
tests/TestCompoundIntegrator.h
tests/TestCompoundIntegrator.h
+33
-1
No files found.
openmmapi/include/openmm/CompoundIntegrator.h
View file @
d51ef9e6
...
...
@@ -9,7 +9,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2015-20
16
Stanford University and the Authors. *
* Portions copyright (c) 2015-20
20
Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
...
...
@@ -194,6 +194,16 @@ protected:
double
getVelocityTimeOffset
()
const
{
return
getIntegrator
(
0
).
getVelocityTimeOffset
();
}
/**
* This is called while writing checkpoints. It gives the integrator a chance to write
* its own data.
*/
void
createCheckpoint
(
std
::
ostream
&
stream
)
const
;
/**
* This is called while loading a checkpoint. The integrator should read in whatever
* data it wrote in createCheckpoint() and update its internal state accordingly.
*/
void
loadCheckpoint
(
std
::
istream
&
stream
);
private:
int
currentIntegrator
;
std
::
vector
<
Integrator
*>
integrators
;
...
...
openmmapi/src/CompoundIntegrator.cpp
View file @
d51ef9e6
...
...
@@ -6,7 +6,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2015-20
16
Stanford University and the Authors. *
* Portions copyright (c) 2015-20
20
Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
...
...
@@ -128,3 +128,15 @@ void CompoundIntegrator::stateChanged(State::DataType changed) {
double
CompoundIntegrator
::
computeKineticEnergy
()
{
return
integrators
[
currentIntegrator
]
->
computeKineticEnergy
();
}
void
CompoundIntegrator
::
createCheckpoint
(
std
::
ostream
&
stream
)
const
{
stream
.
write
((
char
*
)
&
currentIntegrator
,
sizeof
(
int
));
for
(
int
i
=
0
;
i
<
integrators
.
size
();
i
++
)
integrators
[
i
]
->
createCheckpoint
(
stream
);
}
void
CompoundIntegrator
::
loadCheckpoint
(
std
::
istream
&
stream
)
{
stream
.
read
((
char
*
)
&
currentIntegrator
,
sizeof
(
int
));
for
(
int
i
=
0
;
i
<
integrators
.
size
();
i
++
)
integrators
[
i
]
->
loadCheckpoint
(
stream
);
}
tests/TestCompoundIntegrator.h
View file @
d51ef9e6
...
...
@@ -6,7 +6,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2015 Stanford University and the Authors.
*
* Portions copyright (c) 2015
-2020
Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
...
...
@@ -33,6 +33,7 @@
#include "openmm/BrownianIntegrator.h"
#include "openmm/CompoundIntegrator.h"
#include "openmm/Context.h"
#include "openmm/CustomIntegrator.h"
#include "openmm/HarmonicBondForce.h"
#include "openmm/LangevinIntegrator.h"
#include "openmm/System.h"
...
...
@@ -208,6 +209,36 @@ void testDifferentStepSizes() {
}
}
void
testCheckpoint
()
{
// Test that member integrators get loaded correctly from checkpoints.
System
system
;
system
.
addParticle
(
1.0
);
CustomIntegrator
*
custom
=
new
CustomIntegrator
(
0.001
);
custom
->
addGlobalVariable
(
"a"
,
1.0
);
custom
->
addPerDofVariable
(
"b"
,
2.0
);
CompoundIntegrator
integrator
;
integrator
.
addIntegrator
(
custom
);
integrator
.
addIntegrator
(
new
VerletIntegrator
(
0.005
));
Context
context
(
system
,
integrator
,
platform
);
vector
<
Vec3
>
positions
(
1
,
Vec3
());
context
.
setPositions
(
positions
);
custom
->
setGlobalVariable
(
0
,
5.0
);
vector
<
Vec3
>
b1
(
1
,
Vec3
(
1
,
2
,
3
));
custom
->
setPerDofVariable
(
0
,
b1
);
stringstream
checkpoint
;
context
.
createCheckpoint
(
checkpoint
);
custom
->
setGlobalVariable
(
0
,
10.0
);
vector
<
Vec3
>
b2
(
1
,
Vec3
(
4
,
5
,
6
));
custom
->
setPerDofVariable
(
0
,
b2
);
integrator
.
setCurrentIntegrator
(
1
);
context
.
loadCheckpoint
(
checkpoint
);
ASSERT_EQUAL
(
0
,
integrator
.
getCurrentIntegrator
());
ASSERT_EQUAL
(
5.0
,
custom
->
getGlobalVariable
(
0
));
vector
<
Vec3
>
b3
;
custom
->
getPerDofVariable
(
0
,
b3
);
ASSERT_EQUAL_VEC
(
b1
[
0
],
b3
[
0
],
1e-6
);
}
void
runPlatformTests
();
int
main
(
int
argc
,
char
*
argv
[])
{
...
...
@@ -216,6 +247,7 @@ int main(int argc, char* argv[]) {
testChangingIntegrator
();
testChangingParameters
();
testDifferentStepSizes
();
testCheckpoint
();
runPlatformTests
();
}
catch
(
const
exception
&
e
)
{
...
...
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