1#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, strum :: EnumIter)]
3#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
4pub enum PoloniumIsotope {
6 Po186,
8 Po187,
10 Po188,
12 Po189,
14 Po190,
16 Po191,
18 Po192,
20 Po193,
22 Po194,
24 Po195,
26 Po196,
28 Po197,
30 Po198,
32 Po199,
34 Po200,
36 Po201,
38 Po202,
40 Po203,
42 Po204,
44 Po205,
46 Po206,
48 Po207,
50 Po208,
52 Po209,
54 Po210,
56 Po211,
58 Po212,
60 Po213,
62 Po214,
64 Po215,
66 Po216,
68 Po217,
70 Po218,
72 Po219,
74 Po220,
76 Po221,
78 Po222,
80 Po223,
82 Po224,
84 Po225,
86 Po226,
88 Po227,
90}
91impl super::RelativeAtomicMass for PoloniumIsotope {
92 #[inline]
93 fn relative_atomic_mass(&self) -> f64 {
94 match self {
95 Self::Po186 => 186.004393f64,
96 Self::Po187 => 187.003041f64,
97 Self::Po188 => 187.999416f64,
98 Self::Po189 => 188.998473f64,
99 Self::Po190 => 189.995101f64,
100 Self::Po191 => 190.9945585f64,
101 Self::Po192 => 191.991336f64,
102 Self::Po193 => 192.991026f64,
103 Self::Po194 => 193.988186f64,
104 Self::Po195 => 194.988126f64,
105 Self::Po196 => 195.985526f64,
106 Self::Po197 => 196.98566f64,
107 Self::Po198 => 197.983389f64,
108 Self::Po199 => 198.983667f64,
109 Self::Po200 => 199.981799f64,
110 Self::Po201 => 200.9822598f64,
111 Self::Po202 => 201.980758f64,
112 Self::Po203 => 202.9814161f64,
113 Self::Po204 => 203.98031f64,
114 Self::Po205 => 204.981203f64,
115 Self::Po206 => 205.980474f64,
116 Self::Po207 => 206.9815938f64,
117 Self::Po208 => 207.9812461f64,
118 Self::Po209 => 208.9824308f64,
119 Self::Po210 => 209.9828741f64,
120 Self::Po211 => 210.9866536f64,
121 Self::Po212 => 211.9888684f64,
122 Self::Po213 => 212.9928576f64,
123 Self::Po214 => 213.9952017f64,
124 Self::Po215 => 214.9994201f64,
125 Self::Po216 => 216.0019152f64,
126 Self::Po217 => 217.0063182f64,
127 Self::Po218 => 218.0089735f64,
128 Self::Po219 => 219.013614f64,
129 Self::Po220 => 220.016386f64,
130 Self::Po221 => 221.021228f64,
131 Self::Po222 => 222.02414f64,
132 Self::Po223 => 223.02907f64,
133 Self::Po224 => 224.03211f64,
134 Self::Po225 => 225.03707f64,
135 Self::Po226 => 226.04031f64,
136 Self::Po227 => 227.04539f64,
137 }
138 }
139}
140impl super::ElementVariant for PoloniumIsotope {
141 #[inline]
142 fn element(&self) -> crate::Element {
143 crate::Element::Po
144 }
145}
146impl super::MassNumber for PoloniumIsotope {
147 #[inline]
148 fn mass_number(&self) -> u16 {
149 match self {
150 Self::Po186 => 186u16,
151 Self::Po187 => 187u16,
152 Self::Po188 => 188u16,
153 Self::Po189 => 189u16,
154 Self::Po190 => 190u16,
155 Self::Po191 => 191u16,
156 Self::Po192 => 192u16,
157 Self::Po193 => 193u16,
158 Self::Po194 => 194u16,
159 Self::Po195 => 195u16,
160 Self::Po196 => 196u16,
161 Self::Po197 => 197u16,
162 Self::Po198 => 198u16,
163 Self::Po199 => 199u16,
164 Self::Po200 => 200u16,
165 Self::Po201 => 201u16,
166 Self::Po202 => 202u16,
167 Self::Po203 => 203u16,
168 Self::Po204 => 204u16,
169 Self::Po205 => 205u16,
170 Self::Po206 => 206u16,
171 Self::Po207 => 207u16,
172 Self::Po208 => 208u16,
173 Self::Po209 => 209u16,
174 Self::Po210 => 210u16,
175 Self::Po211 => 211u16,
176 Self::Po212 => 212u16,
177 Self::Po213 => 213u16,
178 Self::Po214 => 214u16,
179 Self::Po215 => 215u16,
180 Self::Po216 => 216u16,
181 Self::Po217 => 217u16,
182 Self::Po218 => 218u16,
183 Self::Po219 => 219u16,
184 Self::Po220 => 220u16,
185 Self::Po221 => 221u16,
186 Self::Po222 => 222u16,
187 Self::Po223 => 223u16,
188 Self::Po224 => 224u16,
189 Self::Po225 => 225u16,
190 Self::Po226 => 226u16,
191 Self::Po227 => 227u16,
192 }
193 }
194}
195impl super::IsotopicComposition for PoloniumIsotope {
196 #[inline]
197 fn isotopic_composition(&self) -> Option<f64> {
198 None
199 }
200}
201impl super::MostAbundantIsotope for PoloniumIsotope {
202 fn most_abundant_isotope() -> Self {
203 Self::Po227
204 }
205}
206impl From<PoloniumIsotope> for crate::Isotope {
207 fn from(isotope: PoloniumIsotope) -> Self {
208 crate::Isotope::Po(isotope)
209 }
210}
211impl From<PoloniumIsotope> for crate::Element {
212 fn from(_isotope: PoloniumIsotope) -> Self {
213 crate::Element::Po
214 }
215}
216impl TryFrom<u64> for PoloniumIsotope {
217 type Error = crate::errors::Error;
218 fn try_from(value: u64) -> Result<Self, Self::Error> {
219 match value {
220 186u64 => Ok(Self::Po186),
221 187u64 => Ok(Self::Po187),
222 188u64 => Ok(Self::Po188),
223 189u64 => Ok(Self::Po189),
224 190u64 => Ok(Self::Po190),
225 191u64 => Ok(Self::Po191),
226 192u64 => Ok(Self::Po192),
227 193u64 => Ok(Self::Po193),
228 194u64 => Ok(Self::Po194),
229 195u64 => Ok(Self::Po195),
230 196u64 => Ok(Self::Po196),
231 197u64 => Ok(Self::Po197),
232 198u64 => Ok(Self::Po198),
233 199u64 => Ok(Self::Po199),
234 200u64 => Ok(Self::Po200),
235 201u64 => Ok(Self::Po201),
236 202u64 => Ok(Self::Po202),
237 203u64 => Ok(Self::Po203),
238 204u64 => Ok(Self::Po204),
239 205u64 => Ok(Self::Po205),
240 206u64 => Ok(Self::Po206),
241 207u64 => Ok(Self::Po207),
242 208u64 => Ok(Self::Po208),
243 209u64 => Ok(Self::Po209),
244 210u64 => Ok(Self::Po210),
245 211u64 => Ok(Self::Po211),
246 212u64 => Ok(Self::Po212),
247 213u64 => Ok(Self::Po213),
248 214u64 => Ok(Self::Po214),
249 215u64 => Ok(Self::Po215),
250 216u64 => Ok(Self::Po216),
251 217u64 => Ok(Self::Po217),
252 218u64 => Ok(Self::Po218),
253 219u64 => Ok(Self::Po219),
254 220u64 => Ok(Self::Po220),
255 221u64 => Ok(Self::Po221),
256 222u64 => Ok(Self::Po222),
257 223u64 => Ok(Self::Po223),
258 224u64 => Ok(Self::Po224),
259 225u64 => Ok(Self::Po225),
260 226u64 => Ok(Self::Po226),
261 227u64 => Ok(Self::Po227),
262 _ => Err(crate::errors::Error::Isotope(crate::Element::Po, value)),
263 }
264 }
265}
266impl TryFrom<u8> for PoloniumIsotope {
267 type Error = crate::errors::Error;
268 fn try_from(value: u8) -> Result<Self, Self::Error> {
269 Self::try_from(u64::from(value))
270 }
271}
272impl TryFrom<u16> for PoloniumIsotope {
273 type Error = crate::errors::Error;
274 fn try_from(value: u16) -> Result<Self, Self::Error> {
275 Self::try_from(u64::from(value))
276 }
277}
278impl TryFrom<u32> for PoloniumIsotope {
279 type Error = crate::errors::Error;
280 fn try_from(value: u32) -> Result<Self, Self::Error> {
281 Self::try_from(u64::from(value))
282 }
283}
284impl core::fmt::Display for PoloniumIsotope {
285 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
286 match self {
287 Self::Po186 => write!(f, "Po186"),
288 Self::Po187 => write!(f, "Po187"),
289 Self::Po188 => write!(f, "Po188"),
290 Self::Po189 => write!(f, "Po189"),
291 Self::Po190 => write!(f, "Po190"),
292 Self::Po191 => write!(f, "Po191"),
293 Self::Po192 => write!(f, "Po192"),
294 Self::Po193 => write!(f, "Po193"),
295 Self::Po194 => write!(f, "Po194"),
296 Self::Po195 => write!(f, "Po195"),
297 Self::Po196 => write!(f, "Po196"),
298 Self::Po197 => write!(f, "Po197"),
299 Self::Po198 => write!(f, "Po198"),
300 Self::Po199 => write!(f, "Po199"),
301 Self::Po200 => write!(f, "Po200"),
302 Self::Po201 => write!(f, "Po201"),
303 Self::Po202 => write!(f, "Po202"),
304 Self::Po203 => write!(f, "Po203"),
305 Self::Po204 => write!(f, "Po204"),
306 Self::Po205 => write!(f, "Po205"),
307 Self::Po206 => write!(f, "Po206"),
308 Self::Po207 => write!(f, "Po207"),
309 Self::Po208 => write!(f, "Po208"),
310 Self::Po209 => write!(f, "Po209"),
311 Self::Po210 => write!(f, "Po210"),
312 Self::Po211 => write!(f, "Po211"),
313 Self::Po212 => write!(f, "Po212"),
314 Self::Po213 => write!(f, "Po213"),
315 Self::Po214 => write!(f, "Po214"),
316 Self::Po215 => write!(f, "Po215"),
317 Self::Po216 => write!(f, "Po216"),
318 Self::Po217 => write!(f, "Po217"),
319 Self::Po218 => write!(f, "Po218"),
320 Self::Po219 => write!(f, "Po219"),
321 Self::Po220 => write!(f, "Po220"),
322 Self::Po221 => write!(f, "Po221"),
323 Self::Po222 => write!(f, "Po222"),
324 Self::Po223 => write!(f, "Po223"),
325 Self::Po224 => write!(f, "Po224"),
326 Self::Po225 => write!(f, "Po225"),
327 Self::Po226 => write!(f, "Po226"),
328 Self::Po227 => write!(f, "Po227"),
329 }
330 }
331}
332#[cfg(test)]
333mod tests {
334 use strum::IntoEnumIterator;
335
336 use super::*;
337 use crate::isotopes::{
338 ElementVariant, IsotopicComposition, MassNumber, MostAbundantIsotope, RelativeAtomicMass,
339 };
340 #[test]
341 fn test_relative_atomic_mass() {
342 for isotope in PoloniumIsotope::iter() {
343 let mass = isotope.relative_atomic_mass();
344 assert!(mass > 0.0, "Mass should be positive for {isotope:?}");
345 }
346 }
347 #[test]
348 fn test_element() {
349 for isotope in PoloniumIsotope::iter() {
350 let element = isotope.element();
351 assert_eq!(element, crate::Element::Po, "Element should be correct for {isotope:?}");
352 }
353 }
354 #[test]
355 fn test_mass_number() {
356 for isotope in PoloniumIsotope::iter() {
357 let mass_number = isotope.mass_number();
358 assert!(
359 mass_number > 0 && mass_number < 300,
360 "Mass number should be reasonable for {isotope:?}"
361 );
362 }
363 }
364 #[test]
365 fn test_isotopic_composition() {
366 for isotope in PoloniumIsotope::iter() {
367 let comp = isotope.isotopic_composition();
368 if let Some(c) = comp {
369 assert!(
370 (0.0..=1.0).contains(&c),
371 "Composition should be between 0 and 1 for {isotope:?}"
372 );
373 }
374 }
375 }
376 #[test]
377 fn test_most_abundant() {
378 let most_abundant = PoloniumIsotope::most_abundant_isotope();
379 let _ = most_abundant.relative_atomic_mass();
380 }
381 #[test]
382 fn test_from_isotope() {
383 for isotope in PoloniumIsotope::iter() {
384 let iso: crate::Isotope = isotope.into();
385 match iso {
386 crate::Isotope::Po(i) => assert_eq!(i, isotope),
387 _ => panic!("Wrong isotope type"),
388 }
389 }
390 }
391 #[test]
392 fn test_from_element() {
393 for isotope in PoloniumIsotope::iter() {
394 let elem: crate::Element = isotope.into();
395 assert_eq!(elem, crate::Element::Po);
396 }
397 }
398 #[test]
399 fn test_try_from_mass_number() {
400 for isotope in PoloniumIsotope::iter() {
401 let mass = isotope.mass_number();
402 let iso = PoloniumIsotope::try_from(mass).unwrap();
403 assert_eq!(iso, isotope);
404 let iso_u32 = PoloniumIsotope::try_from(u32::from(mass)).unwrap();
405 assert_eq!(iso_u32, isotope);
406 if let Ok(mass_u8) = u8::try_from(mass) {
407 let iso_u8 = PoloniumIsotope::try_from(mass_u8).unwrap();
408 assert_eq!(iso_u8, isotope);
409 }
410 }
411 assert!(PoloniumIsotope::try_from(0_u16).is_err());
412 assert!(PoloniumIsotope::try_from(1000_u16).is_err());
413 assert!(PoloniumIsotope::try_from(0_u32).is_err());
414 assert!(PoloniumIsotope::try_from(1000_u32).is_err());
415 assert!(PoloniumIsotope::try_from(0_u8).is_err());
416 }
417 #[test]
418 fn test_display() {
419 for isotope in PoloniumIsotope::iter() {
420 let s = alloc::format!("{isotope}");
421 assert!(!s.is_empty(), "Display should not be empty for {isotope:?}");
422 }
423 }
424}