"platforms/hip/include/HipHipFFT3D.h" did not exist on "e9f6e1bfb9a834dc5e34affafea7474ff000184f"
Commit 0b5d58d7 authored by Charlles Abreu's avatar Charlles Abreu
Browse files

Conflict resolution in TestSplineFilter.cpp

parents 9026dbe7 b0d13582
......@@ -3,7 +3,9 @@
try {
$action
} catch (std::exception &e) {
PyErr_SetString(PyExc_Exception, const_cast<char*>(e.what()));
PyObject* mm = PyImport_AddModule("simtk.openmm");
PyObject* openmm_exception = PyObject_GetAttrString(mm, "OpenMMException");
PyErr_SetString(openmm_exception, const_cast<char*>(e.what()));
return NULL;
}
}
......@@ -14,7 +16,9 @@
$action
} catch (std::exception &e) {
PyEval_RestoreThread(_savePythonThreadState);
PyErr_SetString(PyExc_Exception, const_cast<char*>(e.what()));
PyObject* mm = PyImport_AddModule("simtk.openmm");
PyObject* openmm_exception = PyObject_GetAttrString(mm, "OpenMMException");
PyErr_SetString(openmm_exception, const_cast<char*>(e.what()));
return NULL;
}
PyEval_RestoreThread(_savePythonThreadState);
......@@ -26,7 +30,9 @@
$action
} catch (std::exception &e) {
PyEval_RestoreThread(_savePythonThreadState);
PyErr_SetString(PyExc_Exception, const_cast<char*>(e.what()));
PyObject* mm = PyImport_AddModule("simtk.openmm");
PyObject* openmm_exception = PyObject_GetAttrString(mm, "OpenMMException");
PyErr_SetString(openmm_exception, const_cast<char*>(e.what()));
return NULL;
}
PyEval_RestoreThread(_savePythonThreadState);
......
......@@ -96,6 +96,33 @@ class TestCharmmFiles(unittest.TestCase):
totalMass2 = sum([system2.getParticleMass(i) for i in range(system2.getNumParticles())]).value_in_unit(amu)
self.assertAlmostEqual(totalMass1, totalMass2)
def test_DrudeMass(self):
"""Test that setting the mass of Drude particles works correctly."""
psf = CharmmPsfFile('systems/ala3_solv_drude.psf')
crd = CharmmCrdFile('systems/ala3_solv_drude.crd')
params = CharmmParameterSet('systems/toppar_drude_master_protein_2013e.str')
system = psf.createSystem(params, drudeMass=0)
trueMass = [system.getParticleMass(i) for i in range(system.getNumParticles())]
drudeMass = 0.3*amu
system = psf.createSystem(params, drudeMass=drudeMass)
adjustedMass = [system.getParticleMass(i) for i in range(system.getNumParticles())]
drudeForce = [f for f in system.getForces() if isinstance(f, DrudeForce)][0]
drudeParticles = set()
parentParticles = set()
for i in range(drudeForce.getNumParticles()):
params = drudeForce.getParticleParameters(i)
drudeParticles.add(params[0])
parentParticles.add(params[1])
for i in range(system.getNumParticles()):
if i in drudeParticles:
self.assertEqual(0*amu, trueMass[i])
self.assertEqual(drudeMass, adjustedMass[i])
elif i in parentParticles:
self.assertEqual(trueMass[i]-drudeMass, adjustedMass[i])
else:
self.assertEqual(trueMass[i], adjustedMass[i])
def test_NBFIX(self):
"""Tests CHARMM systems with NBFIX Lennard-Jones modifications"""
warnings.filterwarnings('ignore', category=CharmmPSFWarning)
......@@ -395,6 +422,114 @@ class TestCharmmFiles(unittest.TestCase):
self.assertEqual(sorted(system.getConstraintParameters(i)[:2] for i in range(system.getNumConstraints())),
sorted(hBonds_water + hAngles_water + allBonds_methanol + hAngles_methanol))
def test_Constraints_charmm(self):
"""Tests that CHARMM and OpenMM implementation of CHARMM force field produce the same constraints and energy"""
warnings.filterwarnings('ignore', category=CharmmPSFWarning)
psf = CharmmPsfFile('systems/ala3_solv.psf',
unitCellDimensions=Vec3(32.7119500, 32.9959600, 33.0071500) * angstroms)
crd = CharmmCrdFile('systems/ala3_solv.crd')
params = CharmmParameterSet('systems/par_all36_prot.prm',
'systems/toppar_water_ions.str')
plat = Platform.getPlatformByName('Reference')
system_charmm = psf.createSystem(params, nonbondedMethod=PME,
nonbondedCutoff=8 * angstroms)
topology = psf.topology
forcefield = ForceField('charmm36.xml', 'charmm36/water.xml')
system_openmm = forcefield.createSystem(topology, nonbondedMethod=PME,
nonbondedCutoff=8 * angstroms)
# Test different combinations of constrains/rigidWater parameters
system_charmm = psf.createSystem(params, constraints=None, rigidWater=False, nonbondedMethod=PME,
nonbondedCutoff=8 * angstroms)
system_openmm = forcefield.createSystem(topology, constraints=None, rigidWater=False, nonbondedMethod=PME,
nonbondedCutoff=8 * angstroms)
self.assertEqual(system_charmm.getNumConstraints(), 0)
self.assertEqual(system_openmm.getNumConstraints(), 0)
con_charmm = Context(system_charmm, VerletIntegrator(2 * femtoseconds), plat)
con_charmm.setPositions(crd.positions)
con_openmm = Context(system_openmm, VerletIntegrator(2 * femtoseconds), plat)
con_openmm.setPositions(crd.positions)
state_charmm = con_charmm.getState(getEnergy=True, enforcePeriodicBox=True)
ene_charmm = state_charmm.getPotentialEnergy().value_in_unit(kilocalories_per_mole)
state_openmm = con_openmm.getState(getEnergy=True, enforcePeriodicBox=True)
ene_openmm = state_openmm.getPotentialEnergy().value_in_unit(kilocalories_per_mole)
self.assertAlmostEqual(ene_charmm, ene_openmm, delta=0.05)
system_charmm = psf.createSystem(params, constraints=None, rigidWater=True, nonbondedMethod=PME,
nonbondedCutoff=8 * angstroms)
system_openmm = forcefield.createSystem(topology, constraints=None, rigidWater=True, nonbondedMethod=PME,
nonbondedCutoff=8 * angstroms)
self.assertEqual(
sorted(system_charmm.getConstraintParameters(i)[:2] for i in range(system_charmm.getNumConstraints())),
sorted(system_openmm.getConstraintParameters(j)[:2] for j in range(system_openmm.getNumConstraints())))
for i in range(system_charmm.getNumConstraints()):
self.assertAlmostEqual(system_charmm.getConstraintParameters(i)[2],
system_openmm.getConstraintParameters(i)[2], delta=1e-7 * nanometers)
system_charmm = psf.createSystem(params, constraints=HBonds, rigidWater=False, nonbondedMethod=PME,
nonbondedCutoff=8 * angstroms)
system_openmm = forcefield.createSystem(topology, constraints=HBonds, rigidWater=False, nonbondedMethod=PME,
nonbondedCutoff=8 * angstroms)
self.assertEqual(
sorted(system_charmm.getConstraintParameters(i)[:2] for i in range(system_charmm.getNumConstraints())),
sorted(system_openmm.getConstraintParameters(j)[:2] for j in range(system_openmm.getNumConstraints())))
for i in range(system_charmm.getNumConstraints()):
self.assertAlmostEqual(system_charmm.getConstraintParameters(i)[2],
system_openmm.getConstraintParameters(i)[2], delta=1e-7 * nanometers)
system_charmm = psf.createSystem(params, constraints=HBonds, rigidWater=True, nonbondedMethod=PME,
nonbondedCutoff=8 * angstroms)
system_openmm = forcefield.createSystem(topology, constraints=HBonds, rigidWater=True, nonbondedMethod=PME,
nonbondedCutoff=8 * angstroms)
self.assertEqual(
sorted(system_charmm.getConstraintParameters(i)[:2] for i in range(system_charmm.getNumConstraints())),
sorted(system_openmm.getConstraintParameters(j)[:2] for j in range(system_openmm.getNumConstraints())))
for i in range(system_charmm.getNumConstraints()):
self.assertAlmostEqual(system_charmm.getConstraintParameters(i)[2],
system_openmm.getConstraintParameters(i)[2], delta=1e-7 * nanometers)
system_charmm = psf.createSystem(params, constraints=AllBonds, rigidWater=False, nonbondedMethod=PME,
nonbondedCutoff=8 * angstroms)
system_openmm = forcefield.createSystem(topology, constraints=AllBonds, rigidWater=False, nonbondedMethod=PME,
nonbondedCutoff=8 * angstroms)
self.assertEqual(
sorted(system_charmm.getConstraintParameters(i)[:2] for i in range(system_charmm.getNumConstraints())),
sorted(system_openmm.getConstraintParameters(j)[:2] for j in range(system_openmm.getNumConstraints())))
for i in range(system_charmm.getNumConstraints()):
self.assertAlmostEqual(system_charmm.getConstraintParameters(i)[2],
system_openmm.getConstraintParameters(i)[2], delta=1e-7 * nanometers)
system_charmm = psf.createSystem(params, constraints=AllBonds, rigidWater=True, nonbondedMethod=PME,
nonbondedCutoff=8 * angstroms)
system_openmm = forcefield.createSystem(topology, constraints=AllBonds, rigidWater=True, nonbondedMethod=PME,
nonbondedCutoff=8 * angstroms)
self.assertEqual(
sorted(system_charmm.getConstraintParameters(i)[:2] for i in range(system_charmm.getNumConstraints())),
sorted(system_openmm.getConstraintParameters(j)[:2] for j in range(system_openmm.getNumConstraints())))
for i in range(system_charmm.getNumConstraints()):
self.assertAlmostEqual(system_charmm.getConstraintParameters(i)[2],
system_openmm.getConstraintParameters(i)[2], delta=1e-7 * nanometers)
system_charmm = psf.createSystem(params, constraints=HAngles, rigidWater=False, nonbondedMethod=PME,
nonbondedCutoff=8 * angstroms)
system_openmm = forcefield.createSystem(topology, constraints=HAngles, rigidWater=False, nonbondedMethod=PME,
nonbondedCutoff=8 * angstroms)
self.assertEqual(
sorted(system_charmm.getConstraintParameters(i)[:2] for i in range(system_charmm.getNumConstraints())),
sorted(system_openmm.getConstraintParameters(j)[:2] for j in range(system_openmm.getNumConstraints())))
for i in range(system_charmm.getNumConstraints()):
self.assertAlmostEqual(system_charmm.getConstraintParameters(i)[2],
system_openmm.getConstraintParameters(i)[2], delta=1e-7 * nanometers)
system_charmm = psf.createSystem(params, constraints=HAngles, rigidWater=True, nonbondedMethod=PME,
nonbondedCutoff=8 * angstroms)
system_openmm = forcefield.createSystem(topology, constraints=HAngles, rigidWater=True, nonbondedMethod=PME,
nonbondedCutoff=8 * angstroms)
self.assertEqual(
sorted(system_charmm.getConstraintParameters(i)[:2] for i in range(system_charmm.getNumConstraints())),
sorted(system_openmm.getConstraintParameters(j)[:2] for j in range(system_openmm.getNumConstraints())))
for i in range(system_charmm.getNumConstraints()):
self.assertAlmostEqual(system_charmm.getConstraintParameters(i)[2],
system_openmm.getConstraintParameters(i)[2], delta=1e-7 * nanometers)
if __name__ == '__main__':
unittest.main()
......
......@@ -251,6 +251,34 @@ class TestForceField(unittest.TestCase):
totalMass2 = sum([system2.getParticleMass(i) for i in range(system2.getNumParticles())]).value_in_unit(amu)
self.assertAlmostEqual(totalMass1, totalMass2)
def test_DrudeMass(self):
"""Test that setting the mass of Drude particles works correctly."""
forcefield = ForceField('charmm_polar_2013.xml')
pdb = PDBFile('systems/ala_ala_ala.pdb')
modeller = Modeller(pdb.topology, pdb.positions)
modeller.addExtraParticles(forcefield)
system = forcefield.createSystem(modeller.topology, drudeMass=0)
trueMass = [system.getParticleMass(i) for i in range(system.getNumParticles())]
drudeMass = 0.3*amu
system = forcefield.createSystem(modeller.topology, drudeMass=drudeMass)
adjustedMass = [system.getParticleMass(i) for i in range(system.getNumParticles())]
drudeForce = [f for f in system.getForces() if isinstance(f, DrudeForce)][0]
drudeParticles = set()
parentParticles = set()
for i in range(drudeForce.getNumParticles()):
params = drudeForce.getParticleParameters(i)
drudeParticles.add(params[0])
parentParticles.add(params[1])
for i in range(system.getNumParticles()):
if i in drudeParticles:
self.assertEqual(0*amu, trueMass[i])
self.assertEqual(drudeMass, adjustedMass[i])
elif i in parentParticles:
self.assertEqual(trueMass[i]-drudeMass, adjustedMass[i])
else:
self.assertEqual(trueMass[i], adjustedMass[i])
def test_Forces(self):
"""Compute forces and compare them to ones generated with a previous version of OpenMM to ensure they haven't changed."""
......
......@@ -121,6 +121,41 @@ class TestIntegrators(unittest.TestCase):
context.setPositions(pdb.positions)
integrator.step(10)
def testMTSLangevinIntegrator(self):
"""Test the MTSLangevinIntegrator on an explicit solvent system"""
# Create a periodic solvated system with PME
pdb = PDBFile('systems/alanine-dipeptide-explicit.pdb')
ff = ForceField('amber99sbildn.xml', 'tip3p.xml')
system = ff.createSystem(pdb.topology, cutoffMethod=PME)
# Split forces into groups
for force in system.getForces():
if force.__class__.__name__ == 'NonbondedForce':
force.setForceGroup(1)
force.setReciprocalSpaceForceGroup(2)
else:
force.setForceGroup(0)
# Create an integrator
integrator = MTSLangevinIntegrator(300*kelvin, 1/picosecond, 4*femtoseconds, [(2,1), (1,2), (0,4)])
# Run some equilibration.
context = Context(system, integrator)
context.setPositions(pdb.positions)
context.setVelocitiesToTemperature(300*kelvin)
integrator.step(500)
# See if the temperature is correct.
totalEnergy = 0*kilojoules_per_mole
steps = 50
for i in range(steps):
integrator.step(10)
totalEnergy += context.getState(getEnergy=True).getKineticEnergy()
averageEnergy = totalEnergy/steps
dofs = 3*system.getNumParticles() - system.getNumConstraints() - 3
temperature = averageEnergy*2/(dofs*MOLAR_GAS_CONSTANT_R)
self.assertTrue(290*kelvin < temperature < 310*kelvin)
def testNoseHooverIntegrator(self):
"""Test partial thermostating in the NoseHooverIntegrator (only API)"""
pdb = PDBFile('systems/alanine-dipeptide-explicit.pdb')
......
......@@ -32,6 +32,7 @@ class TestPatches(unittest.TestCase):
<AddExternalBond atomName="A"/>
<RemoveExternalBond atomName="C"/>
<ApplyToResidue name="RES"/>
<VirtualSite type="average2" siteName="A" atomName1="B" atomName2="B" weight1="0.8" weight2="0.2"/>
</Patch>
</Patches>
</ForceField>"""
......@@ -47,6 +48,7 @@ class TestPatches(unittest.TestCase):
self.assertEqual(1, len(patch.deletedBonds))
self.assertEqual(1, len(patch.addedExternalBonds))
self.assertEqual(1, len(patch.deletedExternalBonds))
self.assertEqual(1, len(patch.virtualSites))
self.assertEqual(1, len(ff._templatePatches))
self.assertEqual(1, len(ff._templatePatches['RES']))
self.assertEqual('A', patch.addedAtoms[0][0].name)
......@@ -67,6 +69,9 @@ class TestPatches(unittest.TestCase):
self.assertEqual(0, patch.addedExternalBonds[0].residue)
self.assertEqual('C', patch.deletedExternalBonds[0].name)
self.assertEqual(0, patch.deletedExternalBonds[0].residue)
self.assertEqual(0, patch.virtualSites[0][0].index)
self.assertEqual([1, 1], patch.virtualSites[0][0].atoms)
self.assertEqual([0.8, 0.2], patch.virtualSites[0][0].weights)
patch = list(ff._templatePatches['RES'])[0]
self.assertEqual('Test', patch[0])
self.assertEqual(0, patch[1])
......
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