Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions news/deprecate-symmetryutilities-6.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
**Added:**

* Added ``_find_constraints`` method in ``SymmetryConstraints`` class
* Added ``pospar_symbols`` method in ``SymmetryConstraints`` class
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe pos_parm_symbols?

* Added ``pospar_values`` method in ``SymmetryConstraints`` class
* Added ``upar_symbols`` method in ``SymmetryConstraints`` class
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

u_parm_symbols and so on

* Added ``upar_values`` method in ``SymmetryConstraints`` class
* Added ``u_formulas`` method in ``SymmetryConstraints`` class

**Changed:**

* <news item>

**Deprecated:**

* Deprecated ``posparSymbols`` method in ``SymmetryConstraints`` class for removal in version 4.0.0
* Deprecated ``posparValues`` method in ``SymmetryConstraints`` class for removal in version 4.0.0
* Deprecated ``UparSymbols`` method in ``SymmetryConstraints`` class for removal in version 4.0.0
* Deprecated ``UparValues`` method in ``SymmetryConstraints`` class for removal in version 4.0.0
* Deprecated ``UFormulas`` method in ``SymmetryConstraints`` class for removal in version 4.0.0

**Removed:**

* <news item>

**Fixed:**

* <news item>

**Security:**

* <news item>
90 changes: 85 additions & 5 deletions src/diffpy/structure/symmetryutilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -1043,6 +1043,39 @@ def prune_formula_dictionary(eqdict):
return pruned


symmetry_constraints = "diffpy.symmetryutilities.SymmetryConstraints"
posparSymbols_deprecation_msg = build_deprecation_message(
symmetry_constraints,
"posparSymbols",
"pospar_symbols",
removal_version,
)
posparValues_deprecation_msg = build_deprecation_message(
symmetry_constraints,
"posparValues",
"pospar_values",
removal_version,
)
UparSymbols_deprecation_msg = build_deprecation_message(
symmetry_constraints,
"UparSymbols",
"upar_symbols",
removal_version,
)
UparValues_deprecation_msg = build_deprecation_message(
symmetry_constraints,
"UparValues",
"upar_values",
removal_version,
)
UFormulas_deprecation_msg = build_deprecation_message(
symmetry_constraints,
"UFormulas",
"u_formulas",
removal_version,
)


class SymmetryConstraints(object):
"""Generate symmetry constraints for specified positions.

Expand Down Expand Up @@ -1132,10 +1165,10 @@ def __init__(self, spacegroup, positions, Uijs=None, sgoffset=[0, 0, 0], eps=Non
self.Ueqns = numpos * [None]
self.Uisotropy = numpos * [False]
# all members should be initialized here
self._findConstraints()
self._find_constraints()
return

def _findConstraints(self):
def _find_constraints(self):
"""Find constraints for positions and anisotropic displacements
`Uij`."""
numpos = len(self.positions)
Expand Down Expand Up @@ -1184,11 +1217,29 @@ def _findConstraints(self):
self.corepos = [self.positions[i] for i in coreidx]
return

@deprecated(posparSymbols_deprecation_msg)
def posparSymbols(self):
"""'diffpy.structure.SymmetryConstraints.posparSymbols' is
deprecated and will be removed in version 4.0.0.

Please use 'diffpy.structure.SymmetryConstraints.pospar_symbols' instead.
"""
return self.pospar_symbols()

def pospar_symbols(self):
"""Return list of standard position parameter symbols."""
return [n for n, v in self.pospars]

@deprecated(posparValues_deprecation_msg)
def posparValues(self):
"""'diffpy.structure.SymmetryConstraints.posparValues' is
deprecated and will be removed in version 4.0.0.

Please use 'diffpy.structure.SymmetryConstraints.pospar_values' instead.
"""
return self.pospar_values()

def pospar_values(self):
"""Return list of position parameters values."""
return [v for n, v in self.pospars]

Expand All @@ -1214,7 +1265,7 @@ def positionFormulas(self, xyzsymbols=None):
emsg = "Not enough symbols for %i position parameters" % len(self.pospars)
raise SymmetryError(emsg)
# build translation dictionary
trsmbl = dict(zip(self.posparSymbols(), xyzsymbols))
trsmbl = dict(zip(self.pospar_symbols(), xyzsymbols))

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

@deprecated(UparSymbols_deprecation_msg)
def UparSymbols(self):
"""'diffpy.structure.SymmetryConstraints.UparSymbols' is
deprecated and will be removed in version 4.0.0.

Please use 'diffpy.structure.SymmetryConstraints.upar_symbols' instead.
"""
return self.upar_symbols()

def upar_symbols(self):
"""Return list of standard atom displacement parameter
symbols."""
return [n for n, v in self.Upars]

@deprecated(UparValues_deprecation_msg)
def UparValues(self):
"""'diffpy.structure.SymmetryConstraints.UparValues' is
deprecated and will be removed in version 4.0.0.

Please use 'diffpy.structure.SymmetryConstraints.upar_values'
instead.
"""
return [v for n, v in self.Upars]

def upar_values(self):
"""Return list of atom displacement parameters values."""
return [v for n, v in self.Upars]

@deprecated(UFormula_deprecation_msg)
def UFormulas(self, Usymbols=None):
"""'diffpy.structure.SymmetryConstraints.UFormulas' is
deprecated and will be removed in version 4.0.0.

Please use 'diffpy.structure.SymmetryConstraints.u_formulas'
instead.
"""
return self.u_formulas(Usymbols)

def u_formulas(self, Usymbols=None):
"""List of atom displacement formulas with custom parameter
symbols.

Expand All @@ -1282,7 +1362,7 @@ def UFormulas(self, Usymbols=None):
emsg = "Not enough symbols for %i U parameters" % len(self.Upars)
raise SymmetryError(emsg)
# build translation dictionary
trsmbl = dict(zip(self.UparSymbols(), Usymbols))
trsmbl = dict(zip(self.upar_symbols(), Usymbols))

def translatesymbol(matchobj):
return trsmbl[matchobj.group(0)]
Expand Down Expand Up @@ -1315,7 +1395,7 @@ def UFormulasPruned(self, Usymbols=None):
List of atom displacement formulas in tuples of
``(U11, U22, U33, U12, U13, U23)``.
"""
rv = [prune_formula_dictionary(eqns) for eqns in self.UFormulas(Usymbols)]
rv = [prune_formula_dictionary(eqns) for eqns in self.u_formulas(Usymbols)]
return rv


Expand Down
59 changes: 58 additions & 1 deletion tests/test_symmetryutilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ def test_u_formula_g186c_eqxyz(self):
"U13": 0.0,
"U23": 0.0,
}
for ufms in symcon.UFormulas():
for ufms in symcon.u_formulas():
for n, fm in ufms.items():
self.assertEqual(uisod[n], eval(fm, upd))
return
Expand Down Expand Up @@ -905,6 +905,18 @@ def test_UparSymbols(self):
self.assertEqual(["U110"], sc225.UparSymbols())
return

def test_upar_symbols(self):
"""Check SymmetryConstraints.UparSymbols()"""
sg1 = GetSpaceGroup(1)
sg225 = GetSpaceGroup(225)
pos = [[0, 0, 0]]
Uijs = numpy.zeros((1, 3, 3))
sc1 = SymmetryConstraints(sg1, pos, Uijs)
self.assertEqual(6, len(sc1.upar_symbols()))
sc225 = SymmetryConstraints(sg225, pos, Uijs)
self.assertEqual(["U110"], sc225.upar_symbols())
return

def test_UparValues(self):
"""Check SymmetryConstraints.UparValues()"""
places = 12
Expand All @@ -920,6 +932,34 @@ def test_UparValues(self):
self.assertAlmostEqual(0.2, sc225.UparValues()[0], places)
return

def test_upar_values(self):
"""Check SymmetryConstraints.UparValues()"""
places = 12
sg1 = GetSpaceGroup(1)
sg225 = GetSpaceGroup(225)
pos = [[0, 0, 0]]
Uijs = [[[0.1, 0.4, 0.5], [0.4, 0.2, 0.6], [0.5, 0.6, 0.3]]]
sc1 = SymmetryConstraints(sg1, pos, Uijs)
duv = 0.1 * numpy.arange(1, 7) - sc1.upar_values()
self.assertAlmostEqual(0, max(numpy.fabs(duv)), places)
sc225 = SymmetryConstraints(sg225, pos, Uijs)
self.assertEqual(1, len(sc225.upar_values()))
self.assertAlmostEqual(0.2, sc225.upar_values()[0], places)
return

def test_posparSymbols_and_posparValues(self):
"""Check SymmetryConstraints.posparSymbols and_posparValues()"""
sg225 = GetSpaceGroup(225)
eau = ExpandAsymmetricUnit(sg225, [[0, 0, 0]])
sc = SymmetryConstraints(sg225, eau.expandedpos)
sc.pospars = [("x", 0.12), ("y", 0.34), ("z", 0.56)]
actual_symbols = sc.posparSymbols()
actual_values = sc.posparValues()
expected_symbols = ["x", "y", "z"]
expected_values = [0.12, 0.34, 0.56]
assert expected_symbols == actual_symbols
assert expected_values == actual_values


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


@pytest.mark.parametrize(
"params, expected_symbols, expected_values",
[
pytest.param([("x", 0.12), ("y", 0.34), ("z", 0.56)], ["x", "y", "z"], [0.12, 0.34, 0.56]),
],
)
def test_pospar_symbols_and_pospar_values(params, expected_symbols, expected_values):
"""Check SymmetryConstraints.pospar_symbols and_pospar_values()"""
sg225 = GetSpaceGroup(225)
eau = ExpandAsymmetricUnit(sg225, [[0, 0, 0]])
sc = SymmetryConstraints(sg225, eau.expandedpos)
sc.pospars = params
actual_symbols, actual_values = sc.pospar_symbols(), sc.pospar_values()
assert actual_symbols == expected_symbols
assert actual_values == expected_values


if __name__ == "__main__":
unittest.main()
Loading