-
Notifications
You must be signed in to change notification settings - Fork 0
/
interp_kp_dos.m
330 lines (264 loc) · 10.6 KB
/
interp_kp_dos.m
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
function [dos_sweep, idos_sweep, E_list, half_filling_hole_E] = interp_kp_dos(theta_list, sweep_vals, sweep_kpts)
tar_theta_list = theta_list;
% number of extra bands to include
b_size = 52;
for t_idx = 1:length(tar_theta_list)
fprintf("Starting theta %d/%d: ",t_idx,length(tar_theta_list));
tic
tri_idx = 1;
all_kpts1 = sweep_kpts{t_idx};
allbands1 = sweep_vals{t_idx};
kpoints = all_kpts1(:,[1 2]);
eig_vals = allbands1';
nk = sqrt(size(eig_vals,1));
nb = size(eig_vals,2);
n_tri = nk*nk*(2*b_size + 2);
triangles1 = zeros(n_tri,3);
triangles2 = zeros(n_tri,3);
k_tris1 = zeros(n_tri,3,2);
k_tris2 = zeros(n_tri,3,2);
for tar_b = 1:4
%for tar_b = 1;
%fprintf("on band %d / %d \n",tar_b - ((nb/2)-b_size) + 1, 2*b_size + 2);
for i = 1:nk
for j = 1:nk
tar_band(i,j) = eig_vals((i-1)*nk + j,tar_b);
k_mesh(i,j,:) = kpoints((i-1)*nk + j,:);
%k_mesh(i,j,1) = 0.1*(j-nk/2);
%k_mesh(i,j,2) = 0.1*(i-nk/2);
%tar_band(i,j) = norm( squeeze(k_mesh(i,j,:)) ).^2;
end
end
%nk = sqrt(size(k_mesh,1)*size(k_mesh,2));
% make triangles!
for i = 1:nk
for j = 1:nk
ip = i+1;
im = i-1;
jp = j+1;
jm = j-1;
if (ip > nk)
ip = 1;
end
if (im < 1)
im = nk;
end
if (jp > nk)
jp = 1;
end
if (jm < 1)
jm = nk;
end
triangles1(tri_idx,1) = tar_band(i,j);
triangles1(tri_idx,2) = tar_band(ip,j);
triangles1(tri_idx,3) = tar_band(i,jp);
k_tris1(tri_idx,1,:) = k_mesh(1,1,:);
k_tris1(tri_idx,2,:) = k_mesh(2,1,:);
k_tris1(tri_idx,3,:) = k_mesh(1,2,:);
k_0s1(tri_idx,:) = k_mesh(i,j,:);
%k_tris1(tri_idx,1,:) = k_tris1(tri_idx,1,:) + k_mesh(i,j,:);
%k_tris1(tri_idx,2,:) = k_tris1(tri_idx,2,:) + k_mesh(i,j,:);
%k_tris1(tri_idx,3,:) = k_tris1(tri_idx,3,:) + k_mesh(i,j,:);
triangles2(tri_idx,1) = tar_band(i,j);
triangles2(tri_idx,2) = tar_band(im,j);
triangles2(tri_idx,3) = tar_band(i,jm);
k_tris2(tri_idx,1,:) = k_mesh(end,end,:);
k_tris2(tri_idx,2,:) = k_mesh(end-1,end,:);
k_tris2(tri_idx,3,:) = k_mesh(end,end-1,:);
%k_tris2(tri_idx,1,:) = k_tris2(tri_idx,1,:) + k_mesh(i,j,:);
%k_tris2(tri_idx,2,:) = k_tris2(tri_idx,2,:) + k_mesh(i,j,:);
%k_tris2(tri_idx,3,:) = k_tris2(tri_idx,3,:) + k_mesh(i,j,:);
tri_idx = tri_idx+1;
end
end
end
max_E = 1.0;
dE = max_E/1000;
E_list = [-max_E:dE:max_E];
dos = zeros(length(E_list),1);
for E_idx = 1:length(E_list)
E = E_list(E_idx);
if mod(E_idx,500) == 0
fprintf([num2str(100*E_idx/length(E_list)),' p.c. done\n'])
end
for t = 1:length(triangles1)
if E > min(triangles1(t,:)) && E < max(triangles1(t,:))
%dos(E_idx) = dos(E_idx)+1;
% replace this with proper gradient computation function!
% need slope |b| and cross sectional area (length) f!
% our triangular mesh element is spanned by two vectors, v,w
% v is dk1
v(1) = k_tris1(t,2,1) - k_tris1(t,1,1);
v(2) = k_tris1(t,2,2) - k_tris1(t,1,2);
% w is dk2
w(1) = k_tris1(t,3,1) - k_tris1(t,1,1);
w(2) = k_tris1(t,3,2) - k_tris1(t,1,2);
% NOTE: here w(2) == 0!
% E0 is the difference between the sampled Energy and the
% vertex of the triangular mesh element
E0 = E - triangles1(t,1);
% Ev,Ew are the differences between the vertex and the v,w
% points of the triangular mesh element
Ev = triangles1(t,2) - triangles1(t,1);
Ew = triangles1(t,3) - triangles1(t,1);
if (w(2) ~= 0)
fprintf('WARNING: dk2 is not purely along x dir! \n');
pause(10)
end
% b is the gradient, we use w ~ x-hat to quickly compute it
b(1) = Ew/w(1);
b(2) = (Ev - b(1)*v(1)) / v(2);
% For w(2) not equal to zero:
%{
b(1) = Ew*v(1) - Ev*w(1);
b(2) = Ev*w(2) - Ew*v(2);
b = b/( w(2)*v(1) - w(1)*v(2));
%}
% The "t"s tell us where the "E0 energy cross section"
% crosses the boundaries of the triangular mesh element.
% I.e: one of these has to fall outside of the finite range
% [0,1], and then we can calculate the cross-sectional area
% by using the other two (which will both be within [0,1]!)
t1 = E0/dot(b,v);
t2 = E0/dot(b,w);
t3 = (E0 - dot(b,v)) / dot(b,w-v);
f = 0;
if (t3 < 0 || t3 > 1)
p1 = t1*v;
p2 = t2*w;
f = sqrt( sum((p1 - p2).^2) );
end
if (t1 < 0 || t1 > 1)
p2 = t2*w;
p3 = v + t3*(w - v);
f = sqrt( sum((p2 - p3).^2) );
end
if (t2 < 0 || t2 > 1)
p1 = t1*v;
p3 = v + t3*(w - v);
f = sqrt( sum((p1 - p3).^2) );
end
if(norm(b) == 0)
fprintf('WARNING: b = 0! \n');
pause(10)
end
if (f/norm(b) > 10)
fprintf('WARNING!! \n');
pause(10)
end
dos(E_idx) = dos(E_idx) + f/norm(b);
%dos_tots1(E_idx,t) = f/norm(b);
end
if E > min(triangles2(t,:)) && E < max(triangles2(t,:))
% replace this with proper gradient computation function!
% need slope |b| and cross sectional area (length)
% v is dk1
v(1) = k_tris2(t,2,1) - k_tris2(t,1,1);
v(2) = k_tris2(t,2,2) - k_tris2(t,1,2);
% w is dk2
w(1) = k_tris2(t,3,1) - k_tris2(t,1,1);
w(2) = k_tris2(t,3,2) - k_tris2(t,1,2);
E0 = E - triangles2(t,1);
Ev = triangles2(t,2) - triangles2(t,1);
Ew = triangles2(t,3) - triangles2(t,1);
if (w(2) ~= 0)
fprintf('WARNING: dk2 is not purely along x dir! \n');
pause(10)
end
b(1) = Ew/w(1);
b(2) = (Ev - b(1)*v(1)) / v(2);
% For w(2) not equal to zero:
%{
b(1) = Ew*v(1) - Ev*w(1);
b(2) = Ev*w(2) - Ew*v(2);
b = b/( w(2)*v(1) - w(1)*v(2));
%}
t1 = E0/dot(b,v);
t2 = E0/dot(b,w);
t3 = (E0 - dot(b,v)) / dot(b,w-v);
f = 0;
if (t3 < 0 || t3 > 1)
p1 = t1*v;
p2 = t2*w;
f = sqrt( sum((p1 - p2).^2) );
end
if (t1 < 0 || t1 > 1)
p2 = t2*w;
p3 = v + t3*(w - v);
f = sqrt( sum((p2 - p3).^2) );
end
if (t2 < 0 || t2 > 1)
p1 = t1*v;
p3 = v + t3*(w - v);
f = sqrt( sum((p1 - p3).^2) );
end
if(norm(b) == 0)
fprintf('WARNING: b = 0! \n');
pause(10)
end
if (f/norm(b) > 10)
fprintf('WARNING!! \n');
pause(10)
end
dos(E_idx) = dos(E_idx) + f/norm(b);
%dos_tots2(E_idx,t) = f/norm(b);
end
end
%E_idx/length(E_list)
end
%dos_sweep{t_idx} = dos;
idos = zeros(size(dos));
for x = 1:length(E_list)
if (x > 1)
idos(x) = trapz(E_list(1:x),dos(1:x));
end
end
%tot_bands = 4*2*(b_size+1);% 2 for valley, 2 for spin
alpha = 2.47;
sc_alpha = alpha/(2*sind(tar_theta_list(t_idx)/2));
sc_area = sc_alpha^2*sind(60)*1e-2; %area in nm^2
%n0 = 1/sc_area;
%idos_rescale = tot_bands/idos(end);
%dos_rescale = idos_rescale*n0
% 100 for A^2 -> nm^2, 4 for valley/spin, 4pi^2 for
dos_rescale = 100*4/(2*pi)^2;
idos_rescale = dos_rescale*sc_area;
idos(:) = idos_rescale*(idos(:) - 0.5*idos(end));
[val, idx] = min(abs(idos - (-2)));
idos_sweep{t_idx} = idos;
dos_sweep{t_idx} = dos_rescale*dos;
half_filling_hole_E(t_idx) = E_list(idx);
toc
end
% old plotting utilities
%{
clf
hold on
plot(idos,dos_rescale*dos,'k','LineWidth',2);
%text(-14,dos_max*.9,'unrelaxed 0.48^\circ')
dos_max = 60;
m = 6;
axis([-m m 0 dos_max])
set(gca,'XTick',[-m+rem(m,4):4:m])
plot([idos(idx) idos(idx)],[0 dos_max],'--k')
%xticklabels({})
set(gca,'YTick',[])
ylabel('DoS')
xlabel('n/n0')
%}
%{
tar_b = (nb/2);
for i = 1:nk
for j = 1:nk
tar_band(i,j) = eig_vals((i-1)*nk + j,tar_b);
k_mesh(i,j,:) = kpoints((i-1)*nk + j,:);
%k_mesh(i,j,1) = 0.1*(j-nk/2);
%k_mesh(i,j,2) = 0.1*(i-nk/2);
%tar_band(i,j) = norm( squeeze(k_mesh(i,j,:)) ).^2;
end
end
surf(k_mesh(:,:,1),k_mesh(:,:,2),tar_band,'EdgeColor','none','FaceColor','r')
axis([-inf inf -inf inf -inf half_filling_hole_E(end)])
view(2)
%}
end