Eötvös Quantum Utilities  v4.9.146
Providing the Horsepowers in the Quantum Realm
Read_Siesta_Lead.m
Go to the documentation of this file.
1 
2 %> @file Read_Siesta_Lead.m
3 %> @brief Creates the Hamiltonians and overlap integrals from the HSX file data of the Siesta package for the lead
4 %> @Available
5 %> EQuUs v4.9 or later
6 %> @param Param contains general input parameters
7 %> @param SIESTA_HSX_file is the file, where the hamiltonian is stored in a unique sparse format of SIESTA
8 %> @param SIESTA_XML_params parameters from SIESTA xml output
9 %> @param shift, the coordinates to fit to the scattering region
10 %> @param q k-point, where the Hamiltonian and Overlap matrices should be constructed
11 %> @return The constructed Hamiltonian of the whole system as HS, atomic coordinates and a description of the orbital system
12 
13 function [HS, coordsLeads, Atoms] = Siesta_Equus_Read_Lead(id_lead, Param, SIESTA_HSX_file, SIESTA_XML_params,shift, q)
14 
15  %SOME CONSTANTS USE IN SIESTA
16  RytoeV = 1/13.60580; %
17  Bohr = 0.529177; % Angstrom
18 
19  Syslabel = Param.Leads{id_lead}.FileName(1:end-4);
20  xmlfile = [Syslabel,'.xml'];
21 
22  %THESE ARE THE FIELD FROM XML THAT ARE USED LATER
23  fieldsfromxml = { 'siesta:E_Fermi', 'siesta:nkpoints', 'Initial System' ,'siesta:kpoints','siesta:kpt_band', 'siesta:kscell'};
24  Lead_params = Read_Siesta_XML(xmlfile, fieldsfromxml, true);
25  Param.Leads{id_lead}.E_Fermi = Lead_params.E_Fermi;
26 
27  %% EZ ITT RONDA, DE EZ VAN. EZ AZ ADAT NINCS MEG MASHOL
28  %% FIND THE DIRECTORY WHERE THE "filename.out" FILE IS PLACED AND READ IT
29  output_file = [Syslabel,'.out'];
30 % directory = inputP.Path_Leads{lead}(1:end-cellfun(@length, output_file(end)));
31  logfile=fileread(output_file);
32 
33  %% FIND SYSTEM LABEL
34  foundat = findstr(logfile,'SystemLabel');
35  dummy=strsplit(logfile(foundat:foundat+100));
36  system_label = dummy(2);
37 
38  %% FIND SUPERCELL SIZE
39  foundat = findstr(logfile,'supercell');
40  if ~ isempty(foundat)
41  dummy = strsplit(logfile(foundat:foundat+100));
42  if ~isempty(str2num(dummy{3})) && ~isempty(str2num(dummy{4})) && ~isempty(str2num(dummy{5}))
43  nsc = [str2num(dummy{3}) str2num(dummy{4}) str2num(dummy{5})];
44  elseif ~isempty(str2num(dummy{2})) && ~isempty(str2num(dummy{4})) && ~isempty(str2num(dummy{6}))
45  nsc = [str2num(dummy{2}) str2num(dummy{4}) str2num(dummy{6})];
46  else
47  warning(' ************* OH NO! SIESTA OUTPUT CHANGED AGAIN?! ************')
48  exit
49  end
50  else
51  nsc = [1 1 1];
52  end
53  %% SUPERCELL SIZE
54  nnsc=nsc(1)*nsc(2);
55 
56 
57 
58  %% TODO kpoints needed?
59  %param.scatter.kpoints = xml_params.kpoints;
60  %Param.scatter.ElementNumber = SIESTA_XML_params.elmtxv;
61  %Param.scatter.ElementSymbol = SIESTA_XML_params.spxv;
62  %Param.scatter.LatticeVectors = SIESTA_XML_params.Lattice_vectors;
63 
64  kpoints = Lead_params.kpoints;
65  elmtxv = Lead_params.elmtxv;
66  spxv = Lead_params.spxv;
67  LatticeVectors = Lead_params.Lattice_vectors;
68 
69  %STRUCTURES FOR COORDINATES
70  coordsLeads = structures('coordinates');
71 
72  %% SELECT ONLY TRANSVERSE K-POINTS & RESTATE WEIGHTS ??
73  %obj.param.Leads{}.kpoints;
74 
75  %% READ FILE "system_label.HSX"
76  hsx = read_hsx( Param.Leads{id_lead}.FileName );
77 
78  %IF USING THE FORTRAN HSX READER, THEN VARIABLES HAVE TO BE CONVERTED TO DOUBLES
79  hsx.numh=double(hsx.numh);
80  hsx.listhptr=double(hsx.listhptr);
81  hsx.indxuo=double(hsx.indxuo);
82 
83  no_u = double(hsx.no_u);
84  nspin = double(hsx.nspin);
85  gspin = hsx.nspin;
86  if nspin > 2
87  gspin = 1;
88  end
89 
90  %Set units to eV
91  hsx.hamilt = hsx.hamilt/RytoeV;
92 
93  %COORDS and %LATTICE VECTORS
94  coordsLead = structures('coordinates');
95  Atoms = zeros(no_u);
96 
97  %% CREATE ORBITAL INFO
98  iorb = [];
99  coords = zeros(no_u,3);
100  for iuo=1:no_u
101  iat = hsx.iaorb(iuo);
102  iphorb = hsx.iphorb(iuo);
103  spec = hsx.isa(iat);
104 % element_index = Param.scatter.ElementNumber(iat);
105  element_index = Lead_params.elmtxv(iat);
106  coordsLead.x(iuo) = Lead_params.coordinates(iat,1);
107  coordsLead.y(iuo) = Lead_params.coordinates(iat,2);
108  coordsLead.z(iuo) = Lead_params.coordinates(iat,3);
109  Atoms(iuo) = iat;
110  dum = [ iat, hsx.nquant(spec,iphorb), hsx.lquant(spec,iphorb), 0, hsx.zeta(spec,iphorb),...
111  element_index, Get_Atomic_Mass(element_index)];
112  iorb = [iorb; dum];
113  end
114  Param.Leads{id_lead}.coordinates = coordsLead;
115  %IF IT IS COLLINEAR SPIN POLARIZED THEN WE DOUBLE THE SIZE OF THE
116  %HAMILTONIAN AND STORE THEM IN SEPARATE BLOCKS
117  if nspin > 2
118  iorb = [iorb; iorb];
119  end
120 
121 
122  %COMPOSING THE Hk FROM HAMILTONIAN ELEMENTS
123  %EM PART, THE SCATTERING REGION
124  %IN CASE OF JOSEPHSON CURRENT MODE, THIS EXCLUDES THE INTERFACE
125  %WHICH IS PART OF THE ELECTRODES, CLOSEST TO EM, THAT IS NOT USED
126  %FOR THE LEADS CALCULATION
127 
128  %% FIND INDICES BELONGING TO H0 OR H1
129  tt=[]; tk=[];
130  for iuo=1:no_u
131  tt = [ tt 1:hsx.numh(iuo)];
132  tk= [tk hsx.listhptr(iuo).*ones(hsx.numh(iuo),1)'];%'
133  end
134  ind=(tt+tk)';%'
135 
136  iuo=[];
137  for ii=1:no_u
138  iuo = [iuo double(ii).*ones(hsx.numh(ii),1)'];%'
139  end
140  jo = hsx.listh(ind);
141  juo = (hsx.indxuo(jo))';%'
142 
143  ind0 = find(jo <= no_u*nnsc);
144  jo0 = jo(ind0);
145  juo0 = (hsx.indxuo(jo0))';%'
146  iuo0 = iuo(ind0);
147 
148  ind1 = intersect(intersect(find(jo > no_u*nnsc),find(jo <= 2*no_u*nnsc)),find(hsx.xij(3,ind) >= 0.0));
149  jo1 = jo(ind1);
150  juo1 = (hsx.indxuo(jo1))';%'
151  iuo1 = iuo(ind1);
152 
153  % Convert hsx.xij from Bohr to Angstrom
154  xij = hsx.xij*Bohr;
155 
156  %% COMPUTE H and S FOR GIVEN LEAD
157  Rbloch(:,1) = xij(1,ind)' + coordsLead.x(iuo)' - coordsLead.x(juo)';
158  Rbloch(:,2) = xij(2,ind)' + coordsLead.y(iuo)' - coordsLead.y(juo)';
159  Rbloch(:,3) = xij(3,ind)' + coordsLead.z(iuo)' - coordsLead.z(juo)';
160 
161  HS=[];
162  if length(q)>1
163  eikr = exp(-1.0i* (q(1).*Rbloch(ind,1)+q(2).*Rbloch(ind,2)+q(3).*Rbloch(ind,3)));
164  else
165  eikr = ones(length(ind), 1);
166  end
167  if Param.scatter.nspin <= 2
168  HS(1).S0 = sparse(juo0,iuo0, hsx.Sover(ind0).*eikr(ind0),no_u,no_u);
169  HS(1).S1 = sparse(juo1,iuo1, hsx.Sover(ind1).*eikr(ind1),no_u,no_u);
170  for is=1:Param.scatter.nspin
171  HS(is).H0 = sparse(juo0,iuo0, hsx.hamilt(ind0,is).*eikr(ind0),no_u,no_u);
172  HS(is).H1 = sparse(juo1,iuo1, hsx.hamilt(ind1,is).*eikr(ind1),no_u,no_u);
173  end
174  elseif Param.scatter.nspin == 4
175  HS(1).S0 = kron(eye(2),sparse(juo0,iuo0, hsx.Sover(ind0).*eikr(ind0),no_u,no_u));
176  HS(1).S1 = kron(eye(2),sparse(juo1,iuo1, hsx.Sover(ind1).*eikr(ind1),no_u,no_u));
177  H1=kron([1 0; 0 0], sparse(juo0,iuo0, hsx.hamilt(ind0,1).*eikr(ind0),no_u,no_u));
178  H2=kron([0 0; 0 1], sparse(juo0,iuo0, hsx.hamilt(ind0,2).*eikr(ind0),no_u,no_u));
179  H3=kron([0 1; 0 0], sparse(juo0,iuo0, (hsx.hamilt(ind0,3)-1i*hsx.hamilt(ind0,4)).*eikr(ind0),no_u,no_u));
180  H4=kron([0 0; 1 0], sparse(juo0,iuo0, (hsx.hamilt(ind0,3)+1i*hsx.hamilt(ind0,4)).*eikr(ind0),no_u,no_u));
181  HS(1).H0 = H1 + H2 + H3 + H4;
182  H1=kron([1 0; 0 0], sparse(juo1,iuo1, hsx.hamilt(ind1,1).*eikr(ind1),no_u,no_u));
183  H2=kron([0 0; 0 1], sparse(juo1,iuo1, hsx.hamilt(ind1,2).*eikr(ind1),no_u,no_u));
184  H3=kron([0 1; 0 0], sparse(juo1,iuo1, (hsx.hamilt(ind1,3)-1i*hsx.hamilt(ind1,4)).*eikr(ind1),no_u,no_u));
185  H4=kron([0 0; 1 0], sparse(juo1,iuo1, (hsx.hamilt(ind1,3)+1i*hsx.hamilt(ind1,4)).*eikr(ind1),no_u,no_u));
186  HS(1).H1 = H1 + H2 + H3 + H4;
187  elseif Param.scatter.nspin == 8
188  HS(1).S0 = kron(eye(2),sparse(juo0,iuo0, hsx.Sover(ind0).*eikr(ind0),no_u,no_u));
189  HS(1).S1 = kron(eye(2),sparse(juo1,iuo1, hsx.Sover(ind1).*eikr(ind1),no_u,no_u));
190  H1=kron([1 0; 0 0], sparse(juo0,iuo0, (hsx.hamilt(ind0,1)+1i*hsx.hamilt(ind0,5)).*eikr(ind0),no_u,no_u));
191  H2=kron([0 0; 0 1], sparse(juo0,iuo0, (hsx.hamilt(ind0,2)+1i*hsx.hamilt(ind0,6)).*eikr(ind0),no_u,no_u));
192  H3=kron([0 1; 0 0], sparse(juo0,iuo0, (hsx.hamilt(ind0,3)-1i*hsx.hamilt(ind0,4)).*eikr(ind0),no_u,no_u));
193  H4=kron([0 0; 1 0], sparse(juo0,iuo0, (hsx.hamilt(ind0,7)+1i*hsx.hamilt(ind0,8)).*eikr(ind0),no_u,no_u));
194  HS(1).H0 = H1 + H2 + H3 + H4;
195  H1=kron([1 0; 0 0], sparse(juo1,iuo1, (hsx.hamilt(ind1,1)+1i*hsx.hamilt(ind1,5)).*eikr(ind1),no_u,no_u));
196  H2=kron([0 0; 0 1], sparse(juo1,iuo1, (hsx.hamilt(ind1,2)+1i*hsx.hamilt(ind1,6)).*eikr(ind1),no_u,no_u));
197  H3=kron([0 1; 0 0], sparse(juo1,iuo1, (hsx.hamilt(ind1,3)-1i*hsx.hamilt(ind1,4)).*eikr(ind1),no_u,no_u));
198  H4=kron([0 0; 1 0], sparse(juo1,iuo1, (hsx.hamilt(ind1,7)+1i*hsx.hamilt(ind1,8)).*eikr(ind1),no_u,no_u));
199  HS(1).H1 = H1 + H2 + H3 + H4;
200  end
201 
202 %% Change Lead orientation if needed
203  if Param.Leads{id_lead}.Lead_Orientation == -1;
204  HS(1).S1 = HS(1).S1';
205  for is=1:gspin
206  HS(is).H1 = HS(is).H1';
207  end
208  end
209 
210  %% Correction
211  correction = mean(mean(HS(1).H0))-shift;
212 
213  %for is=1:obj.param.scatter.nspin
214  for is=1:gspin
215  HS(is).H0 = HS(is).H0 - correction*HS(1).S0;
216  HS(is).H1 = HS(is).H1 - correction*HS(1).S1;
217  end
218 
219 
220 end %function
type(hsx_t), public hsx
Definition: hsx_EQuUs.f90:25
subroutine read_hsx(fname, fname_len, eq_struct)
Definition: hsx_EQuUs.f90:46
function Hamiltonians(varargin)
Function to create the custom Hamiltonians for the 1D chain.
Structure param contains data structures describing the physical parameters of the scattering center ...
Definition: structures.m:45
function Read_Siesta_XML(xmlfile, fields, readanyway)
function Get_Atomic_Mass(Z)
function structures(name)