#[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 CobaltIsotope {
Co48,
Co50,
Co51,
Co52,
Co53,
Co54,
Co55,
Co56,
Co57,
Co58,
Co59,
Co60,
Co61,
Co62,
Co63,
Co64,
Co65,
Co66,
Co67,
Co68,
Co69,
Co70,
Co71,
Co72,
Co73,
Co74,
Co75,
Co76,
Co77,
Co78,
}
impl super::RelativeAtomicMass for CobaltIsotope {
#[inline]
fn relative_atomic_mass(&self) -> f64 {
match self {
Self::Co48 => 48.00093f64,
Self::Co50 => 49.98091f64,
Self::Co51 => 50.970647f64,
Self::Co52 => 51.96351f64,
Self::Co53 => 52.9542041f64,
Self::Co54 => 53.94845987f64,
Self::Co55 => 54.9419972f64,
Self::Co56 => 55.9398388f64,
Self::Co57 => 56.93629057f64,
Self::Co58 => 57.9357521f64,
Self::Co59 => 58.93319429f64,
Self::Co60 => 59.9338163f64,
Self::Co61 => 60.93247662f64,
Self::Co62 => 61.934059f64,
Self::Co63 => 62.9336f64,
Self::Co64 => 63.935811f64,
Self::Co65 => 64.9364621f64,
Self::Co66 => 65.939443f64,
Self::Co67 => 66.9406096f64,
Self::Co68 => 67.94426f64,
Self::Co69 => 68.94614f64,
Self::Co70 => 69.94963f64,
Self::Co71 => 70.95237f64,
Self::Co72 => 71.95729f64,
Self::Co73 => 72.96039f64,
Self::Co74 => 73.96515f64,
Self::Co75 => 74.96876f64,
Self::Co76 => 75.97413f64,
Self::Co77 => 76.976479f64,
Self::Co78 => 77.983553f64,
}
}
}
impl super::ElementVariant for CobaltIsotope {
#[inline]
fn element(&self) -> crate::Element {
crate::Element::Co
}
}
impl super::MassNumber for CobaltIsotope {
#[inline]
fn mass_number(&self) -> u16 {
match self {
Self::Co48 => 48u16,
Self::Co50 => 50u16,
Self::Co51 => 51u16,
Self::Co52 => 52u16,
Self::Co53 => 53u16,
Self::Co54 => 54u16,
Self::Co55 => 55u16,
Self::Co56 => 56u16,
Self::Co57 => 57u16,
Self::Co58 => 58u16,
Self::Co59 => 59u16,
Self::Co60 => 60u16,
Self::Co61 => 61u16,
Self::Co62 => 62u16,
Self::Co63 => 63u16,
Self::Co64 => 64u16,
Self::Co65 => 65u16,
Self::Co66 => 66u16,
Self::Co67 => 67u16,
Self::Co68 => 68u16,
Self::Co69 => 69u16,
Self::Co70 => 70u16,
Self::Co71 => 71u16,
Self::Co72 => 72u16,
Self::Co73 => 73u16,
Self::Co74 => 74u16,
Self::Co75 => 75u16,
Self::Co76 => 76u16,
Self::Co77 => 77u16,
Self::Co78 => 78u16,
}
}
}
impl super::IsotopicComposition for CobaltIsotope {
#[inline]
fn isotopic_composition(&self) -> Option<f64> {
match self {
Self::Co59 => Some(1f64),
_ => None,
}
}
}
impl super::MostAbundantIsotope for CobaltIsotope {
fn most_abundant_isotope() -> Self {
Self::Co59
}
}
impl From<CobaltIsotope> for crate::Isotope {
fn from(isotope: CobaltIsotope) -> Self {
crate::Isotope::Co(isotope)
}
}
impl From<CobaltIsotope> for crate::Element {
fn from(_isotope: CobaltIsotope) -> Self {
crate::Element::Co
}
}
impl TryFrom<u64> for CobaltIsotope {
type Error = crate::errors::Error;
fn try_from(value: u64) -> Result<Self, Self::Error> {
match value {
48u64 => Ok(Self::Co48),
50u64 => Ok(Self::Co50),
51u64 => Ok(Self::Co51),
52u64 => Ok(Self::Co52),
53u64 => Ok(Self::Co53),
54u64 => Ok(Self::Co54),
55u64 => Ok(Self::Co55),
56u64 => Ok(Self::Co56),
57u64 => Ok(Self::Co57),
58u64 => Ok(Self::Co58),
59u64 => Ok(Self::Co59),
60u64 => Ok(Self::Co60),
61u64 => Ok(Self::Co61),
62u64 => Ok(Self::Co62),
63u64 => Ok(Self::Co63),
64u64 => Ok(Self::Co64),
65u64 => Ok(Self::Co65),
66u64 => Ok(Self::Co66),
67u64 => Ok(Self::Co67),
68u64 => Ok(Self::Co68),
69u64 => Ok(Self::Co69),
70u64 => Ok(Self::Co70),
71u64 => Ok(Self::Co71),
72u64 => Ok(Self::Co72),
73u64 => Ok(Self::Co73),
74u64 => Ok(Self::Co74),
75u64 => Ok(Self::Co75),
76u64 => Ok(Self::Co76),
77u64 => Ok(Self::Co77),
78u64 => Ok(Self::Co78),
_ => Err(crate::errors::Error::Isotope(crate::Element::Co, value)),
}
}
}
impl TryFrom<u8> for CobaltIsotope {
type Error = crate::errors::Error;
fn try_from(value: u8) -> Result<Self, Self::Error> {
Self::try_from(u64::from(value))
}
}
impl TryFrom<u16> for CobaltIsotope {
type Error = crate::errors::Error;
fn try_from(value: u16) -> Result<Self, Self::Error> {
Self::try_from(u64::from(value))
}
}
impl TryFrom<u32> for CobaltIsotope {
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 CobaltIsotope {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::Co48 => write!(f, "Co48"),
Self::Co50 => write!(f, "Co50"),
Self::Co51 => write!(f, "Co51"),
Self::Co52 => write!(f, "Co52"),
Self::Co53 => write!(f, "Co53"),
Self::Co54 => write!(f, "Co54"),
Self::Co55 => write!(f, "Co55"),
Self::Co56 => write!(f, "Co56"),
Self::Co57 => write!(f, "Co57"),
Self::Co58 => write!(f, "Co58"),
Self::Co59 => write!(f, "Co59"),
Self::Co60 => write!(f, "Co60"),
Self::Co61 => write!(f, "Co61"),
Self::Co62 => write!(f, "Co62"),
Self::Co63 => write!(f, "Co63"),
Self::Co64 => write!(f, "Co64"),
Self::Co65 => write!(f, "Co65"),
Self::Co66 => write!(f, "Co66"),
Self::Co67 => write!(f, "Co67"),
Self::Co68 => write!(f, "Co68"),
Self::Co69 => write!(f, "Co69"),
Self::Co70 => write!(f, "Co70"),
Self::Co71 => write!(f, "Co71"),
Self::Co72 => write!(f, "Co72"),
Self::Co73 => write!(f, "Co73"),
Self::Co74 => write!(f, "Co74"),
Self::Co75 => write!(f, "Co75"),
Self::Co76 => write!(f, "Co76"),
Self::Co77 => write!(f, "Co77"),
Self::Co78 => write!(f, "Co78"),
}
}
}
#[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 CobaltIsotope::iter() {
let mass = isotope.relative_atomic_mass();
assert!(mass > 0.0, "Mass should be positive for {isotope:?}");
}
}
#[test]
fn test_element() {
for isotope in CobaltIsotope::iter() {
let element = isotope.element();
assert_eq!(element, crate::Element::Co, "Element should be correct for {isotope:?}");
}
}
#[test]
fn test_mass_number() {
for isotope in CobaltIsotope::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 CobaltIsotope::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 = CobaltIsotope::most_abundant_isotope();
let _ = most_abundant.relative_atomic_mass();
}
#[test]
fn test_from_isotope() {
for isotope in CobaltIsotope::iter() {
let iso: crate::Isotope = isotope.into();
match iso {
crate::Isotope::Co(i) => assert_eq!(i, isotope),
_ => panic!("Wrong isotope type"),
}
}
}
#[test]
fn test_from_element() {
for isotope in CobaltIsotope::iter() {
let elem: crate::Element = isotope.into();
assert_eq!(elem, crate::Element::Co);
}
}
#[test]
fn test_try_from_mass_number() {
for isotope in CobaltIsotope::iter() {
let mass = isotope.mass_number();
let iso = CobaltIsotope::try_from(mass).unwrap();
assert_eq!(iso, isotope);
let iso_u32 = CobaltIsotope::try_from(u32::from(mass)).unwrap();
assert_eq!(iso_u32, isotope);
if let Ok(mass_u8) = u8::try_from(mass) {
let iso_u8 = CobaltIsotope::try_from(mass_u8).unwrap();
assert_eq!(iso_u8, isotope);
}
}
assert!(CobaltIsotope::try_from(0_u16).is_err());
assert!(CobaltIsotope::try_from(1000_u16).is_err());
assert!(CobaltIsotope::try_from(0_u32).is_err());
assert!(CobaltIsotope::try_from(1000_u32).is_err());
assert!(CobaltIsotope::try_from(0_u8).is_err());
}
#[test]
fn test_display() {
for isotope in CobaltIsotope::iter() {
let s = alloc::format!("{isotope}");
assert!(!s.is_empty(), "Display should not be empty for {isotope:?}");
}
}
}