diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 283499b1..879e7c53 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -9,7 +9,7 @@ Release notes Version 3.0.0 – 2019-03-14 -========================== +-------------------------- **Added:** diff --git a/docs/source/api/.placeholder b/docs/source/api/.placeholder deleted file mode 100644 index e69de29b..00000000 diff --git a/docs/source/api/diffpy.srfit.example_package.rst b/docs/source/api/diffpy.srfit.example_package.rst deleted file mode 100644 index 60910070..00000000 --- a/docs/source/api/diffpy.srfit.example_package.rst +++ /dev/null @@ -1,31 +0,0 @@ -.. _example_package documentation: - -|title| -======= - -.. |title| replace:: diffpy.srfit.example_package package - -.. automodule:: diffpy.srfit.example_package - :members: - :undoc-members: - :show-inheritance: - -|foo| ------ - -.. |foo| replace:: diffpy.srfit.example_package.foo module - -.. automodule:: diffpy.srfit.example_package.foo - :members: - :undoc-members: - :show-inheritance: - -|bar| ------ - -.. |bar| replace:: diffpy.srfit.example_package.bar module - -.. automodule:: diffpy.srfit.example_package.foo - :members: - :undoc-members: - :show-inheritance: diff --git a/docs/source/api/diffpy.srfit.rst b/docs/source/api/diffpy.srfit.rst index 5b2b697b..ebff42c6 100644 --- a/docs/source/api/diffpy.srfit.rst +++ b/docs/source/api/diffpy.srfit.rst @@ -14,17 +14,12 @@ Subpackages ----------- .. toctree:: - diffpy.srfit.example_package - -Submodules ----------- - -|module| --------- - -.. |module| replace:: diffpy.srfit.example_submodule module - -.. automodule:: diffpy.srfit.example_submodule - :members: - :undoc-members: - :show-inheritance: + diffpy.srfit.equation + diffpy.srfit.equation.literals + diffpy.srfit.equation.visitors + diffpy.srfit.fitbase + diffpy.srfit.interface + diffpy.srfit.pdf + diffpy.srfit.sas + diffpy.srfit.structure + diffpy.srfit.util diff --git a/docs/source/conf.py b/docs/source/conf.py index 453d9b6a..48865a9b 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -52,7 +52,7 @@ "sphinx.ext.intersphinx", "sphinx_rtd_theme", "sphinx_copybutton", - "m2r", + "m2r2", ] # Add any paths that contain templates here, relative to this directory. diff --git a/docs/source/examples/coreshellnp.rst b/docs/source/examples/coreshellnp.rst index d8a84e0f..334234cc 100644 --- a/docs/source/examples/coreshellnp.rst +++ b/docs/source/examples/coreshellnp.rst @@ -4,4 +4,4 @@ coreshellnp.py ======================== -.. literalinclude:: ../../../examples/coreshellnp.py +.. literalinclude:: ../../examples/coreshellnp.py diff --git a/docs/source/examples/crystalpdf.rst b/docs/source/examples/crystalpdf.rst index 51ef5185..36cfb8f6 100644 --- a/docs/source/examples/crystalpdf.rst +++ b/docs/source/examples/crystalpdf.rst @@ -4,4 +4,4 @@ crystalpdf.py ======================== -.. literalinclude:: ../../../examples/crystalpdf.py +.. literalinclude:: ../../examples/crystalpdf.py diff --git a/docs/source/examples/crystalpdfall.rst b/docs/source/examples/crystalpdfall.rst index b2f74fb8..68a5584a 100644 --- a/docs/source/examples/crystalpdfall.rst +++ b/docs/source/examples/crystalpdfall.rst @@ -4,4 +4,4 @@ crystalpdfall.py ======================== -.. literalinclude:: ../../../examples/crystalpdfall.py +.. literalinclude:: ../../examples/crystalpdfall.py diff --git a/docs/source/examples/crystalpdfobjcryst.rst b/docs/source/examples/crystalpdfobjcryst.rst index 4542b65a..6badf9f4 100644 --- a/docs/source/examples/crystalpdfobjcryst.rst +++ b/docs/source/examples/crystalpdfobjcryst.rst @@ -4,4 +4,4 @@ crystalpdfobjcryst.py ======================== -.. literalinclude:: ../../../examples/crystalpdfobjcryst.py +.. literalinclude:: ../../examples/crystalpdfobjcryst.py diff --git a/docs/source/examples/crystalpdftwodata.rst b/docs/source/examples/crystalpdftwodata.rst index 9b42e45f..a2e76eb0 100644 --- a/docs/source/examples/crystalpdftwodata.rst +++ b/docs/source/examples/crystalpdftwodata.rst @@ -4,4 +4,4 @@ crystalpdftwodata.py ======================== -.. literalinclude:: ../../../examples/crystalpdftwodata.py +.. literalinclude:: ../../examples/crystalpdftwodata.py diff --git a/docs/source/examples/crystalpdftwophase.rst b/docs/source/examples/crystalpdftwophase.rst index eb2cf18b..50a5eb21 100644 --- a/docs/source/examples/crystalpdftwophase.rst +++ b/docs/source/examples/crystalpdftwophase.rst @@ -4,4 +4,4 @@ crystalpdftwophase.py ======================== -.. literalinclude:: ../../../examples/crystalpdftwophase.py +.. literalinclude:: ../../examples/crystalpdftwophase.py diff --git a/docs/source/examples/debyemodel.rst b/docs/source/examples/debyemodel.rst index 436d20ca..1f85ea6d 100644 --- a/docs/source/examples/debyemodel.rst +++ b/docs/source/examples/debyemodel.rst @@ -4,4 +4,4 @@ debyemodel.py ======================== -.. literalinclude:: ../../../examples/debyemodel.py +.. literalinclude:: ../../examples/debyemodel.py diff --git a/docs/source/examples/debyemodelII.rst b/docs/source/examples/debyemodelII.rst index d44cc60d..3345c4a0 100644 --- a/docs/source/examples/debyemodelII.rst +++ b/docs/source/examples/debyemodelII.rst @@ -4,4 +4,4 @@ debyemodelII.py ======================== -.. literalinclude:: ../../../examples/debyemodelII.py +.. literalinclude:: ../../examples/debyemodelII.py diff --git a/docs/source/examples/ellipsoidsas.rst b/docs/source/examples/ellipsoidsas.rst index 132b2ee7..e885f1ef 100644 --- a/docs/source/examples/ellipsoidsas.rst +++ b/docs/source/examples/ellipsoidsas.rst @@ -4,4 +4,4 @@ ellipsoidsas.py ======================== -.. literalinclude:: ../../../examples/ellipsoidsas.py +.. literalinclude:: ../../examples/ellipsoidsas.py diff --git a/docs/source/examples/gaussiangenerator.rst b/docs/source/examples/gaussiangenerator.rst index eb101bb9..dc459834 100644 --- a/docs/source/examples/gaussiangenerator.rst +++ b/docs/source/examples/gaussiangenerator.rst @@ -4,4 +4,4 @@ gaussiangenerator.py ======================== -.. literalinclude:: ../../../examples/gaussiangenerator.py +.. literalinclude:: ../../examples/gaussiangenerator.py diff --git a/docs/source/examples/gaussianrecipe.rst b/docs/source/examples/gaussianrecipe.rst index 73f94eac..7b0eaa1a 100644 --- a/docs/source/examples/gaussianrecipe.rst +++ b/docs/source/examples/gaussianrecipe.rst @@ -4,4 +4,4 @@ gaussianrecipe.py ======================== -.. literalinclude:: ../../../examples/gaussianrecipe.py +.. literalinclude:: ../../examples/gaussianrecipe.py diff --git a/docs/source/examples/interface.rst b/docs/source/examples/interface.rst index 41e706a8..c43db23a 100644 --- a/docs/source/examples/interface.rst +++ b/docs/source/examples/interface.rst @@ -4,4 +4,4 @@ interface.py ======================== -.. literalinclude:: ../../../examples/interface.py +.. literalinclude:: ../../examples/interface.py diff --git a/docs/source/examples/npintensity.rst b/docs/source/examples/npintensity.rst index be8705eb..ce9ca226 100644 --- a/docs/source/examples/npintensity.rst +++ b/docs/source/examples/npintensity.rst @@ -4,4 +4,4 @@ npintensity.py ======================== -.. literalinclude:: ../../../examples/npintensity.py +.. literalinclude:: ../../examples/npintensity.py diff --git a/docs/source/examples/npintensityII.rst b/docs/source/examples/npintensityII.rst index 0fb043ea..56750adc 100644 --- a/docs/source/examples/npintensityII.rst +++ b/docs/source/examples/npintensityII.rst @@ -4,4 +4,4 @@ npintensityII.py ======================== -.. literalinclude:: ../../../examples/npintensityII.py +.. literalinclude:: ../../examples/npintensityII.py diff --git a/docs/source/examples/nppdfcrystal.rst b/docs/source/examples/nppdfcrystal.rst index 38bd3523..44640074 100644 --- a/docs/source/examples/nppdfcrystal.rst +++ b/docs/source/examples/nppdfcrystal.rst @@ -4,4 +4,4 @@ nppdfcrystal.py ======================== -.. literalinclude:: ../../../examples/nppdfcrystal.py +.. literalinclude:: ../../examples/nppdfcrystal.py diff --git a/docs/source/examples/nppdfobjcryst.rst b/docs/source/examples/nppdfobjcryst.rst index c5ba169e..977b156c 100644 --- a/docs/source/examples/nppdfobjcryst.rst +++ b/docs/source/examples/nppdfobjcryst.rst @@ -4,4 +4,4 @@ nppdfobjcryst.py ======================== -.. literalinclude:: ../../../examples/nppdfobjcryst.py +.. literalinclude:: ../../examples/nppdfobjcryst.py diff --git a/docs/source/examples/nppdfsas.rst b/docs/source/examples/nppdfsas.rst index 26852a89..48564ed3 100644 --- a/docs/source/examples/nppdfsas.rst +++ b/docs/source/examples/nppdfsas.rst @@ -4,4 +4,4 @@ nppdfsas.py ======================== -.. literalinclude:: ../../../examples/nppdfsas.py +.. literalinclude:: ../../examples/nppdfsas.py diff --git a/docs/source/examples/simplepdf.rst b/docs/source/examples/simplepdf.rst index a926db37..6b959a5c 100644 --- a/docs/source/examples/simplepdf.rst +++ b/docs/source/examples/simplepdf.rst @@ -4,4 +4,4 @@ simplepdf.py ======================== -.. literalinclude:: ../../../examples/simplepdf.py +.. literalinclude:: ../../examples/simplepdf.py diff --git a/docs/source/examples/simplepdftwophase.rst b/docs/source/examples/simplepdftwophase.rst index 8e61dec2..acde5190 100644 --- a/docs/source/examples/simplepdftwophase.rst +++ b/docs/source/examples/simplepdftwophase.rst @@ -4,4 +4,4 @@ simplepdftwophase.py ======================== -.. literalinclude:: ../../../examples/simplepdftwophase.py +.. literalinclude:: ../../examples/simplepdftwophase.py diff --git a/docs/source/examples/simplerecipe.rst b/docs/source/examples/simplerecipe.rst index 046b09cd..e79a2e09 100644 --- a/docs/source/examples/simplerecipe.rst +++ b/docs/source/examples/simplerecipe.rst @@ -4,4 +4,4 @@ simplerecipe.py ======================== -.. literalinclude:: ../../../examples/simplerecipe.py +.. literalinclude:: ../../examples/simplerecipe.py diff --git a/docs/source/extending.rst b/docs/source/extending.rst index 5aa596eb..464cd16c 100644 --- a/docs/source/extending.rst +++ b/docs/source/extending.rst @@ -180,7 +180,7 @@ external program before or after interfacing with SrFit. An example of a customized Profile is the ``SASProfile`` class in the ``diffpy.srfit.sas.sasprofile`` module: -.. literalinclude:: ../../../src/diffpy/srfit/sas/sasprofile.py +.. literalinclude:: ../../src/diffpy/srfit/sas/sasprofile.py :pyobject: SASProfile The ``__init__`` method sets the ``xobs``, ``yobs`` and ``dyobs`` attributes of @@ -218,7 +218,7 @@ to keep the restraint cost comparable to the residual of a single data point. ``Restraint`` whose penalty is the root-mean-square deviation from the expected and calculated BVS of a structure. -.. literalinclude:: ../../../src/diffpy/srfit/structure/bvsrestraint.py +.. literalinclude:: ../../src/diffpy/srfit/structure/bvsrestraint.py :pyobject: BVSRestraint Note that the penalty scaling is optional (selected by the `scaled` flag) and @@ -230,7 +230,7 @@ restrainable object. A ``BVSRestraint`` is used to restrain a ``SrRealParSet``, which is a ``ParameterSet`` wrapper base class for SrReal-compatible structures. The restraint is applied with the ``restrainBVS`` method. -.. literalinclude:: ../../../src/diffpy/srfit/structure/srrealparset.py +.. literalinclude:: ../../src/diffpy/srfit/structure/srrealparset.py :pyobject: SrRealParSet.restrainBVS The purpose of the method is to create the custom ``Restraint`` object, diff --git a/docs/source/release.rst b/docs/source/release.rst index 7ec4f81d..27cd0cc9 100644 --- a/docs/source/release.rst +++ b/docs/source/release.rst @@ -1,3 +1,5 @@ +:tocdepth: -1 + .. index:: release notes -.. mdinclude:: ../../../CHANGELOG.md +.. include:: ../../CHANGELOG.rst diff --git a/news/fix-docstring.rst b/news/fix-docstring.rst new file mode 100644 index 00000000..a59b442a --- /dev/null +++ b/news/fix-docstring.rst @@ -0,0 +1,23 @@ +**Added:** + +* No news added: Fix the docstring in this repo + +**Changed:** + +* + +**Deprecated:** + +* + +**Removed:** + +* + +**Fixed:** + +* + +**Security:** + +* diff --git a/src/diffpy/srfit/equation/builder.py b/src/diffpy/srfit/equation/builder.py index dcd58ca2..cca64f6b 100644 --- a/src/diffpy/srfit/equation/builder.py +++ b/src/diffpy/srfit/equation/builder.py @@ -109,12 +109,17 @@ class EquationFactory(object): """A Factory for equations. - builders -- A dictionary of BaseBuilders registered with the - factory, indexed by name. - newargs -- A set of new arguments created by makeEquation. This is - redefined whenever makeEquation is called. - equations -- Set of equations that have been built by the - EquationFactory. + Attributes + ---------- + builders + A dictionary of BaseBuilders registered with the + factory, indexed by name. + newargs + A set of new arguments created by makeEquation. This is + redefined whenever makeEquation is called. + equations + Set of equations that have been built by the + EquationFactory. """ symbols = ("+", "-", "*", "/", "**", "%", "|") @@ -137,21 +142,26 @@ def makeEquation( ): """Make an equation from an equation string. - Arguments - eqstr -- An equation in string form using standard python - syntax. The equation string can use any function - registered literal or function, including numpy ufuncs - that are automatically registered. - buildargs -- A flag indicating whether missing arguments can be - created by the Factory (default True). If False, then - the a ValueError will be raised if there are undefined - arguments in the eqstr. Built arguments will be of type - argclass. - argclass -- Class to use when creating new Arguments (default - diffpy.srfit.equation.literals.Argument). The class - constructor must accept the 'name' key word. - argkw -- Key word dictionary to pass to the argclass constructor - (default {}). + Parameters + ---------- + eqstr + An equation in string form using standard python + syntax. The equation string can use any function + registered literal or function, including numpy ufuncs + that are automatically registered. + buildargs + A flag indicating whether missing arguments can be + created by the Factory (default True). If False, then + the a ValueError will be raised if there are undefined + arguments in the eqstr. Built arguments will be of type + argclass. + argclass + Class to use when creating new Arguments (default + diffpy.srfit.equation.literals.Argument). The class + constructor must accept the 'name' key word. + argkw + Key word dictionary to pass to the argclass constructor + (default {}). Returns a callable Literal representing the equation string. """ @@ -202,11 +212,16 @@ def registerFunction(self, name, func, argnames): This will register a builder for the function. - name -- The name of the function - func -- A callable python object - argnames-- The argument names for func. If these names do not - correspond to builders, then new constants with value 0 - will be created for each name. + Attributes + ---------- + name + The name of the function + func + A callable python object + argnames + The argument names for func. If these names do not + correspond to builders, then new constants with value 0 + will be created for each name. Returns the registered builder. """ @@ -293,17 +308,22 @@ def _prepareBuilders(self, eqstr, buildargs, argclass, argkw): arguments, and creates new arguments if allowed. In the process it rebuilds the newargs attribute. - Arguments - eqstr -- An equation in string as specified in the makeEquation - method. - buildargs -- A flag indicating whether missing arguments can be - created by the factory. If False, then the a ValueError - will be raised if there are undefined arguments in the - eqstr. - argclass -- Class to use when creating new Arguments. The class - constructor must accept the 'name' key word. - argkw -- Key word dictionary to pass to the argclass - constructor. + Parameters + ---------- + eqstr + An equation in string as specified in the makeEquation + method. + buildargs + A flag indicating whether missing arguments can be + created by the factory. If False, then the a ValueError + will be raised if there are undefined arguments in the + eqstr. + argclass + Class to use when creating new Arguments. The class + constructor must accept the 'name' key word. + argkw + Key word dictionary to pass to the argclass + constructor. Raises ValueError if new arguments must be created, but this is disallowed due to the buildargs flag. @@ -392,7 +412,9 @@ class BaseBuilder(object): arguments can be other BaseBuilder instances or constants. Attributes - literal -- The equation Literal being built by this instance. + ---------- + literal + The equation Literal being built by this instance. """ def __init__(self): @@ -424,8 +446,11 @@ def __evalBinary(self, other, OperatorClass, onleft=True): Other can be an BaseBuilder or a constant. - onleft -- Indicates that the operator was passed on the left side - (default True). + Attributes + ---------- + onleft + Indicates that the operator was passed on the left side + (default True). """ # Create the Operator op = OperatorClass() @@ -520,20 +545,27 @@ class ArgumentBuilder(BaseBuilder): arguments can be other BaseBuilder instances or constants. Attributes - literal -- The Argument wrapped by this instance. + ---------- + literal + The Argument wrapped by this instance. """ def __init__(self, value=None, name=None, const=False, arg=None): """Create an ArgumentBuilder instance, containing a new Argument. - Arguments - value -- The value of the wrapped Argument (float, default None) - name -- The name of the wrapped Argument (string, default None) - const -- Flag indicating whether the Argument is constant (bool, - default False) - arg -- A pre-defined Argument to use. If this is None (default), - then a new Argument will be created from value, name and - const. + Parameters + ---------- + value + The value of the wrapped Argument (float, default None) + name + The name of the wrapped Argument (string, default None) + const + Flag indicating whether the Argument is constant (bool, + default False) + arg + A pre-defined Argument to use. If this is None (default), + then a new Argument will be created from value, name and + const. """ BaseBuilder.__init__(self) if arg is None: @@ -552,19 +584,25 @@ class OperatorBuilder(BaseBuilder): """BaseBuilder wrapper around an Operator literal. Attributes - literal -- The Operator wrapped by this instance. - name -- The name of the operator to be wrapped + ---------- + literal + The Operator wrapped by this instance. + name + The name of the operator to be wrapped """ def __init__(self, name, op=None): """Wrap an Operator or a function by name. - Arguments - name -- The name of the wrapped Operator - op -- If specified, this sets the literal attribute as this - operator (default None). Otherwise, the name is assumed to - be that of a numpy ufunc, which is used to specify the - Operator. + Parameters + ---------- + name + The name of the wrapped Operator + op + If specified, this sets the literal attribute as this + operator (default None). Otherwise, the name is assumed to + be that of a numpy ufunc, which is used to specify the + Operator. """ BaseBuilder.__init__(self) self.name = name @@ -576,7 +614,10 @@ def __call__(self, *args): This creates a new builder that encapsulates the operation. - args -- Arguments of the operation. + Attributes + ---------- + args + Arguments of the operation. Raises ValueError if self.literal.nin >= 0 and len(args) != op.nin """ @@ -637,10 +678,16 @@ def wrapOperator(name, op): def wrapFunction(name, func, nin=2, nout=1): """Wrap a function in an OperatorBuilder instance. - name -- The name of the function - func -- A callable python object - nin -- The number of input arguments (default 2) - nout -- The number of return values (default 1) + Attributes + ---------- + name + The name of the function + func + A callable python object + nin + The number of input arguments (default 2) + nout + The number of return values (default 1) Returns the OperatorBuilder instance that wraps the function. """ diff --git a/src/diffpy/srfit/equation/equationmod.py b/src/diffpy/srfit/equation/equationmod.py index 2b9c116e..aab8d99f 100644 --- a/src/diffpy/srfit/equation/equationmod.py +++ b/src/diffpy/srfit/equation/equationmod.py @@ -56,19 +56,32 @@ class Equation(Operator): accepts new argument values for the literal tree. Attributes - root -- The root Literal of the equation tree - argdict -- An OrderedDict of Arguments from the root. - args -- Property that gets the values of argdict. + ---------- + root + The root Literal of the equation tree + argdict + An OrderedDict of Arguments from the root. + args + Property that gets the values of argdict. Operator Attributes - args -- List of Literal arguments, set with 'addLiteral' - name -- A name for this operator. e.g. "add" or "sin" - nin -- Number of inputs (<1 means this is variable) - nout -- Number of outputs - operation -- Function that performs the operation. e.g. numpy.add. - symbol -- The symbolic representation. e.g. "+" or "sin". - _value -- The value of the Operator. - value -- Property for 'getValue'. + ------------------- + args + List of Literal arguments, set with 'addLiteral' + name + A name for this operator. e.g. "add" or "sin" + nin + Number of inputs (<1 means this is variable) + nout + Number of outputs + operation + Function that performs the operation. e.g. numpy.add. + symbol + The symbolic representation. e.g. "+" or "sin". + _value + The value of the Operator. + value + Property for 'getValue'. """ # define abstract attributes from the Operator base. @@ -78,10 +91,14 @@ class Equation(Operator): def __init__(self, name=None, root=None): """Initialize. - name -- A name for this Equation. - root -- The root node of the Literal tree (default None). If root - is not passed here, you must call the 'setRoot' method to - set or change the root node. + Attributes + ---------- + name + A name for this Equation. + root + The root node of the Literal tree (default None). If root + is not passed here, you must call the 'setRoot' method to + set or change the root node. """ # Operator stuff. We circumvent Operator.__init__ since we're using # args as a property. We cannot set it, as the Operator tries to do. @@ -127,7 +144,7 @@ def __getattr__(self, name): ) def __dir__(self): - "Return sorted list of attributes for this object." + """Return sorted list of attributes for this object.""" rv = set(dir(type(self))) rv.update(self.__dict__, self.argdict) rv = sorted(rv) diff --git a/src/diffpy/srfit/equation/literals/argument.py b/src/diffpy/srfit/equation/literals/argument.py index 9f9f1cd7..60d639f2 100644 --- a/src/diffpy/srfit/equation/literals/argument.py +++ b/src/diffpy/srfit/equation/literals/argument.py @@ -30,11 +30,16 @@ class Argument(Literal, ArgumentABC): """Argument class. Attributes - name -- A name for this Argument. - const -- A flag indicating whether this is considered a constant. - Constants may be given special treatment by the Visitors. - _value -- The value of the Argument. Modified with 'setValue'. - value -- Property for 'getValue' and 'setValue'. + ---------- + name + A name for this Argument. + const + A flag indicating whether this is considered a constant. + Constants may be given special treatment by the Visitors. + _value + The value of the Argument. Modified with 'setValue'. + value + Property for 'getValue' and 'setValue'. """ const = None @@ -57,7 +62,10 @@ def getValue(self): def setValue(self, val): """Set the value of the Literal. - val -- The value to assign + Attributes + ---------- + val + The value to assign """ if isinstance(self._value, ndarray) or isinstance(val, ndarray): notequiv = not array_equal(self._value, val) diff --git a/src/diffpy/srfit/equation/literals/literal.py b/src/diffpy/srfit/equation/literals/literal.py index 1bf7fdac..ebdc17a9 100644 --- a/src/diffpy/srfit/equation/literals/literal.py +++ b/src/diffpy/srfit/equation/literals/literal.py @@ -31,8 +31,11 @@ class Literal(Observable, LiteralABC): Literal derives from Observable. See diffpy.srfit.util.observable. Attributes - name -- A name for this Literal (default None). - _value -- The value of the Literal. + ---------- + name + A name for this Literal (default None). + _value + The value of the Literal. """ name = None diff --git a/src/diffpy/srfit/equation/literals/operators.py b/src/diffpy/srfit/equation/literals/operators.py index 1f26c2e6..98264bec 100644 --- a/src/diffpy/srfit/equation/literals/operators.py +++ b/src/diffpy/srfit/equation/literals/operators.py @@ -345,7 +345,10 @@ def __init__(self, op): Arguments - op -- A numpy ufunc + Attributes + ---------- + op + A numpy ufunc """ Operator.__init__(self, name=op.__name__) self.symbol = op.__name__ diff --git a/src/diffpy/srfit/equation/visitors/__init__.py b/src/diffpy/srfit/equation/visitors/__init__.py index f6cce3bd..ef50ec43 100644 --- a/src/diffpy/srfit/equation/visitors/__init__.py +++ b/src/diffpy/srfit/equation/visitors/__init__.py @@ -35,8 +35,11 @@ def getArgs(literal, getconsts=True): """Get the Arguments of a Literal tree. - getconsts -- If True (default), then Arguments designated as constant - are also retrieved. + Attributes + ---------- + getconsts + If True (default), then Arguments designated as constant + are also retrieved. Returns a list of Arguments searched for depth-first. """ @@ -47,9 +50,12 @@ def getArgs(literal, getconsts=True): def getExpression(literal, eqskip=None): """Get math expression string from the Literal tree object. - eqskip -- regular expression pattern for Equation objects that should - be printed under their own name. Expand all Equation objects - when None. + Attributes + ---------- + eqskip + regular expression pattern for Equation objects that should + be printed under their own name. Expand all Equation objects + when None. Return string. """ diff --git a/src/diffpy/srfit/equation/visitors/argfinder.py b/src/diffpy/srfit/equation/visitors/argfinder.py index 089c8bcc..13ba085a 100644 --- a/src/diffpy/srfit/equation/visitors/argfinder.py +++ b/src/diffpy/srfit/equation/visitors/argfinder.py @@ -26,16 +26,21 @@ class ArgFinder(Visitor): """ArgFinder extracts Arguments from a Literal tree. Attributes - args -- The list of collected Arguments - getconsts -- Flag indicating whether to grab constant arguments. + ---------- + args + The list of collected Arguments + getconsts + Flag indicating whether to grab constant arguments. """ def __init__(self, getconsts=True): """Initialize. - Arguments - getconsts -- Flag indicating whether to parse constant arguments - (default True). + Parameters + ---------- + getconsts + Flag indicating whether to parse constant arguments + (default True). """ self.args = [] self.getconsts = getconsts diff --git a/src/diffpy/srfit/equation/visitors/printer.py b/src/diffpy/srfit/equation/visitors/printer.py index b3bc5d9d..4926c9ae 100644 --- a/src/diffpy/srfit/equation/visitors/printer.py +++ b/src/diffpy/srfit/equation/visitors/printer.py @@ -30,10 +30,14 @@ class Printer(Visitor): Attributes: - eqskip -- regular expression pattern for Equation objects that should - not be expanded, but printed under their own name. Expand - all equations when None. - output -- The output generated by the printer. + Attributes + ---------- + eqskip + regular expression pattern for Equation objects that should + not be expanded, but printed under their own name. Expand + all equations when None. + output + The output generated by the printer. """ # store compiled RE pattern for eqskip or None when none. diff --git a/src/diffpy/srfit/equation/visitors/swapper.py b/src/diffpy/srfit/equation/visitors/swapper.py index 756cdb68..b5ddbf4d 100644 --- a/src/diffpy/srfit/equation/visitors/swapper.py +++ b/src/diffpy/srfit/equation/visitors/swapper.py @@ -25,17 +25,24 @@ class Swapper(Visitor): Note that this cannot swap out a root node of a literal tree. This case must be tested for explicitly. - Attributes: - newlit -- The literal to be placed into the literal tree. - oldlit -- The literal to be replaced. + Attributes + ---------- + newlit + The literal to be placed into the literal tree. + oldlit + The literal to be replaced. """ def __init__(self, oldlit, newlit): """Initialize. - oldlit -- The literal to be replaced. - newlit -- The literal to be placed into the literal tree. See the - class for how the replacement takes place. + Attributes + ---------- + oldlit + The literal to be replaced. + newlit + The literal to be placed into the literal tree. See the + class for how the replacement takes place. """ self.newlit = newlit diff --git a/src/diffpy/srfit/equation/visitors/validator.py b/src/diffpy/srfit/equation/visitors/validator.py index cdf6d542..13f5e4e5 100644 --- a/src/diffpy/srfit/equation/visitors/validator.py +++ b/src/diffpy/srfit/equation/visitors/validator.py @@ -34,10 +34,13 @@ class Validator(Visitor): """Validator error for checking validity of an equation tree. - Attributes: - errors -- List of strings describing errors. - _nin -- Variable for counting the number input arguments for an - operator. + Attributes + ---------- + errors + List of strings describing errors. + _nin + Variable for counting the number input arguments for an + operator. """ def __init__(self): diff --git a/src/diffpy/srfit/fitbase/calculator.py b/src/diffpy/srfit/fitbase/calculator.py index 32e4c094..75083b4e 100644 --- a/src/diffpy/srfit/fitbase/calculator.py +++ b/src/diffpy/srfit/fitbase/calculator.py @@ -36,30 +36,50 @@ class Calculator(Operator, ParameterSet): calculate a generic signal. Attributes - name -- A name for this organizer. - meta -- A dictionary of metadata needed by the calculator. - _calculators -- A managed dictionary of Calculators, indexed by name. - _constraints -- A set of constrained Parameters. Constraints can be - added using the 'constrain' methods. - _parameters -- A managed OrderedDict of contained Parameters. - _parsets -- A managed dictionary of ParameterSets. - _restraints -- A set of Restraints. Restraints can be added using the - 'restrain' or 'confine' methods. - _eqfactory -- A diffpy.srfit.equation.builder.EquationFactory - instance that is used create Equations from string. + ---------- + name + A name for this organizer. + meta + A dictionary of metadata needed by the calculator. + _calculators + A managed dictionary of Calculators, indexed by name. + _constraints + A set of constrained Parameters. Constraints can be + added using the 'constrain' methods. + _parameters + A managed OrderedDict of contained Parameters. + _parsets + A managed dictionary of ParameterSets. + _restraints + A set of Restraints. Restraints can be added using the + 'restrain' or 'confine' methods. + _eqfactory + A diffpy.srfit.equation.builder.EquationFactory + instance that is used create Equations from string. Operator Attributes - args -- List of Literal arguments - nin -- Number of inputs (<1 means this is variable) - nout -- Number of outputs (1) - operation -- Function that performs the operation, self.__call__ - symbol -- Same as name - _value -- The value of the Operator. - value -- Property for 'getValue'. + ------------------- + args + List of Literal arguments + nin + Number of inputs (<1 means this is variable) + nout + Number of outputs (1) + operation + Function that performs the operation, self.__call__ + symbol + Same as name + _value + The value of the Operator. + value + Property for 'getValue'. Properties - names -- Variable names (read only). See getNames. - values -- Variable values (read only). See getValues. + ---------- + names + Variable names (read only). See getNames. + values + Variable values (read only). See getValues. """ # define abstract attributes from the Operator base. diff --git a/src/diffpy/srfit/fitbase/configurable.py b/src/diffpy/srfit/fitbase/configurable.py index 4aecfd5e..a06c62ba 100644 --- a/src/diffpy/srfit/fitbase/configurable.py +++ b/src/diffpy/srfit/fitbase/configurable.py @@ -26,9 +26,11 @@ class Configurable(object): A Configurable has state of which a FitRecipe must be aware. Attributes - _configobjs -- Set of Configureables in a hierarchy or instances. - Messages get passed up the hierarchy to a FitReciple - via these objects. + ---------- + _configobjs + Set of Configureables in a hierarchy or instances. + Messages get passed up the hierarchy to a FitReciple + via these objects. """ def __init__(self): diff --git a/src/diffpy/srfit/fitbase/constraint.py b/src/diffpy/srfit/fitbase/constraint.py index 5cf1e2f3..68171548 100644 --- a/src/diffpy/srfit/fitbase/constraint.py +++ b/src/diffpy/srfit/fitbase/constraint.py @@ -33,9 +33,12 @@ class Constraint(Validatable): constraint owns it). Attributes - par -- A Parameter that is the subject of the constraint. - eq -- An equation whose evaluation is used to set the value of the - constraint. + ---------- + par + A Parameter that is the subject of the constraint. + eq + An equation whose evaluation is used to set the value of the + constraint. """ def __init__(self): diff --git a/src/diffpy/srfit/fitbase/fitcontribution.py b/src/diffpy/srfit/fitbase/fitcontribution.py index 7b5abbf1..dba5f7f3 100644 --- a/src/diffpy/srfit/fitbase/fitcontribution.py +++ b/src/diffpy/srfit/fitbase/fitcontribution.py @@ -40,29 +40,47 @@ class FitContribution(ParameterSet): FitContribution. Attributes - name -- A name for this FitContribution. - profile -- A Profile that holds the measured (and calculated) - signal. - _calculators -- A managed dictionary of Calculators, indexed by name. - _constraints -- A set of constrained Parameters. Constraints can be - added using the 'constrain' methods. - _generators -- A managed dictionary of ProfileGenerators. - _parameters -- A managed OrderedDict of parameters. - _restraints -- A set of Restraints. Restraints can be added using the - 'restrain' method. - _parsets -- A managed dictionary of ParameterSets. - _eqfactory -- A diffpy.srfit.equation.builder.EquationFactory - instance that is used to create constraints and - restraints from string - _eq -- The FitContribution equation that will be optimized. - _reseq -- The residual equation. - _xname -- Name of the x-variable - _yname -- Name of the y-variable - _dyname -- Name of the dy-variable + ---------- + name + A name for this FitContribution. + profile + A Profile that holds the measured (and calculated) + signal. + _calculators + A managed dictionary of Calculators, indexed by name. + _constraints + A set of constrained Parameters. Constraints can be + added using the 'constrain' methods. + _generators + A managed dictionary of ProfileGenerators. + _parameters + A managed OrderedDict of parameters. + _restraints + A set of Restraints. Restraints can be added using the + 'restrain' method. + _parsets + A managed dictionary of ParameterSets. + _eqfactory + A diffpy.srfit.equation.builder.EquationFactory + instance that is used to create constraints and + restraints from string + _eq + The FitContribution equation that will be optimized. + _reseq + The residual equation. + _xname + Name of the x-variable + _yname + Name of the y-variable + _dyname + Name of the dy-variable Properties - names -- Variable names (read only). See getNames. - values -- Variable values (read only). See getValues. + ---------- + names + Variable names (read only). See getNames. + values + Variable values (read only). See getValues. """ def __init__(self, name): @@ -82,20 +100,26 @@ def __init__(self, name): def setProfile(self, profile, xname=None, yname=None, dyname=None): """Assign the Profile for this FitContribution. - profile -- A Profile that specifies the calculation points and that - will store the calculated signal. - xname -- The name of the independent variable from the Profile. If - this is None (default), then the name specified by the - Profile for this parameter will be used. This variable is - usable within string equations with the specified name. - yname -- The name of the observed Profile. If this is None - (default), then the name specified by the Profile for this - parameter will be used. This variable is usable within - string equations with the specified name. - dyname -- The name of the uncertainty in the observed Profile. If - this is None (default), then the name specified by the - Profile for this parameter will be used. This variable is - usable within string equations with the specified name. + Attributes + ---------- + profile + A Profile that specifies the calculation points and that + will store the calculated signal. + xname + The name of the independent variable from the Profile. If + this is None (default), then the name specified by the + Profile for this parameter will be used. This variable is + usable within string equations with the specified name. + yname + The name of the observed Profile. If this is None + (default), then the name specified by the Profile for this + parameter will be used. This variable is usable within + string equations with the specified name. + dyname + The name of the uncertainty in the observed Profile. If + this is None (default), then the name specified by the + Profile for this parameter will be used. This variable is + usable within string equations with the specified name. """ # Enforce type of the profile argument if not isinstance(profile, Profile): @@ -145,9 +169,13 @@ def addProfileGenerator(self, gen, name=None): Calling addProfileGenerator sets the profile equation to call the calculator and if there is not a profile equation already. - gen -- A ProfileGenerator instance - name -- A name for the calculator. If name is None (default), then - the ProfileGenerator's name attribute will be used. + Attributes + ---------- + gen + A ProfileGenerator instance + name + A name for the calculator. If name is None (default), then + the ProfileGenerator's name attribute will be used. Raises ValueError if the ProfileGenerator has no name. Raises ValueError if the ProfileGenerator has the same name as some @@ -179,14 +207,18 @@ def setEquation(self, eqstr, ns={}): for this FitContribution. The equation will be usable within setResidualEquation as "eq", and it takes no arguments. - eqstr -- A string representation of the equation. Any Parameter - registered by addParameter or setProfile, or function - registered by setCalculator, registerFunction or - registerStringFunction can be can be used in the equation - by name. Other names will be turned into Parameters of this - FitContribution. - ns -- A dictionary of Parameters, indexed by name, that are used - in the eqstr, but not registered (default {}). + Attributes + ---------- + eqstr + A string representation of the equation. Any Parameter + registered by addParameter or setProfile, or function + registered by setCalculator, registerFunction or + registerStringFunction can be can be used in the equation + by name. Other names will be turned into Parameters of this + FitContribution. + ns + A dictionary of Parameters, indexed by name, that are used + in the eqstr, but not registered (default {}). Raises ValueError if ns uses a name that is already used for a variable. @@ -226,10 +258,13 @@ def getEquation(self): def setResidualEquation(self, eqstr): """Set the residual equation for the FitContribution. - eqstr -- A string representation of the residual. If eqstr is None - (default), then the previous residual equation will be - used, or the chi2 residual will be used if that does not - exist. + Attributes + ---------- + eqstr + A string representation of the residual. If eqstr is None + (default), then the previous residual equation will be + used, or the chi2 residual will be used if that does not + exist. Two residuals are preset for convenience, "chiv" and "resv". chiv is defined such that dot(chiv, chiv) = chi^2. diff --git a/src/diffpy/srfit/fitbase/fithook.py b/src/diffpy/srfit/fitbase/fithook.py index 01bb2652..14c5811c 100644 --- a/src/diffpy/srfit/fitbase/fithook.py +++ b/src/diffpy/srfit/fitbase/fithook.py @@ -56,15 +56,22 @@ def reset(self, recipe): def precall(self, recipe): """This is called within FitRecipe.residual, before the calculation. - recipe -- The FitRecipe instance + Attributes + ---------- + recipe + The FitRecipe instance """ return def postcall(self, recipe, chiv): """This is called within FitRecipe.residual, after the calculation. - recipe -- The FitRecipe instance - chiv -- The residual vector + Attributes + ---------- + recipe + The FitRecipe instance + chiv + The residual vector """ return @@ -80,12 +87,20 @@ class PrintFitHook(FitHook): Attributes - count -- The number of times the residual has been called (default 0). - verbose -- An integer telling how verbose to be (default 1). - 0 -- print nothing - 1 -- print the count during the precall - 2 -- print the residual during the postcall - >=3 -- print the variables during the postcall + Attributes + ---------- + count + The number of times the residual has been called (default 0). + verbose + An integer telling how verbose to be (default 1). + 0 + print nothing + 1 + print the count during the precall + 2 + print the residual during the postcall + >=3 + print the variables during the postcall """ def __init__(self): @@ -108,7 +123,10 @@ def reset(self, recipe): def precall(self, recipe): """This is called within FitRecipe.residual, before the calculation. - recipe -- The FitRecipe instance + Attributes + ---------- + recipe + The FitRecipe instance """ self.count += 1 if self.verbose > 0: @@ -118,8 +136,12 @@ def precall(self, recipe): def postcall(self, recipe, chiv): """This is called within FitRecipe.residual, after the calculation. - recipe -- The FitRecipe instance - chiv -- The residual vector + Attributes + ---------- + recipe + The FitRecipe instance + chiv + The residual vector """ if self.verbose < 2: return @@ -209,8 +231,12 @@ def postcall(self, recipe, chiv): Find data and plot it. - recipe -- The FitRecipe instance - chiv -- The residual vector + Attributes + ---------- + recipe + The FitRecipe instance + chiv + The residual vector """ FitHook.postcall(self, recipe, chiv) import pylab diff --git a/src/diffpy/srfit/fitbase/fitrecipe.py b/src/diffpy/srfit/fitbase/fitrecipe.py index f6f0cbd7..7c1e3357 100644 --- a/src/diffpy/srfit/fitbase/fitrecipe.py +++ b/src/diffpy/srfit/fitbase/fitrecipe.py @@ -50,42 +50,65 @@ class FitRecipe(_fitrecipe_interface, RecipeOrganizer): """FitRecipe class. Attributes - name -- A name for this FitRecipe. - fithooks -- List of FitHook instances that can pass information out - of the system during a refinement. By default, the is - populated by a PrintFitHook instance. - _constraints -- A dictionary of Constraints, indexed by the constrained - Parameter. Constraints can be added using the - 'constrain' method. - _oconstraints -- An ordered list of the constraints from this and all - sub-components. - _calculators -- A managed dictionary of Calculators. - _contributions -- A managed OrderedDict of FitContributions. - _parameters -- A managed OrderedDict of parameters (in this case the - parameters are varied). - _parsets -- A managed dictionary of ParameterSets. - _eqfactory -- A diffpy.srfit.equation.builder.EquationFactory - instance that is used to create constraints and - restraints from string - _restraintlist -- A list of restraints from this and all sub-components. - _restraints -- A set of Restraints. Restraints can be added using the - 'restrain' or 'confine' methods. - _ready -- A flag indicating if all attributes are ready for the - calculation. - _tagmanager -- A TagManager instance for managing tags on Parameters. - _weights -- List of weighing factors for each FitContribution. The - weights are multiplied by the residual of the - FitContribution when determining the overall residual. - _fixedtag -- "__fixed", used for tagging variables as fixed. Don't - use this tag unless you want issues. + ---------- + name + A name for this FitRecipe. + fithooks + List of FitHook instances that can pass information out + of the system during a refinement. By default, the is + populated by a PrintFitHook instance. + _constraints + A dictionary of Constraints, indexed by the constrained + Parameter. Constraints can be added using the + 'constrain' method. + _oconstraints + An ordered list of the constraints from this and all + sub-components. + _calculators + A managed dictionary of Calculators. + _contributions + A managed OrderedDict of FitContributions. + _parameters + A managed OrderedDict of parameters (in this case the + parameters are varied). + _parsets + A managed dictionary of ParameterSets. + _eqfactory + A diffpy.srfit.equation.builder.EquationFactory + instance that is used to create constraints and + restraints from string + _restraintlist + A list of restraints from this and all sub-components. + _restraints + A set of Restraints. Restraints can be added using the + 'restrain' or 'confine' methods. + _ready + A flag indicating if all attributes are ready for the + calculation. + _tagmanager + A TagManager instance for managing tags on Parameters. + _weights + List of weighing factors for each FitContribution. The + weights are multiplied by the residual of the + FitContribution when determining the overall residual. + _fixedtag + "__fixed", used for tagging variables as fixed. Don't + use this tag unless you want issues. Properties - names -- Variable names (read only). See getNames. - values -- Variable values (read only). See getValues. - fixednames -- Names of the fixed refinable variables (read only). - fixedvalues -- Values of the fixed refinable variables (read only). - bounds -- Bounds on parameters (read only). See getBounds. - bounds2 -- Bounds on parameters (read only). See getBounds2. + ---------- + names + Variable names (read only). See getNames. + values + Variable values (read only). See getValues. + fixednames + Names of the fixed refinable variables (read only). + fixedvalues + Values of the fixed refinable variables (read only). + bounds + Bounds on parameters (read only). See getBounds. + bounds2 + Bounds on parameters (read only). See getBounds2. """ fixednames = property( @@ -138,9 +161,13 @@ def pushFitHook(self, fithook, index=None): diffpy.srfit.fitbase.fithook.FitHook class for the required interface. Added FitHooks will be called sequentially during refinement. - fithook -- FitHook instance to add to the sequence - index -- Index for inserting fithook into the list of fit hooks. If - this is None (default), the fithook is added to the end. + Attributes + ---------- + fithook + FitHook instance to add to the sequence + index + Index for inserting fithook into the list of fit hooks. If + this is None (default), the fithook is added to the end. """ if index is None: index = len(self.fithooks) @@ -152,9 +179,13 @@ def pushFitHook(self, fithook, index=None): def popFitHook(self, fithook=None, index=-1): """Remove a FitHook by index or reference. - fithook -- FitHook instance to remove from the sequence. If this is - None (default), default to index. - index -- Index of FitHook instance to remove (default -1). + Attributes + ---------- + fithook + FitHook instance to remove from the sequence. If this is + None (default), default to index. + index + Index of FitHook instance to remove (default -1). Raises ValueError if fithook is not None, but is not present in the sequence. @@ -178,7 +209,10 @@ def clearFitHooks(self): def addContribution(self, con, weight=1.0): """Add a FitContribution to the FitRecipe. - con -- The FitContribution to be stored. + Attributes + ---------- + con + The FitContribution to be stored. Raises ValueError if the FitContribution has no name Raises ValueError if the FitContribution has the same name as some @@ -197,7 +231,10 @@ def setWeight(self, con, weight): def addParameterSet(self, parset): """Add a ParameterSet to the hierarchy. - parset -- The ParameterSet to be stored. + Attributes + ---------- + parset + The ParameterSet to be stored. Raises ValueError if the ParameterSet has no name. Raises ValueError if the ParameterSet has the same name as some other @@ -217,12 +254,14 @@ def removeParameterSet(self, parset): def residual(self, p=[]): """Calculate the vector residual to be optimized. - Arguments - p -- The list of current variable values, provided in the same order - as the '_parameters' list. If p is an empty iterable (default), - then it is assumed that the parameters have already been - updated in some other way, and the explicit update within this - function is skipped. + Parameters + ---------- + p + The list of current variable values, provided in the same order + as the '_parameters' list. If p is an empty iterable (default), + then it is assumed that the parameters have already been + updated in some other way, and the explicit update within this + function is skipped. The residual is by default the weighted concatenation of each FitContribution's residual, plus the value of each restraint. The array @@ -266,12 +305,14 @@ def residual(self, p=[]): def scalarResidual(self, p=[]): """Calculate the scalar residual to be optimized. - Arguments - p -- The list of current variable values, provided in the same order - as the '_parameters' list. If p is an empty iterable (default), - then it is assumed that the parameters have already been - updated in some other way, and the explicit update within this - function is skipped. + Parameters + ---------- + p + The list of current variable values, provided in the same order + as the '_parameters' list. If p is an empty iterable (default), + then it is assumed that the parameters have already been + updated in some other way, and the explicit update within this + function is skipped. The residual is by default the weighted concatenation of each FitContribution's residual, plus the value of each restraint. The array @@ -445,17 +486,25 @@ def addVar( ): """Add a variable to be refined. - par -- A Parameter that will be varied during a fit. - value -- An initial value for the variable. If this is None - (default), then the current value of par will be used. - name -- A name for this variable. If name is None (default), then - the name of the parameter will be used. - fixed -- Fix the variable so that it does not vary (default False). - tag -- A tag for the variable. This can be used to retrieve, fix - or free variables by tag (default None). Note that a - variable is automatically tagged with its name and "all". - tags -- A list of tags (default []). Both tag and tags can be - applied. + Attributes + ---------- + par + A Parameter that will be varied during a fit. + value + An initial value for the variable. If this is None + (default), then the current value of par will be used. + name + A name for this variable. If name is None (default), then + the name of the parameter will be used. + fixed + Fix the variable so that it does not vary (default False). + tag + A tag for the variable. This can be used to retrieve, fix + or free variables by tag (default None). Note that a + variable is automatically tagged with its name and "all". + tags + A list of tags (default []). Both tag and tags can be + applied. Returns the ParameterProxy (variable) for the passed Parameter. @@ -495,7 +544,10 @@ def delVar(self, var): Note that constraints and restraints involving the variable are not modified. - var -- A variable of the FitRecipe. + Attributes + ---------- + var + A variable of the FitRecipe. Raises ValueError if var is not part of the FitRecipe. """ @@ -519,19 +571,26 @@ def newVar(self, name, value=None, fixed=False, tag=None, tags=[]): optimization routine, and therefore should only be created to be used in constraint or restraint equations. - name -- The name of the variable. The variable will be able to be - used by this name in restraint and constraint equations. - value -- An initial value for the variable. If this is None - (default), then the variable will be given the value of the - first non-None-valued Parameter constrained to it. If this - fails, an error will be thrown when 'residual' is called. - fixed -- Fix the variable so that it does not vary (default False). - The variable will still be managed by the FitRecipe. - tag -- A tag for the variable. This can be used to fix and free - variables by tag (default None). Note that a variable is - automatically tagged with its name and "all". - tags -- A list of tags (default []). Both tag and tags can be - applied. + Attributes + ---------- + name + The name of the variable. The variable will be able to be + used by this name in restraint and constraint equations. + value + An initial value for the variable. If this is None + (default), then the variable will be given the value of the + first non-None-valued Parameter constrained to it. If this + fails, an error will be thrown when 'residual' is called. + fixed + Fix the variable so that it does not vary (default False). + The variable will still be managed by the FitRecipe. + tag + A tag for the variable. This can be used to fix and free + variables by tag (default None). Note that a variable is + automatically tagged with its name and "all". + tags + A list of tags (default []). Both tag and tags can be + applied. Returns the new variable (Parameter instance). """ @@ -564,7 +623,10 @@ def _newParameter(self, name, value, check=True): def __getVarAndCheck(self, var): """Get the actual variable from var. - var -- A variable of the FitRecipe, or the name of a variable. + Attributes + ---------- + var + A variable of the FitRecipe, or the name of a variable. Returns the variable or None if the variable cannot be found in the _parameters list. @@ -682,7 +744,10 @@ def unconstrain(self, *pars): This removes any constraints on a Parameter. If the Parameter is also a variable of the recipe, it will be freed as well. - *pars -- The names of Parameters or Parameters to unconstrain. + Attributes + ---------- + *pars + The names of Parameters or Parameters to unconstrain. Raises ValueError if the Parameter is not constrained. @@ -719,14 +784,19 @@ def constrain(self, par, con, ns={}): and its current value is None. A constrained variable will be set as fixed. - par -- The Parameter to constrain. - con -- A string representation of the constraint equation or a - Parameter to constrain to. A constraint equation must - consist of numpy operators and "known" Parameters. - Parameters are known if they are in the ns argument, or if - they are managed by this object. - ns -- A dictionary of Parameters, indexed by name, that are used - in the eqstr, but not part of this object (default {}). + Attributes + ---------- + par + The Parameter to constrain. + con + A string representation of the constraint equation or a + Parameter to constrain to. A constraint equation must + consist of numpy operators and "known" Parameters. + Parameters are known if they are in the ns argument, or if + they are managed by this object. + ns + A dictionary of Parameters, indexed by name, that are used + in the eqstr, but not part of this object (default {}). Raises ValueError if ns uses a name that is already used for a variable. @@ -795,9 +865,13 @@ def boundsToRestraints(self, sig=1, scaled=False): The bounds become limits on the restraint. - sig -- The uncertainty on the bounds (scalar or iterable, - default 1). - scaled -- Scale the restraints, see restrain. + Attributes + ---------- + sig + The uncertainty on the bounds (scalar or iterable, + default 1). + scaled + Scale the restraints, see restrain. """ pars = self._parameters.values() if not hasattr(sig, "__iter__"): diff --git a/src/diffpy/srfit/fitbase/fitresults.py b/src/diffpy/srfit/fitbase/fitresults.py index 12c15120..e402bfd5 100644 --- a/src/diffpy/srfit/fitbase/fitresults.py +++ b/src/diffpy/srfit/fitbase/fitresults.py @@ -37,33 +37,58 @@ class FitResults(object): """Class for processing, presenting and storing results of a fit. Attributes - recipe -- The recipe containing the results. - cov -- The covariance matrix from the recipe. - conresults -- An ordered dictionary of ContributionResults for each - FitContribution, indexed by the FitContribution name. - derivstep -- The fractional step size for calculating numeric - derivatives. Default 1e-8. - varnames -- Names of the variables in the recipe. - varvals -- Values of the variables in the recipe. - varunc -- Uncertainties in the variable values. - showfixed -- Show fixed variables (default True). - fixednames -- Names of the fixed variables of the recipe. - fixedvals -- Values of the fixed variables of the recipe. - showcon -- Show constraint values in the output (default False). - connames -- Names of the constrained parameters. - convals -- Values of the constrained parameters. - conunc -- Uncertainties in the constraint values. - residual -- The scalar residual of the recipe. - penalty -- The penalty to residual from the restraints. - chi2 -- The chi2 of the recipe. - cumchi2 -- The cumulative chi2 of the recipe. - rchi2 -- The reduced chi2 of the recipe. - rw -- The Rw of the recipe. - cumrw -- The cumulative Rw of the recipe. - messages -- A list of messages about the results. - precision -- The precision of numeric output (default 8). - _dcon -- The derivatives of the constraint equations with respect to - the variables. This is used internally. + ---------- + recipe + The recipe containing the results. + cov + The covariance matrix from the recipe. + conresults + An ordered dictionary of ContributionResults for each + FitContribution, indexed by the FitContribution name. + derivstep + The fractional step size for calculating numeric + derivatives. Default 1e-8. + varnames + Names of the variables in the recipe. + varvals + Values of the variables in the recipe. + varunc + Uncertainties in the variable values. + showfixed + Show fixed variables (default True). + fixednames + Names of the fixed variables of the recipe. + fixedvals + Values of the fixed variables of the recipe. + showcon + Show constraint values in the output (default False). + connames + Names of the constrained parameters. + convals + Values of the constrained parameters. + conunc + Uncertainties in the constraint values. + residual + The scalar residual of the recipe. + penalty + The penalty to residual from the restraints. + chi2 + The chi2 of the recipe. + cumchi2 + The cumulative chi2 of the recipe. + rchi2 + The reduced chi2 of the recipe. + rw + The Rw of the recipe. + cumrw + The cumulative Rw of the recipe. + messages + A list of messages about the results. + precision + The precision of numeric output (default 8). + _dcon + The derivatives of the constraint equations with respect to + the variables. This is used internally. Each of these attributes, except the recipe, are created or updated when the update method is called. @@ -72,11 +97,17 @@ class FitResults(object): def __init__(self, recipe, update=True, showfixed=True, showcon=False): """Initialize the attributes. - recipe -- The recipe containing the results - update -- Flag indicating whether to do an immediate update (default - True). - showcon -- Show fixed variables in the output (default True). - showcon -- Show constraint values in the output (default False). + Attributes + ---------- + recipe + The recipe containing the results + update + Flag indicating whether to do an immediate update (default + True). + showcon + Show fixed variables in the output (default True). + showcon + Show constraint values in the output (default False). """ self.recipe = recipe self.conresults = OrderedDict() @@ -298,9 +329,14 @@ def formatResults(self, header="", footer="", update=False): This function is called by printResults and saveResults. Overloading the formatting here will change all three functions. - header -- A header to add to the output (default "") - footer -- A footer to add to the output (default "") - update -- Flag indicating whether to call update() (default False). + Attributes + ---------- + header + A header to add to the output (default "") + footer + A footer to add to the output (default "") + update + Flag indicating whether to call update() (default False). Returns a string containing the formatted results. """ @@ -479,9 +515,14 @@ def formatResults(self, header="", footer="", update=False): def printResults(self, header="", footer="", update=False): """Format and print the results. - header -- A header to add to the output (default "") - footer -- A footer to add to the output (default "") - update -- Flag indicating whether to call update() (default False). + Attributes + ---------- + header + A header to add to the output (default "") + footer + A footer to add to the output (default "") + update + Flag indicating whether to call update() (default False). """ print(self.formatResults(header, footer, update).rstrip()) return @@ -493,9 +534,13 @@ def saveResults(self, filename, header="", footer="", update=False): """Format and save the results. filename - Name of the save file. - header -- A header to add to the output (default "") - footer -- A footer to add to the output (default "") - update -- Flag indicating whether to call update() (default False). + ---------------------------------- + header + A header to add to the output (default "") + footer + A footer to add to the output (default "") + update + Flag indicating whether to call update() (default False). """ # Save the time and user from getpass import getuser @@ -521,33 +566,52 @@ class ContributionResults(object): This does not store the FitContribution. Attributes - y -- The FitContribution's profile over the calculation range - (default None). - dy -- The uncertainty in the FitContribution's profile over the - calculation range (default None). - x -- A numpy array of the calculated independent variable for the - FitContribution (default None). - ycalc -- A numpy array of the calculated signal for the FitContribution - (default None). - residual -- The scalar residual of the FitContribution. - chi2 -- The chi2 of the FitContribution. - cumchi2 -- The cumulative chi2 of the FitContribution. - rw -- The Rw of the FitContribution. - cumrw -- The cumulative Rw of the FitContribution. - weight -- The weight of the FitContribution in the recipe. - conlocs -- The location of the constrained parameters in the - FitContribution (see the - RecipeContainer._locateManagedObject method). - convals -- Values of the constrained parameters. - conunc -- Uncertainties in the constraint values. + ---------- + y + The FitContribution's profile over the calculation range + (default None). + dy + The uncertainty in the FitContribution's profile over the + calculation range (default None). + x + A numpy array of the calculated independent variable for the + FitContribution (default None). + ycalc + A numpy array of the calculated signal for the FitContribution + (default None). + residual + The scalar residual of the FitContribution. + chi2 + The chi2 of the FitContribution. + cumchi2 + The cumulative chi2 of the FitContribution. + rw + The Rw of the FitContribution. + cumrw + The cumulative Rw of the FitContribution. + weight + The weight of the FitContribution in the recipe. + conlocs + The location of the constrained parameters in the + FitContribution (see the + RecipeContainer._locateManagedObject method). + convals + Values of the constrained parameters. + conunc + Uncertainties in the constraint values. """ def __init__(self, con, weight, fitres): """Initialize the attributes. - con -- The FitContribution - weight -- The weight of the FitContribution in the recipe - fitres -- The FitResults instance to contain this ContributionResults + Attributes + ---------- + con + The FitContribution + weight + The weight of the FitContribution in the recipe + fitres + The FitResults instance to contain this ContributionResults """ self.x = None self.y = None @@ -629,8 +693,11 @@ def resultsDictionary(results): This reads the results from file and stores them in a dictionary to be returned to the caller. The dictionary may contain non-result entries. - results -- An open file-like object, name of a file that contains - results from FitResults or a string containing fit results. + Attributes + ---------- + results + An open file-like object, name of a file that contains + results from FitResults or a string containing fit results. """ resstr = inputToString(results) @@ -654,9 +721,13 @@ def initializeRecipe(recipe, results): free) in the recipe to the results values. Note that the recipe has to be configured, with variables. This does not reconstruct a FitRecipe. - recipe -- A configured recipe with variables - results -- An open file-like object, name of a file that contains - results from FitResults or a string containing fit results. + Attributes + ---------- + recipe + A configured recipe with variables + results + An open file-like object, name of a file that contains + results from FitResults or a string containing fit results. """ mpairs = resultsDictionary(results) diff --git a/src/diffpy/srfit/fitbase/parameter.py b/src/diffpy/srfit/fitbase/parameter.py index e9e6cf8b..531a07d1 100644 --- a/src/diffpy/srfit/fitbase/parameter.py +++ b/src/diffpy/srfit/fitbase/parameter.py @@ -40,25 +40,37 @@ class Parameter(_parameter_interface, Argument, Validatable): """Parameter class. Attributes - name -- A name for this Parameter. - const -- A flag indicating whether this is considered a constant. - _value -- The value of the Parameter. Modified with 'setValue'. - value -- Property for 'getValue' and 'setValue'. - constrained -- A flag indicating if the Parameter is constrained - (default False). - bounds -- A 2-list defining the bounds on the Parameter. This can be - used by some optimizers when the Parameter is varied. See - FitRecipe.getBounds and FitRecipe.boundsToRestraints. + ---------- + name + A name for this Parameter. + const + A flag indicating whether this is considered a constant. + _value + The value of the Parameter. Modified with 'setValue'. + value + Property for 'getValue' and 'setValue'. + constrained + A flag indicating if the Parameter is constrained + (default False). + bounds + A 2-list defining the bounds on the Parameter. This can be + used by some optimizers when the Parameter is varied. See + FitRecipe.getBounds and FitRecipe.boundsToRestraints. """ def __init__(self, name, value=None, const=False): """Initialization. - name -- The name of this Parameter (must be a valid attribute - identifier) - value -- The initial value of this Parameter (default 0). - const -- A flag inticating whether the Parameter is a constant (like - pi). + Attributes + ---------- + name + The name of this Parameter (must be a valid attribute + identifier) + value + The initial value of this Parameter (default 0). + const + A flag inticating whether the Parameter is a constant (like + pi). Raises ValueError if the name is not a valid attribute identifier """ @@ -71,11 +83,16 @@ def __init__(self, name, value=None, const=False): def setValue(self, val): """Set the value of the Parameter and the bounds. - val -- The value to assign. - lb -- The lower bounds for the bounds list. If this is None - (default), then the lower bound will not be alterered. - ub -- The upper bounds for the bounds list. If this is None - (default), then the upper bound will not be alterered. + Attributes + ---------- + val + The value to assign. + lb + The lower bounds for the bounds list. If this is None + (default), then the lower bound will not be alterered. + ub + The upper bounds for the bounds list. If this is None + (default), then the upper bound will not be alterered. Returns self so that mutators can be chained. """ @@ -85,11 +102,15 @@ def setValue(self, val): def setConst(self, const=True, value=None): """Toggle the Parameter as constant. - const -- Flag indicating if the parameter is constant (default - True). - value -- An optional value for the parameter (default None). If this - is not None, then the parameter will get a new value, - constant or otherwise. + Attributes + ---------- + const + Flag indicating if the parameter is constant (default + True). + value + An optional value for the parameter (default None). If this + is not None, then the parameter will get a new value, + constant or otherwise. Returns self so that mutators can be chained. """ @@ -101,8 +122,12 @@ def setConst(self, const=True, value=None): def boundRange(self, lb=None, ub=None): """Set lower and upper bound of the Parameter. - lb -- The lower bound for the bounds list. - ub -- The upper bound for the bounds list. + Attributes + ---------- + lb + The lower bound for the bounds list. + ub + The upper bound for the bounds list. Returns self so that mutators can be chained. """ @@ -115,11 +140,15 @@ def boundRange(self, lb=None, ub=None): def boundWindow(self, lr=0, ur=None): """Create bounds centered on the current value of the Parameter. - lr -- The radius of the lower bound (default 0). The lower bound is - computed as value - lr. - ur -- The radius of the upper bound. The upper bound is computed as - value + ur. If this is None (default), then the value of the - lower radius is used. + Attributes + ---------- + lr + The radius of the lower bound (default 0). The lower bound is + computed as value - lr. + ur + The radius of the upper bound. The upper bound is computed as + value + ur. If this is None (default), then the value of the + lower radius is used. Returns self so that mutators can be chained. """ @@ -152,16 +181,23 @@ class ParameterProxy(Parameter): This allows for the same parameter to have multiple names. Attributes - name -- A name for this ParameterProxy. Names should be unique within a - RecipeOrganizer and should be valid attribute names. - par -- The Parameter this is a proxy for. + ---------- + name + A name for this ParameterProxy. Names should be unique within a + RecipeOrganizer and should be valid attribute names. + par + The Parameter this is a proxy for. """ def __init__(self, name, par): """Initialization. - name -- The name of this ParameterProxy. - par -- The Parameter this is a proxy for. + Attributes + ---------- + name + The name of this ParameterProxy. + par + The Parameter this is a proxy for. Raises ValueError if the name is not a valid attribute identifier """ @@ -250,24 +286,31 @@ class ParameterAdapter(Parameter): def __init__(self, name, obj, getter=None, setter=None, attr=None): """Wrap an object as a Parameter. - name -- The name of this Parameter. - obj -- The object to be wrapped. - getter -- The unbound function that can be used to access the - attribute containing the parameter value. getter(obj) - should return the Parameter value. If getter is None - (default), it is assumed that an attribute is accessed - via attr. If attr is also specified, then the Parameter - value will be accessed via getter(obj, attr). - setter -- The unbound function that can be used to modify the - attribute containing the parameter value. - setter(obj, value) should set the attribute to the - passed value. If setter is None (default), it is assumed - that an attribute is accessed via attr. If attr is also - specified, then the Parameter value will be set via - setter(obj, attr, value). - attr -- The name of the attribute that contains the value of the - parameter. If attr is None (default), then both getter and - setter must be specified. + Attributes + ---------- + name + The name of this Parameter. + obj + The object to be wrapped. + getter + The unbound function that can be used to access the + attribute containing the parameter value. getter(obj) + should return the Parameter value. If getter is None + (default), it is assumed that an attribute is accessed + via attr. If attr is also specified, then the Parameter + value will be accessed via getter(obj, attr). + setter + The unbound function that can be used to modify the + attribute containing the parameter value. + setter(obj, value) should set the attribute to the + passed value. If setter is None (default), it is assumed + that an attribute is accessed via attr. If attr is also + specified, then the Parameter value will be set via + setter(obj, attr, value). + attr + The name of the attribute that contains the value of the + parameter. If attr is None (default), then both getter and + setter must be specified. Raises ValueError if exactly one of getter or setter is not None, or if getter, setter and attr are all None. diff --git a/src/diffpy/srfit/fitbase/parameterset.py b/src/diffpy/srfit/fitbase/parameterset.py index 69efaa7c..6aafdf79 100644 --- a/src/diffpy/srfit/fitbase/parameterset.py +++ b/src/diffpy/srfit/fitbase/parameterset.py @@ -40,27 +40,41 @@ class ParameterSet(RecipeOrganizer): methods. Attributes - name -- A name for this organizer. - _calculators -- A managed dictionary of Calculators, indexed by name. - _constraints -- A set of constrained Parameters. Constraints can be - added using the 'constrain' methods. - _parameters -- A managed OrderedDict of parameters. - _restraints -- A set of Restraints. Restraints can be added using the - 'restrain' methods. - _parsets -- A managed dictionary of ParameterSets. - _eqfactory -- A diffpy.srfit.equation.builder.EquationFactory - instance that is used to create constraints and - restraints from string equations. + ---------- + name + A name for this organizer. + _calculators + A managed dictionary of Calculators, indexed by name. + _constraints + A set of constrained Parameters. Constraints can be + added using the 'constrain' methods. + _parameters + A managed OrderedDict of parameters. + _restraints + A set of Restraints. Restraints can be added using the + 'restrain' methods. + _parsets + A managed dictionary of ParameterSets. + _eqfactory + A diffpy.srfit.equation.builder.EquationFactory + instance that is used to create constraints and + restraints from string equations. Properties - names -- Variable names (read only). See getNames. - values -- Variable values (read only). See getValues. + ---------- + names + Variable names (read only). See getNames. + values + Variable values (read only). See getValues. """ def __init__(self, name): """Initialize. - name -- The name of this ParameterSet. + Attributes + ---------- + name + The name of this ParameterSet. """ RecipeOrganizer.__init__(self, name) @@ -76,7 +90,10 @@ def __init__(self, name): def addParameterSet(self, parset): """Add a ParameterSet to the hierarchy. - parset -- The ParameterSet to be stored. + Attributes + ---------- + parset + The ParameterSet to be stored. Raises ValueError if the ParameterSet has no name. Raises ValueError if the ParameterSet has the same name as some other @@ -96,8 +113,11 @@ def removeParameterSet(self, parset): def setConst(self, const=True): """Set every parameter within the set to a constant. - const -- Flag indicating if the parameter is constant (default - True). + Attributes + ---------- + const + Flag indicating if the parameter is constant (default + True). """ for par in self.iterPars(): par.setConst(const) diff --git a/src/diffpy/srfit/fitbase/profile.py b/src/diffpy/srfit/fitbase/profile.py index da0e04ce..035166e4 100644 --- a/src/diffpy/srfit/fitbase/profile.py +++ b/src/diffpy/srfit/fitbase/profile.py @@ -42,29 +42,46 @@ class Profile(Observable, Validatable): Attributes - _xobs -- A numpy array of the observed independent variable (default - None) - xobs -- Read-only property of _xobs. - _yobs -- A numpy array of the observed signal (default None) - yobs -- Read-only property of _yobs. - _dyobs -- A numpy array of the uncertainty of the observed signal - (default None, optional). - dyobs -- Read-only property of _dyobs. - x -- A numpy array of the calculated independent variable (default - None, property for xpar accessors). - y -- The profile over the calculation range (default None, property - for ypar accessors). - dy -- The uncertainty in the profile over the calculation range - (default None, property for dypar accessors). - ycalc -- A numpy array of the calculated signal (default None). - xpar -- A Parameter that stores x (named "x"). - ypar -- A Parameter that stores y (named "y"). - dypar -- A Parameter that stores dy (named "dy"). - ycpar -- A Parameter that stores ycalc (named "ycalc"). This is - not observed by the profile, but it is present so it can be - constrained to. - meta -- A dictionary of metadata. This is only set if provided by a - parser. + Attributes + ---------- + _xobs + A numpy array of the observed independent variable (default + None) + xobs + Read-only property of _xobs. + _yobs + A numpy array of the observed signal (default None) + yobs + Read-only property of _yobs. + _dyobs + A numpy array of the uncertainty of the observed signal + (default None, optional). + dyobs + Read-only property of _dyobs. + x + A numpy array of the calculated independent variable (default + None, property for xpar accessors). + y + The profile over the calculation range (default None, property + for ypar accessors). + dy + The uncertainty in the profile over the calculation range + (default None, property for dypar accessors). + ycalc + A numpy array of the calculated signal (default None). + xpar + A Parameter that stores x (named "x"). + ypar + A Parameter that stores y (named "y"). + dypar + A Parameter that stores dy (named "dy"). + ycpar + A Parameter that stores ycalc (named "ycalc"). This is + not observed by the profile, but it is present so it can be + constrained to. + meta + A dictionary of metadata. This is only set if provided by a + parser. """ def __init__(self): @@ -121,12 +138,16 @@ def loadParsedData(self, parser): def setObservedProfile(self, xobs, yobs, dyobs=None): """Set the observed profile. - Arguments - xobs -- Numpy array of the independent variable - yobs -- Numpy array of the observed signal. - dyobs -- Numpy array of the uncertainty in the observed signal. If - dyobs is None (default), it will be set to 1 at each - observed xobs. + Parameters + ---------- + xobs + Numpy array of the independent variable + yobs + Numpy array of the observed signal. + dyobs + Numpy array of the uncertainty in the observed signal. If + dyobs is None (default), it will be set to 1 at each + observed xobs. Raises ValueError if len(yobs) != len(xobs) Raises ValueError if dyobs != None and len(dyobs) != len(xobs) @@ -259,9 +280,11 @@ def _isobs(a): def setCalculationPoints(self, x): """Set the calculation points. - Arguments - x -- A non-empty numpy array containing the calculation points. If - xobs exists, the bounds of x will be limited to its bounds. + Parameters + ---------- + x + A non-empty numpy array containing the calculation points. If + xobs exists, the bounds of x will be limited to its bounds. This will create y and dy on the specified grid if xobs, yobs and dyobs exist. @@ -391,10 +414,14 @@ def _validate(self): def rebinArray(A, xold, xnew): """Rebin the an array by interpolating over the new x range. - Arguments: - A -- Array to interpolate - xold -- Old sampling array - xnew -- New sampling array + Parameters + ---------- + A + Array to interpolate + xold + Old sampling array + xnew + New sampling array This uses cubic spline interpolation. diff --git a/src/diffpy/srfit/fitbase/profilegenerator.py b/src/diffpy/srfit/fitbase/profilegenerator.py index 2df9916e..92694423 100644 --- a/src/diffpy/srfit/fitbase/profilegenerator.py +++ b/src/diffpy/srfit/fitbase/profilegenerator.py @@ -50,37 +50,60 @@ class ProfileGenerator(Operator, ParameterSet): an evaluation network. Attributes - name -- A name for this organizer. - profile -- A Profile instance that contains the calculation range - and will contain the generated profile. - meta -- A dictionary of metadata needed by the generator. - eq -- The Equation object used to wrap this ProfileGenerator. - This is set when the ProfileGenerator is added to a - FitContribution. - _calculators -- A managed dictionary of Calculators, indexed by name. - _constraints -- A set of constrained Parameters. Constraints can be - added using the 'constrain' methods. - _parameters -- A managed OrderedDict of contained Parameters. - _parsets -- A managed dictionary of ParameterSets. - _restraints -- A set of Restraints. Restraints can be added using the - 'restrain' or 'confine' methods. - _eqfactory -- A diffpy.srfit.equation.builder.EquationFactory - instance that is used create Equations from string. + ---------- + name + A name for this organizer. + profile + A Profile instance that contains the calculation range + and will contain the generated profile. + meta + A dictionary of metadata needed by the generator. + eq + The Equation object used to wrap this ProfileGenerator. + This is set when the ProfileGenerator is added to a + FitContribution. + _calculators + A managed dictionary of Calculators, indexed by name. + _constraints + A set of constrained Parameters. Constraints can be + added using the 'constrain' methods. + _parameters + A managed OrderedDict of contained Parameters. + _parsets + A managed dictionary of ParameterSets. + _restraints + A set of Restraints. Restraints can be added using the + 'restrain' or 'confine' methods. + _eqfactory + A diffpy.srfit.equation.builder.EquationFactory + instance that is used create Equations from string. Operator Attributes - args -- List of Literal arguments, set with 'addLiteral' - name -- A name for this operator. e.g. "add" or "sin" - nin -- Number of inputs (<1 means this is variable) - nout -- Number of outputs - operation -- Function that performs the operation. e.g. numpy.add. In - this case, operation is an instance method. - symbol -- The symbolic representation. e.g. "+" or "sin" - _value -- The value of the Operator. - value -- Property for 'getValue'. + ------------------- + args + List of Literal arguments, set with 'addLiteral' + name + A name for this operator. e.g. "add" or "sin" + nin + Number of inputs (<1 means this is variable) + nout + Number of outputs + operation + Function that performs the operation. e.g. numpy.add. In + this case, operation is an instance method. + symbol + The symbolic representation. e.g. "+" or "sin" + _value + The value of the Operator. + value + Property for 'getValue'. Properties - names -- Variable names (read only). See getNames. - values -- Variable values (read only). See getValues. + ---------- + names + Variable names (read only). See getNames. + values + Variable values (read only). See getValues. """ # define abstract attributes from the Operator base. @@ -124,8 +147,11 @@ def operation(self): def setProfile(self, profile): """Assign the profile. - profile -- A Profile that specifies the calculation points and which - will store the calculated signal. + Attributes + ---------- + profile + A Profile that specifies the calculation points and which + will store the calculated signal. """ if self.profile is not None: self.profile.removeObserver(self._flush) diff --git a/src/diffpy/srfit/fitbase/profileparser.py b/src/diffpy/srfit/fitbase/profileparser.py index fd2d8d04..1f4ef1fc 100644 --- a/src/diffpy/srfit/fitbase/profileparser.py +++ b/src/diffpy/srfit/fitbase/profileparser.py @@ -31,34 +31,52 @@ class ProfileParser(object): Attributes - _format -- Name of the data format that this parses (string, default - ""). The format string is a unique identifier for the data - format handled by the parser. - _banks -- The data from each bank. Each bank contains a (x, y, dx, - dy) - tuple: - x -- A numpy array containing the independent - variable read from the file. - y -- A numpy array containing the profile - from the file. - dx -- A numpy array containing the uncertainty in x - read from the file. This is None if the - uncertainty cannot be read. - dy -- A numpy array containing the uncertainty read - from the file. This is None if the uncertainty - cannot be read. - _x -- Independent variable from the chosen bank - _y -- Profile from the chosen bank - _dx -- Uncertainty in independent variable from the chosen bank - _dy -- Uncertainty in profile from the chosen bank - _meta -- A dictionary containing metadata read from the file. + Attributes + ---------- + _format + Name of the data format that this parses (string, default + ""). The format string is a unique identifier for the data + format handled by the parser. + _banks + The data from each bank. Each bank contains a (x, y, dx, + dy) + tuple: + x + A numpy array containing the independent + variable read from the file. + y + A numpy array containing the profile + from the file. + dx + A numpy array containing the uncertainty in x + read from the file. This is None if the + uncertainty cannot be read. + dy + A numpy array containing the uncertainty read + from the file. This is None if the uncertainty + cannot be read. + _x + Independent variable from the chosen bank + _y + Profile from the chosen bank + _dx + Uncertainty in independent variable from the chosen bank + _dy + Uncertainty in profile from the chosen bank + _meta + A dictionary containing metadata read from the file. General Metadata - filename -- The name of the file from which data was parsed. This key - will not exist if data was not read from file. - nbanks -- The number of banks parsed. - bank -- The chosen bank number. + Attributes + ---------- + filename + The name of the file from which data was parsed. This key + will not exist if data was not read from file. + nbanks + The number of banks parsed. + bank + The chosen bank number. """ _format = "" @@ -85,8 +103,10 @@ def parseString(self, patstring): This wipes out the currently loaded data and selected bank number. - Arguments - patstring -- A string containing the pattern + Parameters + ---------- + patstring + A string containing the pattern Raises ParseError if the string cannot be parsed """ @@ -97,8 +117,10 @@ def parseFile(self, filename): This wipes out the currently loaded data and selected bank number. - Arguments - filename -- The name of the file to parse + Parameters + ---------- + filename + The name of the file to parse Raises IOError if the file cannot be read Raises ParseError if the file cannot be parsed @@ -129,8 +151,10 @@ def selectBank(self, index): parser is used to parse more data. This uses python list notation, so index -n returns the nth bank from the end. - Arguments: - index -- index of bank (integer, starting at 0). + Parameters + ---------- + index + index of bank (integer, starting at 0). Raises IndexError if requesting a bank that does not exist """ @@ -160,9 +184,11 @@ def getData(self, index=None): parser is used to parse more data. This uses python list notation, so index -n returns the nth bank from the end. - Arguments: - index -- index of bank (integer, starting at 0, default None). If - index is None then the currently selected bank is used. + Parameters + ---------- + index + index of bank (integer, starting at 0, default None). If + index is None then the currently selected bank is used. This returns (x, y, dx, dy) tuple for the bank. dx is 0 if it cannot be determined from the data format. diff --git a/src/diffpy/srfit/fitbase/recipeorganizer.py b/src/diffpy/srfit/fitbase/recipeorganizer.py index ea2641cb..1b14d0a4 100644 --- a/src/diffpy/srfit/fitbase/recipeorganizer.py +++ b/src/diffpy/srfit/fitbase/recipeorganizer.py @@ -66,18 +66,26 @@ class RecipeContainer(Observable, Configurable, Validatable): it may depend. Attributes - name -- A name for this RecipeContainer. Names should be unique - within a RecipeContainer and should be valid attribute - names. - _parameters -- A managed OrderedDict of contained Parameters. - __managed -- A list of managed dictionaries. This is used for - attribute access, addition and removal. - _configobjs -- A set of configurable objects that must know of - configuration changes within this object. + ---------- + name + A name for this RecipeContainer. Names should be unique + within a RecipeContainer and should be valid attribute + names. + _parameters + A managed OrderedDict of contained Parameters. + __managed + A list of managed dictionaries. This is used for + attribute access, addition and removal. + _configobjs + A set of configurable objects that must know of + configuration changes within this object. Properties - names -- Variable names (read only). See getNames. - values -- Variable values (read only). See getValues. + ---------- + names + Variable names (read only). See getNames. + values + Variable values (read only). See getValues. """ names = property(lambda self: self.getNames()) @@ -164,7 +172,7 @@ def __getattr__(self, name): ) def __dir__(self): - "Return sorted list of attributes for this object." + """Return sorted list of attributes for this object.""" rv = set(dir(type(self))) rv.update(self.__dict__) # self.get fetches looks up for items in all managed dictionaries. @@ -232,10 +240,15 @@ def getValues(self): def _addObject(self, obj, d, check=True): """Add an object to a managed dictionary. - obj -- The object to be stored. - d -- The managed dictionary to store the object in. - check -- If True (default), a ValueError is raised an object of the - given name already exists. + Attributes + ---------- + obj + The object to be stored. + d + The managed dictionary to store the object in. + check + If True (default), a ValueError is raised an object of the + given name already exists. Raises ValueError if the object has no name. Raises ValueError if the object has the same name as some other managed @@ -295,7 +308,10 @@ def _removeObject(self, obj, d): def _locateManagedObject(self, obj): """Find the location a managed object within the hierarchy. - obj -- The object to find. + Attributes + ---------- + obj + The object to find. Returns a list of objects. The first member of the list is this object, and each subsequent member is a sub-object of the previous one. The @@ -359,22 +375,32 @@ class RecipeOrganizer(_recipeorganizer_interface, RecipeContainer): _getConstraints and _getRestraints methods. Attributes - name -- A name for this organizer. Names should be unique - within a RecipeOrganizer and should be valid attribute - names. - _calculators -- A managed dictionary of Calculators, indexed by name. - _parameters -- A managed OrderedDict of contained Parameters. - _constraints -- A dictionary of Constraints, indexed by the constrained - Parameter. Constraints can be added using the - 'constrain' method. - _restraints -- A set of Restraints. Restraints can be added using the - 'restrain' method. - _eqfactory -- A diffpy.srfit.equation.builder.EquationFactory - instance that is used create Equations from string. + ---------- + name + A name for this organizer. Names should be unique + within a RecipeOrganizer and should be valid attribute + names. + _calculators + A managed dictionary of Calculators, indexed by name. + _parameters + A managed OrderedDict of contained Parameters. + _constraints + A dictionary of Constraints, indexed by the constrained + Parameter. Constraints can be added using the + 'constrain' method. + _restraints + A set of Restraints. Restraints can be added using the + 'restrain' method. + _eqfactory + A diffpy.srfit.equation.builder.EquationFactory + instance that is used create Equations from string. Properties - names -- Variable names (read only). See getNames. - values -- Variable values (read only). See getValues. + ---------- + names + Variable names (read only). See getNames. + values + Variable values (read only). See getValues. Raises ValueError if the name is not a valid attribute identifier """ @@ -408,9 +434,13 @@ def _addParameter(self, par, check=True): Parameters added in this way are registered with the _eqfactory. - par -- The Parameter to be stored. - check -- If True (default), a ValueError is raised a Parameter of - the specified name has already been inserted. + Attributes + ---------- + par + The Parameter to be stored. + check + If True (default), a ValueError is raised a Parameter of + the specified name has already been inserted. Raises ValueError if the Parameter has no name. Raises ValueError if the Parameter has the same name as a contained @@ -448,10 +478,14 @@ def registerCalculator(self, f, argnames=None): arguments like a function or without, in which case the values of the Parameters created from argnames will be be used to compute the value. - f -- The Calculator to register. - argnames -- The names of the arguments to f (list or None). - If this is None, then the argument names will be - extracted from the function. + Attributes + ---------- + f + The Calculator to register. + argnames + The names of the arguments to f (list or None). + If this is None, then the argument names will be + extracted from the function. """ self._eqfactory.registerOperator(f.name, f) self._addObject(f, self._calculators) @@ -479,14 +513,19 @@ def registerFunction(self, f, name=None, argnames=None): equations. The resulting equation does not require the arguments to be passed in the equation string, as this will be handled automatically. - f -- The callable to register. If this is an Equation - instance, then all that needs to be provided is a name. - name -- The name of the function to be used in equations. If - this is None (default), the method will try to - determine the name of the function automatically. - argnames -- The names of the arguments to f (list or None). - If this is None (default), then the argument names will - be extracted from the function. + Attributes + ---------- + f + The callable to register. If this is an Equation + instance, then all that needs to be provided is a name. + name + The name of the function to be used in equations. If + this is None (default), the method will try to + determine the name of the function automatically. + argnames + The names of the arguments to f (list or None). + If this is None (default), then the argument names will + be extracted from the function. Note that name and argnames can be extracted from regular python functions (of type 'function'), bound class methods and callable @@ -578,11 +617,16 @@ def registerStringFunction(self, fstr, name, ns={}): equations. The resulting equation does not require the arguments to be passed in the function string, as this will be handled automatically. - fstr -- A string equation to register. - name -- The name of the function to be used in equations. - ns -- A dictionary of Parameters, indexed by name, that are - used in fstr, but not part of the FitRecipe (default - {}). + Attributes + ---------- + fstr + A string equation to register. + name + The name of the function to be used in equations. + ns + A dictionary of Parameters, indexed by name, that are + used in fstr, but not part of the FitRecipe (default + {}). Raises ValueError if ns uses a name that is already used for another managed object. @@ -607,10 +651,14 @@ def registerStringFunction(self, fstr, name, ns={}): def evaluateEquation(self, eqstr, ns={}): """Evaluate a string equation. - eqstr -- A string equation to evaluate. The equation is evaluated at - the current value of the registered Parameters. - ns -- A dictionary of Parameters, indexed by name, that are - used in fstr, but not part of the FitRecipe (default {}). + Attributes + ---------- + eqstr + A string equation to evaluate. The equation is evaluated at + the current value of the registered Parameters. + ns + A dictionary of Parameters, indexed by name, that are + used in fstr, but not part of the FitRecipe (default {}). Raises ValueError if ns uses a name that is already used for a variable. @@ -627,14 +675,19 @@ def constrain(self, par, con, ns={}): Note that only one constraint can exist on a Parameter at a time. - par -- The name of a Parameter or a Parameter to constrain. - con -- A string representation of the constraint equation or a - Parameter to constrain to. A constraint equation must - consist of numpy operators and "known" Parameters. - Parameters are known if they are in the ns argument, or if - they are managed by this object. - ns -- A dictionary of Parameters, indexed by name, that are used - in the parameter, but not part of this object (default {}). + Attributes + ---------- + par + The name of a Parameter or a Parameter to constrain. + con + A string representation of the constraint equation or a + Parameter to constrain to. A constraint equation must + consist of numpy operators and "known" Parameters. + Parameters are known if they are in the ns argument, or if + they are managed by this object. + ns + A dictionary of Parameters, indexed by name, that are used + in the parameter, but not part of this object (default {}). Raises ValueError if ns uses a name that is already used for a variable. @@ -678,7 +731,10 @@ def constrain(self, par, con, ns={}): def isConstrained(self, par): """Determine if a Parameter is constrained in this object. - par -- The name of a Parameter or a Parameter to check. + Attributes + ---------- + par + The name of a Parameter or a Parameter to check. """ if isinstance(par, six.string_types): name = par @@ -691,7 +747,10 @@ def unconstrain(self, *pars): This removes any constraints on a Parameter. - *pars -- The names of Parameters or Parameters to unconstrain. + Attributes + ---------- + *pars + The names of Parameters or Parameters to unconstrain. Raises ValueError if the Parameter is not constrained. @@ -723,8 +782,11 @@ def unconstrain(self, *pars): def getConstrainedPars(self, recurse=False): """Get a list of constrained managed Parameters in this object. - recurse -- Recurse into managed objects and retrieve their constrained - Parameters as well (default False). + Attributes + ---------- + recurse + Recurse into managed objects and retrieve their constrained + Parameters as well (default False). """ const = self._getConstraints(recurse) return const.keys() @@ -732,8 +794,11 @@ def getConstrainedPars(self, recurse=False): def clearConstraints(self, recurse=False): """Clear all constraints managed by this organizer. - recurse -- Recurse into managed objects and clear all constraints - found there as well. + Attributes + ---------- + recurse + Recurse into managed objects and clear all constraints + found there as well. This removes constraints that are held in this organizer, no matter where the constrained parameters are from. @@ -749,16 +814,24 @@ def clearConstraints(self, recurse=False): def restrain(self, res, lb=-inf, ub=inf, sig=1, scaled=False, ns={}): """Restrain an expression to specified bounds. - res -- An equation string or Parameter to restrain. - lb -- The lower bound on the restraint evaluation (default -inf). - ub -- The lower bound on the restraint evaluation (default inf). - sig -- The uncertainty on the bounds (default 1). - scaled -- A flag indicating if the restraint is scaled (multiplied) - by the unrestrained point-average chi^2 (chi^2/numpoints) - (default False). - ns -- A dictionary of Parameters, indexed by name, that are used - in the equation string, but not part of the RecipeOrganizer - (default {}). + Attributes + ---------- + res + An equation string or Parameter to restrain. + lb + The lower bound on the restraint evaluation (default -inf). + ub + The lower bound on the restraint evaluation (default inf). + sig + The uncertainty on the bounds (default 1). + scaled + A flag indicating if the restraint is scaled (multiplied) + by the unrestrained point-average chi^2 (chi^2/numpoints) + (default False). + ns + A dictionary of Parameters, indexed by name, that are used + in the equation string, but not part of the RecipeOrganizer + (default {}). The penalty is calculated as (max(0, lb - val, val - ub)/sig)**2 @@ -789,7 +862,10 @@ def restrain(self, res, lb=-inf, ub=inf, sig=1, scaled=False, ns={}): def addRestraint(self, res): """Add a Restraint instance to the RecipeOrganizer. - res -- A Restraint instance. + Attributes + ---------- + res + A Restraint instance. """ self._restraints.add(res) # Our configuration changed. Notify observers. @@ -799,8 +875,11 @@ def addRestraint(self, res): def unrestrain(self, *ress): """Remove a Restraint from the RecipeOrganizer. - *ress -- Restraints returned from the 'restrain' method or added - with the 'addRestraint' method. + Attributes + ---------- + *ress + Restraints returned from the 'restrain' method or added + with the 'addRestraint' method. """ update = False restuple = tuple(self._restraints) @@ -818,8 +897,11 @@ def unrestrain(self, *ress): def clearRestraints(self, recurse=False): """Clear all restraints. - recurse -- Recurse into managed objects and clear all restraints - found there as well. + Attributes + ---------- + recurse + Recurse into managed objects and clear all restraints + found there as well. """ self.unrestrain(*self._restraints) if recurse: @@ -1014,21 +1096,29 @@ def equationFromString( ): """Make an equation from a string. - eqstr -- A string representation of the equation. The equation must - consist of numpy operators and "known" Parameters. Parameters - are known if they are in ns, or already defined in the factory. - factory -- An EquationFactory instance. - ns -- A dictionary of Parameters indexed by name that are used - in the eqstr but not already defined in the factory - (default {}). - buildargs -- A flag indicating whether missing Parameters can be created - by the Factory (default False). If False, then the a ValueError - will be raised if there are undefined arguments in the eqstr. - argclass -- Class to use when creating new Arguments (default - Parameter). The class constructor must accept the 'name' key - word. - argkw -- Key word dictionary to pass to the argclass constructor - (default {}). + Attributes + ---------- + eqstr + A string representation of the equation. The equation must + consist of numpy operators and "known" Parameters. Parameters + are known if they are in ns, or already defined in the factory. + factory + An EquationFactory instance. + ns + A dictionary of Parameters indexed by name that are used + in the eqstr but not already defined in the factory + (default {}). + buildargs + A flag indicating whether missing Parameters can be created + by the Factory (default False). If False, then the a ValueError + will be raised if there are undefined arguments in the eqstr. + argclass + Class to use when creating new Arguments (default + Parameter). The class constructor must accept the 'name' key + word. + argkw + Key word dictionary to pass to the argclass constructor + (default {}). Raises ValueError if ns uses a name that is already defined in the factory. Raises ValueError if the equation has undefined parameters. diff --git a/src/diffpy/srfit/fitbase/restraint.py b/src/diffpy/srfit/fitbase/restraint.py index f7f2da3c..f7e68bbe 100644 --- a/src/diffpy/srfit/fitbase/restraint.py +++ b/src/diffpy/srfit/fitbase/restraint.py @@ -32,14 +32,20 @@ class Restraint(Validatable): """Restraint class. Attributes - eq -- An equation whose evaluation is compared against the restraint - bounds. - lb -- The lower bound on the restraint evaluation (default -inf). - ub -- The lower bound on the restraint evaluation (default inf). - sig -- The uncertainty on the bounds (default 1). - scaled -- A flag indicating if the restraint is scaled (multiplied) by - the unrestrained point-average chi^2 (chi^2/numpoints) - (default False). + ---------- + eq + An equation whose evaluation is compared against the restraint + bounds. + lb + The lower bound on the restraint evaluation (default -inf). + ub + The lower bound on the restraint evaluation (default inf). + sig + The uncertainty on the bounds (default 1). + scaled + A flag indicating if the restraint is scaled (multiplied) by + the unrestrained point-average chi^2 (chi^2/numpoints) + (default False). The penalty is calculated as (max(0, lb - val, val - ub)/sig)**2 @@ -50,16 +56,23 @@ class Restraint(Validatable): def __init__(self, eq, lb=-inf, ub=inf, sig=1, scaled=False): """Restrain an equation to specified bounds. - eq -- An equation whose evaluation is compared against the - restraint bounds. - lb -- The lower bound on the restraint evaluation (float, default - -inf). - ub -- The lower bound on the restraint evaluation (float, default - inf). - sig -- The uncertainty on the bounds (default 1). - scaled -- A flag indicating if the restraint is scaled (multiplied) - by the unrestrained point-average chi^2 (chi^2/numpoints) - (bool, default False). + Attributes + ---------- + eq + An equation whose evaluation is compared against the + restraint bounds. + lb + The lower bound on the restraint evaluation (float, default + -inf). + ub + The lower bound on the restraint evaluation (float, default + inf). + sig + The uncertainty on the bounds (default 1). + scaled + A flag indicating if the restraint is scaled (multiplied) + by the unrestrained point-average chi^2 (chi^2/numpoints) + (bool, default False). """ self.eq = eq self.lb = float(lb) @@ -71,8 +84,11 @@ def __init__(self, eq, lb=-inf, ub=inf, sig=1, scaled=False): def penalty(self, w=1.0): """Calculate the penalty of the restraint. - w -- The point-average chi^2 which is optionally used to scale the - penalty (default 1.0). + Attributes + ---------- + w + The point-average chi^2 which is optionally used to scale the + penalty (default 1.0). Returns the penalty as a float """ diff --git a/src/diffpy/srfit/fitbase/simplerecipe.py b/src/diffpy/srfit/fitbase/simplerecipe.py index 2f454fd2..77b361cc 100644 --- a/src/diffpy/srfit/fitbase/simplerecipe.py +++ b/src/diffpy/srfit/fitbase/simplerecipe.py @@ -29,40 +29,62 @@ class SimpleRecipe(FitRecipe): fit recipe. Attributes - profile -- The built-in Profile object. - contribution -- The built-in FitContribution object. - results -- The built-in FitResults object. - name -- A name for this FitRecipe. - fithook -- An object to be called whenever within the residual - (default FitHook()) that can pass information out of - the system during a refinement. - _constraints -- A dictionary of Constraints, indexed by the constrained - Parameter. Constraints can be added using the - 'constrain' method. - _oconstraints -- An ordered list of the constraints from this and all - sub-components. - _calculators -- A managed dictionary of Calculators. - _contributions -- A managed OrderedDict of FitContributions. - _parameters -- A managed OrderedDict of parameters (in this case the - parameters are varied). - _parsets -- A managed dictionary of ParameterSets. - _eqfactory -- A diffpy.srfit.equation.builder.EquationFactory - instance that is used to create constraints and - restraints from string - _fixed -- A set of parameters that are not actually varied. - _restraintlist -- A list of restraints from this and all sub-components. - _restraints -- A set of Restraints. Restraints can be added using the - 'restrain' or 'confine' methods. - _ready -- A flag indicating if all attributes are ready for the - calculation. - _tagdict -- A dictionary of tags to variables. - _weights -- List of weighing factors for each FitContribution. The - weights are multiplied by the residual of the - FitContribution when determining the overall residual. + ---------- + profile + The built-in Profile object. + contribution + The built-in FitContribution object. + results + The built-in FitResults object. + name + A name for this FitRecipe. + fithook + An object to be called whenever within the residual + (default FitHook()) that can pass information out of + the system during a refinement. + _constraints + A dictionary of Constraints, indexed by the constrained + Parameter. Constraints can be added using the + 'constrain' method. + _oconstraints + An ordered list of the constraints from this and all + sub-components. + _calculators + A managed dictionary of Calculators. + _contributions + A managed OrderedDict of FitContributions. + _parameters + A managed OrderedDict of parameters (in this case the + parameters are varied). + _parsets + A managed dictionary of ParameterSets. + _eqfactory + A diffpy.srfit.equation.builder.EquationFactory + instance that is used to create constraints and + restraints from string + _fixed + A set of parameters that are not actually varied. + _restraintlist + A list of restraints from this and all sub-components. + _restraints + A set of Restraints. Restraints can be added using the + 'restrain' or 'confine' methods. + _ready + A flag indicating if all attributes are ready for the + calculation. + _tagdict + A dictionary of tags to variables. + _weights + List of weighing factors for each FitContribution. The + weights are multiplied by the residual of the + FitContribution when determining the overall residual. Properties - names -- Variable names (read only). See getNames. - values -- Variable values (read only). See getValues. + ---------- + names + Variable names (read only). See getNames. + values + Variable values (read only). See getValues. """ def __init__(self, name="fit", conclass=FitContribution): @@ -97,12 +119,16 @@ def loadParsedData(self, parser): def setObservedProfile(self, xobs, yobs, dyobs=None): """Set the observed profile. - Arguments - xobs -- Numpy array of the independent variable - yobs -- Numpy array of the observed signal. - dyobs -- Numpy array of the uncertainty in the observed signal. If - dyobs is None (default), it will be set to 1 at each - observed xobs. + Parameters + ---------- + xobs + Numpy array of the independent variable + yobs + Numpy array of the observed signal. + dyobs + Numpy array of the uncertainty in the observed signal. If + dyobs is None (default), it will be set to 1 at each + observed xobs. Raises ValueError if len(yobs) != len(xobs) Raises ValueError if dyobs != None and len(dyobs) != len(xobs) @@ -146,9 +172,11 @@ def setCalculationRange(self, xmin=None, xmax=None, dx=None): def setCalculationPoints(self, x): """Set the calculation points. - Arguments - x -- A non-empty numpy array containing the calculation points. If - xobs exists, the bounds of x will be limited to its bounds. + Parameters + ---------- + x + A non-empty numpy array containing the calculation points. If + xobs exists, the bounds of x will be limited to its bounds. This will create y and dy on the specified grid if xobs, yobs and dyobs exist. @@ -179,11 +207,15 @@ def setEquation(self, eqstr, ns={}): The equation will be usable within setResidualEquation as "eq", and it takes no arguments. - eqstr -- A string representation of the equation. Variables will be - extracted from this equation and be given an initial value - of 0. - ns -- A dictionary of Parameters, indexed by name, that are used - in the eqstr, but not registered (default {}). + Attributes + ---------- + eqstr + A string representation of the equation. Variables will be + extracted from this equation and be given an initial value + of 0. + ns + A dictionary of Parameters, indexed by name, that are used + in the eqstr, but not registered (default {}). Raises ValueError if ns uses a name that is already used for a variable. @@ -209,8 +241,12 @@ def __call__(self): def printResults(self, header="", footer=""): """Format and print the results. - header -- A header to add to the output (default "") - footer -- A footer to add to the output (default "") + Attributes + ---------- + header + A header to add to the output (default "") + footer + A footer to add to the output (default "") """ self.results.printResults(header, footer, True) return @@ -219,8 +255,11 @@ def saveResults(self, filename, header="", footer=""): """Format and save the results. filename - Name of the save file. - header -- A header to add to the output (default "") - footer -- A footer to add to the output (default "") + ---------------------------------- + header + A header to add to the output (default "") + footer + A footer to add to the output (default "") """ self.results.saveResults(filename, header, footer, True) diff --git a/src/diffpy/srfit/interface/interface.py b/src/diffpy/srfit/interface/interface.py index c9f67c57..a0b7a21a 100644 --- a/src/diffpy/srfit/interface/interface.py +++ b/src/diffpy/srfit/interface/interface.py @@ -40,7 +40,10 @@ def __lshift__(self, v): Think of '<<' as injecting a value - v -- value or Argument derivative + Attributes + ---------- + v + value or Argument derivative """ if isinstance(v, ArgumentABC): self.value = v.value diff --git a/src/diffpy/srfit/pdf/basepdfgenerator.py b/src/diffpy/srfit/pdf/basepdfgenerator.py index 3fd58805..ed4b8b99 100644 --- a/src/diffpy/srfit/pdf/basepdfgenerator.py +++ b/src/diffpy/srfit/pdf/basepdfgenerator.py @@ -38,38 +38,59 @@ class BasePDFGenerator(ProfileGenerator): pyobjcryst.molecule.Molecule instances. Note that the managed Parameters are not created until the structure is added. - Attributes: - _calc -- PDFCalculator or DebyePDFCalculator instance for calculating - the PDF. - _phase -- The structure ParameterSet used to calculate the profile. - stru -- The structure objected adapted by _phase. - _lastr -- The last value of r over which the PDF was calculated. This is - used to configure the calculator when r changes. - _pool -- A multiprocessing.Pool for managing parallel computation. - - Managed Parameters: - scale -- Scale factor - delta1 -- Linear peak broadening term - delta2 -- Quadratic peak broadening term - qbroad -- Resolution peak broadening term - qdamp -- Resolution peak dampening term + Attributes + ---------- + _calc + PDFCalculator or DebyePDFCalculator instance for calculating + the PDF. + _phase + The structure ParameterSet used to calculate the profile. + stru + The structure objected adapted by _phase. + _lastr + The last value of r over which the PDF was calculated. This is + used to configure the calculator when r changes. + _pool + A multiprocessing.Pool for managing parallel computation. + + Managed Parameters + ------------------ + scale + Scale factor + delta1 + Linear peak broadening term + delta2 + Quadratic peak broadening term + qbroad + Resolution peak broadening term + qdamp + Resolution peak dampening term Managed ParameterSets: The structure ParameterSet (SrRealParSet instance) used to calculate the profile is named by the user. - Usable Metadata: - stype -- The scattering type "X" for x-ray, "N" for neutron (see - 'setScatteringType'). - qmax -- The maximum scattering vector used to generate the PDF (see - setQmax). - qmin -- The minimum scattering vector used to generate the PDF (see - setQmin). - scale -- See Managed Parameters. - delta1 -- See Managed Parameters. - delta2 -- See Managed Parameters. - qbroad -- See Managed Parameters. - qdamp -- See Managed Parameters. + Usable Metadata + --------------- + stype + The scattering type "X" for x-ray, "N" for neutron (see + 'setScatteringType'). + qmax + The maximum scattering vector used to generate the PDF (see + setQmax). + qmin + The minimum scattering vector used to generate the PDF (see + setQmin). + scale + See Managed Parameters. + delta1 + See Managed Parameters. + delta2 + See Managed Parameters. + qbroad + See Managed Parameters. + qdamp + See Managed Parameters. """ def __init__(self, name="pdf"): @@ -103,9 +124,13 @@ def _setCalculator(self, calc): def parallel(self, ncpu, mapfunc=None): """Run calculation in parallel. - ncpu -- Number of parallel processes. Revert to serial mode when 1. - mapfunc -- A mapping function to use. If this is None (default), - multiprocessing.Pool.imap_unordered will be used. + Attributes + ---------- + ncpu + Number of parallel processes. Revert to serial mode when 1. + mapfunc + A mapping function to use. If this is None (default), + multiprocessing.Pool.imap_unordered will be used. No return value. """ @@ -157,9 +182,12 @@ def processMetaData(self): def setScatteringType(self, stype="X"): """Set the scattering type. - stype -- "X" for x-ray, "N" for neutron, "E" for electrons, - or any registered type from diffpy.srreal from - ScatteringFactorTable.getRegisteredTypes(). + Attributes + ---------- + stype + "X" for x-ray, "N" for neutron, "E" for electrons, + or any registered type from diffpy.srreal from + ScatteringFactorTable.getRegisteredTypes(). Raises ValueError for unknown scattering type. """ @@ -203,14 +231,19 @@ def setStructure(self, stru, name="phase", periodic=True): See those classes (located in diffpy.srfit.structure) for how they are used. The resulting ParameterSet will be managed by this generator. - stru -- diffpy.structure.Structure, pyobjcryst.crystal.Crystal or - pyobjcryst.molecule.Molecule instance. Default None. - name -- A name to give to the managed ParameterSet that adapts stru - (default "phase"). - periodic -- The structure should be treated as periodic (default - True). Note that some structures do not support - periodicity, in which case this will have no effect on the - PDF calculation. + Attributes + ---------- + stru + diffpy.structure.Structure, pyobjcryst.crystal.Crystal or + pyobjcryst.molecule.Molecule instance. Default None. + name + A name to give to the managed ParameterSet that adapts stru + (default "phase"). + periodic + The structure should be treated as periodic (default + True). Note that some structures do not support + periodicity, in which case this will have no effect on the + PDF calculation. """ # Create the ParameterSet @@ -228,13 +261,17 @@ def setPhase(self, parset, periodic=True): object (from diffpy or pyobjcryst). The passed ParameterSet will be managed by this generator. - parset -- A SrRealParSet that holds the structural information. - This can be used to share the phase between multiple - BasePDFGenerators, and have the changes in one reflect in - another. - periodic -- The structure should be treated as periodic (default True). - Note that some structures do not support periodicity, in - which case this will be ignored. + Attributes + ---------- + parset + A SrRealParSet that holds the structural information. + This can be used to share the phase between multiple + BasePDFGenerators, and have the changes in one reflect in + another. + periodic + The structure should be treated as periodic (default True). + Note that some structures do not support periodicity, in + which case this will be ignored. """ # Store the ParameterSet for easy access self._phase = parset diff --git a/src/diffpy/srfit/pdf/characteristicfunctions.py b/src/diffpy/srfit/pdf/characteristicfunctions.py index a8718e57..504d103d 100644 --- a/src/diffpy/srfit/pdf/characteristicfunctions.py +++ b/src/diffpy/srfit/pdf/characteristicfunctions.py @@ -47,8 +47,12 @@ def sphericalCF(r, psize): """Spherical nanoparticle characteristic function. - r -- distance of interaction - psize -- The particle diameter + Attributes + ---------- + r + distance of interaction + psize + The particle diameter From Kodama et al., Acta Cryst. A, 62, 444-453 (converted from radius to diameter) @@ -67,8 +71,12 @@ def spheroidalCF(r, erad, prad): Spheroid with radii (erad, erad, prad) - prad -- polar radius - erad -- equatorial radius + Attributes + ---------- + prad + polar radius + erad + equatorial radius erad < prad equates to a prolate spheroid erad > prad equates to a oblate spheroid @@ -84,9 +92,14 @@ def spheroidalCF2(r, psize, axrat): Form factor for ellipsoid with radii (psize/2, psize/2, axrat*psize/2) - r -- distance of interaction - psize -- The equatorial diameter - axrat -- The ratio of axis lengths + Attributes + ---------- + r + distance of interaction + psize + The equatorial diameter + axrat + The ratio of axis lengths From Lei et al., Phys. Rev. B, 80, 024118 (2009) """ @@ -189,9 +202,14 @@ def lognormalSphericalCF(r, psize, psig): """Spherical nanoparticle characteristic function with lognormal size distribution. - r -- distance of interaction - psize -- The mean particle diameter - psig -- The log-normal width of the particle diameter + Attributes + ---------- + r + distance of interaction + psize + The mean particle diameter + psig + The log-normal width of the particle diameter Here, r is the independent variable, mu is the mean of the distribution (not of the particle size), and s is the width of the distribution. This is @@ -240,8 +258,12 @@ def lognormalSphericalCF(r, psize, psig): def sheetCF(r, sthick): """Nanosheet characteristic function. - r -- distance of interaction - sthick -- Thickness of nanosheet + Attributes + ---------- + r + distance of interaction + sthick + Thickness of nanosheet From Kodama et al., Acta Cryst. A, 62, 444-453 """ @@ -265,8 +287,12 @@ def sheetCF(r, sthick): def shellCF(r, radius, thickness): """Spherical shell characteristic function. - radius -- Inner radius - thickness -- Thickness of shell + Attributes + ---------- + radius + Inner radius + thickness + Thickness of shell outer radius = radius + thickness @@ -280,8 +306,12 @@ def shellCF(r, radius, thickness): def shellCF2(r, a, delta): """Spherical shell characteristic function. - a -- Central radius - delta -- Thickness of shell + Attributes + ---------- + a + Central radius + delta + Thickness of shell outer radius = a + thickness/2 @@ -325,8 +355,10 @@ class SASCF(Calculator): f(r) = 1 / (4 pi r) * SINFT(I(Q)), where "SINFT" represents the sine Fourier transform. - Attributes: - _model -- BaseModel object this adapts. + Attributes + ---------- + _model + BaseModel object this adapts. Managed Parameters: These depend on the parameters of the BaseModel object held by _model. They @@ -339,8 +371,12 @@ class SASCF(Calculator): def __init__(self, name, model): """Initialize the generator. - name -- A name for the SASCF - model -- SASModel object this adapts. + Attributes + ---------- + name + A name for the SASCF + model + SASModel object this adapts. """ Calculator.__init__(self, name) diff --git a/src/diffpy/srfit/pdf/debyepdfgenerator.py b/src/diffpy/srfit/pdf/debyepdfgenerator.py index e83e2026..1d182c73 100644 --- a/src/diffpy/srfit/pdf/debyepdfgenerator.py +++ b/src/diffpy/srfit/pdf/debyepdfgenerator.py @@ -32,36 +32,56 @@ class DebyePDFGenerator(BasePDFGenerator): pyobjcryst.molecule.Molecule instances. Note that the managed Parameters are not created until the structure is added. - Attributes: - _calc -- DebyePDFCalculator instance for calculating the PDF - _phase -- The structure ParameterSets used to calculate the profile. - stru -- The structure objected adapted by _phase. - _lastr -- The last value of r over which the PDF was calculated. This is - used to configure the calculator when r changes. - - Managed Parameters: - scale -- Scale factor - delta1 -- Linear peak broadening term - delta2 -- Quadratic peak broadening term - qbroad -- Resolution peak broadening term - qdamp -- Resolution peak dampening term + Attributes + ---------- + _calc + DebyePDFCalculator instance for calculating the PDF + _phase + The structure ParameterSets used to calculate the profile. + stru + The structure objected adapted by _phase. + _lastr + The last value of r over which the PDF was calculated. This is + used to configure the calculator when r changes. + + Managed Parameters + ------------------ + scale + Scale factor + delta1 + Linear peak broadening term + delta2 + Quadratic peak broadening term + qbroad + Resolution peak broadening term + qdamp + Resolution peak dampening term Managed ParameterSets: The structure ParameterSet (SrRealStructure instance) used to calculate the profile is named by the user. - Usable Metadata: - stype -- The scattering type "X" for x-ray, "N" for neutron (see - 'setScatteringType'). - qmax -- The maximum scattering vector used to generate the PDF (see - setQmax). - qmin -- The minimum scattering vector used to generate the PDF (see - setQmin). - scale -- See Managed Parameters. - delta1 -- See Managed Parameters. - delta2 -- See Managed Parameters. - qbroad -- See Managed Parameters. - qdamp -- See Managed Parameters. + Usable Metadata + --------------- + stype + The scattering type "X" for x-ray, "N" for neutron (see + 'setScatteringType'). + qmax + The maximum scattering vector used to generate the PDF (see + setQmax). + qmin + The minimum scattering vector used to generate the PDF (see + setQmin). + scale + See Managed Parameters. + delta1 + See Managed Parameters. + delta2 + See Managed Parameters. + qbroad + See Managed Parameters. + qdamp + See Managed Parameters. """ def setStructure(self, stru, name="phase", periodic=False): @@ -72,14 +92,19 @@ def setStructure(self, stru, name="phase", periodic=False): See those classes (located in diffpy.srfit.structure) for how they are used. The resulting ParameterSet will be managed by this generator. - stru -- diffpy.structure.Structure, pyobjcryst.crystal.Crystal or - pyobjcryst.molecule.Molecule instance. Default None. - name -- A name to give to the managed ParameterSet that adapts stru - (default "phase"). - periodic -- The structure should be treated as periodic (default - False). Note that some structures do not support - periodicity, in which case this will have no effect on the - PDF calculation. + Attributes + ---------- + stru + diffpy.structure.Structure, pyobjcryst.crystal.Crystal or + pyobjcryst.molecule.Molecule instance. Default None. + name + A name to give to the managed ParameterSet that adapts stru + (default "phase"). + periodic + The structure should be treated as periodic (default + False). Note that some structures do not support + periodicity, in which case this will have no effect on the + PDF calculation. """ return BasePDFGenerator.setStructure(self, stru, name, periodic) @@ -91,13 +116,17 @@ def setPhase(self, parset, periodic=False): object (from diffpy or pyobjcryst). The passed ParameterSet will be managed by this generator. - parset -- A SrRealParSet that holds the structural information. - This can be used to share the phase between multiple - BasePDFGenerators, and have the changes in one reflect in - another. - periodic -- The structure should be treated as periodic (default True). - Note that some structures do not support periodicity, in - which case this will be ignored. + Attributes + ---------- + parset + A SrRealParSet that holds the structural information. + This can be used to share the phase between multiple + BasePDFGenerators, and have the changes in one reflect in + another. + periodic + The structure should be treated as periodic (default True). + Note that some structures do not support periodicity, in + which case this will be ignored. """ return BasePDFGenerator.setPhase(self, parset, periodic) diff --git a/src/diffpy/srfit/pdf/pdfcontribution.py b/src/diffpy/srfit/pdf/pdfcontribution.py index b6b0740d..0304bd07 100644 --- a/src/diffpy/srfit/pdf/pdfcontribution.py +++ b/src/diffpy/srfit/pdf/pdfcontribution.py @@ -32,39 +32,62 @@ class PDFContribution(FitContribution): attributes (see setPhase). Attributes - name -- A name for this FitContribution. - profile -- A Profile that holds the measured (and calculated) - signal. - _meta -- Metadata dictionary. This is specific to this object, - and not shared with the profile. This is used to record - configuration options, like qmax. - _calculators -- A managed dictionary of Calculators, indexed by name. - _constraints -- A set of constrained Parameters. Constraints can be - added using the 'constrain' methods. - _generators -- A managed dictionary of ProfileGenerators. - _parameters -- A managed OrderedDict of parameters. - _restraints -- A set of Restraints. Restraints can be added using the - 'restrain' or 'confine' methods. - _parsets -- A managed dictionary of ParameterSets. - _eqfactory -- A diffpy.srfit.equation.builder.EquationFactory - instance that is used to create constraints and - restraints from string - _eq -- The FitContribution equation that will be optimized. - _reseq -- The residual equation. - _xname -- Name of the x-variable - _yname -- Name of the y-variable - _dyname -- Name of the dy-variable - - Managed Parameters: - scale -- Scale factor - qbroad -- Resolution peak broadening term - qdamp -- Resolution peak dampening term + ---------- + name + A name for this FitContribution. + profile + A Profile that holds the measured (and calculated) + signal. + _meta + Metadata dictionary. This is specific to this object, + and not shared with the profile. This is used to record + configuration options, like qmax. + _calculators + A managed dictionary of Calculators, indexed by name. + _constraints + A set of constrained Parameters. Constraints can be + added using the 'constrain' methods. + _generators + A managed dictionary of ProfileGenerators. + _parameters + A managed OrderedDict of parameters. + _restraints + A set of Restraints. Restraints can be added using the + 'restrain' or 'confine' methods. + _parsets + A managed dictionary of ParameterSets. + _eqfactory + A diffpy.srfit.equation.builder.EquationFactory + instance that is used to create constraints and + restraints from string + _eq + The FitContribution equation that will be optimized. + _reseq + The residual equation. + _xname + Name of the x-variable + _yname + Name of the y-variable + _dyname + Name of the dy-variable + + Managed Parameters + ------------------ + scale + Scale factor + qbroad + Resolution peak broadening term + qdamp + Resolution peak dampening term """ def __init__(self, name): """Create the PDFContribution. - name -- The name of the contribution. + Attributes + ---------- + name + The name of the contribution. """ FitContribution.__init__(self, name) self._meta = {} @@ -88,8 +111,11 @@ def loadData(self, data): This uses the PDFParser to load the data and then passes it to the built-in profile with loadParsedData. - data -- An open file-like object, name of a file that contains data - or a string containing the data. + Attributes + ---------- + data + An open file-like object, name of a file that contains data + or a string containing the data. """ # Get the data into a string from diffpy.srfit.util.inpututils import inputToString @@ -154,21 +180,26 @@ def savetxt(self, fname, **kwargs): def addStructure(self, name, stru, periodic=True): """Add a phase that goes into the PDF calculation. - name -- A name to give the generator that will manage the PDF - calculation from the passed structure. The adapted - structure will be accessible via the name "phase" as an - attribute of the generator, e.g. - contribution.name.phase, where 'contribution' is this - contribution and 'name' is passed name. - (default), then the name will be set as "phase". - stru -- diffpy.structure.Structure, pyobjcryst.crystal.Crystal or - pyobjcryst.molecule.Molecule instance. Default None. - periodic -- The structure should be treated as periodic. If this is - True (default), then a PDFGenerator will be used to - calculate the PDF from the phase. Otherwise, a - DebyePDFGenerator will be used. Note that some structures - do not support periodicity, in which case this may be - ignored. + Attributes + ---------- + name + A name to give the generator that will manage the PDF + calculation from the passed structure. The adapted + structure will be accessible via the name "phase" as an + attribute of the generator, e.g. + contribution.name.phase, where 'contribution' is this + contribution and 'name' is passed name. + (default), then the name will be set as "phase". + stru + diffpy.structure.Structure, pyobjcryst.crystal.Crystal or + pyobjcryst.molecule.Molecule instance. Default None. + periodic + The structure should be treated as periodic. If this is + True (default), then a PDFGenerator will be used to + calculate the PDF from the phase. Otherwise, a + DebyePDFGenerator will be used. Note that some structures + do not support periodicity, in which case this may be + ignored. Returns the new phase (ParameterSet appropriate for what was passed in stru.) @@ -192,22 +223,27 @@ def addStructure(self, name, stru, periodic=True): def addPhase(self, name, parset, periodic=True): """Add a phase that goes into the PDF calculation. - name -- A name to give the generator that will manage the PDF - calculation from the passed parameter phase. The parset - will be accessible via the name "phase" as an attribute - of the generator, e.g., contribution.name.phase, where - 'contribution' is this contribution and 'name' is passed - name. - parset -- A SrRealParSet that holds the structural information. - This can be used to share the phase between multiple - BasePDFGenerators, and have the changes in one reflect in - another. - periodic -- The structure should be treated as periodic. If this is - True (default), then a PDFGenerator will be used to - calculate the PDF from the phase. Otherwise, a - DebyePDFGenerator will be used. Note that some structures - do not support periodicity, in which case this may be - ignored. + Attributes + ---------- + name + A name to give the generator that will manage the PDF + calculation from the passed parameter phase. The parset + will be accessible via the name "phase" as an attribute + of the generator, e.g., contribution.name.phase, where + 'contribution' is this contribution and 'name' is passed + name. + parset + A SrRealParSet that holds the structural information. + This can be used to share the phase between multiple + BasePDFGenerators, and have the changes in one reflect in + another. + periodic + The structure should be treated as periodic. If this is + True (default), then a PDFGenerator will be used to + calculate the PDF from the phase. Otherwise, a + DebyePDFGenerator will be used. Note that some structures + do not support periodicity, in which case this may be + ignored. Returns the new phase (ParameterSet appropriate for what was passed in stru.) @@ -269,7 +305,10 @@ def _getMetaValue(self, kwd): def setScatteringType(self, type="X"): """Set the scattering type. - type -- "X" for x-ray or "N" for neutron + Attributes + ---------- + type + "X" for x-ray or "N" for neutron Raises ValueError if type is not "X" or "N" """ diff --git a/src/diffpy/srfit/pdf/pdfgenerator.py b/src/diffpy/srfit/pdf/pdfgenerator.py index 9b5b1608..f78c799f 100644 --- a/src/diffpy/srfit/pdf/pdfgenerator.py +++ b/src/diffpy/srfit/pdf/pdfgenerator.py @@ -34,35 +34,54 @@ class PDFGenerator(BasePDFGenerator): pyobjcryst.molecule.Molecule instances. Note that the managed Parameters are not created until the structure is added. - Attributes: - _calc -- PDFCalculator instance for calculating the PDF - _phase -- The structure ParameterSet used to calculate the profile. - _lastr -- The last value of r over which the PDF was calculated. This is - used to configure the calculator when r changes. + Attributes + ---------- + _calc + PDFCalculator instance for calculating the PDF + _phase + The structure ParameterSet used to calculate the profile. + _lastr + The last value of r over which the PDF was calculated. This is + used to configure the calculator when r changes. - Managed Parameters: - scale -- Scale factor - delta1 -- Linear peak broadening term - delta2 -- Quadratic peak broadening term - qbroad -- Resolution peak broadening term - qdamp -- Resolution peak dampening term + Managed Parameters + ------------------ + scale + Scale factor + delta1 + Linear peak broadening term + delta2 + Quadratic peak broadening term + qbroad + Resolution peak broadening term + qdamp + Resolution peak dampening term Managed ParameterSets: The structure ParameterSet (SrRealStructure instance) used to calculate the profile is named by the user. - Usable Metadata: - stype -- The scattering type "X" for x-ray, "N" for neutron (see - 'setScatteringType'). - qmax -- The maximum scattering vector used to generate the PDF (see - setQmax). - qmin -- The minimum scattering vector used to generate the PDF (see - setQmin). - scale -- See Managed Parameters. - delta1 -- See Managed Parameters. - delta2 -- See Managed Parameters. - qbroad -- See Managed Parameters. - qdamp -- See Managed Parameters. + Usable Metadata + --------------- + stype + The scattering type "X" for x-ray, "N" for neutron (see + 'setScatteringType'). + qmax + The maximum scattering vector used to generate the PDF (see + setQmax). + qmin + The minimum scattering vector used to generate the PDF (see + setQmin). + scale + See Managed Parameters. + delta1 + See Managed Parameters. + delta2 + See Managed Parameters. + qbroad + See Managed Parameters. + qdamp + See Managed Parameters. """ def __init__(self, name="pdf"): diff --git a/src/diffpy/srfit/pdf/pdfparser.py b/src/diffpy/srfit/pdf/pdfparser.py index d3a617b9..847d7c26 100644 --- a/src/diffpy/srfit/pdf/pdfparser.py +++ b/src/diffpy/srfit/pdf/pdfparser.py @@ -35,45 +35,74 @@ class PDFParser(ProfileParser): Attributes - _format -- Name of the data format that this parses (string, default - ""). The format string is a unique identifier for the data - format handled by the parser. - _banks -- The data from each bank. Each bank contains a - (x, y, dx, dy) tuple: - x -- A numpy array containing the independent - variable read from the file. - y -- A numpy array containing the profile - from the file. - dx -- A numpy array containing the uncertainty in x - read from the file. This is 0 if the - uncertainty cannot be read. - dy -- A numpy array containing the uncertainty read - from the file. This is 0 if the uncertainty - cannot be read. - _x -- Independent variable from the chosen bank - _y -- Profile from the chosen bank - _dx -- Uncertainty in independent variable from the chosen bank - _dy -- Uncertainty in profile from the chosen bank - _meta -- A dictionary containing metadata read from the file. + Attributes + ---------- + _format + Name of the data format that this parses (string, default + ""). The format string is a unique identifier for the data + format handled by the parser. + _banks + The data from each bank. Each bank contains a + (x, y, dx, dy) tuple: + x + A numpy array containing the independent + variable read from the file. + y + A numpy array containing the profile + from the file. + dx + A numpy array containing the uncertainty in x + read from the file. This is 0 if the + uncertainty cannot be read. + dy + A numpy array containing the uncertainty read + from the file. This is 0 if the uncertainty + cannot be read. + _x + Independent variable from the chosen bank + _y + Profile from the chosen bank + _dx + Uncertainty in independent variable from the chosen bank + _dy + Uncertainty in profile from the chosen bank + _meta + A dictionary containing metadata read from the file. General Metadata - filename -- The name of the file from which data was parsed. This key - will not exist if data was not read from file. - nbanks -- The number of banks parsed. - bank -- The chosen bank number. + Attributes + ---------- + filename + The name of the file from which data was parsed. This key + will not exist if data was not read from file. + nbanks + The number of banks parsed. + bank + The chosen bank number. Metadata - These may appear in the metadata dictionary - stype -- The scattering type ("X", "N") - qmin -- Minimum scattering vector (float) - qmax -- Maximum scattering vector (float) - qdamp -- Resolution damping factor (float) - qbroad -- Resolution broadening factor (float) - spdiameter -- Nanoparticle diameter (float) - scale -- Data scale (float) - temperature -- Temperature (float) - doping -- Doping (float) + Attributes + ---------- + stype + The scattering type ("X", "N") + qmin + Minimum scattering vector (float) + qmax + Maximum scattering vector (float) + qdamp + Resolution damping factor (float) + qbroad + Resolution broadening factor (float) + spdiameter + Nanoparticle diameter (float) + scale + Data scale (float) + temperature + Temperature (float) + doping + Doping (float) """ _format = "PDF" @@ -85,8 +114,10 @@ def parseString(self, patstring): This wipes out the currently loaded data and selected bank number. - Arguments - patstring -- A string containing the pattern + Parameters + ---------- + patstring + A string containing the pattern Raises ParseError if the string cannot be parsed """ diff --git a/src/diffpy/srfit/sas/prcalculator.py b/src/diffpy/srfit/sas/prcalculator.py index 1dc6414d..74fd811a 100644 --- a/src/diffpy/srfit/sas/prcalculator.py +++ b/src/diffpy/srfit/sas/prcalculator.py @@ -43,23 +43,33 @@ class PrCalculator(Calculator): This is obtained from P(r) as P(r) = 4 pi r**2 f(r). - Attributes: - _invertor -- sas.pr.invertor.Invertor object. This object is internal, - but can be configured by the user after initialization. - Note that the 'x', 'y' and 'err' attributes get overwritten - every time the invertor is used. - - Managed Parameters: - scale -- The scale factor (default 1). - q -- The q-values of the I(q) signal - iq -- The I(q) signal - diq -- The uncertainty in I(q) + Attributes + ---------- + _invertor + sas.pr.invertor.Invertor object. This object is internal, + but can be configured by the user after initialization. + Note that the 'x', 'y' and 'err' attributes get overwritten + every time the invertor is used. + + Managed Parameters + ------------------ + scale + The scale factor (default 1). + q + The q-values of the I(q) signal + iq + The I(q) signal + diq + The uncertainty in I(q) """ def __init__(self, name): """Initialize the generator. - name -- A name for the PrCalculator + Attributes + ---------- + name + A name for the PrCalculator """ Calculator.__init__(self, name) @@ -112,17 +122,24 @@ class CFCalculator(PrCalculator): f(r) = P(r) / 4 pi r**2 which is the nanoparticle form factor scaled by density. - Attributes: - _invertor -- sas.pr.invertor.Invertor object. This object is internal, - but can be configured by the user after initialization. - Note that the 'x', 'y' and 'err' attributes get overwritten - every time the invertor is used. - - Managed Parameters: - scale -- The scale factor (default 1). - q -- The q-values of the I(q) signal - iq -- The I(q) signal - diq -- The uncertainty in I(q) + Attributes + ---------- + _invertor + sas.pr.invertor.Invertor object. This object is internal, + but can be configured by the user after initialization. + Note that the 'x', 'y' and 'err' attributes get overwritten + every time the invertor is used. + + Managed Parameters + ------------------ + scale + The scale factor (default 1). + q + The q-values of the I(q) signal + iq + The I(q) signal + diq + The uncertainty in I(q) """ def __call__(self, r): diff --git a/src/diffpy/srfit/sas/sasgenerator.py b/src/diffpy/srfit/sas/sasgenerator.py index bb3de8cf..64b781f0 100644 --- a/src/diffpy/srfit/sas/sasgenerator.py +++ b/src/diffpy/srfit/sas/sasgenerator.py @@ -27,8 +27,10 @@ class SASGenerator(ProfileGenerator): """A class for calculating I(Q) from a scattering type. - Attributes: - _model -- BaseModel object this adapts. + Attributes + ---------- + _model + BaseModel object this adapts. Managed Parameters: These depend on the parameters of the BaseModel object held by _model. They @@ -41,8 +43,12 @@ class SASGenerator(ProfileGenerator): def __init__(self, name, model): """Initialize the generator. - name -- A name for the SASGenerator - model -- SASModel object this adapts. + Attributes + ---------- + name + A name for the SASGenerator + model + SASModel object this adapts. """ ProfileGenerator.__init__(self, name) diff --git a/src/diffpy/srfit/sas/sasimport.py b/src/diffpy/srfit/sas/sasimport.py index 093a67b3..2c15c4ad 100644 --- a/src/diffpy/srfit/sas/sasimport.py +++ b/src/diffpy/srfit/sas/sasimport.py @@ -18,7 +18,10 @@ def sasimport(modname): """Import specified module from the SasView sas package. - modname -- absolute module name contained in the sas package. + Attributes + ---------- + modname + absolute module name contained in the sas package. When specified import does not work directly, try older API-s and raise DeprecationWarning. Raise ImportError if nothing works. diff --git a/src/diffpy/srfit/sas/sasparameter.py b/src/diffpy/srfit/sas/sasparameter.py index 0f042772..ad3d9895 100644 --- a/src/diffpy/srfit/sas/sasparameter.py +++ b/src/diffpy/srfit/sas/sasparameter.py @@ -27,26 +27,40 @@ class SASParameter(Parameter): """Class adapting a sasmodel parameter to srfit Parameter. Attributes - name -- A name for this Parameter. - const -- A flag indicating whether this is considered a constant. - _value -- The value of the Parameter. Modified with 'setValue'. - value -- Property for 'getValue' and 'setValue'. - constrained -- A flag indicating if the Parameter is constrained - (default False). - bounds -- A 2-list defining the bounds on the Parameter. This can be - used by some optimizers when the Parameter is varied. These - bounds are unrelated to restraints on a Parameter. - _model -- The BaseModel to which the underlying parameter belongs. - _parname -- The name of the underlying BaseModel parameter. + ---------- + name + A name for this Parameter. + const + A flag indicating whether this is considered a constant. + _value + The value of the Parameter. Modified with 'setValue'. + value + Property for 'getValue' and 'setValue'. + constrained + A flag indicating if the Parameter is constrained + (default False). + bounds + A 2-list defining the bounds on the Parameter. This can be + used by some optimizers when the Parameter is varied. These + bounds are unrelated to restraints on a Parameter. + _model + The BaseModel to which the underlying parameter belongs. + _parname + The name of the underlying BaseModel parameter. """ def __init__(self, name, model, parname=None): """Create the Parameter. - name -- Name of the Parameter - model -- The BaseModel to which the underlying parameter belongs - parname -- Name of parameter used by the model. If this is None - (default), then name is used. + Attributes + ---------- + name + Name of the Parameter + model + The BaseModel to which the underlying parameter belongs + parname + Name of parameter used by the model. If this is None + (default), then name is used. """ self._parname = parname or name val = model.getParam(self._parname) diff --git a/src/diffpy/srfit/sas/sasparser.py b/src/diffpy/srfit/sas/sasparser.py index 113648e9..875198d4 100644 --- a/src/diffpy/srfit/sas/sasparser.py +++ b/src/diffpy/srfit/sas/sasparser.py @@ -33,37 +33,58 @@ class SASParser(ProfileParser): Attributes - _format -- Name of the data format that this parses (string, default - ""). The format string is a unique identifier for the data - format handled by the parser. - _banks -- The data from each bank. Each bank contains a - (x, y, dx, dy) tuple: - x -- A numpy array containing the independent - variable read from the file. - y -- A numpy array containing the profile - from the file. - dx -- A numpy array containing the uncertainty in x - read from the file. This is 0 if the - uncertainty cannot be read. - dy -- A numpy array containing the uncertainty read - from the file. This is 0 if the uncertainty - cannot be read. - _x -- Independent variable from the chosen bank - _y -- Profile from the chosen bank - _dx -- Uncertainty in independent variable from the chosen bank - _dy -- Uncertainty in profile from the chosen bank - _meta -- A dictionary containing metadata read from the file. + Attributes + ---------- + _format + Name of the data format that this parses (string, default + ""). The format string is a unique identifier for the data + format handled by the parser. + _banks + The data from each bank. Each bank contains a + (x, y, dx, dy) tuple: + x + A numpy array containing the independent + variable read from the file. + y + A numpy array containing the profile + from the file. + dx + A numpy array containing the uncertainty in x + read from the file. This is 0 if the + uncertainty cannot be read. + dy + A numpy array containing the uncertainty read + from the file. This is 0 if the uncertainty + cannot be read. + _x + Independent variable from the chosen bank + _y + Profile from the chosen bank + _dx + Uncertainty in independent variable from the chosen bank + _dy + Uncertainty in profile from the chosen bank + _meta + A dictionary containing metadata read from the file. General Metadata - filename -- The name of the file from which data was parsed. This key - will not exist if data was not read from file. - nbanks -- The number of banks parsed. - bank -- The chosen bank number. + Attributes + ---------- + filename + The name of the file from which data was parsed. This key + will not exist if data was not read from file. + nbanks + The number of banks parsed. + bank + The chosen bank number. Metadata - These may appear in the metadata dictionary - datainfo -- The DataInfo object used to do the data parsing. + Attributes + ---------- + datainfo + The DataInfo object used to do the data parsing. """ _format = "SAS" @@ -73,8 +94,10 @@ def parseFile(self, filename): This wipes out the currently loaded data and selected bank number. - Arguments - filename -- The name of the file to parse + Parameters + ---------- + filename + The name of the file to parse Raises IOError if the file cannot be read Raises ParseError if the file cannot be parsed @@ -106,8 +129,10 @@ def parseString(self, patstring): This wipes out the currently loaded data and selected bank number. - Arguments - patstring -- A string containing the pattern + Parameters + ---------- + patstring + A string containing the pattern Raises ParseError if the string cannot be parsed """ diff --git a/src/diffpy/srfit/sas/sasprofile.py b/src/diffpy/srfit/sas/sasprofile.py index 517b2de1..ff48f7ba 100644 --- a/src/diffpy/srfit/sas/sasprofile.py +++ b/src/diffpy/srfit/sas/sasprofile.py @@ -31,34 +31,56 @@ class SASProfile(Profile): Attributes - _xobs -- A numpy array of the observed independent variable (default - None) - xobs -- Read-only property of _xobs. - _yobs -- A numpy array of the observed signal (default None) - yobs -- Read-only property of _yobs. - _dyobs -- A numpy array of the uncertainty of the observed signal - (default None, optional). - dyobs -- Read-only property of _dyobs. - x -- A numpy array of the calculated independent variable (default - None, property for xpar accessors). - y -- The profile over the calculation range (default None, property - for ypar accessors). - dy -- The uncertainty in the profile over the calculation range - (default None, property for dypar accessors). - ycalc -- A numpy array of the calculated signal (default None). - xpar -- A ProfileParameter that stores x (named "x"). - ypar -- A ProfileParameter that stores y (named "y"). - dypar -- A ProfileParameter that stores dy (named "dy"). - meta -- A dictionary of metadata. This is only set if provided by a - parser. - - _datainfo -- The DataInfo object this wraps. + Attributes + ---------- + _xobs + A numpy array of the observed independent variable (default + None) + xobs + Read-only property of _xobs. + _yobs + A numpy array of the observed signal (default None) + yobs + Read-only property of _yobs. + _dyobs + A numpy array of the uncertainty of the observed signal + (default None, optional). + dyobs + Read-only property of _dyobs. + x + A numpy array of the calculated independent variable (default + None, property for xpar accessors). + y + The profile over the calculation range (default None, property + for ypar accessors). + dy + The uncertainty in the profile over the calculation range + (default None, property for dypar accessors). + ycalc + A numpy array of the calculated signal (default None). + xpar + A ProfileParameter that stores x (named "x"). + ypar + A ProfileParameter that stores y (named "y"). + dypar + A ProfileParameter that stores dy (named "dy"). + meta + A dictionary of metadata. This is only set if provided by a + parser. + + Attributes + ---------- + _datainfo + The DataInfo object this wraps. """ def __init__(self, datainfo): """Initialize the attributes. - datainfo -- The DataInfo object this wraps. + Attributes + ---------- + datainfo + The DataInfo object this wraps. """ self._datainfo = datainfo Profile.__init__(self) @@ -76,12 +98,16 @@ def setObservedProfile(self, xobs, yobs, dyobs=None): This is overloaded to change the value within the datainfo object. - Arguments - xobs -- Numpy array of the independent variable - yobs -- Numpy array of the observed signal. - dyobs -- Numpy array of the uncertainty in the observed signal. If - dyobs is None (default), it will be set to 1 at each - observed xobs. + Parameters + ---------- + xobs + Numpy array of the independent variable + yobs + Numpy array of the observed signal. + dyobs + Numpy array of the uncertainty in the observed signal. If + dyobs is None (default), it will be set to 1 at each + observed xobs. Raises ValueError if len(yobs) != len(xobs) Raises ValueError if dyobs != None and len(dyobs) != len(xobs) diff --git a/src/diffpy/srfit/structure/__init__.py b/src/diffpy/srfit/structure/__init__.py index b48bb60d..2a34680e 100644 --- a/src/diffpy/srfit/structure/__init__.py +++ b/src/diffpy/srfit/structure/__init__.py @@ -25,8 +25,12 @@ def struToParameterSet(name, stru): This returns a ParameterSet adapted for the structure depending on its type. - stru -- a structure object known by this module - name -- A name to give the structure. + Attributes + ---------- + stru + a structure object known by this module + name + A name to give the structure. Raises TypeError if stru cannot be adapted """ diff --git a/src/diffpy/srfit/structure/basestructureparset.py b/src/diffpy/srfit/structure/basestructureparset.py index 31c619c9..4c975774 100644 --- a/src/diffpy/srfit/structure/basestructureparset.py +++ b/src/diffpy/srfit/structure/basestructureparset.py @@ -30,8 +30,10 @@ class BaseStructureParSet(ParameterSet): help interface the ParameterSet with the space group constraint methods in the sgconstraints module and to ProfileGenerators. - Attributes: - stru -- The adapted object + Attributes + ---------- + stru + The adapted object """ @classmethod diff --git a/src/diffpy/srfit/structure/bvsrestraint.py b/src/diffpy/srfit/structure/bvsrestraint.py index b9c9226c..da00b397 100644 --- a/src/diffpy/srfit/structure/bvsrestraint.py +++ b/src/diffpy/srfit/structure/bvsrestraint.py @@ -30,23 +30,33 @@ class BVSRestraint(Restraint): The restraint penalty is the root-mean-square deviation of the theoretical and calculated bond-valence sum of a structure. - Attributes: - _calc -- The SrReal BVSCalculator instance. - _parset -- The SrRealParSet that created this BVSRestraint. - sig -- The uncertainty on the BVS (default 1). - scaled -- A flag indicating if the restraint is scaled (multiplied) - by the unrestrained point-average chi^2 (chi^2/numpoints) - (default False). + Attributes + ---------- + _calc + The SrReal BVSCalculator instance. + _parset + The SrRealParSet that created this BVSRestraint. + sig + The uncertainty on the BVS (default 1). + scaled + A flag indicating if the restraint is scaled (multiplied) + by the unrestrained point-average chi^2 (chi^2/numpoints) + (default False). """ def __init__(self, parset, sig=1, scaled=False): """Initialize the Restraint. - parset -- SrRealParSet that creates this BVSRestraint. - sig -- The uncertainty on the BVS (default 1). - scaled -- A flag indicating if the restraint is scaled - (multiplied) by the unrestrained point-average chi^2 - (chi^2/numpoints) (bool, default False). + Attributes + ---------- + parset + SrRealParSet that creates this BVSRestraint. + sig + The uncertainty on the BVS (default 1). + scaled + A flag indicating if the restraint is scaled + (multiplied) by the unrestrained point-average chi^2 + (chi^2/numpoints) (bool, default False). """ from diffpy.srreal.bvscalculator import BVSCalculator @@ -59,8 +69,11 @@ def __init__(self, parset, sig=1, scaled=False): def penalty(self, w=1.0): """Calculate the penalty of the restraint. - w -- The point-average chi^2 which is optionally used to scale the - penalty (float, default 1.0). + Attributes + ---------- + w + The point-average chi^2 which is optionally used to scale the + penalty (float, default 1.0). """ # Get the bvms from the BVSCalculator stru = self._parset._getSrRealStructure() diff --git a/src/diffpy/srfit/structure/cctbxparset.py b/src/diffpy/srfit/structure/cctbxparset.py index a61a1d50..fd56a2f3 100644 --- a/src/diffpy/srfit/structure/cctbxparset.py +++ b/src/diffpy/srfit/structure/cctbxparset.py @@ -39,22 +39,31 @@ class CCTBXScattererParSet(ParameterSet): This class derives from ParameterSet. - Attributes: - name -- Name of the scatterer. The name is always of the form - "%s%i" % (element, number), where the number is the running - index of that element type (starting at 0). - x (y, z) -- Atom position in crystal coordinates (ParameterAdapter) - occupancy -- Occupancy of the atom on its crystal location - (ParameterAdapter) - Uiso -- Isotropic scattering factor (ParameterAdapter). + Attributes + ---------- + name + Name of the scatterer. The name is always of the form + "%s%i" % (element, number), where the number is the running + index of that element type (starting at 0). + x (y, z) -- Atom position in crystal coordinates (ParameterAdapter) + occupancy + Occupancy of the atom on its crystal location + (ParameterAdapter) + Uiso + Isotropic scattering factor (ParameterAdapter). """ def __init__(self, name, strups, idx): """Initialize. - name -- The name of this scatterer. - strups -- The CCTBXCrystalParSet that contains the cctbx structure - idx -- The index of the scatterer in the structure. + Attributes + ---------- + name + The name of this scatterer. + strups + The CCTBXCrystalParSet that contains the cctbx structure + idx + The index of the scatterer in the structure. """ ParameterSet.__init__(self, name) self.strups = strups @@ -123,16 +132,32 @@ def _getElem(self): class CCTBXUnitCellParSet(ParameterSet): """A wrapper for cctbx unit_cell object. - Attributes: - name -- Always "unitcell". - a, b, c, alpha, beta, gamma -- Unit cell parameters (ParameterAdapter). + Attributes + ---------- + name + Always "unitcell". + a + Unit cell parameters (ParameterAdapter). + b + Unit cell parameters (ParameterAdapter). + c + Unit cell parameters (ParameterAdapter). + alpha + Unit cell parameters (ParameterAdapter). + beta + Unit cell parameters (ParameterAdapter). + gamma + Unit cell parameters (ParameterAdapter). """ def __init__(self, strups): """Initialize. - strups -- The CCTBXCrystalParSet that contains the cctbx structure - and the unit cell we're wrapper. + Attributes + ---------- + strups + The CCTBXCrystalParSet that contains the cctbx structure + and the unit cell we're wrapper. """ ParameterSet.__init__(self, "unitcell") self.strups = strups @@ -190,17 +215,25 @@ def f(dummy, value): class CCTBXCrystalParSet(BaseStructureParSet): """A wrapper for CCTBX structure. - Attributes: - stru -- The adapted cctbx structure object. - scatterers -- The list of ScattererParSets. - unitcell -- The CCTBXUnitCellParSet for the structure. + Attributes + ---------- + stru + The adapted cctbx structure object. + scatterers + The list of ScattererParSets. + unitcell + The CCTBXUnitCellParSet for the structure. """ def __init__(self, name, stru): """Initialize. - name -- A name for this - stru -- A CCTBX structure instance. + Attributes + ---------- + name + A name for this + stru + A CCTBX structure instance. """ ParameterSet.__init__(self, name) self.stru = stru diff --git a/src/diffpy/srfit/structure/diffpyparset.py b/src/diffpy/srfit/structure/diffpyparset.py index 3c0f7a41..7263e1f0 100644 --- a/src/diffpy/srfit/structure/diffpyparset.py +++ b/src/diffpy/srfit/structure/diffpyparset.py @@ -60,31 +60,41 @@ class DiffpyAtomParSet(ParameterSet): This class derives from diffpy.srfit.fitbase.parameterset.ParameterSet. See this class for base attributes. - Attributes: - atom -- The diffpy.structure.Atom this is adapting - element -- The element name (property). - - Managed Parameters: - x (y, z) -- Atom position in crystal coordinates (ParameterAdapter) - occupancy -- Occupancy of the atom on its crystal location - (ParameterAdapter) - occ -- Proxy for occupancy (ParameterProxy). - U11, U22, U33, U12, U21, U23, U32, U13, U31 - -- Anisotropic displacement factor for atom (ParameterAdapter - or ParameterProxy). Note that the Uij and Uji parameters - are the same. - Uiso -- Isotropic ADP (ParameterAdapter). - B11, B22, B33, B12, B21, B23, B32, B13, B31 - -- Anisotropic displacement factor for atom (ParameterAdapter - or ParameterProxy). Note that the Bij and Bji parameters - are the same. (Bij = 8*pi**2*Uij) - Biso -- Isotropic ADP (ParameterAdapter). + Attributes + ---------- + atom + The diffpy.structure.Atom this is adapting + element + The element name (property). + + Managed Parameters + ------------------ + occupancy + Occupancy of the atom on its crystal location + (ParameterAdapter) + occ + Proxy for occupancy (ParameterProxy). + U11, U22, U33, U12, U21, U23, U32, U13, U31 + -- Anisotropic displacement factor for atom (ParameterAdapter + or ParameterProxy). Note that the Uij and Uji parameters + are the same. + Uiso + Isotropic ADP (ParameterAdapter). + B11, B22, B33, B12, B21, B23, B32, B13, B31 + -- Anisotropic displacement factor for atom (ParameterAdapter + or ParameterProxy). Note that the Bij and Bji parameters + are the same. (Bij = 8*pi**2*Uij) + Biso + Isotropic ADP (ParameterAdapter). """ def __init__(self, name, atom): """Initialize. - atom -- A diffpy.structure.Atom instance + Attributes + ---------- + atom + A diffpy.structure.Atom instance """ ParameterSet.__init__(self, name) self.atom = atom @@ -164,22 +174,41 @@ def _latsetter(par): class DiffpyLatticeParSet(ParameterSet): """A wrapper for diffpy.structure.Lattice. - This class derives from diffpy.srfit.fitbase.parameterset.ParameterSet. See - this class for base attributes. + This class derives from diffpy.srfit.fitbase.parameterset.ParameterSet. + See this class for base attributes. Attributes - lattice -- The diffpy.structure.Lattice this is adapting - name -- Always "lattice" - angunits -- "deg", the units of angle - - Managed Parameters: - a, b, c, alpha, beta, gamma -- The lattice parameters (ParameterAdapter). + ---------- + lattice + The diffpy.structure.Lattice this is adapting + name + Always "lattice" + angunits + "deg", the units of angle + + Parameters + ---------- + a + Unit cell parameters (ParameterAdapter). + b + Unit cell parameters (ParameterAdapter). + c + Unit cell parameters (ParameterAdapter). + alpha + Unit cell parameters (ParameterAdapter). + beta + Unit cell parameters (ParameterAdapter). + gamma + Unit cell parameters (ParameterAdapter). """ def __init__(self, lattice): """Initialize. - lattice -- A diffpy.structure.Lattice instance + Attributes + ---------- + lattice + A diffpy.structure.Lattice instance """ ParameterSet.__init__(self, "lattice") self.angunits = "deg" @@ -224,24 +253,34 @@ class DiffpyStructureParSet(SrRealParSet): This class derives from diffpy.srfit.fitbase.parameterset.ParameterSet. See this class for base attributes. - Attributes: - atoms -- The list of DiffpyAtomParSets, provided for convenience. - stru -- The diffpy.structure.Structure this is adapting - - Managed ParameterSets: - lattice -- The managed DiffpyLatticeParSet - -- A managed DiffpyAtomParSets. is the atomic element and - is the index of that element in the structure, - starting from zero. Thus, for nickel in P1 symmetry, the - managed DiffpyAtomParSets will be named "Ni0", "Ni1", "Ni2" - and "Ni3". + Attributes + ---------- + atoms + The list of DiffpyAtomParSets, provided for convenience. + stru + The diffpy.structure.Structure this is adapting + + Managed ParameterSets + --------------------- + lattice + The managed DiffpyLatticeParSet + + A managed DiffpyAtomParSets. is the atomic element and + is the index of that element in the structure, + starting from zero. Thus, for nickel in P1 symmetry, the + managed DiffpyAtomParSets will be named "Ni0", "Ni1", "Ni2" + and "Ni3". """ def __init__(self, name, stru): """Initialize. - name -- A name for the structure - stru -- A diffpy.structure.Structure instance + Attributes + ---------- + name + A name for the structure + stru + A diffpy.structure.Structure instance """ SrRealParSet.__init__(self, name) self.stru = stru diff --git a/src/diffpy/srfit/structure/objcrystparset.py b/src/diffpy/srfit/structure/objcrystparset.py index 5feef034..b7345422 100644 --- a/src/diffpy/srfit/structure/objcrystparset.py +++ b/src/diffpy/srfit/structure/objcrystparset.py @@ -65,22 +65,31 @@ class ObjCrystScattererParSet(ParameterSet): objects with a similar interface (MolAtom). See the ParameterSet class for base attributes. - Attributes: - scat -- The adapted pyobjcryst object. - parent -- The ParameterSet this belongs to - - Managed Parameters: - x, y, z -- Scatterer position in crystal coordinates (ParameterWraper) - occ -- Occupancy of the scatterer on its crystal site - (ParameterWraper) + Attributes + ---------- + scat + The adapted pyobjcryst object. + parent + The ParameterSet this belongs to + + Managed Parameters + ------------------ + occ + Occupancy of the scatterer on its crystal site + (ParameterWraper) """ def __init__(self, name, scat, parent): """Initialize. - name -- The name of the scatterer - scat -- The pyobjcryst.Scatterer instance - parent -- The ParameterSet this belongs to + Attributes + ---------- + name + The name of the scatterer + scat + The pyobjcryst.Scatterer instance + parent + The ParameterSet this belongs to """ ParameterSet.__init__(self, name) self.scat = scat @@ -110,28 +119,39 @@ class ObjCrystAtomParSet(ObjCrystScattererParSet): This class derives from ObjCrystScattererParSet. - Attributes: - scat -- The adapted pyobjcryst.atom.Atom. - element -- Non-refinable name of the element (property). - parent -- The ObjCrystCrystalParSet this belongs to. - - Managed Parameters: - x, y, z -- Atom position in crystal coordinates (ParameterAdapter) - occ -- Occupancy of the atom on its crystal location - (ParameterAdapter) - Biso -- Isotropic scattering factor (ParameterAdapter). - B11, B22, B33, B12, B21, B23, B32, B13, B31 - -- Anisotropic displacement factor for scatterer - (ParameterAdapter or ParameterProxy). Note that the Bij and Bji - parameters are the same. + Attributes + ---------- + scat + The adapted pyobjcryst.atom.Atom. + element + Non-refinable name of the element (property). + parent + The ObjCrystCrystalParSet this belongs to. + + Managed Parameters + ------------------ + occ + Occupancy of the atom on its crystal location + (ParameterAdapter) + Biso + Isotropic scattering factor (ParameterAdapter). + B11, B22, B33, B12, B21, B23, B32, B13, B31 + -- Anisotropic displacement factor for scatterer + (ParameterAdapter or ParameterProxy). Note that the Bij and Bji + parameters are the same. """ def __init__(self, name, atom, parent): """Initialize. - name -- The name of the scatterer - scat -- The Scatterer instance - parent -- The ObjCrystCrystalParSet this belongs to + Attributes + ---------- + name + The name of the scatterer + scat + The Scatterer instance + parent + The ObjCrystCrystalParSet this belongs to """ ObjCrystScattererParSet.__init__(self, name, atom, parent) sp = atom.GetScatteringPower() @@ -174,18 +194,23 @@ class ObjCrystMoleculeParSet(ObjCrystScattererParSet): This class derives from ObjCrystScattererParSet. - Attributes: - scat -- The adapted pyobjcryst.molecule.Molecule. - stru -- The adapted pyobjcryst.molecule.Molecule. - parent -- The ObjCrystCrystalParSet this belongs to. - ObjCrystMoleculeParSets can be used on their own, in which - case this is None. - - Managed Parameters: - x, y, z -- Molecule position in crystal coordinates (ParameterAdapter) - occ -- Occupancy of the molecule on its crystal location - (ParameterAdapter) - q0, q1, q2, q3 -- Orientational quaternion (ParameterAdapter) + Attributes + ---------- + scat + The adapted pyobjcryst.molecule.Molecule. + stru + The adapted pyobjcryst.molecule.Molecule. + parent + The ObjCrystCrystalParSet this belongs to. + ObjCrystMoleculeParSets can be used on their own, in which + case this is None. + + Managed Parameters + ------------------ + occ + Occupancy of the molecule on its crystal location + (ParameterAdapter) + q0, q1, q2, q3 -- Orientational quaternion (ParameterAdapter) Other attributes are inherited from diffpy.srfit.fitbase.parameterset.ParameterSet @@ -194,9 +219,14 @@ class ObjCrystMoleculeParSet(ObjCrystScattererParSet): def __init__(self, name, molecule, parent=None): """Initialize. - name -- The name of the scatterer - molecule -- The pyobjcryst.Molecule instance - parent -- The ObjCrystCrystalParSet this belongs to (default None). + Attributes + ---------- + name + The name of the scatterer + molecule + The pyobjcryst.Molecule instance + parent + The ObjCrystCrystalParSet this belongs to (default None). """ ObjCrystScattererParSet.__init__(self, name, molecule, parent) self.stru = molecule @@ -369,14 +399,22 @@ def restrainBondLength( This creates an instance of ObjCrystBondLengthRestraint and adds it to the ObjCrystMoleculeParSet. - atom1 -- First atom (ObjCrystMolAtomParSet) in the bond - atom2 -- Second atom (ObjCrystMolAtomParSet) in the bond - length -- The length of the bond (Angstroms) - sigma -- The uncertainty of the bond length (Angstroms) - delta -- The width of the bond (Angstroms) - scaled -- A flag indicating if the restraint is scaled (multiplied) - by the unrestrained point-average chi^2 (chi^2/numpoints) - (default False) + Attributes + ---------- + atom1 + First atom (ObjCrystMolAtomParSet) in the bond + atom2 + Second atom (ObjCrystMolAtomParSet) in the bond + length + The length of the bond (Angstroms) + sigma + The uncertainty of the bond length (Angstroms) + delta + The width of the bond (Angstroms) + scaled + A flag indicating if the restraint is scaled (multiplied) + by the unrestrained point-average chi^2 (chi^2/numpoints) + (default False) Returns ------- @@ -398,13 +436,20 @@ def restrainBondLengthParameter( This creates an instance of ObjCrystBondLengthRestraint and adds it to the ObjCrystMoleculeParSet. - par -- A ObjCrystBondLengthParameter (see addBondLengthParameter) - length -- The length of the bond (Angstroms) - sigma -- The uncertainty of the bond length (Angstroms) - delta -- The width of the bond (Angstroms) - scaled -- A flag indicating if the restraint is scaled (multiplied) - by the unrestrained point-average chi^2 (chi^2/numpoints) - (default False) + Attributes + ---------- + par + A ObjCrystBondLengthParameter (see addBondLengthParameter) + length + The length of the bond (Angstroms) + sigma + The uncertainty of the bond length (Angstroms) + delta + The width of the bond (Angstroms) + scaled + A flag indicating if the restraint is scaled (multiplied) + by the unrestrained point-average chi^2 (chi^2/numpoints) + (default False) Returns the ObjCrystBondLengthRestraint object for use with the 'unrestrain' method. @@ -421,16 +466,25 @@ def restrainBondAngle( This creates an instance of ObjCrystBondAngleRestraint and adds it to the ObjCrystMoleculeParSet. - atom1 -- First atom (ObjCrystMolAtomParSet) in the bond angle - atom2 -- Second (central) atom (ObjCrystMolAtomParSet) in the bond - angle - atom3 -- Third atom (ObjCrystMolAtomParSet) in the bond angle - angle -- The bond angle (radians) - sigma -- The uncertainty of the bond angle (radians) - delta -- The width of the bond angle (radians) - scaled -- A flag indicating if the restraint is scaled (multiplied) - by the unrestrained point-average chi^2 (chi^2/numpoints) - (default False). + Attributes + ---------- + atom1 + First atom (ObjCrystMolAtomParSet) in the bond angle + atom2 + Second (central) atom (ObjCrystMolAtomParSet) in the bond + angle + atom3 + Third atom (ObjCrystMolAtomParSet) in the bond angle + angle + The bond angle (radians) + sigma + The uncertainty of the bond angle (radians) + delta + The width of the bond angle (radians) + scaled + A flag indicating if the restraint is scaled (multiplied) + by the unrestrained point-average chi^2 (chi^2/numpoints) + (default False). Returns the ObjCrystBondAngleRestraint object for use with the 'unrestrain' method. @@ -450,13 +504,20 @@ def restrainBondAngleParameter( This creates an instance of ObjCrystBondAngleRestraint and adds it to the ObjCrystMoleculeParSet. - par -- A ObjCrystBondAngleParameter (see addBondAngleParameter) - angle -- The bond angle (radians) - sigma -- The uncertainty of the bond angle (radians) - delta -- The width of the bond angle (radians) - scaled -- A flag indicating if the restraint is scaled (multiplied) - by the unrestrained point-average chi^2 (chi^2/numpoints) - (default False). + Attributes + ---------- + par + A ObjCrystBondAngleParameter (see addBondAngleParameter) + angle + The bond angle (radians) + sigma + The uncertainty of the bond angle (radians) + delta + The width of the bond angle (radians) + scaled + A flag indicating if the restraint is scaled (multiplied) + by the unrestrained point-average chi^2 (chi^2/numpoints) + (default False). Returns the ObjCrystBondAngleRestraint object for use with the 'unrestrain' method. @@ -473,16 +534,26 @@ def restrainDihedralAngle( This creates an instance of ObjCrystDihedralAngleRestraint and adds it to the ObjCrystMoleculeParSet. - atom1 -- First atom (ObjCrystMolAtomParSet) in the angle - atom2 -- Second (central) atom (ObjCrystMolAtomParSet) in the angle - atom3 -- Third (central) atom (ObjCrystMolAtomParSet) in the angle - atom4 -- Fourth atom in the angle (ObjCrystMolAtomParSet) - angle -- The dihedral angle (radians) - sigma -- The uncertainty of the dihedral angle (radians) - delta -- The width of the dihedral angle (radians) - scaled -- A flag indicating if the restraint is scaled (multiplied) - by the unrestrained point-average chi^2 (chi^2/numpoints) - (default False). + Attributes + ---------- + atom1 + First atom (ObjCrystMolAtomParSet) in the angle + atom2 + Second (central) atom (ObjCrystMolAtomParSet) in the angle + atom3 + Third (central) atom (ObjCrystMolAtomParSet) in the angle + atom4 + Fourth atom in the angle (ObjCrystMolAtomParSet) + angle + The dihedral angle (radians) + sigma + The uncertainty of the dihedral angle (radians) + delta + The width of the dihedral angle (radians) + scaled + A flag indicating if the restraint is scaled (multiplied) + by the unrestrained point-average chi^2 (chi^2/numpoints) + (default False). Returns the ObjCrystDihedralAngleRestraint object for use with the 'unrestrain' method. @@ -502,14 +573,21 @@ def restrainDihedralAngleParameter( This creates an instance of ObjCrystDihedralAngleRestraint and adds it to the ObjCrystMoleculeParSet. - par -- A ObjCrystDihedralAngleParameter (see - addDihedralAngleParameter) - angle -- The dihedral angle (radians) - sigma -- The uncertainty of the dihedral angle (radians) - delta -- The width of the dihedral angle (radians) - scaled -- A flag indicating if the restraint is scaled (multiplied) - by the unrestrained point-average chi^2 (chi^2/numpoints) - (default False). + Attributes + ---------- + par + A ObjCrystDihedralAngleParameter (see + addDihedralAngleParameter) + angle + The dihedral angle (radians) + sigma + The uncertainty of the dihedral angle (radians) + delta + The width of the dihedral angle (radians) + scaled + A flag indicating if the restraint is scaled (multiplied) + by the unrestrained point-average chi^2 (chi^2/numpoints) + (default False). Returns the ObjCrystDihedralAngleRestraint object for use with the 'unrestrain' method. @@ -533,15 +611,22 @@ def addBondLengthParameter( This creates a ObjCrystBondLengthParameter to the ObjCrystMoleculeParSet that can be adjusted during the fit. - name -- The name of the ObjCrystBondLengthParameter - atom1 -- The first atom (ObjCrystMolAtomParSet) in the bond - atom2 -- The second (mutated) atom (ObjCrystMolAtomParSet) in the - bond - value -- An initial value for the bond length. If this is None - (default), then the current distance between the atoms will - be used. - const -- A flag indicating whether the Parameter is constant - (default False) + Attributes + ---------- + name + The name of the ObjCrystBondLengthParameter + atom1 + The first atom (ObjCrystMolAtomParSet) in the bond + atom2 + The second (mutated) atom (ObjCrystMolAtomParSet) in the + bond + value + An initial value for the bond length. If this is None + (default), then the current distance between the atoms will + be used. + const + A flag indicating whether the Parameter is constant + (default False) Returns the new ObjCrystBondLengthParameter. """ @@ -558,17 +643,25 @@ def addBondAngleParameter( This creates a ObjCrystBondAngleParameter to the ObjCrystMoleculeParSet that can be adjusted during the fit. - name -- The name of the ObjCrystBondAngleParameter - atom1 -- The first atom (ObjCrystMolAtomParSet) in the bond angle - atom2 -- The second (central) atom (ObjCrystMolAtomParSet) in the - bond angle - atom3 -- The third (mutated) atom (ObjCrystMolAtomParSet) in the - bond angle - value -- An initial value for the bond angle. If this is None - (default), then the current bond angle between the atoms - will be used. - const -- A flag indicating whether the Parameter is constant - (default False). + Attributes + ---------- + name + The name of the ObjCrystBondAngleParameter + atom1 + The first atom (ObjCrystMolAtomParSet) in the bond angle + atom2 + The second (central) atom (ObjCrystMolAtomParSet) in the + bond angle + atom3 + The third (mutated) atom (ObjCrystMolAtomParSet) in the + bond angle + value + An initial value for the bond angle. If this is None + (default), then the current bond angle between the atoms + will be used. + const + A flag indicating whether the Parameter is constant + (default False). Returns the new ObjCrystBondAngleParameter. """ @@ -587,20 +680,29 @@ def addDihedralAngleParameter( This creates a ObjCrystDihedralAngleParameter to the ObjCrystMoleculeParSet that can be adjusted during the fit. - name -- The name of the ObjCrystDihedralAngleParameter. - atom1 -- The first atom (ObjCrystMolAtomParSet) in the dihderal - angle. - atom2 -- The second (central) atom (ObjCrystMolAtomParSet) in the - dihderal angle - atom3 -- The third (central) atom (ObjCrystMolAtomParSet) in the - dihderal angle - atom4 -- The fourth (mutated) atom (ObjCrystMolAtomParSet) in the - dihderal angle - value -- An initial value for the dihedral angle. If this is None - (default), then the current dihedral angle between atoms - will be used. - const -- A flag indicating whether the Parameter is constant - (default False). + Attributes + ---------- + name + The name of the ObjCrystDihedralAngleParameter. + atom1 + The first atom (ObjCrystMolAtomParSet) in the dihderal + angle. + atom2 + The second (central) atom (ObjCrystMolAtomParSet) in the + dihderal angle + atom3 + The third (central) atom (ObjCrystMolAtomParSet) in the + dihderal angle + atom4 + The fourth (mutated) atom (ObjCrystMolAtomParSet) in the + dihderal angle + value + An initial value for the dihedral angle. If this is None + (default), then the current dihedral angle between atoms + will be used. + const + A flag indicating whether the Parameter is constant + (default False). Returns the new ObjCrystDihedralAngleParameter. """ @@ -622,29 +724,40 @@ class ObjCrystMolAtomParSet(ObjCrystScattererParSet): MolAtom does not derive from Scatterer, but the relevant interface is the same within pyobjcryst. See the ParameterSet class for base attributes. - Attributes: - scat -- The adapted pyobjcryst.molecule.MolAtom. - parent -- The ObjCrystCrystalParSet this belongs to - element -- Non-refinable name of the element (property). - - Managed Parameters: - x, y, z -- Atom position in crystal coordinates (ParameterAdapter) - occ -- Occupancy of the atom on its crystal location - (ParameterAdapter) - Biso -- Isotropic scattering factor (ParameterAdapter). This does - not exist for dummy atoms. See the 'isDummy' method. - B11, B22, B33, B12, B21, B23, B32, B13, B31 - -- Anisotropic displacement factor for scatterer - (ParameterAdapter or ParameterProxy). Note that the Bij and Bji - parameters are the same. + Attributes + ---------- + scat + The adapted pyobjcryst.molecule.MolAtom. + parent + The ObjCrystCrystalParSet this belongs to + element + Non-refinable name of the element (property). + + Managed Parameters + ------------------ + occ + Occupancy of the atom on its crystal location + (ParameterAdapter) + Biso + Isotropic scattering factor (ParameterAdapter). This does + not exist for dummy atoms. See the 'isDummy' method. + B11, B22, B33, B12, B21, B23, B32, B13, B31 + -- Anisotropic displacement factor for scatterer + (ParameterAdapter or ParameterProxy). Note that the Bij and Bji + parameters are the same. """ def __init__(self, name, scat, parent): """Initialize. - name -- The name of the scatterer - scat -- The Scatterer instance - parent -- The ObjCrystCrystalParSet this belongs to + Attributes + ---------- + name + The name of the scatterer + scat + The Scatterer instance + parent + The ObjCrystCrystalParSet this belongs to """ ObjCrystScattererParSet.__init__(self, name, scat, parent) sp = scat.GetScatteringPower() @@ -696,20 +809,27 @@ class ObjCrystMoleculeRestraint(object): diffpy.srfit.fitbase.restraint.Restraint. The 'restrain' method is not needed or implemented. - Attributes: - res -- The pyobjcryst Molecule restraint. - scaled -- A flag indicating if the restraint is scaled (multiplied) by - the unrestrained point-average chi^2 (chi^2/numpoints) (default - False). + Attributes + ---------- + res + The pyobjcryst Molecule restraint. + scaled + A flag indicating if the restraint is scaled (multiplied) by + the unrestrained point-average chi^2 (chi^2/numpoints) (default + False). """ def __init__(self, res, scaled=False): """Create a Restraint-like from a pyobjcryst Molecule restraint. - res -- The pyobjcryst Molecule restraint. - scaled -- A flag indicating if the restraint is scaled (multiplied) - by the unrestrained point-average chi^2 (chi^2/numpoints) - (default False). + Attributes + ---------- + res + The pyobjcryst Molecule restraint. + scaled + A flag indicating if the restraint is scaled (multiplied) + by the unrestrained point-average chi^2 (chi^2/numpoints) + (default False). """ self.res = res self.scaled = scaled @@ -718,8 +838,11 @@ def __init__(self, res, scaled=False): def penalty(self, w=1.0): """Calculate the penalty of the restraint. - w -- The point-average chi^2 which is optionally used to scale the - penalty (default 1.0). + Attributes + ---------- + w + The point-average chi^2 which is optionally used to scale the + penalty (default 1.0). """ penalty = self.res.GetLogLikelihood() if self.scaled: @@ -733,29 +856,45 @@ def penalty(self, w=1.0): class ObjCrystBondLengthRestraint(ObjCrystMoleculeRestraint): """Restrain the distance between two atoms. - Attributes: - atom1 -- The first atom in the bond (ObjCrystMolAtomParSet) - atom2 -- The second atom in the bond (ObjCrystMolAtomParSet) - length -- The length of the bond (Angstroms) - sigma -- The uncertainty of the bond length (Angstroms) - delta -- The width of the bond (Angstroms) - res -- The pyobjcryst BondLength restraint - scaled -- A flag indicating if the restraint is scaled (multiplied) by - the unrestrained point-average chi^2 (chi^2/numpoints) (default - False) + Attributes + ---------- + atom1 + The first atom in the bond (ObjCrystMolAtomParSet) + atom2 + The second atom in the bond (ObjCrystMolAtomParSet) + length + The length of the bond (Angstroms) + sigma + The uncertainty of the bond length (Angstroms) + delta + The width of the bond (Angstroms) + res + The pyobjcryst BondLength restraint + scaled + A flag indicating if the restraint is scaled (multiplied) by + the unrestrained point-average chi^2 (chi^2/numpoints) (default + False) """ def __init__(self, atom1, atom2, length, sigma, delta, scaled=False): """Create a bond length restraint. - atom1 -- First atom (ObjCrystMolAtomParSet) in the bond - atom2 -- Second atom (ObjCrystMolAtomParSet) in the bond - length -- The length of the bond (Angstroms) - sigma -- The uncertainty of the bond length (Angstroms) - delta -- The width of the bond (Angstroms) - scaled -- A flag indicating if the restraint is scaled (multiplied) - by the unrestrained point-average chi^2 (chi^2/numpoints) - (default False) + Attributes + ---------- + atom1 + First atom (ObjCrystMolAtomParSet) in the bond + atom2 + Second atom (ObjCrystMolAtomParSet) in the bond + length + The length of the bond (Angstroms) + sigma + The uncertainty of the bond length (Angstroms) + delta + The width of the bond (Angstroms) + scaled + A flag indicating if the restraint is scaled (multiplied) + by the unrestrained point-average chi^2 (chi^2/numpoints) + (default False) """ self.atom1 = atom1 self.atom2 = atom2 @@ -787,32 +926,50 @@ def __init__(self, atom1, atom2, length, sigma, delta, scaled=False): class ObjCrystBondAngleRestraint(ObjCrystMoleculeRestraint): """Restrain the angle defined by three atoms. - Attributes: - atom1 -- The first atom in the angle (ObjCrystMolAtomParSet) - atom2 -- The second atom in the angle (ObjCrystMolAtomParSet) - atom3 -- The third atom in the angle (ObjCrystMolAtomParSet) - angle -- The bond angle (radians) - sigma -- The uncertainty of the bond angle (radians) - delta -- The width of the bond angle (radians) - res -- The pyobjcryst BondAngle restraint - scaled -- A flag indicating if the restraint is scaled (multiplied) by - the unrestrained point-average chi^2 (chi^2/numpoints) (default - False) + Attributes + ---------- + atom1 + The first atom in the angle (ObjCrystMolAtomParSet) + atom2 + The second atom in the angle (ObjCrystMolAtomParSet) + atom3 + The third atom in the angle (ObjCrystMolAtomParSet) + angle + The bond angle (radians) + sigma + The uncertainty of the bond angle (radians) + delta + The width of the bond angle (radians) + res + The pyobjcryst BondAngle restraint + scaled + A flag indicating if the restraint is scaled (multiplied) by + the unrestrained point-average chi^2 (chi^2/numpoints) (default + False) """ def __init__(self, atom1, atom2, atom3, angle, sigma, delta, scaled=False): """Create a bond angle restraint. - atom1 -- First atom (ObjCrystMolAtomParSet) in the bond angle - atom2 -- Second (central) atom (ObjCrystMolAtomParSet) in the bond - angle - atom3 -- Third atom (ObjCrystMolAtomParSet) in the bond angle - angle -- The bond angle (radians) - sigma -- The uncertainty of the bond angle (radians) - delta -- The width of the bond angle (radians) - scaled -- A flag indicating if the restraint is scaled (multiplied) - by the unrestrained point-average chi^2 (chi^2/numpoints) - (default False). + Attributes + ---------- + atom1 + First atom (ObjCrystMolAtomParSet) in the bond angle + atom2 + Second (central) atom (ObjCrystMolAtomParSet) in the bond + angle + atom3 + Third atom (ObjCrystMolAtomParSet) in the bond angle + angle + The bond angle (radians) + sigma + The uncertainty of the bond angle (radians) + delta + The width of the bond angle (radians) + scaled + A flag indicating if the restraint is scaled (multiplied) + by the unrestrained point-average chi^2 (chi^2/numpoints) + (default False). """ self.atom1 = atom1 self.atom2 = atom2 @@ -847,18 +1004,28 @@ def __init__(self, atom1, atom2, atom3, angle, sigma, delta, scaled=False): class ObjCrystDihedralAngleRestraint(ObjCrystMoleculeRestraint): """Restrain the dihedral (torsion) angle defined by four atoms. - Attributes: - atom1 -- The first atom in the angle (ObjCrystMolAtomParSet) - atom2 -- The second (central) atom in the angle (ObjCrystMolAtomParSet) - atom3 -- The third (central) atom in the angle (ObjCrystMolAtomParSet) - atom4 -- The fourth atom in the angle (ObjCrystMolAtomParSet) - angle -- The dihedral angle (radians) - sigma -- The uncertainty of the dihedral angle (radians) - delta -- The width of the dihedral angle (radians) - res -- The pyobjcryst DihedralAngle restraint - scaled -- A flag indicating if the restraint is scaled (multiplied) by - the unrestrained point-average chi^2 (chi^2/numpoints) (default - False) + Attributes + ---------- + atom1 + The first atom in the angle (ObjCrystMolAtomParSet) + atom2 + The second (central) atom in the angle (ObjCrystMolAtomParSet) + atom3 + The third (central) atom in the angle (ObjCrystMolAtomParSet) + atom4 + The fourth atom in the angle (ObjCrystMolAtomParSet) + angle + The dihedral angle (radians) + sigma + The uncertainty of the dihedral angle (radians) + delta + The width of the dihedral angle (radians) + res + The pyobjcryst DihedralAngle restraint + scaled + A flag indicating if the restraint is scaled (multiplied) by + the unrestrained point-average chi^2 (chi^2/numpoints) (default + False) """ def __init__( @@ -866,16 +1033,26 @@ def __init__( ): """Create a dihedral angle restraint. - atom1 -- First atom (ObjCrystMolAtomParSet) in the angle - atom2 -- Second (central) atom (ObjCrystMolAtomParSet) in the angle - atom3 -- Third (central) atom (ObjCrystMolAtomParSet) in the angle - atom4 -- Fourth atom in the angle (ObjCrystMolAtomParSet) - angle -- The dihedral angle (radians) - sigma -- The uncertainty of the dihedral angle (radians) - delta -- The width of the dihedral angle (radians) - scaled -- A flag indicating if the restraint is scaled (multiplied) - by the unrestrained point-average chi^2 (chi^2/numpoints) - (default False). + Attributes + ---------- + atom1 + First atom (ObjCrystMolAtomParSet) in the angle + atom2 + Second (central) atom (ObjCrystMolAtomParSet) in the angle + atom3 + Third (central) atom (ObjCrystMolAtomParSet) in the angle + atom4 + Fourth atom in the angle (ObjCrystMolAtomParSet) + angle + The dihedral angle (radians) + sigma + The uncertainty of the dihedral angle (radians) + delta + The width of the dihedral angle (radians) + scaled + A flag indicating if the restraint is scaled (multiplied) + by the unrestrained point-average chi^2 (chi^2/numpoints) + (default False). """ self.atom1 = atom1 self.atom2 = atom2 @@ -914,24 +1091,34 @@ class StretchModeParameter(Parameter): This class relies upon attributes that do not belong to it. Do not instantiate this class. - Required attributes: - matoms -- The set of all mutated AtomParSets - molecule -- The ObjCrystMoleculeParSet the atoms belong to - mode -- The pyobjcryst.molecule.StretchMode used to change atomic - positions. - keepcenter -- Flag indicating whether to keep the center of mass of the - molecule stationary within the crystal when changing the - value of the parameter (bool, default True). + Required attributes + ------------------- + matoms + The set of all mutated AtomParSets + molecule + The ObjCrystMoleculeParSet the atoms belong to + mode + The pyobjcryst.molecule.StretchMode used to change atomic + positions. + keepcenter + Flag indicating whether to keep the center of mass of the + molecule stationary within the crystal when changing the + value of the parameter (bool, default True). """ def __init__(self, name, value=None, const=False): """Initialization. - name -- The name of this Parameter (must be a valid attribute - identifier) - value -- The initial value of this Parameter (default 0). - const -- A flag inticating whether the Parameter is a constant (like - pi). + Attributes + ---------- + name + The name of this Parameter (must be a valid attribute + identifier) + value + The initial value of this Parameter (default 0). + const + A flag inticating whether the Parameter is a constant (like + pi). Raises ValueError if the name is not a valid attribute identifier """ @@ -1032,41 +1219,62 @@ class ObjCrystBondLengthParameter(StretchModeParameter): bond length changes the position of the second MolAtom and Molecule, even if either is set as constant. - Attributes: - atom1 -- The first ObjCrystMolAtomParSet in the bond - atom2 -- The second (mutated) ObjCrystMolAtomParSet in the bond - matoms -- The set of all mutated ObjCrystMolAtomParSets - molecule -- The ObjCrystMoleculeParSet the ObjCrystMolAtomParSets - belong to - mode -- The pyobjcryst.molecule.StretchModeBondLength for the bond + Attributes + ---------- + atom1 + The first ObjCrystMolAtomParSet in the bond + atom2 + The second (mutated) ObjCrystMolAtomParSet in the bond + matoms + The set of all mutated ObjCrystMolAtomParSets + molecule + The ObjCrystMoleculeParSet the ObjCrystMolAtomParSets + belong to + mode + The pyobjcryst.molecule.StretchModeBondLength for the bond Inherited Attributes - name -- A name for this Parameter. - const -- A flag indicating whether this is considered a constant. - _value -- The value of the Parameter. Modified with 'setValue'. - value -- Property for 'getValue' and 'setValue'. - constraint -- A callable that calculates the value of this Parameter. If - this is None (None), the the Parameter is responsible for its - own value. The callable takes no arguments. - bounds -- A 2-list defining the bounds on the Parameter. This can be - used by some optimizers when the Parameter is varied. + -------------------- + name + A name for this Parameter. + const + A flag indicating whether this is considered a constant. + _value + The value of the Parameter. Modified with 'setValue'. + value + Property for 'getValue' and 'setValue'. + constraint + A callable that calculates the value of this Parameter. If + this is None (None), the the Parameter is responsible for its + own value. The callable takes no arguments. + bounds + A 2-list defining the bounds on the Parameter. This can be + used by some optimizers when the Parameter is varied. """ def __init__(self, name, atom1, atom2, value=None, const=False, mode=None): """Create a ObjCrystBondLengthParameter. - name -- The name of the ObjCrystBondLengthParameter - atom1 -- The first atom (ObjCrystMolAtomParSet) in the bond - atom2 -- The second (mutated) atom (ObjCrystMolAtomParSet) in the - bond - value -- An initial value for the bond length. If this is None - (default), then the current distance between the atoms will - be used. - const -- A flag indicating whether the Parameter is constant - (default False) - mode -- An extant pyobjcryst.molecule.StretchModeBondLength to use. - If this is None (default), then a new StretchModeBondLength - will be built. + Attributes + ---------- + name + The name of the ObjCrystBondLengthParameter + atom1 + The first atom (ObjCrystMolAtomParSet) in the bond + atom2 + The second (mutated) atom (ObjCrystMolAtomParSet) in the + bond + value + An initial value for the bond length. If this is None + (default), then the current distance between the atoms will + be used. + const + A flag indicating whether the Parameter is constant + (default False) + mode + An extant pyobjcryst.molecule.StretchModeBondLength to use. + If this is None (default), then a new StretchModeBondLength + will be built. """ # Create the mode @@ -1100,11 +1308,15 @@ def setConst(self, const=True, value=None): This sets the underlying ObjCrystMolAtomParSet positions const as well. - const -- Flag indicating if the Parameter is constant (default - True). - value -- An optional value for the Parameter (default None). If this - is not None, then the Parameter will get a new value, - constant or otherwise. + Attributes + ---------- + const + Flag indicating if the Parameter is constant (default + True). + value + An optional value for the Parameter (default None). If this + is not None, then the Parameter will get a new value, + constant or otherwise. """ StretchModeParameter.setConst(self, const, value) @@ -1144,24 +1356,38 @@ class ObjCrystBondAngleParameter(StretchModeParameter): See precautions in the ObjCrystBondLengthParameter class. Attributes - atom1 -- The first ObjCrystAtomParSet in the bond angle - atom2 -- The second (central) ObjCrystMolAtomParSet in the bond angle - atom3 -- The third (mutated) ObjCrystMolAtomParSet in the bond angle - matoms -- The set of all mutated ObjCrystMolAtomParSets - molecule -- The ObjCrystMoleculeParSet the ObjCrystMolAtomParSets - belong to - mode -- The pyobjcryst.molecule.StretchModeBondAngle for the bond angle + ---------- + atom1 + The first ObjCrystAtomParSet in the bond angle + atom2 + The second (central) ObjCrystMolAtomParSet in the bond angle + atom3 + The third (mutated) ObjCrystMolAtomParSet in the bond angle + matoms + The set of all mutated ObjCrystMolAtomParSets + molecule + The ObjCrystMoleculeParSet the ObjCrystMolAtomParSets + belong to + mode + The pyobjcryst.molecule.StretchModeBondAngle for the bond angle Inherited Attributes - name -- A name for this Parameter. - const -- A flag indicating whether this is considered a constant. - _value -- The value of the Parameter. Modified with 'setValue'. - value -- Property for 'getValue' and 'setValue'. - constraint -- A callable that calculates the value of this Parameter. If - this is None (None), the the Parameter is responsible for its - own value. The callable takes no arguments. - bounds -- A 2-list defining the bounds on the Parameter. This can be - used by some optimizers when the Parameter is varied. + -------------------- + name + A name for this Parameter. + const + A flag indicating whether this is considered a constant. + _value + The value of the Parameter. Modified with 'setValue'. + value + Property for 'getValue' and 'setValue'. + constraint + A callable that calculates the value of this Parameter. If + this is None (None), the the Parameter is responsible for its + own value. The callable takes no arguments. + bounds + A 2-list defining the bounds on the Parameter. This can be + used by some optimizers when the Parameter is varied. """ def __init__( @@ -1169,19 +1395,28 @@ def __init__( ): """Create a ObjCrystBondAngleParameter. - name -- The name of the ObjCrystBondAngleParameter. - atom1 -- The first atom (ObjCrystMolAtomParSet) in the bond angle - atom2 -- The second (central) atom (ObjCrystMolAtomParSet) in the - bond angle - atom3 -- The third (mutated) atom (ObjCrystMolAtomParSet) in the - bond angle - value -- An initial value for the bond length. If this is None - (default), then the current bond angle between the atoms - will be used. - const -- A flag indicating whether the Parameter is constant - (default False). - mode -- A pre-built mode to place in this Parameter. If this is - None (default), then a StretchMode will be built. + Attributes + ---------- + name + The name of the ObjCrystBondAngleParameter. + atom1 + The first atom (ObjCrystMolAtomParSet) in the bond angle + atom2 + The second (central) atom (ObjCrystMolAtomParSet) in the + bond angle + atom3 + The third (mutated) atom (ObjCrystMolAtomParSet) in the + bond angle + value + An initial value for the bond length. If this is None + (default), then the current bond angle between the atoms + will be used. + const + A flag indicating whether the Parameter is constant + (default False). + mode + A pre-built mode to place in this Parameter. If this is + None (default), then a StretchMode will be built. """ # Create the stretch mode @@ -1218,11 +1453,15 @@ def setConst(self, const=True, value=None): This sets the underlying ObjCrystMolAtomParSet positions const as well. - const -- Flag indicating if the Parameter is constant (default - True). - value -- An optional value for the Parameter (default None). If this - is not None, then the Parameter will get a new value, - constant or otherwise. + Attributes + ---------- + const + Flag indicating if the Parameter is constant (default + True). + value + An optional value for the Parameter (default None). If this + is not None, then the Parameter will get a new value, + constant or otherwise. """ StretchModeParameter.setConst(self, const, value) for a in [self.atom1, self.atom2, self.atom3]: @@ -1263,27 +1502,42 @@ class ObjCrystDihedralAngleParameter(StretchModeParameter): See precautions in the ObjCrystBondLengthParameter class. Attributes - atom1 -- The first ObjCrystMolAtomParSet in the dihedral angle - atom2 -- The second (central) ObjCrystMolAtomParSet in the dihedral - angle - atom3 -- The third (central) ObjCrystMolAtomParSet in the dihedral angle - atom4 -- The fourth (mutated) ObjCrystMolAtomParSet in the dihedral - angle - matoms -- The set of all mutated ObjCrystMolAtomParSets - molecule -- The ObjCrystMoleculeParSet the atoms belong to - mode -- The pyobjcryst.molecule.StretchModeTorsion for the dihedral - angle + ---------- + atom1 + The first ObjCrystMolAtomParSet in the dihedral angle + atom2 + The second (central) ObjCrystMolAtomParSet in the dihedral + angle + atom3 + The third (central) ObjCrystMolAtomParSet in the dihedral angle + atom4 + The fourth (mutated) ObjCrystMolAtomParSet in the dihedral + angle + matoms + The set of all mutated ObjCrystMolAtomParSets + molecule + The ObjCrystMoleculeParSet the atoms belong to + mode + The pyobjcryst.molecule.StretchModeTorsion for the dihedral + angle Inherited Attributes - name -- A name for this Parameter. - const -- A flag indicating whether this is considered a constant. - _value -- The value of the Parameter. Modified with 'setValue'. - value -- Property for 'getValue' and 'setValue'. - constraint -- A callable that calculates the value of this Parameter. If - this is None (None), the the Parameter is responsible for its - own value. The callable takes no arguments. - bounds -- A 2-list defining the bounds on the Parameter. This can be - used by some optimizers when the Parameter is varied. + -------------------- + name + A name for this Parameter. + const + A flag indicating whether this is considered a constant. + _value + The value of the Parameter. Modified with 'setValue'. + value + Property for 'getValue' and 'setValue'. + constraint + A callable that calculates the value of this Parameter. If + this is None (None), the the Parameter is responsible for its + own value. The callable takes no arguments. + bounds + A 2-list defining the bounds on the Parameter. This can be + used by some optimizers when the Parameter is varied. """ def __init__( @@ -1299,22 +1553,32 @@ def __init__( ): """Create a ObjCrystDihedralAngleParameter. - name -- The name of the ObjCrystDihedralAngleParameter - atom1 -- The first atom (ObjCrystMolAtomParSet) in the dihderal - angle - atom2 -- The second (central) atom (ObjCrystMolAtomParSet) in the - dihderal angle - atom3 -- The third (central) atom (ObjCrystMolAtomParSet) in the - dihderal angle - atom4 -- The fourth (mutated) atom (ObjCrystMolAtomParSet) in the - dihderal angle - value -- An initial value for the bond length. If this is None - (default), then the current dihedral angle between atoms - will be used. - const -- A flag indicating whether the Parameter is constant - (default False). - mode -- A pre-built mode to place in this Parameter. If this is - None (default), then a StretchMode will be built. + Attributes + ---------- + name + The name of the ObjCrystDihedralAngleParameter + atom1 + The first atom (ObjCrystMolAtomParSet) in the dihderal + angle + atom2 + The second (central) atom (ObjCrystMolAtomParSet) in the + dihderal angle + atom3 + The third (central) atom (ObjCrystMolAtomParSet) in the + dihderal angle + atom4 + The fourth (mutated) atom (ObjCrystMolAtomParSet) in the + dihderal angle + value + An initial value for the bond length. If this is None + (default), then the current dihedral angle between atoms + will be used. + const + A flag indicating whether the Parameter is constant + (default False). + mode + A pre-built mode to place in this Parameter. If this is + None (default), then a StretchMode will be built. """ # Create the stretch mode @@ -1352,11 +1616,15 @@ def setConst(self, const=True, value=None): This sets the underlying ObjCrystMolAtomParSet positions const as well. - const -- Flag indicating if the Parameter is constant (default - True). - value -- An optional value for the Parameter (default None). If this - is not None, then the Parameter will get a new value, - constant or otherwise. + Attributes + ---------- + const + Flag indicating if the Parameter is constant (default + True). + value + An optional value for the Parameter (default None). If this + is not None, then the Parameter will get a new value, + constant or otherwise. """ StretchModeParameter.setConst(self, const, value) for a in [self.atom1, self.atom2, self.atom3, self.atom4]: @@ -1390,35 +1658,47 @@ def getValue(self): class ObjCrystCrystalParSet(SrRealParSet): """A adaptor for pyobjcryst.crystal.Crystal instance. - This class derives from diffpy.srfit.fitbase.parameterset.ParameterSet. See - this class for base attributes. - - Attributes: - stru -- The adapted pyobjcryst.Crystal. - scatterers -- The list of aggregated ScattererParSets (either - ObjCrystAtomParSet or ObjCrystMoleculeParSet), provided for - convenience. - _sgpars -- A BaseSpaceGroupParameters object containing free structure - Parameters. See the diffpy.srfit.structure.sgconstraints - module. - sgpars -- property that creates _sgpars when it is needed. - angunits -- "rad", the units of angle - - Managed Parameters: - a, b, c, alpha, beta, gamma -- Lattice parameters (ParameterAdapter) - - Managed ParameterSets: - -- A ObjCrystScattererParSet (either ObjCrystAtomParSet or - ObjCrystMoleculeParSet), where is the name of the - adapted pyobjcryst.atom.Atom or - pyobjcryst.molecule.Molecule. + This class derives from diffpy.srfit.fitbase.parameterset.ParameterSet. + See this class for base attributes. + + Attributes + ---------- + stru + The adapted pyobjcryst.Crystal. + scatterers + The list of aggregated ScattererParSets (either + ObjCrystAtomParSet or ObjCrystMoleculeParSet), provided for + convenience. + _sgpars + A BaseSpaceGroupParameters object containing free structure + Parameters. See the diffpy.srfit.structure.sgconstraints + module. + sgpars + property that creates _sgpars when it is needed. + angunits + "rad", the units of angle + + Parameters + ---------- + x + Scatterer position in crystal coordinates (ParameterWraper) + y + Scatterer position in crystal coordinates (ParameterWraper) + z + Scatterer position in crystal coordinates (ParameterWraper) + occ + Occupancy of the scatterer on its crystal site (ParameterWraper) """ def __init__(self, name, cryst): """Initialize. - name -- A name for this ParameterSet - cryst -- An pyobjcryst.Crystal instance. + Attributes + ---------- + name + A name for this ParameterSet + cryst + An pyobjcryst.Crystal instance. """ SrRealParSet.__init__(self, name) self.angunits = "rad" @@ -1486,7 +1766,10 @@ def _constrainSpaceGroup(self): def _createSpaceGroup(sgobjcryst): """Create a diffpy.structure SpaceGroup object from pyobjcryst. - sgobjcryst -- A pyobjcryst.spacegroup.SpaceGroup instance. + Attributes + ---------- + sgobjcryst + A pyobjcryst.spacegroup.SpaceGroup instance. This uses the actual space group operations from the pyobjcryst.spacegroup.SpaceGroup instance so there is no ambiguity diff --git a/src/diffpy/srfit/structure/sgconstraints.py b/src/diffpy/srfit/structure/sgconstraints.py index 68cb7734..72df87c1 100644 --- a/src/diffpy/srfit/structure/sgconstraints.py +++ b/src/diffpy/srfit/structure/sgconstraints.py @@ -41,24 +41,33 @@ def constrainAsSpaceGroup( symmetry. Passed scatterers are explicitly constrained to the specified space group. The ADPs and lattice may be constrained as well. - Arguments: - phase -- A BaseStructure object. - spacegroup -- The space group number, symbol or an instance of - SpaceGroup class from diffpy.structure package. - sgoffset -- Optional offset for sg origin (default [0, 0, 0]). - scatterers -- The scatterer ParameterSets to constrain. If scatterers - is None (default), then all scatterers accessible from - phase.getScatterers will be constrained. - constrainlat -- Flag indicating whether to constrain the lattice - (default True). - constrainadps -- Flag indicating whether to constrain the ADPs - (default True). - adpsymbols -- A list of the ADP names. By default this is equal to - diffpy.structure.symmetryutilities.stdUsymbols (U11, - U22, etc.). The names must be given in the same order - as stdUsymbols. - isosymbol -- Symbol for isotropic ADP (default "Uiso"). If None, - isotropic ADPs will be constrained via the anisotropic ADPs. + Parameters + ---------- + phase + A BaseStructure object. + spacegroup + The space group number, symbol or an instance of + SpaceGroup class from diffpy.structure package. + sgoffset + Optional offset for sg origin (default [0, 0, 0]). + scatterers + The scatterer ParameterSets to constrain. If scatterers + is None (default), then all scatterers accessible from + phase.getScatterers will be constrained. + constrainlat + Flag indicating whether to constrain the lattice + (default True). + constrainadps + Flag indicating whether to constrain the ADPs + (default True). + adpsymbols + A list of the ADP names. By default this is equal to + diffpy.structure.symmetryutilities.stdUsymbols (U11, + U22, etc.). The names must be given in the same order + as stdUsymbols. + isosymbol + Symbol for isotropic ADP (default "Uiso"). If None, + isotropic ADPs will be constrained via the anisotropic ADPs. New Parameters that are used in constraints are created within a SpaceGroupParameters object, which is returned from this function. @@ -68,22 +77,30 @@ def constrainAsSpaceGroup( The lattice constraints are applied as following. - Crystal System: - Triclinic -- No constraints. - Monoclinic -- alpha and beta are fixed to 90 unless alpha != beta and - alpha == gamma, in which case alpha and gamma are fixed - to 90. - Orthorhombic -- alpha, beta and gamma are fixed to 90. - Tetragonal -- b is constrained to a and alpha, beta and gamma are - fixed to 90. - Trigonal -- If gamma == 120, then b is constrained to a, alpha - and beta are fixed to 90 and gamma is fixed to 120. - Otherwise, b and c are constrained to a, beta and gamma - are fixed to alpha. - Hexagonal -- b is constrained to a, alpha and beta are fixed to 90 - and gamma is fixed to 120. - Cubic -- b and c are constrained to a, and alpha, beta and - gamma are fixed to 90. + Crystal System + -------------- + Triclinic + No constraints. + Monoclinic + alpha and beta are fixed to 90 unless alpha != beta and + alpha == gamma, in which case alpha and gamma are fixed + to 90. + Orthorhombic + alpha, beta and gamma are fixed to 90. + Tetragonal + b is constrained to a and alpha, beta and gamma are + fixed to 90. + Trigonal + If gamma == 120, then b is constrained to a, alpha + and beta are fixed to 90 and gamma is fixed to 120. + Otherwise, b and c are constrained to a, beta and gamma + are fixed to alpha. + Hexagonal + b is constrained to a, alpha and beta are fixed to 90 + and gamma is fixed to 120. + Cubic + b and c are constrained to a, and alpha, beta and + gamma are fixed to 90. """ from diffpy.structure.spacegroups import GetSpaceGroup, SpaceGroup @@ -118,7 +135,9 @@ def _constrainAsSpaceGroup( """Restricted interface to constrainAsSpaceGroup. Arguments: As constrainAsSpaceGroup, except - sg -- diffpy.structure.spacegroups.SpaceGroup instance + ------------------------------------------- + sg + diffpy.structure.spacegroups.SpaceGroup instance """ from diffpy.structure.symmetryutilities import stdUsymbols @@ -155,7 +174,9 @@ class is to make it easy to access the free variables of a structure for scripting purposes. Attributes - name -- "sgpars" + ---------- + name + "sgpars" """ def __init__(self, name="sgpars"): @@ -169,9 +190,13 @@ def __init__(self, name="sgpars"): def addParameter(self, par, check=True): """Store a Parameter. - par -- The Parameter to be stored. - check -- If True (default), a ValueError is raised a Parameter of - the specified name has already been inserted. + Attributes + ---------- + par + The Parameter to be stored. + check + If True (default), a ValueError is raised a Parameter of + the specified name has already been inserted. Raises ValueError if the Parameter has no name. """ @@ -192,24 +217,39 @@ class SpaceGroupParameters(BaseSpaceGroupParameters): attribute access of a ParameterSet. Attributes - name -- "sgpars" - phase -- The constrained BaseStructure object. - sg -- The diffpy.structure.spacegroups.SpaceGroup object - corresponding to the space group. - sgoffset -- Optional offset for the space group origin. - scatterers -- The constrained scatterer ParameterSets. - constrainlat -- Flag indicating whether the lattice is constrained. - constrainadps -- Flag indicating whether the ADPs are constrained. - adpsymbols -- A list of the ADP names. - _xyzpars -- BaseSpaceGroupParameters of free xyz Parameters that are - constrained to. - xyzpars -- Property that populates _xyzpars. - _latpars -- BaseSpaceGroupParameters of free lattice Parameters that - are constrained to. - latpars -- Property that populates _latpars. - _adppars -- BaseSpaceGroupParameters of free ADPs that are constrained - to. - adppars -- Property that populates _adppars. + ---------- + name + "sgpars" + phase + The constrained BaseStructure object. + sg + The diffpy.structure.spacegroups.SpaceGroup object + corresponding to the space group. + sgoffset + Optional offset for the space group origin. + scatterers + The constrained scatterer ParameterSets. + constrainlat + Flag indicating whether the lattice is constrained. + constrainadps + Flag indicating whether the ADPs are constrained. + adpsymbols + A list of the ADP names. + _xyzpars + BaseSpaceGroupParameters of free xyz Parameters that are + constrained to. + xyzpars + Property that populates _xyzpars. + _latpars + BaseSpaceGroupParameters of free lattice Parameters that + are constrained to. + latpars + Property that populates _latpars. + _adppars + BaseSpaceGroupParameters of free ADPs that are constrained + to. + adppars + Property that populates _adppars. """ def __init__( @@ -225,22 +265,31 @@ def __init__( ): """Create the SpaceGroupParameters object. - Arguments: - phase -- A BaseStructure object to be constrained. - sg -- The space group number or symbol (compatible with - diffpy.structure.spacegroups.GetSpaceGroup. - sgoffset -- Optional offset for sg origin. - scatterers -- The scatterer ParameterSets to constrain. If scatterers - is None, then all scatterers accessible from - phase.getScatterers will be constrained. - constrainlat -- Flag indicating whether to constrain the lattice. - constrainadps -- Flag indicating whether to constrain the ADPs. - adpsymbols -- A list of the ADP names. The names must be given in the - same order as - diffpy.structure.symmetryutilities.stdUsymbols. - isosymbol -- Symbol for isotropic ADP (default "Uiso"). If None, - isotropic ADPs will be constrained via the anisotropic - ADPs. + Parameters + ---------- + phase + A BaseStructure object to be constrained. + sg + The space group number or symbol (compatible with + diffpy.structure.spacegroups.GetSpaceGroup. + sgoffset + Optional offset for sg origin. + scatterers + The scatterer ParameterSets to constrain. If scatterers + is None, then all scatterers accessible from + phase.getScatterers will be constrained. + constrainlat + Flag indicating whether to constrain the lattice. + constrainadps + Flag indicating whether to constrain the ADPs. + adpsymbols + A list of the ADP names. The names must be given in the + same order as + diffpy.structure.symmetryutilities.stdUsymbols. + isosymbol + Symbol for isotropic ADP (default "Uiso"). If None, + isotropic ADPs will be constrained via the anisotropic + ADPs. """ BaseSpaceGroupParameters.__init__(self) self._latpars = None @@ -421,7 +470,10 @@ def _constrainLattice(self): def _constrainXYZs(self, positions): """Constrain the positions. - positions -- The coordinates of the scatterers. + Attributes + ---------- + positions + The coordinates of the scatterers. """ from diffpy.structure.symmetryutilities import SymmetryConstraints @@ -461,7 +513,10 @@ def _constrainXYZs(self, positions): def _constrainADPs(self, positions): """Constrain the ADPs. - positions -- The coordinates of the scatterers. + Attributes + ---------- + positions + The coordinates of the scatterers. """ from diffpy.structure.symmetryutilities import ( @@ -561,8 +616,12 @@ def _constrainADPs(self, positions): def __addPar(self, parname, par): """Constrain a parameter via proxy with a specified name. - par -- Parameter to constrain - idx -- Index to identify scatterer from which par comes + Attributes + ---------- + par + Parameter to constrain + idx + Index to identify scatterer from which par comes """ newpar = ParameterProxy(parname, par) self.addParameter(newpar) @@ -711,11 +770,18 @@ def _constrainCubic(lattice): def _makeconstraint(parname, formula, scatterer, idx, ns={}): """Constrain a parameter according to a formula. - parname -- Name of parameter - formula -- Constraint formula - scatterer -- scatterer containing par of parname - idx -- Index to identify scatterer from which par comes - ns -- namespace to draw extra names from (default {}) + Attributes + ---------- + parname + Name of parameter + formula + Constraint formula + scatterer + scatterer containing par of parname + idx + Index to identify scatterer from which par comes + ns + namespace to draw extra names from (default {}) Returns the parameter if it is free. """ diff --git a/src/diffpy/srfit/structure/srrealparset.py b/src/diffpy/srfit/structure/srrealparset.py index 4bd8b877..4d7ddee3 100644 --- a/src/diffpy/srfit/structure/srrealparset.py +++ b/src/diffpy/srfit/structure/srrealparset.py @@ -26,11 +26,14 @@ class SrRealParSet(BaseStructureParSet): This derives from BaseStructureParSet and provides some extended functionality provided by SrReal. - Attributes: - stru -- The adapted object - _usesymmetry -- A flag indicating if SrReal calculators that operate on - this object should use symmetry. By default this is - True. + Attributes + ---------- + stru + The adapted object + _usesymmetry + A flag indicating if SrReal calculators that operate on + this object should use symmetry. By default this is + True. """ def __init__(self, *args, **kw): @@ -49,10 +52,14 @@ def restrainBVS(self, sig=1, scaled=False): this is also scaled by the current point-averaged chi^2 value so the restraint is roughly equally weighted in the fit. - sig -- The uncertainty on the BVS (default 1). - scaled -- A flag indicating if the restraint is scaled - (multiplied) by the unrestrained point-average chi^2 - (chi^2/numpoints) (default False). + Attributes + ---------- + sig + The uncertainty on the BVS (default 1). + scaled + A flag indicating if the restraint is scaled + (multiplied) by the unrestrained point-average chi^2 + (chi^2/numpoints) (default False). Returns the BVSRestraint object for use with the 'unrestrain' method. """ diff --git a/src/diffpy/srfit/util/inpututils.py b/src/diffpy/srfit/util/inpututils.py index 0645354a..0f9e00f0 100644 --- a/src/diffpy/srfit/util/inpututils.py +++ b/src/diffpy/srfit/util/inpututils.py @@ -25,8 +25,11 @@ def inputToString(input): This is useful when you want a method to accept a string, open file object or file name. - input -- An open file-like object, name of a file - or a string containing the input. + Attributes + ---------- + input + An open file-like object, name of a file + or a string containing the input. Returns the input in a string Raises IOError if the input is supected to be a file name, but the file diff --git a/src/diffpy/srfit/util/tagmanager.py b/src/diffpy/srfit/util/tagmanager.py index 65e4ab9e..76b99eea 100644 --- a/src/diffpy/srfit/util/tagmanager.py +++ b/src/diffpy/srfit/util/tagmanager.py @@ -28,10 +28,14 @@ class TagManager(object): Manage tags on hashable objects. Tags are strings that carry metadata. - silent -- Flag indicating whether to silently pass by when a tag - cannot be found (bool, True). If this is False, then a - KeyError will be thrown when a tag cannot be found. - _tagdict -- A dictionary of tags to sets of tagged objects. + Attributes + ---------- + silent + Flag indicating whether to silently pass by when a tag + cannot be found (bool, True). If this is False, then a + KeyError will be thrown when a tag cannot be found. + _tagdict + A dictionary of tags to sets of tagged objects. """ def __init__(self): @@ -49,8 +53,12 @@ def tag(self, obj, *tags): Tags are stored as strings. - obj -- Any hashable object to be untagged. - *tags -- Tags to apply to obj. + Attributes + ---------- + obj + Any hashable object to be untagged. + *tags + Tags to apply to obj. Raises TypeError if obj is not hashable. """ @@ -62,9 +70,13 @@ def tag(self, obj, *tags): def untag(self, obj, *tags): """Remove tags from an object. - obj -- Any hashable object to be untagged. - *tags -- Tags to remove from obj. If this is empty, then all - tags will be removed from obj. + Attributes + ---------- + obj + Any hashable object to be untagged. + *tags + Tags to remove from obj. If this is empty, then all + tags will be removed from obj. Raises KeyError if a passed tag does not apply to obj and self.silent is False