def test_time_series(self): """Check that accumulator results are the same as the respective numpy result. """ system = espressomd.System(box_l=3 * [1.]) system.part.add(pos=np.random.random((N_PART, 3))) obs = ParticlePositions(ids=system.part[:].id) time_series = TimeSeries(obs=obs) positions = [] for _ in range(10): pos = np.random.random((N_PART, 3)) positions.append(pos) system.part[:].pos = pos time_series.update() for result, expected in zip(time_series.time_series(), positions): np.testing.assert_array_equal( np.array(result).reshape((N_PART, 3)), expected) time_series.clear() self.assertEqual(len(time_series.time_series()), 0)
def test_msd_global_temp(self): """Tests diffusion via MSD for global gamma and temperature""" gamma = 9.4 kT = 0.37 dt = 0.5 system = self.system system.part.clear() p = system.part.add(pos=(0, 0, 0), id=0) system.time_step = dt system.thermostat.set_brownian(kT=kT, gamma=gamma, seed=42) system.cell_system.skin = 0.4 pos_obs = ParticlePositions(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") system.auto_update_accumulators.add(c_pos) system.integrator.run(500000) c_pos.finalize() # Check MSD msd = c_pos.result() system.auto_update_accumulators.clear() def expected_msd(x): return 2. * kT / gamma * x for i in range(2, 6): np.testing.assert_allclose(msd[i, 2:5], expected_msd(msd[i, 0]), rtol=0.02)
gamma = 2.4 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)
gamma=1., seed=np.random.randint(0, 1000)) # Place a single active particle that can rotate in all 3 dimensions. # Set mass and rotational inertia to separate the timescales for # translational and rotational diffusion. system.part.add(pos=[5.0, 5.0, 5.0], swimming={'v_swim': vel}, mass=0.1, 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)
# Perform equilibration # Integrate for k in range(equi_steps): print("Equilibration: {} of {}".format(k, equi_steps)) system.integrator.run(equi_length) ########################################################################## for cnt in range(5): # Set up the MSD calculation tmax = prod_steps * prod_length * dt pos_id = ParticlePositions(ids=[cent]) 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) ## Exercise 7a ## # Construct the auto-correlators for the AVACF, using the example # of the MSD. ... # Perform production # Integrate
system.time_step = eq_tstep for i in range(equilibration_iterations): system.integrator.run(equilibration_interval) energies = system.analysis.energy() print("eq run {} at time {}\n".format(i, system.time)) print("\nEquilibration done\n") system.time_step = time_step # 2. Setup an observable for the particle positions from espressomd.observables import ParticlePositions # We pass the ids of the particles to be tracked to the observable. # Here this is 0..n_part part_pos = ParticlePositions(ids=range(n_part)) # 3. Define a correlator recording the square distances the particles have traveled # in various time intervals from espressomd.correlators import Correlator # The correlator works with the part_pos observable. Here, no second # observableis needed # For short time spans, we record in linear time distances # for larger time spans, we record in larger and larger steps. # Use 10 linear measurements 10 time steps apart, each. # The "square_distance_component_wise" correlation operation tells # the correlator how to calculate a result from the measurements of the # observables at different times
system.thermostat.set_dpd(kT=kT, seed=42) 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):
import numpy as np 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)