Getting volume from box lengths and angles#

Computing periodic-cell volume directly from edge lengths and crystallographic angles.

Added in version 1.0.0.

import numpy as np
import molsysmt as msm

MolSysMT uses lengths (a, b, c) and angles (alpha, beta, gamma), where alpha is between b and c, beta is between a and c, and gamma is between a and b. The function evaluates the closed-form triclinic-cell expression directly, avoiding precision loss from constructing an intermediate rounded box matrix.

lengths = [[2.0, 2.0, 3.0]] * msm.pyunitwizard.unit('nm')
angles = [[90.0, 90.0, 60.0]] * msm.pyunitwizard.unit('degrees')
volume = msm.pbc.get_volume_from_lengths_and_angles(lengths, angles)

expected = 6.0 * np.sqrt(3.0)
np.testing.assert_allclose(
    msm.pyunitwizard.get_value(volume, to_unit='nm**3'),
    [expected],
    rtol=0.0,
    atol=1.0e-12,
)
volume

The analytic result is 6*sqrt(3) nm^3. This example is part of MolSysMT’s Scientific Truth Suite rather than a cross-implementation parity check.

See also

Use molsysmt.pbc.get_volume_from_box() when a box matrix is already available.