molsysmt.pbc.get_volume_from_lengths_and_angles#
- molsysmt.pbc.get_volume_from_lengths_and_angles(box_lengths, box_angles)[source]#
Computing box volume from lengths and angles.
- Parameters:
box_lengths (quantity) – Edge lengths (a, b, c).
box_angles (quantity) – Angles (alpha, beta, gamma).
- Returns:
Volume in cubic nanometers.
- Return type:
quantity
Notes
The volume is evaluated directly as
abc * sqrt(1 + 2 cos(alpha) cos(beta) cos(gamma) - cos(alpha)**2 - cos(beta)**2 - cos(gamma)**2).This avoids propagating the six-decimal matrix rounding performed by
molsysmt.pbc.get_box_from_lengths_and_angles().See also
molsysmt.pbc.get_volume_from_box()Computing the volume from a box matrix.
Examples
Computing the volume of a triclinic box with a 60-degree gamma angle:
>>> import numpy as np >>> import molsysmt as msm >>> 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) >>> value = msm.pyunitwizard.get_value(volume, to_unit='nm**3') >>> np.testing.assert_allclose(value, [6.0 * np.sqrt(3.0)], atol=1.0e-12)
User guide
See the User Guide tutorial for a worked example:
molsysmt.pbc.get_volume_from_lengths_and_angles().Added in version 1.0.0.