12 USE omp_lib,
ONLY: omp_get_num_threads,&
19 gto_basis_set_p_type,&
29 USE dbcsr_api,
ONLY: dbcsr_filter,&
32 dbcsr_get_matrix_type,&
35 dbcsr_type_antisymmetric,&
36 dbcsr_type_no_symmetry
38 dbt_blk_sizes, dbt_clear, dbt_copy, dbt_create, dbt_destroy, dbt_filter, dbt_get_block, &
39 dbt_get_info, dbt_get_num_blocks, dbt_get_nze_total, dbt_get_stored_coordinates, &
40 dbt_iterator_next_block, dbt_iterator_num_blocks, dbt_iterator_start, dbt_iterator_stop, &
41 dbt_iterator_type, dbt_ndims, dbt_put_block, dbt_reserve_blocks, dbt_type
55 hfx_compression_type,&
103 #include "./base/base_uses.f90"
109 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'qs_tensors'
118 TYPE one_dim_int_array
119 INTEGER,
DIMENSION(:),
ALLOCATABLE :: array
123 INTEGER,
PARAMETER,
PRIVATE :: cache_size = 1024
142 sym_ij, molecular, dist_2d, pot_to_rad)
143 TYPE(neighbor_list_set_p_type),
DIMENSION(:), &
145 TYPE(gto_basis_set_p_type),
DIMENSION(:) :: basis_i, basis_j
146 TYPE(libint_potential_type),
INTENT(IN) :: potential_parameter
147 CHARACTER(LEN=*),
INTENT(IN) :: name
148 TYPE(qs_environment_type),
POINTER :: qs_env
149 LOGICAL,
INTENT(IN),
OPTIONAL :: sym_ij, molecular
150 TYPE(distribution_2d_type),
OPTIONAL,
POINTER :: dist_2d
151 INTEGER,
INTENT(IN),
OPTIONAL :: pot_to_rad
153 INTEGER :: ikind, nkind, pot_to_rad_prv
154 LOGICAL,
ALLOCATABLE,
DIMENSION(:) :: i_present, j_present
155 REAL(
dp),
ALLOCATABLE,
DIMENSION(:, :) :: pair_radius
156 REAL(kind=
dp) :: subcells
157 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: i_radius, j_radius
158 TYPE(atomic_kind_type),
DIMENSION(:),
POINTER :: atomic_kind_set
159 TYPE(cell_type),
POINTER :: cell
160 TYPE(distribution_1d_type),
POINTER :: local_particles
161 TYPE(distribution_2d_type),
POINTER :: dist_2d_prv
162 TYPE(local_atoms_type),
ALLOCATABLE,
DIMENSION(:) :: atom2d
163 TYPE(molecule_type),
DIMENSION(:),
POINTER :: molecule_set
164 TYPE(particle_type),
DIMENSION(:),
POINTER :: particle_set
166 NULLIFY (atomic_kind_set, cell, local_particles, molecule_set, &
167 particle_set, dist_2d_prv)
169 IF (
PRESENT(pot_to_rad))
THEN
170 pot_to_rad_prv = pot_to_rad
178 particle_set=particle_set, &
179 atomic_kind_set=atomic_kind_set, &
180 local_particles=local_particles, &
181 distribution_2d=dist_2d_prv, &
182 molecule_set=molecule_set)
186 ALLOCATE (i_present(nkind), j_present(nkind))
187 ALLOCATE (i_radius(nkind), j_radius(nkind))
194 IF (
PRESENT(dist_2d)) dist_2d_prv => dist_2d
201 IF (
ASSOCIATED(basis_i(ikind)%gto_basis_set))
THEN
202 i_present(ikind) = .true.
203 CALL get_gto_basis_set(basis_i(ikind)%gto_basis_set, kind_radius=i_radius(ikind))
205 IF (
ASSOCIATED(basis_j(ikind)%gto_basis_set))
THEN
206 j_present(ikind) = .true.
207 CALL get_gto_basis_set(basis_j(ikind)%gto_basis_set, kind_radius=j_radius(ikind))
215 IF (
ASSOCIATED(basis_i(ikind)%gto_basis_set))
THEN
216 i_present(ikind) = .true.
217 IF (pot_to_rad_prv == 1) i_radius(ikind) = 1000000.0_dp
219 IF (
ASSOCIATED(basis_j(ikind)%gto_basis_set))
THEN
220 j_present(ikind) = .true.
221 IF (pot_to_rad_prv == 2) j_radius(ikind) = 1000000.0_dp
230 IF (
ASSOCIATED(basis_i(ikind)%gto_basis_set))
THEN
231 i_present(ikind) = .true.
232 CALL get_gto_basis_set(basis_i(ikind)%gto_basis_set, kind_radius=i_radius(ikind))
233 IF (pot_to_rad_prv == 1) i_radius(ikind) = i_radius(ikind) +
cutoff_screen_factor*potential_parameter%cutoff_radius
235 IF (
ASSOCIATED(basis_j(ikind)%gto_basis_set))
THEN
236 j_present(ikind) = .true.
237 CALL get_gto_basis_set(basis_j(ikind)%gto_basis_set, kind_radius=j_radius(ikind))
238 IF (pot_to_rad_prv == 2) j_radius(ikind) = j_radius(ikind) +
cutoff_screen_factor*potential_parameter%cutoff_radius
243 cpabort(
"Operator not implemented.")
246 ALLOCATE (pair_radius(nkind, nkind))
250 ALLOCATE (atom2d(nkind))
252 CALL atom2d_build(atom2d, local_particles, dist_2d_prv, atomic_kind_set, &
253 molecule_set, molecule_only=.false., particle_set=particle_set)
255 symmetric=sym_ij, molecular=molecular, nlname=trim(name))
279 dist_3d, potential_parameter, name, qs_env, &
280 sym_ij, sym_jk, sym_ik, molecular, op_pos, &
282 TYPE(neighbor_list_3c_type),
INTENT(OUT) :: ijk_list
283 TYPE(gto_basis_set_p_type),
DIMENSION(:) :: basis_i, basis_j, basis_k
284 TYPE(distribution_3d_type),
INTENT(IN) :: dist_3d
285 TYPE(libint_potential_type),
INTENT(IN) :: potential_parameter
286 CHARACTER(LEN=*),
INTENT(IN) :: name
287 TYPE(qs_environment_type),
POINTER :: qs_env
288 LOGICAL,
INTENT(IN),
OPTIONAL :: sym_ij, sym_jk, sym_ik, molecular
289 INTEGER,
INTENT(IN),
OPTIONAL :: op_pos
290 LOGICAL,
INTENT(IN),
OPTIONAL :: own_dist
292 CHARACTER(len=*),
PARAMETER :: routinen =
'build_3c_neighbor_lists'
294 INTEGER :: handle, op_pos_prv, sym_level
295 TYPE(libint_potential_type) :: pot_par_1, pot_par_2
297 CALL timeset(routinen, handle)
299 IF (
PRESENT(op_pos))
THEN
305 SELECT CASE (op_pos_prv)
307 pot_par_1 = potential_parameter
310 pot_par_2 = potential_parameter
315 qs_env, sym_ij=.false., molecular=molecular, &
316 dist_2d=dist_3d%dist_2d_1, pot_to_rad=1)
319 qs_env, sym_ij=.false., molecular=molecular, &
320 dist_2d=dist_3d%dist_2d_2, pot_to_rad=2)
325 IF (
PRESENT(sym_ij))
THEN
328 sym_level = sym_level + 1
332 IF (
PRESENT(sym_jk))
THEN
335 sym_level = sym_level + 1
339 IF (
PRESENT(sym_ik))
THEN
342 sym_level = sym_level + 1
346 IF (sym_level >= 2)
THEN
350 ijk_list%dist_3d = dist_3d
351 IF (
PRESENT(own_dist))
THEN
352 ijk_list%owns_dist = own_dist
354 ijk_list%owns_dist = .false.
357 CALL timestop(handle)
366 PURE FUNCTION include_symmetric(a, b)
367 INTEGER,
INTENT(IN) :: a, b
368 LOGICAL :: include_symmetric
371 include_symmetric = (
modulo(a + b, 2) /= 0)
373 include_symmetric = (
modulo(a + b, 2) == 0)
383 TYPE(neighbor_list_3c_type),
INTENT(INOUT) :: ijk_list
388 IF (ijk_list%owns_dist)
THEN
400 TYPE(neighbor_list_3c_iterator_type),
INTENT(OUT) :: iterator
401 TYPE(neighbor_list_3c_type),
INTENT(IN) :: ijk_nl
403 CHARACTER(len=*),
PARAMETER :: routinen =
'neighbor_list_3c_iterator_create'
407 CALL timeset(routinen, handle)
412 iterator%iter_level = 0
413 iterator%ijk_nl = ijk_nl
415 iterator%bounds_i = 0
416 iterator%bounds_j = 0
417 iterator%bounds_k = 0
419 CALL timestop(handle)
429 SUBROUTINE nl_3c_iter_set_bounds(iterator, bounds_i, bounds_j, bounds_k)
430 TYPE(neighbor_list_3c_iterator_type), &
431 INTENT(INOUT) :: iterator
432 INTEGER,
DIMENSION(2),
INTENT(IN),
OPTIONAL :: bounds_i, bounds_j, bounds_k
434 IF (
PRESENT(bounds_i)) iterator%bounds_i = bounds_i
435 IF (
PRESENT(bounds_j)) iterator%bounds_j = bounds_j
436 IF (
PRESENT(bounds_k)) iterator%bounds_k = bounds_k
445 TYPE(neighbor_list_3c_iterator_type), &
446 INTENT(INOUT) :: iterator
448 CHARACTER(len=*),
PARAMETER :: routinen =
'neighbor_list_3c_iterator_destroy'
452 CALL timeset(routinen, handle)
455 NULLIFY (iterator%iter_ij)
456 NULLIFY (iterator%iter_jk)
458 CALL timestop(handle)
467 TYPE(neighbor_list_3c_iterator_type), &
468 INTENT(INOUT) :: iterator
471 INTEGER :: iatom, iter_level, jatom, jatom_1, &
475 iter_level = iterator%iter_level
477 IF (iter_level == 0)
THEN
480 IF (iter_stat /= 0)
THEN
486 IF ((iterator%bounds_i(1) > 0 .AND. iatom < iterator%bounds_i(1)) &
487 .OR. (iterator%bounds_i(2) > 0 .AND. iatom > iterator%bounds_i(2))) skip_this = .true.
488 IF ((iterator%bounds_j(1) > 0 .AND. jatom < iterator%bounds_j(1)) &
489 .OR. (iterator%bounds_j(2) > 0 .AND. jatom > iterator%bounds_j(2))) skip_this = .true.
498 IF (iter_stat /= 0)
THEN
499 iterator%iter_level = 0
503 iterator%iter_level = 1
506 cpassert(iter_stat == 0)
507 cpassert(iterator%iter_level == 1)
511 cpassert(jatom_1 == jatom_2)
515 IF ((iterator%bounds_k(1) > 0 .AND. katom < iterator%bounds_k(1)) &
516 .OR. (iterator%bounds_k(2) > 0 .AND. katom > iterator%bounds_k(2))) skip_this = .true.
523 SELECT CASE (iterator%ijk_nl%sym)
527 skip_this = .NOT. include_symmetric(iatom, jatom)
529 skip_this = .NOT. include_symmetric(jatom, katom)
531 skip_this = .NOT. include_symmetric(iatom, katom)
533 skip_this = .NOT. include_symmetric(iatom, jatom) .OR. .NOT. include_symmetric(jatom, katom)
535 cpabort(
"should not happen")
563 rij, rjk, rik, cell_j, cell_k)
564 TYPE(neighbor_list_3c_iterator_type), &
565 INTENT(INOUT) :: iterator
566 INTEGER,
INTENT(OUT),
OPTIONAL :: ikind, jkind, kkind, nkind, iatom, &
568 REAL(kind=
dp),
DIMENSION(3),
INTENT(OUT),
OPTIONAL :: rij, rjk, rik
569 INTEGER,
DIMENSION(3),
INTENT(OUT),
OPTIONAL :: cell_j, cell_k
571 INTEGER,
DIMENSION(2) :: atoms_1, atoms_2, kinds_1, kinds_2
572 INTEGER,
DIMENSION(3) :: cell_1, cell_2
573 REAL(kind=
dp),
DIMENSION(3) :: r_1, r_2
575 cpassert(iterator%iter_level == 1)
578 ikind=kinds_1(1), jkind=kinds_1(2), nkind=nkind, &
579 iatom=atoms_1(1), jatom=atoms_1(2), r=r_1, &
583 ikind=kinds_2(1), jkind=kinds_2(2), &
584 iatom=atoms_2(1), jatom=atoms_2(2), r=r_2, &
587 IF (
PRESENT(ikind)) ikind = kinds_1(1)
588 IF (
PRESENT(jkind)) jkind = kinds_1(2)
589 IF (
PRESENT(kkind)) kkind = kinds_2(2)
590 IF (
PRESENT(iatom)) iatom = atoms_1(1)
591 IF (
PRESENT(jatom)) jatom = atoms_1(2)
592 IF (
PRESENT(katom)) katom = atoms_2(2)
594 IF (
PRESENT(rij)) rij = r_1
595 IF (
PRESENT(rjk)) rjk = r_2
596 IF (
PRESENT(rik)) rik = r_1 + r_2
598 IF (
PRESENT(cell_j)) cell_j = cell_1
599 IF (
PRESENT(cell_k)) cell_k = cell_1 + cell_2
623 SUBROUTINE alloc_block_3c(t3c, nl_3c, basis_i, basis_j, basis_k, qs_env, potential_parameter, op_pos, &
624 do_kpoints, do_hfx_kpoints, bounds_i, bounds_j, bounds_k, RI_range, &
626 TYPE(dbt_type),
DIMENSION(:, :),
INTENT(INOUT) :: t3c
627 TYPE(neighbor_list_3c_type),
INTENT(INOUT) :: nl_3c
628 TYPE(gto_basis_set_p_type),
DIMENSION(:) :: basis_i, basis_j, basis_k
629 TYPE(qs_environment_type),
POINTER :: qs_env
630 TYPE(libint_potential_type),
INTENT(IN) :: potential_parameter
631 INTEGER,
INTENT(IN),
OPTIONAL :: op_pos
632 LOGICAL,
INTENT(IN),
OPTIONAL :: do_kpoints, do_hfx_kpoints
633 INTEGER,
DIMENSION(2),
INTENT(IN),
OPTIONAL :: bounds_i, bounds_j, bounds_k
634 REAL(
dp),
INTENT(IN),
OPTIONAL :: ri_range
635 INTEGER,
DIMENSION(:),
INTENT(IN),
OPTIONAL :: img_to_ri_cell
637 CHARACTER(LEN=*),
PARAMETER :: routinen =
'alloc_block_3c'
639 INTEGER :: handle, iatom, ikind, j_img, jatom, &
640 jcell, jkind, k_img, katom, kcell, &
641 kkind, natom, ncell_ri, nimg, op_ij, &
643 INTEGER(int_8) :: a, b, nblk_per_thread
644 INTEGER(int_8),
ALLOCATABLE,
DIMENSION(:, :) :: nblk
645 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: img_to_ri_cell_prv
646 INTEGER,
DIMENSION(3) :: blk_idx, cell_j, cell_k, &
647 kp_index_lbounds, kp_index_ubounds
648 INTEGER,
DIMENSION(:, :, :),
POINTER :: cell_to_index
649 LOGICAL :: do_hfx_kpoints_prv, do_kpoints_prv
650 REAL(kind=
dp) :: dij, dik, djk, dr_ij, dr_ik, dr_jk, &
651 kind_radius_i, kind_radius_j, &
653 REAL(kind=
dp),
DIMENSION(3) :: rij, rik, rjk
654 TYPE(atomic_kind_type),
DIMENSION(:),
POINTER :: atomic_kind_set
655 TYPE(cell_type),
POINTER :: cell
656 TYPE(dft_control_type),
POINTER :: dft_control
657 TYPE(kpoint_type),
POINTER :: kpoints
658 TYPE(mp_para_env_type),
POINTER :: para_env
659 TYPE(neighbor_list_3c_iterator_type) :: nl_3c_iter
660 TYPE(one_dim_int_array),
ALLOCATABLE, &
661 DIMENSION(:, :) :: alloc_i, alloc_j, alloc_k
662 TYPE(qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
664 CALL timeset(routinen, handle)
665 NULLIFY (qs_kind_set, atomic_kind_set, cell)
667 IF (
PRESENT(do_kpoints))
THEN
668 do_kpoints_prv = do_kpoints
670 do_kpoints_prv = .false.
672 IF (
PRESENT(do_hfx_kpoints))
THEN
673 do_hfx_kpoints_prv = do_hfx_kpoints
675 do_hfx_kpoints_prv = .false.
677 IF (do_hfx_kpoints_prv)
THEN
678 cpassert(do_kpoints_prv)
679 cpassert(
PRESENT(ri_range))
680 cpassert(
PRESENT(img_to_ri_cell))
683 IF (
PRESENT(img_to_ri_cell))
THEN
684 ALLOCATE (img_to_ri_cell_prv(
SIZE(img_to_ri_cell)))
685 img_to_ri_cell_prv(:) = img_to_ri_cell
688 dr_ij = 0.0_dp; dr_jk = 0.0_dp; dr_ik = 0.0_dp
692 IF (
PRESENT(op_pos))
THEN
698 SELECT CASE (op_pos_prv)
700 op_ij = potential_parameter%potential_type
702 op_jk = potential_parameter%potential_type
721 CALL get_qs_env(qs_env, atomic_kind_set=atomic_kind_set, qs_kind_set=qs_kind_set, natom=natom, &
722 dft_control=dft_control, kpoints=kpoints, para_env=para_env, cell=cell)
724 IF (do_kpoints_prv)
THEN
725 nimg = dft_control%nimages
727 IF (do_hfx_kpoints_prv)
THEN
729 ncell_ri =
SIZE(t3c, 2)
737 IF (do_kpoints_prv)
THEN
738 kp_index_lbounds = lbound(cell_to_index)
739 kp_index_ubounds = ubound(cell_to_index)
743 ALLOCATE (nblk(nimg, ncell_ri))
748 CALL nl_3c_iter_set_bounds(nl_3c_iter, bounds_i, bounds_j, bounds_k)
752 rij=rij, rjk=rjk, rik=rik, cell_j=cell_j, cell_k=cell_k)
758 IF (do_kpoints_prv)
THEN
760 IF (any([cell_j(1), cell_j(2), cell_j(3)] < kp_index_lbounds) .OR. &
761 any([cell_j(1), cell_j(2), cell_j(3)] > kp_index_ubounds)) cycle
763 jcell = cell_to_index(cell_j(1), cell_j(2), cell_j(3))
764 IF (jcell > nimg .OR. jcell < 1) cycle
766 IF (any([cell_k(1), cell_k(2), cell_k(3)] < kp_index_lbounds) .OR. &
767 any([cell_k(1), cell_k(2), cell_k(3)] > kp_index_ubounds)) cycle
769 kcell = cell_to_index(cell_k(1), cell_k(2), cell_k(3))
770 IF (kcell > nimg .OR. kcell < 1) cycle
771 IF (do_hfx_kpoints_prv)
THEN
772 IF (dik > ri_range) cycle
783 IF (kind_radius_j + kind_radius_i + dr_ij < dij) cycle
784 IF (kind_radius_j + kind_radius_k + dr_jk < djk) cycle
785 IF (kind_radius_k + kind_radius_i + dr_ik < dik) cycle
787 nblk(jcell, kcell) = nblk(jcell, kcell) + 1
792 ALLOCATE (alloc_i(nimg, ncell_ri))
793 ALLOCATE (alloc_j(nimg, ncell_ri))
794 ALLOCATE (alloc_k(nimg, ncell_ri))
795 DO k_img = 1, ncell_ri
797 ALLOCATE (alloc_i(j_img, k_img)%array(nblk(j_img, k_img)))
798 ALLOCATE (alloc_j(j_img, k_img)%array(nblk(j_img, k_img)))
799 ALLOCATE (alloc_k(j_img, k_img)%array(nblk(j_img, k_img)))
806 CALL nl_3c_iter_set_bounds(nl_3c_iter, bounds_i, bounds_j, bounds_k)
810 iatom=iatom, jatom=jatom, katom=katom, &
811 rij=rij, rjk=rjk, rik=rik, cell_j=cell_j, cell_k=cell_k)
817 IF (do_kpoints_prv)
THEN
819 IF (any([cell_j(1), cell_j(2), cell_j(3)] < kp_index_lbounds) .OR. &
820 any([cell_j(1), cell_j(2), cell_j(3)] > kp_index_ubounds)) cycle
822 jcell = cell_to_index(cell_j(1), cell_j(2), cell_j(3))
823 IF (jcell > nimg .OR. jcell < 1) cycle
825 IF (any([cell_k(1), cell_k(2), cell_k(3)] < kp_index_lbounds) .OR. &
826 any([cell_k(1), cell_k(2), cell_k(3)] > kp_index_ubounds)) cycle
828 kcell = cell_to_index(cell_k(1), cell_k(2), cell_k(3))
829 IF (kcell > nimg .OR. kcell < 1) cycle
830 IF (do_hfx_kpoints_prv)
THEN
831 IF (dik > ri_range) cycle
832 kcell = img_to_ri_cell_prv(kcell)
838 blk_idx = [iatom, jatom, katom]
839 IF (do_hfx_kpoints_prv)
THEN
840 blk_idx(3) = (kcell - 1)*natom + katom
848 IF (kind_radius_j + kind_radius_i + dr_ij < dij) cycle
849 IF (kind_radius_j + kind_radius_k + dr_jk < djk) cycle
850 IF (kind_radius_k + kind_radius_i + dr_ik < dik) cycle
852 nblk(jcell, kcell) = nblk(jcell, kcell) + 1
855 alloc_i(jcell, kcell)%array(nblk(jcell, kcell)) = blk_idx(1)
856 alloc_j(jcell, kcell)%array(nblk(jcell, kcell)) = blk_idx(2)
857 alloc_k(jcell, kcell)%array(nblk(jcell, kcell)) = blk_idx(3)
865 DO k_img = 1, ncell_ri
867 IF (
ALLOCATED(alloc_i(j_img, k_img)%array))
THEN
868 nblk_per_thread = nblk(j_img, k_img)/omp_get_num_threads() + 1
869 a = omp_get_thread_num()*nblk_per_thread + 1
870 b = min(a + nblk_per_thread, nblk(j_img, k_img))
871 CALL dbt_reserve_blocks(t3c(j_img, k_img), &
872 alloc_i(j_img, k_img)%array(a:b), &
873 alloc_j(j_img, k_img)%array(a:b), &
874 alloc_k(j_img, k_img)%array(a:b))
880 CALL timestop(handle)
899 SUBROUTINE alloc_block_3c_old(t3c, nl_3c, basis_i, basis_j, basis_k, qs_env, potential_parameter, op_pos, &
900 do_kpoints, bounds_i, bounds_j, bounds_k)
901 TYPE(dbt_type),
DIMENSION(:, :),
INTENT(INOUT) :: t3c
902 TYPE(neighbor_list_3c_type),
INTENT(INOUT) :: nl_3c
903 TYPE(gto_basis_set_p_type),
DIMENSION(:) :: basis_i, basis_j, basis_k
904 TYPE(qs_environment_type),
POINTER :: qs_env
905 TYPE(libint_potential_type),
INTENT(IN) :: potential_parameter
906 INTEGER,
INTENT(IN),
OPTIONAL :: op_pos
907 LOGICAL,
INTENT(IN),
OPTIONAL :: do_kpoints
908 INTEGER,
DIMENSION(2),
INTENT(IN),
OPTIONAL :: bounds_i, bounds_j, bounds_k
910 CHARACTER(LEN=*),
PARAMETER :: routinen =
'alloc_block_3c_old'
912 INTEGER :: blk_cnt, handle, i, i_img, iatom, iblk, ikind, iproc, j_img, jatom, jcell, jkind, &
913 katom, kcell, kkind, natom, nimg, op_ij, op_jk, op_pos_prv
914 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: tmp
915 INTEGER,
DIMENSION(3) :: cell_j, cell_k, kp_index_lbounds, &
917 INTEGER,
DIMENSION(:, :, :),
POINTER :: cell_to_index
918 LOGICAL :: do_kpoints_prv, new_block
919 REAL(kind=
dp) :: dij, dik, djk, dr_ij, dr_ik, dr_jk, &
920 kind_radius_i, kind_radius_j, &
922 REAL(kind=
dp),
DIMENSION(3) :: rij, rik, rjk
923 TYPE(atomic_kind_type),
DIMENSION(:),
POINTER :: atomic_kind_set
924 TYPE(dft_control_type),
POINTER :: dft_control
925 TYPE(kpoint_type),
POINTER :: kpoints
926 TYPE(mp_para_env_type),
POINTER :: para_env
927 TYPE(neighbor_list_3c_iterator_type) :: nl_3c_iter
928 TYPE(one_dim_int_array),
ALLOCATABLE, &
929 DIMENSION(:, :) :: alloc_i, alloc_j, alloc_k
930 TYPE(qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
932 CALL timeset(routinen, handle)
933 NULLIFY (qs_kind_set, atomic_kind_set)
935 IF (
PRESENT(do_kpoints))
THEN
936 do_kpoints_prv = do_kpoints
938 do_kpoints_prv = .false.
941 dr_ij = 0.0_dp; dr_jk = 0.0_dp; dr_ik = 0.0_dp
945 IF (
PRESENT(op_pos))
THEN
951 SELECT CASE (op_pos_prv)
953 op_ij = potential_parameter%potential_type
955 op_jk = potential_parameter%potential_type
974 CALL get_qs_env(qs_env, atomic_kind_set=atomic_kind_set, qs_kind_set=qs_kind_set, natom=natom, &
975 dft_control=dft_control, kpoints=kpoints, para_env=para_env)
977 IF (do_kpoints_prv)
THEN
978 nimg = dft_control%nimages
984 ALLOCATE (alloc_i(nimg, nimg))
985 ALLOCATE (alloc_j(nimg, nimg))
986 ALLOCATE (alloc_k(nimg, nimg))
988 IF (do_kpoints_prv)
THEN
989 kp_index_lbounds = lbound(cell_to_index)
990 kp_index_ubounds = ubound(cell_to_index)
994 CALL nl_3c_iter_set_bounds(nl_3c_iter, bounds_i, bounds_j, bounds_k)
997 iatom=iatom, jatom=jatom, katom=katom, &
998 rij=rij, rjk=rjk, rik=rik, cell_j=cell_j, cell_k=cell_k)
1000 IF (do_kpoints_prv)
THEN
1002 IF (any([cell_j(1), cell_j(2), cell_j(3)] < kp_index_lbounds) .OR. &
1003 any([cell_j(1), cell_j(2), cell_j(3)] > kp_index_ubounds)) cycle
1005 jcell = cell_to_index(cell_j(1), cell_j(2), cell_j(3))
1006 IF (jcell > nimg .OR. jcell < 1) cycle
1008 IF (any([cell_k(1), cell_k(2), cell_k(3)] < kp_index_lbounds) .OR. &
1009 any([cell_k(1), cell_k(2), cell_k(3)] > kp_index_ubounds)) cycle
1011 kcell = cell_to_index(cell_k(1), cell_k(2), cell_k(3))
1012 IF (kcell > nimg .OR. kcell < 1) cycle
1014 jcell = 1; kcell = 1
1025 IF (kind_radius_j + kind_radius_i + dr_ij < dij) cycle
1026 IF (kind_radius_j + kind_radius_k + dr_jk < djk) cycle
1027 IF (kind_radius_k + kind_radius_i + dr_ik < dik) cycle
1034 associate(ai => alloc_i(jcell, kcell))
1035 associate(aj => alloc_j(jcell, kcell))
1036 associate(ak => alloc_k(jcell, kcell))
1039 IF (
ALLOCATED(aj%array))
THEN
1040 DO iblk = 1,
SIZE(aj%array)
1041 IF (ai%array(iblk) == iatom .AND. &
1042 aj%array(iblk) == jatom .AND. &
1043 ak%array(iblk) == katom)
THEN
1049 IF (.NOT. new_block) cycle
1051 IF (
ALLOCATED(ai%array))
THEN
1052 blk_cnt =
SIZE(ai%array)
1053 ALLOCATE (tmp(blk_cnt))
1054 tmp(:) = ai%array(:)
1055 DEALLOCATE (ai%array)
1056 ALLOCATE (ai%array(blk_cnt + 1))
1057 ai%array(1:blk_cnt) = tmp(:)
1058 ai%array(blk_cnt + 1) = iatom
1060 ALLOCATE (ai%array(1))
1064 IF (
ALLOCATED(aj%array))
THEN
1065 tmp(:) = aj%array(:)
1066 DEALLOCATE (aj%array)
1067 ALLOCATE (aj%array(blk_cnt + 1))
1068 aj%array(1:blk_cnt) = tmp(:)
1069 aj%array(blk_cnt + 1) = jatom
1071 ALLOCATE (aj%array(1))
1075 IF (
ALLOCATED(ak%array))
THEN
1076 tmp(:) = ak%array(:)
1077 DEALLOCATE (ak%array)
1078 ALLOCATE (ak%array(blk_cnt + 1))
1079 ak%array(1:blk_cnt) = tmp(:)
1080 ak%array(blk_cnt + 1) = katom
1082 ALLOCATE (ak%array(1))
1086 IF (
ALLOCATED(tmp))
DEALLOCATE (tmp)
1096 IF (
ALLOCATED(alloc_i(i_img, j_img)%array))
THEN
1097 DO i = 1,
SIZE(alloc_i(i_img, j_img)%array)
1098 CALL dbt_get_stored_coordinates(t3c(i_img, j_img), &
1099 [alloc_i(i_img, j_img)%array(i), alloc_j(i_img, j_img)%array(i), &
1100 alloc_k(i_img, j_img)%array(i)], &
1102 cpassert(iproc .EQ. para_env%mepos)
1105 CALL dbt_reserve_blocks(t3c(i_img, j_img), &
1106 alloc_i(i_img, j_img)%array, &
1107 alloc_j(i_img, j_img)%array, &
1108 alloc_k(i_img, j_img)%array)
1113 CALL timestop(handle)
1142 nl_3c, basis_i, basis_j, basis_k, &
1143 potential_parameter, der_eps, &
1144 op_pos, do_kpoints, do_hfx_kpoints, &
1145 bounds_i, bounds_j, bounds_k, &
1146 RI_range, img_to_RI_cell)
1148 TYPE(dbt_type),
DIMENSION(:, :, :),
INTENT(INOUT) :: t3c_der_i, t3c_der_k
1149 REAL(kind=dp),
INTENT(IN) :: filter_eps
1150 TYPE(qs_environment_type),
POINTER :: qs_env
1151 TYPE(neighbor_list_3c_type),
INTENT(INOUT) :: nl_3c
1152 TYPE(gto_basis_set_p_type),
DIMENSION(:) :: basis_i, basis_j, basis_k
1153 TYPE(libint_potential_type),
INTENT(IN) :: potential_parameter
1154 REAL(kind=dp),
INTENT(IN),
OPTIONAL :: der_eps
1155 INTEGER,
INTENT(IN),
OPTIONAL :: op_pos
1156 LOGICAL,
INTENT(IN),
OPTIONAL :: do_kpoints, do_hfx_kpoints
1157 INTEGER,
DIMENSION(2),
INTENT(IN),
OPTIONAL :: bounds_i, bounds_j, bounds_k
1158 REAL(dp),
INTENT(IN),
OPTIONAL :: ri_range
1159 INTEGER,
DIMENSION(:),
INTENT(IN),
OPTIONAL :: img_to_ri_cell
1161 CHARACTER(LEN=*),
PARAMETER :: routinen =
'build_3c_derivatives'
1163 INTEGER :: block_end_i, block_end_j, block_end_k, block_start_i, block_start_j, &
1164 block_start_k, egfi, handle, handle2, i, i_img, i_xyz, iatom, ibasis, ikind, ilist,
imax, &
1165 iset, j_img, jatom, jcell, jkind, jset, katom, kcell, kkind, kset, m_max, max_ncoi, &
1166 max_ncoj, max_ncok, max_nset, max_nsgfi, max_nsgfj, max_nsgfk, maxli, maxlj, maxlk, &
1167 mepos, natom, nbasis, ncell_ri, ncoi, ncoj, ncok, nimg, nseti, nsetj, nsetk, nthread, &
1168 op_ij, op_jk, op_pos_prv, sgfi, sgfj, sgfk, unit_id
1169 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: img_to_ri_cell_prv
1170 INTEGER,
DIMENSION(2) :: bo
1171 INTEGER,
DIMENSION(3) :: blk_idx, blk_size, cell_j, cell_k, &
1172 kp_index_lbounds, kp_index_ubounds, sp
1173 INTEGER,
DIMENSION(:),
POINTER :: lmax_i, lmax_j, lmax_k, lmin_i, lmin_j, &
1174 lmin_k, npgfi, npgfj, npgfk, nsgfi, &
1176 INTEGER,
DIMENSION(:, :),
POINTER :: first_sgf_i, first_sgf_j, first_sgf_k
1177 INTEGER,
DIMENSION(:, :, :),
POINTER :: cell_to_index
1178 LOGICAL :: do_hfx_kpoints_prv, do_kpoints_prv, &
1180 LOGICAL,
DIMENSION(3) :: block_j_not_zero, block_k_not_zero, &
1181 der_j_zero, der_k_zero
1182 REAL(dp),
DIMENSION(3) :: der_ext_i, der_ext_j, der_ext_k
1183 REAL(kind=dp) :: dij, dik, djk, dr_ij, dr_ik, dr_jk, &
1184 kind_radius_i, kind_radius_j, &
1185 kind_radius_k, prefac
1186 REAL(kind=dp),
ALLOCATABLE,
DIMENSION(:) :: ccp_buffer, cpp_buffer, &
1187 max_contraction_i, max_contraction_j, &
1189 REAL(kind=dp),
ALLOCATABLE,
DIMENSION(:, :, :) :: dijk_contr, dummy_block_t
1190 REAL(kind=dp),
ALLOCATABLE,
DIMENSION(:, :, :, :) :: block_t_i, block_t_j, block_t_k, dijk_j, &
1191 dijk_k, tmp_ijk_i, tmp_ijk_j
1192 REAL(kind=dp),
DIMENSION(3) :: ri, rij, rik, rj, rjk, rk
1193 REAL(kind=dp),
DIMENSION(:),
POINTER :: set_radius_i, set_radius_j, set_radius_k
1194 REAL(kind=dp),
DIMENSION(:, :),
POINTER :: rpgf_i, rpgf_j, rpgf_k, sphi_i, sphi_j, &
1195 sphi_k, zeti, zetj, zetk
1196 TYPE(atomic_kind_type),
DIMENSION(:),
POINTER :: atomic_kind_set
1197 TYPE(cp_2d_r_p_type),
DIMENSION(:, :),
POINTER :: spi, spk, tspj
1198 TYPE(cp_libint_t) :: lib
1199 TYPE(dbt_type) :: t3c_tmp
1200 TYPE(dbt_type),
ALLOCATABLE,
DIMENSION(:, :) :: t3c_template
1201 TYPE(dbt_type),
ALLOCATABLE,
DIMENSION(:, :, :) :: t3c_der_j
1202 TYPE(dft_control_type),
POINTER :: dft_control
1203 TYPE(gto_basis_set_type),
POINTER :: basis_set
1204 TYPE(kpoint_type),
POINTER :: kpoints
1205 TYPE(mp_para_env_type),
POINTER :: para_env
1206 TYPE(neighbor_list_3c_iterator_type) :: nl_3c_iter
1207 TYPE(qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
1209 CALL timeset(routinen, handle)
1211 IF (
PRESENT(do_kpoints))
THEN
1212 do_kpoints_prv = do_kpoints
1214 do_kpoints_prv = .false.
1217 IF (
PRESENT(do_hfx_kpoints))
THEN
1218 do_hfx_kpoints_prv = do_hfx_kpoints
1220 do_hfx_kpoints_prv = .false.
1222 IF (do_hfx_kpoints_prv)
THEN
1223 cpassert(do_kpoints_prv)
1224 cpassert(
PRESENT(ri_range))
1225 cpassert(
PRESENT(img_to_ri_cell))
1228 IF (
PRESENT(img_to_ri_cell))
THEN
1229 ALLOCATE (img_to_ri_cell_prv(
SIZE(img_to_ri_cell)))
1230 img_to_ri_cell_prv(:) = img_to_ri_cell
1233 op_ij = do_potential_id; op_jk = do_potential_id
1235 IF (
PRESENT(op_pos))
THEN
1241 SELECT CASE (op_pos_prv)
1243 op_ij = potential_parameter%potential_type
1245 op_jk = potential_parameter%potential_type
1248 dr_ij = 0.0_dp; dr_jk = 0.0_dp; dr_ik = 0.0_dp
1250 IF (op_ij == do_potential_truncated .OR. op_ij == do_potential_short)
THEN
1251 dr_ij = potential_parameter%cutoff_radius*cutoff_screen_factor
1252 dr_ik = potential_parameter%cutoff_radius*cutoff_screen_factor
1253 ELSEIF (op_ij == do_potential_coulomb)
THEN
1254 dr_ij = 1000000.0_dp
1255 dr_ik = 1000000.0_dp
1258 IF (op_jk == do_potential_truncated .OR. op_jk == do_potential_short)
THEN
1259 dr_jk = potential_parameter%cutoff_radius*cutoff_screen_factor
1260 dr_ik = potential_parameter%cutoff_radius*cutoff_screen_factor
1261 ELSEIF (op_jk == do_potential_coulomb)
THEN
1262 dr_jk = 1000000.0_dp
1263 dr_ik = 1000000.0_dp
1266 NULLIFY (qs_kind_set, atomic_kind_set)
1269 CALL get_qs_env(qs_env, atomic_kind_set=atomic_kind_set, qs_kind_set=qs_kind_set, &
1270 natom=natom, kpoints=kpoints, dft_control=dft_control, para_env=para_env)
1272 IF (do_kpoints_prv)
THEN
1273 nimg = dft_control%nimages
1275 IF (do_hfx_kpoints_prv)
THEN
1276 nimg =
SIZE(t3c_der_k, 1)
1277 ncell_ri =
SIZE(t3c_der_k, 2)
1279 CALL get_kpoint_info(kpoints, cell_to_index=cell_to_index)
1285 IF (do_hfx_kpoints_prv)
THEN
1286 cpassert(op_pos_prv == 2)
1288 cpassert(all(shape(t3c_der_k) == [nimg, ncell_ri, 3]))
1291 ALLOCATE (t3c_template(nimg, ncell_ri))
1292 DO j_img = 1, ncell_ri
1294 CALL dbt_create(t3c_der_i(i_img, j_img, 1), t3c_template(i_img, j_img))
1298 CALL alloc_block_3c(t3c_template, nl_3c, basis_i, basis_j, basis_k, qs_env, potential_parameter, &
1299 op_pos=op_pos_prv, do_kpoints=do_kpoints, do_hfx_kpoints=do_hfx_kpoints, &
1300 bounds_i=bounds_i, bounds_j=bounds_j, bounds_k=bounds_k, &
1301 ri_range=ri_range, img_to_ri_cell=img_to_ri_cell)
1303 DO j_img = 1, ncell_ri
1305 CALL dbt_copy(t3c_template(i_img, j_img), t3c_der_i(i_img, j_img, i_xyz))
1306 CALL dbt_copy(t3c_template(i_img, j_img), t3c_der_k(i_img, j_img, i_xyz))
1311 DO j_img = 1, ncell_ri
1313 CALL dbt_destroy(t3c_template(i_img, j_img))
1316 DEALLOCATE (t3c_template)
1318 IF (nl_3c%sym == symmetric_jk)
THEN
1319 ALLOCATE (t3c_der_j(nimg, ncell_ri, 3))
1321 DO j_img = 1, ncell_ri
1323 CALL dbt_create(t3c_der_k(i_img, j_img, i_xyz), t3c_der_j(i_img, j_img, i_xyz))
1324 CALL dbt_copy(t3c_der_k(i_img, j_img, i_xyz), t3c_der_j(i_img, j_img, i_xyz))
1331 nbasis =
SIZE(basis_i)
1336 DO ibasis = 1, nbasis
1337 CALL get_gto_basis_set(gto_basis_set=basis_i(ibasis)%gto_basis_set, maxl=
imax, &
1338 nset=iset, nsgf_set=nsgfi, npgf=npgfi)
1339 maxli = max(maxli,
imax)
1340 max_nset = max(max_nset, iset)
1341 max_nsgfi = max(max_nsgfi, maxval(nsgfi))
1342 max_ncoi = max(max_ncoi, maxval(npgfi)*
ncoset(maxli))
1347 DO ibasis = 1, nbasis
1348 CALL get_gto_basis_set(gto_basis_set=basis_j(ibasis)%gto_basis_set, maxl=
imax, &
1349 nset=jset, nsgf_set=nsgfj, npgf=npgfj)
1350 maxlj = max(maxlj,
imax)
1351 max_nset = max(max_nset, jset)
1352 max_nsgfj = max(max_nsgfj, maxval(nsgfj))
1353 max_ncoj = max(max_ncoj, maxval(npgfj)*
ncoset(maxlj))
1358 DO ibasis = 1, nbasis
1359 CALL get_gto_basis_set(gto_basis_set=basis_k(ibasis)%gto_basis_set, maxl=
imax, &
1360 nset=kset, nsgf_set=nsgfk, npgf=npgfk)
1361 maxlk = max(maxlk,
imax)
1362 max_nset = max(max_nset, kset)
1363 max_nsgfk = max(max_nsgfk, maxval(nsgfk))
1364 max_ncok = max(max_ncok, maxval(npgfk)*
ncoset(maxlk))
1366 m_max = maxli + maxlj + maxlk + 1
1371 NULLIFY (tspj, spi, spk)
1372 ALLOCATE (spi(max_nset, nbasis), tspj(max_nset, nbasis), spk(max_nset, nbasis))
1374 DO ibasis = 1, nbasis
1375 DO iset = 1, max_nset
1376 NULLIFY (spi(iset, ibasis)%array)
1377 NULLIFY (tspj(iset, ibasis)%array)
1379 NULLIFY (spk(iset, ibasis)%array)
1384 DO ibasis = 1, nbasis
1385 IF (ilist == 1) basis_set => basis_i(ibasis)%gto_basis_set
1386 IF (ilist == 2) basis_set => basis_j(ibasis)%gto_basis_set
1387 IF (ilist == 3) basis_set => basis_k(ibasis)%gto_basis_set
1389 DO iset = 1, basis_set%nset
1391 ncoi = basis_set%npgf(iset)*
ncoset(basis_set%lmax(iset))
1392 sgfi = basis_set%first_sgf(1, iset)
1393 egfi = sgfi + basis_set%nsgf_set(iset) - 1
1395 IF (ilist == 1)
THEN
1396 ALLOCATE (spi(iset, ibasis)%array(ncoi, basis_set%nsgf_set(iset)))
1397 spi(iset, ibasis)%array(:, :) = basis_set%sphi(1:ncoi, sgfi:egfi)
1399 ELSE IF (ilist == 2)
THEN
1400 ALLOCATE (tspj(iset, ibasis)%array(basis_set%nsgf_set(iset), ncoi))
1401 tspj(iset, ibasis)%array(:, :) = transpose(basis_set%sphi(1:ncoi, sgfi:egfi))
1404 ALLOCATE (spk(iset, ibasis)%array(ncoi, basis_set%nsgf_set(iset)))
1405 spk(iset, ibasis)%array(:, :) = basis_set%sphi(1:ncoi, sgfi:egfi)
1413 IF (op_ij == do_potential_truncated .OR. op_jk == do_potential_truncated)
THEN
1415 IF (m_max > get_lmax_init())
THEN
1416 IF (para_env%mepos == 0)
THEN
1417 CALL open_file(unit_number=unit_id, file_name=potential_parameter%filename)
1419 CALL init(m_max, unit_id, para_env%mepos, para_env)
1420 IF (para_env%mepos == 0)
THEN
1421 CALL close_file(unit_id)
1426 CALL init_md_ftable(nmax=m_max)
1428 IF (do_kpoints_prv)
THEN
1429 kp_index_lbounds = lbound(cell_to_index)
1430 kp_index_ubounds = ubound(cell_to_index)
1456 CALL cp_libint_init_3eri1(lib, max(maxli, maxlj, maxlk))
1457 CALL cp_libint_set_contrdepth(lib, 1)
1460 ALLOCATE (cpp_buffer(max_nsgfj*max_ncok), ccp_buffer(max_nsgfj*max_nsgfk*max_ncoi))
1465 IF (
PRESENT(bounds_i))
THEN
1466 bo = get_limit(bounds_i(2) - bounds_i(1) + 1, nthread, mepos)
1467 bo(:) = bo(:) + bounds_i(1) - 1
1468 CALL nl_3c_iter_set_bounds(nl_3c_iter, bo, bounds_j, bounds_k)
1469 ELSE IF (
PRESENT(bounds_j))
THEN
1470 bo = get_limit(bounds_j(2) - bounds_j(1) + 1, nthread, mepos)
1471 bo(:) = bo(:) + bounds_j(1) - 1
1472 CALL nl_3c_iter_set_bounds(nl_3c_iter, bounds_i, bo, bounds_k)
1473 ELSE IF (
PRESENT(bounds_k))
THEN
1474 bo = get_limit(bounds_k(2) - bounds_k(1) + 1, nthread, mepos)
1475 bo(:) = bo(:) + bounds_k(1) - 1
1476 CALL nl_3c_iter_set_bounds(nl_3c_iter, bounds_i, bounds_j, bo)
1478 bo = get_limit(natom, nthread, mepos)
1479 CALL nl_3c_iter_set_bounds(nl_3c_iter, bo, bounds_j, bounds_k)
1483 IF (bo(1) > bo(2)) skip = .true.
1487 iatom=iatom, jatom=jatom, katom=katom, &
1488 rij=rij, rjk=rjk, rik=rik, cell_j=cell_j, cell_k=cell_k)
1495 IF (do_kpoints_prv)
THEN
1497 ELSEIF (nl_3c%sym == symmetric_jk)
THEN
1498 IF (jatom == katom)
THEN
1506 IF (do_hfx_kpoints_prv) prefac = 1.0_dp
1508 IF (do_kpoints_prv)
THEN
1510 IF (any([cell_j(1), cell_j(2), cell_j(3)] < kp_index_lbounds) .OR. &
1511 any([cell_j(1), cell_j(2), cell_j(3)] > kp_index_ubounds)) cycle
1513 jcell = cell_to_index(cell_j(1), cell_j(2), cell_j(3))
1514 IF (jcell > nimg .OR. jcell < 1) cycle
1516 IF (any([cell_k(1), cell_k(2), cell_k(3)] < kp_index_lbounds) .OR. &
1517 any([cell_k(1), cell_k(2), cell_k(3)] > kp_index_ubounds)) cycle
1519 kcell = cell_to_index(cell_k(1), cell_k(2), cell_k(3))
1520 IF (kcell > nimg .OR. kcell < 1) cycle
1522 IF (do_hfx_kpoints_prv)
THEN
1523 IF (dik > ri_range) cycle
1524 kcell = img_to_ri_cell_prv(kcell)
1527 jcell = 1; kcell = 1
1530 blk_idx = [iatom, jatom, katom]
1531 IF (do_hfx_kpoints_prv)
THEN
1532 blk_idx(3) = (kcell - 1)*natom + katom
1536 CALL get_gto_basis_set(basis_i(ikind)%gto_basis_set, first_sgf=first_sgf_i, lmax=lmax_i, lmin=lmin_i, &
1537 npgf=npgfi, nset=nseti, nsgf_set=nsgfi, pgf_radius=rpgf_i, set_radius=set_radius_i, &
1538 sphi=sphi_i, zet=zeti, kind_radius=kind_radius_i)
1540 CALL get_gto_basis_set(basis_j(jkind)%gto_basis_set, first_sgf=first_sgf_j, lmax=lmax_j, lmin=lmin_j, &
1541 npgf=npgfj, nset=nsetj, nsgf_set=nsgfj, pgf_radius=rpgf_j, set_radius=set_radius_j, &
1542 sphi=sphi_j, zet=zetj, kind_radius=kind_radius_j)
1544 CALL get_gto_basis_set(basis_k(kkind)%gto_basis_set, first_sgf=first_sgf_k, lmax=lmax_k, lmin=lmin_k, &
1545 npgf=npgfk, nset=nsetk, nsgf_set=nsgfk, pgf_radius=rpgf_k, set_radius=set_radius_k, &
1546 sphi=sphi_k, zet=zetk, kind_radius=kind_radius_k)
1548 IF (kind_radius_j + kind_radius_i + dr_ij < dij) cycle
1549 IF (kind_radius_j + kind_radius_k + dr_jk < djk) cycle
1550 IF (kind_radius_k + kind_radius_i + dr_ik < dik) cycle
1552 ALLOCATE (max_contraction_i(nseti))
1553 max_contraction_i = 0.0_dp
1555 sgfi = first_sgf_i(1, iset)
1556 max_contraction_i(iset) = maxval((/(sum(abs(sphi_i(:, i))), i=sgfi, sgfi + nsgfi(iset) - 1)/))
1559 ALLOCATE (max_contraction_j(nsetj))
1560 max_contraction_j = 0.0_dp
1562 sgfj = first_sgf_j(1, jset)
1563 max_contraction_j(jset) = maxval((/(sum(abs(sphi_j(:, i))), i=sgfj, sgfj + nsgfj(jset) - 1)/))
1566 ALLOCATE (max_contraction_k(nsetk))
1567 max_contraction_k = 0.0_dp
1569 sgfk = first_sgf_k(1, kset)
1570 max_contraction_k(kset) = maxval((/(sum(abs(sphi_k(:, i))), i=sgfk, sgfk + nsgfk(kset) - 1)/))
1573 CALL dbt_blk_sizes(t3c_der_i(jcell, kcell, 1), blk_idx, blk_size)
1575 ALLOCATE (block_t_i(blk_size(2), blk_size(3), blk_size(1), 3))
1576 ALLOCATE (block_t_j(blk_size(2), blk_size(3), blk_size(1), 3))
1577 ALLOCATE (block_t_k(blk_size(2), blk_size(3), blk_size(1), 3))
1582 block_j_not_zero = .false.
1583 block_k_not_zero = .false.
1589 IF (set_radius_j(jset) + set_radius_i(iset) + dr_ij < dij) cycle
1593 IF (set_radius_j(jset) + set_radius_k(kset) + dr_jk < djk) cycle
1594 IF (set_radius_k(kset) + set_radius_i(iset) + dr_ik < dik) cycle
1596 ncoi = npgfi(iset)*
ncoset(lmax_i(iset))
1597 ncoj = npgfj(jset)*
ncoset(lmax_j(jset))
1598 ncok = npgfk(kset)*
ncoset(lmax_k(kset))
1600 sgfi = first_sgf_i(1, iset)
1601 sgfj = first_sgf_j(1, jset)
1602 sgfk = first_sgf_k(1, kset)
1604 IF (ncoj*ncok*ncoi > 0)
THEN
1605 ALLOCATE (dijk_j(ncoj, ncok, ncoi, 3))
1606 ALLOCATE (dijk_k(ncoj, ncok, ncoi, 3))
1607 dijk_j(:, :, :, :) = 0.0_dp
1608 dijk_k(:, :, :, :) = 0.0_dp
1610 der_j_zero = .false.
1611 der_k_zero = .false.
1618 IF (op_pos_prv == 1)
THEN
1619 CALL eri_3center_derivs(dijk_j, dijk_k, &
1620 lmin_j(jset), lmax_j(jset), npgfj(jset), zetj(:, jset), rpgf_j(:, jset), rj, &
1621 lmin_k(kset), lmax_k(kset), npgfk(kset), zetk(:, kset), rpgf_k(:, kset), rk, &
1622 lmin_i(iset), lmax_i(iset), npgfi(iset), zeti(:, iset), rpgf_i(:, iset), ri, &
1623 djk, dij, dik, lib, potential_parameter, &
1624 der_abc_1_ext=der_ext_j, der_abc_2_ext=der_ext_k)
1626 ALLOCATE (tmp_ijk_i(ncoi, ncoj, ncok, 3))
1627 ALLOCATE (tmp_ijk_j(ncoi, ncoj, ncok, 3))
1628 tmp_ijk_i(:, :, :, :) = 0.0_dp
1629 tmp_ijk_j(:, :, :, :) = 0.0_dp
1631 CALL eri_3center_derivs(tmp_ijk_i, tmp_ijk_j, &
1632 lmin_i(iset), lmax_i(iset), npgfi(iset), zeti(:, iset), rpgf_i(:, iset), ri, &
1633 lmin_j(jset), lmax_j(jset), npgfj(jset), zetj(:, jset), rpgf_j(:, jset), rj, &
1634 lmin_k(kset), lmax_k(kset), npgfk(kset), zetk(:, kset), rpgf_k(:, kset), rk, &
1635 dij, dik, djk, lib, potential_parameter, &
1636 der_abc_1_ext=der_ext_i, der_abc_2_ext=der_ext_j)
1642 dijk_j(:, :, i, i_xyz) = tmp_ijk_j(i, :, :, i_xyz)
1643 dijk_k(:, :, i, i_xyz) = -(dijk_j(:, :, i, i_xyz) + tmp_ijk_i(i, :, :, i_xyz))
1644 der_ext_k(i_xyz) = max(der_ext_k(i_xyz), maxval(abs(dijk_k(:, :, i, i_xyz))))
1647 DEALLOCATE (tmp_ijk_i, tmp_ijk_j)
1651 IF (
PRESENT(der_eps))
THEN
1653 IF (der_eps > der_ext_j(i_xyz)*(max_contraction_i(iset)* &
1654 max_contraction_j(jset)* &
1655 max_contraction_k(kset)))
THEN
1656 der_j_zero(i_xyz) = .true.
1661 IF (der_eps > der_ext_k(i_xyz)*(max_contraction_i(iset)* &
1662 max_contraction_j(jset)* &
1663 max_contraction_k(kset)))
THEN
1664 der_k_zero(i_xyz) = .true.
1667 IF (all(der_j_zero) .AND. all(der_k_zero))
THEN
1668 DEALLOCATE (dijk_j, dijk_k)
1673 ALLOCATE (dijk_contr(nsgfj(jset), nsgfk(kset), nsgfi(iset)))
1675 block_start_j = sgfj
1676 block_end_j = sgfj + nsgfj(jset) - 1
1677 block_start_k = sgfk
1678 block_end_k = sgfk + nsgfk(kset) - 1
1679 block_start_i = sgfi
1680 block_end_i = sgfi + nsgfi(iset) - 1
1683 IF (der_j_zero(i_xyz)) cycle
1685 block_j_not_zero(i_xyz) = .true.
1686 CALL libxsmm_abc_contract(dijk_contr, dijk_j(:, :, :, i_xyz), tspj(jset, jkind)%array, &
1687 spk(kset, kkind)%array, spi(iset, ikind)%array, &
1688 ncoj, ncok, ncoi, nsgfj(jset), nsgfk(kset), &
1689 nsgfi(iset), cpp_buffer, ccp_buffer)
1691 block_t_j(block_start_j:block_end_j, &
1692 block_start_k:block_end_k, &
1693 block_start_i:block_end_i, i_xyz) = &
1694 block_t_j(block_start_j:block_end_j, &
1695 block_start_k:block_end_k, &
1696 block_start_i:block_end_i, i_xyz) + &
1697 prefac*dijk_contr(:, :, :)
1702 IF (der_k_zero(i_xyz)) cycle
1704 block_k_not_zero(i_xyz) = .true.
1705 CALL libxsmm_abc_contract(dijk_contr, dijk_k(:, :, :, i_xyz), tspj(jset, jkind)%array, &
1706 spk(kset, kkind)%array, spi(iset, ikind)%array, &
1707 ncoj, ncok, ncoi, nsgfj(jset), nsgfk(kset), &
1708 nsgfi(iset), cpp_buffer, ccp_buffer)
1710 block_t_k(block_start_j:block_end_j, &
1711 block_start_k:block_end_k, &
1712 block_start_i:block_end_i, i_xyz) = &
1713 block_t_k(block_start_j:block_end_j, &
1714 block_start_k:block_end_k, &
1715 block_start_i:block_end_i, i_xyz) + &
1716 prefac*dijk_contr(:, :, :)
1720 DEALLOCATE (dijk_j, dijk_k, dijk_contr)
1726 CALL timeset(routinen//
"_put_dbcsr", handle2)
1728 sp = shape(block_t_i(:, :, :, 1))
1733 IF ((.NOT. block_j_not_zero(i_xyz)) .AND. (.NOT. block_k_not_zero(i_xyz))) cycle
1734 block_t_i(:, :, :, i_xyz) = -(block_t_j(:, :, :, i_xyz) + block_t_k(:, :, :, i_xyz))
1736 CALL dbt_put_block(t3c_der_i(jcell, kcell, i_xyz), blk_idx, sp, &
1737 reshape(block_t_i(:, :, :, i_xyz), shape=sp, order=[2, 3, 1]), &
1742 IF (nl_3c%sym == symmetric_jk)
THEN
1744 sp = shape(block_t_j(:, :, :, 1))
1748 IF (.NOT. block_j_not_zero(i_xyz)) cycle
1749 CALL dbt_put_block(t3c_der_j(jcell, kcell, i_xyz), blk_idx, sp, &
1750 reshape(block_t_j(:, :, :, i_xyz), shape=sp, order=[2, 3, 1]), &
1756 sp = shape(block_t_k(:, :, :, 1))
1760 IF (.NOT. block_k_not_zero(i_xyz)) cycle
1761 CALL dbt_put_block(t3c_der_k(jcell, kcell, i_xyz), blk_idx, sp, &
1762 reshape(block_t_k(:, :, :, i_xyz), shape=sp, order=[2, 3, 1]), &
1767 CALL timestop(handle2)
1769 DEALLOCATE (block_t_i)
1770 DEALLOCATE (block_t_j)
1771 DEALLOCATE (block_t_k)
1773 DEALLOCATE (max_contraction_i, max_contraction_j, max_contraction_k)
1776 CALL cp_libint_cleanup_3eri1(lib)
1781 IF (do_kpoints_prv .AND. .NOT. do_hfx_kpoints_prv)
THEN
1786 CALL dbt_filter(t3c_der_i(jcell, kcell, i_xyz), filter_eps/2)
1787 CALL dbt_filter(t3c_der_k(jcell, kcell, i_xyz), filter_eps/2)
1792 ELSEIF (nl_3c%sym == symmetric_jk)
THEN
1794 CALL dbt_create(t3c_der_k(1, 1, 1), t3c_tmp)
1798 CALL dbt_copy(t3c_der_j(jcell, kcell, i_xyz), t3c_der_k(jcell, kcell, i_xyz), &
1799 order=[1, 3, 2], move_data=.true., summation=.true.)
1800 CALL dbt_filter(t3c_der_k(jcell, kcell, i_xyz), filter_eps)
1802 CALL dbt_copy(t3c_der_i(jcell, kcell, i_xyz), t3c_tmp)
1803 CALL dbt_copy(t3c_tmp, t3c_der_i(jcell, kcell, i_xyz), &
1804 order=[1, 3, 2], move_data=.true., summation=.true.)
1805 CALL dbt_filter(t3c_der_i(jcell, kcell, i_xyz), filter_eps)
1809 CALL dbt_destroy(t3c_tmp)
1811 ELSEIF (nl_3c%sym == symmetric_none)
THEN
1813 DO kcell = 1, ncell_ri
1815 CALL dbt_filter(t3c_der_i(jcell, kcell, i_xyz), filter_eps)
1816 CALL dbt_filter(t3c_der_k(jcell, kcell, i_xyz), filter_eps)
1821 cpabort(
"requested symmetric case not implemented")
1824 IF (nl_3c%sym == symmetric_jk)
THEN
1828 CALL dbt_destroy(t3c_der_j(i_img, j_img, i_xyz))
1834 DO iset = 1, max_nset
1835 DO ibasis = 1, nbasis
1836 IF (
ASSOCIATED(spi(iset, ibasis)%array))
DEALLOCATE (spi(iset, ibasis)%array)
1837 IF (
ASSOCIATED(tspj(iset, ibasis)%array))
DEALLOCATE (tspj(iset, ibasis)%array)
1839 IF (
ASSOCIATED(spk(iset, ibasis)%array))
DEALLOCATE (spk(iset, ibasis)%array)
1843 DEALLOCATE (spi, tspj, spk)
1845 CALL timestop(handle)
1866 nl_3c, basis_i, basis_j, basis_k, &
1867 potential_parameter, der_eps, op_pos)
1869 REAL(dp),
DIMENSION(3, 3),
INTENT(INOUT) :: work_virial
1870 TYPE(dbt_type),
INTENT(INOUT) :: t3c_trace
1871 REAL(kind=dp),
INTENT(IN) :: pref
1872 TYPE(qs_environment_type),
POINTER :: qs_env
1873 TYPE(neighbor_list_3c_type),
INTENT(INOUT) :: nl_3c
1874 TYPE(gto_basis_set_p_type),
DIMENSION(:) :: basis_i, basis_j, basis_k
1875 TYPE(libint_potential_type),
INTENT(IN) :: potential_parameter
1876 REAL(kind=dp),
INTENT(IN),
OPTIONAL :: der_eps
1877 INTEGER,
INTENT(IN),
OPTIONAL :: op_pos
1879 CHARACTER(LEN=*),
PARAMETER :: routinen =
'calc_3c_virial'
1881 INTEGER :: block_end_i, block_end_j, block_end_k, block_start_i, block_start_j, &
1882 block_start_k, egfi, handle, i, i_xyz, iatom, ibasis, ikind, ilist,
imax, iset, j_xyz, &
1883 jatom, jkind, jset, katom, kkind, kset, m_max, max_ncoi, max_ncoj, max_ncok, max_nset, &
1884 max_nsgfi, max_nsgfj, max_nsgfk, maxli, maxlj, maxlk, mepos, natom, nbasis, ncoi, ncoj, &
1885 ncok, nseti, nsetj, nsetk, nthread, op_ij, op_jk, op_pos_prv, sgfi, sgfj, sgfk, unit_id
1886 INTEGER,
DIMENSION(2) :: bo
1887 INTEGER,
DIMENSION(3) :: blk_size, sp
1888 INTEGER,
DIMENSION(:),
POINTER :: lmax_i, lmax_j, lmax_k, lmin_i, lmin_j, &
1889 lmin_k, npgfi, npgfj, npgfk, nsgfi, &
1891 INTEGER,
DIMENSION(:, :),
POINTER :: first_sgf_i, first_sgf_j, first_sgf_k
1892 LOGICAL :: found, skip
1893 LOGICAL,
DIMENSION(3) :: block_j_not_zero, block_k_not_zero, &
1894 der_j_zero, der_k_zero
1896 REAL(dp),
DIMENSION(3) :: der_ext_i, der_ext_j, der_ext_k
1897 REAL(kind=dp) :: dij, dik, djk, dr_ij, dr_ik, dr_jk, &
1898 kind_radius_i, kind_radius_j, &
1900 REAL(kind=dp),
ALLOCATABLE,
DIMENSION(:) :: ccp_buffer, cpp_buffer, &
1901 max_contraction_i, max_contraction_j, &
1903 REAL(kind=dp),
ALLOCATABLE,
DIMENSION(:, :, :) :: ablock, dijk_contr, tmp_block
1904 REAL(kind=dp),
ALLOCATABLE,
DIMENSION(:, :, :, :) :: block_t_i, block_t_j, block_t_k, dijk_j, &
1906 REAL(kind=dp),
DIMENSION(3) :: ri, rij, rik, rj, rjk, rk, scoord
1907 REAL(kind=dp),
DIMENSION(:),
POINTER :: set_radius_i, set_radius_j, set_radius_k
1908 REAL(kind=dp),
DIMENSION(:, :),
POINTER :: rpgf_i, rpgf_j, rpgf_k, sphi_i, sphi_j, &
1909 sphi_k, zeti, zetj, zetk
1910 TYPE(atomic_kind_type),
DIMENSION(:),
POINTER :: atomic_kind_set
1911 TYPE(cell_type),
POINTER :: cell
1912 TYPE(cp_2d_r_p_type),
DIMENSION(:, :),
POINTER :: spi, spk, tspj
1913 TYPE(cp_libint_t) :: lib
1914 TYPE(dft_control_type),
POINTER :: dft_control
1915 TYPE(gto_basis_set_type),
POINTER :: basis_set
1916 TYPE(mp_para_env_type),
POINTER :: para_env
1917 TYPE(neighbor_list_3c_iterator_type) :: nl_3c_iter
1918 TYPE(particle_type),
DIMENSION(:),
POINTER :: particle_set
1919 TYPE(qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
1921 CALL timeset(routinen, handle)
1923 op_ij = do_potential_id; op_jk = do_potential_id
1925 IF (
PRESENT(op_pos))
THEN
1930 cpassert(op_pos == 1)
1931 cpassert(.NOT. nl_3c%sym == symmetric_jk)
1933 SELECT CASE (op_pos_prv)
1935 op_ij = potential_parameter%potential_type
1937 op_jk = potential_parameter%potential_type
1940 dr_ij = 0.0_dp; dr_jk = 0.0_dp; dr_ik = 0.0_dp
1942 IF (op_ij == do_potential_truncated .OR. op_ij == do_potential_short)
THEN
1943 dr_ij = potential_parameter%cutoff_radius*cutoff_screen_factor
1944 dr_ik = potential_parameter%cutoff_radius*cutoff_screen_factor
1945 ELSEIF (op_ij == do_potential_coulomb)
THEN
1946 dr_ij = 1000000.0_dp
1947 dr_ik = 1000000.0_dp
1950 IF (op_jk == do_potential_truncated .OR. op_jk == do_potential_short)
THEN
1951 dr_jk = potential_parameter%cutoff_radius*cutoff_screen_factor
1952 dr_ik = potential_parameter%cutoff_radius*cutoff_screen_factor
1953 ELSEIF (op_jk == do_potential_coulomb)
THEN
1954 dr_jk = 1000000.0_dp
1955 dr_ik = 1000000.0_dp
1958 NULLIFY (qs_kind_set, atomic_kind_set)
1961 CALL get_qs_env(qs_env, atomic_kind_set=atomic_kind_set, qs_kind_set=qs_kind_set, &
1962 natom=natom, dft_control=dft_control, para_env=para_env, &
1963 particle_set=particle_set, cell=cell)
1966 nbasis =
SIZE(basis_i)
1971 DO ibasis = 1, nbasis
1972 CALL get_gto_basis_set(gto_basis_set=basis_i(ibasis)%gto_basis_set, maxl=
imax, &
1973 nset=iset, nsgf_set=nsgfi, npgf=npgfi)
1974 maxli = max(maxli,
imax)
1975 max_nset = max(max_nset, iset)
1976 max_nsgfi = max(max_nsgfi, maxval(nsgfi))
1977 max_ncoi = max(max_ncoi, maxval(npgfi)*
ncoset(maxli))
1982 DO ibasis = 1, nbasis
1983 CALL get_gto_basis_set(gto_basis_set=basis_j(ibasis)%gto_basis_set, maxl=
imax, &
1984 nset=jset, nsgf_set=nsgfj, npgf=npgfj)
1985 maxlj = max(maxlj,
imax)
1986 max_nset = max(max_nset, jset)
1987 max_nsgfj = max(max_nsgfj, maxval(nsgfj))
1988 max_ncoj = max(max_ncoj, maxval(npgfj)*
ncoset(maxlj))
1993 DO ibasis = 1, nbasis
1994 CALL get_gto_basis_set(gto_basis_set=basis_k(ibasis)%gto_basis_set, maxl=
imax, &
1995 nset=kset, nsgf_set=nsgfk, npgf=npgfk)
1996 maxlk = max(maxlk,
imax)
1997 max_nset = max(max_nset, kset)
1998 max_nsgfk = max(max_nsgfk, maxval(nsgfk))
1999 max_ncok = max(max_ncok, maxval(npgfk)*
ncoset(maxlk))
2001 m_max = maxli + maxlj + maxlk + 1
2006 NULLIFY (tspj, spi, spk)
2007 ALLOCATE (spi(max_nset, nbasis), tspj(max_nset, nbasis), spk(max_nset, nbasis))
2009 DO ibasis = 1, nbasis
2010 DO iset = 1, max_nset
2011 NULLIFY (spi(iset, ibasis)%array)
2012 NULLIFY (tspj(iset, ibasis)%array)
2014 NULLIFY (spk(iset, ibasis)%array)
2019 DO ibasis = 1, nbasis
2020 IF (ilist == 1) basis_set => basis_i(ibasis)%gto_basis_set
2021 IF (ilist == 2) basis_set => basis_j(ibasis)%gto_basis_set
2022 IF (ilist == 3) basis_set => basis_k(ibasis)%gto_basis_set
2024 DO iset = 1, basis_set%nset
2026 ncoi = basis_set%npgf(iset)*
ncoset(basis_set%lmax(iset))
2027 sgfi = basis_set%first_sgf(1, iset)
2028 egfi = sgfi + basis_set%nsgf_set(iset) - 1
2030 IF (ilist == 1)
THEN
2031 ALLOCATE (spi(iset, ibasis)%array(ncoi, basis_set%nsgf_set(iset)))
2032 spi(iset, ibasis)%array(:, :) = basis_set%sphi(1:ncoi, sgfi:egfi)
2034 ELSE IF (ilist == 2)
THEN
2035 ALLOCATE (tspj(iset, ibasis)%array(basis_set%nsgf_set(iset), ncoi))
2036 tspj(iset, ibasis)%array(:, :) = transpose(basis_set%sphi(1:ncoi, sgfi:egfi))
2039 ALLOCATE (spk(iset, ibasis)%array(ncoi, basis_set%nsgf_set(iset)))
2040 spk(iset, ibasis)%array(:, :) = basis_set%sphi(1:ncoi, sgfi:egfi)
2048 IF (op_ij == do_potential_truncated .OR. op_jk == do_potential_truncated)
THEN
2050 IF (m_max > get_lmax_init())
THEN
2051 IF (para_env%mepos == 0)
THEN
2052 CALL open_file(unit_number=unit_id, file_name=potential_parameter%filename)
2054 CALL init(m_max, unit_id, para_env%mepos, para_env)
2055 IF (para_env%mepos == 0)
THEN
2056 CALL close_file(unit_id)
2061 CALL init_md_ftable(nmax=m_max)
2085 CALL cp_libint_init_3eri1(lib, max(maxli, maxlj, maxlk))
2086 CALL cp_libint_set_contrdepth(lib, 1)
2089 ALLOCATE (cpp_buffer(max_nsgfj*max_ncok), ccp_buffer(max_nsgfj*max_nsgfk*max_ncoi))
2095 bo = get_limit(natom, nthread, mepos)
2096 CALL nl_3c_iter_set_bounds(nl_3c_iter, bounds_i=bo)
2099 IF (bo(1) > bo(2)) skip = .true.
2103 iatom=iatom, jatom=jatom, katom=katom, &
2104 rij=rij, rjk=rjk, rik=rik)
2107 CALL dbt_get_block(t3c_trace, [iatom, jatom, katom], tmp_block, found)
2108 IF (.NOT. found) cycle
2110 CALL get_gto_basis_set(basis_i(ikind)%gto_basis_set, first_sgf=first_sgf_i, lmax=lmax_i, lmin=lmin_i, &
2111 npgf=npgfi, nset=nseti, nsgf_set=nsgfi, pgf_radius=rpgf_i, set_radius=set_radius_i, &
2112 sphi=sphi_i, zet=zeti, kind_radius=kind_radius_i)
2114 CALL get_gto_basis_set(basis_j(jkind)%gto_basis_set, first_sgf=first_sgf_j, lmax=lmax_j, lmin=lmin_j, &
2115 npgf=npgfj, nset=nsetj, nsgf_set=nsgfj, pgf_radius=rpgf_j, set_radius=set_radius_j, &
2116 sphi=sphi_j, zet=zetj, kind_radius=kind_radius_j)
2118 CALL get_gto_basis_set(basis_k(kkind)%gto_basis_set, first_sgf=first_sgf_k, lmax=lmax_k, lmin=lmin_k, &
2119 npgf=npgfk, nset=nsetk, nsgf_set=nsgfk, pgf_radius=rpgf_k, set_radius=set_radius_k, &
2120 sphi=sphi_k, zet=zetk, kind_radius=kind_radius_k)
2126 IF (kind_radius_j + kind_radius_i + dr_ij < dij) cycle
2127 IF (kind_radius_j + kind_radius_k + dr_jk < djk) cycle
2128 IF (kind_radius_k + kind_radius_i + dr_ik < dik) cycle
2130 ALLOCATE (max_contraction_i(nseti))
2131 max_contraction_i = 0.0_dp
2133 sgfi = first_sgf_i(1, iset)
2134 max_contraction_i(iset) = maxval((/(sum(abs(sphi_i(:, i))), i=sgfi, sgfi + nsgfi(iset) - 1)/))
2137 ALLOCATE (max_contraction_j(nsetj))
2138 max_contraction_j = 0.0_dp
2140 sgfj = first_sgf_j(1, jset)
2141 max_contraction_j(jset) = maxval((/(sum(abs(sphi_j(:, i))), i=sgfj, sgfj + nsgfj(jset) - 1)/))
2144 ALLOCATE (max_contraction_k(nsetk))
2145 max_contraction_k = 0.0_dp
2147 sgfk = first_sgf_k(1, kset)
2148 max_contraction_k(kset) = maxval((/(sum(abs(sphi_k(:, i))), i=sgfk, sgfk + nsgfk(kset) - 1)/))
2151 CALL dbt_blk_sizes(t3c_trace, [iatom, jatom, katom], blk_size)
2153 ALLOCATE (block_t_i(blk_size(2), blk_size(3), blk_size(1), 3))
2154 ALLOCATE (block_t_j(blk_size(2), blk_size(3), blk_size(1), 3))
2155 ALLOCATE (block_t_k(blk_size(2), blk_size(3), blk_size(1), 3))
2157 ALLOCATE (ablock(blk_size(2), blk_size(3), blk_size(1)))
2158 DO i = 1, blk_size(1)
2159 ablock(:, :, i) = tmp_block(i, :, :)
2161 DEALLOCATE (tmp_block)
2166 block_j_not_zero = .false.
2167 block_k_not_zero = .false.
2173 IF (set_radius_j(jset) + set_radius_i(iset) + dr_ij < dij) cycle
2177 IF (set_radius_j(jset) + set_radius_k(kset) + dr_jk < djk) cycle
2178 IF (set_radius_k(kset) + set_radius_i(iset) + dr_ik < dik) cycle
2180 ncoi = npgfi(iset)*
ncoset(lmax_i(iset))
2181 ncoj = npgfj(jset)*
ncoset(lmax_j(jset))
2182 ncok = npgfk(kset)*
ncoset(lmax_k(kset))
2184 sgfi = first_sgf_i(1, iset)
2185 sgfj = first_sgf_j(1, jset)
2186 sgfk = first_sgf_k(1, kset)
2188 IF (ncoj*ncok*ncoi > 0)
THEN
2189 ALLOCATE (dijk_j(ncoj, ncok, ncoi, 3))
2190 ALLOCATE (dijk_k(ncoj, ncok, ncoi, 3))
2191 dijk_j(:, :, :, :) = 0.0_dp
2192 dijk_k(:, :, :, :) = 0.0_dp
2194 der_j_zero = .false.
2195 der_k_zero = .false.
2202 CALL eri_3center_derivs(dijk_j, dijk_k, &
2203 lmin_j(jset), lmax_j(jset), npgfj(jset), zetj(:, jset), rpgf_j(:, jset), rj, &
2204 lmin_k(kset), lmax_k(kset), npgfk(kset), zetk(:, kset), rpgf_k(:, kset), rk, &
2205 lmin_i(iset), lmax_i(iset), npgfi(iset), zeti(:, iset), rpgf_i(:, iset), ri, &
2206 djk, dij, dik, lib, potential_parameter, &
2207 der_abc_1_ext=der_ext_j, der_abc_2_ext=der_ext_k)
2209 IF (
PRESENT(der_eps))
THEN
2211 IF (der_eps > der_ext_j(i_xyz)*(max_contraction_i(iset)* &
2212 max_contraction_j(jset)* &
2213 max_contraction_k(kset)))
THEN
2214 der_j_zero(i_xyz) = .true.
2219 IF (der_eps > der_ext_k(i_xyz)*(max_contraction_i(iset)* &
2220 max_contraction_j(jset)* &
2221 max_contraction_k(kset)))
THEN
2222 der_k_zero(i_xyz) = .true.
2225 IF (all(der_j_zero) .AND. all(der_k_zero))
THEN
2226 DEALLOCATE (dijk_j, dijk_k)
2231 ALLOCATE (dijk_contr(nsgfj(jset), nsgfk(kset), nsgfi(iset)))
2233 block_start_j = sgfj
2234 block_end_j = sgfj + nsgfj(jset) - 1
2235 block_start_k = sgfk
2236 block_end_k = sgfk + nsgfk(kset) - 1
2237 block_start_i = sgfi
2238 block_end_i = sgfi + nsgfi(iset) - 1
2241 IF (der_j_zero(i_xyz)) cycle
2243 block_j_not_zero(i_xyz) = .true.
2244 CALL libxsmm_abc_contract(dijk_contr, dijk_j(:, :, :, i_xyz), tspj(jset, jkind)%array, &
2245 spk(kset, kkind)%array, spi(iset, ikind)%array, &
2246 ncoj, ncok, ncoi, nsgfj(jset), nsgfk(kset), &
2247 nsgfi(iset), cpp_buffer, ccp_buffer)
2249 block_t_j(block_start_j:block_end_j, &
2250 block_start_k:block_end_k, &
2251 block_start_i:block_end_i, i_xyz) = &
2252 block_t_j(block_start_j:block_end_j, &
2253 block_start_k:block_end_k, &
2254 block_start_i:block_end_i, i_xyz) + &
2260 IF (der_k_zero(i_xyz)) cycle
2262 block_k_not_zero(i_xyz) = .true.
2263 CALL libxsmm_abc_contract(dijk_contr, dijk_k(:, :, :, i_xyz), tspj(jset, jkind)%array, &
2264 spk(kset, kkind)%array, spi(iset, ikind)%array, &
2265 ncoj, ncok, ncoi, nsgfj(jset), nsgfk(kset), &
2266 nsgfi(iset), cpp_buffer, ccp_buffer)
2268 block_t_k(block_start_j:block_end_j, &
2269 block_start_k:block_end_k, &
2270 block_start_i:block_end_i, i_xyz) = &
2271 block_t_k(block_start_j:block_end_j, &
2272 block_start_k:block_end_k, &
2273 block_start_i:block_end_i, i_xyz) + &
2278 DEALLOCATE (dijk_j, dijk_k, dijk_contr)
2286 block_t_i(:, :, :, i_xyz) = -block_t_j(:, :, :, i_xyz) - block_t_k(:, :, :, i_xyz)
2291 force = pref*sum(ablock(:, :, :)*block_t_i(:, :, :, i_xyz))
2292 CALL real_to_scaled(scoord, particle_set(iatom)%r, cell)
2295 work_virial(i_xyz, j_xyz) = work_virial(i_xyz, j_xyz) + force*scoord(j_xyz)
2301 force = pref*sum(ablock(:, :, :)*block_t_j(:, :, :, i_xyz))
2302 CALL real_to_scaled(scoord, particle_set(iatom)%r + rij, cell)
2305 work_virial(i_xyz, j_xyz) = work_virial(i_xyz, j_xyz) + force*scoord(j_xyz)
2311 force = pref*sum(ablock(:, :, :)*block_t_k(:, :, :, i_xyz))
2312 CALL real_to_scaled(scoord, particle_set(iatom)%r + rik, cell)
2315 work_virial(i_xyz, j_xyz) = work_virial(i_xyz, j_xyz) + force*scoord(j_xyz)
2319 DEALLOCATE (block_t_i)
2320 DEALLOCATE (block_t_j)
2321 DEALLOCATE (block_t_k)
2323 DEALLOCATE (max_contraction_i, max_contraction_j, max_contraction_k, ablock)
2326 CALL cp_libint_cleanup_3eri1(lib)
2330 DO iset = 1, max_nset
2331 DO ibasis = 1, nbasis
2332 IF (
ASSOCIATED(spi(iset, ibasis)%array))
DEALLOCATE (spi(iset, ibasis)%array)
2333 IF (
ASSOCIATED(tspj(iset, ibasis)%array))
DEALLOCATE (tspj(iset, ibasis)%array)
2335 IF (
ASSOCIATED(spk(iset, ibasis)%array))
DEALLOCATE (spk(iset, ibasis)%array)
2339 DEALLOCATE (spi, tspj, spk)
2341 CALL timestop(handle)
2371 nl_3c, basis_i, basis_j, basis_k, &
2372 potential_parameter, int_eps, &
2373 op_pos, do_kpoints, do_hfx_kpoints, desymmetrize, &
2374 bounds_i, bounds_j, bounds_k, &
2375 RI_range, img_to_RI_cell)
2377 TYPE(dbt_type),
DIMENSION(:, :),
INTENT(INOUT) :: t3c
2378 REAL(kind=dp),
INTENT(IN) :: filter_eps
2379 TYPE(qs_environment_type),
POINTER :: qs_env
2380 TYPE(neighbor_list_3c_type),
INTENT(INOUT) :: nl_3c
2381 TYPE(gto_basis_set_p_type),
DIMENSION(:) :: basis_i, basis_j, basis_k
2382 TYPE(libint_potential_type),
INTENT(IN) :: potential_parameter
2383 REAL(kind=dp),
INTENT(IN),
OPTIONAL :: int_eps
2384 INTEGER,
INTENT(IN),
OPTIONAL :: op_pos
2385 LOGICAL,
INTENT(IN),
OPTIONAL :: do_kpoints, do_hfx_kpoints, desymmetrize
2386 INTEGER,
DIMENSION(2),
INTENT(IN),
OPTIONAL :: bounds_i, bounds_j, bounds_k
2387 REAL(dp),
INTENT(IN),
OPTIONAL :: ri_range
2388 INTEGER,
DIMENSION(:),
INTENT(IN),
OPTIONAL :: img_to_ri_cell
2390 CHARACTER(LEN=*),
PARAMETER :: routinen =
'build_3c_integrals'
2392 INTEGER :: block_end_i, block_end_j, block_end_k, block_start_i, block_start_j, &
2393 block_start_k, egfi, handle, handle2, i, iatom, ibasis, ikind, ilist,
imax, iset, jatom, &
2394 jcell, jkind, jset, katom, kcell, kkind, kset, m_max, max_ncoi, max_ncoj, max_ncok, &
2395 max_nset, max_nsgfi, max_nsgfj, max_nsgfk, maxli, maxlj, maxlk, mepos, natom, nbasis, &
2396 ncell_ri, ncoi, ncoj, ncok, nimg, nseti, nsetj, nsetk, nthread, op_ij, op_jk, op_pos_prv, &
2397 sgfi, sgfj, sgfk, unit_id
2398 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: img_to_ri_cell_prv
2399 INTEGER,
DIMENSION(2) :: bo
2400 INTEGER,
DIMENSION(3) :: blk_idx, blk_size, cell_j, cell_k, &
2401 kp_index_lbounds, kp_index_ubounds, sp
2402 INTEGER,
DIMENSION(:),
POINTER :: lmax_i, lmax_j, lmax_k, lmin_i, lmin_j, &
2403 lmin_k, npgfi, npgfj, npgfk, nsgfi, &
2405 INTEGER,
DIMENSION(:, :),
POINTER :: first_sgf_i, first_sgf_j, first_sgf_k
2406 INTEGER,
DIMENSION(:, :, :),
POINTER :: cell_to_index
2407 LOGICAL :: block_not_zero, debug, desymmetrize_prv, &
2408 do_hfx_kpoints_prv, do_kpoints_prv, &
2410 REAL(kind=dp) :: dij, dik, djk, dr_ij, dr_ik, dr_jk, &
2411 kind_radius_i, kind_radius_j, &
2412 kind_radius_k, max_contraction_i, &
2414 REAL(kind=dp),
ALLOCATABLE,
DIMENSION(:) :: ccp_buffer, cpp_buffer, &
2415 max_contraction_j, max_contraction_k
2416 REAL(kind=dp),
ALLOCATABLE,
DIMENSION(:, :, :) :: block_t, dummy_block_t, sijk, &
2418 REAL(kind=dp),
DIMENSION(1, 1, 1) :: counter
2419 REAL(kind=dp),
DIMENSION(3) :: ri, rij, rik, rj, rjk, rk
2420 REAL(kind=dp),
DIMENSION(:),
POINTER :: set_radius_i, set_radius_j, set_radius_k
2421 REAL(kind=dp),
DIMENSION(:, :),
POINTER :: rpgf_i, rpgf_j, rpgf_k, sphi_i, sphi_j, &
2422 sphi_k, zeti, zetj, zetk
2423 TYPE(atomic_kind_type),
DIMENSION(:),
POINTER :: atomic_kind_set
2424 TYPE(cell_type),
POINTER :: cell
2425 TYPE(cp_2d_r_p_type),
DIMENSION(:, :),
POINTER :: spi, spk, tspj
2426 TYPE(cp_libint_t) :: lib
2427 TYPE(dbt_type) :: t_3c_tmp
2428 TYPE(dft_control_type),
POINTER :: dft_control
2429 TYPE(gto_basis_set_type),
POINTER :: basis_set
2430 TYPE(kpoint_type),
POINTER :: kpoints
2431 TYPE(mp_para_env_type),
POINTER :: para_env
2432 TYPE(neighbor_list_3c_iterator_type) :: nl_3c_iter
2433 TYPE(qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
2435 CALL timeset(routinen, handle)
2439 IF (
PRESENT(do_kpoints))
THEN
2440 do_kpoints_prv = do_kpoints
2442 do_kpoints_prv = .false.
2445 IF (
PRESENT(do_hfx_kpoints))
THEN
2446 do_hfx_kpoints_prv = do_hfx_kpoints
2448 do_hfx_kpoints_prv = .false.
2450 IF (do_hfx_kpoints_prv)
THEN
2451 cpassert(do_kpoints_prv)
2452 cpassert(
PRESENT(ri_range))
2453 cpassert(
PRESENT(img_to_ri_cell))
2456 IF (
PRESENT(img_to_ri_cell))
THEN
2457 ALLOCATE (img_to_ri_cell_prv(
SIZE(img_to_ri_cell)))
2458 img_to_ri_cell_prv(:) = img_to_ri_cell
2461 IF (
PRESENT(desymmetrize))
THEN
2462 desymmetrize_prv = desymmetrize
2464 desymmetrize_prv = .true.
2467 op_ij = do_potential_id; op_jk = do_potential_id
2469 IF (
PRESENT(op_pos))
THEN
2475 SELECT CASE (op_pos_prv)
2477 op_ij = potential_parameter%potential_type
2479 op_jk = potential_parameter%potential_type
2482 dr_ij = 0.0_dp; dr_jk = 0.0_dp; dr_ik = 0.0_dp
2484 IF (op_ij == do_potential_truncated .OR. op_ij == do_potential_short)
THEN
2485 dr_ij = potential_parameter%cutoff_radius*cutoff_screen_factor
2486 dr_ik = potential_parameter%cutoff_radius*cutoff_screen_factor
2487 ELSEIF (op_ij == do_potential_coulomb)
THEN
2488 dr_ij = 1000000.0_dp
2489 dr_ik = 1000000.0_dp
2492 IF (op_jk == do_potential_truncated .OR. op_jk == do_potential_short)
THEN
2493 dr_jk = potential_parameter%cutoff_radius*cutoff_screen_factor
2494 dr_ik = potential_parameter%cutoff_radius*cutoff_screen_factor
2495 ELSEIF (op_jk == do_potential_coulomb)
THEN
2496 dr_jk = 1000000.0_dp
2497 dr_ik = 1000000.0_dp
2500 NULLIFY (qs_kind_set, atomic_kind_set)
2503 CALL get_qs_env(qs_env, atomic_kind_set=atomic_kind_set, qs_kind_set=qs_kind_set, cell=cell, &
2504 natom=natom, kpoints=kpoints, dft_control=dft_control, para_env=para_env)
2506 CALL alloc_block_3c(t3c, nl_3c, basis_i, basis_j, basis_k, qs_env, potential_parameter, &
2507 op_pos=op_pos_prv, do_kpoints=do_kpoints, do_hfx_kpoints=do_hfx_kpoints, &
2508 bounds_i=bounds_i, bounds_j=bounds_j, bounds_k=bounds_k, &
2509 ri_range=ri_range, img_to_ri_cell=img_to_ri_cell)
2511 IF (do_kpoints_prv)
THEN
2512 nimg = dft_control%nimages
2514 IF (do_hfx_kpoints_prv)
THEN
2516 ncell_ri =
SIZE(t3c, 2)
2518 CALL get_kpoint_info(kpoints, cell_to_index=cell_to_index)
2524 IF (do_hfx_kpoints_prv)
THEN
2525 cpassert(op_pos_prv == 2)
2526 cpassert(.NOT. desymmetrize_prv)
2527 ELSE IF (do_kpoints_prv)
THEN
2528 cpassert(all(shape(t3c) == [nimg, ncell_ri]))
2532 nbasis =
SIZE(basis_i)
2537 DO ibasis = 1, nbasis
2538 CALL get_gto_basis_set(gto_basis_set=basis_i(ibasis)%gto_basis_set, maxl=
imax, &
2539 nset=iset, nsgf_set=nsgfi, npgf=npgfi)
2540 maxli = max(maxli,
imax)
2541 max_nset = max(max_nset, iset)
2542 max_nsgfi = max(max_nsgfi, maxval(nsgfi))
2543 max_ncoi = max(max_ncoi, maxval(npgfi)*
ncoset(maxli))
2548 DO ibasis = 1, nbasis
2549 CALL get_gto_basis_set(gto_basis_set=basis_j(ibasis)%gto_basis_set, maxl=
imax, &
2550 nset=jset, nsgf_set=nsgfj, npgf=npgfj)
2551 maxlj = max(maxlj,
imax)
2552 max_nset = max(max_nset, jset)
2553 max_nsgfj = max(max_nsgfj, maxval(nsgfj))
2554 max_ncoj = max(max_ncoj, maxval(npgfj)*
ncoset(maxlj))
2559 DO ibasis = 1, nbasis
2560 CALL get_gto_basis_set(gto_basis_set=basis_k(ibasis)%gto_basis_set, maxl=
imax, &
2561 nset=kset, nsgf_set=nsgfk, npgf=npgfk)
2562 maxlk = max(maxlk,
imax)
2563 max_nset = max(max_nset, kset)
2564 max_nsgfk = max(max_nsgfk, maxval(nsgfk))
2565 max_ncok = max(max_ncok, maxval(npgfk)*
ncoset(maxlk))
2567 m_max = maxli + maxlj + maxlk
2572 NULLIFY (tspj, spi, spk)
2573 ALLOCATE (spi(max_nset, nbasis), tspj(max_nset, nbasis), spk(max_nset, nbasis))
2575 DO ibasis = 1, nbasis
2576 DO iset = 1, max_nset
2577 NULLIFY (spi(iset, ibasis)%array)
2578 NULLIFY (tspj(iset, ibasis)%array)
2580 NULLIFY (spk(iset, ibasis)%array)
2585 DO ibasis = 1, nbasis
2586 IF (ilist == 1) basis_set => basis_i(ibasis)%gto_basis_set
2587 IF (ilist == 2) basis_set => basis_j(ibasis)%gto_basis_set
2588 IF (ilist == 3) basis_set => basis_k(ibasis)%gto_basis_set
2590 DO iset = 1, basis_set%nset
2592 ncoi = basis_set%npgf(iset)*
ncoset(basis_set%lmax(iset))
2593 sgfi = basis_set%first_sgf(1, iset)
2594 egfi = sgfi + basis_set%nsgf_set(iset) - 1
2596 IF (ilist == 1)
THEN
2597 ALLOCATE (spi(iset, ibasis)%array(ncoi, basis_set%nsgf_set(iset)))
2598 spi(iset, ibasis)%array(:, :) = basis_set%sphi(1:ncoi, sgfi:egfi)
2600 ELSE IF (ilist == 2)
THEN
2601 ALLOCATE (tspj(iset, ibasis)%array(basis_set%nsgf_set(iset), ncoi))
2602 tspj(iset, ibasis)%array(:, :) = transpose(basis_set%sphi(1:ncoi, sgfi:egfi))
2605 ALLOCATE (spk(iset, ibasis)%array(ncoi, basis_set%nsgf_set(iset)))
2606 spk(iset, ibasis)%array(:, :) = basis_set%sphi(1:ncoi, sgfi:egfi)
2614 IF (op_ij == do_potential_truncated .OR. op_jk == do_potential_truncated)
THEN
2616 IF (m_max > get_lmax_init())
THEN
2617 IF (para_env%mepos == 0)
THEN
2618 CALL open_file(unit_number=unit_id, file_name=potential_parameter%filename)
2620 CALL init(m_max, unit_id, para_env%mepos, para_env)
2621 IF (para_env%mepos == 0)
THEN
2622 CALL close_file(unit_id)
2627 CALL init_md_ftable(nmax=m_max)
2629 IF (do_kpoints_prv)
THEN
2630 kp_index_lbounds = lbound(cell_to_index)
2631 kp_index_ubounds = ubound(cell_to_index)
2658 CALL cp_libint_init_3eri(lib, max(maxli, maxlj, maxlk))
2659 CALL cp_libint_set_contrdepth(lib, 1)
2662 ALLOCATE (cpp_buffer(max_nsgfj*max_ncok), ccp_buffer(max_nsgfj*max_nsgfk*max_ncoi))
2667 IF (
PRESENT(bounds_i))
THEN
2668 bo = get_limit(bounds_i(2) - bounds_i(1) + 1, nthread, mepos)
2669 bo(:) = bo(:) + bounds_i(1) - 1
2670 CALL nl_3c_iter_set_bounds(nl_3c_iter, bo, bounds_j, bounds_k)
2671 ELSE IF (
PRESENT(bounds_j))
THEN
2673 bo = get_limit(bounds_j(2) - bounds_j(1) + 1, nthread, mepos)
2674 bo(:) = bo(:) + bounds_j(1) - 1
2675 CALL nl_3c_iter_set_bounds(nl_3c_iter, bounds_i, bo, bounds_k)
2676 ELSE IF (
PRESENT(bounds_k))
THEN
2677 bo = get_limit(bounds_k(2) - bounds_k(1) + 1, nthread, mepos)
2678 bo(:) = bo(:) + bounds_k(1) - 1
2679 CALL nl_3c_iter_set_bounds(nl_3c_iter, bounds_i, bounds_j, bo)
2681 bo = get_limit(natom, nthread, mepos)
2682 CALL nl_3c_iter_set_bounds(nl_3c_iter, bo, bounds_j, bounds_k)
2686 IF (bo(1) > bo(2)) skip = .true.
2690 iatom=iatom, jatom=jatom, katom=katom, &
2691 rij=rij, rjk=rjk, rik=rik, cell_j=cell_j, cell_k=cell_k)
2698 IF (do_kpoints_prv)
THEN
2700 ELSEIF (nl_3c%sym == symmetric_jk)
THEN
2701 IF (jatom == katom)
THEN
2708 ELSEIF (nl_3c%sym == symmetric_ij)
THEN
2709 IF (iatom == jatom)
THEN
2719 IF (do_hfx_kpoints_prv) prefac = 1.0_dp
2721 IF (do_kpoints_prv)
THEN
2723 IF (any([cell_j(1), cell_j(2), cell_j(3)] < kp_index_lbounds) .OR. &
2724 any([cell_j(1), cell_j(2), cell_j(3)] > kp_index_ubounds)) cycle
2726 jcell = cell_to_index(cell_j(1), cell_j(2), cell_j(3))
2727 IF (jcell > nimg .OR. jcell < 1) cycle
2729 IF (any([cell_k(1), cell_k(2), cell_k(3)] < kp_index_lbounds) .OR. &
2730 any([cell_k(1), cell_k(2), cell_k(3)] > kp_index_ubounds)) cycle
2732 kcell = cell_to_index(cell_k(1), cell_k(2), cell_k(3))
2733 IF (kcell > nimg .OR. kcell < 1) cycle
2735 IF (do_hfx_kpoints_prv)
THEN
2736 IF (dik > ri_range) cycle
2737 kcell = img_to_ri_cell_prv(kcell)
2740 jcell = 1; kcell = 1
2743 blk_idx = [iatom, jatom, katom]
2744 IF (do_hfx_kpoints_prv)
THEN
2745 blk_idx(3) = (kcell - 1)*natom + katom
2749 CALL get_gto_basis_set(basis_i(ikind)%gto_basis_set, first_sgf=first_sgf_i, lmax=lmax_i, lmin=lmin_i, &
2750 npgf=npgfi, nset=nseti, nsgf_set=nsgfi, pgf_radius=rpgf_i, set_radius=set_radius_i, &
2751 sphi=sphi_i, zet=zeti, kind_radius=kind_radius_i)
2753 CALL get_gto_basis_set(basis_j(jkind)%gto_basis_set, first_sgf=first_sgf_j, lmax=lmax_j, lmin=lmin_j, &
2754 npgf=npgfj, nset=nsetj, nsgf_set=nsgfj, pgf_radius=rpgf_j, set_radius=set_radius_j, &
2755 sphi=sphi_j, zet=zetj, kind_radius=kind_radius_j)
2757 CALL get_gto_basis_set(basis_k(kkind)%gto_basis_set, first_sgf=first_sgf_k, lmax=lmax_k, lmin=lmin_k, &
2758 npgf=npgfk, nset=nsetk, nsgf_set=nsgfk, pgf_radius=rpgf_k, set_radius=set_radius_k, &
2759 sphi=sphi_k, zet=zetk, kind_radius=kind_radius_k)
2761 IF (kind_radius_j + kind_radius_i + dr_ij < dij) cycle
2762 IF (kind_radius_j + kind_radius_k + dr_jk < djk) cycle
2763 IF (kind_radius_k + kind_radius_i + dr_ik < dik) cycle
2765 ALLOCATE (max_contraction_j(nsetj))
2767 sgfj = first_sgf_j(1, jset)
2768 max_contraction_j(jset) = maxval((/(sum(abs(sphi_j(:, i))), i=sgfj, sgfj + nsgfj(jset) - 1)/))
2771 ALLOCATE (max_contraction_k(nsetk))
2773 sgfk = first_sgf_k(1, kset)
2774 max_contraction_k(kset) = maxval((/(sum(abs(sphi_k(:, i))), i=sgfk, sgfk + nsgfk(kset) - 1)/))
2777 CALL dbt_blk_sizes(t3c(jcell, kcell), blk_idx, blk_size)
2779 ALLOCATE (block_t(blk_size(2), blk_size(3), blk_size(1)))
2782 block_not_zero = .false.
2785 sgfi = first_sgf_i(1, iset)
2786 max_contraction_i = maxval((/(sum(abs(sphi_i(:, i))), i=sgfi, sgfi + nsgfi(iset) - 1)/))
2790 IF (set_radius_j(jset) + set_radius_i(iset) + dr_ij < dij) cycle
2794 IF (set_radius_j(jset) + set_radius_k(kset) + dr_jk < djk) cycle
2795 IF (set_radius_k(kset) + set_radius_i(iset) + dr_ik < dik) cycle
2797 ncoi = npgfi(iset)*
ncoset(lmax_i(iset))
2798 ncoj = npgfj(jset)*
ncoset(lmax_j(jset))
2799 ncok = npgfk(kset)*
ncoset(lmax_k(kset))
2802 IF (ncoj*ncok*ncoi == 0) cycle
2809 ALLOCATE (sijk(ncoj, ncok, ncoi))
2810 IF (op_pos_prv == 1)
THEN
2811 sijk(:, :, :) = 0.0_dp
2812 CALL eri_3center(sijk, &
2813 lmin_j(jset), lmax_j(jset), npgfj(jset), zetj(:, jset), rpgf_j(:, jset), rj, &
2814 lmin_k(kset), lmax_k(kset), npgfk(kset), zetk(:, kset), rpgf_k(:, kset), rk, &
2815 lmin_i(iset), lmax_i(iset), npgfi(iset), zeti(:, iset), rpgf_i(:, iset), ri, &
2816 djk, dij, dik, lib, potential_parameter, int_abc_ext=sijk_ext)
2818 ALLOCATE (tmp_ijk(ncoi, ncoj, ncok))
2819 tmp_ijk(:, :, :) = 0.0_dp
2820 CALL eri_3center(tmp_ijk, &
2821 lmin_i(iset), lmax_i(iset), npgfi(iset), zeti(:, iset), rpgf_i(:, iset), ri, &
2822 lmin_j(jset), lmax_j(jset), npgfj(jset), zetj(:, jset), rpgf_j(:, jset), rj, &
2823 lmin_k(kset), lmax_k(kset), npgfk(kset), zetk(:, kset), rpgf_k(:, kset), rk, &
2824 dij, dik, djk, lib, potential_parameter, int_abc_ext=sijk_ext)
2828 sijk(:, :, i) = tmp_ijk(i, :, :)
2830 DEALLOCATE (tmp_ijk)
2833 IF (
PRESENT(int_eps))
THEN
2834 IF (int_eps > sijk_ext*(max_contraction_i* &
2835 max_contraction_j(jset)* &
2836 max_contraction_k(kset)))
THEN
2842 block_not_zero = .true.
2843 ALLOCATE (sijk_contr(nsgfj(jset), nsgfk(kset), nsgfi(iset)))
2844 CALL libxsmm_abc_contract(sijk_contr, sijk, tspj(jset, jkind)%array, &
2845 spk(kset, kkind)%array, spi(iset, ikind)%array, &
2846 ncoj, ncok, ncoi, nsgfj(jset), nsgfk(kset), &
2847 nsgfi(iset), cpp_buffer, ccp_buffer)
2850 sgfj = first_sgf_j(1, jset)
2851 sgfk = first_sgf_k(1, kset)
2853 block_start_j = sgfj
2854 block_end_j = sgfj + nsgfj(jset) - 1
2855 block_start_k = sgfk
2856 block_end_k = sgfk + nsgfk(kset) - 1
2857 block_start_i = sgfi
2858 block_end_i = sgfi + nsgfi(iset) - 1
2860 block_t(block_start_j:block_end_j, &
2861 block_start_k:block_end_k, &
2862 block_start_i:block_end_i) = &
2863 block_t(block_start_j:block_end_j, &
2864 block_start_k:block_end_k, &
2865 block_start_i:block_end_i) + &
2866 prefac*sijk_contr(:, :, :)
2867 DEALLOCATE (sijk_contr)
2875 IF (block_not_zero)
THEN
2877 CALL timeset(routinen//
"_put_dbcsr", handle2)
2879 CALL dbt_get_block(t3c(jcell, kcell), blk_idx, dummy_block_t, found=found)
2886 CALL dbt_put_block(t3c(jcell, kcell), blk_idx, sp, &
2887 reshape(block_t, shape=sp, order=[2, 3, 1]), summation=.true.)
2889 CALL timestop(handle2)
2893 DEALLOCATE (block_t)
2894 DEALLOCATE (max_contraction_j, max_contraction_k)
2897 CALL cp_libint_cleanup_3eri(lib)
2903 IF (nl_3c%sym == symmetric_jk .OR. do_kpoints_prv)
THEN
2905 IF (.NOT. do_hfx_kpoints_prv)
THEN
2909 CALL dbt_filter(t3c(jcell, kcell), filter_eps/2)
2913 DO kcell = 1, ncell_ri
2915 CALL dbt_filter(t3c(jcell, kcell), filter_eps)
2920 IF (desymmetrize_prv)
THEN
2922 CALL dbt_create(t3c(1, 1), t_3c_tmp)
2925 CALL dbt_copy(t3c(jcell, kcell), t_3c_tmp)
2926 CALL dbt_copy(t_3c_tmp, t3c(kcell, jcell), order=[1, 3, 2], summation=.true., move_data=.true.)
2927 CALL dbt_filter(t3c(kcell, jcell), filter_eps)
2930 DO kcell = jcell + 1, nimg
2932 CALL dbt_copy(t3c(jcell, kcell), t_3c_tmp)
2933 CALL dbt_copy(t_3c_tmp, t3c(kcell, jcell), order=[1, 3, 2], summation=.false., move_data=.true.)
2934 CALL dbt_filter(t3c(kcell, jcell), filter_eps)
2937 CALL dbt_destroy(t_3c_tmp)
2939 ELSEIF (nl_3c%sym == symmetric_ij)
THEN
2942 CALL dbt_filter(t3c(jcell, kcell), filter_eps/2)
2945 ELSEIF (nl_3c%sym == symmetric_none)
THEN
2948 CALL dbt_filter(t3c(jcell, kcell), filter_eps)
2952 cpabort(
"requested symmetric case not implemented")
2955 DO iset = 1, max_nset
2956 DO ibasis = 1, nbasis
2957 IF (
ASSOCIATED(spi(iset, ibasis)%array))
DEALLOCATE (spi(iset, ibasis)%array)
2958 IF (
ASSOCIATED(tspj(iset, ibasis)%array))
DEALLOCATE (tspj(iset, ibasis)%array)
2960 IF (
ASSOCIATED(spk(iset, ibasis)%array))
DEALLOCATE (spk(iset, ibasis)%array)
2963 DEALLOCATE (spi, tspj, spk)
2965 CALL timestop(handle)
2981 nl_2c, basis_i, basis_j, &
2982 potential_parameter, do_kpoints)
2984 TYPE(dbcsr_type),
DIMENSION(:, :),
INTENT(INOUT) :: t2c_der
2985 REAL(kind=dp),
INTENT(IN) :: filter_eps
2986 TYPE(qs_environment_type),
POINTER :: qs_env
2987 TYPE(neighbor_list_set_p_type),
DIMENSION(:), &
2989 TYPE(gto_basis_set_p_type),
DIMENSION(:) :: basis_i, basis_j
2990 TYPE(libint_potential_type),
INTENT(IN) :: potential_parameter
2991 LOGICAL,
INTENT(IN),
OPTIONAL :: do_kpoints
2993 CHARACTER(len=*),
PARAMETER :: routinen =
'build_2c_derivatives'
2995 INTEGER :: handle, i_xyz, iatom, ibasis, icol, ikind,
imax, img, irow, iset, jatom, jkind, &
2996 jset, m_max, maxli, maxlj, natom, ncoi, ncoj, nimg, nseti, nsetj, op_prv, sgfi, sgfj, &
2998 INTEGER,
DIMENSION(3) :: cell_j, kp_index_lbounds, &
3000 INTEGER,
DIMENSION(:),
POINTER :: lmax_i, lmax_j, lmin_i, lmin_j, npgfi, &
3002 INTEGER,
DIMENSION(:, :),
POINTER :: first_sgf_i, first_sgf_j
3003 INTEGER,
DIMENSION(:, :, :),
POINTER :: cell_to_index
3004 LOGICAL :: do_kpoints_prv, do_symmetric, found, &
3006 REAL(kind=dp) :: dab
3007 REAL(kind=dp),
ALLOCATABLE,
DIMENSION(:, :) :: dij_contr, dij_rs
3008 REAL(kind=dp),
ALLOCATABLE,
DIMENSION(:, :, :) :: dij
3009 REAL(kind=dp),
DIMENSION(3) :: ri, rij, rj
3010 REAL(kind=dp),
DIMENSION(:),
POINTER :: set_radius_i, set_radius_j
3011 REAL(kind=dp),
DIMENSION(:, :),
POINTER :: rpgf_i, rpgf_j, sphi_i, sphi_j, zeti, &
3013 TYPE(atomic_kind_type),
DIMENSION(:),
POINTER :: atomic_kind_set
3014 TYPE(block_p_type),
DIMENSION(3) :: block_t
3015 TYPE(cp_libint_t) :: lib
3016 TYPE(dft_control_type),
POINTER :: dft_control
3017 TYPE(kpoint_type),
POINTER :: kpoints
3018 TYPE(mp_para_env_type),
POINTER :: para_env
3019 TYPE(neighbor_list_iterator_p_type), &
3020 DIMENSION(:),
POINTER :: nl_iterator
3021 TYPE(qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
3023 CALL timeset(routinen, handle)
3025 IF (
PRESENT(do_kpoints))
THEN
3026 do_kpoints_prv = do_kpoints
3028 do_kpoints_prv = .false.
3031 op_prv = potential_parameter%potential_type
3033 NULLIFY (qs_kind_set, atomic_kind_set, block_t(1)%block, block_t(2)%block, block_t(3)%block, cell_to_index)
3036 CALL get_qs_env(qs_env, atomic_kind_set=atomic_kind_set, qs_kind_set=qs_kind_set, &
3037 natom=natom, kpoints=kpoints, dft_control=dft_control, para_env=para_env)
3039 IF (do_kpoints_prv)
THEN
3040 nimg =
SIZE(t2c_der, 1)
3041 CALL get_kpoint_info(kpoints, cell_to_index=cell_to_index)
3042 kp_index_lbounds = lbound(cell_to_index)
3043 kp_index_ubounds = ubound(cell_to_index)
3049 cpassert(
SIZE(nl_2c) > 0)
3050 CALL get_neighbor_list_set_p(neighbor_list_sets=nl_2c, symmetric=do_symmetric)
3052 IF (do_symmetric)
THEN
3056 cpassert(dbcsr_get_matrix_type(t2c_der(img, i_xyz)) == dbcsr_type_antisymmetric)
3062 cpassert(dbcsr_get_matrix_type(t2c_der(img, i_xyz)) == dbcsr_type_no_symmetry)
3069 CALL cp_dbcsr_alloc_block_from_nbl(t2c_der(img, i_xyz), nl_2c)
3074 DO ibasis = 1,
SIZE(basis_i)
3075 CALL get_gto_basis_set(gto_basis_set=basis_i(ibasis)%gto_basis_set, maxl=
imax)
3076 maxli = max(maxli,
imax)
3079 DO ibasis = 1,
SIZE(basis_j)
3080 CALL get_gto_basis_set(gto_basis_set=basis_j(ibasis)%gto_basis_set, maxl=
imax)
3081 maxlj = max(maxlj,
imax)
3084 m_max = maxli + maxlj + 1
3087 IF (op_prv == do_potential_truncated)
THEN
3089 IF (m_max > get_lmax_init())
THEN
3090 IF (para_env%mepos == 0)
THEN
3091 CALL open_file(unit_number=unit_id, file_name=potential_parameter%filename)
3093 CALL init(m_max, unit_id, para_env%mepos, para_env)
3094 IF (para_env%mepos == 0)
THEN
3095 CALL close_file(unit_id)
3100 CALL init_md_ftable(nmax=m_max)
3102 CALL cp_libint_init_2eri1(lib, max(maxli, maxlj))
3103 CALL cp_libint_set_contrdepth(lib, 1)
3105 CALL neighbor_list_iterator_create(nl_iterator, nl_2c)
3106 DO WHILE (neighbor_list_iterate(nl_iterator) == 0)
3108 CALL get_iterator_info(nl_iterator, ikind=ikind, jkind=jkind, &
3109 iatom=iatom, jatom=jatom, r=rij, cell=cell_j)
3110 IF (do_kpoints_prv)
THEN
3111 IF (any([cell_j(1), cell_j(2), cell_j(3)] < kp_index_lbounds) .OR. &
3112 any([cell_j(1), cell_j(2), cell_j(3)] > kp_index_ubounds)) cycle
3113 img = cell_to_index(cell_j(1), cell_j(2), cell_j(3))
3114 IF (img > nimg .OR. img < 1) cycle
3119 CALL get_gto_basis_set(basis_i(ikind)%gto_basis_set, first_sgf=first_sgf_i, lmax=lmax_i, lmin=lmin_i, &
3120 npgf=npgfi, nset=nseti, nsgf_set=nsgfi, pgf_radius=rpgf_i, set_radius=set_radius_i, &
3121 sphi=sphi_i, zet=zeti)
3123 CALL get_gto_basis_set(basis_j(jkind)%gto_basis_set, first_sgf=first_sgf_j, lmax=lmax_j, lmin=lmin_j, &
3124 npgf=npgfj, nset=nsetj, nsgf_set=nsgfj, pgf_radius=rpgf_j, set_radius=set_radius_j, &
3125 sphi=sphi_j, zet=zetj)
3127 IF (do_symmetric)
THEN
3128 IF (iatom <= jatom)
THEN
3141 trans = do_symmetric .AND. (iatom > jatom)
3144 CALL dbcsr_get_block_p(matrix=t2c_der(img, i_xyz), &
3145 row=irow, col=icol, block=block_t(i_xyz)%block, found=found)
3151 ncoi = npgfi(iset)*
ncoset(lmax_i(iset))
3152 sgfi = first_sgf_i(1, iset)
3156 ncoj = npgfj(jset)*
ncoset(lmax_j(jset))
3157 sgfj = first_sgf_j(1, jset)
3159 IF (ncoi*ncoj > 0)
THEN
3160 ALLOCATE (dij_contr(nsgfi(iset), nsgfj(jset)))
3161 ALLOCATE (dij(ncoi, ncoj, 3))
3162 dij(:, :, :) = 0.0_dp
3167 CALL eri_2center_derivs(dij, lmin_i(iset), lmax_i(iset), npgfi(iset), zeti(:, iset), &
3168 rpgf_i(:, iset), ri, lmin_j(jset), lmax_j(jset), npgfj(jset), zetj(:, jset), &
3169 rpgf_j(:, jset), rj, dab, lib, potential_parameter)
3173 dij_contr(:, :) = 0.0_dp
3174 CALL ab_contract(dij_contr, dij(:, :, i_xyz), &
3175 sphi_i(:, sgfi:), sphi_j(:, sgfj:), &
3176 ncoi, ncoj, nsgfi(iset), nsgfj(jset))
3180 ALLOCATE (dij_rs(nsgfj(jset), nsgfi(iset)))
3181 dij_rs(:, :) = -1.0_dp*transpose(dij_contr)
3183 ALLOCATE (dij_rs(nsgfi(iset), nsgfj(jset)))
3184 dij_rs(:, :) = dij_contr
3187 CALL block_add(
"IN", dij_rs, &
3188 nsgfi(iset), nsgfj(jset), block_t(i_xyz)%block, &
3189 sgfi, sgfj, trans=trans)
3193 DEALLOCATE (dij, dij_contr)
3199 CALL cp_libint_cleanup_2eri1(lib)
3201 CALL neighbor_list_iterator_release(nl_iterator)
3204 CALL dbcsr_finalize(t2c_der(img, i_xyz))
3205 CALL dbcsr_filter(t2c_der(img, i_xyz), filter_eps)
3209 CALL timestop(handle)
3225 SUBROUTINE calc_2c_virial(work_virial, t2c_trace, pref, qs_env, nl_2c, basis_i, basis_j, potential_parameter)
3226 REAL(dp),
DIMENSION(3, 3),
INTENT(INOUT) :: work_virial
3227 TYPE(dbcsr_type),
INTENT(INOUT) :: t2c_trace
3228 REAL(kind=dp),
INTENT(IN) :: pref
3229 TYPE(qs_environment_type),
POINTER :: qs_env
3230 TYPE(neighbor_list_set_p_type),
DIMENSION(:), &
3232 TYPE(gto_basis_set_p_type),
DIMENSION(:) :: basis_i, basis_j
3233 TYPE(libint_potential_type),
INTENT(IN) :: potential_parameter
3235 CHARACTER(len=*),
PARAMETER :: routinen =
'calc_2c_virial'
3237 INTEGER :: handle, i_xyz, iatom, ibasis, ikind,
imax, iset, j_xyz, jatom, jkind, jset, &
3238 m_max, maxli, maxlj, natom, ncoi, ncoj, nseti, nsetj, op_prv, sgfi, sgfj, unit_id
3239 INTEGER,
DIMENSION(:),
POINTER :: lmax_i, lmax_j, lmin_i, lmin_j, npgfi, &
3241 INTEGER,
DIMENSION(:, :),
POINTER :: first_sgf_i, first_sgf_j
3242 LOGICAL :: do_symmetric, found
3244 REAL(dp),
DIMENSION(:, :),
POINTER :: pblock
3245 REAL(kind=dp) :: dab
3246 REAL(kind=dp),
ALLOCATABLE,
DIMENSION(:, :) :: dij_contr
3247 REAL(kind=dp),
ALLOCATABLE,
DIMENSION(:, :, :) :: dij
3248 REAL(kind=dp),
DIMENSION(3) :: ri, rij, rj, scoord
3249 REAL(kind=dp),
DIMENSION(:),
POINTER :: set_radius_i, set_radius_j
3250 REAL(kind=dp),
DIMENSION(:, :),
POINTER :: rpgf_i, rpgf_j, sphi_i, sphi_j, zeti, &
3252 TYPE(atomic_kind_type),
DIMENSION(:),
POINTER :: atomic_kind_set
3253 TYPE(cell_type),
POINTER :: cell
3254 TYPE(cp_libint_t) :: lib
3255 TYPE(dft_control_type),
POINTER :: dft_control
3256 TYPE(mp_para_env_type),
POINTER :: para_env
3257 TYPE(neighbor_list_iterator_p_type), &
3258 DIMENSION(:),
POINTER :: nl_iterator
3259 TYPE(particle_type),
DIMENSION(:),
POINTER :: particle_set
3260 TYPE(qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
3262 CALL timeset(routinen, handle)
3264 op_prv = potential_parameter%potential_type
3266 NULLIFY (qs_kind_set, atomic_kind_set, pblock, particle_set, cell)
3269 CALL get_qs_env(qs_env, atomic_kind_set=atomic_kind_set, qs_kind_set=qs_kind_set, &
3270 natom=natom, dft_control=dft_control, para_env=para_env, &
3271 particle_set=particle_set, cell=cell)
3274 cpassert(
SIZE(nl_2c) > 0)
3275 CALL get_neighbor_list_set_p(neighbor_list_sets=nl_2c, symmetric=do_symmetric)
3276 cpassert(.NOT. do_symmetric)
3279 DO ibasis = 1,
SIZE(basis_i)
3280 CALL get_gto_basis_set(gto_basis_set=basis_i(ibasis)%gto_basis_set, maxl=
imax)
3281 maxli = max(maxli,
imax)
3284 DO ibasis = 1,
SIZE(basis_j)
3285 CALL get_gto_basis_set(gto_basis_set=basis_j(ibasis)%gto_basis_set, maxl=
imax)
3286 maxlj = max(maxlj,
imax)
3289 m_max = maxli + maxlj + 1
3292 IF (op_prv == do_potential_truncated)
THEN
3294 IF (m_max > get_lmax_init())
THEN
3295 IF (para_env%mepos == 0)
THEN
3296 CALL open_file(unit_number=unit_id, file_name=potential_parameter%filename)
3298 CALL init(m_max, unit_id, para_env%mepos, para_env)
3299 IF (para_env%mepos == 0)
THEN
3300 CALL close_file(unit_id)
3305 CALL init_md_ftable(nmax=m_max)
3307 CALL cp_libint_init_2eri1(lib, max(maxli, maxlj))
3308 CALL cp_libint_set_contrdepth(lib, 1)
3310 CALL neighbor_list_iterator_create(nl_iterator, nl_2c)
3311 DO WHILE (neighbor_list_iterate(nl_iterator) == 0)
3313 CALL get_iterator_info(nl_iterator, ikind=ikind, jkind=jkind, &
3314 iatom=iatom, jatom=jatom, r=rij)
3316 CALL get_gto_basis_set(basis_i(ikind)%gto_basis_set, first_sgf=first_sgf_i, lmax=lmax_i, lmin=lmin_i, &
3317 npgf=npgfi, nset=nseti, nsgf_set=nsgfi, pgf_radius=rpgf_i, set_radius=set_radius_i, &
3318 sphi=sphi_i, zet=zeti)
3320 CALL get_gto_basis_set(basis_j(jkind)%gto_basis_set, first_sgf=first_sgf_j, lmax=lmax_j, lmin=lmin_j, &
3321 npgf=npgfj, nset=nsetj, nsgf_set=nsgfj, pgf_radius=rpgf_j, set_radius=set_radius_j, &
3322 sphi=sphi_j, zet=zetj)
3326 CALL dbcsr_get_block_p(t2c_trace, iatom, jatom, pblock, found)
3327 IF (.NOT. found) cycle
3331 ncoi = npgfi(iset)*
ncoset(lmax_i(iset))
3332 sgfi = first_sgf_i(1, iset)
3336 ncoj = npgfj(jset)*
ncoset(lmax_j(jset))
3337 sgfj = first_sgf_j(1, jset)
3339 IF (ncoi*ncoj > 0)
THEN
3340 ALLOCATE (dij_contr(nsgfi(iset), nsgfj(jset)))
3341 ALLOCATE (dij(ncoi, ncoj, 3))
3342 dij(:, :, :) = 0.0_dp
3347 CALL eri_2center_derivs(dij, lmin_i(iset), lmax_i(iset), npgfi(iset), zeti(:, iset), &
3348 rpgf_i(:, iset), ri, lmin_j(jset), lmax_j(jset), npgfj(jset), zetj(:, jset), &
3349 rpgf_j(:, jset), rj, dab, lib, potential_parameter)
3353 dij_contr(:, :) = 0.0_dp
3354 CALL ab_contract(dij_contr, dij(:, :, i_xyz), &
3355 sphi_i(:, sgfi:), sphi_j(:, sgfj:), &
3356 ncoi, ncoj, nsgfi(iset), nsgfj(jset))
3358 force = sum(pblock(sgfi:sgfi + nsgfi(iset) - 1, sgfj:sgfj + nsgfj(jset) - 1)*dij_contr(:, :))
3362 CALL real_to_scaled(scoord, particle_set(iatom)%r, cell)
3364 work_virial(i_xyz, j_xyz) = work_virial(i_xyz, j_xyz) + force*scoord(j_xyz)
3368 CALL real_to_scaled(scoord, particle_set(iatom)%r + rij, cell)
3370 work_virial(i_xyz, j_xyz) = work_virial(i_xyz, j_xyz) - force*scoord(j_xyz)
3374 DEALLOCATE (dij, dij_contr)
3379 CALL neighbor_list_iterator_release(nl_iterator)
3381 CALL cp_libint_cleanup_2eri1(lib)
3383 CALL timestop(handle)
3403 nl_2c, basis_i, basis_j, &
3404 potential_parameter, do_kpoints, &
3405 do_hfx_kpoints, ext_kpoints, regularization_RI)
3407 TYPE(dbcsr_type),
DIMENSION(:),
INTENT(INOUT) :: t2c
3408 REAL(kind=dp),
INTENT(IN) :: filter_eps
3409 TYPE(qs_environment_type),
POINTER :: qs_env
3410 TYPE(neighbor_list_set_p_type),
DIMENSION(:), &
3412 TYPE(gto_basis_set_p_type),
DIMENSION(:) :: basis_i, basis_j
3413 TYPE(libint_potential_type),
INTENT(IN) :: potential_parameter
3414 LOGICAL,
INTENT(IN),
OPTIONAL :: do_kpoints, do_hfx_kpoints
3415 TYPE(kpoint_type),
OPTIONAL,
POINTER :: ext_kpoints
3416 REAL(kind=dp),
OPTIONAL :: regularization_ri
3418 CHARACTER(len=*),
PARAMETER :: routinen =
'build_2c_integrals'
3420 INTEGER :: handle, i_diag, iatom, ibasis, icol, ikind,
imax, img, irow, iset, jatom, jkind, &
3421 jset, m_max, maxli, maxlj, natom, ncoi, ncoj, nimg, nseti, nsetj, op_prv, sgfi, sgfj, &
3423 INTEGER,
DIMENSION(3) :: cell_j, kp_index_lbounds, &
3425 INTEGER,
DIMENSION(:),
POINTER :: lmax_i, lmax_j, lmin_i, lmin_j, npgfi, &
3427 INTEGER,
DIMENSION(:, :),
POINTER :: first_sgf_i, first_sgf_j
3428 INTEGER,
DIMENSION(:, :, :),
POINTER :: cell_to_index
3429 LOGICAL :: do_hfx_kpoints_prv, do_kpoints_prv, &
3430 do_symmetric, found, trans
3431 REAL(kind=dp) :: dab, my_regularization_ri
3432 REAL(kind=dp),
ALLOCATABLE,
DIMENSION(:, :) :: sij, sij_contr, sij_rs
3433 REAL(kind=dp),
DIMENSION(3) :: ri, rij, rj
3434 REAL(kind=dp),
DIMENSION(:),
POINTER :: set_radius_i, set_radius_j
3435 REAL(kind=dp),
DIMENSION(:, :),
POINTER :: rpgf_i, rpgf_j, sphi_i, sphi_j, zeti, &
3437 TYPE(atomic_kind_type),
DIMENSION(:),
POINTER :: atomic_kind_set
3438 TYPE(block_p_type) :: block_t
3439 TYPE(cell_type),
POINTER :: cell
3440 TYPE(cp_libint_t) :: lib
3441 TYPE(dft_control_type),
POINTER :: dft_control
3442 TYPE(kpoint_type),
POINTER :: kpoints
3443 TYPE(mp_para_env_type),
POINTER :: para_env
3444 TYPE(neighbor_list_iterator_p_type), &
3445 DIMENSION(:),
POINTER :: nl_iterator
3446 TYPE(qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
3448 CALL timeset(routinen, handle)
3450 IF (
PRESENT(do_kpoints))
THEN
3451 do_kpoints_prv = do_kpoints
3453 do_kpoints_prv = .false.
3456 IF (
PRESENT(do_hfx_kpoints))
THEN
3457 do_hfx_kpoints_prv = do_hfx_kpoints
3459 do_hfx_kpoints_prv = .false.
3461 IF (do_hfx_kpoints_prv)
THEN
3462 cpassert(do_kpoints_prv)
3465 my_regularization_ri = 0.0_dp
3466 IF (
PRESENT(regularization_ri)) my_regularization_ri = regularization_ri
3468 op_prv = potential_parameter%potential_type
3470 NULLIFY (qs_kind_set, atomic_kind_set, block_t%block, cell_to_index)
3473 CALL get_qs_env(qs_env, atomic_kind_set=atomic_kind_set, qs_kind_set=qs_kind_set, cell=cell, &
3474 natom=natom, dft_control=dft_control, para_env=para_env, kpoints=kpoints)
3476 IF (
PRESENT(ext_kpoints)) kpoints => ext_kpoints
3478 IF (do_kpoints_prv)
THEN
3480 CALL get_kpoint_info(kpoints, cell_to_index=cell_to_index)
3481 kp_index_lbounds = lbound(cell_to_index)
3482 kp_index_ubounds = ubound(cell_to_index)
3488 cpassert(
SIZE(nl_2c) > 0)
3489 CALL get_neighbor_list_set_p(neighbor_list_sets=nl_2c, symmetric=do_symmetric)
3491 IF (do_symmetric)
THEN
3493 cpassert(dbcsr_has_symmetry(t2c(img)))
3497 cpassert(.NOT. dbcsr_has_symmetry(t2c(img)))
3502 CALL cp_dbcsr_alloc_block_from_nbl(t2c(img), nl_2c)
3506 DO ibasis = 1,
SIZE(basis_i)
3507 CALL get_gto_basis_set(gto_basis_set=basis_i(ibasis)%gto_basis_set, maxl=
imax)
3508 maxli = max(maxli,
imax)
3511 DO ibasis = 1,
SIZE(basis_j)
3512 CALL get_gto_basis_set(gto_basis_set=basis_j(ibasis)%gto_basis_set, maxl=
imax)
3513 maxlj = max(maxlj,
imax)
3516 m_max = maxli + maxlj
3519 IF (op_prv == do_potential_truncated)
THEN
3521 IF (m_max > get_lmax_init())
THEN
3522 IF (para_env%mepos == 0)
THEN
3523 CALL open_file(unit_number=unit_id, file_name=potential_parameter%filename)
3525 CALL init(m_max, unit_id, para_env%mepos, para_env)
3526 IF (para_env%mepos == 0)
THEN
3527 CALL close_file(unit_id)
3532 CALL init_md_ftable(nmax=m_max)
3534 CALL cp_libint_init_2eri(lib, max(maxli, maxlj))
3535 CALL cp_libint_set_contrdepth(lib, 1)
3537 CALL neighbor_list_iterator_create(nl_iterator, nl_2c)
3538 DO WHILE (neighbor_list_iterate(nl_iterator) == 0)
3540 CALL get_iterator_info(nl_iterator, ikind=ikind, jkind=jkind, &
3541 iatom=iatom, jatom=jatom, r=rij, cell=cell_j)
3542 IF (do_kpoints_prv)
THEN
3543 IF (any([cell_j(1), cell_j(2), cell_j(3)] < kp_index_lbounds) .OR. &
3544 any([cell_j(1), cell_j(2), cell_j(3)] > kp_index_ubounds)) cycle
3545 img = cell_to_index(cell_j(1), cell_j(2), cell_j(3))
3546 IF (img > nimg .OR. img < 1) cycle
3551 CALL get_gto_basis_set(basis_i(ikind)%gto_basis_set, first_sgf=first_sgf_i, lmax=lmax_i, lmin=lmin_i, &
3552 npgf=npgfi, nset=nseti, nsgf_set=nsgfi, pgf_radius=rpgf_i, set_radius=set_radius_i, &
3553 sphi=sphi_i, zet=zeti)
3555 CALL get_gto_basis_set(basis_j(jkind)%gto_basis_set, first_sgf=first_sgf_j, lmax=lmax_j, lmin=lmin_j, &
3556 npgf=npgfj, nset=nsetj, nsgf_set=nsgfj, pgf_radius=rpgf_j, set_radius=set_radius_j, &
3557 sphi=sphi_j, zet=zetj)
3559 IF (do_symmetric)
THEN
3560 IF (iatom <= jatom)
THEN
3574 CALL dbcsr_get_block_p(matrix=t2c(img), &
3575 row=irow, col=icol, block=block_t%block, found=found)
3577 trans = do_symmetric .AND. (iatom > jatom)
3581 ncoi = npgfi(iset)*
ncoset(lmax_i(iset))
3582 sgfi = first_sgf_i(1, iset)
3586 ncoj = npgfj(jset)*
ncoset(lmax_j(jset))
3587 sgfj = first_sgf_j(1, jset)
3589 IF (ncoi*ncoj > 0)
THEN
3590 ALLOCATE (sij_contr(nsgfi(iset), nsgfj(jset)))
3591 sij_contr(:, :) = 0.0_dp
3593 ALLOCATE (sij(ncoi, ncoj))
3599 CALL eri_2center(sij, lmin_i(iset), lmax_i(iset), npgfi(iset), zeti(:, iset), &
3600 rpgf_i(:, iset), ri, lmin_j(jset), lmax_j(jset), npgfj(jset), zetj(:, jset), &
3601 rpgf_j(:, jset), rj, dab, lib, potential_parameter)
3603 CALL ab_contract(sij_contr, sij, &
3604 sphi_i(:, sgfi:), sphi_j(:, sgfj:), &
3605 ncoi, ncoj, nsgfi(iset), nsgfj(jset))
3609 ALLOCATE (sij_rs(nsgfj(jset), nsgfi(iset)))
3610 sij_rs(:, :) = transpose(sij_contr)
3612 ALLOCATE (sij_rs(nsgfi(iset), nsgfj(jset)))
3613 sij_rs(:, :) = sij_contr
3616 DEALLOCATE (sij_contr)
3619 IF (.NOT. do_hfx_kpoints_prv)
THEN
3620 IF (do_kpoints_prv .AND. cell_j(1) == 0 .AND. cell_j(2) == 0 .AND. cell_j(3) == 0 .AND. &
3621 iatom == jatom .AND. iset == jset)
THEN
3622 DO i_diag = 1, nsgfi(iset)
3623 sij_rs(i_diag, i_diag) = sij_rs(i_diag, i_diag) + &
3624 regularization_ri*max(1.0_dp, 1.0_dp/minval(zeti(:, iset)))
3629 CALL block_add(
"IN", sij_rs, &
3630 nsgfi(iset), nsgfj(jset), block_t%block, &
3631 sgfi, sgfj, trans=trans)
3639 CALL cp_libint_cleanup_2eri(lib)
3641 CALL neighbor_list_iterator_release(nl_iterator)
3643 CALL dbcsr_finalize(t2c(img))
3644 CALL dbcsr_filter(t2c(img), filter_eps)
3647 CALL timestop(handle)
3660 TYPE(dbt_type),
INTENT(INOUT) ::
tensor
3661 INTEGER,
ALLOCATABLE,
DIMENSION(:, :), &
3662 INTENT(INOUT) :: blk_indices
3663 TYPE(hfx_compression_type),
INTENT(INOUT) :: compressed
3664 REAL(dp),
INTENT(IN) :: eps
3665 REAL(dp),
INTENT(INOUT) :: memory
3667 INTEGER :: buffer_left, buffer_size, buffer_start, &
3668 i, iblk, memory_usage, nbits, nblk, &
3669 nints, offset, shared_offset
3670 INTEGER(int_8) :: estimate_to_store_int, &
3671 storage_counter_integrals
3672 INTEGER,
DIMENSION(3) :: ind
3674 REAL(dp) :: spherical_estimate
3675 REAL(dp),
ALLOCATABLE,
DIMENSION(:, :, :),
TARGET :: blk_data
3676 REAL(dp),
DIMENSION(:),
POINTER :: blk_data_1d
3677 TYPE(dbt_iterator_type) :: iter
3678 TYPE(hfx_cache_type),
DIMENSION(:),
POINTER :: integral_caches
3679 TYPE(hfx_cache_type),
POINTER :: maxval_cache
3680 TYPE(hfx_container_type),
DIMENSION(:),
POINTER :: integral_containers
3681 TYPE(hfx_container_type),
POINTER :: maxval_container
3683 CALL dealloc_containers(compressed, memory_usage)
3684 CALL alloc_containers(compressed, 1)
3686 maxval_container => compressed%maxval_container(1)
3687 integral_containers => compressed%integral_containers(:, 1)
3689 CALL hfx_init_container(maxval_container, memory_usage, .false.)
3691 CALL hfx_init_container(integral_containers(i), memory_usage, .false.)
3694 maxval_cache => compressed%maxval_cache(1)
3695 integral_caches => compressed%integral_caches(:, 1)
3697 IF (
ALLOCATED(blk_indices))
DEALLOCATE (blk_indices)
3698 ALLOCATE (blk_indices(dbt_get_num_blocks(
tensor), 3))
3702 CALL dbt_iterator_start(iter,
tensor)
3703 nblk = dbt_iterator_num_blocks(iter)
3705 offset = shared_offset
3706 shared_offset = shared_offset + nblk
3709 CALL dbt_iterator_next_block(iter, ind)
3710 blk_indices(offset + iblk, :) = ind(:)
3712 CALL dbt_iterator_stop(iter)
3716 DO i = 1,
SIZE(blk_indices, 1)
3717 ind = blk_indices(i, :)
3718 CALL dbt_get_block(
tensor, ind, blk_data, found)
3720 nints =
SIZE(blk_data)
3721 blk_data_1d(1:nints) => blk_data
3722 spherical_estimate = maxval(abs(blk_data_1d))
3723 IF (spherical_estimate == 0.0_dp) spherical_estimate = tiny(spherical_estimate)
3724 estimate_to_store_int = exponent(spherical_estimate)
3725 estimate_to_store_int = max(estimate_to_store_int, -15_int_8)
3727 CALL hfx_add_single_cache_element(estimate_to_store_int, 6, &
3728 maxval_cache, maxval_container, memory_usage, &
3731 spherical_estimate = set_exponent(1.0_dp, estimate_to_store_int + 1)
3733 nbits = exponent(anint(spherical_estimate/eps)) + 1
3734 IF (nbits > 64)
THEN
3735 CALL cp_abort(__location__, &
3736 "Overflow during tensor compression. Please use a larger EPS_FILTER or EPS_STORAGE_SCALING")
3742 DO WHILE (buffer_left > 0)
3743 buffer_size = min(buffer_left, cache_size)
3744 CALL hfx_add_mult_cache_elements(blk_data_1d(buffer_start:), &
3745 buffer_size, nbits, &
3746 integral_caches(nbits), &
3747 integral_containers(nbits), &
3751 buffer_left = buffer_left - buffer_size
3752 buffer_start = buffer_start + buffer_size
3755 NULLIFY (blk_data_1d);
DEALLOCATE (blk_data)
3760 storage_counter_integrals = memory_usage*cache_size
3761 memory = memory + real(storage_counter_integrals, dp)/1024/128
3765 CALL hfx_flush_last_cache(6, maxval_cache, maxval_container, memory_usage, &
3768 CALL hfx_flush_last_cache(i, integral_caches(i), integral_containers(i), &
3769 memory_usage, .false.)
3772 CALL hfx_reset_cache_and_container(maxval_cache, maxval_container, memory_usage, .false.)
3774 CALL hfx_reset_cache_and_container(integral_caches(i), integral_containers(i), &
3775 memory_usage, .false.)
3789 TYPE(dbt_type),
INTENT(INOUT) ::
tensor
3790 INTEGER,
DIMENSION(:, :) :: blk_indices
3791 TYPE(hfx_compression_type),
INTENT(INOUT) :: compressed
3792 REAL(dp),
INTENT(IN) :: eps
3794 INTEGER :: a, b, buffer_left, buffer_size, &
3795 buffer_start, i, memory_usage, nbits, &
3796 nblk_per_thread, nints
3797 INTEGER(int_8) :: estimate_to_store_int
3798 INTEGER,
DIMENSION(3) :: blk_size, ind
3799 REAL(dp) :: spherical_estimate
3800 REAL(dp),
ALLOCATABLE,
DIMENSION(:),
TARGET :: blk_data
3801 REAL(dp),
DIMENSION(:, :, :),
POINTER :: blk_data_3d
3802 TYPE(hfx_cache_type),
DIMENSION(:),
POINTER :: integral_caches
3803 TYPE(hfx_cache_type),
POINTER :: maxval_cache
3804 TYPE(hfx_container_type),
DIMENSION(:),
POINTER :: integral_containers
3805 TYPE(hfx_container_type),
POINTER :: maxval_container
3807 maxval_cache => compressed%maxval_cache(1)
3808 maxval_container => compressed%maxval_container(1)
3809 integral_caches => compressed%integral_caches(:, 1)
3810 integral_containers => compressed%integral_containers(:, 1)
3814 CALL hfx_decompress_first_cache(6, maxval_cache, maxval_container, memory_usage, .false.)
3817 CALL hfx_decompress_first_cache(i, integral_caches(i), integral_containers(i), &
3818 memory_usage, .false.)
3823 nblk_per_thread =
SIZE(blk_indices, 1)/omp_get_num_threads() + 1
3824 a = omp_get_thread_num()*nblk_per_thread + 1
3825 b = min(a + nblk_per_thread,
SIZE(blk_indices, 1))
3826 CALL dbt_reserve_blocks(
tensor, blk_indices(a:b, :))
3830 DO i = 1,
SIZE(blk_indices, 1)
3831 ind = blk_indices(i, :)
3832 CALL dbt_blk_sizes(
tensor, ind, blk_size)
3833 nints = product(blk_size)
3834 CALL hfx_get_single_cache_element( &
3835 estimate_to_store_int, 6, &
3836 maxval_cache, maxval_container, memory_usage, &
3839 spherical_estimate = set_exponent(1.0_dp, estimate_to_store_int + 1)
3841 nbits = exponent(anint(spherical_estimate/eps)) + 1
3846 ALLOCATE (blk_data(nints))
3847 DO WHILE (buffer_left > 0)
3848 buffer_size = min(buffer_left, cache_size)
3849 CALL hfx_get_mult_cache_elements(blk_data(buffer_start), &
3850 buffer_size, nbits, &
3851 integral_caches(nbits), &
3852 integral_containers(nbits), &
3856 buffer_left = buffer_left - buffer_size
3857 buffer_start = buffer_start + buffer_size
3860 blk_data_3d(1:blk_size(1), 1:blk_size(2), 1:blk_size(3)) => blk_data
3861 CALL dbt_put_block(
tensor, ind, blk_size, blk_data_3d)
3862 NULLIFY (blk_data_3d);
DEALLOCATE (blk_data)
3865 CALL hfx_reset_cache_and_container(maxval_cache, maxval_container, memory_usage, .false.)
3867 CALL hfx_reset_cache_and_container(integral_caches(i), integral_containers(i), &
3868 memory_usage, .false.)
3879 TYPE(dbt_type),
INTENT(IN) ::
tensor
3880 INTEGER(int_8),
INTENT(OUT) :: nze
3881 REAL(dp),
INTENT(OUT) :: occ
3883 INTEGER,
DIMENSION(dbt_ndims(tensor)) :: dims
3885 nze = dbt_get_nze_total(
tensor)
3886 CALL dbt_get_info(
tensor, nfull_total=dims)
3887 occ = real(nze, dp)/product(real(dims, dp))
static int imax(int x, int y)
Returns the larger of two given integer (missing from the C standard)
static GRID_HOST_DEVICE int ncoset(const int l)
Number of Cartesian orbitals up to given angular momentum quantum.
static GRID_HOST_DEVICE int modulo(int a, int m)
Equivalent of Fortran's MODULO, which always return a positive number. https://gcc....
Contraction of integrals over primitive Cartesian Gaussians based on the contraction matrix sphi whic...
subroutine, public libxsmm_abc_contract(abcint, sabc, tsphi_a, sphi_b, sphi_c, ncoa, ncob, ncoc, nsgfa, nsgfb, nsgfc, cpp_buffer, ccp_buffer)
3-center contraction routine from primitive cartesain Gaussians to spherical Gaussian functions....
subroutine, public ab_contract(abint, sab, sphi_a, sphi_b, ncoa, ncob, nsgfa, nsgfb)
contract overlap integrals (a,b) and transfer to spherical Gaussians
Set of routines to: Contract integrals over primitive Gaussians Decontract (density) matrices Trace m...
Define the atomic kind types and their sub types.
subroutine, public get_gto_basis_set(gto_basis_set, name, aliases, norm_type, kind_radius, ncgf, nset, nsgf, cgf_symbol, sgf_symbol, norm_cgf, set_radius, lmax, lmin, lx, ly, lz, m, ncgf_set, npgf, nsgf_set, nshell, cphi, pgf_radius, sphi, scon, zet, first_cgf, first_sgf, l, last_cgf, last_sgf, n, gcc, maxco, maxl, maxpgf, maxsgf_set, maxshell, maxso, nco_sum, npgf_sum, nshell_sum, maxder, short_kind_radius)
...
collect pointers to a block of reals
Handles all functions related to the CELL.
subroutine, public real_to_scaled(s, r, cell)
Transform real to scaled cell coordinates. s=h_inv*r.
various utilities that regard array of different kinds: output, allocation,... maybe it is not a good...
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
Routines that link DBCSR and CP2K concepts together.
subroutine, public cp_dbcsr_alloc_block_from_nbl(matrix, sab_orb, desymmetrize)
allocate the blocks of a dbcsr based on the neighbor list
Utility routines to open and close files. Tracking of preconnections.
subroutine, public open_file(file_name, file_status, file_form, file_action, file_position, file_pad, unit_number, debug, skip_get_unit_number, file_access)
Opens the requested file using a free unit number.
subroutine, public close_file(unit_number, file_status, keep_preconnection)
Close an open file given by its logical unit number. Optionally, keep the file and unit preconnected.
This is the start of a dbt_api, all publically needed functions are exported here....
stores a lists of integer that are local to a processor. The idea is that these integers represent ob...
stores a mapping of 2D info (e.g. matrix) on a 2D processor distribution (i.e. blacs grid) where cpus...
Calculation of the incomplete Gamma function F_n(t) for multi-center integrals over Cartesian Gaussia...
subroutine, public init_md_ftable(nmax)
Initialize a table of F_n(t) values in the range 0 <= t <= 12 with a stepsize of 0....
routines and types for Hartree-Fock-Exchange
subroutine, public hfx_add_single_cache_element(value, nbits, cache, container, memory_usage, use_disk_storage, max_val_memory)
This routine adds an int_8 value to a cache. If the cache is full a compression routine is invoked an...
subroutine, public hfx_get_mult_cache_elements(values, nints, nbits, cache, container, eps_schwarz, pmax_entry, memory_usage, use_disk_storage)
This routine returns a bunch real values from a cache. If the cache is empty a decompression routine ...
subroutine, public hfx_flush_last_cache(nbits, cache, container, memory_usage, use_disk_storage)
This routine compresses the last probably not yet compressed cache into a container
subroutine, public hfx_get_single_cache_element(value, nbits, cache, container, memory_usage, use_disk_storage)
This routine returns an int_8 value from a cache. If the cache is empty a decompression routine is in...
subroutine, public hfx_decompress_first_cache(nbits, cache, container, memory_usage, use_disk_storage)
This routine decompresses the first bunch of data in a container and copies them into a cache
subroutine, public hfx_add_mult_cache_elements(values, nints, nbits, cache, container, eps_schwarz, pmax_entry, memory_usage, use_disk_storage)
This routine adds an a few real values to a cache. If the cache is full a compression routine is invo...
subroutine, public hfx_reset_cache_and_container(cache, container, memory_usage, do_disk_storage)
This routine resets the containers list pointer to the first element and moves the element counters o...
Types and set/get functions for HFX.
subroutine, public dealloc_containers(DATA, memory_usage)
...
subroutine, public alloc_containers(DATA, bin_size)
...
subroutine, public hfx_init_container(container, memory_usage, do_disk_storage)
This routine deletes all list entries in a container in order to deallocate the memory.
Defines the basic variable types.
integer, parameter, public int_8
integer, parameter, public dp
Types and basic routines needed for a kpoint calculation.
subroutine, public get_kpoint_info(kpoint, kp_scheme, nkp_grid, kp_shift, symmetry, verbose, full_grid, use_real_wfn, eps_geo, parallel_group_size, kp_range, nkp, xkp, wkp, para_env, blacs_env_all, para_env_kp, para_env_inter_kp, blacs_env, kp_env, kp_aux_env, mpools, iogrp, nkp_groups, kp_dist, cell_to_index, index_to_cell, sab_nl, sab_nl_nosym)
Retrieve information from a kpoint environment.
2- and 3-center electron repulsion integral routines based on libint2 Currently available operators: ...
subroutine, public eri_2center(int_ab, la_min, la_max, npgfa, zeta, rpgfa, ra, lb_min, lb_max, npgfb, zetb, rpgfb, rb, dab, lib, potential_parameter)
Computes the 2-center electron repulsion integrals (a|b) for a given set of cartesian gaussian orbita...
subroutine, public eri_3center(int_abc, la_min, la_max, npgfa, zeta, rpgfa, ra, lb_min, lb_max, npgfb, zetb, rpgfb, rb, lc_min, lc_max, npgfc, zetc, rpgfc, rc, dab, dac, dbc, lib, potential_parameter, int_abc_ext)
Computes the 3-center electron repulsion integrals (ab|c) for a given set of cartesian gaussian orbit...
real(kind=dp), parameter, public cutoff_screen_factor
subroutine, public eri_2center_derivs(der_ab, la_min, la_max, npgfa, zeta, rpgfa, ra, lb_min, lb_max, npgfb, zetb, rpgfb, rb, dab, lib, potential_parameter)
Computes the 2-center derivatives of the electron repulsion integrals (a|b) for a given set of cartes...
subroutine, public eri_3center_derivs(der_abc_1, der_abc_2, la_min, la_max, npgfa, zeta, rpgfa, ra, lb_min, lb_max, npgfb, zetb, rpgfb, rb, lc_min, lc_max, npgfc, zetc, rpgfc, rc, dab, dac, dbc, lib, potential_parameter, der_abc_1_ext, der_abc_2_ext)
Computes the derivatives of the 3-center electron repulsion integrals (ab|c) for a given set of carte...
Interface to the Libint-Library or a c++ wrapper.
subroutine, public cp_libint_cleanup_3eri1(lib)
subroutine, public cp_libint_init_3eri1(lib, max_am)
subroutine, public cp_libint_cleanup_2eri1(lib)
subroutine, public cp_libint_init_2eri1(lib, max_am)
subroutine, public cp_libint_init_2eri(lib, max_am)
subroutine, public cp_libint_init_3eri(lib, max_am)
subroutine, public cp_libint_cleanup_3eri(lib)
subroutine, public cp_libint_set_contrdepth(lib, contrdepth)
subroutine, public cp_libint_cleanup_2eri(lib)
Interface to the message passing library MPI.
Define the data structure for the molecule information.
Provides Cartesian and spherical orbital pointers and indices.
integer, dimension(:), allocatable, public ncoset
Define the data structure for the particle information.
subroutine, public get_qs_env(qs_env, atomic_kind_set, qs_kind_set, cell, super_cell, cell_ref, use_ref_cell, kpoints, dft_control, mos, sab_orb, sab_all, qmmm, qmmm_periodic, sac_ae, sac_ppl, sac_lri, sap_ppnl, sab_vdw, sab_scp, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, sab_xb, sab_xtb_nonbond, sab_almo, sab_kp, sab_kp_nosym, particle_set, energy, force, matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, run_rtp, rtp, matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_ks_im_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, matrix_s_RI_aux_kp, matrix_s, matrix_s_RI_aux, matrix_w, matrix_p_mp2, matrix_p_mp2_admm, rho, rho_xc, pw_env, ewald_env, ewald_pw, active_space, mpools, input, para_env, blacs_env, scf_control, rel_control, kinetic, qs_charges, vppl, rho_core, rho_nlcc, rho_nlcc_g, ks_env, ks_qmmm_env, wf_history, scf_env, local_particles, local_molecules, distribution_2d, dbcsr_dist, molecule_kind_set, molecule_set, subsys, cp_subsys, oce, local_rho_set, rho_atom_set, task_list, task_list_soft, rho0_atom_set, rho0_mpole, rhoz_set, ecoul_1c, rho0_s_rs, rho0_s_gs, do_kpoints, has_unit_metric, requires_mo_derivs, mo_derivs, mo_loc_history, nkind, natom, nelectron_total, nelectron_spin, efield, neighbor_list_id, linres_control, xas_env, virial, cp_ddapc_env, cp_ddapc_ewald, outer_scf_history, outer_scf_ihistory, x_data, et_coupling, dftb_potential, results, se_taper, se_store_int_env, se_nddo_mpole, se_nonbond_env, admm_env, lri_env, lri_density, exstate_env, ec_env, dispersion_env, gcp_env, vee, rho_external, external_vxc, mask, mp2_env, bs_env, kg_env, WannierCentres, atprop, ls_scf_env, do_transport, transport_env, v_hartree_rspace, s_mstruct_changed, rho_changed, potential_changed, forces_up_to_date, mscfg_env, almo_scf_env, gradient_history, variable_history, embed_pot, spin_embed_pot, polar_env, mos_last_converged, rhs)
Get the QUICKSTEP environment.
Define the quickstep kind type and their sub types.
Define the neighbor list data types and the corresponding functionality.
subroutine, public release_neighbor_list_sets(nlists)
releases an array of neighbor_list_sets
integer function, public nl_sub_iterate(iterator_set, mepos)
...
subroutine, public neighbor_list_iterator_create(iterator_set, nl, search, nthread)
Neighbor list iterator functions.
subroutine, public neighbor_list_iterator_release(iterator_set)
...
subroutine, public get_neighbor_list_set_p(neighbor_list_sets, nlist, symmetric)
Return the components of the first neighbor list set.
integer function, public neighbor_list_iterate(iterator_set, mepos)
...
subroutine, public get_iterator_info(iterator_set, mepos, ikind, jkind, nkind, ilist, nlist, inode, nnode, iatom, jatom, r, cell)
...
Generate the atomic neighbor lists.
subroutine, public atom2d_cleanup(atom2d)
free the internals of atom2d
subroutine, public pair_radius_setup(present_a, present_b, radius_a, radius_b, pair_radius, prmin)
...
subroutine, public build_neighbor_lists(ab_list, particle_set, atom, cell, pair_radius, subcells, mic, symmetric, molecular, subset_of_mol, current_subset, operator_type, nlname, atomb_to_keep)
Build simple pair neighbor lists.
subroutine, public atom2d_build(atom2d, distribution_1d, distribution_2d, atomic_kind_set, molecule_set, molecule_only, particle_set)
Build some distribution structure of atoms, refactored from build_qs_neighbor_lists.
Utility methods to build 3-center integral tensors of various types.
integer, parameter, public symmetrik_ik
integer, parameter, public symmetric_jk
integer, parameter, public symmetric_ijk
integer, parameter, public symmetric_ij
integer, parameter, public symmetric_none
subroutine, public distribution_3d_destroy(dist)
Destroy a 3d distribution.
Utility methods to build 3-center integral tensors of various types.
subroutine, public calc_3c_virial(work_virial, t3c_trace, pref, qs_env, nl_3c, basis_i, basis_j, basis_k, potential_parameter, der_eps, op_pos)
Calculates the 3c virial contributions on the fly.
subroutine, public build_2c_neighbor_lists(ij_list, basis_i, basis_j, potential_parameter, name, qs_env, sym_ij, molecular, dist_2d, pot_to_rad)
Build 2-center neighborlists adapted to different operators This mainly wraps build_neighbor_lists fo...
subroutine, public build_3c_derivatives(t3c_der_i, t3c_der_k, filter_eps, qs_env, nl_3c, basis_i, basis_j, basis_k, potential_parameter, der_eps, op_pos, do_kpoints, do_hfx_kpoints, bounds_i, bounds_j, bounds_k, RI_range, img_to_RI_cell)
Build 3-center derivative tensors.
recursive integer function, public neighbor_list_3c_iterate(iterator)
Iterate 3c-nl iterator.
subroutine, public compress_tensor(tensor, blk_indices, compressed, eps, memory)
...
subroutine, public neighbor_list_3c_iterator_destroy(iterator)
Destroy 3c-nl iterator.
subroutine, public neighbor_list_3c_destroy(ijk_list)
Destroy 3c neighborlist.
subroutine, public calc_2c_virial(work_virial, t2c_trace, pref, qs_env, nl_2c, basis_i, basis_j, potential_parameter)
Calculates the virial coming from 2c derivatives on the fly.
subroutine, public decompress_tensor(tensor, blk_indices, compressed, eps)
...
subroutine, public build_2c_derivatives(t2c_der, filter_eps, qs_env, nl_2c, basis_i, basis_j, potential_parameter, do_kpoints)
Calculates the derivatives of 2-center integrals, wrt to the first center.
subroutine, public get_tensor_occupancy(tensor, nze, occ)
...
subroutine, public build_3c_neighbor_lists(ijk_list, basis_i, basis_j, basis_k, dist_3d, potential_parameter, name, qs_env, sym_ij, sym_jk, sym_ik, molecular, op_pos, own_dist)
Build a 3-center neighbor list.
subroutine, public build_2c_integrals(t2c, filter_eps, qs_env, nl_2c, basis_i, basis_j, potential_parameter, do_kpoints, do_hfx_kpoints, ext_kpoints, regularization_RI)
...
subroutine, public build_3c_integrals(t3c, filter_eps, qs_env, nl_3c, basis_i, basis_j, basis_k, potential_parameter, int_eps, op_pos, do_kpoints, do_hfx_kpoints, desymmetrize, bounds_i, bounds_j, bounds_k, RI_range, img_to_RI_cell)
Build 3-center integral tensor.
subroutine, public neighbor_list_3c_iterator_create(iterator, ijk_nl)
Create a 3-center neighborlist iterator.
subroutine, public get_3c_iterator_info(iterator, ikind, jkind, kkind, nkind, iatom, jatom, katom, rij, rjk, rik, cell_j, cell_k)
Get info of current iteration.
This module computes the basic integrals for the truncated coulomb operator.
subroutine, public init(Nder, iunit, mepos, group)
...
integer function, public get_lmax_init()
Returns the value of nderiv_init so that one can check if opening the potential file is worhtwhile.
All kind of helpful little routines.
pure integer function, dimension(2), public get_limit(m, n, me)
divide m entries into n parts, return size of part me