-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTDVPData.m
5010 lines (4621 loc) · 181 KB
/
TDVPData.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
classdef TDVPData
% The 'TDVPData' class is used to load, process and analyze data
% generated by VMPS/TDVP code
%
% Defines all properties of objects from class 'TDVPData'.
% They are accessed by objName.property
properties
tCalc; % t of the simulation
dt; % timesteps
t; % t of observables
tS; % t of star extraction
omega; % frequency axis for star picture
para;
tresults;
version;
nChains;
chainLabel; % Name of the Chains
sysLabel; % Name of System States
% for SBM:
alpha; % if Spin-Boson
s; % if Spin-Boson
spin; % Spin Observable
% for DPMES
CTShift; % string
% for all
lastIdx; % last Observable Idx
occC; % chain occupation
occCd; % chain occupation, diabatic projection
occCa; % chain occupation, adiabatic projection
occCc; % chain occupation, |TT><LE+| coherence projection
occS; % star occupation
xC; % chain displacement
xCd; % chain displacement, diabatic projection
xCa; % chain displacement, adiabatic projection
xCc; % chain displacement, |TT><LE+| coherence projection
xC2; % chain <x^2>
xC2d; % chain <x^2>, diabatic projection
xC2a; % chain <x^2>, adiabatic projection
xS; % star displacement
jC; % chain current
rho; % rduced density matrix
rhoOscRes; % residual of populations after exponential fit
stateProj; % state projection amplitude
sysState; % state of system
Heff; % effective potential for system
mps; % MPS and Vmat of sites 1&2
Vmat;
treeMPS; % The TreeMPS
LegLabel; %
Comment; %
folder; % for easy identification
end
methods
function obj = TDVPData(fname,varargin)
% obj = TDVPData(para,tresults)
%
% Load TDVP dataset into a TDVPData object
if nargin > 1
% TDVPData(para,tresults)
% fname = para, varargin{1} = tresults
if isstruct(fname) && isstruct(varargin{1})
temp.para = fname;
temp.tresults = varargin{1};
else
fprintf('please program me\n');
end
elseif nargin == 0
return; % empty initialization
elseif nargin == 1 && ischar(fname)
try
temp = load(fname);
% Deserialize if needed
Vars = fields(temp);
for ii = 1:size(Vars)
x = temp.(Vars{ii});
if isa(x,'uint8')
temp.(Vars{ii}) = hlp_deserialize(x);
% eval(sprintf('%s = hlp_deserialize(%s);',Vars(ii).name,Vars(ii).name));
end
end
catch err
fprintf('load failed for: %s\n',fname);
return;
end
elseif iscell(fname)
% TDVPData({file1,file2,file3,...}
% to be loaded into TDVPData array!
L = length(fname);
obj(L,1) = TDVPData();
for ii = 1:L
obj(ii) = TDVPData(fname{ii});
end
return;
end
% assign parameters
if isfield(temp, 'para') && isfield(temp,'tresults')
obj.para = temp.para;
obj.tresults = temp.tresults;
else
return
end
if isfield(obj.para.tdvp,'version')
obj.version = str2double(obj.para.tdvp.version(2:end));
else
obj.version = 0;
end
if isfield(obj.tresults,'lastIdx')
obj.lastIdx = obj.tresults.lastIdx;
else
obj.lastIdx = size(obj.tresults.nx,1);
end
if isfield(obj.tresults,'spin')
obj.spin = zeros(obj.lastIdx,3,'single'); % t x 3
obj.spin(:,1) = obj.tresults.spin.sx(1:obj.lastIdx);
obj.spin(:,2) = obj.tresults.spin.sy(1:obj.lastIdx);
obj.spin(:,3) = obj.tresults.spin.sz(1:obj.lastIdx);
end
if obj.version >= 50 && isfield(obj.tresults,'n')
obj.occC = obj.tresults.n;
elseif isfield(obj.tresults,'nx')
obj.occC = real(obj.tresults.nx);
end
if obj.version >= 72 && isfield(obj.tresults,'na')
obj.occCa = obj.tresults.na;
if isempty(obj.occC)
obj.occC = squeeze(sum(real(obj.occCa),3));
end
end
if obj.version >= 72 && isfield(obj.tresults,'nd')
obj.occCd = obj.tresults.nd;
if isempty(obj.occC)
obj.occC = squeeze(sum(real(obj.occCd),3));
end
end
if obj.version >= 72 && isfield(obj.tresults,'nc')
obj.occCc = obj.tresults.nc;
end
if obj.version >= 66 && isfield(obj.tresults,'x')
if ndims(obj.tresults.x) == 3
obj.xC = obj.tresults.x;
elseif ~isempty(strfind(obj.para.tdvp.Observables,'.x.')) % support for version <=72
obj.xCd = obj.tresults.x;
if isempty(obj.xC)
obj.xC = squeeze(sum(real(obj.xCd),3));
end
elseif ~isempty(strfind(obj.para.tdvp.Observables,'.x2.')) % support for version <=72
obj.xCa = obj.tresults.x;
if isempty(obj.xC)
obj.xC = squeeze(sum(real(obj.xCd),3));
end
end
end
if obj.version >= 72 && isfield(obj.tresults,'xa')
obj.xCa = obj.tresults.xa;
if isempty(obj.xC)
obj.xC = squeeze(sum(real(obj.xCa),3));
end
end
if obj.version >= 72 && isfield(obj.tresults,'xd')
obj.xCd = obj.tresults.xd;
if isempty(obj.xC)
obj.xC = squeeze(sum(real(obj.xCd),3));
end
end
if obj.version >= 72 && isfield(obj.tresults,'xc')
obj.xCc = obj.tresults.xc;
end
if obj.version >= 72 && isfield(obj.tresults,'x2')
obj.xC2 = obj.tresults.x2;
end
if obj.version >= 72 && isfield(obj.tresults,'x2a')
obj.xC2a = obj.tresults.x2a;
if isempty(obj.xC2)
obj.xC2 = squeeze(sum(real(obj.xC2a),3));
end
end
if obj.version >= 72 && isfield(obj.tresults,'x2d')
obj.xC2d = obj.tresults.x2d;
if isempty(obj.xC2)
obj.xC2 = squeeze(sum(real(obj.xC2d),3));
end
end
if obj.version >= 42 && isfield(obj.tresults,'t')
obj.t = obj.tresults.t;
obj.dt = max(diff(obj.tresults.t)); % important for fourier smoothing
else
obj.t = obj.para.tdvp.t;
obj.dt = max(diff(obj.t)); % important for fourier smoothing
end
obj.tCalc = obj.para.tdvp.t;
if isfield(obj.para,'nChains')
obj.nChains = obj.para.nChains;
else
obj.nChains = 1;
end
if isfield(obj.tresults,'rho')
obj.rho = obj.tresults.rho;
else
obj.rho = [];
end
obj.rhoOscRes = [];
if isfield(obj.tresults,'system') && isfield(obj.tresults.system,'state')
obj.sysState = obj.tresults.system.state;
else
obj.sysState = [];
end
% save star observables
if isfield(obj.tresults,'star')
if isfield(obj.tresults.star,'n')
obj.occS = obj.tresults.star.n;
if obj.version <= 42 && size(obj.occS,1) == length(obj.tresults.star.omega)
obj.occS = obj.occS.';
end
else
obj.occS = 0;
end
if isfield(obj.tresults.star,'x')
obj.xS = obj.tresults.star.x;
else
obj.xS = 0;
end
obj.tS = obj.tresults.star.t;
if size(obj.tresults.star.omega,1) ~= 1
obj.omega = obj.tresults.star.omega; % w x nChains
else
obj.omega = obj.tresults.star.omega.'; % w x 1
end
end
% extract simulation parameters SBM
if ~isempty(strfind(obj.para.model,'SpinBoson'))
if isa(obj.para.chain,'struct')
if isfield(obj.para,'alpha')
obj.alpha = obj.para.alpha;
end
if isfield(obj.para,'s')
obj.s = obj.para.s;
end
elseif isa(obj.para.chain,'cell')
obj.alpha = cellfun(@(x) x.alpha, obj.para.chain);
obj.s = cellfun(@(x) x.s , obj.para.chain);
end
end
if isfield(obj.tresults,'stateProjection')
obj.stateProj = obj.tresults.stateProjection;
end
if isfield(obj.tresults,'Heff')
obj.Heff = obj.tresults.Heff;
end
if isfield(obj.tresults,'mps')
obj.mps = obj.tresults.mps;
obj.tresults.mps = [];
obj.Vmat = obj.tresults.Vmat;
obj.tresults.Vmat = [];
end
if isfield(temp,'treeMPS')
obj.treeMPS = temp.treeMPS;
end
obj.chainLabel = arrayfun(@(x) sprintf('$%d$',x),1:obj.nChains,'UniformOutput',false);
obj.sysLabel = arrayfun(@(x) sprintf('$%d$',x),1:2,'UniformOutput',false); % TODO: needs fixing
if ~isempty(strfind(obj.para.model,'DPMES'))
% Need fully enclosed Latex expressions to enable embedding into other expressions.
obj.sysLabel = {'$\mathrm{TT}$','$\mathrm{LE}^+$','$\mathrm{LE}^-$','$\mathrm{CT}^+$','$\mathrm{CT}^-$'};
% any particular vars for DPMES?
temp = regexp(obj.para.folder,'CT([-.0-9]*)','tokens');
if ~isempty(temp)
obj.CTShift = temp{1}{1};
else
temp = regexp(obj.para.folder,'Delta([-.0-9]*)State','tokens');
if ~isempty(temp)
obj.CTShift = temp{1}{1};
else
obj.CTShift = 0; % give up
end
end
if strcmp(obj.para.model,'DPMES4-5C')
obj.sysLabel = {'$\mathrm{TT}$','$\mathrm{LE}^+$','$\mathrm{CT}^+$','$\mathrm{CT}^-$'};
obj.chainLabel = { '$A_{1,1}$', '$A_{1,2}$', '$B_{1}$', '$A_2$', '$B_{2}$' };
end
if strcmp(obj.para.model,'DPMES5-7C')
obj.chainLabel = { '$A_{1,1}$', '$A_{1,2}$', '$A_2$', '$B_{1}$', '$B_{2,1}$', '$B_{2,2}$', '$B_{2,3}$' };
end
if strcmp(obj.para.model,'DPMESclust7-1')
obj.chainLabel = { '$B_{1,1}$', '$B_{1,2}$', '$A_{1,1}$', '$A_{1,2}$', '$B_{2,1}$', '$B_{2,2}$', '$A_2$' };
end
if strcmp(obj.para.model,'DPMES-Tree4')
obj.chainLabel = { '$B_{1,1}$', '$B_{1,2}$', '$A_{1,1}$', '$A_{1,2}$', '$A_2$', '$B_{2,1}$', '$B_{2,2}$' };
end
if strcmp(obj.para.model,'DPMES-Tree6')
% 'B21', 'B22', 'B11', 'B12', 'B13', 'B14', 'A2', 'A11', 'A12'
obj.chainLabel = { '$B_{2,1}$', '$B_{2,2}$', '$B_{1,1}$', '$B_{1,2}$', '$B_{1,3}$', '$B_{1,4}$', '$A_2$', '$A_{1,1}$', '$A_{1,2}$' };
end
end
obj.LegLabel = '';
obj.folder = obj.para.folder;
end
function obj = setLegLabel(obj,entry)
if iscell(entry)
for i = 1:length(obj)
obj(i) = obj(i).setLegLabel(entry{i});
end
return;
end
if ~isa(entry,'string')
obj.LegLabel = num2str(entry);
else
obj.LegLabel = varName;
end
end
function obj = setComment(obj, str)
obj.Comment = str;
end
function obj = setHeffTo(obj,type)
%% obj = setHeffTo(obj,type)
% type: {'pes','tes'} to select between TES and PES in the plotting routines
%
switch type
case 'pes'
obj.Heff = obj.tresults.pes;
case 'tes'
obj.Heff = obj.tresults.Heff;
end
end
function out = gettRhoiiSystem(obj)
% DEPRECATED: Use getData('rhoii') instead
% returns the diagonal of the system reduced density matrix
out = 0;
if isfield(obj.tresults,'PPCWavefunction')
out = obj.tresults.PPCWavefunction;
elseif isfield(obj.tresults,'rho')
out = cell2mat(arrayfun(@(i) diag(squeeze(obj.tresults.rho(i,:,:))),1:size(obj.tresults.rho,1),'UniformOutput',false)).';
end
end
function out = getData(obj,type,varargin)
%% out = getData(obj,type,varargin)
% returns certain data or observables:
%
% getData('rhoii') t x dk system RDM populations
% getData('rhoii','state',n) t x 1 system RDM population of state n
%
full = 0; % truncate to simulated time - tresults.lastIdx
idxOffset = 0;
out = 0;
% Parse additional inputs
p = inputParser;
addParameter(p,'state',0,@isnumeric); % used in heff
addParameter(p,'full' ,0,@islogical);
p.addOptional('factor',0,@isnumeric);
parse(p,varargin{:});
switch lower(type)
case 'calctime'
out = obj.para.tdvp.calcTime;
idxOffset = 1;
case 'calctime-d'
out = diff(obj.para.tdvp.calcTime);
idxOffset = 2;
case 'rhoii'
if isfield(obj.tresults,'PPCWavefunction')
rhoii = obj.tresults.PPCWavefunction;
elseif isfield(obj.tresults,'rho')
rhoii = cell2mat(arrayfun(@(i) diag(squeeze(obj.tresults.rho(i,:,:))),1:obj.lastIdx,'UniformOutput',false)).';
else
warning('TDVPData:getData:rhoii','rho does not exist');
rhoii = 0;
end
out = rhoii;
h.state = p.Results.state;
if h.state ~= 0 && h.state <= size(out,2)
% return only a single state
out = out(:,h.state);
end
full = 1;
case 'rhoii-osc-res'
% oscillating residuals
plotFit = 1; % 1: plot the fitted functions into separate figure to evaluate fitness.
rhoii = abs(obj.getData('rhoii')); % t x dk(1)
out = zeros(size(rhoii));
% fit and remove exponential components to obtain the residuals
if plotFit
f = gcf;
figure; hold all; ax = gca;
plot(obj.t(1:obj.lastIdx),rhoii);
ax.ColorOrderIndex = 1; % reset to have fit in same color as original data
end
for m = 1:size(rhoii,2)
fun{1} = @(x,xdata) x(1)+x(2).*exp(x(3).*xdata); % exponential model with shift
fun{2} = @(x,xdata) x(1)+x(2).*exp(x(3).*xdata)+x(4).*exp(x(5).*xdata); % exponential model with shift
a0{1} = double([rhoii(end,m),rhoii(1,m)-rhoii(end,m),-0.01]); % initial guesses
if rhoii(1,m) == 0
a0{1}(3) = mean(diff(rhoii(100:200,m)))/obj.t(2); % rise if starting from 0
end
a0{2} = double([rhoii(end,m),rhoii(1,m)-rhoii(end,m),-0.01,rhoii(1,m)-rhoii(end,m),+0.01]); % initial guesses
for k = 1:length(fun)
[x{k},r(k),res{k}] = lsqcurvefit(fun{k},a0{k},double(obj.t(1:obj.lastIdx).'), double(rhoii(:,m)));
end
[~,ind] = min(r); % pick function with minimal residual norm;
if plotFit, plot(obj.t(1:obj.lastIdx),fun{ind}(x{ind},obj.t(1:obj.lastIdx))); end
out(:,m) = res{ind}; % save the residual
end
if plotFit, figure(f); end
full = 1;
case 'rhoii-osc-res-med'
% oscillating residuals
rhoii = abs(obj.getData('rhoii')); % t x dk(1)
% fit by smoothing and remove exponential components to obtain the residuals
out = TDVPData.movAvgRes(rhoii,170/obj.t(2)); % 170 or 350
full = 1;
case 'rhoii-osc-res-mean'
% oscillating residuals by removing DC via mean
out = TDVPData.meanRes(abs(obj.getData('rhoii')));
full = 1;
case 'rhoij'
% out{1}: t x #off-diagonal elements
% out{2}: [from,to] x #off-diagonal elements
% carries information to identify objects in out{1}
if ~isfield(obj.tresults,'rho') || isempty(obj.tresults.rho)
error('TDVPData:getData:rhoij','rho does not exist')
end
out = {};
r = obj.tresults.rho(1:obj.lastIdx,:,:);
d = size(r);
out{1} = zeros(d(1),d(2)*(d(2)-1)/2-1); % calculates number of off-diagonals
out{2} = zeros(2,size(out,2));
iC = 1;
for jj = 1:d(2)
for ii = jj:d(2)
if ii ~= jj
out{1}(:,iC) = r(:,ii,jj); % get offdiag
out{2}(:,iC) = [jj,ii];
iC = iC+1;
end
end
end
full = 1;
case 'vne'
% von Neumann Entropy = -tr(r ln r)
rdm = obj.tresults.rho; % t x i x j
out = zeros(size(rdm,1),1); % t x 1
rdm = permute(rdm,[2,3,1]); % i x j x t
for ii = 1:length(out)
out(ii) = real(-sum(sum(rdm(:,:,ii).*log(rdm(:,:,ii).'))));
end
case 'sys-env-x'
out = obj.getSysEnvObs('x'); % returns t x NC cell array; using mps(:,2), Vmat(:,2)
full = 1;
case 'sys-env-n'
out = obj.getSysEnvObs('n'); % returns t x NC cell array; using mps(:,2), Vmat(:,2)
full = 1;
case 'sz'
out = obj.tresults.spin.sz;
case 'spin'
case 'spin-ttm'
out = struct();
[sx,sy,sz] = spinop('Z');
finalT = obj.t(end)*p.Results.factor; % how far to extrapolate in time, TODO: make argument
n = round(finalT/obj.dt);
rhoT = zeros(length(obj.tresults.TTM.T)*4,1);
Esigma = zeros(n,3);
T = reshape(obj.tresults.TTM.T, 4,[]); % creates [T(1) T(2) T(3) ...]
for i = 1:n
if i == 1
rho = [1,0,0,0]';
else
rho = T*rhoT;
end
rhoT = [rho; rhoT(1:end-4)]; % prepend new vector rho(i)
rho = reshape(rho,[2,2]); % reshape rho(i) for observables
Esigma(i,1) = trace(sx*rho);
Esigma(i,2) = trace(sy*rho);
Esigma(i,3) = trace(sz*rho);
end
out.sx = real(Esigma(:,1));
out.sy = real(Esigma(:,2));
out.sz = real(Esigma(:,3));
out.t = 0:obj.dt:finalT;
return;
case 'heff-e'
% calculate energy from heff & sysState
d = size(obj.Heff); % t x D x dk x D x dk
obj.Heff = permute(reshape(obj.Heff, [d(1),d(2)*d(3), d(4)*d(5)]), [2,3,1]); % (D * dk) x (D * dk) x t
obj.sysState = reshape(permute(obj.sysState, [3,2,1]), [d(2)*d(3),d(1)]); % (D * dk) x t
out = arrayfun(@(i) (obj.sysState(:,i)'*obj.Heff(:,:,i)*obj.sysState(:,i))/(obj.sysState(:,i)'*obj.sysState(:,i)),1:obj.lastIdx);
out = real(out);
case 'heff'
assert(~isempty(obj.Heff),'Heff was not extracted in simulation');
h.state = p.Results.state;
[V,D] = arrayfun(@(i) eig(squeeze(obj.Heff(i,h.state,:,h.state,:)),'vector'),[1:obj.lastIdx]','UniformOutput',false);
D = real(cell2mat(D'))';
[D,I] = sort(D,2); % sort eigenvalues ascending, get I to sort V
V = arrayfun(@(i) V{i}(:,I(i,:)),[1:obj.lastIdx]','UniformOutput',false); % reorder eigenvectors accordingly
out = {};
out{1} = D; % t x dk_eig
out{2} = V; % t x dk x dk_eig
case 'heff-pop'
h.state = p.Results.state;
temp = obj.getData('heff','state',h.state);
D = temp{1}; V = temp{2};
% V{i}: dk x D_eig
Vtemp = cell2mat(V); % creates (dk*t) x D_eig
Vtemp = reshape(Vtemp,[size(V{1},1),length(V),size(V{1},1)]); % dk x t x D_eig
Vtemp = permute(Vtemp, [2,3,1]); % t x D_eig x dk
% obj.sysState: t x dk x D
tempState = permute(obj.sysState(1:obj.lastIdx,:,h.state),[1,3,2]); % t x 1 x dk
pop = sum(bsxfun(@times,Vtemp ,tempState),3);
pop = pop.*conj(pop); % t x dk_eig x 1
out = {};
out{1} = D; % t x dk_eig
out{2} = pop; % t x dk_eig
case 'heff-pop-diab'
h.state = p.Results.state;
temp = obj.getData('heff','state',h.state);
D = temp{1}; V = temp{2};
% V{i}: dk x D_eig
Vtemp = cell2mat(V); % creates (dk*t) x D_eig
Vtemp = reshape(Vtemp,[size(V{1},1),length(V),size(V{1},1)]); % dk x t x D_eig
Vtemp = permute(Vtemp, [2,3,1]); % t x D_eig x dk
% obj.sysState: t x dk x D
tempState = permute(obj.sysState(1:obj.lastIdx,:,h.state),[1,3,2]); % t x 1 x dk
pop = sum(bsxfun(@times,Vtemp ,tempState),3);
pop = pop.*conj(pop); % t x dk_eig x 1
pop = bsxfun(@times,(Vtemp.*conj(Vtemp)),pop); % t x dk_eig x dk
pop = permute(pop,[1,3,2]);
out = {};
out{1} = D; % t x dk_eig
out{2} = pop; % t x dk x dk_eig
case 'heff-swap'
% swaps Bond states according to matrix defined in 'state':
% h.state has to be a matrix defining: [tIdx, n1, n2], which pair of D states n1, n2 have to be swapped.
h.state = p.Results.state;
if ~ismatrix(h.state)
error('for this, h.state has to be a matrix defining: [tIdx, n1, n2], which D states have to be swapped');
end
obj2 = obj; % copy obj.
D = size(obj.sysState,3);
for ii = 0:size(h.state,1)
if ii == 0
start = 1;
stop = h.state(1,1)-1;
thisPerm = eye(D); % start off with identity matrix
else
start = stop+1;
if ii < size(h.state,1)
stop = h.state(ii+1,1)-1; % last index within this cut, should always be < obj.lastIdx
else
stop = obj.lastIdx;
end
newPerm = eye(D);
newPerm([h.state(ii,2),h.state(ii,3)],:) = newPerm([h.state(ii,3),h.state(ii,2)],:);
thisPerm = thisPerm*newPerm;
end
% apply permutation
obj2.sysState(start:stop,:,:) = contracttensors(obj.sysState(start:stop,:,:),3,3, thisPerm,2,1);
temp = contracttensors(obj.Heff(start:stop,:,:,:,:),5,2, thisPerm,2,1); % t x dk x D x dk x D,
temp = contracttensors(temp, 5,3, thisPerm,2,1); % t x dk x dk x D x D,
obj2.Heff(start:stop,:,:,:,:) = permute(temp,[1,4,2,5,3]); % t x D x dk x D x dk
end
out = obj2;
case 'heff-current'
% best on an already swapped Heff.
% calculates the transition rates / currents from one diabatic state to another
% is equivalent to evaluating all the elements which can make up the current operator j = i[H,N]
% out: t x D' x dk' x D x dk
rho_SE = bsxfun(@times, permute(conj(obj.sysState), [1 3 2]) , permute(obj.sysState, [1,4,5,3,2])); % t x D' x dk' x 1 x 1 .* t x 1 x 1 x D x dk = t x D' x dk' x D x dk
out = -2 * imag(obj.Heff(1:obj.lastIdx,:,:,:,:) .* conj(rho_SE(1:obj.lastIdx,:,:,:,:))); % is 2*Im( Tr(H rho*) )
full = 1;
case 'heff-current-squared'
% Possibly relevant for superexchange. Uses H^2
% calculates the transition rates / currents from one diabatic state to another
% is equivalent to evaluating all the elements which can make up the current operator j = i[H,N]
% out: t x D' x dk' x D x dk
rho_SE = bsxfun(@times, permute(conj(obj.sysState), [1 3 2]) , permute(obj.sysState, [1,4,5,3,2])); % t x D' x dk' x 1 x 1 .* t x 1 x 1 x D x dk = t x D' x dk' x D x dk
heffsquared = squeeze(sum(sum(bsxfun(@times, obj.Heff, permute(obj.Heff, [1,6,7,2,3,4,5])),4),5));
out = -2 * imag(heffsquared(1:obj.lastIdx,:,:,:,:) .* conj(rho_SE(1:obj.lastIdx,:,:,:,:))); % is 2*Im( Tr(H rho*) )
full = 1;
case 'heff-current-v2'
% calculates the transition rates / currents from one diabatic state to another
% is equivalent to evaluating all the elements which can make up the current operator j = i[H,N]
rho_SE = bsxfun(@times, permute(conj(obj.sysState), [1 3 2]) , permute(obj.sysState, [1,4,5,3,2])); % t x D' x dk' x 1 x 1 .* t x 1 x 1 x D x dk = t x D' x dk' x D x dk
rho_SE = rho_SE(1:obj.lastIdx,:,:,:,:);
d = size(rho_SE);
Nop = zeros(d(5)); Nop(2,2) = 1; % select which state to look at.
HN = contracttensors(obj.Heff(1:obj.lastIdx,:,:,:,:),5,5,Nop,2,1); % multiply into last dk
out = -2 * imag(HN .* conj(rho_SE)); % is 2*Im( Tr(H rho*) )
full = 1;
case 'heff-diab-state'
% Transform Heff with the Eigensystem of the LE+ staets only.
% This eliminates the coupling terms for different environment states but same system states, assuming that the trafo is similar for all system states.
% only cross-terms between different electronic states are still present
% Find and Sort EigenSystem of the LE+ Heff
% DEPRECATED: USE heff-full-diab-partdiag
assert(~isempty(obj.Heff),'Heff was not extracted in simulation');
d = size(obj.Heff); % t x D' x dk' x D x dk
obj.Heff = reshape(obj.Heff,d(1),d(2)*d(3),d(4)*d(5)); % t x D' * dk' x D * dk
% heff is 'blockdiagonal' with dk running faster than D
sub_idx = (1:d(2)) + (p.Results.state-1)*d(2);
[V,D] = arrayfun(@(i) eig(squeeze(obj.Heff(i,sub_idx,sub_idx)),'vector'),[1:obj.lastIdx]','UniformOutput',false);
D = real(cell2mat(D'))';
[D,I] = sort(D,2); % sort eigenvalues ascending, get I to sort V
V = arrayfun(@(i) kron(eye(d(2)),V{i}(:,I(i,:))),[1:obj.lastIdx]','UniformOutput',false); % reorder eigenvectors accordingly and expand to D*dk
% Transform Heff to remove coupling between same system states
heff = arrayfun(@(i) V{i}'*squeeze(obj.Heff(i,:,:))*V{i}, [1:obj.lastIdx]','UniformOutput',false);
D = arrayfun(@(i) diag(squeeze(heff{i})),1:obj.lastIdx,'UniformOutput',false);
D = real(cell2mat(D))';
% VC for V-contribution/ diabatic Character
VC = cell2mat(V); % creates (D*dk*t) x D*dk_eig
VC = reshape(VC,[size(V{1},1),length(V),size(V{1},1)]); % D*dk x t x D*dk_eig
VC = permute(VC, [3,1,2]); % D*dk_eig x D*dk x t
d = size(VC);
VC = reshape(VC, [d(1),sqrt(d(2))*[1,1], d(3)]); % D*dk_eig x D x dk x t
VC = squeeze(sum(VC.*conj(VC),2)); % D*dk_eig x dk x t
% Now: VC has percentage of dk contribution on each D*dk_eig and t
out = {};
out{1} = D; % t x D*dk_eig
out{2} = V; % t x D*dk x D*dk_eig, cell
out{3} = VC; % D*dk_eig x dk x t
case 'heff-full-nondiag'
%% Do not Diagonalise Heff
% return heff-full diagonal entries without diagonalisation
% do not sort, since this allows using plain lines with correct colors
assert(~isempty(obj.Heff),'Heff was not extracted in simulation');
d = size(obj.Heff); % t x D' x dk' x D x dk
heff = reshape(obj.Heff,d(1),d(2)*d(3),d(4)*d(5)); % t x D' * dk' x D * dk
D = arrayfun(@(i) diag(squeeze(heff(i,:,:)))',[1:obj.lastIdx]','UniformOutput',false);
D = real(cell2mat(D)); % t x D*dk
% [D,I] = sort(D,2); % sort eigenvalues ascending, get I to sort V
V = arrayfun(@(i) eye(d(2)*d(3)),[1:obj.lastIdx]','UniformOutput',false); % identity since no basis trafo! compatible with other functions!
% V = arrayfun(@(i) V{i}(:,I(i,:)),[1:obj.lastIdx]','UniformOutput',false); % Reorder to energy sorting
%% Make output
out = {};
out{1} = D; % t x D*dk
out{2} = V; % t x D*dk x D*dk_eig, cell
case 'heff-full-diab-nondiag'
% Get diabatic character of surfaces from Heff trafo
% VC: diabatic character normalised to 1
out = obj.getData('heff-full-nondiag');
D = out{1}; % t x D*dk_eig
V = out{2}; % t x D*dk x D*dk_eig, cell
% VC for V-contribution/ diabatic Character
VC = diabaticCharacter(V); % D*dk_eig x dk x t
% Now: VC has percentage of dk contribution on each D*dk_eig and t
out = {};
out{1} = D; % t x D*dk_eig
out{2} = V; % t x D*dk x D*dk_eig, cell
out{3} = VC; % D*dk_eig x dk x t
case 'heff-full-pop-nondiag'
%% return heff-full, state, population, and diabatic population without diagonalisation
out = obj.getData('heff-full-nondiag');
D = out{1}; % t x D*dk_eig
V = out{2}; % t x D*dk x D*dk_eig, cell
Vtemp = permute(cell2mat(permute(V,[2,3,1])),[3,1,2]); % t x D*dk x D*dk_eig
% obj.sysState: t x dk x D
d = size(obj.sysState); d(1) = obj.lastIdx;
tempState = permute(obj.sysState(1:obj.lastIdx,:,:),[1,3,2]); % t x D x dk
tempState = reshape(tempState, [d(1),d(2)*d(3)]); % t x D*dk
tempState = bsxfun(@times,conj(Vtemp),tempState); % t x D*dk x D*dk_eig
pop = squeeze(sum(tempState,2));
pop = pop.*conj(pop); % t x D*dk_eig
% pop is sysState rotated into adiab Basis then taken probability -> should be correct
% select popDiab2:
Vpop = Vtemp.*conj(Vtemp); % t x D*dk x D*dk_eig
Vpop = reshape(Vpop,d(1), d(2), d(3), []); % t x D x dk x D*dk_eig
Vpop = squeeze(sum(Vpop, 2)); % t x dk x D*dk_eig
popDiab = bsxfun(@times, Vpop, permute(pop, [1,3,2])); % t x dk x D*dk_eig
%% Make output
out = {};
out{1} = D; % t x D*dk
out{2} = pop; % t x D*dk
out{3} = popDiab; % t x dk x D*dk_eig
out{4} = Vtemp; % t x D*dk x D*dk_eig
case 'heff-full-partdiag'
% Transform Heff with the Eigensystem of the LE+ staets only.
% This eliminates the coupling terms for different environment states but same system states, assuming that the trafo is similar for all system states.
% only cross-terms between different electronic states are still present
% Find and Sort EigenSystem of the LE+ Heff
assert(~isempty(obj.Heff),'Heff was not extracted in simulation');
d = size(obj.Heff); % t x D' x dk' x D x dk
obj.Heff = reshape(obj.Heff,d(1),d(2)*d(3),d(4)*d(5)); % t x D' * dk' x D * dk
% heff is 'blockdiagonal' with dk running faster than D
sub_idx = (1:d(2)) + (p.Results.state-1)*d(2);
[V,D] = arrayfun(@(i) eig(squeeze(obj.Heff(i,sub_idx,sub_idx)),'vector'),[1:obj.lastIdx]','UniformOutput',false);
D = real(cell2mat(D'))';
[D,I] = sort(D,2); % sort eigenvalues ascending, get I to sort V
V = arrayfun(@(i) kron(eye(d(2)),V{i}(:,I(i,:))),[1:obj.lastIdx]','UniformOutput',false); % reorder eigenvectors accordingly and expand to D*dk
% Transform Heff to remove coupling between same system states
heff = arrayfun(@(i) V{i}'*squeeze(obj.Heff(i,:,:))*V{i}, [1:obj.lastIdx]','UniformOutput',false);
D = arrayfun(@(i) diag(squeeze(heff{i})),1:obj.lastIdx,'UniformOutput',false);
D = real(cell2mat(D))';
%% Make output
out = {};
out{1} = D; % t x D*dk
out{2} = V; % t x D*dk x D*dk_eig, cell
case 'heff-full-diab-partdiag'
% Get diabatic character of surfaces from Heff trafo
% VC: diabatic character normalised to 1
out = obj.getData('heff-full-partdiag','state',p.Results.state);
D = out{1}; % t x D*dk_eig
V = out{2}; % t x D*dk x D*dk_eig, cell
% VC for V-contribution/ diabatic Character
VC = diabaticCharacter(V); % D*dk_eig x dk x t
% Now: VC has percentage of dk contribution on each D*dk_eig and t
out = {};
out{1} = D; % t x D*dk_eig
out{2} = V; % t x D*dk x D*dk_eig, cell
out{3} = VC; % D*dk_eig x dk x t
case 'heff-full-pop-partdiag'
%% return heff-full, state, population, and diabatic population without diagonalisation
out = obj.getData('heff-full-partdiag','state',p.Results.state);
D = out{1}; % t x D*dk_eig
V = out{2}; % t x D*dk x D*dk_eig, cell
Vtemp = permute(cell2mat(permute(V,[2,3,1])),[3,1,2]); % t x D*dk x D*dk_eig
% obj.sysState: t x dk x D
d = size(obj.sysState); d(1) = obj.lastIdx;
tempState = permute(obj.sysState(1:obj.lastIdx,:,:),[1,3,2]); % t x D x dk
tempState = reshape(tempState, [d(1),d(2)*d(3)]); % t x D*dk
tempState = bsxfun(@times,conj(Vtemp),tempState); % t x D*dk x D*dk_eig
pop = squeeze(sum(tempState,2));
pop = pop.*conj(pop); % t x D*dk_eig
% pop is sysState rotated into adiab Basis then taken probability -> should be correct
% select popDiab2:
Vpop = Vtemp.*conj(Vtemp); % t x D*dk x D*dk_eig
Vpop = reshape(Vpop,d(1), d(2), d(3), []); % t x D x dk x D*dk_eig
Vpop = squeeze(sum(Vpop, 2)); % t x dk x D*dk_eig
popDiab = bsxfun(@times, Vpop, permute(pop, [1,3,2])); % t x dk x D*dk_eig
%% Make output
out = {};
out{1} = D; % t x D*dk
out{2} = pop; % t x D*dk
out{3} = popDiab; % t x dk x D*dk_eig
out{4} = Vtemp; % t x D*dk x D*dk_eig
case 'heff-full-diag'
% Diagonalise entire Heff
% Find and Sort EigenSystem of the full Heff
assert(~isempty(obj.Heff),'Heff was not extracted in simulation');
d = size(obj.Heff); % t x D' x dk' x D x dk
obj.Heff = reshape(obj.Heff,d(1),d(2)*d(3),d(4)*d(5)); % t x D' * dk' x D * dk
[V,D] = arrayfun(@(i) eig(squeeze(obj.Heff(i,:,:)),'vector'),[1:obj.lastIdx]','UniformOutput',false);
D = real(cell2mat(D'))';
[D,I] = sort(D,2); % sort eigenvalues ascending, get I to sort V
V = arrayfun(@(i) V{i}(:,I(i,:)),[1:obj.lastIdx]','UniformOutput',false); % reorder eigenvectors accordingly
out = {};
out{1} = D; % t x D*dk_eig
out{2} = V; % t x D*dk x D*dk_eig, cell
case 'heff-full-diab'
% 'heff-full-diab-diag'
% VC: diabatic character normalised to 1
out = obj.getData('heff-full-diag');
D = out{1}; % t x D*dk_eig
V = out{2}; % t x D*dk x D*dk_eig, cell
% VC for V-contribution/ diabatic Character
VC = diabaticCharacter(V); % D*dk_eig x dk x t
% Now: VC has percentage of dk contribution on each D*dk_eig and t
out = {};
out{1} = D; % t x D*dk_eig
out{2} = V; % t x D*dk x D*dk_eig, cell
out{3} = VC; % D*dk_eig x dk x t
case 'heff-full-pop'
%% Calculates the Diabatic and Adiabatic population on the HEff surfaces
% 'heff-full-pop-diag'
% Vtemp: trafo from diabat to adiabats
temp = obj.getData('heff-full-diag');
D = temp{1}; % t x D*dk_eig
V = temp{2}; % t cell x D*dk x D*dk_eig
Vtemp = permute(cell2mat(permute(V,[2,3,1])),[3,1,2]); % t x D*dk x D*dk_eig
% obj.sysState: t x dk x D
d = size(obj.sysState); d(1) = obj.lastIdx;
tempState = permute(obj.sysState(1:obj.lastIdx,:,:),[1,3,2]); % t x D x dk
tempState = reshape(tempState, [d(1),d(2)*d(3)]); % t x D*dk
tempState = bsxfun(@times,conj(Vtemp),tempState); % t x D*dk x D*dk_eig
pop = squeeze(sum(tempState,2));
pop = pop.*conj(pop); % t x D*dk_eig
% pop is sysState rotated into adiab Basis then taken probability -> should be correct
% select popDiab2:
Vpop = Vtemp.*conj(Vtemp); % t x D*dk x D*dk_eig
Vpop = reshape(Vpop,d(1), d(2), d(3), []); % t x D x dk x D*dk_eig
Vpop = squeeze(sum(Vpop, 2)); % t x dk x D*dk_eig
popDiab = bsxfun(@times, Vpop, permute(pop, [1,3,2])); % t x dk x D*dk_eig
out = {};
out{1} = D; % t x D*dk_eig
out{2} = pop; % t x D*dk_eig
out{3} = popDiab; % t x dk x D*dk_eig
out{4} = Vtemp; % t x D*dk x D*dk_eig
return;
%% Different approaches to popDiab:
% Summary:
% 1 == 4: diabatic population is correct, but distribution over adiabats wrong
% 2 == 5: adiabatic pop is correct, but division into diabats is wrong!
% 3: mixture between 1 and 2 but still wrong
% can measure similarity with norm(popDiab(:)-popDiab4(:))
% popDiab1: summing over D amplitudes before squaring for populations
popDiab1 = reshape(tempState, d(1), d(3), d(2), []); % t x D x dk x D*dk_eig
popDiab1 = squeeze(sum(popDiab1,2)); % t x dk x D*dk_eig
popDiab1 = popDiab1.*conj(popDiab1);
% divide pop into popDiab by using mapping information from V
% this yields results which do not respect inter-adiabat-coherences,
% thus are wrong when summing over D*dk_eig to recover diabat populations
Vpop = Vtemp.*conj(Vtemp); % t x D*dk x D*dk_eig
Vpop = reshape(Vpop,d(1), d(2), d(3), []); % t x D x dk x D*dk_eig
Vpop = squeeze(sum(Vpop, 2)); % t x dk x D*dk_eig
popDiab2 = bsxfun(@times, Vpop, permute(pop, [1,3,2])); % t x dk x D*dk_eig
% popDiab3: take pop and multiply with distribution of popDiab1
temp = bsxfun(@rdivide, popDiab, sum(popDiab,2)); % normalise
popDiab3 = bsxfun(@times, temp, permute(pop, [1,3,2])); % t x dk x D*dk_eig
% popDiab4: tempState^2 then sum over D; very similar to 1
popDiab4 = reshape(tempState, d(1), d(3), d(2), []); % t x D x dk x D*dk_eig
popDiab4 = popDiab4.*conj(popDiab4);
popDiab4 = squeeze(sum(popDiab4,2)); % t x dk x D*dk_eig
% popDiab5: map from adiab into dk D and trace over D; identical to 2
popDiab5 = sum(tempState,2); % t x 1 x D*dk_eig
popDiab5 = bsxfun(@times, Vtemp, popDiab5); % t x D*dk x D*dk_eig
popDiab5 = reshape(popDiab5, d(1), d(3), d(2), []); % t x D x dk x D*dk_eig
popDiab5 = squeeze(sum(popDiab5.*conj(popDiab5),2)); % t x dk x D*dk_eig
% out{3} = popDiab2; % select between 1-5
case 'heff-full-main-bonds'
% take the dominantly populated surface and derive its breakdown into bond states
% this allows estimation of participating environments
out = obj.getData('heff-full-pop');
D = out{1}; % t x D*dk_eig
pop = out{2}; % t x D*dk_eig
popDiab = out{3}; % t x dk x D*dk_eig
Vtemp = out{4}; % t x D*dk x D*dk_eig
% find which surface is dominantly populated
[maxPop,Imax] = max(pop,[],2);
% take corresponding mapping
d = size(Vtemp);
dk = size(popDiab,2);
D = d(2)/dk;
VtempNew = zeros(d(1),d(2));
for ii = 1:d(1)
VtempNew(ii,:) = Vtemp(ii,:,Imax(ii)); % t x D*dk
end
legLab = cell(d(2),1);
for ii = 1:d(2)
[mm,nn] = ind2sub([D,dk],ii);
legLab{ii} = sprintf('$|$%s,$%d\\rangle$',obj.sysLabel{nn},mm);
end
out = {};
out{1} = VtempNew; % t x D*dk
out{2} = legLab; % D*dk
case 'pes-from-tes'
% get the adiabatic states from the TES
% use these to get the corresponding PES
%% First make sure TES is selected
tes = obj.setHeffTo('tes');
tesout = tes.getData('heff-full-diab');
D = tesout{1}; % t x D*dk_eig
V = tesout{2}; % t x D*dk x D*dk_eig, cell in timesteps
VC = tesout{3}; % D*dk_eig x dk x t
% V contains map from diabatic System-Environment basis (SE) into adiabatic basis
%% Get PES into heff
pes = obj.setHeffTo('pes');
d = size(pes.Heff); % t x D' x dk' x D x dk
pes.Heff = reshape(pes.Heff,d(1),d(2)*d(3),d(4)*d(5)); % t x D' * dk' x D * dk
out = {};
out{1} = arrayfun(@(ii) V{ii}'*squeeze(pes.Heff(ii,:,:))*V{ii}, [1:pes.lastIdx]','UniformOutput',false); % t cell: D*dk_eig' x D*dk_eig
% take only diagonal of potential:
out{1} = cell2mat(cellfun(@(x) real(diag(x)'),out{1}, 'UniformOutput',false)); % t x D*dk_eig
out{2} = VC; % D*dk_eig x dk x t
case 'tes-from-pes'
% get the adiabatic states from the PES
% use these to get the corresponding TES
%% First make sure TES is selected
pes = obj.setHeffTo('pes');
pesout = pes.getData('heff-full-diab');
D = pesout{1}; % t x D*dk_eig
V = pesout{2}; % t x D*dk x D*dk_eig, cell in timesteps
VC = pesout{3}; % D*dk_eig x dk x t
% V contains map from diabatic System-Environment basis (SE) into adiabatic basis
%% Get TES into heff
tes = obj.setHeffTo('tes');
d = size(tes.Heff); % t x D' x dk' x D x dk
tes.Heff = reshape(tes.Heff,d(1),d(2)*d(3),d(4)*d(5)); % t x D' * dk' x D * dk
out = {};
out{1} = arrayfun(@(ii) V{ii}'*squeeze(tes.Heff(ii,:,:))*V{ii}, [1:tes.lastIdx]','UniformOutput',false); % t cell: D*dk_eig' x D*dk_eig
% take only diagonal of potential:
out{1} = cell2mat(cellfun(@(x) real(diag(x)'),out{1}, 'UniformOutput',false)); % t x D*dk_eig
out{2} = VC; % D*dk_eig x dk x t
case 'rho-se'
% get rho from sysState which contains correlations with the environment.
rho_SE = bsxfun(@times, permute(conj(obj.sysState), [1 3 2]) , permute(obj.sysState, [1,4,5,3,2])); % t x D' x dk' x 1 x 1 .* t x 1 x 1 x D x dk = t x D' x dk' x D x dk
% make labels
d = size(rho_SE);
legLab = cell(prod(d(2:end)),1);
for ii = 1:prod(d(2:end))
[l,m,n,o] = ind2sub(d(2:end),ii);
legLab{ii} = sprintf('$|%d\\rangle|%d\\rangle \\to |%d\\rangle|%d\\rangle$',o,n,m,l);
end
rho_SE = reshape(rho_SE,d(1),[]);
out = {};
out{1} = rho_SE(1:obj.lastIdx,:); % t x D'*dk'*D*dk
out{2} = legLab; % D'*dk'*D*dk
case 'is-heff-selfadjoint'
% 'out' contains the total absolute error of Heff-Heff' as measure of self-adjointness
d = size(obj.Heff);
heffTemp = conj(reshape(permute(obj.Heff, [1,4,5,2,3]),d(1),[])); % form hermitian conjugate; t x rest
heff = reshape(obj.Heff, d(1),[]);
out = sum(abs(heff - heffTemp),2);
full = 1;
case 'is-rho-se-selfadjoint'
% 'out' contains the total absolute error of rhoSE-rhoSE' as measure of self-adjointness
rho_SE = bsxfun(@times, permute(conj(obj.sysState), [1 3 2]) , permute(obj.sysState, [1,4,5,3,2])); % t x D' x dk' x 1 x 1 .* t x 1 x 1 x D x dk = t x D' x dk' x D x dk
d = size(rho_SE);
rho_SETemp = conj(reshape(permute(rho_SE, [1,4,5,2,3]),d(1),[])); % form hermitian conjugate; t x rest
rho_SE = reshape(rho_SE, d(1),[]);
out = sum(abs(rho_SE - rho_SETemp),2);
full = 1;
case 'is-heff-current-antisymmetric'
% 'out' contains the total absolute error of cur+cur.' as measure of anti-symmetry
cur = obj.getData('heff-current');
d = size(cur);
curTemp = reshape(permute(cur, [1,4,5,2,3]),d(1),[]); % form transpose; t x rest
cur = reshape(cur, d(1),[]);
out = sum(abs(cur + curTemp),2);
full = 1;
case 'is-heff-current-total-zero'