Skip to content

Commit fd16b4c

Browse files
authored
Merge pull request #170 from stevenhua0320/deprecate-symmetryutilities-6
chore: deprecate SymmetryConstraints class method
2 parents 1395fc3 + 820a3d6 commit fd16b4c

File tree

3 files changed

+175
-6
lines changed

3 files changed

+175
-6
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
**Added:**
2+
3+
* Added ``_find_constraints`` method in ``SymmetryConstraints`` class
4+
* Added ``pos_parm_symbols`` method in ``SymmetryConstraints`` class
5+
* Added ``pos_parm_values`` method in ``SymmetryConstraints`` class
6+
* Added ``u_parm_symbols`` method in ``SymmetryConstraints`` class
7+
* Added ``u_parm_values`` method in ``SymmetryConstraints`` class
8+
* Added ``u_formulas`` method in ``SymmetryConstraints`` class
9+
10+
**Changed:**
11+
12+
* <news item>
13+
14+
**Deprecated:**
15+
16+
* Deprecated ``posparSymbols`` method in ``SymmetryConstraints`` class for removal in version 4.0.0
17+
* Deprecated ``posparValues`` method in ``SymmetryConstraints`` class for removal in version 4.0.0
18+
* Deprecated ``UparSymbols`` method in ``SymmetryConstraints`` class for removal in version 4.0.0
19+
* Deprecated ``UparValues`` method in ``SymmetryConstraints`` class for removal in version 4.0.0
20+
* Deprecated ``UFormulas`` method in ``SymmetryConstraints`` class for removal in version 4.0.0
21+
22+
**Removed:**
23+
24+
* <news item>
25+
26+
**Fixed:**
27+
28+
* <news item>
29+
30+
**Security:**
31+
32+
* <news item>

src/diffpy/structure/symmetryutilities.py

Lines changed: 85 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,6 +1043,39 @@ def prune_formula_dictionary(eqdict):
10431043
return pruned
10441044

10451045

1046+
symmetry_constraints = "diffpy.symmetryutilities.SymmetryConstraints"
1047+
posparSymbols_deprecation_msg = build_deprecation_message(
1048+
symmetry_constraints,
1049+
"posparSymbols",
1050+
"pospar_symbols",
1051+
removal_version,
1052+
)
1053+
posparValues_deprecation_msg = build_deprecation_message(
1054+
symmetry_constraints,
1055+
"posparValues",
1056+
"pospar_values",
1057+
removal_version,
1058+
)
1059+
UparSymbols_deprecation_msg = build_deprecation_message(
1060+
symmetry_constraints,
1061+
"UparSymbols",
1062+
"upar_symbols",
1063+
removal_version,
1064+
)
1065+
UparValues_deprecation_msg = build_deprecation_message(
1066+
symmetry_constraints,
1067+
"UparValues",
1068+
"upar_values",
1069+
removal_version,
1070+
)
1071+
UFormulas_deprecation_msg = build_deprecation_message(
1072+
symmetry_constraints,
1073+
"UFormulas",
1074+
"u_formulas",
1075+
removal_version,
1076+
)
1077+
1078+
10461079
class SymmetryConstraints(object):
10471080
"""Generate symmetry constraints for specified positions.
10481081
@@ -1132,10 +1165,10 @@ def __init__(self, spacegroup, positions, Uijs=None, sgoffset=[0, 0, 0], eps=Non
11321165
self.Ueqns = numpos * [None]
11331166
self.Uisotropy = numpos * [False]
11341167
# all members should be initialized here
1135-
self._findConstraints()
1168+
self._find_constraints()
11361169
return
11371170

1138-
def _findConstraints(self):
1171+
def _find_constraints(self):
11391172
"""Find constraints for positions and anisotropic displacements
11401173
`Uij`."""
11411174
numpos = len(self.positions)
@@ -1184,11 +1217,29 @@ def _findConstraints(self):
11841217
self.corepos = [self.positions[i] for i in coreidx]
11851218
return
11861219

1220+
@deprecated(posparSymbols_deprecation_msg)
11871221
def posparSymbols(self):
1222+
"""'diffpy.structure.SymmetryConstraints.posparSymbols' is
1223+
deprecated and will be removed in version 4.0.0.
1224+
1225+
Please use 'diffpy.structure.SymmetryConstraints.pos_parm_symbols' instead.
1226+
"""
1227+
return self.pos_parm_symbols()
1228+
1229+
def pos_parm_symbols(self):
11881230
"""Return list of standard position parameter symbols."""
11891231
return [n for n, v in self.pospars]
11901232

1233+
@deprecated(posparValues_deprecation_msg)
11911234
def posparValues(self):
1235+
"""'diffpy.structure.SymmetryConstraints.posparValues' is
1236+
deprecated and will be removed in version 4.0.0.
1237+
1238+
Please use 'diffpy.structure.SymmetryConstraints.pos_parm_values' instead.
1239+
"""
1240+
return self.pos_parm_values()
1241+
1242+
def pos_parm_values(self):
11921243
"""Return list of position parameters values."""
11931244
return [v for n, v in self.pospars]
11941245

@@ -1214,7 +1265,7 @@ def positionFormulas(self, xyzsymbols=None):
12141265
emsg = "Not enough symbols for %i position parameters" % len(self.pospars)
12151266
raise SymmetryError(emsg)
12161267
# build translation dictionary
1217-
trsmbl = dict(zip(self.posparSymbols(), xyzsymbols))
1268+
trsmbl = dict(zip(self.pos_parm_symbols(), xyzsymbols))
12181269

12191270
def translatesymbol(matchobj):
12201271
return trsmbl[matchobj.group(0)]
@@ -1249,16 +1300,45 @@ def positionFormulasPruned(self, xyzsymbols=None):
12491300
rv = [prune_formula_dictionary(eqns) for eqns in self.positionFormulas(xyzsymbols)]
12501301
return rv
12511302

1303+
@deprecated(UparSymbols_deprecation_msg)
12521304
def UparSymbols(self):
1305+
"""'diffpy.structure.SymmetryConstraints.UparSymbols' is
1306+
deprecated and will be removed in version 4.0.0.
1307+
1308+
Please use 'diffpy.structure.SymmetryConstraints.u_parm_symbols' instead.
1309+
"""
1310+
return self.u_parm_symbols()
1311+
1312+
def u_parm_symbols(self):
12531313
"""Return list of standard atom displacement parameter
12541314
symbols."""
12551315
return [n for n, v in self.Upars]
12561316

1317+
@deprecated(UparValues_deprecation_msg)
12571318
def UparValues(self):
1319+
"""'diffpy.structure.SymmetryConstraints.UparValues' is
1320+
deprecated and will be removed in version 4.0.0.
1321+
1322+
Please use 'diffpy.structure.SymmetryConstraints.u_parm_values'
1323+
instead.
1324+
"""
1325+
return [v for n, v in self.Upars]
1326+
1327+
def u_parm_values(self):
12581328
"""Return list of atom displacement parameters values."""
12591329
return [v for n, v in self.Upars]
12601330

1331+
@deprecated(UFormula_deprecation_msg)
12611332
def UFormulas(self, Usymbols=None):
1333+
"""'diffpy.structure.SymmetryConstraints.UFormulas' is
1334+
deprecated and will be removed in version 4.0.0.
1335+
1336+
Please use 'diffpy.structure.SymmetryConstraints.u_formulas'
1337+
instead.
1338+
"""
1339+
return self.u_formulas(Usymbols)
1340+
1341+
def u_formulas(self, Usymbols=None):
12621342
"""List of atom displacement formulas with custom parameter
12631343
symbols.
12641344
@@ -1282,7 +1362,7 @@ def UFormulas(self, Usymbols=None):
12821362
emsg = "Not enough symbols for %i U parameters" % len(self.Upars)
12831363
raise SymmetryError(emsg)
12841364
# build translation dictionary
1285-
trsmbl = dict(zip(self.UparSymbols(), Usymbols))
1365+
trsmbl = dict(zip(self.u_parm_symbols(), Usymbols))
12861366

12871367
def translatesymbol(matchobj):
12881368
return trsmbl[matchobj.group(0)]
@@ -1315,7 +1395,7 @@ def UFormulasPruned(self, Usymbols=None):
13151395
List of atom displacement formulas in tuples of
13161396
``(U11, U22, U33, U12, U13, U23)``.
13171397
"""
1318-
rv = [prune_formula_dictionary(eqns) for eqns in self.UFormulas(Usymbols)]
1398+
rv = [prune_formula_dictionary(eqns) for eqns in self.u_formulas(Usymbols)]
13191399
return rv
13201400

13211401

tests/test_symmetryutilities.py

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,7 @@ def test_u_formula_g186c_eqxyz(self):
758758
"U13": 0.0,
759759
"U23": 0.0,
760760
}
761-
for ufms in symcon.UFormulas():
761+
for ufms in symcon.u_formulas():
762762
for n, fm in ufms.items():
763763
self.assertEqual(uisod[n], eval(fm, upd))
764764
return
@@ -905,6 +905,18 @@ def test_UparSymbols(self):
905905
self.assertEqual(["U110"], sc225.UparSymbols())
906906
return
907907

908+
def test_upar_symbols(self):
909+
"""Check SymmetryConstraints.UparSymbols()"""
910+
sg1 = GetSpaceGroup(1)
911+
sg225 = GetSpaceGroup(225)
912+
pos = [[0, 0, 0]]
913+
Uijs = numpy.zeros((1, 3, 3))
914+
sc1 = SymmetryConstraints(sg1, pos, Uijs)
915+
self.assertEqual(6, len(sc1.u_parm_symbols()))
916+
sc225 = SymmetryConstraints(sg225, pos, Uijs)
917+
self.assertEqual(["U110"], sc225.u_parm_symbols())
918+
return
919+
908920
def test_UparValues(self):
909921
"""Check SymmetryConstraints.UparValues()"""
910922
places = 12
@@ -920,6 +932,34 @@ def test_UparValues(self):
920932
self.assertAlmostEqual(0.2, sc225.UparValues()[0], places)
921933
return
922934

935+
def test_upar_values(self):
936+
"""Check SymmetryConstraints.UparValues()"""
937+
places = 12
938+
sg1 = GetSpaceGroup(1)
939+
sg225 = GetSpaceGroup(225)
940+
pos = [[0, 0, 0]]
941+
Uijs = [[[0.1, 0.4, 0.5], [0.4, 0.2, 0.6], [0.5, 0.6, 0.3]]]
942+
sc1 = SymmetryConstraints(sg1, pos, Uijs)
943+
duv = 0.1 * numpy.arange(1, 7) - sc1.u_parm_values()
944+
self.assertAlmostEqual(0, max(numpy.fabs(duv)), places)
945+
sc225 = SymmetryConstraints(sg225, pos, Uijs)
946+
self.assertEqual(1, len(sc225.u_parm_values()))
947+
self.assertAlmostEqual(0.2, sc225.u_parm_values()[0], places)
948+
return
949+
950+
def test_posparSymbols_and_posparValues(self):
951+
"""Check SymmetryConstraints.posparSymbols and_posparValues()"""
952+
sg225 = GetSpaceGroup(225)
953+
eau = ExpandAsymmetricUnit(sg225, [[0, 0, 0]])
954+
sc = SymmetryConstraints(sg225, eau.expandedpos)
955+
sc.pospars = [("x", 0.12), ("y", 0.34), ("z", 0.56)]
956+
actual_symbols = sc.posparSymbols()
957+
actual_values = sc.posparValues()
958+
expected_symbols = ["x", "y", "z"]
959+
expected_values = [0.12, 0.34, 0.56]
960+
assert expected_symbols == actual_symbols
961+
assert expected_values == actual_values
962+
923963

924964
# def test_UFormulas(self):
925965
# """check SymmetryConstraints.UFormulas()
@@ -1056,5 +1096,22 @@ def test_null_space(A, expected_dim):
10561096
assert numpy.allclose(actual @ actual.T, numpy.eye(expected_dim), atol=1e-12)
10571097

10581098

1099+
@pytest.mark.parametrize(
1100+
"params, expected_symbols, expected_values",
1101+
[
1102+
pytest.param([("x", 0.12), ("y", 0.34), ("z", 0.56)], ["x", "y", "z"], [0.12, 0.34, 0.56]),
1103+
],
1104+
)
1105+
def test_pospar_symbols_and_pospar_values(params, expected_symbols, expected_values):
1106+
"""Check SymmetryConstraints.pospar_symbols and_pospar_values()"""
1107+
sg225 = GetSpaceGroup(225)
1108+
eau = ExpandAsymmetricUnit(sg225, [[0, 0, 0]])
1109+
sc = SymmetryConstraints(sg225, eau.expandedpos)
1110+
sc.pospars = params
1111+
actual_symbols, actual_values = sc.pos_parm_symbols(), sc.pos_parm_values()
1112+
assert actual_symbols == expected_symbols
1113+
assert actual_values == expected_values
1114+
1115+
10591116
if __name__ == "__main__":
10601117
unittest.main()

0 commit comments

Comments
 (0)