#[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))]
#[cfg_attr(feature = "mem_size", derive(mem_dbg::MemSize))]
#[cfg_attr(feature = "mem_dbg", derive(mem_dbg::MemDbg))]
#[cfg_attr(feature = "mem_size", mem_size(flat))]
pub enum LanthanumIsotope {
La116,
La117,
La118,
La119,
La120,
La121,
La122,
La123,
La124,
La125,
La126,
La127,
La128,
La129,
La130,
La131,
La132,
La133,
La134,
La135,
La136,
La137,
La138,
La139,
La140,
La141,
La142,
La143,
La144,
La145,
La146,
La147,
La148,
La149,
La150,
La151,
La152,
La153,
La154,
La155,
La156,
La157,
}
impl super::RelativeAtomicMass for LanthanumIsotope {
#[inline]
fn relative_atomic_mass(&self) -> f64 {
match self {
Self::La116 => 115.9563f64,
Self::La117 => 116.94999f64,
Self::La118 => 117.94673f64,
Self::La119 => 118.94099f64,
Self::La120 => 119.93807f64,
Self::La121 => 120.93315f64,
Self::La122 => 121.93071f64,
Self::La123 => 122.9263f64,
Self::La124 => 123.924574f64,
Self::La125 => 124.920816f64,
Self::La126 => 125.919513f64,
Self::La127 => 126.916375f64,
Self::La128 => 127.915592f64,
Self::La129 => 128.912694f64,
Self::La130 => 129.912369f64,
Self::La131 => 130.91007f64,
Self::La132 => 131.910119f64,
Self::La133 => 132.908218f64,
Self::La134 => 133.908514f64,
Self::La135 => 134.906984f64,
Self::La136 => 135.907635f64,
Self::La137 => 136.9064504f64,
Self::La138 => 137.9071149f64,
Self::La139 => 138.9063563f64,
Self::La140 => 139.9094806f64,
Self::La141 => 140.910966f64,
Self::La142 => 141.9140909f64,
Self::La143 => 142.9160795f64,
Self::La144 => 143.919646f64,
Self::La145 => 144.921808f64,
Self::La146 => 145.925875f64,
Self::La147 => 146.928418f64,
Self::La148 => 147.932679f64,
Self::La149 => 148.93535f64,
Self::La150 => 149.93947f64,
Self::La151 => 150.94232f64,
Self::La152 => 151.94682f64,
Self::La153 => 152.95036f64,
Self::La154 => 153.95517f64,
Self::La155 => 154.95901f64,
Self::La156 => 155.964519f64,
Self::La157 => 156.968792f64,
}
}
}
impl super::ElementVariant for LanthanumIsotope {
#[inline]
fn element(&self) -> crate::Element {
crate::Element::La
}
}
impl super::MassNumber for LanthanumIsotope {
#[inline]
fn mass_number(&self) -> u16 {
match self {
Self::La116 => 116u16,
Self::La117 => 117u16,
Self::La118 => 118u16,
Self::La119 => 119u16,
Self::La120 => 120u16,
Self::La121 => 121u16,
Self::La122 => 122u16,
Self::La123 => 123u16,
Self::La124 => 124u16,
Self::La125 => 125u16,
Self::La126 => 126u16,
Self::La127 => 127u16,
Self::La128 => 128u16,
Self::La129 => 129u16,
Self::La130 => 130u16,
Self::La131 => 131u16,
Self::La132 => 132u16,
Self::La133 => 133u16,
Self::La134 => 134u16,
Self::La135 => 135u16,
Self::La136 => 136u16,
Self::La137 => 137u16,
Self::La138 => 138u16,
Self::La139 => 139u16,
Self::La140 => 140u16,
Self::La141 => 141u16,
Self::La142 => 142u16,
Self::La143 => 143u16,
Self::La144 => 144u16,
Self::La145 => 145u16,
Self::La146 => 146u16,
Self::La147 => 147u16,
Self::La148 => 148u16,
Self::La149 => 149u16,
Self::La150 => 150u16,
Self::La151 => 151u16,
Self::La152 => 152u16,
Self::La153 => 153u16,
Self::La154 => 154u16,
Self::La155 => 155u16,
Self::La156 => 156u16,
Self::La157 => 157u16,
}
}
}
impl super::IsotopicComposition for LanthanumIsotope {
#[inline]
fn isotopic_composition(&self) -> Option<f64> {
match self {
Self::La138 => Some(0.0008881f64),
Self::La139 => Some(0.9991119f64),
_ => None,
}
}
}
impl super::MostAbundantIsotope for LanthanumIsotope {
fn most_abundant_isotope() -> Self {
Self::La139
}
}
impl From<LanthanumIsotope> for crate::Isotope {
fn from(isotope: LanthanumIsotope) -> Self {
crate::Isotope::La(isotope)
}
}
impl From<LanthanumIsotope> for crate::Element {
fn from(_isotope: LanthanumIsotope) -> Self {
crate::Element::La
}
}
impl TryFrom<u64> for LanthanumIsotope {
type Error = crate::errors::Error;
fn try_from(value: u64) -> Result<Self, Self::Error> {
match value {
116u64 => Ok(Self::La116),
117u64 => Ok(Self::La117),
118u64 => Ok(Self::La118),
119u64 => Ok(Self::La119),
120u64 => Ok(Self::La120),
121u64 => Ok(Self::La121),
122u64 => Ok(Self::La122),
123u64 => Ok(Self::La123),
124u64 => Ok(Self::La124),
125u64 => Ok(Self::La125),
126u64 => Ok(Self::La126),
127u64 => Ok(Self::La127),
128u64 => Ok(Self::La128),
129u64 => Ok(Self::La129),
130u64 => Ok(Self::La130),
131u64 => Ok(Self::La131),
132u64 => Ok(Self::La132),
133u64 => Ok(Self::La133),
134u64 => Ok(Self::La134),
135u64 => Ok(Self::La135),
136u64 => Ok(Self::La136),
137u64 => Ok(Self::La137),
138u64 => Ok(Self::La138),
139u64 => Ok(Self::La139),
140u64 => Ok(Self::La140),
141u64 => Ok(Self::La141),
142u64 => Ok(Self::La142),
143u64 => Ok(Self::La143),
144u64 => Ok(Self::La144),
145u64 => Ok(Self::La145),
146u64 => Ok(Self::La146),
147u64 => Ok(Self::La147),
148u64 => Ok(Self::La148),
149u64 => Ok(Self::La149),
150u64 => Ok(Self::La150),
151u64 => Ok(Self::La151),
152u64 => Ok(Self::La152),
153u64 => Ok(Self::La153),
154u64 => Ok(Self::La154),
155u64 => Ok(Self::La155),
156u64 => Ok(Self::La156),
157u64 => Ok(Self::La157),
_ => Err(crate::errors::Error::Isotope(crate::Element::La, value)),
}
}
}
impl TryFrom<u8> for LanthanumIsotope {
type Error = crate::errors::Error;
fn try_from(value: u8) -> Result<Self, Self::Error> {
Self::try_from(u64::from(value))
}
}
impl TryFrom<u16> for LanthanumIsotope {
type Error = crate::errors::Error;
fn try_from(value: u16) -> Result<Self, Self::Error> {
Self::try_from(u64::from(value))
}
}
impl TryFrom<u32> for LanthanumIsotope {
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 LanthanumIsotope {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::La116 => write!(f, "La116"),
Self::La117 => write!(f, "La117"),
Self::La118 => write!(f, "La118"),
Self::La119 => write!(f, "La119"),
Self::La120 => write!(f, "La120"),
Self::La121 => write!(f, "La121"),
Self::La122 => write!(f, "La122"),
Self::La123 => write!(f, "La123"),
Self::La124 => write!(f, "La124"),
Self::La125 => write!(f, "La125"),
Self::La126 => write!(f, "La126"),
Self::La127 => write!(f, "La127"),
Self::La128 => write!(f, "La128"),
Self::La129 => write!(f, "La129"),
Self::La130 => write!(f, "La130"),
Self::La131 => write!(f, "La131"),
Self::La132 => write!(f, "La132"),
Self::La133 => write!(f, "La133"),
Self::La134 => write!(f, "La134"),
Self::La135 => write!(f, "La135"),
Self::La136 => write!(f, "La136"),
Self::La137 => write!(f, "La137"),
Self::La138 => write!(f, "La138"),
Self::La139 => write!(f, "La139"),
Self::La140 => write!(f, "La140"),
Self::La141 => write!(f, "La141"),
Self::La142 => write!(f, "La142"),
Self::La143 => write!(f, "La143"),
Self::La144 => write!(f, "La144"),
Self::La145 => write!(f, "La145"),
Self::La146 => write!(f, "La146"),
Self::La147 => write!(f, "La147"),
Self::La148 => write!(f, "La148"),
Self::La149 => write!(f, "La149"),
Self::La150 => write!(f, "La150"),
Self::La151 => write!(f, "La151"),
Self::La152 => write!(f, "La152"),
Self::La153 => write!(f, "La153"),
Self::La154 => write!(f, "La154"),
Self::La155 => write!(f, "La155"),
Self::La156 => write!(f, "La156"),
Self::La157 => write!(f, "La157"),
}
}
}
#[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 LanthanumIsotope::iter() {
let mass = isotope.relative_atomic_mass();
assert!(mass > 0.0, "Mass should be positive for {isotope:?}");
}
}
#[test]
fn test_element() {
for isotope in LanthanumIsotope::iter() {
let element = isotope.element();
assert_eq!(element, crate::Element::La, "Element should be correct for {isotope:?}");
}
}
#[test]
fn test_mass_number() {
for isotope in LanthanumIsotope::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 LanthanumIsotope::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 = LanthanumIsotope::most_abundant_isotope();
let _ = most_abundant.relative_atomic_mass();
}
#[test]
fn test_from_isotope() {
for isotope in LanthanumIsotope::iter() {
let iso: crate::Isotope = isotope.into();
match iso {
crate::Isotope::La(i) => assert_eq!(i, isotope),
_ => panic!("Wrong isotope type"),
}
}
}
#[test]
fn test_from_element() {
for isotope in LanthanumIsotope::iter() {
let elem: crate::Element = isotope.into();
assert_eq!(elem, crate::Element::La);
}
}
#[test]
fn test_try_from_mass_number() {
for isotope in LanthanumIsotope::iter() {
let mass = isotope.mass_number();
let iso = LanthanumIsotope::try_from(mass).unwrap();
assert_eq!(iso, isotope);
let iso_u32 = LanthanumIsotope::try_from(u32::from(mass)).unwrap();
assert_eq!(iso_u32, isotope);
if let Ok(mass_u8) = u8::try_from(mass) {
let iso_u8 = LanthanumIsotope::try_from(mass_u8).unwrap();
assert_eq!(iso_u8, isotope);
}
}
assert!(LanthanumIsotope::try_from(0_u16).is_err());
assert!(LanthanumIsotope::try_from(1000_u16).is_err());
assert!(LanthanumIsotope::try_from(0_u32).is_err());
assert!(LanthanumIsotope::try_from(1000_u32).is_err());
assert!(LanthanumIsotope::try_from(0_u8).is_err());
}
#[test]
fn test_display() {
for isotope in LanthanumIsotope::iter() {
let s = alloc::format!("{isotope}");
assert!(!s.is_empty(), "Display should not be empty for {isotope:?}");
}
}
}