| Home | Trees | Indices | Help |
|---|
|
|
1 import os
2 #from .FortranFormat import *
3 import chianti.constants as const
4 from .util import ion2filename
5 #
6 # -------------------------------------------------------------------------------------
7 #
8 #def elvlcRead(ions, filename = 0, verbose=0, useTh=0):
9 # """
10 # read a chianti energy level file and returns
11 # {"lvl":lvl,"conf":conf,"term":term,"spin":spin,"l":l,"spd":spd,"j":j
12 # ,"mult":mult,"ecm":ecm,"eryd":eryd,"ecmth":ecmth,"erydth":erydth,"ref":ref,"pretty":pretty, 'ionS':ions}
13 # if a energy value for ecm or eryd is zero(=unknown), the theoretical values
14 # (ecmth and erydth) are inserted
15 # """
16 # #
17 # fstring='i3,i6,a15,i3,i3,a3,f4.1,i3,4f15.2'
18 # elvlcFormat=FortranFormat(fstring)
19 # #
20 # if filename:
21 # elvlname = filename
22 # bname = os.path.basename(filename)
23 # ions = bname.split('.')[0]
24 # else:
25 # fname=ion2filename(ions)
26 # elvlname=fname+'.elvlc'
27 # if not os.path.isfile(elvlname):
28 # print((' elvlc file does not exist: %s'%(elvlname)))
29 # return {'status':0}
30 # status = 1
31 # input=open(elvlname,'r')
32 # s1=input.readlines()
33 # input.close()
34 # nlvls=0
35 # ndata=2
36 # while ndata > 1:
37 # s1a=s1[nlvls][:-1]
38 # s2=s1a.split()
39 # ndata=len(s2)
40 # nlvls=nlvls+1
41 # nlvls-=1
42 # if verbose:
43 # print((' nlvls = %i'%(nlvls)))
44 # lvl=[0]*nlvls
45 # conf=[0]*nlvls
46 # term=[0]*nlvls
47 # spin=[0]*nlvls
48 # l=[0]*nlvls
49 # spd=[0]*nlvls
50 # j=[0]*nlvls
51 # mult=[0]*nlvls
52 # ecm=[0]*nlvls
53 # eryd=[0]*nlvls
54 # ecmth=[0]*nlvls
55 # erydth=[0]*nlvls
56 # pretty=[0]*nlvls
57 # for i in range(0,nlvls):
58 # if verbose:
59 # print((s1[i][0:115]))
60 # inpt=FortranLine(s1[i][0:115],elvlcFormat)
61 # lvl[i]=inpt[0]
62 # conf[i]=inpt[1]
63 # term[i]=inpt[2].strip()
64 # spin[i]=inpt[3]
65 # l[i]=inpt[4]
66 # spd[i]=inpt[5].strip()
67 # j[i]=inpt[6]
68 # mult[i]=inpt[7]
69 # ecm[i]=inpt[8]
70 # eryd[i]=inpt[9]
71 # ecmth[i]=inpt[10]
72 # erydth[i]=inpt[11]
73 # if ecm[i] == 0.:
74 # if useTh:
75 # ecm[i] = ecmth[i]
76 # eryd[i] = erydth[i]
77 # stuff = term[i].strip() + ' %1i%1s%3.1f'%( spin[i], spd[i], j[i])
78 # pretty[i] = stuff.strip()
79 # ref=[]
80 # for i in range(nlvls+1,len(s1)-1):
81 # s1a=s1[i][:-1]
82 # ref.append(s1a.strip())
83 ## self.const.Elvlc={"lvl":lvl,"conf":conf,"term":term,"spin":spin,"l":l,"spd":spd,"j":j
84 ## ,"mult":mult,"ecm":ecm,"eryd":eryd,"ecmth":ecmth,"erydth":erydth,"ref":ref}
85 # return {"lvl":lvl,"conf":conf,"term":term,"spin":spin,"l":l,"spd":spd,"j":j
86 # ,"mult":mult,"ecm":ecm,"eryd":eryd,"ecmth":ecmth,"erydth":erydth,"ref":ref,"pretty":pretty, 'ionS':ions, 'status':status}
87 #
88 # -------------------------------------------------------------------------------------
89 #
91 ''' creates a .elvlc in the current directory
92 info is a dictionary that must contain the following keys
93 ionS, the Chianti style name of the ion such as c_4
94 conf, an integer denoting the configuration - not too essential
95 term, a string showing the configuration
96 spin, an integer of the spin of the state in LS coupling
97 l, an integer of the angular momentum quantum number
98 spd, an string for the alphabetic symbol of the angular momemtum, S, P, D, etc
99 j, a floating point number, the total angular momentum
100 ecm, the observed energy in inverse cm, if unknown, the value is 0.
101 eryd, the observed energy in Rydbergs, if unknown, the value is 0.
102 ecmth, the calculated energy from the scattering calculation, in inverse cm
103 erydth, the calculated energy from the scattering calculation in Rydbergs
104 ref, the references in the literature to the data in the input info
105 the output filename will be ionS+'.elvlc' unless outfile is specified
106 addLvl is to add a constant value to the index of all levels
107 '''
108 gname = info['ionS']
109 if outfile:
110 elvlcName = outfile
111 else:
112 elvlcName = gname + '.elvlc'
113 print((' elvlc file name = %s'%(elvlcName)))
114 out = open(elvlcName, 'w')
115 for i, conf in enumerate(info['conf']):
116 mult = int(2.*info['j'][i]+1.)
117 thisTerm = info['term'][i].ljust(14)
118 pstring = '%3i%6s%15s%3i%3i%2s%5.1f%3i%15.3f%15.6f%15.3f%15.6f \n'%(i+1+addLvl, conf, thisTerm, info['spin'][i], info['l'][i], info['spd'][i], info['j'][i], mult, info['ecm'][i], info['eryd'][i], info['ecmth'][i], info['erydth'][i])
119 #i3,a6,a15,2i3,a2,f5.1,i3,f15.3,f15.6,f15.3,f15.6
120 out.write(pstring)
121 out.write(' -1\n')
122 out.write('%filename: ' + elvlcName + '\n')
123 for one in info['ref']:
124 out.write(one+'\n')
125 out.write(' -1\n')
126 out.close()
127 return
128 #
129 # -------------------------------------------------------------------------------------
130 #
132 """
133 this is text-wise not different that the v8.0 util.wgfaRead except that it uses the
134 archival elvlcRead above
135
136 reads chianti wgfa file and returns
137 {"lvl1":lvl1,"lvl2":lvl2,"wvl":wvl,"gf":gf,"avalue":avalue,"ref":ref}
138 if elvlcname is specified, the lsj term labels are returned as 'pretty1' and 'pretty2'
139 """
140 #
141 if filename:
142 wgfaname = filename
143 if elvlcname < 0:
144 elvlcnamee = 0
145 elvlc = 0
146 elif not elvlcname:
147 elvlcname = os.path.splitext(wgfaname)[0] + '.elvlc'
148 if os.path.isfile(elvlcname):
149 elvlc = elvlcRead('', elvlcname)
150 else:
151 elvlc = 0
152 else:
153 elvlc = elvlcRead('',elvlcname)
154
155 else:
156 fname=ion2filename(ions)
157 wgfaname=fname+'.wgfa'
158 elvlcname = fname + '.elvlc'
159 if os.path.isfile(elvlcname):
160 elvlc = elvlcRead('', elvlcname)
161 else:
162 elvlc = 0
163 if verbose:
164 if elvlc:
165 print(' have elvlc data')
166 else:
167 print(' do not have elvlc data')
168 #
169 input=open(wgfaname,'r')
170 s1=input.readlines()
171 input.close()
172 nwvl=0
173 ndata=2
174 while ndata > 1:
175 s1a=s1[nwvl]
176 s2=s1a.split()
177 ndata=len(s2)
178 nwvl += 1
179 nwvl -= 1
180 if verbose:
181 print(' nwvl = %10i ndata = %4i'%(nwvl, ndata))
182 lvl1=[0]*nwvl
183 lvl2=[0]*nwvl
184 wvl=[0.]*nwvl
185 gf=[0.]*nwvl
186 avalue=[0.]*nwvl
187 if elvlc:
188 pretty1 = ['']*nwvl
189 pretty2 = ['']*nwvl
190 #
191 if verbose:
192 print(' nwvl = %10i'%(nwvl))
193 #
194 wgfaFormat='(2i5,f15.3,2e15.3)'
195 for ivl in range(nwvl):
196 inpt=FortranLine(s1[ivl],wgfaFormat)
197 lvl1[ivl]=inpt[0]
198 lvl2[ivl]=inpt[1]
199 wvl[ivl]=inpt[2]
200 gf[ivl]=inpt[3]
201 avalue[ivl]=inpt[4]
202 if elvlc:
203 pretty1[ivl] = elvlc['pretty'][inpt[0] - 1]
204 pretty2[ivl] = elvlc['pretty'][inpt[1] - 1]
205
206 ref=[]
207 # should skip the last '-1' in the file
208 for i in range(nwvl+1,len(s1) -1):
209 s1a=s1[i][:-1]
210 ref.append(s1a.strip())
211 Wgfa={"lvl1":lvl1,"lvl2":lvl2,"wvl":wvl,"gf":gf,"avalue":avalue,"ref":ref, 'ionS':ions, 'filename':wgfaname}
212 if total:
213 avalueLvl = [0.]*max(lvl2)
214 for iwvl in range(nwvl):
215 avalueLvl[lvl2[iwvl] -1] += avalue[iwvl]
216 Wgfa['avalueLvl'] = avalueLvl
217
218 if elvlc:
219 Wgfa['pretty1'] = pretty1
220 Wgfa['pretty2'] = pretty2
221 #
222 return Wgfa
223 #
224 # --------------------------------------
225 #
226
| Home | Trees | Indices | Help |
|---|
| Generated by Epydoc 3.0.1 on Sun Feb 7 12:06:09 2016 | http://epydoc.sourceforge.net |