Skip to content

Commit d2d6285

Browse files
committed
chore: deprecate spacegroup method
1 parent 4957ccf commit d2d6285

File tree

7 files changed

+265
-83
lines changed

7 files changed

+265
-83
lines changed

devutils/sgtbx_extra_groups.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import numpy
1818
from cctbx import sgtbx
1919

20-
from diffpy.structure.spacegroups import IsSpaceGroupIdentifier, SpaceGroup, SymOp, mmLibSpaceGroupList
20+
from diffpy.structure.spacegroups import SpaceGroup, SymOp, is_space_group_identifier, mmLibSpaceGroupList
2121

2222

2323
def tupleToSGArray(tpl):
@@ -196,7 +196,7 @@ def main():
196196
if findEquivalentMMSpaceGroup(grp):
197197
continue
198198
shn = smbls.hermann_mauguin().replace(" ", "")
199-
if IsSpaceGroupIdentifier(shn):
199+
if is_space_group_identifier(shn):
200200
continue
201201
sg = mmSpaceGroupFromSymbol(uhm)
202202
hsg = hashMMSpaceGroup(sg)

news/deprecate-spacegroup.rst

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
**Added:**
2+
3+
* Added ``get_symop`` method in ``parsers/p_cif.py``
4+
* Added ``get_space_group`` method in ``spacegroups.py``
5+
* Added ``find_space_group`` method in ``spacegroups.py``
6+
* Added ``is_space_group_identifier`` method in ``spacegroups.py``
7+
* Added ``_hash_symop_list`` method in ``spacegroups.py``
8+
* Added ``_build_sg_lookup_table`` method in ``spacegroups.py``
9+
* Added ``_get_sg_hash_lookup_table`` method in ``spacegroups.py``
10+
11+
**Changed:**
12+
13+
* <news item>
14+
15+
**Deprecated:**
16+
17+
* Deprecated ``getSymOp`` method in ``parsers/p_cif.py`` for removal in version 4.0.0
18+
* Deprecated ``GetSpaceGroup`` method in ``spacegroups.py`` for removal in version 4.0.0
19+
* Deprecated ``IsSpaceGroupIdentifier`` method in ``spacegroups.py`` for removal in version 4.0.0
20+
* Deprecated ``FindSpaceGroup`` method in ``spacegroups.py`` for removal in version 4.0.0
21+
* Deprecated ``_hashSymOpList`` method in ``spacegroups.py`` for removal in version 4.0.0
22+
23+
**Removed:**
24+
25+
* <news item>
26+
27+
**Fixed:**
28+
29+
* <news item>
30+
31+
**Security:**
32+
33+
* <news item>

src/diffpy/structure/parsers/p_cif.py

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,12 @@ def _parse_space_group_symop_operation_xyz(self, block):
593593
block : CifBlock
594594
Instance of `CifBlock`.
595595
"""
596-
from diffpy.structure.spacegroups import FindSpaceGroup, GetSpaceGroup, IsSpaceGroupIdentifier, SpaceGroup
596+
from diffpy.structure.spacegroups import (
597+
SpaceGroup,
598+
find_space_group,
599+
get_space_group,
600+
is_space_group_identifier,
601+
)
597602

598603
self.asymmetric_unit = list(self.stru)
599604
sym_synonyms = (
@@ -608,7 +613,7 @@ def _parse_space_group_symop_operation_xyz(self, block):
608613
sym_loop_name = sym_loop_name[0]
609614
sym_loop = block.GetLoop(sym_loop_name)
610615
for eqxyz in sym_loop[sym_loop_name]:
611-
opcif = getSymOp(eqxyz)
616+
opcif = get_symop(eqxyz)
612617
symop_list.append(opcif)
613618
# determine space group number
614619
sg_nameHall = block.get("_space_group_name_Hall", "") or block.get("_symmetry_space_group_name_Hall", "")
@@ -623,12 +628,12 @@ def _parse_space_group_symop_operation_xyz(self, block):
623628
# try to reuse existing space group from symmetry operations
624629
if symop_list:
625630
try:
626-
self.spacegroup = FindSpaceGroup(symop_list)
631+
self.spacegroup = find_space_group(symop_list)
627632
except ValueError:
628633
pass
629634
# otherwise lookup the space group from its identifier
630-
if self.spacegroup is None and sgid and IsSpaceGroupIdentifier(sgid):
631-
self.spacegroup = GetSpaceGroup(sgid)
635+
if self.spacegroup is None and sgid and is_space_group_identifier(sgid):
636+
self.spacegroup = get_space_group(sgid)
632637
# define new spacegroup when symmetry operations were listed, but
633638
# there is no match to an existing definition
634639
if symop_list and self.spacegroup is None:
@@ -824,6 +829,12 @@ def to_lines(self, stru):
824829
"get_parser",
825830
removal_version,
826831
)
832+
getSymOp_deprecation_msg = build_deprecation_message(
833+
parsers_base,
834+
"getSymOp",
835+
"get_symop",
836+
removal_version,
837+
)
827838
# constant regular expression for leading_float()
828839
rx_float = re.compile(r"[-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?")
829840

@@ -878,7 +889,17 @@ def leading_float(s, d=0.0):
878889
symvec["+z"] = symvec["z"]
879890

880891

892+
@deprecated(getSymOp_deprecation_msg)
881893
def getSymOp(s):
894+
"""This function has been deprecated and will be removed in version
895+
4.0.0.
896+
897+
Please use diffpy.structure.get_symop instead.
898+
"""
899+
return get_symop(s)
900+
901+
902+
def get_symop(s):
882903
"""Create `SpaceGroups.SymOp` instance from a string.
883904
884905
Parameters
@@ -913,7 +934,7 @@ def getParser(eps=None):
913934
"""This function has been deprecated and will be removed in version
914935
4.0.0.
915936
916-
Please use diffpy.structure.P_cif.get_parser instead.
937+
Please use diffpy.structure.get_parser instead.
917938
"""
918939
return get_parser(eps)
919940

src/diffpy/structure/spacegroups.py

Lines changed: 76 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -643,14 +643,50 @@
643643
Tr_34_34_14,
644644
Tr_34_34_34,
645645
)
646+
from diffpy.utils._deprecator import build_deprecation_message, deprecated
646647

647648
# Import SpaceGroup objects --------------------------------------------------
648-
649+
base = "diffpy.structure"
650+
removal_version = "4.0.0"
651+
GetSpaceGroup_deprecation_msg = build_deprecation_message(
652+
base,
653+
"GetSpaceGroup",
654+
"get_space_group",
655+
removal_version,
656+
)
657+
FindSpaceGroup_deprecation_msg = build_deprecation_message(
658+
base,
659+
"FindSpaceGroup",
660+
"find_space_group",
661+
removal_version,
662+
)
663+
IsSpaceGroupIdentifier_deprecation_msg = build_deprecation_message(
664+
base,
665+
"IsSpaceGroupIdentifier",
666+
"is_space_group_identifier",
667+
removal_version,
668+
)
669+
_hashSymOpList_deprecation_msg = build_deprecation_message(
670+
base,
671+
"_hashSymOpList",
672+
"_hash_symop_list",
673+
removal_version,
674+
)
649675

650676
SpaceGroupList = mmLibSpaceGroupList + sgtbxSpaceGroupList
651677

652678

679+
@deprecated(GetSpaceGroup_deprecation_msg)
653680
def GetSpaceGroup(sgid):
681+
"""This function has been deprecated and will be removed in version
682+
4.0.0.
683+
684+
Please use diffpy.structure.get_space_group instead.
685+
"""
686+
return get_space_group(sgid)
687+
688+
689+
def get_space_group(sgid):
654690
"""Returns the SpaceGroup instance for the given identifier.
655691
656692
Parameters
@@ -670,7 +706,7 @@ def GetSpaceGroup(sgid):
670706
When the identifier is not found.
671707
"""
672708
if not _sg_lookup_table:
673-
_buildSGLookupTable()
709+
_build_sg_lookup_table()
674710
if sgid in _sg_lookup_table:
675711
return _sg_lookup_table[sgid]
676712
# Try different versions of sgid, first make sure it is a string
@@ -691,10 +727,22 @@ def GetSpaceGroup(sgid):
691727
raise ValueError(emsg)
692728

693729

730+
@deprecated(IsSpaceGroupIdentifier_deprecation_msg)
694731
def IsSpaceGroupIdentifier(sgid):
695732
"""Check if identifier can be used as an argument to
696733
`GetSpaceGroup`.
697734
735+
Returns
736+
-------
737+
bool
738+
"""
739+
return is_space_group_identifier(sgid)
740+
741+
742+
def is_space_group_identifier(sgid):
743+
"""Check if identifier can be used as an argument to
744+
`GetSpaceGroup`.
745+
698746
Returns
699747
-------
700748
bool
@@ -707,7 +755,17 @@ def IsSpaceGroupIdentifier(sgid):
707755
return rv
708756

709757

758+
@deprecated(FindSpaceGroup_deprecation_msg)
710759
def FindSpaceGroup(symops, shuffle=False):
760+
"""This function has been deprecated and will be removed in version
761+
4.0.0.
762+
763+
Please use diffpy.structure.find_space_group instead.
764+
"""
765+
return find_space_group(symops, shuffle=shuffle)
766+
767+
768+
def find_space_group(symops, shuffle=False):
711769
"""Lookup SpaceGroup from a given list of symmetry operations.
712770
713771
Parameters
@@ -732,8 +790,8 @@ def FindSpaceGroup(symops, shuffle=False):
732790
When `symops` do not match any known SpaceGroup.
733791
"""
734792

735-
tb = _getSGHashLookupTable()
736-
hh = _hashSymOpList(symops)
793+
tb = _get_sg_hash_lookup_table()
794+
hh = _hash_symop_list(symops)
737795
if hh not in tb:
738796
raise ValueError("Cannot find SpaceGroup for the specified symops.")
739797
rv = tb[hh]
@@ -746,7 +804,17 @@ def FindSpaceGroup(symops, shuffle=False):
746804
return rv
747805

748806

807+
@deprecated(_hashSymOpList_deprecation_msg)
749808
def _hashSymOpList(symops):
809+
"""This function has been deprecated and will be removed in version
810+
4.0.0.
811+
812+
Please use diffpy.structure._hash_symop_list instead.
813+
"""
814+
return _hash_symop_list(symops)
815+
816+
817+
def _hash_symop_list(symops):
750818
"""Return hash value for a sequence of `SymOp` objects.
751819
752820
The symops are sorted so the results is independent of symops order.
@@ -766,7 +834,7 @@ def _hashSymOpList(symops):
766834
return rv
767835

768836

769-
def _buildSGLookupTable():
837+
def _build_sg_lookup_table():
770838
"""Rebuild space group lookup table from the `SpaceGroupList` data.
771839
772840
This routine updates the global `_sg_lookup_table` dictionary.
@@ -809,16 +877,16 @@ def _buildSGLookupTable():
809877
_sg_lookup_table = {}
810878

811879

812-
def _getSGHashLookupTable():
880+
def _get_sg_hash_lookup_table():
813881
"""Return lookup table of symop hashes to standard `SpaceGroup`
814882
objects."""
815883
if _sg_hash_lookup_table:
816884
return _sg_hash_lookup_table
817885
for sg in SpaceGroupList:
818-
h = _hashSymOpList(sg.symop_list)
886+
h = _hash_symop_list(sg.symop_list)
819887
_sg_hash_lookup_table[h] = sg
820888
assert len(_sg_hash_lookup_table) == len(SpaceGroupList)
821-
return _getSGHashLookupTable()
889+
return _get_sg_hash_lookup_table()
822890

823891

824892
_sg_hash_lookup_table = {}

tests/test_p_cif.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
from diffpy.structure import Structure
2323
from diffpy.structure.parsers import get_parser, getParser
24-
from diffpy.structure.parsers.p_cif import P_cif, getSymOp, leading_float
24+
from diffpy.structure.parsers.p_cif import P_cif, get_symop, getSymOp, leading_float
2525
from diffpy.structure.structureerrors import StructureFormatError
2626

2727
# ----------------------------------------------------------------------------
@@ -56,6 +56,20 @@ def test_getSymOp(self):
5656
self.assertEqual(str(op1_std), str(op1))
5757
return
5858

59+
def test_get_symop(self):
60+
"""Check get_symop()"""
61+
from diffpy.structure.spacegroups import Rot_X_mY_Z, SymOp, Tr_0_12_12
62+
63+
op = get_symop("x,1/2-y,1/2+z")
64+
op_std = SymOp(Rot_X_mY_Z, Tr_0_12_12)
65+
self.assertEqual(str(op_std), str(op))
66+
from diffpy.structure.spacegroups import Rot_mX_mXY_Z, Tr_0_0_12
67+
68+
op1 = get_symop("-x,-x+y,1/2+z")
69+
op1_std = SymOp(Rot_mX_mXY_Z, Tr_0_0_12)
70+
self.assertEqual(str(op1_std), str(op1))
71+
return
72+
5973

6074
# End of class TestRoutines
6175

@@ -332,7 +346,7 @@ def test_unknown_occupancy(self):
332346

333347
def test_unknown_spacegroup_number(self):
334348
"test CIF file with unknown space group symbol"
335-
from diffpy.structure.spacegroups import GetSpaceGroup, _hashSymOpList
349+
from diffpy.structure.spacegroups import _hash_symop_list, get_space_group
336350

337351
with open(self.pbteciffile) as fp:
338352
lines = fp.readlines()
@@ -346,9 +360,9 @@ def test_unknown_spacegroup_number(self):
346360
ciftxt = "".join(lines)
347361
stru = self.ptest.parse(ciftxt)
348362
self.assertEqual(8, len(stru))
349-
h225 = _hashSymOpList(GetSpaceGroup(225).iter_symops())
363+
h225 = _hash_symop_list(get_space_group(225).iter_symops())
350364
sgcif = self.ptest.spacegroup
351-
self.assertEqual(h225, _hashSymOpList(sgcif.iter_symops()))
365+
self.assertEqual(h225, _hash_symop_list(sgcif.iter_symops()))
352366
return
353367

354368
def test_nosites_cif(self):

0 commit comments

Comments
 (0)