Skip to content

Commit fe2ac51

Browse files
authored
Merge pull request #172 from stevenhua0320/deprecate-utils
chore: deprecate utils method and private methods in parsers
2 parents 64aa1c7 + 6286234 commit fe2ac51

File tree

5 files changed

+151
-54
lines changed

5 files changed

+151
-54
lines changed

news/deprecate-utils.rst

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
**Added:**
2+
3+
* Added ``atom_bare_symbol`` method in ``utils.py``
4+
* Added ``_get_ordered_formats`` method in ``p_auto.py``
5+
* Added ``_wrap_parse_method`` method in ``p_auto.py``
6+
* Added ``_tr_atom_site_u_iso_or_equiv`` method in ``p_cif.py``
7+
* Added ``_tr_atom_site_b_iso_or_equiv`` method in ``p_cif.py``
8+
* Added ``_tr_atom_site_aniso_u_11`` method in ``p_cif.py``
9+
* Added ``_tr_atom_site_aniso_u_22`` method in ``p_cif.py``
10+
* Added ``_tr_atom_site_aniso_u_33`` method in ``p_cif.py``
11+
* Added ``_tr_atom_site_aniso_u_12`` method in ``p_cif.py``
12+
* Added ``_tr_atom_site_aniso_u_13`` method in ``p_cif.py``
13+
* Added ``_tr_atom_site_aniso_u_23`` method in ``p_cif.py``
14+
* Added ``_tr_atom_site_aniso_b_11`` method in ``p_cif.py``
15+
* Added ``_tr_atom_site_aniso_b_22`` method in ``p_cif.py``
16+
* Added ``_tr_atom_site_aniso_b_33`` method in ``p_cif.py``
17+
* Added ``_tr_atom_site_aniso_b_12`` method in ``p_cif.py``
18+
* Added ``_tr_atom_site_aniso_b_13`` method in ``p_cif.py``
19+
* Added ``_tr_atom_site_aniso_b_23`` method in ``p_cif.py``
20+
21+
**Changed:**
22+
23+
* <news item>
24+
25+
**Deprecated:**
26+
27+
* Deprecated ``atomBareSymbol`` method in ``utils.py`` for removal in version 4.0.0
28+
29+
**Removed:**
30+
31+
* <news item>
32+
33+
**Fixed:**
34+
35+
* <news item>
36+
37+
**Security:**
38+
39+
* <news item>

src/diffpy/structure/parsers/p_auto.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def __init__(self, **kw):
5151
return
5252

5353
# parseLines helpers
54-
def _getOrderedFormats(self):
54+
def _get_ordered_formats(self):
5555
"""Build a list of relevance ordered structure formats.
5656
5757
This only works when `self.filename` has a known extension.
@@ -96,7 +96,7 @@ def parseLines(self, lines):
9696
------
9797
StructureFormatError
9898
"""
99-
return self._wrapParseMethod("parseLines", lines)
99+
return self._wrap_parse_method("parseLines", lines)
100100

101101
def parse(self, s):
102102
"""Detect format and create `Structure` instance from a string.
@@ -117,7 +117,7 @@ def parse(self, s):
117117
------
118118
StructureFormatError
119119
"""
120-
return self._wrapParseMethod("parse", s)
120+
return self._wrap_parse_method("parse", s)
121121

122122
def parseFile(self, filename):
123123
"""Detect format and create Structure instance from an existing
@@ -143,9 +143,9 @@ def parseFile(self, filename):
143143
If the file cannot be read.
144144
"""
145145
self.filename = filename
146-
return self._wrapParseMethod("parseFile", filename)
146+
return self._wrap_parse_method("parseFile", filename)
147147

148-
def _wrapParseMethod(self, method, *args, **kwargs):
148+
def _wrap_parse_method(self, method, *args, **kwargs):
149149
"""A helper evaluator method that try the specified parse method
150150
with each registered structure parser and return the first
151151
successful result.
@@ -173,7 +173,7 @@ def _wrapParseMethod(self, method, *args, **kwargs):
173173
"""
174174
from diffpy.structure.parsers import getParser
175175

176-
ofmts = self._getOrderedFormats()
176+
ofmts = self._get_ordered_formats()
177177
stru = None
178178
# try all parsers in sequence
179179
parsers_emsgs = []

src/diffpy/structure/parsers/p_cif.py

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -104,23 +104,23 @@ class P_cif(StructureParser):
104104
"_tr_atom_site_cartn_x",
105105
"_tr_atom_site_cartn_y",
106106
"_tr_atom_site_cartn_z",
107-
"_tr_atom_site_U_iso_or_equiv",
108-
"_tr_atom_site_B_iso_or_equiv",
107+
"_tr_atom_site_u_iso_or_equiv",
108+
"_tr_atom_site_b_iso_or_equiv",
109109
"_tr_atom_site_adp_type",
110110
"_tr_atom_site_thermal_displace_type",
111111
"_tr_atom_site_occupancy",
112-
"_tr_atom_site_aniso_U_11",
113-
"_tr_atom_site_aniso_U_22",
114-
"_tr_atom_site_aniso_U_33",
115-
"_tr_atom_site_aniso_U_12",
116-
"_tr_atom_site_aniso_U_13",
117-
"_tr_atom_site_aniso_U_23",
118-
"_tr_atom_site_aniso_B_11",
119-
"_tr_atom_site_aniso_B_22",
120-
"_tr_atom_site_aniso_B_33",
121-
"_tr_atom_site_aniso_B_12",
122-
"_tr_atom_site_aniso_B_13",
123-
"_tr_atom_site_aniso_B_23",
112+
"_tr_atom_site_aniso_u_11",
113+
"_tr_atom_site_aniso_u_22",
114+
"_tr_atom_site_aniso_u_33",
115+
"_tr_atom_site_aniso_u_12",
116+
"_tr_atom_site_aniso_u_13",
117+
"_tr_atom_site_aniso_u_23",
118+
"_tr_atom_site_aniso_b_11",
119+
"_tr_atom_site_aniso_b_22",
120+
"_tr_atom_site_aniso_b_33",
121+
"_tr_atom_site_aniso_b_12",
122+
"_tr_atom_site_aniso_b_13",
123+
"_tr_atom_site_aniso_b_23",
124124
)
125125
)
126126
# make _atom_setters case insensitive
@@ -185,15 +185,15 @@ def _tr_atom_site_cartn_z(a, value):
185185

186186
_tr_atom_site_cartn_z = staticmethod(_tr_atom_site_cartn_z)
187187

188-
def _tr_atom_site_U_iso_or_equiv(a, value):
188+
def _tr_atom_site_u_iso_or_equiv(a, value):
189189
a.Uisoequiv = leading_float(value)
190190

191-
_tr_atom_site_U_iso_or_equiv = staticmethod(_tr_atom_site_U_iso_or_equiv)
191+
_tr_atom_site_u_iso_or_equiv = staticmethod(_tr_atom_site_u_iso_or_equiv)
192192

193-
def _tr_atom_site_B_iso_or_equiv(a, value):
193+
def _tr_atom_site_b_iso_or_equiv(a, value):
194194
a.Uisoequiv = P_cif.BtoU * leading_float(value)
195195

196-
_tr_atom_site_B_iso_or_equiv = staticmethod(_tr_atom_site_B_iso_or_equiv)
196+
_tr_atom_site_b_iso_or_equiv = staticmethod(_tr_atom_site_b_iso_or_equiv)
197197

198198
def _tr_atom_site_adp_type(a, value):
199199
a.anisotropy = value not in ("Uiso", "Biso")
@@ -206,65 +206,65 @@ def _tr_atom_site_occupancy(a, value):
206206

207207
_tr_atom_site_occupancy = staticmethod(_tr_atom_site_occupancy)
208208

209-
def _tr_atom_site_aniso_U_11(a, value):
209+
def _tr_atom_site_aniso_u_11(a, value):
210210
a.U11 = leading_float(value)
211211

212-
_tr_atom_site_aniso_U_11 = staticmethod(_tr_atom_site_aniso_U_11)
212+
_tr_atom_site_aniso_u_11 = staticmethod(_tr_atom_site_aniso_u_11)
213213

214-
def _tr_atom_site_aniso_U_22(a, value):
214+
def _tr_atom_site_aniso_u_22(a, value):
215215
a.U22 = leading_float(value)
216216

217-
_tr_atom_site_aniso_U_22 = staticmethod(_tr_atom_site_aniso_U_22)
217+
_tr_atom_site_aniso_u_22 = staticmethod(_tr_atom_site_aniso_u_22)
218218

219-
def _tr_atom_site_aniso_U_33(a, value):
219+
def _tr_atom_site_aniso_u_33(a, value):
220220
a.U33 = leading_float(value)
221221

222-
_tr_atom_site_aniso_U_33 = staticmethod(_tr_atom_site_aniso_U_33)
222+
_tr_atom_site_aniso_u_33 = staticmethod(_tr_atom_site_aniso_u_33)
223223

224-
def _tr_atom_site_aniso_U_12(a, value):
224+
def _tr_atom_site_aniso_u_12(a, value):
225225
a.U12 = leading_float(value)
226226

227-
_tr_atom_site_aniso_U_12 = staticmethod(_tr_atom_site_aniso_U_12)
227+
_tr_atom_site_aniso_u_12 = staticmethod(_tr_atom_site_aniso_u_12)
228228

229-
def _tr_atom_site_aniso_U_13(a, value):
229+
def _tr_atom_site_aniso_u_13(a, value):
230230
a.U13 = leading_float(value)
231231

232-
_tr_atom_site_aniso_U_13 = staticmethod(_tr_atom_site_aniso_U_13)
232+
_tr_atom_site_aniso_u_13 = staticmethod(_tr_atom_site_aniso_u_13)
233233

234-
def _tr_atom_site_aniso_U_23(a, value):
234+
def _tr_atom_site_aniso_u_23(a, value):
235235
a.U23 = leading_float(value)
236236

237-
_tr_atom_site_aniso_U_23 = staticmethod(_tr_atom_site_aniso_U_23)
237+
_tr_atom_site_aniso_u_23 = staticmethod(_tr_atom_site_aniso_u_23)
238238

239-
def _tr_atom_site_aniso_B_11(a, value):
239+
def _tr_atom_site_aniso_b_11(a, value):
240240
a.U11 = P_cif.BtoU * leading_float(value)
241241

242-
_tr_atom_site_aniso_B_11 = staticmethod(_tr_atom_site_aniso_B_11)
242+
_tr_atom_site_aniso_b_11 = staticmethod(_tr_atom_site_aniso_b_11)
243243

244-
def _tr_atom_site_aniso_B_22(a, value):
244+
def _tr_atom_site_aniso_b_22(a, value):
245245
a.U22 = P_cif.BtoU * leading_float(value)
246246

247-
_tr_atom_site_aniso_B_22 = staticmethod(_tr_atom_site_aniso_B_22)
247+
_tr_atom_site_aniso_b_22 = staticmethod(_tr_atom_site_aniso_b_22)
248248

249-
def _tr_atom_site_aniso_B_33(a, value):
249+
def _tr_atom_site_aniso_b_33(a, value):
250250
a.U33 = P_cif.BtoU * leading_float(value)
251251

252-
_tr_atom_site_aniso_B_33 = staticmethod(_tr_atom_site_aniso_B_33)
252+
_tr_atom_site_aniso_b_33 = staticmethod(_tr_atom_site_aniso_b_33)
253253

254-
def _tr_atom_site_aniso_B_12(a, value):
254+
def _tr_atom_site_aniso_b_12(a, value):
255255
a.U12 = P_cif.BtoU * leading_float(value)
256256

257-
_tr_atom_site_aniso_B_12 = staticmethod(_tr_atom_site_aniso_B_12)
257+
_tr_atom_site_aniso_b_12 = staticmethod(_tr_atom_site_aniso_b_12)
258258

259-
def _tr_atom_site_aniso_B_13(a, value):
259+
def _tr_atom_site_aniso_b_13(a, value):
260260
a.U13 = P_cif.BtoU * leading_float(value)
261261

262-
_tr_atom_site_aniso_B_13 = staticmethod(_tr_atom_site_aniso_B_13)
262+
_tr_atom_site_aniso_b_13 = staticmethod(_tr_atom_site_aniso_b_13)
263263

264-
def _tr_atom_site_aniso_B_23(a, value):
264+
def _tr_atom_site_aniso_b_23(a, value):
265265
a.U23 = P_cif.BtoU * leading_float(value)
266266

267-
_tr_atom_site_aniso_B_23 = staticmethod(_tr_atom_site_aniso_B_23)
267+
_tr_atom_site_aniso_b_23 = staticmethod(_tr_atom_site_aniso_b_23)
268268

269269
def _get_atom_setters(cifloop):
270270
"""Static method for finding translators of CifLoop items to
@@ -602,10 +602,10 @@ def _parse_space_group_symop_operation_xyz(self, block):
602602
if self.spacegroup is None:
603603
emsg = "CIF file has unknown space group identifier {!r}."
604604
raise StructureFormatError(emsg.format(sgid))
605-
self._expandAsymmetricUnit(block)
605+
self._expand_asymmetric_unit(block)
606606
return
607607

608-
def _expandAsymmetricUnit(self, block):
608+
def _expand_asymmetric_unit(self, block):
609609
"""Perform symmetry expansion of `self.stru` using
610610
`self.spacegroup`.
611611

src/diffpy/structure/utils.py

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,17 @@
1818

1919
import numpy
2020

21+
from diffpy.utils._deprecator import build_deprecation_message, deprecated
22+
23+
base = "diffpy.structure"
24+
removal_version = "4.0.0"
25+
atomBareSymbol_deprecation_msg = build_deprecation_message(
26+
base,
27+
"atomBareSymbol",
28+
"atom_bare_symbol",
29+
removal_version,
30+
)
31+
2132

2233
def isiterable(obj):
2334
"""``True`` if argument is iterable."""
@@ -35,7 +46,18 @@ def isfloat(s):
3546
return False
3647

3748

49+
@deprecated(atomBareSymbol_deprecation_msg)
3850
def atomBareSymbol(smbl):
51+
"""This function has been deprecated and will be removed in version
52+
4.0.0.
53+
54+
Please use diffpy.structure.atom_bare_symbol instead.
55+
"""
56+
57+
return atom_bare_symbol(smbl)
58+
59+
60+
def atom_bare_symbol(smbl):
3961
"""Remove atom type string stripped of isotope and ion charge
4062
symbols.
4163
@@ -54,14 +76,13 @@ def atomBareSymbol(smbl):
5476
5577
Examples
5678
--------
57-
>>> atomBareSymbol("Cl-")
79+
>>> atom_bare_symbol("Cl-")
5880
'Cl'
59-
>>> atomBareSymbol("Ca2+")
81+
>>> atom_bare_symbol("Ca2+")
6082
'Ca'
61-
>>> atomBareSymbol("12-C")
83+
>>> atom_bare_symbol("12-C")
6284
'C'
6385
"""
64-
6586
rv = smbl.strip().lstrip("0123456789-").rstrip("123456789+-")
6687
return rv
6788

tests/test_utils.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env python
2+
##############################################################################
3+
#
4+
# diffpy.structure Complex Modeling Initiative
5+
# (c) 2016 Brookhaven Science Associates,
6+
# Brookhaven National Laboratory.
7+
# All rights reserved.
8+
#
9+
# File coded by: Pavol Juhas
10+
#
11+
# See AUTHORS.txt for a list of people who contributed.
12+
# See LICENSE.txt for license information.
13+
#
14+
##############################################################################
15+
"""Test for Structure utilities."""
16+
import pytest
17+
18+
from diffpy.structure.utils import atom_bare_symbol, atomBareSymbol
19+
20+
21+
def test_atomBareSymbol():
22+
assert atomBareSymbol("Cl-") == "Cl"
23+
assert atomBareSymbol("Ca2+") == "Ca"
24+
assert atomBareSymbol("12-C") == "C"
25+
26+
27+
@pytest.mark.parametrize(
28+
"symbol, expected",
29+
[
30+
("Cl-", "Cl"),
31+
("Ca2+", "Ca"),
32+
("12-C", "C"),
33+
],
34+
)
35+
def test_atom_bare_symbol(symbol, expected):
36+
actual = atom_bare_symbol(symbol)
37+
assert actual == expected

0 commit comments

Comments
 (0)