62 dbt_clear, dbt_create, dbt_destroy, dbt_filter, dbt_iterator_blocks_left, &
63 dbt_iterator_next_block, dbt_iterator_start, dbt_iterator_stop, dbt_iterator_type, &
64 dbt_mp_environ_pgrid, dbt_pgrid_create, dbt_pgrid_destroy, dbt_pgrid_type, dbt_type
141#include "base/base_uses.f90"
156 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'gw_utils'
171 CHARACTER(LEN=*),
PARAMETER :: routinen =
'create_and_init_bs_env_for_gw'
175 CALL timeset(routinen, handle)
179 CALL get_parameters_from_qs_env(qs_env, bs_env)
181 CALL read_gw_input_parameters(bs_env, bs_sec)
183 CALL print_header_and_input_parameters(bs_env)
185 CALL setup_ao_and_ri_basis_set(qs_env, bs_env)
187 CALL set_heuristic_parameters(bs_env, qs_env)
191 CALL get_ri_basis(qs_env, bs_env)
193 CALL compute_v_xc(qs_env, bs_env)
195 CALL init_interaction_radii(bs_env)
200 IF (.NOT. bs_env%do_gw_ri_rs .OR. &
203 CALL create_tensors(qs_env, bs_env)
206 CALL allocate_gw_eigenvalues(bs_env)
208 SELECT CASE (bs_env%gw_implementation)
211 CALL check_sparsity_3c(qs_env, bs_env)
213 CALL set_sparsity_parallelization_parameters(bs_env)
215 CALL check_for_restart_files(qs_env, bs_env)
219 CALL check_for_restart_files(qs_env, bs_env)
223 CALL compute_3c_integrals(qs_env, bs_env)
225 CALL setup_cells_delta_r(bs_env)
227 CALL setup_parallelization_delta_r(bs_env)
229 CALL allocate_matrices_small_cell_full_kp_tensor(qs_env, bs_env)
231 CALL trafo_v_xc_r_to_kp(qs_env, bs_env)
233 CALL heuristic_ri_regularization(qs_env, bs_env)
237 CALL trafo_v_xc_r_to_kp(qs_env, bs_env)
243 CALL setup_time_and_frequency_minimax_grid(bs_env)
252 IF (.NOT. bs_env%do_ldos .AND. &
258 CALL timestop(handle)
267 SUBROUTINE get_parameters_from_qs_env(qs_env, bs_env)
273 NULLIFY (input, rtbse_sec)
274 CALL get_qs_env(qs_env, atomic_kind_set=bs_env%ri_rs%atomic_kind_set, &
275 cell=bs_env%ri_rs%cell, particle_set=bs_env%ri_rs%particle_set, input=input)
279 END SUBROUTINE get_parameters_from_qs_env
286 SUBROUTINE read_gw_input_parameters(bs_env, bs_sec)
290 CHARACTER(LEN=*),
PARAMETER :: routinen =
'read_gw_input_parameters'
295 grid_opt_sec, gw_sec, ri_rs_sec
297 CALL timeset(routinen, handle)
299 NULLIFY (auto_ri_sec, cohsex_sec, evgw0_sec, grid_opt_sec, gw_sec, ri_rs_sec)
310 CALL section_vals_val_get(gw_sec,
"REGULARIZATION_MINIMAX", r_val=bs_env%input_regularization_minimax)
322 CALL read_rirs_input(bs_env%ri_rs, ri_rs_sec)
323 CALL read_rirs_grid_opt(bs_env%ri_rs, grid_opt_sec)
324 CALL read_evgw0_input(bs_env, evgw0_sec, do_evgw0)
325 CALL read_auto_ri_input(bs_env%auto_ri, auto_ri_sec)
326 CALL check_gw_input(bs_env, do_evgw0)
328 CALL timestop(handle)
330 END SUBROUTINE read_gw_input_parameters
337 SUBROUTINE read_rirs_input(ri_rs, ri_rs_sec)
341 CHARACTER(LEN=*),
PARAMETER :: routinen =
'read_rirs_input'
345 CALL timeset(routinen, handle)
352 CALL timestop(handle)
354 END SUBROUTINE read_rirs_input
361 SUBROUTINE read_rirs_grid_opt(ri_rs, grid_opt_sec)
362 TYPE(
ri_rs_env),
INTENT(INOUT),
TARGET :: ri_rs
365 CHARACTER(LEN=*),
PARAMETER :: routinen =
'read_rirs_grid_opt'
370 CALL timeset(routinen, handle)
373 IF (.NOT. ri_rs%grid_opt%enabled)
THEN
374 CALL timestop(handle)
379 grid_opt => ri_rs%grid_opt
381 CALL section_vals_val_get(grid_opt_sec,
"CUTOFF_ATOMIC_CLUSTER", r_val=grid_opt%cutoff_atomic_cluster)
385 CALL timestop(handle)
387 END SUBROUTINE read_rirs_grid_opt
395 SUBROUTINE read_evgw0_input(bs_env, evgw0_sec, do_evgw0)
398 LOGICAL,
INTENT(OUT) :: do_evgw0
400 CHARACTER(LEN=*),
PARAMETER :: routinen =
'read_evgw0_input'
404 CALL timeset(routinen, handle)
410 CALL timestop(handle)
412 END SUBROUTINE read_evgw0_input
419 SUBROUTINE read_auto_ri_input(auto_ri, auto_ri_sec)
423 CHARACTER(LEN=*),
PARAMETER :: routinen =
'read_auto_ri_input'
427 CALL timeset(routinen, handle)
430 IF (.NOT. auto_ri%enabled)
THEN
431 CALL timestop(handle)
436 CALL section_vals_val_get(auto_ri_sec,
"OCC_EMPTY_FRONTIER_ORBITAL_WINDOW", r_val=auto_ri%occ_energy_window)
438 CALL timestop(handle)
440 END SUBROUTINE read_auto_ri_input
447 SUBROUTINE check_gw_input(bs_env, do_evgw0)
449 LOGICAL,
INTENT(IN) :: do_evgw0
451 CHARACTER(LEN=*),
PARAMETER :: routinen =
'check_gw_input'
455 CALL timeset(routinen, handle)
458 cpassert(.NOT. bs_env%ri_rs%grid_opt%enabled .OR. bs_env%do_gw_ri_rs)
459 IF (bs_env%ri_rs%grid_opt%enabled)
THEN
460 IF (bs_env%ri_rs%grid_opt%rs_ao_ratio <= 0.0_dp) cpabort(
"RS_AO_RATIO must be positive")
461 IF (bs_env%ri_rs%grid_opt%max_iter < 1)
THEN
462 cpabort(
"GRID_OPTIMIZATION%MAX_ITER must be positive")
464 IF (bs_env%ri_rs%grid_opt%cutoff_atomic_cluster == 0.0_dp)
THEN
465 cpabort(
"CUTOFF_ATOMIC_CLUSTER must be nonzero")
468 IF (bs_env%do_gw_ri_rs)
THEN
469 IF (bs_env%ri_rs%tikhonov < 0.0_dp)
THEN
470 cpabort(
"RI_RS%TIKHONOV must not be negative")
473 IF (.NOT. bs_env%ri_rs%grid_opt%enabled)
THEN
474 cpabort(
"Full-k RI-RS GW requires RI_RS%GRID_OPTIMIZATION")
476 IF (bs_env%size_lattice_sum_V < 1)
THEN
477 cpabort(
"GW%SIZE_LATTICE_SUM must be positive")
482 IF (.NOT. (bs_env%ri_metric%omega > 0.0_dp))
THEN
483 cpabort(
"RI_CUTOFF_ATTENUATION must be positive for periodic RI-RS GW")
485 IF (.NOT. (all(bs_env%periodic == [1, 1, 0]) .OR. all(bs_env%periodic == 1)))
THEN
486 cpabort(
"Periodic RI-RS GW requires PERIODIC XY or XYZ")
488 IF (bs_env%approx_kp_extrapol)
THEN
489 cpabort(
"APPROX_KP_EXTRAPOL cannot be combined with RI-RS GW")
492 IF (.NOT. do_evgw0) bs_env%evgw0_n_iter = 1
493 IF (do_evgw0 .AND. bs_env%evgw0_eps_iter <= 0.0_dp)
THEN
494 cpabort(
"EVGW0%EPS_ITER must be positive")
498 cpassert(.NOT. do_evgw0 .OR. bs_env%do_gw_ri_rs)
499 IF (bs_env%auto_ri%enabled)
THEN
501 cpassert(bs_env%do_gw_ri_rs)
502 IF (bs_env%do_periodic .AND. &
504 cpabort(
'Periodic AUTO_RI requires RI_RS_SMALL_CELL_FULL_KP')
506 IF (.NOT. (bs_env%auto_ri%ri_ao_ratio > 0.0_dp)) cpabort(
"AUTO_RI%RI_AO_RATIO must be positive")
507 IF (.NOT. (bs_env%auto_ri%occ_energy_window >= 0.0_dp))
THEN
508 cpabort(
"AUTO_RI%OCC_EMPTY_FRONTIER_ORBITAL_WINDOW must be nonnegative")
512 bs_env%gw_flavour =
g0w0
514 bs_env%gw_flavour =
evgw0
515 CALL cp_warn(__location__, &
516 "evGW0 in the RI-RS GW code is experimental. The quasiparticle energies "// &
517 "of the previous cycle are fed back into the Green's function, so the "// &
518 "error of the analytic continuation propagates and accumulates over the "// &
519 "cycles instead of affecting one state only, as it does in G0W0. In "// &
520 "tests on small molecules the resulting deviation stayed below 100 meV, "// &
521 "but this has not been established in general. Use at your own risk and "// &
522 "check the convergence of the reported states.")
525 CALL resolve_memory_per_proc(bs_env)
527 CALL timestop(handle)
529 END SUBROUTINE check_gw_input
539 SUBROUTINE resolve_memory_per_proc(bs_env)
542 CHARACTER(LEN=*),
PARAMETER :: routinen =
'resolve_memory_per_proc'
543 REAL(kind=
dp),
PARAMETER :: detected_memory_fraction = 0.8_dp, &
544 fallback_memory_per_proc_gb = 2.0_dp
547 REAL(kind=
dp) :: mem_free_per_proc_gb, mem_occ_per_proc_gb
549 CALL timeset(routinen, handle)
551 bs_env%auto_memory_per_proc = bs_env%input_memory_per_proc_GB <= 0.0_dp
553 IF (bs_env%auto_memory_per_proc)
THEN
559 bs_env%input_memory_per_proc_GB = detected_memory_fraction*mem_free_per_proc_gb &
560 + mem_occ_per_proc_gb
563 IF (mem_free_per_proc_gb <= 0.0_dp)
THEN
564 bs_env%auto_memory_per_proc = .false.
565 bs_env%input_memory_per_proc_GB = fallback_memory_per_proc_gb
566 CALL cp_warn(__location__, &
567 "Could not detect the available memory per MPI process. Falling back "// &
568 "to MEMORY_PER_PROC = 2 GB. Set MEMORY_PER_PROC in the GW section "// &
569 "explicitly for good performance.")
572 ELSE IF (bs_env%do_gw_ri_rs)
THEN
574 CALL cp_warn(__location__, &
575 "MEMORY_PER_PROC is set, but it is not used by this RI-RS GW code path, "// &
576 "which detects the available memory per MPI process automatically. The "// &
577 "keyword is ignored.")
581 CALL timestop(handle)
583 END SUBROUTINE resolve_memory_per_proc
589 SUBROUTINE print_header_and_input_parameters(bs_env)
593 CHARACTER(LEN=*),
PARAMETER :: routinen =
'print_header_and_input_parameters'
597 CALL timeset(routinen, handle)
602 WRITE (u,
'(T2,A)')
' '
603 WRITE (u,
'(T2,A)') repeat(
'-', 79)
604 WRITE (u,
'(T2,A,A78)')
'-',
'-'
605 WRITE (u,
'(T2,A,A46,A32)')
'-',
'GW CALCULATION',
'-'
606 WRITE (u,
'(T2,A,A78)')
'-',
'-'
607 WRITE (u,
'(T2,A)') repeat(
'-', 79)
608 WRITE (u,
'(T2,A)')
' '
609 WRITE (u,
'(T2,A,I45)')
'Input: Number of time/freq. points', bs_env%num_time_freq_points
610 WRITE (u,
"(T2,A,F44.1,A)")
'Input: ω_max for fitting Σ(iω) (eV)', bs_env%freq_max_fit*
evolt
612 WRITE (u,
"(T2,A,A51)")
'Input: Analytic continuation',
'NEVANLINNA'
614 WRITE (u,
"(T2,A,A51)")
'Input: Analytic continuation',
'PADE'
616 WRITE (u,
'(T2,A,ES27.1)')
'Input: Filter threshold for sparse tensor operations', &
618 WRITE (u,
"(T2,A,L55)")
'Input: Apply Hedin shift', bs_env%do_hedin_shift
619 IF (bs_env%auto_memory_per_proc)
THEN
620 WRITE (u,
'(T2,A,F34.1,A)')
'Detected: Available memory per MPI process', &
621 bs_env%input_memory_per_proc_GB,
' GB'
623 WRITE (u,
'(T2,A,F37.1,A)')
'Input: Available memory per MPI process', &
624 bs_env%input_memory_per_proc_GB,
' GB'
626 IF (bs_env%do_gw_ri_rs)
CALL print_gw_rirs_input(bs_env)
627 IF (bs_env%do_static_cohsex)
THEN
629 WRITE (u, fmt=
"(T2,A,T71,A10)")
"static COHSEX approximation (COHSEX)",
"QP_UPDATE"
631 WRITE (u, fmt=
"(T2,A,T71,A10)")
"static COHSEX approximation (COHSEX)",
"DIAGONAL"
633 WRITE (u, fmt=
"(T2,A,T74,F8.6)")
"static COHSEX scaling of Σ^c, occ-occ (COHSEX%SCALE_OCC):", &
634 bs_env%cohsex_scale_occ
635 WRITE (u, fmt=
"(T2,A,T74,F8.6)")
"static COHSEX scaling of Σ^c, virt-virt (COHSEX%SCALE_VIRT):", &
636 bs_env%cohsex_scale_virt
641 CALL timestop(handle)
643 END SUBROUTINE print_header_and_input_parameters
649 SUBROUTINE print_gw_rirs_input(bs_env)
652 CHARACTER(LEN=*),
PARAMETER :: routinen =
'print_gw_rirs_input'
654 INTEGER :: handle, unit_nr
656 CALL timeset(routinen, handle)
658 unit_nr = bs_env%unit_nr
660 WRITE (unit_nr,
'(A)')
' '
661 WRITE (unit_nr,
'(T2,A,ES43.2)')
'Input: RI-RS Tikhonov regularization', &
662 bs_env%ri_rs%tikhonov
663 CALL print_cutoff_radius_input(unit_nr,
'AO grid hard cutoff radius', &
664 bs_env%ri_rs%cutoff_radius_ri_ao)
665 CALL print_cutoff_radius_input(unit_nr,
'G/W panel truncation radius', &
666 bs_env%ri_rs%cutoff_radius_v_w)
667 WRITE (unit_nr,
'(T2,A,A62)')
'Input: GW flavour', trim(
gw_flavour_label(bs_env))
669 IF (bs_env%ri_rs%grid_opt%enabled)
THEN
670 WRITE (unit_nr,
'(A)')
' '
671 WRITE (unit_nr,
'(T2,A,T80,L1)') &
672 'Input: RI-RS grid optimization activated', .true.
673 WRITE (unit_nr,
'(T2,A,T69,F12.1)') &
674 'Input: RS points per AO function', bs_env%ri_rs%grid_opt%rs_ao_ratio
675 IF (bs_env%ri_rs%grid_opt%cutoff_atomic_cluster < 0.0_dp)
THEN
676 WRITE (unit_nr,
'(T2,A,T52,A29)') &
677 'Input: Atomic cluster radius',
'Automatic: 1.4 x nearest atom'
679 WRITE (unit_nr,
'(T2,A,T73,F6.1,A)') &
680 'Input: Cutoff radius for atomic clusters', &
681 bs_env%ri_rs%grid_opt%cutoff_atomic_cluster*
angstrom,
' Å'
683 WRITE (unit_nr,
'(T2,A,T75,I6)') &
684 'Input: Maximum grid optimization iterations', &
685 bs_env%ri_rs%grid_opt%max_iter
688 IF (bs_env%auto_ri%enabled)
THEN
689 WRITE (unit_nr,
'(A)')
' '
690 WRITE (unit_nr,
'(T2,A,T80,L1)') &
691 'Input: AUTO_RI basis optimization activated:', .true.
692 WRITE (unit_nr,
'(T2,A,T69,F12.1)') &
693 'Input: AUTO_RI number of RI functions per AO function:', bs_env%auto_ri%ri_ao_ratio
694 WRITE (unit_nr,
'(T2,A,T74,F4.1,A)') &
695 'Input: AUTO_RI frontier orbital window:', bs_env%auto_ri%occ_energy_window*
evolt,
' eV'
698 IF (bs_env%gw_flavour ==
evgw0)
THEN
699 WRITE (unit_nr,
'(T2,A,I42)')
'Input: Maximum number of evGW0 cycles', &
701 WRITE (unit_nr,
'(T2,A,F42.5,A)')
'Input: evGW0 convergence threshold', &
702 bs_env%evgw0_eps_iter*
evolt,
' eV'
704 WRITE (unit_nr,
'(A)')
' '
706 CALL timestop(handle)
708 END SUBROUTINE print_gw_rirs_input
716 SUBROUTINE print_cutoff_radius_input(unit_nr, label, cutoff_radius)
717 INTEGER,
INTENT(IN) :: unit_nr
718 CHARACTER(LEN=*),
INTENT(IN) :: label
719 REAL(kind=
dp),
INTENT(IN) :: cutoff_radius
721 CHARACTER(LEN=*),
PARAMETER :: routinen =
'print_cutoff_radius_input'
725 CALL timeset(routinen, handle)
727 IF (cutoff_radius > 0.0_dp)
THEN
728 WRITE (unit_nr,
'(T2,2A,T73,F6.2,A)') &
729 'Input: ', trim(label), cutoff_radius*
angstrom,
' Å'
732 CALL timestop(handle)
734 END SUBROUTINE print_cutoff_radius_input
741 SUBROUTINE setup_ao_and_ri_basis_set(qs_env, bs_env)
745 CHARACTER(LEN=*),
PARAMETER :: routinen =
'setup_AO_and_RI_basis_set'
747 INTEGER :: handle, ikind, natom, nkind, sort_basis
751 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
753 CALL timeset(routinen, handle)
756 qs_kind_set=qs_kind_set, &
757 particle_set=particle_set, &
758 natom=natom, nkind=nkind, dft_control=dft_control)
761 IF (bs_env%auto_ri%enabled)
THEN
764 NULLIFY (reference_basis)
765 CALL get_qs_kind(qs_kind_set(ikind), basis_set=reference_basis, basis_type=
"RI_AUX")
766 IF (.NOT.
ASSOCIATED(reference_basis))
THEN
768 dft_control%auto_basis_ri_aux, basis_sort=sort_basis)
769 IF (reference_basis%norm_type < 0) reference_basis%norm_type = 2
777 ALLOCATE (bs_env%sizes_RI(natom), bs_env%sizes_AO(natom))
778 ALLOCATE (bs_env%basis_set_RI(nkind), bs_env%basis_set_AO(nkind))
784 basis=bs_env%basis_set_RI)
786 basis=bs_env%basis_set_AO)
788 CALL timestop(handle)
790 END SUBROUTINE setup_ao_and_ri_basis_set
797 SUBROUTINE set_heuristic_parameters(bs_env, qs_env)
801 CHARACTER(LEN=*),
PARAMETER :: routinen =
'set_heuristic_parameters'
803 INTEGER :: exchange_grid(3), handle, u
804 LOGICAL :: do_bvk_cell
806 CALL timeset(routinen, handle)
809 bs_env%nparam_pade = 16
812 bs_env%num_points_per_magnitude = 200
814 IF (bs_env%input_regularization_minimax > -1.0e-12_dp)
THEN
815 bs_env%regularization_minimax = bs_env%input_regularization_minimax
820 IF (bs_env%do_periodic .OR. bs_env%num_time_freq_points >= 20)
THEN
821 bs_env%regularization_minimax = 1.0e-6_dp
823 bs_env%regularization_minimax = 0.0_dp
827 bs_env%stabilize_exp = 70.0_dp
828 bs_env%eps_atom_grid_2d_mat = 1.0e-50_dp
834 bs_env%nevanlinna%rcond_weights = 1.0e-10_dp
835 bs_env%nevanlinna%window_min_points = 6
836 bs_env%nevanlinna%window_freq_min = 10.0_dp/
evolt
837 bs_env%nevanlinna%window_freq_max = 100.0_dp/
evolt
838 bs_env%nevanlinna%window_spread = 0.05_dp/
evolt
839 bs_env%nevanlinna%qp_newton_max_step = 1.0_dp/
evolt
840 bs_env%nevanlinna%qp_maxz_radius = 1.5_dp/
evolt
845 bs_env%ri_metric%filename =
"t_c_g.dat"
848 CALL erfc_cutoff(1.0e-10_dp, bs_env%ri_metric%omega, bs_env%ri_metric%cutoff_radius)
849 bs_env%ri_metric%filename =
""
851 bs_env%ri_metric%omega = 0.0_dp
854 bs_env%eps_eigval_mat_RI = 0.0_dp
856 IF (bs_env%input_regularization_RI >= 0.0_dp)
THEN
857 bs_env%regularization_RI = bs_env%input_regularization_RI
860 bs_env%regularization_RI = 1.0e-8_dp
865 bs_env%regularization_RI = 1.0e-2_dp
868 IF (.NOT. bs_env%do_periodic) bs_env%regularization_RI = 0.0_dp
874 IF (bs_env%do_periodic)
THEN
877 SELECT CASE (bs_env%gw_implementation)
880 exchange_grid = bs_env%kpoints_scf_desymm%nkp_grid
882 exchange_grid = bs_env%cell_grid_scf_desymm
885 rel_cutoff_trunc_coulomb_ri_x=0.5_dp, &
886 cell_grid=exchange_grid, &
887 do_bvk_cell=do_bvk_cell)
890 bs_env%trunc_coulomb%cutoff_radius = -1.0_dp
891 bs_env%trunc_coulomb%omega = 0.0_dp
892 bs_env%trunc_coulomb%filename =
""
897 bs_env%heuristic_filter_factor = 1.0e-4_dp
901 IF (bs_env%do_periodic)
THEN
902 WRITE (u, fmt=
"(T2,2A,F21.1,A)")
"Cutoff radius for the truncated Coulomb ", &
903 "operator in Σ^x:", bs_env%trunc_coulomb%cutoff_radius*
angstrom,
" Å"
905 SELECT CASE (bs_env%ri_metric%potential_type)
907 WRITE (u, fmt=
"(T2,A,T61,F12.2,A)")
"Input: Attenuation of the RI metric:", &
908 bs_env%ri_metric%omega,
" bohr^-1"
910 WRITE (u, fmt=
"(T2,2A,F15.1,A)")
"Cutoff radius for the truncated Coulomb ", &
911 "operator in RI metric:", bs_env%ri_metric%cutoff_radius*
angstrom,
" Å"
913 IF (bs_env%num_time_freq_points < 35)
THEN
914 WRITE (u, fmt=
"(T2,A,ES38.1)")
"Regularization parameter of minimax grids", &
915 bs_env%regularization_minimax
918 WRITE (u, fmt=
"(T2,A,ES31.1)")
"SVD cutoff of minimax weights for Σ(iτ) -> Σ(iω)", &
919 bs_env%nevanlinna%rcond_weights
922 WRITE (u, fmt=
"(T2,A,T72,A9)")
"Coulomb matrix V(q) from",
"Ewald sum"
923 IF (all(bs_env%periodic == [1, 1, 0]))
THEN
924 WRITE (u, fmt=
"(T2,A,I43)")
"Lattice sum size for 2D V(q=0) body:", bs_env%size_lattice_sum_V
926 ELSE IF (bs_env%do_periodic)
THEN
927 WRITE (u, fmt=
"(T2,A,I53)")
"Lattice sum size for V(k):", bs_env%size_lattice_sum_V
931 CALL timestop(handle)
933 END SUBROUTINE set_heuristic_parameters
940 SUBROUTINE get_ri_basis(qs_env, bs_env)
944 CHARACTER(LEN=*),
PARAMETER :: routinen =
'get_RI_basis'
948 CALL timeset(routinen, handle)
950 CALL set_ao_ri_basis_function_indices(qs_env, bs_env)
951 CALL setup_kpoints_chi_eps_w(bs_env, bs_env%kpoints_chi_eps_W)
954 CALL setup_cells_3c(qs_env, bs_env)
956 CALL set_parallelization_parameters(qs_env, bs_env)
957 CALL allocate_matrices(qs_env, bs_env)
960 CALL compute_minv_gamma(qs_env, bs_env)
963 CALL timestop(handle)
965 END SUBROUTINE get_ri_basis
972 SUBROUTINE set_ao_ri_basis_function_indices(qs_env, bs_env)
976 CHARACTER(LEN=*),
PARAMETER :: routinen =
'set_AO_RI_basis_function_indices'
978 INTEGER :: handle, i_ri, iatom, ikind, iset, &
979 max_ao_bf_per_atom, n_ao_test, n_atom, &
980 n_kind, n_ri, nset, u
981 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: kind_of
982 INTEGER,
DIMENSION(:),
POINTER :: l_max, l_min, nsgf_set
985 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
987 CALL timeset(routinen, handle)
990 CALL get_qs_env(qs_env, atomic_kind_set=atomic_kind_set, qs_kind_set=qs_kind_set)
992 n_kind =
SIZE(qs_kind_set)
993 n_atom = bs_env%n_atom
998 CALL get_qs_kind(qs_kind_set(ikind), basis_set=basis, basis_type=
"RI_AUX")
999 cpassert(
ASSOCIATED(basis))
1002 ALLOCATE (bs_env%i_RI_start_from_atom(n_atom))
1003 ALLOCATE (bs_env%i_RI_end_from_atom(n_atom))
1004 ALLOCATE (bs_env%i_ao_start_from_atom(n_atom))
1005 ALLOCATE (bs_env%i_ao_end_from_atom(n_atom))
1008 DO iatom = 1, n_atom
1009 bs_env%i_RI_start_from_atom(iatom) = n_ri + 1
1010 n_ri = n_ri + bs_env%sizes_RI(iatom)
1011 bs_env%i_RI_end_from_atom(iatom) = n_ri
1015 max_ao_bf_per_atom = 0
1017 DO iatom = 1, n_atom
1018 bs_env%i_ao_start_from_atom(iatom) = n_ao_test + 1
1019 n_ao_test = n_ao_test + bs_env%sizes_AO(iatom)
1020 bs_env%i_ao_end_from_atom(iatom) = n_ao_test
1021 max_ao_bf_per_atom = max(max_ao_bf_per_atom, bs_env%sizes_AO(iatom))
1023 cpassert(n_ao_test == bs_env%n_ao)
1024 bs_env%max_AO_bf_per_atom = max_ao_bf_per_atom
1027 ALLOCATE (bs_env%l_RI(n_ri), source=-1)
1028 IF (bs_env%auto_ri%enabled)
THEN
1029 cpassert(bs_env%auto_ri%ready)
1032 DO iatom = 1, n_atom
1033 ikind = kind_of(iatom)
1034 nset = bs_env%basis_set_RI(ikind)%gto_basis_set%nset
1035 l_max => bs_env%basis_set_RI(ikind)%gto_basis_set%lmax
1036 l_min => bs_env%basis_set_RI(ikind)%gto_basis_set%lmin
1037 nsgf_set => bs_env%basis_set_RI(ikind)%gto_basis_set%nsgf_set
1039 cpassert(l_max(iset) == l_min(iset))
1040 bs_env%l_RI(i_ri + 1:i_ri + nsgf_set(iset)) = l_max(iset)
1041 i_ri = i_ri + nsgf_set(iset)
1044 cpassert(i_ri == n_ri)
1046 WRITE (u, fmt=
"(T2,A)")
" "
1047 WRITE (u, fmt=
"(T2,2A,T75,I8)")
"Number of auxiliary Gaussian basis functions ", &
1052 CALL timestop(handle)
1054 END SUBROUTINE set_ao_ri_basis_function_indices
1061 SUBROUTINE setup_kpoints_chi_eps_w(bs_env, kpoints_chi_eps_W)
1066 CHARACTER(LEN=*),
PARAMETER :: routinen =
'setup_kpoints_chi_eps_W'
1068 INTEGER :: handle, i_dim, n_dim, nkp, nkp_extra, &
1070 INTEGER,
DIMENSION(3) :: nkp_grid, nkp_grid_extra, periodic
1071 REAL(kind=
dp) :: exp_s_p, n_dim_inv
1073 CALL timeset(routinen, handle)
1076 NULLIFY (kpoints_chi_eps_w)
1079 kpoints_chi_eps_w%kp_scheme =
"GENERAL"
1081 periodic(1:3) = bs_env%periodic(1:3)
1083 cpassert(
SIZE(bs_env%nkp_grid_chi_eps_W_input) == 3)
1085 IF (bs_env%nkp_grid_chi_eps_W_input(1) > 0 .AND. &
1086 bs_env%nkp_grid_chi_eps_W_input(2) > 0 .AND. &
1087 bs_env%nkp_grid_chi_eps_W_input(3) > 0)
THEN
1092 SELECT CASE (periodic(i_dim))
1095 nkp_grid_extra(i_dim) = 1
1097 nkp_grid(i_dim) = bs_env%nkp_grid_chi_eps_W_input(i_dim)
1098 nkp_grid_extra(i_dim) = nkp_grid(i_dim)*2
1100 cpabort(
"Error in periodicity.")
1104 ELSE IF (bs_env%nkp_grid_chi_eps_W_input(1) == -1 .AND. &
1105 bs_env%nkp_grid_chi_eps_W_input(2) == -1 .AND. &
1106 bs_env%nkp_grid_chi_eps_W_input(3) == -1)
THEN
1112 cpassert(periodic(i_dim) == 0 .OR. periodic(i_dim) == 1)
1114 SELECT CASE (periodic(i_dim))
1117 nkp_grid_extra(i_dim) = 1
1119 SELECT CASE (bs_env%gw_implementation)
1122 nkp_grid_extra(i_dim) = 6
1124 nkp_grid(i_dim) = bs_env%kpoints_scf_desymm%nkp_grid(i_dim)
1125 nkp_grid_extra(i_dim) = 1
1127 nkp_grid(i_dim) = bs_env%kpoints_scf_desymm%nkp_grid(i_dim)*4
1128 nkp_grid_extra(i_dim) = bs_env%kpoints_scf_desymm%nkp_grid(i_dim)*8
1131 cpabort(
"Error in periodicity.")
1138 cpabort(
"An error occured when setting up the k-mesh for W.")
1142 nkp_orig = max(product(nkp_grid)/2, 1)
1143 nkp_extra = product(nkp_grid_extra)/2
1145 cpassert(all(nkp_grid == bs_env%kpoints_scf_desymm%nkp_grid))
1146 nkp_orig = product(nkp_grid)
1148 cpassert(nkp_orig == bs_env%nkp_scf_desymm)
1151 nkp = nkp_orig + nkp_extra
1153 kpoints_chi_eps_w%nkp_grid(1:3) = nkp_grid(1:3)
1154 kpoints_chi_eps_w%nkp = nkp
1156 bs_env%nkp_grid_chi_eps_W_orig(1:3) = nkp_grid(1:3)
1157 bs_env%nkp_grid_chi_eps_W_extra(1:3) = nkp_grid_extra(1:3)
1158 bs_env%nkp_chi_eps_W_orig = nkp_orig
1159 bs_env%nkp_chi_eps_W_orig_plus_extra = nkp
1161 ALLOCATE (kpoints_chi_eps_w%xkp(3, nkp), kpoints_chi_eps_w%wkp(nkp))
1162 ALLOCATE (bs_env%wkp_no_extra(nkp), bs_env%wkp_s_p(nkp))
1165 kpoints_chi_eps_w%xkp = bs_env%kpoints_scf_desymm%xkp(1:3, :)
1167 CALL compute_xkp(kpoints_chi_eps_w%xkp, 1, nkp_orig, nkp_grid)
1168 CALL compute_xkp(kpoints_chi_eps_w%xkp, nkp_orig + 1, nkp, nkp_grid_extra)
1171 n_dim = sum(periodic)
1172 IF (n_dim == 0)
THEN
1174 kpoints_chi_eps_w%wkp(1) = 1.0_dp
1175 bs_env%wkp_s_p(1) = 1.0_dp
1176 bs_env%wkp_no_extra(1) = 1.0_dp
1178 kpoints_chi_eps_w%wkp = 1.0_dp/real(nkp,
dp)
1179 bs_env%wkp_s_p(:) = kpoints_chi_eps_w%wkp
1180 bs_env%wkp_no_extra(:) = kpoints_chi_eps_w%wkp
1183 n_dim_inv = 1.0_dp/real(n_dim, kind=
dp)
1186 CALL compute_wkp(kpoints_chi_eps_w%wkp(1:nkp_orig), nkp_orig, nkp_extra, n_dim_inv)
1187 CALL compute_wkp(kpoints_chi_eps_w%wkp(nkp_orig + 1:nkp), &
1188 nkp_extra, nkp_orig, n_dim_inv)
1190 bs_env%wkp_no_extra(1:nkp_orig) = 0.0_dp
1191 bs_env%wkp_no_extra(nkp_orig + 1:nkp) = 1.0_dp/real(nkp_extra, kind=
dp)
1193 IF (n_dim == 3)
THEN
1196 exp_s_p = 2.0_dp*n_dim_inv
1197 CALL compute_wkp(bs_env%wkp_s_p(1:nkp_orig), nkp_orig, nkp_extra, exp_s_p)
1198 CALL compute_wkp(bs_env%wkp_s_p(nkp_orig + 1:nkp), nkp_extra, nkp_orig, exp_s_p)
1200 bs_env%wkp_s_p(1:nkp) = bs_env%wkp_no_extra(1:nkp)
1205 IF (bs_env%approx_kp_extrapol)
THEN
1206 bs_env%wkp_orig = 1.0_dp/real(nkp_orig, kind=
dp)
1212 bs_env%nkp_chi_eps_W_batch = 4
1214 bs_env%num_chi_eps_W_batches = (bs_env%nkp_chi_eps_W_orig_plus_extra - 1)/ &
1215 bs_env%nkp_chi_eps_W_batch + 1
1219 IF (u > 0 .AND. bs_env%do_periodic)
THEN
1220 WRITE (u, fmt=
"(T2,A)")
" "
1221 SELECT CASE (bs_env%gw_implementation)
1223 WRITE (u,
'(T2,A,T71,3I4)')
"K-point mesh for χ, ε, W", nkp_grid
1225 WRITE (u, fmt=
"(T2,1A,T71,3I4)")
"K-point mesh 1 for χ, ε, W", nkp_grid(1:3)
1226 WRITE (u, fmt=
"(T2,2A,T71,3I4)")
"K-point mesh 2 for χ, ε, W ", &
1227 "(for k-point extrapolation of W)", nkp_grid_extra(1:3)
1228 WRITE (u, fmt=
"(T2,A,T80,L)")
"Approximate the k-point extrapolation", &
1229 bs_env%approx_kp_extrapol
1233 CALL timestop(handle)
1235 END SUBROUTINE setup_kpoints_chi_eps_w
1246 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: xkp
1247 INTEGER :: ikp_start, ikp_end
1248 INTEGER,
DIMENSION(3) :: grid
1250 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_xkp'
1252 INTEGER :: handle, i, ix, iy, iz
1254 CALL timeset(routinen, handle)
1261 IF (i > ikp_end) cycle
1263 xkp(1, i) = real(2*ix - grid(1) - 1, kind=
dp)/(2._dp*real(grid(1), kind=
dp))
1264 xkp(2, i) = real(2*iy - grid(2) - 1, kind=
dp)/(2._dp*real(grid(2), kind=
dp))
1265 xkp(3, i) = real(2*iz - grid(3) - 1, kind=
dp)/(2._dp*real(grid(3), kind=
dp))
1272 CALL timestop(handle)
1283 SUBROUTINE compute_wkp(wkp, nkp_1, nkp_2, exponent)
1284 REAL(kind=
dp),
DIMENSION(:) :: wkp
1285 INTEGER :: nkp_1, nkp_2
1286 REAL(kind=
dp) :: exponent
1288 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_wkp'
1291 REAL(kind=
dp) :: nkp_ratio
1293 CALL timeset(routinen, handle)
1295 nkp_ratio = real(nkp_2, kind=
dp)/real(nkp_1, kind=
dp)
1297 wkp(:) = 1.0_dp/real(nkp_1, kind=
dp)/(1.0_dp - nkp_ratio**exponent)
1299 CALL timestop(handle)
1301 END SUBROUTINE compute_wkp
1308 SUBROUTINE setup_cells_3c(qs_env, bs_env)
1313 CHARACTER(LEN=*),
PARAMETER :: routinen =
'setup_cells_3c'
1315 INTEGER :: atom_i, atom_j, atom_k, block_count, handle, i, i_cell_x, i_cell_x_max, &
1316 i_cell_x_min, i_size, ikind, img, j, j_cell, j_cell_max, j_cell_y, j_cell_y_max, &
1317 j_cell_y_min, j_size, k_cell, k_cell_max, k_cell_z, k_cell_z_max, k_cell_z_min, k_size, &
1318 nimage_pairs_3c, nimages_3c, nimages_3c_max, nkind, u
1319 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: kind_of, n_other_3c_images_max
1320 INTEGER,
ALLOCATABLE,
DIMENSION(:, :) :: index_to_cell_3c_max, nblocks_3c_max
1321 INTEGER,
DIMENSION(3) :: cell_index, n_max
1322 REAL(kind=
dp) :: avail_mem_per_proc_gb, cell_dist, cell_radius_3c, dij, dik, djk, eps, &
1323 exp_min_ao, exp_min_ri, frobenius_norm, mem_3c_gb, mem_occ_per_proc_gb, radius_ao, &
1324 radius_ao_product, radius_ri
1325 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: exp_ao_kind, exp_ri_kind, &
1327 radius_ao_product_kind, radius_ri_kind
1328 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :, :) :: int_3c
1329 REAL(kind=
dp),
DIMENSION(3) :: rij, rik, rjk, vec_cell_j, vec_cell_k
1330 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: exp_ao, exp_ri
1335 CALL timeset(routinen, handle)
1337 CALL get_qs_env(qs_env, nkind=nkind, atomic_kind_set=atomic_kind_set, particle_set=particle_set, cell=cell)
1339 ALLOCATE (exp_ao_kind(nkind), exp_ri_kind(nkind), radius_ao_kind(nkind), &
1340 radius_ao_product_kind(nkind), radius_ri_kind(nkind))
1342 exp_min_ri = 10.0_dp
1343 exp_min_ao = 10.0_dp
1344 exp_ri_kind = 10.0_dp
1345 exp_ao_kind = 10.0_dp
1347 eps = bs_env%eps_filter*bs_env%heuristic_filter_factor
1356 DO i = 1,
SIZE(exp_ri, 1)
1357 DO j = 1,
SIZE(exp_ri, 2)
1358 IF (exp_ri(i, j) < exp_min_ri .AND. exp_ri(i, j) > 1e-3_dp) exp_min_ri = exp_ri(i, j)
1359 IF (exp_ri(i, j) < exp_ri_kind(ikind) .AND. exp_ri(i, j) > 1e-3_dp)
THEN
1360 exp_ri_kind(ikind) = exp_ri(i, j)
1364 DO i = 1,
SIZE(exp_ao, 1)
1365 DO j = 1,
SIZE(exp_ao, 2)
1366 IF (exp_ao(i, j) < exp_min_ao .AND. exp_ao(i, j) > 1e-3_dp) exp_min_ao = exp_ao(i, j)
1367 IF (exp_ao(i, j) < exp_ao_kind(ikind) .AND. exp_ao(i, j) > 1e-3_dp)
THEN
1368 exp_ao_kind(ikind) = exp_ao(i, j)
1372 radius_ao_kind(ikind) = sqrt(-log(eps)/exp_ao_kind(ikind))
1373 radius_ao_product_kind(ikind) = sqrt(-log(eps)/(2.0_dp*exp_ao_kind(ikind)))
1374 radius_ri_kind(ikind) = sqrt(-log(eps)/exp_ri_kind(ikind))
1377 radius_ao = sqrt(-log(eps)/exp_min_ao)
1378 radius_ao_product = sqrt(-log(eps)/(2.0_dp*exp_min_ao))
1379 radius_ri = sqrt(-log(eps)/exp_min_ri)
1384 cell_radius_3c = radius_ao_product + radius_ri + bs_env%ri_metric%cutoff_radius
1386 n_max(1:3) = bs_env%periodic(1:3)*30
1397 DO i_cell_x = -n_max(1), n_max(1)
1398 DO j_cell_y = -n_max(2), n_max(2)
1399 DO k_cell_z = -n_max(3), n_max(3)
1401 cell_index(1:3) = [i_cell_x, j_cell_y, k_cell_z]
1403 CALL get_cell_dist(cell_index, bs_env%hmat, cell_dist)
1405 IF (cell_dist < cell_radius_3c)
THEN
1406 nimages_3c_max = nimages_3c_max + 1
1407 i_cell_x_min = min(i_cell_x_min, i_cell_x)
1408 i_cell_x_max = max(i_cell_x_max, i_cell_x)
1409 j_cell_y_min = min(j_cell_y_min, j_cell_y)
1410 j_cell_y_max = max(j_cell_y_max, j_cell_y)
1411 k_cell_z_min = min(k_cell_z_min, k_cell_z)
1412 k_cell_z_max = max(k_cell_z_max, k_cell_z)
1421 ALLOCATE (index_to_cell_3c_max(3, nimages_3c_max))
1424 DO i_cell_x = -n_max(1), n_max(1)
1425 DO j_cell_y = -n_max(2), n_max(2)
1426 DO k_cell_z = -n_max(3), n_max(3)
1428 cell_index(1:3) = [i_cell_x, j_cell_y, k_cell_z]
1430 CALL get_cell_dist(cell_index, bs_env%hmat, cell_dist)
1432 IF (cell_dist < cell_radius_3c)
THEN
1434 index_to_cell_3c_max(1:3, img) = cell_index(1:3)
1442 ALLOCATE (nblocks_3c_max(nimages_3c_max, nimages_3c_max))
1443 nblocks_3c_max(:, :) = 0
1446 DO j_cell = 1, nimages_3c_max
1447 DO k_cell = 1, nimages_3c_max
1449 DO atom_j = 1, bs_env%n_atom
1450 DO atom_k = 1, bs_env%n_atom
1451 DO atom_i = 1, bs_env%n_atom
1453 block_count = block_count + 1
1454 IF (
modulo(block_count, bs_env%para_env%num_pe) /= bs_env%para_env%mepos) cycle
1456 CALL scaled_to_real(vec_cell_j, real(index_to_cell_3c_max(1:3, j_cell), kind=
dp), cell)
1457 CALL scaled_to_real(vec_cell_k, real(index_to_cell_3c_max(1:3, k_cell), kind=
dp), cell)
1459 rij =
pbc(particle_set(atom_j)%r(:), cell) -
pbc(particle_set(atom_i)%r(:), cell) + vec_cell_j(:)
1460 rjk =
pbc(particle_set(atom_k)%r(:), cell) -
pbc(particle_set(atom_j)%r(:), cell) &
1461 + vec_cell_k(:) - vec_cell_j(:)
1462 rik(:) = rij(:) + rjk(:)
1466 IF (djk > radius_ao_kind(kind_of(atom_j)) + radius_ao_kind(kind_of(atom_k))) cycle
1467 IF (dij > radius_ao_kind(kind_of(atom_j)) + radius_ri_kind(kind_of(atom_i)) &
1468 + bs_env%ri_metric%cutoff_radius) cycle
1469 IF (dik > radius_ri_kind(kind_of(atom_i)) + radius_ao_kind(kind_of(atom_k)) &
1470 + bs_env%ri_metric%cutoff_radius) cycle
1474 nblocks_3c_max(j_cell, k_cell) = nblocks_3c_max(j_cell, k_cell) + 1
1478 j_size = bs_env%i_ao_end_from_atom(atom_j) - bs_env%i_ao_start_from_atom(atom_j) + 1
1479 k_size = bs_env%i_ao_end_from_atom(atom_k) - bs_env%i_ao_start_from_atom(atom_k) + 1
1480 i_size = bs_env%i_RI_end_from_atom(atom_i) - bs_env%i_RI_start_from_atom(atom_i) + 1
1482 ALLOCATE (int_3c(j_size, k_size, i_size))
1487 basis_j=bs_env%basis_set_AO, &
1488 basis_k=bs_env%basis_set_AO, &
1489 basis_i=bs_env%basis_set_RI, &
1490 cell_j=index_to_cell_3c_max(1:3, j_cell), &
1491 cell_k=index_to_cell_3c_max(1:3, k_cell), &
1492 atom_k=atom_k, atom_j=atom_j, atom_i=atom_i)
1494 frobenius_norm = norm2(int_3c)
1500 IF (frobenius_norm > eps)
THEN
1501 nblocks_3c_max(j_cell, k_cell) = nblocks_3c_max(j_cell, k_cell) + 1
1511 CALL bs_env%para_env%sum(nblocks_3c_max)
1513 ALLOCATE (n_other_3c_images_max(nimages_3c_max))
1514 n_other_3c_images_max(:) = 0
1519 DO j_cell = 1, nimages_3c_max
1520 DO k_cell = 1, nimages_3c_max
1521 IF (nblocks_3c_max(j_cell, k_cell) > 0)
THEN
1522 n_other_3c_images_max(j_cell) = n_other_3c_images_max(j_cell) + 1
1523 nimage_pairs_3c = nimage_pairs_3c + 1
1527 IF (n_other_3c_images_max(j_cell) > 0) nimages_3c = nimages_3c + 1
1531 bs_env%nimages_3c = nimages_3c
1532 ALLOCATE (bs_env%index_to_cell_3c(3, nimages_3c))
1533 ALLOCATE (bs_env%cell_to_index_3c(i_cell_x_min:i_cell_x_max, &
1534 j_cell_y_min:j_cell_y_max, &
1535 k_cell_z_min:k_cell_z_max))
1536 bs_env%cell_to_index_3c(:, :, :) = -1
1538 ALLOCATE (bs_env%nblocks_3c(nimages_3c, nimages_3c))
1539 bs_env%nblocks_3c(nimages_3c, nimages_3c) = 0
1542 DO j_cell_max = 1, nimages_3c_max
1543 IF (n_other_3c_images_max(j_cell_max) == 0) cycle
1545 cell_index(1:3) = index_to_cell_3c_max(1:3, j_cell_max)
1546 bs_env%index_to_cell_3c(1:3, j_cell) = cell_index(1:3)
1547 bs_env%cell_to_index_3c(cell_index(1), cell_index(2), cell_index(3)) = j_cell
1550 DO k_cell_max = 1, nimages_3c_max
1551 IF (n_other_3c_images_max(k_cell_max) == 0) cycle
1554 bs_env%nblocks_3c(j_cell, k_cell) = nblocks_3c_max(j_cell_max, k_cell_max)
1560 mem_3c_gb = real(bs_env%n_RI, kind=
dp)*real(bs_env%n_ao, kind=
dp)**2 &
1561 *real(nimage_pairs_3c, kind=
dp)*8e-9_dp
1566 avail_mem_per_proc_gb = bs_env%input_memory_per_proc_GB - mem_occ_per_proc_gb
1569 bs_env%group_size_tensor = max(int(mem_3c_gb/avail_mem_per_proc_gb + 1.0_dp), 1)
1574 WRITE (u, fmt=
"(T2,A,F52.1,A)")
"Radius of atomic orbitals", radius_ao*
angstrom,
" Å"
1575 WRITE (u, fmt=
"(T2,A,F55.1,A)")
"Radius of RI functions", radius_ri*
angstrom,
" Å"
1576 WRITE (u, fmt=
"(T2,A,I47)")
"Number of cells for 3c integrals", nimages_3c
1577 WRITE (u, fmt=
"(T2,A,I42)")
"Number of cell pairs for 3c integrals", nimage_pairs_3c
1578 WRITE (u,
'(T2,A)')
''
1579 IF (bs_env%auto_memory_per_proc)
THEN
1580 WRITE (u,
'(T2,A,F34.1,A)')
'Detected: Available memory per MPI process', &
1581 bs_env%input_memory_per_proc_GB,
' GB'
1583 WRITE (u,
'(T2,A,F37.1,A)')
'Input: Available memory per MPI process', &
1584 bs_env%input_memory_per_proc_GB,
' GB'
1586 WRITE (u,
'(T2,A,F35.1,A)')
'Used memory per MPI process before GW run', &
1587 mem_occ_per_proc_gb,
' GB'
1588 WRITE (u,
'(T2,A,F44.1,A)')
'Memory of three-center integrals', mem_3c_gb,
' GB'
1591 CALL timestop(handle)
1593 END SUBROUTINE setup_cells_3c
1601 SUBROUTINE get_cell_dist(cell_index, hmat, cell_dist)
1603 INTEGER,
DIMENSION(3) :: cell_index
1604 REAL(kind=
dp) :: hmat(3, 3), cell_dist
1606 CHARACTER(LEN=*),
PARAMETER :: routinen =
'get_cell_dist'
1608 INTEGER :: handle, i_dim
1609 INTEGER,
DIMENSION(3) :: cell_index_adj
1610 REAL(kind=
dp) :: cell_dist_3(3)
1612 CALL timeset(routinen, handle)
1617 IF (cell_index(i_dim) > 0) cell_index_adj(i_dim) = cell_index(i_dim) - 1
1618 IF (cell_index(i_dim) < 0) cell_index_adj(i_dim) = cell_index(i_dim) + 1
1619 IF (cell_index(i_dim) == 0) cell_index_adj(i_dim) = cell_index(i_dim)
1622 cell_dist_3(1:3) = matmul(hmat, real(cell_index_adj, kind=
dp))
1624 cell_dist = norm2(cell_dist_3)
1626 CALL timestop(handle)
1628 END SUBROUTINE get_cell_dist
1635 SUBROUTINE set_parallelization_parameters(qs_env, bs_env)
1639 CHARACTER(LEN=*),
PARAMETER :: routinen =
'set_parallelization_parameters'
1641 INTEGER :: color_sub, dummy_1, dummy_2, handle, &
1642 num_pe, num_t_groups, u
1645 CALL timeset(routinen, handle)
1649 num_pe = para_env%num_pe
1652 IF (bs_env%group_size_tensor < 0 .OR. bs_env%group_size_tensor > num_pe)
THEN
1653 bs_env%group_size_tensor = num_pe
1657 IF (
modulo(num_pe, bs_env%group_size_tensor) /= 0)
THEN
1658 CALL find_good_group_size(num_pe, bs_env%group_size_tensor)
1662 color_sub = para_env%mepos/bs_env%group_size_tensor
1663 bs_env%tensor_group_color = color_sub
1665 ALLOCATE (bs_env%para_env_tensor)
1666 CALL bs_env%para_env_tensor%from_split(para_env, color_sub)
1668 num_t_groups = para_env%num_pe/bs_env%group_size_tensor
1669 bs_env%num_tensor_groups = num_t_groups
1671 CALL get_i_j_atoms(bs_env%atoms_i, bs_env%atoms_j, bs_env%n_atom_i, bs_env%n_atom_j, &
1674 ALLOCATE (bs_env%atoms_i_t_group(2, num_t_groups))
1675 ALLOCATE (bs_env%atoms_j_t_group(2, num_t_groups))
1676 DO color_sub = 0, num_t_groups - 1
1677 CALL get_i_j_atoms(bs_env%atoms_i_t_group(1:2, color_sub + 1), &
1678 bs_env%atoms_j_t_group(1:2, color_sub + 1), &
1679 dummy_1, dummy_2, color_sub, bs_env)
1683 IF (u > 0 .AND. .NOT. bs_env%do_gw_ri_rs)
THEN
1684 WRITE (u,
'(T2,A,I47)')
'Group size for tensor operations', bs_env%group_size_tensor
1685 IF (bs_env%group_size_tensor > 1 .AND. bs_env%n_atom < 5)
THEN
1686 WRITE (u,
'(T2,A)')
'The requested group size is > 1 which can lead to bad performance.'
1687 WRITE (u,
'(T2,A)')
'Using more memory per MPI process might improve performance.'
1688 WRITE (u,
'(T2,A)')
'(Also increase MEMORY_PER_PROC when using more memory per process.)'
1692 CALL timestop(handle)
1694 END SUBROUTINE set_parallelization_parameters
1701 SUBROUTINE find_good_group_size(num_pe, group_size)
1703 INTEGER :: num_pe, group_size
1705 CHARACTER(LEN=*),
PARAMETER :: routinen =
'find_good_group_size'
1707 INTEGER :: group_size_minus, group_size_orig, &
1708 group_size_plus, handle, i_diff
1710 CALL timeset(routinen, handle)
1712 group_size_orig = group_size
1714 DO i_diff = 1, num_pe
1716 group_size_minus = group_size - i_diff
1718 IF (
modulo(num_pe, group_size_minus) == 0 .AND. group_size_minus > 0)
THEN
1719 group_size = group_size_minus
1723 group_size_plus = group_size + i_diff
1725 IF (
modulo(num_pe, group_size_plus) == 0 .AND. group_size_plus <= num_pe)
THEN
1726 group_size = group_size_plus
1732 IF (group_size_orig == group_size) cpabort(
"Group size error")
1734 CALL timestop(handle)
1736 END SUBROUTINE find_good_group_size
1747 SUBROUTINE get_i_j_atoms(atoms_i, atoms_j, n_atom_i, n_atom_j, color_sub, bs_env)
1749 INTEGER,
DIMENSION(2) :: atoms_i, atoms_j
1750 INTEGER :: n_atom_i, n_atom_j, color_sub
1753 CHARACTER(LEN=*),
PARAMETER :: routinen =
'get_i_j_atoms'
1755 INTEGER :: handle, i_atoms_per_group, i_group, &
1756 ipcol, ipcol_loop, iprow, iprow_loop, &
1757 j_atoms_per_group, npcol, nprow
1759 CALL timeset(routinen, handle)
1762 CALL square_mesh(nprow, npcol, bs_env%num_tensor_groups)
1765 DO ipcol_loop = 0, npcol - 1
1766 DO iprow_loop = 0, nprow - 1
1767 IF (i_group == color_sub)
THEN
1771 i_group = i_group + 1
1775 IF (
modulo(bs_env%n_atom, nprow) == 0)
THEN
1776 i_atoms_per_group = bs_env%n_atom/nprow
1778 i_atoms_per_group = bs_env%n_atom/nprow + 1
1781 IF (
modulo(bs_env%n_atom, npcol) == 0)
THEN
1782 j_atoms_per_group = bs_env%n_atom/npcol
1784 j_atoms_per_group = bs_env%n_atom/npcol + 1
1787 atoms_i(1) = iprow*i_atoms_per_group + 1
1788 atoms_i(2) = min((iprow + 1)*i_atoms_per_group, bs_env%n_atom)
1789 n_atom_i = atoms_i(2) - atoms_i(1) + 1
1791 atoms_j(1) = ipcol*j_atoms_per_group + 1
1792 atoms_j(2) = min((ipcol + 1)*j_atoms_per_group, bs_env%n_atom)
1793 n_atom_j = atoms_j(2) - atoms_j(1) + 1
1795 CALL timestop(handle)
1797 END SUBROUTINE get_i_j_atoms
1805 SUBROUTINE square_mesh(nprow, npcol, nproc)
1806 INTEGER :: nprow, npcol, nproc
1808 CHARACTER(LEN=*),
PARAMETER :: routinen =
'square_mesh'
1810 INTEGER :: gcd_max, handle, ipe, jpe
1812 CALL timeset(routinen, handle)
1815 DO ipe = 1, ceiling(sqrt(real(nproc,
dp)))
1817 IF (ipe*jpe /= nproc) cycle
1818 IF (
gcd(ipe, jpe) >= gcd_max)
THEN
1821 gcd_max =
gcd(ipe, jpe)
1825 CALL timestop(handle)
1827 END SUBROUTINE square_mesh
1834 SUBROUTINE allocate_matrices(qs_env, bs_env)
1838 CHARACTER(LEN=*),
PARAMETER :: routinen =
'allocate_matrices'
1840 INTEGER :: handle, i_t
1845 CALL timeset(routinen, handle)
1847 CALL get_qs_env(qs_env, para_env=para_env, blacs_env=blacs_env)
1849 fm_struct => bs_env%fm_ks_Gamma(1)%matrix_struct
1854 NULLIFY (fm_struct_ri_global)
1855 CALL cp_fm_struct_create(fm_struct_ri_global, context=blacs_env, nrow_global=bs_env%n_RI, &
1856 ncol_global=bs_env%n_RI, para_env=para_env)
1857 CALL cp_fm_create(bs_env%fm_RI_RI, fm_struct_ri_global)
1858 CALL cp_fm_create(bs_env%fm_chi_Gamma_freq, fm_struct_ri_global)
1859 CALL cp_fm_create(bs_env%fm_W_MIC_freq, fm_struct_ri_global)
1860 IF (bs_env%approx_kp_extrapol)
THEN
1861 CALL cp_fm_create(bs_env%fm_W_MIC_freq_1_extra, fm_struct_ri_global)
1862 CALL cp_fm_create(bs_env%fm_W_MIC_freq_1_no_extra, fm_struct_ri_global)
1868 IF (.NOT. bs_env%do_gw_ri_rs)
THEN
1870 NULLIFY (blacs_env_tensor)
1877 CALL create_mat_munu(bs_env%mat_ao_ao_tensor, qs_env, bs_env%eps_atom_grid_2d_mat, &
1878 blacs_env_tensor, do_ri_aux_basis=.false.)
1880 CALL create_mat_munu(bs_env%mat_RI_RI_tensor, qs_env, bs_env%eps_atom_grid_2d_mat, &
1881 blacs_env_tensor, do_ri_aux_basis=.true.)
1886 CALL create_mat_munu(bs_env%mat_RI_RI, qs_env, bs_env%eps_atom_grid_2d_mat, &
1887 blacs_env, do_ri_aux_basis=.true., &
1888 custom_row_blk_sizes=bs_env%sizes_RI)
1890 NULLIFY (bs_env%mat_chi_Gamma_tau)
1893 DO i_t = 1, bs_env%num_time_freq_points
1894 ALLOCATE (bs_env%mat_chi_Gamma_tau(i_t)%matrix)
1895 CALL dbcsr_create(bs_env%mat_chi_Gamma_tau(i_t)%matrix, template=bs_env%mat_RI_RI%matrix)
1898 CALL timestop(handle)
1900 END SUBROUTINE allocate_matrices
1907 SUBROUTINE compute_minv_gamma(qs_env, bs_env)
1911 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_Minv_Gamma'
1914 REAL(kind=
dp) :: eigenvalue_threshold, &
1915 metric_regularization
1916 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:, :) :: fm_m
1918 CALL timeset(routinen, handle)
1920 CALL cp_fm_create(bs_env%fm_Minv_Gamma, bs_env%fm_RI_RI%matrix_struct)
1921 IF (bs_env%auto_ri%enabled)
THEN
1922 cpassert(bs_env%auto_ri%ready)
1923 CALL cp_fm_to_fm(bs_env%auto_ri%M_pq_inv, bs_env%fm_Minv_Gamma)
1925 metric_regularization = 0.0_dp
1926 eigenvalue_threshold = 0.0_dp
1927 IF (bs_env%do_gw_ri_rs)
THEN
1928 metric_regularization = bs_env%regularization_RI
1929 eigenvalue_threshold = bs_env%eps_eigval_mat_RI
1933 regularization_ri=metric_regularization)
1934 CALL fm_invert(fm_m(1, 1), eigenvalue_threshold, bs_env%unit_nr)
1935 CALL cp_fm_to_fm(fm_m(1, 1), bs_env%fm_Minv_Gamma)
1939 CALL timestop(handle)
1941 END SUBROUTINE compute_minv_gamma
1948 SUBROUTINE compute_v_xc(qs_env, bs_env)
1952 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_V_xc'
1954 INTEGER :: handle, img, ispin, myfun, nimages
1955 LOGICAL :: hf_present
1956 REAL(kind=
dp) :: energy_ex, energy_exc, energy_total, &
1958 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: mat_ks_without_v_xc
1959 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_ks_kp
1964 CALL timeset(routinen, handle)
1966 CALL get_qs_env(qs_env, input=input, energy=energy, dft_control=dft_control)
1969 nimages = dft_control%nimages
1970 dft_control%nimages = bs_env%nimages_scf
1977 hf_present = .false.
1978 IF (
ASSOCIATED(hf_section))
THEN
1981 IF (hf_present)
THEN
1988 energy_total = energy%total
1989 energy_exc = energy%exc
1990 energy_ex = energy%ex
1992 SELECT CASE (bs_env%gw_implementation)
1995 NULLIFY (mat_ks_without_v_xc)
1998 DO ispin = 1, bs_env%n_spin
1999 ALLOCATE (mat_ks_without_v_xc(ispin)%matrix)
2000 IF (hf_present)
THEN
2001 CALL dbcsr_create(mat_ks_without_v_xc(ispin)%matrix, template=bs_env%mat_ao_ao%matrix, &
2002 matrix_type=dbcsr_type_symmetric)
2004 CALL dbcsr_create(mat_ks_without_v_xc(ispin)%matrix, template=bs_env%mat_ao_ao%matrix)
2010 ext_ks_matrix=mat_ks_without_v_xc)
2012 DO ispin = 1, bs_env%n_spin
2014 CALL cp_fm_create(bs_env%fm_V_xc_Gamma(ispin), bs_env%fm_s_Gamma%matrix_struct)
2015 CALL copy_dbcsr_to_fm(mat_ks_without_v_xc(ispin)%matrix, bs_env%fm_V_xc_Gamma(ispin))
2019 beta=1.0_dp, matrix_b=bs_env%fm_ks_Gamma(ispin))
2027 CALL build_periodic_ks_with_gapw_density(qs_env)
2028 CALL get_qs_env(qs_env=qs_env, matrix_ks_kp=matrix_ks_kp)
2030 ALLOCATE (bs_env%fm_V_xc_R(dft_control%nimages, bs_env%n_spin))
2031 DO ispin = 1, bs_env%n_spin
2032 DO img = 1, dft_control%nimages
2034 CALL copy_dbcsr_to_fm(matrix_ks_kp(ispin, img)%matrix, bs_env%fm_work_mo(1))
2035 CALL cp_fm_create(bs_env%fm_V_xc_R(img, ispin), bs_env%fm_work_mo(1)%matrix_struct, &
2039 beta=1.0_dp, matrix_b=bs_env%fm_work_mo(1))
2046 energy%total = energy_total
2047 energy%exc = energy_exc
2048 energy%ex = energy_ex
2051 dft_control%nimages = nimages
2056 IF (hf_present)
THEN
2064 CALL build_periodic_ks_with_gapw_density(qs_env)
2065 DO ispin = 1, bs_env%n_spin
2066 DO img = 1, dft_control%nimages
2068 CALL copy_dbcsr_to_fm(matrix_ks_kp(ispin, img)%matrix, bs_env%fm_work_mo(1))
2071 beta=1.0_dp, matrix_b=bs_env%fm_work_mo(1))
2076 CALL timestop(handle)
2078 END SUBROUTINE compute_v_xc
2084 SUBROUTINE build_periodic_ks_with_gapw_density(qs_env)
2090 CALL get_qs_env(qs_env, dft_control=dft_control)
2091 IF (dft_control%qs_control%gapw .OR. dft_control%qs_control%gapw_xc)
THEN
2097 END SUBROUTINE build_periodic_ks_with_gapw_density
2103 SUBROUTINE init_interaction_radii(bs_env)
2106 CHARACTER(LEN=*),
PARAMETER :: routinen =
'init_interaction_radii'
2108 INTEGER :: handle, ibasis
2111 CALL timeset(routinen, handle)
2113 DO ibasis = 1,
SIZE(bs_env%basis_set_AO)
2115 orb_basis => bs_env%basis_set_AO(ibasis)%gto_basis_set
2118 ri_basis => bs_env%basis_set_RI(ibasis)%gto_basis_set
2123 CALL timestop(handle)
2125 END SUBROUTINE init_interaction_radii
2132 SUBROUTINE create_tensors(qs_env, bs_env)
2136 CHARACTER(LEN=*),
PARAMETER :: routinen =
'create_tensors'
2140 CALL timeset(routinen, handle)
2144 CALL create_3c_t(bs_env%t_RI_AO__AO, bs_env%para_env_tensor,
"(RI AO | AO)", [1, 2], [3], &
2145 bs_env%sizes_RI, bs_env%sizes_AO, &
2146 create_nl_3c=.true., nl_3c=bs_env%nl_3c, qs_env=qs_env)
2147 CALL create_3c_t(bs_env%t_RI__AO_AO, bs_env%para_env_tensor,
"(RI | AO AO)", [1], [2, 3], &
2148 bs_env%sizes_RI, bs_env%sizes_AO)
2150 CALL create_2c_t(bs_env)
2152 CALL timestop(handle)
2154 END SUBROUTINE create_tensors
2169 SUBROUTINE create_3c_t(tensor, para_env, tensor_name, map1, map2, sizes_RI, sizes_AO, &
2170 create_nl_3c, nl_3c, qs_env)
2173 CHARACTER(LEN=12) :: tensor_name
2174 INTEGER,
DIMENSION(:) :: map1, map2
2175 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: sizes_ri, sizes_ao
2176 LOGICAL,
OPTIONAL :: create_nl_3c
2180 CHARACTER(LEN=*),
PARAMETER :: routinen =
'create_3c_t'
2182 INTEGER :: handle, nkind
2183 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: dist_ao_1, dist_ao_2, dist_ri
2184 INTEGER,
DIMENSION(3) :: pcoord, pdims, pdims_3d
2185 LOGICAL :: my_create_nl_3c
2186 TYPE(dbt_pgrid_type) :: pgrid_3d
2191 CALL timeset(routinen, handle)
2194 CALL dbt_pgrid_create(para_env, pdims_3d, pgrid_3d)
2196 pgrid_3d, sizes_ri, sizes_ao, sizes_ao, &
2197 map1=map1, map2=map2, name=tensor_name)
2199 IF (
PRESENT(create_nl_3c))
THEN
2200 my_create_nl_3c = create_nl_3c
2202 my_create_nl_3c = .false.
2205 IF (my_create_nl_3c)
THEN
2206 CALL get_qs_env(qs_env, nkind=nkind, particle_set=particle_set)
2207 CALL dbt_mp_environ_pgrid(pgrid_3d, pdims, pcoord)
2208 CALL mp_comm_t3c_2%create(pgrid_3d%mp_comm_2d, 3, pdims)
2210 nkind, particle_set, mp_comm_t3c_2, own_comm=.true.)
2213 qs_env%bs_env%basis_set_RI, &
2214 qs_env%bs_env%basis_set_AO, &
2215 qs_env%bs_env%basis_set_AO, &
2216 dist_3d, qs_env%bs_env%ri_metric, &
2217 "GW_3c_nl", qs_env, own_dist=.true.)
2220 DEALLOCATE (dist_ri, dist_ao_1, dist_ao_2)
2221 CALL dbt_pgrid_destroy(pgrid_3d)
2223 CALL timestop(handle)
2225 END SUBROUTINE create_3c_t
2231 SUBROUTINE create_2c_t(bs_env)
2234 CHARACTER(LEN=*),
PARAMETER :: routinen =
'create_2c_t'
2237 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: dist_1, dist_2
2238 INTEGER,
DIMENSION(2) :: pdims_2d
2239 TYPE(dbt_pgrid_type) :: pgrid_2d
2241 CALL timeset(routinen, handle)
2246 CALL dbt_pgrid_create(bs_env%para_env_tensor, pdims_2d, pgrid_2d)
2249 bs_env%sizes_AO, bs_env%sizes_AO, &
2251 DEALLOCATE (dist_1, dist_2)
2253 bs_env%sizes_RI, bs_env%sizes_RI, &
2255 DEALLOCATE (dist_1, dist_2)
2257 bs_env%sizes_RI, bs_env%sizes_RI, &
2259 DEALLOCATE (dist_1, dist_2)
2260 CALL dbt_pgrid_destroy(pgrid_2d)
2262 CALL timestop(handle)
2264 END SUBROUTINE create_2c_t
2270 SUBROUTINE allocate_gw_eigenvalues(bs_env)
2273 CHARACTER(LEN=*),
PARAMETER :: routinen =
'allocate_GW_eigenvalues'
2275 INTEGER :: handle, n_ao, n_spin, nkp
2277 CALL timeset(routinen, handle)
2280 nkp = bs_env%nkp_bs_and_DOS
2281 n_spin = bs_env%n_spin
2283 IF (.NOT.
ALLOCATED(bs_env%eigenval_GW))
THEN
2284 ALLOCATE (bs_env%eigenval_GW(n_ao, nkp, n_spin))
2286 IF (.NOT.
ALLOCATED(bs_env%eigenval_HF))
THEN
2287 ALLOCATE (bs_env%eigenval_HF(n_ao, nkp, n_spin))
2290 SELECT CASE (bs_env%gw_flavour)
2292 IF (.NOT.
ALLOCATED(bs_env%eigenval_G0W0))
THEN
2293 ALLOCATE (bs_env%eigenval_G0W0(n_ao, nkp, n_spin))
2297 IF (bs_env%gw_flavour ==
evgw0 .AND. .NOT.
ALLOCATED(bs_env%eigenval_evGW0))
THEN
2298 ALLOCATE (bs_env%eigenval_evGW0(n_ao, nkp, n_spin))
2301 CALL timestop(handle)
2303 END SUBROUTINE allocate_gw_eigenvalues
2310 SUBROUTINE check_sparsity_3c(qs_env, bs_env)
2314 CHARACTER(LEN=*),
PARAMETER :: routinen =
'check_sparsity_3c'
2316 INTEGER :: handle, n_atom_step, ri_atom
2317 INTEGER(int_8) :: non_zero_elements_sum, nze
2318 REAL(
dp) :: max_dist_ao_atoms, occ, occupation_sum
2319 REAL(kind=
dp) :: t1, t2
2320 TYPE(dbt_type),
ALLOCATABLE,
DIMENSION(:, :) :: t_3c_global_array
2322 CALL timeset(routinen, handle)
2327 ALLOCATE (t_3c_global_array(1, 1))
2328 CALL dbt_create(bs_env%t_RI_AO__AO, t_3c_global_array(1, 1))
2332 ALLOCATE (bs_env%min_RI_idx_from_AO_AO_atom(bs_env%n_atom, bs_env%n_atom))
2333 ALLOCATE (bs_env%max_RI_idx_from_AO_AO_atom(bs_env%n_atom, bs_env%n_atom))
2334 ALLOCATE (bs_env%min_AO_idx_from_RI_AO_atom(bs_env%n_atom, bs_env%n_atom))
2335 ALLOCATE (bs_env%max_AO_idx_from_RI_AO_atom(bs_env%n_atom, bs_env%n_atom))
2336 bs_env%min_RI_idx_from_AO_AO_atom(:, :) = bs_env%n_RI
2337 bs_env%max_RI_idx_from_AO_AO_atom(:, :) = 1
2338 bs_env%min_AO_idx_from_RI_AO_atom(:, :) = bs_env%n_AO
2339 bs_env%max_AO_idx_from_RI_AO_atom(:, :) = 1
2341 CALL bs_env%para_env%sync()
2344 occupation_sum = 0.0_dp
2345 non_zero_elements_sum = 0
2346 max_dist_ao_atoms = 0.0_dp
2347 n_atom_step = int(sqrt(real(bs_env%n_atom, kind=
dp)))
2349 DO ri_atom = 1, bs_env%n_atom, n_atom_step
2352 bs_env%eps_filter, &
2355 int_eps=bs_env%eps_filter, &
2356 basis_i=bs_env%basis_set_RI, &
2357 basis_j=bs_env%basis_set_AO, &
2358 basis_k=bs_env%basis_set_AO, &
2359 bounds_i=[ri_atom, min(ri_atom + n_atom_step - 1, bs_env%n_atom)], &
2360 potential_parameter=bs_env%ri_metric, &
2361 desymmetrize=.false.)
2363 CALL dbt_filter(t_3c_global_array(1, 1), bs_env%eps_filter)
2365 CALL bs_env%para_env%sync()
2368 non_zero_elements_sum = non_zero_elements_sum + nze
2369 occupation_sum = occupation_sum + occ
2371 CALL get_max_dist_ao_atoms(t_3c_global_array(1, 1), max_dist_ao_atoms, qs_env)
2374 CALL get_i_j_atom_ranges(t_3c_global_array(1, 1), bs_env)
2376 CALL dbt_clear(t_3c_global_array(1, 1))
2383 bs_env%max_dist_AO_atoms = max_dist_ao_atoms
2385 bs_env%occupation_3c_int = occupation_sum
2387 CALL bs_env%para_env%min(bs_env%min_RI_idx_from_AO_AO_atom)
2388 CALL bs_env%para_env%max(bs_env%max_RI_idx_from_AO_AO_atom)
2389 CALL bs_env%para_env%min(bs_env%min_AO_idx_from_RI_AO_atom)
2390 CALL bs_env%para_env%max(bs_env%max_AO_idx_from_RI_AO_atom)
2392 CALL dbt_destroy(t_3c_global_array(1, 1))
2393 DEALLOCATE (t_3c_global_array)
2395 IF (bs_env%unit_nr > 0)
THEN
2396 WRITE (bs_env%unit_nr,
'(T2,A)')
''
2397 WRITE (bs_env%unit_nr,
'(T2,A,F27.1,A)') &
2398 'Computed 3-center integrals (µν|P), Exec. time', t2 - t1,
' s'
2399 WRITE (bs_env%unit_nr,
'(T2,A,F48.3,A)')
'Percentage of non-zero (µν|P)', &
2400 bs_env%occupation_3c_int*100,
' %'
2401 WRITE (bs_env%unit_nr,
'(T2,A,F33.1,A)')
'Max. distance between µ,ν in non-zero (µν|P)', &
2402 bs_env%max_dist_AO_atoms*
angstrom,
' A'
2403 WRITE (bs_env%unit_nr,
'(T2,2A,I20,A)')
'Required memory if storing all 3-center ', &
2404 'integrals (µν|P)', int(real(non_zero_elements_sum, kind=
dp)*8.0e-9_dp),
' GB'
2407 CALL timestop(handle)
2409 END SUBROUTINE check_sparsity_3c
2417 SUBROUTINE get_max_dist_ao_atoms(t_3c_int, max_dist_AO_atoms, qs_env)
2418 TYPE(dbt_type) :: t_3c_int
2419 REAL(kind=
dp),
INTENT(INOUT) :: max_dist_ao_atoms
2422 CHARACTER(LEN=*),
PARAMETER :: routinen =
'get_max_dist_AO_atoms'
2424 INTEGER :: atom_1, atom_2, handle, num_cells
2425 INTEGER,
DIMENSION(3) :: atom_ind
2426 INTEGER,
DIMENSION(:, :),
POINTER :: index_to_cell
2427 REAL(kind=
dp) :: abs_rab
2428 REAL(kind=
dp),
DIMENSION(3) :: rab
2430 TYPE(dbt_iterator_type) :: iter
2434 CALL timeset(routinen, handle)
2436 NULLIFY (cell, particle_set, para_env)
2437 CALL get_qs_env(qs_env, cell=cell, particle_set=particle_set, para_env=para_env)
2448 CALL dbt_iterator_start(iter, t_3c_int)
2449 DO WHILE (dbt_iterator_blocks_left(iter))
2450 CALL dbt_iterator_next_block(iter, atom_ind)
2452 atom_1 = atom_ind(2)
2453 atom_2 = atom_ind(3)
2454 rab =
pbc(particle_set(atom_1)%r(1:3), particle_set(atom_2)%r(1:3), cell)
2455 abs_rab = sqrt(rab(1)**2 + rab(2)**2 + rab(3)**2)
2458 max_dist_ao_atoms = max(max_dist_ao_atoms, abs_rab)
2461 CALL dbt_iterator_stop(iter)
2464 CALL para_env%max(max_dist_ao_atoms)
2466 CALL timestop(handle)
2468 END SUBROUTINE get_max_dist_ao_atoms
2475 SUBROUTINE get_i_j_atom_ranges(t_3c, bs_env)
2476 TYPE(dbt_type) :: t_3c
2479 CHARACTER(LEN=*),
PARAMETER :: routinen =
'get_i_j_atom_ranges'
2481 INTEGER :: handle, idx_ao_end, idx_ao_start, &
2482 idx_ri_end, idx_ri_start
2483 INTEGER,
DIMENSION(3) :: atom_ind
2484 TYPE(dbt_iterator_type) :: iter
2486 CALL timeset(routinen, handle)
2494 CALL dbt_iterator_start(iter, t_3c)
2495 DO WHILE (dbt_iterator_blocks_left(iter))
2496 CALL dbt_iterator_next_block(iter, atom_ind)
2499 idx_ri_start = bs_env%i_RI_start_from_atom(atom_ind(1))
2500 idx_ri_end = bs_env%i_RI_end_from_atom(atom_ind(1))
2502 idx_ao_start = bs_env%i_ao_start_from_atom(atom_ind(2))
2503 idx_ao_end = bs_env%i_ao_end_from_atom(atom_ind(2))
2507 bs_env%min_RI_idx_from_AO_AO_atom(atom_ind(2), atom_ind(3)) = &
2508 min(bs_env%min_RI_idx_from_AO_AO_atom(atom_ind(2), atom_ind(3)), idx_ri_start)
2510 bs_env%max_RI_idx_from_AO_AO_atom(atom_ind(2), atom_ind(3)) = &
2511 max(bs_env%max_RI_idx_from_AO_AO_atom(atom_ind(2), atom_ind(3)), idx_ri_end)
2514 bs_env%min_AO_idx_from_RI_AO_atom(atom_ind(1), atom_ind(3)) = &
2515 min(bs_env%min_AO_idx_from_RI_AO_atom(atom_ind(1), atom_ind(3)), idx_ao_start)
2517 bs_env%max_AO_idx_from_RI_AO_atom(atom_ind(1), atom_ind(3)) = &
2518 max(bs_env%max_AO_idx_from_RI_AO_atom(atom_ind(1), atom_ind(3)), idx_ao_end)
2521 CALL dbt_iterator_stop(iter)
2524 CALL timestop(handle)
2526 END SUBROUTINE get_i_j_atom_ranges
2532 SUBROUTINE set_sparsity_parallelization_parameters(bs_env)
2535 CHARACTER(LEN=*),
PARAMETER :: routinen =
'set_sparsity_parallelization_parameters'
2537 INTEGER :: handle, i_ivl, il_ivl, j_ivl, n_atom_per_il_ivl, n_atom_per_ivl, n_intervals_i, &
2538 n_intervals_inner_loop_atoms, n_intervals_j, u
2539 INTEGER(KIND=int_8) :: input_memory_per_proc
2541 CALL timeset(routinen, handle)
2544 bs_env%safety_factor_memory = 0.10_dp
2546 input_memory_per_proc = int(bs_env%input_memory_per_proc_GB*1.0e9_dp, kind=
int_8)
2552 n_atom_per_ivl = int(sqrt(bs_env%safety_factor_memory*input_memory_per_proc &
2553 *bs_env%group_size_tensor/24/bs_env%n_RI &
2554 /sqrt(bs_env%occupation_3c_int)))/bs_env%max_AO_bf_per_atom
2556 n_intervals_i = (bs_env%n_atom_i - 1)/n_atom_per_ivl + 1
2557 n_intervals_j = (bs_env%n_atom_j - 1)/n_atom_per_ivl + 1
2559 bs_env%n_intervals_i = n_intervals_i
2560 bs_env%n_intervals_j = n_intervals_j
2562 ALLOCATE (bs_env%i_atom_intervals(2, n_intervals_i))
2563 ALLOCATE (bs_env%j_atom_intervals(2, n_intervals_j))
2565 DO i_ivl = 1, n_intervals_i
2566 bs_env%i_atom_intervals(1, i_ivl) = (i_ivl - 1)*n_atom_per_ivl + bs_env%atoms_i(1)
2567 bs_env%i_atom_intervals(2, i_ivl) = min(i_ivl*n_atom_per_ivl + bs_env%atoms_i(1) - 1, &
2571 DO j_ivl = 1, n_intervals_j
2572 bs_env%j_atom_intervals(1, j_ivl) = (j_ivl - 1)*n_atom_per_ivl + bs_env%atoms_j(1)
2573 bs_env%j_atom_intervals(2, j_ivl) = min(j_ivl*n_atom_per_ivl + bs_env%atoms_j(1) - 1, &
2577 ALLOCATE (bs_env%skip_Sigma_occ(n_intervals_i, n_intervals_j))
2578 ALLOCATE (bs_env%skip_Sigma_vir(n_intervals_i, n_intervals_j))
2579 bs_env%skip_Sigma_occ(:, :) = .false.
2580 bs_env%skip_Sigma_vir(:, :) = .false.
2581 bs_env%n_skip_chi = 0
2583 ALLOCATE (bs_env%skip_chi(n_intervals_i, n_intervals_j))
2584 bs_env%skip_chi(:, :) = .false.
2585 bs_env%n_skip_sigma = 0
2590 n_atom_per_il_ivl = min(int(bs_env%safety_factor_memory*input_memory_per_proc &
2591 *bs_env%group_size_tensor/n_atom_per_ivl &
2592 /bs_env%max_AO_bf_per_atom &
2593 /bs_env%n_RI/8/sqrt(bs_env%occupation_3c_int) &
2594 /bs_env%max_AO_bf_per_atom), bs_env%n_atom)
2596 n_intervals_inner_loop_atoms = (bs_env%n_atom - 1)/n_atom_per_il_ivl + 1
2598 bs_env%n_intervals_inner_loop_atoms = n_intervals_inner_loop_atoms
2600 ALLOCATE (bs_env%inner_loop_atom_intervals(2, n_intervals_inner_loop_atoms))
2601 DO il_ivl = 1, n_intervals_inner_loop_atoms
2602 bs_env%inner_loop_atom_intervals(1, il_ivl) = (il_ivl - 1)*n_atom_per_il_ivl + 1
2603 bs_env%inner_loop_atom_intervals(2, il_ivl) = min(il_ivl*n_atom_per_il_ivl, bs_env%n_atom)
2608 WRITE (u,
'(T2,A)')
''
2609 WRITE (u,
'(T2,A,I33)')
'Number of i and j atoms in M_λνP(τ), N_νλQ(τ):', n_atom_per_ivl
2610 WRITE (u,
'(T2,A,I18)')
'Number of inner loop atoms for µ in M_λνP = sum_µ (µν|P) G_µλ', &
2614 CALL timestop(handle)
2616 END SUBROUTINE set_sparsity_parallelization_parameters
2623 SUBROUTINE check_for_restart_files(qs_env, bs_env)
2627 CHARACTER(LEN=*),
PARAMETER :: routinen =
'check_for_restart_files'
2629 CHARACTER(LEN=9) :: frmt
2630 CHARACTER(len=default_path_length) :: f_chi, f_s_n, f_s_p, f_s_x, f_w_t, &
2631 prefix, project_name, z_lp_name
2632 INTEGER :: handle, i_spin, i_t_or_w, ind, n_spin, &
2633 num_time_freq_points
2634 LOGICAL :: chi_exists, sigma_neg_time_exists, &
2635 sigma_pos_time_exists, &
2636 sigma_x_spin_exists, w_time_exists, &
2641 CALL timeset(routinen, handle)
2643 num_time_freq_points = bs_env%num_time_freq_points
2644 n_spin = bs_env%n_spin
2646 ALLOCATE (bs_env%read_chi(num_time_freq_points))
2647 ALLOCATE (bs_env%calc_chi(num_time_freq_points))
2648 ALLOCATE (bs_env%Sigma_c_exists(num_time_freq_points, n_spin))
2656 WRITE (prefix,
'(2A)') trim(project_name),
"-RESTART_"
2657 bs_env%prefix = prefix
2659 bs_env%all_W_exist = .true.
2661 DO i_t_or_w = 1, num_time_freq_points
2663 IF (i_t_or_w < 10)
THEN
2664 WRITE (frmt,
'(A)')
'(3A,I1,A)'
2665 WRITE (f_chi, frmt) trim(prefix), bs_env%chi_name,
"_0", i_t_or_w,
".matrix"
2666 WRITE (f_w_t, frmt) trim(prefix), bs_env%W_time_name,
"_0", i_t_or_w,
".matrix"
2667 ELSE IF (i_t_or_w < 100)
THEN
2668 WRITE (frmt,
'(A)')
'(3A,I2,A)'
2669 WRITE (f_chi, frmt) trim(prefix), bs_env%chi_name,
"_", i_t_or_w,
".matrix"
2670 WRITE (f_w_t, frmt) trim(prefix), bs_env%W_time_name,
"_", i_t_or_w,
".matrix"
2672 cpabort(
'Please implement more than 99 time/frequency points.')
2675 INQUIRE (file=trim(f_chi), exist=chi_exists)
2676 INQUIRE (file=trim(f_w_t), exist=w_time_exists)
2678 bs_env%read_chi(i_t_or_w) = chi_exists
2679 bs_env%calc_chi(i_t_or_w) = .NOT. chi_exists
2681 bs_env%all_W_exist = bs_env%all_W_exist .AND. w_time_exists
2684 DO i_spin = 1, n_spin
2686 ind = i_t_or_w + (i_spin - 1)*num_time_freq_points
2689 WRITE (frmt,
'(A)')
'(3A,I1,A)'
2690 WRITE (f_s_p, frmt) trim(prefix), bs_env%Sigma_p_name,
"_0", ind,
".matrix"
2691 WRITE (f_s_n, frmt) trim(prefix), bs_env%Sigma_n_name,
"_0", ind,
".matrix"
2692 ELSE IF (ind < 100)
THEN
2693 WRITE (frmt,
'(A)')
'(3A,I2,A)'
2694 WRITE (f_s_p, frmt) trim(prefix), bs_env%Sigma_p_name,
"_", ind,
".matrix"
2695 WRITE (f_s_n, frmt) trim(prefix), bs_env%Sigma_n_name,
"_", ind,
".matrix"
2697 cpabort(
'Please implement more than 99 combined spin+freq indices.')
2700 INQUIRE (file=trim(f_s_p), exist=sigma_pos_time_exists)
2701 INQUIRE (file=trim(f_s_n), exist=sigma_neg_time_exists)
2703 bs_env%Sigma_c_exists(i_t_or_w, i_spin) = sigma_pos_time_exists .AND. &
2704 sigma_neg_time_exists
2713 WRITE (f_w_t,
'(3A,I1,A)') trim(prefix),
"W_freq_rtp",
"_0", 0,
".matrix"
2714 INQUIRE (file=trim(f_w_t), exist=w_time_exists)
2715 bs_env%all_W_exist = bs_env%all_W_exist .AND. w_time_exists
2719 IF (bs_env%do_gw_ri_rs)
THEN
2720 WRITE (z_lp_name,
'(3A)') trim(prefix),
"Z_lP",
".matrix"
2721 INQUIRE (file=trim(z_lp_name), exist=z_lp_exists)
2722 bs_env%ri_rs%Z_lP_exists = z_lp_exists
2725 IF (bs_env%all_W_exist)
THEN
2726 bs_env%read_chi(:) = .false.
2727 bs_env%calc_chi(:) = .false.
2730 bs_env%Sigma_x_exists = .true.
2731 DO i_spin = 1, n_spin
2732 WRITE (f_s_x,
'(3A,I1,A)') trim(prefix), bs_env%Sigma_x_name,
"_0", i_spin,
".matrix"
2733 INQUIRE (file=trim(f_s_x), exist=sigma_x_spin_exists)
2734 bs_env%Sigma_x_exists = bs_env%Sigma_x_exists .AND. sigma_x_spin_exists
2738 bs_env%Sigma_c_freq_zero_exists = bs_env%do_static_cohsex
2739 DO i_spin = 1, n_spin
2740 WRITE (f_s_x,
'(3A,I1,A)') trim(prefix), bs_env%Sigma_c_freq_zero_name,
"_0", i_spin,
".matrix"
2741 INQUIRE (file=trim(f_s_x), exist=sigma_x_spin_exists)
2742 bs_env%Sigma_c_freq_zero_exists = bs_env%Sigma_c_freq_zero_exists .AND. sigma_x_spin_exists
2747 IF (any(bs_env%read_chi(:)) &
2748 .OR. any(bs_env%Sigma_c_exists) &
2749 .OR. bs_env%all_W_exist &
2750 .OR. bs_env%Sigma_x_exists &
2751 .OR. bs_env%Sigma_c_freq_zero_exists &
2754 IF (qs_env%scf_env%iter_count /= 1)
THEN
2755 CALL cp_warn(__location__,
"SCF needed more than 1 step, "// &
2756 "which might lead to spurious GW results when using GW restart files. ")
2760 CALL timestop(handle)
2762 END SUBROUTINE check_for_restart_files
2769 SUBROUTINE compute_3c_integrals(qs_env, bs_env)
2774 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_3c_integrals'
2776 INTEGER :: handle, j_cell, k_cell, nimages_3c
2778 CALL timeset(routinen, handle)
2780 nimages_3c = bs_env%nimages_3c
2781 ALLOCATE (bs_env%t_3c_int(nimages_3c, nimages_3c))
2782 DO j_cell = 1, nimages_3c
2783 DO k_cell = 1, nimages_3c
2784 CALL dbt_create(bs_env%t_RI_AO__AO, bs_env%t_3c_int(j_cell, k_cell))
2789 bs_env%eps_filter, &
2792 int_eps=bs_env%eps_filter*0.05_dp, &
2793 basis_i=bs_env%basis_set_RI, &
2794 basis_j=bs_env%basis_set_AO, &
2795 basis_k=bs_env%basis_set_AO, &
2796 potential_parameter=bs_env%ri_metric, &
2797 desymmetrize=.false., do_kpoints=.true., cell_sym=.true., &
2798 cell_to_index_ext=bs_env%cell_to_index_3c)
2800 CALL bs_env%para_env%sync()
2802 CALL timestop(handle)
2804 END SUBROUTINE compute_3c_integrals
2810 SUBROUTINE setup_cells_delta_r(bs_env)
2814 CHARACTER(LEN=*),
PARAMETER :: routinen =
'setup_cells_Delta_R'
2818 CALL timeset(routinen, handle)
2823 CALL sum_two_r_grids(bs_env%index_to_cell_3c, &
2824 bs_env%index_to_cell_3c, &
2825 bs_env%nimages_3c, bs_env%nimages_3c, &
2826 bs_env%index_to_cell_Delta_R, &
2827 bs_env%cell_to_index_Delta_R, &
2828 bs_env%nimages_Delta_R)
2830 IF (bs_env%unit_nr > 0)
THEN
2831 WRITE (bs_env%unit_nr, fmt=
"(T2,A,I61)")
"Number of cells ΔR", bs_env%nimages_Delta_R
2834 CALL timestop(handle)
2836 END SUBROUTINE setup_cells_delta_r
2848 SUBROUTINE sum_two_r_grids(index_to_cell_1, index_to_cell_2, nimages_1, nimages_2, &
2849 index_to_cell, cell_to_index, nimages)
2851 INTEGER,
DIMENSION(:, :) :: index_to_cell_1, index_to_cell_2
2852 INTEGER :: nimages_1, nimages_2
2853 INTEGER,
ALLOCATABLE,
DIMENSION(:, :) :: index_to_cell
2854 INTEGER,
DIMENSION(:, :, :),
POINTER :: cell_to_index
2857 CHARACTER(LEN=*),
PARAMETER :: routinen =
'sum_two_R_grids'
2859 INTEGER :: handle, i_dim, img_1, img_2, nimages_max
2860 INTEGER,
ALLOCATABLE,
DIMENSION(:, :) :: index_to_cell_tmp
2861 INTEGER,
DIMENSION(3) :: cell_1, cell_2, r, r_max, r_min
2863 CALL timeset(routinen, handle)
2866 r_min(i_dim) = minval(index_to_cell_1(i_dim, :)) + minval(index_to_cell_2(i_dim, :))
2867 r_max(i_dim) = maxval(index_to_cell_1(i_dim, :)) + maxval(index_to_cell_2(i_dim, :))
2870 nimages_max = (r_max(1) - r_min(1) + 1)*(r_max(2) - r_min(2) + 1)*(r_max(3) - r_min(3) + 1)
2872 ALLOCATE (index_to_cell_tmp(3, nimages_max))
2873 index_to_cell_tmp(:, :) = -1
2875 ALLOCATE (cell_to_index(r_min(1):r_max(1), r_min(2):r_max(2), r_min(3):r_max(3)))
2876 cell_to_index(:, :, :) = -1
2880 DO img_1 = 1, nimages_1
2882 DO img_2 = 1, nimages_2
2884 cell_1(1:3) = index_to_cell_1(1:3, img_1)
2885 cell_2(1:3) = index_to_cell_2(1:3, img_2)
2887 r(1:3) = cell_1(1:3) + cell_2(1:3)
2890 IF (cell_to_index(r(1), r(2), r(3)) == -1)
THEN
2892 nimages = nimages + 1
2893 cell_to_index(r(1), r(2), r(3)) = nimages
2894 index_to_cell_tmp(1:3, nimages) = r(1:3)
2902 ALLOCATE (index_to_cell(3, nimages))
2903 index_to_cell(:, :) = index_to_cell_tmp(1:3, 1:nimages)
2905 CALL timestop(handle)
2907 END SUBROUTINE sum_two_r_grids
2913 SUBROUTINE setup_parallelization_delta_r(bs_env)
2917 CHARACTER(LEN=*),
PARAMETER :: routinen =
'setup_parallelization_Delta_R'
2919 INTEGER :: handle, i_cell_delta_r, i_task_local, &
2921 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: i_cell_delta_r_group, &
2922 n_tensor_ops_delta_r
2924 CALL timeset(routinen, handle)
2926 CALL compute_n_tensor_ops_delta_r(bs_env, n_tensor_ops_delta_r)
2928 CALL compute_delta_r_dist(bs_env, n_tensor_ops_delta_r, i_cell_delta_r_group, n_tasks_local)
2930 bs_env%n_tasks_Delta_R_local = n_tasks_local
2932 ALLOCATE (bs_env%task_Delta_R(n_tasks_local))
2935 DO i_cell_delta_r = 1, bs_env%nimages_Delta_R
2937 IF (i_cell_delta_r_group(i_cell_delta_r) /= bs_env%tensor_group_color) cycle
2939 i_task_local = i_task_local + 1
2941 bs_env%task_Delta_R(i_task_local) = i_cell_delta_r
2945 ALLOCATE (bs_env%skip_DR_chi(n_tasks_local))
2946 bs_env%skip_DR_chi(:) = .false.
2947 ALLOCATE (bs_env%skip_DR_Sigma(n_tasks_local))
2948 bs_env%skip_DR_Sigma(:) = .false.
2950 CALL allocate_skip_3xr(bs_env%skip_DR_R12_S_Goccx3c_chi, bs_env)
2951 CALL allocate_skip_3xr(bs_env%skip_DR_R12_S_Gvirx3c_chi, bs_env)
2952 CALL allocate_skip_3xr(bs_env%skip_DR_R_R2_MxM_chi, bs_env)
2954 CALL allocate_skip_3xr(bs_env%skip_DR_R1_S2_Gx3c_Sigma, bs_env)
2955 CALL allocate_skip_3xr(bs_env%skip_DR_R1_R_MxM_Sigma, bs_env)
2957 CALL timestop(handle)
2959 END SUBROUTINE setup_parallelization_delta_r
2966 SUBROUTINE compute_n_tensor_ops_delta_r(bs_env, n_tensor_ops_Delta_R)
2968 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: n_tensor_ops_delta_r
2970 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_n_tensor_ops_Delta_R'
2972 INTEGER :: handle, i_cell_delta_r, i_cell_r, i_cell_r1, i_cell_r1_minus_r, i_cell_r2, &
2973 i_cell_r2_m_r1, i_cell_s1, i_cell_s1_m_r1_p_r2, i_cell_s1_minus_r, i_cell_s2, &
2975 INTEGER,
DIMENSION(3) :: cell_dr, cell_m_r1, cell_r, cell_r1, cell_r1_minus_r, cell_r2, &
2976 cell_r2_m_r1, cell_s1, cell_s1_m_r2_p_r1, cell_s1_minus_r, cell_s1_p_s2_m_r1, cell_s2
2977 LOGICAL :: cell_found
2979 CALL timeset(routinen, handle)
2981 nimages_delta_r = bs_env%nimages_Delta_R
2983 ALLOCATE (n_tensor_ops_delta_r(nimages_delta_r))
2984 n_tensor_ops_delta_r(:) = 0
2987 DO i_cell_delta_r = 1, nimages_delta_r
2989 IF (
modulo(i_cell_delta_r, bs_env%num_tensor_groups) /= bs_env%tensor_group_color) cycle
2991 DO i_cell_r1 = 1, bs_env%nimages_3c
2993 cell_r1(1:3) = bs_env%index_to_cell_3c(1:3, i_cell_r1)
2994 cell_dr(1:3) = bs_env%index_to_cell_Delta_R(1:3, i_cell_delta_r)
2997 CALL add_r(cell_r1, cell_dr, bs_env%index_to_cell_3c, cell_s1, &
2998 cell_found, bs_env%cell_to_index_3c, i_cell_s1)
2999 IF (.NOT. cell_found) cycle
3001 DO i_cell_r2 = 1, bs_env%nimages_scf_desymm
3003 cell_r2(1:3) = bs_env%kpoints_scf_desymm%index_to_cell(1:3, i_cell_r2)
3006 CALL add_r(cell_r2, -cell_r1, bs_env%index_to_cell_3c, cell_r2_m_r1, &
3007 cell_found, bs_env%cell_to_index_3c, i_cell_r2_m_r1)
3008 IF (.NOT. cell_found) cycle
3011 CALL add_r(cell_s1, cell_r2_m_r1, bs_env%index_to_cell_3c, cell_s1_m_r2_p_r1, &
3012 cell_found, bs_env%cell_to_index_3c, i_cell_s1_m_r1_p_r2)
3013 IF (.NOT. cell_found) cycle
3015 n_tensor_ops_delta_r(i_cell_delta_r) = n_tensor_ops_delta_r(i_cell_delta_r) + 1
3019 DO i_cell_s2 = 1, bs_env%nimages_scf_desymm
3021 cell_s2(1:3) = bs_env%kpoints_scf_desymm%index_to_cell(1:3, i_cell_s2)
3022 cell_m_r1(1:3) = -cell_r1(1:3)
3023 cell_s1_p_s2_m_r1(1:3) = cell_s1(1:3) + cell_s2(1:3) - cell_r1(1:3)
3026 IF (.NOT. cell_found) cycle
3029 IF (.NOT. cell_found) cycle
3033 DO i_cell_r = 1, bs_env%nimages_scf_desymm
3035 cell_r = bs_env%kpoints_scf_desymm%index_to_cell(1:3, i_cell_r)
3038 CALL add_r(cell_r1, -cell_r, bs_env%index_to_cell_3c, cell_r1_minus_r, &
3039 cell_found, bs_env%cell_to_index_3c, i_cell_r1_minus_r)
3040 IF (.NOT. cell_found) cycle
3043 CALL add_r(cell_s1, -cell_r, bs_env%index_to_cell_3c, cell_s1_minus_r, &
3044 cell_found, bs_env%cell_to_index_3c, i_cell_s1_minus_r)
3045 IF (.NOT. cell_found) cycle
3053 CALL bs_env%para_env%sum(n_tensor_ops_delta_r)
3055 CALL timestop(handle)
3057 END SUBROUTINE compute_n_tensor_ops_delta_r
3069 SUBROUTINE add_r(cell_1, cell_2, index_to_cell, cell_1_plus_2, cell_found, &
3070 cell_to_index, i_cell_1_plus_2)
3072 INTEGER,
DIMENSION(3) :: cell_1, cell_2
3073 INTEGER,
DIMENSION(:, :) :: index_to_cell
3074 INTEGER,
DIMENSION(3) :: cell_1_plus_2
3075 LOGICAL :: cell_found
3076 INTEGER,
DIMENSION(:, :, :),
INTENT(IN), &
3077 OPTIONAL,
POINTER :: cell_to_index
3078 INTEGER,
INTENT(OUT),
OPTIONAL :: i_cell_1_plus_2
3080 CHARACTER(LEN=*),
PARAMETER :: routinen =
'add_R'
3084 CALL timeset(routinen, handle)
3086 cell_1_plus_2(1:3) = cell_1(1:3) + cell_2(1:3)
3090 IF (
PRESENT(i_cell_1_plus_2))
THEN
3091 IF (cell_found)
THEN
3092 cpassert(
PRESENT(cell_to_index))
3093 i_cell_1_plus_2 = cell_to_index(cell_1_plus_2(1), cell_1_plus_2(2), cell_1_plus_2(3))
3095 i_cell_1_plus_2 = -1000
3099 CALL timestop(handle)
3101 END SUBROUTINE add_r
3110 INTEGER,
DIMENSION(3) :: cell
3111 INTEGER,
DIMENSION(:, :) :: index_to_cell
3112 LOGICAL :: cell_found
3114 CHARACTER(LEN=*),
PARAMETER :: routinen =
'is_cell_in_index_to_cell'
3116 INTEGER :: handle, i_cell, nimg
3117 INTEGER,
DIMENSION(3) :: cell_i
3119 CALL timeset(routinen, handle)
3121 nimg =
SIZE(index_to_cell, 2)
3123 cell_found = .false.
3127 cell_i(1:3) = index_to_cell(1:3, i_cell)
3129 IF (cell_i(1) == cell(1) .AND. cell_i(2) == cell(2) .AND. cell_i(3) == cell(3))
THEN
3135 CALL timestop(handle)
3146 SUBROUTINE compute_delta_r_dist(bs_env, n_tensor_ops_Delta_R, i_cell_Delta_R_group, n_tasks_local)
3148 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: n_tensor_ops_delta_r, &
3149 i_cell_delta_r_group
3150 INTEGER :: n_tasks_local
3152 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_Delta_R_dist'
3154 INTEGER :: handle, i_delta_r_max_op, i_group_min, &
3156 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: n_tensor_ops_delta_r_in_group
3158 CALL timeset(routinen, handle)
3160 nimages_delta_r = bs_env%nimages_Delta_R
3164 IF (u > 0 .AND. nimages_delta_r < bs_env%num_tensor_groups)
THEN
3165 WRITE (u, fmt=
"(T2,A,I5,A,I5,A)")
"There are only ", nimages_delta_r, &
3166 " tasks to work on but there are ", bs_env%num_tensor_groups,
" groups."
3167 WRITE (u, fmt=
"(T2,A)")
"Please reduce the number of MPI processes."
3168 WRITE (u,
'(T2,A)')
''
3171 ALLOCATE (n_tensor_ops_delta_r_in_group(bs_env%num_tensor_groups))
3172 n_tensor_ops_delta_r_in_group(:) = 0
3173 ALLOCATE (i_cell_delta_r_group(nimages_delta_r))
3174 i_cell_delta_r_group(:) = -1
3178 DO WHILE (any(n_tensor_ops_delta_r(:) /= 0))
3181 i_delta_r_max_op = maxloc(n_tensor_ops_delta_r, 1)
3184 i_group_min = minloc(n_tensor_ops_delta_r_in_group, 1)
3187 i_cell_delta_r_group(i_delta_r_max_op) = i_group_min - 1
3188 n_tensor_ops_delta_r_in_group(i_group_min) = n_tensor_ops_delta_r_in_group(i_group_min) + &
3189 n_tensor_ops_delta_r(i_delta_r_max_op)
3192 n_tensor_ops_delta_r(i_delta_r_max_op) = 0
3194 IF (bs_env%tensor_group_color == i_group_min - 1) n_tasks_local = n_tasks_local + 1
3198 CALL timestop(handle)
3200 END SUBROUTINE compute_delta_r_dist
3207 SUBROUTINE allocate_skip_3xr(skip, bs_env)
3208 LOGICAL,
ALLOCATABLE,
DIMENSION(:, :, :) :: skip
3211 CHARACTER(LEN=*),
PARAMETER :: routinen =
'allocate_skip_3xR'
3215 CALL timeset(routinen, handle)
3217 ALLOCATE (skip(bs_env%n_tasks_Delta_R_local, bs_env%nimages_3c, bs_env%nimages_scf_desymm))
3218 skip(:, :, :) = .false.
3220 CALL timestop(handle)
3222 END SUBROUTINE allocate_skip_3xr
3229 SUBROUTINE allocate_matrices_small_cell_full_kp_tensor(qs_env, bs_env)
3233 CHARACTER(LEN=*),
PARAMETER :: routinen =
'allocate_matrices_small_cell_full_kp_tensor'
3235 INTEGER :: handle, i_spin, i_t, img, n_spin, &
3236 nimages_scf, num_time_freq_points
3240 CALL timeset(routinen, handle)
3242 nimages_scf = bs_env%nimages_scf_desymm
3243 num_time_freq_points = bs_env%num_time_freq_points
3244 n_spin = bs_env%n_spin
3246 CALL get_qs_env(qs_env, para_env=para_env, blacs_env=blacs_env)
3248 ALLOCATE (bs_env%fm_G_S(nimages_scf))
3249 ALLOCATE (bs_env%fm_Sigma_x_R(nimages_scf))
3250 ALLOCATE (bs_env%fm_chi_R_t(nimages_scf, num_time_freq_points))
3251 ALLOCATE (bs_env%fm_MWM_R_t(nimages_scf, num_time_freq_points))
3252 ALLOCATE (bs_env%fm_Sigma_c_R_neg_tau(nimages_scf, num_time_freq_points, n_spin))
3253 ALLOCATE (bs_env%fm_Sigma_c_R_pos_tau(nimages_scf, num_time_freq_points, n_spin))
3254 DO img = 1, nimages_scf
3255 CALL cp_fm_create(bs_env%fm_G_S(img), bs_env%fm_work_mo(1)%matrix_struct)
3256 CALL cp_fm_create(bs_env%fm_Sigma_x_R(img), bs_env%fm_work_mo(1)%matrix_struct)
3257 DO i_t = 1, num_time_freq_points
3258 CALL cp_fm_create(bs_env%fm_chi_R_t(img, i_t), bs_env%fm_RI_RI%matrix_struct)
3259 CALL cp_fm_create(bs_env%fm_MWM_R_t(img, i_t), bs_env%fm_RI_RI%matrix_struct)
3261 DO i_spin = 1, n_spin
3262 CALL cp_fm_create(bs_env%fm_Sigma_c_R_neg_tau(img, i_t, i_spin), &
3263 bs_env%fm_work_mo(1)%matrix_struct)
3264 CALL cp_fm_create(bs_env%fm_Sigma_c_R_pos_tau(img, i_t, i_spin), &
3265 bs_env%fm_work_mo(1)%matrix_struct)
3266 CALL cp_fm_set_all(bs_env%fm_Sigma_c_R_neg_tau(img, i_t, i_spin), 0.0_dp)
3267 CALL cp_fm_set_all(bs_env%fm_Sigma_c_R_pos_tau(img, i_t, i_spin), 0.0_dp)
3272 CALL timestop(handle)
3274 END SUBROUTINE allocate_matrices_small_cell_full_kp_tensor
3281 SUBROUTINE trafo_v_xc_r_to_kp(qs_env, bs_env)
3285 CHARACTER(LEN=*),
PARAMETER :: routinen =
'trafo_V_xc_R_to_kp'
3287 INTEGER :: handle, ikp, img, ispin, n_ao
3288 TYPE(
cp_cfm_type) :: cfm_kp_group, cfm_mo_coeff, cfm_v_xc
3290 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_ks
3295 CALL timeset(routinen, handle)
3299 CALL get_qs_env(qs_env, para_env=para_env, matrix_ks_kp=matrix_ks)
3301 CALL cp_cfm_create(cfm_v_xc, bs_env%cfm_work_mo%matrix_struct)
3302 CALL cp_cfm_create(cfm_mo_coeff, bs_env%cfm_work_mo%matrix_struct)
3303 CALL cp_fm_create(fm_v_xc_re, bs_env%cfm_work_mo%matrix_struct)
3305 DO img = 1, bs_env%nimages_scf
3306 DO ispin = 1, bs_env%n_spin
3308 CALL dbcsr_set(matrix_ks(ispin, img)%matrix, 0.0_dp)
3309 CALL copy_fm_to_dbcsr(bs_env%fm_V_xc_R(img, ispin), matrix_ks(ispin, img)%matrix)
3317 ALLOCATE (bs_env%v_xc_n(n_ao, bs_env%nkp_bs_and_DOS, bs_env%n_spin))
3319 DO ispin = 1, bs_env%n_spin
3320 DO ikp = 1, bs_env%nkp_bs_and_DOS
3328 CALL cp_cfm_to_cfm(bs_env%cfm_mo_coeff_kp(ikp, ispin), cfm_mo_coeff)
3346 CALL build_periodic_ks_with_gapw_density(qs_env)
3352 CALL timestop(handle)
3354 END SUBROUTINE trafo_v_xc_r_to_kp
3361 SUBROUTINE heuristic_ri_regularization(qs_env, bs_env)
3365 CHARACTER(LEN=*),
PARAMETER :: routinen =
'heuristic_RI_regularization'
3367 COMPLEX(KIND=dp),
ALLOCATABLE,
DIMENSION(:, :, :) :: m
3368 INTEGER :: handle, ikp, ikp_local, n_ri, nkp, &
3370 REAL(kind=
dp) :: cond_nr, cond_nr_max, max_ev, &
3371 max_ev_ikp, min_ev, min_ev_ikp
3372 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :, :) :: m_r
3374 CALL timeset(routinen, handle)
3377 CALL get_v_tr_r(m_r, bs_env%ri_metric, 0.0_dp, bs_env, qs_env)
3379 nkp = bs_env%nkp_chi_eps_W_orig_plus_extra
3385 IF (
modulo(ikp, bs_env%para_env%num_pe) /= bs_env%para_env%mepos) cycle
3386 nkp_local = nkp_local + 1
3389 ALLOCATE (m(n_ri, n_ri, nkp_local))
3392 cond_nr_max = 0.0_dp
3399 IF (
modulo(ikp, bs_env%para_env%num_pe) /= bs_env%para_env%mepos) cycle
3401 ikp_local = ikp_local + 1
3404 CALL rs_to_kp(m_r, m(:, :, ikp_local), &
3405 bs_env%kpoints_scf_desymm%index_to_cell, &
3406 bs_env%kpoints_chi_eps_W%xkp(1:3, ikp))
3409 CALL local_complex_power(m(:, :, ikp_local), 1.0_dp, 0.0_dp, cond_nr, min_ev_ikp, max_ev_ikp)
3411 IF (cond_nr > cond_nr_max) cond_nr_max = cond_nr
3412 IF (max_ev_ikp > max_ev) max_ev = max_ev_ikp
3413 IF (min_ev_ikp < min_ev) min_ev = min_ev_ikp
3417 CALL bs_env%para_env%max(cond_nr_max)
3418 CALL bs_env%para_env%min(min_ev)
3419 CALL bs_env%para_env%max(max_ev)
3423 WRITE (u, fmt=
"(T2,A,ES34.1)")
"Min. abs. eigenvalue of RI metric matrix M(k)", min_ev
3424 WRITE (u, fmt=
"(T2,A,ES34.1)")
"Max. abs. eigenvalue of RI metric matrix M(k)", max_ev
3425 WRITE (u, fmt=
"(T2,A,ES50.1)")
"Max. condition number of M(k)", cond_nr_max
3428 CALL timestop(handle)
3430 END SUBROUTINE heuristic_ri_regularization
3436 SUBROUTINE setup_time_and_frequency_minimax_grid(bs_env)
3439 CHARACTER(LEN=*),
PARAMETER :: routinen =
'setup_time_and_frequency_minimax_grid'
3441 INTEGER :: handle, homo, ispin, n_mo, n_top, &
3442 num_time_freq_points, u
3443 REAL(kind=
dp) :: e_max, e_max_ispin, e_min, e_min_ispin, &
3444 e_range, max_error_min, max_error_sigma
3446 CALL timeset(routinen, handle)
3449 num_time_freq_points = bs_env%num_time_freq_points
3454 DO ispin = 1, bs_env%n_spin
3455 homo = bs_env%n_occ(ispin)
3460 n_top = max(min(bs_env%n_mo_retained, n_mo), homo + 1)
3462 SELECT CASE (bs_env%gw_implementation)
3464 e_min_ispin = bs_env%eigenval_scf_Gamma(homo + 1, ispin) - &
3465 bs_env%eigenval_scf_Gamma(homo, ispin)
3466 e_max_ispin = bs_env%eigenval_scf_Gamma(n_top, ispin) - &
3467 bs_env%eigenval_scf_Gamma(1, ispin)
3469 e_min_ispin = minval(bs_env%eigenval_scf(homo + 1, :, ispin)) - &
3470 maxval(bs_env%eigenval_scf(homo, :, ispin))
3471 e_max_ispin = maxval(bs_env%eigenval_scf(n_top, :, ispin)) - &
3472 minval(bs_env%eigenval_scf(1, :, ispin))
3474 e_min = min(e_min, e_min_ispin)
3475 e_max = max(e_max, e_max_ispin)
3480 IF (bs_env%n_spin > 1)
THEN
3481 CALL cp_hint(__location__, &
3482 "Open-shell GW uses one time-frequency grid spanning [min gap, max span] across both "// &
3483 "spin channels; raise NUM_TIME_FREQ_POINTS if QP convergence is marginal for "// &
3484 "strongly spin-asymmetric systems.")
3487 e_range = e_max/e_min
3490 bs_env%num_points_per_magnitude, bs_env%time_frequency_grid, &
3491 build_frequency=.true., build_time=.true., build_transforms=.true., &
3492 build_sine=.true., time_scaling=2.0_dp, time_weight_scaling=1.0_dp, &
3493 max_fit_error=max_error_min, print_warning=.false., unit_nr=0, &
3494 prefer_external_backend=.false.)
3501 bs_env%num_points_per_magnitude, bs_env%time_frequency_grid_sigma, &
3502 build_frequency=.true., build_time=.true., build_transforms=.true., &
3503 build_sine=.true., time_scaling=2.0_dp, time_weight_scaling=1.0_dp, &
3504 max_fit_error=max_error_sigma, print_warning=.false., unit_nr=0, &
3505 prefer_external_backend=.false., &
3506 rcond=bs_env%nevanlinna%rcond_weights)
3508 bs_env%time_frequency_grid_sigma = bs_env%time_frequency_grid
3512 bs_env%num_freq_points_fit = count(bs_env%time_frequency_grid%frequency < bs_env%freq_max_fit)
3515 ALLOCATE (bs_env%imag_freq_points_fit(bs_env%num_freq_points_fit))
3516 bs_env%imag_freq_points_fit(:) = pack(bs_env%time_frequency_grid%frequency, &
3517 bs_env%time_frequency_grid%frequency < bs_env%freq_max_fit)
3521 IF (bs_env%num_freq_points_fit < bs_env%nparam_pade)
THEN
3522 bs_env%nparam_pade = bs_env%num_freq_points_fit
3527 bs_env%num_freq_points_pade = bs_env%num_freq_points_fit
3529 bs_env%num_freq_points_fit = num_time_freq_points
3530 DEALLOCATE (bs_env%imag_freq_points_fit)
3531 ALLOCATE (bs_env%imag_freq_points_fit(num_time_freq_points))
3532 bs_env%imag_freq_points_fit(:) = bs_env%time_frequency_grid%frequency
3537 WRITE (u,
'(T2,A)')
''
3538 WRITE (u,
'(T2,A,F50.2)')
'SCF fundamental band gap (eV)', e_min*
evolt
3539 WRITE (u,
'(T2,A,F53.2)')
'Max. SCF eigval diff. (eV)', e_max*
evolt
3540 WRITE (u,
'(T2,A,F55.2)')
'E-Range for minimax grid', e_range
3541 WRITE (u,
'(T2,A,I27)')
'Number of Padé parameters for analytic continuation:', &
3543 WRITE (u,
'(T2,A)')
''
3551 CALL timestop(handle)
3553 END SUBROUTINE setup_time_and_frequency_minimax_grid
3565 CHARACTER(LEN=*),
PARAMETER :: routinen =
'de_init_bs_env'
3568 LOGICAL :: retain_nl_3c, rirs_kernel
3570 CALL timeset(routinen, handle)
3578 retain_nl_3c = bs_env%keep_3c_nl
3579 IF (
ASSOCIATED(bs_env%nl_3c%ij_list) .AND. (bs_env%rtp_method ==
rtp_method_bse))
THEN
3581 retain_nl_3c = retain_nl_3c .OR. .NOT. rirs_kernel
3584 IF (retain_nl_3c)
THEN
3585 IF (bs_env%unit_nr > 0)
WRITE (bs_env%unit_nr, *)
"Keep nl_3c for BSE"
3590 CALL timestop(handle)
3607 LOGICAL,
INTENT(OUT),
OPTIONAL :: rirs_kernel
3609 INTEGER :: kernel_ri
3610 LOGICAL :: my_rirs_kernel
3614 NULLIFY (dft_control, input)
3615 CALL get_qs_env(qs_env, dft_control=dft_control, input=input)
3619 SELECT CASE (kernel_ri)
3621 my_rirs_kernel = .true.
3623 my_rirs_kernel = .false.
3625 my_rirs_kernel = bs_env%do_gw_ri_rs
3631 cpwarn(
"RI-RS kernels are implemented for linearized RT-BSE only; forcing AO")
3633 my_rirs_kernel = .false.
3636 IF (
PRESENT(rirs_kernel)) rirs_kernel = my_rirs_kernel
3652 eigenval_scf, ikp, ispin, i_iter)
3655 COMPLEX(KIND=dp),
DIMENSION(:, :),
INTENT(IN) :: sigma_c_ikp_n_freq
3656 REAL(kind=
dp),
DIMENSION(:) :: sigma_x_ikp_n, v_xc_ikp_n, eigenval_scf
3657 INTEGER :: ikp, ispin
3658 INTEGER,
INTENT(IN),
OPTIONAL :: i_iter
3660 CHARACTER(LEN=*),
PARAMETER :: routinen =
'analyt_conti_and_print'
3661 INTEGER,
PARAMETER :: max_pade_orders = 7
3663 CHARACTER(len=3) :: occ_vir
3664 CHARACTER(len=default_path_length) :: fname
3665 CHARACTER(len=default_string_length) :: gw_label
3666 INTEGER :: ac_used, handle, i_central, i_mo, i_order, icycle, ikp_for_print, iunit, &
3667 n_ac_nevanlinna, n_ac_pade, n_central, n_mo, n_orders, n_window, nkp
3668 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: multi_count
3669 INTEGER,
DIMENSION(max_pade_orders) :: order_index
3670 LOGICAL :: do_nevanlinna, is_bandstruc_kpoint, &
3671 multi_i, print_dos_kpoints, print_ikp
3672 LOGICAL,
ALLOCATABLE,
DIMENSION(:) :: multi, unstable
3673 REAL(kind=
dp) :: ac_pick, pick_min
3674 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: eigenval_g, m_value, sigma_c_ikp_n_qp, &
3676 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: sigma_c_orders
3677 REAL(kind=
dp),
DIMENSION(max_pade_orders) :: sigma_c_sorted
3679 CALL timeset(routinen, handle)
3682 IF (
PRESENT(i_iter)) icycle = i_iter
3689 n_orders = max(1, min(max_pade_orders, bs_env%nparam_pade - 1))
3690 n_central = min(n_orders, 3 -
modulo(n_orders + 1, 2))
3691 i_central = (n_orders - n_central)/2 + 1
3694 ALLOCATE (z_value(n_mo), m_value(n_mo), sigma_c_ikp_n_qp(n_mo), eigenval_g(n_mo), &
3695 sigma_c_orders(n_mo, n_orders))
3696 sigma_c_orders(:, :) = 0.0_dp
3697 sigma_c_ikp_n_qp(:) = 0.0_dp
3700 ALLOCATE (unstable(n_mo), multi(n_mo), multi_count(n_mo))
3701 unstable(:) = .false.
3713 IF (bs_env%gw_flavour ==
evgw0 .AND.
ALLOCATED(bs_env%eigenval_evGW0))
THEN
3714 eigenval_g(:) = bs_env%eigenval_evGW0(:, ikp, ispin)
3716 eigenval_g(:) = eigenval_scf(:)
3719 IF (do_nevanlinna)
THEN
3724 IF (
modulo(i_mo, bs_env%para_env%num_pe) /= bs_env%para_env%mepos) cycle
3726 bs_env%imag_freq_points_fit, z_value, m_value, &
3727 sigma_c_ikp_n_freq(:, 1:bs_env%num_freq_points_fit), &
3728 sigma_x_ikp_n(:) - v_xc_ikp_n(:), &
3729 eigenval_g(:), eigenval_scf(:), &
3730 bs_env%do_hedin_shift, &
3731 i_mo, bs_env%n_occ(ispin), bs_env%n_vir(ispin), &
3732 bs_env%nparam_pade, bs_env%num_freq_points_fit, &
3734 0.0_dp, .true., .false., 1, e_fermi_ext=bs_env%e_fermi(ispin), &
3736 num_fit_points_pade=bs_env%num_freq_points_pade, &
3737 qp_start_eigenval=.true., &
3738 qp_newton_max_step=bs_env%nevanlinna%qp_newton_max_step, &
3739 qp_maxz_radius=bs_env%nevanlinna%qp_maxz_radius, qp_multi=multi_i)
3740 IF (multi_i) multi_count(i_mo) = 1
3742 n_ac_nevanlinna = n_ac_nevanlinna + 1
3744 n_ac_pade = n_ac_pade + 1
3746 pick_min = min(pick_min, ac_pick)
3749 CALL bs_env%para_env%sum(sigma_c_ikp_n_qp)
3750 CALL bs_env%para_env%sum(n_ac_nevanlinna)
3751 CALL bs_env%para_env%sum(n_ac_pade)
3752 CALL bs_env%para_env%min(pick_min)
3753 CALL bs_env%para_env%sum(multi_count)
3754 multi(:) = (multi_count(:) > 0)
3756 CALL qp_median_over_windows(bs_env, sigma_c_ikp_n_freq, sigma_x_ikp_n, v_xc_ikp_n, &
3757 eigenval_g, eigenval_scf, ispin, sigma_c_ikp_n_qp, unstable, &
3759 CALL propagate_unstable_marks(unstable, multi, bs_env%n_occ(ispin))
3760 CALL print_qp_marks(bs_env, unstable, multi, n_window, ikp, ispin)
3767 IF (
modulo(i_mo, bs_env%para_env%num_pe) /= bs_env%para_env%mepos) cycle
3769 DO i_order = 1, n_orders
3771 bs_env%imag_freq_points_fit, z_value, m_value, &
3772 sigma_c_ikp_n_freq(:, 1:bs_env%num_freq_points_fit), &
3773 sigma_x_ikp_n(:) - v_xc_ikp_n(:), &
3774 eigenval_g(:), eigenval_scf(:), &
3775 bs_env%do_hedin_shift, &
3776 i_mo, bs_env%n_occ(ispin), bs_env%n_vir(ispin), &
3777 bs_env%nparam_pade - i_order + 1, bs_env%num_freq_points_fit, &
3779 0.0_dp, .true., .false., 1, e_fermi_ext=bs_env%e_fermi(ispin))
3783 CALL bs_env%para_env%sum(sigma_c_orders)
3786 sigma_c_sorted(1:n_orders) = sigma_c_orders(i_mo, 1:n_orders)
3787 CALL sort(sigma_c_sorted(1:n_orders), n_orders, order_index(1:n_orders))
3788 sigma_c_ikp_n_qp(i_mo) = sum(sigma_c_sorted(i_central:i_central + n_central - 1))/ &
3789 REAL(n_central, kind=
dp)
3794 CALL correct_obvious_fitting_fails(sigma_c_ikp_n_qp, ispin, bs_env)
3796 bs_env%eigenval_GW(:, ikp, ispin) = eigenval_scf(:) + &
3797 sigma_c_ikp_n_qp(:) + &
3798 sigma_x_ikp_n(:) - &
3801 IF (
ALLOCATED(bs_env%eigenval_G0W0) .AND. icycle == 1)
THEN
3802 bs_env%eigenval_G0W0(:, ikp, ispin) = bs_env%eigenval_GW(:, ikp, ispin)
3805 bs_env%eigenval_HF(:, ikp, ispin) = eigenval_scf(:) + sigma_x_ikp_n(:) - v_xc_ikp_n(:)
3808 print_dos_kpoints = (bs_env%nkp_only_bs <= 0)
3810 is_bandstruc_kpoint = (ikp > bs_env%nkp_only_DOS)
3811 print_ikp = print_dos_kpoints .OR. is_bandstruc_kpoint
3813 IF (bs_env%para_env%is_source() .AND. print_ikp)
THEN
3815 IF (print_dos_kpoints)
THEN
3816 nkp = bs_env%nkp_only_DOS
3819 nkp = bs_env%nkp_only_bs
3820 ikp_for_print = ikp - bs_env%nkp_only_DOS
3823 fname =
"bandstructure_SCF_and_G0W0"
3827 IF (ikp_for_print == 1 .AND. ispin == 1 .AND. icycle == 1)
THEN
3828 CALL open_file(trim(fname), unit_number=iunit, file_status=
"REPLACE", &
3829 file_action=
"WRITE")
3831 CALL open_file(trim(fname), unit_number=iunit, file_status=
"OLD", &
3832 file_action=
"WRITE", file_position=
"APPEND")
3835 IF (bs_env%gw_flavour ==
evgw0 .AND. ikp_for_print == 1 .AND. ispin == 1)
THEN
3836 WRITE (iunit,
"(A)")
" "
3837 WRITE (iunit,
"(A,I0)")
"evGW0 cycle: ", icycle
3838 IF (icycle == 1)
THEN
3839 WRITE (iunit,
'(A)')
'# G0W0 spectrum (first cycle, without SOC)'
3843 WRITE (iunit,
"(A)")
" "
3844 WRITE (iunit,
"(A10,I7,A25,3F10.4,T90,A7,I2)")
"kpoint: ", ikp_for_print,
"coordinate: ", &
3845 bs_env%kpoints_DOS%xkp(:, ikp),
"spin: ", ispin
3846 WRITE (iunit,
"(A)")
" "
3847 IF (do_nevanlinna)
THEN
3848 WRITE (iunit,
"(A,I6,A,I6,A,ES10.2)")
" analytic continuation: Nevanlinna for", &
3849 n_ac_nevanlinna,
" level(s), Padé fallback for", n_ac_pade, &
3850 " level(s); smallest relative Pick eigenvalue", pick_min
3851 WRITE (iunit,
"(A)")
" "
3854 IF (bs_env%gw_flavour ==
evgw0 .AND. icycle == 1)
THEN
3855 gw_label =
"ϵ_nk^G0W0 (eV)"
3857 WRITE (iunit,
"(A5,A12,3A17,A16,A18)")
"n",
"k",
"ϵ_nk^DFT (eV)",
"Σ^c_nk (eV)", &
3858 "Σ^x_nk (eV)",
"v_nk^xc (eV)", trim(gw_label)
3859 WRITE (iunit,
"(A)")
" "
3862 IF (i_mo <= bs_env%n_occ(ispin)) occ_vir =
'occ'
3863 IF (i_mo > bs_env%n_occ(ispin)) occ_vir =
'vir'
3864 WRITE (iunit,
"(I5,3A,I5,4F16.3,F17.3,A)") i_mo,
' (', occ_vir,
') ', ikp_for_print, &
3865 eigenval_scf(i_mo)*
evolt, &
3866 sigma_c_ikp_n_qp(i_mo)*
evolt, &
3867 sigma_x_ikp_n(i_mo)*
evolt, &
3868 v_xc_ikp_n(i_mo)*
evolt, &
3869 bs_env%eigenval_GW(i_mo, ikp, ispin)*
evolt, &
3870 trim(merge(
' *',
' ', unstable(i_mo)))//trim(merge(
' m',
' ', multi(i_mo)))
3873 WRITE (iunit,
"(A)")
" "
3874 IF (any(unstable))
WRITE (iunit,
"(A)") &
3875 " * not reliable: the fit windows disagree, or an unstable or multi-solution level "// &
3876 "lies between this level and the HOMO (occupied) or the LUMO (virtual)"
3877 IF (any(multi))
WRITE (iunit,
"(A)") &
3878 " m multi-solution level: a second quasiparticle solution carries more than a quarter "// &
3885 CALL timestop(handle)
3905 SUBROUTINE qp_median_over_windows(bs_env, Sigma_c_ikp_n_freq, Sigma_x_ikp_n, V_xc_ikp_n, &
3906 eigenval_G, eigenval_scf, ispin, Sigma_c_ikp_n_qp, unstable, multi, &
3910 COMPLEX(KIND=dp),
DIMENSION(:, :),
INTENT(IN) :: sigma_c_ikp_n_freq
3911 REAL(kind=
dp),
DIMENSION(:) :: sigma_x_ikp_n, v_xc_ikp_n, eigenval_g, &
3914 REAL(kind=
dp),
DIMENSION(:) :: sigma_c_ikp_n_qp
3915 LOGICAL,
DIMENSION(:) :: unstable, multi
3916 INTEGER,
INTENT(OUT) :: n_window
3918 CHARACTER(LEN=*),
PARAMETER :: routinen =
'qp_median_over_windows'
3919 REAL(kind=
dp),
PARAMETER :: max_abs_sigma = 1.0e3_dp
3921 COMPLEX(KIND=dp),
ALLOCATABLE,
DIMENSION(:, :) :: sig_sel
3922 INTEGER :: handle, i_mo, i_win, j, k_w, n_mo, &
3924 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: multi_count, order, window_size
3927 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: m_dummy, q_sorted, sigma_c_win, w_sel, &
3929 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: q_win
3931 CALL timeset(routinen, handle)
3934 n_w = bs_env%num_time_freq_points
3937 ALLOCATE (order(n_w), window_size(n_w))
3944 DO WHILE (i_win >= 1)
3945 IF (bs_env%time_frequency_grid%frequency(order(i_win)) <= bs_env%time_frequency_grid%frequency(k_w))
EXIT
3946 order(i_win + 1) = order(i_win)
3949 order(i_win + 1) = k_w
3953 DO j = bs_env%nevanlinna%window_min_points, n_w
3954 v = bs_env%time_frequency_grid%frequency(order(j))
3955 IF (v >= bs_env%nevanlinna%window_freq_min .AND. v <= bs_env%nevanlinna%window_freq_max)
THEN
3956 n_window = n_window + 1
3957 window_size(n_window) = j
3962 IF (n_window < 2)
THEN
3963 CALL cp_warn(__location__,
"Fewer than two fit windows for the Nevanlinna continuation, "// &
3964 "so no error estimate; all GW levels are marked as not reliable. "// &
3965 "Increase NUM_TIME_FREQ_POINTS.")
3966 unstable(:) = .true.
3968 IF (n_window == 0)
THEN
3969 DEALLOCATE (order, window_size)
3970 CALL timestop(handle)
3974 ALLOCATE (q_win(n_mo, n_window), sigma_c_win(n_mo), q_sorted(n_window), &
3975 multi_count(n_mo), z_dummy(n_mo), m_dummy(n_mo))
3976 q_win(:, :) = 0.0_dp
3979 DO i_win = 1, n_window
3980 k_w = window_size(i_win)
3981 ALLOCATE (w_sel(k_w), sig_sel(n_mo, k_w))
3983 w_sel(j) = bs_env%time_frequency_grid%frequency(order(j))
3984 sig_sel(:, j) = sigma_c_ikp_n_freq(:, order(j))
3986 sigma_c_win(:) = 0.0_dp
3988 IF (
modulo(i_mo, bs_env%para_env%num_pe) /= bs_env%para_env%mepos) cycle
3990 sigma_x_ikp_n(:) - v_xc_ikp_n(:), &
3991 eigenval_g(:), eigenval_scf(:), &
3992 bs_env%do_hedin_shift, &
3993 i_mo, bs_env%n_occ(ispin), bs_env%n_vir(ispin), &
3996 0.0_dp, .true., .false., 1, e_fermi_ext=bs_env%e_fermi(ispin), &
3998 qp_newton_max_step=bs_env%nevanlinna%qp_newton_max_step, &
3999 qp_maxz_radius=bs_env%nevanlinna%qp_maxz_radius, qp_multi=multi_i)
4000 q_win(i_mo, i_win) = sigma_c_win(i_mo)
4001 IF (multi_i) multi_count(i_mo) = multi_count(i_mo) + 1
4003 DEALLOCATE (w_sel, sig_sel)
4006 CALL bs_env%para_env%sum(q_win)
4007 CALL bs_env%para_env%sum(multi_count)
4008 multi(:) = (2*multi_count(:) > n_window)
4013 DO i_win = 1, n_window
4014 v = q_win(i_mo, i_win)
4015 IF (.NOT. (v == v) .OR. abs(v) > max_abs_sigma) cycle
4016 n_valid = n_valid + 1
4019 IF (q_sorted(j - 1) <= v)
EXIT
4020 q_sorted(j) = q_sorted(j - 1)
4026 IF (n_valid < 2) unstable(i_mo) = .true.
4027 IF (n_valid == 0) cycle
4028 IF (
modulo(n_valid, 2) == 1)
THEN
4029 sigma_c_ikp_n_qp(i_mo) = q_sorted((n_valid + 1)/2)
4031 sigma_c_ikp_n_qp(i_mo) = 0.5_dp*(q_sorted(n_valid/2) + q_sorted(n_valid/2 + 1))
4033 IF (n_valid > 1) unstable(i_mo) = (q_sorted(n_valid) - q_sorted(1) > bs_env%nevanlinna%window_spread)
4036 DEALLOCATE (order, window_size, q_win, sigma_c_win, q_sorted, multi_count, z_dummy, m_dummy)
4038 CALL timestop(handle)
4040 END SUBROUTINE qp_median_over_windows
4050 SUBROUTINE propagate_unstable_marks(unstable, multi, homo)
4052 LOGICAL,
DIMENSION(:),
INTENT(INOUT) :: unstable
4053 LOGICAL,
DIMENSION(:),
INTENT(IN) :: multi
4054 INTEGER,
INTENT(IN) :: homo
4057 LOGICAL :: beyond_mark
4059 beyond_mark = .false.
4060 DO i_mo = homo, 1, -1
4061 IF (beyond_mark) unstable(i_mo) = .true.
4062 IF (unstable(i_mo) .OR. multi(i_mo)) beyond_mark = .true.
4065 beyond_mark = .false.
4066 DO i_mo = homo + 1,
SIZE(unstable)
4067 IF (beyond_mark) unstable(i_mo) = .true.
4068 IF (unstable(i_mo) .OR. multi(i_mo)) beyond_mark = .true.
4071 END SUBROUTINE propagate_unstable_marks
4082 SUBROUTINE print_qp_marks(bs_env, unstable, multi, n_window, ikp, ispin)
4085 LOGICAL,
DIMENSION(:),
INTENT(IN) :: unstable, multi
4086 INTEGER,
INTENT(IN) :: n_window, ikp, ispin
4090 homo = bs_env%n_occ(ispin)
4094 WRITE (u,
'(T2,A,I6,A,I2,A,I4,A)')
'GW analytic continuation (k-point', ikp,
', spin', &
4095 ispin,
'): Nevanlinna, median over', n_window,
' fit windows'
4096 WRITE (u,
'(T2,A,I49)')
'Levels marked * (not reliable)', count(unstable)
4097 WRITE (u,
'(T2,A,I47)')
'Levels marked m (multi-solution)', count(multi)
4098 WRITE (u,
'(T2,A)')
' '
4102 IF (unstable(homo))
THEN
4103 cpwarn(
"Analytic continuation unstable for the HOMO; its G0W0 energy is not reliable.")
4105 IF (multi(homo))
THEN
4106 cpwarn(
"The HOMO has a second quasiparticle solution of comparable weight.")
4109 IF (homo <
SIZE(unstable))
THEN
4110 IF (unstable(homo + 1))
THEN
4111 cpwarn(
"Analytic continuation unstable for the LUMO; its G0W0 energy is not reliable.")
4113 IF (multi(homo + 1))
THEN
4114 cpwarn(
"The LUMO has a second quasiparticle solution of comparable weight.")
4118 END SUBROUTINE print_qp_marks
4126 SUBROUTINE correct_obvious_fitting_fails(Sigma_c_ikp_n_qp, ispin, bs_env)
4127 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: sigma_c_ikp_n_qp
4131 CHARACTER(LEN=*),
PARAMETER :: routinen =
'correct_obvious_fitting_fails'
4133 INTEGER :: handle, homo, i_mo, j_mo, &
4134 n_levels_scissor, n_mo
4135 LOGICAL :: is_occ, is_vir
4136 REAL(kind=
dp) :: sum_sigma_c
4138 CALL timeset(routinen, handle)
4141 homo = bs_env%n_occ(ispin)
4146 IF (abs(sigma_c_ikp_n_qp(i_mo)) > 13.0_dp/
evolt)
THEN
4148 is_occ = (i_mo <= homo)
4149 is_vir = (i_mo > homo)
4151 n_levels_scissor = 0
4152 sum_sigma_c = 0.0_dp
4158 IF (is_occ .AND. j_mo > homo) cycle
4159 IF (is_vir .AND. j_mo <= homo) cycle
4160 IF (abs(i_mo - j_mo) > 10) cycle
4161 IF (i_mo == j_mo) cycle
4163 n_levels_scissor = n_levels_scissor + 1
4164 sum_sigma_c = sum_sigma_c + sigma_c_ikp_n_qp(j_mo)
4169 sigma_c_ikp_n_qp(i_mo) = sum_sigma_c/real(n_levels_scissor, kind=
dp)
4175 CALL timestop(handle)
4177 END SUBROUTINE correct_obvious_fitting_fails
4188 SUBROUTINE g_occ_vir(bs_env, tau, fm_G_Gamma, ispin, occ, vir)
4190 REAL(kind=
dp) :: tau
4195 CHARACTER(LEN=*),
PARAMETER :: routinen =
'G_occ_vir'
4197 INTEGER :: first_mo, handle, homo, i_mo, last_mo
4198 REAL(kind=
dp) :: tau_e
4199 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: column_factors
4201 CALL timeset(routinen, handle)
4203 cpassert(occ .NEQV. vir)
4205 homo = bs_env%n_occ(ispin)
4208 last_mo = min(bs_env%n_ao, bs_env%n_mo_retained)
4210 last_mo = min(last_mo, homo)
4214 ALLOCATE (column_factors(first_mo:last_mo))
4215 DO i_mo = first_mo, last_mo
4216 tau_e = abs(tau*0.5_dp*(bs_env%eigenval_scf_Gamma(i_mo, ispin) - bs_env%e_fermi(ispin)))
4217 IF (tau_e < bs_env%stabilize_exp)
THEN
4218 column_factors(i_mo) = exp(-tau_e)
4220 column_factors(i_mo) = 0.0_dp
4225 bs_env%fm_work_mo(1), fm_g_gamma)
4226 DEALLOCATE (column_factors)
4228 CALL timestop(handle)
static GRID_HOST_DEVICE int modulo(int a, int m)
Equivalent of Fortran's MODULO, which always return a positive number. https://gcc....
Define the atomic kind types and their sub types.
subroutine, public get_atomic_kind_set(atomic_kind_set, atom_of_kind, kind_of, natom_of_kind, maxatom, natom, nshell, fist_potential_present, shell_present, shell_adiabatic, shell_check_distance, damping_present)
Get attributes of an atomic kind set.
Automatic generation of auxiliary basis sets of different kind.
subroutine, public create_ri_aux_basis_set(ri_aux_basis_set, qs_kind, basis_cntrl, basis_type, basis_sort)
Create a RI_AUX basis set using some heuristics.
subroutine, public add_basis_set_to_container(container, basis_set, basis_set_type)
...
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, npgf_seg_sum, ccon)
...
subroutine, public init_orb_basis_set(gto_basis_set)
Initialise a Gaussian-type orbital (GTO) basis set data set.
collects all references to literature in CP2K as new algorithms / method are included from literature...
integer, save, public graml2024
Handles all functions related to the CELL.
subroutine, public scaled_to_real(r, s, cell)
Transform scaled cell coordinates real coordinates. r=h*s.
methods related to the blacs parallel environment
subroutine, public cp_blacs_env_release(blacs_env)
releases the given blacs_env
subroutine, public cp_blacs_env_create(blacs_env, para_env, blacs_grid_layout, blacs_repeatable, row_major, grid_2d)
allocates and initializes a type that represent a blacs context
Represents a complex full matrix distributed on many processors.
subroutine, public cp_cfm_copy_general(source, destination, para_env)
General copy of a cfm matrix to another cfm matrix. Uses non-blocking MPI rather than ScaLAPACK.
subroutine, public cp_cfm_release(matrix)
Releases a full matrix.
subroutine, public cp_cfm_create(matrix, matrix_struct, name, nrow, ncol, set_zero)
Creates a new full matrix with the given structure.
subroutine, public cp_cfm_to_fm(msource, mtargetr, mtargeti)
Copy real and imaginary parts of a complex full matrix into separate real-value full matrices.
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
subroutine, public dbcsr_set(matrix, alpha)
...
DBCSR operations in CP2K.
subroutine, public copy_dbcsr_to_fm(matrix, fm, plan, check_plan)
Copy a DBCSR matrix to a BLACS matrix.
subroutine, public copy_fm_to_dbcsr(fm, matrix, keep_sparsity)
Copy a BLACS matrix to a dbcsr matrix.
Utility routines to open and close files.
subroutine, public open_file(file_name, unit_number, file_status, file_form, file_action, file_position, file_pad, file_access, debug)
Opens a file and returns its logical unit number.
subroutine, public close_file(unit_number, file_status)
Closes an open file given by its logical unit number.
Basic linear algebra operations for full matrices.
subroutine, public cp_fm_scale_and_add(alpha, matrix_a, beta, matrix_b)
calc A <- alpha*A + beta*B optimized for alpha == 1.0 (just add beta*B) and beta == 0....
represent the structure of a full matrix
subroutine, public cp_fm_struct_create(fmstruct, para_env, context, nrow_global, ncol_global, nrow_block, ncol_block, descriptor, first_p_pos, local_leading_dimension, template_fmstruct, square_blocks, force_block)
allocates and initializes a full matrix structure
subroutine, public cp_fm_struct_release(fmstruct)
releases a full matrix structure
represent a full matrix distributed on many processors
subroutine, public cp_fm_get_diag(matrix, diag, n_active)
returns the diagonal elements of a fm
subroutine, public cp_fm_set_all(matrix, alpha, beta)
set all elements of a matrix to the same value, and optionally the diagonal to a different one
subroutine, public cp_fm_create(matrix, matrix_struct, name, nrow, ncol, set_zero)
creates a new full matrix with the given structure
various routines to log and control the output. The idea is that decisions about where to log should ...
type(cp_logger_type) function, pointer, public cp_get_default_logger()
returns the default logger
routines to handle the output, The idea is to remove the decision of wheter to output and what to out...
character(len=default_path_length) function, public cp_print_key_generate_filename(logger, print_key, middle_name, extension, my_local)
Utility function that returns a unit number to write the print key. Might open a file with a unique f...
This is the start of a dbt_api, all publically needed functions are exported here....
Automatic RI basis set optimization for molecular and periodic GW.
subroutine, public generate_auto_ri_basis(qs_env, bs_env)
Selects molecular or periodic atom-local AA RI-basis optimization.
Input and persistent data for automatic RI basis optimization.
Coulomb matrices and screened interactions for imaginary-time GW.
subroutine, public get_v_tr_r(v_tr_r, pot_type, regularization_ri, bs_env, qs_env)
...
Gamma-point (q = 0) correction of W and Σ for periodic RI-RS GW.
subroutine, public prepare_ri_rs_gamma_correction(qs_env, bs_env)
Preserve distributed AO position, Hamiltonian and overlap images before QS release....
Utility method to build 3-center integrals for small cell GW.
subroutine, public build_3c_integral_block(int_3c, qs_env, potential_parameter, basis_j, basis_k, basis_i, cell_j, cell_k, cell_i, atom_j, atom_k, atom_i, j_bf_start_from_atom, k_bf_start_from_atom, i_bf_start_from_atom)
...
Full-matrix operations not provided by the CP2K FM packages.
subroutine, public fm_invert(matrix_a, eigenvalue_threshold, unit_nr)
Inverts a symmetric matrix. First, Cholesky decomposition is tried. If it fails, the matrix is diagon...
subroutine, public cfm_contract_aba(matrix_a, matrix_b, matrix_c, workspace)
Computes A^H B A for complex full matrices.
subroutine, public local_complex_power(matrix, exponent, eps, cond_nr, min_ev, max_ev, relative_eps)
Compute a spectral power of a local complex Hermitian matrix. Eigenvalues not larger than eps (or rel...
subroutine, public rtbse_resolve_rirs_flag(qs_env, bs_env, rirs_kernel)
Resolve the linRTBSE RI-RS kernel switch from the KERNEL_RI input and the GW default.
subroutine, public compute_xkp(xkp, ikp_start, ikp_end, grid)
...
subroutine, public create_and_init_bs_env_for_gw(qs_env, bs_env, bs_sec)
Initializes the GW environment from the input and electronic-structure data.
subroutine, public add_r(cell_1, cell_2, index_to_cell, cell_1_plus_2, cell_found, cell_to_index, i_cell_1_plus_2)
...
subroutine, public de_init_bs_env(qs_env, bs_env)
Releases the memory-heavy GW intermediates that cannot be freed in bs_env_release,...
subroutine, public analyt_conti_and_print(bs_env, sigma_c_ikp_n_freq, sigma_x_ikp_n, v_xc_ikp_n, eigenval_scf, ikp, ispin, i_iter)
...
subroutine, public is_cell_in_index_to_cell(cell, index_to_cell, cell_found)
...
subroutine, public g_occ_vir(bs_env, tau, fm_g_gamma, ispin, occ, vir)
Build the real Gamma occupied or virtual one-particle propagator.
Defines the basic variable types.
integer, parameter, public int_8
integer, parameter, public dp
integer, parameter, public default_string_length
integer, parameter, public default_path_length
Implements simple k-space/R-space transformations and Gamma-point MIC reconstruction.
subroutine, public rs_to_kp(rs_real, ks_complex, index_to_cell, xkp, deriv_direction, hmat)
Integrate RS matrices (stored as Fortran array) into a kpoint matrix at given kp.
Types and basic routines needed for a kpoint calculation.
subroutine, public kpoint_release(kpoint)
Release a kpoint environment, deallocate all data.
subroutine, public kpoint_create(kpoint)
Create a kpoint environment.
Machine interface based on Fortran 2003 and POSIX.
real(kind=dp) function, public m_walltime()
returns time from a real-time clock, protected against rolling early/easily
Collection of simple mathematical functions and subroutines.
elemental integer function, public gcd(a, b)
computes the greatest common divisor of two number
subroutine, public erfc_cutoff(eps, omg, r_cutoff)
compute a truncation radius for the shortrange operator
Interface to the message passing library MPI.
subroutine, public mp_mem_used_per_rank_gb(comm, mem_used_gb)
Memory that is currently occupied by this process, in GB, maximized over all ranks of comm,...
subroutine, public mp_mem_avail_per_rank_gb(comm, mem_avail_gb)
Memory that is currently free on the node, per MPI rank of that node, in GB.
Calls routines to get RI integrals and calculate total energies.
subroutine, public create_mat_munu(mat_munu, qs_env, eps_grid, blacs_env_sub, do_ri_aux_basis, do_mixed_basis, group_size_prim, do_alloc_blocks_from_nbl, do_kpoints, sab_orb_sub, dbcsr_sym_type, custom_row_blk_sizes)
Encapsulate the building of dbcsr_matrix mat_munu.
Framework for 2c-integrals for RI.
subroutine, public ri_2c_integral_mat(qs_env, fm_matrix_minv_l_gamma, fm_matrix_l_struct, dimen_ri, ri_metric, put_mat_ks_env, regularization_ri)
...
subroutine, public trunc_coulomb_for_exchange(qs_env, trunc_coulomb, rel_cutoff_trunc_coulomb_ri_x, cell_grid, do_bvk_cell)
...
Define methods related to particle_type.
subroutine, public get_particle_set(particle_set, qs_kind_set, first_sgf, last_sgf, nsgf, nmao, basis, ncgf)
Get the components of a particle set.
Define the data structure for the particle information.
Definition of physical constants:
real(kind=dp), parameter, public evolt
real(kind=dp), parameter, public angstrom
character(len=default_string_length) function, public gw_flavour_label(bs_env)
Name of the GW flavour that was requested, for printing.
subroutine, public create_operator_kpoints(qs_env, bs_env, kpoints, cfm_kp_group)
Set up the bandstructure and DOS k-points as one k-point group spanning all ranks,...
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, mimic, 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_pp, sab_xtb_nonbond, sab_almo, sab_kp, sab_kp_nosym, sab_cneo, 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, matrix_vhxc, 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, xcint_weights, 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, rhoz_cneo_set, ecoul_1c, rho0_s_rs, rho0_s_gs, rhoz_cneo_s_rs, rhoz_cneo_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, harris_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, eeq, rhs, do_rixs, tb_tblite)
Get the QUICKSTEP environment.
subroutine, public qs_env_part_release(qs_env)
releases part of the given qs_env in order to save memory
Some utility functions for the calculation of integrals.
subroutine, public basis_set_list_setup(basis_set_list, basis_type, qs_kind_set)
Set up an easy accessible list of the basis sets for all kinds.
Calculate the interaction radii for the operator matrix calculation.
subroutine, public init_interaction_radii_orb_basis(orb_basis_set, eps_pgf_orb, eps_pgf_short)
...
Define the quickstep kind type and their sub types.
subroutine, public get_qs_kind(qs_kind, basis_set, basis_type, ncgf, nsgf, all_potential, tnadd_potential, gth_potential, sgp_potential, upf_potential, cneo_potential, se_parameter, dftb_parameter, xtb_parameter, dftb3_param, zatom, zeff, elec_conf, mao, lmax_dftb, alpha_core_charge, ccore_charge, core_charge, core_charge_radius, paw_proj_set, paw_atom, hard_radius, hard0_radius, max_rad_local, covalent_radius, vdw_radius, gpw_type_forced, harmonics, max_iso_not0, max_s_harm, grid_atom, ngrid_ang, ngrid_rad, lmax_rho0, dft_plus_u_atom, l_of_dft_plus_u, n_of_dft_plus_u, u_minus_j, hund_j, u_of_dft_plus_u, j_of_dft_plus_u, alpha_of_dft_plus_u, beta_of_dft_plus_u, j0_of_dft_plus_u, occupation_of_dft_plus_u, dispersion, bs_occupation, magnetization, no_optimize, addel, laddel, naddel, orbitals, max_scf, eps_scf, smear, u_ramping, u_minus_j_target, eps_u_ramping, proj_shell_charge, lr_atom, do_mtlr, u_j_loop, ao_coef, init_u_ramping_each_scf, reltmat, ghost, monovalent, floating, name, element_symbol, pao_basis_size, pao_model_file, pao_potentials, pao_descriptors, nelec)
Get attributes of an atomic kind.
Assembly of real and complex k-point operators from real-space DBCSR matrices. Outputs use the distri...
subroutine, public kpoint_operator_context_create(ctx, kpoints, ao_ao_fm, nspin)
Create an empty operator context. The context owns no buffers after this call; they are created on fi...
subroutine, public kpoint_operator_prepare(ctx, rsmat, slot, prepared, matrix_row, target)
Prepare an immutable operator slot for group-local assembly. Refresh after the source values change,...
subroutine, public kpoint_operator_get(ctx, ikp, ispin, rsmat, cmat, fm_re, fm_im, mat_re, mat_im, matrix_row, slot, grid)
Assemble one operator for one global round and spin in one call: run the single-group transfer of the...
integer, parameter, public kpoint_slot_ks
subroutine, public kpoint_operator_context_release(ctx)
Release the context together with every buffer it created. Call once, at the end of the fixed-layout ...
routines that build the Kohn-Sham matrix (i.e calculate the coulomb and xc parts
subroutine, public qs_ks_build_kohn_sham_matrix(qs_env, calculate_forces, just_energy, print_active, ext_ks_matrix, ext_xc_section)
routine where the real calculations are made: the KS matrix is calculated
methods of the rho structure (defined in qs_rho_types)
subroutine, public qs_rho_update_rho(rho_struct, qs_env, rho_xc_external, local_rho_set, task_list_external, task_list_external_soft, pw_env_external, para_env_external)
updates rho_r and rho_g to the rhorho_ao. if use_kinetic_energy_density also computes tau_r and tau_g...
superstucture that hold various representations of the density and keeps track of which ones are vali...
Utility methods to build 3-center integral tensors of various types.
subroutine, public distribution_3d_create(dist_3d, dist1, dist2, dist3, nkind, particle_set, mp_comm_3d, own_comm)
Create a 3d distribution.
subroutine, public create_2c_tensor(t2c, dist_1, dist_2, pgrid, sizes_1, sizes_2, order, name)
...
subroutine, public create_3c_tensor(t3c, dist_1, dist_2, dist_3, pgrid, sizes_1, sizes_2, sizes_3, map1, map2, name)
...
Utility methods to build 3-center integral tensors of various types.
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, cell_sym, bounds_i, bounds_j, bounds_k, ri_range, img_to_ri_cell, cell_to_index_ext)
Build 3-center integral tensor.
subroutine, public neighbor_list_3c_destroy(ijk_list)
Destroy 3c neighborlist.
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.
Shared real-space resolution-of-identity grid and matrix data.
Utility routines for RPA and GW with imaginary time.
Routines for GW, continuous development [Jan Wilhelm].
subroutine, public continuation_pade(vec_gw_energ, vec_omega_fit_gw, z_value, m_value, vec_sigma_c_gw, vec_sigma_x_minus_vxc_gw, eigenval, eigenval_scf, do_hedin_shift, n_level_gw, gw_corr_lev_occ, gw_corr_lev_vir, nparam_pade, num_fit_points, crossing_search, homo, fermi_level_offset, do_gw_im_time, print_self_energy, count_ev_sc_gw, vec_gw_dos, dos_lower_bound, dos_precision, ndos, min_level_self_energy, max_level_self_energy, dos_eta, dos_min, dos_max, e_fermi_ext, output_spin, output_kpoint, ac_method, ac_used, ac_pick, num_fit_points_pade, qp_start_eigenval, qp_newton_max_step, qp_maxz_radius, qp_multi)
perform analytic continuation with pade approximation
Definition and construction of time/frequency grids for correlation methods.
subroutine, public build_minimax_time_frequency_grid(num_points, energy_min, energy_max, regularization, num_points_per_magnitude, grid, build_frequency, build_time, build_transforms, build_sine, time_scaling, time_weight_scaling, max_fit_error, print_warning, unit_nr, prefer_external_backend, used_external_backend, rcond)
Build a minimax time/frequency grid through the common backend boundary.
All kind of helpful little routines.
Provides all information about an atomic kind.
Type defining parameters related to the simulation cell.
represent a blacs multidimensional parallel environment (for the mpi corrispective see cp_paratypes/m...
Represent a complex full matrix.
keeps the information about the structure of a full matrix
type of a logger, at the moment it contains just a print level starting at which level it should be l...
Contains information about kpoints.
stores all the informations relevant to an mpi environment
Provides all information about a quickstep kind.
Caller-owned assembly context for a fixed geometry and parallel layout. OT retains it for one inner S...
keeps the density in various representations, keeping track of which ones are valid.