### Install XrayDB via pip Source: https://github.com/xraypy/xraydb/blob/master/doc/installation.rst Use this command to install the XrayDB Python module and its associated SQLite database. ```bash pip install xraydb ``` -------------------------------- ### Calculate Fluxes for Gas Mixtures Source: https://github.com/xraypy/xraydb/blob/master/doc/examples.rst Example of specifying a gas mixture using a dictionary of gas names and fractional densities. ```python >>> fl = ionchamber_fluxes(gas={'Kr':0.5, 'Ar': 0.5}, volts=1.25, energy=18000, length=10, sensitivity=1, sensitivity_units='microA/V') >>> print(f"Incident= {fl.incident:g} Hz, Transmitted flux= {fl.transmitted:g} Hz") Incident= 1.43737e+10 Hz, Transmitted flux= 3.28986e+09 Hz ``` -------------------------------- ### Calculate Ion Chamber Currents Example Source: https://github.com/xraypy/xraydb/blob/master/doc/examples.rst Basic usage example for calculating incident and transmitted flux for a nitrogen-filled chamber. ```python >>> fl = ionchamber_fluxes(gas='nitrogen', volts=1.25, energy=18000, length=10.0, sensitivity=1.e-6) >>> print(f"Incident= {fl.incident:g} Hz, Transmitted flux= {fl.transmitted:g} Hz") Incident= 2.2358e+12 Hz, Transmitted flux= 2.214e+12 Hz ``` -------------------------------- ### XrayDB Python API Usage Source: https://github.com/xraypy/xraydb/blob/master/doc/python.rst Examples of using xraydb functions for atomic properties, scattering factors, emission lines, absorption edges, and attenuation factors. ```pycon >>> import xraydb >>> xraydb.atomic_number('Ag') 47 # # X-ray elastic (Thomson) scattering factors: >>> import numpy as np >>> q =np.linspace(0, 5, 11) >>> xraydb.f0('Fe', q) array([25.994603 , 11.50848469, 6.55945765, 4.71039413, 3.21048827, 2.20939146, 1.65112769, 1.36705887, 1.21133507, 1.10155689, 1.0035555 ]) # # X-ray emission lines: >>> for name, line in xraydb.xray_lines('Zn', 'K').items(): ... print(name, ' = ', line) ... Ka3 = XrayLine(energy=8462.8, intensity=0.000316256, initial_level='K', final_level='L1') Ka2 = XrayLine(energy=8614.1, intensity=0.294353, initial_level='K', final_level='L2') Ka1 = XrayLine(energy=8637.2, intensity=0.576058, initial_level='K', final_level='L3') Kb3 = XrayLine(energy=9567.6, intensity=0.0438347, initial_level='K', final_level='M2') Kb1 = XrayLine(energy=9570.4, intensity=0.0846229, initial_level='K', final_level='M3') Kb5 = XrayLine(energy=9648.8, intensity=0.000815698, initial_level='K', final_level='M4,5') # # X-ray absorption edges: >>> xraydb.xray_edge('As', 'K') XrayEdge(energy=11867.0, fyield=0.548989, jump_ratio=7.314) # # X-ray attenuation factors: >>> as_kedge = xraydb.xray_edge('As', 'K').energy >>> energies = np.linspace(-50, 50, 5) + as_kedge >>> muvals = xraydb.mu_elam('As', energies) >>> for en, mu in zip(energies, muvals): ... print("{:.0f} {:8.2f}".format(en, mu)) ... 11817 26.07 11842 25.92 11867 25.77 11892 178.32 11917 177.38 ``` -------------------------------- ### Get material properties Source: https://github.com/xraypy/xraydb/blob/master/doc/python.rst Retrieves the chemical formula and density for a specified material name. ```pycon >>> xraydb.get_material('kapton') ('C22H10N2O5', 1.43) ``` -------------------------------- ### Initialize XrayDB Instance Source: https://github.com/xraypy/xraydb/blob/master/doc/python.rst Use this to obtain an instance of the XrayDB object for accessing database methods. ```pycon >>> import xraydb >>> xdb = xraydb.get_xraydb() ``` -------------------------------- ### Clone XrayDB Repository Source: https://github.com/xraypy/xraydb/blob/master/doc/installation.rst Use this command to download the full source code kit for development purposes. ```bash git clone https://github.com/xraypy/XrayDB.git ``` -------------------------------- ### Querying XrayDB with SQLite Source: https://github.com/xraypy/xraydb/blob/master/doc/dbschema.rst Basic command-line usage for accessing the database and executing SQL queries. ```default system~> sqlite3 xraydb.sqlite sqlite> .headers on sqlite> select * from elements where atomic_number=47; atomic_number|element|name|molar_mass|density 47|Ag|silver|107.868|10.48 ``` -------------------------------- ### coated_reflectivity(coating, coating_thick, substrate, theta, energy, coating_dens=None, surface_roughness=0.0, substrate_dens=None, substrate_roughness=0.0, binder=None, binder_thick=None, binder_dens=None, polarization='s', output='intensity') Source: https://github.com/xraypy/xraydb/blob/master/doc/python.rst Calculates the reflectivity for a coated mirror. ```APIDOC ## coated_reflectivity ### Description Calculates the reflectivity for a coated mirror given the coating and substrate properties. ### Parameters - **coating** (str) - Required - Coating material name or formula. - **coating_thick** (float) - Required - Thickness of coating in Angstroms. - **substrate** (string) - Required - Substrate material name or formula. - **theta** (float or nd-array) - Required - Mirror angle in radians. - **energy** (float or nd-array) - Required - X-ray energy in eV. - **coating_dens** (None) - Optional - Density of mirror coating in g/cm^3. - **surface_roughness** (float) - Optional - Coating roughness in Angstroms. - **substrate_dens** (float) - Optional - Density of substrate in g/cm^3. - **substrate_roughness** (float) - Optional - Substrate roughness in Angstroms. - **binder** (str) - Optional - Binder material name or formula. - **binder_thick** (float) - Optional - Thickness of binder in Angstroms. - **binder_dens** (float) - Optional - Density of binder in g/cm^3. - **polarization** ('s' or 'p') - Optional - Mirror orientation relative to X-ray polarization. - **output** (str) - Optional - Output intensity or complex amplitude. ### Returns - **reflectivity** (float/array) - Mirror reflectivity values. ``` -------------------------------- ### multilayer_reflectivity(stackup, thickness, substrate, theta, energy, n_periods=1, density=None, substrate_density=None, substrate_rough=0.0, surface_rough=0.0, polarization='s', output='intensity') Source: https://github.com/xraypy/xraydb/blob/master/doc/python.rst Calculates the reflectivity for a multilayer mirror. ```APIDOC ## multilayer_reflectivity ### Description Calculates the reflectivity for a multilayer mirror based on the provided stackup, thickness, and material properties. ### Parameters - **stackup** (list of formulas) - Required - Material name or formula (e.g., 'Si', 'Rh'). - **thickness** (list) - Required - Thickness of layers in Angstroms. - **substrate** (string) - Required - Substrate material name or formula. - **theta** (float or nd-array) - Required - Mirror angle in radians. - **energy** (float or nd-array) - Required - X-ray energy in eV. - **n_periods** (int) - Optional - Number of periods in multilayer. - **density** (list or None) - Optional - Material densities in g/cm^3. - **substrate_density** (float) - Optional - Density of substrate in g/cm^3. - **substrate_rough** (float) - Optional - Mirror roughness in Angstroms. - **surface_rough** (float) - Optional - Mirror roughness in Angstroms. - **polarization** ('s' or 'p') - Optional - Mirror orientation relative to X-ray polarization. - **output** (str) - Optional - Output intensity or complex amplitude. ### Returns - **reflectivity** (float/array) - Mirror reflectivity values. ``` -------------------------------- ### ck_probability(element, initial, final, total=True) Source: https://github.com/xraypy/xraydb/blob/master/doc/python.rst Calculates the transition probability for an element given the initial and final levels. ```APIDOC ## ck_probability(element, initial, final, total=True) ### Description Retrieves the transition probability for an element between specified initial and final levels. ### Parameters - **element** (int, str) - Required - Atomic number or atomic symbol for the element. - **initial** (str) - Required - IUPAC symbol for the initial level. - **final** (str) - Required - IUPAC symbol for the final level. - **total** (bool) - Optional - Whether to include transitions via possible intermediate levels (default: True). ### Returns - **float** - Transition probability, or 0 if the transition is not allowed. ``` -------------------------------- ### Calculate Ion Chamber Fluxes with Different Sensitivity Units Source: https://github.com/xraypy/xraydb/blob/master/doc/examples.rst Demonstrates equivalent results using different sensitivity unit specifications. ```python >>> fluxes = ionchamber_fluxes('N2', volts=1, energy=10000, length=10, sensitivity=1.e-9) >>> fluxes = ionchamber_fluxes('N2', volts=1, energy=10000, length=10, sensitivity=1, sensitivity_units='nA/V') ``` -------------------------------- ### Retrieve materials list Source: https://github.com/xraypy/xraydb/blob/master/doc/python.rst Fetches all available materials from the database, optionally filtered by category. ```pycon >>> for name, m in xraydb.get_materials().items(): ... print(name, m) ... water H2O 1.0 lead Pb 11.34 aluminum Al 2.7 kapton C22H10N2O5 1.42 polyimide C22H10N2O5 1.42 nitrogen N 0.00125 argon Ar 0.001784 ... ``` -------------------------------- ### Calculate absorption for specific materials Source: https://github.com/xraypy/xraydb/blob/master/doc/examples.rst Demonstrates replacing the default material calculation with a specific material and density. ```python mu = material_mu('H2O', energy) ``` ```python mu = material_mu('CaCO3', energy, density=2.71) ``` -------------------------------- ### Find material instance Source: https://github.com/xraypy/xraydb/blob/master/doc/python.rst Looks up a material by name or formula and returns the corresponding Material instance. ```pycon >>> xraydb.find_material('kapton') Material(formula='C22H10N2O5', density=1.42, name='kapton', categories=['polymer']) ``` -------------------------------- ### get_materials(force_read=False, categories=None) Source: https://github.com/xraypy/xraydb/blob/master/doc/python.rst Retrieves a dictionary of all available materials from the database. ```APIDOC ## get_materials(force_read=False, categories=None) ### Description Fetches all materials currently stored in the database. ### Parameters - **force_read** (bool) - Optional - Whether to force a re-reading of the materials database. Defaults to False. - **categories** (list of strings) - Optional - Restrict results to those matching specific category names. ### Returns - **dict** - A dictionary with material names as keys and Materials instances as values. ``` -------------------------------- ### Draw Energy Levels and Transitions Source: https://github.com/xraypy/xraydb/blob/master/poster/elines.tex Path commands defining the horizontal energy levels and vertical transition lines with labels. ```latex (0, 0mm) node[edge]$K$ -- ++(29, 0) node[orbital] $1s$; (0, 40mm) node[edge]$L_1$ -- ++(29, 0) node[orbital] $2s$; (0, 45mm) node[edge]$L_2$ -- ++(29, 0) node[orbital] $2p_{1/2}$; (0, 50mm) node[edge]$L_3$ -- ++(29, 0) node[orbital] $2p_{3/2}$; (0, 80mm) node[edge] $M_1$ -- ++(29, 0) node[orbital] $3s$; (0, 85mm) node[edge] -- ++(29, 0) node[orbital] $3p_{1/2}$; (0, 90mm) node[edge] $M_3$ -- ++(29, 0) node[orbital] $3p_{3/2}$; (0, 95mm) node[edge] -- ++(29, 0) node[orbital] $3d_{3/2}$; (0, 100mm) node[edge] $M_5$ -- ++(29, 0) node[orbital] $3d_{5/2}$; (0, 120mm) node[edge] $N_1$ -- ++(29, 0) node[orbital] $4s$; (0, 125mm) node[edge] -- ++(29, 0) node[orbital] $4p_{1/2}$; (0, 130mm) node[edge] $N_3$ -- ++(29, 0) node[orbital] $4p_{3/2}$; (0, 135mm) node[edge] -- ++(29, 0) node[orbital] $4d_{3/2}; (0, 140mm) node[edge] $N_5$ -- ++(29, 0) node[orbital] $4d_{5/2}; (0, 145mm) node[edge] -- ++(29, 0) node[orbital] $4f_{5/2}; (0, 150mm) node[edge] $N_7$ -- ++(29, 0) node[orbital] $4f_{7/2}; (5mm, 152mm) -- ++(5mm, -7mm); (10mm, 147mm) -- node[sieg] $M_{\alpha}$ (10mm, 120mm) -- (10mm, 100mm) ; (25mm, 147mm) -- node[sieg] $M_{\beta}$ (25mm, 97mm) -- (25mm, 95mm) ; (35mm, 82mm) -- node[sieg] $L_l$ (35mm, 62mm) -- node[frac] 0.003 (35mm, 50mm) ; (50mm, 97mm) -- node[sieg] $L_{\alpha_2}$ (50mm, 64mm) -- node[frac] 0.09 (50mm, 50mm) ; (65mm, 102mm) -- node[sieg] $L_{\alpha_1}$ (65mm, 69mm) -- node[frac] 0.80 (65mm, 50mm) ; (75mm, 142mm) -- (80mm, 135mm); (80mm, 137mm) -- node[sieg] $L_{\beta_2}$ (80mm, 77mm) -- node[frac] 0.11 (80mm, 50mm) ; (105mm, 97mm) -- node[sieg] $L_{\beta_1}$ (105mm, 58mm) -- node[frac] 0.88 (105mm, 45mm) ; (120mm, 137mm) -- node[sieg] $L_{\gamma_1}$ (120mm, 69mm) -- node[frac] 0.09 (120mm, 45mm) ; (145mm, 87mm) -- node[sieg] $L_{\beta_4}$ (145mm, 55mm) -- node[frac] 0.32 (145mm, 40mm) ; (160mm, 92mm) -- node[sieg] $L_{\beta_3}$ (160mm, 61mm) -- node[frac] 0.50 (160mm, 40mm) ; (175mm, 127mm) -- node[sieg] $L_{\gamma_2}$ (175mm,67mm) -- node[frac] 0.08 (175mm, 40mm) ; (190mm, 132mm) -- node[sieg] $L_{\gamma_3}$ (190mm, 79mm) -- node[frac] 0.10 (190mm, 40mm) ; (215mm, 47mm) -- node[sieg] $K_{\alpha_2}$ (215mm, 16mm) -- node[frac] 0.29 (215mm, 0mm) ; (230mm, 52mm) -- node[sieg] $K_{\alpha_1}$ (230mm, 23mm) -- node[frac] 0.54 (230mm, 0mm) ; (245mm, 87mm) -- node[sieg] $K_{\beta_3}$ (245mm, 30mm) -- node[frac] 0.05 (245mm, 0mm); (260mm, 92mm) -- node[sieg] $K_{\beta_1}$ (260mm, 36mm) -- node[frac] 0.09 (260mm, 0mm); (270mm, 132mm) -- ++(5mm, -7mm); (275mm, 127mm) -- node[sieg] $K_{\beta_2}$ (275mm, 48mm) -- node[frac] 0.03 (275mm, 0mm) ; ``` -------------------------------- ### Calculate coated mirror reflectivity Source: https://github.com/xraypy/xraydb/blob/master/doc/examples.rst Uses coated_reflectivity to model mirrors with specific coating and binding layers, comparing them against bulk material reflectivity. ```python import numpy as np from xraydb import (coated_reflectivity, mirror_reflectivity) import matplotlib.pyplot as plt coating = 'Rh' coating_thick = 300 substrate = 'Si' theta = 0.004 energy = np.linspace(10000, 35000, 500) binder = 'Cr' binder_thick = 30 refl_coat = coated_reflectivity(coating, coating_thick, substrate, theta, energy, binder=binder, binder_thick=binder_thick) refl_rhod = mirror_reflectivity('Rh', theta, energy) title = f'$\rm {coating_thick} \AA \> {coating}/{binder_thick} \AA \> {binder} \> coated \> {substrate} \> mirror \> \theta\, =\, {theta*1000:.0f} mrad $' plt.plot(energy, refl_coat, label='Rh coated') plt.plot(energy, refl_rhod, label='Rh bulk') plt.title(title) plt.xlabel('Energy (eV)') plt.ylabel('Reflectivity') plt.yscale('log') plt.legend() plt.show() ``` -------------------------------- ### add_material(name, formula, density, categories=None) Source: https://github.com/xraypy/xraydb/blob/master/doc/python.rst Adds a new material to the user's local material database. ```APIDOC ## add_material(name, formula, density, categories=None) ### Description Adds a custom material to the local configuration file for use in future sessions. ### Parameters - **name** (str) - Required - Name of the material. - **formula** (str) - Required - Chemical formula. - **density** (float) - Required - Density of the material. - **categories** (list of strings) - Optional - List of category names. ### Returns - **None** ``` -------------------------------- ### get_material(name) Source: https://github.com/xraypy/xraydb/blob/master/doc/python.rst Looks up a material by name and returns its formula and density. ```APIDOC ## get_material(name) ### Description Retrieves the chemical formula and density for a specified material name. ### Parameters - **name** (str) - Required - The name of the material or chemical formula. ### Returns - **tuple** - A tuple containing the chemical formula (str) and density (float). ``` -------------------------------- ### Calculate and plot Darwin widths Source: https://github.com/xraypy/xraydb/blob/master/doc/examples.rst Calculates Darwin widths for Si(111) and Si(333) crystals and plots their reflectivity profiles. ```python import numpy as np from xraydb import darwin_width import matplotlib.pyplot as plt dw_si111 = darwin_width(10000, 'Si', (1, 1, 1)) dw_si333 = darwin_width(30000, 'Si', (3, 3, 3)) print(dw_si111.theta_width*1e6) fmt_string = "Darwin Width for {:s} at {:.0f} keV: {:5.2f} microrad, {:5.2f} eV" print(fmt_string.format('Si(111)', 10, dw_si111.theta_width*1e6, dw_si111.energy_width)) print(fmt_string.format('Si(333)', 30, dw_si333.theta_width*1e6, dw_si333.energy_width)) dtheta = dw_si111.dtheta*1e6 denergy = dw_si111.denergy[::-1] # slightly advanced matplotlib hackery: fig, ax = plt.subplots(constrained_layout=True) ax.plot(dtheta, dw_si111.intensity, label='$I$, Si(111)', linewidth=2) ax.plot(dtheta, dw_si111.intensity**2, label='$I^2$, Si(111)', linewidth=2) ax.plot(dw_si333.dtheta*1e6, dw_si333.intensity**2, label='$I^2$ Si(333) 30 keV', linewidth=2) ax.set_title('X-ray diffraction intensity at 10keV') ax.set_xlabel('Angle - $\theta_B$ ($ \mu \mathrm{rad}$)') ax.set_ylabel('Reflectivity') ax.legend() plt.show() ``` ```text Darwin Width for Si(111) at 10 keV: 26.96 microrad, 1.34 eV Darwin Width for Si(333) at 30 keV: 1.81 microrad, 0.27 eV ``` -------------------------------- ### Calculate multilayer mirror reflectivity Source: https://github.com/xraypy/xraydb/blob/master/doc/examples.rst Uses multilayer_reflectivity to compute reflectivity for periodic layered structures on a substrate. ```python import numpy as np from xraydb import multilayer_reflectivity import matplotlib.pyplot as plt # 40 layers of [27Ang Si, 18Ang W] materials = ['Si', 'W'] thicknesses = [27, 18] # angstroms n_periods = 40 substrate = 'SiO2' theta = 0.01 energy = np.linspace(500, 20000, 5000) reflect = multilayer_reflectivity(materials, thicknesses, substrate, theta, energy, n_periods=n_periods) plt.plot(energy, reflect) plt.title(f'$\rm 40 x [27\AA\, Si,\, 18\AA\, W] \> multilayer \> \theta\, = \, {theta*1000:.0f}\> mrad$') plt.xlabel('Energy (eV)') plt.ylabel('Reflectivity') plt.show() ``` -------------------------------- ### material_mu_components(name, energy, density=None, kind='total') Source: https://github.com/xraypy/xraydb/blob/master/doc/python.rst Calculates the absorption coefficient (in 1/cm) for a compound and returns component details. ```APIDOC ## material_mu_components(name, energy, density=None, kind='total') ### Description Calculates the absorption coefficient (in 1/cm) for a compound and returns a dictionary containing mass, density, elements, and per-element mu values. ### Parameters - **name** (str) - Required - Chemical formula or name of material from materials list. - **energy** (float or ndarray) - Required - Energy or array of energies in eV. - **density** (None or float) - Optional - Material density (gr/cm^3). - **kind** (str) - Optional - 'photo' or 'total' for whether to return the photo-absorption or total cross-section (default: 'total'). ### Returns - components (dict) - Dictionary with 'mass', 'density', 'elements' (list), and per-element tuples of (stoichiometric fraction, atomic mass, mu). ``` -------------------------------- ### Add custom material Source: https://github.com/xraypy/xraydb/blob/master/doc/python.rst Adds a new material to the local user database, which persists across sessions. ```pycon >>> xraydb.add_material('becopper', 'Cu0.98e0.02', 8.3, categories=['metal']) ``` -------------------------------- ### f0_ions(element=None) Source: https://github.com/xraypy/xraydb/blob/master/doc/python.rst Lists ion names supported in the f0() calculation. ```APIDOC ## f0_ions(element=None) ### Description Returns a list of strings for matching ion names supported in the f0() calculation. ### Parameters - **element** (None, int, str) - Optional - Scatterer identifier. ``` -------------------------------- ### mirror_reflectivity(formula, theta, energy, density=None, roughness=0.0, polarization='s', output='intensity') Source: https://github.com/xraypy/xraydb/blob/master/doc/python.rst Calculates the mirror reflectivity for a thick, single-layer mirror. ```APIDOC ## mirror_reflectivity ### Description Calculates mirror reflectivity for a thick, single-layer mirror given material properties and geometry. ### Parameters - **formula** (string) - Required - Material name or formula - **theta** (float or nd-array) - Required - Mirror angle in radians - **energy** (float or nd-array) - Required - X-ray energy in eV - **density** (float or None) - Optional - Material density in g/cm^3 - **roughness** (float) - Optional - Mirror roughness in Angstroms. Default: 0.0 - **polarization** (string) - Optional - Mirror orientation ('s' or 'p'). Default: 's' - **output** (string) - Optional - Output type ('intensity' or 'amplitude'). Default: 'intensity' ### Returns - **reflectivity** (float or nd-array) - Mirror reflectivity values. ``` -------------------------------- ### get_xraydb() Source: https://github.com/xraypy/xraydb/blob/master/doc/python.rst Returns an instance of the XrayDB object to access the database. ```APIDOC ## get_xraydb() ### Description Returns an instance of the XrayDB object. ### Returns - **XrayDB** - An instance of the XrayDB class. ### Example ```python import xraydb xdb = xraydb.get_xraydb() ``` ``` -------------------------------- ### xray_lines(element, initial_level=None, excitation_energy=None) Source: https://github.com/xraypy/xraydb/blob/master/doc/python.rst Retrieves a dictionary of X-ray emission lines for a given element. Excitation energy, if provided, supersedes the initial level parameter. ```APIDOC ## xray_lines(element, initial_level=None, excitation_energy=None) ### Description Retrieves a dictionary of X-ray emission lines for a specified element. The returned dictionary uses Siegbahn notation as keys and XrayLine tuples as values. ### Parameters - **element** (int, str) - Required - Atomic number or atomic symbol for the element. - **initial_level** (None, str) - Optional - IUPAC symbol of the initial level. - **excitation_energy** (None, float) - Optional - Excitation energy; if provided, it supersedes the initial_level parameter. ### Returns - **dict** - Dictionary of X-ray lines containing (energy, intensity, initial level, final level) tuples. ``` -------------------------------- ### Calculate material attenuation and components Source: https://github.com/xraypy/xraydb/blob/master/doc/python.rst Retrieves the attenuation coefficient and a dictionary of elemental components for a given material. ```pycon >>> xraydb.material_mu('quartz', 10000) 50.36774553547068 >>> xraydb.material_mu_components('quartz', 10000) {'mass': 60.0843, 'density': 2.65, 'elements': ['Si', 'O'], 'Si': (1, 28.0855, 33.87943243018506), 'O': (2.0, 15.9994, 5.952824815297084)} ``` -------------------------------- ### Calculate 1/e absorption depth Source: https://github.com/xraypy/xraydb/blob/master/doc/examples.rst Calculates the 1/e absorption depth for a specific material at a given energy. ```python >>> from xraydb import material_mu >>> mu_20kev = xraydb.material_mu('CaCO3', 20000, density=2.71) >>> print("CaCO3 1/e depth at 20keV = {:.3f} mm".format(10/mu_20kev)) CaCO3 1/e depth at 20keV = 0.648 mm ``` -------------------------------- ### Retrieve X-ray emission lines for an element Source: https://github.com/xraypy/xraydb/blob/master/doc/python.rst Iterate through and print X-ray emission lines for a specific element and initial level. ```pycon >>> for name, line in xraydb.xray_lines('Mn', 'K').items(): ... print(name, line) ... Ka3 XrayLine(energy=5769.9, intensity=0.000265963, initial_level='K', final_level='L1') Ka2 XrayLine(energy=5889.1, intensity=0.293941, initial_level='K', final_level='L2') Ka1 XrayLine(energy=5900.3, intensity=0.58134, initial_level='K', final_level='L3') Kb3 XrayLine(energy=6491.8, intensity=0.042234, initial_level='K', final_level='M2') Kb1 XrayLine(energy=6491.8, intensity=0.0815329, initial_level='K', final_level='M3') Kb5 XrayLine(energy=6537.0, intensity=0.000685981, initial_level='K', final_level='M4,5') ``` -------------------------------- ### Calculate single layer mirror reflectivity Source: https://github.com/xraypy/xraydb/blob/master/doc/examples.rst Uses mirror_reflectivity to compare energy-dependent reflectivity across different materials at a fixed incident angle. ```python import numpy as np from xraydb import mirror_reflectivity import matplotlib.pyplot as plt energy = np.linspace(1000, 51000, 501) r_si = mirror_reflectivity('Si', 0.002, energy) r_ni = mirror_reflectivity('Ni', 0.002, energy) r_rh = mirror_reflectivity('Rh', 0.002, energy) r_pt = mirror_reflectivity('Pt', 0.002, energy) plt.plot(energy, r_si, label='Si') plt.plot(energy, r_ni, label='Ni') plt.plot(energy, r_rh, label='Rh') plt.plot(energy, r_pt, label='Pt') plt.title('X-ray reflectivity at $\theta=2 \mathrm{mrad}$') plt.xlabel('Energy (eV)') plt.ylabel('Reflectivity') plt.legend() plt.show() ``` -------------------------------- ### find_material(name) Source: https://github.com/xraypy/xraydb/blob/master/doc/python.rst Looks up a material by name or formula and returns its instance. ```APIDOC ## find_material(name) ### Description Retrieves a material instance based on its name or chemical formula. ### Parameters - **name** (str) - Required - The name of the material or chemical formula. ### Returns - **Material** - The material instance. ``` -------------------------------- ### darwin_width(energy, crystal='Si', hkl=(1, 1, 1), a=None, polarization='s', ignore_f2=False, ignore_f1=False, m=1) Source: https://github.com/xraypy/xraydb/blob/master/doc/python.rst Calculates the Darwin width for a specific crystal reflection and X-ray energy. ```APIDOC ## darwin_width ### Description Calculates the Darwin width for a crystal reflection and energy. Returns a named tuple 'DarwinWidth' containing various angular and energy width parameters. ### Parameters - **energy** (float) - Required - X-ray energy in eV - **crystal** (string) - Optional - Name of crystal ('Si', 'Ge', or 'C'). Default: 'Si' - **hkl** (tuple) - Optional - h, k, l for reflection. Default: (1, 1, 1) - **a** (float or None) - Optional - Lattice constant. Default: None - **polarization** (string) - Optional - Mono orientation ('s', 'p', 'u'). Default: 's' - **ignore_f1** (bool) - Optional - Ignore contribution from f1. Default: False - **ignore_f2** (bool) - Optional - Ignore contribution from f2. Default: False - **m** (int) - Optional - Order of reflection. Default: 1 ### Returns - **DarwinWidth** (named tuple) - Contains fields: theta, theta_offset, theta_width, theta_fwhm, rocking_theta_fwhm, energy_width, energy_fwhm, rocking_energy_fwhm, zeta, dtheta, denergy, intensity, rocking_curve. ``` -------------------------------- ### Calculate fluorescence yield Source: https://github.com/xraypy/xraydb/blob/master/doc/python.rst Calculate fluorescence yield, average energy, and net probability for specific elements and X-ray lines. ```pycon >>> xraydb.fluor_yield('Fe', 'K', 'Ka', 8000) 0.350985, 6400.752419799043, 0.874576096 ``` ```pycon >>> xraydb.fluor_yield('Fe', 'K', 'Ka', 6800) 0.0, 6400.752419799043, 0.874576096 ``` ```pycon >>> xraydb.fluor_yield('Ag', 'L3', 'La', 6000) 0.052, 2982.129655446868, 0.861899000000000 ``` -------------------------------- ### ionchamber_fluxes(gas='nitrogen', volts=1.0, length=100.0, energy=10000.0, sensitivity=1e-06, sensitivity_units='A/V', with_compton=True, both_carriers=True) Source: https://github.com/xraypy/xraydb/blob/master/doc/python.rst Calculates ion chamber and PIN diode fluxes for a gas, mixture of gases, or semiconductor material. ```APIDOC ## ionchamber_fluxes ### Description Calculates incident, transmitted, and absorbed X-ray fluxes for an ion chamber or PIN diode. It accounts for gas composition, chamber length, X-ray energy, and current amplifier settings. ### Parameters - **gas** (string or dict) - Optional - Name or formula of fill gas or diode material, or a dictionary of gas fractions. Default: 'nitrogen'. - **volts** (float) - Optional - Measured voltage output of current amplifier. Default: 1.0. - **length** (float) - Optional - Active length of ion chamber in cm. Default: 100.0. - **energy** (float) - Optional - X-ray energy in eV. Default: 10000.0. - **sensitivity** (float) - Optional - Current amplifier sensitivity. Default: 1e-06. - **sensitivity_units** (string) - Optional - Units of current amplifier sensitivity. Default: 'A/V'. - **with_compton** (bool) - Optional - Switch to control the contribution of Compton scattering. Default: True. - **both_carriers** (bool) - Optional - Switch to control whether to count both electron and ion current. Default: True. ### Returns - **IonchamberFluxes** (named tuple) - Contains fields: incident (Hz), transmitted (Hz), photo (Hz), and incoherent (Hz). ``` -------------------------------- ### Atomic and Material Functions Source: https://github.com/xraypy/xraydb/blob/master/doc/python.rst A collection of functions for calculating atomic properties, cross-sections, and material characteristics. ```APIDOC ## Atomic and Material Functions - **ck_probability()**: Coster-Kronig transition probability between two atomic levels. - **mu_elam()**: Absorption cross-section, photo-electric or total for an element. - **coherent_cross_section_elam()**: Coherent scattering cross-section for an element. - **incoherent_cross_section_elam()**: Incoherent scattering cross-section for an element. - **chantler_energies()**: Energies of tabulation for Chantler data. - **f1_chantler()**: f'(E) anomalous scattering factor. - **f2_chantler()**: f"(E) anomalous scattering factor. - **mu_chantler()**: Absorption cross-section. - **guess_edge()**: Guess element and edge from energy of absorption edge. - **chemparse()**: Parse a chemical formula to atomic abundances. - **validate_formula()**: Test whether a chemical formula can be parsed. - **get_materials()**: Get a dictionary of known materials {name:(formula, density)}. - **get_material()**: Get a (formula, density) tuple for a material in the materials database. - **find_material()**: Get a material instance for a material in the materials database. - **add_material()**: Add a material to local materials database. - **material_mu()**: Absorption cross-section for a material at X-ray energies. - **material_mu_components()**: Dictionary of elemental components of mu for material. - **xray_delta_beta()**: Anomalous index of refraction for material and energy. - **darwin_width()**: Darwin widths for monochromator crystals. - **mirror_reflectivity()**: X-ray reflectivities for mirror materials (thick slab limit). - **multilayer_reflectivity()**: X-ray reflectivities for multilayer mirrors. - **coated_reflectivity()**: X-ray reflectivities for coated mirrors. - **ionization_potential()**: Effective ionization potential for a gas, as for ion chambers. - **ionchamber_fluxes()**: Calculate fluxes from ion chamber voltages, gases, and sensitivities. ``` -------------------------------- ### f0(ion, q) Source: https://github.com/xraypy/xraydb/blob/master/doc/python.rst Calculates the elastic X-ray scattering factor, f0(q), for an ion. ```APIDOC ## f0(ion, q) ### Description Calculates the elastic X-ray scattering factor, f0(q), for an ion. ### Parameters - **ion** (int, str) - Required - Atomic number, atomic symbol, or ionic symbol. - **q** (float, ndarray) - Required - Q value(s) for scattering. ``` -------------------------------- ### material_mu(name, energy, density=None, kind='total') Source: https://github.com/xraypy/xraydb/blob/master/doc/python.rst Calculates the X-ray attenuation length (in 1/cm) for a material by name or formula. ```APIDOC ## material_mu(name, energy, density=None, kind='total') ### Description Calculates the X-ray attenuation length (in 1/cm) for a material by name or formula. ### Parameters - **name** (str) - Required - Chemical formula or name of material from materials list. - **energy** (float or ndarray) - Required - Energy or array of energies in eV. - **density** (None or float) - Optional - Material density (gr/cm^3). - **kind** (str) - Optional - 'photo' or 'total' for whether to return the photo-absorption or total cross-section (default: 'total'). ### Returns - absorption length (float) - The absorption length in 1/cm. ``` -------------------------------- ### xray_delta_beta(material, density, energy) Source: https://github.com/xraypy/xraydb/blob/master/doc/python.rst Calculates the anomalous components of the index of refraction for a material. ```APIDOC ## xray_delta_beta(material, density, energy) ### Description Calculates the anomalous components of the index of refraction for a material using tabulated scattering components. ### Parameters - **material** (str) - Required - Chemical formula (e.g., 'Fe2O3'). - **density** (float) - Required - Material density in g/cm^3. - **energy** (float) - Required - X-ray energy in eV. ### Returns - (delta, beta, atlen) (tuple) - Returns the real part of index of refraction (delta), imaginary part (beta), and attenuation length (atlen) in cm. ``` -------------------------------- ### Define TikZ Styles for X-ray Diagrams Source: https://github.com/xraypy/xraydb/blob/master/poster/elines.tex These styles configure line properties, fonts, and positioning for energy levels and transition paths. ```latex glevel/.style=line width=0.8mm, draw=black!40 blevel/.style=line width=0.8mm, draw=blue!80 rlevel/.style=line width=0.8mm, draw=red!80 xray/.style=*->,>=triangle 45, line width=1mm, font= sieg/.style=fill=white, font= frac/.style=above,fill=white edge/.style=left, font= orbital/.style=right, font= xjoin/.style=*-, line width=1mm ``` -------------------------------- ### Calculate Ion Chamber Fluxes for Gas Mixtures Source: https://github.com/xraypy/xraydb/blob/master/doc/python.rst Computes flux values for a mixture of gases by passing a dictionary defining the relative fractions. ```pycon >>> fl = ionchamber_fluxes(gas={'nitrogen':0.5, 'helium': 0.5}, volts=1.25, length=20.0, energy=10000.0, sensitivity=1.e-6) ``` ```pycon >>> print(f"Fluxes: In={fl.incident:g}, Out={fl.transmitted:g}, Transmitted={100*fl.transmitted/fl.incident:.2f}%") Fluxes: In=6.83845e+11, Out=6.51188e+11, Transmitted=95.22% ``` -------------------------------- ### guess_edge(energy, edges=('K', 'L3', 'L2', 'L1', 'M5')) Source: https://github.com/xraypy/xraydb/blob/master/doc/python.rst Estimates an element and edge based on a provided energy value. ```APIDOC ## guess_edge(energy, edges=('K', 'L3', 'L2', 'L1', 'M5')) ### Description Guesses the most likely element and edge based on an approximate energy value in eV. ### Parameters - **energy** (float) - Required - The approximate edge energy in eV. - **edges** (list of strings) - Optional - The list of edges to consider. Defaults to ('K', 'L3', 'L2', 'L1', 'M5'). ### Returns - **tuple** - A tuple containing (atomic symbol, edge) for the best guess. ``` -------------------------------- ### Plot X-ray mass attenuation for selected elements Source: https://github.com/xraypy/xraydb/blob/master/doc/examples.rst Calculates and plots the total mass attenuation coefficient for Carbon, Copper, and Gold across a range of energies using mu_elam. ```python #!/usr/bin/env python # XrayDB example script python/examples/mu_elements.py # # plot X-ray mass attenuation for selected elements # import numpy as np import matplotlib.pyplot as plt import wxmplot.interactive as wi from xraydb import mu_elam , atomic_symbol energy = np.arange(500, 120000, 10) # energy in eV for elem in ('C', 'Cu', 'Au'): mu = mu_elam(elem, energy) plt.plot(energy, mu, label=elem, linewidth=2) plt.title('X-ray mass attenuation') plt.xlabel('Energy (eV)') plt.ylabel(r'$\mu/\rho \rm\, (cm^2/gr)$') plt.legend() plt.yscale('log') plt.xscale('log') plt.show() ``` -------------------------------- ### Plot X-ray rocking curve Source: https://github.com/xraypy/xraydb/blob/master/doc/examples.rst Visualizes the intensity of a single reflection compared to the rocking curve of two crystals. ```python import numpy as np from xraydb import darwin_width import matplotlib.pyplot as plt dw_si111 = darwin_width(10000, 'Si', (1, 1, 1)) dtheta = dw_si111.dtheta*1e6 fig, ax = plt.subplots(constrained_layout=True) ax.plot(dtheta, dw_si111.intensity, label='$I$, 1 crystal', linewidth=2) ax.plot(dtheta, dw_si111.rocking_curve, label='Rocking Curve', linewidth=2) ax.set_title('X-ray Rocking Curve at 10keV, Si(111)') ax.set_xlabel('Angle - $\theta_B$ ($ \mu ext{rad}$)') ax.set_ylabel('Reflectivity') ax.legend() plt.show() ``` -------------------------------- ### atomic_density(element) Source: https://github.com/xraypy/xraydb/blob/master/doc/python.rst Retrieves the density (gr/cm^3) for the common form of an element. ```APIDOC ## atomic_density(element) ### Description Returns the density (gr/cm^3) for the common form of an element. ### Parameters - **element** (int, str) - Required - Atomic number or atomic symbol. ``` -------------------------------- ### Calculate Darwin Width Source: https://github.com/xraypy/xraydb/blob/master/doc/python.rst Computes the Darwin width for a specified crystal reflection and X-ray energy. Requires the crystal structure to be one of Si, Ge, or C. ```python >>> dw = darwin_width(10000, crystal=’Si’, hkl=(1, 1, 1)) >>> print(dw.theta_width, dw.energy_width) 2.695922108316184e-05 1.336668903324966 ``` -------------------------------- ### mu_elam(element, energy, kind='total') Source: https://github.com/xraypy/xraydb/blob/master/doc/python.rst Retrieves the X-ray mass attenuation coefficient (mu/rho) for a given element and energy using Elam tables. ```APIDOC ## mu_elam(element, energy, kind='total') ### Description Returns the X-ray mass attenuation coefficient (mu/rho) for an element and energy or array of energies. Data is sourced from the Elam tables. ### Parameters - **element** (int, str) - Required - Atomic number or atomic symbol for the element. - **energy** (float, ndarray) - Required - Energy or array of energies. - **kind** (str) - Optional - Type of cross-section to use: 'total', 'photo', 'coh', or 'incoh'. Defaults to 'total'. ### Returns - float or ndarray - The attenuation coefficient in cm^2/gr. ```