From f9035310cf51f6beb654369d377b58c847fed041 Mon Sep 17 00:00:00 2001 From: stevenhua0320 Date: Sun, 22 Feb 2026 15:55:58 -0500 Subject: [PATCH 1/3] chore: deprecate setLatPar and setLatBase method --- news/deprecate-lattice.rst | 25 +++++++ .../structure/expansion/supercell_mod.py | 2 +- src/diffpy/structure/lattice.py | 63 +++++++++++++--- src/diffpy/structure/parsers/p_discus.py | 2 +- src/diffpy/structure/parsers/p_pdb.py | 4 +- src/diffpy/structure/parsers/p_xcfg.py | 2 +- tests/test_lattice.py | 75 ++++++++++++++++--- 7 files changed, 148 insertions(+), 25 deletions(-) create mode 100644 news/deprecate-lattice.rst diff --git a/news/deprecate-lattice.rst b/news/deprecate-lattice.rst new file mode 100644 index 00000000..6b8c6740 --- /dev/null +++ b/news/deprecate-lattice.rst @@ -0,0 +1,25 @@ +**Added:** + +* Added ``set_lat_par`` method into ``Lattice`` class +* Added ``set_lar_base`` method into ``Lattice`` class + +**Changed:** + +* + +**Deprecated:** + +* Deprecated ``setLatPar`` method in ``Lattice`` class for removal in version 4.0.0 +* Deprecated ``setLatBase`` method in ``Lattice`` class for removal in version 4.0.0 + +**Removed:** + +* + +**Fixed:** + +* + +**Security:** + +* diff --git a/src/diffpy/structure/expansion/supercell_mod.py b/src/diffpy/structure/expansion/supercell_mod.py index 44d55408..a8f6fcdc 100644 --- a/src/diffpy/structure/expansion/supercell_mod.py +++ b/src/diffpy/structure/expansion/supercell_mod.py @@ -82,7 +82,7 @@ def supercell(S, mno): newS.__setitem__(slice(None), newAtoms, copy=False) # take care of lattice parameters - newS.lattice.setLatPar(a=mno[0] * S.lattice.a, b=mno[1] * S.lattice.b, c=mno[2] * S.lattice.c) + newS.lattice.set_lat_par(a=mno[0] * S.lattice.a, b=mno[1] * S.lattice.b, c=mno[2] * S.lattice.c) return newS diff --git a/src/diffpy/structure/lattice.py b/src/diffpy/structure/lattice.py index 73885e4f..78a18475 100644 --- a/src/diffpy/structure/lattice.py +++ b/src/diffpy/structure/lattice.py @@ -27,6 +27,22 @@ import numpy.linalg as numalg from diffpy.structure.structureerrors import LatticeError +from diffpy.utils._deprecator import build_deprecation_message, deprecated + +base = "diffpy.structure.Lattice" +removal_version = "4.0.0" +setLatPar_deprecation_msg = build_deprecation_message( + base, + "setLatPar", + "set_lat_par", + removal_version, +) +setLatBase_deprecation_msg = build_deprecation_message( + base, + "setLatBase", + "set_lat_base", + removal_version, +) # Helper Functions ----------------------------------------------------------- @@ -168,37 +184,37 @@ class Lattice(object): a = property( lambda self: self._a, - lambda self, value: self.setLatPar(a=value), + lambda self, value: self.set_lat_par(a=value), doc="The unit cell length *a*.", ) b = property( lambda self: self._b, - lambda self, value: self.setLatPar(b=value), + lambda self, value: self.set_lat_par(b=value), doc="The unit cell length *b*.", ) c = property( lambda self: self._c, - lambda self, value: self.setLatPar(c=value), + lambda self, value: self.set_lat_par(c=value), doc="The unit cell length *c*.", ) alpha = property( lambda self: self._alpha, - lambda self, value: self.setLatPar(alpha=value), + lambda self, value: self.set_lat_par(alpha=value), doc="The cell angle *alpha* in degrees.", ) beta = property( lambda self: self._beta, - lambda self, value: self.setLatPar(beta=value), + lambda self, value: self.set_lat_par(beta=value), doc="The cell angle *beta* in degrees.", ) gamma = property( lambda self: self._gamma, - lambda self, value: self.setLatPar(gamma=value), + lambda self, value: self.set_lat_par(gamma=value), doc="The cell angle *gamma* in degrees.", ) @@ -323,12 +339,12 @@ def __init__( # work out argument variants # Lattice() if not argset: - self.setLatPar(1.0, 1.0, 1.0, 90.0, 90.0, 90.0, baserot) + self.set_lat_par(1.0, 1.0, 1.0, 90.0, 90.0, 90.0, baserot) # Lattice(base=abc) elif base is not None: if len(argset) > 1: raise ValueError("'base' must be the only argument.") - self.setLatBase(base) + self.set_lat_base(base) # Lattice(lat) elif isinstance(a, Lattice): if len(argset) > 1: @@ -339,10 +355,10 @@ def __init__( abcabg = ("a", "b", "c", "alpha", "beta", "gamma") if not argset.issuperset(abcabg): raise ValueError("Provide all 6 cell parameters.") - self.setLatPar(a, b, c, alpha, beta, gamma, baserot=baserot) + self.set_lat_par(a, b, c, alpha, beta, gamma, baserot=baserot) return - def setLatPar( + def set_lat_par( self, a=None, b=None, @@ -441,7 +457,34 @@ def setLatPar( self.isotropicunit = _isotropicunit(self.recnormbase) return + @deprecated(setLatPar_deprecation_msg) + def setLatPar( + self, + a=None, + b=None, + c=None, + alpha=None, + beta=None, + gamma=None, + baserot=None, + ): + """This function has been deprecated and will be removed in + version 4.0.0. + + Please use diffpy.structure.Lattice.set_lat_par instead. + """ + return self.set_lat_par(a, b, c, alpha, beta, gamma, baserot) + + @deprecated(setLatBase_deprecation_msg) def setLatBase(self, base): + """This function has been deprecated and will be removed in + version 4.0.0. + + Please use diffpy.structure.Lattice.set_lat_base instead. + """ + return self.set_lat_base(base) + + def set_lat_base(self, base): """Set new base vectors for this lattice. This updates the cell lengths and cell angles according to the diff --git a/src/diffpy/structure/parsers/p_discus.py b/src/diffpy/structure/parsers/p_discus.py index 7dba1e96..d09f7ebe 100644 --- a/src/diffpy/structure/parsers/p_discus.py +++ b/src/diffpy/structure/parsers/p_discus.py @@ -201,7 +201,7 @@ def _parse_cell(self, words): words = self.line.replace(",", " ").split() latpars = [float(w) for w in words[1:7]] try: - self.stru.lattice.setLatPar(*latpars) + self.stru.lattice.set_lat_par(*latpars) except ZeroDivisionError: emsg = "%d: Invalid lattice parameters - zero cell volume" % self.nl raise StructureFormatError(emsg) diff --git a/src/diffpy/structure/parsers/p_pdb.py b/src/diffpy/structure/parsers/p_pdb.py index 8694dba1..31199f76 100644 --- a/src/diffpy/structure/parsers/p_pdb.py +++ b/src/diffpy/structure/parsers/p_pdb.py @@ -157,7 +157,7 @@ def parseLines(self, lines): alpha = float(line[33:40]) beta = float(line[40:47]) gamma = float(line[47:54]) - stru.lattice.setLatPar(a, b, c, alpha, beta, gamma) + stru.lattice.set_lat_par(a, b, c, alpha, beta, gamma) scale = numpy.transpose(stru.lattice.recbase) elif record == "SCALE1": sc = numpy.zeros((3, 3), dtype=float) @@ -171,7 +171,7 @@ def parseLines(self, lines): scaleU[2] = float(line[45:55]) base = numpy.transpose(numpy.linalg.inv(sc)) abcABGcryst = numpy.array(stru.lattice.abcABG()) - stru.lattice.setLatBase(base) + stru.lattice.set_lat_base(base) abcABGscale = numpy.array(stru.lattice.abcABG()) reldiff = numpy.fabs(1.0 - abcABGscale / abcABGcryst) if not numpy.all(reldiff < 1.0e-4): diff --git a/src/diffpy/structure/parsers/p_xcfg.py b/src/diffpy/structure/parsers/p_xcfg.py index 08c108a9..40cc7c82 100644 --- a/src/diffpy/structure/parsers/p_xcfg.py +++ b/src/diffpy/structure/parsers/p_xcfg.py @@ -253,7 +253,7 @@ def parseLines(self, lines): emsg = ("%d: auxiliary fields are " "not consistent with entry_count") % p_nl raise StructureFormatError(emsg) # define proper lattice - stru.lattice.setLatBase(xcfg_H0) + stru.lattice.set_lat_base(xcfg_H0) # here we are inside the data block p_element = None for line in ilines: diff --git a/tests/test_lattice.py b/tests/test_lattice.py index d9efff6f..98c4a28c 100644 --- a/tests/test_lattice.py +++ b/tests/test_lattice.py @@ -44,7 +44,7 @@ def test___init__(self): self.assertRaises(ValueError, Lattice, 1, 2, 3) self.assertRaises(ValueError, Lattice, 1, 2, 3, 80, 90) L0 = self.lattice - L0.setLatBase(L0.cartesian([[1, 1, 0], [0, 1, 1], [1, 0, 1]])) + L0.set_lat_base(L0.cartesian([[1, 1, 0], [0, 1, 1], [1, 0, 1]])) L1 = Lattice(L0) self.assertTrue(numpy.array_equal(L0.base, L1.base)) L2 = Lattice(base=L0.base) @@ -77,6 +77,28 @@ def cosd(x): self.assertAlmostEqual(cosd(120.0), dot(base[0], base[1]) / (1 * 2), self.places) return + def test_set_lat_par(self): + """Check calculation of standard unit cell vectors.""" + from math import cos, radians, sqrt + + from numpy import dot + + def norm(x): + return sqrt(sum([xi**2 for xi in x])) + + def cosd(x): + return cos(radians(x)) + + self.lattice.set_lat_par(1.0, 2.0, 3.0, 80, 100, 120) + base = self.lattice.base + self.assertAlmostEqual(1.0, norm(base[0]), self.places) + self.assertAlmostEqual(2.0, norm(base[1]), self.places) + self.assertAlmostEqual(3.0, norm(base[2]), self.places) + self.assertAlmostEqual(cosd(80.0), dot(base[1], base[2]) / (2 * 3), self.places) + self.assertAlmostEqual(cosd(100.0), dot(base[0], base[2]) / (1 * 3), self.places) + self.assertAlmostEqual(cosd(120.0), dot(base[0], base[1]) / (1 * 2), self.places) + return + def test_latpar_properties(self): """Check assignment to a, b, c, alpha, beta, gamma.""" lat = self.lattice @@ -152,9 +174,9 @@ def test_setLatBase(self): self.assertAlmostEqual(detR0, 1.0, self.places) # try if rotation matrix works self.assertEqual(numpy.all(base == self.lattice.base), True) - self.lattice.setLatPar(alpha=44, beta=66, gamma=88) + self.lattice.set_lat_par(alpha=44, beta=66, gamma=88) self.assertNotEqual(numpy.all(base == self.lattice.base), True) - self.lattice.setLatPar(alpha=60, beta=60, gamma=60) + self.lattice.set_lat_par(alpha=60, beta=60, gamma=60) self.assertTrue(numpy.allclose(base[0], self.lattice.base[0])) self.assertTrue(numpy.allclose(base[1], self.lattice.base[1])) self.assertTrue(numpy.allclose(base[2], self.lattice.base[2])) @@ -171,6 +193,39 @@ def test_setLatBase(self): ) return + def test_set_lat_base(self): + """Check calculation of unit cell rotation.""" + base = numpy.array([[1.0, 1.0, 0.0], [0.0, 1.0, 1.0], [1.0, 0.0, 1.0]]) + self.lattice.set_lat_base(base) + self.assertAlmostEqual(self.lattice.a, numpy.sqrt(2.0), self.places) + self.assertAlmostEqual(self.lattice.b, numpy.sqrt(2.0), self.places) + self.assertAlmostEqual(self.lattice.c, numpy.sqrt(2.0), self.places) + self.assertAlmostEqual(self.lattice.alpha, 60.0, self.places) + self.assertAlmostEqual(self.lattice.beta, 60.0, self.places) + self.assertAlmostEqual(self.lattice.gamma, 60.0, self.places) + detR0 = numalg.det(self.lattice.baserot) + self.assertAlmostEqual(detR0, 1.0, self.places) + # try if rotation matrix works + self.assertEqual(numpy.all(base == self.lattice.base), True) + self.lattice.set_lat_par(alpha=44, beta=66, gamma=88) + self.assertNotEqual(numpy.all(base == self.lattice.base), True) + self.lattice.set_lat_par(alpha=60, beta=60, gamma=60) + self.assertTrue(numpy.allclose(base[0], self.lattice.base[0])) + self.assertTrue(numpy.allclose(base[1], self.lattice.base[1])) + self.assertTrue(numpy.allclose(base[2], self.lattice.base[2])) + # try base checking + self.assertRaises( + LatticeError, + self.lattice.set_lat_base, + [[1, 0, 0], [1, 0, 0], [0, 0, 1]], + ) + self.assertRaises( + LatticeError, + self.lattice.set_lat_base, + [[1, 0, 0], [0, 0, 1], [0, 1, 0]], + ) + return + def test_reciprocal(self): """Check calculation of reciprocal lattice.""" r1 = self.lattice.reciprocal() @@ -185,7 +240,7 @@ def test_reciprocal(self): def test_dot(self): """Check dot product of lattice vectors.""" L = self.lattice - L.setLatPar(gamma=120) + L.set_lat_par(gamma=120) self.assertAlmostEqual(-0.5, L.dot([1, 0, 0], [0, 1, 0]), self.places) va5 = numpy.tile([1.0, 0.0, 0.0], (5, 1)) vb5 = numpy.tile([0.0, 1.0, 0.0], (5, 1)) @@ -199,14 +254,14 @@ def test_norm(self): self.assertEqual(1, self.lattice.norm([1, 0, 0])) u = numpy.array([[3, 4, 0], [1, 1, 1]]) self.assertTrue(numpy.allclose([5, 3**0.5], self.lattice.norm(u))) - self.lattice.setLatPar(gamma=120) + self.lattice.set_lat_par(gamma=120) self.assertAlmostEqual(1, self.lattice.norm([1, 1, 0]), self.places) return def test_rnorm(self): """Check norm of a reciprocal vector.""" L = self.lattice - L.setLatPar(1, 1.5, 2.3, 80, 95, 115) + L.set_lat_par(1, 1.5, 2.3, 80, 95, 115) r = L.reciprocal() hkl = [0.5, 0.3, 0.2] self.assertAlmostEqual(r.norm(hkl), L.rnorm(hkl), self.places) @@ -217,7 +272,7 @@ def test_rnorm(self): def test_dist(self): """Check dist function for distance between lattice points.""" L = self.lattice - L.setLatPar(1, 1.5, 2.3, 80, 95, 115) + L.set_lat_par(1, 1.5, 2.3, 80, 95, 115) u = [0.1, 0.3, 0.7] v = [0.3, 0.7, 0.7] d0 = numalg.norm(L.cartesian(numpy.array(u) - v)) @@ -235,7 +290,7 @@ def test_angle(self): from math import acos, degrees L = self.lattice - L.setLatPar(1, 1.5, 2.3, 80, 95, 115) + L.set_lat_par(1, 1.5, 2.3, 80, 95, 115) u = [0.1, 0.3, 0.7] v = [0.3, 0.7, 0.7] uc = L.cartesian(u) @@ -254,12 +309,12 @@ def test_repr(self): """Check string representation of this lattice.""" r = repr(self.lattice) self.assertEqual(r, "Lattice()") - self.lattice.setLatPar(1, 2, 3, 10, 20, 30) + self.lattice.set_lat_par(1, 2, 3, 10, 20, 30) r = repr(self.lattice) r0 = "Lattice(a=1, b=2, c=3, alpha=10, beta=20, gamma=30)" self.assertEqual(r, r0) base = [[1.0, 1.0, 0.0], [0.0, 2.0, 2.0], [3.0, 0.0, 3.0]] - self.lattice.setLatBase(base) + self.lattice.set_lat_base(base) r = repr(self.lattice) self.assertEqual(r, "Lattice(base=%r)" % self.lattice.base) From cca23ffc753bf019e37a89771c0e00ffe555b1bc Mon Sep 17 00:00:00 2001 From: stevenhua0320 Date: Sun, 22 Feb 2026 19:50:11 -0500 Subject: [PATCH 2/3] chore: rename the lower-case function to make it clearer in meaning --- .../structure/expansion/supercell_mod.py | 2 +- src/diffpy/structure/lattice.py | 28 ++++++++-------- src/diffpy/structure/parsers/p_discus.py | 2 +- src/diffpy/structure/parsers/p_pdb.py | 4 +-- src/diffpy/structure/parsers/p_xcfg.py | 2 +- tests/test_lattice.py | 32 +++++++++---------- 6 files changed, 35 insertions(+), 35 deletions(-) diff --git a/src/diffpy/structure/expansion/supercell_mod.py b/src/diffpy/structure/expansion/supercell_mod.py index a8f6fcdc..bcaceb70 100644 --- a/src/diffpy/structure/expansion/supercell_mod.py +++ b/src/diffpy/structure/expansion/supercell_mod.py @@ -82,7 +82,7 @@ def supercell(S, mno): newS.__setitem__(slice(None), newAtoms, copy=False) # take care of lattice parameters - newS.lattice.set_lat_par(a=mno[0] * S.lattice.a, b=mno[1] * S.lattice.b, c=mno[2] * S.lattice.c) + newS.lattice.set_latt_parms(a=mno[0] * S.lattice.a, b=mno[1] * S.lattice.b, c=mno[2] * S.lattice.c) return newS diff --git a/src/diffpy/structure/lattice.py b/src/diffpy/structure/lattice.py index 78a18475..f75e061c 100644 --- a/src/diffpy/structure/lattice.py +++ b/src/diffpy/structure/lattice.py @@ -34,7 +34,7 @@ setLatPar_deprecation_msg = build_deprecation_message( base, "setLatPar", - "set_lat_par", + "set_lat_parms", removal_version, ) setLatBase_deprecation_msg = build_deprecation_message( @@ -184,37 +184,37 @@ class Lattice(object): a = property( lambda self: self._a, - lambda self, value: self.set_lat_par(a=value), + lambda self, value: self.set_latt_parms(a=value), doc="The unit cell length *a*.", ) b = property( lambda self: self._b, - lambda self, value: self.set_lat_par(b=value), + lambda self, value: self.set_latt_parms(b=value), doc="The unit cell length *b*.", ) c = property( lambda self: self._c, - lambda self, value: self.set_lat_par(c=value), + lambda self, value: self.set_latt_parms(c=value), doc="The unit cell length *c*.", ) alpha = property( lambda self: self._alpha, - lambda self, value: self.set_lat_par(alpha=value), + lambda self, value: self.set_latt_parms(alpha=value), doc="The cell angle *alpha* in degrees.", ) beta = property( lambda self: self._beta, - lambda self, value: self.set_lat_par(beta=value), + lambda self, value: self.set_latt_parms(beta=value), doc="The cell angle *beta* in degrees.", ) gamma = property( lambda self: self._gamma, - lambda self, value: self.set_lat_par(gamma=value), + lambda self, value: self.set_latt_parms(gamma=value), doc="The cell angle *gamma* in degrees.", ) @@ -339,12 +339,12 @@ def __init__( # work out argument variants # Lattice() if not argset: - self.set_lat_par(1.0, 1.0, 1.0, 90.0, 90.0, 90.0, baserot) + self.set_latt_parms(1.0, 1.0, 1.0, 90.0, 90.0, 90.0, baserot) # Lattice(base=abc) elif base is not None: if len(argset) > 1: raise ValueError("'base' must be the only argument.") - self.set_lat_base(base) + self.set_new_latt_base_vec(base) # Lattice(lat) elif isinstance(a, Lattice): if len(argset) > 1: @@ -355,10 +355,10 @@ def __init__( abcabg = ("a", "b", "c", "alpha", "beta", "gamma") if not argset.issuperset(abcabg): raise ValueError("Provide all 6 cell parameters.") - self.set_lat_par(a, b, c, alpha, beta, gamma, baserot=baserot) + self.set_latt_parms(a, b, c, alpha, beta, gamma, baserot=baserot) return - def set_lat_par( + def set_latt_parms( self, a=None, b=None, @@ -473,7 +473,7 @@ def setLatPar( Please use diffpy.structure.Lattice.set_lat_par instead. """ - return self.set_lat_par(a, b, c, alpha, beta, gamma, baserot) + return self.set_latt_parms(a, b, c, alpha, beta, gamma, baserot) @deprecated(setLatBase_deprecation_msg) def setLatBase(self, base): @@ -482,9 +482,9 @@ def setLatBase(self, base): Please use diffpy.structure.Lattice.set_lat_base instead. """ - return self.set_lat_base(base) + return self.set_new_latt_base_vec(base) - def set_lat_base(self, base): + def set_new_latt_base_vec(self, base): """Set new base vectors for this lattice. This updates the cell lengths and cell angles according to the diff --git a/src/diffpy/structure/parsers/p_discus.py b/src/diffpy/structure/parsers/p_discus.py index d09f7ebe..8039c7c5 100644 --- a/src/diffpy/structure/parsers/p_discus.py +++ b/src/diffpy/structure/parsers/p_discus.py @@ -201,7 +201,7 @@ def _parse_cell(self, words): words = self.line.replace(",", " ").split() latpars = [float(w) for w in words[1:7]] try: - self.stru.lattice.set_lat_par(*latpars) + self.stru.lattice.set_latt_parms(*latpars) except ZeroDivisionError: emsg = "%d: Invalid lattice parameters - zero cell volume" % self.nl raise StructureFormatError(emsg) diff --git a/src/diffpy/structure/parsers/p_pdb.py b/src/diffpy/structure/parsers/p_pdb.py index 31199f76..7dc2f327 100644 --- a/src/diffpy/structure/parsers/p_pdb.py +++ b/src/diffpy/structure/parsers/p_pdb.py @@ -157,7 +157,7 @@ def parseLines(self, lines): alpha = float(line[33:40]) beta = float(line[40:47]) gamma = float(line[47:54]) - stru.lattice.set_lat_par(a, b, c, alpha, beta, gamma) + stru.lattice.set_latt_parms(a, b, c, alpha, beta, gamma) scale = numpy.transpose(stru.lattice.recbase) elif record == "SCALE1": sc = numpy.zeros((3, 3), dtype=float) @@ -171,7 +171,7 @@ def parseLines(self, lines): scaleU[2] = float(line[45:55]) base = numpy.transpose(numpy.linalg.inv(sc)) abcABGcryst = numpy.array(stru.lattice.abcABG()) - stru.lattice.set_lat_base(base) + stru.lattice.set_new_latt_base_vec(base) abcABGscale = numpy.array(stru.lattice.abcABG()) reldiff = numpy.fabs(1.0 - abcABGscale / abcABGcryst) if not numpy.all(reldiff < 1.0e-4): diff --git a/src/diffpy/structure/parsers/p_xcfg.py b/src/diffpy/structure/parsers/p_xcfg.py index 40cc7c82..ee626293 100644 --- a/src/diffpy/structure/parsers/p_xcfg.py +++ b/src/diffpy/structure/parsers/p_xcfg.py @@ -253,7 +253,7 @@ def parseLines(self, lines): emsg = ("%d: auxiliary fields are " "not consistent with entry_count") % p_nl raise StructureFormatError(emsg) # define proper lattice - stru.lattice.set_lat_base(xcfg_H0) + stru.lattice.set_new_latt_base_vec(xcfg_H0) # here we are inside the data block p_element = None for line in ilines: diff --git a/tests/test_lattice.py b/tests/test_lattice.py index 98c4a28c..48415352 100644 --- a/tests/test_lattice.py +++ b/tests/test_lattice.py @@ -44,7 +44,7 @@ def test___init__(self): self.assertRaises(ValueError, Lattice, 1, 2, 3) self.assertRaises(ValueError, Lattice, 1, 2, 3, 80, 90) L0 = self.lattice - L0.set_lat_base(L0.cartesian([[1, 1, 0], [0, 1, 1], [1, 0, 1]])) + L0.set_new_latt_base_vec(L0.cartesian([[1, 1, 0], [0, 1, 1], [1, 0, 1]])) L1 = Lattice(L0) self.assertTrue(numpy.array_equal(L0.base, L1.base)) L2 = Lattice(base=L0.base) @@ -89,7 +89,7 @@ def norm(x): def cosd(x): return cos(radians(x)) - self.lattice.set_lat_par(1.0, 2.0, 3.0, 80, 100, 120) + self.lattice.set_latt_parms(1.0, 2.0, 3.0, 80, 100, 120) base = self.lattice.base self.assertAlmostEqual(1.0, norm(base[0]), self.places) self.assertAlmostEqual(2.0, norm(base[1]), self.places) @@ -174,9 +174,9 @@ def test_setLatBase(self): self.assertAlmostEqual(detR0, 1.0, self.places) # try if rotation matrix works self.assertEqual(numpy.all(base == self.lattice.base), True) - self.lattice.set_lat_par(alpha=44, beta=66, gamma=88) + self.lattice.set_latt_parms(alpha=44, beta=66, gamma=88) self.assertNotEqual(numpy.all(base == self.lattice.base), True) - self.lattice.set_lat_par(alpha=60, beta=60, gamma=60) + self.lattice.set_latt_parms(alpha=60, beta=60, gamma=60) self.assertTrue(numpy.allclose(base[0], self.lattice.base[0])) self.assertTrue(numpy.allclose(base[1], self.lattice.base[1])) self.assertTrue(numpy.allclose(base[2], self.lattice.base[2])) @@ -196,7 +196,7 @@ def test_setLatBase(self): def test_set_lat_base(self): """Check calculation of unit cell rotation.""" base = numpy.array([[1.0, 1.0, 0.0], [0.0, 1.0, 1.0], [1.0, 0.0, 1.0]]) - self.lattice.set_lat_base(base) + self.lattice.set_new_latt_base_vec(base) self.assertAlmostEqual(self.lattice.a, numpy.sqrt(2.0), self.places) self.assertAlmostEqual(self.lattice.b, numpy.sqrt(2.0), self.places) self.assertAlmostEqual(self.lattice.c, numpy.sqrt(2.0), self.places) @@ -207,21 +207,21 @@ def test_set_lat_base(self): self.assertAlmostEqual(detR0, 1.0, self.places) # try if rotation matrix works self.assertEqual(numpy.all(base == self.lattice.base), True) - self.lattice.set_lat_par(alpha=44, beta=66, gamma=88) + self.lattice.set_latt_parms(alpha=44, beta=66, gamma=88) self.assertNotEqual(numpy.all(base == self.lattice.base), True) - self.lattice.set_lat_par(alpha=60, beta=60, gamma=60) + self.lattice.set_latt_parms(alpha=60, beta=60, gamma=60) self.assertTrue(numpy.allclose(base[0], self.lattice.base[0])) self.assertTrue(numpy.allclose(base[1], self.lattice.base[1])) self.assertTrue(numpy.allclose(base[2], self.lattice.base[2])) # try base checking self.assertRaises( LatticeError, - self.lattice.set_lat_base, + self.lattice.set_new_latt_base_vec, [[1, 0, 0], [1, 0, 0], [0, 0, 1]], ) self.assertRaises( LatticeError, - self.lattice.set_lat_base, + self.lattice.set_new_latt_base_vec, [[1, 0, 0], [0, 0, 1], [0, 1, 0]], ) return @@ -240,7 +240,7 @@ def test_reciprocal(self): def test_dot(self): """Check dot product of lattice vectors.""" L = self.lattice - L.set_lat_par(gamma=120) + L.set_latt_parms(gamma=120) self.assertAlmostEqual(-0.5, L.dot([1, 0, 0], [0, 1, 0]), self.places) va5 = numpy.tile([1.0, 0.0, 0.0], (5, 1)) vb5 = numpy.tile([0.0, 1.0, 0.0], (5, 1)) @@ -254,14 +254,14 @@ def test_norm(self): self.assertEqual(1, self.lattice.norm([1, 0, 0])) u = numpy.array([[3, 4, 0], [1, 1, 1]]) self.assertTrue(numpy.allclose([5, 3**0.5], self.lattice.norm(u))) - self.lattice.set_lat_par(gamma=120) + self.lattice.set_latt_parms(gamma=120) self.assertAlmostEqual(1, self.lattice.norm([1, 1, 0]), self.places) return def test_rnorm(self): """Check norm of a reciprocal vector.""" L = self.lattice - L.set_lat_par(1, 1.5, 2.3, 80, 95, 115) + L.set_latt_parms(1, 1.5, 2.3, 80, 95, 115) r = L.reciprocal() hkl = [0.5, 0.3, 0.2] self.assertAlmostEqual(r.norm(hkl), L.rnorm(hkl), self.places) @@ -272,7 +272,7 @@ def test_rnorm(self): def test_dist(self): """Check dist function for distance between lattice points.""" L = self.lattice - L.set_lat_par(1, 1.5, 2.3, 80, 95, 115) + L.set_latt_parms(1, 1.5, 2.3, 80, 95, 115) u = [0.1, 0.3, 0.7] v = [0.3, 0.7, 0.7] d0 = numalg.norm(L.cartesian(numpy.array(u) - v)) @@ -290,7 +290,7 @@ def test_angle(self): from math import acos, degrees L = self.lattice - L.set_lat_par(1, 1.5, 2.3, 80, 95, 115) + L.set_latt_parms(1, 1.5, 2.3, 80, 95, 115) u = [0.1, 0.3, 0.7] v = [0.3, 0.7, 0.7] uc = L.cartesian(u) @@ -309,12 +309,12 @@ def test_repr(self): """Check string representation of this lattice.""" r = repr(self.lattice) self.assertEqual(r, "Lattice()") - self.lattice.set_lat_par(1, 2, 3, 10, 20, 30) + self.lattice.set_latt_parms(1, 2, 3, 10, 20, 30) r = repr(self.lattice) r0 = "Lattice(a=1, b=2, c=3, alpha=10, beta=20, gamma=30)" self.assertEqual(r, r0) base = [[1.0, 1.0, 0.0], [0.0, 2.0, 2.0], [3.0, 0.0, 3.0]] - self.lattice.set_lat_base(base) + self.lattice.set_new_latt_base_vec(base) r = repr(self.lattice) self.assertEqual(r, "Lattice(base=%r)" % self.lattice.base) From 74683b6d8d8e84ba72f96511ec7d61b84da9e277 Mon Sep 17 00:00:00 2001 From: stevenhua0320 Date: Sun, 22 Feb 2026 19:52:30 -0500 Subject: [PATCH 3/3] fix: rename new function name in deprecation message and in news --- news/deprecate-lattice.rst | 4 ++-- src/diffpy/structure/lattice.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/news/deprecate-lattice.rst b/news/deprecate-lattice.rst index 6b8c6740..d3ef5438 100644 --- a/news/deprecate-lattice.rst +++ b/news/deprecate-lattice.rst @@ -1,7 +1,7 @@ **Added:** -* Added ``set_lat_par`` method into ``Lattice`` class -* Added ``set_lar_base`` method into ``Lattice`` class +* Added ``set_latt_parms`` method into ``Lattice`` class +* Added ``set_new_latt_base_vec`` method into ``Lattice`` class **Changed:** diff --git a/src/diffpy/structure/lattice.py b/src/diffpy/structure/lattice.py index f75e061c..76fe41d1 100644 --- a/src/diffpy/structure/lattice.py +++ b/src/diffpy/structure/lattice.py @@ -34,13 +34,13 @@ setLatPar_deprecation_msg = build_deprecation_message( base, "setLatPar", - "set_lat_parms", + "set_latt_parms", removal_version, ) setLatBase_deprecation_msg = build_deprecation_message( base, "setLatBase", - "set_lat_base", + "set_new_latt_base_vec", removal_version, )