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
4c5f80ce
"vscode:/vscode.git/clone" did not exist on "ba8dccd648cf5f6fa2b330392dcaa11a494be7bb"
Commit
4c5f80ce
authored
Oct 01, 2014
by
peastman
Browse files
Merge pull request #634 from kyleabeauchamp/statepickle
Added fix for #632
parents
deebf493
9c7c79a1
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
68 additions
and
2 deletions
+68
-2
wrappers/python/src/swig_doxygen/swig_lib/python/extend.i
wrappers/python/src/swig_doxygen/swig_lib/python/extend.i
+12
-0
wrappers/python/src/swig_doxygen/swig_lib/python/pythoncode.i
...pers/python/src/swig_doxygen/swig_lib/python/pythoncode.i
+2
-2
wrappers/python/tests/TestPickle.py
wrappers/python/tests/TestPickle.py
+54
-0
No files found.
wrappers/python/src/swig_doxygen/swig_lib/python/extend.i
View file @
4c5f80ce
...
...
@@ -454,3 +454,15 @@ Parameters:
return
self
.
__copy__
()
}
}
%
extend
OpenMM
::
Integrator
{
%
pythoncode
{
def
__getstate__
(
self
)
:
serializationString
=
XmlSerializer
.
serialize
(
self
)
return
serializationString
def
__setstate__
(
self
,
serializationString
)
:
system
=
XmlSerializer
.
deserialize
(
serializationString
)
self
.
this
=
system
.
this
}
}
wrappers/python/src/swig_doxygen/swig_lib/python/pythoncode.i
View file @
4c5f80ce
...
...
@@ -75,12 +75,12 @@ class State(_object):
self
.
_paramMap
=
paramMap
def
__getstate__
(
self
)
:
serializationString
=
XmlSerializer
.
serialize
State
(
self
)
serializationString
=
XmlSerializer
.
serialize
(
self
)
return
serializationString
def
__setstate__
(
self
,
serializationString
)
:
print
'
calling
set
state
'
dState
=
XmlSerializer
.
deserialize
State
(
serializationString
)
dState
=
XmlSerializer
.
deserialize
(
serializationString
)
#
Safe
provided
no
__slots__
or
other
weird
things
are
used
self
.
__dict__
.
update
(
dState
.
__dict__
)
...
...
wrappers/python/tests/TestPickle.py
0 → 100644
View file @
4c5f80ce
import
unittest
from
validateConstraints
import
*
from
simtk.openmm.app
import
*
from
simtk.openmm
import
*
from
simtk.unit
import
*
import
simtk.openmm.app.element
as
elem
import
simtk.openmm.app.forcefield
as
forcefield
import
copy
import
pickle
class
TestPickle
(
unittest
.
TestCase
):
"""Pickling / deepcopy of OpenMM state and integrator objects."""
def
setUp
(
self
):
"""Set up the tests by loading the input pdb files and force field
xml files.
"""
# alanine dipeptide with explicit water
self
.
pdb1
=
PDBFile
(
'systems/alanine-dipeptide-explicit.pdb'
)
self
.
forcefield1
=
ForceField
(
'amber99sb.xml'
,
'tip3p.xml'
)
self
.
topology1
=
self
.
pdb1
.
topology
self
.
topology1
.
setUnitCellDimensions
(
Vec3
(
2
,
2
,
2
))
# alalnine dipeptide with implicit water
self
.
pdb2
=
PDBFile
(
'systems/alanine-dipeptide-implicit.pdb'
)
self
.
forcefield2
=
ForceField
(
'amber99sb.xml'
,
'amber99_obc.xml'
)
def
test_deepcopy
(
self
):
"""Test that serialization/deserialization works (via deepcopy)."""
system
=
self
.
forcefield1
.
createSystem
(
self
.
pdb1
.
topology
)
integrator
=
VerletIntegrator
(
2
*
femtosecond
)
context
=
Context
(
system
,
integrator
)
context
.
setPositions
(
self
.
pdb1
.
positions
)
state
=
context
.
getState
(
getPositions
=
True
,
getForces
=
True
,
getEnergy
=
True
)
system2
=
copy
.
deepcopy
(
system
)
integrator2
=
copy
.
deepcopy
(
integrator
)
state2
=
copy
.
deepcopy
(
state
)
str_state
=
pickle
.
dumps
(
state
)
str_integrator
=
pickle
.
dumps
(
integrator
)
state3
=
pickle
.
loads
(
str_state
)
context
.
setState
(
state3
)
del
context
,
integrator
if
__name__
==
'__main__'
:
unittest
.
main
()
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