########################## # 4. add particles to system # ########################## print 'Adding particles and tuples...' props = ['id', 'pos', 'v', 'f', 'pib', 'type', 'mass', 'adrat'] allParticlesAT = [] allParticles = [] tuples = [] # prepare trotter beads (add here these particles just temporarily) for pid_trotter in range(num_Trotter_beads): allParticlesAT.append([ pid_trotter + 1, Real3D(x[pid_trotter], y[pid_trotter], z[pid_trotter]), # position Real3D(vx[pid_trotter], vy[pid_trotter], vz[pid_trotter]), # velocity Real3D(0, 0, 0), # force pid_trotter % nTrotter + 1, types[pid_trotter], masses[pid_trotter], 1 ]) # pib, type, mass, is AT particle # create atoms for pid_atom in range(num_atoms): # Preparation of tuples (tuples define, which atoms/trotter beads belong to which CG molecules/atoms) tmptuple = [pid_atom + num_Trotter_beads + 1] for pid_trotter in range(nTrotter): pid = pid_atom * nTrotter + pid_trotter
########################## # 4. add particles to system # ########################## print('Adding particles and tuples...') props = ['id', 'pos', 'v', 'f', 'type', 'mass', 'q', 'adrat'] allParticlesAT = [] allParticles = [] tuples = [] # prepare atomistic particles (add these particles here just temporarily) for pid in range(num_particles_AT): part = [ pid + 1, Real3D(x[pid], y[pid], z[pid]), Real3D(vx[pid], vy[pid], vz[pid]), Real3D(0, 0, 0), types[pid], masses[pid], charges[pid], 1 ] allParticlesAT.append(part) # create coarse-grained particles for pidCG in range(num_particles_CG): # we put CG molecule in first atom, later CG molecules will be positioned in the center # note that we put the CG molecule at the first atom's position. Later the CG molecule will be positioned in the center of mass of all it's atoms tmptuple = [pidCG + num_particles_AT + 1] for pidAT in range(3): pid = pidCG * 3 + pidAT tmptuple.append((allParticlesAT[pid])[0]) firsParticleId = tmptuple[1]
properties = ['id', 'type', 'pos', 'v', 'mass', 'q', 'adrat'] allParticles = [] tuples = [] #add particles in order CG1,AA11,AA12,AA13...CG2,AA21,AA22,AA23... etc. mapAtToCgIndex = {} #first adres particles for i in range(nWaterMols): cgindex = i + nProtAtoms + nProtCgparticles + nWaterAtoms tmptuple = [particlePID[cgindex]] # first CG particle allParticles.append([ particlePID[cgindex], particleTypes[cgindex], Real3D(particleX[cgindex], particleY[cgindex], particleZ[cgindex]), Real3D(particleVX[cgindex], particleVY[cgindex], particleVZ[cgindex]), particleMasses[cgindex], particleCharges[cgindex], 0 ]) # then AA particles for j in range(nWaterAtomsPerMol): aaindex = i * nWaterAtomsPerMol + j + nProtAtoms tmptuple.append(particlePID[aaindex]) allParticles.append([ particlePID[aaindex], particleTypes[aaindex], Real3D(particleX[aaindex], particleY[aaindex], particleZ[aaindex]), Real3D(particleVX[aaindex], particleVY[aaindex], particleVZ[aaindex]), particleMasses[aaindex], particleCharges[aaindex], 1 ]) mapAtToCgIndex[particlePID[aaindex]] = particlePID[cgindex]
comm = MPI.COMM_WORLD nodeGrid = decomp.nodeGrid(comm.size,size,rc,skin) cellGrid = decomp.cellGrid(size, nodeGrid, rc, skin) # AdResS domain decomposition system.storage = espressopp.storage.DomainDecompositionAdress(system, nodeGrid, cellGrid) # prepare AT particles allParticlesAT = [] allParticles = [] tuples = [] for pidAT in range(num_particles): allParticlesAT.append([pidAT, # add here these particles just temporarly! Real3D(x[pidAT], y[pidAT], z[pidAT]), Real3D(vx[pidAT], vy[pidAT], vz[pidAT]), Real3D(fx[pidAT], fy[pidAT], fz[pidAT]), 1, 1.0, 1]) # type, mass, is AT particle # create CG particles from center of mass for pidCG in range(num_particlesCG): cmp = [0,0,0] cmv = [0,0,0] tmptuple = [pidCG+num_particles] # com calculation for pidAT in range(4): pid = pidCG*4+pidAT tmptuple.append(pid) pos = (allParticlesAT[pid])[1] vel = (allParticlesAT[pid])[2]
coulomb_prefactor = bjerrumlength * temperature nodeGrid = espressopp.tools.decomp.nodeGrid(MPI.COMM_WORLD.size) cellGrid = espressopp.tools.decomp.cellGrid(box, nodeGrid, rspacecutoff, skin) system = espressopp.System() system.rng = espressopp.esutil.RNG() system.bc = espressopp.bc.OrthorhombicBC(system.rng, box) system.skin = skin 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)
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) pt.setAnalysisE(interLJ) pt.setAnalysisT(espressopp.analysis.Temperature(system)) pt.setAnalysisNPart(espressopp.analysis.NPart(system)) pt.endDefiningSystem(i) # let each system reach its temperature for p in range(100): pt.run(100) multiT = pt._multisystem.runAnalysisTemperature() print "%s" % multiT for p in range(10):
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,size,rc,skin) cellGrid = decomp.cellGrid(size, nodeGrid, rc, skin) system.storage = espressopp.storage.DomainDecomposition(system, nodeGrid, cellGrid) # add particles to the system and then decompose props = ['id', 'pos', 'v', 'type'] 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]] allParticles.append(part) system.storage.addParticles(allParticles, *props) system.storage.decompose() # Tabulated Verlet list for non-bonded interactions vl = espressopp.VerletList(system, cutoff = rc + system.skin) internb = espressopp.interaction.VerletListTabulated(vl) gromacs.setTabulatedInteractions(potentials, particleTypes, system, internb) vl.exclude(exclusions)
systemPPPM.bc = espressopp.bc.OrthorhombicBC(systemPPPM.rng, box) systemPPPM.skin = skin systemPPPM.storage = espressopp.storage.DomainDecomposition( systemPPPM, nodeGrid, cellGrid) ####################################################################################### # adding particles props = ['id', 'pos', 'type', 'q'] new_particles = [] countX = countY = countZ = 0 for i in range(0, num_particles): # charge should be accordingly to NaCl crystall charge = pow(-1, countX + countY + countZ) part = [i, Real3D(x[i], y[i], z[i]), 0, charge] new_particles.append(part) countX += 1 if countX >= N: countX = 0 countY += 1 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
nodeGrid = espressopp.tools.decomp.nodeGrid(espressopp.MPI.COMM_WORLD.size) lb = espressopp.integrator.LatticeBoltzmann(system, nodeGrid) # add extension to the integrator integrator.addExtension(lb) # specify desired temperature (set the fluctuations if any) lb.nSteps = 1 lb.visc_b = 3. lb.visc_s = 3. lb.lbTemp = 1. lb.profStep = 5000 #initPop = espressopp.integrator.LBInitPopUniform(system,lb) initPop = espressopp.integrator.LBInitPopWave(system, lb) initPop.createDenVel(1.0, Real3D(0., 0., 0.)) #initPop.createDenVel(1.0, Real3D(0.,0.,0.001)) lboutputScreen = espressopp.analysis.LBOutputScreen(system, lb) OUT3 = espressopp.integrator.ExtAnalyze(lboutputScreen, lb.profStep) integrator.addExtension(OUT3) ## add some profiling statistics for the run for k in range(3): # lb.readCouplForces() integrator.run(50000) s = str(integrator.step) mdoutput = 'dump.' + s + '.xyz' espressopp.tools.writexyz(mdoutput, system) lb.saveCouplForces()
def polymerRW(pid, startpos, numberOfMonomers, bondlength, return_angles=False, return_dihedrals=False, mindist=None, rng=None): x = startpos[0] y = startpos[1] z = startpos[2] positions = [ Real3D(x, y, z) ] bonds = [] avecostheta = 0.0 if return_angles == True: angles = [] if return_dihedrals == True: dihedrals = [] for i in xrange(numberOfMonomers-1): if mindist and i > 0: while True: if rng==None: nextZ = (2.0*random.uniform(0,1)-1.0)*bondlength; phi = 2.0*pi*random.uniform(0,1); else: nextZ = (2.0*rng()-1.0)*bondlength; phi = 2.0*pi*rng(); rr = sqrt(bondlength*bondlength-nextZ*nextZ); nextX = rr*cos(phi); nextY = rr*sin(phi); ax = positions[i][0] - positions[i-1][0] ay = positions[i][1] - positions[i-1][1] az = positions[i][2] - positions[i-1][2] la = sqrt(ax*ax + ay*ay + az*az) bx = - nextX by = - nextY bz = - nextZ lb = sqrt(bx*bx + by*by + bz*bz) cx = ax - bx cy = ay - by cz = az - bz lc = sqrt(cx*cx + cy*cy + cz*cz) if lc > mindist: avecostheta += - (ax*bx + ay*by + az*bz) / (la * lb) #print "cos theta:", (ax*bx + ay*by + az*bz) / (la * lb) break else: if rng==None: nextZ = (2.0*random.uniform(0,1)-1.0)*bondlength; phi = 2.0*pi*random.uniform(0,1); else: nextZ = (2.0*rng()-1.0)*bondlength; phi = 2.0*pi*rng(); rr = sqrt(bondlength*bondlength-nextZ*nextZ); nextX = rr*cos(phi); nextY = rr*sin(phi); x += nextX y += nextY z += nextZ # update monomer list: positions.append(Real3D(x, y, z)) # update bond list: bonds.append((pid+i,pid+i+1)) if return_angles == True: if i < numberOfMonomers-2: angles.append((pid+i, pid+i+1, pid+i+2)) if return_dihedrals == True: if i < numberOfMonomers-3: dihedrals.append((pid+i, pid+i+1, pid+i+2, pid+i+3)) if mindist: avecostheta /= (numberOfMonomers-2) if return_angles == True: if return_dihedrals == True: if mindist: return positions, bonds, angles, dihedrals , avecostheta else: return positions, bonds, angles, dihedrals else: if mindist: return positions, bonds, angles, avecostheta else: return positions, bonds, angles else: if return_dihedrals == True: if mindist: return positions, bonds, dihedrals, avecostheta else: return positions, bonds, dihedrals else: if mindist: return positions, bonds, avecostheta else: return positions, bonds
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) # add particles to the system and then decompose props = ['id', 'pos', 'v', 'type'] 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] ] allParticles.append(part) system.storage.addParticles(allParticles, *props) system.storage.decompose() # Tabulated Verlet list for non-bonded interactions vl = espressopp.VerletList(system, cutoff=rc + system.skin) internb = espressopp.interaction.VerletListTabulated(vl) gromacs.setTabulatedInteractions(potentials, particleTypes, system, internb) vl.exclude(exclusions) # bonded 2-body interactions bondedinteractions = gromacs.setBondedInteractions(system, bondtypes,
# create a default system with 0 particles and cubic box system, integrator = espressopp.standard_system.Default(box=(20, 20, 20)) # LATTICE BOLTZMANN INITIALIZATION # define grid and connect to the integrator lb = espressopp.integrator.LatticeBoltzmann(system, Ni=Int3D(20, 20, 20)) integrator.addExtension(lb) # output of the progress to the screen lboutputScreen = espressopp.analysis.LBOutputScreen(system, lb) OUT1 = espressopp.integrator.ExtAnalyze(lboutputScreen, 100) integrator.addExtension(OUT1) # initialize initial density and velocity initPop = espressopp.integrator.LBInitPopUniform(system, lb) initPop.createDenVel(1.0, Real3D(0., 0., 0.)) # APPLICATION OF FORCES TO THE LIQUID # output velocity profile vz (x) lboutputVzOfX = espressopp.analysis.LBOutputProfileVzOfX(system, lb) OUT2 = espressopp.integrator.ExtAnalyze(lboutputVzOfX, 100) integrator.addExtension(OUT2) # set external constant (gravity-like) force lbforce = espressopp.integrator.LBInitConstForce(system, lb) lbforce.setForce(Real3D(0., 0., 0.0001)) # run 500 steps with it integrator.run(500) # add a periodic force with a specified amplitude to the existing body force lbforce2 = espressopp.integrator.LBInitPeriodicForce(system, lb)
system, integrator = espressopp.standard_system.Default(box=box) # calculate CPU nodeGrid based on the number of CPUs nodeGrid = espressopp.tools.decomp.nodeGrid(espressopp.MPI.COMM_WORLD.size) # LATTICE BOLTZMANN (LB) INITIALIZATION # define an lb object and connect to the integrator lb = espressopp.integrator.LatticeBoltzmann(system, nodeGrid) integrator.addExtension(lb) # set up temperature for thermal fluctuations ( LJ units ) lb.lbTemp = 1. # initialize initial density and velocity initDen = 1. # initial density on a site (LB units!) initVel = Real3D(0.) # initial velocity on a site (LB units!) initPop = espressopp.integrator.LBInitPopUniform(system, lb) initPop.createDenVel(initDen, initVel) # output of the progress to the screen outStep = 250 # period of the statistics update lbOutScreen = espressopp.analysis.LBOutputScreen(system, lb) outputToScreen = espressopp.integrator.ExtAnalyze(lbOutScreen, outStep) integrator.addExtension(outputToScreen) # output velocity profile vz (x) outStep = 500 lbOutVelFile = espressopp.analysis.LBOutputVzOfX(system, lb) outputToFile = espressopp.integrator.ExtAnalyze(lbOutVelFile, outStep) integrator.addExtension(outputToFile)
L = 20 # box dimension in every direction box = (L, L, L) # create a default system with 0 particles and cubic box system, integrator = espressopp.standard_system.Default(box=box) # calculate CPU nodeGrid based on the number of CPUs nodeGrid = espressopp.tools.decomp.nodeGrid(espressopp.MPI.COMM_WORLD.size) # LATTICE BOLTZMANN (LB) INITIALIZATION # define an lb object and connect to the integrator lb = espressopp.integrator.LatticeBoltzmann(system, nodeGrid) integrator.addExtension(lb) # initialize initial density and velocity initDen = 1. # initial density on a site (LB units!) initVel = Real3D(0.) # initial velocity on a site (LB units!) initPop = espressopp.integrator.LBInitPopUniform(system, lb) initPop.createDenVel(initDen, initVel) # output of the progress to the screen outStep = 250 # period of the statistics update lbOutScreen = espressopp.analysis.LBOutputScreen(system, lb) outputToScreen = espressopp.integrator.ExtAnalyze(lbOutScreen, outStep) integrator.addExtension(outputToScreen) # output velocity profile vz (x) outStep = 500 lbOutVelFile = espressopp.analysis.LBOutputVzOfX(system, lb) outputToFile = espressopp.integrator.ExtAnalyze(lbOutVelFile, outStep) integrator.addExtension(outputToFile)
print 'timestep is ', integrator.dt #print 'gamma of the thermostat is ', thermostat.gamma #print 'temperature of the thermostat is ', thermostat.temperature # redefine bonds props = ['id', 'type', 'mass', 'pos', 'v'] bondlist = espressopp.FixedPairList(system.storage) mass = 1.0 for i in range(num_chains): chain = [] bonds = [] for k in range(monomers_per_chain): partid = i * monomers_per_chain + k + 1 pos = Real3D(x[partid - 1], y[partid - 1], z[partid - 1]) v = Real3D(vx[partid - 1], vy[partid - 1], vz[partid - 1]) particle = [partid, type[partid - 1], mass, pos, v] chain.append(particle) if partid % monomers_per_chain != 0: bonds.append((partid, partid + 1)) system.storage.addParticles(chain, *props) system.storage.decompose() bondlist.addBonds(bonds) system.storage.decompose() potFENE = espressopp.interaction.FENE(K=30.0, r0=0.0, rMax=1.5) interFENE = espressopp.interaction.FixedPairListFENE(system, bondlist, potFENE) system.addInteraction(interFENE)
def test_PIAdResS(self): print 'param =', self.param constkinmass = self.param['constkinmass'] PILE = self.param['PILE'] realkinmass = self.param['realkinmass'] centroidthermostat = self.param['centroidthermostat'] KTI = self.param['KTI'] speedupInterAtom = self.param['speedupInterAtom'] speedupFreezeRings = self.param['speedupFreezeRings'] spherical_adress = self.param['spherical_adress'] nb_forcefield_setup = self.param['nb_forcefield_setup'] energy_before = self.param['energy_before'] energy_after = self.param['energy_after'] steps = 10 timestep_short = 0.001 / 16.0 multiplier_short_to_medium = 4 multiplier_medium_to_long = 4 interaction_cutoff = 0.84 potential_cutoff = 0.78 skin = 0.1 gamma = 0.0 temp = 2.50266751 if KTI: ex_size = 100.0 else: ex_size = 1.0 hy_size = 1.5 nTrotter = 4 clmassmultiplier = 100.0 PILElambda = 0.0 CMDparameter = 1.0 tabFEC_H = "FEC_H.dat" tabFEC_O = "FEC_O.dat" tabTHDF_H = "ThdForce_H.dat" tabTHDF_O = "ThdForce_O.dat" tabAngle = "tableESP_angle.dat" tabBondHH = "tableESP_bondHH.dat" tabBondOH = "tableESP_bondOH.dat" tabHW_HW = "tableESP_HW_HW.dat" tabHW_OW = "tableESP_HW_OW.dat" tabOW_OW = "tableESP_OW_OW.dat" pid, types, x, y, z, vx, vy, vz, Lx, Ly, Lz = espressopp.tools.readxyz( "input_test.xyz") masses = [] for item in types: if item == 1: masses.append(15.9994) else: masses.append(1.008) num_Trotter_beads = len(x) num_atoms = len(x) / nTrotter size = (Lx, Ly, Lz) system = espressopp.System() 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, interaction_cutoff, skin) system.rng = espressopp.esutil.RNG() system.storage = espressopp.storage.DomainDecompositionAdress( system, nodeGrid, cellGrid) props = ['id', 'pos', 'v', 'f', 'pib', 'type', 'mass', 'adrat'] allParticlesAT = [] allParticles = [] tuples = [] for pid_trotter in range(num_Trotter_beads): allParticlesAT.append([ pid_trotter + 1, Real3D(x[pid_trotter], y[pid_trotter], z[pid_trotter]), Real3D(vx[pid_trotter], vy[pid_trotter], vz[pid_trotter]), Real3D(0, 0, 0), pid_trotter % nTrotter + 1, types[pid_trotter], masses[pid_trotter], 1 ]) for pid_atom in range(num_atoms): tmptuple = [pid_atom + num_Trotter_beads + 1] for pid_trotter in range(nTrotter): pid = pid_atom * nTrotter + pid_trotter tmptuple.append((allParticlesAT[pid])[0]) firstParticleId = tmptuple[1] cmp = allParticlesAT[firstParticleId - 1][1] cmv = allParticlesAT[firstParticleId - 1][2] allParticles.append([ pid_atom + num_Trotter_beads + 1, Real3D(cmp[0], cmp[1], cmp[2]), Real3D(cmv[0], cmv[1], cmv[2]), Real3D(0, 0, 0), 0, types[pid_atom * nTrotter], masses[pid_atom * nTrotter], 0 ]) for pid_trotter in range(nTrotter): pid = pid_atom * nTrotter + pid_trotter allParticles.append([(allParticlesAT[pid])[0], (allParticlesAT[pid])[1], (allParticlesAT[pid])[2], (allParticlesAT[pid])[3], (allParticlesAT[pid])[4], (allParticlesAT[pid])[5], (allParticlesAT[pid])[6], (allParticlesAT[pid])[7]]) tuples.append(tmptuple) system.storage.addParticles(allParticles, *props) ftpl = espressopp.FixedTupleListAdress(system.storage) ftpl.addTuples(tuples) system.storage.setFixedTuplesAdress(ftpl) system.storage.decompose() bondsOH = [] bondsHH = [] for part in range(num_atoms / 3): bondsOH.append((num_Trotter_beads + 1 + 3 * part, num_Trotter_beads + 1 + 3 * part + 1)) bondsOH.append((num_Trotter_beads + 1 + 3 * part, num_Trotter_beads + 1 + 3 * part + 2)) bondsHH.append((num_Trotter_beads + 1 + 3 * part + 1, num_Trotter_beads + 1 + 3 * part + 2)) fplOH = espressopp.FixedPairList(system.storage) fplHH = espressopp.FixedPairList(system.storage) fplOH.addBonds(bondsOH) fplHH.addBonds(bondsHH) angles = [] for part in range(num_atoms / 3): angles.append((num_Trotter_beads + 1 + 3 * part + 1, num_Trotter_beads + 1 + 3 * part, num_Trotter_beads + 1 + 3 * part + 2)) ftl = espressopp.FixedTripleList(system.storage) ftl.addTriples(angles) vl = espressopp.VerletListAdress(system, cutoff=interaction_cutoff, adrcut=interaction_cutoff, dEx=ex_size, dHy=hy_size, adrCenter=[Lx / 2, Ly / 2, Lz / 2], exclusionlist=bondsOH + bondsHH, sphereAdr=spherical_adress) if nb_forcefield_setup == 1: interNB = espressopp.interaction.VerletListPIadressTabulatedLJ( vl, ftpl, nTrotter, speedupInterAtom) elif nb_forcefield_setup == 2: interNB = espressopp.interaction.VerletListPIadressNoDriftTabulated( vl, ftpl, nTrotter, speedupInterAtom) elif nb_forcefield_setup == 3: interNB = espressopp.interaction.VerletListPIadressTabulated( vl, ftpl, nTrotter, speedupInterAtom) else: raise ValueError( "Wrong nb_forcefield_setup integer (only 1,2,3 accepted.") potOOqm = espressopp.interaction.Tabulated(itype=3, filename=tabOW_OW, cutoff=potential_cutoff) potHOqm = espressopp.interaction.Tabulated(itype=3, filename=tabHW_OW, cutoff=potential_cutoff) potHHqm = espressopp.interaction.Tabulated(itype=3, filename=tabHW_HW, cutoff=potential_cutoff) if nb_forcefield_setup == 1: interNB.setPotentialQM(type1=1, type2=1, potential=potOOqm) interNB.setPotentialQM(type1=1, type2=0, potential=potHOqm) interNB.setPotentialQM(type1=0, type2=0, potential=potHHqm) potOOcl = espressopp.interaction.LennardJones( epsilon=temp, sigma=0.25, shift='auto', cutoff=1.122462048309373 * 0.25) interNB.setPotentialCL(type1=1, type2=1, potential=potOOcl) elif nb_forcefield_setup == 2: interNB.setPotential(type1=1, type2=1, potential=potOOqm) interNB.setPotential(type1=1, type2=0, potential=potHOqm) interNB.setPotential(type1=0, type2=0, potential=potHHqm) elif nb_forcefield_setup == 3: interNB.setPotentialQM(type1=1, type2=1, potential=potOOqm) interNB.setPotentialQM(type1=1, type2=0, potential=potHOqm) interNB.setPotentialQM(type1=0, type2=0, potential=potHHqm) interNB.setPotentialCL(type1=1, type2=1, potential=potOOqm) interNB.setPotentialCL(type1=1, type2=0, potential=potHOqm) interNB.setPotentialCL(type1=0, type2=0, potential=potHHqm) system.addInteraction(interNB) potBondHH = espressopp.interaction.Tabulated(itype=3, filename=tabBondHH) potBondOH = espressopp.interaction.Tabulated(itype=3, filename=tabBondOH) interBondedHH = espressopp.interaction.FixedPairListPIadressTabulated( system, fplHH, ftpl, potBondHH, nTrotter, speedupInterAtom) interBondedOH = espressopp.interaction.FixedPairListPIadressTabulated( system, fplOH, ftpl, potBondOH, nTrotter, speedupInterAtom) system.addInteraction(interBondedHH) system.addInteraction(interBondedOH) potAngle = espressopp.interaction.TabulatedAngular(itype=3, filename=tabAngle) interAngle = espressopp.interaction.FixedTripleListPIadressTabulatedAngular( system, ftl, ftpl, potAngle, nTrotter, speedupInterAtom) system.addInteraction(interAngle) integrator = espressopp.integrator.PIAdressIntegrator( system=system, verletlist=vl, timestep=timestep_short, sSteps=multiplier_short_to_medium, mSteps=multiplier_medium_to_long, nTrotter=nTrotter, realKinMass=realkinmass, constKinMass=constkinmass, temperature=temp, gamma=gamma, centroidThermostat=centroidthermostat, CMDparameter=CMDparameter, PILE=PILE, PILElambda=PILElambda, CLmassmultiplier=clmassmultiplier, speedup=speedupFreezeRings, KTI=KTI) if not KTI: fec = espressopp.integrator.FreeEnergyCompensation( system, center=[Lx / 2, Ly / 2, Lz / 2], ntrotter=nTrotter) fec.addForce(itype=3, filename=tabFEC_O, type=1) fec.addForce(itype=3, filename=tabFEC_H, type=0) integrator.addExtension(fec) thdf = espressopp.integrator.TDforce(system, vl) thdf.addForce(itype=3, filename=tabTHDF_O, type=1) thdf.addForce(itype=3, filename=tabTHDF_H, type=0) integrator.addExtension(thdf) if KTI: for i in range(1, num_Trotter_beads + num_atoms + 1): system.storage.modifyParticle(i, 'lambda_adrd', 0.0) system.storage.modifyParticle(i, 'lambda_adr', 0.0) system.storage.modifyParticle( i, 'varmass', clmassmultiplier * system.storage.getParticle(i).mass) system.storage.decompose() espressopp.tools.AdressDecomp(system, integrator) Eb = interBondedOH.computeEnergy() + interBondedHH.computeEnergy() EAng = interAngle.computeEnergy() ELj = interNB.computeEnergy() Ek = integrator.computeKineticEnergy() EPI = integrator.computeRingEnergy() if KTI == False: Ecorr = fec.computeCompEnergy() + thdf.computeTDEnergy() else: Ecorr = 0.0 energy_before_thistest = Ek + Eb + EAng + ELj + EPI + Ecorr integrator.run(steps) Eb = interBondedOH.computeEnergy() + interBondedHH.computeEnergy() EAng = interAngle.computeEnergy() ELj = interNB.computeEnergy() Ek = integrator.computeKineticEnergy() EPI = integrator.computeRingEnergy() if KTI == False: Ecorr = fec.computeCompEnergy() + thdf.computeTDEnergy() else: Ecorr = 0.0 energy_after_thistest = Ek + Eb + EAng + ELj + EPI + Ecorr self.assertAlmostEqual(energy_before_thistest, energy_before, places=5) self.assertAlmostEqual(energy_after_thistest, energy_after, places=5)
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,size,rc,skin) cellGrid = decomp.cellGrid(size, nodeGrid, rc, skin) 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.addParticles([[pid + 1, Real3D(x[pid], y[pid], z[pid]), types[pid]]], "id", "pos", "type") system.storage.decompose() # convert gromacs tabulated files to espressopp++ format gromacs.convertTable(tabAAg, tabAA, sigma, epsilon, c6, c12) gromacs.convertTable(tabABg, tabAB, sigma, epsilon, c6, c12) gromacs.convertTable(tabBBg, tabBB, sigma, epsilon, c6, c12) gromacs.convertTable(tab2bg, tab2b, sigma, epsilon, c6, c12) gromacs.convertTable(tab3bg, tab3b, sigma, epsilon, c6, c12) # non-bonded interactions, B is type 0, A is type 1 # Verlet list vl = espressopp.VerletList(system, cutoff = rc + system.skin)
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
# reading initial file file = open('ini_conf_diamond.xyz') lines = file.readlines() coord = [] vel = [] count = 0 for line in lines: if count==0: num_particles = int(line.split()[0]) count=1 elif count==1: Lx, Ly, Lz = list(map(float, line.split()[0:3])) count=2 elif(count==2): id1, type1, x, y, z, vx, vy, vz = list(map(float, line.split()[0:8])) coord.append( Real3D(x,y,z) ) vel.append( Real3D(vx,vy,vz) ) density = num_particles / (Lx * Ly * Lz) box = (Lx, Ly, Lz) ###################################################################### sys.stdout.write('Setting up simulation ...\n') system = espressopp.System() system.rng = espressopp.esutil.RNG() system.bc = espressopp.bc.OrthorhombicBC(system.rng, box) system.skin = skin comm = MPI.COMM_WORLD nodeGrid = decomp.nodeGrid(comm.size,box,rc,skin) cellGrid = decomp.cellGrid(box, nodeGrid, rc, skin)
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)
pid = 0 for i in range(int(N)): for j in range(int(N)): for k in range(int(N)): m = (i + 2 * j + 3 * k) % 11 r = 0.45 + m * 0.01 x = (i + r) / N * size[0] y = (j + r) / N * size[1] z = (k + r) / N * size[2] x = 1.0 * i y = 1.0 * j z = 1.0 * k system.storage.addParticle(pid, Real3D(x, y, z)) # not yet: dd.setVelocity(id, (1.0, 0.0, 0.0)) pid = pid + 1 system.storage.decompose() # integrator integrator = espressopp.integrator.VelocityVerlet(system) integrator.dt = 0.005 # now build Verlet List # ATTENTION: you must not add the skin explicitly here logging.getLogger("Interpolation").setLevel(logging.DEBUG) vl = espressopp.VerletList(system, cutoff=cutoff)
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, size, rc, skin) cellGrid = decomp.cellGrid(size, nodeGrid, rc, skin) 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.addParticles( [[pid + 1, Real3D(x[pid], y[pid], z[pid]), types[pid]]], "id", "pos", "type") system.storage.decompose() # convert gromacs tabulated files to espressopp++ format gromacs.convertTable(tabAAg, tabAA, sigma, epsilon, c6, c12) gromacs.convertTable(tabABg, tabAB, sigma, epsilon, c6, c12) gromacs.convertTable(tabBBg, tabBB, sigma, epsilon, c6, c12) gromacs.convertTable(tab2bg, tab2b, sigma, epsilon, c6, c12) gromacs.convertTable(tab3bg, tab3b, sigma, epsilon, c6, c12) # non-bonded interactions, B is type 0, A is type 1 # Verlet list vl = espressopp.VerletList(system, cutoff=rc + system.skin) # note: in the previous version of this example, exclusions were treated # incorrectly. Here the nrexcl=3 parameter is taken into account
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(0, 0, 0), types[pid], masses[pid], charges[pid] ] allParticles.append(part) system.storage.addParticles(allParticles, *props) #system.storage.decompose() # set up LJ interaction according to the parameters read from the .top file #ljinteraction=gromacs.setLennardJonesInteractions(system, defaults, atomtypeparameters, verletlist,rc) ########## tabulated nb interactions ############ tabfilesnb = ["table_O_O.xvg", "table_H_O.xvg", "table_H_H.xvg"] potentials = genTabPotentials(tabfilesnb) tabulatedinteraction = espressopp.interaction.VerletListTabulated(verletlist) tabulatedinteraction.setPotential(0, 0, potentials["O_O"]) tabulatedinteraction.setPotential(0, 1, potentials["H_O"])
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)
comm = MPI.COMM_WORLD nodeGrid = decomp.nodeGrid(comm.size) cellGrid = decomp.cellGrid(size, nodeGrid, rc, skin) # (H-)AdResS domain decomposition system.storage = espressopp.storage.DomainDecompositionAdress( system, nodeGrid, cellGrid) # prepare AT particles allParticlesAT = [] allParticles = [] tuples = [] for pidAT in range(num_particles): allParticlesAT.append([ pidAT, # add here these particles just temporarily Real3D(x[pidAT], y[pidAT], z[pidAT]), # position Real3D(vx[pidAT], vy[pidAT], vz[pidAT]), # velocity Real3D(0, 0, 0), # force 1, 1.0, 1 ]) # type, mass, is AT particle # create CG particles for pidCG in range(num_particlesCG): # we put CG molecule in first atom, later CG molecules will be positioned in the center cmp = espressopp.tools.AdressSetCG(4, pidCG, allParticlesAT) # Preparation of tuples (tuples define, which atoms belong to which CG molecules) tmptuple = [pidCG + num_particles] for pidAT2 in range(4): pid = pidCG * 4 + pidAT2
comm = MPI.COMM_WORLD nodeGrid = decomp.nodeGrid(comm.size, size, rc, skin) cellGrid = decomp.cellGrid(size, nodeGrid, rc, skin, halfCellInt) #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 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)
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, size, rc, skin) cellGrid = decomp.cellGrid(size, nodeGrid, rc, skin) system.storage = espressopp.storage.DomainDecomposition( system, nodeGrid, cellGrid) # add particles to the system and then decompose props = ['id', 'type', 'mass', 'pos', 'v'] new_particles = [] for i in range(num_particles): part = [ i + 1, 0, 1.0, Real3D(x[i], y[i], z[i]), Real3D(vx[i], vy[i], vz[i]) ] new_particles.append(part) system.storage.addParticles(new_particles, *props) system.storage.decompose() # all particles interact via a LJ interaction (use Verlet lists) vl = espressopp.VerletList(system, cutoff=rc + system.skin) #potLJ = espressopp.interaction.LennardJones(epsilon=1.0, sigma=1.0, cutoff=rc, shift=False) #interLJ = espressopp.interaction.VerletListLennardJones(vl) potLJ = espressopp.interaction.LennardJonesGromacs(epsilon=1.0, sigma=1.0, r1=2.0, cutoff=rc, shift=False)
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
properties = ['id', 'type', 'pos', 'v', 'mass', 'q', 'adrat'] allParticles = [] tuples = [] #add particles in order CG1,AA11,AA12,AA13...CG2,AA21,AA22,AA23... etc. mapAtToCgIndex = {} #first adres particles for i in range(nWaterMols): cgindex = i + nSoluteAtoms + nSoluteCgparticles + nWaterAtoms tmptuple = [particlePID[cgindex]] # first CG particle allParticles.append([particlePID[cgindex], particleTypes[cgindex], Real3D(particleX[cgindex],particleY[cgindex],particleZ[cgindex]), Real3D(particleVX[cgindex],particleVY[cgindex],particleVZ[cgindex]), particleMasses[cgindex],particleCharges[cgindex],0]) # then AA particles for j in range(nWaterAtomsPerMol): aaindex = i*nWaterAtomsPerMol + j + nSoluteAtoms tmptuple.append(particlePID[aaindex]) allParticles.append([particlePID[aaindex], particleTypes[aaindex], Real3D(particleX[aaindex],particleY[aaindex],particleZ[aaindex]), Real3D(particleVX[aaindex],particleVY[aaindex],particleVZ[aaindex]), particleMasses[aaindex],particleCharges[aaindex],1]) mapAtToCgIndex[particlePID[aaindex]]=particlePID[cgindex] tuples.append(tmptuple) # then solute
def setUp(self): system = espressopp.System() rng = espressopp.esutil.RNG() N = 4 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 = SIZE / 2. - system.skin comm = espressopp.MPI.COMM_WORLD nodeGrid = espressopp.tools.decomp.nodeGrid( espressopp.MPI.COMM_WORLD.size) cellGrid = espressopp.tools.decomp.cellGrid(box, nodeGrid, cutoff, system.skin) 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 for i in xrange(N): for j in xrange(N): for k in xrange(N): r = 0.25 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 Fixed Local Tuple List tuplelist = espressopp.FixedLocalTupleList(system.storage) self.system = system self.N = N self.tuplelist = tuplelist