#[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 IodineIsotope {
I108,
I109,
I110,
I111,
I112,
I113,
I114,
I115,
I116,
I117,
I118,
I119,
I120,
I121,
I122,
I123,
I124,
I125,
I126,
I127,
I128,
I129,
I130,
I131,
I132,
I133,
I134,
I135,
I136,
I137,
I138,
I139,
I140,
I141,
I142,
I143,
I144,
I145,
I146,
I147,
}
impl super::RelativeAtomicMass for IodineIsotope {
#[inline]
fn relative_atomic_mass(&self) -> f64 {
match self {
Self::I108 => 107.94348f64,
Self::I109 => 108.9380853f64,
Self::I110 => 109.935089f64,
Self::I111 => 110.9302692f64,
Self::I112 => 111.928005f64,
Self::I113 => 112.9236501f64,
Self::I114 => 113.92185f64,
Self::I115 => 114.918048f64,
Self::I116 => 115.91681f64,
Self::I117 => 116.913648f64,
Self::I118 => 117.913074f64,
Self::I119 => 118.910074f64,
Self::I120 => 119.910087f64,
Self::I121 => 120.9074051f64,
Self::I122 => 121.9075888f64,
Self::I123 => 122.9055885f64,
Self::I124 => 123.906209f64,
Self::I125 => 124.9046294f64,
Self::I126 => 125.9056233f64,
Self::I127 => 126.9044719f64,
Self::I128 => 127.9058086f64,
Self::I129 => 128.9049837f64,
Self::I130 => 129.9066702f64,
Self::I131 => 130.9061263f64,
Self::I132 => 131.9079935f64,
Self::I133 => 132.907797f64,
Self::I134 => 133.9097588f64,
Self::I135 => 134.9100488f64,
Self::I136 => 135.914604f64,
Self::I137 => 136.9180282f64,
Self::I138 => 137.9227264f64,
Self::I139 => 138.926506f64,
Self::I140 => 139.93173f64,
Self::I141 => 140.93569f64,
Self::I142 => 141.9412f64,
Self::I143 => 142.94565f64,
Self::I144 => 143.95139f64,
Self::I145 => 144.95605f64,
Self::I146 => 145.961846f64,
Self::I147 => 146.966505f64,
}
}
}
impl super::ElementVariant for IodineIsotope {
#[inline]
fn element(&self) -> crate::Element {
crate::Element::I
}
}
impl super::MassNumber for IodineIsotope {
#[inline]
fn mass_number(&self) -> u16 {
match self {
Self::I108 => 108u16,
Self::I109 => 109u16,
Self::I110 => 110u16,
Self::I111 => 111u16,
Self::I112 => 112u16,
Self::I113 => 113u16,
Self::I114 => 114u16,
Self::I115 => 115u16,
Self::I116 => 116u16,
Self::I117 => 117u16,
Self::I118 => 118u16,
Self::I119 => 119u16,
Self::I120 => 120u16,
Self::I121 => 121u16,
Self::I122 => 122u16,
Self::I123 => 123u16,
Self::I124 => 124u16,
Self::I125 => 125u16,
Self::I126 => 126u16,
Self::I127 => 127u16,
Self::I128 => 128u16,
Self::I129 => 129u16,
Self::I130 => 130u16,
Self::I131 => 131u16,
Self::I132 => 132u16,
Self::I133 => 133u16,
Self::I134 => 134u16,
Self::I135 => 135u16,
Self::I136 => 136u16,
Self::I137 => 137u16,
Self::I138 => 138u16,
Self::I139 => 139u16,
Self::I140 => 140u16,
Self::I141 => 141u16,
Self::I142 => 142u16,
Self::I143 => 143u16,
Self::I144 => 144u16,
Self::I145 => 145u16,
Self::I146 => 146u16,
Self::I147 => 147u16,
}
}
}
impl super::IsotopicComposition for IodineIsotope {
#[inline]
fn isotopic_composition(&self) -> Option<f64> {
match self {
Self::I127 => Some(1f64),
_ => None,
}
}
}
impl super::MostAbundantIsotope for IodineIsotope {
fn most_abundant_isotope() -> Self {
Self::I127
}
}
impl From<IodineIsotope> for crate::Isotope {
fn from(isotope: IodineIsotope) -> Self {
crate::Isotope::I(isotope)
}
}
impl From<IodineIsotope> for crate::Element {
fn from(_isotope: IodineIsotope) -> Self {
crate::Element::I
}
}
impl TryFrom<u64> for IodineIsotope {
type Error = crate::errors::Error;
fn try_from(value: u64) -> Result<Self, Self::Error> {
match value {
108u64 => Ok(Self::I108),
109u64 => Ok(Self::I109),
110u64 => Ok(Self::I110),
111u64 => Ok(Self::I111),
112u64 => Ok(Self::I112),
113u64 => Ok(Self::I113),
114u64 => Ok(Self::I114),
115u64 => Ok(Self::I115),
116u64 => Ok(Self::I116),
117u64 => Ok(Self::I117),
118u64 => Ok(Self::I118),
119u64 => Ok(Self::I119),
120u64 => Ok(Self::I120),
121u64 => Ok(Self::I121),
122u64 => Ok(Self::I122),
123u64 => Ok(Self::I123),
124u64 => Ok(Self::I124),
125u64 => Ok(Self::I125),
126u64 => Ok(Self::I126),
127u64 => Ok(Self::I127),
128u64 => Ok(Self::I128),
129u64 => Ok(Self::I129),
130u64 => Ok(Self::I130),
131u64 => Ok(Self::I131),
132u64 => Ok(Self::I132),
133u64 => Ok(Self::I133),
134u64 => Ok(Self::I134),
135u64 => Ok(Self::I135),
136u64 => Ok(Self::I136),
137u64 => Ok(Self::I137),
138u64 => Ok(Self::I138),
139u64 => Ok(Self::I139),
140u64 => Ok(Self::I140),
141u64 => Ok(Self::I141),
142u64 => Ok(Self::I142),
143u64 => Ok(Self::I143),
144u64 => Ok(Self::I144),
145u64 => Ok(Self::I145),
146u64 => Ok(Self::I146),
147u64 => Ok(Self::I147),
_ => Err(crate::errors::Error::Isotope(crate::Element::I, value)),
}
}
}
impl TryFrom<u8> for IodineIsotope {
type Error = crate::errors::Error;
fn try_from(value: u8) -> Result<Self, Self::Error> {
Self::try_from(u64::from(value))
}
}
impl TryFrom<u16> for IodineIsotope {
type Error = crate::errors::Error;
fn try_from(value: u16) -> Result<Self, Self::Error> {
Self::try_from(u64::from(value))
}
}
impl TryFrom<u32> for IodineIsotope {
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 IodineIsotope {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::I108 => write!(f, "I108"),
Self::I109 => write!(f, "I109"),
Self::I110 => write!(f, "I110"),
Self::I111 => write!(f, "I111"),
Self::I112 => write!(f, "I112"),
Self::I113 => write!(f, "I113"),
Self::I114 => write!(f, "I114"),
Self::I115 => write!(f, "I115"),
Self::I116 => write!(f, "I116"),
Self::I117 => write!(f, "I117"),
Self::I118 => write!(f, "I118"),
Self::I119 => write!(f, "I119"),
Self::I120 => write!(f, "I120"),
Self::I121 => write!(f, "I121"),
Self::I122 => write!(f, "I122"),
Self::I123 => write!(f, "I123"),
Self::I124 => write!(f, "I124"),
Self::I125 => write!(f, "I125"),
Self::I126 => write!(f, "I126"),
Self::I127 => write!(f, "I127"),
Self::I128 => write!(f, "I128"),
Self::I129 => write!(f, "I129"),
Self::I130 => write!(f, "I130"),
Self::I131 => write!(f, "I131"),
Self::I132 => write!(f, "I132"),
Self::I133 => write!(f, "I133"),
Self::I134 => write!(f, "I134"),
Self::I135 => write!(f, "I135"),
Self::I136 => write!(f, "I136"),
Self::I137 => write!(f, "I137"),
Self::I138 => write!(f, "I138"),
Self::I139 => write!(f, "I139"),
Self::I140 => write!(f, "I140"),
Self::I141 => write!(f, "I141"),
Self::I142 => write!(f, "I142"),
Self::I143 => write!(f, "I143"),
Self::I144 => write!(f, "I144"),
Self::I145 => write!(f, "I145"),
Self::I146 => write!(f, "I146"),
Self::I147 => write!(f, "I147"),
}
}
}
#[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 IodineIsotope::iter() {
let mass = isotope.relative_atomic_mass();
assert!(mass > 0.0, "Mass should be positive for {isotope:?}");
}
}
#[test]
fn test_element() {
for isotope in IodineIsotope::iter() {
let element = isotope.element();
assert_eq!(element, crate::Element::I, "Element should be correct for {isotope:?}");
}
}
#[test]
fn test_mass_number() {
for isotope in IodineIsotope::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 IodineIsotope::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 = IodineIsotope::most_abundant_isotope();
let _ = most_abundant.relative_atomic_mass();
}
#[test]
fn test_from_isotope() {
for isotope in IodineIsotope::iter() {
let iso: crate::Isotope = isotope.into();
match iso {
crate::Isotope::I(i) => assert_eq!(i, isotope),
_ => panic!("Wrong isotope type"),
}
}
}
#[test]
fn test_from_element() {
for isotope in IodineIsotope::iter() {
let elem: crate::Element = isotope.into();
assert_eq!(elem, crate::Element::I);
}
}
#[test]
fn test_try_from_mass_number() {
for isotope in IodineIsotope::iter() {
let mass = isotope.mass_number();
let iso = IodineIsotope::try_from(mass).unwrap();
assert_eq!(iso, isotope);
let iso_u32 = IodineIsotope::try_from(u32::from(mass)).unwrap();
assert_eq!(iso_u32, isotope);
if let Ok(mass_u8) = u8::try_from(mass) {
let iso_u8 = IodineIsotope::try_from(mass_u8).unwrap();
assert_eq!(iso_u8, isotope);
}
}
assert!(IodineIsotope::try_from(0_u16).is_err());
assert!(IodineIsotope::try_from(1000_u16).is_err());
assert!(IodineIsotope::try_from(0_u32).is_err());
assert!(IodineIsotope::try_from(1000_u32).is_err());
assert!(IodineIsotope::try_from(0_u8).is_err());
}
#[test]
fn test_display() {
for isotope in IodineIsotope::iter() {
let s = alloc::format!("{isotope}");
assert!(!s.is_empty(), "Display should not be empty for {isotope:?}");
}
}
}