hoomd.trigger

Overview

hoomd.trigger.After

Trigger on all steps after a given step.

hoomd.trigger.And

Boolean and operation.

hoomd.trigger.Before

Trigger on all steps before a given step.

hoomd.trigger.Not

Negate a trigger.

hoomd.trigger.On

Trigger on a specific timestep.

hoomd.trigger.Or

Boolean or operation.

hoomd.trigger.Periodic

Trigger periodically.

hoomd.trigger.Trigger

Base class trigger.

Details

Triggers determine when hoomd.Operations 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)

Trigger on all steps after a given step.

Parameters

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

hoomd.trigger.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)

Boolean and operation.

Parameters

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

hoomd.trigger.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)

Trigger on all steps before a given step.

Parameters

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

hoomd.trigger.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)

Negate a trigger.

Parameters

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

hoomd.trigger.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)

Trigger on a specific timestep.

Parameters

timestep (int) – The timestep to trigger on.

hoomd.trigger.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)

Boolean or operation.

Parameters

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

hoomd.trigger.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 [hoomd.trigger.Trigger]

class hoomd.trigger.Periodic(period, phase)

Trigger periodically.

Parameters
  • period (int) – timesteps for periodicity

  • phase (int) – timesteps for phase

hoomd.trigger.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