def test_modify_velocity(self): part = particles.PointParticles(4) part.v = self.four_by3 assert_equals(part.n, 4) sttr = lambda v: part.__setattr__("v", v) assert_raises(ValueError, sttr, self.three_by3) np.testing.assert_array_equal(part.v, self.four_by3)
def test_modify_force(self): part = particles.PointParticles(4) part.f = self.four_by3 assert_equals(part.n, 4) sttr = lambda f: part.__setattr__("f", f) assert_raises(ValueError, sttr, self.three_by3) np.testing.assert_array_equal(part.f, self.four_by3)
def test_modify_position(self): part = particles.PointParticles(4) me = self.four_by3.copy() part.x = self.four_by3 np.testing.assert_array_equal(part.x, self.four_by3) part.x[0, 0] = 1000 np.testing.assert_array_equal(me, self.four_by3)
def test_modify_position(self): part = particles.PointParticles(4) part.x = self.four_by3 assert_equals(part.n, 4) sttr = lambda x: part.__setattr__("x", x) assert_raises(ValueError, sttr, self.three_by3) np.testing.assert_array_equal(part.x, self.four_by3)
def test_modify_mass(self): part = particles.PointParticles(4) part.mass = np.array([1.0, 1.0, 2.0, 2.0], dtype=np.float32) assert_equals(part.n, 4) part.mass = 1.0 np.testing.assert_array_equal(part.mass, np.array([1, 1, 1, 1], dtype=np.float32)) sttr = lambda mass: part.__setattr__("mass", mass) assert_raises(ValueError, sttr, np.array([1.0, 1.0, 1.0]))
def test_modify_type(self): part = particles.PointParticles(4) part.t = np.array([1, 1, 2, 2], dtype=np.int32) np.testing.assert_array_equal(part.t, np.array([1, 1, 2, 2])) part.t = 1 np.testing.assert_array_equal(part.t, np.array([1, 1, 1, 1], dtype=np.int32)) sttr = lambda t: part.__setattr__("t", t) assert_raises(ValueError, sttr, np.array([1, 1, 1]))
from pexmd import particles, box, integrator, interaction import numpy as np import matplotlib.pyplot as plt # Weird way to initialize the particles (see #2) positions = np.array([[-0.6, -0.6, 0.0], [0.6, -0.5, 0.0], [-0.6, 0.6, 0.0], [0.6, 0.6, 0.0]]) part = particles.PointParticles(len(positions)) part.x = positions part.t = 1 part.mass = np.array([3.0, 3.0, 2.0, 3.0]) dt = 0.005 evol = integrator.Andersen(dt, 100, 0.5) # We should initalize this in a much better way (see #3) x0 = np.array([-0.7] * 3) xf = np.array([0.7] * 3) b = box.Box(x0, xf, t='Fixed') #lj = interaction.LennardJones([1, 1], 5.4, 1.0, 1.0, "None") lj = interaction.Morse([1, 1], 5.4, 1.0, 1.0, "None") pp = [] kk = [] tt = [] for t in np.arange(0, 2, dt): part.x, part.v = evol.first_step(part.x, part.v, part.a) part.x, part.v = b.wrap_boundary(part.x, part.v) part.f, e = lj.forces(part.x, part.v, part.t) part.x, part.v = evol.last_step(part.x, part.v, part.a) tt.append(t)
def test_calculate_acceleration(self): part = particles.PointParticles(4) part.f = self.four_by3 part.mass = 2.0 np.testing.assert_array_equal(part.a, self.four_by3 / 2)
def test_create_point_particles(self): part = particles.PointParticles(3) np.testing.assert_array_equal(part.idx, np.arange(3))
nparticles = 80 dt = 0.1 t_end = 20 temperature_ini = 100.0 scale = 100. # Initializing particles: positions_ini = np.random.rand(nparticles, 3) positions_ini = scale * 10000 * positions_ini velocities_ini = np.random.normal(0., math.sqrt(temperature_ini), size=(nparticles, 3)) #velocities_ini = np.zeros((nparticles, 3), dtype=np.float32) masses_ini = np.full((nparticles), 1.) part = particles.PointParticles(nparticles) part.x = positions_ini part.v = velocities_ini part.t = 1 part.mass = masses_ini evol = integrator.Andersen(dt, temperature_ini, 10.) # We should initalize this in a much better way (see #3) x0 = np.array([-scale] * 3) xf = np.array([scale] * 3) b = box.Box(x0, xf, t='Periodic') #lj = interaction.LennardJones([1, 1], 5.4, 1.0, 1.0, "Displace") lj = interaction.Morse([1, 1], 5.4, 1.0, 1.0, 1.0, "Displace")
def test_set_position_wrong_size(self): part = particles.PointParticles(4) sttr = lambda x: part.__setattr__("x", x) assert_raises(ValueError, sttr, self.three_by3)
def test_set_position_from_list(self): part = particles.PointParticles(4) part.x = self.lfour_by3 assert_equals(part.n, 4) assert_equals(type(part.x), np.ndarray)
def test_set_position_from_array(self): part = particles.PointParticles(4) part.x = self.four_by3 assert_equals(part.n, 4)