mirror of
https://github.com/pfloos/quack
synced 2025-05-06 23:24:58 +02:00
added sorted eigenvalues complex diag
This commit is contained in:
parent
4e015ecd4d
commit
0db651d868
@ -34,7 +34,7 @@ if __name__ == "__main__":
|
|||||||
with open("../int/nBas.dat", 'r') as f:
|
with open("../int/nBas.dat", 'r') as f:
|
||||||
size = int(f.readline().strip())
|
size = int(f.readline().strip())
|
||||||
print("nBas: ", size)
|
print("nBas: ", size)
|
||||||
width = 5
|
width = 0
|
||||||
generate_cap_file("../int/CAP.dat", size, width)
|
generate_cap_file("../int/CAP.dat", size, width)
|
||||||
W = read_and_construct_matrix("../int/CAP.dat", size)
|
W = read_and_construct_matrix("../int/CAP.dat", size)
|
||||||
print("W matrix:")
|
print("W matrix:")
|
||||||
|
@ -3,4 +3,4 @@
|
|||||||
cp ./methods.test ../input/methods
|
cp ./methods.test ../input/methods
|
||||||
cp ./options.test ../input/options
|
cp ./options.test ../input/options
|
||||||
cd ..
|
cd ..
|
||||||
python3 PyDuck.py -x N2 -b sto-3g -c -1 -m 2
|
python3 PyDuck.py -x N2 -b sto-3g -c 0 -m 1
|
||||||
|
@ -34,11 +34,11 @@ subroutine cRHF(dotest,maxSCF,thresh,max_diis,guess_type,level_shift,nNuc,ZNuc,r
|
|||||||
integer :: nSCF
|
integer :: nSCF
|
||||||
integer :: nBasSq
|
integer :: nBasSq
|
||||||
integer :: n_diis
|
integer :: n_diis
|
||||||
double precision :: ET
|
complex*16 :: ET
|
||||||
double precision :: EV
|
complex*16 :: EV
|
||||||
double precision :: EJ
|
complex*16 :: EJ
|
||||||
double precision :: EK
|
complex*16 :: EK
|
||||||
double precision :: dipole(ncart)
|
complex*16 :: dipole(ncart)
|
||||||
|
|
||||||
double precision :: Conv
|
double precision :: Conv
|
||||||
double precision :: rcond
|
double precision :: rcond
|
||||||
@ -91,10 +91,10 @@ subroutine cRHF(dotest,maxSCF,thresh,max_diis,guess_type,level_shift,nNuc,ZNuc,r
|
|||||||
Hc(:,:) = cmplx(T+V,W,kind=8)
|
Hc(:,:) = cmplx(T+V,W,kind=8)
|
||||||
|
|
||||||
! Guess coefficients and density matrix
|
! Guess coefficients and density matrix
|
||||||
|
|
||||||
|
|
||||||
call complex_mo_guess(nBas,nBas,guess_type,S,Hc,X,c)
|
call complex_mo_guess(nBas,nBas,guess_type,S,Hc,X,c)
|
||||||
P(:,:) = 2d0*matmul(c(:,1:nO),transpose(c(:,1:nO)))
|
P(:,:) = 2d0*matmul(c(:,1:nO),transpose(c(:,1:nO)))
|
||||||
|
|
||||||
! Initialization
|
! Initialization
|
||||||
|
|
||||||
n_diis = 0
|
n_diis = 0
|
||||||
@ -135,18 +135,21 @@ subroutine cRHF(dotest,maxSCF,thresh,max_diis,guess_type,level_shift,nNuc,ZNuc,r
|
|||||||
|
|
||||||
! Kinetic energy
|
! Kinetic energy
|
||||||
|
|
||||||
ET = trace_matrix(nBas,matmul(P,T))
|
ET = cmplx(trace_matrix(nBas,real(matmul(P,T))),trace_matrix(nBas,aimag(matmul(P,T))),kind=8)
|
||||||
! Potential energy
|
! Potential energy
|
||||||
|
|
||||||
EV = trace_matrix(nBas,matmul(P,V))
|
EV = cmplx(trace_matrix(nBas,real(matmul(P,V))),trace_matrix(nBas,aimag(matmul(P,V))),kind=8)
|
||||||
|
|
||||||
|
|
||||||
! Hartree energy
|
! Hartree energy
|
||||||
|
|
||||||
EJ = 0.5d0*trace_matrix(nBas,matmul(P,J))
|
EJ = 0.5d0*cmplx(trace_matrix(nBas,real(matmul(P,J))),trace_matrix(nBas,aimag(matmul(P,J))),kind=8)
|
||||||
|
|
||||||
|
|
||||||
! Exchange energy
|
! Exchange energy
|
||||||
|
|
||||||
EK = 0.25d0*trace_matrix(nBas,matmul(P,K))
|
EK = 0.25d0*cmplx(trace_matrix(nBas,real(matmul(P,K))),trace_matrix(nBas,aimag(matmul(P,K))),kind=8)
|
||||||
|
|
||||||
|
|
||||||
! Total energy
|
! Total energy
|
||||||
|
|
||||||
@ -160,16 +163,15 @@ subroutine cRHF(dotest,maxSCF,thresh,max_diis,guess_type,level_shift,nNuc,ZNuc,r
|
|||||||
! call complex_DIIS_extrapolation(rcond,nBasSq,nBasSq,n_diis,err_diis,F_diis,err,F)
|
! call complex_DIIS_extrapolation(rcond,nBasSq,nBasSq,n_diis,err_diis,F_diis,err,F)
|
||||||
!
|
!
|
||||||
! end if
|
! end if
|
||||||
!
|
|
||||||
! Level shift
|
! Level shift
|
||||||
if(level_shift > 0d0 .and. Conv > thresh) call level_shifting(level_shift,nBas,nBas,nO,S,c,F)
|
if(level_shift > 0d0 .and. Conv > thresh) call complex_level_shifting(level_shift,nBas,nBas,nO,S,c,F)
|
||||||
|
|
||||||
! Diagonalize Fock matrix
|
! Diagonalize Fock matrix
|
||||||
|
|
||||||
Fp = matmul(transpose(X),matmul(F,X))
|
Fp = matmul(transpose(X),matmul(F,X))
|
||||||
cp(:,:) = Fp(:,:)
|
cp(:,:) = Fp(:,:)
|
||||||
write(*,*) nBas
|
call complex_diagonalize_matrix(nBas,Fp,eHF)
|
||||||
call complex_diagonalize_matrix(nBas,cp,eHF)
|
|
||||||
c = matmul(X,cp)
|
c = matmul(X,cp)
|
||||||
! Density matrix
|
! Density matrix
|
||||||
|
|
||||||
@ -178,7 +180,7 @@ subroutine cRHF(dotest,maxSCF,thresh,max_diis,guess_type,level_shift,nNuc,ZNuc,r
|
|||||||
! Dump results
|
! Dump results
|
||||||
|
|
||||||
write(*,'(1X,A1,1X,I3,1X,A1,1X,F32.10,1X,A1,1X,F32.10,A1,1X,A1,1X,F32.10,1X,A1,1X,F32.10,1X,A1,1X,E10.2,1X,A1,1X)') &
|
write(*,'(1X,A1,1X,I3,1X,A1,1X,F32.10,1X,A1,1X,F32.10,A1,1X,A1,1X,F32.10,1X,A1,1X,F32.10,1X,A1,1X,E10.2,1X,A1,1X)') &
|
||||||
'|',nSCF,'|',real(ERHF),'+',aimag(ERHF),'i','|',EJ,'|',EK,'|',Conv,'|'
|
'|',nSCF,'|',real(ERHF),'+',aimag(ERHF),'i','|',real(EJ),'|',real(EK),'|',Conv,'|'
|
||||||
write(*,*) real(ERHF),'+',aimag(ERHF),'i'
|
write(*,*) real(ERHF),'+',aimag(ERHF),'i'
|
||||||
end do
|
end do
|
||||||
write(*,*)'--------------------------------------------------------------------------------------------------'
|
write(*,*)'--------------------------------------------------------------------------------------------------'
|
||||||
|
@ -12,12 +12,12 @@ subroutine complex_core_guess(nBas, nOrb, Hc, X, c)
|
|||||||
|
|
||||||
! Local variables
|
! Local variables
|
||||||
|
|
||||||
complex*16,allocatable :: cp(:,:)
|
complex*16,allocatable :: cp(:,:)
|
||||||
complex*16,allocatable :: e(:)
|
complex*16,allocatable :: e(:)
|
||||||
|
|
||||||
! Output variables
|
! Output variables
|
||||||
|
|
||||||
complex*16,intent(out) :: c(nBas,nOrb)
|
complex*16,intent(inout) :: c(nBas,nOrb)
|
||||||
|
|
||||||
! Memory allocation
|
! Memory allocation
|
||||||
|
|
||||||
|
@ -28,9 +28,7 @@ subroutine complex_mo_guess(nBas, nOrb, guess_type, S, Hc, X, c)
|
|||||||
|
|
||||||
write(*,*) 'Core guess...'
|
write(*,*) 'Core guess...'
|
||||||
call complex_core_guess(nBas, nOrb, Hc, X, c)
|
call complex_core_guess(nBas, nOrb, Hc, X, c)
|
||||||
|
|
||||||
else
|
else
|
||||||
|
|
||||||
print*,'Wrong guess option'
|
print*,'Wrong guess option'
|
||||||
stop
|
stop
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
subroutine level_shifting(level_shift, nBas, nOrb, nO, S, c, F)
|
subroutine complex_level_shifting(level_shift, nBas, nOrb, nO, S, c, F)
|
||||||
|
|
||||||
! Perform level-shifting on the Fock matrix
|
! Perform level-shifting on the Fock matrix
|
||||||
|
|
||||||
@ -21,7 +21,7 @@ subroutine level_shifting(level_shift, nBas, nOrb, nO, S, c, F)
|
|||||||
|
|
||||||
! Output variables
|
! Output variables
|
||||||
|
|
||||||
double precision,intent(inout):: F(nBas,nBas)
|
complex*16,intent(inout) :: F(nBas,nBas)
|
||||||
|
|
||||||
allocate(F_MO(nOrb,nOrb), Sc(nBas,nOrb))
|
allocate(F_MO(nOrb,nOrb), Sc(nBas,nOrb))
|
||||||
complex_level_shift = cmplx(level_shift, 0.0,kind=8)
|
complex_level_shift = cmplx(level_shift, 0.0,kind=8)
|
||||||
|
15
src/utils/complex_matout.f90
Normal file
15
src/utils/complex_matout.f90
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
subroutine complex_matout(n,m,A)
|
||||||
|
|
||||||
|
implicit none
|
||||||
|
|
||||||
|
! Input variables
|
||||||
|
|
||||||
|
integer,intent(in) :: n,m
|
||||||
|
complex*16,intent(in) :: A(n,m)
|
||||||
|
|
||||||
|
write( *,*) 'Real part:'
|
||||||
|
call matout(n,m,real(A))
|
||||||
|
write (*,*) 'Imaginary part:'
|
||||||
|
call matout(n,m,aimag(A))
|
||||||
|
|
||||||
|
end subroutine
|
33
src/utils/complex_sort_eigenvalues.f90
Normal file
33
src/utils/complex_sort_eigenvalues.f90
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
subroutine complex_sort_eigenvalues(N, eigvals, eigvecs)
|
||||||
|
implicit none
|
||||||
|
integer, intent(in) :: N
|
||||||
|
complex*16, intent(inout) :: eigvals(N)
|
||||||
|
complex*16, intent(inout) :: eigvecs(N, N)
|
||||||
|
|
||||||
|
integer :: i, j
|
||||||
|
complex*16 :: temp_eigval
|
||||||
|
complex*16 :: temp_vec(N)
|
||||||
|
logical :: swapped
|
||||||
|
|
||||||
|
do i = 1, N-1
|
||||||
|
swapped = .FALSE.
|
||||||
|
do j = 1, N-i
|
||||||
|
if (REAL(eigvals(j)) > REAL(eigvals(j+1))) then
|
||||||
|
! Swap eigenvalues
|
||||||
|
temp_eigval = eigvals(j)
|
||||||
|
eigvals(j) = eigvals(j+1)
|
||||||
|
eigvals(j+1) = temp_eigval
|
||||||
|
|
||||||
|
! Swap corresponding eigenvectors
|
||||||
|
temp_vec = eigvecs(:, j)
|
||||||
|
eigvecs(:, j) = eigvecs(:, j+1)
|
||||||
|
eigvecs(:, j+1) = temp_vec
|
||||||
|
|
||||||
|
swapped = .TRUE.
|
||||||
|
end if
|
||||||
|
end do
|
||||||
|
! If no swaps were made, the array is already sorted
|
||||||
|
if (.not. swapped) exit
|
||||||
|
end do
|
||||||
|
|
||||||
|
end subroutine
|
17
src/utils/complex_vecout.f90
Normal file
17
src/utils/complex_vecout.f90
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
subroutine complex_vecout(n,v)
|
||||||
|
|
||||||
|
implicit none
|
||||||
|
|
||||||
|
! Input variables
|
||||||
|
integer,intent(in) :: n
|
||||||
|
complex*16,intent(in) :: v(n)
|
||||||
|
! Local variables
|
||||||
|
double precision,allocatable :: v2(:,:)
|
||||||
|
|
||||||
|
allocate(v2(n,2))
|
||||||
|
write(*,*) 'First column real part, second imaginary part'
|
||||||
|
v2(:,1) = real(v)
|
||||||
|
v2(:,2) = aimag(v)
|
||||||
|
call matout(n,2,v2)
|
||||||
|
deallocate(v2)
|
||||||
|
end subroutine
|
@ -149,23 +149,22 @@ subroutine complex_diagonalize_matrix(N,A,e)
|
|||||||
complex*16 :: VR(N,N)
|
complex*16 :: VR(N,N)
|
||||||
|
|
||||||
! Memory allocation
|
! Memory allocation
|
||||||
|
|
||||||
allocate(work(1))
|
allocate(work(1))
|
||||||
|
|
||||||
lwork = -1
|
lwork = -1
|
||||||
call zgeev('N','V',N,A,N,e,VL,N,VR,N,work,lwork,rwork,info)
|
call zgeev('N','V',N,A,N,e,VL,N,VR,N,work,lwork,rwork,info)
|
||||||
lwork = int(work(1))
|
lwork = max(1,int(real(work(1))))
|
||||||
|
|
||||||
deallocate(work)
|
deallocate(work)
|
||||||
|
|
||||||
allocate(work(lwork))
|
allocate(work(lwork))
|
||||||
|
|
||||||
call zgeev('N','V',N,A,N,e,VL,N,VR,N,work,lwork,rwork,info)
|
call zgeev('N','V',N,A,N,e,VL,N,VR,N,work,lwork,rwork,info)
|
||||||
|
call complex_sort_eigenvalues(N,e,VR)
|
||||||
|
|
||||||
deallocate(work)
|
deallocate(work)
|
||||||
A = VR
|
A = VR
|
||||||
|
|
||||||
if(info /= 0) then
|
if(info /= 0) then
|
||||||
print*,'Problem in diagonalize_matrix (zgees)!!'
|
print*,'Problem in diagonalize_matrix (zgeev)!!'
|
||||||
end if
|
end if
|
||||||
|
|
||||||
end subroutine
|
end subroutine
|
||||||
|
Loading…
x
Reference in New Issue
Block a user