elements_rs 0.2.5

A comprehensive library for chemical elements and their isotopes with rich metadata
Documentation
//! Isotopes of the element Copper
#[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))]
/// Isotopes of the element Copper
pub enum CopperIsotope {
    /// Isotope Cu53 of Copper
    Cu53,
    /// Isotope Cu54 of Copper
    Cu54,
    /// Isotope Cu55 of Copper
    Cu55,
    /// Isotope Cu56 of Copper
    Cu56,
    /// Isotope Cu57 of Copper
    Cu57,
    /// Isotope Cu58 of Copper
    Cu58,
    /// Isotope Cu59 of Copper
    Cu59,
    /// Isotope Cu60 of Copper
    Cu60,
    /// Isotope Cu61 of Copper
    Cu61,
    /// Isotope Cu62 of Copper
    Cu62,
    /// Isotope Cu63 of Copper
    Cu63,
    /// Isotope Cu64 of Copper
    Cu64,
    /// Isotope Cu65 of Copper
    Cu65,
    /// Isotope Cu66 of Copper
    Cu66,
    /// Isotope Cu67 of Copper
    Cu67,
    /// Isotope Cu68 of Copper
    Cu68,
    /// Isotope Cu69 of Copper
    Cu69,
    /// Isotope Cu70 of Copper
    Cu70,
    /// Isotope Cu71 of Copper
    Cu71,
    /// Isotope Cu72 of Copper
    Cu72,
    /// Isotope Cu73 of Copper
    Cu73,
    /// Isotope Cu74 of Copper
    Cu74,
    /// Isotope Cu75 of Copper
    Cu75,
    /// Isotope Cu76 of Copper
    Cu76,
    /// Isotope Cu77 of Copper
    Cu77,
    /// Isotope Cu78 of Copper
    Cu78,
    /// Isotope Cu79 of Copper
    Cu79,
    /// Isotope Cu80 of Copper
    Cu80,
    /// Isotope Cu81 of Copper
    Cu81,
    /// Isotope Cu82 of Copper
    Cu82,
    /// Isotope Cu83 of Copper
    Cu83,
    /// Isotope Cu84 of Copper
    Cu84,
}
impl super::RelativeAtomicMass for CopperIsotope {
    #[inline]
    fn relative_atomic_mass(&self) -> f64 {
        match self {
            Self::Cu53 => 52.98459f64,
            Self::Cu54 => 53.97666f64,
            Self::Cu55 => 54.96604f64,
            Self::Cu56 => 55.95895f64,
            Self::Cu57 => 56.9492125f64,
            Self::Cu58 => 57.94453305f64,
            Self::Cu59 => 58.93949748f64,
            Self::Cu60 => 59.9373645f64,
            Self::Cu61 => 60.9334576f64,
            Self::Cu62 => 61.93259541f64,
            Self::Cu63 => 62.92959772f64,
            Self::Cu64 => 63.92976434f64,
            Self::Cu65 => 64.9277897f64,
            Self::Cu66 => 65.92886903f64,
            Self::Cu67 => 66.9277303f64,
            Self::Cu68 => 67.9296109f64,
            Self::Cu69 => 68.9294293f64,
            Self::Cu70 => 69.9323921f64,
            Self::Cu71 => 70.9326768f64,
            Self::Cu72 => 71.9358203f64,
            Self::Cu73 => 72.9366744f64,
            Self::Cu74 => 73.9398749f64,
            Self::Cu75 => 74.9415226f64,
            Self::Cu76 => 75.945275f64,
            Self::Cu77 => 76.94792f64,
            Self::Cu78 => 77.95223f64,
            Self::Cu79 => 78.95502f64,
            Self::Cu80 => 79.96089f64,
            Self::Cu81 => 80.96587f64,
            Self::Cu82 => 81.97244f64,
            Self::Cu83 => 82.97811f64,
            Self::Cu84 => 83.985271f64,
        }
    }
}
impl super::ElementVariant for CopperIsotope {
    #[inline]
    fn element(&self) -> crate::Element {
        crate::Element::Cu
    }
}
impl super::MassNumber for CopperIsotope {
    #[inline]
    fn mass_number(&self) -> u16 {
        match self {
            Self::Cu53 => 53u16,
            Self::Cu54 => 54u16,
            Self::Cu55 => 55u16,
            Self::Cu56 => 56u16,
            Self::Cu57 => 57u16,
            Self::Cu58 => 58u16,
            Self::Cu59 => 59u16,
            Self::Cu60 => 60u16,
            Self::Cu61 => 61u16,
            Self::Cu62 => 62u16,
            Self::Cu63 => 63u16,
            Self::Cu64 => 64u16,
            Self::Cu65 => 65u16,
            Self::Cu66 => 66u16,
            Self::Cu67 => 67u16,
            Self::Cu68 => 68u16,
            Self::Cu69 => 69u16,
            Self::Cu70 => 70u16,
            Self::Cu71 => 71u16,
            Self::Cu72 => 72u16,
            Self::Cu73 => 73u16,
            Self::Cu74 => 74u16,
            Self::Cu75 => 75u16,
            Self::Cu76 => 76u16,
            Self::Cu77 => 77u16,
            Self::Cu78 => 78u16,
            Self::Cu79 => 79u16,
            Self::Cu80 => 80u16,
            Self::Cu81 => 81u16,
            Self::Cu82 => 82u16,
            Self::Cu83 => 83u16,
            Self::Cu84 => 84u16,
        }
    }
}
impl super::IsotopicComposition for CopperIsotope {
    #[inline]
    fn isotopic_composition(&self) -> Option<f64> {
        match self {
            Self::Cu63 => Some(0.6915f64),
            Self::Cu65 => Some(0.3085f64),
            _ => None,
        }
    }
}
impl super::MostAbundantIsotope for CopperIsotope {
    fn most_abundant_isotope() -> Self {
        Self::Cu63
    }
}
impl From<CopperIsotope> for crate::Isotope {
    fn from(isotope: CopperIsotope) -> Self {
        crate::Isotope::Cu(isotope)
    }
}
impl From<CopperIsotope> for crate::Element {
    fn from(_isotope: CopperIsotope) -> Self {
        crate::Element::Cu
    }
}
impl TryFrom<u64> for CopperIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u64) -> Result<Self, Self::Error> {
        match value {
            53u64 => Ok(Self::Cu53),
            54u64 => Ok(Self::Cu54),
            55u64 => Ok(Self::Cu55),
            56u64 => Ok(Self::Cu56),
            57u64 => Ok(Self::Cu57),
            58u64 => Ok(Self::Cu58),
            59u64 => Ok(Self::Cu59),
            60u64 => Ok(Self::Cu60),
            61u64 => Ok(Self::Cu61),
            62u64 => Ok(Self::Cu62),
            63u64 => Ok(Self::Cu63),
            64u64 => Ok(Self::Cu64),
            65u64 => Ok(Self::Cu65),
            66u64 => Ok(Self::Cu66),
            67u64 => Ok(Self::Cu67),
            68u64 => Ok(Self::Cu68),
            69u64 => Ok(Self::Cu69),
            70u64 => Ok(Self::Cu70),
            71u64 => Ok(Self::Cu71),
            72u64 => Ok(Self::Cu72),
            73u64 => Ok(Self::Cu73),
            74u64 => Ok(Self::Cu74),
            75u64 => Ok(Self::Cu75),
            76u64 => Ok(Self::Cu76),
            77u64 => Ok(Self::Cu77),
            78u64 => Ok(Self::Cu78),
            79u64 => Ok(Self::Cu79),
            80u64 => Ok(Self::Cu80),
            81u64 => Ok(Self::Cu81),
            82u64 => Ok(Self::Cu82),
            83u64 => Ok(Self::Cu83),
            84u64 => Ok(Self::Cu84),
            _ => Err(crate::errors::Error::Isotope(crate::Element::Cu, value)),
        }
    }
}
impl TryFrom<u8> for CopperIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u8) -> Result<Self, Self::Error> {
        Self::try_from(u64::from(value))
    }
}
impl TryFrom<u16> for CopperIsotope {
    type Error = crate::errors::Error;
    fn try_from(value: u16) -> Result<Self, Self::Error> {
        Self::try_from(u64::from(value))
    }
}
impl TryFrom<u32> for CopperIsotope {
    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 CopperIsotope {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        match self {
            Self::Cu53 => write!(f, "Cu53"),
            Self::Cu54 => write!(f, "Cu54"),
            Self::Cu55 => write!(f, "Cu55"),
            Self::Cu56 => write!(f, "Cu56"),
            Self::Cu57 => write!(f, "Cu57"),
            Self::Cu58 => write!(f, "Cu58"),
            Self::Cu59 => write!(f, "Cu59"),
            Self::Cu60 => write!(f, "Cu60"),
            Self::Cu61 => write!(f, "Cu61"),
            Self::Cu62 => write!(f, "Cu62"),
            Self::Cu63 => write!(f, "Cu63"),
            Self::Cu64 => write!(f, "Cu64"),
            Self::Cu65 => write!(f, "Cu65"),
            Self::Cu66 => write!(f, "Cu66"),
            Self::Cu67 => write!(f, "Cu67"),
            Self::Cu68 => write!(f, "Cu68"),
            Self::Cu69 => write!(f, "Cu69"),
            Self::Cu70 => write!(f, "Cu70"),
            Self::Cu71 => write!(f, "Cu71"),
            Self::Cu72 => write!(f, "Cu72"),
            Self::Cu73 => write!(f, "Cu73"),
            Self::Cu74 => write!(f, "Cu74"),
            Self::Cu75 => write!(f, "Cu75"),
            Self::Cu76 => write!(f, "Cu76"),
            Self::Cu77 => write!(f, "Cu77"),
            Self::Cu78 => write!(f, "Cu78"),
            Self::Cu79 => write!(f, "Cu79"),
            Self::Cu80 => write!(f, "Cu80"),
            Self::Cu81 => write!(f, "Cu81"),
            Self::Cu82 => write!(f, "Cu82"),
            Self::Cu83 => write!(f, "Cu83"),
            Self::Cu84 => write!(f, "Cu84"),
        }
    }
}
#[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 CopperIsotope::iter() {
            let mass = isotope.relative_atomic_mass();
            assert!(mass > 0.0, "Mass should be positive for {isotope:?}");
        }
    }
    #[test]
    fn test_element() {
        for isotope in CopperIsotope::iter() {
            let element = isotope.element();
            assert_eq!(element, crate::Element::Cu, "Element should be correct for {isotope:?}");
        }
    }
    #[test]
    fn test_mass_number() {
        for isotope in CopperIsotope::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 CopperIsotope::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 = CopperIsotope::most_abundant_isotope();
        let _ = most_abundant.relative_atomic_mass();
    }
    #[test]
    fn test_from_isotope() {
        for isotope in CopperIsotope::iter() {
            let iso: crate::Isotope = isotope.into();
            match iso {
                crate::Isotope::Cu(i) => assert_eq!(i, isotope),
                _ => panic!("Wrong isotope type"),
            }
        }
    }
    #[test]
    fn test_from_element() {
        for isotope in CopperIsotope::iter() {
            let elem: crate::Element = isotope.into();
            assert_eq!(elem, crate::Element::Cu);
        }
    }
    #[test]
    fn test_try_from_mass_number() {
        for isotope in CopperIsotope::iter() {
            let mass = isotope.mass_number();
            let iso = CopperIsotope::try_from(mass).unwrap();
            assert_eq!(iso, isotope);
            let iso_u32 = CopperIsotope::try_from(u32::from(mass)).unwrap();
            assert_eq!(iso_u32, isotope);
            if let Ok(mass_u8) = u8::try_from(mass) {
                let iso_u8 = CopperIsotope::try_from(mass_u8).unwrap();
                assert_eq!(iso_u8, isotope);
            }
        }
        assert!(CopperIsotope::try_from(0_u16).is_err());
        assert!(CopperIsotope::try_from(1000_u16).is_err());
        assert!(CopperIsotope::try_from(0_u32).is_err());
        assert!(CopperIsotope::try_from(1000_u32).is_err());
        assert!(CopperIsotope::try_from(0_u8).is_err());
    }
    #[test]
    fn test_display() {
        for isotope in CopperIsotope::iter() {
            let s = alloc::format!("{isotope}");
            assert!(!s.is_empty(), "Display should not be empty for {isotope:?}");
        }
    }
}