def test_respect_constraints_wall(self): """ Check that constraints are respected. """ num_poly = 20 num_mono = 5 bond_length = 1.19 w = espressomd.shapes.Wall(normal=[0., 0., 1.], dist=0.5 * self.box_l) wall_constraint = espressomd.constraints.ShapeBasedConstraint(shape=w) c = self.system.constraints.add(wall_constraint) positions = polymer.positions( n_polymers=num_poly, beads_per_chain=num_mono, bond_length=bond_length, respect_constraints=True, seed=self.seed) positions %= self.box_l z_components = positions[:, :, 2][0] for z in z_components: print(z) self.assertGreaterEqual(z, 0.5 * self.box_l) # assert that illegal start position raises error with self.assertRaisesRegex(Exception, 'Invalid start positions.'): illegal_start = np.array([[1., 1., 0.2 * self.box_l]]) positions = polymer.positions( n_polymers=1, beads_per_chain=10, start_positions=illegal_start, bond_length=bond_length, respect_constraints=True, seed=self.seed) self.system.constraints.remove(wall_constraint)
def test_start_positions(self): """ Check that setting start positions behaves correctly. """ num_poly = 90 num_mono = 25 bond_length = 0.83 start_positions = np.random.random((num_poly, 3)) * self.box_l # make sure that incorrect size leads to error with self.assertRaises(ValueError): positions = polymer.positions(n_polymers=num_poly + 1, beads_per_chain=num_mono, start_positions=start_positions, bond_length=bond_length, seed=self.seed) # check that start positions are actually used positions = polymer.positions(n_polymers=num_poly, beads_per_chain=num_mono, start_positions=start_positions, bond_length=bond_length, seed=self.seed) self.assertListEqual(start_positions.tolist(), positions[:, 0].tolist())
def setUpClass(cls): box_l = 20.0 # start with a small box cls.system.box_l = np.array([box_l, box_l, box_l]) cls.system.cell_system.set_n_square(use_verlet_lists=False) fene = FeneBond(k=30, d_r_max=2) cls.system.bonded_inter.add(fene) positions = polymer.positions(n_polymers=cls.num_poly, bond_length=0.9, beads_per_chain=cls.num_mono, seed=42) for p in positions: for ndx, m in enumerate(p): part_id = len(cls.system.part) cls.system.part.add(id=part_id, pos=m) if ndx > 0: cls.system.part[part_id].add_bond((fene, part_id - 1)) # bring two polymers to opposite corners: # far in cell centre, but mirror images are close head_id = 0 tail_id = head_id + cls.num_mono cm = np.mean(cls.system.part[head_id:tail_id].pos, axis=0) cls.system.part[head_id:tail_id].pos = cls.system.part[ head_id:tail_id].pos - cm + cls.system.box_l head_id = cls.num_mono + 1 tail_id = head_id + cls.num_mono cm = np.mean(cls.system.part[head_id:tail_id].pos, axis=0) cls.system.part[head_id:tail_id].pos -= cm
def test_bond_lengths(self): """ Check that distance between neighboring monomers is indeed bond_length. """ bond_lengths = [0.735, 1.459] num_poly = 10 num_mono = 25 for bond_length in bond_lengths: positions = polymer.positions( n_polymers=num_poly, beads_per_chain=num_mono, bond_length=bond_length, seed=self.seed) self.assertShape(positions, num_poly, num_mono) self.assertBondLength(positions, bond_length)
def test_min_dist(self): """ Check that min_dist is respected. """ num_poly = 5 num_mono = 150 bond_length = 0.945 positions = polymer.positions( n_polymers=num_poly, beads_per_chain=num_mono, bond_length=bond_length, min_distance=bond_length, seed=self.seed) self.assertBondLength(positions, bond_length) self.assertMinDistGreaterEqual(positions, bond_length - 1e-10)
def test_bond_angles(self): """ Check that bond_angle is obeyed. """ bond_angles = [0.436 * np.pi, np.pi / 3., np.pi / 5.] num_poly = 10 num_mono = 25 bond_length = 1.34 for bond_angle in bond_angles: positions = polymer.positions( n_polymers=num_poly, beads_per_chain=num_mono, bond_angle=bond_angle, bond_length=bond_length, seed=self.seed) self.assertShape(positions, num_poly, num_mono) self.assertBondLength(positions, bond_length) self.assertBondAngle(positions, bond_angle, bond_length)
from espressomd import polymer from espressomd import interactions system = espressomd.System(box_l=[100.0, 100.0, 100.0]) system.set_random_state_PRNG() #system.seed = system.cell_system.get_state()['n_nodes'] * [1234] system.time_step = 0.01 system.thermostat.set_langevin(kT=1.0, gamma=1.0, seed=42) system.cell_system.skin = 0.4 fene = interactions.FeneBond(k=10, d_r_max=2) system.bonded_inter.add(fene) positions = polymer.positions(n_polymers=5, beads_per_chain=50, bond_length=1.0, seed=1234) for polymer in positions: for i, pos in enumerate(polymer): id = len(system.part) system.part.add(id=id, pos=pos) if i > 0: system.part[id].add_bond((fene, id - 1)) system.integrator.run(steps=0) h5_file = h5md.H5md(filename="sample.h5", write_pos=True, write_vel=True, write_force=True, write_species=True, write_mass=False,
c2 = system.constraints.add(particle_type=0, penetrable=False, only_positive=False, shape=ceil) # create stiff FENE bonds fene = interactions.FeneBond(k=30, d_r_max=2) system.bonded_inter.add(fene) # start it next to the wall to test it! start = np.array([1, 1, 1 + wall_offset]) # polymer.positions will avoid violating the constraints positions = polymer.positions(n_polymers=1, beads_per_chain=50, bond_length=1.0, seed=1234, min_distance=0.9, respect_constraints=True) for i, pos in enumerate(positions[0]): id = len(system.part) system.part.add(id=id, pos=pos) if i > 0: system.part[id].add_bond((fene, id - 1)) # Warmup ############################################################# minimize_steps = 20 minimize_n_times = 10 min_dist = 0.9
# bonding interaction parameter bond_l = 1.2 # bond length kbond = 100 # force constant for harmonic bond harmonic_bond = interactions.HarmonicBond(k=kbond, r_0=bond_l) system.bonded_inter.add(harmonic_bond) # non-bonding interactions (LJ) lj_eps = 1.0 lj_sig = 1.0 lj_cut = 1.12246 lj_shift = 0.0 # setting up the polymer positions = polymer.positions(n_polymers=N_P, beads_per_chain=MPC, bond_length=bond_l, seed=13) for polymer in positions: for i, pos in enumerate(polymer): id = len(system.part) system.part.add(id=id, pos=pos, type=type_A, q=charges[type_A]) if i > 0: system.part[id].add_bond((harmonic_bond, id - 1)) # setting up counterions for i in range(N0): system.part.add(pos=np.random.random(3) * system.box_l, type=type_H, q=charges[type_H]) # setting up other ions # - Na+ and OH-
box_v = n_part / density Box_l = (box_v**(1. / 3.)) * np.ones(3) system.change_volume_and_rescale_particles(d_new=Box_l[0]) #system.thermostat.set_langevin(kT=1, gamma=1, seed=88) system.time_step = 0.01 system.cell_system.skin = 0.1 print("The Vol. of Box Simulation is", box_v, "\n") ############################################ ###### initializing polymers ####### ############################################ for k in frac_range: polymers = polymer.positions(n_polymers=n_polymers, beads_per_chain=beads_per_chain, bond_length=1., seed=88) frac_phobic = k polymers_list = [] c = 0 ## unnecessary list. creates a list that gonna contains others lists. for p in polymers: polymers_list.append( [x for x in range(c, c + beads_per_chain)] ) ## inserts a list(numbered from c to c+beads_per_chain) into polymers_list for each polymer p in polymers c += beads_per_chain for i, m in enumerate(p): if i < beads_per_chain * frac_phobic: id = len(system.part) system.part.add(id=id, type=0, pos=m) if i > 0:
cs.set_domain_decomposition(True) cs.set_domain_decomposition(use_verlet_lists=True) system.thermostat.set_langevin(kT=1.0, gamma=1.0, seed=42) system.time_step = 0.01 # Create a minimal polymer system.non_bonded_inter[0, 0].lennard_jones.set_params(epsilon=1, sigma=1, cutoff=2**(1. / 6), shift="auto") fene = interactions.FeneBond(k=10, d_r_max=1.5) system.bonded_inter.add(fene) positions = polymer.positions(n_polymers=1, beads_per_chain=100, bond_length=0.97, seed=1234, min_distance=0.969) for i, pos in enumerate(positions[0]): id = len(system.part) system.part.add(id=id, pos=pos) if i > 0: system.part[id].add_bond((fene, id - 1)) n_steps = 1000 print("Testing without verlet lists...") cs.set_domain_decomposition(use_verlet_lists=False) for skin in np.arange(5, 15, 1): profile()