Commit 71d33617 authored by John Chodera (MSKCC)'s avatar John Chodera (MSKCC)
Browse files

Merge remote-tracking branch 'upstream/master'

parents eb232608 9da36463
...@@ -417,7 +417,6 @@ Parameters: ...@@ -417,7 +417,6 @@ Parameters:
@staticmethod @staticmethod
def deserialize(inputString): def deserialize(inputString):
"""Reconstruct an object that has been serialized as XML.""" """Reconstruct an object that has been serialized as XML."""
# Look for the first tag to figure out what type of object it is.
import re import re
match = re.search("<([^?]\S*)", inputString) match = re.search("<([^?]\S*)", inputString)
if match is None: if match is None:
......
...@@ -6,3 +6,12 @@ ...@@ -6,3 +6,12 @@
%include pythonprepend.i %include pythonprepend.i
%include pythonappend.i %include pythonappend.i
%include typemaps.i %include typemaps.i
/* SWIG 3.x resolved a bug in which all wrapped C++ functions took *args as its
* default argument list. OpenMM then exploited this bug by doing stuff like
* passing args to stripUnits (and all added code assumed that the arguments
* were in an "args" list). So in order to restore this arguably buggy behavior
* from SWIG 2, enable the "compactdefaultargs" feature globally.
*
* See https://github.com/swig/swig/issues/387
*/
%feature("compactdefaultargs");
import unittest import unittest
import os
import tempfile
from validateConstraints import * from validateConstraints import *
from simtk.openmm.app import * from simtk.openmm.app import *
from simtk.openmm import * from simtk.openmm import *
...@@ -10,6 +12,7 @@ prmtop2 = AmberPrmtopFile('systems/alanine-dipeptide-implicit.prmtop') ...@@ -10,6 +12,7 @@ prmtop2 = AmberPrmtopFile('systems/alanine-dipeptide-implicit.prmtop')
prmtop3 = AmberPrmtopFile('systems/ff14ipq.parm7') prmtop3 = AmberPrmtopFile('systems/ff14ipq.parm7')
prmtop4 = AmberPrmtopFile('systems/Mg_water.prmtop') prmtop4 = AmberPrmtopFile('systems/Mg_water.prmtop')
prmtop5 = AmberPrmtopFile('systems/tz2.truncoct.parm7') prmtop5 = AmberPrmtopFile('systems/tz2.truncoct.parm7')
prmtop6 = AmberPrmtopFile('systems/gaffwat.parm7')
inpcrd3 = AmberInpcrdFile('systems/ff14ipq.rst7') inpcrd3 = AmberInpcrdFile('systems/ff14ipq.rst7')
inpcrd4 = AmberInpcrdFile('systems/Mg_water.inpcrd') inpcrd4 = AmberInpcrdFile('systems/Mg_water.inpcrd')
...@@ -198,6 +201,24 @@ class TestAmberPrmtopFile(unittest.TestCase): ...@@ -198,6 +201,24 @@ class TestAmberPrmtopFile(unittest.TestCase):
# Amber using this force field. # Amber using this force field.
self.assertAlmostEqual(-7042.3903307/ene, 1, places=3) self.assertAlmostEqual(-7042.3903307/ene, 1, places=3)
def test_HAngle(self):
""" Test that HAngle constraints are properly handled for all hydrogens """
system = prmtop6.createSystem(nonbondedMethod=PME,
nonbondedCutoff=1*nanometers,
constraints=HBonds)
self.assertEqual(system.getForce(0).getNumBonds(), 0)
self.assertEqual(system.getNumParticles(), 3000)
self.assertEqual(system.getNumConstraints(), 2000)
self.assertEqual(system.getForce(1).getNumAngles(), 1000)
system = prmtop6.createSystem(nonbondedMethod=PME,
nonbondedCutoff=1*nanometers,
constraints=HAngles)
self.assertEqual(system.getForce(0).getNumBonds(), 0)
self.assertEqual(system.getNumParticles(), 3000)
self.assertEqual(system.getNumConstraints(), 3000)
self.assertEqual(system.getForce(1).getNumAngles(), 0)
def test_LJ1264(self): def test_LJ1264(self):
"""Test prmtop with 12-6-4 vdW potential implemented""" """Test prmtop with 12-6-4 vdW potential implemented"""
system = prmtop4.createSystem(nonbondedMethod=PME, system = prmtop4.createSystem(nonbondedMethod=PME,
...@@ -275,5 +296,27 @@ class TestAmberPrmtopFile(unittest.TestCase): ...@@ -275,5 +296,27 @@ class TestAmberPrmtopFile(unittest.TestCase):
diff = norm(f1-f2) diff = norm(f1-f2)
self.assertTrue(diff < 0.1 or diff/norm(f1) < 1e-4) self.assertTrue(diff < 0.1 or diff/norm(f1) < 1e-4)
def test_with_dcd_reporter(self):
"""Check that an amber simulation like the docs example works with a DCD reporter."""
temperature = 50*kelvin
prmtop = prmtop4 # Mg + water
inpcrd = inpcrd4 # Mg + water
system = prmtop.createSystem(nonbondedMethod=PME, nonbondedCutoff=1*nanometer, constraints=HBonds)
system.addForce(MonteCarloBarostat(1.0 * atmospheres, temperature, 1))
integrator = LangevinIntegrator(temperature, 1.0 / picosecond, 0.0001 * picoseconds)
simulation = Simulation(prmtop.topology, system, integrator)
simulation.context.setPositions(inpcrd.positions)
simulation.context.setPeriodicBoxVectors(*inpcrd.boxVectors)
fname = tempfile.mktemp(suffix='.dcd')
simulation.reporters.append(DCDReporter(fname, 1)) # This is an explicit test for the bugs in issue #850
simulation.step(5)
os.remove(fname)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
...@@ -115,6 +115,13 @@ class TestCharmmFiles(unittest.TestCase): ...@@ -115,6 +115,13 @@ class TestCharmmFiles(unittest.TestCase):
ene = state.getPotentialEnergy().value_in_unit(kilocalories_per_mole) ene = state.getPotentialEnergy().value_in_unit(kilocalories_per_mole)
self.assertAlmostEqual(ene, 15490.0033559, delta=0.05) self.assertAlmostEqual(ene, 15490.0033559, delta=0.05)
def test_InsCode(self):
""" Test the parsing of PSF files that contain insertion codes in their residue numbers """
psf = CharmmPsfFile('systems/4TVP-dmj_wat-ion.psf')
self.assertEqual(len(list(psf.topology.atoms())), 66264)
self.assertEqual(len(list(psf.topology.residues())), 20169)
self.assertEqual(len(list(psf.topology.bonds())), 46634)
def test_ImplicitSolventForces(self): def test_ImplicitSolventForces(self):
"""Compute forces for different implicit solvent types, and compare them to ones generated with a previous version of OpenMM to ensure they haven't changed.""" """Compute forces for different implicit solvent types, and compare them to ones generated with a previous version of OpenMM to ensure they haven't changed."""
solventType = [HCT, OBC1, OBC2, GBn, GBn2] solventType = [HCT, OBC1, OBC2, GBn, GBn2]
......
import pickle import pickle
import unittest import random
from simtk.unit import dalton from simtk.unit import dalton, is_quantity
from simtk.openmm.app import element from simtk.openmm.app import element
import unittest
class TestElement(unittest.TestCase): class TestElement(unittest.TestCase):
def test_immutable(self): def test_immutable(self):
...@@ -14,18 +15,37 @@ class TestElement(unittest.TestCase): ...@@ -14,18 +15,37 @@ class TestElement(unittest.TestCase):
newsulfur = pickle.loads(pickle.dumps(element.sulfur)) newsulfur = pickle.loads(pickle.dumps(element.sulfur))
# make sure that a new object is not created during the pickle/unpickle # make sure that a new object is not created during the pickle/unpickle
# cycle # cycle
assert element.sulfur == newsulfur self.assertEqual(element.sulfur, newsulfur)
assert element.sulfur is newsulfur self.assertTrue(element.sulfur is newsulfur)
assert id(element.sulfur) == id(newsulfur)
def test_attributes(self): def test_attributes(self):
assert element.hydrogen.atomic_number == 1 self.assertEqual(element.hydrogen.atomic_number, 1)
assert element.hydrogen.symbol == 'H' self.assertEqual(element.hydrogen.symbol, 'H')
assert element.hydrogen.name == 'hydrogen' self.assertEqual(element.hydrogen.name, 'hydrogen')
assert element.hydrogen.mass == 1.007947 * dalton self.assertEqual(element.hydrogen.mass, 1.007947 * dalton)
def test_getByMass(self):
""" Tests the getByMass method """
def exhaustive_search(mass):
"""
Searches through all element symbols and finds the one with the
smallest mass difference
"""
min_diff = mass
closest_element = None
for symbol, elem in element.Element._elements_by_symbol.items():
diff = abs(elem.mass._value - mass)
if diff < min_diff:
min_diff = diff
closest_element = elem
return closest_element
# Check 5000 random numbers between 0 and 300
for i in range(5000):
mass = random.random() * 300
elem = element.Element.getByMass(mass)
self.assertTrue(elem is exhaustive_search(mass))
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
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