Commit 9639837c authored by John Chodera (MSKCC)'s avatar John Chodera (MSKCC)
Browse files

Add Python test to catch force deepcopy bug

parent 8eaf3c9c
...@@ -9,7 +9,7 @@ import copy ...@@ -9,7 +9,7 @@ import copy
import pickle import pickle
class TestPickle(unittest.TestCase): class TestPickle(unittest.TestCase):
"""Pickling / deepcopy of OpenMM state and integrator objects.""" """Pickling / deepcopy of OpenMM objects."""
def setUp(self): def setUp(self):
"""Set up the tests by loading the input pdb files and force field """Set up the tests by loading the input pdb files and force field
...@@ -26,9 +26,8 @@ class TestPickle(unittest.TestCase): ...@@ -26,9 +26,8 @@ class TestPickle(unittest.TestCase):
self.pdb2 = PDBFile('systems/alanine-dipeptide-implicit.pdb') self.pdb2 = PDBFile('systems/alanine-dipeptide-implicit.pdb')
self.forcefield2 = ForceField('amber99sb.xml', 'amber99_obc.xml') self.forcefield2 = ForceField('amber99sb.xml', 'amber99_obc.xml')
def test_system_integrator_deepcopy(self):
def test_deepcopy(self): """Test that serialization/deserialization of system and integrator works (via deepcopy)."""
"""Test that serialization/deserialization works (via deepcopy)."""
system = self.forcefield1.createSystem(self.pdb1.topology) system = self.forcefield1.createSystem(self.pdb1.topology)
integrator = VerletIntegrator(2*femtosecond) integrator = VerletIntegrator(2*femtosecond)
...@@ -46,9 +45,14 @@ class TestPickle(unittest.TestCase): ...@@ -46,9 +45,14 @@ class TestPickle(unittest.TestCase):
state3 = pickle.loads(str_state) state3 = pickle.loads(str_state)
context.setState(state3) context.setState(state3)
del context, integrator del context, integrator
def test_force_deepcopy(self):
"""Test that deep copying of forces works correctly."""
force = NonbondedForce()
force_copy = copy.deepcopy(force)
self.assertIsEqual(force.__class__.__name__, 'NonbondedForce')
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment