#[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 PromethiumIsotope {
Pm126,
Pm127,
Pm128,
Pm129,
Pm130,
Pm131,
Pm132,
Pm133,
Pm134,
Pm135,
Pm136,
Pm137,
Pm138,
Pm139,
Pm140,
Pm141,
Pm142,
Pm143,
Pm144,
Pm145,
Pm146,
Pm147,
Pm148,
Pm149,
Pm150,
Pm151,
Pm152,
Pm153,
Pm154,
Pm155,
Pm156,
Pm157,
Pm158,
Pm159,
Pm160,
Pm161,
Pm162,
Pm163,
Pm164,
Pm165,
}
impl super::RelativeAtomicMass for PromethiumIsotope {
#[inline]
fn relative_atomic_mass(&self) -> f64 {
match self {
Self::Pm126 => 125.95792f64,
Self::Pm127 => 126.95192f64,
Self::Pm128 => 127.9487f64,
Self::Pm129 => 128.94323f64,
Self::Pm130 => 129.94053f64,
Self::Pm131 => 130.93567f64,
Self::Pm132 => 131.93384f64,
Self::Pm133 => 132.929782f64,
Self::Pm134 => 133.928353f64,
Self::Pm135 => 134.924823f64,
Self::Pm136 => 135.923585f64,
Self::Pm137 => 136.92048f64,
Self::Pm138 => 137.919548f64,
Self::Pm139 => 138.9168f64,
Self::Pm140 => 139.91604f64,
Self::Pm141 => 140.913555f64,
Self::Pm142 => 141.91289f64,
Self::Pm143 => 142.9109383f64,
Self::Pm144 => 143.9125964f64,
Self::Pm145 => 144.9127559f64,
Self::Pm146 => 145.9147024f64,
Self::Pm147 => 146.915145f64,
Self::Pm148 => 147.9174819f64,
Self::Pm149 => 148.9183423f64,
Self::Pm150 => 149.920991f64,
Self::Pm151 => 150.9212175f64,
Self::Pm152 => 151.923506f64,
Self::Pm153 => 152.9241567f64,
Self::Pm154 => 153.926472f64,
Self::Pm155 => 154.928137f64,
Self::Pm156 => 155.9311175f64,
Self::Pm157 => 156.9331214f64,
Self::Pm158 => 157.936565f64,
Self::Pm159 => 158.939287f64,
Self::Pm160 => 159.9431f64,
Self::Pm161 => 160.94607f64,
Self::Pm162 => 161.95022f64,
Self::Pm163 => 162.95357f64,
Self::Pm164 => 163.958819f64,
Self::Pm165 => 164.96278f64,
}
}
}
impl super::ElementVariant for PromethiumIsotope {
#[inline]
fn element(&self) -> crate::Element {
crate::Element::Pm
}
}
impl super::MassNumber for PromethiumIsotope {
#[inline]
fn mass_number(&self) -> u16 {
match self {
Self::Pm126 => 126u16,
Self::Pm127 => 127u16,
Self::Pm128 => 128u16,
Self::Pm129 => 129u16,
Self::Pm130 => 130u16,
Self::Pm131 => 131u16,
Self::Pm132 => 132u16,
Self::Pm133 => 133u16,
Self::Pm134 => 134u16,
Self::Pm135 => 135u16,
Self::Pm136 => 136u16,
Self::Pm137 => 137u16,
Self::Pm138 => 138u16,
Self::Pm139 => 139u16,
Self::Pm140 => 140u16,
Self::Pm141 => 141u16,
Self::Pm142 => 142u16,
Self::Pm143 => 143u16,
Self::Pm144 => 144u16,
Self::Pm145 => 145u16,
Self::Pm146 => 146u16,
Self::Pm147 => 147u16,
Self::Pm148 => 148u16,
Self::Pm149 => 149u16,
Self::Pm150 => 150u16,
Self::Pm151 => 151u16,
Self::Pm152 => 152u16,
Self::Pm153 => 153u16,
Self::Pm154 => 154u16,
Self::Pm155 => 155u16,
Self::Pm156 => 156u16,
Self::Pm157 => 157u16,
Self::Pm158 => 158u16,
Self::Pm159 => 159u16,
Self::Pm160 => 160u16,
Self::Pm161 => 161u16,
Self::Pm162 => 162u16,
Self::Pm163 => 163u16,
Self::Pm164 => 164u16,
Self::Pm165 => 165u16,
}
}
}
impl super::IsotopicComposition for PromethiumIsotope {
#[inline]
fn isotopic_composition(&self) -> Option<f64> {
None
}
}
impl super::MostAbundantIsotope for PromethiumIsotope {
fn most_abundant_isotope() -> Self {
Self::Pm165
}
}
impl From<PromethiumIsotope> for crate::Isotope {
fn from(isotope: PromethiumIsotope) -> Self {
crate::Isotope::Pm(isotope)
}
}
impl From<PromethiumIsotope> for crate::Element {
fn from(_isotope: PromethiumIsotope) -> Self {
crate::Element::Pm
}
}
impl TryFrom<u64> for PromethiumIsotope {
type Error = crate::errors::Error;
fn try_from(value: u64) -> Result<Self, Self::Error> {
match value {
126u64 => Ok(Self::Pm126),
127u64 => Ok(Self::Pm127),
128u64 => Ok(Self::Pm128),
129u64 => Ok(Self::Pm129),
130u64 => Ok(Self::Pm130),
131u64 => Ok(Self::Pm131),
132u64 => Ok(Self::Pm132),
133u64 => Ok(Self::Pm133),
134u64 => Ok(Self::Pm134),
135u64 => Ok(Self::Pm135),
136u64 => Ok(Self::Pm136),
137u64 => Ok(Self::Pm137),
138u64 => Ok(Self::Pm138),
139u64 => Ok(Self::Pm139),
140u64 => Ok(Self::Pm140),
141u64 => Ok(Self::Pm141),
142u64 => Ok(Self::Pm142),
143u64 => Ok(Self::Pm143),
144u64 => Ok(Self::Pm144),
145u64 => Ok(Self::Pm145),
146u64 => Ok(Self::Pm146),
147u64 => Ok(Self::Pm147),
148u64 => Ok(Self::Pm148),
149u64 => Ok(Self::Pm149),
150u64 => Ok(Self::Pm150),
151u64 => Ok(Self::Pm151),
152u64 => Ok(Self::Pm152),
153u64 => Ok(Self::Pm153),
154u64 => Ok(Self::Pm154),
155u64 => Ok(Self::Pm155),
156u64 => Ok(Self::Pm156),
157u64 => Ok(Self::Pm157),
158u64 => Ok(Self::Pm158),
159u64 => Ok(Self::Pm159),
160u64 => Ok(Self::Pm160),
161u64 => Ok(Self::Pm161),
162u64 => Ok(Self::Pm162),
163u64 => Ok(Self::Pm163),
164u64 => Ok(Self::Pm164),
165u64 => Ok(Self::Pm165),
_ => Err(crate::errors::Error::Isotope(crate::Element::Pm, value)),
}
}
}
impl TryFrom<u8> for PromethiumIsotope {
type Error = crate::errors::Error;
fn try_from(value: u8) -> Result<Self, Self::Error> {
Self::try_from(u64::from(value))
}
}
impl TryFrom<u16> for PromethiumIsotope {
type Error = crate::errors::Error;
fn try_from(value: u16) -> Result<Self, Self::Error> {
Self::try_from(u64::from(value))
}
}
impl TryFrom<u32> for PromethiumIsotope {
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 PromethiumIsotope {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::Pm126 => write!(f, "Pm126"),
Self::Pm127 => write!(f, "Pm127"),
Self::Pm128 => write!(f, "Pm128"),
Self::Pm129 => write!(f, "Pm129"),
Self::Pm130 => write!(f, "Pm130"),
Self::Pm131 => write!(f, "Pm131"),
Self::Pm132 => write!(f, "Pm132"),
Self::Pm133 => write!(f, "Pm133"),
Self::Pm134 => write!(f, "Pm134"),
Self::Pm135 => write!(f, "Pm135"),
Self::Pm136 => write!(f, "Pm136"),
Self::Pm137 => write!(f, "Pm137"),
Self::Pm138 => write!(f, "Pm138"),
Self::Pm139 => write!(f, "Pm139"),
Self::Pm140 => write!(f, "Pm140"),
Self::Pm141 => write!(f, "Pm141"),
Self::Pm142 => write!(f, "Pm142"),
Self::Pm143 => write!(f, "Pm143"),
Self::Pm144 => write!(f, "Pm144"),
Self::Pm145 => write!(f, "Pm145"),
Self::Pm146 => write!(f, "Pm146"),
Self::Pm147 => write!(f, "Pm147"),
Self::Pm148 => write!(f, "Pm148"),
Self::Pm149 => write!(f, "Pm149"),
Self::Pm150 => write!(f, "Pm150"),
Self::Pm151 => write!(f, "Pm151"),
Self::Pm152 => write!(f, "Pm152"),
Self::Pm153 => write!(f, "Pm153"),
Self::Pm154 => write!(f, "Pm154"),
Self::Pm155 => write!(f, "Pm155"),
Self::Pm156 => write!(f, "Pm156"),
Self::Pm157 => write!(f, "Pm157"),
Self::Pm158 => write!(f, "Pm158"),
Self::Pm159 => write!(f, "Pm159"),
Self::Pm160 => write!(f, "Pm160"),
Self::Pm161 => write!(f, "Pm161"),
Self::Pm162 => write!(f, "Pm162"),
Self::Pm163 => write!(f, "Pm163"),
Self::Pm164 => write!(f, "Pm164"),
Self::Pm165 => write!(f, "Pm165"),
}
}
}
#[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 PromethiumIsotope::iter() {
let mass = isotope.relative_atomic_mass();
assert!(mass > 0.0, "Mass should be positive for {isotope:?}");
}
}
#[test]
fn test_element() {
for isotope in PromethiumIsotope::iter() {
let element = isotope.element();
assert_eq!(element, crate::Element::Pm, "Element should be correct for {isotope:?}");
}
}
#[test]
fn test_mass_number() {
for isotope in PromethiumIsotope::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 PromethiumIsotope::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 = PromethiumIsotope::most_abundant_isotope();
let _ = most_abundant.relative_atomic_mass();
}
#[test]
fn test_from_isotope() {
for isotope in PromethiumIsotope::iter() {
let iso: crate::Isotope = isotope.into();
match iso {
crate::Isotope::Pm(i) => assert_eq!(i, isotope),
_ => panic!("Wrong isotope type"),
}
}
}
#[test]
fn test_from_element() {
for isotope in PromethiumIsotope::iter() {
let elem: crate::Element = isotope.into();
assert_eq!(elem, crate::Element::Pm);
}
}
#[test]
fn test_try_from_mass_number() {
for isotope in PromethiumIsotope::iter() {
let mass = isotope.mass_number();
let iso = PromethiumIsotope::try_from(mass).unwrap();
assert_eq!(iso, isotope);
let iso_u32 = PromethiumIsotope::try_from(u32::from(mass)).unwrap();
assert_eq!(iso_u32, isotope);
if let Ok(mass_u8) = u8::try_from(mass) {
let iso_u8 = PromethiumIsotope::try_from(mass_u8).unwrap();
assert_eq!(iso_u8, isotope);
}
}
assert!(PromethiumIsotope::try_from(0_u16).is_err());
assert!(PromethiumIsotope::try_from(1000_u16).is_err());
assert!(PromethiumIsotope::try_from(0_u32).is_err());
assert!(PromethiumIsotope::try_from(1000_u32).is_err());
assert!(PromethiumIsotope::try_from(0_u8).is_err());
}
#[test]
fn test_display() {
for isotope in PromethiumIsotope::iter() {
let s = alloc::format!("{isotope}");
assert!(!s.is_empty(), "Display should not be empty for {isotope:?}");
}
}
}