Forces

mechanica.Force

alias of mechanica.mechanica.MxForce

class mechanica.MxForce

MxForce is a metatype, in that Mechanica has lots of different instances of force functions, that have different attributes, but only have one base type.

Forces are one of the fundamental processes in Mechanica that cause objects to move.

bind_species(a_type: MxParticleType, coupling_symbol: std::string const &) HRESULT

Bind a force to a species.

When a force is bound to a species, the magnitude of the force is scaled by the concentration of the species.

Parameters
  • a_type (MxParticleType) – particle type containing the species

  • coupling_symbol (string) – symbol of the species

Return type

int

Returns

HRESULT

static berenderson_tstat(tau: float const &) Berendsen *

Creates a Berendsen thermostat.

The thermostat uses the target temperature \(T_0\) from the object to which it is bound. The Berendsen thermostat effectively re-scales the velocities of an object in order to make the temperature of that family of objects match a specified temperature.

The Berendsen thermostat force has the function form:

\[\frac{\mathbf{p}}{\tau_T} \left(\frac{T_0}{T} - 1 \right),\]

where \(\mathbf{p}\) is the momentum, \(T\) is the measured temperature of a family of particles, \(T_0\) is the control temperature, and \(\tau_T\) is the coupling constant. The coupling constant is a measure of the time scale on which the thermostat operates, and has units of time. Smaller values of \(\tau_T\) result in a faster acting thermostat, and larger values result in a slower acting thermostat.

Parameters

tau (float) – time constant that determines how rapidly the thermostat effects the system.

Return type

Berendsen

Returns

Berendsen*

static random(std: float const &, mean: float const &, duration: float const & = 0.01) Gaussian *

Creates a random force.

A random force has a randomly selected orientation and magnitude.

Orientation is selected according to a uniform distribution on the unit sphere.

Magnitude is selected according to a prescribed mean and standard deviation.

Parameters
  • std (float) – standard deviation of magnitude

  • mean (float) – mean of magnitude

  • duration (float) – duration of force. Defaults to 0.01.

Return type

Gaussian

Returns

Gaussian*

static friction(coef: float const &, std: float const & = 0.0, mean: float const & = 0.0, duration: float const & = 0.1) Friction *

Creates a friction force.

A friction force has the form:

\[- \frac{|| \mathbf{v} ||}{\tau} \mathbf{v} + \mathbf{f}_{r} ,\]

where \(\mathbf{v}\) is the velocity of a particle, \(\tau\) is a time constant and \(\mathbf{f}_r\) is a random force.

Parameters
  • coef (float) – time constant

  • std (float) – standard deviation of random force magnitude

  • mean (float) – mean of random force magnitude

  • duration (float) – duration of force. Defaults to 0.1.

Return type

Friction

Returns

Friction*

toString() std::string

Get a JSON string representation

Return type

string

Returns

std::string

static fromString(str: std::string const &) MxForce *

Create from a JSON string representation

Parameters

str (string) –

Return type

MxForce

Returns

MxForce*

__reduce__()

Helper for pickle.

mechanica.ConstantForce

alias of mechanica.mechanica.MxConstantForcePy

class mechanica.MxConstantForce(*args)

Bases: mechanica.mechanica.MxForce

A custom force function.

The force is updated according to an update frequency.

This object acts like a constant force, but also acts like a time event, in that it periodically calls a custom function to update the applied force.

property value

Current value of the force.

This can be set to a function that takes no arguments and returns a 3-component list of floats.

property period

Period of the force

static fromForce(f: MxForce) MxConstantForce *

Convert basic force to MxConstantForce.

If the basic force is not a MxConstantForce, then NULL is returned.

Parameters

f (MxForce) –

Return type

MxConstantForce

Returns

MxConstantForce*

class mechanica.MxConstantForcePy(*args)

Bases: mechanica.mechanica.MxConstantForce

Creates an instance from an underlying custom python function

Parameters
  • f (PyObject) – python function. Takes no arguments and returns a three-component vector.

  • period (float) – period at which the force is updated.

static fromForce(f: MxForce) MxConstantForcePy *

Convert basic force to MxConstantForcePy.

If the basic force is not a MxConstantForcePy, then NULL is returned.

Parameters

f (MxForce) –

Return type

MxConstantForcePy

Returns

MxConstantForcePy*

mechanica.ForceSum

alias of mechanica.mechanica.MxForceSum

class mechanica.MxForceSum

Bases: mechanica.mechanica.MxForce

f1
f2
static fromForce(f: MxForce) MxForceSum *

Convert basic force to force sum.

If the basic force is not a force sum, then NULL is returned.

Parameters

f (MxForce) –

Return type

MxForceSum

Returns

MxForceSum*

class mechanica.Berendsen

Bases: mechanica.mechanica.MxForce

Berendsen force.

Create one with MxForce.berenderson_tstat.

itau

time constant

static fromForce(f: MxForce) Berendsen *

Convert basic force to Berendsen.

If the basic force is not a Berendsen, then NULL is returned.

Parameters

f (MxForce) –

Return type

Berendsen

Returns

Berendsen*

class mechanica.Gaussian

Bases: mechanica.mechanica.MxForce

Random force.

Create one with MxForce.random.

std

standard deviation of magnitude

mean

mean of magnitude

durration_steps

duration of force.

static fromForce(f: MxForce) Gaussian *

Convert basic force to Gaussian.

If the basic force is not a Gaussian, then NULL is returned.

Parameters

f (MxForce) –

Return type

Gaussian

Returns

Gaussian*

class mechanica.Friction

Bases: mechanica.mechanica.MxForce

Friction force.

Create one with MxForce.friction.

coef

time constant

std

standard deviation of random force magnitude

mean

mean of random force magnitude

durration_steps

duration of force, in time steps

static fromForce(f: MxForce) Friction *

Convert basic force to Friction.

If the basic force is not a Friction, then NULL is returned.

Parameters

f (MxForce) –

Return type

Friction

Returns

Friction*