def setUpClass(cls): write_ordered = False from espressomd.io.writer import h5md h5_units = h5md.UnitSystem(time='ps', mass='u', length='m', charge='e') h5 = h5md.H5md( filename="test.h5", write_pos=True, write_vel=True, write_force=True, write_species=True, write_mass=True, write_charge=True, write_ordered=write_ordered, unit_system=h5_units) h5.write() h5.flush() h5.close() cls.py_file = h5py.File("test.h5", 'r') cls.py_pos = cls.py_file['particles/atoms/position/value'][0] cls.py_img = cls.py_file['particles/atoms/image/value'][0] cls.py_vel = cls.py_file['particles/atoms/velocity/value'][0] if espressomd.has_features(['ELECTROSTATICS']): cls.py_crg = cls.py_file['particles/atoms/charge/value'][0] cls.py_f = cls.py_file['particles/atoms/force/value'][0] cls.py_id = cls.py_file['particles/atoms/id/value'][0] cls.py_bonds = cls.py_file['connectivity/atoms']
def setUpClass(cls): write_ordered = False from espressomd.io.writer import h5md # pylint: disable=import-error h5 = h5md.H5md(filename="test.h5", write_pos=True, write_vel=True, write_force=True, write_species=True, write_mass=True, write_ordered=write_ordered) h5.write() h5.flush() h5.close() cls.py_file = h5py.File("test.h5", 'r') cls.py_pos = cls.py_file['particles/atoms/position/value'][0] cls.py_img = cls.py_file['particles/atoms/image/value'][0] cls.py_vel = cls.py_file['particles/atoms/velocity/value'][0] cls.py_f = cls.py_file['particles/atoms/force/value'][0] cls.py_id = cls.py_file['particles/atoms/id/value'][0] cls.py_bonds = cls.py_file['connectivity/atoms']
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, write_charge=True, write_ordered=True) for i in range(1): h5_file.write() h5_file.flush() h5_file.close()
system = espressomd.System(box_l=[100.0, 100.0, 100.0]) 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.linear_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)) h5_units = h5md.UnitSystem(time='ps', mass='u', length='nm', charge='e') h5_file = h5md.H5md(file_path="sample.h5", unit_system=h5_units) for i in range(2): h5_file.write() system.integrator.run(steps=10) h5_file.flush() h5_file.close()
system.actors.add(lb_fluid) print("** Done LB") print("Equilibrate...", ) system.integrator.run(5000) print("** Done equilibration") system.time = 0 if save_h5md: h5_file = h5md.H5md(filename=h5md_file_name, write_pos=True, write_vel=False, write_force=False, write_species=True, write_mass=False, write_charge=True, write_ordered=True) h5_file.write() h5_file.flush() print("integrating...") while (system.time < final_time): system.integrator.run(500) if save_h5md: h5_file.write() h5_file.flush() if save_h5md: h5_file.close()
# Warmup loop for i in range(eq_steps): print("warmup step", i) system.integrator.run(steps_per_int) print("Running at temperature T={:.2f}".format(calc_temperature(system))) if espresso_release >= (4, 2): h5_opts = {"file_path": "traj.h5"} else: h5_opts = {"filename": "traj.h5"} h5_file = h5md.H5md(write_pos=True, write_vel=True, write_force=True, write_species=False, write_mass=True, write_ordered=False, **h5_opts) starttime = time.time() # Integration loop for i in range(int_steps): system.integrator.run(steps_per_int) E = system.analysis.energy() e_pot = (E['total'] - E['kinetic']) / len(system.part) print("time: {:.3f} potential energy: {:.2f}".format(i * time_step, e_pot)) h5_file.write()
system.non_bonded_inter[0, 0].tabulated.set_params(min=min_r, max=max_r, energy=p, force=f) # Warmup loop for i in range(eq_steps): print("warmup step", i) system.integrator.run(steps_per_int) print("Running at temperature T={:.2f}".format(calc_temperature(system))) h5_file = h5md.H5md(filename="traj.h5", write_pos=True, write_vel=True, write_force=True, write_species=False, write_mass=True, write_ordered=False) starttime = time.time() # Integration loop for i in range(int_steps): system.integrator.run(steps_per_int) E = system.analysis.energy() e_pot = (E['total'] - E['kinetic']) / len(system.part) print("time: {:.3f} potential energy: {:.2f}".format(i * time_step, e_pot)) h5_file.write()
# Take care of the COM movement system.galilei.galilei_transform() # Add Lees-Edwards to the script system.cell_system.node_grid = [1, n_nodes_x, n_nodes_y] system.cell_system.set_domain_decomposition( fully_connected=[True, False, False]) system.lees_edwards.protocol = lees_edwards.LinearShear(shear_velocity=vel, shear_direction=0, shear_plane_normal=1) # Open h5md file h5 = h5md.H5md(filename="./trajectory.h5", write_pos=True, write_lees_edwards_offset=True, write_vel=True, write_ordered=True) # Sampling + write h5md files for i in range(args.samples): h5.write() print("Step:", i, flush=True) system.integrator.run(iterations) #Close all the files h5.close()