### ionchamber_fluxes example with default sensitivity units Source: https://xraypy.github.io/XrayDB/_sources/examples.rst.txt Example call to ionchamber_fluxes for nitrogen gas with a 1 V output, 10 cm length, 10000 eV energy, and sensitivity of 1e-9 A/V (default units). ```python >>> fluxes = ionchamber_fluxes('N2', volts=1, energy=10000, length=10, sensitivity=1.e-9) ``` -------------------------------- ### Get material formula and density with get_material() Source: https://xraypy.github.io/XrayDB/python.html Looks up a material by name using get_material() and returns a tuple of chemical formula and density. The example shows the result for 'kapton'. ```python >>> xraydb.get_material('kapton') ('C22H10N2O5', 1.43) ``` -------------------------------- ### Install xraydb with pip Source: https://xraypy.github.io/XrayDB/installation.html Installs the XrayDB Python module, which includes the SQLite database. May require administrative privileges or sudo depending on the system and Python installation. Supports Python 3.9 and above. ```bash pip install xraydb ``` -------------------------------- ### ionchamber_fluxes example with explicit sensitivity units Source: https://xraypy.github.io/XrayDB/_sources/examples.rst.txt Example call to ionchamber_fluxes for nitrogen gas with a 1 V output, 10 cm length, 10000 eV energy, and sensitivity of 1 nA/V specified via sensitivity_units. ```python >>> fluxes = ionchamber_fluxes('N2', volts=1, energy=10000, length=10, sensitivity=1, sensitivity_units='nA/V') ``` -------------------------------- ### Access XrayDB with sqlite3 CLI Source: https://xraypy.github.io/XrayDB/dbschema.html Example of opening the xraydb.sqlite file and executing a standard SQL query to retrieve element data. ```sql 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 ``` -------------------------------- ### Calculate ion chamber currents example Source: https://xraypy.github.io/XrayDB/examples.html An example calculation of ion chamber currents showing how to access the incident and transmitted flux from the returned named tuple. ```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 ``` -------------------------------- ### xray_lines('Mn', 'K') example Source: https://xraypy.github.io/XrayDB/python.html Iterates over the dictionary returned by xray_lines('Mn', 'K') and prints each line name with its XrayLine tuple. The output shows the energy, intensity, initial level, and final level for each emission line. ```python >>> 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 Ion Chamber Fluxes Source: https://xraypy.github.io/XrayDB/_sources/examples.rst.txt Example of calculating ion chamber currents using the ionchamber_fluxes function. ```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 ``` -------------------------------- ### fluor_yield('Fe', 'K', 'Ka', 6800) example Source: https://xraypy.github.io/XrayDB/python.html Calls fluor_yield for iron K-alpha at 6800 eV, returning a yield of 0.0 because the incident energy is below the absorption edge. ```python >>> xraydb.fluor_yield('Fe', 'K', 'Ka', 6800) 0.0, 6400.752419799043, 0.874576096 ``` -------------------------------- ### fluor_yield('Fe', 'K', 'Ka', 8000) example Source: https://xraypy.github.io/XrayDB/python.html Calls fluor_yield for iron K-alpha at 8000 eV, returning the fluorescence yield, weighted average fluorescence energy, and net probability. ```python >>> xraydb.fluor_yield('Fe', 'K', 'Ka', 8000) 0.350, 6400.752419799043, 0.874576096 ``` -------------------------------- ### Find material by name with find_material() Source: https://xraypy.github.io/XrayDB/python.html Looks up a material by name using find_material() and returns a Material instance with formula, density, name, and categories. The example shows the result for 'kapton'. ```python >>> xraydb.find_material('kapton') Material(formula='C22H10N2O5', density=1.42, name='kapton', categories=['polymer']) ``` -------------------------------- ### Add custom material with add_material() Source: https://xraypy.github.io/XrayDB/python.html Adds a custom material to the user's local database using add_material(). The example adds 'becopper' with formula 'Cu0.98e0.02', density 8.3, and category 'metal'. The data is saved to 'xraydb/materials.dat' in the user's configuration folder and persists across sessions. ```python >>> xraydb.add_material('becopper', 'Cu0.98e0.02', 8.3, categories=['metal']) ``` -------------------------------- ### Calculate Ion Chamber Fluxes with Gas Mixture Source: https://xraypy.github.io/XrayDB/_sources/examples.rst.txt Example of calculating ion chamber currents using a dictionary to specify a mixture of gases. ```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 ``` -------------------------------- ### fluor_yield('Ag', 'L3', 'La', 6000) example Source: https://xraypy.github.io/XrayDB/python.html Calls fluor_yield for silver L3-alpha at 6000 eV, returning the fluorescence yield, weighted average energy, and net probability. ```python >>> xraydb.fluor_yield('Ag', 'L3', 'La', 6000) 0.052, 2982.129655446868, 0.861899000000000 ``` -------------------------------- ### Compute ion chamber fluxes with ionchamber_fluxes() Source: https://xraypy.github.io/XrayDB/python.html Use ionchamber_fluxes() to compute ion chamber fluxes for a given gas, voltage, length, energy, and sensitivity. The first example uses nitrogen with default sensitivity units (A/V); the second prints the resulting fluxes and transmitted percentage. The third example uses a gas mixture of nitrogen and helium; the fourth prints the corresponding fluxes and transmitted percentage. ```python >>> from xraydb import ionchamber_fluxes >>> fl = ionchamber_fluxes(gas='nitrogen', volts=1.25, length=20.0, energy=10e3, sensitivity=1.e-6) ``` ```python >>> print(f"Fluxes: In={fl.incident:g}, Out={fl.transmitted:g}, Transmitted={100*fl.transmitted/fl.incident:.2f}%") Fluxes: In=3.20045e+11, Out=2.90464e+11, Transmitted=90.76% ``` ```python >>> fl = ionchamber_fluxes(gas={'nitrogen':0.5, 'helium': 0.5}, volts=1.25, length=20.0, energy=10000.0, sensitivity=1.e-6) ``` ```python >>> 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% ``` -------------------------------- ### Parse chemical formulas with chemparse() Source: https://xraypy.github.io/XrayDB/python.html Shows how to parse chemical formulas with chemparse(). The first example imports the function and parses a formula with parentheses and water. The second parses a formula with a decimal exponent. The third distinguishes uppercase 'CO' (carbon monoxide) from 'Co' (cobalt). The fourth shows that lowercase 'co' raises a ValueError. ```python >>> from xraydb import chemparse >>> chemparse('Mn(SO4)2(H2O)7)') {'H': 14.0, 'S': 2.0, 'Mn': 1, 'O': 15.0} ``` ```python >>> chemparse('Zn1.e-5Fe3O4') {'Zn': 1e-05, 'Fe': 3.0, 'O': 4.0} ``` ```python >>> chemparse('CO') {'C': 1, 'O': 1} >>> chemparse('Co') {'Co': 1} ``` ```python >>> chemparse('co') ValueError: unrecognized element or number: co ``` -------------------------------- ### xray_edges(element) Source: https://xraypy.github.io/XrayDB/python.html Get dictionary of x-ray absorption edges for an element, including energy, fluorescence yield, and jump ratio. ```APIDOC ## xray_edges(element) ### Description Get dictionary of x-ray absorption edges: energy (in eV), fluorescence yield, and jump ratio for an element. ### Method Function call ### Endpoint xray_edges(element) ### Parameters - **element** (int, str) - Required - atomic number or atomic symbol for element ### Returns dictionary of XrayEdge named tuples. Keys are edge (iupac symbol) and values are XrayEdge namedtuple containing (energy, fluorescence_yield, edge_jump). ``` -------------------------------- ### Calculate and plot Darwin widths with darwin_width() Source: https://xraypy.github.io/XrayDB/examples.html Compute Darwin widths for Si(111) at 10 keV and Si(333) at 30 keV using darwin_width(), print the angular and energy widths, and plot the reflectivity curves. The example shows the returned DarwinWidth fields (theta_width, energy_width, dtheta, intensity) and uses matplotlib to display the intensity and its square for both reflections. ```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() ``` -------------------------------- ### atomic_density(element) Source: https://xraypy.github.io/XrayDB/python.html Get the density of common form of an element. ```APIDOC ## atomic_density(element) ### Description Returns density (gr/cm^3) for common form of an element. ### Parameters - **element** (int or str) - Required - atomic number or atomic symbol for element ### Returns - density in gm/cm^3 ``` -------------------------------- ### xray_edge(element, edge, energy_only=False) Source: https://xraypy.github.io/XrayDB/python.html Get x-ray absorption edge data for an element: energy (in eV), fluorescence yield, and jump ratio. ```APIDOC ## xray_edge(element, edge, energy_only=False) ### Description Get x-ray absorption edge data for an element: energy (in eV), fluorescence yield, and jump ratio. ### Method Function call ### Endpoint xray_edge(element, edge, energy_only=False) ### Parameters - **element** (int, str) - Required - atomic number or atomic symbol for element - **edge** (str) - Required - iupac symbol of X-ray edge - **energy_only** (bool) - Optional - whether to return only the energy [False] ### Returns XrayEdge namedtuple containing (energy, fluorescence_yield, edge_jump) or float of energy if energy_only is True. ``` -------------------------------- ### Validate chemical formulas with validate_formula() Source: https://xraypy.github.io/XrayDB/python.html Shows how to check whether a chemical formula is valid using validate_formula(). The first example returns True for a valid formula. The second and third return False for invalid formulas (missing closing parenthesis and unrecognized element 'Z'). ```python >>> from xraydb import validate_formula >>> validate_formula('Mn(SO4)2(H2O)7)') True ``` ```python >>> validate_formula('Mn(SO4)2(H2O7') False ``` ```python >>> validate_formula('Z') False ``` -------------------------------- ### material_mu: absorption length for a material Source: https://xraypy.github.io/XrayDB/python.html Returns the absorption length in 1/cm for a material by name or formula at a given energy in eV. The example shows the result for water at 10000 eV. ```python >>> material_mu('H2O', 10000.0) 5.32986401658495 ``` -------------------------------- ### 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://xraypy.github.io/XrayDB/python.html Calculates reflectivity for a multilayer mirror. Parameters include stackup, thickness, substrate, theta, energy, and optional parameters for periods, density, roughness, polarization, and output. ```APIDOC ## 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') ### Description Calculates reflectivity for a multilayer mirror. ### Method Function call ### Endpoint 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') ### Parameters #### Path Parameters - **stackup** - Required - description not provided in source - **thickness** - Required - description not provided in source - **substrate** - Required - description not provided in source - **theta** - Required - description not provided in source - **energy** - Required - description not provided in source - **n_periods** (int) - Optional - number of periods [default 1] - **density** - Optional - description not provided in source - **substrate_density** - Optional - description not provided in source - **substrate_rough** (float) - Optional - substrate roughness [default 0.0] - **surface_rough** (float) - Optional - surface roughness [default 0.0] - **polarization** ('s') - Optional - polarization [default 's'] - **output** ('intensity') - Optional - output type [default 'intensity'] ### Returns Reflectivity values for the multilayer mirror. ### Notes No additional notes provided in source. ``` -------------------------------- ### List all materials with get_materials() Source: https://xraypy.github.io/XrayDB/python.html Iterates over the dictionary returned by get_materials() and prints each material's name, formula, and density. The output shows a few entries from the built-in materials database. ```python >>> 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 ... ``` -------------------------------- ### atomic_name(z) Source: https://xraypy.github.io/XrayDB/python.html Get the atomic name for a given atomic number. ```APIDOC ## atomic_name(z) ### Description Returns the atomic name (English) for an atomic number. ### Parameters - **z** (int) - Required - atomic number ### Returns - atomic name (English) ``` -------------------------------- ### atomic_number(element) Source: https://xraypy.github.io/XrayDB/python.html Get the atomic number (z) for a given element name. ```APIDOC ## atomic_number(element) ### Description Returns the atomic number z for an element name. ### Parameters - **element** (str) - Required - atomic symbol ### Returns - atomic number ``` -------------------------------- ### material_mu and material_mu_components for quartz Source: https://xraypy.github.io/XrayDB/python.html Shows the absorption coefficient for quartz at 10000 eV and the detailed per-element components returned by material_mu_components, including mass, density, and element tuples of (stoichiometric fraction, atomic mass, mu). ```python >>> 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)} ``` -------------------------------- ### ck_probability(element, initial, final, total=True) Source: https://xraypy.github.io/XrayDB/python.html Calculates the transition probability for a given element, initial level, and final level. ```APIDOC ## ck_probability(element, initial, final, total=True) ### Description Transition probability for an element, initial, and final levels. ### Method Function call ### Endpoint ck_probability(element, initial, final, total=True) ### Parameters - **element** (int, str) - Required - atomic number, atomic symbol for element - **initial** (str) - Required - iupac symbol for initial level - **final** (str) - Required - iupac symbol for final level - **total** (bool) - Optional - whether to include transitions via possible intermediate levels [True] ### Returns transition probability, or 0 if transition is not allowed. ``` -------------------------------- ### Calculate ion chamber fluxes with sensitivity units Source: https://xraypy.github.io/XrayDB/examples.html Demonstrates that using different sensitivity units like 'A/V' and 'nA/V' yields the same results. ```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') ``` -------------------------------- ### Replace material calculation for CaCO3 Source: https://xraypy.github.io/XrayDB/examples.html Demonstrates replacing the water material calculation with CaCO3, specifying a custom density. ```python mu = material_mu('H2O', energy) ``` ```python mu = material_mu('CaCO3', energy, density=2.71) ``` -------------------------------- ### get_xraydb() returns XrayDB instance Source: https://xraypy.github.io/XrayDB/python.html Creates an instance of the XrayDB class by calling get_xraydb(). The returned object provides access to the xraydb.sqlite database. ```python >>> import xraydb >>> xdb = xraydb.get_xraydb() ``` -------------------------------- ### Use xraydb functions for atomic and X-ray data Source: https://xraypy.github.io/XrayDB/_sources/python.rst.txt Interactive Python session showing core xraydb functions: atomic_number, f0, xray_lines, xray_edge, and mu_elam. The output includes the atomic number of Ag, elastic scattering factors for Fe, emission lines for Zn, the As K edge, and attenuation factors near the edge. ```python >>> 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 ``` -------------------------------- ### Calculate multilayer mirror reflectivity Source: https://xraypy.github.io/XrayDB/examples.html Calculates and plots the reflectivity for a 40-period [Si, W] multilayer mirror on an SiO2 substrate using Parratt’s Recursive Method. ```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() ``` -------------------------------- ### get_materials Source: https://xraypy.github.io/XrayDB/_sources/python.rst.txt Returns a dictionary of known materials. ```APIDOC ## get_materials ### Description Returns a dictionary of known materials with their formulas and densities. ### Method Function call ### Endpoint `get_materials()` ### Parameters None ### Returns - **materials** (dict) - Dictionary mapping material names to (formula, density) tuples. ``` -------------------------------- ### Clone XrayDB development repository Source: https://xraypy.github.io/XrayDB/installation.html Clones the full source code kit from GitHub, which contains the current database, original source data, Python module, and files for generating Periodic Table posters. Use this to work with data sources or add/modify data. ```bash git clone https://github.com/xraypy/XrayDB.git ``` -------------------------------- ### add_material Source: https://xraypy.github.io/XrayDB/_sources/python.rst.txt Adds a material to the local materials database. ```APIDOC ## add_material ### Description Adds a material to the local materials database. ### Method Function call ### Endpoint `add_material(name, formula, density)` ### Parameters - **name** (str) - Required - Material name. - **formula** (str) - Required - Chemical formula. - **density** (float) - Required - Density in g/cm^3. ### Returns None ``` -------------------------------- ### XrayDB database schema (version 4) Source: https://xraypy.github.io/XrayDB/_sources/dbschema.rst.txt Displays the full SQLite schema for version 4 of the xraydb.sqlite database, listing all tables and their columns. Tables include Version, elements, xray_levels, xray_transitions, Coster_Kronig, photoabsorption, scattering, Waasmaier, KeskiRahkonen_Krause, Krause_Oliver, corelevel_widths, and Chantler. ```sql Table Version (id integer primary key, tag text, date text, notes text); Table elements (atomic_number integer primary key, element text, name text, molar_mass real, density real); Table xray_levels (id integer primary key, element text, iupac_symbol text, absorption_edge real, fluorescence_yield real, jump_ratio real); Table xray_transitions (id integer primary key, element text, iupac_symbol text, siegbahn_symbol text, initial_level text, final_level text, emission_energy real, intensity real); Table Coster_Kronig (id integer primary key, element text, initial_level text, final_level text, transition_probability real, total_transition_probability real); Table photoabsorption (id integer primary key, element text, log_energy text, log_photoabsorption text, log_photoabsorption_spline text); Table scattering (id integer primary key, element text, log_energy text, log_coherent_scatter text, log_coherent_scatter_spline text, log_incoherent_scatter text, log_incoherent_scatter_spline text); Table Waasmaier (id integer primary key, atomic_number integer, element text, ion text, offset real, scale text, exponents text); Table KeskiRahkonen_Krause (id integer primary key, atomic_number integer, element text, edge text, width float); Table Krause_Oliver (id integer primary key, atomic_number integer, element text, edge text, width float); Table corelevel_widths (id integer primary key, atomic_number integer, element text, edge text, width float); Table Chantler (id integer primary key, element text, sigma_mu real, mue_f2 real, density real, corr_henke float, corr_cl35 float, corr_nucl float, energy text, f1 text, f2 text, mu_photo text, mu_incoh text, mu_total text); ``` -------------------------------- ### Query elements table with sqlite3 Source: https://xraypy.github.io/XrayDB/_sources/dbschema.rst.txt Shows basic usage of the sqlite3 command-line program to query the elements table for atomic number 47. Enables headers with '.headers on' and displays the result row. ```sql sqlite3 xraydb.sqlite .headers on select * from elements where atomic_number=47; ``` -------------------------------- ### Plot Darwin Width and Rocking Curve in Python Source: https://xraypy.github.io/XrayDB/examples.html Imports `darwin_width` from xraydb and uses matplotlib to plot the intensity of a single reflection and the rocking curve of two crystals for Si(111) at 10 keV, using micro-radian offsets. ```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 \mathrm{rad}$)') ax.set_ylabel('Reflectivity') ax.legend() plt.show() ``` -------------------------------- ### Calculate coated mirror reflectivity Source: https://xraypy.github.io/XrayDB/examples.html Calculates and plots the reflectivity for a Rh-coated Si mirror with a Cr binder layer, comparing it to a bulk Rh mirror at 4 mrad. ```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() ``` -------------------------------- ### material_mu_components(name, energy, density=None, kind='total') Source: https://xraypy.github.io/XrayDB/python.html Computes the absorption coefficient (in 1/cm) for a compound and returns a dictionary for constructing mu per element. ```APIDOC ## material_mu_components(name, energy, density=None, kind='total') ### Description Computes the absorption coefficient (in 1/cm) for a compound and returns a dictionary for constructing mu per element. ### 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 (g/cm^3). If None and material is known, that density will be used. - **kind** (str) - Optional - 'photo' or 'total' for whether to return photo-absorption or total cross-section. Default is 'total'. ### Returns - dict with elements 'mass' (total mass), 'density', and 'elements' (list of atomic symbols). For each element, an item with atomic symbol as key and tuple of (stoichiometric fraction, atomic mass, mu). ### Example ```python >>> 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)} ``` ``` -------------------------------- ### darwin_width(energy, crystal='Si', hkl=(1,1,1), a=None, polarization='s', ignore_f2=False, ignore_f1=False, m=1) Source: https://xraypy.github.io/XrayDB/python.html Calculates the Darwin width for a crystal reflection at a given energy. Returns a named tuple with angular and energy widths, rocking curve data, and related parameters. ```APIDOC ## darwin_width(energy, crystal='Si', hkl=(1,1,1), a=None, polarization='s', ignore_f2=False, ignore_f1=False, m=1) ### Description Calculates the Darwin width for a crystal reflection at a given energy. ### Method Function call ### Endpoint darwin_width(energy, crystal='Si', hkl=(1,1,1), a=None, polarization='s', ignore_f2=False, ignore_f1=False, m=1) ### Parameters #### Path Parameters - **energy** (float) - Required - X-ray energy in eV - **crystal** (string) - Optional - name of crystal (one of '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 - use built-in value] - **polarization** ('s','p','u') - Optional - mono orientation relative to X-ray polarization [default 's'] - **ignore_f1** (bool) - Optional - ignore contribution from f1 - dispersion [default False] - **ignore_f2** (bool) - Optional - ignore contribution from f2 - absorption [default False] - **m** (int) - Optional - order of reflection [default 1] ### Returns A named tuple 'DarwinWidth' with fields: - theta: float, nominal Bragg angle, in rad - theta_offset: float, angular offset from Bragg angle, in rad - theta_width: float, estimated angular Darwin width, in rad - theta_fwhm: float, estimated FWHM of angular intensity, in rad - rocking_theta_fwhm: float, estimated FWHM of a rocking curve, in rad - energy_width: float, estimated angular Darwin width, in rad - energy_fwhm: float, estimated FWHM of energy intensity, in eV - rocking_energy_fwhm: float, estimated FWHM of a rocking curve, in eV - zeta: nd-array of Zeta parameter (delta_Lambda / Lambda) - dtheta: nd-array of angles away from Bragg angle, theta in rad - denergy: nd-array of energies away from Bragg energy, in eV - intensity: nd-array of reflected intensity - rocking_curve: nd-array of rocking curve of 2 crystals ### Notes 1. This follows the calculation from section 6.4 of Elements of Modern X-ray Physics, 2nd Edition J Als-Nielsen, and D. McMorrow. 2. Only diamond structures (Si, Ge, diamond) are currently supported. Default values of lattice constant a are in Angstroms: 5.4309 for Si, 5.6578, for 'Ge', and 3.567 for 'C'. 3. The theta_width and energy_width values will closely match the width of the intensity profile that would = 1 when ignoring the effect of absorption. These are the values commonly reported as 'Darwin Width'. The value reported for theta_fwhm' and `energy_fwhm are larger than this by sqrt(9/8) ~= 1.06. 4. Polarization can be 's', 'p', 'u', or None. 's' means vertically deflecting crystal and a horizontally-polarized source, as for most synchrotron beamlines. 'p' is for a horizontally-deflecting crystal. 'u' or None is for unpolarized light, as for most fluorescence/emission. 5. The rocking_curve will be the convolution of the intensity with itself, to simulate an angular scan of one crystal with respect to the other, as is often done with double-crystal monochromators. rocking_theta_fwhm and rocking_energy_fwhm will be the FWHM of this curve in angle and energy, and will typiccally be ~1.5x the Darwin widths in theta_width and energy_width, respectively. ### Example ```python >>> dw = darwin_width(10000, crystal='Si', hkl=(1, 1, 1)) >>> print(dw.theta_width, dw.energy_width) 2.695922108316184e-05 1.336668903324966 ``` ``` -------------------------------- ### coated_reflectivity Source: https://xraypy.github.io/XrayDB/python.html Computes reflectivity for a coated mirror, allowing specification of coating, substrate, and optional binder layers. ```APIDOC ## coated_reflectivity ### Description Computes reflectivity for a coated mirror, allowing specification of coating, substrate, and optional binder layers. ### Method Function call ### Endpoint `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')` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **coating** (str) - Required - Coating material name or formula (e.g., 'Si', 'Rh', 'silicon') - **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 (default None) - **surface_roughness** (float) - Optional - Coating roughness in Angstroms (default 0.0) - **substrate_dens** (float) - Optional - Density of substrate in g/cm^3 (default None) - **substrate_roughness** (float) - Optional - Substrate roughness in Angstroms (default 0.0) - **binder** (str) - Optional - Binder material name or formula (default None) - **binder_thick** (float) - Optional - Thickness of binder in Angstroms (default None) - **binder_dens** (float) - Optional - Density of binder in g/cm^3 (default None) - **polarization** ('s' or 'p') - Optional - Mirror orientation relative to X-ray polarization (default 's') - **output** (str) - Optional - Output intensity or complex amplitude (default 'intensity') ### Request Example ``` coated_reflectivity('Rh', 100.0, 'Si', 0.01, 10000.0) ``` ### Response #### Success Response (200) - **mirror reflectivity values** (float or nd-array) - Reflectivity values #### Response Example ``` 0.95 ``` ### Notes - Only one of theta or energy can be an nd-array. - Densities can be None for known materials or a list of 1 period ([‘Mo’, ‘Si’]) for a multilayer stackup. - Polarization of ‘s’ puts the X-ray polarization along the mirror surface, ‘p’ puts it normal to the mirror surface. For horizontally polarized X-ray beams from storage rings, ‘s’ will usually mean ‘vertically deflecting’ and ‘p’ will usually mean ‘horizontally deflecting’. ``` -------------------------------- ### mirror_reflectivity(formula, theta, energy, density=None, roughness=0.0, polarization='s', output='intensity') Source: https://xraypy.github.io/XrayDB/python.html Calculates mirror reflectivity for a thick, single-layer mirror. Accepts material formula, angle, energy, and optional density, roughness, polarization, and output type. ```APIDOC ## mirror_reflectivity(formula, theta, energy, density=None, roughness=0.0, polarization='s', output='intensity') ### Description Calculates mirror reflectivity for a thick, single-layer mirror. ### Method Function call ### Endpoint mirror_reflectivity(formula, theta, energy, density=None, roughness=0.0, polarization='s', output='intensity') ### Parameters #### Path Parameters - **formula** (string) - Required - material name or formula ('Si', 'Rh', 'silicon') - **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 - **polarization** ('s' or 'p') - Optional - mirror orientation relative to X-ray polarization - **output** (str) - Optional - output intensity or complex amplitude ### Returns Mirror reflectivity values ### Notes 1. If both theta and energy are nd-arrays, it returns a 2D array of theta vs energy. Ex: r[i,j] = r(theta[i], energy[j]) 2. density can be None for known materials 3. polarization of 's' puts the X-ray polarization along the mirror surface, 'p' puts it normal to the mirror surface. For horizontally polarized X-ray beams from storage rings, 's' will usually mean 'vertically deflecting' and 'p' will usually mean 'horizontally deflecting'. ``` -------------------------------- ### mirror_reflectivity Source: https://xraypy.github.io/XrayDB/python.html Computes mirror reflectivity for a stackup of materials, including multilayer structures, given the angle and energy. ```APIDOC ## mirror_reflectivity ### Description Computes mirror reflectivity for a stackup of materials, including multilayer structures, given the angle and energy. ### Method Function call ### Endpoint `mirror_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')` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **stackup** (list of formulas) - Required - Material name or formula for each layer (e.g., 'Si', 'Rh', 'silicon') - **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 (default 1) - **density** (list or None) - Optional - Material densities in g/cm^3 (default None) - **substrate_density** (float) - Optional - Density of substrate in g/cm^3 (default None) - **substrate_rough** (float) - Optional - Mirror roughness in Angstroms (default 0.0) - **surface_rough** (float) - Optional - Mirror roughness in Angstroms (default 0.0) - **polarization** ('s' or 'p') - Optional - Mirror orientation relative to X-ray polarization (default 's') - **output** (str) - Optional - Output intensity or complex amplitude (default 'intensity') ### Request Example ``` mirror_reflectivity(['Mo', 'Si'], [20, 30], 'Si', 0.01, 10000.0, n_periods=10) ``` ### Response #### Success Response (200) - **mirror reflectivity values** (float or nd-array) - Reflectivity values #### Response Example ``` 0.987 ``` ### Notes - Only one of theta or energy can be an nd-array. - thickness should be the same length as stackup. - density can be None for known materials or a list of 1 period ([‘Mo’, ‘Si’]) for a multilayer stackup. - polarization of ‘s’ puts the X-ray polarization along the mirror surface, ‘p’ puts it normal to the mirror surface. For horizontally polarized X-ray beams from storage rings, ‘s’ will usually mean ‘vertically deflecting’ and ‘p’ will usually mean ‘horizontally deflecting’. ```