Skip to content

Commit 1646a8b

Browse files
authored
Merge pull request #168 from stevenhua0320/deprecate-symmetryutilities-4
chore: deprecate method in GeneratorSite class
2 parents d34a414 + 0d60a73 commit 1646a8b

File tree

3 files changed

+65
-13
lines changed

3 files changed

+65
-13
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
**Added:**
2+
3+
* Added ``convert_fp_num_to_signed_rational`` method in ``GeneratorSite`` class
4+
* Added ``_find_null_space`` method in ``GeneratorSite`` class
5+
* Added ``_find_pos_parameters`` method in ``GeneratorSite`` class
6+
* Added ``_find_u_space`` method in ``GeneratorSite`` class
7+
* Added ``_find_u_parameters`` method in ``GeneratorSite`` class
8+
* Added ``_find_eq_uij`` method in ``GeneratorSite`` class
9+
10+
**Changed:**
11+
12+
* <news item>
13+
14+
**Deprecated:**
15+
16+
* Deprecated ``signedRatStr`` method in in ``GeneratorSite`` class for removal in version 4.0.0
17+
18+
**Removed:**
19+
20+
* <news item>
21+
22+
**Fixed:**
23+
24+
* <news item>
25+
26+
**Security:**
27+
28+
* <news item>

src/diffpy/structure/symmetryutilities.py

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,14 @@ def _find_invariants(symops):
469469

470470
# ----------------------------------------------------------------------------
471471

472+
generator_site = "diffpy.symmetryutilities.GeneratorSite"
473+
signedRatStr_deprecation_msg = build_deprecation_message(
474+
generator_site,
475+
"signedRatStr",
476+
"convert_fp_num_to_signed_rational",
477+
removal_version,
478+
)
479+
472480

473481
class GeneratorSite(object):
474482
"""Storage of data related to a generator positions.
@@ -593,14 +601,14 @@ def __init__(
593601
self.symops = ops
594602
self.multiplicity = mult
595603
self.invariants = invariants
596-
self._findNullSpace()
597-
self._findPosParameters()
598-
self._findUSpace()
599-
self._findUParameters()
600-
self._findeqUij()
604+
self._find_null_space()
605+
self._find_pos_parameters()
606+
self._find_u_space()
607+
self._find_u_parameters()
608+
self._find_eq_uij()
601609
return
602610

603-
def signedRatStr(self, x):
611+
def convert_fp_num_to_signed_rational(self, x):
604612
"""Convert floating point number to signed rational
605613
representation.
606614
@@ -628,7 +636,16 @@ def signedRatStr(self, x):
628636
# here we have fraction
629637
return "%+.0f/%.0f" % (nom[idx[0]], den[idx[0]])
630638

631-
def _findNullSpace(self):
639+
@deprecated(signedRatStr_deprecation_msg)
640+
def signedRatStr(self, x):
641+
"""'diffpy.structure.GeneratorSite.signedRatStr' is deprecated
642+
and will be removed in version 4.0.0.
643+
644+
Please use 'diffpy.structure.GeneratorSite.convert_fp_num_to_signed_rational' instead.
645+
"""
646+
return self.convert_fp_num_to_signed_rational(x)
647+
648+
def _find_null_space(self):
632649
"""Calculate `self.null_space` from `self.invariants`.
633650
634651
Try to represent `self.null_space` using small integers.
@@ -660,7 +677,7 @@ def _findNullSpace(self):
660677
row[:] = (sgrow * abrow) / sgrow[idx] / abrow[idx]
661678
return
662679

663-
def _findPosParameters(self):
680+
def _find_pos_parameters(self):
664681
"""Find pparameters and their values for expressing
665682
`self.xyz`."""
666683
usedsymbol = {}
@@ -677,7 +694,7 @@ def _findPosParameters(self):
677694
usedsymbol[vname] = True
678695
return
679696

680-
def _findUSpace(self):
697+
def _find_u_space(self):
681698
"""Find independent U components with respect to invariant
682699
rotations."""
683700
n = len(self.invariants)
@@ -710,7 +727,7 @@ def _findUSpace(self):
710727
self.Uisotropy = len(self.Uspace) == 1
711728
return
712729

713-
def _findUParameters(self):
730+
def _find_u_parameters(self):
714731
"""Find Uparameters and their values for expressing
715732
`self.Uij`."""
716733
# permute indices as 00 11 22 01 02 12 10 20 21
@@ -726,7 +743,7 @@ def _findUParameters(self):
726743
self.Uparameters.append((vname, varvalue))
727744
return
728745

729-
def _findeqUij(self):
746+
def _find_eq_uij(self):
730747
"""Adjust `self.Uij` and `self.eqUij` to be consistent with
731748
spacegroup."""
732749
self.Uij = numpy.zeros((3, 3), dtype=float)
@@ -782,14 +799,14 @@ def positionFormula(self, pos, xyzsymbols=("x", "y", "z")):
782799
if abs(nvec[i]) < epsilon:
783800
continue
784801
xyzformula[i] += "%s*%s " % (
785-
self.signedRatStr(nvec[i]),
802+
self.convert_fp_num_to_signed_rational(nvec[i]),
786803
name2sym[vname],
787804
)
788805
# add constant offset teqpos to all formulas
789806
for i in range(3):
790807
if xyzformula[i] and abs(teqpos[i]) < epsilon:
791808
continue
792-
xyzformula[i] += self.signedRatStr(teqpos[i])
809+
xyzformula[i] += self.convert_fp_num_to_signed_rational(teqpos[i])
793810
# reduce unnecessary +1* and -1*
794811
xyzformula = [re.sub("^[+]1[*]|(?<=[+-])1[*]", "", f).strip() for f in xyzformula]
795812
return dict(zip(("x", "y", "z"), xyzformula))

tests/test_symmetryutilities.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,13 @@ def test_signedRatStr(self):
302302
self.assertEqual("+1", g.signedRatStr(1.00000000000002))
303303
return
304304

305+
def test_convert_fp_num_to_signed_rational(self):
306+
"check GeneratorSite.test_convert_fp_num_to_signed_rational()"
307+
g = self.g117c
308+
self.assertEqual("-1", g.convert_fp_num_to_signed_rational(-1.00000000000002))
309+
self.assertEqual("+1", g.convert_fp_num_to_signed_rational(1.00000000000002))
310+
return
311+
305312
def test_positionFormula(self):
306313
"""Check GeneratorSite.positionFormula()"""
307314
# 117c

0 commit comments

Comments
 (0)