Action¶
- class hoomd.custom.Action¶
Base class for user-defined actions.
To implement a custom operation in Python, subclass
hoomd.custom.Actionand implement theact()method to perform the desired action. To include the action in the simulation run loop, pass an instance of the action tohoomd.update.CustomUpdater,hoomd.write.CustomWriter, orhoomd.tune.CustomTuner.Examples:
class ExampleAction(hoomd.custom.Action): def act(self, timestep): snapshot = self._state.get_snapshot() if snapshot.communicator.rank == 0: self.com = snapshot.particles.position.mean(axis=0)
To request that HOOMD-blue compute virials, pressure, the rotational kinetic energy, or the external field virial, set the flags attribute with the appropriate flags from the internal
Action.Flagsenumeration:class ExampleAction(hoomd.custom.Action): flags = [ Action.Flags.ROTATIONAL_KINETIC_ENERGY, Action.Flags.PRESSURE_TENSOR, Action.Flags.EXTERNAL_FIELD_VIRIAL, ] def act(self, timestep): pass
Use the
hoomd.logging.logdecorator to define loggable properties:class ExampleAction(hoomd.custom.Action): @hoomd.logging.log def answer(self): return 42 def act(self, timestep): pass example_action = ExampleAction() logger.add(example_action, quantities=["answer"])
- flags¶
List of flags from the
Action.Flags. Used to tell the integrator if specific quantities are needed for the action.- Type:
- class Flags(*values)¶
Flags to indictate the integrator should calculate quantities.
PRESSURE_TENSOR = 0
ROTATIONAL_KINETIC_ENERGY = 1
EXTERNAL_FIELD_VIRIAL = 2
- abstractmethod act(timestep)¶
Performs whatever action a subclass implements.
- Parameters:
timestep (int) – The current timestep in a simulation.
Note
Use
self._stateto access the simulation state viahoomd.Statewhen using the base classattach.
- attach(simulation)¶
Attaches the Action to the
hoomd.Simulation.- Parameters:
simulation (hoomd.Simulation) – The simulation to attach the action to.
Stores the simulation state in
self._state. Override this in derived classes to implement other behaviors.
- detach()¶
Detaches the Action from the
hoomd.Simulation.