1#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, strum :: EnumIter)]
3#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
4pub enum SilverIsotope {
6 Ag93,
8 Ag94,
10 Ag95,
12 Ag96,
14 Ag97,
16 Ag98,
18 Ag99,
20 Ag100,
22 Ag101,
24 Ag102,
26 Ag103,
28 Ag104,
30 Ag105,
32 Ag106,
34 Ag107,
36 Ag108,
38 Ag109,
40 Ag110,
42 Ag111,
44 Ag112,
46 Ag113,
48 Ag114,
50 Ag115,
52 Ag116,
54 Ag117,
56 Ag118,
58 Ag119,
60 Ag120,
62 Ag121,
64 Ag122,
66 Ag123,
68 Ag124,
70 Ag125,
72 Ag126,
74 Ag127,
76 Ag128,
78 Ag129,
80 Ag130,
82}
83impl super::RelativeAtomicMass for SilverIsotope {
84 #[inline]
85 fn relative_atomic_mass(&self) -> f64 {
86 match self {
87 Self::Ag93 => 92.95033f64,
88 Self::Ag94 => 93.94373f64,
89 Self::Ag95 => 94.93602f64,
90 Self::Ag96 => 95.930744f64,
91 Self::Ag97 => 96.92397f64,
92 Self::Ag98 => 97.92156f64,
93 Self::Ag99 => 98.9176458f64,
94 Self::Ag100 => 99.9161154f64,
95 Self::Ag101 => 100.912684f64,
96 Self::Ag102 => 101.9117047f64,
97 Self::Ag103 => 102.9089631f64,
98 Self::Ag104 => 103.9086239f64,
99 Self::Ag105 => 104.9065256f64,
100 Self::Ag106 => 105.9066636f64,
101 Self::Ag107 => 106.9050916f64,
102 Self::Ag108 => 107.9059503f64,
103 Self::Ag109 => 108.9047553f64,
104 Self::Ag110 => 109.9061102f64,
105 Self::Ag111 => 110.9052959f64,
106 Self::Ag112 => 111.9070486f64,
107 Self::Ag113 => 112.906573f64,
108 Self::Ag114 => 113.908823f64,
109 Self::Ag115 => 114.908767f64,
110 Self::Ag116 => 115.9113868f64,
111 Self::Ag117 => 116.911774f64,
112 Self::Ag118 => 117.9145955f64,
113 Self::Ag119 => 118.91557f64,
114 Self::Ag120 => 119.9187848f64,
115 Self::Ag121 => 120.920125f64,
116 Self::Ag122 => 121.923664f64,
117 Self::Ag123 => 122.925337f64,
118 Self::Ag124 => 123.92893f64,
119 Self::Ag125 => 124.93105f64,
120 Self::Ag126 => 125.93475f64,
121 Self::Ag127 => 126.93711f64,
122 Self::Ag128 => 127.94106f64,
123 Self::Ag129 => 128.94395f64,
124 Self::Ag130 => 129.9507f64,
125 }
126 }
127}
128impl super::ElementVariant for SilverIsotope {
129 #[inline]
130 fn element(&self) -> crate::Element {
131 crate::Element::Ag
132 }
133}
134impl super::MassNumber for SilverIsotope {
135 #[inline]
136 fn mass_number(&self) -> u16 {
137 match self {
138 Self::Ag93 => 93u16,
139 Self::Ag94 => 94u16,
140 Self::Ag95 => 95u16,
141 Self::Ag96 => 96u16,
142 Self::Ag97 => 97u16,
143 Self::Ag98 => 98u16,
144 Self::Ag99 => 99u16,
145 Self::Ag100 => 100u16,
146 Self::Ag101 => 101u16,
147 Self::Ag102 => 102u16,
148 Self::Ag103 => 103u16,
149 Self::Ag104 => 104u16,
150 Self::Ag105 => 105u16,
151 Self::Ag106 => 106u16,
152 Self::Ag107 => 107u16,
153 Self::Ag108 => 108u16,
154 Self::Ag109 => 109u16,
155 Self::Ag110 => 110u16,
156 Self::Ag111 => 111u16,
157 Self::Ag112 => 112u16,
158 Self::Ag113 => 113u16,
159 Self::Ag114 => 114u16,
160 Self::Ag115 => 115u16,
161 Self::Ag116 => 116u16,
162 Self::Ag117 => 117u16,
163 Self::Ag118 => 118u16,
164 Self::Ag119 => 119u16,
165 Self::Ag120 => 120u16,
166 Self::Ag121 => 121u16,
167 Self::Ag122 => 122u16,
168 Self::Ag123 => 123u16,
169 Self::Ag124 => 124u16,
170 Self::Ag125 => 125u16,
171 Self::Ag126 => 126u16,
172 Self::Ag127 => 127u16,
173 Self::Ag128 => 128u16,
174 Self::Ag129 => 129u16,
175 Self::Ag130 => 130u16,
176 }
177 }
178}
179impl super::IsotopicComposition for SilverIsotope {
180 #[inline]
181 fn isotopic_composition(&self) -> Option<f64> {
182 match self {
183 Self::Ag107 => Some(0.51839f64),
184 Self::Ag109 => Some(0.48161f64),
185 _ => None,
186 }
187 }
188}
189impl super::MostAbundantIsotope for SilverIsotope {
190 fn most_abundant_isotope() -> Self {
191 Self::Ag107
192 }
193}
194impl From<SilverIsotope> for crate::Isotope {
195 fn from(isotope: SilverIsotope) -> Self {
196 crate::Isotope::Ag(isotope)
197 }
198}
199impl From<SilverIsotope> for crate::Element {
200 fn from(_isotope: SilverIsotope) -> Self {
201 crate::Element::Ag
202 }
203}
204impl TryFrom<u64> for SilverIsotope {
205 type Error = crate::errors::Error;
206 fn try_from(value: u64) -> Result<Self, Self::Error> {
207 match value {
208 93u64 => Ok(Self::Ag93),
209 94u64 => Ok(Self::Ag94),
210 95u64 => Ok(Self::Ag95),
211 96u64 => Ok(Self::Ag96),
212 97u64 => Ok(Self::Ag97),
213 98u64 => Ok(Self::Ag98),
214 99u64 => Ok(Self::Ag99),
215 100u64 => Ok(Self::Ag100),
216 101u64 => Ok(Self::Ag101),
217 102u64 => Ok(Self::Ag102),
218 103u64 => Ok(Self::Ag103),
219 104u64 => Ok(Self::Ag104),
220 105u64 => Ok(Self::Ag105),
221 106u64 => Ok(Self::Ag106),
222 107u64 => Ok(Self::Ag107),
223 108u64 => Ok(Self::Ag108),
224 109u64 => Ok(Self::Ag109),
225 110u64 => Ok(Self::Ag110),
226 111u64 => Ok(Self::Ag111),
227 112u64 => Ok(Self::Ag112),
228 113u64 => Ok(Self::Ag113),
229 114u64 => Ok(Self::Ag114),
230 115u64 => Ok(Self::Ag115),
231 116u64 => Ok(Self::Ag116),
232 117u64 => Ok(Self::Ag117),
233 118u64 => Ok(Self::Ag118),
234 119u64 => Ok(Self::Ag119),
235 120u64 => Ok(Self::Ag120),
236 121u64 => Ok(Self::Ag121),
237 122u64 => Ok(Self::Ag122),
238 123u64 => Ok(Self::Ag123),
239 124u64 => Ok(Self::Ag124),
240 125u64 => Ok(Self::Ag125),
241 126u64 => Ok(Self::Ag126),
242 127u64 => Ok(Self::Ag127),
243 128u64 => Ok(Self::Ag128),
244 129u64 => Ok(Self::Ag129),
245 130u64 => Ok(Self::Ag130),
246 _ => Err(crate::errors::Error::Isotope(crate::Element::Ag, value)),
247 }
248 }
249}
250impl TryFrom<u8> for SilverIsotope {
251 type Error = crate::errors::Error;
252 fn try_from(value: u8) -> Result<Self, Self::Error> {
253 Self::try_from(u64::from(value))
254 }
255}
256impl TryFrom<u16> for SilverIsotope {
257 type Error = crate::errors::Error;
258 fn try_from(value: u16) -> Result<Self, Self::Error> {
259 Self::try_from(u64::from(value))
260 }
261}
262impl TryFrom<u32> for SilverIsotope {
263 type Error = crate::errors::Error;
264 fn try_from(value: u32) -> Result<Self, Self::Error> {
265 Self::try_from(u64::from(value))
266 }
267}
268impl core::fmt::Display for SilverIsotope {
269 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
270 match self {
271 Self::Ag93 => write!(f, "Ag93"),
272 Self::Ag94 => write!(f, "Ag94"),
273 Self::Ag95 => write!(f, "Ag95"),
274 Self::Ag96 => write!(f, "Ag96"),
275 Self::Ag97 => write!(f, "Ag97"),
276 Self::Ag98 => write!(f, "Ag98"),
277 Self::Ag99 => write!(f, "Ag99"),
278 Self::Ag100 => write!(f, "Ag100"),
279 Self::Ag101 => write!(f, "Ag101"),
280 Self::Ag102 => write!(f, "Ag102"),
281 Self::Ag103 => write!(f, "Ag103"),
282 Self::Ag104 => write!(f, "Ag104"),
283 Self::Ag105 => write!(f, "Ag105"),
284 Self::Ag106 => write!(f, "Ag106"),
285 Self::Ag107 => write!(f, "Ag107"),
286 Self::Ag108 => write!(f, "Ag108"),
287 Self::Ag109 => write!(f, "Ag109"),
288 Self::Ag110 => write!(f, "Ag110"),
289 Self::Ag111 => write!(f, "Ag111"),
290 Self::Ag112 => write!(f, "Ag112"),
291 Self::Ag113 => write!(f, "Ag113"),
292 Self::Ag114 => write!(f, "Ag114"),
293 Self::Ag115 => write!(f, "Ag115"),
294 Self::Ag116 => write!(f, "Ag116"),
295 Self::Ag117 => write!(f, "Ag117"),
296 Self::Ag118 => write!(f, "Ag118"),
297 Self::Ag119 => write!(f, "Ag119"),
298 Self::Ag120 => write!(f, "Ag120"),
299 Self::Ag121 => write!(f, "Ag121"),
300 Self::Ag122 => write!(f, "Ag122"),
301 Self::Ag123 => write!(f, "Ag123"),
302 Self::Ag124 => write!(f, "Ag124"),
303 Self::Ag125 => write!(f, "Ag125"),
304 Self::Ag126 => write!(f, "Ag126"),
305 Self::Ag127 => write!(f, "Ag127"),
306 Self::Ag128 => write!(f, "Ag128"),
307 Self::Ag129 => write!(f, "Ag129"),
308 Self::Ag130 => write!(f, "Ag130"),
309 }
310 }
311}
312#[cfg(test)]
313mod tests {
314 use strum::IntoEnumIterator;
315
316 use super::*;
317 use crate::isotopes::{
318 ElementVariant, IsotopicComposition, MassNumber, MostAbundantIsotope, RelativeAtomicMass,
319 };
320 #[test]
321 fn test_relative_atomic_mass() {
322 for isotope in SilverIsotope::iter() {
323 let mass = isotope.relative_atomic_mass();
324 assert!(mass > 0.0, "Mass should be positive for {isotope:?}");
325 }
326 }
327 #[test]
328 fn test_element() {
329 for isotope in SilverIsotope::iter() {
330 let element = isotope.element();
331 assert_eq!(element, crate::Element::Ag, "Element should be correct for {isotope:?}");
332 }
333 }
334 #[test]
335 fn test_mass_number() {
336 for isotope in SilverIsotope::iter() {
337 let mass_number = isotope.mass_number();
338 assert!(
339 mass_number > 0 && mass_number < 300,
340 "Mass number should be reasonable for {isotope:?}"
341 );
342 }
343 }
344 #[test]
345 fn test_isotopic_composition() {
346 for isotope in SilverIsotope::iter() {
347 let comp = isotope.isotopic_composition();
348 if let Some(c) = comp {
349 assert!(
350 (0.0..=1.0).contains(&c),
351 "Composition should be between 0 and 1 for {isotope:?}"
352 );
353 }
354 }
355 }
356 #[test]
357 fn test_most_abundant() {
358 let most_abundant = SilverIsotope::most_abundant_isotope();
359 let _ = most_abundant.relative_atomic_mass();
360 }
361 #[test]
362 fn test_from_isotope() {
363 for isotope in SilverIsotope::iter() {
364 let iso: crate::Isotope = isotope.into();
365 match iso {
366 crate::Isotope::Ag(i) => assert_eq!(i, isotope),
367 _ => panic!("Wrong isotope type"),
368 }
369 }
370 }
371 #[test]
372 fn test_from_element() {
373 for isotope in SilverIsotope::iter() {
374 let elem: crate::Element = isotope.into();
375 assert_eq!(elem, crate::Element::Ag);
376 }
377 }
378 #[test]
379 fn test_try_from_mass_number() {
380 for isotope in SilverIsotope::iter() {
381 let mass = isotope.mass_number();
382 let iso = SilverIsotope::try_from(mass).unwrap();
383 assert_eq!(iso, isotope);
384 let iso_u32 = SilverIsotope::try_from(u32::from(mass)).unwrap();
385 assert_eq!(iso_u32, isotope);
386 if let Ok(mass_u8) = u8::try_from(mass) {
387 let iso_u8 = SilverIsotope::try_from(mass_u8).unwrap();
388 assert_eq!(iso_u8, isotope);
389 }
390 }
391 assert!(SilverIsotope::try_from(0_u16).is_err());
392 assert!(SilverIsotope::try_from(1000_u16).is_err());
393 assert!(SilverIsotope::try_from(0_u32).is_err());
394 assert!(SilverIsotope::try_from(1000_u32).is_err());
395 assert!(SilverIsotope::try_from(0_u8).is_err());
396 }
397 #[test]
398 fn test_display() {
399 for isotope in SilverIsotope::iter() {
400 let s = alloc::format!("{isotope}");
401 assert!(!s.is_empty(), "Display should not be empty for {isotope:?}");
402 }
403 }
404}