#[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 CadmiumIsotope {
Cd94,
Cd95,
Cd96,
Cd97,
Cd98,
Cd99,
Cd100,
Cd101,
Cd102,
Cd103,
Cd104,
Cd105,
Cd106,
Cd107,
Cd108,
Cd109,
Cd110,
Cd111,
Cd112,
Cd113,
Cd114,
Cd115,
Cd116,
Cd117,
Cd118,
Cd119,
Cd120,
Cd121,
Cd122,
Cd123,
Cd124,
Cd125,
Cd126,
Cd127,
Cd128,
Cd129,
Cd130,
Cd131,
Cd132,
Cd133,
Cd134,
}
impl super::RelativeAtomicMass for CadmiumIsotope {
#[inline]
fn relative_atomic_mass(&self) -> f64 {
match self {
Self::Cd94 => 93.956586f64,
Self::Cd95 => 94.94994f64,
Self::Cd96 => 95.94034f64,
Self::Cd97 => 96.9351f64,
Self::Cd98 => 97.927389f64,
Self::Cd99 => 98.9249258f64,
Self::Cd100 => 99.9203488f64,
Self::Cd101 => 100.9185862f64,
Self::Cd102 => 101.914482f64,
Self::Cd103 => 102.9134165f64,
Self::Cd104 => 103.9098564f64,
Self::Cd105 => 104.9094639f64,
Self::Cd106 => 105.9064599f64,
Self::Cd107 => 106.9066121f64,
Self::Cd108 => 107.9041834f64,
Self::Cd109 => 108.9049867f64,
Self::Cd110 => 109.90300661f64,
Self::Cd111 => 110.90418287f64,
Self::Cd112 => 111.90276287f64,
Self::Cd113 => 112.90440813f64,
Self::Cd114 => 113.90336509f64,
Self::Cd115 => 114.90543751f64,
Self::Cd116 => 115.90476315f64,
Self::Cd117 => 116.907226f64,
Self::Cd118 => 117.906922f64,
Self::Cd119 => 118.909847f64,
Self::Cd120 => 119.9098681f64,
Self::Cd121 => 120.9129637f64,
Self::Cd122 => 121.9134591f64,
Self::Cd123 => 122.9168925f64,
Self::Cd124 => 123.9176574f64,
Self::Cd125 => 124.9212576f64,
Self::Cd126 => 125.9224291f64,
Self::Cd127 => 126.926472f64,
Self::Cd128 => 127.9278129f64,
Self::Cd129 => 128.93182f64,
Self::Cd130 => 129.93394f64,
Self::Cd131 => 130.9406f64,
Self::Cd132 => 131.94604f64,
Self::Cd133 => 132.95285f64,
Self::Cd134 => 133.957638f64,
}
}
}
impl super::ElementVariant for CadmiumIsotope {
#[inline]
fn element(&self) -> crate::Element {
crate::Element::Cd
}
}
impl super::MassNumber for CadmiumIsotope {
#[inline]
fn mass_number(&self) -> u16 {
match self {
Self::Cd94 => 94u16,
Self::Cd95 => 95u16,
Self::Cd96 => 96u16,
Self::Cd97 => 97u16,
Self::Cd98 => 98u16,
Self::Cd99 => 99u16,
Self::Cd100 => 100u16,
Self::Cd101 => 101u16,
Self::Cd102 => 102u16,
Self::Cd103 => 103u16,
Self::Cd104 => 104u16,
Self::Cd105 => 105u16,
Self::Cd106 => 106u16,
Self::Cd107 => 107u16,
Self::Cd108 => 108u16,
Self::Cd109 => 109u16,
Self::Cd110 => 110u16,
Self::Cd111 => 111u16,
Self::Cd112 => 112u16,
Self::Cd113 => 113u16,
Self::Cd114 => 114u16,
Self::Cd115 => 115u16,
Self::Cd116 => 116u16,
Self::Cd117 => 117u16,
Self::Cd118 => 118u16,
Self::Cd119 => 119u16,
Self::Cd120 => 120u16,
Self::Cd121 => 121u16,
Self::Cd122 => 122u16,
Self::Cd123 => 123u16,
Self::Cd124 => 124u16,
Self::Cd125 => 125u16,
Self::Cd126 => 126u16,
Self::Cd127 => 127u16,
Self::Cd128 => 128u16,
Self::Cd129 => 129u16,
Self::Cd130 => 130u16,
Self::Cd131 => 131u16,
Self::Cd132 => 132u16,
Self::Cd133 => 133u16,
Self::Cd134 => 134u16,
}
}
}
impl super::IsotopicComposition for CadmiumIsotope {
#[inline]
fn isotopic_composition(&self) -> Option<f64> {
match self {
Self::Cd106 => Some(0.0125f64),
Self::Cd108 => Some(0.0089f64),
Self::Cd110 => Some(0.1249f64),
Self::Cd111 => Some(0.128f64),
Self::Cd112 => Some(0.2413f64),
Self::Cd113 => Some(0.1222f64),
Self::Cd114 => Some(0.2873f64),
Self::Cd116 => Some(0.0749f64),
_ => None,
}
}
}
impl super::MostAbundantIsotope for CadmiumIsotope {
fn most_abundant_isotope() -> Self {
Self::Cd114
}
}
impl From<CadmiumIsotope> for crate::Isotope {
fn from(isotope: CadmiumIsotope) -> Self {
crate::Isotope::Cd(isotope)
}
}
impl From<CadmiumIsotope> for crate::Element {
fn from(_isotope: CadmiumIsotope) -> Self {
crate::Element::Cd
}
}
impl TryFrom<u64> for CadmiumIsotope {
type Error = crate::errors::Error;
fn try_from(value: u64) -> Result<Self, Self::Error> {
match value {
94u64 => Ok(Self::Cd94),
95u64 => Ok(Self::Cd95),
96u64 => Ok(Self::Cd96),
97u64 => Ok(Self::Cd97),
98u64 => Ok(Self::Cd98),
99u64 => Ok(Self::Cd99),
100u64 => Ok(Self::Cd100),
101u64 => Ok(Self::Cd101),
102u64 => Ok(Self::Cd102),
103u64 => Ok(Self::Cd103),
104u64 => Ok(Self::Cd104),
105u64 => Ok(Self::Cd105),
106u64 => Ok(Self::Cd106),
107u64 => Ok(Self::Cd107),
108u64 => Ok(Self::Cd108),
109u64 => Ok(Self::Cd109),
110u64 => Ok(Self::Cd110),
111u64 => Ok(Self::Cd111),
112u64 => Ok(Self::Cd112),
113u64 => Ok(Self::Cd113),
114u64 => Ok(Self::Cd114),
115u64 => Ok(Self::Cd115),
116u64 => Ok(Self::Cd116),
117u64 => Ok(Self::Cd117),
118u64 => Ok(Self::Cd118),
119u64 => Ok(Self::Cd119),
120u64 => Ok(Self::Cd120),
121u64 => Ok(Self::Cd121),
122u64 => Ok(Self::Cd122),
123u64 => Ok(Self::Cd123),
124u64 => Ok(Self::Cd124),
125u64 => Ok(Self::Cd125),
126u64 => Ok(Self::Cd126),
127u64 => Ok(Self::Cd127),
128u64 => Ok(Self::Cd128),
129u64 => Ok(Self::Cd129),
130u64 => Ok(Self::Cd130),
131u64 => Ok(Self::Cd131),
132u64 => Ok(Self::Cd132),
133u64 => Ok(Self::Cd133),
134u64 => Ok(Self::Cd134),
_ => Err(crate::errors::Error::Isotope(crate::Element::Cd, value)),
}
}
}
impl TryFrom<u8> for CadmiumIsotope {
type Error = crate::errors::Error;
fn try_from(value: u8) -> Result<Self, Self::Error> {
Self::try_from(u64::from(value))
}
}
impl TryFrom<u16> for CadmiumIsotope {
type Error = crate::errors::Error;
fn try_from(value: u16) -> Result<Self, Self::Error> {
Self::try_from(u64::from(value))
}
}
impl TryFrom<u32> for CadmiumIsotope {
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 CadmiumIsotope {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::Cd94 => write!(f, "Cd94"),
Self::Cd95 => write!(f, "Cd95"),
Self::Cd96 => write!(f, "Cd96"),
Self::Cd97 => write!(f, "Cd97"),
Self::Cd98 => write!(f, "Cd98"),
Self::Cd99 => write!(f, "Cd99"),
Self::Cd100 => write!(f, "Cd100"),
Self::Cd101 => write!(f, "Cd101"),
Self::Cd102 => write!(f, "Cd102"),
Self::Cd103 => write!(f, "Cd103"),
Self::Cd104 => write!(f, "Cd104"),
Self::Cd105 => write!(f, "Cd105"),
Self::Cd106 => write!(f, "Cd106"),
Self::Cd107 => write!(f, "Cd107"),
Self::Cd108 => write!(f, "Cd108"),
Self::Cd109 => write!(f, "Cd109"),
Self::Cd110 => write!(f, "Cd110"),
Self::Cd111 => write!(f, "Cd111"),
Self::Cd112 => write!(f, "Cd112"),
Self::Cd113 => write!(f, "Cd113"),
Self::Cd114 => write!(f, "Cd114"),
Self::Cd115 => write!(f, "Cd115"),
Self::Cd116 => write!(f, "Cd116"),
Self::Cd117 => write!(f, "Cd117"),
Self::Cd118 => write!(f, "Cd118"),
Self::Cd119 => write!(f, "Cd119"),
Self::Cd120 => write!(f, "Cd120"),
Self::Cd121 => write!(f, "Cd121"),
Self::Cd122 => write!(f, "Cd122"),
Self::Cd123 => write!(f, "Cd123"),
Self::Cd124 => write!(f, "Cd124"),
Self::Cd125 => write!(f, "Cd125"),
Self::Cd126 => write!(f, "Cd126"),
Self::Cd127 => write!(f, "Cd127"),
Self::Cd128 => write!(f, "Cd128"),
Self::Cd129 => write!(f, "Cd129"),
Self::Cd130 => write!(f, "Cd130"),
Self::Cd131 => write!(f, "Cd131"),
Self::Cd132 => write!(f, "Cd132"),
Self::Cd133 => write!(f, "Cd133"),
Self::Cd134 => write!(f, "Cd134"),
}
}
}
#[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 CadmiumIsotope::iter() {
let mass = isotope.relative_atomic_mass();
assert!(mass > 0.0, "Mass should be positive for {isotope:?}");
}
}
#[test]
fn test_element() {
for isotope in CadmiumIsotope::iter() {
let element = isotope.element();
assert_eq!(element, crate::Element::Cd, "Element should be correct for {isotope:?}");
}
}
#[test]
fn test_mass_number() {
for isotope in CadmiumIsotope::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 CadmiumIsotope::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 = CadmiumIsotope::most_abundant_isotope();
let _ = most_abundant.relative_atomic_mass();
}
#[test]
fn test_from_isotope() {
for isotope in CadmiumIsotope::iter() {
let iso: crate::Isotope = isotope.into();
match iso {
crate::Isotope::Cd(i) => assert_eq!(i, isotope),
_ => panic!("Wrong isotope type"),
}
}
}
#[test]
fn test_from_element() {
for isotope in CadmiumIsotope::iter() {
let elem: crate::Element = isotope.into();
assert_eq!(elem, crate::Element::Cd);
}
}
#[test]
fn test_try_from_mass_number() {
for isotope in CadmiumIsotope::iter() {
let mass = isotope.mass_number();
let iso = CadmiumIsotope::try_from(mass).unwrap();
assert_eq!(iso, isotope);
let iso_u32 = CadmiumIsotope::try_from(u32::from(mass)).unwrap();
assert_eq!(iso_u32, isotope);
if let Ok(mass_u8) = u8::try_from(mass) {
let iso_u8 = CadmiumIsotope::try_from(mass_u8).unwrap();
assert_eq!(iso_u8, isotope);
}
}
assert!(CadmiumIsotope::try_from(0_u16).is_err());
assert!(CadmiumIsotope::try_from(1000_u16).is_err());
assert!(CadmiumIsotope::try_from(0_u32).is_err());
assert!(CadmiumIsotope::try_from(1000_u32).is_err());
assert!(CadmiumIsotope::try_from(0_u8).is_err());
}
#[test]
fn test_display() {
for isotope in CadmiumIsotope::iter() {
let s = alloc::format!("{isotope}");
assert!(!s.is_empty(), "Display should not be empty for {isotope:?}");
}
}
}