API Reference¶
This section contains the API reference for XRayLabTool’s modular architecture.
XRayLabTool is organized into focused sub-packages:
calculators: Core X-ray physics calculations
data_handling: Atomic data caching and batch processing
interfaces: CLI and completion systems
validation: Input validation and error handling
io_operations: File operations and export functionality
analysis: Material comparison and absorption edge detection
export: CSV/JSON export for downstream analysis
gui: PySide6 desktop application
backend: NumPy/JAX array backend abstraction
utils: Utility functions and constants
Core API
- Calculators Module
- Data Handling Module
- Interfaces Module
- Validation Module
- I/O Operations Module
- Utilities Module
- Constants Module
ANGSTROM_TO_METERAVOGADROCM_TO_METERDEGREES_TO_RADIANSELEMENT_CHARGEENERGY_TO_WAVELENGTH_FACTOREV_TO_KEVKEV_TO_EVMETER_TO_ANGSTROMMETER_TO_CMPIPLANCKRADIANS_TO_DEGREESSCATTERING_FACTORSPEED_OF_LIGHTSQRT_2THOMPSONTWO_PIattenuation_length_cm()critical_angle_degrees()energy_to_wavelength_angstrom()validate_constants()wavelength_angstrom_to_energy()- Usage Examples
- Constants Reference Table
- CODATA Standards
High-Level Interface¶
The primary entry points for most users:
Main Calculation Functions¶
- xraylabtool.calculate_single_material_properties(formula, energy_keV=None, density=None, *, energy=None)[source]
Calculate X-ray optical properties for a single material composition.
This is a pure function that calculates comprehensive X-ray optical properties for a single chemical formula at given energies and density. It returns an XRayResult dataclass containing all computed properties.
- Parameters:
formula (
str) – Chemical formula string (e.g., “SiO2”, “Al2O3”, “CaCO3”)energy_keV (
float|floating|ndarray[tuple[Any,...],dtype[TypeVar(_ScalarT, bound=generic)]] |list|None) – X-ray energies in keV. Valid range: 0.03-30.0 keVdensity (
float|floating|ndarray[tuple[Any,...],dtype[TypeVar(_ScalarT, bound=generic)]] |None) – Material mass density in g/cm³ (must be positive)energy (
float|floating|ndarray[tuple[Any,...],dtype[TypeVar(_ScalarT, bound=generic)]] |list|None) – Optional backward-compatible alias (eV). If provided, interpreted as electron-volts and converted to keV.
- Returns:
Dataclass containing all calculated X-ray properties.
- Return type:
XRayResult- Raises:
FormulaError – If chemical formula cannot be parsed or contains invalid elements
EnergyError – If energy values are outside valid range (0.03-30.0 keV)
ValidationError – If density is not positive or other validation failures
Examples
>>> import xraylabtool as xlt >>> result = xlt.calculate_single_material_properties("SiO2", 8.0, 2.2) >>> print(f"Formula: {result.formula}") Formula: SiO2
See also
calculate_xray_properties : Calculate properties for multiple materials XRayResult : Complete documentation of returned dataclass
- xraylabtool.calculate_xray_properties(formulas, energies, densities)[source]
Calculate X-ray optical properties for multiple material compositions.
- Parameters:
- Returns:
Dictionary mapping formula strings to XRayResult objects.
- Return type:
- Raises:
ValidationError – If inputs don’t match
RuntimeError – If no formulas were processed successfully
See also
calculate_single_material_properties : Single material calculations XRayResult : Documentation of returned data structure
Quick Reference¶
Single Material Calculation:
import xraylabtool as xrt
result = xrt.calculate_single_material_properties(
formula="Si",
density=2.33,
energy=8000
)
Batch Calculation:
materials = [
{"formula": "Si", "density": 2.33},
{"formula": "Al", "density": 2.70}
]
energies = [5000, 8000, 10000]
results = xrt.calculate_xray_properties(materials, energies)
Formula Parsing:
from xraylabtool.utils import parse_formula
composition = parse_formula("SiO2")
# Returns: {"Si": 1, "O": 2}
Unit Conversions:
from xraylabtool.utils import energy_to_wavelength, wavelength_to_energy
wavelength = energy_to_wavelength(8000) # eV to Angstrom
energy = wavelength_to_energy(1.55) # Angstrom to eV
Exception Hierarchy¶
- class xraylabtool.exceptions.XRayLabToolError[source]
Bases:
ExceptionBase exception for all XRayLabTool-related errors.
- class xraylabtool.exceptions.ValidationError(message, parameter=None, value=None)[source]
Bases:
XRayLabToolErrorException raised when input validation fails.
- class xraylabtool.exceptions.FormulaError(message, formula=None)[source]
Bases:
XRayLabToolErrorException raised for invalid chemical formulas.
- class xraylabtool.exceptions.EnergyError(message, energy=None, valid_range=None)[source]
Bases:
XRayLabToolErrorException raised for invalid energy values or ranges.
- class xraylabtool.exceptions.CalculationError(message, formula=None, energy=None)[source]
Bases:
XRayLabToolErrorException raised when X-ray property calculations fail.