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
e25f5acf
Commit
e25f5acf
authored
Mar 19, 2015
by
peastman
Browse files
Merge pull request #856 from swails/fix_hangles
Fix HAngles with Amber prmtop files
parents
2762adf4
aba4c054
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
6167 additions
and
27 deletions
+6167
-27
wrappers/python/simtk/openmm/app/amberprmtopfile.py
wrappers/python/simtk/openmm/app/amberprmtopfile.py
+2
-3
wrappers/python/simtk/openmm/app/internal/amber_file_parser.py
...ers/python/simtk/openmm/app/internal/amber_file_parser.py
+28
-24
wrappers/python/tests/TestAmberPrmtopFile.py
wrappers/python/tests/TestAmberPrmtopFile.py
+19
-0
wrappers/python/tests/systems/gaffwat.parm7
wrappers/python/tests/systems/gaffwat.parm7
+6118
-0
No files found.
wrappers/python/simtk/openmm/app/amberprmtopfile.py
View file @
e25f5acf
...
@@ -73,9 +73,8 @@ class AmberPrmtopFile(object):
...
@@ -73,9 +73,8 @@ class AmberPrmtopFile(object):
def
__init__
(
self
,
file
):
def
__init__
(
self
,
file
):
"""Load a prmtop file."""
"""Load a prmtop file."""
top
=
Topology
()
## The Topology read from the prmtop file
## The Topology read from the prmtop file
self
.
topology
=
top
self
.
topology
=
top
=
Topology
()
self
.
elements
=
[]
self
.
elements
=
[]
# Load the prmtop file
# Load the prmtop file
...
@@ -229,7 +228,7 @@ class AmberPrmtopFile(object):
...
@@ -229,7 +228,7 @@ class AmberPrmtopFile(object):
elif
implicitSolvent
is
None
:
elif
implicitSolvent
is
None
:
implicitSolventKappa
=
0.0
implicitSolventKappa
=
0.0
sys
=
amber_file_parser
.
readAmberSystem
(
prmtop_loader
=
self
.
_prmtop
,
shake
=
constraintString
,
sys
=
amber_file_parser
.
readAmberSystem
(
self
.
topology
,
prmtop_loader
=
self
.
_prmtop
,
shake
=
constraintString
,
nonbondedCutoff
=
nonbondedCutoff
,
nonbondedMethod
=
methodMap
[
nonbondedMethod
],
nonbondedCutoff
=
nonbondedCutoff
,
nonbondedMethod
=
methodMap
[
nonbondedMethod
],
flexibleConstraints
=
False
,
gbmodel
=
implicitString
,
soluteDielectric
=
soluteDielectric
,
flexibleConstraints
=
False
,
gbmodel
=
implicitString
,
soluteDielectric
=
soluteDielectric
,
solventDielectric
=
solventDielectric
,
implicitSolventKappa
=
implicitSolventKappa
,
solventDielectric
=
solventDielectric
,
implicitSolventKappa
=
implicitSolventKappa
,
...
...
wrappers/python/simtk/openmm/app/internal/amber_file_parser.py
View file @
e25f5acf
...
@@ -122,21 +122,22 @@ class PrmtopLoader(object):
...
@@ -122,21 +122,22 @@ class PrmtopLoader(object):
with
open
(
inFilename
,
'r'
)
as
fIn
:
with
open
(
inFilename
,
'r'
)
as
fIn
:
for
line
in
fIn
:
for
line
in
fIn
:
if
line
.
startswith
(
'%VERSION'
):
if
line
[
0
]
==
'%'
:
tag
,
self
.
_prmtopVersion
=
line
.
rstrip
().
split
(
None
,
1
)
if
line
.
startswith
(
'%VERSION'
):
elif
line
.
startswith
(
'%FLAG'
):
tag
,
self
.
_prmtopVersion
=
line
.
rstrip
().
split
(
None
,
1
)
tag
,
flag
=
line
.
rstrip
().
split
(
None
,
1
)
elif
line
.
startswith
(
'%FLAG'
):
self
.
_flags
.
append
(
flag
)
tag
,
flag
=
line
.
rstrip
().
split
(
None
,
1
)
self
.
_raw_data
[
flag
]
=
[]
self
.
_flags
.
append
(
flag
)
elif
line
.
startswith
(
'%FORMAT'
):
self
.
_raw_data
[
flag
]
=
[]
format
=
line
.
rstrip
()
elif
line
.
startswith
(
'%FORMAT'
):
index0
=
format
.
index
(
'('
)
format
=
line
.
rstrip
()
index1
=
format
.
index
(
')'
)
index0
=
format
.
index
(
'('
)
format
=
format
[
index0
+
1
:
index1
]
index1
=
format
.
index
(
')'
)
m
=
FORMAT_RE_PATTERN
.
search
(
format
)
format
=
format
[
index0
+
1
:
index1
]
self
.
_raw_format
[
self
.
_flags
[
-
1
]]
=
(
format
,
m
.
group
(
1
),
m
.
group
(
2
),
m
.
group
(
3
),
m
.
group
(
4
))
m
=
FORMAT_RE_PATTERN
.
search
(
format
)
elif
line
.
startswith
(
'%COMMENT'
):
self
.
_raw_format
[
self
.
_flags
[
-
1
]]
=
(
format
,
m
.
group
(
1
),
m
.
group
(
2
),
int
(
m
.
group
(
3
)),
m
.
group
(
4
))
continue
elif
line
.
startswith
(
'%COMMENT'
):
continue
elif
self
.
_flags
\
elif
self
.
_flags
\
and
'TITLE'
==
self
.
_flags
[
-
1
]
\
and
'TITLE'
==
self
.
_flags
[
-
1
]
\
and
not
self
.
_raw_data
[
'TITLE'
]:
and
not
self
.
_raw_data
[
'TITLE'
]:
...
@@ -144,8 +145,7 @@ class PrmtopLoader(object):
...
@@ -144,8 +145,7 @@ class PrmtopLoader(object):
else
:
else
:
flag
=
self
.
_flags
[
-
1
]
flag
=
self
.
_flags
[
-
1
]
(
format
,
numItems
,
itemType
,
(
format
,
numItems
,
itemType
,
itemLength
,
itemPrecision
)
=
self
.
_getFormat
(
flag
)
iLength
,
itemPrecision
)
=
self
.
_getFormat
(
flag
)
iLength
=
int
(
itemLength
)
line
=
line
.
rstrip
()
line
=
line
.
rstrip
()
for
index
in
range
(
0
,
len
(
line
),
iLength
):
for
index
in
range
(
0
,
len
(
line
),
iLength
):
item
=
line
[
index
:
index
+
iLength
]
item
=
line
[
index
:
index
+
iLength
]
...
@@ -651,7 +651,7 @@ class PrmtopLoader(object):
...
@@ -651,7 +651,7 @@ class PrmtopLoader(object):
# AMBER System builder (based on, but not identical to, systemManager from 'zander')
# AMBER System builder (based on, but not identical to, systemManager from 'zander')
#=============================================================================================
#=============================================================================================
def
readAmberSystem
(
prmtop_filename
=
None
,
prmtop_loader
=
None
,
shake
=
None
,
gbmodel
=
None
,
def
readAmberSystem
(
topology
,
prmtop_filename
=
None
,
prmtop_loader
=
None
,
shake
=
None
,
gbmodel
=
None
,
soluteDielectric
=
1.0
,
solventDielectric
=
78.5
,
soluteDielectric
=
1.0
,
solventDielectric
=
78.5
,
implicitSolventKappa
=
0.0
*
(
1
/
units
.
nanometer
),
nonbondedCutoff
=
None
,
implicitSolventKappa
=
0.0
*
(
1
/
units
.
nanometer
),
nonbondedCutoff
=
None
,
nonbondedMethod
=
'NoCutoff'
,
scee
=
None
,
scnb
=
None
,
mm
=
None
,
verbose
=
False
,
nonbondedMethod
=
'NoCutoff'
,
scee
=
None
,
scnb
=
None
,
mm
=
None
,
verbose
=
False
,
...
@@ -659,6 +659,9 @@ def readAmberSystem(prmtop_filename=None, prmtop_loader=None, shake=None, gbmode
...
@@ -659,6 +659,9 @@ def readAmberSystem(prmtop_filename=None, prmtop_loader=None, shake=None, gbmode
"""
"""
Create an OpenMM System from an Amber prmtop file.
Create an OpenMM System from an Amber prmtop file.
REQUIRED ARGUMENT
topology (forcefield.Topology) The topology for the system that is about
to be created
ARGUMENTS (specify one or the other, but not both)
ARGUMENTS (specify one or the other, but not both)
prmtop_filename (String) - name of Amber prmtop file (new-style only)
prmtop_filename (String) - name of Amber prmtop file (new-style only)
prmtop_loader (PrmtopLoader) - the loaded prmtop file
prmtop_loader (PrmtopLoader) - the loaded prmtop file
...
@@ -739,7 +742,7 @@ def readAmberSystem(prmtop_filename=None, prmtop_loader=None, shake=None, gbmode
...
@@ -739,7 +742,7 @@ def readAmberSystem(prmtop_filename=None, prmtop_loader=None, shake=None, gbmode
system
.
addParticle
(
mass
)
system
.
addParticle
(
mass
)
# Add constraints.
# Add constraints.
isWater
=
[
prmtop
.
getResidueLabel
(
i
)
in
(
'WAT'
,
'TP4'
,
'TP5'
,
'T4E'
)
for
i
in
range
(
prmtop
.
getNumAtoms
())]
isWater
=
[
prmtop
.
getResidueLabel
(
i
)
in
(
'WAT'
,
'HOH'
,
'TP4'
,
'TP5'
,
'T4E'
)
for
i
in
range
(
prmtop
.
getNumAtoms
())]
if
shake
in
(
'h-bonds'
,
'all-bonds'
,
'h-angles'
):
if
shake
in
(
'h-bonds'
,
'all-bonds'
,
'h-angles'
):
for
(
iAtom
,
jAtom
,
k
,
rMin
)
in
prmtop
.
getBondsWithH
():
for
(
iAtom
,
jAtom
,
k
,
rMin
)
in
prmtop
.
getBondsWithH
():
system
.
addConstraint
(
iAtom
,
jAtom
,
rMin
)
system
.
addConstraint
(
iAtom
,
jAtom
,
rMin
)
...
@@ -774,13 +777,14 @@ def readAmberSystem(prmtop_filename=None, prmtop_loader=None, shake=None, gbmode
...
@@ -774,13 +777,14 @@ def readAmberSystem(prmtop_filename=None, prmtop_loader=None, shake=None, gbmode
distance
=
c
[
2
].
value_in_unit
(
units
.
nanometer
)
distance
=
c
[
2
].
value_in_unit
(
units
.
nanometer
)
atomConstraints
[
c
[
0
]].
append
((
c
[
1
],
distance
))
atomConstraints
[
c
[
0
]].
append
((
c
[
1
],
distance
))
atomConstraints
[
c
[
1
]].
append
((
c
[
0
],
distance
))
atomConstraints
[
c
[
1
]].
append
((
c
[
0
],
distance
))
topatoms
=
list
(
topology
.
atoms
())
for
(
iAtom
,
jAtom
,
kAtom
,
k
,
aMin
)
in
prmtop
.
getAngles
():
for
(
iAtom
,
jAtom
,
kAtom
,
k
,
aMin
)
in
prmtop
.
getAngles
():
if
shake
==
'h-angles'
:
if
shake
==
'h-angles'
:
type1
=
prmtop
.
getAtomType
(
iAtom
)
atomI
=
topatoms
[
iAtom
]
type2
=
prmtop
.
getAtomType
(
jAtom
)
atomJ
=
topatoms
[
jAtom
]
type3
=
prmtop
.
getAtomType
(
kAtom
)
atomK
=
topatoms
[
kAtom
]
numH
=
len
([
type
for
type
in
(
type1
,
type3
)
if
type
.
startswith
(
'H'
)]
)
numH
=
((
atomI
.
element
.
atomic_number
==
1
)
+
(
atomK
.
element
.
atomic_number
==
1
)
)
constrained
=
(
numH
==
2
or
(
numH
==
1
and
type2
.
startswith
(
'O'
)
))
constrained
=
(
numH
==
2
or
(
numH
==
1
and
atomJ
.
element
is
elem
.
oxygen
))
else
:
else
:
constrained
=
False
constrained
=
False
if
constrained
:
if
constrained
:
...
...
wrappers/python/tests/TestAmberPrmtopFile.py
View file @
e25f5acf
...
@@ -12,6 +12,7 @@ prmtop2 = AmberPrmtopFile('systems/alanine-dipeptide-implicit.prmtop')
...
@@ -12,6 +12,7 @@ prmtop2 = AmberPrmtopFile('systems/alanine-dipeptide-implicit.prmtop')
prmtop3
=
AmberPrmtopFile
(
'systems/ff14ipq.parm7'
)
prmtop3
=
AmberPrmtopFile
(
'systems/ff14ipq.parm7'
)
prmtop4
=
AmberPrmtopFile
(
'systems/Mg_water.prmtop'
)
prmtop4
=
AmberPrmtopFile
(
'systems/Mg_water.prmtop'
)
prmtop5
=
AmberPrmtopFile
(
'systems/tz2.truncoct.parm7'
)
prmtop5
=
AmberPrmtopFile
(
'systems/tz2.truncoct.parm7'
)
prmtop6
=
AmberPrmtopFile
(
'systems/gaffwat.parm7'
)
inpcrd3
=
AmberInpcrdFile
(
'systems/ff14ipq.rst7'
)
inpcrd3
=
AmberInpcrdFile
(
'systems/ff14ipq.rst7'
)
inpcrd4
=
AmberInpcrdFile
(
'systems/Mg_water.inpcrd'
)
inpcrd4
=
AmberInpcrdFile
(
'systems/Mg_water.inpcrd'
)
...
@@ -200,6 +201,24 @@ class TestAmberPrmtopFile(unittest.TestCase):
...
@@ -200,6 +201,24 @@ class TestAmberPrmtopFile(unittest.TestCase):
# Amber using this force field.
# Amber using this force field.
self
.
assertAlmostEqual
(
-
7042.3903307
/
ene
,
1
,
places
=
3
)
self
.
assertAlmostEqual
(
-
7042.3903307
/
ene
,
1
,
places
=
3
)
def
test_HAngle
(
self
):
""" Test that HAngle constraints are properly handled for all hydrogens """
system
=
prmtop6
.
createSystem
(
nonbondedMethod
=
PME
,
nonbondedCutoff
=
1
*
nanometers
,
constraints
=
HBonds
)
self
.
assertEqual
(
system
.
getForce
(
0
).
getNumBonds
(),
0
)
self
.
assertEqual
(
system
.
getNumParticles
(),
3000
)
self
.
assertEqual
(
system
.
getNumConstraints
(),
2000
)
self
.
assertEqual
(
system
.
getForce
(
1
).
getNumAngles
(),
1000
)
system
=
prmtop6
.
createSystem
(
nonbondedMethod
=
PME
,
nonbondedCutoff
=
1
*
nanometers
,
constraints
=
HAngles
)
self
.
assertEqual
(
system
.
getForce
(
0
).
getNumBonds
(),
0
)
self
.
assertEqual
(
system
.
getNumParticles
(),
3000
)
self
.
assertEqual
(
system
.
getNumConstraints
(),
3000
)
self
.
assertEqual
(
system
.
getForce
(
1
).
getNumAngles
(),
0
)
def
test_LJ1264
(
self
):
def
test_LJ1264
(
self
):
"""Test prmtop with 12-6-4 vdW potential implemented"""
"""Test prmtop with 12-6-4 vdW potential implemented"""
system
=
prmtop4
.
createSystem
(
nonbondedMethod
=
PME
,
system
=
prmtop4
.
createSystem
(
nonbondedMethod
=
PME
,
...
...
wrappers/python/tests/systems/gaffwat.parm7
0 → 100644
View file @
e25f5acf
This diff is collapsed.
Click to expand it.
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