Esempio n. 1
0
def test_all_filter(make_filter_snapshot, simulation_factory):
    particle_types = ['A']
    N = 10
    filter_snapshot = make_filter_snapshot(n=N, particle_types=particle_types)
    sim = simulation_factory(filter_snapshot)
    all_filter = All()
    assert all_filter(sim.state) == list(range(N))
Esempio n. 2
0
    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)
Esempio n. 3
0
    def write(state, filename, filter=All(), mode='wb', log=None):
        """Write the given simulation state out to a GSD file.

        Args:
            state (State): Simulation state.
            filename (str): File name to write.
            filter (`hoomd.filter.ParticleFilter`): Select the particles to
              write.
            mode (str): The file open mode. Defaults to ``'wb'``.
            log (`hoomd.logging.Logger`): Provide log quantities to write.

        The valid file modes for `write` are ``'wb'`` and ``'xb'``.
        """
        if mode != 'wb' and mode != 'xb':
            raise ValueError(f"Invalid GSD.write file mode: {mode}")

        writer = _hoomd.GSDDumpWriter(state._cpp_sys_def, filename,
                                      state._get_group(filter), mode, False)

        if state._simulation._system_communicator is not None:
            writer.setCommunicator(state._simulation._system_communicator)

        if log is not None:
            writer.log_writer = _GSDLogWriter(log)
        writer.analyze(state._simulation.timestep)
Esempio n. 4
0
 def __init__(self, trigger, box1, box2, variant, filter=All()):
     params = ParameterDict(box1=Box,
                            box2=Box,
                            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)
Esempio n. 5
0
    def update(state, box, filter=All()):
        """Immediately scale the particle in the system state to the given box.

        Args:
            state (State): System state to scale.
            box (Box): New box.
            filter (hoomd.filter.ParticleFilter): The subset of particles to
                update.
        """
        group = state._get_group(filter)
        updater = _hoomd.BoxResizeUpdater(state._cpp_sys_def, state.box, box,
                                          Constant(1), group)
        updater.update(state._simulation.timestep)
Esempio n. 6
0
 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)
Esempio n. 7
0
    def __init__(self,
                 trigger,
                 filename,
                 filter=All(),
                 overwrite=False,
                 unwrap_full=False,
                 unwrap_rigid=False,
                 angle_z=False):

        # initialize base class
        super().__init__(trigger)
        self._param_dict.update(
            ParameterDict(filename=str(filename),
                          filter=ParticleFilter,
                          overwrite=bool(overwrite),
                          unwrap_full=bool(unwrap_full),
                          unwrap_rigid=bool(unwrap_rigid),
                          angle_z=bool(angle_z)))
        self.filter = filter