soprano.calculate.xrd.xrd#

Classes and functions for simulating X-ray diffraction spectroscopic results from structures.

Classes

XRDCalculator([lambdax, theta2_digits, ...])

A class implementing methods for XRD simulations, comparisons and fittings.

XraySpectrum(theta2, hkl, hkl_unique, invd, ...)

Create new instance of XraySpectrum(theta2, hkl, hkl_unique, invd, intensity, lambdax)

XraySpectrumData(theta2, intensity)

Create new instance of XraySpectrumData(theta2, intensity)

class soprano.calculate.xrd.xrd.XRDCalculator(lambdax=1.54056, theta2_digits=6, baseline=0.0, peak_func=None, peak_f_args=None)[source]#

Bases: object

A class implementing methods for XRD simulations, comparisons and fittings.

Initialize the XDRCalculator object’s main parameters

Args:
lambdax (Optional[float]): X-ray wavelength in Angstroms
(default is 1.54056 Ang)
theta2_digits (Optional[int]): Rounding within which
two theta angles (in degrees)
are considered to be equivalent
(default is 6 digits) when
calculating theoretical peaks
baseline (Optional[float]): baseline to use as starting point for
simulated spectra
peak_func (Optional[function<float, float, *kargs>
=> <np.ndarray>]): the function used to
simulate peaks. Should take
th2 as its first argument,
peak centre as its second,
and any number of optional
arguments. Returns a numpy
array containing the peak
shape. Should be able to
work with numpy arrays as
input
peak_f_args (Optional[list<float>]): optional arguments for
peak_func. If no peak_func
has been supplied by the
user, the first value will
be used as the Gaussian width
dataset_range(xpeaks, theta2_range=(None, None))[source]#
Restrict the given dataset (XraySpectrum or XraySpectrumData) to

only the values that lie within a certain theta2 range.

Args:
xpeaks (XraySpectrum or XraySpectrumData): the dataset to modify
theta2_range (tuple<int>): a tuple indicating minimum and maximum
of the desired theta2 range (degrees).
A value of None means no boundary
Returns:
xpeaks_restrict (XraySpectrum or XraySpectrumData): the restricted
dataset
Raises:
ValueError: if some of the values passed are invalid
exp_dataset(th2_axis, int_axis)[source]#

Build an experimental dataset as an XraySpectrumData object.

Args:
th2_axis (np.ndarray): array containing the values for 2*theta
int_axis (np.ndarray): array containing the values for intensity
Returns:
exp_spec (XraySpectrumData): named tuple containing the
experimental dataset
Raises:
ValueError: if some of the values passed are invalid
lebail_fit(xpeaks, exp_spec, rwp_tol=0.01, max_iter=100)[source]#

Perform a refining on an XraySpectrum object’s intensities based on experimental data with leBail’s method.

Args:
xpeaks (XraySpectrum): object containing the details of the XRD
peaks
exp_spec (XraySpectrumData): experimental data, dataset built
using xrd_exp_dataset
rwp_tol (Optional[float]): tolerance on the Rwp error value
between two iterations that stops the
calculation. Default is 1e-2
max_iter (Optional[int]): maximum number of iterations to perform
Returns:
xpeaks_scaled (XraySpectrum): a new XraySpectrum object, with
intensities properly scaled to match
the experimental data
simul_spec (np.ndarray): final simulated XRD spectrum
simul_peaks (np.ndarray): final simulated spectrum broken by peak
contribution along axis 1
rwp (float): the final value of Rwp (fitness of simulated to
experimental data)
Raises:
ValueError: if some of the arguments are invalid
property peak_f_args#

Additional arguments to be passed to peak_func

property peak_func#

The function used to build peaks in simulated spectra

Should be of form peak_func(theta2, peak_position, *peak_f_args)

powder_peaks(atoms=None, latt_abc=None, n=1, o='all')[source]#

Calculate the peaks (without intensities) of a powder XRD spectrum given either an Atoms object or the lattice in ABC form and the spacegroup indices to apply the selection rules

Args:
atoms (Optional[soprano.Atoms]): atoms object to gather lattice
and spacegroup information from
latt_abc (Optional[np.ndarray]): periodic lattice in ABC form,
Angstroms and radians
n (Optional[int]): International number of the required spacegroup
o (Optional[int]): Sub-option of the required spacegroup
Returns:
xpeaks (XraySpectrum): a named tuple containing the peaks
with theta2, corresponding hkl indices,
a unique hkl tuple for each peak,
inverse reciprocal lattice distances,
intensities and wavelength
Raises:
ValueError: if some of the arguments are invalid
set_peak_func(peak_func=None, peak_f_args=None)[source]#

Set a new peak_func for this XDRCalculator. If no new function is passed, reset the default Gaussian function.

Args:
peak_func (Optional[function<float, float, *kargs>
=> <np.ndarray>]): the function used to
simulate peaks. Should
take th2 as its first
argument, peak centre as
its second, and any
number of optional
arguments. Returns a
numpy array containing
the peak shape. Should
be able to work with
numpy arrays as input
peak_f_args (Optional[list<float>]): optional arguments for
peak_func. If no peak_func
has been supplied by the
user, the first value will
be used as the Gaussian
width
spec_simul(xpeaks, th2_axis)[source]#

Simulate an XRD spectrum given positions of peaks, intensities, baseline, and a peak function (a Gaussian by default).

Args:
xpeaks (XraySpectrum): object containing the details of the XRD
peaks
th2_axis (np.ndarray): theta2 axis points on which the
spectrum should be simulated
Returns:
simul_spec (XraySpectrumData): simulated XRD spectrum
simul_peaks (np.ndarray): simulated spectrum intensities broken by
peak contribution along axis 1
Raises:
ValueError: if some of the arguments are invalid
class soprano.calculate.xrd.xrd.XraySpectrum(theta2, hkl, hkl_unique, invd, intensity, lambdax)#

Bases: tuple

Create new instance of XraySpectrum(theta2, hkl, hkl_unique, invd, intensity, lambdax)

_asdict()#

Return a new dict which maps field names to their values.

classmethod _make(iterable)#

Make a new XraySpectrum object from a sequence or iterable

_replace(**kwds)#

Return a new XraySpectrum object replacing specified fields with new values

count(value, /)#

Return number of occurrences of value.

hkl#

Alias for field number 1

hkl_unique#

Alias for field number 2

index(value, start=0, stop=9223372036854775807, /)#

Return first index of value.

Raises ValueError if the value is not present.

intensity#

Alias for field number 4

invd#

Alias for field number 3

lambdax#

Alias for field number 5

theta2#

Alias for field number 0

class soprano.calculate.xrd.xrd.XraySpectrumData(theta2, intensity)#

Bases: tuple

Create new instance of XraySpectrumData(theta2, intensity)

_asdict()#

Return a new dict which maps field names to their values.

classmethod _make(iterable)#

Make a new XraySpectrumData object from a sequence or iterable

_replace(**kwds)#

Return a new XraySpectrumData object replacing specified fields with new values

count(value, /)#

Return number of occurrences of value.

index(value, start=0, stop=9223372036854775807, /)#

Return first index of value.

Raises ValueError if the value is not present.

intensity#

Alias for field number 1

theta2#

Alias for field number 0

soprano.calculate.xrd.xrd._Rwp_eval(simul_int, exp_int)[source]#

Evaluate Rwp for use in LeBail fitting

soprano.calculate.xrd.xrd._gauss_peak_default(x, x0, w)[source]#

Gaussian peak function (for spectrum simulation)

soprano.calculate.xrd.xrd._leBail_rescale_I(simul_peaks, simul_spec, exp_spec)[source]#

Returns rescaling factors for intensities in leBail fitting