rexafs 0.2.12

Rust-powered X-ray absorption spectroscopy analysis and EXAFS fitting
Documentation
"""Generate src/xafs/structure/element_table.rs from pymatgen's element data.

Run:  uv run --project crates/rexafs/tests/pythonscript python crates/rexafs/scripts/generate_element_table.py
"""
from pathlib import Path
from pymatgen.core import Element
from pymatgen.analysis.molecule_structure_comparator import CovalentRadius
from pymatgen.vis.structure_vtk import EL_COLORS

OUT = Path(__file__).resolve().parents[1] / "src" / "xafs" / "structure" / "element_table.rs"
rows = []
for z in range(1, 104):
    el = Element.from_Z(z)
    cov = CovalentRadius.radius.get(el.symbol)
    if cov is None:
        cov = float(el.atomic_radius) if el.atomic_radius else 1.5
    atomic = el.atomic_radius
    if atomic is None:
        atomic = cov
    color = EL_COLORS["Jmol"].get(el.symbol, (200, 200, 200))
    mass = float(el.atomic_mass)
    rows.append(f'    Element {{ z: {z}, symbol: "{el.symbol}", name: "{el.long_name}", mass: {mass:.4f}, covalent_radius: {float(cov):.3f}, atomic_radius: {float(atomic):.3f}, cpk: [{color[0]}, {color[1]}, {color[2]}] }},')
text = "//! Generated by scripts/generate_element_table.py from pymatgen (masses, radii) and Jmol CPK colours.\n//! Do not edit by hand.\n\nuse super::element::Element;\n\npub(super) const ELEMENTS: [Element; 103] = [\n" + "\n".join(rows) + "\n];\n"
OUT.write_text(text)
print(OUT, len(rows))