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
f3e28c4d
Commit
f3e28c4d
authored
Mar 08, 2016
by
ChayaSt
Browse files
cleaned up L-J generator
parent
471f760f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
41 deletions
+45
-41
wrappers/python/simtk/openmm/app/forcefield.py
wrappers/python/simtk/openmm/app/forcefield.py
+45
-41
No files found.
wrappers/python/simtk/openmm/app/forcefield.py
View file @
f3e28c4d
...
@@ -1674,18 +1674,19 @@ class NonbondedGenerator(object):
...
@@ -1674,18 +1674,19 @@ class NonbondedGenerator(object):
parsers
[
"NonbondedForce"
]
=
NonbondedGenerator
.
parseElement
parsers
[
"NonbondedForce"
]
=
NonbondedGenerator
.
parseElement
class
NBFix
Generator
(
object
):
class
LennardJones
Generator
(
object
):
"""A NBFix generator to construct the L-J force with NBFIX implemented as a lookup table"""
"""A NBFix generator to construct the L-J force with NBFIX implemented as a lookup table"""
def
__init__
(
self
,
forcefield
):
def
__init__
(
self
,
forcefield
,
lj14scale
):
self
.
ff
=
forcefield
self
.
ff
=
forcefield
self
.
types1
=
[]
self
.
types1
=
[]
self
.
types2
=
[]
self
.
types2
=
[]
self
.
emin
=
[]
self
.
emin
=
[]
self
.
rmin
=
[]
self
.
rmin
=
[]
self
.
lj_types
=
[
f
for
f
in
forcefield
.
_forces
if
isinstance
(
f
,
NonbondedGenerator
)][
0
].
params
self
.
lj14scale
=
lj14scale
self
.
lj_types
=
ForceField
.
_AtomTypeParameters
(
forcefield
,
'LennardJonesForce'
,
'Atom'
,
(
'sigma'
,
'epsilon'
))
def
registerNBF
ix
(
self
,
parameters
):
def
registerNBF
IX
(
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
])
self
.
types1
.
append
(
types
[
0
][
0
])
...
@@ -1693,37 +1694,28 @@ class NBFixGenerator(object):
...
@@ -1693,37 +1694,28 @@ class NBFixGenerator(object):
self
.
emin
.
append
(
_convertParameterToNumber
(
parameters
[
'emin'
]))
self
.
emin
.
append
(
_convertParameterToNumber
(
parameters
[
'emin'
]))
self
.
rmin
.
append
(
_convertParameterToNumber
(
parameters
[
'rmin'
]))
self
.
rmin
.
append
(
_convertParameterToNumber
(
parameters
[
'rmin'
]))
def
registerLennardJones
(
self
,
parameters
):
self
.
lj_types
.
registerAtom
(
parameters
)
@
staticmethod
@
staticmethod
def
parseElement
(
element
,
ff
):
def
parseElement
(
element
,
ff
):
existing
=
[
f
for
f
in
ff
.
_forces
if
isinstance
(
f
,
NBFix
Generator
)]
existing
=
[
f
for
f
in
ff
.
_forces
if
isinstance
(
f
,
LennardJones
Generator
)]
if
len
(
existing
)
==
0
:
if
len
(
existing
)
==
0
:
generator
=
NBFixGenerator
(
ff
)
generator
=
LennardJonesGenerator
(
ff
,
float
(
element
.
attrib
[
'lj14scale'
])
)
ff
.
registerGenerator
(
generator
)
ff
.
registerGenerator
(
generator
)
else
:
else
:
# Multiple <
NBFix
Force> tags were found, probably in different files
# Multiple <
LennardJones
Force> tags were found, probably in different files
generator
=
existing
[
0
]
generator
=
existing
[
0
]
for
nbfix
in
element
.
findall
(
'NBFix'
):
for
LJ
in
element
.
findall
(
'Atom'
):
generator
.
registerNBFix
(
nbfix
.
attrib
)
generator
.
registerLennardJones
(
LJ
.
attrib
)
for
Nbfix
in
element
.
findall
(
'AtomTypePair'
):
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 """
# First check if there are at least two atoms in the system that have nbfix
self
.
NBFIX
=
False
for
a
in
data
.
atoms
:
atype
=
data
.
atomType
[
a
]
if
atype
in
self
.
types1
:
for
b
in
data
.
atoms
:
btype
=
data
.
atomType
[
b
]
if
btype
in
self
.
types2
:
self
.
NBFIX
=
True
if
not
self
.
NBFIX
:
return
# NonBondedForce for 'standard' nonbonded interactions. This will be modified
nonbonded
=
[
f
for
f
in
sys
.
getForces
()
if
isinstance
(
f
,
mm
.
openmm
.
NonbondedForce
)][
0
]
# 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
...
@@ -1798,29 +1790,41 @@ class NBFixGenerator(object):
...
@@ -1798,29 +1790,41 @@ class NBFixGenerator(object):
# Add the particles
# Add the particles
for
i
in
lj_indx_list
:
for
i
in
lj_indx_list
:
self
.
force
.
addParticle
((
i
-
1
,))
self
.
force
.
addParticle
((
i
-
1
,))
# Now wipe out the L-J parameters in the nonbonded force
self
.
force
.
setUseLongRangeCorrection
(
True
)
for
i
in
range
(
nonbonded
.
getNumParticles
()):
self
.
force
.
setCutoffDistance
(
nonbondedCutoff
)
chg
,
sig
,
eps
=
nonbonded
.
getParticleParameters
(
i
)
nonbonded
.
setParticleParameters
(
i
,
chg
,
0.5
,
0.0
)
sys
.
addForce
(
self
.
force
)
sys
.
addForce
(
self
.
force
)
def
postprocessSystem
(
self
,
sys
,
data
,
args
):
def
postprocessSystem
(
self
,
sys
,
data
,
args
):
if
not
self
.
NBFIX
:
return
nonbonded
=
[
f
for
f
in
sys
.
getForces
()
if
isinstance
(
f
,
mm
.
NonbondedForce
)][
0
]
# transfer the exclusions from NonBonded
bondIndices
=
[]
for
ii
in
range
(
nonbonded
.
getNumExceptions
()):
for
bond
in
data
.
bonds
:
i
,
j
,
qq
,
ss
,
ee
=
nonbonded
.
getExceptionParameters
(
ii
)
bondIndices
.
append
((
bond
.
atom1
,
bond
.
atom2
))
self
.
force
.
addExclusion
(
i
,
j
)
# Now transfer the other properties (cutoff, switching function, etc.)
# If a virtual site does *not* share exclusions with another atom, add a bond between it and its first parent
self
.
force
.
setUseLongRangeCorrection
(
True
)
# atom.
self
.
force
.
setCutoffDistance
(
nonbonded
.
getCutoffDistance
())
for
i
in
range
(
sys
.
getNumParticles
()):
if
nonbonded
.
getUseSwitchingFunction
():
if
sys
.
isVirtualSite
(
i
):
self
.
force
.
setUseSwitchingFunction
(
True
)
(
site
,
atoms
,
excludeWith
)
=
data
.
virtualSites
[
data
.
atoms
[
i
]]
self
.
force
.
setSwitchingDistance
(
nonbonded
.
getSwitchingDistance
())
if
excludeWith
is
None
:
bondIndices
.
append
((
i
,
site
.
getParticle
(
0
)))
# Certain particles, such as lone pairs and Drude particles, share exclusions with a parent atom.
# If the parent atom does not interact with an atom, the child particle does not either.
for
atom1
,
atom2
in
bondIndices
:
for
child1
in
data
.
excludeAtomWith
[
atom1
]:
bondIndices
.
append
((
child1
,
atom2
))
for
child2
in
data
.
excludeAtomWith
[
atom2
]:
bondIndices
.
append
((
child1
,
child2
))
for
child2
in
data
.
excludeAtomWith
[
atom2
]:
bondIndices
.
append
((
atom1
,
child2
))
# Create the exceptions.
self
.
force
.
createExclusionsFromBonds
(
bondIndices
,
2
)
parsers
[
"
NBFixForce"
]
=
NBFix
Generator
.
parseElement
parsers
[
"
LennardJonesForce"
]
=
LennardJones
Generator
.
parseElement
## @private
## @private
class
GBSAOBCGenerator
(
object
):
class
GBSAOBCGenerator
(
object
):
...
...
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