Skip to main content

elements_rs/isotopes/
caesium.rs

1//! Isotopes of the element Caesium
2#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, strum :: EnumIter)]
3#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
4#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
5/// Isotopes of the element Caesium
6pub enum CaesiumIsotope {
7    /// Isotope Cs112 of Caesium
8    Cs112,
9    /// Isotope Cs113 of Caesium
10    Cs113,
11    /// Isotope Cs114 of Caesium
12    Cs114,
13    /// Isotope Cs115 of Caesium
14    Cs115,
15    /// Isotope Cs116 of Caesium
16    Cs116,
17    /// Isotope Cs117 of Caesium
18    Cs117,
19    /// Isotope Cs118 of Caesium
20    Cs118,
21    /// Isotope Cs119 of Caesium
22    Cs119,
23    /// Isotope Cs120 of Caesium
24    Cs120,
25    /// Isotope Cs121 of Caesium
26    Cs121,
27    /// Isotope Cs122 of Caesium
28    Cs122,
29    /// Isotope Cs123 of Caesium
30    Cs123,
31    /// Isotope Cs124 of Caesium
32    Cs124,
33    /// Isotope Cs125 of Caesium
34    Cs125,
35    /// Isotope Cs126 of Caesium
36    Cs126,
37    /// Isotope Cs127 of Caesium
38    Cs127,
39    /// Isotope Cs128 of Caesium
40    Cs128,
41    /// Isotope Cs129 of Caesium
42    Cs129,
43    /// Isotope Cs130 of Caesium
44    Cs130,
45    /// Isotope Cs131 of Caesium
46    Cs131,
47    /// Isotope Cs132 of Caesium
48    Cs132,
49    /// Isotope Cs133 of Caesium
50    Cs133,
51    /// Isotope Cs134 of Caesium
52    Cs134,
53    /// Isotope Cs135 of Caesium
54    Cs135,
55    /// Isotope Cs136 of Caesium
56    Cs136,
57    /// Isotope Cs137 of Caesium
58    Cs137,
59    /// Isotope Cs138 of Caesium
60    Cs138,
61    /// Isotope Cs139 of Caesium
62    Cs139,
63    /// Isotope Cs140 of Caesium
64    Cs140,
65    /// Isotope Cs141 of Caesium
66    Cs141,
67    /// Isotope Cs142 of Caesium
68    Cs142,
69    /// Isotope Cs143 of Caesium
70    Cs143,
71    /// Isotope Cs144 of Caesium
72    Cs144,
73    /// Isotope Cs145 of Caesium
74    Cs145,
75    /// Isotope Cs146 of Caesium
76    Cs146,
77    /// Isotope Cs147 of Caesium
78    Cs147,
79    /// Isotope Cs148 of Caesium
80    Cs148,
81    /// Isotope Cs149 of Caesium
82    Cs149,
83    /// Isotope Cs150 of Caesium
84    Cs150,
85    /// Isotope Cs151 of Caesium
86    Cs151,
87}
88impl super::RelativeAtomicMass for CaesiumIsotope {
89    #[inline]
90    fn relative_atomic_mass(&self) -> f64 {
91        match self {
92            Self::Cs112 => 111.950309f64,
93            Self::Cs113 => 112.9444291f64,
94            Self::Cs114 => 113.941296f64,
95            Self::Cs115 => 114.93591f64,
96            Self::Cs116 => 115.93337f64,
97            Self::Cs117 => 116.928617f64,
98            Self::Cs118 => 117.92656f64,
99            Self::Cs119 => 118.922377f64,
100            Self::Cs120 => 119.920677f64,
101            Self::Cs121 => 120.917227f64,
102            Self::Cs122 => 121.916108f64,
103            Self::Cs123 => 122.912996f64,
104            Self::Cs124 => 123.9122578f64,
105            Self::Cs125 => 124.909728f64,
106            Self::Cs126 => 125.909446f64,
107            Self::Cs127 => 126.9074174f64,
108            Self::Cs128 => 127.9077487f64,
109            Self::Cs129 => 128.9060657f64,
110            Self::Cs130 => 129.9067093f64,
111            Self::Cs131 => 130.9054649f64,
112            Self::Cs132 => 131.9064339f64,
113            Self::Cs133 => 132.905451961f64,
114            Self::Cs134 => 133.906718503f64,
115            Self::Cs135 => 134.905977f64,
116            Self::Cs136 => 135.9073114f64,
117            Self::Cs137 => 136.90708923f64,
118            Self::Cs138 => 137.9110171f64,
119            Self::Cs139 => 138.9133638f64,
120            Self::Cs140 => 139.9172831f64,
121            Self::Cs141 => 140.9200455f64,
122            Self::Cs142 => 141.924296f64,
123            Self::Cs143 => 142.927349f64,
124            Self::Cs144 => 143.932076f64,
125            Self::Cs145 => 144.935527f64,
126            Self::Cs146 => 145.940344f64,
127            Self::Cs147 => 146.944156f64,
128            Self::Cs148 => 147.94923f64,
129            Self::Cs149 => 148.95302f64,
130            Self::Cs150 => 149.95833f64,
131            Self::Cs151 => 150.96258f64,
132        }
133    }
134}
135impl super::ElementVariant for CaesiumIsotope {
136    #[inline]
137    fn element(&self) -> crate::Element {
138        crate::Element::Cs
139    }
140}
141impl super::MassNumber for CaesiumIsotope {
142    #[inline]
143    fn mass_number(&self) -> u16 {
144        match self {
145            Self::Cs112 => 112u16,
146            Self::Cs113 => 113u16,
147            Self::Cs114 => 114u16,
148            Self::Cs115 => 115u16,
149            Self::Cs116 => 116u16,
150            Self::Cs117 => 117u16,
151            Self::Cs118 => 118u16,
152            Self::Cs119 => 119u16,
153            Self::Cs120 => 120u16,
154            Self::Cs121 => 121u16,
155            Self::Cs122 => 122u16,
156            Self::Cs123 => 123u16,
157            Self::Cs124 => 124u16,
158            Self::Cs125 => 125u16,
159            Self::Cs126 => 126u16,
160            Self::Cs127 => 127u16,
161            Self::Cs128 => 128u16,
162            Self::Cs129 => 129u16,
163            Self::Cs130 => 130u16,
164            Self::Cs131 => 131u16,
165            Self::Cs132 => 132u16,
166            Self::Cs133 => 133u16,
167            Self::Cs134 => 134u16,
168            Self::Cs135 => 135u16,
169            Self::Cs136 => 136u16,
170            Self::Cs137 => 137u16,
171            Self::Cs138 => 138u16,
172            Self::Cs139 => 139u16,
173            Self::Cs140 => 140u16,
174            Self::Cs141 => 141u16,
175            Self::Cs142 => 142u16,
176            Self::Cs143 => 143u16,
177            Self::Cs144 => 144u16,
178            Self::Cs145 => 145u16,
179            Self::Cs146 => 146u16,
180            Self::Cs147 => 147u16,
181            Self::Cs148 => 148u16,
182            Self::Cs149 => 149u16,
183            Self::Cs150 => 150u16,
184            Self::Cs151 => 151u16,
185        }
186    }
187}
188impl super::IsotopicComposition for CaesiumIsotope {
189    #[inline]
190    fn isotopic_composition(&self) -> Option<f64> {
191        match self {
192            Self::Cs133 => Some(1f64),
193            _ => None,
194        }
195    }
196}
197impl super::MostAbundantIsotope for CaesiumIsotope {
198    fn most_abundant_isotope() -> Self {
199        Self::Cs133
200    }
201}
202impl From<CaesiumIsotope> for crate::Isotope {
203    fn from(isotope: CaesiumIsotope) -> Self {
204        crate::Isotope::Cs(isotope)
205    }
206}
207impl From<CaesiumIsotope> for crate::Element {
208    fn from(_isotope: CaesiumIsotope) -> Self {
209        crate::Element::Cs
210    }
211}
212impl TryFrom<u64> for CaesiumIsotope {
213    type Error = crate::errors::Error;
214    fn try_from(value: u64) -> Result<Self, Self::Error> {
215        match value {
216            112u64 => Ok(Self::Cs112),
217            113u64 => Ok(Self::Cs113),
218            114u64 => Ok(Self::Cs114),
219            115u64 => Ok(Self::Cs115),
220            116u64 => Ok(Self::Cs116),
221            117u64 => Ok(Self::Cs117),
222            118u64 => Ok(Self::Cs118),
223            119u64 => Ok(Self::Cs119),
224            120u64 => Ok(Self::Cs120),
225            121u64 => Ok(Self::Cs121),
226            122u64 => Ok(Self::Cs122),
227            123u64 => Ok(Self::Cs123),
228            124u64 => Ok(Self::Cs124),
229            125u64 => Ok(Self::Cs125),
230            126u64 => Ok(Self::Cs126),
231            127u64 => Ok(Self::Cs127),
232            128u64 => Ok(Self::Cs128),
233            129u64 => Ok(Self::Cs129),
234            130u64 => Ok(Self::Cs130),
235            131u64 => Ok(Self::Cs131),
236            132u64 => Ok(Self::Cs132),
237            133u64 => Ok(Self::Cs133),
238            134u64 => Ok(Self::Cs134),
239            135u64 => Ok(Self::Cs135),
240            136u64 => Ok(Self::Cs136),
241            137u64 => Ok(Self::Cs137),
242            138u64 => Ok(Self::Cs138),
243            139u64 => Ok(Self::Cs139),
244            140u64 => Ok(Self::Cs140),
245            141u64 => Ok(Self::Cs141),
246            142u64 => Ok(Self::Cs142),
247            143u64 => Ok(Self::Cs143),
248            144u64 => Ok(Self::Cs144),
249            145u64 => Ok(Self::Cs145),
250            146u64 => Ok(Self::Cs146),
251            147u64 => Ok(Self::Cs147),
252            148u64 => Ok(Self::Cs148),
253            149u64 => Ok(Self::Cs149),
254            150u64 => Ok(Self::Cs150),
255            151u64 => Ok(Self::Cs151),
256            _ => Err(crate::errors::Error::Isotope(crate::Element::Cs, value)),
257        }
258    }
259}
260impl TryFrom<u8> for CaesiumIsotope {
261    type Error = crate::errors::Error;
262    fn try_from(value: u8) -> Result<Self, Self::Error> {
263        Self::try_from(u64::from(value))
264    }
265}
266impl TryFrom<u16> for CaesiumIsotope {
267    type Error = crate::errors::Error;
268    fn try_from(value: u16) -> Result<Self, Self::Error> {
269        Self::try_from(u64::from(value))
270    }
271}
272impl TryFrom<u32> for CaesiumIsotope {
273    type Error = crate::errors::Error;
274    fn try_from(value: u32) -> Result<Self, Self::Error> {
275        Self::try_from(u64::from(value))
276    }
277}
278impl core::fmt::Display for CaesiumIsotope {
279    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
280        match self {
281            Self::Cs112 => write!(f, "Cs112"),
282            Self::Cs113 => write!(f, "Cs113"),
283            Self::Cs114 => write!(f, "Cs114"),
284            Self::Cs115 => write!(f, "Cs115"),
285            Self::Cs116 => write!(f, "Cs116"),
286            Self::Cs117 => write!(f, "Cs117"),
287            Self::Cs118 => write!(f, "Cs118"),
288            Self::Cs119 => write!(f, "Cs119"),
289            Self::Cs120 => write!(f, "Cs120"),
290            Self::Cs121 => write!(f, "Cs121"),
291            Self::Cs122 => write!(f, "Cs122"),
292            Self::Cs123 => write!(f, "Cs123"),
293            Self::Cs124 => write!(f, "Cs124"),
294            Self::Cs125 => write!(f, "Cs125"),
295            Self::Cs126 => write!(f, "Cs126"),
296            Self::Cs127 => write!(f, "Cs127"),
297            Self::Cs128 => write!(f, "Cs128"),
298            Self::Cs129 => write!(f, "Cs129"),
299            Self::Cs130 => write!(f, "Cs130"),
300            Self::Cs131 => write!(f, "Cs131"),
301            Self::Cs132 => write!(f, "Cs132"),
302            Self::Cs133 => write!(f, "Cs133"),
303            Self::Cs134 => write!(f, "Cs134"),
304            Self::Cs135 => write!(f, "Cs135"),
305            Self::Cs136 => write!(f, "Cs136"),
306            Self::Cs137 => write!(f, "Cs137"),
307            Self::Cs138 => write!(f, "Cs138"),
308            Self::Cs139 => write!(f, "Cs139"),
309            Self::Cs140 => write!(f, "Cs140"),
310            Self::Cs141 => write!(f, "Cs141"),
311            Self::Cs142 => write!(f, "Cs142"),
312            Self::Cs143 => write!(f, "Cs143"),
313            Self::Cs144 => write!(f, "Cs144"),
314            Self::Cs145 => write!(f, "Cs145"),
315            Self::Cs146 => write!(f, "Cs146"),
316            Self::Cs147 => write!(f, "Cs147"),
317            Self::Cs148 => write!(f, "Cs148"),
318            Self::Cs149 => write!(f, "Cs149"),
319            Self::Cs150 => write!(f, "Cs150"),
320            Self::Cs151 => write!(f, "Cs151"),
321        }
322    }
323}
324#[cfg(test)]
325mod tests {
326    use strum::IntoEnumIterator;
327
328    use super::*;
329    use crate::isotopes::{
330        ElementVariant, IsotopicComposition, MassNumber, MostAbundantIsotope, RelativeAtomicMass,
331    };
332    #[test]
333    fn test_relative_atomic_mass() {
334        for isotope in CaesiumIsotope::iter() {
335            let mass = isotope.relative_atomic_mass();
336            assert!(mass > 0.0, "Mass should be positive for {isotope:?}");
337        }
338    }
339    #[test]
340    fn test_element() {
341        for isotope in CaesiumIsotope::iter() {
342            let element = isotope.element();
343            assert_eq!(element, crate::Element::Cs, "Element should be correct for {isotope:?}");
344        }
345    }
346    #[test]
347    fn test_mass_number() {
348        for isotope in CaesiumIsotope::iter() {
349            let mass_number = isotope.mass_number();
350            assert!(
351                mass_number > 0 && mass_number < 300,
352                "Mass number should be reasonable for {isotope:?}"
353            );
354        }
355    }
356    #[test]
357    fn test_isotopic_composition() {
358        for isotope in CaesiumIsotope::iter() {
359            let comp = isotope.isotopic_composition();
360            if let Some(c) = comp {
361                assert!(
362                    (0.0..=1.0).contains(&c),
363                    "Composition should be between 0 and 1 for {isotope:?}"
364                );
365            }
366        }
367    }
368    #[test]
369    fn test_most_abundant() {
370        let most_abundant = CaesiumIsotope::most_abundant_isotope();
371        let _ = most_abundant.relative_atomic_mass();
372    }
373    #[test]
374    fn test_from_isotope() {
375        for isotope in CaesiumIsotope::iter() {
376            let iso: crate::Isotope = isotope.into();
377            match iso {
378                crate::Isotope::Cs(i) => assert_eq!(i, isotope),
379                _ => panic!("Wrong isotope type"),
380            }
381        }
382    }
383    #[test]
384    fn test_from_element() {
385        for isotope in CaesiumIsotope::iter() {
386            let elem: crate::Element = isotope.into();
387            assert_eq!(elem, crate::Element::Cs);
388        }
389    }
390    #[test]
391    fn test_try_from_mass_number() {
392        for isotope in CaesiumIsotope::iter() {
393            let mass = isotope.mass_number();
394            let iso = CaesiumIsotope::try_from(mass).unwrap();
395            assert_eq!(iso, isotope);
396            let iso_u32 = CaesiumIsotope::try_from(u32::from(mass)).unwrap();
397            assert_eq!(iso_u32, isotope);
398            if let Ok(mass_u8) = u8::try_from(mass) {
399                let iso_u8 = CaesiumIsotope::try_from(mass_u8).unwrap();
400                assert_eq!(iso_u8, isotope);
401            }
402        }
403        assert!(CaesiumIsotope::try_from(0_u16).is_err());
404        assert!(CaesiumIsotope::try_from(1000_u16).is_err());
405        assert!(CaesiumIsotope::try_from(0_u32).is_err());
406        assert!(CaesiumIsotope::try_from(1000_u32).is_err());
407        assert!(CaesiumIsotope::try_from(0_u8).is_err());
408    }
409    #[test]
410    fn test_display() {
411        for isotope in CaesiumIsotope::iter() {
412            let s = alloc::format!("{isotope}");
413            assert!(!s.is_empty(), "Display should not be empty for {isotope:?}");
414        }
415    }
416}