Skip to content

xray_utils

X-ray scattering utility funcitons

diffractometer_twotheta(delta=0, gamma=0)

Return the Bragg 2-theta angle for diffractometer detector rotations delta (vertical) and gamma (horizontal)

Source code in mmg_toolbox/utils/xray_utils.py
def diffractometer_twotheta(delta=0, gamma=0):
    """Return the Bragg 2-theta angle for diffractometer detector rotations delta (vertical) and gamma (horizontal)"""
    delta = np.deg2rad(delta)
    gamma = np.deg2rad(gamma)
    twotheta = np.arccos(np.cos(delta) * np.cos(gamma))
    return np.rad2deg(twotheta)

photon_energy(wavelength_a)

Converts wavelength in A to energy in keV energy_kev = photon_energy(wavelength_a) Energy [keV] = h*c/L = 12.3984 / lambda [A]

Source code in mmg_toolbox/utils/xray_utils.py
def photon_energy(wavelength_a):
    """
    Converts wavelength in A to energy in keV
     energy_kev = photon_energy(wavelength_a)
     Energy [keV] = h*c/L = 12.3984 / lambda [A]
    """

    # SI: E = hc/lambda
    lam = wavelength_a * Const.A
    E = Const.h * Const.c / lam

    # Electron Volts:
    energy = E / Const.e
    return energy / 1000.0

photon_wavelength(energy_kev)

Converts energy in keV to wavelength in A wavelength_a = photon_wavelength(energy_kev) lambda [A] = h*c/E = 12.3984 / E [keV]

Source code in mmg_toolbox/utils/xray_utils.py
def photon_wavelength(energy_kev):
    """
    Converts energy in keV to wavelength in A
     wavelength_a = photon_wavelength(energy_kev)
     lambda [A] = h*c/E = 12.3984 / E [keV]
    """

    # Electron Volts:
    E = 1000 * energy_kev * Const.e

    # SI: E = hc/lambda
    lam = Const.h * Const.c / E
    wavelength = lam / Const.A
    return wavelength

polarisation_pi(delta=0, gamma=0)

Returns the scattered polerisation vector in the Pi' channel

Source code in mmg_toolbox/utils/xray_utils.py
def polarisation_pi(delta=0, gamma=0):
    """
    Returns the scattered polerisation vector in the Pi' channel
    """
    sd = np.sin(np.deg2rad(delta))
    sg = np.sin(np.deg2rad(gamma))
    cd = np.cos(np.deg2rad(delta))
    cg = np.cos(np.deg2rad(gamma))
    return np.array([-sg * sd, cd, -cg * sd])

polarisation_sigma(delta=0, gamma=0)

Returns the scattered polerisation vector in the sigma' channel

Source code in mmg_toolbox/utils/xray_utils.py
def polarisation_sigma(delta=0, gamma=0):
    """
    Returns the scattered polerisation vector in the sigma' channel
    """
    sd = np.sin(np.deg2rad(delta))
    sg = np.sin(np.deg2rad(gamma))
    cd = np.cos(np.deg2rad(delta))
    cg = np.cos(np.deg2rad(gamma))
    return np.array([cg, 0, -sg])

resolution2energy(res, twotheta=180.0)

Calcualte the energy required to achieve a specific resolution at a given two-theta

Parameters:

Name Type Description Default
res

measurement resolution in A (==d-spacing)

required
twotheta

Bragg angle in Degrees

180.0

Returns:

Type Description

float

Source code in mmg_toolbox/utils/xray_utils.py
def resolution2energy(res, twotheta=180.):
    """
    Calcualte the energy required to achieve a specific resolution at a given two-theta
    :param res: measurement resolution in A (==d-spacing)
    :param twotheta: Bragg angle in Degrees
    :return: float
    """
    theta = twotheta * Const.pi / 360  # theta in radians
    return (Const.h * Const.c * 1e10) / (res * np.sin(theta) * Const.e * 2 * 1000.)

wavevector(wavelength_a)

Return wavevector = 2pi/lambda

Source code in mmg_toolbox/utils/xray_utils.py
def wavevector(wavelength_a):
    """Return wavevector = 2pi/lambda"""
    return 2 * Const.pi / wavelength_a

wavevector_f(wavelength_a, delta=0, gamma=0)

Returns a 3D wavevector for the final wavevector

Source code in mmg_toolbox/utils/xray_utils.py
def wavevector_f(wavelength_a, delta=0, gamma=0):
    """
    Returns a 3D wavevector for the final wavevector
    """
    k = wavevector(wavelength_a)
    sd = np.sin(np.deg2rad(delta))
    sg = np.sin(np.deg2rad(gamma))
    cd = np.cos(np.deg2rad(delta))
    cg = np.cos(np.deg2rad(gamma))
    return k * np.array([sg * cd, sd, cg * cd])

wavevector_i(wavelength_a)

Returns a 3D wavevector for the initial wavevector

Source code in mmg_toolbox/utils/xray_utils.py
def wavevector_i(wavelength_a):
    """
    Returns a 3D wavevector for the initial wavevector
    """
    k = wavevector(wavelength_a)
    return np.array([0, 0, k])

wavevector_t(wavelength_a, delta=0, gamma=0)

Returns the wavevector transfer in inverse-Angstroms Q = kf - ki

Source code in mmg_toolbox/utils/xray_utils.py
def wavevector_t(wavelength_a, delta=0, gamma=0):
    """
    Returns the wavevector transfer in inverse-Angstroms
      Q = kf - ki
    """
    ki = wavevector_i(wavelength_a)
    kf = wavevector_f(wavelength_a, delta, gamma)
    return kf - ki

you_normal_vector(eta=0, chi=90, mu=0)

Determine the normal vector using the You diffractometer angles you_normal_vector(0, 0, 0) = [1, 0, 0] you_normal_vector(0, 90, 0) = [0, 1, 0] you_normal_vector(90, 90, 0) = [0, 0, -1] you_normal_vector(0, 0, 90) = [0, 0, -1]

Parameters:

Name Type Description Default
eta

angle (deg) along the x-axis

0
mu

angle (deg) about the z-axis

0
chi

angle deg) a

90

Returns:

Type Description

array

Source code in mmg_toolbox/utils/xray_utils.py
def you_normal_vector(eta=0, chi=90, mu=0):
    """
    Determine the normal vector using the You diffractometer angles
      you_normal_vector(0, 0, 0) = [1, 0, 0]
      you_normal_vector(0, 90, 0) = [0, 1, 0]
      you_normal_vector(90, 90, 0) = [0, 0, -1]
      you_normal_vector(0, 0, 90) = [0, 0, -1]
    :param eta: angle (deg) along the x-axis
    :param mu: angle (deg) about the z-axis
    :param chi: angle deg) a
    :return: array
    """
    eta = np.deg2rad(eta)
    chi = np.deg2rad(chi)
    mu = np.deg2rad(mu)
    normal = np.array([np.sin(mu) * np.sin(eta) * np.sin(chi) + np.cos(mu) * np.cos(chi),
                       np.cos(eta) * np.sin(chi),
                       -np.cos(mu) * np.sin(eta) * np.sin(chi) - np.sin(mu) * np.cos(chi)])
    return normal