hoomd.trigger

Overview

After

Trigger on all steps after a given step.

And

Boolean and operation.

Before

Trigger on all steps before a given step.

Not

Negate a trigger.

On

Trigger on a specific timestep.

Or

Boolean or operation.

Periodic

Trigger periodically.

Trigger

Base class trigger.

trigger_like

An object that can serve as a trigger for an operation.

Details

Triggers determine when hoomd.operation.Operation instances activate.

A Trigger is a boolean valued function of the timestep. The operation will perform its action when Trigger returns True. A single trigger object may be assigned to multiple operations.

User defined triggers

You can define your own triggers by subclassing Trigger in Python. When you do so, override the Trigger.compute method and explicitly call the base class constructor in __init__.

Example

Define a custom trigger:

class CustomTrigger(hoomd.trigger.Trigger):

    def __init__(self):
        hoomd.trigger.Trigger.__init__(self)

    def compute(self, timestep):
        return (timestep**(1 / 2)).is_integer()
class hoomd.trigger.After(timestep)

Bases: Trigger

Trigger on all steps after a given step.

Parameters

timestep (int) – The step before the trigger will start.

After returns True for all time steps greater than timestep:

return t > timestep

Example:

# trigger every 100 time steps after 1000 time steps.
trigger = hoomd.trigger.And([
        hoomd.trigger.After(1000),
        hoomd.trigger.Periodic(100)])
timestep

The step before the trigger will start.

Type

int

class hoomd.trigger.And(triggers)

Bases: Trigger

Boolean and operation.

Parameters

triggers (list [Trigger]) – List of triggers.

And returns True when all the input triggers returns True:

return all([f(t) for f in triggers])

Example:

# trigger every 100 time steps after 1000 time steps.
trig = hoomd.trigger.And([
        hoomd.trigger.After(1000),
        hoomd.trigger.Periodic(100)])
triggers

List of triggers.

Type

list[hoomd.trigger.Trigger]

class hoomd.trigger.Before(timestep)

Bases: Trigger

Trigger on all steps before a given step.

Parameters

timestep (int) – The step after the trigger ends.

Before evaluates True for all time steps less than the timestep:

return t < timestep

Example:

# trigger every 100 time steps at less than first 5000 steps.
trigger = hoomd.trigger.And(
    [hoomd.trigger.Periodic(100),
    hoomd.trigger.Before(sim.timestep + 5000)])
timestep

The step after the trigger ends.

Type

int

class hoomd.trigger.Not(trigger)

Bases: Trigger

Negate a trigger.

Parameters

trigger (hoomd.trigger.Trigger) – The trigger object to negate.

Not returns the boolean negation of trigger:

return not trigger(t)

Example:

trigger = hoomd.trigger.Not(hoomd.trigger.After(1000))
trigger

The trigger object to negate.

Type

hoomd.trigger.Trigger

class hoomd.trigger.On(timestep)

Bases: Trigger

Trigger on a specific timestep.

Parameters

timestep (int) – The timestep to trigger on.

On returns True for steps equal to timestep:

return t == timestep

Example:

# trigger at 1000 time steps
trigger = hoomd.trigger.On(1000)
timestep

The timestep to trigger on.

Type

int

class hoomd.trigger.Or(triggers)

Bases: Trigger

Boolean or operation.

Parameters

triggers (list [Trigger]) – List of triggers.

Or returns True when any of the input triggers returns True:

return any([f(t) for f in triggers])

Example:

# trigger every 100 time steps before at time step of 1000.
# or      every 10  time steps after  at time step of 1000.
trig = hoomd.trigger.Or([hoomd.trigger.And([
                            hoomd.trigger.Before(1000),
                            hoomd.trigger.Periodic(100)]),
                        [hoomd.trigger.And([
                            hoomd.trigger.After(1000),
                            hoomd.trigger.Periodic(10)])
                        ])
triggers

List of triggers.

Type

list [Trigger]

class hoomd.trigger.Periodic(period, phase)

Bases: Trigger

Trigger periodically.

Parameters
  • period (int) – timesteps for periodicity

  • phase (int) – timesteps for phase

Periodic evaluates True every period steps offset by phase:

return (t - phase) % period == 0

Example:

trig = hoomd.trigger.Periodic(100)
period

periodicity in time step.

Type

int

phase

phase in time step.

Type

int

class hoomd.trigger.Trigger

Base class trigger.

Provides methods common to all triggers.

Attention

Users should instantiate the subclasses, using Trigger directly will result in an error.

__call__(timestep)

Evaluate the trigger.

Parameters

timestep (int) – The timestep.

Note

When called several times with the same timestep, __call__ calls compute on the first invocation, caches the value, and returns that cached value in subsequent calls.

Returns

True when the trigger is active, False when it is not.

Return type

bool

compute(timestep)

Evaluate the trigger.

Parameters

timestep (int) – The timestep.

Returns

True when the trigger is active, False when it is not.

Return type

bool

hoomd.trigger.trigger_like

An object that can serve as a trigger for an operation.

Any instance of a Trigger subclass is allowed, as well as an int instance or any object convertible to an int. The integer is converted to a Periodic trigger via Periodic(period=int(a)) where a is the passed integer.

Note

Attributes that are Trigger objects can be set via a trigger_like object.

alias of Union[Trigger, int]