4
1
mirror of https://github.com/pfloos/quack synced 2024-06-02 11:25:28 +02:00
quack/src/CC/rCCD.f90

233 lines
6.2 KiB
Fortran
Raw Normal View History

2023-11-13 22:15:00 +01:00
subroutine rCCD(dotest,maxSCF,thresh,max_diis,nBasin,nCin,nOin,nVin,nRin,ERI,ENuc,ERHF,eHF)
2019-10-15 23:13:00 +02:00
! Ring CCD module
implicit none
! Input variables
logical,intent(in) :: dotest
2019-10-15 23:13:00 +02:00
integer,intent(in) :: maxSCF
integer,intent(in) :: max_diis
double precision,intent(in) :: thresh
2020-03-26 16:57:46 +01:00
integer,intent(in) :: nBasin
integer,intent(in) :: nCin
integer,intent(in) :: nOin
integer,intent(in) :: nVin
integer,intent(in) :: nRin
2022-09-28 16:09:09 +02:00
double precision,intent(in) :: ENuc
double precision,intent(in) :: ERHF
2020-03-26 16:57:46 +01:00
double precision,intent(in) :: eHF(nBasin)
double precision,intent(in) :: ERI(nBasin,nBasin,nBasin,nBasin)
2019-10-15 23:13:00 +02:00
! Local variables
2020-03-26 16:57:46 +01:00
integer :: nBas
integer :: nC
2019-10-15 23:13:00 +02:00
integer :: nO
integer :: nV
2020-03-26 16:57:46 +01:00
integer :: nR
2019-10-15 23:13:00 +02:00
integer :: nSCF
double precision :: Conv
2020-03-26 16:57:46 +01:00
double precision :: EcMP2
double precision :: ECC,EcCC
2019-10-15 23:13:00 +02:00
double precision,allocatable :: seHF(:)
double precision,allocatable :: sERI(:,:,:,:)
double precision,allocatable :: dbERI(:,:,:,:)
double precision,allocatable :: eO(:)
double precision,allocatable :: eV(:)
double precision,allocatable :: delta_OOVV(:,:,:,:)
double precision,allocatable :: OOVV(:,:,:,:)
double precision,allocatable :: OVVO(:,:,:,:)
2022-09-28 16:09:09 +02:00
double precision,allocatable :: r(:,:,:,:)
double precision,allocatable :: t(:,:,:,:)
2019-10-15 23:13:00 +02:00
2020-03-22 23:01:36 +01:00
integer :: n_diis
double precision :: rcond
double precision,allocatable :: error_diis(:,:)
double precision,allocatable :: t_diis(:,:)
2022-09-28 16:09:09 +02:00
logical :: do_EE_EOM_CC_1h1p = .true.
2019-10-15 23:13:00 +02:00
! Hello world
write(*,*)
write(*,*)'**************************************'
2020-03-21 22:50:43 +01:00
write(*,*)'| ring CCD calculation |'
2019-10-15 23:13:00 +02:00
write(*,*)'**************************************'
write(*,*)
! Spatial to spin orbitals
2020-03-26 16:57:46 +01:00
nBas = 2*nBasin
nC = 2*nCin
nO = 2*nOin
nV = 2*nVin
nR = 2*nRin
2019-10-15 23:13:00 +02:00
2023-11-13 22:15:00 +01:00
allocate(seHF(nBas),sERI(nBas,nBas,nBas,nBas))
2019-10-15 23:13:00 +02:00
2020-03-26 16:57:46 +01:00
call spatial_to_spin_MO_energy(nBasin,eHF,nBas,seHF)
call spatial_to_spin_ERI(nBasin,ERI,nBas,sERI)
2019-10-15 23:13:00 +02:00
! Antysymmetrize ERIs
2020-03-26 16:57:46 +01:00
allocate(dbERI(nBas,nBas,nBas,nBas))
2019-10-15 23:13:00 +02:00
2023-07-19 11:03:55 +02:00
call antisymmetrize_ERI(2,nBas,sERI,dbERI)
2019-10-15 23:13:00 +02:00
deallocate(sERI)
! Form energy denominator
allocate(eO(nO),eV(nV))
allocate(delta_OOVV(nO,nO,nV,nV))
2023-11-13 22:15:00 +01:00
eO(:) = seHF(1:nO)
eV(:) = seHF(nO+1:nBas)
2019-10-15 23:13:00 +02:00
2020-03-26 16:57:46 +01:00
call form_delta_OOVV(nC,nO,nV,nR,eO,eV,delta_OOVV)
2019-10-15 23:13:00 +02:00
2023-11-13 22:15:00 +01:00
deallocate(seHF)
2019-10-15 23:13:00 +02:00
! Create integral batches
2021-11-10 14:47:26 +01:00
allocate(OOVV(nO,nO,nV,nV),OVVO(nO,nV,nV,nO))
2019-10-15 23:13:00 +02:00
2021-11-10 09:42:30 +01:00
OOVV(:,:,:,:) = dbERI( 1:nO , 1:nO ,nO+1:nBas,nO+1:nBas)
OVVO(:,:,:,:) = dbERI( 1:nO ,nO+1:nBas,nO+1:nBas, 1:nO )
2019-10-15 23:13:00 +02:00
deallocate(dbERI)
! MP2 guess amplitudes
2022-09-28 16:09:09 +02:00
allocate(t(nO,nO,nV,nV))
2019-10-15 23:13:00 +02:00
2022-09-28 16:09:09 +02:00
t(:,:,:,:) = -OOVV(:,:,:,:)/delta_OOVV(:,:,:,:)
2019-10-15 23:13:00 +02:00
2022-09-28 16:09:09 +02:00
call CCD_correlation_energy(nC,nO,nV,nR,OOVV,t,EcMP2)
2020-03-22 23:01:36 +01:00
! Memory allocation for DIIS
allocate(error_diis(nO*nO*nV*nV,max_diis),t_diis(nO*nO*nV*nV,max_diis))
2019-10-15 23:13:00 +02:00
! Initialization
2022-09-28 16:09:09 +02:00
allocate(r(nO,nO,nV,nV))
2019-10-15 23:13:00 +02:00
Conv = 1d0
nSCF = 0
2020-03-22 23:01:36 +01:00
n_diis = 0
t_diis(:,:) = 0d0
error_diis(:,:) = 0d0
2019-10-15 23:13:00 +02:00
!------------------------------------------------------------------------
! Main SCF loop
!------------------------------------------------------------------------
write(*,*)
write(*,*)'----------------------------------------------------'
2020-03-21 22:50:43 +01:00
write(*,*)'| ring CCD calculation |'
2019-10-15 23:13:00 +02:00
write(*,*)'----------------------------------------------------'
write(*,'(1X,A1,1X,A3,1X,A1,1X,A16,1X,A1,1X,A10,1X,A1,1X,A10,1X,A1,1X)') &
'|','#','|','E(CCD)','|','Ec(CCD)','|','Conv','|'
write(*,*)'----------------------------------------------------'
do while(Conv > thresh .and. nSCF < maxSCF)
! Increment
nSCF = nSCF + 1
! Compute residual
2022-09-28 16:09:09 +02:00
call form_ring_r(nC,nO,nV,nR,OVVO,OOVV,t,r)
2019-10-15 23:13:00 +02:00
2022-09-28 16:09:09 +02:00
r(:,:,:,:) = OOVV(:,:,:,:) + delta_OOVV(:,:,:,:)*t(:,:,:,:) + r(:,:,:,:)
2019-10-15 23:13:00 +02:00
! Check convergence
2022-09-28 16:09:09 +02:00
Conv = maxval(abs(r(nC+1:nO,nC+1:nO,1:nV-nR,1:nV-nR)))
2019-10-15 23:13:00 +02:00
! Update amplitudes
2022-09-28 16:09:09 +02:00
t(:,:,:,:) = t(:,:,:,:) - r(:,:,:,:)/delta_OOVV(:,:,:,:)
2019-10-15 23:13:00 +02:00
! Compute correlation energy
call CCD_correlation_energy(nC,nO,nV,nR,OOVV,t,EcCC)
2019-10-15 23:13:00 +02:00
! Dump results
ECC = ERHF + EcCC
2019-10-15 23:13:00 +02:00
2020-03-22 23:01:36 +01:00
! DIIS extrapolation
n_diis = min(n_diis+1,max_diis)
2022-09-28 16:09:09 +02:00
call DIIS_extrapolation(rcond,nO*nO*nV*nV,nO*nO*nV*nV,n_diis,error_diis,t_diis,-r/delta_OOVV,t)
2020-03-22 23:01:36 +01:00
! Reset DIIS if required
if(abs(rcond) < 1d-15) n_diis = 0
2019-10-15 23:13:00 +02:00
write(*,'(1X,A1,1X,I3,1X,A1,1X,F16.10,1X,A1,1X,F10.6,1X,A1,1X,F10.6,1X,A1,1X)') &
'|',nSCF,'|',ECC+ENuc,'|',EcCC,'|',Conv,'|'
2019-10-15 23:13:00 +02:00
2023-12-03 18:47:30 +01:00
end do
2019-10-15 23:13:00 +02:00
write(*,*)'----------------------------------------------------'
!------------------------------------------------------------------------
! End of SCF loop
!------------------------------------------------------------------------
! Did it actually converge?
if(nSCF == maxSCF) then
write(*,*)
write(*,*)'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'
write(*,*)' Convergence failed '
write(*,*)'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'
write(*,*)
stop
2023-12-03 18:47:30 +01:00
end if
2019-10-15 23:13:00 +02:00
write(*,*)
2020-01-14 14:44:01 +01:00
write(*,*)'----------------------------------------------------'
2020-03-21 22:50:43 +01:00
write(*,*)' ring CCD energy '
2020-01-14 14:44:01 +01:00
write(*,*)'----------------------------------------------------'
write(*,'(1X,A30,1X,F15.10)')' E(rCCD) = ',ECC
write(*,'(1X,A30,1X,F15.10)')' Ec(rCCD) = ',EcCC
2020-01-14 14:44:01 +01:00
write(*,*)'----------------------------------------------------'
2019-10-15 23:13:00 +02:00
write(*,*)
2022-09-28 16:09:09 +02:00
! write(*,*)
! write(*,*)'----------------------------------------------------'
! write(*,*)' ring CCD amplitudes '
! write(*,*)'----------------------------------------------------'
! call matout(nO*nO,nV*nV,t)
! write(*,*)
!------------------------------------------------------------------------
! EOM section
!------------------------------------------------------------------------
! EE-EOM-CCD (1h1p)
if(do_EE_EOM_CC_1h1p) call EE_EOM_CCD_1h1p(nC,nO,nV,nR,eO,eV,OOVV,OVVO,t)
if(dotest) then
call dump_test_value('R','rCCD correlation energy',EcCC)
end if
2023-07-27 11:38:38 +02:00
end subroutine