23. Mixture model evaluator¶
sasmodels.mixture¶
Mixture model¶
The product model multiplies the structure factor by the form factor, modulated by the effective radius of the form. The resulting model has a attributes of both the model description (with parameters, etc.) and the module evaluator (with call, release, etc.).
To use it, first load form factor P and structure factor S, then create ProductModel(P, S).
- class sasmodels.mixture.MixtureKernel(model_info: ModelInfo, kernels: list[Kernel], q: tuple[ndarray])¶
Bases:
KernelInstantiated kernel for mixture of models.
- Fq(call_details: CallDetails, values: np.ndarray, cutoff: np.ndarray, magnetic: float, radius_effective_mode: bool = 0) np.ndarray¶
Returns <F(q)>, <F(q)^2>, effective radius, shell volume and form:shell volume ratio. The <F(q)> term may be None if the form factor does not support direct computation of \(F(q)\)
\(P(q) = <F^2(q)>/<V>\) is used for structure factor calculations,
\[I(q) = \text{scale} \cdot P(q) \cdot S(q) + \text{background}\]For the beta approximation, this becomes
\[I(q) = \text{scale} P (1 + <F>^2/<F^2> (S - 1)) + \text{background} = \text{scale}/<V> (<F^2> + <F>^2 (S - 1)) + \text{background}\]\(<F(q)>\) and \(<F^2(q)>\) are averaged by polydispersity in shape and orientation, with each configuration \(x_k\) having form factor \(F(q, x_k)\), weight \(w_k\) and volume \(V_k\). The result is:
\[P(q)=\frac{\sum w_k F^2(q, x_k) / \sum w_k}{\sum w_k V_k / \sum w_k}\]The form factor itself is scaled by volume and contrast to compute the total scattering. This is then squared, and the volume weighted F^2 is then normalized by volume F. For a given density, the number of scattering centers is assumed to scale linearly with volume. Later scaling the resulting \(P(q)\) by the volume fraction of particles gives the total scattering on an absolute scale. Most models incorporate the volume fraction into the overall scale parameter. An exception is vesicle, which includes the volume fraction parameter in the model itself, scaling \(F\) by \(\surd V_f\) so that the math for the beta approximation works out.
By scaling \(P(q)\) by total weight \(\sum w_k\), there is no need to make sure that the polydisperisity distributions normalize to one. In particular, any distibution values \(x_k\) outside the valid domain of \(F\) will not be included, and the distribution will be implicitly truncated. This is controlled by the parameter limits defined in the model (which truncate the distribution before calling the kernel) as well as any region excluded using the INVALID macro defined within the model itself.
The volume used in the polydispersity calculation is the form volume for solid objects or the shell volume for hollow objects. Shell volume should be used within \(F\) so that the normalizing scale represents the volume fraction of the shell rather than the entire form. This corresponds to the volume fraction of shell-forming material added to the solvent.
The calculation of \(S\) requires the effective radius and the volume fraction of the particles. The model can have several different ways to compute effective radius, with the radius_effective_mode parameter used to select amongst them. The volume fraction of particles should be determined from the total volume fraction of the form, not just the shell volume fraction. This makes a difference for hollow shapes, which need to scale the volume fraction by the returned volume ratio when computing \(S\). For solid objects, the shell volume is set to the form volume so this scale factor evaluates to one and so can be used for both hollow and solid shapes.
- Iq(call_details: CallDetails, values: ndarray, cutoff: ndarray, magnetic: float) ndarray¶
Returns I(q) from the polydisperse average scattering.
\[I(q) = \text{scale} \cdot P(q) + \text{background}\]With the correct choice of model and contrast, setting scale to the volume fraction \(V_f\) of particles should match the measured absolute scattering. Some models (e.g., vesicle) have volume fraction built into the model, and do not need an additional scale.
- __annotations__ = {}¶
- __call__(call_details: CallDetails, values: ndarray, cutoff: ndarray, magnetic: float) ndarray¶
Returns I(q) from the polydisperse average scattering.
\[I(q) = \text{scale} \cdot P(q) + \text{background}\]With the correct choice of model and contrast, setting scale to the volume fraction \(V_f\) of particles should match the measured absolute scattering. Some models (e.g., vesicle) have volume fraction built into the model, and do not need an additional scale.
- __class__¶
alias of
type
- __delattr__(name, /)¶
Implement delattr(self, name).
- __dict__ = mappingproxy({'__module__': 'sasmodels.mixture', '__doc__': '\n Instantiated kernel for mixture of models.\n ', '__init__': <function MixtureKernel.__init__>, 'Iq': <function MixtureKernel.Iq>, '__call__': <function MixtureKernel.Iq>, 'release': <function MixtureKernel.release>, '__annotations__': {'results': 'Callable[[], OrderedDict]', 'dim': 'str', 'info': 'ModelInfo', 'dtype': 'np.dtype', 'q_input': 'Any', 'result': 'np.ndarray'}})¶
- __dir__()¶
Default dir() implementation.
- __doc__ = '\n Instantiated kernel for mixture of models.\n '¶
- __eq__(value, /)¶
Return self==value.
- __format__(format_spec, /)¶
Default object formatter.
- __ge__(value, /)¶
Return self>=value.
- __getattribute__(name, /)¶
Return getattr(self, name).
- __getstate__()¶
Helper for pickle.
- __gt__(value, /)¶
Return self>value.
- __hash__()¶
Return hash(self).
- classmethod __init_subclass__()¶
This method is called when a class is subclassed.
The default implementation does nothing. It may be overridden to extend subclasses.
- __le__(value, /)¶
Return self<=value.
- __lt__(value, /)¶
Return self<value.
- __module__ = 'sasmodels.mixture'¶
- __ne__(value, /)¶
Return self!=value.
- classmethod __new__(*args, **kwargs)¶
- __reduce__()¶
Helper for pickle.
- __reduce_ex__(protocol, /)¶
Helper for pickle.
- __repr__()¶
Return repr(self).
- __setattr__(name, value, /)¶
Implement setattr(self, name, value).
- __sizeof__()¶
Size of object in memory, in bytes.
- __str__()¶
Return str(self).
- classmethod __subclasshook__()¶
Abstract classes can override this to customize issubclass().
This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotImplemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the normal algorithm (and the outcome is cached).
- __weakref__¶
list of weak references to the object
- _call_kernel(call_details: CallDetails, values: np.ndarray, cutoff: np.ndarray, magnetic: float, radius_effective_mode: bool) None¶
Call the kernel. Subclasses defining kernels for particular execution engines need to provide an implementation for this.
- dim: str = None¶
Kernel dimension, either “1d” or “2d”.
- dtype: np.dtype = None¶
Numerical precision for the computation.
- release() None¶
Free resources associated with the kernel.
- result: np.ndarray = None¶
Place to hold result of _call_kernel() for subclass.
- class sasmodels.mixture.MixtureModel(model_info: ModelInfo, parts: list[KernelModel])¶
Bases:
KernelModelModel definition for mixture of models.
- __annotations__ = {}¶
- __class__¶
alias of
type
- __delattr__(name, /)¶
Implement delattr(self, name).
- __dict__ = mappingproxy({'__module__': 'sasmodels.mixture', '__doc__': '\n Model definition for mixture of models.\n ', '__init__': <function MixtureModel.__init__>, 'make_kernel': <function MixtureModel.make_kernel>, 'release': <function MixtureModel.release>, '__annotations__': {'info': 'ModelInfo', 'dtype': 'np.dtype'}})¶
- __dir__()¶
Default dir() implementation.
- __doc__ = '\n Model definition for mixture of models.\n '¶
- __eq__(value, /)¶
Return self==value.
- __format__(format_spec, /)¶
Default object formatter.
- __ge__(value, /)¶
Return self>=value.
- __getattribute__(name, /)¶
Return getattr(self, name).
- __getstate__()¶
Helper for pickle.
- __gt__(value, /)¶
Return self>value.
- __hash__()¶
Return hash(self).
- __init__(model_info: ModelInfo, parts: list[KernelModel]) None¶
- classmethod __init_subclass__()¶
This method is called when a class is subclassed.
The default implementation does nothing. It may be overridden to extend subclasses.
- __le__(value, /)¶
Return self<=value.
- __lt__(value, /)¶
Return self<value.
- __module__ = 'sasmodels.mixture'¶
- __ne__(value, /)¶
Return self!=value.
- classmethod __new__(*args, **kwargs)¶
- __reduce__()¶
Helper for pickle.
- __reduce_ex__(protocol, /)¶
Helper for pickle.
- __repr__()¶
Return repr(self).
- __setattr__(name, value, /)¶
Implement setattr(self, name, value).
- __sizeof__()¶
Size of object in memory, in bytes.
- __str__()¶
Return str(self).
- classmethod __subclasshook__()¶
Abstract classes can override this to customize issubclass().
This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotImplemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the normal algorithm (and the outcome is cached).
- __weakref__¶
list of weak references to the object
- dtype: np.dtype = None¶
- make_kernel(q_vectors: list[ndarray]) MixtureKernel¶
Instantiate a kernel for evaluating the model at q_vectors.
- release() None¶
Free resources associated with the kernel.
- class sasmodels.mixture._MixtureParts(model_info: ModelInfo, kernels: list[Kernel], call_details: CallDetails, values: ndarray)¶
Bases:
objectMixture component iterator.
- __class__¶
alias of
type
- __delattr__(name, /)¶
Implement delattr(self, name).
- __dict__ = mappingproxy({'__module__': 'sasmodels.mixture', '__doc__': '\n Mixture component iterator.\n ', '__init__': <function _MixtureParts.__init__>, '__iter__': <function _MixtureParts.__iter__>, '__next__': <function _MixtureParts.__next__>, 'next': <function _MixtureParts.__next__>, '_part_details': <function _MixtureParts._part_details>, '_part_values': <function _MixtureParts._part_values>, '__dict__': <attribute '__dict__' of '_MixtureParts' objects>, '__weakref__': <attribute '__weakref__' of '_MixtureParts' objects>, '__annotations__': {}})¶
- __dir__()¶
Default dir() implementation.
- __doc__ = '\n Mixture component iterator.\n '¶
- __eq__(value, /)¶
Return self==value.
- __format__(format_spec, /)¶
Default object formatter.
- __ge__(value, /)¶
Return self>=value.
- __getattribute__(name, /)¶
Return getattr(self, name).
- __getstate__()¶
Helper for pickle.
- __gt__(value, /)¶
Return self>value.
- __hash__()¶
Return hash(self).
- __init__(model_info: ModelInfo, kernels: list[Kernel], call_details: CallDetails, values: ndarray) None¶
- classmethod __init_subclass__()¶
This method is called when a class is subclassed.
The default implementation does nothing. It may be overridden to extend subclasses.
- __iter__() _MixtureParts¶
- __le__(value, /)¶
Return self<=value.
- __lt__(value, /)¶
Return self<value.
- __module__ = 'sasmodels.mixture'¶
- __ne__(value, /)¶
Return self!=value.
- classmethod __new__(*args, **kwargs)¶
- __next__() tuple[list[Callable], CallDetails, ndarray]¶
- __reduce__()¶
Helper for pickle.
- __reduce_ex__(protocol, /)¶
Helper for pickle.
- __repr__()¶
Return repr(self).
- __setattr__(name, value, /)¶
Implement setattr(self, name, value).
- __sizeof__()¶
Size of object in memory, in bytes.
- __str__()¶
Return str(self).
- classmethod __subclasshook__()¶
Abstract classes can override this to customize issubclass().
This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotImplemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the normal algorithm (and the outcome is cached).
- __weakref__¶
list of weak references to the object
- _part_details(info: ModelInfo, par_index: int) CallDetails¶
- next() tuple[list[Callable], CallDetails, ndarray]¶