コード例 #1
0
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);
コード例 #2
0
ファイル: init.py プロジェクト: TaherGhasimakbari/hoomd
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);
コード例 #3
0
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)
コード例 #4
0
def tag_list(name, tags):
    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');
    
    # build a vector of the tags
    cpp_list = hoomd.std_vector_uint();
    for t in tags:
        cpp_list.push_back(t);

    # create the group
    cpp_group = hoomd.ParticleGroup(globals.system_definition, cpp_list);

    # 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);
コード例 #5
0
def type(type, name=None, update=False):
    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,
                                        update)

    # 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)
コード例 #6
0
def tag_list(name, tags):
    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')

    # build a vector of the tags
    cpp_list = hoomd.std_vector_uint()
    for t in tags:
        cpp_list.push_back(t)

    # create the group
    cpp_group = hoomd.ParticleGroup(globals.system_definition, cpp_list)

    # 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)
コード例 #7
0
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)
コード例 #8
0
ファイル: init.py プロジェクト: harperic/hoomd-blue
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");
    
    # create the generator
    generator = hoomd.RandomGenerator(my_exec_conf,box, seed);
    
    # 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));
        
        
    # 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);
コード例 #9
0
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)