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