1#[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))]
5pub enum GoldIsotope {
7 Au169,
9 Au170,
11 Au171,
13 Au172,
15 Au173,
17 Au174,
19 Au175,
21 Au176,
23 Au177,
25 Au178,
27 Au179,
29 Au180,
31 Au181,
33 Au182,
35 Au183,
37 Au184,
39 Au185,
41 Au186,
43 Au187,
45 Au188,
47 Au189,
49 Au190,
51 Au191,
53 Au192,
55 Au193,
57 Au194,
59 Au195,
61 Au196,
63 Au197,
65 Au198,
67 Au199,
69 Au200,
71 Au201,
73 Au202,
75 Au203,
77 Au204,
79 Au205,
81 Au206,
83 Au207,
85 Au208,
87 Au209,
89 Au210,
91}
92impl super::RelativeAtomicMass for GoldIsotope {
93 #[inline]
94 fn relative_atomic_mass(&self) -> f64 {
95 match self {
96 Self::Au169 => 168.99808f64,
97 Self::Au170 => 169.99597f64,
98 Self::Au171 => 170.991876f64,
99 Self::Au172 => 171.989942f64,
100 Self::Au173 => 172.986241f64,
101 Self::Au174 => 173.984717f64,
102 Self::Au175 => 174.981304f64,
103 Self::Au176 => 175.98025f64,
104 Self::Au177 => 176.97687f64,
105 Self::Au178 => 177.976032f64,
106 Self::Au179 => 178.973174f64,
107 Self::Au180 => 179.972523f64,
108 Self::Au181 => 180.970079f64,
109 Self::Au182 => 181.969618f64,
110 Self::Au183 => 182.967591f64,
111 Self::Au184 => 183.967452f64,
112 Self::Au185 => 184.96579f64,
113 Self::Au186 => 185.965953f64,
114 Self::Au187 => 186.964543f64,
115 Self::Au188 => 187.965349f64,
116 Self::Au189 => 188.963948f64,
117 Self::Au190 => 189.964698f64,
118 Self::Au191 => 190.963702f64,
119 Self::Au192 => 191.964814f64,
120 Self::Au193 => 192.9641373f64,
121 Self::Au194 => 193.9654178f64,
122 Self::Au195 => 194.9650352f64,
123 Self::Au196 => 195.9665699f64,
124 Self::Au197 => 196.96656879f64,
125 Self::Au198 => 197.96824242f64,
126 Self::Au199 => 198.96876528f64,
127 Self::Au200 => 199.970756f64,
128 Self::Au201 => 200.9716575f64,
129 Self::Au202 => 201.973856f64,
130 Self::Au203 => 202.9751544f64,
131 Self::Au204 => 203.97783f64,
132 Self::Au205 => 204.97985f64,
133 Self::Au206 => 205.98474f64,
134 Self::Au207 => 206.9884f64,
135 Self::Au208 => 207.99345f64,
136 Self::Au209 => 208.99735f64,
137 Self::Au210 => 210.0025f64,
138 }
139 }
140}
141impl super::ElementVariant for GoldIsotope {
142 #[inline]
143 fn element(&self) -> crate::Element {
144 crate::Element::Au
145 }
146}
147impl super::MassNumber for GoldIsotope {
148 #[inline]
149 fn mass_number(&self) -> u16 {
150 match self {
151 Self::Au169 => 169u16,
152 Self::Au170 => 170u16,
153 Self::Au171 => 171u16,
154 Self::Au172 => 172u16,
155 Self::Au173 => 173u16,
156 Self::Au174 => 174u16,
157 Self::Au175 => 175u16,
158 Self::Au176 => 176u16,
159 Self::Au177 => 177u16,
160 Self::Au178 => 178u16,
161 Self::Au179 => 179u16,
162 Self::Au180 => 180u16,
163 Self::Au181 => 181u16,
164 Self::Au182 => 182u16,
165 Self::Au183 => 183u16,
166 Self::Au184 => 184u16,
167 Self::Au185 => 185u16,
168 Self::Au186 => 186u16,
169 Self::Au187 => 187u16,
170 Self::Au188 => 188u16,
171 Self::Au189 => 189u16,
172 Self::Au190 => 190u16,
173 Self::Au191 => 191u16,
174 Self::Au192 => 192u16,
175 Self::Au193 => 193u16,
176 Self::Au194 => 194u16,
177 Self::Au195 => 195u16,
178 Self::Au196 => 196u16,
179 Self::Au197 => 197u16,
180 Self::Au198 => 198u16,
181 Self::Au199 => 199u16,
182 Self::Au200 => 200u16,
183 Self::Au201 => 201u16,
184 Self::Au202 => 202u16,
185 Self::Au203 => 203u16,
186 Self::Au204 => 204u16,
187 Self::Au205 => 205u16,
188 Self::Au206 => 206u16,
189 Self::Au207 => 207u16,
190 Self::Au208 => 208u16,
191 Self::Au209 => 209u16,
192 Self::Au210 => 210u16,
193 }
194 }
195}
196impl super::IsotopicComposition for GoldIsotope {
197 #[inline]
198 fn isotopic_composition(&self) -> Option<f64> {
199 match self {
200 Self::Au197 => Some(1f64),
201 _ => None,
202 }
203 }
204}
205impl super::MostAbundantIsotope for GoldIsotope {
206 fn most_abundant_isotope() -> Self {
207 Self::Au197
208 }
209}
210impl From<GoldIsotope> for crate::Isotope {
211 fn from(isotope: GoldIsotope) -> Self {
212 crate::Isotope::Au(isotope)
213 }
214}
215impl From<GoldIsotope> for crate::Element {
216 fn from(_isotope: GoldIsotope) -> Self {
217 crate::Element::Au
218 }
219}
220impl TryFrom<u64> for GoldIsotope {
221 type Error = crate::errors::Error;
222 fn try_from(value: u64) -> Result<Self, Self::Error> {
223 match value {
224 169u64 => Ok(Self::Au169),
225 170u64 => Ok(Self::Au170),
226 171u64 => Ok(Self::Au171),
227 172u64 => Ok(Self::Au172),
228 173u64 => Ok(Self::Au173),
229 174u64 => Ok(Self::Au174),
230 175u64 => Ok(Self::Au175),
231 176u64 => Ok(Self::Au176),
232 177u64 => Ok(Self::Au177),
233 178u64 => Ok(Self::Au178),
234 179u64 => Ok(Self::Au179),
235 180u64 => Ok(Self::Au180),
236 181u64 => Ok(Self::Au181),
237 182u64 => Ok(Self::Au182),
238 183u64 => Ok(Self::Au183),
239 184u64 => Ok(Self::Au184),
240 185u64 => Ok(Self::Au185),
241 186u64 => Ok(Self::Au186),
242 187u64 => Ok(Self::Au187),
243 188u64 => Ok(Self::Au188),
244 189u64 => Ok(Self::Au189),
245 190u64 => Ok(Self::Au190),
246 191u64 => Ok(Self::Au191),
247 192u64 => Ok(Self::Au192),
248 193u64 => Ok(Self::Au193),
249 194u64 => Ok(Self::Au194),
250 195u64 => Ok(Self::Au195),
251 196u64 => Ok(Self::Au196),
252 197u64 => Ok(Self::Au197),
253 198u64 => Ok(Self::Au198),
254 199u64 => Ok(Self::Au199),
255 200u64 => Ok(Self::Au200),
256 201u64 => Ok(Self::Au201),
257 202u64 => Ok(Self::Au202),
258 203u64 => Ok(Self::Au203),
259 204u64 => Ok(Self::Au204),
260 205u64 => Ok(Self::Au205),
261 206u64 => Ok(Self::Au206),
262 207u64 => Ok(Self::Au207),
263 208u64 => Ok(Self::Au208),
264 209u64 => Ok(Self::Au209),
265 210u64 => Ok(Self::Au210),
266 _ => Err(crate::errors::Error::Isotope(crate::Element::Au, value)),
267 }
268 }
269}
270impl TryFrom<u8> for GoldIsotope {
271 type Error = crate::errors::Error;
272 fn try_from(value: u8) -> Result<Self, Self::Error> {
273 Self::try_from(u64::from(value))
274 }
275}
276impl TryFrom<u16> for GoldIsotope {
277 type Error = crate::errors::Error;
278 fn try_from(value: u16) -> Result<Self, Self::Error> {
279 Self::try_from(u64::from(value))
280 }
281}
282impl TryFrom<u32> for GoldIsotope {
283 type Error = crate::errors::Error;
284 fn try_from(value: u32) -> Result<Self, Self::Error> {
285 Self::try_from(u64::from(value))
286 }
287}
288impl core::fmt::Display for GoldIsotope {
289 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
290 match self {
291 Self::Au169 => write!(f, "Au169"),
292 Self::Au170 => write!(f, "Au170"),
293 Self::Au171 => write!(f, "Au171"),
294 Self::Au172 => write!(f, "Au172"),
295 Self::Au173 => write!(f, "Au173"),
296 Self::Au174 => write!(f, "Au174"),
297 Self::Au175 => write!(f, "Au175"),
298 Self::Au176 => write!(f, "Au176"),
299 Self::Au177 => write!(f, "Au177"),
300 Self::Au178 => write!(f, "Au178"),
301 Self::Au179 => write!(f, "Au179"),
302 Self::Au180 => write!(f, "Au180"),
303 Self::Au181 => write!(f, "Au181"),
304 Self::Au182 => write!(f, "Au182"),
305 Self::Au183 => write!(f, "Au183"),
306 Self::Au184 => write!(f, "Au184"),
307 Self::Au185 => write!(f, "Au185"),
308 Self::Au186 => write!(f, "Au186"),
309 Self::Au187 => write!(f, "Au187"),
310 Self::Au188 => write!(f, "Au188"),
311 Self::Au189 => write!(f, "Au189"),
312 Self::Au190 => write!(f, "Au190"),
313 Self::Au191 => write!(f, "Au191"),
314 Self::Au192 => write!(f, "Au192"),
315 Self::Au193 => write!(f, "Au193"),
316 Self::Au194 => write!(f, "Au194"),
317 Self::Au195 => write!(f, "Au195"),
318 Self::Au196 => write!(f, "Au196"),
319 Self::Au197 => write!(f, "Au197"),
320 Self::Au198 => write!(f, "Au198"),
321 Self::Au199 => write!(f, "Au199"),
322 Self::Au200 => write!(f, "Au200"),
323 Self::Au201 => write!(f, "Au201"),
324 Self::Au202 => write!(f, "Au202"),
325 Self::Au203 => write!(f, "Au203"),
326 Self::Au204 => write!(f, "Au204"),
327 Self::Au205 => write!(f, "Au205"),
328 Self::Au206 => write!(f, "Au206"),
329 Self::Au207 => write!(f, "Au207"),
330 Self::Au208 => write!(f, "Au208"),
331 Self::Au209 => write!(f, "Au209"),
332 Self::Au210 => write!(f, "Au210"),
333 }
334 }
335}
336#[cfg(test)]
337mod tests {
338 use strum::IntoEnumIterator;
339
340 use super::*;
341 use crate::isotopes::{
342 ElementVariant, IsotopicComposition, MassNumber, MostAbundantIsotope, RelativeAtomicMass,
343 };
344 #[test]
345 fn test_relative_atomic_mass() {
346 for isotope in GoldIsotope::iter() {
347 let mass = isotope.relative_atomic_mass();
348 assert!(mass > 0.0, "Mass should be positive for {isotope:?}");
349 }
350 }
351 #[test]
352 fn test_element() {
353 for isotope in GoldIsotope::iter() {
354 let element = isotope.element();
355 assert_eq!(element, crate::Element::Au, "Element should be correct for {isotope:?}");
356 }
357 }
358 #[test]
359 fn test_mass_number() {
360 for isotope in GoldIsotope::iter() {
361 let mass_number = isotope.mass_number();
362 assert!(
363 mass_number > 0 && mass_number < 300,
364 "Mass number should be reasonable for {isotope:?}"
365 );
366 }
367 }
368 #[test]
369 fn test_isotopic_composition() {
370 for isotope in GoldIsotope::iter() {
371 let comp = isotope.isotopic_composition();
372 if let Some(c) = comp {
373 assert!(
374 (0.0..=1.0).contains(&c),
375 "Composition should be between 0 and 1 for {isotope:?}"
376 );
377 }
378 }
379 }
380 #[test]
381 fn test_most_abundant() {
382 let most_abundant = GoldIsotope::most_abundant_isotope();
383 let _ = most_abundant.relative_atomic_mass();
384 }
385 #[test]
386 fn test_from_isotope() {
387 for isotope in GoldIsotope::iter() {
388 let iso: crate::Isotope = isotope.into();
389 match iso {
390 crate::Isotope::Au(i) => assert_eq!(i, isotope),
391 _ => panic!("Wrong isotope type"),
392 }
393 }
394 }
395 #[test]
396 fn test_from_element() {
397 for isotope in GoldIsotope::iter() {
398 let elem: crate::Element = isotope.into();
399 assert_eq!(elem, crate::Element::Au);
400 }
401 }
402 #[test]
403 fn test_try_from_mass_number() {
404 for isotope in GoldIsotope::iter() {
405 let mass = isotope.mass_number();
406 let iso = GoldIsotope::try_from(mass).unwrap();
407 assert_eq!(iso, isotope);
408 let iso_u32 = GoldIsotope::try_from(u32::from(mass)).unwrap();
409 assert_eq!(iso_u32, isotope);
410 if let Ok(mass_u8) = u8::try_from(mass) {
411 let iso_u8 = GoldIsotope::try_from(mass_u8).unwrap();
412 assert_eq!(iso_u8, isotope);
413 }
414 }
415 assert!(GoldIsotope::try_from(0_u16).is_err());
416 assert!(GoldIsotope::try_from(1000_u16).is_err());
417 assert!(GoldIsotope::try_from(0_u32).is_err());
418 assert!(GoldIsotope::try_from(1000_u32).is_err());
419 assert!(GoldIsotope::try_from(0_u8).is_err());
420 }
421 #[test]
422 fn test_display() {
423 for isotope in GoldIsotope::iter() {
424 let s = alloc::format!("{isotope}");
425 assert!(!s.is_empty(), "Display should not be empty for {isotope:?}");
426 }
427 }
428}