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
883cb72c
Commit
883cb72c
authored
Apr 26, 2017
by
Rafal P. Wiewiora
Browse files
add new code to RBTorsion and CustomTorsion
parent
4f11c10f
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
151 additions
and
36 deletions
+151
-36
wrappers/python/simtk/openmm/app/forcefield.py
wrappers/python/simtk/openmm/app/forcefield.py
+151
-36
No files found.
wrappers/python/simtk/openmm/app/forcefield.py
View file @
883cb72c
...
@@ -1736,6 +1736,7 @@ def _createResidueTemplate(residue):
...
@@ -1736,6 +1736,7 @@ def _createResidueTemplate(residue):
template
.
addExternalBondByName
(
atom2
.
name
)
template
.
addExternalBondByName
(
atom2
.
name
)
return
template
return
template
# The following classes are generators that know how to create Force subclasses and add them to a System that is being
# The following classes are generators that know how to create Force subclasses and add them to a System that is being
# created. Each generator class must define two methods: 1) a static method that takes an etree Element and a ForceField,
# created. Each generator class must define two methods: 1) a static method that takes an etree Element and a ForceField,
# and returns the corresponding generator object; 2) a createForce() method that constructs the Force object and adds it
# and returns the corresponding generator object; 2) a createForce() method that constructs the Force object and adds it
...
@@ -2062,12 +2063,16 @@ parsers["PeriodicTorsionForce"] = PeriodicTorsionGenerator.parseElement
...
@@ -2062,12 +2063,16 @@ parsers["PeriodicTorsionForce"] = PeriodicTorsionGenerator.parseElement
class
RBTorsion
(
object
):
class
RBTorsion
(
object
):
"""An RBTorsion records the information for a Ryckaert-Bellemans torsion definition."""
"""An RBTorsion records the information for a Ryckaert-Bellemans torsion definition."""
def
__init__
(
self
,
types
,
c
):
def
__init__
(
self
,
types
,
c
,
ordering
=
'default'
):
self
.
types1
=
types
[
0
]
self
.
types1
=
types
[
0
]
self
.
types2
=
types
[
1
]
self
.
types2
=
types
[
1
]
self
.
types3
=
types
[
2
]
self
.
types3
=
types
[
2
]
self
.
types4
=
types
[
3
]
self
.
types4
=
types
[
3
]
self
.
c
=
c
self
.
c
=
c
if
ordering
==
'default'
or
ordering
==
'amber'
:
self
.
ordering
=
ordering
else
:
raise
ValueError
(
'Illegal ordering type for RBTorsion (%s,%s,%s,%s)'
%
(
types
[
0
],
types
[
1
],
types
[
2
],
types
[
3
]))
## @private
## @private
class
RBTorsionGenerator
(
object
):
class
RBTorsionGenerator
(
object
):
...
@@ -2093,6 +2098,9 @@ class RBTorsionGenerator(object):
...
@@ -2093,6 +2098,9 @@ class RBTorsionGenerator(object):
for
torsion
in
element
.
findall
(
'Improper'
):
for
torsion
in
element
.
findall
(
'Improper'
):
types
=
ff
.
_findAtomTypes
(
torsion
.
attrib
,
4
)
types
=
ff
.
_findAtomTypes
(
torsion
.
attrib
,
4
)
if
None
not
in
types
:
if
None
not
in
types
:
if
'ordering'
in
element
.
attrib
:
generator
.
improper
.
append
(
RBTorsion
(
types
,
[
float
(
torsion
.
attrib
[
'c'
+
str
(
i
)])
for
i
in
range
(
6
)],
element
.
attrib
[
'ordering'
]))
else
:
generator
.
improper
.
append
(
RBTorsion
(
types
,
[
float
(
torsion
.
attrib
[
'c'
+
str
(
i
)])
for
i
in
range
(
6
)]))
generator
.
improper
.
append
(
RBTorsion
(
types
,
[
float
(
torsion
.
attrib
[
'c'
+
str
(
i
)])
for
i
in
range
(
6
)]))
def
createForce
(
self
,
sys
,
data
,
nonbondedMethod
,
nonbondedCutoff
,
args
):
def
createForce
(
self
,
sys
,
data
,
nonbondedMethod
,
nonbondedCutoff
,
args
):
...
@@ -2141,6 +2149,7 @@ class RBTorsionGenerator(object):
...
@@ -2141,6 +2149,7 @@ class RBTorsionGenerator(object):
if
type1
in
types1
:
if
type1
in
types1
:
for
(
t2
,
t3
,
t4
)
in
itertools
.
permutations
(((
type2
,
1
),
(
type3
,
2
),
(
type4
,
3
))):
for
(
t2
,
t3
,
t4
)
in
itertools
.
permutations
(((
type2
,
1
),
(
type3
,
2
),
(
type4
,
3
))):
if
t2
[
0
]
in
types2
and
t3
[
0
]
in
types3
and
t4
[
0
]
in
types4
:
if
t2
[
0
]
in
types2
and
t3
[
0
]
in
types3
and
t4
[
0
]
in
types4
:
if
tordef
.
ordering
==
'default'
:
if
hasWildcard
:
if
hasWildcard
:
# Workaround to be more consistent with AMBER. It uses wildcards to define most of its
# Workaround to be more consistent with AMBER. It uses wildcards to define most of its
# impropers, which leaves the ordering ambiguous. It then follows some bizarre rules
# impropers, which leaves the ordering ambiguous. It then follows some bizarre rules
...
@@ -2155,8 +2164,57 @@ class RBTorsionGenerator(object):
...
@@ -2155,8 +2164,57 @@ class RBTorsionGenerator(object):
(
a1
,
a2
)
=
(
a2
,
a1
)
(
a1
,
a2
)
=
(
a2
,
a1
)
match
=
(
a1
,
a2
,
torsion
[
0
],
torsion
[
t4
[
1
]],
tordef
)
match
=
(
a1
,
a2
,
torsion
[
0
],
torsion
[
t4
[
1
]],
tordef
)
else
:
else
:
# There are no wildcards, so the order is unambiguous.
-
# There are no wildcards, so the order is unambiguous.
match
=
(
torsion
[
0
],
torsion
[
t2
[
1
]],
torsion
[
t3
[
1
]],
torsion
[
t4
[
1
]],
tordef
)
-
match
=
(
torsion
[
0
],
torsion
[
t2
[
1
]],
torsion
[
t3
[
1
]],
torsion
[
t4
[
1
]],
tordef
)
break
elif
tordef
.
ordering
==
'amber'
:
# topology atom indexes
a2
=
torsion
[
t2
[
1
]]
a3
=
torsion
[
t3
[
1
]]
a4
=
torsion
[
t4
[
1
]]
# residue indexes
r2
=
data
.
atoms
[
a2
].
residue
.
index
r3
=
data
.
atoms
[
a3
].
residue
.
index
r4
=
data
.
atoms
[
a4
].
residue
.
index
# template atom indexes
ta2
=
data
.
atomTemplateIndexes
[
data
.
atoms
[
a2
]]
ta3
=
data
.
atomTemplateIndexes
[
data
.
atoms
[
a3
]]
ta4
=
data
.
atomTemplateIndexes
[
data
.
atoms
[
a4
]]
# elements
e2
=
data
.
atoms
[
a2
].
element
e3
=
data
.
atoms
[
a3
].
element
e4
=
data
.
atoms
[
a4
].
element
if
not
hasWildcard
:
if
t2
[
0
]
==
t4
[
0
]
and
(
r2
>
r4
or
(
r2
==
r4
and
ta2
>
ta4
)):
(
a2
,
a4
)
=
(
a4
,
a2
)
r2
=
data
.
atoms
[
a2
].
residue
.
index
r4
=
data
.
atoms
[
a4
].
residue
.
index
ta2
=
data
.
atomTemplateIndexes
[
data
.
atoms
[
a2
]]
ta4
=
data
.
atomTemplateIndexes
[
data
.
atoms
[
a4
]]
if
t3
[
0
]
==
t4
[
0
]
and
(
r3
>
r4
or
(
r3
==
r4
and
ta3
>
ta4
)):
(
a3
,
a4
)
=
(
a4
,
a3
)
r3
=
data
.
atoms
[
a3
].
residue
.
index
r4
=
data
.
atoms
[
a4
].
residue
.
index
ta3
=
data
.
atomTemplateIndexes
[
data
.
atoms
[
a3
]]
ta4
=
data
.
atomTemplateIndexes
[
data
.
atoms
[
a4
]]
if
t2
[
0
]
==
t3
[
0
]
and
(
r2
>
r3
or
(
r2
==
r3
and
ta2
>
ta3
)):
(
a2
,
a3
)
=
(
a3
,
a2
)
else
:
if
e2
==
e4
and
(
r2
>
r4
or
(
r2
==
r4
and
ta2
>
ta4
)):
(
a2
,
a4
)
=
(
a4
,
a2
)
r2
=
data
.
atoms
[
a2
].
residue
.
index
r4
=
data
.
atoms
[
a4
].
residue
.
index
ta2
=
data
.
atomTemplateIndexes
[
data
.
atoms
[
a2
]]
ta4
=
data
.
atomTemplateIndexes
[
data
.
atoms
[
a4
]]
if
e3
==
e4
and
(
r3
>
r4
or
(
r3
==
r4
and
ta3
>
ta4
)):
(
a3
,
a4
)
=
(
a4
,
a3
)
r3
=
data
.
atoms
[
a3
].
residue
.
index
r4
=
data
.
atoms
[
a4
].
residue
.
index
ta3
=
data
.
atomTemplateIndexes
[
data
.
atoms
[
a3
]]
ta4
=
data
.
atomTemplateIndexes
[
data
.
atoms
[
a4
]]
if
r2
>
r3
or
(
r2
==
r3
and
ta2
>
ta3
):
(
a2
,
a3
)
=
(
a3
,
a2
)
match
=
(
a2
,
a3
,
torsion
[
0
],
a4
,
tordef
)
break
break
if
match
is
not
None
:
if
match
is
not
None
:
(
a1
,
a2
,
a3
,
a4
,
tordef
)
=
match
(
a1
,
a2
,
a3
,
a4
,
tordef
)
=
match
...
@@ -2618,12 +2676,16 @@ parsers["CustomAngleForce"] = CustomAngleGenerator.parseElement
...
@@ -2618,12 +2676,16 @@ parsers["CustomAngleForce"] = CustomAngleGenerator.parseElement
class
CustomTorsion
(
object
):
class
CustomTorsion
(
object
):
"""A CustomTorsion records the information for a custom torsion definition."""
"""A CustomTorsion records the information for a custom torsion definition."""
def
__init__
(
self
,
types
,
paramValues
):
def
__init__
(
self
,
types
,
paramValues
,
ordering
=
'default'
):
self
.
types1
=
types
[
0
]
self
.
types1
=
types
[
0
]
self
.
types2
=
types
[
1
]
self
.
types2
=
types
[
1
]
self
.
types3
=
types
[
2
]
self
.
types3
=
types
[
2
]
self
.
types4
=
types
[
3
]
self
.
types4
=
types
[
3
]
self
.
paramValues
=
paramValues
self
.
paramValues
=
paramValues
if
ordering
==
'default'
or
ordering
==
'amber'
:
self
.
ordering
=
ordering
else
:
raise
ValueError
(
'Illegal ordering type for CustomTorsion (%s,%s,%s,%s)'
%
(
types
[
0
],
types
[
1
],
types
[
2
],
types
[
3
]))
## @private
## @private
class
CustomTorsionGenerator
(
object
):
class
CustomTorsionGenerator
(
object
):
...
@@ -2652,6 +2714,9 @@ class CustomTorsionGenerator(object):
...
@@ -2652,6 +2714,9 @@ class CustomTorsionGenerator(object):
for
torsion
in
element
.
findall
(
'Improper'
):
for
torsion
in
element
.
findall
(
'Improper'
):
types
=
ff
.
_findAtomTypes
(
torsion
.
attrib
,
4
)
types
=
ff
.
_findAtomTypes
(
torsion
.
attrib
,
4
)
if
None
not
in
types
:
if
None
not
in
types
:
if
'ordering'
in
element
.
attrib
:
generator
.
improper
.
append
(
CustomTorsion
(
types
,
[
float
(
torsion
.
attrib
[
param
])
for
param
in
generator
.
perTorsionParams
],
element
.
attrib
[
'ordering'
]))
else
:
generator
.
improper
.
append
(
CustomTorsion
(
types
,
[
float
(
torsion
.
attrib
[
param
])
for
param
in
generator
.
perTorsionParams
]))
generator
.
improper
.
append
(
CustomTorsion
(
types
,
[
float
(
torsion
.
attrib
[
param
])
for
param
in
generator
.
perTorsionParams
]))
def
createForce
(
self
,
sys
,
data
,
nonbondedMethod
,
nonbondedCutoff
,
args
):
def
createForce
(
self
,
sys
,
data
,
nonbondedMethod
,
nonbondedCutoff
,
args
):
...
@@ -2699,6 +2764,7 @@ class CustomTorsionGenerator(object):
...
@@ -2699,6 +2764,7 @@ class CustomTorsionGenerator(object):
if
type1
in
types1
:
if
type1
in
types1
:
for
(
t2
,
t3
,
t4
)
in
itertools
.
permutations
(((
type2
,
1
),
(
type3
,
2
),
(
type4
,
3
))):
for
(
t2
,
t3
,
t4
)
in
itertools
.
permutations
(((
type2
,
1
),
(
type3
,
2
),
(
type4
,
3
))):
if
t2
[
0
]
in
types2
and
t3
[
0
]
in
types3
and
t4
[
0
]
in
types4
:
if
t2
[
0
]
in
types2
and
t3
[
0
]
in
types3
and
t4
[
0
]
in
types4
:
if
tordef
.
ordering
==
'default'
:
if
hasWildcard
:
if
hasWildcard
:
# Workaround to be more consistent with AMBER. It uses wildcards to define most of its
# Workaround to be more consistent with AMBER. It uses wildcards to define most of its
# impropers, which leaves the ordering ambiguous. It then follows some bizarre rules
# impropers, which leaves the ordering ambiguous. It then follows some bizarre rules
...
@@ -2713,8 +2779,57 @@ class CustomTorsionGenerator(object):
...
@@ -2713,8 +2779,57 @@ class CustomTorsionGenerator(object):
(
a1
,
a2
)
=
(
a2
,
a1
)
(
a1
,
a2
)
=
(
a2
,
a1
)
match
=
(
a1
,
a2
,
torsion
[
0
],
torsion
[
t4
[
1
]],
tordef
)
match
=
(
a1
,
a2
,
torsion
[
0
],
torsion
[
t4
[
1
]],
tordef
)
else
:
else
:
# There are no wildcards, so the order is unambiguous.
-
# There are no wildcards, so the order is unambiguous.
match
=
(
torsion
[
0
],
torsion
[
t2
[
1
]],
torsion
[
t3
[
1
]],
torsion
[
t4
[
1
]],
tordef
)
-
match
=
(
torsion
[
0
],
torsion
[
t2
[
1
]],
torsion
[
t3
[
1
]],
torsion
[
t4
[
1
]],
tordef
)
break
elif
tordef
.
ordering
==
'amber'
:
# topology atom indexes
a2
=
torsion
[
t2
[
1
]]
a3
=
torsion
[
t3
[
1
]]
a4
=
torsion
[
t4
[
1
]]
# residue indexes
r2
=
data
.
atoms
[
a2
].
residue
.
index
r3
=
data
.
atoms
[
a3
].
residue
.
index
r4
=
data
.
atoms
[
a4
].
residue
.
index
# template atom indexes
ta2
=
data
.
atomTemplateIndexes
[
data
.
atoms
[
a2
]]
ta3
=
data
.
atomTemplateIndexes
[
data
.
atoms
[
a3
]]
ta4
=
data
.
atomTemplateIndexes
[
data
.
atoms
[
a4
]]
# elements
e2
=
data
.
atoms
[
a2
].
element
e3
=
data
.
atoms
[
a3
].
element
e4
=
data
.
atoms
[
a4
].
element
if
not
hasWildcard
:
if
t2
[
0
]
==
t4
[
0
]
and
(
r2
>
r4
or
(
r2
==
r4
and
ta2
>
ta4
)):
(
a2
,
a4
)
=
(
a4
,
a2
)
r2
=
data
.
atoms
[
a2
].
residue
.
index
r4
=
data
.
atoms
[
a4
].
residue
.
index
ta2
=
data
.
atomTemplateIndexes
[
data
.
atoms
[
a2
]]
ta4
=
data
.
atomTemplateIndexes
[
data
.
atoms
[
a4
]]
if
t3
[
0
]
==
t4
[
0
]
and
(
r3
>
r4
or
(
r3
==
r4
and
ta3
>
ta4
)):
(
a3
,
a4
)
=
(
a4
,
a3
)
r3
=
data
.
atoms
[
a3
].
residue
.
index
r4
=
data
.
atoms
[
a4
].
residue
.
index
ta3
=
data
.
atomTemplateIndexes
[
data
.
atoms
[
a3
]]
ta4
=
data
.
atomTemplateIndexes
[
data
.
atoms
[
a4
]]
if
t2
[
0
]
==
t3
[
0
]
and
(
r2
>
r3
or
(
r2
==
r3
and
ta2
>
ta3
)):
(
a2
,
a3
)
=
(
a3
,
a2
)
else
:
if
e2
==
e4
and
(
r2
>
r4
or
(
r2
==
r4
and
ta2
>
ta4
)):
(
a2
,
a4
)
=
(
a4
,
a2
)
r2
=
data
.
atoms
[
a2
].
residue
.
index
r4
=
data
.
atoms
[
a4
].
residue
.
index
ta2
=
data
.
atomTemplateIndexes
[
data
.
atoms
[
a2
]]
ta4
=
data
.
atomTemplateIndexes
[
data
.
atoms
[
a4
]]
if
e3
==
e4
and
(
r3
>
r4
or
(
r3
==
r4
and
ta3
>
ta4
)):
(
a3
,
a4
)
=
(
a4
,
a3
)
r3
=
data
.
atoms
[
a3
].
residue
.
index
r4
=
data
.
atoms
[
a4
].
residue
.
index
ta3
=
data
.
atomTemplateIndexes
[
data
.
atoms
[
a3
]]
ta4
=
data
.
atomTemplateIndexes
[
data
.
atoms
[
a4
]]
if
r2
>
r3
or
(
r2
==
r3
and
ta2
>
ta3
):
(
a2
,
a3
)
=
(
a3
,
a2
)
match
=
(
a2
,
a3
,
torsion
[
0
],
a4
,
tordef
)
break
break
if
match
is
not
None
:
if
match
is
not
None
:
(
a1
,
a2
,
a3
,
a4
,
tordef
)
=
match
(
a1
,
a2
,
a3
,
a4
,
tordef
)
=
match
...
...
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