(git:419edc0)
Loading...
Searching...
No Matches
gw_utils.F
Go to the documentation of this file.
1!--------------------------------------------------------------------------------------------------!
2! CP2K: A general program to perform molecular dynamics simulations !
3! Copyright 2000-2025 CP2K developers group <https://cp2k.org> !
4! !
5! SPDX-License-Identifier: GPL-2.0-or-later !
6!--------------------------------------------------------------------------------------------------!
7
8! **************************************************************************************************
9!> \brief
10!> \author Jan Wilhelm
11!> \date 07.2023
12! **************************************************************************************************
18 USE bibliography, ONLY: graml2024,&
19 cite_reference
20 USE cell_types, ONLY: cell_type,&
21 pbc,&
26 USE cp_cfm_types, ONLY: cp_cfm_create,&
32 USE cp_dbcsr_api, ONLY: &
34 dbcsr_release, dbcsr_set, dbcsr_type, dbcsr_type_no_symmetry, dbcsr_type_symmetric
40 USE cp_files, ONLY: close_file,&
46 USE cp_fm_types, ONLY: cp_fm_create,&
54 USE dbt_api, ONLY: &
55 dbt_clear, dbt_create, dbt_destroy, dbt_filter, dbt_iterator_blocks_left, &
56 dbt_iterator_next_block, dbt_iterator_start, dbt_iterator_stop, dbt_iterator_type, &
57 dbt_mp_environ_pgrid, dbt_pgrid_create, dbt_pgrid_destroy, dbt_pgrid_type, dbt_type
73 USE kinds, ONLY: default_string_length,&
74 dp,&
75 int_8
77 USE kpoint_types, ONLY: get_kpoint_info,&
83 USE machine, ONLY: m_memory,&
85 USE mathconstants, ONLY: gaussi,&
86 z_one,&
87 z_zero
88 USE mathlib, ONLY: diag_complex,&
89 gcd
90 USE message_passing, ONLY: mp_cart_type,&
96 USE mp2_gpw, ONLY: create_mat_munu
104 USE physcon, ONLY: angstrom,&
105 evolt
114 USE qs_kind_types, ONLY: get_qs_kind,&
119 USE qs_tensors, ONLY: build_2c_integrals,&
130 USE rpa_gw, ONLY: continuation_pade
131#include "base/base_uses.f90"
132
133 IMPLICIT NONE
134
135 PRIVATE
136
140
141 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'gw_utils'
142
143CONTAINS
144
145! **************************************************************************************************
146!> \brief ...
147!> \param qs_env ...
148!> \param bs_env ...
149!> \param bs_sec ...
150! **************************************************************************************************
151 SUBROUTINE create_and_init_bs_env_for_gw(qs_env, bs_env, bs_sec)
152 TYPE(qs_environment_type), POINTER :: qs_env
153 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
154 TYPE(section_vals_type), POINTER :: bs_sec
155
156 CHARACTER(LEN=*), PARAMETER :: routinen = 'create_and_init_bs_env_for_gw'
157
158 INTEGER :: handle
159
160 CALL timeset(routinen, handle)
161
162 CALL cite_reference(graml2024)
163
164 CALL read_gw_input_parameters(bs_env, bs_sec)
165
166 CALL print_header_and_input_parameters(bs_env)
167
168 CALL setup_ao_and_ri_basis_set(qs_env, bs_env)
169
170 CALL get_ri_basis_and_basis_function_indices(qs_env, bs_env)
171
172 CALL set_heuristic_parameters(bs_env, qs_env)
173
175
176 CALL setup_kpoints_chi_eps_w(bs_env, bs_env%kpoints_chi_eps_W)
177
178 IF (bs_env%small_cell_full_kp_or_large_cell_Gamma == small_cell_full_kp) THEN
179 CALL setup_cells_3c(qs_env, bs_env)
180 END IF
181
182 CALL set_parallelization_parameters(qs_env, bs_env)
183
184 CALL allocate_matrices(qs_env, bs_env)
185
186 CALL compute_v_xc(qs_env, bs_env)
187
188 CALL create_tensors(qs_env, bs_env)
189
190 SELECT CASE (bs_env%small_cell_full_kp_or_large_cell_Gamma)
191 CASE (large_cell_gamma)
192
193 CALL allocate_gw_eigenvalues(bs_env)
194
195 CALL check_sparsity_3c(qs_env, bs_env)
196
197 CALL set_sparsity_parallelization_parameters(bs_env)
198
199 CALL check_for_restart_files(qs_env, bs_env)
200
201 CASE (small_cell_full_kp)
202
203 CALL compute_3c_integrals(qs_env, bs_env)
204
205 CALL setup_cells_delta_r(bs_env)
206
207 CALL setup_parallelization_delta_r(bs_env)
208
209 CALL allocate_matrices_small_cell_full_kp(qs_env, bs_env)
210
211 CALL trafo_v_xc_r_to_kp(qs_env, bs_env)
212
213 CALL heuristic_ri_regularization(qs_env, bs_env)
214
215 END SELECT
216
217 CALL setup_time_and_frequency_minimax_grid(bs_env)
218
219 ! free memory in qs_env; only if one is not calculating the LDOS because
220 ! we need real-space grid operations in pw_env, task_list for the LDOS
221 ! Recommendation in case of memory issues: first perform GW calculation without calculating
222 ! LDOS (to safe memor). Then, use GW restart files
223 ! in a subsequent calculation to calculate the LDOS
224 ! Marek : TODO - boolean that does not interfere with RTP init but sets this to correct value
225 IF (.NOT. bs_env%do_ldos .AND. .false.) THEN
226 CALL qs_env_part_release(qs_env)
227 END IF
228
229 CALL timestop(handle)
230
231 END SUBROUTINE create_and_init_bs_env_for_gw
232
233! **************************************************************************************************
234!> \brief ...
235!> \param bs_env ...
236! **************************************************************************************************
237 SUBROUTINE de_init_bs_env(bs_env)
238 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
239
240 CHARACTER(LEN=*), PARAMETER :: routinen = 'de_init_bs_env'
241
242 INTEGER :: handle
243
244 CALL timeset(routinen, handle)
245 ! deallocate quantities here which:
246 ! 1. cannot be deallocated in bs_env_release due to circular dependencies
247 ! 2. consume a lot of memory and should not be kept until the quantity is
248 ! deallocated in bs_env_release
249
250 IF (ASSOCIATED(bs_env%nl_3c%ij_list) .AND. (bs_env%rtp_method == rtp_method_bse)) THEN
251 IF (bs_env%unit_nr > 0) WRITE (bs_env%unit_nr, *) "Retaining nl_3c for RTBSE"
252 ELSE
253 CALL neighbor_list_3c_destroy(bs_env%nl_3c)
254 END IF
255
257
258 CALL timestop(handle)
259
260 END SUBROUTINE de_init_bs_env
261
262! **************************************************************************************************
263!> \brief ...
264!> \param bs_env ...
265!> \param bs_sec ...
266! **************************************************************************************************
267 SUBROUTINE read_gw_input_parameters(bs_env, bs_sec)
268 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
269 TYPE(section_vals_type), POINTER :: bs_sec
270
271 CHARACTER(LEN=*), PARAMETER :: routinen = 'read_gw_input_parameters'
272
273 INTEGER :: handle
274 TYPE(section_vals_type), POINTER :: gw_sec
275
276 CALL timeset(routinen, handle)
277
278 NULLIFY (gw_sec)
279 gw_sec => section_vals_get_subs_vals(bs_sec, "GW")
280
281 CALL section_vals_val_get(gw_sec, "NUM_TIME_FREQ_POINTS", i_val=bs_env%num_time_freq_points)
282 CALL section_vals_val_get(gw_sec, "EPS_FILTER", r_val=bs_env%eps_filter)
283 CALL section_vals_val_get(gw_sec, "REGULARIZATION_RI", r_val=bs_env%input_regularization_RI)
284 CALL section_vals_val_get(gw_sec, "CUTOFF_RADIUS_RI", r_val=bs_env%ri_metric%cutoff_radius)
285 CALL section_vals_val_get(gw_sec, "MEMORY_PER_PROC", r_val=bs_env%input_memory_per_proc_GB)
286 CALL section_vals_val_get(gw_sec, "APPROX_KP_EXTRAPOL", l_val=bs_env%approx_kp_extrapol)
287 CALL section_vals_val_get(gw_sec, "SIZE_LATTICE_SUM", i_val=bs_env%size_lattice_sum_V)
288 CALL section_vals_val_get(gw_sec, "KPOINTS_W", i_vals=bs_env%nkp_grid_chi_eps_W_input)
289 CALL section_vals_val_get(gw_sec, "HEDIN_SHIFT", l_val=bs_env%do_hedin_shift)
290 CALL section_vals_val_get(gw_sec, "FREQ_MAX_FIT", r_val=bs_env%freq_max_fit)
291
292 CALL timestop(handle)
293
294 END SUBROUTINE read_gw_input_parameters
295
296! **************************************************************************************************
297!> \brief ...
298!> \param qs_env ...
299!> \param bs_env ...
300! **************************************************************************************************
301 SUBROUTINE setup_ao_and_ri_basis_set(qs_env, bs_env)
302 TYPE(qs_environment_type), POINTER :: qs_env
303 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
304
305 CHARACTER(LEN=*), PARAMETER :: routinen = 'setup_AO_and_RI_basis_set'
306
307 INTEGER :: handle, natom, nkind
308 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
309 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
310
311 CALL timeset(routinen, handle)
312
313 CALL get_qs_env(qs_env, &
314 qs_kind_set=qs_kind_set, &
315 particle_set=particle_set, &
316 natom=natom, nkind=nkind)
317
318 ! set up basis
319 ALLOCATE (bs_env%sizes_RI(natom), bs_env%sizes_AO(natom))
320 ALLOCATE (bs_env%basis_set_RI(nkind), bs_env%basis_set_AO(nkind))
321
322 CALL basis_set_list_setup(bs_env%basis_set_RI, "RI_AUX", qs_kind_set)
323 CALL basis_set_list_setup(bs_env%basis_set_AO, "ORB", qs_kind_set)
324
325 CALL get_particle_set(particle_set, qs_kind_set, nsgf=bs_env%sizes_RI, &
326 basis=bs_env%basis_set_RI)
327 CALL get_particle_set(particle_set, qs_kind_set, nsgf=bs_env%sizes_AO, &
328 basis=bs_env%basis_set_AO)
329
330 CALL timestop(handle)
331
332 END SUBROUTINE setup_ao_and_ri_basis_set
333
334! **************************************************************************************************
335!> \brief ...
336!> \param qs_env ...
337!> \param bs_env ...
338! **************************************************************************************************
339 SUBROUTINE get_ri_basis_and_basis_function_indices(qs_env, bs_env)
340 TYPE(qs_environment_type), POINTER :: qs_env
341 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
342
343 CHARACTER(LEN=*), PARAMETER :: routinen = 'get_RI_basis_and_basis_function_indices'
344
345 INTEGER :: handle, i_ri, iatom, ikind, iset, &
346 max_ao_bf_per_atom, n_ao_test, n_atom, &
347 n_kind, n_ri, nset, nsgf, u
348 INTEGER, ALLOCATABLE, DIMENSION(:) :: kind_of
349 INTEGER, DIMENSION(:), POINTER :: l_max, l_min, nsgf_set
350 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
351 TYPE(gto_basis_set_type), POINTER :: basis_set_a
352 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
353
354 CALL timeset(routinen, handle)
355
356 ! determine RI basis set size
357 CALL get_qs_env(qs_env, atomic_kind_set=atomic_kind_set, qs_kind_set=qs_kind_set)
358
359 n_kind = SIZE(qs_kind_set)
360 n_atom = bs_env%n_atom
361
362 CALL get_atomic_kind_set(atomic_kind_set, kind_of=kind_of)
363
364 DO ikind = 1, n_kind
365 CALL get_qs_kind(qs_kind=qs_kind_set(ikind), basis_set=basis_set_a, &
366 basis_type="RI_AUX")
367 IF (.NOT. ASSOCIATED(basis_set_a)) THEN
368 CALL cp_abort(__location__, &
369 "At least one RI_AUX basis set was not explicitly invoked in &KIND-section.")
370 END IF
371 END DO
372
373 ALLOCATE (bs_env%i_RI_start_from_atom(n_atom))
374 ALLOCATE (bs_env%i_RI_end_from_atom(n_atom))
375 ALLOCATE (bs_env%i_ao_start_from_atom(n_atom))
376 ALLOCATE (bs_env%i_ao_end_from_atom(n_atom))
377
378 n_ri = 0
379 DO iatom = 1, n_atom
380 bs_env%i_RI_start_from_atom(iatom) = n_ri + 1
381 ikind = kind_of(iatom)
382 CALL get_qs_kind(qs_kind=qs_kind_set(ikind), nsgf=nsgf, basis_type="RI_AUX")
383 n_ri = n_ri + nsgf
384 bs_env%i_RI_end_from_atom(iatom) = n_ri
385 END DO
386 bs_env%n_RI = n_ri
387
388 max_ao_bf_per_atom = 0
389 n_ao_test = 0
390 DO iatom = 1, n_atom
391 bs_env%i_ao_start_from_atom(iatom) = n_ao_test + 1
392 ikind = kind_of(iatom)
393 CALL get_qs_kind(qs_kind=qs_kind_set(ikind), nsgf=nsgf, basis_type="ORB")
394 n_ao_test = n_ao_test + nsgf
395 bs_env%i_ao_end_from_atom(iatom) = n_ao_test
396 max_ao_bf_per_atom = max(max_ao_bf_per_atom, nsgf)
397 END DO
398 cpassert(n_ao_test == bs_env%n_ao)
399 bs_env%max_AO_bf_per_atom = max_ao_bf_per_atom
400
401 ALLOCATE (bs_env%l_RI(n_ri))
402 i_ri = 0
403 DO iatom = 1, n_atom
404 ikind = kind_of(iatom)
405
406 nset = bs_env%basis_set_RI(ikind)%gto_basis_set%nset
407 l_max => bs_env%basis_set_RI(ikind)%gto_basis_set%lmax
408 l_min => bs_env%basis_set_RI(ikind)%gto_basis_set%lmin
409 nsgf_set => bs_env%basis_set_RI(ikind)%gto_basis_set%nsgf_set
410
411 DO iset = 1, nset
412 cpassert(l_max(iset) == l_min(iset))
413 bs_env%l_RI(i_ri + 1:i_ri + nsgf_set(iset)) = l_max(iset)
414 i_ri = i_ri + nsgf_set(iset)
415 END DO
416
417 END DO
418 cpassert(i_ri == n_ri)
419
420 u = bs_env%unit_nr
421
422 IF (u > 0) THEN
423 WRITE (u, fmt="(T2,A)") " "
424 WRITE (u, fmt="(T2,2A,T75,I8)") "Number of auxiliary Gaussian basis functions ", &
425 χε"for , , W", n_ri
426 END IF
427
428 CALL timestop(handle)
429
430 END SUBROUTINE get_ri_basis_and_basis_function_indices
431
432! **************************************************************************************************
433!> \brief ...
434!> \param bs_env ...
435!> \param kpoints ...
436! **************************************************************************************************
437 SUBROUTINE setup_kpoints_chi_eps_w(bs_env, kpoints)
438
439 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
440 TYPE(kpoint_type), POINTER :: kpoints
441
442 CHARACTER(LEN=*), PARAMETER :: routinen = 'setup_kpoints_chi_eps_W'
443
444 INTEGER :: handle, i_dim, n_dim, nkp, nkp_extra, &
445 nkp_orig, u
446 INTEGER, DIMENSION(3) :: nkp_grid, nkp_grid_extra, periodic
447 REAL(kind=dp) :: exp_s_p, n_dim_inv
448
449 CALL timeset(routinen, handle)
450
451 ! routine adapted from mp2_integrals.F
452 NULLIFY (kpoints)
453 CALL kpoint_create(kpoints)
454
455 kpoints%kp_scheme = "GENERAL"
456
457 periodic(1:3) = bs_env%periodic(1:3)
458
459 cpassert(SIZE(bs_env%nkp_grid_chi_eps_W_input) == 3)
460
461 IF (bs_env%nkp_grid_chi_eps_W_input(1) > 0 .AND. &
462 bs_env%nkp_grid_chi_eps_W_input(2) > 0 .AND. &
463 bs_env%nkp_grid_chi_eps_W_input(3) > 0) THEN
464 ! 1. k-point mesh for χ, ε, W from input
465 DO i_dim = 1, 3
466 SELECT CASE (periodic(i_dim))
467 CASE (0)
468 nkp_grid(i_dim) = 1
469 nkp_grid_extra(i_dim) = 1
470 CASE (1)
471 nkp_grid(i_dim) = bs_env%nkp_grid_chi_eps_W_input(i_dim)
472 nkp_grid_extra(i_dim) = nkp_grid(i_dim)*2
473 CASE DEFAULT
474 cpabort("Error in periodicity.")
475 END SELECT
476 END DO
477
478 ELSE IF (bs_env%nkp_grid_chi_eps_W_input(1) == -1 .AND. &
479 bs_env%nkp_grid_chi_eps_W_input(2) == -1 .AND. &
480 bs_env%nkp_grid_chi_eps_W_input(3) == -1) THEN
481 ! 2. automatic k-point mesh for χ, ε, W
482
483 DO i_dim = 1, 3
484
485 cpassert(periodic(i_dim) == 0 .OR. periodic(i_dim) == 1)
486
487 SELECT CASE (periodic(i_dim))
488 CASE (0)
489 nkp_grid(i_dim) = 1
490 nkp_grid_extra(i_dim) = 1
491 CASE (1)
492 SELECT CASE (bs_env%small_cell_full_kp_or_large_cell_Gamma)
493 CASE (large_cell_gamma)
494 nkp_grid(i_dim) = 4
495 nkp_grid_extra(i_dim) = 6
496 CASE (small_cell_full_kp)
497 nkp_grid(i_dim) = bs_env%kpoints_scf_desymm%nkp_grid(i_dim)*4
498 nkp_grid_extra(i_dim) = bs_env%kpoints_scf_desymm%nkp_grid(i_dim)*8
499 END SELECT
500 CASE DEFAULT
501 cpabort("Error in periodicity.")
502 END SELECT
503
504 END DO
505
506 ELSE
507
508 cpabort("An error occured when setting up the k-mesh for W.")
509
510 END IF
511
512 nkp_orig = max(nkp_grid(1)*nkp_grid(2)*nkp_grid(3)/2, 1)
513
514 nkp_extra = nkp_grid_extra(1)*nkp_grid_extra(2)*nkp_grid_extra(3)/2
515
516 nkp = nkp_orig + nkp_extra
517
518 kpoints%nkp_grid(1:3) = nkp_grid(1:3)
519 kpoints%nkp = nkp
520
521 bs_env%nkp_grid_chi_eps_W_orig(1:3) = nkp_grid(1:3)
522 bs_env%nkp_grid_chi_eps_W_extra(1:3) = nkp_grid_extra(1:3)
523 bs_env%nkp_chi_eps_W_orig = nkp_orig
524 bs_env%nkp_chi_eps_W_extra = nkp_extra
525 bs_env%nkp_chi_eps_W_orig_plus_extra = nkp
526
527 ALLOCATE (kpoints%xkp(3, nkp), kpoints%wkp(nkp))
528 ALLOCATE (bs_env%wkp_no_extra(nkp), bs_env%wkp_s_p(nkp))
529
530 CALL compute_xkp(kpoints%xkp, 1, nkp_orig, nkp_grid)
531 CALL compute_xkp(kpoints%xkp, nkp_orig + 1, nkp, nkp_grid_extra)
532
533 n_dim = sum(periodic)
534 IF (n_dim == 0) THEN
535 ! molecules
536 kpoints%wkp(1) = 1.0_dp
537 bs_env%wkp_s_p(1) = 1.0_dp
538 bs_env%wkp_no_extra(1) = 1.0_dp
539 ELSE
540
541 n_dim_inv = 1.0_dp/real(n_dim, kind=dp)
542
543 ! k-point weights are chosen to automatically extrapolate the k-point mesh
544 CALL compute_wkp(kpoints%wkp(1:nkp_orig), nkp_orig, nkp_extra, n_dim_inv)
545 CALL compute_wkp(kpoints%wkp(nkp_orig + 1:nkp), nkp_extra, nkp_orig, n_dim_inv)
546
547 bs_env%wkp_no_extra(1:nkp_orig) = 0.0_dp
548 bs_env%wkp_no_extra(nkp_orig + 1:nkp) = 1.0_dp/real(nkp_extra, kind=dp)
549
550 IF (n_dim == 3) THEN
551 ! W_PQ(k) for an s-function P and a p-function Q diverges as 1/k at k=0
552 ! (instead of 1/k^2 for P and Q both being s-functions).
553 exp_s_p = 2.0_dp*n_dim_inv
554 CALL compute_wkp(bs_env%wkp_s_p(1:nkp_orig), nkp_orig, nkp_extra, exp_s_p)
555 CALL compute_wkp(bs_env%wkp_s_p(nkp_orig + 1:nkp), nkp_extra, nkp_orig, exp_s_p)
556 ELSE
557 bs_env%wkp_s_p(1:nkp) = bs_env%wkp_no_extra(1:nkp)
558 END IF
559
560 END IF
561
562 IF (bs_env%approx_kp_extrapol) THEN
563 bs_env%wkp_orig = 1.0_dp/real(nkp_orig, kind=dp)
564 END IF
565
566 ! heuristic parameter: how many k-points for χ, ε, and W are used simultaneously
567 ! (less simultaneous k-points: less memory, but more computational effort because of
568 ! recomputation of V(k))
569 bs_env%nkp_chi_eps_W_batch = 4
570
571 bs_env%num_chi_eps_W_batches = (bs_env%nkp_chi_eps_W_orig_plus_extra - 1)/ &
572 bs_env%nkp_chi_eps_W_batch + 1
573
574 u = bs_env%unit_nr
575
576 IF (u > 0) THEN
577 WRITE (u, fmt="(T2,A)") " "
578 WRITE (u, fmt="(T2,1A,T71,3I4)") χε"K-point mesh 1 for , , W", nkp_grid(1:3)
579 WRITE (u, fmt="(T2,2A,T71,3I4)") χε"K-point mesh 2 for , , W ", &
580 "(for k-point extrapolation of W)", nkp_grid_extra(1:3)
581 WRITE (u, fmt="(T2,A,T80,L)") "Approximate the k-point extrapolation", &
582 bs_env%approx_kp_extrapol
583 END IF
584
585 CALL timestop(handle)
586
587 END SUBROUTINE setup_kpoints_chi_eps_w
588
589! **************************************************************************************************
590!> \brief ...
591!> \param kpoints ...
592!> \param qs_env ...
593! **************************************************************************************************
594 SUBROUTINE kpoint_init_cell_index_simple(kpoints, qs_env)
595
596 TYPE(kpoint_type), POINTER :: kpoints
597 TYPE(qs_environment_type), POINTER :: qs_env
598
599 CHARACTER(LEN=*), PARAMETER :: routinen = 'kpoint_init_cell_index_simple'
600
601 INTEGER :: handle
602 TYPE(dft_control_type), POINTER :: dft_control
603 TYPE(mp_para_env_type), POINTER :: para_env
604 TYPE(neighbor_list_set_p_type), DIMENSION(:), &
605 POINTER :: sab_orb
606
607 CALL timeset(routinen, handle)
608
609 NULLIFY (dft_control, para_env, sab_orb)
610 CALL get_qs_env(qs_env=qs_env, para_env=para_env, dft_control=dft_control, sab_orb=sab_orb)
611 CALL kpoint_init_cell_index(kpoints, sab_orb, para_env, dft_control)
612
613 CALL timestop(handle)
614
615 END SUBROUTINE kpoint_init_cell_index_simple
616
617! **************************************************************************************************
618!> \brief ...
619!> \param xkp ...
620!> \param ikp_start ...
621!> \param ikp_end ...
622!> \param grid ...
623! **************************************************************************************************
624 SUBROUTINE compute_xkp(xkp, ikp_start, ikp_end, grid)
625
626 REAL(kind=dp), DIMENSION(:, :), POINTER :: xkp
627 INTEGER :: ikp_start, ikp_end
628 INTEGER, DIMENSION(3) :: grid
629
630 CHARACTER(LEN=*), PARAMETER :: routinen = 'compute_xkp'
631
632 INTEGER :: handle, i, ix, iy, iz
633
634 CALL timeset(routinen, handle)
635
636 i = ikp_start
637 DO ix = 1, grid(1)
638 DO iy = 1, grid(2)
639 DO iz = 1, grid(3)
640
641 IF (i > ikp_end) cycle
642
643 xkp(1, i) = real(2*ix - grid(1) - 1, kind=dp)/(2._dp*real(grid(1), kind=dp))
644 xkp(2, i) = real(2*iy - grid(2) - 1, kind=dp)/(2._dp*real(grid(2), kind=dp))
645 xkp(3, i) = real(2*iz - grid(3) - 1, kind=dp)/(2._dp*real(grid(3), kind=dp))
646 i = i + 1
647
648 END DO
649 END DO
650 END DO
651
652 CALL timestop(handle)
653
654 END SUBROUTINE compute_xkp
655
656! **************************************************************************************************
657!> \brief ...
658!> \param wkp ...
659!> \param nkp_1 ...
660!> \param nkp_2 ...
661!> \param exponent ...
662! **************************************************************************************************
663 SUBROUTINE compute_wkp(wkp, nkp_1, nkp_2, exponent)
664 REAL(kind=dp), DIMENSION(:) :: wkp
665 INTEGER :: nkp_1, nkp_2
666 REAL(kind=dp) :: exponent
667
668 CHARACTER(LEN=*), PARAMETER :: routinen = 'compute_wkp'
669
670 INTEGER :: handle
671 REAL(kind=dp) :: nkp_ratio
672
673 CALL timeset(routinen, handle)
674
675 nkp_ratio = real(nkp_2, kind=dp)/real(nkp_1, kind=dp)
676
677 wkp(:) = 1.0_dp/real(nkp_1, kind=dp)/(1.0_dp - nkp_ratio**exponent)
678
679 CALL timestop(handle)
680
681 END SUBROUTINE compute_wkp
682
683! **************************************************************************************************
684!> \brief ...
685!> \param qs_env ...
686!> \param bs_env ...
687! **************************************************************************************************
688 SUBROUTINE allocate_matrices(qs_env, bs_env)
689 TYPE(qs_environment_type), POINTER :: qs_env
690 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
691
692 CHARACTER(LEN=*), PARAMETER :: routinen = 'allocate_matrices'
693
694 INTEGER :: handle, i_t
695 TYPE(cp_blacs_env_type), POINTER :: blacs_env, blacs_env_tensor
696 TYPE(cp_fm_struct_type), POINTER :: fm_struct, fm_struct_ri_global
697 TYPE(mp_para_env_type), POINTER :: para_env
698
699 CALL timeset(routinen, handle)
700
701 CALL get_qs_env(qs_env, para_env=para_env, blacs_env=blacs_env)
702
703 fm_struct => bs_env%fm_ks_Gamma(1)%matrix_struct
704
705 CALL cp_fm_create(bs_env%fm_Gocc, fm_struct)
706 CALL cp_fm_create(bs_env%fm_Gvir, fm_struct)
707
708 NULLIFY (fm_struct_ri_global)
709 CALL cp_fm_struct_create(fm_struct_ri_global, context=blacs_env, nrow_global=bs_env%n_RI, &
710 ncol_global=bs_env%n_RI, para_env=para_env)
711 CALL cp_fm_create(bs_env%fm_RI_RI, fm_struct_ri_global)
712 CALL cp_fm_create(bs_env%fm_chi_Gamma_freq, fm_struct_ri_global)
713 CALL cp_fm_create(bs_env%fm_W_MIC_freq, fm_struct_ri_global)
714 IF (bs_env%approx_kp_extrapol) THEN
715 CALL cp_fm_create(bs_env%fm_W_MIC_freq_1_extra, fm_struct_ri_global)
716 CALL cp_fm_create(bs_env%fm_W_MIC_freq_1_no_extra, fm_struct_ri_global)
717 CALL cp_fm_set_all(bs_env%fm_W_MIC_freq_1_extra, 0.0_dp)
718 CALL cp_fm_set_all(bs_env%fm_W_MIC_freq_1_no_extra, 0.0_dp)
719 END IF
720 CALL cp_fm_struct_release(fm_struct_ri_global)
721
722 ! create blacs_env for subgroups of tensor operations
723 NULLIFY (blacs_env_tensor)
724 CALL cp_blacs_env_create(blacs_env=blacs_env_tensor, para_env=bs_env%para_env_tensor)
725
726 ! allocate dbcsr matrices in the tensor subgroup; actually, one only needs a small
727 ! subset of blocks in the tensor subgroup, however, all atomic blocks are allocated.
728 ! One might think of creating a dbcsr matrix with only the blocks that are needed
729 ! in the tensor subgroup
730 CALL create_mat_munu(bs_env%mat_ao_ao_tensor, qs_env, bs_env%eps_atom_grid_2d_mat, &
731 blacs_env_tensor, do_ri_aux_basis=.false.)
732
733 CALL create_mat_munu(bs_env%mat_RI_RI_tensor, qs_env, bs_env%eps_atom_grid_2d_mat, &
734 blacs_env_tensor, do_ri_aux_basis=.true.)
735
736 CALL create_mat_munu(bs_env%mat_RI_RI, qs_env, bs_env%eps_atom_grid_2d_mat, &
737 blacs_env, do_ri_aux_basis=.true.)
738
739 CALL cp_blacs_env_release(blacs_env_tensor)
740
741 NULLIFY (bs_env%mat_chi_Gamma_tau)
742 CALL dbcsr_allocate_matrix_set(bs_env%mat_chi_Gamma_tau, bs_env%num_time_freq_points)
743
744 DO i_t = 1, bs_env%num_time_freq_points
745 ALLOCATE (bs_env%mat_chi_Gamma_tau(i_t)%matrix)
746 CALL dbcsr_create(bs_env%mat_chi_Gamma_tau(i_t)%matrix, template=bs_env%mat_RI_RI%matrix)
747 END DO
748
749 CALL timestop(handle)
750
751 END SUBROUTINE allocate_matrices
752
753! **************************************************************************************************
754!> \brief ...
755!> \param bs_env ...
756! **************************************************************************************************
757 SUBROUTINE allocate_gw_eigenvalues(bs_env)
758 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
759
760 CHARACTER(LEN=*), PARAMETER :: routinen = 'allocate_GW_eigenvalues'
761
762 INTEGER :: handle
763
764 CALL timeset(routinen, handle)
765
766 ALLOCATE (bs_env%eigenval_G0W0(bs_env%n_ao, bs_env%nkp_bs_and_DOS, bs_env%n_spin))
767 ALLOCATE (bs_env%eigenval_HF(bs_env%n_ao, bs_env%nkp_bs_and_DOS, bs_env%n_spin))
768
769 CALL timestop(handle)
770
771 END SUBROUTINE allocate_gw_eigenvalues
772
773! **************************************************************************************************
774!> \brief ...
775!> \param qs_env ...
776!> \param bs_env ...
777! **************************************************************************************************
778 SUBROUTINE create_tensors(qs_env, bs_env)
779 TYPE(qs_environment_type), POINTER :: qs_env
780 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
781
782 CHARACTER(LEN=*), PARAMETER :: routinen = 'create_tensors'
783
784 INTEGER :: handle
785
786 CALL timeset(routinen, handle)
787
788 CALL init_interaction_radii(bs_env)
789
790 ! split blocks does not improve load balancing/efficienfy for tensor contraction, so we go
791 ! with the standard atomic blocks
792 CALL create_3c_t(bs_env%t_RI_AO__AO, bs_env%para_env_tensor, "(RI AO | AO)", [1, 2], [3], &
793 bs_env%sizes_RI, bs_env%sizes_AO, &
794 create_nl_3c=.true., nl_3c=bs_env%nl_3c, qs_env=qs_env)
795 CALL create_3c_t(bs_env%t_RI__AO_AO, bs_env%para_env_tensor, "(RI | AO AO)", [1], [2, 3], &
796 bs_env%sizes_RI, bs_env%sizes_AO)
797
798 CALL create_2c_t(bs_env, bs_env%sizes_RI, bs_env%sizes_AO)
799
800 CALL timestop(handle)
801
802 END SUBROUTINE create_tensors
803
804! **************************************************************************************************
805!> \brief ...
806!> \param qs_env ...
807!> \param bs_env ...
808! **************************************************************************************************
809 SUBROUTINE check_sparsity_3c(qs_env, bs_env)
810 TYPE(qs_environment_type), POINTER :: qs_env
811 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
812
813 CHARACTER(LEN=*), PARAMETER :: routinen = 'check_sparsity_3c'
814
815 INTEGER :: handle, n_atom_step, ri_atom
816 INTEGER(int_8) :: mem, non_zero_elements_sum, nze
817 REAL(dp) :: max_dist_ao_atoms, occ, occupation_sum
818 REAL(kind=dp) :: t1, t2
819 TYPE(dbt_type) :: t_3c_global
820 TYPE(dbt_type), ALLOCATABLE, DIMENSION(:, :) :: t_3c_global_array
821 TYPE(neighbor_list_3c_type) :: nl_3c_global
822
823 CALL timeset(routinen, handle)
824
825 ! check the sparsity of 3c integral tensor (µν|P); calculate maximum distance between
826 ! AO atoms µ, ν where at least a single integral (µν|P) is larger than the filter threshold
827 CALL create_3c_t(t_3c_global, bs_env%para_env, "(RI AO | AO)", [1, 2], [3], &
828 bs_env%sizes_RI, bs_env%sizes_AO, &
829 create_nl_3c=.true., nl_3c=nl_3c_global, qs_env=qs_env)
830
831 CALL m_memory(mem)
832 CALL bs_env%para_env%max(mem)
833
834 ALLOCATE (t_3c_global_array(1, 1))
835 CALL dbt_create(t_3c_global, t_3c_global_array(1, 1))
836
837 CALL bs_env%para_env%sync()
838 t1 = m_walltime()
839
840 occupation_sum = 0.0_dp
841 non_zero_elements_sum = 0
842 max_dist_ao_atoms = 0.0_dp
843 n_atom_step = int(sqrt(real(bs_env%n_atom, kind=dp)))
844 ! do not compute full 3c integrals at once because it may cause out of memory
845 DO ri_atom = 1, bs_env%n_atom, n_atom_step
846
847 CALL build_3c_integrals(t_3c_global_array, &
848 bs_env%eps_filter, &
849 qs_env, &
850 nl_3c_global, &
851 int_eps=bs_env%eps_filter, &
852 basis_i=bs_env%basis_set_RI, &
853 basis_j=bs_env%basis_set_AO, &
854 basis_k=bs_env%basis_set_AO, &
855 bounds_i=[ri_atom, min(ri_atom + n_atom_step - 1, bs_env%n_atom)], &
856 potential_parameter=bs_env%ri_metric, &
857 desymmetrize=.false.)
858
859 CALL dbt_filter(t_3c_global_array(1, 1), bs_env%eps_filter)
860
861 CALL bs_env%para_env%sync()
862
863 CALL get_tensor_occupancy(t_3c_global_array(1, 1), nze, occ)
864 non_zero_elements_sum = non_zero_elements_sum + nze
865 occupation_sum = occupation_sum + occ
866
867 CALL get_max_dist_ao_atoms(t_3c_global_array(1, 1), max_dist_ao_atoms, qs_env)
868
869 CALL dbt_clear(t_3c_global_array(1, 1))
870
871 END DO
872
873 t2 = m_walltime()
874
875 bs_env%occupation_3c_int = occupation_sum
876 bs_env%max_dist_AO_atoms = max_dist_ao_atoms
877
878 CALL dbt_destroy(t_3c_global)
879 CALL dbt_destroy(t_3c_global_array(1, 1))
880 DEALLOCATE (t_3c_global_array)
881
882 CALL neighbor_list_3c_destroy(nl_3c_global)
883
884 IF (bs_env%unit_nr > 0) THEN
885 WRITE (bs_env%unit_nr, '(T2,A)') ''
886 WRITE (bs_env%unit_nr, '(T2,A,F27.1,A)') &
887 µν'Computed 3-center integrals (|P), execution time', t2 - t1, ' s'
888 WRITE (bs_env%unit_nr, '(T2,A,F48.3,A)') µν'Percentage of non-zero (|P)', &
889 occupation_sum*100, ' %'
890 WRITE (bs_env%unit_nr, '(T2,A,F33.1,A)') µνµν'Max. distance between , in non-zero (|P)', &
891 max_dist_ao_atoms*angstrom, ' A'
892 WRITE (bs_env%unit_nr, '(T2,2A,I20,A)') 'Required memory if storing all 3-center ', &
893 µν'integrals (|P)', int(real(non_zero_elements_sum, kind=dp)*8.0e-9_dp), ' GB'
894 END IF
895
896 CALL timestop(handle)
897
898 END SUBROUTINE check_sparsity_3c
899
900! **************************************************************************************************
901!> \brief ...
902!> \param bs_env ...
903!> \param sizes_RI ...
904!> \param sizes_AO ...
905! **************************************************************************************************
906 SUBROUTINE create_2c_t(bs_env, sizes_RI, sizes_AO)
907 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
908 INTEGER, ALLOCATABLE, DIMENSION(:) :: sizes_ri, sizes_ao
909
910 CHARACTER(LEN=*), PARAMETER :: routinen = 'create_2c_t'
911
912 INTEGER :: handle
913 INTEGER, ALLOCATABLE, DIMENSION(:) :: dist_1, dist_2
914 INTEGER, DIMENSION(2) :: pdims_2d
915 TYPE(dbt_pgrid_type) :: pgrid_2d
916
917 CALL timeset(routinen, handle)
918
919 ! inspired from rpa_im_time.F / hfx_types.F
920
921 pdims_2d = 0
922 CALL dbt_pgrid_create(bs_env%para_env_tensor, pdims_2d, pgrid_2d)
923
924 CALL create_2c_tensor(bs_env%t_G, dist_1, dist_2, pgrid_2d, sizes_ao, sizes_ao, &
925 name="(AO | AO)")
926 DEALLOCATE (dist_1, dist_2)
927 CALL create_2c_tensor(bs_env%t_chi, dist_1, dist_2, pgrid_2d, sizes_ri, sizes_ri, &
928 name="(RI | RI)")
929 DEALLOCATE (dist_1, dist_2)
930 CALL create_2c_tensor(bs_env%t_W, dist_1, dist_2, pgrid_2d, sizes_ri, sizes_ri, &
931 name="(RI | RI)")
932 DEALLOCATE (dist_1, dist_2)
933 CALL dbt_pgrid_destroy(pgrid_2d)
934
935 CALL timestop(handle)
936
937 END SUBROUTINE create_2c_t
938
939! **************************************************************************************************
940!> \brief ...
941!> \param tensor ...
942!> \param para_env ...
943!> \param tensor_name ...
944!> \param map1 ...
945!> \param map2 ...
946!> \param sizes_RI ...
947!> \param sizes_AO ...
948!> \param create_nl_3c ...
949!> \param nl_3c ...
950!> \param qs_env ...
951! **************************************************************************************************
952 SUBROUTINE create_3c_t(tensor, para_env, tensor_name, map1, map2, sizes_RI, sizes_AO, &
953 create_nl_3c, nl_3c, qs_env)
954 TYPE(dbt_type) :: tensor
955 TYPE(mp_para_env_type), POINTER :: para_env
956 CHARACTER(LEN=12) :: tensor_name
957 INTEGER, DIMENSION(:) :: map1, map2
958 INTEGER, ALLOCATABLE, DIMENSION(:) :: sizes_ri, sizes_ao
959 LOGICAL, OPTIONAL :: create_nl_3c
960 TYPE(neighbor_list_3c_type), OPTIONAL :: nl_3c
961 TYPE(qs_environment_type), OPTIONAL, POINTER :: qs_env
962
963 CHARACTER(LEN=*), PARAMETER :: routinen = 'create_3c_t'
964
965 INTEGER :: handle, nkind
966 INTEGER, ALLOCATABLE, DIMENSION(:) :: dist_ao_1, dist_ao_2, dist_ri
967 INTEGER, DIMENSION(3) :: pcoord, pdims, pdims_3d
968 LOGICAL :: my_create_nl_3c
969 TYPE(dbt_pgrid_type) :: pgrid_3d
970 TYPE(distribution_3d_type) :: dist_3d
971 TYPE(mp_cart_type) :: mp_comm_t3c_2
972 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
973
974 CALL timeset(routinen, handle)
975
976 pdims_3d = 0
977 CALL dbt_pgrid_create(para_env, pdims_3d, pgrid_3d)
978 CALL create_3c_tensor(tensor, dist_ri, dist_ao_1, dist_ao_2, &
979 pgrid_3d, sizes_ri, sizes_ao, sizes_ao, &
980 map1=map1, map2=map2, name=tensor_name)
981
982 IF (PRESENT(create_nl_3c)) THEN
983 my_create_nl_3c = create_nl_3c
984 ELSE
985 my_create_nl_3c = .false.
986 END IF
987
988 IF (my_create_nl_3c) THEN
989 CALL get_qs_env(qs_env, nkind=nkind, particle_set=particle_set)
990 CALL dbt_mp_environ_pgrid(pgrid_3d, pdims, pcoord)
991 CALL mp_comm_t3c_2%create(pgrid_3d%mp_comm_2d, 3, pdims)
992 CALL distribution_3d_create(dist_3d, dist_ri, dist_ao_1, dist_ao_2, &
993 nkind, particle_set, mp_comm_t3c_2, own_comm=.true.)
994
995 CALL build_3c_neighbor_lists(nl_3c, &
996 qs_env%bs_env%basis_set_RI, &
997 qs_env%bs_env%basis_set_AO, &
998 qs_env%bs_env%basis_set_AO, &
999 dist_3d, qs_env%bs_env%ri_metric, &
1000 "GW_3c_nl", qs_env, own_dist=.true.)
1001 END IF
1002
1003 DEALLOCATE (dist_ri, dist_ao_1, dist_ao_2)
1004 CALL dbt_pgrid_destroy(pgrid_3d)
1005
1006 CALL timestop(handle)
1007
1008 END SUBROUTINE create_3c_t
1009
1010! **************************************************************************************************
1011!> \brief ...
1012!> \param bs_env ...
1013! **************************************************************************************************
1014 SUBROUTINE init_interaction_radii(bs_env)
1015 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
1016
1017 CHARACTER(LEN=*), PARAMETER :: routinen = 'init_interaction_radii'
1018
1019 INTEGER :: handle, ibasis
1020 TYPE(gto_basis_set_type), POINTER :: orb_basis, ri_basis
1021
1022 CALL timeset(routinen, handle)
1023
1024 DO ibasis = 1, SIZE(bs_env%basis_set_AO)
1025
1026 orb_basis => bs_env%basis_set_AO(ibasis)%gto_basis_set
1027 CALL init_interaction_radii_orb_basis(orb_basis, bs_env%eps_filter)
1028
1029 ri_basis => bs_env%basis_set_RI(ibasis)%gto_basis_set
1030 CALL init_interaction_radii_orb_basis(ri_basis, bs_env%eps_filter)
1031
1032 END DO
1033
1034 CALL timestop(handle)
1035
1036 END SUBROUTINE init_interaction_radii
1037
1038! **************************************************************************************************
1039!> \brief ...
1040!> \param t_3c_int ...
1041!> \param max_dist_AO_atoms ...
1042!> \param qs_env ...
1043! **************************************************************************************************
1044 SUBROUTINE get_max_dist_ao_atoms(t_3c_int, max_dist_AO_atoms, qs_env)
1045 TYPE(dbt_type) :: t_3c_int
1046 REAL(kind=dp) :: max_dist_ao_atoms
1047 TYPE(qs_environment_type), POINTER :: qs_env
1048
1049 CHARACTER(LEN=*), PARAMETER :: routinen = 'get_max_dist_AO_atoms'
1050
1051 INTEGER :: atom_1, atom_2, handle, num_cells
1052 INTEGER, DIMENSION(3) :: atom_ind
1053 INTEGER, DIMENSION(:, :), POINTER :: index_to_cell
1054 REAL(kind=dp) :: abs_rab
1055 REAL(kind=dp), DIMENSION(3) :: rab
1056 TYPE(cell_type), POINTER :: cell
1057 TYPE(dbt_iterator_type) :: iter
1058 TYPE(mp_para_env_type), POINTER :: para_env
1059 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
1060
1061 CALL timeset(routinen, handle)
1062
1063 NULLIFY (cell, particle_set, para_env)
1064 CALL get_qs_env(qs_env, cell=cell, particle_set=particle_set, para_env=para_env)
1065
1066!$OMP PARALLEL DEFAULT(NONE) &
1067!$OMP SHARED(t_3c_int, max_dist_AO_atoms, num_cells, index_to_cell, particle_set, cell) &
1068!$OMP PRIVATE(iter,atom_ind,rab, abs_rab, atom_1, atom_2)
1069 CALL dbt_iterator_start(iter, t_3c_int)
1070 DO WHILE (dbt_iterator_blocks_left(iter))
1071 CALL dbt_iterator_next_block(iter, atom_ind)
1072
1073 atom_1 = atom_ind(2)
1074 atom_2 = atom_ind(3)
1075
1076 rab = pbc(particle_set(atom_1)%r(1:3), particle_set(atom_2)%r(1:3), cell)
1077
1078 abs_rab = sqrt(rab(1)**2 + rab(2)**2 + rab(3)**2)
1079
1080 max_dist_ao_atoms = max(max_dist_ao_atoms, abs_rab)
1081
1082 END DO
1083 CALL dbt_iterator_stop(iter)
1084!$OMP END PARALLEL
1085
1086 CALL para_env%max(max_dist_ao_atoms)
1087
1088 CALL timestop(handle)
1089
1090 END SUBROUTINE get_max_dist_ao_atoms
1091
1092! **************************************************************************************************
1093!> \brief ...
1094!> \param bs_env ...
1095! **************************************************************************************************
1096 SUBROUTINE set_sparsity_parallelization_parameters(bs_env)
1097 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
1098
1099 CHARACTER(LEN=*), PARAMETER :: routinen = 'set_sparsity_parallelization_parameters'
1100
1101 INTEGER :: handle, i_ivl, il_ivl, j_ivl, n_atom_per_il_ivl, n_atom_per_ivl, n_intervals_i, &
1102 n_intervals_inner_loop_atoms, n_intervals_j, u
1103 INTEGER(KIND=int_8) :: input_memory_per_proc
1104
1105 CALL timeset(routinen, handle)
1106
1107 ! heuristic parameter to prevent out of memory
1108 bs_env%safety_factor_memory = 0.10_dp
1109
1110 input_memory_per_proc = int(bs_env%input_memory_per_proc_GB*1.0e9_dp, kind=int_8)
1111
1112 ! choose atomic range for λ ("i_atom"), ν ("j_atom") in
1113 ! M_λνP(iτ) = sum_µ (µν|P) G^occ_µλ(i|τ|,k=0)
1114 ! N_νλQ(iτ) = sum_σ (σλ|Q) G^vir_σν(i|τ|,k=0)
1115 ! such that M and N fit into the memory
1116 n_atom_per_ivl = int(sqrt(bs_env%safety_factor_memory*input_memory_per_proc &
1117 *bs_env%group_size_tensor/24/bs_env%n_RI &
1118 /sqrt(bs_env%occupation_3c_int)))/bs_env%max_AO_bf_per_atom
1119
1120 n_intervals_i = (bs_env%n_atom_i - 1)/n_atom_per_ivl + 1
1121 n_intervals_j = (bs_env%n_atom_j - 1)/n_atom_per_ivl + 1
1122
1123 bs_env%n_atom_per_interval_ij = n_atom_per_ivl
1124 bs_env%n_intervals_i = n_intervals_i
1125 bs_env%n_intervals_j = n_intervals_j
1126
1127 ALLOCATE (bs_env%i_atom_intervals(2, n_intervals_i))
1128 ALLOCATE (bs_env%j_atom_intervals(2, n_intervals_j))
1129
1130 DO i_ivl = 1, n_intervals_i
1131 bs_env%i_atom_intervals(1, i_ivl) = (i_ivl - 1)*n_atom_per_ivl + bs_env%atoms_i(1)
1132 bs_env%i_atom_intervals(2, i_ivl) = min(i_ivl*n_atom_per_ivl + bs_env%atoms_i(1) - 1, &
1133 bs_env%atoms_i(2))
1134 END DO
1135
1136 DO j_ivl = 1, n_intervals_j
1137 bs_env%j_atom_intervals(1, j_ivl) = (j_ivl - 1)*n_atom_per_ivl + bs_env%atoms_j(1)
1138 bs_env%j_atom_intervals(2, j_ivl) = min(j_ivl*n_atom_per_ivl + bs_env%atoms_j(1) - 1, &
1139 bs_env%atoms_j(2))
1140 END DO
1141
1142 ALLOCATE (bs_env%skip_Sigma_occ(n_intervals_i, n_intervals_j))
1143 ALLOCATE (bs_env%skip_Sigma_vir(n_intervals_i, n_intervals_j))
1144 bs_env%skip_Sigma_occ(:, :) = .false.
1145 bs_env%skip_Sigma_vir(:, :) = .false.
1146
1147 ! choose atomic range for µ and σ ("inner loop (IL) atom") in
1148 ! M_λνP(iτ) = sum_µ (µν|P) G^occ_µλ(i|τ|,k=0)
1149 ! N_νλQ(iτ) = sum_σ (σλ|Q) G^vir_σν(i|τ|,k=0)
1150 n_atom_per_il_ivl = min(int(bs_env%safety_factor_memory*input_memory_per_proc &
1151 *bs_env%group_size_tensor/n_atom_per_ivl &
1152 /bs_env%max_AO_bf_per_atom &
1153 /bs_env%n_RI/8/sqrt(bs_env%occupation_3c_int) &
1154 /bs_env%max_AO_bf_per_atom), bs_env%n_atom)
1155
1156 n_intervals_inner_loop_atoms = (bs_env%n_atom - 1)/n_atom_per_il_ivl + 1
1157
1158 bs_env%n_atom_per_IL_interval = n_atom_per_il_ivl
1159 bs_env%n_intervals_inner_loop_atoms = n_intervals_inner_loop_atoms
1160
1161 ALLOCATE (bs_env%inner_loop_atom_intervals(2, n_intervals_inner_loop_atoms))
1162 DO il_ivl = 1, n_intervals_inner_loop_atoms
1163 bs_env%inner_loop_atom_intervals(1, il_ivl) = (il_ivl - 1)*n_atom_per_il_ivl + 1
1164 bs_env%inner_loop_atom_intervals(2, il_ivl) = min(il_ivl*n_atom_per_il_ivl, bs_env%n_atom)
1165 END DO
1166
1167 u = bs_env%unit_nr
1168 IF (u > 0) THEN
1169 WRITE (u, '(T2,A)') ''
1170 WRITE (u, '(T2,A,I33)') λντνλτ'Number of i and j atoms in M_P(), N_Q():', n_atom_per_ivl
1171 WRITE (u, '(T2,A,I18)') µλνµµνµλ'Number of inner loop atoms for in M_P = sum_ (|P) G_', &
1172 n_atom_per_il_ivl
1173 END IF
1174
1175 CALL timestop(handle)
1176
1177 END SUBROUTINE set_sparsity_parallelization_parameters
1178
1179! **************************************************************************************************
1180!> \brief ...
1181!> \param qs_env ...
1182!> \param bs_env ...
1183! **************************************************************************************************
1184 SUBROUTINE check_for_restart_files(qs_env, bs_env)
1185 TYPE(qs_environment_type), POINTER :: qs_env
1186 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
1187
1188 CHARACTER(LEN=*), PARAMETER :: routinen = 'check_for_restart_files'
1189
1190 CHARACTER(LEN=9) :: frmt
1191 CHARACTER(LEN=default_string_length) :: f_chi, f_s_n, f_s_p, f_s_x, f_w_t, &
1192 prefix, project_name
1193 INTEGER :: handle, i_spin, i_t_or_w, ind, n_spin, &
1194 num_time_freq_points
1195 LOGICAL :: chi_exists, sigma_neg_time_exists, &
1196 sigma_pos_time_exists, &
1197 sigma_x_spin_exists, w_time_exists
1198 TYPE(cp_logger_type), POINTER :: logger
1199 TYPE(section_vals_type), POINTER :: input, print_key
1200
1201 CALL timeset(routinen, handle)
1202
1203 num_time_freq_points = bs_env%num_time_freq_points
1204 n_spin = bs_env%n_spin
1205
1206 ALLOCATE (bs_env%read_chi(num_time_freq_points))
1207 ALLOCATE (bs_env%calc_chi(num_time_freq_points))
1208 ALLOCATE (bs_env%Sigma_c_exists(num_time_freq_points, n_spin))
1209
1210 CALL get_qs_env(qs_env, input=input)
1211
1212 logger => cp_get_default_logger()
1213 print_key => section_vals_get_subs_vals(input, 'PROPERTIES%BANDSTRUCTURE%GW%PRINT%RESTART')
1214 project_name = cp_print_key_generate_filename(logger, print_key, extension="", &
1215 my_local=.false.)
1216 WRITE (prefix, '(2A)') trim(project_name), "-RESTART_"
1217 bs_env%prefix = prefix
1218
1219 bs_env%all_W_exist = .true.
1220
1221 DO i_t_or_w = 1, num_time_freq_points
1222
1223 IF (i_t_or_w < 10) THEN
1224 WRITE (frmt, '(A)') '(3A,I1,A)'
1225 WRITE (f_chi, frmt) trim(prefix), bs_env%chi_name, "_0", i_t_or_w, ".matrix"
1226 WRITE (f_w_t, frmt) trim(prefix), bs_env%W_time_name, "_0", i_t_or_w, ".matrix"
1227 ELSE IF (i_t_or_w < 100) THEN
1228 WRITE (frmt, '(A)') '(3A,I2,A)'
1229 WRITE (f_chi, frmt) trim(prefix), bs_env%chi_name, "_", i_t_or_w, ".matrix"
1230 WRITE (f_w_t, frmt) trim(prefix), bs_env%W_time_name, "_", i_t_or_w, ".matrix"
1231 ELSE
1232 cpabort('Please implement more than 99 time/frequency points.')
1233 END IF
1234
1235 INQUIRE (file=trim(f_chi), exist=chi_exists)
1236 INQUIRE (file=trim(f_w_t), exist=w_time_exists)
1237
1238 bs_env%read_chi(i_t_or_w) = chi_exists
1239 bs_env%calc_chi(i_t_or_w) = .NOT. chi_exists
1240
1241 bs_env%all_W_exist = bs_env%all_W_exist .AND. w_time_exists
1242
1243 ! the self-energy is spin-dependent
1244 DO i_spin = 1, n_spin
1245
1246 ind = i_t_or_w + (i_spin - 1)*num_time_freq_points
1247
1248 IF (ind < 10) THEN
1249 WRITE (frmt, '(A)') '(3A,I1,A)'
1250 WRITE (f_s_p, frmt) trim(prefix), bs_env%Sigma_p_name, "_0", ind, ".matrix"
1251 WRITE (f_s_n, frmt) trim(prefix), bs_env%Sigma_n_name, "_0", ind, ".matrix"
1252 ELSE IF (i_t_or_w < 100) THEN
1253 WRITE (frmt, '(A)') '(3A,I2,A)'
1254 WRITE (f_s_p, frmt) trim(prefix), bs_env%Sigma_p_name, "_", ind, ".matrix"
1255 WRITE (f_s_n, frmt) trim(prefix), bs_env%Sigma_n_name, "_", ind, ".matrix"
1256 END IF
1257
1258 INQUIRE (file=trim(f_s_p), exist=sigma_pos_time_exists)
1259 INQUIRE (file=trim(f_s_n), exist=sigma_neg_time_exists)
1260
1261 bs_env%Sigma_c_exists(i_t_or_w, i_spin) = sigma_pos_time_exists .AND. &
1262 sigma_neg_time_exists
1263
1264 END DO
1265
1266 END DO
1267
1268 ! Marek : In the RTBSE run, check also for zero frequency W
1269 IF (bs_env%rtp_method == rtp_method_bse) THEN
1270 WRITE (f_w_t, '(3A,I1,A)') trim(prefix), "W_freq_rtp", "_0", 0, ".matrix"
1271 INQUIRE (file=trim(f_w_t), exist=w_time_exists)
1272 bs_env%all_W_exist = bs_env%all_W_exist .AND. w_time_exists
1273 END IF
1274
1275 IF (bs_env%all_W_exist) THEN
1276 bs_env%read_chi(:) = .false.
1277 bs_env%calc_chi(:) = .false.
1278 END IF
1279
1280 bs_env%Sigma_x_exists = .true.
1281 DO i_spin = 1, n_spin
1282 WRITE (f_s_x, '(3A,I1,A)') trim(prefix), bs_env%Sigma_x_name, "_0", i_spin, ".matrix"
1283 INQUIRE (file=trim(f_s_x), exist=sigma_x_spin_exists)
1284 bs_env%Sigma_x_exists = bs_env%Sigma_x_exists .AND. sigma_x_spin_exists
1285 END DO
1286
1287 CALL timestop(handle)
1288
1289 END SUBROUTINE check_for_restart_files
1290
1291! **************************************************************************************************
1292!> \brief ...
1293!> \param qs_env ...
1294!> \param bs_env ...
1295! **************************************************************************************************
1296 SUBROUTINE set_parallelization_parameters(qs_env, bs_env)
1297 TYPE(qs_environment_type), POINTER :: qs_env
1298 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
1299
1300 CHARACTER(LEN=*), PARAMETER :: routinen = 'set_parallelization_parameters'
1301
1302 INTEGER :: color_sub, dummy_1, dummy_2, handle, &
1303 num_pe, num_t_groups, u
1304 INTEGER(KIND=int_8) :: mem
1305 TYPE(mp_para_env_type), POINTER :: para_env
1306
1307 CALL timeset(routinen, handle)
1308
1309 CALL get_qs_env(qs_env, para_env=para_env)
1310
1311 num_pe = para_env%num_pe
1312 ! if not already set, use all processors for the group (for large-cell GW, performance
1313 ! seems to be best for a single group with all MPI processes per group)
1314 IF (bs_env%group_size_tensor < 0 .OR. bs_env%group_size_tensor > num_pe) &
1315 bs_env%group_size_tensor = num_pe
1316
1317 ! group_size_tensor must divide num_pe without rest; otherwise everything will be complicated
1318 IF (modulo(num_pe, bs_env%group_size_tensor) .NE. 0) THEN
1319 CALL find_good_group_size(num_pe, bs_env%group_size_tensor)
1320 END IF
1321
1322 ! para_env_tensor for tensor subgroups
1323 color_sub = para_env%mepos/bs_env%group_size_tensor
1324 bs_env%tensor_group_color = color_sub
1325
1326 ALLOCATE (bs_env%para_env_tensor)
1327 CALL bs_env%para_env_tensor%from_split(para_env, color_sub)
1328
1329 num_t_groups = para_env%num_pe/bs_env%group_size_tensor
1330 bs_env%num_tensor_groups = num_t_groups
1331
1332 CALL get_i_j_atoms(bs_env%atoms_i, bs_env%atoms_j, bs_env%n_atom_i, bs_env%n_atom_j, &
1333 color_sub, bs_env)
1334
1335 ALLOCATE (bs_env%atoms_i_t_group(2, num_t_groups))
1336 ALLOCATE (bs_env%atoms_j_t_group(2, num_t_groups))
1337 DO color_sub = 0, num_t_groups - 1
1338 CALL get_i_j_atoms(bs_env%atoms_i_t_group(1:2, color_sub + 1), &
1339 bs_env%atoms_j_t_group(1:2, color_sub + 1), &
1340 dummy_1, dummy_2, color_sub, bs_env)
1341 END DO
1342
1343 CALL m_memory(mem)
1344 CALL bs_env%para_env%max(mem)
1345
1346 u = bs_env%unit_nr
1347 IF (u > 0) THEN
1348 WRITE (u, '(T2,A,I47)') 'Group size for tensor operations', bs_env%group_size_tensor
1349 IF (bs_env%group_size_tensor > 1 .AND. bs_env%n_atom < 5) THEN
1350 WRITE (u, '(T2,A)') 'The requested group size is > 1 which can lead to bad performance.'
1351 WRITE (u, '(T2,A)') 'Using more memory per MPI process might improve performance.'
1352 WRITE (u, '(T2,A)') '(Also increase MEMORY_PER_PROC when using more memory per process.)'
1353 END IF
1354 END IF
1355
1356 CALL timestop(handle)
1357
1358 END SUBROUTINE set_parallelization_parameters
1359
1360! **************************************************************************************************
1361!> \brief ...
1362!> \param num_pe ...
1363!> \param group_size ...
1364! **************************************************************************************************
1365 SUBROUTINE find_good_group_size(num_pe, group_size)
1366
1367 INTEGER :: num_pe, group_size
1368
1369 CHARACTER(LEN=*), PARAMETER :: routinen = 'find_good_group_size'
1370
1371 INTEGER :: group_size_minus, group_size_orig, &
1372 group_size_plus, handle, i_diff
1373
1374 CALL timeset(routinen, handle)
1375
1376 group_size_orig = group_size
1377
1378 DO i_diff = 1, num_pe
1379
1380 group_size_minus = group_size - i_diff
1381
1382 IF (modulo(num_pe, group_size_minus) == 0 .AND. group_size_minus > 0) THEN
1383 group_size = group_size_minus
1384 EXIT
1385 END IF
1386
1387 group_size_plus = group_size + i_diff
1388
1389 IF (modulo(num_pe, group_size_plus) == 0 .AND. group_size_plus <= num_pe) THEN
1390 group_size = group_size_plus
1391 EXIT
1392 END IF
1393
1394 END DO
1395
1396 IF (group_size_orig == group_size) cpabort("Group size error")
1397
1398 CALL timestop(handle)
1399
1400 END SUBROUTINE find_good_group_size
1401
1402! **************************************************************************************************
1403!> \brief ...
1404!> \param atoms_i ...
1405!> \param atoms_j ...
1406!> \param n_atom_i ...
1407!> \param n_atom_j ...
1408!> \param color_sub ...
1409!> \param bs_env ...
1410! **************************************************************************************************
1411 SUBROUTINE get_i_j_atoms(atoms_i, atoms_j, n_atom_i, n_atom_j, color_sub, bs_env)
1412
1413 INTEGER, DIMENSION(2) :: atoms_i, atoms_j
1414 INTEGER :: n_atom_i, n_atom_j, color_sub
1415 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
1416
1417 CHARACTER(LEN=*), PARAMETER :: routinen = 'get_i_j_atoms'
1418
1419 INTEGER :: handle, i_atoms_per_group, i_group, &
1420 ipcol, ipcol_loop, iprow, iprow_loop, &
1421 j_atoms_per_group, npcol, nprow
1422
1423 CALL timeset(routinen, handle)
1424
1425 ! create a square mesh of tensor groups for iatom and jatom; code from blacs_env_create
1426 CALL square_mesh(nprow, npcol, bs_env%num_tensor_groups)
1427
1428 i_group = 0
1429 DO ipcol_loop = 0, npcol - 1
1430 DO iprow_loop = 0, nprow - 1
1431 IF (i_group == color_sub) THEN
1432 iprow = iprow_loop
1433 ipcol = ipcol_loop
1434 END IF
1435 i_group = i_group + 1
1436 END DO
1437 END DO
1438
1439 IF (modulo(bs_env%n_atom, nprow) == 0) THEN
1440 i_atoms_per_group = bs_env%n_atom/nprow
1441 ELSE
1442 i_atoms_per_group = bs_env%n_atom/nprow + 1
1443 END IF
1444
1445 IF (modulo(bs_env%n_atom, npcol) == 0) THEN
1446 j_atoms_per_group = bs_env%n_atom/npcol
1447 ELSE
1448 j_atoms_per_group = bs_env%n_atom/npcol + 1
1449 END IF
1450
1451 atoms_i(1) = iprow*i_atoms_per_group + 1
1452 atoms_i(2) = min((iprow + 1)*i_atoms_per_group, bs_env%n_atom)
1453 n_atom_i = atoms_i(2) - atoms_i(1) + 1
1454
1455 atoms_j(1) = ipcol*j_atoms_per_group + 1
1456 atoms_j(2) = min((ipcol + 1)*j_atoms_per_group, bs_env%n_atom)
1457 n_atom_j = atoms_j(2) - atoms_j(1) + 1
1458
1459 CALL timestop(handle)
1460
1461 END SUBROUTINE get_i_j_atoms
1462
1463! **************************************************************************************************
1464!> \brief ...
1465!> \param nprow ...
1466!> \param npcol ...
1467!> \param nproc ...
1468! **************************************************************************************************
1469 SUBROUTINE square_mesh(nprow, npcol, nproc)
1470 INTEGER :: nprow, npcol, nproc
1471
1472 CHARACTER(LEN=*), PARAMETER :: routinen = 'square_mesh'
1473
1474 INTEGER :: gcd_max, handle, ipe, jpe
1475
1476 CALL timeset(routinen, handle)
1477
1478 gcd_max = -1
1479 DO ipe = 1, ceiling(sqrt(real(nproc, dp)))
1480 jpe = nproc/ipe
1481 IF (ipe*jpe .NE. nproc) cycle
1482 IF (gcd(ipe, jpe) >= gcd_max) THEN
1483 nprow = ipe
1484 npcol = jpe
1485 gcd_max = gcd(ipe, jpe)
1486 END IF
1487 END DO
1488
1489 CALL timestop(handle)
1490
1491 END SUBROUTINE square_mesh
1492
1493! **************************************************************************************************
1494!> \brief ...
1495!> \param bs_env ...
1496!> \param qs_env ...
1497! **************************************************************************************************
1498 SUBROUTINE set_heuristic_parameters(bs_env, qs_env)
1499 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
1500 TYPE(qs_environment_type), OPTIONAL, POINTER :: qs_env
1501
1502 CHARACTER(LEN=*), PARAMETER :: routinen = 'set_heuristic_parameters'
1503
1504 INTEGER :: handle, u
1505 LOGICAL :: do_bvk_cell
1506
1507 CALL timeset(routinen, handle)
1508
1509 ! for generating numerically stable minimax Fourier integration weights
1510 bs_env%num_points_per_magnitude = 200
1511
1512 ! for periodic systems and for 20 minimax points, we use a regularized minimax mesh
1513 ! (from experience: regularized minimax meshes converges faster for periodic systems
1514 ! and for 20 pts)
1515 IF (sum(bs_env%periodic) .NE. 0 .OR. bs_env%num_time_freq_points >= 20) THEN
1516 bs_env%regularization_minimax = 1.0e-6_dp
1517 ELSE
1518 bs_env%regularization_minimax = 0.0_dp
1519 END IF
1520
1521 bs_env%stabilize_exp = 70.0_dp
1522 bs_env%eps_atom_grid_2d_mat = 1.0e-50_dp
1523
1524 ! use a 16-parameter Padé fit
1525 bs_env%nparam_pade = 16
1526
1527 ! resolution of the identity with the truncated Coulomb metric, cutoff radius 3 Angström
1528 bs_env%ri_metric%potential_type = do_potential_truncated
1529 bs_env%ri_metric%omega = 0.0_dp
1530 ! cutoff radius is specified in the input
1531 bs_env%ri_metric%filename = "t_c_g.dat"
1532
1533 bs_env%eps_eigval_mat_RI = 0.0_dp
1534
1535 IF (bs_env%input_regularization_RI > -1.0e-12_dp) THEN
1536 bs_env%regularization_RI = bs_env%input_regularization_RI
1537 ELSE
1538 ! default case:
1539
1540 ! 1. for periodic systems, we use the regularized resolution of the identity per default
1541 bs_env%regularization_RI = 1.0e-2_dp
1542
1543 ! 2. for molecules, no regularization is necessary
1544 IF (sum(bs_env%periodic) == 0) bs_env%regularization_RI = 0.0_dp
1545
1546 END IF
1547
1548 ! truncated Coulomb operator for exchange self-energy
1549 ! (see details in Guidon, VandeVondele, Hutter, JCTC 5, 3010 (2009) and references therein)
1550 do_bvk_cell = bs_env%small_cell_full_kp_or_large_cell_Gamma == small_cell_full_kp
1551 CALL trunc_coulomb_for_exchange(qs_env, bs_env%trunc_coulomb, &
1552 rel_cutoff_trunc_coulomb_ri_x=0.5_dp, &
1553 cell_grid=bs_env%cell_grid_scf_desymm, &
1554 do_bvk_cell=do_bvk_cell)
1555
1556 ! for small-cell GW, we need more cells than normally used by the filter bs_env%eps_filter
1557 ! (in particular for computing the self-energy because of higher number of cells needed)
1558 bs_env%heuristic_filter_factor = 1.0e-4
1559
1560 u = bs_env%unit_nr
1561 IF (u > 0) THEN
1562 WRITE (u, fmt="(T2,2A,F21.1,A)") "Cutoff radius for the truncated Coulomb ", &
1563 Σ"operator in ^x:", bs_env%trunc_coulomb%cutoff_radius*angstrom, Å" "
1564 WRITE (u, fmt="(T2,2A,F15.1,A)") "Cutoff radius for the truncated Coulomb ", &
1565 "operator in RI metric:", bs_env%ri_metric%cutoff_radius*angstrom, Å" "
1566 WRITE (u, fmt="(T2,A,ES48.1)") "Regularization parameter of RI ", bs_env%regularization_RI
1567 WRITE (u, fmt="(T2,A,I53)") "Lattice sum size for V(k):", bs_env%size_lattice_sum_V
1568 END IF
1569
1570 CALL timestop(handle)
1571
1572 END SUBROUTINE set_heuristic_parameters
1573
1574! **************************************************************************************************
1575!> \brief ...
1576!> \param bs_env ...
1577! **************************************************************************************************
1578 SUBROUTINE print_header_and_input_parameters(bs_env)
1579
1580 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
1581
1582 CHARACTER(LEN=*), PARAMETER :: routinen = 'print_header_and_input_parameters'
1583
1584 INTEGER :: handle, u
1585
1586 CALL timeset(routinen, handle)
1587
1588 u = bs_env%unit_nr
1589
1590 IF (u > 0) THEN
1591 WRITE (u, '(T2,A)') ' '
1592 WRITE (u, '(T2,A)') repeat('-', 79)
1593 WRITE (u, '(T2,A,A78)') '-', '-'
1594 WRITE (u, '(T2,A,A46,A32)') '-', 'GW CALCULATION', '-'
1595 WRITE (u, '(T2,A,A78)') '-', '-'
1596 WRITE (u, '(T2,A)') repeat('-', 79)
1597 WRITE (u, '(T2,A)') ' '
1598 WRITE (u, '(T2,A,I45)') 'Input: Number of time/freq. points', bs_env%num_time_freq_points
1599 WRITE (u, "(T2,A,F44.1,A)") ωΣω'Input: _max for fitting (i) (eV)', bs_env%freq_max_fit*evolt
1600 WRITE (u, '(T2,A,ES27.1)') 'Input: Filter threshold for sparse tensor operations', &
1601 bs_env%eps_filter
1602 WRITE (u, "(T2,A,L55)") 'Input: Apply Hedin shift', bs_env%do_hedin_shift
1603 END IF
1604
1605 CALL timestop(handle)
1606
1607 END SUBROUTINE print_header_and_input_parameters
1608
1609! **************************************************************************************************
1610!> \brief ...
1611!> \param qs_env ...
1612!> \param bs_env ...
1613! **************************************************************************************************
1614 SUBROUTINE compute_v_xc(qs_env, bs_env)
1615 TYPE(qs_environment_type), POINTER :: qs_env
1616 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
1617
1618 CHARACTER(LEN=*), PARAMETER :: routinen = 'compute_V_xc'
1619
1620 INTEGER :: handle, img, ispin, myfun, nimages
1621 LOGICAL :: hf_present
1622 REAL(kind=dp) :: energy_ex, energy_exc, energy_total, &
1623 myfraction
1624 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: mat_ks_without_v_xc
1625 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: matrix_ks_kp
1626 TYPE(dft_control_type), POINTER :: dft_control
1627 TYPE(qs_energy_type), POINTER :: energy
1628 TYPE(section_vals_type), POINTER :: hf_section, input, xc_section
1629
1630 CALL timeset(routinen, handle)
1631
1632 CALL get_qs_env(qs_env, input=input, energy=energy, dft_control=dft_control)
1633
1634 ! previously, dft_control%nimages set to # neighbor cells, revert for Γ-only KS matrix
1635 nimages = dft_control%nimages
1636 dft_control%nimages = bs_env%nimages_scf
1637
1638 ! we need to reset XC functional, therefore, get XC input
1639 xc_section => section_vals_get_subs_vals(input, "DFT%XC")
1640 CALL section_vals_val_get(xc_section, "XC_FUNCTIONAL%_SECTION_PARAMETERS_", i_val=myfun)
1641 CALL section_vals_val_set(xc_section, "XC_FUNCTIONAL%_SECTION_PARAMETERS_", i_val=xc_none)
1642 ! IF (ASSOCIATED(section_vals_get_subs_vals(xc_section, "HF", can_return_null=.TRUE.))) THEN
1643 hf_section => section_vals_get_subs_vals(input, "DFT%XC%HF", can_return_null=.true.)
1644 hf_present = .false.
1645 IF (ASSOCIATED(hf_section)) THEN
1646 CALL section_vals_get(hf_section, explicit=hf_present)
1647 END IF
1648 IF (hf_present) THEN
1649 ! Special case for handling hfx
1650 CALL section_vals_val_get(xc_section, "HF%FRACTION", r_val=myfraction)
1651 CALL section_vals_val_set(xc_section, "HF%FRACTION", r_val=0.0_dp)
1652 END IF
1653
1654 ! save the energy before the energy gets updated
1655 energy_total = energy%total
1656 energy_exc = energy%exc
1657 energy_ex = energy%ex
1658
1659 SELECT CASE (bs_env%small_cell_full_kp_or_large_cell_Gamma)
1660 CASE (large_cell_gamma)
1661
1662 NULLIFY (mat_ks_without_v_xc)
1663 CALL dbcsr_allocate_matrix_set(mat_ks_without_v_xc, bs_env%n_spin)
1664
1665 DO ispin = 1, bs_env%n_spin
1666 ALLOCATE (mat_ks_without_v_xc(ispin)%matrix)
1667 IF (hf_present) THEN
1668 CALL dbcsr_create(mat_ks_without_v_xc(ispin)%matrix, template=bs_env%mat_ao_ao%matrix, &
1669 matrix_type=dbcsr_type_symmetric)
1670 ELSE
1671 CALL dbcsr_create(mat_ks_without_v_xc(ispin)%matrix, template=bs_env%mat_ao_ao%matrix)
1672 END IF
1673 END DO
1674
1675 ! calculate KS-matrix without XC
1676 CALL qs_ks_build_kohn_sham_matrix(qs_env, calculate_forces=.false., just_energy=.false., &
1677 ext_ks_matrix=mat_ks_without_v_xc)
1678
1679 DO ispin = 1, bs_env%n_spin
1680 ! transfer dbcsr matrix to fm
1681 CALL cp_fm_create(bs_env%fm_V_xc_Gamma(ispin), bs_env%fm_s_Gamma%matrix_struct)
1682 CALL copy_dbcsr_to_fm(mat_ks_without_v_xc(ispin)%matrix, bs_env%fm_V_xc_Gamma(ispin))
1683
1684 ! v_xc = h_ks - h_ks(v_xc = 0)
1685 CALL cp_fm_scale_and_add(alpha=-1.0_dp, matrix_a=bs_env%fm_V_xc_Gamma(ispin), &
1686 beta=1.0_dp, matrix_b=bs_env%fm_ks_Gamma(ispin))
1687 END DO
1688
1689 CALL dbcsr_deallocate_matrix_set(mat_ks_without_v_xc)
1690
1691 CASE (small_cell_full_kp)
1692
1693 ! calculate KS-matrix without XC
1694 CALL qs_ks_build_kohn_sham_matrix(qs_env, calculate_forces=.false., just_energy=.false.)
1695 CALL get_qs_env(qs_env=qs_env, matrix_ks_kp=matrix_ks_kp)
1696
1697 ALLOCATE (bs_env%fm_V_xc_R(dft_control%nimages, bs_env%n_spin))
1698 DO ispin = 1, bs_env%n_spin
1699 DO img = 1, dft_control%nimages
1700 ! safe fm_V_xc_R in fm_matrix because saving in dbcsr matrix caused trouble...
1701 CALL copy_dbcsr_to_fm(matrix_ks_kp(ispin, img)%matrix, bs_env%fm_work_mo(1))
1702 CALL cp_fm_create(bs_env%fm_V_xc_R(img, ispin), bs_env%fm_work_mo(1)%matrix_struct)
1703 ! store h_ks(v_xc = 0) in fm_V_xc_R
1704 CALL cp_fm_scale_and_add(alpha=1.0_dp, matrix_a=bs_env%fm_V_xc_R(img, ispin), &
1705 beta=1.0_dp, matrix_b=bs_env%fm_work_mo(1))
1706 END DO
1707 END DO
1708
1709 END SELECT
1710
1711 ! set back the energy
1712 energy%total = energy_total
1713 energy%exc = energy_exc
1714 energy%ex = energy_ex
1715
1716 ! set back nimages
1717 dft_control%nimages = nimages
1718
1719 ! set the DFT functional and HF fraction back
1720 CALL section_vals_val_set(xc_section, "XC_FUNCTIONAL%_SECTION_PARAMETERS_", &
1721 i_val=myfun)
1722 IF (hf_present) THEN
1723 CALL section_vals_val_set(xc_section, "HF%FRACTION", &
1724 r_val=myfraction)
1725 END IF
1726
1727 IF (bs_env%small_cell_full_kp_or_large_cell_Gamma == small_cell_full_kp) THEN
1728 ! calculate KS-matrix again with XC
1729 CALL qs_ks_build_kohn_sham_matrix(qs_env, calculate_forces=.false., just_energy=.false.)
1730 DO ispin = 1, bs_env%n_spin
1731 DO img = 1, dft_control%nimages
1732 ! store h_ks in fm_work_mo
1733 CALL copy_dbcsr_to_fm(matrix_ks_kp(ispin, img)%matrix, bs_env%fm_work_mo(1))
1734 ! v_xc = h_ks - h_ks(v_xc = 0)
1735 CALL cp_fm_scale_and_add(alpha=-1.0_dp, matrix_a=bs_env%fm_V_xc_R(img, ispin), &
1736 beta=1.0_dp, matrix_b=bs_env%fm_work_mo(1))
1737 END DO
1738 END DO
1739 END IF
1740
1741 CALL timestop(handle)
1742
1743 END SUBROUTINE compute_v_xc
1744
1745! **************************************************************************************************
1746!> \brief ...
1747!> \param bs_env ...
1748! **************************************************************************************************
1749 SUBROUTINE setup_time_and_frequency_minimax_grid(bs_env)
1750 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
1751
1752 CHARACTER(LEN=*), PARAMETER :: routinen = 'setup_time_and_frequency_minimax_grid'
1753
1754 INTEGER :: handle, homo, i_w, ierr, ispin, j_w, &
1755 n_mo, num_time_freq_points, u
1756 REAL(kind=dp) :: e_max, e_max_ispin, e_min, e_min_ispin, &
1757 e_range, max_error_min
1758 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: points_and_weights
1759
1760 CALL timeset(routinen, handle)
1761
1762 n_mo = bs_env%n_ao
1763 num_time_freq_points = bs_env%num_time_freq_points
1764
1765 ALLOCATE (bs_env%imag_freq_points(num_time_freq_points))
1766 ALLOCATE (bs_env%imag_time_points(num_time_freq_points))
1767 ALLOCATE (bs_env%imag_time_weights_freq_zero(num_time_freq_points))
1768 ALLOCATE (bs_env%weights_cos_t_to_w(num_time_freq_points, num_time_freq_points))
1769 ALLOCATE (bs_env%weights_cos_w_to_t(num_time_freq_points, num_time_freq_points))
1770 ALLOCATE (bs_env%weights_sin_t_to_w(num_time_freq_points, num_time_freq_points))
1771
1772 ! minimum and maximum difference between eigenvalues of unoccupied and an occupied MOs
1773 e_min = 1000.0_dp
1774 e_max = -1000.0_dp
1775 DO ispin = 1, bs_env%n_spin
1776 homo = bs_env%n_occ(ispin)
1777 SELECT CASE (bs_env%small_cell_full_kp_or_large_cell_Gamma)
1778 CASE (large_cell_gamma)
1779 e_min_ispin = bs_env%eigenval_scf_Gamma(homo + 1, ispin) - &
1780 bs_env%eigenval_scf_Gamma(homo, ispin)
1781 e_max_ispin = bs_env%eigenval_scf_Gamma(n_mo, ispin) - &
1782 bs_env%eigenval_scf_Gamma(1, ispin)
1783 CASE (small_cell_full_kp)
1784 e_min_ispin = minval(bs_env%eigenval_scf(homo + 1, :, ispin)) - &
1785 maxval(bs_env%eigenval_scf(homo, :, ispin))
1786 e_max_ispin = maxval(bs_env%eigenval_scf(n_mo, :, ispin)) - &
1787 minval(bs_env%eigenval_scf(1, :, ispin))
1788 END SELECT
1789 e_min = min(e_min, e_min_ispin)
1790 e_max = max(e_max, e_max_ispin)
1791 END DO
1792
1793 e_range = e_max/e_min
1794
1795 ALLOCATE (points_and_weights(2*num_time_freq_points))
1796
1797 ! frequency points
1798 IF (num_time_freq_points .LE. 20) THEN
1799 CALL get_rpa_minimax_coeff(num_time_freq_points, e_range, points_and_weights, ierr, .false.)
1800 ELSE
1801 CALL get_rpa_minimax_coeff_larger_grid(num_time_freq_points, e_range, points_and_weights)
1802 END IF
1803
1804 ! one needs to scale the minimax grids, see Azizi, Wilhelm, Golze, Panades-Barrueta,
1805 ! Giantomassi, Rinke, Draxl, Gonze et al., 2 publications
1806 bs_env%imag_freq_points(:) = points_and_weights(1:num_time_freq_points)*e_min
1807
1808 ! determine number of fit points in the interval [0,ω_max] for virt, or [-ω_max,0] for occ
1809 bs_env%num_freq_points_fit = 0
1810 DO i_w = 1, num_time_freq_points
1811 IF (bs_env%imag_freq_points(i_w) < bs_env%freq_max_fit) THEN
1812 bs_env%num_freq_points_fit = bs_env%num_freq_points_fit + 1
1813 END IF
1814 END DO
1815
1816 ! iω values for the analytic continuation Σ^c_n(iω,k) -> Σ^c_n(ϵ,k)
1817 ALLOCATE (bs_env%imag_freq_points_fit(bs_env%num_freq_points_fit))
1818 j_w = 0
1819 DO i_w = 1, num_time_freq_points
1820 IF (bs_env%imag_freq_points(i_w) < bs_env%freq_max_fit) THEN
1821 j_w = j_w + 1
1822 bs_env%imag_freq_points_fit(j_w) = bs_env%imag_freq_points(i_w)
1823 END IF
1824 END DO
1825
1826 ! reset the number of Padé parameters if smaller than the number of
1827 ! imaginary-frequency points for the fit
1828 IF (bs_env%num_freq_points_fit < bs_env%nparam_pade) THEN
1829 bs_env%nparam_pade = bs_env%num_freq_points_fit
1830 END IF
1831
1832 ! time points
1833 IF (num_time_freq_points .LE. 20) THEN
1834 CALL get_exp_minimax_coeff(num_time_freq_points, e_range, points_and_weights)
1835 ELSE
1836 CALL get_exp_minimax_coeff_gw(num_time_freq_points, e_range, points_and_weights)
1837 END IF
1838
1839 bs_env%imag_time_points(:) = points_and_weights(1:num_time_freq_points)/(2.0_dp*e_min)
1840 bs_env%imag_time_weights_freq_zero(:) = points_and_weights(num_time_freq_points + 1:)/(e_min)
1841
1842 DEALLOCATE (points_and_weights)
1843
1844 u = bs_env%unit_nr
1845 IF (u > 0) THEN
1846 WRITE (u, '(T2,A)') ''
1847 WRITE (u, '(T2,A,F55.2)') 'SCF direct band gap (eV)', e_min*evolt
1848 WRITE (u, '(T2,A,F53.2)') 'Max. SCF eigval diff. (eV)', e_max*evolt
1849 WRITE (u, '(T2,A,F55.2)') 'E-Range for minimax grid', e_range
1850 WRITE (u, '(T2,A,I27)') é'Number of Pad parameters for analytic continuation:', &
1851 bs_env%nparam_pade
1852 WRITE (u, '(T2,A)') ''
1853 END IF
1854
1855 ! in minimax grids, Fourier transforms t -> w and w -> t are split using
1856 ! e^(iwt) = cos(wt) + i sin(wt); we thus calculate weights for trafos with a cos and
1857 ! sine prefactor; details in Azizi, Wilhelm, Golze, Giantomassi, Panades-Barrueta,
1858 ! Rinke, Draxl, Gonze et al., 2 publications
1859
1860 ! cosine transform weights imaginary time to imaginary frequency
1861 CALL get_l_sq_wghts_cos_tf_t_to_w(num_time_freq_points, &
1862 bs_env%imag_time_points, &
1863 bs_env%weights_cos_t_to_w, &
1864 bs_env%imag_freq_points, &
1865 e_min, e_max, max_error_min, &
1866 bs_env%num_points_per_magnitude, &
1867 bs_env%regularization_minimax)
1868
1869 ! cosine transform weights imaginary frequency to imaginary time
1870 CALL get_l_sq_wghts_cos_tf_w_to_t(num_time_freq_points, &
1871 bs_env%imag_time_points, &
1872 bs_env%weights_cos_w_to_t, &
1873 bs_env%imag_freq_points, &
1874 e_min, e_max, max_error_min, &
1875 bs_env%num_points_per_magnitude, &
1876 bs_env%regularization_minimax)
1877
1878 ! sine transform weights imaginary time to imaginary frequency
1879 CALL get_l_sq_wghts_sin_tf_t_to_w(num_time_freq_points, &
1880 bs_env%imag_time_points, &
1881 bs_env%weights_sin_t_to_w, &
1882 bs_env%imag_freq_points, &
1883 e_min, e_max, max_error_min, &
1884 bs_env%num_points_per_magnitude, &
1885 bs_env%regularization_minimax)
1886
1887 CALL timestop(handle)
1888
1889 END SUBROUTINE setup_time_and_frequency_minimax_grid
1890
1891! **************************************************************************************************
1892!> \brief ...
1893!> \param qs_env ...
1894!> \param bs_env ...
1895! **************************************************************************************************
1896 SUBROUTINE setup_cells_3c(qs_env, bs_env)
1897
1898 TYPE(qs_environment_type), POINTER :: qs_env
1899 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
1900
1901 CHARACTER(LEN=*), PARAMETER :: routinen = 'setup_cells_3c'
1902
1903 INTEGER :: atom_i, atom_j, atom_k, block_count, handle, i, i_cell_x, i_cell_x_max, &
1904 i_cell_x_min, i_size, ikind, img, j, j_cell, j_cell_max, j_cell_y, j_cell_y_max, &
1905 j_cell_y_min, j_size, k_cell, k_cell_max, k_cell_z, k_cell_z_max, k_cell_z_min, k_size, &
1906 nimage_pairs_3c, nimages_3c, nimages_3c_max, nkind, u
1907 INTEGER(KIND=int_8) :: mem_occ_per_proc
1908 INTEGER, ALLOCATABLE, DIMENSION(:) :: kind_of, n_other_3c_images_max
1909 INTEGER, ALLOCATABLE, DIMENSION(:, :) :: index_to_cell_3c_max, nblocks_3c_max
1910 INTEGER, DIMENSION(3) :: cell_index, n_max
1911 REAL(kind=dp) :: avail_mem_per_proc_gb, cell_dist, cell_radius_3c, dij, dik, djk, eps, &
1912 exp_min_ao, exp_min_ri, frobenius_norm, mem_3c_gb, mem_occ_per_proc_gb, radius_ao, &
1913 radius_ao_product, radius_ri
1914 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: exp_ao_kind, exp_ri_kind, &
1915 radius_ao_kind, &
1916 radius_ao_product_kind, radius_ri_kind
1917 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :, :) :: int_3c
1918 REAL(kind=dp), DIMENSION(3) :: rij, rik, rjk, vec_cell_j, vec_cell_k
1919 REAL(kind=dp), DIMENSION(:, :), POINTER :: exp_ao, exp_ri
1920 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
1921 TYPE(cell_type), POINTER :: cell
1922 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
1923
1924 CALL timeset(routinen, handle)
1925
1926 CALL get_qs_env(qs_env, nkind=nkind, atomic_kind_set=atomic_kind_set, particle_set=particle_set, cell=cell)
1927
1928 ALLOCATE (exp_ao_kind(nkind), exp_ri_kind(nkind), radius_ao_kind(nkind), &
1929 radius_ao_product_kind(nkind), radius_ri_kind(nkind))
1930
1931 exp_min_ri = 10.0_dp
1932 exp_min_ao = 10.0_dp
1933 exp_ri_kind = 10.0_dp
1934 exp_ao_kind = 10.0_dp
1935
1936 eps = bs_env%eps_filter*bs_env%heuristic_filter_factor
1937
1938 DO ikind = 1, nkind
1939
1940 CALL get_gto_basis_set(bs_env%basis_set_RI(ikind)%gto_basis_set, zet=exp_ri)
1941 CALL get_gto_basis_set(bs_env%basis_set_ao(ikind)%gto_basis_set, zet=exp_ao)
1942
1943 ! we need to remove all exponents lower than a lower bound, e.g. 1E-3, because
1944 ! for contracted basis sets, there might be exponents = 0 in zet
1945 DO i = 1, SIZE(exp_ri, 1)
1946 DO j = 1, SIZE(exp_ri, 2)
1947 IF (exp_ri(i, j) < exp_min_ri .AND. exp_ri(i, j) > 1e-3_dp) exp_min_ri = exp_ri(i, j)
1948 IF (exp_ri(i, j) < exp_ri_kind(ikind) .AND. exp_ri(i, j) > 1e-3_dp) &
1949 exp_ri_kind(ikind) = exp_ri(i, j)
1950 END DO
1951 END DO
1952 DO i = 1, SIZE(exp_ao, 1)
1953 DO j = 1, SIZE(exp_ao, 2)
1954 IF (exp_ao(i, j) < exp_min_ao .AND. exp_ao(i, j) > 1e-3_dp) exp_min_ao = exp_ao(i, j)
1955 IF (exp_ao(i, j) < exp_ao_kind(ikind) .AND. exp_ao(i, j) > 1e-3_dp) &
1956 exp_ao_kind(ikind) = exp_ao(i, j)
1957 END DO
1958 END DO
1959 radius_ao_kind(ikind) = sqrt(-log(eps)/exp_ao_kind(ikind))
1960 radius_ao_product_kind(ikind) = sqrt(-log(eps)/(2.0_dp*exp_ao_kind(ikind)))
1961 radius_ri_kind(ikind) = sqrt(-log(eps)/exp_ri_kind(ikind))
1962 END DO
1963
1964 radius_ao = sqrt(-log(eps)/exp_min_ao)
1965 radius_ao_product = sqrt(-log(eps)/(2.0_dp*exp_min_ao))
1966 radius_ri = sqrt(-log(eps)/exp_min_ri)
1967
1968 CALL get_atomic_kind_set(atomic_kind_set=atomic_kind_set, kind_of=kind_of)
1969
1970 ! For a 3c integral (μR υS | P0) we have that cell R and cell S need to be within radius_3c
1971 cell_radius_3c = radius_ao_product + radius_ri + bs_env%ri_metric%cutoff_radius
1972
1973 n_max(1:3) = bs_env%periodic(1:3)*30
1974
1975 nimages_3c_max = 0
1976
1977 i_cell_x_min = 0
1978 i_cell_x_max = 0
1979 j_cell_y_min = 0
1980 j_cell_y_max = 0
1981 k_cell_z_min = 0
1982 k_cell_z_max = 0
1983
1984 DO i_cell_x = -n_max(1), n_max(1)
1985 DO j_cell_y = -n_max(2), n_max(2)
1986 DO k_cell_z = -n_max(3), n_max(3)
1987
1988 cell_index(1:3) = (/i_cell_x, j_cell_y, k_cell_z/)
1989
1990 CALL get_cell_dist(cell_index, bs_env%hmat, cell_dist)
1991
1992 IF (cell_dist < cell_radius_3c) THEN
1993 nimages_3c_max = nimages_3c_max + 1
1994 i_cell_x_min = min(i_cell_x_min, i_cell_x)
1995 i_cell_x_max = max(i_cell_x_max, i_cell_x)
1996 j_cell_y_min = min(j_cell_y_min, j_cell_y)
1997 j_cell_y_max = max(j_cell_y_max, j_cell_y)
1998 k_cell_z_min = min(k_cell_z_min, k_cell_z)
1999 k_cell_z_max = max(k_cell_z_max, k_cell_z)
2000 END IF
2001
2002 END DO
2003 END DO
2004 END DO
2005
2006 ! get index_to_cell_3c_max for the maximum possible cell range;
2007 ! compute 3c integrals later in this routine and check really which cell is needed
2008 ALLOCATE (index_to_cell_3c_max(nimages_3c_max, 3))
2009
2010 img = 0
2011 DO i_cell_x = -n_max(1), n_max(1)
2012 DO j_cell_y = -n_max(2), n_max(2)
2013 DO k_cell_z = -n_max(3), n_max(3)
2014
2015 cell_index(1:3) = (/i_cell_x, j_cell_y, k_cell_z/)
2016
2017 CALL get_cell_dist(cell_index, bs_env%hmat, cell_dist)
2018
2019 IF (cell_dist < cell_radius_3c) THEN
2020 img = img + 1
2021 index_to_cell_3c_max(img, 1:3) = cell_index(1:3)
2022 END IF
2023
2024 END DO
2025 END DO
2026 END DO
2027
2028 ! get pairs of R and S which have non-zero 3c integral (μR υS | P0)
2029 ALLOCATE (nblocks_3c_max(nimages_3c_max, nimages_3c_max))
2030 nblocks_3c_max(:, :) = 0
2031
2032 block_count = 0
2033 DO j_cell = 1, nimages_3c_max
2034 DO k_cell = 1, nimages_3c_max
2035
2036 DO atom_j = 1, bs_env%n_atom
2037 DO atom_k = 1, bs_env%n_atom
2038 DO atom_i = 1, bs_env%n_atom
2039
2040 block_count = block_count + 1
2041 IF (modulo(block_count, bs_env%para_env%num_pe) .NE. bs_env%para_env%mepos) cycle
2042
2043 CALL scaled_to_real(vec_cell_j, real(index_to_cell_3c_max(j_cell, 1:3), kind=dp), cell)
2044 CALL scaled_to_real(vec_cell_k, real(index_to_cell_3c_max(k_cell, 1:3), kind=dp), cell)
2045
2046 rij = pbc(particle_set(atom_j)%r(:), cell) - pbc(particle_set(atom_i)%r(:), cell) + vec_cell_j(:)
2047 rjk = pbc(particle_set(atom_k)%r(:), cell) - pbc(particle_set(atom_j)%r(:), cell) &
2048 + vec_cell_k(:) - vec_cell_j(:)
2049 rik(:) = rij(:) + rjk(:)
2050 dij = norm2(rij)
2051 dik = norm2(rik)
2052 djk = norm2(rjk)
2053 IF (djk > radius_ao_kind(kind_of(atom_j)) + radius_ao_kind(kind_of(atom_k))) cycle
2054 IF (dij > radius_ao_kind(kind_of(atom_j)) + radius_ri_kind(kind_of(atom_i)) &
2055 + bs_env%ri_metric%cutoff_radius) cycle
2056 IF (dik > radius_ri_kind(kind_of(atom_i)) + radius_ao_kind(kind_of(atom_k)) &
2057 + bs_env%ri_metric%cutoff_radius) cycle
2058
2059 j_size = bs_env%i_ao_end_from_atom(atom_j) - bs_env%i_ao_start_from_atom(atom_j) + 1
2060 k_size = bs_env%i_ao_end_from_atom(atom_k) - bs_env%i_ao_start_from_atom(atom_k) + 1
2061 i_size = bs_env%i_RI_end_from_atom(atom_i) - bs_env%i_RI_start_from_atom(atom_i) + 1
2062
2063 ALLOCATE (int_3c(j_size, k_size, i_size))
2064
2065 ! compute 3-c int. ( μ(atom j) R , ν (atom k) S | P (atom i) 0 )
2066 ! ("|": truncated Coulomb operator), inside build_3c_integrals: (j k | i)
2067 CALL build_3c_integral_block(int_3c, qs_env, bs_env%ri_metric, &
2068 basis_j=bs_env%basis_set_AO, &
2069 basis_k=bs_env%basis_set_AO, &
2070 basis_i=bs_env%basis_set_RI, &
2071 cell_j=index_to_cell_3c_max(j_cell, 1:3), &
2072 cell_k=index_to_cell_3c_max(k_cell, 1:3), &
2073 atom_k=atom_k, atom_j=atom_j, atom_i=atom_i)
2074
2075 frobenius_norm = sqrt(sum(int_3c(:, :, :)**2))
2076
2077 DEALLOCATE (int_3c)
2078
2079 ! we use a higher threshold here to safe memory when storing the 3c integrals
2080 ! in every tensor group
2081 IF (frobenius_norm > eps) THEN
2082 nblocks_3c_max(j_cell, k_cell) = nblocks_3c_max(j_cell, k_cell) + 1
2083 END IF
2084
2085 END DO
2086 END DO
2087 END DO
2088
2089 END DO
2090 END DO
2091
2092 CALL bs_env%para_env%sum(nblocks_3c_max)
2093
2094 ALLOCATE (n_other_3c_images_max(nimages_3c_max))
2095 n_other_3c_images_max(:) = 0
2096
2097 nimages_3c = 0
2098 nimage_pairs_3c = 0
2099
2100 DO j_cell = 1, nimages_3c_max
2101 DO k_cell = 1, nimages_3c_max
2102 IF (nblocks_3c_max(j_cell, k_cell) > 0) THEN
2103 n_other_3c_images_max(j_cell) = n_other_3c_images_max(j_cell) + 1
2104 nimage_pairs_3c = nimage_pairs_3c + 1
2105 END IF
2106 END DO
2107
2108 IF (n_other_3c_images_max(j_cell) > 0) nimages_3c = nimages_3c + 1
2109
2110 END DO
2111
2112 bs_env%nimages_3c = nimages_3c
2113 ALLOCATE (bs_env%index_to_cell_3c(nimages_3c, 3))
2114 ALLOCATE (bs_env%cell_to_index_3c(i_cell_x_min:i_cell_x_max, &
2115 j_cell_y_min:j_cell_y_max, &
2116 k_cell_z_min:k_cell_z_max))
2117 bs_env%cell_to_index_3c(:, :, :) = -1
2118
2119 ALLOCATE (bs_env%nblocks_3c(nimages_3c, nimages_3c))
2120 bs_env%nblocks_3c(nimages_3c, nimages_3c) = 0
2121
2122 j_cell = 0
2123 DO j_cell_max = 1, nimages_3c_max
2124 IF (n_other_3c_images_max(j_cell_max) == 0) cycle
2125 j_cell = j_cell + 1
2126 cell_index(1:3) = index_to_cell_3c_max(j_cell_max, 1:3)
2127 bs_env%index_to_cell_3c(j_cell, 1:3) = cell_index(1:3)
2128 bs_env%cell_to_index_3c(cell_index(1), cell_index(2), cell_index(3)) = j_cell
2129
2130 k_cell = 0
2131 DO k_cell_max = 1, nimages_3c_max
2132 IF (n_other_3c_images_max(k_cell_max) == 0) cycle
2133 k_cell = k_cell + 1
2134
2135 bs_env%nblocks_3c(j_cell, k_cell) = nblocks_3c_max(j_cell_max, k_cell_max)
2136 END DO
2137
2138 END DO
2139
2140 ! we use: 8*10^-9 GB / double precision number
2141 mem_3c_gb = real(bs_env%n_RI, kind=dp)*real(bs_env%n_ao, kind=dp)**2 &
2142 *real(nimage_pairs_3c, kind=dp)*8e-9_dp
2143
2144 CALL m_memory(mem_occ_per_proc)
2145 CALL bs_env%para_env%max(mem_occ_per_proc)
2146
2147 mem_occ_per_proc_gb = real(mem_occ_per_proc, kind=dp)/1.0e9_dp
2148
2149 ! number of processors per group that entirely stores the 3c integrals and does tensor ops
2150 avail_mem_per_proc_gb = bs_env%input_memory_per_proc_GB - mem_occ_per_proc_gb
2151
2152 ! careful: downconvering real to integer, 1.9 -> 1; thus add 1.0 for upconversion, 1.9 -> 2
2153 bs_env%group_size_tensor = max(int(mem_3c_gb/avail_mem_per_proc_gb + 1.0_dp), 1)
2154
2155 u = bs_env%unit_nr
2156
2157 IF (u > 0) THEN
2158 WRITE (u, fmt="(T2,A,F52.1,A)") "Radius of atomic orbitals", radius_ao*angstrom, Å" "
2159 WRITE (u, fmt="(T2,A,F55.1,A)") "Radius of RI functions", radius_ri*angstrom, Å" "
2160 WRITE (u, fmt="(T2,A,I47)") "Number of cells for 3c integrals", nimages_3c
2161 WRITE (u, fmt="(T2,A,I42)") "Number of cell pairs for 3c integrals", nimage_pairs_3c
2162 WRITE (u, '(T2,A)') ''
2163 WRITE (u, '(T2,A,F37.1,A)') 'Input: Available memory per MPI process', &
2164 bs_env%input_memory_per_proc_GB, ' GB'
2165 WRITE (u, '(T2,A,F35.1,A)') 'Used memory per MPI process before GW run', &
2166 mem_occ_per_proc_gb, ' GB'
2167 WRITE (u, '(T2,A,F44.1,A)') 'Memory of three-center integrals', mem_3c_gb, ' GB'
2168 END IF
2169
2170 CALL timestop(handle)
2171
2172 END SUBROUTINE setup_cells_3c
2173
2174! **************************************************************************************************
2175!> \brief ...
2176!> \param index_to_cell_1 ...
2177!> \param index_to_cell_2 ...
2178!> \param nimages_1 ...
2179!> \param nimages_2 ...
2180!> \param index_to_cell ...
2181!> \param cell_to_index ...
2182!> \param nimages ...
2183! **************************************************************************************************
2184 SUBROUTINE sum_two_r_grids(index_to_cell_1, index_to_cell_2, nimages_1, nimages_2, &
2185 index_to_cell, cell_to_index, nimages)
2186
2187 INTEGER, DIMENSION(:, :) :: index_to_cell_1, index_to_cell_2
2188 INTEGER :: nimages_1, nimages_2
2189 INTEGER, ALLOCATABLE, DIMENSION(:, :) :: index_to_cell
2190 INTEGER, DIMENSION(:, :, :), POINTER :: cell_to_index
2191 INTEGER :: nimages
2192
2193 CHARACTER(LEN=*), PARAMETER :: routinen = 'sum_two_R_grids'
2194
2195 INTEGER :: handle, i_dim, img_1, img_2, nimages_max
2196 INTEGER, ALLOCATABLE, DIMENSION(:, :) :: index_to_cell_tmp
2197 INTEGER, DIMENSION(3) :: cell_1, cell_2, r, r_max, r_min
2198
2199 CALL timeset(routinen, handle)
2200
2201 DO i_dim = 1, 3
2202 r_min(i_dim) = minval(index_to_cell_1(:, i_dim)) + minval(index_to_cell_2(:, i_dim))
2203 r_max(i_dim) = maxval(index_to_cell_1(:, i_dim)) + maxval(index_to_cell_2(:, i_dim))
2204 END DO
2205
2206 nimages_max = (r_max(1) - r_min(1) + 1)*(r_max(2) - r_min(2) + 1)*(r_max(3) - r_min(3) + 1)
2207
2208 ALLOCATE (index_to_cell_tmp(nimages_max, 3))
2209 index_to_cell_tmp(:, :) = -1
2210
2211 ALLOCATE (cell_to_index(r_min(1):r_max(1), r_min(2):r_max(2), r_min(3):r_max(3)))
2212 cell_to_index(:, :, :) = -1
2213
2214 nimages = 0
2215
2216 DO img_1 = 1, nimages_1
2217
2218 DO img_2 = 1, nimages_2
2219
2220 cell_1(1:3) = index_to_cell_1(img_1, 1:3)
2221 cell_2(1:3) = index_to_cell_2(img_2, 1:3)
2222
2223 r(1:3) = cell_1(1:3) + cell_2(1:3)
2224
2225 ! check whether we have found a new cell
2226 IF (cell_to_index(r(1), r(2), r(3)) == -1) THEN
2227
2228 nimages = nimages + 1
2229 cell_to_index(r(1), r(2), r(3)) = nimages
2230 index_to_cell_tmp(nimages, 1:3) = r(1:3)
2231
2232 END IF
2233
2234 END DO
2235
2236 END DO
2237
2238 ALLOCATE (index_to_cell(nimages, 3))
2239 index_to_cell(:, :) = index_to_cell_tmp(1:nimages, 1:3)
2240
2241 CALL timestop(handle)
2242
2243 END SUBROUTINE sum_two_r_grids
2244
2245! **************************************************************************************************
2246!> \brief ...
2247!> \param qs_env ...
2248!> \param bs_env ...
2249! **************************************************************************************************
2250 SUBROUTINE compute_3c_integrals(qs_env, bs_env)
2251
2252 TYPE(qs_environment_type), POINTER :: qs_env
2253 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
2254
2255 CHARACTER(LEN=*), PARAMETER :: routinen = 'compute_3c_integrals'
2256
2257 INTEGER :: handle, j_cell, k_cell, nimages_3c
2258
2259 CALL timeset(routinen, handle)
2260
2261 nimages_3c = bs_env%nimages_3c
2262 ALLOCATE (bs_env%t_3c_int(nimages_3c, nimages_3c))
2263 DO j_cell = 1, nimages_3c
2264 DO k_cell = 1, nimages_3c
2265 CALL dbt_create(bs_env%t_RI_AO__AO, bs_env%t_3c_int(j_cell, k_cell))
2266 END DO
2267 END DO
2268
2269 CALL build_3c_integrals(bs_env%t_3c_int, &
2270 bs_env%eps_filter, &
2271 qs_env, &
2272 bs_env%nl_3c, &
2273 int_eps=bs_env%eps_filter*0.05_dp, &
2274 basis_i=bs_env%basis_set_RI, &
2275 basis_j=bs_env%basis_set_AO, &
2276 basis_k=bs_env%basis_set_AO, &
2277 potential_parameter=bs_env%ri_metric, &
2278 desymmetrize=.false., do_kpoints=.true., cell_sym=.true., &
2279 cell_to_index_ext=bs_env%cell_to_index_3c)
2280
2281 CALL bs_env%para_env%sync()
2282
2283 CALL timestop(handle)
2284
2285 END SUBROUTINE compute_3c_integrals
2286
2287! **************************************************************************************************
2288!> \brief ...
2289!> \param cell_index ...
2290!> \param hmat ...
2291!> \param cell_dist ...
2292! **************************************************************************************************
2293 SUBROUTINE get_cell_dist(cell_index, hmat, cell_dist)
2294
2295 INTEGER, DIMENSION(3) :: cell_index
2296 REAL(kind=dp) :: hmat(3, 3), cell_dist
2297
2298 CHARACTER(LEN=*), PARAMETER :: routinen = 'get_cell_dist'
2299
2300 INTEGER :: handle, i_dim
2301 INTEGER, DIMENSION(3) :: cell_index_adj
2302 REAL(kind=dp) :: cell_dist_3(3)
2303
2304 CALL timeset(routinen, handle)
2305
2306 ! the distance of cells needs to be taken to adjacent neighbors, not
2307 ! between the center of the cells. We thus need to rescale the cell index
2308 DO i_dim = 1, 3
2309 IF (cell_index(i_dim) > 0) cell_index_adj(i_dim) = cell_index(i_dim) - 1
2310 IF (cell_index(i_dim) < 0) cell_index_adj(i_dim) = cell_index(i_dim) + 1
2311 IF (cell_index(i_dim) == 0) cell_index_adj(i_dim) = cell_index(i_dim)
2312 END DO
2313
2314 cell_dist_3(1:3) = matmul(hmat, real(cell_index_adj, kind=dp))
2315
2316 cell_dist = sqrt(abs(sum(cell_dist_3(1:3)**2)))
2317
2318 CALL timestop(handle)
2319
2320 END SUBROUTINE get_cell_dist
2321
2322! **************************************************************************************************
2323!> \brief ...
2324!> \param qs_env ...
2325!> \param bs_env ...
2326!> \param kpoints ...
2327!> \param do_print ...
2328! **************************************************************************************************
2329 SUBROUTINE setup_kpoints_scf_desymm(qs_env, bs_env, kpoints, do_print)
2330 TYPE(qs_environment_type), POINTER :: qs_env
2331 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
2332 TYPE(kpoint_type), POINTER :: kpoints
2333
2334 CHARACTER(LEN=*), PARAMETER :: routinen = 'setup_kpoints_scf_desymm'
2335
2336 INTEGER :: handle, i_cell_x, i_dim, img, j_cell_y, &
2337 k_cell_z, nimages, nkp, u
2338 INTEGER, DIMENSION(3) :: cell_grid, cixd, nkp_grid
2339 TYPE(kpoint_type), POINTER :: kpoints_scf
2340
2341 LOGICAL:: do_print
2342
2343 CALL timeset(routinen, handle)
2344
2345 NULLIFY (kpoints)
2346 CALL kpoint_create(kpoints)
2347
2348 CALL get_qs_env(qs_env=qs_env, kpoints=kpoints_scf)
2349
2350 nkp_grid(1:3) = kpoints_scf%nkp_grid(1:3)
2351 nkp = nkp_grid(1)*nkp_grid(2)*nkp_grid(3)
2352
2353 ! we need in periodic directions at least 2 k-points in the SCF
2354 DO i_dim = 1, 3
2355 IF (bs_env%periodic(i_dim) == 1) THEN
2356 cpassert(nkp_grid(i_dim) > 1)
2357 END IF
2358 END DO
2359
2360 kpoints%kp_scheme = "GENERAL"
2361 kpoints%nkp_grid(1:3) = nkp_grid(1:3)
2362 kpoints%nkp = nkp
2363 bs_env%nkp_scf_desymm = nkp
2364
2365 ALLOCATE (kpoints%xkp(1:3, nkp))
2366 CALL compute_xkp(kpoints%xkp, 1, nkp, nkp_grid)
2367
2368 ALLOCATE (kpoints%wkp(nkp))
2369 kpoints%wkp(:) = 1.0_dp/real(nkp, kind=dp)
2370
2371 ! for example 4x3x6 kpoint grid -> 3x3x5 cell grid because we need the same number of
2372 ! neighbor cells on both sides of the unit cell
2373 cell_grid(1:3) = nkp_grid(1:3) - modulo(nkp_grid(1:3) + 1, 2)
2374 ! cell index: for example for x: from -n_x/2 to +n_x/2, n_x: number of cells in x direction
2375 cixd(1:3) = cell_grid(1:3)/2
2376
2377 nimages = cell_grid(1)*cell_grid(2)*cell_grid(3)
2378
2379 bs_env%nimages_scf_desymm = nimages
2380
2381 ALLOCATE (kpoints%cell_to_index(-cixd(1):cixd(1), -cixd(2):cixd(2), -cixd(3):cixd(3)))
2382 ALLOCATE (kpoints%index_to_cell(nimages, 3))
2383
2384 img = 0
2385 DO i_cell_x = -cixd(1), cixd(1)
2386 DO j_cell_y = -cixd(2), cixd(2)
2387 DO k_cell_z = -cixd(3), cixd(3)
2388 img = img + 1
2389 kpoints%cell_to_index(i_cell_x, j_cell_y, k_cell_z) = img
2390 kpoints%index_to_cell(img, 1:3) = (/i_cell_x, j_cell_y, k_cell_z/)
2391 END DO
2392 END DO
2393 END DO
2394
2395 u = bs_env%unit_nr
2396 IF (u > 0 .AND. do_print) THEN
2397 WRITE (u, fmt="(T2,A,I49)") χΣ"Number of cells for G, , W, ", nimages
2398 END IF
2399
2400 CALL timestop(handle)
2401
2402 END SUBROUTINE setup_kpoints_scf_desymm
2403
2404! **************************************************************************************************
2405!> \brief ...
2406!> \param bs_env ...
2407! **************************************************************************************************
2408 SUBROUTINE setup_cells_delta_r(bs_env)
2409
2410 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
2411
2412 CHARACTER(LEN=*), PARAMETER :: routinen = 'setup_cells_Delta_R'
2413
2414 INTEGER :: handle
2415
2416 CALL timeset(routinen, handle)
2417
2418 ! cell sums batch wise for fixed ΔR = S_1 - R_1; for example:
2419 ! Σ_λσ^R = sum_PR1νS1 M^G_λ0,νS1,PR1 M^W_σR,νS1,PR1
2420
2421 CALL sum_two_r_grids(bs_env%index_to_cell_3c, &
2422 bs_env%index_to_cell_3c, &
2423 bs_env%nimages_3c, bs_env%nimages_3c, &
2424 bs_env%index_to_cell_Delta_R, &
2425 bs_env%cell_to_index_Delta_R, &
2426 bs_env%nimages_Delta_R)
2427
2428 IF (bs_env%unit_nr > 0) THEN
2429 WRITE (bs_env%unit_nr, fmt="(T2,A,I61)") Δ"Number of cells R", bs_env%nimages_Delta_R
2430 END IF
2431
2432 CALL timestop(handle)
2433
2434 END SUBROUTINE setup_cells_delta_r
2435
2436! **************************************************************************************************
2437!> \brief ...
2438!> \param bs_env ...
2439! **************************************************************************************************
2440 SUBROUTINE setup_parallelization_delta_r(bs_env)
2441
2442 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
2443
2444 CHARACTER(LEN=*), PARAMETER :: routinen = 'setup_parallelization_Delta_R'
2445
2446 INTEGER :: handle, i_cell_delta_r, i_task_local, &
2447 n_tasks_local
2448 INTEGER, ALLOCATABLE, DIMENSION(:) :: i_cell_delta_r_group, &
2449 n_tensor_ops_delta_r
2450
2451 CALL timeset(routinen, handle)
2452
2453 CALL compute_n_tensor_ops_delta_r(bs_env, n_tensor_ops_delta_r)
2454
2455 CALL compute_delta_r_dist(bs_env, n_tensor_ops_delta_r, i_cell_delta_r_group, n_tasks_local)
2456
2457 bs_env%n_tasks_Delta_R_local = n_tasks_local
2458
2459 ALLOCATE (bs_env%task_Delta_R(n_tasks_local))
2460
2461 i_task_local = 0
2462 DO i_cell_delta_r = 1, bs_env%nimages_Delta_R
2463
2464 IF (i_cell_delta_r_group(i_cell_delta_r) /= bs_env%tensor_group_color) cycle
2465
2466 i_task_local = i_task_local + 1
2467
2468 bs_env%task_Delta_R(i_task_local) = i_cell_delta_r
2469
2470 END DO
2471
2472 ALLOCATE (bs_env%skip_DR_chi(n_tasks_local))
2473 bs_env%skip_DR_chi(:) = .false.
2474 ALLOCATE (bs_env%skip_DR_Sigma(n_tasks_local))
2475 bs_env%skip_DR_Sigma(:) = .false.
2476
2477 CALL allocate_skip_3xr(bs_env%skip_DR_R12_S_Goccx3c_chi, bs_env)
2478 CALL allocate_skip_3xr(bs_env%skip_DR_R12_S_Gvirx3c_chi, bs_env)
2479 CALL allocate_skip_3xr(bs_env%skip_DR_R_R2_MxM_chi, bs_env)
2480
2481 CALL allocate_skip_3xr(bs_env%skip_DR_R1_S2_Gx3c_Sigma, bs_env)
2482 CALL allocate_skip_3xr(bs_env%skip_DR_R1_R_MxM_Sigma, bs_env)
2483
2484 CALL timestop(handle)
2485
2486 END SUBROUTINE setup_parallelization_delta_r
2487
2488! **************************************************************************************************
2489!> \brief ...
2490!> \param skip ...
2491!> \param bs_env ...
2492! **************************************************************************************************
2493 SUBROUTINE allocate_skip_3xr(skip, bs_env)
2494 LOGICAL, ALLOCATABLE, DIMENSION(:, :, :) :: skip
2495 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
2496
2497 CHARACTER(LEN=*), PARAMETER :: routinen = 'allocate_skip_3xR'
2498
2499 INTEGER :: handle
2500
2501 CALL timeset(routinen, handle)
2502
2503 ALLOCATE (skip(bs_env%n_tasks_Delta_R_local, bs_env%nimages_3c, bs_env%nimages_scf_desymm))
2504 skip(:, :, :) = .false.
2505
2506 CALL timestop(handle)
2507
2508 END SUBROUTINE allocate_skip_3xr
2509
2510! **************************************************************************************************
2511!> \brief ...
2512!> \param bs_env ...
2513!> \param n_tensor_ops_Delta_R ...
2514!> \param i_cell_Delta_R_group ...
2515!> \param n_tasks_local ...
2516! **************************************************************************************************
2517 SUBROUTINE compute_delta_r_dist(bs_env, n_tensor_ops_Delta_R, i_cell_Delta_R_group, n_tasks_local)
2518 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
2519 INTEGER, ALLOCATABLE, DIMENSION(:) :: n_tensor_ops_delta_r, &
2520 i_cell_delta_r_group
2521 INTEGER :: n_tasks_local
2522
2523 CHARACTER(LEN=*), PARAMETER :: routinen = 'compute_Delta_R_dist'
2524
2525 INTEGER :: handle, i_delta_r_max_op, i_group_min, &
2526 nimages_delta_r, u
2527 INTEGER, ALLOCATABLE, DIMENSION(:) :: n_tensor_ops_delta_r_in_group
2528
2529 CALL timeset(routinen, handle)
2530
2531 nimages_delta_r = bs_env%nimages_Delta_R
2532
2533 u = bs_env%unit_nr
2534
2535 IF (u > 0 .AND. nimages_delta_r < bs_env%num_tensor_groups) THEN
2536 WRITE (u, fmt="(T2,A,I5,A,I5,A)") "There are only ", nimages_delta_r, &
2537 " tasks to work on but there are ", bs_env%num_tensor_groups, " groups."
2538 WRITE (u, fmt="(T2,A)") "Please reduce the number of MPI processes."
2539 WRITE (u, '(T2,A)') ''
2540 END IF
2541
2542 ALLOCATE (n_tensor_ops_delta_r_in_group(bs_env%num_tensor_groups))
2543 n_tensor_ops_delta_r_in_group(:) = 0
2544 ALLOCATE (i_cell_delta_r_group(nimages_delta_r))
2545 i_cell_delta_r_group(:) = -1
2546
2547 n_tasks_local = 0
2548
2549 DO WHILE (any(n_tensor_ops_delta_r(:) .NE. 0))
2550
2551 ! get largest element of n_tensor_ops_Delta_R
2552 i_delta_r_max_op = maxloc(n_tensor_ops_delta_r, 1)
2553
2554 ! distribute i_Delta_R_max_op to tensor group which has currently the smallest load
2555 i_group_min = minloc(n_tensor_ops_delta_r_in_group, 1)
2556
2557 ! the tensor groups are 0-index based; but i_group_min is 1-index based
2558 i_cell_delta_r_group(i_delta_r_max_op) = i_group_min - 1
2559 n_tensor_ops_delta_r_in_group(i_group_min) = n_tensor_ops_delta_r_in_group(i_group_min) + &
2560 n_tensor_ops_delta_r(i_delta_r_max_op)
2561
2562 ! remove i_Delta_R_max_op from n_tensor_ops_Delta_R
2563 n_tensor_ops_delta_r(i_delta_r_max_op) = 0
2564
2565 IF (bs_env%tensor_group_color == i_group_min - 1) n_tasks_local = n_tasks_local + 1
2566
2567 END DO
2568
2569 CALL timestop(handle)
2570
2571 END SUBROUTINE compute_delta_r_dist
2572
2573! **************************************************************************************************
2574!> \brief ...
2575!> \param bs_env ...
2576!> \param n_tensor_ops_Delta_R ...
2577! **************************************************************************************************
2578 SUBROUTINE compute_n_tensor_ops_delta_r(bs_env, n_tensor_ops_Delta_R)
2579 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
2580 INTEGER, ALLOCATABLE, DIMENSION(:) :: n_tensor_ops_delta_r
2581
2582 CHARACTER(LEN=*), PARAMETER :: routinen = 'compute_n_tensor_ops_Delta_R'
2583
2584 INTEGER :: handle, i_cell_delta_r, i_cell_r, i_cell_r1, i_cell_r1_minus_r, i_cell_r2, &
2585 i_cell_r2_m_r1, i_cell_s1, i_cell_s1_m_r1_p_r2, i_cell_s1_minus_r, i_cell_s2, &
2586 nimages_delta_r
2587 INTEGER, DIMENSION(3) :: cell_dr, cell_m_r1, cell_r, cell_r1, cell_r1_minus_r, cell_r2, &
2588 cell_r2_m_r1, cell_s1, cell_s1_m_r2_p_r1, cell_s1_minus_r, cell_s1_p_s2_m_r1, cell_s2
2589 LOGICAL :: cell_found
2590
2591 CALL timeset(routinen, handle)
2592
2593 nimages_delta_r = bs_env%nimages_Delta_R
2594
2595 ALLOCATE (n_tensor_ops_delta_r(nimages_delta_r))
2596 n_tensor_ops_delta_r(:) = 0
2597
2598 ! compute number of tensor operations for specific Delta_R
2599 DO i_cell_delta_r = 1, nimages_delta_r
2600
2601 IF (modulo(i_cell_delta_r, bs_env%num_tensor_groups) /= bs_env%tensor_group_color) cycle
2602
2603 DO i_cell_r1 = 1, bs_env%nimages_3c
2604
2605 cell_r1(1:3) = bs_env%index_to_cell_3c(i_cell_r1, 1:3)
2606 cell_dr(1:3) = bs_env%index_to_cell_Delta_R(i_cell_delta_r, 1:3)
2607
2608 ! S_1 = R_1 + ΔR (from ΔR = S_1 - R_1)
2609 CALL add_r(cell_r1, cell_dr, bs_env%index_to_cell_3c, cell_s1, &
2610 cell_found, bs_env%cell_to_index_3c, i_cell_s1)
2611 IF (.NOT. cell_found) cycle
2612
2613 DO i_cell_r2 = 1, bs_env%nimages_scf_desymm
2614
2615 cell_r2(1:3) = bs_env%kpoints_scf_desymm%index_to_cell(i_cell_r2, 1:3)
2616
2617 ! R_2 - R_1
2618 CALL add_r(cell_r2, -cell_r1, bs_env%index_to_cell_3c, cell_r2_m_r1, &
2619 cell_found, bs_env%cell_to_index_3c, i_cell_r2_m_r1)
2620 IF (.NOT. cell_found) cycle
2621
2622 ! S_1 - R_1 + R_2
2623 CALL add_r(cell_s1, cell_r2_m_r1, bs_env%index_to_cell_3c, cell_s1_m_r2_p_r1, &
2624 cell_found, bs_env%cell_to_index_3c, i_cell_s1_m_r1_p_r2)
2625 IF (.NOT. cell_found) cycle
2626
2627 n_tensor_ops_delta_r(i_cell_delta_r) = n_tensor_ops_delta_r(i_cell_delta_r) + 1
2628
2629 END DO ! i_cell_R2
2630
2631 DO i_cell_s2 = 1, bs_env%nimages_scf_desymm
2632
2633 cell_s2(1:3) = bs_env%kpoints_scf_desymm%index_to_cell(i_cell_s2, 1:3)
2634 cell_m_r1(1:3) = -cell_r1(1:3)
2635 cell_s1_p_s2_m_r1(1:3) = cell_s1(1:3) + cell_s2(1:3) - cell_r1(1:3)
2636
2637 CALL is_cell_in_index_to_cell(cell_m_r1, bs_env%index_to_cell_3c, cell_found)
2638 IF (.NOT. cell_found) cycle
2639
2640 CALL is_cell_in_index_to_cell(cell_s1_p_s2_m_r1, bs_env%index_to_cell_3c, cell_found)
2641 IF (.NOT. cell_found) cycle
2642
2643 END DO ! i_cell_S2
2644
2645 DO i_cell_r = 1, bs_env%nimages_scf_desymm
2646
2647 cell_r = bs_env%kpoints_scf_desymm%index_to_cell(i_cell_r, 1:3)
2648
2649 ! R_1 - R
2650 CALL add_r(cell_r1, -cell_r, bs_env%index_to_cell_3c, cell_r1_minus_r, &
2651 cell_found, bs_env%cell_to_index_3c, i_cell_r1_minus_r)
2652 IF (.NOT. cell_found) cycle
2653
2654 ! S_1 - R
2655 CALL add_r(cell_s1, -cell_r, bs_env%index_to_cell_3c, cell_s1_minus_r, &
2656 cell_found, bs_env%cell_to_index_3c, i_cell_s1_minus_r)
2657 IF (.NOT. cell_found) cycle
2658
2659 END DO ! i_cell_R
2660
2661 END DO ! i_cell_R1
2662
2663 END DO ! i_cell_Delta_R
2664
2665 CALL bs_env%para_env%sum(n_tensor_ops_delta_r)
2666
2667 CALL timestop(handle)
2668
2669 END SUBROUTINE compute_n_tensor_ops_delta_r
2670
2671! **************************************************************************************************
2672!> \brief ...
2673!> \param cell_1 ...
2674!> \param cell_2 ...
2675!> \param index_to_cell ...
2676!> \param cell_1_plus_2 ...
2677!> \param cell_found ...
2678!> \param cell_to_index ...
2679!> \param i_cell_1_plus_2 ...
2680! **************************************************************************************************
2681 SUBROUTINE add_r(cell_1, cell_2, index_to_cell, cell_1_plus_2, cell_found, &
2682 cell_to_index, i_cell_1_plus_2)
2683
2684 INTEGER, DIMENSION(3) :: cell_1, cell_2
2685 INTEGER, DIMENSION(:, :) :: index_to_cell
2686 INTEGER, DIMENSION(3) :: cell_1_plus_2
2687 LOGICAL :: cell_found
2688 INTEGER, DIMENSION(:, :, :), INTENT(IN), &
2689 OPTIONAL, POINTER :: cell_to_index
2690 INTEGER, INTENT(OUT), OPTIONAL :: i_cell_1_plus_2
2691
2692 CHARACTER(LEN=*), PARAMETER :: routinen = 'add_R'
2693
2694 INTEGER :: handle
2695
2696 CALL timeset(routinen, handle)
2697
2698 cell_1_plus_2(1:3) = cell_1(1:3) + cell_2(1:3)
2699
2700 CALL is_cell_in_index_to_cell(cell_1_plus_2, index_to_cell, cell_found)
2701
2702 IF (PRESENT(i_cell_1_plus_2)) THEN
2703 IF (cell_found) THEN
2704 cpassert(PRESENT(cell_to_index))
2705 i_cell_1_plus_2 = cell_to_index(cell_1_plus_2(1), cell_1_plus_2(2), cell_1_plus_2(3))
2706 ELSE
2707 i_cell_1_plus_2 = -1000
2708 END IF
2709 END IF
2710
2711 CALL timestop(handle)
2712
2713 END SUBROUTINE add_r
2714
2715! **************************************************************************************************
2716!> \brief ...
2717!> \param cell ...
2718!> \param index_to_cell ...
2719!> \param cell_found ...
2720! **************************************************************************************************
2721 SUBROUTINE is_cell_in_index_to_cell(cell, index_to_cell, cell_found)
2722 INTEGER, DIMENSION(3) :: cell
2723 INTEGER, DIMENSION(:, :) :: index_to_cell
2724 LOGICAL :: cell_found
2725
2726 CHARACTER(LEN=*), PARAMETER :: routinen = 'is_cell_in_index_to_cell'
2727
2728 INTEGER :: handle, i_cell, nimg
2729 INTEGER, DIMENSION(3) :: cell_i
2730
2731 CALL timeset(routinen, handle)
2732
2733 nimg = SIZE(index_to_cell, 1)
2734
2735 cell_found = .false.
2736
2737 DO i_cell = 1, nimg
2738
2739 cell_i(1:3) = index_to_cell(i_cell, 1:3)
2740
2741 IF (cell_i(1) == cell(1) .AND. cell_i(2) == cell(2) .AND. cell_i(3) == cell(3)) THEN
2742 cell_found = .true.
2743 END IF
2744
2745 END DO
2746
2747 CALL timestop(handle)
2748
2749 END SUBROUTINE is_cell_in_index_to_cell
2750
2751! **************************************************************************************************
2752!> \brief ...
2753!> \param qs_env ...
2754!> \param bs_env ...
2755! **************************************************************************************************
2756 SUBROUTINE allocate_matrices_small_cell_full_kp(qs_env, bs_env)
2757 TYPE(qs_environment_type), POINTER :: qs_env
2758 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
2759
2760 CHARACTER(LEN=*), PARAMETER :: routinen = 'allocate_matrices_small_cell_full_kp'
2761
2762 INTEGER :: handle, i_spin, i_t, img, n_spin, &
2763 nimages_scf, num_time_freq_points
2764 TYPE(cp_blacs_env_type), POINTER :: blacs_env
2765 TYPE(mp_para_env_type), POINTER :: para_env
2766
2767 CALL timeset(routinen, handle)
2768
2769 nimages_scf = bs_env%nimages_scf_desymm
2770 num_time_freq_points = bs_env%num_time_freq_points
2771 n_spin = bs_env%n_spin
2772
2773 CALL get_qs_env(qs_env, para_env=para_env, blacs_env=blacs_env)
2774
2775 ALLOCATE (bs_env%fm_G_S(nimages_scf))
2776 ALLOCATE (bs_env%fm_Sigma_x_R(nimages_scf))
2777 ALLOCATE (bs_env%fm_chi_R_t(nimages_scf, num_time_freq_points))
2778 ALLOCATE (bs_env%fm_MWM_R_t(nimages_scf, num_time_freq_points))
2779 ALLOCATE (bs_env%fm_Sigma_c_R_neg_tau(nimages_scf, num_time_freq_points, n_spin))
2780 ALLOCATE (bs_env%fm_Sigma_c_R_pos_tau(nimages_scf, num_time_freq_points, n_spin))
2781 DO img = 1, nimages_scf
2782 CALL cp_fm_create(bs_env%fm_G_S(img), bs_env%fm_work_mo(1)%matrix_struct)
2783 CALL cp_fm_create(bs_env%fm_Sigma_x_R(img), bs_env%fm_work_mo(1)%matrix_struct)
2784 DO i_t = 1, num_time_freq_points
2785 CALL cp_fm_create(bs_env%fm_chi_R_t(img, i_t), bs_env%fm_RI_RI%matrix_struct)
2786 CALL cp_fm_create(bs_env%fm_MWM_R_t(img, i_t), bs_env%fm_RI_RI%matrix_struct)
2787 CALL cp_fm_set_all(bs_env%fm_MWM_R_t(img, i_t), 0.0_dp)
2788 DO i_spin = 1, n_spin
2789 CALL cp_fm_create(bs_env%fm_Sigma_c_R_neg_tau(img, i_t, i_spin), &
2790 bs_env%fm_work_mo(1)%matrix_struct)
2791 CALL cp_fm_create(bs_env%fm_Sigma_c_R_pos_tau(img, i_t, i_spin), &
2792 bs_env%fm_work_mo(1)%matrix_struct)
2793 CALL cp_fm_set_all(bs_env%fm_Sigma_c_R_neg_tau(img, i_t, i_spin), 0.0_dp)
2794 CALL cp_fm_set_all(bs_env%fm_Sigma_c_R_pos_tau(img, i_t, i_spin), 0.0_dp)
2795 END DO
2796 END DO
2797 END DO
2798
2799 CALL timestop(handle)
2800
2801 END SUBROUTINE allocate_matrices_small_cell_full_kp
2802
2803! **************************************************************************************************
2804!> \brief ...
2805!> \param qs_env ...
2806!> \param bs_env ...
2807! **************************************************************************************************
2808 SUBROUTINE trafo_v_xc_r_to_kp(qs_env, bs_env)
2809 TYPE(qs_environment_type), POINTER :: qs_env
2810 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
2811
2812 CHARACTER(LEN=*), PARAMETER :: routinen = 'trafo_V_xc_R_to_kp'
2813
2814 INTEGER :: handle, ikp, img, ispin, n_ao
2815 INTEGER, DIMENSION(:, :, :), POINTER :: cell_to_index_scf
2816 TYPE(cp_cfm_type) :: cfm_mo_coeff, cfm_tmp, cfm_v_xc
2817 TYPE(cp_fm_type) :: fm_v_xc_re
2818 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: matrix_ks
2819 TYPE(kpoint_type), POINTER :: kpoints_scf
2820 TYPE(neighbor_list_set_p_type), DIMENSION(:), &
2821 POINTER :: sab_nl
2822
2823 CALL timeset(routinen, handle)
2824
2825 n_ao = bs_env%n_ao
2826
2827 CALL get_qs_env(qs_env, matrix_ks_kp=matrix_ks, kpoints=kpoints_scf)
2828
2829 NULLIFY (sab_nl)
2830 CALL get_kpoint_info(kpoints_scf, sab_nl=sab_nl, cell_to_index=cell_to_index_scf)
2831
2832 CALL cp_cfm_create(cfm_v_xc, bs_env%cfm_work_mo%matrix_struct)
2833 CALL cp_cfm_create(cfm_mo_coeff, bs_env%cfm_work_mo%matrix_struct)
2834 CALL cp_cfm_create(cfm_tmp, bs_env%cfm_work_mo%matrix_struct)
2835 CALL cp_fm_create(fm_v_xc_re, bs_env%cfm_work_mo%matrix_struct)
2836
2837 DO img = 1, bs_env%nimages_scf
2838 DO ispin = 1, bs_env%n_spin
2839 ! JW kind of hack because the format of matrix_ks remains dubious...
2840 CALL dbcsr_set(matrix_ks(ispin, img)%matrix, 0.0_dp)
2841 CALL copy_fm_to_dbcsr(bs_env%fm_V_xc_R(img, ispin), matrix_ks(ispin, img)%matrix)
2842 END DO
2843 END DO
2844
2845 ALLOCATE (bs_env%v_xc_n(n_ao, bs_env%nkp_bs_and_DOS, bs_env%n_spin))
2846
2847 DO ispin = 1, bs_env%n_spin
2848 DO ikp = 1, bs_env%nkp_bs_and_DOS
2849
2850 ! v^xc^R -> v^xc(k) (matrix_ks stores v^xc^R, see SUBROUTINE compute_V_xc)
2851 CALL rsmat_to_kp(matrix_ks, ispin, bs_env%kpoints_DOS%xkp(1:3, ikp), &
2852 cell_to_index_scf, sab_nl, bs_env, cfm_v_xc)
2853
2854 ! get C_µn(k)
2855 CALL cp_cfm_to_cfm(bs_env%cfm_mo_coeff_kp(ikp, ispin), cfm_mo_coeff)
2856
2857 ! v^xc_nm(k_i) = sum_µν C^*_µn(k_i) v^xc_µν(k_i) C_νn(k_i)
2858 CALL parallel_gemm('N', 'N', n_ao, n_ao, n_ao, z_one, cfm_v_xc, cfm_mo_coeff, &
2859 z_zero, cfm_tmp)
2860 CALL parallel_gemm('C', 'N', n_ao, n_ao, n_ao, z_one, cfm_mo_coeff, cfm_tmp, &
2861 z_zero, cfm_v_xc)
2862
2863 ! get v^xc_nn(k_i) which is a real quantity as v^xc is Hermitian
2864 CALL cp_cfm_to_fm(cfm_v_xc, fm_v_xc_re)
2865 CALL cp_fm_get_diag(fm_v_xc_re, bs_env%v_xc_n(:, ikp, ispin))
2866
2867 END DO
2868
2869 END DO
2870
2871 ! just rebuild the overwritten KS matrix again
2872 CALL qs_ks_build_kohn_sham_matrix(qs_env, calculate_forces=.false., just_energy=.false.)
2873
2874 CALL cp_cfm_release(cfm_v_xc)
2875 CALL cp_cfm_release(cfm_mo_coeff)
2876 CALL cp_cfm_release(cfm_tmp)
2877 CALL cp_fm_release(fm_v_xc_re)
2878
2879 CALL timestop(handle)
2880
2881 END SUBROUTINE trafo_v_xc_r_to_kp
2882
2883! **************************************************************************************************
2884!> \brief ...
2885!> \param qs_env ...
2886!> \param bs_env ...
2887! **************************************************************************************************
2888 SUBROUTINE heuristic_ri_regularization(qs_env, bs_env)
2889 TYPE(qs_environment_type), POINTER :: qs_env
2890 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
2891
2892 CHARACTER(LEN=*), PARAMETER :: routinen = 'heuristic_RI_regularization'
2893
2894 COMPLEX(KIND=dp), ALLOCATABLE, DIMENSION(:, :, :) :: m
2895 INTEGER :: handle, ikp, ikp_local, n_ri, nkp, &
2896 nkp_local, u
2897 REAL(kind=dp) :: cond_nr, cond_nr_max, max_ev, &
2898 max_ev_ikp, min_ev, min_ev_ikp
2899 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :, :) :: m_r
2900
2901 CALL timeset(routinen, handle)
2902
2903 ! compute M^R_PQ = <phi_P,0|V^tr(rc)|phi_Q,R> for RI metric
2904 CALL get_v_tr_r(m_r, bs_env%ri_metric, 0.0_dp, bs_env, qs_env)
2905
2906 nkp = bs_env%nkp_chi_eps_W_orig_plus_extra
2907 n_ri = bs_env%n_RI
2908
2909 nkp_local = 0
2910 DO ikp = 1, nkp
2911 ! trivial parallelization over k-points
2912 IF (modulo(ikp, bs_env%para_env%num_pe) .NE. bs_env%para_env%mepos) cycle
2913 nkp_local = nkp_local + 1
2914 END DO
2915
2916 ALLOCATE (m(n_ri, n_ri, nkp_local))
2917
2918 ikp_local = 0
2919 cond_nr_max = 0.0_dp
2920 min_ev = 1000.0_dp
2921 max_ev = -1000.0_dp
2922
2923 DO ikp = 1, nkp
2924
2925 ! trivial parallelization
2926 IF (modulo(ikp, bs_env%para_env%num_pe) .NE. bs_env%para_env%mepos) cycle
2927
2928 ikp_local = ikp_local + 1
2929
2930 ! M(k) = sum_R e^ikR M^R
2931 CALL trafo_rs_to_ikp(m_r, m(:, :, ikp_local), &
2932 bs_env%kpoints_scf_desymm%index_to_cell, &
2933 bs_env%kpoints_chi_eps_W%xkp(1:3, ikp))
2934
2935 ! compute condition number of M_PQ(k)
2936 CALL power(m(:, :, ikp_local), 1.0_dp, 0.0_dp, cond_nr, min_ev_ikp, max_ev_ikp)
2937
2938 IF (cond_nr > cond_nr_max) cond_nr_max = cond_nr
2939 IF (max_ev_ikp > max_ev) max_ev = max_ev_ikp
2940 IF (min_ev_ikp < min_ev) min_ev = min_ev_ikp
2941
2942 END DO ! ikp
2943
2944 CALL bs_env%para_env%max(cond_nr_max)
2945
2946 u = bs_env%unit_nr
2947 IF (u > 0) THEN
2948 WRITE (u, fmt="(T2,A,ES34.1)") "Min. abs. eigenvalue of RI metric matrix M(k)", min_ev
2949 WRITE (u, fmt="(T2,A,ES34.1)") "Max. abs. eigenvalue of RI metric matrix M(k)", max_ev
2950 WRITE (u, fmt="(T2,A,ES50.1)") "Max. condition number of M(k)", cond_nr_max
2951 END IF
2952
2953 CALL timestop(handle)
2954
2955 END SUBROUTINE heuristic_ri_regularization
2956
2957! **************************************************************************************************
2958!> \brief ...
2959!> \param V_tr_R ...
2960!> \param pot_type ...
2961!> \param regularization_RI ...
2962!> \param bs_env ...
2963!> \param qs_env ...
2964! **************************************************************************************************
2965 SUBROUTINE get_v_tr_r(V_tr_R, pot_type, regularization_RI, bs_env, qs_env)
2966 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :, :) :: v_tr_r
2967 TYPE(libint_potential_type) :: pot_type
2968 REAL(kind=dp) :: regularization_ri
2969 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
2970 TYPE(qs_environment_type), POINTER :: qs_env
2971
2972 CHARACTER(LEN=*), PARAMETER :: routinen = 'get_V_tr_R'
2973
2974 INTEGER :: handle, img, nimages_scf_desymm
2975 INTEGER, ALLOCATABLE, DIMENSION(:) :: sizes_ri
2976 INTEGER, DIMENSION(:), POINTER :: col_bsize, row_bsize
2977 TYPE(cp_blacs_env_type), POINTER :: blacs_env
2978 TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:) :: fm_v_tr_r
2979 TYPE(dbcsr_distribution_type) :: dbcsr_dist
2980 TYPE(dbcsr_type), ALLOCATABLE, DIMENSION(:) :: mat_v_tr_r
2981 TYPE(distribution_2d_type), POINTER :: dist_2d
2982 TYPE(neighbor_list_set_p_type), DIMENSION(:), &
2983 POINTER :: sab_ri
2984 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
2985 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
2986
2987 CALL timeset(routinen, handle)
2988
2989 NULLIFY (sab_ri, dist_2d)
2990
2991 CALL get_qs_env(qs_env=qs_env, &
2992 blacs_env=blacs_env, &
2993 distribution_2d=dist_2d, &
2994 qs_kind_set=qs_kind_set, &
2995 particle_set=particle_set)
2996
2997 ALLOCATE (sizes_ri(bs_env%n_atom))
2998 CALL get_particle_set(particle_set, qs_kind_set, nsgf=sizes_ri, basis=bs_env%basis_set_RI)
2999 CALL build_2c_neighbor_lists(sab_ri, bs_env%basis_set_RI, bs_env%basis_set_RI, &
3000 pot_type, "2c_nl_RI", qs_env, sym_ij=.false., &
3001 dist_2d=dist_2d)
3002 CALL cp_dbcsr_dist2d_to_dist(dist_2d, dbcsr_dist)
3003 ALLOCATE (row_bsize(SIZE(sizes_ri)))
3004 ALLOCATE (col_bsize(SIZE(sizes_ri)))
3005 row_bsize(:) = sizes_ri
3006 col_bsize(:) = sizes_ri
3007
3008 nimages_scf_desymm = bs_env%nimages_scf_desymm
3009 ALLOCATE (mat_v_tr_r(nimages_scf_desymm))
3010 CALL dbcsr_create(mat_v_tr_r(1), "(RI|RI)", dbcsr_dist, dbcsr_type_no_symmetry, &
3011 row_bsize, col_bsize)
3012 DEALLOCATE (row_bsize, col_bsize)
3013
3014 DO img = 2, nimages_scf_desymm
3015 CALL dbcsr_create(mat_v_tr_r(img), template=mat_v_tr_r(1))
3016 END DO
3017
3018 CALL build_2c_integrals(mat_v_tr_r, 0.0_dp, qs_env, sab_ri, bs_env%basis_set_RI, &
3019 bs_env%basis_set_RI, pot_type, do_kpoints=.true., &
3020 ext_kpoints=bs_env%kpoints_scf_desymm, &
3021 regularization_ri=regularization_ri)
3022
3023 ALLOCATE (fm_v_tr_r(nimages_scf_desymm))
3024 DO img = 1, nimages_scf_desymm
3025 CALL cp_fm_create(fm_v_tr_r(img), bs_env%fm_RI_RI%matrix_struct)
3026 CALL copy_dbcsr_to_fm(mat_v_tr_r(img), fm_v_tr_r(img))
3027 CALL dbcsr_release(mat_v_tr_r(img))
3028 END DO
3029
3030 IF (.NOT. ALLOCATED(v_tr_r)) THEN
3031 ALLOCATE (v_tr_r(bs_env%n_RI, bs_env%n_RI, nimages_scf_desymm))
3032 END IF
3033
3034 CALL fm_to_local_array(fm_v_tr_r, v_tr_r)
3035
3036 CALL cp_fm_release(fm_v_tr_r)
3037 CALL dbcsr_distribution_release(dbcsr_dist)
3038 CALL release_neighbor_list_sets(sab_ri)
3039
3040 CALL timestop(handle)
3041
3042 END SUBROUTINE get_v_tr_r
3043
3044! **************************************************************************************************
3045!> \brief ...
3046!> \param matrix ...
3047!> \param exponent ...
3048!> \param eps ...
3049!> \param cond_nr ...
3050!> \param min_ev ...
3051!> \param max_ev ...
3052! **************************************************************************************************
3053 SUBROUTINE power(matrix, exponent, eps, cond_nr, min_ev, max_ev)
3054 COMPLEX(KIND=dp), DIMENSION(:, :) :: matrix
3055 REAL(kind=dp) :: exponent, eps
3056 REAL(kind=dp), OPTIONAL :: cond_nr, min_ev, max_ev
3057
3058 CHARACTER(len=*), PARAMETER :: routinen = 'power'
3059
3060 COMPLEX(KIND=dp), ALLOCATABLE, DIMENSION(:, :) :: eigenvectors
3061 INTEGER :: handle, i, n
3062 REAL(kind=dp) :: pos_eval
3063 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: eigenvalues
3064
3065 CALL timeset(routinen, handle)
3066
3067 ! make matrix perfectly Hermitian
3068 matrix(:, :) = 0.5_dp*(matrix(:, :) + conjg(transpose(matrix(:, :))))
3069
3070 n = SIZE(matrix, 1)
3071 ALLOCATE (eigenvalues(n), eigenvectors(n, n))
3072 CALL diag_complex(matrix, eigenvectors, eigenvalues)
3073
3074 IF (PRESENT(cond_nr)) cond_nr = maxval(abs(eigenvalues))/minval(abs(eigenvalues))
3075 IF (PRESENT(min_ev)) min_ev = minval(abs(eigenvalues))
3076 IF (PRESENT(max_ev)) max_ev = maxval(abs(eigenvalues))
3077
3078 DO i = 1, n
3079 IF (eps < eigenvalues(i)) THEN
3080 pos_eval = (eigenvalues(i))**(0.5_dp*exponent)
3081 ELSE
3082 pos_eval = 0.0_dp
3083 END IF
3084 eigenvectors(:, i) = eigenvectors(:, i)*pos_eval
3085 END DO
3086
3087 CALL zgemm("N", "C", n, n, n, z_one, eigenvectors, n, eigenvectors, n, z_zero, matrix, n)
3088
3089 DEALLOCATE (eigenvalues, eigenvectors)
3090
3091 CALL timestop(handle)
3092
3093 END SUBROUTINE power
3094
3095! **************************************************************************************************
3096!> \brief ...
3097!> \param bs_env ...
3098!> \param Sigma_c_n_time ...
3099!> \param Sigma_c_n_freq ...
3100!> \param ispin ...
3101! **************************************************************************************************
3102 SUBROUTINE time_to_freq(bs_env, Sigma_c_n_time, Sigma_c_n_freq, ispin)
3103 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
3104 REAL(kind=dp), DIMENSION(:, :, :) :: sigma_c_n_time, sigma_c_n_freq
3105 INTEGER :: ispin
3106
3107 CHARACTER(LEN=*), PARAMETER :: routinen = 'time_to_freq'
3108
3109 INTEGER :: handle, i_t, j_w, n_occ
3110 REAL(kind=dp) :: freq_j, time_i, w_cos_ij, w_sin_ij
3111 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :) :: sigma_c_n_cos_time, sigma_c_n_sin_time
3112
3113 CALL timeset(routinen, handle)
3114
3115 ALLOCATE (sigma_c_n_cos_time(bs_env%n_ao, bs_env%num_time_freq_points))
3116 ALLOCATE (sigma_c_n_sin_time(bs_env%n_ao, bs_env%num_time_freq_points))
3117
3118 sigma_c_n_cos_time(:, :) = 0.5_dp*(sigma_c_n_time(:, :, 1) + sigma_c_n_time(:, :, 2))
3119 sigma_c_n_sin_time(:, :) = 0.5_dp*(sigma_c_n_time(:, :, 1) - sigma_c_n_time(:, :, 2))
3120
3121 sigma_c_n_freq(:, :, :) = 0.0_dp
3122
3123 DO i_t = 1, bs_env%num_time_freq_points
3124
3125 DO j_w = 1, bs_env%num_time_freq_points
3126
3127 freq_j = bs_env%imag_freq_points(j_w)
3128 time_i = bs_env%imag_time_points(i_t)
3129 ! integration weights for cosine and sine transform
3130 w_cos_ij = bs_env%weights_cos_t_to_w(j_w, i_t)*cos(freq_j*time_i)
3131 w_sin_ij = bs_env%weights_sin_t_to_w(j_w, i_t)*sin(freq_j*time_i)
3132
3133 ! 1. Re(Σ^c_nn(k_i,iω)) from cosine transform
3134 sigma_c_n_freq(:, j_w, 1) = sigma_c_n_freq(:, j_w, 1) + &
3135 w_cos_ij*sigma_c_n_cos_time(:, i_t)
3136
3137 ! 2. Im(Σ^c_nn(k_i,iω)) from sine transform
3138 sigma_c_n_freq(:, j_w, 2) = sigma_c_n_freq(:, j_w, 2) + &
3139 w_sin_ij*sigma_c_n_sin_time(:, i_t)
3140
3141 END DO
3142
3143 END DO
3144
3145 ! for occupied levels, we need the correlation self-energy for negative omega.
3146 ! Therefore, weight_sin should be computed with -omega, which results in an
3147 ! additional minus for the imaginary part:
3148 n_occ = bs_env%n_occ(ispin)
3149 sigma_c_n_freq(1:n_occ, :, 2) = -sigma_c_n_freq(1:n_occ, :, 2)
3150
3151 CALL timestop(handle)
3152
3153 END SUBROUTINE time_to_freq
3154
3155! **************************************************************************************************
3156!> \brief ...
3157!> \param bs_env ...
3158!> \param Sigma_c_ikp_n_freq ...
3159!> \param Sigma_x_ikp_n ...
3160!> \param V_xc_ikp_n ...
3161!> \param eigenval_scf ...
3162!> \param ikp ...
3163!> \param ispin ...
3164! **************************************************************************************************
3165 SUBROUTINE analyt_conti_and_print(bs_env, Sigma_c_ikp_n_freq, Sigma_x_ikp_n, V_xc_ikp_n, &
3166 eigenval_scf, ikp, ispin)
3167
3168 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
3169 REAL(kind=dp), DIMENSION(:, :, :) :: sigma_c_ikp_n_freq
3170 REAL(kind=dp), DIMENSION(:) :: sigma_x_ikp_n, v_xc_ikp_n, eigenval_scf
3171 INTEGER :: ikp, ispin
3172
3173 CHARACTER(LEN=*), PARAMETER :: routinen = 'analyt_conti_and_print'
3174
3175 CHARACTER(len=3) :: occ_vir
3176 CHARACTER(len=default_string_length) :: fname
3177 INTEGER :: handle, i_mo, ikp_for_print, iunit, &
3178 n_mo, nkp
3179 LOGICAL :: is_bandstruc_kpoint, print_dos_kpoints, &
3180 print_ikp
3181 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: dummy, sigma_c_ikp_n_qp
3182
3183 CALL timeset(routinen, handle)
3184
3185 n_mo = bs_env%n_ao
3186 ALLOCATE (dummy(n_mo), sigma_c_ikp_n_qp(n_mo))
3187 sigma_c_ikp_n_qp(:) = 0.0_dp
3188
3189 DO i_mo = 1, n_mo
3190
3191 ! parallelization
3192 IF (modulo(i_mo, bs_env%para_env%num_pe) /= bs_env%para_env%mepos) cycle
3193
3194 CALL continuation_pade(sigma_c_ikp_n_qp, &
3195 bs_env%imag_freq_points_fit, dummy, dummy, &
3196 sigma_c_ikp_n_freq(:, 1:bs_env%num_freq_points_fit, 1)*z_one + &
3197 sigma_c_ikp_n_freq(:, 1:bs_env%num_freq_points_fit, 2)*gaussi, &
3198 sigma_x_ikp_n(:) - v_xc_ikp_n(:), &
3199 eigenval_scf(:), eigenval_scf(:), &
3200 bs_env%do_hedin_shift, &
3201 i_mo, bs_env%n_occ(ispin), bs_env%n_vir(ispin), &
3202 bs_env%nparam_pade, bs_env%num_freq_points_fit, &
3203 ri_rpa_g0w0_crossing_newton, bs_env%n_occ(ispin), &
3204 0.0_dp, .true., .false., 1, e_fermi_ext=bs_env%e_fermi(ispin))
3205 END DO
3206
3207 CALL bs_env%para_env%sum(sigma_c_ikp_n_qp)
3208
3209 CALL correct_obvious_fitting_fails(sigma_c_ikp_n_qp, ispin, bs_env)
3210
3211 bs_env%eigenval_G0W0(:, ikp, ispin) = eigenval_scf(:) + &
3212 sigma_c_ikp_n_qp(:) + &
3213 sigma_x_ikp_n(:) - &
3214 v_xc_ikp_n(:)
3215
3216 bs_env%eigenval_HF(:, ikp, ispin) = eigenval_scf(:) + sigma_x_ikp_n(:) - v_xc_ikp_n(:)
3217
3218 ! only print eigenvalues of DOS k-points in case no bandstructure path has been given
3219 print_dos_kpoints = (bs_env%nkp_only_bs .LE. 0)
3220 ! in kpoints_DOS, the last nkp_only_bs are bandstructure k-points
3221 is_bandstruc_kpoint = (ikp > bs_env%nkp_only_DOS)
3222 print_ikp = print_dos_kpoints .OR. is_bandstruc_kpoint
3223
3224 IF (bs_env%para_env%is_source() .AND. print_ikp) THEN
3225
3226 IF (print_dos_kpoints) THEN
3227 nkp = bs_env%nkp_only_DOS
3228 ikp_for_print = ikp
3229 ELSE
3230 nkp = bs_env%nkp_only_bs
3231 ikp_for_print = ikp - bs_env%nkp_only_DOS
3232 END IF
3233
3234 fname = "bandstructure_SCF_and_G0W0"
3235
3236 IF (ikp_for_print == 1) THEN
3237 CALL open_file(trim(fname), unit_number=iunit, file_status="REPLACE", &
3238 file_action="WRITE")
3239 ELSE
3240 CALL open_file(trim(fname), unit_number=iunit, file_status="OLD", &
3241 file_action="WRITE", file_position="APPEND")
3242 END IF
3243
3244 WRITE (iunit, "(A)") " "
3245 WRITE (iunit, "(A10,I7,A25,3F10.4)") "kpoint: ", ikp_for_print, "coordinate: ", &
3246 bs_env%kpoints_DOS%xkp(:, ikp)
3247 WRITE (iunit, "(A)") " "
3248 WRITE (iunit, "(A5,A12,3A17,A16,A18)") "n", "k", ϵ"_nk^DFT (eV)", Σ"^c_nk (eV)", &
3249 Σ"^x_nk (eV)", "v_nk^xc (eV)", ϵ"_nk^G0W0 (eV)"
3250 WRITE (iunit, "(A)") " "
3251
3252 DO i_mo = 1, n_mo
3253 IF (i_mo .LE. bs_env%n_occ(ispin)) occ_vir = 'occ'
3254 IF (i_mo > bs_env%n_occ(ispin)) occ_vir = 'vir'
3255 WRITE (iunit, "(I5,3A,I5,4F16.3,F17.3)") i_mo, ' (', occ_vir, ') ', ikp_for_print, &
3256 eigenval_scf(i_mo)*evolt, &
3257 sigma_c_ikp_n_qp(i_mo)*evolt, &
3258 sigma_x_ikp_n(i_mo)*evolt, &
3259 v_xc_ikp_n(i_mo)*evolt, &
3260 bs_env%eigenval_G0W0(i_mo, ikp, ispin)*evolt
3261 END DO
3262
3263 WRITE (iunit, "(A)") " "
3264
3265 CALL close_file(iunit)
3266
3267 END IF
3268
3269 CALL timestop(handle)
3270
3271 END SUBROUTINE analyt_conti_and_print
3272
3273! **************************************************************************************************
3274!> \brief ...
3275!> \param Sigma_c_ikp_n_qp ...
3276!> \param ispin ...
3277!> \param bs_env ...
3278! **************************************************************************************************
3279 SUBROUTINE correct_obvious_fitting_fails(Sigma_c_ikp_n_qp, ispin, bs_env)
3280 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: sigma_c_ikp_n_qp
3281 INTEGER :: ispin
3282 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
3283
3284 CHARACTER(LEN=*), PARAMETER :: routinen = 'correct_obvious_fitting_fails'
3285
3286 INTEGER :: handle, homo, i_mo, j_mo, &
3287 n_levels_scissor, n_mo
3288 LOGICAL :: is_occ, is_vir
3289 REAL(kind=dp) :: sum_sigma_c
3290
3291 CALL timeset(routinen, handle)
3292
3293 n_mo = bs_env%n_ao
3294 homo = bs_env%n_occ(ispin)
3295
3296 DO i_mo = 1, n_mo
3297
3298 ! if |𝚺^c| > 13 eV, we use a scissors shift
3299 IF (abs(sigma_c_ikp_n_qp(i_mo)) > 13.0_dp/evolt) THEN
3300
3301 is_occ = (i_mo .LE. homo)
3302 is_vir = (i_mo > homo)
3303
3304 n_levels_scissor = 0
3305 sum_sigma_c = 0.0_dp
3306
3307 ! compute scissor
3308 DO j_mo = 1, n_mo
3309
3310 ! only compute scissor from other GW levels close in energy
3311 IF (is_occ .AND. j_mo > homo) cycle
3312 IF (is_vir .AND. j_mo .LE. homo) cycle
3313 IF (abs(i_mo - j_mo) > 10) cycle
3314 IF (i_mo == j_mo) cycle
3315
3316 n_levels_scissor = n_levels_scissor + 1
3317 sum_sigma_c = sum_sigma_c + sigma_c_ikp_n_qp(j_mo)
3318
3319 END DO
3320
3321 ! overwrite the self-energy with scissor shift
3322 sigma_c_ikp_n_qp(i_mo) = sum_sigma_c/real(n_levels_scissor, kind=dp)
3323
3324 END IF
3325
3326 END DO ! i_mo
3327
3328 CALL timestop(handle)
3329
3330 END SUBROUTINE correct_obvious_fitting_fails
3331
3332END MODULE gw_utils
static GRID_HOST_DEVICE int modulo(int a, int m)
Equivalent of Fortran's MODULO, which always return a positive number. https://gcc....
struct tensor_ tensor
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.
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)
...
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.
Definition cell_types.F:15
subroutine, public scaled_to_real(r, s, cell)
Transform scaled cell coordinates real coordinates. r=h*s.
Definition cell_types.F:516
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_create(matrix, matrix_struct, name)
Creates a new full matrix with the given structure.
subroutine, public cp_cfm_release(matrix)
Releases a full matrix.
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_distribution_release(dist)
...
subroutine, public dbcsr_set(matrix, alpha)
...
subroutine, public dbcsr_release(matrix)
...
DBCSR operations in CP2K.
subroutine, public cp_dbcsr_dist2d_to_dist(dist2d, dist)
Creates a DBCSR distribution from a distribution_2d.
subroutine, public copy_dbcsr_to_fm(matrix, fm)
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. Tracking of preconnections.
Definition cp_files.F:16
subroutine, public open_file(file_name, file_status, file_form, file_action, file_position, file_pad, unit_number, debug, skip_get_unit_number, file_access)
Opens the requested file using a free unit number.
Definition cp_files.F:308
subroutine, public close_file(unit_number, file_status, keep_preconnection)
Close an open file given by its logical unit number. Optionally, keep the file and unit preconnected.
Definition cp_files.F:119
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
Definition cp_fm_types.F:15
subroutine, public cp_fm_get_diag(matrix, diag)
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, use_sp)
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....
Definition dbt_api.F:17
stores a mapping of 2D info (e.g. matrix) on a 2D processor distribution (i.e. blacs grid) where cpus...
subroutine, public fm_to_local_array(fm_s, array_s, weight, add)
...
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)
...
subroutine, public trafo_rs_to_ikp(array_rs, array_kp, index_to_cell, xkp)
...
subroutine, public get_v_tr_r(v_tr_r, pot_type, regularization_ri, bs_env, qs_env)
...
Definition gw_utils.F:2966
subroutine, public time_to_freq(bs_env, sigma_c_n_time, sigma_c_n_freq, ispin)
...
Definition gw_utils.F:3103
subroutine, public de_init_bs_env(bs_env)
...
Definition gw_utils.F:238
subroutine, public compute_xkp(xkp, ikp_start, ikp_end, grid)
...
Definition gw_utils.F:625
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)
...
Definition gw_utils.F:3167
subroutine, public create_and_init_bs_env_for_gw(qs_env, bs_env, bs_sec)
...
Definition gw_utils.F:152
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)
...
Definition gw_utils.F:2683
subroutine, public kpoint_init_cell_index_simple(kpoints, qs_env)
...
Definition gw_utils.F:595
subroutine, public get_i_j_atoms(atoms_i, atoms_j, n_atom_i, n_atom_j, color_sub, bs_env)
...
Definition gw_utils.F:1412
subroutine, public power(matrix, exponent, eps, cond_nr, min_ev, max_ev)
...
Definition gw_utils.F:3054
subroutine, public is_cell_in_index_to_cell(cell, index_to_cell, cell_found)
...
Definition gw_utils.F:2722
collects all constants needed in input so that they can be used without circular dependencies
integer, parameter, public do_potential_truncated
integer, parameter, public rtp_method_bse
integer, parameter, public small_cell_full_kp
integer, parameter, public large_cell_gamma
integer, parameter, public xc_none
integer, parameter, public ri_rpa_g0w0_crossing_newton
objects that represent the structure of input sections and the data contained in an input section
subroutine, public section_vals_val_set(section_vals, keyword_name, i_rep_section, i_rep_val, val, l_val, i_val, r_val, c_val, l_vals_ptr, i_vals_ptr, r_vals_ptr, c_vals_ptr)
sets the requested value
recursive type(section_vals_type) function, pointer, public section_vals_get_subs_vals(section_vals, subsection_name, i_rep_section, can_return_null)
returns the values of the requested subsection
subroutine, public section_vals_get(section_vals, ref_count, n_repetition, n_subs_vals_rep, section, explicit)
returns various attributes about the section_vals
subroutine, public section_vals_val_get(section_vals, keyword_name, i_rep_section, i_rep_val, n_rep_val, val, l_val, i_val, r_val, c_val, l_vals, i_vals, r_vals, c_vals, explicit)
returns the requested value
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public int_8
Definition kinds.F:54
integer, parameter, public dp
Definition kinds.F:34
integer, parameter, public default_string_length
Definition kinds.F:57
Routines needed for kpoint calculation.
subroutine, public kpoint_init_cell_index(kpoint, sab_nl, para_env, dft_control)
Generates the mapping of cell indices and linear RS index CELL (0,0,0) is always mapped to index 1.
Types and basic routines needed for a kpoint calculation.
subroutine, public kpoint_create(kpoint)
Create a kpoint environment.
subroutine, public get_kpoint_info(kpoint, kp_scheme, nkp_grid, kp_shift, symmetry, verbose, full_grid, use_real_wfn, eps_geo, parallel_group_size, kp_range, nkp, xkp, wkp, para_env, blacs_env_all, para_env_kp, para_env_inter_kp, blacs_env, kp_env, kp_aux_env, mpools, iogrp, nkp_groups, kp_dist, cell_to_index, index_to_cell, sab_nl, sab_nl_nosym)
Retrieve information from a kpoint environment.
2- and 3-center electron repulsion integral routines based on libint2 Currently available operators: ...
Interface to the Libint-Library or a c++ wrapper.
subroutine, public cp_libint_static_cleanup()
subroutine, public cp_libint_static_init()
Machine interface based on Fortran 2003 and POSIX.
Definition machine.F:17
subroutine, public m_memory(mem)
Returns the total amount of memory [bytes] in use, if known, zero otherwise.
Definition machine.F:440
real(kind=dp) function, public m_walltime()
returns time from a real-time clock, protected against rolling early/easily
Definition machine.F:147
Definition of mathematical constants and functions.
complex(kind=dp), parameter, public z_one
complex(kind=dp), parameter, public gaussi
complex(kind=dp), parameter, public z_zero
Collection of simple mathematical functions and subroutines.
Definition mathlib.F:15
subroutine, public diag_complex(matrix, eigenvectors, eigenvalues)
Diagonalizes a local complex Hermitian matrix using LAPACK. Based on cp_cfm_heevd.
Definition mathlib.F:1743
elemental integer function, public gcd(a, b)
computes the greatest common divisor of two number
Definition mathlib.F:1280
Interface to the message passing library MPI.
Routines to calculate the minimax coefficients in order to approximate 1/x as a sum over exponential ...
subroutine, public get_exp_minimax_coeff_gw(k, e_range, aw)
...
Routines to calculate the minimax coefficients in order to approximate 1/x as a sum over exponential ...
Definition minimax_exp.F:29
subroutine, public get_exp_minimax_coeff(k, rc, aw, mm_error, which_coeffs)
Get best minimax approximation for given input parameters. Automatically chooses the most exact set o...
Routines to calculate the minimax coefficients for approximating 1/x as 1/x ~ 1/pi SUM_{i}^{K} w_i x^...
Definition minimax_rpa.F:14
subroutine, public get_rpa_minimax_coeff_larger_grid(k, e_range, aw)
...
subroutine, public get_rpa_minimax_coeff(k, e_range, aw, ierr, print_warning)
The a_i and w_i coefficient are stored in aw such that the first 1:K elements correspond to a_i and t...
Definition minimax_rpa.F:41
Calls routines to get RI integrals and calculate total energies.
Definition mp2_gpw.F:14
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)
Encapsulate the building of dbcsr_matrix mat_munu.
Definition mp2_gpw.F:990
Routines to calculate frequency and time grids (integration points and weights) for correlation metho...
Definition mp2_grids.F:14
subroutine, public get_l_sq_wghts_cos_tf_w_to_t(num_integ_points, tau_tj, weights_cos_tf_w_to_t, omega_tj, e_min, e_max, max_error, num_points_per_magnitude, regularization)
...
Definition mp2_grids.F:1244
subroutine, public get_l_sq_wghts_cos_tf_t_to_w(num_integ_points, tau_tj, weights_cos_tf_t_to_w, omega_tj, e_min, e_max, max_error, num_points_per_magnitude, regularization)
Calculate integration weights for the tau grid (in dependency of the omega node)
Definition mp2_grids.F:745
subroutine, public get_l_sq_wghts_sin_tf_t_to_w(num_integ_points, tau_tj, weights_sin_tf_t_to_w, omega_tj, e_min, e_max, max_error, num_points_per_magnitude, regularization)
Calculate integration weights for the tau grid (in dependency of the omega node)
Definition mp2_grids.F:881
Framework for 2c-integrals for RI.
Definition mp2_ri_2c.F:14
subroutine, public trunc_coulomb_for_exchange(qs_env, trunc_coulomb, rel_cutoff_trunc_coulomb_ri_x, cell_grid, do_bvk_cell)
...
Definition mp2_ri_2c.F:1613
basic linear algebra operations for full matrixes
Define methods related to particle_type.
subroutine, public get_particle_set(particle_set, qs_kind_set, first_sgf, last_sgf, nsgf, nmao, basis)
Get the components of a particle set.
Define the data structure for the particle information.
Definition of physical constants:
Definition physcon.F:68
real(kind=dp), parameter, public evolt
Definition physcon.F:183
real(kind=dp), parameter, public angstrom
Definition physcon.F:144
subroutine, public rsmat_to_kp(mat_rs, ispin, xkp, cell_to_index_scf, sab_nl, bs_env, cfm_kp, imag_rs_mat)
...
subroutine, public get_qs_env(qs_env, atomic_kind_set, qs_kind_set, cell, super_cell, cell_ref, use_ref_cell, kpoints, dft_control, mos, sab_orb, sab_all, qmmm, qmmm_periodic, sac_ae, sac_ppl, sac_lri, sap_ppnl, sab_vdw, sab_scp, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, sab_xb, sab_xtb_pp, sab_xtb_nonbond, sab_almo, sab_kp, sab_kp_nosym, particle_set, energy, force, matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, run_rtp, rtp, matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_ks_im_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, matrix_s_ri_aux_kp, matrix_s, matrix_s_ri_aux, matrix_w, matrix_p_mp2, matrix_p_mp2_admm, rho, rho_xc, pw_env, ewald_env, ewald_pw, active_space, mpools, input, para_env, blacs_env, scf_control, rel_control, kinetic, qs_charges, vppl, rho_core, rho_nlcc, rho_nlcc_g, ks_env, ks_qmmm_env, wf_history, scf_env, local_particles, local_molecules, distribution_2d, dbcsr_dist, molecule_kind_set, molecule_set, subsys, cp_subsys, oce, local_rho_set, rho_atom_set, task_list, task_list_soft, rho0_atom_set, rho0_mpole, rhoz_set, ecoul_1c, rho0_s_rs, rho0_s_gs, do_kpoints, has_unit_metric, requires_mo_derivs, mo_derivs, mo_loc_history, nkind, natom, nelectron_total, nelectron_spin, efield, neighbor_list_id, linres_control, xas_env, virial, cp_ddapc_env, cp_ddapc_ewald, outer_scf_history, outer_scf_ihistory, x_data, et_coupling, dftb_potential, results, se_taper, se_store_int_env, se_nddo_mpole, se_nonbond_env, admm_env, lri_env, lri_density, exstate_env, ec_env, 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)
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, 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, 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, init_u_ramping_each_scf, reltmat, ghost, floating, name, element_symbol, pao_basis_size, pao_model_file, pao_potentials, pao_descriptors, nelec)
Get attributes of an atomic kind.
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)
routine where the real calculations are made: the KS matrix is calculated
Define the neighbor list data types and the corresponding functionality.
subroutine, public release_neighbor_list_sets(nlists)
releases an array of neighbor_list_sets
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.
Definition qs_tensors.F:11
subroutine, public build_2c_integrals(t2c, filter_eps, qs_env, nl_2c, basis_i, basis_j, potential_parameter, do_kpoints, do_hfx_kpoints, ext_kpoints, regularization_ri)
...
subroutine, public build_2c_neighbor_lists(ij_list, basis_i, basis_j, potential_parameter, name, qs_env, sym_ij, molecular, dist_2d, pot_to_rad)
Build 2-center neighborlists adapted to different operators This mainly wraps build_neighbor_lists fo...
Definition qs_tensors.F:143
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.
Definition qs_tensors.F:383
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.
Definition qs_tensors.F:282
Routines for GW, continuous development [Jan Wilhelm].
Definition rpa_gw.F:14
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)
perform analytic continuation with pade approximation
Definition rpa_gw.F:4314
Provides all information about an atomic kind.
Type defining parameters related to the simulation cell.
Definition cell_types.F:55
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
represent a full matrix
type of a logger, at the moment it contains just a print level starting at which level it should be l...
distributes pairs on a 2d grid of processors
Contains information about kpoints.
stores all the informations relevant to an mpi environment
Provides all information about a quickstep kind.