Skip to main content

Crate rexafs

Crate rexafs 

Source
Expand description

Process and fit X-ray absorption spectroscopy (XAS) data in Rust.

Start with Spectrum, an owned spectrum with mutable processing settings. Spectrum::fft calculates missing normalization and background stages; Spectrum::ifft filters the Fourier result back to a real signal. No calculation runs when a result getter is called. Getters return None until the relevant stage succeeds, or after its results are invalidated.

§A checked processing pipeline

use rexafs::{PrePostEdge, Spectrum, XrayFFTF, AUTOBK};

fn analyze(energy_ev: &[f64], mu: &[f64]) -> rexafs::Result<Spectrum> {
    let mut spectrum = Spectrum::from_arrays(energy_ev, mu)?;
    spectrum.set_normalization_method(PrePostEdge::new())?;
    spectrum.set_background_method(AUTOBK::new())?;
    let mut transform = XrayFFTF::default();
    transform.kweight = Some(2.0);
    spectrum.set_fft(transform).fft()?;
    // k() and chi() borrow; chir_mag() returns an owned vector.
    println!("E0 = {:?} eV", spectrum.e0());
    Ok(spectrum)
}

Energy is in eV, the photoelectron wave number k is in Å⁻¹, and Fourier distance R is in Å. Spectrum::from_arrays copies finite, equally sized slices with at least two points and strictly increasing energy. Later stages also need sufficient pre-edge, post-edge and EXAFS coverage. Use the typed Error to report a failed stage; successful earlier stages can remain stored.

§Find the API you need

Entry pointPurpose
Spectrum, GroupOne spectrum or a collection, with automatic prerequisite stages.
PrePostEdge, AUTOBK, XrayFFTF, XrayFFTRDefaults and configurable normalization, background and Fourier operations.
toolsCalibration, alignment, deglitching, smoothing, rebinning and merging.
analysisLinear combination fitting and principal component analysis.
ioQAS/XDI data and Athena project interchange.
structureStructures, clusters, scattering paths and FEFF inputs.
fittingFEFF path models and single, joint or independent fits.
rmcExperimental reverse Monte Carlo refinement of atomic coordinates.

Rust setters take ownership of settings. Call .clone() before passing a configuration if you need to retain it. Setters invalidate dependent results; direct edits to legacy public fields require Spectrum::invalidate_derived.

§Cargo features

trust-region is enabled by default and provides optional optimizer support. plotting enables the ruviz plot builders. refeff-runner and feff10-runner enable calculation backends; fitting existing FEFF path files needs neither. amcsd enables a local structure catalog; materials-project and cod enable online sources through the shared http feature. ndarray-compat selects the historical ndarray implementation instead of the default nalgebra path. Optional backends may need extra platform dependencies. Enabling every feature also selects ndarray-compat, so it does not describe the default numerical backend.

See the user guide and processing theory for workflows and interpretation. The crate was developed under the codename xraytsubaki.

Scientific background: Newville et al., AUTOBK (1993) and Rehr and Albers, XAFS theory (2000). The fixed endpoint penalty is a rexafs-specific choice; Fourier peaks are not automatically phase corrected.

Re-exports§

pub use xafs::analysis::peakfit::PeakFit;
pub use xafs::analysis::peakfit::PeakFitError;
pub use xafs::analysis::peakfit::PeakFitResult;
pub use xafs::background::BackgroundMethod;
pub use xafs::background::AUTOBK;
pub use xafs::fluorescence::AbsorptionMode;
pub use xafs::fluorescence::FluorescenceCorrection;
pub use xafs::fluorescence::FluorescenceCorrectionResult;
pub use xafs::fluorescence::FluorescenceError;
pub use xafs::normalization::MBack;
pub use xafs::normalization::NormalizationMethod;
pub use xafs::normalization::PrePostEdge;
pub use xafs::xasgroup::XASGroup as Group;
pub use xafs::xasspectrum::XASSpectrum as Spectrum;
pub use xafs::xrayfft::FFTGrid;
pub use xafs::xrayfft::XrayFFTF;
pub use xafs::xrayfft::XrayFFTR;
pub use xafs::analysis;
pub use xafs::fitting;
pub use xafs::io;
pub use xafs::rmc;
pub use xafs::structure;
pub use xafs::tools;
pub use xafs::transform;
pub use xafs::Result;
pub use xafs::XAFSError as Error;
pub use crate::xafs::wavelet::Wavelet;
pub use crate::xafs::wavelet::WaveletError;
pub use crate::xafs::wavelet::WaveletMap;
pub use crate::xafs::wavelet::WaveletPreparation;
pub use crate::xafs::wavelet::WaveletRegionValue;
pub use crate::xafs::wavelet::WaveletSize;
pub use crate::xafs::wavelet::WaveletWindow;

Modules§

atomic
Offline atomic references for absorption normalization and correction (since 0.2.10).
parser
Reserved parser module retained for source compatibility.
prelude
Common spectrum, fitting, structure and data-treatment imports.
xafs
Processing, analysis, fitting, structures and interchange for XAS spectra.