From eea6ee1a12d3070de7ee656b6f11852d7fc06e60 Mon Sep 17 00:00:00 2001 From: Caden Myers Date: Fri, 13 Nov 2026 10:40:24 -0500 Subject: [PATCH] fix: replace deprecated srfit pdf/structure API in examples Import from diffpy.cmipdf and diffpy.cmistructure instead of diffpy.srfit.pdf and diffpy.srfit.structure, and use set_structure, set_qmax, set_qmin, get_scatterers, get_lattice and .structure in the example scripts and notebooks under docs/examples. Co-Authored-By: Claude Opus 5.5 --- .../examples/core/intensityfit/npintensity.py | 16 ++++++------ .../core/intensityfit/npintensityII.py | 4 +-- .../exercises/diffpy-cmi/fitBulkNi.ipynb | 10 +++---- .../exercises/diffpy-cmi/fitNPPt.ipynb | 12 ++++----- .../solutions/diffpy-cmi/fitBulkNi.py | 10 +++---- .../diffpy-cmi/fitBulkNi_NPPt_soln2.ipynb | 12 ++++----- .../solutions/diffpy-cmi/fitNPPt.py | 12 ++++----- .../solutions/diffpy-cmi/helper_functions.py | 8 +++--- .../solutions/diffpy-cmi/fit2P.py | 12 ++++----- .../solutions/diffpy-cmi/fitCrystalGen.py | 10 +++---- .../solutions/diffpy-cmi/fitTSeries.py | 10 +++---- .../solutions/diffpy-cmi/fitCdSeNP.py | 26 +++++++++---------- .../solutions/diffpy-cmi/fitCdSeNP.py | 12 ++++----- .../pdf/nanoparticle-fit/coreshellnp.py | 12 ++++----- news/fix-example-deprecations.rst | 23 ++++++++++++++++ 15 files changed, 106 insertions(+), 83 deletions(-) create mode 100644 news/fix-example-deprecations.rst diff --git a/docs/examples/core/intensityfit/npintensity.py b/docs/examples/core/intensityfit/npintensity.py index 9e4c8fd..054f81e 100644 --- a/docs/examples/core/intensityfit/npintensity.py +++ b/docs/examples/core/intensityfit/npintensity.py @@ -47,6 +47,7 @@ import numpy from diffpy.cmi.fit_tools import optimize_recipe +from diffpy.cmistructure.diffpyparset import DiffpyStructureParSet from diffpy.srfit.fitbase import ( FitContribution, FitRecipe, @@ -54,7 +55,6 @@ Profile, ProfileGenerator, ) -from diffpy.srfit.structure.diffpyparset import DiffpyStructureParSet ###### # Example Code @@ -103,7 +103,7 @@ def set_structure(self, strufile): function whenever it is called. This will create the refinement Parameters using the - DiffpyStructureParSet adapter from diffpy.srfit.structure.diffpyparset. + DiffpyStructureParSet adapter from diffpy.cmistructure.diffpyparset. DiffpyStructureParSet is a ParameterSet object that organizes and gives attribute access to Parameters and ParameterSets adapted from a diffpy Structure object. The Parameters embedded in the DiffpyStructureParSet @@ -113,14 +113,14 @@ def set_structure(self, strufile): are organized hierarchically: phase - - lattice (retrieved with 'getLattice') + - lattice (retrieved with 'get_lattice') - a - b - c - alpha - beta - gamma - - scatterers (retrieved with 'getScatterers') + - scatterers (retrieved with 'get_scatterers') - atom1 (the name depends on the element) - x - y @@ -136,7 +136,7 @@ def set_structure(self, strufile): - etc. The diffpy.structure.Structure instance is held within the - DiffpyStructureParSet as the 'stru' attribute. + DiffpyStructureParSet as the 'structure' attribute. """ # Load the structure from file from diffpy.structure import Structure @@ -170,7 +170,7 @@ def __call__(self, q): """ self.count += 1 print("iofq called", self.count) - return iofq(self.phase.stru, q) + return iofq(self.phase.structure, q) # End class IntensityGenerator @@ -287,7 +287,7 @@ def gaussian(q, q0, width): # parameters to the same value (the lattice is cubic). Note that we # constrain to the "a" Parameter directly. In previous examples, we # constrained to a Variable by name. This has the same effect. - lattice = phase.getLattice() + lattice = phase.get_lattice() a = lattice.a recipe.add_variable(a) recipe.add_constraint(lattice.b, a) @@ -297,7 +297,7 @@ def gaussian(q, q0, width): # this. Note that we don't give Uiso an initial value. The initial value # will be inferred from the following constraints. Uiso = recipe.create_new_variable("Uiso") - for atom in phase.getScatterers(): + for atom in phase.get_scatterers(): recipe.add_constraint(atom.Uiso, Uiso) # Give the recipe away so it can be used! diff --git a/docs/examples/core/intensityfit/npintensityII.py b/docs/examples/core/intensityfit/npintensityII.py index 6400fea..2164b41 100644 --- a/docs/examples/core/intensityfit/npintensityII.py +++ b/docs/examples/core/intensityfit/npintensityII.py @@ -171,7 +171,7 @@ def gaussian(q, q0, width): # We can also refine structural parameters. We only have to do this once, # since each generator holds the same DiffpyStructureParSet. phase = generator1.phase - lattice = phase.getLattice() + lattice = phase.get_lattice() a = recipe.add_variable(lattice.a) # We want to allow for isotropic expansion, so we'll make constraints for # that. @@ -182,7 +182,7 @@ def gaussian(q, q0, width): # this. Note that we don't give Uiso an initial value. The initial value # will be inferred from the subsequent constraints. Uiso = recipe.create_new_variable("Uiso") - for atom in phase.getScatterers(): + for atom in phase.get_scatterers(): recipe.add_constraint(atom.Uiso, Uiso) # Give the recipe away so it can be used! diff --git a/docs/examples/pdf/ch03NiModelling/exercises/diffpy-cmi/fitBulkNi.ipynb b/docs/examples/pdf/ch03NiModelling/exercises/diffpy-cmi/fitBulkNi.ipynb index 7e578ea..401d435 100644 --- a/docs/examples/pdf/ch03NiModelling/exercises/diffpy-cmi/fitBulkNi.ipynb +++ b/docs/examples/pdf/ch03NiModelling/exercises/diffpy-cmi/fitBulkNi.ipynb @@ -63,9 +63,9 @@ "from diffpy.srfit.fitbase import FitContribution, FitRecipe\n", "from diffpy.srfit.fitbase import FitResults\n", "from diffpy.srfit.fitbase import Profile\n", - "from diffpy.srfit.pdf import PDFParser, PDFGenerator\n", + "from diffpy.cmipdf import PDFParser, PDFGenerator\n", "from diffpy.structure.parsers import get_parser\n", - "from diffpy.srfit.structure import constrain_as_space_group" + "from diffpy.cmistructure import constrain_as_space_group" ] }, { @@ -311,7 +311,7 @@ " # This Generator will later compute the model PDF for the structure\n", " # object we provide it here.\n", " generator_crystal1 = PDFGenerator(\"G1\")\n", - " generator_crystal1.setStructure(stru1, periodic=True)\n", + " generator_crystal1.set_structure(stru1, periodic=True)\n", "\n", " # 12: Create a Fit Contribution object, and arbitrarily name it 'crystal'.\n", " # We then give the PDF Generator object we created just above\n", @@ -363,8 +363,8 @@ " # below '.value = ' syntax.\n", " recipe.crystal.G1.qdamp.value = QDAMP_I\n", " recipe.crystal.G1.qbroad.value = QBROAD_I\n", - " recipe.crystal.G1.setQmax(QMAX)\n", - " recipe.crystal.G1.setQmin(QMIN)\n", + " recipe.crystal.G1.set_qmax(QMAX)\n", + " recipe.crystal.G1.set_qmin(QMIN)\n", "\n", " # 17: Add a variable to the Fit Recipe object, initialize the variables\n", " # with some value, and tag it with an arbitrary string. Here we add the scale\n", diff --git a/docs/examples/pdf/ch03NiModelling/exercises/diffpy-cmi/fitNPPt.ipynb b/docs/examples/pdf/ch03NiModelling/exercises/diffpy-cmi/fitNPPt.ipynb index a464aca..6f5dd06 100644 --- a/docs/examples/pdf/ch03NiModelling/exercises/diffpy-cmi/fitNPPt.ipynb +++ b/docs/examples/pdf/ch03NiModelling/exercises/diffpy-cmi/fitNPPt.ipynb @@ -47,10 +47,10 @@ "outputs": [], "source": [ "from diffpy.srfit.fitbase import FitContribution, FitRecipe, FitResults, Profile\n", - "from diffpy.srfit.pdf import PDFParser, PDFGenerator\n", + "from diffpy.cmipdf import PDFParser, PDFGenerator\n", "from diffpy.structure.parsers import get_parser\n", - "from diffpy.srfit.pdf.characteristicfunctions import spherical_particle\n", - "from diffpy.srfit.structure import constrain_as_space_group" + "from diffpy.cmipdf.characteristicfunctions import spherical_particle\n", + "from diffpy.cmistructure import constrain_as_space_group" ] }, { @@ -273,7 +273,7 @@ "\n", " # 12: Create a PDF Generator object for a periodic structure model.\n", " generator_crystal1 = PDFGenerator(\"G1\")\n", - " generator_crystal1.setStructure(stru1, periodic=True)\n", + " generator_crystal1.set_structure(stru1, periodic=True)\n", "\n", " # 13: Create a Fit Contribution object.\n", " contribution = FitContribution(\"crystal\")\n", @@ -312,8 +312,8 @@ " # assign Q_max and Q_min.\n", " generator_crystal1.qdamp.value = QDAMP_I\n", " generator_crystal1.qbroad.value = QBROAD_I\n", - " generator_crystal1.setQmax(QMAX)\n", - " generator_crystal1.setQmin(QMIN)\n", + " generator_crystal1.set_qmax(QMAX)\n", + " generator_crystal1.set_qmin(QMIN)\n", "\n", " # 18: Add, initialize, and tag variables in the Fit Recipe object.\n", " # In this case we also add 'psize', which is the NP size.\n", diff --git a/docs/examples/pdf/ch03NiModelling/solutions/diffpy-cmi/fitBulkNi.py b/docs/examples/pdf/ch03NiModelling/solutions/diffpy-cmi/fitBulkNi.py index f6be5e1..e41ca52 100644 --- a/docs/examples/pdf/ch03NiModelling/solutions/diffpy-cmi/fitBulkNi.py +++ b/docs/examples/pdf/ch03NiModelling/solutions/diffpy-cmi/fitBulkNi.py @@ -15,14 +15,14 @@ from scipy.optimize import least_squares # ... and the relevant CMI packages +from diffpy.cmipdf import PDFGenerator, PDFParser +from diffpy.cmistructure import constrain_as_space_group from diffpy.srfit.fitbase import ( FitContribution, FitRecipe, FitResults, Profile, ) -from diffpy.srfit.pdf import PDFGenerator, PDFParser -from diffpy.srfit.structure import constrain_as_space_group from diffpy.structure.parsers import get_parser plt.style.use(all_styles["bg-style"]) @@ -116,7 +116,7 @@ def make_recipe(cif_path, dat_path): # This Generator will later compute the model PDF for the structure # object we provide it here. generator_crystal1 = PDFGenerator("G1") - generator_crystal1.setStructure(stru1, periodic=True) + generator_crystal1.set_structure(stru1, periodic=True) # 12: Create a Fit Contribution object, and arbitrarily name it 'crystal'. # We then give the PDF Generator object we created just above @@ -173,8 +173,8 @@ def make_recipe(cif_path, dat_path): # below '.value = ' syntax. recipe.crystal.G1.qdamp.value = QDAMP_I recipe.crystal.G1.qbroad.value = QBROAD_I - recipe.crystal.G1.setQmax(QMAX) - recipe.crystal.G1.setQmin(QMIN) + recipe.crystal.G1.set_qmax(QMAX) + recipe.crystal.G1.set_qmin(QMIN) # 17: Add a variable to the Fit Recipe object, initialize the variables # with some value, and tag it with an arbitrary string. Here we add the diff --git a/docs/examples/pdf/ch03NiModelling/solutions/diffpy-cmi/fitBulkNi_NPPt_soln2.ipynb b/docs/examples/pdf/ch03NiModelling/solutions/diffpy-cmi/fitBulkNi_NPPt_soln2.ipynb index 6b883a8..347c6fc 100644 --- a/docs/examples/pdf/ch03NiModelling/solutions/diffpy-cmi/fitBulkNi_NPPt_soln2.ipynb +++ b/docs/examples/pdf/ch03NiModelling/solutions/diffpy-cmi/fitBulkNi_NPPt_soln2.ipynb @@ -55,14 +55,14 @@ "\n", "from diffpy.utils.parsers.loaddata import loadData\n", "from diffpy.srfit.fitbase import FitRecipe, FitContribution, Profile, FitResults\n", - "from diffpy.srfit.pdf import PDFGenerator, PDFParser\n", + "from diffpy.cmipdf import PDFGenerator, PDFParser\n", "from diffpy.srfit.fitbase.parameterset import ParameterSet\n", "from pyobjcryst import loadCrystal\n", "from pyobjcryst.crystal import Crystal\n", "\n", "#We import the form factors. We will use this to fit the Pt nanoparticles as spherical particles.\n", - "import diffpy.srfit.pdf.characteristicfunctions\n", - "F = diffpy.srfit.pdf.characteristicfunctions" + "import diffpy.cmipdf.characteristicfunctions\n", + "F = diffpy.cmipdf.characteristicfunctions" ] }, { @@ -123,7 +123,7 @@ " fc = FitContribution(fc_name)\n", " for name, crystal in crystals.items():\n", " pg = PDFGenerator(name)\n", - " pg.setStructure(crystal, periodic=True)\n", + " pg.set_structure(crystal, periodic=True)\n", " fc.add_profile_generator(pg)\n", " for name, (f, argnames) in functions.items():\n", " fc.register_function(f, name=name, argnames=argnames)\n", @@ -236,7 +236,7 @@ " fixed=True,\n", " tags=_get_tags(name, \"lat\")\n", " ).bound_range(0.)\n", - " atoms: typing.List[ParameterSet] = pg.phase.getScatterers()\n", + " atoms: typing.List[ParameterSet] = pg.phase.get_scatterers()\n", " for atom in atoms:\n", " par = atom.Biso\n", " recipe.add_variable(\n", @@ -537,7 +537,7 @@ " if pg_names is not None:\n", " for pg_name in pg_names:\n", " pg: PDFGenerator = getattr(fc, pg_name)\n", - " stru: Crystal = pg.stru\n", + " stru: Crystal = pg.structure\n", " cif_path = f_path.with_name(\n", " \"{}_{}\".format(f_path.stem, pg_name)\n", " ).with_suffix(\".cif\")\n", diff --git a/docs/examples/pdf/ch03NiModelling/solutions/diffpy-cmi/fitNPPt.py b/docs/examples/pdf/ch03NiModelling/solutions/diffpy-cmi/fitNPPt.py index 981d03c..70097f2 100644 --- a/docs/examples/pdf/ch03NiModelling/solutions/diffpy-cmi/fitNPPt.py +++ b/docs/examples/pdf/ch03NiModelling/solutions/diffpy-cmi/fitNPPt.py @@ -19,15 +19,15 @@ from scipy.optimize import least_squares # ... and the relevant CMI packages +from diffpy.cmipdf import PDFGenerator, PDFParser +from diffpy.cmipdf.characteristicfunctions import spherical_particle +from diffpy.cmistructure import constrain_as_space_group from diffpy.srfit.fitbase import ( FitContribution, FitRecipe, FitResults, Profile, ) -from diffpy.srfit.pdf import PDFGenerator, PDFParser -from diffpy.srfit.pdf.characteristicfunctions import spherical_particle -from diffpy.srfit.structure import constrain_as_space_group from diffpy.structure.parsers import get_parser plt.style.use(all_styles["bg-style"]) @@ -126,7 +126,7 @@ def make_recipe(cif_path, dat_path): # 12: Create a PDF Generator object for a periodic structure model. generator_crystal1 = PDFGenerator("G1") - generator_crystal1.setStructure(stru1, periodic=True) + generator_crystal1.set_structure(stru1, periodic=True) # 13: Create a Fit Contribution object. contribution = FitContribution("crystal") @@ -172,8 +172,8 @@ def make_recipe(cif_path, dat_path): # assign Q_max and Q_min. generator_crystal1.qdamp.value = QDAMP_I generator_crystal1.qbroad.value = QBROAD_I - generator_crystal1.setQmax(QMAX) - generator_crystal1.setQmin(QMIN) + generator_crystal1.set_qmax(QMAX) + generator_crystal1.set_qmin(QMIN) # 18: Add, initialize, and tag variables in the Fit Recipe object. # In this case we also add 'psize', which is the NP size. diff --git a/docs/examples/pdf/ch03NiModelling/solutions/diffpy-cmi/helper_functions.py b/docs/examples/pdf/ch03NiModelling/solutions/diffpy-cmi/helper_functions.py index 1238cb2..04821b5 100644 --- a/docs/examples/pdf/ch03NiModelling/solutions/diffpy-cmi/helper_functions.py +++ b/docs/examples/pdf/ch03NiModelling/solutions/diffpy-cmi/helper_functions.py @@ -5,6 +5,7 @@ from pyobjcryst.crystal import Crystal from scipy.optimize import least_squares +from diffpy.cmipdf import PDFGenerator, PDFParser from diffpy.srfit.fitbase import ( FitContribution, FitRecipe, @@ -12,7 +13,6 @@ Profile, ) from diffpy.srfit.fitbase.parameterset import ParameterSet -from diffpy.srfit.pdf import PDFGenerator, PDFParser # Recipe functions @@ -51,7 +51,7 @@ def _create_recipe( fc = FitContribution(fc_name) for name, crystal in crystals.items(): pg = PDFGenerator(name) - pg.setStructure(crystal, periodic=True) + pg.set_structure(crystal, periodic=True) fc.add_profile_generator(pg) for name, (f, argnames) in functions.items(): fc.register_function(f, name=name, argnames=argnames) @@ -162,7 +162,7 @@ def _add_params_in_pg(recipe: FitRecipe, pg: PDFGenerator) -> None: fixed=True, tags=_get_tags(name, "lat"), ).bound_range(0.0) - atoms: typing.List[ParameterSet] = pg.phase.getScatterers() + atoms: typing.List[ParameterSet] = pg.phase.get_scatterers() for atom in atoms: par = atom.Biso recipe.add_variable( @@ -435,7 +435,7 @@ def save_results( if pg_names is not None: for pg_name in pg_names: pg: PDFGenerator = getattr(fc, pg_name) - stru: Crystal = pg.stru + stru: Crystal = pg.structure cif_path = f_path.with_name( "{}_{}".format(f_path.stem, pg_name) ).with_suffix(".cif") diff --git a/docs/examples/pdf/ch05Fit2Phase/solutions/diffpy-cmi/fit2P.py b/docs/examples/pdf/ch05Fit2Phase/solutions/diffpy-cmi/fit2P.py index eed99ef..7b1bf52 100644 --- a/docs/examples/pdf/ch05Fit2Phase/solutions/diffpy-cmi/fit2P.py +++ b/docs/examples/pdf/ch05Fit2Phase/solutions/diffpy-cmi/fit2P.py @@ -16,14 +16,14 @@ from scipy.optimize import least_squares # ... and the relevant CMI packages +from diffpy.cmipdf import PDFGenerator, PDFParser +from diffpy.cmistructure import constrain_as_space_group from diffpy.srfit.fitbase import ( FitContribution, FitRecipe, FitResults, Profile, ) -from diffpy.srfit.pdf import PDFGenerator, PDFParser -from diffpy.srfit.structure import constrain_as_space_group from diffpy.structure.parsers import get_parser plt.style.use(all_styles["bg-style"]) @@ -109,12 +109,12 @@ def make_recipe(cif_path1, cif_path2, dat_path): # 11a: Create a PDF Generator object for a periodic structure model # of phase 1. generator_crystal1 = PDFGenerator("G_Si") - generator_crystal1.setStructure(stru1, periodic=True) + generator_crystal1.set_structure(stru1, periodic=True) # 11b: Create a PDF Generator object for a periodic structure model # of phase 2. generator_crystal2 = PDFGenerator("G_Ni") - generator_crystal2.setStructure(stru2, periodic=True) + generator_crystal2.set_structure(stru2, periodic=True) # 12: Create a Fit Contribution object. This is new, as we # need to tell the Fit Contribution about BOTH the phase @@ -192,8 +192,8 @@ def make_recipe(cif_path1, cif_path2, dat_path): # assign Q_max and Q_min for each phase. generator.qdamp.value = QDAMP_I generator.qbroad.value = QBROAD_I - generator.setQmax(QMAX) - generator.setQmin(QMIN) + generator.set_qmax(QMAX) + generator.set_qmin(QMIN) # 18c: Get the symmetry equivalent parameters for each phase. spacegroupparams = constrain_as_space_group( diff --git a/docs/examples/pdf/ch06RefineCrystalStructureGen/solutions/diffpy-cmi/fitCrystalGen.py b/docs/examples/pdf/ch06RefineCrystalStructureGen/solutions/diffpy-cmi/fitCrystalGen.py index c63fe52..5f80686 100644 --- a/docs/examples/pdf/ch06RefineCrystalStructureGen/solutions/diffpy-cmi/fitCrystalGen.py +++ b/docs/examples/pdf/ch06RefineCrystalStructureGen/solutions/diffpy-cmi/fitCrystalGen.py @@ -16,14 +16,14 @@ from scipy.optimize import least_squares # ... and the relevant CMI packages +from diffpy.cmipdf import PDFGenerator, PDFParser +from diffpy.cmistructure import constrain_as_space_group from diffpy.srfit.fitbase import ( FitContribution, FitRecipe, FitResults, Profile, ) -from diffpy.srfit.pdf import PDFGenerator, PDFParser -from diffpy.srfit.structure import constrain_as_space_group from diffpy.structure.atom import Atom from diffpy.structure.parsers import get_parser @@ -114,7 +114,7 @@ def make_recipe(cif_path, dat_path): # 12: Create a PDF Generator object for a periodic structure model. generator_crystal1 = PDFGenerator("G1") - generator_crystal1.setStructure(stru1, periodic=True) + generator_crystal1.set_structure(stru1, periodic=True) # 13: Create a Fit Contribution object. contribution = FitContribution("crystal") @@ -155,8 +155,8 @@ def make_recipe(cif_path, dat_path): # assign Q_max and Q_min. generator_crystal1.qdamp.value = QDAMP_I generator_crystal1.qbroad.value = QBROAD_I - generator_crystal1.setQmax(QMAX) - generator_crystal1.setQmin(QMIN) + generator_crystal1.set_qmax(QMAX) + generator_crystal1.set_qmin(QMIN) # 18: Add, initialize, and tag the scale variable. recipe.add_variable(contribution.s1, SCALE_I, tag="scale") diff --git a/docs/examples/pdf/ch07StructuralPhaseTransitions/solutions/diffpy-cmi/fitTSeries.py b/docs/examples/pdf/ch07StructuralPhaseTransitions/solutions/diffpy-cmi/fitTSeries.py index d675a77..a8b067c 100644 --- a/docs/examples/pdf/ch07StructuralPhaseTransitions/solutions/diffpy-cmi/fitTSeries.py +++ b/docs/examples/pdf/ch07StructuralPhaseTransitions/solutions/diffpy-cmi/fitTSeries.py @@ -15,14 +15,14 @@ from scipy.optimize import least_squares # ... and the relevant CMI packages +from diffpy.cmipdf import PDFGenerator, PDFParser +from diffpy.cmistructure import constrain_as_space_group from diffpy.srfit.fitbase import ( FitContribution, FitRecipe, FitResults, Profile, ) -from diffpy.srfit.pdf import PDFGenerator, PDFParser -from diffpy.srfit.structure import constrain_as_space_group from diffpy.structure.parsers import get_parser plt.style.use(all_styles["bg-style"]) @@ -111,7 +111,7 @@ def make_recipe(cif_path, dat_path): # 11: Create a PDF Generator object for a periodic structure model. generator_crystal1 = PDFGenerator("G1") - generator_crystal1.setStructure(stru1, periodic=True) + generator_crystal1.set_structure(stru1, periodic=True) # 12: Create a Fit Contribution object. contribution = FitContribution("crystal") @@ -152,8 +152,8 @@ def make_recipe(cif_path, dat_path): # assign Q_max and Q_min. generator_crystal1.qdamp.value = QDAMP_I generator_crystal1.qbroad.value = QBROAD_I - generator_crystal1.setQmax(QMAX) - generator_crystal1.setQmin(QMIN) + generator_crystal1.set_qmax(QMAX) + generator_crystal1.set_qmin(QMIN) # 17: Add, initialize, and tag the scale variable. recipe.add_variable(contribution.s1, SCALE_I, tag="scale") diff --git a/docs/examples/pdf/ch08NPRefinement/solutions/diffpy-cmi/fitCdSeNP.py b/docs/examples/pdf/ch08NPRefinement/solutions/diffpy-cmi/fitCdSeNP.py index f28168e..63c2980 100644 --- a/docs/examples/pdf/ch08NPRefinement/solutions/diffpy-cmi/fitCdSeNP.py +++ b/docs/examples/pdf/ch08NPRefinement/solutions/diffpy-cmi/fitCdSeNP.py @@ -14,15 +14,15 @@ from scipy.optimize import least_squares # ... and the relevant CMI packages +from diffpy.cmipdf import PDFGenerator, PDFParser +from diffpy.cmipdf.characteristicfunctions import spherical_particle +from diffpy.cmistructure import constrain_as_space_group from diffpy.srfit.fitbase import ( FitContribution, FitRecipe, FitResults, Profile, ) -from diffpy.srfit.pdf import PDFGenerator, PDFParser -from diffpy.srfit.pdf.characteristicfunctions import spherical_particle -from diffpy.srfit.structure import constrain_as_space_group from diffpy.structure.parsers import get_parser # Config ############################## @@ -108,7 +108,7 @@ def make_recipe_one_phase(cif_path, dat_path, adp_iso=True): # 12: Create a PDF Generator object for a periodic structure model. generator_crystal1 = PDFGenerator("G1") - generator_crystal1.setStructure(stru1, periodic=True) + generator_crystal1.set_structure(stru1, periodic=True) # 13: Create a Fit Contribution object. contribution = FitContribution("crystal") @@ -155,8 +155,8 @@ def make_recipe_one_phase(cif_path, dat_path, adp_iso=True): # assign Q_max and Q_min. generator_crystal1.qdamp.value = QDAMP generator_crystal1.qbroad.value = QBROAD - generator_crystal1.setQmax(QMAX) - generator_crystal1.setQmin(QMIN) + generator_crystal1.set_qmax(QMAX) + generator_crystal1.set_qmin(QMIN) # 18: Add, initialize, and tag variables in the Fit Recipe object. # In this case we also add psize, which is the NP size. @@ -201,7 +201,7 @@ def make_recipe_one_phase(cif_path, dat_path, adp_iso=True): # 23: For all atoms in the structure model, we constrain their # Uiso according to their species. - atoms = generator_crystal1.phase.getScatterers() + atoms = generator_crystal1.phase.get_scatterers() for atom in atoms: if atom.element == "Cd": recipe.add_constraint(atom.Uiso, cd_uiso) @@ -279,12 +279,12 @@ def make_recipe_two_phase(cif_path1, cif_path2, dat_path): # 32: Create a PDF Generator object for a periodic structure model # of phase 1. generator_crystal1 = PDFGenerator("G1") - generator_crystal1.setStructure(stru1, periodic=True) + generator_crystal1.set_structure(stru1, periodic=True) # 33: Create a PDF Generator object for a periodic structure model # of phase 2. generator_crystal2 = PDFGenerator("G2") - generator_crystal2.setStructure(stru2, periodic=True) + generator_crystal2.set_structure(stru2, periodic=True) # 33: Make convenient lists of the generators and space group names generators = [generator_crystal1, generator_crystal2] @@ -361,8 +361,8 @@ def make_recipe_two_phase(cif_path1, cif_path2, dat_path): # assign Q_max and Q_min. generator_crystal1.qdamp.value = QDAMP generator_crystal1.qbroad.value = QBROAD - generator_crystal1.setQmax(QMAX) - generator_crystal1.setQmin(QMIN) + generator_crystal1.set_qmax(QMAX) + generator_crystal1.set_qmin(QMIN) # 41: We create the variables of ADP and assign the initial value to them, # specified above. In this example, we use isotropic ADP for all atoms. @@ -381,7 +381,7 @@ def make_recipe_two_phase(cif_path1, cif_path2, dat_path): recipe.add_constraint(generator.delta2, delta2) # 45: turn off anisotropy - generator.phase.stru.anisotropy = False + generator.phase.structure.anisotropy = False # 46: Use the srfit function constrain_as_space_group to constrain # the lattice, ADP parameters, and atomic positions according to the @@ -407,7 +407,7 @@ def make_recipe_two_phase(cif_path1, cif_path2, dat_path): # 47: We do not use the ADP portion of spacegroupparams, instead we # add isotropic ADPs. We use one set across both phases. - atoms = generator.phase.getScatterers() + atoms = generator.phase.get_scatterers() for atom in atoms: if atom.element == "Cd": recipe.add_constraint(atom.Uiso, cd_uiso) diff --git a/docs/examples/pdf/ch11ClusterXYZ/solutions/diffpy-cmi/fitCdSeNP.py b/docs/examples/pdf/ch11ClusterXYZ/solutions/diffpy-cmi/fitCdSeNP.py index d541418..6ba2b77 100644 --- a/docs/examples/pdf/ch11ClusterXYZ/solutions/diffpy-cmi/fitCdSeNP.py +++ b/docs/examples/pdf/ch11ClusterXYZ/solutions/diffpy-cmi/fitCdSeNP.py @@ -11,13 +11,13 @@ import numpy as np from scipy.optimize import least_squares +from diffpy.cmipdf import DebyePDFGenerator, PDFParser from diffpy.srfit.fitbase import ( FitContribution, FitRecipe, FitResults, Profile, ) -from diffpy.srfit.pdf import DebyePDFGenerator, PDFParser from diffpy.structure import Structure # Config ############################## @@ -89,7 +89,7 @@ def make_recipe(stru_path, dat_path): # 10: Create a Debye PDF Generator object for the discrete structure model. generator_cluster1 = DebyePDFGenerator("G1") - generator_cluster1.setStructure(stru1, periodic=False) + generator_cluster1.set_structure(stru1, periodic=False) # 11: Create a Fit Contribution object. contribution = FitContribution("cluster") @@ -129,8 +129,8 @@ def make_recipe(stru_path, dat_path): # assign Q_max and Q_min. generator_cluster1.qdamp.value = QDAMP_I generator_cluster1.qbroad.value = QBROAD_I - generator_cluster1.setQmax(QMAX) - generator_cluster1.setQmin(QMIN) + generator_cluster1.set_qmax(QMAX) + generator_cluster1.set_qmin(QMIN) # 16: Add, initialize, and tag variables in the Fit Recipe object. # In this case we also add psize, which is the NP size. @@ -142,7 +142,7 @@ def make_recipe(stru_path, dat_path): phase_cluster1 = generator_cluster1.phase - lattice1 = phase_cluster1.getLattice() + lattice1 = phase_cluster1.get_lattice() recipe.create_new_variable("zoomscale", ZOOMSCALE_I, tag="lat") @@ -153,7 +153,7 @@ def make_recipe(stru_path, dat_path): # 18: Initialize an atoms object and constrain the isotropic # Atomic Displacement Parameters (ADPs) per element. - atoms1 = phase_cluster1.getScatterers() + atoms1 = phase_cluster1.get_scatterers() recipe.create_new_variable("Cd_Uiso", UISO_Cd_I, tag="adp") recipe.create_new_variable("Se_Uiso", UISO_Se_I, tag="adp") diff --git a/docs/examples/pdf/nanoparticle-fit/coreshellnp.py b/docs/examples/pdf/nanoparticle-fit/coreshellnp.py index 92b6f9b..f25b77a 100644 --- a/docs/examples/pdf/nanoparticle-fit/coreshellnp.py +++ b/docs/examples/pdf/nanoparticle-fit/coreshellnp.py @@ -25,13 +25,13 @@ from pyobjcryst import loadCrystal from scipy.optimize import leastsq +from diffpy.cmipdf import PDFGenerator, PDFParser from diffpy.srfit.fitbase import ( FitContribution, FitRecipe, FitResults, Profile, ) -from diffpy.srfit.pdf import PDFGenerator, PDFParser # Example Code @@ -54,13 +54,13 @@ def make_recipe(stru1, stru2, datname): # The generator for the CdS core. We call it "G_CdS" and will use this name # later when we set the fitting equation in the FitContribution. generator_cds = PDFGenerator("G_CdS") - generator_cds.setStructure(stru1) - generator_cds.setQmax(26) + generator_cds.set_structure(stru1) + generator_cds.set_qmax(26) generator_cds.qdamp.value = 0.0396 # The generator for the ZnS shell. We call it "G_ZnS". generator_zns = PDFGenerator("G_ZnS") - generator_zns.setStructure(stru2) - generator_zns.setQmax(26) + generator_zns.set_structure(stru2) + generator_zns.set_qmax(26) generator_zns.qdamp.value = 0.0396 # The FitContribution @@ -74,7 +74,7 @@ def make_recipe(stru1, stru2, datname): # and a spherical shell CF for the shell. Since this is set up as two # phases, we implicitly assume that the core-shell correlations contribute # very little to the PDF. - from diffpy.srfit.pdf.characteristicfunctions import ( + from diffpy.cmipdf.characteristicfunctions import ( shell_particle, spherical_particle, ) diff --git a/news/fix-example-deprecations.rst b/news/fix-example-deprecations.rst new file mode 100644 index 0000000..e35e71f --- /dev/null +++ b/news/fix-example-deprecations.rst @@ -0,0 +1,23 @@ +**Added:** + +* + +**Changed:** + +* + +**Deprecated:** + +* + +**Removed:** + +* + +**Fixed:** + +* Use ``diffpy.cmipdf`` and ``diffpy.cmistructure`` and their snake_case methods in the examples to remove deprecation warnings from ``diffpy.srfit``. + +**Security:** + +*