示例#1
0
文件: gsd.py 项目: tltht/hoomd-blue
    def __init__(self,
                 filename,
                 trigger,
                 filter=All(),
                 mode='ab',
                 truncate=False,
                 dynamic=None,
                 log=None):

        super().__init__(trigger)

        dynamic_validation = OnlyFrom(
            ['attribute', 'property', 'momentum', 'topology'],
            preprocess=array_to_strings)

        dynamic = ['property'] if dynamic is None else dynamic
        self._param_dict.update(
            ParameterDict(filename=str(filename),
                          filter=ParticleFilter,
                          mode=str(mode),
                          truncate=bool(truncate),
                          dynamic=[dynamic_validation],
                          _defaults=dict(filter=filter, dynamic=dynamic)))

        self._log = None if log is None else _GSDLogWriter(log)
示例#2
0
 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)
示例#3
0
    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)
示例#4
0
    def __init__(self, dt, aniso='auto', forces=None, constraints=None,
                 methods=None):

        super().__init__(forces, constraints, methods)

        self._param_dict = ParameterDict(
            dt=float(dt),
            aniso=OnlyFrom(['true', 'false', 'auto'],
                           preprocess=_preprocess_aniso),
            _defaults=dict(aniso="auto")
            )
        if aniso is not None:
            self.aniso = aniso
示例#5
0
    def __init__(self, buffer, exclusions, rebuild_check_delay, diameter_shift,
                 check_dist, max_diameter):

        validate_exclusions = OnlyFrom([
            'bond', 'angle', 'constraint', 'dihedral', 'special_pair', 'body',
            '1-3', '1-4'
        ])
        # default exclusions
        params = ParameterDict(exclusions=[validate_exclusions],
                               buffer=float(buffer),
                               rebuild_check_delay=int(rebuild_check_delay),
                               check_dist=bool(check_dist),
                               diameter_shift=bool(diameter_shift),
                               max_diameter=float(max_diameter),
                               _defaults={'exclusions': exclusions})
        self._param_dict.update(params)
示例#6
0
    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()
示例#8
0
    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)