Commit dab7a82c authored by peastman's avatar peastman
Browse files

Merge pull request #406 from swails/master

Add support for native CHARMM files
parents 5485a4e3 66bcd1e0
...@@ -377,5 +377,5 @@ def _format_83(f): ...@@ -377,5 +377,5 @@ def _format_83(f):
return '%8.3f' % f return '%8.3f' % f
if -9999999 < f < 99999999: if -9999999 < f < 99999999:
return ('%8.3f' % f)[:8] return ('%8.3f' % f)[:8]
raise ValueError('coordinate "%s" could not be represnted ' raise ValueError('coordinate "%s" could not be represented '
'in a width-8 field' % f) 'in a width-8 field' % f)
import unittest
from validateConstraints import *
from simtk.openmm.app import *
from simtk.openmm import *
from simtk.unit import *
import simtk.openmm.app.element as elem
class TestCharmmFiles(unittest.TestCase):
"""Test the GromacsTopFile.createSystem() method."""
def setUp(self):
"""Set up the tests by loading the input files."""
# alanine tripeptide; no waters
self.psf_c = CharmmPsfFile('systems/ala_ala_ala.psf')
self.psf_x = CharmmPsfFile('systems/ala_ala_ala.xpsf')
self.psf_v = CharmmPsfFile('systems/ala_ala_ala.vpsf')
self.params = CharmmParameterSet(
'systems/charmm22.rtf', 'systems/charmm22.par')
self.pdb = PDBFile('systems/ala_ala_ala.pdb')
def test_NonbondedMethod(self):
"""Test both non-periodic methods for the systems"""
methodMap = {NoCutoff:NonbondedForce.NoCutoff,
CutoffNonPeriodic:NonbondedForce.CutoffNonPeriodic}
for top in (self.psf_c, self.psf_x, self.psf_v):
for method in methodMap:
system = top.createSystem(self.params, nonbondedMethod=method)
forces = system.getForces()
self.assertTrue(any(isinstance(f, NonbondedForce) and
f.getNonbondedMethod()==methodMap[method]
for f in forces))
def test_Cutoff(self):
"""Test to make sure the nonbondedCutoff parameter is passed correctly."""
for top in (self.psf_c, self.psf_x, self.psf_v):
for method in [CutoffNonPeriodic]:
system = top.createSystem(self.params, nonbondedMethod=method,
nonbondedCutoff=2*nanometer,
constraints=HBonds)
cutoff_distance = 0.0*nanometer
cutoff_check = 2.0*nanometer
for force in system.getForces():
if isinstance(force, NonbondedForce):
cutoff_distance = force.getCutoffDistance()
self.assertEqual(cutoff_distance, cutoff_check)
def test_RemoveCMMotion(self):
"""Test both options (True and False) for the removeCMMotion parameter."""
for b in [True, False]:
system = self.psf_c.createSystem(self.params, removeCMMotion=b)
self.assertEqual(any(isinstance(f, CMMotionRemover) for f in system.getForces()), b)
def test_ImplicitSolvent(self):
"""Test implicit solvent using the implicitSolvent parameter.
"""
system = self.psf_v.createSystem(self.params, implicitSolvent=OBC2)
self.assertTrue(any(isinstance(f, CustomGBForce) for f in system.getForces()))
def test_ImplicitSolventParameters(self):
"""Test that solventDielectric and soluteDielectric are passed correctly.
"""
system = self.psf_x.createSystem(self.params, implicitSolvent=GBn,
solventDielectric=50.0,
soluteDielectric = 0.9)
found_matching_solvent_dielectric=False
found_matching_solute_dielectric=False
for force in system.getForces():
if isinstance(force, CustomGBForce):
for i in range(force.getNumGlobalParameters()):
if force.getGlobalParameterName(i) == 'solventDielectric':
if force.getGlobalParameterDefaultValue(i) == 50.0:
found_matching_solvent_dielectric = True
elif force.getGlobalParameterName(i) == 'soluteDielectric':
if force.getGlobalParameterDefaultValue(i) == 0.9:
found_matching_solute_dielectric = True
if isinstance(force, NonbondedForce):
self.assertEqual(force.getReactionFieldDielectric(), 1.0)
self.assertTrue(found_matching_solvent_dielectric and
found_matching_solute_dielectric)
def test_HydrogenMass(self):
"""Test that altering the mass of hydrogens works correctly."""
topology = self.psf_v.topology
hydrogenMass = 4*amu
system1 = self.psf_v.createSystem(self.params)
system2 = self.psf_v.createSystem(self.params, hydrogenMass=hydrogenMass)
for atom in topology.atoms():
if atom.element == elem.hydrogen:
self.assertNotEqual(hydrogenMass, system1.getParticleMass(atom.index))
self.assertEqual(hydrogenMass, system2.getParticleMass(atom.index))
totalMass1 = sum([system1.getParticleMass(i) for i in range(system1.getNumParticles())]).value_in_unit(amu)
totalMass2 = sum([system2.getParticleMass(i) for i in range(system2.getNumParticles())]).value_in_unit(amu)
self.assertAlmostEqual(totalMass1, totalMass2)
if __name__ == '__main__':
unittest.main()
REMARK original generated coordinate pdb file
ATOM 1 N ALA X 1 0.024 -0.103 -0.101 1.00 0.00 P1 N
ATOM 2 HT1 ALA X 1 0.027 -1.132 -0.239 1.00 0.00 P1 H
ATOM 3 HT2 ALA X 1 -0.805 0.163 0.471 1.00 0.00 P1 H
ATOM 4 HT3 ALA X 1 -0.059 0.384 -1.019 1.00 0.00 P1 H
ATOM 5 CA ALA X 1 1.247 0.375 0.636 1.00 0.00 P1 C
ATOM 6 HA ALA X 1 0.814 0.861 1.495 1.00 0.00 P1 H
ATOM 7 CB ALA X 1 2.057 -0.772 1.289 1.00 0.00 P1 C
ATOM 8 HB1 ALA X 1 3.136 -0.752 1.032 1.00 0.00 P1 H
ATOM 9 HB2 ALA X 1 1.990 -0.641 2.395 1.00 0.00 P1 H
ATOM 10 HB3 ALA X 1 1.656 -1.782 1.063 1.00 0.00 P1 H
ATOM 11 C ALA X 1 1.956 1.579 0.036 1.00 0.00 P1 C
ATOM 12 O ALA X 1 1.219 2.525 -0.201 1.00 0.00 P1 O
ATOM 13 N ALA X 2 3.289 1.631 -0.202 1.00 0.00 P1 N
ATOM 14 HN ALA X 2 3.939 0.868 -0.174 1.00 0.00 P1 H
ATOM 15 CA ALA X 2 3.990 2.909 -0.215 1.00 0.00 P1 C
ATOM 16 HA ALA X 2 3.742 3.440 0.695 1.00 0.00 P1 H
ATOM 17 CB ALA X 2 3.662 3.802 -1.434 1.00 0.00 P1 C
ATOM 18 HB1 ALA X 2 4.192 4.778 -1.358 1.00 0.00 P1 H
ATOM 19 HB2 ALA X 2 3.956 3.311 -2.382 1.00 0.00 P1 H
ATOM 20 HB3 ALA X 2 2.577 4.027 -1.467 1.00 0.00 P1 H
ATOM 21 C ALA X 2 5.487 2.654 -0.128 1.00 0.00 P1 C
ATOM 22 O ALA X 2 5.889 1.489 -0.137 1.00 0.00 P1 O
ATOM 23 C ALA X 3 8.018 5.323 0.136 1.00 0.00 P1 C
ATOM 24 OT1 ALA X 3 7.032 6.119 0.127 1.00 0.00 P1 O
ATOM 25 OT2 ALA X 3 9.219 5.692 0.188 1.00 0.00 P1 O
ATOM 26 N ALA X 3 6.275 3.733 -0.037 1.00 0.00 P1 N
ATOM 27 HN ALA X 3 5.963 4.691 -0.028 1.00 0.00 P1 H
ATOM 28 CA ALA X 3 7.707 3.802 0.068 1.00 0.00 P1 C
ATOM 29 HA ALA X 3 8.160 3.418 -0.833 1.00 0.00 P1 H
ATOM 30 CB ALA X 3 8.233 3.093 1.333 1.00 0.00 P1 C
ATOM 31 HB1 ALA X 3 9.342 3.149 1.356 1.00 0.00 P1 H
ATOM 32 HB2 ALA X 3 7.835 3.593 2.240 1.00 0.00 P1 H
ATOM 33 HB3 ALA X 3 7.923 2.030 1.332 1.00 0.00 P1 H
END
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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