#[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))]
#[cfg_attr(feature = "mem_size", derive(mem_dbg::MemSize))]
#[cfg_attr(feature = "mem_dbg", derive(mem_dbg::MemDbg))]
#[cfg_attr(feature = "mem_size", mem_size(flat))]
pub enum GermaniumIsotope {
Ge59,
Ge60,
Ge61,
Ge62,
Ge63,
Ge64,
Ge65,
Ge66,
Ge67,
Ge68,
Ge69,
Ge70,
Ge71,
Ge72,
Ge73,
Ge74,
Ge75,
Ge76,
Ge77,
Ge78,
Ge79,
Ge80,
Ge81,
Ge82,
Ge83,
Ge84,
Ge85,
Ge86,
Ge87,
Ge88,
Ge89,
Ge90,
}
impl super::RelativeAtomicMass for GermaniumIsotope {
#[inline]
fn relative_atomic_mass(&self) -> f64 {
match self {
Self::Ge59 => 58.98249f64,
Self::Ge60 => 59.97036f64,
Self::Ge61 => 60.96379f64,
Self::Ge62 => 61.95502f64,
Self::Ge63 => 62.949628f64,
Self::Ge64 => 63.9416899f64,
Self::Ge65 => 64.9393681f64,
Self::Ge66 => 65.9338621f64,
Self::Ge67 => 66.9327339f64,
Self::Ge68 => 67.9280953f64,
Self::Ge69 => 68.9279645f64,
Self::Ge70 => 69.92424875f64,
Self::Ge71 => 70.92495233f64,
Self::Ge72 => 71.922075826f64,
Self::Ge73 => 72.923458956f64,
Self::Ge74 => 73.921177761f64,
Self::Ge75 => 74.92285837f64,
Self::Ge76 => 75.921402726f64,
Self::Ge77 => 76.923549843f64,
Self::Ge78 => 77.9228529f64,
Self::Ge79 => 78.92536f64,
Self::Ge80 => 79.9253508f64,
Self::Ge81 => 80.9288329f64,
Self::Ge82 => 81.929774f64,
Self::Ge83 => 82.9345391f64,
Self::Ge84 => 83.9375751f64,
Self::Ge85 => 84.9429697f64,
Self::Ge86 => 85.94658f64,
Self::Ge87 => 86.95268f64,
Self::Ge88 => 87.95691f64,
Self::Ge89 => 88.96379f64,
Self::Ge90 => 89.96863f64,
}
}
}
impl super::ElementVariant for GermaniumIsotope {
#[inline]
fn element(&self) -> crate::Element {
crate::Element::Ge
}
}
impl super::MassNumber for GermaniumIsotope {
#[inline]
fn mass_number(&self) -> u16 {
match self {
Self::Ge59 => 59u16,
Self::Ge60 => 60u16,
Self::Ge61 => 61u16,
Self::Ge62 => 62u16,
Self::Ge63 => 63u16,
Self::Ge64 => 64u16,
Self::Ge65 => 65u16,
Self::Ge66 => 66u16,
Self::Ge67 => 67u16,
Self::Ge68 => 68u16,
Self::Ge69 => 69u16,
Self::Ge70 => 70u16,
Self::Ge71 => 71u16,
Self::Ge72 => 72u16,
Self::Ge73 => 73u16,
Self::Ge74 => 74u16,
Self::Ge75 => 75u16,
Self::Ge76 => 76u16,
Self::Ge77 => 77u16,
Self::Ge78 => 78u16,
Self::Ge79 => 79u16,
Self::Ge80 => 80u16,
Self::Ge81 => 81u16,
Self::Ge82 => 82u16,
Self::Ge83 => 83u16,
Self::Ge84 => 84u16,
Self::Ge85 => 85u16,
Self::Ge86 => 86u16,
Self::Ge87 => 87u16,
Self::Ge88 => 88u16,
Self::Ge89 => 89u16,
Self::Ge90 => 90u16,
}
}
}
impl super::IsotopicComposition for GermaniumIsotope {
#[inline]
fn isotopic_composition(&self) -> Option<f64> {
match self {
Self::Ge70 => Some(0.2057f64),
Self::Ge72 => Some(0.2745f64),
Self::Ge73 => Some(0.0775f64),
Self::Ge74 => Some(0.365f64),
Self::Ge76 => Some(0.0773f64),
_ => None,
}
}
}
impl super::MostAbundantIsotope for GermaniumIsotope {
fn most_abundant_isotope() -> Self {
Self::Ge74
}
}
impl From<GermaniumIsotope> for crate::Isotope {
fn from(isotope: GermaniumIsotope) -> Self {
crate::Isotope::Ge(isotope)
}
}
impl From<GermaniumIsotope> for crate::Element {
fn from(_isotope: GermaniumIsotope) -> Self {
crate::Element::Ge
}
}
impl TryFrom<u64> for GermaniumIsotope {
type Error = crate::errors::Error;
fn try_from(value: u64) -> Result<Self, Self::Error> {
match value {
59u64 => Ok(Self::Ge59),
60u64 => Ok(Self::Ge60),
61u64 => Ok(Self::Ge61),
62u64 => Ok(Self::Ge62),
63u64 => Ok(Self::Ge63),
64u64 => Ok(Self::Ge64),
65u64 => Ok(Self::Ge65),
66u64 => Ok(Self::Ge66),
67u64 => Ok(Self::Ge67),
68u64 => Ok(Self::Ge68),
69u64 => Ok(Self::Ge69),
70u64 => Ok(Self::Ge70),
71u64 => Ok(Self::Ge71),
72u64 => Ok(Self::Ge72),
73u64 => Ok(Self::Ge73),
74u64 => Ok(Self::Ge74),
75u64 => Ok(Self::Ge75),
76u64 => Ok(Self::Ge76),
77u64 => Ok(Self::Ge77),
78u64 => Ok(Self::Ge78),
79u64 => Ok(Self::Ge79),
80u64 => Ok(Self::Ge80),
81u64 => Ok(Self::Ge81),
82u64 => Ok(Self::Ge82),
83u64 => Ok(Self::Ge83),
84u64 => Ok(Self::Ge84),
85u64 => Ok(Self::Ge85),
86u64 => Ok(Self::Ge86),
87u64 => Ok(Self::Ge87),
88u64 => Ok(Self::Ge88),
89u64 => Ok(Self::Ge89),
90u64 => Ok(Self::Ge90),
_ => Err(crate::errors::Error::Isotope(crate::Element::Ge, value)),
}
}
}
impl TryFrom<u8> for GermaniumIsotope {
type Error = crate::errors::Error;
fn try_from(value: u8) -> Result<Self, Self::Error> {
Self::try_from(u64::from(value))
}
}
impl TryFrom<u16> for GermaniumIsotope {
type Error = crate::errors::Error;
fn try_from(value: u16) -> Result<Self, Self::Error> {
Self::try_from(u64::from(value))
}
}
impl TryFrom<u32> for GermaniumIsotope {
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 GermaniumIsotope {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::Ge59 => write!(f, "Ge59"),
Self::Ge60 => write!(f, "Ge60"),
Self::Ge61 => write!(f, "Ge61"),
Self::Ge62 => write!(f, "Ge62"),
Self::Ge63 => write!(f, "Ge63"),
Self::Ge64 => write!(f, "Ge64"),
Self::Ge65 => write!(f, "Ge65"),
Self::Ge66 => write!(f, "Ge66"),
Self::Ge67 => write!(f, "Ge67"),
Self::Ge68 => write!(f, "Ge68"),
Self::Ge69 => write!(f, "Ge69"),
Self::Ge70 => write!(f, "Ge70"),
Self::Ge71 => write!(f, "Ge71"),
Self::Ge72 => write!(f, "Ge72"),
Self::Ge73 => write!(f, "Ge73"),
Self::Ge74 => write!(f, "Ge74"),
Self::Ge75 => write!(f, "Ge75"),
Self::Ge76 => write!(f, "Ge76"),
Self::Ge77 => write!(f, "Ge77"),
Self::Ge78 => write!(f, "Ge78"),
Self::Ge79 => write!(f, "Ge79"),
Self::Ge80 => write!(f, "Ge80"),
Self::Ge81 => write!(f, "Ge81"),
Self::Ge82 => write!(f, "Ge82"),
Self::Ge83 => write!(f, "Ge83"),
Self::Ge84 => write!(f, "Ge84"),
Self::Ge85 => write!(f, "Ge85"),
Self::Ge86 => write!(f, "Ge86"),
Self::Ge87 => write!(f, "Ge87"),
Self::Ge88 => write!(f, "Ge88"),
Self::Ge89 => write!(f, "Ge89"),
Self::Ge90 => write!(f, "Ge90"),
}
}
}
#[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 GermaniumIsotope::iter() {
let mass = isotope.relative_atomic_mass();
assert!(mass > 0.0, "Mass should be positive for {isotope:?}");
}
}
#[test]
fn test_element() {
for isotope in GermaniumIsotope::iter() {
let element = isotope.element();
assert_eq!(element, crate::Element::Ge, "Element should be correct for {isotope:?}");
}
}
#[test]
fn test_mass_number() {
for isotope in GermaniumIsotope::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 GermaniumIsotope::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 = GermaniumIsotope::most_abundant_isotope();
let _ = most_abundant.relative_atomic_mass();
}
#[test]
fn test_from_isotope() {
for isotope in GermaniumIsotope::iter() {
let iso: crate::Isotope = isotope.into();
match iso {
crate::Isotope::Ge(i) => assert_eq!(i, isotope),
_ => panic!("Wrong isotope type"),
}
}
}
#[test]
fn test_from_element() {
for isotope in GermaniumIsotope::iter() {
let elem: crate::Element = isotope.into();
assert_eq!(elem, crate::Element::Ge);
}
}
#[test]
fn test_try_from_mass_number() {
for isotope in GermaniumIsotope::iter() {
let mass = isotope.mass_number();
let iso = GermaniumIsotope::try_from(mass).unwrap();
assert_eq!(iso, isotope);
let iso_u32 = GermaniumIsotope::try_from(u32::from(mass)).unwrap();
assert_eq!(iso_u32, isotope);
if let Ok(mass_u8) = u8::try_from(mass) {
let iso_u8 = GermaniumIsotope::try_from(mass_u8).unwrap();
assert_eq!(iso_u8, isotope);
}
}
assert!(GermaniumIsotope::try_from(0_u16).is_err());
assert!(GermaniumIsotope::try_from(1000_u16).is_err());
assert!(GermaniumIsotope::try_from(0_u32).is_err());
assert!(GermaniumIsotope::try_from(1000_u32).is_err());
assert!(GermaniumIsotope::try_from(0_u8).is_err());
}
#[test]
fn test_display() {
for isotope in GermaniumIsotope::iter() {
let s = alloc::format!("{isotope}");
assert!(!s.is_empty(), "Display should not be empty for {isotope:?}");
}
}
}