nucleus_class.py
Go to the documentation of this file.
1
from
__future__
import
print_function
2
from
scipy.interpolate
import
interp1d
3
import
numpy
as
np
4
import
math
5
import
os
6
import
sys
7
import
inspect
8
9
class
nucleus(object):
10
"""
11
nucleus: contains basic information of a nuclei. For example the name, the name in the network, the amount of protons, neutrons and the mass number
12
"""
13
14
# constructor
15
def
__init__
(self,name='',Z=-1,N=-1,Y=0.,quiet=False,init_prop=False):
16
"""
17
Input:
18
name - name of the nuclei. All informations are extracted from this name.
19
"""
20
self.
__input_name
= name
21
self.
__name
= name.lower()
22
self.
__A
= -1
23
self.
__Z
= -1
24
self.
__N
= -1
25
self.
__warn
=
False
26
self.
__quiet
= quiet
27
self.
__ab
= Y
28
self.
__is_stable
=
False
29
#Sorting criteria
30
self.
__sort_Z
=
True
31
32
#Special cases
33
if
self.
__name
==
'p'
:
34
self.
__name
=
'h1'
35
if
self.
__name
==
'n'
or
self.
__name
==
'neutrons'
:
36
self.
__name
=
'neutron'
37
if
self.
__name
==
'd'
:
38
self.
__name
=
'h2'
39
if
self.
__name
==
't'
:
40
self.
__name
=
'h3'
41
if
self.
__name
==
'al-6'
:
42
self.
__name
=
'al26'
43
if
self.
__name
==
'al*6'
:
44
self.
__name
=
'al26'
45
46
self.
__elementname
=
''
47
self.
__elname
= (
'neutron'
,
'h'
,
'he'
,
'li'
,
'be'
,
'b'
,
'c'
,
'n'
,
'o'
,
'f'
,
'ne'
,
'na'
,
'mg'
,
'al'
,
'si'
,
'p'
,
's'
,
'cl'
,
'ar'
,
'k'
,
'ca'
,
'sc'
,
'ti'
,
'v'
,
'cr'
,
'mn'
,
'fe'
,
48
'co'
,
'ni'
,
'cu'
,
'zn'
,
'ga'
,
'ge'
,
'as'
,
'se'
,
'br'
,
'kr'
,
'rb'
,
'sr'
,
'y'
,
'zr'
,
'nb'
,
'mo'
,
'tc'
,
'ru'
,
'rh'
,
'pd'
,
'ag'
,
'cd'
,
'in'
,
'sn'
,
'sb'
,
49
'te'
,
'i'
,
'xe'
,
'cs'
,
'ba'
,
'la'
,
'ce'
,
'pr'
,
'nd'
,
'pm'
,
'sm'
,
'eu'
,
'gd'
,
'tb'
,
'dy'
,
'ho'
,
'er'
,
'tm'
,
'yb'
,
'lu'
,
'hf'
,
'ta'
,
'w'
,
're'
,
'os'
,
50
'ir'
,
'pt'
,
'au'
,
'hg'
,
'tl'
,
'pb'
,
'bi'
,
'po'
,
'at'
,
'rn'
,
'fr'
,
'ra'
,
'ac'
,
'th'
,
'pa'
,
'u'
,
'np'
,
'pu'
,
'am'
,
'cm'
,
'bk'
,
'cf'
,
'es'
,
'fm'
,
'md'
,
51
'no'
,
'lr'
,
'rf'
,
'db'
,
'sg'
,
'bh'
,
'hs'
,
'mt'
,
'ds'
,
'rg'
,
'cn'
,
'nh'
,
'fl'
,
'mc'
,
'lv'
,
'ts'
,
'og'
,
"uue"
,
"ubn"
,
"ubu"
,
"ubb"
,
"ubt"
,
"ubq"
,
"ubp"
,
52
"ubh"
,
"ubs"
,
"ubo"
,
"ube"
,
"utn"
,
"utu"
,
"utb"
,
"utt"
,
"utq"
,
"utp"
,
"uth"
,
"uts"
,
"uto"
,
"ute"
,
"uqn"
,
"uqu"
)
53
54
55
if
(Z!=-1
and
N!=-1):
56
if
((Z >= len(self.
__elname
))
and
not
self.
__quiet
):
57
print(
'Proton number exceeds the one of database '
,Z)
58
self.
__A
= Z + N
59
self.
__name
= self.
__elname
[Z] + str(self.
__A
)
60
61
self.
__initialize
()
62
63
if
init_prop:
64
self.
__init_properties
()
65
66
# Check if an error occured
67
self.
__not_a_isotope
= (self.
__Z
== -1)
68
69
70
71
def
__init_properties
(self):
72
"""
73
Initialize basic properties, like stableness etc.
74
"""
75
# Check if it is stable
76
stable_nuc = np.loadtxt(os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))+
'/data/stableiso.dat'
,unpack=
True
,usecols=[0],dtype=str)
77
if
self.
__name
in
stable_nuc:
78
self.
__is_stable
=
True
79
else
:
80
self.
__is_stable
=
False
81
82
83
84
def
is_stable
(self):
85
"""
86
Is it a stable nucleus?
87
"""
88
return
self.
__is_stable
89
90
91
def
get_not_a_isotope
(self):
92
"""
93
Check if the input was a valid isotope. True if not, False if it is valid
94
"""
95
return
self.
__not_a_isotope
96
97
def
__initialize
(self):
98
"""
99
Extract the information of protonnumber neutronnumber out of the name.
100
"""
101
self.
__A
=
''
.join(filter(
lambda
x: x.isdigit(),self.
__name
))
102
103
if
(self.
__A
!=
''
):
104
self.
__A
= int(self.
__A
)
105
else
:
106
self.
__A
= 1
107
108
self.
__elementname
=
''
.join(filter(
lambda
x:
not
x.isdigit(),self.
__name
)).strip()
109
110
if
self.
__elementname
in
self.
__elname
:
111
self.
__Z
= self.
__elname
.index(self.
__elementname
)
#protonnumber
112
if
self.
__elementname
.lower()==
"n"
and
self.
__A
==1:
113
self.
__Z
= 0
114
else
:
115
self.
__Z
= -1
116
if
not
self.
__quiet
:
117
print(
'Warning: The element '
+self.
__elementname
+
' is not known by nuclei class.'
)
118
self.
__warn
=
True
119
120
self.
__N
= self.
__A
- self.
__Z
121
self.
__nrnname
=
'i'
+self.
__name
122
123
self.
__N
= self.
__A
- self.
__Z
124
125
#~ Getters
126
def
get_A
(self):
127
"""
128
get_A : Get the mass number of the nucleus
129
"""
130
return
self.
__A
131
132
def
get_elnames
(self):
133
"""
134
get_elnames : Get elementnames
135
"""
136
return
self.
__elname
137
138
def
get_Z
(self):
139
"""
140
get_Z : Get the proton number of the nucleus
141
"""
142
return
self.
__Z
143
144
def
get_N
(self):
145
"""
146
get_N : Get the neutron number of the nucleus
147
"""
148
return
self.
__N
149
150
def
get_Y
(self):
151
"""
152
get_Y : Get the abundance of the nucleus
153
"""
154
return
self.
__ab
155
156
def
get_X
(self):
157
"""
158
get_X : Get the mass fraction of the nucleus
159
"""
160
return
self.
__ab
* self.
__A
161
162
def
get_elementname
(self):
163
"""
164
get_elementname : Get the corresponding name of the element (as a string)
165
"""
166
return
self.
__elementname
167
168
def
get_name
(self):
169
"""
170
get_name : Get the full name of the nucleus. The name is the elementname plus the massnumber as a string
171
"""
172
if
self.
__name
==
"neutron1"
:
173
outp=
"n"
174
elif
self.
__name
==
"h1"
:
175
outp=
'p'
176
elif
self.
__name
==
"h2"
:
177
outp=
'd'
178
elif
self.
__name
==
"h3"
:
179
outp=
't'
180
else
:
181
outp=self.
__name
182
return
outp
183
184
def
get_input_name
(self):
185
"""
186
get_input_name : Get the name as it was inputted
187
"""
188
return
self.
__input_name
189
190
191
192
193
def
get_seedline
(self):
194
"""
195
get_seedline : Get the line for the nucleus as it is necessary for the seed file
196
"""
197
mafra =
'%1.6e'
% float(self.
get_X
())
198
nam = self.
get_name
()
199
if
nam.strip() ==
'neutron'
:
200
nam =
'n'
201
elif
nam.strip() ==
'h1'
:
202
nam =
'p'
203
elif
nam.strip() ==
'h2'
:
204
nam =
'd'
205
elif
nam.strip() ==
'h3'
:
206
nam =
't'
207
208
line = nam.rjust(5) +
' '
*7 + mafra
209
return
line
210
211
def
set_X
(self,X):
212
"""
213
set_X : set the massfraction of the nucleus
214
"""
215
self.
__ab
= X / self.
__A
216
217
def
set_Y
(self,Y):
218
"""
219
set_X : set the massfraction of the nucleus
220
"""
221
self.
__ab
= Y
222
223
def
set_sortcriteria
(self,criteria):
224
"""
225
set_sortcriteria : Set the criteria for sorting (possible values are "A" and "Z")
226
"""
227
if
criteria ==
'Z'
:
228
self.
__sort_Z
=
True
229
if
criteria ==
'A'
:
230
self.
__sort_Z
=
False
231
232
def
__gt__
(self,other):
233
"""
234
A nucleus is greater if it has an higher proton number
235
"""
236
if
self.
__sort_Z
==
True
:
#Sort Z
237
if
(self.
__Z
> other.get_Z()):
238
return
True
239
elif
(self.
__Z
== other.get_Z()):
240
if
(self.
__A
>= other.get_A()):
241
return
True
242
else
:
243
return
False
244
else
:
245
return
False
246
else
:
#Sort A
247
if
(self.
__A
> other.get_A()):
248
return
True
249
elif
(self.
__A
== other.get_A()):
250
if
(self.
__Z
>= other.get_Z()):
251
return
True
252
else
:
253
return
False
254
else
:
255
return
False
src_files.nucleus_class.nucleus.__not_a_isotope
__not_a_isotope
Definition:
nucleus_class.py:67
src_files.nucleus_class.nucleus.get_name
def get_name(self)
Definition:
nucleus_class.py:168
src_files.nucleus_class.nucleus.__init__
def __init__(self, name='', Z=-1, N=-1, Y=0., quiet=False, init_prop=False)
Definition:
nucleus_class.py:15
src_files.nucleus_class.nucleus.set_sortcriteria
def set_sortcriteria(self, criteria)
Definition:
nucleus_class.py:219
src_files.nucleus_class.nucleus.__quiet
__quiet
Definition:
nucleus_class.py:26
src_files.nucleus_class.nucleus.__init_properties
def __init_properties(self)
Definition:
nucleus_class.py:71
src_files.nucleus_class.nucleus.is_stable
def is_stable(self)
Definition:
nucleus_class.py:84
src_files.nucleus_class.nucleus.__elname
__elname
Definition:
nucleus_class.py:47
src_files.nucleus_class.nucleus.get_Z
def get_Z(self)
Definition:
nucleus_class.py:138
src_files.nucleus_class.nucleus.__initialize
def __initialize(self)
Definition:
nucleus_class.py:97
src_files.nucleus_class.nucleus.__sort_Z
__sort_Z
Definition:
nucleus_class.py:30
src_files.nucleus_class.nucleus.__elementname
__elementname
Definition:
nucleus_class.py:46
src_files.nucleus_class.nucleus.get_elnames
def get_elnames(self)
Definition:
nucleus_class.py:132
src_files.nucleus_class.nucleus.get_A
def get_A(self)
Definition:
nucleus_class.py:126
src_files.nucleus_class.nucleus.__nrnname
__nrnname
Definition:
nucleus_class.py:121
src_files.nucleus_class.nucleus.get_input_name
def get_input_name(self)
Definition:
nucleus_class.py:180
src_files.nucleus_class.nucleus.__gt__
def __gt__(self, other)
Definition:
nucleus_class.py:228
src_files.nucleus_class.nucleus.__name
__name
Definition:
nucleus_class.py:21
src_files.nucleus_class.nucleus.get_elementname
def get_elementname(self)
Definition:
nucleus_class.py:162
src_files.nucleus_class.nucleus.__Z
__Z
Definition:
nucleus_class.py:23
src_files.nucleus_class.nucleus.set_X
def set_X(self, X)
Definition:
nucleus_class.py:207
src_files.nucleus_class.nucleus.get_not_a_isotope
def get_not_a_isotope(self)
Definition:
nucleus_class.py:91
src_files.nucleus_class.nucleus.get_X
def get_X(self)
Definition:
nucleus_class.py:156
src_files.nucleus_class.nucleus.__ab
__ab
Definition:
nucleus_class.py:27
src_files.nucleus_class.nucleus.__warn
__warn
Definition:
nucleus_class.py:25
src_files.nucleus_class.nucleus.__is_stable
__is_stable
Definition:
nucleus_class.py:28
src_files.nucleus_class.nucleus.__input_name
__input_name
Definition:
nucleus_class.py:20
src_files.nucleus_class.nucleus.set_Y
def set_Y(self, Y)
Definition:
nucleus_class.py:213
src_files.nucleus_class.nucleus.__A
__A
Definition:
nucleus_class.py:22
src_files.nucleus_class.nucleus.get_seedline
def get_seedline(self)
Definition:
nucleus_class.py:189
src_files.nucleus_class.nucleus.get_Y
def get_Y(self)
Definition:
nucleus_class.py:150
src_files.nucleus_class.nucleus.get_N
def get_N(self)
Definition:
nucleus_class.py:144
src_files.nucleus_class.nucleus.__N
__N
Definition:
nucleus_class.py:24
bin
summary_script
src_files
nucleus_class.py