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