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
213c77eb
Commit
213c77eb
authored
Jul 21, 2014
by
peastman
Browse files
Merge pull request #548 from peastman/master
Created ForceField.loadFile()
parents
8db70d34
039b53b8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
42 deletions
+54
-42
wrappers/python/simtk/openmm/app/forcefield.py
wrappers/python/simtk/openmm/app/forcefield.py
+54
-42
No files found.
wrappers/python/simtk/openmm/app/forcefield.py
View file @
213c77eb
...
@@ -100,7 +100,7 @@ class ForceField(object):
...
@@ -100,7 +100,7 @@ class ForceField(object):
"""Load one or more XML files and create a ForceField object based on them.
"""Load one or more XML files and create a ForceField object based on them.
Parameters:
Parameters:
- files A list of XML files defining the force field. Each entry may
- files
(list)
A list of XML files defining the force field. Each entry may
be an absolute file path, a path relative to the current working
be an absolute file path, a path relative to the current working
directory, a path relative to this module's data subdirectory
directory, a path relative to this module's data subdirectory
(for built in force fields), or an open file-like object with a
(for built in force fields), or an open file-like object with a
...
@@ -113,47 +113,59 @@ class ForceField(object):
...
@@ -113,47 +113,59 @@ class ForceField(object):
self
.
_forces
=
[]
self
.
_forces
=
[]
self
.
_scripts
=
[]
self
.
_scripts
=
[]
for
file
in
files
:
for
file
in
files
:
try
:
self
.
loadFile
(
file
)
# this handles either filenames or open file-like objects
tree
=
etree
.
parse
(
file
)
def
loadFile
(
self
,
file
):
except
IOError
:
"""Load an XML file and add the definitions from it to this FieldField.
tree
=
etree
.
parse
(
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'data'
,
file
))
root
=
tree
.
getroot
()
Parameters:
- file (string or file) An XML file containing force field definitions. It may
# Load the atom types.
be either an absolute file path, a path relative to the current working
directory, a path relative to this module's data subdirectory
if
tree
.
getroot
().
find
(
'AtomTypes'
)
is
not
None
:
(for built in force fields), or an open file-like object with a
for
type
in
tree
.
getroot
().
find
(
'AtomTypes'
).
findall
(
'Type'
):
read() method from which the forcefield XML data can be loaded.
self
.
registerAtomType
(
type
.
attrib
)
"""
try
:
# Load the residue templates.
# this handles either filenames or open file-like objects
tree
=
etree
.
parse
(
file
)
if
tree
.
getroot
().
find
(
'Residues'
)
is
not
None
:
except
IOError
:
for
residue
in
root
.
find
(
'Residues'
).
findall
(
'Residue'
):
tree
=
etree
.
parse
(
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'data'
,
file
))
resName
=
residue
.
attrib
[
'name'
]
root
=
tree
.
getroot
()
template
=
ForceField
.
_TemplateData
(
resName
)
for
atom
in
residue
.
findall
(
'Atom'
):
# Load the atom types.
template
.
atoms
.
append
(
ForceField
.
_TemplateAtomData
(
atom
.
attrib
[
'name'
],
atom
.
attrib
[
'type'
],
self
.
_atomTypes
[
atom
.
attrib
[
'type'
]][
2
]))
for
site
in
residue
.
findall
(
'VirtualSite'
):
if
tree
.
getroot
().
find
(
'AtomTypes'
)
is
not
None
:
template
.
virtualSites
.
append
(
ForceField
.
_VirtualSiteData
(
site
))
for
type
in
tree
.
getroot
().
find
(
'AtomTypes'
).
findall
(
'Type'
):
for
bond
in
residue
.
findall
(
'Bond'
):
self
.
registerAtomType
(
type
.
attrib
)
template
.
addBond
(
int
(
bond
.
attrib
[
'from'
]),
int
(
bond
.
attrib
[
'to'
]))
for
bond
in
residue
.
findall
(
'ExternalBond'
):
# Load the residue templates.
b
=
int
(
bond
.
attrib
[
'from'
])
template
.
externalBonds
.
append
(
b
)
if
tree
.
getroot
().
find
(
'Residues'
)
is
not
None
:
template
.
atoms
[
b
].
externalBonds
+=
1
for
residue
in
root
.
find
(
'Residues'
).
findall
(
'Residue'
):
self
.
registerResidueTemplate
(
template
)
resName
=
residue
.
attrib
[
'name'
]
template
=
ForceField
.
_TemplateData
(
resName
)
# Load force definitions
for
atom
in
residue
.
findall
(
'Atom'
):
template
.
atoms
.
append
(
ForceField
.
_TemplateAtomData
(
atom
.
attrib
[
'name'
],
atom
.
attrib
[
'type'
],
self
.
_atomTypes
[
atom
.
attrib
[
'type'
]][
2
]))
for
child
in
root
:
for
site
in
residue
.
findall
(
'VirtualSite'
):
if
child
.
tag
in
parsers
:
template
.
virtualSites
.
append
(
ForceField
.
_VirtualSiteData
(
site
))
parsers
[
child
.
tag
](
child
,
self
)
for
bond
in
residue
.
findall
(
'Bond'
):
template
.
addBond
(
int
(
bond
.
attrib
[
'from'
]),
int
(
bond
.
attrib
[
'to'
]))
# Load scripts
for
bond
in
residue
.
findall
(
'ExternalBond'
):
b
=
int
(
bond
.
attrib
[
'from'
])
for
node
in
tree
.
getroot
().
findall
(
'Script'
):
template
.
externalBonds
.
append
(
b
)
self
.
registerScript
(
node
.
text
)
template
.
atoms
[
b
].
externalBonds
+=
1
self
.
registerResidueTemplate
(
template
)
# Load force definitions
for
child
in
root
:
if
child
.
tag
in
parsers
:
parsers
[
child
.
tag
](
child
,
self
)
# Load scripts
for
node
in
tree
.
getroot
().
findall
(
'Script'
):
self
.
registerScript
(
node
.
text
)
def
getGenerators
(
self
):
def
getGenerators
(
self
):
"""Get the list of all registered generators."""
"""Get the list of all registered generators."""
...
...
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