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
7b767ce4
Commit
7b767ce4
authored
Jan 02, 2016
by
John Chodera (MSKCC)
Browse files
Add more informative error message when loading ffxml file fails.
parent
3244fecf
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
14 deletions
+26
-14
wrappers/python/simtk/openmm/app/forcefield.py
wrappers/python/simtk/openmm/app/forcefield.py
+13
-1
wrappers/python/tests/TestForceField.py
wrappers/python/tests/TestForceField.py
+13
-13
No files found.
wrappers/python/simtk/openmm/app/forcefield.py
View file @
7b767ce4
...
...
@@ -124,7 +124,7 @@ class ForceField(object):
self
.
loadFile
(
file
)
def
loadFile
(
self
,
file
):
"""Load an XML file and add the definitions from it to this F
ield
Field.
"""Load an XML file and add the definitions from it to this F
orce
Field.
Parameters
----------
...
...
@@ -140,6 +140,18 @@ class ForceField(object):
tree
=
etree
.
parse
(
file
)
except
IOError
:
tree
=
etree
.
parse
(
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'data'
,
file
))
except
Exception
as
e
:
# Fail with a more useful 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
'
if
hasattr
(
file
,
'close'
):
filename
=
file
.
name
else
:
filename
=
file
msg
+=
'ForceField.loadFile() encountered an error reading file: %s'
%
filename
raise
Exception
(
msg
)
root
=
tree
.
getroot
()
# Load the atom types.
...
...
wrappers/python/tests/TestForceField.py
View file @
7b767ce4
...
...
@@ -293,20 +293,20 @@ class TestForceField(unittest.TestCase):
# Define forcefield parameters used by simpleTemplateGenerator.
# NOTE: This parameter definition file will currently only work for residues that either have
# no external bonds or external bonds to other residues parameterized by the simpleTemplateGenerator.
simple_ffxml_contents
=
"""
simple_ffxml_contents
=
"""
\
<ForceField>
<AtomTypes>
<Type name="XXX" class="XXX" element="C" mass="12"/>
</AtomTypes>
<HarmonicBondForce>
<Bond type1="XXX" type2="XXX" length="0.1409" k="392459.2"/>
</HarmonicBondForce>
<HarmonicAngleForce>
<Angle type1="XXX" type2="XXX" type3="XXX" angle="2.09439510239" k="527.184"/>
</HarmonicAngleForce>
<NonbondedForce coulomb14scale="0.833333" lj14scale="0.5">
<Atom type="XXX" charge="0.000" sigma="0.315" epsilon="0.635"/>
</NonbondedForce>
<AtomTypes>
<Type name="XXX" class="XXX" element="C" mass="12"/>
</AtomTypes>
<HarmonicBondForce>
<Bond type1="XXX" type2="XXX" length="0.1409" k="392459.2"/>
</HarmonicBondForce>
<HarmonicAngleForce>
<Angle type1="XXX" type2="XXX" type3="XXX" angle="2.09439510239" k="527.184"/>
</HarmonicAngleForce>
<NonbondedForce coulomb14scale="0.833333" lj14scale="0.5">
<Atom type="XXX" charge="0.000" sigma="0.315" epsilon="0.635"/>
</NonbondedForce>
</ForceField>"""
simple_ffxml
=
StringIO
(
simple_ffxml_contents
)
...
...
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