diff --git a/news/deprecate-parser-display.rst b/news/deprecate-parser-display.rst new file mode 100644 index 0000000..4aaa4e0 --- /dev/null +++ b/news/deprecate-parser-display.rst @@ -0,0 +1,31 @@ +**Added:** + +* Added ``input_formats`` method in ``parsers/__init__.py`` +* Added ``output_formats`` method in ``parsers/__init__.py`` +* Added ``title_lines`` method in ``p_pdb.py`` +* Added ``cryst1_lines`` method in ``p_pdb.py`` +* Added ``atom_lines`` method in ``p_pdb.py`` + +**Changed:** + +* + +**Deprecated:** + +* Deprecated ``inputFormats`` method in ``parsers/__init__.py`` for removal in version 4.0.0 +* Deprecated ``outputFormats`` method in ``parsers/__init__.py`` for removal in version 4.0.0 +* Deprecated ``titleLines`` method in ``p_pdb.py`` for removal in version 4.0.0 +* Deprecated ``crystl1Lines`` method in ``p_pdb.py`` for removal in version 4.0.0 +* Deprecated ``atomLines`` method in ``p_pdb.py`` for removal in version 4.0.0 + +**Removed:** + +* + +**Fixed:** + +* + +**Security:** + +* diff --git a/src/diffpy/structure/apps/anyeye.py b/src/diffpy/structure/apps/anyeye.py index b75c5bd..56e16f4 100755 --- a/src/diffpy/structure/apps/anyeye.py +++ b/src/diffpy/structure/apps/anyeye.py @@ -72,9 +72,9 @@ def usage(style=None): if style == "brief": msg = msg.split("\n")[1] + "\n" + "Try `%s --help' for more information." % myname else: - from diffpy.structure.parsers import inputFormats + from diffpy.structure.parsers import input_formats - fmts = [f for f in inputFormats() if f != "auto"] + fmts = [f for f in input_formats() if f != "auto"] msg = msg.replace("inputFormats", " ".join(fmts)) print(msg) return diff --git a/src/diffpy/structure/apps/transtru.py b/src/diffpy/structure/apps/transtru.py index 7155a86..d942564 100755 --- a/src/diffpy/structure/apps/transtru.py +++ b/src/diffpy/structure/apps/transtru.py @@ -52,10 +52,10 @@ def usage(style=None): if style == "brief": msg = msg.split("\n")[1] + "\n" + "Try `%s --help' for more information." % myname else: - from diffpy.structure.parsers import inputFormats, outputFormats + from diffpy.structure.parsers import input_formats, output_formats - msg = msg.replace("inputFormats", " ".join(inputFormats())) - msg = msg.replace("outputFormats", " ".join(outputFormats())) + msg = msg.replace("inputFormats", " ".join(input_formats())) + msg = msg.replace("outputFormats", " ".join(output_formats())) print(msg) return @@ -88,14 +88,14 @@ def main(): usage("brief") sys.exit() # process arguments - from diffpy.structure.parsers import inputFormats, outputFormats + from diffpy.structure.parsers import input_formats, output_formats try: infmt, outfmt = args[0].split("..", 1) - if infmt not in inputFormats(): + if infmt not in input_formats(): print("'%s' is not valid input format" % infmt, file=sys.stderr) sys.exit(2) - if outfmt not in outputFormats(): + if outfmt not in output_formats(): print("'%s' is not valid output format" % outfmt, file=sys.stderr) sys.exit(2) except ValueError: diff --git a/src/diffpy/structure/parsers/__init__.py b/src/diffpy/structure/parsers/__init__.py index 6bf1231..124b91a 100644 --- a/src/diffpy/structure/parsers/__init__.py +++ b/src/diffpy/structure/parsers/__init__.py @@ -46,28 +46,26 @@ "get_parser", removal_version, ) +inputFormats_deprecation_msg = build_deprecation_message( + parsers_base, + "inputFormats", + "input_formats", + removal_version, +) +outputFormats_deprecation_msg = build_deprecation_message( + parsers_base, + "outputFormats", + "output_formats", + removal_version, +) @deprecated(getParser_deprecation_msg) def getParser(format, **kw): - """Return Parser instance for a given structure format. - - Parameters - ---------- - format : str - String with the format name, see `parser_index_mod`. - **kw : dict - Keyword arguments passed to the Parser init function. + """This function has been deprecated and will be removed in version + 4.0.0. - Returns - ------- - Parser - Parser instance for the given format. - - Raises - ------ - StructureFormatError - When the format is not defined. + Please use diffpy.structure.get_parser instead. """ return get_parser(format, **kw) @@ -102,14 +100,34 @@ def get_parser(format, **kw): return ns["pm"].get_parser(**kw) +@deprecated(inputFormats_deprecation_msg) def inputFormats(): + """This function has been deprecated and will be removed in version + 4.0.0. + + Please use diffpy.structure.input_formats instead. + """ + return input_formats() + + +def input_formats(): """Return list of implemented input structure formats.""" input_formats = [fmt for fmt, prop in parser_index.items() if prop["has_input"]] input_formats.sort() return input_formats +@deprecated(outputFormats_deprecation_msg) def outputFormats(): + """This function has been deprecated and will be removed in version + 4.0.0. + + Please use diffpy.structure.output_formats instead. + """ + return output_formats() + + +def output_formats(): """Return list of implemented output structure formats.""" output_formats = [fmt for fmt, prop in parser_index.items() if prop["has_output"]] output_formats.sort() diff --git a/src/diffpy/structure/parsers/p_auto.py b/src/diffpy/structure/parsers/p_auto.py index eb5fbe3..a0683d5 100644 --- a/src/diffpy/structure/parsers/p_auto.py +++ b/src/diffpy/structure/parsers/p_auto.py @@ -73,9 +73,9 @@ def _get_ordered_formats(self): This only works when `self.filename` has a known extension. """ - from diffpy.structure.parsers import inputFormats + from diffpy.structure.parsers import input_formats - ofmts = [fmt for fmt in inputFormats() if fmt != "auto"] + ofmts = [fmt for fmt in input_formats() if fmt != "auto"] if not self.filename: return ofmts # filename is defined here @@ -252,17 +252,10 @@ def _wrap_parse_method(self, method: object, *args: object, **kwargs: object) -> @deprecated(getParser_deprecation_msg) def getParser(**kw): - """Return a new instance of the automatic parser. - - Parameters - ---------- - **kw : dict - Keyword arguments for the structure parser + """This function has been deprecated and will be removed in version + 4.0.0. - Returns - ------- - P_auto - Instance of `P_auto`. + Please use diffpy.structure.P_auto.get_parser instead. """ return get_parser(**kw) diff --git a/src/diffpy/structure/parsers/p_cif.py b/src/diffpy/structure/parsers/p_cif.py index 2f58bd5..679c4cc 100644 --- a/src/diffpy/structure/parsers/p_cif.py +++ b/src/diffpy/structure/parsers/p_cif.py @@ -910,18 +910,10 @@ def getSymOp(s): @deprecated(getParser_deprecation_msg) def getParser(eps=None): - """Return new `parser` object for CIF format. + """This function has been deprecated and will be removed in version + 4.0.0. - Parameters - ---------- - eps : float, Optional - fractional coordinates cutoff for duplicate positions. - When ``None`` use the default for `ExpandAsymmetricUnit`: ``1.0e-5``. - - Returns - ------- - P_cif - Instance of `P_cif`. + Please use diffpy.structure.P_cif.get_parser instead. """ return get_parser(eps) diff --git a/src/diffpy/structure/parsers/p_discus.py b/src/diffpy/structure/parsers/p_discus.py index 0fc7122..3e77b55 100644 --- a/src/diffpy/structure/parsers/p_discus.py +++ b/src/diffpy/structure/parsers/p_discus.py @@ -424,12 +424,10 @@ def _parse_not_implemented(self, words): @deprecated(getParser_deprecation_msg) def getParser(): - """Return new `parser` object for DISCUS format. + """This function has been deprecated and will be removed in version + 4.0.0. - Returns - ------- - P_discus - Instance of `P_discus`. + Please use diffpy.structure.P_discus.get_parser instead. """ return get_parser() diff --git a/src/diffpy/structure/parsers/p_pdb.py b/src/diffpy/structure/parsers/p_pdb.py index 7e3bbef..98bc4b7 100644 --- a/src/diffpy/structure/parsers/p_pdb.py +++ b/src/diffpy/structure/parsers/p_pdb.py @@ -45,6 +45,24 @@ "to_lines", removal_version, ) +titleLines_deprecation_msg = build_deprecation_message( + base, + "titleLines", + "title_lines", + removal_version, +) +cryst1Lines_deprecation_msg = build_deprecation_message( + base, + "cryst1Lines", + "cryst1_lines", + removal_version, +) +atomLines_deprecation_msg = build_deprecation_message( + base, + "atomLines", + "atom_lines", + removal_version, +) class P_pdb(StructureParser): @@ -269,7 +287,12 @@ def parse_lines(self, lines): raise e.with_traceback(exc_traceback) return stru + @deprecated(titleLines_deprecation_msg) def titleLines(self, stru): + """Build lines corresponding to `TITLE` record.""" + return self.title_lines(stru) + + def title_lines(self, stru): """Build lines corresponding to `TITLE` record.""" lines = [] title = stru.title @@ -288,7 +311,12 @@ def titleLines(self, stru): title = title[stop:] return lines + @deprecated(cryst1Lines_deprecation_msg) def cryst1Lines(self, stru): + """Build lines corresponding to `CRYST1` record.""" + return self.cryst1_lines(stru) + + def cryst1_lines(self, stru): """Build lines corresponding to `CRYST1` record.""" lines = [] latpar = ( @@ -304,7 +332,13 @@ def cryst1Lines(self, stru): lines.append("%-80s" % line) return lines + @deprecated(atomLines_deprecation_msg) def atomLines(self, stru, idx): + """Build `ATOM` records and possibly `SIGATM`, `ANISOU` or + `SIGUIJ` records for `structure` stru `atom` number aidx.""" + return self.atom_lines(stru, idx) + + def atom_lines(self, stru, idx): """Build `ATOM` records and possibly `SIGATM`, `ANISOU` or `SIGUIJ` records for `structure` stru `atom` number aidx.""" lines = [] @@ -425,10 +459,10 @@ def to_lines(self, stru): List of lines in PDB format. """ lines = [] - lines.extend(self.titleLines(stru)) - lines.extend(self.cryst1Lines(stru)) + lines.extend(self.title_lines(stru)) + lines.extend(self.cryst1_lines(stru)) for idx in range(len(stru)): - lines.extend(self.atomLines(stru, idx)) + lines.extend(self.atom_lines(stru, idx)) line = ( "TER " # 1-6 + "%(serial)5i " # 7-11, 12-17 diff --git a/src/diffpy/structure/parsers/p_pdffit.py b/src/diffpy/structure/parsers/p_pdffit.py index bc3f187..2347f3f 100644 --- a/src/diffpy/structure/parsers/p_pdffit.py +++ b/src/diffpy/structure/parsers/p_pdffit.py @@ -198,81 +198,12 @@ def parse_lines(self, lines): return stru def toLines(self, stru): - """Convert `Structure` stru to a list of lines in PDFfit format. - - Parameters - ---------- - stru : Structure - Structure to be converted. + """This function has been deprecated and will be removed in + version 4.0.0. - Returns - ------- - list of str - List of lines in PDFfit format. + Please use diffpy.structure.P_pdffit.toLines instead. """ - # build the stru_pdffit dictionary initialized from the defaults - # in PDFFitStructure - stru_pdffit = PDFFitStructure().pdffit - if stru.pdffit: - stru_pdffit.update(stru.pdffit) - lines = [] - # default values of standard deviations - d_sigxyz = numpy.zeros(3, dtype=float) - d_sigo = 0.0 - d_sigU = numpy.zeros((3, 3), dtype=float) - # here we can start - line = "title " + stru.title - lines.append(line.strip()) - lines.append("format pdffit") - lines.append("scale %9.6f" % stru_pdffit["scale"]) - lines.append( - "sharp %9.6f, %9.6f, %9.6f, %9.6f" - % ( - stru_pdffit["delta2"], - stru_pdffit["delta1"], - stru_pdffit["sratio"], - stru_pdffit["rcut"], - ) - ) - lines.append("spcgr " + stru_pdffit["spcgr"]) - if stru_pdffit.get("spdiameter", 0.0) > 0.0: - line = "shape sphere, %g" % stru_pdffit["spdiameter"] - lines.append(line) - if stru_pdffit.get("stepcut", 0.0) > 0.0: - line = "shape stepcut, %g" % stru_pdffit["stepcut"] - lines.append(line) - lat = stru.lattice - lines.append( - "cell %9.6f, %9.6f, %9.6f, %9.6f, %9.6f, %9.6f" - % (lat.a, lat.b, lat.c, lat.alpha, lat.beta, lat.gamma) - ) - lines.append("dcell %9.6f, %9.6f, %9.6f, %9.6f, %9.6f, %9.6f" % tuple(stru_pdffit["dcell"])) - lines.append("ncell %9i, %9i, %9i, %9i" % (1, 1, 1, len(stru))) - lines.append("atoms") - for a in stru: - ad = a.__dict__ - lines.append( - "%-4s %17.8f %17.8f %17.8f %12.4f" - % ( - a.element.upper(), - a.xyz[0], - a.xyz[1], - a.xyz[2], - a.occupancy, - ) - ) - sigmas = numpy.concatenate((ad.get("sigxyz", d_sigxyz), [ad.get("sigo", d_sigo)])) - lines.append(" %18.8f %17.8f %17.8f %12.4f" % tuple(sigmas)) - sigU = ad.get("sigU", d_sigU) - Uii = (a.U[0][0], a.U[1][1], a.U[2][2]) - Uij = (a.U[0][1], a.U[0][2], a.U[1][2]) - sigUii = (sigU[0][0], sigU[1][1], sigU[2][2]) - sigUij = (sigU[0][1], sigU[0][2], sigU[1][2]) - lines.append(" %18.8f %17.8f %17.8f" % Uii) - lines.append(" %18.8f %17.8f %17.8f" % sigUii) - lines.append(" %18.8f %17.8f %17.8f" % Uij) - lines.append(" %18.8f %17.8f %17.8f" % sigUij) - return lines + return self.to_lines(stru) def to_lines(self, stru): """Convert `Structure` stru to a list of lines in PDFfit format. @@ -386,12 +317,10 @@ def _parse_shape(self, line): def getParser(): - """Return new `parser` object for PDFfit format. + """This function has been deprecated and will be removed in version + 4.0.0. - Returns - ------- - P_pdffit - Instance of `P_pdffit`. + Please use diffpy.structure.P_pdffit.get_parser instead. """ return get_parser() diff --git a/src/diffpy/structure/parsers/p_rawxyz.py b/src/diffpy/structure/parsers/p_rawxyz.py index fc115fa..2a8332b 100644 --- a/src/diffpy/structure/parsers/p_rawxyz.py +++ b/src/diffpy/structure/parsers/p_rawxyz.py @@ -181,12 +181,10 @@ def to_lines(self, stru): @deprecated(getParser_deprecation_msg) def getParser(): - """Return new `parser` object for RAWXYZ format. + """This function has been deprecated and will be removed in version + 4.0.0. - Returns - ------- - P_rawxyz - Instance of `P_rawxyz`. + Please use diffpy.structure.P_rawxyz.get_parser instead. """ return get_parser() diff --git a/src/diffpy/structure/parsers/p_xcfg.py b/src/diffpy/structure/parsers/p_xcfg.py index c5709a8..7965767 100644 --- a/src/diffpy/structure/parsers/p_xcfg.py +++ b/src/diffpy/structure/parsers/p_xcfg.py @@ -458,12 +458,10 @@ def to_lines(self, stru): @deprecated(getParser_deprecation_msg) def getParser(): - """Return new `parser` object for XCFG format. + """This function has been deprecated and will be removed in version + 4.0.0. - Returns - ------- - P_xcfg - Instance of `P_xcfg`. + Please use diffpy.structure.P_xcfg.get_parser instead. """ return get_parser() diff --git a/src/diffpy/structure/parsers/p_xyz.py b/src/diffpy/structure/parsers/p_xyz.py index 0238ecc..60c8dd8 100644 --- a/src/diffpy/structure/parsers/p_xyz.py +++ b/src/diffpy/structure/parsers/p_xyz.py @@ -193,12 +193,10 @@ def to_lines(self, stru): @deprecated(getParser_deprecation_msg) def getParser(): - """Return new `parser` object for XYZ format. + """This function has been deprecated and will be removed in version + 4.0.0. - Returns - ------- - P_xcfg - Instance of `P_xyz`. + Please use diffpy.structure.P_xyz.get_parser instead. """ return get_parser()