Eötvös Quantum Utilities  v4.9.146
Providing the Horsepowers in the Quantum Realm
Siesta_Interface.m
Go to the documentation of this file.
1 %% Eotvos Quantum Transport Utilities - Custom_Hamiltonians
2 % Copyright (C) 2015-2018 Peter Rakyta, Ph.D., David Visontai, Ph.D.
3 %
4 % This program is free software: you can redistribute it and/or modify
5 % it under the terms of the GNU General Public License as published by
6 % the Free Software Foundation, either version 3 of the License, or
7 % (at your option) any later version.
8 %
9 % This program is distributed in the hope that it will be useful,
10 % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 % GNU General Public License for more details.
13 %
14 % You should have received a copy of the GNU General Public License
15 % along with this program. If not, see http://www.gnu.org/licenses/.
16 %
17 % Interface to import Siesta hamiltonian from Syslabe.HSX provided by other codes or created
18 % manually
19 %%
20 
21 %> @file Siesta_Interface.m
22 %> @brief Creates the Hamiltonians and overlap integrals from the loaded data from the Siesta package.
23 %
24 %> @Available
25 %> EQuUs v4.9.... or later
26 %> @param WorkingDir is declared in the input, this is where the SIESTA files are to be found
27 %> @param Param contains input parameters
28 %> @param q k-point, where the Hamiltonian and Overlap matrices should be constructed
29 %> @return The Leads' H0 and H1 as HL0, SL0, HL1, SL1, the hamiltonian of the scattering part as HSC and SSC and coupling between the scattering region and the leads as Hc and SC. Coordinates and the Fermi energy is returned as well.
30 function [HL0, SL0, HL1, SL1, coordsLeads, HSC, SSC, coordsSC, ...
31  H1_t, S1_t, HSC_t, SSC_t, HC, SC, EF] = Siesta_Interface(WorkingDir, Param, q)
32 
33  Syslabel = Param.scatter.FileName(1:end-4);
34  XML_file = [WorkingDir, '/', Syslabel, '.xml'];
35  HSX_file = [WorkingDir, '/', Syslabel, '.HSX'];
36 
37  %THESE ARE THE FIELDS FROM XML THAT ARE USED LATER
38  fieldsfromxml = {'siesta:E_Fermi', 'siesta:nkpoints', 'Initial System', 'siesta:kpoints', 'siesta:kpt_band'};
39  xml_params = Read_Siesta_XML(XML_file, fieldsfromxml, false);
40  EF = xml_params.E_Fermi;
41  % Use only those k-points that have kz=kpoint(3)=0.0000 ASSUMING THAT
42  % THE DIRECTION OF THE TRANSPORT IS ALONG THE Z AXIS
43  kpoints = xml_params.kpoints(abs(xml_params.kpoints(:,3))<0.0000001,:);
44 
45  % bug fixed: variable atom confronting with object atom
46  % see doc. MATLAB/Octave language support for Atom at https://atom.io/packages/language-matlab
47 
48  H1_t = [];
49  S1_t = [];
50  HSC_t = [];
51  SSC_t = [];
52 
53 %% CREATE ATOM VECTOR
54  NumLeads=length(Param.Leads);
55  natoms=length(Param.scatter(1).Atom);
56  for ilead=1:NumLeads
57  natoms = natoms + length(Param.Leads{ilead}.Atom);
58  end
59 
60  atom=zeros(natoms,5);
61 
62  Number_of_layers_in_leads = zeros(NumLeads);
63  Terminating_layer_in_leads = zeros(NumLeads);
64  Lead_orientation = zeros(NumLeads);
65  for ilead=1:NumLeads
66  if size(Param.Leads{ilead}.Atom)~=0;
67  Number_of_layers_in_leads(ilead) = max([Param.Leads{ilead}.Atom(1).PL, Param.Leads{ilead}.Atom(end).PL]);
68  Terminating_layer_in_leads(ilead) = max([Param.Leads{ilead}.Atom(1).PL, Param.Leads{ilead}.Atom(end).PL]);
69  Lead_orientation(ilead) = Param.Leads{ilead}.Lead_Orientation;
70  end
71  for atm=Param.Leads{ilead}.Atom
72  atom(atm.Id,2) = ilead;
73  atom(atm.Id,3) = atm.PL;
74  end
75  end
76 
77  atom(:,1)=1:natoms;
78 
79 %% READ SCATTERING REGION FROM SIESTA HSX
80 
81 
82  %[HS_EM, coordsSC, H1_t, S1_t, HSC_t, tiorb] = Siesta_Equus_Read_EM(Param, HSX_file, xml_params, q);
83  [HS_EM, coordsSC, tiorb, Param, ScatterAtoms] = Read_Siesta_Scatter(Param, HSX_file, xml_params, q);
84 
85  %THIS SHOWS WHICH ORBITAL BELONGS TO WHICH ATOM
86  iorb = [tiorb(:,1), atom(tiorb(:,1),2:3), tiorb(:,2:end)];
87 
88  % THIS JUST INDICATES WHETHER THE HAMILTONIAN IS IN ONE BLOCK OR TWO
89  % IN CASE OF COLLINEAR POLARIZED SPIN CALCULATION IT IS IN 2 SUBBLOCKS
90  % OTHERWISE IN 1 SUBBLOCK
91  gspin = 1;
92  if Param.scatter.nspin==2
93  gspin = 2;
94  Param.scatter.ElementNumber = [Param.scatter.ElementNumber, Param.scatter.ElementNumber];
95  Param.scatter.ElementSymbol = [Param.scatter.ElementSymbol, Param.scatter.ElementSymbol];
96  Param.scatter.Atom = [Param.scatter.Atom, Param.scatter.Atom];
97  siorb = size(iorb, 1);
98  %iorb = [iorb; iorb];
99  %iorb(siorb+1:end, 1) = iorb(1:siorb, 1) + siorb;
100  end
101 % READ SCATTERING INFORMATIONS ---------------------------------------
102 
103 
104 %% ORBITAL INFOS
105 
106  %CREATE ORBITAL REGISTER
107  Orbitals.Mol = intersect(find(iorb(:,2)==0), find(iorb(:,3)==0));
108  Orbitals.ExtMol = Orbitals.Mol';
109  for ilead=1:NumLeads
110  if Terminating_layer_in_leads(ilead)==1 & ~Param.Leads{ilead}.Use_External_Lead
111  fprintf('There must be more than 1 unit cell for leads if no external is provided!');
112  quit;
113  end
114  for ipl=1:Terminating_layer_in_leads(ilead)
115  aux = intersect(find(iorb(:,2)==ilead), find(iorb(:,3)==ipl));
116  Orbitals.Lead{ilead}.PL{ipl} = aux;
117  if ipl<Terminating_layer_in_leads(ilead)
118  Orbitals.ExtMol = [Orbitals.ExtMol, aux'];
119  end
120  end
121  end
122  Orbitals.ExtMol = sort(Orbitals.ExtMol);
123 
124 % END OF ORBITAL INFOS ------------------------------------
125 
126 LeadAtoms = {};
127 %% SET UP LEADS
128 % for ispin = 1:gspin
129  %for ik = 1:length(param.scatter.kpoints)
130  for id_lead=1:NumLeads
131  if Param.Leads{id_lead}.Use_External_Lead == 1
132  %% READ EXTERNAL LEADS IF REQUESTED
133  disp(' Reading LEAD Hamiltonian from Siesta')
134 
135  %aux = orbLead(ilead,:,leadp(ilead,2));
136  aux = Orbitals.Lead{id_lead}.PL{1};
137  shift = mean(mean(HS_EM(1).H(aux,aux)));
138  [HS_Lead(id_lead).lead, coordsLeads{id_lead}, LeadAtoms{id_lead}] = Read_Siesta_Lead(id_lead, Param, HSX_file, xml_params, shift, q);
139 
140  HL0{id_lead} = HS_Lead(id_lead).lead(1).H0;
141  SL0{id_lead} = HS_Lead(id_lead).lead(1).S0;
142  HL1{id_lead} = HS_Lead(id_lead).lead(1).H1;
143  SL1{id_lead} = HS_Lead(id_lead).lead(1).S1;
144  H1_t{id_lead} = zeros(size(HL1));
145  S1_t{id_lead} = zeros(size(SL1));
146 
147  else
148  %% OR FROM SCATTERING REGION
149  clear aux0 aux1
150  LastTerminatingLayer = Terminating_layer_in_leads(id_lead);
151  if LastTerminatingLayer
152  aux0 = Orbitals.Lead{id_lead}.PL{LastTerminatingLayer};
153  aux1 = Orbitals.Lead{id_lead}.PL{LastTerminatingLayer-1};
154  HL0{id_lead} = HS_EM(1).H(aux0, aux0);
155  HL1{id_lead} = HS_EM(1).H(aux0, aux1);
156  SL0{id_lead} = HS_EM(1).S(aux0, aux0);
157  SL1{id_lead} = HS_EM(1).S(aux0, aux1);
158  coordsLeads{id_lead}.x = coordsSC.x([aux0; aux1]);
159  coordsLeads{id_lead}.y = coordsSC.y([aux0; aux1]);
160  coordsLeads{id_lead}.z = coordsSC.z([aux0; aux1]);
161  LeadAtoms{id_lead} = ScatterAtoms([aux0; aux1]);
162 
163  if Param.scatter.nspin==2
164  HL0 = [HL0{id_lead}, sparse([],[],[], size(HL0{id_lead},1), size(HL0{id_lead},2)); sparse([],[],[], size(HL0{id_lead},1), size(HL0{id_lead},2)), HS_EM(2).H(aux0, aux0)];
165  HL1 = [HL1{id_lead}, sparse([],[],[], size(HL1{id_lead},1), size(HL1{id_lead},2)); sparse([],[],[], size(HL1{id_lead},1), size(HL1{id_lead},2)), HS_EM(2).H(aux0, aux1)];
166  coordsLeads{id_lead}.x = [coordsLeads{id_lead}.x, coordsLeads{id_lead}.x];
167  coordsLeads{id_lead}.y = [coordsLeads{id_lead}.y, coordsLeads{id_lead}.y];
168  coordsLeads{id_lead}.z = [coordsLeads{id_lead}.z, coordsLeads{id_lead}.z];
169  LeadAtoms{id_lead} = [LeadAtoms{id_lead}, LeadAtoms{id_lead}];
170  coordsLeads{id_lead}.spinup = [ true(size(HL0{id_lead},1),1); false(size(HL0{id_lead},1),1)];
171  end
172 % else
173 % HL0{id_lead} = [];
174 % HL1{id_lead} = [];
175 % SL0{id_lead} = [];
176 % SL1{id_lead} = [];
177 % coordsLeads{id_lead}.x = [];
178 % coordsLeads{id_lead}.y = [];
179 % coordsLeads{id_lead}.z = [];
180  end
181 
182  H1_t{id_lead} = zeros(size(HL1));
183  S1_t{id_lead} = zeros(size(SL1));
184  end
185  end;
186 % end;
187 
188 % END OF LEADS SETUP INFOS ------------------------------------
189 
190 
191 
192  coordsSC.x = coordsSC.x(Orbitals.Mol);
193  coordsSC.y = coordsSC.y(Orbitals.Mol);
194  coordsSC.z = coordsSC.z(Orbitals.Mol);
195  ScatterAtoms = ScatterAtoms(Orbitals.Mol);
196 
197  if Param.scatter.nspin==2
198  coordsSC{id_lead}.x = [coordsSC{id_lead}.x, coordsSC{id_lead}.x];
199  coordsSC{id_lead}.y = [coordsSC{id_lead}.y, coordsSC{id_lead}.y];
200  coordsSC{id_lead}.z = [coordsSC{id_lead}.z, coordsSC{id_lead}.z];
201  coordsSC{id_lead}.Atoms = [coordsSC{id_lead}.Atoms, coordsSC{id_lead}.Atoms];
202  coordsSC{id_lead}.spinup = [ true(size(HL0{id_lead},1),1); false(size(HL0{id_lead},1),1)];
203  end
204 
205  % FROM THE WHOLE HAMILTONIAN CUT OUT THE EFFECT OF PERIODICITY
206  for ispin = 1:gspin
207  for il1=1:NumLeads
208  for il2=il1+1:NumLeads
209  Leadorb1 = [];
210  for ipl1=1:Terminating_layer_in_leads(il1)
211  %Leadorb1 = [Leadorb1; Orbitals.Lead{il1}.PL{ipl1}];
212  Leadorb1 = [Leadorb1, Orbitals.Lead{il1}.PL{ipl1}];
213  Leadorb2 = [];
214  for ipl2=1:Terminating_layer_in_leads(il2)
215  %Leadorb2 = [Leadorb2; Orbitals.Lead{il2}.PL{ipl2}];
216  Leadorb2 = [Leadorb2, Orbitals.Lead{il2}.PL{ipl2}'];
217  HS_EM(ispin).H(Leadorb1, Leadorb2) = 0;
218  HS_EM(ispin).H(Leadorb2, Leadorb1) = 0;
219  end
220  end
221  end
222  end
223  end
224 
225 
226 
227  %% LOAD SCATTERING REGION INTO HSC, SSC
228  %ez jo egyebkent
229  HSC = HS_EM(1).H(Orbitals.Mol, Orbitals.Mol);
230  SSC = HS_EM(1).S(Orbitals.Mol, Orbitals.Mol);
231  if Param.scatter.nspin==2
232  HSC = [HSC, sparse([],[],[], size(HSC, 1), size(HSC, 2)); sparse([],[],[], size(HSC, 1), size(HSC, 2)), HS_EM(2).H(Orbitals.Mol, Orbitals.Mol)];
233  SSC = [SSC, sparse([],[],[], size(SSC, 1), size(SSC, 2)); sparse([],[],[], size(SSC, 1), size(HSC, 2)), HS_EM(2).S(Orbitals.Mol, Orbitals.Mol)];
234  end
235  %% LOAD INTERFACE INTO HC, SC
236  for ilead =1:NumLeads
237  LastTerminatingLayer = Terminating_layer_in_leads(ilead);
238  if LastTerminatingLayer
239  C = Orbitals.Lead{ilead}.PL{max(LastTerminatingLayer-1, 1)};
240  %ez jo!!!
241  HC{ilead} = HS_EM(ispin).H(C, Orbitals.Mol);
242  SC{ilead} = HS_EM(ispin).S(C, Orbitals.Mol);
243  else
244  HC{ilead} = [];
245  SC{ilead} = [];
246  end
247  end
248 
249  HSC_t = zeros(size(HSC));
250  SSC_t = zeros(size(SSC));
251 
252 end %function
253 
254 
255 
256 
257 
258 % %Returns with element number
259 % function indx = get_atomindex(sym)
260 % Syms={'H','He','Li','Be','B','C','N','O','F','Ne','Na','Mg','Al','Si','P','S','Cl',...
261 % 'Ar','K','Ca','Sc','Ti','V','Cr','Mn','Fe','Co','Ni','Cu','Zn','Ga','Ge','As',...
262 % 'Se','Br','Kr','Rb','Sr','Y','Zr','Nb','Mo','Tc','Ru','Rh','Pd','Ag','Cd','In',...
263 % 'Sn','Sb','Te','I','Xe','Cs','Ba','La','Ce','Pr','Nd','Pm','Sm','Eu','Gd','Tb',...
264 % 'Dy','Ho','Er','Tm','Yb','Lu','Hf','Ta','W','Re','Os','Ir','Pt','Au','Hg','Tl','Pb',...
265 % 'Bi','Po','At','Rn','Fr','Ra','Ac','Th','Pa','U','Np','Pu','Am','Cm','Bk','Cf','Es','Fm','Md','No',...
266 % 'Lr','Rf','Db','Sg','Bh','Hs','Mt','Ds','Rg','Cn','Uut','Uuq','Uup','Uuh','Uus','Uuo'};
267 %
268 % indx=find(ismember(Syms,sym)==1);
269 %
270 % end
271 
272 
lead_param Leads
A list of structures lead_param containing the physical parameters for the scattering region.
Definition: structures.m:49
function Transport(Energy, B)
Calculates the conductance at a given energy value.
function Hamiltonians(varargin)
Function to create the custom Hamiltonians for the 1D chain.
A class to import custom Hamiltonians provided by other codes or created manually
Structure param contains data structures describing the physical parameters of the scattering center ...
Definition: structures.m:45