elements_rs/isotopes/
lawrencium.rs

1//! Isotopes of the element Lawrencium
2#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, strum :: EnumIter)]
3#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
4/// Isotopes of the element Lawrencium
5pub enum LawrenciumIsotope {
6    /// Isotope Lr251 of Lawrencium
7    Lr251,
8    /// Isotope Lr252 of Lawrencium
9    Lr252,
10    /// Isotope Lr253 of Lawrencium
11    Lr253,
12    /// Isotope Lr254 of Lawrencium
13    Lr254,
14    /// Isotope Lr255 of Lawrencium
15    Lr255,
16    /// Isotope Lr256 of Lawrencium
17    Lr256,
18    /// Isotope Lr257 of Lawrencium
19    Lr257,
20    /// Isotope Lr258 of Lawrencium
21    Lr258,
22    /// Isotope Lr259 of Lawrencium
23    Lr259,
24    /// Isotope Lr260 of Lawrencium
25    Lr260,
26    /// Isotope Lr261 of Lawrencium
27    Lr261,
28    /// Isotope Lr262 of Lawrencium
29    Lr262,
30    /// Isotope Lr263 of Lawrencium
31    Lr263,
32    /// Isotope Lr264 of Lawrencium
33    Lr264,
34    /// Isotope Lr265 of Lawrencium
35    Lr265,
36    /// Isotope Lr266 of Lawrencium
37    Lr266,
38}
39impl super::RelativeAtomicMass for LawrenciumIsotope {
40    #[inline]
41    fn relative_atomic_mass(&self) -> f64 {
42        match self {
43            Self::Lr251 => 251.09418f64,
44            Self::Lr252 => 252.09526f64,
45            Self::Lr253 => 253.09509f64,
46            Self::Lr254 => 254.09648f64,
47            Self::Lr255 => 255.096562f64,
48            Self::Lr256 => 256.098494f64,
49            Self::Lr257 => 257.099418f64,
50            Self::Lr258 => 258.10176f64,
51            Self::Lr259 => 259.102902f64,
52            Self::Lr260 => 260.1055f64,
53            Self::Lr261 => 261.10688f64,
54            Self::Lr262 => 262.10961f64,
55            Self::Lr263 => 263.11136f64,
56            Self::Lr264 => 264.1142f64,
57            Self::Lr265 => 265.11619f64,
58            Self::Lr266 => 266.11983f64,
59        }
60    }
61}
62impl super::ElementVariant for LawrenciumIsotope {
63    #[inline]
64    fn element(&self) -> crate::Element {
65        crate::Element::Lr
66    }
67}
68impl super::MassNumber for LawrenciumIsotope {
69    #[inline]
70    fn mass_number(&self) -> u16 {
71        match self {
72            Self::Lr251 => 251u16,
73            Self::Lr252 => 252u16,
74            Self::Lr253 => 253u16,
75            Self::Lr254 => 254u16,
76            Self::Lr255 => 255u16,
77            Self::Lr256 => 256u16,
78            Self::Lr257 => 257u16,
79            Self::Lr258 => 258u16,
80            Self::Lr259 => 259u16,
81            Self::Lr260 => 260u16,
82            Self::Lr261 => 261u16,
83            Self::Lr262 => 262u16,
84            Self::Lr263 => 263u16,
85            Self::Lr264 => 264u16,
86            Self::Lr265 => 265u16,
87            Self::Lr266 => 266u16,
88        }
89    }
90}
91impl super::IsotopicComposition for LawrenciumIsotope {
92    #[inline]
93    fn isotopic_composition(&self) -> Option<f64> {
94        None
95    }
96}
97impl super::MostAbundantIsotope for LawrenciumIsotope {
98    fn most_abundant_isotope() -> Self {
99        Self::Lr266
100    }
101}
102impl From<LawrenciumIsotope> for crate::Isotope {
103    fn from(isotope: LawrenciumIsotope) -> Self {
104        crate::Isotope::Lr(isotope)
105    }
106}
107impl From<LawrenciumIsotope> for crate::Element {
108    fn from(_isotope: LawrenciumIsotope) -> Self {
109        crate::Element::Lr
110    }
111}
112impl TryFrom<u64> for LawrenciumIsotope {
113    type Error = crate::errors::Error;
114    fn try_from(value: u64) -> Result<Self, Self::Error> {
115        match value {
116            251u64 => Ok(Self::Lr251),
117            252u64 => Ok(Self::Lr252),
118            253u64 => Ok(Self::Lr253),
119            254u64 => Ok(Self::Lr254),
120            255u64 => Ok(Self::Lr255),
121            256u64 => Ok(Self::Lr256),
122            257u64 => Ok(Self::Lr257),
123            258u64 => Ok(Self::Lr258),
124            259u64 => Ok(Self::Lr259),
125            260u64 => Ok(Self::Lr260),
126            261u64 => Ok(Self::Lr261),
127            262u64 => Ok(Self::Lr262),
128            263u64 => Ok(Self::Lr263),
129            264u64 => Ok(Self::Lr264),
130            265u64 => Ok(Self::Lr265),
131            266u64 => Ok(Self::Lr266),
132            _ => Err(crate::errors::Error::Isotope(crate::Element::Lr, value)),
133        }
134    }
135}
136impl TryFrom<u8> for LawrenciumIsotope {
137    type Error = crate::errors::Error;
138    fn try_from(value: u8) -> Result<Self, Self::Error> {
139        Self::try_from(u64::from(value))
140    }
141}
142impl TryFrom<u16> for LawrenciumIsotope {
143    type Error = crate::errors::Error;
144    fn try_from(value: u16) -> Result<Self, Self::Error> {
145        Self::try_from(u64::from(value))
146    }
147}
148impl TryFrom<u32> for LawrenciumIsotope {
149    type Error = crate::errors::Error;
150    fn try_from(value: u32) -> Result<Self, Self::Error> {
151        Self::try_from(u64::from(value))
152    }
153}
154impl core::fmt::Display for LawrenciumIsotope {
155    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
156        match self {
157            Self::Lr251 => write!(f, "Lr251"),
158            Self::Lr252 => write!(f, "Lr252"),
159            Self::Lr253 => write!(f, "Lr253"),
160            Self::Lr254 => write!(f, "Lr254"),
161            Self::Lr255 => write!(f, "Lr255"),
162            Self::Lr256 => write!(f, "Lr256"),
163            Self::Lr257 => write!(f, "Lr257"),
164            Self::Lr258 => write!(f, "Lr258"),
165            Self::Lr259 => write!(f, "Lr259"),
166            Self::Lr260 => write!(f, "Lr260"),
167            Self::Lr261 => write!(f, "Lr261"),
168            Self::Lr262 => write!(f, "Lr262"),
169            Self::Lr263 => write!(f, "Lr263"),
170            Self::Lr264 => write!(f, "Lr264"),
171            Self::Lr265 => write!(f, "Lr265"),
172            Self::Lr266 => write!(f, "Lr266"),
173        }
174    }
175}
176#[cfg(test)]
177mod tests {
178    use strum::IntoEnumIterator;
179
180    use super::*;
181    use crate::isotopes::{
182        ElementVariant, IsotopicComposition, MassNumber, MostAbundantIsotope, RelativeAtomicMass,
183    };
184    #[test]
185    fn test_relative_atomic_mass() {
186        for isotope in LawrenciumIsotope::iter() {
187            let mass = isotope.relative_atomic_mass();
188            assert!(mass > 0.0, "Mass should be positive for {isotope:?}");
189        }
190    }
191    #[test]
192    fn test_element() {
193        for isotope in LawrenciumIsotope::iter() {
194            let element = isotope.element();
195            assert_eq!(element, crate::Element::Lr, "Element should be correct for {isotope:?}");
196        }
197    }
198    #[test]
199    fn test_mass_number() {
200        for isotope in LawrenciumIsotope::iter() {
201            let mass_number = isotope.mass_number();
202            assert!(
203                mass_number > 0 && mass_number < 300,
204                "Mass number should be reasonable for {isotope:?}"
205            );
206        }
207    }
208    #[test]
209    fn test_isotopic_composition() {
210        for isotope in LawrenciumIsotope::iter() {
211            let comp = isotope.isotopic_composition();
212            if let Some(c) = comp {
213                assert!(
214                    (0.0..=1.0).contains(&c),
215                    "Composition should be between 0 and 1 for {isotope:?}"
216                );
217            }
218        }
219    }
220    #[test]
221    fn test_most_abundant() {
222        let most_abundant = LawrenciumIsotope::most_abundant_isotope();
223        let _ = most_abundant.relative_atomic_mass();
224    }
225    #[test]
226    fn test_from_isotope() {
227        for isotope in LawrenciumIsotope::iter() {
228            let iso: crate::Isotope = isotope.into();
229            match iso {
230                crate::Isotope::Lr(i) => assert_eq!(i, isotope),
231                _ => panic!("Wrong isotope type"),
232            }
233        }
234    }
235    #[test]
236    fn test_from_element() {
237        for isotope in LawrenciumIsotope::iter() {
238            let elem: crate::Element = isotope.into();
239            assert_eq!(elem, crate::Element::Lr);
240        }
241    }
242    #[test]
243    fn test_try_from_mass_number() {
244        for isotope in LawrenciumIsotope::iter() {
245            let mass = isotope.mass_number();
246            let iso = LawrenciumIsotope::try_from(mass).unwrap();
247            assert_eq!(iso, isotope);
248            let iso_u32 = LawrenciumIsotope::try_from(u32::from(mass)).unwrap();
249            assert_eq!(iso_u32, isotope);
250            if let Ok(mass_u8) = u8::try_from(mass) {
251                let iso_u8 = LawrenciumIsotope::try_from(mass_u8).unwrap();
252                assert_eq!(iso_u8, isotope);
253            }
254        }
255        assert!(LawrenciumIsotope::try_from(0_u16).is_err());
256        assert!(LawrenciumIsotope::try_from(1000_u16).is_err());
257        assert!(LawrenciumIsotope::try_from(0_u32).is_err());
258        assert!(LawrenciumIsotope::try_from(1000_u32).is_err());
259        assert!(LawrenciumIsotope::try_from(0_u8).is_err());
260    }
261    #[test]
262    fn test_display() {
263        for isotope in LawrenciumIsotope::iter() {
264            let s = alloc::format!("{isotope}");
265            assert!(!s.is_empty(), "Display should not be empty for {isotope:?}");
266        }
267    }
268}