def setUp(self): super(TestCaseRemoveNeighbourBond, self).setUp() particle_list = [ (3, 3, espressopp.Real3D(3.0, 2.0, 2.0), 2, 1), (4, 4, espressopp.Real3D(3.5, 2.0, 2.0), 2, 1), (5, 4, espressopp.Real3D(3.5, 2.0, 2.0), 2, 1), (6, 3, espressopp.Real3D(3.5, 2.0, 2.0), 2, 1), (7, 4, espressopp.Real3D(3.5, 2.0, 2.0), 2, 1), ] self.system.storage.addParticles(particle_list, *self.part_prop) self.system.storage.decompose() self.fpl23 = espressopp.FixedPairList(self.system.storage) self.fpl24 = espressopp.FixedPairList(self.system.storage) self.fpl34 = espressopp.FixedPairList(self.system.storage) self.ftl234 = espressopp.FixedTripleList(self.system.storage) self.ftl234.addTriples([(2, 3, 4)]) self.fpl23.addBonds([(2, 3)]) self.fpl24.addBonds([(2, 7)]) self.fpl34.addBonds([(3, 4), (3, 5), (4, 6)]) self.topology_manager.register_tuple(self.fpl24, 2, 4) self.topology_manager.register_tuple(self.fpl34, 3, 4) self.topology_manager.register_tuple(self.fpl23, 2, 3) self.topology_manager.register_triplet(self.ftl234, 2, 3, 4) self.topology_manager.initialize_topology()
def setUp(self): super(TestCaseExchangeReaction, self).setUp() import logging # 0-1-2-3-2-1-2-3-2-1-0 particle_list = [ (3, 0, espressopp.Real3D(3.0, 2.0, 2.0), 2, 1), (4, 1, espressopp.Real3D(3.2, 2.0, 2.0), 2, 0), (5, 2, espressopp.Real3D(3.4, 2.0, 2.0), 2, 2), (6, 3, espressopp.Real3D(3.6, 2.0, 2.0), 3, 3), (7, 2, espressopp.Real3D(3.8, 2.0, 2.0), 4, 2), (8, 1, espressopp.Real3D(4.0, 2.0, 2.0), 4, 0), (9, 2, espressopp.Real3D(4.2, 2.0, 2.0), 4, 2), (10, 3, espressopp.Real3D(4.4, 2.0, 2.0), 5, 3), (11, 2, espressopp.Real3D(4.6, 2.0, 2.0), 6, 2), (12, 1, espressopp.Real3D(4.8, 2.0, 2.0), 6, 0), (13, 0, espressopp.Real3D(5.0, 2.0, 2.0), 6, 2), (14, 4, espressopp.Real3D(4.2, 1.8, 2.0), 7, 4), ] self.system.storage.addParticles(particle_list, *self.part_prop) self.system.storage.decompose() # ('id', 'type', 'pos', 'res_id', 'state') self.fpl_static = espressopp.FixedPairList(self.system.storage) self.ftl_static = espressopp.FixedTripleList(self.system.storage) self.ftl123 = espressopp.FixedTripleList(self.system.storage) self.ftl232 = espressopp.FixedTripleList(self.system.storage) self.fpl_chem = espressopp.FixedPairList(self.system.storage) self.dynamic_exclude = espressopp.DynamicExcludeList(self.integrator) self.dynamic_exclude.observe_tuple(self.fpl_static) self.dynamic_exclude.observe_tuple(self.fpl_chem) self.dynamic_exclude.observe_triple(self.ftl_static) self.dynamic_exclude.observe_triple(self.ftl123) self.dynamic_exclude.observe_triple(self.ftl232) self.dynamic_exclude.observe_tuple(self.fpl_chem) self.fpl_static.addBonds([(3, 4), (4, 5), (7, 8), (8, 9), (11, 12), (12, 13)]) self.topology_manager.observe_tuple(self.fpl_static) self.ftl_static.addTriples([(3, 4, 5), (7, 8, 9), (11, 12, 13)]) self.ftl123.addTriples([(4, 5, 6), (6, 7, 8), (8, 9, 10), (10, 11, 12)]) self.topology_manager.register_triplet(self.ftl123, 1, 2, 3) self.ftl232.addTriples([(5, 6, 7), (9, 10, 11)]) self.topology_manager.register_triplet(self.ftl232, 2, 3, 2) self.fpl_chem.addBonds([(5, 6), (6, 7), (9, 10), (10, 11)]) self.topology_manager.register_tuple(self.fpl_chem, 2, 3) self.topology_manager.initialize_topology() self.dynamic_exclude.update()
def setUp(self): # Initialize the espressopp system box = (10, 10, 10) system = espressopp.System() self.system = system system.kb = 1.0 system.rng = espressopp.esutil.RNG() system.bc = espressopp.bc.OrthorhombicBC(system.rng, box) system.skin = 0.3 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) # Adding ten nodes self.N = 8 particle_list = [] for pid in range(1, self.N + 1): pos = system.bc.getRandomPos() particle_list.append((pid, pos, 1 if pid < 5 else 2)) system.storage.addParticles(particle_list, 'id', 'pos', 'res_id') system.storage.decompose() self.integrator = espressopp.integrator.VelocityVerlet(system) self.integrator.dt = 0.0025 self.fpl1 = espressopp.FixedPairList(system.storage) self.fpl1.addBonds([(1, 2), (2, 3), (2, 4)]) self.fpl2 = espressopp.FixedPairList(system.storage) self.fpl2.addBonds([(5, 6), (6, 7), (6, 8)]) self.fpl3 = espressopp.FixedPairList(system.storage) self.ftl = espressopp.FixedTripleList(system.storage) self.ftl.addTriples([(1, 2, 3), (1, 2, 4), (5, 6, 7), (5, 6, 8)]) self.fql = espressopp.FixedQuadrupleList(system.storage) self.fql2 = espressopp.FixedQuadrupleList(system.storage) topology_manager = espressopp.integrator.TopologyManager(system) self.topology_manager = topology_manager topology_manager.observe_tuple(self.fpl1) topology_manager.observe_tuple(self.fpl2) topology_manager.observe_tuple(self.fpl3) topology_manager.register_triplet(self.ftl, 0) topology_manager.register_quadruplet(self.fql, 0) topology_manager.register_quadruplet(self.fql2, 0, 0, 0, 1) topology_manager.register_tuple(self.fpl3, 0, 0) topology_manager.initialize_topology() self.integrator.addExtension(topology_manager)
def test_fpl_argument_to_reaction(self): fpl = espressopp.FixedPairListLambda(self.system.storage) espressopp.integrator.Reaction(0, 0, 0, 0, 0, 0, 0, 0, rate=0.1, fpl=fpl, cutoff=0.0) fpl = espressopp.FixedPairList(self.system.storage) espressopp.integrator.Reaction(0, 0, 0, 0, 0, 0, 0, 0, rate=0.1, fpl=fpl, cutoff=0.0)
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 setUp(self): # Initialize the espressopp system box = (10, 10, 10) system = espressopp.System() self.system = system system.kb = 1.0 system.rng = espressopp.esutil.RNG() system.bc = espressopp.bc.OrthorhombicBC(system.rng, box) system.skin = 0.3 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) # Adding ten nodes self.N = 6 particle_prop = ['id', 'pos', 'type', 'res_id', 'mass', 'state'] particle_list = [[1, None, 1, 1, 1.0, 2], [2, None, 1, 1, 1.0, 2], [3, None, 3, 1, 1.0, 3], [4, None, 2, 1, 1.0, 9], [5, None, 4, 1, 1.0, 8], [6, None, 3, 1, 1.0, 7]] for pid in range(0, self.N): pos = system.bc.getRandomPos() particle_list[pid][1] = pos system.storage.addParticles(particle_list, *particle_prop) system.storage.decompose() self.integrator = espressopp.integrator.VelocityVerlet(system) self.integrator.dt = 0.0025 bonds = [(1, 2), (1, 5), (1, 6), (2, 3), (2, 4)] self.fpl1 = espressopp.FixedPairList(system.storage) self.fpl1.addBonds(bonds) self.fpl3 = espressopp.FixedPairList(system.storage) topology_manager = espressopp.integrator.TopologyManager(system) self.topology_manager = topology_manager topology_manager.observe_tuple(self.fpl1) topology_manager.observe_tuple(self.fpl3) topology_manager.register_tuple(self.fpl3, 0, 0) topology_manager.initialize_topology() self.integrator.addExtension(topology_manager)
def setUp(self): super(TestFixedPairListTypesTabulated, self).setUp() particle_list = [(1, 1, espressopp.Real3D(2.0, 2.0, 2.0)), (2, 1, espressopp.Real3D(3.0, 2.0, 2.0)), (3, 2, espressopp.Real3D(2.0, 3.0, 2.0)), (4, 2, espressopp.Real3D(3.0, 3.0, 2.0))] self.system.storage.addParticles(particle_list, *self.part_prop) self.system.storage.decompose() self.fpl1 = espressopp.FixedPairList(self.system.storage) self.fpl1.addBonds([(1, 2), (3, 4)]) self.interaction = espressopp.interaction.FixedPairListTypesTabulated( self.system, self.fpl1)
def setBondedInteractions(system, input_conf, ftpl): ret_list = {} bonds = input_conf.bondtypes bondtypeparams = input_conf.bondtypeparams for (bid, cross_bonds), bondlist in bonds.iteritems(): if ftpl: fpl = espressopp.FixedPairListAdress(system.storage, ftpl) else: fpl = espressopp.FixedPairList(system.storage) fpl.addBonds(bondlist) bdinteraction = bondtypeparams[bid].createEspressoInteraction(system, fpl) if bdinteraction: system.addInteraction(bdinteraction, 'bond_{}{}'.format( bid, '_cross' if cross_bonds else '')) ret_list.update({(bid, cross_bonds): bdinteraction}) return ret_list
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 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)
def setUp(self): self.h5md_file = 'topo_output.h5' remove_file(self.h5md_file) self.system, self.integrator = espressopp.standard_system.Default( (10., 10., 10.), dt=0.1) self.particles = [(1, espressopp.Real3D(1, 2, 3), 1), (2, espressopp.Real3D(2, 3, 4), 2), (3, espressopp.Real3D(3, 4, 5), 3), (4, espressopp.Real3D(4, 5, 6), 4)] self.system.storage.addParticles(self.particles, 'id', 'pos', 'type') self.fpl = espressopp.FixedPairList(self.system.storage) self.fpl.addBonds([(1, 2), (2, 3)]) self.ftl = espressopp.FixedTripleList(self.system.storage) self.ftl.addTriples([(1, 2, 3)]) self.fql = espressopp.FixedQuadrupleList(self.system.storage) self.fql.addQuadruples([(1, 2, 3, 4)]) self.dump_h5md = espressopp.io.DumpH5MD(self.system, self.integrator, self.h5md_file, store_species=True, store_velocity=True, store_state=True) self.dump_topology = espressopp.io.DumpTopology( self.system, self.integrator, self.dump_h5md) self.dump_topology.observe_tuple(self.fpl, 'bonds_0') self.dump_topology.observe_triple(self.ftl, 'angles_0') self.dump_topology.observe_quadruple(self.fql, 'dihs_0') self.dump_topology.dump() ext_dump = espressopp.integrator.ExtAnalyze(self.dump_topology, 1) self.integrator.addExtension(ext_dump)
def test_synthesis_reaction(self): particles = [ (3, 3, espressopp.Real3D(4.0, 2.0, 2.0), 1, 1), (4, 3, espressopp.Real3D(4.0, 3.0, 2.0), 2, 0), (5, 3, espressopp.Real3D(4.0, 6.0, 2.0), 3, 0), ] self.system.storage.addParticles(particles, *self.part_prop) self.system.storage.decompose() fpl = espressopp.FixedPairList(self.system.storage) ar = espressopp.integrator.AssociationReaction(self.system, self.vl, fpl, self.system.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 self.integrator.addExtension(ar) self.assertEqual(fpl.getAllBonds(), []) self.integrator.run(2000) self.assertEqual(fpl.getAllBonds(), [(3, 4)])
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): # 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
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)
integrator.dt = dt # set-up of the thermostat thermostat = espressopp.integrator.LangevinThermostat(system) thermostat.gamma = 1.0 thermostat.temperature = temperature integrator.addExtension(thermostat) print 'timestep is ', integrator.dt print 'gamma of the thermostat is ', thermostat.gamma print 'temperature of the thermostat is ', thermostat.temperature props = ['id', 'type', 'mass', 'pos', 'v'] vel_zero = espressopp.Real3D(0.0, 0.0, 0.0) bondlist = espressopp.FixedPairList(system.storage) pid = 1 ptype = 0 mass = 1.0 chain = [] exclusionlist = [ ] # to separate bonded and non-bonded LJ potentials; used for equilibration for i in range(num_chains): startpos = system.bc.getRandomPos() positions, bonds = espressopp.tools.topology.polymerRW( pid, startpos, mon_per_chain, bondlen) for k in range(mon_per_chain): part = [pid + k, ptype, mass, positions[k], vel_zero] chain.append(part) if (k < mon_per_chain - 1):
gromacs.convertTable("table_CGwat_CGwat.xvg", fe, 1, 1, 1, 1) potCG = espressopp.interaction.Tabulated(itype=3, filename=fe, cutoff=intCutoff) lj_adres_interaction.setPotentialCG(type1=typeCG, type2=typeCG, potential=potCG) ## bonded (fixed list) interactions for protein (actually between CG particles in AA region) ## ## set up LJ 1-4 interactions cgOnefourpairslist = [] for (a1, a2) in atOnefourpairslist: cgOnefourpairslist.append((mapAtToCgIndex[a1], mapAtToCgIndex[a2])) print '# ', len(cgOnefourpairslist), ' 1-4 pairs in aa-hybrid region' onefourlist = espressopp.FixedPairList(system.storage) onefourlist.addBonds(cgOnefourpairslist) lj14interaction = gromacs.setLennardJones14Interactions( system, defaults, atomtypeparameters, onefourlist, intCutoff) # set up coulomb 1-4 interactions qq14_interactions = gromacs.setCoulomb14Interactions(system, defaults, onefourlist, intCutoff, atTypes) ## set up bond interactions according to the parameters read from the .top file # only for protein, not for water cgBondtypes = {} for btkey in atBondtypes.keys(): newBondtypes = [] for (a1, a2) in atBondtypes[btkey]:
def setup_reactions(self): """Setup reactions. Returns: The espressopp.integrator.ChemicalReaction extension and the list of fixed pair lists with new bonds. """ self.ar_interval = int(self.cfg['general']['interval']) ar = espressopp.integrator.ChemicalReaction( self.system, self.vl, self.system.storage, self.tm, self.ar_interval) ar.nearest_mode = self.cfg['general']['nearest'] if self.cfg['general']['pair_distances_filename']: ar.pair_distances_filename = self.cfg['general']['pair_distances_filename'] if self.cfg['general']['max_per_interval'] > 0: ar.max_per_interval = self.cfg['general']['max_per_interval'] fpls = [] reactions = [] extensions_to_integrator = [] fpl_def = collections.namedtuple('FPLDef', ['fpl', 'type_list']) self.reaction_index = {} reaction_idx = 0 for group_name, reaction_group in self.cfg['reactions'].items(): print('Setting reaction group {}'.format(group_name)) type2fpl = {} # Setting the interaction for the pairs created by this reaction group. if self.args.t_hybrid_bond > 0: fpl = espressopp.FixedPairListLambda(self.system.storage, 0.0) interaction_class = eval('espressopp.interaction.FixedPairListLambda{}'.format( reaction_group['potential'])) else: fpl = espressopp.FixedPairList(self.system.storage) interaction_class = eval('espressopp.interaction.FixedPairList{}'.format( reaction_group['potential'])) pot_class = eval('espressopp.interaction.{}'.format(reaction_group['potential'])) # Convert if it's possible, values for float pot_options = {} for k, v in reaction_group['potential_options'].items(): try: pot_options[k] = float(v) except ValueError: pot_options[k] = v print('Setting potential for bond with class {}, options {}'.format( reaction_group['potential'], reaction_group['potential_options'])) potential = pot_class(**pot_options) interaction = interaction_class(self.system, fpl, potential) fpl.interaction = interaction self.system.addInteraction(interaction, 'chem_fpl_{}'.format(group_name)) # Setting the post process extensions. group_extensions = self._prepare_group_postprocess(reaction_group['extensions']) extensions_to_integrator = [] extensions_to_reactions = collections.defaultdict(list) for k, v in group_extensions.items(): for x in v: if x.ext is not None: if x.ext_type == EXT_INTEGRATOR: extensions_to_integrator.append(x.ext) elif x.ext_type == EXT_POSTPROCESS: extensions_to_reactions[k].append(x) else: raise RuntimeError('Wrong ext_type={}'.format(x.ext_type)) # Process the reactions. reaction_type_list = [] print('Setting chemical reactions in group') for chem_reaction in reaction_group['reaction_list']: # Pass connectivity map from group level to reaction level chem_reaction['connectivity_map'] = reaction_group['connectivity_map'] # Dissociation reaction will be done in second run. if chem_reaction['reaction_type'] == REACTION_DISSOCATION: continue r, reaction_types = self._setup_reaction(chem_reaction, fpl) if r is not None: reaction_type_list.extend(reaction_types) for ext_name, extensions in extensions_to_reactions.items(): if ext_name in chem_reaction['exclude_extensions']: print('Skip extension: {} ({})'.format(ext_name, chem_reaction['equation'])) else: for extension in extensions: print('Add extension {} to {} ({}): {}'.format( ext_name, chem_reaction['equation'], extension.pp_type, extension.ext)) if extension.pp_type: r.add_postprocess(extension.ext, extension.pp_type) else: r.add_postprocess(extension.ext) ar.add_reaction(r) self.reaction_index[reaction_idx] = chem_reaction['equation'] reactions.append(r) reaction_idx += 1 for t1, t2 in reaction_types: type2fpl[(t1, t2)] = fpl type2fpl[(t2, t1)] = fpl # Now process dissociation reactions. # Pitfall, It can only sees fixed pair lists in given group for chem_reaction in reaction_group['reaction_list']: if chem_reaction['reaction_type'] != REACTION_DISSOCATION: # only dissociation continue r, reaction_types = self._setup_reaction_dissocation(chem_reaction, type2fpl) if r is not None: #reaction_type_list.extend(reaction_types) self.separate_fpls.add(tuple(reaction_types[0])) for ext_name, extensions in extensions_to_reactions.items(): if ext_name in chem_reaction['exclude_extensions']: print('Skip extension: {} ({})'.format(ext_name, chem_reaction['equation'])) else: for extension in extensions: print('Add extension {} to {} ({}): {}'.format( ext_name, chem_reaction['equation'], extension.pp_type, extension.ext)) if extension.pp_type: r.add_postprocess(extension.ext, extension.pp_type) else: r.add_postprocess(extension.ext) ar.add_reaction(r) self.reaction_index[reaction_idx] = chem_reaction['equation'] reactions.append(r) reaction_idx += 1 fpls.append(fpl_def(fpl, set(reaction_type_list))) return ar, fpls, reactions, extensions_to_integrator
def createPathintegralSystem( allParticles, props, types, system, langevin, potentials, P, # the Trotter Number (number of imaginary time slices) polymerInitR=0.01, # polymer radius for setting up ring in 2d plane hbar=0.063507807 # hbar in gromacs units [kJ/mol ps] ): # 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 #### #claParticles=[] #maxParticleID = int(espressopp.analysis.MaxPID(system).compute()) #for pid in range(maxParticleID+1): #if system.storage.particleExists(pid): #claParticles.append(system.storage.getParticle(pid)) #for p in claParticles: #print p.type ### ## 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 range(1, P): for p in allParticles: pid = p[propDict['id']] newparticle = copy.deepcopy(p) # set new types newparticle[propDict['type']] = newparticle[propDict[ 'type']] + numtypes * i # set types accoring to imag time index # 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) system.storage.addParticles(piParticles, *props) # expand non-bonded potentials numInteraction = system.getNumberOfInteractions() for n in range(numInteraction): interaction = system.getInteraction(n) print("expanding interaction", interaction) if interaction.bondType() == espressopp.interaction.Nonbonded: for i in range(P): for j in range(numtypes): for k in range(numtypes): pot = interaction.getPotential(j, k) interaction.setPotential(numtypes * i + j, numtypes * i + k, pot) if interaction.bondType() == espressopp.interaction.Pair: bond_fpl = interaction.getFixedPairList() cla_bonds = bond_fpl.getBonds()[0] for i in range(1, P): 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) if interaction.bondType() == espressopp.interaction.Angular: angle_ftl = interaction.getFixedTripleList() cla_angles = angle_ftl.getTriples()[0] for i in range(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 = dihedral_fql.getQuadruples()[0] for i in range(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) # 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.items(): 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 range(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
def applyBoreschRestraints(system, restraintAtoms, restraintK, restraintR0): restraintinteraction = {} restraintBond = espressopp.FixedPairList(system.storage) restraintBond.addBonds([(restraintAtoms['a'], restraintAtoms['A'])]) potint = espressopp.interaction.FixedPairListHarmonic( system, restraintBond, potential=espressopp.interaction.Harmonic(K=0.5 * restraintK['aA'], r0=restraintR0['aA'], cutoff=5.0, shift=0.0)) system.addInteraction(potint) restraintinteraction.update({0: potint}) restraintAngle = espressopp.FixedTripleList(system.storage) restraintAngle.addTriples([(restraintAtoms['a'], restraintAtoms['A'], restraintAtoms['B'])]) potint = espressopp.interaction.FixedTripleListAngularHarmonic( system, restraintAngle, potential=espressopp.interaction.AngularHarmonic( K=0.5 * restraintK['aAB'], theta0=restraintR0['aAB'] * math.pi / 180.0)) system.addInteraction(potint) restraintinteraction.update({1: potint}) restraintAngle = espressopp.FixedTripleList(system.storage) restraintAngle.addTriples([(restraintAtoms['b'], restraintAtoms['a'], restraintAtoms['A'])]) potint = espressopp.interaction.FixedTripleListAngularHarmonic( system, restraintAngle, potential=espressopp.interaction.AngularHarmonic( K=0.5 * restraintK['baA'], theta0=restraintR0['baA'] * math.pi / 180.0)) system.addInteraction(potint) restraintinteraction.update({2: potint}) restraintDih = espressopp.FixedQuadrupleList(system.storage) restraintDih.addQuadruples([(restraintAtoms['c'], restraintAtoms['b'], restraintAtoms['a'], restraintAtoms['A'])]) potint = espressopp.interaction.FixedQuadrupleListDihedralHarmonic( system, restraintDih, potential=espressopp.interaction.DihedralHarmonic( K=restraintK['cbaA'], phi0=restraintR0['cbaA'] * math.pi / 180.0)) system.addInteraction(potint) restraintinteraction.update({3: potint}) restraintDih = espressopp.FixedQuadrupleList(system.storage) restraintDih.addQuadruples([(restraintAtoms['b'], restraintAtoms['a'], restraintAtoms['A'], restraintAtoms['B'])]) potint = espressopp.interaction.FixedQuadrupleListDihedralHarmonic( system, restraintDih, potential=espressopp.interaction.DihedralHarmonic( K=restraintK['baAB'], phi0=restraintR0['baAB'] * math.pi / 180.0)) system.addInteraction(potint) restraintinteraction.update({4: potint}) restraintDih = espressopp.FixedQuadrupleList(system.storage) restraintDih.addQuadruples([(restraintAtoms['a'], restraintAtoms['A'], restraintAtoms['B'], restraintAtoms['C'])]) potint = espressopp.interaction.FixedQuadrupleListDihedralHarmonic( system, restraintDih, potential=espressopp.interaction.DihedralHarmonic( K=restraintK['aABC'], phi0=restraintR0['aABC'] * math.pi / 180.0)) system.addInteraction(potint) restraintinteraction.update({5: potint}) return restraintinteraction
def setPairInteractions(system, input_conf, cutoff, coulomb_cutoff, ftpl=None): pairs = input_conf.pairtypes fudgeQQ = float(input_conf.defaults['fudgeQQ']) pref = 138.935485 * fudgeQQ # we want gromacs units, so this is 1/(4 pi eps_0) ins units of kJ mol^-1 e^-2, scaled by fudge factor pairtypeparams = input_conf.pairtypeparams static_14_pairs = [] cross_14_pairs_cg = [] cross_14_pairs_at = [] for (pid, cross_bonds), pair_list in pairs.iteritems(): params = pairtypeparams[pid] is_cg = input_conf.atomtypeparams[ input_conf.types[pair_list[0][0] - 1]]['particletype'] == 'V' if is_cg or ftpl is None: fpl = espressopp.FixedPairList(system.storage) else: fpl = espressopp.FixedPairListAdress(system.storage, ftpl) fpl.addBonds(pair_list) if cross_bonds or is_cg: if is_cg: cross_14_pairs_cg.extend(pair_list) else: cross_14_pairs_at.extend(pair_list) else: static_14_pairs.extend(pair_list) if not cross_bonds: is_cg = None if params['sig'] > 0.0 and params['eps'] > 0.0: print('Pair interaction {} num pairs: {} sig={} eps={} cutoff={} is_cg={}'.format( params, len(pair_list), params['sig'], params['eps'], cutoff, is_cg)) pot = espressopp.interaction.LennardJones( sigma=params['sig'], epsilon=params['eps'], shift='auto', cutoff=cutoff) if is_cg is None: interaction = espressopp.interaction.FixedPairListLennardJones(system, fpl, pot) else: interaction = espressopp.interaction.FixedPairListAdressLennardJones( system, fpl, pot, is_cg) system.addInteraction(interaction, 'lj-14_{}{}'.format(pid, '_cross' if cross_bonds else '')) # Set Coulomb14 if static_14_pairs or cross_14_pairs_cg or cross_14_pairs_at: type_pairs = set() for type_1, pi in input_conf.atomtypeparams.iteritems(): for type_2, pj in input_conf.atomtypeparams.iteritems(): if pi['particletype'] != 'V' and pj['particletype'] != 'V': type_pairs.add(tuple(sorted([type_1, type_2]))) type_pairs = sorted(type_pairs) print('Using fudgeQQ: {}, type_pairs: {}'.format(fudgeQQ, len(type_pairs))) potQQ = espressopp.interaction.CoulombTruncated(prefactor=pref, cutoff=coulomb_cutoff) if static_14_pairs: print('Defined {} of static coulomb 1-4 pairs'.format(len(static_14_pairs))) fpl_static = espressopp.FixedPairList(system.storage) fpl_static.addBonds(static_14_pairs) interaction_static = espressopp.interaction.FixedPairListTypesCoulombTruncated(system, fpl_static) for type_1, type_2 in type_pairs: interaction_static.setPotential(type1=type_1, type2=type_2, potential=potQQ) system.addInteraction(interaction_static, 'coulomb14') if cross_14_pairs_cg: print('Defined {} of cross coulomb CG 1-4 pairs'.format(len(cross_14_pairs_cg))) fpl_cross = espressopp.FixedPairList(system.storage) fpl_cross.addBonds(cross_14_pairs_cg) # Now set cross potential. interaction_dynamic = espressopp.interaction.FixedPairListAdressTypesCoulombTruncated( system, fpl_cross, True) for type_1, type_2 in type_pairs: interaction_dynamic.setPotential(type1=type_1, type2=type_2, potential=potQQ) system.addInteraction(interaction_dynamic, 'coulomb14_cg_cross') if cross_14_pairs_at: print('Defined {} of cross coulomb AT 1-4 pairs'.format(len(cross_14_pairs_at))) fpl_cross = espressopp.FixedPairList(system.storage) fpl_cross.addBonds(cross_14_pairs_at) # Now set cross potential. interaction_dynamic = espressopp.interaction.FixedPairListAdressTypesCoulombTruncated( system, fpl_cross, False) for type_1, type_2 in type_pairs: interaction_dynamic.setPotential(type1=type_1, type2=type_2, potential=potQQ) system.addInteraction(interaction_dynamic, 'coulomb14_at_cross')
def test_set_fixedpairlist(self): fpl = espressopp.FixedPairList(self.system.storage) fpl.addBonds([(1, 1)]) self.interaction.setFixedPairList(fpl) ret_fpl = self.interaction.getFixedPairList() self.assertEqual(ret_fpl.getBonds(), [[(1, 1)]])
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 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
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)
def test_phi0(self): #create system with three torsions, and for each one set a potential with a different phi0 values, to check that the interaction potential works for all combinations of positive and negative phi and phi0 phi0 = [10.0, -170.0, 170.0] particle_list = [ #add particles with initial torsion angle +90 (1, 0, espressopp.Real3D(2.0, 3.0, 3.0), 1.0), (2, 0, espressopp.Real3D(2.0, 2.0, 3.0), 1.0), (3, 0, espressopp.Real3D(2.0, 2.0, 2.0), 1.0), (4, 0, espressopp.Real3D(3.0, 2.0, 2.0), 1.0), #add particles with initial torsion angle 160 (5, 0, espressopp.Real3D(2.0, 3.0, 3.0), 1.0), (6, 0, espressopp.Real3D(2.0, 2.0, 3.0), 1.0), (7, 0, espressopp.Real3D(2.0, 2.0, 2.0), 1.0), (8, 0, espressopp.Real3D(2.4, 0.8, 2.0), 1.0), #add particles with initial torsion angle -161 (9, 0, espressopp.Real3D(2.0, 3.0, 3.0), 1.0), (10, 0, espressopp.Real3D(2.0, 2.0, 3.0), 1.0), (11, 0, espressopp.Real3D(2.0, 2.0, 2.0), 1.0), (12, 0, espressopp.Real3D(1.6, 0.8, 2.0), 1.0), ] self.system.storage.addParticles(particle_list, 'id', 'type', 'pos', 'mass') self.system.storage.decompose() quadrupleslist = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]] torsiontuples = [(1, 2, 3, 4), (5, 6, 7, 8), (9, 10, 11, 12)] bondtuples = [(1, 2), (2, 3), (3, 4), (5, 6), (6, 7), (7, 8), (9, 10), (10, 11), (11, 12)] #add torsions interactions = [] for i in range(3): fql = espressopp.FixedQuadrupleList(self.system.storage) fql.addQuadruples([torsiontuples[i]]) interaction = espressopp.interaction.FixedQuadrupleListDihedralHarmonic( self.system, fql, potential=espressopp.interaction.DihedralHarmonic( K=1.0, phi0=phi0[i] * math.pi / 180.0)) self.system.addInteraction(interaction) interactions.append(interaction) #add bonds so that atoms in the torsions don't drift too far apart fpl = espressopp.FixedPairList(self.system.storage) fpl.addBonds(bondtuples) interaction = espressopp.interaction.FixedPairListHarmonic( self.system, fpl, potential=espressopp.interaction.Harmonic(K=1.0, r0=1.0)) self.system.addInteraction(interaction) integrator = espressopp.integrator.VelocityVerlet(self.system) integrator.run(50) self.assertAlmostEqual(interactions[0].computeEnergy(), 0.747885, places=5) self.assertAlmostEqual(interactions[1].computeEnergy(), 0.099570, places=5) self.assertAlmostEqual(interactions[2].computeEnergy(), 0.099570, places=5) self.assertAlmostEqual(calc_dihedral(self, quadrupleslist[0]), 1.397549, places=5) self.assertAlmostEqual(calc_dihedral(self, quadrupleslist[1]), 2.869874, places=5) self.assertAlmostEqual(calc_dihedral(self, quadrupleslist[2]), -2.869874, places=5)
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 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
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) 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) ftl.addTriples(angles) potCosine = espressopp.interaction.Cosine(K=1.5, theta0=3.1415926) interCosine = espressopp.interaction.FixedTripleListCosine( system, ftl, potCosine) system.addInteraction(interCosine) # print simulation parameters print ''
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()])