pyxtal.XRD module

Module for XRD simulation

class pyxtal.XRD.Profile(method='mod_pseudo-voigt', res=0.02, user_kwargs=None)[source]

Bases: object

This class applies a profiling function to simulated or experimentally obtained XRD spectra.

Parameters:
  • method (str) – Type of function used to profile

  • res (float) – resolution of the profiling array in degree

  • user_kwargs (dict) – The parameters for the profiling method.

get_profile(two_thetas, intensities, min2theta, max2theta)[source]

Performs profiling with selected function, resolution, and parameters

Parameters:
  • two_thetas (-) – 1d float array simulated/measured 2 theta values

  • intensities (-) – simulated/measures peaks

class pyxtal.XRD.Similarity(f, g, N=None, x_range=None, l=2.0, weight='cosine')[source]

Bases: object

cosineFunction()[source]

cosine function to weight correlations

show(filename=None, fontsize=None, labels=None)[source]

show the comparison plot

Parameters:
  • filename (None) – name of the xrd plot. If None, show the plot

  • [A (labels) – labels of each plot

  • B] – labels of each plot

triangleFunction()[source]

Triangle function to weight correlations

class pyxtal.XRD.XRD(crystal, wavelength=1.54184, thetas=[0, 180], res=0.01, per_N=30000, ncpu=1, filename=None, preferred_orientation=False, march_parameter=None, TWO_THETA_TOL=1e-05, SCALED_INTENSITY_TOL=1e-05)[source]

Bases: object

A class to compute the powder XRD.

Parameters:
  • crystal – ase atoms object

  • wavelength (float) – wavelength of the X-ray in Angstrom (default: 1.54184)

  • thetas (list) – list of 2theta angles in degrees (default: [0, 180])

  • res (float) – resolution of the XRD in degrees (default: 0.01)

  • per_N (int) – number of hkl per process (default: 30000)

  • ncpu – int, number of cpu to use (default: 1)

  • preferred_orientation – boolean, whether to use preferred orientation

  • march_parameter – float, the march parameter for preferred orientation

  • TWO_THETA_TOL – tolerance to find repeating angles

  • SCALED_INTENSITY_TOL – threshold for intensities

all_dhkl(crystal)[source]

3x3 representation -> 1x6 (a, b, c, alpha, beta, gamma)

by_hkl(hkl=None, N_max=None)[source]

d for any give abitray [h,k,l] index

static draw_hkl(hkl)[source]

turn negative numbers in hkl to overbar

get_plot(grainsize=20, orientation=0.1, thermo=0.1, L=500, H=50, S=25, bg_order=6, bg_ratio=0.05, mix_ratio=0.02, dx=0.02)[source]

Generate a simulated XRD plot with various parameters. Inspired from Pysimxrd at PyPI. Needs to double check the parameters.

Parameters:
  • grainsize (float) – Grain size in micrometers.

  • orientation (float) – Preferred orientation factor.

  • thermo (float) – Thermal vibration factor.

  • L (float) – Axial divergence length.

  • H (float) – Axial divergence height.

  • S (float) – Slit width.

  • bg_order (int) – Order of the polynomial background.

  • bg_ratio (float) – Ratio of background intensity.

  • mix_ratio (float) – Ratio of random noise intensity.

  • dx (float) – Step size for the simulated XRD.

Returns:

Simulated 2-theta values and corresponding intensities.

Return type:

tuple

get_profile(method='gaussian', res=0.01, user_kwargs=None)[source]

return the profile detail

get_unique_families(hkls, verbose=False)[source]

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

Parameters:
  • hkls ([h, k, l]) – List of Miller indices.

  • verbose (bool) – Whether or not to print out information on families.

Returns:

multiplicity}: A dict with unique hkl and multiplicity.

Return type:

{hkl

intensity(crystal)[source]

This function calculates all that is necessary to find the intensities. This scheme is similar to pymatgen If the number of hkl is significanly large, will automtically switch to the fast mode in which we only calculate the intensity and do not care the exact hkl families

Args:

load(filename)[source]

Load the pxrd from txt file

plot_pxrd(filename=None, profile=None, minimum_I=0.01, show_hkl=True, fontsize=None, figsize=(20, 10), res=0.02, fwhm=0.1, ax=None, xlim=None, width=1.0, legend=None, show=False)[source]

plot PXRD

Parameters:
  • filename (None) – name of the xrd plot. If None, show the plot

  • profile – type of peak profile

  • minimum_I (0.01) – the minimum intensity to include in the plot

  • show_hkl (True) – whether or not show hkl labels

  • fontsize (None) – fontsize of text in the plot

  • figsize ((20, 10)) – figsize

  • xlim (None) – the 2theta range [x_min, x_max]

plotly_pxrd(profile='gaussian', minimum_I=0.01, res=0.02, FWHM=0.1, height=450, html=None)[source]
pxrdf()[source]

Group the equivalent hkl planes together by 2 heta angle N*6 arrays, Angle, d_hkl, h, k, l, intensity

save(filename)[source]

savetxt file

pyxtal.XRD.add_peak(twotheta, mu, gamma, sigma2, L, H, S, step=0.02, width=0.1, sigma2_distor=0.001)[source]

Add a single peak to the XRD pattern using Voigt profile, axial divergence, slit function, and lattice distortion.

Parameters:
  • twotheta (array-like) – Array of 2-theta

  • mu (float) – Peak center (2-theta) in degrees.

  • gamma (float) – Lorentzian HWHM parameter.

  • sigma2 (float) – Gaussian variance parameter.

  • L (float) – Axial divergence length.

  • H (float) – Axial divergence height.

  • S (float) – Slit half-width.

  • step (float) – Step size for the 2-theta array.

  • width (float) – Width of the slit function in degrees.

  • sigma2_distor (float) – Variance for lattice distortion Gaussian.

Returns:

Array of same shape as twotheta with the peak intensity.

Return type:

ndarray

pyxtal.XRD.axial_div(x, mu, L, H, S)[source]

Van Laar axial divergence PDF (not CDF!)

pyxtal.XRD.axial_div_bak(x, mu, L, H, S)[source]

Calculate the axial divergence peak contribution using the Van Laar model.

Parameters:
  • x (array-like) – Array of 2-theta values in degrees.

  • mu (float) – Peak center (2-theta) in degrees.

  • L (float) – Axial divergence length (same units as H and S).

  • H (float) – Axial divergence height.

  • S (float) – Slit half-width (same units as H).

Returns:

Array of same shape as x with the axial divergence shape (unnormalized).

Return type:

ndarray

pyxtal.XRD.check_pxrd_match(xtal, ref_pxrd, s_tol=0.8, top_n=3, peak_tol=0.1, ang_tol=1.0, wave_length=1.5406, verbose=False)[source]

Check if there is a false match between the pyxtal structure and the reference PXRD. First, check the similarity between the two PXRDs. If the similarity is above s_tol, Second, for each of the top_n strongest peaks in the computed PXRD, check if the related peaks (within peak_tol) are present in the reference PXRD within a tolerance.

Parameters:
  • xtal – pyxtal object

  • ref_pxrd – a 2D array of (thetas, intensities) for the reference PXRD

  • s_tol – similarity tolerance, default is 0.8

  • top_n – number of strongest peaks to consider, default is 3

  • peak_tol – tolerance for peaks to be considered for a comparison, default is 0.05

  • ang_tol – tolerance for matching peaks in degrees, default is 1.0

  • wave_length – X-ray wavelength, default is Cu K-alpha

  • verbose – whether or not print the information

Returns:

True if there is a false match, False otherwise

Return type:

bool

pyxtal.XRD.create_index(imax=1, jmax=1, kmax=1)[source]

shortcut to get the index

pyxtal.XRD.gaussian(theta2, alpha, fwhm)[source]

Gaussian function for profiling peaks

pyxtal.XRD.gaussian_integrated(bin_left, bin_right, center, fwhm)[source]
pyxtal.XRD.get_all_intensity(N_cycles, N_atom, per_N, positions, hkls, s2s, coeffs, zs)[source]
pyxtal.XRD.get_all_intensity_par(cpu, queue, cycles, Start, End, hkl_per_proc, positions, hkls, s2s, coeffs, zs)[source]
pyxtal.XRD.get_intensity(positions, hkl, s2, coeffs, z)[source]

Calculate the intensity for a given set of positions, hkl, s2, coefficients, and atomic numbers. :param positions: N*3 array of atomic positions in fractional coordinates. :type positions: np.ndarray :param hkl: 3*M array of Miller indices. :type hkl: np.ndarray :param s2: M array of sin^2(theta) values. :type s2: np.ndarray :param coeffs: N*4*2 array of coefficients for each atom. :type coeffs: np.ndarray :param z: N*1 array of atomic numbers. :type z: np.ndarray

Returns:

M array of calculated intensities.

Return type:

np.ndarray

pyxtal.XRD.get_para_from_pxrd(ref_pxd, spg, wave_length=1.5406)[source]

Estimate the lattice parameters from the reference PXRD using Bragg’s law and cubic assumption.

Parameters:
  • ref_pxd – tuple of (thetas, intensities) for the reference PXRD

  • spg – space group number

  • wave_length – X-ray wavelength, default is Cu K-alpha

Returns:

estimated lattice parameter

Return type:

a

pyxtal.XRD.is_multiple(hkl, ref_hkl)[source]
pyxtal.XRD.lorentzian(theta2, alpha, fwhm)[source]

Lorentzian function for profiling peaks

pyxtal.XRD.map_intensity(peak, x, twotheta)[source]

Map peak intensities from fine grid (x) to coarse grid (twotheta). Uses cubic spline interpolation to produce continuous, smooth profiles.

Parameters:
  • peak (array-like) – Peak intensities on fine grid x.

  • x (array-like) – Fine grid positions (degrees).

  • twotheta (array-like) – Coarse grid positions (degrees).

Returns:

Interpolated intensities on twotheta grid.

Return type:

ndarray

pyxtal.XRD.mod_pseudo_voigt(x, fwhm, A, eta_h, eta_l, N)[source]

A modified split-type pseudo-Voigt function for profiling peaks - Izumi, F., & Ikeda, T. (2000).

pyxtal.XRD.pseudo_voigt(theta2, alpha, fwhm, eta)[source]

Original Pseudo-Voigt function for profiling peaks - Thompson, D. E. Cox & J. B. Hastings (1986).

pyxtal.XRD.pxrd_refine(xtal, ref_pxrd, thetas, steps=50)[source]

Improve the lattice w.r.t the reference PXRD

Parameters:
  • xtal – pyxtal object

  • ref_pxrd – tuple of (thetas, intensities) for the reference PXRD

  • thetas – list of angles to calculate the PXRD

  • steps (int) – number of steps for optimization

Returns:

refined pyxtal object x: parameters used for optimization sim: similarity value between the refined PXRD and the reference PXRD

Return type:

xtal

pyxtal.XRD.similarity_calculate(r, w, d, Npts, fy, gy)[source]

Compute the similarity between the pair of spectra f, g