#[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 PoloniumIsotope {
Po186,
Po187,
Po188,
Po189,
Po190,
Po191,
Po192,
Po193,
Po194,
Po195,
Po196,
Po197,
Po198,
Po199,
Po200,
Po201,
Po202,
Po203,
Po204,
Po205,
Po206,
Po207,
Po208,
Po209,
Po210,
Po211,
Po212,
Po213,
Po214,
Po215,
Po216,
Po217,
Po218,
Po219,
Po220,
Po221,
Po222,
Po223,
Po224,
Po225,
Po226,
Po227,
}
impl super::RelativeAtomicMass for PoloniumIsotope {
#[inline]
fn relative_atomic_mass(&self) -> f64 {
match self {
Self::Po186 => 186.004393f64,
Self::Po187 => 187.003041f64,
Self::Po188 => 187.999416f64,
Self::Po189 => 188.998473f64,
Self::Po190 => 189.995101f64,
Self::Po191 => 190.9945585f64,
Self::Po192 => 191.991336f64,
Self::Po193 => 192.991026f64,
Self::Po194 => 193.988186f64,
Self::Po195 => 194.988126f64,
Self::Po196 => 195.985526f64,
Self::Po197 => 196.98566f64,
Self::Po198 => 197.983389f64,
Self::Po199 => 198.983667f64,
Self::Po200 => 199.981799f64,
Self::Po201 => 200.9822598f64,
Self::Po202 => 201.980758f64,
Self::Po203 => 202.9814161f64,
Self::Po204 => 203.98031f64,
Self::Po205 => 204.981203f64,
Self::Po206 => 205.980474f64,
Self::Po207 => 206.9815938f64,
Self::Po208 => 207.9812461f64,
Self::Po209 => 208.9824308f64,
Self::Po210 => 209.9828741f64,
Self::Po211 => 210.9866536f64,
Self::Po212 => 211.9888684f64,
Self::Po213 => 212.9928576f64,
Self::Po214 => 213.9952017f64,
Self::Po215 => 214.9994201f64,
Self::Po216 => 216.0019152f64,
Self::Po217 => 217.0063182f64,
Self::Po218 => 218.0089735f64,
Self::Po219 => 219.013614f64,
Self::Po220 => 220.016386f64,
Self::Po221 => 221.021228f64,
Self::Po222 => 222.02414f64,
Self::Po223 => 223.02907f64,
Self::Po224 => 224.03211f64,
Self::Po225 => 225.03707f64,
Self::Po226 => 226.04031f64,
Self::Po227 => 227.04539f64,
}
}
}
impl super::ElementVariant for PoloniumIsotope {
#[inline]
fn element(&self) -> crate::Element {
crate::Element::Po
}
}
impl super::MassNumber for PoloniumIsotope {
#[inline]
fn mass_number(&self) -> u16 {
match self {
Self::Po186 => 186u16,
Self::Po187 => 187u16,
Self::Po188 => 188u16,
Self::Po189 => 189u16,
Self::Po190 => 190u16,
Self::Po191 => 191u16,
Self::Po192 => 192u16,
Self::Po193 => 193u16,
Self::Po194 => 194u16,
Self::Po195 => 195u16,
Self::Po196 => 196u16,
Self::Po197 => 197u16,
Self::Po198 => 198u16,
Self::Po199 => 199u16,
Self::Po200 => 200u16,
Self::Po201 => 201u16,
Self::Po202 => 202u16,
Self::Po203 => 203u16,
Self::Po204 => 204u16,
Self::Po205 => 205u16,
Self::Po206 => 206u16,
Self::Po207 => 207u16,
Self::Po208 => 208u16,
Self::Po209 => 209u16,
Self::Po210 => 210u16,
Self::Po211 => 211u16,
Self::Po212 => 212u16,
Self::Po213 => 213u16,
Self::Po214 => 214u16,
Self::Po215 => 215u16,
Self::Po216 => 216u16,
Self::Po217 => 217u16,
Self::Po218 => 218u16,
Self::Po219 => 219u16,
Self::Po220 => 220u16,
Self::Po221 => 221u16,
Self::Po222 => 222u16,
Self::Po223 => 223u16,
Self::Po224 => 224u16,
Self::Po225 => 225u16,
Self::Po226 => 226u16,
Self::Po227 => 227u16,
}
}
}
impl super::IsotopicComposition for PoloniumIsotope {
#[inline]
fn isotopic_composition(&self) -> Option<f64> {
None
}
}
impl super::MostAbundantIsotope for PoloniumIsotope {
fn most_abundant_isotope() -> Self {
Self::Po227
}
}
impl From<PoloniumIsotope> for crate::Isotope {
fn from(isotope: PoloniumIsotope) -> Self {
crate::Isotope::Po(isotope)
}
}
impl From<PoloniumIsotope> for crate::Element {
fn from(_isotope: PoloniumIsotope) -> Self {
crate::Element::Po
}
}
impl TryFrom<u64> for PoloniumIsotope {
type Error = crate::errors::Error;
fn try_from(value: u64) -> Result<Self, Self::Error> {
match value {
186u64 => Ok(Self::Po186),
187u64 => Ok(Self::Po187),
188u64 => Ok(Self::Po188),
189u64 => Ok(Self::Po189),
190u64 => Ok(Self::Po190),
191u64 => Ok(Self::Po191),
192u64 => Ok(Self::Po192),
193u64 => Ok(Self::Po193),
194u64 => Ok(Self::Po194),
195u64 => Ok(Self::Po195),
196u64 => Ok(Self::Po196),
197u64 => Ok(Self::Po197),
198u64 => Ok(Self::Po198),
199u64 => Ok(Self::Po199),
200u64 => Ok(Self::Po200),
201u64 => Ok(Self::Po201),
202u64 => Ok(Self::Po202),
203u64 => Ok(Self::Po203),
204u64 => Ok(Self::Po204),
205u64 => Ok(Self::Po205),
206u64 => Ok(Self::Po206),
207u64 => Ok(Self::Po207),
208u64 => Ok(Self::Po208),
209u64 => Ok(Self::Po209),
210u64 => Ok(Self::Po210),
211u64 => Ok(Self::Po211),
212u64 => Ok(Self::Po212),
213u64 => Ok(Self::Po213),
214u64 => Ok(Self::Po214),
215u64 => Ok(Self::Po215),
216u64 => Ok(Self::Po216),
217u64 => Ok(Self::Po217),
218u64 => Ok(Self::Po218),
219u64 => Ok(Self::Po219),
220u64 => Ok(Self::Po220),
221u64 => Ok(Self::Po221),
222u64 => Ok(Self::Po222),
223u64 => Ok(Self::Po223),
224u64 => Ok(Self::Po224),
225u64 => Ok(Self::Po225),
226u64 => Ok(Self::Po226),
227u64 => Ok(Self::Po227),
_ => Err(crate::errors::Error::Isotope(crate::Element::Po, value)),
}
}
}
impl TryFrom<u8> for PoloniumIsotope {
type Error = crate::errors::Error;
fn try_from(value: u8) -> Result<Self, Self::Error> {
Self::try_from(u64::from(value))
}
}
impl TryFrom<u16> for PoloniumIsotope {
type Error = crate::errors::Error;
fn try_from(value: u16) -> Result<Self, Self::Error> {
Self::try_from(u64::from(value))
}
}
impl TryFrom<u32> for PoloniumIsotope {
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 PoloniumIsotope {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::Po186 => write!(f, "Po186"),
Self::Po187 => write!(f, "Po187"),
Self::Po188 => write!(f, "Po188"),
Self::Po189 => write!(f, "Po189"),
Self::Po190 => write!(f, "Po190"),
Self::Po191 => write!(f, "Po191"),
Self::Po192 => write!(f, "Po192"),
Self::Po193 => write!(f, "Po193"),
Self::Po194 => write!(f, "Po194"),
Self::Po195 => write!(f, "Po195"),
Self::Po196 => write!(f, "Po196"),
Self::Po197 => write!(f, "Po197"),
Self::Po198 => write!(f, "Po198"),
Self::Po199 => write!(f, "Po199"),
Self::Po200 => write!(f, "Po200"),
Self::Po201 => write!(f, "Po201"),
Self::Po202 => write!(f, "Po202"),
Self::Po203 => write!(f, "Po203"),
Self::Po204 => write!(f, "Po204"),
Self::Po205 => write!(f, "Po205"),
Self::Po206 => write!(f, "Po206"),
Self::Po207 => write!(f, "Po207"),
Self::Po208 => write!(f, "Po208"),
Self::Po209 => write!(f, "Po209"),
Self::Po210 => write!(f, "Po210"),
Self::Po211 => write!(f, "Po211"),
Self::Po212 => write!(f, "Po212"),
Self::Po213 => write!(f, "Po213"),
Self::Po214 => write!(f, "Po214"),
Self::Po215 => write!(f, "Po215"),
Self::Po216 => write!(f, "Po216"),
Self::Po217 => write!(f, "Po217"),
Self::Po218 => write!(f, "Po218"),
Self::Po219 => write!(f, "Po219"),
Self::Po220 => write!(f, "Po220"),
Self::Po221 => write!(f, "Po221"),
Self::Po222 => write!(f, "Po222"),
Self::Po223 => write!(f, "Po223"),
Self::Po224 => write!(f, "Po224"),
Self::Po225 => write!(f, "Po225"),
Self::Po226 => write!(f, "Po226"),
Self::Po227 => write!(f, "Po227"),
}
}
}
#[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 PoloniumIsotope::iter() {
let mass = isotope.relative_atomic_mass();
assert!(mass > 0.0, "Mass should be positive for {isotope:?}");
}
}
#[test]
fn test_element() {
for isotope in PoloniumIsotope::iter() {
let element = isotope.element();
assert_eq!(element, crate::Element::Po, "Element should be correct for {isotope:?}");
}
}
#[test]
fn test_mass_number() {
for isotope in PoloniumIsotope::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 PoloniumIsotope::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 = PoloniumIsotope::most_abundant_isotope();
let _ = most_abundant.relative_atomic_mass();
}
#[test]
fn test_from_isotope() {
for isotope in PoloniumIsotope::iter() {
let iso: crate::Isotope = isotope.into();
match iso {
crate::Isotope::Po(i) => assert_eq!(i, isotope),
_ => panic!("Wrong isotope type"),
}
}
}
#[test]
fn test_from_element() {
for isotope in PoloniumIsotope::iter() {
let elem: crate::Element = isotope.into();
assert_eq!(elem, crate::Element::Po);
}
}
#[test]
fn test_try_from_mass_number() {
for isotope in PoloniumIsotope::iter() {
let mass = isotope.mass_number();
let iso = PoloniumIsotope::try_from(mass).unwrap();
assert_eq!(iso, isotope);
let iso_u32 = PoloniumIsotope::try_from(u32::from(mass)).unwrap();
assert_eq!(iso_u32, isotope);
if let Ok(mass_u8) = u8::try_from(mass) {
let iso_u8 = PoloniumIsotope::try_from(mass_u8).unwrap();
assert_eq!(iso_u8, isotope);
}
}
assert!(PoloniumIsotope::try_from(0_u16).is_err());
assert!(PoloniumIsotope::try_from(1000_u16).is_err());
assert!(PoloniumIsotope::try_from(0_u32).is_err());
assert!(PoloniumIsotope::try_from(1000_u32).is_err());
assert!(PoloniumIsotope::try_from(0_u8).is_err());
}
#[test]
fn test_display() {
for isotope in PoloniumIsotope::iter() {
let s = alloc::format!("{isotope}");
assert!(!s.is_empty(), "Display should not be empty for {isotope:?}");
}
}
}