pylj.simulation#

The base class the two simulations share.

Shared simulation base class and sample records.

pylj.simulation.DEFAULT_CUT_OFF = 15#

The cut-off used when none is given, in Angstrom, or half the box if that is smaller.

class pylj.simulation.Samples(step: NDArray[int64] = <factory>)[source]#

Bases: object

The record a simulation’s sample appends to.

Every array holds one entry per call of sample, in order.

step#

The step at which each sample was taken.

Type:

numpy._typing._array_like.NDArray[numpy.int64]

add(**values: float) None[source]#

Appends one value to every array.

Parameters:

**values – One value for each of this record’s arrays, by name.

Raises:

ValueError – If the names do not match this record’s arrays exactly.

class pylj.simulation.Simulation(configuration: Configuration, model: Model, *, cut_off: float | None = None, seed: int | None = None)[source]#

Bases: ABC

The base class molecular dynamics and Monte Carlo share.

The constructor takes a configuration that is already built, in SI units; the initialise method of either subclass builds one from a model and a number of atoms instead.

Parameters:
  • configuration – The starting configuration.

  • model – The model.

  • cut_off – The separation, in metres, beyond which a pair’s energy and force are zero. By default DEFAULT_CUT_OFF Angstrom or half the box, whichever is smaller; it may not exceed half the box.

  • seed – Seed for the random number generator; the same seed reproduces the run, and without one the run differs each time.

configuration#

The current configuration.

rng#

The random number generator for this simulation.

steps#

The number of steps taken.

samples#

The record sample appends to.

trajectory#

The configurations sampled so far, a Trajectory.

Raises:

ValueError – If a species in the configuration is not in the model, or the cut-off exceeds half the box.

abstractmethod step() None[source]#

Advances the simulation by one step.

abstractmethod sample() None[source]#

Records the current step in samples.

restart() Self[source]#

Returns a new simulation continuing from the current configuration.

The new simulation copies the model, the numerical choices and the state of the random number generator, and starts with steps at zero, no samples and an empty trajectory. This simulation is unchanged. Use it to start a production run after equilibration:

for _ in range(1000):
    simulation.step()
production = simulation.restart()
for _ in range(5000):
    production.step()
    production.sample()
Returns:

The new simulation.