From 99575aaf9a3b5f8a6a2f840ddbdb59b9035cb0a0 Mon Sep 17 00:00:00 2001 From: stevenhua0320 Date: Tue, 24 Feb 2026 12:47:48 -0500 Subject: [PATCH 1/2] chore: deprecate methods in --- news/deprecate-symmetryutilities-1.rst | 25 +++++++++++++++ src/diffpy/structure/pdffitstructure.py | 11 +++++++ src/diffpy/structure/symmetryutilities.py | 38 ++++++++++++++++++++++- tests/test_symmetryutilities.py | 35 +++++++++++++++++++++ 4 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 news/deprecate-symmetryutilities-1.rst diff --git a/news/deprecate-symmetryutilities-1.rst b/news/deprecate-symmetryutilities-1.rst new file mode 100644 index 0000000..a6ccd9b --- /dev/null +++ b/news/deprecate-symmetryutilities-1.rst @@ -0,0 +1,25 @@ +**Added:** + +* Added ``is_space_group_lat_par`` method in ``symmetryutilities.py`` +* Added ``is_constant_formula`` method in ``symmetryutilities.py`` + +**Changed:** + +* + +**Deprecated:** + +* Deprecated ``isSpaceGroupLatPar`` method in ``symmetryutilities.py`` for removal in version 4.0.0 +* Deprecated ``isconstantFormula`` method in ``symmetryutilities.py`` for removal in version 4.0.0 + +**Removed:** + +* + +**Fixed:** + +* + +**Security:** + +* diff --git a/src/diffpy/structure/pdffitstructure.py b/src/diffpy/structure/pdffitstructure.py index 7a49d28..23f4035 100644 --- a/src/diffpy/structure/pdffitstructure.py +++ b/src/diffpy/structure/pdffitstructure.py @@ -16,6 +16,16 @@ from diffpy.structure.structure import Structure +from diffpy.utils._deprecator import build_deprecation_message, deprecated + +base = "diffpy.structure.PDFFitStructure" +removal_version = "4.0.0" +readStr_deprecation_msg = build_deprecation_message( + base, + "isSpaceGroupLatPar", + "is_space_group_lat_par", + removal_version, +) # ---------------------------------------------------------------------------- @@ -78,6 +88,7 @@ def read(self, filename, format="auto"): self.pdffit["spcgr"] = sg.short_name return p + @deprecated(readStr_deprecation_msg) def readStr(self, s, format="auto"): """'diffpy.structure.PDFFitStructure.readStr' is deprecated and will be removed in version 4.0.0. diff --git a/src/diffpy/structure/symmetryutilities.py b/src/diffpy/structure/symmetryutilities.py index d255666..edf81fd 100644 --- a/src/diffpy/structure/symmetryutilities.py +++ b/src/diffpy/structure/symmetryutilities.py @@ -32,6 +32,22 @@ import numpy from diffpy.structure.structureerrors import SymmetryError +from diffpy.utils._deprecator import build_deprecation_message, deprecated + +base = "diffpy.structure" +removal_version = "4.0.0" +isSpaceGroupLatPar_deprecation_msg = build_deprecation_message( + base, + "isSpaceGroupLatPar", + "is_space_group_lat_par", + removal_version, +) +isconstantFormula_deprecation_msg = build_deprecation_message( + base, + "isconstantFormula", + "is_constant_formula", + removal_version, +) # Constants ------------------------------------------------------------------ @@ -42,7 +58,17 @@ # ---------------------------------------------------------------------------- +@deprecated(isSpaceGroupLatPar_deprecation_msg) def isSpaceGroupLatPar(spacegroup, a, b, c, alpha, beta, gamma): + """'diffpy.structure.isSpaceGroupLatPar' is deprecated and will be + removed in version 4.0.0. + + Please use 'diffpy.structure.is_space_group_lat_par' instead. + """ + return is_space_group_lat_par(spacegroup, a, b, c, alpha, beta, gamma) + + +def is_space_group_lat_par(spacegroup, a, b, c, alpha, beta, gamma): """Check if space group allows passed lattice parameters. Parameters @@ -110,7 +136,17 @@ def check_cubic(): _rx_constant_formula = re.compile(r"[-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)??(/[-+]?\d+)?$") +@deprecated(isconstantFormula_deprecation_msg) def isconstantFormula(s): + """'diffpy.structure.isconstantFormula' is deprecated and will be + removed in version 4.0.0. + + Please use 'diffpy.structure.is_constant_formula' instead. + """ + return is_constant_formula(s) + + +def is_constant_formula(s): """Check if formula string is constant. Parameters @@ -837,7 +873,7 @@ def pruneFormulaDictionary(eqdict): """ pruned = {} for smb, eq in eqdict.items(): - if not isconstantFormula(eq): + if not is_constant_formula(eq): pruned[smb] = eq return pruned diff --git a/tests/test_symmetryutilities.py b/tests/test_symmetryutilities.py index 5002a29..caad3a8 100644 --- a/tests/test_symmetryutilities.py +++ b/tests/test_symmetryutilities.py @@ -27,6 +27,8 @@ SymmetryConstraints, _Position2Tuple, expandPosition, + is_constant_formula, + is_space_group_lat_par, isconstantFormula, isSpaceGroupLatPar, pruneFormulaDictionary, @@ -67,6 +69,30 @@ def test_isSpaceGroupLatPar(self): self.assertTrue(isSpaceGroupLatPar(cubic, 3, 3, 3, 90, 90, 90)) return + def test_is_space_group_lat_par(self): + """Check isSpaceGroupLatPar()""" + triclinic = GetSpaceGroup("P1") + monoclinic = GetSpaceGroup("P2") + orthorhombic = GetSpaceGroup("P222") + tetragonal = GetSpaceGroup("P4") + trigonal = GetSpaceGroup("P3") + hexagonal = GetSpaceGroup("P6") + cubic = GetSpaceGroup("P23") + self.assertTrue(is_space_group_lat_par(triclinic, 1, 2, 3, 40, 50, 60)) + self.assertFalse(is_space_group_lat_par(monoclinic, 1, 2, 3, 40, 50, 60)) + self.assertTrue(is_space_group_lat_par(monoclinic, 1, 2, 3, 90, 50, 90)) + self.assertFalse(is_space_group_lat_par(orthorhombic, 1, 2, 3, 90, 50, 90)) + self.assertTrue(is_space_group_lat_par(orthorhombic, 1, 2, 3, 90, 90, 90)) + self.assertFalse(is_space_group_lat_par(tetragonal, 1, 2, 3, 90, 90, 90)) + self.assertTrue(is_space_group_lat_par(tetragonal, 2, 2, 3, 90, 90, 90)) + self.assertFalse(is_space_group_lat_par(trigonal, 2, 2, 3, 90, 90, 90)) + self.assertTrue(is_space_group_lat_par(trigonal, 2, 2, 2, 80, 80, 80)) + self.assertFalse(is_space_group_lat_par(hexagonal, 2, 2, 2, 80, 80, 80)) + self.assertTrue(is_space_group_lat_par(hexagonal, 2, 2, 3, 90, 90, 120)) + self.assertFalse(is_space_group_lat_par(cubic, 2, 2, 3, 90, 90, 120)) + self.assertTrue(is_space_group_lat_par(cubic, 3, 3, 3, 90, 90, 90)) + return + def test_sgtbx_spacegroup_aliases(self): """Check GetSpaceGroup for non-standard aliases from sgtbx.""" self.assertIs(GetSpaceGroup("Fm3m"), GetSpaceGroup(225)) @@ -100,6 +126,15 @@ def test_isconstantFormula(self): self.assertTrue(isconstantFormula("+13/ 9")) return + def test_is_constant_formula(self): + """Check isconstantFormula()""" + self.assertFalse(is_constant_formula("x-y+z")) + self.assertTrue(is_constant_formula("6.023e23")) + self.assertTrue(is_constant_formula("22/7")) + self.assertTrue(is_constant_formula("- 22/7")) + self.assertTrue(is_constant_formula("+13/ 9")) + return + # End of class TestRoutines From 9a4195a134581b955159d6493b2ec0ef8c01a713 Mon Sep 17 00:00:00 2001 From: stevenhua0320 Date: Tue, 24 Feb 2026 15:12:54 -0500 Subject: [PATCH 2/2] fix: fix deprecation message and rename the snakecase method to be consistent. --- news/deprecate-symmetryutilities-1.rst | 2 +- src/diffpy/structure/pdffitstructure.py | 4 ++-- src/diffpy/structure/symmetryutilities.py | 8 +++---- tests/test_symmetryutilities.py | 28 +++++++++++------------ 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/news/deprecate-symmetryutilities-1.rst b/news/deprecate-symmetryutilities-1.rst index a6ccd9b..36cde7f 100644 --- a/news/deprecate-symmetryutilities-1.rst +++ b/news/deprecate-symmetryutilities-1.rst @@ -1,6 +1,6 @@ **Added:** -* Added ``is_space_group_lat_par`` method in ``symmetryutilities.py`` +* Added ``is_space_group_latt_parms`` method in ``symmetryutilities.py`` * Added ``is_constant_formula`` method in ``symmetryutilities.py`` **Changed:** diff --git a/src/diffpy/structure/pdffitstructure.py b/src/diffpy/structure/pdffitstructure.py index 23f4035..2ee1f7a 100644 --- a/src/diffpy/structure/pdffitstructure.py +++ b/src/diffpy/structure/pdffitstructure.py @@ -22,8 +22,8 @@ removal_version = "4.0.0" readStr_deprecation_msg = build_deprecation_message( base, - "isSpaceGroupLatPar", - "is_space_group_lat_par", + "readStr", + "read_structure", removal_version, ) diff --git a/src/diffpy/structure/symmetryutilities.py b/src/diffpy/structure/symmetryutilities.py index edf81fd..57d6b43 100644 --- a/src/diffpy/structure/symmetryutilities.py +++ b/src/diffpy/structure/symmetryutilities.py @@ -39,7 +39,7 @@ isSpaceGroupLatPar_deprecation_msg = build_deprecation_message( base, "isSpaceGroupLatPar", - "is_space_group_lat_par", + "is_space_group_latt_parms", removal_version, ) isconstantFormula_deprecation_msg = build_deprecation_message( @@ -63,12 +63,12 @@ def isSpaceGroupLatPar(spacegroup, a, b, c, alpha, beta, gamma): """'diffpy.structure.isSpaceGroupLatPar' is deprecated and will be removed in version 4.0.0. - Please use 'diffpy.structure.is_space_group_lat_par' instead. + Please use 'diffpy.structure.is_space_group_latt_parms' instead. """ - return is_space_group_lat_par(spacegroup, a, b, c, alpha, beta, gamma) + return is_space_group_latt_parms(spacegroup, a, b, c, alpha, beta, gamma) -def is_space_group_lat_par(spacegroup, a, b, c, alpha, beta, gamma): +def is_space_group_latt_parms(spacegroup, a, b, c, alpha, beta, gamma): """Check if space group allows passed lattice parameters. Parameters diff --git a/tests/test_symmetryutilities.py b/tests/test_symmetryutilities.py index caad3a8..fabe40e 100644 --- a/tests/test_symmetryutilities.py +++ b/tests/test_symmetryutilities.py @@ -28,7 +28,7 @@ _Position2Tuple, expandPosition, is_constant_formula, - is_space_group_lat_par, + is_space_group_latt_parms, isconstantFormula, isSpaceGroupLatPar, pruneFormulaDictionary, @@ -78,19 +78,19 @@ def test_is_space_group_lat_par(self): trigonal = GetSpaceGroup("P3") hexagonal = GetSpaceGroup("P6") cubic = GetSpaceGroup("P23") - self.assertTrue(is_space_group_lat_par(triclinic, 1, 2, 3, 40, 50, 60)) - self.assertFalse(is_space_group_lat_par(monoclinic, 1, 2, 3, 40, 50, 60)) - self.assertTrue(is_space_group_lat_par(monoclinic, 1, 2, 3, 90, 50, 90)) - self.assertFalse(is_space_group_lat_par(orthorhombic, 1, 2, 3, 90, 50, 90)) - self.assertTrue(is_space_group_lat_par(orthorhombic, 1, 2, 3, 90, 90, 90)) - self.assertFalse(is_space_group_lat_par(tetragonal, 1, 2, 3, 90, 90, 90)) - self.assertTrue(is_space_group_lat_par(tetragonal, 2, 2, 3, 90, 90, 90)) - self.assertFalse(is_space_group_lat_par(trigonal, 2, 2, 3, 90, 90, 90)) - self.assertTrue(is_space_group_lat_par(trigonal, 2, 2, 2, 80, 80, 80)) - self.assertFalse(is_space_group_lat_par(hexagonal, 2, 2, 2, 80, 80, 80)) - self.assertTrue(is_space_group_lat_par(hexagonal, 2, 2, 3, 90, 90, 120)) - self.assertFalse(is_space_group_lat_par(cubic, 2, 2, 3, 90, 90, 120)) - self.assertTrue(is_space_group_lat_par(cubic, 3, 3, 3, 90, 90, 90)) + self.assertTrue(is_space_group_latt_parms(triclinic, 1, 2, 3, 40, 50, 60)) + self.assertFalse(is_space_group_latt_parms(monoclinic, 1, 2, 3, 40, 50, 60)) + self.assertTrue(is_space_group_latt_parms(monoclinic, 1, 2, 3, 90, 50, 90)) + self.assertFalse(is_space_group_latt_parms(orthorhombic, 1, 2, 3, 90, 50, 90)) + self.assertTrue(is_space_group_latt_parms(orthorhombic, 1, 2, 3, 90, 90, 90)) + self.assertFalse(is_space_group_latt_parms(tetragonal, 1, 2, 3, 90, 90, 90)) + self.assertTrue(is_space_group_latt_parms(tetragonal, 2, 2, 3, 90, 90, 90)) + self.assertFalse(is_space_group_latt_parms(trigonal, 2, 2, 3, 90, 90, 90)) + self.assertTrue(is_space_group_latt_parms(trigonal, 2, 2, 2, 80, 80, 80)) + self.assertFalse(is_space_group_latt_parms(hexagonal, 2, 2, 2, 80, 80, 80)) + self.assertTrue(is_space_group_latt_parms(hexagonal, 2, 2, 3, 90, 90, 120)) + self.assertFalse(is_space_group_latt_parms(cubic, 2, 2, 3, 90, 90, 120)) + self.assertTrue(is_space_group_latt_parms(cubic, 3, 3, 3, 90, 90, 90)) return def test_sgtbx_spacegroup_aliases(self):