Nuclide 0.3.0

Database and simple modeling of all known nuclides
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
/*

  Decay modes, For efficiency purposes absolutely zero checks are performance
  ZZZAAAM syntax acceptance
  Isomers


  check if electron neutrino and electron have same energy output/mass

  /*
     Correct formula for particle energies

     total_energy = daughterenergy + n*particle + n*particle2
     particle_energy = n*particle + n*particle2;

     To solve for particle mass

     particlemass*
  */
  
  DecayStruct should have an All variant
  
  
  Functions to implement
  // return NAN if DecayMode not possible
  fn branching_ratio<DecayMode> -> f64
  
  fn parent_list -> Vec<Nuclide>
  // Vector of potential daughters no energies
  fn daughter_list -> Vec<Nuclide>
  
  fn daughter_list_energetic<DecayMode> -> Vec<Vec<Particle>>
  // returns
  fn unchecked_decay<DecayMode> -> 
  
  // Attempts to decay nuclide returns None if it is not a supported branch
  fn single_decay<DecayMode> -> Option<Nuclide>
  
  // Continously applies the same decay mode
  fn continous_decay<DecayMode> -> 
  
  // Returns Nan for All or if separation is not possible
  fn separation_energy<DecayMode> -> f64
  
  // Halflife for the decay branch, inf if stable and NaN if decaymode is not supported
  fn half_life<DecayMode> -> f64
  
    // Decay constant for the decay branch, inf if stable and NaN if decaymode is not supported
  fn decay_constant<DecayMode> -> f64
  // Replaces decay_time, returns the probability of decay for given branch. Zero if stable or branch not supported
  fn decay_probability<DecayMode>(T)
  
  
  Constructing a parent list 
  
    Enumerate all decay possibilities
    Change the nuclide to find the parent, then check possible decay modes that lead to the daughter
    Fission is not counted

*/
use crate::nuclidedata::nuclidestruct::Nuclide;
use crate::nuclidedata::decaymodes::*;
//use crate::atom::Atom;
use crate::nuclidedata::decay_chain::DECAY_CHAIN;
use crate::Particle;

// Given an u64 representation of the decay modes it returns the corresponding u64 for 
pub(crate) fn decayindex<T: DecayMode>(idx: usize, decay_rep: u64) -> Option<u64>{
      let modes = DECAY_CHAIN[idx].to_be_bytes();
      let d_mode = T::decay_index() as u8;
      
      if modes[0] == d_mode{
        return Some(DECAY_CHAIN[idx-5])
      }
      if modes[1] == d_mode{
         return Some(DECAY_CHAIN[idx-4])
      }
      if modes[2] == d_mode{
      return Some(DECAY_CHAIN[idx-3])
      }
      if modes[3] == d_mode{
      return Some(DECAY_CHAIN[idx-2])
      }
      if modes[4] == d_mode{
       return Some(DECAY_CHAIN[idx-1])
      }
      return None
}


pub(crate) mod private{
//use crate::Nuclide;
//use crate::Particle;
use crate::*;
use crate::nuclidedata::decaymodes::*;
pub trait InternalDecay {
   fn decay(x: &mut Nuclide) -> (f64,Vec<Particle>);
   // Decay_index return u32::MAX if not supported by system 254 for all decay modes
   fn decay_index() -> u32;
  // fn unchecked_decay_result(x: &Nuclide) -> Nuclide;
  // fn decay_result(x: &Nuclide) -> Option<Nuclide>;
}

impl<const K: usize> InternalDecay for ProtonEmission<K>{
   fn decay(x : &mut Nuclide) -> (f64,Vec<Particle>){
     proton_emission(x,K)
   }
   
   fn decay_index() -> u32{
     if K == 1{
      return 2
     }
     
     if K == 2{
      return 3
     }
     
     return u32::MAX
   }
   
   

}

impl<const K: usize> InternalDecay for NeutronEmission<K>{
   fn decay(x : &mut Nuclide) -> (f64,Vec<Particle>){
     neutron_emission(x,K)
   }
   
   fn decay_index() -> u32{
     if K == 1{
      return 4
     }
     if K == 2{
      return 5
     }
     return u32::MAX
   }
}

impl InternalDecay for NeutronDeuteron{
  fn decay(x : &mut Nuclide) -> (f64,Vec<Particle>){
     neutron_deuteron(x)
   }
    // FIXME
     fn decay_index() -> u32{
       return u32::MAX
     }
}

impl InternalDecay for NeutronTriton{
  fn decay(x : &mut Nuclide) -> (f64,Vec<Particle>){
     neutron_triton(x)
   }
   // FIXME
  fn decay_index() -> u32{
      return u32::MAX
  }
}

impl<const K: usize> InternalDecay for AlphaEmission<K>{
   fn decay(x : &mut Nuclide) -> (f64,Vec<Particle>){
     alpha_emission(x,K)
   }
   
  fn decay_index() -> u32{
    if K == 1{
      return 1
    }
    return u32::MAX  
  }
}

impl<const K: usize> InternalDecay for AlphaNeutron<K>{
   fn decay(x : &mut Nuclide) -> (f64,Vec<Particle>){
     alpha_neutron(x,K)
   }
   // FIXME
  fn decay_index() -> u32{
      return u32::MAX
  }   
}

impl<const K: usize> InternalDecay for ElectronCapture<K>{
   fn decay(x : &mut Nuclide) -> (f64,Vec<Particle>){
     electron_capture(x,K)
   }

  fn decay_index() -> u32{
      if K == 1{
       return 6
      }
      if K == 2{
       return 7
      }
      return u32::MAX
  }   
}

impl<const K: usize> InternalDecay for ElectronEmission<K>{
   fn decay(x : &mut Nuclide) -> (f64,Vec<Particle>){
     electron_emission(x,K)
   }
   
  fn decay_index() -> u32{
      if K == 1{
       return 11
      }
      if K == 2{
       return 12
      }
      return u32::MAX
  }
     
}

impl<const K: usize> InternalDecay for ElectronNeutron<K>{
   fn decay(x : &mut Nuclide) -> (f64,Vec<Particle>){
     electron_neutron(x,K)
   }

  fn decay_index() -> u32{
      if K == 1{
        return 13
      }
      if K == 2{
        return 14
      }
      if K == 3{
       return 15
      }
      return u32::MAX
  }
     
}

impl<const K: usize> InternalDecay for ElectronProton<K>{
   fn decay(x : &mut Nuclide) -> (f64,Vec<Particle>){
     electron_proton(x,K)
   }
   // FIXME
  fn decay_index() -> u32{
      return u32::MAX
  }
     
}

impl InternalDecay for ElectronAlpha{
  fn decay(x : &mut Nuclide) -> (f64,Vec<Particle>){
     electron_alpha(x)
   }
   
  fn decay_index() -> u32{
      return 19
  }   
}

impl InternalDecay for ElectronDeuteron{
  fn decay(x : &mut Nuclide) -> (f64,Vec<Particle>){
     electron_deuteron(x)
   }
   
  fn decay_index() -> u32{
      return 21
  }   
}

impl InternalDecay for ElectronTriton{
  fn decay(x : &mut Nuclide) -> (f64,Vec<Particle>){
     electron_triton(x)
   }
   
  fn decay_index() -> u32{
      return 22
  }   
}

impl InternalDecay for ElectronFission{
  fn decay(x : &mut Nuclide) -> (f64,Vec<Particle>){
     electron_fission(x)
   }
   
  fn decay_index() -> u32{
      return 24
  }   
}

impl<const K: usize> InternalDecay for PositronEmission<K>{
   fn decay(x : &mut Nuclide) -> (f64,Vec<Particle>){
     positron_emission(x,K)
   }
   
  fn decay_index() -> u32{
      if K == 1{
       return 9
      }
      if K == 2{
       return 10
      }
      return u32::MAX
  }   
}

impl<const K: usize> InternalDecay for PositronProton<K>{
   fn decay(x : &mut Nuclide) -> (f64,Vec<Particle>){
     positron_proton(x,K)
   }

  fn decay_index() -> u32{
      if K == 1{
        return 16
      }
      if K == 1{
        return 17
      }
      if K == 1{
        return 18
      }
      return u32::MAX
  }   
}

impl InternalDecay for PositronAlpha{
  fn decay(x : &mut Nuclide) -> (f64,Vec<Particle>){
     positron_alpha(x)
   }
   
  fn decay_index() -> u32{
      return 20
  }   
}

impl InternalDecay for PositronFission{
  fn decay(x : &mut Nuclide) -> (f64,Vec<Particle>){
     positron_fission(x)
   }
   
  fn decay_index() -> u32{
      return 25
  }   
}

impl InternalDecay for SpontaneousFission{
  fn decay(x : &mut Nuclide) -> (f64,Vec<Particle>){
     spontaneous_fission(x)
   }
   
  fn decay_index() -> u32{
      return 23
  }   
}

impl<const K: usize> InternalDecay for ClusterDecay<K>{
   fn decay(x : &mut Nuclide) -> (f64,Vec<Particle>){
     cluster_decay(x,&Nuclide::assign(K))
   }
   
  fn decay_index() -> u32{
      if K == 60{
        return 26
      }
      if K == 128{
       return 27
      }
      if K == 132{
       return 28
      }
      if K == 224{
       return 30
      }
      if K == 226{
       return 31
      }
      return u32::MAX
  }   
}

impl<const D: usize, const S: usize> InternalDecay for DoubleCluster<D,S>{
   fn decay(x : &mut Nuclide) -> (f64,Vec<Particle>){
     double_cluster(x,&Nuclide::assign(D), &Nuclide::assign(S))
   }
   
  fn decay_index() -> u32{
      if D == 132 && S == 134{
        return 29
      }
      if D == 134 && S == 132{
       return 29
      }
      return u32::MAX
  }   
} // end trait

} // end pub mod

pub trait DecayMode : private::InternalDecay{}

impl<const K: usize> DecayMode for ProtonEmission<K>{}
impl<const K: usize> DecayMode for NeutronEmission<K>{}
impl<const K: usize> DecayMode for AlphaEmission<K>{}
impl<const K: usize> DecayMode for AlphaNeutron<K>{}
impl DecayMode for NeutronDeuteron{}
impl DecayMode for NeutronTriton{}
impl<const K: usize> DecayMode for ElectronCapture<K>{}
impl<const K: usize> DecayMode for ElectronEmission<K>{}
impl<const K: usize> DecayMode for ElectronNeutron<K>{}
impl<const K: usize> DecayMode for ElectronProton<K>{}
impl DecayMode for ElectronAlpha{}
impl DecayMode for ElectronDeuteron{}
impl DecayMode for ElectronTriton{}
impl DecayMode for ElectronFission{}
impl<const K: usize> DecayMode for PositronEmission<K>{}
impl<const K: usize> DecayMode for PositronProton<K>{}
impl DecayMode for PositronAlpha{}
impl DecayMode for PositronFission{}
impl DecayMode for SpontaneousFission{}
impl<const K: usize> DecayMode for ClusterDecay<K>{}
impl<const D: usize, const S: usize> DecayMode for DoubleCluster<D,S>{}