4
1
mirror of https://github.com/pfloos/quack synced 2024-06-13 16:55:28 +02:00
quack/src/GW/evGW.f90

341 lines
10 KiB
Fortran
Raw Normal View History

2022-11-30 16:41:19 +01:00
subroutine evGW(maxSCF,thresh,max_diis,doACFDT,exchange_kernel,doXBS,COHSEX,BSE,BSE2,TDA_W,TDA,dBSE,dTDA,evDyn,ppBSE, &
2023-06-30 16:47:26 +02:00
singlet,triplet,linearize,eta,regularize,nBas,nC,nO,nV,nR,nS,ENuc,ERHF,ERI_AO,ERI_MO,dipole_int,PHF,cHF,eHF,Vxc,eG0W0)
2019-03-19 10:13:33 +01:00
! Perform self-consistent eigenvalue-only GW calculation
implicit none
include 'parameters.h'
! Input variables
2019-04-02 22:58:24 +02:00
integer,intent(in) :: maxSCF
integer,intent(in) :: max_diis
double precision,intent(in) :: thresh
double precision,intent(in) :: ENuc
double precision,intent(in) :: ERHF
2020-01-14 21:27:34 +01:00
logical,intent(in) :: doACFDT
2020-01-16 21:39:00 +01:00
logical,intent(in) :: exchange_kernel
2020-01-14 21:27:34 +01:00
logical,intent(in) :: doXBS
2019-04-02 22:58:24 +02:00
logical,intent(in) :: COHSEX
logical,intent(in) :: BSE
2022-11-28 10:52:06 +01:00
logical,intent(in) :: BSE2
2020-06-09 21:24:37 +02:00
logical,intent(in) :: TDA_W
2019-04-02 22:58:24 +02:00
logical,intent(in) :: TDA
2020-06-14 21:20:01 +02:00
logical,intent(in) :: dBSE
2020-06-14 13:04:16 +02:00
logical,intent(in) :: dTDA
2020-06-14 21:20:01 +02:00
logical,intent(in) :: evDyn
2022-09-09 21:48:50 +02:00
logical,intent(in) :: ppBSE
2020-09-24 11:56:06 +02:00
logical,intent(in) :: singlet
logical,intent(in) :: triplet
2023-06-30 16:47:26 +02:00
logical,intent(in) :: linearize
2019-09-22 21:15:53 +02:00
double precision,intent(in) :: eta
2021-12-17 11:41:40 +01:00
logical,intent(in) :: regularize
2021-10-18 10:10:54 +02:00
integer,intent(in) :: nBas
integer,intent(in) :: nC
integer,intent(in) :: nO
integer,intent(in) :: nV
integer,intent(in) :: nR
integer,intent(in) :: nS
2021-02-15 17:27:06 +01:00
double precision,intent(in) :: PHF(nBas,nBas)
2019-04-02 22:58:24 +02:00
double precision,intent(in) :: eHF(nBas)
2021-02-15 17:27:06 +01:00
double precision,intent(in) :: cHF(nBas,nBas)
2021-02-15 22:00:19 +01:00
double precision,intent(in) :: Vxc(nBas)
2019-04-02 22:58:24 +02:00
double precision,intent(in) :: eG0W0(nBas)
2021-02-15 17:27:06 +01:00
double precision,intent(in) :: ERI_AO(nBas,nBas,nBas,nBas)
double precision,intent(in) :: ERI_MO(nBas,nBas,nBas,nBas)
double precision,intent(in) :: dipole_int(nBas,nBas,ncart)
2019-03-19 10:13:33 +01:00
! Local variables
2019-04-02 22:58:24 +02:00
logical :: linear_mixing
integer :: ispin
integer :: nSCF
integer :: n_diis
2023-06-30 16:47:26 +02:00
integer :: i,a,jb,p
2019-04-01 15:53:39 +02:00
double precision :: rcond
2019-04-02 22:58:24 +02:00
double precision :: Conv
2020-09-24 11:56:06 +02:00
double precision :: EcRPA
2019-05-04 17:13:50 +02:00
double precision :: EcBSE(nspin)
2020-01-14 22:56:20 +01:00
double precision :: EcAC(nspin)
2022-09-09 21:48:50 +02:00
double precision :: EcppBSE(nspin)
2019-04-02 22:58:24 +02:00
double precision :: EcGM
2020-01-08 10:17:19 +01:00
double precision :: alpha
2023-06-30 16:47:26 +02:00
double precision :: Dpijb,Dpajb
2019-04-02 22:58:24 +02:00
double precision,allocatable :: error_diis(:,:)
double precision,allocatable :: e_diis(:,:)
double precision,allocatable :: eGW(:)
double precision,allocatable :: eOld(:)
double precision,allocatable :: Z(:)
2021-02-15 17:27:06 +01:00
double precision,allocatable :: SigX(:)
2019-04-02 22:58:24 +02:00
double precision,allocatable :: SigC(:)
2020-09-24 11:56:06 +02:00
double precision,allocatable :: OmRPA(:)
double precision,allocatable :: XpY_RPA(:,:)
double precision,allocatable :: XmY_RPA(:,:)
double precision,allocatable :: rho_RPA(:,:,:)
2023-06-30 16:47:26 +02:00
double precision,allocatable :: eGWlin(:)
2019-03-19 10:13:33 +01:00
2022-09-09 21:48:50 +02:00
integer :: nBas2
integer :: nC2
integer :: nO2
integer :: nV2
integer :: nR2
integer :: nS2
double precision,allocatable :: seHF(:),seGW(:),sERI(:,:,:,:)
2019-03-19 10:13:33 +01:00
! Hello world
write(*,*)
write(*,*)'************************************************'
write(*,*)'| Self-consistent evGW calculation |'
write(*,*)'************************************************'
write(*,*)
2019-07-15 14:22:32 +02:00
! COHSEX approximation
2020-09-24 11:56:06 +02:00
if(COHSEX) then
write(*,*) 'COHSEX approximation activated!'
write(*,*)
end if
2019-07-15 14:22:32 +02:00
2020-06-09 21:24:37 +02:00
! TDA for W
2020-09-24 11:56:06 +02:00
if(TDA_W) then
write(*,*) 'Tamm-Dancoff approximation for dynamic screening!'
write(*,*)
end if
2020-06-09 21:24:37 +02:00
! TDA
2020-09-24 11:56:06 +02:00
if(TDA) then
write(*,*) 'Tamm-Dancoff approximation activated!'
write(*,*)
end if
2019-03-19 10:13:33 +01:00
! Linear mixing
linear_mixing = .false.
2020-01-08 10:17:19 +01:00
alpha = 0.2d0
2019-03-19 10:13:33 +01:00
! Memory allocation
2021-02-15 17:27:06 +01:00
allocate(eGW(nBas),eOld(nBas),Z(nBas),SigX(nBas),SigC(nBas),OmRPA(nS),XpY_RPA(nS,nS),XmY_RPA(nS,nS), &
2023-06-30 16:47:26 +02:00
rho_RPA(nBas,nBas,nS),error_diis(nBas,max_diis),e_diis(nBas,max_diis),eGWlin(nBas))
2019-03-19 10:13:33 +01:00
2021-02-15 17:27:06 +01:00
! Compute the exchange part of the self-energy
call self_energy_exchange_diag(nBas,cHF,PHF,ERI_AO,SigX)
2019-03-19 10:13:33 +01:00
! Initialization
nSCF = 0
ispin = 1
n_diis = 0
Conv = 1d0
e_diis(:,:) = 0d0
error_diis(:,:) = 0d0
eGW(:) = eG0W0(:)
eOld(:) = eGW(:)
Z(:) = 1d0
2022-01-06 22:36:30 +01:00
rcond = 0d0
2019-03-19 10:13:33 +01:00
2023-06-30 16:47:26 +02:00
2019-03-19 10:13:33 +01:00
!------------------------------------------------------------------------
! Main loop
!------------------------------------------------------------------------
do while(Conv > thresh .and. nSCF <= maxSCF)
2020-09-24 11:56:06 +02:00
! Compute screening
2019-03-19 10:13:33 +01:00
2022-11-30 16:41:19 +01:00
call linear_response(ispin,.true.,TDA_W,eta,nBas,nC,nO,nV,nR,nS,1d0,eGW,ERI_MO, &
EcRPA,OmRPA,XpY_RPA,XmY_RPA)
2019-03-19 10:13:33 +01:00
2022-11-30 16:41:19 +01:00
! Compute spectral weights
2019-03-19 10:13:33 +01:00
2021-02-15 17:27:06 +01:00
call excitation_density(nBas,nC,nO,nR,nS,ERI_MO,XpY_RPA,rho_RPA)
2019-03-19 10:13:33 +01:00
2022-11-30 16:41:19 +01:00
! Compute correlation part of the self-energy
2019-03-19 10:13:33 +01:00
2022-11-30 16:41:19 +01:00
if(regularize) then
2021-12-17 11:41:40 +01:00
2022-11-30 16:41:19 +01:00
call regularized_self_energy_correlation_diag(COHSEX,eta,nBas,nC,nO,nV,nR,nS,eGW,OmRPA,rho_RPA,EcGM,SigC)
2023-06-30 16:47:26 +02:00
call renormalization_factor_SRG(eta,nBas,nC,nO,nV,nR,nS,eGW,OmRPA,rho_RPA,Z)
2021-12-17 11:41:40 +01:00
2022-11-30 16:41:19 +01:00
else
2021-12-17 11:41:40 +01:00
2022-11-30 16:41:19 +01:00
call self_energy_correlation_diag(COHSEX,eta,nBas,nC,nO,nV,nR,nS,eGW,OmRPA,rho_RPA,EcGM,SigC)
call renormalization_factor(COHSEX,eta,nBas,nC,nO,nV,nR,nS,eGW,OmRPA,rho_RPA,Z)
2021-12-17 11:41:40 +01:00
end if
2019-03-19 10:13:33 +01:00
2020-03-14 23:00:44 +01:00
! Solve the quasi-particle equation
2019-03-19 10:13:33 +01:00
2023-06-30 16:47:26 +02:00
eGWlin(:) = eHF(:) + SigX(:) + SigC(:) - Vxc(:)
! Linearized or graphical solution?
if(linearize) then
write(*,*) ' *** Quasiparticle energies obtained by linearization *** '
write(*,*)
eGW(:) = eGWlin(:)
else
write(*,*) ' *** Quasiparticle energies obtained by root search (experimental) *** '
write(*,*)
call QP_graph(nBas,nC,nO,nV,nR,nS,eta,eHF,SigX,Vxc,OmRPA,rho_RPA,eGWlin,eGW,regularize)
end if
2019-03-19 10:13:33 +01:00
! Convergence criteria
Conv = maxval(abs(eGW - eOld))
! Print results
2020-09-24 11:56:06 +02:00
call print_evGW(nBas,nO,nSCF,Conv,eHF,ENuc,ERHF,SigC,Z,eGW,EcRPA,EcGM)
2019-03-19 10:13:33 +01:00
! Linear mixing or DIIS extrapolation
if(linear_mixing) then
2020-01-08 10:17:19 +01:00
eGW(:) = alpha*eGW(:) + (1d0 - alpha)*eOld(:)
2019-03-19 10:13:33 +01:00
else
n_diis = min(n_diis+1,max_diis)
2021-03-27 15:03:54 +01:00
if(abs(rcond) > 1d-7) then
call DIIS_extrapolation(rcond,nBas,nBas,n_diis,error_diis,e_diis,eGW-eOld,eGW)
else
n_diis = 0
2021-12-17 11:41:40 +01:00
end if
2019-03-19 10:13:33 +01:00
2021-12-17 11:41:40 +01:00
end if
2019-03-19 10:13:33 +01:00
! Save quasiparticles energy for next cycle
eOld(:) = eGW(:)
! Increment
nSCF = nSCF + 1
2021-12-17 11:41:40 +01:00
end do
2019-03-19 10:13:33 +01:00
!------------------------------------------------------------------------
! End main loop
!------------------------------------------------------------------------
! Plot stuff
2020-01-15 22:29:43 +01:00
! call plot_GW(nBas,nC,nO,nV,nR,nS,eHF,eGW,Omega(:,ispin),rho(:,:,:,ispin),rhox(:,:,:,ispin))
2019-03-19 10:13:33 +01:00
! Did it actually converge?
if(nSCF == maxSCF+1) then
write(*,*)
write(*,*)'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'
write(*,*)' Convergence failed '
write(*,*)'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'
write(*,*)
2020-06-03 12:46:26 +02:00
stop
2019-03-19 10:13:33 +01:00
2021-12-17 11:41:40 +01:00
end if
2019-03-19 10:13:33 +01:00
2020-09-24 11:56:06 +02:00
! Deallocate memory
2020-01-15 22:29:43 +01:00
2020-09-24 11:56:06 +02:00
deallocate(eOld,Z,SigC,OmRPA,XpY_RPA,XmY_RPA,rho_RPA,error_diis,e_diis)
2020-01-15 22:29:43 +01:00
2019-03-19 10:13:33 +01:00
! Perform BSE calculation
if(BSE) then
2022-11-28 10:52:06 +01:00
call Bethe_Salpeter(BSE2,TDA_W,TDA,dBSE,dTDA,evDyn,singlet,triplet,eta,nBas,nC,nO,nV,nR,nS,ERI_MO,dipole_int,eGW,eGW,EcBSE)
2020-09-24 11:56:06 +02:00
if(exchange_kernel) then
EcBSE(1) = 0.5d0*EcBSE(1)
EcBSE(2) = 1.5d0*EcBSE(2)
end if
2019-03-19 10:13:33 +01:00
2020-01-14 22:56:20 +01:00
write(*,*)
write(*,*)'-------------------------------------------------------------------------------'
2020-01-23 21:22:41 +01:00
write(*,'(2X,A50,F20.10)') 'Tr@BSE@evGW correlation energy (singlet) =',EcBSE(1)
write(*,'(2X,A50,F20.10)') 'Tr@BSE@evGW correlation energy (triplet) =',EcBSE(2)
write(*,'(2X,A50,F20.10)') 'Tr@BSE@evGW correlation energy =',EcBSE(1) + EcBSE(2)
write(*,'(2X,A50,F20.10)') 'Tr@BSE@evGW total energy =',ENuc + ERHF + EcBSE(1) + EcBSE(2)
2019-05-04 17:13:50 +02:00
write(*,*)'-------------------------------------------------------------------------------'
write(*,*)
2020-01-14 16:36:11 +01:00
! Compute the BSE correlation energy via the adiabatic connection
2020-01-14 21:27:34 +01:00
if(doACFDT) then
2020-01-14 16:36:11 +01:00
write(*,*) '------------------------------------------------------'
write(*,*) 'Adiabatic connection version of BSE correlation energy'
write(*,*) '------------------------------------------------------'
write(*,*)
2020-01-14 21:27:34 +01:00
if(doXBS) then
2020-01-14 16:36:11 +01:00
2020-01-14 21:27:34 +01:00
write(*,*) '*** scaled screening version (XBS) ***'
2020-01-14 16:36:11 +01:00
write(*,*)
end if
2021-02-15 17:27:06 +01:00
call ACFDT(exchange_kernel,doXBS,.true.,TDA_W,TDA,BSE,singlet,triplet,eta,nBas,nC,nO,nV,nR,nS,ERI_MO,eGW,eGW,EcAC)
2020-01-14 22:56:20 +01:00
write(*,*)
write(*,*)'-------------------------------------------------------------------------------'
2020-01-23 21:22:41 +01:00
write(*,'(2X,A50,F20.10)') 'AC@BSE@evGW correlation energy (singlet) =',EcAC(1)
write(*,'(2X,A50,F20.10)') 'AC@BSE@evGW correlation energy (triplet) =',EcAC(2)
write(*,'(2X,A50,F20.10)') 'AC@BSE@evGW correlation energy =',EcAC(1) + EcAC(2)
write(*,'(2X,A50,F20.10)') 'AC@BSE@evGW total energy =',ENuc + ERHF + EcAC(1) + EcAC(2)
2020-01-14 22:56:20 +01:00
write(*,*)'-------------------------------------------------------------------------------'
write(*,*)
2020-01-14 16:36:11 +01:00
end if
2021-12-17 11:41:40 +01:00
end if
2019-03-19 10:13:33 +01:00
2022-09-09 21:48:50 +02:00
if(ppBSE) then
call Bethe_Salpeter_pp(TDA_W,TDA,singlet,triplet,eta,nBas,nC,nO,nV,nR,nS,ERI_MO,dipole_int,eHF,eGW,EcppBSE)
write(*,*)
write(*,*)'-------------------------------------------------------------------------------'
write(*,'(2X,A50,F20.10)') 'Tr@ppBSE@G0W0 correlation energy (singlet) =',EcppBSE(1)
write(*,'(2X,A50,F20.10)') 'Tr@ppBSE@G0W0 correlation energy (triplet) =',3d0*EcppBSE(2)
write(*,'(2X,A50,F20.10)') 'Tr@ppBSE@G0W0 correlation energy =',EcppBSE(1) + 3d0*EcppBSE(2)
write(*,'(2X,A50,F20.10)') 'Tr@ppBSE@G0W0 total energy =',ENuc + ERHF + EcppBSE(1) + 3d0*EcppBSE(2)
write(*,*)'-------------------------------------------------------------------------------'
write(*,*)
nBas2 = 2*nBas
nO2 = 2*nO
nV2 = 2*nV
nC2 = 2*nC
nR2 = 2*nR
nS2 = nO2*nV2
allocate(seHF(nBas2),seGW(nBas2),sERI(nBas2,nBas2,nBas2,nBas2))
call spatial_to_spin_MO_energy(nBas,eHF,nBas2,seHF)
call spatial_to_spin_MO_energy(nBas,eGW,nBas2,seGW)
call spatial_to_spin_ERI(nBas,ERI_MO,nBas2,sERI)
call Bethe_Salpeter_pp_so(TDA_W,TDA,singlet,triplet,eta,nBas2,nC2,nO2,nV2,nR2,nS2,sERI,dipole_int,seHF,seGW,EcppBSE)
end if
2019-03-19 10:13:33 +01:00
end subroutine evGW