#[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 TantalumIsotope {
Ta155,
Ta156,
Ta157,
Ta158,
Ta159,
Ta160,
Ta161,
Ta162,
Ta163,
Ta164,
Ta165,
Ta166,
Ta167,
Ta168,
Ta169,
Ta170,
Ta171,
Ta172,
Ta173,
Ta174,
Ta175,
Ta176,
Ta177,
Ta178,
Ta179,
Ta180,
Ta181,
Ta182,
Ta183,
Ta184,
Ta185,
Ta186,
Ta187,
Ta188,
Ta189,
Ta190,
Ta191,
Ta192,
Ta193,
Ta194,
}
impl super::RelativeAtomicMass for TantalumIsotope {
#[inline]
fn relative_atomic_mass(&self) -> f64 {
match self {
Self::Ta155 => 154.97424f64,
Self::Ta156 => 155.97203f64,
Self::Ta157 => 156.96818f64,
Self::Ta158 => 157.96654f64,
Self::Ta159 => 158.963023f64,
Self::Ta160 => 159.961488f64,
Self::Ta161 => 160.958452f64,
Self::Ta162 => 161.957294f64,
Self::Ta163 => 162.954337f64,
Self::Ta164 => 163.953534f64,
Self::Ta165 => 164.950781f64,
Self::Ta166 => 165.950512f64,
Self::Ta167 => 166.948093f64,
Self::Ta168 => 167.948047f64,
Self::Ta169 => 168.946011f64,
Self::Ta170 => 169.946175f64,
Self::Ta171 => 170.944476f64,
Self::Ta172 => 171.944895f64,
Self::Ta173 => 172.94375f64,
Self::Ta174 => 173.944454f64,
Self::Ta175 => 174.943737f64,
Self::Ta176 => 175.944857f64,
Self::Ta177 => 176.9444795f64,
Self::Ta178 => 177.945678f64,
Self::Ta179 => 178.9459366f64,
Self::Ta180 => 179.9474648f64,
Self::Ta181 => 180.9479958f64,
Self::Ta182 => 181.9501519f64,
Self::Ta183 => 182.9513726f64,
Self::Ta184 => 183.954008f64,
Self::Ta185 => 184.955559f64,
Self::Ta186 => 185.958551f64,
Self::Ta187 => 186.960386f64,
Self::Ta188 => 187.963916f64,
Self::Ta189 => 188.96583f64,
Self::Ta190 => 189.96939f64,
Self::Ta191 => 190.97156f64,
Self::Ta192 => 191.97514f64,
Self::Ta193 => 192.97766f64,
Self::Ta194 => 193.98161f64,
}
}
}
impl super::ElementVariant for TantalumIsotope {
#[inline]
fn element(&self) -> crate::Element {
crate::Element::Ta
}
}
impl super::MassNumber for TantalumIsotope {
#[inline]
fn mass_number(&self) -> u16 {
match self {
Self::Ta155 => 155u16,
Self::Ta156 => 156u16,
Self::Ta157 => 157u16,
Self::Ta158 => 158u16,
Self::Ta159 => 159u16,
Self::Ta160 => 160u16,
Self::Ta161 => 161u16,
Self::Ta162 => 162u16,
Self::Ta163 => 163u16,
Self::Ta164 => 164u16,
Self::Ta165 => 165u16,
Self::Ta166 => 166u16,
Self::Ta167 => 167u16,
Self::Ta168 => 168u16,
Self::Ta169 => 169u16,
Self::Ta170 => 170u16,
Self::Ta171 => 171u16,
Self::Ta172 => 172u16,
Self::Ta173 => 173u16,
Self::Ta174 => 174u16,
Self::Ta175 => 175u16,
Self::Ta176 => 176u16,
Self::Ta177 => 177u16,
Self::Ta178 => 178u16,
Self::Ta179 => 179u16,
Self::Ta180 => 180u16,
Self::Ta181 => 181u16,
Self::Ta182 => 182u16,
Self::Ta183 => 183u16,
Self::Ta184 => 184u16,
Self::Ta185 => 185u16,
Self::Ta186 => 186u16,
Self::Ta187 => 187u16,
Self::Ta188 => 188u16,
Self::Ta189 => 189u16,
Self::Ta190 => 190u16,
Self::Ta191 => 191u16,
Self::Ta192 => 192u16,
Self::Ta193 => 193u16,
Self::Ta194 => 194u16,
}
}
}
impl super::IsotopicComposition for TantalumIsotope {
#[inline]
fn isotopic_composition(&self) -> Option<f64> {
match self {
Self::Ta180 => Some(0.0001201f64),
Self::Ta181 => Some(0.9998799f64),
_ => None,
}
}
}
impl super::MostAbundantIsotope for TantalumIsotope {
fn most_abundant_isotope() -> Self {
Self::Ta181
}
}
impl From<TantalumIsotope> for crate::Isotope {
fn from(isotope: TantalumIsotope) -> Self {
crate::Isotope::Ta(isotope)
}
}
impl From<TantalumIsotope> for crate::Element {
fn from(_isotope: TantalumIsotope) -> Self {
crate::Element::Ta
}
}
impl TryFrom<u64> for TantalumIsotope {
type Error = crate::errors::Error;
fn try_from(value: u64) -> Result<Self, Self::Error> {
match value {
155u64 => Ok(Self::Ta155),
156u64 => Ok(Self::Ta156),
157u64 => Ok(Self::Ta157),
158u64 => Ok(Self::Ta158),
159u64 => Ok(Self::Ta159),
160u64 => Ok(Self::Ta160),
161u64 => Ok(Self::Ta161),
162u64 => Ok(Self::Ta162),
163u64 => Ok(Self::Ta163),
164u64 => Ok(Self::Ta164),
165u64 => Ok(Self::Ta165),
166u64 => Ok(Self::Ta166),
167u64 => Ok(Self::Ta167),
168u64 => Ok(Self::Ta168),
169u64 => Ok(Self::Ta169),
170u64 => Ok(Self::Ta170),
171u64 => Ok(Self::Ta171),
172u64 => Ok(Self::Ta172),
173u64 => Ok(Self::Ta173),
174u64 => Ok(Self::Ta174),
175u64 => Ok(Self::Ta175),
176u64 => Ok(Self::Ta176),
177u64 => Ok(Self::Ta177),
178u64 => Ok(Self::Ta178),
179u64 => Ok(Self::Ta179),
180u64 => Ok(Self::Ta180),
181u64 => Ok(Self::Ta181),
182u64 => Ok(Self::Ta182),
183u64 => Ok(Self::Ta183),
184u64 => Ok(Self::Ta184),
185u64 => Ok(Self::Ta185),
186u64 => Ok(Self::Ta186),
187u64 => Ok(Self::Ta187),
188u64 => Ok(Self::Ta188),
189u64 => Ok(Self::Ta189),
190u64 => Ok(Self::Ta190),
191u64 => Ok(Self::Ta191),
192u64 => Ok(Self::Ta192),
193u64 => Ok(Self::Ta193),
194u64 => Ok(Self::Ta194),
_ => Err(crate::errors::Error::Isotope(crate::Element::Ta, value)),
}
}
}
impl TryFrom<u8> for TantalumIsotope {
type Error = crate::errors::Error;
fn try_from(value: u8) -> Result<Self, Self::Error> {
Self::try_from(u64::from(value))
}
}
impl TryFrom<u16> for TantalumIsotope {
type Error = crate::errors::Error;
fn try_from(value: u16) -> Result<Self, Self::Error> {
Self::try_from(u64::from(value))
}
}
impl TryFrom<u32> for TantalumIsotope {
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 TantalumIsotope {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::Ta155 => write!(f, "Ta155"),
Self::Ta156 => write!(f, "Ta156"),
Self::Ta157 => write!(f, "Ta157"),
Self::Ta158 => write!(f, "Ta158"),
Self::Ta159 => write!(f, "Ta159"),
Self::Ta160 => write!(f, "Ta160"),
Self::Ta161 => write!(f, "Ta161"),
Self::Ta162 => write!(f, "Ta162"),
Self::Ta163 => write!(f, "Ta163"),
Self::Ta164 => write!(f, "Ta164"),
Self::Ta165 => write!(f, "Ta165"),
Self::Ta166 => write!(f, "Ta166"),
Self::Ta167 => write!(f, "Ta167"),
Self::Ta168 => write!(f, "Ta168"),
Self::Ta169 => write!(f, "Ta169"),
Self::Ta170 => write!(f, "Ta170"),
Self::Ta171 => write!(f, "Ta171"),
Self::Ta172 => write!(f, "Ta172"),
Self::Ta173 => write!(f, "Ta173"),
Self::Ta174 => write!(f, "Ta174"),
Self::Ta175 => write!(f, "Ta175"),
Self::Ta176 => write!(f, "Ta176"),
Self::Ta177 => write!(f, "Ta177"),
Self::Ta178 => write!(f, "Ta178"),
Self::Ta179 => write!(f, "Ta179"),
Self::Ta180 => write!(f, "Ta180"),
Self::Ta181 => write!(f, "Ta181"),
Self::Ta182 => write!(f, "Ta182"),
Self::Ta183 => write!(f, "Ta183"),
Self::Ta184 => write!(f, "Ta184"),
Self::Ta185 => write!(f, "Ta185"),
Self::Ta186 => write!(f, "Ta186"),
Self::Ta187 => write!(f, "Ta187"),
Self::Ta188 => write!(f, "Ta188"),
Self::Ta189 => write!(f, "Ta189"),
Self::Ta190 => write!(f, "Ta190"),
Self::Ta191 => write!(f, "Ta191"),
Self::Ta192 => write!(f, "Ta192"),
Self::Ta193 => write!(f, "Ta193"),
Self::Ta194 => write!(f, "Ta194"),
}
}
}
#[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 TantalumIsotope::iter() {
let mass = isotope.relative_atomic_mass();
assert!(mass > 0.0, "Mass should be positive for {isotope:?}");
}
}
#[test]
fn test_element() {
for isotope in TantalumIsotope::iter() {
let element = isotope.element();
assert_eq!(element, crate::Element::Ta, "Element should be correct for {isotope:?}");
}
}
#[test]
fn test_mass_number() {
for isotope in TantalumIsotope::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 TantalumIsotope::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 = TantalumIsotope::most_abundant_isotope();
let _ = most_abundant.relative_atomic_mass();
}
#[test]
fn test_from_isotope() {
for isotope in TantalumIsotope::iter() {
let iso: crate::Isotope = isotope.into();
match iso {
crate::Isotope::Ta(i) => assert_eq!(i, isotope),
_ => panic!("Wrong isotope type"),
}
}
}
#[test]
fn test_from_element() {
for isotope in TantalumIsotope::iter() {
let elem: crate::Element = isotope.into();
assert_eq!(elem, crate::Element::Ta);
}
}
#[test]
fn test_try_from_mass_number() {
for isotope in TantalumIsotope::iter() {
let mass = isotope.mass_number();
let iso = TantalumIsotope::try_from(mass).unwrap();
assert_eq!(iso, isotope);
let iso_u32 = TantalumIsotope::try_from(u32::from(mass)).unwrap();
assert_eq!(iso_u32, isotope);
if let Ok(mass_u8) = u8::try_from(mass) {
let iso_u8 = TantalumIsotope::try_from(mass_u8).unwrap();
assert_eq!(iso_u8, isotope);
}
}
assert!(TantalumIsotope::try_from(0_u16).is_err());
assert!(TantalumIsotope::try_from(1000_u16).is_err());
assert!(TantalumIsotope::try_from(0_u32).is_err());
assert!(TantalumIsotope::try_from(1000_u32).is_err());
assert!(TantalumIsotope::try_from(0_u8).is_err());
}
#[test]
fn test_display() {
for isotope in TantalumIsotope::iter() {
let s = alloc::format!("{isotope}");
assert!(!s.is_empty(), "Display should not be empty for {isotope:?}");
}
}
}