# pymatgen.analysis.diffraction.xrd module¶

class XRDCalculator(wavelength='CuKa', symprec=0, debye_waller_factors=None)[source]

Bases: object

Computes the XRD pattern of a crystal structure.

This code is implemented by Shyue Ping Ong as part of UCSD’s NANO106 - Crystallography of Materials. The formalism for this code is based on that given in Chapters 11 and 12 of Structure of Materials by Marc De Graef and Michael E. McHenry. This takes into account the atomic scattering factors and the Lorentz polarization factor, but not the Debye-Waller (temperature) factor (for which data is typically not available). Note that the multiplicity correction is not needed since this code simply goes through all reciprocal points within the limiting sphere, which includes all symmetrically equivalent facets. The algorithm is as follows

1. Calculate reciprocal lattice of structure. Find all reciprocal points within the limiting sphere given by $$\frac{2}{\lambda}$$.

2. For each reciprocal point $$\mathbf{g_{hkl}}$$ corresponding to lattice plane $$(hkl)$$, compute the Bragg condition $$\sin(\theta) = \frac{\lambda}{2d_{hkl}}$$

3. Compute the structure factor as the sum of the atomic scattering factors. The atomic scattering factors are given by

$f(s) = Z - 41.78214 \times s^2 \times \sum\limits_{i=1}^n a_i \exp(-b_is^2)$

where $$s = \frac{\sin(\theta)}{\lambda}$$ and $$a_i$$ and $$b_i$$ are the fitted parameters for each element. The structure factor is then given by

$F_{hkl} = \sum\limits_{j=1}^N f_j \exp(2\pi i \mathbf{g_{hkl}} \cdot \mathbf{r})$
4. The intensity is then given by the modulus square of the structure factor.

$I_{hkl} = F_{hkl}F_{hkl}^*$
5. Finally, the Lorentz polarization correction factor is applied. This factor is given by:

$P(\theta) = \frac{1 + \cos^2(2\theta)} {\sin^2(\theta)\cos(\theta)}$

Initializes the XRD calculator with a given radiation.

Parameters: wavelength (str/float) – The wavelength can be specified as either a float or a string. If it is a string, it must be one of the supported definitions in the AVAILABLE_RADIATION class variable, which provides useful commonly used wavelengths. If it is a float, it is interpreted as a wavelength in angstroms. Defaults to “CuKa”, i.e, Cu K_alpha radiation. symprec (float) – Symmetry precision for structure refinement. If set to 0, no refinement is done. Otherwise, refinement is performed using spglib with provided precision. ({element symbol (debye_waller_factors) – float}): Allows the specification of Debye-Waller factors. Note that these factors are temperature dependent.
AVAILABLE_RADIATION = ('CuKa', 'CuKa2', 'CuKa1', 'CuKb1', 'MoKa', 'MoKa2', 'MoKa1', 'MoKb1', 'CrKa', 'CrKa2', 'CrKa1', 'CrKb1', 'FeKa', 'FeKa2', 'FeKa1', 'FeKb1', 'CoKa', 'CoKa2', 'CoKa1', 'CoKb1', 'AgKa', 'AgKa2', 'AgKa1', 'AgKb1')
SCALED_INTENSITY_TOL = 0.001
TWO_THETA_TOL = 1e-05
get_xrd_data(structure, scaled=True, two_theta_range=(0, 90))[source]

Calculates the XRD data for a structure.

Parameters: structure (Structure) – Input structure scaled (bool) – Whether to return scaled intensities. The maximum peak is set to a value of 100. Defaults to True. Use False if you need the absolute values to combine XRD plots. two_theta_range ([float of length 2]) – Tuple for range of two_thetas to calculate in degrees. Defaults to (0, 90). Set to None if you want all diffracted beams within the limiting sphere of radius 2 / wavelength. (XRD pattern) in the form of [[two_theta, intensity, {(h, k, l): mult}, d_hkl], …] Two_theta is in degrees. Intensity is in arbitrary units and if scaled (the default), has a maximum value of 100 for the highest peak. {(h, k, l): mult} is a dict of Miller indices for all diffracted lattice facets contributing to that intensity and their multiplicities. d_hkl is the interplanar spacing.
get_xrd_plot(structure, two_theta_range=(0, 90), annotate_peaks=True, ax=None, with_labels=True, fontsize=16)[source]

Returns the XRD plot as a matplotlib.pyplot.

Parameters: structure – Input structure two_theta_range ([float of length 2]) – Tuple for range of two_thetas to calculate in degrees. Defaults to (0, 90). Set to None if you want all diffracted beams within the limiting sphere of radius 2 / wavelength. annotate_peaks – Whether to annotate the peaks with plane information. ax – matplotlib Axes or None if a new figure should be created. with_labels – True to add xlabels and ylabels to the plot. fontsize – (int) fontsize for peak labels. (matplotlib.pyplot)
plot_structures(structures, two_theta_range=(0, 90), annotate_peaks=True, fontsize=6, **kwargs)[source]

Plot XRD for multiple structures on the same figure.

Args:

structures (Structure): List of structures two_theta_range ([float of length 2]): Tuple for range of

two_thetas to calculate in degrees. Defaults to (0, 90). Set to None if you want all diffracted beams within the limiting sphere of radius 2 / wavelength.
annotate_peaks (bool): Whether to annotate the peaks with plane
information.

fontsize: (int) fontsize for peak labels.

keyword arguments controlling the display of the figure:

kwargs Meaning
title Title of the plot (Default: None).
show True to show the figure (default: True).
savefig ‘abc.png’ or ‘abc.eps’ to save the figure to a file.
size_kwargs Dictionary with options passed to fig.set_size_inches example: size_kwargs=dict(w=3, h=4)
tight_layout True if to call fig.tight_layout (default: False)
show_xrd_plot(structure, two_theta_range=(0, 90), annotate_peaks=True)[source]

Shows the XRD plot.

Parameters: structure (Structure) – Input structure two_theta_range ([float of length 2]) – Tuple for range of two_thetas to calculate in degrees. Defaults to (0, 90). Set to None if you want all diffracted beams within the limiting sphere of radius 2 / wavelength. annotate_peaks (bool) – Whether to annotate the peaks with plane information.
get_unique_families(hkls)[source]

Returns unique families of Miller indices. Families must be permutations of each other.

Parameters: hkls ([h, k, l]) – List of Miller indices. multiplicity}: A dict with unique hkl and multiplicity. {hkl