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
c6225e7a
Commit
c6225e7a
authored
Oct 29, 2019
by
peastman
Browse files
Minor cleanup based on comments
parent
d88ddb3b
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
14 deletions
+27
-14
wrappers/python/simtk/openmm/app/forcefield.py
wrappers/python/simtk/openmm/app/forcefield.py
+26
-13
wrappers/python/tests/TestForceField.py
wrappers/python/tests/TestForceField.py
+1
-1
No files found.
wrappers/python/simtk/openmm/app/forcefield.py
View file @
c6225e7a
...
@@ -632,6 +632,29 @@ class ForceField(object):
...
@@ -632,6 +632,29 @@ class ForceField(object):
atom
=
self
.
getAtomIndexByName
(
atom_name
)
atom
=
self
.
getAtomIndexByName
(
atom_name
)
self
.
addExternalBond
(
atom
)
self
.
addExternalBond
(
atom
)
def
areParametersIdentical
(
self
,
template2
,
matchingAtoms
,
matchingAtoms2
):
"""Get whether this template and another one both assign identical atom types and parameters to all atoms.
Parameters
----------
template2: _TemplateData
the template to compare this one to
matchingAtoms: list
the indices of atoms in this template that atoms of the residue are matched to
matchingAtoms2: list
the indices of atoms in template2 that atoms of the residue are matched to
"""
atoms1
=
[
self
.
atoms
[
m
]
for
m
in
matchingAtoms
]
atoms2
=
[
template2
.
atoms
[
m
]
for
m
in
matchingAtoms2
]
if
any
(
a1
.
type
!=
a2
.
type
or
a1
.
parameters
!=
a2
.
parameters
for
a1
,
a2
in
zip
(
atoms1
,
atoms2
)):
return
False
# Properly comparing virtual sites really needs a much more complicated analysis. This simple check
# could easily fail for templates containing vsites, even if they're actually identical. Since we
# currently have no force fields that include both patches and vsites, I'm not going to worry about it now.
if
self
.
virtualSites
!=
template2
.
virtualSites
:
return
False
return
True
class
_TemplateAtomData
(
object
):
class
_TemplateAtomData
(
object
):
"""Inner class used to encapsulate data about an atom in a residue template definition."""
"""Inner class used to encapsulate data about an atom in a residue template definition."""
def
__init__
(
self
,
name
,
type
,
element
,
parameters
=
{}):
def
__init__
(
self
,
name
,
type
,
element
,
parameters
=
{}):
...
@@ -866,7 +889,7 @@ class ForceField(object):
...
@@ -866,7 +889,7 @@ class ForceField(object):
Returns
Returns
-------
-------
template : _
ForceField
Template
template : _Template
Data
The matching forcefield residue template, or None if no matches are found.
The matching forcefield residue template, or None if no matches are found.
matches : list
matches : list
a list specifying which atom of the template each atom of the residue
a list specifying which atom of the template each atom of the residue
...
@@ -890,19 +913,9 @@ class ForceField(object):
...
@@ -890,19 +913,9 @@ class ForceField(object):
elif
len
(
allMatches
)
>
1
:
elif
len
(
allMatches
)
>
1
:
# We found multiple matches. This is OK if and only if they assign identical types and parameters to all atoms.
# We found multiple matches. This is OK if and only if they assign identical types and parameters to all atoms.
t1
,
m1
=
allMatches
[
0
]
t1
,
m1
=
allMatches
[
0
]
atoms1
=
[
t1
.
atoms
[
m
]
for
m
in
m1
]
allIdentical
=
True
for
t2
,
m2
in
allMatches
[
1
:]:
for
t2
,
m2
in
allMatches
[
1
:]:
atoms2
=
[
t2
.
atoms
[
m
]
for
m
in
m2
]
if
not
t1
.
areParametersIdentical
(
t2
,
m1
,
m2
):
if
any
(
a1
.
type
!=
a2
.
type
or
a1
.
parameters
!=
a2
.
parameters
for
a1
,
a2
in
zip
(
atoms1
,
atoms2
)):
raise
Exception
(
'Multiple non-identical matching templates found for residue %d (%s): %s.'
%
(
res
.
index
+
1
,
res
.
name
,
', '
.
join
(
match
[
0
].
name
for
match
in
allMatches
)))
allIdentical
=
False
# Properly comparing virtual sites really needs a much more complicated analysis. This simple check
# could easily fail for templates containing vsites, even if they're actually identical. Since we
# currently have no force fields that include both patches and vsites, I'm not going to worry about it now.
if
t1
.
virtualSites
!=
t2
.
virtualSites
:
allIdentical
=
False
if
not
allIdentical
:
raise
Exception
(
'Multiple matching templates found for residue %d (%s): %s.'
%
(
res
.
index
+
1
,
res
.
name
,
', '
.
join
(
match
[
0
].
name
for
match
in
allMatches
)))
template
=
allMatches
[
0
][
0
]
template
=
allMatches
[
0
][
0
]
matches
=
allMatches
[
0
][
1
]
matches
=
allMatches
[
0
][
1
]
return
[
template
,
matches
]
return
[
template
,
matches
]
...
...
wrappers/python/tests/TestForceField.py
View file @
c6225e7a
...
@@ -477,7 +477,7 @@ class TestForceField(unittest.TestCase):
...
@@ -477,7 +477,7 @@ class TestForceField(unittest.TestCase):
self
.
assertEqual
(
unmatched_residues
[
0
].
chain
.
id
,
'X'
)
self
.
assertEqual
(
unmatched_residues
[
0
].
chain
.
id
,
'X'
)
self
.
assertEqual
(
unmatched_residues
[
0
].
id
,
'1'
)
self
.
assertEqual
(
unmatched_residues
[
0
].
id
,
'1'
)
def
test_
g
generateTemplatesForUnmatchedResidues
(
self
):
def
test_generateTemplatesForUnmatchedResidues
(
self
):
"""Test generation of blank forcefield residue templates for unmatched residues."""
"""Test generation of blank forcefield residue templates for unmatched residues."""
#
#
# Test where we generate parameters for only a ligand.
# Test where we generate parameters for only a ligand.
...
...
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