elements_rs/isotopes/
bohrium.rs

1//! Isotopes of the element Bohrium
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 Bohrium
5pub enum BohriumIsotope {
6    /// Isotope Bh260 of Bohrium
7    Bh260,
8    /// Isotope Bh261 of Bohrium
9    Bh261,
10    /// Isotope Bh262 of Bohrium
11    Bh262,
12    /// Isotope Bh263 of Bohrium
13    Bh263,
14    /// Isotope Bh264 of Bohrium
15    Bh264,
16    /// Isotope Bh265 of Bohrium
17    Bh265,
18    /// Isotope Bh266 of Bohrium
19    Bh266,
20    /// Isotope Bh267 of Bohrium
21    Bh267,
22    /// Isotope Bh268 of Bohrium
23    Bh268,
24    /// Isotope Bh269 of Bohrium
25    Bh269,
26    /// Isotope Bh270 of Bohrium
27    Bh270,
28    /// Isotope Bh271 of Bohrium
29    Bh271,
30    /// Isotope Bh272 of Bohrium
31    Bh272,
32    /// Isotope Bh273 of Bohrium
33    Bh273,
34    /// Isotope Bh274 of Bohrium
35    Bh274,
36    /// Isotope Bh275 of Bohrium
37    Bh275,
38}
39impl super::RelativeAtomicMass for BohriumIsotope {
40    #[inline]
41    fn relative_atomic_mass(&self) -> f64 {
42        match self {
43            Self::Bh260 => 260.12166f64,
44            Self::Bh261 => 261.12145f64,
45            Self::Bh262 => 262.12297f64,
46            Self::Bh263 => 263.12292f64,
47            Self::Bh264 => 264.12459f64,
48            Self::Bh265 => 265.12491f64,
49            Self::Bh266 => 266.12679f64,
50            Self::Bh267 => 267.1275f64,
51            Self::Bh268 => 268.12969f64,
52            Self::Bh269 => 269.13042f64,
53            Self::Bh270 => 270.13336f64,
54            Self::Bh271 => 271.13526f64,
55            Self::Bh272 => 272.13826f64,
56            Self::Bh273 => 273.14024f64,
57            Self::Bh274 => 274.14355f64,
58            Self::Bh275 => 275.14567f64,
59        }
60    }
61}
62impl super::ElementVariant for BohriumIsotope {
63    #[inline]
64    fn element(&self) -> crate::Element {
65        crate::Element::Bh
66    }
67}
68impl super::MassNumber for BohriumIsotope {
69    #[inline]
70    fn mass_number(&self) -> u16 {
71        match self {
72            Self::Bh260 => 260u16,
73            Self::Bh261 => 261u16,
74            Self::Bh262 => 262u16,
75            Self::Bh263 => 263u16,
76            Self::Bh264 => 264u16,
77            Self::Bh265 => 265u16,
78            Self::Bh266 => 266u16,
79            Self::Bh267 => 267u16,
80            Self::Bh268 => 268u16,
81            Self::Bh269 => 269u16,
82            Self::Bh270 => 270u16,
83            Self::Bh271 => 271u16,
84            Self::Bh272 => 272u16,
85            Self::Bh273 => 273u16,
86            Self::Bh274 => 274u16,
87            Self::Bh275 => 275u16,
88        }
89    }
90}
91impl super::IsotopicComposition for BohriumIsotope {
92    #[inline]
93    fn isotopic_composition(&self) -> Option<f64> {
94        None
95    }
96}
97impl super::MostAbundantIsotope for BohriumIsotope {
98    fn most_abundant_isotope() -> Self {
99        Self::Bh275
100    }
101}
102impl From<BohriumIsotope> for crate::Isotope {
103    fn from(isotope: BohriumIsotope) -> Self {
104        crate::Isotope::Bh(isotope)
105    }
106}
107impl From<BohriumIsotope> for crate::Element {
108    fn from(_isotope: BohriumIsotope) -> Self {
109        crate::Element::Bh
110    }
111}
112impl TryFrom<u64> for BohriumIsotope {
113    type Error = crate::errors::Error;
114    fn try_from(value: u64) -> Result<Self, Self::Error> {
115        match value {
116            260u64 => Ok(Self::Bh260),
117            261u64 => Ok(Self::Bh261),
118            262u64 => Ok(Self::Bh262),
119            263u64 => Ok(Self::Bh263),
120            264u64 => Ok(Self::Bh264),
121            265u64 => Ok(Self::Bh265),
122            266u64 => Ok(Self::Bh266),
123            267u64 => Ok(Self::Bh267),
124            268u64 => Ok(Self::Bh268),
125            269u64 => Ok(Self::Bh269),
126            270u64 => Ok(Self::Bh270),
127            271u64 => Ok(Self::Bh271),
128            272u64 => Ok(Self::Bh272),
129            273u64 => Ok(Self::Bh273),
130            274u64 => Ok(Self::Bh274),
131            275u64 => Ok(Self::Bh275),
132            _ => Err(crate::errors::Error::Isotope(crate::Element::Bh, value)),
133        }
134    }
135}
136impl TryFrom<u8> for BohriumIsotope {
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 BohriumIsotope {
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 BohriumIsotope {
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 BohriumIsotope {
155    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
156        match self {
157            Self::Bh260 => write!(f, "Bh260"),
158            Self::Bh261 => write!(f, "Bh261"),
159            Self::Bh262 => write!(f, "Bh262"),
160            Self::Bh263 => write!(f, "Bh263"),
161            Self::Bh264 => write!(f, "Bh264"),
162            Self::Bh265 => write!(f, "Bh265"),
163            Self::Bh266 => write!(f, "Bh266"),
164            Self::Bh267 => write!(f, "Bh267"),
165            Self::Bh268 => write!(f, "Bh268"),
166            Self::Bh269 => write!(f, "Bh269"),
167            Self::Bh270 => write!(f, "Bh270"),
168            Self::Bh271 => write!(f, "Bh271"),
169            Self::Bh272 => write!(f, "Bh272"),
170            Self::Bh273 => write!(f, "Bh273"),
171            Self::Bh274 => write!(f, "Bh274"),
172            Self::Bh275 => write!(f, "Bh275"),
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 BohriumIsotope::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 BohriumIsotope::iter() {
194            let element = isotope.element();
195            assert_eq!(element, crate::Element::Bh, "Element should be correct for {isotope:?}");
196        }
197    }
198    #[test]
199    fn test_mass_number() {
200        for isotope in BohriumIsotope::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 BohriumIsotope::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 = BohriumIsotope::most_abundant_isotope();
223        let _ = most_abundant.relative_atomic_mass();
224    }
225    #[test]
226    fn test_from_isotope() {
227        for isotope in BohriumIsotope::iter() {
228            let iso: crate::Isotope = isotope.into();
229            match iso {
230                crate::Isotope::Bh(i) => assert_eq!(i, isotope),
231                _ => panic!("Wrong isotope type"),
232            }
233        }
234    }
235    #[test]
236    fn test_from_element() {
237        for isotope in BohriumIsotope::iter() {
238            let elem: crate::Element = isotope.into();
239            assert_eq!(elem, crate::Element::Bh);
240        }
241    }
242    #[test]
243    fn test_try_from_mass_number() {
244        for isotope in BohriumIsotope::iter() {
245            let mass = isotope.mass_number();
246            let iso = BohriumIsotope::try_from(mass).unwrap();
247            assert_eq!(iso, isotope);
248            let iso_u32 = BohriumIsotope::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 = BohriumIsotope::try_from(mass_u8).unwrap();
252                assert_eq!(iso_u8, isotope);
253            }
254        }
255        assert!(BohriumIsotope::try_from(0_u16).is_err());
256        assert!(BohriumIsotope::try_from(1000_u16).is_err());
257        assert!(BohriumIsotope::try_from(0_u32).is_err());
258        assert!(BohriumIsotope::try_from(1000_u32).is_err());
259        assert!(BohriumIsotope::try_from(0_u8).is_err());
260    }
261    #[test]
262    fn test_display() {
263        for isotope in BohriumIsotope::iter() {
264            let s = alloc::format!("{isotope}");
265            assert!(!s.is_empty(), "Display should not be empty for {isotope:?}");
266        }
267    }
268}