forked from wannier-developers/wannier90
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot.F90
1616 lines (1442 loc) · 68 KB
/
plot.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
!-*- mode: F90 -*-!
!------------------------------------------------------------!
! This file is distributed as part of the Wannier90 code and !
! under the terms of the GNU General Public License. See the !
! file `LICENSE' in the root directory of the Wannier90 !
! distribution, or http://www.gnu.org/copyleft/gpl.txt !
! !
! The webpage of the Wannier90 code is www.wannier.org !
! !
! The Wannier90 code is hosted on GitHub: !
! !
! https://github.com/wannier-developers/wannier90 !
!------------------------------------------------------------!
module w90_plot
!! This module handles various plots
implicit none
private
public :: plot_main
contains
!============================================!
subroutine plot_main( )
!! Main plotting routine
!============================================!
use w90_constants, only : eps6
use w90_io, only : stdout,io_stopwatch
use w90_parameters, only : num_kpts,bands_plot,dos_plot, &
kpt_latt,fermi_surface_plot, &
wannier_plot,timing_level,&
write_hr,write_rmn,write_tb,write_u_matrices
use w90_hamiltonian, only : hamiltonian_get_hr,hamiltonian_write_hr, &
hamiltonian_setup,hamiltonian_write_rmn,&
hamiltonian_write_tb, nrpts, irvec
use w90_ws_distance, only : done_ws_distance, ws_translate_dist, &
ws_write_vec
implicit none
integer :: nkp
logical :: have_gamma
if (timing_level>0) call io_stopwatch('plot: main',1)
write(stdout,'(1x,a)') '*---------------------------------------------------------------------------*'
write(stdout,'(1x,a)') '| PLOTTING |'
write(stdout,'(1x,a)') '*---------------------------------------------------------------------------*'
write(stdout,*)
if(bands_plot .or. dos_plot .or. fermi_surface_plot .or. write_hr) then
! Check if the kmesh includes the gamma point
have_gamma=.false.
do nkp=1,num_kpts
if (all(abs(kpt_latt(:,nkp))<eps6)) have_gamma=.true.
end do
if(.not. have_gamma) &
write(stdout,'(1x,a)') '!!!! Kpoint grid does not include Gamma. ' // &
& ' Interpolation may be incorrect. !!!!'
! Transform Hamiltonian to WF basis
!
call hamiltonian_setup()
!
call hamiltonian_get_hr()
!
if(bands_plot) call plot_interpolate_bands
!
if(fermi_surface_plot) call plot_fermi_surface
!
if(write_hr) call hamiltonian_write_hr()
!
if(write_rmn) call hamiltonian_write_rmn()
!
if(write_tb) call hamiltonian_write_tb()
!
if (write_hr.or.write_rmn.or.write_tb) then
if (.not.done_ws_distance) call ws_translate_dist(nrpts,irvec)
call ws_write_vec(nrpts,irvec)
end if
end if
if(wannier_plot) call plot_wannier
if(write_u_matrices) call plot_u_matrices
if (timing_level>0) call io_stopwatch('plot: main',2)
end subroutine plot_main
!-----------------------------------!
!----------------- Private Routines ------------------------------
!-----------------------------------!
!============================================!
subroutine plot_interpolate_bands
!============================================!
! !
!! Plots the interpolated band structure
! !
!============================================!
use w90_constants, only : dp,cmplx_0,cmplx_i,twopi
use w90_io, only : io_error,stdout,io_file_unit,seedname,&
io_time,io_stopwatch
use w90_parameters, only : num_wann,bands_num_points,recip_metric,&
bands_num_spec_points,timing_level, &
bands_spec_points,bands_label,bands_plot_format, &
bands_plot_mode,num_bands_project,bands_plot_project, &
use_ws_distance
use w90_hamiltonian, only : irvec,nrpts,ndegen,ham_r
use w90_ws_distance, only : irdist_ws,wdist_ndeg, &
ws_translate_dist
implicit none
complex(kind=dp),allocatable :: ham_r_cut(:,:,:)
complex(kind=dp),allocatable :: ham_pack(:)
complex(kind=dp) :: fac
complex(kind=dp),allocatable :: ham_kprm(:,:)
complex(kind=dp),allocatable :: U_int(:,:)
complex(kind=dp),allocatable :: cwork(:)
real(kind=dp),allocatable :: rwork(:)
real(kind=dp) :: kpath_len(bands_num_spec_points/2)
integer :: kpath_pts(bands_num_spec_points/2)
real(kind=dp), allocatable :: xval(:)
real(kind=dp), allocatable :: eig_int(:,:),plot_kpoint(:,:)
real(kind=dp), allocatable :: bands_proj(:,:)
real(kind=dp) :: rdotk,vec(3),emin,emax,time0
integer, allocatable :: irvec_cut(:,:)
integer :: irvec_max(3)
integer :: nrpts_cut
integer, allocatable :: iwork(:),ifail(:)
integer :: info,i,j
integer :: irpt,nfound,loop_kpt,counter
integer :: loop_spts,total_pts,loop_i,nkp,ideg
integer :: num_paths,num_spts,ierr
integer :: bndunit,gnuunit,loop_w,loop_p
character(len=3),allocatable :: glabel(:)
character(len=10),allocatable :: xlabel(:)
character(len=10),allocatable :: ctemp(:)
!
if (timing_level>1) call io_stopwatch('plot: interpolate_bands',1)
!
time0=io_time()
write(stdout,*)
write(stdout,'(1x,a)') 'Calculating interpolated band-structure'
write(stdout,*)
!
allocate(ham_pack((num_wann*(num_wann+1))/2),stat=ierr)
if (ierr/=0) call io_error('Error in allocating ham_pack in plot_interpolate_bands')
allocate(ham_kprm(num_wann,num_wann),stat=ierr)
if (ierr/=0) call io_error('Error in allocating ham_kprm in plot_interpolate_bands')
allocate(U_int(num_wann,num_wann),stat=ierr)
if (ierr/=0) call io_error('Error in allocating U_int in plot_interpolate_bands')
allocate(cwork(2*num_wann),stat=ierr)
if (ierr/=0) call io_error('Error in allocating cwork in plot_interpolate_bands')
allocate(rwork(7*num_wann),stat=ierr)
if (ierr/=0) call io_error('Error in allocating rwork in plot_interpolate_bands')
allocate(iwork(5*num_wann),stat=ierr)
if (ierr/=0) call io_error('Error in allocating iwork in plot_interpolate_bands')
allocate(ifail(num_wann),stat=ierr)
if (ierr/=0) call io_error('Error in allocating ifail in plot_interpolate_bands')
!
! Work out how many points in the total path and the positions of the special points
!
num_paths=bands_num_spec_points/2
num_spts=num_paths+1
do loop_spts=1,num_paths
vec=bands_spec_points(:,2*loop_spts)-bands_spec_points(:,2*loop_spts-1)
kpath_len(loop_spts)=sqrt(dot_product(vec,(matmul(recip_metric,vec))))
if(loop_spts==1) then
kpath_pts(loop_spts)=bands_num_points
else
kpath_pts(loop_spts)=nint(real(bands_num_points,dp)*kpath_len(loop_spts)/kpath_len(1))
end if
end do
total_pts=sum(kpath_pts)+1
allocate(plot_kpoint(3,total_pts),stat=ierr)
if (ierr/=0) call io_error('Error in allocating plot_kpoint in plot_interpolate_bands')
allocate(xval(total_pts),stat=ierr)
if (ierr/=0) call io_error('Error in allocating xval in plot_interpolate_bands')
allocate(eig_int(num_wann,total_pts),stat=ierr)
if (ierr/=0) call io_error('Error in allocating eig_int in plot_interpolate_bands')
allocate(bands_proj(num_wann,total_pts),stat=ierr)
if (ierr/=0) call io_error('Error in allocating bands_proj in plot_interpolate_bands')
allocate(glabel(num_spts),stat=ierr)
if (ierr/=0) call io_error('Error in allocating num_spts in plot_interpolate_bands')
allocate(xlabel(num_spts),stat=ierr)
if (ierr/=0) call io_error('Error in allocating xlabel in plot_interpolate_bands')
allocate(ctemp(bands_num_spec_points),stat=ierr)
if (ierr/=0) call io_error('Error in allocating ctemp in plot_interpolate_bands')
eig_int=0.0_dp;bands_proj=0.0_dp
!
! Find the position of each kpoint in the path
!
counter=0
do loop_spts=1,num_paths
do loop_i=1,kpath_pts(loop_spts)
counter=counter+1
if(counter==1) then
xval(counter)=0.0_dp
else
xval(counter)=xval(counter-1)+kpath_len(loop_spts)/real(kpath_pts(loop_spts),dp)
endif
plot_kpoint(:,counter)=bands_spec_points(:,2*loop_spts-1)+ &
(bands_spec_points(:,2*loop_spts)-bands_spec_points(:,2*loop_spts-1))* &
(real(loop_i-1,dp)/real(kpath_pts(loop_spts),dp))
end do
end do
xval(total_pts)=sum(kpath_len)
plot_kpoint(:,total_pts)=bands_spec_points(:,bands_num_spec_points)
!
! Write out the kpoints in the path
!
bndunit=io_file_unit()
open(bndunit,file=trim(seedname)//'_band.kpt',form='formatted')
write(bndunit,*) total_pts
do loop_spts=1,total_pts
write(bndunit,'(3f12.6,3x,a)') (plot_kpoint(loop_i,loop_spts),loop_i=1,3),"1.0"
end do
close(bndunit)
!
! Cut H matrix in real-space
!
if (index(bands_plot_mode,'cut').ne.0) call plot_cut_hr()
!
! Interpolate the Hamiltonian at each kpoint
!
if(use_ws_distance)then
if (index(bands_plot_mode,'s-k').ne.0) then
call ws_translate_dist(nrpts, irvec, force_recompute=.true.)
elseif (index(bands_plot_mode,'cut').ne.0) then
call ws_translate_dist(nrpts_cut, irvec_cut, force_recompute=.true.)
else
call io_error('Error in plot_interpolate bands: value of bands_plot_mode not recognised')
endif
endif
! [lp] the s-k and cut codes are very similar when use_ws_distance is used, a complete
! mercge after this point is not impossible
do loop_kpt=1,total_pts
ham_kprm=cmplx_0
!
if (index(bands_plot_mode,'s-k').ne.0) then
do irpt=1,nrpts
! [lp] Shift the WF to have the minimum distance IJ, see also ws_distance.F90
if(use_ws_distance)then
do j=1,num_wann
do i=1,num_wann
do ideg = 1,wdist_ndeg(i,j,irpt)
rdotk=twopi*dot_product(plot_kpoint(:,loop_kpt),&
real(irdist_ws(:,ideg,i,j,irpt),dp))
fac=cmplx(cos(rdotk),sin(rdotk),dp)/real(ndegen(irpt)*wdist_ndeg(i,j,irpt),dp)
ham_kprm(i,j)=ham_kprm(i,j)+fac*ham_r(i,j,irpt)
enddo
enddo
enddo
else
! [lp] Original code, without IJ-dependent shift:
rdotk=twopi*dot_product(plot_kpoint(:,loop_kpt),irvec(:,irpt))
fac=cmplx(cos(rdotk),sin(rdotk),dp)/real(ndegen(irpt),dp)
ham_kprm=ham_kprm+fac*ham_r(:,:,irpt)
endif
end do
! end of s-k mode
elseif (index(bands_plot_mode,'cut').ne.0) then
do irpt=1,nrpts_cut
! [lp] Shift the WF to have the minimum distance IJ, see also ws_distance.F90
if(use_ws_distance)then
do j=1,num_wann
do i=1,num_wann
do ideg = 1,wdist_ndeg(j,i,irpt)
rdotk=twopi*dot_product(plot_kpoint(:,loop_kpt), &
real(irdist_ws(:,ideg,i,j,irpt),dp))
fac=cmplx(cos(rdotk),sin(rdotk),dp)/real(wdist_ndeg(i,j,irpt),dp)
ham_kprm(i,j)=ham_kprm(i,j)+fac*ham_r_cut(i,j,irpt)
enddo
enddo
enddo
! [lp] Original code, without IJ-dependent shift:
else
rdotk=twopi*dot_product(plot_kpoint(:,loop_kpt),irvec_cut(:,irpt))
!~[aam] check divide by ndegen?
fac=cmplx(cos(rdotk),sin(rdotk),dp)
ham_kprm=ham_kprm+fac*ham_r_cut(:,:,irpt)
endif ! end of use_ws_distance
end do
endif ! end of "cut" mode
!
! Diagonalise H_k (->basis of eigenstates)
do j=1,num_wann
do i=1,j
ham_pack(i+((j-1)*j)/2)=ham_kprm(i,j)
enddo
enddo
call ZHPEVX('V','A','U',num_wann,ham_pack,0.0_dp,0.0_dp,0,0,-1.0_dp, &
nfound,eig_int(1,loop_kpt),U_int,num_wann,cwork,rwork,iwork,ifail,info)
if(info < 0) then
write(stdout,'(a,i3,a)') 'THE ',-info, ' ARGUMENT OF ZHPEVX HAD AN ILLEGAL VALUE'
call io_error('Error in plot_interpolate_bands')
endif
if(info > 0) then
write(stdout,'(i3,a)') info,' EIGENVECTORS FAILED TO CONVERGE'
call io_error('Error in plot_interpolate_bands')
endif
! Compute projection onto WF if requested
if(num_bands_project>0) then
do loop_w=1,num_wann
do loop_p=1,num_wann
if(any(bands_plot_project==loop_p)) then
bands_proj(loop_w,loop_kpt)=bands_proj(loop_w,loop_kpt)+abs(U_int(loop_p,loop_w))**2
end if
end do
end do
end if
!
end do
!
! Interpolation Finished!
! Now we write plotting files
!
emin=minval(eig_int)-1.0_dp
emax=maxval(eig_int)+1.0_dp
if(index(bands_plot_format,'gnu')>0) call plot_interpolate_gnuplot
if(index(bands_plot_format,'xmgr')>0) call plot_interpolate_xmgrace
write(stdout,'(1x,a,f11.3,a)') &
'Time to calculate interpolated band structure ',io_time()-time0,' (sec)'
write(stdout,*)
if (allocated(ham_r_cut)) deallocate(ham_r_cut,stat=ierr)
if (ierr/=0) call io_error('Error in deallocating ham_r_cut in plot_interpolate_bands')
if (allocated(irvec_cut)) deallocate(irvec_cut,stat=ierr)
if (ierr/=0) call io_error('Error in deallocating irvec_cut in plot_interpolate_bands')
!
if (timing_level>1) call io_stopwatch('plot: interpolate_bands',2)
!
contains
!============================================!
subroutine plot_cut_hr()
!============================================!
!
!! In real-space picture, ham_r(j,i,k) is an interaction between
!! j_th WF at 0 and i_th WF at the lattice point translated
!! by matmul(real_lattice(:,:),irvec(:,k))
!! We truncate Hamiltonian matrix when
!! 1) | r_i(0) - r_j (R) | > dist_cutoff
!! 2) | ham_r(i,j,k) | < hr_cutoff
!! while the condition 1) is essential to get a meaningful band structure,
!! ( dist_cutoff must be smaller than the shortest distance from
!! the center of W-S supercell to the points at the cell boundaries )
!! the condition 2) is optional.
!!
!! limitation: when bands_plot_dim .ne. 3
!! one_dim_vec must be parallel to one of the cartesian axis
!! and perpendicular to the other two primitive lattice vectors
!============================================!
use w90_constants, only : dp,cmplx_0, eps8
use w90_io, only : io_error,stdout
use w90_parameters, only : num_wann, mp_grid, real_lattice, &
one_dim_dir, bands_plot_dim, &
hr_cutoff, dist_cutoff, dist_cutoff_mode
use w90_hamiltonian, only : wannier_centres_translated
implicit none
!
integer :: nrpts_tmp
integer :: one_dim_vec, two_dim_vec(2)
integer :: i, j, n1, n2, n3, i1, i2, i3
real(kind=dp), allocatable :: ham_r_tmp(:,:)
real(kind=dp), allocatable :: shift_vec(:,:)
real(kind=dp) :: dist_ij_vec(3)
real(kind=dp) :: dist_vec(3)
real(kind=dp) :: dist
allocate(ham_r_tmp(num_wann,num_wann),stat=ierr)
if (ierr/=0) call io_error('Error in allocating ham_r_tmp in plot_cut_hr')
irvec_max = maxval(irvec,DIM=2)+1
if (bands_plot_dim .ne. 3) then
! Find one_dim_vec which is parallel to one_dim_dir
! two_dim_vec - the other two lattice vectors
! Along the confined directions, take only irvec=0
j = 0
do i=1,3
if ( abs(abs(real_lattice(one_dim_dir,i)) &
- sqrt(dot_product(real_lattice(:,i),real_lattice(:,i)))) .lt. eps8 ) then
one_dim_vec = i
j = j +1
end if
end do
if ( j .ne. 1 ) call io_error('Error: 1-d lattice vector not defined in plot_cut_hr')
j=0
do i=1,3
if ( i .ne. one_dim_vec ) then
j = j +1
two_dim_vec(j)=i
end if
end do
if (bands_plot_dim .eq. 1) then
irvec_max(two_dim_vec(1))=0
irvec_max(two_dim_vec(2))=0
end if
if (bands_plot_dim .eq. 2) irvec_max(one_dim_vec)=0
end if
nrpts_cut = (2*irvec_max(1)+1)*(2*irvec_max(2)+1)*(2*irvec_max(3)+1)
allocate(ham_r_cut(num_wann,num_wann,nrpts_cut),stat=ierr)
if (ierr/=0) call io_error('Error in allocating ham_r_cut in plot_cut_hr')
allocate(irvec_cut(3,nrpts_cut),stat=ierr)
if (ierr/=0) call io_error('Error in allocating irvec_cut in plot_cut_hr')
allocate(shift_vec(3,nrpts_cut),stat=ierr)
if (ierr/=0) call io_error('Error in allocating shift_vec in plot_cut_hr')
nrpts_tmp = 0
do n1 = -irvec_max(1), irvec_max(1)
do n2 = -irvec_max(2), irvec_max(2)
loop_n3: do n3 = -irvec_max(3), irvec_max(3)
do irpt = 1, nrpts
i1 = mod(n1 - irvec(1,irpt),mp_grid(1))
i2 = mod(n2 - irvec(2,irpt),mp_grid(2))
i3 = mod(n3 - irvec(3,irpt),mp_grid(3))
if (i1.eq.0 .and. i2.eq.0 .and. i3.eq.0 ) then
nrpts_tmp = nrpts_tmp+1
ham_r_cut(:,:,nrpts_tmp) = ham_r(:,:,irpt)
irvec_cut(1,nrpts_tmp)=n1
irvec_cut(2,nrpts_tmp)=n2
irvec_cut(3,nrpts_tmp)=n3
cycle loop_n3
end if
end do
end do loop_n3
end do
end do
if ( nrpts_tmp .ne. nrpts_cut) then
write(stdout,'(a)') 'FAILED TO EXPAND ham_r'
call io_error('Error in plot_cut_hr')
end if
! AAM: 29/10/2009 Bug fix thanks to Dr Shujun Hu, NIMS, Japan.
do irpt = 1, nrpts_cut
! line below is incorrect for non-orthorhombic cells
!shift_vec(:,irpt) = matmul(real_lattice(:,:),real(irvec_cut(:,irpt),dp))
! line below is the same as calculating
! matmul(transpose(real_lattice(:,:)),irvec_cut(:,irpt))
shift_vec(:,irpt) = matmul(real(irvec_cut(:,irpt),dp),real_lattice(:,:))
end do
! note: dist_cutoff_mode does not necessarily follow bands_plot_dim
! e.g. for 1-d system (bands_plot_dim=1) we can still apply 3-d dist_cutoff (dist_cutoff_mode=three_dim)
if (index(dist_cutoff_mode, 'one_dim')>0) then
do i=1,num_wann
do j=1,num_wann
dist_ij_vec(one_dim_dir)= &
wannier_centres_translated(one_dim_dir,i) - wannier_centres_translated(one_dim_dir,j)
do irpt =1, nrpts_cut
dist_vec(one_dim_dir) = dist_ij_vec(one_dim_dir)+ shift_vec(one_dim_dir,irpt)
dist = abs(dist_vec(one_dim_dir))
if ( dist .gt. dist_cutoff ) &
ham_r_cut(j,i,irpt) = cmplx_0
end do
end do
end do
else if (index(dist_cutoff_mode, 'two_dim')>0) then
do i=1,num_wann
do j=1,num_wann
dist_ij_vec(:)=wannier_centres_translated(:,i) - wannier_centres_translated(:,j)
do irpt =1, nrpts_cut
dist_vec(:) = dist_ij_vec(:)+ shift_vec(:,irpt)
dist_vec(one_dim_dir) = 0.0_dp
dist = sqrt(dot_product(dist_vec,dist_vec))
if ( dist .gt. dist_cutoff ) &
ham_r_cut(j,i,irpt) = cmplx_0
end do
end do
end do
else
do i=1,num_wann
do j=1,num_wann
dist_ij_vec(:)=wannier_centres_translated(:,i) - wannier_centres_translated(:,j)
do irpt =1, nrpts_cut
dist_vec(:) = dist_ij_vec(:)+ shift_vec(:,irpt)
dist = sqrt(dot_product(dist_vec,dist_vec))
if ( dist .gt. dist_cutoff ) &
ham_r_cut(j,i,irpt) = cmplx_0
end do
end do
end do
end if
do irpt = 1,nrpts_cut
do i=1, num_wann
do j=1,num_wann
if (abs(ham_r_cut(j,i,irpt)) .lt. hr_cutoff) &
ham_r_cut(j,i,irpt) = cmplx_0
end do
end do
end do
write(stdout,'(/1x,a78)') repeat('-',78)
write(stdout,'(1x,4x,a)') &
'Maximum absolute value of Real-space Hamiltonian at each lattice point'
write(stdout,'(1x,8x,a62)') repeat('-',62)
write(stdout,'(1x,11x,a,11x,a)') 'Lattice point R', 'Max |H_ij(R)|'
! output maximum ham_r_cut at each lattice point
do irpt = 1, nrpts_cut
ham_r_tmp(:,:)=abs(ham_r_cut(:,:,irpt))
write(stdout,'(1x,9x,3I5,9x,F12.6)') irvec_cut(:,irpt),maxval(ham_r_tmp)
end do
!
return
end subroutine plot_cut_hr
!============================================!
subroutine plot_interpolate_gnuplot
!============================================!
! !
!! Plots the interpolated band structure in gnuplot format
!============================================!
use w90_constants, only : dp
use w90_io, only : io_file_unit,seedname
use w90_parameters, only : num_wann,bands_num_spec_points, &
bands_label,num_bands_project
implicit none
!
bndunit=io_file_unit()
open(bndunit,file=trim(seedname)//'_band.dat',form='formatted')
gnuunit=io_file_unit()
open(gnuunit,file=trim(seedname)//'_band.gnu',form='formatted')
!
! Gnuplot format
!
do i=1,num_wann
do nkp=1,total_pts
if(num_bands_project>0) then
write(bndunit,'(3E16.8)') xval(nkp),eig_int(i,nkp),bands_proj(i,nkp)
else
write(bndunit,'(2E16.8)') xval(nkp),eig_int(i,nkp)
end if
enddo
write(bndunit,*) ' '
enddo
close(bndunit)
! Axis labels
glabel(1)=' '//bands_label(1)//' '
do i=2,num_paths
if(bands_label(2*(i-1))/=bands_label(2*(i-1)+1)) then
glabel(i)=bands_label(2*(i-1))//'/'//bands_label(2*(i-1)+1)
else
glabel(i)=' '//bands_label(2*(i-1))//' '
end if
end do
glabel(num_spts)=' '//bands_label(bands_num_spec_points)//' '
! gnu file
write(gnuunit,701) xval(total_pts),emin,emax
do i = 1, num_paths-1
write(gnuunit,705) sum(kpath_len(1:i)),emin,sum(kpath_len(1:i)),emax
enddo
write(gnuunit,702, advance="no") glabel(1),0.0_dp,(glabel(i+1),sum(kpath_len(1:i)),i=1,bands_num_spec_points/2-1)
write(gnuunit,703) glabel(1+bands_num_spec_points/2),sum(kpath_len(:))
write(gnuunit,*) 'plot ','"'//trim(seedname)//'_band.dat','"'
close(gnuunit)
if(num_bands_project>0) then
gnuunit=io_file_unit()
open(gnuunit,file=trim(seedname)//'_band_proj.gnu',form='formatted')
write(gnuunit,'(a)') '#File to plot a colour-mapped Bandstructure'
write(gnuunit,'(a)') 'set palette defined ( 0 "blue", 3 "green", 6 "yellow", 10 "red" )'
write(gnuunit,'(a)') 'unset ztics'
write(gnuunit,'(a)') 'unset key'
write(gnuunit,'(a)') '# can make pointsize smaller (~0.5). Too small and nothing is printed'
write(gnuunit,'(a)') 'set pointsize 0.8'
write(gnuunit,'(a)') 'set grid xtics'
write(gnuunit,'(a)') 'set view 0,0'
write(gnuunit,'(a,f9.5,a)') 'set xrange [0:',xval(total_pts),']'
write(gnuunit,'(a,f9.5,a,f9.5,a)') 'set yrange [',emin,':',emax,']'
write(gnuunit,702, advance="no") glabel(1),0.0_dp,(glabel(i+1),sum(kpath_len(1:i)),i=1,bands_num_spec_points/2-1)
write(gnuunit,703) glabel(1+bands_num_spec_points/2),sum(kpath_len(:))
write(gnuunit,'(a,a,a,a)') 'splot ','"'//trim(seedname)//'_band.dat','"',' u 1:2:3 w p pt 13 palette'
write(gnuunit,'(a)') '#use the next lines to make a nice figure for a paper'
write(gnuunit,'(a)') '#set term postscript enhanced eps color lw 0.5 dl 0.5'
write(gnuunit,'(a)') '#set pointsize 0.275'
end if
!
701 format('set style data dots',/,'set nokey',/, 'set xrange [0:',F8.5,']',/,'set yrange [',F9.5,' :',F9.5,']')
702 format('set xtics (',:20('"',A3,'" ',F8.5,','))
703 format(A3,'" ',F8.5,')')
705 format('set arrow from ',F8.5,',',F10.5,' to ',F8.5,',',F10.5, ' nohead')
end subroutine plot_interpolate_gnuplot
subroutine plot_interpolate_xmgrace
!============================================!
! !
!! Plots the interpolated band structure in Xmgrace format
!============================================!
use w90_io, only : io_file_unit,seedname,io_date
use w90_parameters, only : num_wann,bands_num_spec_points
implicit none
character (len=9) :: cdate, ctime
call io_date(cdate, ctime)
! Axis labels
! Switch any G to Gamma
do i=1,bands_num_spec_points
if(bands_label(i)=='G') then
ctemp(i)='\xG\0'
else
ctemp(i)=bands_label(i)
end if
end do
xlabel(1)=' '//trim(ctemp(1))//' '
do i=2,num_paths
if(ctemp(2*(i-1))/=ctemp(2*(i-1)+1)) then
xlabel(i)=trim(ctemp(2*(i-1)))//'/'//trim(ctemp(2*(i-1)+1))
else
xlabel(i)=ctemp(2*(i-1))
end if
end do
xlabel(num_spts)=ctemp(bands_num_spec_points)
gnuunit=io_file_unit()
open(gnuunit,file=trim(seedname)//'_band.agr',form='formatted')
!
! Xmgrace format
!
write(gnuunit,'(a)') '# Grace project file '
write(gnuunit,'(a)') '# written using Wannier90 www.wannier.org '
write(gnuunit,'(a)') '@version 50113 '
write(gnuunit,'(a)') '@page size 792, 612 '
write(gnuunit,'(a)') '@page scroll 5% '
write(gnuunit,'(a)') '@page inout 5% '
write(gnuunit,'(a)') '@link page off '
write(gnuunit,'(a)') '@timestamp def "'//cdate//' at '//ctime//'" '
write(gnuunit,'(a)') '@with g0'
write(gnuunit,'(a)') '@ world xmin 0.00'
write(gnuunit,'(a,f10.5)') '@ world xmax ',xval(total_pts)
write(gnuunit,'(a,f10.5)') '@ world ymin ',emin
write(gnuunit,'(a,f10.5)') '@ world ymax ',emax
write(gnuunit,'(a)') '@default linewidth 1.5'
write(gnuunit,'(a)') '@ xaxis tick on'
write(gnuunit,'(a)') '@ xaxis tick major 1'
write(gnuunit,'(a)') '@ xaxis tick major color 1'
write(gnuunit,'(a)') '@ xaxis tick major linestyle 3'
write(gnuunit,'(a)') '@ xaxis tick major grid on'
write(gnuunit,'(a)') '@ xaxis tick spec type both'
write(gnuunit,'(a,i0)') '@ xaxis tick spec ',1+bands_num_spec_points/2
write(gnuunit,'(a)') '@ xaxis tick major 0, 0'
do i=1,bands_num_spec_points/2
write(gnuunit,'(a,i0,a,a)') '@ xaxis ticklabel ',i-1,',', '"'//trim(adjustl(xlabel(i)))//'"'
write(gnuunit,'(a,i0,a,f10.5)') '@ xaxis tick major ',i,' , ',sum(kpath_len(1:i))
end do
write(gnuunit,'(a,i0,a)') '@ xaxis ticklabel ',bands_num_spec_points/2 &
,',"'//trim(adjustl(xlabel(1+bands_num_spec_points/2)))//'"'
write(gnuunit,'(a)') '@ xaxis ticklabel char size 1.500000'
write(gnuunit,'(a)') '@ yaxis tick major 10'
write(gnuunit,'(a)') '@ yaxis label "Band Energy (eV)"'
write(gnuunit,'(a)') '@ yaxis label char size 1.500000'
write(gnuunit,'(a)') '@ yaxis ticklabel char size 1.500000'
do i=1,num_wann
write(gnuunit,'(a,i0,a)') '@ s',i-1,' line color 1'
end do
do i=1,num_wann
write(gnuunit,'(a,i0)') '@target G0.S',i-1
write(gnuunit,'(a)') '@type xy'
do nkp=1,total_pts
write(gnuunit,'(2E16.8)') xval(nkp),eig_int(i,nkp)
end do
write(gnuunit,'(a,i0)') '&'
end do
end subroutine plot_interpolate_xmgrace
end subroutine plot_interpolate_bands
!===========================================================!
subroutine plot_fermi_surface
!===========================================================!
! !
!! Prepares a Xcrysden bxsf file to view the fermi surface
! !
!===========================================================!
use w90_constants, only : dp,cmplx_0,cmplx_i,twopi
use w90_io, only : io_error,stdout,io_file_unit,seedname,&
io_date,io_time,io_stopwatch
use w90_parameters, only : num_wann,fermi_surface_num_points,timing_level,&
recip_lattice,nfermi,fermi_energy_list
use w90_hamiltonian, only : irvec,nrpts,ndegen,ham_r
implicit none
complex(kind=dp) ,allocatable :: ham_pack(:)
complex(kind=dp) :: fac
complex(kind=dp) ,allocatable :: ham_kprm(:,:)
complex(kind=dp) ,allocatable :: U_int(:,:)
complex(kind=dp) ,allocatable :: cwork(:)
real(kind=dp) ,allocatable :: rwork(:)
real(kind=dp),allocatable :: eig_int(:,:)
real(kind=dp) :: rdotk,time0
integer, allocatable :: iwork(:),ifail(:)
integer :: loop_x,loop_y,loop_z,INFO,ikp,i,j,ierr
integer :: irpt,nfound,npts_plot,loop_kpt,bxsf_unit
character(len=9) :: cdate, ctime
!
if (timing_level>1) call io_stopwatch('plot: fermi_surface',1)
time0=io_time()
write(stdout,*)
write(stdout,'(1x,a)') 'Calculating Fermi surface'
write(stdout,*)
!
if(nfermi>1) call io_error("Error in plot: nfermi>1. Set the fermi level "&
//"using the input parameter 'fermi_level'")
!
allocate(ham_pack((num_wann*(num_wann+1))/2),stat=ierr)
if (ierr/=0) call io_error('Error in allocating ham_pack plot_fermi_surface')
allocate(ham_kprm(num_wann,num_wann),stat=ierr)
if (ierr/=0) call io_error('Error in allocating ham_kprm plot_fermi_surface')
allocate(U_int(num_wann,num_wann),stat=ierr)
if (ierr/=0) call io_error('Error in allocating U_int in plot_fermi_surface')
allocate(cwork(2*num_wann),stat=ierr)
if (ierr/=0) call io_error('Error in allocating cwork in plot_fermi_surface')
allocate(rwork(7*num_wann),stat=ierr)
if (ierr/=0) call io_error('Error in allocating rwork in plot_fermi_surface')
allocate(iwork(5*num_wann),stat=ierr)
if (ierr/=0) call io_error('Error in allocating iwork in plot_fermi_surface')
allocate(ifail(num_wann),stat=ierr)
if (ierr/=0) call io_error('Error in allocating ifail in plot_fermi_surface')
!
npts_plot=(fermi_surface_num_points+1)**3
allocate(eig_int(num_wann,npts_plot),stat=ierr)
if (ierr/=0) call io_error('Error in allocating eig_int in plot_fermi_surface')
eig_int=0.0_dp
U_int=(0.0_dp,0.0_dp)
!
ikp=0
do loop_x=1,fermi_surface_num_points+1
do loop_y=1,fermi_surface_num_points+1
do loop_z=1,fermi_surface_num_points+1
ikp=ikp+1
ham_kprm=cmplx_0
do irpt=1,nrpts
rdotk=twopi*real( (loop_x-1)*irvec(1,irpt)+ &
(loop_y-1)*irvec(2,irpt) + (loop_z-1)* &
irvec(3,irpt) ,dp)/real(fermi_surface_num_points,dp)
fac=cmplx(cos(rdotk),sin(rdotk),dp)/real(ndegen(irpt),dp)
ham_kprm=ham_kprm+fac*ham_r(:,:,irpt)
end do
! Diagonalise H_k (->basis of eigenstates)
do j=1,num_wann
do i=1,j
ham_pack(i+((j-1)*j)/2)=ham_kprm(i,j)
enddo
enddo
call ZHPEVX('N','A','U',num_wann,ham_pack,0.0_dp,0.0_dp,0,0,-1.0_dp, &
nfound,eig_int(1,ikp),U_int,num_wann,cwork,rwork,iwork,ifail,info)
if(info < 0) then
write(stdout,'(a,i3,a)') 'THE ',-info, ' ARGUMENT OF ZHPEVX HAD AN ILLEGAL VALUE'
call io_error('Error in plot_fermi_surface')
endif
if(info > 0) then
write(stdout,'(i3,a)') info,' EIGENVECTORS FAILED TO CONVERGE'
call io_error('Error in plot_fermi_surface')
endif
end do
end do
end do
call io_date(cdate, ctime)
bxsf_unit=io_file_unit()
open(bxsf_unit,FILE=trim(seedname)//'.bxsf',STATUS='UNKNOWN',FORM='FORMATTED')
write(bxsf_unit,*) ' BEGIN_INFO'
write(bxsf_unit,*) ' #'
write(bxsf_unit,*) ' # this is a Band-XCRYSDEN-Structure-File'
write(bxsf_unit,*) ' # for Fermi Surface Visualisation'
write(bxsf_unit,*) ' #'
write(bxsf_unit,*) ' # Generated by the Wannier90 code http://www.wannier.org'
write(bxsf_unit,*) ' # On ',cdate,' at ',ctime
write(bxsf_unit,*) ' #'
write(bxsf_unit,*) ' Fermi Energy:', fermi_energy_list(1)
write(bxsf_unit,*) ' END_INFO'
write(bxsf_unit,*)
write(bxsf_unit,*) ' BEGIN_BLOCK_BANDGRID_3D'
write(bxsf_unit,*) 'from_wannier_code'
write(bxsf_unit,*) ' BEGIN_BANDGRID_3D_fermi'
write(bxsf_unit,*) num_wann
write(bxsf_unit,*) fermi_surface_num_points+1,fermi_surface_num_points+1,fermi_surface_num_points+1
write(bxsf_unit,*) '0.0 0.0 0.0'
write(bxsf_unit,*) (recip_lattice(1,i), i=1,3)
write(bxsf_unit,*) (recip_lattice(2,i), i=1,3)
write(bxsf_unit,*) (recip_lattice(3,i), i=1,3)
do i=1,num_wann
write(bxsf_unit,*) 'BAND: ',i
do loop_kpt=1,npts_plot
write(bxsf_unit,'(2E16.8)') eig_int(i,loop_kpt)
enddo
enddo
write(bxsf_unit,*) 'END_BANDGRID_3D'
write(bxsf_unit,*) ' END_BLOCK_BANDGRID_3D'
close(bxsf_unit)
write(stdout,'(1x,a,f11.3,a)') 'Time to calculate interpolated Fermi surface ',io_time()-time0,' (sec)'
write(stdout,*)
!
if (timing_level>1) call io_stopwatch('plot: fermi_surface',2)
!
return
end subroutine plot_fermi_surface
!============================================!
subroutine plot_wannier
!============================================!
! !
!! Plot the WF in Xcrysden format
!! based on code written by Michel Posternak
! !
!============================================!
use w90_constants, only : dp,cmplx_0,cmplx_i,twopi,cmplx_1
use w90_io, only : io_error,stdout,io_file_unit,seedname, &
io_date,io_stopwatch
use w90_parameters, only : num_wann,num_bands,num_kpts,u_matrix,spin, &
ngs=>wannier_plot_supercell,kpt_latt,num_species,atoms_species_num, &
atoms_symbol,atoms_pos_cart,num_atoms,real_lattice,have_disentangled, &
ndimwin,lwindow,u_matrix_opt,num_wannier_plot,wannier_plot_list, &
wannier_plot_mode,wvfn_formatted,timing_level,wannier_plot_format, &
spinors, wannier_plot_spinor_mode, wannier_plot_spinor_phase
implicit none
real(kind=dp) :: scalfac,tmax,tmaxx,x_0ang,y_0ang,z_0ang
real(kind=dp) :: fxcry(3),dirl(3,3),w_real,w_imag,ratmax,ratio
real(kind=dp) :: upspinor, dnspinor,upphase,dnphase
complex(kind=dp), allocatable :: wann_func(:,:,:,:)
complex(kind=dp), allocatable :: r_wvfn(:,:)
complex(kind=dp), allocatable :: r_wvfn_tmp(:,:)
complex(kind=dp), allocatable :: wann_func_nc(:,:,:,:,:) ! add the spinor dim.
complex(kind=dp), allocatable :: r_wvfn_nc(:,:,:) ! add the spinor dim.
complex(kind=dp), allocatable :: r_wvfn_tmp_nc(:,:,:) ! add the spinor dim.
complex(kind=dp) :: catmp,wmod
logical :: have_file
integer :: i,j,nsp,nat,nbnd,counter,ierr
integer :: loop_kpt,ik,ix,iy,iz,nk,ngx,ngy,ngz,nxx,nyy,nzz
integer :: loop_b,nx,ny,nz,npoint,file_unit,loop_w,num_inc
integer :: ispinor
character(len=11) :: wfnname
character(len=60) :: wanxsf,wancube
character(len=9) :: cdate, ctime
logical :: inc_band(num_bands)
!
if (timing_level>1) call io_stopwatch('plot: wannier',1)
!
if (.not.spinors) then
write(wfnname,200 ) 1,spin
else
write(wfnname,199 ) 1
endif
inquire(file=wfnname,exist=have_file)
if(.not.have_file) call io_error('plot_wannier: file '//wfnname//' not found')
file_unit=io_file_unit()
if(wvfn_formatted) then
open(unit=file_unit,file=wfnname,form='formatted')
read(file_unit,*) ngx,ngy,ngz,nk,nbnd
else
open(unit=file_unit,file=wfnname,form='unformatted')
read(file_unit) ngx,ngy,ngz,nk,nbnd
end if
close(file_unit)
200 format ('UNK',i5.5,'.',i1)
199 format ('UNK',i5.5,'.','NC')
allocate(wann_func(-((ngs(1))/2)*ngx:((ngs(1)+1)/2)*ngx-1,&
-((ngs(2))/2)*ngy:((ngs(2)+1)/2)*ngy-1,&
-((ngs(3))/2)*ngz:((ngs(3)+1)/2)*ngz-1,num_wannier_plot),stat=ierr )
if (ierr/=0) call io_error('Error in allocating wann_func in plot_wannier')
wann_func=cmplx_0
if (spinors) then
allocate(wann_func_nc(-((ngs(1))/2)*ngx:((ngs(1)+1)/2)*ngx-1,&
-((ngs(2))/2)*ngy:((ngs(2)+1)/2)*ngy-1,&
-((ngs(3))/2)*ngz:((ngs(3)+1)/2)*ngz-1,2,num_wannier_plot),stat=ierr )
if (ierr/=0) call io_error('Error in allocating wann_func_nc in plot_wannier')
wann_func_nc=cmplx_0
endif
if (.not.spinors) then
if(have_disentangled) then
allocate(r_wvfn_tmp(ngx*ngy*ngz,maxval(ndimwin)),stat=ierr )
if (ierr/=0) call io_error('Error in allocating r_wvfn_tmp in plot_wannier')
end if
allocate(r_wvfn(ngx*ngy*ngz,num_wann),stat=ierr )
if (ierr/=0) call io_error('Error in allocating r_wvfn in plot_wannier')
else
if(have_disentangled) then
allocate(r_wvfn_tmp_nc(ngx*ngy*ngz,maxval(ndimwin),2),stat=ierr )
if (ierr/=0) call io_error('Error in allocating r_wvfn_tmp_nc in plot_wannier')
end if
allocate(r_wvfn_nc(ngx*ngy*ngz,num_wann,2),stat=ierr )
if (ierr/=0) call io_error('Error in allocating r_wvfn_nc in plot_wannier')
endif
call io_date(cdate, ctime)
do loop_kpt=1,num_kpts
inc_band=.true.
num_inc=num_wann
if(have_disentangled) then
inc_band(:)=lwindow(:,loop_kpt)
num_inc=ndimwin(loop_kpt)
end if
if (.not.spinors) then
write(wfnname,200 ) loop_kpt,spin
else
write(wfnname,199 ) loop_kpt
endif
file_unit=io_file_unit()
if(wvfn_formatted) then
open(unit=file_unit,file=wfnname,form='formatted')
read(file_unit,*) ix,iy,iz,ik,nbnd
else
open(unit=file_unit,file=wfnname,form='unformatted')
read(file_unit) ix,iy,iz,ik,nbnd
end if
if ( (ix/=ngx) .or. (iy/=ngy) .or. (iz/=ngz) .or. (ik/=loop_kpt) ) then
write(stdout,'(1x,a,a)') 'WARNING: mismatch in file',trim(wfnname)
write(stdout,'(1x,5(a6,I5))') ' ix=',ix ,' iy=',iy ,' iz=',iz ,' ik=',ik ,' nbnd=',nbnd
write(stdout,'(1x,5(a6,I5))') ' ngx=',ngx,' ngy=',ngy,' ngz=',ngz,' kpt=',loop_kpt,'bands=',num_bands
call io_error('plot_wannier')
end if
if(have_disentangled) then
counter=1
do loop_b=1,num_bands
if(counter>num_inc) exit
if(wvfn_formatted) then
do nx=1,ngx*ngy*ngz
read(file_unit,*) w_real, w_imag
if (.not.spinors) then
r_wvfn_tmp(nx,counter) = cmplx(w_real,w_imag,kind=dp)
else
r_wvfn_tmp_nc(nx,counter,1) = cmplx(w_real,w_imag,kind=dp) ! up-spinor
endif
end do
if (spinors) then
do nx=1,ngx*ngy*ngz
read(file_unit,*) w_real, w_imag
r_wvfn_tmp_nc(nx,counter,2) = cmplx(w_real,w_imag,kind=dp) ! down-spinor
end do
endif
else
if (.not.spinors) then
read(file_unit) (r_wvfn_tmp(nx,counter),nx=1,ngx*ngy*ngz)
else
read(file_unit) (r_wvfn_tmp_nc(nx,counter,1),nx=1,ngx*ngy*ngz) ! up-spinor
read(file_unit) (r_wvfn_tmp_nc(nx,counter,2),nx=1,ngx*ngy*ngz) ! down-spinor
endif
end if
if(inc_band(loop_b)) counter=counter+1
end do
else
do loop_b=1,num_bands