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