def enable_histograms(self, ftm_min, ftm_max): util.print_status_line() self.ftm_min = ftm_min self.ftm_max = ftm_max self.ftm_parameters_set = True
def read_xml(filename, restart = None, time_step = None, wrap_coordinates = False): util.print_status_line(); # initialize GPU/CPU execution configuration and MPI early my_exec_conf = _create_exec_conf_deprecated(); # check if initialization has already occured if is_initialized(): globals.msg.error("Cannot initialize more than once\n"); raise RuntimeError("Error reading XML file"); filename_to_read = filename; if restart is not None: if os.path.isfile(restart): filename_to_read = restart; # read in the data initializer = hoomd.HOOMDInitializer(my_exec_conf,filename_to_read,wrap_coordinates); snapshot = initializer.getSnapshot() my_domain_decomposition = _create_domain_decomposition(snapshot._global_box); if my_domain_decomposition is not None: globals.system_definition = hoomd.SystemDefinition(snapshot, my_exec_conf, my_domain_decomposition); else: globals.system_definition = hoomd.SystemDefinition(snapshot, my_exec_conf); # initialize the system if time_step is None: globals.system = hoomd.System(globals.system_definition, initializer.getTimeStep()); else: globals.system = hoomd.System(globals.system_definition, time_step); _perform_common_init_tasks(); return hoomd_script.data.system_data(globals.system_definition);
def read_snapshot(snapshot): util.print_status_line(); # initialize GPU/CPU execution configuration and MPI early my_exec_conf = _create_exec_conf_deprecated(); # check if initialization has already occured if is_initialized(): globals.msg.error("Cannot initialize more than once\n"); raise RuntimeError("Error creating random polymers"); # broadcast snapshot metadata so that all ranks have _global_box (the user may have set box only on rank 0) snapshot._broadcast(my_exec_conf); my_domain_decomposition = _create_domain_decomposition(snapshot._global_box); if my_domain_decomposition is not None: globals.system_definition = hoomd.SystemDefinition(snapshot, my_exec_conf, my_domain_decomposition); else: globals.system_definition = hoomd.SystemDefinition(snapshot, my_exec_conf); # initialize the system globals.system = hoomd.System(globals.system_definition, 0); _perform_common_init_tasks(); return hoomd_script.data.system_data(globals.system_definition);
def read_xml(filename, time_step=None, wrap_coordinates=False): util.print_status_line() # initialize GPU/CPU execution configuration and MPI early my_exec_conf = _create_exec_conf() # check if initialization has already occured if is_initialized(): globals.msg.error("Cannot initialize more than once\n") raise RuntimeError("Error creating random polymers") # read in the data initializer = hoomd.HOOMDInitializer(my_exec_conf, filename, wrap_coordinates) snapshot = initializer.getSnapshot() my_domain_decomposition = _create_domain_decomposition(snapshot.global_box) if my_domain_decomposition is not None: globals.system_definition = hoomd.SystemDefinition(snapshot, my_exec_conf, my_domain_decomposition) else: globals.system_definition = hoomd.SystemDefinition(snapshot, my_exec_conf) # initialize the system if time_step is None: globals.system = hoomd.System(globals.system_definition, initializer.getTimeStep()) else: globals.system = hoomd.System(globals.system_definition, time_step) _perform_common_init_tasks() return data.system_data(globals.system_definition)
def read_bin(filename, time_step=None): util.print_status_line() globals.msg.warning("init.read_bin is deprecated and will be removed in the next release") # initialize GPU/CPU execution configuration and MPI early my_exec_conf = _create_exec_conf() # check if initialization has already occurred if is_initialized(): globals.msg.error("Cannot initialize more than once\n") raise RuntimeError("Error initializing") # read in the data initializer = hoomd.HOOMDBinaryInitializer(my_exec_conf, filename) snapshot = initializer.getSnapshot() my_domain_decomposition = _create_domain_decomposition(snapshot.global_box) if my_domain_decomposition is not None: globals.system_definition = hoomd.SystemDefinition(snapshot, my_exec_conf, my_domain_decomposition) else: globals.system_definition = hoomd.SystemDefinition(snapshot, my_exec_conf) # initialize the system if time_step is None: globals.system = hoomd.System(globals.system_definition, initializer.getTimeStep()) else: globals.system = hoomd.System(globals.system_definition, time_step) _perform_common_init_tasks() return data.system_data(globals.system_definition)
def __init__(self, group): util.print_status_line(); # Error out in MPI simulations if (hoomd.is_MPI_available()): if globals.system_definition.getParticleData().getDomainDecomposition(): globals.msg.error("charge.pppm is not supported in multi-processor simulations.\n\n") raise RuntimeError("Error initializing PPPM.") # initialize the base class force._force.__init__(self); # create the c++ mirror class # update the neighbor list neighbor_list = pair._update_global_nlist(0.0) neighbor_list.subscribe(lambda: self.log*0.0) if not globals.exec_conf.isCUDAEnabled(): self.cpp_force = hoomd.PPPMForceCompute(globals.system_definition, neighbor_list.cpp_nlist, group.cpp_group); else: self.cpp_force = hoomd.PPPMForceComputeGPU(globals.system_definition, neighbor_list.cpp_nlist, group.cpp_group); globals.system.addCompute(self.cpp_force, self.force_name); # error check flag - must be set to true by set_params in order for the run() to commence self.params_set = False; # initialize the short range part of electrostatics util._disable_status_lines = True; self.ewald = pair.ewald(r_cut = 0.0); util._disable_status_lines = False;
def __init__(self, name=None): util.print_status_line() # check that some bonds are defined if globals.system_definition.getBondData().getNumBonds() == 0: globals.msg.error("No bonds are defined.\n") raise RuntimeError("Error creating bond forces") # initialize the base class bond._bond.__init__(self, name) # create the c++ mirror class if not globals.exec_conf.isCUDAEnabled(): self.cpp_force = _custom_pair_potentials.PotentialBondFENENOLJ( globals.system_definition, self.name) else: self.cpp_force = _custom_pair_potentials.PotentialBondFENENOLJGPU( globals.system_definition, self.name) self.cpp_force.setBlockSize( tune._get_optimal_block_size('bond.fene')) globals.system.addCompute(self.cpp_force, self.force_name) # setup the coefficient options self.required_coeffs = ['k', 'r0', 'roff']
def __init__(self, filename, period, group=None, overwrite=False, offdiag=False): util.print_status_line() # initialize base class analyze._analyzer.__init__(self) # Find the dcd extension and construct new file names end = filename.find('.dcd') file_diag = filename[:end] + '.diag.dcd' file_off = filename[:end] + '.off.dcd' # create the c++ mirror class reported_period = period if type(period) != type(1): reported_period = 1000 if group is None: util._disable_status_lines = True group = hs_group.all() util._disable_status_lines = False self.cpp_analyzer = _custom_analyzers_plugin.StressPerAtomDumpWriter( globals.system_definition, file_diag, file_off, int(reported_period), group.cpp_group, overwrite, offdiag) self.setupAnalyzer(period)
def enable_histograms(self,ftm_min, ftm_max): util.print_status_line() self.ftm_min = ftm_min self.ftm_max = ftm_max self.ftm_parameters_set = True
def __init__(self, r_cut, name=None): util.print_status_line(); # tell the base class how we operate # initialize the base class pair.pair.__init__(self, r_cut, name); # update the neighbor list neighbor_list = pair._update_global_nlist(r_cut); neighbor_list.subscribe(lambda: self.log*self.get_max_rcut()) # create the c++ mirror class if not globals.exec_conf.isCUDAEnabled(): self.cpp_force = _evaluators_ext_template.PotentialPairLJ2(globals.system_definition, neighbor_list.cpp_nlist, self.name); self.cpp_class = _evaluators_ext_template.PotentialPairLJ2; else: neighbor_list.cpp_nlist.setStorageMode(hoomd.NeighborList.storageMode.full); self.cpp_force = _evaluators_ext_template.PotentialPairLJ2GPU(globals.system_definition, neighbor_list.cpp_nlist, self.name); self.cpp_class = _evaluators_ext_template.PotentialPairLJ2GPU; # you can play with the block size value, set it to any multiple of 32 up to 1024. Use the # lj.benchmark() command to find out which block size performs the fastest self.cpp_force.setBlockSize(64); globals.system.addCompute(self.cpp_force, self.force_name); # setup the coefficent options self.required_coeffs = ['epsilon', 'sigma', 'alpha']; self.pair_coeff.set_default_coeff('alpha', 1.0);
def __init__(self, filename="dump", period=None, file1=None, file2=None, compress=True): util.print_status_line(); # initialize base class analyze._analyzer.__init__(self); # create the c++ mirror class self.cpp_analyzer = hoomd.HOOMDBinaryDumpWriter(globals.system_definition, filename); self.cpp_analyzer.enableCompression(compress) # handle the alternation setting # first, check that they are both set if (file1 is not None and file2 is None) or (file2 is not None and file1 is None): globals.msg.error("file1 and file2 must either both be set or both left as None.\n"); raise RuntimeError('Error initializing dump.bin'); if file1 is not None: self.cpp_analyzer.setAlternatingWrites(file1, file2) if period is None: globals.msg.warning("Alternating file output set for dump.bin, but period is not set.\n"); globals.msg.warning("No output will be written.\n"); globals.msg.warning("dump.bin does not support triclinic boxes.\n"); globals.msg.warning("dump.bin is deprecated and will be replaced in v1.0.0\n"); if period is not None: self.setupAnalyzer(period); self.enabled = True; self.prev_period = 1; elif filename != "dump": util._disable_status_lines = True; self.write(filename); util._disable_status_lines = False; else: self.enabled = False;
def __init__(self, filename, quantities, period, header_prefix='', overwrite=False, phase=-1): util.print_status_line(); # initialize base class _analyzer.__init__(self); if filename is None or filename == "": filename = ""; period = 1; # create the c++ mirror class self.cpp_analyzer = hoomd.Logger(globals.system_definition, filename, header_prefix, overwrite); self.setupAnalyzer(period, phase); # set the logged quantities quantity_list = hoomd.std_vector_string(); for item in quantities: quantity_list.append(str(item)); self.cpp_analyzer.setLoggedQuantities(quantity_list); # add the logger to the list of loggers globals.loggers.append(self); # store metadata self.metadata_fields = ['filename','period'] self.filename = filename self.period = period
def write_restart(self): util.print_status_line(); if not self.restart: raise ValueError("Cannot write_restart() when restart=False"); self.cpp_analyzer.analyze(globals.system.getCurrentTimeStep());
def __init__(self, r_buff=None, check_period=None, d_max=None, dist_check=True, name=None): util.print_status_line() _nlist.__init__(self) # the r_cut will be overridden by the pair potentials attached to the neighbor list default_r_cut = 0.0 # assume r_buff = 0.4 as a typical default value that the user can (and should) override default_r_buff = 0.4 # create the C++ mirror class if not globals.exec_conf.isCUDAEnabled(): self.cpp_nlist = hoomd.NeighborListTree(globals.system_definition, default_r_cut, default_r_buff) else: self.cpp_nlist = hoomd.NeighborListGPUTree(globals.system_definition, default_r_cut, default_r_buff) self.cpp_nlist.setEvery(1, True) if name is None: self.name = "tree_nlist_%d" % tree.cur_id tree.cur_id += 1 else: self.name = name globals.system.addCompute(self.cpp_nlist, self.name) # register this neighbor list with the globals globals.neighbor_lists += [self] # save the user defined parameters util._disable_status_lines = True self.set_params(r_buff, check_period, d_max, dist_check) util._disable_status_lines = False
def disable(self, log=False): util.print_status_line(); util._disable_status_lines = True; force._force.disable(self, log); self.ewald.disable(log); util._disable_status_lines = False;
def enable(self): util.print_status_line() if self.enabled == False: globals.msg.error( "you cannot re-enable DCD output after it has been disabled\n") raise RuntimeError('Error enabling updater')
def tags(tag_min, tag_max=None, name=None): util.print_status_line(); # check if initialization has occurred if not init.is_initialized(): globals.msg.error("Cannot create a group before initialization\n"); raise RuntimeError('Error creating group'); # handle the optional argument if tag_max is not None: if name is None: name = 'tags ' + str(tag_min) + '-' + str(tag_max); else: # if the option is not specified, tag_max is set equal to tag_min to include only that particle in the range # and the name is chosen accordingly tag_max = tag_min; if name is None: name = 'tag ' + str(tag_min); # create the group selector = hoomd.ParticleSelectorTag(globals.system_definition, tag_min, tag_max); cpp_group = hoomd.ParticleGroup(globals.system_definition, selector); # notify the user of the created group globals.msg.notice(2, 'Group "' + name + '" created containing ' + str(cpp_group.getNumMembersGlobal()) + ' particles\n'); # return it in the wrapper class return group(name, cpp_group);
def all(): util.print_status_line() # check if initialization has occurred if not init.is_initialized(): globals.msg.error("Cannot create a group before initialization\n") raise RuntimeError('Error creating group') name = 'all' # the all group is special: when the first one is created, it is cached in globals and future calls to group.all() # return the cached version if globals.group_all is not None: expected_N = globals.system_definition.getParticleData().getNGlobal() if len(globals.group_all) != expected_N: globals.msg.error( "globals.group_all does not appear to be the group of all particles!\n" ) raise RuntimeError('Error creating group') return globals.group_all # create the group selector = hoomd.ParticleSelectorAll(globals.system_definition) cpp_group = hoomd.ParticleGroup(globals.system_definition, selector, True) # notify the user of the created group globals.msg.notice( 2, 'Group "' + name + '" created containing ' + str(cpp_group.getNumMembersGlobal()) + ' particles\n') # cache it and then return it in the wrapper class globals.group_all = group(name, cpp_group) return globals.group_all
def __init__(self, r_cut, name=None): util.print_status_line() # tell the base class how we operate # initialize the base class pair.pair.__init__(self, r_cut, name) # update the neighbor list neighbor_list = pair._update_global_nlist(r_cut) neighbor_list.subscribe(lambda: self.log * self.get_max_rcut()) # create the c++ mirror class if not globals.exec_conf.isCUDAEnabled(): self.cpp_force = _evaluators_ext_template.PotentialPairLJ2( globals.system_definition, neighbor_list.cpp_nlist, self.name) self.cpp_class = _evaluators_ext_template.PotentialPairLJ2 else: neighbor_list.cpp_nlist.setStorageMode( hoomd.NeighborList.storageMode.full) self.cpp_force = _evaluators_ext_template.PotentialPairLJ2GPU( globals.system_definition, neighbor_list.cpp_nlist, self.name) self.cpp_class = _evaluators_ext_template.PotentialPairLJ2GPU # you can play with the block size value, set it to any multiple of 32 up to 1024. Use the # lj.benchmark() command to find out which block size performs the fastest self.cpp_force.setBlockSize(64) globals.system.addCompute(self.cpp_force, self.force_name) # setup the coefficent options self.required_coeffs = ['epsilon', 'sigma', 'alpha'] self.pair_coeff.set_default_coeff('alpha', 1.0)
def __init__(self, group, P, r): util.print_status_line(); # Error out in MPI simulations if (hoomd.is_MPI_available()): if globals.system_definition.getParticleData().getDomainDecomposition(): globals.msg.error("constrain.sphere is not supported in multi-processor simulations.\n\n") raise RuntimeError("Error initializing constraint force.") # initialize the base class _constraint_force.__init__(self); # create the c++ mirror class P = hoomd.make_scalar3(P[0], P[1], P[2]); if not globals.exec_conf.isCUDAEnabled(): self.cpp_force = hoomd.ConstraintSphere(globals.system_definition, group.cpp_group, P, r); else: self.cpp_force = hoomd.ConstraintSphereGPU(globals.system_definition, group.cpp_group, P, r); globals.system.addCompute(self.cpp_force, self.force_name); # store metadata self.group = group self.P = P self.r = r self.metadata_fields = ['group','P', 'r']
def __init__(self, walls, r_cut=False, d_max=None, name=""): util.print_status_line() # tell the base class how we operate # initialize the base class wallpotential.__init__(self, walls, r_cut, name) # update the neighbor list if d_max is None: sysdef = globals.system_definition d_max = sysdef.getParticleData().getMaxDiameter() globals.msg.notice(2, "Notice: slj set d_max=" + str(d_max) + "\n") # create the c++ mirror class if not globals.exec_conf.isCUDAEnabled(): self.cpp_force = hoomd.WallsPotentialSLJ(globals.system_definition, self.name) self.cpp_class = hoomd.WallsPotentialSLJ else: self.cpp_force = hoomd.WallsPotentialSLJGPU( globals.system_definition, self.name) self.cpp_class = hoomd.WallsPotentialSLJGPU globals.system.addCompute(self.cpp_force, self.force_name) # setup the coefficient options self.required_coeffs += ['epsilon', 'sigma', 'alpha'] self.force_coeff.set_default_coeff('alpha', 1.0)
def __init__(self, filename, period, group=None, overwrite=False, unwrap_full=False, unwrap_rigid=False, angle_z=False): util.print_status_line() # initialize base class analyze._analyzer.__init__(self) # create the c++ mirror class reported_period = period try: reported_period = int(period) except TypeError: reported_period = 1 if group is None: util._disable_status_lines = True group = hs_group.all() util._disable_status_lines = False self.cpp_analyzer = hoomd.DCDDumpWriter(globals.system_definition, filename, int(reported_period), group.cpp_group, overwrite) self.cpp_analyzer.setUnwrapFull(unwrap_full) self.cpp_analyzer.setUnwrapRigid(unwrap_rigid) self.cpp_analyzer.setAngleZ(angle_z) self.setupAnalyzer(period)
def enable(self): util.print_status_line() util._disable_status_lines = True force._force.enable(self) self.ewald.enable() util._disable_status_lines = False
def disable(self, log=False): util.print_status_line() util._disable_status_lines = True force._force.disable(self, log) self.ewald.disable(log) util._disable_status_lines = False
def __init__(self, filename="dump", period=None, phase=-1): util.print_status_line(); # Error out in MPI simulations if (hoomd.is_MPI_available()): if globals.system_definition.getParticleData().getDomainDecomposition(): globals.msg.error("dump.pdb is not supported in multi-processor simulations.\n\n") raise RuntimeError("Error writing PDB file.") # initialize base class analyze._analyzer.__init__(self); # create the c++ mirror class self.cpp_analyzer = hoomd.PDBDumpWriter(globals.system_definition, filename); if period is not None: self.setupAnalyzer(period, phase); self.enabled = True; self.prev_period = 1; elif filename != "dump": util._disable_status_lines = True; self.write(filename); util._disable_status_lines = False; else: self.enabled = False;
def __init__(self, fx, fy, fz, group=None): util.print_status_line() # initialize the base class _force.__init__(self) # create the c++ mirror class if (group is not None): self.cpp_force = hoomd.ConstForceCompute(globals.system_definition, group.cpp_group, fx, fy, fz) else: self.cpp_force = hoomd.ConstForceCompute( globals.system_definition, globals.group_all.cpp_group, fx, fy, fz) # store metadata self.metadata_fields = ['fx', 'fy', 'fz'] self.fx = fx self.fy = fy self.fz = fz if group is not None: self.metadata_fields.append('group') self.group = group globals.system.addCompute(self.cpp_force, self.force_name)
def set_from_file(self, bondname, filename): util.print_status_line() # open the file f = open(filename) r_table = [] V_table = [] F_table = [] # read in lines from the file for line in f.readlines(): line = line.strip() # skip comment lines if line[0] == '#': continue # split out the columns cols = line.split() values = [float(f) for f in cols] # validate the input if len(values) != 3: globals.msg.error( "bond.table: file must have exactly 3 columns\n") raise RuntimeError("Error reading table file") # append to the tables r_table.append(values[0]) V_table.append(values[1]) F_table.append(values[2]) # validate input if self.width != len(r_table): globals.msg.error("bond.table: file must have exactly " + str(self.width) + " rows\n") raise RuntimeError("Error reading table file") # extract rmin and rmax rmin_table = r_table[0] rmax_table = r_table[-1] # check for even spacing dr = (rmax_table - rmin_table) / float(self.width - 1) for i in range(0, self.width): r = rmin_table + dr * i if math.fabs(r - r_table[i]) > 1e-3: globals.msg.error( "bond.table: r must be monotonically increasing and evenly spaced\n" ) raise RuntimeError("Error reading table file") util._disable_status_lines = True self.bond_coeff.set(bondname, func=_table_eval, rmin=rmin_table, rmax=rmax_table, coeff=dict(V=V_table, F=F_table, width=self.width)) util._disable_status_lines = True
def read_snapshot(snapshot): util.print_status_line() # initialize GPU/CPU execution configuration and MPI early my_exec_conf = _create_exec_conf_deprecated() # check if initialization has already occured if is_initialized(): globals.msg.error("Cannot initialize more than once\n") raise RuntimeError("Error initializing") # broadcast snapshot metadata so that all ranks have _global_box (the user may have set box only on rank 0) snapshot._broadcast(my_exec_conf) my_domain_decomposition = _create_domain_decomposition( snapshot._global_box) if my_domain_decomposition is not None: globals.system_definition = hoomd.SystemDefinition( snapshot, my_exec_conf, my_domain_decomposition) else: globals.system_definition = hoomd.SystemDefinition( snapshot, my_exec_conf) # initialize the system globals.system = hoomd.System(globals.system_definition, 0) _perform_common_init_tasks() return hoomd_script.data.system_data(globals.system_definition)
def __init__(self, name=None): util.print_status_line() # check that some bonds are defined if globals.system_definition.getBondData().getNumBonds() == 0: print >> sys.stderr, "\n***Error! No bonds are defined.\n" raise RuntimeError("Error creating bond forces") # initialize the base class _bond.__init__(self, name) # create the c++ mirror class if not globals.exec_conf.isCUDAEnabled(): self.cpp_force = _evaluators_ext_template.PotentialBondHarmonicDPD( globals.system_definition, self.name) else: self.cpp_force = _evaluators_ext_template.PotentialBondHarmonicDPDGPU( globals.system_definition, self.name) # you can play with the block size value, set it to any multiple of 32 up to 1024. Use the # harmonic_dpd.benchmark() command to find out which block size performs the fastest self.cpp_force.setBlockSize(64) globals.system.addCompute(self.cpp_force, self.force_name) self.required_coeffs = ['k', 'r0', 'r_cut', 'A']
def __init__(self, group, P, r): util.print_status_line() # Error out in MPI simulations if (hoomd.is_MPI_available()): if globals.system_definition.getParticleData( ).getDomainDecomposition(): globals.msg.error( "constrain.sphere is not supported in multi-processor simulations.\n\n" ) raise RuntimeError("Error initializing constraint force.") # initialize the base class _constraint_force.__init__(self) # create the c++ mirror class P = hoomd.make_scalar3(P[0], P[1], P[2]) if not globals.exec_conf.isCUDAEnabled(): self.cpp_force = hoomd.ConstraintSphere(globals.system_definition, group.cpp_group, P, r) else: self.cpp_force = hoomd.ConstraintSphereGPU( globals.system_definition, group.cpp_group, P, r) globals.system.addCompute(self.cpp_force, self.force_name) # store metadata self.group = group self.P = P self.r = r self.metadata_fields = ['group', 'P', 'r']
def __init__(self, filename, period=None, unwrap_rigid=False, phase=-1, addInfo=None): util.print_status_line() # initialize base class analyze._analyzer.__init__(self) # create the c++ mirror class self.cpp_analyzer = hoomd.POSDumpWriter(globals.system_definition, filename) self.cpp_analyzer.setUnwrapRigid(unwrap_rigid) if addInfo is not None: self.cpp_analyzer.setAddInfo(addInfo) if period is not None: self.setupAnalyzer(period, phase) self.enabled = True self.prev_period = 1 else: self.enabled = False # store metadata self.filename = filename self.period = period self.unwrap_rigid = unwrap_rigid self.metadata_fields = ['filename', 'period', 'unwrap_rigid']
def __init__(self, r_cut, name=None): util.print_status_line() # tell the base class how we operate # initialize the base class pair.pair.__init__(self, r_cut, name) # update the neighbor list neighbor_list = pair._update_global_nlist(r_cut) neighbor_list.subscribe(lambda: self.log * self.get_max_rcut()) # create the c++ mirror class if not globals.exec_conf.isCUDAEnabled(): self.cpp_force = _custom_pair_potentials.PotentialPairLowe( globals.system_definition, neighbor_list.cpp_nlist, self.name) self.cpp_class = _custom_pair_potentials.PotentialPairLowe else: neighbor_list.cpp_nlist.setStorageMode( hoomd.NeighborList.storageMode.full) self.cpp_force = _custom_pair_potentials.PotentialPairLoweGPU( globals.system_definition, neighbor_list.cpp_nlist, self.name) self.cpp_class = _custom_pair_potentials.PotentialPairLoweGPU self.cpp_force.setBlockSize( tune._get_optimal_block_size('pair.dpd_conservative')) self.cpp_force.setBlockSize(64) globals.system.addCompute(self.cpp_force, self.force_name) # setup the coefficent options self.required_coeffs = ['A']
def __init__(self, group): util.print_status_line(); # initialize base class _compute.__init__(self); suffix = ''; if group.name != 'all': suffix = '_' + group.name; # warn user if an existing compute thermo already uses this group or name for t in globals.thermos: if t.group is group: globals.msg.warning("compute.thermo already specified for this group"); elif t.group.name == group.name: globals.msg.warning("compute.thermo already specified for a group with name " + str(group.name) + "\n"); # create the c++ mirror class if not globals.exec_conf.isCUDAEnabled(): self.cpp_compute = hoomd.ComputeThermo(globals.system_definition, group.cpp_group, suffix); else: self.cpp_compute = hoomd.ComputeThermoGPU(globals.system_definition, group.cpp_group, suffix); globals.system.addCompute(self.cpp_compute, self.compute_name); # save the group for later referencing self.group = group; # add ourselves to the list of compute thermos specified so far globals.thermos.append(self);
def __init__(self, r_cut=1.2, name=None): util.print_status_line(); self.r_cut = r_cut; # tell the base class how we operate # initialize the base class pair.pair.__init__(self, r_cut, name); # update the neighbor list neighbor_list = pair._update_global_nlist(r_cut); neighbor_list.subscribe(lambda: self.log*self.get_max_rcut()) # create the c++ mirror class if not globals.exec_conf.isCUDAEnabled(): self.cpp_force = _martini_plugin.PotentialPairCoulombM(globals.system_definition, neighbor_list.cpp_nlist, self.name); self.cpp_class = _martini_plugin.PotentialPairCoulombM; else: neighbor_list.cpp_nlist.setStorageMode(hoomd.NeighborList.storageMode.full); self.cpp_force = _martini_plugin.PotentialPairCoulombMGPU(globals.system_definition, neighbor_list.cpp_nlist, self.name); self.cpp_class = _martini_plugin.PotentialPairCoulombMGPU; self.cpp_force.setBlockSize(128); globals.system.addCompute(self.cpp_force, self.force_name); # setup the coefficent options self.required_coeffs = ['f', 'er', 'ron'];
def __init__(self, filename, groups, period, header_prefix='', r0_file=None, overwrite=False): util.print_status_line(); # Error out in MPI simulations # if (hoomd.is_MPI_available()): # if globals.system_definition.getParticleData().getDomainDecomposition(): # globals.msg.error("analyze.msd is not supported in multi-processor simulations.\n\n") # raise RuntimeError("Error creating analyzer.") # initialize base class _analyzer.__init__(self); # create the c++ mirror class self.cpp_analyzer = hoomd.MSDAnalyzer(globals.system_definition, filename, header_prefix, overwrite); self.setupAnalyzer(period); # it is an error to specify no groups if len(groups) == 0: globals.msg.error('At least one group must be specified to analyze.msd\n'); raise RuntimeError('Error creating analyzer'); # set the group columns for cur_group in groups: self.cpp_analyzer.addColumn(cur_group.cpp_group, cur_group.name); if r0_file is not None: self.cpp_analyzer.setR0(r0_file);
def enable(self): util.print_status_line(); util._disable_status_lines = True; force._force.enable(self); self.ewald.enable(); util._disable_status_lines = False;
def create_empty(N, box, n_particle_types=1, n_bond_types=0, n_angle_types=0, n_dihedral_types=0, n_improper_types=0): util.print_status_line(); # check if initialization has already occurred if is_initialized(): globals.msg.error("Cannot initialize more than once\n"); raise RuntimeError('Error initializing'); my_exec_conf = _create_exec_conf(); # create the empty system boxdim = hoomd.BoxDim(float(box[0]), float(box[1]), float(box[2])); globals.system_definition = hoomd.SystemDefinition(N, boxdim, n_particle_types, n_bond_types, n_angle_types, n_dihedral_types, n_improper_types, my_exec_conf); # initialize the system globals.system = hoomd.System(globals.system_definition, 0); _perform_common_init_tasks(); return data.system_data(globals.system_definition);
def __init__(self, filename="dump", period=None, time_step=None, phase=-1, restart=False, **params): util.print_status_line(); # initialize base class analyze._analyzer.__init__(self); # check restart options self.restart = restart; if restart and period is None: raise ValueError("a period must be specified with restart=True"); # create the c++ mirror class self.cpp_analyzer = hoomd.HOOMDDumpWriter(globals.system_definition, filename, restart); util._disable_status_lines = True; self.set_params(**params); util._disable_status_lines = False; if period is not None: self.setupAnalyzer(period, phase); self.enabled = True; self.prev_period = 1; elif filename != "dump": util._disable_status_lines = True; self.write(filename, time_step); util._disable_status_lines = False; else: self.enabled = False; # store metadata self.filename = filename self.period = period self.metadata_fields = ['filename','period']
def read_bin(filename): util.print_status_line(); # initialize GPU/CPU execution configuration and MPI early my_exec_conf = _create_exec_conf(); # check if initialization has already occurred if is_initialized(): globals.msg.error("Cannot initialize more than once\n"); raise RuntimeError('Error initializing'); # read in the data initializer = hoomd.HOOMDBinaryInitializer(my_exec_conf,filename); snapshot = initializer.getSnapshot() my_domain_decomposition = _create_domain_decomposition(snapshot.global_box); if my_domain_decomposition is not None: globals.system_definition = hoomd.SystemDefinition(snapshot, my_exec_conf, my_domain_decomposition); else: globals.system_definition = hoomd.SystemDefinition(snapshot, my_exec_conf); # initialize the system if time_step is None: globals.system = hoomd.System(globals.system_definition, initializer.getTimeStep()); else: globals.system = hoomd.System(globals.system_definition, time_step); _perform_common_init_tasks(); return data.system_data(globals.system_definition);
def __init__(self, filename, period, group=None, overwrite=False, unwrap_full=False, unwrap_rigid=False, angle_z=False, phase=-1): util.print_status_line(); # initialize base class analyze._analyzer.__init__(self); # create the c++ mirror class reported_period = period; try: reported_period = int(period); except TypeError: reported_period = 1; if group is None: util._disable_status_lines = True; group = hs_group.all(); util._disable_status_lines = False; self.cpp_analyzer = hoomd.DCDDumpWriter(globals.system_definition, filename, int(reported_period), group.cpp_group, overwrite); self.cpp_analyzer.setUnwrapFull(unwrap_full); self.cpp_analyzer.setUnwrapRigid(unwrap_rigid); self.cpp_analyzer.setAngleZ(angle_z); self.setupAnalyzer(period, phase); # store metadata self.filename = filename self.period = period self.group = group self.metadata_fields = ['filename','period','group']
def __init__(self, filename, chainlength, endtime, period=1, overwrite=False): util.print_status_line(); # initialize base class _analyzer.__init__(self); self.cpp_analyzer = _EndtoEndAutoCorrelation_plugin.EndtoEndAutoCorrelation(globals.system_definition, filename, chainlength, endtime, overwrite); self.setupAnalyzer(period)
def __init__(self, group1=None, group2=None, Ex=None, Ey=None, Ez=None, lD=None, bj=None, qt=1000.0, cut=None): util.print_status_line() # initialize the base class _force.__init__(self) # update the neighbor list #neighbor_list = pair._update_global_nlist(0.0) #neighbor_list.subscribe(lambda: self.log*0.0) # initialize the reflected c++ class if not globals.exec_conf.isCUDAEnabled(): self.cpp_force = _freedrain_force_plugin.FreeDrainForceCompute( globals.system_definition, group1.cpp_group, group2.cpp_group, Ex, Ey, Ez, lD, bj, qt, cut) else: self.cpp_force = _freedrain_force_plugin.FreeDrainForceComputeGPU( globals.system_definition, group1.cpp_group, group2.cpp_group, Ex, Ey, Ez, lD, bj, qt, cut) #self.cpp_force = _freedrain_force_plugin.FreeDrainForceCompute(globals.system_definition,neighbor_list.cpp_nlist,group1.cpp_group,group2.cpp_group,Ex,Ey,Ez,lD,bj,cut); globals.system.addCompute(self.cpp_force, self.force_name)
def __init__(self, filename, period=None, unwrap_rigid=False, phase=-1, addInfo=None): util.print_status_line(); # initialize base class analyze._analyzer.__init__(self); # create the c++ mirror class self.cpp_analyzer = hoomd.POSDumpWriter(globals.system_definition, filename); self.cpp_analyzer.setUnwrapRigid(unwrap_rigid); if addInfo is not None: self.cpp_analyzer.setAddInfo(addInfo); if period is not None: self.setupAnalyzer(period, phase); self.enabled = True; self.prev_period = 1; else: self.enabled = False; # store metadata self.filename = filename self.period = period self.unwrap_rigid = unwrap_rigid self.metadata_fields = ['filename', 'period', 'unwrap_rigid']
def __init__(self, filename, groups, period, header_prefix='', r0_file=None, overwrite=False): util.print_status_line() # initialize base class _analyzer.__init__(self) # create the c++ mirror class self.cpp_analyzer = hoomd.MSDAnalyzer(globals.system_definition, filename, header_prefix, overwrite) self.setupAnalyzer(period) # it is an error to specify no groups if len(groups) == 0: globals.msg.error( 'At least one group must be specified to analyze.msd\n') raise RuntimeError('Error creating analyzer') # set the group columns for cur_group in groups: self.cpp_analyzer.addColumn(cur_group.cpp_group, cur_group.name) if r0_file is not None: self.cpp_analyzer.setR0(r0_file)
def __init__(self, x=True, y=True, z=True, tolerance=1.02, maxiter=1, period=1000, phase=-1): util.print_status_line(); # initialize base class _updater.__init__(self); # balancing cannot be done without mpi if not hoomd.is_MPI_available(): globals.msg.warning("Ignoring balance command, not supported in current configuration.\n") return # create the c++ mirror class if not globals.exec_conf.isCUDAEnabled(): self.cpp_updater = hoomd.LoadBalancer(globals.system_definition, globals.decomposition.cpp_dd); else: self.cpp_updater = hoomd.LoadBalancerGPU(globals.system_definition, globals.decomposition.cpp_dd); self.setupUpdater(period,phase) # stash arguments to metadata self.metadata_fields = ['tolerance','maxiter','period','phase'] self.period = period self.phase = phase # configure the parameters util._disable_status_lines = True self.set_params(x,y,z,tolerance, maxiter) util._disable_status_lines = False
def __init__(self, group): util.print_status_line() # initialize base class _compute.__init__(self) suffix = '' if group.name != 'all': suffix = '_' + group.name # warn user if an existing compute thermo already uses this group or name for t in globals.thermos: if t.group is group: globals.msg.warning( "compute.thermo already specified for this group") elif t.group.name == group.name: globals.msg.warning( "compute.thermo already specified for a group with name " + str(group.name) + "\n") # create the c++ mirror class if not globals.exec_conf.isCUDAEnabled(): self.cpp_compute = hoomd.ComputeThermo(globals.system_definition, group.cpp_group, suffix) else: self.cpp_compute = hoomd.ComputeThermoGPU( globals.system_definition, group.cpp_group, suffix) globals.system.addCompute(self.cpp_compute, self.compute_name) # save the group for later referencing self.group = group # add ourselves to the list of compute thermos specified so far globals.thermos.append(self)
def tags(tag_min, tag_max=None, name=None): util.print_status_line() # check if initialization has occurred if not init.is_initialized(): globals.msg.error("Cannot create a group before initialization\n") raise RuntimeError('Error creating group') # handle the optional argument if tag_max is not None: if name is None: name = 'tags ' + str(tag_min) + '-' + str(tag_max) else: # if the option is not specified, tag_max is set equal to tag_min to include only that particle in the range # and the name is chosen accordingly tag_max = tag_min if name is None: name = 'tag ' + str(tag_min) # create the group selector = hoomd.ParticleSelectorTag(globals.system_definition, tag_min, tag_max) cpp_group = hoomd.ParticleGroup(globals.system_definition, selector) # notify the user of the created group globals.msg.notice( 2, 'Group "' + name + '" created containing ' + str(cpp_group.getNumMembersGlobal()) + ' particles\n') # return it in the wrapper class return group(name, cpp_group)
def write_restart(self): util.print_status_line() if not self.restart: raise ValueError("Cannot write_restart() when restart=False") self.cpp_analyzer.analyze(globals.system.getCurrentTimeStep())
def read_xml(filename, time_step=None, wrap_coordinates=False): util.print_status_line() # initialize GPU/CPU execution configuration and MPI early my_exec_conf = _create_exec_conf() # check if initialization has already occured if is_initialized(): globals.msg.error("Cannot initialize more than once\n") raise RuntimeError("Error creating random polymers") # read in the data initializer = hoomd.HOOMDInitializer(my_exec_conf, filename, wrap_coordinates) snapshot = initializer.getSnapshot() my_domain_decomposition = _create_domain_decomposition(snapshot.global_box) if my_domain_decomposition is not None: globals.system_definition = hoomd.SystemDefinition( snapshot, my_exec_conf, my_domain_decomposition) else: globals.system_definition = hoomd.SystemDefinition( snapshot, my_exec_conf) # initialize the system if time_step is None: globals.system = hoomd.System(globals.system_definition, initializer.getTimeStep()) else: globals.system = hoomd.System(globals.system_definition, time_step) _perform_common_init_tasks() return data.system_data(globals.system_definition)
def __init__(self, filename="dump", period=None, phase=-1): util.print_status_line() # Error out in MPI simulations if (hoomd.is_MPI_available()): if globals.system_definition.getParticleData( ).getDomainDecomposition(): globals.msg.error( "dump.pdb is not supported in multi-processor simulations.\n\n" ) raise RuntimeError("Error writing PDB file.") # initialize base class analyze._analyzer.__init__(self) # create the c++ mirror class self.cpp_analyzer = hoomd.PDBDumpWriter(globals.system_definition, filename) if period is not None: self.setupAnalyzer(period, phase) self.enabled = True self.prev_period = 1 elif filename != "dump": util._disable_status_lines = True self.write(filename) util._disable_status_lines = False else: self.enabled = False
def read_bin(filename, time_step=None): util.print_status_line() globals.msg.warning( "init.read_bin is deprecated and will be removed in the next release") # initialize GPU/CPU execution configuration and MPI early my_exec_conf = _create_exec_conf() # check if initialization has already occurred if is_initialized(): globals.msg.error("Cannot initialize more than once\n") raise RuntimeError('Error initializing') # read in the data initializer = hoomd.HOOMDBinaryInitializer(my_exec_conf, filename) snapshot = initializer.getSnapshot() my_domain_decomposition = _create_domain_decomposition(snapshot.global_box) if my_domain_decomposition is not None: globals.system_definition = hoomd.SystemDefinition( snapshot, my_exec_conf, my_domain_decomposition) else: globals.system_definition = hoomd.SystemDefinition( snapshot, my_exec_conf) # initialize the system if time_step is None: globals.system = hoomd.System(globals.system_definition, initializer.getTimeStep()) else: globals.system = hoomd.System(globals.system_definition, time_step) _perform_common_init_tasks() return data.system_data(globals.system_definition)
def all(): util.print_status_line(); # check if initialization has occurred if not init.is_initialized(): globals.msg.error("Cannot create a group before initialization\n"); raise RuntimeError('Error creating group'); # the all group is special: when the first one is created, it is cached in globals and future calls to group.all() # return the cached version if globals.group_all is not None: expected_N = globals.system_definition.getParticleData().getNGlobal(); if len(globals.group_all) != expected_N: globals.msg.error("globals.group_all does not appear to be the group of all particles!\n"); raise RuntimeError('Error creating group'); return globals.group_all; # choose the tag range tag_min = 0; tag_max = globals.system_definition.getParticleData().getNGlobal()-1; # create the group name = 'all'; selector = hoomd.ParticleSelectorTag(globals.system_definition, tag_min, tag_max); cpp_group = hoomd.ParticleGroup(globals.system_definition, selector); # notify the user of the created group globals.msg.notice(2, 'Group "' + name + '" created containing ' + str(cpp_group.getNumMembersGlobal()) + ' particles\n'); # cache it and then return it in the wrapper class globals.group_all = group(name, cpp_group); return globals.group_all;
def read_snapshot(snapshot): util.print_status_line() # initialize GPU/CPU execution configuration and MPI early my_exec_conf = _create_exec_conf() # check if initialization has already occured if is_initialized(): globals.msg.error("Cannot initialize more than once\n") raise RuntimeError("Error creating random polymers") my_domain_decomposition = _create_domain_decomposition(snapshot.global_box) if my_domain_decomposition is not None: globals.system_definition = hoomd.SystemDefinition( snapshot, my_exec_conf, my_domain_decomposition) else: globals.system_definition = hoomd.SystemDefinition( snapshot, my_exec_conf) # initialize the system globals.system = hoomd.System(globals.system_definition, 0) _perform_common_init_tasks() return data.system_data(globals.system_definition)
def type(type, name=None): util.print_status_line(); # check if initialization has occurred if not init.is_initialized(): globals.msg.error("Cannot create a group before initialization\n"); raise RuntimeError('Error creating group'); if name is None: name = 'type ' + type; # get a list of types from the particle data ntypes = globals.system_definition.getParticleData().getNTypes(); type_list = []; for i in range(0,ntypes): type_list.append(globals.system_definition.getParticleData().getNameByType(i)); if type not in type_list: globals.msg.warning(str(type) + " does not exist in the system, creating an empty group\n"); cpp_list = hoomd.std_vector_uint(); cpp_group = hoomd.ParticleGroup(globals.system_definition, cpp_list); else: type_id = globals.system_definition.getParticleData().getTypeByName(type); selector = hoomd.ParticleSelectorType(globals.system_definition, type_id, type_id); cpp_group = hoomd.ParticleGroup(globals.system_definition, selector); # notify the user of the created group globals.msg.notice(2, 'Group "' + name + '" created containing ' + str(cpp_group.getNumMembersGlobal()) + ' particles\n'); # return it in the wrapper class return group(name, cpp_group);
def set_params(self, T=None): util.print_status_line(); self.check_initialization(); if T is not None: T = variant._setup_variant_input(T); self.cpp_updater.setT(T.cpp_variant);
def set_params(self, add_hills=None, mode=None, stride=None, adaptive=None, sigma_g=None, multiple_walkers=None): util.print_status_line(); if add_hills is not None: self.cpp_integrator.setAddHills(add_hills) if mode is not None: if (mode == "standard"): cpp_mode = _metadynamics.IntegratorMetaDynamics.mode.standard elif (mode == "well_tempered"): cpp_mode = _metadynamics.IntegratorMetaDynamics.mode.well_tempered else: globals.msg.error("integrate.mode_metadynamics: Unsupported metadynamics mode.\n") raise RuntimeError('Error setting up Metadynamics.'); self.cpp_integrator.setMode(cpp_mode) if stride is not None: self.cpp_integrator.setStride(int(stride)) if adaptive is not None: self.cpp_integrator.setAdaptive(adaptive) if sigma_g is not None: self.cpp_integrator.setSigmaG(sigma_g) if multiple_walkers is not None: self.cpp_integrator.setMultipleWalkers(multiple_walkers)
def create_random(N, phi_p=None, name="A", min_dist=0.7, box=None, seed=1): util.print_status_line(); # initialize GPU/CPU execution configuration and MPI early my_exec_conf = _create_exec_conf(); # check if initialization has already occured if is_initialized(): globals.msg.error("Cannot initialize more than once\n"); raise RuntimeError("Error initializing"); # abuse the polymer generator to generate single particles if phi_p is not None: # calculate the box size L = math.pow(math.pi/6.0*N / phi_p, 1.0/3.0); box = data.boxdim(L=L); if box is None: raise RuntimeError('box or phi_p must be specified'); if not isinstance(box, data.boxdim): globals.msg.error('box must be a data.boxdim object'); raise TypeError('box must be a data.boxdim object'); # create the generator generator = hoomd.RandomGenerator(my_exec_conf, box._getBoxDim(), seed, box.dimensions); # build type list type_vector = hoomd.std_vector_string(); type_vector.append(name); # empty bond lists for single particles bond_ab = hoomd.std_vector_uint(); bond_type = hoomd.std_vector_string(); # create the generator generator.addGenerator(int(N), hoomd.PolymerParticleGenerator(my_exec_conf, 1.0, type_vector, bond_ab, bond_ab, bond_type, 100, box.dimensions)); # set the separation radius generator.setSeparationRadius(name, min_dist/2.0); # generate the particles generator.generate(); # initialize snapshot snapshot = generator.getSnapshot() my_domain_decomposition = _create_domain_decomposition(snapshot.global_box); if my_domain_decomposition is not None: globals.system_definition = hoomd.SystemDefinition(snapshot, my_exec_conf, my_domain_decomposition); else: globals.system_definition = hoomd.SystemDefinition(snapshot, my_exec_conf); # initialize the system globals.system = hoomd.System(globals.system_definition, 0); _perform_common_init_tasks(); return data.system_data(globals.system_definition);