#[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 TinIsotope {
Sn99,
Sn100,
Sn101,
Sn102,
Sn103,
Sn104,
Sn105,
Sn106,
Sn107,
Sn108,
Sn109,
Sn110,
Sn111,
Sn112,
Sn113,
Sn114,
Sn115,
Sn116,
Sn117,
Sn118,
Sn119,
Sn120,
Sn121,
Sn122,
Sn123,
Sn124,
Sn125,
Sn126,
Sn127,
Sn128,
Sn129,
Sn130,
Sn131,
Sn132,
Sn133,
Sn134,
Sn135,
Sn136,
Sn137,
Sn138,
Sn139,
Sn140,
}
impl super::RelativeAtomicMass for TinIsotope {
#[inline]
fn relative_atomic_mass(&self) -> f64 {
match self {
Self::Sn99 => 98.94853f64,
Self::Sn100 => 99.9385f64,
Self::Sn101 => 100.93526f64,
Self::Sn102 => 101.93029f64,
Self::Sn103 => 102.928105f64,
Self::Sn104 => 103.9231052f64,
Self::Sn105 => 104.9212684f64,
Self::Sn106 => 105.9169574f64,
Self::Sn107 => 106.9157137f64,
Self::Sn108 => 107.9118943f64,
Self::Sn109 => 108.9112921f64,
Self::Sn110 => 109.907845f64,
Self::Sn111 => 110.9077401f64,
Self::Sn112 => 111.90482387f64,
Self::Sn113 => 112.9051757f64,
Self::Sn114 => 113.9027827f64,
Self::Sn115 => 114.903344699f64,
Self::Sn116 => 115.9017428f64,
Self::Sn117 => 116.90295398f64,
Self::Sn118 => 117.90160657f64,
Self::Sn119 => 118.90331117f64,
Self::Sn120 => 119.90220163f64,
Self::Sn121 => 120.9042426f64,
Self::Sn122 => 121.9034438f64,
Self::Sn123 => 122.9057252f64,
Self::Sn124 => 123.9052766f64,
Self::Sn125 => 124.9077864f64,
Self::Sn126 => 125.907659f64,
Self::Sn127 => 126.91039f64,
Self::Sn128 => 127.910507f64,
Self::Sn129 => 128.913465f64,
Self::Sn130 => 129.9139738f64,
Self::Sn131 => 130.917045f64,
Self::Sn132 => 131.9178267f64,
Self::Sn133 => 132.9239134f64,
Self::Sn134 => 133.9286821f64,
Self::Sn135 => 134.9349086f64,
Self::Sn136 => 135.93999f64,
Self::Sn137 => 136.94655f64,
Self::Sn138 => 137.95184f64,
Self::Sn139 => 138.957799f64,
Self::Sn140 => 139.962973f64,
}
}
}
impl super::ElementVariant for TinIsotope {
#[inline]
fn element(&self) -> crate::Element {
crate::Element::Sn
}
}
impl super::MassNumber for TinIsotope {
#[inline]
fn mass_number(&self) -> u16 {
match self {
Self::Sn99 => 99u16,
Self::Sn100 => 100u16,
Self::Sn101 => 101u16,
Self::Sn102 => 102u16,
Self::Sn103 => 103u16,
Self::Sn104 => 104u16,
Self::Sn105 => 105u16,
Self::Sn106 => 106u16,
Self::Sn107 => 107u16,
Self::Sn108 => 108u16,
Self::Sn109 => 109u16,
Self::Sn110 => 110u16,
Self::Sn111 => 111u16,
Self::Sn112 => 112u16,
Self::Sn113 => 113u16,
Self::Sn114 => 114u16,
Self::Sn115 => 115u16,
Self::Sn116 => 116u16,
Self::Sn117 => 117u16,
Self::Sn118 => 118u16,
Self::Sn119 => 119u16,
Self::Sn120 => 120u16,
Self::Sn121 => 121u16,
Self::Sn122 => 122u16,
Self::Sn123 => 123u16,
Self::Sn124 => 124u16,
Self::Sn125 => 125u16,
Self::Sn126 => 126u16,
Self::Sn127 => 127u16,
Self::Sn128 => 128u16,
Self::Sn129 => 129u16,
Self::Sn130 => 130u16,
Self::Sn131 => 131u16,
Self::Sn132 => 132u16,
Self::Sn133 => 133u16,
Self::Sn134 => 134u16,
Self::Sn135 => 135u16,
Self::Sn136 => 136u16,
Self::Sn137 => 137u16,
Self::Sn138 => 138u16,
Self::Sn139 => 139u16,
Self::Sn140 => 140u16,
}
}
}
impl super::IsotopicComposition for TinIsotope {
#[inline]
fn isotopic_composition(&self) -> Option<f64> {
match self {
Self::Sn112 => Some(0.0097f64),
Self::Sn114 => Some(0.0066f64),
Self::Sn115 => Some(0.0034f64),
Self::Sn116 => Some(0.1454f64),
Self::Sn117 => Some(0.0768f64),
Self::Sn118 => Some(0.2422f64),
Self::Sn119 => Some(0.0859f64),
Self::Sn120 => Some(0.3258f64),
Self::Sn122 => Some(0.0463f64),
Self::Sn124 => Some(0.0579f64),
_ => None,
}
}
}
impl super::MostAbundantIsotope for TinIsotope {
fn most_abundant_isotope() -> Self {
Self::Sn120
}
}
impl From<TinIsotope> for crate::Isotope {
fn from(isotope: TinIsotope) -> Self {
crate::Isotope::Sn(isotope)
}
}
impl From<TinIsotope> for crate::Element {
fn from(_isotope: TinIsotope) -> Self {
crate::Element::Sn
}
}
impl TryFrom<u64> for TinIsotope {
type Error = crate::errors::Error;
fn try_from(value: u64) -> Result<Self, Self::Error> {
match value {
99u64 => Ok(Self::Sn99),
100u64 => Ok(Self::Sn100),
101u64 => Ok(Self::Sn101),
102u64 => Ok(Self::Sn102),
103u64 => Ok(Self::Sn103),
104u64 => Ok(Self::Sn104),
105u64 => Ok(Self::Sn105),
106u64 => Ok(Self::Sn106),
107u64 => Ok(Self::Sn107),
108u64 => Ok(Self::Sn108),
109u64 => Ok(Self::Sn109),
110u64 => Ok(Self::Sn110),
111u64 => Ok(Self::Sn111),
112u64 => Ok(Self::Sn112),
113u64 => Ok(Self::Sn113),
114u64 => Ok(Self::Sn114),
115u64 => Ok(Self::Sn115),
116u64 => Ok(Self::Sn116),
117u64 => Ok(Self::Sn117),
118u64 => Ok(Self::Sn118),
119u64 => Ok(Self::Sn119),
120u64 => Ok(Self::Sn120),
121u64 => Ok(Self::Sn121),
122u64 => Ok(Self::Sn122),
123u64 => Ok(Self::Sn123),
124u64 => Ok(Self::Sn124),
125u64 => Ok(Self::Sn125),
126u64 => Ok(Self::Sn126),
127u64 => Ok(Self::Sn127),
128u64 => Ok(Self::Sn128),
129u64 => Ok(Self::Sn129),
130u64 => Ok(Self::Sn130),
131u64 => Ok(Self::Sn131),
132u64 => Ok(Self::Sn132),
133u64 => Ok(Self::Sn133),
134u64 => Ok(Self::Sn134),
135u64 => Ok(Self::Sn135),
136u64 => Ok(Self::Sn136),
137u64 => Ok(Self::Sn137),
138u64 => Ok(Self::Sn138),
139u64 => Ok(Self::Sn139),
140u64 => Ok(Self::Sn140),
_ => Err(crate::errors::Error::Isotope(crate::Element::Sn, value)),
}
}
}
impl TryFrom<u8> for TinIsotope {
type Error = crate::errors::Error;
fn try_from(value: u8) -> Result<Self, Self::Error> {
Self::try_from(u64::from(value))
}
}
impl TryFrom<u16> for TinIsotope {
type Error = crate::errors::Error;
fn try_from(value: u16) -> Result<Self, Self::Error> {
Self::try_from(u64::from(value))
}
}
impl TryFrom<u32> for TinIsotope {
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 TinIsotope {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::Sn99 => write!(f, "Sn99"),
Self::Sn100 => write!(f, "Sn100"),
Self::Sn101 => write!(f, "Sn101"),
Self::Sn102 => write!(f, "Sn102"),
Self::Sn103 => write!(f, "Sn103"),
Self::Sn104 => write!(f, "Sn104"),
Self::Sn105 => write!(f, "Sn105"),
Self::Sn106 => write!(f, "Sn106"),
Self::Sn107 => write!(f, "Sn107"),
Self::Sn108 => write!(f, "Sn108"),
Self::Sn109 => write!(f, "Sn109"),
Self::Sn110 => write!(f, "Sn110"),
Self::Sn111 => write!(f, "Sn111"),
Self::Sn112 => write!(f, "Sn112"),
Self::Sn113 => write!(f, "Sn113"),
Self::Sn114 => write!(f, "Sn114"),
Self::Sn115 => write!(f, "Sn115"),
Self::Sn116 => write!(f, "Sn116"),
Self::Sn117 => write!(f, "Sn117"),
Self::Sn118 => write!(f, "Sn118"),
Self::Sn119 => write!(f, "Sn119"),
Self::Sn120 => write!(f, "Sn120"),
Self::Sn121 => write!(f, "Sn121"),
Self::Sn122 => write!(f, "Sn122"),
Self::Sn123 => write!(f, "Sn123"),
Self::Sn124 => write!(f, "Sn124"),
Self::Sn125 => write!(f, "Sn125"),
Self::Sn126 => write!(f, "Sn126"),
Self::Sn127 => write!(f, "Sn127"),
Self::Sn128 => write!(f, "Sn128"),
Self::Sn129 => write!(f, "Sn129"),
Self::Sn130 => write!(f, "Sn130"),
Self::Sn131 => write!(f, "Sn131"),
Self::Sn132 => write!(f, "Sn132"),
Self::Sn133 => write!(f, "Sn133"),
Self::Sn134 => write!(f, "Sn134"),
Self::Sn135 => write!(f, "Sn135"),
Self::Sn136 => write!(f, "Sn136"),
Self::Sn137 => write!(f, "Sn137"),
Self::Sn138 => write!(f, "Sn138"),
Self::Sn139 => write!(f, "Sn139"),
Self::Sn140 => write!(f, "Sn140"),
}
}
}
#[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 TinIsotope::iter() {
let mass = isotope.relative_atomic_mass();
assert!(mass > 0.0, "Mass should be positive for {isotope:?}");
}
}
#[test]
fn test_element() {
for isotope in TinIsotope::iter() {
let element = isotope.element();
assert_eq!(element, crate::Element::Sn, "Element should be correct for {isotope:?}");
}
}
#[test]
fn test_mass_number() {
for isotope in TinIsotope::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 TinIsotope::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 = TinIsotope::most_abundant_isotope();
let _ = most_abundant.relative_atomic_mass();
}
#[test]
fn test_from_isotope() {
for isotope in TinIsotope::iter() {
let iso: crate::Isotope = isotope.into();
match iso {
crate::Isotope::Sn(i) => assert_eq!(i, isotope),
_ => panic!("Wrong isotope type"),
}
}
}
#[test]
fn test_from_element() {
for isotope in TinIsotope::iter() {
let elem: crate::Element = isotope.into();
assert_eq!(elem, crate::Element::Sn);
}
}
#[test]
fn test_try_from_mass_number() {
for isotope in TinIsotope::iter() {
let mass = isotope.mass_number();
let iso = TinIsotope::try_from(mass).unwrap();
assert_eq!(iso, isotope);
let iso_u32 = TinIsotope::try_from(u32::from(mass)).unwrap();
assert_eq!(iso_u32, isotope);
if let Ok(mass_u8) = u8::try_from(mass) {
let iso_u8 = TinIsotope::try_from(mass_u8).unwrap();
assert_eq!(iso_u8, isotope);
}
}
assert!(TinIsotope::try_from(0_u16).is_err());
assert!(TinIsotope::try_from(1000_u16).is_err());
assert!(TinIsotope::try_from(0_u32).is_err());
assert!(TinIsotope::try_from(1000_u32).is_err());
assert!(TinIsotope::try_from(0_u8).is_err());
}
#[test]
fn test_display() {
for isotope in TinIsotope::iter() {
let s = alloc::format!("{isotope}");
assert!(!s.is_empty(), "Display should not be empty for {isotope:?}");
}
}
}