/search.css" rel="stylesheet" type="text/css"/> /search.js">
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

g4data.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 from data import units
00004 import elements
00005 
00006 class G4RadData(object):
00007     
00008     # Cache all loaded states, map from (z,a) tuple
00009     states = {}
00010 
00011     def nuclideData(self,z,a):
00012         '''Return given nuclide data'''
00013         try:
00014             return G4RadData.states[(z,a)]
00015         except KeyError:
00016             pass
00017         try:
00018             nuc = NuclideData(z,a)
00019         except IOError,err:
00020             err = 'Illegal Z=%d, A=%d\n%s'%(z,a,err)
00021             raise ValueError,err
00022         G4RadData.states[(z,a)] = nuc
00023         return nuc
00024 
00025 class NuclideDecay:
00026     'Holds decay type, fraction qvalue and daughter excitation energy'
00027     def __init__(self,type,fraction,qvalue,daughterExcitation=0,daughterZ=0,daughterA=0,rad = None):
00028         self.type = type
00029         self.fraction = fraction
00030         self.qvalue = qvalue
00031         self.daughterExcitation = daughterExcitation
00032         self.radiation = rad
00033         self.daughterZ = daughterZ
00034         self.daughterA = daughterA
00035         return
00036 
00037     def __str__(self):
00038         return '\t\t%s %6.3f%% Q=%8.4f [%8.4f] (%s)'%(self.type,self.fraction*100,self.qvalue,self.daughterExcitation,self.radiation)
00039     pass
00040 
00041 class NuclideState:
00042     'Holds nuclide halflife, excitation energy and collection of NuclideDecay'
00043     def __init__(self,name,halflife=None):
00044         self.name = name
00045         self.halflife = halflife
00046         self.excitation = 0.0
00047         self.decays = []
00048         return
00049 
00050     def __str__(self):
00051         ret = ['\tstate %s (%s) [%.2f] %d decays:'%(self.name,self.halflife,self.excitation,len(self.decays))]
00052         for dk in self.decays:
00053             ret.append(str(dk))
00054             continue
00055         return '\n'.join(ret)
00056     pass
00057 
00058 
00059 class NuclideData(object):
00060     'Hold all decay data about a nuclide from G4RadioActivity data files'
00061     
00062     def __init__(self,z,a):
00063         '''Create data for given Z and A'''
00064         self.Z = z
00065         self.A = a
00066         self.states = []
00067         self.name = '%d%s'%(self.A,elements.symbol(self.Z))
00068         self.load()
00069         return
00070 
00071     def __str__(self):
00072         ret = ['z%d.a%d %s %d excited state(s):'%(self.Z,self.A,self.name,len(self.states))]
00073         for s in self.states:
00074             ret.append(str(s))
00075             continue
00076         return '\n'.join(ret)
00077 
00078     def excitedState(self,nucexenergy = 0.0):
00079         '''Return state with given excitation energy'''
00080         for s in self.states:
00081             if nucexenergy == s.excitation: return s
00082             continue
00083         return None
00084 
00085     def load(self):
00086         import os
00087         dir = os.getenv('G4RADIOACTIVEDATA')
00088         if dir is None:
00089             raise EnvironmentError,'No G4RADIOACTIVEDATA variable, can not find data for Z=%d, A=%d'%(self.Z,self.A)
00090         file = dir + '/z%d.a%d'%(self.Z,self.A)
00091         file = open(file)
00092         types_seen = {}
00093         for line in file.readlines():
00094             line = line.strip()
00095             #print line
00096 
00097             # skip comments
00098             if line[0] == '#': continue
00099 
00100             # parent
00101             if line[0] == 'P':
00102                 self.states.append(NuclideState(self.name))
00103                 types_seen = {}
00104                 p,ex,hl = line.split()
00105                 self.states[-1].excitation = float(ex)
00106                 self.states[-1].halflife = float(hl)*units.second
00107                 continue
00108 
00109             # warning
00110             if line[0] == 'W':
00111                 #print line
00112                 continue
00113                 
00114             # now parsing data
00115             chunks = line.split()
00116 
00117             # skip first total BR for type
00118             if not types_seen.has_key(chunks[0]):
00119                 types_seen[chunks[0]] = float(chunks[2])
00120                 continue
00121 
00122             dk = NuclideDecay(chunks[0],float(chunks[2])/100.0,
00123                               float(chunks[3])*units.keV,float(chunks[1])*units.keV)
00124             import decay
00125             if dk.type == 'Alpha':
00126                 dk.daughterZ = self.Z - 2
00127                 dk.daughterA = self.A - 4
00128                 dk.radiation = decay.AlphaDecay(dk.qvalue,self.Z)
00129             elif dk.type == 'BetaMinus':
00130                 dk.daughterZ = self.Z + 1
00131                 dk.daughterA = self.A
00132                 dk.radiation = decay.BetaDecay(dk.qvalue,self.Z)
00133             elif dk.type == 'BetaPlus':
00134                 dk.daughterZ = self.Z - 1
00135                 dk.daughterA = self.A
00136                 dk.radiation = decay.BetaDecay(dk.qvalue,-1*self.Z)
00137             else:
00138                 print 'Warning - not yet supported decay type: %s'%dk.type
00139                 continue
00140 
00141             self.states[-1].decays.append(dk)
00142             continue
00143         return
00144 
00145     pass
00146 
00147 if '__main__' == __name__:
00148     import sys
00149     nd = NuclideData(int(sys.argv[1]),int(sys.argv[2]))
00150     print nd
00151 
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Fri May 16 2014 10:21:06 for GenDecay by doxygen 1.7.4