Eötvös Quantum Utilities  v5.0.144
Providing the Horsepowers in the Quantum Realm
Ribbon_Leads.m
Go to the documentation of this file.
1 %% Eotvos Quantum Transport Utilities - Ribbon
2 % Copyright (C) 2019 Peter Rakyta, 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 unit_tests Unit Tests
18 %> @{
19 %> @file Ribbon_Leads.m
20 %> @brief A class for calculations on a structure made of two connected leds.
21 %> @Available
22 %> EQuUs v5.0.144 or later
23 %> @}
24 %
25 %> @file Ribbon_Leads.m
26 %> @brief A class for calculations on a structure made of two connected leds.
27 classdef Ribbon_Leads < Ribbon
28 
29 
30  properties ( Access = public )
31  end
32 
33 
34 methods ( Access = public )
35 %% Contructor of the class
36 %> @brief Constructor of the class.
37 %> @param Opt An instance of the structure #Opt.
38 %> @param varargin Cell array of optional parameters. For details see #InputParsing.
39 %> @return An instance of the class
40  function obj = Ribbon_Leads( varargin )
41  obj = obj@Ribbon();
42 
43 
44  if strcmpi( class(obj), 'Ribbon_Leads')
45  % processing the optional parameters
46  obj.InputParsing(varargin{:})
47 
48 
49  obj.display(['EQuUs:Utils:', class(obj), ':Ribbon_Leads: Creating a Ribbon object'])
50 
51  % create the shape of the scattering region
52  obj.createShape();
53 
54  % set the Fermi level
55  obj.setFermiEnergy();
56 
57  % exporting calculation parameters into an XML format
58  createOutput( obj.filenameOut, obj.Opt, obj.param );
59 
60  % create class intances and initializing class attributes
61  obj.CreateHandles();
62 
63  % create Hamiltonians and coordinates of the unit cells
64  obj.CreateRibbon();
65  end
66 
67 
68 
69  end
70 
71 
72 
73 %% CustomDysonFunc
74 %> @brief Custom Dyson function for a general two terminal arrangement.
75 %> @param varargin Cell array of optional parameters (https://www.mathworks.com/help/matlab/ref/varargin.html):
76 %> @param 'gfininv' The inverse of the Greens function of the scattering region. For default the inverse of the attribute #G is used.
77 %> @param 'constant_channels' Logical value. Set true (default) to keep constant the number of the open channels in the leads for each energy value, or false otherwise.
78 %> @param 'onlyGinverz' Logical value. Set true to calculate only the inverse of the total Green operator, or false (default) to calculate #G as well.
79 %> @param 'recalculateSurface' A vector of the identification numbers of the lead surfaces to be recalculated.
80 %> @param 'decimate' Logical value. Set true (default) to eliminate all inner sites in the Greens function and keep only the selected sites. Set false to omit the decimation procedure.
81 %> @param 'kulso_szabfokok' Array of sites to be kept after the decimation procedure. (Use parameter 'keep_sites' instead)
82 %> @param 'selfEnergy' Logical value. Set true to use the self energies of the leads in the Dyson equation, or false (default) to use the surface Green function instead.
83 %> @param 'keep_sites' Name of sites to be kept in the resulted Green function (POssible values are: 'scatter', 'interface', 'lead').
84 %> @return [1] The calculated Greens function.
85 %> @return [2] The inverse of the Green operator.
86 %> @return [3] An instance of structure #junction_sites describing the sites in the calculated Green operator.
87  function [Gret, Ginverz, junction_sites] = CustomDysonFunc( obj, varargin )
88 
89  p = inputParser;
90  p.addParameter('gfininv', []);
91  p.addParameter('constant_channels', true);
92  p.addParameter('onlyGinverz', false );
93  p.addParameter('recalculateSurface', 1:length(obj.param.Leads) );
94  p.addParameter('decimate', true );
95  p.addParameter('kulso_szabfokok', []); %The list of sites to be left after the decimation procedure
96  p.addParameter('SelfEnergy', false); %set true to calculate the Dyson equation with the self energy
97  p.addParameter('keep_sites', 'lead'); %identification of sites to be kept (scatter, interface, lead)
98  p.parse(varargin{:});
99  gfininv = p.Results.gfininv;
100  constant_channels = p.Results.constant_channels;
101  onlyGinverz = p.Results.onlyGinverz;
102  recalculateSurface = p.Results.recalculateSurface;
103  decimate = p.Results.decimate;
104  kulso_szabfokok = p.Results.kulso_szabfokok;
105  useSelfEnergy = p.Results.SelfEnergy;
106  keep_sites = p.Results.keep_sites;
107 
108  if isempty(gfininv)
109  if ~isempty( obj.Ginv )
110  gfininv = obj.Ginv;
111  else
112  rcond_G = rcond(obj.G);
113  if isnan(rcond_G) || abs( rcond_G ) < 1e-15
114  gfininv = obj.inv_SVD( obj.G );
115  else
116  gfininv = inv(obj.G);
117  end
118  end
119  end
120 
121  if ~isempty(recalculateSurface)
122 
123  % creating interfaces for the Leads
124  if constant_channels
125  shiftLeads = ones(length(obj.param.Leads),1)*obj.E;
126  else
127  shiftLeads = ones(length(obj.param.Leads),1)*0;
128  end
129 
130  % creating objects describing the Leads
131  Leads = obj.FL_handles.LeadCalc('shiftLeads', shiftLeads, ...
132  'SelfEnergy', useSelfEnergy, 'SurfaceGreensFunction', ~useSelfEnergy, 'gauge_field', obj.gauge_field, 'leads', recalculateSurface, 'q', obj.q, ...
133  'leadmodel', obj.leadmodel, 'CustomHamiltonian', obj.cCustom_Hamiltonians);
134  else
135  Leads = obj.FL_handles.Read( 'Leads' );
136  end
137 
138 
139  Neffs = obj.FL_handles.Get_Neff();
140 
141 
142  if useSelfEnergy
143  Ginverz = CalcGinverzwithSelfEnergy();
144  else
145  Ginverz = CalcGinverz();
146  end
147 
148  junction_sites = GetJunctionSites();
149 
150  if decimate
151  GetSitesForDecimation();
152  Ginverz = obj.DecimationFunction( kulso_szabfokok, Ginverz);
153  end
154 
155 
156 
157  if onlyGinverz
158  Gret = [];
159  return
160  end
161 
162  if issparse( Ginverz )
163  err = MException(['EQuUs:Utils:', class(obj), ':CustomDysonFunc', 'Ginverz is sparse. Calculation of the inverse of a sparse matrix is not supported at this point']);
164  save('Error_Ribbon_CustomDysonFunc.mat');
165  throw(err);
166  end
167 
168  rcond_Ginverz = rcond(Ginverz);
169  if isnan( rcond_Ginverz )
170  err = MException(['EQuUs:Utils:', class(obj), ':CustomDysonFunc'], 'NaN is the condition number for Ginverz');
171  save('Error_Ribbon_CustomDysonFunc.mat');
172  throw(err);
173  end
174 
175  if abs( rcond_Ginverz ) < 1e-15
176  obj.display( ['EQuUs:Utils:', class(obj), ':CustomDysonFunc: Regularizing Ginverz by SVD'],1);
177  Gret = obj.inv_SVD( Ginverz );
178  else
179  Gret = inv( Ginverz );
180  end
181 
182  % nested functions
183 
184  %-------------------------------
185  %> calculate the inverse Greens function
186  function Ginverz = CalcGinverz()
187 
188  Gsurfinverz = cell(length(Neffs),1);
189  for idx = 1:length(Neffs)
190  Gsurfinverz{idx} = Leads{idx}.Read('gsurfinv');
191  end
192 
193  K_interface = cell(length(Neffs),1);
194  K1_sc = cell(length(Neffs),1);
195  K1adj_sc = cell(length(Neffs),1);
196  K1 = cell(length(Neffs),1);
197  K1adj = cell(length(Neffs),1);
198  for idx = 1:length(recalculateSurface)
199  obj.CreateInterface( recalculateSurface(idx) );
200  end
201  for idx = 1:length( obj.Interface_Regions )
202  [K_interface{idx}, K1{idx}, K1adj{idx}, K1_sc{idx}, K1adj_sc{idx}] = obj.Interface_Regions{idx}.Get_Effective_Hamiltonians();
203  end
204 
205  % only leads
206  %Ginverz = [Gsurfinverz{1}, -K1{1}; -K1adj{1}, Gsurfinverz{2}];
207 
208 
209  % leads and the interface region
210 
211  % leads
212  Ginverz_leads = [Gsurfinverz{1}, zeros(size(Gsurfinverz{1})); zeros(size(Gsurfinverz{1})), Gsurfinverz{2}];
213 
214  % interface region
215  Ginverz_interface = [-K_interface{1}, -K1adj{2}; -K1{2}, -K_interface{2}];
216 
217  % coupling
218  Ginverz_coupling = [ K1_sc{1}; K1_sc{2}];
219  Ginverz_coupling_adj = [ K1adj_sc{1}, K1adj_sc{2}];
220 
221  Ginverz = [Ginverz_leads, Ginverz_coupling; Ginverz_coupling_adj, Ginverz_interface];
222 
223  end
224 
225 
226  %-------------------------------
227  % calculate the inverse Greens function with the self energy
228  function Ginverz = CalcGinverzwithSelfEnergy()
229 
230  error('Not developed yet')
231 
232  end
233 
234 
235  % creating site indexes corresponding to the elements of the calculated Green operator
236  function junction_sites = GetJunctionSites()
237 
239 
240  % determine the matrix sizes
241  size_K0_leads = zeros(length(Leads), 1);
242  size_K0_interface = zeros(length(Leads), 1);
243  for kdx = 1:length(Leads)
244  K0_lead = Leads{kdx}.Get_Effective_Hamiltonians();
245  size_K0_leads(kdx) = size(K0_lead,1);
246 
247  K0_interface = obj.Interface_Regions{kdx}.Get_Effective_Hamiltonians();
248  size_K0_interface(kdx) = size(K0_interface,1);
249  end
250 
251  % determine junction sites corresponding to the scattering region
252  junction_sites.Scatter = structures('sites');
253  junction_sites.Scatter.coordinates = obj.CreateH.Read('coordinates');
254  junction_sites.Scatter.kulso_szabfokok = obj.CreateH.Read('kulso_szabfokok');
255 
256  if useSelfEnergy
257  junction_sites.Scatter.site_indexes = sum(size_K0_interface) + (1:size(gfininv,1)); %including 2*interface regions
258  else
259  junction_sites.Scatter.site_indexes = sum(size_K0_leads) + sum(size_K0_interface) + (1:size(gfininv,1)); %including 2*interface regions and 2 leads
260  end
261 
262  % determine junction sites corresponding to the interface
263  % regions and leads
264  junction_sites.Leads = cell(length(Leads),1);
265  junction_sites.Interface = cell(length(Leads),1);
266  [~, coordinates_interface] = obj.getCoordinates();
267  for kdx = 1:length(Leads)
268  junction_sites.Interface{kdx} = structures('sites');
269  junction_sites.Leads{kdx} = structures('sites');
270 
271  if useSelfEnergy
272  junction_sites.Interface{kdx}.site_indexes = sum(size_K0_interface(1:kdx-1)) + (1:size_K0_interface(kdx));
273  junction_sites.Interface{kdx}.coordinates = coordinates_interface{kdx};
274 
275  junction_sites.Leads{kdx}.site_indexes = sum(size_K0_interface(1:kdx-1)) + (1:size_K0_leads(kdx));
276  junction_sites.Leads{kdx}.coordinates = Leads{kdx}.Read('coordinates');
277  junction_sites.Leads{kdx}.kulso_szabfokok = Leads{kdx}.Read('kulso_szabfokok');
278  else
279  junction_sites.Leads{kdx}.site_indexes = sum(size_K0_leads(1:kdx-1)) + (1:size_K0_leads(kdx));
280  junction_sites.Leads{kdx}.coordinates = Leads{kdx}.Read('coordinates');
281  junction_sites.Leads{kdx}.kulso_szabfokok = Leads{kdx}.Read('kulso_szabfokok');
282 
283  junction_sites.Interface{kdx}.site_indexes = sum(size_K0_leads) + sum(size_K0_interface(1:kdx-1)) + (1:size_K0_interface(kdx));
284  junction_sites.Interface{kdx}.coordinates = coordinates_interface{kdx};
285  end
286 
287 
288 
289  end
290 
291  end
292 
293 
294  % Obtain the site indexes to be decimated out and removes the unnecesarry sites from the structure junction_sites according to the
295  % performed decimation
296  function GetSitesForDecimation()
297 
298  if isempty(kulso_szabfokok)
299  if strcmpi(keep_sites, 'scatter')
300  kulso_szabfokok = get_scatter_sites();
301 
302  junction_sites.Scatter.site_indexes = 1:length(kulso_szabfokok);
303  junction_sites.Interface = [];
304  junction_sites.Leads = [];
305 
306  elseif strcmpi(keep_sites, 'interface')
307  kulso_szabfokok = get_interface_sites();
308 
309  junction_sites.Scatter = [];
310  interface_size = 0;
311  for idx = 1:length( junction_sites.Interface )
312  junction_sites.Interface{idx}.site_indexes = interface_size + (1: length(junction_sites.Interface{idx}.site_indexes));
313  interface_size = interface_size + length(junction_sites.Interface{idx}.site_indexes);
314  end
315  junction_sites.Leads = [];
316 
317  elseif strcmpi(keep_sites, 'lead')
318  kulso_szabfokok = get_lead_sites();
319 
320  junction_sites.Scatter = [];
321  junction_sites.Interface = [];
322  leads_size = 0;
323  for idx = 1:length( junction_sites.Leads )
324  junction_sites.Leads{idx}.site_indexes = leads_size + (1: length(junction_sites.Leads{idx}.site_indexes));
325  leads_size = leads_size + length(junction_sites.Leads{idx}.site_indexes);
326  end
327  else
328  error(['EQuUs:Utils:', class(obj), ':CustomDysonFunc'], ['Undifined Sites: ', keep_sites]);
329  end
330 
331  else
332  % for custom given kulso_szabfokok
333 
334  % determine sites in the scattering center
335  junction_sites.Scatter = SelectSites( junction_sites.Scatter );
336 
337 
338  % determine sites in the interface regions
339  for idx = 1:length(junction_sites.Interface)
340  junction_sites.Interface{idx} = SelectSites( junction_sites.Interface{idx} );
341  end
342 
343 
344  % determine sites in the interface regions
345  for idx = 1:length(junction_sites.Leads)
346  junction_sites.Leads{idx} = SelectSites( junction_sites.Leads{idx} );
347  end
348 
349 
350  end
351 
352  %-------------------------------------------------------------
353  % an auxilary function to select the sites to be kept
354  function sites_ret = SelectSites( sites )
355  site_indexes_tmp = sites.site_indexes;
356  start_index = find( min(site_indexes_tmp) <= kulso_szabfokok, 1, 'first');
357  end_index = find( max(site_indexes_tmp) >= kulso_szabfokok, 1, 'last');
358 
359  if isempty(start_index)
360  sites_ret = [];
361  return
362  end
363 
364  sites_ret = structures('sites');
365  sites_ret.coordinates = sites.coordinates;
366 
367  % selecting site indexes
368  if isempty(end_index)
369  sites_ret.site_indexes = 1:length(kulso_szabfokok(start_index:end));
370  else
371  sites_ret.site_indexes = 1:length(kulso_szabfokok(start_index:end_index));
372  end
373 
374  % selecting coordinate sof the sites
375  names = fieldnames( sites.coordinates );
376  for iidx = 1:length(names)
377  fieldname = names(iidx);
378  if strcmpi( fieldname, 'a') || strcmpi( fieldname, 'b')
379  continue
380  end
381 
382  field_tmp = sites_ret.coordinates.(fieldname);
383 
384  if isempty(field_tmp)
385  continue
386  end
387 
388  if isempty(end_index)
389  field_tmp = field_tmp( kulso_szabfokok(start_index:end) - min(site_indexes_tmp) + 1 );
390  else
391  field_tmp = field_tmp( kulso_szabfokok(start_index:end_index) - min(site_indexes_tmp) + 1 );
392  end
393  sites_ret.coordinates.(fieldname) = field_tmp;
394  end
395 
396 
397  end
398 
399  end
400 
401 
402  %-------------------------------
403  % determine the site indexes of the scattering region within Ginverz
404  function kulso_szabfokok = get_scatter_sites()
405  kulso_szabfokok = junction_sites.Scatter.site_indexes;
406  end
407 
408  %-------------------------------
409  % determine the site indexes of the interface region within Ginverz
410  function kulso_szabfokok = get_interface_sites()
411  size_interface = 0;
412  for idx = 1:length( junction_sites.Interface )
413  size_interface = size_interface + length(junction_sites.Interface{idx}.site_indexes);
414  end
415 
416  kulso_szabfokok = zeros( size_interface, 1);
417  size_interface = 0;
418  for idx = 1:length( junction_sites.Interface )
419  indexes = size_interface + ( 1:length(junction_sites.Interface{idx}.site_indexes) );
420  kulso_szabfokok(indexes) = junction_sites.Interface{idx}.site_indexes;
421  size_interface = size_interface + length(junction_sites.Interface{idx}.site_indexes);
422  end
423 
424  end
425 
426  %-------------------------------
427  % determine the site indexes of the leads within Ginverz
428  function kulso_szabfokok = get_lead_sites()
429 
430  size_leads = 0;
431  for idx = 1:length( junction_sites.Leads )
432  size_leads = size_leads + length(junction_sites.Leads{idx}.site_indexes);
433  end
434 
435  kulso_szabfokok = zeros( size_leads, 1);
436  size_leads = 0;
437  for idx = 1:length( junction_sites.Leads )
438  indexes = size_leads + ( 1:length(junction_sites.Leads{idx}.site_indexes) );
439  kulso_szabfokok(indexes) = junction_sites.Leads{idx}.site_indexes;
440  size_leads = size_leads + length(junction_sites.Leads{idx}.site_indexes);
441  end
442 
443 
444  end
445 
446  % end nested functions
447 
448  end
449 
450 
451 
452 %% CreateClone
453 %> @brief Creates a clone of the present object.
454 %> @return Returns with the cloned object.
455  function ret = CreateClone( obj )
456 
457  ret = Ribbon_Leads( 'width', obj.width, ...
458  'height', obj.height, ...
459  'filenameIn', obj.filenameIn, ...
460  'filenameOut', obj.filenameOut, ...
461  'E', obj.E, ...
462  'EF', 0, ...
463  'phi', obj.phi, ...
464  'silent', obj.silent, ...
465  'transversepotential', obj.transversepotential, ...
466  'Opt', obj.Opt, ...
467  'param', obj.param, ...
468  'q', obj.q, ...
469  'leadmodel', obj.leadmodel, ...
470  'interfacemodel', obj.interfacemodel);
471 
472  ret.EF = obj.EF;
473  ret.CreateH = obj.CreateH.CreateClone();
474  ret.FL_handles = obj.FL_handles.CreateClone();
475  ret.Scatter_UC = obj.Scatter_UC.CreateClone();
476  ret.Interface_Regions = cell(size(obj.Interface_Regions));
477  for idx = 1:length(obj.Interface_Regions)
478  ret.Interface_Regions{idx} = obj.Interface_Regions{idx}.CreateClone();
479  end
480  if ~isempty( obj.PeierlsTransform_Scatter )
481  ret.PeierlsTransform_Scatter = obj.PeierlsTransform_Scatter.CreateClone();
482  end
483 
484  if ~isempty( obj.PeierlsTransform_Leads )
485  ret.PeierlsTransform_Leads = obj.PeierlsTransform_Leads.CreateClone();
486  end
487  ret.gauge_field = obj.gauge_field; % function handle for the scalar field to transform the vector potential from Landauy to Landaux
488 
489  end
490 
491 
492 end % methods public
493 
494 
495 methods (Access=protected)
496 
497 
498 %% InputParsing
499 %> @brief Parses the optional parameters for the class constructor.
500 %> @param varargin Cell array of optional parameters (https://www.mathworks.com/help/matlab/ref/varargin.html):
501 %> @param 'width' Integer. The number of the nonsingular atomic sites in the cross section of the ribbon.
502 %> @param 'height' Integer. The height of the ribbon in units of the lattice vector.
503 %> @param 'filenameIn' The input filename containing the computational parameters. (Use parameters 'Op' and 'param' instead)
504 %> @param 'filenameOut' The output filename to export the computational parameters.
505 %> @param 'WorkingDir' The absolute path to the working directoy.
506 %> @param 'E' The energy value used in the calculations (in the same units as the Hamiltonian).
507 %> @param 'EF' The Fermi energy in the same units as the Hamiltonian. Attribute #E is measured from this value. (Use for equilibrium calculations in the zero temperature limit. Overrides the one comming from the external source)
508 %> @param 'silent' Set true to suppress output messages.
509 %> @param 'transversepotential' A function handle pot = f( #Coordinates ) or pot=f( #CreateLeadHamiltonians, Energy) of the transverse potential applied in the lead. (Instead of #CreateLeadHamiltonians can be used its derived class)
510 %> @param 'leadmodel' A function handle #Lead=f( idx, E, varargin ) of the alternative lead model with equivalent inputs and return values as #Transport_Interface.SurfaceGreenFunctionCalculator and with E standing for the energy.
511 %> @param 'interfacemodel' A function handle f( #InterfaceRegion ) to manually adjus the interface regions. (Usefull when 'leadmodel' is also given. For example see @InterfaceModel)
512 %> @param 'Opt' An instance of the structure #Opt.
513 %> @param 'param' An instance of the structure #param.
514 %> @param 'q' The transverse momentum quantum number.
515  function InputParsing( obj, varargin )
516  % calling the input parsing of the superclass
517  InputParsing@Ribbon( obj, varargin{:});
518 
519  end
520 
521 end % methdos protected
522 
523 
524 
525 end
Structure Opt contains the basic computational parameters used in EQuUs.
Definition: structures.m:60
Structure shape contains data about the geometry of the scattering region.
Definition: structures.m:106
Class to create and store Hamiltonian of the translational invariant leads.
A class for calculations on a ribbon of finite width for equilibrium calculations mostly in the zero ...
Definition: Ribbon.m:34
sites Interface
Structure sites describing the geometry of the interface regions.
Definition: structures.m:182
function Transport(Energy, B)
Calculates the conductance at a given energy value.
A class to evaluate the Dyson equation and to calculate the scattering matrix for equilibrium process...
function Hamiltonians(varargin)
Function to create the custom Hamiltonians for the 1D chain.
function createOutput(filename, Opt, param)
This function creates an output file containing the running parameters.
function Landauy(x, y, eta_B)
Vector potential in the Landau gauge parallel to the y direction.
kulso_szabfokok
An array containing the site indexes connected to other parts.
Definition: structures.m:193
A class describing the interface region between the scattering region and a lead.
A class to calculate the Green functions and self energies of a translational invariant lead The nota...
Definition: Lead.m:29
function InterfaceModel(Interface_Region)
Method to adjust the Hamiltonians of the interface regions.
Structure param contains data structures describing the physical parameters of the scattering center ...
Definition: structures.m:45
site_indexes
An array containing the site indexes of the given system part.
Definition: structures.m:191
Structure sites contains data to identify the individual sites in a matrix.
Definition: structures.m:187
sites Leads
Structure sites describing the geometry of the leads.
Definition: structures.m:178
function Landaux(x, y, eta_B, Aconst, height, lattice_constant)
Vector potential in the Landau gauge parallel to the x direction.
function SurfaceGreenFunctionCalculator(idx, varargin)
Calculates the surface Green's function or the self energy of a Lead.
function gauge_field(x, y, eta_B, Aconst, height, lattice_constant)
Scalar gauge field connecting Landaux and Landauy gauges.
coordinates
An instance of structure coordinates describing the geometry.
Definition: structures.m:189
sites Scatter
Structure sites describing the geometry of the scattering region.
Definition: structures.m:180
Structure containing the coordinates and other quantum number identifiers of the sites in the Hamilto...
Definition: Coordinates.m:24
function structures(name)
Structure junction_sites contains data to identify the individual sites of the leads,...
Definition: structures.m:176