Eötvös Quantum Utilities  v5.0.144
Providing the Horsepowers in the Quantum Realm
Custom_Hamiltonians.m
Go to the documentation of this file.
1 %% Eotvos Quantum Transport Utilities - Custom_Hamiltonians
2 % Copyright (C) 2015-2016 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 %> @addtogroup basic Basic Functionalities
18 %> @{
19 %> @file Custom_Hamiltonians.m
20 %> @brief A class to import custom Hamiltonians provided by other codes or created manually
21 %> @}
22 %> @brief A class to import custom Hamiltonians provided by other codes or created manually
23 %> @Available
24 %> EQuUs v4.8 or later
25 %%
27 
28 properties (Access = protected )
29  %> An instance of structure param
30  param
31  %> Cell array of Hamiltonians of one slab in the leads
32  H0 = [];
33  %> Cell array of couplings between the slabs of the leads
34  H1 = [];
35  %> Cell array of transverse coupling between the unit cells of the lead
36  H1_transverse = [];
37  %> Hamiltonian of the scattering region
38  Hscatter = [];
39  %> transverse coupling for the scattering region
40  Hscatter_transverse = [];
41  %> Cell array of couplings between the scattering region and the leads
42  Hcoupling = [];
43  %> Cell array of overlap integrals of one slab in the leads
44  S0 = [];
45  %> Cell array of overlap integrals between the slabs of the leads
46  S1 = [];
47  %> overlap integrals for the transverse coupling between the unit cells of the lead
48  S1_transverse = [];
49  %> Overlap integrals of the scattering region
50  Sscatter = [];
51  %> overlap integrals for the transverse coupling in the scattering region
52  Sscatter_transverse = [];
53  %> Cell array of overlap integrals between the scattering region and the leads
54  Scoupling = [];
55  %> Cell array of coordinates of the leads
56  coordinates = [];
57  %> coordinates of the scattering region
58  coordinates_scatter = [];
59  %> logical value: true if Hamiltonians are loaded, false otherwise.
60  Hamiltonians_loaded = false;
61  %> The Fermi energy
62  EF
63  %> Function Handle for the custom Hamiltonians with identical input values as #LoadHamiltonians, and output values described in the example #Hamiltonians.
64  CustomHamiltoniansHandle
65  %> list of optional parameters (see #InputParsing for details)
66  varargin
67 end
68 
69 
70 
71 methods (Access = public )
72 
73 
74 %% Constructor of the class
75 %> @brief Constructor of the class.
76 %> @param Opt An instance of the structure #Opt.
77 %> @param param An instance of structure #param.
78 %> @param varargin Cell array of optional parameters. For details see #InputParsing.
79 %> @return An instance of the class
80 function obj = Custom_Hamiltonians( Opt, param, varargin )
81  obj = obj@Messages( Opt );
82  obj.param = param;
83  obj.varargin = varargin;
84 
85  obj.Initialize();
86 
87 end
88 
89 
90 %% LoadHamiltonians
91 %> @brief Obtain the Hamiltonians from the external source
92 %> @param varargin Cell array of optional parameters (https://www.mathworks.com/help/matlab/ref/varargin.html):
93 %> @param 'q' The transverse momentum quantum number.
94 % @param 'Extmol' The transverse momentum quantum number.
95 % @param 'GollumInput' The transverse momentum quantum number.
96 % @param 'WorkingDir' The transverse momentum quantum number.
97 function LoadHamiltonians(obj, varargin)
98 
99  p = inputParser;
100 
101  p.addParameter('q', []);
102  p.addParameter('Extmol', 'Extended_Molecule.mat');
103  p.addParameter('GollumInput', 'input.mat');
104  p.addParameter('WorkingDir', pwd);
105 
106  p.parse(varargin{:});
107 
108 
109  q = p.Results.q;
110  Extmol = p.Results.Extmol;
111  GollumInput = p.Results.GollumInput;
112  WorkingDir = p.Results.WorkingDir;
113 
114  if isempty(obj.Opt.custom_Hamiltonians)
115  % no external source is selected
116  warning(['EQuUs:', class(obj), ':LoadHamiltonians'], 'No external source was defined in the input parameters.')
117  return
118 
119  % Siesta Hamiltonians
120  elseif strcmpi( obj.Opt.custom_Hamiltonians, 'siesta' )
121 
122 
123  % Coordinatzes needs to be determined : TODO
124  [obj.H0, obj.S0, obj.H1, obj.S1, obj.coordinates, ...
125  obj.Hscatter, obj.Sscatter, obj.coordinates_scatter, obj.Hcoupling, obj.Scoupling] = obj.Siesta_Equus_interface(WorkingDir, GollumInput, Extmol);
126 
127  %!!!!!!!!!!!!!!!!!! Correct in the Gollum_Equus_interface
128  for idx = 1: length(obj.Hcoupling)
129  obj.Hcoupling{idx} = obj.Hcoupling{idx}';
130  obj.Scoupling{idx} = obj.Scoupling{idx}';
131  end
132 
133  obj.H1_transverse = cell(size(obj.H0));
134 
135  if ~issparse(obj.Hscatter)
136  obj.Hscatter = sparse(obj.Hscatter);
137  end
138 
139  if ~issparse(obj.Sscatter)
140  obj.Sscatter = sparse(obj.Sscatter);
141  end
142 
143 % obj.S1{1} = obj.S1{1}';
144 % obj.S1{2} = obj.S1{2}';
145 %
146 
147 
148  %**************************************** develpoment lines *******************************************************
149 % obj.H0{2} = obj.H0{1};
150 % obj.H1{2} = obj.H1{1};
151 % obj.Hscatter = sparse(obj.H0{1});
152 %
153 % obj.S0{2} = obj.S0{1};
154 % obj.S1{2} = obj.S1{1};
155 % obj.Sscatter = sparse(obj.S0{1});
156 
157 % obj.H0{1} = obj.H0{1} + 0.5*obj.S0{1};
158 % obj.H1{1} = obj.H1{1} + 0.5*obj.S1{1};
159 % obj.H0{2} = obj.H0{2} + speye(size(obj.H0{2}));
160 % for idx = 1:length(obj.H0)
161 % obj.S0{idx} = [];speye(size(obj.S0{idx}));
162 % obj.S1{idx} = [];sparse([],[],[], size(obj.H1{idx},1), size(obj.H1{idx},2));
163 % end
164 % obj.Sscatter = [];speye(size(obj.Hscatter));
165 % for idx =1:length(obj.Hcoupling)
166 % obj.Scoupling{idx} = [];sparse([],[],[], size(obj.Hcoupling{idx},1), size(obj.Hcoupling{idx},2));
167 % end
168 
169 
170 
171  % Custom created Hamiltonians
172  elseif strcmpi( obj.Opt.custom_Hamiltonians, 'custom' )
173 
174  if isempty(obj.CustomHamiltoniansHandle)
175  error(['EQuUs:', class(obj), ':LoadHamiltonians'], 'Undefinied function handle for the custom Hamiltonians')
176  end
177 
178  [obj.H0, obj.S0, obj.H1, obj.S1, obj.H1_transverse, obj.coordinates, ...
179  obj.Hscatter, obj.Sscatter, obj.Hscatter_transverse, obj.Sscatter_transverse, ...
180  obj.coordinates_scatter, obj.Hcoupling, obj.Scoupling] = obj.CustomHamiltoniansHandle();
181 
182  else
183  error(['EQuUs:', class(obj), ':LoadHamiltonians'], 'Undefinied option of the attribute Opt.custom_Hamiltonians')
184 
185  end
186 
187 
188  % transform Hamiltonians into grand canonical potential
189  if ~isempty( obj.EF )
190  for idx = 1:length( obj.S0 )
191  if ~isempty( obj.S0{idx} )
192  obj.H0{idx} = obj.H0{idx} - obj.EF*obj.S0{idx};
193  obj.H1{idx} = obj.H1{idx} - obj.EF*obj.S1{idx};
194  else
195  obj.H0{idx} = obj.H0{idx} - obj.EF*speye(size(obj.H0{idx}));
196  end
197  end
198 
199  for idx = 1:length( obj.Scoupling )
200  if ~isempty( obj.Scoupling{idx} )
201  obj.Hcoupling{idx} = obj.Hcoupling{idx} - obj.EF*obj.Scoupling{idx};
202  end
203  end
204 
205  if ~isempty(obj.Sscatter)
206  obj.Hscatter = obj.Hscatter - obj.EF*obj.Sscatter;
207  else
208  obj.Hscatter = obj.Hscatter - obj.EF*speye(size(obj.Hscatter));
209  end
210  end
211 
212 
213  obj.Hamiltonians_loaded = true;
214 
215 % for idx = 1:length(obj.H0)
216 % obj.S0{idx} = [];speye(size(obj.S0{idx}));
217 % obj.S1{idx} = [];sparse([],[],[], size(obj.H1{idx},1), size(obj.H1{idx},2));
218 % end
219 % obj.Sscatter = [];speye(size(obj.Hscatter));
220 % for idx =1:length(obj.Hcoupling)
221 % obj.Scoupling{idx} = [];sparse([],[],[], size(obj.Hcoupling{idx},1), size(obj.Hcoupling{idx},2));
222 % end
223 
224 end
225 
226 
227 
228 
229 
230 %% Reset
231 %> @brief Resets all elements in the object.
232  function Reset( obj )
233 
234  if strcmpi( class(obj), 'Custom_Hamiltonians' )
235  meta_data = metaclass(obj);
236 
237  for idx = 1:length(meta_data.PropertyList)
238  prop_name = meta_data.PropertyList(idx).Name;
239  if strcmp(prop_name, 'Opt') || strcmp( prop_name, 'param') || strcmp(prop_name, 'varargin')
240  continue
241  end
242  obj.Clear( prop_name );
243  end
244  end
245 
246  obj.Initialize();
247  end
248 
249 
250 
251 %% Write
252 %> @brief Sets the value of an attribute in the class.
253 %> @param MemberName The name of the attribute to be set.
254 %> @param input The value to be set.
255  function Write( obj, MemberName, input)
256 
257  if strcmp(MemberName, 'param')
258  obj.param = input;
259  obj.Reset();
260  return
261  elseif strcmp(MemberName, 'Opt')
262  obj.Opt = input;
263  obj.Reset();
264  else
265  try
266  obj.(MemberName) = input;
267  catch
268  error(['EQuUs:', class(obj), ':Read'], ['No property to write with name: ', MemberName]);
269  end
270  end
271  end
272 %% Read
273 %> @brief Query for the value of an attribute in the class.
274 %> @param MemberName The name of the attribute to be set.
275 %> @return Returns with the value of the attribute.
276  function ret = Read(obj, MemberName)
277  try
278  ret = obj.(MemberName);
279  catch
280  error(['EQuUs:', class(obj), ':Read'], ['No property to read with name: ', MemberName]);
281  end
282  end
283 %% Clear
284 %> @brief Clears the value of an attribute in the class.
285 %> @param MemberName The name of the attribute to be cleared.
286  function Clear(obj, MemberName)
287  try
288  obj.(MemberName) = [];
289  catch
290  error(['EQuUs:', class(obj), ':Clear'], ['No property to clear with name: ', MemberName]);
291  end
292 
293  end
294 
295 end % methods public
296 
297 
298 methods ( Access = private )
299 
300 %% Initialize
301 %> @brief Initializes object properties.
302  function Initialize(obj)
303 
304  obj.Hamiltonians_loaded = false;
305  obj.EF = 0;
306 
307  obj.InputParsing( obj.varargin{:} )
308  end
309 
310 %% Siesta_Equus_interface
311 %> @brief Creates the Hamiltonians and overlap integrals from the loaded data from the Siesta package.
312 %> @param Directory
313 %> @param input
314 %> @param extmol
315 %> @return ...
316  function [HL0,SL0,HL1,SL1,coordsLeads,HSC,SSC,coordsSC,HC,SC] = Siesta_Equus_interface( obj, Directory,input,extmol)
317 
318  %obj.param.scatter
319 
320  %SCATTERING REGION
321  %----------------------------------------------------------------------------------------
322  HSC=0; SSC=0;
323 
324  % bug fixed: variable atom confronting with object atom
325  % see doc. MATLAB/Octave language support for Atom at https://atom.io/packages/language-matlab
326 
327  HandleForLoad = LoadFromFile( fullfile(Directory, input) );
328  atom = HandleForLoad.LoadVariable('atom', 'NoEmpty', 'On');
329  leadp = HandleForLoad.LoadVariable('leadp', 'NoEmpty', 'On');
330  HandleForLoad.ClearLoadedVariables();
331 
332  HandleForLoad = LoadFromFile( fullfile(Directory, extmol) );
333  HSM = HandleForLoad.LoadVariable('HSM', 'NoEmpty', 'On');
334  iorb = HandleForLoad.LoadVariable('iorb', 'NoEmpty', 'On');
335  kpoints_EM = HandleForLoad.LoadVariable('kpoints_EM', 'NoEmpty', 'On');
336  nspin = HandleForLoad.LoadVariable('nspin', 'NoEmpty', 'On');
337  HandleForLoad.ClearLoadedVariables();
338 
339 
340 
341  numLead=size(leadp,1);
342  iorb = cat(2,atom(iorb(:,1),2:3),iorb); % iorb: Region PL atom-lead atom n l m z
343  norb=size(iorb,1); % Define # of orbitals
344  orb_molecule = find(iorb(:,1)==0); % Orbitals in Extended Molecule
345 
346  %STRUCTURES FOR COORDINATES
347  coordsLeads = cell( 1, length(leadp(:,1)) );
348  for i=1:length(leadp(:,1))
349  coordsLeads{i} = structures('coordinates');
350  end
351  coordsSC = structures('coordinates');
352 
353  %orb_scissors = intersect(find(iorb(:,1)==0),find(iorb(:,2)==0)); % Orbitals in Molecule
354 
355  %GATHER ORBITALS FOR LEADS
356  for lead=1:numLead % Orbitals in PLs up to TPL
357  aux = intersect(find(iorb(:,1)==lead),find(iorb(:,2)==1));
358  for PL=2:leadp(lead,1)
359  aux=cat(2,aux,intersect(find(iorb(:,1)==lead),find(iorb(:,2)==PL)));
360  end
361  switch lead
362  case(1)
363  orb1=aux;
364  case(2)
365  orb2=aux;
366  case(3)
367  orb3=aux;
368  case(4)
369  orb4=aux;
370  end;
371 
372 % coordsLeads(lead).a=1;
373 % if (size(iorb)(2)>7)
374 % coordsLeads(lead).x=iorb(aux(:,leadp(lead,2)),8);
375 % coordsLeads(lead).y=iorb(aux(:,leadp(lead,2)),9);
376 % coordsLeads(lead).z=iorb(aux(:,leadp(lead,2)),10);
377 
378 %MY WAY OF INTERPRETING THE INPUT FILE
379 % coordsLeads(lead).x=iorb(aux(leadp(lead,2)+1:leadp(lead,1)),8);
380 % coordsLeads(lead).y=iorb(aux(leadp(lead,2)+1:leadp(lead,1)),9);
381 % coordsLeads(lead).z=iorb(aux(leadp(lead,2)+1:leadp(lead,1)),10);
382  aux = [];
383  end
384 
385  %LOAD HAMILTONIANS FROM SEPARATE LEAD FILES
386  %-------------------------------------------------------------------------------
387  for lead=1:numLead
388 
389 
390  if (leadp(lead,3)~=0)
391  HandleForLoad = LoadFromFile( fullfile(Directory, ['Lead_', int2str(lead), '.mat']) );
392  HSL = HandleForLoad.LoadVariable('HSL', 'NoEmpty', 'On');
393  kpoints_Lead = HandleForLoad.LoadVariable('kpoints_Lead', 'NoEmpty', 'On');
394  HandleForLoad.ClearLoadedVariables();
395  switch lead
396  case(1)
397  HSL_1=HSL; kpoints_1=kpoints_Lead;
398  case(2)
399  HSL_2=HSL; kpoints_2=kpoints_Lead;
400  case(3)
401  HSL_3=HSL; kpoints_3=kpoints_Lead;
402  case(4)
403  HSL_4=HSL; kpoints_4=kpoints_Lead;
404  end;
405  end;
406  end
407 
408 
409 
410  for spin = 1:nspin
411  for k_EM = 1:size(kpoints_EM,1)
412  H = [];
413  S = [];
414  HL0 = [];
415  HL1 = [];
416  SL0 = [];
417  SL1 = [];
418  G = [];
419  for i=1:size(HSM,1)
420  if (find(HSM(i,1)==k_EM)) % H & S for given k & spin
421  H(HSM(i,2),HSM(i,3))=HSM(i,4+2*spin)+1.0i*HSM(i,5+2*spin);
422  S(HSM(i,2),HSM(i,3))=HSM(i,4)+1.0i*HSM(i,5);
423  end
424  end
425 % if ( scissors(1) == 1 ) % Add scissor corrections
426 % scissor_corrections;
427 % end;
428  for lead=1:numLead
429  k_choice = [];
430  kj = [];
431  HSL = [];
432  kpoints_Lead = [];
433  HL01 = [];
434  SL0t = [];
435  HL1t = [];
436  SL1t = [];
437  aux2 = [];
438 
439  if (leadp(lead,3)~=0)
440  switch lead
441  case(1)
442  HSL=HSL_1; kpoints_Lead=kpoints_1;
443  case(2)
444  HSL=HSL_2; kpoints_Lead=kpoints_2;
445  case(3)
446  HSL=HSL_3; kpoints_Lead=kpoints_3;
447  case(4)
448  HSL=HSL_4; kpoints_Lead=kpoints_4;
449  end;
450 
451  for k_Lead=1:size(kpoints_Lead,1)
452  if (abs(kpoints_EM(k_EM,1)+kpoints_Lead(k_Lead,1))<1d-6 && abs(kpoints_EM(k_EM,2)+kpoints_Lead(k_Lead,2))<1d-6)
453  k_choice=k_Lead; kj=1;
454  elseif (abs(kpoints_EM(k_EM,1)-kpoints_Lead(k_Lead,1))<1d-6 && abs(kpoints_EM(k_EM,2)-kpoints_Lead(k_Lead,2))<1d-6)
455  k_choice=k_Lead; kj=0;
456  end
457  end
458 
459  for i=1:size(HSL,1)
460  if (find(HSL(i,1)==k_choice))
461  HL0t(HSL(i,2),HSL(i,3))=HSL(i,4+2*spin) + (-1)^kj*1.0i*HSL(i,5+2*spin);
462  SL0t(HSL(i,2),HSL(i,3))=HSL(i,4) + (-1)^kj*1.0i*HSL(i,5);
463  HL1t(HSL(i,2),HSL(i,3))=HSL(i,4+2*(nspin+spin+1)) + (-1)^kj*1.0i*HSL(i,5+2*(nspin+spin+1));
464  SL1t(HSL(i,2),HSL(i,3))=HSL(i,4+2*(nspin+1)) + (-1)^kj*1.0i*HSL(i,5+2*(nspin+1));
465  end;
466  HL0{lead}=HL0t;
467  SL0{lead}=SL0t;
468  HL1{lead}=HL1t;
469  SL1{lead}=SL1t;
470 
471 
472  end;
473 
474  aux2 = intersect(find(iorb(:,1)==lead),find(iorb(:,2)==leadp(lead,2)));
475 
476 %WE HAVE TO APPLY THIS SOMEWHERE (ONLY WHEN USING SEPARATE LEAD CALCULATION)
477  correction(lead)=HL0{lead}(1,1)-H(aux2(1),aux2(1));
478  end; %if
479  end; %for numLeads
480 
481  %EM PART, THE SCATTERING REGION
482  %IN CASE OF JOSEPHSON CURRENT MODE, THIS EXCLUDES THE INTERFACE
483  %WHICH IS THE PART OF THE ELECTRODES, CLOSEST TO EM, THAT IS NOT USED
484  %FOR THE LEADS CALCULATION
485  HSC = H(orb_molecule,orb_molecule);
486  SSC = S(orb_molecule,orb_molecule);
487  p_mol=length(HSC); % Define pointers
488 
489  for lead=1:numLead
490  switch lead
491  case(1)
492  aux=orb1;
493  case(2)
494  aux=orb2;
495  case(3)
496  aux=orb3;
497  case(4)
498  aux=orb4;
499  end
500 
501  %COUPLING BETWEEN EM AND THE FRIST LEAD UNIT CELL
502  B=reshape(aux,numel(aux),1); C=aux(:,1);
503  HC{lead}=H(orb_molecule,C); %Attach coupling to Lead
504  SC{lead}=S(orb_molecule,C); %Attach coupling to Lead
505 
506  if ( leadp(lead,3) == 0 )
507  HL0{lead}=H(aux(:,leadp(lead,1)),aux(:,leadp(lead,1))); %K0=<TPL|K|TPL>
508  HL1{lead}=H(aux(:,leadp(lead,1)),aux(:,leadp(lead,1)-1)); %K1=<TPL|K|TPL-1>+coords="in"
509  SL0{lead}=S(aux(:,leadp(lead,1)),aux(:,leadp(lead,1))); %Needed to normalize states
510  SL1{lead}=S(aux(:,leadp(lead,1)),aux(:,leadp(lead,1)-1));
511  end;
512 
513 
514  end;%Lead loop
515  end %k loop
516  end % spin loop
517 
518 end %function
519 
520 
521 %% InputParsing
522 %> @brief Parses the optional parameters for the class constructor.
523 %> @param varargin Optional parameters, see the web documantation.
524 %> @param 'EF' The Fermi energy.
525 %> @param 'CustomHamiltoniansHandle' A function handle for the custom Hamiltonians with identical input values as #LoadHamiltonians, and output values described in the example #Hamiltonians.
526  function InputParsing( obj, varargin )
527 
528  p = inputParser;
529  p.addParameter('EF', []);
530  p.addParameter('CustomHamiltoniansHandle', []);
531 
532  p.parse(varargin{:});
533 
534 
535  obj.EF = p.Results.EF;
536  obj.CustomHamiltoniansHandle = p.Results.CustomHamiltoniansHandle;
537 
538 
539  end
540 
541 
542 end % methods private
543 
544 end
Structure Atom contains the atomic identifiers of the sites.
Definition: structures.m:148
A class containing methodes for displaying several standard messages.
Definition: Messages.m:24
Structure Opt contains the basic computational parameters used in EQuUs.
Definition: structures.m:60
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
A class to calculate the Green functions and self energies of a translational invariant lead The nota...
Definition: Lead.m:29
Structure param contains data structures describing the physical parameters of the scattering center ...
Definition: structures.m:45
scatter_param scatter
An instance of the structure scatter_param containing the physical parameters for the scattering regi...
Definition: structures.m:47
A class providing interface to load variables from a file.
Definition: LoadFromFile.m:24
function structures(name)