diffpy.srfit 3.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- diffpy/__init__.py +15 -0
- diffpy/srfit/__init__.py +41 -0
- diffpy/srfit/equation/__init__.py +31 -0
- diffpy/srfit/equation/builder.py +702 -0
- diffpy/srfit/equation/equationmod.py +213 -0
- diffpy/srfit/equation/literals/__init__.py +71 -0
- diffpy/srfit/equation/literals/abcs.py +81 -0
- diffpy/srfit/equation/literals/argument.py +76 -0
- diffpy/srfit/equation/literals/literal.py +69 -0
- diffpy/srfit/equation/literals/operators.py +380 -0
- diffpy/srfit/equation/visitors/__init__.py +94 -0
- diffpy/srfit/equation/visitors/argfinder.py +62 -0
- diffpy/srfit/equation/visitors/printer.py +120 -0
- diffpy/srfit/equation/visitors/swapper.py +142 -0
- diffpy/srfit/equation/visitors/validator.py +113 -0
- diffpy/srfit/equation/visitors/visitor.py +62 -0
- diffpy/srfit/exceptions.py +29 -0
- diffpy/srfit/fitbase/__init__.py +53 -0
- diffpy/srfit/fitbase/calculator.py +110 -0
- diffpy/srfit/fitbase/configurable.py +57 -0
- diffpy/srfit/fitbase/constraint.py +117 -0
- diffpy/srfit/fitbase/fitcontribution.py +351 -0
- diffpy/srfit/fitbase/fithook.py +227 -0
- diffpy/srfit/fitbase/fitrecipe.py +826 -0
- diffpy/srfit/fitbase/fitresults.py +674 -0
- diffpy/srfit/fitbase/parameter.py +314 -0
- diffpy/srfit/fitbase/parameterset.py +110 -0
- diffpy/srfit/fitbase/profile.py +405 -0
- diffpy/srfit/fitbase/profilegenerator.py +168 -0
- diffpy/srfit/fitbase/profileparser.py +179 -0
- diffpy/srfit/fitbase/recipeorganizer.py +1074 -0
- diffpy/srfit/fitbase/restraint.py +117 -0
- diffpy/srfit/fitbase/simplerecipe.py +230 -0
- diffpy/srfit/fitbase/validatable.py +59 -0
- diffpy/srfit/interface/__init__.py +33 -0
- diffpy/srfit/interface/interface.py +180 -0
- diffpy/srfit/pdf/__init__.py +24 -0
- diffpy/srfit/pdf/basepdfgenerator.py +296 -0
- diffpy/srfit/pdf/characteristicfunctions.py +432 -0
- diffpy/srfit/pdf/debyepdfgenerator.py +115 -0
- diffpy/srfit/pdf/pdfcontribution.py +311 -0
- diffpy/srfit/pdf/pdfgenerator.py +77 -0
- diffpy/srfit/pdf/pdfparser.py +226 -0
- diffpy/srfit/sas/__init__.py +30 -0
- diffpy/srfit/sas/prcalculator.py +139 -0
- diffpy/srfit/sas/sasgenerator.py +70 -0
- diffpy/srfit/sas/sasimport.py +66 -0
- diffpy/srfit/sas/sasparameter.py +70 -0
- diffpy/srfit/sas/sasparser.py +133 -0
- diffpy/srfit/sas/sasprofile.py +94 -0
- diffpy/srfit/structure/__init__.py +60 -0
- diffpy/srfit/structure/basestructureparset.py +62 -0
- diffpy/srfit/structure/bvsrestraint.py +101 -0
- diffpy/srfit/structure/cctbxparset.py +292 -0
- diffpy/srfit/structure/diffpyparset.py +303 -0
- diffpy/srfit/structure/objcrystparset.py +1552 -0
- diffpy/srfit/structure/sgconstraints.py +761 -0
- diffpy/srfit/structure/srrealparset.py +92 -0
- diffpy/srfit/util/__init__.py +50 -0
- diffpy/srfit/util/argbinders.py +29 -0
- diffpy/srfit/util/inpututils.py +50 -0
- diffpy/srfit/util/nameutils.py +45 -0
- diffpy/srfit/util/observable.py +93 -0
- diffpy/srfit/util/tagmanager.py +150 -0
- diffpy/srfit/util/weakrefcallable.py +170 -0
- diffpy/srfit/version.py +26 -0
- diffpy_srfit-3.1.0.dist-info/METADATA +216 -0
- diffpy_srfit-3.1.0.dist-info/RECORD +73 -0
- diffpy_srfit-3.1.0.dist-info/WHEEL +5 -0
- diffpy_srfit-3.1.0.dist-info/licenses/AUTHORS.rst +10 -0
- diffpy_srfit-3.1.0.dist-info/licenses/LICENSE.rst +138 -0
- diffpy_srfit-3.1.0.dist-info/licenses/LICENSE_DANSE.rst +34 -0
- diffpy_srfit-3.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
##############################################################################
|
|
3
|
+
#
|
|
4
|
+
# diffpy.srfit by DANSE Diffraction group
|
|
5
|
+
# Simon J. L. Billinge
|
|
6
|
+
# (c) 2008 The Trustees of Columbia University
|
|
7
|
+
# in the City of New York. All rights reserved.
|
|
8
|
+
#
|
|
9
|
+
# File coded by: Chris Farrow
|
|
10
|
+
#
|
|
11
|
+
# See AUTHORS.txt for a list of people who contributed.
|
|
12
|
+
# See LICENSE_DANSE.txt for license information.
|
|
13
|
+
#
|
|
14
|
+
##############################################################################
|
|
15
|
+
"""Restraints class.
|
|
16
|
+
|
|
17
|
+
Restraints are used by RecipeOrganizers to organize restraint equations.
|
|
18
|
+
Restraints store an Equation, bounds on its value, and the form of the
|
|
19
|
+
penalty function for breaking a restraint. This penalty is added to the
|
|
20
|
+
residual equation calculated by a FitRecipe.
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
__all__ = ["Restraint"]
|
|
24
|
+
|
|
25
|
+
from numpy import inf
|
|
26
|
+
|
|
27
|
+
from diffpy.srfit.exceptions import SrFitError
|
|
28
|
+
from diffpy.srfit.fitbase.validatable import Validatable
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class Restraint(Validatable):
|
|
32
|
+
"""Restraint class.
|
|
33
|
+
|
|
34
|
+
Attributes
|
|
35
|
+
eq -- An equation whose evaluation is compared against the restraint
|
|
36
|
+
bounds.
|
|
37
|
+
lb -- The lower bound on the restraint evaluation (default -inf).
|
|
38
|
+
ub -- The lower bound on the restraint evaluation (default inf).
|
|
39
|
+
sig -- The uncertainty on the bounds (default 1).
|
|
40
|
+
scaled -- A flag indicating if the restraint is scaled (multiplied) by
|
|
41
|
+
the unrestrained point-average chi^2 (chi^2/numpoints)
|
|
42
|
+
(default False).
|
|
43
|
+
|
|
44
|
+
The penalty is calculated as
|
|
45
|
+
(max(0, lb - val, val - ub)/sig)**2
|
|
46
|
+
and val is the value of the calculated equation. This is multiplied by the
|
|
47
|
+
average chi^2 if scaled is True.
|
|
48
|
+
"""
|
|
49
|
+
|
|
50
|
+
def __init__(self, eq, lb=-inf, ub=inf, sig=1, scaled=False):
|
|
51
|
+
"""Restrain an equation to specified bounds.
|
|
52
|
+
|
|
53
|
+
eq -- An equation whose evaluation is compared against the
|
|
54
|
+
restraint bounds.
|
|
55
|
+
lb -- The lower bound on the restraint evaluation (float, default
|
|
56
|
+
-inf).
|
|
57
|
+
ub -- The lower bound on the restraint evaluation (float, default
|
|
58
|
+
inf).
|
|
59
|
+
sig -- The uncertainty on the bounds (default 1).
|
|
60
|
+
scaled -- A flag indicating if the restraint is scaled (multiplied)
|
|
61
|
+
by the unrestrained point-average chi^2 (chi^2/numpoints)
|
|
62
|
+
(bool, default False).
|
|
63
|
+
"""
|
|
64
|
+
self.eq = eq
|
|
65
|
+
self.lb = float(lb)
|
|
66
|
+
self.ub = float(ub)
|
|
67
|
+
self.sig = float(sig)
|
|
68
|
+
self.scaled = bool(scaled)
|
|
69
|
+
return
|
|
70
|
+
|
|
71
|
+
def penalty(self, w=1.0):
|
|
72
|
+
"""Calculate the penalty of the restraint.
|
|
73
|
+
|
|
74
|
+
w -- The point-average chi^2 which is optionally used to scale the
|
|
75
|
+
penalty (default 1.0).
|
|
76
|
+
|
|
77
|
+
Returns the penalty as a float
|
|
78
|
+
"""
|
|
79
|
+
val = self.eq()
|
|
80
|
+
penalty = (max(0, self.lb - val, val - self.ub) / self.sig) ** 2
|
|
81
|
+
|
|
82
|
+
if self.scaled:
|
|
83
|
+
penalty *= w
|
|
84
|
+
|
|
85
|
+
return penalty
|
|
86
|
+
|
|
87
|
+
def _validate(self):
|
|
88
|
+
"""Validate my state.
|
|
89
|
+
|
|
90
|
+
This validates eq.
|
|
91
|
+
|
|
92
|
+
Raises SrFitError if validation fails.
|
|
93
|
+
"""
|
|
94
|
+
if self.eq is None:
|
|
95
|
+
raise SrFitError("eq is None")
|
|
96
|
+
from diffpy.srfit.equation.visitors import validate
|
|
97
|
+
|
|
98
|
+
try:
|
|
99
|
+
validate(self.eq)
|
|
100
|
+
except ValueError as e:
|
|
101
|
+
raise SrFitError(e)
|
|
102
|
+
|
|
103
|
+
# Try to get the value of eq.
|
|
104
|
+
try:
|
|
105
|
+
val = self.eq()
|
|
106
|
+
except TypeError:
|
|
107
|
+
raise SrFitError("eq cannot be evaluated")
|
|
108
|
+
finally:
|
|
109
|
+
if val is None:
|
|
110
|
+
raise SrFitError("eq evaluates to None")
|
|
111
|
+
|
|
112
|
+
return
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
# End class Restraint
|
|
116
|
+
|
|
117
|
+
# End of file
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
##############################################################################
|
|
3
|
+
#
|
|
4
|
+
# diffpy.srfit by DANSE Diffraction group
|
|
5
|
+
# Simon J. L. Billinge
|
|
6
|
+
# (c) 2008 The Trustees of Columbia University
|
|
7
|
+
# in the City of New York. All rights reserved.
|
|
8
|
+
#
|
|
9
|
+
# File coded by: Chris Farrow
|
|
10
|
+
#
|
|
11
|
+
# See AUTHORS.txt for a list of people who contributed.
|
|
12
|
+
# See LICENSE_DANSE.txt for license information.
|
|
13
|
+
#
|
|
14
|
+
##############################################################################
|
|
15
|
+
"""Simple FitRecipe class that includes a FitContribution and Profile."""
|
|
16
|
+
|
|
17
|
+
from diffpy.srfit.fitbase.fitcontribution import FitContribution
|
|
18
|
+
from diffpy.srfit.fitbase.fitrecipe import FitRecipe
|
|
19
|
+
from diffpy.srfit.fitbase.fitresults import FitResults
|
|
20
|
+
from diffpy.srfit.fitbase.profile import Profile
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class SimpleRecipe(FitRecipe):
|
|
24
|
+
"""SimpleRecipe class.
|
|
25
|
+
|
|
26
|
+
This is a FitRecipe with a built-in Profile (the 'profile' attribute) and
|
|
27
|
+
FitContribution (the 'contribution' attribute). Unique methods from each of
|
|
28
|
+
these are exposed through this class to facilitate the creation of a simple
|
|
29
|
+
fit recipe.
|
|
30
|
+
|
|
31
|
+
Attributes
|
|
32
|
+
profile -- The built-in Profile object.
|
|
33
|
+
contribution -- The built-in FitContribution object.
|
|
34
|
+
results -- The built-in FitResults object.
|
|
35
|
+
name -- A name for this FitRecipe.
|
|
36
|
+
fithook -- An object to be called whenever within the residual
|
|
37
|
+
(default FitHook()) that can pass information out of
|
|
38
|
+
the system during a refinement.
|
|
39
|
+
_constraints -- A dictionary of Constraints, indexed by the constrained
|
|
40
|
+
Parameter. Constraints can be added using the
|
|
41
|
+
'constrain' method.
|
|
42
|
+
_oconstraints -- An ordered list of the constraints from this and all
|
|
43
|
+
sub-components.
|
|
44
|
+
_calculators -- A managed dictionary of Calculators.
|
|
45
|
+
_contributions -- A managed OrderedDict of FitContributions.
|
|
46
|
+
_parameters -- A managed OrderedDict of parameters (in this case the
|
|
47
|
+
parameters are varied).
|
|
48
|
+
_parsets -- A managed dictionary of ParameterSets.
|
|
49
|
+
_eqfactory -- A diffpy.srfit.equation.builder.EquationFactory
|
|
50
|
+
instance that is used to create constraints and
|
|
51
|
+
restraints from string
|
|
52
|
+
_fixed -- A set of parameters that are not actually varied.
|
|
53
|
+
_restraintlist -- A list of restraints from this and all sub-components.
|
|
54
|
+
_restraints -- A set of Restraints. Restraints can be added using the
|
|
55
|
+
'restrain' or 'confine' methods.
|
|
56
|
+
_ready -- A flag indicating if all attributes are ready for the
|
|
57
|
+
calculation.
|
|
58
|
+
_tagdict -- A dictionary of tags to variables.
|
|
59
|
+
_weights -- List of weighing factors for each FitContribution. The
|
|
60
|
+
weights are multiplied by the residual of the
|
|
61
|
+
FitContribution when determining the overall residual.
|
|
62
|
+
|
|
63
|
+
Properties
|
|
64
|
+
names -- Variable names (read only). See getNames.
|
|
65
|
+
values -- Variable values (read only). See getValues.
|
|
66
|
+
"""
|
|
67
|
+
|
|
68
|
+
def __init__(self, name="fit", conclass=FitContribution):
|
|
69
|
+
"""Initialization."""
|
|
70
|
+
FitRecipe.__init__(self, name)
|
|
71
|
+
self.fithooks[0].verbose = 3
|
|
72
|
+
contribution = conclass("contribution")
|
|
73
|
+
self.profile = Profile()
|
|
74
|
+
contribution.setProfile(self.profile)
|
|
75
|
+
self.addContribution(contribution)
|
|
76
|
+
self.results = FitResults(self, update=False)
|
|
77
|
+
|
|
78
|
+
# Adopt all the FitContribution methods
|
|
79
|
+
public = [
|
|
80
|
+
aname
|
|
81
|
+
for aname in dir(contribution)
|
|
82
|
+
if aname not in dir(self) and not aname.startswith("_")
|
|
83
|
+
]
|
|
84
|
+
for mname in public:
|
|
85
|
+
method = getattr(contribution, mname)
|
|
86
|
+
setattr(self, mname, method)
|
|
87
|
+
return
|
|
88
|
+
|
|
89
|
+
# Profile methods
|
|
90
|
+
def loadParsedData(self, parser):
|
|
91
|
+
"""Load parsed data from a ProfileParser.
|
|
92
|
+
|
|
93
|
+
This sets the xobs, yobs, dyobs arrays as well as the metadata.
|
|
94
|
+
"""
|
|
95
|
+
return self.profile.loadParsedData(parser)
|
|
96
|
+
|
|
97
|
+
def setObservedProfile(self, xobs, yobs, dyobs=None):
|
|
98
|
+
"""Set the observed profile.
|
|
99
|
+
|
|
100
|
+
Arguments
|
|
101
|
+
xobs -- Numpy array of the independent variable
|
|
102
|
+
yobs -- Numpy array of the observed signal.
|
|
103
|
+
dyobs -- Numpy array of the uncertainty in the observed signal. If
|
|
104
|
+
dyobs is None (default), it will be set to 1 at each
|
|
105
|
+
observed xobs.
|
|
106
|
+
|
|
107
|
+
Raises ValueError if len(yobs) != len(xobs)
|
|
108
|
+
Raises ValueError if dyobs != None and len(dyobs) != len(xobs)
|
|
109
|
+
"""
|
|
110
|
+
return self.profile.setObservedProfile(xobs, yobs, dyobs)
|
|
111
|
+
|
|
112
|
+
def setCalculationRange(self, xmin=None, xmax=None, dx=None):
|
|
113
|
+
"""Set epsilon-inclusive calculation range.
|
|
114
|
+
|
|
115
|
+
Adhere to the observed ``xobs`` points when ``dx`` is the same
|
|
116
|
+
as in the data. ``xmin`` and ``xmax`` are clipped at the bounds
|
|
117
|
+
of the observed data.
|
|
118
|
+
|
|
119
|
+
Parameters
|
|
120
|
+
----------
|
|
121
|
+
|
|
122
|
+
xmin : float or "obs", optional
|
|
123
|
+
The minimum value of the independent variable. Keep the
|
|
124
|
+
current minimum when not specified. If specified as "obs"
|
|
125
|
+
reset to the minimum observed value.
|
|
126
|
+
xmax : float or "obs", optional
|
|
127
|
+
The maximum value of the independent variable. Keep the
|
|
128
|
+
current maximum when not specified. If specified as "obs"
|
|
129
|
+
reset to the maximum observed value.
|
|
130
|
+
dx : float or "obs", optional
|
|
131
|
+
The sample spacing in the independent variable. When different
|
|
132
|
+
from the data, resample the ``x`` as anchored at ``xmin``.
|
|
133
|
+
|
|
134
|
+
Note that xmin is always inclusive (unless clipped). xmax is inclusive
|
|
135
|
+
if it is within the bounds of the observed data.
|
|
136
|
+
|
|
137
|
+
Raises
|
|
138
|
+
------
|
|
139
|
+
AttributeError
|
|
140
|
+
If there is no observed data.
|
|
141
|
+
ValueError
|
|
142
|
+
When xmin > xmax or if dx <= 0. Also if dx > xmax - xmin.
|
|
143
|
+
"""
|
|
144
|
+
return self.profile.setCalculationRange(xmin, xmax, dx)
|
|
145
|
+
|
|
146
|
+
def setCalculationPoints(self, x):
|
|
147
|
+
"""Set the calculation points.
|
|
148
|
+
|
|
149
|
+
Arguments
|
|
150
|
+
x -- A non-empty numpy array containing the calculation points. If
|
|
151
|
+
xobs exists, the bounds of x will be limited to its bounds.
|
|
152
|
+
|
|
153
|
+
This will create y and dy on the specified grid if xobs, yobs and
|
|
154
|
+
dyobs exist.
|
|
155
|
+
"""
|
|
156
|
+
return self.profile.setCalculationPoints(x)
|
|
157
|
+
|
|
158
|
+
def loadtxt(self, *args, **kw):
|
|
159
|
+
"""Use numpy.loadtxt to load data.
|
|
160
|
+
|
|
161
|
+
Arguments are passed to numpy.loadtxt. unpack = True is
|
|
162
|
+
enforced. The first two arrays returned by numpy.loadtxt are
|
|
163
|
+
assumed to be x and y. If there is a third array, it is assumed
|
|
164
|
+
to by dy. Any other arrays are ignored. These are passed to
|
|
165
|
+
setObservedProfile.
|
|
166
|
+
|
|
167
|
+
Raises ValueError if the call to numpy.loadtxt returns fewer
|
|
168
|
+
than 2 arrays.
|
|
169
|
+
|
|
170
|
+
Returns the x, y and dy arrays loaded from the file
|
|
171
|
+
"""
|
|
172
|
+
return self.profile.loadtxt(*args, **kw)
|
|
173
|
+
|
|
174
|
+
# FitContribution
|
|
175
|
+
def setEquation(self, eqstr, ns={}):
|
|
176
|
+
"""Set the profile equation for the FitContribution.
|
|
177
|
+
|
|
178
|
+
This sets the equation that will be used when generating the residual.
|
|
179
|
+
The equation will be usable within setResidualEquation as "eq", and it
|
|
180
|
+
takes no arguments.
|
|
181
|
+
|
|
182
|
+
eqstr -- A string representation of the equation. Variables will be
|
|
183
|
+
extracted from this equation and be given an initial value
|
|
184
|
+
of 0.
|
|
185
|
+
ns -- A dictionary of Parameters, indexed by name, that are used
|
|
186
|
+
in the eqstr, but not registered (default {}).
|
|
187
|
+
|
|
188
|
+
Raises ValueError if ns uses a name that is already used for a
|
|
189
|
+
variable.
|
|
190
|
+
"""
|
|
191
|
+
self.contribution.setEquation(eqstr, ns={})
|
|
192
|
+
# Extract variables
|
|
193
|
+
for par in self.contribution:
|
|
194
|
+
# Skip Profile Parameters
|
|
195
|
+
if par.name in ("x", "y", "dy"):
|
|
196
|
+
continue
|
|
197
|
+
if par.value is None:
|
|
198
|
+
par.value = 0
|
|
199
|
+
if par.name not in self._parameters:
|
|
200
|
+
self.addVar(par)
|
|
201
|
+
return
|
|
202
|
+
|
|
203
|
+
def __call__(self):
|
|
204
|
+
"""Evaluate the contribution equation."""
|
|
205
|
+
return self.contribution.evaluate()
|
|
206
|
+
|
|
207
|
+
# FitResults methods
|
|
208
|
+
|
|
209
|
+
def printResults(self, header="", footer=""):
|
|
210
|
+
"""Format and print the results.
|
|
211
|
+
|
|
212
|
+
header -- A header to add to the output (default "")
|
|
213
|
+
footer -- A footer to add to the output (default "")
|
|
214
|
+
"""
|
|
215
|
+
self.results.printResults(header, footer, True)
|
|
216
|
+
return
|
|
217
|
+
|
|
218
|
+
def saveResults(self, filename, header="", footer=""):
|
|
219
|
+
"""Format and save the results.
|
|
220
|
+
|
|
221
|
+
filename - Name of the save file.
|
|
222
|
+
header -- A header to add to the output (default "")
|
|
223
|
+
footer -- A footer to add to the output (default "")
|
|
224
|
+
"""
|
|
225
|
+
self.results.saveResults(filename, header, footer, True)
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
# End class SimpleRecipe
|
|
229
|
+
|
|
230
|
+
# End of file
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
##############################################################################
|
|
3
|
+
#
|
|
4
|
+
# diffpy.srfit by DANSE Diffraction group
|
|
5
|
+
# Simon J. L. Billinge
|
|
6
|
+
# (c) 2008 The Trustees of Columbia University
|
|
7
|
+
# in the City of New York. All rights reserved.
|
|
8
|
+
#
|
|
9
|
+
# File coded by: Chris Farrow
|
|
10
|
+
#
|
|
11
|
+
# See AUTHORS.txt for a list of people who contributed.
|
|
12
|
+
# See LICENSE_DANSE.txt for license information.
|
|
13
|
+
#
|
|
14
|
+
##############################################################################
|
|
15
|
+
"""Validatable class.
|
|
16
|
+
|
|
17
|
+
A Validatable has state that must be validated before a FitRecipe can
|
|
18
|
+
first calculate the residual.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
__all__ = ["Validatable"]
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class Validatable(object):
|
|
25
|
+
"""Validatable class.
|
|
26
|
+
|
|
27
|
+
A Validatable has state that must be validated by a FitRecipe.
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
def _validateOthers(self, iterable):
|
|
31
|
+
"""Method to validate configuration of Validatables in iterable.
|
|
32
|
+
|
|
33
|
+
This is provided as a convenience for derived classes. No need
|
|
34
|
+
to overload this. Call this method from overloaded _validate
|
|
35
|
+
with an iterable of other Validatables.
|
|
36
|
+
"""
|
|
37
|
+
for obj in iterable:
|
|
38
|
+
if obj is self:
|
|
39
|
+
continue
|
|
40
|
+
if isinstance(obj, Validatable):
|
|
41
|
+
obj._validate()
|
|
42
|
+
|
|
43
|
+
return
|
|
44
|
+
|
|
45
|
+
def _validate(self):
|
|
46
|
+
"""Validate self and Validatables.
|
|
47
|
+
|
|
48
|
+
Overload this in a derived class.
|
|
49
|
+
|
|
50
|
+
Raises AttributeError if validation fails.
|
|
51
|
+
"""
|
|
52
|
+
# Validate self here.
|
|
53
|
+
# Then validate others.
|
|
54
|
+
return
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
# End class Validatable
|
|
58
|
+
|
|
59
|
+
# End of file
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
##############################################################################
|
|
3
|
+
#
|
|
4
|
+
# diffpy.srfit by DANSE Diffraction group
|
|
5
|
+
# Simon J. L. Billinge
|
|
6
|
+
# (c) 2010 The Trustees of Columbia University
|
|
7
|
+
# in the City of New York. All rights reserved.
|
|
8
|
+
#
|
|
9
|
+
# File coded by: Chris Farrow
|
|
10
|
+
#
|
|
11
|
+
# See AUTHORS.txt for a list of people who contributed.
|
|
12
|
+
# See LICENSE_DANSE.txt for license information.
|
|
13
|
+
#
|
|
14
|
+
##############################################################################
|
|
15
|
+
"""Usability interface for SrFit.
|
|
16
|
+
|
|
17
|
+
The classes and functions in this package are designed to unobtrusively
|
|
18
|
+
mix with base SrFit objects and provide them with interface enhancements
|
|
19
|
+
for scripting.
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
from diffpy.srfit.interface.interface import (
|
|
24
|
+
FitRecipeInterface,
|
|
25
|
+
ParameterInterface,
|
|
26
|
+
RecipeOrganizerInterface,
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
_parameter_interface = ParameterInterface
|
|
30
|
+
_recipeorganizer_interface = RecipeOrganizerInterface
|
|
31
|
+
_fitrecipe_interface = FitRecipeInterface
|
|
32
|
+
|
|
33
|
+
# End of file
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
##############################################################################
|
|
3
|
+
#
|
|
4
|
+
# diffpy.srfit by DANSE Diffraction group
|
|
5
|
+
# Simon J. L. Billinge
|
|
6
|
+
# (c) 2010 The Trustees of Columbia University
|
|
7
|
+
# in the City of New York. All rights reserved.
|
|
8
|
+
#
|
|
9
|
+
# File coded by: Chris Farrow
|
|
10
|
+
#
|
|
11
|
+
# See AUTHORS.txt for a list of people who contributed.
|
|
12
|
+
# See LICENSE_DANSE.txt for license information.
|
|
13
|
+
#
|
|
14
|
+
##############################################################################
|
|
15
|
+
"""Interface enhancements for Parameter-type classes.
|
|
16
|
+
|
|
17
|
+
Most interface additions can thought of by considering the classes in
|
|
18
|
+
SrFit to be sets of parameters. "+=" adds a new parameter, when that
|
|
19
|
+
makes sense. "|=" is the 'union' of these sets, and in general is used
|
|
20
|
+
to combine different objects. See individual interface classes for
|
|
21
|
+
specifics.
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
__all__ = [
|
|
25
|
+
"ParameterInterface",
|
|
26
|
+
"FitRecipeInterface",
|
|
27
|
+
"RecipeOrganizerInterface",
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
import six
|
|
31
|
+
|
|
32
|
+
from diffpy.srfit.equation.literals.abcs import ArgumentABC
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class ParameterInterface(object):
|
|
36
|
+
"""Mix-in class for enhancing the Parameter interface."""
|
|
37
|
+
|
|
38
|
+
def __lshift__(self, v):
|
|
39
|
+
"""SetValue with <<
|
|
40
|
+
|
|
41
|
+
Think of '<<' as injecting a value
|
|
42
|
+
|
|
43
|
+
v -- value or Argument derivative
|
|
44
|
+
"""
|
|
45
|
+
if isinstance(v, ArgumentABC):
|
|
46
|
+
self.value = v.value
|
|
47
|
+
else:
|
|
48
|
+
self.value = v
|
|
49
|
+
return self
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
# End class ParameterInterface
|
|
53
|
+
|
|
54
|
+
# ----------------------------------------------------------------------------
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
class RecipeOrganizerInterface(object):
|
|
58
|
+
"""Mix-in class for enhancing the RecipeOrganizer interface."""
|
|
59
|
+
|
|
60
|
+
def __imul__(self, args):
|
|
61
|
+
"""Constrain with *=
|
|
62
|
+
|
|
63
|
+
Think of '*' as a push-pin.
|
|
64
|
+
|
|
65
|
+
This accepts arguments for a single constraint.
|
|
66
|
+
"""
|
|
67
|
+
_applyargs(args, self.constrain)
|
|
68
|
+
return self
|
|
69
|
+
|
|
70
|
+
def __imod__(self, args):
|
|
71
|
+
"""Restrain with %=
|
|
72
|
+
|
|
73
|
+
This of '%' as a loose rope.
|
|
74
|
+
|
|
75
|
+
This accepts arguments for a single restraint.
|
|
76
|
+
"""
|
|
77
|
+
_applyargs(args, self.restrain)
|
|
78
|
+
return self
|
|
79
|
+
|
|
80
|
+
def __iadd__(self, args):
|
|
81
|
+
"""_newParameter or _addParameter with +=
|
|
82
|
+
|
|
83
|
+
Think of "+" as addition of a Parameter.
|
|
84
|
+
|
|
85
|
+
This accepts arguments for a single function call.
|
|
86
|
+
"""
|
|
87
|
+
|
|
88
|
+
# Want to detect _addParameter or _newParameter
|
|
89
|
+
def f(*args):
|
|
90
|
+
if isinstance(args[0], six.string_types):
|
|
91
|
+
self._newParameter(*args)
|
|
92
|
+
else:
|
|
93
|
+
self._addParameter(*args)
|
|
94
|
+
return
|
|
95
|
+
|
|
96
|
+
_applyargs(args, f)
|
|
97
|
+
return self
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
# End class RecipeOrganizerInterface
|
|
101
|
+
|
|
102
|
+
# ----------------------------------------------------------------------------
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
class FitRecipeInterface(object):
|
|
106
|
+
"""Mix-in class for enhancing the FitRecipe interface."""
|
|
107
|
+
|
|
108
|
+
def __ior__(self, args):
|
|
109
|
+
"""AddContribution with |=
|
|
110
|
+
|
|
111
|
+
Think of "|" as the union of components.
|
|
112
|
+
|
|
113
|
+
This accepts a single argument.
|
|
114
|
+
"""
|
|
115
|
+
self.addContribution(args)
|
|
116
|
+
return self
|
|
117
|
+
|
|
118
|
+
def __iadd__(self, args):
|
|
119
|
+
"""AddVar or newVar with +=
|
|
120
|
+
|
|
121
|
+
Think of "+" as addition of a variable.
|
|
122
|
+
|
|
123
|
+
This accepts a single argument or an iterable of single
|
|
124
|
+
arguments or argument tuples.
|
|
125
|
+
"""
|
|
126
|
+
|
|
127
|
+
# Want to detect addVar or newVar
|
|
128
|
+
def f(*args):
|
|
129
|
+
if isinstance(args[0], six.string_types):
|
|
130
|
+
self.newVar(*args)
|
|
131
|
+
else:
|
|
132
|
+
self.addVar(*args)
|
|
133
|
+
return
|
|
134
|
+
|
|
135
|
+
_applymanyargs(args, f)
|
|
136
|
+
return self
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
# End class FitRecipeInterface
|
|
140
|
+
|
|
141
|
+
# Local helper functions -----------------------------------------------------
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def _applymanyargs(args, f):
|
|
145
|
+
"""Apply arguments to a function.
|
|
146
|
+
|
|
147
|
+
Args can be any of the following.
|
|
148
|
+
arg
|
|
149
|
+
(arg1, arg2, ...)
|
|
150
|
+
((arg1a, arg1b, ...), ...)
|
|
151
|
+
"""
|
|
152
|
+
if not hasattr(args, "__iter__"):
|
|
153
|
+
f(args)
|
|
154
|
+
return
|
|
155
|
+
|
|
156
|
+
for arg in args:
|
|
157
|
+
if hasattr(arg, "__iter__"):
|
|
158
|
+
f(*arg)
|
|
159
|
+
else:
|
|
160
|
+
f(arg)
|
|
161
|
+
|
|
162
|
+
return
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def _applyargs(args, f):
|
|
166
|
+
"""Apply arguments to a function.
|
|
167
|
+
|
|
168
|
+
Args can be any of the following.
|
|
169
|
+
arg
|
|
170
|
+
(arg1, arg2, ...)
|
|
171
|
+
((arg1a, arg1b, ...), ...)
|
|
172
|
+
"""
|
|
173
|
+
if not hasattr(args, "__iter__"):
|
|
174
|
+
f(args)
|
|
175
|
+
else:
|
|
176
|
+
f(*args)
|
|
177
|
+
return
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
# End of file
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
##############################################################################
|
|
3
|
+
#
|
|
4
|
+
# diffpy.srfit by DANSE Diffraction group
|
|
5
|
+
# Simon J. L. Billinge
|
|
6
|
+
# (c) 2008 The Trustees of Columbia University
|
|
7
|
+
# in the City of New York. All rights reserved.
|
|
8
|
+
#
|
|
9
|
+
# File coded by: Chris Farrow
|
|
10
|
+
#
|
|
11
|
+
# See AUTHORS.txt for a list of people who contributed.
|
|
12
|
+
# See LICENSE_DANSE.txt for license information.
|
|
13
|
+
#
|
|
14
|
+
##############################################################################
|
|
15
|
+
"""PDF calculation tools."""
|
|
16
|
+
|
|
17
|
+
__all__ = ["PDFGenerator", "DebyePDFGenerator", "PDFContribution", "PDFParser"]
|
|
18
|
+
|
|
19
|
+
from diffpy.srfit.pdf.debyepdfgenerator import DebyePDFGenerator
|
|
20
|
+
from diffpy.srfit.pdf.pdfcontribution import PDFContribution
|
|
21
|
+
from diffpy.srfit.pdf.pdfgenerator import PDFGenerator
|
|
22
|
+
from diffpy.srfit.pdf.pdfparser import PDFParser
|
|
23
|
+
|
|
24
|
+
# End of file
|