Example #1
0
    def __init__(self):
        # check if initialization has occurred
        if not init.is_initialized():
            globals.msg.error("Cannot create a variant before initialization\n");
            raise RuntimeError('Error creating variant');

        self.cpp_variant = None;
Example #2
0
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);
Example #3
0
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
Example #4
0
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;
Example #5
0
def r_buff(warmup=200000, r_min=0.05, r_max=1.0, jumps=20, steps=5000, set_max_check_period=False):
    # check if initialization has occurred
    if not init.is_initialized():
        globals.msg.error("Cannot tune r_buff before initialization\n");

    # check that there is a nlist
    if globals.neighbor_list is None:
        globals.msg.error("Cannot tune r_buff when there is no neighbor list\n");

    # start off at a check_period of 1
    globals.neighbor_list.set_params(check_period=1);

    # make the warmup run
    hoomd_script.run(warmup);

    # initialize scan variables
    dr = (r_max - r_min) / (jumps - 1);
    r_buff_list = [];
    tps_list = [];

    # loop over all desired r_buff points
    for i in range(0,jumps):
        # set the current r_buff
        r_buff = r_min + i * dr;
        globals.neighbor_list.set_params(r_buff=r_buff);

        # run the benchmark 3 times
        tps = [];
        hoomd_script.run(steps);
        tps.append(globals.system.getLastTPS())
        hoomd_script.run(steps);
        tps.append(globals.system.getLastTPS())
        hoomd_script.run(steps);
        tps.append(globals.system.getLastTPS())

        # record the median tps of the 3
        tps.sort();
        tps_list.append(tps[1]);
        r_buff_list.append(r_buff);

    # find the fastest r_buff
    fastest = tps_list.index(max(tps_list));
    fastest_r_buff = r_buff_list[fastest];

    # set the fastest and rerun the warmup steps to identify the max check period
    globals.neighbor_list.set_params(r_buff=fastest_r_buff);
    hoomd_script.run(warmup);

    # notify the user of the benchmark results
    globals.msg.notice(2, "r_buff = " + str(r_buff_list) + '\n');
    globals.msg.notice(2, "tps = " + str(tps_list) + '\n');
    globals.msg.notice(2, "Optimal r_buff: " + str(fastest_r_buff) + '\n');
    globals.msg.notice(2, "Maximum check_period: " + str(globals.neighbor_list.query_update_period()) + '\n');

    # set the found max check period
    if set_max_check_period:
        globals.neighbor_list.set_params(check_period=globals.neighbor_list.query_update_period());

    # return the results to the script
    return (fastest_r_buff, globals.neighbor_list.query_update_period());
Example #6
0
    def __init__(self, name=None):
        # check if initialization has occured
        if not init.is_initialized():
            globals.msg.error("Cannot create force before initialization\n");
            raise RuntimeError('Error creating force');

        # Allow force to store a name.  Used for discombobulation in the logger
        if name is None:
            self.name = "";
        else:
            self.name="_" + name;

        self.cpp_force = None;

        # increment the id counter
        id = _force.cur_id;
        _force.cur_id += 1;

        self.force_name = "force%d" % (id);
        self.enabled = True;
        self.log =True;
        globals.forces.append(self);

        # base class constructor
        meta._metadata.__init__(self)
Example #7
0
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)
Example #8
0
    def verify(self, required_coeffs):
        # first, check that the system has been initialized
        if not init.is_initialized():
            globals.msg.error("Cannot verify force coefficients before initialization\n");
            raise RuntimeError('Error verifying force coefficients');

        # 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));

        valid = True;
        # loop over all possible types and verify that all required variables are set
        for i in range(0,ntypes):
            type = type_list[i];

            if type not in self.values.keys() and len(required_coeffs):
                globals.msg.error("Particle type " + type + " is missing required coefficients\n");
                return False

            # verify that all required values are set by counting the matches
            count = 0;
            for coeff_name in self.values[type].keys():
                if not coeff_name in required_coeffs:
                    globals.msg.notice(3, "Possible typo? Force coeff " + str(coeff_name) + " is specified for type " + str(type) +\
                          ", but is not used by the external force");
                else:
                    count += 1;

            if count != len(required_coeffs):
                globals.msg.error("Particle type " + type + " is missing required coefficients\n");
                valid = False;

        return valid;
Example #9
0
def get_step():
    # check if initialization has occurred
    if not init.is_initialized():
        globals.msg.error("Cannot get step before initialization\n");
        raise RuntimeError('Error getting step');

    return globals.system.getCurrentTimeStep();
Example #10
0
    def verify(self, required_coeffs):
        # first, check that the system has been initialized
        if not init.is_initialized():
            globals.msg.error("Cannot verify force coefficients before initialization\n");
            raise RuntimeError('Error verifying force coefficients');

        # 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));

        valid = True;
        # loop over all possible types and verify that all required variables are set
        for i in range(0,ntypes):
            type = type_list[i];

            if type not in self.values.keys() and len(required_coeffs):
                globals.msg.error("Particle type " + type + " is missing required coefficients\n");
                return False

            # verify that all required values are set by counting the matches
            count = 0;
            for coeff_name in self.values[type].keys():
                if not coeff_name in required_coeffs:
                    globals.msg.notice(3, "Possible typo? Force coeff " + str(coeff_name) + " is specified for type " + str(type) +\
                          ", but is not used by the external force");
                else:
                    count += 1;

            if count != len(required_coeffs):
                globals.msg.error("Particle type " + type + " is missing required coefficients\n");
                valid = False;

        return valid;
Example #11
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);
Example #12
0
    def __init__(self, name=None):
        # check if initialization has occured
        if not init.is_initialized():
            globals.msg.error("Cannot create force before initialization\n")
            raise RuntimeError('Error creating force')

        # Allow force to store a name.  Used for discombobulation in the logger
        if name is None:
            self.name = ""
        else:
            self.name = "_" + name

        self.cpp_force = None

        # increment the id counter
        id = _force.cur_id
        _force.cur_id += 1

        self.force_name = "force%d" % (id)
        self.enabled = True
        self.log = True
        globals.forces.append(self)

        # base class constructor
        meta._metadata.__init__(self)
Example #13
0
def get_step():
    # check if initialization has occurred
    if not init.is_initialized():
        globals.msg.error("Cannot get step before initialization\n")
        raise RuntimeError('Error getting step')

    return globals.system.getCurrentTimeStep()
Example #14
0
def get_rank():
    if hoomd.is_MPI_available():
        if init.is_initialized():
            return globals.exec_conf.getRank()
        else:
            return hoomd.ExecutionConfiguration.guessRank(globals.msg)
    else:
        return 0
Example #15
0
def get_rank():
    if hoomd.is_MPI_available():
        if init.is_initialized():
            return globals.exec_conf.getRank()
        else:
            return hoomd.ExecutionConfiguration.guessRank(globals.msg)
    else:
        return 0;
Example #16
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 #17
0
def set_mode(mode):
    if init.is_initialized():
            globals.msg.error("Cannot change mode after initialization\n");
            raise RuntimeError('Error setting option');

    if mode is not None:
        if not (mode == "cpu" or mode == "gpu"):
            globals.msg.error("Invalid mode setting\n");
            raise RuntimeError('Error setting option');

    globals.options.mode = mode;
Example #18
0
def set_mode(mode):
    if init.is_initialized():
            globals.msg.error("Cannot change mode after initialization\n");
            raise RuntimeError('Error setting option');

    if mode is not None:
        if not (mode == "cpu" or mode == "gpu"):
            globals.msg.error("Invalid mode setting\n");
            raise RuntimeError('Error setting option');

    globals.options.mode = mode;
Example #19
0
def get_num_ranks():
    if hoomd.is_MPI_available():
        if init.is_initialized():
            return globals.exec_conf.getNRanks();
        else:
            if globals.options.nrank is not None:
                return globals.options.nrank;
            else:
                return hoomd.ExecutionConfiguration.getNRanksGlobal()
    else:
        return 1;
Example #20
0
def get_num_ranks():
    if hoomd.is_MPI_available():
        if init.is_initialized():
            return globals.exec_conf.getNRanks()
        else:
            if globals.options.nrank is not None:
                return globals.options.nrank
            else:
                return hoomd.ExecutionConfiguration.getNRanksGlobal()
    else:
        return 1
Example #21
0
def get_partition():
    if hoomd.is_MPI_available():
        if init.is_initialized():
            return globals.exec_conf.getPartition()
        else:
            if globals.options.nrank is not None:
                return int(hoomd.ExecutionConfiguration.guessRank(globals.msg)/globals.options.nrank)
            else:
                return 0
    else:
        return 0;
Example #22
0
def get_rank():
    if hoomd.is_MPI_available():
        if init.is_initialized():
            return globals.exec_conf.getRank()
        else:
            if globals.options.nrank is not None:
                # recompute local rank
                return int(hoomd.ExecutionConfiguration.getRankGlobal() % globals.options.nrank)
            else:
                return hoomd.ExecutionConfiguration.getRankGlobal()
    else:
        return 0;
Example #23
0
def get_partition():
    if hoomd.is_MPI_available():
        if init.is_initialized():
            return globals.exec_conf.getPartition()
        else:
            if globals.options.nrank is not None:
                # re-compute partition number
                return int(hoomd.ExecutionConfiguration.getRankGlobal()/globals.options.nrank)
            else:
                return 0
    else:
        return 0;
Example #24
0
def get_partition():
    if hoomd.is_MPI_available():
        if init.is_initialized():
            return globals.exec_conf.getPartition()
        else:
            if globals.options.nrank is not None:
                return int(
                    hoomd.ExecutionConfiguration.guessRank(globals.msg) /
                    globals.options.nrank)
            else:
                return 0
    else:
        return 0
Example #25
0
def get_partition():
    if hoomd.is_MPI_available():
        if init.is_initialized():
            return globals.exec_conf.getPartition()
        else:
            if globals.options.nrank is not None:
                # re-compute partition number
                return int(hoomd.ExecutionConfiguration.getRankGlobal() /
                           globals.options.nrank)
            else:
                return 0
    else:
        return 0
Example #26
0
def get_rank():
    if hoomd.is_MPI_available():
        if init.is_initialized():
            return globals.exec_conf.getRank()
        else:
            if globals.options.nrank is not None:
                # recompute local rank
                return int(hoomd.ExecutionConfiguration.getRankGlobal() %
                           globals.options.nrank)
            else:
                return hoomd.ExecutionConfiguration.getRankGlobal()
    else:
        return 0
Example #27
0
    def __init__(self):
        # check if initialization has occurred
        if not init.is_initialized():
            globals.msg.error("Cannot create updater before initialization\n");
            raise RuntimeError('Error creating updater');

        self.cpp_updater = None;

        # increment the id counter
        id = _updater.cur_id;
        _updater.cur_id += 1;

        self.updater_name = "updater%d" % (id);
        self.enabled = True;
Example #28
0
    def __init__(self):
        # check if initialization has occurred
        if not init.is_initialized():
            globals.msg.error("Cannot create analyzer before initialization\n")
            raise RuntimeError("Error creating analyzer")

        self.cpp_analyzer = None

        # increment the id counter
        id = _analyzer.cur_id
        _analyzer.cur_id += 1

        self.analyzer_name = "analyzer%d" % (id)
        self.enabled = True
Example #29
0
    def __init__(self):
        # check if initialization has occurred
        if not init.is_initialized():
            globals.msg.error("Cannot create analyzer before initialization\n")
            raise RuntimeError('Error creating analyzer')

        self.cpp_analyzer = None

        # increment the id counter
        id = _analyzer.cur_id
        _analyzer.cur_id += 1

        self.analyzer_name = "analyzer%d" % (id)
        self.enabled = True
Example #30
0
    def __init__(self):
        # check if initialization has occurred
        if not init.is_initialized():
            globals.msg.error("Cannot create compute before initialization\n");
            raise RuntimeError('Error creating compute');

        self.cpp_compute = None;

        # increment the id counter
        id = _compute.cur_id;
        _compute.cur_id += 1;

        self.compute_name = "compute%d" % (id);
        self.enabled = True;
Example #31
0
    def __init__(self):
        # check if initialization has occurred
        if not init.is_initialized():
            globals.msg.error("Cannot create compute before initialization\n")
            raise RuntimeError('Error creating compute')

        self.cpp_compute = None

        # increment the id counter
        id = _compute.cur_id
        _compute.cur_id += 1

        self.compute_name = "compute%d" % (id)
        self.enabled = True
Example #32
0
def cuboid(name,
           xmin=None,
           xmax=None,
           ymin=None,
           ymax=None,
           zmin=None,
           zmax=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 arguments
    box = globals.system_definition.getParticleData().getBox()
    if xmin is None:
        xmin = box.getLo().x - 0.5
    if xmax is None:
        xmax = box.getHi().x + 0.5
    if ymin is None:
        ymin = box.getLo().y - 0.5
    if ymax is None:
        ymax = box.getHi().y + 0.5
    if zmin is None:
        zmin = box.getLo().z - 0.5
    if zmax is None:
        zmax = box.getHi().z + 0.5

    ll = hoomd.Scalar3()
    ur = hoomd.Scalar3()
    ll.x = float(xmin)
    ll.y = float(ymin)
    ll.z = float(zmin)
    ur.x = float(xmax)
    ur.y = float(ymax)
    ur.z = float(zmax)

    # create the group
    selector = hoomd.ParticleSelectorCuboid(globals.system_definition, ll, ur)
    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)
Example #33
0
def series(warmup=100000, repeat=20, steps=10000, limit_hours=None):
    # check if initialization has occurred
    if not init.is_initialized():
        globals.msg.error("Cannot tune r_buff before initialization\n");

    tps_list = [];

    if warmup > 0:
        hoomd_script.run(warmup);

    for i in range(0,repeat):
        hoomd_script.run(steps, limit_hours=limit_hours);
        tps_list.append(globals.system.getLastTPS());

    return tps_list;
Example #34
0
def series(warmup=100000, repeat=20, steps=10000, limit_hours=None):
    # check if initialization has occurred
    if not init.is_initialized():
        globals.msg.error("Cannot tune r_buff before initialization\n");

    tps_list = [];

    if warmup > 0:
        hoomd_script.run(warmup);

    for i in range(0,repeat):
        hoomd_script.run(steps, limit_hours=limit_hours);
        tps_list.append(globals.system.getLastTPS());

    return tps_list;
Example #35
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 #36
0
    def __init__(self):
        # check if initialization has occured
        if not init.is_initialized():
            globals.msg.error("Cannot create neighbor list before initialization\n");
            raise RuntimeError('Error creating neighbor list');
        
        # default exclusions
        self.is_exclusion_overridden = False;
        self.exclusions = None

        # save the parameters we set
        self.r_cut = rcut();
        self.r_buff = 0.0;

        # save a list of subscribers that may have a say in determining the maximum r_cut
        self.subscriber_callbacks = [];
Example #37
0
def set_ncpu(ncpu):
    if init.is_initialized():
            globals.msg.error("Cannot change number of threads after initialization\n");
            raise RuntimeError('Error setting option');
    
    if ncpu is not None:
        try:
            ncpu = int(ncpu);
        except ValueError:
            globals.msg.error("ncpu must be an integer\n");
            raise RuntimeError('Error setting option');
        
        # imply mode=cpu
        globals.options.mode = "cpu";
        
    globals.options.ncpu = ncpu;
Example #38
0
def set_gpu(gpu):
    if init.is_initialized():
            globals.msg.error("Cannot change gpu after initialization\n");
            raise RuntimeError('Error setting option');

    if gpu is not None:
        try:
            gpu = int(gpu);
        except ValueError:
            globals.msg.error("gpu must be an integer\n");
            raise RuntimeError('Error setting option');

        # imply mode=gpu
        globals.options.mode = "gpu";

    globals.options.gpu = gpu;
Example #39
0
def set_ncpu(ncpu):
    if init.is_initialized():
            globals.msg.error("Cannot change number of threads after initialization\n");
            raise RuntimeError('Error setting option');

    if ncpu is not None:
        try:
            ncpu = int(ncpu);
        except ValueError:
            globals.msg.error("ncpu must be an integer\n");
            raise RuntimeError('Error setting option');

        # imply mode=cpu
        globals.options.mode = "cpu";

    globals.options.ncpu = ncpu;
Example #40
0
def set_gpu(gpu):
    if init.is_initialized():
            globals.msg.error("Cannot change gpu after initialization\n");
            raise RuntimeError('Error setting option');

    if gpu is not None:
        try:
            gpu = int(gpu);
        except ValueError:
            globals.msg.error("gpu must be an integer\n");
            raise RuntimeError('Error setting option');

        # imply mode=gpu
        globals.options.mode = "gpu";

    globals.options.gpu = gpu;
Example #41
0
def rigid():
    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');

    # create the group
    name = 'rigid';
    selector = hoomd.ParticleSelectorRigid(globals.system_definition, True);
    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);
Example #42
0
def series(warmup=100000, repeat=20, steps=10000):
    # check if initialization has occurred
    if not init.is_initialized():
        globals.msg.error("Cannot tune r_buff before initialization\n");

    tps_list = [];

    hoomd_script.run(warmup);
    for i in range(0,repeat):
        hoomd_script.run(steps);
        tps_list.append(globals.system.getLastTPS());

    if numpy is not None:
        globals.msg.notice(1, "**Notice: Series average TPS: %4.2f\n" % numpy.average(tps_list));
        globals.msg.notice(1, "          Series median TPS : %4.2f\n" % numpy.median(tps_list));
        globals.msg.notice(1, "          Series TPS std dev: %4.2f" % numpy.std(tps_list));

    return tps_list;
Example #43
0
    def __init__(self):
        # check if initialization has occured
        if not init.is_initialized():
            globals.msg.error("Cannot create force before initialization\n")
            raise RuntimeError('Error creating constraint force')

        self.cpp_force = None

        # increment the id counter
        id = _constraint_force.cur_id
        _constraint_force.cur_id += 1

        self.force_name = "constraint_force%d" % (id)
        self.enabled = True
        globals.constraint_forces.append(self)

        # create force data iterator
        self.forces = data.force_data(self)
    def __init__(self):
        # check if initialization has occured
        if not init.is_initialized():
            globals.msg.error("Cannot create force before initialization\n");
            raise RuntimeError('Error creating constraint force');
        
        self.cpp_force = None;

        # increment the id counter
        id = _constraint_force.cur_id;
        _constraint_force.cur_id += 1;
        
        self.force_name = "constraint_force%d" % (id);
        self.enabled = True;
        globals.constraint_forces.append(self);
        
        # create force data iterator
        self.forces = data.force_data(self);
Example #45
0
    def verify(self, required_coeffs):
        # first, check that the system has been initialized
        if not init.is_initialized():
            globals.msg.error("Cannot verify bond coefficients before initialization\n")
            raise RuntimeError("Error verifying force coefficients")

        # get a list of types from the particle data
        ntypes = globals.system_definition.getBondData().getNTypes()
        type_list = []
        for i in range(0, ntypes):
            type_list.append(globals.system_definition.getBondData().getNameByType(i))

        valid = True
        # loop over all possible types and verify that all required variables are set
        for i in range(0, ntypes):
            type = type_list[i]

            if type not in self.values.keys():
                globals.msg.error("Bond type " + str(type) + " not found in bond coeff\n")
                valid = False
                continue

            # verify that all required values are set by counting the matches
            count = 0
            for coeff_name in self.values[type].keys():
                if not coeff_name in required_coeffs:
                    globals.msg.notice(
                        2,
                        "Notice: Possible typo? Force coeff "
                        + str(coeff_name)
                        + " is specified for type "
                        + str(type)
                        + ", but is not used by the bond force\n",
                    )
                else:
                    count += 1

            if count != len(required_coeffs):
                globals.msg.error("Bond type " + str(type) + " is missing required coefficients\n")
                valid = False

        return valid
Example #46
0
    def __init__(self):
        # check if initialization has occurred
        if not init.is_initialized():
            globals.msg.error("Cannot create updater before initialization\n");
            raise RuntimeError('Error creating updater');

        self.cpp_updater = None;

        # increment the id counter
        id = _updater.cur_id;
        _updater.cur_id += 1;

        self.updater_name = "updater%d" % (id);
        self.enabled = True;

        # Store a reference in global simulation variables
        globals.updaters.append(self)

        # base class constructor
        meta._metadata.__init__(self)
Example #47
0
def rigid():
    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')

    # create the group
    name = 'rigid'
    selector = hoomd.ParticleSelectorRigid(globals.system_definition, True)
    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)
Example #48
0
    def __init__(self):
        # check if initialization has occurred
        if not init.is_initialized():
            globals.msg.error("Cannot create analyzer before initialization\n");
            raise RuntimeError('Error creating analyzer');

        self.cpp_analyzer = None;

        # increment the id counter
        id = _analyzer.cur_id;
        _analyzer.cur_id += 1;

        self.analyzer_name = "analyzer%d" % (id);
        self.enabled = True;

        # Store a reference in global simulation variables
        globals.analyzers.append(self)

        # base class constructor
        meta._metadata.__init__(self)
Example #49
0
    def fill(self):
        # first, check that the system has been initialized
        if not init.is_initialized():
            globals.msg.error("Cannot fill rcut(i,j) before initialization\n");
            raise RuntimeError('Error filling nlist rcut(i,j)');

        # 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));

        # loop over all possible pairs and require that a dictionary key exists for them
        for i in range(0,ntypes):
            for j in range(i,ntypes):
                a = type_list[i];
                b = type_list[j];
                    
                # ensure the pair
                cur_pair = self.ensure_pair(a,b);
Example #50
0
def cuboid(name, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=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 arguments
    box = globals.system_definition.getParticleData().getBox();
    if xmin is None:
        xmin = box.getLo().x - 0.5;
    if xmax is None:
        xmax = box.getHi().x + 0.5;
    if ymin is None:
        ymin = box.getLo().y - 0.5;
    if ymax is None:
        ymax = box.getHi().y + 0.5;
    if zmin is None:
        zmin = box.getLo().z - 0.5;
    if zmax is None:
        zmax = box.getHi().z + 0.5;
    
    ll = hoomd.Scalar3();
    ur = hoomd.Scalar3();
    ll.x = float(xmin);
    ll.y = float(ymin);
    ll.z = float(zmin);
    ur.x = float(xmax);
    ur.y = float(ymax);
    ur.z = float(zmax);
    
    # create the group
    selector = hoomd.ParticleSelectorCuboid(globals.system_definition, ll, ur);
    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);
Example #51
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);
Example #52
0
    def verify(self, required_coeffs):
        # first, check that the system has been initialized
        if not init.is_initialized():
            globals.msg.error(
                "Cannot verify angle coefficients before initialization\n")
            raise RuntimeError('Error verifying force coefficients')

        # get a list of types from the particle data
        ntypes = globals.system_definition.getAngleData().getNTypes()
        type_list = []
        for i in range(0, ntypes):
            type_list.append(
                globals.system_definition.getAngleData().getNameByType(i))

        valid = True
        # loop over all possible types and verify that all required variables are set
        for i in range(0, ntypes):
            type = type_list[i]

            if type not in self.values.keys():
                globals.msg.error("Angle type " + str(type) +
                                  " not found in angle coeff\n")
                valid = False
                continue

            # verify that all required values are set by counting the matches
            count = 0
            for coeff_name in self.values[type].keys():
                if not coeff_name in required_coeffs:
                    globals.msg.notice(2, "Notice: Possible typo? Force coeff " + str(coeff_name) + " is specified for type " + str(type) + \
                          ", but is not used by the angle force\n")
                else:
                    count += 1

            if count != len(required_coeffs):
                globals.msg.error("Angle type " + str(type) +
                                  " is missing required coefficients\n")
                valid = False

        return valid
Example #53
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)
Example #54
0
def charged(name='charged'):
    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')

    util._disable_status_lines = True

    # determine the group of particles that are charged
    charged_tags = []
    sysdef = globals.system_definition
    pdata = data.particle_data(sysdef.getParticleData())
    for i in range(0, len(pdata)):
        if pdata[i].charge != 0.0:
            charged_tags.append(i)

    retval = tag_list(name, charged_tags)
    util._disable_status_lines = False

    return retval
Example #55
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)
Example #56
0
def series(warmup=100000, repeat=20, steps=10000):
    # check if initialization has occurred
    if not init.is_initialized():
        globals.msg.error("Cannot tune r_buff before initialization\n")

    tps_list = []

    hoomd_script.run(warmup)
    for i in range(0, repeat):
        hoomd_script.run(steps)
        tps_list.append(globals.system.getLastTPS())

    if numpy is not None:
        globals.msg.notice(
            1,
            "**Notice: Series average TPS: %4.2f\n" % numpy.average(tps_list))
        globals.msg.notice(
            1,
            "          Series median TPS : %4.2f\n" % numpy.median(tps_list))
        globals.msg.notice(
            1, "          Series TPS std dev: %4.2f" % numpy.std(tps_list))

    return tps_list
Example #57
0
def run_upto(step, **keywords):
    if 'quiet' in keywords and not keywords['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')

    # determine the number of steps to run
    step = int(step)
    cur_step = globals.system.getCurrentTimeStep()

    if cur_step >= step:
        globals.msg.warning(
            "Requesting run up to a time step that has already passed, doing nothing\n"
        )
        return

    n_steps = step - cur_step

    _util._disable_status_lines = True
    run(n_steps, **keywords)
    _util._disable_status_lines = False