hoomd.variant#

Overview

Constant

A constant value.

Cycle

A cycle of linear ramps.

Power

An approach from initial to final value following t**power.

Ramp

A linear ramp.

Variant

Variant base class.

variant_like

alias of Union[Variant, float]

Details

Define quantities that vary over the simulation.

A Variant object represents a function of the time step. Some operations accept Variant values for certain parameters, such as the kT parameter to hoomd.md.methods.thermostats.Bussi.

See Variant for details on creating user-defined variants or use one of the provided subclasses.

class hoomd.variant.Constant(value)#

Bases: Variant

A constant value.

Parameters:

value (float) – The value.

Constant returns value at all time steps.

Example:

variant = hoomd.variant.Constant(1.0)
value#

The value.

Type:

float

__eq__(other)#

Return whether two variants are equivalent.

class hoomd.variant.Cycle(A, B, t_start, t_A, t_AB, t_B, t_BA)#

Bases: Variant

A cycle of linear ramps.

Parameters:
  • A (float) – The first value.

  • B (float) – The second value.

  • t_start (int) – The start time step.

  • t_A (int) – The hold time at the first value.

  • t_AB (int) – The time spent ramping from A to B.

  • t_B (int) – The hold time at the second value.

  • t_BA (int) – The time spent ramping from B to A.

Cycle holds the value A until time t_start. It continues holding that value until t_start + t_A. Then it ramps linearly from A to B over t_AB steps and holds the value B for t_B steps. After this, it ramps back from B to A over t_BA steps and repeats the cycle starting with t_A. Cycle repeats this cycle indefinitely.

Example plot of a cycle variant.

Example:

variant = hoomd.variant.Cycle(A=1.0,
                              B=2.0,
                              t_start=10_000,
                              t_A=100_000,
                              t_AB=1_000_000,
                              t_B=200_000,
                              t_BA=2_000_000)
A#

The first value.

Type:

float

B#

The second value.

Type:

float

t_start#

The start time step.

Type:

int

t_A#

The holding time at A.

Type:

int

t_AB#

The time spent ramping from A to B.

Type:

int

t_B#

The holding time at B.

Type:

int

t_BA#

The time spent ramping from B to A.

Type:

int

__eq__(other)#

Return whether two variants are equivalent.

class hoomd.variant.Power(A, B, power, t_start, t_ramp)#

Bases: Variant

An approach from initial to final value following t**power.

Parameters:
  • A (float) – The start value.

  • B (float) – The end value.

  • power (float) – The power of the approach to B.

  • t_start (int) – The start time step.

  • t_ramp (int) – The length of the ramp.

Power holds the value A until time t_start. Then it progresses at \(t^{\mathrm{power}}\) from A to B over t_ramp steps and holds the value B after that.

Example plot of a power variant.

Example:

variant = hoomd.variant.Power(A=2,
                              B=8,
                              power=1 / 10,
                              t_start=10, t_ramp=20)
A#

The start value.

Type:

float

B#

The end value.

Type:

float

power#

The power of the approach to B.

Type:

float

t_start#

The start time step.

Type:

int

t_ramp#

The length of the ramp.

Type:

int

__eq__(other)#

Return whether two variants are equivalent.

class hoomd.variant.Ramp(A, B, t_start, t_ramp)#

Bases: Variant

A linear ramp.

Parameters:
  • A (float) – The start value.

  • B (float) – The end value.

  • t_start (int) – The start time step.

  • t_ramp (int) – The length of the ramp.

Ramp holds the value A until time t_start. Then it ramps linearly from A to B over t_ramp steps and holds the value B.

Example plot of a ramp variant.

Example:

variant = hoomd.variant.Ramp(A=1.0,
                             B=2.0,
                             t_start=10_000,
                             t_ramp=100_000)
A#

The start value.

Type:

float

B#

The end value.

Type:

float

t_start#

The start time step.

Type:

int

t_ramp#

The length of the ramp.

Type:

int

__eq__(other)#

Return whether two variants are equivalent.

class hoomd.variant.Variant#

Variant base class.

Provides methods common to all variants and a base class for user-defined variants.

Subclasses should override the __call__, _min, and _max methods and must explicitly call the base class constructor in __init__:

class CustomVariant(hoomd.variant.Variant):
    def __init__(self):
        hoomd.variant.Variant.__init__(self)

    def __call__(self, timestep):
        return (float(timestep)**(1 / 2))

    def _min(self):
        return 0.0

    def _max(self):
        return float('inf')

Note

Provide the minimum and maximum values in the _min and _max methods respectively.

__call__(timestep)#

Evaluate the function.

Parameters:

timestep (int) – The time step.

Returns:

The value of the function at the given time step.

Return type:

float

__getstate__()#

Get the variant’s __dict__ attribute.

__setstate__(state)#

Restore the state of the variant.

property max#

The maximum value of this variant for \(t \in [0,\infty)\).

property min#

The minimum value of this variant for \(t \in [0,\infty)\).

hoomd.variant.variant_like#

alias of Union[Variant, float]

Modules