Skip to content

chore: derepcate P_pdb method#177

Merged
sbillinge merged 1 commit intodiffpy:v3.4.0from
stevenhua0320:deprecate-parser-display
Mar 6, 2026
Merged

chore: derepcate P_pdb method#177
sbillinge merged 1 commit intodiffpy:v3.4.0from
stevenhua0320:deprecate-parser-display

Conversation

@stevenhua0320
Copy link
Contributor

@sbillinge ready to review. Note that I realized in the previous getParser and toLines process I missed to replace the deprecation docstring for all of the getParser and one of the function replacement to to_lines call. In this PR I also supplement that.

@codecov
Copy link

codecov bot commented Mar 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.15%. Comparing base (810ef8a) to head (c89466c).
⚠️ Report is 3 commits behind head on v3.4.0.

Additional details and impacted files
@@           Coverage Diff           @@
##           v3.4.0     #177   +/-   ##
=======================================
  Coverage   99.15%   99.15%           
=======================================
  Files          14       14           
  Lines        2359     2359           
=======================================
  Hits         2339     2339           
  Misses         20       20           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

return stru

def toLines(self, stru):
"""Convert `Structure` stru to a list of lines in PDFfit format.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stevenhua0320 this is a lot of lines being deleted. Normally, this would be the new function. Please can you check that everything is ok here and confirm before I merge this? Thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sbillinge I have checked this. This is because in the previous PR I forgot to replace the old function with the new function call. Originally I have created the new function but forgot to replace it. This is the current code in this branch. I also run the pytest and everything is right.

    def toLines(self, stru):
        """This function has been deprecated and will be removed in
        version 4.0.0.

        Please use diffpy.structure.P_pdffit.toLines instead.
        """
        return self.to_lines(stru)

    def to_lines(self, stru):
        """Convert `Structure` stru to a list of lines in PDFfit format.

        Parameters
        ----------
        stru : Structure
            Structure to be converted.

        Returns
        -------
        list of str
            List of lines in PDFfit format.
        """
        # 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

@sbillinge sbillinge merged commit a70bc27 into diffpy:v3.4.0 Mar 6, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants