Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions freud/box.py
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,24 @@ def to_matrix(self):
]
)

def to_box_params(self):
r"""Returns the box lengths and tilt factors as a flat (6,) tuple.

The output from this method can be saved as a `GSD box <https://gsd.readthedocs.io/en/stable/schema-hoomd.html#chunk-configuration-box>`_.

Example::

>>> box = freud.box.Box.cube(L=10)
>>> box.to_box_params()
(10.0, 10.0, 10.0, 0.0, 0.0, 0.0)

Returns:
tuple:
The box extents along each axis and tilt factors
:math:`(L_x, L_y, L_z, xy, xz, yz)`.
"""
return (self.Lx, self.Ly, self.Lz, self.xy, self.xz, self.yz)

def to_box_lengths_and_angles(self):
r"""Return the box lengths and angles.

Expand Down
10 changes: 10 additions & 0 deletions tests/test_box_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,16 @@ def test_to_dict(self):
for k, v in box_dict.items():
npt.assert_allclose(v, box2[k])

def test_to_box_params(self):
box = freud.box.Box(2, 2, 2, 1, 0.5, 0.1)
npt.assert_equal(box.to_box_params(), [*box.to_dict().values()][:6])
npt.assert_equal(
box.to_box_params(), [box.Lx, box.Ly, box.Lz, box.xy, box.xz, box.yz]
)

box2 = freud.box.Box.cube(0.001)
npt.assert_allclose(box2.to_box_params(), [0.001, 0.001, 0.001, 0, 0, 0])

def test_from_box(self):
"""Test various methods of initializing a box"""
box = freud.box.Box(2, 2, 2, 1, 0.5, 0.1)
Expand Down