Skip to content

Run black . without any manual modification #73

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions doc/examples/coreshellnp.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def makeRecipe(stru1, stru2, datname):
# phases, we implicitly assume that the core-shell correlations contribute
# very little to the PDF.
from diffpy.srfit.pdf.characteristicfunctions import shellCF, sphericalCF

contribution.registerFunction(sphericalCF, name="f_CdS")
contribution.registerFunction(shellCF, name="f_ZnS")

Expand Down Expand Up @@ -137,10 +138,11 @@ def plotResults(recipe):
diff = g - gcalc + diffzero

import pylab
pylab.plot(r, g, 'bo', label="G(r) Data")
pylab.plot(r, gcalc, 'r-', label="G(r) Fit")
pylab.plot(r, diff, 'g-', label="G(r) diff")
pylab.plot(r, diffzero, 'k-')

pylab.plot(r, g, "bo", label="G(r) Data")
pylab.plot(r, gcalc, "r-", label="G(r) Fit")
pylab.plot(r, diff, "g-", label="G(r) diff")
pylab.plot(r, diffzero, "k-")
pylab.xlabel(r"$r (\AA)$")
pylab.ylabel(r"$G (\AA^{-2})$")
pylab.legend(loc=1)
Expand All @@ -162,6 +164,7 @@ def main():
stru2 = loadCrystal(znsciffile)
recipe = makeRecipe(stru1, stru2, data)
from diffpy.srfit.fitbase.fithook import PlotFitHook

recipe.pushFitHook(PlotFitHook())
recipe.fithooks[0].verbose = 3

Expand Down
18 changes: 11 additions & 7 deletions doc/examples/crystalpdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

####### Example Code


def makeRecipe(ciffile, datname):
"""Create a fitting recipe for crystalline PDF data."""

Expand All @@ -50,7 +51,7 @@ def makeRecipe(ciffile, datname):
parser = PDFParser()
parser.parseFile(datname)
profile.loadParsedData(parser)
profile.setCalculationRange(xmax = 20)
profile.setCalculationRange(xmax=20)

## The ProfileGenerator
# The PDFGenerator is for configuring and calculating a PDF profile. Here,
Expand All @@ -69,7 +70,7 @@ def makeRecipe(ciffile, datname):
# before.
contribution = FitContribution("nickel")
contribution.addProfileGenerator(generator)
contribution.setProfile(profile, xname = "r")
contribution.setProfile(profile, xname="r")

## Make the FitRecipe and add the FitContribution.
recipe = FitRecipe()
Expand All @@ -92,6 +93,7 @@ def makeRecipe(ciffile, datname):
# documentation for more details. The 'constrainAsSpaceGroup' method may
# create new Parameters, which it returns in a SpaceGroupParameters object.
from diffpy.srfit.structure import constrainAsSpaceGroup

sgpars = constrainAsSpaceGroup(phase, "Fm-3m")

# The SpaceGroupParameters object returned by 'constrainAsSpaceGroup' holds
Expand Down Expand Up @@ -121,6 +123,7 @@ def makeRecipe(ciffile, datname):
# Give the recipe away so it can be used!
return recipe


def plotResults(recipe):
"""Plot the results contained within a refined FitRecipe."""

Expand All @@ -132,19 +135,20 @@ def plotResults(recipe):
diff = g - gcalc + diffzero

import pylab
pylab.plot(r,g,'bo',label="G(r) Data")
pylab.plot(r, gcalc,'r-',label="G(r) Fit")
pylab.plot(r,diff,'g-',label="G(r) diff")
pylab.plot(r,diffzero,'k-')

pylab.plot(r, g, "bo", label="G(r) Data")
pylab.plot(r, gcalc, "r-", label="G(r) Fit")
pylab.plot(r, diff, "g-", label="G(r) diff")
pylab.plot(r, diffzero, "k-")
pylab.xlabel(r"$r (\AA)$")
pylab.ylabel(r"$G (\AA^{-2})$")
pylab.legend(loc=1)

pylab.show()
return

if __name__ == "__main__":

if __name__ == "__main__":
# Make the data and the recipe
ciffile = "data/ni.cif"
data = "data/ni-q27r100-neutron.gr"
Expand Down
71 changes: 36 additions & 35 deletions doc/examples/crystalpdfall.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,26 @@

####### Example Code


def makeProfile(datafile):
"""Make an place data within a Profile."""
profile = Profile()
parser = PDFParser()
parser.parseFile(datafile)
profile.loadParsedData(parser)
profile.setCalculationRange(xmax = 20)
profile.setCalculationRange(xmax=20)
return profile


def makeContribution(name, generator, profile):
"""Make a FitContribution and add a generator and profile."""
contribution = FitContribution(name)
contribution.addProfileGenerator(generator)
contribution.setProfile(profile, xname = "r")
contribution.setProfile(profile, xname="r")
return contribution

def makeRecipe(ciffile_ni, ciffile_si, xdata_ni, ndata_ni, xdata_si,
xdata_sini):

def makeRecipe(ciffile_ni, ciffile_si, xdata_ni, ndata_ni, xdata_si, xdata_sini):
"""Create a fitting recipe for crystalline PDF data."""

## The Profiles
Expand Down Expand Up @@ -81,8 +83,7 @@ def makeRecipe(ciffile_ni, ciffile_si, xdata_ni, ndata_ni, xdata_si,
xcontribution_ni = makeContribution("xnickel", xgenerator_ni, xprofile_ni)
xcontribution_si = makeContribution("xsilicon", xgenerator_si, xprofile_si)
ncontribution_ni = makeContribution("nnickel", ngenerator_ni, nprofile_ni)
xcontribution_sini = makeContribution("xsini", xgenerator_sini_ni,
xprofile_sini)
xcontribution_sini = makeContribution("xsini", xgenerator_sini_ni, xprofile_sini)
xcontribution_sini.addProfileGenerator(xgenerator_sini_si)
xcontribution_sini.setEquation("scale * (xG_sini_ni + xG_sini_si)")

Expand All @@ -101,22 +102,22 @@ def makeRecipe(ciffile_ni, ciffile_si, xdata_ni, ndata_ni, xdata_si,

# Now we vary and constrain Parameters as before.
for par in phase_ni.sgpars:
recipe.addVar(par, name = par.name + "_ni")
recipe.addVar(par, name=par.name + "_ni")
delta2_ni = recipe.newVar("delta2_ni", 2.5)
recipe.constrain(xgenerator_ni.delta2, delta2_ni)
recipe.constrain(ngenerator_ni.delta2, delta2_ni)
recipe.constrain(xgenerator_sini_ni.delta2, delta2_ni)

for par in phase_si.sgpars:
recipe.addVar(par, name = par.name + "_si")
recipe.addVar(par, name=par.name + "_si")
delta2_si = recipe.newVar("delta2_si", 2.5)
recipe.constrain(xgenerator_si.delta2, delta2_si)
recipe.constrain(xgenerator_sini_si.delta2, delta2_si)

# Now the experimental parameters
recipe.addVar(xgenerator_ni.scale, name = "xscale_ni")
recipe.addVar(xgenerator_si.scale, name = "xscale_si")
recipe.addVar(ngenerator_ni.scale, name = "nscale_ni")
recipe.addVar(xgenerator_ni.scale, name="xscale_ni")
recipe.addVar(xgenerator_si.scale, name="xscale_si")
recipe.addVar(ngenerator_ni.scale, name="nscale_ni")
recipe.addVar(xcontribution_sini.scale, 1.0, "xscale_sini")
recipe.newVar("pscale_sini_ni", 0.8)
recipe.constrain(xgenerator_sini_ni.scale, "pscale_sini_ni")
Expand All @@ -133,6 +134,7 @@ def makeRecipe(ciffile_ni, ciffile_si, xdata_ni, ndata_ni, xdata_si,
# Give the recipe away so it can be used!
return recipe


def plotResults(recipe):
"""Plot the results contained within a refined FitRecipe."""

Expand All @@ -141,67 +143,67 @@ def plotResults(recipe):
xr_ni = xnickel.profile.x
xg_ni = xnickel.profile.y
xgcalc_ni = xnickel.profile.ycalc
xdiffzero_ni = -0.8 * max(xg_ni) * numpy.ones_like(xg_ni)
xdiffzero_ni = -0.8 * max(xg_ni) * numpy.ones_like(xg_ni)
xdiff_ni = xg_ni - xgcalc_ni + xdiffzero_ni

xsilicon = recipe.xsilicon
xr_si = xsilicon.profile.x
xg_si = xsilicon.profile.y
xgcalc_si = xsilicon.profile.ycalc
xdiffzero_si = -0.8 * max(xg_si) * numpy.ones_like(xg_si)
xdiffzero_si = -0.8 * max(xg_si) * numpy.ones_like(xg_si)
xdiff_si = xg_si - xgcalc_si + xdiffzero_si

nnickel = recipe.nnickel
nr_ni = nnickel.profile.x
ng_ni = nnickel.profile.y
ngcalc_ni = nnickel.profile.ycalc
ndiffzero_ni = -0.8 * max(ng_ni) * numpy.ones_like(ng_ni)
ndiffzero_ni = -0.8 * max(ng_ni) * numpy.ones_like(ng_ni)
ndiff_ni = ng_ni - ngcalc_ni + ndiffzero_ni

xsini = recipe.xsini
xr_sini = xsini.profile.x
xg_sini = xsini.profile.y
xgcalc_sini = xsini.profile.ycalc
xdiffzero_sini = -0.8 * max(xg_sini) * numpy.ones_like(xg_sini)
xdiffzero_sini = -0.8 * max(xg_sini) * numpy.ones_like(xg_sini)
xdiff_sini = xg_sini - xgcalc_sini + xdiffzero_sini


import pylab

pylab.subplot(2, 2, 1)
pylab.plot(xr_ni,xg_ni,'bo',label="G(r) x-ray nickel Data")
pylab.plot(xr_ni,xgcalc_ni,'r-',label="G(r) x-ray nickel Fit")
pylab.plot(xr_ni,xdiff_ni,'g-',label="G(r) x-ray nickel diff")
pylab.plot(xr_ni,xdiffzero_ni,'k-')
pylab.plot(xr_ni, xg_ni, "bo", label="G(r) x-ray nickel Data")
pylab.plot(xr_ni, xgcalc_ni, "r-", label="G(r) x-ray nickel Fit")
pylab.plot(xr_ni, xdiff_ni, "g-", label="G(r) x-ray nickel diff")
pylab.plot(xr_ni, xdiffzero_ni, "k-")
pylab.xlabel(r"$r (\AA)$")
pylab.ylabel(r"$G (\AA^{-2})$")
pylab.legend(loc=1)

pylab.subplot(2, 2, 2)
pylab.plot(xr_si,xg_si,'bo',label="G(r) x-ray silicon Data")
pylab.plot(xr_si,xgcalc_si,'r-',label="G(r) x-ray silicon Fit")
pylab.plot(xr_si,xdiff_si,'g-',label="G(r) x-ray silicon diff")
pylab.plot(xr_si,xdiffzero_si,'k-')
pylab.plot(xr_si, xg_si, "bo", label="G(r) x-ray silicon Data")
pylab.plot(xr_si, xgcalc_si, "r-", label="G(r) x-ray silicon Fit")
pylab.plot(xr_si, xdiff_si, "g-", label="G(r) x-ray silicon diff")
pylab.plot(xr_si, xdiffzero_si, "k-")
pylab.legend(loc=1)

pylab.subplot(2, 2, 3)
pylab.plot(nr_ni,ng_ni,'bo',label="G(r) neutron nickel Data")
pylab.plot(nr_ni,ngcalc_ni,'r-',label="G(r) neutron nickel Fit")
pylab.plot(nr_ni,ndiff_ni,'g-',label="G(r) neutron nickel diff")
pylab.plot(nr_ni,ndiffzero_ni,'k-')
pylab.plot(nr_ni, ng_ni, "bo", label="G(r) neutron nickel Data")
pylab.plot(nr_ni, ngcalc_ni, "r-", label="G(r) neutron nickel Fit")
pylab.plot(nr_ni, ndiff_ni, "g-", label="G(r) neutron nickel diff")
pylab.plot(nr_ni, ndiffzero_ni, "k-")
pylab.legend(loc=1)

pylab.subplot(2, 2, 4)
pylab.plot(xr_sini,xg_sini,'bo',label="G(r) x-ray sini Data")
pylab.plot(xr_sini,xgcalc_sini,'r-',label="G(r) x-ray sini Fit")
pylab.plot(xr_sini,xdiff_sini,'g-',label="G(r) x-ray sini diff")
pylab.plot(xr_sini,xdiffzero_sini,'k-')
pylab.plot(xr_sini, xg_sini, "bo", label="G(r) x-ray sini Data")
pylab.plot(xr_sini, xgcalc_sini, "r-", label="G(r) x-ray sini Fit")
pylab.plot(xr_sini, xdiff_sini, "g-", label="G(r) x-ray sini diff")
pylab.plot(xr_sini, xdiffzero_sini, "k-")
pylab.legend(loc=1)

pylab.show()
return

if __name__ == "__main__":

if __name__ == "__main__":
# Make the data and the recipe
ciffile_ni = "data/ni.cif"
ciffile_si = "data/si.cif"
Expand All @@ -211,8 +213,7 @@ def plotResults(recipe):
xdata_sini = "data/si90ni10-q27r60-xray.gr"

# Make the recipe
recipe = makeRecipe(ciffile_ni, ciffile_si, xdata_ni, ndata_ni, xdata_si,
xdata_sini)
recipe = makeRecipe(ciffile_ni, ciffile_si, xdata_ni, ndata_ni, xdata_si, xdata_sini)

# Optimize
scipyOptimize(recipe)
Expand Down
9 changes: 5 additions & 4 deletions doc/examples/crystalpdfobjcryst.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

####### Example Code


def makeRecipe(ciffile, datname):
"""Create a fitting recipe for crystalline PDF data."""

Expand All @@ -43,7 +44,7 @@ def makeRecipe(ciffile, datname):
parser = PDFParser()
parser.parseFile(datname)
profile.loadParsedData(parser)
profile.setCalculationRange(xmax = 20)
profile.setCalculationRange(xmax=20)

## The ProfileGenerator
# This time we use the CreateCrystalFromCIF method of pyobjcryst.crystal to
Expand All @@ -57,7 +58,7 @@ def makeRecipe(ciffile, datname):
## The FitContribution
contribution = FitContribution("nickel")
contribution.addProfileGenerator(generator)
contribution.setProfile(profile, xname = "r")
contribution.setProfile(profile, xname="r")

# Make the FitRecipe and add the FitContribution.
recipe = FitRecipe()
Expand Down Expand Up @@ -86,7 +87,7 @@ def makeRecipe(ciffile, datname):
for par in phase.sgpars:
recipe.addVar(par)
# set the initial thermal factor to a non-zero value
assert hasattr(recipe, 'B11_0')
assert hasattr(recipe, "B11_0")
recipe.B11_0 = 0.1

# We now select non-structural parameters to refine.
Expand All @@ -100,8 +101,8 @@ def makeRecipe(ciffile, datname):
# Give the recipe away so it can be used!
return recipe

if __name__ == "__main__":

if __name__ == "__main__":
# Make the data and the recipe
ciffile = "data/si.cif"
data = "data/si-q27r60-xray.gr"
Expand Down
Loading