Пример #1
0
    def test_zz_lj(self):
        """
        Simulate an LJ liquid under linear shear and verify forces.
        This is to make sure that no pairs get lost or are outdated
        in the short range loop. To have deterministic forces, velocity
        capping is used rather than a thermostat.
        """
        system = self.system
        self.setup_lj_liquid()
        system.lees_edwards.protocol = espressomd.lees_edwards.LinearShear(
            shear_velocity=0.3, initial_pos_offset=0.01)
        system.lees_edwards.shear_direction = 2
        system.lees_edwards.shear_plane_normal = 0
        system.integrator.run(1, recalc_forces=True)
        tests_common.check_non_bonded_loop_trace(system)

        # Rewind the clock to get back the LE offset applied during force calc
        system.time = system.time - system.time_step
        tests_common.verify_lj_forces(system, 1E-7)

        system.thermostat.set_langevin(kT=.1, gamma=5, seed=2)
        system.integrator.run(50)
        tests_common.check_non_bonded_loop_trace(system)
Пример #2
0
    def run_test_lj(self):
        """This fills the system with vs-based dumbells, adds a lj potential,
          integrates and verifies forces. This is to make sure that no pairs
          get lost or are outdated in the short range loop"""
        system = self.system
        system.virtual_sites = VirtualSitesRelative()
        # Parameters
        n = 90
        phi = 0.6
        sigma = 1.
        eps = .025
        cut = sigma * 2**(1. / 6.)

        kT = 2
        gamma = .5

        # box
        l = (n / 6. * np.pi * sigma**3 / phi)**(1. / 3.)

        # Setup
        system.box_l = [l, l, l]
        system.min_global_cut = 0.501
        system.part.clear()

        system.time_step = 0.01
        system.thermostat.turn_off()

        # Dumbells consist of 2 virtual lj spheres + central particle w/o interactions
        # For n spheres, n/2 dumbells.
        for i in range(int(n / 2)):
            # Type=1, i.e., no lj ia for the center of mass particles
            system.part.add(rotation=(1, 1, 1),
                            id=3 * i,
                            pos=random.random(3) * l,
                            type=1,
                            omega_lab=0.3 * random.random(3),
                            v=random.random(3))
            # lj spheres
            system.part.add(rotation=(1, 1, 1),
                            id=3 * i + 1,
                            pos=system.part[3 * i].pos +
                            system.part[3 * i].director / 2.,
                            type=0)
            system.part.add(rotation=(1, 1, 1),
                            id=3 * i + 2,
                            pos=system.part[3 * i].pos -
                            system.part[3 * i].director / 2.,
                            type=0)
            system.part[3 * i + 1].vs_auto_relate_to(3 * i)
            self.verify_vs(system.part[3 * i + 1], verify_velocity=False)
            system.part[3 * i + 2].vs_auto_relate_to(3 * i)
            self.verify_vs(system.part[3 * i + 2], verify_velocity=False)
        system.integrator.run(0, recalc_forces=True)
        # interactions
        system.non_bonded_inter[0, 0].lennard_jones.set_params(epsilon=eps,
                                                               sigma=sigma,
                                                               cutoff=cut,
                                                               shift="auto")
        # Remove overlap
        system.integrator.set_steepest_descent(f_max=0,
                                               gamma=0.1,
                                               max_displacement=0.1)
        while system.analysis.energy()["total"] > 10 * n:
            system.integrator.run(20)
        # Integrate
        system.integrator.set_vv()
        for i in range(10):
            # Langevin to maintain stability
            system.thermostat.set_langevin(kT=kT, gamma=gamma, seed=42)
            system.integrator.run(50)
            system.thermostat.turn_off()
            # Constant energy to get rid of thermostat forces in the
            # verification
            system.integrator.run(2)
            # Check the virtual sites config,pos and vel of the lj spheres
            for j in range(int(n / 2)):
                self.verify_vs(system.part[3 * j + 1])
                self.verify_vs(system.part[3 * j + 2])

            # Verify lj forces on the particles. The non-virtual particles are
            # skipped because the forces on them originate from the vss and not
            # the lj interaction
            verify_lj_forces(system, 1E-10,
                             3 * np.arange(int(n / 2), dtype=int))

        # Test applying changes
        enegry_pre_change = system.analysis.energy()['total']
        pressure_pre_change = system.analysis.pressure()['total']
        system.part[0].pos = system.part[0].pos + (2.2, -1.4, 4.2)
        enegry_post_change = system.analysis.energy()['total']
        pressure_post_change = system.analysis.pressure()['total']
        self.assertNotAlmostEqual(enegry_pre_change, enegry_post_change)
        self.assertNotAlmostEqual(pressure_pre_change, pressure_post_change)

        # Turn off lj interaction
        system.non_bonded_inter[0, 0].lennard_jones.set_params(epsilon=0,
                                                               sigma=0,
                                                               cutoff=0,
                                                               shift=0)