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
9bce462d
Commit
9bce462d
authored
Jul 02, 2014
by
peastman
Browse files
Improved API for modifying ForceField
parent
e0cf53ba
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
19 deletions
+16
-19
wrappers/python/simtk/openmm/app/forcefield.py
wrappers/python/simtk/openmm/app/forcefield.py
+14
-17
wrappers/python/tests/TestForceField.py
wrappers/python/tests/TestForceField.py
+2
-2
No files found.
wrappers/python/simtk/openmm/app/forcefield.py
View file @
9bce462d
...
@@ -120,13 +120,7 @@ class ForceField(object):
...
@@ -120,13 +120,7 @@ class ForceField(object):
if
tree
.
getroot
().
find
(
'AtomTypes'
)
is
not
None
:
if
tree
.
getroot
().
find
(
'AtomTypes'
)
is
not
None
:
for
type
in
tree
.
getroot
().
find
(
'AtomTypes'
).
findall
(
'Type'
):
for
type
in
tree
.
getroot
().
find
(
'AtomTypes'
).
findall
(
'Type'
):
element
=
None
self
.
registerAtomType
(
type
.
attrib
)
if
'element'
in
type
.
attrib
:
element
=
elem
.
get_by_symbol
(
type
.
attrib
[
'element'
])
name
=
type
.
attrib
[
'name'
]
if
name
in
self
.
_atomTypes
:
raise
ValueError
(
'Found multiple definitions for atom type: '
+
name
)
self
.
registerAtomType
(
name
,
type
.
attrib
[
'class'
],
_convertParameterToNumber
(
type
.
attrib
[
'mass'
]),
element
)
# Load the residue templates.
# Load the residue templates.
...
@@ -165,16 +159,19 @@ class ForceField(object):
...
@@ -165,16 +159,19 @@ class ForceField(object):
"""Register a new generator."""
"""Register a new generator."""
self
.
_forces
.
append
(
generator
)
self
.
_forces
.
append
(
generator
)
def
registerAtomType
(
self
,
name
,
atomClass
,
mass
,
element
):
def
registerAtomType
(
self
,
parameters
):
"""Register a new atom type.
"""Register a new atom type."""
name
=
parameters
[
'name'
]
Parameters:
if
name
in
self
.
_atomTypes
:
- name (str) The name of the new atom type
raise
ValueError
(
'Found multiple definitions for atom type: '
+
name
)
- atomClass (str) The class of the new atom type
atomClass
=
parameters
[
'class'
]
- mass (mass) The atomic mass of the new atom type
mass
=
_convertParameterToNumber
(
parameters
[
'mass'
])
- element (element) The element of the new atom type
element
=
None
"""
if
'element'
in
parameters
:
self
.
_atomTypes
[
name
]
=
(
atomClass
,
_convertParameterToNumber
(
mass
),
element
)
element
=
parameters
[
'element'
]
if
not
isinstance
(
element
,
elem
.
Element
):
element
=
elem
.
get_by_symbol
(
element
)
self
.
_atomTypes
[
name
]
=
(
atomClass
,
mass
,
element
)
if
atomClass
in
self
.
_atomClasses
:
if
atomClass
in
self
.
_atomClasses
:
typeSet
=
self
.
_atomClasses
[
atomClass
]
typeSet
=
self
.
_atomClasses
[
atomClass
]
else
:
else
:
...
...
wrappers/python/tests/TestForceField.py
View file @
9bce462d
...
@@ -156,8 +156,8 @@ class TestForceField(unittest.TestCase):
...
@@ -156,8 +156,8 @@ class TestForceField(unittest.TestCase):
# Build the ForceField for TIP3P programmatically.
# Build the ForceField for TIP3P programmatically.
ff
=
ForceField
()
ff
=
ForceField
()
ff
.
registerAtomType
(
'tip3p-O'
,
'
OW'
,
15.99943
*
daltons
,
elem
.
oxygen
)
ff
.
registerAtomType
(
{
'name'
:
'tip3p-O'
,
'
class'
:
'OW'
,
'mass'
:
15.99943
*
daltons
,
'element'
:
elem
.
oxygen
}
)
ff
.
registerAtomType
(
'tip3p-H'
,
'
HW'
,
1.007947
*
daltons
,
elem
.
hydrogen
)
ff
.
registerAtomType
(
{
'name'
:
'tip3p-H'
,
'
class'
:
'HW'
,
'mass'
:
1.007947
*
daltons
,
'element'
:
elem
.
hydrogen
}
)
residue
=
ForceField
.
_TemplateData
(
'HOH'
)
residue
=
ForceField
.
_TemplateData
(
'HOH'
)
residue
.
atoms
.
append
(
ForceField
.
_TemplateAtomData
(
'O'
,
'tip3p-O'
,
elem
.
oxygen
))
residue
.
atoms
.
append
(
ForceField
.
_TemplateAtomData
(
'O'
,
'tip3p-O'
,
elem
.
oxygen
))
residue
.
atoms
.
append
(
ForceField
.
_TemplateAtomData
(
'H1'
,
'tip3p-H'
,
elem
.
hydrogen
))
residue
.
atoms
.
append
(
ForceField
.
_TemplateAtomData
(
'H1'
,
'tip3p-H'
,
elem
.
hydrogen
))
...
...
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