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
8a6c98c2
"openmmapi/vscode:/vscode.git/clone" did not exist on "cbd45dcac111308cb3af068c3844666e78918f09"
Commit
8a6c98c2
authored
Oct 06, 2015
by
M J Harvey
Browse files
Add permissive flag to permit undefined atomtypes when reading charmm parameter files
parent
4b431ec2
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
6 deletions
+28
-6
wrappers/python/simtk/openmm/app/charmmparameterset.py
wrappers/python/simtk/openmm/app/charmmparameterset.py
+28
-6
No files found.
wrappers/python/simtk/openmm/app/charmmparameterset.py
View file @
8a6c98c2
...
...
@@ -100,7 +100,7 @@ class CharmmParameterSet(object):
except
ValueError
:
raise
CharmmFileError
(
'Could not convert %s to %s'
%
(
msg
,
type
))
def
__init__
(
self
,
*
args
):
def
__init__
(
self
,
*
args
,
permissive
=
False
):
# Instantiate the list types
self
.
atom_types_str
=
dict
()
self
.
atom_types_int
=
dict
()
...
...
@@ -136,11 +136,11 @@ class CharmmParameterSet(object):
else
:
raise
TypeError
(
'Unrecognized file type: %s'
%
arg
)
for
top
in
tops
:
self
.
readTopologyFile
(
top
)
for
par
in
pars
:
self
.
readParameterFile
(
par
)
for
par
in
pars
:
self
.
readParameterFile
(
par
,
permissive
=
self
.
permissive
)
for
strf
in
strs
:
self
.
readStreamFile
(
strf
)
@
classmethod
def
loadSet
(
cls
,
tfile
=
None
,
pfile
=
None
,
sfiles
=
[]):
def
loadSet
(
cls
,
tfile
=
None
,
pfile
=
None
,
sfiles
=
[]
,
permissive
=
False
):
"""
Instantiates a CharmmParameterSet from a Topology file and a Parameter
file (or just a Parameter file if it has all information)
...
...
@@ -149,6 +149,8 @@ class CharmmParameterSet(object):
- tfile (str) : Name of the Topology (RTF/TOP) file
- pfile (str) : Name of the Parameter (PAR) file
- sfiles (list of str) : List or tuple of stream (STR) file names.
- permissive (bool) : Accept non-bonbded parameters for undefined
atom types (default False)
Returns:
New CharmmParameterSet populated with the parameters found in the
...
...
@@ -165,7 +167,7 @@ class CharmmParameterSet(object):
if
tfile
is
not
None
:
inst
.
readTopologyFile
(
tfile
)
if
pfile
is
not
None
:
inst
.
readParameterFile
(
pfile
)
inst
.
readParameterFile
(
pfile
,
permissive
=
permissive
)
if
isinstance
(
sfiles
,
str
):
# The API docstring requests a list, but allow for users to pass a
# string with a single filename instead
...
...
@@ -175,7 +177,7 @@ class CharmmParameterSet(object):
inst
.
readStreamFile
(
sfile
)
return
inst
def
readParameterFile
(
self
,
pfile
):
def
readParameterFile
(
self
,
pfile
,
permissive
=
False
):
"""
Reads all of the parameters from a parameter file. Versions 36 and
later of the CHARMM force field files have an ATOMS section defining
...
...
@@ -184,6 +186,8 @@ class CharmmParameterSet(object):
Parameters:
- pfile (str) : Name of the CHARMM PARameter file to read
- permissive (bool) : Accept non-bonbded parameters for undefined
atom types (default False)
Notes: The atom types must all be loaded by the end of this routine.
Either supply a PAR file with atom definitions in them or read in a
...
...
@@ -477,6 +481,23 @@ class CharmmParameterSet(object):
if
current_cmap
is
not
None
:
ty
=
CmapType
(
current_cmap_res
,
current_cmap_data
)
self
.
cmap_types
[
current_cmap
]
=
ty
# If in permissive mode create an atomtype for every type used in
# the nonbonded parameters. This is a work-around for when all that's
# available is a CHARMM22 inp file, which has no ATOM/MASS fields
if
permissive
:
try
:
idx
=
max
(
self
.
atom_types_int
.
keys
())
+
1000
except
:
idx
=
10000
for
key
in
nonbonded_types
:
if
not
key
in
self
.
atom_types_str
:
atype
=
AtomType
(
name
=
key
,
number
=
idx
,
mass
=
float
(
'NaN'
),
atomic_number
=
1
)
self
.
atom_types_str
[
key
]
=
atype
self
.
atom_types_int
[
key
]
=
atype
idx
=
idx
+
1
# Now we're done. Load the nonbonded types into the relevant AtomType
# instances. In order for this to work, all keys in nonbonded_types
# must be in the self.atom_types_str dict. Raise a RuntimeError if this
...
...
@@ -487,6 +508,7 @@ class CharmmParameterSet(object):
except
KeyError
:
raise
RuntimeError
(
'Atom type %s not present in AtomType list'
%
key
)
if
parameterset
is
not
None
:
self
.
parametersets
.
append
(
parameterset
)
if
own_handle
:
f
.
close
()
...
...
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