refnx.reflect¶

class
refnx.reflect.
Component
[source]¶ Bases:
object
A base class for describing the structure of a subset of an interface.

__or__
(other)[source]¶ OR’ing components can create a
Structure
. Parameters
other (refnx.reflect.Structure`, refnx.reflect.Component) – Combines with this component to make a Structure
 Returns
s – The created Structure
 Return type
Examples
>>> air = SLD(0, name='air') >>> sio2 = SLD(3.47, name='SiO2') >>> si = SLD(2.07, name='Si') >>> structure = air  sio2(20, 3)  si(0, 3)

logp
()[source]¶ The logprobability that this Component adds to the total logprior term. Do not include logprobability terms for the actual parameters, these are automatically included elsewhere.
 Returns
logp – Logprobability
 Return type

property
parameters
¶ refnx.analysis.Parameters
associated with this component

slabs
(structure=None)[source]¶ The slab representation of this component
 Parameters
structure (refnx.reflect.Structure) – The Structure hosting the Component.
 Returns
slabs (np.ndarray) – Slab representation of this Component. Has shape (N, 5).
 slab[N, 0]
thickness of layer N
 slab[N, 1]
SLD.real of layer N (not including solvent)
 slab[N, 2]
overall SLD.imag of layer N (not including solvent)
 slab[N, 3]
roughness between layer N and N1
 slab[N, 4]
volume fraction of solvent in layer N.
If a Component returns None, then it doesn’t have any slabs.


class
refnx.reflect.
LipidLeaflet
(apm, b_heads, vm_heads, thickness_heads, b_tails, vm_tails, thickness_tails, rough_head_tail, rough_preceding_mono, head_solvent=None, tail_solvent=None, reverse_monolayer=False, name='')[source]¶ Bases:
refnx.reflect.structure.Component
Describes a lipid leaflet Component at an interface
 Parameters
APM (float or refnx.analysis.Parameter) –
b_heads (float, refnx.analysis.Parameter, complex or SLD) – Sum of coherent scattering lengths of head group (Angstrom). When an SLD is provided it is simply an easy way to provide a complex value. LipidLeaflet.b_heads_real is set to SLD.real, etc.
vm_heads (float or refnx.analysis.Parameter) – Molecular volume of head group (Angstrom**2)
thickness_heads (float or refnx.analysis.Parameter) – Thickness of head group region (Angstrom)
b_tails (float, refnx.analysis.Parameter, complex or SLD) – Sum of coherent scattering lengths of tail group (Angstrom). When an SLD is provided it is simply an easy way to provide a complex value. LipidLeaflet.b_tails_real is set to SLD.real, etc.
vm_tails (float or refnx.analysis.Parameter) – Molecular volume of tail group (Angstrom**2)
thickness_tails (float or refnx.analysis.Parameter) – Thickness of head group region (Angstrom)
rough_head_tail (float or refnx.analysis.Parameter) – Roughness of headtail group (Angstrom)
rough_preceding_mono (float or refnx.analysis.Parameter) – Roughness between preceding component (in the fronting direction) and the monolayer (Angstrom). If reverse_monolayer is False then this is the roughness between the preceding component and the heads, if reverse_monolayer is True then this is the roughness between the preceding component and the tails.
head_solvent (None, float, complex, refnx.reflect.SLD) – Solvent for the head region. If None, then solvation will be performed by the parent Structure, using the Structure.solvent attribute. Other options are coerced to an SLD object using SLD(float  complex). A float/complex argument is the SLD of the solvent (10**6 Angstrom**2).
tail_solvent (None, float, complex, refnx.reflect.SLD) – Solvent for the tail region. If None, then solvation will be performed by the parent Structure, using the Structure.solvent attribute. Other options are coerced to an SLD object using SLD(float  complex). A float/complex argument is the SLD of the solvent (10**6 Angstrom**2).
reverse_monolayer (bool, optional) – The default is to have heads closer to the fronting medium and tails closer to the backing medium. If reverse_monolayer is True then the tails will be closer to the fronting medium and heads closer to the backing medium.
name (str, optional) – The name for the component
Notes
The sum of coherent scattering lengths must be in Angstroms, the volume must be in cubic Angstroms. This is because the SLD of a tail group is calculated as b_tails / vm_tails * 1e6 to achieve the units 10**6 Angstrom**2.

logp
()[source]¶ The logprobability that this Component adds to the total logprior term. Do not include logprobability terms for the actual parameters, these are automatically included elsewhere.
 Returns
logp – Logprobability
 Return type

property
parameters
¶ refnx.analysis.Parameters
associated with this component

slabs
(structure=None)[source]¶ Slab representation of monolayer, as an array
 Parameters
structure (refnx.reflect.Structure) – The Structure hosting this Component

class
refnx.reflect.
MixedReflectModel
(structures, scales=None, bkg=1e07, name='', dq=5.0, threads=1, quad_order=17)[source]¶ Bases:
object
Calculates an incoherent average of reflectivities from a sequence of structures. Such a situation may occur if a sample is not uniform over its illuminated area.
 Parameters
structures (sequence of refnx.reflect.Structure) – The interfacial structures to incoherently average
scales (None, sequence of float or refnx.analysis.Parameter, optional) – scale factors. The reflectivities calculated from each of the structures are multiplied by their respective scale factor during overall summation. These values are turned into Parameters during the construction of this object. You must supply a scale factor for each of the structures. If scales is None, then default scale factors are used: [1 / len(structures)] * len(structures). It is a good idea to set the lower bound of each scale factor to zero (not done by default).
bkg (float or refnx.analysis.Parameter, optional) – linear background added to the overall reflectivity. This is turned into a Parameter during the construction of this object.
name (str, optional) – Name of the mixed Model
dq (float or refnx.analysis.Parameter, optional) –
dq == 0 then no resolution smearing is employed.
 dq is a float or refnx.analysis.Parameter
a constant dQ/Q resolution smearing is employed. For 5% resolution smearing supply 5.
However, if x_err is supplied to the model method, then that overrides any setting given here. This value is turned into a Parameter during the construction of this object.
threads (int, optional) – Specifies the number of threads for parallel calculation. This option is only applicable if you are using the
_creflect
module. The option is ignored if using the pure python calculator,_reflect
. If threads == 1 then all available processors are used.quad_order (int, optional) – the order of the Gaussian quadrature polynomial for doing the resolution smearing. default = 17. Don’t choose less than 13. If quad_order == ‘ultimate’ then adaptive quadrature is used. Adaptive quadrature will always work, but takes a _long_ time (2 or 3 orders of magnitude longer). Fixed quadrature will always take a lot less time. BUT it won’t necessarily work across all samples. For example, 13 points may be fine for a thin layer, but will be atrocious at describing a multilayer with bragg peaks.

__call__
(x, p=None, x_err=None)[source]¶ Calculate the generative model
 Parameters
x (float or np.ndarray) – q values for the calculation.
p (refnx.analysis.Parameters, optional) – parameters required to calculate the model
x_err (np.ndarray) – dq resolution smearing values for the dataset being considered.
 Returns
reflectivity – Calculated reflectivity
 Return type
np.ndarray

property
bkg
¶ refnx.analysis.Parameter
 linear background added to all model values.

property
dq
¶ 
 dq.value == 0
no resolution smearing is employed.
 dq.value > 0
a constant dQ/Q resolution smearing is employed. For 5% resolution smearing supply 5. However, if x_err is supplied to the model method, then that overrides any setting reported here.

logp
()[source]¶ Additional logprobability terms for the reflectivity model. Do not include logprobability terms for model parameters, these are automatically calculated elsewhere.
 Returns
logp – logprobability of structure.
 Return type

model
(x, p=None, x_err=None)[source]¶ Calculate the reflectivity of this model
 Parameters
x (float or np.ndarray) – q values for the calculation.
p (refnx.analysis.Parameter, optional) – parameters required to calculate the model
x_err (np.ndarray) – dq resolution smearing values for the dataset being considered.
 Returns
reflectivity
 Return type
np.ndarray

property
parameters
¶ refnx.analysis.Parameters
 parameters associated with this model.

property
scales
¶ refnx.analysis.Parameter
 the reflectivity from each of the structures are multiplied by these values to account for patchiness.

property
structures
¶ list of
refnx.reflect.Structure
that describe the patchiness of the surface.

class
refnx.reflect.
Motofit
[source]¶ Bases:
object
An interactive slab modeller (Jupyter/ipywidgets based) for Neutron and Xray reflectometry data.
The interactive modeller is designed to be used in a Jupyter notebook.
>>> # specify that plots are in a separate graph window >>> %matplotlib qt
>>> # alternately if you want the graph to be embedded in the notebook use >>> # %matplotlib notebook
>>> from refnx.reflect import Motofit >>> # create an instance of the modeller >>> app = Motofit() >>> # display it in the notebook by calling the object with a datafile. >>> app('dataset1.txt') >>> # lets fit a different dataset >>> app2 = Motofit() >>> app2('dataset2.txt')
The Motofit instance has several useful attributes that can be used in other cells. For example, one can access the objective and curvefitter attributes for more advanced fitting functionality than is available in the GUI. A code attribute can be used to retrieve a Python code fragment that can be used as a basis for developing more complicated models, such as interparameter constraints, global fitting, etc.

dataset
¶ The dataset associated with the modeller
 Type

model
¶ Calculates a theoretical model, from an interfacial structure (model.Structure).

objective
¶ The Objective that allows one to compare the model against the data.

curvefitter
¶ Object for fitting the data based on the objective.

fig
¶ Graph displaying the data.
 Type
matplotlib.Figure

__call__
(data=None, model=None)[source]¶ Display the Motofit GUI in a Jupyter notebook cell.
 Parameters
data (refnx.dataset.Data1D) – The dataset to associate with the Motofit instance.
model (refnx.reflect.ReflectModel or str or filelike) – A model to associate with the data. If model is a str or filelike then the load_model method will be used to try and load the model from file. This assumes that the file is a pickle of a ReflectModel

property
code
Executable Python code fragment for the GUI model.

property
curvefitter

do_fit
(*args)[source]¶ Ask the Motofit object to perform a fit (differential evolution).
 Parameters
change –
Notes
After performing the fit the Jupyter display is updated.

load_data
(data)[source]¶ Load a dataset into the Motofit instance.
 Parameters
data (refnx.dataset.Data1D, or str, or filelike) –

load_model
(*args, f=None)[source]¶ Load a serialised model. If f is not specified then an attempt will be made to find a model corresponding to the current dataset name, ‘model_’ + self.dataset.name + ‘.pkl’. If there is no current dataset then the most recent model will be loaded.
 Parameters
f (file like or str, optional) – pickle file to load model from.

save_model
(*args, f=None)[source]¶ Serialise a model to a pickle file. If f is not specified then the file name is constructed from the current dataset name; if there is no current dataset then the filename is constructed from the current time. These constructed filenames will be in the current working directory, for a specific save location f must be provided.
 Parameters
f (file like or str, optional) – File to save model to.

set_model
(model)[source]¶ Change the refnx.reflect.ReflectModel associated with the Motofit instance.
 Parameters
model (refnx.reflect.ReflectModel) –


class
refnx.reflect.
ReflectModel
(structure, scale=1, bkg=1e07, name='', dq=5.0, threads=1, quad_order=17)[source]¶ Bases:
object
 Parameters
structure (refnx.reflect.Structure) – The interfacial structure.
scale (float or refnx.analysis.Parameter, optional) – scale factor. All model values are multiplied by this value before the background is added. This is turned into a Parameter during the construction of this object.
bkg (float or refnx.analysis.Parameter, optional) – Qindependent constant background added to all model values. This is turned into a Parameter during the construction of this object.
name (str, optional) – Name of the Model
dq (float or refnx.analysis.Parameter, optional) –
dq == 0 then no resolution smearing is employed.
 dq is a float or refnx.analysis.Parameter
a constant dQ/Q resolution smearing is employed. For 5% resolution smearing supply 5.
However, if x_err is supplied to the model method, then that overrides any setting given here. This value is turned into a Parameter during the construction of this object.
threads (int, optional) – Specifies the number of threads for parallel calculation. This option is only applicable if you are using the
_creflect
module. The option is ignored if using the pure python calculator,_reflect
. If threads == 1 then all available processors are used.quad_order (int, optional) – the order of the Gaussian quadrature polynomial for doing the resolution smearing. default = 17. Don’t choose less than 13. If quad_order == ‘ultimate’ then adaptive quadrature is used. Adaptive quadrature will always work, but takes a _long_ time (2 or 3 orders of magnitude longer). Fixed quadrature will always take a lot less time. BUT it won’t necessarily work across all samples. For example, 13 points may be fine for a thin layer, but will be atrocious at describing a multilayer with bragg peaks.

__call__
(x, p=None, x_err=None)[source]¶ Calculate the generative model
 Parameters
x (float or np.ndarray) – q values for the calculation.
p (refnx.analysis.Parameters, optional) – parameters required to calculate the model
x_err (np.ndarray) – dq resolution smearing values for the dataset being considered.
 Returns
reflectivity – Calculated reflectivity
 Return type
np.ndarray

property
bkg
¶ refnx.analysis.Parameter
 linear background added to all model values.

property
dq
¶ 
 dq.value == 0
no resolution smearing is employed.
 dq.value > 0
a constant dQ/Q resolution smearing is employed. For 5% resolution smearing supply 5. However, if x_err is supplied to the model method, then that overrides any setting reported here.

logp
()[source]¶ Additional logprobability terms for the reflectivity model. Do not include logprobability terms for model parameters, these are automatically included elsewhere.
 Returns
logp – logprobability of structure.
 Return type

model
(x, p=None, x_err=None)[source]¶ Calculate the reflectivity of this model
 Parameters
x (float or np.ndarray) – q values for the calculation.
p (refnx.analysis.Parameters, optional) – parameters required to calculate the model
x_err (np.ndarray) – dq resolution smearing values for the dataset being considered.
 Returns
reflectivity – Calculated reflectivity
 Return type
np.ndarray

property
parameters
¶ refnx.analysis.Parameters
 parameters associated with this model.

property
scale
¶ refnx.analysis.Parameter
 all model values are multiplied by this value before the background is added.

property
structure
¶ refnx.reflect.Structure
 object describing the interface of a reflectometry sample.

class
refnx.reflect.
SLD
(value, name='')[source]¶ Bases:
object
Object representing freely varying SLD of a material
 Parameters
value (float, complex, Parameter, Parameters) – Scattering length density of a material. Units (10**6 Angstrom**2)
name (str, optional) – Name of material.
Notes
An SLD object can be used to create a Slab:
>>> # an SLD object representing Silicon Dioxide >>> sio2 = SLD(3.47, name='SiO2') >>> # create a Slab of SiO2 20 A in thickness, with a 3 A roughness >>> sio2_layer = sio2(20, 3)
The SLD object can also be made from a complex number, or from Parameters
>>> sio2 = SLD(3.47+0.01j) >>> re = Parameter(3.47) >>> im = Parameter(0.01) >>> sio2 = SLD(re) >>> sio2 = SLD([re, im])

__call__
(thick=0, rough=0)[source]¶ Create a
Slab
. Parameters
thick (refnx.analysis.Parameter or float) – Thickness of slab in Angstrom
rough (refnx.analysis.Parameter or float) – Roughness of slab in Angstrom
 Returns
slab – The newly made Slab.
 Return type
Example
>>> # an SLD object representing Silicon Dioxide >>> sio2 = SLD(3.47, name='SiO2') >>> # create a Slab of SiO2 20 A in thickness, with a 3 A roughness >>> sio2_layer = sio2(20, 3)

property
parameters
¶ refnx.analysis.Parameters
associated with this component

class
refnx.reflect.
Slab
(thick, sld, rough, name='', vfsolv=0)[source]¶ Bases:
refnx.reflect.structure.Component
A slab component has uniform SLD over its thickness.
 Parameters
thick (refnx.analysis.Parameter or float) – thickness of slab (Angstrom)
sld (refnx.reflect.SLD, complex, or float) – (complex) SLD of film (/1e6 Angstrom**2)
rough (float) – roughness on top of this slab (Angstrom)
name (str) – Name of this slab
vfsolv (refnx.analysis.Parameter or float) – Volume fraction of solvent [0, 1]

property
parameters
¶ refnx.analysis.Parameters
associated with this component

slabs
(structure=None)[source]¶ Slab representation of this component. See
Component.slabs

class
refnx.reflect.
Spline
(extent, vs, dz, name='', interpolator=<class 'scipy.interpolate._cubic.PchipInterpolator'>, zgrad=True, microslab_max_thickness=1)[source]¶ Bases:
refnx.reflect.structure.Component
Freeform modelling of the real part of an SLD profile using spline interpolation.
 Parameters
vs (Sequence of float/Parameter) – the real part of the SLD values of each of the knots.
dz (Sequence of float/Parameter) – the lateral offset between successive knots.
name (str) – Name of component
interpolator (scipy.interpolate Univariate Interpolator, optional) – Which scipy.interpolate Univariate Interpolator to use.
zgrad (bool, optional) – If true then extra control knots are placed outside this spline with the same SLD as the materials on the left and right. With a monotonic interpolator this guarantees that the gradient is zero at either end of the interval.
microslab_max_thickness (float) – Maximum size of the microslabs approximating the spline.
Notes
This spline component only generates the real part of the SLD (thereby assuming that the imaginary part is negligible). The sequence dz are the lateral offsets of the knots normalised to a unit interval [0, 1]. The reason for using lateral offsets is so that the knots are monotonically increasing in location. When each dz offset is turned into a Parameter it is given bounds in [0, 1]. Thus with an extent of 500, and dz = [0.1, 0.2, 0.2], the knots will be at [0, 50, 150, 250, 500]. Notice that there are two extra knots for the start and end of the interval (disregarding the zgrad control knots). If
np.sum(dz) > 1
, then the knot spacings are normalised to 1. e.g. dz of [0.1, 0.2, 0.9] would result in knots (in the normalised interval) of [0, 0.0833, 0.25, 1, 1]. If vs is monotonic then the output spline will be monotonic. If vs is not monotonic then there may be regions of the spline larger or smaller than left or right. The slab representation of this component are approximated using a ‘microslab’ representation of spline. The max thickness of each microslab is microslab_max_thickness.A Spline component should not be used more than once in a given Structure.

__call__
(z, structure)[source]¶ Calculates the spline value at z
 Parameters
z (float) – Distance along spline
structure (refnx.reflect.Structure) – Structure hosting this Component
 Returns
sld – Real part of SLD
 Return type

logp
()[source]¶ The logprobability that this Component adds to the total logprior term. Do not include logprobability terms for the actual parameters, these are automatically included elsewhere.
 Returns
logp – Logprobability
 Return type

property
parameters
¶ refnx.analysis.Parameters
associated with this component

slabs
(structure=None)[source]¶ Slab representation of the spline, as an array
 Parameters
structure (refnx.reflect.Structure) – The Structure hosting this Component

class
refnx.reflect.
Stack
(components=(), name='', repeats=1)[source]¶ Bases:
collections.UserList
,refnx.reflect.structure.Component
A series of Components to be considered as one. When part of a Structure the Stack can represent a multilayer by setting the repeats attribute.
 Parameters
components (sequence) – A series of Components to initialise the stack with
name (str) – Name of the Stack
repeats (number, Parameter) – When viewed from a parent Structure the Components in this Stack will appear to be repeated repeats times. Internally repeats is rounded to the nearest integer before use, allowing it to be used as a fitting parameter.
Notes
To add Components to the Stack you can:
initialise the object with a list of Components
utilise list methods (extend, append, insert, etc)
Add by __ior__ (e.g. stack = component)
You can’t use __or__ to add Components to a stack (e.g.
Stack()  component
) OR’ing a Stack with other Components will make a Structure.
append
(item)[source]¶ Append a
Component
to the Stack. Parameters
item (refnx.reflect.Component) – The component to be added.

property
components
¶ The list of components in the sample.

property
parameters
¶ refnx.analysis.Parameters
, all the parameters associated with this structure.

slabs
(structure=None)[source]¶ Slab representation of this component. See
Component.slabs
Notes
The overall set of slabs returned by this method consists of the concatenated constituent Component slabs repeated Stack.repeats times.

class
refnx.reflect.
Structure
(components=(), name='', solvent=None, reverse_structure=False, contract=0)[source]¶ Bases:
collections.UserList
Represents the interfacial Structure of a reflectometry sample. Successive Components are added to the Structure to construct the interface.
 Parameters
components (sequence) – A sequence of Components to initialise the Structure.
name (str) – Name of this structure
solvent (refnx.reflect.SLD) – Specifies the scattering length density used for solvation. If no solvent is specified then the SLD of the solvent is assumed to be the SLD of Structure[1].slabs()[1] (after any possible slab order reversal).
reverse_structure (bool) – If Structure.reverse_structure is True then the slab representation produced by Structure.slabs is reversed. The sld profile and calculated reflectivity will correspond to this reversed structure.
contract (float) – If contract > 0 then an attempt to contract/shrink the slab representation is made. Use larger values for coarser profiles (and vice versa). A typical starting value to try might be 1.0.
Notes
If Structure.reverse_structure is True then the slab representation order is reversed. If no solvent is specified then the volume fraction of solvent in each of the Components is assumed to have the scattering length density of Structure[1].slabs()[1] after any possible slab order reversal. This slab corresponds to the scattering length density of the semiinfinite backing medium. The profile contraction specified by the contract keyword can improve calculation time for Structures created with microslicing (such as analytical profiles). If you use this option it is recommended to check the reflectivity signal with and without contraction to ensure they are comparable.
Example
>>> from refnx.reflect import SLD >>> # make the materials >>> air = SLD(0, 0) >>> # overall SLD of polymer is (1.0 + 0.001j) x 10**6 A**2 >>> polymer = SLD(1.0 + 0.0001j) >>> si = SLD(2.07) >>> # Make the structure, s, from slabs. >>> # The polymer slab has a thickness of 200 A and a air/polymer roughness >>> # of 4 A. >>> s = air(0, 0)  polymer(200, 4)  si(0, 3)

__ior__
(other)[source]¶ Build a structure by IOR’ing Structures/Components/SLDs.
Examples
>>> air = SLD(0, name='air') >>> sio2 = SLD(3.47, name='SiO2') >>> si = SLD(2.07, name='Si') >>> structure = air  sio2(20, 3) >>> structure = si(0, 4)

__or__
(other)[source]¶ Build a structure by OR’ing Structures/Components/SLDs.
Examples
>>> air = SLD(0, name='air') >>> sio2 = SLD(3.47, name='SiO2') >>> si = SLD(2.07, name='Si') >>> structure = Structure() >>> structure = air  sio2(20, 3)  si(0, 3)

append
(item)[source]¶ Append a
Component
to the Structure. Parameters
item (refnx.reflect.Component) – The component to be added.

property
components
¶ The list of components in the sample.

contract
= None¶ float if contract > 0 then an attempt to contract/shrink the slab representation is made. Use larger values for coarser profiles (and vice versa). A typical starting value to try might be 1.0.

logp
()[source]¶ logprobability for the interfacial structure. Note that if a given component is present more than once in a Structure then it’s logprob will be counted twice.
 Returns
logp – logprior for the Structure.
 Return type

property
name
¶

static
overall_sld
(slabs, solvent)[source]¶ Performs a volume fraction weighted average of the material SLD in a layer and the solvent in a layer.
 Parameters
slabs (np.ndarray) – Slab representation of the layers to be averaged.
solvent (complex or reflect.SLD) – SLD of solvating material.
 Returns
averaged_slabs – the averaged slabs.
 Return type
np.ndarray

property
parameters
¶ refnx.analysis.Parameters
, all the parameters associated with this structure.

plot
(pvals=None, samples=0, fig=None)[source]¶ Plot the structure.
Requires matplotlib be installed.
 Parameters
pvals (np.ndarray, optional) – Numeric values for the Parameter’s that are varying
samples (number) – If this structures constituent parameters have been sampled, how many samples you wish to plot on the graph.
fig (Figure instance, optional) – If fig is not supplied then a new figure is created. Otherwise the graph is created on the current axes on the supplied figure.
 Returns
fig, ax – matplotlib figure and axes objects.
 Return type
matplotlib.Figure
,matplotlib.Axes

reflectivity
(q, threads=0)[source]¶ Calculate theoretical reflectivity of this structure
 Parameters
q (arraylike) – Q values (Angstrom**1) for evaluation
threads (int, optional) – Specifies the number of threads for parallel calculation. This option is only applicable if you are using the
_creflect
module. The option is ignored if using the pure python calculator,_reflect
. If threads == 0 then all available processors are used.

property
reverse_structure
¶ bool if True then the slab representation produced by
Structure.slabs
is reversed. The sld profile and calculated reflectivity will correspond to this reversed structure.

slabs
(**kwds)[source]¶  Returns
slabs – Slab representation of this structure. Has shape (N, 5).
 slab[N, 0]
thickness of layer N
 slab[N, 1]
overall SLD.real of layer N (material AND solvent)
 slab[N, 2]
overall SLD.imag of layer N (material AND solvent)
 slab[N, 3]
roughness between layer N and N1
 slab[N, 4]
volume fraction of solvent in layer N.
 Return type
np.ndarray
Notes
If Structure.reversed is True then the slab representation order is reversed. The slab order is reversed before the solvation calculation is done. I.e. if Structure.solvent == ‘backing’ and Structure.reversed is True then the material that solvates the system is the component in Structure[0], which corresponds to Structure.slab[1].

sld_profile
(z=None)[source]¶ Calculates an SLD profile, as a function of distance through the interface.
 Parameters
z (float) – Interfacial distance (Angstrom) measured from interface between the fronting medium and the first layer.
 Returns
sld – Scattering length density / 1e6 Angstrom**2
 Return type
Notes
This can be called in vectorised fashion.

property
solvent
¶

refnx.reflect.
reflectivity
(q, slabs, scale=1.0, bkg=0.0, dq=5.0, quad_order=17, threads=1)[source]¶ Abeles matrix formalism for calculating reflectivity from a stratified medium.
 Parameters
q (np.ndarray) – The qvalues required for the calculation. \(Q=\frac{4Pi}{\lambda}\sin(\Omega)\). Units = Angstrom**1
slabs (np.ndarray) –
coefficients required for the calculation, has shape (2 + N, 4), where N is the number of layers
 slabs[0, 0]
ignored
 slabs[N, 0]
thickness of layer N
 slabs[N+1, 0]
ignored
 slabs[0, 1]
SLD_real of fronting (/1e6 Angstrom**2)
 slabs[N, 1]
SLD_real of layer N (/1e6 Angstrom**2)
 slabs[1, 1]
SLD_real of backing (/1e6 Angstrom**2)
 slabs[0, 2]
SLD_imag of fronting (/1e6 Angstrom**2)
 slabs[N, 2]
iSLD_imag of layer N (/1e6 Angstrom**2)
 slabs[1, 2]
iSLD_imag of backing (/1e6 Angstrom**2)
 slabs[0, 3]
ignored
 slabs[N, 3]
roughness between layer N1/N
 slabs[1, 3]
roughness between backing and layer N
scale (float) – scale factor. All model values are multiplied by this value before the background is added
bkg (float) – Qindependent constant background added to all model values.
dq (float or np.ndarray, optional) –
 dq == 0
no resolution smearing is employed.
 dq is a float
a constant dQ/Q resolution smearing is employed. For 5% resolution smearing supply 5.
 dq is the same shape as q
the array contains the FWHM of a Gaussian approximated resolution kernel. Point by point resolution smearing is employed. Use this option if dQ/Q varies across your dataset.
 dq.ndim == q.ndim + 2 and q.shape == dq[…, 3].shape
an individual resolution kernel is applied to each measurement point. This resolution kernel is a probability distribution function (PDF). dqvals will have the shape (qvals.shape, 2, M). There are M points in the kernel. dq[:, 0, :] holds the q values for the kernel, dq[:, 1, :] gives the corresponding probability.
quad_order (int, optional) – the order of the Gaussian quadrature polynomial for doing the resolution smearing. default = 17. Don’t choose less than 13. If quad_order == ‘ultimate’ then adaptive quadrature is used. Adaptive quadrature will always work, but takes a _long_ time (2 or 3 orders of magnitude longer). Fixed quadrature will always take a lot less time. BUT it won’t necessarily work across all samples. For example, 13 points may be fine for a thin layer, but will be atrocious at describing a multilayer with bragg peaks.
threads (int, optional) – Specifies the number of threads for parallel calculation. This option is only applicable if you are using the
_creflect
module. The option is ignored if using the pure python calculator,_reflect
. If threads == 1 then all available processors are used.
Example
>>> from refnx.reflect import reflectivity >>> q = np.linspace(0.01, 0.5, 1000) >>> slabs = np.array([[0, 2.07, 0, 0], ... [100, 3.47, 0, 3], ... [500, 0.5, 0.00001, 3], ... [0, 6.36, 0, 3]]) >>> print(reflectivity(q, slabs))

refnx.reflect.
sld_profile
(slabs, z=None)[source]¶ Calculates an SLD profile, as a function of distance through the interface.
 Parameters
z (float) – Interfacial distance (Angstrom) measured from interface between the fronting medium and the first layer.
 Returns
sld – Scattering length density / 1e6 Angstrom**2
 Return type
Notes
This can be called in vectorised fashion.

refnx.reflect.
test
= <refnx._lib._testutils.PytestTester object>¶