# Box Module¶

Contains data structures for simulation boxes.

## Simulation Box¶

class freud.box.Box(*args, **kwargs)[source]

The freud Box class for simulation boxes.

Module author: Richmond Newman <newmanrs@umich.edu>

Changed in version 0.7.0: Added box periodicity interface

Parameters: Lx (float) – Length of side x Ly (float) – Length of side y Lz (float) – Length of side z xy (float) – Tilt of xy plane xz (float) – Tilt of xz plane yz (float) – Tilt of yz plane is2D (bool) – Specify that this box is 2-dimensional, default is 3-dimensional.
L

Return the lengths of the box as a tuple (x, y, z)

Linv

Return the inverse lengths of the box (1/Lx, 1/Ly, 1/Lz)

Returns: dimensions of the box as (1/Lx, 1/Ly, 1/Lz) (float, float, float)
Lx

Length of the x-dimension of the box

Getter: Returns this box’s x-dimension length Sets this box’s x-dimension length float
Ly

Length of the y-dimension of the box

Getter: Returns this box’s y-dimension length Sets this box’s y-dimension length float
Lz

Length of the z-dimension of the box

Getter: Returns this box’s z-dimension length Sets this box’s z-dimension length float
classmethod cube(L)[source]

Construct a cubic box with equal lengths.

Parameters: L (float) – The edge length
dimensions

Number of dimensions of this box (only 2 or 3 are supported)

Getter: Returns this box’s number of dimensions Sets this box’s number of dimensions int
classmethod from_box(box)[source]

Initialize a box instance from another box instance.

classmethod from_matrix(boxMatrix, dimensions=None)[source]

Initialize a box instance from a box matrix.

getCoordinates(self, f)

Convert a vector of relative box coordinates (each in [0..1]) into absolute coordinates

Parameters: f (list[float, float, float]) – list[fx, fy, fz] list[x, y, z] list[float, float, float]
getL(self)

Return the lengths of the box as a tuple (x, y, z)

Returns: dimensions of the box as (x, y, z) (float, float, float)
getLatticeVector(self, i)

Get the lattice vector with index i

Parameters: i (unsigned int) – Index (0<=i
getLinv(self)

Return the inverse lengths of the box (1/Lx, 1/Ly, 1/Lz)

Returns: dimensions of the box as (1/Lx, 1/Ly, 1/Lz) (float, float, float)
getLx(self)

Length of the x-dimension of the box

Returns: This box’s x-dimension length float
getLy(self)

Length of the y-dimension of the box

Returns: This box’s y-dimension length float
getLz(self)

Length of the z-dimension of the box

Returns: This box’s z-dimension length float
getPeriodic(self)

Get the box’s periodicity in each dimension

Returns: list of periodic attributes in x, y, z list[bool, bool, bool]
getPeriodicX(self)

Get the box periodicity in the x direction

Returns: True if periodic, False if not bool
getPeriodicY(self)

Get the box periodicity in the y direction

Returns: True if periodic, False if not bool
getPeriodicZ(self)

Get the box periodicity in the z direction

Returns: True if periodic, False if not bool
getTiltFactorXY(self)

Return the tilt factor xy

Returns: xy tilt factor float
getTiltFactorXZ(self)

Return the tilt factor xz

Returns: xz tilt factor float
getTiltFactorYZ(self)

Return the tilt factor yz

Returns: yz tilt factor float
getVolume(self)

Return the box volume (area in 2D)

Returns: box volume float
is2D(self)

Return if box is 2D (True) or 3D (False)

Returns: True if 2D, False if 3D bool
makeCoordinates(self, f)

Convert fractional coordinates into real coordinates

Parameters: f (numpy.ndarray([x, y, z], dtype=numpy.float32)) – Fractional coordinates between 0 and 1 within parallelpipedal box A vector inside the box corresponding to f
makeFraction(self, vec)

Convert fractional coordinates into real coordinates

Parameters: vec (numpy.ndarray([x, y, z], dtype=numpy.float32)) – Coordinates within parallelpipedal box Fractional vector inside the box corresponding to f
periodic

Box periodicity in each dimension

Getter: Returns this box’s periodicity in each dimension (True if periodic, False if not) Set this box’s periodicity in each dimension list[bool, bool, bool]
set2D(self, val)

Set the dimensionality to 2D (True) or 3D (False)

Parameters: val (bool) – 2D=True, 3D=False
setL(self, L)

Set all side lengths of box to L

Parameters: L (float) – Side length of box
setPeriodic(self, x, y, z)

Set the box’s periodicity in each dimension

Parameters: x (bool) – True if periodic in x, False if not y (bool) – True if periodic in y, False if not z (bool) – True if periodic in z, False if not
setPeriodicX(self, val)

Set the box periodicity in the x direction

Parameters: val (bool) – True if periodic, False if not
setPeriodicY(self, val)

Set the box periodicity in the y direction

Parameters: val (bool) – True if periodic, False if not
setPeriodicZ(self, val)

Set the box periodicity in the z direction

Parameters: val (bool) – True if periodic, False if not
classmethod square(L)[source]

Construct a 2-dimensional (square) box with equal lengths.

Parameters: L (float) – The edge length
to_matrix()[source]

Returns the box matrix (3x3).

Returns: box matrix list of lists, shape 3x3
to_tuple()[source]

Returns the box as named tuple.

Returns: box parameters namedtuple
unwrap(self, vecs, imgs)

Wrap a given array of vectors back into the box from python

Parameters: vecs – numpy array of vectors (Nx3) (or just 3 elements) to wrap vecs returned in place (nothing returned)
volume

Return the box volume (area in 2D)

Returns: box volume float
wrap(self, vecs)

Wrap a given array of vectors back into the box from python

Parameters: vecs – numpy array of vectors (Nx3) (or just 3 elements) to wrap vecs returned in place (nothing returned)
xy

Tilt factor xy of the box

Returns: xy tilt factor float
xz

Tilt factor xz of the box

Returns: xz tilt factor float
yz

Tilt factor yz of the box

Returns: yz tilt factor float