Commit a3476d23 authored by peastman's avatar peastman
Browse files

Merge pull request #1086 from rmcgibbo/py3

Fix two tests for python3
parents c2891265 920d3d4b
...@@ -3,12 +3,16 @@ from validateConstraints import * ...@@ -3,12 +3,16 @@ from validateConstraints import *
from simtk.openmm.app import * from simtk.openmm.app import *
from simtk.openmm import * from simtk.openmm import *
from simtk.unit import * from simtk.unit import *
from simtk.openmm.app.gromacstopfile import _defaultGromacsIncludeDir
import simtk.openmm.app.element as elem import simtk.openmm.app.element as elem
GROMACS_INCLUDE = _defaultGromacsIncludeDir()
@unittest.skipIf(not os.path.exists(GROMACS_INCLUDE), 'GROMACS is not installed')
class TestGromacsTopFile(unittest.TestCase): class TestGromacsTopFile(unittest.TestCase):
"""Test the GromacsTopFile.createSystem() method.""" """Test the GromacsTopFile.createSystem() method."""
def setUp(self): def setUp(self):
"""Set up the tests by loading the input files.""" """Set up the tests by loading the input files."""
...@@ -20,15 +24,15 @@ class TestGromacsTopFile(unittest.TestCase): ...@@ -20,15 +24,15 @@ class TestGromacsTopFile(unittest.TestCase):
def test_NonbondedMethod(self): def test_NonbondedMethod(self):
"""Test all five options for the nonbondedMethod parameter.""" """Test all five options for the nonbondedMethod parameter."""
methodMap = {NoCutoff:NonbondedForce.NoCutoff, methodMap = {NoCutoff:NonbondedForce.NoCutoff,
CutoffNonPeriodic:NonbondedForce.CutoffNonPeriodic, CutoffNonPeriodic:NonbondedForce.CutoffNonPeriodic,
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.top1.createSystem(nonbondedMethod=method) system = self.top1.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]
for f in forces)) for f in forces))
def test_ff99SBILDN(self): def test_ff99SBILDN(self):
...@@ -49,8 +53,8 @@ class TestGromacsTopFile(unittest.TestCase): ...@@ -49,8 +53,8 @@ class TestGromacsTopFile(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.top1.createSystem(nonbondedMethod=method, system = self.top1.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
...@@ -63,8 +67,8 @@ class TestGromacsTopFile(unittest.TestCase): ...@@ -63,8 +67,8 @@ class TestGromacsTopFile(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.top1.createSystem(nonbondedMethod=method, system = self.top1.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
...@@ -86,9 +90,9 @@ class TestGromacsTopFile(unittest.TestCase): ...@@ -86,9 +90,9 @@ class TestGromacsTopFile(unittest.TestCase):
topology = self.top1.topology topology = self.top1.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.top1.createSystem(constraints=constraints_value, system = self.top1.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)
def test_ImplicitSolvent(self): def test_ImplicitSolvent(self):
...@@ -102,8 +106,8 @@ class TestGromacsTopFile(unittest.TestCase): ...@@ -102,8 +106,8 @@ class TestGromacsTopFile(unittest.TestCase):
"""Test that solventDielectric and soluteDielectric are passed correctly. """Test that solventDielectric and soluteDielectric are passed correctly.
""" """
system = self.top2.createSystem(implicitSolvent=OBC2, system = self.top2.createSystem(implicitSolvent=OBC2,
solventDielectric=50.0, solventDielectric=50.0,
soluteDielectric = 0.9) soluteDielectric = 0.9)
found_matching_solvent_dielectric=False found_matching_solvent_dielectric=False
found_matching_solute_dielectric=False found_matching_solute_dielectric=False
...@@ -115,12 +119,12 @@ class TestGromacsTopFile(unittest.TestCase): ...@@ -115,12 +119,12 @@ class TestGromacsTopFile(unittest.TestCase):
found_matching_solute_dielectric = True found_matching_solute_dielectric = True
if isinstance(force, NonbondedForce): if isinstance(force, NonbondedForce):
self.assertEqual(force.getReactionFieldDielectric(), 1.0) self.assertEqual(force.getReactionFieldDielectric(), 1.0)
self.assertTrue(found_matching_solvent_dielectric and self.assertTrue(found_matching_solvent_dielectric and
found_matching_solute_dielectric) found_matching_solute_dielectric)
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.top1.topology topology = self.top1.topology
hydrogenMass = 4*amu hydrogenMass = 4*amu
system1 = self.top1.createSystem() system1 = self.top1.createSystem()
......
import sys
import unittest import unittest
from simtk.openmm.app import * from simtk.openmm.app import *
from simtk.openmm import * 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
import cStringIO if sys.version_info >= (3, 0):
from io import StringIO
else:
from cStringIO import StringIO
class TestPdbFile(unittest.TestCase): class TestPdbFile(unittest.TestCase):
"""Test the PDB file parser""" """Test the PDB file parser"""
def test_Triclinic(self): def test_Triclinic(self):
"""Test parsing a file that describes a triclinic box.""" """Test parsing a file that describes a triclinic box."""
pdb = PDBFile('systems/triclinic.pdb') pdb = PDBFile('systems/triclinic.pdb')
...@@ -43,9 +48,9 @@ class TestPdbFile(unittest.TestCase): ...@@ -43,9 +48,9 @@ class TestPdbFile(unittest.TestCase):
def test_WriteFile(self): def test_WriteFile(self):
"""Write a file, read it back, and make sure it matches the original.""" """Write a file, read it back, and make sure it matches the original."""
pdb1 = PDBFile('systems/triclinic.pdb') pdb1 = PDBFile('systems/triclinic.pdb')
output = cStringIO.StringIO() output = StringIO()
PDBFile.writeFile(pdb1.topology, pdb1.positions, output) PDBFile.writeFile(pdb1.topology, pdb1.positions, output)
input = cStringIO.StringIO(output.getvalue()) input = StringIO(output.getvalue())
pdb2 = PDBFile(input) pdb2 = PDBFile(input)
output.close(); output.close();
input.close(); input.close();
......
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