import time import espressopp nsteps = 10 isteps = 100 rc = pow(2.0, 1.0 / 6.0) skin = 0.4 timestep = 0.005 # set temperature to None for NVE-simulations temperature = 1.0 ###################################################################### ### IT SHOULD BE UNNECESSARY TO MAKE MODIFICATIONS BELOW THIS LINE ### ###################################################################### print espressopp.Version().info() print 'Setting up simulation ...' bonds, angles, x, y, z, Lx, Ly, Lz = espressopp.tools.convert.lammps.read( 'polymer_melt.lammps') bonds, angles, x, y, z, Lx, Ly, Lz = espressopp.tools.replicate(bonds, angles, x, y, z, Lx, Ly, Lz, xdim=1, ydim=1, zdim=1) num_particles = len(x)
dt = 0.001 #ps nSteps = 1000 #total number of steps nStepsPerOutput = 100 #frequency for printing energies and trajectory nOutput = nSteps / nStepsPerOutput # Parameters for size of AdResS dimensions ex_size = 1.00 hy_size = 1.00 print '# radius of atomistic region = ', ex_size print '# thickness of hybrid region = ', hy_size trjfile = "trj.gro" # print ESPResSo++ version and compile info print '# ', espressopp.Version().info() # print simulation parameters (useful to have them in a log file) print "# nbCutoff = ", nbCutoff print "# intCutoff = ", intCutoff print "# skin = ", skin print "# dt = ", dt print "# nSteps = ", nSteps print "# output every ", nStepsPerOutput, " steps" ######################################################################## # 2. read in coordinates and topology ######################################################################## ## get info on (complete) atomistic system ## print '# Reading gromacs top and gro files...'
def bench_lj(xyz_file): # read from xyz file print("reading from: ", xyz_file) pid, type, xpos, ypos, zpos, xvel, yvel, zvel, Lx, Ly, Lz = readxyz(xyz_file) Npart = len(pid) box = (Lx,Ly,Lz) ################################################ # SIMULATION PARAMETERS ################################################ # cutoff of the short range potential r_cutoff = 2.5 # VerletList skin size (also used for domain decomposition) skin = 0.4 # time step for the velocity verlet integrator dt = 0.005 # Lennard Jones epsilon during equilibration phase epsilon00 = 0.1 epsilon11 = 0.9 epsilon01 = (0.1*0.3)**(0.5) # Lennard Jones sigma during warmup and equilibration sigma00 = 1.0 sigma11 = 0.6 sigma01 = (sigma00+sigma11)/2.0 steps = 100 ################################################ # SETUP SYSTEM ################################################ # create the basic system system = espressopp.System() # use the random number generator that is included within the ESPResSo++ package system.rng = espressopp.esutil.RNG() # use orthorhombic periodic boundary conditions system.bc = espressopp.bc.OrthorhombicBC(system.rng, box) # set the skin size used for verlet lists and cell sizes system.skin = skin # get the number of CPUs to use NCPUs = espressopp.MPI.COMM_WORLD.size # calculate a regular 3D grid according to the number of CPUs available nodeGrid = espressopp.tools.decomp.nodeGrid(NCPUs, box, r_cutoff, skin) # calculate a 3D subgrid to speed up verlet list builds and communication cellGrid = espressopp.tools.decomp.cellGrid(box, nodeGrid, r_cutoff, skin) print("gitrevision = ", espressopp.Version().gitrevision) print("NCPUs = ", NCPUs) print("r_cutoff = ", r_cutoff) print("skin = ", skin) print("box = ", box) print("nodeGrid = ", nodeGrid) print("cellGrid = ", cellGrid) print("Nparticles = ", Npart) print("steps = ", steps) # create a domain decomposition particle storage with the calculated nodeGrid and cellGrid system.storage = espressopp.storage.DomainDecomposition(system, nodeGrid, cellGrid) # use a velocity Verlet integration scheme integrator = espressopp.integrator.VelocityVerlet(system) # set the integration step integrator.dt = dt ################################################ # ADD PARTICLES ################################################ props = ['id', 'type', 'pos'] print("adding particles to storage...") new_particles = [] pid = 0 for x, y, z in zip(xpos, ypos, zpos): ptype = pid % 2 new_particles.append([pid, ptype, Real3D(x,y,z)]) pid += 1 system.storage.addParticles(new_particles, *props) system.storage.decompose() print("adding particles to storage... DONE") ######################################################################## # 7. setting up interaction potential for the equilibration # ######################################################################## verletlist = espressopp.VerletList(system, r_cutoff) interaction = espressopp.interaction.VerletListLennardJones(verletlist) interaction.setPotential(type1=0, type2=0, potential=espressopp.interaction.LennardJones( epsilon=epsilon00, sigma=sigma00, cutoff=r_cutoff, shift=0.0)) interaction.setPotential(type1=0, type2=1, potential=espressopp.interaction.LennardJones( epsilon=epsilon01, sigma=sigma01, cutoff=r_cutoff, shift=0.0)) interaction.setPotential(type1=1, type2=1, potential=espressopp.interaction.LennardJones( epsilon=epsilon11, sigma=sigma11, cutoff=r_cutoff, shift=0.0)) system.addInteraction(interaction) print("running integrator...") integrator.run(steps) print("running integrator... DONE") keys = [ "Run", # 0 "ForceComp[0]", # 1 "ForceComp[1]", # 2 "ForceComp[2]", # 3 "UpdateGhosts", # 4 "CollectGhostForces", # 5 "Integrate1", # 6 "Integrate2", # 7 "Resort", # 8 "Lost" # 9 ] sub_keys = [0,6,8,4,1,2,5,7] timers = list(integrator.getTimers()) timers_summ = np.mean(np.array(timers),axis=0) # add non-interacting particles of different type # this forces potentialArray to resize print("adding more particles to storage...") new_particles = [] for x, y, z in zip(xpos[:10], ypos[:10], zpos[:10]): ptype = 6 new_particles.append([pid, ptype, Real3D(x,y,z)]) pid += 1 system.storage.addParticles(new_particles, *props) system.storage.decompose() print("adding more particles to storage... DONE") print("running integrator...") integrator.run(steps) print("running integrator... DONE") timers = list(integrator.getTimers()) timers_summ += np.mean(np.array(timers),axis=0) print("") for k in sub_keys: print("{:18} = {}".format(keys[k],timers_summ[k])) print("") temperature = espressopp.analysis.Temperature(system) T = temperature.compute() print("temperature = {}".format(T)) T_exp = 0.160074388303 assert(abs(T-T_exp)<1.0e-8)
# # This file is execfile()d with the current directory set to its containing dir. # # Note that not all possible configuration values are present in this # autogenerated file. # # All configuration values have a default; values that are commented out # serve to show the default. import sys, os import datetime # Gets version directly from the code try: import espressopp ver = espressopp.Version() ESPP_VERSION = '{}.{}.{}'.format( ver.major, ver.minor, ver.patchlevel) except ImportError: ESPP_VERSION = '1.9.3' # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. # -- General configuration ----------------------------------------------------- # Add any Sphinx extension module names here, as strings. They can be extensions # coming with Sphinx (named 'sphinx.ext.*') or your custom ones. # extensions = ['sphinx.ext.autodoc', 'sphinx.ext.doctest', # 'sphinx.ext.intersphinx', 'sphinx.ext.coverage',
def warmup(p): ''' Generate configuration and perform warmup ''' seed = 6543215 # seed for random temperature = 1.0 # set temperature to None for NVE-simulations # set parameters for simulations num_chains = p['number_of_chains'] monomers_per_chain = p['degree_of_polymerization'] L = p['L'] ###################################################################### ### IT SHOULD BE UNNECESSARY TO MAKE MODIFICATIONS BELOW THIS LINE ### ###################################################################### nsteps = p['num_steps_wu'] isteps = p['ints_per_step_wu'] rc = pow(2.0, 1.0 / 6.0) skin = p['skin'] timestep = p['dt'] box = p['box'] print(epp.Version().info()) print('Setting up simulation ...') #logging.getLogger("SteepestDescent").setLevel(logging.INFO) system = epp.System() system.rng = epp.esutil.RNG() system.rng.seed(seed) system.bc = epp.bc.OrthorhombicBC(system.rng, box) system.skin = skin nodeGrid = epp.tools.decomp.nodeGrid(epp.MPI.COMM_WORLD.size) cellGrid = epp.tools.decomp.cellGrid(box, nodeGrid, rc, skin) system.storage = epp.storage.DomainDecomposition(system, nodeGrid, cellGrid) integrator = epp.integrator.VelocityVerlet(system) integrator.dt = timestep thermostat = epp.integrator.LangevinThermostat(system) thermostat.gamma = p['langevin_gamma'] thermostat.temperature = p['temperature'] integrator.addExtension(thermostat) steepest = epp.integrator.MinimizeEnergy(system, gamma=0.001, ftol=0.1, max_displacement=0.001, variable_step_flag=False) # set the polymer properties bondlen = 0.97 props = ['id', 'type', 'mass', 'pos', 'v'] vel_zero = epp.Real3D(0.0, 0.0, 0.0) bondlist = epp.FixedPairList(system.storage) #anglelist = epp.FixedTripleList(system.storage) pid = 1 bead_type = 0 mass = 1.0 # add particles to the system and then decompose # do this in chunks of 1000 particles to speed it up chain = [] for _ in range(num_chains): startpos = system.bc.getRandomPos() positions, bonds, _ = epp.tools.topology.polymerRW( pid, startpos, monomers_per_chain, bondlen, True) for k in range(monomers_per_chain): part = [pid + k, bead_type, mass, positions[k], vel_zero] chain.append(part) pid += monomers_per_chain #bead_type += 1 system.storage.addParticles(chain, *props) system.storage.decompose() chain = [] bondlist.addBonds(bonds) #anglelist.addTriples(angles) system.storage.addParticles(chain, *props) system.storage.decompose() num_particles = num_chains * monomers_per_chain density = num_particles * 1.0 / (L * L * L) # Lennard-Jones with Verlet list vl = epp.VerletList(system, cutoff=rc) potLJ = epp.interaction.LennardJones(epsilon=1.0, sigma=1.0, cutoff=rc, shift=0) interLJ = epp.interaction.VerletListLennardJones(vl) interLJ.setPotential(type1=0, type2=0, potential=potLJ) system.addInteraction(interLJ) # FENE bonds potFENE = epp.interaction.FENECapped(K=3000.0, r0=0.0, rMax=1.5, cutoff=8, r_cap=1.49999) interFENE = epp.interaction.FixedPairListFENECapped( system, bondlist, potFENE) system.addInteraction(interFENE, 'FENE') # Cosine with FixedTriple list #potCosine = epp.interaction.Cosine(K=1.5, theta0=3.1415926) #interCosine = epp.interaction.FixedTripleListCosine(system, anglelist, potCosine) #system.addInteraction(interCosine) # print simulation parameters print('') print('number of particles = ', num_particles) print('length of system = ', L) print('density = ', density) print('rc = ', rc) print('dt = ', integrator.dt) print('skin = ', system.skin) print('temperature = ', temperature) print('nsteps = ', nsteps) print('isteps = ', isteps) print('NodeGrid = ', system.storage.getNodeGrid()) print('CellGrid = ', system.storage.getCellGrid()) print('') # epp.tools.decomp.tuneSkin(system, integrator) #filename = "initial_for_relax.res" #epp.tools.pdb.pdbwrite(filename, system, monomers_per_chain, False) epp.tools.analyse.info(system, steepest) start_time = time.clock() for k in range(10): steepest.run(isteps) epp.tools.analyse.info(system, steepest) # exchange the FENE potential epp.System.removeInteractionByName(system, 'FENE') potFENE = epp.interaction.FENECapped(K=30.0, r0=0.0, rMax=1.5, cutoff=8, r_cap=1.499999) interFENE = epp.interaction.FixedPairListFENECapped( system, bondlist, potFENE) system.addInteraction(interFENE) for k in range(20): steepest.run(isteps) epp.tools.analyse.info(system, steepest) end_time = time.clock() epp.tools.analyse.info(system, integrator) for k in range(2): integrator.run(isteps) epp.tools.analyse.info(system, integrator) end_time = time.clock() epp.tools.analyse.info(system, integrator) epp.tools.analyse.final_info(system, integrator, vl, start_time, end_time) customWritexyz("final_configuration_warmup.xyz", system, velocities=True, append=False)