-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathparseNNDC2.py
1681 lines (1267 loc) · 52.4 KB
/
parseNNDC2.py
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
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/python3.4
#note python3 only
import readline
import xml.dom.minidom
from xml.dom.minidom import parse, parseString
import urllib.request
import subprocess
import highlighter
import re
import os
import sys
import pdb
from NNDC_Parser import NNDCParser
class Run():
'''
an interface for NNDCParser.
'''
def __init__( self, inFile=""):
# upper energy limit.
self.lvlE_limitU = 3000 # -1 = no limit
self.__A_min = 1
self.__A_max = -1 # -1 = no limit
self.__A_flag = 0 # 0 = none, 1 = odd, 2 = even
self.__Z_min = 1
self.__Z_max = -1 # -1 = no limit
self.__Z_flag = 0 # 0 = none, 1 = odd, 2 = even
self.__N_min = 0
self.__N_max = -1 # -1 = no limit
self.__N_flag = 0 # 0 = none, 1 = odd, 2 = even
self.__As = [] # manual selected A
self.__Zs = [] # manual selected Z
self.__Ns = [] # manual selected N
self.use_lvl_builder = True
self.show_gam = True
self.__valid_syms = [] # updated at __load_mass16_table
self.__nuclei_syms = []
# to use mass16.xml as our symbol table.
# self.__nuclei_table has a structure of [ (), (), (), ]
# each elment is ( sym, A, Z, N )
self.__nuclei_table = self.__load_mass16_table()
self.nuclei_list = self.__nuclei_table[:]
# reaction energy table, for Sn, Sp ...
# each element is a dic, key = sym, Sn, Sp, S2n, S2p, Qa
self.__rec_eng_table = self.__load_mass16_Sn_table()
self.__useRange = True
self.parser = NNDCParser()
while( 1 ):
self.__process()
def __load_mass16_table( self ):
'''
we load mass16.xml as our symbol table.
'''
try:
f = open("mass16.xml","r")
f.close()
except:
print( "Error: cannot open mass16.xml ")
print( "Please check the file.")
sys.exit(0)
doc = parse( open("mass16.xml") )
nuclei_table = doc.getElementsByTagName("nuclei")
nuclei_table_new = []
for nuclei in nuclei_table:
sym = nuclei.getAttribute('sym')
A = nuclei.getAttribute('A')
Z = nuclei.getAttribute('Z')
A = int(A)
Z = int(Z)
N = A-Z
nuclei_table_new.append( (sym, A, Z, N) )
self.__valid_syms.append( sym )
return nuclei_table_new
def __load_mass16_Sn_table( self ):
'''
we load mass16_Sn.xml as our reaction energy table.
'''
try:
f = open("mass16_Sn.xml","r")
f.close()
except:
print( "Error: cannot open mass16_Sn.xml ")
print( "Please check the file.")
sys.exit(0)
doc = parse( open("mass16_Sn.xml") )
eng_table = doc.getElementsByTagName("nuclei")
eng_table_new = []
for nuclei in eng_table:
sym = nuclei.getAttribute('sym')
Sn = nuclei.getAttribute('Sn')
Sp = nuclei.getAttribute('Sp')
S2n = nuclei.getAttribute('S2n')
S2p = nuclei.getAttribute('S2p')
Qa = nuclei.getAttribute('Qa')
try:
# print ( "debug", Sn,"." )
Sn = float(Sn)
except:
Sn = "None"
try:
Sp = float(Sp)
except:
Sp = "None"
try:
S2n = float(S2n)
except:
S2n = "None"
try:
S2p = float(S2p)
except:
S2p = "None"
try:
Qa = float(Qa)
Sa = -Qa
except:
Sa = "None"
tmp_dic = { 'sym': sym,\
'Sn' : Sn , 'Sp' : Sp,\
'S2n': S2n, 'S2p': S2p,\
'Sa' : Sa }
eng_table_new.append( tmp_dic )
return eng_table_new
def __get_eng_limits( self, sym_input, \
lowE_type, lowE_shift, uppE_type, uppE_shift ):
'''
lowE_type and uppE_type are keys.
when we can found key 'Sn', 'Sp' ... in a nuclei
then we return good_status = True.
note: some nuclei don't have Sn value from table.
'''
good_status = True
if( lowE_type == "gs" ): E1 = 0.
if( uppE_type == "gs" ): E2 = 0.
for tmp_dic in self.__rec_eng_table:
sym = tmp_dic['sym']
if( sym == sym_input ):
if( lowE_type in tmp_dic ):
E1 = tmp_dic[lowE_type]
if( E1 == "None" ): good_status = False
if( uppE_type in tmp_dic ):
E2 = tmp_dic[uppE_type]
if( E2 == "None" ): good_status = False
if( good_status ):
E1 += lowE_shift
E2 += uppE_shift
else:
E1 = E2= 0
return E1, E2, good_status
pass
def __print_selected_nuclei( self ):
'''
(1) print out the selected nuclei_list
(2) update self.nuclei_list
'''
nuclei_list = []
# -----------manual selection -----------
# if when using manual selection, the range selection
# will be skip.
if len( self.__As ) > 0 :
for nuclei in self.__nuclei_table:
A = nuclei[1]
if A in self.__As:
nuclei_list.append( nuclei )
else:
nuclei_list = self.__nuclei_table[:]
# print( "debug 1, len = ", len(nuclei_list) )
tmp_list = []
if len( self.__Zs ) > 0 :
for nuclei in nuclei_list:
Z = nuclei[2]
if Z in self.__Zs:
tmp_list.append( nuclei )
nuclei_list = tmp_list[:]
# print( "debug 2, len = ", len(nuclei_list) )
tmp_list = []
if len( self.__Ns ) > 0 :
for nuclei in nuclei_list:
N = nuclei[3]
if N in self.__Ns:
tmp_list.append( nuclei )
nuclei_list = tmp_list[:]
# print( "debug 3, len = ", len(nuclei_list) )
# -----------range selection -----------
# do A selection
tmp_list = []
if( self.__A_max == -1 ):
# no limit, so we add in all nuclei.
for nuclei in nuclei_list:
tmp_list.append( nuclei )
elif( self.__A_max >= 1 ):
for nuclei in nuclei_list:
A = nuclei[1]
if( A >= self.__A_min and A <= self.__A_max ):
tmp_list.append( nuclei )
nuclei_list = tmp_list[:]
# deal with odd/even A
tmp_list = []
for nuclei in nuclei_list:
A = nuclei[1]
Odd_A = False
Even_A = False
if( A % 2 == 1 ): Odd_A = True
if( A % 2 == 0 ): Even_A = True
if( self.__A_flag == 1 and Odd_A ):
tmp_list.append( nuclei )
elif( self.__A_flag == 2 and Even_A ):
tmp_list.append( nuclei )
elif( self.__A_flag == 0 ):
tmp_list.append( nuclei )
nuclei_list = tmp_list[:]
# do Z selection
tmp_list = []
if( self.__Z_max == -1 ):
# no limit, so we add in all nuclei.
for nuclei in nuclei_list:
tmp_list.append( nuclei )
elif( self.__Z_max >= 1 ):
for nuclei in nuclei_list:
Z = nuclei[2]
if( Z >= self.__Z_min and Z <= self.__Z_max ):
tmp_list.append( nuclei )
nuclei_list = tmp_list[:]
# deal with odd/even Z
tmp_list = []
for nuclei in nuclei_list:
Z = nuclei[2]
Odd_Z = False
Even_Z = False
if( Z % 2 == 1 ): Odd_Z = True
if( Z % 2 == 0 ): Even_Z = True
if( self.__Z_flag == 1 and Odd_Z ):
tmp_list.append( nuclei )
elif( self.__Z_flag == 2 and Even_Z ):
tmp_list.append( nuclei )
elif( self.__Z_flag == 0 ):
tmp_list.append( nuclei )
nuclei_list = tmp_list[:]
# do N selection
tmp_list = []
if( self.__N_max == -1 ):
# no limit, so we add in all nuclei.
for nuclei in nuclei_list:
tmp_list.append( nuclei )
elif( self.__N_max >= 1 ):
for nuclei in nuclei_list:
N = nuclei[3]
if( N >= self.__N_min and N <= self.__N_max ):
tmp_list.append( nuclei )
nuclei_list = tmp_list[:]
# deal with odd/even Z
tmp_list = []
for nuclei in nuclei_list:
N = nuclei[3]
Odd_N = False
Even_N = False
if( N % 2 == 1 ): Odd_N = True
if( N % 2 == 0 ): Even_N = True
if( self.__N_flag == 1 and Odd_N ):
tmp_list.append( nuclei )
elif( self.__N_flag == 2 and Even_N ):
tmp_list.append( nuclei )
elif( self.__N_flag == 0 ):
tmp_list.append( nuclei )
nuclei_list = tmp_list[:]
# update
self.nuclei_list = nuclei_list[:]
# output sting
outStr = "\n %4d nuclei are selected:\n "\
%len( nuclei_list)
if len( nuclei_list) > 10:
# over than 10 items
# first 5
for nuclei in nuclei_list[:5]:
sym = nuclei[0]
outStr += "%5s " %sym
outStr += "...\n "
# last 5
tmp_list = []
for i in range(5):
idx = -1*i - 1
nuclei = nuclei_list[ idx ]
sym = nuclei[0]
tmp_list.append( sym)
for x in reversed( tmp_list):
outStr += "%5s " %x
else:
# less or equal to 10 items.
itemp = 0
for nuclei in nuclei_list[:10]:
sym = nuclei[0]
outStr += "%5s " %sym
itemp += 1
if itemp == 5: outStr += "\n "
#=========================================
# for manual input
if( not self.__useRange ):
outStr2 = "\n %4d nuclei are selected:\n "\
%len(self.__nuclei_syms)
if len(self.__nuclei_syms) > 10:
#first 5
for sym in self.__nuclei_syms:
outStr2 += "%5s " %sym
outStr2 += "...\n "
#last 5
for i in range(5):
idx = -1*i - 1
sym = self.__nuclei_syms[idx]
outStr2 += "%5s " %sym
else:
# less or equal to 10 items.
itemp = 0
for sym in self.__nuclei_syms[:10]:
outStr2 += "%5s " %sym
itemp += 1
if itemp == 5: outStr2 += "\n "
return outStr2
return outStr
pass
def __set_A_flag( self ):
opt = input( "Set A to (0) none, (1) odd, (2) even :" )
opt = opt.rstrip()
opt = opt.lstrip()
if opt == "0" :
self.__A_flag = 0
elif opt == "1" :
self.__A_flag = 1
elif opt == "2" :
self.__A_flag = 2
else:
self.__A_flag = 0
def __set_Z_flag( self ):
opt = input( "Set Z to (0) none, (1) odd, (2) even :" )
opt = opt.rstrip()
opt = opt.lstrip()
if opt == "0" :
self.__Z_flag = 0
elif opt == "1" :
self.__Z_flag = 1
elif opt == "2" :
self.__Z_flag = 2
else:
self.__Z_flag = 0
def __set_N_flag( self ):
opt = input( "Set N to (0) none, (1) odd, (2) even :" )
opt = opt.rstrip()
opt = opt.lstrip()
if opt == "0" :
self.__N_flag = 0
elif opt == "1" :
self.__N_flag = 1
elif opt == "2" :
self.__N_flag = 2
else:
self.__N_flag = 0
def __set_As( self ):
As = input( "input numbers (separate by spaces): ")
As = As.split()
for item in As:
item = int( item )
self.__As.append( item )
# force to skip range selection.
if( len( self.__As ) > 0 ):
self.__A_max = -1 # -1 = no limit
pass
def __set_Zs( self ):
Zs = input( "input numbers (separate by spaces): ")
Zs = Zs.split()
for item in Zs:
item = int( item )
self.__Zs.append( item )
# force to skip range selection.
if( len( self.__Zs ) > 0 ):
self.__Z_max = -1 # -1 = no limit
pass
def __set_Ns( self ):
Ns = input( "input numbers (separate by spaces): ")
Ns = Ns.split()
for item in Ns:
item = int( item )
self.__Ns.append( item )
# force to skip range selection.
if( len( self.__Ns ) > 0 ):
self.__N_max = -1 # -1 = no limit
pass
def __set_A_selection( self ):
while( 1 ):
os.system('clear');
print( " ->SELECTION SUMMARY->A SELECTION SUBMENU")
print( self.__print_status() )
print( self.__print_selected_nuclei() )
print(" --------------------------------\n")
print( " (a) add one or more" )
print( " (s) set odd/even " )
print( " (R) Reset A selections")
print( " (X) Done")
print( " Or input two num for A1 and A2 range (separate by spaces) ")
opt = input( "\nYour choice: " )
if opt.lower() == "x": break
elif opt.lower() == "a": self.__set_As()
elif opt.lower() == "s": self.__set_A_flag()
elif opt.lower() == "r" :
self.__A_min = 1
self.__A_max = -1 # -1 = no limit
self.__A_flag = 0 # 0 = none, 1 = odd, 2 = even
self.__As = []
opt = opt.split()
if len(opt) == 2:
As = [ int(opt[0]), int(opt[1]) ]
self.__A_min = min( As )
self.__A_max = max( As )
if self.__A_min < 1 : self.__A_min = 1
def __set_Z_selection( self ):
while( 1 ):
os.system('clear');
print( " ->SELECTION SUMMARY->Z SELECTION SUBMENU")
print( self.__print_status() )
print( self.__print_selected_nuclei() )
print(" --------------------------------\n")
print( " (a) add one or more" )
print( " (s) set odd/even " )
print( " (R) Reset Z selections")
print( " (X) Done")
print( " Or input two num for Z1 and Z2 range (separate by spaces) ")
opt = input( "\nYour choice: " )
if opt.lower() == "x": break
elif opt.lower() == "a": self.__set_Zs()
elif opt.lower() == "s": self.__set_Z_flag()
elif opt.lower() == "r" :
self.__Z_min = 1
self.__Z_max = -1 # -1 = no limit
self.__Z_flag = 0 # 0 = none, 1 = odd, 2 = even
self.__Zs = []
opt = opt.split()
if len(opt) == 2:
Zs = [ int(opt[0]), int(opt[1]) ]
self.__Z_min = min( Zs )
self.__Z_max = max( Zs )
if self.__Z_min < 1 : self.__Z_min = 1
def __set_N_selection( self ):
while( 1 ):
os.system('clear');
print( " ->SELECTION SUMMARY->N SELECTION SUBMENU")
print( self.__print_status() )
print( self.__print_selected_nuclei() )
print(" --------------------------------\n")
print( " (a) add one or more" )
print( " (s) set odd/even " )
print( " (R) Reset N selections")
print( " (X) Done")
print( " Or input two num for N1 and N2 range (separate by spaces) ")
opt = input( "\nYour choice: " )
if opt.lower() == "x": break
elif opt.lower() == "a": self.__set_Ns()
elif opt.lower() == "s": self.__set_N_flag()
elif opt.lower() == "r" :
self.__N_min = 1
self.__N_max = -1 # -1 = no limit
self.__N_flag = 0 # 0 = none, 1 = odd, 2 = even
self.__Ns = []
opt = opt.split()
if len(opt) == 2:
Ns = [ int(opt[0]), int(opt[1]) ]
self.__N_min = min( Ns )
self.__N_max = max( Ns )
if self.__N_min < 1 : self.__N_min = 1
def __reset_nuclei_selection( self ):
self.__A_min = 1
self.__A_max = -1
self.__A_flag = 0
self.__Z_min = 1
self.__Z_max = -1
self.__Z_flag = 0
self.__N_min = 0
self.__N_max = -1
self.__N_flag = 0
self.__nuclei_syms = []
pass
def __print_A_status( self ):
# range selection part
if self.__A_max < 1:
sA_selection = "None"
if self.__A_max >= 1:
sA_selection = "%3d:%3d" %(self.__A_min, self.__A_max)
if self.__A_flag == 1: sA_selection += " odd A"
if self.__A_flag == 2: sA_selection += " even A"
sA_selection = " A1 <= A <= A2 [current %s]"%(sA_selection)
# manual selection part
if len(self.__As) > 0:
sA_selection = " A = ["
for item in self.__As:
sA_selection += "%2d, " %item
# remove the last ", "
sA_selection = sA_selection[:-2]
sA_selection += " ]"
return sA_selection
def __print_Z_status( self ):
# range selection part
if self.__Z_max < 1:
sZ_selection = "None"
if self.__Z_max >= 1:
sZ_selection = "%3d:%3d" %(self.__Z_min, self.__Z_max)
if self.__Z_flag == 1: sZ_selection += " odd Z"
if self.__Z_flag == 2: sZ_selection += " even Z"
sZ_selection = " Z1 <= Z <= Z2 [current %s]"%(sZ_selection)
# manual selection part
if len(self.__Zs) > 0:
sZ_selection = " Z = ["
for item in self.__Zs:
sZ_selection += "%2d, " %item
# remove the last ", "
sZ_selection = sZ_selection[:-2]
sZ_selection += " ]"
return sZ_selection
def __print_N_status( self ):
# range selection part
if self.__N_max < 1:
sN_selection = "None"
if self.__N_max >= 1:
sN_selection = "%3d:%3d" %(self.__N_min, self.__N_max)
if self.__N_flag == 1: sN_selection += " odd N"
if self.__N_flag == 2: sN_selection += " even N"
sN_selection = " N1 <= N <= N2 [current %s]"%(sN_selection)
# manual selection part
if len(self.__Ns) > 0:
sN_selection = " N = ["
for item in self.__Ns:
sN_selection += "%2d, " %item
# remove the last ", "
sN_selection = sN_selection[:-2]
sN_selection += " ]"
return sN_selection
def __print_status( self ):
strOut = ""
strOut += self.__print_A_status() + "\n"
strOut += self.__print_Z_status() + "\n"
strOut += self.__print_N_status()
return strOut
def __print_select_nuclei_menu( self ):
strOut = " ->SELECTION SUMMARY\n"
strOut += self.__print_status() + "\n"
strOut += self.__print_selected_nuclei() + "\n"
strOut += " --------------------------------\n\n"
strOut += " (1) select A or set (A1,A2) range\n"
strOut += " (2) select Z or set (Z1,Z2) range\n"
strOut += " (3) select N or set (N1,N2) range\n"
strOut += " \n"
strOut += " (4) select nuclei symbols \n"
strOut += " --------------------------------\n"
strOut += " (R) Reset selections \n"
strOut += " (X) Done \n"
print( strOut )
opt = input("Your choice: ")
return opt
pass
def __set_sym_selection( self ):
print( "Input symbols ex. 4He 7Li (separate by spaces), and 0 for reset. ")
# print( "Only valid symbols will be added.")
opt = input( "Your choice: " )
if opt == "0":
self.__nuclei_syms = []
else:
syms = opt.split()
for sym in syms:
if sym in self.__valid_syms:
self.__nuclei_syms.append( sym )
pass
def __select_nuclei( self ):
while( 1 ):
os.system('clear');
opt = self.__print_select_nuclei_menu()
if opt == "1" :
self.__useRange = True
self.__nuclei_syms = [] # reset
self.__set_A_selection()
elif opt == "2" :
self.__useRange = True
self.__nuclei_syms = [] # reset
self.__set_Z_selection()
elif opt == "3" :
self.__useRange = True
self.__nuclei_syms = [] # reset
self.__set_N_selection()
elif opt == "4":
# disable selection by range.
# we do manual input.
self.__useRange = False
# we set the range selection
self.__A_min = 1
self.__A_max = -1
self.__A_flag = 0
self.__Z_min = 1
self.__Z_max = -1
self.__Z_flag = 0
self.__N_min = 0
self.__N_max = -1
self.__N_flag = 0
self.__set_sym_selection()
elif opt.lower() == 'r' :
# to reset ALL
self.__reset_nuclei_selection()
elif opt.lower() == 'x' :
break
pass
def __set_upper_energy_limit( self ):
limit = input( "input the upper energy limits in keV (0=none): " )
try:
fLimit = float( limit )
self.lvlE_limitU = fLimit
except:
self.lvlE_limitU = -1
if limit == "0" : self.lvlE_limitU = -1
pass
def __set_use_lvl_builder( self ):
opt = input( "to use lvl_builder? (y/N): " )
if opt.lower() == "n" or len(opt)==0: self.use_lvl_builder = False
elif opt.lower() == 'y': self.use_lvl_builder = True
else: self.use_lvl_builder = False
def __set_show_gam( self ):
opt = input( "to show gammas? (y/N): " )
if opt.lower() == "n" or len(opt)==0: self.show_gam = False
elif opt.lower() == 'y': self.show_gam = True
else: self.show_gam = False
def __process( self ):
'''
it will be use in the while loop at the __init__, served as
the main function to interact with a user.
'''
opt = self.__print_main_menu()
# opt = "a1"
# self.__nuclei_syms = ["31Si", ]
if( opt.lower() == "1" ):
self.__select_nuclei()
elif( opt.lower() == "2" ):
self.__set_upper_energy_limit()
elif( opt.lower() == "3" ):
self.__set_use_lvl_builder()
elif( opt.lower() == "4" ):
self.__set_show_gam()
elif( opt.lower() == "a1" ):
os.system('clear')
self.__run_plot_lvl_schemes()
elif( opt.lower() == "a2" ):
os.system('clear')
self.__run_find_reference()
elif( opt.lower() == "a3" ):
os.system('clear')
self.__run_plot_lvl_schemes_with_JPIs()
elif( opt.lower() == "a4" ):
os.system('clear')
self.__run_plot_lvl_schemes_with_stateN()
elif( opt.lower() == "a5" ):
os.system('clear')
self.__run_plot_lvl_schemes_with_rec_eng()
elif( opt.lower() == "r" ):
self.__reset_to_default()
elif( opt.lower() == "xx" ):
sys.exit(1)
def __print_main_menu( self ):
'''
print the main menu and then return the option.
'''
os.system('clear');
sNucleiList=""
if( self.__useRange ):
# selection by range
if len(self.nuclei_list)== 0 :
sNucleiList = "None"
else:
sNucleiList = "%2d nuclei" %len(self.nuclei_list)
else:
if len(self.__nuclei_syms)== 0 :
sNucleiList = "None"
elif len(self.__nuclei_syms) > 5 :
# over 5 terms
for sym in self.__nuclei_syms[:5] :
sNucleiList += "%s " %sym
sNucleiList += "..."
else:
for sym in self.__nuclei_syms :
sNucleiList += "%s " %sym
# energy upper limit.
if self.lvlE_limitU == -1:
sLvlE_limitU = "None"
elif self.lvlE_limitU > 0:
sLvlE_limitU = "%.f" %float( self.lvlE_limitU )
# use lvl_builder
if self.use_lvl_builder:
sUseLvlBuilder = "True"
else:
sUseLvlBuilder = "False"
# show gam
if self.show_gam:
sShow_gam = "True"
else:
sShow_gam = "False"
strOut = "\n ~Welcome to NNDC parser~ \n"
strOut += "\n (1) Select nuclei [current: %s]\n" %sNucleiList
strOut+=" (2) upper engergy limit [current: %5s] (keV)\n"%(sLvlE_limitU)
strOut+=" (3) to use lvl_builder [current: %5s]\n" %(sUseLvlBuilder)
strOut+=" (4) to show gammas [current: %5s]" %(sShow_gam)
strOut+="""
-----------------------------------------------------------
(a1) plot level schemes
(a2) plot level schemes with ref selections.
(a3) plot level schemes with JPi selections
(a4) plot level schemes with # of states limt
(a5) plot level schemes with Sn, Sp...limts
-----------------------------------------------------------
(R) Reset to default
(XX) Exit
Your choice: """
opt = input( strOut )
return opt.lower()
def __reset_to_default( self ):
'''
reset ALL setting.
'''
self.lvlE_limitU = 3000 # -1 = no limit
self.__A_min = 1
self.__A_max = -1 # -1 = no limit
self.__A_flag = 0 # 0 = none, 1 = odd, 2 = even
self.__Z_min = 1
self.__Z_max = -1 # -1 = no limit
self.__Z_flag = 0 # 0 = none, 1 = odd, 2 = even
self.__N_min = 0
self.__N_max = -1 # -1 = no limit
self.__N_flag = 0 # 0 = none, 1 = odd, 2 = even
self.__As = [] # manual selected A
self.__Zs = [] # manual selected Z
self.__Ns = [] # manual selected N
self.use_lvl_builder = True
self.show_gam = True
self.__nuclei_syms = []
self.__useRange = True
pass
def __get_symbols( self ):
'''
organize our selection to a list of symbols for our
selected nuclei.
'''
if len(self.__nuclei_syms) > 0 :
return self.__nuclei_syms
elif len(self.nuclei_list) > 0:
nuclei_list = []
for nuclei in self.nuclei_list:
sym = nuclei[0]
nuclei_list.append( sym )
return nuclei_list[:]
else:
return []
def __check_has_data( self, nucleus ):
'''
to check whether we have data or not for a given nucleus at NNDC
'''
# old link
# url=\
# 'https://www.nndc.bnl.gov/nudat2/getdataset.jsp?nucleus=%s&unc=nds' %nucleus
url=\
'https://www.nndc.bnl.gov/nudat3/getdatasetClassic.jsp?nucleus=%s&unc=nds'%nucleus
marker = "<TABLE cellspacing=1 cellpadding=4 width=800>"
content =""
with urllib.request.urlopen( url ) as f:
content = f.read().decode('utf-8')
if( content.find("Empty dataset") != -1 or \
content.find(marker) == -1 ):
return (False, "")
else:
return (True, content )
def __check_JPI( self, cnt_JPIs, JPINs ):
flag = False