Commit 23522479 authored by ChayaSt's avatar ChayaSt
Browse files

added postprocessSystem

parent da4cb9b0
...@@ -1683,7 +1683,7 @@ class NBFixGenerator(object): ...@@ -1683,7 +1683,7 @@ class NBFixGenerator(object):
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] self.lj_types = [f for f in forcefield._forces if isinstance(f, NonbondedGenerator)][0].params
def registerNBFix(self, parameters): def registerNBFix(self, parameters):
types = self.ff._findAtomTypes(parameters, 2) types = self.ff._findAtomTypes(parameters, 2)
...@@ -1718,13 +1718,13 @@ class NBFixGenerator(object): ...@@ -1718,13 +1718,13 @@ class NBFixGenerator(object):
CustomNonbondedForce CustomNonbondedForce
""" """
# NonBondedForce for 'standard' nonbonded interactions. This will be modified # NonBondedForce for 'standard' nonbonded interactions. This will be modified
nonbfrc = [f for f in sys.getForces if isinstance(f, mm.openmm.NonbondedForce)][0] 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
lj_indx_list = [0 for atom in data.atoms] lj_indx_list = [0 for atom in data.atoms]
li_radii, lj_depths = [], [] lj_radii, lj_depths = [], []
num_lj_types= 0 num_lj_types= 0
lj_type_list = [] lj_type_list = []
for i, atom in enumerate(data.atoms): for i, atom in enumerate(data.atoms):
...@@ -1772,50 +1772,58 @@ class NBFixGenerator(object): ...@@ -1772,50 +1772,58 @@ class NBFixGenerator(object):
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
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)')
force.addTabulatedFunction('acoef', self.force.addTabulatedFunction('acoef',
mm.Discrete2DFunction(num_lj_types, num_lj_types, acoef)) mm.Discrete2DFunction(num_lj_types, num_lj_types, acoef))
force.addTabulatedFunction('bcoef', self.force.addTabulatedFunction('bcoef',
mm.Discrete2DFunction(num_lj_types, num_lj_types, bcoef)) mm.Discrete2DFunction(num_lj_types, num_lj_types, bcoef))
force.addPerParticleParameter('type') self.force.addPerParticleParameter('type')
if (nonbondedMethod is PME or nonbondedMethod is Ewald or if (nonbondedMethod is PME or nonbondedMethod is Ewald or
nonbondedMethod is CutoffPeriodic): nonbondedMethod is CutoffPeriodic):
force.setNonbondedMethod(mm.CustomNonbondedForce.CutoffPeriodic) self.force.setNonbondedMethod(mm.CustomNonbondedForce.CutoffPeriodic)
elif nonbondedMethod is NoCutoff: elif nonbondedMethod is NoCutoff:
force.setNonbondedMethod(mm.CustomNonbondedForce.NoCutoff) self.force.setNonbondedMethod(mm.CustomNonbondedForce.NoCutoff)
elif nonbondedMethod is CutoffNonPeriodic: elif nonbondedMethod is CutoffNonPeriodic:
force.setNonbondedMethod(mm.CustomNonbondedForce.CutoffNonPeriodic) self.force.setNonbondedMethod(mm.CustomNonbondedForce.CutoffNonPeriodic)
else: else:
raise AssertionError('Unrecognized nonbonded method [%s]' % raise AssertionError('Unrecognized nonbonded method [%s]' %
nonbondedMethod) nonbondedMethod)
# Add the particles # Add the particles
for i in lj_indx_list: for i in lj_indx_list:
force.addParticle((i-1,)) self.force.addParticle((i-1,))
# Now wipe out the L-J parameters in the nonbonded force # Now wipe out the L-J parameters in the nonbonded force
for i in range(nonbfrc.getNumParticles()): for i in range(nonbonded.getNumParticles()):
chg, sig, eps = nonbfrc.getParticleParameters(i) chg, sig, eps = nonbonded.getParticleParameters(i)
nonbfrc.setParticleParameters(i, chg, 0.5, 0.0) nonbonded.setParticleParameters(i, chg, 0.5, 0.0)
# Now transfer the exclusions sys.addForce(self.force)
for ii in range(nonbfrc.getNumExceptions()):
i, j, qq, ss, ee = nonbfrc.getExceptionParameters(ii) def postprocessSystem(self, sys, data, args):
force.addExclusion(i, j) nonbonded = [f for f in sys.getForces() if isinstance(f, mm.NonbondedForce)][0]
# transfer the exclusions from NonBonded
for ii in range(nonbonded.getNumExceptions()):
i, j, qq, ss, ee = nonbonded.getExceptionParameters(ii)
self.force.addExclusion(i, j)
# Now transfer the other properties (cutoff, switching function, etc.) # Now transfer the other properties (cutoff, switching function, etc.)
force.setUseLongRangeCorrection(True) self.force.setUseLongRangeCorrection(True)
if nonbondedMethod is NoCutoff: # if nonbondedMethod is NoCutoff:
force.setNonbondedMethod(mm.CustomNonbondedForce.NoCutoff) # self.force.setNonbondedMethod(mm.CustomNonbondedForce.NoCutoff)
elif nonbondedMethod is CutoffNonPeriodic: # elif nonbondedMethod is CutoffNonPeriodic:
force.setNonbondedMethod(mm.CustomNonbondedForce.CutoffNonPeriodic) # self.force.setNonbondedMethod(mm.CustomNonbondedForce.CutoffNonPeriodic)
elif nonbondedMethod in (PME, Ewald, CutoffPeriodic): # elif nonbondedMethod in (PME, Ewald, CutoffPeriodic):
force.setNonbondedMethod(mm.CustomNonbondedForce.CutoffPeriodic) # self.force.setNonbondedMethod(mm.CustomNonbondedForce.CutoffPeriodic)
else: # else:
raise AssertionError('Unsupported nonbonded method %s' % # raise AssertionError('Unsupported nonbonded method %s' %
nonbondedMethod) # nonbondedMethod)
force.setCutoffDistance(nonbfrc.getCutoffDistance()) self.force.setCutoffDistance(nonbonded.getCutoffDistance())
if nonbfrc.getUseSwitchingFunction(): if nonbonded.getUseSwitchingFunction():
force.setUseSwitchingFunction(True) self.force.setUseSwitchingFunction(True)
force.setSwitchingDistance(nonbfrc.getSwitchingDistance()) self.force.setSwitchingDistance(nonbonded.getSwitchingDistance())
parsers["NBFixForce"] = NBFixGenerator.parseElement parsers["NBFixForce"] = NBFixGenerator.parseElement
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment