relentless.model.Cuboid#

class relentless.model.Cuboid(Lx, Ly, Lz)#

Orthorhombic box.

A Cuboid is a special type of TriclinicBox. The three box vectors point along the \(x\), \(y\), and \(z\) axes, so they are all orthogonal (i.e. \(xy=xz=yz=0\)). Each vector can have a different length, \(L_x\), \(L_y\), and \(L_z\).

Parameters:
  • Lx (float) – Length along the \(x\) axis.

  • Ly (float) – Length along the \(y\) axis.

  • Lz (float) – Length along the \(z\) axis.

Methods

as_array([convention])

Convert to array of lengths and tilt factors.

coordinate_to_fraction(r)

Make fractional coordinates from Cartesian coordinates.

fraction_to_coordinate(x)

Make Cartesian coordinates from fractional coordinates.

from_json(data)

Deserialize from a dictionary.

to_json()

Serialize as a dictionary.

wrap(positions)

Wrap positions subject to periodic boundary conditions.

Attributes

extent

Extent of the region.

high

low

as_array(convention=None)#

Convert to array of lengths and tilt factors.

Parameters:

convention ({'LAMMPS','HOOMD'}, optional) – Convention to use for the tilt factors. Default of None will use the convention for the box.

Returns:

An array containing (Lx,Ly,Lz,xy,xz,yz) according to the convention.

Return type:

numpy.ndarray

coordinate_to_fraction(r)#

Make fractional coordinates from Cartesian coordinates.

The Cartesian coordinates r are projected onto the three (potentially nonorthogonal) basis vectors defining the box to yield fractional coordinates x such that:

\[\mathbf{r} = \mathbf{r}_{\rm low} + (\mathbf{a}\quad\mathbf{b}\quad\mathbf{c}) \cdot \mathbf{x}\]

where \(\mathbf{r}_{\rm low}\) is the lower bound of the box, i.e., low.

Parameters:

r (array_like) – Cartesian coordinates (or array of).

Returns:

Fractional coordinates x corresponding to r.

Return type:

numpy.ndarray

property extent#

Extent of the region.

Type:

float

fraction_to_coordinate(x)#

Make Cartesian coordinates from fractional coordinates.

The fractional coordinates x are converted to Cartesian coordinates r using the basis vectors of the box. See coordinate_to_fraction() for the definition of these coordinates.

Parameters:

r (array_like) – Fractional coordinates (or array of).

Returns:

Cartesian coordinates r corresponding to x.

Return type:

numpy.ndarray

classmethod from_json(data)#

Deserialize from a dictionary.

Parameters:

data (dict) – The serialized equivalent of the Cuboid object. The keys of data should be ('Lx','Ly','Lz'), and their values should be floats.

Returns:

A new Cuboid object constructed from the data.

Return type:

Cuboid

to_json()#

Serialize as a dictionary.

The dictionary contains the three box lengths Lx, Ly, and Lz.

Returns:

The serialized Cuboid.

Return type:

dict

wrap(positions)#

Wrap positions subject to periodic boundary conditions.

Three-dimensional periodic boundary conditions are applied to ensure the positions lie within the box. This is achieved by converting to fractional coordinates, bounding the fractional coordinates within \([0,1)\), then converting back to Cartesian coordinates.

Parameters:

positions (array_like) – Position vector(s).

Returns:

Wrapped position(s).

Return type:

numpy.ndarray