def test_on_radius(self): # set up normal domain decomposition box = (10, 10, 10) nodeGrid = espressopp.tools.decomp.nodeGrid( espressopp.MPI.COMM_WORLD.size, box, rc=1.5, skin=0.3) cellGrid = espressopp.tools.decomp.cellGrid(box, nodeGrid, rc=1.5, skin=0.3) self.system.storage = espressopp.storage.DomainDecomposition( self.system, nodeGrid, cellGrid) # add some particles (normal, coarse-grained particles only) particle_list = [ (1, 1, 0, espressopp.Real3D(5.5, 5.0, 5.0), 1.0, 0, 1.), (2, 1, 0, espressopp.Real3D(6.5, 5.0, 5.0), 1.0, 0, 1.), (3, 1, 0, espressopp.Real3D(7.5, 5.0, 5.0), 1.0, 0, 1.), ] self.system.storage.addParticles(particle_list, 'id', 'type', 'q', 'pos', 'mass', 'adrat', 'radius') self.system.storage.decompose() # generate a verlet list vl = espressopp.VerletList(self.system, cutoff=1.5) # integrator integrator = espressopp.integrator.VelocityVerlet(self.system) integrator.dt = 0.01 # integrator on radius radius_mass = 10. integratorOnRadius = espressopp.integrator.VelocityVerletOnRadius( self.system, dampingmass=radius_mass) integrator.addExtension(integratorOnRadius) # Langevin Thermostat on Radius langevin = espressopp.integrator.LangevinThermostatOnRadius( self.system, dampingmass=radius_mass) langevin.gamma = 1.0 langevin.temperature = 10.0 langevin.addExclusions([1]) integrator.addExtension(langevin) # coordinates of particles before integration before = [ self.system.storage.getParticle(i).radius for i in range(1, 4) ] # run ten steps integrator.run(10) # coordinates of particles after integration after = [ self.system.storage.getParticle(i).radius for i in range(1, 4) ] # run checks (first particle excluded, hence it's radius should not change. The other should have changed, however, as they feel the thermostat on radius) self.assertEqual(before[0], after[0]) self.assertNotEqual(before[1], after[1]) self.assertNotEqual(before[2], after[2])
def test_tab_dih(self): # integrator integrator = espressopp.integrator.VelocityVerlet(self.system) integrator.dt = 0.001 # now build Verlet List # ATTENTION: you must not add the skin explicitly here logging.getLogger("Interpolation").setLevel(logging.INFO) vl = espressopp.VerletList(self.system, cutoff = cutoff) # bonds writeTabFile(tabBond, k=400000, x0=0.4, N=500, low=0.01, high=0.80) fpl = espressopp.FixedPairList(self.system.storage) fpl.addBonds([(0,1),(1,2),(2,3)]) potBond = espressopp.interaction.Tabulated(itype=spline, filename=tabBond) interBond = espressopp.interaction.FixedPairListTabulated(self.system, fpl, potBond) self.system.addInteraction(interBond) # dihedral spring = 10 x_rest = 0.0 writeTabFile(tabDih, k=spring, x0=x_rest, N=500, low=-np.pi, high=np.pi) fql = espressopp.FixedQuadrupleList(self.system.storage) fql.addQuadruples([(0,1,2,3)]) potDihed1 = espressopp.interaction.TabulatedDihedral(itype=spline, filename=tabDih) interDihed1 = espressopp.interaction.FixedQuadrupleListTabulatedDihedral(self.system, fql, potDihed1) potDihed2 = espressopp.interaction.DihedralHarmonic(spring, x_rest) interDihed2 = espressopp.interaction.FixedQuadrupleListDihedralHarmonic(self.system, fql, potDihed2) self.system.addInteraction(interDihed1) temp = espressopp.analysis.Temperature(self.system) temperature = temp.compute() Ek = 0.5 * temperature * (3 * numParticles) Ep = interDihed1.computeEnergy() # langevin thermostat langevin = espressopp.integrator.LangevinThermostat(self.system) integrator.addExtension(langevin) langevin.gamma = 1.0 langevin.temperature = 2.479 # in kJ/mol print("Running at temperature T = {:.3f} kJ/mol/k_B".format(langevin.temperature)) start_time = time.process_time() print(" ***") print("{:8s} {:8s} {:8s}".format("Step","E_tab","E_harm")) for k in range(nsnapshots): Ed1, Ed2 = interDihed1.computeEnergy(), interDihed2.computeEnergy() if k % 10 == 0: self.assertAlmostEqual(Ed1, Ed2, places=2) print('{:8d} {:8f} {:8f}'.format(((k+10)*nsteps),Ed1, Ed2)) integrator.run(nsteps)
def test_cap_force_array_group(self): # set up normal domain decomposition nodeGrid = espressopp.tools.decomp.nodeGrid( espressopp.MPI.COMM_WORLD.size) cellGrid = espressopp.tools.decomp.cellGrid(self.box, nodeGrid, 1.5, 0.3) self.system.storage = espressopp.storage.DomainDecomposition( self.system, nodeGrid, cellGrid) # add some particles (normal, coarse-grained particles only) particle_list = [ (1, 0, 0, espressopp.Real3D(4.95, 5.0, 5.0), 1.0, 0, 1.), (2, 0, 0, espressopp.Real3D(5.05, 5.0, 5.0), 1.0, 0, 1.), ] self.system.storage.addParticles(particle_list, 'id', 'type', 'q', 'pos', 'mass', 'adrat', 'radius') self.system.storage.decompose() # integrator integrator = espressopp.integrator.VelocityVerlet(self.system) integrator.dt = 0.005 # Lennard-Jones with Verlet list rc_lj = pow(2.0, 1.0 / 6.0) vl = espressopp.VerletList(self.system, cutoff=rc_lj) potLJ = espressopp.interaction.LennardJones(epsilon=1., sigma=1., cutoff=rc_lj, shift=0) interLJ = espressopp.interaction.VerletListLennardJones(vl) interLJ.setPotential(type1=0, type2=0, potential=potLJ) self.system.addInteraction(interLJ) # create a ParticleGroup instance particle_group = espressopp.ParticleGroup(self.system.storage) particle_group.add(1) # create a CapForce instance capforce = espressopp.integrator.CapForce( self.system, espressopp.Real3D(1.0, 1.0, 1.0), particle_group) integrator.addExtension(capforce) # run 1 step integrator.run(1) particle1 = self.system.storage.getParticle(1) particle2 = self.system.storage.getParticle(2) print(particle1.f, particle2.f) # run checks self.assertTrue( math.fabs(particle1.f[0]) == 1.0, "The force of particle 1 is not capped.") self.assertTrue( math.fabs(particle2.f[0]) > 1.0, "The force of particle 2 is capped.")
def test_normal(self): # set up normal domain decomposition nodeGrid = espressopp.tools.decomp.nodeGrid(espressopp.MPI.COMM_WORLD.size) cellGrid = espressopp.tools.decomp.cellGrid((10, 10, 10), nodeGrid, 1.5, 0.3) self.system.storage = espressopp.storage.DomainDecomposition(self.system, nodeGrid, cellGrid) # add some particles (normal, coarse-grained particles only) particle_list = [ (1, 1, 0, espressopp.Real3D(5.5, 5.0, 5.0), 1.0, 0), (2, 1, 0, espressopp.Real3D(6.5, 5.0, 5.0), 1.0, 0), (3, 1, 0, espressopp.Real3D(7.5, 5.0, 5.0), 1.0, 0), ] self.system.storage.addParticles(particle_list, 'id', 'type', 'q', 'pos', 'mass','adrat') self.system.storage.decompose() # generate a verlet list vl = espressopp.VerletList(self.system, cutoff=1.5) # integrator integrator = espressopp.integrator.VelocityVerlet(self.system) integrator.dt = 0.01 # Langevin Thermostat langevin = espressopp.integrator.LangevinThermostat(self.system) langevin.gamma = 1.0 langevin.temperature = 1.0 langevin.adress = False langevin.addExclusions([1]) integrator.addExtension(langevin) # coordinates of particles before integration before =[self.system.storage.getParticle(i).pos[j] for i in range(1,4) for j in range(3)] # run ten steps integrator.run(10) # coordinates of particles after integration after = [self.system.storage.getParticle(i).pos[j] for i in range(1,4) for j in range(3)] # run checks (first particle excluded, hence it should not move. The other should have moved, however, as they feel the thermostat) self.assertEqual(before[0], after[0]) self.assertEqual(before[1], after[1]) self.assertEqual(before[2], after[2]) self.assertNotEqual(before[3], after[3]) self.assertNotEqual(before[4], after[4]) self.assertNotEqual(before[5], after[5]) self.assertNotEqual(before[6], after[6]) self.assertNotEqual(before[7], after[7]) self.assertNotEqual(before[8], after[8])
def setUp(self): system, integrator = espressopp.standard_system.Default(box, rc=rc, skin=0.3, dt=0.005, temperature=1.) system.storage.addParticles([[1,0,espressopp.Real3D(0,0,1)]],'id','type','pos') system.storage.addParticles([[2,0,espressopp.Real3D(0,0,1+math.pow(2,1./6.))]],'id','type','pos') system.storage.decompose() # non-bonded LJcos potential vl = espressopp.VerletList(system, cutoff=rc) LJcos = espressopp.interaction.LJcos(phi=phi) LJcosInter = espressopp.interaction.VerletListLJcos(vl) LJcosInter.setPotential(type1=0, type2=0, potential=LJcos) system.addInteraction(LJcosInter) # set self self.system = system self.LJcosInter = LJcosInter
def setUp(self): self.system, self.integrator = self.create_system() self.vl = espressopp.VerletList(self.system, cutoff=2.5) self.part_prop = ('id', 'type', 'pos', 'res_id', 'state') particle_list = [(1, 1, espressopp.Real3D(2.0, 2.0, 2.0), 1, 1), (2, 2, espressopp.Real3D(2.5, 2.0, 2.0), 2, 1)] self.system.storage.addParticles(particle_list, *self.part_prop) self.fpl1 = espressopp.FixedPairList(self.system.storage) topology_manager = espressopp.integrator.TopologyManager(self.system) topology_manager.observe_tuple(self.fpl1) topology_manager.initialize_topology() self.topology_manager = topology_manager self.integrator.addExtension(topology_manager) self.ar = espressopp.integrator.ChemicalReaction( self.system, self.vl, self.system.storage, topology_manager, 1) self.integrator.addExtension(self.ar) super(ESPPTestCase, self).setUp()
def test_potential(self): particle_list = [ (1, espressopp.Real3D(2.0, 2.0, 2.0), 1.0), (2, espressopp.Real3D(2.1, 2.0, 2.0), 1.0), ] self.system.storage.addParticles(particle_list, 'id', 'pos', 'mass') self.system.storage.decompose() minimize_energy = espressopp.integrator.MinimizeEnergy( self.system, gamma=0.00001, ftol=1.0, max_displacement=0.001) vl = espressopp.VerletList(self.system, cutoff=2.5) lj = espressopp.interaction.LennardJones(sigma=1.0, epsilon=1.0, cutoff=2.5) interaction = espressopp.interaction.VerletListLennardJones(vl) interaction.setPotential(type1=0, type2=0, potential=lj) self.system.addInteraction(interaction) energy_before = interaction.computeEnergy() minimize_energy.run(2000) self.assertLessEqual(minimize_energy.f_max, 1.0) self.assertLess(interaction.computeEnergy(), energy_before)
def setUp(self): box = (10, 10, 10) system = espressopp.System() system.kb = 1.0 system.rng = espressopp.esutil.RNG() system.bc = espressopp.bc.OrthorhombicBC(system.rng, box) system.skin = 0.3 self.system = system nodeGrid = espressopp.tools.decomp.nodeGrid(MPI.COMM_WORLD.size) cellGrid = espressopp.tools.decomp.cellGrid(box, nodeGrid, 2.5, system.skin) system.storage = espressopp.storage.DomainDecomposition( system, nodeGrid, cellGrid) self.integrator = espressopp.integrator.VelocityVerlet(system) self.integrator.dt = 0.0025 vl = espressopp.VerletList(system, cutoff=1.0) self.part_prop = ('id', 'type', 'pos', 'res_id', 'state') particle_list = [(1, 1, espressopp.Real3D(2.0, 2.0, 2.0), 1, 1), (2, 2, espressopp.Real3D(2.5, 2.0, 2.0), 2, 1), (3, 2, espressopp.Real3D(2.5, 2.0, 2.0), 2, 2), (4, 4, espressopp.Real3D(2.5, 2.0, 2.0), 2, 1)] system.storage.addParticles(particle_list, *self.part_prop) self.fpl1 = espressopp.FixedPairList(system.storage) topology_manager = espressopp.integrator.TopologyManager(system) topology_manager = topology_manager topology_manager.observe_tuple(self.fpl1) topology_manager.initialize_topology() self.topology_manager = topology_manager self.integrator.addExtension(topology_manager) self.ar = espressopp.integrator.ChemicalReaction( system, vl, system.storage, topology_manager, 1) self.integrator.addExtension(self.ar)
rc = 2 * pow(2, 1./6.) skin = 0.3 dt = 0.000001 epsilon = 0. sigma = 1. temperature = 1.2 print "Initial values" system = espressopp.System() system.rng = espressopp.esutil.RNG() system.bc = espressopp.bc.OrthorhombicBC(system.rng, box) system.skin = skin nodeGrid = espressopp.tools.decomp.nodeGrid(espressopp.MPI.COMM_WORLD.size) cellGrid = espressopp.tools.decomp.cellGrid(box, nodeGrid, rc, skin) system.storage = espressopp.storage.DomainDecomposition(system, nodeGrid, cellGrid) interaction = espressopp.interaction.VerletListLennardJones(espressopp.VerletList(system, cutoff=rc)) potLJ = espressopp.interaction.LennardJones(epsilon, sigma, rc) interaction.setPotential(type1=0, type2=0, potential=potLJ) system.addInteraction(interaction) integrator = espressopp.integrator.VelocityVerlet(system) integrator.dt = dt thermostat = espressopp.integrator.LangevinThermostat(system) thermostat.gamma = 1.0 thermostat.temperature = temperature integrator.addExtension(thermostat) print integrator.dt print thermostat.gamma print thermostat.temperature
if countY >= N: countY = 0 countZ += 1 # adding particles to Ewald system systemEwald.storage.addParticles(new_particles, *props) systemEwald.storage.decompose() # adding particles to PPPM system systemPPPM.storage.addParticles(new_particles, *props) systemPPPM.storage.decompose() ## potentials and interactions ## # setting a Verlet list vlEwald = espressopp.VerletList(systemEwald, rspacecutoff) vlPPPM = espressopp.VerletList(systemPPPM, rspacecutoff) # real space interaction for Ewald system # R space part of electrostatic interaction coulombR_potEwald = espressopp.interaction.CoulombRSpace( coulomb_prefactor, alphaEwald, rspacecutoff) # creating an interaction based on the Verlet list coulombR_intEwald = espressopp.interaction.VerletListCoulombRSpace(vlEwald) # setting the potential for the interaction between particles of type 0 and 0 coulombR_intEwald.setPotential(type1=0, type2=0, potential=coulombR_potEwald) # adding the interaction to the system systemEwald.addInteraction(coulombR_intEwald) # real space interaction for PPPM system # R space part of electrostatic interaction
for i in range(num_chains): #print "Init LJ3:", i for j in range(monomers_per_chain): goal = min(j + 3, monomers_per_chain) for k in range(j + 1, goal): #print "Init LJ3:", i*monomers_per_chain + j, i*monomers_per_chain + k dmy_pair = [i * monomers_per_chain + j, i * monomers_per_chain + k] exclusion_list.append(dmy_pair) capradO = 2.**(1. / 6.) * sigma potLJO = espressopp.interaction.LennardJonesCapped(epsilon, sigma, cutoff=rc_lj, caprad=capradO, shift=0) print("Init LJ4") vl = espressopp.VerletList(system, cutoff=rc_lj, exclusionlist=exclusion_list) interLJO = espressopp.interaction.VerletListLennardJonesCapped(vl) #for i in xrange(num_chains): # interLJ.setPotential(type1=i, type2=i, potential=potLJ) #for i in xrange(num_chains): # for j in xrange(i, num_chains): # interLJO.setPotential(type1=i, type2=j, potential=potLJO)# that should be reused in fb loops interLJO.setPotential(type1=0, type2=0, potential=potLJO) # that should be reused in fb loops system.addInteraction(interLJO) print("Init FENE") # FENE bonds potFENE = espressopp.interaction.FENECapped(K=K_fene, r0=r0_fene, rMax=rmax_fene,
def LennardJones(num_particles, box=(0, 0, 0), rc=1.12246, skin=0.3, dt=0.005, epsilon=1.0, sigma=1.0, shift='auto', temperature=None, xyzfilename=None, xyzrfilename=None): if xyzfilename and xyzrfilename: print "ERROR: only one of xyzfilename (only xyz data) or xyzrfilename (additional particle radius data) can be provided." sys.exit(1) if xyzrfilename: pidf, typef, xposf, yposf, zposf, xvelf, yvelf, zvelf, Lxf, Lyf, Lzf, radiusf = espressopp.tools.readxyzr( xyzrfilename) box = (Lxf, Lyf, Lzf) num_particles = len(pidf) elif xyzfilename: pidf, typef, xposf, yposf, zposf, xvelf, yvelf, zvelf, Lxf, Lyf, Lzf = espressopp.tools.readxyz( xyzfilename) box = (Lxf, Lyf, Lzf) num_particles = len(pidf) else: if box[0] <= 0 or box[1] <= 0 or box[2] <= 0: print "WARNING: no valid box size specified, box size set to (100,100,100) !" system = espressopp.System() system.rng = espressopp.esutil.RNG() system.bc = espressopp.bc.OrthorhombicBC(system.rng, box) system.skin = skin nodeGrid = espressopp.tools.decomp.nodeGrid(MPI.COMM_WORLD.size) cellGrid = espressopp.tools.decomp.cellGrid(box, nodeGrid, rc, skin) system.storage = espressopp.storage.DomainDecomposition( system, nodeGrid, cellGrid) interaction = espressopp.interaction.VerletListLennardJones( espressopp.VerletList(system, cutoff=rc)) interaction.setPotential(type1=0, type2=0, potential=espressopp.interaction.LennardJones( epsilon, sigma, rc, shift)) system.addInteraction(interaction) integrator = espressopp.integrator.VelocityVerlet(system) integrator.dt = dt if (temperature != None): thermostat = espressopp.integrator.LangevinThermostat(system) thermostat.gamma = 1.0 thermostat.temperature = temperature integrator.addExtension(thermostat) mass = 1.0 if xyzrfilename: new_particles = [] props = ['id', 'type', 'mass', 'pos', 'v', 'radius'] for idx in xrange(num_particles): part = [ pidf[idx], typef[idx], mass, espressopp.Real3D(xposf[idx], yposf[idx], zposf[idx]), espressopp.Real3D(xvelf[idx], yvelf[idx], zvelf[idx]), radiusf[idx] ] new_particles.append(part) if idx % 1000 == 0: system.storage.addParticles(new_particles, *props) system.storage.decompose() new_particles = [] system.storage.addParticles(new_particles, *props) system.storage.decompose() elif xyzfilename: new_particles = [] props = ['id', 'type', 'mass', 'pos', 'v'] for idx in xrange(num_particles): part = [ pidf[idx], typef[idx], mass, espressopp.Real3D(xposf[idx], yposf[idx], zposf[idx]), espressopp.Real3D(xvelf[idx], yvelf[idx], zvelf[idx]) ] new_particles.append(part) if idx % 1000 == 0: system.storage.addParticles(new_particles, *props) system.storage.decompose() new_particles = [] system.storage.addParticles(new_particles, *props) system.storage.decompose() else: props = ['id', 'type', 'mass', 'pos', 'v'] new_particles = [] pid = 1 while pid <= num_particles: type = 0 mass = 1.0 pos = system.bc.getRandomPos() vel = espressopp.Real3D(0.0, 0.0, 0.0) part = [pid, type, mass, pos, vel] new_particles.append(part) if pid % 1000 == 0: system.storage.addParticles(new_particles, *props) system.storage.decompose() new_particles = [] pid += 1 system.storage.addParticles(new_particles, *props) system.storage.decompose() return system, integrator
def createPathintegralSystem(allParticles, props, types, system, exclusions, integrator, langevin, rcut, P, polymerInitR=0.01, hbar=0.063507807, disableVVL=False): # Turns the classical system into a Pathintegral system with P beads numtypes = max(types) + 1 num_cla_part = len(allParticles) ## make a dictionary for properties ##(TODO: better to use esp++ particle ?) propDict = {} for p in props: propDict.update({p: len(propDict)}) piParticles = [] ringids = { } #dict with key: classical particle id, value vector of ids in the ring polymer vptuples = [] if not disableVVL: vcl = espressopp.CellList() ftpl = espressopp.FixedTupleList(system.storage) #vvl=espressopp.VirtualVerletList(system, rcut, ftpl) vvl = espressopp.VirtualVerletList(system, rcut, ftpl) # create a cell list which will store the virtual particles after domain decomposition vvl.setCellList(vcl) ## some data structures that will be usefull later ## ringids has all imaginary time beads belonging to a classical bead pid ## allParticlesById is used to acces particles properties by pid allParticlesById = {} for p in allParticles: pid = p[propDict['id']] ringids.update({pid: []}) allParticlesById.update({pid: p}) for i in xrange(1, P): for p in allParticles: pid = p[propDict['id']] newparticle = copy.deepcopy(p) # set types accoring to imag time index newparticle[propDict['type']] = newparticle[ propDict['type']] + numtypes * i # set positions newpos = newparticle[propDict['pos']] newpos[0] = newpos[0] + polymerInitR * math.cos( i * 2 * math.pi / P) - polymerInitR newpos[1] = newpos[1] + polymerInitR * math.sin( i * 2 * math.pi / P) newid = len(allParticles) + len(piParticles) + 1 newparticle[propDict['id']] = newid piParticles.append(newparticle) ringids[pid].append(newid) if not disableVVL: iVerletLists = {} for i in xrange(1, P + 1): iVerletLists.update( {i: espressopp.VerletList(system, 0, rebuild=False)}) iVerletLists[i].disconnect() ## map types to sub-verlet lists using the VirtualVerletList classical ## classical types are in types ## type at imaginary time i=t+numtypes*i for i in xrange(1, P + 1): tt = [] for j in xrange(0, numtypes): pitype = types[j] + numtypes * (i - 1) tt.append(pitype) #print i, "mapped", tt, " to ", iVerletLists[i] vvl.mapTypeToVerletList(tt, iVerletLists[1]) system.storage.addParticles(piParticles, *props) #print "1 PYTHON IMG 1947", system.storage.getParticle(1947).pos, system.storage.getParticle(1947).imageBox #print "RINGIDS", ringids # store each ring in a FixedTupleList if not disableVVL: vParticles = [] vptype = numtypes * ( P + 1) + 1 # this is the type assigned to virtual particles for k, v in ringids.iteritems(): cog = allParticlesById[k][propDict['pos']] for pid in v: cog = cog + allParticlesById[k][propDict['pos']] cog = cog / (len(v) + 1) #create a virtual particle for each ring vpprops = ['id', 'pos', 'v', 'type', 'mass', 'q'] vpid = len(allParticles) + len(piParticles) + len(vParticles) + 1 part = [vpid, cog, Real3D(0, 0, 0), vptype, 0, 0] vParticles.append(part) # first item in tuple is the virtual particle id: t = [vpid] t.append(k) t = t + v vptuples.append(t) #print "VPARTICLE", part, "TUPLE", t system.storage.addParticles(vParticles, *vpprops) #always decpmpose before adding tuples system.storage.decompose() for t in vptuples: ftpl.addTuple(t) extVP = espressopp.integrator.ExtVirtualParticles(system, vcl) extVP.addVirtualParticleTypes([vptype]) extVP.setFixedTupleList(ftpl) integrator.addExtension(extVP) # expand non-bonded potentials numInteraction = system.getNumberOfInteractions() for n in xrange(numInteraction): interaction = system.getInteraction(n) ## TODO: in case of VVL: clone interaction, add potential! print "expanding interaction", interaction if interaction.bondType() == espressopp.interaction.Nonbonded: for i in xrange(P): for j in xrange(numtypes): for k in xrange(numtypes): pot = interaction.getPotential(j, k) interaction.setPotential(numtypes * i + j, numtypes * i + k, pot) print "Interaction", numtypes * i + j, numtypes * i + k, pot if not disableVVL: vl = interaction.getVerletList() #print "VL has", vl.totalSize(),"disconnecting" vl.disconnect() interaction.setVerletList(iVerletLists[1]) if interaction.bondType() == espressopp.interaction.Pair: bond_fpl = interaction.getFixedPairList() cla_bonds = [] # loop over bond lists returned by each cpu for l in bond_fpl.getBonds(): cla_bonds.extend(l) #print "CLA BONDS", bond_fpl.size() for i in xrange(1, P): tmp = 0 for b in cla_bonds: # create additional bonds for this imag time bond_fpl.add(b[0] + num_cla_part * i, b[1] + num_cla_part * i) tmp += 1 #print "trying to add", tmp, "bonds" #print "i=", i, " PI BONDS", bond_fpl.size() if interaction.bondType() == espressopp.interaction.Angular: angle_ftl = interaction.getFixedTripleList() # loop over triple lists returned by each cpu cla_angles = [] for l in angle_ftl.getTriples(): cla_angles.extend(l) #print "CLA_ANGLES", cla_angles for i in xrange(1, P): for a in cla_angles: # create additional angles for this imag time angle_ftl.add(a[0] + num_cla_part * i, a[1] + num_cla_part * i, a[2] + num_cla_part * i) if interaction.bondType() == espressopp.interaction.Dihedral: dihedral_fql = interaction.getFixedQuadrupleList() cla_dihedrals = [] for l in dihedral_fql.getQuadruples(): cla_dihedrals.extend(l) for i in xrange(1, P): for d in cla_dihedrals: # create additional dihedrals for this imag time dihedral_fql.add(d[0] + num_cla_part * i, d[1] + num_cla_part * i, d[2] + num_cla_part * i, d[3] + num_cla_part * i) piexcl = [] for i in xrange(1, P): for e in exclusions: # create additional exclusions for this imag time piexcl.append((e[0] + num_cla_part * i, e[1] + num_cla_part * i)) exclusions.extend(piexcl) if not disableVVL: vvl.exclude(exclusions) # now we analyze how many unique different masses are in the system as we have to create an harmonic spring interaction for each of them unique_masses = [] for p in allParticles: mass = p[propDict['mass']] if not mass in unique_masses: unique_masses.append(mass) kineticTermInteractions = { } # key: mass value: corresponding harmonic spring interaction for m in unique_masses: fpl = espressopp.FixedPairList(system.storage) k = m * P * P * langevin.temperature * langevin.temperature / (hbar * hbar) pot = espressopp.interaction.Harmonic(k, 0.0) interb = espressopp.interaction.FixedPairListHarmonic(system, fpl, pot) system.addInteraction(interb) kineticTermInteractions.update({m: interb}) for idcla, idpi in ringids.iteritems(): p = allParticlesById[idcla] mass = p[propDict['mass']] interactionList = kineticTermInteractions[mass].getFixedPairList( ) #find the appropriate interaction based on the mass # harmonic spring between atom at imag-time i and imag-time i+1 for i in xrange(len(idpi) - 1): interactionList.add(idpi[i], idpi[i + 1]) #close the ring interactionList.add(idcla, idpi[0]) interactionList.add(idcla, idpi[len(idpi) - 1]) # instead of scaling the potentials, we scale the temperature! langevin.temperature = langevin.temperature * P if not disableVVL: return iVerletLists
system.storage = espressopp.storage.DomainDecomposition( system, nodeGrid, cellGrid) # Adding the particles props = ['id', 'pos', 'type', 'q'] new_particles = [] for i in range(0, num_particles): part = [i, Real3D(x[i], y[i], z[i]), type[i], q[i]] new_particles.append(part) system.storage.addParticles(new_particles, *props) system.storage.decompose() ## potential and interaction ## # setting the Verlet list vl = espressopp.VerletList(system, rspacecutoff + skin) # the R space part of electrostatic interaction according to the Ewald method ''' Creating the Coulomb potential which is responsible for the R space part according to the Ewald method. It is based on the Coulomb prefactor (coulomb_prefactor), Ewald parameter (alpha), and the cutoff in R space (rspacecutoff) ''' coulombR_pot = espressopp.interaction.CoulombRSpace(coulomb_prefactor, alpha, rspacecutoff) # creating the interaction based on the Verlet list coulombR_int = espressopp.interaction.VerletListCoulombRSpace(vl) # setting the potential for the interaction between particles of type 0 and 0 coulombR_int.setPotential(type1=0, type2=0, potential=coulombR_pot) # adding the interaction to the system
sys.stdout.write('Setting up simulation ...\n') system = espressopp.System() system.rng = espressopp.esutil.RNG() system.bc = espressopp.bc.OrthorhombicBC(system.rng, size) system.skin = skin comm = MPI.COMM_WORLD nodeGrid = decomp.nodeGrid(comm.size) cellGrid = decomp.cellGrid(size, nodeGrid, rc, skin) system.storage = espressopp.storage.DomainDecomposition( system, nodeGrid, cellGrid) # setting up GROMACS interaction stuff # create a force capped Lennard-Jones interaction that uses a verlet list verletlist = espressopp.VerletList(system, rc) interaction = espressopp.interaction.VerletListLennardJonesGromacs(verletlist) # add particles to the system and then decompose props = ['id', 'pos', 'v', 'type', 'mass', 'q'] allParticles = [] for pid in range(num_particles): part = [ pid + 1, Real3D(x[pid], y[pid], z[pid]), Real3D(vx[pid], vy[pid], vz[pid]), types[pid], masses[pid], charges[pid] ] allParticles.append(part) system.storage.addParticles(allParticles, *props) system.storage.decompose()
def init_polymer_melt_simulation(use_replicate_parallel): start_time = time.process_time() bonds, angles, x, y, z, Lx, Ly, Lz = espressopp.tools.lammps.read('polymer_melt.lammps') if use_replicate_parallel: # rp stores bonds, angles, and positions rp = espressopp.tools.ReplicateParallel() num_particles, Lx, Ly, Lz = rp.replicate(bonds, angles, x, y, z, Lx, Ly, Lz, *repl) else: bonds, angles, x, y, z, Lx, Ly, Lz = espressopp.tools.replicate(bonds, angles, x, y, z, Lx, Ly, Lz, *repl) num_particles = len(x) density = num_particles / (Lx * Ly * Lz) box = (Lx, Ly, Lz) system, integrator = espressopp.standard_system.Default(box=box, rc=rc, skin=skin, dt=timestep, temperature=temperature) if use_replicate_parallel: props = ['type', 'mass'] num_particles_seed = len(x) seed_particles = [] for i in range(num_particles_seed): part = [0, 1.0] seed_particles.append(part) # rp workers add replicated particles in parallel rp.addParticles(system.storage, 1, seed_particles, *props) else: # add particles to the system and then decompose # do this in chunks of 1000 particles to speed it up props = ['id', 'type', 'mass', 'pos'] new_particles = [] for i in range(num_particles): part = [i + 1, 0, 1.0, espressopp.Real3D(x[i], y[i], z[i])] new_particles.append(part) if i % 1000 == 0: system.storage.addParticles(new_particles, *props) system.storage.decompose() new_particles = [] system.storage.addParticles(new_particles, *props) system.storage.decompose() # Lennard-Jones with Verlet list vl = espressopp.VerletList(system, cutoff = rc) potLJ = espressopp.interaction.LennardJones(epsilon=1.0, sigma=1.0, cutoff=rc, shift=0) interLJ = espressopp.interaction.VerletListLennardJones(vl) interLJ.setPotential(type1=0, type2=0, potential=potLJ) system.addInteraction(interLJ) # FENE bonds fpl = espressopp.FixedPairList(system.storage) if use_replicate_parallel: # rp workers add replicated bonds in parallel rp.addBonds(fpl) else: fpl.addBonds(bonds) potFENE = espressopp.interaction.FENE(K=30.0, r0=0.0, rMax=1.5) interFENE = espressopp.interaction.FixedPairListFENE(system, fpl, potFENE) system.addInteraction(interFENE) # Cosine with FixedTriple list ftl = espressopp.FixedTripleList(system.storage) if use_replicate_parallel: # rp workers add replicated triples in parallel rp.addTriples(ftl) else: ftl.addTriples(angles) potCosine = espressopp.interaction.Cosine(K=1.5, theta0=3.1415926) interCosine = espressopp.interaction.FixedTripleListCosine(system, ftl, potCosine) system.addInteraction(interCosine) end_time = time.process_time() # get positions, bonds and angles configurations = espressopp.analysis.Configurations(system, pos=True, vel=False, force=False) configurations.gather() pos = [configurations[0][i] for i in range(num_particles)] bonds = np.array(fpl.getBonds()) angles = np.array(ftl.getTriples()) return end_time - start_time, pos, bonds, angles
def PolymerMelt(num_chains, nsolvents, monomers_per_chain, box=(0, 0, 0), bondlen=0.97, rc=1.12246, skin=0.3, dt=0.005, epsilon=1.0, sigma=1.0, shift='auto', temperature=None, xyzfilename=None, monomer_type=0, solvent_type=1): if xyzfilename: pidf, typef, xposf, yposf, zposf, xvelf, yvelf, zvelf, Lxf, Lyf, Lzf = espressopp.tools.readxyz( xyzfilename) box = (Lxf, Lyf, Lzf) else: if box[0] <= 0 or box[1] <= 0 or box[2] <= 0: print "WARNING: no valid box size specified, box size set to (100,100,100) !" box = (100, 100, 100) system = espressopp.System() system.rng = espressopp.esutil.RNG() system.bc = espressopp.bc.OrthorhombicBC(system.rng, box) system.skin = skin nodeGrid = espressopp.tools.decomp.nodeGrid(MPI.COMM_WORLD.size) cellGrid = espressopp.tools.decomp.cellGrid(box, nodeGrid, rc, skin) system.storage = espressopp.storage.DomainDecomposition( system, nodeGrid, cellGrid) # LJ interaction vl = espressopp.VerletList(system, cutoff=rc) interaction = espressopp.interaction.VerletListLennardJones(vl) interaction.setPotential( type1=monomer_type, type2=monomer_type, potential=espressopp.interaction.LennardJones(epsilon, sigma, rc, shift)) interaction.setPotential( type1=solvent_type, type2=solvent_type, potential=espressopp.interaction.LennardJones(epsilon, sigma, rc, shift)) interaction.setPotential( type1=monomer_type, type2=solvent_type, potential=espressopp.interaction.LennardJones(epsilon, sigma, rc, shift)) system.addInteraction(interaction, 'lj') integrator = espressopp.integrator.VelocityVerlet(system) integrator.dt = dt if (temperature != None): thermostat = espressopp.integrator.LangevinThermostat(system) thermostat.gamma = 1.0 thermostat.temperature = temperature integrator.addExtension(thermostat) mass = 1.0 if xyzfilename: props = ['id', 'type', 'mass', 'pos', 'v'] bondlist = espressopp.FixedPairList(system.storage) particles = [] bonds = [] for i in xrange(num_chains): for k in xrange(monomers_per_chain): idx = i * monomers_per_chain + k part = [pidf[idx], typef[idx], mass, espressopp.Real3D(xposf[idx], yposf[idx], zposf[idx]), espressopp.Real3D(xvelf[idx], yvelf[idx], zvelf[idx])] particles.append(part) if k > 0: bonds.append((pidf[idx - 1], pidf[idx])) # Read solvent for i in xrange(0, nsolvents): idx = num_chains * monomers_per_chain + i part = [pidf[idx], typef[idx], mass, espressopp.Real3D(xposf[idx], yposf[idx], zposf[idx]), espressopp.Real3D(xvelf[idx], yvelf[idx], zvelf[idx])] particles.append(part) system.storage.addParticles(particles, *props) system.storage.decompose() vl.exclude(bonds) bondlist.addBonds(bonds) else: props = ['id', 'type', 'mass', 'pos', 'v'] vel_zero = espressopp.Real3D(0.0, 0.0, 0.0) bondlist = espressopp.FixedPairList(system.storage) pid = 1 particles = [] bonds = [] for i in xrange(num_chains): startpos = system.bc.getRandomPos() positions, b = espressopp.tools.topology.polymerRW( pid, startpos, monomers_per_chain, 1.2) for k in xrange(monomers_per_chain): part = [pid + k, monomer_type, mass, positions[k], vel_zero] particles.append(part) pid += monomers_per_chain bonds.extend(b) for i in xrange(1, nsolvents + 1): startpos = system.bc.getRandomPos() particles.append([pid, solvent_type, mass, startpos, vel_zero]) pid += 1 system.storage.addParticles(particles, *props) system.storage.decompose() vl.exclude(bonds) bondlist.addBonds(bonds) # FENE bonds potFENE=espressopp.interaction.FENELennardJones(K=30.0, r0=0.0, rMax=1.5) interFENE=espressopp.interaction.FixedPairListFENELennardJones( system, bondlist, potFENE) system.addInteraction(interFENE, 'fene') return system, integrator, vl
def generate_vl(useBuffers): print( 'VERLET LIST {}USING BUFFERS'.format('NOT ' if not useBuffers else '')) nsteps = 1 isteps = 10 # # NOTE: For performance comparison increase isteps to 1000 # rc = 2.5 skin = 0.4 timestep = 0.005 dt = 0.005 epsilon = 1.0 sigma = 1.0 # set temperature to None for NVE-simulations temperature = 1.0 xyz_file = "lennard_jones_fluid_10000.xyz" pid, type, xpos, ypos, zpos, xvel, yvel, zvel, Lx, Ly, Lz = readxyz( xyz_file) box = (Lx, Ly, Lz) num_particles = len(pid) system, integrator = espressopp.standard_system.Default( box=box, rc=rc, skin=skin, dt=timestep, temperature=temperature) props = ['id', 'type', 'mass', 'pos', 'v'] new_particles = [] for i in range(num_particles): part = [ i + 1, 0, 1.0, espressopp.Real3D(xpos[i], ypos[i], zpos[i]), espressopp.Real3D(xvel[i], yvel[i], zvel[i]) ] new_particles.append(part) if i % 1000 == 0: system.storage.addParticles(new_particles, *props) system.storage.decompose() new_particles = [] system.storage.addParticles(new_particles, *props) system.storage.decompose() # Lennard-Jones with Verlet list vl = espressopp.VerletList(system, cutoff=rc, useBuffers=useBuffers) potLJ = espressopp.interaction.LennardJones(epsilon=epsilon, sigma=sigma, cutoff=rc, shift=0) interLJ = espressopp.interaction.VerletListLennardJones(vl) interLJ.setPotential(type1=0, type2=0, potential=potLJ) system.addInteraction(interLJ) # espressopp.tools.analyse.info(system, integrator) espressopp.tools.analyse.info(system, integrator) start_time = time.process_time() for k in range(nsteps): integrator.run(isteps) espressopp.tools.analyse.info(system, integrator) end_time = time.process_time() espressopp.tools.analyse.final_info(system, integrator, vl, start_time, end_time) pairs = sum(vl.getAllPairs(), []) return pairs
def setUp(self): # globals global Ni, temperature # constants rc = pow(2, 1. / 6.) skin = 0.3 epsilon = 1. # system set up system = espressopp.System() system.rng = espressopp.esutil.RNG() global Npart if (os.path.isfile(mdoutput)): pid, ptype, x, y, z, vx, vy, vz, Lx, Ly, Lz = espressopp.tools.readxyz( mdoutput) Npart = len(pid) sigma = 1. timestep = 0.005 box = (Lx, Ly, Lz) else: sigma = 0. timestep = 0.001 box = (Ni, Ni, Ni) system.bc = espressopp.bc.OrthorhombicBC(system.rng, box) system.skin = skin nodeGrid = espressopp.tools.decomp.nodeGrid( espressopp.MPI.COMM_WORLD.size) cellGrid = espressopp.tools.decomp.cellGrid(box, nodeGrid, rc, skin) system.storage = espressopp.storage.DomainDecomposition( system, nodeGrid, cellGrid) # interaction interaction = espressopp.interaction.VerletListLennardJones( espressopp.VerletList(system, cutoff=rc)) potLJ = espressopp.interaction.LennardJones(epsilon, sigma, rc) interaction.setPotential(type1=0, type2=0, potential=potLJ) system.addInteraction(interaction) # integrator integrator = espressopp.integrator.VelocityVerlet(system) integrator.dt = timestep # thermostat thermostat = espressopp.integrator.LangevinThermostat(system) thermostat.gamma = 1.0 thermostat.temperature = temperature integrator.addExtension(thermostat) if (os.path.isfile(mdoutput)): props = ['id', 'type', 'mass', 'pos', 'v'] new_particles = [] for pid in range(Npart): part = [ pid + 1, 0, 1.0, Real3D(x[pid], y[pid], z[pid]), Real3D(vx[pid], vy[pid], vz[pid]) ] new_particles.append(part) system.storage.addParticles(new_particles, *props) system.storage.decompose() else: # make dense system particle_list = [] mass = 1. for k in range(Npart): pid = k + 1 pos = system.bc.getRandomPos() v = Real3D(0.) ptype = 0 part = [pid, ptype, mass, pos, v] particle_list.append(part) system.storage.addParticles(particle_list, 'id', 'type', 'mass', 'pos', 'v') system.storage.decompose() print "Warm up. Sigma will be increased from 0. to 1." new_sigma = sigma for k in range(50): integrator.run(100) new_sigma += 0.02 if (new_sigma > 0.8): integrator.dt = 0.005 potLJ = espressopp.interaction.LennardJones( epsilon, new_sigma, rc) interaction.setPotential(type1=0, type2=0, potential=potLJ) espressopp.tools.fastwritexyz(mdoutput, system) # LB will control thermostatting now thermostat.disconnect() integrator.step = 0 # set up LB fluid lb = espressopp.integrator.LatticeBoltzmann(system, nodeGrid) integrator.addExtension(lb) # set initial populations global initDen, initVel initPop = espressopp.integrator.LBInitPopUniform(system, lb) initPop.createDenVel(initDen, Real3D(initVel)) # set up LB profiler global runSteps lb.profStep = int(.5 * runSteps) lboutputScreen = espressopp.analysis.LBOutputScreen(system, lb) ext_lboutputScreen = espressopp.integrator.ExtAnalyze( lboutputScreen, lb.profStep) integrator.addExtension(ext_lboutputScreen) # lb parameters: viscosities, temperature, time contrast b/w MD and LB lb.visc_b = 3. lb.visc_s = 3. lb.lbTemp = temperature lb.nSteps = 5 # set self self.system = system self.lb = lb self.integrator = integrator self.lboutput = lboutputScreen
def test0Build(self): system = espressopp.System() rng = espressopp.esutil.RNG() SIZE = float(N) box = Real3D(SIZE) bc = espressopp.bc.OrthorhombicBC(None, box) system.bc = bc system.rng = rng system.skin = skin comm = espressopp.MPI.COMM_WORLD nodeGrid = (1, 1, comm.size) cellGrid = [1, 1, 1] for i in xrange(3): cellGrid[i] = calcNumberCells(SIZE, nodeGrid[i], cutoff) print 'NodeGrid = %s' % (nodeGrid, ) print 'CellGrid = %s' % cellGrid dd = espressopp.storage.DomainDecomposition(system, comm, nodeGrid, cellGrid) system.storage = dd id = 0 for i in xrange(N): for j in xrange(N): for k in xrange(N): m = (i + 2 * j + 3 * k) % 11 r = 0.45 + m * 0.01 x = (i + r) / N * SIZE y = (j + r) / N * SIZE z = (k + r) / N * SIZE dd.addParticle(id, Real3D(x, y, z)) # not yet: dd.setVelocity(id, (1.0, 0.0, 0.0)) id = id + 1 dd.decompose() integrator = espressopp.integrator.VelocityVerlet(system) print 'integrator.dt = %g, will be set to 0.005' % integrator.dt integrator.dt = 0.005 print 'integrator.dt = %g, is now ' % integrator.dt # now build Verlet List # ATTENTION: you have to add the skin explicitly here vl = espressopp.VerletList(system, cutoff=cutoff + system.skin) potLJ = espressopp.interaction.LennardJones(1.0, 1.0, cutoff=cutoff) # ATTENTION: auto shift was enabled print "potLJ, shift = %g" % potLJ.shift interLJ = espressopp.interaction.VerletListLennardJones(vl) interLJ.setPotential(type1=0, type2=0, potential=potLJ) # Todo system.addInteraction(interLJ) temp = espressopp.analysis.Temperature(system) temperature = temp.compute() kineticEnergy = 0.5 * temperature * (3 * N * N * N) potentialEnergy = interLJ.computeEnergy() print 'Start: tot energy = %10.6f pot = %10.6f kin = %10.f temp = %10.6f' % ( kineticEnergy + potentialEnergy, potentialEnergy, kineticEnergy, temperature) nsteps = 10 # logging.getLogger("MDIntegrator").setLevel(logging.DEBUG) for i in xrange(20): integrator.run(nsteps) temperature = temp.compute() kineticEnergy = 0.5 * temperature * (3 * N * N * N) potentialEnergy = interLJ.computeEnergy() print 'Step %6d: tot energy = %10.6f pot = %10.6f kin = %10.6f temp = %f' % ( nsteps * (i + 1), kineticEnergy + potentialEnergy, potentialEnergy, kineticEnergy, temperature)
def test0Lattice(self): system = espressopp.System() rng = espressopp.esutil.RNG() N = 6 SIZE = float(N) box = Real3D(SIZE) bc = espressopp.bc.OrthorhombicBC(None, box) system.bc = bc # a small skin avoids rounding problems system.skin = 0.001 cutoff = 1.733 comm = espressopp.MPI.COMM_WORLD nodeGrid = (1, 1, comm.size) cellGrid = [1, 1, 1] for i in xrange(3): cellGrid[i] = calcNumberCells(SIZE, nodeGrid[i], cutoff) print 'NodeGrid = %s' % (nodeGrid, ) print 'CellGrid = %s' % cellGrid system.storage = espressopp.storage.DomainDecomposition( system, nodeGrid, cellGrid) pid = 0 for i in xrange(N): for j in xrange(N): for k in xrange(N): r = 0.5 x = (i + r) / N * SIZE y = (j + r) / N * SIZE z = (k + r) / N * SIZE system.storage.addParticle(pid, Real3D(x, y, z)) pid = pid + 1 system.storage.decompose() # now build Verlet List vl = espressopp.VerletList(system, 0.0) self.assertEqual(vl.totalSize(), 0) vl = espressopp.VerletList(system, 1.0) # there are N * N * N * 6 / 2 pairs in cutoff 1.0 self.assertEqual(vl.totalSize(), N * N * N * 3) # there are N * N * N * 18 / 2 pairs in cutoff sqrt(2.0) vl = espressopp.VerletList(system, math.sqrt(2.0)) self.assertEqual(vl.totalSize(), N * N * N * 9) vl = espressopp.VerletList(system, math.sqrt(3.0)) # there are N * N * N * 26 / 2 pairs in cutoff self.assertEqual(vl.totalSize(), N * N * N * 13)
def setUp(self): # set up system system = espressopp.System() system.rng = espressopp.esutil.RNG() system.bc = espressopp.bc.OrthorhombicBC(system.rng, size) system.skin = skin comm = MPI.COMM_WORLD nodeGrid = Int3D(1, 1, comm.size) cellGrid = Int3D(calcNumberCells(size[0], nodeGrid[0], cutoff), calcNumberCells(size[1], nodeGrid[1], cutoff), calcNumberCells(size[2], nodeGrid[2], cutoff)) system.storage = espressopp.storage.DomainDecomposition( system, nodeGrid, cellGrid) pid = 0 system.storage.addParticle(0, Real3D(0.15, 0.1, 0)) system.storage.addParticle(1, Real3D(0.4, 0.1, 0)) system.storage.decompose() # integrator integrator = espressopp.integrator.VelocityVerlet(system) integrator.dt = 0.001 # now build Verlet List # ATTENTION: you must not add the skin explicitly here logging.getLogger("Interpolation").setLevel(logging.INFO) vl = espressopp.VerletList(system, cutoff=cutoff) scaling_cv = 1.5 alpha = 0.1 # ATTENTION: auto shift was enabled # bonds writeTabFile(tabBonds[0], k=100000, x0=0.26, N=500, low=0.01, high=0.6) writeTabFile(tabBonds[1], k=50000, x0=0.24, N=500, low=0.01, high=0.6) fpl = espressopp.FixedPairList(system.storage) fpl.addBonds([(0, 1)]) potBond = espressopp.interaction.TabulatedSubEns() potBond.addInteraction( 1, tabBonds[0], espressopp.RealND([0.262, 0., 0., scaling_cv * 0.424, 0., 0.])) potBond.addInteraction(1, tabBonds[1], espressopp.RealND([0., 0., 0., 0., 0., 0.])) potBond.alpha_set(alpha) cv_bl = espressopp.FixedPairList(system.storage) cv_bl.addBonds([]) potBond.colVarBondList = cv_bl cv_al = espressopp.FixedTripleList(system.storage) cv_al.addTriples([]) potBond.colVarAngleList = cv_al # Renormalize the CVs potBond.colVarSd_set(0, 0.0119) # Target probabilities potBond.targetProb_set(0, tgt_probs[0]) potBond.targetProb_set(1, tgt_probs[1]) interBond = espressopp.interaction.FixedPairListTabulatedSubEns( system, fpl, potBond) system.addInteraction(interBond) temp = espressopp.analysis.Temperature(system) temperature = temp.compute() Ek = 0.5 * temperature * (2 * numParticles) Ep = interBond.computeEnergy() # langevin thermostat langevin = espressopp.integrator.LangevinThermostat(system) integrator.addExtension(langevin) langevin.gamma = 1.0 langevin.temperature = 2.479 # in kJ/mol # sock = espressopp.tools.vmd.connect(system) configurations = espressopp.analysis.Configurations(system) self.configuration = configurations self.system = system self.temp = temp self.integrator = integrator self.interBond = interBond self.potBond = potBond
pos = system.bc.getRandomPos() # add a particle with particle id pid and coordinate pos to the system # coordinates are automatically folded according to periodic boundary conditions # the following default values are set for each particle: # (type=0, mass=1.0, velocity=(0,0,0), charge=0.0) system.storage.addParticle(pid, pos) # distribute the particles to parallel CPUs system.storage.decompose() ######################################################################## # 5. setting up interaction potential for the warmup # ######################################################################## # create a verlet list that uses a cutoff radius = warmup_cutoff # the verlet radius is automatically increased by system.skin (see system setup) verletlist = espressopp.VerletList(system, warmup_cutoff) # create a force capped Lennard-Jones potential # the potential is automatically shifted so that U(r=cutoff) = 0.0 LJpot = espressopp.interaction.LennardJonesCapped(epsilon=epsilon_start, sigma=sigma, cutoff=warmup_cutoff, caprad=capradius, shift='auto') # create a force capped Lennard-Jones interaction that uses a verlet list interaction = espressopp.interaction.VerletListLennardJonesCapped(verletlist) # tell the interaction to use the above defined force capped Lennard-Jones potential # between 2 particles of type 0 interaction.setPotential(type1=0, type2=0, potential=LJpot) ######################################################################## # 6. running the warmup loop
#nodeGrid = Int3D(1, 1, comm.size) #cellGrid = Int3D( #calcNumberCells(size[0], nodeGrid[0], rc), #calcNumberCells(size[1], nodeGrid[1], rc), #calcNumberCells(size[2], nodeGrid[2], rc) #) system.storage = espressopp.storage.DomainDecomposition(system, nodeGrid, cellGrid, halfCellInt) # add particles to the system and then decompose system.storage.addParticles(new_particles, *props) system.storage.decompose() # Lennard-Jones with Verlet list vl = espressopp.VerletList(system, cutoff = rc + system.skin, useBuffers=useBuffers) if tabulation: interLJ = espressopp.interaction.VerletListTabulated(vl) interLJ.setPotential(type1=0, type2=0, potential=potTabLJ) else: interLJ = espressopp.interaction.VerletListLennardJones(vl) interLJ.setPotential(type1=0, type2=0, potential=potLJ) system.addInteraction(interLJ) # FENE bonds with Fixed Pair List fpl = espressopp.FixedPairList(system.storage) fpl.addBonds(bonds) if tabulation: interFENE = espressopp.interaction.FixedPairListTabulated(system, fpl, potTabFENE) #interFENE.setPotential(type1=0, type2=0, potential=potTabFENE) # no longer needed
def test_normal(self): # set up normal domain decomposition box = (10, 10, 10) nodeGrid = espressopp.tools.decomp.nodeGrid( espressopp.MPI.COMM_WORLD.size, box, rc=1.5, skin=0.3) cellGrid = espressopp.tools.decomp.cellGrid(box, nodeGrid, rc=1.5, skin=0.3) self.system.storage = espressopp.storage.DomainDecomposition( self.system, nodeGrid, cellGrid) # add some particles (normal, coarse-grained particles only) x = [ espressopp.Real3D(5.5, 5.0, 5.0), espressopp.Real3D(6.0, 5.0, 5.0) ] v = [ espressopp.Real3D(0.5, 0.25, 0.25), espressopp.Real3D(-0.25, 0.5, -0.25) ] particle_list = [(1, 1, x[0], v[0], 1.0), (2, 1, x[1], v[1], 1.0)] self.system.storage.addParticles(particle_list, 'id', 'type', 'pos', 'v', 'mass') self.system.storage.decompose() # generate a verlet list vl = espressopp.VerletList(self.system, cutoff=1.5) # integrator integrator = espressopp.integrator.VelocityVerlet(self.system) integrator.dt = 0.01 # DPD Thermostat dpd = espressopp.integrator.DPDThermostat(self.system, vl) dpd.gamma = 2.0 dpd.tgamma = 5.0 dpd.temperature = 2.0 integrator.addExtension(dpd) #This is the first step, which is always a heat-up step, hence the factor of sqrt(3) noise_pref = np.sqrt(3.0 * 24.0 * dpd.temperature / integrator.dt) # coordinates of particles before integration d0 = x[0] - x[1] print(d0, type(d0), x) dist = espressopp.Real3D(d0) dist_norm = np.sqrt(dist * dist) dist_unitv = dist / dist_norm veldiff = espressopp.Real3D(v[0] - v[1]) omega = 1.0 - dist_norm / 1.5 f_expected = [espressopp.Real3D(0.0), espressopp.Real3D(0.0)] #longitudinal contribution r0 = self.system.rng() - 0.5 f_damp = (dist_unitv * veldiff) * dpd.gamma * omega * omega f_noise = noise_pref * np.sqrt(dpd.gamma) * omega * r0 f_expected[0] += (f_noise - f_damp) * dist_unitv f_expected[1] -= (f_noise - f_damp) * dist_unitv #transversal contribution tf_damp = espressopp.Real3D(0.0) tf_damp[0] = (1.0 - dist_unitv[0]*dist_unitv[0])*veldiff[0] \ - dist_unitv[0]*dist_unitv[1]*veldiff[1] \ - dist_unitv[0]*dist_unitv[2]*veldiff[2] tf_damp[1] = (1.0 - dist_unitv[1]*dist_unitv[1])*veldiff[1] \ - dist_unitv[1]*dist_unitv[0]*veldiff[0] \ - dist_unitv[1]*dist_unitv[2]*veldiff[2] tf_damp[2] = (1.0 - dist_unitv[2]*dist_unitv[2])*veldiff[2] \ - dist_unitv[2]*dist_unitv[0]*veldiff[0] \ - dist_unitv[2]*dist_unitv[1]*veldiff[1] tf_noise = espressopp.Real3D(0.0) r1 = self.system.rng() - .5 r2 = self.system.rng() - .5 r3 = self.system.rng() - .5 randvec = espressopp.Real3D(r1, r2, r3) tf_noise[0] = (1.0 - dist_unitv[0]*dist_unitv[0])*randvec[0] \ - dist_unitv[0]*dist_unitv[1]*randvec[1] \ - dist_unitv[0]*dist_unitv[2]*randvec[2] tf_noise[1] = (1.0 - dist_unitv[1]*dist_unitv[1])*randvec[1] \ - dist_unitv[1]*dist_unitv[0]*randvec[0] \ - dist_unitv[1]*dist_unitv[2]*randvec[2] tf_noise[2] = (1.0 - dist_unitv[2]*dist_unitv[2])*randvec[2] \ - dist_unitv[2]*dist_unitv[0]*randvec[0] \ - dist_unitv[2]*dist_unitv[1]*randvec[1] f_expected[0] += ( noise_pref * np.sqrt(dpd.tgamma) * omega * tf_noise\ - dpd.tgamma * omega * omega * tf_damp ) f_expected[1] -= ( noise_pref * np.sqrt(dpd.tgamma) * omega * tf_noise\ - dpd.tgamma * omega * omega * tf_damp ) # calculate forces self.system.rng.seed(1) integrator.run(0) f_result = [ self.system.storage.getParticle(1).f, self.system.storage.getParticle(2).f ] #the checks follow #Do we obey Sir Isaac? self.assertEqual(f_result[0], -1.0 * f_result[1]) #Check if the forces are (almost) equal self.assertAlmostEqual(f_expected[0][0], f_result[0][0], places=5) self.assertAlmostEqual(f_expected[0][1], f_result[0][1], places=5) self.assertAlmostEqual(f_expected[0][2], f_result[0][2], places=5) self.assertAlmostEqual(f_expected[1][0], f_result[1][0], places=5) self.assertAlmostEqual(f_expected[1][1], f_result[1][1], places=5) self.assertAlmostEqual(f_expected[1][2], f_result[1][2], places=5)
def PolymerMelt(num_chains, monomers_per_chain, box=(0, 0, 0), bondlen=0.97, rc=1.12246, skin=0.3, dt=0.005, epsilon=1.0, sigma=1.0, shift='auto', temperature=None, xyzfilename=None, xyzrfilename=None): if xyzfilename and xyzrfilename: print "ERROR: only one of xyzfilename (only xyz data) or xyzrfilename (additional particle radius data) can be provided." sys.exit(1) if xyzrfilename: pidf, typef, xposf, yposf, zposf, xvelf, yvelf, zvelf, Lxf, Lyf, Lzf, radiusf = espressopp.tools.readxyzr( xyzrfilename) box = (Lxf, Lyf, Lzf) elif xyzfilename: pidf, typef, xposf, yposf, zposf, xvelf, yvelf, zvelf, Lxf, Lyf, Lzf = espressopp.tools.readxyz( xyzfilename) box = (Lxf, Lyf, Lzf) else: if box[0] <= 0 or box[1] <= 0 or box[2] <= 0: print "WARNING: no valid box size specified, box size set to (100,100,100) !" box = (100, 100, 100) system = espressopp.System() system.rng = espressopp.esutil.RNG() system.bc = espressopp.bc.OrthorhombicBC(system.rng, box) system.skin = skin nodeGrid = espressopp.tools.decomp.nodeGrid(MPI.COMM_WORLD.size, box, rc, skin) cellGrid = espressopp.tools.decomp.cellGrid(box, nodeGrid, rc, skin) system.storage = espressopp.storage.DomainDecomposition( system, nodeGrid, cellGrid) interaction = espressopp.interaction.VerletListLennardJones( espressopp.VerletList(system, cutoff=rc)) interaction.setPotential(type1=0, type2=0, potential=espressopp.interaction.LennardJones( epsilon, sigma, rc, shift)) system.addInteraction(interaction) integrator = espressopp.integrator.VelocityVerlet(system) integrator.dt = dt if (temperature != None): thermostat = espressopp.integrator.LangevinThermostat(system) thermostat.gamma = 1.0 thermostat.temperature = temperature integrator.addExtension(thermostat) mass = 1.0 if xyzrfilename: props = ['id', 'type', 'mass', 'pos', 'v', 'radius'] bondlist = espressopp.FixedPairList(system.storage) for i in xrange(num_chains): chain = [] bonds = [] for k in xrange(monomers_per_chain): idx = i * monomers_per_chain + k part = [ pidf[idx], typef[idx], mass, espressopp.Real3D(xposf[idx], yposf[idx], zposf[idx]), espressopp.Real3D(xvelf[idx], yvelf[idx], zvelf[idx]), radiusf[idx] ] chain.append(part) if k > 0: bonds.append((pidf[idx - 1], pidf[idx])) system.storage.addParticles(chain, *props) system.storage.decompose() bondlist.addBonds(bonds) elif xyzfilename: props = ['id', 'type', 'mass', 'pos', 'v'] bondlist = espressopp.FixedPairList(system.storage) for i in xrange(num_chains): chain = [] bonds = [] for k in xrange(monomers_per_chain): idx = i * monomers_per_chain + k part = [ pidf[idx], typef[idx], mass, espressopp.Real3D(xposf[idx], yposf[idx], zposf[idx]), espressopp.Real3D(xvelf[idx], yvelf[idx], zvelf[idx]) ] chain.append(part) if k > 0: bonds.append((pidf[idx - 1], pidf[idx])) system.storage.addParticles(chain, *props) system.storage.decompose() bondlist.addBonds(bonds) else: props = ['id', 'type', 'mass', 'pos', 'v'] vel_zero = espressopp.Real3D(0.0, 0.0, 0.0) bondlist = espressopp.FixedPairList(system.storage) pid = 1 type = 0 chain = [] for i in xrange(num_chains): startpos = system.bc.getRandomPos() positions, bonds = espressopp.tools.topology.polymerRW( pid, startpos, monomers_per_chain, bondlen) for k in xrange(monomers_per_chain): part = [pid + k, type, mass, positions[k], vel_zero] chain.append(part) pid += monomers_per_chain type += 1 system.storage.addParticles(chain, *props) system.storage.decompose() chain = [] bondlist.addBonds(bonds) system.storage.decompose() # FENE bonds potFENE = espressopp.interaction.FENE(K=30.0, r0=0.0, rMax=1.5) interFENE = espressopp.interaction.FixedPairListFENE( system, bondlist, potFENE) system.addInteraction(interFENE) return system, integrator class KGMelt: def __init__(self, num_chains, chain_len): self._num_chains = num_chains self._chain_len = chain_len self._num_particles = num_chains * chain_len self._density = 0.8449 self._L = pow(self._num_particles / self._density, 1.0 / 3.0) self._box = (L, L, L) self._system = espress.System()
def test_random_box_ar(self): system1, integrator1 = self.create_system() system2, integrator2 = self.create_system() for pid in range(3, 1000, 1): pos = system1.bc.getRandomPos() system1.storage.addParticle(pid, pos) system1.storage.modifyParticle(pid, 'type', 3) system1.storage.modifyParticle(pid, 'state', 0) system1.storage.modifyParticle(pid, 'res_id', pid) system2.storage.addParticle(pid, pos) system2.storage.modifyParticle(pid, 'type', 3) system2.storage.modifyParticle(pid, 'state', 0) system2.storage.modifyParticle(pid, 'res_id', pid) system1.storage.decompose() system2.storage.decompose() fpl_old = espressopp.FixedPairList(system1.storage) vl_old = espressopp.VerletList(system1, cutoff=2.5) ar = espressopp.integrator.AssociationReaction(system1, vl_old, fpl_old, system1.storage) ar.rate = 1000.0 ar.interval = 1 ar.cutoff = 1.2 ar.typeA = 3 ar.typeB = 3 ar.deltaA = 1 ar.deltaB = 1 ar.stateAMin = 0 integrator1.addExtension(ar) # Second system vl = espressopp.VerletList(system2, cutoff=2.5) fpl1 = espressopp.FixedPairList(system2.storage) topology_manager = espressopp.integrator.TopologyManager(system2) ar2 = espressopp.integrator.ChemicalReaction(system2, vl, system2.storage, topology_manager, 1) integrator2.addExtension(ar2) r_type_1 = espressopp.integrator.Reaction(type_1=3, type_2=3, delta_1=1, delta_2=1, min_state_1=0, max_state_1=10**8, min_state_2=0, max_state_2=1, rate=1000.0, cutoff=1.2, fpl=fpl1) ar2.interval = 1 ar2.add_reaction(r_type_1) ar2.nearest_mode = True ar2.pair_distances_filename = 'pairs_distances.txt' #self.assertEqual(fpl_old.getAllBonds(), []) #self.assertEqual(fpl1.getAllBonds(), []) integrator1.run(1) integrator2.run(1) ar2.pair_distances_filename = '' integrator2.run(1) ar2.pair_distances_filename = 'abc.txt' integrator2.run(1) s_old = set([tuple(sorted(x)) for x in fpl_old.getAllBonds()]) s_new = set([tuple(sorted(x)) for x in fpl1.getAllBonds()])
#nodeGrid = Int3D(1, 1, comm.size) #cellGrid = Int3D( #calcNumberCells(size[0], nodeGrid[0], rc), #calcNumberCells(size[1], nodeGrid[1], rc), #calcNumberCells(size[2], nodeGrid[2], rc) #) system.storage = espressopp.storage.DomainDecomposition( system, nodeGrid, cellGrid) # add particles to the system and then decompose for pid in range(num_particles): system.storage.addParticle(pid + 1, Real3D(x[pid], y[pid], z[pid])) system.storage.decompose() # Lennard-Jones with Verlet list vl = espressopp.VerletList(system, cutoff=rc + system.skin) if tabulation: interLJ = espressopp.interaction.VerletListTabulated(vl) interLJ.setPotential(type1=0, type2=0, potential=potTabLJ) else: interLJ = espressopp.interaction.VerletListLennardJones(vl) interLJ.setPotential(type1=0, type2=0, potential=potLJ) system.addInteraction(interLJ) # FENE bonds with Fixed Pair List fpl = espressopp.FixedPairList(system.storage) fpl.addBonds(bonds) if tabulation: interFENE = espressopp.interaction.FixedPairListTabulated( system, fpl, potTabFENE) #interFENE.setPotential(type1=0, type2=0, potential=potTabFENE) # no longer needed
pt.startDefiningSystem(i) pid, type, x, y, z, vx, vy, vz, Lx, Ly, Lz = espressopp.tools.readxyz('parallel_tempering.xyz') num_particles = len(pid) boxsize = (Lx, Ly, Lz) rho = num_particles / (Lx * Ly * Lz) system = espressopp.System() rng = espressopp.esutil.RNG() bc = espressopp.bc.OrthorhombicBC(rng, boxsize) system.bc = bc system.rng = rng system.skin = skin nodeGrid = espressopp.tools.decomp.nodeGrid(pt.getNumberOfCPUsPerSystem()) cellGrid = espressopp.tools.decomp.cellGrid(boxsize,nodeGrid,rc,skin) storage = espressopp.storage.DomainDecomposition(system, nodeGrid, cellGrid, nocheck=True) system.storage = storage vl = espressopp.VerletList(system,cutoff=rc) potLJ = espressopp.interaction.LennardJones(epsilon, sigma, rc, shift) interLJ = espressopp.interaction.VerletListLennardJones(vl) integrator = espressopp.integrator.VelocityVerlet(system) integrator.dt = dt langevin = espressopp.integrator.LangevinThermostat(system) langevin.gamma = gamma langevin.temperature = temperature*i/20 + 0.2 integrator.addExtension(langevin) interLJ.setPotential(type1=0, type2=0, potential=potLJ) system.addInteraction(interLJ) for k in range(num_particles): storage.addParticle(pid[k], Real3D(x[k], y[k], z[k]), checkexist=False) storage.decompose() pt.setIntegrator(integrator, langevin)
def setUp(self): # set up system global Ni, temperature box = (Ni, Ni, Ni) rc = pow(2, 1. / 6.) skin = 0.3 epsilon = 1. sigma = 0. # system set up system = espressopp.System() system.rng = espressopp.esutil.RNG() system.bc = espressopp.bc.OrthorhombicBC(system.rng, box) system.skin = skin nodeGrid = espressopp.tools.decomp.nodeGrid( espressopp.MPI.COMM_WORLD.size) cellGrid = espressopp.tools.decomp.cellGrid(box, nodeGrid, rc, skin) system.storage = espressopp.storage.DomainDecomposition( system, nodeGrid, cellGrid) # interaction interaction = espressopp.interaction.VerletListLennardJones( espressopp.VerletList(system, cutoff=rc)) potLJ = espressopp.interaction.LennardJones(epsilon, sigma, rc) interaction.setPotential(type1=0, type2=0, potential=potLJ) system.addInteraction(interaction) # integrator integrator = espressopp.integrator.VelocityVerlet(system) integrator.dt = 0.001 # thermostat thermostat = espressopp.integrator.LangevinThermostat(system) thermostat.gamma = 1.0 thermostat.temperature = temperature integrator.addExtension(thermostat) # make dense system global num_particles particle_list = [] mass = 1. for k in range(num_particles): pid = k + 1 pos = system.bc.getRandomPos() v = Real3D(0, 0, 0) type = 0 part = [pid, pos, type, v, mass] particle_list.append(part) system.storage.addParticles(particle_list, 'id', 'pos', 'type', 'v', 'mass') system.storage.decompose() print "Warm up. Sigma will be increased from 0. to 1." new_sigma = sigma for k in range(100): integrator.run(100) new_sigma += 0.01 if (new_sigma > 0.8): integrator.dt = 0.005 potLJ = espressopp.interaction.LennardJones(epsilon, new_sigma, rc) interaction.setPotential(type1=0, type2=0, potential=potLJ) # LB will control thermostatting now thermostat.disconnect() integrator.step = 0 # set up LB fluid lb = espressopp.integrator.LatticeBoltzmann(system, nodeGrid) integrator.addExtension(lb) # set initial populations global initDen, initVel initPop = espressopp.integrator.LBInitPopUniform(system, lb) initPop.createDenVel(initDen, Real3D(initVel)) # set up LB profiler global runSteps lb.profStep = int(.5 * runSteps) lboutputScreen = espressopp.analysis.LBOutputScreen(system, lb) ext_lboutputScreen = espressopp.integrator.ExtAnalyze( lboutputScreen, runSteps) integrator.addExtension(ext_lboutputScreen) # lb parameters: viscosities, temperature, time contrast b/w MD and LB lb.visc_b = 3. lb.visc_s = 3. lb.lbTemp = temperature lb.nSteps = 5 # set self self.lb = lb self.lboutput = lboutputScreen self.integrator = integrator