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,18 +5,13 @@ from simtk.openmm import *
from simtk.unit import *
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):
"""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):
"""Test all five options for the nonbondedMethod parameter."""
......@@ -25,7 +20,7 @@ class TestAmberPrmtopFile(unittest.TestCase):
CutoffPeriodic:NonbondedForce.CutoffPeriodic,
Ewald:NonbondedForce.Ewald, PME: NonbondedForce.PME}
for method in methodMap:
system = self.prmtop1.createSystem(nonbondedMethod=method)
system = prmtop1.createSystem(nonbondedMethod=method)
forces = system.getForces()
self.assertTrue(any(isinstance(f, NonbondedForce) and
f.getNonbondedMethod()==methodMap[method]
......@@ -35,7 +30,7 @@ class TestAmberPrmtopFile(unittest.TestCase):
"""Test to make sure the nonbondedCutoff parameter is passed correctly."""
for method in [CutoffNonPeriodic, CutoffPeriodic, Ewald, PME]:
system = self.prmtop1.createSystem(nonbondedMethod=method,
system = prmtop1.createSystem(nonbondedMethod=method,
nonbondedCutoff=2*nanometer,
constraints=HBonds)
cutoff_distance = 0.0*nanometer
......@@ -49,7 +44,7 @@ class TestAmberPrmtopFile(unittest.TestCase):
"""Test to make sure the ewaldErrorTolerance parameter is passed correctly."""
for method in [Ewald, PME]:
system = self.prmtop1.createSystem(nonbondedMethod=method,
system = prmtop1.createSystem(nonbondedMethod=method,
ewaldErrorTolerance=1e-6,
constraints=HBonds)
tolerance = 0
......@@ -63,17 +58,17 @@ class TestAmberPrmtopFile(unittest.TestCase):
"""Test both options (True and False) for the removeCMMotion parameter."""
for b in [True, False]:
system = self.prmtop1.createSystem(removeCMMotion=b)
system = prmtop1.createSystem(removeCMMotion=b)
forces = system.getForces()
self.assertEqual(any(isinstance(f, CMMotionRemover) for f in forces), b)
def test_RigidWaterAndConstraints(self):
"""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 rigidWater_value in [True, False]:
system = self.prmtop1.createSystem(constraints=constraints_value,
system = prmtop1.createSystem(constraints=constraints_value,
rigidWater=rigidWater_value)
validateConstraints(self, topology, system,
constraints_value, rigidWater_value)
......@@ -84,7 +79,7 @@ class TestAmberPrmtopFile(unittest.TestCase):
"""
for implicitSolvent_value in [HCT, OBC1, OBC2, GBn]:
system = self.prmtop2.createSystem(implicitSolvent=implicitSolvent_value)
system = prmtop2.createSystem(implicitSolvent=implicitSolvent_value)
forces = system.getForces()
if implicitSolvent_value in set([HCT, OBC1, GBn]):
force_type = CustomGBForce
......@@ -99,7 +94,7 @@ class TestAmberPrmtopFile(unittest.TestCase):
CutoffNonPeriodic:NonbondedForce.CutoffNonPeriodic}
for implicitSolvent_value in [HCT, OBC1, OBC2, GBn]:
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)
found_matching_solvent_dielectric=False
found_matching_solute_dielectric=False
......@@ -136,10 +131,10 @@ class TestAmberPrmtopFile(unittest.TestCase):
def test_HydrogenMass(self):
"""Test that altering the mass of hydrogens works correctly."""
topology = self.prmtop1.topology
topology = prmtop1.topology
hydrogenMass = 4*amu
system1 = self.prmtop1.createSystem()
system2 = self.prmtop1.createSystem(hydrogenMass=hydrogenMass)
system1 = prmtop1.createSystem()
system2 = prmtop1.createSystem(hydrogenMass=hydrogenMass)
for atom in topology.atoms():
if atom.element == elem.hydrogen:
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