forked from asdamle/SCDM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen_kpts.m
92 lines (74 loc) · 2.58 KB
/
gen_kpts.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
function [kpts, kpath_loc, kpath] = gen_kpts(kstart,kend,kpath,numpts,varargin)
% only option for a third input argument is a file to write the kpts to,
% this file is written in a format that works with postw90.x
% only do relative coords for the moment?
% each row of kstart and kend define endpoints of a path in kspace
% the start and end are assumed to be the same, up to periodicity
% this means the distance is set to 0 between these points when plotting,
% even if they are not technically the same point.
% numpts is the number of points on each path between the fixed points
% kpath is a string of points in the set {G,L,X,K}, should be equal to the
% number of paths+1, labels are assumed to occur at every transition from
% one path to the next, plus one at the start and one at the end.
%check / fix
% kL = [0.50000 0.50000 0.5000];
% kG = [0.00000 0.00000 0.0000];
% kX = [0.50000 -0.50000 0.0000];
% kK = [0.37500 -0.37500 0.0000];
n = size(kstart,1);
% build paths
% A = zeros(n,3);
% for k = 1:n
% switch upper(kpath(k))
% case {'G'}
% A(k,:) = kG;
% case {'L'}
% A(k,:) = kL;
% case {'K'}
% A(k,:) = kK;
% case {'X'}
% A(k,:) = kX;
% otherwise
% disp('invalid input')
% break;
% end
% end
m = size(kstart,1);
total_kpts = m*(numpts + 2);
kpath_loc = zeros(m+1,1);
kline = linspace(0,1,numpts+2);
kpath_loc(1) = 1;
kpts = repmat(1-kline(:),1,3).*repmat(kstart(1,:),numpts+2,1) + ...
repmat(kline(:),1,3).*repmat(kend(1,:),numpts+2,1);
kpath_loc(2) = size(kpts,1);
for k = 2:n
temp = repmat(1-kline(:),1,3).*repmat(kstart(k,:),numpts+2,1) + ...
repmat(kline(:),1,3).*repmat(kend(k,:),numpts+2,1);
kpts = [kpts; temp];
kpath_loc(k+1) = size(kpts,1);
end
kpath = upper(kpath);
% do file i/o
if nargin > 2
fname = varargin{1};
fid = fopen(fname,'w+');
fprintf(fid,'kpt list generated by MATLAB\n');
fprintf(fid,'crystal\n'); % only relative coords here for the moment
fprintf(fid,'%i\n',total_kpts);
temp = [(1:total_kpts)' kpts];
fprintf(fid,'%d %7.5f %7.5f %7.5f\n',temp');
fclose(fid);
end
% This is used for generating the path for QE nscf calculation
if nargin > 3
fname = varargin{2};
fid = fopen(fname,'w+');
fprintf(fid,'kpt list generated by MATLAB\n');
fprintf(fid,'K_POINTS {crystal}\n');
fprintf(fid,'%i\n',total_kpts);
wgts = ones(total_kpts,1)*1./total_kpts;
temp = [kpts wgts];
fprintf(fid,'%7.5f %7.5f %7.5f %7.5f\n',temp');
fclose(fid);
end
end