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
fb13fc68
"serialization/vscode:/vscode.git/clone" did not exist on "7f1dd6a35e4b404959a2671c0931f25cb3f1882b"
Commit
fb13fc68
authored
Mar 29, 2013
by
Peter Eastman
Browse files
GromacsTopFile processes [pairs] lines correctly
parent
0f83704f
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
52 additions
and
2 deletions
+52
-2
wrappers/python/simtk/openmm/app/gromacstopfile.py
wrappers/python/simtk/openmm/app/gromacstopfile.py
+52
-2
No files found.
wrappers/python/simtk/openmm/app/gromacstopfile.py
View file @
fb13fc68
...
...
@@ -6,7 +6,7 @@ Simbios, the NIH National Center for Physics-Based Simulation of
Biological Structures at Stanford, funded under the NIH Roadmap for
Medical Research, grant U54 GM072970. See https://simtk.org.
Portions copyright (c) 2012 Stanford University and the Authors.
Portions copyright (c) 2012
-2013
Stanford University and the Authors.
Authors: Peter Eastman
Contributors:
...
...
@@ -58,6 +58,7 @@ class GromacsTopFile(object):
self
.
angles
=
[]
self
.
dihedrals
=
[]
self
.
exclusions
=
[]
self
.
pairs
=
[]
def
_processFile
(
self
,
file
):
append
=
''
...
...
@@ -144,6 +145,8 @@ class GromacsTopFile(object):
self
.
_processDihedral
(
line
)
elif
self
.
_currentCategory
==
'exclusions'
:
self
.
_processExclusion
(
line
)
elif
self
.
_currentCategory
==
'pairs'
:
self
.
_processPair
(
line
)
elif
self
.
_currentCategory
==
'atomtypes'
:
self
.
_processAtomType
(
line
)
elif
self
.
_currentCategory
==
'bondtypes'
:
...
...
@@ -154,6 +157,8 @@ class GromacsTopFile(object):
self
.
_processDihedralType
(
line
)
elif
self
.
_currentCategory
==
'implicit_genborn_params'
:
self
.
_processImplicitType
(
line
)
elif
self
.
_currentCategory
==
'pairtypes'
:
self
.
_processPairType
(
line
)
def
_processDefaults
(
self
,
line
):
"""Process the [ defaults ] line."""
...
...
@@ -235,6 +240,17 @@ class GromacsTopFile(object):
raise
ValueError
(
'Too few fields in [ exclusions ] line: '
+
line
);
self
.
_currentMoleculeType
.
exclusions
.
append
(
fields
)
def
_processPair
(
self
,
line
):
"""Process a line in the [ pairs ] category."""
if
self
.
_currentMoleculeType
is
None
:
raise
ValueError
(
'Found [ pairs ] section before [ moleculetype ]'
)
fields
=
line
.
split
()
if
len
(
fields
)
<
3
:
raise
ValueError
(
'Too few fields in [ pairs ] line: '
+
line
);
if
fields
[
2
]
!=
'1'
:
raise
ValueError
(
'Unsupported function type in [ pairs ] line: '
+
line
);
self
.
_currentMoleculeType
.
pairs
.
append
(
fields
)
def
_processAtomType
(
self
,
line
):
"""Process a line in the [ atomtypes ] category."""
fields
=
line
.
split
()
...
...
@@ -281,6 +297,15 @@ class GromacsTopFile(object):
raise
ValueError
(
'Too few fields in [ implicit_genborn_params ] line: '
+
line
);
self
.
_implicitTypes
[
fields
[
0
]]
=
fields
def
_processPairType
(
self
,
line
):
"""Process a line in the [ pairtypes ] category."""
fields
=
line
.
split
()
if
len
(
fields
)
<
5
:
raise
ValueError
(
'Too few fields in [ pairtypes] line: '
+
line
);
if
fields
[
2
]
!=
'1'
:
raise
ValueError
(
'Unsupported function type in [ pairtypes ] line: '
+
line
);
self
.
_pairTypes
[
fields
[
0
]]
=
fields
def
__init__
(
self
,
file
,
unitCellDimensions
=
None
,
includeDir
=
'/usr/local/gromacs/share/gromacs/top'
,
defines
=
{}):
"""Load a top file.
...
...
@@ -306,6 +331,7 @@ class GromacsTopFile(object):
self
.
_angleTypes
=
{}
self
.
_dihedralTypes
=
{}
self
.
_implicitTypes
=
{}
self
.
_pairTypes
=
{}
self
.
_processFile
(
file
)
# Create the Topology from it.
...
...
@@ -402,6 +428,8 @@ class GromacsTopFile(object):
rb
=
None
bondIndices
=
[]
topologyAtoms
=
list
(
self
.
topology
.
atoms
())
exceptions
=
[]
fudgeQQ
=
float
(
self
.
_defaults
[
4
])
# Loop over molecules and create the specified number of each type.
...
...
@@ -557,9 +585,31 @@ class GromacsTopFile(object):
atoms
=
[
int
(
x
)
-
1
for
x
in
fields
[:
2
]]
bondIndices
.
append
((
baseAtomIndex
+
atoms
[
0
],
baseAtomIndex
+
atoms
[
1
]))
# Record nonbonded exceptions.
for
fields
in
moleculeType
.
pairs
:
atoms
=
[
int
(
x
)
-
1
for
x
in
fields
[:
2
]]
types
=
tuple
(
atomTypes
[
i
]
for
i
in
atoms
)
if
len
(
fields
)
>=
5
:
params
=
fields
[
3
:
5
]
elif
types
in
self
.
_pairTypes
:
params
=
self
.
_pairTypes
[
types
][
3
:
5
]
elif
types
[::
-
1
]
in
self
.
_pairTypes
:
params
=
self
.
_pairTypes
[
types
[::
-
1
]][
3
:
5
]
else
:
continue
# We'll use the automatically generated parameters
atom1params
=
nb
.
getParticleParameters
(
baseAtomIndex
+
atoms
[
0
])
atom2params
=
nb
.
getParticleParameters
(
baseAtomIndex
+
atoms
[
1
])
exceptions
.
append
((
baseAtomIndex
+
atoms
[
0
],
baseAtomIndex
+
atoms
[
1
],
atom1params
[
0
]
*
atom2params
[
0
]
*
fudgeQQ
,
params
[
0
],
params
[
1
]))
# Create nonbonded exceptions.
nb
.
createExceptionsFromBonds
(
bondIndices
,
fudgeQQ
,
float
(
self
.
_defaults
[
3
]))
for
exception
in
exceptions
:
nb
.
addException
(
exception
[
0
],
exception
[
1
],
exception
[
2
],
float
(
exception
[
3
]),
float
(
exception
[
4
]),
True
)
# Finish configuring the NonbondedForce.
nb
.
createExceptionsFromBonds
(
bondIndices
,
float
(
self
.
_defaults
[
4
]),
float
(
self
.
_defaults
[
3
]))
methodMap
=
{
ff
.
NoCutoff
:
mm
.
NonbondedForce
.
NoCutoff
,
ff
.
CutoffNonPeriodic
:
mm
.
NonbondedForce
.
CutoffNonPeriodic
,
ff
.
CutoffPeriodic
:
mm
.
NonbondedForce
.
CutoffPeriodic
,
...
...
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