Unverified Commit 2eb2c464 authored by peastman's avatar peastman Committed by GitHub
Browse files

Merge pull request #1938 from peastman/includes

Improvement to processing of includes in force fields
parents b7fbe622 4111024b
...@@ -2959,12 +2959,6 @@ relative either to the directory containing the parent XML file (the one with ...@@ -2959,12 +2959,6 @@ relative either to the directory containing the parent XML file (the one with
the :code:`<Include>` tag) or the OpenMM data directory (the one containing the :code:`<Include>` tag) or the OpenMM data directory (the one containing
built in force fields). built in force fields).
The included file is fully processed before any other tags in the parent file
are processed, and its definitions are added to the force field. This means the
parent file can refer to atom types defined in the included file, but not the
other way around. If there are multiple :code:`<Include>` tags, they are processed
in the order they appear in the file.
Using Multiple Files Using Multiple Files
******************** ********************
......
...@@ -190,12 +190,16 @@ class ForceField(object): ...@@ -190,12 +190,16 @@ class ForceField(object):
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): if isinstance(files, tuple):
files = (files,) files = list(files)
else:
files = [files]
trees = [] trees = []
for file in files: i = 0
while i < len(files):
file = files[i]
tree = None tree = None
try: try:
# this handles either filenames or open file-like objects # this handles either filenames or open file-like objects
...@@ -221,12 +225,12 @@ class ForceField(object): ...@@ -221,12 +225,12 @@ class ForceField(object):
raise ValueError('Could not locate file "%s"' % file) raise ValueError('Could not locate file "%s"' % file)
trees.append(tree) trees.append(tree)
i += 1
# Process includes. # Process includes in this file.
for parentFile, tree in zip(files, trees): if isinstance(file, str):
if isinstance(parentFile, str): parentDir = os.path.dirname(file)
parentDir = os.path.dirname(parentFile)
else: else:
parentDir = '' parentDir = ''
for include in tree.getroot().findall('Include'): for include in tree.getroot().findall('Include'):
...@@ -234,7 +238,8 @@ class ForceField(object): ...@@ -234,7 +238,8 @@ class ForceField(object):
joined = os.path.join(parentDir, includeFile) joined = os.path.join(parentDir, includeFile)
if os.path.isfile(joined): if os.path.isfile(joined):
includeFile = joined includeFile = joined
self.loadFile(includeFile) if includeFile not in files:
files.append(includeFile)
# Load the atom types. # Load the atom types.
......
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