relentless.model.Square#
- class relentless.model.Square(L)#
Square box.
A Square is a special type of
Rectanglewhere all vectors have the same length \(L\).- Parameters:
L (float) – The edge length of the square.
Methods
as_array([convention])Convert to array of lengths and tilt factor.
Make fractional coordinates from Cartesian coordinates.
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 of the region.
highlow- as_array(convention=None)#
Convert to array of lengths and tilt factor.
- Parameters:
convention ({'LAMMPS','HOOMD'}, optional) – Convention to use for the tilt factors. Default of
Nonewill use the convention for the box.- Returns:
An array containing
(Lx,Ly,xy)according to theconvention.- Return type:
- coordinate_to_fraction(r)#
Make fractional coordinates from Cartesian coordinates.
The Cartesian coordinates r are projected onto the two (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}) \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:
- 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:
- classmethod from_json(data)#
Deserialize from a dictionary.
- to_json()#
Serialize as a dictionary.
The dictionary contains the box length
L.- Returns:
The serialized Square.
- Return type:
- wrap(positions)#
Wrap positions subject to periodic boundary conditions.
Two-dimensional periodic boundary conditions are applied to ensure the
positionslie 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: