Exemple #1
0
class MPIIOTest(ut.TestCase):

    """
    Test class for the MPI-IO core functionality.
    Generates random particles, dumps them, reads them in,
    again and then checks the input against the initially created random
    particles.
    """
    s = espressomd.system.System(box_l=[1, 1, 1])
    # Just a bunch of random interactions such that add_bond does not throw
    for i in range(nbonds):
        s.bonded_inter[i] = AngleHarmonic(bend=i, phi0=i)
    test_particles = random_particles()

    def setUp(self):
        """Sets up a system from test_particles and prepares environment
        for the tests."""
        clean_files()  # Prior call might not have completed successfully
        for p in self.test_particles:
            self.s.part.add(id=p.id, type=p.type, pos=p.pos, v=p.v)
            for b in p.bonds:
                self.s.part[p.id].add_bond(b)

    def tearDown(self):
        clean_files()

    def check_files_exist(self):
        """Checks if all necessary files have been written."""
        for fn in filenames:
            self.assertTrue(os.path.isfile(fn))

    def check_sample_system(self):
        """Checks the particles in the ESPResSo system "self.s" against the
        true values in "self.test_particles"."""
        for p, q in zip(self.s.part, self.test_particles):
            self.assertEqual(p.id, q.id)
            self.assertEqual(p.type, q.type)
            numpy.testing.assert_array_equal(numpy.copy(p.pos), q.pos)
            numpy.testing.assert_array_equal(numpy.copy(p.v), q.v)
            self.assertEqual(len(p.bonds), len(q.bonds))
            # Check all bonds
            for bp, bq in zip(p.bonds, q.bonds):
                # Bond type - "bend" stores the index of the bond
                self.assertEqual(bp[0].params["bend"], bq[0])
                # Bond partners
                numpy.testing.assert_array_equal(bp[1:], bq[1:])

    def test_mpiio(self):
        espressomd.io.mpiio.mpiio.write(
            filename, types=True, positions=True, velocities=True, bonds=True)

        self.check_files_exist()

        self.s.part.clear()  # Clear to be on the safe side
        espressomd.io.mpiio.mpiio.read(
            filename, types=True, positions=True, velocities=True, bonds=True)

        self.check_sample_system()
Exemple #2
0
    def test_bind_three_particles(self):
        # Setup particles
        self.s.part.clear()
        dx = np.array((1, 0, 0))
        dy = np.array((0, 1, 0))
        dz = np.array((0, 0, 1))
        a = np.array((0.499, 0.499, 0.499))
        b = a + 0.1 * dx
        c = a + 0.03 * dx + 0.03 * dy
        d = a + 0.03 * dx - 0.03 * dy
        e = a - 0.1 * dx

        self.s.part.add(id=0, pos=a)
        self.s.part.add(id=1, pos=b)
        self.s.part.add(id=2, pos=c)
        self.s.part.add(id=3, pos=d)
        self.s.part.add(id=4, pos=e)

        # Setup bonds
        res = 181
        for i in range(0, res, 1):
            self.s.bonded_inter[i + 2] = AngleHarmonic(bend=1,
                                                       phi0=float(i) /
                                                       (res - 1) * np.pi)
        cutoff = 0.11
        self.s.collision_detection.set_params(
            mode="bind_three_particles",
            bond_centers=self.H,
            bond_three_particles=2,
            three_particle_binding_angle_resolution=res,
            distance=cutoff)
        self.get_state_set_state_consistency()

        self.s.time_step = 1E-6
        self.s.integrator.run(1, recalc_forces=True)
        self.verify_triangle_binding(cutoff, self.s.bonded_inter[2], res)
        # Make sure no extra bonds appear
        self.s.integrator.run(1, recalc_forces=True)
        self.verify_triangle_binding(cutoff, self.s.bonded_inter[2], res)

        # Place the particles in two steps and make sure, the bonds are the
        # same
        self.s.part.clear()
        self.s.part.add(id=0, pos=a)
        self.s.part.add(id=2, pos=c)
        self.s.part.add(id=3, pos=d)
        self.s.integrator.run(1, recalc_forces=True)

        self.s.part.add(id=4, pos=e)
        self.s.part.add(id=1, pos=b)
        self.s.cell_system.set_domain_decomposition()
        self.s.integrator.run(1, recalc_forces=True)
        self.verify_triangle_binding(cutoff, self.s.bonded_inter[2], res)
        self.s.cell_system.set_n_square()
        self.s.part[:].bonds = ()
        self.s.integrator.run(1, recalc_forces=True)
        self.verify_triangle_binding(cutoff, self.s.bonded_inter[2], res)
        self.s.time_step = self.time_step
Exemple #3
0
 def set_bending_interaction(self):
     angle_harmonic = AngleHarmonic(bend=3.2, phi0=np.pi)
     sys.bonded_inter.add(angle_harmonic)
     list_of_stuff = [
         x.id for x in sys.part.select(
             lambda p: p.id in self.attributes.realz_indices)
     ]
     for x in list_of_stuff[1:-1]:
         sys.part[x].add_bond((angle_harmonic, x - 1, x + 1))