# UnitCell¶

class UnitCell

An UnitCell represent the box containing the atoms, and its periodicity

A unit cell is represented by the cell matrix, containing the three cell vectors:

| a_x   b_x   c_x |
| a_y   b_y   c_y |
| a_z   b_z   c_z |

Public Types

enum CellShape

Possible shapes for the unit cell.

Values:

enumerator ORTHORHOMBIC

Orthorhombic cell, with the three angles equals to 90°

enumerator TRICLINIC

Triclinic cell, with any values for the angles.

enumerator INFINITE

Infinite cell, to use when there is no cell.

Public Functions

UnitCell()

Construct an INFINITE unit cell, with all lengths set to 0

UnitCell(Vector3D lengths)

Construct an ORTHORHOMBIC unit cell with the given cell lengths

UnitCell(Vector3D lengths, Vector3D angles)

Construct a unit cell with the given cell lengths and angles

If all lengths are set to 0, then the cell is INFINITE. If at least one length is not zero and all angles are 90.0, then the cell is ORTHORHOMBIC. Else a TRICLINIC cell is created.

UnitCell(Matrix3D matrix)

Construct a unit cell from a cell matrix.

If matrix contains only zeros, then an infinite cell is created. If only the diagonal of the matrix is non-zero, then the cell is ORTHORHOMBIC. Else a TRICLINIC cell is created. The matrix entries should be in Angstroms.

inline Matrix3D matrix() const

Get the cell matrix

inline CellShape shape() const

Get the cell shape

void set_shape(CellShape shape)

Set the cell shape to shape

Throws:

Error – if shape is ORTHORHOMBIC and some angles are not 90°, or if shape is INFINITE and some lengths are not 0.0.

Vector3D lengths() const

Get the lengths of the cell’s vectors, in angstroms.

Vector3D angles() const

Get the angles between the cell’s vectors in degrees

void set_lengths(Vector3D lengths)

Set the lengths of the cell’s vectors. The values should be in angstroms.

This function reset cell orientation!

After the call, the cell is aligned such that the first cell vector is along the x axis, and the second cell vector is in the xy plane.

Throws:

Error – if the cell shape is INFINITE.

void set_angles(Vector3D angles)

Set the angles between the cell’s vectors. The values should be in degrees.

This function reset cell orientation!

After the call, the cell is aligned such that the first cell vector is along the x axis, and the second cell vector is in the xy plane.

Throws:

Error – if the cell shape is not TRICLINIC.

double volume() const

Get the unit cell volume

Vector3D wrap(const Vector3D &vector) const

Wrap the vector in the unit cell, using periodic boundary conditions.

For an orthorhombic unit cell, this make sure that all the vector components are between -L/2 and L/2 where L is the corresponding cell length.