Commit 27dcdb77 authored by Jason Swails's avatar Jason Swails
Browse files

Move prmtop instantiation outside of the setUp routine and put it in the module

itself. This way each parm is only read once for every test (rather than being
read for every test, even when they're not used, as part of the setUp routine).
For large systems, this makes the tests run a lot faster (for small systems it's
not a large speedup).

All tests continue to pass. This change also tests that the various calls to
createSystem and such do not actually change the object in a detrimental way.
parent 7a034156
...@@ -5,17 +5,12 @@ from simtk.openmm import * ...@@ -5,17 +5,12 @@ from simtk.openmm import *
from simtk.unit import * from simtk.unit import *
import simtk.openmm.app.element as elem import simtk.openmm.app.element as elem
prmtop1 = AmberPrmtopFile('systems/alanine-dipeptide-explicit.prmtop')
prmtop2 = AmberPrmtopFile('systems/alanine-dipeptide-implicit.prmtop')
class TestAmberPrmtopFile(unittest.TestCase): class TestAmberPrmtopFile(unittest.TestCase):
"""Test the AmberPrmtopFile.createSystem() method.""" """Test the AmberPrmtopFile.createSystem() method."""
def setUp(self):
"""Set up the tests by loading the input files."""
# alanine dipeptide with explicit water
self.prmtop1 = AmberPrmtopFile('systems/alanine-dipeptide-explicit.prmtop')
# alanine dipeptide with implicit water
self.prmtop2 = AmberPrmtopFile('systems/alanine-dipeptide-implicit.prmtop')
def test_NonbondedMethod(self): def test_NonbondedMethod(self):
"""Test all five options for the nonbondedMethod parameter.""" """Test all five options for the nonbondedMethod parameter."""
...@@ -25,7 +20,7 @@ class TestAmberPrmtopFile(unittest.TestCase): ...@@ -25,7 +20,7 @@ class TestAmberPrmtopFile(unittest.TestCase):
CutoffPeriodic:NonbondedForce.CutoffPeriodic, CutoffPeriodic:NonbondedForce.CutoffPeriodic,
Ewald:NonbondedForce.Ewald, PME: NonbondedForce.PME} Ewald:NonbondedForce.Ewald, PME: NonbondedForce.PME}
for method in methodMap: for method in methodMap:
system = self.prmtop1.createSystem(nonbondedMethod=method) system = prmtop1.createSystem(nonbondedMethod=method)
forces = system.getForces() forces = system.getForces()
self.assertTrue(any(isinstance(f, NonbondedForce) and self.assertTrue(any(isinstance(f, NonbondedForce) and
f.getNonbondedMethod()==methodMap[method] f.getNonbondedMethod()==methodMap[method]
...@@ -35,9 +30,9 @@ class TestAmberPrmtopFile(unittest.TestCase): ...@@ -35,9 +30,9 @@ class TestAmberPrmtopFile(unittest.TestCase):
"""Test to make sure the nonbondedCutoff parameter is passed correctly.""" """Test to make sure the nonbondedCutoff parameter is passed correctly."""
for method in [CutoffNonPeriodic, CutoffPeriodic, Ewald, PME]: for method in [CutoffNonPeriodic, CutoffPeriodic, Ewald, PME]:
system = self.prmtop1.createSystem(nonbondedMethod=method, system = prmtop1.createSystem(nonbondedMethod=method,
nonbondedCutoff=2*nanometer, nonbondedCutoff=2*nanometer,
constraints=HBonds) constraints=HBonds)
cutoff_distance = 0.0*nanometer cutoff_distance = 0.0*nanometer
cutoff_check = 2.0*nanometer cutoff_check = 2.0*nanometer
for force in system.getForces(): for force in system.getForces():
...@@ -49,9 +44,9 @@ class TestAmberPrmtopFile(unittest.TestCase): ...@@ -49,9 +44,9 @@ class TestAmberPrmtopFile(unittest.TestCase):
"""Test to make sure the ewaldErrorTolerance parameter is passed correctly.""" """Test to make sure the ewaldErrorTolerance parameter is passed correctly."""
for method in [Ewald, PME]: for method in [Ewald, PME]:
system = self.prmtop1.createSystem(nonbondedMethod=method, system = prmtop1.createSystem(nonbondedMethod=method,
ewaldErrorTolerance=1e-6, ewaldErrorTolerance=1e-6,
constraints=HBonds) constraints=HBonds)
tolerance = 0 tolerance = 0
tolerance_check = 1e-6 tolerance_check = 1e-6
for force in system.getForces(): for force in system.getForces():
...@@ -63,18 +58,18 @@ class TestAmberPrmtopFile(unittest.TestCase): ...@@ -63,18 +58,18 @@ class TestAmberPrmtopFile(unittest.TestCase):
"""Test both options (True and False) for the removeCMMotion parameter.""" """Test both options (True and False) for the removeCMMotion parameter."""
for b in [True, False]: for b in [True, False]:
system = self.prmtop1.createSystem(removeCMMotion=b) system = prmtop1.createSystem(removeCMMotion=b)
forces = system.getForces() forces = system.getForces()
self.assertEqual(any(isinstance(f, CMMotionRemover) for f in forces), b) self.assertEqual(any(isinstance(f, CMMotionRemover) for f in forces), b)
def test_RigidWaterAndConstraints(self): def test_RigidWaterAndConstraints(self):
"""Test all eight options for the constraints and rigidWater parameters.""" """Test all eight options for the constraints and rigidWater parameters."""
topology = self.prmtop1.topology topology = prmtop1.topology
for constraints_value in [None, HBonds, AllBonds, HAngles]: for constraints_value in [None, HBonds, AllBonds, HAngles]:
for rigidWater_value in [True, False]: for rigidWater_value in [True, False]:
system = self.prmtop1.createSystem(constraints=constraints_value, system = prmtop1.createSystem(constraints=constraints_value,
rigidWater=rigidWater_value) rigidWater=rigidWater_value)
validateConstraints(self, topology, system, validateConstraints(self, topology, system,
constraints_value, rigidWater_value) constraints_value, rigidWater_value)
...@@ -84,7 +79,7 @@ class TestAmberPrmtopFile(unittest.TestCase): ...@@ -84,7 +79,7 @@ class TestAmberPrmtopFile(unittest.TestCase):
""" """
for implicitSolvent_value in [HCT, OBC1, OBC2, GBn]: for implicitSolvent_value in [HCT, OBC1, OBC2, GBn]:
system = self.prmtop2.createSystem(implicitSolvent=implicitSolvent_value) system = prmtop2.createSystem(implicitSolvent=implicitSolvent_value)
forces = system.getForces() forces = system.getForces()
if implicitSolvent_value in set([HCT, OBC1, GBn]): if implicitSolvent_value in set([HCT, OBC1, GBn]):
force_type = CustomGBForce force_type = CustomGBForce
...@@ -99,7 +94,7 @@ class TestAmberPrmtopFile(unittest.TestCase): ...@@ -99,7 +94,7 @@ class TestAmberPrmtopFile(unittest.TestCase):
CutoffNonPeriodic:NonbondedForce.CutoffNonPeriodic} CutoffNonPeriodic:NonbondedForce.CutoffNonPeriodic}
for implicitSolvent_value in [HCT, OBC1, OBC2, GBn]: for implicitSolvent_value in [HCT, OBC1, OBC2, GBn]:
for method in methodMap: for method in methodMap:
system = self.prmtop2.createSystem(implicitSolvent=implicitSolvent_value, system = prmtop2.createSystem(implicitSolvent=implicitSolvent_value,
solventDielectric=50.0, soluteDielectric=0.9, nonbondedMethod=method) solventDielectric=50.0, soluteDielectric=0.9, nonbondedMethod=method)
found_matching_solvent_dielectric=False found_matching_solvent_dielectric=False
found_matching_solute_dielectric=False found_matching_solute_dielectric=False
...@@ -136,10 +131,10 @@ class TestAmberPrmtopFile(unittest.TestCase): ...@@ -136,10 +131,10 @@ class TestAmberPrmtopFile(unittest.TestCase):
def test_HydrogenMass(self): def test_HydrogenMass(self):
"""Test that altering the mass of hydrogens works correctly.""" """Test that altering the mass of hydrogens works correctly."""
topology = self.prmtop1.topology topology = prmtop1.topology
hydrogenMass = 4*amu hydrogenMass = 4*amu
system1 = self.prmtop1.createSystem() system1 = prmtop1.createSystem()
system2 = self.prmtop1.createSystem(hydrogenMass=hydrogenMass) system2 = prmtop1.createSystem(hydrogenMass=hydrogenMass)
for atom in topology.atoms(): for atom in topology.atoms():
if atom.element == elem.hydrogen: if atom.element == elem.hydrogen:
self.assertNotEqual(hydrogenMass, system1.getParticleMass(atom.index)) self.assertNotEqual(hydrogenMass, system1.getParticleMass(atom.index))
......
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