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

GromacsTopFile supports [ settles ] directive (#4188)

parent f67c7b7e
...@@ -278,6 +278,8 @@ class GromacsTopFile(object): ...@@ -278,6 +278,8 @@ class GromacsTopFile(object):
self._processPair(line) self._processPair(line)
elif self._currentCategory == 'constraints': elif self._currentCategory == 'constraints':
self._processConstraint(line) self._processConstraint(line)
elif self._currentCategory == 'settles':
self._processSettles(line)
elif self._currentCategory == 'cmap': elif self._currentCategory == 'cmap':
self._processCmap(line) self._processCmap(line)
elif self._currentCategory == 'atomtypes': elif self._currentCategory == 'atomtypes':
...@@ -411,6 +413,18 @@ class GromacsTopFile(object): ...@@ -411,6 +413,18 @@ class GromacsTopFile(object):
raise ValueError('Too few fields in [ constraints ] line: '+line) raise ValueError('Too few fields in [ constraints ] line: '+line)
self._currentMoleculeType.constraints.append(fields) self._currentMoleculeType.constraints.append(fields)
def _processSettles(self, line):
"""Process a line in the [ settles ] category."""
if self._currentMoleculeType is None:
raise ValueError('Found [ settles ] section before [ moleculetype ]')
fields = line.split()
if len(fields) < 4:
raise ValueError('Too few fields in [ settles ] line: '+line)
atom = int(fields[0])
self._currentMoleculeType.constraints.append([str(atom), str(atom+1), fields[1], fields[2]])
self._currentMoleculeType.constraints.append([str(atom), str(atom+2), fields[1], fields[2]])
self._currentMoleculeType.constraints.append([str(atom+1), str(atom+2), fields[1], fields[3]])
def _processCmap(self, line): def _processCmap(self, line):
"""Process a line in the [ cmaps ] category.""" """Process a line in the [ cmaps ] category."""
if self._currentMoleculeType is None: if self._currentMoleculeType is None:
......
...@@ -218,6 +218,7 @@ class TestGromacsTopFile(unittest.TestCase): ...@@ -218,6 +218,7 @@ class TestGromacsTopFile(unittest.TestCase):
"""Test a three particle virtual site.""" """Test a three particle virtual site."""
top = GromacsTopFile('systems/tip4pew.top') top = GromacsTopFile('systems/tip4pew.top')
system = top.createSystem() system = top.createSystem()
self.assertEqual(3, system.getNumConstraints())
self.assertTrue(system.isVirtualSite(3)) self.assertTrue(system.isVirtualSite(3))
vs = system.getVirtualSite(3) vs = system.getVirtualSite(3)
self.assertIsInstance(vs, ThreeParticleAverageSite) self.assertIsInstance(vs, ThreeParticleAverageSite)
......
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