Commit 8a6c98c2 authored by M J Harvey's avatar M J Harvey
Browse files

Add permissive flag to permit undefined atomtypes when reading charmm parameter files

parent 4b431ec2
...@@ -100,7 +100,7 @@ class CharmmParameterSet(object): ...@@ -100,7 +100,7 @@ class CharmmParameterSet(object):
except ValueError: except ValueError:
raise CharmmFileError('Could not convert %s to %s' % (msg, type)) raise CharmmFileError('Could not convert %s to %s' % (msg, type))
def __init__(self, *args): def __init__(self, *args, permissive=False):
# Instantiate the list types # Instantiate the list types
self.atom_types_str = dict() self.atom_types_str = dict()
self.atom_types_int = dict() self.atom_types_int = dict()
...@@ -136,11 +136,11 @@ class CharmmParameterSet(object): ...@@ -136,11 +136,11 @@ class CharmmParameterSet(object):
else: else:
raise TypeError('Unrecognized file type: %s' % arg) raise TypeError('Unrecognized file type: %s' % arg)
for top in tops: self.readTopologyFile(top) 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) for strf in strs: self.readStreamFile(strf)
@classmethod @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 Instantiates a CharmmParameterSet from a Topology file and a Parameter
file (or just a Parameter file if it has all information) file (or just a Parameter file if it has all information)
...@@ -149,6 +149,8 @@ class CharmmParameterSet(object): ...@@ -149,6 +149,8 @@ class CharmmParameterSet(object):
- tfile (str) : Name of the Topology (RTF/TOP) file - tfile (str) : Name of the Topology (RTF/TOP) file
- pfile (str) : Name of the Parameter (PAR) file - pfile (str) : Name of the Parameter (PAR) file
- sfiles (list of str) : List or tuple of stream (STR) file names. - 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: Returns:
New CharmmParameterSet populated with the parameters found in the New CharmmParameterSet populated with the parameters found in the
...@@ -165,7 +167,7 @@ class CharmmParameterSet(object): ...@@ -165,7 +167,7 @@ class CharmmParameterSet(object):
if tfile is not None: if tfile is not None:
inst.readTopologyFile(tfile) inst.readTopologyFile(tfile)
if pfile is not None: if pfile is not None:
inst.readParameterFile(pfile) inst.readParameterFile(pfile, permissive=permissive)
if isinstance(sfiles, str): if isinstance(sfiles, str):
# The API docstring requests a list, but allow for users to pass a # The API docstring requests a list, but allow for users to pass a
# string with a single filename instead # string with a single filename instead
...@@ -175,7 +177,7 @@ class CharmmParameterSet(object): ...@@ -175,7 +177,7 @@ class CharmmParameterSet(object):
inst.readStreamFile(sfile) inst.readStreamFile(sfile)
return inst return inst
def readParameterFile(self, pfile): def readParameterFile(self, pfile, permissive=False):
""" """
Reads all of the parameters from a parameter file. Versions 36 and Reads all of the parameters from a parameter file. Versions 36 and
later of the CHARMM force field files have an ATOMS section defining later of the CHARMM force field files have an ATOMS section defining
...@@ -184,6 +186,8 @@ class CharmmParameterSet(object): ...@@ -184,6 +186,8 @@ class CharmmParameterSet(object):
Parameters: Parameters:
- pfile (str) : Name of the CHARMM PARameter file to read - 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. 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 Either supply a PAR file with atom definitions in them or read in a
...@@ -477,6 +481,23 @@ class CharmmParameterSet(object): ...@@ -477,6 +481,23 @@ class CharmmParameterSet(object):
if current_cmap is not None: if current_cmap is not None:
ty = CmapType(current_cmap_res, current_cmap_data) ty = CmapType(current_cmap_res, current_cmap_data)
self.cmap_types[current_cmap] = ty 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 # Now we're done. Load the nonbonded types into the relevant AtomType
# instances. In order for this to work, all keys in nonbonded_types # 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 # must be in the self.atom_types_str dict. Raise a RuntimeError if this
...@@ -487,6 +508,7 @@ class CharmmParameterSet(object): ...@@ -487,6 +508,7 @@ class CharmmParameterSet(object):
except KeyError: except KeyError:
raise RuntimeError('Atom type %s not present in AtomType list' % raise RuntimeError('Atom type %s not present in AtomType list' %
key) key)
if parameterset is not None: self.parametersets.append(parameterset) if parameterset is not None: self.parametersets.append(parameterset)
if own_handle: f.close() if own_handle: f.close()
......
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