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
361db168
Commit
361db168
authored
Apr 17, 2017
by
peastman
Browse files
Defined entry point so other packages can add force field directories
parent
58c63b05
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
1 deletion
+15
-1
wrappers/python/simtk/openmm/app/forcefield.py
wrappers/python/simtk/openmm/app/forcefield.py
+15
-1
No files found.
wrappers/python/simtk/openmm/app/forcefield.py
View file @
361db168
...
@@ -46,6 +46,13 @@ import simtk.unit as unit
...
@@ -46,6 +46,13 @@ import simtk.unit as unit
from
.
import
element
as
elem
from
.
import
element
as
elem
from
simtk.openmm.app
import
Topology
from
simtk.openmm.app
import
Topology
from
simtk.openmm.app.internal.singleton
import
Singleton
from
simtk.openmm.app.internal.singleton
import
Singleton
from
pkg_resources
import
iter_entry_points
# Directories from which to load built in force fields.
_dataDirectories
=
[
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'data'
)]
for
entry
in
iter_entry_points
(
group
=
'openmm.forcefielddir'
):
_dataDirectories
.
append
(
entry
.
load
()())
def
_convertParameterToNumber
(
param
):
def
_convertParameterToNumber
(
param
):
if
unit
.
is_quantity
(
param
):
if
unit
.
is_quantity
(
param
):
...
@@ -186,11 +193,16 @@ class ForceField(object):
...
@@ -186,11 +193,16 @@ class ForceField(object):
trees
=
[]
trees
=
[]
for
file
in
files
:
for
file
in
files
:
tree
=
None
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
)
except
IOError
:
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
:
except
Exception
as
e
:
# Fail with an error message about which file could not be read.
# Fail with an error message about which file could not be read.
# TODO: Also handle case where fallback to 'data' directory encounters problems,
# TODO: Also handle case where fallback to 'data' directory encounters problems,
...
@@ -202,6 +214,8 @@ class ForceField(object):
...
@@ -202,6 +214,8 @@ class ForceField(object):
filename
=
str
(
file
)
filename
=
str
(
file
)
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
)
if
tree
is
None
:
raise
ValueError
(
'Could not locate file "%s"'
%
file
)
trees
.
append
(
tree
)
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