Skip to main content

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#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
5/// Isotopes of the element Bohrium
6pub enum BohriumIsotope {
7    /// Isotope Bh260 of Bohrium
8    Bh260,
9    /// Isotope Bh261 of Bohrium
10    Bh261,
11    /// Isotope Bh262 of Bohrium
12    Bh262,
13    /// Isotope Bh263 of Bohrium
14    Bh263,
15    /// Isotope Bh264 of Bohrium
16    Bh264,
17    /// Isotope Bh265 of Bohrium
18    Bh265,
19    /// Isotope Bh266 of Bohrium
20    Bh266,
21    /// Isotope Bh267 of Bohrium
22    Bh267,
23    /// Isotope Bh268 of Bohrium
24    Bh268,
25    /// Isotope Bh269 of Bohrium
26    Bh269,
27    /// Isotope Bh270 of Bohrium
28    Bh270,
29    /// Isotope Bh271 of Bohrium
30    Bh271,
31    /// Isotope Bh272 of Bohrium
32    Bh272,
33    /// Isotope Bh273 of Bohrium
34    Bh273,
35    /// Isotope Bh274 of Bohrium
36    Bh274,
37    /// Isotope Bh275 of Bohrium
38    Bh275,
39}
40impl super::RelativeAtomicMass for BohriumIsotope {
41    #[inline]
42    fn relative_atomic_mass(&self) -> f64 {
43        match self {
44            Self::Bh260 => 260.12166f64,
45            Self::Bh261 => 261.12145f64,
46            Self::Bh262 => 262.12297f64,
47            Self::Bh263 => 263.12292f64,
48            Self::Bh264 => 264.12459f64,
49            Self::Bh265 => 265.12491f64,
50            Self::Bh266 => 266.12679f64,
51            Self::Bh267 => 267.1275f64,
52            Self::Bh268 => 268.12969f64,
53            Self::Bh269 => 269.13042f64,
54            Self::Bh270 => 270.13336f64,
55            Self::Bh271 => 271.13526f64,
56            Self::Bh272 => 272.13826f64,
57            Self::Bh273 => 273.14024f64,
58            Self::Bh274 => 274.14355f64,
59            Self::Bh275 => 275.14567f64,
60        }
61    }
62}
63impl super::ElementVariant for BohriumIsotope {
64    #[inline]
65    fn element(&self) -> crate::Element {
66        crate::Element::Bh
67    }
68}
69impl super::MassNumber for BohriumIsotope {
70    #[inline]
71    fn mass_number(&self) -> u16 {
72        match self {
73            Self::Bh260 => 260u16,
74            Self::Bh261 => 261u16,
75            Self::Bh262 => 262u16,
76            Self::Bh263 => 263u16,
77            Self::Bh264 => 264u16,
78            Self::Bh265 => 265u16,
79            Self::Bh266 => 266u16,
80            Self::Bh267 => 267u16,
81            Self::Bh268 => 268u16,
82            Self::Bh269 => 269u16,
83            Self::Bh270 => 270u16,
84            Self::Bh271 => 271u16,
85            Self::Bh272 => 272u16,
86            Self::Bh273 => 273u16,
87            Self::Bh274 => 274u16,
88            Self::Bh275 => 275u16,
89        }
90    }
91}
92impl super::IsotopicComposition for BohriumIsotope {
93    #[inline]
94    fn isotopic_composition(&self) -> Option<f64> {
95        None
96    }
97}
98impl super::MostAbundantIsotope for BohriumIsotope {
99    fn most_abundant_isotope() -> Self {
100        Self::Bh275
101    }
102}
103impl From<BohriumIsotope> for crate::Isotope {
104    fn from(isotope: BohriumIsotope) -> Self {
105        crate::Isotope::Bh(isotope)
106    }
107}
108impl From<BohriumIsotope> for crate::Element {
109    fn from(_isotope: BohriumIsotope) -> Self {
110        crate::Element::Bh
111    }
112}
113impl TryFrom<u64> for BohriumIsotope {
114    type Error = crate::errors::Error;
115    fn try_from(value: u64) -> Result<Self, Self::Error> {
116        match value {
117            260u64 => Ok(Self::Bh260),
118            261u64 => Ok(Self::Bh261),
119            262u64 => Ok(Self::Bh262),
120            263u64 => Ok(Self::Bh263),
121            264u64 => Ok(Self::Bh264),
122            265u64 => Ok(Self::Bh265),
123            266u64 => Ok(Self::Bh266),
124            267u64 => Ok(Self::Bh267),
125            268u64 => Ok(Self::Bh268),
126            269u64 => Ok(Self::Bh269),
127            270u64 => Ok(Self::Bh270),
128            271u64 => Ok(Self::Bh271),
129            272u64 => Ok(Self::Bh272),
130            273u64 => Ok(Self::Bh273),
131            274u64 => Ok(Self::Bh274),
132            275u64 => Ok(Self::Bh275),
133            _ => Err(crate::errors::Error::Isotope(crate::Element::Bh, value)),
134        }
135    }
136}
137impl TryFrom<u8> for BohriumIsotope {
138    type Error = crate::errors::Error;
139    fn try_from(value: u8) -> Result<Self, Self::Error> {
140        Self::try_from(u64::from(value))
141    }
142}
143impl TryFrom<u16> for BohriumIsotope {
144    type Error = crate::errors::Error;
145    fn try_from(value: u16) -> Result<Self, Self::Error> {
146        Self::try_from(u64::from(value))
147    }
148}
149impl TryFrom<u32> for BohriumIsotope {
150    type Error = crate::errors::Error;
151    fn try_from(value: u32) -> Result<Self, Self::Error> {
152        Self::try_from(u64::from(value))
153    }
154}
155impl core::fmt::Display for BohriumIsotope {
156    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
157        match self {
158            Self::Bh260 => write!(f, "Bh260"),
159            Self::Bh261 => write!(f, "Bh261"),
160            Self::Bh262 => write!(f, "Bh262"),
161            Self::Bh263 => write!(f, "Bh263"),
162            Self::Bh264 => write!(f, "Bh264"),
163            Self::Bh265 => write!(f, "Bh265"),
164            Self::Bh266 => write!(f, "Bh266"),
165            Self::Bh267 => write!(f, "Bh267"),
166            Self::Bh268 => write!(f, "Bh268"),
167            Self::Bh269 => write!(f, "Bh269"),
168            Self::Bh270 => write!(f, "Bh270"),
169            Self::Bh271 => write!(f, "Bh271"),
170            Self::Bh272 => write!(f, "Bh272"),
171            Self::Bh273 => write!(f, "Bh273"),
172            Self::Bh274 => write!(f, "Bh274"),
173            Self::Bh275 => write!(f, "Bh275"),
174        }
175    }
176}
177#[cfg(test)]
178mod tests {
179    use strum::IntoEnumIterator;
180
181    use super::*;
182    use crate::isotopes::{
183        ElementVariant, IsotopicComposition, MassNumber, MostAbundantIsotope, RelativeAtomicMass,
184    };
185    #[test]
186    fn test_relative_atomic_mass() {
187        for isotope in BohriumIsotope::iter() {
188            let mass = isotope.relative_atomic_mass();
189            assert!(mass > 0.0, "Mass should be positive for {isotope:?}");
190        }
191    }
192    #[test]
193    fn test_element() {
194        for isotope in BohriumIsotope::iter() {
195            let element = isotope.element();
196            assert_eq!(element, crate::Element::Bh, "Element should be correct for {isotope:?}");
197        }
198    }
199    #[test]
200    fn test_mass_number() {
201        for isotope in BohriumIsotope::iter() {
202            let mass_number = isotope.mass_number();
203            assert!(
204                mass_number > 0 && mass_number < 300,
205                "Mass number should be reasonable for {isotope:?}"
206            );
207        }
208    }
209    #[test]
210    fn test_isotopic_composition() {
211        for isotope in BohriumIsotope::iter() {
212            let comp = isotope.isotopic_composition();
213            if let Some(c) = comp {
214                assert!(
215                    (0.0..=1.0).contains(&c),
216                    "Composition should be between 0 and 1 for {isotope:?}"
217                );
218            }
219        }
220    }
221    #[test]
222    fn test_most_abundant() {
223        let most_abundant = BohriumIsotope::most_abundant_isotope();
224        let _ = most_abundant.relative_atomic_mass();
225    }
226    #[test]
227    fn test_from_isotope() {
228        for isotope in BohriumIsotope::iter() {
229            let iso: crate::Isotope = isotope.into();
230            match iso {
231                crate::Isotope::Bh(i) => assert_eq!(i, isotope),
232                _ => panic!("Wrong isotope type"),
233            }
234        }
235    }
236    #[test]
237    fn test_from_element() {
238        for isotope in BohriumIsotope::iter() {
239            let elem: crate::Element = isotope.into();
240            assert_eq!(elem, crate::Element::Bh);
241        }
242    }
243    #[test]
244    fn test_try_from_mass_number() {
245        for isotope in BohriumIsotope::iter() {
246            let mass = isotope.mass_number();
247            let iso = BohriumIsotope::try_from(mass).unwrap();
248            assert_eq!(iso, isotope);
249            let iso_u32 = BohriumIsotope::try_from(u32::from(mass)).unwrap();
250            assert_eq!(iso_u32, isotope);
251            if let Ok(mass_u8) = u8::try_from(mass) {
252                let iso_u8 = BohriumIsotope::try_from(mass_u8).unwrap();
253                assert_eq!(iso_u8, isotope);
254            }
255        }
256        assert!(BohriumIsotope::try_from(0_u16).is_err());
257        assert!(BohriumIsotope::try_from(1000_u16).is_err());
258        assert!(BohriumIsotope::try_from(0_u32).is_err());
259        assert!(BohriumIsotope::try_from(1000_u32).is_err());
260        assert!(BohriumIsotope::try_from(0_u8).is_err());
261    }
262    #[test]
263    fn test_display() {
264        for isotope in BohriumIsotope::iter() {
265            let s = alloc::format!("{isotope}");
266            assert!(!s.is_empty(), "Display should not be empty for {isotope:?}");
267        }
268    }
269}