Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
tsoc
openmm
Commits
792a9c07
Commit
792a9c07
authored
Apr 18, 2017
by
peastman
Committed by
GitHub
Apr 18, 2017
Browse files
Merge pull request #1789 from peastman/datadirs
Defined entry point so other packages can add force field directories
parents
58c63b05
d4341587
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
1 deletion
+18
-1
wrappers/python/simtk/openmm/app/forcefield.py
wrappers/python/simtk/openmm/app/forcefield.py
+18
-1
No files found.
wrappers/python/simtk/openmm/app/forcefield.py
View file @
792a9c07
...
...
@@ -47,6 +47,16 @@ from . import element as elem
from
simtk.openmm.app
import
Topology
from
simtk.openmm.app.internal.singleton
import
Singleton
# Directories from which to load built in force fields.
_dataDirectories
=
[
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'data'
)]
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
def
_convertParameterToNumber
(
param
):
if
unit
.
is_quantity
(
param
):
if
param
.
unit
.
is_compatible
(
unit
.
bar
):
...
...
@@ -186,11 +196,16 @@ class ForceField(object):
trees
=
[]
for
file
in
files
:
tree
=
None
try
:
# this handles either filenames or open file-like objects
tree
=
etree
.
parse
(
file
)
except
IOError
:
tree
=
etree
.
parse
(
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'data'
,
file
))
for
dataDir
in
_dataDirectories
:
f
=
os
.
path
.
join
(
dataDir
,
file
)
if
os
.
path
.
isfile
(
f
):
tree
=
etree
.
parse
(
f
)
break
except
Exception
as
e
:
# Fail with an error message about which file could not be read.
# TODO: Also handle case where fallback to 'data' directory encounters problems,
...
...
@@ -202,6 +217,8 @@ class ForceField(object):
filename
=
str
(
file
)
msg
+=
"ForceField.loadFile() encountered an error reading file '%s'
\n
"
%
filename
raise
Exception
(
msg
)
if
tree
is
None
:
raise
ValueError
(
'Could not locate file "%s"'
%
file
)
trees
.
append
(
tree
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment