Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
149 changes: 149 additions & 0 deletions periodictable/xsf.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,155 @@ def index_of_refraction(compound, *, density=None, natural_density=None,
wavelength=wavelength)
return 1 - wavelength**2/(2*pi)*(f1 + f2*1j)*1e-6

def delta(compound, *, density=None, natural_density=None,
energy=None, wavelength=None):
"""
Calculates the δ component of the index of refraction for a given compound

:Parameters:
*compound* : Formula initializer
Chemical formula.
*density* : float | |g/cm^3|
Mass density of the compound, or None for default.
*natural_density* : float | |g/cm^3|
Mass density of the compound at naturally occurring isotope abundance.
*wavelength* : float or vector | |Ang|
Wavelength of the X-ray.
*energy* : float or vector | keV
Energy of the X-ray, if *wavelength* is not specified.

:Returns:
*delta* : float or vector | unitless
δ component of the index of refraction of the material at the given energy

:Notes:

Formula taken from http://xdb.lbl.gov (section 1.7) and checked
against http://henke.lbl.gov/optical_constants/getdb2.html.
"""
if energy is not None:
wavelength = xray_wavelength(energy)
assert wavelength is not None, "scattering calculation needs energy or wavelength"
f1, f2 = xray_sld(compound,
density=density, natural_density=natural_density,
wavelength=wavelength)
return wavelength**2/(2*pi)*(f1)*1e-6

def beta(compound, *, density=None, natural_density=None,
energy=None, wavelength=None):
"""
Calculates the β component of the index of refraction for a given compound

:Parameters:
*compound* : Formula initializer
Chemical formula.
*density* : float | |g/cm^3|
Mass density of the compound, or None for default.
*natural_density* : float | |g/cm^3|
Mass density of the compound at naturally occurring isotope abundance.
*wavelength* : float or vector | |Ang|
Wavelength of the X-ray.
*energy* : float or vector | keV
Energy of the X-ray, if *wavelength* is not specified.

:Returns:
*beta* : float or vector | unitless
β component of the index of refraction of the material at the given energy

:Notes:

Formula taken from the equation

.. math::

n = 1 - \delta + i \beta

derivitive of the formula http://xdb.lbl.gov (section 1.7) using a more common
sign convention for the imaginary part of the index of refraction. Checked
against http://henke.lbl.gov/optical_constants/getdb2.html.
"""
if energy is not None:
wavelength = xray_wavelength(energy)
assert wavelength is not None, "scattering calculation needs energy or wavelength"
f1, f2 = xray_sld(compound,
density=density, natural_density=natural_density,
wavelength=wavelength)
return wavelength**2/(2*pi)*(f2)*1e-6

def n(compound, *, density=None, natural_density=None,
energy=None, wavelength=None):
"""
Calculates the real part (n) of the index of refraction for a given compound

:Parameters:
*compound* : Formula initializer
Chemical formula.
*density* : float | |g/cm^3|
Mass density of the compound, or None for default.
*natural_density* : float | |g/cm^3|
Mass density of the compound at naturally occurring isotope abundance.
*wavelength* : float or vector | |Ang|
Wavelength of the X-ray.
*energy* : float or vector | keV
Energy of the X-ray, if *wavelength* is not specified.

:Returns:
*n* : float or vector | unitless
n component of the index of refraction of the material at the given energy

:Notes:

Formula taken from the equation

.. math::

n = 1 - \delta

derivitive of the formula for δ from http://xdb.lbl.gov (section 1.7) using a more common
sign convention for the imaginary part of the index of refraction. Checked
against http://henke.lbl.gov/optical_constants/getdb2.html.
"""
return 1 - delta(compound,
density=density, natural_density=natural_density,
energy=energy, wavelength=wavelength)

def k(compound, *, density=None, natural_density=None,
energy=None, wavelength=None):
"""
Calculates the imaginary part (k) of the index of refraction for a given compound

:Parameters:
*compound* : Formula initializer
Chemical formula.
*density* : float | |g/cm^3|
Mass density of the compound, or None for default.
*natural_density* : float | |g/cm^3|
Mass density of the compound at naturally occurring isotope abundance.
*wavelength* : float or vector | |Ang|
Wavelength of the X-ray.
*energy* : float or vector | keV
Energy of the X-ray, if *wavelength* is not specified.

:Returns:
*k* : float or vector | unitless
k component of the index of refraction of the material at the given energy

:Notes:

Formula taken from the equation

.. math::

n = 1 - \delta + i \beta

derivitive of the formula for β from http://xdb.lbl.gov (section 1.7) using a more common
sign convention for the imaginary part of the index of refraction. Checked
against http://henke.lbl.gov/optical_constants/getdb2.html.
"""
return beta(compound,
density=density, natural_density=natural_density,
energy=energy, wavelength=wavelength)

def mirror_reflectivity(compound, *, density=None, natural_density=None,
energy=None, wavelength=None,
angle=None, roughness=0):
Expand Down