#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, strum :: EnumIter)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
pub enum CeriumIsotope {
Ce119,
Ce120,
Ce121,
Ce122,
Ce123,
Ce124,
Ce125,
Ce126,
Ce127,
Ce128,
Ce129,
Ce130,
Ce131,
Ce132,
Ce133,
Ce134,
Ce135,
Ce136,
Ce137,
Ce138,
Ce139,
Ce140,
Ce141,
Ce142,
Ce143,
Ce144,
Ce145,
Ce146,
Ce147,
Ce148,
Ce149,
Ce150,
Ce151,
Ce152,
Ce153,
Ce154,
Ce155,
Ce156,
Ce157,
Ce158,
Ce159,
}
impl super::RelativeAtomicMass for CeriumIsotope {
#[inline]
fn relative_atomic_mass(&self) -> f64 {
match self {
Self::Ce119 => 118.95271f64,
Self::Ce120 => 119.94654f64,
Self::Ce121 => 120.94335f64,
Self::Ce122 => 121.93787f64,
Self::Ce123 => 122.93528f64,
Self::Ce124 => 123.93031f64,
Self::Ce125 => 124.92844f64,
Self::Ce126 => 125.923971f64,
Self::Ce127 => 126.922727f64,
Self::Ce128 => 127.918911f64,
Self::Ce129 => 128.918102f64,
Self::Ce130 => 129.914736f64,
Self::Ce131 => 130.914429f64,
Self::Ce132 => 131.911464f64,
Self::Ce133 => 132.91152f64,
Self::Ce134 => 133.908928f64,
Self::Ce135 => 134.909161f64,
Self::Ce136 => 135.90712921f64,
Self::Ce137 => 136.90776236f64,
Self::Ce138 => 137.905991f64,
Self::Ce139 => 138.9066551f64,
Self::Ce140 => 139.9054431f64,
Self::Ce141 => 140.9082807f64,
Self::Ce142 => 141.9092504f64,
Self::Ce143 => 142.9123921f64,
Self::Ce144 => 143.9136529f64,
Self::Ce145 => 144.917265f64,
Self::Ce146 => 145.918802f64,
Self::Ce147 => 146.9226899f64,
Self::Ce148 => 147.924424f64,
Self::Ce149 => 148.928427f64,
Self::Ce150 => 149.930384f64,
Self::Ce151 => 150.934272f64,
Self::Ce152 => 151.9366f64,
Self::Ce153 => 152.94093f64,
Self::Ce154 => 153.9438f64,
Self::Ce155 => 154.94855f64,
Self::Ce156 => 155.95183f64,
Self::Ce157 => 156.95705f64,
Self::Ce158 => 157.960773f64,
Self::Ce159 => 158.966355f64,
}
}
}
impl super::ElementVariant for CeriumIsotope {
#[inline]
fn element(&self) -> crate::Element {
crate::Element::Ce
}
}
impl super::MassNumber for CeriumIsotope {
#[inline]
fn mass_number(&self) -> u16 {
match self {
Self::Ce119 => 119u16,
Self::Ce120 => 120u16,
Self::Ce121 => 121u16,
Self::Ce122 => 122u16,
Self::Ce123 => 123u16,
Self::Ce124 => 124u16,
Self::Ce125 => 125u16,
Self::Ce126 => 126u16,
Self::Ce127 => 127u16,
Self::Ce128 => 128u16,
Self::Ce129 => 129u16,
Self::Ce130 => 130u16,
Self::Ce131 => 131u16,
Self::Ce132 => 132u16,
Self::Ce133 => 133u16,
Self::Ce134 => 134u16,
Self::Ce135 => 135u16,
Self::Ce136 => 136u16,
Self::Ce137 => 137u16,
Self::Ce138 => 138u16,
Self::Ce139 => 139u16,
Self::Ce140 => 140u16,
Self::Ce141 => 141u16,
Self::Ce142 => 142u16,
Self::Ce143 => 143u16,
Self::Ce144 => 144u16,
Self::Ce145 => 145u16,
Self::Ce146 => 146u16,
Self::Ce147 => 147u16,
Self::Ce148 => 148u16,
Self::Ce149 => 149u16,
Self::Ce150 => 150u16,
Self::Ce151 => 151u16,
Self::Ce152 => 152u16,
Self::Ce153 => 153u16,
Self::Ce154 => 154u16,
Self::Ce155 => 155u16,
Self::Ce156 => 156u16,
Self::Ce157 => 157u16,
Self::Ce158 => 158u16,
Self::Ce159 => 159u16,
}
}
}
impl super::IsotopicComposition for CeriumIsotope {
#[inline]
fn isotopic_composition(&self) -> Option<f64> {
match self {
Self::Ce136 => Some(0.00185f64),
Self::Ce138 => Some(0.00251f64),
Self::Ce140 => Some(0.8845f64),
Self::Ce142 => Some(0.11114f64),
_ => None,
}
}
}
impl super::MostAbundantIsotope for CeriumIsotope {
fn most_abundant_isotope() -> Self {
Self::Ce140
}
}
impl From<CeriumIsotope> for crate::Isotope {
fn from(isotope: CeriumIsotope) -> Self {
crate::Isotope::Ce(isotope)
}
}
impl From<CeriumIsotope> for crate::Element {
fn from(_isotope: CeriumIsotope) -> Self {
crate::Element::Ce
}
}
impl TryFrom<u64> for CeriumIsotope {
type Error = crate::errors::Error;
fn try_from(value: u64) -> Result<Self, Self::Error> {
match value {
119u64 => Ok(Self::Ce119),
120u64 => Ok(Self::Ce120),
121u64 => Ok(Self::Ce121),
122u64 => Ok(Self::Ce122),
123u64 => Ok(Self::Ce123),
124u64 => Ok(Self::Ce124),
125u64 => Ok(Self::Ce125),
126u64 => Ok(Self::Ce126),
127u64 => Ok(Self::Ce127),
128u64 => Ok(Self::Ce128),
129u64 => Ok(Self::Ce129),
130u64 => Ok(Self::Ce130),
131u64 => Ok(Self::Ce131),
132u64 => Ok(Self::Ce132),
133u64 => Ok(Self::Ce133),
134u64 => Ok(Self::Ce134),
135u64 => Ok(Self::Ce135),
136u64 => Ok(Self::Ce136),
137u64 => Ok(Self::Ce137),
138u64 => Ok(Self::Ce138),
139u64 => Ok(Self::Ce139),
140u64 => Ok(Self::Ce140),
141u64 => Ok(Self::Ce141),
142u64 => Ok(Self::Ce142),
143u64 => Ok(Self::Ce143),
144u64 => Ok(Self::Ce144),
145u64 => Ok(Self::Ce145),
146u64 => Ok(Self::Ce146),
147u64 => Ok(Self::Ce147),
148u64 => Ok(Self::Ce148),
149u64 => Ok(Self::Ce149),
150u64 => Ok(Self::Ce150),
151u64 => Ok(Self::Ce151),
152u64 => Ok(Self::Ce152),
153u64 => Ok(Self::Ce153),
154u64 => Ok(Self::Ce154),
155u64 => Ok(Self::Ce155),
156u64 => Ok(Self::Ce156),
157u64 => Ok(Self::Ce157),
158u64 => Ok(Self::Ce158),
159u64 => Ok(Self::Ce159),
_ => Err(crate::errors::Error::Isotope(crate::Element::Ce, value)),
}
}
}
impl TryFrom<u8> for CeriumIsotope {
type Error = crate::errors::Error;
fn try_from(value: u8) -> Result<Self, Self::Error> {
Self::try_from(u64::from(value))
}
}
impl TryFrom<u16> for CeriumIsotope {
type Error = crate::errors::Error;
fn try_from(value: u16) -> Result<Self, Self::Error> {
Self::try_from(u64::from(value))
}
}
impl TryFrom<u32> for CeriumIsotope {
type Error = crate::errors::Error;
fn try_from(value: u32) -> Result<Self, Self::Error> {
Self::try_from(u64::from(value))
}
}
impl core::fmt::Display for CeriumIsotope {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::Ce119 => write!(f, "Ce119"),
Self::Ce120 => write!(f, "Ce120"),
Self::Ce121 => write!(f, "Ce121"),
Self::Ce122 => write!(f, "Ce122"),
Self::Ce123 => write!(f, "Ce123"),
Self::Ce124 => write!(f, "Ce124"),
Self::Ce125 => write!(f, "Ce125"),
Self::Ce126 => write!(f, "Ce126"),
Self::Ce127 => write!(f, "Ce127"),
Self::Ce128 => write!(f, "Ce128"),
Self::Ce129 => write!(f, "Ce129"),
Self::Ce130 => write!(f, "Ce130"),
Self::Ce131 => write!(f, "Ce131"),
Self::Ce132 => write!(f, "Ce132"),
Self::Ce133 => write!(f, "Ce133"),
Self::Ce134 => write!(f, "Ce134"),
Self::Ce135 => write!(f, "Ce135"),
Self::Ce136 => write!(f, "Ce136"),
Self::Ce137 => write!(f, "Ce137"),
Self::Ce138 => write!(f, "Ce138"),
Self::Ce139 => write!(f, "Ce139"),
Self::Ce140 => write!(f, "Ce140"),
Self::Ce141 => write!(f, "Ce141"),
Self::Ce142 => write!(f, "Ce142"),
Self::Ce143 => write!(f, "Ce143"),
Self::Ce144 => write!(f, "Ce144"),
Self::Ce145 => write!(f, "Ce145"),
Self::Ce146 => write!(f, "Ce146"),
Self::Ce147 => write!(f, "Ce147"),
Self::Ce148 => write!(f, "Ce148"),
Self::Ce149 => write!(f, "Ce149"),
Self::Ce150 => write!(f, "Ce150"),
Self::Ce151 => write!(f, "Ce151"),
Self::Ce152 => write!(f, "Ce152"),
Self::Ce153 => write!(f, "Ce153"),
Self::Ce154 => write!(f, "Ce154"),
Self::Ce155 => write!(f, "Ce155"),
Self::Ce156 => write!(f, "Ce156"),
Self::Ce157 => write!(f, "Ce157"),
Self::Ce158 => write!(f, "Ce158"),
Self::Ce159 => write!(f, "Ce159"),
}
}
}
#[cfg(test)]
mod tests {
use strum::IntoEnumIterator;
use super::*;
use crate::isotopes::{
ElementVariant, IsotopicComposition, MassNumber, MostAbundantIsotope, RelativeAtomicMass,
};
#[test]
fn test_relative_atomic_mass() {
for isotope in CeriumIsotope::iter() {
let mass = isotope.relative_atomic_mass();
assert!(mass > 0.0, "Mass should be positive for {isotope:?}");
}
}
#[test]
fn test_element() {
for isotope in CeriumIsotope::iter() {
let element = isotope.element();
assert_eq!(element, crate::Element::Ce, "Element should be correct for {isotope:?}");
}
}
#[test]
fn test_mass_number() {
for isotope in CeriumIsotope::iter() {
let mass_number = isotope.mass_number();
assert!(
mass_number > 0 && mass_number < 300,
"Mass number should be reasonable for {isotope:?}"
);
}
}
#[test]
fn test_isotopic_composition() {
for isotope in CeriumIsotope::iter() {
let comp = isotope.isotopic_composition();
if let Some(c) = comp {
assert!(
(0.0..=1.0).contains(&c),
"Composition should be between 0 and 1 for {isotope:?}"
);
}
}
}
#[test]
fn test_most_abundant() {
let most_abundant = CeriumIsotope::most_abundant_isotope();
let _ = most_abundant.relative_atomic_mass();
}
#[test]
fn test_from_isotope() {
for isotope in CeriumIsotope::iter() {
let iso: crate::Isotope = isotope.into();
match iso {
crate::Isotope::Ce(i) => assert_eq!(i, isotope),
_ => panic!("Wrong isotope type"),
}
}
}
#[test]
fn test_from_element() {
for isotope in CeriumIsotope::iter() {
let elem: crate::Element = isotope.into();
assert_eq!(elem, crate::Element::Ce);
}
}
#[test]
fn test_try_from_mass_number() {
for isotope in CeriumIsotope::iter() {
let mass = isotope.mass_number();
let iso = CeriumIsotope::try_from(mass).unwrap();
assert_eq!(iso, isotope);
let iso_u32 = CeriumIsotope::try_from(u32::from(mass)).unwrap();
assert_eq!(iso_u32, isotope);
if let Ok(mass_u8) = u8::try_from(mass) {
let iso_u8 = CeriumIsotope::try_from(mass_u8).unwrap();
assert_eq!(iso_u8, isotope);
}
}
assert!(CeriumIsotope::try_from(0_u16).is_err());
assert!(CeriumIsotope::try_from(1000_u16).is_err());
assert!(CeriumIsotope::try_from(0_u32).is_err());
assert!(CeriumIsotope::try_from(1000_u32).is_err());
assert!(CeriumIsotope::try_from(0_u8).is_err());
}
#[test]
fn test_display() {
for isotope in CeriumIsotope::iter() {
let s = alloc::format!("{isotope}");
assert!(!s.is_empty(), "Display should not be empty for {isotope:?}");
}
}
}