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
032c0498
"wrappers/python/vscode:/vscode.git/clone" did not exist on "b7088b74013784d6bad5d5a27923974bfacdaaea"
Commit
032c0498
authored
Feb 18, 2019
by
tic20
Browse files
simple optimization to ForceField class
parent
bd788d90
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
15 deletions
+20
-15
wrappers/python/simtk/openmm/app/forcefield.py
wrappers/python/simtk/openmm/app/forcefield.py
+20
-15
No files found.
wrappers/python/simtk/openmm/app/forcefield.py
View file @
032c0498
...
@@ -263,17 +263,17 @@ class ForceField(object):
...
@@ -263,17 +263,17 @@ class ForceField(object):
template
=
ForceField
.
_TemplateData
(
resName
)
template
=
ForceField
.
_TemplateData
(
resName
)
if
'override'
in
residue
.
attrib
:
if
'override'
in
residue
.
attrib
:
template
.
overrideLevel
=
int
(
residue
.
attrib
[
'override'
])
template
.
overrideLevel
=
int
(
residue
.
attrib
[
'override'
])
atomIndices
=
{}
atomIndices
=
template
.
atomIndices
for
atom
in
residue
.
findall
(
'Atom'
):
for
ia
,
atom
in
enumerate
(
residue
.
findall
(
'Atom'
)
)
:
params
=
{}
params
=
{}
for
key
in
atom
.
attrib
:
a_attrib
=
atom
.
attrib
if
key
not
in
(
'name'
,
'type'
):
atomName
=
a_attrib
.
pop
(
'name'
)
params
[
key
]
=
_convertParameterToNumber
(
atom
.
attrib
[
key
])
atomName
=
atom
.
attrib
[
'name'
]
if
atomName
in
atomIndices
:
if
atomName
in
atomIndices
:
raise
ValueError
(
'Residue '
+
resName
+
' contains multiple atoms named '
+
atomName
)
raise
ValueError
(
'Residue '
+
resName
+
' contains multiple atoms named '
+
atomName
)
atomIndices
[
atomName
]
=
len
(
template
.
atoms
)
typeName
=
a_attrib
.
pop
(
'type'
)
typeName
=
atom
.
attrib
[
'type'
]
for
key
in
atom
.
attrib
:
params
[
key
]
=
_convertParameterToNumber
(
atom
.
attrib
[
key
])
atomIndices
[
atomName
]
=
ia
template
.
atoms
.
append
(
ForceField
.
_TemplateAtomData
(
atomName
,
typeName
,
self
.
_atomTypes
[
typeName
].
element
,
params
))
template
.
atoms
.
append
(
ForceField
.
_TemplateAtomData
(
atomName
,
typeName
,
self
.
_atomTypes
[
typeName
].
element
,
params
))
for
site
in
residue
.
findall
(
'VirtualSite'
):
for
site
in
residue
.
findall
(
'VirtualSite'
):
template
.
virtualSites
.
append
(
ForceField
.
_VirtualSiteData
(
site
,
atomIndices
))
template
.
virtualSites
.
append
(
ForceField
.
_VirtualSiteData
(
site
,
atomIndices
))
...
@@ -588,6 +588,7 @@ class ForceField(object):
...
@@ -588,6 +588,7 @@ class ForceField(object):
def
__init__
(
self
,
name
):
def
__init__
(
self
,
name
):
self
.
name
=
name
self
.
name
=
name
self
.
atoms
=
[]
self
.
atoms
=
[]
self
.
atomIndices
=
{}
self
.
virtualSites
=
[]
self
.
virtualSites
=
[]
self
.
bonds
=
[]
self
.
bonds
=
[]
self
.
externalBonds
=
[]
self
.
externalBonds
=
[]
...
@@ -595,15 +596,19 @@ class ForceField(object):
...
@@ -595,15 +596,19 @@ class ForceField(object):
def
getAtomIndexByName
(
self
,
atom_name
):
def
getAtomIndexByName
(
self
,
atom_name
):
"""Look up an atom index by atom name, providing a helpful error message if not found."""
"""Look up an atom index by atom name, providing a helpful error message if not found."""
for
(
index
,
atom
)
in
enumerate
(
self
.
atoms
):
index
=
self
.
atomIndices
.
get
(
atom_name
,
None
)
if
atom
.
name
==
atom_nam
e
:
if
index
is
not
Non
e
:
return
index
return
index
# Provide a helpful error message if atom name not found.
# Provide a helpful error message if atom name not found.
msg
=
"Atom name '%s' not found in residue template '%s'.
\n
"
%
(
atom_name
,
self
.
name
)
msg
=
"Atom name '%s' not found in residue template '%s'.
\n
"
%
(
atom_name
,
self
.
name
)
msg
+=
"Possible atom names are: %s"
%
str
(
list
(
map
(
lambda
x
:
x
.
name
,
self
.
atoms
)))
msg
+=
"Possible atom names are: %s"
%
str
(
list
(
map
(
lambda
x
:
x
.
name
,
self
.
atoms
)))
raise
ValueError
(
msg
)
raise
ValueError
(
msg
)
def
addAtom
(
self
,
atom
):
self
.
atoms
.
append
(
atom
)
self
.
atomIndices
[
atom
.
name
]
=
len
(
self
.
atoms
)
def
addBond
(
self
,
atom1
,
atom2
):
def
addBond
(
self
,
atom1
,
atom2
):
"""Add a bond between two atoms in a template given their indices in the template."""
"""Add a bond between two atoms in a template given their indices in the template."""
self
.
bonds
.
append
((
atom1
,
atom2
))
self
.
bonds
.
append
((
atom1
,
atom2
))
...
@@ -712,11 +717,11 @@ class ForceField(object):
...
@@ -712,11 +717,11 @@ class ForceField(object):
for
atom
in
template
.
atoms
:
for
atom
in
template
.
atoms
:
if
not
any
(
deleted
.
name
==
atom
.
name
and
deleted
.
residue
==
index
for
deleted
in
self
.
deletedAtoms
):
if
not
any
(
deleted
.
name
==
atom
.
name
and
deleted
.
residue
==
index
for
deleted
in
self
.
deletedAtoms
):
newTemplate
.
atom
s
.
append
(
ForceField
.
_TemplateAtomData
(
atom
.
name
,
atom
.
type
,
atom
.
element
,
atom
.
parameters
))
newTemplate
.
a
ddA
tom
(
ForceField
.
_TemplateAtomData
(
atom
.
name
,
atom
.
type
,
atom
.
element
,
atom
.
parameters
))
for
atom
in
self
.
addedAtoms
[
index
]:
for
atom
in
self
.
addedAtoms
[
index
]:
if
any
(
a
.
name
==
atom
.
name
for
a
in
newTemplate
.
atoms
):
if
any
(
a
.
name
==
atom
.
name
for
a
in
newTemplate
.
atoms
):
raise
ValueError
(
"Patch '%s' adds an atom with the same name as an existing atom: %s"
%
(
self
.
name
,
atom
.
name
))
raise
ValueError
(
"Patch '%s' adds an atom with the same name as an existing atom: %s"
%
(
self
.
name
,
atom
.
name
))
newTemplate
.
atom
s
.
append
(
ForceField
.
_TemplateAtomData
(
atom
.
name
,
atom
.
type
,
atom
.
element
,
atom
.
parameters
))
newTemplate
.
a
ddA
tom
(
ForceField
.
_TemplateAtomData
(
atom
.
name
,
atom
.
type
,
atom
.
element
,
atom
.
parameters
))
oldAtomIndex
=
dict
([(
atom
.
name
,
i
)
for
i
,
atom
in
enumerate
(
template
.
atoms
)])
oldAtomIndex
=
dict
([(
atom
.
name
,
i
)
for
i
,
atom
in
enumerate
(
template
.
atoms
)])
newAtomIndex
=
dict
([(
atom
.
name
,
i
)
for
i
,
atom
in
enumerate
(
newTemplate
.
atoms
)])
newAtomIndex
=
dict
([(
atom
.
name
,
i
)
for
i
,
atom
in
enumerate
(
newTemplate
.
atoms
)])
for
atom
in
self
.
changedAtoms
[
index
]:
for
atom
in
self
.
changedAtoms
[
index
]:
...
@@ -1540,7 +1545,7 @@ def _applyMultiResiduePatch(data, clusters, patch, candidateTemplates, selectedT
...
@@ -1540,7 +1545,7 @@ def _applyMultiResiduePatch(data, clusters, patch, candidateTemplates, selectedT
bondsMatch
&=
atom2
.
index
in
bondedToAtom
[
atom1
.
index
]
bondsMatch
&=
atom2
.
index
in
bondedToAtom
[
atom1
.
index
]
if
bondsMatch
:
if
bondsMatch
:
# We successfully matched the template to the residues. Record the parameters.
# We successfully matched the template to the residues. Record the parameters.
for
i
in
range
(
patch
.
numResidues
):
for
i
in
range
(
patch
.
numResidues
):
data
.
recordMatchedAtomParameters
(
residues
[
i
],
patchedTemplates
[
i
],
residueMatches
[
i
])
data
.
recordMatchedAtomParameters
(
residues
[
i
],
patchedTemplates
[
i
],
residueMatches
[
i
])
newlyMatchedClusters
.
append
(
cluster
)
newlyMatchedClusters
.
append
(
cluster
)
...
@@ -1631,7 +1636,7 @@ def _createResidueTemplate(residue):
...
@@ -1631,7 +1636,7 @@ def _createResidueTemplate(residue):
"""
"""
template
=
ForceField
.
_TemplateData
(
residue
.
name
)
template
=
ForceField
.
_TemplateData
(
residue
.
name
)
for
atom
in
residue
.
atoms
():
for
atom
in
residue
.
atoms
():
template
.
atom
s
.
append
(
ForceField
.
_TemplateAtomData
(
atom
.
name
,
None
,
atom
.
element
))
template
.
a
ddA
tom
(
ForceField
.
_TemplateAtomData
(
atom
.
name
,
None
,
atom
.
element
))
for
(
atom1
,
atom2
)
in
residue
.
internal_bonds
():
for
(
atom1
,
atom2
)
in
residue
.
internal_bonds
():
template
.
addBondByName
(
atom1
.
name
,
atom2
.
name
)
template
.
addBondByName
(
atom1
.
name
,
atom2
.
name
)
residue_atoms
=
[
atom
for
atom
in
residue
.
atoms
()
]
residue_atoms
=
[
atom
for
atom
in
residue
.
atoms
()
]
...
...
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