def test(self): num_poly = 2 num_mono = 5 polymer.create_polymer(start_pos=[1, 1, 1], N_P=num_poly, bond_length=0.9, bond=self.fene, MPC=num_mono, start_id=2) # Was the start id considered # bond=fene,start_id=2) for i in 0, 1: self.assertTrue(not self.system.part.exists(i)) # Were all other particles placed in the correct order for i in range(2, 2 + num_mono * num_poly): self.assertTrue(self.system.part.exists(i)) # Total number of particles self.assertEqual(len(self.system.part), num_mono * num_poly) # Start position np.testing.assert_allclose(np.copy(self.system.part[2].pos), [1., 1., 1.]) # Distance between consecutive particles for i in range(num_poly): first_particle = 2 + num_mono * i for j in range(first_particle + 1, first_particle + num_mono): print(first_particle, j) self.assertAlmostEqual(self.system.distance( self.system.part[j], self.system.part[j - 1]), 0.9, places=5) # Test polymer with specified pos2 self.system.part.clear() polymer.create_polymer(start_pos=[1, 1, 1], pos2=[1.9, 1, 1], N_P=1, bond_length=0.9, bond=self.fene, MPC=num_mono, start_id=2, angle2=1) np.testing.assert_allclose(np.copy(self.system.part[2].pos), [1., 1., 1.]) np.testing.assert_allclose(np.copy(self.system.part[3].pos), [1.9, 1., 1.])
def setUpClass(self): box_l = 20.0 # start with a small bo self.system.box_l = np.array([box_l, box_l, box_l]) self.system.cell_system.set_n_square(use_verlet_lists=False) fene = FeneBond(k=30, d_r_max=2) self.system.bonded_inter.add(fene) polymer.create_polymer(N_P=self.num_poly, bond_length=0.9, MPC=self.num_mono, bond=fene) # bring two polymers to opposite corners: # far in centre cell, but mirror images are close head_id = 0 tail_id = head_id + self.num_mono cm = np.mean(self.system.part[head_id:tail_id].pos, axis=0) self.system.part[head_id:tail_id].pos = self.system.part[ head_id:tail_id].pos - cm + self.system.box_l head_id = self.num_mono + 1 tail_id = head_id + self.num_mono cm = np.mean(self.system.part[head_id:tail_id].pos, axis=0) self.system.part[head_id:tail_id].pos -= cm
def calc(var): # AVB: Create an output directory for this to store the output files outdir = "./Noelle/r01.5kBT4Ads/1000=3.2" if not os.path.exists(outdir): os.makedirs(outdir) # Setup constant time_step = 0.01 loops = 30 step_per_loop = 100 # AVB: the parameters (that I usually use) a = 0.05 r0 = 2.0 * a kBT = 4.0e-6 vwf_type = 0 collagen_type = 1 monomer_mass = 0.01 box_l = 32.0 #print("Shear velocity:") #shear_velocity = float(input()) #vy = box_l*shear_velocity vy = var print(vy) v = [0, vy, 0] # System setup system = 0 system = System(box_l=[box_l, box_l, box_l]) system.set_random_state_PRNG() np.random.seed(seed=system.seed) system.cell_system.skin = 0.4 mpc = 20 # The number of monomers has been set to be 20 as default # Change this value for further simulations # Fene interaction fene = interactions.FeneBond(k=0.04, d_r_max=0.3) system.bonded_inter.add(fene) # Setup polymer of part_id 0 with fene bond # AVB: Notice the mode, max_tries and shield parameters for pruned self-avoiding random walk algorithm polymer.create_polymer(N_P=1, MPC=mpc, bond=fene, bond_length=r0, start_pos=[29.8, 16.0, 16.0], mode=2, max_tries=100, shield=0.6 * r0) # AVB: setting the type of particles and changing mass of each monomer to 0.01 system.part[:].type = vwf_type system.part[:].mass = monomer_mass # AVB: I suggest to add Lennard-Jones interaction between the monomers # AVB: to reproduce hydrophobicity # AVB: parameters for the potential (amplitude and cut-off redius) amplVwfVwf = 4.0 * kBT # sometimes we change this to 2.0*kBT rcutVwfVwf = 1.5 * r0 # AVB: the potential system.non_bonded_inter[vwf_type, vwf_type].lennard_jones.set_params( epsilon=amplVwfVwf, sigma=r0 / 1.122, shift="auto", cutoff=rcutVwfVwf, min=r0 * 0.6) print("Warming up the polymer chain.") ## For longer chains (>100) an extensive ## warmup is neccessary ... system.time_step = 0.002 system.thermostat.set_langevin(kT=4.0e-6, gamma=1.0) # AVB: Here the Langevin thermostat is needed, because we have not yet initialized the LB-fluid. # AVB: And somehow it is necessary so that the polymer adopts the equilibrium conformation of the globule. # AVB: you may skip this step for i in range(100): system.force_cap = float(i) + 1 system.integrator.run(100) print("Warmup finished.") system.force_cap = 0 system.integrator.run(100) system.time_step = time_step system.integrator.run(500) # AVB: the following command turns the Langevin thermostat on in line 49 system.thermostat.turn_off() # AVB: This command sets the velocities of all particles to zero system.part[:].v = [0, 0, 0] # AVB: The density was too small here. I have set 1.0 for now. # AVB: It would be necessary to recalculate, but the density of the liquid should not affect the movements of the polymer (this is how our physical model works). lbf = espressomd.lb.LBFluid(agrid=1, dens=1.0, visc=1.0e2, tau=time_step, fric=0.01) system.actors.add(lbf) system.thermostat.set_lb(kT=4.0e-6) # Setup boundaries walls = [lbboundaries.LBBoundary() for k in range(2)] walls[0].set_params(shape=shapes.Wall(normal=[1, 0, 0], dist=1.5), velocity=v) walls[1].set_params(shape=shapes.Wall(normal=[-1, 0, 0], dist=-30.5)) for wall in walls: system.lbboundaries.add(wall) print("Warming up the system with LB fluid.") system.integrator.run(5000) print("LB fluid warming finished.") # AVB: after this you should have a completely collapsed polymer globule # AVB: If you want to watch the process of globule formation in Paraview, just change 5000 to 0 in line 100 N = 25 x_coord = np.array([30] * N) y_coord = np.arange(14, 24, 5 / N) z_coord = np.arange(14, 24, 5 / N) for i in range(N): for j in range(N): system.part.add(id=i * N + j + 100, pos=np.array([x_coord[i], y_coord[j], z_coord[i]]), v=np.array([0, 0, 0]), type=i * N + j + 100) all_collagen = range(100, (N - 1) * N + (N - 1) + 100) system.comfixed.types = all_collagen for i in range(100, (N - 1) * N + (N - 1) + 100): system.non_bonded_inter[vwf_type, i].lennard_jones.set_params(epsilon=amplVwfVwf, sigma=r0 / 1.122, shift="auto", cutoff=rcutVwfVwf, min=r0 * 0.6) # configure correlators com_pos = ComPosition(ids=(0, )) c = Correlator(obs1=com_pos, tau_lin=16, tau_max=loops * step_per_loop, delta_N=1, corr_operation="square_distance_componentwise", compress1="discard1") system.auto_update_accumulators.add(c) print("Sampling started.") print("lenth after warmup") print( system.analysis.calc_re(chain_start=0, number_of_chains=1, chain_length=mpc - 1)[0]) lengths = [] ylengths = [] for i in range(loops): system.integrator.run(step_per_loop) system.analysis.append() lengths.append( system.analysis.calc_re(chain_start=0, number_of_chains=1, chain_length=mpc - 1)[0]) lbf.print_vtk_velocity(outdir + "/" + str(vy) + "%04i.vtk" % i) system.part.writevtk(outdir + "/" + str(vy) + "vwf_all%04i.vtk" % i, types=all_collagen) system.part.writevtk(outdir + "/" + str(vy) + "vwf_poly%04i.vtk" % i, types=[0]) cor = list(system.part[:].pos) y = [] for l in cor: y.append(l[1]) ylengths.append(max(y) - min(y)) sys.stdout.write("\rSampling: %05i" % i) sys.stdout.flush() walls[0].set_params(shape=shapes.Wall(normal=[1, 0, 0], dist=1.5)) walls[1].set_params(shape=shapes.Wall(normal=[-1, 0, 0], dist=-30.5)) for i in range(100): system.integrator.run(step_per_loop) lengths.append( system.analysis.calc_re(chain_start=0, number_of_chains=1, chain_length=mpc - 1)[0]) system.part.writevtk(outdir + "/" + str(vy) + "vwf_all[r0=2,kBT=4]intheEND.vtk") with open(outdir + "/lengths" + str(vy) + ".dat", "a") as datafile: datafile.write("\n".join(map(str, lengths))) with open(outdir + "/lengthsY" + str(vy) + ".dat", "a") as datafile: datafile.write("\n".join(map(str, ylengths))) mean_vy = [(vy * 10000) / 32, sum(ylengths) / len(ylengths)] print("mean_vy") print(mean_vy) with open(outdir + "/mean_vy" + "2kBT_2r0" + ".dat", "a") as datafile: datafile.write(" ".join(map(str, mean_vy))) c.finalize() corrdata = c.result() corr = zeros((corrdata.shape[0], 2)) corr[:, 0] = corrdata[:, 0] corr[:, 1] = (corrdata[:, 2] + corrdata[:, 3] + corrdata[:, 4]) / 3 savetxt(outdir + "/msd_nom" + str(mpc) + ".dat", corr) with open(outdir + "/rh_out.dat", "a") as datafile: rh = system.analysis.calc_rh(chain_start=0, number_of_chains=1, chain_length=mpc - 1) datafile.write(str(mpc) + " " + str(rh[0]) + "\n")
mpc = int(sys.argv[1]) except: raise ValueError("First argument cannot be transformed into integer!") # Lennard-Jones interaction system.non_bonded_inter[0,0].lennard_jones.set_params( epsilon=1.0, sigma=1.0, shift=0.25, cutoff=1.226) # Fene interaction fene = interactions.FeneBond(k=7, d_r_max=2) system.bonded_inter.add(fene) # Setup polymer of part_id 0 with fene bond polymer.create_polymer(N_P=1, MPC=mpc, bond=fene, bond_length=1) print("Warming up the polymer chain.") ## For longer chains (>100) an extensive ## warmup is neccessary ... system.time_step = 0.002 system.thermostat.set_langevin(kT=1.0, gamma=10) for i in range(100): system.force_cap = i system.integrator.run(1000) print("Warmup finished.") system.force_cap = 0 system.integrator.run(10000)
system.thermostat.set_langevin(kT=1.0, gamma=1.0) system.cell_system.set_n_square(use_verlet_lists=False) outfile = open('polymer.vtf', 'w') 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=2) system.bonded_inter.add(fene) polymer.create_polymer(N_P=1, bond_length=1.0, type_poly_neutral=0, type_poly_charged=0, MPC=50, bond=fene, start_pos=[0., 0., 0.]) vtf.writevsf(system, outfile) ############################################################# # Warmup # ############################################################# warm_steps = 10 lj_cap = 1 system.force_cap = lj_cap i = 0 act_min_dist = system.analysis.min_dist()
system.box_l = [100, 100, 100] system.thermostat.set_langevin(kT=1.0, gamma=1.0) system.cell_system.set_n_square(use_verlet_lists=False) outfile = open('polymer.vtf', 'w') 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=2) system.bonded_inter.add(fene) polymer.create_polymer(N_P=1, bond_length=1.0, type_poly_neutral=0, type_poly_charged=0, MPC=50, bond=fene) vtf.writevsf(system, outfile) ############################################################# # Warmup # ############################################################# warm_steps = 10 lj_cap = 1 system.force_cap = lj_cap i = 0 act_min_dist = system.analysis.min_dist() # warmp with zero temperature to remove overlaps
# domain decomposition with verlet list: three equivalent commands cs.set_domain_decomposition() cs.set_domain_decomposition(True) cs.set_domain_decomposition(use_verlet_lists=True) system.thermostat.set_langevin(kT=1.0, gamma=1.0) 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) polymer.create_polymer( N_P=1, bond_length=0.97, MPC=100, bond=fene, start_pos=[0, 0, 0]) 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() print("Testing with verlet lists...") cs.set_domain_decomposition(use_verlet_lists=True) for skin in np.arange(5, 15, 1): profile() cs.set_n_square(True) print("Testing with N-squared ...")
# domain decomposition with verlet list: three equivalent commands cs.set_domain_decomposition() cs.set_domain_decomposition(True) cs.set_domain_decomposition(use_verlet_lists=True) system.thermostat.set_langevin(kT=1.0, gamma=1.0) 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) polymer.create_polymer(N_P=1, bond_length=0.97, MPC=100, bond=fene) 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() print("Testing with verlet lists...") cs.set_domain_decomposition(use_verlet_lists=True) for skin in np.arange(5, 15, 1): profile() cs.set_n_square(True) print("Testing with N-squared ...")
import espressomd # pylint: disable=import-error from espressomd.io.writer import h5md # pylint: disable=import-error 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) system.cell_system.skin = 0.4 fene = interactions.FeneBond(k=10, d_r_max=2) system.bonded_inter.add(fene) polymer.create_polymer(N_P=5, bond_length=1.0, MPC=50, bond=fene) 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, write_charge=True, write_ordered=True) for i in range(1): h5_file.write() h5_file.flush() h5_file.close()
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) system.cell_system.skin = 0.4 fene = interactions.FeneBond(k=10, d_r_max=2) system.bonded_inter.add(fene) polymer.create_polymer(N_P=5, bond_length=1.0, MPC=50, bond=fene, start_pos=[1., 1., 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, write_charge=True, write_ordered=True) for i in range(1): h5_file.write() h5_file.flush()
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 polymer.create_polymer(N_P=N_P, bond_length=bond_l, MPC=MPC, start_id=0, bond=harmonic_bond, type_poly_neutral=type_HA, type_poly_charged=type_A, mode=0, val_poly=charges[type_A]) # 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- for i in range(nNaOH): system.part.add(pos=np.random.random(3) * system.box_l, type=type_OH,
# Lennard-Jones interaction #system.non_bonded_inter[0,0].lennard_jones.set_params( # epsilon=0.01, sigma=1.0, # shift="auto", cutoff=2.0**(1.0/6.0)) # Fene interaction fene = interactions.FeneBond(k=0.4, d_r_max=0.3) system.bonded_inter.add(fene) # Setup polymer of part_id 0 with fene bond # AVB: Notice the mode, max_tries and shield parameters for pruned self-avoiding random walk algorithm polymer.create_polymer(N_P=1, MPC=mpc, bond=fene, bond_length=r0, start_pos=[16.0, 16.0, 16.0], mode=2, max_tries=100, shield=0.6 * r0) # AVB: setting the type of particles and changing mass of each monomer to 0.01 system.part[:].type = vwf_type system.part[:].mass = monomer_mass # AVB: I suggest to add Lennard-Jones interaction between the monomers # AVB: to reproduce hydrophobicity # AVB: parameters for the potential (amplitude and cut-off redius) amplVwfVwf = 4.0 * kBT # sometimes we change this to 2.0*kBT rcutVwfVwf = 2.0 * r0 # AVB: the potential system.non_bonded_inter[vwf_type,
type_counter += 1 system.non_bonded_inter[type_mono, type_mono].lennard_jones.set_params( epsilon=1., sigma=1., cutoff=2.**(1. / 6.), shift="auto") # See PRL-A, Volume 33, number 5, May 1986, Gary S. Grest and Kurt Kremer k_fene = (30. * epsilon) / (sigma * sigma) r_fene = 1.5 * sigma fene = interactions.FeneBond(k=k_fene, d_r_max=r_fene) system.bonded_inter.add(fene) poly_start = 0 polymer.create_polymer(N_P=1, bond_length=0.97, MPC=n_mono, start_id=poly_start, bond=fene, type_poly_neutral=type_mono, type_poly_charged=type_mono, mode=1) poly_end = poly_start + n_mono # this is to init a polymer a s straight line #for p in range(0,n_mono): # system.part.add(id=p, pos=[p+0.5, 1,1], type=type_mono ) #for p in range(1,n_mono): # system.part[p].add_bond((fene,p-1)) print("\t** Placed {} monomers\n".format(n_mono)) cap = 1 system.non_bonded_inter.set_force_cap(cap) print("Warming up... ", )