"platforms/cpu/vscode:/vscode.git/clone" did not exist on "b683cd81f19ce3aff97d17ba03bc9d1ec4e67fa4"
Commit 004db14a authored by Rafal P. Wiewiora's avatar Rafal P. Wiewiora
Browse files

read all ffxmls together by section, rather than all sections in one file first

parent d2725cd3
...@@ -120,21 +120,27 @@ class ForceField(object): ...@@ -120,21 +120,27 @@ class ForceField(object):
self._forces = [] self._forces = []
self._scripts = [] self._scripts = []
self._templateGenerators = [] self._templateGenerators = []
for file in files: self.loadFile(files)
self.loadFile(file)
def loadFile(self, file): def loadFile(self, files):
"""Load an XML file and add the definitions from it to this ForceField. """Load an XML file and add the definitions from it to this ForceField.
Parameters Parameters
---------- ----------
file : string or file files : string or file or tuple
An XML file containing force field definitions. It may be either an An XML file or tuple of XML files containing force field definitions.
absolute file path, a path relative to the current working Each entry may be either an absolute file path, a path relative to the current working
directory, a path relative to this module's data subdirectory (for directory, a path relative to this module's data subdirectory (for
built in force fields), or an open file-like object with a read() built in force fields), or an open file-like object with a read()
method from which the forcefield XML data can be loaded. method from which the forcefield XML data can be loaded.
""" """
if not isinstance(files, tuple):
files = (files,)
trees = []
for file in files:
try: try:
# this handles either filenames or open file-like objects # this handles either filenames or open file-like objects
tree = etree.parse(file) tree = etree.parse(file)
...@@ -152,18 +158,21 @@ class ForceField(object): ...@@ -152,18 +158,21 @@ class ForceField(object):
msg += "ForceField.loadFile() encountered an error reading file '%s'\n" % filename msg += "ForceField.loadFile() encountered an error reading file '%s'\n" % filename
raise Exception(msg) raise Exception(msg)
root = tree.getroot() trees.append(tree)
# Load the atom types. # Load the atom types.
for tree in trees:
if tree.getroot().find('AtomTypes') is not None: if tree.getroot().find('AtomTypes') is not None:
for type in tree.getroot().find('AtomTypes').findall('Type'): for type in tree.getroot().find('AtomTypes').findall('Type'):
self.registerAtomType(type.attrib) self.registerAtomType(type.attrib)
# Load the residue templates. # Load the residue templates.
for tree in trees:
if tree.getroot().find('Residues') is not None: if tree.getroot().find('Residues') is not None:
for residue in root.find('Residues').findall('Residue'): for residue in tree.getroot().find('Residues').findall('Residue'):
resName = residue.attrib['name'] resName = residue.attrib['name']
template = ForceField._TemplateData(resName) template = ForceField._TemplateData(resName)
atomIndices = {} atomIndices = {}
...@@ -194,12 +203,14 @@ class ForceField(object): ...@@ -194,12 +203,14 @@ class ForceField(object):
# Load force definitions # Load force definitions
for child in root: for tree in trees:
for child in tree.getroot():
if child.tag in parsers: if child.tag in parsers:
parsers[child.tag](child, self) parsers[child.tag](child, self)
# Load scripts # Load scripts
for tree in trees:
for node in tree.getroot().findall('Script'): for node in tree.getroot().findall('Script'):
self.registerScript(node.text) self.registerScript(node.text)
......
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