From d09a89c65fd2864b507c49be5b8f95b3e7d1092e Mon Sep 17 00:00:00 2001 From: stevenhua0320 Date: Mon, 23 Feb 2026 15:37:44 -0500 Subject: [PATCH] chore: deprecate abcABG and readStr method --- news/deprecate-lattice-readstr-method.rst | 25 +++++++++++++++++++++++ src/diffpy/structure/lattice.py | 15 ++++++++++++++ src/diffpy/structure/pdffitstructure.py | 9 ++++++++ tests/test_lattice.py | 6 +++--- tests/test_p_discus.py | 2 +- tests/test_structure.py | 11 +++++++++- tests/test_supercell.py | 4 ++-- 7 files changed, 65 insertions(+), 7 deletions(-) create mode 100644 news/deprecate-lattice-readstr-method.rst diff --git a/news/deprecate-lattice-readstr-method.rst b/news/deprecate-lattice-readstr-method.rst new file mode 100644 index 00000000..31ff9ff4 --- /dev/null +++ b/news/deprecate-lattice-readstr-method.rst @@ -0,0 +1,25 @@ +**Added:** + +* Added ``read_structure`` method into ``PDFFitStructure`` class +* Added ``cell_parms`` method into ``Lattice`` class + +**Changed:** + +* + +**Deprecated:** + +* Deprecated ``readStr`` method in ``PDFFitStructure`` class for removal in version 4.0.0 +* Deprecated ``abcABG`` method in ``Lattice`` class for removal in version 4.0.0 + +**Removed:** + +* + +**Fixed:** + +* + +**Security:** + +* diff --git a/src/diffpy/structure/lattice.py b/src/diffpy/structure/lattice.py index 76fe41d1..bdef059a 100644 --- a/src/diffpy/structure/lattice.py +++ b/src/diffpy/structure/lattice.py @@ -43,6 +43,12 @@ "set_new_latt_base_vec", removal_version, ) +abcABG_deprecation_msg = build_deprecation_message( + base, + "abcABG", + "cell_parms", + removal_version, +) # Helper Functions ----------------------------------------------------------- @@ -559,7 +565,16 @@ def set_new_latt_base_vec(self, base): ) return + @deprecated(abcABG_deprecation_msg) def abcABG(self): + """'diffpy.structure.Lattice.abcABG' is deprecated and will be + removed in version 4.0.0. + + Please use 'diffpy.structure.Lattice.cell_parms' instead. + """ + return self.cell_parms() + + def cell_parms(self): """Return the cell parameters in the standard setting. Returns diff --git a/src/diffpy/structure/pdffitstructure.py b/src/diffpy/structure/pdffitstructure.py index 9cad2d2d..7a49d28e 100644 --- a/src/diffpy/structure/pdffitstructure.py +++ b/src/diffpy/structure/pdffitstructure.py @@ -79,6 +79,15 @@ def read(self, filename, format="auto"): return p def readStr(self, s, format="auto"): + """'diffpy.structure.PDFFitStructure.readStr' is deprecated and + will be removed in version 4.0.0. + + Please use 'diffpy.structure.PDFFitStructure.read_structure' + instead. + """ + return self.read_structure(s, format) + + def read_structure(self, s, format="auto"): """Same as `Structure.readStr`, but update `spcgr` value in `self.pdffit` when parser can get spacegroup. diff --git a/tests/test_lattice.py b/tests/test_lattice.py index 48415352..c1cc80c8 100644 --- a/tests/test_lattice.py +++ b/tests/test_lattice.py @@ -50,7 +50,7 @@ def test___init__(self): L2 = Lattice(base=L0.base) self.assertTrue(numpy.array_equal(L0.base, L2.base)) self.assertTrue(numpy.array_equal(L0.isotropicunit, L2.isotropicunit)) - L3 = Lattice(*L0.abcABG(), baserot=L0.baserot) + L3 = Lattice(*L0.cell_parms(), baserot=L0.baserot) self.assertTrue(numpy.allclose(L0.base, L3.base)) self.assertTrue(numpy.allclose(L0.isotropicunit, L3.isotropicunit)) return @@ -229,10 +229,10 @@ def test_set_lat_base(self): def test_reciprocal(self): """Check calculation of reciprocal lattice.""" r1 = self.lattice.reciprocal() - self.assertEqual((1, 1, 1, 90, 90, 90), r1.abcABG()) + self.assertEqual((1, 1, 1, 90, 90, 90), r1.cell_parms()) L2 = Lattice(2, 4, 8, 90, 90, 90) r2 = L2.reciprocal() - self.assertEqual((0.5, 0.25, 0.125, 90, 90, 90), r2.abcABG()) + self.assertEqual((0.5, 0.25, 0.125, 90, 90, 90), r2.cell_parms()) rr2 = r2.reciprocal() self.assertTrue(numpy.array_equal(L2.base, rr2.base)) return diff --git a/tests/test_p_discus.py b/tests/test_p_discus.py index 1bfd7595..852acdfa 100644 --- a/tests/test_p_discus.py +++ b/tests/test_p_discus.py @@ -46,7 +46,7 @@ def test_read_discus_Ni(self): self.assertEqual("Fm-3m", stru.pdffit["spcgr"]) # cell record abcABG = (3.52, 3.52, 3.52, 90.0, 90.0, 90.0) - self.assertEqual(abcABG, stru.lattice.abcABG()) + self.assertEqual(abcABG, stru.lattice.cell_parms()) # ncell self.assertEqual([1, 1, 1, 4], stru.pdffit["ncell"]) self.assertEqual(4, len(stru)) diff --git a/tests/test_structure.py b/tests/test_structure.py index c5b17ce5..50445157 100644 --- a/tests/test_structure.py +++ b/tests/test_structure.py @@ -420,7 +420,7 @@ def test___imul__(self): self.assertEqual(0, len(self.stru)) return - def test__get_lattice(self): + def test__get_lattice_dep(self): """Check Structure._get_lattice()""" lat = Lattice() stru = Structure() @@ -429,6 +429,15 @@ def test__get_lattice(self): self.assertTrue(lat is stru2.lattice) return + def test__get_lattice(self): + """Check Structure._get_lattice()""" + lat = Lattice() + stru = Structure() + self.assertEqual((1, 1, 1, 90, 90, 90), stru.lattice.cell_parms()) + stru2 = Structure(lattice=lat) + self.assertTrue(lat is stru2.lattice) + return + def test__set_lattice(self): """Check Structure._set_lattice()""" lat = Lattice() diff --git a/tests/test_supercell.py b/tests/test_supercell.py index d20434ca..1b476c46 100644 --- a/tests/test_supercell.py +++ b/tests/test_supercell.py @@ -59,8 +59,8 @@ def test_ni_supercell(self): """Check supercell expansion for Ni.""" ni_123 = supercell(self.stru_ni, (1, 2, 3)) self.assertEqual(6 * len(self.stru_ni), len(ni_123)) - a, b, c = self.stru_ni.lattice.abcABG()[:3] - a1, b2, c3 = ni_123.lattice.abcABG()[:3] + a, b, c = self.stru_ni.lattice.cell_parms()[:3] + a1, b2, c3 = ni_123.lattice.cell_parms()[:3] self.assertAlmostEqual(a, a1, 8) self.assertAlmostEqual(b * 2, b2, 8) self.assertAlmostEqual(c * 3, c3, 8)