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
004db14a
Commit
004db14a
authored
Jan 28, 2016
by
Rafal P. Wiewiora
Browse files
read all ffxmls together by section, rather than all sections in one file first
parent
d2725cd3
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
71 additions
and
60 deletions
+71
-60
wrappers/python/simtk/openmm/app/forcefield.py
wrappers/python/simtk/openmm/app/forcefield.py
+71
-60
No files found.
wrappers/python/simtk/openmm/app/forcefield.py
View file @
004db14a
...
...
@@ -120,21 +120,27 @@ class ForceField(object):
self
.
_forces
=
[]
self
.
_scripts
=
[]
self
.
_templateGenerators
=
[]
for
file
in
files
:
self
.
loadFile
(
file
)
self
.
loadFile
(
files
)
def
loadFile
(
self
,
file
):
def
loadFile
(
self
,
file
s
):
"""Load an XML file and add the definitions from it to this ForceField.
Parameters
----------
file : string or file
An XML file containing force field definitions.
It may be either an
absolute file path, a path relative to the current working
file
s
: string or file
or tuple
An XML file
or tuple of XML files
containing force field definitions.
Each entry may be either an
absolute file path, a path relative to the current working
directory, a path relative to this module's data subdirectory (for
built in force fields), or an open file-like object with a read()
method from which the forcefield XML data can be loaded.
"""
if
not
isinstance
(
files
,
tuple
):
files
=
(
files
,)
trees
=
[]
for
file
in
files
:
try
:
# this handles either filenames or open file-like objects
tree
=
etree
.
parse
(
file
)
...
...
@@ -152,18 +158,21 @@ class ForceField(object):
msg
+=
"ForceField.loadFile() encountered an error reading file '%s'
\n
"
%
filename
raise
Exception
(
msg
)
root
=
tree
.
getroot
()
trees
.
append
(
tree
)
# Load the atom types.
for
tree
in
trees
:
if
tree
.
getroot
().
find
(
'AtomTypes'
)
is
not
None
:
for
type
in
tree
.
getroot
().
find
(
'AtomTypes'
).
findall
(
'Type'
):
self
.
registerAtomType
(
type
.
attrib
)
# Load the residue templates.
for
tree
in
trees
:
if
tree
.
getroot
().
find
(
'Residues'
)
is
not
None
:
for
residue
in
root
.
find
(
'Residues'
).
findall
(
'Residue'
):
for
residue
in
tree
.
get
root
()
.
find
(
'Residues'
).
findall
(
'Residue'
):
resName
=
residue
.
attrib
[
'name'
]
template
=
ForceField
.
_TemplateData
(
resName
)
atomIndices
=
{}
...
...
@@ -194,12 +203,14 @@ class ForceField(object):
# Load force definitions
for
child
in
root
:
for
tree
in
trees
:
for
child
in
tree
.
getroot
():
if
child
.
tag
in
parsers
:
parsers
[
child
.
tag
](
child
,
self
)
# Load scripts
for
tree
in
trees
:
for
node
in
tree
.
getroot
().
findall
(
'Script'
):
self
.
registerScript
(
node
.
text
)
...
...
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