Skip to content

Commit

Permalink
Rename cell to box
Browse files Browse the repository at this point in the history
  • Loading branch information
janbridley committed Jan 16, 2025
1 parent 7ae4ff4 commit 7331d04
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
4 changes: 2 additions & 2 deletions doc/source/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ Once `freud`_ is installed, crystal structures can be easily replicated!
.. doctest-requires:: freud

>>> import freud
>>> box = freud.Box(*cif.cell)
>>> box = freud.Box(*cif.box)
>>> uc = freud.data.UnitCell(box, basis_positions=pos)
>>> box, pos = uc.generate_system(num_replicas=2)
>>> assert len(pos) == 4 * 2**3
>>> np.testing.assert_allclose(box.L / 2, cif.cell[:3], atol=1e-15)
>>> np.testing.assert_allclose(box.L / 2, 3.6, atol=1e-15)
12 changes: 6 additions & 6 deletions parsnip/parsnip.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,29 +526,29 @@ def cast_values(self, cast: bool):
self._cast_values = cast

@property
def cell(self):
def box(self):
"""Read the unit cell as a `freud`_ or HOOMD `box-like`_ object.
.. _`box-like`: https://hoomd-blue.readthedocs.io/en/v5.0.0/hoomd/module-box.html#hoomd.box.box_like
.. _`freud`: https://freud.readthedocs.io/en/latest/gettingstarted/examples/module_intros/box.Box.html
.. important::
``cif.cell`` returns box extents and tilt factors, while
``cif.box`` returns box extents and tilt factors, while
``CifFile.read_cell_params`` returns unit cell vector lengths and angles.
See the `box-like`_ documentation linked above for more details.
Example
-------
This method provides a convinient interface to create box objects.
>>> cell = cif.cell
>>> print(cell)
>>> box = cif.box
>>> print(box)
(3.6, 3.6, 3.6, 0.0, 0.0, 0.0)
>>> import freud, hoomd # doctest: +SKIP
>>> freud.Box(*cell) # doctest: +SKIP
>>> freud.Box(*box) # doctest: +SKIP
freud.box.Box(Lx=3.6, Ly=3.6, Lz=3.6, xy=0, xz=0, yz=0, ...)
>>> hoomd.Box(*cell) # doctest: +SKIP
>>> hoomd.Box(*box) # doctest: +SKIP
hoomd.box.Box(Lx=3.6, Ly=3.6, Lz=3.6, xy=0.0, xz=0.0, yz=0.0)
Expand Down
11 changes: 9 additions & 2 deletions tests/test_patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,16 @@ def test_box(cif_data):
)

freud_box = freud.Box.from_box_lengths_and_angles(*cif_box)
freud_box_2 = freud.Box(*cif_data.file.box)
parsnip_box = _box_from_lengths_and_angles(*cif_box)

np.testing.assert_allclose(parsnip_box[:3], freud_box.L, atol=1e-12)
np.testing.assert_allclose(parsnip_box[:3], freud_box.L, atol=1e-15)
np.testing.assert_allclose(
parsnip_box[3:], [freud_box.xy, freud_box.xz, freud_box.yz], atol=1e-12
parsnip_box[3:], [freud_box.xy, freud_box.xz, freud_box.yz], atol=1e-15
)
if "PDB" not in cif_data.filename:
np.testing.assert_allclose(
[*freud_box.L, freud_box.xy, freud_box.xz, freud_box.yz],
[*freud_box_2.L, freud_box_2.xy, freud_box_2.xz, freud_box_2.yz],
atol=1e-8,
)

0 comments on commit 7331d04

Please sign in to comment.