Ejemplo n.º 1
0
    def check_global(self, N, kT, steps, v_minmax, n_bins, error_tol,
                     recalc_forces):
        """
        Test Langevin/Brownian dynamics velocity distribution with global kT
        and gamma.

        Parameters
        ----------
        N : :obj:`int`
            Number of particles.
        kT : :obj:`float`
            Global temperature.
        steps : :obj:`int`
            Number of sampling steps.
        v_minmax : :obj:`float`
            Velocity range.
        n_bins : :obj:`int`
            Number of bins.
        error_tol : :obj:`float`
            Error tolerance.
        recalc_forces : :obj:`bool`
            True if the forces should be recalculated after every step.
        """
        system = self.system

        # Place particles
        system.part.add(pos=np.random.random((N, 3)))

        # Enable rotation if compiled in
        if espressomd.has_features("ROTATION"):
            system.part[:].rotation = [1, 1, 1]

        # Warmup
        system.integrator.run(20)

        vel_obs = ParticleVelocities(ids=system.part[:].id)
        vel_acc = TimeSeries(obs=vel_obs)
        system.auto_update_accumulators.add(vel_acc)

        if espressomd.has_features("ROTATION"):
            omega_obs = ParticleBodyAngularVelocities(ids=system.part[:].id)
            omega_acc = TimeSeries(obs=omega_obs)
            system.auto_update_accumulators.add(omega_acc)

        # Sampling
        v_stored = np.zeros((steps, N, 3))
        omega_stored = np.zeros((steps, N, 3))
        for i in range(steps):
            system.integrator.run(1, recalc_forces=recalc_forces)
            v_stored[i] = system.part[:].v
            if espressomd.has_features("ROTATION"):
                omega_stored[i] = system.part[:].omega_body

        vel = vel_acc.time_series().reshape((-1, 3))
        self.check_velocity_distribution(vel, v_minmax, n_bins, error_tol, kT)
        if espressomd.has_features("ROTATION"):
            omega = omega_acc.time_series().reshape((-1, 3))
            self.check_velocity_distribution(omega, v_minmax, n_bins,
                                             error_tol, kT)
Ejemplo n.º 2
0
    def check_noise_correlation(self, kT, steps, delta):
        """Test the Langevin/Brownian noise is uncorrelated.

        Parameters
        ----------
        kT : :obj:`float`
            Global temperature.
        steps : :obj:`int`
            Number of sampling steps.
        delta : :obj:`float`
            Error tolerance.
        """

        system = self.system
        vel_obs = ParticleVelocities(ids=system.part[:].id)
        vel_series = TimeSeries(obs=vel_obs)
        system.auto_update_accumulators.add(vel_series)
        if espressomd.has_features("ROTATION"):
            system.part[:].rotation = (1, 1, 1)
            omega_obs = ParticleBodyAngularVelocities(ids=system.part[:].id)
            omega_series = TimeSeries(obs=omega_obs)
            system.auto_update_accumulators.add(omega_series)

        system.integrator.run(steps)

        # test translational noise correlation
        vel = np.array(vel_series.time_series())
        for ind in range(2):
            for i in range(3):
                for j in range(i, 3):
                    corrcoef = np.dot(vel[:, ind, i], vel[:, ind,
                                                          j]) / steps / kT
                    if i == j:
                        self.assertAlmostEqual(corrcoef, 1.0, delta=delta)
                    else:
                        self.assertAlmostEqual(corrcoef, 0.0, delta=delta)

        # test rotational noise correlation
        if espressomd.has_features("ROTATION"):
            omega = np.array(omega_series.time_series())
            for ind in range(2):
                for i in range(3):
                    for j in range(3):
                        corrcoef = np.dot(omega[:, ind, i],
                                          omega[:, ind, j]) / steps / kT
                        if i == j:
                            self.assertAlmostEqual(corrcoef, 1.0, delta=delta)
                        else:
                            self.assertAlmostEqual(corrcoef, 0.0, delta=delta)
                        # translational and angular velocities should be
                        # independent
                        corrcoef = np.dot(vel[:, ind, i],
                                          omega[:, ind, j]) / steps / kT
                        self.assertAlmostEqual(corrcoef, 0.0, delta=delta)
Ejemplo n.º 3
0
    def check_per_particle(self, N, kT, gamma_local, steps, v_minmax, n_bins,
                           error_tol):
        """
        Test Langevin/Brownian dynamics velocity distribution with global and
        particle-specific kT/gamma. Covers all combinations of particle
        specific-gamma and temp set or not set.

        Parameters
        ----------
        N : :obj:`int`
            Number of particles.
        kT : :obj:`float`
            Global temperature.
        gamma_local : :obj:`float`
            Per-particle gamma.
        steps : :obj:`int`
            Number of sampling steps.
        v_minmax : :obj:`float`
            Velocity range.
        n_bins : :obj:`int`
            Number of bins.
        error_tol : :obj:`float`
            Error tolerance.
        """
        system = self.system
        system.part.add(pos=np.random.random((N, 3)))
        if espressomd.has_features("ROTATION"):
            system.part[:].rotation = [1, 1, 1]

        if espressomd.has_features("PARTICLE_ANISOTROPY"):
            gamma_local = 3 * [gamma_local]

        # Set different gamma on 2nd half of particles
        system.part[N // 2:].gamma = gamma_local

        system.integrator.run(50)

        vel_obs = ParticleVelocities(ids=system.part[:].id)
        vel_acc = TimeSeries(obs=vel_obs)
        system.auto_update_accumulators.add(vel_acc)

        if espressomd.has_features("ROTATION"):
            omega_obs = ParticleBodyAngularVelocities(ids=system.part[:].id)
            omega_acc = TimeSeries(obs=omega_obs)
            system.auto_update_accumulators.add(omega_acc)

        system.integrator.run(steps)

        vel = vel_acc.time_series().reshape((-1, 3))
        self.check_velocity_distribution(vel, v_minmax, n_bins, error_tol, kT)
        if espressomd.has_features("ROTATION"):
            omega = omega_acc.time_series().reshape((-1, 3))
            self.check_velocity_distribution(omega, v_minmax, n_bins,
                                             error_tol, kT)
Ejemplo n.º 4
0
    def test_08__noise_correlation(self):
        """Checks that the Brownian noise is uncorrelated"""

        system = self.system
        system.part.clear()
        system.time_step = 0.01
        system.cell_system.skin = 0.1
        system.part.add(id=(0, 1), pos=np.zeros((2, 3)))
        vel_obs = ParticleVelocities(ids=system.part[:].id)
        vel_series = TimeSeries(obs=vel_obs)
        system.auto_update_accumulators.add(vel_series)
        if espressomd.has_features("ROTATION"):
            system.part[:].rotation = (1, 1, 1)
            omega_obs = ParticleBodyAngularVelocities(ids=system.part[:].id)
            omega_series = TimeSeries(obs=omega_obs)
            system.auto_update_accumulators.add(omega_series)

        kT = 3.2
        system.thermostat.set_brownian(kT=kT, gamma=2.1, seed=17)
        steps = int(1e4)
        system.integrator.run(steps)
        system.auto_update_accumulators.clear()

        # test translational noise correlation
        vel = np.array(vel_series.time_series())
        for ind in range(2):
            for i in range(3):
                for j in range(i, 3):
                    corrcoef = np.dot(vel[:, ind, i], vel[:, ind,
                                                          j]) / steps / kT
                    if i == j:
                        self.assertAlmostEqual(corrcoef, 1.0, delta=0.04)
                    else:
                        self.assertLessEqual(np.abs(corrcoef), 0.04)

        # test rotational noise correlation
        if espressomd.has_features("ROTATION"):
            omega = np.array(omega_series.time_series())
            for ind in range(2):
                for i in range(3):
                    for j in range(3):
                        corrcoef = np.dot(omega[:, ind, i],
                                          omega[:, ind, j]) / steps / kT
                        if i == j:
                            self.assertAlmostEqual(corrcoef, 1.0, delta=0.04)
                        else:
                            self.assertLessEqual(np.abs(corrcoef), 0.04)
                        # translational and angular velocities should be
                        # independent
                        corrcoef = np.dot(vel[:, ind, i],
                                          omega[:, ind, j]) / steps / kT
                        self.assertLessEqual(np.abs(corrcoef), 0.04)
Ejemplo n.º 5
0
    def test_06__diffusion(self):
        """This tests rotational and translational diffusion coeff via Green-Kubo"""
        system = self.system
        system.part.clear()

        kT = 1.37
        dt = 0.1
        system.time_step = dt

        # Translational gamma. We cannot test per-component, if rotation is on,
        # because body and space frames become different.
        gamma = 3.1

        # Rotational gamma
        gamma_rot_i = 4.7
        gamma_rot_a = [4.2, 1, 1.2]

        # If we have langevin per particle:
        # per particle kT
        per_part_kT = 1.6
        # Translation
        per_part_gamma = 1.63
        # Rotational
        per_part_gamma_rot_i = 2.6
        per_part_gamma_rot_a = [2.4, 3.8, 1.1]

        # Particle with global thermostat params
        p_global = system.part.add(pos=(0, 0, 0))
        # Make sure, mass doesn't change diff coeff
        self.setup_diff_mass_rinertia(p_global)

        # particle specific gamma, kT, and both
        if espressomd.has_features("LANGEVIN_PER_PARTICLE"):
            p_gamma = system.part.add(pos=(0, 0, 0))
            self.setup_diff_mass_rinertia(p_gamma)
            if espressomd.has_features("PARTICLE_ANISOTROPY"):
                p_gamma.gamma = per_part_gamma, per_part_gamma, per_part_gamma
                if espressomd.has_features("ROTATION"):
                    p_gamma.gamma_rot = per_part_gamma_rot_a
            else:
                p_gamma.gamma = per_part_gamma
                if espressomd.has_features("ROTATION"):
                    p_gamma.gamma_rot = per_part_gamma_rot_i

            p_kT = system.part.add(pos=(0, 0, 0))
            self.setup_diff_mass_rinertia(p_kT)
            p_kT.temp = per_part_kT

            p_both = system.part.add(pos=(0, 0, 0))
            self.setup_diff_mass_rinertia(p_both)
            p_both.temp = per_part_kT
            if espressomd.has_features("PARTICLE_ANISOTROPY"):
                p_both.gamma = per_part_gamma, per_part_gamma, per_part_gamma
                if espressomd.has_features("ROTATION"):
                    p_both.gamma_rot = per_part_gamma_rot_a
            else:
                p_both.gamma = per_part_gamma
                if espressomd.has_features("ROTATION"):
                    p_both.gamma_rot = per_part_gamma_rot_i

        # Thermostat setup
        if espressomd.has_features("ROTATION"):
            if espressomd.has_features("PARTICLE_ANISOTROPY"):
                # particle anisotropy and rotation
                system.thermostat.set_langevin(kT=kT,
                                               gamma=gamma,
                                               gamma_rotation=gamma_rot_a,
                                               seed=41)
            else:
                # Rotation without particle anisotropy
                system.thermostat.set_langevin(kT=kT,
                                               gamma=gamma,
                                               gamma_rotation=gamma_rot_i,
                                               seed=41)
        else:
            # No rotation
            system.thermostat.set_langevin(kT=kT, gamma=gamma, seed=41)

        system.cell_system.skin = 0.4
        system.integrator.run(100)

        # Correlators
        vel_obs = {}
        omega_obs = {}
        corr_vel = {}
        corr_omega = {}
        all_particles = [p_global]
        if espressomd.has_features("LANGEVIN_PER_PARTICLE"):
            all_particles.append(p_gamma)
            all_particles.append(p_kT)
            all_particles.append(p_both)

        # linear vel
        vel_obs = ParticleVelocities(ids=system.part[:].id)
        corr_vel = Correlator(obs1=vel_obs,
                              tau_lin=10,
                              tau_max=1.4,
                              delta_N=2,
                              corr_operation="componentwise_product",
                              compress1="discard1")
        system.auto_update_accumulators.add(corr_vel)
        # angular vel
        if espressomd.has_features("ROTATION"):
            omega_obs = ParticleBodyAngularVelocities(ids=system.part[:].id)
            corr_omega = Correlator(obs1=omega_obs,
                                    tau_lin=10,
                                    tau_max=1.5,
                                    delta_N=2,
                                    corr_operation="componentwise_product",
                                    compress1="discard1")
            system.auto_update_accumulators.add(corr_omega)

        system.integrator.run(80000)

        system.auto_update_accumulators.remove(corr_vel)
        corr_vel.finalize()
        if espressomd.has_features("ROTATION"):
            system.auto_update_accumulators.remove(corr_omega)
            corr_omega.finalize()

        # Verify diffusion
        # Translation
        # Cast gammas to vector, to make checks independent of
        # PARTICLE_ANISOTROPY
        gamma = np.ones(3) * gamma
        per_part_gamma = np.ones(3) * per_part_gamma
        self.verify_diffusion(p_global, corr_vel, kT, gamma)
        if espressomd.has_features("LANGEVIN_PER_PARTICLE"):
            self.verify_diffusion(p_gamma, corr_vel, kT, per_part_gamma)
            self.verify_diffusion(p_kT, corr_vel, per_part_kT, gamma)
            self.verify_diffusion(p_both, corr_vel, per_part_kT,
                                  per_part_gamma)

        # Rotation
        if espressomd.has_features("ROTATION"):
            # Decide on effective gamma rotation, since for rotation it is
            # direction dependent
            eff_gamma_rot = None
            per_part_eff_gamma_rot = None
            if espressomd.has_features("PARTICLE_ANISOTROPY"):
                eff_gamma_rot = gamma_rot_a
                eff_per_part_gamma_rot = per_part_gamma_rot_a
            else:
                eff_gamma_rot = gamma_rot_i * np.ones(3)
                eff_per_part_gamma_rot = per_part_gamma_rot_i * np.ones(3)

            self.verify_diffusion(p_global, corr_omega, kT, eff_gamma_rot)
            if espressomd.has_features("LANGEVIN_PER_PARTICLE"):
                self.verify_diffusion(p_gamma, corr_omega, kT,
                                      eff_per_part_gamma_rot)
                self.verify_diffusion(p_kT, corr_omega, per_part_kT,
                                      eff_gamma_rot)
                self.verify_diffusion(p_both, corr_omega, per_part_kT,
                                      eff_per_part_gamma_rot)
Ejemplo n.º 6
0
kT = 1.37
dt = 0.05

system = espressomd.System(box_l=[1.0, 1.0, 1.0])
system.set_random_state_PRNG()
#system.seed = system.cell_system.get_state()['n_nodes'] * [1234]
np.random.seed(seed=system.seed)

p = system.part.add(pos=(0, 0, 0), id=0)
system.time_step = dt
system.thermostat.set_langevin(kT=kT, gamma=gamma, seed=42)
system.cell_system.skin = 0.4
system.integrator.run(1000)

pos_obs = ParticlePositions(ids=(0, ))
vel_obs = ParticleVelocities(ids=(0, ))

c_pos = Correlator(obs1=pos_obs,
                   tau_lin=16,
                   tau_max=100.,
                   delta_N=10,
                   corr_operation="square_distance_componentwise",
                   compress1="discard1")
c_vel = Correlator(obs1=vel_obs,
                   tau_lin=16,
                   tau_max=20.,
                   delta_N=1,
                   corr_operation="scalar_product",
                   compress1="discard1")
system.auto_update_accumulators.add(c_pos)
system.auto_update_accumulators.add(c_vel)
Ejemplo n.º 7
0
                    rotation=3 * [True],
                    rinertia=3 * [1.])

    # Initialize the mean squared displacement (MSD) correlator
    tmax = system.time_step * SAMP_STEPS

    pos_id = ParticlePositions(ids=[0])
    msd = Correlator(obs1=pos_id,
                     corr_operation="square_distance_componentwise",
                     delta_N=1,
                     tau_max=tmax,
                     tau_lin=16)
    system.auto_update_accumulators.add(msd)

    # Initialize the velocity auto-correlation function (VACF) correlator
    vel_id = ParticleVelocities(ids=[0])
    vacf = Correlator(obs1=vel_id,
                      corr_operation="scalar_product",
                      delta_N=1,
                      tau_max=tmax,
                      tau_lin=16)
    system.auto_update_accumulators.add(vacf)

    # Initialize the angular velocity auto-correlation function (AVACF)
    # correlator
    ang_id = ParticleAngularVelocities(ids=[0])
    avacf = Correlator(obs1=ang_id,
                       corr_operation="scalar_product",
                       delta_N=1,
                       tau_max=tmax,
                       tau_lin=16)
Ejemplo n.º 8
0
 def test_particle_coupling(self):
     part_vel = ParticleVelocities(ids=list(range(100)))
     mean_velocity = np.mean(part_vel.calculate())
     self.assertGreater(mean_velocity, 1e-5)
system.cell_system.skin = 0.4

# Set up the DPD friction interaction
system.non_bonded_inter[0, 0].dpd.set_params(
    weight_function=1, gamma=gamma, r_cut=r_cut,
    trans_weight_function=0, trans_gamma=0, trans_r_cut=0)

# Set up the repulsive interaction
system.non_bonded_inter[0,0].hat.set_params(F_max=F_max, cutoff=r_cut)

# Warm up and equilibration
system.integrator.run(10000)

# Set up of correlators for positions and velocity
pos_obs = ParticlePositions(ids=(np.arange(n_part)))
vel_obs = ParticleVelocities(ids=(np.arange(n_part)))

c_pos = Correlator(obs1=pos_obs, tau_lin=16, tau_max=10000., delta_N=10,
                   corr_operation="square_distance_componentwise",
                   compress1="discard1")
c_vel = Correlator(obs1=vel_obs, tau_lin=16, tau_max=10., delta_N=1,
                   corr_operation="scalar_product", compress1="discard1")

system.auto_update_accumulators.add(c_pos)
system.auto_update_accumulators.add(c_vel)

# Open h5md file
h5 = h5md.H5md(filename="./trajectory.h5", write_pos=True, write_lees_edwards_offset = True, write_vel = True, write_ordered=True)

for i in range(args.samples):
    print(i, flush=True)
Ejemplo n.º 10
0
gamma = 2.4
kT = 1.37
dt = 0.05

system = espressomd.System(box_l=[1.0, 1.0, 1.0])
np.random.seed(seed=42)

p = system.part.add(pos=(0, 0, 0))
system.time_step = dt
system.thermostat.set_langevin(kT=kT, gamma=gamma, seed=42)
system.cell_system.skin = 0.4
system.integrator.run(1000)

pos_obs = ParticlePositions(ids=(p.id, ))
vel_obs = ParticleVelocities(ids=(p.id, ))

c_pos = Correlator(obs1=pos_obs,
                   tau_lin=16,
                   tau_max=100.,
                   delta_N=10,
                   corr_operation="square_distance_componentwise",
                   compress1="discard1")
c_vel = Correlator(obs1=vel_obs,
                   tau_lin=16,
                   tau_max=20.,
                   delta_N=1,
                   corr_operation="scalar_product",
                   compress1="discard1")
system.auto_update_accumulators.add(c_pos)
system.auto_update_accumulators.add(c_vel)