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 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 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 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])) my_domain_decomposition = _create_domain_decomposition(boxdim) if my_domain_decomposition is not None: 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, my_domain_decomposition) else: 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 create_empty(N, box, particle_types=['A'], bond_types=[], angle_types=[], dihedral_types=[], improper_types=[]): 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') globals.msg.warning( "init.create_empty() is deprecated. Use data.make_snapshot and init.read_snapshot instead\n" ) my_exec_conf = _create_exec_conf_deprecated() # create the empty system if not isinstance(box, hoomd_script.data.boxdim): globals.msg.error('box must be a data.boxdim object') raise TypeError('box must be a data.boxdim object') boxdim = box._getBoxDim() my_domain_decomposition = _create_domain_decomposition(boxdim) if my_domain_decomposition is not None: globals.system_definition = hoomd.SystemDefinition( N, boxdim, len(particle_types), len(bond_types), len(angle_types), len(dihedral_types), len(improper_types), my_exec_conf, my_domain_decomposition) else: globals.system_definition = hoomd.SystemDefinition( N, boxdim, len(particle_types), len(bond_types), len(angle_types), len(dihedral_types), len(improper_types), my_exec_conf) globals.system_definition.setNDimensions(box.dimensions) # transfer names to C++ for i, name in enumerate(particle_types): globals.system_definition.getParticleData().setTypeName(i, name) for i, name in enumerate(bond_types): globals.system_definition.getBondData().setTypeName(i, name) for i, name in enumerate(angle_types): globals.system_definition.getAngleData().setTypeName(i, name) for i, name in enumerate(dihedral_types): globals.system_definition.getDihedralData().setTypeName(i, name) for i, name in enumerate(improper_types): globals.system_definition.getImproperData().setTypeName(i, name) # 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 create_random(N, phi_p, name="A", min_dist=0.7): 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 # calculat the box size L = math.pow(math.pi / 6.0 * N / phi_p, 1.0 / 3.0) box = hoomd.BoxDim(L) # create the generator generator = hoomd.RandomGenerator(my_exec_conf, box, 12345) # 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)) # 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)
def create_random_polymers(box, polymers, separation, 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 creating random polymers") if type(polymers) != type([]) or len(polymers) == 0: globals.msg.error( "Polymers specified incorrectly. See the hoomd_script documentation\n" ) raise RuntimeError("Error creating random polymers") if type(separation) != type(dict()) or len(separation) == 0: globals.msg.error( "Polymers specified incorrectly. See the hoomd_script documentation\n" ) raise RuntimeError("Error creating random polymers") if not isinstance(box, data.boxdim): globals.msg.error('Box must be a data.boxdim object\n') raise TypeError('box must be a data.boxdim object') # create the generator generator = hoomd.RandomGenerator(my_exec_conf, box._getBoxDim(), seed, box.dimensions) # make a list of types used for an eventual check vs the types in separation for completeness types_used = [] # track the minimum bond length min_bond_len = None # build the polymer generators for poly in polymers: type_list = [] # check that all fields are specified if not 'bond_len' in poly: globals.msg.error('Polymer specification missing bond_len\n') raise RuntimeError("Error creating random polymers") if min_bond_len is None: min_bond_len = poly['bond_len'] else: min_bond_len = min(min_bond_len, poly['bond_len']) if not 'type' in poly: globals.msg.error('Polymer specification missing type\n') raise RuntimeError("Error creating random polymers") if not 'count' in poly: globals.msg.error('Polymer specification missing count\n') raise RuntimeError("Error creating random polymers") if not 'bond' in poly: globals.msg.error('Polymer specification missing bond\n') raise RuntimeError("Error creating random polymers") # build type list type_vector = hoomd.std_vector_string() for t in poly['type']: type_vector.append(t) if not t in types_used: types_used.append(t) # build bond list bond_a = hoomd.std_vector_uint() bond_b = hoomd.std_vector_uint() bond_name = hoomd.std_vector_string() # if the bond setting is 'linear' create a default set of bonds if poly['bond'] == 'linear': for i in range(0, len(poly['type']) - 1): bond_a.push_back(i) bond_b.push_back(i + 1) bond_name.append('polymer') #if it is a list, parse the user custom bonds elif type(poly['bond']) == type([]): for t in poly['bond']: # a 2-tuple gets the default 'polymer' name for the bond if len(t) == 2: a, b = t name = 'polymer' # and a 3-tuple specifies the name directly elif len(t) == 3: a, b, name = t else: globals.msg.error( 'Custom bond ' + str(t) + ' must have either two or three elements\n') raise RuntimeError("Error creating random polymers") bond_a.push_back(a) bond_b.push_back(b) bond_name.append(name) else: globals.msg.error('Unexpected argument value for polymer bond\n') raise RuntimeError("Error creating random polymers") # create the generator generator.addGenerator( int(poly['count']), hoomd.PolymerParticleGenerator(my_exec_conf, poly['bond_len'], type_vector, bond_a, bond_b, bond_name, 100, box.dimensions)) # check that all used types are in the separation list for t in types_used: if not t in separation: globals.msg.error("No separation radius specified for type " + str(t) + "\n") raise RuntimeError("Error creating random polymers") # set the separation radii, checking that it is within the minimum bond length for t, r in separation.items(): generator.setSeparationRadius(t, r) if 2 * r >= min_bond_len: globals.msg.error("Separation radius " + str(r) + " is too big for the minimum bond length of " + str(min_bond_len) + " specified\n") raise RuntimeError("Error creating random polymers") # generate the particles generator.generate() # copy over data to 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)
def create_random(N, phi_p=None, name="A", min_dist=0.7, box=None, seed=1, dimensions=3): 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") # check that dimensions are appropriate if dimensions not in (2, 3): raise ValueError('dimensions must be 2 or 3') # abuse the polymer generator to generate single particles if phi_p is not None: # calculate the box size L = math.pow(math.pi / (2.0 * dimensions) * N / phi_p, 1.0 / dimensions) box = hoomd_script.data.boxdim(L=L, dimensions=dimensions) if box is None: raise RuntimeError('box or phi_p must be specified') if not isinstance(box, hoomd_script.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 hoomd_script.data.system_data(globals.system_definition)