-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparameter_common.py
executable file
·316 lines (299 loc) · 12.9 KB
/
parameter_common.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
#!/usr/bin/python2
from __future__ import division
import numpy as np
from atom import Atom
import math
from copy import copy
#import pydot
class Parameter(object):
"""
"""
def __init__(self,l1f,l0f,B,d1,gamma,egpair,omega_list,parameter,filename):
"""
if d1 == 1 then d1 else d2
l1f = (5,4,3)
l0f = (4,3)
"""
self.d1 = d1
self.egpair = egpair
self.l1f = l1f
self.l0f = l0f
self.B = B
self.parameter = parameter
self.omega_list = omega_list
self.filename = filename
#self.graph = pydot.Dot('csgraph',graph_type = 'digraph')
self.l1subg = {}
self.l0subg = {}
self.l1subn = {}
self.l0subn = {}
self.gamma = gamma
n = 0#total sublevels
for i in l1f:
n += 2*i + 1
for i in l0f:
n += 2*i + 1
self.parameter['n'] = n
def level_group(self):
"""
put all levels in L == 1 in one group, and two fine structure in L == 0 in two group
"""
level_group = []
l1_levels = 0
for i in self.l1f:
l1_levels += 2*i+1
level_group.append(range(l1_levels))
for i in self.l0f:
level_group.append(range(l1_levels,l1_levels+2*i+1))
l1_levels += 2*i+1
self.parameter['level_group']=level_group
def omega(self):
mub = 9.27400915e-28/1.054571628e-34 #\frac{mu_b}{\hbar}
gs = 2.0023193043622 # g_s Electron spin g-factor
gl = 0.99999587 # g_l Electron orbital g-factor
# Fine structure lande g-factor
gjs = 2.00254032 # g_J (6^2 S_{1/2})
gjp12 = 0.665900 # g_J (6^2 P_{1/2})
gjp32 = 1.33400 # g_J (6^2 P_{3/2})
gi = -0.00039885395 # g_I Nuclear g-factor
counter = 0
I = 7.0/2.0
self.parameter['omega']=[]
for LL in enumerate((self.l1f,self.l0f)):
if LL[0] == 0: #p
L = 1
if self.d1 == 1: #d1
gj = gjp12
J = 1.0/2.0
elif self.d1 == 0: #d2
gj = gjp32
J = 3.0/2.0
elif LL[0] == 1: #s
gj = gjs
L=0
J = 1.0/2.0
for F in LL[1]:#l
gf = gj * (F*(F+1) - I*(I+1) + J*(J+1)) / (2*F*(F+1)) + gi * (F*(F+1)+ I*(I+1) - J*(J+1)) / (2*F*(F+1))
for m in range(-F,F+1): #m
#print L,F,m,self.omega_list[counter] + mub * self.B * m * gf
self.parameter['omega'].append(self.omega_list[counter] + mub * self.B * m * gf)
counter += 1
def index2lfm(self,n):
l = 1
for i in self.l1f:
if n < 2*i + 1:
f = i
m = n - f
break
else:
n -= 2*i + 1
else:
l = 0
for j in self.l0f:
if n < 2*j + 1:
f = j
m = n - f
break
else:
n -= 2*j + 1
return l,f,m
def lfm2index(self,l,f,m):
index = 0
if l == 1:
for i in self.l1f:
if f != i:
index += 2*i+1
else:
index += m + f
break
else:
for i in self.l1f:
index += 2*i+1
for i in self.l0f:
if f != i:
index += 2*i+1
else:
index += m + f
break
return index
def dipole(self):
self.parameter['dipole'] = []
for k in range(len(self.parameter['e_amp'])):
if self.d1 == 1:
j2 = 1.0/2.0
else:
j2 = 3.0/2.0
n=self.parameter['n'] # number of levels (include sub levels)
tmp = [[0 for i in range(n)] for j in range(n)] # make a nxn matrix
cs = Atom()
for i in range(n):
for j in range(n):
d1 = self.index2lfm(i)
d2 = self.index2lfm(j)
if d1[0] == 0 and d2[0] == 1:
q_arr=self.parameter['e_amp'][k][1]
for q in q_arr:
coef = {'q':q,
'L1':0,
'L2':1,
'F1':d1[1],
'F2':d2[1],
'mf1':d1[2],
'mf2':d2[2],
'J1':1.0/2.0,
'J2':j2,
'I':7.0/2.0}
tmp[i][j] += cs.dipole_element(**coef)
elif d2[0] == 0 and d1[0] == 1:
q_arr=self.parameter['e_amp'][k][1]
for q in q_arr:
coef = {'q':q,
'L1':0,
'L2':1,
'F1':d2[1],
'F2':d1[1],
'mf1':d2[2],
'mf2':d1[2],
'J1':1.0/2.0,
'J2':j2,
'I':7.0/2.0}
tmp[i][j] += cs.dipole_element(**coef)
else:
tmp[i][j] = 0.0
self.parameter['dipole'].append(copy(tmp))
def decoherence(self):
gamma = self.gamma
if self.d1 == 1:
j2 = 1.0/2.0
#Gamma = 2*np.pi*4.575e6 #Decay Rate/Natural Line Width (rad)
else:
j2 = 3.0/2.0
#Gamma = 2*np.pi*5.234e6 #Decay Rate/Natural Line Width (rad)
#Gamma = 2*np.pi*750.0e6
Gamma = 2*np.pi*9e7
n=self.parameter['n']
self.parameter['decoherence_matrix'] = [[[] for i in range(n)] for j in range(n)]
cs = Atom()
#gamma
for i in range(n):
for j in range(i,n):
d1 = self.index2lfm(i)
d2 = self.index2lfm(j)
if d1[0:2] == (0,4) and d2[0:2] == (0,3): #ground state
#if np.abs(d1[2]-d2[2]) <= 2: #no selection rule
self.parameter['decoherence_matrix'][i][i].append([i,i,-1.0*gamma])
self.parameter['decoherence_matrix'][i][i].append([j,j,gamma])
self.parameter['decoherence_matrix'][j][j].append([j,j,-1.0*gamma])
self.parameter['decoherence_matrix'][j][j].append([i,i,gamma])
self.parameter['decoherence_matrix'][i][j].append([i,j,-1.0*gamma])
# self.graph.add_edge(pydot.Edge(self.l0subn[4][int(d1[2]+q+4)],self.l0subn[3][int(d1[2]+3)],label = 'gamma/9'))
if d2[0:2] == (0,3):
for q in range(-4,5):
allow_state = []
allow_state.append(self.lfm2index(0,4,q))
# print allow_state ,self.index2lfm(i),self.index2lfm(j)
if i in allow_state:
# print('allowed non diagonal states')
self.parameter['decoherence_matrix'][i][j].append([i,j,-1.0*gamma/9.0])
#Gamma
for pair in self.egpair:
for i in range(n):
for j in range(i,n):
d1 = self.index2lfm(i)
d2 = self.index2lfm(j)
if d1[0:2] == pair[0] and d2[0:2] == pair[0] and i != j: #both are excited
self.parameter['decoherence_matrix'][i][j].append([i,j,-1.0*Gamma])
elif d1[0:2] == pair[0] and d2[0:2] == pair[1]:#d1 is excited d2 is ground
self.parameter['decoherence_matrix'][i][j].append([i,j,-1.0*Gamma/2.0])
elif d1[0:2] == pair[1] and d2[0:2] == pair[0]:# d2 is excited d1 is ground
self.parameter['decoherence_matrix'][i][j].append([i,j,-1.0*Gamma/2.0])
elif d1[0:2] == pair[1] and d2[0:2] == pair[1]:# both ground
for q in (-1.0,0.0,1.0):
f1 = pair[0][1]
if (d1[2]+q <= f1 and d1[2]+q >= -1*f1) and (d2[2]+q <= f1 and d2[2]+q >= -1*f1):
coef1 = {'q':q,
'L1':0,
'L2':1,
'F1':pair[1][1],
'F2':pair[0][1],
'mf1':d1[2],
'mf2':d1[2]+q,
'J1':1.0/2.0,
'J2':j2,
'I':7.0/2.0}
coef2 = {'q':q,
'L1':0,
'L2':1,
'F1':pair[1][1],
'F2':pair[0][1],
'mf1':d2[2],
'mf2':d2[2]+q,
'J1':1.0/2.0,
'J2':j2,
'I':7.0/2.0}
#this correction coefficient (see equation 54) should be written to atom.py later
rev = (-1)**(pair[0][1]-pair[1][1]+q)*math.sqrt((2*pair[0][1]+1)/(2*pair[1][1]+1))
rev = rev**2 #-1's power doesn't matter now, but still need to be checked
tmp = Gamma*cs.cg_coef(**coef1)*cs.cg_coef(**coef2)*rev
if tmp != 0.0:
ii = self.lfm2index(pair[0][0],pair[0][1],d1[2]+q)
jj = self.lfm2index(pair[0][0],pair[0][1],d2[2]+q)
self.parameter['decoherence_matrix'][i][j].append([ii,jj,tmp])
if ii == jj:
self.parameter['decoherence_matrix'][int(ii)][int(jj)].append([ii,jj,-1*tmp])
#add to graph
# f1 = int(pair[0][1])
# f2 = int(pair[1][1])
# label = '%.2e'%tmp
#self.graph.add_edge(pydot.Edge(self.l1subn[f1][int(d1[2]+q+f1)],self.l0subn[f2][int(d1[2]+f2)],label = label))
def nu(self):
self.parameter['nu'] = []
for pair in self.parameter['nup']:
freq = self.parameter['omega'][self.lfm2index(*pair[0])]-self.parameter['omega'][self.lfm2index(*pair[1])]
self.parameter['nu'].append(freq)
def write(self):
self.parameter['gamma'] = self.gamma
self.parameter['d1'] = self.d1
#self.prepare_graph()
self.level_group()
self.omega()
self.nu()
self.dipole()
self.decoherence()
#print " L F M|"
#print "----------------------------------------"
# sum = 0.0
# psum = 0.0
# for i in range(self.parameter['n']):
# iter = self.parameter['decoherence_matrix'][i][i]
# for j in iter:
# sum += j[2]
# psum += j[2]
# print "{:3d}:{:3d} {:3d} {:3d}| {:<100} |Sum is: {:>20f}".format(i,self.index2lfm(i)[0],self.index2lfm(i)[1],self.index2lfm(i)[2],iter,psum)
# psum = 0.0
#print "the sum is %f" %sum
txtf = open(self.filename+'.txt','w')
txtf.write(str(self.parameter))
txtf.close()
#self.write_graph()
# def prepare_graph(self):
# for i in self.l1f:
# self.l1subg[i] = pydot.Subgraph('',rank = 'same')
# self.l1subn[i] = []
# for j in range(-1*i,i+1):
# name = 'L=1,F=%d,m=%d' %(i,j)
# self.l1subn[i].append(pydot.Node(name))
# self.l1subg[i].add_node(self.l1subn[i][j+i])
# self.graph.add_subgraph(self.l1subg[i])
# for i in self.l0f:
# self.l0subg[i] = pydot.Subgraph('',rank = 'same')
# self.l0subn[i] = []
# for j in range(-1*i,i+1):
# name = 'L=0,F=%d,m=%d' %(i,j)
# self.l0subn[i].append(pydot.Node(name))
# self.l0subg[i].add_node(self.l0subn[i][j+i])
# self.graph.add_subgraph(self.l0subg[i])
# def write_graph(self):
# self.graph.write_png(self.filename+'.png')
if __name__ == '__main__':
pass