10
0
mirror of https://github.com/LCPQ/quantum_package synced 2024-06-21 20:52:18 +02:00

MRCC_Utils_new seems to work, but not sure

This commit is contained in:
Manu 2015-07-28 16:41:02 +02:00
parent 83c8b0c3f8
commit 608f1fd302
9 changed files with 920 additions and 8 deletions

View File

@ -0,0 +1,23 @@
===========
MRCC Module
===========
Needed Modules
==============
.. Do not edit this section. It was auto-generated from the
.. by the `update_README.py` script.
.. image:: tree_dependency.png
* `Perturbation <http://github.com/LCPQ/quantum_package/tree/master/src/Perturbation>`_
* `Selectors_full <http://github.com/LCPQ/quantum_package/tree/master/src/Selectors_full>`_
* `Generators_full <http://github.com/LCPQ/quantum_package/tree/master/src/Generators_full>`_
* `Psiref_Utils <http://github.com/LCPQ/quantum_package/tree/master/src/Psiref_Utils>`_
Documentation
=============
.. Do not edit this section. It was auto-generated from the
.. by the `update_README.py` script.

View File

@ -0,0 +1,430 @@
subroutine davidson_diag_mrcc(dets_in,u_in,energies,dim_in,sze,N_st,Nint,iunit,istate)
use bitmasks
implicit none
BEGIN_DOC
! Davidson diagonalization.
!
! dets_in : bitmasks corresponding to determinants
!
! u_in : guess coefficients on the various states. Overwritten
! on exit
!
! dim_in : leftmost dimension of u_in
!
! sze : Number of determinants
!
! N_st : Number of eigenstates
!
! iunit : Unit number for the I/O
!
! Initial guess vectors are not necessarily orthonormal
END_DOC
integer, intent(in) :: dim_in, sze, N_st, Nint, iunit, istate
integer(bit_kind), intent(in) :: dets_in(Nint,2,sze)
double precision, intent(inout) :: u_in(dim_in,N_st)
double precision, intent(out) :: energies(N_st)
double precision, allocatable :: H_jj(:)
double precision :: diag_h_mat_elem
integer :: i
ASSERT (N_st > 0)
ASSERT (sze > 0)
ASSERT (Nint > 0)
ASSERT (Nint == N_int)
PROVIDE mo_bielec_integrals_in_map
allocate(H_jj(sze))
!$OMP PARALLEL DEFAULT(NONE) &
!$OMP SHARED(sze,H_jj,N_det_ref,dets_in,Nint,istate,delta_ii,idx_ref) &
!$OMP PRIVATE(i)
!$OMP DO SCHEDULE(guided)
do i=1,sze
H_jj(i) = diag_h_mat_elem(dets_in(1,1,i),Nint)
enddo
!$OMP END DO
!$OMP DO SCHEDULE(guided)
do i=1,N_det_ref
H_jj(idx_ref(i)) += delta_ii(i,istate)
enddo
!$OMP END DO
!$OMP END PARALLEL
call davidson_diag_hjj_mrcc(dets_in,u_in,H_jj,energies,dim_in,sze,N_st,Nint,iunit,istate)
deallocate (H_jj)
end
subroutine davidson_diag_hjj_mrcc(dets_in,u_in,H_jj,energies,dim_in,sze,N_st,Nint,iunit,istate)
use bitmasks
implicit none
BEGIN_DOC
! Davidson diagonalization with specific diagonal elements of the H matrix
!
! H_jj : specific diagonal H matrix elements to diagonalize de Davidson
!
! dets_in : bitmasks corresponding to determinants
!
! u_in : guess coefficients on the various states. Overwritten
! on exit
!
! dim_in : leftmost dimension of u_in
!
! sze : Number of determinants
!
! N_st : Number of eigenstates
!
! iunit : Unit for the I/O
!
! Initial guess vectors are not necessarily orthonormal
END_DOC
integer, intent(in) :: dim_in, sze, N_st, Nint, istate
integer(bit_kind), intent(in) :: dets_in(Nint,2,sze)
double precision, intent(in) :: H_jj(sze)
integer, intent(in) :: iunit
double precision, intent(inout) :: u_in(dim_in,N_st)
double precision, intent(out) :: energies(N_st)
integer :: iter
integer :: i,j,k,l,m
logical :: converged
double precision :: overlap(N_st,N_st)
double precision :: u_dot_v, u_dot_u
integer, allocatable :: kl_pairs(:,:)
integer :: k_pairs, kl
integer :: iter2
double precision, allocatable :: W(:,:,:), U(:,:,:), R(:,:)
double precision, allocatable :: y(:,:,:,:), h(:,:,:,:), lambda(:)
double precision :: diag_h_mat_elem
double precision :: residual_norm(N_st)
character*(16384) :: write_buffer
double precision :: to_print(2,N_st)
double precision :: cpu, wall
PROVIDE det_connections
call write_time(iunit)
call wall_time(wall)
call cpu_time(cpu)
write(iunit,'(A)') ''
write(iunit,'(A)') 'Davidson Diagonalization'
write(iunit,'(A)') '------------------------'
write(iunit,'(A)') ''
call write_int(iunit,N_st,'Number of states')
call write_int(iunit,sze,'Number of determinants')
write(iunit,'(A)') ''
write_buffer = '===== '
do i=1,N_st
write_buffer = trim(write_buffer)//' ================ ================'
enddo
write(iunit,'(A)') trim(write_buffer)
write_buffer = ' Iter'
do i=1,N_st
write_buffer = trim(write_buffer)//' Energy Residual'
enddo
write(iunit,'(A)') trim(write_buffer)
write_buffer = '===== '
do i=1,N_st
write_buffer = trim(write_buffer)//' ================ ================'
enddo
write(iunit,'(A)') trim(write_buffer)
allocate( &
kl_pairs(2,N_st*(N_st+1)/2), &
W(sze,N_st,davidson_sze_max), &
U(sze,N_st,davidson_sze_max), &
R(sze,N_st), &
h(N_st,davidson_sze_max,N_st,davidson_sze_max), &
y(N_st,davidson_sze_max,N_st,davidson_sze_max), &
lambda(N_st*davidson_sze_max))
ASSERT (N_st > 0)
ASSERT (sze > 0)
ASSERT (Nint > 0)
ASSERT (Nint == N_int)
! Initialization
! ==============
k_pairs=0
do l=1,N_st
do k=1,l
k_pairs+=1
kl_pairs(1,k_pairs) = k
kl_pairs(2,k_pairs) = l
enddo
enddo
!$OMP PARALLEL DEFAULT(NONE) &
!$OMP SHARED(U,sze,N_st,overlap,kl_pairs,k_pairs, &
!$OMP Nint,dets_in,u_in) &
!$OMP PRIVATE(k,l,kl,i)
! Orthonormalize initial guess
! ============================
!$OMP DO
do kl=1,k_pairs
k = kl_pairs(1,kl)
l = kl_pairs(2,kl)
if (k/=l) then
overlap(k,l) = u_dot_v(U_in(1,k),U_in(1,l),sze)
overlap(l,k) = overlap(k,l)
else
overlap(k,k) = u_dot_u(U_in(1,k),sze)
endif
enddo
!$OMP END DO
!$OMP END PARALLEL
call ortho_lowdin(overlap,size(overlap,1),N_st,U_in,size(U_in,1),sze)
! Davidson iterations
! ===================
converged = .False.
do while (.not.converged)
!$OMP PARALLEL DEFAULT(NONE) &
!$OMP PRIVATE(k,i) SHARED(U,u_in,sze,N_st)
do k=1,N_st
!$OMP DO
do i=1,sze
U(i,k,1) = u_in(i,k)
enddo
!$OMP END DO
enddo
!$OMP END PARALLEL
do iter=1,davidson_sze_max-1
! Compute W_k = H |u_k>
! ----------------------
do k=1,N_st
call H_u_0_mrcc(W(1,k,iter),U(1,k,iter),H_jj,sze,dets_in,Nint,istate)
enddo
! Compute h_kl = <u_k | W_l> = <u_k| H |u_l>
! -------------------------------------------
do l=1,N_st
do k=1,N_st
do iter2=1,iter-1
h(k,iter2,l,iter) = u_dot_v(U(1,k,iter2),W(1,l,iter),sze)
h(k,iter,l,iter2) = h(k,iter2,l,iter)
enddo
enddo
do k=1,l
h(k,iter,l,iter) = u_dot_v(U(1,k,iter),W(1,l,iter),sze)
h(l,iter,k,iter) = h(k,iter,l,iter)
enddo
enddo
!DEBUG H MATRIX
!do i=1,iter
! print '(10(x,F16.10))', h(1,i,1,1:i)
!enddo
!print *, ''
!END
! Diagonalize h
! -------------
call lapack_diag(lambda,y,h,N_st*davidson_sze_max,N_st*iter)
! Express eigenvectors of h in the determinant basis
! --------------------------------------------------
do k=1,N_st
do i=1,sze
U(i,k,iter+1) = 0.d0
W(i,k,iter+1) = 0.d0
do l=1,N_st
do iter2=1,iter
U(i,k,iter+1) = U(i,k,iter+1) + U(i,l,iter2)*y(l,iter2,k,1)
W(i,k,iter+1) = W(i,k,iter+1) + W(i,l,iter2)*y(l,iter2,k,1)
enddo
enddo
enddo
enddo
! Compute residual vector
! -----------------------
do k=1,N_st
do i=1,sze
R(i,k) = lambda(k) * U(i,k,iter+1) - W(i,k,iter+1)
enddo
residual_norm(k) = u_dot_u(R(1,k),sze)
to_print(1,k) = lambda(k) + nuclear_repulsion
to_print(2,k) = residual_norm(k)
enddo
write(iunit,'(X,I3,X,100(X,F16.10,X,E16.6))'), iter, to_print(:,1:N_st)
call davidson_converged(lambda,residual_norm,wall,iter,cpu,N_st,converged)
if (converged) then
exit
endif
! Davidson step
! -------------
do k=1,N_st
do i=1,sze
U(i,k,iter+1) = -1.d0/max(H_jj(i) - lambda(k),1.d-2) * R(i,k)
enddo
enddo
! Gram-Schmidt
! ------------
double precision :: c
do k=1,N_st
do iter2=1,iter
do l=1,N_st
c = u_dot_v(U(1,k,iter+1),U(1,l,iter2),sze)
do i=1,sze
U(i,k,iter+1) -= c * U(i,l,iter2)
enddo
enddo
enddo
do l=1,k-1
c = u_dot_v(U(1,k,iter+1),U(1,l,iter+1),sze)
do i=1,sze
U(i,k,iter+1) -= c * U(i,l,iter+1)
enddo
enddo
call normalize( U(1,k,iter+1), sze )
enddo
!DEBUG : CHECK OVERLAP
!print *, '==='
!do k=1,iter+1
! do l=1,k
! c = u_dot_v(U(1,1,k),U(1,1,l),sze)
! print *, k,l, c
! enddo
!enddo
!print *, '==='
!pause
!END DEBUG
enddo
if (.not.converged) then
iter = davidson_sze_max-1
endif
! Re-contract to u_in
! -----------
do k=1,N_st
energies(k) = lambda(k)
do i=1,sze
u_in(i,k) = 0.d0
do iter2=1,iter
do l=1,N_st
u_in(i,k) += U(i,l,iter2)*y(l,iter2,k,1)
enddo
enddo
enddo
enddo
enddo
write_buffer = '===== '
do i=1,N_st
write_buffer = trim(write_buffer)//' ================ ================'
enddo
write(iunit,'(A)') trim(write_buffer)
write(iunit,'(A)') ''
call write_time(iunit)
deallocate ( &
kl_pairs, &
W, &
U, &
R, &
h, &
y, &
lambda &
)
abort_here = abort_all
end
subroutine H_u_0_mrcc(v_0,u_0,H_jj,n,keys_tmp,Nint,istate)
use bitmasks
implicit none
BEGIN_DOC
! Computes v_0 = H|u_0>
!
! n : number of determinants
!
! H_jj : array of <j|H|j>
END_DOC
integer, intent(in) :: n,Nint,istate
double precision, intent(out) :: v_0(n)
double precision, intent(in) :: u_0(n)
double precision, intent(in) :: H_jj(n)
integer(bit_kind),intent(in) :: keys_tmp(Nint,2,n)
integer, allocatable :: idx(:)
double precision :: hij
double precision, allocatable :: vt(:)
integer :: i,j,k,l, jj,ii
integer :: i0, j0
ASSERT (Nint > 0)
ASSERT (Nint == N_int)
ASSERT (n>0)
PROVIDE ref_bitmask_energy delta_ij
integer, parameter :: block_size = 157
!$OMP PARALLEL DEFAULT(NONE) &
!$OMP PRIVATE(i,hij,j,k,idx,jj,ii,vt) &
!$OMP SHARED(n_det_ref,n_det_non_ref,idx_ref,idx_non_ref,n,H_jj,u_0,keys_tmp,Nint,v_0,istate,delta_ij)
!$OMP DO SCHEDULE(static)
do i=1,n
v_0(i) = H_jj(i) * u_0(i)
enddo
!$OMP END DO
allocate(idx(0:n), vt(n))
Vt = 0.d0
!$OMP DO SCHEDULE(guided)
do i=1,n
idx(0) = i
call filter_connected_davidson(keys_tmp,keys_tmp(1,1,i),Nint,i-1,idx)
do jj=1,idx(0)
j = idx(jj)
if ( (dabs(u_0(j)) > 1.d-7).or.((dabs(u_0(i)) > 1.d-7)) ) then
call i_H_j(keys_tmp(1,1,j),keys_tmp(1,1,i),Nint,hij)
hij = hij
vt (i) = vt (i) + hij*u_0(j)
vt (j) = vt (j) + hij*u_0(i)
endif
enddo
enddo
!$OMP END DO
!$OMP DO SCHEDULE(guided)
do ii=1,n_det_ref
i = idx_ref(ii)
do jj = 1, n_det_non_ref
j = idx_non_ref(jj)
vt (i) = vt (i) + delta_ij(ii,jj,istate)*u_0(j)
vt (j) = vt (j) + delta_ij(ii,jj,istate)*u_0(i)
enddo
enddo
!$OMP END DO
!$OMP CRITICAL
do i=1,n
v_0(i) = v_0(i) + vt(i)
enddo
!$OMP END CRITICAL
deallocate(idx,vt)
!$OMP END PARALLEL
end

View File

@ -0,0 +1,85 @@
subroutine get_excitation_operators_for_one_ref(det_ref,i_state,ndetnonref,N_connect_ref,excitation_operators,amplitudes_phase_less,index_connected)
use bitmasks
implicit none
integer(bit_kind), intent(in) :: det_ref(N_int,2)
integer, intent(in) :: i_state,ndetnonref
integer*2, intent(out) :: excitation_operators(5,ndetnonref)
integer, intent(out) :: index_connected(ndetnonref)
integer, intent(out) :: N_connect_ref
double precision, intent(out) :: amplitudes_phase_less(ndetnonref)
integer :: i,j,k,l,degree,h1,p1,h2,p2,s1,s2
integer :: exc(0:2,2,2)
double precision :: phase,hij
BEGIN_DOC
! This subroutine provides all the amplitudes and excitation operators
! that one needs to go from the reference to the non reference wave function
! you enter with det_ref that is a reference determinant
!
! N_connect_ref is the number of determinants belonging to psi_non_ref
! that are connected to det_ref.
!
! amplitudes_phase_less(i) = amplitude phase less t_{I->i} = <I|H|i> * lambda_mrcc(i) * phase(I->i)
!
! excitation_operators(:,i) represents the holes and particles that
! link the ith connected determinant to det_ref
! if ::
! excitation_operators(5,i) = 2 :: double excitation alpha
! excitation_operators(5,i) = -2 :: double excitation beta
!!! excitation_operators(1,i) :: hole 1
!!! excitation_operators(2,i) :: particle 1
!!! excitation_operators(3,i) :: hole 2
!!! excitation_operators(4,i) :: particle 2
! else if ::
! excitation_operators(5,i) = 1 :: single excitation alpha
!!! excitation_operators(1,i) :: hole 1
!!! excitation_operators(2,i) :: particle 1
! else if ::
! excitation_operators(5,i) = -1 :: single excitation beta
!!! excitation_operators(3,i) :: hole 1
!!! excitation_operators(4,i) :: particle 1
! else if ::
!!! excitation_operators(5,i) = 0 :: double excitation alpha/beta
!!! excitation_operators(1,i) :: hole 1 alpha
!!! excitation_operators(2,i) :: particle 1 alpha
!!! excitation_operators(3,i) :: hole 2 beta
!!! excitation_operators(4,i) :: particle 2 beta
END_DOC
N_connect_ref = 0
do i = 1, ndetnonref
call i_H_j_phase_out(det_ref,psi_non_ref(1,1,i),N_int,hij,phase,exc,degree)
! if(dabs(hij).le.mo_integrals_threshold)cycle
N_connect_ref +=1
index_connected(N_connect_ref) = i
call decode_exc(exc,degree,h1,p1,h2,p2,s1,s2)
amplitudes_phase_less(N_connect_ref) = hij * lambda_mrcc(i_state,i) !*phase
if(degree==2)then
excitation_operators(1,N_connect_ref) = h1
excitation_operators(2,N_connect_ref) = p1
excitation_operators(3,N_connect_ref) = h2
excitation_operators(4,N_connect_ref) = p2
if(s1==s2.and.s1==1)then ! double alpha
excitation_operators(5,N_connect_ref)= 2
elseif(s1==s2.and.s1==2)then ! double beta
excitation_operators(5,N_connect_ref)=-2
else
excitation_operators(5,N_connect_ref)= 0 ! double alpha/beta
endif
elseif(degree==1)then
if(s1==1)then ! mono alpha
excitation_operators(5,N_connect_ref)= 1
excitation_operators(1,N_connect_ref) = h1
excitation_operators(2,N_connect_ref) = p1
else ! mono beta
excitation_operators(5,N_connect_ref)=-1
excitation_operators(3,N_connect_ref) = h1
excitation_operators(4,N_connect_ref) = p1
endif
else
N_connect_ref-=1
endif
enddo
end

View File

@ -0,0 +1,129 @@
subroutine mrcc_dress(ndetref,ndetnonref,nstates,delta_ij_,delta_ii_)
use bitmasks
implicit none
integer, intent(in) :: ndetref,nstates,ndetnonref
double precision, intent(inout) :: delta_ii_(ndetref,nstates),delta_ij_(ndetref,ndetnonref,nstates)
integer :: i,j,k,l
integer :: i_state
integer :: N_connect_ref
integer*2,allocatable :: excitation_operators(:,:)
double precision, allocatable :: amplitudes_phase_less(:)
double precision, allocatable :: coef_test(:)
integer(bit_kind), allocatable :: key_test(:,:)
integer, allocatable :: index_connected(:)
integer :: i_hole,i_particle,ispin,i_ok,connected_to_ref,index_wf
integer, allocatable :: idx_vector(:), degree_vector(:)
double precision :: phase_ij
double precision :: dij,phase_la
double precision :: hij,phase
integer :: exc(0:2,2,2),degree
logical :: is_in_wavefunction
allocate(excitation_operators(5,N_det_non_ref))
allocate(amplitudes_phase_less(N_det_non_ref))
allocate(key_test(N_int,2))
allocate(index_connected(N_det_non_ref))
allocate(idx_vector(0:N_det_non_ref))
allocate(degree_vector(N_det_non_ref))
i_state = 1
do i = 1, N_det_ref
call get_excitation_operators_for_one_ref(psi_ref(1,1,i),i_state,N_det_non_ref,N_connect_ref,excitation_operators,amplitudes_phase_less,index_connected)
print*,'N_connect_ref =',N_connect_ref
do l = 1, N_det_non_ref
double precision :: t_il,phase_il,hil
call i_H_j_phase_out(psi_ref(1,1,i),psi_non_ref(1,1,l),N_int,hil,phase_il,exc,degree)
t_il = hil * lambda_mrcc(i_state,l)
! loop on the non ref determinants
do j = 1, N_connect_ref
! loop on the excitation operators linked to i
if(j==l)cycle
do k = 1, N_int
key_test(k,1) = psi_non_ref(k,1,l)
key_test(k,2) = psi_non_ref(k,2,l)
enddo
! we apply the excitation operator T_I->j
call apply_excitation_operator(key_test,excitation_operators(1,j),i_ok)
if(i_ok.ne.1)cycle
! we check if such determinant is already in the wave function
if(is_in_wavefunction(key_test,N_int,N_det))cycle
! we get the phase for psi_non_ref(l) -> T_I->j |psi_non_ref(l)>
call get_excitation(psi_non_ref(1,1,l),key_test,exc,degree,phase_la,N_int)
! we get the phase T_I->j
call i_H_j_phase_out(psi_ref(1,1,i),psi_non_ref(1,1,index_connected(j)),N_int,hij,phase_ij,exc,degree)
! we compute the contribution to the coef of key_test
dij = t_il * hij * phase_la *phase_ij *lambda_mrcc(i_state,index_connected(j)) * 0.5d0
! we compute the interaction of such determinant with all the non_ref dets
call get_excitation_degree_vector(psi_non_ref,key_test,degree_vector,N_int,N_det_non_ref,idx_vector)
do k = 1, idx_vector(0)
call i_H_j_phase_out(key_test,psi_non_ref(1,1,idx_vector(k)),N_int,hij,phase,exc,degree)
delta_ij_(i,idx_vector(k),i_state) += hij * dij
enddo
enddo
if(dabs(psi_ref_coef(i,i_state)).le.5.d-5)cycle
! delta_ij_(i,l,i_state) = delta_ij_(i,l,i_state) * 0.5d0
delta_ii_(i,i_state) -= delta_ij_(i,l,i_state) * psi_non_ref_coef(l,i_state) / psi_ref_coef(i,i_state)
enddo
enddo
deallocate(excitation_operators)
deallocate(amplitudes_phase_less)
deallocate(key_test)
deallocate(idx_vector)
deallocate(degree_vector)
end
subroutine apply_excitation_operator(key_in,excitation_operator,i_ok)
use bitmasks
implicit none
integer(bit_kind), intent(inout) :: key_in
integer, intent (out) :: i_ok
integer*2 :: excitation_operator(5)
integer :: i_particle,i_hole,ispin
! Do excitation
if(excitation_operator(5)==1)then ! mono alpha
i_hole = excitation_operator(1)
i_particle = excitation_operator(2)
ispin = 1
call do_mono_excitation(key_in,i_hole,i_particle,ispin,i_ok)
else if (excitation_operator(5)==-1)then ! mono beta
i_hole = excitation_operator(3)
i_particle = excitation_operator(4)
ispin = 2
call do_mono_excitation(key_in,i_hole,i_particle,ispin,i_ok)
else if (excitation_operator(5) == -2 )then ! double beta
i_hole = excitation_operator(1)
i_particle = excitation_operator(2)
ispin = 2
call do_mono_excitation(key_in,i_hole,i_particle,ispin,i_ok)
if(i_ok.ne.1)return
i_hole = excitation_operator(3)
i_particle = excitation_operator(4)
ispin = 2
call do_mono_excitation(key_in,i_hole,i_particle,ispin,i_ok)
else if (excitation_operator(5) == 2 )then ! double alpha
i_hole = excitation_operator(1)
i_particle = excitation_operator(2)
ispin = 1
call do_mono_excitation(key_in,i_hole,i_particle,ispin,i_ok)
if(i_ok.ne.1)return
i_hole = excitation_operator(3)
i_particle = excitation_operator(4)
ispin = 1
call do_mono_excitation(key_in,i_hole,i_particle,ispin,i_ok)
else if (excitation_operator(5) == 0 )then ! double alpha/alpha
i_hole = excitation_operator(1)
i_particle = excitation_operator(2)
ispin = 1
call do_mono_excitation(key_in,i_hole,i_particle,ispin,i_ok)
if(i_ok.ne.1)return
i_hole = excitation_operator(3)
i_particle = excitation_operator(4)
ispin = 2
call do_mono_excitation(key_in,i_hole,i_particle,ispin,i_ok)
endif
end

View File

@ -0,0 +1,67 @@
subroutine run_mrcc
implicit none
call set_generators_bitmasks_as_holes_and_particles
call mrcc_iterations
end
subroutine mrcc_iterations
implicit none
integer :: i,j
double precision :: E_new, E_old, delta_e
integer :: iteration
E_new = 0.d0
delta_E = 1.d0
iteration = 0
do while (delta_E > 1.d-8)
iteration += 1
print *, '==========================='
print *, 'MRCC Iteration', iteration
print *, '==========================='
print *, ''
E_old = sum(ci_energy_dressed)
call write_double(6,ci_energy_dressed(1),"MRCC energy")
call diagonalize_ci_dressed
E_new = sum(ci_energy_dressed)
delta_E = dabs(E_new - E_old)
! stop
if (iteration > 200) then
exit
endif
enddo
call write_double(6,ci_energy_dressed(1),"Final MRCC energy")
call ezfio_set_mrcc_cassd_energy(ci_energy_dressed(1))
call save_wavefunction
end
subroutine set_generators_bitmasks_as_holes_and_particles
implicit none
integer :: i,k
do k = 1, N_generators_bitmask
do i = 1, N_int
! Pure single part
generators_bitmask(i,1,1,k) = holes_operators(i,1) ! holes for pure single exc alpha
generators_bitmask(i,1,2,k) = particles_operators(i,1) ! particles for pure single exc alpha
generators_bitmask(i,2,1,k) = holes_operators(i,2) ! holes for pure single exc beta
generators_bitmask(i,2,2,k) = particles_operators(i,2) ! particles for pure single exc beta
! Double excitation
generators_bitmask(i,1,3,k) = holes_operators(i,1) ! holes for first single exc alpha
generators_bitmask(i,1,4,k) = particles_operators(i,1) ! particles for first single exc alpha
generators_bitmask(i,2,3,k) = holes_operators(i,2) ! holes for first single exc beta
generators_bitmask(i,2,4,k) = particles_operators(i,2) ! particles for first single exc beta
generators_bitmask(i,1,5,k) = holes_operators(i,1) ! holes for second single exc alpha
generators_bitmask(i,1,6,k) = particles_operators(i,1) ! particles for second single exc alpha
generators_bitmask(i,2,5,k) = holes_operators(i,2) ! holes for second single exc beta
generators_bitmask(i,2,6,k) = particles_operators(i,2) ! particles for second single exc beta
enddo
enddo
touch generators_bitmask
end

View File

@ -0,0 +1,179 @@
BEGIN_PROVIDER [ double precision, lambda_mrcc, (N_states,psi_det_size) ]
&BEGIN_PROVIDER [ double precision, lambda_pert, (N_states,psi_det_size) ]
implicit none
BEGIN_DOC
! cm/<Psi_0|H|D_m> or perturbative 1/Delta_E(m)
END_DOC
integer :: i,k
double precision :: ihpsi(N_states), hii
integer :: i_ok
i_ok = 0
do i=1,N_det_non_ref
call i_h_psi(psi_non_ref(1,1,i), psi_ref, psi_ref_coef, N_int, N_det_ref,&
size(psi_ref_coef,1), n_states, ihpsi)
call i_h_j(psi_non_ref(1,1,i),psi_non_ref(1,1,i),N_int,hii)
do k=1,N_states
lambda_pert(k,i) = 1.d0 / (psi_ref_energy_diagonalized(k)-hii)
if (dabs(ihpsi(k)).le.1.d-3) then
i_ok +=1
lambda_mrcc(k,i) = lambda_pert(k,i)
else
lambda_mrcc(k,i) = psi_non_ref_coef(i,k)/ihpsi(k)
endif
enddo
enddo
print*,'N_det_non_ref = ',N_det_non_ref
print*,'Number of Perturbatively treated determinants = ',i_ok
print*,'psi_coef_ref_ratio = ',psi_ref_coef(2,1)/psi_ref_coef(1,1)
END_PROVIDER
!BEGIN_PROVIDER [ double precision, delta_ij_non_ref, (N_det_non_ref, N_det_non_ref,N_states) ]
!implicit none
!BEGIN_DOC
!! Dressing matrix in SD basis
!END_DOC
!delta_ij_non_ref = 0.d0
!call H_apply_mrcc_simple(delta_ij_non_ref,N_det_non_ref)
!END_PROVIDER
BEGIN_PROVIDER [ double precision, delta_ij, (N_det_ref,N_det_non_ref,N_states) ]
&BEGIN_PROVIDER [ double precision, delta_ii, (N_det_ref,N_states) ]
implicit none
BEGIN_DOC
! Dressing matrix in N_det basis
END_DOC
integer :: i,j,m
delta_ij = 0.d0
delta_ii = 0.d0
call mrcc_dress(N_det_ref,N_det_non_ref,N_states,delta_ij,delta_ii)
write(33,*)delta_ij
write(34,*)delta_ii
END_PROVIDER
BEGIN_PROVIDER [ double precision, h_matrix_dressed, (N_det,N_det,N_states) ]
implicit none
BEGIN_DOC
! Dressed H with Delta_ij
END_DOC
integer :: i, j,istate,ii,jj
do istate = 1,N_states
do j=1,N_det
do i=1,N_det
h_matrix_dressed(i,j,istate) = h_matrix_all_dets(i,j)
enddo
enddo
do ii = 1, N_det_ref
i =idx_ref(ii)
h_matrix_dressed(i,i,istate) += delta_ii(ii,istate)
do jj = 1, N_det_non_ref
j =idx_non_ref(jj)
h_matrix_dressed(i,j,istate) += delta_ij(ii,jj,istate)
h_matrix_dressed(j,i,istate) += delta_ij(ii,jj,istate)
enddo
enddo
enddo
END_PROVIDER
BEGIN_PROVIDER [ double precision, CI_electronic_energy_dressed, (N_states_diag) ]
&BEGIN_PROVIDER [ double precision, CI_eigenvectors_dressed, (N_det,N_states_diag) ]
&BEGIN_PROVIDER [ double precision, CI_eigenvectors_s2_dressed, (N_states_diag) ]
implicit none
BEGIN_DOC
! Eigenvectors/values of the CI matrix
END_DOC
integer :: i,j
do j=1,N_states_diag
do i=1,N_det
CI_eigenvectors_dressed(i,j) = psi_coef(i,j)
enddo
enddo
if (diag_algorithm == "Davidson") then
integer :: istate
istate = 1
call davidson_diag_mrcc(psi_det,CI_eigenvectors_dressed,CI_electronic_energy_dressed,&
size(CI_eigenvectors_dressed,1),N_det,N_states_diag,N_int,output_determinants,istate)
else if (diag_algorithm == "Lapack") then
double precision, allocatable :: eigenvectors(:,:), eigenvalues(:)
allocate (eigenvectors(size(H_matrix_dressed,1),N_det))
allocate (eigenvalues(N_det))
call lapack_diag(eigenvalues,eigenvectors, &
H_matrix_dressed,size(H_matrix_dressed,1),N_det)
CI_electronic_energy_dressed(:) = 0.d0
do i=1,N_det
CI_eigenvectors_dressed(i,1) = eigenvectors(i,1)
enddo
integer :: i_state
double precision :: s2
i_state = 0
if (s2_eig) then
do j=1,N_det
call get_s2_u0(psi_det,eigenvectors(1,j),N_det,N_det,s2)
if(dabs(s2-expected_s2).le.0.3d0)then
i_state += 1
do i=1,N_det
CI_eigenvectors_dressed(i,i_state) = eigenvectors(i,j)
enddo
CI_electronic_energy_dressed(i_state) = eigenvalues(j)
CI_eigenvectors_s2_dressed(i_state) = s2
endif
if (i_state.ge.N_states_diag) then
exit
endif
enddo
else
do j=1,N_states_diag
call get_s2_u0(psi_det,eigenvectors(1,j),N_det,N_det,s2)
i_state += 1
do i=1,N_det
CI_eigenvectors_dressed(i,i_state) = eigenvectors(i,j)
enddo
CI_electronic_energy_dressed(i_state) = eigenvalues(j)
CI_eigenvectors_s2_dressed(i_state) = s2
enddo
endif
deallocate(eigenvectors,eigenvalues)
endif
END_PROVIDER
BEGIN_PROVIDER [ double precision, CI_energy_dressed, (N_states_diag) ]
implicit none
BEGIN_DOC
! N_states lowest eigenvalues of the dressed CI matrix
END_DOC
integer :: j
character*(8) :: st
call write_time(output_determinants)
do j=1,N_states_diag
CI_energy_dressed(j) = CI_electronic_energy_dressed(j) + nuclear_repulsion
enddo
END_PROVIDER
subroutine diagonalize_CI_dressed
implicit none
BEGIN_DOC
! Replace the coefficients of the CI states by the coefficients of the
! eigenstates of the CI matrix
END_DOC
integer :: i,j
do j=1,N_states_diag
do i=1,N_det
psi_coef(i,j) = CI_eigenvectors_dressed(i,j)
enddo
enddo
SOFT_TOUCH psi_coef
end

Binary file not shown.

After

Width:  |  Height:  |  Size: 106 KiB

View File

@ -12,7 +12,7 @@ BEGIN_PROVIDER [ integer, davidson_sze_max ]
! Max number of Davidson sizes
END_DOC
ASSERT (davidson_sze_max <= davidson_iter_max)
davidson_sze_max = 8*N_states_diag
davidson_sze_max = min(8,2*N_states_diag)
END_PROVIDER
subroutine davidson_diag(dets_in,u_in,energies,dim_in,sze,N_st,Nint,iunit)
@ -376,7 +376,7 @@ end
! Can be : [ energy | residual | both | wall_time | cpu_time | iterations ]
END_DOC
davidson_criterion = 'residual'
davidson_threshold = 1.d-9
davidson_threshold = 1.d-15
END_PROVIDER
subroutine davidson_converged(energy,residual,wall,iterations,cpu,N_st,converged)

View File

@ -1096,13 +1096,9 @@ subroutine H_u_0(v_0,u_0,H_jj,n,keys_tmp,Nint)
!$OMP PARALLEL DEFAULT(NONE) &
!$OMP PRIVATE(i,hij,j,k,idx,jj,vt) &
!$OMP SHARED(n,H_jj,u_0,keys_tmp,Nint,v_0)
!$OMP DO SCHEDULE(static)
do i=1,n
v_0(i) = H_jj(i) * u_0(i)
enddo
!$OMP END DO
allocate(idx(0:n), vt(n))
Vt = 0.d0
v_0 = 0.d0
!$OMP DO SCHEDULE(guided)
do i=1,n
idx(0) = i
@ -1119,11 +1115,14 @@ subroutine H_u_0(v_0,u_0,H_jj,n,keys_tmp,Nint)
!$OMP END DO
!$OMP CRITICAL
do i=1,n
v_0(i) = v_0(i) + vt(i)
v_0(i) = v_0(i) + vt(i)
enddo
!$OMP END CRITICAL
deallocate(idx,vt)
!$OMP END PARALLEL
do i=1,n
v_0(i) += H_jj(i) * u_0(i)
enddo
end