Skip to main content

elements_rs/isotopes/
astatine.rs

1//! Isotopes of the element Astatine
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 Astatine
6pub enum AstatineIsotope {
7    /// Isotope At191 of Astatine
8    At191,
9    /// Isotope At192 of Astatine
10    At192,
11    /// Isotope At193 of Astatine
12    At193,
13    /// Isotope At194 of Astatine
14    At194,
15    /// Isotope At195 of Astatine
16    At195,
17    /// Isotope At196 of Astatine
18    At196,
19    /// Isotope At197 of Astatine
20    At197,
21    /// Isotope At198 of Astatine
22    At198,
23    /// Isotope At199 of Astatine
24    At199,
25    /// Isotope At200 of Astatine
26    At200,
27    /// Isotope At201 of Astatine
28    At201,
29    /// Isotope At202 of Astatine
30    At202,
31    /// Isotope At203 of Astatine
32    At203,
33    /// Isotope At204 of Astatine
34    At204,
35    /// Isotope At205 of Astatine
36    At205,
37    /// Isotope At206 of Astatine
38    At206,
39    /// Isotope At207 of Astatine
40    At207,
41    /// Isotope At208 of Astatine
42    At208,
43    /// Isotope At209 of Astatine
44    At209,
45    /// Isotope At210 of Astatine
46    At210,
47    /// Isotope At211 of Astatine
48    At211,
49    /// Isotope At212 of Astatine
50    At212,
51    /// Isotope At213 of Astatine
52    At213,
53    /// Isotope At214 of Astatine
54    At214,
55    /// Isotope At215 of Astatine
56    At215,
57    /// Isotope At216 of Astatine
58    At216,
59    /// Isotope At217 of Astatine
60    At217,
61    /// Isotope At218 of Astatine
62    At218,
63    /// Isotope At219 of Astatine
64    At219,
65    /// Isotope At220 of Astatine
66    At220,
67    /// Isotope At221 of Astatine
68    At221,
69    /// Isotope At222 of Astatine
70    At222,
71    /// Isotope At223 of Astatine
72    At223,
73    /// Isotope At224 of Astatine
74    At224,
75    /// Isotope At225 of Astatine
76    At225,
77    /// Isotope At226 of Astatine
78    At226,
79    /// Isotope At227 of Astatine
80    At227,
81    /// Isotope At228 of Astatine
82    At228,
83    /// Isotope At229 of Astatine
84    At229,
85}
86impl super::RelativeAtomicMass for AstatineIsotope {
87    #[inline]
88    fn relative_atomic_mass(&self) -> f64 {
89        match self {
90            Self::At191 => 191.004148f64,
91            Self::At192 => 192.003152f64,
92            Self::At193 => 192.999927f64,
93            Self::At194 => 193.999236f64,
94            Self::At195 => 194.9962685f64,
95            Self::At196 => 195.9958f64,
96            Self::At197 => 196.993189f64,
97            Self::At198 => 197.992784f64,
98            Self::At199 => 198.9905277f64,
99            Self::At200 => 199.990351f64,
100            Self::At201 => 200.9884171f64,
101            Self::At202 => 201.98863f64,
102            Self::At203 => 202.986943f64,
103            Self::At204 => 203.987251f64,
104            Self::At205 => 204.986076f64,
105            Self::At206 => 205.986657f64,
106            Self::At207 => 206.9858f64,
107            Self::At208 => 207.9866133f64,
108            Self::At209 => 208.9861702f64,
109            Self::At210 => 209.9871479f64,
110            Self::At211 => 210.9874966f64,
111            Self::At212 => 211.9907377f64,
112            Self::At213 => 212.992937f64,
113            Self::At214 => 213.9963721f64,
114            Self::At215 => 214.9986528f64,
115            Self::At216 => 216.0024236f64,
116            Self::At217 => 217.0047192f64,
117            Self::At218 => 218.008695f64,
118            Self::At219 => 219.0111618f64,
119            Self::At220 => 220.015433f64,
120            Self::At221 => 221.018017f64,
121            Self::At222 => 222.022494f64,
122            Self::At223 => 223.025151f64,
123            Self::At224 => 224.029749f64,
124            Self::At225 => 225.03263f64,
125            Self::At226 => 226.03716f64,
126            Self::At227 => 227.04024f64,
127            Self::At228 => 228.04475f64,
128            Self::At229 => 229.04812f64,
129        }
130    }
131}
132impl super::ElementVariant for AstatineIsotope {
133    #[inline]
134    fn element(&self) -> crate::Element {
135        crate::Element::At
136    }
137}
138impl super::MassNumber for AstatineIsotope {
139    #[inline]
140    fn mass_number(&self) -> u16 {
141        match self {
142            Self::At191 => 191u16,
143            Self::At192 => 192u16,
144            Self::At193 => 193u16,
145            Self::At194 => 194u16,
146            Self::At195 => 195u16,
147            Self::At196 => 196u16,
148            Self::At197 => 197u16,
149            Self::At198 => 198u16,
150            Self::At199 => 199u16,
151            Self::At200 => 200u16,
152            Self::At201 => 201u16,
153            Self::At202 => 202u16,
154            Self::At203 => 203u16,
155            Self::At204 => 204u16,
156            Self::At205 => 205u16,
157            Self::At206 => 206u16,
158            Self::At207 => 207u16,
159            Self::At208 => 208u16,
160            Self::At209 => 209u16,
161            Self::At210 => 210u16,
162            Self::At211 => 211u16,
163            Self::At212 => 212u16,
164            Self::At213 => 213u16,
165            Self::At214 => 214u16,
166            Self::At215 => 215u16,
167            Self::At216 => 216u16,
168            Self::At217 => 217u16,
169            Self::At218 => 218u16,
170            Self::At219 => 219u16,
171            Self::At220 => 220u16,
172            Self::At221 => 221u16,
173            Self::At222 => 222u16,
174            Self::At223 => 223u16,
175            Self::At224 => 224u16,
176            Self::At225 => 225u16,
177            Self::At226 => 226u16,
178            Self::At227 => 227u16,
179            Self::At228 => 228u16,
180            Self::At229 => 229u16,
181        }
182    }
183}
184impl super::IsotopicComposition for AstatineIsotope {
185    #[inline]
186    fn isotopic_composition(&self) -> Option<f64> {
187        None
188    }
189}
190impl super::MostAbundantIsotope for AstatineIsotope {
191    fn most_abundant_isotope() -> Self {
192        Self::At229
193    }
194}
195impl From<AstatineIsotope> for crate::Isotope {
196    fn from(isotope: AstatineIsotope) -> Self {
197        crate::Isotope::At(isotope)
198    }
199}
200impl From<AstatineIsotope> for crate::Element {
201    fn from(_isotope: AstatineIsotope) -> Self {
202        crate::Element::At
203    }
204}
205impl TryFrom<u64> for AstatineIsotope {
206    type Error = crate::errors::Error;
207    fn try_from(value: u64) -> Result<Self, Self::Error> {
208        match value {
209            191u64 => Ok(Self::At191),
210            192u64 => Ok(Self::At192),
211            193u64 => Ok(Self::At193),
212            194u64 => Ok(Self::At194),
213            195u64 => Ok(Self::At195),
214            196u64 => Ok(Self::At196),
215            197u64 => Ok(Self::At197),
216            198u64 => Ok(Self::At198),
217            199u64 => Ok(Self::At199),
218            200u64 => Ok(Self::At200),
219            201u64 => Ok(Self::At201),
220            202u64 => Ok(Self::At202),
221            203u64 => Ok(Self::At203),
222            204u64 => Ok(Self::At204),
223            205u64 => Ok(Self::At205),
224            206u64 => Ok(Self::At206),
225            207u64 => Ok(Self::At207),
226            208u64 => Ok(Self::At208),
227            209u64 => Ok(Self::At209),
228            210u64 => Ok(Self::At210),
229            211u64 => Ok(Self::At211),
230            212u64 => Ok(Self::At212),
231            213u64 => Ok(Self::At213),
232            214u64 => Ok(Self::At214),
233            215u64 => Ok(Self::At215),
234            216u64 => Ok(Self::At216),
235            217u64 => Ok(Self::At217),
236            218u64 => Ok(Self::At218),
237            219u64 => Ok(Self::At219),
238            220u64 => Ok(Self::At220),
239            221u64 => Ok(Self::At221),
240            222u64 => Ok(Self::At222),
241            223u64 => Ok(Self::At223),
242            224u64 => Ok(Self::At224),
243            225u64 => Ok(Self::At225),
244            226u64 => Ok(Self::At226),
245            227u64 => Ok(Self::At227),
246            228u64 => Ok(Self::At228),
247            229u64 => Ok(Self::At229),
248            _ => Err(crate::errors::Error::Isotope(crate::Element::At, value)),
249        }
250    }
251}
252impl TryFrom<u8> for AstatineIsotope {
253    type Error = crate::errors::Error;
254    fn try_from(value: u8) -> Result<Self, Self::Error> {
255        Self::try_from(u64::from(value))
256    }
257}
258impl TryFrom<u16> for AstatineIsotope {
259    type Error = crate::errors::Error;
260    fn try_from(value: u16) -> Result<Self, Self::Error> {
261        Self::try_from(u64::from(value))
262    }
263}
264impl TryFrom<u32> for AstatineIsotope {
265    type Error = crate::errors::Error;
266    fn try_from(value: u32) -> Result<Self, Self::Error> {
267        Self::try_from(u64::from(value))
268    }
269}
270impl core::fmt::Display for AstatineIsotope {
271    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
272        match self {
273            Self::At191 => write!(f, "At191"),
274            Self::At192 => write!(f, "At192"),
275            Self::At193 => write!(f, "At193"),
276            Self::At194 => write!(f, "At194"),
277            Self::At195 => write!(f, "At195"),
278            Self::At196 => write!(f, "At196"),
279            Self::At197 => write!(f, "At197"),
280            Self::At198 => write!(f, "At198"),
281            Self::At199 => write!(f, "At199"),
282            Self::At200 => write!(f, "At200"),
283            Self::At201 => write!(f, "At201"),
284            Self::At202 => write!(f, "At202"),
285            Self::At203 => write!(f, "At203"),
286            Self::At204 => write!(f, "At204"),
287            Self::At205 => write!(f, "At205"),
288            Self::At206 => write!(f, "At206"),
289            Self::At207 => write!(f, "At207"),
290            Self::At208 => write!(f, "At208"),
291            Self::At209 => write!(f, "At209"),
292            Self::At210 => write!(f, "At210"),
293            Self::At211 => write!(f, "At211"),
294            Self::At212 => write!(f, "At212"),
295            Self::At213 => write!(f, "At213"),
296            Self::At214 => write!(f, "At214"),
297            Self::At215 => write!(f, "At215"),
298            Self::At216 => write!(f, "At216"),
299            Self::At217 => write!(f, "At217"),
300            Self::At218 => write!(f, "At218"),
301            Self::At219 => write!(f, "At219"),
302            Self::At220 => write!(f, "At220"),
303            Self::At221 => write!(f, "At221"),
304            Self::At222 => write!(f, "At222"),
305            Self::At223 => write!(f, "At223"),
306            Self::At224 => write!(f, "At224"),
307            Self::At225 => write!(f, "At225"),
308            Self::At226 => write!(f, "At226"),
309            Self::At227 => write!(f, "At227"),
310            Self::At228 => write!(f, "At228"),
311            Self::At229 => write!(f, "At229"),
312        }
313    }
314}
315#[cfg(test)]
316mod tests {
317    use strum::IntoEnumIterator;
318
319    use super::*;
320    use crate::isotopes::{
321        ElementVariant, IsotopicComposition, MassNumber, MostAbundantIsotope, RelativeAtomicMass,
322    };
323    #[test]
324    fn test_relative_atomic_mass() {
325        for isotope in AstatineIsotope::iter() {
326            let mass = isotope.relative_atomic_mass();
327            assert!(mass > 0.0, "Mass should be positive for {isotope:?}");
328        }
329    }
330    #[test]
331    fn test_element() {
332        for isotope in AstatineIsotope::iter() {
333            let element = isotope.element();
334            assert_eq!(element, crate::Element::At, "Element should be correct for {isotope:?}");
335        }
336    }
337    #[test]
338    fn test_mass_number() {
339        for isotope in AstatineIsotope::iter() {
340            let mass_number = isotope.mass_number();
341            assert!(
342                mass_number > 0 && mass_number < 300,
343                "Mass number should be reasonable for {isotope:?}"
344            );
345        }
346    }
347    #[test]
348    fn test_isotopic_composition() {
349        for isotope in AstatineIsotope::iter() {
350            let comp = isotope.isotopic_composition();
351            if let Some(c) = comp {
352                assert!(
353                    (0.0..=1.0).contains(&c),
354                    "Composition should be between 0 and 1 for {isotope:?}"
355                );
356            }
357        }
358    }
359    #[test]
360    fn test_most_abundant() {
361        let most_abundant = AstatineIsotope::most_abundant_isotope();
362        let _ = most_abundant.relative_atomic_mass();
363    }
364    #[test]
365    fn test_from_isotope() {
366        for isotope in AstatineIsotope::iter() {
367            let iso: crate::Isotope = isotope.into();
368            match iso {
369                crate::Isotope::At(i) => assert_eq!(i, isotope),
370                _ => panic!("Wrong isotope type"),
371            }
372        }
373    }
374    #[test]
375    fn test_from_element() {
376        for isotope in AstatineIsotope::iter() {
377            let elem: crate::Element = isotope.into();
378            assert_eq!(elem, crate::Element::At);
379        }
380    }
381    #[test]
382    fn test_try_from_mass_number() {
383        for isotope in AstatineIsotope::iter() {
384            let mass = isotope.mass_number();
385            let iso = AstatineIsotope::try_from(mass).unwrap();
386            assert_eq!(iso, isotope);
387            let iso_u32 = AstatineIsotope::try_from(u32::from(mass)).unwrap();
388            assert_eq!(iso_u32, isotope);
389            if let Ok(mass_u8) = u8::try_from(mass) {
390                let iso_u8 = AstatineIsotope::try_from(mass_u8).unwrap();
391                assert_eq!(iso_u8, isotope);
392            }
393        }
394        assert!(AstatineIsotope::try_from(0_u16).is_err());
395        assert!(AstatineIsotope::try_from(1000_u16).is_err());
396        assert!(AstatineIsotope::try_from(0_u32).is_err());
397        assert!(AstatineIsotope::try_from(1000_u32).is_err());
398        assert!(AstatineIsotope::try_from(0_u8).is_err());
399    }
400    #[test]
401    fn test_display() {
402        for isotope in AstatineIsotope::iter() {
403            let s = alloc::format!("{isotope}");
404            assert!(!s.is_empty(), "Display should not be empty for {isotope:?}");
405        }
406    }
407}