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
bfde67e9
Commit
bfde67e9
authored
Jun 05, 2025
by
Evan Pretti
Browse files
Handle relative includes and errors in force fields in data directories
parent
2b8ad703
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
10 deletions
+7
-10
wrappers/python/openmm/app/forcefield.py
wrappers/python/openmm/app/forcefield.py
+7
-10
No files found.
wrappers/python/openmm/app/forcefield.py
View file @
bfde67e9
...
@@ -245,20 +245,19 @@ class ForceField(object):
...
@@ -245,20 +245,19 @@ class ForceField(object):
i
=
0
i
=
0
while
i
<
len
(
files
):
while
i
<
len
(
files
):
file
=
files
[
i
]
file
=
files
[
i
]
tree
=
None
# this handles either filenames or open file-like objects
try
:
if
isinstance
(
file
,
str
)
and
not
os
.
path
.
isfile
(
file
):
# this handles either filenames or open file-like objects
tree
=
etree
.
parse
(
file
)
except
IOError
:
for
dataDir
in
_getDataDirectories
():
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
):
tre
e
=
etree
.
parse
(
f
)
fil
e
=
f
break
break
try
:
tree
=
etree
.
parse
(
file
)
except
FileNotFoundError
:
raise
ValueError
(
'Could not locate file "%s"'
%
file
)
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,
# but this is much less worrisome because we control those files.
msg
=
str
(
e
)
+
'
\n
'
msg
=
str
(
e
)
+
'
\n
'
if
hasattr
(
file
,
'name'
):
if
hasattr
(
file
,
'name'
):
filename
=
file
.
name
filename
=
file
.
name
...
@@ -266,8 +265,6 @@ class ForceField(object):
...
@@ -266,8 +265,6 @@ 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
)
i
+=
1
i
+=
1
...
...
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