2022-02-02 15:06:51 +01:00
|
|
|
subroutine RHF(maxSCF,thresh,max_diis,guess_type,level_shift,nNuc,ZNuc,rNuc,ENuc, &
|
|
|
|
nBas,nO,S,T,V,Hc,F,ERI,dipole_int,X,ERHF,e,c,P,Vx)
|
2019-03-19 10:13:33 +01:00
|
|
|
|
|
|
|
! Perform restricted Hartree-Fock calculation
|
|
|
|
|
|
|
|
implicit none
|
2020-10-04 09:36:03 +02:00
|
|
|
include 'parameters.h'
|
2019-03-19 10:13:33 +01:00
|
|
|
|
|
|
|
! Input variables
|
|
|
|
|
2022-02-02 15:06:51 +01:00
|
|
|
integer,intent(in) :: maxSCF
|
|
|
|
integer,intent(in) :: max_diis
|
|
|
|
integer,intent(in) :: guess_type
|
2019-03-19 10:13:33 +01:00
|
|
|
double precision,intent(in) :: thresh
|
2022-02-03 10:05:58 +01:00
|
|
|
double precision,intent(in) :: level_shift
|
2019-03-19 10:13:33 +01:00
|
|
|
|
2020-10-04 09:36:03 +02:00
|
|
|
integer,intent(in) :: nBas
|
|
|
|
integer,intent(in) :: nO
|
|
|
|
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-04 09:36:03 +02:00
|
|
|
double precision,intent(in) :: S(nBas,nBas)
|
|
|
|
double precision,intent(in) :: T(nBas,nBas)
|
|
|
|
double precision,intent(in) :: V(nBas,nBas)
|
|
|
|
double precision,intent(in) :: Hc(nBas,nBas)
|
|
|
|
double precision,intent(in) :: X(nBas,nBas)
|
|
|
|
double precision,intent(in) :: ERI(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-18 23:22:23 +02:00
|
|
|
integer :: nSCF
|
|
|
|
integer :: nBasSq
|
|
|
|
integer :: n_diis
|
2020-10-04 12:40:44 +02:00
|
|
|
double precision :: ET
|
|
|
|
double precision :: EV
|
|
|
|
double precision :: EJ
|
|
|
|
double precision :: EK
|
|
|
|
double precision :: dipole(ncart)
|
|
|
|
|
2019-04-18 23:22:23 +02:00
|
|
|
double precision :: Conv
|
|
|
|
double precision :: Gap
|
2019-03-19 11:21:34 +01:00
|
|
|
double precision :: rcond
|
2019-03-19 10:13:33 +01:00
|
|
|
double precision,external :: trace_matrix
|
2019-04-18 23:22:23 +02:00
|
|
|
double precision,allocatable :: error(:,:)
|
|
|
|
double precision,allocatable :: error_diis(:,:)
|
|
|
|
double precision,allocatable :: F_diis(:,:)
|
|
|
|
double precision,allocatable :: J(:,:)
|
|
|
|
double precision,allocatable :: K(:,:)
|
|
|
|
double precision,allocatable :: cp(:,:)
|
|
|
|
double precision,allocatable :: Fp(:,:)
|
|
|
|
|
2019-03-19 10:13:33 +01:00
|
|
|
! Output variables
|
|
|
|
|
2019-03-19 11:21:34 +01:00
|
|
|
double precision,intent(out) :: ERHF
|
|
|
|
double precision,intent(out) :: e(nBas)
|
|
|
|
double precision,intent(out) :: c(nBas,nBas)
|
|
|
|
double precision,intent(out) :: P(nBas,nBas)
|
2021-02-15 17:27:06 +01:00
|
|
|
double precision,intent(out) :: Vx(nBas)
|
2022-01-04 11:39:33 +01:00
|
|
|
double precision,intent(out) :: F(nBas,nBas)
|
2019-03-19 10:13:33 +01:00
|
|
|
|
|
|
|
! Hello world
|
|
|
|
|
|
|
|
write(*,*)
|
|
|
|
write(*,*)'************************************************'
|
|
|
|
write(*,*)'| Restricted Hartree-Fock calculation |'
|
|
|
|
write(*,*)'************************************************'
|
|
|
|
write(*,*)
|
|
|
|
|
|
|
|
! Useful quantities
|
|
|
|
|
|
|
|
nBasSq = nBas*nBas
|
|
|
|
|
|
|
|
! Memory allocation
|
|
|
|
|
2022-02-02 15:06:51 +01:00
|
|
|
allocate(J(nBas,nBas),K(nBas,nBas),error(nBas,nBas),cp(nBas,nBas),Fp(nBas,nBas), &
|
2019-03-19 10:13:33 +01:00
|
|
|
error_diis(nBasSq,max_diis),F_diis(nBasSq,max_diis))
|
|
|
|
|
2022-02-02 15:06:51 +01:00
|
|
|
! Guess coefficients and density matrix
|
2019-03-19 10:13:33 +01:00
|
|
|
|
2022-02-02 15:06:51 +01:00
|
|
|
call mo_guess(nBas,guess_type,S,Hc,X,c)
|
|
|
|
P(:,:) = 2d0*matmul(c(:,1:nO),transpose(c(:,1:nO)))
|
2019-03-19 10:13:33 +01:00
|
|
|
|
|
|
|
! Initialization
|
|
|
|
|
|
|
|
F_diis(:,:) = 0d0
|
|
|
|
error_diis(:,:) = 0d0
|
2022-02-02 15:06:51 +01:00
|
|
|
Conv = 1d0
|
|
|
|
n_diis = 0
|
|
|
|
nSCF = 0
|
|
|
|
rcond = 0d0
|
2019-03-19 10:13:33 +01:00
|
|
|
|
|
|
|
!------------------------------------------------------------------------
|
|
|
|
! Main SCF loop
|
|
|
|
!------------------------------------------------------------------------
|
|
|
|
write(*,*)
|
|
|
|
write(*,*)'----------------------------------------------------'
|
|
|
|
write(*,*)'| RHF calculation |'
|
|
|
|
write(*,*)'----------------------------------------------------'
|
|
|
|
write(*,'(1X,A1,1X,A3,1X,A1,1X,A16,1X,A1,1X,A10,1X,A1,1X,A10,1X,A1,1X)') &
|
|
|
|
'|','#','|','HF energy','|','Conv','|','HL Gap','|'
|
|
|
|
write(*,*)'----------------------------------------------------'
|
|
|
|
|
|
|
|
do while(Conv > thresh .and. nSCF < maxSCF)
|
|
|
|
|
|
|
|
! Increment
|
|
|
|
|
|
|
|
nSCF = nSCF + 1
|
|
|
|
|
|
|
|
! Build Fock matrix
|
|
|
|
|
|
|
|
call Coulomb_matrix_AO_basis(nBas,P,ERI,J)
|
|
|
|
call exchange_matrix_AO_basis(nBas,P,ERI,K)
|
|
|
|
|
2019-03-19 11:21:34 +01:00
|
|
|
F(:,:) = Hc(:,:) + J(:,:) + 0.5d0*K(:,:)
|
2019-03-19 10:13:33 +01:00
|
|
|
|
|
|
|
! Check convergence
|
|
|
|
|
|
|
|
error = matmul(F,matmul(P,S)) - matmul(matmul(S,P),F)
|
2022-02-02 15:06:51 +01:00
|
|
|
Conv = maxval(abs(error))
|
2019-03-19 10:13:33 +01:00
|
|
|
|
|
|
|
! DIIS extrapolation
|
|
|
|
|
2022-11-29 14:47:51 +01:00
|
|
|
if(max_diis > 1) then
|
2022-02-02 15:06:51 +01:00
|
|
|
|
2022-11-29 14:47:51 +01:00
|
|
|
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-02-02 15:06:51 +01:00
|
|
|
|
2021-03-27 15:03:54 +01:00
|
|
|
end if
|
2019-03-19 10:13:33 +01:00
|
|
|
|
2022-02-02 15:06:51 +01:00
|
|
|
! Level-shifting
|
|
|
|
|
2022-02-03 10:05:58 +01:00
|
|
|
if(level_shift > 0d0 .and. Conv > thresh) call level_shifting(level_shift,nBas,nO,S,c,F)
|
2022-02-02 15:06:51 +01:00
|
|
|
|
2019-03-19 10:13:33 +01:00
|
|
|
! Diagonalize Fock matrix
|
|
|
|
|
|
|
|
Fp = matmul(transpose(X),matmul(F,X))
|
|
|
|
cp(:,:) = Fp(:,:)
|
|
|
|
call diagonalize_matrix(nBas,cp,e)
|
|
|
|
c = matmul(X,cp)
|
|
|
|
|
|
|
|
! Density matrix
|
|
|
|
|
|
|
|
P(:,:) = 2d0*matmul(c(:,1:nO),transpose(c(:,1:nO)))
|
2019-04-18 23:22:23 +02:00
|
|
|
|
2019-03-19 10:13:33 +01:00
|
|
|
! Compute HF energy
|
|
|
|
|
2022-02-02 15:06:51 +01:00
|
|
|
ERHF = trace_matrix(nBas,matmul(P,Hc)) &
|
|
|
|
+ 0.5d0*trace_matrix(nBas,matmul(P,J)) &
|
|
|
|
+ 0.25d0*trace_matrix(nBas,matmul(P,K))
|
2019-03-19 10:13:33 +01:00
|
|
|
|
|
|
|
! Compute HOMO-LUMO gap
|
|
|
|
|
|
|
|
if(nBas > nO) then
|
|
|
|
|
|
|
|
Gap = e(nO+1) - e(nO)
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
Gap = 0d0
|
|
|
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
! Dump results
|
|
|
|
|
|
|
|
write(*,'(1X,A1,1X,I3,1X,A1,1X,F16.10,1X,A1,1X,F10.6,1X,A1,1X,F10.6,1X,A1,1X)') &
|
|
|
|
'|',nSCF,'|',ERHF+ENuc,'|',Conv,'|',Gap,'|'
|
|
|
|
|
|
|
|
enddo
|
|
|
|
write(*,*)'----------------------------------------------------'
|
|
|
|
!------------------------------------------------------------------------
|
|
|
|
! End of SCF loop
|
|
|
|
!------------------------------------------------------------------------
|
|
|
|
|
|
|
|
! Did it actually converge?
|
|
|
|
|
|
|
|
if(nSCF == maxSCF) then
|
|
|
|
|
|
|
|
write(*,*)
|
|
|
|
write(*,*)'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'
|
|
|
|
write(*,*)' Convergence failed '
|
|
|
|
write(*,*)'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'
|
|
|
|
write(*,*)
|
|
|
|
|
|
|
|
stop
|
|
|
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
! Compute HF energy
|
|
|
|
|
|
|
|
ET = trace_matrix(nBas,matmul(P,T))
|
|
|
|
EV = trace_matrix(nBas,matmul(P,V))
|
|
|
|
EJ = 0.5d0*trace_matrix(nBas,matmul(P,J))
|
2019-03-19 11:21:34 +01:00
|
|
|
EK = 0.25d0*trace_matrix(nBas,matmul(P,K))
|
2019-03-19 10:13:33 +01:00
|
|
|
ERHF = ET + EV + EJ + EK
|
|
|
|
|
2021-02-15 17:27:06 +01:00
|
|
|
! Compute dipole moments
|
|
|
|
|
2020-10-04 09:36:03 +02:00
|
|
|
call dipole_moment(nBas,P,nNuc,ZNuc,rNuc,dipole_int,dipole)
|
|
|
|
call print_RHF(nBas,nO,e,C,ENuc,ET,EV,EJ,EK,ERHF,dipole)
|
2019-03-19 10:13:33 +01:00
|
|
|
|
2022-08-16 15:59:15 +02:00
|
|
|
! dump orbitals for potential restart
|
|
|
|
|
|
|
|
call dump_orbitals(nBas,c)
|
|
|
|
|
2021-02-15 17:27:06 +01:00
|
|
|
! Compute Vx for post-HF calculations
|
|
|
|
|
2022-01-26 13:05:16 +01:00
|
|
|
call mo_fock_exchange_potential(nBas,c,P,ERI,Vx)
|
2021-02-15 17:27:06 +01:00
|
|
|
|
2019-03-19 10:13:33 +01:00
|
|
|
end subroutine RHF
|