Unverified Commit 6f1db1fb authored by peastman's avatar peastman Committed by GitHub
Browse files

Merge pull request #2054 from peastman/forcefielddir

Improved behavior of adding force field directories
parents 72def6fb ac27d6b7
...@@ -6,7 +6,7 @@ Simbios, the NIH National Center for Physics-Based Simulation of ...@@ -6,7 +6,7 @@ Simbios, the NIH National Center for Physics-Based Simulation of
Biological Structures at Stanford, funded under the NIH Roadmap for Biological Structures at Stanford, funded under the NIH Roadmap for
Medical Research, grant U54 GM072970. See https://simtk.org. Medical Research, grant U54 GM072970. See https://simtk.org.
Portions copyright (c) 2012-2017 Stanford University and the Authors. Portions copyright (c) 2012-2018 Stanford University and the Authors.
Authors: Peter Eastman, Mark Friedrichs Authors: Peter Eastman, Mark Friedrichs
Contributors: Contributors:
...@@ -49,13 +49,19 @@ from simtk.openmm.app.internal.singleton import Singleton ...@@ -49,13 +49,19 @@ from simtk.openmm.app.internal.singleton import Singleton
# Directories from which to load built in force fields. # Directories from which to load built in force fields.
_dataDirectories = [os.path.join(os.path.dirname(__file__), 'data')] _dataDirectories = None
try:
from pkg_resources import iter_entry_points def _getDataDirectories():
for entry in iter_entry_points(group='openmm.forcefielddir'): global _dataDirectories
_dataDirectories.append(entry.load()()) if _dataDirectories is None:
except: _dataDirectories = [os.path.join(os.path.dirname(__file__), 'data')]
pass # pkg_resources is not installed try:
from pkg_resources import iter_entry_points
for entry in iter_entry_points(group='openmm.forcefielddir'):
_dataDirectories.append(entry.load()())
except:
pass # pkg_resources is not installed
return _dataDirectories
def _convertParameterToNumber(param): def _convertParameterToNumber(param):
if unit.is_quantity(param): if unit.is_quantity(param):
...@@ -205,7 +211,7 @@ class ForceField(object): ...@@ -205,7 +211,7 @@ class ForceField(object):
# 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)
except IOError: except IOError:
for dataDir in _dataDirectories: for dataDir in _getDataDirectories():
f = os.path.join(dataDir, file) f = os.path.join(dataDir, file)
if os.path.isfile(f): if os.path.isfile(f):
tree = etree.parse(f) tree = etree.parse(f)
......
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