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
b44a8829
"devtools/vscode:/vscode.git/clone" did not exist on "9bedaa9b5106b324a561bb7970ead8b29cd2a8af"
Commit
b44a8829
authored
Mar 15, 2016
by
ChayaSt
Browse files
cleanup. Use lookup in dict instead of nested loops
parent
8c85cdce
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
57 deletions
+42
-57
wrappers/python/simtk/openmm/app/forcefield.py
wrappers/python/simtk/openmm/app/forcefield.py
+42
-57
No files found.
wrappers/python/simtk/openmm/app/forcefield.py
View file @
b44a8829
...
@@ -1679,20 +1679,20 @@ class LennardJonesGenerator(object):
...
@@ -1679,20 +1679,20 @@ class LennardJonesGenerator(object):
def
__init__
(
self
,
forcefield
,
lj14scale
):
def
__init__
(
self
,
forcefield
,
lj14scale
):
self
.
ff
=
forcefield
self
.
ff
=
forcefield
self
.
types1
=
[]
self
.
nbfix_types
=
{}
self
.
types2
=
[]
self
.
emin
=
[]
self
.
rmin
=
[]
self
.
lj14scale
=
lj14scale
self
.
lj14scale
=
lj14scale
self
.
lj_types
=
ForceField
.
_AtomTypeParameters
(
forcefield
,
'LennardJonesForce'
,
'Atom'
,
(
'sigma'
,
'epsilon'
))
self
.
lj_types
=
ForceField
.
_AtomTypeParameters
(
forcefield
,
'LennardJonesForce'
,
'Atom'
,
(
'sigma'
,
'epsilon'
))
def
registerNBFIX
(
self
,
parameters
):
def
registerNBFIX
(
self
,
parameters
):
types
=
self
.
ff
.
_findAtomTypes
(
parameters
,
2
)
types
=
self
.
ff
.
_findAtomTypes
(
parameters
,
2
)
if
None
not
in
types
:
if
None
not
in
types
:
self
.
types1
.
append
(
types
[
0
][
0
])
type1
=
types
[
0
][
0
]
self
.
types2
.
append
(
types
[
1
][
0
])
type2
=
types
[
1
][
0
]
self
.
emin
.
append
(
_convertParameterToNumber
(
parameters
[
'emin'
]))
emin
=
_convertParameterToNumber
(
parameters
[
'emin'
])
self
.
rmin
.
append
(
_convertParameterToNumber
(
parameters
[
'rmin'
]))
rmin
=
_convertParameterToNumber
(
parameters
[
'rmin'
])
self
.
nbfix_types
[(
type1
,
type2
)]
=
[
emin
,
rmin
]
self
.
nbfix_types
[(
type2
,
type1
)]
=
[
emin
,
rmin
]
def
registerLennardJones
(
self
,
parameters
):
def
registerLennardJones
(
self
,
parameters
):
self
.
lj_types
.
registerAtom
(
parameters
)
self
.
lj_types
.
registerAtom
(
parameters
)
...
@@ -1714,68 +1714,54 @@ class LennardJonesGenerator(object):
...
@@ -1714,68 +1714,54 @@ class LennardJonesGenerator(object):
generator
.
registerNBFIX
(
Nbfix
.
attrib
)
generator
.
registerNBFIX
(
Nbfix
.
attrib
)
def
createForce
(
self
,
sys
,
data
,
nonbondedMethod
,
nonbondedCutoff
,
args
):
def
createForce
(
self
,
sys
,
data
,
nonbondedMethod
,
nonbondedCutoff
,
args
):
""" Ewald and PME will be interpreted as CutoffPeriodic for the CustomNonbondedForce """
#Ewald and PME will be interpreted as CutoffPeriodic for the CustomNonbondedForce
# We need a CustomNonbondedForce to implement the NBFIX functionality.
# We need a CustomNonbondedForce to implement the NBFIX functionality.
# First derive the lookup tables
# First derive the lookup tables
lj_indx_list
=
[
0
for
atom
in
data
.
atoms
]
lj_indx_list
=
[
0
for
atom
in
data
.
atoms
]
lj_radii
,
lj_depths
=
[],
[]
num_lj_types
=
0
num_lj_types
=
0
lj_type_list
=
[]
lj_type_list
=
[]
type_map
=
{}
for
i
,
atom
in
enumerate
(
data
.
atoms
):
for
i
,
atom
in
enumerate
(
data
.
atoms
):
atype
=
data
.
atomType
[
atom
]
atype
=
data
.
atomType
[
atom
]
values
=
self
.
lj_types
.
paramsForType
[
atype
]
values
=
self
.
lj_types
.
paramsForType
[
atype
]
if
lj_indx_list
[
i
]:
continue
if
lj_indx_list
[
i
]:
continue
# ljtype has been assigned an index
num_lj_types
+=
1
if
values
in
type_map
.
values
()
and
not
atype
in
[
type
for
key
in
self
.
nbfix_types
.
keys
()
for
type
in
key
]:
lj_indx_list
[
i
]
=
num_lj_types
# only non NBFIX types can be compressed
rmin
=
values
[
'sigma'
]
*
2
**
(
1.0
/
6
)
/
2
lj_indx_list
[
i
]
=
type_map
.
values
().
index
(
values
)
+
1
ljtype
=
(
rmin
,
abs
(
values
[
'epsilon'
]))
else
:
lj_type_list
.
append
(
atype
)
type_map
[
num_lj_types
+
1
]
=
values
lj_radii
.
append
(
rmin
)
lj_indx_list
[
i
]
=
num_lj_types
+
1
lj_depths
.
append
(
abs
(
values
[
'epsilon'
]))
num_lj_types
+=
1
for
j
in
range
(
i
+
1
,
len
(
data
.
atoms
)):
lj_type_list
.
append
(
atype
)
atype2
=
data
.
atomType
[
data
.
atoms
[
j
]]
if
lj_indx_list
[
j
]
>
0
:
continue
if
atype2
==
atype
:
lj_indx_list
[
j
]
=
num_lj_types
elif
not
(
atype
in
self
.
types1
)
or
(
atype
in
self
.
types2
):
# only non NBFIX types can be compressed
values
=
self
.
lj_types
.
paramsForType
[
atype2
]
ljtype2
=
(
values
[
'sigma'
]
*
2
**
(
1.0
/
6
)
/
2
,
abs
(
values
[
'epsilon'
]))
if
ljtype
==
ljtype2
:
lj_indx_list
[
j
]
=
num_lj_types
# Now everything is assigned. Create the A- and B-coefficient arrays
# Now everything is assigned. Create the A- and B-coefficient arrays
acoef
=
[
0
for
i
in
range
(
num_lj_types
*
num_lj_types
)]
acoef
=
[
0
for
i
in
range
(
num_lj_types
*
num_lj_types
)]
bcoef
=
acoef
[:]
bcoef
=
acoef
[:]
for
m
in
range
(
num_lj_types
):
for
m
in
range
(
num_lj_types
):
for
n
in
range
(
num_lj_types
):
for
n
in
range
(
num_lj_types
):
namem
=
lj_type_list
[
m
]
pair
=
(
lj_type_list
[
m
],
lj_type_list
[
n
])
namen
=
lj_type_list
[
n
]
if
len
(
self
.
nbfix_types
)
>
0
:
if
range
(
len
(
self
.
types1
)):
if
pair
in
self
.
nbfix_types
:
for
k
in
range
(
len
(
self
.
types1
)):
wdij
=
self
.
nbfix_types
[
pair
][
0
]
types1
=
self
.
types1
[
k
]
rij
=
self
.
nbfix_types
[
pair
][
1
]
types2
=
self
.
types2
[
k
]
rij6
=
rij
**
6
if
(
namem
==
types1
and
namen
==
types2
)
or
(
namem
==
types2
and
namen
==
types1
):
acoef
[
m
+
num_lj_types
*
n
]
=
math
.
sqrt
(
wdij
)
*
rij6
rij
=
self
.
rmin
[
k
]
bcoef
[
m
+
num_lj_types
*
n
]
=
2
*
wdij
*
rij6
wdij
=
self
.
emin
[
k
]
continue
rij6
=
rij
**
6
else
:
acoef
[
m
+
num_lj_types
*
n
]
=
math
.
sqrt
(
wdij
)
*
rij6
rij
=
(
type_map
[
m
+
1
][
'sigma'
]
+
type_map
[
n
+
1
][
'sigma'
])
*
2
**
(
1.0
/
6
)
/
2
bcoef
[
m
+
num_lj_types
*
n
]
=
2
*
wdij
*
rij6
rij6
=
rij
**
6
break
wdij
=
math
.
sqrt
(
type_map
[
m
+
1
][
'epsilon'
]
*
type_map
[
n
+
1
][
'epsilon'
])
else
:
acoef
[
m
+
num_lj_types
*
n
]
=
math
.
sqrt
(
wdij
)
*
rij6
rij
=
(
lj_radii
[
m
]
+
lj_radii
[
n
])
bcoef
[
m
+
num_lj_types
*
n
]
=
2
*
wdij
*
rij6
rij6
=
rij
**
6
wdij
=
math
.
sqrt
(
lj_depths
[
m
]
*
lj_depths
[
n
])
acoef
[
m
+
num_lj_types
*
n
]
=
math
.
sqrt
(
wdij
)
*
rij6
bcoef
[
m
+
num_lj_types
*
n
]
=
2
*
wdij
*
rij6
else
:
else
:
rij
=
(
lj_radii
[
m
]
+
lj_radii
[
n
])
rij
=
(
type_map
[
m
+
1
][
'sigma'
]
+
type_map
[
n
+
1
][
'sigma'
])
*
2
**
(
1.0
/
6
)
/
2
rij6
=
rij
**
6
rij6
=
rij
**
6
wdij
=
math
.
sqrt
(
lj_depths
[
m
]
*
lj_depths
[
n
])
wdij
=
math
.
sqrt
(
type_map
[
m
+
1
][
'epsilon'
]
*
type_map
[
n
+
1
][
'epsilon'
])
acoef
[
m
+
num_lj_types
*
n
]
=
math
.
sqrt
(
wdij
)
*
rij6
acoef
[
m
+
num_lj_types
*
n
]
=
math
.
sqrt
(
wdij
)
*
rij6
bcoef
[
m
+
num_lj_types
*
n
]
=
2
*
wdij
*
rij6
bcoef
[
m
+
num_lj_types
*
n
]
=
2
*
wdij
*
rij6
self
.
force
=
mm
.
CustomNonbondedForce
(
'(a/r6)^2-b/r6; r6=r2*r2*r2; r2=r^2; '
self
.
force
=
mm
.
CustomNonbondedForce
(
'(a/r6)^2-b/r6; r6=r2*r2*r2; r2=r^2; '
'a=acoef(type1, type2); '
'a=acoef(type1, type2); '
'b=bcoef(type1, type2)'
)
'b=bcoef(type1, type2)'
)
...
@@ -1804,7 +1790,6 @@ class LennardJonesGenerator(object):
...
@@ -1804,7 +1790,6 @@ class LennardJonesGenerator(object):
lj14ScaleForce
=
mm
.
CustomBondForce
(
'(a/r^6)^2-(b/r^6); r6=r2*r2*r2; r2=r^2;'
lj14ScaleForce
=
mm
.
CustomBondForce
(
'(a/r^6)^2-(b/r^6); r6=r2*r2*r2; r2=r^2;'
'a=acoef;'
'a=acoef;'
'b=bcoef;'
)
'b=bcoef;'
)
lj14ScaleForce
.
addGlobalParameter
(
'lj14scale'
,
self
.
lj14scale
)
lj14ScaleForce
.
addPerBondParameter
(
'acoef'
)
lj14ScaleForce
.
addPerBondParameter
(
'acoef'
)
lj14ScaleForce
.
addPerBondParameter
(
'bcoef'
)
lj14ScaleForce
.
addPerBondParameter
(
'bcoef'
)
lj14Pairs
=
[]
lj14Pairs
=
[]
...
@@ -1813,11 +1798,11 @@ class LennardJonesGenerator(object):
...
@@ -1813,11 +1798,11 @@ class LennardJonesGenerator(object):
for
torsion
in
data
.
propers
:
for
torsion
in
data
.
propers
:
lj14Pairs
.
append
((
torsion
[
0
],
torsion
[
3
]))
lj14Pairs
.
append
((
torsion
[
0
],
torsion
[
3
]))
for
lj14Pair
in
lj14Pairs
:
for
lj14Pair
in
lj14Pairs
:
i
=
lj_indx_list
[
lj14Pair
[
0
]]
-
1
i
=
lj_indx_list
[
lj14Pair
[
0
]]
j
=
lj_indx_list
[
lj14Pair
[
1
]]
-
1
j
=
lj_indx_list
[
lj14Pair
[
1
]]
rminij
=
(
lj_radii
[
i
]
+
lj_radii
[
j
])
rminij
=
(
type_map
[
i
][
'sigma'
]
+
type_map
[
j
][
'sigma'
])
*
2
**
(
1.0
/
6
)
/
2
rij6
=
rminij
**
6
rij6
=
rminij
**
6
wdij14
=
self
.
lj14scale
*
math
.
sqrt
(
lj_depths
[
i
]
*
lj_depths
[
j
])
wdij14
=
self
.
lj14scale
*
math
.
sqrt
(
type_map
[
i
][
'epsilon'
]
*
type_map
[
j
][
'epsilon'
])
acoefScaled
=
(
math
.
sqrt
(
wdij14
)
*
rij6
)
acoefScaled
=
(
math
.
sqrt
(
wdij14
)
*
rij6
)
bcoefScaled
=
(
2
*
wdij14
*
rij6
)
bcoefScaled
=
(
2
*
wdij14
*
rij6
)
lj14ScaleForce
.
addBond
(
lj14Pair
[
0
],
lj14Pair
[
1
],
[
acoefScaled
,
bcoefScaled
])
lj14ScaleForce
.
addBond
(
lj14Pair
[
0
],
lj14Pair
[
1
],
[
acoefScaled
,
bcoefScaled
])
...
...
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