#[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 MercuryIsotope {
Hg170,
Hg171,
Hg172,
Hg173,
Hg174,
Hg175,
Hg176,
Hg177,
Hg178,
Hg179,
Hg180,
Hg181,
Hg182,
Hg183,
Hg184,
Hg185,
Hg186,
Hg187,
Hg188,
Hg189,
Hg190,
Hg191,
Hg192,
Hg193,
Hg194,
Hg195,
Hg196,
Hg197,
Hg198,
Hg199,
Hg200,
Hg201,
Hg202,
Hg203,
Hg204,
Hg205,
Hg206,
Hg207,
Hg208,
Hg209,
Hg210,
Hg211,
Hg212,
Hg213,
Hg214,
Hg215,
Hg216,
}
impl super::RelativeAtomicMass for MercuryIsotope {
#[inline]
fn relative_atomic_mass(&self) -> f64 {
match self {
Self::Hg170 => 170.005814f64,
Self::Hg171 => 171.00353f64,
Self::Hg172 => 171.99881f64,
Self::Hg173 => 172.99709f64,
Self::Hg174 => 173.992865f64,
Self::Hg175 => 174.991441f64,
Self::Hg176 => 175.987361f64,
Self::Hg177 => 176.986277f64,
Self::Hg178 => 177.982484f64,
Self::Hg179 => 178.981831f64,
Self::Hg180 => 179.97826f64,
Self::Hg181 => 180.977819f64,
Self::Hg182 => 181.974689f64,
Self::Hg183 => 182.9744448f64,
Self::Hg184 => 183.971714f64,
Self::Hg185 => 184.971899f64,
Self::Hg186 => 185.969362f64,
Self::Hg187 => 186.969814f64,
Self::Hg188 => 187.967567f64,
Self::Hg189 => 188.968195f64,
Self::Hg190 => 189.966323f64,
Self::Hg191 => 190.967157f64,
Self::Hg192 => 191.965635f64,
Self::Hg193 => 192.966653f64,
Self::Hg194 => 193.9654491f64,
Self::Hg195 => 194.966721f64,
Self::Hg196 => 195.9658326f64,
Self::Hg197 => 196.9672128f64,
Self::Hg198 => 197.9667686f64,
Self::Hg199 => 198.96828064f64,
Self::Hg200 => 199.96832659f64,
Self::Hg201 => 200.97030284f64,
Self::Hg202 => 201.9706434f64,
Self::Hg203 => 202.9728728f64,
Self::Hg204 => 203.97349398f64,
Self::Hg205 => 204.9760734f64,
Self::Hg206 => 205.977514f64,
Self::Hg207 => 206.9823f64,
Self::Hg208 => 207.985759f64,
Self::Hg209 => 208.99072f64,
Self::Hg210 => 209.99424f64,
Self::Hg211 => 210.99933f64,
Self::Hg212 => 212.00296f64,
Self::Hg213 => 213.00823f64,
Self::Hg214 => 214.012f64,
Self::Hg215 => 215.0174f64,
Self::Hg216 => 216.02132f64,
}
}
}
impl super::ElementVariant for MercuryIsotope {
#[inline]
fn element(&self) -> crate::Element {
crate::Element::Hg
}
}
impl super::MassNumber for MercuryIsotope {
#[inline]
fn mass_number(&self) -> u16 {
match self {
Self::Hg170 => 170u16,
Self::Hg171 => 171u16,
Self::Hg172 => 172u16,
Self::Hg173 => 173u16,
Self::Hg174 => 174u16,
Self::Hg175 => 175u16,
Self::Hg176 => 176u16,
Self::Hg177 => 177u16,
Self::Hg178 => 178u16,
Self::Hg179 => 179u16,
Self::Hg180 => 180u16,
Self::Hg181 => 181u16,
Self::Hg182 => 182u16,
Self::Hg183 => 183u16,
Self::Hg184 => 184u16,
Self::Hg185 => 185u16,
Self::Hg186 => 186u16,
Self::Hg187 => 187u16,
Self::Hg188 => 188u16,
Self::Hg189 => 189u16,
Self::Hg190 => 190u16,
Self::Hg191 => 191u16,
Self::Hg192 => 192u16,
Self::Hg193 => 193u16,
Self::Hg194 => 194u16,
Self::Hg195 => 195u16,
Self::Hg196 => 196u16,
Self::Hg197 => 197u16,
Self::Hg198 => 198u16,
Self::Hg199 => 199u16,
Self::Hg200 => 200u16,
Self::Hg201 => 201u16,
Self::Hg202 => 202u16,
Self::Hg203 => 203u16,
Self::Hg204 => 204u16,
Self::Hg205 => 205u16,
Self::Hg206 => 206u16,
Self::Hg207 => 207u16,
Self::Hg208 => 208u16,
Self::Hg209 => 209u16,
Self::Hg210 => 210u16,
Self::Hg211 => 211u16,
Self::Hg212 => 212u16,
Self::Hg213 => 213u16,
Self::Hg214 => 214u16,
Self::Hg215 => 215u16,
Self::Hg216 => 216u16,
}
}
}
impl super::IsotopicComposition for MercuryIsotope {
#[inline]
fn isotopic_composition(&self) -> Option<f64> {
match self {
Self::Hg196 => Some(0.0015f64),
Self::Hg198 => Some(0.0997f64),
Self::Hg199 => Some(0.1687f64),
Self::Hg200 => Some(0.231f64),
Self::Hg201 => Some(0.1318f64),
Self::Hg202 => Some(0.2986f64),
Self::Hg204 => Some(0.0687f64),
_ => None,
}
}
}
impl super::MostAbundantIsotope for MercuryIsotope {
fn most_abundant_isotope() -> Self {
Self::Hg202
}
}
impl From<MercuryIsotope> for crate::Isotope {
fn from(isotope: MercuryIsotope) -> Self {
crate::Isotope::Hg(isotope)
}
}
impl From<MercuryIsotope> for crate::Element {
fn from(_isotope: MercuryIsotope) -> Self {
crate::Element::Hg
}
}
impl TryFrom<u64> for MercuryIsotope {
type Error = crate::errors::Error;
fn try_from(value: u64) -> Result<Self, Self::Error> {
match value {
170u64 => Ok(Self::Hg170),
171u64 => Ok(Self::Hg171),
172u64 => Ok(Self::Hg172),
173u64 => Ok(Self::Hg173),
174u64 => Ok(Self::Hg174),
175u64 => Ok(Self::Hg175),
176u64 => Ok(Self::Hg176),
177u64 => Ok(Self::Hg177),
178u64 => Ok(Self::Hg178),
179u64 => Ok(Self::Hg179),
180u64 => Ok(Self::Hg180),
181u64 => Ok(Self::Hg181),
182u64 => Ok(Self::Hg182),
183u64 => Ok(Self::Hg183),
184u64 => Ok(Self::Hg184),
185u64 => Ok(Self::Hg185),
186u64 => Ok(Self::Hg186),
187u64 => Ok(Self::Hg187),
188u64 => Ok(Self::Hg188),
189u64 => Ok(Self::Hg189),
190u64 => Ok(Self::Hg190),
191u64 => Ok(Self::Hg191),
192u64 => Ok(Self::Hg192),
193u64 => Ok(Self::Hg193),
194u64 => Ok(Self::Hg194),
195u64 => Ok(Self::Hg195),
196u64 => Ok(Self::Hg196),
197u64 => Ok(Self::Hg197),
198u64 => Ok(Self::Hg198),
199u64 => Ok(Self::Hg199),
200u64 => Ok(Self::Hg200),
201u64 => Ok(Self::Hg201),
202u64 => Ok(Self::Hg202),
203u64 => Ok(Self::Hg203),
204u64 => Ok(Self::Hg204),
205u64 => Ok(Self::Hg205),
206u64 => Ok(Self::Hg206),
207u64 => Ok(Self::Hg207),
208u64 => Ok(Self::Hg208),
209u64 => Ok(Self::Hg209),
210u64 => Ok(Self::Hg210),
211u64 => Ok(Self::Hg211),
212u64 => Ok(Self::Hg212),
213u64 => Ok(Self::Hg213),
214u64 => Ok(Self::Hg214),
215u64 => Ok(Self::Hg215),
216u64 => Ok(Self::Hg216),
_ => Err(crate::errors::Error::Isotope(crate::Element::Hg, value)),
}
}
}
impl TryFrom<u8> for MercuryIsotope {
type Error = crate::errors::Error;
fn try_from(value: u8) -> Result<Self, Self::Error> {
Self::try_from(u64::from(value))
}
}
impl TryFrom<u16> for MercuryIsotope {
type Error = crate::errors::Error;
fn try_from(value: u16) -> Result<Self, Self::Error> {
Self::try_from(u64::from(value))
}
}
impl TryFrom<u32> for MercuryIsotope {
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 MercuryIsotope {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::Hg170 => write!(f, "Hg170"),
Self::Hg171 => write!(f, "Hg171"),
Self::Hg172 => write!(f, "Hg172"),
Self::Hg173 => write!(f, "Hg173"),
Self::Hg174 => write!(f, "Hg174"),
Self::Hg175 => write!(f, "Hg175"),
Self::Hg176 => write!(f, "Hg176"),
Self::Hg177 => write!(f, "Hg177"),
Self::Hg178 => write!(f, "Hg178"),
Self::Hg179 => write!(f, "Hg179"),
Self::Hg180 => write!(f, "Hg180"),
Self::Hg181 => write!(f, "Hg181"),
Self::Hg182 => write!(f, "Hg182"),
Self::Hg183 => write!(f, "Hg183"),
Self::Hg184 => write!(f, "Hg184"),
Self::Hg185 => write!(f, "Hg185"),
Self::Hg186 => write!(f, "Hg186"),
Self::Hg187 => write!(f, "Hg187"),
Self::Hg188 => write!(f, "Hg188"),
Self::Hg189 => write!(f, "Hg189"),
Self::Hg190 => write!(f, "Hg190"),
Self::Hg191 => write!(f, "Hg191"),
Self::Hg192 => write!(f, "Hg192"),
Self::Hg193 => write!(f, "Hg193"),
Self::Hg194 => write!(f, "Hg194"),
Self::Hg195 => write!(f, "Hg195"),
Self::Hg196 => write!(f, "Hg196"),
Self::Hg197 => write!(f, "Hg197"),
Self::Hg198 => write!(f, "Hg198"),
Self::Hg199 => write!(f, "Hg199"),
Self::Hg200 => write!(f, "Hg200"),
Self::Hg201 => write!(f, "Hg201"),
Self::Hg202 => write!(f, "Hg202"),
Self::Hg203 => write!(f, "Hg203"),
Self::Hg204 => write!(f, "Hg204"),
Self::Hg205 => write!(f, "Hg205"),
Self::Hg206 => write!(f, "Hg206"),
Self::Hg207 => write!(f, "Hg207"),
Self::Hg208 => write!(f, "Hg208"),
Self::Hg209 => write!(f, "Hg209"),
Self::Hg210 => write!(f, "Hg210"),
Self::Hg211 => write!(f, "Hg211"),
Self::Hg212 => write!(f, "Hg212"),
Self::Hg213 => write!(f, "Hg213"),
Self::Hg214 => write!(f, "Hg214"),
Self::Hg215 => write!(f, "Hg215"),
Self::Hg216 => write!(f, "Hg216"),
}
}
}
#[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 MercuryIsotope::iter() {
let mass = isotope.relative_atomic_mass();
assert!(mass > 0.0, "Mass should be positive for {isotope:?}");
}
}
#[test]
fn test_element() {
for isotope in MercuryIsotope::iter() {
let element = isotope.element();
assert_eq!(element, crate::Element::Hg, "Element should be correct for {isotope:?}");
}
}
#[test]
fn test_mass_number() {
for isotope in MercuryIsotope::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 MercuryIsotope::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 = MercuryIsotope::most_abundant_isotope();
let _ = most_abundant.relative_atomic_mass();
}
#[test]
fn test_from_isotope() {
for isotope in MercuryIsotope::iter() {
let iso: crate::Isotope = isotope.into();
match iso {
crate::Isotope::Hg(i) => assert_eq!(i, isotope),
_ => panic!("Wrong isotope type"),
}
}
}
#[test]
fn test_from_element() {
for isotope in MercuryIsotope::iter() {
let elem: crate::Element = isotope.into();
assert_eq!(elem, crate::Element::Hg);
}
}
#[test]
fn test_try_from_mass_number() {
for isotope in MercuryIsotope::iter() {
let mass = isotope.mass_number();
let iso = MercuryIsotope::try_from(mass).unwrap();
assert_eq!(iso, isotope);
let iso_u32 = MercuryIsotope::try_from(u32::from(mass)).unwrap();
assert_eq!(iso_u32, isotope);
if let Ok(mass_u8) = u8::try_from(mass) {
let iso_u8 = MercuryIsotope::try_from(mass_u8).unwrap();
assert_eq!(iso_u8, isotope);
}
}
assert!(MercuryIsotope::try_from(0_u16).is_err());
assert!(MercuryIsotope::try_from(1000_u16).is_err());
assert!(MercuryIsotope::try_from(0_u32).is_err());
assert!(MercuryIsotope::try_from(1000_u32).is_err());
assert!(MercuryIsotope::try_from(0_u8).is_err());
}
#[test]
fn test_display() {
for isotope in MercuryIsotope::iter() {
let s = alloc::format!("{isotope}");
assert!(!s.is_empty(), "Display should not be empty for {isotope:?}");
}
}
}