def set_param(self, type_name, types, positions, orientations=None, charges=None, diameters=None): R""" Set constituent particle types and coordinates for a rigid body. Args: type_name (str): The type of the central particle types (list): List of types of constituent particles positions (list): List of relative positions of constituent particles orientations (list): List of orientations of constituent particles (**optional**) charge (list): List of charges of constituent particles (**optional**) diameters (list): List of diameters of constituent particles (**optional**) .. caution:: The constituent particle type must be exist. If it does not exist, it can be created on the fly using ``system.particles.types.add('A_const')`` (see :py:mod:`hoomd.data`). Example:: rigid = constrain.rigd() rigid.set_param('A', types = ['A_const', 'A_const'], positions = [(0,0,1),(0,0,-1)]) rigid.set_param('B', types = ['B_const', 'B_const'], positions = [(0,0,.5),(0,0,-.5)]) """ # get a list of types from the particle data ntypes = hoomd.context.current.system_definition.getParticleData( ).getNTypes() type_list = [] for i in range(0, ntypes): type_list.append(hoomd.context.current.system_definition. getParticleData().getNameByType(i)) if type_name not in type_list: hoomd.context.msg.error('Type ' '{}' ' not found.\n'.format(type_name)) raise RuntimeError( 'Error setting up parameters for constrain.rigid()') type_id = type_list.index(type_name) if not isinstance(types, list): hoomd.context.msg.error('Expecting list of particle types.\n') raise RuntimeError( 'Error setting up parameters for constrain.rigid()') type_vec = _hoomd.std_vector_uint() for t in types: if t not in type_list: hoomd.context.msg.error('Type ' '{}' ' not found.\n'.format(t)) raise RuntimeError( 'Error setting up parameters for constrain.rigid()') constituent_type_id = type_list.index(t) type_vec.append(constituent_type_id) pos_vec = _hoomd.std_vector_scalar3() positions_list = list(positions) for p in positions_list: p = tuple(p) if len(p) != 3: hoomd.context.msg.error( 'Particle position is not a coordinate triple.\n') raise RuntimeError( 'Error setting up parameters for constrain.rigid()') pos_vec.append(_hoomd.make_scalar3(p[0], p[1], p[2])) orientation_vec = _hoomd.std_vector_scalar4() if orientations is not None: orientations_list = list(orientations) for o in orientations_list: o = tuple(o) if len(o) != 4: hoomd.context.msg.error( 'Particle orientation is not a 4-tuple.\n') raise RuntimeError( 'Error setting up parameters for constrain.rigid()') orientation_vec.append( _hoomd.make_scalar4(o[0], o[1], o[2], o[3])) else: for p in positions: orientation_vec.append(_hoomd.make_scalar4(1, 0, 0, 0)) charge_vec = _hoomd.std_vector_scalar() if charges is not None: charges_list = list(charges) for c in charges_list: charge_vec.append(float(c)) else: for p in positions: charge_vec.append(0.0) diameter_vec = _hoomd.std_vector_scalar() if diameters is not None: diameters_list = list(diameters) for d in diameters_list: diameter_vec.append(float(d)) else: for p in positions: diameter_vec.append(1.0) # set parameters in C++ force self.cpp_force.setParam(type_id, type_vec, pos_vec, orientation_vec, charge_vec, diameter_vec)
def set_param(self,type_name, types, positions, orientations=None, charges=None, diameters=None): R""" Set constituent particle types and coordinates for a rigid body. Args: type_name (str): The type of the central particle types (list): List of types of constituent particles positions (list): List of relative positions of constituent particles orientations (list): List of orientations of constituent particles (**optional**) charge (list): List of charges of constituent particles (**optional**) diameters (list): List of diameters of constituent particles (**optional**) .. caution:: The constituent particle type must be exist. If it does not exist, it can be created on the fly using ``system.particles.types.add('A_const')`` (see :py:mod:`hoomd.data`). Example:: rigid = constrain.rigd() rigid.set_param('A', types = ['A_const', 'A_const'], positions = [(0,0,1),(0,0,-1)]) rigid.set_param('B', types = ['B_const', 'B_const'], positions = [(0,0,.5),(0,0,-.5)]) """ # get a list of types from the particle data ntypes = hoomd.context.current.system_definition.getParticleData().getNTypes(); type_list = []; for i in range(0,ntypes): type_list.append(hoomd.context.current.system_definition.getParticleData().getNameByType(i)); if type_name not in type_list: hoomd.context.msg.error('Type ''{}'' not found.\n'.format(type_name)) raise RuntimeError('Error setting up parameters for constrain.rigid()') type_id = type_list.index(type_name) if not isinstance(types, list): hoomd.context.msg.error('Expecting list of particle types.\n') raise RuntimeError('Error setting up parameters for constrain.rigid()') type_vec = _hoomd.std_vector_uint() for t in types: if t not in type_list: hoomd.context.msg.error('Type ''{}'' not found.\n'.format(t)) raise RuntimeError('Error setting up parameters for constrain.rigid()') constituent_type_id = type_list.index(t) type_vec.append(constituent_type_id) pos_vec = _hoomd.std_vector_scalar3() positions_list = list(positions) for p in positions_list: p = tuple(p) if len(p) != 3: hoomd.context.msg.error('Particle position is not a coordinate triple.\n') raise RuntimeError('Error setting up parameters for constrain.rigid()') pos_vec.append(_hoomd.make_scalar3(p[0],p[1],p[2])) orientation_vec = _hoomd.std_vector_scalar4() if orientations is not None: orientations_list = list(orientations) for o in orientations_list: o = tuple(o) if len(o) != 4: hoomd.context.msg.error('Particle orientation is not a 4-tuple.\n') raise RuntimeError('Error setting up parameters for constrain.rigid()') orientation_vec.append(_hoomd.make_scalar4(o[0], o[1], o[2], o[3])) else: for p in positions: orientation_vec.append(_hoomd.make_scalar4(1,0,0,0)) charge_vec = _hoomd.std_vector_scalar() if charges is not None: charges_list = list(charges) for c in charges_list: charge_vec.append(float(c)) else: for p in positions: charge_vec.append(0.0) diameter_vec = _hoomd.std_vector_scalar() if diameters is not None: diameters_list = list(diameters) for d in diameters_list: diameter_vec.append(float(d)) else: for p in positions: diameter_vec.append(1.0) # set parameters in C++ force self.cpp_force.setParam(type_id, type_vec, pos_vec, orientation_vec, charge_vec, diameter_vec)