is_cell_orthogonal

mdcraft.lib.cell.is_cell_orthogonal(box_size: np.ndarray[float_t] | 'unit.Quantity' | Q_, /, *, n_dimensions: int | None = None, _reduce: bool = True) bool[source]

Checks if a unit cell is orthogonal.

Parameters:
box_sizenumpy.ndarray, openmm.unit.Quantity, or pint.Quantity, positional-only

Dimensions \((L_x,L_y[,L_z])\), lattice parameters \((a,b[,c,\alpha,\beta],\gamma)\), or box vectors \((\mathbf{a};\mathbf{b}[;\mathbf{c}])\).

Note

Lattice parameters should always be provided in an array without explicit units.

Shapes: \((d,)\) for dimensions, \((3,)\) (2D) or \((6,)\) (3D) for lattice parameters, or \((d,d)\) for box vectors.

Reference units: \(\mathrm{nm}\) for lengths and degrees (\(^\circ\)) for angles.

n_dimensionsint, keyword-only, optional

Dimensionality of the box \(d\). Only used when box_size has shape \((3,)\).

Valid values: 2 or 3.

Returns:
is_orthogonalbool

Whether the box is orthogonal.

Examples

If dimensions are provided, the box is naturally orthogonal:

>>> is_cell_orthogonal(np.array((3.0, 4.0)))
True
>>> is_cell_orthogonal(np.array((3.0, 4.0, 5.0)))
True

If lattice parameters are provided, the box is orthogonal if the angles are all \(90^\circ\):

>>> is_cell_orthogonal(np.array((3.0, 4.0, 90.0)))
True
>>> is_cell_orthogonal(np.array((3.0, 4.0, 5.0, 90.0, 90.0, 90.0)))
True
>>> is_cell_orthogonal(np.array((3.0, 4.0, 5.0, 45.0, 45.0, 45.0)))
False

If box vectors are provided, the box is orthogonal if all off-diagonal components are zero:

>>> is_cell_orthogonal(np.array(((3.0, 0.0), (0.0, 4.0))))
True
>>> is_cell_orthogonal(
...     np.array(
...         ((3.0, 0.0, 0.0), (0.0, 4.0, 0.0), (0.0, 0.0, 5.0))
...     )
... )
True
>>> is_cell_orthogonal(
...     np.array(
...         ((3.0, 0.0, 0.0), (0.0, 4.0, 0.1), (0.1, 0.1, 5.0))
...     )
... )
False

Box vectors are automatically reduced to their restricted forms before checking for orthogonality:

>>> box_vectors = np.array(
...     (
...         (9 / np.sqrt(11), 3 / np.sqrt(11), 3 / np.sqrt(11)),
...         (-4 / np.sqrt(6), 8 / np.sqrt(6), 4 / np.sqrt(6)),
...         (5 / np.sqrt(66), 20 / np.sqrt(66), -35 / np.sqrt(66))
...     )
... )
>>> is_cell_orthogonal(box_vectors)
True