#[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 ThalliumIsotope {
Tl176,
Tl177,
Tl178,
Tl179,
Tl180,
Tl181,
Tl182,
Tl183,
Tl184,
Tl185,
Tl186,
Tl187,
Tl188,
Tl189,
Tl190,
Tl191,
Tl192,
Tl193,
Tl194,
Tl195,
Tl196,
Tl197,
Tl198,
Tl199,
Tl200,
Tl201,
Tl202,
Tl203,
Tl204,
Tl205,
Tl206,
Tl207,
Tl208,
Tl209,
Tl210,
Tl211,
Tl212,
Tl213,
Tl214,
Tl215,
Tl216,
Tl217,
}
impl super::RelativeAtomicMass for ThalliumIsotope {
#[inline]
fn relative_atomic_mass(&self) -> f64 {
match self {
Self::Tl176 => 176.000624f64,
Self::Tl177 => 176.996431f64,
Self::Tl178 => 177.99485f64,
Self::Tl179 => 178.991111f64,
Self::Tl180 => 179.990057f64,
Self::Tl181 => 180.98626f64,
Self::Tl182 => 181.985713f64,
Self::Tl183 => 182.982193f64,
Self::Tl184 => 183.981886f64,
Self::Tl185 => 184.978789f64,
Self::Tl186 => 185.978651f64,
Self::Tl187 => 186.9759063f64,
Self::Tl188 => 187.976021f64,
Self::Tl189 => 188.973588f64,
Self::Tl190 => 189.973828f64,
Self::Tl191 => 190.9717842f64,
Self::Tl192 => 191.972225f64,
Self::Tl193 => 192.970502f64,
Self::Tl194 => 193.971081f64,
Self::Tl195 => 194.969774f64,
Self::Tl196 => 195.970481f64,
Self::Tl197 => 196.969576f64,
Self::Tl198 => 197.970483f64,
Self::Tl199 => 198.969877f64,
Self::Tl200 => 199.9709633f64,
Self::Tl201 => 200.970822f64,
Self::Tl202 => 201.972102f64,
Self::Tl203 => 202.9723446f64,
Self::Tl204 => 203.9738639f64,
Self::Tl205 => 204.9744278f64,
Self::Tl206 => 205.9761106f64,
Self::Tl207 => 206.9774197f64,
Self::Tl208 => 207.982019f64,
Self::Tl209 => 208.9853594f64,
Self::Tl210 => 209.990074f64,
Self::Tl211 => 210.993475f64,
Self::Tl212 => 211.99834f64,
Self::Tl213 => 213.001915f64,
Self::Tl214 => 214.00694f64,
Self::Tl215 => 215.01064f64,
Self::Tl216 => 216.0158f64,
Self::Tl217 => 217.01966f64,
}
}
}
impl super::ElementVariant for ThalliumIsotope {
#[inline]
fn element(&self) -> crate::Element {
crate::Element::Tl
}
}
impl super::MassNumber for ThalliumIsotope {
#[inline]
fn mass_number(&self) -> u16 {
match self {
Self::Tl176 => 176u16,
Self::Tl177 => 177u16,
Self::Tl178 => 178u16,
Self::Tl179 => 179u16,
Self::Tl180 => 180u16,
Self::Tl181 => 181u16,
Self::Tl182 => 182u16,
Self::Tl183 => 183u16,
Self::Tl184 => 184u16,
Self::Tl185 => 185u16,
Self::Tl186 => 186u16,
Self::Tl187 => 187u16,
Self::Tl188 => 188u16,
Self::Tl189 => 189u16,
Self::Tl190 => 190u16,
Self::Tl191 => 191u16,
Self::Tl192 => 192u16,
Self::Tl193 => 193u16,
Self::Tl194 => 194u16,
Self::Tl195 => 195u16,
Self::Tl196 => 196u16,
Self::Tl197 => 197u16,
Self::Tl198 => 198u16,
Self::Tl199 => 199u16,
Self::Tl200 => 200u16,
Self::Tl201 => 201u16,
Self::Tl202 => 202u16,
Self::Tl203 => 203u16,
Self::Tl204 => 204u16,
Self::Tl205 => 205u16,
Self::Tl206 => 206u16,
Self::Tl207 => 207u16,
Self::Tl208 => 208u16,
Self::Tl209 => 209u16,
Self::Tl210 => 210u16,
Self::Tl211 => 211u16,
Self::Tl212 => 212u16,
Self::Tl213 => 213u16,
Self::Tl214 => 214u16,
Self::Tl215 => 215u16,
Self::Tl216 => 216u16,
Self::Tl217 => 217u16,
}
}
}
impl super::IsotopicComposition for ThalliumIsotope {
#[inline]
fn isotopic_composition(&self) -> Option<f64> {
match self {
Self::Tl203 => Some(0.2952f64),
Self::Tl205 => Some(0.7048f64),
_ => None,
}
}
}
impl super::MostAbundantIsotope for ThalliumIsotope {
fn most_abundant_isotope() -> Self {
Self::Tl205
}
}
impl From<ThalliumIsotope> for crate::Isotope {
fn from(isotope: ThalliumIsotope) -> Self {
crate::Isotope::Tl(isotope)
}
}
impl From<ThalliumIsotope> for crate::Element {
fn from(_isotope: ThalliumIsotope) -> Self {
crate::Element::Tl
}
}
impl TryFrom<u64> for ThalliumIsotope {
type Error = crate::errors::Error;
fn try_from(value: u64) -> Result<Self, Self::Error> {
match value {
176u64 => Ok(Self::Tl176),
177u64 => Ok(Self::Tl177),
178u64 => Ok(Self::Tl178),
179u64 => Ok(Self::Tl179),
180u64 => Ok(Self::Tl180),
181u64 => Ok(Self::Tl181),
182u64 => Ok(Self::Tl182),
183u64 => Ok(Self::Tl183),
184u64 => Ok(Self::Tl184),
185u64 => Ok(Self::Tl185),
186u64 => Ok(Self::Tl186),
187u64 => Ok(Self::Tl187),
188u64 => Ok(Self::Tl188),
189u64 => Ok(Self::Tl189),
190u64 => Ok(Self::Tl190),
191u64 => Ok(Self::Tl191),
192u64 => Ok(Self::Tl192),
193u64 => Ok(Self::Tl193),
194u64 => Ok(Self::Tl194),
195u64 => Ok(Self::Tl195),
196u64 => Ok(Self::Tl196),
197u64 => Ok(Self::Tl197),
198u64 => Ok(Self::Tl198),
199u64 => Ok(Self::Tl199),
200u64 => Ok(Self::Tl200),
201u64 => Ok(Self::Tl201),
202u64 => Ok(Self::Tl202),
203u64 => Ok(Self::Tl203),
204u64 => Ok(Self::Tl204),
205u64 => Ok(Self::Tl205),
206u64 => Ok(Self::Tl206),
207u64 => Ok(Self::Tl207),
208u64 => Ok(Self::Tl208),
209u64 => Ok(Self::Tl209),
210u64 => Ok(Self::Tl210),
211u64 => Ok(Self::Tl211),
212u64 => Ok(Self::Tl212),
213u64 => Ok(Self::Tl213),
214u64 => Ok(Self::Tl214),
215u64 => Ok(Self::Tl215),
216u64 => Ok(Self::Tl216),
217u64 => Ok(Self::Tl217),
_ => Err(crate::errors::Error::Isotope(crate::Element::Tl, value)),
}
}
}
impl TryFrom<u8> for ThalliumIsotope {
type Error = crate::errors::Error;
fn try_from(value: u8) -> Result<Self, Self::Error> {
Self::try_from(u64::from(value))
}
}
impl TryFrom<u16> for ThalliumIsotope {
type Error = crate::errors::Error;
fn try_from(value: u16) -> Result<Self, Self::Error> {
Self::try_from(u64::from(value))
}
}
impl TryFrom<u32> for ThalliumIsotope {
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 ThalliumIsotope {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::Tl176 => write!(f, "Tl176"),
Self::Tl177 => write!(f, "Tl177"),
Self::Tl178 => write!(f, "Tl178"),
Self::Tl179 => write!(f, "Tl179"),
Self::Tl180 => write!(f, "Tl180"),
Self::Tl181 => write!(f, "Tl181"),
Self::Tl182 => write!(f, "Tl182"),
Self::Tl183 => write!(f, "Tl183"),
Self::Tl184 => write!(f, "Tl184"),
Self::Tl185 => write!(f, "Tl185"),
Self::Tl186 => write!(f, "Tl186"),
Self::Tl187 => write!(f, "Tl187"),
Self::Tl188 => write!(f, "Tl188"),
Self::Tl189 => write!(f, "Tl189"),
Self::Tl190 => write!(f, "Tl190"),
Self::Tl191 => write!(f, "Tl191"),
Self::Tl192 => write!(f, "Tl192"),
Self::Tl193 => write!(f, "Tl193"),
Self::Tl194 => write!(f, "Tl194"),
Self::Tl195 => write!(f, "Tl195"),
Self::Tl196 => write!(f, "Tl196"),
Self::Tl197 => write!(f, "Tl197"),
Self::Tl198 => write!(f, "Tl198"),
Self::Tl199 => write!(f, "Tl199"),
Self::Tl200 => write!(f, "Tl200"),
Self::Tl201 => write!(f, "Tl201"),
Self::Tl202 => write!(f, "Tl202"),
Self::Tl203 => write!(f, "Tl203"),
Self::Tl204 => write!(f, "Tl204"),
Self::Tl205 => write!(f, "Tl205"),
Self::Tl206 => write!(f, "Tl206"),
Self::Tl207 => write!(f, "Tl207"),
Self::Tl208 => write!(f, "Tl208"),
Self::Tl209 => write!(f, "Tl209"),
Self::Tl210 => write!(f, "Tl210"),
Self::Tl211 => write!(f, "Tl211"),
Self::Tl212 => write!(f, "Tl212"),
Self::Tl213 => write!(f, "Tl213"),
Self::Tl214 => write!(f, "Tl214"),
Self::Tl215 => write!(f, "Tl215"),
Self::Tl216 => write!(f, "Tl216"),
Self::Tl217 => write!(f, "Tl217"),
}
}
}
#[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 ThalliumIsotope::iter() {
let mass = isotope.relative_atomic_mass();
assert!(mass > 0.0, "Mass should be positive for {isotope:?}");
}
}
#[test]
fn test_element() {
for isotope in ThalliumIsotope::iter() {
let element = isotope.element();
assert_eq!(element, crate::Element::Tl, "Element should be correct for {isotope:?}");
}
}
#[test]
fn test_mass_number() {
for isotope in ThalliumIsotope::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 ThalliumIsotope::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 = ThalliumIsotope::most_abundant_isotope();
let _ = most_abundant.relative_atomic_mass();
}
#[test]
fn test_from_isotope() {
for isotope in ThalliumIsotope::iter() {
let iso: crate::Isotope = isotope.into();
match iso {
crate::Isotope::Tl(i) => assert_eq!(i, isotope),
_ => panic!("Wrong isotope type"),
}
}
}
#[test]
fn test_from_element() {
for isotope in ThalliumIsotope::iter() {
let elem: crate::Element = isotope.into();
assert_eq!(elem, crate::Element::Tl);
}
}
#[test]
fn test_try_from_mass_number() {
for isotope in ThalliumIsotope::iter() {
let mass = isotope.mass_number();
let iso = ThalliumIsotope::try_from(mass).unwrap();
assert_eq!(iso, isotope);
let iso_u32 = ThalliumIsotope::try_from(u32::from(mass)).unwrap();
assert_eq!(iso_u32, isotope);
if let Ok(mass_u8) = u8::try_from(mass) {
let iso_u8 = ThalliumIsotope::try_from(mass_u8).unwrap();
assert_eq!(iso_u8, isotope);
}
}
assert!(ThalliumIsotope::try_from(0_u16).is_err());
assert!(ThalliumIsotope::try_from(1000_u16).is_err());
assert!(ThalliumIsotope::try_from(0_u32).is_err());
assert!(ThalliumIsotope::try_from(1000_u32).is_err());
assert!(ThalliumIsotope::try_from(0_u8).is_err());
}
#[test]
fn test_display() {
for isotope in ThalliumIsotope::iter() {
let s = alloc::format!("{isotope}");
assert!(!s.is_empty(), "Display should not be empty for {isotope:?}");
}
}
}