def test_constrain_rg(self): # set up normal domain decomposition nodeGrid = espressopp.tools.decomp.nodeGrid( espressopp.MPI.COMM_WORLD.size, self.box, rc=1.5, skin=0.3) cellGrid = espressopp.tools.decomp.cellGrid(self.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(4.0, 5.0, 5.0), 1.0, 0, 1.), (2, 1, 0, espressopp.Real3D(4.5, 5.866, 5.0), 1.0, 0, 1.), (3, 1, 0, espressopp.Real3D(5.0, 5.0, 5.0), 1.0, 0, 1.), (4, 1, 0, espressopp.Real3D(5.5, 4.134, 5.0), 1.0, 0, 1.), (5, 1, 0, espressopp.Real3D(6.0, 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 # Langevin Thermostat langevin = espressopp.integrator.LangevinThermostat(self.system) langevin.gamma = 1.0 langevin.temperature = 1.0 integrator.addExtension(langevin) # Harmonic bonds bondlist = espressopp.FixedPairList(self.system.storage) for i in range(1, 5): bondlist.add(i, i + 1) potBond = espressopp.interaction.Harmonic(K=100., r0=1.0) interBond = espressopp.interaction.FixedPairListHarmonic( self.system, bondlist, potBond) self.system.addInteraction(interBond) # constrain center of mass tuplelist = espressopp.FixedLocalTupleList(self.system.storage) tuple = [] for i in range(1, 6): tuple.append(i) tuplelist.addTuple(tuple) potRG = espressopp.interaction.ConstrainRG(2000.) interRG = espressopp.interaction.FixedLocalTupleListConstrainRG( self.system, tuplelist, potRG) self.system.addInteraction(interRG, 'Constrain_RG') # radius of gyration of particles before integration before = [0., 0., 0.] particle = self.system.storage.getParticle(1) dmy_p = [] dmy_ele = [] for i in xrange(3): dmy_ele.append(particle.pos[i]) dmy_p.append(dmy_ele) for i in xrange(2, 6): particle = self.system.storage.getParticle(i) diff = [] for j in xrange(3): x_i = particle.pos[j] - dmy_p[i - 2][j] x_i = x_i - round(x_i / self.L) * self.L diff.append(x_i + dmy_p[i - 2][j]) dmy_p.append(diff) for i in xrange(5): for j in xrange(3): before[j] += dmy_p[i][j] for i in xrange(3): before[i] /= 5. print "before COM =", before before_rg = 0. for i in xrange(5): for j in xrange(3): before_rg += (dmy_p[i][j] - before[j])**2 before_rg = before_rg**0.5 print "before Rg =", before_rg # run twenty thousand steps integrator.run(20000) # center of mass of particles after integration after = [0., 0., 0.] particle = self.system.storage.getParticle(1) dmy_p = [] dmy_ele = [] for i in xrange(3): dmy_ele.append(particle.pos[i]) dmy_p.append(dmy_ele) for i in xrange(2, 6): particle = self.system.storage.getParticle(i) diff = [] for j in xrange(3): x_i = particle.pos[j] - dmy_p[i - 2][j] x_i = x_i - round(x_i / self.L) * self.L diff.append(x_i + dmy_p[i - 2][j]) dmy_p.append(diff) for i in xrange(5): for j in xrange(3): after[j] += dmy_p[i][j] for i in xrange(3): after[i] /= 5. print "after COM =", after after_rg = 0. for i in xrange(5): for j in xrange(3): after_rg += (dmy_p[i][j] - after[j])**2 after_rg = after_rg**0.5 print "after Rg =", after_rg # run checks self.assertTrue(fabs((before_rg - after_rg) / before_rg) < 0.03)
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,box,cutoff,system.skin) 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
def test_constrain_com(self): # set up normal domain decomposition nodeGrid = espressopp.tools.decomp.nodeGrid(espressopp.MPI.COMM_WORLD.size,self.box,rc=1.5, skin=self.skin) cellGrid = espressopp.tools.decomp.cellGrid(self.box, nodeGrid, rc=1.5, skin=self.skin) 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(3.0, 5.0, 5.0), 1.0, 0, 1.), (2, 1, 0, espressopp.Real3D(4.0, 5.0, 5.0), 2.0, 0, 1.), (3, 1, 0, espressopp.Real3D(5.0, 5.0, 5.0), 3.0, 0, 1.), (4, 1, 0, espressopp.Real3D(6.0, 5.0, 5.0), 2.0, 0, 1.), (5, 1, 0, espressopp.Real3D(7.0, 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 # Langevin Thermostat langevin = espressopp.integrator.LangevinThermostat(self.system) langevin.gamma = 1.0 langevin.temperature = 1.0 integrator.addExtension(langevin) # Harmonic bonds bondlist = espressopp.FixedPairList(self.system.storage) for i in range(1, 5): bondlist.add(i, i + 1) potBond = espressopp.interaction.Harmonic(K=100., r0 = 1.0) interBond = espressopp.interaction.FixedPairListHarmonic(self.system, bondlist, potBond) self.system.addInteraction(interBond) # constrain center of mass tuplelist = espressopp.FixedLocalTupleList(self.system.storage) tuple = [] for i in range(1, 6): tuple.append(i) tuplelist.addTuple(tuple) potCOM = espressopp.interaction.ConstrainCOM(1000.) interCOM = espressopp.interaction.FixedLocalTupleListConstrainCOM(self.system, tuplelist, potCOM) self.system.addInteraction(interCOM, 'Constrain_COM') # center of mass of particles before integration before = [0., 0., 0.] particle = self.system.storage.getParticle(1) dmy_p = [] dmy_ele = [] mass = [] for i in range(3): dmy_ele.append(particle.pos[i]) dmy_p.append(dmy_ele) mass.append(particle.mass) for i in range(2, 6): particle = self.system.storage.getParticle(i) mass.append(particle.mass) diff = [] for j in range(3): x_i = particle.pos[j] - dmy_p[i - 2][j] x_i = x_i - round(x_i/self.L)*self.L diff.append(x_i + dmy_p[i - 2][j]) dmy_p.append(diff) total_mass = 0. for i in range(5): total_mass += mass[i] for j in range(3): before[j] += mass[i]*dmy_p[i][j] for i in range(3): before[i] /= total_mass print("before", before) # run twenty thousand steps integrator.run(20000) # center of mass of particles after integration after= [0., 0., 0.] particle = self.system.storage.getParticle(1) dmy_p = [] dmy_ele = [] mass = [] for i in range(3): dmy_ele.append(particle.pos[i]) dmy_p.append(dmy_ele) mass.append(particle.mass) for i in range(2, 6): particle = self.system.storage.getParticle(i) mass.append(particle.mass) diff = [] for j in range(3): x_i = particle.pos[j] - dmy_p[i - 2][j] x_i = x_i - round(x_i/self.L)*self.L diff.append(x_i + dmy_p[i - 2][j]) dmy_p.append(diff) total_mass = 0. for i in range(5): total_mass += mass[i] for j in range(3): after[j] += mass[i]*dmy_p[i][j] for i in range(3): after[i] /= total_mass print("after", after) # run checks self.assertTrue(fabs(before[0] - after[0]) < 0.04) self.assertTrue(fabs(before[1] - after[1]) < 0.04) self.assertTrue(fabs(before[2] - after[2]) < 0.04)
(float(parameters[8 - i_diff]) + 2.*L)%L) print i*monomers_per_chain + j, " ", res_positions radius = float(parameters[10 - i_diff]) part = [res_positions, radius] cg_chain.append(part) j +=1 # Init fine-grained polymer configuration N_blob = N_blob/2 monomers_per_chain *= 2 props = ['id', 'type', 'mass', 'pos', 'v', 'radius', 'vradius'] bondlist = espressopp.FixedPairList(system.storage) anglelist = espressopp.FixedTripleList(system.storage) tuplelist = espressopp.FixedLocalTupleList(system.storage) pid = 1 type = 0 mass = 1.0*N_blob integrator.dt = timestep*(mass*B_cg**2/temperature)**0.5 #0.005*sqrt(Nb*m*l^2/kbT)=unit_time/200 #integrator.dt = timestep*(mass/temperature)**0.5 #0.005*sqrt(Nb*m*l^2/kbT)=unit_time/200/B_cg chain = [] for i in range(num_chains): startpos = system.bc.getRandomPos() positions, bonds, angles = espressopp.tools.topology.polymerRW(pid, startpos, monomers_per_chain, bondlen, True) for j in range(monomers_per_chain/2): id = i*(monomers_per_chain/2) + j vector = [] if j == 0: