#[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 GadoliniumIsotope {
Gd133,
Gd134,
Gd135,
Gd136,
Gd137,
Gd138,
Gd139,
Gd140,
Gd141,
Gd142,
Gd143,
Gd144,
Gd145,
Gd146,
Gd147,
Gd148,
Gd149,
Gd150,
Gd151,
Gd152,
Gd153,
Gd154,
Gd155,
Gd156,
Gd157,
Gd158,
Gd159,
Gd160,
Gd161,
Gd162,
Gd163,
Gd164,
Gd165,
Gd166,
Gd167,
Gd168,
Gd169,
Gd170,
Gd171,
Gd172,
}
impl super::RelativeAtomicMass for GadoliniumIsotope {
#[inline]
fn relative_atomic_mass(&self) -> f64 {
match self {
Self::Gd133 => 132.96133f64,
Self::Gd134 => 133.95566f64,
Self::Gd135 => 134.95245f64,
Self::Gd136 => 135.9473f64,
Self::Gd137 => 136.94502f64,
Self::Gd138 => 137.94025f64,
Self::Gd139 => 138.93813f64,
Self::Gd140 => 139.933674f64,
Self::Gd141 => 140.932126f64,
Self::Gd142 => 141.928116f64,
Self::Gd143 => 142.92675f64,
Self::Gd144 => 143.922963f64,
Self::Gd145 => 144.921713f64,
Self::Gd146 => 145.9183188f64,
Self::Gd147 => 146.9191014f64,
Self::Gd148 => 147.9181215f64,
Self::Gd149 => 148.9193481f64,
Self::Gd150 => 149.9186644f64,
Self::Gd151 => 150.920356f64,
Self::Gd152 => 151.9197995f64,
Self::Gd153 => 152.921758f64,
Self::Gd154 => 153.9208741f64,
Self::Gd155 => 154.9226305f64,
Self::Gd156 => 155.9221312f64,
Self::Gd157 => 156.9239686f64,
Self::Gd158 => 157.9241123f64,
Self::Gd159 => 158.926397f64,
Self::Gd160 => 159.9270624f64,
Self::Gd161 => 160.9296775f64,
Self::Gd162 => 161.930993f64,
Self::Gd163 => 162.9341769f64,
Self::Gd164 => 163.93583f64,
Self::Gd165 => 164.93936f64,
Self::Gd166 => 165.94146f64,
Self::Gd167 => 166.94545f64,
Self::Gd168 => 167.94808f64,
Self::Gd169 => 168.9526f64,
Self::Gd170 => 169.956146f64,
Self::Gd171 => 170.961127f64,
Self::Gd172 => 171.964605f64,
}
}
}
impl super::ElementVariant for GadoliniumIsotope {
#[inline]
fn element(&self) -> crate::Element {
crate::Element::Gd
}
}
impl super::MassNumber for GadoliniumIsotope {
#[inline]
fn mass_number(&self) -> u16 {
match self {
Self::Gd133 => 133u16,
Self::Gd134 => 134u16,
Self::Gd135 => 135u16,
Self::Gd136 => 136u16,
Self::Gd137 => 137u16,
Self::Gd138 => 138u16,
Self::Gd139 => 139u16,
Self::Gd140 => 140u16,
Self::Gd141 => 141u16,
Self::Gd142 => 142u16,
Self::Gd143 => 143u16,
Self::Gd144 => 144u16,
Self::Gd145 => 145u16,
Self::Gd146 => 146u16,
Self::Gd147 => 147u16,
Self::Gd148 => 148u16,
Self::Gd149 => 149u16,
Self::Gd150 => 150u16,
Self::Gd151 => 151u16,
Self::Gd152 => 152u16,
Self::Gd153 => 153u16,
Self::Gd154 => 154u16,
Self::Gd155 => 155u16,
Self::Gd156 => 156u16,
Self::Gd157 => 157u16,
Self::Gd158 => 158u16,
Self::Gd159 => 159u16,
Self::Gd160 => 160u16,
Self::Gd161 => 161u16,
Self::Gd162 => 162u16,
Self::Gd163 => 163u16,
Self::Gd164 => 164u16,
Self::Gd165 => 165u16,
Self::Gd166 => 166u16,
Self::Gd167 => 167u16,
Self::Gd168 => 168u16,
Self::Gd169 => 169u16,
Self::Gd170 => 170u16,
Self::Gd171 => 171u16,
Self::Gd172 => 172u16,
}
}
}
impl super::IsotopicComposition for GadoliniumIsotope {
#[inline]
fn isotopic_composition(&self) -> Option<f64> {
match self {
Self::Gd152 => Some(0.002f64),
Self::Gd154 => Some(0.0218f64),
Self::Gd155 => Some(0.148f64),
Self::Gd156 => Some(0.2047f64),
Self::Gd157 => Some(0.1565f64),
Self::Gd158 => Some(0.2484f64),
Self::Gd160 => Some(0.2186f64),
_ => None,
}
}
}
impl super::MostAbundantIsotope for GadoliniumIsotope {
fn most_abundant_isotope() -> Self {
Self::Gd158
}
}
impl From<GadoliniumIsotope> for crate::Isotope {
fn from(isotope: GadoliniumIsotope) -> Self {
crate::Isotope::Gd(isotope)
}
}
impl From<GadoliniumIsotope> for crate::Element {
fn from(_isotope: GadoliniumIsotope) -> Self {
crate::Element::Gd
}
}
impl TryFrom<u64> for GadoliniumIsotope {
type Error = crate::errors::Error;
fn try_from(value: u64) -> Result<Self, Self::Error> {
match value {
133u64 => Ok(Self::Gd133),
134u64 => Ok(Self::Gd134),
135u64 => Ok(Self::Gd135),
136u64 => Ok(Self::Gd136),
137u64 => Ok(Self::Gd137),
138u64 => Ok(Self::Gd138),
139u64 => Ok(Self::Gd139),
140u64 => Ok(Self::Gd140),
141u64 => Ok(Self::Gd141),
142u64 => Ok(Self::Gd142),
143u64 => Ok(Self::Gd143),
144u64 => Ok(Self::Gd144),
145u64 => Ok(Self::Gd145),
146u64 => Ok(Self::Gd146),
147u64 => Ok(Self::Gd147),
148u64 => Ok(Self::Gd148),
149u64 => Ok(Self::Gd149),
150u64 => Ok(Self::Gd150),
151u64 => Ok(Self::Gd151),
152u64 => Ok(Self::Gd152),
153u64 => Ok(Self::Gd153),
154u64 => Ok(Self::Gd154),
155u64 => Ok(Self::Gd155),
156u64 => Ok(Self::Gd156),
157u64 => Ok(Self::Gd157),
158u64 => Ok(Self::Gd158),
159u64 => Ok(Self::Gd159),
160u64 => Ok(Self::Gd160),
161u64 => Ok(Self::Gd161),
162u64 => Ok(Self::Gd162),
163u64 => Ok(Self::Gd163),
164u64 => Ok(Self::Gd164),
165u64 => Ok(Self::Gd165),
166u64 => Ok(Self::Gd166),
167u64 => Ok(Self::Gd167),
168u64 => Ok(Self::Gd168),
169u64 => Ok(Self::Gd169),
170u64 => Ok(Self::Gd170),
171u64 => Ok(Self::Gd171),
172u64 => Ok(Self::Gd172),
_ => Err(crate::errors::Error::Isotope(crate::Element::Gd, value)),
}
}
}
impl TryFrom<u8> for GadoliniumIsotope {
type Error = crate::errors::Error;
fn try_from(value: u8) -> Result<Self, Self::Error> {
Self::try_from(u64::from(value))
}
}
impl TryFrom<u16> for GadoliniumIsotope {
type Error = crate::errors::Error;
fn try_from(value: u16) -> Result<Self, Self::Error> {
Self::try_from(u64::from(value))
}
}
impl TryFrom<u32> for GadoliniumIsotope {
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 GadoliniumIsotope {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::Gd133 => write!(f, "Gd133"),
Self::Gd134 => write!(f, "Gd134"),
Self::Gd135 => write!(f, "Gd135"),
Self::Gd136 => write!(f, "Gd136"),
Self::Gd137 => write!(f, "Gd137"),
Self::Gd138 => write!(f, "Gd138"),
Self::Gd139 => write!(f, "Gd139"),
Self::Gd140 => write!(f, "Gd140"),
Self::Gd141 => write!(f, "Gd141"),
Self::Gd142 => write!(f, "Gd142"),
Self::Gd143 => write!(f, "Gd143"),
Self::Gd144 => write!(f, "Gd144"),
Self::Gd145 => write!(f, "Gd145"),
Self::Gd146 => write!(f, "Gd146"),
Self::Gd147 => write!(f, "Gd147"),
Self::Gd148 => write!(f, "Gd148"),
Self::Gd149 => write!(f, "Gd149"),
Self::Gd150 => write!(f, "Gd150"),
Self::Gd151 => write!(f, "Gd151"),
Self::Gd152 => write!(f, "Gd152"),
Self::Gd153 => write!(f, "Gd153"),
Self::Gd154 => write!(f, "Gd154"),
Self::Gd155 => write!(f, "Gd155"),
Self::Gd156 => write!(f, "Gd156"),
Self::Gd157 => write!(f, "Gd157"),
Self::Gd158 => write!(f, "Gd158"),
Self::Gd159 => write!(f, "Gd159"),
Self::Gd160 => write!(f, "Gd160"),
Self::Gd161 => write!(f, "Gd161"),
Self::Gd162 => write!(f, "Gd162"),
Self::Gd163 => write!(f, "Gd163"),
Self::Gd164 => write!(f, "Gd164"),
Self::Gd165 => write!(f, "Gd165"),
Self::Gd166 => write!(f, "Gd166"),
Self::Gd167 => write!(f, "Gd167"),
Self::Gd168 => write!(f, "Gd168"),
Self::Gd169 => write!(f, "Gd169"),
Self::Gd170 => write!(f, "Gd170"),
Self::Gd171 => write!(f, "Gd171"),
Self::Gd172 => write!(f, "Gd172"),
}
}
}
#[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 GadoliniumIsotope::iter() {
let mass = isotope.relative_atomic_mass();
assert!(mass > 0.0, "Mass should be positive for {isotope:?}");
}
}
#[test]
fn test_element() {
for isotope in GadoliniumIsotope::iter() {
let element = isotope.element();
assert_eq!(element, crate::Element::Gd, "Element should be correct for {isotope:?}");
}
}
#[test]
fn test_mass_number() {
for isotope in GadoliniumIsotope::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 GadoliniumIsotope::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 = GadoliniumIsotope::most_abundant_isotope();
let _ = most_abundant.relative_atomic_mass();
}
#[test]
fn test_from_isotope() {
for isotope in GadoliniumIsotope::iter() {
let iso: crate::Isotope = isotope.into();
match iso {
crate::Isotope::Gd(i) => assert_eq!(i, isotope),
_ => panic!("Wrong isotope type"),
}
}
}
#[test]
fn test_from_element() {
for isotope in GadoliniumIsotope::iter() {
let elem: crate::Element = isotope.into();
assert_eq!(elem, crate::Element::Gd);
}
}
#[test]
fn test_try_from_mass_number() {
for isotope in GadoliniumIsotope::iter() {
let mass = isotope.mass_number();
let iso = GadoliniumIsotope::try_from(mass).unwrap();
assert_eq!(iso, isotope);
let iso_u32 = GadoliniumIsotope::try_from(u32::from(mass)).unwrap();
assert_eq!(iso_u32, isotope);
if let Ok(mass_u8) = u8::try_from(mass) {
let iso_u8 = GadoliniumIsotope::try_from(mass_u8).unwrap();
assert_eq!(iso_u8, isotope);
}
}
assert!(GadoliniumIsotope::try_from(0_u16).is_err());
assert!(GadoliniumIsotope::try_from(1000_u16).is_err());
assert!(GadoliniumIsotope::try_from(0_u32).is_err());
assert!(GadoliniumIsotope::try_from(1000_u32).is_err());
assert!(GadoliniumIsotope::try_from(0_u8).is_err());
}
#[test]
fn test_display() {
for isotope in GadoliniumIsotope::iter() {
let s = alloc::format!("{isotope}");
assert!(!s.is_empty(), "Display should not be empty for {isotope:?}");
}
}
}