hoomd.custom

Overview

Action

Base class for all Python Actions.

CustomOperation

Wrapper for user created hoomd.custom.Action objects.

Details

class hoomd.custom.Action

Base class for all Python Actions.

This class is the parent class for all Python Action subclasses. This class requires all subclasses to implement the act() method which performs the Python object’s task whether that be updating the system, writing output, or analyzing some property of the system.

To use subclasses of this class, the object must be passed as an argument to a hoomd.update.CustomUpdater, hoomd.write.CustomWriter, or hoomd.tune.CustomTuner constructor.

If the pressure, rotational kinetic energy, or external field virial is needed for a subclass, the flags attribute of the class needs to be set with the appropriate flags from the internal Action.Flags enumeration.

from hoomd.custom import Action


class ExampleActionWithFlag(Action):
    flags = [Action.Flags.ROTATIONAL_KINETIC_ENERGY,
             Action.Flags.PRESSURE_TENSOR,
             Action.Flags.EXTERNAL_FIELD_VIRIAL]

    def act(self, timestep):
        pass

For advertising loggable quantities through the wrapping object, the decorator hoomd.logging.log can be used.

from hoomd.python_action import Action
from hoomd.logging import log


class ExampleActionWithFlag(Action):

    @log
    def answer(self):
        return 42

    def act(self, timestep):
        pass

An example of a Action that actually performs an action is given below. This Action computes the center of mass of the system.

from hoomd.custom import Action


class ExampleAction(Action):
    def act(self, timestep):
        self.com = self._state.snapshot.particles.position.mean(axis=0)
flags

List of flags from the hoomd.custom.Action.Flags. Used to tell the integrator if specific quantities are needed for the action.

Type

list[hoomd.custom.Action.Flags]

class Flags(value)

Flags to indictate the integrator should calcuate certain quantities.

  • PRESSURE_TENSOR = 0

  • ROTATIONAL_KINETIC_ENERGY = 1

  • EXTERNAL_FIELD_VIRIAL = 2

abstract act(timestep)

Performs whatever action a subclass implements.

This method can change the state (updater) or compute or store data (analyzer).

Parameters

timestep (int) – The current timestep in a simulation.

Note

A hoomd.State is not given here. This means that if the default attach method is overwritten, there is no way to query or change the state when called. By default, the state is accessible through self._state after attaching.

attach(simulation)

Attaches the Action to the hoomd.Simulation.

Parameters

simulation (hoomd.Simulation) – The simulation to attach the action to.

detach()

Detaches the Action from the hoomd.Simulation.

property loggables

Return a name, category mapping of loggable quantities.

Type

dict[str, str]

class hoomd.custom.CustomOperation(action, trigger=1)

Wrapper for user created hoomd.custom.Action objects.

This is the parent class for hoomd.update.CustomUpdater and hoomd.analyze.CustomWriter. A basic wrapper that allows for Python object inheriting from hoomd.custom.Action to be attached to a simulation. To see how to implement a custom Python action, look at the documentation for hoomd.custom.Action.

This class also implements a “pass-through” system for attributes. Attributes and methods from the passed in action will be available directly in this class. This does not apply to attributes with these names: trigger, _action, and action.

Note

Due to the pass through no attribute should exist both in hoomd.custom.CustomOperation and the hoomd.custom.Action.

Note

This object should not be instantiated or subclassed by an user.

trigger

A trigger to determine when the wrapped hoomd.custom.Action is run.

Type

hoomd.trigger.Trigger

__getattr__(attr)

Allows pass through to grab attributes/methods of the wrapped object.

act(timestep)

Perform the action of the custom action if attached.

Calls through to the action property of the instance.

Parameters

timestep (int) – The current timestep of the state.

property action

hoomd.custom.Action The action the operation wraps.