From 7331d0461dfd01293287c7979704edd673c13420 Mon Sep 17 00:00:00 2001 From: janbridley Date: Wed, 15 Jan 2025 21:58:00 -0500 Subject: [PATCH] Rename cell to box --- doc/source/quickstart.rst | 4 ++-- parsnip/parsnip.py | 12 ++++++------ tests/test_patterns.py | 11 +++++++++-- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/doc/source/quickstart.rst b/doc/source/quickstart.rst index 1baae62..f79f00f 100644 --- a/doc/source/quickstart.rst +++ b/doc/source/quickstart.rst @@ -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) diff --git a/parsnip/parsnip.py b/parsnip/parsnip.py index 12cb3b2..616a1fb 100644 --- a/parsnip/parsnip.py +++ b/parsnip/parsnip.py @@ -526,7 +526,7 @@ 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 @@ -534,7 +534,7 @@ def cell(self): .. 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. @@ -542,13 +542,13 @@ def cell(self): ------- 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) diff --git a/tests/test_patterns.py b/tests/test_patterns.py index d656a7d..f941e70 100644 --- a/tests/test_patterns.py +++ b/tests/test_patterns.py @@ -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, + )