forked from asdamle/SCDM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
valance_and_conduction_wannier.m
88 lines (70 loc) · 1.99 KB
/
valance_and_conduction_wannier.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
function [] = valance_and_conduction_wannier(fin,fout)
% if nwan >= 1 use as number of wannier functions to choose
% if nwan < 1 use as a relative threshold on diagonal of R
% Read basic information
fid=fopen(fin,'r');
nband=fscanf(fid,'%d',1);
nk=fscanf(fid,'%d',1);
nwan=fscanf(fid,'%g',1);
if nwan >= 1
nwan = round(nwan);
end
feig = fscanf(fid,'%s',1);
mu = fscanf(fid,'%g',1);
sigma = fscanf(fid,'%g',1);
kpts = zeros(nk,3);
for k = 1 : nk
kpts(k,:) = fscanf(fid,'%g',3);
end
fclose(fid);
E = load(feig);
eigKpts = reshape(E(:,3),nband,nk);
[check, gamma_idx] = min(sum(abs(kpts),2));
if check ~= 0
disp('no gamma point found')
end
occ = (1/2)*erfc((eigKpts-mu)/sigma);
[Psi,nx,ny,nz] = readUNK(gamma_idx);
disp('Computing columns...');
[~, ~, perm]=qr((Psi*diag(occ(:,gamma_idx)))','vector');
if nwan >= 1
cols = perm(1:nwan);
else
nwan = find(abs(diag(R))/abs(R(1,1)) < nwan,1);
cols = perm(1:nwan);
end
[Xs,Ys,Zs] = ndgrid(0:nx-1,0:ny-1,0:nz-1);
Xs = Xs/nx;
Ys = Ys/ny;
Zs = Zs/nz;
rposFrac = [Xs(:) , Ys(:) , Zs(:)];
% The phase factor is important for approximating integration in the
% global domain.
disp('Performing projections...');
Amn = cell(nk,1);
for k = 1 : nk
centerFrac = rposFrac(cols,:);
centerFrac = centerFrac - round(centerFrac);
phase = exp(1i*2*pi*centerFrac*kpts(k,:)');
Psi = readUNK(k);
Psi = diag(phase)*Psi(cols,:)*diag(occ(:,k));
Psi = Psi';
% Amn{k} = Psi / (sqrtm(Psi'*Psi));
[Umn, Smn, Vmn] = svd(Psi,0); %#ok
Amn{k} = Umn*(Vmn');
end
% Write the overlap matrix .amn that can be called by Wannier90
write_amn(Amn,nk,fout);
% disp('Writing amn file...');
% fid = fopen(fout, 'w');
% fprintf(fid,'Input from SCDM-k\n');
% fprintf(fid,' %10d %10d %10d\n', nband, nk, nwan);
% for k= 1 : nk
% for j = 1 : nwan % check
% for i = 1 : nband % check
% fprintf(fid, '%5d%5d%5d %16.12f %16.12f\n', ...
% i, j, k, real(Amn{k}(i,j)), imag(Amn{k}(i,j)));
% end
% end
% end
% fclose(fid);