def test_sphere(self): if HOOMD_v1: from hoomd_script import init, sorter, data, dump, run self.system = init.create_empty(N=2, box=data.boxdim(L=10, dimensions=2), particle_types=['A']) self.addCleanup(init.reset) else: from hoomd import init, data, run, context, lattice from hoomd.update import sort as sorter from hoomd.deprecated import dump self.system = init.create_lattice(unitcell=lattice.sq(10), n=(2, 1)) self.addCleanup(context.initialize, "--mode=cpu") hoomd.option.set_notice_level(0) self.addCleanup(self.del_system) self.mc = hpmc.integrate.sphere(seed=10) self.mc.shape_param.set("A", diameter=1.0) self.addCleanup(self.del_mc) self.system.particles[0].position = (0, 0, 0) self.system.particles[0].orientation = (1, 0, 0, 0) self.system.particles[1].position = (2, 0, 0) self.system.particles[1].orientation = (1, 0, 0, 0) if HOOMD_v1: sorter.set_params(grid=8) else: context.current.sorter.set_params(grid=8) dump.pos(filename=self.fn_pos, period=1) run(10, quiet=True) with io.open(self.fn_pos, 'r', encoding='utf-8') as posfile: traj = self.read_trajectory(posfile) shape = traj[0].shapedef['A'] assert shape.shape_class == 'sphere' assert np.isclose(shape.diameter, float(1.0))
def r_buff(warmup=200000, r_min=0.05, r_max=1.0, jumps=20, steps=5000, set_max_check_period=False): # check if initialization has occurred if not init.is_initialized(): globals.msg.error("Cannot tune r_buff before initialization\n"); # check that there is a nlist if globals.neighbor_list is None: globals.msg.error("Cannot tune r_buff when there is no neighbor list\n"); # start off at a check_period of 1 globals.neighbor_list.set_params(check_period=1); # make the warmup run hoomd_script.run(warmup); # initialize scan variables dr = (r_max - r_min) / (jumps - 1); r_buff_list = []; tps_list = []; # loop over all desired r_buff points for i in range(0,jumps): # set the current r_buff r_buff = r_min + i * dr; globals.neighbor_list.set_params(r_buff=r_buff); # run the benchmark 3 times tps = []; hoomd_script.run(steps); tps.append(globals.system.getLastTPS()) hoomd_script.run(steps); tps.append(globals.system.getLastTPS()) hoomd_script.run(steps); tps.append(globals.system.getLastTPS()) # record the median tps of the 3 tps.sort(); tps_list.append(tps[1]); r_buff_list.append(r_buff); # find the fastest r_buff fastest = tps_list.index(max(tps_list)); fastest_r_buff = r_buff_list[fastest]; # set the fastest and rerun the warmup steps to identify the max check period globals.neighbor_list.set_params(r_buff=fastest_r_buff); hoomd_script.run(warmup); # notify the user of the benchmark results globals.msg.notice(2, "r_buff = " + str(r_buff_list) + '\n'); globals.msg.notice(2, "tps = " + str(tps_list) + '\n'); globals.msg.notice(2, "Optimal r_buff: " + str(fastest_r_buff) + '\n'); globals.msg.notice(2, "Maximum check_period: " + str(globals.neighbor_list.query_update_period()) + '\n'); # set the found max check period if set_max_check_period: globals.neighbor_list.set_params(check_period=globals.neighbor_list.query_update_period()); # return the results to the script return (fastest_r_buff, globals.neighbor_list.query_update_period());
def run_brownian(self, T=0.01, runs=50000): # run brownian dynamics integration method with a step distance limit # for a bit to get rid of overlapping particles if not hasattr(self, 'bdnvt'): self.bdnvt = self.integrator.bdnvt(group=self.all, limit=2, T=T) hmd.run(runs) self.bdnvt.disable() # you have to stop the integration afterward. self.analyzer.disable()
def run_aneal(self): #reenable normal integration mode self.integrator.mode_standard(dt=0.005) if not hasattr(self, 'nvt'): self.nvt = self.integrator.nvt(group=self.all, T=variant.linear_interp(self.aneal.steps), tau=0.5) self.analyzer.enable() hmd.run(self.aneal.last()) self.analyzer.disable() self.nvt.disable()
def series(warmup=100000, repeat=20, steps=10000, limit_hours=None): # check if initialization has occurred if not init.is_initialized(): globals.msg.error("Cannot tune r_buff before initialization\n"); tps_list = []; if warmup > 0: hoomd_script.run(warmup); for i in range(0,repeat): hoomd_script.run(steps, limit_hours=limit_hours); tps_list.append(globals.system.getLastTPS()); return tps_list;
def series(warmup=100000, repeat=20, steps=10000): # check if initialization has occurred if not init.is_initialized(): globals.msg.error("Cannot tune r_buff before initialization\n"); tps_list = []; hoomd_script.run(warmup); for i in range(0,repeat): hoomd_script.run(steps); tps_list.append(globals.system.getLastTPS()); if numpy is not None: globals.msg.notice(1, "**Notice: Series average TPS: %4.2f\n" % numpy.average(tps_list)); globals.msg.notice(1, " Series median TPS : %4.2f\n" % numpy.median(tps_list)); globals.msg.notice(1, " Series TPS std dev: %4.2f" % numpy.std(tps_list)); return tps_list;
def test_convex_polyhedron(self): if HOOMD_v1: from hoomd_script import init, sorter, data, dump, run from hoomd_plugins import hpmc self.system = init.create_empty(N=2, box=data.boxdim(L=10, dimensions=2), particle_types=['A']) self.addCleanup(init.reset) else: from hoomd import init, data, run, hpmc, context, lattice from hoomd.update import sort as sorter from hoomd.deprecated import dump self.system = init.create_lattice(unitcell=lattice.sq(10), n=(2, 1)) self.addCleanup(context.initialize, "--mode=cpu") hoomd.option.set_notice_level(0) self.addCleanup(self.del_system) self.mc = hpmc.integrate.convex_polyhedron(seed=10) self.addCleanup(self.del_mc) shape_vertices = np.array([[-2, -1, -1], [-2, 1, -1], [-2, -1, 1], [-2, 1, 1], [2, -1, -1], [2, 1, -1], [2, -1, 1], [2, 1, 1]]) self.mc.shape_param.set("A", vertices=shape_vertices) self.system.particles[0].position = (0, 0, 0) self.system.particles[0].orientation = (1, 0, 0, 0) self.system.particles[1].position = (2, 0, 0) self.system.particles[1].orientation = (1, 0, 0, 0) if HOOMD_v1: sorter.set_params(grid=8) else: context.current.sorter.set_params(grid=8) pos_writer = dump.pos(filename=self.fn_pos, period=1) self.mc.setup_pos_writer(pos_writer) run(10, quiet=True) with io.open(self.fn_pos, 'r', encoding='utf-8') as posfile: traj = self.read_trajectory(posfile) shape = traj[0].shapedef['A'] assert shape.shape_class == 'poly3d' assert np.array_equal(shape.vertices, shape_vertices)
def series(warmup=100000, repeat=20, steps=10000): # check if initialization has occurred if not init.is_initialized(): globals.msg.error("Cannot tune r_buff before initialization\n") tps_list = [] hoomd_script.run(warmup) for i in range(0, repeat): hoomd_script.run(steps) tps_list.append(globals.system.getLastTPS()) if numpy is not None: globals.msg.notice( 1, "**Notice: Series average TPS: %4.2f\n" % numpy.average(tps_list)) globals.msg.notice( 1, " Series median TPS : %4.2f\n" % numpy.median(tps_list)) globals.msg.notice( 1, " Series TPS std dev: %4.2f" % numpy.std(tps_list)) return tps_list
def test_ellipsoid(self): if HOOMD_v1: from hoomd_script import init, sorter, data, dump, run self.system = init.create_empty(N=2, box=data.boxdim(L=10, dimensions=2), particle_types=['A']) self.addCleanup(init.reset) else: from hoomd import init, data, run, context, lattice from hoomd.update import sort as sorter from hoomd.deprecated import dump self.system = init.create_lattice(unitcell=lattice.sq(10), n=(2, 1)) self.addCleanup(context.initialize, "--mode=cpu") hoomd.option.set_notice_level(0) self.addCleanup(self.del_system) self.mc = hpmc.integrate.ellipsoid(seed=10) a = 0.5 b = 0.25 c = 0.125 self.mc.shape_param.set("A", a=a, b=b, c=c) self.addCleanup(self.del_mc) self.system.particles[0].position = (0, 0, 0) self.system.particles[0].orientation = (1, 0, 0, 0) self.system.particles[1].position = (2, 0, 0) self.system.particles[1].orientation = (1, 0, 0, 0) if HOOMD_v1: sorter.set_params(grid=8) else: context.current.sorter.set_params(grid=8) pos_writer = dump.pos(filename=self.fn_pos, period=1) self.mc.setup_pos_writer(pos_writer) run(10, quiet=True) with io.open(self.fn_pos, 'r', encoding='utf-8') as posfile: self.read_trajectory(posfile)
def test_sphere(self): if HOOMD_v1: from hoomd_script import init, sorter, data, dump, run self.system = init.create_empty(N=2, box=data.boxdim(L=10, dimensions=2), particle_types=['A']) self.addCleanup(init.reset) else: from hoomd import init, data, run, context, lattice from hoomd.update import sort as sorter from hoomd.deprecated import dump self.system = init.create_lattice(unitcell=lattice.sq(10), n=(2, 1)) self.addCleanup(context.initialize, "--mode=cpu") self.addCleanup(self.del_system) self.mc = hpmc.integrate.sphere(seed=10) self.mc.shape_param.set("A", diameter=1.0) self.addCleanup(self.del_mc) self.system.particles[0].position = (1, 0, 0) self.system.particles[0].orientation = (1, 0, 0, 0) self.system.particles[1].position = (2, 0, 0) self.system.particles[1].orientation = (1, 0, 0, 0) if HOOMD_v1: sorter.set_params(grid=8) else: context.current.sorter.set_params(grid=8) with tempfile.NamedTemporaryFile('r') as tmpfile: pos = dump.pos(filename=tmpfile.name, period=1) run(10, quiet=True) snapshot_0 = self.system.take_snapshot() frame_0 = garnett.trajectory.Frame.from_hoomd_snapshot(snapshot_0) run(1, quiet=True) # the hoomd pos-writer lags by one sweep tmpfile.flush() traj = self.read_trajectory(tmpfile) frame_1 = traj[-1] # Ensure that some attributes are equal between the POS file and HOOMD snapshot # (not all properties are supported by a POS file of spheres) for attr in ('box', 'position', 'types', 'typeid'): np.testing.assert_equal(getattr(frame_0, attr), getattr(frame_1, attr)) # Pos-files don't support box dimensions. frame_1.box.dimensions = self.system.box.dimensions snapshot_1 = frame_1.to_hoomd_snapshot() self.assert_snapshots_equal(snapshot_0, snapshot_1) self.system.restore_snapshot(snapshot_1) pos.disable() run(1, quiet=True) # sanity check
def find_optimal_block_sizes(save = True, only=None): from hoomd_script import bond from hoomd_script import angle from hoomd_script import improper from hoomd_script import dihedral util._disable_status_lines = True; # we cannot save if only is set if only: save = False; # list of force computes to tune fc_list = [ ('pair.table', 'pair_table_setup', 500), ('bond.table', 'bond_table_setup', 2000), ('pair.lj', 'pair_lj_setup', 500), ('pair.force_shifted_lj', 'pair_force_shifted_lj_setup', 500), ('pair.slj', 'pair_slj_setup', 500), ('pair.yukawa', 'pair_yukawa_setup', 500), ('pair.ewald', 'pair_ewald_setup', 500), ('pair.cgcmm', 'pair_cgcmm_setup', 500), ('pair.gauss', 'pair_gauss_setup', 500), ('pair.morse', 'pair_morse_setup', 500), ('pair.dpd', 'pair_dpd_setup', 500), ('pair.dpdlj', 'pair_dpdlj_setup', 500), ('pair.dpd_conservative', 'pair_dpd_conservative_setup', 500), ('bond.harmonic', 'bond.harmonic', 10000), ('bond.fene', 'bond_fene_setup', 2000), ('angle.harmonic', 'angle.harmonic', 3000), ('angle.cgcmm', 'angle.cgcmm', 2000), ('dihedral.harmonic', 'dihedral.harmonic', 1000), ('improper.harmonic', 'improper.harmonic', 1000)]; # setup the particle system to benchmark polymer = dict(bond_len=1.2, type=['A']*50, bond="linear", count=2000); N = len(polymer['type']) * polymer['count']; phi_p = 0.2; L = math.pow(math.pi * N / (6.0 * phi_p), 1.0/3.0); sysdef = init.create_random_polymers(box=hoomd.BoxDim(L), polymers=[polymer], separation=dict(A=0.35, B=0.35), seed=12) # need some angles, dihedrals, and impropers to benchmark angle_data = sysdef.sysdef.getAngleData(); dihedral_data = sysdef.sysdef.getDihedralData(); improper_data = sysdef.sysdef.getImproperData(); num_particles = len(polymer['type']) * polymer['count']; for i in range(1,num_particles-3): angle_data.addAngle(hoomd.Angle(0, i, i+1, i+2)); for i in range(1,num_particles-4): dihedral_data.addDihedral(hoomd.Dihedral(0, i, i+1, i+2, i+3)); improper_data.addDihedral(hoomd.Dihedral(0, i, i+1, i+2, i+3)); del angle_data del dihedral_data del improper_data del sysdef # run one time step to resort the particles for optimal memory access patterns hoomd_script.run(1); # list of optimal databases optimal_dbs = []; num_repeats = 3; for i in range(0,num_repeats): # initialize an empty database of optimal sizes optimal_db = {}; # for each force compute for (fc_name,fc_init,n) in fc_list: if only and (not fc_name in only): continue globals.msg.notice(2, 'Benchmarking ' + str(fc_name) + '\n'); # create it and benchmark it fc = eval(fc_init + '()') optimal = _find_optimal_block_size_fc(fc, n) optimal_db[fc_name] = optimal; # clean up fc.disable() del fc # now, benchmark the neighbor list if (only is None) or (only == 'nlist'): globals.msg.notice(2, 'Benchmarking nlist\n'); lj = pair_lj_setup(); optimal = _find_optimal_block_size_nl(globals.neighbor_list, 100) optimal_db['nlist'] = optimal; del lj; # and the neighbor list filtering if (only is None) or (only == 'nlist.filter'): globals.msg.notice(2, 'Benchmarking nlist.filter\n'); lj = pair_lj_setup(); globals.neighbor_list.reset_exclusions(exclusions = ['bond', 'angle']) optimal = _find_optimal_block_size_nl_filter(globals.neighbor_list, 200) optimal_db['nlist.filter'] = optimal; del lj; # add it to the list optimal_dbs.append(optimal_db); # print out all the optimal block sizes globals.msg.notice(2, '*****************\n'); globals.msg.notice(2, 'Optimal block sizes found:\n'); for db in optimal_dbs: globals.msg.notice(2, str(db) + '\n'); # create a new db with the common optimal settings globals.msg.notice(2, "Chosing common optimal block sizes:\n"); common_optimal_db = _choose_optimal_block_sizes(optimal_dbs); globals.msg.notice(2, str(common_optimal_db) + '\n'); globals.msg.notice(2, '*****************\n') if save: _save_override_file(common_optimal_db); ## Currently not working for some reason..... # init.reset(); util._disable_status_lines = False;
def find_optimal_block_sizes(save=True, only=None): from hoomd_script import bond from hoomd_script import angle from hoomd_script import improper from hoomd_script import dihedral util._disable_status_lines = True # we cannot save if only is set if only: save = False # list of force computes to tune fc_list = [('pair.table', 'pair_table_setup', 500), ('bond.table', 'bond_table_setup', 2000), ('pair.lj', 'pair_lj_setup', 500), ('pair.force_shifted_lj', 'pair_force_shifted_lj_setup', 500), ('pair.slj', 'pair_slj_setup', 500), ('pair.yukawa', 'pair_yukawa_setup', 500), ('pair.ewald', 'pair_ewald_setup', 500), ('pair.cgcmm', 'pair_cgcmm_setup', 500), ('pair.gauss', 'pair_gauss_setup', 500), ('pair.morse', 'pair_morse_setup', 500), ('pair.dpd', 'pair_dpd_setup', 500), ('pair.dpdlj', 'pair_dpdlj_setup', 500), ('pair.dpd_conservative', 'pair_dpd_conservative_setup', 500), ('bond.harmonic', 'bond.harmonic', 10000), ('bond.fene', 'bond_fene_setup', 2000), ('angle.harmonic', 'angle.harmonic', 3000), ('angle.cgcmm', 'angle.cgcmm', 2000), ('dihedral.harmonic', 'dihedral.harmonic', 1000), ('improper.harmonic', 'improper.harmonic', 1000)] # setup the particle system to benchmark polymer = dict(bond_len=1.2, type=['A'] * 50, bond="linear", count=2000) N = len(polymer['type']) * polymer['count'] phi_p = 0.2 L = math.pow(math.pi * N / (6.0 * phi_p), 1.0 / 3.0) sysdef = init.create_random_polymers(box=hoomd.BoxDim(L), polymers=[polymer], separation=dict(A=0.35, B=0.35), seed=12) # need some angles, dihedrals, and impropers to benchmark angle_data = sysdef.sysdef.getAngleData() dihedral_data = sysdef.sysdef.getDihedralData() improper_data = sysdef.sysdef.getImproperData() num_particles = len(polymer['type']) * polymer['count'] for i in range(1, num_particles - 3): angle_data.addAngle(hoomd.Angle(0, i, i + 1, i + 2)) for i in range(1, num_particles - 4): dihedral_data.addDihedral(hoomd.Dihedral(0, i, i + 1, i + 2, i + 3)) improper_data.addDihedral(hoomd.Dihedral(0, i, i + 1, i + 2, i + 3)) del angle_data del dihedral_data del improper_data del sysdef # run one time step to resort the particles for optimal memory access patterns hoomd_script.run(1) # list of optimal databases optimal_dbs = [] num_repeats = 3 for i in range(0, num_repeats): # initialize an empty database of optimal sizes optimal_db = {} # for each force compute for (fc_name, fc_init, n) in fc_list: if only and (not fc_name in only): continue globals.msg.notice(2, 'Benchmarking ' + str(fc_name) + '\n') # create it and benchmark it fc = eval(fc_init + '()') optimal = _find_optimal_block_size_fc(fc, n) optimal_db[fc_name] = optimal # clean up fc.disable() del fc # now, benchmark the neighbor list if (only is None) or (only == 'nlist'): globals.msg.notice(2, 'Benchmarking nlist\n') lj = pair_lj_setup() optimal = _find_optimal_block_size_nl(globals.neighbor_list, 100) optimal_db['nlist'] = optimal del lj # and the neighbor list filtering if (only is None) or (only == 'nlist.filter'): globals.msg.notice(2, 'Benchmarking nlist.filter\n') lj = pair_lj_setup() globals.neighbor_list.reset_exclusions( exclusions=['bond', 'angle']) optimal = _find_optimal_block_size_nl_filter( globals.neighbor_list, 200) optimal_db['nlist.filter'] = optimal del lj # add it to the list optimal_dbs.append(optimal_db) # print out all the optimal block sizes globals.msg.notice(2, '*****************\n') globals.msg.notice(2, 'Optimal block sizes found:\n') for db in optimal_dbs: globals.msg.notice(2, str(db) + '\n') # create a new db with the common optimal settings globals.msg.notice(2, "Chosing common optimal block sizes:\n") common_optimal_db = _choose_optimal_block_sizes(optimal_dbs) globals.msg.notice(2, str(common_optimal_db) + '\n') globals.msg.notice(2, '*****************\n') if save: _save_override_file(common_optimal_db) ## Currently not working for some reason..... # init.reset(); util._disable_status_lines = False