Skip to content

Commit e49212e

Browse files
authored
dep & test: Replace deprecated functions and add tests for interface.py (#230)
* chore: replace deprecated functions * replace deprecated function in test * fix deprecated functions in examples and add tests for interface * fix file header * trigger ci * doc: add short hand operators to docs
1 parent 856116e commit e49212e

20 files changed

Lines changed: 125 additions & 44 deletions

‎docs/examples/coreshellnp.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
from pathlib import Path
2424

25-
from pyobjcryst import loadCrystal
25+
from pyobjcryst.crystal import create_crystal_from_cif
2626
from scipy.optimize import leastsq
2727

2828
from diffpy.srfit.fitbase import (
@@ -94,7 +94,7 @@ def makeRecipe(stru1, stru2, datname):
9494
# diameter to twice the shell radius.
9595
recipe.add_variable(contribution.radius, 15)
9696
recipe.add_variable(contribution.thickness, 11)
97-
recipe.add_constraint(contribution.psize, "2 * radius")
97+
recipe.add_constraint(contribution.particle_diameter, "2 * radius")
9898

9999
# Configure the fit variables
100100
# Start by configuring the scale factor and resolution factors.
@@ -152,8 +152,8 @@ def main():
152152
data = Path(__file__).parent / "data/CdS_ZnS_nano.gr"
153153

154154
# Make the recipe
155-
stru1 = loadCrystal(cdsciffile)
156-
stru2 = loadCrystal(znsciffile)
155+
stru1 = create_crystal_from_cif(str(cdsciffile))
156+
stru2 = create_crystal_from_cif(str(znsciffile))
157157
recipe = makeRecipe(stru1, stru2, data)
158158
from diffpy.srfit.fitbase.fithook import PlotFitHook
159159

‎docs/examples/crystalpdfall.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from pathlib import Path
2222

2323
from gaussianrecipe import scipyOptimize
24-
from pyobjcryst import loadCrystal
24+
from pyobjcryst.crystal import create_crystal_from_cif
2525

2626
from diffpy.srfit.fitbase import (
2727
FitContribution,
@@ -67,12 +67,12 @@ def makeRecipe(
6767
# The ProfileGenerators
6868
# We create one for each phase and share the phases.
6969
xgenerator_ni = PDFGenerator("xG_ni")
70-
stru = loadCrystal(ciffile_ni)
70+
stru = create_crystal_from_cif(str(ciffile_ni))
7171
xgenerator_ni.setStructure(stru)
7272
phase_ni = xgenerator_ni.phase
7373

7474
xgenerator_si = PDFGenerator("xG_si")
75-
stru = loadCrystal(ciffile_si)
75+
stru = create_crystal_from_cif(str(ciffile_si))
7676
xgenerator_si.setStructure(stru)
7777
phase_si = xgenerator_si.phase
7878

‎docs/examples/crystalpdfobjcryst.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from pathlib import Path
2323

2424
from gaussianrecipe import scipyOptimize
25-
from pyobjcryst import loadCrystal
25+
from pyobjcryst.crystal import create_crystal_from_cif
2626

2727
from diffpy.srfit.fitbase import (
2828
FitContribution,
@@ -56,7 +56,7 @@ def makeRecipe(ciffile, datname):
5656
# create a Crystal object. That object is passed to the PDFGenerator as in
5757
# the previous example.
5858
generator = PDFGenerator("G")
59-
stru = loadCrystal(ciffile)
59+
stru = create_crystal_from_cif(str(ciffile))
6060
generator.setStructure(stru)
6161
generator.setQmax(40.0)
6262

‎docs/examples/crystalpdftwodata.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from pathlib import Path
2424

2525
from gaussianrecipe import scipyOptimize
26-
from pyobjcryst import loadCrystal
26+
from pyobjcryst.crystal import create_crystal_from_cif
2727

2828
from diffpy.srfit.fitbase import (
2929
FitContribution,
@@ -59,7 +59,7 @@ def makeRecipe(ciffile, xdatname, ndatname):
5959
# The ProfileGenerators
6060
# We need one of these for the x-ray data.
6161
xgenerator = PDFGenerator("G")
62-
stru = loadCrystal(ciffile)
62+
stru = create_crystal_from_cif(str(ciffile))
6363
xgenerator.setStructure(stru)
6464

6565
# And we need one for the neutron data. We want to refine the same

‎docs/examples/crystalpdftwophase.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from pathlib import Path
2424

2525
from gaussianrecipe import scipyOptimize
26-
from pyobjcryst import loadCrystal
26+
from pyobjcryst.crystal import create_crystal_from_cif
2727

2828
from diffpy.srfit.fitbase import (
2929
FitContribution,
@@ -61,11 +61,11 @@ def makeRecipe(niciffile, siciffile, datname):
6161
# The generator for the nickel phase. We call it "G_ni" and will use this
6262
# name later when we set the fitting equation in the FitContribution.
6363
generator_ni = PDFGenerator("G_ni")
64-
stru = loadCrystal(niciffile)
64+
stru = create_crystal_from_cif(str(niciffile))
6565
generator_ni.setStructure(stru)
6666
# The generator for the silicon phase. We call it "G_si".
6767
generator_si = PDFGenerator("G_si")
68-
stru = loadCrystal(siciffile)
68+
stru = create_crystal_from_cif(str(siciffile))
6969
generator_si.setStructure(stru)
7070

7171
# The FitContribution

‎docs/examples/gaussianrecipe.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ def scipyOptimize(recipe):
172172
# scipy. We simply have to give it the function to minimize
173173
# (recipe.residual) and the starting values of the Variables
174174
# (recipe.get_values()).
175-
from scipy.optimize.minpack import leastsq
175+
from scipy.optimize import leastsq
176176

177177
print("Fit using scipy's LM optimizer")
178178
leastsq(recipe.residual, recipe.get_values())

‎docs/examples/nppdfcrystal.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
import matplotlib.pyplot as plt
2929
from gaussianrecipe import scipyOptimize
30-
from pyobjcryst import loadCrystal
30+
from pyobjcryst.crystal import create_crystal_from_cif
3131

3232
from diffpy.srfit.fitbase import (
3333
FitContribution,
@@ -53,7 +53,7 @@ def makeRecipe(ciffile, grdata):
5353

5454
pdfgenerator = PDFGenerator("G")
5555
pdfgenerator.setQmax(30.0)
56-
stru = loadCrystal(ciffile)
56+
stru = create_crystal_from_cif(str(ciffile))
5757
pdfgenerator.setStructure(stru)
5858
pdfcontribution.add_profile_generator(pdfgenerator)
5959

@@ -66,15 +66,15 @@ def makeRecipe(ciffile, grdata):
6666
pdfcontribution.set_equation("f * G")
6767

6868
# Now make the recipe. Make sure we fit the characteristic function shape
69-
# parameters, in this case 'psize', which is the diameter of the particle.
69+
# parameters, in this case 'particle_diameter'.
7070
recipe = FitRecipe()
7171
recipe.add_contribution(pdfcontribution)
7272

7373
phase = pdfgenerator.phase
7474
for par in phase.sgpars:
7575
recipe.add_variable(par)
7676

77-
recipe.add_variable(pdfcontribution.psize, 20)
77+
recipe.add_variable(pdfcontribution.particle_diameter, 20)
7878
recipe.add_variable(pdfgenerator.scale, 1)
7979
recipe.add_variable(pdfgenerator.delta2, 0)
8080
recipe.B11_0 = 0.1

‎docs/examples/nppdfsas.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
import matplotlib.pyplot as plt
2828
from gaussianrecipe import scipyOptimize
29-
from pyobjcryst import loadCrystal
29+
from pyobjcryst.crystal import create_crystal_from_cif
3030

3131
from diffpy.srfit.fitbase import (
3232
FitContribution,
@@ -58,7 +58,7 @@ def makeRecipe(ciffile, grdata, iqdata):
5858

5959
pdfgenerator = PDFGenerator("G")
6060
pdfgenerator.setQmax(30.0)
61-
stru = loadCrystal(ciffile)
61+
stru = create_crystal_from_cif(str(ciffile))
6262
pdfgenerator.setStructure(stru)
6363
pdfcontribution.add_profile_generator(pdfgenerator)
6464
pdfcontribution.set_residual_equation("resv")

‎docs/examples/simplepdftwophase.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from pathlib import Path
1818

1919
from gaussianrecipe import scipyOptimize
20-
from pyobjcryst import loadCrystal
20+
from pyobjcryst.crystal import create_crystal_from_cif
2121

2222
from diffpy.srfit.fitbase import FitRecipe, FitResults
2323
from diffpy.srfit.pdf import PDFContribution
@@ -33,10 +33,10 @@ def makeRecipe(niciffile, siciffile, datname):
3333
contribution.loadData(datname)
3434
contribution.set_calculation_range(xmax=20)
3535

36-
stru = loadCrystal(niciffile)
36+
stru = create_crystal_from_cif(str(niciffile))
3737
contribution.addStructure("ni", stru)
3838

39-
stru = loadCrystal(siciffile)
39+
stru = create_crystal_from_cif(str(siciffile))
4040
contribution.addStructure("si", stru)
4141

4242
# Make the FitRecipe and add the FitContribution.

‎docs/examples/threedoublepeaks.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ def scipyOptimize(recipe):
184184
# scipy. We simply have to give it the function to minimize
185185
# (recipe.residual) and the starting values of the Variables
186186
# (recipe.get_values()).
187-
from scipy.optimize.minpack import leastsq
187+
from scipy.optimize import leastsq
188188

189189
print("Fit using scipy's LM optimizer")
190190
leastsq(recipe.residual, recipe.get_values())

0 commit comments

Comments
 (0)