Skip to content

Commit 614d468

Browse files
authored
Merge pull request #169 from cadenmyers13/recipeorg-dep2
deprecate: deprecate the rest of the methods in `recipeorganizer.py`
2 parents 5e91f9b + c115478 commit 614d468

27 files changed

+616
-221
lines changed

docs/examples/coreshellnp.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,14 @@ def makeRecipe(stru1, stru2, datname):
9191
# diameter to twice the shell radius.
9292
recipe.add_variable(contribution.radius, 15)
9393
recipe.add_variable(contribution.thickness, 11)
94-
recipe.constrain(contribution.psize, "2 * radius")
94+
recipe.add_constraint(contribution.psize, "2 * radius")
9595

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

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

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

134134
# Give the recipe away so it can be used!

docs/examples/crystalpdfall.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,24 +113,24 @@ def makeRecipe(
113113
for par in phase_ni.sgpars:
114114
recipe.add_variable(par, name=par.name + "_ni")
115115
delta2_ni = recipe.create_new_variable("delta2_ni", 2.5)
116-
recipe.constrain(xgenerator_ni.delta2, delta2_ni)
117-
recipe.constrain(ngenerator_ni.delta2, delta2_ni)
118-
recipe.constrain(xgenerator_sini_ni.delta2, delta2_ni)
116+
recipe.add_constraint(xgenerator_ni.delta2, delta2_ni)
117+
recipe.add_constraint(ngenerator_ni.delta2, delta2_ni)
118+
recipe.add_constraint(xgenerator_sini_ni.delta2, delta2_ni)
119119

120120
for par in phase_si.sgpars:
121121
recipe.add_variable(par, name=par.name + "_si")
122122
delta2_si = recipe.create_new_variable("delta2_si", 2.5)
123-
recipe.constrain(xgenerator_si.delta2, delta2_si)
124-
recipe.constrain(xgenerator_sini_si.delta2, delta2_si)
123+
recipe.add_constraint(xgenerator_si.delta2, delta2_si)
124+
recipe.add_constraint(xgenerator_sini_si.delta2, delta2_si)
125125

126126
# Now the experimental parameters
127127
recipe.add_variable(xgenerator_ni.scale, name="xscale_ni")
128128
recipe.add_variable(xgenerator_si.scale, name="xscale_si")
129129
recipe.add_variable(ngenerator_ni.scale, name="nscale_ni")
130130
recipe.add_variable(xcontribution_sini.scale, 1.0, "xscale_sini")
131131
recipe.create_new_variable("pscale_sini_ni", 0.8)
132-
recipe.constrain(xgenerator_sini_ni.scale, "pscale_sini_ni")
133-
recipe.constrain(xgenerator_sini_si.scale, "1 - pscale_sini_ni")
132+
recipe.add_constraint(xgenerator_sini_ni.scale, "pscale_sini_ni")
133+
recipe.add_constraint(xgenerator_sini_si.scale, "1 - pscale_sini_ni")
134134

135135
# The qdamp parameters are too correlated to vary so we fix them based on
136136
# previous measurements.

docs/examples/crystalpdftwodata.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ def makeRecipe(ciffile, xdatname, ndatname):
121121
# delta2 is a non-structual material property. Thus, we constrain together
122122
# delta2 Parameter from each PDFGenerator.
123123
delta2 = recipe.create_new_variable("delta2", 2)
124-
recipe.constrain(xgenerator.delta2, delta2)
125-
recipe.constrain(ngenerator.delta2, delta2)
124+
recipe.add_constraint(xgenerator.delta2, delta2)
125+
recipe.add_constraint(ngenerator.delta2, delta2)
126126

127127
# We only need to constrain phase properties once since there is a single
128128
# ObjCrystCrystalParSet for the Crystal.

docs/examples/crystalpdftwophase.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,12 @@ def makeRecipe(niciffile, siciffile, datname):
9090
# Start by configuring the scale factor and resolution factors.
9191
# We want the sum of the phase scale factors to be 1.
9292
recipe.create_new_variable("scale_ni", 0.1)
93-
recipe.constrain(generator_ni.scale, "scale_ni")
94-
recipe.constrain(generator_si.scale, "1 - scale_ni")
93+
recipe.add_constraint(generator_ni.scale, "scale_ni")
94+
recipe.add_constraint(generator_si.scale, "1 - scale_ni")
9595
# We also want the resolution factor to be the same on each.
9696
recipe.create_new_variable("qdamp", 0.03)
97-
recipe.constrain(generator_ni.qdamp, "qdamp")
98-
recipe.constrain(generator_si.qdamp, "qdamp")
97+
recipe.add_constraint(generator_ni.qdamp, "qdamp")
98+
recipe.add_constraint(generator_si.qdamp, "qdamp")
9999

100100
# Vary the global scale as well.
101101
recipe.add_variable(contribution.scale, 1)
@@ -123,18 +123,30 @@ def makeRecipe(niciffile, siciffile, datname):
123123
# derived has no uncertainty. Thus, we will tell the recipe to scale the
124124
# residual, which means that it will be weighted as much as the average
125125
# data point during the fit.
126-
recipe.restrain("a_ni", lb=3.527, ub=3.527, scaled=True)
126+
recipe.add_soft_bounds(
127+
"a_ni", lower_bound=3.527, upper_bound=3.527, scaled=True
128+
)
127129
# Now we do the same with the delta2 and Biso parameters (remember that
128130
# Biso = 8*pi**2*Uiso)
129-
recipe.restrain("delta2_ni", lb=2.22, ub=2.22, scaled=True)
130-
recipe.restrain("Biso_0_ni", lb=0.454, ub=0.454, scaled=True)
131+
recipe.add_soft_bounds(
132+
"delta2_ni", lower_bound=2.22, upper_bound=2.22, scaled=True
133+
)
134+
recipe.add_soft_bounds(
135+
"Biso_0_ni", lower_bound=0.454, upper_bound=0.454, scaled=True
136+
)
131137
#
132138
# We can do the same with the silicon values. We haven't done a thorough
133139
# job of measuring the uncertainties in the results, so we'll scale these
134140
# as well.
135-
recipe.restrain("a_si", lb=5.430, ub=5.430, scaled=True)
136-
recipe.restrain("delta2_si", lb=3.54, ub=3.54, scaled=True)
137-
recipe.restrain("Biso_0_si", lb=0.645, ub=0.645, scaled=True)
141+
recipe.add_soft_bounds(
142+
"a_si", lower_bound=5.430, upper_bound=5.430, scaled=True
143+
)
144+
recipe.add_soft_bounds(
145+
"delta2_si", lower_bound=3.54, upper_bound=3.54, scaled=True
146+
)
147+
recipe.add_soft_bounds(
148+
"Biso_0_si", lower_bound=0.645, upper_bound=0.645, scaled=True
149+
)
138150

139151
# Give the recipe away so it can be used!
140152
return recipe

docs/examples/debyemodel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def makeRecipe():
152152
# breaking the restraint by the point-average chi^2 value so that the
153153
# restraint is roughly as significant as any other data point throughout
154154
# the fit.
155-
recipe.restrain(recipe.offset, lb=0, scaled=True)
155+
recipe.add_soft_bounds(recipe.offset, lower_bound=0, scaled=True)
156156

157157
# We're done setting up the recipe. We can now do other things with it.
158158
return recipe

docs/examples/debyemodelII.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ def makeRecipeII():
8989
# We create a new Variable and use the recipe's "constrain" method to
9090
# associate the Debye temperature parameters with that variable.
9191
recipe.create_new_variable("thetaD", 100)
92-
recipe.constrain(recipe.lowT.thetaD, "thetaD")
93-
recipe.constrain(recipe.highT.thetaD, "thetaD")
92+
recipe.add_constraint(recipe.lowT.thetaD, "thetaD")
93+
recipe.add_constraint(recipe.highT.thetaD, "thetaD")
9494
return recipe
9595

9696

docs/examples/npintensity.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,15 +290,15 @@ def gaussian(q, q0, width):
290290
lattice = phase.getLattice()
291291
a = lattice.a
292292
recipe.add_variable(a)
293-
recipe.constrain(lattice.b, a)
294-
recipe.constrain(lattice.c, a)
293+
recipe.add_constraint(lattice.b, a)
294+
recipe.add_constraint(lattice.c, a)
295295
# We want to refine the thermal parameters as well. We will add a new
296296
# Variable that we call "Uiso" and constrain the atomic Uiso values to
297297
# this. Note that we don't give Uiso an initial value. The initial value
298298
# will be inferred from the following constraints.
299299
Uiso = recipe.create_new_variable("Uiso")
300300
for atom in phase.getScatterers():
301-
recipe.constrain(atom.Uiso, Uiso)
301+
recipe.add_constraint(atom.Uiso, Uiso)
302302

303303
# Give the recipe away so it can be used!
304304
return recipe

docs/examples/npintensityII.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,15 +173,15 @@ def gaussian(q, q0, width):
173173
a = recipe.add_variable(lattice.a)
174174
# We want to allow for isotropic expansion, so we'll make constraints for
175175
# that.
176-
recipe.constrain(lattice.b, a)
177-
recipe.constrain(lattice.c, a)
176+
recipe.add_constraint(lattice.b, a)
177+
recipe.add_constraint(lattice.c, a)
178178
# We want to refine the thermal parameters as well. We will add a new
179179
# variable that we call "Uiso" and constrain the atomic Uiso values to
180180
# this. Note that we don't give Uiso an initial value. The initial value
181181
# will be inferred from the subsequent constraints.
182182
Uiso = recipe.create_new_variable("Uiso")
183183
for atom in phase.getScatterers():
184-
recipe.constrain(atom.Uiso, Uiso)
184+
recipe.add_constraint(atom.Uiso, Uiso)
185185

186186
# Give the recipe away so it can be used!
187187
return recipe

docs/examples/nppdfobjcryst.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def makeRecipe(molecule, datname):
7373
# has no scattering power. It is only used as a reference point for
7474
# our bond length. We don't want to constrain it.
7575
if not atom.isDummy():
76-
recipe.constrain(atom.Biso, Biso)
76+
recipe.add_constraint(atom.Biso, Biso)
7777

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

102102
# Add the correlation term, scale. The scale is too short to effectively
103103
# determine qdamp.

docs/examples/nppdfsas.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ def makeRecipe(ciffile, grdata, iqdata):
113113
# Even though the cfcalculator and sasgenerator depend on the same sas
114114
# model, we must still constrain the cfcalculator Parameters so that it is
115115
# informed of changes in the refined parameters.
116-
recipe.constrain(cfcalculator.radius_a, "radius_a")
117-
recipe.constrain(cfcalculator.radius_b, "radius_b")
116+
recipe.add_constraint(cfcalculator.radius_a, "radius_a")
117+
recipe.add_constraint(cfcalculator.radius_b, "radius_b")
118118

119119
return recipe
120120

@@ -126,9 +126,9 @@ def fitRecipe(recipe):
126126
recipe.set_weight(recipe.pdf, 0)
127127
recipe.fix("all")
128128
recipe.free("radius_a", "radius_b", iqscale=1e8)
129-
recipe.constrain("radius_b", "radius_a")
129+
recipe.add_constraint("radius_b", "radius_a")
130130
scipyOptimize(recipe)
131-
recipe.unconstrain("radius_b")
131+
recipe.remove_constraint("radius_b")
132132

133133
# Tune PDF
134134
recipe.set_weight(recipe.pdf, 1)

0 commit comments

Comments
 (0)