diffpy.srfit 3.1.0rc0__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.0rc0.dist-info/METADATA +216 -0
- diffpy_srfit-3.1.0rc0.dist-info/RECORD +73 -0
- diffpy_srfit-3.1.0rc0.dist-info/WHEEL +5 -0
- diffpy_srfit-3.1.0rc0.dist-info/licenses/AUTHORS.rst +10 -0
- diffpy_srfit-3.1.0rc0.dist-info/licenses/LICENSE.rst +138 -0
- diffpy_srfit-3.1.0rc0.dist-info/licenses/LICENSE_DANSE.rst +34 -0
- diffpy_srfit-3.1.0rc0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,213 @@
|
|
|
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
|
+
"""The Equation class for holding and evaluating an equation.
|
|
16
|
+
|
|
17
|
+
Equation is a functor that holds a Literal tree that defines an
|
|
18
|
+
equation. It's __call__ method evaluates the equation at the most recent
|
|
19
|
+
value of its Arguments. The non-constant arguments are accessible as
|
|
20
|
+
attributes of the Equation instance and can be passed as arguments to
|
|
21
|
+
__call__.
|
|
22
|
+
|
|
23
|
+
Example > # make a Literal tree. Here's a simple one > add =
|
|
24
|
+
AdditionOperator() > a = Argument(name="a") # Don't forget to name
|
|
25
|
+
these! > b = Argument(name="b") > add.addLiteral(a) > add.addLiteral(b)
|
|
26
|
+
> # make an Equation instance and pass the root > eq = Equation(root =
|
|
27
|
+
add) > eq(a=3, b=4) # returns 7 > eq(a=2) # remembers b=4, returns 6 >
|
|
28
|
+
eq.a.setValue(-3) > eq.b.setValue(3) > eq() # uses last assignment of a
|
|
29
|
+
and b, returns 0
|
|
30
|
+
|
|
31
|
+
See the class documentation for more information.
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
__all__ = ["Equation"]
|
|
35
|
+
|
|
36
|
+
from collections import OrderedDict
|
|
37
|
+
|
|
38
|
+
from diffpy.srfit.equation.literals.literal import Literal
|
|
39
|
+
from diffpy.srfit.equation.literals.operators import Operator
|
|
40
|
+
from diffpy.srfit.equation.visitors import getArgs, swap, validate
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class Equation(Operator):
|
|
44
|
+
"""Class for holding and evaluating a Literal tree.
|
|
45
|
+
|
|
46
|
+
Instances have attributes that are the non-const Arguments of the tree
|
|
47
|
+
(accessed by name) and a __call__ method that evaluates the tree. It is
|
|
48
|
+
assumed, but not enforced that Arguments have unique names. If this is not
|
|
49
|
+
the case, then one should keep its own list of Arguments.
|
|
50
|
+
|
|
51
|
+
The tree is scanned for errors when it is added. Thus, the tree should be
|
|
52
|
+
complete before putting it inside an Equation.
|
|
53
|
+
|
|
54
|
+
Equations can act as Operator nodes within a literal tree. In this context,
|
|
55
|
+
they evaluate as the root node, but provide a calling interface that
|
|
56
|
+
accepts new argument values for the literal tree.
|
|
57
|
+
|
|
58
|
+
Attributes
|
|
59
|
+
root -- The root Literal of the equation tree
|
|
60
|
+
argdict -- An OrderedDict of Arguments from the root.
|
|
61
|
+
args -- Property that gets the values of argdict.
|
|
62
|
+
|
|
63
|
+
Operator Attributes
|
|
64
|
+
args -- List of Literal arguments, set with 'addLiteral'
|
|
65
|
+
name -- A name for this operator. e.g. "add" or "sin"
|
|
66
|
+
nin -- Number of inputs (<1 means this is variable)
|
|
67
|
+
nout -- Number of outputs
|
|
68
|
+
operation -- Function that performs the operation. e.g. numpy.add.
|
|
69
|
+
symbol -- The symbolic representation. e.g. "+" or "sin".
|
|
70
|
+
_value -- The value of the Operator.
|
|
71
|
+
value -- Property for 'getValue'.
|
|
72
|
+
"""
|
|
73
|
+
|
|
74
|
+
# define abstract attributes from the Operator base.
|
|
75
|
+
nin = None
|
|
76
|
+
nout = 1
|
|
77
|
+
|
|
78
|
+
def __init__(self, name=None, root=None):
|
|
79
|
+
"""Initialize.
|
|
80
|
+
|
|
81
|
+
name -- A name for this Equation.
|
|
82
|
+
root -- The root node of the Literal tree (default None). If root
|
|
83
|
+
is not passed here, you must call the 'setRoot' method to
|
|
84
|
+
set or change the root node.
|
|
85
|
+
"""
|
|
86
|
+
# Operator stuff. We circumvent Operator.__init__ since we're using
|
|
87
|
+
# args as a property. We cannot set it, as the Operator tries to do.
|
|
88
|
+
if name is None and root is not None:
|
|
89
|
+
name = "eq_%s" % root.name
|
|
90
|
+
Literal.__init__(self, name)
|
|
91
|
+
self.root = None
|
|
92
|
+
self.argdict = OrderedDict()
|
|
93
|
+
if root is not None:
|
|
94
|
+
self.setRoot(root)
|
|
95
|
+
return
|
|
96
|
+
|
|
97
|
+
@property
|
|
98
|
+
def symbol(self):
|
|
99
|
+
return self.name
|
|
100
|
+
|
|
101
|
+
def operation(self, *args, **kw):
|
|
102
|
+
"""Evaluate this Equation object.
|
|
103
|
+
|
|
104
|
+
Same as the __call__ method. This method is used via the
|
|
105
|
+
Operator interface.
|
|
106
|
+
|
|
107
|
+
Return the result of __call__(*args, **kw).
|
|
108
|
+
"""
|
|
109
|
+
return self.__call__(*args, **kw)
|
|
110
|
+
|
|
111
|
+
def _getArgs(self):
|
|
112
|
+
return list(self.argdict.values())
|
|
113
|
+
|
|
114
|
+
args = property(_getArgs)
|
|
115
|
+
|
|
116
|
+
def __getattr__(self, name):
|
|
117
|
+
"""Gives access to the Arguments as attributes."""
|
|
118
|
+
# Avoid infinite loop on argdict lookup.
|
|
119
|
+
argdict = object.__getattribute__(self, "argdict")
|
|
120
|
+
if name not in argdict:
|
|
121
|
+
raise AttributeError("No argument named '%s' here" % name)
|
|
122
|
+
return argdict[name]
|
|
123
|
+
|
|
124
|
+
# Ensure there is no __dir__ override in the base class.
|
|
125
|
+
assert getattr(Operator, "__dir__", None) is getattr(
|
|
126
|
+
object, "__dir__", None
|
|
127
|
+
)
|
|
128
|
+
|
|
129
|
+
def __dir__(self):
|
|
130
|
+
"Return sorted list of attributes for this object."
|
|
131
|
+
rv = set(dir(type(self)))
|
|
132
|
+
rv.update(self.__dict__, self.argdict)
|
|
133
|
+
rv = sorted(rv)
|
|
134
|
+
return rv
|
|
135
|
+
|
|
136
|
+
def setRoot(self, root):
|
|
137
|
+
"""Set the root of the Literal tree.
|
|
138
|
+
|
|
139
|
+
Raises:
|
|
140
|
+
ValueError if errors are found in the Literal tree.
|
|
141
|
+
"""
|
|
142
|
+
|
|
143
|
+
# Validate the new root
|
|
144
|
+
validate(root)
|
|
145
|
+
|
|
146
|
+
# Stop observing the old root
|
|
147
|
+
if self.root is not None:
|
|
148
|
+
self.root.removeObserver(self._flush)
|
|
149
|
+
|
|
150
|
+
# Add the new root
|
|
151
|
+
self.root = root
|
|
152
|
+
self.root.addObserver(self._flush)
|
|
153
|
+
self._flush(other=(self,))
|
|
154
|
+
|
|
155
|
+
# Get the args
|
|
156
|
+
args = getArgs(root, getconsts=False)
|
|
157
|
+
self.argdict = OrderedDict([(arg.name, arg) for arg in args])
|
|
158
|
+
|
|
159
|
+
# Set Operator attributes
|
|
160
|
+
self.nin = len(self.args)
|
|
161
|
+
|
|
162
|
+
return
|
|
163
|
+
|
|
164
|
+
def __call__(self, *args, **kw):
|
|
165
|
+
"""Call the equation.
|
|
166
|
+
|
|
167
|
+
New Argument values are accepted as arguments or keyword
|
|
168
|
+
assignments (or both). The order of accepted arguments is given
|
|
169
|
+
by the args attribute. The Equation will remember values set in
|
|
170
|
+
this way.
|
|
171
|
+
|
|
172
|
+
Raises ValueError when a passed argument cannot be found
|
|
173
|
+
"""
|
|
174
|
+
# Process args
|
|
175
|
+
for idx, val in enumerate(args):
|
|
176
|
+
if idx >= len(self.argdict):
|
|
177
|
+
raise ValueError("Too many arguments")
|
|
178
|
+
arg = self.args[idx]
|
|
179
|
+
arg.setValue(val)
|
|
180
|
+
|
|
181
|
+
# Process kw
|
|
182
|
+
for name, val in kw.items():
|
|
183
|
+
arg = self.argdict.get(name)
|
|
184
|
+
if arg is None:
|
|
185
|
+
raise ValueError("No argument named '%s' here" % name)
|
|
186
|
+
arg.setValue(val)
|
|
187
|
+
|
|
188
|
+
self._value = self.root.getValue()
|
|
189
|
+
return self._value
|
|
190
|
+
|
|
191
|
+
def swap(self, oldlit, newlit):
|
|
192
|
+
"""Swap a literal in the equation for another.
|
|
193
|
+
|
|
194
|
+
Note that this may change the root and the operation interface
|
|
195
|
+
"""
|
|
196
|
+
newroot = swap(self.root, oldlit, newlit)
|
|
197
|
+
self.setRoot(newroot)
|
|
198
|
+
return
|
|
199
|
+
|
|
200
|
+
# Operator methods
|
|
201
|
+
|
|
202
|
+
def addLiteral(self, literal):
|
|
203
|
+
"""Cannot add a literal to an Equation."""
|
|
204
|
+
raise RuntimeError("Cannot add literals to an Equation.")
|
|
205
|
+
|
|
206
|
+
# Visitors can treat us differently than an Operator.
|
|
207
|
+
|
|
208
|
+
def identify(self, visitor):
|
|
209
|
+
"""Identify self to a visitor."""
|
|
210
|
+
return visitor.onEquation(self)
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
# End of file
|
|
@@ -0,0 +1,71 @@
|
|
|
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
|
+
"""Building blocks for defining a lazy evaluation network.
|
|
16
|
+
|
|
17
|
+
Literals are the building blocks of the evaluation network. An Argument
|
|
18
|
+
holds the name and value of an equation variable. Operators are used to
|
|
19
|
+
compose other Literals to produce a new value.
|
|
20
|
+
|
|
21
|
+
Literal networks can be evaluated or have other actions performed on
|
|
22
|
+
them by Visitors (in diffpy.srfit.equation.visitors). The Literal-
|
|
23
|
+
Visitor relationship is that described by the Visitor pattern (
|
|
24
|
+
|
|
25
|
+
http://en.wikipedia.org/wiki/Visitor_pattern).
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
__all__ = [
|
|
29
|
+
"Argument",
|
|
30
|
+
"Operator",
|
|
31
|
+
"BinaryOperator",
|
|
32
|
+
"CustomOperator",
|
|
33
|
+
"AdditionOperator",
|
|
34
|
+
"SubtractionOperator",
|
|
35
|
+
"MultiplicationOperator",
|
|
36
|
+
"DivisionOperator",
|
|
37
|
+
"ExponentiationOperator",
|
|
38
|
+
"RemainderOperator",
|
|
39
|
+
"NegationOperator",
|
|
40
|
+
"ConvolutionOperator",
|
|
41
|
+
"SumOperator",
|
|
42
|
+
"UFuncOperator",
|
|
43
|
+
"ArrayOperator",
|
|
44
|
+
"PolyvalOperator",
|
|
45
|
+
"makeOperator",
|
|
46
|
+
]
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
# Import the operators
|
|
50
|
+
|
|
51
|
+
from diffpy.srfit.equation.literals.argument import Argument
|
|
52
|
+
from diffpy.srfit.equation.literals.operators import (
|
|
53
|
+
AdditionOperator,
|
|
54
|
+
ArrayOperator,
|
|
55
|
+
BinaryOperator,
|
|
56
|
+
ConvolutionOperator,
|
|
57
|
+
CustomOperator,
|
|
58
|
+
DivisionOperator,
|
|
59
|
+
ExponentiationOperator,
|
|
60
|
+
MultiplicationOperator,
|
|
61
|
+
NegationOperator,
|
|
62
|
+
Operator,
|
|
63
|
+
PolyvalOperator,
|
|
64
|
+
RemainderOperator,
|
|
65
|
+
SubtractionOperator,
|
|
66
|
+
SumOperator,
|
|
67
|
+
UFuncOperator,
|
|
68
|
+
makeOperator,
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
# End of file
|
|
@@ -0,0 +1,81 @@
|
|
|
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
|
+
"""Abstract Base Classes for Literals."""
|
|
16
|
+
|
|
17
|
+
__all__ = ["LiteralABC", "ArgumentABC", "OperatorABC"]
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
from abc import ABCMeta, abstractmethod, abstractproperty
|
|
21
|
+
|
|
22
|
+
import six
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
@six.add_metaclass(ABCMeta)
|
|
26
|
+
class LiteralABC(object):
|
|
27
|
+
"""Abstract Base Class for Literal.
|
|
28
|
+
|
|
29
|
+
See Literal for usage.
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
@abstractmethod
|
|
33
|
+
def identify(self, visitor):
|
|
34
|
+
pass
|
|
35
|
+
|
|
36
|
+
@abstractmethod
|
|
37
|
+
def getValue(self):
|
|
38
|
+
pass
|
|
39
|
+
|
|
40
|
+
name = abstractproperty(None, None)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
# End class LiteralABC
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class ArgumentABC(LiteralABC):
|
|
47
|
+
"""Abstract Base Class for Argument.
|
|
48
|
+
|
|
49
|
+
See Argument for usage.
|
|
50
|
+
"""
|
|
51
|
+
|
|
52
|
+
@abstractmethod
|
|
53
|
+
def setValue(self, value):
|
|
54
|
+
pass
|
|
55
|
+
|
|
56
|
+
const = abstractproperty(None, None)
|
|
57
|
+
value = abstractproperty(None, None)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
# End class ArgumentABC
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
class OperatorABC(LiteralABC):
|
|
64
|
+
"""Abstract Base Class for Operator.
|
|
65
|
+
|
|
66
|
+
See Operator for usage.
|
|
67
|
+
"""
|
|
68
|
+
|
|
69
|
+
@abstractmethod
|
|
70
|
+
def addLiteral(self, literal):
|
|
71
|
+
pass
|
|
72
|
+
|
|
73
|
+
args = abstractproperty(None, None)
|
|
74
|
+
nin = abstractproperty(None, None)
|
|
75
|
+
nout = abstractproperty(None, None)
|
|
76
|
+
operation = abstractproperty(None, None)
|
|
77
|
+
symbol = abstractproperty(None, None)
|
|
78
|
+
value = abstractproperty(None, None)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
# End class OperatorABC
|
|
@@ -0,0 +1,76 @@
|
|
|
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
|
+
"""Argument class.
|
|
16
|
+
|
|
17
|
+
Arguments are the leaves of an equation tree, in essence a variable or a
|
|
18
|
+
constant.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
__all__ = ["Argument"]
|
|
22
|
+
|
|
23
|
+
from numpy import array_equal, ndarray
|
|
24
|
+
|
|
25
|
+
from diffpy.srfit.equation.literals.abcs import ArgumentABC
|
|
26
|
+
from diffpy.srfit.equation.literals.literal import Literal
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class Argument(Literal, ArgumentABC):
|
|
30
|
+
"""Argument class.
|
|
31
|
+
|
|
32
|
+
Attributes
|
|
33
|
+
name -- A name for this Argument.
|
|
34
|
+
const -- A flag indicating whether this is considered a constant.
|
|
35
|
+
Constants may be given special treatment by the Visitors.
|
|
36
|
+
_value -- The value of the Argument. Modified with 'setValue'.
|
|
37
|
+
value -- Property for 'getValue' and 'setValue'.
|
|
38
|
+
"""
|
|
39
|
+
|
|
40
|
+
const = None
|
|
41
|
+
|
|
42
|
+
def __init__(self, name=None, value=None, const=False):
|
|
43
|
+
"""Initialization."""
|
|
44
|
+
Literal.__init__(self, name)
|
|
45
|
+
self.const = const
|
|
46
|
+
self.value = value
|
|
47
|
+
return
|
|
48
|
+
|
|
49
|
+
def identify(self, visitor):
|
|
50
|
+
"""Identify self to a visitor."""
|
|
51
|
+
return visitor.onArgument(self)
|
|
52
|
+
|
|
53
|
+
def getValue(self):
|
|
54
|
+
"""Get the value of this Literal."""
|
|
55
|
+
return self._value
|
|
56
|
+
|
|
57
|
+
def setValue(self, val):
|
|
58
|
+
"""Set the value of the Literal.
|
|
59
|
+
|
|
60
|
+
val -- The value to assign
|
|
61
|
+
"""
|
|
62
|
+
if isinstance(self._value, ndarray) or isinstance(val, ndarray):
|
|
63
|
+
notequiv = not array_equal(self._value, val)
|
|
64
|
+
else:
|
|
65
|
+
notequiv = self._value != val
|
|
66
|
+
if notequiv:
|
|
67
|
+
self._value = val
|
|
68
|
+
self.notify()
|
|
69
|
+
return
|
|
70
|
+
|
|
71
|
+
value = property(
|
|
72
|
+
lambda self: self.getValue(), lambda self, val: self.setValue(val)
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
# End of file
|
|
@@ -0,0 +1,69 @@
|
|
|
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
|
+
"""Literal base class used to construct equation trees.
|
|
16
|
+
|
|
17
|
+
Literals are base pieces of the equation hierarchy. The 'identify'
|
|
18
|
+
method identifies the Literal to a visitor by calling the identifying
|
|
19
|
+
method of the vistior.
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
__all__ = ["Literal"]
|
|
23
|
+
|
|
24
|
+
from diffpy.srfit.equation.literals.abcs import LiteralABC
|
|
25
|
+
from diffpy.srfit.util.observable import Observable
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class Literal(Observable, LiteralABC):
|
|
29
|
+
"""Abstract class for equation pieces, such as operators and arguments.
|
|
30
|
+
|
|
31
|
+
Literal derives from Observable. See diffpy.srfit.util.observable.
|
|
32
|
+
|
|
33
|
+
Attributes
|
|
34
|
+
name -- A name for this Literal (default None).
|
|
35
|
+
_value -- The value of the Literal.
|
|
36
|
+
"""
|
|
37
|
+
|
|
38
|
+
name = None
|
|
39
|
+
_value = None
|
|
40
|
+
|
|
41
|
+
def __init__(self, name=None):
|
|
42
|
+
"""Initialization."""
|
|
43
|
+
Observable.__init__(self)
|
|
44
|
+
if name is not None:
|
|
45
|
+
self.name = name
|
|
46
|
+
return
|
|
47
|
+
|
|
48
|
+
def getValue(self):
|
|
49
|
+
"""Get the value of the Literal."""
|
|
50
|
+
raise NotImplementedError("Define in derived class")
|
|
51
|
+
|
|
52
|
+
def identify(self, visitor):
|
|
53
|
+
"""Identify self to a visitor."""
|
|
54
|
+
m = "'%s' must override 'identify'" % self.__class__.__name__
|
|
55
|
+
raise NotImplementedError(m)
|
|
56
|
+
|
|
57
|
+
def _flush(self, other):
|
|
58
|
+
"""Invalidate my state and notify observers."""
|
|
59
|
+
if self._value is None:
|
|
60
|
+
return
|
|
61
|
+
self._value = None
|
|
62
|
+
self.notify(other)
|
|
63
|
+
return
|
|
64
|
+
|
|
65
|
+
def __str__(self):
|
|
66
|
+
return "%s(%s)" % (self.__class__.__name__, self.name)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
# End of file
|