#[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 SamariumIsotope {
Sm128,
Sm129,
Sm130,
Sm131,
Sm132,
Sm133,
Sm134,
Sm135,
Sm136,
Sm137,
Sm138,
Sm139,
Sm140,
Sm141,
Sm142,
Sm143,
Sm144,
Sm145,
Sm146,
Sm147,
Sm148,
Sm149,
Sm150,
Sm151,
Sm152,
Sm153,
Sm154,
Sm155,
Sm156,
Sm157,
Sm158,
Sm159,
Sm160,
Sm161,
Sm162,
Sm163,
Sm164,
Sm165,
Sm166,
Sm167,
Sm168,
}
impl super::RelativeAtomicMass for SamariumIsotope {
#[inline]
fn relative_atomic_mass(&self) -> f64 {
match self {
Self::Sm128 => 127.95842f64,
Self::Sm129 => 128.95476f64,
Self::Sm130 => 129.949f64,
Self::Sm131 => 130.94618f64,
Self::Sm132 => 131.94087f64,
Self::Sm133 => 132.93856f64,
Self::Sm134 => 133.93411f64,
Self::Sm135 => 134.93252f64,
Self::Sm136 => 135.928276f64,
Self::Sm137 => 136.926971f64,
Self::Sm138 => 137.923244f64,
Self::Sm139 => 138.922297f64,
Self::Sm140 => 139.918995f64,
Self::Sm141 => 140.9184816f64,
Self::Sm142 => 141.9152044f64,
Self::Sm143 => 142.9146353f64,
Self::Sm144 => 143.9120065f64,
Self::Sm145 => 144.9134173f64,
Self::Sm146 => 145.913047f64,
Self::Sm147 => 146.9149044f64,
Self::Sm148 => 147.9148292f64,
Self::Sm149 => 148.9171921f64,
Self::Sm150 => 149.9172829f64,
Self::Sm151 => 150.9199398f64,
Self::Sm152 => 151.9197397f64,
Self::Sm153 => 152.9221047f64,
Self::Sm154 => 153.9222169f64,
Self::Sm155 => 154.9246477f64,
Self::Sm156 => 155.925536f64,
Self::Sm157 => 156.9284187f64,
Self::Sm158 => 157.929951f64,
Self::Sm159 => 158.9332172f64,
Self::Sm160 => 159.9353353f64,
Self::Sm161 => 160.9391602f64,
Self::Sm162 => 161.94146f64,
Self::Sm163 => 162.94555f64,
Self::Sm164 => 163.94836f64,
Self::Sm165 => 164.95297f64,
Self::Sm166 => 165.956575f64,
Self::Sm167 => 166.962072f64,
Self::Sm168 => 167.966033f64,
}
}
}
impl super::ElementVariant for SamariumIsotope {
#[inline]
fn element(&self) -> crate::Element {
crate::Element::Sm
}
}
impl super::MassNumber for SamariumIsotope {
#[inline]
fn mass_number(&self) -> u16 {
match self {
Self::Sm128 => 128u16,
Self::Sm129 => 129u16,
Self::Sm130 => 130u16,
Self::Sm131 => 131u16,
Self::Sm132 => 132u16,
Self::Sm133 => 133u16,
Self::Sm134 => 134u16,
Self::Sm135 => 135u16,
Self::Sm136 => 136u16,
Self::Sm137 => 137u16,
Self::Sm138 => 138u16,
Self::Sm139 => 139u16,
Self::Sm140 => 140u16,
Self::Sm141 => 141u16,
Self::Sm142 => 142u16,
Self::Sm143 => 143u16,
Self::Sm144 => 144u16,
Self::Sm145 => 145u16,
Self::Sm146 => 146u16,
Self::Sm147 => 147u16,
Self::Sm148 => 148u16,
Self::Sm149 => 149u16,
Self::Sm150 => 150u16,
Self::Sm151 => 151u16,
Self::Sm152 => 152u16,
Self::Sm153 => 153u16,
Self::Sm154 => 154u16,
Self::Sm155 => 155u16,
Self::Sm156 => 156u16,
Self::Sm157 => 157u16,
Self::Sm158 => 158u16,
Self::Sm159 => 159u16,
Self::Sm160 => 160u16,
Self::Sm161 => 161u16,
Self::Sm162 => 162u16,
Self::Sm163 => 163u16,
Self::Sm164 => 164u16,
Self::Sm165 => 165u16,
Self::Sm166 => 166u16,
Self::Sm167 => 167u16,
Self::Sm168 => 168u16,
}
}
}
impl super::IsotopicComposition for SamariumIsotope {
#[inline]
fn isotopic_composition(&self) -> Option<f64> {
match self {
Self::Sm144 => Some(0.0307f64),
Self::Sm147 => Some(0.1499f64),
Self::Sm148 => Some(0.1124f64),
Self::Sm149 => Some(0.1382f64),
Self::Sm150 => Some(0.0738f64),
Self::Sm152 => Some(0.2675f64),
Self::Sm154 => Some(0.2275f64),
_ => None,
}
}
}
impl super::MostAbundantIsotope for SamariumIsotope {
fn most_abundant_isotope() -> Self {
Self::Sm152
}
}
impl From<SamariumIsotope> for crate::Isotope {
fn from(isotope: SamariumIsotope) -> Self {
crate::Isotope::Sm(isotope)
}
}
impl From<SamariumIsotope> for crate::Element {
fn from(_isotope: SamariumIsotope) -> Self {
crate::Element::Sm
}
}
impl TryFrom<u64> for SamariumIsotope {
type Error = crate::errors::Error;
fn try_from(value: u64) -> Result<Self, Self::Error> {
match value {
128u64 => Ok(Self::Sm128),
129u64 => Ok(Self::Sm129),
130u64 => Ok(Self::Sm130),
131u64 => Ok(Self::Sm131),
132u64 => Ok(Self::Sm132),
133u64 => Ok(Self::Sm133),
134u64 => Ok(Self::Sm134),
135u64 => Ok(Self::Sm135),
136u64 => Ok(Self::Sm136),
137u64 => Ok(Self::Sm137),
138u64 => Ok(Self::Sm138),
139u64 => Ok(Self::Sm139),
140u64 => Ok(Self::Sm140),
141u64 => Ok(Self::Sm141),
142u64 => Ok(Self::Sm142),
143u64 => Ok(Self::Sm143),
144u64 => Ok(Self::Sm144),
145u64 => Ok(Self::Sm145),
146u64 => Ok(Self::Sm146),
147u64 => Ok(Self::Sm147),
148u64 => Ok(Self::Sm148),
149u64 => Ok(Self::Sm149),
150u64 => Ok(Self::Sm150),
151u64 => Ok(Self::Sm151),
152u64 => Ok(Self::Sm152),
153u64 => Ok(Self::Sm153),
154u64 => Ok(Self::Sm154),
155u64 => Ok(Self::Sm155),
156u64 => Ok(Self::Sm156),
157u64 => Ok(Self::Sm157),
158u64 => Ok(Self::Sm158),
159u64 => Ok(Self::Sm159),
160u64 => Ok(Self::Sm160),
161u64 => Ok(Self::Sm161),
162u64 => Ok(Self::Sm162),
163u64 => Ok(Self::Sm163),
164u64 => Ok(Self::Sm164),
165u64 => Ok(Self::Sm165),
166u64 => Ok(Self::Sm166),
167u64 => Ok(Self::Sm167),
168u64 => Ok(Self::Sm168),
_ => Err(crate::errors::Error::Isotope(crate::Element::Sm, value)),
}
}
}
impl TryFrom<u8> for SamariumIsotope {
type Error = crate::errors::Error;
fn try_from(value: u8) -> Result<Self, Self::Error> {
Self::try_from(u64::from(value))
}
}
impl TryFrom<u16> for SamariumIsotope {
type Error = crate::errors::Error;
fn try_from(value: u16) -> Result<Self, Self::Error> {
Self::try_from(u64::from(value))
}
}
impl TryFrom<u32> for SamariumIsotope {
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 SamariumIsotope {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::Sm128 => write!(f, "Sm128"),
Self::Sm129 => write!(f, "Sm129"),
Self::Sm130 => write!(f, "Sm130"),
Self::Sm131 => write!(f, "Sm131"),
Self::Sm132 => write!(f, "Sm132"),
Self::Sm133 => write!(f, "Sm133"),
Self::Sm134 => write!(f, "Sm134"),
Self::Sm135 => write!(f, "Sm135"),
Self::Sm136 => write!(f, "Sm136"),
Self::Sm137 => write!(f, "Sm137"),
Self::Sm138 => write!(f, "Sm138"),
Self::Sm139 => write!(f, "Sm139"),
Self::Sm140 => write!(f, "Sm140"),
Self::Sm141 => write!(f, "Sm141"),
Self::Sm142 => write!(f, "Sm142"),
Self::Sm143 => write!(f, "Sm143"),
Self::Sm144 => write!(f, "Sm144"),
Self::Sm145 => write!(f, "Sm145"),
Self::Sm146 => write!(f, "Sm146"),
Self::Sm147 => write!(f, "Sm147"),
Self::Sm148 => write!(f, "Sm148"),
Self::Sm149 => write!(f, "Sm149"),
Self::Sm150 => write!(f, "Sm150"),
Self::Sm151 => write!(f, "Sm151"),
Self::Sm152 => write!(f, "Sm152"),
Self::Sm153 => write!(f, "Sm153"),
Self::Sm154 => write!(f, "Sm154"),
Self::Sm155 => write!(f, "Sm155"),
Self::Sm156 => write!(f, "Sm156"),
Self::Sm157 => write!(f, "Sm157"),
Self::Sm158 => write!(f, "Sm158"),
Self::Sm159 => write!(f, "Sm159"),
Self::Sm160 => write!(f, "Sm160"),
Self::Sm161 => write!(f, "Sm161"),
Self::Sm162 => write!(f, "Sm162"),
Self::Sm163 => write!(f, "Sm163"),
Self::Sm164 => write!(f, "Sm164"),
Self::Sm165 => write!(f, "Sm165"),
Self::Sm166 => write!(f, "Sm166"),
Self::Sm167 => write!(f, "Sm167"),
Self::Sm168 => write!(f, "Sm168"),
}
}
}
#[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 SamariumIsotope::iter() {
let mass = isotope.relative_atomic_mass();
assert!(mass > 0.0, "Mass should be positive for {isotope:?}");
}
}
#[test]
fn test_element() {
for isotope in SamariumIsotope::iter() {
let element = isotope.element();
assert_eq!(element, crate::Element::Sm, "Element should be correct for {isotope:?}");
}
}
#[test]
fn test_mass_number() {
for isotope in SamariumIsotope::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 SamariumIsotope::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 = SamariumIsotope::most_abundant_isotope();
let _ = most_abundant.relative_atomic_mass();
}
#[test]
fn test_from_isotope() {
for isotope in SamariumIsotope::iter() {
let iso: crate::Isotope = isotope.into();
match iso {
crate::Isotope::Sm(i) => assert_eq!(i, isotope),
_ => panic!("Wrong isotope type"),
}
}
}
#[test]
fn test_from_element() {
for isotope in SamariumIsotope::iter() {
let elem: crate::Element = isotope.into();
assert_eq!(elem, crate::Element::Sm);
}
}
#[test]
fn test_try_from_mass_number() {
for isotope in SamariumIsotope::iter() {
let mass = isotope.mass_number();
let iso = SamariumIsotope::try_from(mass).unwrap();
assert_eq!(iso, isotope);
let iso_u32 = SamariumIsotope::try_from(u32::from(mass)).unwrap();
assert_eq!(iso_u32, isotope);
if let Ok(mass_u8) = u8::try_from(mass) {
let iso_u8 = SamariumIsotope::try_from(mass_u8).unwrap();
assert_eq!(iso_u8, isotope);
}
}
assert!(SamariumIsotope::try_from(0_u16).is_err());
assert!(SamariumIsotope::try_from(1000_u16).is_err());
assert!(SamariumIsotope::try_from(0_u32).is_err());
assert!(SamariumIsotope::try_from(1000_u32).is_err());
assert!(SamariumIsotope::try_from(0_u8).is_err());
}
#[test]
fn test_display() {
for isotope in SamariumIsotope::iter() {
let s = alloc::format!("{isotope}");
assert!(!s.is_empty(), "Display should not be empty for {isotope:?}");
}
}
}