def __init__(self, filter, flow_target, slab_direction, flow_direction, n_slabs, max_slab=-1, min_slab=-1): params = ParameterDict( filter=hoomd.filter.ParticleFilter, flow_target=hoomd.variant.Variant, slab_direction=OnlyTypes(str, strict=True, postprocess=self._to_lowercase), flow_direction=OnlyTypes(str, strict=True, postprocess=self._to_lowercase), n_slabs=OnlyTypes(int, preprocess=self._preprocess_n_slabs), max_slab=OnlyTypes(int, preprocess=self._preprocess_max_slab), min_slab=OnlyTypes(int, preprocess=self._preprocess_min_slab), flow_epsilon=float(1e-2)) params.update( dict(filter=filter, flow_target=flow_target, slab_direction=slab_direction, flow_direction=flow_direction, n_slabs=n_slabs)) self._param_dict.update(params) self._param_dict.update(dict(max_slab=max_slab)) self._param_dict.update(dict(min_slab=min_slab)) # This updater has to be applied every timestep super().__init__(hoomd.trigger.Periodic(1))
def __init__(self, target, solver, max_chain_time=None): # A flag for knowing when to update the maximum move sizes self._update_chain_time = False # A counter when tuned reaches 1 it means that the tuner has reported # being tuned one time in a row. However, as the first run of the tuner # is likely at timestep 0 which means that the counters are (0, 0) and # _ChainTimeTuneDefinition returns y == target for that case, we need # two rounds of tuning to be sure that we have converged. Since, in # general, solvers do not do much if any work on already tuned tunables, # this is not a performance problem. self._tuned = 0 self._is_attached = False self._chain_time_def = _ChainTimeTuneDefinition( target, (self._min_chain_time, max_chain_time)) param_dict = ParameterDict( target=OnlyTypes(float, postprocess=self._process_chain_time_target), solver=SolverStep, max_chain_time=OnlyTypes( float, allow_none=True, postprocess=self._process_chain_time_range), min_chain_time=OnlyTypes( float, postprocess=self._process_chain_time_range)) self._param_dict.update(param_dict) self.target = target self.solver = solver self.max_chain_time = max_chain_time self.min_chain_time = self._min_chain_time
def __init__(self): self._compute = list() self._scheduled = False self._updaters = SyncedList(OnlyTypes(Updater), _triggered_op_conversion) self._writers = SyncedList(OnlyTypes(Writer), _triggered_op_conversion) self._tuners = SyncedList(OnlyTypes(Tuner), lambda x: x._cpp_obj) self._computes = SyncedList(OnlyTypes(Compute), lambda x: x._cpp_obj) self._integrator = None self._tuners.append(ParticleSorter())
def __init__(self, filter, limit=None): # store metadata param_dict = ParameterDict( filter=ParticleFilter, limit=OnlyTypes(float, allow_none=True), zero_force=OnlyTypes(bool, allow_none=False), ) param_dict.update(dict(filter=filter, limit=limit, zero_force=False)) # set defaults self._param_dict.update(param_dict)
def __init__(self, dt, force_tol, angmom_tol, energy_tol, integrate_rotational_dof=False, forces=None, constraints=None, methods=None, rigid=None, min_steps_adapt=5, finc_dt=1.1, fdec_dt=0.5, alpha_start=0.1, fdec_alpha=0.99, min_steps_conv=10): super().__init__(forces, constraints, methods, rigid) pdict = ParameterDict( dt=float(dt), integrate_rotational_dof=bool(integrate_rotational_dof), min_steps_adapt=OnlyTypes(int, preprocess=positive_real), finc_dt=float(finc_dt), fdec_dt=float(fdec_dt), alpha_start=float(alpha_start), fdec_alpha=float(fdec_alpha), force_tol=float(force_tol), angmom_tol=float(angmom_tol), energy_tol=float(energy_tol), min_steps_conv=OnlyTypes(int, preprocess=positive_real), _defaults={ 'min_steps_adapt': 5, 'min_steps_conv': 10 }) self._param_dict.update(pdict) # set these values explicitly so they can be validated self.min_steps_adapt = min_steps_adapt self.min_steps_conv = min_steps_conv # have to remove methods from old syncedlist so new syncedlist doesn't # think members are attached to multiple syncedlists self._methods.clear() methods_list = syncedlist.SyncedList( OnlyTypes((hoomd.md.methods.NVE, hoomd.md.methods.NPH, hoomd.md.methods.rattle.NVE)), syncedlist._PartialGetAttr("_cpp_obj"), iterable=methods) self._methods = methods_list
def __init__(self, moves, target, solver, types=None, max_translation_move=None, max_rotation_move=None): super().__init__(target, solver) # A flag for knowing when to update the maximum move sizes self._should_update_move_sizes = False # set up maximum trial move sizes t_moves = TypeParameter( 'max_translation_move', 'particle_type', TypeParameterDict(OnlyTypes( float, postprocess=self._flag_move_size_update, allow_none=True), len_keys=1)) r_moves = TypeParameter( 'max_rotation_move', 'particle_type', TypeParameterDict(OnlyTypes( float, postprocess=self._flag_move_size_update, allow_none=True), len_keys=1)) self._typeparam_dict = { 'max_translation_move': t_moves, 'max_rotation_move': r_moves } # This is a bit complicated because we are having to ensure that we keep # the list of tunables and the solver updated with the changes to # attributes. However, these are simply forwarding a change along. param_dict = ParameterDict( moves=OnlyIf(to_type_converter([OnlyFrom(['a', 'd'])]), postprocess=self._update_moves), types=OnlyIf(to_type_converter([str]), postprocess=self._update_types, allow_none=True), ) self._param_dict.update(param_dict) self.target = target self.solver = solver self.moves = moves self.types = types self.max_rotation_move.default = max_rotation_move self.max_translation_move.default = max_translation_move if types is not None: self._update_tunables(new_moves=moves, new_types=types)
def __init__(self, filter, limit=None, manifold_constraint=None, tolerance=0.000001): # store metadata param_dict = ParameterDict( filter=ParticleFilter, limit=OnlyTypes(float, allow_none=True), zero_force=OnlyTypes(bool, allow_none=False), ) param_dict.update(dict(filter=filter, limit=limit, zero_force=False)) # set defaults self._param_dict.update(param_dict) super().__init__(manifold_constraint,tolerance)
def __init__(self, box1, box2, variant, trigger, filter=All()): params = ParameterDict(box1=OnlyTypes(Box, preprocess=box_preprocessing), box2=OnlyTypes(Box, preprocess=box_preprocessing), variant=Variant, filter=ParticleFilter) params['box1'] = box1 params['box2'] = box2 params['variant'] = variant params['trigger'] = trigger params['filter'] = filter self._param_dict.update(params) super().__init__(trigger)
def __init__(self, filter, manifold_constraint): # store metadata super().__init__(filter) param_dict = ParameterDict( manifold_constraint=OnlyTypes(Manifold, allow_none=False)) param_dict["manifold_constraint"] = manifold_constraint self._param_dict.update(param_dict)
def __init__(self, filter, rotation_diff=0.1): # store metadata param_dict = ParameterDict( filter=ParticleFilter, rotation_diff=float(rotation_diff), constraint=OnlyTypes( ConstraintForce, allow_none=True, preprocess=ellip_preprocessing ), ) param_dict.update( dict( constraint=None, rotation_diff=rotation_diff, filter=filter, ) ) # set defaults self._param_dict.update(param_dict) active_force = TypeParameter( "active_force", type_kind="particle_types", param_dict=TypeParameterDict((1.0, 0.0, 0.0), len_keys=1), ) active_torque = TypeParameter( "active_torque", type_kind="particle_types", param_dict=TypeParameterDict((0.0, 0.0, 0.0), len_keys=1), ) self._extend_typeparam([active_force, active_torque])
def __init__(self, filter, manifold_constraint, tolerance=0.000001, alpha=None): # store metadata param_dict = ParameterDict( filter=ParticleFilter, alpha=OnlyTypes(float, allow_none=True), ) param_dict.update(dict(alpha=alpha, filter=filter)) # set defaults self._param_dict.update(param_dict) gamma = TypeParameter('gamma', type_kind='particle_types', param_dict=TypeParameterDict(1., len_keys=1)) gamma_r = TypeParameter('gamma_r', type_kind='particle_types', param_dict=TypeParameterDict((1., 1., 1.), len_keys=1)) self._extend_typeparam([gamma, gamma_r]) super().__init__(manifold_constraint, tolerance)
def __setstate__(self, state): if state['_param_dict']['output'] is None: del state['_param_dict']['output'] state['_param_dict']['output'] = stdout state['_param_dict']._type_converter['output'] = OnlyTypes( _OutputWriter, postprocess=_ensure_writable), self.__dict__ = state
def __init__(self, manifold_constraint, tolerance): param_dict = ParameterDict(manifold_constraint=OnlyTypes( Manifold, allow_none=False), tolerance=float(tolerance)) param_dict['manifold_constraint'] = manifold_constraint # set defaults self._param_dict.update(param_dict)
def __init__(self, logger, output=stdout, header_sep='.', delimiter=' ', pretty=True, max_precision=10, max_header_len=None): def writable(fh): if not fh.writable(): raise ValueError("file-like object must be writable.") return fh param_dict = ParameterDict(header_sep=str, delimiter=str, min_column_width=int, max_header_len=OnlyTypes(int, allow_none=True), pretty=bool, max_precision=int, output=OnlyTypes(_OutputWriter, postprocess=writable), logger=Logger) param_dict.update( dict(header_sep=header_sep, delimiter=delimiter, min_column_width=max(10, max_precision + 6), max_header_len=max_header_len, max_precision=max_precision, pretty=pretty, output=output, logger=logger)) self._param_dict = param_dict # internal variables that are not part of the state. # Ensure that only scalar and potentially string are set for the logger if (LoggerCategories.scalar not in logger.categories or logger.categories & self._invalid_logger_categories != LoggerCategories.NONE): raise ValueError( "Given Logger must have the scalar categories set.") self._cur_headers_with_width = dict() self._fmt = _Formatter(pretty, max_precision) self._comm = None
def __init__(self, trigger=200, grid=None): super().__init__(trigger) sorter_params = ParameterDict( grid=OnlyTypes(int, postprocess=ParticleSorter._to_power_of_two, preprocess=ParticleSorter._natural_number, allow_none=True)) self._param_dict.update(sorter_params) self.grid = grid
def __init__(self, trigger=200, grid=None): self._param_dict = ParameterDict( trigger=Trigger, grid=OnlyTypes(int, postprocess=ParticleSorter._to_power_of_two, preprocess=ParticleSorter._natural_number, allow_none=True)) self.trigger = trigger self.grid = grid
def __init__(self, nlist, default_r_cut=None, mode="none"): self._nlist = OnlyTypes(md.nlist.NList, strict=True)(nlist) tp_r_cut = TypeParameter('r_cut', 'particle_types', TypeParameterDict(positive_real, len_keys=2)) if default_r_cut is not None: tp_r_cut.default = default_r_cut self._param_dict.update(ParameterDict(mode=OnlyFrom(['none', 'shift']))) self.mode = mode self._add_typeparam(tp_r_cut)
def __init__(self, forces, constraints, methods, rigid): forces = [] if forces is None else forces constraints = [] if constraints is None else constraints methods = [] if methods is None else methods self._forces = syncedlist.SyncedList( Force, syncedlist._PartialGetAttr('_cpp_obj'), iterable=forces) self._constraints = syncedlist.SyncedList( OnlyTypes(Constraint, disallow_types=(Rigid,)), syncedlist._PartialGetAttr('_cpp_obj'), iterable=constraints) self._methods = syncedlist.SyncedList( Method, syncedlist._PartialGetAttr('_cpp_obj'), iterable=methods) param_dict = ParameterDict(rigid=OnlyTypes(Rigid, allow_none=True)) if rigid is not None and rigid._added: raise ValueError("Rigid object can only belong to one integrator.") param_dict["rigid"] = rigid self._param_dict.update(param_dict)
def __init__(self, default_d=0.1, default_a=0.1, chain_probability=0.5, chain_time=0.5, update_fraction=0.5, nselect=1): # initialize base class super().__init__(default_d, default_a, 0.5, nselect) # Set base parameter dict for hpmc chain integrators param_dict = ParameterDict( chain_probability=OnlyTypes( float, postprocess=self._process_chain_probability), chain_time=OnlyTypes(float, postprocess=self._process_chain_time), update_fraction=OnlyTypes( float, postprocess=self._process_update_fraction)) self._param_dict.update(param_dict) self.chain_probability = chain_probability self.chain_time = chain_time self.update_fraction = update_fraction
def __init__(self, manifold_constraint, tolerance): if manifold_constraint == None and tolerance != 1e-6: raise TypeError("The tolerance for RATTLE integration has been changed but " "manifold_constraint is not specified!") param_dict = ParameterDict( manifold_constraint = OnlyTypes(Manifold, allow_none=True), tolerance=float(tolerance) ) param_dict['manifold_constraint'] = manifold_constraint # set defaults self._param_dict.update(param_dict)
def __init__(self, buffer, exclusions, rebuild_check_delay, check_dist, mesh): validate_exclusions = OnlyFrom([ 'bond', 'angle', 'constraint', 'dihedral', 'special_pair', 'body', '1-3', '1-4', 'meshbond' ]) validate_mesh = OnlyTypes(Mesh, allow_none=True) # default exclusions params = ParameterDict(exclusions=[validate_exclusions], buffer=float(buffer), rebuild_check_delay=int(rebuild_check_delay), check_dist=bool(check_dist)) params["exclusions"] = exclusions self._param_dict.update(params) self._mesh = validate_mesh(mesh)
def __init__( self, boxmc, moves, target, solver, max_move_size=None, ): super().__init__(target, solver) # Flags for knowing when to update classes attributes self._update_move_sizes = False self._should_update_tunables = False # This is a bit complicated because we are having to ensure that we keep # the list of tunables and the solver updated with the changes to # attributes. However, these are simply forwarding a change along. params = ParameterDict( boxmc=hoomd.hpmc.update.BoxMC, moves=[ OnlyFrom(_MoveSizeTuneDefinition.acceptable_attrs, postprocess=self._flag_new_tunables) ], max_move_size=OnlyIf( to_type_converter({ attr: OnlyTypes(float, allow_none=True, postprocess=self._flag_move_size_update) for attr in _MoveSizeTuneDefinition.acceptable_attrs }),)) params["boxmc"] = boxmc params["moves"] = moves if max_move_size is None: max_move_size = { attr: None for attr in _MoveSizeTuneDefinition.acceptable_attrs } params["max_move_size"] = max_move_size self._param_dict.update(params) self._update_tunables()
def __init__(self, target, solver): self._tunables = [] # A counter when tuned reaches 1 it means that the tuner has reported # being tuned one time in a row. However, as the first run of the tuner # is likely at timestep 0 which means that the counters are (0, 0) and # _MoveSizeTuneDefinition returns y == target for that case, we need two # rounds of tuning to be sure that we have converged. Since, in general, # solvers do not do much if any work on already tuned tunables, this is # not a performance problem. self._tuned = 0 self._is_attached = False # This is a bit complicated because we are having to ensure that we keep # the list of tunables and the solver updated with the changes to # attributes. However, these are simply forwarding a change along. param_dict = ParameterDict(target=OnlyTypes( float, postprocess=self._target_postprocess), solver=SolverStep) self._param_dict.update(param_dict) self.target = target self.solver = solver
def __init__(self, filter, kT, alpha=None): # store metadata param_dict = ParameterDict( filter=ParticleFilter, kT=Variant, alpha=OnlyTypes(float, allow_none=True), ) param_dict.update(dict(kT=kT, alpha=alpha, filter=filter)) # set defaults self._param_dict.update(param_dict) gamma = TypeParameter('gamma', type_kind='particle_types', param_dict=TypeParameterDict(1., len_keys=1)) gamma_r = TypeParameter('gamma_r', type_kind='particle_types', param_dict=TypeParameterDict((1., 1., 1.), len_keys=1)) self._extend_typeparam([gamma, gamma_r])
def __init__(self, moves, target, solver, types=None, max_translation_move=None, max_rotation_move=None): def target_postprocess(target): def check_fraction(value): if 0 <= value <= 1: return value raise ValueError( "Value {} should be between 0 and 1.".format(value)) self._update_tunables_attr('target', check_fraction(target)) self._tuned = 0 return target def update_moves(value): self._update_tunables(new_moves=value) self._tuned = 0 return value def update_types(value): self._update_tunables(new_types=value) self._tuned = 0 return value # A flag for knowing when to update the maximum move sizes self._update_move_sizes = False self._tunables = [] # A counter when tuned reaches 1 it means that the tuner has reported # being tuned one time in a row. However, as the first run of the tuner # is likely at timestep 0 which means that the counters are (0, 0) and # _MoveSizeTuneDefinition returns y == target for that case, we need two # rounds of tuning to be sure that we have converged. Since, in general, # solvers do not do much if any work on already tuned tunables, this is # not a performance problem. self._tuned = 0 self._is_attached = False # set up maximum trial move sizes def flag_move_size_update(value): self._update_move_sizes = True return value t_moves = TypeParameter( 'max_translation_move', 'particle_type', TypeParameterDict(OnlyTypes(float, postprocess=flag_move_size_update, allow_none=True), len_keys=1)) r_moves = TypeParameter( 'max_rotation_move', 'particle_type', TypeParameterDict(OnlyTypes(float, postprocess=flag_move_size_update, allow_none=True), len_keys=1)) self._typeparam_dict = { 'max_translation_move': t_moves, 'max_rotation_move': r_moves } # This is a bit complicated because we are having to ensure that we keep # the list of tunables and the solver updated with the changes to # attributes. However, these are simply forwarding a change along. param_dict = ParameterDict( moves=OnlyIf(to_type_converter([OnlyFrom(['a', 'd'])]), postprocess=update_moves), types=OnlyIf(to_type_converter([str]), postprocess=update_types, allow_none=True), target=OnlyTypes(float, postprocess=target_postprocess), solver=SolverStep) self._param_dict.update(param_dict) self.target = target self.solver = solver self.moves = moves self.types = types self.max_rotation_move.default = max_rotation_move self.max_translation_move.default = max_translation_move if types is not None: self._update_tunables(new_moves=moves, new_types=types)
# Copyright (c) 2009-2021 The Regents of the University of Michigan # This file is part of the HOOMD-blue project, released under the BSD 3-Clause # License. """Implement many body potentials.""" import hoomd from hoomd.data.parameterdicts import TypeParameterDict from hoomd.data.typeconverter import OnlyTypes, positive_real from hoomd.data.typeparam import TypeParameter from hoomd.md import _md from hoomd.md.force import Force from hoomd.md.nlist import NList validate_nlist = OnlyTypes(NList) class Triplet(Force): r"""Common three body potential documentation. Users should not invoke :py:class:`Triplet` directly. It is a base class that provides common features to all standard triplet forces. Common documentation for all three-body potentials is documented here. All triplet force commands specify that a given force be computed on all particles which have at least two other particles within a short range cutoff distance :math:`r_{\mathrm{cut}}`. The force :math:`\vec{F}` applied to each particle :math:`i` is: .. math:: :nowrap:
# Copyright (c) 2009-2022 The Regents of the University of Michigan. # Part of HOOMD-blue, released under the BSD 3-Clause License. """Mesh potential base class.""" from hoomd.md import _md from hoomd.mesh import Mesh from hoomd.md.force import Force from hoomd.data.typeconverter import OnlyTypes import hoomd import warnings import copy validate_mesh = OnlyTypes(Mesh) class MeshPotential(Force): """Constructs the bond potential applied to a mesh. `MeshPotential` is the base class for all bond potentials applied to meshes. Warning: This class should not be instantiated by users. The class can be used for `isinstance` or `issubclass` checks. """ def __init__(self, mesh): self._mesh = validate_mesh(mesh) def _add(self, simulation): # if mesh was associated with multiple pair forces and is still # attached, we need to deepcopy existing mesh. mesh = self._mesh