9 releases
Uses new Rust 2024
| new 0.2.1 | Apr 5, 2026 |
|---|---|
| 0.2.0 | Mar 21, 2026 |
| 0.1.6 | Mar 18, 2026 |
| 0.1.4 | Jan 27, 2026 |
| 0.1.0 | Nov 5, 2025 |
#41 in Science
199 downloads per month
Used in molecular-formulas
2MB
48K
SLoC
Elements
A comprehensive Rust crate providing type-safe enumerations and rich metadata for all chemical elements of the periodic table and their isotopes. The crate includes all 118 elements from Hydrogen to Oganesson with detailed information for each isotope including mass numbers, relative atomic masses, isotopic composition, and identification of the most abundant isotope. Chemical properties are fully supported: standard atomic weights, oxidation states with validation, valence electrons, bond numbers, electron configurations with atomic orbitals, principal quantum numbers, and source-specific atomic, covalent, and van der Waals radii.
Would you like to see more information or features? Please open an issue or a pull request!
The crate is no_std, and optionally supports serde for serialization/deserialization and arbitrary for fuzzing.
Usage
Add this to your Cargo.toml:
[dependencies]
elements_rs = "0.1"
Basic Example
use elements_rs::{
AtomicRadius, BondsNumber, CovalentRadius, Element, ValenceElectrons, VanDerWaalsRadius,
};
// Get an element
let carbon = Element::C;
// Access properties
println!("Name: {}", carbon.name());
println!("Atomic weight: {}", carbon.standard_atomic_weight());
println!("Valence electrons: {}", carbon.valence_electrons());
// Check oxidation states
assert!(carbon.is_valid_oxidation_state(4));
assert!(carbon.is_valid_oxidation_state(-4));
// Get bond information
let (min_bonds, max_bonds) = carbon.number_of_bonds();
assert_eq!((min_bonds, max_bonds), (4, 4));
// Source-specific radii are returned in angstrom.
assert_eq!(carbon.slater_atomic_radius(), Some(0.70));
assert_eq!(carbon.cordero_covalent_radius(), Some(0.76));
assert_eq!(carbon.bondi_van_der_waals_radius(), Some(1.70));
Working with Isotopes
use elements_rs::{
Element,
isotopes::{CarbonIsotope, Isotope, MassNumber, RelativeAtomicMass},
};
// Get a specific isotope
let carbon_12 = CarbonIsotope::C12;
println!("Mass number: {}", carbon_12.mass_number());
println!("Relative atomic mass: {}", carbon_12.relative_atomic_mass());
// Get the element-level monoisotopic mass convenience value
let carbon = Element::C;
assert_eq!(carbon.monoisotopic_mass(), 12.0);
// Work with the generic Isotope enum
let isotope = Isotope::C(carbon_12);
Parsing from Strings
use elements_rs::Element;
use std::str::FromStr;
// Parse element symbols
let oxygen = Element::from_str("O").unwrap();
let nitrogen = Element::from_str("N").unwrap();
Feature Flags
serde(default): EnablesSerializeandDeserializeimplementations forElementandIsotopetypesarbitrary: EnablesArbitraryimplementations forElementandIsotopetypes, useful for fuzzing
Contributing
Install prek and set up the pre-commit hooks:
cargo install prek
prek install
License
This project is licensed under the same terms as the parent EMI monorepo.
Dependencies
~0.3–1MB
~21K SLoC