xrayutilities.simpack package¶
Submodules¶
xrayutilities.simpack.darwin_theory module¶

class
xrayutilities.simpack.darwin_theory.
DarwinModel
(qz, qx=0, qy=0, **kwargs)[source]¶ Bases:
xrayutilities.simpack.models.LayerModel
model class inmplementing the basics of the Darwin theory for layers materials. This class is not fully functional and should be used to derive working models for particular material systems.
To make the class functional the user needs to implement the init_structurefactors() and _calc_mono() methods

ncalls
= 0¶


class
xrayutilities.simpack.darwin_theory.
DarwinModelAlGaAs001
(qz, qx=0, qy=0, **kwargs)[source]¶ Bases:
xrayutilities.simpack.darwin_theory.DarwinModelAlloy
Darwin theory of diffraction for Al_x Ga_{1x} As layers. The model is based on separation of the sample structure into building blocks of atomic planes from which a multibeam dynamical model is calculated.

AlAs
= <xrayutilities.materials.material.Crystal object>¶

GaAs
= <xrayutilities.materials.material.Crystal object>¶

aGaAs
= 5.6532499999999999¶

classmethod
abulk
(x)[source]¶ calculate the bulk (relaxed) lattice parameter of the Al_{x}Ga_{1x}As alloy

asub
= 5.6532499999999999¶

eAl
= Al (13)¶

eAs
= As (33)¶

eGa
= Ga (31)¶

classmethod
get_dperp_apar
(x, apar, r=1)[source]¶ calculate inplane lattice parameter and the out of plane lattice plane spacing (of the atomic planes!) from composition and relaxation
Parameters: **x: chemical composition parameter**
apar: inplane lattice parameter of the material below the current layer (onto which the present layer is strained to). This value also served as a reference for the relaxation parameter. r: relaxation parameter. 1=relaxed, 0=pseudomorphic Returns: dperp, apar

re
= 2.8179403227e05¶


class
xrayutilities.simpack.darwin_theory.
DarwinModelAlloy
(qz, qx=0, qy=0, **kwargs)[source]¶ Bases:
xrayutilities.simpack.darwin_theory.DarwinModel
,abc.ABC
extension of the DarwinModel for an binary alloy system were one parameter is used to determine the chemical composition
To make the class functional the user needs to implement the get_dperp_apar() method and define the substrate lattice parameter (asub). See the DarwinModelSiGe001 class for an implementation example.

get_dperp_apar
(x, apar, r=1)[source]¶ calculate inplane lattice parameter and the out of plane lattice plane spacing (of the atomic planes!) from composition and relaxation.
Parameters: **x: chemical composition parameter**
apar: inplane lattice parameter of the material below the current layer (onto which the present layer is strained to). This value also served as a reference for the relaxation parameter. r: relaxation parameter. 1=relaxed, 0=pseudomorphic Returns: dperp, apar

make_monolayers
(s)[source]¶ create monolayer sequence from layer list
Parameters: **s: layer model. list of layer dictionaries including possibility**
to form superlattices. As an example 5 repetitions of a Si(10nm)/Ge(15nm) superlattice on Si would like like: s = [(5, [{‘t’: 100, ‘x’: 0, ‘r’: 0},
{‘t’: 150, ‘x’: 1, ‘r’: 0}]),
{‘t’: 3500000, ‘x’: 0, ‘r’: 0}]
the dictionaries must contain ‘t’: thickness in A, ‘x’: chemical composition, and either ‘r’: relaxation or ‘ai’: inplane lattice parameter. Future implementations for asymmetric peaks might include layer type ‘l’ (not yet implemented). Already now any additional property in the dictionary will be handed on to the returned monolayer list.
asub: inplane lattice parameter of the substrate Returns: monolayer list in a format understood by the simulate and xGe_profile
methods

prop_profile
(ml, prop)[source]¶ calculate the profile of chemical composition or inplane lattice spacing from a monolayer list. One value for each monolayer in the sample is returned.
Parameters: **ml: monolayer list created by make_monolayer()**
prop: name of the property which should be evaluated. Use ‘x’ for the chemical composition and ‘ai’ for the inplane lattice parameter. Returns: zm, propx: zposition, value of the property prop for every
monolayer. z=0 is the surface


class
xrayutilities.simpack.darwin_theory.
DarwinModelGaInAs001
(qz, qx=0, qy=0, **kwargs)[source]¶ Bases:
xrayutilities.simpack.darwin_theory.DarwinModelAlloy
Darwin theory of diffraction for Ga_{1x} In_x As layers. The model is based on separation of the sample structure into building blocks of atomic planes from which a multibeam dynamical model is calculated.

GaAs
= <xrayutilities.materials.material.Crystal object>¶

InAs
= <xrayutilities.materials.material.Crystal object>¶

aGaAs
= 5.6532499999999999¶

classmethod
abulk
(x)[source]¶ calculate the bulk (relaxed) lattice parameter of the Ga_{1x}In_{x}As alloy

asub
= 5.6532499999999999¶

eAs
= As (33)¶

eGa
= Ga (31)¶

eIn
= In (49)¶

classmethod
get_dperp_apar
(x, apar, r=1)[source]¶ calculate inplane lattice parameter and the out of plane lattice plane spacing (of the atomic planes!) from composition and relaxation
Parameters: **x: chemical composition parameter**
apar: inplane lattice parameter of the material below the current layer (onto which the present layer is strained to). This value also served as a reference for the relaxation parameter. r: relaxation parameter. 1=relaxed, 0=pseudomorphic Returns: dperp, apar

re
= 2.8179403227e05¶


class
xrayutilities.simpack.darwin_theory.
DarwinModelSiGe001
(qz, qx=0, qy=0, **kwargs)[source]¶ Bases:
xrayutilities.simpack.darwin_theory.DarwinModelAlloy
model class implementing the Darwin theory of diffraction for SiGe layers. The model is based on separation of the sample structure into building blocks of atomic planes from which a multibeam dynamical model is calculated.

Ge
= <xrayutilities.materials.material.Crystal object>¶

Si
= <xrayutilities.materials.material.Crystal object>¶

aSi
= 5.4310400000000003¶

asub
= 5.4310400000000003¶

eGe
= Ge (32)¶

eSi
= Si (14)¶

classmethod
get_dperp_apar
(x, apar, r=1)[source]¶ calculate inplane lattice parameter and the out of plane lattice plane spacing (of the atomic planes!) from composition and relaxation
Parameters: **x: chemical composition parameter**
apar: inplane lattice parameter of the material below the current layer (onto which the present layer is strained to). This value also served as a reference for the relaxation parameter. r: relaxation parameter. 1=relaxed, 0=pseudomorphic Returns: dperp, apar

re
= 2.8179403227e05¶


xrayutilities.simpack.darwin_theory.
GradedBuffer
(xfrom, xto, nsteps, thickness, relaxation=1)[source]¶ create a multistep graded composition buffer.
Parameters: **xfrom: begin of the composition gradient**
xto: end of the composition gradient nsteps: number of steps of the gradient thickness: total thickness of the Buffer in A relaxation: relaxation of the buffer Returns: layer object needed for the Darwin model simulation
xrayutilities.simpack.fit module¶

xrayutilities.simpack.fit.
fit_xrr
(reflmod, params, ai, data=None, eps=None, xmin=inf, xmax=inf, plot=False, verbose=False, elog=True, maxfev=500)[source]¶ optimize function for a Reflectivity Model using lmfit. The fitting parameters must be specified as instance of lmfits Parameters class.
Parameters: **reflmod: preconfigured SpecularReflectivityModel**
params: instance of lmfits Parameters class. For every layer the parameters ‘{}_thickness’, ‘{}_roughness’, ‘{}_density’, with ‘{}’ representing the layer name are supported. In addition the setup parameters:  ‘I0’ primary beam intensity  ‘background’ background added to the simulation  ‘sample_width’ size of the sample along the beam  ‘beam_width’ width of the beam in the same units  ‘resolution_width’ width of the resolution function in deg  ‘shift’ experimental shift of the incidence angle array ai: array of incidence angles for the calculation data: experimental data which should be fitted eps: (optional) error bar of the data xmin: minimum value of ai which should be used. a mask is generated to cut away other data xmax: maximum value of ai which should be used. a mask is generated to cut away other data plot: flag to decide wheter an plot should be created showing the fit’s progress. If plot is a string it will be used as figure name, which makes reusing the figures easier. verbose: flag to tell if the variation of the fitting error should be output during the fit. elog: logarithmic error during the fit maxfev: maximum number of function evaluations during the leastsq optimization Returns: res: MinimizerResult object from lmfit, which contains the fitted
parameters in res.params (see res.params.pretty_print) or try lmfit.report_fit(res)
xrayutilities.simpack.helpers module¶

xrayutilities.simpack.helpers.
coplanar_alphai
(qx, qz, en='config')[source]¶ calculate coplanar incidence angle from knowledge of the qx and qz coordinates
Parameters: **qx: inplane momentum transfer component**
qz: out of plane momentum transfer component en: xray energy (eV). By default the value from the config is used. Returns: the incidence angle in degree. points in the Laue zone are set to ‘nan’.

xrayutilities.simpack.helpers.
get_qz
(qx, alphai, en='config')[source]¶ calculate the qz position from the qx position and the incidence angle for a coplanar diffraction geometry
Parameters: **qx: inplane momentum transfer component**
alphai: incidence angle (deg) en: xray energy (eV). By default the value from the config is used. Returns: the qz position for the given incidence angle
xrayutilities.simpack.models module¶

class
xrayutilities.simpack.models.
DynamicalModel
(*args, **kwargs)[source]¶ Bases:
xrayutilities.simpack.models.SimpleDynamicalCoplanarModel
Dynamical diffraction model for specular and offspecular qzscans. Calculation of the flux of reflected and diffracted waves for general asymmetric coplanar diffraction from an arbitrary pseudomorphic multilayer is performed by a generalized 2beam theory (4 tiepoints, S and P polarizations)
The first layer in the model is always assumed to be the semiinfinite substrate indepentent of its given thickness

simulate
(alphai, hkl=None, geometry='hi_lo', rettype='intensity')[source]¶ performs the actual diffraction calculation for the specified incidence angles and uses an analytic solution for the quartic dispersion equation
Parameters: **alphai: vector of incidence angles (deg)**
hkl: Miller indices of the diffraction vector (preferable use set_hkl method to speed up repeated calculations of the same peak!) geometry: ‘hi_lo’ for grazing exit (default) and ‘lo_hi’ for grazing incidence rettype: type of the return value. ‘intensity’ (default): returns the diffracted beam flux convoluted with the resolution function; ‘field’: returns the electric field (complex) without convolution with the resolution function, ‘all’: returns the electric field, ai, af (both in degree), and the reflected intensity. Returns: vector of intensities of the diffracted signal


class
xrayutilities.simpack.models.
KinematicalModel
(*args, **kwargs)[source]¶ Bases:
xrayutilities.simpack.models.LayerModel
Kinematical diffraction model for specular and offspecular qzscans. The model calculates the kinematical contribution of one (hkl) Bragg peak, however considers the variation of the structure factor for different ‘q’. The surface geometry is specified using the Experimentobject given to the constructor.

init_chi0
()[source]¶ calculates the needed optical parameters for the simulation. If any of the materials/layers is changing its properties this function needs to be called again before another correct simulation is made. (Changes of thickness does NOT require this!)

simulate
(qz, hkl, absorption=False, refraction=False, rettype='intensity')[source]¶ performs the actual kinematical diffraction calculation on the Qz positions specified considering the contribution from a single Bragg peak.
Parameters: **qz: simulation positions along qz**
hkl: Miller indices of the Bragg peak whos truncation rod should be calculated absorption: flag to tell if absorption correction should be used refraction: flag to tell if basic refraction correction should be performed. If refraction is True absorption correction is also included independent of the absorption flag. rettype: type of the return value. ‘intensity’ (default): returns the diffracted beam flux convoluted with the resolution function; ‘field’: returns the electric field (complex) without convolution with the resolution function, ‘all’: returns the electric field, ai, af (both in degree), and the reflected intensity. Returns: vector of the ratios of the diffracted and primary fluxes


class
xrayutilities.simpack.models.
KinematicalMultiBeamModel
(*args, **kwargs)[source]¶ Bases:
xrayutilities.simpack.models.KinematicalModel
Kinematical diffraction model for specular and offspecular qzscans. The model calculates the kinematical contribution of several Bragg peaks on the truncation rod and considers the variation of the structure factor. In order to use a analytical description for the kinematic diffraction signal all layer thicknesses are changed to a multiple of the respective lattice parameter along qz. Therefore this description only works for (001) surfaces.

simulate
(qz, hkl, absorption=False, refraction=True, rettype='intensity')[source]¶ performs the actual kinematical diffraction calculation on the Qz positions specified considering the contribution from a full truncation rod
Parameters: **qz: simulation positions along qz**
hkl: Miller indices of the Bragg peak whos truncation rod should be calculated absorption: flag to tell if absorption correction should be used refraction: flag to tell if basic refraction correction should be performed. If refraction is True absorption correction is also included independent of the absorption flag. rettype: type of the return value. ‘intensity’ (default): returns the diffracted beam flux convoluted with the resolution function; ‘field’: returns the electric field (complex) without convolution with the resolution function, ‘all’: returns the electric field, ai, af (both in degree), and the reflected intensity. Returns: vector of the ratios of the diffracted and primary fluxes


class
xrayutilities.simpack.models.
LayerModel
(*args, **kwargs)[source]¶ Bases:
xrayutilities.simpack.models.Model
,abc.ABC
generic model class from which further thin film models can be derived from

class
xrayutilities.simpack.models.
Model
(experiment, **kwargs)[source]¶ Bases:
object
generic model class from which further models can be derived from

class
xrayutilities.simpack.models.
SimpleDynamicalCoplanarModel
(*args, **kwargs)[source]¶ Bases:
xrayutilities.simpack.models.KinematicalModel
Dynamical diffraction model for specular and offspecular qzscans. Calculation of the flux of reflected and diffracted waves for general asymmetric coplanar diffraction from an arbitrary pseudomorphic multilayer is performed by a simplified 2beam theory (2 tiepoints, S and P polarizations)
No restrictions are made for the surface orientation.
The first layer in the model is always assumed to be the semiinfinite substrate indepentent of its given thickness
Note
Note: This model should not be used in real life scenarios since the made approximations severely fail for distances far from the reference position.

set_hkl
(*hkl)[source]¶ To speed up future calculations of the same Bragg peak optical parameters can be precalculated using this function.
Parameters: **hkl: Miller indices of the Bragg peak for the calculation**

simulate
(alphai, hkl=None, geometry='hi_lo', idxref=1)[source]¶ performs the actual diffraction calculation for the specified incidence angles.
Parameters: **alphai: vector of incidence angles (deg)**
hkl: Miller indices of the diffraction vector (preferable use set_hkl method to speed up repeated calculations of the same peak!) geometry: ‘hi_lo’ for grazing exit (default) and ‘lo_hi’ for grazing incidence idxref: index of the reference layer. In order to get accurate peak position of the film peak you want this to be the index of the film peak (default: 1). For the substrate use 0. Returns: vector of intensities of the diffracted signal


class
xrayutilities.simpack.models.
SpecularReflectivityModel
(*args, **kwargs)[source]¶ Bases:
xrayutilities.simpack.models.LayerModel
model for specular reflectivity calculations

densityprofile
(nz, plot=False)[source]¶ calculates the electron density of the layerstack from the thickness and roughness of the individual layers
Parameters: **nz: number of values on which the profile should be calculated**
plot: flag to tell if a plot of the profile should be created Returns: z, eprof: coordinates and electron profile. z = 0 corresponds to the
surface

xrayutilities.simpack.mpl_helper module¶
Defines new matplotlib Sqrt scale which further allows for negative values by using the sign of the original value as sign of the plotted value.

class
xrayutilities.simpack.mpl_helper.
SqrtAllowNegScale
(axis, **kwargs)[source]¶ Bases:
matplotlib.scale.ScaleBase
Scales data using a sqrtfunction, however, allowing also negative values.
 The scale function:
 sign(y) * sqrt(abs(y))
 The inverse scale function:
 sign(y) * y**2

class
InvertedSqrtTransform
(shorthand_name=None)[source]¶ Bases:
matplotlib.transforms.Transform

input_dims
= 1¶

is_separable
= True¶

output_dims
= 1¶


class
SqrtAllowNegScale.
SqrtTransform
(shorthand_name=None)[source]¶ Bases:
matplotlib.transforms.Transform

input_dims
= 1¶

is_separable
= True¶

output_dims
= 1¶


SqrtAllowNegScale.
limit_range_for_scale
(vmin, vmax, minpos)[source]¶ Override to limit the bounds of the axis to the domain of the transform. In the case of Mercator, the bounds should be limited to the threshold that was passed in. Unlike the autoscaling provided by the tick locators, this range limiting will always be adhered to, whether the axis range is set manually, determined automatically or changed through panning and zooming.

SqrtAllowNegScale.
name
= 'sqrt'¶
xrayutilities.simpack.powder module¶
This module contains the core definitions for the XRD Fundamental Parameneters Model (FPA) computation in Python. The main computational class is FP_profile, which stores cached information to allow it to efficiently recompute profiles when parameters have been modified. For the user an Powder class is available which can calculate a complete powder pattern of a crystalline material.
The diffractometer line profile functions are calculated by methods from Cheary & Coelho 1998 and Mullen & Cline paper and ‘R’ package. Accumulate all convolutions in Fourier space, for efficiency, except for axial divergence, which needs to be weighted in real space for I3 integral.
More details about the applied algorithms can be found in the paper by M. H. Mendelhall et al., Journal of Research of NIST 120, 223 (2015) to which you should also refer for a careful definition of all the parameters

class
xrayutilities.simpack.powder.
FP_profile
(anglemode, gaussian_smoother_bins_sigma=1.0, oversampling=10)[source]¶ the main fundamental parameters class, which handles a single reflection. This class is designed to be highly extensible by inheriting new convolvers. When it is initialized, it scans its namespace for specially formatted names, which can come from mixin classes. If it finds a function name of the form conv_xxx, it will call this funtion to create a convolver. If it finds a name of the form info_xxx it will associate the dictionary with that convolver, which can be used in UI generation, for example. The class, as it stands, does nothing significant with it. If it finds str_xxx, it will use that function to format a printout of the current state of the convolver conv_xxx, to allow improved report generation for convolvers.
When it is asked to generate a profile, it calls all known convolvers. Each convolver returns the Fourier transform of its convolvution. The transforms are multiplied together, inverse transformed, and after fixing the periodicity issue, subsampled, smoothed and returned.
If a convolver returns *None*, it is not multipled into the product.
 Noteable class parameters:
max_history_length: the number of histories to cache (default=5); can be overridden if memory is an issue. length_scale_m: length_scale_m sets scaling for nice printing of parameters. if the units are in mm everywhere, set it to 0.001, e.g. convolvers which implement their own str_xxx method may use this to format their results, especially if ‘natural’ units are not meters. Typical is wavelengths and lattices in nm or angstroms, for example.

add_buffer
(b)[source]¶ add a numpy array to the list of objects that can be thrown away on pickling.
Parameters: **b: the buffer to add to the list** Returns: return the same buffer, to make nesting easy.

axial_helper
(outerbound, innerbound, epsvals, destination, peakpos=0, y0=0, k=0)[source]¶ the function F0 from the paper. compute k/sqrt(peakposx)+y0 nonzero between outer & inner (inner is closer to peak) or k/sqrt(xpeakpos)+y0 if reversed (i.e. if outer > peak) fully evaluated on a specified eps grid, and stuff into destination
Parameters: **outerbound: the edge of the function farthest from the singularity,**
referenced to epsvals
innerbound: the edge closest to the singularity, referenced to epsvals epsvals: the array of twotheta values or offsets destination: an array into which final results are summed. modified in place! peakpos: the position of the singularity, referenced to epsvals. y0: the constant offset k: the scale factor Returns: (*lower_index*, *upper_index*) python style bounds
for region of *destination* which has been modified.

compute_line_profile
(convolver_names=None, compute_derivative=False, return_convolver=False)[source]¶ execute all the convolutions; if convolver_names is None, use everything we have, otherwise, use named convolutions.
Parameters: **convolver_names: a list of convolvers to select. If *None*, use all**
found convolvers.
compute_derivative: if *True*, also return d/dx(function) for peak position fitting Returns: a profile_data object with much information about the peak

conv_absorption
()[source]¶ compute the sample transparency correction, including the finitethickness version
Returns: the convolver

conv_axial
()[source]¶ compute the Fourier transform of the axial divergence component
Returns: the transform buffer, or *None* if this is being ignored

conv_displacement
()[source]¶ compute the peak shift due to sample displacement and the *2theta* zero offset
Returns: the convolver

conv_emission
()[source]¶ compute the emission spectrum and (for convenience) the particle size widths
Returns: the convolver for the emission and particle sizes Note
Note: the particle size and strain stuff here is just to be consistent
with *Topas* and to be vaguely efficient about the computation, since all of these have the same general shape.

conv_flat_specimen
()[source]¶ compute the convolver for the flatspecimen correction
Returns: the convolver

conv_global
()[source]¶ a dummy convolver to hold global variables and information. the global context isn’t really a convolver, returning *None* means ignore result
Returns: *None*, always

conv_receiver_slit
()[source]¶ compute the rectangular convolution for the receiver slit or SiPSD pixel size
Returns: the convolver

conv_si_psd
()[source]¶ compute the convolver for the integral of defocusing of the face of an Si PSD
Returns: the convolver

conv_smoother
()[source]¶ compute the convolver to smooth the final result with a Gaussian before downsampling.
Returns: the convolver

conv_tube_tails
()[source]¶ compute the Fourier transform of the rectangular tube tails function
Returns: the transform buffer, or *None* if this is being ignored

full_axdiv_I2
(Lx=None, Ls=None, Lr=None, R=None, twotheta=None, beta=None, epsvals=None)[source]¶ return the *I2* function
Parameters: **Lx: length of the xray filament**
Ls: length of the sample Lr: length of the receiver slit R: diffractometer length, assumed symmetrical twotheta: angle, in radians, of the center of the computation beta: offset angle epsvals: array of offsets from center of computation, in radians Returns: (*epsvals*, *idxmin*, *idxmax*, *I2p*, *I2m*).
*idxmin* and *idxmax* are the full pythonstyle bounds of the nonzero region of *I2p* and *I2m*. *I2p* and *I2m* are I2+ and I2 from the paper, the contributions to the intensity.

full_axdiv_I3
(Lx=None, Ls=None, Lr=None, R=None, twotheta=None, epsvals=None, sollerIdeg=None, sollerDdeg=None, nsteps=10, axDiv='')[source]¶ carry out the integral of *I2* over *beta* and the Soller slits.
Parameters: **Lx: length of the xray filament**
Ls: length of the sample Lr: length of the receiver slit R: the (assumed symmetrical) diffractometer radius twotheta: angle, in radians, of the center of the computation epsvals: array of offsets from center of computation, in radians sollerIdeg: the fullwidth (both sides) cutoff angle of the incident Soller slit sollerDdeg: the fullwidth (both sides) cutoff angle of the detector Soller slit nsteps: the number of subdivisions for the integral axDiv: not used Returns: the accumulated integral, a copy of a persistent buffer *_axial*

general_tophat
(name='', width=None)[source]¶ a utility to compute a transformed tophat function and save it in a convolver buffer
Parameters: **name: the name of the convolver cache buffer to update**
width: the width in 2theta space of the tophat Returns: the updated convolver buffer, or *None* if the width was *None*

get_conv
(name, key, format=<type 'float'>)[source]¶ get a cached, precomputed convolver associated with the given parameters, or a newly zeroed convolver if the cache doesn’t contain it. Recycles old cache entries.
This takes advantage of the mutability of arrays. When the contents of the array are changed by the convolver, the cached copy is implicitly updated, so that the next time this is called with the same parameters, it will return the previous array.
Parameters: **name: the name of the convolver to seek**
key: any hashable object which identifies the parameters for the computation format: the type of the array to create, if one is not found. Returns: flag, which is *True* if valid data were found, or *False* if the
returned array is zero, and *array*, which must be computed by the
convolver if *flag* was *False*.

get_convolver_information
()[source]¶ return a list of convolvers, and what we know about them. function scans for functions named conv_xxx, and associated info_xxx entries.
Returns: list of (convolver_xxx, info_xxx) pairs

get_function_name
()[source]¶ return the name of the function that called this. Useful for convolvers to identify themselves
Returns: name of calling function

get_good_bin_count
(count)[source]¶ find a bin count close to what we need, which works well for Fourier transforms.
Parameters: **count: a number of bins.** Returns: a bin count somewhat larger than *count* which is efficient for FFT

info_emission
= {'param_info': {'emiss_lor_widths': ('Lorenztian emission fwhm (m)', (1e13,)), 'crystallite_size_lor': ('Lorentzian crystallite size fwhm (m)', 1e06), 'emiss_wavelengths': ('wavelengths (m)', (1.58e10,)), 'emiss_intensities': ('relative intensities', (1.0,)), 'emiss_gauss_widths': ('Gaussian emissions fwhm (m)', (1e13,)), 'crystallite_size_gauss': ('Gaussian crystallite size fwhm (m)', 1e06)}, 'help': 'this should be help information', 'group_name': 'Incident beam and crystal size'}¶

info_global
= {'param_info': {'twotheta0_deg': ('Bragg center of peak (degrees)', 30.0), 'd': ('d spacing (m)', 4e10), 'dominant_wavelength': ('wavelength of most intense line (m)', 1.5e10)}, 'help': 'this should be help information', 'group_name': 'Global parameters'}¶

classmethod
isequivalent
(hkl1, hkl2, crystalsystem)[source]¶ function to determine if according to the convolvers included in this class two sets of Miller indices are equivalent. This function is only calles when the class attribute ‘isotropic’ is False.
Parameters: **hkl1,2: Miller indices to be checked for equivalence**
crystalsystem: symmetry class of the material which is considered Returns: True or False

isotropic
= True¶

length_scale_m
= 1.0¶

max_history_length
= 5¶

self_clean
()[source]¶ do some cleanup to make us more compact; Instance can no longer be used after doing this, but can be pickled.

set_optimized_window
(twotheta_window_center_deg, twotheta_approx_window_fullwidth_deg, twotheta_exact_bin_spacing_deg)[source]¶ pick a bin count which factors cleanly for FFT, and adjust the window width to preserve the exact center and bin spacing
Parameters: **twotheta_window_center_deg: exact position of center bin, in degrees**
twotheta_approx_window_fullwidth_deg: approximate desired width twotheta_exact_bin_spacing_deg: the exact bin spacing to use

set_parameters
(convolver='global', **kwargs)[source]¶ update the dictionary of parameters associated with the given convolver
Parameters: **convolver: the name of the convolver. name ‘global’, e.g., attaches**
to function ‘conv_global’
kwargs: keywordvalue pairs to update the convolvers dictionary.

set_window
(twotheta_window_center_deg, twotheta_window_fullwidth_deg, twotheta_output_points)[source]¶ move the compute window to a new location and compute grids, without resetting all parameters. Clears convolution history and sets up many arrays.
Parameters: **twotheta_window_center_deg: the center position of the middle bin of**
the window, in degrees
twotheta_window_fullwidth_deg: the full width of the window, in degrees twotheta_output_points: the number of bins in the final output

class
xrayutilities.simpack.powder.
PowderDiffraction
(mat, **kwargs)[source]¶ Bases:
xrayutilities.experiment.PowderExperiment
Experimental class for powder diffraction. This class calculates the structure factors of powder diffraction lines and uses instances of FP_profile to perform the convolution with experimental resolution function calculated by the fundamental parameters approach. This class used multiprocessing to speed up calculation. Set config.NTHREADS=1 to restrict this to one worker process.

Calculate
(twotheta, **kwargs)[source]¶ calculate the powder diffraction pattern including convolution with the resolution function and map them onto the twotheta positions. This also performs the calculation of the peak intensities from the internal material object
Parameters: **twotheta: two theta values at which the powder pattern should be**
calculated.
Note
 Note: Bragg peaks are only included up to tt_cutoff set in
 the class constructor!
 **kwargs: additional keyword arguments are passed to the Convolve
 function
Returns: output intensity values for the twotheta values given in the input

Convolve
(twotheta, window_width='config', mode='multi')[source]¶ convolute the powder lines with the resolution function and map them onto the twotheta positions. This calculates the powder pattern excluding any background contribution
Parameters: **twotheta: two theta values at which the powder pattern should be**
calculated.
window_width: width of the calculation window of a single peak mode: multiprocessing mode, either ‘multi’ to use multiple processes or ‘local’ to restrict the calculation to a single process **Note: Bragg peaks are only included up to tt_cutoff set in**
the class constructor!
Returns: output intensity values for the twotheta values given in the input

correction_factor
(ang)[source]¶ calculate the correction factor for the diffracted intensities. This contains the polarization effects and the Lorentz factor
Parameters: **ang: theta diffraction angles for which the correction should be**
calculated
Returns: f: array of the same shape as ang containing the correction factors

energy
¶

init_powder_lines
(tt_cutoff)[source]¶ calculates the powder intensity and positions up to an angle of tt_cutoff (deg) and stores the result in the data dictionary whose structure is as follows:
The data dictionary has one entry per line with a unique identifier as key of the entry. The entries themself are dictionaries which have the following entries:
hkl: (h, k, l), Miller indices of the Bragg peak r: reflection strength of the line ang: Bragg angle of the peak (theta = 2theta/2!) qpos: reciprocal space position

load_settings_from_config
(settings)[source]¶ load parameters from the config and update these settings with the options from the settings parameter

merge_lines
(data)[source]¶ if calculation if isotropic lines at the same qposition can be merged to one line to reduce the calculational effort
Parameters: **data: numpy field array with values of ‘hkl’ (Miller indices of the**
peaks), ‘q’ (qposition), and ‘r’ (reflection strength) as produced by the structure_factors method
Returns: hkl, q, ang, r: Miller indices, qposition, diffraction angle (Theta),
and reflection strength of the material

set_sample_parameters
()[source]¶ load sample parameters from the Powder class and use them in all FP_profile instances of this object

set_wavelength_from_params
()[source]¶ sets the wavelenth in the base class from the settings dictionary of the FP_profile classes and also set it in the ‘global’ part of the parameters

structure_factors
(tt_cutoff)[source]¶ determine structure factors/reflection strength of all Bragg peaks up to tt_cutoff
Parameters: **tt_cutoff: upper cutoff value of 2theta until which the reflection**
strength are calculated
Returns: numpy array with field for ‘hkl’ (Miller indices of the peaks),
‘q’ (qposition), and ‘r’ (reflection strength) of the Bragg peaks

twotheta
¶

update_powder_lines
(tt_cutoff)[source]¶ calculates the powder intensity and positions up to an angle of tt_cutoff (deg) and updates the values in:
ids: list of unique identifiers of the powder line data: array with intensities ang: bragg angles of the peaks (theta=2theta/2!) qpos: reciprocal space position of intensities

update_settings
(newsettings={})[source]¶ update settings of all instances of FP_profile
Parameters: **newsettings: dictionary with new settings. It has to include one**
subdictionary for every convolver which should have its settings changed.

wavelength
¶

window_width
¶


class
xrayutilities.simpack.powder.
convolver_handler
[source]¶ Bases:
object
manage the convolvers of on process

class
xrayutilities.simpack.powder.
manager
(address=None, authkey=None, serializer='pickle')[source]¶ Bases:
multiprocessing.managers.BaseManager
xrayutilities.simpack.powdermodel module¶

class
xrayutilities.simpack.powdermodel.
PowderModel
(*args, **kwargs)[source]¶ Bases:
object
Class to help with powder calculations for multiple materials. For basic calculations the Powder class together with the Fundamental parameters approach is used.

create_fitparameters
()[source]¶ function to create a fit model with all instrument and sample parameters.
Parameters: **pass** Returns: lmfit Parameters instance

fit
(params, twotheta, data, std=None, maxfev=200)[source]¶ make least squares fit with parameters supplied by the user
Parameters: **params: lmfit Parameters object with all parameters set as intended**
by the user
twotheta: angular values for the fit data: experimental intensities for the fit std: standard deviation of the experimental data. if ‘None” the sqrt of the data will be used maxfev: maximal number of simulations during the least squares refinement Returns: lmfit MinimizerResult

set_background
(btype, **kwargs)[source]¶ define background as spline or polynomial function
Parameters: **btype: background type: either ‘polynomial’ or ‘spline’. Depending on**
this value the expected keyword arguments differ.
kwargs:  ‘spline’:
x: xvalues (twotheta) of the background points y: intensity values of the background  ‘polynomial’:
p: polynomial coefficients from the highest degree to the constant term. len of p decides about the degree of the polynomial

set_lmfit_parameters
(lmparams)[source]¶ function to update the settings of this class during an least squares fit
Parameters: **lmparams: lmfit Parameters list of sample and instrument parameters**

set_parameters
(params)[source]¶ set simulation parameters of all subobjects
Parameters: **params: settings dictionaries for the convolvers.**

simulate
(twotheta, **kwargs)[source]¶ calculate the powder diffraction pattern of all materials and sum the results based on the relative volume of the materials.
Parameters: **twotheta: positions at which the powder spectrum should be evaluated**
 **kwargs:
background: an array of background values (same shape as twotheta) if no background is given then the background is calculated as previously set by the set_background function or is 0. further keyword arguments are passed to the Convolve function of of the PowderDiffraction objects
Returns: summed powder diffraction intensity of all materials present in the
model
Known issue: possibility to add a background is currently missing!


xrayutilities.simpack.powdermodel.
Rietveld_error_metrics
(exp, sim, weight=None, std=None, Nvar=0, disp=False)[source]¶ calculates common error metrics for Rietveld refinement.
Parameters: **exp: experimental datapoints**
sim: simulated data weight: weight factor in the least squares sum. If it is None the weight is estimated from the counting statistics of ‘exp’ std: standard deviation of the experimental data. alternative way of specifying the weight factor. when both are given weight overwrites std! Nvar: number of variables in the refinement disp: flag to tell if a line with the calculated values should be printed. Returns: M, Rp, Rwp, Rwpexp, chi2

xrayutilities.simpack.powdermodel.
plot_powder
(twotheta, exp, sim, mask=None, scale='sqrt', fig='XU:powder', show_diff=True, show_legend=True)[source]¶ Convenience function to plot the comparison between experimental and simulated powder diffraction data
Parameters: **twotheta: angle values used for the xaxis of the plot (deg)**
exp: experimental data (same shape as twotheta). If None only the simulation and no difference will be plotted sim: simulated data mask: mask to reduce the twotheta values to the be used as xcoordinates of sim scale: string specifying the scale of the yaxis. Valid are: ‘linear, ‘sqrt’, and ‘log’. fig: matplotlib figure name (figure will be cleared!) show_diff: flag to specify if a difference curve should be shown show_legend: flag to specify if a legend should be shown
xrayutilities.simpack.smaterials module¶

class
xrayutilities.simpack.smaterials.
CrystalStack
(name, *args)[source]¶ Bases:
xrayutilities.simpack.smaterials.LayerStack
extends the built in list type to enable building a stack of crystalline Layers by various methods.

class
xrayutilities.simpack.smaterials.
GradedLayerStack
(alloy, xfrom, xto, nsteps, thickness, **kwargs)[source]¶ Bases:
xrayutilities.simpack.smaterials.CrystalStack
generates a sequence of layers with a gradient in chemical composition

class
xrayutilities.simpack.smaterials.
Layer
(material, thickness, **kwargs)[source]¶ Bases:
xrayutilities.simpack.smaterials.SMaterial
Object describing part of a thin film sample. The properties of a layer :are:
Material: an xrayutilties material describing optical and crystal properties of the thin film Thickness: film thickness in Angstrom Roughness: root mean square roughness of the top interface in Angstrom

class
xrayutilities.simpack.smaterials.
LayerStack
(name, *args)[source]¶ Bases:
xrayutilities.simpack.smaterials.MaterialList
extends the built in list type to enable building a stack of Layer by various methods.

class
xrayutilities.simpack.smaterials.
MaterialList
(name, *args)[source]¶ Bases:
_abcoll.MutableSequence
class representing the basics of a list of materials for simulations within xrayutilities. It extends the built in list type.

class
xrayutilities.simpack.smaterials.
Powder
(material, volume, **kwargs)[source]¶ Bases:
xrayutilities.simpack.smaterials.SMaterial
Object describing part of a powder sample. The properties of a powder :are:
Material: an xrayutilties material (Crystal) describing optical and crystal properties of the thin film Volume: powder’s volume (in pseudo units, since only the relative volume enters the calculation)  Optionally also the following can be set:
crystallite_size_lor: Lorentzian crystallite size fwhm (m) crystallite_size_gauss: Gaussian crystallite size fwhm (m) strain_lor: extra peak width proportional to tan(theta) strain_gauss: extra peak width proportional to tan(theta)

class
xrayutilities.simpack.smaterials.
PowderList
(name, *args)[source]¶ Bases:
xrayutilities.simpack.smaterials.MaterialList
extends the built in list type to enable building a list of Powder by various methods.

class
xrayutilities.simpack.smaterials.
PseudomorphicStack001
(name, *args)[source]¶ Bases:
xrayutilities.simpack.smaterials.CrystalStack
generate a sequence of pseudomorphic crystalline Layers. Surface orientation is assumed to be 001 and materials must be cubic/tetragonal.

trans
= <xrayutilities.math.transforms.Transform object>¶


class
xrayutilities.simpack.smaterials.
PseudomorphicStack111
(name, *args)[source]¶ Bases:
xrayutilities.simpack.smaterials.PseudomorphicStack001
generate a sequence of pseudomorphic crystalline Layers. Surface orientation is assumed to be 111 and materials must be cubic.

trans
= <xrayutilities.math.transforms.CoordinateTransform object>¶

Module contents¶
simulation subpackage of xrayutilities.
This package provides possibilities to simulate Xray diffraction and reflectivity curves of thin film samples. It could be extended for more general use in future if there is demand for that.
In addition it provides a fitting routine for reflectivity data which is based on lmfit.