10
0
mirror of https://github.com/LCPQ/quantum_package synced 2024-12-27 06:43:48 +01:00
quantum_package/plugins/garniron/mrcepa0/dressing.irp.f

1261 lines
41 KiB
Fortran
Raw Normal View History

2016-03-04 16:52:46 +01:00
use bitmasks
2017-10-12 10:05:27 +02:00
BEGIN_PROVIDER [ integer, N_mrcc_teeth ]
N_mrcc_teeth = 10
END_PROVIDER
BEGIN_PROVIDER [ double precision, mrcc_norm_acc, (0:N_det_non_ref, N_states) ]
&BEGIN_PROVIDER [ double precision, mrcc_norm, (0:N_det_non_ref, N_states) ]
&BEGIN_PROVIDER [ double precision, mrcc_teeth_size, (0:N_det_non_ref, N_states) ]
&BEGIN_PROVIDER [ integer, mrcc_teeth, (0:N_mrcc_teeth+1, N_states) ]
implicit none
integer :: i, j, st, nt
double precision :: norm_sto, jump, norm_mwen, norm_loc
if(N_states /= 1) stop "mrcc_sto may not work with N_states /= 1"
do st=1,N_states
!norm_non_ref = 1d0
!do i=1,N_det_ref
! norm_non_ref -= psi_ref_coef(i,st)**2
!end do
mrcc_teeth(0,st) = 1
!norm_non_sto = norm_non_ref
norm_sto = 1d0
do i=1,N_det
mrcc_teeth(1,st) = i
jump = (1d0 / dfloat(N_mrcc_teeth)) * norm_sto
if(psi_coef_generators(i,1)**2 < jump / 2d0) exit
!if(i==80) exit
norm_sto -= psi_coef_generators(i,1)**2
end do
print *, "FIRST", mrcc_teeth(1,st)
norm_loc = 0d0
mrcc_norm_acc(0,st) = 0d0
nt = 1
do i=1,mrcc_teeth(1,st)-1
mrcc_norm_acc(i,st) = mrcc_norm_acc(i-1,st) + psi_coef_generators(i,st)**2
end do
do i=mrcc_teeth(1,st), N_det_generators!-mrcc_teeth(1,st)+1
norm_mwen = psi_coef_generators(i,st)**2!-1+mrcc_teeth(1,st),st)**2
mrcc_norm_acc(i,st) = mrcc_norm_acc(i-1,st) + norm_mwen
norm_loc += norm_mwen
if(norm_loc > (jump*dfloat(nt))) then
nt = nt + 1
mrcc_teeth(nt,st) = i
end if
end do
if(nt > N_mrcc_teeth+1) then
print *, "foireouse mrcc_teeth", nt, mrcc_teeth(nt,st), N_det_non_ref
stop
end if
mrcc_teeth(N_mrcc_teeth+1,st) = N_det_non_ref+1
!mrcc_norm_acc(:,st) = mrcc_norm_acc(:,st) / norm_non_ref
norm_loc = 0d0
do i=N_mrcc_teeth, 0, -1
mrcc_teeth_size(i,st) = mrcc_norm_acc(mrcc_teeth(i+1,st)-1,st) - mrcc_norm_acc(mrcc_teeth(i,st)-1, st)
mrcc_norm_acc(mrcc_teeth(i,st):mrcc_teeth(i+1,st)-1,st) -= mrcc_norm_acc(mrcc_teeth(i,st)-1, st)
mrcc_norm_acc(mrcc_teeth(i,st):mrcc_teeth(i+1,st)-1,st) = &
mrcc_norm_acc(mrcc_teeth(i,st):mrcc_teeth(i+1,st)-1,st) / mrcc_teeth_size(i,st)
mrcc_norm(mrcc_teeth(i,st), st) = mrcc_norm_acc(mrcc_teeth(i,st), st)
do j=mrcc_teeth(i,st)+1, mrcc_teeth(i+1,1)-1
mrcc_norm(j,1) = mrcc_norm_acc(j, st) - mrcc_norm_acc(j-1, st)
end do
end do
end do
END_PROVIDER
2016-05-13 19:28:50 +02:00
BEGIN_PROVIDER [ double precision, delta_ij_cancel, (N_states,N_det_non_ref) ]
&BEGIN_PROVIDER [ double precision, delta_ij_s2_cancel, (N_states,N_det_non_ref) ]
use bitmasks
implicit none
integer :: i_state, i, i_I, J, k, k2, k1, kk, ll, m,l, deg, ni, m2
integer :: n(2)
integer :: p1,p2,h1,h2,s1,s2, blok, I_s, J_s, kn
logical :: ok
double precision :: phase_ia, phase_Ik, phase_Jl, phase_Ji,phase_la, phase_ka, phase_tmp
double precision :: Hka, Hla, Ska, Sla, tmp
double precision :: diI, hIi, hJi, delta_JI, dkI, HkI,ci_inv(N_states), cj_inv(N_states)
double precision :: contrib, contrib_s2, wall, iwall
integer, dimension(0:2,2,2) :: exc_iI, exc_Ik, exc_IJ, exc
integer(bit_kind) :: det_tmp(N_int, 2), det_tmp2(N_int, 2),inac, virt
integer, external :: get_index_in_psi_det_sorted_bit, searchDet,detCmp
logical, external :: is_in_wavefunction
2017-10-18 15:10:15 +02:00
provide dij
delta_ij_cancel = 0d0
do i=1,N_det_ref
!$OMP PARALLEL DO default(shared) private(kk, k, blok, exc_Ik,det_tmp2,ok,deg,phase_Ik, l,ll) &
2018-02-16 17:26:34 +01:00
!$OMP private(contrib, contrib_s2, i_state)
do kk = 1, nlink(i)
k = det_cepa0_idx(linked(kk, i))
blok = blokMwen(kk, i)
call get_excitation(psi_ref(1,1,i),psi_non_ref(1,1,k),exc_Ik,deg,phase_Ik,N_int)
do j=1,N_det_ref
if(j == i) cycle
call apply_excitation(psi_ref(1,1,J),exc_Ik,det_tmp2,ok,N_int)
if(.not. ok) cycle
l = searchDet(det_cepa0(1,1,cepa0_shortcut(blok)), det_tmp2,cepa0_shortcut(blok+1)-cepa0_shortcut(blok), N_int)
if(l == -1) cycle
ll = cepa0_shortcut(blok)-1+l
l = det_cepa0_idx(ll)
ll = child_num(ll, J)
do i_state = 1, N_states
contrib = (dij(j, l, i_state) - dij(i, k, i_state)) * delta_cas(i,j,i_state)! * Hla *phase_ia * phase_ik
contrib_s2 = dij(j, l, i_state) - dij(i, k, i_state)! * Sla*phase_ia * phase_ik
!$OMP ATOMIC
2018-02-16 17:26:34 +01:00
delta_ij_cancel(i_state,l) += contrib * psi_ref_coef(i,i_state)
!$OMP ATOMIC
2018-02-16 17:26:34 +01:00
delta_ij_s2_cancel(i_state,l) += contrib_s2* psi_ref_coef(i,i_state)
end do
end do
end do
2017-10-18 15:10:15 +02:00
!$OMP END PARALLEL DO
enddo
END_PROVIDER
BEGIN_PROVIDER [ double precision, delta_ij_mrcc, (N_states,N_det_non_ref) ]
&BEGIN_PROVIDER [ double precision, delta_ij_s2_mrcc, (N_states,N_det_non_ref) ]
2016-05-13 19:28:50 +02:00
use bitmasks
implicit none
2018-06-27 15:20:33 +02:00
integer :: gen, h, p, n, t, i, h1, h2, p1, p2, s1, s2
2016-05-20 11:27:39 +02:00
integer(bit_kind) :: mask(N_int, 2), omask(N_int, 2)
2016-05-26 13:52:48 +02:00
integer(bit_kind),allocatable :: buf(:,:,:)
2016-05-13 19:28:50 +02:00
logical :: ok
2016-05-20 09:44:22 +02:00
logical, external :: detEq
2017-03-06 18:55:53 +01:00
integer, external :: omp_get_thread_num
double precision :: contrib(N_states)
2016-05-13 19:28:50 +02:00
2017-10-18 15:10:15 +02:00
provide dij hh_shortcut psi_det_size
contrib = 0d0
2016-05-13 19:28:50 +02:00
delta_ij_mrcc = 0d0
2016-11-18 19:17:34 +01:00
delta_ij_s2_mrcc = 0d0
2017-10-18 15:10:15 +02:00
2018-06-27 15:20:33 +02:00
!$OMP PARALLEL default(none) &
!$OMP shared(contrib,psi_det_generators, N_det_generators, hh_exists, pp_exists, N_int, hh_shortcut) &
!$OMP shared(N_det_non_ref, N_det_ref, delta_ij_mrcc, delta_ij_s2_mrcc) &
2018-06-27 15:20:33 +02:00
!$OMP private(h, n, mask, omask, buf, ok,gen)
allocate(buf(N_int, 2, N_det_non_ref))
!$OMP DO schedule(dynamic)
2016-05-20 09:44:22 +02:00
do gen= 1, N_det_generators
2016-08-03 00:18:53 +02:00
if(mod(gen, 1000) == 0) print *, "mrcc ", gen, "/", N_det_generators
2016-05-13 19:28:50 +02:00
do h=1, hh_shortcut(0)
call apply_hole_local(psi_det_generators(1,1,gen), hh_exists(1, h), mask, ok, N_int)
2016-05-13 19:28:50 +02:00
if(.not. ok) cycle
2016-05-20 09:44:22 +02:00
omask = 0_bit_kind
2016-06-14 09:22:32 +02:00
if(hh_exists(1, h) /= 0) omask = mask
2016-05-13 19:28:50 +02:00
n = 1
2016-05-20 09:44:22 +02:00
do p=hh_shortcut(h), hh_shortcut(h+1)-1
call apply_particle_local(mask, pp_exists(1, p), buf(1,1,n), ok, N_int)
2016-05-13 19:28:50 +02:00
if(ok) n = n + 1
2017-04-13 00:43:45 +02:00
if(n > N_det_non_ref) stop "Buffer too small in MRCC..."
2016-05-20 09:44:22 +02:00
end do
2016-05-13 19:28:50 +02:00
n = n - 1
2016-07-06 15:43:21 +02:00
2016-11-18 19:17:34 +01:00
if(n /= 0) then
2018-02-16 17:26:34 +01:00
call mrcc_part_dress(delta_ij_mrcc, delta_ij_s2_mrcc, gen,n,buf,N_int,omask,contrib)
2016-11-18 19:17:34 +01:00
endif
2016-07-06 15:43:21 +02:00
2016-05-13 19:28:50 +02:00
end do
end do
2018-06-27 15:20:33 +02:00
!$OMP END DO
deallocate(buf)
!$OMP END PARALLEL
2016-05-13 19:28:50 +02:00
END_PROVIDER
2016-05-20 11:27:39 +02:00
! subroutine blit(b1, b2)
! double precision :: b1(N_states,N_det_non_ref), b2(N_states,N_det_non_ref)
2016-05-20 11:27:39 +02:00
! b1 = b1 + b2
! end subroutine
2018-02-16 17:26:34 +01:00
subroutine mrcc_part_dress(delta_ij_, delta_ij_s2_, i_generator,n_selected,det_buffer,Nint,key_mask,contrib)
2016-05-13 19:28:50 +02:00
use bitmasks
implicit none
integer, intent(in) :: i_generator,n_selected, Nint
double precision, intent(inout) :: delta_ij_(N_states,N_det_non_ref)
double precision, intent(inout) :: delta_ij_s2_(N_states,N_det_non_ref)
2016-05-13 19:28:50 +02:00
integer(bit_kind), intent(in) :: det_buffer(Nint,2,n_selected)
integer :: i,j,k,l,m
2016-05-26 13:52:48 +02:00
integer,allocatable :: idx_alpha(:), degree_alpha(:)
2016-05-13 19:28:50 +02:00
logical :: good, fullMatch
2016-05-26 13:52:48 +02:00
integer(bit_kind),allocatable :: tq(:,:,:)
2017-03-17 12:17:05 +01:00
integer :: N_tq, c_ref ,degree1, degree2, degree
2016-05-13 19:28:50 +02:00
2017-03-17 12:17:05 +01:00
double precision :: hIk, hla, hIl, sla, dIk(N_states), dka(N_states), dIa(N_states), hka
2016-11-18 19:17:34 +01:00
double precision, allocatable :: dIa_hla(:,:), dIa_sla(:,:)
2016-05-13 19:28:50 +02:00
double precision :: haj, phase, phase2
integer :: exc(0:2,2,2)
integer :: h1,h2,p1,p2,s1,s2
integer(bit_kind) :: tmp_det(Nint,2)
integer :: i_state, k_sd, l_sd, i_I, i_alpha
integer(bit_kind),allocatable :: miniList(:,:,:)
2016-05-26 13:52:48 +02:00
integer(bit_kind),intent(in) :: key_mask(Nint, 2)
2016-05-13 19:28:50 +02:00
integer,allocatable :: idx_miniList(:)
integer :: N_miniList, ni, leng
2016-11-18 19:17:34 +01:00
double precision, allocatable :: hij_cache(:), sij_cache(:)
2016-05-13 19:28:50 +02:00
integer(bit_kind), allocatable :: microlist(:,:,:), microlist_zero(:,:,:)
integer, allocatable :: idx_microlist(:), N_microlist(:), ptr_microlist(:), idx_microlist_zero(:)
integer :: mobiles(2), smallerlist
2016-05-20 09:44:22 +02:00
logical, external :: detEq, is_generable
2016-07-06 15:43:21 +02:00
!double precision, external :: get_dij, get_dij_index
2017-06-02 01:15:29 +02:00
double precision :: Delta_E_inv(N_states)
double precision, intent(inout) :: contrib(N_states)
2018-02-26 11:33:32 +01:00
double precision :: sdress, hdress
2018-02-20 15:51:53 +01:00
2018-07-25 01:13:04 +02:00
PROVIDE n_act_orb elec_num
2017-10-12 10:05:27 +02:00
if (perturbative_triples) then
PROVIDE one_anhil fock_virt_total fock_core_inactive_total one_creat
endif
2016-05-20 09:44:22 +02:00
2017-03-17 12:17:05 +01:00
2016-05-13 19:28:50 +02:00
leng = max(N_det_generators, N_det_non_ref)
2016-11-18 19:17:34 +01:00
allocate(miniList(Nint, 2, leng), tq(Nint,2,n_selected), idx_minilist(leng), hij_cache(N_det_non_ref), sij_cache(N_det_non_ref))
2016-05-26 13:52:48 +02:00
allocate(idx_alpha(0:psi_det_size), degree_alpha(psi_det_size))
2016-05-13 19:28:50 +02:00
call create_minilist_find_previous(key_mask, psi_det_generators, miniList, i_generator-1, N_miniList, fullMatch, Nint)
allocate(ptr_microlist(0:mo_tot_num*2+1), &
N_microlist(0:mo_tot_num*2) )
allocate( microlist(Nint,2,N_minilist*4), &
idx_microlist(N_minilist*4))
if(key_mask(1,1) /= 0) then
call create_microlist(miniList, N_minilist, key_mask, microlist, idx_microlist, N_microlist, ptr_microlist, Nint)
2016-05-20 09:44:22 +02:00
call filter_tq_micro(i_generator,n_selected,det_buffer,Nint,tq,N_tq,microlist,ptr_microlist,N_microlist,key_mask)
2016-05-13 19:28:50 +02:00
else
2016-05-20 09:44:22 +02:00
call filter_tq(i_generator,n_selected,det_buffer,Nint,tq,N_tq,miniList,N_minilist)
2016-05-13 19:28:50 +02:00
end if
2016-07-06 15:43:21 +02:00
2016-05-13 19:28:50 +02:00
deallocate(microlist, idx_microlist)
2016-11-18 19:17:34 +01:00
allocate (dIa_hla(N_states,N_det_non_ref), dIa_sla(N_states,N_det_non_ref))
2016-05-13 19:28:50 +02:00
! |I>
! |alpha>
if(N_tq > 0) then
call create_minilist(key_mask, psi_non_ref, miniList, idx_minilist, N_det_non_ref, N_minilist, Nint)
if(N_minilist == 0) return
2017-06-07 22:19:27 +02:00
if(sum(abs(key_mask(1:N_int,1))) /= 0) then
2016-05-13 19:28:50 +02:00
allocate(microlist_zero(Nint,2,N_minilist), idx_microlist_zero(N_minilist))
allocate( microlist(Nint,2,N_minilist*4), &
idx_microlist(N_minilist*4))
call create_microlist(miniList, N_minilist, key_mask, microlist, idx_microlist, N_microlist, ptr_microlist, Nint)
do i=0,mo_tot_num*2
do k=ptr_microlist(i),ptr_microlist(i+1)-1
idx_microlist(k) = idx_minilist(idx_microlist(k))
end do
end do
do l=1,N_microlist(0)
do k=1,Nint
microlist_zero(k,1,l) = microlist(k,1,l)
microlist_zero(k,2,l) = microlist(k,2,l)
enddo
idx_microlist_zero(l) = idx_microlist(l)
enddo
end if
end if
do i_alpha=1,N_tq
if(key_mask(1,1) /= 0) then
call getMobiles(tq(1,1,i_alpha), key_mask, mobiles, Nint)
2016-05-13 19:28:50 +02:00
if(N_microlist(mobiles(1)) < N_microlist(mobiles(2))) then
smallerlist = mobiles(1)
else
smallerlist = mobiles(2)
end if
2016-05-13 19:28:50 +02:00
do l=0,N_microlist(smallerlist)-1
microlist_zero(:,:,ptr_microlist(1) + l) = microlist(:,:,ptr_microlist(smallerlist) + l)
idx_microlist_zero(ptr_microlist(1) + l) = idx_microlist(ptr_microlist(smallerlist) + l)
end do
call get_excitation_degree_vector(microlist_zero,tq(1,1,i_alpha),degree_alpha,Nint,N_microlist(smallerlist)+N_microlist(0),idx_alpha)
do j=1,idx_alpha(0)
idx_alpha(j) = idx_microlist_zero(idx_alpha(j))
end do
else
call get_excitation_degree_vector(miniList,tq(1,1,i_alpha),degree_alpha,Nint,N_minilist,idx_alpha)
do j=1,idx_alpha(0)
idx_alpha(j) = idx_miniList(idx_alpha(j))
end do
end if
do l_sd=1,idx_alpha(0)
k_sd = idx_alpha(l_sd)
call i_h_j(tq(1,1,i_alpha),psi_non_ref(1,1,idx_alpha(l_sd)),Nint,hij_cache(k_sd))
2016-11-18 19:17:34 +01:00
call get_s2(tq(1,1,i_alpha),psi_non_ref(1,1,idx_alpha(l_sd)),Nint,sij_cache(k_sd))
!if(sij_cache(k_sd) /= 0D0) PRINT *, "SIJ ", sij_cache(k_sd)
2016-05-13 19:28:50 +02:00
enddo
2016-05-13 19:28:50 +02:00
! |I>
do i_I=1,N_det_ref
! Find triples and quadruple grand parents
2017-03-17 12:17:05 +01:00
call get_excitation_degree(tq(1,1,i_alpha),psi_ref(1,1,i_I),degree1,Nint)
if (degree1 > 4) then
2016-05-13 19:28:50 +02:00
cycle
endif
do i_state=1,N_states
dIa(i_state) = 0.d0
enddo
! <I| <> |alpha>
do k_sd=1,idx_alpha(0)
2016-05-13 19:28:50 +02:00
call get_excitation_degree(psi_ref(1,1,i_I),psi_non_ref(1,1,idx_alpha(k_sd)),degree,Nint)
if (degree > 2) then
cycle
endif
2016-05-13 19:28:50 +02:00
! <I| /k\ |alpha>
2016-06-14 15:26:50 +02:00
2016-05-13 19:28:50 +02:00
! |l> = Exc(k -> alpha) |I>
2017-03-17 12:17:05 +01:00
call get_excitation(psi_non_ref(1,1,idx_alpha(k_sd)),tq(1,1,i_alpha),exc,degree2,phase,Nint)
call decode_exc(exc,degree2,h1,p1,h2,p2,s1,s2)
2016-05-13 19:28:50 +02:00
do k=1,N_int
tmp_det(k,1) = psi_ref(k,1,i_I)
tmp_det(k,2) = psi_ref(k,2,i_I)
enddo
logical :: ok
2016-05-13 19:28:50 +02:00
call apply_excitation(psi_ref(1,1,i_I), exc, tmp_det, ok, Nint)
2017-03-03 10:41:55 +01:00
do i_state=1,N_states
dIK(i_state) = dij(i_I, idx_alpha(k_sd), i_state)
enddo
2016-05-13 19:28:50 +02:00
! <I| \l/ |alpha>
do i_state=1,N_states
dka(i_state) = 0.d0
enddo
2017-03-17 12:17:05 +01:00
if (ok) then
do l_sd=k_sd+1,idx_alpha(0)
call get_excitation_degree(tmp_det,psi_non_ref(1,1,idx_alpha(l_sd)),degree,Nint)
if (degree == 0) then
2016-05-13 19:28:50 +02:00
call get_excitation(psi_ref(1,1,i_I),psi_non_ref(1,1,idx_alpha(l_sd)),exc,degree,phase2,Nint)
do i_state=1,N_states
2016-07-06 15:43:21 +02:00
dka(i_state) = dij(i_I, idx_alpha(l_sd), i_state) * phase * phase2
2016-05-13 19:28:50 +02:00
enddo
2017-03-17 12:17:05 +01:00
exit
2016-05-13 19:28:50 +02:00
endif
2017-03-17 12:17:05 +01:00
enddo
2017-03-23 14:48:21 +01:00
else if (perturbative_triples) then
! Linked
hka = hij_cache(idx_alpha(k_sd))
if (dabs(hka) > 1.d-12) then
call get_delta_e_dyall_general_mp(psi_ref(1,1,i_I),tq(1,1,i_alpha),Delta_E_inv)
2018-06-27 15:20:33 +02:00
do i_state=1,N_states
ASSERT (Delta_E_inv(i_state) < 0.d0)
dka(i_state) = hka / Delta_E_inv(i_state)
enddo
endif
2017-06-02 01:15:29 +02:00
endif
2018-06-27 15:20:33 +02:00
2017-06-02 01:15:29 +02:00
if (perturbative_triples.and. (degree2 == 1) ) then
call i_h_j(psi_ref(1,1,i_I),tmp_det,Nint,hka)
hka = hij_cache(idx_alpha(k_sd)) - hka
if (dabs(hka) > 1.d-12) then
call get_delta_e_dyall_general_mp(psi_ref(1,1,i_I),tq(1,1,i_alpha),Delta_E_inv)
do i_state=1,N_states
ASSERT (Delta_E_inv(i_state) < 0.d0)
dka(i_state) = hka / Delta_E_inv(i_state)
enddo
endif
2018-06-27 15:20:33 +02:00
2017-03-17 12:17:05 +01:00
endif
2018-06-27 15:20:33 +02:00
2016-05-13 19:28:50 +02:00
do i_state=1,N_states
dIa(i_state) = dIa(i_state) + dIk(i_state) * dka(i_state)
enddo
enddo
2018-06-27 15:20:33 +02:00
2016-05-13 19:28:50 +02:00
do l_sd=1,idx_alpha(0)
k_sd = idx_alpha(l_sd)
hla = hij_cache(k_sd)
2016-11-18 19:17:34 +01:00
sla = sij_cache(k_sd)
2016-05-13 19:28:50 +02:00
do i_state=1,N_states
2018-02-16 17:26:34 +01:00
dIa_hla(i_state,k_sd) = dIa(i_state) * hla
dIa_sla(i_state,k_sd) = dIa(i_state) * sla
2016-05-13 19:28:50 +02:00
enddo
enddo
do i_state=1,N_states
2018-06-27 15:20:33 +02:00
do l_sd=1,idx_alpha(0)
k_sd = idx_alpha(l_sd)
2018-02-16 17:26:34 +01:00
hdress = dIa_hla(i_state,k_sd) * psi_ref_coef(i_I,i_state)
sdress = dIa_sla(i_state,k_sd) * psi_ref_coef(i_I,i_state)
!$OMP ATOMIC
2018-06-27 15:20:33 +02:00
contrib(i_state) += hdress * psi_non_ref_coef(k_sd, i_state)
!$OMP ATOMIC
delta_ij_(i_state,k_sd) += hdress
!$OMP ATOMIC
delta_ij_s2_(i_state,k_sd) += sdress
enddo
2016-05-13 19:28:50 +02:00
enddo
enddo
enddo
2018-02-20 15:51:53 +01:00
2016-11-18 19:17:34 +01:00
deallocate (dIa_hla,dIa_sla,hij_cache,sij_cache)
2016-05-20 09:44:22 +02:00
deallocate(miniList, idx_miniList)
2016-05-13 19:28:50 +02:00
end
2018-02-16 17:26:34 +01:00
BEGIN_PROVIDER [ double precision, mrcc_previous_E, (N_states) ]
2017-10-27 11:14:22 +02:00
implicit none
BEGIN_DOC
!energy difference between last two mrcc iterations
END_DOC
mrcc_previous_E(:) = ref_bitmask_energy
2018-02-16 17:26:34 +01:00
END_PROVIDER
2017-10-27 11:14:22 +02:00
BEGIN_PROVIDER [ double precision, delta_ij_mrcc_zmq, (N_states,N_det_non_ref) ]
&BEGIN_PROVIDER [ double precision, delta_ij_s2_mrcc_zmq, (N_states,N_det_non_ref) ]
2017-10-27 11:14:22 +02:00
use bitmasks
implicit none
integer :: i,j,k
double precision, allocatable :: mrcc(:)
2018-01-09 10:41:45 +01:00
double precision :: E_CI_before!, relative_error
2018-07-25 11:48:12 +02:00
double precision :: target_error
2017-10-27 11:14:22 +02:00
allocate(mrcc(N_states))
delta_ij_mrcc_zmq = 0d0
delta_ij_s2_mrcc_zmq = 0d0
!call random_seed()
E_CI_before = mrcc_E0_denominator(1) + nuclear_repulsion
threshold_selectors = 1.d0
threshold_generators = 1d0
2018-07-25 11:48:12 +02:00
target_error = thresh_dressed_ci * 5.d-2
target_error = 0.d0
2018-01-09 10:41:45 +01:00
call ZMQ_mrcc(E_CI_before, mrcc, delta_ij_mrcc_zmq, delta_ij_s2_mrcc_zmq, abs(target_error))
2017-12-11 15:28:24 +01:00
2017-10-27 11:14:22 +02:00
mrcc_previous_E(:) = mrcc_E0_denominator(:)
END_PROVIDER
2016-03-11 19:35:57 +01:00
BEGIN_PROVIDER [ double precision, delta_ij, (N_states,N_det_non_ref) ]
&BEGIN_PROVIDER [ double precision, delta_ij_s2, (N_states,N_det_non_ref) ]
2016-03-11 19:35:57 +01:00
use bitmasks
implicit none
2016-11-14 23:57:23 +01:00
integer :: i, j, i_state
2018-06-27 15:20:33 +02:00
!mrmode : 1=mrcepa0, 2=mrsc2 add, 3=mrcc 5=mrcc_stoch
2018-02-16 17:26:34 +01:00
if(mrmode == 5) then
2017-10-27 11:14:22 +02:00
do j = 1, N_det_non_ref
do i_state = 1, N_states
delta_ij(i_state,j) = delta_ij_mrcc_zmq(i_state,j)
delta_ij_s2(i_state,j) = delta_ij_s2_mrcc_zmq(i_state,j)
2017-10-27 11:14:22 +02:00
enddo
end do
2017-10-12 10:05:27 +02:00
else if(mrmode == 3) then
2016-05-20 09:44:22 +02:00
do j = 1, N_det_non_ref
2016-11-14 23:57:23 +01:00
do i_state = 1, N_states
delta_ij(i_state,j) = delta_ij_mrcc(i_state,j)
delta_ij_s2(i_state,j) = delta_ij_s2_mrcc(i_state,j)
2016-11-14 23:57:23 +01:00
enddo
end do
2016-11-14 23:57:23 +01:00
else if(mrmode == 2) then
do j = 1, N_det_non_ref
do i_state = 1, N_states
delta_ij(i_state,j) = delta_ij_old(i_state,j)
delta_ij_s2(i_state,j) = delta_ij_s2_old(i_state,j)
2016-11-14 23:57:23 +01:00
enddo
end do
2016-11-14 23:57:23 +01:00
else if(mrmode == 1) then
do j = 1, N_det_non_ref
do i_state = 1, N_states
delta_ij(i_state,j) = delta_mrcepa0_ij(j,i_state)
delta_ij_s2(i_state,j) = delta_mrcepa0_ij_s2(j,i_state)
2016-11-14 23:57:23 +01:00
enddo
end do
2016-11-14 23:57:23 +01:00
else
stop "invalid mrmode"
end if
2016-03-11 19:35:57 +01:00
END_PROVIDER
2016-03-04 16:52:46 +01:00
BEGIN_PROVIDER [ integer, cepa0_shortcut, (0:N_det_non_ref+1) ]
&BEGIN_PROVIDER [ integer, det_cepa0_idx, (N_det_non_ref) ]
&BEGIN_PROVIDER [ integer(bit_kind), det_cepa0_active, (N_int,2,N_det_non_ref) ]
&BEGIN_PROVIDER [ integer(bit_kind), det_ref_active, (N_int,2,N_det_ref) ]
&BEGIN_PROVIDER [ integer(bit_kind), active_sorb, (N_int,2) ]
2016-04-15 15:16:46 +02:00
&BEGIN_PROVIDER [ integer(bit_kind), det_cepa0, (N_int,2,N_det_non_ref) ]
2016-04-29 16:23:20 +02:00
&BEGIN_PROVIDER [ integer, nlink, (N_det_ref) ]
&BEGIN_PROVIDER [ integer, linked, (N_det_non_ref,N_det_ref) ]
&BEGIN_PROVIDER [ integer, blokMwen, (N_det_non_ref,N_det_ref) ]
&BEGIN_PROVIDER [ double precision, searchance, (N_det_ref) ]
&BEGIN_PROVIDER [ integer, child_num, (N_det_non_ref,N_det_ref) ]
2016-03-04 16:52:46 +01:00
use bitmasks
implicit none
2016-05-26 13:52:48 +02:00
integer(bit_kind),allocatable :: det_noactive(:,:,:)
integer, allocatable :: shortcut(:), idx(:)
integer(bit_kind) :: nonactive_sorb(N_int,2), det(N_int, 2)
integer i, II, j, k, n, ni, blok, degree
2016-03-04 16:52:46 +01:00
logical, external :: detEq
2016-05-26 13:52:48 +02:00
allocate(det_noactive(N_int, 2, N_det_non_ref))
allocate(idx(N_det_non_ref), shortcut(0:N_det_non_ref+1))
print *, "pre start"
active_sorb(:,:) = 0_8
nonactive_sorb(:,:) = not(0_8)
2016-03-11 19:35:57 +01:00
if(N_det_ref > 1) then
do i=1, N_det_ref
do k=1, N_int
active_sorb(k,1) = ior(psi_ref(k,1,i), active_sorb(k,1))
active_sorb(k,2) = ior(psi_ref(k,2,i), active_sorb(k,2))
nonactive_sorb(k,1) = iand(psi_ref(k,1,i), nonactive_sorb(k,1))
nonactive_sorb(k,2) = iand(psi_ref(k,2,i), nonactive_sorb(k,2))
end do
end do
do k=1, N_int
active_sorb(k,1) = iand(active_sorb(k,1), not(nonactive_sorb(k,1)))
active_sorb(k,2) = iand(active_sorb(k,2), not(nonactive_sorb(k,2)))
2016-03-11 19:35:57 +01:00
end do
end if
2016-05-03 11:34:03 +02:00
2016-03-04 16:52:46 +01:00
do i=1, N_det_non_ref
do k=1, N_int
det_noactive(k,1,i) = iand(psi_non_ref(k,1,i), not(active_sorb(k,1)))
det_noactive(k,2,i) = iand(psi_non_ref(k,2,i), not(active_sorb(k,2)))
end do
2016-03-04 16:52:46 +01:00
end do
call sort_dets_ab(det_noactive, det_cepa0_idx, cepa0_shortcut, N_det_non_ref, N_int)
2016-03-11 19:35:57 +01:00
2016-04-26 17:27:21 +02:00
do i=1,N_det_non_ref
det_cepa0(:,:,i) = psi_non_ref(:,:,det_cepa0_idx(i))
2016-03-04 16:52:46 +01:00
end do
2016-04-26 17:27:21 +02:00
2016-03-04 16:52:46 +01:00
cepa0_shortcut(0) = 1
cepa0_shortcut(1) = 1
do i=2,N_det_non_ref
if(.not. detEq(det_noactive(1,1,i), det_noactive(1,1,i-1), N_int)) then
cepa0_shortcut(0) += 1
cepa0_shortcut(cepa0_shortcut(0)) = i
end if
end do
2016-03-11 19:35:57 +01:00
cepa0_shortcut(cepa0_shortcut(0)+1) = N_det_non_ref+1
2016-04-15 15:16:46 +02:00
2016-04-26 17:27:21 +02:00
if(.true.) then
do i=1,cepa0_shortcut(0)
n = cepa0_shortcut(i+1) - cepa0_shortcut(i)
call sort_dets_ab(det_cepa0(1,1,cepa0_shortcut(i)), idx, shortcut, n, N_int)
do k=1,n
idx(k) = det_cepa0_idx(cepa0_shortcut(i)-1+idx(k))
end do
det_cepa0_idx(cepa0_shortcut(i):cepa0_shortcut(i)+n-1) = idx(:n)
end do
end if
do i=1,N_det_ref
do k=1, N_int
det_ref_active(k,1,i) = iand(psi_ref(k,1,i), active_sorb(k,1))
det_ref_active(k,2,i) = iand(psi_ref(k,2,i), active_sorb(k,2))
end do
2016-04-15 15:16:46 +02:00
end do
2016-04-26 17:27:21 +02:00
do i=1,N_det_non_ref
do k=1, N_int
det_cepa0_active(k,1,i) = iand(psi_non_ref(k,1,det_cepa0_idx(i)), active_sorb(k,1))
det_cepa0_active(k,2,i) = iand(psi_non_ref(k,2,det_cepa0_idx(i)), active_sorb(k,2))
end do
end do
do i=1,N_det_non_ref
if(.not. detEq(psi_non_ref(1,1,det_cepa0_idx(i)), det_cepa0(1,1,i),N_int)) stop "STOOOP"
end do
2016-04-29 16:23:20 +02:00
searchance = 0d0
child_num = 0
do J = 1, N_det_ref
nlink(J) = 0
do blok=1,cepa0_shortcut(0)
do k=cepa0_shortcut(blok), cepa0_shortcut(blok+1)-1
call get_excitation_degree(psi_ref(1,1,J),det_cepa0(1,1,k),degree,N_int)
if(degree <= 2) then
nlink(J) += 1
linked(nlink(J),J) = k
child_num(k, J) = nlink(J)
blokMwen(nlink(J),J) = blok
searchance(J) += 1d0 + log(dfloat(cepa0_shortcut(blok+1) - cepa0_shortcut(blok)))
end if
end do
end do
end do
2016-04-15 15:16:46 +02:00
print *, "pre done"
2016-03-04 16:52:46 +01:00
END_PROVIDER
2016-06-14 14:37:46 +02:00
2016-04-15 09:16:31 +02:00
BEGIN_PROVIDER [ double precision, delta_cas, (N_det_ref, N_det_ref, N_states) ]
2016-11-18 19:17:34 +01:00
&BEGIN_PROVIDER [ double precision, delta_cas_s2, (N_det_ref, N_det_ref, N_states) ]
2016-04-15 09:16:31 +02:00
use bitmasks
implicit none
integer :: i,j,k
2016-11-18 19:17:34 +01:00
double precision :: Sjk,Hjk, Hki, Hij
2016-07-06 15:43:21 +02:00
!double precision, external :: get_dij
2016-06-14 14:37:46 +02:00
integer i_state, degree
2016-06-20 10:52:54 +02:00
provide lambda_mrcc dIj
2016-04-15 09:16:31 +02:00
do i_state = 1, N_states
2016-11-18 19:17:34 +01:00
!$OMP PARALLEL DO default(none) schedule(dynamic) private(j,k,Sjk,Hjk,Hki,degree) shared(lambda_mrcc,i_state, N_det_non_ref,psi_ref, psi_non_ref,N_int,delta_cas,delta_cas_s2,N_det_ref,dij)
2016-04-15 09:16:31 +02:00
do i=1,N_det_ref
2016-06-14 14:37:46 +02:00
do j=1,i
call get_excitation_degree(psi_ref(1,1,i), psi_ref(1,1,j), degree, N_int)
delta_cas(i,j,i_state) = 0d0
2016-11-18 19:17:34 +01:00
delta_cas_s2(i,j,i_state) = 0d0
2016-06-14 14:37:46 +02:00
do k=1,N_det_non_ref
call i_h_j(psi_ref(1,1,j), psi_non_ref(1,1,k),N_int,Hjk)
2016-11-18 19:17:34 +01:00
call get_s2(psi_ref(1,1,j), psi_non_ref(1,1,k),N_int,Sjk)
2016-06-14 14:37:46 +02:00
2016-07-06 15:43:21 +02:00
delta_cas(i,j,i_state) += Hjk * dij(i, k, i_state) ! * Hki * lambda_mrcc(i_state, k)
2016-11-18 19:17:34 +01:00
delta_cas_s2(i,j,i_state) += Sjk * dij(i, k, i_state) ! * Ski * lambda_mrcc(i_state, k)
2016-06-14 14:37:46 +02:00
end do
2016-04-15 09:16:31 +02:00
delta_cas(j,i,i_state) = delta_cas(i,j,i_state)
2016-11-18 19:17:34 +01:00
delta_cas_s2(j,i,i_state) = delta_cas_s2(i,j,i_state)
2016-06-14 14:37:46 +02:00
end do
2016-04-15 09:16:31 +02:00
end do
2016-06-14 14:37:46 +02:00
!$OMP END PARALLEL DO
2016-04-15 09:16:31 +02:00
end do
END_PROVIDER
2016-03-04 16:52:46 +01:00
2016-05-03 11:34:03 +02:00
2016-04-15 15:16:46 +02:00
logical function isInCassd(a,Nint)
use bitmasks
implicit none
integer, intent(in) :: Nint
integer(bit_kind), intent(in) :: a(Nint,2)
integer(bit_kind) :: inac, virt
integer :: ni, i, deg
isInCassd = .false.
2016-05-03 11:34:03 +02:00
2016-04-15 15:16:46 +02:00
deg = 0
2016-05-03 11:34:03 +02:00
do i=1,2
2016-04-15 15:16:46 +02:00
do ni=1,Nint
virt = iand(not(HF_bitmask(ni,i)), not(active_sorb(ni,i)))
deg += popcnt(iand(virt, a(ni,i)))
if(deg > 2) return
end do
end do
deg = 0
do i=1,2
do ni=1,Nint
inac = iand(HF_bitmask(ni,i), not(active_sorb(ni,i)))
deg += popcnt(xor(iand(inac,a(ni,i)), inac))
if(deg > 2) return
end do
end do
isInCassd = .true.
end function
2016-05-03 11:34:03 +02:00
subroutine getHP(a,h,p,Nint)
use bitmasks
implicit none
integer, intent(in) :: Nint
integer(bit_kind), intent(in) :: a(Nint,2)
integer, intent(out) :: h, p
integer(bit_kind) :: inac, virt
integer :: ni, i, deg
!isInCassd = .false.
h = 0
p = 0
deg = 0
lp : do i=1,2
do ni=1,Nint
virt = iand(not(HF_bitmask(ni,i)), not(active_sorb(ni,i)))
deg += popcnt(iand(virt, a(ni,i)))
if(deg > 2) exit lp
end do
end do lp
p = deg
deg = 0
lh : do i=1,2
do ni=1,Nint
inac = iand(HF_bitmask(ni,i), not(active_sorb(ni,i)))
deg += popcnt(xor(iand(inac,a(ni,i)), inac))
if(deg > 2) exit lh
end do
end do lh
h = deg
!isInCassd = .true.
2017-05-16 16:58:24 +02:00
end subroutine
2016-05-03 11:34:03 +02:00
2016-03-11 19:35:57 +01:00
BEGIN_PROVIDER [ double precision, delta_mrcepa0_ij, (N_det_non_ref,N_states) ]
&BEGIN_PROVIDER [ double precision, delta_mrcepa0_ij_s2, (N_det_non_ref,N_states) ]
use bitmasks
implicit none
integer :: i_state, i, i_I, J, k, degree, degree2, m, l, deg, ni
2016-04-15 09:16:31 +02:00
integer :: p1,p2,h1,h2,s1,s2, p1_,p2_,h1_,h2_,s1_,s2_, sortRefIdx(N_det_ref)
logical :: ok
double precision :: phase_iI, phase_Ik, phase_Jl, phase_IJ, phase_al, diI, hIi, hJi, delta_JI, dkI(1), HkI, ci_inv(1), dia_hla(1)
double precision :: contrib, contrib_s2, HIIi, HJk, wall
integer, dimension(0:2,2,2) :: exc_iI, exc_Ik, exc_IJ
2016-05-26 13:52:48 +02:00
integer(bit_kind) :: det_tmp(N_int, 2), made_hole(N_int,2), made_particle(N_int,2), myActive(N_int,2)
integer(bit_kind),allocatable :: sortRef(:,:,:)
integer, allocatable :: idx_sorted_bit(:)
2016-04-15 09:16:31 +02:00
integer, external :: get_index_in_psi_det_sorted_bit, searchDet
logical, external :: is_in_wavefunction, detEq
2016-07-06 15:43:21 +02:00
!double precision, external :: get_dij
integer :: II, blok
2016-04-26 17:27:21 +02:00
integer*8, save :: notf = 0
2016-04-15 15:16:46 +02:00
call wall_time(wall)
2016-05-26 13:52:48 +02:00
allocate(idx_sorted_bit(N_det), sortRef(N_int,2,N_det_ref))
2016-04-26 17:27:21 +02:00
sortRef(:,:,:) = det_ref_active(:,:,:)
2016-04-15 09:16:31 +02:00
call sort_det(sortRef, sortRefIdx, N_det_ref, N_int)
idx_sorted_bit(:) = -1
do i=1,N_det_non_ref
idx_sorted_bit(get_index_in_psi_det_sorted_bit(psi_non_ref(1,1,i), N_int)) = i
enddo
2016-06-20 10:52:54 +02:00
! To provide everything
2016-07-06 15:43:21 +02:00
contrib = dij(1, 1, 1)
delta_mrcepa0_ij(:,:) = 0d0
delta_mrcepa0_ij_s2(:,:) = 0d0
2016-11-18 19:17:34 +01:00
do i_state = 1, N_states
!$OMP PARALLEL DO default(none) schedule(dynamic) shared(delta_mrcepa0_ij, delta_mrcepa0_ij_s2) &
!$OMP private(m,i,II,J,k,degree,myActive,made_hole,made_particle,hjk,contrib,contrib_s2) &
!$OMP shared(active_sorb, psi_non_ref, psi_non_ref_coef, psi_ref, psi_ref_coef, cepa0_shortcut, det_cepa0_active) &
2016-11-18 19:17:34 +01:00
!$OMP shared(N_det_ref, N_det_non_ref,N_int,det_cepa0_idx,lambda_mrcc,det_ref_active, delta_cas, delta_cas_s2) &
2018-02-16 17:26:34 +01:00
!$OMP shared(notf,i_state, sortRef, sortRefIdx, dij)
do blok=1,cepa0_shortcut(0)
do i=cepa0_shortcut(blok), cepa0_shortcut(blok+1)-1
do II=1,N_det_ref
call get_excitation_degree(psi_ref(1,1,II),psi_non_ref(1,1,det_cepa0_idx(i)),degree,N_int)
if (degree > 2 ) cycle
do ni=1,N_int
made_hole(ni,1) = iand(det_ref_active(ni,1,II), xor(det_cepa0_active(ni,1,i), det_ref_active(ni,1,II)))
made_hole(ni,2) = iand(det_ref_active(ni,2,II), xor(det_cepa0_active(ni,2,i), det_ref_active(ni,2,II)))
2016-04-15 09:16:31 +02:00
made_particle(ni,1) = iand(det_cepa0_active(ni,1,i), xor(det_cepa0_active(ni,1,i), det_ref_active(ni,1,II)))
made_particle(ni,2) = iand(det_cepa0_active(ni,2,i), xor(det_cepa0_active(ni,2,i), det_ref_active(ni,2,II)))
end do
2016-04-26 17:27:21 +02:00
kloop: do k=cepa0_shortcut(blok), cepa0_shortcut(blok+1)-1 !i
2016-06-14 14:37:46 +02:00
!if(lambda_mrcc(i_state, det_cepa0_idx(k)) == 0d0) cycle
do ni=1,N_int
if(iand(made_hole(ni,1), det_cepa0_active(ni,1,k)) /= 0) cycle kloop
if(iand(made_particle(ni,1), det_cepa0_active(ni,1,k)) /= made_particle(ni,1)) cycle kloop
if(iand(made_hole(ni,2), det_cepa0_active(ni,2,k)) /= 0) cycle kloop
if(iand(made_particle(ni,2), det_cepa0_active(ni,2,k)) /= made_particle(ni,2)) cycle kloop
end do
do ni=1,N_int
myActive(ni,1) = xor(det_cepa0_active(ni,1,k), made_hole(ni,1))
myActive(ni,1) = xor(myActive(ni,1), made_particle(ni,1))
myActive(ni,2) = xor(det_cepa0_active(ni,2,k), made_hole(ni,2))
myActive(ni,2) = xor(myActive(ni,2), made_particle(ni,2))
end do
2016-04-15 09:16:31 +02:00
j = searchDet(sortRef, myActive, N_det_ref, N_int)
2016-04-26 17:27:21 +02:00
if(j == -1) then
cycle
end if
2016-04-15 09:16:31 +02:00
j = sortRefIdx(j)
2016-04-26 17:27:21 +02:00
!$OMP ATOMIC
notf = notf+1
2016-06-14 14:37:46 +02:00
2017-10-18 15:10:15 +02:00
contrib = delta_cas(II, J, i_state)* dij(J, det_cepa0_idx(k), i_state)
contrib_s2 = delta_cas_s2(II, J, i_state) * dij(J, det_cepa0_idx(k), i_state)
2016-04-15 09:16:31 +02:00
2016-10-18 23:07:03 +02:00
!$OMP ATOMIC
2018-02-16 17:26:34 +01:00
delta_mrcepa0_ij(det_cepa0_idx(i), i_state) += contrib * psi_ref_coef(J,i_state)
delta_mrcepa0_ij_s2(det_cepa0_idx(i), i_state) += contrib_s2 * psi_ref_coef(J,i_state)
2016-04-15 09:16:31 +02:00
end do kloop
end do
end do
end do
!$OMP END PARALLEL DO
end do
deallocate(idx_sorted_bit)
2016-04-15 15:16:46 +02:00
call wall_time(wall)
2016-04-26 17:27:21 +02:00
print *, "cepa0", wall, notf
2016-11-18 19:17:34 +01:00
END_PROVIDER
BEGIN_PROVIDER [ double precision, delta_sub_ij, (N_det_non_ref,N_states) ]
2016-03-04 16:52:46 +01:00
use bitmasks
implicit none
integer :: i_state, i, i_I, J, k, degree, degree2, l, deg, ni
2016-03-11 19:35:57 +01:00
integer :: p1,p2,h1,h2,s1,s2, p1_,p2_,h1_,h2_,s1_,s2_
logical :: ok
double precision :: phase_Ji, phase_Ik, phase_Ii
double precision :: contrib, delta_IJk, HJk, HIk, HIl
2016-03-11 19:35:57 +01:00
integer, dimension(0:2,2,2) :: exc_Ik, exc_Ji, exc_Ii
integer(bit_kind) :: det_tmp(N_int, 2), det_tmp2(N_int, 2)
integer, allocatable :: idx_sorted_bit(:)
integer, external :: get_index_in_psi_det_sorted_bit
integer :: II, blok
provide delta_cas lambda_mrcc
2016-03-11 19:35:57 +01:00
allocate(idx_sorted_bit(N_det))
idx_sorted_bit(:) = -1
do i=1,N_det_non_ref
idx_sorted_bit(get_index_in_psi_det_sorted_bit(psi_non_ref(1,1,i), N_int)) = i
enddo
do i_state = 1, N_states
delta_sub_ij(:,:) = 0d0
provide mo_bielec_integrals_in_map
!$OMP PARALLEL DO default(none) schedule(dynamic,10) shared(delta_sub_ij) &
!$OMP private(i, J, k, degree, degree2, l, deg, ni) &
!$OMP private(p1,p2,h1,h2,s1,s2, p1_,p2_,h1_,h2_,s1_,s2_) &
!$OMP private(ok, phase_Ji, phase_Ik, phase_Ii, contrib, delta_IJk, HJk, HIk, HIl, exc_Ik, exc_Ji, exc_Ii) &
!$OMP private(det_tmp, det_tmp2, II, blok) &
!$OMP shared(idx_sorted_bit, N_det_non_ref, N_det_ref, N_int, psi_non_ref, psi_non_ref_coef, psi_ref, psi_ref_coef) &
2018-02-16 17:26:34 +01:00
!$OMP shared(i_state,lambda_mrcc, hf_bitmask, active_sorb)
do i=1,N_det_non_ref
if(mod(i,1000) == 0) print *, i, "/", N_det_non_ref
do J=1,N_det_ref
call get_excitation(psi_ref(1,1,J),psi_non_ref(1,1,i),exc_Ji,degree,phase_Ji,N_int)
if(degree == -1) cycle
2016-03-11 19:35:57 +01:00
do II=1,N_det_ref
call apply_excitation(psi_ref(1,1,II),exc_Ji,det_tmp,ok,N_int)
2016-04-15 09:16:31 +02:00
if(.not. ok) cycle
l = get_index_in_psi_det_sorted_bit(det_tmp, N_int)
if(l == 0) cycle
l = idx_sorted_bit(l)
2016-03-11 19:35:57 +01:00
call i_h_j(psi_ref(1,1,II), det_tmp, N_int, HIl)
2016-03-11 19:35:57 +01:00
do k=1,N_det_non_ref
if(lambda_mrcc(i_state, k) == 0d0) cycle
call get_excitation(psi_ref(1,1,II),psi_non_ref(1,1,k),exc_Ik,degree2,phase_Ik,N_int)
det_tmp(:,:) = 0_bit_kind
det_tmp2(:,:) = 0_bit_kind
ok = .true.
do ni=1,N_int
det_tmp(ni,1) = iand(xor(HF_bitmask(ni,1), psi_non_ref(ni,1,k)), not(active_sorb(ni,1)))
det_tmp(ni,2) = iand(xor(HF_bitmask(ni,1), psi_non_ref(ni,1,i)), not(active_sorb(ni,1)))
ok = ok .and. (popcnt(det_tmp(ni,1)) + popcnt(det_tmp(ni,2)) == popcnt(xor(det_tmp(ni,1), det_tmp(ni,2))))
det_tmp(ni,1) = iand(xor(HF_bitmask(ni,2), psi_non_ref(ni,2,k)), not(active_sorb(ni,2)))
det_tmp(ni,2) = iand(xor(HF_bitmask(ni,2), psi_non_ref(ni,2,i)), not(active_sorb(ni,2)))
ok = ok .and. (popcnt(det_tmp(ni,1)) + popcnt(det_tmp(ni,2)) == popcnt(xor(det_tmp(ni,1), det_tmp(ni,2))))
end do
if(ok) cycle
call i_h_j(psi_ref(1,1,J), psi_non_ref(1,1,k), N_int, HJk)
call i_h_j(psi_ref(1,1,II), psi_non_ref(1,1,k), N_int, HIk)
if(HJk == 0) cycle
!assert HIk == 0
delta_IJk = HJk * HIk * lambda_mrcc(i_state, k)
call apply_excitation(psi_non_ref(1,1,i),exc_Ik,det_tmp,ok,N_int)
if(ok) cycle
2016-10-18 23:07:03 +02:00
contrib = delta_IJk * HIl * lambda_mrcc(i_state,l)
!$OMP ATOMIC
2018-02-16 17:26:34 +01:00
delta_sub_ij(i, i_state) += contrib* psi_ref_coef(II,i_state)
end do
2016-03-11 19:35:57 +01:00
end do
end do
end do
!$OMP END PARALLEL DO
2016-03-11 19:35:57 +01:00
end do
deallocate(idx_sorted_bit)
END_PROVIDER
subroutine set_det_bit(det, p, s)
implicit none
integer(bit_kind),intent(inout) :: det(N_int, 2)
integer, intent(in) :: p, s
integer :: ni, pos
ni = (p-1)/bit_kind_size + 1
pos = mod(p-1, bit_kind_size)
det(ni,s) = ibset(det(ni,s), pos)
2016-03-04 16:52:46 +01:00
end subroutine
2016-03-11 19:35:57 +01:00
2016-11-18 19:17:34 +01:00
BEGIN_PROVIDER [ double precision, h_cache, (N_det_ref,N_det_non_ref) ]
&BEGIN_PROVIDER [ double precision, s2_cache, (N_det_ref,N_det_non_ref) ]
2016-05-20 09:44:22 +02:00
implicit none
2016-04-26 17:27:21 +02:00
integer :: i,j
do i=1,N_det_ref
do j=1,N_det_non_ref
2016-11-18 19:17:34 +01:00
call i_h_j(psi_ref(1,1,i), psi_non_ref(1,1,j), N_int, h_cache(i,j))
call get_s2(psi_ref(1,1,i), psi_non_ref(1,1,j), N_int, s2_cache(i,j))
2016-04-26 17:27:21 +02:00
end do
end do
END_PROVIDER
2016-05-20 09:44:22 +02:00
subroutine filter_tq(i_generator,n_selected,det_buffer,Nint,tq,N_tq,miniList,N_miniList)
use bitmasks
implicit none
integer, intent(in) :: i_generator,n_selected, Nint
integer(bit_kind), intent(in) :: det_buffer(Nint,2,n_selected)
integer :: i,j,k,m
logical :: is_in_wavefunction
2016-05-27 14:48:27 +02:00
integer,allocatable :: degree(:)
2016-05-26 13:52:48 +02:00
integer,allocatable :: idx(:)
2016-05-20 09:44:22 +02:00
logical :: good
2016-05-26 13:52:48 +02:00
integer(bit_kind), intent(inout) :: tq(Nint,2,n_selected) !! intent(out)
2016-05-20 09:44:22 +02:00
integer, intent(out) :: N_tq
integer :: nt,ni
logical, external :: is_connected_to, is_generable
integer(bit_kind),intent(in) :: miniList(Nint,2,N_det_generators)
integer,intent(in) :: N_miniList
2016-05-27 14:48:27 +02:00
allocate(degree(psi_det_size))
2016-05-26 13:52:48 +02:00
allocate(idx(0:psi_det_size))
2016-05-20 09:44:22 +02:00
N_tq = 0
i_loop : do i=1,N_selected
do k=1, N_minilist
if(is_generable(miniList(1,1,k), det_buffer(1,1,i), Nint)) cycle i_loop
end do
! Select determinants that are triple or quadruple excitations
! from the ref
good = .True.
call get_excitation_degree_vector(psi_ref,det_buffer(1,1,i),degree,Nint,N_det_ref,idx)
!good=(idx(0) == 0) tant que degree > 2 pas retourné par get_excitation_degree_vector
do k=1,idx(0)
if (degree(k) < 3) then
good = .False.
exit
endif
enddo
if (good) then
if (.not. is_in_wavefunction(det_buffer(1,1,i),Nint)) then
N_tq += 1
2018-07-25 01:13:04 +02:00
do k=1,Nint
2016-05-20 09:44:22 +02:00
tq(k,1,N_tq) = det_buffer(k,1,i)
tq(k,2,N_tq) = det_buffer(k,2,i)
enddo
endif
endif
enddo i_loop
end
subroutine filter_tq_micro(i_generator,n_selected,det_buffer,Nint,tq,N_tq,microlist,ptr_microlist,N_microlist,key_mask)
use bitmasks
implicit none
integer, intent(in) :: i_generator,n_selected, Nint
integer(bit_kind), intent(in) :: det_buffer(Nint,2,n_selected)
integer :: i,j,k,m
logical :: is_in_wavefunction
2016-05-27 14:48:27 +02:00
integer,allocatable :: degree(:)
2016-05-26 13:52:48 +02:00
integer,allocatable :: idx(:)
2016-05-20 09:44:22 +02:00
logical :: good
2016-05-26 13:52:48 +02:00
integer(bit_kind), intent(inout) :: tq(Nint,2,n_selected) !! intent(out)
2016-05-20 09:44:22 +02:00
integer, intent(out) :: N_tq
integer :: nt,ni
logical, external :: is_connected_to, is_generable
integer(bit_kind),intent(in) :: microlist(Nint,2,*)
integer,intent(in) :: ptr_microlist(0:*)
integer,intent(in) :: N_microlist(0:*)
integer(bit_kind),intent(in) :: key_mask(Nint, 2)
integer :: mobiles(2), smallerlist
2016-05-27 14:48:27 +02:00
allocate(degree(psi_det_size))
2016-05-26 13:52:48 +02:00
allocate(idx(0:psi_det_size))
2016-05-20 09:44:22 +02:00
N_tq = 0
i_loop : do i=1,N_selected
call getMobiles(det_buffer(1,1,i), key_mask, mobiles, Nint)
if(N_microlist(mobiles(1)) < N_microlist(mobiles(2))) then
smallerlist = mobiles(1)
else
smallerlist = mobiles(2)
end if
if(N_microlist(smallerlist) > 0) then
do k=ptr_microlist(smallerlist), ptr_microlist(smallerlist)+N_microlist(smallerlist)-1
if(is_generable(microlist(1,1,k), det_buffer(1,1,i), Nint)) cycle i_loop
end do
end if
if(N_microlist(0) > 0) then
do k=1, N_microlist(0)
if(is_generable(microlist(1,1,k), det_buffer(1,1,i), Nint)) cycle i_loop
end do
end if
! Select determinants that are triple or quadruple excitations
! from the ref
good = .True.
call get_excitation_degree_vector(psi_ref,det_buffer(1,1,i),degree,Nint,N_det_ref,idx)
!good=(idx(0) == 0) tant que degree > 2 pas retourné par get_excitation_degree_vector
do k=1,idx(0)
if (degree(k) < 3) then
good = .False.
exit
endif
enddo
if (good) then
if (.not. is_in_wavefunction(det_buffer(1,1,i),Nint)) then
N_tq += 1
do k=1,N_int
tq(k,1,N_tq) = det_buffer(k,1,i)
tq(k,2,N_tq) = det_buffer(k,2,i)
enddo
endif
endif
enddo i_loop
end
2018-07-24 17:59:14 +02:00
subroutine get_cc_coef(tq,c_alpha)
use bitmasks
implicit none
integer(bit_kind), intent(in) :: tq(N_int,2)
double precision, intent(out) :: c_alpha(N_states)
integer :: k
integer :: degree1, degree2, degree
double precision :: hla, hka, dIk(N_states), dka(N_states), dIa(N_states)
double precision :: phase, phase2
integer :: exc(0:2,2,2)
integer :: h1,h2,p1,p2,s1,s2
integer(bit_kind) :: tmp_det(N_int,2)
integer :: i_state, k_sd, l_sd, i_I
logical :: ok
2018-07-25 01:13:04 +02:00
PROVIDE n_act_orb elec_num
2018-07-24 17:59:14 +02:00
if (perturbative_triples) then
PROVIDE one_anhil fock_virt_total fock_core_inactive_total one_creat
endif
c_alpha(1:N_states) = 0.d0
do i_I=1,N_det_ref
! Find triples and quadruple grand parents
call get_excitation_degree(tq,psi_ref(1,1,i_I),degree1,N_int)
if (degree1 < 3) then
return
endif
enddo
! |I>
do i_I=1,N_det_ref
! Find triples and quadruple grand parents
call get_excitation_degree(tq,psi_ref(1,1,i_I),degree1,N_int)
if (degree1 > 4) then
cycle
endif
if ( (degree1 < 3).or.(degree1 > 4) ) stop 'bug'
do i_state=1,N_states
dIa(i_state) = 0.d0
enddo
! <I| <> |alpha>
do k_sd=1,N_det_non_ref
2018-07-25 01:34:20 +02:00
if (maxval(abs(psi_non_ref_coef(k_sd,1:N_states))) < 1.d-10) then
cycle
endif
2018-07-24 17:59:14 +02:00
call get_excitation_degree(tq,psi_non_ref(1,1,k_sd),degree,N_int)
if (degree > 2) then
cycle
endif
call get_excitation_degree(psi_ref(1,1,i_I),psi_non_ref(1,1,k_sd),degree,N_int)
if (degree > 2) then
cycle
endif
2018-07-25 01:34:20 +02:00
do i_state=1,N_states
dIK(i_state) = dij(i_I, k_sd, i_state)
enddo
2018-07-25 11:48:12 +02:00
if (maxval(abs(dIk)) < 1.d-10) then
2018-07-25 01:34:20 +02:00
cycle
endif
2018-07-24 17:59:14 +02:00
! <I| /k\ |alpha>
! |l> = Exc(k -> alpha) |I>
call get_excitation(psi_non_ref(1,1,k_sd),tq,exc,degree2,phase,N_int)
call decode_exc(exc,degree2,h1,p1,h2,p2,s1,s2)
tmp_det(1:N_int,1:2) = psi_ref(1:N_int,1:2,i_I)
call apply_excitation(psi_ref(1,1,i_I), exc, tmp_det, ok, N_int)
! <I| \l/ |alpha>
2018-07-25 01:34:20 +02:00
dka(1:N_states) = 0.d0
2018-07-24 17:59:14 +02:00
if (ok) then
do l_sd=k_sd+1,N_det_non_ref
2018-07-25 01:34:20 +02:00
if (maxval(abs(psi_non_ref_coef(l_sd,1:N_states))) < 1.d-10) then
cycle
endif
2018-07-24 17:59:14 +02:00
call get_excitation_degree(tmp_det,psi_non_ref(1,1,l_sd),degree,N_int)
if (degree == 0) then
call get_excitation(psi_ref(1,1,i_I),psi_non_ref(1,1,l_sd),exc,degree,phase2,N_int)
do i_state=1,N_states
dka(i_state) = dij(i_I, l_sd, i_state) * phase * phase2
enddo
exit
endif
enddo
else if (perturbative_triples) then
! Linked
call i_h_j(tq,psi_non_ref(1,1,k_sd),N_int,hka)
if (dabs(hka) > 1.d-12) then
double precision :: Delta_E(N_states)
call get_delta_e_dyall_general_mp(psi_ref(1,1,i_I),tq,Delta_E)
do i_state=1,N_states
ASSERT (Delta_E(i_state) < 0.d0)
dka(i_state) = hka / Delta_E(i_state)
enddo
endif
endif
if (perturbative_triples.and. (degree2 == 1) ) then
2018-09-28 09:09:27 +02:00
if (ok) then
call i_h_j(psi_ref(1,1,i_I),tmp_det,N_int,hka)
else
hka = 0.d0
endif
2018-07-24 17:59:14 +02:00
call i_h_j(tq,psi_non_ref(1,1,k_sd),N_int,hla)
hka = hla - hka
if (dabs(hka) > 1.d-12) then
call get_delta_e_dyall_general_mp(psi_ref(1,1,i_I),tq,Delta_E)
do i_state=1,N_states
ASSERT (Delta_E(i_state) < 0.d0)
dka(i_state) = hka / Delta_E(i_state)
enddo
endif
endif
do i_state=1,N_states
dIa(i_state) = dIa(i_state) + dIk(i_state) * dka(i_state)
enddo
enddo
do i_state=1,N_states
c_alpha(i_state) += dIa(i_state) * psi_ref_coef(i_I,i_state)
enddo
enddo
end