elements_rs/isotopes/
barium.rs

1//! Isotopes of the element Barium
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 Barium
5pub enum BariumIsotope {
6    /// Isotope Ba114 of Barium
7    Ba114,
8    /// Isotope Ba115 of Barium
9    Ba115,
10    /// Isotope Ba116 of Barium
11    Ba116,
12    /// Isotope Ba117 of Barium
13    Ba117,
14    /// Isotope Ba118 of Barium
15    Ba118,
16    /// Isotope Ba119 of Barium
17    Ba119,
18    /// Isotope Ba120 of Barium
19    Ba120,
20    /// Isotope Ba121 of Barium
21    Ba121,
22    /// Isotope Ba122 of Barium
23    Ba122,
24    /// Isotope Ba123 of Barium
25    Ba123,
26    /// Isotope Ba124 of Barium
27    Ba124,
28    /// Isotope Ba125 of Barium
29    Ba125,
30    /// Isotope Ba126 of Barium
31    Ba126,
32    /// Isotope Ba127 of Barium
33    Ba127,
34    /// Isotope Ba128 of Barium
35    Ba128,
36    /// Isotope Ba129 of Barium
37    Ba129,
38    /// Isotope Ba130 of Barium
39    Ba130,
40    /// Isotope Ba131 of Barium
41    Ba131,
42    /// Isotope Ba132 of Barium
43    Ba132,
44    /// Isotope Ba133 of Barium
45    Ba133,
46    /// Isotope Ba134 of Barium
47    Ba134,
48    /// Isotope Ba135 of Barium
49    Ba135,
50    /// Isotope Ba136 of Barium
51    Ba136,
52    /// Isotope Ba137 of Barium
53    Ba137,
54    /// Isotope Ba138 of Barium
55    Ba138,
56    /// Isotope Ba139 of Barium
57    Ba139,
58    /// Isotope Ba140 of Barium
59    Ba140,
60    /// Isotope Ba141 of Barium
61    Ba141,
62    /// Isotope Ba142 of Barium
63    Ba142,
64    /// Isotope Ba143 of Barium
65    Ba143,
66    /// Isotope Ba144 of Barium
67    Ba144,
68    /// Isotope Ba145 of Barium
69    Ba145,
70    /// Isotope Ba146 of Barium
71    Ba146,
72    /// Isotope Ba147 of Barium
73    Ba147,
74    /// Isotope Ba148 of Barium
75    Ba148,
76    /// Isotope Ba149 of Barium
77    Ba149,
78    /// Isotope Ba150 of Barium
79    Ba150,
80    /// Isotope Ba151 of Barium
81    Ba151,
82    /// Isotope Ba152 of Barium
83    Ba152,
84    /// Isotope Ba153 of Barium
85    Ba153,
86}
87impl super::RelativeAtomicMass for BariumIsotope {
88    #[inline]
89    fn relative_atomic_mass(&self) -> f64 {
90        match self {
91            Self::Ba114 => 113.95066f64,
92            Self::Ba115 => 114.94737f64,
93            Self::Ba116 => 115.94128f64,
94            Self::Ba117 => 116.93814f64,
95            Self::Ba118 => 117.93306f64,
96            Self::Ba119 => 118.93066f64,
97            Self::Ba120 => 119.92605f64,
98            Self::Ba121 => 120.92405f64,
99            Self::Ba122 => 121.919904f64,
100            Self::Ba123 => 122.918781f64,
101            Self::Ba124 => 123.915094f64,
102            Self::Ba125 => 124.914472f64,
103            Self::Ba126 => 125.91125f64,
104            Self::Ba127 => 126.911091f64,
105            Self::Ba128 => 127.908342f64,
106            Self::Ba129 => 128.908681f64,
107            Self::Ba130 => 129.9063207f64,
108            Self::Ba131 => 130.906941f64,
109            Self::Ba132 => 131.9050611f64,
110            Self::Ba133 => 132.9060074f64,
111            Self::Ba134 => 133.90450818f64,
112            Self::Ba135 => 134.90568838f64,
113            Self::Ba136 => 135.90457573f64,
114            Self::Ba137 => 136.90582714f64,
115            Self::Ba138 => 137.905247f64,
116            Self::Ba139 => 138.9088411f64,
117            Self::Ba140 => 139.9106057f64,
118            Self::Ba141 => 140.9144033f64,
119            Self::Ba142 => 141.9164324f64,
120            Self::Ba143 => 142.9206253f64,
121            Self::Ba144 => 143.9229549f64,
122            Self::Ba145 => 144.9275184f64,
123            Self::Ba146 => 145.930284f64,
124            Self::Ba147 => 146.935304f64,
125            Self::Ba148 => 147.938171f64,
126            Self::Ba149 => 148.94308f64,
127            Self::Ba150 => 149.94605f64,
128            Self::Ba151 => 150.95127f64,
129            Self::Ba152 => 151.95481f64,
130            Self::Ba153 => 152.96036f64,
131        }
132    }
133}
134impl super::ElementVariant for BariumIsotope {
135    #[inline]
136    fn element(&self) -> crate::Element {
137        crate::Element::Ba
138    }
139}
140impl super::MassNumber for BariumIsotope {
141    #[inline]
142    fn mass_number(&self) -> u16 {
143        match self {
144            Self::Ba114 => 114u16,
145            Self::Ba115 => 115u16,
146            Self::Ba116 => 116u16,
147            Self::Ba117 => 117u16,
148            Self::Ba118 => 118u16,
149            Self::Ba119 => 119u16,
150            Self::Ba120 => 120u16,
151            Self::Ba121 => 121u16,
152            Self::Ba122 => 122u16,
153            Self::Ba123 => 123u16,
154            Self::Ba124 => 124u16,
155            Self::Ba125 => 125u16,
156            Self::Ba126 => 126u16,
157            Self::Ba127 => 127u16,
158            Self::Ba128 => 128u16,
159            Self::Ba129 => 129u16,
160            Self::Ba130 => 130u16,
161            Self::Ba131 => 131u16,
162            Self::Ba132 => 132u16,
163            Self::Ba133 => 133u16,
164            Self::Ba134 => 134u16,
165            Self::Ba135 => 135u16,
166            Self::Ba136 => 136u16,
167            Self::Ba137 => 137u16,
168            Self::Ba138 => 138u16,
169            Self::Ba139 => 139u16,
170            Self::Ba140 => 140u16,
171            Self::Ba141 => 141u16,
172            Self::Ba142 => 142u16,
173            Self::Ba143 => 143u16,
174            Self::Ba144 => 144u16,
175            Self::Ba145 => 145u16,
176            Self::Ba146 => 146u16,
177            Self::Ba147 => 147u16,
178            Self::Ba148 => 148u16,
179            Self::Ba149 => 149u16,
180            Self::Ba150 => 150u16,
181            Self::Ba151 => 151u16,
182            Self::Ba152 => 152u16,
183            Self::Ba153 => 153u16,
184        }
185    }
186}
187impl super::IsotopicComposition for BariumIsotope {
188    #[inline]
189    fn isotopic_composition(&self) -> Option<f64> {
190        match self {
191            Self::Ba130 => Some(0.00106f64),
192            Self::Ba132 => Some(0.00101f64),
193            Self::Ba134 => Some(0.02417f64),
194            Self::Ba135 => Some(0.06592f64),
195            Self::Ba136 => Some(0.07854f64),
196            Self::Ba137 => Some(0.11232f64),
197            Self::Ba138 => Some(0.71698f64),
198            _ => None,
199        }
200    }
201}
202impl super::MostAbundantIsotope for BariumIsotope {
203    fn most_abundant_isotope() -> Self {
204        Self::Ba138
205    }
206}
207impl From<BariumIsotope> for crate::Isotope {
208    fn from(isotope: BariumIsotope) -> Self {
209        crate::Isotope::Ba(isotope)
210    }
211}
212impl From<BariumIsotope> for crate::Element {
213    fn from(_isotope: BariumIsotope) -> Self {
214        crate::Element::Ba
215    }
216}
217impl TryFrom<u64> for BariumIsotope {
218    type Error = crate::errors::Error;
219    fn try_from(value: u64) -> Result<Self, Self::Error> {
220        match value {
221            114u64 => Ok(Self::Ba114),
222            115u64 => Ok(Self::Ba115),
223            116u64 => Ok(Self::Ba116),
224            117u64 => Ok(Self::Ba117),
225            118u64 => Ok(Self::Ba118),
226            119u64 => Ok(Self::Ba119),
227            120u64 => Ok(Self::Ba120),
228            121u64 => Ok(Self::Ba121),
229            122u64 => Ok(Self::Ba122),
230            123u64 => Ok(Self::Ba123),
231            124u64 => Ok(Self::Ba124),
232            125u64 => Ok(Self::Ba125),
233            126u64 => Ok(Self::Ba126),
234            127u64 => Ok(Self::Ba127),
235            128u64 => Ok(Self::Ba128),
236            129u64 => Ok(Self::Ba129),
237            130u64 => Ok(Self::Ba130),
238            131u64 => Ok(Self::Ba131),
239            132u64 => Ok(Self::Ba132),
240            133u64 => Ok(Self::Ba133),
241            134u64 => Ok(Self::Ba134),
242            135u64 => Ok(Self::Ba135),
243            136u64 => Ok(Self::Ba136),
244            137u64 => Ok(Self::Ba137),
245            138u64 => Ok(Self::Ba138),
246            139u64 => Ok(Self::Ba139),
247            140u64 => Ok(Self::Ba140),
248            141u64 => Ok(Self::Ba141),
249            142u64 => Ok(Self::Ba142),
250            143u64 => Ok(Self::Ba143),
251            144u64 => Ok(Self::Ba144),
252            145u64 => Ok(Self::Ba145),
253            146u64 => Ok(Self::Ba146),
254            147u64 => Ok(Self::Ba147),
255            148u64 => Ok(Self::Ba148),
256            149u64 => Ok(Self::Ba149),
257            150u64 => Ok(Self::Ba150),
258            151u64 => Ok(Self::Ba151),
259            152u64 => Ok(Self::Ba152),
260            153u64 => Ok(Self::Ba153),
261            _ => Err(crate::errors::Error::Isotope(crate::Element::Ba, value)),
262        }
263    }
264}
265impl TryFrom<u8> for BariumIsotope {
266    type Error = crate::errors::Error;
267    fn try_from(value: u8) -> Result<Self, Self::Error> {
268        Self::try_from(u64::from(value))
269    }
270}
271impl TryFrom<u16> for BariumIsotope {
272    type Error = crate::errors::Error;
273    fn try_from(value: u16) -> Result<Self, Self::Error> {
274        Self::try_from(u64::from(value))
275    }
276}
277impl TryFrom<u32> for BariumIsotope {
278    type Error = crate::errors::Error;
279    fn try_from(value: u32) -> Result<Self, Self::Error> {
280        Self::try_from(u64::from(value))
281    }
282}
283impl core::fmt::Display for BariumIsotope {
284    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
285        match self {
286            Self::Ba114 => write!(f, "Ba114"),
287            Self::Ba115 => write!(f, "Ba115"),
288            Self::Ba116 => write!(f, "Ba116"),
289            Self::Ba117 => write!(f, "Ba117"),
290            Self::Ba118 => write!(f, "Ba118"),
291            Self::Ba119 => write!(f, "Ba119"),
292            Self::Ba120 => write!(f, "Ba120"),
293            Self::Ba121 => write!(f, "Ba121"),
294            Self::Ba122 => write!(f, "Ba122"),
295            Self::Ba123 => write!(f, "Ba123"),
296            Self::Ba124 => write!(f, "Ba124"),
297            Self::Ba125 => write!(f, "Ba125"),
298            Self::Ba126 => write!(f, "Ba126"),
299            Self::Ba127 => write!(f, "Ba127"),
300            Self::Ba128 => write!(f, "Ba128"),
301            Self::Ba129 => write!(f, "Ba129"),
302            Self::Ba130 => write!(f, "Ba130"),
303            Self::Ba131 => write!(f, "Ba131"),
304            Self::Ba132 => write!(f, "Ba132"),
305            Self::Ba133 => write!(f, "Ba133"),
306            Self::Ba134 => write!(f, "Ba134"),
307            Self::Ba135 => write!(f, "Ba135"),
308            Self::Ba136 => write!(f, "Ba136"),
309            Self::Ba137 => write!(f, "Ba137"),
310            Self::Ba138 => write!(f, "Ba138"),
311            Self::Ba139 => write!(f, "Ba139"),
312            Self::Ba140 => write!(f, "Ba140"),
313            Self::Ba141 => write!(f, "Ba141"),
314            Self::Ba142 => write!(f, "Ba142"),
315            Self::Ba143 => write!(f, "Ba143"),
316            Self::Ba144 => write!(f, "Ba144"),
317            Self::Ba145 => write!(f, "Ba145"),
318            Self::Ba146 => write!(f, "Ba146"),
319            Self::Ba147 => write!(f, "Ba147"),
320            Self::Ba148 => write!(f, "Ba148"),
321            Self::Ba149 => write!(f, "Ba149"),
322            Self::Ba150 => write!(f, "Ba150"),
323            Self::Ba151 => write!(f, "Ba151"),
324            Self::Ba152 => write!(f, "Ba152"),
325            Self::Ba153 => write!(f, "Ba153"),
326        }
327    }
328}
329#[cfg(test)]
330mod tests {
331    use strum::IntoEnumIterator;
332
333    use super::*;
334    use crate::isotopes::{
335        ElementVariant, IsotopicComposition, MassNumber, MostAbundantIsotope, RelativeAtomicMass,
336    };
337    #[test]
338    fn test_relative_atomic_mass() {
339        for isotope in BariumIsotope::iter() {
340            let mass = isotope.relative_atomic_mass();
341            assert!(mass > 0.0, "Mass should be positive for {isotope:?}");
342        }
343    }
344    #[test]
345    fn test_element() {
346        for isotope in BariumIsotope::iter() {
347            let element = isotope.element();
348            assert_eq!(element, crate::Element::Ba, "Element should be correct for {isotope:?}");
349        }
350    }
351    #[test]
352    fn test_mass_number() {
353        for isotope in BariumIsotope::iter() {
354            let mass_number = isotope.mass_number();
355            assert!(
356                mass_number > 0 && mass_number < 300,
357                "Mass number should be reasonable for {isotope:?}"
358            );
359        }
360    }
361    #[test]
362    fn test_isotopic_composition() {
363        for isotope in BariumIsotope::iter() {
364            let comp = isotope.isotopic_composition();
365            if let Some(c) = comp {
366                assert!(
367                    (0.0..=1.0).contains(&c),
368                    "Composition should be between 0 and 1 for {isotope:?}"
369                );
370            }
371        }
372    }
373    #[test]
374    fn test_most_abundant() {
375        let most_abundant = BariumIsotope::most_abundant_isotope();
376        let _ = most_abundant.relative_atomic_mass();
377    }
378    #[test]
379    fn test_from_isotope() {
380        for isotope in BariumIsotope::iter() {
381            let iso: crate::Isotope = isotope.into();
382            match iso {
383                crate::Isotope::Ba(i) => assert_eq!(i, isotope),
384                _ => panic!("Wrong isotope type"),
385            }
386        }
387    }
388    #[test]
389    fn test_from_element() {
390        for isotope in BariumIsotope::iter() {
391            let elem: crate::Element = isotope.into();
392            assert_eq!(elem, crate::Element::Ba);
393        }
394    }
395    #[test]
396    fn test_try_from_mass_number() {
397        for isotope in BariumIsotope::iter() {
398            let mass = isotope.mass_number();
399            let iso = BariumIsotope::try_from(mass).unwrap();
400            assert_eq!(iso, isotope);
401            let iso_u32 = BariumIsotope::try_from(u32::from(mass)).unwrap();
402            assert_eq!(iso_u32, isotope);
403            if let Ok(mass_u8) = u8::try_from(mass) {
404                let iso_u8 = BariumIsotope::try_from(mass_u8).unwrap();
405                assert_eq!(iso_u8, isotope);
406            }
407        }
408        assert!(BariumIsotope::try_from(0_u16).is_err());
409        assert!(BariumIsotope::try_from(1000_u16).is_err());
410        assert!(BariumIsotope::try_from(0_u32).is_err());
411        assert!(BariumIsotope::try_from(1000_u32).is_err());
412        assert!(BariumIsotope::try_from(0_u8).is_err());
413    }
414    #[test]
415    fn test_display() {
416        for isotope in BariumIsotope::iter() {
417            let s = alloc::format!("{isotope}");
418            assert!(!s.is_empty(), "Display should not be empty for {isotope:?}");
419        }
420    }
421}