Skip to content
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
10 changes: 5 additions & 5 deletions docs/examples/coreshellnp.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,14 @@ def makeRecipe(stru1, stru2, datname):
# diameter to twice the shell radius.
recipe.add_variable(contribution.radius, 15)
recipe.add_variable(contribution.thickness, 11)
recipe.constrain(contribution.psize, "2 * radius")
recipe.add_constraint(contribution.psize, "2 * radius")

# Configure the fit variables
# Start by configuring the scale factor and resolution factors.
# We want the sum of the phase scale factors to be 1.
recipe.create_new_variable("scale_CdS", 0.7)
recipe.constrain(generator_cds.scale, "scale_CdS")
recipe.constrain(generator_zns.scale, "1 - scale_CdS")
recipe.add_constraint(generator_cds.scale, "scale_CdS")
recipe.add_constraint(generator_zns.scale, "1 - scale_CdS")
# We also want the resolution factor to be the same on each.

# Vary the global scale as well.
Expand All @@ -117,7 +117,7 @@ def makeRecipe(stru1, stru2, datname):
)
# Since we know these have stacking disorder, constrain the B33 adps for
# each atom type.
recipe.constrain("B33_1_cds", "B33_0_cds")
recipe.add_constraint("B33_1_cds", "B33_0_cds")
recipe.add_variable(generator_cds.delta2, name="delta2_cds", value=5)

phase_zns = generator_zns.phase
Expand All @@ -128,7 +128,7 @@ def makeRecipe(stru1, stru2, datname):
recipe.add_variable(
phase_zns.sgpars.xyzpars.z_1, name="z_1_zns", tag="xyz"
)
recipe.constrain("B33_1_zns", "B33_0_zns")
recipe.add_constraint("B33_1_zns", "B33_0_zns")
recipe.add_variable(generator_zns.delta2, name="delta2_zns", value=2.5)

# Give the recipe away so it can be used!
Expand Down
14 changes: 7 additions & 7 deletions docs/examples/crystalpdfall.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,24 +113,24 @@ def makeRecipe(
for par in phase_ni.sgpars:
recipe.add_variable(par, name=par.name + "_ni")
delta2_ni = recipe.create_new_variable("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)
recipe.add_constraint(xgenerator_ni.delta2, delta2_ni)
recipe.add_constraint(ngenerator_ni.delta2, delta2_ni)
recipe.add_constraint(xgenerator_sini_ni.delta2, delta2_ni)

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

# Now the experimental parameters
recipe.add_variable(xgenerator_ni.scale, name="xscale_ni")
recipe.add_variable(xgenerator_si.scale, name="xscale_si")
recipe.add_variable(ngenerator_ni.scale, name="nscale_ni")
recipe.add_variable(xcontribution_sini.scale, 1.0, "xscale_sini")
recipe.create_new_variable("pscale_sini_ni", 0.8)
recipe.constrain(xgenerator_sini_ni.scale, "pscale_sini_ni")
recipe.constrain(xgenerator_sini_si.scale, "1 - pscale_sini_ni")
recipe.add_constraint(xgenerator_sini_ni.scale, "pscale_sini_ni")
recipe.add_constraint(xgenerator_sini_si.scale, "1 - pscale_sini_ni")

# The qdamp parameters are too correlated to vary so we fix them based on
# previous measurements.
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/crystalpdftwodata.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ def makeRecipe(ciffile, xdatname, ndatname):
# delta2 is a non-structual material property. Thus, we constrain together
# delta2 Parameter from each PDFGenerator.
delta2 = recipe.create_new_variable("delta2", 2)
recipe.constrain(xgenerator.delta2, delta2)
recipe.constrain(ngenerator.delta2, delta2)
recipe.add_constraint(xgenerator.delta2, delta2)
recipe.add_constraint(ngenerator.delta2, delta2)

# We only need to constrain phase properties once since there is a single
# ObjCrystCrystalParSet for the Crystal.
Expand Down
32 changes: 22 additions & 10 deletions docs/examples/crystalpdftwophase.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ def makeRecipe(niciffile, siciffile, datname):
# Start by configuring the scale factor and resolution factors.
# We want the sum of the phase scale factors to be 1.
recipe.create_new_variable("scale_ni", 0.1)
recipe.constrain(generator_ni.scale, "scale_ni")
recipe.constrain(generator_si.scale, "1 - scale_ni")
recipe.add_constraint(generator_ni.scale, "scale_ni")
recipe.add_constraint(generator_si.scale, "1 - scale_ni")
# We also want the resolution factor to be the same on each.
recipe.create_new_variable("qdamp", 0.03)
recipe.constrain(generator_ni.qdamp, "qdamp")
recipe.constrain(generator_si.qdamp, "qdamp")
recipe.add_constraint(generator_ni.qdamp, "qdamp")
recipe.add_constraint(generator_si.qdamp, "qdamp")

# Vary the global scale as well.
recipe.add_variable(contribution.scale, 1)
Expand Down Expand Up @@ -123,18 +123,30 @@ def makeRecipe(niciffile, siciffile, datname):
# derived has no uncertainty. Thus, we will tell the recipe to scale the
# residual, which means that it will be weighted as much as the average
# data point during the fit.
recipe.restrain("a_ni", lb=3.527, ub=3.527, scaled=True)
recipe.add_soft_bounds(
"a_ni", lower_bound=3.527, upper_bound=3.527, scaled=True
)
# Now we do the same with the delta2 and Biso parameters (remember that
# Biso = 8*pi**2*Uiso)
recipe.restrain("delta2_ni", lb=2.22, ub=2.22, scaled=True)
recipe.restrain("Biso_0_ni", lb=0.454, ub=0.454, scaled=True)
recipe.add_soft_bounds(
"delta2_ni", lower_bound=2.22, upper_bound=2.22, scaled=True
)
recipe.add_soft_bounds(
"Biso_0_ni", lower_bound=0.454, upper_bound=0.454, scaled=True
)
#
# We can do the same with the silicon values. We haven't done a thorough
# job of measuring the uncertainties in the results, so we'll scale these
# as well.
recipe.restrain("a_si", lb=5.430, ub=5.430, scaled=True)
recipe.restrain("delta2_si", lb=3.54, ub=3.54, scaled=True)
recipe.restrain("Biso_0_si", lb=0.645, ub=0.645, scaled=True)
recipe.add_soft_bounds(
"a_si", lower_bound=5.430, upper_bound=5.430, scaled=True
)
recipe.add_soft_bounds(
"delta2_si", lower_bound=3.54, upper_bound=3.54, scaled=True
)
recipe.add_soft_bounds(
"Biso_0_si", lower_bound=0.645, upper_bound=0.645, scaled=True
)

# Give the recipe away so it can be used!
return recipe
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/debyemodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def makeRecipe():
# breaking the restraint by the point-average chi^2 value so that the
# restraint is roughly as significant as any other data point throughout
# the fit.
recipe.restrain(recipe.offset, lb=0, scaled=True)
recipe.add_soft_bounds(recipe.offset, lower_bound=0, scaled=True)

# We're done setting up the recipe. We can now do other things with it.
return recipe
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/debyemodelII.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ def makeRecipeII():
# We create a new Variable and use the recipe's "constrain" method to
# associate the Debye temperature parameters with that variable.
recipe.create_new_variable("thetaD", 100)
recipe.constrain(recipe.lowT.thetaD, "thetaD")
recipe.constrain(recipe.highT.thetaD, "thetaD")
recipe.add_constraint(recipe.lowT.thetaD, "thetaD")
recipe.add_constraint(recipe.highT.thetaD, "thetaD")
return recipe


Expand Down
6 changes: 3 additions & 3 deletions docs/examples/npintensity.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,15 +290,15 @@ def gaussian(q, q0, width):
lattice = phase.getLattice()
a = lattice.a
recipe.add_variable(a)
recipe.constrain(lattice.b, a)
recipe.constrain(lattice.c, a)
recipe.add_constraint(lattice.b, a)
recipe.add_constraint(lattice.c, a)
# We want to refine the thermal parameters as well. We will add a new
# Variable that we call "Uiso" and constrain the atomic Uiso values to
# 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():
recipe.constrain(atom.Uiso, Uiso)
recipe.add_constraint(atom.Uiso, Uiso)

# Give the recipe away so it can be used!
return recipe
Expand Down
6 changes: 3 additions & 3 deletions docs/examples/npintensityII.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,15 @@ def gaussian(q, q0, width):
a = recipe.add_variable(lattice.a)
# We want to allow for isotropic expansion, so we'll make constraints for
# that.
recipe.constrain(lattice.b, a)
recipe.constrain(lattice.c, a)
recipe.add_constraint(lattice.b, a)
recipe.add_constraint(lattice.c, a)
# We want to refine the thermal parameters as well. We will add a new
# variable that we call "Uiso" and constrain the atomic Uiso values to
# 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():
recipe.constrain(atom.Uiso, Uiso)
recipe.add_constraint(atom.Uiso, Uiso)

# Give the recipe away so it can be used!
return recipe
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/nppdfobjcryst.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def makeRecipe(molecule, datname):
# has no scattering power. It is only used as a reference point for
# our bond length. We don't want to constrain it.
if not atom.isDummy():
recipe.constrain(atom.Biso, Biso)
recipe.add_constraint(atom.Biso, Biso)

# We need to let the molecule expand. If we were modeling it as a crystal,
# we could let the unit cell expand. For instruction purposes, we use a
Expand All @@ -97,7 +97,7 @@ def makeRecipe(molecule, datname):
# This creates a Parameter that moves the second atom according to the
# bond length. Note that each Parameter needs a unique name.
par = c60.addBondLengthParameter("rad%i" % i, center, atom)
recipe.constrain(par, radius)
recipe.add_constraint(par, radius)

# Add the correlation term, scale. The scale is too short to effectively
# determine qdamp.
Expand Down
8 changes: 4 additions & 4 deletions docs/examples/nppdfsas.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ def makeRecipe(ciffile, grdata, iqdata):
# Even though the cfcalculator and sasgenerator depend on the same sas
# model, we must still constrain the cfcalculator Parameters so that it is
# informed of changes in the refined parameters.
recipe.constrain(cfcalculator.radius_a, "radius_a")
recipe.constrain(cfcalculator.radius_b, "radius_b")
recipe.add_constraint(cfcalculator.radius_a, "radius_a")
recipe.add_constraint(cfcalculator.radius_b, "radius_b")

return recipe

Expand All @@ -126,9 +126,9 @@ def fitRecipe(recipe):
recipe.set_weight(recipe.pdf, 0)
recipe.fix("all")
recipe.free("radius_a", "radius_b", iqscale=1e8)
recipe.constrain("radius_b", "radius_a")
recipe.add_constraint("radius_b", "radius_a")
scipyOptimize(recipe)
recipe.unconstrain("radius_b")
recipe.remove_constraint("radius_b")

# Tune PDF
recipe.set_weight(recipe.pdf, 1)
Expand Down
28 changes: 20 additions & 8 deletions docs/examples/simplepdftwophase.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ def makeRecipe(niciffile, siciffile, datname):
# Start by configuring the scale factor and resolution factors.
# We want the sum of the phase scale factors to be 1.
recipe.create_new_variable("scale_ni", 0.1)
recipe.constrain(contribution.ni.scale, "scale_ni")
recipe.constrain(contribution.si.scale, "1 - scale_ni")
recipe.add_constraint(contribution.ni.scale, "scale_ni")
recipe.add_constraint(contribution.si.scale, "1 - scale_ni")
# We also want the resolution factor to be the same on each. This is done
# for free by the PDFContribution. We simply need to add it to the recipe.
recipe.add_variable(contribution.qdamp, 0.03)
Expand Down Expand Up @@ -82,18 +82,30 @@ def makeRecipe(niciffile, siciffile, datname):
# derived has no uncertainty. Thus, we will tell the recipe to scale the
# residual, which means that it will be weighted as much as the average
# data point during the fit.
recipe.restrain("a_ni", lb=3.527, ub=3.527, scaled=True)
recipe.add_soft_bounds(
"a_ni", lower_bound=3.527, upper_bound=3.527, scaled=True
)
# Now we do the same with the delta2 and Biso parameters (remember that
# Biso = 8*pi**2*Uiso)
recipe.restrain("delta2_ni", lb=2.22, ub=2.22, scaled=True)
recipe.restrain("Biso_0_ni", lb=0.454, ub=0.454, scaled=True)
recipe.add_soft_bounds(
"delta2_ni", lower_bound=2.22, upper_bound=2.22, scaled=True
)
recipe.add_soft_bounds(
"Biso_0_ni", lower_bound=0.454, upper_bound=0.454, scaled=True
)
#
# We can do the same with the silicon values. We haven't done a thorough
# job of measuring the uncertainties in the results, so we'll scale these
# as well.
recipe.restrain("a_si", lb=5.430, ub=5.430, scaled=True)
recipe.restrain("delta2_si", lb=3.54, ub=3.54, scaled=True)
recipe.restrain("Biso_0_si", lb=0.645, ub=0.645, scaled=True)
recipe.add_soft_bounds(
"a_si", lower_bound=5.430, upper_bound=5.430, scaled=True
)
recipe.add_soft_bounds(
"delta2_si", lower_bound=3.54, upper_bound=3.54, scaled=True
)
recipe.add_soft_bounds(
"Biso_0_si", lower_bound=0.645, upper_bound=0.645, scaled=True
)

# Give the recipe away so it can be used!
return recipe
Expand Down
18 changes: 9 additions & 9 deletions docs/examples/threedoublepeaks.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ def peakloc(mu):
return 180 / pi * arcsin(pi / 180 * l2 * sin(mu) / l1)

recipe.register_function(peakloc)
recipe.constrain(contribution.mu12, "peakloc(mu11)")
recipe.constrain(contribution.mu22, "peakloc(mu21)")
recipe.constrain(contribution.mu32, "peakloc(mu31)")
recipe.add_constraint(contribution.mu12, "peakloc(mu11)")
recipe.add_constraint(contribution.mu22, "peakloc(mu21)")
recipe.add_constraint(contribution.mu32, "peakloc(mu31)")

# Vary the width of the peaks. We know the functional form of the peak
# broadening.
Expand All @@ -139,20 +139,20 @@ def sig(sig0, dsig, mu):
# Now constrain the peak widths to this
recipe.sig0.value = 0.001
recipe.dsig.value = 4.0
recipe.constrain(contribution.sig11, "sig(sig0, dsig, mu11)")
recipe.constrain(
recipe.add_constraint(contribution.sig11, "sig(sig0, dsig, mu11)")
recipe.add_constraint(
contribution.sig12,
"sig(sig0, dsig, mu12)",
ns={"mu12": contribution.mu12},
)
recipe.constrain(contribution.sig21, "sig(sig0, dsig, mu21)")
recipe.constrain(
recipe.add_constraint(contribution.sig21, "sig(sig0, dsig, mu21)")
recipe.add_constraint(
contribution.sig22,
"sig(sig0, dsig, mu22)",
ns={"mu22": contribution.mu22},
)
recipe.constrain(contribution.sig31, "sig(sig0, dsig, mu31)")
recipe.constrain(
recipe.add_constraint(contribution.sig31, "sig(sig0, dsig, mu31)")
recipe.add_constraint(
contribution.sig32,
"sig(sig0, dsig, mu32)",
ns={"mu32": contribution.mu32},
Expand Down
35 changes: 35 additions & 0 deletions news/recipeorg-dep2.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
**Added:**

* Added ``add_constraint`` method to ``RecipeOrganizer``.
* Added ``remove_constraint`` method to ``RecipeOrganizer``.
* Added ``add_soft_bounds`` method to ``RecipeOrganizer``.
* Added ``remove_soft_bounds`` method to ``RecipeOrganizer``.
* Added ``register_soft_bounds`` method to ``RecipeOrganizer``.
* Added ``clear_all_soft_bounds`` method to ``RecipeOrganizer``.
* Added ``get_equation_from_string`` method to ``RecipeOrganizer``.

**Changed:**

* <news item>

**Deprecated:**

* Deprecated ``constrain`` method of ``RecipeOrganizer``. Use ``add_constraint`` instead.
* Deprecated ``unconstrain`` method of ``RecipeOrganizer``. Use ``remove_constraint`` instead.
* Deprecated ``restrain`` method of ``RecipeOrganizer``. Use ``add_soft_bounds`` instead.
* Deprecated ``unrestrain`` methods of ``RecipeOrganizer``. Use ``remove_soft_bounds`` instead.
* Deprecated ``addRestraint`` method of ``RecipeOrganizer``. Use ``register_soft_bounds`` instead.
* Deprecate ``clearRestraints`` method of ``RecipeOrganizer``. Use ``clear_all_soft_bounds`` instead.
* Deprecated ``equationFromString`` method of ``RecipeOrganizer``. Use ``get_equation_from_string`` instead.

**Removed:**

* <news item>

**Fixed:**

* <news item>

**Security:**

* <news item>
Loading
Loading