-
Notifications
You must be signed in to change notification settings - Fork 1
/
Green.f90
3360 lines (3063 loc) · 145 KB
/
Green.f90
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
program GREEN
implicit none
integer :: NUMKX, NUMKY, NUMKZ, NUMK, NUMT, io, i, j, IRLATT, IRLATTMAX, kcounter, LWORK, INFO, NCELLS, &
&NUMIMP, NUMCHEMTYPES, JATOM, rcheck, MAXNEIGHB, NPNT, NPNT1, NPNT2, NPNT3, &
&NPOL, NUMEDOS, ZEROPOL, IEMXD, IEMXDZ, FTIMO
integer, allocatable, dimension(:) :: CHEMTYPE, NEIGHBNUM
integer, allocatable, dimension(:,:) :: IMPPTSVAR, JTYPE
real*8 :: ALAT, a_1(3), a_2(3), a_3(3), RMAX, R0, KPOINT(3), RPOINT(3), TTPRIME(3), ENERGY, EMIN,&
&chempot, T, TBROD, PI, KB, b_1(3), b_2(3), b_3(3), etados, lambda, TOL, tempvalre, tempvalim, EBOT, EMU
real*8, allocatable, dimension(:) :: W, RWORK, E0, ULCN, nu, nuzero, magnet, VSUPCOND
real*8, allocatable, dimension(:,:) :: KPTS, TPTS, EIGENVALUES, RLATT, BETA, LHOPS, PREFACTORS, HOPPVALS
real*8, allocatable, dimension(:,:,:) :: RCONNECT
complex*16 :: CI, IdentityPauli(2,2), xPauli(2,2), yPauli(2,2), zPauli(2,2), tempparam
complex*16, allocatable, dimension(:) :: WORK, DELTA, DF, EZ, DFDOS, EZDOS
complex*16, allocatable, dimension(:,:) :: HAMILTONIAN, HAMILTONIANPREP
complex*16, allocatable, dimension(:,:,:) :: EXPONS, EIGENVECTORS
character(len = 1) :: yesorno, vecorints, dosorno, magorno
character(len = 4) :: fullorp
TOL = 0.0001 ! The fault tolerance for lattice vectors' norms
call CONSTANTS(IdentityPauli,xPauli,yPauli,zPauli,CI,PI,KB)
open(1, file = 'config.dat', action = 'read')
read(1,*) ALAT
read(1,*) a_1
read(1,*) a_2
read(1,*) a_3
read(1,*) NUMKX,NUMKY,NUMKZ
read(1,*) RMAX
read(1,*) R0
read(1,*) NCELLS
read(1,*) T
read(1,*) ! chempot
read(1,*) ! inicharge
read(1,*) ! inidelta
read(1,*) ! mixfactorN
read(1,*) ! mixfactorD
read(1,*) NUMEDOS
read(1,*) etados
read(1,*) ! metalepsilon
read(1,*) ! scepsilon
close(1)
! This is because the lattice vectors are inserted through Bravais coordinates
a_1 = ALAT*a_1
a_2 = ALAT*a_2
a_3 = ALAT*a_3
IRLATTMAX = (2*NCELLS+1)**3 ! Configures how many neighbouring cells are taken into account
call BZ(a_1,a_2,a_3,NUMKX,NUMKY,NUMKZ,PI,KPTS,NUMK,b_1,b_2,b_3) ! We create the Brillouin Zone's k-points to be used later on
! The following reads the number of basis vectors from a file named basisvectors.dat
NUMT = 0
open (2, file = 'basisvectors.dat', action = 'read')
do
read(2,*,iostat=io)
if (io/=0) exit
NUMT = NUMT + 1
end do
close(2)
NUMT = NUMT - 2 ! To ignore the final 2 lines in basisvectors.dat which are the configuration settings.
allocate(TPTS(3,NUMT))
allocate(E0(NUMT))
allocate(ULCN(NUMT)) ! NUMT x 1 column with the U_LCN constant for each basis atom
allocate(nuzero(NUMT)) ! NUMT x 1 column with the charges n_0 of each basis atom
allocate(nu(NUMT)) ! NUMT x 1 column with the charges n of each basis atom
allocate(BETA(3,NUMT)) ! NUMT x 3 matrix with the B_x, B_y, B_z for each basis atom
allocate(DELTA(NUMT))
allocate(magnet(NUMT))
allocate(VSUPCOND(NUMT))
allocate(CHEMTYPE(NUMT)) ! Disciminates between different chemical elements
open (1, file = 'basisvectors.dat', action = 'read')
do i = 1, NUMT
read(1,*) TPTS(1:3,i), CHEMTYPE(i), E0(i), ULCN(i), nuzero(i), BETA(1,i), BETA(2,i), BETA(3,i), VSUPCOND(i)
end do
close(1)
open (1, file = 'scresults.dat', action = 'read')
read(1,*) chempot
do i = 1, NUMT
read(1,*) nu(i), magnet(i), tempvalre, tempvalim
DELTA(i) = dcmplx(tempvalre, tempvalim)
end do
close(1)
NUMCHEMTYPES = MAXVAL(CHEMTYPE)
allocate(LHOPS(NUMCHEMTYPES,NUMCHEMTYPES))
allocate(PREFACTORS(NUMCHEMTYPES,NUMCHEMTYPES))
! The *4 factors are now due to spin and particle-hole
allocate(EIGENVECTORS(4*NUMT,4*NUMT,NUMK))
allocate(EIGENVALUES(4*NUMT,NUMK))
allocate(HAMILTONIAN(4*NUMT,4*NUMT))
allocate(HAMILTONIANPREP(4*NUMT,4*NUMT))
call RPTS(a_1,a_2,a_3,NCELLS,RLATT,IRLATTMAX) ! Here we construct the RLATT Matrix consisting of the lattice sites
call HOPPS(RLATT,IRLATTMAX,R0,NUMCHEMTYPES,LHOPS,NUMT,CHEMTYPE,TPTS,PREFACTORS)
!The following are for the configuration of zheev. The *4 factors are due to spin and particle-hole
!-------------------------------------------------
allocate(W(4*NUMT))
allocate(RWORK(3*(4*NUMT) - 2))
LWORK = 4*NUMT*(4*NUMT+1)
allocate(WORK(LWORK))
!-------------------------------------------------
! That part calculates the number of neighbours that belong in the ith atom's cluster, excluding itself
allocate(NEIGHBNUM(NUMT))
NEIGHBNUM(1:NUMT) = 0
do i = 1, NUMT
do j = 1, NUMT
TTPRIME = TPTS(1:3,j) - TPTS(1:3,i)
do IRLATT = 1, IRLATTMAX
RPOINT = RLATT(1:3,IRLATT)
if (norm2(RPOINT+TTPRIME) < (RMAX+TOL) .and. norm2(RPOINT+TTPRIME) > TOL) then
NEIGHBNUM(i) = NEIGHBNUM(i) + 1
end if
end do
end do
end do
! This part catalogues all the nearest neighbour distances for each atom i, while also listing
! what type of neighbours they are, excluding the on-site interaction
MAXNEIGHB = MAXVAL(NEIGHBNUM)
allocate(JTYPE(MAXNEIGHB,NUMT))
allocate(RCONNECT(3,MAXNEIGHB,NUMT))
RCONNECT(1:3,:,:) = 0.0
JTYPE(:,:) = 0
do i = 1, NUMT
rcheck = 1
do j = 1, NUMT
TTPRIME = TPTS(1:3,j) - TPTS(1:3,i)
do IRLATT = 1, IRLATTMAX
RPOINT = RLATT(1:3,IRLATT)
if (norm2(RPOINT+TTPRIME) < (RMAX+TOL) .and. norm2(RPOINT+TTPRIME) > TOL) then
RCONNECT(1:3,rcheck,i) = RPOINT + TTPRIME
JTYPE(rcheck,i) = j
rcheck = rcheck + 1
end if
end do
end do
end do
! We finally calculate the hopping elements, as well as the fourier exponentials, so that we don't have to calculate
! them after every self-consistency cycle.
allocate(EXPONS(NUMK,MAXNEIGHB,NUMT))
allocate(HOPPVALS(MAXNEIGHB,NUMT))
do kcounter = 1, NUMK
KPOINT = KPTS(1:3,kcounter)
do i = 1, NUMT
do j = 1, NEIGHBNUM(i)
RPOINT = RCONNECT(1:3,j,i)
EXPONS(kcounter,j,i) = exp(-CI*DOT_PRODUCT(KPOINT,RPOINT))
JATOM = JTYPE(j,i)
lambda = PREFACTORS(CHEMTYPE(i),CHEMTYPE(JATOM))
HOPPVALS(j,i) = -lambda*exp(-norm2(RPOINT)/R0)
end do
end do
end do
print *, 'Initiating the diagonalization of the Hamiltonian...'
! Run the Hamiltonian to evaluate the Eigenvalues and Eigenvectors to be used for the Green calculation.
call HAMPREP(NUMT,xPauli,yPauli,zPauli,IdentityPauli,chempot,E0,ULCN,nu,nuzero,BETA,DELTA,HAMILTONIANPREP)
do kcounter = 1, NUMK
call FOURIERHAM(kcounter,NUMK,HAMILTONIANPREP,EXPONS,HOPPVALS,NEIGHBNUM,JTYPE,MAXNEIGHB,NUMT,HAMILTONIAN)
call zheev ('V', 'U', 4*NUMT, HAMILTONIAN, 4*NUMT, W, WORK, LWORK, RWORK, INFO)
EIGENVALUES(:,kcounter) = W
EIGENVECTORS(:,:,kcounter) = HAMILTONIAN
end do
do i = 1, NUMT
nu(i) = 0.d0
DELTA(i) = (0.d0,0.d0)
FTIMO = 4*(i-1)
do kcounter = 1, NUMK
do j = 1, 4*NUMT
ENERGY = EIGENVALUES(j,kcounter)
nu(i) = nu(i) + FERMI(ENERGY,T,KB)*abs(EIGENVECTORS(i,j,kcounter))**2 +&
& FERMI(ENERGY,T,KB)*abs(EIGENVECTORS(i+NUMT,j,kcounter))**2
DELTA(i) = DELTA(i) -FERMI(ENERGY,T,KB)*VSUPCOND(i)*&
&EIGENVECTORS(i,j,kcounter)*CONJG(EIGENVECTORS(i+3*NUMT,j,kcounter))
end do
end do
nu(i) = nu(i)/NUMK
DELTA(i) = DELTA(i)/NUMK
end do
print *, 'Diagonalization finished and eigenvectors/eigenvalues stored.'
print *, 'We proceed with the setup of the energies to be used for the calculation of G.'
open(1, file = 'greenconfig.dat', action = 'read')
read(1,*) NPOL
read(1,*) dosorno
read(1,*) NPNT1
read(1,*) NPNT2
read(1,*) NPNT3
read(1,*) EBOT
read(1,*) vecorints
read(1,*) fullorp
read(1,*) magorno
close(1)
call IDENTIFIER(vecorints,b_1,b_2,b_3,PI,a_1,a_2,a_3,TPTS,NUMT,NUMIMP,IMPPTSVAR)
if (EBOT == -100.0) then
EBOT = MINVAL(EIGENVALUES) - 0.5 ! The - 0.5 factor is inserted to avoid broadening cutoffs
endif
IEMXD = (NPNT1+NPNT2+NPNT3+NPOL)*2 ! In order to setup the EZ and DF arrays
allocate(DF(IEMXD))
allocate(EZ(IEMXD))
! If NPOL == 0 we check if the user wants to perform a DoS calculation apart from the other calculations.
if (NPOL /= 0 .and. dosorno == 'y') then
ZEROPOL = 0
TBROD = etados/(KB*PI)
IEMXDZ = NUMEDOS*2
allocate(DFDOS(IEMXDZ))
allocate(EZDOS(IEMXDZ))
print *, 'It appears that you want to perform a DoS calculation apart from the other calculations.'
print *, 'Should the minimum energy for the DoS be the same as EBOT ? y/n'
171 read *, yesorno
if (yesorno == 'y') then
EMIN = EBOT
else if (yesorno == 'n') then
print *, 'Please enter the minimum energy to be used for the DoS.'
read *, EMIN
else
print *, 'Invalid input. Please enter y or n.'
goto 171
endif
print *, 'Should the maximum eigenvalue of the spectrum be used as the maximum energy? y/n'
172 read *, yesorno
if (yesorno == 'y') then
EMU = MAXVAL(EIGENVALUES) + 0.5 ! The + 0.5 factor is inserted to avoid broadening cutoffs
else if (yesorno == 'n') then
print *, 'Please enter the maximum energy to be used for the DoS.'
read *, EMU
else
print *, 'Invalid input. Please enter y or n.'
goto 172
endif
call EMESHT(EZDOS,DFDOS,NPNT,EMIN,EMU,TBROD,ZEROPOL,NPNT1,NUMEDOS,NPNT3,PI,KB,IEMXDZ)
NUMEDOS = NPNT ! To be written later on the file impconfig.dat
open(1, file = 'energiesfordos.dat', action = 'write')
do i = 1, NPNT
tempparam = EZDOS(i)
write (1, '(2F17.8)') REAL(tempparam), AIMAG(tempparam)
end do
close(1)
print *, 'Energies and weights printed. Initiating Green functions DoS calculations.'
if (fullorp == 'full') then
call FULLGREEN(EIGENVALUES,EIGENVECTORS,NUMT,NUMK,PI,TPTS,a_1,a_2,a_3,KPTS,NUMIMP,IMPPTSVAR,NPNT,ZEROPOL)
else
call PARTIALGREEN(EIGENVALUES,EIGENVECTORS,NUMT,NUMK,TPTS,a_1,a_2,a_3,KPTS,NUMIMP,IMPPTSVAR,NPNT,ZEROPOL)
endif
print *, 'DoS calculated.'
print *, 'We proceed with the setup of the energies to be used for the contours.'
endif
EMU = 0.0 ! Because we are studying superconductivity
call EMESHT(EZ,DF,NPNT,EBOT,EMU,T,NPOL,NPNT1,NPNT2,NPNT3,PI,KB,IEMXD)
open(1, file = 'energies.dat', action = 'write')
do i = 1, NPNT
tempparam = EZ(i)
write (1, '(2F17.8)') REAL(tempparam), AIMAG(tempparam)
end do
close(1)
open(1, file = 'fermiweights.dat', action = 'write')
do i = 1, NPNT
tempparam = DF(i)
write (1, '(2F17.8)') REAL(tempparam), AIMAG(tempparam)
end do
close(1)
print *, 'Energies and weights printed.'
print *, 'Initiating Green functions calculations.'
if (fullorp == 'full') then
call FULLGREEN(EIGENVALUES,EIGENVECTORS,NUMT,NUMK,PI,TPTS,a_1,a_2,a_3,KPTS,NUMIMP,IMPPTSVAR,NPNT,NPOL)
else
call PARTIALGREEN(EIGENVALUES,EIGENVECTORS,NUMT,NUMK,TPTS,a_1,a_2,a_3,KPTS,NUMIMP,IMPPTSVAR,NPNT,NPOL)
endif
! Prepares two config files to be used by the impurity program
open (1, file = 'impconfig.dat', action = 'write')
write (1,*) NUMIMP, '! Number of impurities.'
write (1,*) NPNT, '! Number of energy values.'
write (1,*) NUMEDOS, '! Number of energy values for the DoS.'
write (1,*) ' n ! y to print G_imp elements on a file and n to ignore.'
write (1,*) ' 0.00001 ! epsilon for impurity self-consistency.'
do i = 1, NUMIMP
j = IMPPTSVAR(4,i)
write (1,'(3F15.9, A, I7)') nu(j), REAL(DELTA(j)), AIMAG(DELTA(j)), ' ! n and D for atom No. ', i
end do
close(1)
if (magorno == 'n') then
open (1, file = 'impatoms.dat', action = 'write')
do i = 1, NUMIMP
j = IMPPTSVAR(4,i)
write (1,'(7F15.9, A, I7)') E0(j), BETA(1,j), BETA(2,j), BETA(3,j), VSUPCOND(j), ULCN(j), nuzero(j),&
& ' ! Host No. ', i
write (1,'(7F15.9, A, I7)') E0(j), BETA(1,j), BETA(2,j), BETA(3,j), VSUPCOND(j), ULCN(j), nuzero(j),&
& ' ! Impurity No. ', i
end do
write (1,'(A)') '---------------------------------------------------------------------------------------&
&-------------------'
write (1,'(A)') 'Format: E_0, B_x, B_y, B_z, V,&
& U, n_0'
close(1)
else
call MAGCHAIN(NUMT,NUMIMP,PI,E0,BETA,VSUPCOND,ULCN,nuzero,IMPPTSVAR)
endif
contains
subroutine MAGCHAIN(NUMT,NUMIMP,PI,E0,BETA,VSUPCOND,ULCN,nuzero,IMPPTSVAR)
implicit none
integer :: NUMT, NUMIMP, num, denom, i, IMPPTSVAR(4,NUMIMP)
real*8 :: ROTAXIS(3), theta, E0(NUMT), BETA(3,NUMT), NEWBETA(3,NUMIMP), PI, magB, initheta, TOL, VSUPCONDIMP(NUMT),&
&ROTMATRIX(3,3), INBETA(3), OUTBETA(3), one, zero, sine, cosine, ULCN(NUMT), nuzero(NUMT), VSUPCOND(NUMT)
TOL = 0.000001 ! The tolerance for the "if" checks.
print *, 'Preparing the magnetic chain inputs.'
open(1, file = 'greenconfig.dat', action = 'read')
do i = 1, 9
read(1,*)
end do ! Skips the file's first 9 lines
read(1,*) ROTAXIS
read(1,*) num, denom
close(1)
theta = (num*PI)/denom
if (abs(ROTAXIS(1) - 1.0) < TOL .and. abs(ROTAXIS(2)) < TOL .and. abs(ROTAXIS(3)) < TOL) then
! This is a rotation equivalent to a rotation by the x-axis (i.e. in the y-z plane)
print *, 'Please enter the starting angle with respect to the z-axis.'
print *, 'Format a*PI/b, with a, b: integers. Please enter a.'
read *, num
print *, 'Please enter b.'
read *, denom
initheta = (num*PI)/denom
print *, 'Please enter the magnitude of B.'
read *, magB
do i = 1, NUMIMP
if (i == 1) then
NEWBETA(1,i) = 0.0
NEWBETA(2,i) = magB*SIN(initheta)
NEWBETA(3,i) = magB*COS(initheta)
else
NEWBETA(1,i) = 0.0
NEWBETA(2,i) = magB*SIN(initheta + (i-1)*theta)
NEWBETA(3,i) = magB*COS(initheta + (i-1)*theta)
endif
end do
else if (abs(ROTAXIS(1)) < TOL .and. abs(ROTAXIS(2) - 1.0) < TOL .and. abs(ROTAXIS(3)) < TOL) then
! This is a rotation equivalent to a rotation by the y-axis (i.e. in the x-z plane)
print *, 'Please enter the starting angle with respect to the x-axis.'
print *, 'Format a*PI/b, with a, b: integers. Please enter a.'
read *, num
print *, 'Please enter b.'
read *, denom
initheta = (num*PI)/denom
print *, 'Please enter the magnitude of B.'
read *, magB
do i = 1, NUMIMP
if (i == 1) then
NEWBETA(1,i) = magB*COS(initheta)
NEWBETA(2,i) = 0.0
NEWBETA(3,i) = magB*SIN(initheta)
else
NEWBETA(1,i) = magB*COS(initheta + (i-1)*theta)
NEWBETA(2,i) = 0.0
NEWBETA(3,i) = magB*SIN(initheta + (i-1)*theta)
endif
end do
else if (abs(ROTAXIS(1)) < TOL .and. abs(ROTAXIS(2)) < TOL .and. abs(ROTAXIS(3) - 1.0) < TOL) then
! This is a rotation equivalent to a rotation by the z-axis (i.e. in the x-y plane)
print *, 'Please enter the starting angle with respect to the x-axis.'
print *, 'Format a*PI/b, with a, b: integers. Please enter a.'
read *, num
print *, 'Please enter b.'
read *, denom
initheta = (num*PI)/denom
print *, 'Please enter the magnitude of B.'
read *, magB
do i = 1, NUMIMP
if (i == 1) then
NEWBETA(1,i) = magB*COS(initheta)
NEWBETA(2,i) = magB*SIN(initheta)
NEWBETA(3,i) = 0.0
else
NEWBETA(1,i) = magB*COS(initheta + (i-1)*theta)
NEWBETA(2,i) = magB*SIN(initheta + (i-1)*theta)
NEWBETA(3,i) = 0.0
endif
end do
else
! This is the case where we want to rotate B along an arbitrary axis.
print *, 'Please enter the value of B for the first atom of the chain. Format Bx,By,Bz.'
read *, NEWBETA(:,1)
cosine = COS(theta)
sine = SIN(theta)
! This sets up the rotation matrix.
ROTMATRIX(1,1) = cosine + ROTAXIS(1)**2*(1.0-cosine)
ROTMATRIX(1,2) = ROTAXIS(1)*ROTAXIS(2)*(1.0-cosine) - ROTAXIS(3)*sine
ROTMATRIX(1,3) = ROTAXIS(1)*ROTAXIS(3)*(1.0-cosine) + ROTAXIS(2)*sine
ROTMATRIX(2,1) = ROTAXIS(1)*ROTAXIS(2)*(1.0-cosine) + ROTAXIS(3)*sine
ROTMATRIX(2,2) = cosine + ROTAXIS(2)**2*(1.0-cosine)
ROTMATRIX(2,3) = ROTAXIS(2)*ROTAXIS(3)*(1.0-cosine) - ROTAXIS(1)*sine
ROTMATRIX(3,1) = ROTAXIS(1)*ROTAXIS(3)*(1.0-cosine) - ROTAXIS(2)*sine
ROTMATRIX(3,2) = ROTAXIS(3)*ROTAXIS(2)*(1.0-cosine) + ROTAXIS(1)*sine
ROTMATRIX(3,3) = cosine + ROTAXIS(3)**2*(1.0-cosine)
! Each Beta is multiplied by the rotation matrix.
if (NUMIMP > 1) then
one = 1.0
zero = 0.0
do i = 2, NUMIMP
INBETA(:) = NEWBETA(:,i-1)
call DGEMV ('N', 3, 3, one, ROTMATRIX, 3, INBETA, 1, zero, OUTBETA, 1)
NEWBETA(:,i) = OUTBETA(:)
enddo
endif
endif
open (1, file = 'impatoms.dat', action = 'write')
do i = 1, NUMIMP
j = IMPPTSVAR(4,i)
VSUPCONDIMP(j) = 0.0
write (1,'(7F15.9, A, I7)') E0(j), BETA(1,j), BETA(2,j), BETA(3,j), VSUPCOND(j), ULCN(j), nuzero(j),&
&' ! Host No. ', i
write (1,'(7F15.9, A, I7)') E0(j), NEWBETA(1,i), NEWBETA(2,i), NEWBETA(3,i), VSUPCONDIMP(j), ULCN(j), nuzero(j),&
&' ! Impurity No. ', i
end do
write (1,'(A)') '---------------------------------------------------------------------------------------&
&-------------------'
write (1,'(A)') 'Format: E_0, B_x, B_y, B_z, V,&
& U, n_0'
close(1)
endsubroutine MAGCHAIN
subroutine HOPPS(RLATT,IRLATTMAX,R0,NUMCHEMTYPES,LHOPS,NUMT,CHEMTYPE,TPTS,PREFACTORS)
implicit none
integer :: NUMT, i, j, ITYPE, JTYPE, IRLATT, IRLATTMAX, CHEMTYPE(NUMT), NUMCHEMTYPES
real*8 :: TTPRIME(3), RPOINT(3), TPTS(3,NUMT), RLATT(3,IRLATTMAX), LHOPS(NUMCHEMTYPES,NUMCHEMTYPES), &
&PREFACTORS(NUMCHEMTYPES,NUMCHEMTYPES), NNDIS(NUMCHEMTYPES,NUMCHEMTYPES), expon, R0, TOL
TOL = 0.0001
open (1, file = 'hoppings.dat', action = 'read')
do i = 1, NUMCHEMTYPES
read(1,*) (LHOPS(i,j), j = 1, NUMCHEMTYPES)
end do
close(1)
do i = 1, NUMCHEMTYPES
do j = 1, NUMCHEMTYPES
if (LHOPS(i,j) /= LHOPS(j,i)) then
print *, 'Wrong value inserted as hopping element.'
print *, 'The', i,j, 'value is different from the', j,i, 'value.'
call exit(123)
endif
end do
end do
! This calculates the nearest-neighbour distance for each interaction
do ITYPE = 1, NUMCHEMTYPES
do JTYPE = 1, NUMCHEMTYPES
NNDIS(JTYPE,ITYPE) = 100000.0
do i = 1, NUMT
do j = 1, NUMT
if (CHEMTYPE(i) == ITYPE .and. CHEMTYPE(j) == JTYPE) then
TTPRIME = TPTS(1:3,j) - TPTS(1:3,i)
do IRLATT = 1, IRLATTMAX
RPOINT = RLATT(1:3,IRLATT)
if (NNDIS(JTYPE,ITYPE) > norm2(RPOINT+TTPRIME) .and. norm2(RPOINT+TTPRIME) > TOL) then
NNDIS(JTYPE,ITYPE) = norm2(RPOINT+TTPRIME)
endif
end do
endif
end do
end do
expon = exp(-NNDIS(JTYPE,ITYPE)/R0)
PREFACTORS(JTYPE,ITYPE) = LHOPS(JTYPE,ITYPE)/expon ! This sets the prefactors to be entered in the Hamiltonian
end do
end do
end subroutine HOPPS
subroutine HAMPREP(NUMT,xPauli,yPauli,zPauli,IdentityPauli,chempot,E0,ULCN,nu,nuzero,BETA,DELTA,HAMILTONIANPREP)
implicit none
integer :: NUMT, i
real*8 :: chempot, E0(NUMT), ULCN(NUMT), nu(NUMT), nuzero(NUMT), BETA(3,NUMT)
complex*16 :: xPauli(2,2), yPauli(2,2), zPauli(2,2), IdentityPauli(2,2), helperham(2,2), DELTA(NUMT),&
& HAMILTONIANPREP(4*NUMT,4*NUMT)
HAMILTONIANPREP(:,:) = (0.0,0.0)
do i = 1, NUMT
helperham = (E0(i) - chempot + ULCN(i)*(nu(i) - nuzero(i)))*IdentityPauli -&
&BETA(1,i)*xPauli - BETA(2,i)*yPauli - BETA(3,i)*zPauli
HAMILTONIANPREP(i, i) = helperham(1,1)
HAMILTONIANPREP(i, i + NUMT) = helperham(1,2)
!HAMILTONIANPREP(i, i + 2*NUMT) = (0.0,0.0)
HAMILTONIANPREP(i, i + 3*NUMT) = DELTA(i)
HAMILTONIANPREP(i + NUMT, i) = helperham(2,1)
HAMILTONIANPREP(i + NUMT, i + NUMT) = helperham(2,2)
HAMILTONIANPREP(i + NUMT, i + 2*NUMT) = DELTA(i)
!HAMILTONIANPREP(i + NUMT, i + 3*NUMT) = (0.0,0.0)
!HAMILTONIANPREP(i + 2*NUMT, i) = (0.0,0.0)
HAMILTONIANPREP(i + 2*NUMT, i + NUMT) = CONJG(DELTA(i))
HAMILTONIANPREP(i + 2*NUMT, i + 2*NUMT) = -CONJG(helperham(1,1))
HAMILTONIANPREP(i + 2*NUMT, i + 3*NUMT) = CONJG(helperham(1,2))
HAMILTONIANPREP(i + 3*NUMT, i) = CONJG(DELTA(i))
!HAMILTONIANPREP(i + 3*NUMT, i + NUMT) = (0.0,0.0)
HAMILTONIANPREP(i + 3*NUMT, i + 2*NUMT) = CONJG(helperham(2,1))
HAMILTONIANPREP(i + 3*NUMT, i + 3*NUMT) = -CONJG(helperham(2,2))
end do
end subroutine HAMPREP
subroutine FOURIERHAM(kcounter,NUMK,HAMILTONIANPREP,EXPONS,HOPPVALS,NEIGHBNUM,JTYPE,MAXNEIGHB,NUMT,HAMILTONIAN)
implicit none
integer, intent(in) :: kcounter
integer :: NUMT, NUMK, i, jneighb, NEIGHBNUM(NUMT), MAXNEIGHB, JATOM, JTYPE(MAXNEIGHB,NUMT)
real*8 :: HOPPVALS(MAXNEIGHB,NUMT)
complex*16 :: HAMILTONIAN(4*NUMT,4*NUMT), HAMILTONIANPREP(4*NUMT,4*NUMT), EXPONS(NUMK,MAXNEIGHB,NUMT), term
HAMILTONIAN(:,:) = HAMILTONIANPREP(:,:)
do i = 1, NUMT
do jneighb = 1, NEIGHBNUM(i)
JATOM = JTYPE(jneighb,i)
term = EXPONS(kcounter,jneighb,i)*HOPPVALS(jneighb,i)
HAMILTONIAN(i,JATOM) = HAMILTONIAN(i,JATOM) + term
HAMILTONIAN(i + NUMT,JATOM + NUMT) = HAMILTONIAN(i + NUMT,JATOM + NUMT) + term
HAMILTONIAN(i + 2*NUMT,JATOM + 2*NUMT) = HAMILTONIAN(i + 2*NUMT,JATOM + 2*NUMT) - term
HAMILTONIAN(i + 3*NUMT,JATOM + 3*NUMT) = HAMILTONIAN(i + 3*NUMT,JATOM + 3*NUMT) - term
end do
end do
end subroutine FOURIERHAM
subroutine FULLGREEN(EIGENVALUES,EIGENVECTORS,NUMT,NUMK,PI,TPTS,a_1,a_2,a_3,KPTS,NUMIMP,IMPPTSVAR,NPNT,NPOL)
implicit none
integer :: NUMT, NUMK, IE, i, j, k, n, NUMIMP, IMPPTSVAR(4,NUMIMP), &
&l, m, a, aprime, FTIMO, FTJMO, checker, NPNT, NPOL
real*8 :: PI, EIGENVALUES(4*NUMT,NUMK), greendensityperatom(1+NUMT,NPNT), &
&a_1(3), a_2(3), a_3(3), RPOINT(3), RPRIMEPOINT(3), FOURIERVEC(3), TPTS(3,NUMT), KPTS(3,NUMK), KPOINT(3),&
&greendensity(2,NPNT), densityperimpurity(1+NUMIMP,NPNT), tempval1, tempval2
complex*16 :: EIGENVECTORS(4*NUMT,4*NUMT,NUMK), GMATRIX(4*NUMT,4*NUMT), EZ, ENFRAC, GFK(NUMK,4*NUMT,4*NUMT),&
&GREENR(4*NUMIMP,4*NUMIMP), FOUREXPONS(NUMK,NUMIMP**2), energies(NPNT), WEIGHTS(NPNT)
! This constructs the exponentials to be used in the Fourier transform
checker = 1
do j = 1, NUMIMP
do i = 1, NUMIMP
a = IMPPTSVAR(4,i)
aprime = IMPPTSVAR(4,j)
RPOINT = IMPPTSVAR(1,i)*a_1 + IMPPTSVAR(2,i)*a_2 + IMPPTSVAR(3,i)*a_3
RPRIMEPOINT = IMPPTSVAR(1,j)*a_1 + IMPPTSVAR(2,j)*a_2 + IMPPTSVAR(3,j)*a_3
FOURIERVEC(1:3) = RPRIMEPOINT(1:3) - RPOINT(1:3) + TPTS(1:3,aprime) - TPTS(1:3,a)
do k = 1, NUMK
KPOINT = KPTS(1:3,k)
FOUREXPONS(k,checker) = exp(-CI*DOT_PRODUCT(KPOINT,FOURIERVEC))
end do
checker = checker + 1
end do
end do
if (NPOL == 0) then
open(1, file = 'energiesfordos.dat', action = 'read')
do i = 1, NPNT
read(1,*) tempval1, tempval2
energies(i) = dcmplx(tempval1, tempval2)
end do
close(1)
else
open(1, file = 'energies.dat', action = 'read')
do i = 1, NPNT
read(1,*) tempval1, tempval2
energies(i) = dcmplx(tempval1, tempval2)
end do
close(1)
open(1, file = 'fermiweights.dat', action = 'read')
do i = 1, NPNT
read(1,*) tempval1, tempval2
WEIGHTS(i) = dcmplx(tempval1, tempval2)
end do
close(1)
endif
! This part writes all the Fouriered Green function elements per energy at this text file
if (NPOL == 0) then
open(1, file = 'greenhostfordos.txt', action = 'write')
else
open(1, file = 'greenhost.txt', action = 'write')
endif
do IE = 1, NPNT ! Begins a loop over the energies, in order to find G(E) for each E
EZ = energies(IE)
if (NPOL == 0) then
greendensityperatom(1,IE) = REAL(EZ)
greendensity(1,IE) = REAL(EZ)
greendensity(2,IE) = 0.0
do i = 1, NUMT
greendensityperatom(1+i,IE) = 0.0
end do
densityperimpurity(1,IE) = REAL(EZ)
do i = 1, NUMIMP
densityperimpurity(1+i,IE) = 0.0
end do
endif
! This initiates the calculation of the Green's function matrix G(α,α';E) per k-point
do k = 1, NUMK ! k
! Set all G-matrix values equal to zero, so that the following summation can work
GMATRIX(:,:) = (0.0,0.0)
do i = 1, NUMT ! α
FTIMO = 4*(i-1)
do j = 1, NUMT ! α'
FTJMO = 4*(j-1)
do n = 1, 4*NUMT ! This is the sum over all eigenenergies per k
ENFRAC = (1.0/(EZ-EIGENVALUES(n,k)))
GMATRIX(1 + FTIMO, 1 + FTJMO) = GMATRIX(1 + FTIMO, 1 + FTJMO) +&
&ENFRAC*EIGENVECTORS(i,n,k)*CONJG(EIGENVECTORS(j,n,k)) ! 11
GMATRIX(1 + FTIMO, 2 + FTJMO) = GMATRIX(1 + FTIMO, 2 + FTJMO) +&
&ENFRAC*EIGENVECTORS(i,n,k)*CONJG(EIGENVECTORS(j+NUMT,n,k)) ! 12
GMATRIX(1 + FTIMO, 3 + FTJMO) = GMATRIX(1 + FTIMO, 3 + FTJMO) +&
&ENFRAC*EIGENVECTORS(i,n,k)*CONJG(EIGENVECTORS(j+2*NUMT,n,k)) ! 13
GMATRIX(1 + FTIMO, 4 + FTJMO) = GMATRIX(1 + FTIMO, 4 + FTJMO) +&
&ENFRAC*EIGENVECTORS(i,n,k)*CONJG(EIGENVECTORS(j+3*NUMT,n,k)) ! 14
GMATRIX(2 + FTIMO, 1 + FTJMO) = GMATRIX(2 + FTIMO, 1 + FTJMO) +&
&ENFRAC*EIGENVECTORS(i+NUMT,n,k)*CONJG(EIGENVECTORS(j,n,k)) ! 21
GMATRIX(2 + FTIMO, 2 + FTJMO) = GMATRIX(2 + FTIMO, 2 + FTJMO) +&
&ENFRAC*EIGENVECTORS(i+NUMT,n,k)*CONJG(EIGENVECTORS(j+NUMT,n,k)) ! 22
GMATRIX(2 + FTIMO, 3 + FTJMO) = GMATRIX(2 + FTIMO, 3 + FTJMO) +&
&ENFRAC*EIGENVECTORS(i+NUMT,n,k)*CONJG(EIGENVECTORS(j+2*NUMT,n,k)) ! 23
GMATRIX(2 + FTIMO, 4 + FTJMO) = GMATRIX(2 + FTIMO, 4 + FTJMO) +&
&ENFRAC*EIGENVECTORS(i+NUMT,n,k)*CONJG(EIGENVECTORS(j+3*NUMT,n,k)) ! 24
GMATRIX(3 + FTIMO, 1 + FTJMO) = GMATRIX(3 + FTIMO, 1 + FTJMO) +&
&ENFRAC*EIGENVECTORS(i+2*NUMT,n,k)*CONJG(EIGENVECTORS(j,n,k)) ! 31
GMATRIX(3 + FTIMO, 2 + FTJMO) = GMATRIX(3 + FTIMO, 2 + FTJMO) +&
&ENFRAC*EIGENVECTORS(i+2*NUMT,n,k)*CONJG(EIGENVECTORS(j+NUMT,n,k)) ! 32
GMATRIX(3 + FTIMO, 3 + FTJMO) = GMATRIX(3 + FTIMO, 3 + FTJMO) +&
&ENFRAC*EIGENVECTORS(i+2*NUMT,n,k)*CONJG(EIGENVECTORS(j+2*NUMT,n,k)) ! 33
GMATRIX(3 + FTIMO, 4 + FTJMO) = GMATRIX(3 + FTIMO, 4 + FTJMO) +&
&ENFRAC*EIGENVECTORS(i+2*NUMT,n,k)*CONJG(EIGENVECTORS(j+3*NUMT,n,k)) ! 34
GMATRIX(4 + FTIMO, 1 + FTJMO) = GMATRIX(4 + FTIMO, 1 + FTJMO) +&
&ENFRAC*EIGENVECTORS(i+3*NUMT,n,k)*CONJG(EIGENVECTORS(j,n,k)) ! 41
GMATRIX(4 + FTIMO, 2 + FTJMO) = GMATRIX(4 + FTIMO, 2 + FTJMO) +&
&ENFRAC*EIGENVECTORS(i+3*NUMT,n,k)*CONJG(EIGENVECTORS(j+NUMT,n,k)) ! 42
GMATRIX(4 + FTIMO, 3 + FTJMO) = GMATRIX(4 + FTIMO, 3 + FTJMO) +&
&ENFRAC*EIGENVECTORS(i+3*NUMT,n,k)*CONJG(EIGENVECTORS(j+2*NUMT,n,k)) ! 43
GMATRIX(4 + FTIMO, 4 + FTJMO) = GMATRIX(4 + FTIMO, 4 + FTJMO) +&
&ENFRAC*EIGENVECTORS(i+3*NUMT,n,k)*CONJG(EIGENVECTORS(j+3*NUMT,n,k)) ! 44
end do
end do
end do
if (NPOL == 0) then
do i = 1, NUMT ! Calculation of density for each atom
FTIMO = 4*(i-1)
do j = 1, 2 ! n = u↑u↑* + u↓u↓*
greendensityperatom(1+i,IE) = greendensityperatom(1+i,IE) -&
&(1.0/PI)*AIMAG(GMATRIX(j + FTIMO, j + FTIMO))
end do
end do
endif
GFK(k,:,:) = GMATRIX ! This is a table that contains all G(α,α',k;E) per energy E
end do ! ends k-loop
! Fourier transform of G(k) into G(r-r')
! This constructs a 4*NUMIMP x 4*NUMIMP G(r-r') matrix for each energy EZ
! Startup
GREENR(:,:) = (0.0,0.0)
checker = 1
do j = 1, NUMIMP
FTJMO = 4*(j-1)
aprime = IMPPTSVAR(4,j)
do i = 1, NUMIMP
FTIMO = 4*(i-1)
a = IMPPTSVAR(4,i)
do k = 1, NUMK
do m = 1, 4
do l = 1, 4
GREENR(m + FTIMO, l + FTJMO) = GREENR(m + FTIMO, l + FTJMO) +&
&(1.0/NUMK)*FOUREXPONS(k,checker)*GFK(k, m + 4*(a-1) , l + 4*(aprime-1))
end do
end do
end do
checker = checker + 1
end do
end do
if (NPOL == 0) then
do i = 1, NUMIMP ! Calculation of density for each impurity atom
FTIMO = 4*(i-1)
do j = 1, 2 ! n = u↑u↑* + u↓u↓*
densityperimpurity(1+i,IE) = densityperimpurity(1+i,IE) -&
&(1.0/PI)*AIMAG(GREENR(j + FTIMO, j + FTIMO))
end do
end do
endif
! Writes the Green impurity elements on the corresponding .txt file
do i = 1, 4*NUMIMP
do j = 1, 4*NUMIMP
write (1, '(F17.8, F17.8)') GREENR(i,j)
end do
end do
if (NPOL == 0) then
do i = 1, NUMT ! Calculation of full density
greendensityperatom(i+1,IE) = greendensityperatom(i+1,IE)/NUMK ! Normalization
greendensity(2,IE) = greendensity(2,IE) + (1.0/NUMT)*greendensityperatom(1+i,IE)
end do
endif
end do ! ends energies sum
close(1) ! Closes the .txt file
if (NPOL == 0) then
open(1, file = 'greendensityperatom.txt', action = 'write')
do j = 1, NPNT
do i = 1, NUMT+1
if (i == NUMT+1) then
write (1,'(F17.8)',advance='no') greendensityperatom(i,j)
else
write (1,'(F17.8, A)',advance='no') greendensityperatom(i,j), ','
endif
end do
write (1,*)
end do
close(1)
! The density per atom at the future impurity sites.
open(1, file = 'hostdensities.txt', action = 'write')
do j = 1, NPNT
do i = 1, NUMIMP+1
if (i == NUMIMP+1) then
write (1,'(F17.8)',advance='no') densityperimpurity(i,j)
else
write (1,'(F17.8, A)',advance='no') densityperimpurity(i,j), ','
endif
end do
write (1,*)
end do
close(1)
open(1, file = 'greendensity.txt', action = 'write')
do j = 1, NPNT ! Energies = Intervals + 1
write (1,'(F17.8, A, F17.8)') greendensity(1,j), ',', greendensity(2,j)
end do
close(1)
endif
end subroutine FULLGREEN
subroutine PARTIALGREEN(EIGENVALUES,EIGENVECTORS,NUMT,NUMK,TPTS,a_1,a_2,a_3,KPTS,NUMIMP,IMPPTSVAR,NPNT,NPOL)
implicit none
integer :: NUMT, NUMK, IE, i, j, k, n, NUMIMP, IMPPTSVAR(4,NUMIMP), min_val, max_val, l, m, a, aprime,&
&FTIMO, FTJMO, checker, IMPATOMTYPE(NUMIMP), uniquecounter, NUMATOMS, IATOM, JATOM, NPNT, NPOL
integer, allocatable, dimension(:) :: IMPATOMVALS, UNIQUEIMPATOMS
real*8 :: EIGENVALUES(4*NUMT,NUMK), densityperimpurity(1+NUMIMP,NPNT), tempval1, tempval2,&
&a_1(3), a_2(3), a_3(3), RPOINT(3), RPRIMEPOINT(3), FOURIERVEC(3), TPTS(3,NUMT), KPTS(3,NUMK), KPOINT(3)
complex*16 :: EIGENVECTORS(4*NUMT,4*NUMT,NUMK), GMATRIX(4*NUMT,4*NUMT), EZ, ENFRAC, GFK(NUMK,4*NUMT,4*NUMT),&
&GREENR(4*NUMIMP,4*NUMIMP), FOUREXPONS(NUMK,NUMIMP**2), energies(NPNT), WEIGHTS(NPNT)
! Here we catalogue the different atom types, as numbered by their line on the basisvectors.dat file,
! that correspond to the impurities of the problem.
IMPATOMTYPE(:) = IMPPTSVAR(4,:)
allocate(UNIQUEIMPATOMS(NUMIMP)) ! Helper array
uniquecounter = 0
min_val = MINVAL(IMPATOMTYPE) - 1 ! -1.0 Is inserted for a case of complete degeneracy
max_val = MAXVAL(IMPATOMTYPE)
do while (min_val < max_val)
uniquecounter = uniquecounter + 1
min_val = MINVAL(IMPATOMTYPE, mask = IMPATOMTYPE > min_val)
UNIQUEIMPATOMS(uniquecounter) = min_val
enddo
NUMATOMS = uniquecounter ! The number of basisvectos.dat atoms that enter the impurity problem. NUMATOMS < NUMT
allocate(IMPATOMVALS(NUMATOMS))
IMPATOMVALS = UNIQUEIMPATOMS(1:NUMATOMS)
! IMPATOMVALS now contains only the unique atom types that enter the impurity problem, in ascending order.
! The point of this subroutine, unlike the FULLGREEN subroutine, is to build the Green function only for the
! atoms that enter the impurity problem and not all the atoms in basisvectors.dat
! This constructs the exponentials to be used in the Fourier transform
checker = 1
do j = 1, NUMIMP
do i = 1, NUMIMP
a = IMPPTSVAR(4,i)
aprime = IMPPTSVAR(4,j)
RPOINT = IMPPTSVAR(1,i)*a_1 + IMPPTSVAR(2,i)*a_2 + IMPPTSVAR(3,i)*a_3
RPRIMEPOINT = IMPPTSVAR(1,j)*a_1 + IMPPTSVAR(2,j)*a_2 + IMPPTSVAR(3,j)*a_3
FOURIERVEC(1:3) = RPRIMEPOINT(1:3) - RPOINT(1:3) + TPTS(1:3,aprime) - TPTS(1:3,a)
do k = 1, NUMK
KPOINT = KPTS(1:3,k)
FOUREXPONS(k,checker) = exp(-CI*DOT_PRODUCT(KPOINT,FOURIERVEC))
end do
checker = checker + 1
end do
end do
if (NPOL == 0) then
open(1, file = 'energiesfordos.dat', action = 'read')
do i = 1, NPNT
read(1,*) tempval1, tempval2
energies(i) = dcmplx(tempval1, tempval2)
end do
close(1)
else
open(1, file = 'energies.dat', action = 'read')
do i = 1, NPNT
read(1,*) tempval1, tempval2
energies(i) = dcmplx(tempval1, tempval2)
end do
close(1)
open(1, file = 'fermiweights.dat', action = 'read')
do i = 1, NPNT
read(1,*) tempval1, tempval2
WEIGHTS(i) = dcmplx(tempval1, tempval2)
end do
close(1)
endif
! This part writes all the Fouriered Green function elements per energy at this text file
if (NPOL == 0) then
open(1, file = 'greenhostfordos.txt', action = 'write')
else
open(1, file = 'greenhost.txt', action = 'write')
endif
do IE = 1, NPNT ! Begins a loop over the energies, in order to find G(E) for each E
EZ = energies(IE)
if (NPOL == 0) then
densityperimpurity(1,IE) = REAL(EZ)
do i = 1, NUMIMP
densityperimpurity(1+i,IE) = 0.0
end do
endif
! This initiates the calculation of the Green's function matrix G(α,α';E) per k-point
do k = 1, NUMK ! k
! Set all G-matrix values equal to zero, so that the following summation can work
GMATRIX(:,:) = (0.0,0.0)
do i = 1, NUMATOMS ! α
IATOM = IMPATOMVALS(i)
FTIMO = 4*(IATOM-1)
do j = 1, NUMATOMS ! α'
JATOM = IMPATOMVALS(j)
FTJMO = 4*(JATOM-1)
do n = 1, 4*NUMT ! This is the sum over all eigenenergies per k
ENFRAC = (1.0/(EZ-EIGENVALUES(n,k)))
GMATRIX(1 + FTIMO, 1 + FTJMO) = GMATRIX(1 + FTIMO, 1 + FTJMO) +&
&ENFRAC*EIGENVECTORS(IATOM,n,k)*CONJG(EIGENVECTORS(JATOM,n,k)) ! 11
GMATRIX(1 + FTIMO, 2 + FTJMO) = GMATRIX(1 + FTIMO, 2 + FTJMO) +&
&ENFRAC*EIGENVECTORS(IATOM,n,k)*CONJG(EIGENVECTORS(JATOM+NUMT,n,k)) ! 12
GMATRIX(1 + FTIMO, 3 + FTJMO) = GMATRIX(1 + FTIMO, 3 + FTJMO) +&