20
logical :: gamma_wfsx, got_qcos
20
logical :: gamma_wfsx, got_qcos, non_coll
21
21
integer :: ii1, ii2, ind, ind_red, no1, no2, n_int, nnz
22
integer :: imin, imax, wfs_spin_flag, nspin_blocks
24
complex(DP), dimension(2) :: spinor_1, spinor_2, H_c2
25
complex(DP), dimension(2,2) :: H
26
complex(DP) :: c_c1_c2, c_c1_H_c2
27
real(dp) :: factor_S, factor_H, dos_value
25
29
! We use a smearing function of the form f(x) = exp(-(x/smear)**2) / (smear*sqrt(pi))
26
30
! A weight tolerance of 1.0e-4 corresponds to going about 3*smear on either
136
140
read(wfs_u) nkp, gamma_wfsx
137
141
allocate (wk(nkp), pk(3,nkp))
143
read(wfs_u) wfs_spin_flag ! 1, 2, or 4
144
non_coll = (wfs_spin_flag == 4)
141
146
read(wfs_u) !! Symbols, etc
142
if (debug) print *, "WFSX read: nkp, nsp, nnao: ", nkp, nsp, nao
144
allocate (ados(npts_energy,nsp), ww(npts_energy))
147
if (debug) print *, "WFSX read: nkp, nspin_flag, nnao: ", nkp, wfs_spin_flag, nao
152
nspin_blocks = wfs_spin_flag
154
print *, "NSPIN BLOCKS: ", nspin_blocks
156
allocate (ados(npts_energy,nspin_blocks), ww(npts_energy))
500
507
!=====================
503
allocate (coop_vals(npts_energy,nsp,ncb))
504
allocate (cohp_vals(npts_energy,nsp,ncb))
505
coop_vals(:,:nsp,:ncb)=0.d0
506
cohp_vals(:,:nsp,:ncb)=0.d0
510
allocate (coop_vals(npts_energy,nspin_blocks,ncb))
511
allocate (cohp_vals(npts_energy,nspin_blocks,ncb))
512
coop_vals(:,:,:)=0.d0
513
cohp_vals(:,:,:)=0.d0
509
allocate (pdos_vals(npts_energy,nsp,ncb))
510
pdos_vals(:,:nsp,:ncb) = 0.0_dp
516
allocate (pdos_vals(npts_energy,nspin_blocks,ncb))
517
pdos_vals(:,:,:) = 0.0_dp
513
ados(:,:nsp) = 0.0_dp
515
522
!================================================================
520
allocate(wf(1,1:no_u))
526
! The first dimension is the number of real numbers per orbital
527
! 1 for real wfs, 2 for complex, and four for the two spinor components
530
allocate(wf_single(4,1:no_u))
531
allocate(wf(4,1:no_u))
522
allocate(wf(2,1:no_u))
534
allocate(wf_single(1,1:no_u))
535
allocate(wf(1,1:no_u))
537
allocate(wf_single(2,1:no_u))
538
allocate(wf(2,1:no_u))
525
541
allocate (mask2(1:no_u))
670
687
ind_red = ptr(i1)+i2
671
688
io2 = list_io2(ind_red)
672
689
ind = list_ind(ind_red)
674
! (qcos, qsin) = C_1*conjg(C_2)
675
!AG: Corrected: (qcos, qsin) = conjg(C_1)*(C_2)
676
! We might want to avoid recomputing this
679
qcos = wf(1,io1)*wf(1,io2)
691
! (qcos, qsin) = conjg(C_1) * [S or H] * C_2
692
! We might want to avoid recomputing the "S" pure wf parts
696
! Use 'dp' to keep the wfs in double precision
697
! (Recall that wf() is now dp; converted right after reading)
698
spinor_1 = [ cmplx(wf(1,io1),wf(2,io1), dp), &
699
cmplx(wf(3,io1),wf(4,io1), dp) ]
700
spinor_2 = [ cmplx(wf(1,io2),wf(2,io2), dp), &
701
cmplx(wf(3,io2),wf(4,io2), dp) ]
703
! We take the signs for 1,2 and 2,1
704
! from the construction of Ebs_Haux in 'compute_energies'
705
if (h_spin_dim == 8) then
706
H(1,1) = cmplx(Hamilt(ind,1), Hamilt(ind,5), dp)
707
H(1,2) = cmplx(Hamilt(ind,3), -Hamilt(ind,4), dp)
708
H(2,1) = cmplx(Hamilt(ind,7), Hamilt(ind,8), dp)
709
H(2,2) = cmplx(Hamilt(ind,2), Hamilt(ind,6), dp)
710
else ! nsp=4; just non-collinear; no SOC
711
H(1,1) = cmplx(Hamilt(ind,1), 0.0_dp, dp)
712
H(1,2) = cmplx(Hamilt(ind,3), -Hamilt(ind,4), dp)
713
H(2,1) = cmplx(Hamilt(ind,3), Hamilt(ind,4), dp)
714
H(2,2) = cmplx(Hamilt(ind,2), 0.0_dp, dp)
717
! For DOS/COOP, take as weight the "complete spinor" product
718
! The dot_product is directly sum(conjg(a1)*a2) for complex arrays
719
! The kind returned is "the highest" of the arguments. In this case,
720
! it will be 'dp' if the 'spinor_X' variables are 'dp'.
721
c_c1_c2 = dot_product(spinor_1,spinor_2)
722
qcos= real(c_c1_c2, dp)
725
! For COHP, insert non-trivial H matrix
726
H_c2 = matmul( H, spinor_2 )
727
c_c1_H_c2 = dot_product( spinor_1, H_c2 )
728
qcos_H= real(c_c1_H_c2, dp)
729
qsin_H= aimag(c_c1_H_c2)
682
qcos= (wf(1,io1)*wf(1,io2) + &
684
qsin= (wf(1,io1)*wf(2,io2) - &
732
! These have explicit spin quantum numbers (is)
734
qcos = wf(1,io1)*wf(1,io2)
736
qcos_H = qcos * Hamilt(ind,is)
739
qcos = (wf(1,io1)*wf(1,io2) + &
741
qcos_H = qcos * Hamilt(ind,is)
742
qsin = (wf(1,io1)*wf(2,io2) - &
744
qsin_H = qsin * Hamilt(ind,is)
689
alfa=dot_product(pk(1:3,ik),xij(1:3,ind))
749
alfa=dot_product(pk(1:3,ik),xij(1:3,ind))
691
! Crb = Real(C_1*conjg(C_2)*exp(-i*alfa)) * S_12
692
!AG: This one better -- or Real(conjg(C_1)*C_2)*exp(+i*alfa)) * S_12
693
! Common factor computed here
694
factor = (qcos*cos(alfa)-qsin*sin(alfa)) * wk(ik)
751
! Crb = Real(C_1*conjg(C_2)*exp(-i*alfa)) * S_12
752
! or Real(conjg(C_1)*C_2)*exp(+i*alfa)) * S_12
753
! Common factor computed here
754
factor_S = Sover(ind) * (qcos*cos(alfa)-qsin*sin(alfa)) * wk(ik)
755
factor_H = (qcos_H*cos(alfa)-qsin_H*sin(alfa)) * wk(ik)
697
758
! Note that there is no factor of 2
698
759
do i = imin, imax
699
pdos_vals(i,is,ic)=pdos_vals(i,is,ic) + Sover(ind)*factor*ww(i)
760
pdos_vals(i,is,ic)=pdos_vals(i,is,ic) + factor_S * ww(i)
704
765
!! COOP is basically the off-diagonal DOS, chosen on the basis of particular bonds
705
766
do i = imin, imax
706
coop_vals(i,is,ic)=coop_vals(i,is,ic) + Sover(ind) * factor * ww(i)
707
cohp_vals(i,is,ic)=cohp_vals(i,is,ic) + hamilt(ind,is) * factor * ww(i)
767
coop_vals(i,is,ic)=coop_vals(i,is,ic) + factor_S * ww(i)
768
cohp_vals(i,is,ic)=cohp_vals(i,is,ic) + factor_H * ww(i)
720
781
deallocate (list_io2)
721
782
deallocate (list_ind)
726
open(tab_u,file=trim(mflnm)// "." // trim(tit(ic)) // '.pdos')
727
write(tab_u,"(a1,14x,'ENERGY',4(16x,a1,i1))") '#', ("s",m, m=1,nsp)
729
energy = low_e + e_step*(i-1)
730
write(tab_u,"(f20.8,10(2f13.8,5x))") & ! Spin in loop
731
energy, (pdos_vals(i,is,ic),is=1,nspin)
787
call write_curve_to_file(trim(mflnm)// "." // trim(tit(ic)) // '.pdos', &
740
open(tab_u,file=trim(mflnm)// "." // trim(tit(ic)) // '.coop')
741
write(tab_u,"(a1,14x,'ENERGY',4(16x,a1,i1))") '#', ("s",m, m=1,nsp)
743
energy = low_e + e_step*(i-1)
744
write(tab_u,"(f20.8,10(2f13.8,5x))") & ! Spin in loop
745
energy, (coop_vals(i,is,ic),is=1,nspin)
751
open(tab_u,file=trim(mflnm)// "." // trim(tit(ic)) // '.cohp')
752
write(tab_u,"(a1,14x,'ENERGY',4(16x,a1,i1))") '#', ("s",m, m=1,nsp)
754
energy = low_e + e_step*(i-1)
755
write(tab_u,"(f20.8,10(2f13.8,5x))") & ! Spin in loop
756
energy, (cohp_vals(i,is,ic),is=1,nspin)
791
call write_curve_to_file(trim(mflnm)// "." // trim(tit(ic)) // '.coop', &
793
call write_curve_to_file(trim(mflnm)// "." // trim(tit(ic)) // '.cohp', &
764
799
!--------------------------------------------------------
767
802
! Simple DOS output
770
open(idos,file=trim(sflnm)//".ados",form="formatted", &
771
status="unknown",action="write",position="rewind")
772
write(idos,*) "# Energy SIMPLE DOS"
773
e_step = (high_e-low_e)/(npts_energy-1)
774
do i = 1, npts_energy
775
energy = low_e + e_step*(i-1)
776
! Note division by the number of curves
777
write(idos,*) energy, (ados(i,is)/ncb, is=1,nsp)
804
! Divide by the number of curves
805
call write_curve_to_file(trim(sflnm)//".ados",ados/ncb)
810
subroutine write_curve_to_file(filename,array)
811
character(len=*), intent(in) :: filename
812
real(dp), intent(in) :: array(:,:)
817
! tab_u, low_e, e_step, npts_energy by host association
819
open(tab_u,file=trim(filename))
823
select case ( wfs_spin_flag)
825
! Two identical 'spin' columns, and the sum (complete value) in the third column
826
write(tab_u,"(a1,12x,'ENERGY',3(14x,a))") '#', 's1', 's2=s1', 'total'
828
! Two 'spin' columns, and the sum (complete value) in the third column
829
write(tab_u,"(a1,12x,'ENERGY',3(14x,a))") '#', 's1', 's2', 'total'
831
! A single column with the complete value
832
write(tab_u,"(a1,12x,'ENERGY',14x,a)") '#', 'total'
838
energy = low_e + e_step*(i-1)
839
select case ( wfs_spin_flag)
841
! Two identical 'spin' columns, and the sum (complete value) in the third column
842
write(tab_u,"(f20.8,3(5x,f13.8))") &
843
energy, array(i,1), array(i,1), 2*array(i,1)
845
! Two 'spin' columns, and the sum (complete value) in the third column
846
write(tab_u,"(f20.8,3(5x,f13.8))") &
847
energy, (array(i,is),is=1,nspin_blocks), sum(array(i,:))
849
! A single column with the complete value
850
write(tab_u,"(f20.8,5x,f13.8)") energy, array(i,1)
855
end subroutine write_curve_to_file
785
857
function delta(x) result(res)
786
858
real(dp), intent(in) :: x