#[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 TitaniumIsotope {
Ti38,
Ti39,
Ti40,
Ti41,
Ti42,
Ti43,
Ti44,
Ti45,
Ti46,
Ti47,
Ti48,
Ti49,
Ti50,
Ti51,
Ti52,
Ti53,
Ti54,
Ti55,
Ti56,
Ti57,
Ti58,
Ti59,
Ti60,
Ti61,
Ti62,
Ti63,
Ti64,
Ti65,
}
impl super::RelativeAtomicMass for TitaniumIsotope {
#[inline]
fn relative_atomic_mass(&self) -> f64 {
match self {
Self::Ti38 => 38.01145f64,
Self::Ti39 => 39.00236f64,
Self::Ti40 => 39.9905f64,
Self::Ti41 => 40.983148f64,
Self::Ti42 => 41.97304903f64,
Self::Ti43 => 42.9685225f64,
Self::Ti44 => 43.95968995f64,
Self::Ti45 => 44.95812198f64,
Self::Ti46 => 45.95262772f64,
Self::Ti47 => 46.95175879f64,
Self::Ti48 => 47.94794198f64,
Self::Ti49 => 48.94786568f64,
Self::Ti50 => 49.94478689f64,
Self::Ti51 => 50.94661065f64,
Self::Ti52 => 51.946893f64,
Self::Ti53 => 52.94973f64,
Self::Ti54 => 53.95105f64,
Self::Ti55 => 54.95527f64,
Self::Ti56 => 55.95791f64,
Self::Ti57 => 56.96364f64,
Self::Ti58 => 57.9666f64,
Self::Ti59 => 58.97247f64,
Self::Ti60 => 59.97603f64,
Self::Ti61 => 60.98245f64,
Self::Ti62 => 61.98651f64,
Self::Ti63 => 62.99375f64,
Self::Ti64 => 63.998411f64,
Self::Ti65 => 65.005593f64,
}
}
}
impl super::ElementVariant for TitaniumIsotope {
#[inline]
fn element(&self) -> crate::Element {
crate::Element::Ti
}
}
impl super::MassNumber for TitaniumIsotope {
#[inline]
fn mass_number(&self) -> u16 {
match self {
Self::Ti38 => 38u16,
Self::Ti39 => 39u16,
Self::Ti40 => 40u16,
Self::Ti41 => 41u16,
Self::Ti42 => 42u16,
Self::Ti43 => 43u16,
Self::Ti44 => 44u16,
Self::Ti45 => 45u16,
Self::Ti46 => 46u16,
Self::Ti47 => 47u16,
Self::Ti48 => 48u16,
Self::Ti49 => 49u16,
Self::Ti50 => 50u16,
Self::Ti51 => 51u16,
Self::Ti52 => 52u16,
Self::Ti53 => 53u16,
Self::Ti54 => 54u16,
Self::Ti55 => 55u16,
Self::Ti56 => 56u16,
Self::Ti57 => 57u16,
Self::Ti58 => 58u16,
Self::Ti59 => 59u16,
Self::Ti60 => 60u16,
Self::Ti61 => 61u16,
Self::Ti62 => 62u16,
Self::Ti63 => 63u16,
Self::Ti64 => 64u16,
Self::Ti65 => 65u16,
}
}
}
impl super::IsotopicComposition for TitaniumIsotope {
#[inline]
fn isotopic_composition(&self) -> Option<f64> {
match self {
Self::Ti46 => Some(0.0825f64),
Self::Ti47 => Some(0.0744f64),
Self::Ti48 => Some(0.7372f64),
Self::Ti49 => Some(0.0541f64),
Self::Ti50 => Some(0.0518f64),
_ => None,
}
}
}
impl super::MostAbundantIsotope for TitaniumIsotope {
fn most_abundant_isotope() -> Self {
Self::Ti48
}
}
impl From<TitaniumIsotope> for crate::Isotope {
fn from(isotope: TitaniumIsotope) -> Self {
crate::Isotope::Ti(isotope)
}
}
impl From<TitaniumIsotope> for crate::Element {
fn from(_isotope: TitaniumIsotope) -> Self {
crate::Element::Ti
}
}
impl TryFrom<u64> for TitaniumIsotope {
type Error = crate::errors::Error;
fn try_from(value: u64) -> Result<Self, Self::Error> {
match value {
38u64 => Ok(Self::Ti38),
39u64 => Ok(Self::Ti39),
40u64 => Ok(Self::Ti40),
41u64 => Ok(Self::Ti41),
42u64 => Ok(Self::Ti42),
43u64 => Ok(Self::Ti43),
44u64 => Ok(Self::Ti44),
45u64 => Ok(Self::Ti45),
46u64 => Ok(Self::Ti46),
47u64 => Ok(Self::Ti47),
48u64 => Ok(Self::Ti48),
49u64 => Ok(Self::Ti49),
50u64 => Ok(Self::Ti50),
51u64 => Ok(Self::Ti51),
52u64 => Ok(Self::Ti52),
53u64 => Ok(Self::Ti53),
54u64 => Ok(Self::Ti54),
55u64 => Ok(Self::Ti55),
56u64 => Ok(Self::Ti56),
57u64 => Ok(Self::Ti57),
58u64 => Ok(Self::Ti58),
59u64 => Ok(Self::Ti59),
60u64 => Ok(Self::Ti60),
61u64 => Ok(Self::Ti61),
62u64 => Ok(Self::Ti62),
63u64 => Ok(Self::Ti63),
64u64 => Ok(Self::Ti64),
65u64 => Ok(Self::Ti65),
_ => Err(crate::errors::Error::Isotope(crate::Element::Ti, value)),
}
}
}
impl TryFrom<u8> for TitaniumIsotope {
type Error = crate::errors::Error;
fn try_from(value: u8) -> Result<Self, Self::Error> {
Self::try_from(u64::from(value))
}
}
impl TryFrom<u16> for TitaniumIsotope {
type Error = crate::errors::Error;
fn try_from(value: u16) -> Result<Self, Self::Error> {
Self::try_from(u64::from(value))
}
}
impl TryFrom<u32> for TitaniumIsotope {
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 TitaniumIsotope {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::Ti38 => write!(f, "Ti38"),
Self::Ti39 => write!(f, "Ti39"),
Self::Ti40 => write!(f, "Ti40"),
Self::Ti41 => write!(f, "Ti41"),
Self::Ti42 => write!(f, "Ti42"),
Self::Ti43 => write!(f, "Ti43"),
Self::Ti44 => write!(f, "Ti44"),
Self::Ti45 => write!(f, "Ti45"),
Self::Ti46 => write!(f, "Ti46"),
Self::Ti47 => write!(f, "Ti47"),
Self::Ti48 => write!(f, "Ti48"),
Self::Ti49 => write!(f, "Ti49"),
Self::Ti50 => write!(f, "Ti50"),
Self::Ti51 => write!(f, "Ti51"),
Self::Ti52 => write!(f, "Ti52"),
Self::Ti53 => write!(f, "Ti53"),
Self::Ti54 => write!(f, "Ti54"),
Self::Ti55 => write!(f, "Ti55"),
Self::Ti56 => write!(f, "Ti56"),
Self::Ti57 => write!(f, "Ti57"),
Self::Ti58 => write!(f, "Ti58"),
Self::Ti59 => write!(f, "Ti59"),
Self::Ti60 => write!(f, "Ti60"),
Self::Ti61 => write!(f, "Ti61"),
Self::Ti62 => write!(f, "Ti62"),
Self::Ti63 => write!(f, "Ti63"),
Self::Ti64 => write!(f, "Ti64"),
Self::Ti65 => write!(f, "Ti65"),
}
}
}
#[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 TitaniumIsotope::iter() {
let mass = isotope.relative_atomic_mass();
assert!(mass > 0.0, "Mass should be positive for {isotope:?}");
}
}
#[test]
fn test_element() {
for isotope in TitaniumIsotope::iter() {
let element = isotope.element();
assert_eq!(element, crate::Element::Ti, "Element should be correct for {isotope:?}");
}
}
#[test]
fn test_mass_number() {
for isotope in TitaniumIsotope::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 TitaniumIsotope::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 = TitaniumIsotope::most_abundant_isotope();
let _ = most_abundant.relative_atomic_mass();
}
#[test]
fn test_from_isotope() {
for isotope in TitaniumIsotope::iter() {
let iso: crate::Isotope = isotope.into();
match iso {
crate::Isotope::Ti(i) => assert_eq!(i, isotope),
_ => panic!("Wrong isotope type"),
}
}
}
#[test]
fn test_from_element() {
for isotope in TitaniumIsotope::iter() {
let elem: crate::Element = isotope.into();
assert_eq!(elem, crate::Element::Ti);
}
}
#[test]
fn test_try_from_mass_number() {
for isotope in TitaniumIsotope::iter() {
let mass = isotope.mass_number();
let iso = TitaniumIsotope::try_from(mass).unwrap();
assert_eq!(iso, isotope);
let iso_u32 = TitaniumIsotope::try_from(u32::from(mass)).unwrap();
assert_eq!(iso_u32, isotope);
if let Ok(mass_u8) = u8::try_from(mass) {
let iso_u8 = TitaniumIsotope::try_from(mass_u8).unwrap();
assert_eq!(iso_u8, isotope);
}
}
assert!(TitaniumIsotope::try_from(0_u16).is_err());
assert!(TitaniumIsotope::try_from(1000_u16).is_err());
assert!(TitaniumIsotope::try_from(0_u32).is_err());
assert!(TitaniumIsotope::try_from(1000_u32).is_err());
assert!(TitaniumIsotope::try_from(0_u8).is_err());
}
#[test]
fn test_display() {
for isotope in TitaniumIsotope::iter() {
let s = alloc::format!("{isotope}");
assert!(!s.is_empty(), "Display should not be empty for {isotope:?}");
}
}
}