2020-03-22 22:22:47 +01:00
|
|
|
subroutine pCCD(maxSCF,thresh,max_diis,nBas,nC,nO,nV,nR,ERI,ENuc,ERHF,eHF)
|
2019-10-15 23:13:00 +02:00
|
|
|
|
2020-03-21 22:50:43 +01:00
|
|
|
! pair CCD module
|
2019-10-15 23:13:00 +02:00
|
|
|
|
|
|
|
implicit none
|
|
|
|
|
|
|
|
! Input variables
|
|
|
|
|
|
|
|
integer,intent(in) :: maxSCF
|
|
|
|
integer,intent(in) :: max_diis
|
|
|
|
double precision,intent(in) :: thresh
|
|
|
|
|
2020-03-22 22:22:47 +01:00
|
|
|
integer,intent(in) :: nBas,nC,nO,nV,nR
|
2019-10-15 23:13:00 +02:00
|
|
|
double precision,intent(in) :: ENuc,ERHF
|
|
|
|
double precision,intent(in) :: eHF(nBas)
|
|
|
|
double precision,intent(in) :: ERI(nBas,nBas,nBas,nBas)
|
|
|
|
|
|
|
|
! Local variables
|
|
|
|
|
2020-03-22 15:20:42 +01:00
|
|
|
integer :: i,j,a,b
|
|
|
|
|
2019-10-15 23:13:00 +02:00
|
|
|
integer :: nSCF
|
|
|
|
double precision :: Conv
|
|
|
|
double precision :: ECCD,EcCCD
|
|
|
|
|
2020-03-22 15:20:42 +01:00
|
|
|
double precision,allocatable :: delta_OOVV(:,:)
|
2019-10-15 23:13:00 +02:00
|
|
|
|
2020-03-22 15:20:42 +01:00
|
|
|
double precision,allocatable :: OOOO(:,:)
|
|
|
|
double precision,allocatable :: OOVV(:,:)
|
|
|
|
double precision,allocatable :: OVOV(:,:)
|
|
|
|
double precision,allocatable :: OVVO(:,:)
|
|
|
|
double precision,allocatable :: VVVV(:,:)
|
2019-10-15 23:13:00 +02:00
|
|
|
|
2020-03-22 22:22:47 +01:00
|
|
|
double precision,allocatable :: y(:,:)
|
2019-10-15 23:13:00 +02:00
|
|
|
|
2020-03-22 15:20:42 +01: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(:,:)
|
|
|
|
|
2019-10-15 23:13:00 +02:00
|
|
|
! Hello world
|
|
|
|
|
|
|
|
write(*,*)
|
|
|
|
write(*,*)'**************************************'
|
2020-03-22 15:20:42 +01:00
|
|
|
write(*,*)'| pair CCD calculation |'
|
2019-10-15 23:13:00 +02:00
|
|
|
write(*,*)'**************************************'
|
|
|
|
write(*,*)
|
|
|
|
|
|
|
|
! Form energy denominator
|
|
|
|
|
2020-03-22 15:20:42 +01:00
|
|
|
allocate(delta_OOVV(nO,nV))
|
2019-10-15 23:13:00 +02:00
|
|
|
|
2020-03-24 12:28:56 +01:00
|
|
|
delta_OOVV(:,:) = 0d0
|
|
|
|
|
2020-03-22 22:22:47 +01:00
|
|
|
do i=nC+1,nO
|
|
|
|
do a=1,nV-nR
|
2020-03-22 15:20:42 +01:00
|
|
|
delta_OOVV(i,a) = 2d0*(eHF(nO+a) - eHF(i))
|
|
|
|
enddo
|
|
|
|
enddo
|
2019-10-15 23:13:00 +02:00
|
|
|
|
2020-03-22 15:20:42 +01:00
|
|
|
! Create integral batches
|
2019-10-15 23:13:00 +02:00
|
|
|
|
2020-03-22 15:20:42 +01:00
|
|
|
allocate(OOOO(nO,nO),OOVV(nO,nV),OVOV(nO,nV),OVVO(nO,nV),VVVV(nV,nV))
|
2019-10-15 23:13:00 +02:00
|
|
|
|
2020-03-24 12:28:56 +01:00
|
|
|
OOOO(:,:) = 0d0
|
|
|
|
OOVV(:,:) = 0d0
|
|
|
|
OVVO(:,:) = 0d0
|
|
|
|
VVVV(:,:) = 0d0
|
|
|
|
|
2020-03-22 22:22:47 +01:00
|
|
|
do i=nC+1,nO
|
|
|
|
do j=nC+1,nO
|
2020-03-22 15:20:42 +01:00
|
|
|
OOOO(i,j) = ERI(i,i,j,j)
|
|
|
|
end do
|
|
|
|
end do
|
2019-10-15 23:13:00 +02:00
|
|
|
|
2020-03-22 22:22:47 +01:00
|
|
|
do i=nC+1,nO
|
|
|
|
do a=1,nV-nR
|
2020-03-22 15:20:42 +01:00
|
|
|
OOVV(i,a) = ERI(i,i,nO+a,nO+a)
|
|
|
|
OVOV(i,a) = ERI(i,nO+a,i,nO+a)
|
|
|
|
OVVO(i,a) = ERI(i,nO+a,nO+a,i)
|
|
|
|
end do
|
|
|
|
end do
|
2019-10-15 23:13:00 +02:00
|
|
|
|
2020-03-22 22:22:47 +01:00
|
|
|
do a=1,nV-nR
|
|
|
|
do b=1,nV-nR
|
2020-03-22 15:20:42 +01:00
|
|
|
VVVV(a,b) = ERI(nO+a,nO+a,nO+b,nO+b)
|
|
|
|
end do
|
|
|
|
end do
|
2019-10-15 23:13:00 +02:00
|
|
|
|
|
|
|
! MP2 guess amplitudes
|
|
|
|
|
2020-03-22 15:20:42 +01:00
|
|
|
allocate(t(nO,nV))
|
2019-10-15 23:13:00 +02:00
|
|
|
|
2020-03-22 15:20:42 +01:00
|
|
|
t(:,:) = - OOVV(:,:)/delta_OOVV(:,:)
|
2019-10-15 23:13:00 +02:00
|
|
|
|
2020-03-22 23:01:36 +01:00
|
|
|
! Memory allocation for DIIS
|
|
|
|
|
|
|
|
allocate(error_diis(nO*nV,max_diis),t_diis(nO*nV,max_diis))
|
|
|
|
|
2019-10-15 23:13:00 +02:00
|
|
|
! Initialization
|
|
|
|
|
2020-03-22 22:22:47 +01:00
|
|
|
allocate(r(nO,nV),y(nO,nO))
|
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(*,*)'| pair 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)') &
|
2020-03-21 22:50:43 +01:00
|
|
|
'|','#','|','E(pCCD)','|','Ec(pCCD)','|','Conv','|'
|
2019-10-15 23:13:00 +02:00
|
|
|
write(*,*)'----------------------------------------------------'
|
|
|
|
|
|
|
|
do while(Conv > thresh .and. nSCF < maxSCF)
|
|
|
|
|
2020-03-22 15:20:42 +01:00
|
|
|
! Increment
|
2019-10-15 23:13:00 +02:00
|
|
|
|
|
|
|
nSCF = nSCF + 1
|
|
|
|
|
2020-03-22 15:20:42 +01:00
|
|
|
! Form intermediate array
|
|
|
|
|
2020-03-22 22:22:47 +01:00
|
|
|
y(:,:) = 0d0
|
|
|
|
do i=nC+1,nO
|
|
|
|
do j=nC+1,nO
|
|
|
|
do b=1,nV-nR
|
|
|
|
y(i,j) = y(i,j) + OOVV(j,b)*t(i,b)
|
|
|
|
end do
|
|
|
|
end do
|
|
|
|
end do
|
2020-03-22 15:20:42 +01:00
|
|
|
|
2020-03-22 23:01:36 +01:00
|
|
|
! Compute residual
|
2020-03-21 22:50:43 +01:00
|
|
|
|
2020-03-22 22:22:47 +01:00
|
|
|
do i=nC+1,nO
|
|
|
|
do a=1,nV-nR
|
|
|
|
|
|
|
|
r(i,a) = OOVV(i,a) + delta_OOVV(i,a)*t(i,a) &
|
|
|
|
- 2d0*(2d0*OVOV(i,a) - OVVO(i,a) - OOVV(i,a)*t(i,a))*t(i,a)
|
|
|
|
|
|
|
|
do j=nC+1,nO
|
2020-03-24 12:28:56 +01:00
|
|
|
r(i,a) = r(i,a) - 2d0*OOVV(j,a)*t(j,a)*t(i,a) + OOOO(j,i)*t(j,a) + y(i,j)*t(j,a)
|
2020-03-22 22:22:47 +01:00
|
|
|
end do
|
|
|
|
|
|
|
|
do b=1,nV-nR
|
|
|
|
r(i,a) = r(i,a) - 2d0*OOVV(i,b)*t(i,b)*t(i,a) + VVVV(a,b)*t(i,b)
|
|
|
|
end do
|
|
|
|
|
2020-03-22 15:20:42 +01:00
|
|
|
end do
|
|
|
|
end do
|
2020-03-21 22:50:43 +01:00
|
|
|
|
2020-03-22 15:20:42 +01:00
|
|
|
! Check convergence
|
2020-03-21 22:50:43 +01:00
|
|
|
|
2020-03-22 15:20:42 +01:00
|
|
|
Conv = maxval(abs(r(:,:)))
|
2019-10-15 23:13:00 +02:00
|
|
|
|
2020-03-22 15:20:42 +01:00
|
|
|
! Update amplitudes
|
2019-10-15 23:13:00 +02:00
|
|
|
|
2020-03-22 15:20:42 +01:00
|
|
|
t(:,:) = t(:,:) - r(:,:)/delta_OOVV(:,:)
|
2019-10-15 23:13:00 +02:00
|
|
|
|
2020-03-22 15:20:42 +01:00
|
|
|
! Compute correlation energy
|
2019-10-15 23:13:00 +02:00
|
|
|
|
2020-03-22 22:22:47 +01:00
|
|
|
EcCCD = 0d0
|
|
|
|
do i=nC+1,nO
|
|
|
|
do a=1,nV-nR
|
|
|
|
EcCCD = EcCCD + t(i,a)*OOVV(i,a)
|
|
|
|
end do
|
|
|
|
end do
|
2019-10-15 23:13:00 +02:00
|
|
|
|
2020-03-22 23:01:36 +01:00
|
|
|
! Dump results
|
2019-10-15 23:13:00 +02:00
|
|
|
|
|
|
|
ECCD = ERHF + EcCCD
|
|
|
|
|
2020-03-22 23:01:36 +01:00
|
|
|
! DIIS extrapolation
|
|
|
|
|
|
|
|
n_diis = min(n_diis+1,max_diis)
|
|
|
|
call DIIS_extrapolation(rcond,nO*nV,nO*nV,n_diis,error_diis,t_diis,-r/delta_OOVV,t)
|
|
|
|
|
|
|
|
! 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,'|',ECCD+ENuc,'|',EcCCD,'|',Conv,'|'
|
|
|
|
|
|
|
|
enddo
|
|
|
|
write(*,*)'----------------------------------------------------'
|
|
|
|
!------------------------------------------------------------------------
|
|
|
|
! End of SCF loop
|
|
|
|
!------------------------------------------------------------------------
|
|
|
|
|
|
|
|
! Did it actually converge?
|
|
|
|
|
|
|
|
if(nSCF == maxSCF) then
|
|
|
|
|
|
|
|
write(*,*)
|
|
|
|
write(*,*)'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'
|
|
|
|
write(*,*)' Convergence failed '
|
|
|
|
write(*,*)'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'
|
|
|
|
write(*,*)
|
|
|
|
|
|
|
|
stop
|
|
|
|
|
|
|
|
endif
|
|
|
|
|
2020-03-21 22:50:43 +01:00
|
|
|
end subroutine pCCD
|