#[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 XenonIsotope {
Xe108,
Xe109,
Xe110,
Xe111,
Xe112,
Xe113,
Xe114,
Xe115,
Xe116,
Xe117,
Xe118,
Xe119,
Xe120,
Xe121,
Xe122,
Xe123,
Xe124,
Xe125,
Xe126,
Xe127,
Xe128,
Xe129,
Xe130,
Xe131,
Xe132,
Xe133,
Xe134,
Xe135,
Xe136,
Xe137,
Xe138,
Xe139,
Xe140,
Xe141,
Xe142,
Xe143,
Xe144,
Xe145,
Xe146,
Xe147,
Xe148,
Xe149,
Xe150,
}
impl super::RelativeAtomicMass for XenonIsotope {
#[inline]
fn relative_atomic_mass(&self) -> f64 {
match self {
Self::Xe108 => 107.954232285f64,
Self::Xe109 => 108.95043f64,
Self::Xe110 => 109.94426f64,
Self::Xe111 => 110.941607f64,
Self::Xe112 => 111.935559f64,
Self::Xe113 => 112.9332217f64,
Self::Xe114 => 113.92798f64,
Self::Xe115 => 114.926294f64,
Self::Xe116 => 115.921581f64,
Self::Xe117 => 116.920359f64,
Self::Xe118 => 117.916179f64,
Self::Xe119 => 118.915411f64,
Self::Xe120 => 119.911784f64,
Self::Xe121 => 120.911453f64,
Self::Xe122 => 121.908368f64,
Self::Xe123 => 122.908482f64,
Self::Xe124 => 123.905892f64,
Self::Xe125 => 124.9063944f64,
Self::Xe126 => 125.9042983f64,
Self::Xe127 => 126.9051829f64,
Self::Xe128 => 127.903531f64,
Self::Xe129 => 128.9047808611f64,
Self::Xe130 => 129.903509349f64,
Self::Xe131 => 130.90508406f64,
Self::Xe132 => 131.9041550856f64,
Self::Xe133 => 132.9059108f64,
Self::Xe134 => 133.90539466f64,
Self::Xe135 => 134.9072278f64,
Self::Xe136 => 135.907214484f64,
Self::Xe137 => 136.91155778f64,
Self::Xe138 => 137.9141463f64,
Self::Xe139 => 138.9187922f64,
Self::Xe140 => 139.9216458f64,
Self::Xe141 => 140.9267872f64,
Self::Xe142 => 141.9299731f64,
Self::Xe143 => 142.9353696f64,
Self::Xe144 => 143.9389451f64,
Self::Xe145 => 144.94472f64,
Self::Xe146 => 145.948518f64,
Self::Xe147 => 146.95426f64,
Self::Xe148 => 147.95813f64,
Self::Xe149 => 148.964573f64,
Self::Xe150 => 149.968878f64,
}
}
}
impl super::ElementVariant for XenonIsotope {
#[inline]
fn element(&self) -> crate::Element {
crate::Element::Xe
}
}
impl super::MassNumber for XenonIsotope {
#[inline]
fn mass_number(&self) -> u16 {
match self {
Self::Xe108 => 108u16,
Self::Xe109 => 109u16,
Self::Xe110 => 110u16,
Self::Xe111 => 111u16,
Self::Xe112 => 112u16,
Self::Xe113 => 113u16,
Self::Xe114 => 114u16,
Self::Xe115 => 115u16,
Self::Xe116 => 116u16,
Self::Xe117 => 117u16,
Self::Xe118 => 118u16,
Self::Xe119 => 119u16,
Self::Xe120 => 120u16,
Self::Xe121 => 121u16,
Self::Xe122 => 122u16,
Self::Xe123 => 123u16,
Self::Xe124 => 124u16,
Self::Xe125 => 125u16,
Self::Xe126 => 126u16,
Self::Xe127 => 127u16,
Self::Xe128 => 128u16,
Self::Xe129 => 129u16,
Self::Xe130 => 130u16,
Self::Xe131 => 131u16,
Self::Xe132 => 132u16,
Self::Xe133 => 133u16,
Self::Xe134 => 134u16,
Self::Xe135 => 135u16,
Self::Xe136 => 136u16,
Self::Xe137 => 137u16,
Self::Xe138 => 138u16,
Self::Xe139 => 139u16,
Self::Xe140 => 140u16,
Self::Xe141 => 141u16,
Self::Xe142 => 142u16,
Self::Xe143 => 143u16,
Self::Xe144 => 144u16,
Self::Xe145 => 145u16,
Self::Xe146 => 146u16,
Self::Xe147 => 147u16,
Self::Xe148 => 148u16,
Self::Xe149 => 149u16,
Self::Xe150 => 150u16,
}
}
}
impl super::IsotopicComposition for XenonIsotope {
#[inline]
fn isotopic_composition(&self) -> Option<f64> {
match self {
Self::Xe124 => Some(0.000952f64),
Self::Xe126 => Some(0.00089f64),
Self::Xe128 => Some(0.019102f64),
Self::Xe129 => Some(0.264006f64),
Self::Xe130 => Some(0.04071f64),
Self::Xe131 => Some(0.212324f64),
Self::Xe132 => Some(0.269086f64),
Self::Xe134 => Some(0.104357f64),
Self::Xe136 => Some(0.088573f64),
_ => None,
}
}
}
impl super::MostAbundantIsotope for XenonIsotope {
fn most_abundant_isotope() -> Self {
Self::Xe132
}
}
impl From<XenonIsotope> for crate::Isotope {
fn from(isotope: XenonIsotope) -> Self {
crate::Isotope::Xe(isotope)
}
}
impl From<XenonIsotope> for crate::Element {
fn from(_isotope: XenonIsotope) -> Self {
crate::Element::Xe
}
}
impl TryFrom<u64> for XenonIsotope {
type Error = crate::errors::Error;
fn try_from(value: u64) -> Result<Self, Self::Error> {
match value {
108u64 => Ok(Self::Xe108),
109u64 => Ok(Self::Xe109),
110u64 => Ok(Self::Xe110),
111u64 => Ok(Self::Xe111),
112u64 => Ok(Self::Xe112),
113u64 => Ok(Self::Xe113),
114u64 => Ok(Self::Xe114),
115u64 => Ok(Self::Xe115),
116u64 => Ok(Self::Xe116),
117u64 => Ok(Self::Xe117),
118u64 => Ok(Self::Xe118),
119u64 => Ok(Self::Xe119),
120u64 => Ok(Self::Xe120),
121u64 => Ok(Self::Xe121),
122u64 => Ok(Self::Xe122),
123u64 => Ok(Self::Xe123),
124u64 => Ok(Self::Xe124),
125u64 => Ok(Self::Xe125),
126u64 => Ok(Self::Xe126),
127u64 => Ok(Self::Xe127),
128u64 => Ok(Self::Xe128),
129u64 => Ok(Self::Xe129),
130u64 => Ok(Self::Xe130),
131u64 => Ok(Self::Xe131),
132u64 => Ok(Self::Xe132),
133u64 => Ok(Self::Xe133),
134u64 => Ok(Self::Xe134),
135u64 => Ok(Self::Xe135),
136u64 => Ok(Self::Xe136),
137u64 => Ok(Self::Xe137),
138u64 => Ok(Self::Xe138),
139u64 => Ok(Self::Xe139),
140u64 => Ok(Self::Xe140),
141u64 => Ok(Self::Xe141),
142u64 => Ok(Self::Xe142),
143u64 => Ok(Self::Xe143),
144u64 => Ok(Self::Xe144),
145u64 => Ok(Self::Xe145),
146u64 => Ok(Self::Xe146),
147u64 => Ok(Self::Xe147),
148u64 => Ok(Self::Xe148),
149u64 => Ok(Self::Xe149),
150u64 => Ok(Self::Xe150),
_ => Err(crate::errors::Error::Isotope(crate::Element::Xe, value)),
}
}
}
impl TryFrom<u8> for XenonIsotope {
type Error = crate::errors::Error;
fn try_from(value: u8) -> Result<Self, Self::Error> {
Self::try_from(u64::from(value))
}
}
impl TryFrom<u16> for XenonIsotope {
type Error = crate::errors::Error;
fn try_from(value: u16) -> Result<Self, Self::Error> {
Self::try_from(u64::from(value))
}
}
impl TryFrom<u32> for XenonIsotope {
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 XenonIsotope {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::Xe108 => write!(f, "Xe108"),
Self::Xe109 => write!(f, "Xe109"),
Self::Xe110 => write!(f, "Xe110"),
Self::Xe111 => write!(f, "Xe111"),
Self::Xe112 => write!(f, "Xe112"),
Self::Xe113 => write!(f, "Xe113"),
Self::Xe114 => write!(f, "Xe114"),
Self::Xe115 => write!(f, "Xe115"),
Self::Xe116 => write!(f, "Xe116"),
Self::Xe117 => write!(f, "Xe117"),
Self::Xe118 => write!(f, "Xe118"),
Self::Xe119 => write!(f, "Xe119"),
Self::Xe120 => write!(f, "Xe120"),
Self::Xe121 => write!(f, "Xe121"),
Self::Xe122 => write!(f, "Xe122"),
Self::Xe123 => write!(f, "Xe123"),
Self::Xe124 => write!(f, "Xe124"),
Self::Xe125 => write!(f, "Xe125"),
Self::Xe126 => write!(f, "Xe126"),
Self::Xe127 => write!(f, "Xe127"),
Self::Xe128 => write!(f, "Xe128"),
Self::Xe129 => write!(f, "Xe129"),
Self::Xe130 => write!(f, "Xe130"),
Self::Xe131 => write!(f, "Xe131"),
Self::Xe132 => write!(f, "Xe132"),
Self::Xe133 => write!(f, "Xe133"),
Self::Xe134 => write!(f, "Xe134"),
Self::Xe135 => write!(f, "Xe135"),
Self::Xe136 => write!(f, "Xe136"),
Self::Xe137 => write!(f, "Xe137"),
Self::Xe138 => write!(f, "Xe138"),
Self::Xe139 => write!(f, "Xe139"),
Self::Xe140 => write!(f, "Xe140"),
Self::Xe141 => write!(f, "Xe141"),
Self::Xe142 => write!(f, "Xe142"),
Self::Xe143 => write!(f, "Xe143"),
Self::Xe144 => write!(f, "Xe144"),
Self::Xe145 => write!(f, "Xe145"),
Self::Xe146 => write!(f, "Xe146"),
Self::Xe147 => write!(f, "Xe147"),
Self::Xe148 => write!(f, "Xe148"),
Self::Xe149 => write!(f, "Xe149"),
Self::Xe150 => write!(f, "Xe150"),
}
}
}
#[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 XenonIsotope::iter() {
let mass = isotope.relative_atomic_mass();
assert!(mass > 0.0, "Mass should be positive for {isotope:?}");
}
}
#[test]
fn test_element() {
for isotope in XenonIsotope::iter() {
let element = isotope.element();
assert_eq!(element, crate::Element::Xe, "Element should be correct for {isotope:?}");
}
}
#[test]
fn test_mass_number() {
for isotope in XenonIsotope::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 XenonIsotope::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 = XenonIsotope::most_abundant_isotope();
let _ = most_abundant.relative_atomic_mass();
}
#[test]
fn test_from_isotope() {
for isotope in XenonIsotope::iter() {
let iso: crate::Isotope = isotope.into();
match iso {
crate::Isotope::Xe(i) => assert_eq!(i, isotope),
_ => panic!("Wrong isotope type"),
}
}
}
#[test]
fn test_from_element() {
for isotope in XenonIsotope::iter() {
let elem: crate::Element = isotope.into();
assert_eq!(elem, crate::Element::Xe);
}
}
#[test]
fn test_try_from_mass_number() {
for isotope in XenonIsotope::iter() {
let mass = isotope.mass_number();
let iso = XenonIsotope::try_from(mass).unwrap();
assert_eq!(iso, isotope);
let iso_u32 = XenonIsotope::try_from(u32::from(mass)).unwrap();
assert_eq!(iso_u32, isotope);
if let Ok(mass_u8) = u8::try_from(mass) {
let iso_u8 = XenonIsotope::try_from(mass_u8).unwrap();
assert_eq!(iso_u8, isotope);
}
}
assert!(XenonIsotope::try_from(0_u16).is_err());
assert!(XenonIsotope::try_from(1000_u16).is_err());
assert!(XenonIsotope::try_from(0_u32).is_err());
assert!(XenonIsotope::try_from(1000_u32).is_err());
assert!(XenonIsotope::try_from(0_u8).is_err());
}
#[test]
fn test_display() {
for isotope in XenonIsotope::iter() {
let s = alloc::format!("{isotope}");
assert!(!s.is_empty(), "Display should not be empty for {isotope:?}");
}
}
}