9
1
mirror of https://github.com/QuantumPackage/qp2.git synced 2024-12-22 19:43:32 +01:00

Starting Cholesky transition

This commit is contained in:
Anthony Scemama 2024-06-07 18:03:51 +02:00
parent ca98a6b529
commit 7e1ed69eef
2 changed files with 57 additions and 837 deletions

View File

@ -98,7 +98,10 @@ double precision function get_two_e_integral(i,j,k,l,map)
integer*8 :: ii_8
type(map_type), intent(inout) :: map
real(integral_kind) :: tmp
PROVIDE mo_two_e_integrals_in_map mo_integrals_cache
integer :: kk
PROVIDE mo_two_e_integrals_in_map mo_integrals_cache do_mo_cholesky
if (use_banned_excitation) then
if (banned_excitation(i,k)) then
get_two_e_integral = 0.d0
@ -109,22 +112,43 @@ double precision function get_two_e_integral(i,j,k,l,map)
return
endif
endif
ii = l-mo_integrals_cache_min
ii = ior(ii, k-mo_integrals_cache_min)
ii = ior(ii, j-mo_integrals_cache_min)
ii = ior(ii, i-mo_integrals_cache_min)
if (iand(ii, -128) /= 0) then
!DIR$ FORCEINLINE
call two_e_integrals_index(i,j,k,l,idx)
!DIR$ FORCEINLINE
call map_get(map,idx,tmp)
get_two_e_integral = dble(tmp)
! if (iand(ii, -128) /= 0) then
if (.True.) then
! Integral is not in the cache
if (do_mo_cholesky) then
get_two_e_integral = 0.d0
do kk=1,cholesky_mo_num
get_two_e_integral = get_two_e_integral + cholesky_mo_transp(kk,i,k) * cholesky_mo_transp(kk,j,l)
enddo
else
! Integrals is in the map
!DIR$ FORCEINLINE
call two_e_integrals_index(i,j,k,l,idx)
!DIR$ FORCEINLINE
call map_get(map,idx,tmp)
get_two_e_integral = dble(tmp)
endif
else
! Integrals is in the cache
ii_8 = int(l,8)-mo_integrals_cache_min_8
ii_8 = ior( shiftl(ii_8,7), int(k,8)-mo_integrals_cache_min_8)
ii_8 = ior( shiftl(ii_8,7), int(j,8)-mo_integrals_cache_min_8)
ii_8 = ior( shiftl(ii_8,7), int(i,8)-mo_integrals_cache_min_8)
get_two_e_integral = mo_integrals_cache(ii_8)
endif
end

View File

@ -1,3 +1,26 @@
! 1,2-index integrals are always taken from:
! - mo_two_e_integrals_jj_exchange
! - mo_two_e_integrals_jj_anti
! - mo_two_e_integrals_jj
!
! 3-index integrals are always taken from:
! - big_array_exchange_integrals
! - big_array_coulomb_integrals
!
! If (do_mo_cholesky):
! - Integrals with four 4 active orbitals are stored in the cache map,
! all other integrals are used from cholesky vectors
! - 1,2,3-index arrays are built from cholesky vectors
! Else:
! - All integrals are stored in the map or cache map
! - 1,2,3-index arrays are built from the map
!
! TODO:
! - build cache map from cholesky vectors
! - get_mo_integrals using cholesky
! - get_mo_integralss using cholesky
! - get_mo_integralss in PT2
subroutine mo_two_e_integrals_index(i,j,k,l,i1)
use map_module
implicit none
@ -453,6 +476,9 @@ subroutine add_integrals_to_map(mask_ijkl)
end
subroutine add_integrals_to_map_cholesky
use bitmasks
implicit none
@ -516,837 +542,7 @@ subroutine add_integrals_to_map_cholesky
end
subroutine add_integrals_to_map_three_indices(mask_ijk)
use bitmasks
implicit none
BEGIN_DOC
! Adds integrals to the MO map according to some bitmask
END_DOC
integer(bit_kind), intent(in) :: mask_ijk(N_int,3)
integer :: i,j,k,l
integer :: i0,j0,k0,l0
double precision :: c, cpu_1, cpu_2, wall_1, wall_2, wall_0
integer, allocatable :: list_ijkl(:,:)
integer :: n_i, n_j, n_k
integer :: m
integer, allocatable :: two_e_tmp_0_idx(:)
real(integral_kind), allocatable :: two_e_tmp_0(:,:)
double precision, allocatable :: two_e_tmp_1(:)
double precision, allocatable :: two_e_tmp_2(:,:)
double precision, allocatable :: two_e_tmp_3(:,:,:)
!DIR$ ATTRIBUTES ALIGN : 64 :: two_e_tmp_1, two_e_tmp_2, two_e_tmp_3
integer :: n_integrals
integer :: size_buffer
integer(key_kind),allocatable :: buffer_i(:)
real(integral_kind),allocatable :: buffer_value(:)
double precision :: map_mb
integer :: i1,j1,k1,l1, ii1, kmax, thread_num
integer :: i2,i3,i4
double precision,parameter :: thr_coef = 1.d-10
PROVIDE ao_two_e_integrals_in_map mo_coef
!Get list of MOs for i,j,k and l
!-------------------------------
allocate(list_ijkl(mo_num,4))
call bitstring_to_list( mask_ijk(1,1), list_ijkl(1,1), n_i, N_int )
call bitstring_to_list( mask_ijk(1,2), list_ijkl(1,2), n_j, N_int )
call bitstring_to_list( mask_ijk(1,3), list_ijkl(1,3), n_k, N_int )
j = 0
do i = 1, N_int
j += popcnt(mask_ijk(i,1))
enddo
if(j==0)then
return
endif
j = 0
do i = 1, N_int
j += popcnt(mask_ijk(i,2))
enddo
if(j==0)then
return
endif
j = 0
do i = 1, N_int
j += popcnt(mask_ijk(i,3))
enddo
if(j==0)then
return
endif
if (ao_num > 1289) then
print *, irp_here, ': Integer overflow in ao_num**3'
endif
size_buffer = min(ao_num*ao_num*ao_num,16000000)
print*, 'Providing the molecular integrals '
print*, 'Buffers : ', 8.*(mo_num*(n_j)*(n_k+1) + mo_num+&
ao_num+ao_num*ao_num+ size_buffer*3)/(1024*1024), 'MB / core'
call wall_time(wall_1)
call cpu_time(cpu_1)
!$OMP PARALLEL PRIVATE(m,l1,k1,j1,i1,i2,i3,i4,i,j,k,l,c, ii1,kmax, &
!$OMP two_e_tmp_0_idx, two_e_tmp_0, two_e_tmp_1,two_e_tmp_2,two_e_tmp_3,&
!$OMP buffer_i,buffer_value,n_integrals,wall_2,i0,j0,k0,l0, &
!$OMP wall_0,thread_num) &
!$OMP DEFAULT(NONE) &
!$OMP SHARED(size_buffer,ao_num,mo_num,n_i,n_j,n_k, &
!$OMP mo_coef_transp, &
!$OMP mo_coef_transp_is_built, list_ijkl, &
!$OMP mo_coef_is_built, wall_1, &
!$OMP mo_coef,mo_integrals_threshold,mo_integrals_map)
n_integrals = 0
wall_0 = wall_1
allocate(two_e_tmp_3(mo_num, n_j, n_k), &
two_e_tmp_1(mo_num), &
two_e_tmp_0(ao_num,ao_num), &
two_e_tmp_0_idx(ao_num), &
two_e_tmp_2(mo_num, n_j), &
buffer_i(size_buffer), &
buffer_value(size_buffer) )
thread_num = 0
!$ thread_num = omp_get_thread_num()
!$OMP DO SCHEDULE(guided)
do l1 = 1,ao_num
two_e_tmp_3 = 0.d0
do k1 = 1,ao_num
two_e_tmp_2 = 0.d0
do j1 = 1,ao_num
call get_ao_two_e_integrals(j1,k1,l1,ao_num,two_e_tmp_0(1,j1))
enddo
do j1 = 1,ao_num
kmax = 0
do i1 = 1,ao_num
c = two_e_tmp_0(i1,j1)
if (c == 0.d0) then
cycle
endif
kmax += 1
two_e_tmp_0(kmax,j1) = c
two_e_tmp_0_idx(kmax) = i1
enddo
if (kmax==0) then
cycle
endif
two_e_tmp_1 = 0.d0
ii1=1
do ii1 = 1,kmax-4,4
i1 = two_e_tmp_0_idx(ii1)
i2 = two_e_tmp_0_idx(ii1+1)
i3 = two_e_tmp_0_idx(ii1+2)
i4 = two_e_tmp_0_idx(ii1+3)
do i = list_ijkl(1,1), list_ijkl(n_i,1)
two_e_tmp_1(i) = two_e_tmp_1(i) + &
mo_coef_transp(i,i1) * two_e_tmp_0(ii1,j1) + &
mo_coef_transp(i,i2) * two_e_tmp_0(ii1+1,j1) + &
mo_coef_transp(i,i3) * two_e_tmp_0(ii1+2,j1) + &
mo_coef_transp(i,i4) * two_e_tmp_0(ii1+3,j1)
enddo ! i
enddo ! ii1
i2 = ii1
do ii1 = i2,kmax
i1 = two_e_tmp_0_idx(ii1)
do i = list_ijkl(1,1), list_ijkl(n_i,1)
two_e_tmp_1(i) = two_e_tmp_1(i) + mo_coef_transp(i,i1) * two_e_tmp_0(ii1,j1)
enddo ! i
enddo ! ii1
c = 0.d0
do i = list_ijkl(1,1), list_ijkl(n_i,1)
c = max(c,abs(two_e_tmp_1(i)))
if (c>mo_integrals_threshold) exit
enddo
if ( c < mo_integrals_threshold ) then
cycle
endif
do j0 = 1, n_j
j = list_ijkl(j0,2)
c = mo_coef_transp(j,j1)
if (abs(c) < thr_coef) then
cycle
endif
do i = list_ijkl(1,1), list_ijkl(n_i,1)
two_e_tmp_2(i,j0) = two_e_tmp_2(i,j0) + c * two_e_tmp_1(i)
enddo ! i
enddo ! j
enddo !j1
if ( maxval(abs(two_e_tmp_2)) < mo_integrals_threshold ) then
cycle
endif
do k0 = 1, n_k
k = list_ijkl(k0,3)
c = mo_coef_transp(k,k1)
if (abs(c) < thr_coef) then
cycle
endif
do j0 = 1, n_j
j = list_ijkl(j0,2)
do i = list_ijkl(1,1), k
two_e_tmp_3(i,j0,k0) = two_e_tmp_3(i,j0,k0) + c* two_e_tmp_2(i,j0)
enddo!i
enddo !j
enddo !k
enddo !k1
do l0 = 1,n_j
l = list_ijkl(l0,2)
c = mo_coef_transp(l,l1)
if (abs(c) < thr_coef) then
cycle
endif
do k0 = 1, n_k
k = list_ijkl(k0,3)
i1 = shiftr((k*k-k),1)
two_e_tmp_1 = 0.d0
j0 = l0
j = list_ijkl(j0,2)
do i0 = 1, n_i
i = list_ijkl(i0,1)
if (i>k) then
exit
endif
two_e_tmp_1(i) = c*two_e_tmp_3(i,j0,k0)
enddo
do i0 = 1, n_i
i = list_ijkl(i0,1)
if (i>k) then !min(k,j1-i1)
exit
endif
if (abs(two_e_tmp_1(i)) < mo_integrals_threshold) then
cycle
endif
n_integrals += 1
buffer_value(n_integrals) = two_e_tmp_1(i)
if(i==k .and. j==l .and. i.ne.j)then
buffer_value(n_integrals) = buffer_value(n_integrals) *0.5d0
endif
!DIR$ FORCEINLINE
call mo_two_e_integrals_index(i,j,k,l,buffer_i(n_integrals))
if (n_integrals == size_buffer) then
call insert_into_mo_integrals_map(n_integrals,buffer_i,buffer_value,&
real(mo_integrals_threshold,integral_kind))
n_integrals = 0
endif
enddo
enddo
enddo
do l0 = 1,n_j
l = list_ijkl(l0,2)
c = mo_coef_transp(l,l1)
if (abs(c) < thr_coef) then
cycle
endif
do k0 = 1, n_k
k = list_ijkl(k0,3)
i1 = shiftr((k*k-k),1)
two_e_tmp_1 = 0.d0
j0 = k0
j = list_ijkl(k0,2)
i0 = l0
i = list_ijkl(i0,2)
if (k==l) then
cycle
endif
two_e_tmp_1(i) = c*two_e_tmp_3(i,j0,k0)
n_integrals += 1
buffer_value(n_integrals) = two_e_tmp_1(i)
!DIR$ FORCEINLINE
call mo_two_e_integrals_index(i,j,k,l,buffer_i(n_integrals))
if (n_integrals == size_buffer) then
call insert_into_mo_integrals_map(n_integrals,buffer_i,buffer_value,&
real(mo_integrals_threshold,integral_kind))
n_integrals = 0
endif
enddo
enddo
call wall_time(wall_2)
if (thread_num == 0) then
if (wall_2 - wall_0 > 1.d0) then
wall_0 = wall_2
print*, 100.*float(l1)/float(ao_num), '% in ', &
wall_2-wall_1, 's', map_mb(mo_integrals_map) ,'MB'
endif
endif
enddo
!$OMP END DO NOWAIT
deallocate (two_e_tmp_1,two_e_tmp_2,two_e_tmp_3)
call insert_into_mo_integrals_map(n_integrals,buffer_i,buffer_value,&
real(mo_integrals_threshold,integral_kind))
deallocate(buffer_i, buffer_value)
!$OMP END PARALLEL
call map_merge(mo_integrals_map)
call wall_time(wall_2)
call cpu_time(cpu_2)
integer*8 :: get_mo_map_size, mo_map_size
mo_map_size = get_mo_map_size()
deallocate(list_ijkl)
print*,'Molecular integrals provided:'
print*,' Size of MO map ', map_mb(mo_integrals_map) ,'MB'
print*,' Number of MO integrals: ', mo_map_size
print*,' cpu time :',cpu_2 - cpu_1, 's'
print*,' wall time :',wall_2 - wall_1, 's ( x ', (cpu_2-cpu_1)/(wall_2-wall_1), ')'
end
subroutine add_integrals_to_map_no_exit_34(mask_ijkl)
use bitmasks
implicit none
BEGIN_DOC
! Adds integrals to tha MO map according to some bitmask
END_DOC
integer(bit_kind), intent(in) :: mask_ijkl(N_int,4)
integer :: i,j,k,l
integer :: i0,j0,k0,l0
double precision :: c, cpu_1, cpu_2, wall_1, wall_2, wall_0
integer, allocatable :: list_ijkl(:,:)
integer :: n_i, n_j, n_k, n_l
integer, allocatable :: two_e_tmp_0_idx(:)
real(integral_kind), allocatable :: two_e_tmp_0(:,:)
double precision, allocatable :: two_e_tmp_1(:)
double precision, allocatable :: two_e_tmp_2(:,:)
double precision, allocatable :: two_e_tmp_3(:,:,:)
!DIR$ ATTRIBUTES ALIGN : 64 :: two_e_tmp_1, two_e_tmp_2, two_e_tmp_3
integer :: n_integrals
integer :: size_buffer
integer(key_kind),allocatable :: buffer_i(:)
real(integral_kind),allocatable :: buffer_value(:)
double precision :: map_mb
integer :: i1,j1,k1,l1, ii1, kmax, thread_num
integer :: i2,i3,i4
double precision,parameter :: thr_coef = 1.d-10
PROVIDE ao_two_e_integrals_in_map mo_coef
!Get list of MOs for i,j,k and l
!-------------------------------
allocate(list_ijkl(mo_num,4))
call bitstring_to_list( mask_ijkl(1,1), list_ijkl(1,1), n_i, N_int )
call bitstring_to_list( mask_ijkl(1,2), list_ijkl(1,2), n_j, N_int )
call bitstring_to_list( mask_ijkl(1,3), list_ijkl(1,3), n_k, N_int )
call bitstring_to_list( mask_ijkl(1,4), list_ijkl(1,4), n_l, N_int )
if (ao_num > 1289) then
print *, irp_here, ': Integer overflow in ao_num**3'
endif
size_buffer = min(ao_num*ao_num*ao_num,16000000)
print*, 'Providing the molecular integrals '
print*, 'Buffers : ', 8.*(mo_num*(n_j)*(n_k+1) + mo_num+&
ao_num+ao_num*ao_num+ size_buffer*3)/(1024*1024), 'MB / core'
call wall_time(wall_1)
call cpu_time(cpu_1)
!$OMP PARALLEL PRIVATE(l1,k1,j1,i1,i2,i3,i4,i,j,k,l,c, ii1,kmax, &
!$OMP two_e_tmp_0_idx, two_e_tmp_0, two_e_tmp_1,two_e_tmp_2,two_e_tmp_3,&
!$OMP buffer_i,buffer_value,n_integrals,wall_2,i0,j0,k0,l0, &
!$OMP wall_0,thread_num) &
!$OMP DEFAULT(NONE) &
!$OMP SHARED(size_buffer,ao_num,mo_num,n_i,n_j,n_k,n_l, &
!$OMP mo_coef_transp, &
!$OMP mo_coef_transp_is_built, list_ijkl, &
!$OMP mo_coef_is_built, wall_1, &
!$OMP mo_coef,mo_integrals_threshold,mo_integrals_map)
n_integrals = 0
wall_0 = wall_1
allocate(two_e_tmp_3(mo_num, n_j, n_k), &
two_e_tmp_1(mo_num), &
two_e_tmp_0(ao_num,ao_num), &
two_e_tmp_0_idx(ao_num), &
two_e_tmp_2(mo_num, n_j), &
buffer_i(size_buffer), &
buffer_value(size_buffer) )
thread_num = 0
!$ thread_num = omp_get_thread_num()
!$OMP DO SCHEDULE(guided)
do l1 = 1,ao_num
!IRP_IF COARRAY
! if (mod(l1-this_image(),num_images()) /= 0 ) then
! cycle
! endif
!IRP_ENDIF
two_e_tmp_3 = 0.d0
do k1 = 1,ao_num
two_e_tmp_2 = 0.d0
do j1 = 1,ao_num
call get_ao_two_e_integrals(j1,k1,l1,ao_num,two_e_tmp_0(1,j1))
enddo
do j1 = 1,ao_num
kmax = 0
do i1 = 1,ao_num
c = two_e_tmp_0(i1,j1)
if (c == 0.d0) then
cycle
endif
kmax += 1
two_e_tmp_0(kmax,j1) = c
two_e_tmp_0_idx(kmax) = i1
enddo
if (kmax==0) then
cycle
endif
two_e_tmp_1 = 0.d0
ii1=1
do ii1 = 1,kmax-4,4
i1 = two_e_tmp_0_idx(ii1)
i2 = two_e_tmp_0_idx(ii1+1)
i3 = two_e_tmp_0_idx(ii1+2)
i4 = two_e_tmp_0_idx(ii1+3)
do i = list_ijkl(1,1), list_ijkl(n_i,1)
two_e_tmp_1(i) = two_e_tmp_1(i) + &
mo_coef_transp(i,i1) * two_e_tmp_0(ii1,j1) + &
mo_coef_transp(i,i2) * two_e_tmp_0(ii1+1,j1) + &
mo_coef_transp(i,i3) * two_e_tmp_0(ii1+2,j1) + &
mo_coef_transp(i,i4) * two_e_tmp_0(ii1+3,j1)
enddo ! i
enddo ! ii1
i2 = ii1
do ii1 = i2,kmax
i1 = two_e_tmp_0_idx(ii1)
do i = list_ijkl(1,1), list_ijkl(n_i,1)
two_e_tmp_1(i) = two_e_tmp_1(i) + mo_coef_transp(i,i1) * two_e_tmp_0(ii1,j1)
enddo ! i
enddo ! ii1
c = 0.d0
do i = list_ijkl(1,1), list_ijkl(n_i,1)
c = max(c,abs(two_e_tmp_1(i)))
if (c>mo_integrals_threshold) exit
enddo
if ( c < mo_integrals_threshold ) then
cycle
endif
do j0 = 1, n_j
j = list_ijkl(j0,2)
c = mo_coef_transp(j,j1)
if (abs(c) < thr_coef) then
cycle
endif
do i = list_ijkl(1,1), list_ijkl(n_i,1)
two_e_tmp_2(i,j0) = two_e_tmp_2(i,j0) + c * two_e_tmp_1(i)
enddo ! i
enddo ! j
enddo !j1
if ( maxval(abs(two_e_tmp_2)) < mo_integrals_threshold ) then
cycle
endif
do k0 = 1, n_k
k = list_ijkl(k0,3)
c = mo_coef_transp(k,k1)
if (abs(c) < thr_coef) then
cycle
endif
do j0 = 1, n_j
j = list_ijkl(j0,2)
do i = list_ijkl(1,1), k
two_e_tmp_3(i,j0,k0) = two_e_tmp_3(i,j0,k0) + c* two_e_tmp_2(i,j0)
enddo!i
enddo !j
enddo !k
enddo !k1
do l0 = 1,n_l
l = list_ijkl(l0,4)
c = mo_coef_transp(l,l1)
if (abs(c) < thr_coef) then
cycle
endif
j1 = shiftr((l*l-l),1)
do j0 = 1, n_j
j = list_ijkl(j0,2)
if (j > l) then
exit
endif
j1 += 1
do k0 = 1, n_k
k = list_ijkl(k0,3)
i1 = shiftr((k*k-k),1)
two_e_tmp_1 = 0.d0
do i0 = 1, n_i
i = list_ijkl(i0,1)
if (i>k) then
exit
endif
two_e_tmp_1(i) = c*two_e_tmp_3(i,j0,k0)
enddo
do i0 = 1, n_i
i = list_ijkl(i0,1)
if(i> k)then
exit
endif
if (abs(two_e_tmp_1(i)) < mo_integrals_threshold) then
cycle
endif
n_integrals += 1
buffer_value(n_integrals) = two_e_tmp_1(i)
!DIR$ FORCEINLINE
call mo_two_e_integrals_index(i,j,k,l,buffer_i(n_integrals))
if (n_integrals == size_buffer) then
call insert_into_mo_integrals_map(n_integrals,buffer_i,buffer_value,&
real(mo_integrals_threshold,integral_kind))
n_integrals = 0
endif
enddo
enddo
enddo
enddo
call wall_time(wall_2)
if (thread_num == 0) then
if (wall_2 - wall_0 > 1.d0) then
wall_0 = wall_2
print*, 100.*float(l1)/float(ao_num), '% in ', &
wall_2-wall_1, 's', map_mb(mo_integrals_map) ,'MB'
endif
endif
enddo
!$OMP END DO NOWAIT
deallocate (two_e_tmp_1,two_e_tmp_2,two_e_tmp_3)
call insert_into_mo_integrals_map(n_integrals,buffer_i,buffer_value,&
real(mo_integrals_threshold,integral_kind))
deallocate(buffer_i, buffer_value)
!$OMP END PARALLEL
!IRP_IF COARRAY
! print*, 'Communicating the map'
! call communicate_mo_integrals()
!IRP_ENDIF
call map_merge(mo_integrals_map)
call wall_time(wall_2)
call cpu_time(cpu_2)
integer*8 :: get_mo_map_size, mo_map_size
mo_map_size = get_mo_map_size()
deallocate(list_ijkl)
print*,'Molecular integrals provided:'
print*,' Size of MO map ', map_mb(mo_integrals_map) ,'MB'
print*,' Number of MO integrals: ', mo_map_size
print*,' cpu time :',cpu_2 - cpu_1, 's'
print*,' wall time :',wall_2 - wall_1, 's ( x ', (cpu_2-cpu_1)/(wall_2-wall_1), ')'
end
BEGIN_PROVIDER [ double precision, mo_two_e_integral_jj_from_ao, (mo_num,mo_num) ]
&BEGIN_PROVIDER [ double precision, mo_two_e_integrals_jj_exchange_from_ao, (mo_num,mo_num) ]
&BEGIN_PROVIDER [ double precision, mo_two_e_integrals_jj_anti_from_ao, (mo_num,mo_num) ]
implicit none
BEGIN_DOC
! mo_two_e_integral_jj_from_ao(i,j) = J_ij
! mo_two_e_integrals_jj_exchange_from_ao(i,j) = J_ij
! mo_two_e_integrals_jj_anti_from_ao(i,j) = J_ij - K_ij
END_DOC
integer :: i,j,p,q,r,s
double precision :: c
real(integral_kind) :: integral
integer :: n, pp
real(integral_kind), allocatable :: int_value(:)
integer, allocatable :: int_idx(:)
double precision, allocatable :: iqrs(:,:), iqsr(:,:), iqis(:), iqri(:)
if (.not.do_direct_integrals) then
PROVIDE ao_two_e_integrals_in_map mo_coef
endif
mo_two_e_integral_jj_from_ao = 0.d0
mo_two_e_integrals_jj_exchange_from_ao = 0.d0
!DIR$ ATTRIBUTES ALIGN : $IRP_ALIGN :: iqrs, iqsr
!$OMP PARALLEL DEFAULT(NONE) &
!$OMP PRIVATE (i,j,p,q,r,s,integral,c,n,pp,int_value,int_idx, &
!$OMP iqrs, iqsr,iqri,iqis) &
!$OMP SHARED(mo_num,mo_coef_transp,ao_num, &
!$OMP ao_integrals_threshold,do_direct_integrals) &
!$OMP REDUCTION(+:mo_two_e_integral_jj_from_ao,mo_two_e_integrals_jj_exchange_from_ao)
allocate( int_value(ao_num), int_idx(ao_num), &
iqrs(mo_num,ao_num), iqis(mo_num), iqri(mo_num), &
iqsr(mo_num,ao_num) )
!$OMP DO SCHEDULE (guided)
do s=1,ao_num
do q=1,ao_num
do j=1,ao_num
do i=1,mo_num
iqrs(i,j) = 0.d0
iqsr(i,j) = 0.d0
enddo
enddo
if (do_direct_integrals) then
double precision :: ao_two_e_integral
do r=1,ao_num
call compute_ao_two_e_integrals(q,r,s,ao_num,int_value)
do p=1,ao_num
integral = int_value(p)
if (abs(integral) > ao_integrals_threshold) then
do i=1,mo_num
iqrs(i,r) += mo_coef_transp(i,p) * integral
enddo
endif
enddo
call compute_ao_two_e_integrals(q,s,r,ao_num,int_value)
do p=1,ao_num
integral = int_value(p)
if (abs(integral) > ao_integrals_threshold) then
do i=1,mo_num
iqsr(i,r) += mo_coef_transp(i,p) * integral
enddo
endif
enddo
enddo
else
do r=1,ao_num
call get_ao_two_e_integrals_non_zero(q,r,s,ao_num,int_value,int_idx,n)
do pp=1,n
p = int_idx(pp)
integral = int_value(pp)
if (abs(integral) > ao_integrals_threshold) then
do i=1,mo_num
iqrs(i,r) += mo_coef_transp(i,p) * integral
enddo
endif
enddo
call get_ao_two_e_integrals_non_zero(q,s,r,ao_num,int_value,int_idx,n)
do pp=1,n
p = int_idx(pp)
integral = int_value(pp)
if (abs(integral) > ao_integrals_threshold) then
do i=1,mo_num
iqsr(i,r) += mo_coef_transp(i,p) * integral
enddo
endif
enddo
enddo
endif
iqis = 0.d0
iqri = 0.d0
do r=1,ao_num
do i=1,mo_num
iqis(i) += mo_coef_transp(i,r) * iqrs(i,r)
iqri(i) += mo_coef_transp(i,r) * iqsr(i,r)
enddo
enddo
do i=1,mo_num
do j=1,mo_num
c = mo_coef_transp(j,q)*mo_coef_transp(j,s)
mo_two_e_integral_jj_from_ao(j,i) += c * iqis(i)
mo_two_e_integrals_jj_exchange_from_ao(j,i) += c * iqri(i)
enddo
enddo
enddo
enddo
!$OMP END DO NOWAIT
deallocate(iqrs,iqsr,int_value,int_idx)
!$OMP END PARALLEL
mo_two_e_integrals_jj_anti_from_ao = mo_two_e_integral_jj_from_ao - mo_two_e_integrals_jj_exchange_from_ao
END_PROVIDER
BEGIN_PROVIDER [ double precision, mo_two_e_integrals_vv_from_ao, (mo_num,mo_num) ]
&BEGIN_PROVIDER [ double precision, mo_two_e_integrals_vv_exchange_from_ao, (mo_num,mo_num) ]
&BEGIN_PROVIDER [ double precision, mo_two_e_integrals_vv_anti_from_ao, (mo_num,mo_num) ]
implicit none
BEGIN_DOC
! mo_two_e_integrals_vv_from_ao(i,j) = J_ij
! mo_two_e_integrals_vv_exchange_from_ao(i,j) = J_ij
! mo_two_e_integrals_vv_anti_from_ao(i,j) = J_ij - K_ij
! but only for the virtual orbitals
END_DOC
integer :: i,j,p,q,r,s
integer :: i0,j0
double precision :: c
real(integral_kind) :: integral
integer :: n, pp
real(integral_kind), allocatable :: int_value(:)
integer, allocatable :: int_idx(:)
double precision, allocatable :: iqrs(:,:), iqsr(:,:), iqis(:), iqri(:)
if (.not.do_direct_integrals) then
PROVIDE ao_two_e_integrals_in_map mo_coef
endif
mo_two_e_integrals_vv_from_ao = 0.d0
mo_two_e_integrals_vv_exchange_from_ao = 0.d0
!DIR$ ATTRIBUTES ALIGN : $IRP_ALIGN :: iqrs, iqsr
!$OMP PARALLEL DEFAULT(NONE) &
!$OMP PRIVATE (i0,j0,i,j,p,q,r,s,integral,c,n,pp,int_value,int_idx, &
!$OMP iqrs, iqsr,iqri,iqis) &
!$OMP SHARED(n_virt_orb,mo_num,list_virt,mo_coef_transp,ao_num, &
!$OMP ao_integrals_threshold,do_direct_integrals) &
!$OMP REDUCTION(+:mo_two_e_integrals_vv_from_ao,mo_two_e_integrals_vv_exchange_from_ao)
allocate( int_value(ao_num), int_idx(ao_num), &
iqrs(mo_num,ao_num), iqis(mo_num), iqri(mo_num),&
iqsr(mo_num,ao_num) )
!$OMP DO SCHEDULE (guided)
do s=1,ao_num
do q=1,ao_num
do j=1,ao_num
do i0=1,n_virt_orb
i = list_virt(i0)
iqrs(i,j) = 0.d0
iqsr(i,j) = 0.d0
enddo
enddo
if (do_direct_integrals) then
double precision :: ao_two_e_integral
do r=1,ao_num
call compute_ao_two_e_integrals(q,r,s,ao_num,int_value)
do p=1,ao_num
integral = int_value(p)
if (abs(integral) > ao_integrals_threshold) then
do i0=1,n_virt_orb
i = list_virt(i0)
iqrs(i,r) += mo_coef_transp(i,p) * integral
enddo
endif
enddo
call compute_ao_two_e_integrals(q,s,r,ao_num,int_value)
do p=1,ao_num
integral = int_value(p)
if (abs(integral) > ao_integrals_threshold) then
do i0=1,n_virt_orb
i =list_virt(i0)
iqsr(i,r) += mo_coef_transp(i,p) * integral
enddo
endif
enddo
enddo
else
do r=1,ao_num
call get_ao_two_e_integrals_non_zero(q,r,s,ao_num,int_value,int_idx,n)
do pp=1,n
p = int_idx(pp)
integral = int_value(pp)
if (abs(integral) > ao_integrals_threshold) then
do i0=1,n_virt_orb
i =list_virt(i0)
iqrs(i,r) += mo_coef_transp(i,p) * integral
enddo
endif
enddo
call get_ao_two_e_integrals_non_zero(q,s,r,ao_num,int_value,int_idx,n)
do pp=1,n
p = int_idx(pp)
integral = int_value(pp)
if (abs(integral) > ao_integrals_threshold) then
do i0=1,n_virt_orb
i = list_virt(i0)
iqsr(i,r) += mo_coef_transp(i,p) * integral
enddo
endif
enddo
enddo
endif
iqis = 0.d0
iqri = 0.d0
do r=1,ao_num
do i0=1,n_virt_orb
i = list_virt(i0)
iqis(i) += mo_coef_transp(i,r) * iqrs(i,r)
iqri(i) += mo_coef_transp(i,r) * iqsr(i,r)
enddo
enddo
do i0=1,n_virt_orb
i= list_virt(i0)
do j0=1,n_virt_orb
j = list_virt(j0)
c = mo_coef_transp(j,q)*mo_coef_transp(j,s)
mo_two_e_integrals_vv_from_ao(j,i) += c * iqis(i)
mo_two_e_integrals_vv_exchange_from_ao(j,i) += c * iqri(i)
enddo
enddo
enddo
enddo
!$OMP END DO NOWAIT
deallocate(iqrs,iqsr,int_value,int_idx)
!$OMP END PARALLEL
mo_two_e_integrals_vv_anti_from_ao = mo_two_e_integrals_vv_from_ao - mo_two_e_integrals_vv_exchange_from_ao
! print*, '**********'
! do i0 =1, n_virt_orb
! i = list_virt(i0)
! print*, mo_two_e_integrals_vv_from_ao(i,i)
! enddo
! print*, '**********'
END_PROVIDER
BEGIN_PROVIDER [ double precision, mo_two_e_integrals_jj, (mo_num,mo_num) ]