Skip to content

Commit 810ef8a

Browse files
Merge branch 'v3.4.0' into deprecate-getParser
2 parents 70aa675 + 29ab7d8 commit 810ef8a

File tree

9 files changed

+240
-10
lines changed

9 files changed

+240
-10
lines changed

news/deprecate-toLine.rst

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
**Added:**
2+
3+
* Added ``_parse_cif_data_source`` method in ``p_cif.py``
4+
* Added ``_parse_cif_block`` method in ``p_cif.py``
5+
* Added ``to_lines`` method in ``p_cif.py``
6+
* Added ``to_lines`` method in ``p_pdb.py``
7+
* Added ``to_lines`` method in ``p_rawxyz.py``
8+
* Added ``to_lines`` method in ``p_xcfg.py``
9+
* Added ``to_lines`` method in ``p_xyz.py``
10+
* Added ``to_lines`` method in ``structureparser.py``
11+
* Added ``_lines_iterator`` method in ``p_discus.py``
12+
* Added ``to_lines`` method in ``p_discus.py``
13+
14+
**Changed:**
15+
16+
* <news item>
17+
18+
**Deprecated:**
19+
20+
* Deprecated ``toLines`` method in ``p_cif.py`` for removal in version 4.0.0
21+
* Deprecated ``toLines`` method in ``p_pdb.py`` for removal in version 4.0.0
22+
* Deprecated ``toLines`` method in ``p_rawxyz.py`` for removal in version 4.0.0
23+
* Deprecated ``toLines`` method in ``p_xcfg.py`` for removal in version 4.0.0
24+
* Deprecated ``toLines`` method in ``p_xyz.py`` for removal in version 4.0.0
25+
* Deprecated ``toLines`` method in ``structureparser.py`` for removal in version 4.0.0
26+
* Deprecated ``toLines`` method in ``p_discus.py`` for removal in version 4.0.0
27+
28+
**Removed:**
29+
30+
* <news item>
31+
32+
**Fixed:**
33+
34+
* <news item>
35+
36+
**Security:**
37+
38+
* <news item>

src/diffpy/structure/parsers/p_cif.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@
5656
"parse_file",
5757
removal_version,
5858
)
59+
toLines_deprecation_msg = build_deprecation_message(
60+
base,
61+
"toLines",
62+
"to_lines",
63+
removal_version,
64+
)
5965

6066

6167
class P_cif(StructureParser):
@@ -344,7 +350,7 @@ def parse(self, s):
344350
self.ciffile = None
345351
self.filename = ""
346352
fp = io.StringIO(s)
347-
rv = self._parseCifDataSource(fp)
353+
rv = self._parse_cif_data_source(fp)
348354
return rv
349355

350356
@deprecated(parseLines_deprecation_msg)
@@ -409,11 +415,11 @@ def parse_file(self, filename):
409415
"""
410416
self.ciffile = None
411417
self.filename = filename
412-
rv = self._parseCifDataSource(filename)
418+
rv = self._parse_cif_data_source(filename)
413419
# all good here
414420
return rv
415421

416-
def _parseCifDataSource(self, datasource):
422+
def _parse_cif_data_source(self, datasource):
417423
"""Open and process CIF data from the specified `datasource`.
418424
419425
Parameters
@@ -441,7 +447,7 @@ def _parseCifDataSource(self, datasource):
441447
# Ref: https://bitbucket.org/jamesrhester/pycifrw/issues/19
442448
self.ciffile = CifFile(datasource, grammar="auto")
443449
for blockname in self.ciffile.keys():
444-
self._parseCifBlock(blockname)
450+
self._parse_cif_block(blockname)
445451
# stop after reading the first structure
446452
if self.stru is not None:
447453
break
@@ -452,7 +458,7 @@ def _parseCifDataSource(self, datasource):
452458
raise e.with_traceback(exc_traceback)
453459
return self.stru
454460

455-
def _parseCifBlock(self, blockname):
461+
def _parse_cif_block(self, blockname):
456462
"""Translate CIF file block, skip blocks without
457463
`_atom_site_label`. Updates data members `stru`, `eau`.
458464
@@ -682,7 +688,16 @@ def _expand_asymmetric_unit(self, block):
682688

683689
# conversion to CIF ------------------------------------------------------
684690

691+
@deprecated(toLines_deprecation_msg)
685692
def toLines(self, stru):
693+
"""This function has been deprecated and will be removed in
694+
version 4.0.0.
695+
696+
Please use diffpy.structure.P_cif.to_lines instead.
697+
"""
698+
return self.to_lines(stru)
699+
700+
def to_lines(self, stru):
686701
"""Convert `Structure` to a list of lines in basic CIF format.
687702
688703
Parameters

src/diffpy/structure/parsers/p_discus.py

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,21 @@
2222
from diffpy.structure.structureerrors import StructureFormatError
2323
from diffpy.utils._deprecator import build_deprecation_message, deprecated
2424

25+
base = "diffpy.structure.P_discus"
26+
removal_version = "4.0.0"
27+
parseLines_deprecation_msg = build_deprecation_message(
28+
base,
29+
"parseLines",
30+
"parse_lines",
31+
removal_version,
32+
)
33+
toLines_deprecation_msg = build_deprecation_message(
34+
base,
35+
"toLines",
36+
"to_lines",
37+
removal_version,
38+
)
39+
2540

2641
class P_discus(StructureParser):
2742
"""Parser for DISCUS structure format. The parser chokes on molecule
@@ -60,6 +75,7 @@ def __init__(self):
6075
self.ncell_read = False
6176
return
6277

78+
@deprecated(parseLines_deprecation_msg)
6379
def parseLines(self, lines):
6480
"""Parse list of lines in DISCUS format.
6581
@@ -79,7 +95,7 @@ def parseLines(self, lines):
7995
If the file is not in DISCUS format.
8096
"""
8197
self.lines = lines
82-
ilines = self._linesIterator()
98+
ilines = self._lines_iterator()
8399
self.stru = PDFFitStructure()
84100
record_parsers = {
85101
"cell": self._parse_cell,
@@ -154,7 +170,7 @@ def parse_lines(self, lines):
154170
If the file is not in DISCUS format.
155171
"""
156172
self.lines = lines
157-
ilines = self._linesIterator()
173+
ilines = self._lines_iterator()
158174
self.stru = PDFFitStructure()
159175
record_parsers = {
160176
"cell": self._parse_cell,
@@ -210,7 +226,16 @@ def parse_lines(self, lines):
210226
raise e.with_traceback(exc_traceback)
211227
return self.stru
212228

229+
@deprecated(toLines_deprecation_msg)
213230
def toLines(self, stru):
231+
"""This function has been deprecated and will be removed in
232+
version 4.0.0.
233+
234+
Please use diffpy.structure.P_discus.to_lines instead.
235+
"""
236+
return self.to_lines(stru)
237+
238+
def to_lines(self, stru):
214239
"""Convert `Structure` stru to a list of lines in DISCUS format.
215240
216241
Parameters
@@ -258,7 +283,7 @@ def toLines(self, stru):
258283
)
259284
return lines
260285

261-
def _linesIterator(self):
286+
def _lines_iterator(self):
262287
"""Iterator over `self.lines`, which increments `self.nl`"""
263288
# ignore trailing empty lines
264289
stop = len(self.lines)

src/diffpy/structure/parsers/p_pdb.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@
3939
"parse_lines",
4040
removal_version,
4141
)
42+
toLines_deprecation_msg = build_deprecation_message(
43+
base,
44+
"toLines",
45+
"to_lines",
46+
removal_version,
47+
)
4248

4349

4450
class P_pdb(StructureParser):
@@ -396,7 +402,16 @@ def atomLines(self, stru, idx):
396402
lines.append(line)
397403
return lines
398404

405+
@deprecated(toLines_deprecation_msg)
399406
def toLines(self, stru):
407+
"""This function has been deprecated and will be removed in
408+
version 4.0.0.
409+
410+
Please use diffpy.structure.P_pdb.to_lines instead.
411+
"""
412+
return self.to_lines(stru)
413+
414+
def to_lines(self, stru):
400415
"""Convert `Structure` stru to a list of lines in PDB format.
401416
402417
Parameters

src/diffpy/structure/parsers/p_pdffit.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,83 @@ def toLines(self, stru):
274274
lines.append(" %18.8f %17.8f %17.8f" % sigUij)
275275
return lines
276276

277+
def to_lines(self, stru):
278+
"""Convert `Structure` stru to a list of lines in PDFfit format.
279+
280+
Parameters
281+
----------
282+
stru : Structure
283+
Structure to be converted.
284+
285+
Returns
286+
-------
287+
list of str
288+
List of lines in PDFfit format.
289+
"""
290+
# build the stru_pdffit dictionary initialized from the defaults
291+
# in PDFFitStructure
292+
stru_pdffit = PDFFitStructure().pdffit
293+
if stru.pdffit:
294+
stru_pdffit.update(stru.pdffit)
295+
lines = []
296+
# default values of standard deviations
297+
d_sigxyz = numpy.zeros(3, dtype=float)
298+
d_sigo = 0.0
299+
d_sigU = numpy.zeros((3, 3), dtype=float)
300+
# here we can start
301+
line = "title " + stru.title
302+
lines.append(line.strip())
303+
lines.append("format pdffit")
304+
lines.append("scale %9.6f" % stru_pdffit["scale"])
305+
lines.append(
306+
"sharp %9.6f, %9.6f, %9.6f, %9.6f"
307+
% (
308+
stru_pdffit["delta2"],
309+
stru_pdffit["delta1"],
310+
stru_pdffit["sratio"],
311+
stru_pdffit["rcut"],
312+
)
313+
)
314+
lines.append("spcgr " + stru_pdffit["spcgr"])
315+
if stru_pdffit.get("spdiameter", 0.0) > 0.0:
316+
line = "shape sphere, %g" % stru_pdffit["spdiameter"]
317+
lines.append(line)
318+
if stru_pdffit.get("stepcut", 0.0) > 0.0:
319+
line = "shape stepcut, %g" % stru_pdffit["stepcut"]
320+
lines.append(line)
321+
lat = stru.lattice
322+
lines.append(
323+
"cell %9.6f, %9.6f, %9.6f, %9.6f, %9.6f, %9.6f"
324+
% (lat.a, lat.b, lat.c, lat.alpha, lat.beta, lat.gamma)
325+
)
326+
lines.append("dcell %9.6f, %9.6f, %9.6f, %9.6f, %9.6f, %9.6f" % tuple(stru_pdffit["dcell"]))
327+
lines.append("ncell %9i, %9i, %9i, %9i" % (1, 1, 1, len(stru)))
328+
lines.append("atoms")
329+
for a in stru:
330+
ad = a.__dict__
331+
lines.append(
332+
"%-4s %17.8f %17.8f %17.8f %12.4f"
333+
% (
334+
a.element.upper(),
335+
a.xyz[0],
336+
a.xyz[1],
337+
a.xyz[2],
338+
a.occupancy,
339+
)
340+
)
341+
sigmas = numpy.concatenate((ad.get("sigxyz", d_sigxyz), [ad.get("sigo", d_sigo)]))
342+
lines.append(" %18.8f %17.8f %17.8f %12.4f" % tuple(sigmas))
343+
sigU = ad.get("sigU", d_sigU)
344+
Uii = (a.U[0][0], a.U[1][1], a.U[2][2])
345+
Uij = (a.U[0][1], a.U[0][2], a.U[1][2])
346+
sigUii = (sigU[0][0], sigU[1][1], sigU[2][2])
347+
sigUij = (sigU[0][1], sigU[0][2], sigU[1][2])
348+
lines.append(" %18.8f %17.8f %17.8f" % Uii)
349+
lines.append(" %18.8f %17.8f %17.8f" % sigUii)
350+
lines.append(" %18.8f %17.8f %17.8f" % Uij)
351+
lines.append(" %18.8f %17.8f %17.8f" % sigUij)
352+
return lines
353+
277354
# Protected methods ------------------------------------------------------
278355

279356
def _parse_shape(self, line):

src/diffpy/structure/parsers/p_rawxyz.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@
3434
"parse_lines",
3535
removal_version,
3636
)
37+
toLines_deprecation_msg = build_deprecation_message(
38+
base,
39+
"toLines",
40+
"to_lines",
41+
removal_version,
42+
)
3743

3844

3945
class P_rawxyz(StructureParser):
@@ -130,7 +136,16 @@ def parse_lines(self, lines):
130136
raise e.with_traceback(exc_traceback)
131137
return stru
132138

139+
@deprecated(toLines_deprecation_msg)
133140
def toLines(self, stru):
141+
"""This function has been deprecated and will be removed in
142+
version 4.0.0.
143+
144+
Please use diffpy.structure.P_rawxyz.to_lines instead.
145+
"""
146+
return self.to_lines(stru)
147+
148+
def to_lines(self, stru):
134149
"""Convert Structure stru to a list of lines in RAWXYZ format.
135150
136151
Parameters

src/diffpy/structure/parsers/p_xcfg.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,12 @@
160160
"parse_lines",
161161
removal_version,
162162
)
163+
toLines_deprecation_msg = build_deprecation_message(
164+
base,
165+
"toLines",
166+
"to_lines",
167+
removal_version,
168+
)
163169

164170

165171
class P_xcfg(StructureParser):
@@ -309,7 +315,16 @@ def parse_lines(self, lines):
309315
raise e.with_traceback(exc_traceback)
310316
return stru
311317

318+
@deprecated(toLines_deprecation_msg)
312319
def toLines(self, stru):
320+
"""This function has been deprecated and will be removed in
321+
version 4.0.0.
322+
323+
Please use diffpy.structure.P_xcfg.to_lines instead.
324+
"""
325+
return self.to_lines(stru)
326+
327+
def to_lines(self, stru):
313328
"""Convert Structure stru to a list of lines in XCFG atomeye
314329
format.
315330

src/diffpy/structure/parsers/p_xyz.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@
3434
"parse_lines",
3535
removal_version,
3636
)
37+
toLines_deprecation_msg = build_deprecation_message(
38+
base,
39+
"toLines",
40+
"to_lines",
41+
removal_version,
42+
)
3743

3844

3945
class P_xyz(StructureParser):
@@ -140,7 +146,16 @@ def parse_lines(self, lines):
140146
raise StructureFormatError(emsg)
141147
return stru
142148

149+
@deprecated(toLines_deprecation_msg)
143150
def toLines(self, stru):
151+
"""This function has been deprecated and will be removed in
152+
version 4.0.0.
153+
154+
Please use diffpy.structure.P_xyz.to_lines instead.
155+
"""
156+
return self.to_lines(stru)
157+
158+
def to_lines(self, stru):
144159
"""Convert Structure stru to a list of lines in XYZ format.
145160
146161
Parameters

0 commit comments

Comments
 (0)