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,139 @@
|
|
|
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
|
+
"""Nanoparticle form factor P(r) calculator.
|
|
16
|
+
|
|
17
|
+
The PrCalculator class wraps a sas.pr.invertor.Invertor object as a
|
|
18
|
+
Calculator. This is not wrapped as a ProfileGenerator because it will be
|
|
19
|
+
used to share information between SAS I(Q) to PDF G(r), but it does not
|
|
20
|
+
use the same profile as the PDF, which is where the calculator will be
|
|
21
|
+
applied.
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
__all__ = ["PrCalculator", "CFCalculator"]
|
|
25
|
+
|
|
26
|
+
from functools import partial
|
|
27
|
+
|
|
28
|
+
import numpy
|
|
29
|
+
|
|
30
|
+
from diffpy.srfit.fitbase import Calculator
|
|
31
|
+
|
|
32
|
+
Invertor = None
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class PrCalculator(Calculator):
|
|
36
|
+
"""A class for calculating P(r) from data.
|
|
37
|
+
|
|
38
|
+
This is provided so that SAS data can be used to calculate a nanoparticle
|
|
39
|
+
form factor (characteristic function) for nanoparticle PDF refinements. For
|
|
40
|
+
a crystal-like nanoparticle:
|
|
41
|
+
Gnano(r) = f(r)Gcrystal(r),
|
|
42
|
+
where f(r) is the nanoparticle form factor.
|
|
43
|
+
This is obtained from P(r) as
|
|
44
|
+
P(r) = 4 pi r**2 f(r).
|
|
45
|
+
|
|
46
|
+
Attributes:
|
|
47
|
+
_invertor -- sas.pr.invertor.Invertor object. This object is internal,
|
|
48
|
+
but can be configured by the user after initialization.
|
|
49
|
+
Note that the 'x', 'y' and 'err' attributes get overwritten
|
|
50
|
+
every time the invertor is used.
|
|
51
|
+
|
|
52
|
+
Managed Parameters:
|
|
53
|
+
scale -- The scale factor (default 1).
|
|
54
|
+
q -- The q-values of the I(q) signal
|
|
55
|
+
iq -- The I(q) signal
|
|
56
|
+
diq -- The uncertainty in I(q)
|
|
57
|
+
"""
|
|
58
|
+
|
|
59
|
+
def __init__(self, name):
|
|
60
|
+
"""Initialize the generator.
|
|
61
|
+
|
|
62
|
+
name -- A name for the PrCalculator
|
|
63
|
+
"""
|
|
64
|
+
Calculator.__init__(self, name)
|
|
65
|
+
|
|
66
|
+
# delayed import of Invertor
|
|
67
|
+
global Invertor
|
|
68
|
+
if Invertor is None:
|
|
69
|
+
from diffpy.srfit.sas.sasimport import sasimport
|
|
70
|
+
|
|
71
|
+
Invertor = sasimport("sas.pr.invertor").Invertor
|
|
72
|
+
|
|
73
|
+
self._invertor = Invertor()
|
|
74
|
+
|
|
75
|
+
self._newParameter("scale", 1)
|
|
76
|
+
self._newParameter("q", None)
|
|
77
|
+
self._newParameter("iq", None)
|
|
78
|
+
self._newParameter("diq", None)
|
|
79
|
+
return
|
|
80
|
+
|
|
81
|
+
def __call__(self, r):
|
|
82
|
+
"""Calculate P(r) from the data or calculated signal."""
|
|
83
|
+
q = self.q.value
|
|
84
|
+
iq = self.iq.value
|
|
85
|
+
diq = self.diq.value
|
|
86
|
+
if diq is None:
|
|
87
|
+
diq = numpy.ones_like(q)
|
|
88
|
+
self._invertor.d_max = max(r) + 5.0
|
|
89
|
+
# Assume profile doesn't include 0. It's up to the user to make this
|
|
90
|
+
# happen.
|
|
91
|
+
self._invertor.x = q
|
|
92
|
+
self._invertor.y = iq
|
|
93
|
+
self._invertor.err = diq
|
|
94
|
+
c, c_cov = self._invertor.invert_optimize()
|
|
95
|
+
_inverted_w_c = partial(self._inverted, c=c)
|
|
96
|
+
pr = map(_inverted_w_c, r)
|
|
97
|
+
|
|
98
|
+
pr = numpy.array(pr)
|
|
99
|
+
return self.scale.value * pr
|
|
100
|
+
|
|
101
|
+
def _inverted(self, x, c):
|
|
102
|
+
self._invertor.pr(c, x)
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
# End class PrCalculator
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
class CFCalculator(PrCalculator):
|
|
109
|
+
"""A class for calculating the characteristic function (CF) from data.
|
|
110
|
+
|
|
111
|
+
This calculator produces
|
|
112
|
+
f(r) = P(r) / 4 pi r**2
|
|
113
|
+
which is the nanoparticle form factor scaled by density.
|
|
114
|
+
|
|
115
|
+
Attributes:
|
|
116
|
+
_invertor -- sas.pr.invertor.Invertor object. This object is internal,
|
|
117
|
+
but can be configured by the user after initialization.
|
|
118
|
+
Note that the 'x', 'y' and 'err' attributes get overwritten
|
|
119
|
+
every time the invertor is used.
|
|
120
|
+
|
|
121
|
+
Managed Parameters:
|
|
122
|
+
scale -- The scale factor (default 1).
|
|
123
|
+
q -- The q-values of the I(q) signal
|
|
124
|
+
iq -- The I(q) signal
|
|
125
|
+
diq -- The uncertainty in I(q)
|
|
126
|
+
"""
|
|
127
|
+
|
|
128
|
+
def __call__(self, r):
|
|
129
|
+
"""Calculate P(r) from the data or calculated signal."""
|
|
130
|
+
fr = PrCalculator.__call__(self, r)
|
|
131
|
+
fr /= 4 * numpy.pi * r**2
|
|
132
|
+
if r[0] == 0:
|
|
133
|
+
# Assume the scale makes fr properly normalized. We don't have much
|
|
134
|
+
# other choice.
|
|
135
|
+
fr[0] = 1
|
|
136
|
+
return fr
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
# End class CFCalculator
|
|
@@ -0,0 +1,70 @@
|
|
|
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
|
+
"""SAS profile generator.
|
|
16
|
+
|
|
17
|
+
The SASGenerator class wraps a sas.models.BaseModel object as a
|
|
18
|
+
ProfileGenerator.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
__all__ = ["SASGenerator"]
|
|
22
|
+
|
|
23
|
+
from diffpy.srfit.fitbase import ProfileGenerator
|
|
24
|
+
from diffpy.srfit.sas.sasparameter import SASParameter
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class SASGenerator(ProfileGenerator):
|
|
28
|
+
"""A class for calculating I(Q) from a scattering type.
|
|
29
|
+
|
|
30
|
+
Attributes:
|
|
31
|
+
_model -- BaseModel object this adapts.
|
|
32
|
+
|
|
33
|
+
Managed Parameters:
|
|
34
|
+
These depend on the parameters of the BaseModel object held by _model. They
|
|
35
|
+
are created from the 'params' attribute of the BaseModel. If a dispersion
|
|
36
|
+
is set for the BaseModel, the dispersion "width" will be accessible under
|
|
37
|
+
"<parname>_width", where <parname> is the name a parameter adjusted by
|
|
38
|
+
dispersion.
|
|
39
|
+
"""
|
|
40
|
+
|
|
41
|
+
def __init__(self, name, model):
|
|
42
|
+
"""Initialize the generator.
|
|
43
|
+
|
|
44
|
+
name -- A name for the SASGenerator
|
|
45
|
+
model -- SASModel object this adapts.
|
|
46
|
+
"""
|
|
47
|
+
ProfileGenerator.__init__(self, name)
|
|
48
|
+
|
|
49
|
+
self._model = model
|
|
50
|
+
|
|
51
|
+
# Wrap normal parameters
|
|
52
|
+
for parname in model.params:
|
|
53
|
+
par = SASParameter(parname, model)
|
|
54
|
+
self.addParameter(par)
|
|
55
|
+
|
|
56
|
+
# Wrap dispersion parameters
|
|
57
|
+
for parname in model.dispersion:
|
|
58
|
+
name = parname + "_width"
|
|
59
|
+
parname += ".width"
|
|
60
|
+
par = SASParameter(name, model, parname)
|
|
61
|
+
self.addParameter(par)
|
|
62
|
+
|
|
63
|
+
return
|
|
64
|
+
|
|
65
|
+
def __call__(self, q):
|
|
66
|
+
"""Calculate I(Q) for the BaseModel."""
|
|
67
|
+
return self._model.evalDistribution(q)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
# End class SASGenerator
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
##############################################################################
|
|
3
|
+
#
|
|
4
|
+
# diffpy.srfit Complex Modeling Initiative
|
|
5
|
+
# (c) 2015 Brookhaven Science Associates,
|
|
6
|
+
# Brookhaven National Laboratory.
|
|
7
|
+
# All rights reserved.
|
|
8
|
+
#
|
|
9
|
+
# File coded by: Pavol Juhas
|
|
10
|
+
#
|
|
11
|
+
# See AUTHORS.txt for a list of people who contributed.
|
|
12
|
+
# See LICENSE.txt for license information.
|
|
13
|
+
#
|
|
14
|
+
##############################################################################
|
|
15
|
+
"""Universal import functions for volatile SasView/SansViews API-s."""
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def sasimport(modname):
|
|
19
|
+
"""Import specified module from the SasView sas package.
|
|
20
|
+
|
|
21
|
+
modname -- absolute module name contained in the sas package.
|
|
22
|
+
|
|
23
|
+
When specified import does not work directly, try older API-s and raise
|
|
24
|
+
DeprecationWarning. Raise ImportError if nothing works.
|
|
25
|
+
"""
|
|
26
|
+
if not modname.startswith("sas."):
|
|
27
|
+
emsg = 'Module name must start with "sas."'
|
|
28
|
+
raise ValueError(emsg)
|
|
29
|
+
mobj = None
|
|
30
|
+
# standard import
|
|
31
|
+
try:
|
|
32
|
+
exec("import %s as mobj" % modname)
|
|
33
|
+
except ImportError:
|
|
34
|
+
pass
|
|
35
|
+
else:
|
|
36
|
+
return mobj
|
|
37
|
+
# revert to the old sans namespace, sas --> sans
|
|
38
|
+
modsans = "sans" + modname[3:]
|
|
39
|
+
import warnings
|
|
40
|
+
|
|
41
|
+
wfmt = (
|
|
42
|
+
"Using obsolete package %r instead of %r. Please install "
|
|
43
|
+
"SasView 3.1 or the srfit-sasview package from Anaconda."
|
|
44
|
+
)
|
|
45
|
+
wmsg = wfmt % (modsans, modname)
|
|
46
|
+
try:
|
|
47
|
+
exec("import %s as mobj" % modsans)
|
|
48
|
+
warnings.warn(wmsg, DeprecationWarning)
|
|
49
|
+
except ImportError:
|
|
50
|
+
pass
|
|
51
|
+
else:
|
|
52
|
+
return mobj
|
|
53
|
+
# finally check the oldest DataLoader API for sas.dataloader
|
|
54
|
+
if modname.startswith("sas.dataloader"):
|
|
55
|
+
modloader = "DataLoader" + modname[14:]
|
|
56
|
+
wmsg = wfmt % (modloader, modname)
|
|
57
|
+
try:
|
|
58
|
+
exec("import %s as mobj" % modloader)
|
|
59
|
+
warnings.warn(wmsg, DeprecationWarning)
|
|
60
|
+
except ImportError:
|
|
61
|
+
pass
|
|
62
|
+
else:
|
|
63
|
+
return mobj
|
|
64
|
+
# Obsolete API-s failed here. Import again and let it raise ImportError.
|
|
65
|
+
exec("import %s as mobj" % modname)
|
|
66
|
+
raise AssertionError("The import above was supposed to fail.")
|
|
@@ -0,0 +1,70 @@
|
|
|
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
|
+
"""SAS profile generator.
|
|
16
|
+
|
|
17
|
+
The SASGenerator class wraps a sas.models.BaseModel object as a
|
|
18
|
+
ProfileGenerator.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
__all__ = ["SASParameter"]
|
|
22
|
+
|
|
23
|
+
from diffpy.srfit.fitbase.parameter import Parameter
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class SASParameter(Parameter):
|
|
27
|
+
"""Class adapting a sasmodel parameter to srfit Parameter.
|
|
28
|
+
|
|
29
|
+
Attributes
|
|
30
|
+
name -- A name for this Parameter.
|
|
31
|
+
const -- A flag indicating whether this is considered a constant.
|
|
32
|
+
_value -- The value of the Parameter. Modified with 'setValue'.
|
|
33
|
+
value -- Property for 'getValue' and 'setValue'.
|
|
34
|
+
constrained -- A flag indicating if the Parameter is constrained
|
|
35
|
+
(default False).
|
|
36
|
+
bounds -- A 2-list defining the bounds on the Parameter. This can be
|
|
37
|
+
used by some optimizers when the Parameter is varied. These
|
|
38
|
+
bounds are unrelated to restraints on a Parameter.
|
|
39
|
+
_model -- The BaseModel to which the underlying parameter belongs.
|
|
40
|
+
_parname -- The name of the underlying BaseModel parameter.
|
|
41
|
+
"""
|
|
42
|
+
|
|
43
|
+
def __init__(self, name, model, parname=None):
|
|
44
|
+
"""Create the Parameter.
|
|
45
|
+
|
|
46
|
+
name -- Name of the Parameter
|
|
47
|
+
model -- The BaseModel to which the underlying parameter belongs
|
|
48
|
+
parname -- Name of parameter used by the model. If this is None
|
|
49
|
+
(default), then name is used.
|
|
50
|
+
"""
|
|
51
|
+
self._parname = parname or name
|
|
52
|
+
val = model.getParam(self._parname)
|
|
53
|
+
self._model = model
|
|
54
|
+
Parameter.__init__(self, name, val)
|
|
55
|
+
return
|
|
56
|
+
|
|
57
|
+
def getValue(self):
|
|
58
|
+
"""Get the value of the Parameter."""
|
|
59
|
+
value = self._model.getParam(self._parname)
|
|
60
|
+
return value
|
|
61
|
+
|
|
62
|
+
def setValue(self, value):
|
|
63
|
+
"""Set the value of the Parameter."""
|
|
64
|
+
if value != self.getValue():
|
|
65
|
+
self._model.setParam(self._parname, value)
|
|
66
|
+
self.notify()
|
|
67
|
+
return self
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
# End of class SASParameter
|
|
@@ -0,0 +1,133 @@
|
|
|
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
|
+
"""This module contains parsers for SAS data.
|
|
16
|
+
|
|
17
|
+
SASParser uses the sas DataLoader class to load data.
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
__all__ = ["SASParser"]
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
from diffpy.srfit.exceptions import ParseError
|
|
24
|
+
from diffpy.srfit.fitbase.profileparser import ProfileParser
|
|
25
|
+
from diffpy.srfit.sas.sasimport import sasimport
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class SASParser(ProfileParser):
|
|
29
|
+
"""Class for parsing a sas profile.
|
|
30
|
+
|
|
31
|
+
This uses a sas DataLoader to load the data. The DataInfo object it returns
|
|
32
|
+
is held in the metadata under the name "datainfo".
|
|
33
|
+
|
|
34
|
+
Attributes
|
|
35
|
+
|
|
36
|
+
_format -- Name of the data format that this parses (string, default
|
|
37
|
+
""). The format string is a unique identifier for the data
|
|
38
|
+
format handled by the parser.
|
|
39
|
+
_banks -- The data from each bank. Each bank contains a
|
|
40
|
+
(x, y, dx, dy) tuple:
|
|
41
|
+
x -- A numpy array containing the independent
|
|
42
|
+
variable read from the file.
|
|
43
|
+
y -- A numpy array containing the profile
|
|
44
|
+
from the file.
|
|
45
|
+
dx -- A numpy array containing the uncertainty in x
|
|
46
|
+
read from the file. This is 0 if the
|
|
47
|
+
uncertainty cannot be read.
|
|
48
|
+
dy -- A numpy array containing the uncertainty read
|
|
49
|
+
from the file. This is 0 if the uncertainty
|
|
50
|
+
cannot be read.
|
|
51
|
+
_x -- Independent variable from the chosen bank
|
|
52
|
+
_y -- Profile from the chosen bank
|
|
53
|
+
_dx -- Uncertainty in independent variable from the chosen bank
|
|
54
|
+
_dy -- Uncertainty in profile from the chosen bank
|
|
55
|
+
_meta -- A dictionary containing metadata read from the file.
|
|
56
|
+
|
|
57
|
+
General Metadata
|
|
58
|
+
|
|
59
|
+
filename -- The name of the file from which data was parsed. This key
|
|
60
|
+
will not exist if data was not read from file.
|
|
61
|
+
nbanks -- The number of banks parsed.
|
|
62
|
+
bank -- The chosen bank number.
|
|
63
|
+
|
|
64
|
+
Metadata - These may appear in the metadata dictionary
|
|
65
|
+
|
|
66
|
+
datainfo -- The DataInfo object used to do the data parsing.
|
|
67
|
+
"""
|
|
68
|
+
|
|
69
|
+
_format = "SAS"
|
|
70
|
+
|
|
71
|
+
def parseFile(self, filename):
|
|
72
|
+
"""Parse a file and set the _x, _y, _dx, _dy and _meta variables.
|
|
73
|
+
|
|
74
|
+
This wipes out the currently loaded data and selected bank number.
|
|
75
|
+
|
|
76
|
+
Arguments
|
|
77
|
+
filename -- The name of the file to parse
|
|
78
|
+
|
|
79
|
+
Raises IOError if the file cannot be read
|
|
80
|
+
Raises ParseError if the file cannot be parsed
|
|
81
|
+
"""
|
|
82
|
+
|
|
83
|
+
Loader = sasimport("sas.dataloader.loader").Loader
|
|
84
|
+
loader = Loader()
|
|
85
|
+
|
|
86
|
+
try:
|
|
87
|
+
data = loader.load(filename)
|
|
88
|
+
except RuntimeError as e:
|
|
89
|
+
raise ParseError(e)
|
|
90
|
+
except ValueError as e:
|
|
91
|
+
raise ParseError(e)
|
|
92
|
+
|
|
93
|
+
self._banks = []
|
|
94
|
+
self._meta = {}
|
|
95
|
+
self._meta["filename"] = filename
|
|
96
|
+
self._meta["datainfo"] = data
|
|
97
|
+
|
|
98
|
+
self._banks.append([data.x, data.y, data.dx, data.dy])
|
|
99
|
+
self.selectBank(0)
|
|
100
|
+
return
|
|
101
|
+
|
|
102
|
+
def parseString(self, patstring):
|
|
103
|
+
"""Parse a string and set the _x, _y, _dx, _dy and _meta variables.
|
|
104
|
+
|
|
105
|
+
When _dx or _dy cannot be obtained in the data format it is set to 0.
|
|
106
|
+
|
|
107
|
+
This wipes out the currently loaded data and selected bank number.
|
|
108
|
+
|
|
109
|
+
Arguments
|
|
110
|
+
patstring -- A string containing the pattern
|
|
111
|
+
|
|
112
|
+
Raises ParseError if the string cannot be parsed
|
|
113
|
+
"""
|
|
114
|
+
# This calls on parseFile, as that is how the sas data loader works.
|
|
115
|
+
import tempfile
|
|
116
|
+
|
|
117
|
+
fh, fn = tempfile.mkstemp()
|
|
118
|
+
outfile = open(fn, "w")
|
|
119
|
+
fn.write(patstring)
|
|
120
|
+
outfile.close()
|
|
121
|
+
self.parseFile(fn)
|
|
122
|
+
|
|
123
|
+
del self._metadata["filename"]
|
|
124
|
+
|
|
125
|
+
# Close the temporary file and delete it
|
|
126
|
+
import os
|
|
127
|
+
|
|
128
|
+
os.close(fh)
|
|
129
|
+
os.remove(fn)
|
|
130
|
+
return
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
# End of class SASParser
|
|
@@ -0,0 +1,94 @@
|
|
|
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
|
+
"""Class for adapting a sas DataInfo objects to the Profile interface."""
|
|
16
|
+
|
|
17
|
+
__all__ = ["SASProfile"]
|
|
18
|
+
|
|
19
|
+
from numpy import ones_like
|
|
20
|
+
|
|
21
|
+
from diffpy.srfit.fitbase.profile import Profile
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class SASProfile(Profile):
|
|
25
|
+
"""Observed and calculated profile container for SAS data.
|
|
26
|
+
|
|
27
|
+
This wraps a sas DataInfo object as a Profile object. Use this when you
|
|
28
|
+
want to use and manipulate a DataProfile before using it with SrFit.
|
|
29
|
+
Otherwise, use the SASParser class and load the data into a base Profile
|
|
30
|
+
object.
|
|
31
|
+
|
|
32
|
+
Attributes
|
|
33
|
+
|
|
34
|
+
_xobs -- A numpy array of the observed independent variable (default
|
|
35
|
+
None)
|
|
36
|
+
xobs -- Read-only property of _xobs.
|
|
37
|
+
_yobs -- A numpy array of the observed signal (default None)
|
|
38
|
+
yobs -- Read-only property of _yobs.
|
|
39
|
+
_dyobs -- A numpy array of the uncertainty of the observed signal
|
|
40
|
+
(default None, optional).
|
|
41
|
+
dyobs -- Read-only property of _dyobs.
|
|
42
|
+
x -- A numpy array of the calculated independent variable (default
|
|
43
|
+
None, property for xpar accessors).
|
|
44
|
+
y -- The profile over the calculation range (default None, property
|
|
45
|
+
for ypar accessors).
|
|
46
|
+
dy -- The uncertainty in the profile over the calculation range
|
|
47
|
+
(default None, property for dypar accessors).
|
|
48
|
+
ycalc -- A numpy array of the calculated signal (default None).
|
|
49
|
+
xpar -- A ProfileParameter that stores x (named "x").
|
|
50
|
+
ypar -- A ProfileParameter that stores y (named "y").
|
|
51
|
+
dypar -- A ProfileParameter that stores dy (named "dy").
|
|
52
|
+
meta -- A dictionary of metadata. This is only set if provided by a
|
|
53
|
+
parser.
|
|
54
|
+
|
|
55
|
+
_datainfo -- The DataInfo object this wraps.
|
|
56
|
+
"""
|
|
57
|
+
|
|
58
|
+
def __init__(self, datainfo):
|
|
59
|
+
"""Initialize the attributes.
|
|
60
|
+
|
|
61
|
+
datainfo -- The DataInfo object this wraps.
|
|
62
|
+
"""
|
|
63
|
+
self._datainfo = datainfo
|
|
64
|
+
Profile.__init__(self)
|
|
65
|
+
|
|
66
|
+
self._xobs = self._datainfo.x
|
|
67
|
+
self._yobs = self._datainfo.y
|
|
68
|
+
if self._datainfo.dy is None or 0 == len(self._datainfo.dy):
|
|
69
|
+
self._dyobs = ones_like(self.xobs)
|
|
70
|
+
else:
|
|
71
|
+
self._dyobs = self._datainfo.dy
|
|
72
|
+
return
|
|
73
|
+
|
|
74
|
+
def setObservedProfile(self, xobs, yobs, dyobs=None):
|
|
75
|
+
"""Set the observed profile.
|
|
76
|
+
|
|
77
|
+
This is overloaded to change the value within the datainfo object.
|
|
78
|
+
|
|
79
|
+
Arguments
|
|
80
|
+
xobs -- Numpy array of the independent variable
|
|
81
|
+
yobs -- Numpy array of the observed signal.
|
|
82
|
+
dyobs -- Numpy array of the uncertainty in the observed signal. If
|
|
83
|
+
dyobs is None (default), it will be set to 1 at each
|
|
84
|
+
observed xobs.
|
|
85
|
+
|
|
86
|
+
Raises ValueError if len(yobs) != len(xobs)
|
|
87
|
+
Raises ValueError if dyobs != None and len(dyobs) != len(xobs)
|
|
88
|
+
"""
|
|
89
|
+
Profile.setObservedProfile(self, xobs, yobs, dyobs)
|
|
90
|
+
# Copy the arrays to the _datainfo attribute.
|
|
91
|
+
self._datainfo.x = self._xobs
|
|
92
|
+
self._datainfo.y = self._yobs
|
|
93
|
+
self._datainfo.dy = self._dyobs
|
|
94
|
+
return
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
##############################################################################
|
|
3
|
+
#
|
|
4
|
+
# diffpy.srfit by DANSE Diffraction group
|
|
5
|
+
# Simon J. L. Billinge
|
|
6
|
+
# (c) 2009 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
|
+
"""Modules and classes that adapt structure representations to the ParameterSet
|
|
16
|
+
interface and automatic structure constraint generation from space group
|
|
17
|
+
information."""
|
|
18
|
+
|
|
19
|
+
from diffpy.srfit.structure.sgconstraints import constrainAsSpaceGroup
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def struToParameterSet(name, stru):
|
|
23
|
+
"""Creates a ParameterSet from an structure.
|
|
24
|
+
|
|
25
|
+
This returns a ParameterSet adapted for the structure depending on its
|
|
26
|
+
type.
|
|
27
|
+
|
|
28
|
+
stru -- a structure object known by this module
|
|
29
|
+
name -- A name to give the structure.
|
|
30
|
+
|
|
31
|
+
Raises TypeError if stru cannot be adapted
|
|
32
|
+
"""
|
|
33
|
+
from diffpy.srfit.structure.diffpyparset import DiffpyStructureParSet
|
|
34
|
+
|
|
35
|
+
if DiffpyStructureParSet.canAdapt(stru):
|
|
36
|
+
return DiffpyStructureParSet(name, stru)
|
|
37
|
+
|
|
38
|
+
from diffpy.srfit.structure.objcrystparset import ObjCrystCrystalParSet
|
|
39
|
+
|
|
40
|
+
if ObjCrystCrystalParSet.canAdapt(stru):
|
|
41
|
+
return ObjCrystCrystalParSet(name, stru)
|
|
42
|
+
|
|
43
|
+
from diffpy.srfit.structure.objcrystparset import ObjCrystMoleculeParSet
|
|
44
|
+
|
|
45
|
+
if ObjCrystMoleculeParSet.canAdapt(stru):
|
|
46
|
+
return ObjCrystMoleculeParSet(name, stru)
|
|
47
|
+
|
|
48
|
+
from diffpy.srfit.structure.cctbxparset import CCTBXCrystalParSet
|
|
49
|
+
|
|
50
|
+
if CCTBXCrystalParSet.canAdapt(stru):
|
|
51
|
+
return CCTBXCrystalParSet(name, stru)
|
|
52
|
+
|
|
53
|
+
raise TypeError("Unadaptable structure format")
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
# silence pyflakes checker
|
|
57
|
+
assert constrainAsSpaceGroup
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
# End of file
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
##############################################################################
|
|
3
|
+
#
|
|
4
|
+
# diffpy.srfit by DANSE Diffraction group
|
|
5
|
+
# Simon J. L. Billinge
|
|
6
|
+
# (c) 2009 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
|
+
"""Base class for adapting structures to a ParameterSet interface.
|
|
16
|
+
|
|
17
|
+
The BaseStructureParSet is a ParameterSet with functionality required by
|
|
18
|
+
all structure adapters.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
__all__ = ["BaseStructureParSet"]
|
|
22
|
+
|
|
23
|
+
from diffpy.srfit.fitbase.parameterset import ParameterSet
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class BaseStructureParSet(ParameterSet):
|
|
27
|
+
"""Base class for structure adapters.
|
|
28
|
+
|
|
29
|
+
BaseStructureParSet derives from ParameterSet and provides methods that
|
|
30
|
+
help interface the ParameterSet with the space group constraint methods in
|
|
31
|
+
the sgconstraints module and to ProfileGenerators.
|
|
32
|
+
|
|
33
|
+
Attributes:
|
|
34
|
+
stru -- The adapted object
|
|
35
|
+
"""
|
|
36
|
+
|
|
37
|
+
@classmethod
|
|
38
|
+
def canAdapt(self, stru):
|
|
39
|
+
"""Return whether the structure can be adapted by this class."""
|
|
40
|
+
return False
|
|
41
|
+
|
|
42
|
+
def getLattice(self):
|
|
43
|
+
"""Get a ParameterSet containing the lattice Parameters.
|
|
44
|
+
|
|
45
|
+
The returned ParameterSet may contain other Parameters than the
|
|
46
|
+
lattice Parameters. It is assumed that the lattice parameters
|
|
47
|
+
are named "a", "b", "c", "alpha", "beta", "gamma".
|
|
48
|
+
|
|
49
|
+
Lattice must also have the "angunits" attribute, which is either
|
|
50
|
+
"deg" or "rad", to signify degrees or radians.
|
|
51
|
+
"""
|
|
52
|
+
raise NotImplementedError("The must be overloaded")
|
|
53
|
+
|
|
54
|
+
def getScatterers(self):
|
|
55
|
+
"""Get a list of ParameterSets that represents the scatterers.
|
|
56
|
+
|
|
57
|
+
The site positions must be accessible from the list entries via
|
|
58
|
+
the names "x", "y", and "z". The ADPs must be accessible as
|
|
59
|
+
well, but the name and nature of the ADPs (U-factors, B-factors,
|
|
60
|
+
isotropic, anisotropic) depends on the adapted structure.
|
|
61
|
+
"""
|
|
62
|
+
raise NotImplementedError("The must be overloaded")
|