10
1
mirror of https://github.com/pfloos/quack synced 2024-12-25 13:53:41 +01:00
QuAcK/src/GW/qsGW.f90

352 lines
11 KiB
Fortran
Raw Normal View History

2022-11-28 10:52:06 +01:00
subroutine qsGW(maxSCF,thresh,max_diis,doACFDT,exchange_kernel,doXBS,COHSEX,BSE,BSE2,TDA_W,TDA, &
2022-11-30 16:41:19 +01:00
dBSE,dTDA,evDyn,singlet,triplet,eta,regularize,nNuc,ZNuc,rNuc,ENuc,nBas,nC,nO,nV,nR,nS,ERHF, &
2020-10-21 12:58:37 +02:00
S,X,T,V,Hc,ERI_AO,ERI_MO,dipole_int_AO,dipole_int_MO,PHF,cHF,eHF)
2019-03-19 10:13:33 +01:00
2020-01-14 21:27:34 +01:00
! Perform a quasiparticle self-consistent GW calculation
2019-03-19 10:13:33 +01:00
implicit none
include 'parameters.h'
! Input variables
2019-04-02 22:58:24 +02:00
integer,intent(in) :: maxSCF
integer,intent(in) :: max_diis
2019-03-19 10:13:33 +01:00
double precision,intent(in) :: thresh
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
2020-09-24 11:56:06 +02:00
logical,intent(in) :: singlet
logical,intent(in) :: triplet
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
2020-10-21 12:58:37 +02:00
integer,intent(in) :: nNuc
double precision,intent(in) :: ZNuc(nNuc)
double precision,intent(in) :: rNuc(nNuc,ncart)
2019-03-19 10:13:33 +01:00
double precision,intent(in) :: ENuc
2020-10-21 12:58:37 +02:00
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
2019-05-07 22:55:36 +02:00
double precision,intent(in) :: ERHF
2019-04-02 22:58:24 +02:00
double precision,intent(in) :: eHF(nBas)
double precision,intent(in) :: cHF(nBas,nBas)
double precision,intent(in) :: PHF(nBas,nBas)
double precision,intent(in) :: S(nBas,nBas)
2020-10-21 12:09:18 +02:00
double precision,intent(in) :: T(nBas,nBas)
2019-04-02 22:58:24 +02:00
double precision,intent(in) :: V(nBas,nBas)
double precision,intent(in) :: Hc(nBas,nBas)
double precision,intent(in) :: X(nBas,nBas)
2020-10-21 12:58:37 +02:00
double precision,intent(in) :: ERI_AO(nBas,nBas,nBas,nBas)
double precision,intent(inout):: ERI_MO(nBas,nBas,nBas,nBas)
double precision,intent(in) :: dipole_int_AO(nBas,nBas,ncart)
double precision,intent(in) :: dipole_int_MO(nBas,nBas,ncart)
2019-03-19 10:13:33 +01:00
! Local variables
2019-04-02 22:58:24 +02:00
integer :: nSCF
integer :: nBasSq
integer :: ispin
integer :: n_diis
2021-03-23 22:35:46 +01:00
double precision :: ET
double precision :: EV
double precision :: EJ
double precision :: Ex
double precision :: EqsGW
2020-09-24 11:56:06 +02:00
double precision :: EcRPA
2019-05-07 22:55:36 +02:00
double precision :: EcBSE(nspin)
2020-01-14 22:56:20 +01:00
double precision :: EcAC(nspin)
2019-04-02 22:58:24 +02:00
double precision :: EcGM
double precision :: Conv
2019-04-01 15:53:39 +02:00
double precision :: rcond
2019-03-19 10:13:33 +01:00
double precision,external :: trace_matrix
2020-10-21 12:58:37 +02:00
double precision :: dipole(ncart)
2021-03-27 15:03:54 +01:00
logical :: print_W = .true.
2019-04-02 22:58:24 +02:00
double precision,allocatable :: error_diis(:,:)
double precision,allocatable :: F_diis(:,:)
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(:,:,:)
2019-04-02 22:58:24 +02:00
double precision,allocatable :: c(:,:)
double precision,allocatable :: cp(:,:)
2020-01-14 16:36:11 +01:00
double precision,allocatable :: eGW(:)
2021-03-27 15:03:54 +01:00
double precision,allocatable :: eOld(:)
2019-04-02 22:58:24 +02:00
double precision,allocatable :: P(:,:)
double precision,allocatable :: F(:,:)
double precision,allocatable :: Fp(:,:)
double precision,allocatable :: J(:,:)
double precision,allocatable :: K(:,:)
double precision,allocatable :: SigC(:,:)
double precision,allocatable :: SigCp(:,:)
double precision,allocatable :: SigCm(:,:)
double precision,allocatable :: Z(:)
double precision,allocatable :: error(:,:)
2019-03-19 10:13:33 +01:00
! Hello world
write(*,*)
write(*,*)'************************************************'
write(*,*)'| Self-consistent qsGW calculation |'
write(*,*)'************************************************'
write(*,*)
2019-10-30 10:31:05 +01:00
! Warning
write(*,*) '!! ERIs in MO basis will be overwritten in qsGW !!'
write(*,*)
2019-03-19 10:13:33 +01:00
! Stuff
nBasSq = nBas*nBas
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
2020-06-09 21:24:37 +02:00
2019-03-19 10:13:33 +01:00
! Memory allocation
2021-03-27 15:03:54 +01:00
allocate(eGW(nBas),eOld(nBas),c(nBas,nBas),cp(nBas,nBas),P(nBas,nBas),F(nBas,nBas),Fp(nBas,nBas), &
J(nBas,nBas),K(nBas,nBas),SigC(nBas,nBas),SigCp(nBas,nBas),SigCm(nBas,nBas),Z(nBas), &
OmRPA(nS),XpY_RPA(nS,nS),XmY_RPA(nS,nS),rho_RPA(nBas,nBas,nS), &
2019-10-30 10:31:05 +01:00
error(nBas,nBas),error_diis(nBasSq,max_diis),F_diis(nBasSq,max_diis))
2019-03-19 10:13:33 +01:00
! Initialization
2020-10-21 12:09:18 +02:00
nSCF = -1
2019-03-19 10:13:33 +01:00
n_diis = 0
ispin = 1
Conv = 1d0
P(:,:) = PHF(:,:)
2020-01-14 16:36:11 +01:00
eGW(:) = eHF(:)
2021-03-27 15:03:54 +01:00
eOld(:) = eHF(:)
2019-03-19 10:13:33 +01:00
c(:,:) = cHF(:,:)
F_diis(:,:) = 0d0
error_diis(:,:) = 0d0
2022-01-06 22:36:30 +01:00
rcond = 0d0
2019-03-19 10:13:33 +01:00
!------------------------------------------------------------------------
! Main loop
!------------------------------------------------------------------------
do while(Conv > thresh .and. nSCF <= maxSCF)
2020-10-21 12:09:18 +02:00
! Increment
nSCF = nSCF + 1
2019-03-19 10:13:33 +01:00
! Buid Coulomb matrix
2020-10-21 12:58:37 +02:00
call Coulomb_matrix_AO_basis(nBas,P,ERI_AO,J)
2019-03-19 10:13:33 +01:00
! Compute exchange part of the self-energy
2020-10-21 12:58:37 +02:00
call exchange_matrix_AO_basis(nBas,P,ERI_AO,K)
2019-03-19 10:13:33 +01:00
! AO to MO transformation of two-electron integrals
2020-10-21 12:58:37 +02:00
call AOtoMO_integral_transform(1,1,1,1,nBas,c,ERI_AO,ERI_MO)
2019-03-19 10:13:33 +01:00
! Compute linear response
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)
if(print_W) call print_excitation('RPA@qsGW ',ispin,nS,OmRPA)
2019-03-19 10:13:33 +01:00
! Compute correlation part of the self-energy
2023-07-04 10:51:03 +02:00
call GW_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
if(regularize) then
2021-12-17 11:41:40 +01:00
2022-11-30 16:41:19 +01:00
call regularized_self_energy_correlation(COHSEX,eta,nBas,nC,nO,nV,nR,nS,eGW,OmRPA,rho_RPA,EcGM,SigC)
call regularized_renormalization_factor(COHSEX,eta,nBas,nC,nO,nV,nR,nS,eGW,OmRPA,rho_RPA,Z)
2019-03-19 10:13:33 +01:00
else
2023-07-04 10:44:20 +02:00
call GW_self_energy(COHSEX,eta,nBas,nC,nO,nV,nR,nS,eGW,OmRPA,rho_RPA,EcGM,SigC)
call GW_renormalization_factor(COHSEX,eta,nBas,nC,nO,nV,nR,nS,eGW,OmRPA,rho_RPA,Z)
2019-03-19 10:13:33 +01:00
endif
! Make correlation self-energy Hermitian and transform it back to AO basis
SigCp = 0.5d0*(SigC + transpose(SigC))
SigCm = 0.5d0*(SigC - transpose(SigC))
call MOtoAO_transform(nBas,S,c,SigCp)
! Solve the quasi-particle equation
2019-03-19 11:21:34 +01:00
F(:,:) = Hc(:,:) + J(:,:) + 0.5d0*K(:,:) + SigCp(:,:)
2019-03-19 10:13:33 +01:00
! Compute commutator and convergence criteria
error = matmul(F,matmul(P,S)) - matmul(matmul(S,P),F)
! DIIS extrapolation
2022-11-29 14:47:51 +01:00
if(max_diis > 1) then
n_diis = min(n_diis+1,max_diis)
2021-03-27 15:03:54 +01:00
call DIIS_extrapolation(rcond,nBasSq,nBasSq,n_diis,error_diis,F_diis,error,F)
2022-11-29 14:47:51 +01:00
2021-03-27 15:03:54 +01:00
end if
2019-03-19 10:13:33 +01:00
! Diagonalize Hamiltonian in AO basis
Fp = matmul(transpose(X),matmul(F,X))
cp(:,:) = Fp(:,:)
2020-01-14 16:36:11 +01:00
call diagonalize_matrix(nBas,cp,eGW)
2019-03-19 10:13:33 +01:00
c = matmul(X,cp)
2021-03-27 15:03:54 +01:00
SigCp = matmul(transpose(c),matmul(SigCp,c))
2021-06-25 10:19:42 +02:00
! Compute new density matrix in the AO basis
P(:,:) = 2d0*matmul(c(:,1:nO),transpose(c(:,1:nO)))
2021-03-27 15:03:54 +01:00
! Save quasiparticles energy for next cycle
2022-11-29 14:47:51 +01:00
Conv = maxval(abs(error))
2021-03-27 15:03:54 +01:00
eOld(:) = eGW(:)
2019-03-19 10:13:33 +01:00
2021-03-23 22:35:46 +01:00
!------------------------------------------------------------------------
! Compute total energy
!------------------------------------------------------------------------
! Kinetic energy
ET = trace_matrix(nBas,matmul(P,T))
! Potential energy
EV = trace_matrix(nBas,matmul(P,V))
! Coulomb energy
EJ = 0.5d0*trace_matrix(nBas,matmul(P,J))
! Exchange energy
Ex = 0.25d0*trace_matrix(nBas,matmul(P,K))
! Total energy
EqsGW = ET + EV + EJ + Ex
2019-03-19 10:13:33 +01:00
! Print results
2020-10-21 12:58:37 +02:00
call dipole_moment(nBas,P,nNuc,ZNuc,rNuc,dipole_int_AO,dipole)
2021-03-27 15:03:54 +01:00
call print_qsGW(nBas,nO,nSCF,Conv,thresh,eHF,eGW,c,SigCp,Z,ENuc,ET,EV,EJ,Ex,EcGM,EcRPA,EqsGW,dipole)
2019-03-19 10:13:33 +01:00
enddo
!------------------------------------------------------------------------
! End main loop
!------------------------------------------------------------------------
! Compute second-order correction of the Hermitization error
2020-01-15 22:29:43 +01:00
! call qsGW_PT(nBas,nC,nO,nV,nR,nS,eGW,SigCm)
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
endif
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(c,cp,P,F,Fp,J,K,SigC,SigCp,SigCm,Z,OmRPA,XpY_RPA,XmY_RPA,rho_RPA,error,error_diis,F_diis)
2020-01-15 22:29:43 +01:00
2019-03-19 10:13:33 +01:00
! Perform BSE calculation
if(BSE) then
2023-07-04 11:56:00 +02:00
call GW_phBSE(BSE2,TDA_W,TDA,dBSE,dTDA,evDyn,singlet,triplet,eta,nBas,nC,nO,nV,nR,nS,ERI_MO,dipole_int_MO,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@qsGW correlation energy (singlet) =',EcBSE(1)
write(*,'(2X,A50,F20.10)') 'Tr@BSE@qsGW correlation energy (triplet) =',EcBSE(2)
write(*,'(2X,A50,F20.10)') 'Tr@BSE@qsGW correlation energy =',EcBSE(1) + EcBSE(2)
write(*,'(2X,A50,F20.10)') 'Tr@BSE@qsGW total energy =',ENuc + EqsGW + EcBSE(1) + EcBSE(2)
2019-05-07 22:55:36 +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
2020-10-21 12:58:37 +02: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@qsGW correlation energy (singlet) =',EcAC(1)
write(*,'(2X,A50,F20.10)') 'AC@BSE@qsGW correlation energy (triplet) =',EcAC(2)
write(*,'(2X,A50,F20.10)') 'AC@BSE@qsGW correlation energy =',EcAC(1) + EcAC(2)
write(*,'(2X,A50,F20.10)') 'AC@BSE@qsGW total energy =',ENuc + EqsGW + EcAC(1) + EcAC(2)
2020-01-14 22:56:20 +01:00
write(*,*)'-------------------------------------------------------------------------------'
write(*,*)
2020-01-14 16:36:11 +01:00
end if
end if
2019-03-19 10:13:33 +01:00
2023-07-04 10:44:20 +02:00
end subroutine