"flash_mla/vscode:/vscode.git/clone" did not exist on "c353b35b3c90f8aeb684261d882f3c7975bb5d51"
Commit 92cde5ca authored by John Chodera (MSKCC)'s avatar John Chodera (MSKCC)
Browse files

Convert atom types from tuple to private inner class.

parent c55636e2
...@@ -113,7 +113,7 @@ class ForceField(object): ...@@ -113,7 +113,7 @@ class ForceField(object):
(for built in force fields), or an open file-like object with a (for built in force fields), or an open file-like object with a
read() method from which the forcefield XML data can be loaded. read() method from which the forcefield XML data can be loaded.
""" """
self._atomTypes = {} # self._atomTypes[typename] = (atomclass, mass, element) self._atomTypes = {} # self._atomTypes[typename] in an _AtomType object
self._templates = {} self._templates = {}
self._templateSignatures = {None:[]} self._templateSignatures = {None:[]}
self._atomClasses = {'':set()} self._atomClasses = {'':set()}
...@@ -176,7 +176,8 @@ class ForceField(object): ...@@ -176,7 +176,8 @@ class ForceField(object):
if atomName in atomIndices: if atomName in atomIndices:
raise ValueError('Residue '+resName+' contains multiple atoms named '+atomName) raise ValueError('Residue '+resName+' contains multiple atoms named '+atomName)
atomIndices[atomName] = len(template.atoms) atomIndices[atomName] = len(template.atoms)
template.atoms.append(ForceField._TemplateAtomData(atomName, atom.attrib['type'], self._atomTypes[atom.attrib['type']][2], params)) typeName = atom.attrib['type']
template.atoms.append(ForceField._TemplateAtomData(atomName, typeName, self._atomTypes[typeName].element, params))
for site in residue.findall('VirtualSite'): for site in residue.findall('VirtualSite'):
template.virtualSites.append(ForceField._VirtualSiteData(site, atomIndices)) template.virtualSites.append(ForceField._VirtualSiteData(site, atomIndices))
for bond in residue.findall('Bond'): for bond in residue.findall('Bond'):
...@@ -222,7 +223,7 @@ class ForceField(object): ...@@ -222,7 +223,7 @@ class ForceField(object):
element = parameters['element'] element = parameters['element']
if not isinstance(element, elem.Element): if not isinstance(element, elem.Element):
element = elem.get_by_symbol(element) element = elem.get_by_symbol(element)
self._atomTypes[name] = (atomClass, mass, element) self._atomTypes[name] = _AtomType(name, atomClass, mass, element)
if atomClass in self._atomClasses: if atomClass in self._atomClasses:
typeSet = self._atomClasses[atomClass] typeSet = self._atomClasses[atomClass]
else: else:
...@@ -439,6 +440,14 @@ class ForceField(object): ...@@ -439,6 +440,14 @@ class ForceField(object):
else: else:
self.excludeWith = self.atoms[0] self.excludeWith = self.atoms[0]
class _AtomType:
"""Inner class used to record atom types and associated properties."""
def __init__(self, name, atomClass, mass, element):
self.name = name
self.atomClass = atomClass
self.mass = mass
self.element = element
class _AtomTypeParameters: class _AtomTypeParameters:
"""Inner class used to record parameter values for atom types.""" """Inner class used to record parameter values for atom types."""
def __init__(self, forcefield, forceName, atomTag, paramNames): def __init__(self, forcefield, forceName, atomTag, paramNames):
...@@ -642,9 +651,7 @@ class ForceField(object): ...@@ -642,9 +651,7 @@ class ForceField(object):
msg = "Could not find typename '%s' for atom '%s' in list of known atom types.\n" % (typename, str(atom)) msg = "Could not find typename '%s' for atom '%s' in list of known atom types.\n" % (typename, str(atom))
msg += "Known atom types are: %s" % str(self._atomTypes.keys()) msg += "Known atom types are: %s" % str(self._atomTypes.keys())
raise Exception(msg) raise Exception(msg)
atomtype_data = self._atomTypes[typename] mass = self._atomTypes[typename].mass
mass = atomtype_data[1]
sys.addParticle(mass) sys.addParticle(mass)
# Adjust masses. # Adjust masses.
......
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