Skip to main content

xraydb_data/
lib.rs

1//! Serde data model shared by the `xraydb` crates.
2//!
3//! This crate is `#![no_std]` and holds only plain data structures; all lookup and
4//! calculation lives in `xraydb`. It exists so the generator binary and the library
5//! agree on the on-disk format without the library depending on the generator.
6
7#![no_std]
8#![forbid(unsafe_code)]
9#![warn(missing_docs)]
10#![deny(clippy::unwrap_used, clippy::expect_used)]
11
12extern crate alloc;
13
14use alloc::string::String;
15use alloc::vec::Vec;
16use serde::{Deserialize, Serialize};
17
18/// The complete XrayDB database, deserialized from the embedded blob.
19#[derive(Debug, Serialize, Deserialize)]
20pub struct XrayDatabase {
21    /// Upstream XrayDB version records.
22    pub version: Vec<VersionRecord>,
23    /// One record per element, ordered by atomic number.
24    pub elements: Vec<ElementRecord>,
25    /// Absorption edges (one row per element and IUPAC level).
26    pub xray_levels: Vec<XrayLevelRecord>,
27    /// Emission lines (one row per element and Siegbahn label).
28    pub xray_transitions: Vec<XrayTransitionRecord>,
29    /// Coster-Kronig transition probabilities.
30    pub coster_kronig: Vec<CosterKronigRecord>,
31    /// Elam photoabsorption cross-section splines.
32    pub photoabsorption: Vec<PhotoabsorptionRecord>,
33    /// Elam coherent and incoherent scattering splines.
34    pub scattering: Vec<ScatteringRecord>,
35    /// Chantler anomalous-scattering and attenuation tables.
36    pub chantler: Vec<ChantlerRecord>,
37    /// Waasmaier-Kirfel f0 coefficients, one row per ion.
38    pub waasmaier: Vec<WaasmaierRecord>,
39    /// Tabulated Compton scattering energies.
40    pub compton_energies: ComptonEnergiesRecord,
41    /// Core widths from Keski-Rahkonen & Krause.
42    pub keski_rahkonen_krause: Vec<CoreWidthRecord>,
43    /// Core widths from Krause & Oliver (1979).
44    pub krause_oliver: Vec<CoreWidthRecord>,
45    /// Merged core widths: KK updated with KO for K, L1, L2, L3.
46    pub corelevel_widths: Vec<CoreWidthRecord>,
47    /// Ion-chamber gas ionization potentials, eV per ion pair.
48    pub ionization_potentials: Vec<IonizationPotentialRecord>,
49}
50
51/// One upstream XrayDB version entry.
52#[derive(Debug, Serialize, Deserialize)]
53pub struct VersionRecord {
54    /// Version tag, e.g. `"1.0"`.
55    pub tag: String,
56    /// Release date as written upstream.
57    pub date: String,
58    /// Free-text release notes.
59    pub notes: String,
60}
61
62/// Basic facts about one element.
63#[derive(Debug, Serialize, Deserialize)]
64pub struct ElementRecord {
65    /// Atomic number Z.
66    pub atomic_number: u16,
67    /// Element symbol, e.g. `"Fe"`.
68    pub symbol: String,
69    /// Element name, e.g. `"iron"`.
70    pub name: String,
71    /// Molar mass in g/mol.
72    pub molar_mass: f64,
73    /// Density in g/cm³ at standard conditions.
74    pub density: f64,
75}
76
77/// One absorption edge of one element.
78#[derive(Debug, Serialize, Deserialize)]
79pub struct XrayLevelRecord {
80    /// Element symbol this row belongs to.
81    pub element: String,
82    /// IUPAC level label, e.g. `"K"`, `"L3"`.
83    pub iupac_symbol: String,
84    /// Absorption edge energy in eV.
85    pub absorption_edge: f64,
86    /// Fluorescence yield, 0-1.
87    pub fluorescence_yield: f64,
88    /// Absorption jump ratio across the edge.
89    pub jump_ratio: f64,
90}
91
92/// One emission line of one element.
93#[derive(Debug, Serialize, Deserialize)]
94pub struct XrayTransitionRecord {
95    /// Element symbol this row belongs to.
96    pub element: String,
97    /// IUPAC level label, e.g. `"K"`, `"L3"`.
98    pub iupac_symbol: String,
99    /// Siegbahn line label, e.g. `"Ka1"`.
100    pub siegbahn_symbol: String,
101    /// IUPAC label of the initial (core-hole) level.
102    pub initial_level: String,
103    /// IUPAC label of the final level.
104    pub final_level: String,
105    /// Emission energy in eV.
106    pub emission_energy: f64,
107    /// Relative intensity, normalized within the initial level.
108    pub intensity: f64,
109}
110
111/// One Coster-Kronig transition between levels of the same shell.
112#[derive(Debug, Serialize, Deserialize)]
113pub struct CosterKronigRecord {
114    /// Element symbol this row belongs to.
115    pub element: String,
116    /// IUPAC label of the initial (core-hole) level.
117    pub initial_level: String,
118    /// IUPAC label of the final level.
119    pub final_level: String,
120    /// Direct transition probability.
121    pub transition_probability: f64,
122    /// Total probability including intermediate states.
123    pub total_transition_probability: f64,
124}
125
126/// Elam photoabsorption spline for one element, in log-log space.
127#[derive(Debug, Serialize, Deserialize)]
128pub struct PhotoabsorptionRecord {
129    /// Element symbol this row belongs to.
130    pub element: String,
131    /// Natural log of the tabulated energies in eV.
132    pub log_energy: Vec<f64>,
133    /// Natural log of the photoabsorption cross-section in cm²/g.
134    pub log_photoabsorption: Vec<f64>,
135    /// Second derivatives for `log_photoabsorption`.
136    pub log_photoabsorption_spline: Vec<f64>,
137}
138
139/// Elam coherent and incoherent scattering splines for one element.
140#[derive(Debug, Serialize, Deserialize)]
141pub struct ScatteringRecord {
142    /// Element symbol this row belongs to.
143    pub element: String,
144    /// Natural log of the tabulated energies in eV.
145    pub log_energy: Vec<f64>,
146    /// Natural log of the coherent scattering cross-section in cm²/g.
147    pub log_coherent_scatter: Vec<f64>,
148    /// Second derivatives for `log_coherent_scatter`.
149    pub log_coherent_scatter_spline: Vec<f64>,
150    /// Natural log of the incoherent scattering cross-section in cm²/g.
151    pub log_incoherent_scatter: Vec<f64>,
152    /// Second derivatives for `log_incoherent_scatter`.
153    pub log_incoherent_scatter_spline: Vec<f64>,
154}
155
156/// Chantler tables for one element.
157#[derive(Debug, Serialize, Deserialize)]
158pub struct ChantlerRecord {
159    /// Element symbol this row belongs to.
160    pub element: String,
161    /// Chantler sigma_mu normalization constant.
162    pub sigma_mu: f64,
163    /// Chantler mu_e/f2 conversion constant.
164    pub mue_f2: f64,
165    /// Density in g/cm³ at standard conditions.
166    pub density: f64,
167    /// Henke-scale correction term.
168    pub corr_henke: f64,
169    /// Cromer-Liberman 3.5 keV correction term.
170    pub corr_cl35: f64,
171    /// Nuclear Thomson correction term.
172    pub corr_nucl: f64,
173    /// Tabulated energies in eV.
174    pub energy: Vec<f64>,
175    /// Anomalous scattering factor f' (Z already subtracted).
176    pub f1: Vec<f64>,
177    /// Anomalous scattering factor f".
178    pub f2: Vec<f64>,
179    /// Photoelectric mass attenuation in cm²/g.
180    pub mu_photo: Vec<f64>,
181    /// Incoherent mass attenuation in cm²/g.
182    pub mu_incoh: Vec<f64>,
183    /// Total mass attenuation in cm²/g.
184    pub mu_total: Vec<f64>,
185}
186
187/// Waasmaier-Kirfel f0 coefficients for one ion.
188#[derive(Debug, Serialize, Deserialize)]
189pub struct WaasmaierRecord {
190    /// Atomic number Z.
191    pub atomic_number: u16,
192    /// Element symbol this row belongs to.
193    pub element: String,
194    /// Ion label, e.g. `"Fe"`, `"Fe2+"`.
195    pub ion: String,
196    /// Constant term c in f0(q) = c + sum(a_i exp(-b_i q²)).
197    pub offset: f64,
198    /// Amplitudes a_i.
199    pub scale: Vec<f64>,
200    /// Exponents b_i in Ų.
201    pub exponents: Vec<f64>,
202}
203
204/// Tabulated Compton scattering energies.
205#[derive(Debug, Serialize, Deserialize)]
206pub struct ComptonEnergiesRecord {
207    /// Incident photon energies in eV.
208    pub incident: Vec<f64>,
209    /// Energy of a photon scattered through 90°, in eV.
210    pub xray_90deg: Vec<f64>,
211    /// Mean scattered-photon energy in eV.
212    pub xray_mean: Vec<f64>,
213    /// Mean recoil-electron energy in eV.
214    pub electron_mean: Vec<f64>,
215}
216
217/// Core-hole width for one element and edge.
218#[derive(Debug, Serialize, Deserialize)]
219pub struct CoreWidthRecord {
220    /// Atomic number Z.
221    pub atomic_number: u16,
222    /// Element symbol this row belongs to.
223    pub element: String,
224    /// IUPAC edge label.
225    pub edge: String,
226    /// Core-hole width in eV.
227    pub width: f64,
228}
229
230/// Ionization potential for one counting gas.
231#[derive(Debug, Serialize, Deserialize)]
232pub struct IonizationPotentialRecord {
233    /// Gas name.
234    pub gas: String,
235    /// Ionization potential in eV per ion pair.
236    pub potential: f64,
237}