def test_with_pid_and_velo_xyz(self): particle_list = [ (1, espressopp.Real3D(2.2319834598, 3.5858734534, 4.7485623451), espressopp.Real3D(2.2319834598, 1.5556734534, 4.7485623451), 0), (2, espressopp.Real3D(6.3459834598, 9.5858734534, 16.7485623451), espressopp.Real3D(3.2319834598, 1.5858734534, 1.7485623451), 0), (3, espressopp.Real3D(2.2319834598, 15.5858734534, 5.7485623451), espressopp.Real3D(4.2319834598, 2.5858734534, 2.7485623451), 2), (4, espressopp.Real3D(8.2319834598, 7.9958734534, 14.5325623451), espressopp.Real3D(5.2319834598, 6.5858734534, 18.7485623451), 3), (5, espressopp.Real3D(3.2319834598, 19.5858734534, 4.7485623451), espressopp.Real3D(6.2319834598, 8.5858734534, 7.7485623451), 1), ] self.system.storage.addParticles(particle_list, 'id', 'pos', 'v', 'type') file_xyz = "test_true_pid_true_velo_dumpXYZ_type_not_hardcoded.xyz" dump_xyz = espressopp.io.DumpXYZ(self.system, self.integrator, filename=file_xyz, unfolded=False, length_factor=1.0, length_unit='LJ', store_pids=True, store_velocities=True, append=False) dump_xyz.dump() #filecmp.clear_cache() self.assertTrue( filecmp.cmp(file_xyz, expected_files[2], shallow=False), "!!! Error! Files are not equal!! They should be equal!")
def test_cyclization(self): """Check if it is possible to make an cycle""" particle_list = [ (3, 2, espressopp.Real3D(2.0, 3.0, 2.0), 3, 1), (4, 1, espressopp.Real3D(2.5, 3.0, 2.0), 4, 1), ] self.system.storage.addParticles(particle_list, *self.part_prop) self.system.storage.decompose() self.topology_manager.initialize_topology() r_type_1 = espressopp.integrator.Reaction(type_1=1, type_2=2, delta_1=1, delta_2=1, min_state_1=1, max_state_1=3, min_state_2=1, max_state_2=3, rate=400.0, fpl=self.fpl1, cutoff=1.1) self.ar.add_reaction(r_type_1) fpl1_before = self.fpl1.getBonds() self.assertEquals(fpl1_before, [[]]) self.integrator.run(4) fpl1_after = self.fpl1.getBonds() # Full cycle. self.assertItemsEqual(fpl1_after[0], [(2, 4), (3, 4), (1, 2), (1, 3)])
def test_simple_gromacs(self): particle_list = [ (1, espressopp.Real3D(2.2319834598, 3.5858734534, 4.7485623451), espressopp.Real3D(2.2319834598, 1.5556734534, 4.7485623451), 0), (2, espressopp.Real3D(6.3459834598, 9.5858734534, 16.7485623451), espressopp.Real3D(3.2319834598, 1.5858734534, 1.7485623451), 0), (3, espressopp.Real3D(2.2319834598, 15.5858734534, 5.7485623451), espressopp.Real3D(4.2319834598, 2.5858734534, 2.7485623451), 2), (4, espressopp.Real3D(8.2319834598, 7.9958734534, 14.5325623451), espressopp.Real3D(5.2319834598, 6.5858734534, 18.7485623451), 3), (5, espressopp.Real3D(3.2319834598, 19.5858734534, 4.7485623451), espressopp.Real3D(6.2319834598, 8.5858734534, 7.7485623451), 1), ] self.system.storage.addParticles(particle_list, 'id', 'pos', 'v', 'type') file_gro = "test_standard_dumpGRO_type_not_hardcoded.gro" dump_gro = espressopp.io.DumpGRO(self.system, self.integrator, filename=file_gro, unfolded=False, length_factor=1.0, length_unit='LJ', append=False) dump_gro.dump() self.assertTrue( filecmp.cmp(file_gro, expected_files[0], shallow=False), "!!! Error! Files are not equal!! They should be equal!")
def test_non_cyclization(self): """Check if it is possible to make an cycle""" particle_list = [ (3, 2, espressopp.Real3D(2.0, 3.0, 2.0), 1, 1), (4, 1, espressopp.Real3D(2.5, 3.0, 2.0), 1, 1), ] self.system.storage.addParticles(particle_list, *self.part_prop) self.system.storage.modifyParticle(1, 'res_id', 2) self.system.storage.modifyParticle(2, 'res_id', 2) self.fpl1.addBonds([(1, 2), (3, 4), (1, 3)]) self.topology_manager.initialize_topology() self.system.storage.decompose() self.integrator.run(0) r_type_1 = espressopp.integrator.Reaction(type_1=1, type_2=2, delta_1=1, delta_2=1, min_state_1=1, max_state_1=3, min_state_2=1, max_state_2=3, rate=400.0, fpl=self.fpl1, cutoff=1.1) r_type_1.intraresidual = False self.ar.add_reaction(r_type_1) fpl1_before = self.fpl1.getBonds() self.integrator.run(2) fpl1_after = self.fpl1.getBonds() # Full cycle. self.assertEquals(set(fpl1_after[0]), {(1, 2), (1, 3), (3, 4)})
def setUp(self): system = espressopp.System() system.bc = espressopp.bc.OrthorhombicBC(system.rng, (10, 10, 10)) system.rng = espressopp.esutil.RNG(54321) system.skin = 0.3 system.comm = MPI.COMM_WORLD self.system = system system.storage = espressopp.storage.DomainDecomposition(system) particle_lists = [ (1, espressopp.Real3D(0, 1, 2), espressopp.Real3D(0, 0, 0)), (2, espressopp.Real3D(0, 1, 2), espressopp.Real3D(0, 0, 0)), (3, espressopp.Real3D(0, 1, 2), espressopp.Real3D(0, 0, 0)), (4, espressopp.Real3D(0, 1, 2), espressopp.Real3D(0, 0, 0)), (5, espressopp.Real3D(0, 1, 2), espressopp.Real3D(0, 0, 0)) ] self.thermo_group_pids = [1, 2, 3] self.non_thermo_group_pids = [4, 5] system.storage.addParticles(particle_lists, 'id', 'pos', 'v') self.thermo_group = espressopp.ParticleGroup(system.storage) for p in self.thermo_group_pids: self.thermo_group.add(p) self.integrator = espressopp.integrator.VelocityVerlet(system) self.integrator.dt = 0.001
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 test_simple_xtc(self): particle_list = [(1, espressopp.Real3D(4.75575, 5.82131, 16.9163)), (2, espressopp.Real3D(3.04417, 11.7107, 3.86951)), (3, espressopp.Real3D(16.2125, 3.47061, 9.69966)), (4, espressopp.Real3D(3.03725, 7.33914, 9.83473)), (5, espressopp.Real3D(18.2019, 5.30514, 17.8638)), (6, espressopp.Real3D(4.40702, 12.636, 11.4215)), (7, espressopp.Real3D(6.64315, 2.0891, 10.0586)), (8, espressopp.Real3D(11.3479, 17.0833, 0.802817)), (9, espressopp.Real3D(2.16045, 12.7879, 0.26222))] self.system.storage.addParticles(particle_list, 'id', 'pos') file_xtc_9atoms = "test_without_compression.xtc" dump_xtc = espressopp.io.DumpXTC(self.system, self.integrator, filename=file_xtc_9atoms, unfolded=False, length_factor=1.0, append=False) dump_xtc.dump() self.system.storage.addParticles( [(10, espressopp.Real3D(14.4037, 2.03629, 9.6589))], 'id', 'pos') file_xtc_10atoms = "test_with_compression.xtc" dump_xtc = espressopp.io.DumpXTC(self.system, self.integrator, filename=file_xtc_10atoms, unfolded=False, length_factor=1.0, append=False) dump_xtc.dump()
def test_on_radius(self): # set up normal domain decomposition box = (10, 10, 10) nodeGrid = espressopp.tools.decomp.nodeGrid( espressopp.MPI.COMM_WORLD.size, box, rc=1.5, skin=0.3) cellGrid = espressopp.tools.decomp.cellGrid(box, nodeGrid, rc=1.5, skin=0.3) self.system.storage = espressopp.storage.DomainDecomposition( self.system, nodeGrid, cellGrid) # add some particles (normal, coarse-grained particles only) particle_list = [ (1, 1, 0, espressopp.Real3D(5.5, 5.0, 5.0), 1.0, 0, 1.), (2, 1, 0, espressopp.Real3D(6.5, 5.0, 5.0), 1.0, 0, 1.), (3, 1, 0, espressopp.Real3D(7.5, 5.0, 5.0), 1.0, 0, 1.), ] self.system.storage.addParticles(particle_list, 'id', 'type', 'q', 'pos', 'mass', 'adrat', 'radius') self.system.storage.decompose() # generate a verlet list vl = espressopp.VerletList(self.system, cutoff=1.5) # integrator integrator = espressopp.integrator.VelocityVerlet(self.system) integrator.dt = 0.01 # integrator on radius radius_mass = 10. integratorOnRadius = espressopp.integrator.VelocityVerletOnRadius( self.system, dampingmass=radius_mass) integrator.addExtension(integratorOnRadius) # Langevin Thermostat on Radius langevin = espressopp.integrator.LangevinThermostatOnRadius( self.system, dampingmass=radius_mass) langevin.gamma = 1.0 langevin.temperature = 10.0 langevin.addExclusions([1]) integrator.addExtension(langevin) # coordinates of particles before integration before = [ self.system.storage.getParticle(i).radius for i in range(1, 4) ] # run ten steps integrator.run(10) # coordinates of particles after integration after = [ self.system.storage.getParticle(i).radius for i in range(1, 4) ] # run checks (first particle excluded, hence it's radius should not change. The other should have changed, however, as they feel the thermostat on radius) self.assertEqual(before[0], after[0]) self.assertNotEqual(before[1], after[1]) self.assertNotEqual(before[2], after[2])
def setUp(self): self.system, self.integrator = espressopp.standard_system.Minimal( 0, (10., 10., 10.)) particles = [(1, 0, espressopp.Real3D(5, 5, 5)), (2, 0, espressopp.Real3D(5, 6.97, 5)), (3, 1, espressopp.Real3D(5, 8.94, 5)), (4, 1, espressopp.Real3D(5, 10.94, 5))] self.part_prop = ('id', 'type', 'pos') self.system.storage.addParticles(particles, *self.part_prop)
def setUp(self): # set up system system = espressopp.System() box = (10, 10, 10) system.bc = espressopp.bc.OrthorhombicBC(system.rng, box) system.skin = 0.3 system.comm = MPI.COMM_WORLD nodeGrid = espressopp.tools.decomp.nodeGrid( espressopp.MPI.COMM_WORLD.size, box, rc=1.5, skin=system.skin) cellGrid = espressopp.tools.decomp.cellGrid(box, nodeGrid, rc=1.5, skin=system.skin) system.storage = espressopp.storage.DomainDecompositionAdress( system, nodeGrid, cellGrid) self.system = system # add some particles particle_list = [ (1, 1, 0, espressopp.Real3D(5.5, 5.0, 5.0), 1.0, 0), (2, 1, 0, espressopp.Real3D(6.5, 5.0, 5.0), 1.0, 0), (3, 1, 0, espressopp.Real3D(7.5, 5.0, 5.0), 1.0, 0), (4, 1, 0, espressopp.Real3D(8.5, 5.0, 5.0), 1.0, 0), (5, 1, 0, espressopp.Real3D(9.5, 5.0, 5.0), 1.0, 0), (6, 0, 1.0, espressopp.Real3D(5.5, 5.0, 5.0), 1.0, 1), (7, 0, 1.0, espressopp.Real3D(6.5, 5.0, 5.0), 1.0, 1), (8, 0, 1.0, espressopp.Real3D(7.5, 5.0, 5.0), 1.0, 1), (9, 0, 1.0, espressopp.Real3D(8.5, 5.0, 5.0), 1.0, 1), (10, 0, 1.0, espressopp.Real3D(9.5, 5.0, 5.0), 1.0, 1), ] tuples = [(1, 6), (2, 7), (3, 8), (4, 9), (5, 10)] self.system.storage.addParticles(particle_list, 'id', 'type', 'q', 'pos', 'mass', 'adrat') self.ftpl = espressopp.FixedTupleListAdress(self.system.storage) self.ftpl.addTuples(tuples) self.system.storage.setFixedTuplesAdress(self.ftpl) self.system.storage.decompose() # set up a verlet list self.vl = espressopp.VerletListAdress(self.system, cutoff=1.5, adrcut=1.5, dEx=2.0, dHy=1.0, adrCenter=[5.0, 5.0, 5.0], sphereAdr=False) # set up integrator self.integrator = espressopp.integrator.VelocityVerletRESPA( self.system) self.integrator.dt = 0.01 self.integrator.multistep = 4 adress = espressopp.integrator.Adress(self.system, self.vl, self.ftpl, multistep=4) self.integrator.addExtension(adress)
def test_cap_force_array_group(self): # set up normal domain decomposition nodeGrid = espressopp.tools.decomp.nodeGrid( espressopp.MPI.COMM_WORLD.size) cellGrid = espressopp.tools.decomp.cellGrid(self.box, nodeGrid, 1.5, 0.3) self.system.storage = espressopp.storage.DomainDecomposition( self.system, nodeGrid, cellGrid) # add some particles (normal, coarse-grained particles only) particle_list = [ (1, 0, 0, espressopp.Real3D(4.95, 5.0, 5.0), 1.0, 0, 1.), (2, 0, 0, espressopp.Real3D(5.05, 5.0, 5.0), 1.0, 0, 1.), ] self.system.storage.addParticles(particle_list, 'id', 'type', 'q', 'pos', 'mass', 'adrat', 'radius') self.system.storage.decompose() # integrator integrator = espressopp.integrator.VelocityVerlet(self.system) integrator.dt = 0.005 # Lennard-Jones with Verlet list rc_lj = pow(2.0, 1.0 / 6.0) vl = espressopp.VerletList(self.system, cutoff=rc_lj) potLJ = espressopp.interaction.LennardJones(epsilon=1., sigma=1., cutoff=rc_lj, shift=0) interLJ = espressopp.interaction.VerletListLennardJones(vl) interLJ.setPotential(type1=0, type2=0, potential=potLJ) self.system.addInteraction(interLJ) # create a ParticleGroup instance particle_group = espressopp.ParticleGroup(self.system.storage) particle_group.add(1) # create a CapForce instance capforce = espressopp.integrator.CapForce( self.system, espressopp.Real3D(1.0, 1.0, 1.0), particle_group) integrator.addExtension(capforce) # run 1 step integrator.run(1) particle1 = self.system.storage.getParticle(1) particle2 = self.system.storage.getParticle(2) print(particle1.f, particle2.f) # run checks self.assertTrue( math.fabs(particle1.f[0]) == 1.0, "The force of particle 1 is not capped.") self.assertTrue( math.fabs(particle2.f[0]) > 1.0, "The force of particle 2 is capped.")
def setUp(self): super(TestCaseChangeNeighbourProperty, 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, 3, espressopp.Real3D(3.5, 2.0, 2.0), 1, 7), (6, 4, espressopp.Real3D(3.5, 2.0, 2.0), 1, 1)] self.system.storage.addParticles(particle_list, *self.part_prop) self.fpl1.addBonds([(2, 3), (3, 4), (1, 5), (5, 6)]) self.topology_manager.initialize_topology()
def test_no_potential(self): particle_list = [ (1, espressopp.Real3D(2.0, 2.0, 2.0), 1.0), (2, espressopp.Real3D(3.0, 2.0, 2.0), 1.0), ] self.system.storage.addParticles(particle_list, 'id', 'pos', 'mass') self.system.storage.decompose() minimize_energy = espressopp.integrator.MinimizeEnergy(self.system, 0.001, 0.0, 0.001) minimize_energy.run(10) self.assertEqual(minimize_energy.f_max, 0.0);
def test_sphere(self): # add some particles particle_list = [ (1, 1, 0, espressopp.Real3D(5.0, 5.5, 5.0), 1.0, 0), (2, 1, 0, espressopp.Real3D(5.0, 6.5, 5.0), 1.0, 0), (3, 1, 0, espressopp.Real3D(5.0, 7.5, 5.0), 1.0, 0), (4, 1, 0, espressopp.Real3D(5.0, 8.5, 5.0), 1.0, 0), (5, 1, 0, espressopp.Real3D(5.0, 9.5, 5.0), 1.0, 0), (6, 0, 0, espressopp.Real3D(5.0, 5.5, 5.0), 1.0, 1), (7, 0, 0, espressopp.Real3D(5.0, 6.5, 5.0), 1.0, 1), (8, 0, 0, espressopp.Real3D(5.0, 7.5, 5.0), 1.0, 1), (9, 0, 0, espressopp.Real3D(5.0, 8.5, 5.0), 1.0, 1), (10, 0, 0, espressopp.Real3D(5.0, 9.5, 5.0), 1.0, 1), ] tuples = [(1,6),(2,7),(3,8),(4,9),(5,10)] self.system.storage.addParticles(particle_list, 'id', 'type', 'q', 'pos', 'mass','adrat') ftpl = espressopp.FixedTupleListAdress(self.system.storage) ftpl.addTuples(tuples) self.system.storage.setFixedTuplesAdress(ftpl) self.system.storage.decompose() # generate a verlet list vl = espressopp.VerletListAdress(self.system, cutoff=1.5, adrcut=1.5, dEx=2.0, dHy=1.0, adrCenter=[5.0, 5.0, 5.0], sphereAdr=True) # initialize lambda values integrator = espressopp.integrator.VelocityVerlet(self.system) integrator.dt = 0.01 adress = espressopp.integrator.Adress(self.system,vl,ftpl) integrator.addExtension(adress) espressopp.tools.AdressDecomp(self.system, integrator) # set up FEC fec = espressopp.integrator.FreeEnergyCompensation(self.system, center=[5.0, 5.0, 5.0], sphereAdr=True) fec.addForce(itype=3,filename="table_fec.tab",type=1) integrator.addExtension(fec) # y coordinates of particles before integration before = [self.system.storage.getParticle(i).pos[1] for i in range(1,6)] # run ten steps integrator.run(10) energy = fec.computeCompEnergy() # y coordinates of particles after integration after = [self.system.storage.getParticle(i).pos[1] for i in range(1,6)] # run checks (as for test with slab-geometry, but check y-coordinates this time. Given the now spherical setup, particles should move as before but along the y-axis). self.assertEqual(before[0], after[0]) self.assertEqual(before[1], after[1]) self.assertAlmostEqual(after[2], 7.598165, places=5) self.assertEqual(before[3], after[3]) self.assertEqual(before[4], after[4]) self.assertAlmostEqual(energy, 6.790157, places=5)
def test0get(self): system = espressopp.System() system.rng = espressopp.esutil.RNG() system.bc = espressopp.bc.OrthorhombicBC(system.rng, (10.0, 10.0, 10.0)) system.storage = espressopp.storage.DomainDecomposition( system=system, nodeGrid=(1,1,1), cellGrid=(2,2,2)) p = system.storage.addParticle(0, (1.0, 1.0, 1.0)) p.v = espressopp.Real3D(1.0, 1.0, 1.0) self.assertAlmostEqualReal3D(p.v, espressopp.Real3D(1.0, 1.0, 1.0))
def test_slab(self): # add some particles particle_list = [ (1, 1, 0, espressopp.Real3D(5.5, 5.0, 5.0), 1.0, 0), (2, 1, 0, espressopp.Real3D(6.5, 5.0, 5.0), 1.0, 0), (3, 1, 0, espressopp.Real3D(7.5, 5.0, 5.0), 1.0, 0), (4, 1, 0, espressopp.Real3D(8.5, 5.0, 5.0), 1.0, 0), (5, 1, 0, espressopp.Real3D(9.5, 5.0, 5.0), 1.0, 0), (6, 0, 0, espressopp.Real3D(5.5, 5.0, 5.0), 1.0, 1), (7, 0, 0, espressopp.Real3D(6.5, 5.0, 5.0), 1.0, 1), (8, 0, 0, espressopp.Real3D(7.5, 5.0, 5.0), 1.0, 1), (9, 0, 0, espressopp.Real3D(8.5, 5.0, 5.0), 1.0, 1), (10, 0, 0, espressopp.Real3D(9.5, 5.0, 5.0), 1.0, 1), ] tuples = [(1,6),(2,7),(3,8),(4,9),(5,10)] self.system.storage.addParticles(particle_list, 'id', 'type', 'q', 'pos', 'mass','adrat') ftpl = espressopp.FixedTupleListAdress(self.system.storage) ftpl.addTuples(tuples) self.system.storage.setFixedTuplesAdress(ftpl) self.system.storage.decompose() # generate a verlet list vl = espressopp.VerletListAdress(self.system, cutoff=1.5, adrcut=1.5, dEx=2.0, dHy=1.0, adrCenter=[5.0, 5.0, 5.0], sphereAdr=False) # initialize lambda values integrator = espressopp.integrator.VelocityVerlet(self.system) integrator.dt = 0.01 adress = espressopp.integrator.Adress(self.system,vl,ftpl) integrator.addExtension(adress) espressopp.tools.AdressDecomp(self.system, integrator) # set up FEC fec = espressopp.integrator.FreeEnergyCompensation(self.system, center=[5.0, 5.0, 5.0]) fec.addForce(itype=3,filename="table_fec.tab",type=1) integrator.addExtension(fec) # x coordinates of particles before integration before = [self.system.storage.getParticle(i).pos[0] for i in range(1,6)] # run ten steps and compute energy integrator.run(10) energy = fec.computeCompEnergy() # x coordinates of particles after integration after = [self.system.storage.getParticle(i).pos[0] for i in range(1,6)] # run checks (only one particle is in hybrid region and should feel the FEC. Also check that its FEC energy is correct) self.assertEqual(before[0], after[0]) self.assertEqual(before[1], after[1]) self.assertAlmostEqual(after[2], 7.598165, places=5) self.assertEqual(before[3], after[3]) self.assertEqual(before[4], after[4]) self.assertAlmostEqual(energy, 6.790157, places=5)
def setUp(self): # super(TestParticleGroupByTypeTest, self).setUp() self.system, self.integrator = espressopp.standard_system.Minimal( 0, (10., 10., 10.), dt=0.01) self.particle_list = [(1, 0, espressopp.Real3D(1, 1, 1)), (2, 1, espressopp.Real3D(1, 1, 6)), (3, 1, espressopp.Real3D(1, 1, 4.7)), (4, 2, espressopp.Real3D(1, 1, 10))] self.part_prop = ['id', 'type', 'pos'] self.system.storage.addParticles(self.particle_list, *self.part_prop) self.system.storage.decompose()
def setUp(self): self.system, self.integrator = espressopp.standard_system.Minimal( 0, (10., 10., 10.)) particles = [(1, 0, espressopp.Real3D(5, 5, 5)), (2, 0, espressopp.Real3D(5, 6.97, 5)), (3, 1, espressopp.Real3D(5, 8.94, 5)), (4, 1, espressopp.Real3D(5, 10.94, 5))] self.part_prop = ('id', 'type', 'pos') self.system.storage.addParticles(particles, *self.part_prop) self.fixed_dynamic_resolution = espressopp.integrator.FixedListDynamicResolution( self.system) self.integrator.addExtension(self.fixed_dynamic_resolution)
def setUp(self): self.h5md_file = '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')
def test_slab(self): # add some particles particle_list = [ (1, 1, 0, espressopp.Real3D(5.5, 5.0, 5.0), 1.0, 0), (2, 1, 0, espressopp.Real3D(6.5, 5.0, 5.0), 1.0, 0), (3, 1, 0, espressopp.Real3D(7.5, 5.0, 5.0), 1.0, 0), (4, 1, 0, espressopp.Real3D(8.5, 5.0, 5.0), 1.0, 0), (5, 1, 0, espressopp.Real3D(9.5, 5.0, 5.0), 1.0, 0), (6, 0, 0, espressopp.Real3D(5.5, 5.0, 5.0), 1.0, 1), (7, 0, 0, espressopp.Real3D(6.5, 5.0, 5.0), 1.0, 1), (8, 0, 0, espressopp.Real3D(7.5, 5.0, 5.0), 1.0, 1), (9, 0, 0, espressopp.Real3D(8.5, 5.0, 5.0), 1.0, 1), (10, 0, 0, espressopp.Real3D(9.5, 5.0, 5.0), 1.0, 1), ] tuples = [(1,6),(2,7),(3,8),(4,9),(5,10)] self.system.storage.addParticles(particle_list, 'id', 'type', 'q', 'pos', 'mass','adrat') ftpl = espressopp.FixedTupleListAdress(self.system.storage) ftpl.addTuples(tuples) self.system.storage.setFixedTuplesAdress(ftpl) self.system.storage.decompose() # generate a verlet list vl = espressopp.VerletListAdress(self.system, cutoff=1.5, adrcut=1.5, dEx=1.0, dHy=1.0, adrCenter=[5.0, 5.0, 5.0], sphereAdr=False) # initialize lambda values integrator = espressopp.integrator.VelocityVerlet(self.system) integrator.dt = 0.01 adress = espressopp.integrator.Adress(self.system,vl,ftpl) integrator.addExtension(adress) espressopp.tools.AdressDecomp(self.system, integrator) # set up TD force thdforce = espressopp.integrator.TDforce(self.system,vl) thdforce.addForce(itype=3,filename="table_tf.tab",type=1) integrator.addExtension(thdforce) # x coordinates of particles before integration before = [self.system.storage.getParticle(i).pos[0] for i in range(1,6)] # run ten steps integrator.run(10) # x coordinates of particles after integration after = [self.system.storage.getParticle(i).pos[0] for i in range(1,6)] # run checks (only one particle is in hybrid region, should feel the thermodynamic force, and should hence move along the x direction) self.assertEqual(before[0], after[0]) self.assertAlmostEqual(after[1], 6.596913, places=5) self.assertEqual(before[2], after[2]) self.assertEqual(before[3], after[3]) self.assertEqual(before[4], after[4])
def test_fixed_sphere(self): # add some particles particle_list = [ (1, 1, 0, espressopp.Real3D(5.0, 5.5, 5.0), 1.0, 0), (2, 1, 0, espressopp.Real3D(5.0, 6.5, 5.0), 1.0, 0), (3, 1, 0, espressopp.Real3D(5.0, 7.5, 5.0), 1.0, 0), (4, 1, 0, espressopp.Real3D(5.0, 8.5, 5.0), 1.0, 0), (5, 1, 0, espressopp.Real3D(5.0, 9.5, 5.0), 1.0, 0), (6, 0, 0, espressopp.Real3D(5.0, 5.5, 5.0), 1.0, 1), (7, 0, 0, espressopp.Real3D(5.0, 6.5, 5.0), 1.0, 1), (8, 0, 0, espressopp.Real3D(5.0, 7.5, 5.0), 1.0, 1), (9, 0, 0, espressopp.Real3D(5.0, 8.5, 5.0), 1.0, 1), (10, 0, 0, espressopp.Real3D(5.0, 9.5, 5.0), 1.0, 1), ] tuples = [(1,6),(2,7),(3,8),(4,9),(5,10)] self.system.storage.addParticles(particle_list, 'id', 'type', 'q', 'pos', 'mass','adrat') ftpl = espressopp.FixedTupleListAdress(self.system.storage) ftpl.addTuples(tuples) self.system.storage.setFixedTuplesAdress(ftpl) self.system.storage.decompose() # generate a verlet list vl = espressopp.VerletListAdress(self.system, cutoff=1.5, adrcut=1.5, dEx=1.0, dHy=1.0, adrCenter=[5.0, 5.0, 5.0], sphereAdr=True) # initialize lambda values integrator = espressopp.integrator.VelocityVerlet(self.system) integrator.dt = 0.01 adress = espressopp.integrator.Adress(self.system,vl,ftpl) integrator.addExtension(adress) espressopp.tools.AdressDecomp(self.system, integrator) # set up TD force thdforce = espressopp.integrator.TDforce(self.system,vl) thdforce.addForce(itype=3,filename="table_tf.tab",type=1) integrator.addExtension(thdforce) # y coordinates of particles before integration before = [self.system.storage.getParticle(i).pos[1] for i in range(1,6)] # run ten steps integrator.run(10) # y coordinates of particles after integration after = [self.system.storage.getParticle(i).pos[1] for i in range(1,6)] # run checks (as test before, just that particles should move in y-direction given the new setup and the spherical adaptive resolution geometry) self.assertEqual(before[0], after[0]) self.assertAlmostEqual(after[1], 6.596913, places=5) self.assertEqual(before[2], after[2]) self.assertEqual(before[3], after[3]) self.assertEqual(before[4], after[4])
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 test_normal(self): # set up normal domain decomposition nodeGrid = espressopp.tools.decomp.nodeGrid(espressopp.MPI.COMM_WORLD.size) cellGrid = espressopp.tools.decomp.cellGrid((10, 10, 10), nodeGrid, 1.5, 0.3) self.system.storage = espressopp.storage.DomainDecomposition(self.system, nodeGrid, cellGrid) # add some particles (normal, coarse-grained particles only) particle_list = [ (1, 1, 0, espressopp.Real3D(5.5, 5.0, 5.0), 1.0, 0), (2, 1, 0, espressopp.Real3D(6.5, 5.0, 5.0), 1.0, 0), (3, 1, 0, espressopp.Real3D(7.5, 5.0, 5.0), 1.0, 0), ] self.system.storage.addParticles(particle_list, 'id', 'type', 'q', 'pos', 'mass','adrat') self.system.storage.decompose() # generate a verlet list vl = espressopp.VerletList(self.system, cutoff=1.5) # integrator integrator = espressopp.integrator.VelocityVerlet(self.system) integrator.dt = 0.01 # Langevin Thermostat langevin = espressopp.integrator.LangevinThermostat(self.system) langevin.gamma = 1.0 langevin.temperature = 1.0 langevin.adress = False langevin.addExclusions([1]) integrator.addExtension(langevin) # coordinates of particles before integration before =[self.system.storage.getParticle(i).pos[j] for i in range(1,4) for j in range(3)] # run ten steps integrator.run(10) # coordinates of particles after integration after = [self.system.storage.getParticle(i).pos[j] for i in range(1,4) for j in range(3)] # run checks (first particle excluded, hence it should not move. The other should have moved, however, as they feel the thermostat) self.assertEqual(before[0], after[0]) self.assertEqual(before[1], after[1]) self.assertEqual(before[2], after[2]) self.assertNotEqual(before[3], after[3]) self.assertNotEqual(before[4], after[4]) self.assertNotEqual(before[5], after[5]) self.assertNotEqual(before[6], after[6]) self.assertNotEqual(before[7], after[7]) self.assertNotEqual(before[8], after[8])
def setUp(self): super(TestFixedTripleListTypesTabulated, self).setUp() # Test the energy computation. Distance between particles 1.0 particle_list = [(1, 1, espressopp.Real3D(1.0, 1.0, 2.0)), (2, 2, espressopp.Real3D(0.0, 0.0, 2.0)), (3, 1, espressopp.Real3D(1.0, 0.0, 2.0)), (4, 3, espressopp.Real3D(1.0, 0.0, 2.0)), (5, 3, espressopp.Real3D(1.0, 1.0, 2.0))] self.system.storage.addParticles(particle_list, *self.part_prop) self.system.storage.decompose() self.ftl1 = espressopp.FixedTripleList(self.system.storage) self.ftl1.addTriples([(1, 2, 3), (4, 2, 5)]) self.interaction = espressopp.interaction.FixedTripleListTypesTabulatedAngular( self.system, self.ftl1)
def setUp(self): super(TestFixedQuadrupleListTypesTabulated, self).setUp() # Test the energy computation. Distance between particles 1.0 particle_list = [ (1, 1, espressopp.Real3D(0.0, 0.0, 0.0)), (2, 1, espressopp.Real3D(2.0, 0.0, 0.0)), (3, 1, espressopp.Real3D(2.0, 0.0, 2.0)), (4, 1, espressopp.Real3D(2.0, 2.0, 2.0)), ] self.system.storage.addParticles(particle_list, *self.part_prop) self.system.storage.decompose() self.fql1 = espressopp.FixedQuadrupleList(self.system.storage) self.fql1.addQuadruples([(1, 2, 3, 4)]) self.interaction = espressopp.interaction.FixedQuadrupleListTypesTabulatedDihedral(self.system, self.fql1)
def test_densitycalculation(self): # add some particles particle_list = [ (1, 1, 0, espressopp.Real3D(5.5, 5.0, 5.0), 1.0, 0), (2, 1, 0, espressopp.Real3D(6.5, 5.0, 5.0), 1.0, 0), (3, 1, 0, espressopp.Real3D(7.5, 5.0, 5.0), 1.0, 0), (4, 1, 0, espressopp.Real3D(8.5, 5.0, 5.0), 1.0, 0), (5, 1, 0, espressopp.Real3D(9.5, 5.0, 5.0), 1.0, 0), (6, 0, 0, espressopp.Real3D(5.5, 5.0, 5.0), 1.0, 1), (7, 0, 0, espressopp.Real3D(6.5, 5.0, 5.0), 1.0, 1), (8, 0, 0, espressopp.Real3D(7.5, 5.0, 5.0), 1.0, 1), (9, 0, 0, espressopp.Real3D(8.5, 5.0, 5.0), 1.0, 1), (10, 0, 0, espressopp.Real3D(9.5, 5.0, 5.0), 1.0, 1), ] tuples = [(1, 6), (2, 7), (3, 8), (4, 9), (5, 10)] self.system.storage.addParticles(particle_list, 'id', 'type', 'q', 'pos', 'mass', 'adrat') ftpl = espressopp.FixedTupleListAdress(self.system.storage) ftpl.addTuples(tuples) self.system.storage.setFixedTuplesAdress(ftpl) self.system.storage.decompose() # generate a verlet list vl = espressopp.VerletListAdress(self.system, cutoff=1.5, adrcut=1.5, dEx=2.0, dHy=1.0, adrCenter=[5.0, 5.0, 5.0], sphereAdr=False) # initialize lambda values integrator = espressopp.integrator.VelocityVerlet(self.system) adress = espressopp.integrator.Adress(self.system, vl, ftpl) integrator.addExtension(adress) espressopp.tools.AdressDecomp(self.system, integrator) # calculate density profile densityprofile = espressopp.analysis.AdressDensity(self.system, vl) densityprofile.addExclusions([8]) density_array = densityprofile.compute(5) # run checks self.assertAlmostEqual(density_array[0], 31.250000, places=5) self.assertAlmostEqual(density_array[1], 4.464286, places=5) self.assertAlmostEqual(density_array[2], 0.0, places=5) self.assertAlmostEqual(density_array[3], 0.844595, places=5) self.assertAlmostEqual(density_array[4], 0.512295, places=5)
def test_MSID(self): # default system: NVE, dt=0.005, boxsize=(10,10,10) system1, integrator1 = espressopp.standard_system.Default((10, 10, 10)) system2, integrator2 = espressopp.standard_system.Default((10, 10, 10)) # add 10 straight chains, particle ids are numbered from 0 to 99 system1.storage.addParticles( [[cid * 10 + k, espressopp.Real3D(k, cid, 0)] for cid in range(10) for k in range(10)], 'id', 'pos') system1.storage.decompose() msid1 = espressopp.analysis.MeanSquareInternalDist(system1, chainlength=10, start_pid=0) msid1.gather() res1 = msid1.compute() # add 10 straight chains, particle ids are numbered from 1 to 100 system2.storage.addParticles( [[cid * 10 + k + 1, espressopp.Real3D(k, cid, 0)] for cid in range(10) for k in range(10)], 'id', 'pos') system2.storage.decompose() msid2 = espressopp.analysis.MeanSquareInternalDist(system2, chainlength=10, start_pid=1) msid2.gather() res2 = msid2.compute() self.assertTrue(res1[0] == 1) self.assertTrue(res1[1] == 4) self.assertTrue(res1[2] == 9) self.assertTrue(res1[3] == 16) self.assertTrue(res1[4] == 25) self.assertTrue(res1[5] == 36) self.assertTrue(res1[6] == 49) self.assertTrue(res1[7] == 64) self.assertTrue(res1[8] == 81) self.assertTrue(res2[0] == 1) self.assertTrue(res2[1] == 4) self.assertTrue(res2[2] == 9) self.assertTrue(res2[3] == 16) self.assertTrue(res2[4] == 25) self.assertTrue(res2[5] == 36) self.assertTrue(res2[6] == 49) self.assertTrue(res2[7] == 64) self.assertTrue(res2[8] == 81)
def test_particle_gets_into_region(self): # Now run integrator, particle 3 will move into region after while self.system.storage.modifyParticle(3, 'v', espressopp.Real3D(0, 0, 0.5)) for i in range(10): self.integrator.run(100) self.assertEqual(self.particle_region.size(), 3) # Particle 3 in the region self.assertEqual(self.particle_region.get_particle_ids(), [[2, 3, 4]])
def setUp(self): system, integrator = espressopp.standard_system.Default(box, rc=rc, skin=0.3, dt=0.005, temperature=1.) system.storage.addParticles([[1,0,espressopp.Real3D(0,0,1)]],'id','type','pos') system.storage.addParticles([[2,0,espressopp.Real3D(0,0,1+math.pow(2,1./6.))]],'id','type','pos') system.storage.decompose() # non-bonded LJcos potential vl = espressopp.VerletList(system, cutoff=rc) LJcos = espressopp.interaction.LJcos(phi=phi) LJcosInter = espressopp.interaction.VerletListLJcos(vl) LJcosInter.setPotential(type1=0, type2=0, potential=LJcos) system.addInteraction(LJcosInter) # set self self.system = system self.LJcosInter = LJcosInter
def get_velocity(system, n): """Obtain total velocity of a espressopp system.""" total_v = espressopp.Real3D(0.) total_m = 0. for i in range(int(n)): p = system.storage.getParticle(i) total_v += p.v*p.mass total_m += p.mass return total_v/total_m