Skip to content
Merged
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
25 changes: 25 additions & 0 deletions news/deprecate-symmetryutilities-1.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
**Added:**

* Added ``is_space_group_latt_parms`` method in ``symmetryutilities.py``
* Added ``is_constant_formula`` method in ``symmetryutilities.py``

**Changed:**

* <news item>

**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:**

* <news item>

**Fixed:**

* <news item>

**Security:**

* <news item>
11 changes: 11 additions & 0 deletions src/diffpy/structure/pdffitstructure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
"readStr",
"read_structure",
removal_version,
)

# ----------------------------------------------------------------------------

Expand Down Expand Up @@ -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.
Expand Down
38 changes: 37 additions & 1 deletion src/diffpy/structure/symmetryutilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_latt_parms",
removal_version,
)
isconstantFormula_deprecation_msg = build_deprecation_message(
base,
"isconstantFormula",
"is_constant_formula",
removal_version,
)

# Constants ------------------------------------------------------------------

Expand All @@ -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_latt_parms' instead.
"""
return is_space_group_latt_parms(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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
35 changes: 35 additions & 0 deletions tests/test_symmetryutilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
SymmetryConstraints,
_Position2Tuple,
expandPosition,
is_constant_formula,
is_space_group_latt_parms,
isconstantFormula,
isSpaceGroupLatPar,
pruneFormulaDictionary,
Expand Down Expand Up @@ -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_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):
"""Check GetSpaceGroup for non-standard aliases from sgtbx."""
self.assertIs(GetSpaceGroup("Fm3m"), GetSpaceGroup(225))
Expand Down Expand Up @@ -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

Expand Down
Loading