def setBondedInteractions(system, input_conf, ftpl): ret_list = {} bonds = input_conf.bondtypes bondtypeparams = input_conf.bondtypeparams for (bid, cross_bonds), bondlist in bonds.iteritems(): if ftpl: fpl = espressopp.FixedPairListAdress(system.storage, ftpl) else: fpl = espressopp.FixedPairList(system.storage) fpl.addBonds(bondlist) bdinteraction = bondtypeparams[bid].createEspressoInteraction(system, fpl) if bdinteraction: system.addInteraction(bdinteraction, 'bond_{}{}'.format( bid, '_cross' if cross_bonds else '')) ret_list.update({(bid, cross_bonds): bdinteraction}) return ret_list
# append tuple to tuplelist tuples.append(tmptuple) # add particles to system system.storage.addParticles(allParticles, "id", "pos", "v", "f", "type", "mass", "adrat") # create FixedTupleList object ftpl = espressopp.FixedTupleListAdress(system.storage) # and add the tuples ftpl.addTuples(tuples) system.storage.setFixedTuplesAdress(ftpl) # add bonds between AT particles fpl = espressopp.FixedPairListAdress(system.storage, ftpl) bonds = Tetracryst.makebonds(len(x)) fpl.addBonds(bonds) # decompose after adding tuples and bonds print "Added tuples and bonds, decomposing now ..." system.storage.decompose() print "done decomposing" # AdResS Verlet list vl = espressopp.VerletListAdress(system, cutoff=rc, adrcut=rc, dEx=ex_size, dHy=hy_size, adrCenter=[Lx/2, Ly/2, Lz/2]) # non-bonded potentials # LJ capped WCA between AT and tabulated potential between CG particles
verletlist = espressopp.VerletListAdress(system, cutoff=nbCutoff, adrcut=nbCutoff, dEx=ex_size, dHy=hy_size, pids=[mapAtToCgIndex[cm]], sphereAdr=True) # set up LJ interaction according to the parameters read from the .top file lj_adres_interaction = gromacs.setLennardJonesInteractionsTI(system, defaults, atomtypeparameters, verletlist, nbCutoff, epsilonB=0.0, sigmaSC=sigmaSC, alphaSC=alphaSC, powerSC=powerSC, lambdaTI=lambdaTIVdwl, pidlist=stateBIndices, annihilate=False, adress=True, ftpl=ftpl) # set up coulomb interactions according to the parameters read from the .top file # !! Warning: this only works for reaction-field now! qq_adres_interaction = gromacs.setCoulombInteractionsTI(system, verletlist, nbCutoff, atTypes, epsilon1=1, epsilon2=80, kappa=0, lambdaTI=lambdaTICoul, pidlist=stateBIndices, annihilate=False, adress=True, ftpl=ftpl) # bonded (fixed list) interactions in solute (between atomistic particles, solute is one coarse-grained particle) # only for solute, no bonded interactions for water # set up LJ 1-4 interactions onefourlist = espressopp.FixedPairListAdress(system.storage,ftpl) onefourlist.addBonds(atOnefourpairslist) lj14interaction=gromacs.setLennardJones14Interactions(system, defaults, atomtypeparameters, onefourlist, nbCutoff) # set up coulomb 1-4 interactions qq14_interactions=gromacs.setCoulomb14Interactions(system, defaults, onefourlist, nbCutoff, atTypes) ## set up bond interactions according to the parameters read from the .top file bondedinteractions=gromacs.setBondedInteractionsAdress(system, atBondtypes, bondtypeparams,ftpl) # set up angle interactions according to the parameters read from the .top file angleinteractions=gromacs.setAngleInteractionsAdress(system, atAngletypes, angletypeparams,ftpl) # set up dihedral interactions according to the parameters read from the .top file dihedralinteractions=gromacs.setDihedralInteractionsAdress(system, atDihedraltypes, dihedraltypeparams,ftpl)
def setPairInteractions(system, input_conf, cutoff, coulomb_cutoff, ftpl=None): pairs = input_conf.pairtypes fudgeQQ = float(input_conf.defaults['fudgeQQ']) pref = 138.935485 * fudgeQQ # we want gromacs units, so this is 1/(4 pi eps_0) ins units of kJ mol^-1 e^-2, scaled by fudge factor pairtypeparams = input_conf.pairtypeparams static_14_pairs = [] cross_14_pairs_cg = [] cross_14_pairs_at = [] for (pid, cross_bonds), pair_list in pairs.iteritems(): params = pairtypeparams[pid] is_cg = input_conf.atomtypeparams[ input_conf.types[pair_list[0][0] - 1]]['particletype'] == 'V' if is_cg or ftpl is None: fpl = espressopp.FixedPairList(system.storage) else: fpl = espressopp.FixedPairListAdress(system.storage, ftpl) fpl.addBonds(pair_list) if cross_bonds or is_cg: if is_cg: cross_14_pairs_cg.extend(pair_list) else: cross_14_pairs_at.extend(pair_list) else: static_14_pairs.extend(pair_list) if not cross_bonds: is_cg = None if params['sig'] > 0.0 and params['eps'] > 0.0: print('Pair interaction {} num pairs: {} sig={} eps={} cutoff={} is_cg={}'.format( params, len(pair_list), params['sig'], params['eps'], cutoff, is_cg)) pot = espressopp.interaction.LennardJones( sigma=params['sig'], epsilon=params['eps'], shift='auto', cutoff=cutoff) if is_cg is None: interaction = espressopp.interaction.FixedPairListLennardJones(system, fpl, pot) else: interaction = espressopp.interaction.FixedPairListAdressLennardJones( system, fpl, pot, is_cg) system.addInteraction(interaction, 'lj-14_{}{}'.format(pid, '_cross' if cross_bonds else '')) # Set Coulomb14 if static_14_pairs or cross_14_pairs_cg or cross_14_pairs_at: type_pairs = set() for type_1, pi in input_conf.atomtypeparams.iteritems(): for type_2, pj in input_conf.atomtypeparams.iteritems(): if pi['particletype'] != 'V' and pj['particletype'] != 'V': type_pairs.add(tuple(sorted([type_1, type_2]))) type_pairs = sorted(type_pairs) print('Using fudgeQQ: {}, type_pairs: {}'.format(fudgeQQ, len(type_pairs))) potQQ = espressopp.interaction.CoulombTruncated(prefactor=pref, cutoff=coulomb_cutoff) if static_14_pairs: print('Defined {} of static coulomb 1-4 pairs'.format(len(static_14_pairs))) fpl_static = espressopp.FixedPairList(system.storage) fpl_static.addBonds(static_14_pairs) interaction_static = espressopp.interaction.FixedPairListTypesCoulombTruncated(system, fpl_static) for type_1, type_2 in type_pairs: interaction_static.setPotential(type1=type_1, type2=type_2, potential=potQQ) system.addInteraction(interaction_static, 'coulomb14') if cross_14_pairs_cg: print('Defined {} of cross coulomb CG 1-4 pairs'.format(len(cross_14_pairs_cg))) fpl_cross = espressopp.FixedPairList(system.storage) fpl_cross.addBonds(cross_14_pairs_cg) # Now set cross potential. interaction_dynamic = espressopp.interaction.FixedPairListAdressTypesCoulombTruncated( system, fpl_cross, True) for type_1, type_2 in type_pairs: interaction_dynamic.setPotential(type1=type_1, type2=type_2, potential=potQQ) system.addInteraction(interaction_dynamic, 'coulomb14_cg_cross') if cross_14_pairs_at: print('Defined {} of cross coulomb AT 1-4 pairs'.format(len(cross_14_pairs_at))) fpl_cross = espressopp.FixedPairList(system.storage) fpl_cross.addBonds(cross_14_pairs_at) # Now set cross potential. interaction_dynamic = espressopp.interaction.FixedPairListAdressTypesCoulombTruncated( system, fpl_cross, False) for type_1, type_2 in type_pairs: interaction_dynamic.setPotential(type1=type_1, type2=type_2, potential=potQQ) system.addInteraction(interaction_dynamic, 'coulomb14_at_cross')
def test_rattle(self): #add particles # 4-3-5 # | # | # 2-1 particle_list = [(6, 1, espressopp.Real3D(3.2, 3.3, 3.0), espressopp.Real3D(0, 0, 0), 9.0, 0), (1, 0, espressopp.Real3D(3.2, 3.1, 3.0), espressopp.Real3D(0.27, -0.07, 0.10), 3.0, 1), (2, 0, espressopp.Real3D(3.1, 3.1, 3.0), espressopp.Real3D(0.23, 0.22, 0.00), 1.0, 1), (3, 0, espressopp.Real3D(3.2, 3.3, 3.0), espressopp.Real3D(0.24, -0.37, -0.10), 3.0, 1), (4, 0, espressopp.Real3D(3.1, 3.3, 3.0), espressopp.Real3D(0.14, 0.20, -0.05), 1.0, 1), (5, 0, espressopp.Real3D(3.3, 3.3, 3.0), espressopp.Real3D(0.04, 0.17, -0.20), 1.0, 1)] tuples = [(6, 1, 2, 3, 4, 5)] constrainedBondsList = [[1, 2, 0.1, 3.0, 1.0], [3, 4, 0.1, 3.0, 1.0], [3, 5, 0.1, 3.0, 1.0]] #pid1,pid2,constraintDist,mass1,mass2 constraintDist2 = [] for bond in constrainedBondsList: constraintDist2.append(bond[2] * bond[2]) self.system.storage.addParticles(particle_list, 'id', 'type', 'pos', 'v', 'mass', 'adrat') ftpl = espressopp.FixedTupleListAdress(self.system.storage) ftpl.addTuples(tuples) self.system.storage.setFixedTuplesAdress(ftpl) self.system.storage.decompose() vl = espressopp.VerletListAdress(self.system, cutoff=1.5, adrcut=1.5, dEx=2.0, dHy=1.0, pids=[6], sphereAdr=True) #one unconstrained bond fpl = espressopp.FixedPairListAdress(self.system.storage, ftpl) fpl.addBonds([(1, 3)]) pot = espressopp.interaction.Harmonic(K=5.0, r0=0.2) interB = espressopp.interaction.FixedPairListHarmonic( self.system, fpl, pot) self.system.addInteraction(interB) #some angles ftl = espressopp.FixedTripleListAdress(self.system.storage, ftpl) ftl.addTriples([(2, 1, 3), (1, 3, 4), (1, 3, 5)]) pot = espressopp.interaction.AngularHarmonic(K=5.0, theta0=math.pi / 2.0) interA = espressopp.interaction.FixedTripleListAngularHarmonic( self.system, ftl, pot) self.system.addInteraction(interA) #initialize lambda values integrator = espressopp.integrator.VelocityVerlet(self.system) adress = espressopp.integrator.Adress(self.system, vl, ftpl) integrator.addExtension(adress) espressopp.tools.AdressDecomp(self.system, integrator) rattle = espressopp.integrator.Rattle(self.system, maxit=1000, tol=1e-6, rptol=1e-6) rattle.addConstrainedBonds(constrainedBondsList) integrator.addExtension(rattle) integrator.run(5) #check if bond lengths are the same as constraint lengths for i, bond in enumerate(constrainedBondsList): pid1 = bond[0] pid2 = bond[1] dist2 = sqrlen( self.system.bc.getMinimumImageVector( self.system.storage.getParticle(pid1).pos, self.system.storage.getParticle(pid2).pos)) self.assertAlmostEqual(constraintDist2[i], dist2, places=6) #check velocities after 5 steps of deterministic simulation vsum = 0.0 for pid in xrange(1, 6): part = self.system.storage.getParticle(pid) vsum += sqrlen(part.v) self.assertAlmostEqual(vsum, 0.3842668659, places=6)