Unverified Commit e2453f5e authored by Peter Eastman's avatar Peter Eastman Committed by GitHub
Browse files

Don't add extra bond between water hydrogens (#4219)

parent 6a09626b
...@@ -160,7 +160,13 @@ class AmberPrmtopFile(object): ...@@ -160,7 +160,13 @@ class AmberPrmtopFile(object):
atoms = list(top.atoms()) atoms = list(top.atoms())
for bond in prmtop.getBondsWithH(): for bond in prmtop.getBondsWithH():
top.addBond(atoms[bond[0]], atoms[bond[1]]) a1 = atoms[bond[0]]
a2 = atoms[bond[1]]
if a1.residue.name == 'HOH' and a1.element == elem.hydrogen and a2.element == elem.hydrogen:
# Don't add the "bond" Amber lists between the two hydrogens of a water molecule.
pass
else:
top.addBond(a1, a2)
for bond in prmtop.getBondsNoH(): for bond in prmtop.getBondsNoH():
top.addBond(atoms[bond[0]], atoms[bond[1]]) top.addBond(atoms[bond[0]], atoms[bond[1]])
......
...@@ -78,12 +78,14 @@ class TestAmberPrmtopFile(unittest.TestCase): ...@@ -78,12 +78,14 @@ class TestAmberPrmtopFile(unittest.TestCase):
"""Test all eight options for the constraints and rigidWater parameters.""" """Test all eight options for the constraints and rigidWater parameters."""
topology = prmtop1.topology topology = prmtop1.topology
for constraints_value in [None, HBonds, AllBonds, HAngles]: for constraints in [None, HBonds, AllBonds, HAngles]:
for rigidWater_value in [True, False]: for rigidWater in [True, False]:
system = prmtop1.createSystem(constraints=constraints_value, system = prmtop1.createSystem(constraints=constraints, rigidWater=rigidWater)
rigidWater=rigidWater_value) if constraints != None:
validateConstraints(self, topology, system, # Amber adds an extra "bond" between water hydrogens, so any constraint
constraints_value, rigidWater_value) # method except None is equivalent to rigidWater=True.
rigidWater = True
validateConstraints(self, topology, system, constraints, rigidWater)
def test_ImplicitSolvent(self): def test_ImplicitSolvent(self):
"""Test the four types of implicit solvents using the implicitSolvent """Test the four types of implicit solvents using the implicitSolvent
...@@ -460,5 +462,16 @@ class TestAmberPrmtopFile(unittest.TestCase): ...@@ -460,5 +462,16 @@ class TestAmberPrmtopFile(unittest.TestCase):
# If a constraint was added to a massless particle, this will throw an exception. # If a constraint was added to a massless particle, this will throw an exception.
context = Context(system, integrator, Platform.getPlatformByName('Reference')) context = Context(system, integrator, Platform.getPlatformByName('Reference'))
def testWaterBonds(self):
"""Test that water molecules have the right set of bonds"""
top = prmtop1.topology
for residue in top.residues():
if residue.name == 'HOH':
bonds = list(residue.bonds())
self.assertEqual(2, len(bonds))
for a1, a2 in bonds:
self.assertTrue(a1.element == elem.oxygen or a2.element == elem.oxygen)
self.assertTrue(a1.element == elem.hydrogen or a2.element == elem.hydrogen)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
...@@ -439,7 +439,6 @@ class TestForceField(unittest.TestCase): ...@@ -439,7 +439,6 @@ class TestForceField(unittest.TestCase):
<Atom name="H2" type="tip3p-H" charge="0.417"/> <Atom name="H2" type="tip3p-H" charge="0.417"/>
<Bond from="0" to="1"/> <Bond from="0" to="1"/>
<Bond from="0" to="2"/> <Bond from="0" to="2"/>
<Bond from="1" to="2"/>
</Residue> </Residue>
<Residue name="HOH2"> <Residue name="HOH2">
<Atom name="O" type="tip3p-O" charge="0.834"/> <Atom name="O" type="tip3p-O" charge="0.834"/>
...@@ -447,7 +446,6 @@ class TestForceField(unittest.TestCase): ...@@ -447,7 +446,6 @@ class TestForceField(unittest.TestCase):
<Atom name="H2" type="tip3p-H" charge="-0.417"/> <Atom name="H2" type="tip3p-H" charge="-0.417"/>
<Bond from="0" to="1"/> <Bond from="0" to="1"/>
<Bond from="0" to="2"/> <Bond from="0" to="2"/>
<Bond from="1" to="2"/>
</Residue> </Residue>
</Residues> </Residues>
<NonbondedForce coulomb14scale="0.833333" lj14scale="0.5"> <NonbondedForce coulomb14scale="0.833333" lj14scale="0.5">
......
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