Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
tsoc
openmm
Commits
0b5d58d7
Commit
0b5d58d7
authored
May 27, 2020
by
Charlles Abreu
Browse files
Conflict resolution in TestSplineFilter.cpp
parents
9026dbe7
b0d13582
Changes
105
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
212 additions
and
3 deletions
+212
-3
wrappers/python/src/swig_doxygen/swig_lib/python/exceptions.i
...pers/python/src/swig_doxygen/swig_lib/python/exceptions.i
+9
-3
wrappers/python/tests/TestCharmmFiles.py
wrappers/python/tests/TestCharmmFiles.py
+135
-0
wrappers/python/tests/TestForceField.py
wrappers/python/tests/TestForceField.py
+28
-0
wrappers/python/tests/TestIntegrators.py
wrappers/python/tests/TestIntegrators.py
+35
-0
wrappers/python/tests/TestPatches.py
wrappers/python/tests/TestPatches.py
+5
-0
No files found.
wrappers/python/src/swig_doxygen/swig_lib/python/exceptions.i
View file @
0b5d58d7
...
...
@@ -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
)
;
...
...
wrappers/python/tests/TestCharmmFiles.py
View file @
0b5d58d7
...
...
@@ -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
()
...
...
wrappers/python/tests/TestForceField.py
View file @
0b5d58d7
...
...
@@ -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."""
...
...
wrappers/python/tests/TestIntegrators.py
View file @
0b5d58d7
...
...
@@ -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'
)
...
...
wrappers/python/tests/TestPatches.py
View file @
0b5d58d7
...
...
@@ -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
])
...
...
Prev
1
2
3
4
5
6
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment