elements_rs/isotopes/
curium.rs

1//! Isotopes of the element Curium
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 Curium
5pub enum CuriumIsotope {
6    /// Isotope Cm232 of Curium
7    Cm232,
8    /// Isotope Cm233 of Curium
9    Cm233,
10    /// Isotope Cm234 of Curium
11    Cm234,
12    /// Isotope Cm235 of Curium
13    Cm235,
14    /// Isotope Cm236 of Curium
15    Cm236,
16    /// Isotope Cm237 of Curium
17    Cm237,
18    /// Isotope Cm238 of Curium
19    Cm238,
20    /// Isotope Cm239 of Curium
21    Cm239,
22    /// Isotope Cm240 of Curium
23    Cm240,
24    /// Isotope Cm241 of Curium
25    Cm241,
26    /// Isotope Cm242 of Curium
27    Cm242,
28    /// Isotope Cm243 of Curium
29    Cm243,
30    /// Isotope Cm244 of Curium
31    Cm244,
32    /// Isotope Cm245 of Curium
33    Cm245,
34    /// Isotope Cm246 of Curium
35    Cm246,
36    /// Isotope Cm247 of Curium
37    Cm247,
38    /// Isotope Cm248 of Curium
39    Cm248,
40    /// Isotope Cm249 of Curium
41    Cm249,
42    /// Isotope Cm250 of Curium
43    Cm250,
44    /// Isotope Cm251 of Curium
45    Cm251,
46    /// Isotope Cm252 of Curium
47    Cm252,
48}
49impl super::RelativeAtomicMass for CuriumIsotope {
50    #[inline]
51    fn relative_atomic_mass(&self) -> f64 {
52        match self {
53            Self::Cm232 => 232.04982f64,
54            Self::Cm233 => 233.05077f64,
55            Self::Cm234 => 234.05016f64,
56            Self::Cm235 => 235.05154f64,
57            Self::Cm236 => 236.051374f64,
58            Self::Cm237 => 237.052869f64,
59            Self::Cm238 => 238.053081f64,
60            Self::Cm239 => 239.05491f64,
61            Self::Cm240 => 240.0555297f64,
62            Self::Cm241 => 241.0576532f64,
63            Self::Cm242 => 242.058836f64,
64            Self::Cm243 => 243.0613893f64,
65            Self::Cm244 => 244.0627528f64,
66            Self::Cm245 => 245.0654915f64,
67            Self::Cm246 => 246.0672238f64,
68            Self::Cm247 => 247.0703541f64,
69            Self::Cm248 => 248.0723499f64,
70            Self::Cm249 => 249.0759548f64,
71            Self::Cm250 => 250.078358f64,
72            Self::Cm251 => 251.082286f64,
73            Self::Cm252 => 252.08487f64,
74        }
75    }
76}
77impl super::ElementVariant for CuriumIsotope {
78    #[inline]
79    fn element(&self) -> crate::Element {
80        crate::Element::Cm
81    }
82}
83impl super::MassNumber for CuriumIsotope {
84    #[inline]
85    fn mass_number(&self) -> u16 {
86        match self {
87            Self::Cm232 => 232u16,
88            Self::Cm233 => 233u16,
89            Self::Cm234 => 234u16,
90            Self::Cm235 => 235u16,
91            Self::Cm236 => 236u16,
92            Self::Cm237 => 237u16,
93            Self::Cm238 => 238u16,
94            Self::Cm239 => 239u16,
95            Self::Cm240 => 240u16,
96            Self::Cm241 => 241u16,
97            Self::Cm242 => 242u16,
98            Self::Cm243 => 243u16,
99            Self::Cm244 => 244u16,
100            Self::Cm245 => 245u16,
101            Self::Cm246 => 246u16,
102            Self::Cm247 => 247u16,
103            Self::Cm248 => 248u16,
104            Self::Cm249 => 249u16,
105            Self::Cm250 => 250u16,
106            Self::Cm251 => 251u16,
107            Self::Cm252 => 252u16,
108        }
109    }
110}
111impl super::IsotopicComposition for CuriumIsotope {
112    #[inline]
113    fn isotopic_composition(&self) -> Option<f64> {
114        None
115    }
116}
117impl super::MostAbundantIsotope for CuriumIsotope {
118    fn most_abundant_isotope() -> Self {
119        Self::Cm252
120    }
121}
122impl From<CuriumIsotope> for crate::Isotope {
123    fn from(isotope: CuriumIsotope) -> Self {
124        crate::Isotope::Cm(isotope)
125    }
126}
127impl From<CuriumIsotope> for crate::Element {
128    fn from(_isotope: CuriumIsotope) -> Self {
129        crate::Element::Cm
130    }
131}
132impl TryFrom<u64> for CuriumIsotope {
133    type Error = crate::errors::Error;
134    fn try_from(value: u64) -> Result<Self, Self::Error> {
135        match value {
136            232u64 => Ok(Self::Cm232),
137            233u64 => Ok(Self::Cm233),
138            234u64 => Ok(Self::Cm234),
139            235u64 => Ok(Self::Cm235),
140            236u64 => Ok(Self::Cm236),
141            237u64 => Ok(Self::Cm237),
142            238u64 => Ok(Self::Cm238),
143            239u64 => Ok(Self::Cm239),
144            240u64 => Ok(Self::Cm240),
145            241u64 => Ok(Self::Cm241),
146            242u64 => Ok(Self::Cm242),
147            243u64 => Ok(Self::Cm243),
148            244u64 => Ok(Self::Cm244),
149            245u64 => Ok(Self::Cm245),
150            246u64 => Ok(Self::Cm246),
151            247u64 => Ok(Self::Cm247),
152            248u64 => Ok(Self::Cm248),
153            249u64 => Ok(Self::Cm249),
154            250u64 => Ok(Self::Cm250),
155            251u64 => Ok(Self::Cm251),
156            252u64 => Ok(Self::Cm252),
157            _ => Err(crate::errors::Error::Isotope(crate::Element::Cm, value)),
158        }
159    }
160}
161impl TryFrom<u8> for CuriumIsotope {
162    type Error = crate::errors::Error;
163    fn try_from(value: u8) -> Result<Self, Self::Error> {
164        Self::try_from(u64::from(value))
165    }
166}
167impl TryFrom<u16> for CuriumIsotope {
168    type Error = crate::errors::Error;
169    fn try_from(value: u16) -> Result<Self, Self::Error> {
170        Self::try_from(u64::from(value))
171    }
172}
173impl TryFrom<u32> for CuriumIsotope {
174    type Error = crate::errors::Error;
175    fn try_from(value: u32) -> Result<Self, Self::Error> {
176        Self::try_from(u64::from(value))
177    }
178}
179impl core::fmt::Display for CuriumIsotope {
180    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
181        match self {
182            Self::Cm232 => write!(f, "Cm232"),
183            Self::Cm233 => write!(f, "Cm233"),
184            Self::Cm234 => write!(f, "Cm234"),
185            Self::Cm235 => write!(f, "Cm235"),
186            Self::Cm236 => write!(f, "Cm236"),
187            Self::Cm237 => write!(f, "Cm237"),
188            Self::Cm238 => write!(f, "Cm238"),
189            Self::Cm239 => write!(f, "Cm239"),
190            Self::Cm240 => write!(f, "Cm240"),
191            Self::Cm241 => write!(f, "Cm241"),
192            Self::Cm242 => write!(f, "Cm242"),
193            Self::Cm243 => write!(f, "Cm243"),
194            Self::Cm244 => write!(f, "Cm244"),
195            Self::Cm245 => write!(f, "Cm245"),
196            Self::Cm246 => write!(f, "Cm246"),
197            Self::Cm247 => write!(f, "Cm247"),
198            Self::Cm248 => write!(f, "Cm248"),
199            Self::Cm249 => write!(f, "Cm249"),
200            Self::Cm250 => write!(f, "Cm250"),
201            Self::Cm251 => write!(f, "Cm251"),
202            Self::Cm252 => write!(f, "Cm252"),
203        }
204    }
205}
206#[cfg(test)]
207mod tests {
208    use strum::IntoEnumIterator;
209
210    use super::*;
211    use crate::isotopes::{
212        ElementVariant, IsotopicComposition, MassNumber, MostAbundantIsotope, RelativeAtomicMass,
213    };
214    #[test]
215    fn test_relative_atomic_mass() {
216        for isotope in CuriumIsotope::iter() {
217            let mass = isotope.relative_atomic_mass();
218            assert!(mass > 0.0, "Mass should be positive for {isotope:?}");
219        }
220    }
221    #[test]
222    fn test_element() {
223        for isotope in CuriumIsotope::iter() {
224            let element = isotope.element();
225            assert_eq!(element, crate::Element::Cm, "Element should be correct for {isotope:?}");
226        }
227    }
228    #[test]
229    fn test_mass_number() {
230        for isotope in CuriumIsotope::iter() {
231            let mass_number = isotope.mass_number();
232            assert!(
233                mass_number > 0 && mass_number < 300,
234                "Mass number should be reasonable for {isotope:?}"
235            );
236        }
237    }
238    #[test]
239    fn test_isotopic_composition() {
240        for isotope in CuriumIsotope::iter() {
241            let comp = isotope.isotopic_composition();
242            if let Some(c) = comp {
243                assert!(
244                    (0.0..=1.0).contains(&c),
245                    "Composition should be between 0 and 1 for {isotope:?}"
246                );
247            }
248        }
249    }
250    #[test]
251    fn test_most_abundant() {
252        let most_abundant = CuriumIsotope::most_abundant_isotope();
253        let _ = most_abundant.relative_atomic_mass();
254    }
255    #[test]
256    fn test_from_isotope() {
257        for isotope in CuriumIsotope::iter() {
258            let iso: crate::Isotope = isotope.into();
259            match iso {
260                crate::Isotope::Cm(i) => assert_eq!(i, isotope),
261                _ => panic!("Wrong isotope type"),
262            }
263        }
264    }
265    #[test]
266    fn test_from_element() {
267        for isotope in CuriumIsotope::iter() {
268            let elem: crate::Element = isotope.into();
269            assert_eq!(elem, crate::Element::Cm);
270        }
271    }
272    #[test]
273    fn test_try_from_mass_number() {
274        for isotope in CuriumIsotope::iter() {
275            let mass = isotope.mass_number();
276            let iso = CuriumIsotope::try_from(mass).unwrap();
277            assert_eq!(iso, isotope);
278            let iso_u32 = CuriumIsotope::try_from(u32::from(mass)).unwrap();
279            assert_eq!(iso_u32, isotope);
280            if let Ok(mass_u8) = u8::try_from(mass) {
281                let iso_u8 = CuriumIsotope::try_from(mass_u8).unwrap();
282                assert_eq!(iso_u8, isotope);
283            }
284        }
285        assert!(CuriumIsotope::try_from(0_u16).is_err());
286        assert!(CuriumIsotope::try_from(1000_u16).is_err());
287        assert!(CuriumIsotope::try_from(0_u32).is_err());
288        assert!(CuriumIsotope::try_from(1000_u32).is_err());
289        assert!(CuriumIsotope::try_from(0_u8).is_err());
290    }
291    #[test]
292    fn test_display() {
293        for isotope in CuriumIsotope::iter() {
294            let s = alloc::format!("{isotope}");
295            assert!(!s.is_empty(), "Display should not be empty for {isotope:?}");
296        }
297    }
298}