Example #1
0
def run(tsteps,
        profile=False,
        limit_hours=None,
        limit_multiple=1,
        callback_period=0,
        callback=None,
        quiet=False):
    if not quiet:
        _util.print_status_line()
    # check if initialization has occured
    if not init.is_initialized():
        globals.msg.error("Cannot run before initialization\n")
        raise RuntimeError('Error running')

    if globals.integrator is None:
        globals.msg.warning("Starting a run without an integrator set")
    else:
        globals.integrator.update_forces()
        globals.integrator.update_methods()
        globals.integrator.update_thermos()

    # update autotuner parameters
    globals.system.setAutotunerParams(globals.options.autotuner_enable,
                                      int(globals.options.autotuner_period))

    # if rigid bodies, setxv
    if len(data.system_data(globals.system_definition).bodies) > 0:
        data.system_data(globals.system_definition).bodies.updateRV()

    for logger in globals.loggers:
        logger.update_quantities()
    globals.system.enableProfiler(profile)
    globals.system.enableQuietRun(quiet)

    if globals.neighbor_list:
        globals.neighbor_list.update_rcut()
        globals.neighbor_list.update_exclusions_defaults()

    # update all user-defined neighbor lists
    for nl in globals.neighbor_lists:
        nl.update_rcut()
        nl.update_exclusions_defaults()

    # detect 0 hours remaining properly
    if limit_hours == 0.0:
        globals.msg.warning(
            "Requesting a run() with a 0 time limit, doing nothing.\n")
        return
    if limit_hours is None:
        limit_hours = 0.0

    if not quiet:
        globals.msg.notice(1, "** starting run **\n")
    globals.system.run(int(tsteps), callback_period, callback, limit_hours,
                       int(limit_multiple))
    if not quiet:
        globals.msg.notice(1, "** run complete **\n")
Example #2
0
def run(tsteps, profile=False, limit_hours=None, limit_multiple=1, callback_period=0, callback=None, quiet=False):
    if not quiet:
        _util.print_status_line();
    # check if initialization has occured
    if not init.is_initialized():
        globals.msg.error("Cannot run before initialization\n");
        raise RuntimeError('Error running');

    if globals.integrator is None:
        globals.msg.warning("Starting a run without an integrator set");
    else:
        globals.integrator.update_forces();
        globals.integrator.update_methods();
        globals.integrator.update_thermos();

    # update autotuner parameters
    globals.system.setAutotunerParams(globals.options.autotuner_enable, int(globals.options.autotuner_period));

    # if rigid bodies, setxv
    if len(data.system_data(globals.system_definition).bodies) > 0:
        data.system_data(globals.system_definition).bodies.updateRV()

    for logger in globals.loggers:
        logger.update_quantities();
    globals.system.enableProfiler(profile);
    globals.system.enableQuietRun(quiet);

    if globals.neighbor_list:
        globals.neighbor_list.update_rcut();
        globals.neighbor_list.update_exclusions_defaults();
    
    # update all user-defined neighbor lists
    for nl in globals.neighbor_lists:
        nl.update_rcut()
        nl.update_exclusions_defaults()

    # detect 0 hours remaining properly
    if limit_hours == 0.0:
        globals.msg.warning("Requesting a run() with a 0 time limit, doing nothing.\n");
        return;
    if limit_hours is None:
        limit_hours = 0.0

    if not quiet:
        globals.msg.notice(1, "** starting run **\n");
    globals.system.run(int(tsteps), callback_period, callback, limit_hours, int(limit_multiple));
    if not quiet:
        globals.msg.notice(1, "** run complete **\n");
Example #3
0
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)
Example #4
0
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 recursivelyMark(self,nodeID, nodes, local_bonds=None, local_id=None, bond_type=None, local_types=None):
        system = data.system_data(globals.system_definition)
        (connections, visited) = nodes[nodeID]
        if visited:
            return

        connectedNodeID = local_id

        if local_id is None:
            local_id = -1

        local_id += 1

        if not local_types:
            local_types = []

        if not local_bonds:
            local_bonds = []

        if connectedNodeID is not None:
            local_bonds.append((connectedNodeID,local_id,bond_type))
        
        # mark as visited 
        nodes[nodeID][1] = True
         
        local_types.append(system.particles[nodeID].type)
        
        for (next_connectedNodeID,next_bond_type) in connections:
            ret = self.recursivelyMark(next_connectedNodeID, nodes, local_bonds, local_id, next_bond_type, local_types)
            if ret is not None:
                ((local_bonds,local_types),local_id) = ret
        
        return ((local_bonds,local_types),local_id)
Example #6
0
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)
Example #7
0
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 find_distinct_species(self):
        # nodes correspond to particles
        # bonds are connections between nodes
        nodes = []; 

        system = data.system_data(globals.system_definition)
        nparticles = len(system.particles)
        for p in range(0,nparticles):
            nodes.append([[], False])
        
        for bond in system.bonds:
            btype =  globals.system_definition.getBondData().getTypeByName(bond.type)
            nodes[bond.a][0].append((bond.b, btype));
            nodes[bond.b][0].append((bond.a, btype));

        # find distinct connected components
        species = {};
       
        for (nodeID, (connections, visited)) in enumerate(nodes):
            if visited == False:
                (this_species, natoms) = self.recursivelyMark(nodeID, nodes)
                this_species = tuple([tuple(sublist) for sublist in this_species])
                if this_species not in species.keys():
                    species[this_species]=[1, natoms+1]
                else:
                    species[this_species][0]+=1;

        return species; 
Example #9
0
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)
Example #10
0
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)
Example #11
0
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);
Example #12
0
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);
Example #13
0
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);
Example #14
0
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');

    my_exec_conf = _create_exec_conf();

    # create the empty system
    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');

    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 data.system_data(globals.system_definition);
Example #15
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)
Example #16
0
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')

    my_exec_conf = _create_exec_conf()

    # create the empty system
    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')

    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 data.system_data(globals.system_definition)
Example #17
0
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, time_step);
    
    _perform_common_init_tasks();
    return data.system_data(globals.system_definition);
    def generate_parameters(self):
        system = data.system_data(globals.system_definition)
        parameters = "MdSimulation{\n"
        parameters += " FileMaster{\n"
        parameters += "  commandFileName paramfile\n"
        parameters += "  inputPrefix ./\n"
        parameters += "  outputPrefix " + str(self.out_dir) + "/\n"
        parameters += " }\n"
        parameters += " nAtomType "+ str(len(system.particles.types)) + "\n"
        parameters += " nBondType "+ str(system.bonds.bdata.getNTypes()) + "\n"
        parameters += " atomTypes "
        for cur_type in system.particles.types: 
            parameters += " " +  cur_type + " 1.0"; # mass 1.0
        parameters += "\n"
        parameters += " maskedPairPolicy"
        if (globals.neighbor_list.cpp_nlist.getNumExclusions(2) > 0):
            parameters += " MaskBonded\n"
        else:
            parameters += " MaskNone\n"

        parameters += " SpeciesManager{\n"
        for cur_species in self.species.keys():
            parameters += "  Species{\n"
            parameters += "  moleculeCapacity " + str(self.species[cur_species][0]) + "\n"
            parameters += "  nAtom " + str(self.species[cur_species][1]) + "\n"
            parameters += "  nBond " + str(len(cur_species[0])) + "\n"
            parameters += "  atomTypeIds\n"
            for cur_type in cur_species[1]:
                parameters += str(system.particles.types.index(cur_type)) + "\n"
            parameters += "  speciesBonds\n"
            
            for cur_bond in cur_species[0]:
                parameters += str(cur_bond[0]) + " " + str(cur_bond[1]) + " " + str(cur_bond[2]) + "\n"
            parameters += "  }\n"
        parameters += " }\n"
        parameters += " Random{\n"
        parameters += "   seed 0\n"
        parameters += " }\n"
        parameters += " MdSystem{\n"

        # count pair forces
        num_pair_force = 0;   
        for force in globals.forces:
            if force.enabled and isinstance(force, pair.pair):
                num_pair_force+=1
                pair_force = force;       

        if num_pair_force == 0 or num_pair_force > 1:
            print >> sys.stderr, "\n***Error! Only one pair force is supported in Simpatico";
            raise RuntimeError('Error creating Simpatico parameter file');

        parameters += "  pairStyle"
        if (isinstance(pair_force, pair.lj)):
            parameters += " LJPair\n"
            pair_parameters = "   epsilon"
            for typei in system.particles.types:
                for typej in system.particles.types:
                    pair_parameters += " " + str(pair_force.pair_coeff.get(typei,typej,'epsilon'))
            pair_parameters += "\n"
            pair_parameters += "   sigma"
            for typei in system.particles.types:
                for typej in system.particles.types:
                    pair_parameters += " " + str(pair_force.pair_coeff.get(typei,typej,'sigma'))
            pair_parameters += "\n"
            pair_parameters += "   cutoff"
            for typei in system.particles.types:
                for typej in system.particles.types:
                    pair_parameters += " " + str(pair_force.pair_coeff.get(typei,typej,'r_cut'))
            pair_parameters += "\n"
        elif (isinstance(pair_force, pair.dpd_conservative)):
            parameters += " DpdPair\n"
            pair_parameters = "   epsilon"
            for typei in system.particles.types:
                for typej in system.particles.types:
                    pair_parameters += " " + str(pair_force.pair_coeff.get(typei,typej,'A'))
            pair_parameters += "\n"
            pair_parameters += "   sigma"
            for typei in system.particles.types:
                for typej in system.particles.types:
                    pair_parameters += " " + str(pair_force.pair_coeff.get(typei,typej,'r_cut'))
            pair_parameters += "\n"
        else:
            parameters += " LJPair\n"
            pair_parameters = "   epsilon"
            for typei in system.particles.types:
                for typej in system.particles.types:
                    pair_parameters += " 1.0"
            pair_parameters += "\n"
            pair_parameters += "   sigma"
            for typei in system.particles.types:
                for typej in system.particles.types:
                    pair_parameters += " 1.0"
            pair_parameters += "\n"
            pair_parameters += "   cutoff"
            for typei in system.particles.types:
                for typej in system.particles.types:
                    pair_parameters += " 1.0"
            pair_parameters += "\n"
 
            globals.msg.warning("Unsupported pair potential. Substituting default values.\n")

        # map bond potential
        parameters += "  bondStyle"
        bond_force = None;
        for force in globals.forces:
            if isinstance(force,bond.harmonic) or isinstance(force,bond.fene):
                if bond_force is not None:
                    print >> sys.stderr, "\n***Error! Only one bond force is supported";
                    raise RuntimeError('Error creating Simpatico parameter file');
                bond_force = force

        nbondtypes = globals.system_definition.getBondData().getNTypes();
        bond_type_list = [];
        for i in range(0,nbondtypes):
            bond_type_list.append(globals.system_definition.getBondData().getNameByType(i));

        if isinstance(bond_force,bond.harmonic):
            parameters += " HarmonicBond\n"
            bond_parameters = "   kappa"
            for type in bond_type_list:
                bond_parameters += " " + str(bond_force.bond_coeff.get(type,'k'))
            bond_parameters += "\n"
            bond_parameters += "   length"
            for type in bond_type_list:
                bond_parameters += " " + str(bond_force.bond_coeff.get(type,'r0'))
            bond_parameters += "\n"
        else:
            print >> sys.stderr, "\n***Error! Unsupported bond potential";
            raise RuntimeError('Error creating Simpatico parameter file');

        parameters += "  MdPairPotential{\n"
        parameters += pair_parameters
        # leave some room for fluctuations
        parameters += "   maxBoundary orthorhombic " + str(2.0*system.box.Lx) + " " + str(2.0*system.box.Ly) + " " + str(2.0*system.box.Lz) + "\n"
        parameters += "  PairList{\n"
        parameters += "    atomCapacity " + str(len(system.particles)) + "\n"
        # adjust neighbors_per_atom if necessary
        neighbors_per_atom = 50
        parameters += "    pairCapacity " + str(len(system.particles)*neighbors_per_atom) + "\n"
        parameters += "    skin  .001\n " # any value > 0 
        parameters += "   }\n"
        parameters += "  }\n"
        parameters += "  BondPotential{\n"
        parameters += bond_parameters
        parameters += "  }\n"

        parameters += "  EnergyEnsemble{\n"
        parameters += "   type isothermal\n" # for post-processing we can choose any energy ensemble
        parameters += "   temperature 1.0\n"
        parameters += "  }\n"
        parameters += "  BoundaryEnsemble{\n"
        parameters += "   type rigid\n" # choose default boundary ensemble
        parameters += "  }\n"
        parameters += "  NvtNhIntegrator{\n"
        parameters += "   dt 0.001\n" # standard values
        parameters += "   tauT 1.0\n" 
        parameters += "  }\n"
        parameters += " }\n"

        # append definition of diagnostic manager
        parameters += " AnalyzerManager{\n"
        parameters += "  baseInterval 1\n"
        if self.diagnostic_params is not None:
             parameters += self.diagnostic_params
        parameters += " }\n"
        parameters += " saveInterval 0\n"
        parameters += "}\n"

        return parameters
Example #19
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)
Example #20
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");
    
    # 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);