#[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 PalladiumIsotope {
Pd90,
Pd91,
Pd92,
Pd93,
Pd94,
Pd95,
Pd96,
Pd97,
Pd98,
Pd99,
Pd100,
Pd101,
Pd102,
Pd103,
Pd104,
Pd105,
Pd106,
Pd107,
Pd108,
Pd109,
Pd110,
Pd111,
Pd112,
Pd113,
Pd114,
Pd115,
Pd116,
Pd117,
Pd118,
Pd119,
Pd120,
Pd121,
Pd122,
Pd123,
Pd124,
Pd125,
Pd126,
Pd127,
Pd128,
Pd129,
Pd130,
Pd131,
}
impl super::RelativeAtomicMass for PalladiumIsotope {
#[inline]
fn relative_atomic_mass(&self) -> f64 {
match self {
Self::Pd90 => 89.95737f64,
Self::Pd91 => 90.95032f64,
Self::Pd92 => 91.94088f64,
Self::Pd93 => 92.93651f64,
Self::Pd94 => 93.9290376f64,
Self::Pd95 => 94.9248898f64,
Self::Pd96 => 95.9182151f64,
Self::Pd97 => 96.916472f64,
Self::Pd98 => 97.9126983f64,
Self::Pd99 => 98.9117748f64,
Self::Pd100 => 99.908505f64,
Self::Pd101 => 100.9082864f64,
Self::Pd102 => 101.9056022f64,
Self::Pd103 => 102.9060809f64,
Self::Pd104 => 103.9040305f64,
Self::Pd105 => 104.9050796f64,
Self::Pd106 => 105.9034804f64,
Self::Pd107 => 106.9051282f64,
Self::Pd108 => 107.9038916f64,
Self::Pd109 => 108.9059504f64,
Self::Pd110 => 109.9051722f64,
Self::Pd111 => 110.90768968f64,
Self::Pd112 => 111.9073297f64,
Self::Pd113 => 112.910261f64,
Self::Pd114 => 113.9103686f64,
Self::Pd115 => 114.913659f64,
Self::Pd116 => 115.914297f64,
Self::Pd117 => 116.9179547f64,
Self::Pd118 => 117.9190667f64,
Self::Pd119 => 118.9233402f64,
Self::Pd120 => 119.9245511f64,
Self::Pd121 => 120.9289503f64,
Self::Pd122 => 121.930632f64,
Self::Pd123 => 122.93514f64,
Self::Pd124 => 123.93714f64,
Self::Pd125 => 124.94179f64,
Self::Pd126 => 125.94416f64,
Self::Pd127 => 126.94907f64,
Self::Pd128 => 127.95183f64,
Self::Pd129 => 128.959334f64,
Self::Pd130 => 129.964863f64,
Self::Pd131 => 130.972367f64,
}
}
}
impl super::ElementVariant for PalladiumIsotope {
#[inline]
fn element(&self) -> crate::Element {
crate::Element::Pd
}
}
impl super::MassNumber for PalladiumIsotope {
#[inline]
fn mass_number(&self) -> u16 {
match self {
Self::Pd90 => 90u16,
Self::Pd91 => 91u16,
Self::Pd92 => 92u16,
Self::Pd93 => 93u16,
Self::Pd94 => 94u16,
Self::Pd95 => 95u16,
Self::Pd96 => 96u16,
Self::Pd97 => 97u16,
Self::Pd98 => 98u16,
Self::Pd99 => 99u16,
Self::Pd100 => 100u16,
Self::Pd101 => 101u16,
Self::Pd102 => 102u16,
Self::Pd103 => 103u16,
Self::Pd104 => 104u16,
Self::Pd105 => 105u16,
Self::Pd106 => 106u16,
Self::Pd107 => 107u16,
Self::Pd108 => 108u16,
Self::Pd109 => 109u16,
Self::Pd110 => 110u16,
Self::Pd111 => 111u16,
Self::Pd112 => 112u16,
Self::Pd113 => 113u16,
Self::Pd114 => 114u16,
Self::Pd115 => 115u16,
Self::Pd116 => 116u16,
Self::Pd117 => 117u16,
Self::Pd118 => 118u16,
Self::Pd119 => 119u16,
Self::Pd120 => 120u16,
Self::Pd121 => 121u16,
Self::Pd122 => 122u16,
Self::Pd123 => 123u16,
Self::Pd124 => 124u16,
Self::Pd125 => 125u16,
Self::Pd126 => 126u16,
Self::Pd127 => 127u16,
Self::Pd128 => 128u16,
Self::Pd129 => 129u16,
Self::Pd130 => 130u16,
Self::Pd131 => 131u16,
}
}
}
impl super::IsotopicComposition for PalladiumIsotope {
#[inline]
fn isotopic_composition(&self) -> Option<f64> {
match self {
Self::Pd102 => Some(0.0102f64),
Self::Pd104 => Some(0.1114f64),
Self::Pd105 => Some(0.2233f64),
Self::Pd106 => Some(0.2733f64),
Self::Pd108 => Some(0.2646f64),
Self::Pd110 => Some(0.1172f64),
_ => None,
}
}
}
impl super::MostAbundantIsotope for PalladiumIsotope {
fn most_abundant_isotope() -> Self {
Self::Pd106
}
}
impl From<PalladiumIsotope> for crate::Isotope {
fn from(isotope: PalladiumIsotope) -> Self {
crate::Isotope::Pd(isotope)
}
}
impl From<PalladiumIsotope> for crate::Element {
fn from(_isotope: PalladiumIsotope) -> Self {
crate::Element::Pd
}
}
impl TryFrom<u64> for PalladiumIsotope {
type Error = crate::errors::Error;
fn try_from(value: u64) -> Result<Self, Self::Error> {
match value {
90u64 => Ok(Self::Pd90),
91u64 => Ok(Self::Pd91),
92u64 => Ok(Self::Pd92),
93u64 => Ok(Self::Pd93),
94u64 => Ok(Self::Pd94),
95u64 => Ok(Self::Pd95),
96u64 => Ok(Self::Pd96),
97u64 => Ok(Self::Pd97),
98u64 => Ok(Self::Pd98),
99u64 => Ok(Self::Pd99),
100u64 => Ok(Self::Pd100),
101u64 => Ok(Self::Pd101),
102u64 => Ok(Self::Pd102),
103u64 => Ok(Self::Pd103),
104u64 => Ok(Self::Pd104),
105u64 => Ok(Self::Pd105),
106u64 => Ok(Self::Pd106),
107u64 => Ok(Self::Pd107),
108u64 => Ok(Self::Pd108),
109u64 => Ok(Self::Pd109),
110u64 => Ok(Self::Pd110),
111u64 => Ok(Self::Pd111),
112u64 => Ok(Self::Pd112),
113u64 => Ok(Self::Pd113),
114u64 => Ok(Self::Pd114),
115u64 => Ok(Self::Pd115),
116u64 => Ok(Self::Pd116),
117u64 => Ok(Self::Pd117),
118u64 => Ok(Self::Pd118),
119u64 => Ok(Self::Pd119),
120u64 => Ok(Self::Pd120),
121u64 => Ok(Self::Pd121),
122u64 => Ok(Self::Pd122),
123u64 => Ok(Self::Pd123),
124u64 => Ok(Self::Pd124),
125u64 => Ok(Self::Pd125),
126u64 => Ok(Self::Pd126),
127u64 => Ok(Self::Pd127),
128u64 => Ok(Self::Pd128),
129u64 => Ok(Self::Pd129),
130u64 => Ok(Self::Pd130),
131u64 => Ok(Self::Pd131),
_ => Err(crate::errors::Error::Isotope(crate::Element::Pd, value)),
}
}
}
impl TryFrom<u8> for PalladiumIsotope {
type Error = crate::errors::Error;
fn try_from(value: u8) -> Result<Self, Self::Error> {
Self::try_from(u64::from(value))
}
}
impl TryFrom<u16> for PalladiumIsotope {
type Error = crate::errors::Error;
fn try_from(value: u16) -> Result<Self, Self::Error> {
Self::try_from(u64::from(value))
}
}
impl TryFrom<u32> for PalladiumIsotope {
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 PalladiumIsotope {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::Pd90 => write!(f, "Pd90"),
Self::Pd91 => write!(f, "Pd91"),
Self::Pd92 => write!(f, "Pd92"),
Self::Pd93 => write!(f, "Pd93"),
Self::Pd94 => write!(f, "Pd94"),
Self::Pd95 => write!(f, "Pd95"),
Self::Pd96 => write!(f, "Pd96"),
Self::Pd97 => write!(f, "Pd97"),
Self::Pd98 => write!(f, "Pd98"),
Self::Pd99 => write!(f, "Pd99"),
Self::Pd100 => write!(f, "Pd100"),
Self::Pd101 => write!(f, "Pd101"),
Self::Pd102 => write!(f, "Pd102"),
Self::Pd103 => write!(f, "Pd103"),
Self::Pd104 => write!(f, "Pd104"),
Self::Pd105 => write!(f, "Pd105"),
Self::Pd106 => write!(f, "Pd106"),
Self::Pd107 => write!(f, "Pd107"),
Self::Pd108 => write!(f, "Pd108"),
Self::Pd109 => write!(f, "Pd109"),
Self::Pd110 => write!(f, "Pd110"),
Self::Pd111 => write!(f, "Pd111"),
Self::Pd112 => write!(f, "Pd112"),
Self::Pd113 => write!(f, "Pd113"),
Self::Pd114 => write!(f, "Pd114"),
Self::Pd115 => write!(f, "Pd115"),
Self::Pd116 => write!(f, "Pd116"),
Self::Pd117 => write!(f, "Pd117"),
Self::Pd118 => write!(f, "Pd118"),
Self::Pd119 => write!(f, "Pd119"),
Self::Pd120 => write!(f, "Pd120"),
Self::Pd121 => write!(f, "Pd121"),
Self::Pd122 => write!(f, "Pd122"),
Self::Pd123 => write!(f, "Pd123"),
Self::Pd124 => write!(f, "Pd124"),
Self::Pd125 => write!(f, "Pd125"),
Self::Pd126 => write!(f, "Pd126"),
Self::Pd127 => write!(f, "Pd127"),
Self::Pd128 => write!(f, "Pd128"),
Self::Pd129 => write!(f, "Pd129"),
Self::Pd130 => write!(f, "Pd130"),
Self::Pd131 => write!(f, "Pd131"),
}
}
}
#[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 PalladiumIsotope::iter() {
let mass = isotope.relative_atomic_mass();
assert!(mass > 0.0, "Mass should be positive for {isotope:?}");
}
}
#[test]
fn test_element() {
for isotope in PalladiumIsotope::iter() {
let element = isotope.element();
assert_eq!(element, crate::Element::Pd, "Element should be correct for {isotope:?}");
}
}
#[test]
fn test_mass_number() {
for isotope in PalladiumIsotope::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 PalladiumIsotope::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 = PalladiumIsotope::most_abundant_isotope();
let _ = most_abundant.relative_atomic_mass();
}
#[test]
fn test_from_isotope() {
for isotope in PalladiumIsotope::iter() {
let iso: crate::Isotope = isotope.into();
match iso {
crate::Isotope::Pd(i) => assert_eq!(i, isotope),
_ => panic!("Wrong isotope type"),
}
}
}
#[test]
fn test_from_element() {
for isotope in PalladiumIsotope::iter() {
let elem: crate::Element = isotope.into();
assert_eq!(elem, crate::Element::Pd);
}
}
#[test]
fn test_try_from_mass_number() {
for isotope in PalladiumIsotope::iter() {
let mass = isotope.mass_number();
let iso = PalladiumIsotope::try_from(mass).unwrap();
assert_eq!(iso, isotope);
let iso_u32 = PalladiumIsotope::try_from(u32::from(mass)).unwrap();
assert_eq!(iso_u32, isotope);
if let Ok(mass_u8) = u8::try_from(mass) {
let iso_u8 = PalladiumIsotope::try_from(mass_u8).unwrap();
assert_eq!(iso_u8, isotope);
}
}
assert!(PalladiumIsotope::try_from(0_u16).is_err());
assert!(PalladiumIsotope::try_from(1000_u16).is_err());
assert!(PalladiumIsotope::try_from(0_u32).is_err());
assert!(PalladiumIsotope::try_from(1000_u32).is_err());
assert!(PalladiumIsotope::try_from(0_u8).is_err());
}
#[test]
fn test_display() {
for isotope in PalladiumIsotope::iter() {
let s = alloc::format!("{isotope}");
assert!(!s.is_empty(), "Display should not be empty for {isotope:?}");
}
}
}