#[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 AntimonyIsotope {
Sb103,
Sb104,
Sb105,
Sb106,
Sb107,
Sb108,
Sb109,
Sb110,
Sb111,
Sb112,
Sb113,
Sb114,
Sb115,
Sb116,
Sb117,
Sb118,
Sb119,
Sb120,
Sb121,
Sb122,
Sb123,
Sb124,
Sb125,
Sb126,
Sb127,
Sb128,
Sb129,
Sb130,
Sb131,
Sb132,
Sb133,
Sb134,
Sb135,
Sb136,
Sb137,
Sb138,
Sb139,
Sb140,
Sb141,
Sb142,
}
impl super::RelativeAtomicMass for AntimonyIsotope {
#[inline]
fn relative_atomic_mass(&self) -> f64 {
match self {
Self::Sb103 => 102.93969f64,
Self::Sb104 => 103.93648f64,
Self::Sb105 => 104.931276f64,
Self::Sb106 => 105.928638f64,
Self::Sb107 => 106.9241506f64,
Self::Sb108 => 107.9222267f64,
Self::Sb109 => 108.9181411f64,
Self::Sb110 => 109.9168543f64,
Self::Sb111 => 110.9132182f64,
Self::Sb112 => 111.9124f64,
Self::Sb113 => 112.909375f64,
Self::Sb114 => 113.90929f64,
Self::Sb115 => 114.906598f64,
Self::Sb116 => 115.9067931f64,
Self::Sb117 => 116.9048415f64,
Self::Sb118 => 117.9055321f64,
Self::Sb119 => 118.9039455f64,
Self::Sb120 => 119.9050794f64,
Self::Sb121 => 120.903812f64,
Self::Sb122 => 121.9051699f64,
Self::Sb123 => 122.9042132f64,
Self::Sb124 => 123.905935f64,
Self::Sb125 => 124.905253f64,
Self::Sb126 => 125.907253f64,
Self::Sb127 => 126.9069243f64,
Self::Sb128 => 127.909146f64,
Self::Sb129 => 128.909147f64,
Self::Sb130 => 129.911662f64,
Self::Sb131 => 130.9119888f64,
Self::Sb132 => 131.9145077f64,
Self::Sb133 => 132.9152732f64,
Self::Sb134 => 133.9205357f64,
Self::Sb135 => 134.9251851f64,
Self::Sb136 => 135.9307459f64,
Self::Sb137 => 136.93555f64,
Self::Sb138 => 137.94145f64,
Self::Sb139 => 138.94655f64,
Self::Sb140 => 139.95283f64,
Self::Sb141 => 140.957552f64,
Self::Sb142 => 141.963918f64,
}
}
}
impl super::ElementVariant for AntimonyIsotope {
#[inline]
fn element(&self) -> crate::Element {
crate::Element::Sb
}
}
impl super::MassNumber for AntimonyIsotope {
#[inline]
fn mass_number(&self) -> u16 {
match self {
Self::Sb103 => 103u16,
Self::Sb104 => 104u16,
Self::Sb105 => 105u16,
Self::Sb106 => 106u16,
Self::Sb107 => 107u16,
Self::Sb108 => 108u16,
Self::Sb109 => 109u16,
Self::Sb110 => 110u16,
Self::Sb111 => 111u16,
Self::Sb112 => 112u16,
Self::Sb113 => 113u16,
Self::Sb114 => 114u16,
Self::Sb115 => 115u16,
Self::Sb116 => 116u16,
Self::Sb117 => 117u16,
Self::Sb118 => 118u16,
Self::Sb119 => 119u16,
Self::Sb120 => 120u16,
Self::Sb121 => 121u16,
Self::Sb122 => 122u16,
Self::Sb123 => 123u16,
Self::Sb124 => 124u16,
Self::Sb125 => 125u16,
Self::Sb126 => 126u16,
Self::Sb127 => 127u16,
Self::Sb128 => 128u16,
Self::Sb129 => 129u16,
Self::Sb130 => 130u16,
Self::Sb131 => 131u16,
Self::Sb132 => 132u16,
Self::Sb133 => 133u16,
Self::Sb134 => 134u16,
Self::Sb135 => 135u16,
Self::Sb136 => 136u16,
Self::Sb137 => 137u16,
Self::Sb138 => 138u16,
Self::Sb139 => 139u16,
Self::Sb140 => 140u16,
Self::Sb141 => 141u16,
Self::Sb142 => 142u16,
}
}
}
impl super::IsotopicComposition for AntimonyIsotope {
#[inline]
fn isotopic_composition(&self) -> Option<f64> {
match self {
Self::Sb121 => Some(0.5721f64),
Self::Sb123 => Some(0.4279f64),
_ => None,
}
}
}
impl super::MostAbundantIsotope for AntimonyIsotope {
fn most_abundant_isotope() -> Self {
Self::Sb121
}
}
impl From<AntimonyIsotope> for crate::Isotope {
fn from(isotope: AntimonyIsotope) -> Self {
crate::Isotope::Sb(isotope)
}
}
impl From<AntimonyIsotope> for crate::Element {
fn from(_isotope: AntimonyIsotope) -> Self {
crate::Element::Sb
}
}
impl TryFrom<u64> for AntimonyIsotope {
type Error = crate::errors::Error;
fn try_from(value: u64) -> Result<Self, Self::Error> {
match value {
103u64 => Ok(Self::Sb103),
104u64 => Ok(Self::Sb104),
105u64 => Ok(Self::Sb105),
106u64 => Ok(Self::Sb106),
107u64 => Ok(Self::Sb107),
108u64 => Ok(Self::Sb108),
109u64 => Ok(Self::Sb109),
110u64 => Ok(Self::Sb110),
111u64 => Ok(Self::Sb111),
112u64 => Ok(Self::Sb112),
113u64 => Ok(Self::Sb113),
114u64 => Ok(Self::Sb114),
115u64 => Ok(Self::Sb115),
116u64 => Ok(Self::Sb116),
117u64 => Ok(Self::Sb117),
118u64 => Ok(Self::Sb118),
119u64 => Ok(Self::Sb119),
120u64 => Ok(Self::Sb120),
121u64 => Ok(Self::Sb121),
122u64 => Ok(Self::Sb122),
123u64 => Ok(Self::Sb123),
124u64 => Ok(Self::Sb124),
125u64 => Ok(Self::Sb125),
126u64 => Ok(Self::Sb126),
127u64 => Ok(Self::Sb127),
128u64 => Ok(Self::Sb128),
129u64 => Ok(Self::Sb129),
130u64 => Ok(Self::Sb130),
131u64 => Ok(Self::Sb131),
132u64 => Ok(Self::Sb132),
133u64 => Ok(Self::Sb133),
134u64 => Ok(Self::Sb134),
135u64 => Ok(Self::Sb135),
136u64 => Ok(Self::Sb136),
137u64 => Ok(Self::Sb137),
138u64 => Ok(Self::Sb138),
139u64 => Ok(Self::Sb139),
140u64 => Ok(Self::Sb140),
141u64 => Ok(Self::Sb141),
142u64 => Ok(Self::Sb142),
_ => Err(crate::errors::Error::Isotope(crate::Element::Sb, value)),
}
}
}
impl TryFrom<u8> for AntimonyIsotope {
type Error = crate::errors::Error;
fn try_from(value: u8) -> Result<Self, Self::Error> {
Self::try_from(u64::from(value))
}
}
impl TryFrom<u16> for AntimonyIsotope {
type Error = crate::errors::Error;
fn try_from(value: u16) -> Result<Self, Self::Error> {
Self::try_from(u64::from(value))
}
}
impl TryFrom<u32> for AntimonyIsotope {
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 AntimonyIsotope {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::Sb103 => write!(f, "Sb103"),
Self::Sb104 => write!(f, "Sb104"),
Self::Sb105 => write!(f, "Sb105"),
Self::Sb106 => write!(f, "Sb106"),
Self::Sb107 => write!(f, "Sb107"),
Self::Sb108 => write!(f, "Sb108"),
Self::Sb109 => write!(f, "Sb109"),
Self::Sb110 => write!(f, "Sb110"),
Self::Sb111 => write!(f, "Sb111"),
Self::Sb112 => write!(f, "Sb112"),
Self::Sb113 => write!(f, "Sb113"),
Self::Sb114 => write!(f, "Sb114"),
Self::Sb115 => write!(f, "Sb115"),
Self::Sb116 => write!(f, "Sb116"),
Self::Sb117 => write!(f, "Sb117"),
Self::Sb118 => write!(f, "Sb118"),
Self::Sb119 => write!(f, "Sb119"),
Self::Sb120 => write!(f, "Sb120"),
Self::Sb121 => write!(f, "Sb121"),
Self::Sb122 => write!(f, "Sb122"),
Self::Sb123 => write!(f, "Sb123"),
Self::Sb124 => write!(f, "Sb124"),
Self::Sb125 => write!(f, "Sb125"),
Self::Sb126 => write!(f, "Sb126"),
Self::Sb127 => write!(f, "Sb127"),
Self::Sb128 => write!(f, "Sb128"),
Self::Sb129 => write!(f, "Sb129"),
Self::Sb130 => write!(f, "Sb130"),
Self::Sb131 => write!(f, "Sb131"),
Self::Sb132 => write!(f, "Sb132"),
Self::Sb133 => write!(f, "Sb133"),
Self::Sb134 => write!(f, "Sb134"),
Self::Sb135 => write!(f, "Sb135"),
Self::Sb136 => write!(f, "Sb136"),
Self::Sb137 => write!(f, "Sb137"),
Self::Sb138 => write!(f, "Sb138"),
Self::Sb139 => write!(f, "Sb139"),
Self::Sb140 => write!(f, "Sb140"),
Self::Sb141 => write!(f, "Sb141"),
Self::Sb142 => write!(f, "Sb142"),
}
}
}
#[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 AntimonyIsotope::iter() {
let mass = isotope.relative_atomic_mass();
assert!(mass > 0.0, "Mass should be positive for {isotope:?}");
}
}
#[test]
fn test_element() {
for isotope in AntimonyIsotope::iter() {
let element = isotope.element();
assert_eq!(element, crate::Element::Sb, "Element should be correct for {isotope:?}");
}
}
#[test]
fn test_mass_number() {
for isotope in AntimonyIsotope::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 AntimonyIsotope::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 = AntimonyIsotope::most_abundant_isotope();
let _ = most_abundant.relative_atomic_mass();
}
#[test]
fn test_from_isotope() {
for isotope in AntimonyIsotope::iter() {
let iso: crate::Isotope = isotope.into();
match iso {
crate::Isotope::Sb(i) => assert_eq!(i, isotope),
_ => panic!("Wrong isotope type"),
}
}
}
#[test]
fn test_from_element() {
for isotope in AntimonyIsotope::iter() {
let elem: crate::Element = isotope.into();
assert_eq!(elem, crate::Element::Sb);
}
}
#[test]
fn test_try_from_mass_number() {
for isotope in AntimonyIsotope::iter() {
let mass = isotope.mass_number();
let iso = AntimonyIsotope::try_from(mass).unwrap();
assert_eq!(iso, isotope);
let iso_u32 = AntimonyIsotope::try_from(u32::from(mass)).unwrap();
assert_eq!(iso_u32, isotope);
if let Ok(mass_u8) = u8::try_from(mass) {
let iso_u8 = AntimonyIsotope::try_from(mass_u8).unwrap();
assert_eq!(iso_u8, isotope);
}
}
assert!(AntimonyIsotope::try_from(0_u16).is_err());
assert!(AntimonyIsotope::try_from(1000_u16).is_err());
assert!(AntimonyIsotope::try_from(0_u32).is_err());
assert!(AntimonyIsotope::try_from(1000_u32).is_err());
assert!(AntimonyIsotope::try_from(0_u8).is_err());
}
#[test]
fn test_display() {
for isotope in AntimonyIsotope::iter() {
let s = alloc::format!("{isotope}");
assert!(!s.is_empty(), "Display should not be empty for {isotope:?}");
}
}
}