#[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))]
pub enum HafniumIsotope {
Hf153,
Hf154,
Hf155,
Hf156,
Hf157,
Hf158,
Hf159,
Hf160,
Hf161,
Hf162,
Hf163,
Hf164,
Hf165,
Hf166,
Hf167,
Hf168,
Hf169,
Hf170,
Hf171,
Hf172,
Hf173,
Hf174,
Hf175,
Hf176,
Hf177,
Hf178,
Hf179,
Hf180,
Hf181,
Hf182,
Hf183,
Hf184,
Hf185,
Hf186,
Hf187,
Hf188,
Hf189,
Hf190,
}
impl super::RelativeAtomicMass for HafniumIsotope {
#[inline]
fn relative_atomic_mass(&self) -> f64 {
match self {
Self::Hf153 => 152.97069f64,
Self::Hf154 => 153.96486f64,
Self::Hf155 => 154.96311f64,
Self::Hf156 => 155.95935f64,
Self::Hf157 => 156.95824f64,
Self::Hf158 => 157.954801f64,
Self::Hf159 => 158.953996f64,
Self::Hf160 => 159.950691f64,
Self::Hf161 => 160.950278f64,
Self::Hf162 => 161.9472148f64,
Self::Hf163 => 162.947113f64,
Self::Hf164 => 163.944371f64,
Self::Hf165 => 164.944567f64,
Self::Hf166 => 165.94218f64,
Self::Hf167 => 166.9426f64,
Self::Hf168 => 167.940568f64,
Self::Hf169 => 168.941259f64,
Self::Hf170 => 169.939609f64,
Self::Hf171 => 170.940492f64,
Self::Hf172 => 171.93945f64,
Self::Hf173 => 172.940513f64,
Self::Hf174 => 173.9400461f64,
Self::Hf175 => 174.9415092f64,
Self::Hf176 => 175.9414076f64,
Self::Hf177 => 176.9432277f64,
Self::Hf178 => 177.9437058f64,
Self::Hf179 => 178.9458232f64,
Self::Hf180 => 179.946557f64,
Self::Hf181 => 180.9491083f64,
Self::Hf182 => 181.9505612f64,
Self::Hf183 => 182.95353f64,
Self::Hf184 => 183.955446f64,
Self::Hf185 => 184.958862f64,
Self::Hf186 => 185.960897f64,
Self::Hf187 => 186.96477f64,
Self::Hf188 => 187.96685f64,
Self::Hf189 => 188.97084f64,
Self::Hf190 => 189.973376f64,
}
}
}
impl super::ElementVariant for HafniumIsotope {
#[inline]
fn element(&self) -> crate::Element {
crate::Element::Hf
}
}
impl super::MassNumber for HafniumIsotope {
#[inline]
fn mass_number(&self) -> u16 {
match self {
Self::Hf153 => 153u16,
Self::Hf154 => 154u16,
Self::Hf155 => 155u16,
Self::Hf156 => 156u16,
Self::Hf157 => 157u16,
Self::Hf158 => 158u16,
Self::Hf159 => 159u16,
Self::Hf160 => 160u16,
Self::Hf161 => 161u16,
Self::Hf162 => 162u16,
Self::Hf163 => 163u16,
Self::Hf164 => 164u16,
Self::Hf165 => 165u16,
Self::Hf166 => 166u16,
Self::Hf167 => 167u16,
Self::Hf168 => 168u16,
Self::Hf169 => 169u16,
Self::Hf170 => 170u16,
Self::Hf171 => 171u16,
Self::Hf172 => 172u16,
Self::Hf173 => 173u16,
Self::Hf174 => 174u16,
Self::Hf175 => 175u16,
Self::Hf176 => 176u16,
Self::Hf177 => 177u16,
Self::Hf178 => 178u16,
Self::Hf179 => 179u16,
Self::Hf180 => 180u16,
Self::Hf181 => 181u16,
Self::Hf182 => 182u16,
Self::Hf183 => 183u16,
Self::Hf184 => 184u16,
Self::Hf185 => 185u16,
Self::Hf186 => 186u16,
Self::Hf187 => 187u16,
Self::Hf188 => 188u16,
Self::Hf189 => 189u16,
Self::Hf190 => 190u16,
}
}
}
impl super::IsotopicComposition for HafniumIsotope {
#[inline]
fn isotopic_composition(&self) -> Option<f64> {
match self {
Self::Hf174 => Some(0.0016f64),
Self::Hf176 => Some(0.0526f64),
Self::Hf177 => Some(0.186f64),
Self::Hf178 => Some(0.2728f64),
Self::Hf179 => Some(0.1362f64),
Self::Hf180 => Some(0.3508f64),
_ => None,
}
}
}
impl super::MostAbundantIsotope for HafniumIsotope {
fn most_abundant_isotope() -> Self {
Self::Hf180
}
}
impl From<HafniumIsotope> for crate::Isotope {
fn from(isotope: HafniumIsotope) -> Self {
crate::Isotope::Hf(isotope)
}
}
impl From<HafniumIsotope> for crate::Element {
fn from(_isotope: HafniumIsotope) -> Self {
crate::Element::Hf
}
}
impl TryFrom<u64> for HafniumIsotope {
type Error = crate::errors::Error;
fn try_from(value: u64) -> Result<Self, Self::Error> {
match value {
153u64 => Ok(Self::Hf153),
154u64 => Ok(Self::Hf154),
155u64 => Ok(Self::Hf155),
156u64 => Ok(Self::Hf156),
157u64 => Ok(Self::Hf157),
158u64 => Ok(Self::Hf158),
159u64 => Ok(Self::Hf159),
160u64 => Ok(Self::Hf160),
161u64 => Ok(Self::Hf161),
162u64 => Ok(Self::Hf162),
163u64 => Ok(Self::Hf163),
164u64 => Ok(Self::Hf164),
165u64 => Ok(Self::Hf165),
166u64 => Ok(Self::Hf166),
167u64 => Ok(Self::Hf167),
168u64 => Ok(Self::Hf168),
169u64 => Ok(Self::Hf169),
170u64 => Ok(Self::Hf170),
171u64 => Ok(Self::Hf171),
172u64 => Ok(Self::Hf172),
173u64 => Ok(Self::Hf173),
174u64 => Ok(Self::Hf174),
175u64 => Ok(Self::Hf175),
176u64 => Ok(Self::Hf176),
177u64 => Ok(Self::Hf177),
178u64 => Ok(Self::Hf178),
179u64 => Ok(Self::Hf179),
180u64 => Ok(Self::Hf180),
181u64 => Ok(Self::Hf181),
182u64 => Ok(Self::Hf182),
183u64 => Ok(Self::Hf183),
184u64 => Ok(Self::Hf184),
185u64 => Ok(Self::Hf185),
186u64 => Ok(Self::Hf186),
187u64 => Ok(Self::Hf187),
188u64 => Ok(Self::Hf188),
189u64 => Ok(Self::Hf189),
190u64 => Ok(Self::Hf190),
_ => Err(crate::errors::Error::Isotope(crate::Element::Hf, value)),
}
}
}
impl TryFrom<u8> for HafniumIsotope {
type Error = crate::errors::Error;
fn try_from(value: u8) -> Result<Self, Self::Error> {
Self::try_from(u64::from(value))
}
}
impl TryFrom<u16> for HafniumIsotope {
type Error = crate::errors::Error;
fn try_from(value: u16) -> Result<Self, Self::Error> {
Self::try_from(u64::from(value))
}
}
impl TryFrom<u32> for HafniumIsotope {
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 HafniumIsotope {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::Hf153 => write!(f, "Hf153"),
Self::Hf154 => write!(f, "Hf154"),
Self::Hf155 => write!(f, "Hf155"),
Self::Hf156 => write!(f, "Hf156"),
Self::Hf157 => write!(f, "Hf157"),
Self::Hf158 => write!(f, "Hf158"),
Self::Hf159 => write!(f, "Hf159"),
Self::Hf160 => write!(f, "Hf160"),
Self::Hf161 => write!(f, "Hf161"),
Self::Hf162 => write!(f, "Hf162"),
Self::Hf163 => write!(f, "Hf163"),
Self::Hf164 => write!(f, "Hf164"),
Self::Hf165 => write!(f, "Hf165"),
Self::Hf166 => write!(f, "Hf166"),
Self::Hf167 => write!(f, "Hf167"),
Self::Hf168 => write!(f, "Hf168"),
Self::Hf169 => write!(f, "Hf169"),
Self::Hf170 => write!(f, "Hf170"),
Self::Hf171 => write!(f, "Hf171"),
Self::Hf172 => write!(f, "Hf172"),
Self::Hf173 => write!(f, "Hf173"),
Self::Hf174 => write!(f, "Hf174"),
Self::Hf175 => write!(f, "Hf175"),
Self::Hf176 => write!(f, "Hf176"),
Self::Hf177 => write!(f, "Hf177"),
Self::Hf178 => write!(f, "Hf178"),
Self::Hf179 => write!(f, "Hf179"),
Self::Hf180 => write!(f, "Hf180"),
Self::Hf181 => write!(f, "Hf181"),
Self::Hf182 => write!(f, "Hf182"),
Self::Hf183 => write!(f, "Hf183"),
Self::Hf184 => write!(f, "Hf184"),
Self::Hf185 => write!(f, "Hf185"),
Self::Hf186 => write!(f, "Hf186"),
Self::Hf187 => write!(f, "Hf187"),
Self::Hf188 => write!(f, "Hf188"),
Self::Hf189 => write!(f, "Hf189"),
Self::Hf190 => write!(f, "Hf190"),
}
}
}
#[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 HafniumIsotope::iter() {
let mass = isotope.relative_atomic_mass();
assert!(mass > 0.0, "Mass should be positive for {isotope:?}");
}
}
#[test]
fn test_element() {
for isotope in HafniumIsotope::iter() {
let element = isotope.element();
assert_eq!(element, crate::Element::Hf, "Element should be correct for {isotope:?}");
}
}
#[test]
fn test_mass_number() {
for isotope in HafniumIsotope::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 HafniumIsotope::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 = HafniumIsotope::most_abundant_isotope();
let _ = most_abundant.relative_atomic_mass();
}
#[test]
fn test_from_isotope() {
for isotope in HafniumIsotope::iter() {
let iso: crate::Isotope = isotope.into();
match iso {
crate::Isotope::Hf(i) => assert_eq!(i, isotope),
_ => panic!("Wrong isotope type"),
}
}
}
#[test]
fn test_from_element() {
for isotope in HafniumIsotope::iter() {
let elem: crate::Element = isotope.into();
assert_eq!(elem, crate::Element::Hf);
}
}
#[test]
fn test_try_from_mass_number() {
for isotope in HafniumIsotope::iter() {
let mass = isotope.mass_number();
let iso = HafniumIsotope::try_from(mass).unwrap();
assert_eq!(iso, isotope);
let iso_u32 = HafniumIsotope::try_from(u32::from(mass)).unwrap();
assert_eq!(iso_u32, isotope);
if let Ok(mass_u8) = u8::try_from(mass) {
let iso_u8 = HafniumIsotope::try_from(mass_u8).unwrap();
assert_eq!(iso_u8, isotope);
}
}
assert!(HafniumIsotope::try_from(0_u16).is_err());
assert!(HafniumIsotope::try_from(1000_u16).is_err());
assert!(HafniumIsotope::try_from(0_u32).is_err());
assert!(HafniumIsotope::try_from(1000_u32).is_err());
assert!(HafniumIsotope::try_from(0_u8).is_err());
}
#[test]
fn test_display() {
for isotope in HafniumIsotope::iter() {
let s = alloc::format!("{isotope}");
assert!(!s.is_empty(), "Display should not be empty for {isotope:?}");
}
}
}