(git:27c966b)
Loading...
Searching...
No Matches
gw_ri_rs_non_periodic.F
Go to the documentation of this file.
1!--------------------------------------------------------------------------------------------------!
2! CP2K: A general program to perform molecular dynamics simulations !
3! Copyright 2000-2026 CP2K developers group <https://cp2k.org> !
4! !
5! SPDX-License-Identifier: GPL-2.0-or-later !
6!--------------------------------------------------------------------------------------------------!
7
8! **************************************************************************************************
9!> \brief GW using RI-RS Approximation for molecules
10!> \par History
11!> 04.2026 created [Ritaj Tyagi]
12! **************************************************************************************************
13
16 USE cp_fm_diag, ONLY: cp_fm_geeig
17 USE cp_fm_types, ONLY: cp_fm_create,&
30 USE input_constants, ONLY: g0w0,&
31 evgw0
32 USE kinds, ONLY: dp,&
33 int_8,&
37 USE physcon, ONLY: evolt
49#include "./base/base_uses.f90"
50
51 IMPLICIT NONE
52
53 PRIVATE
54
55 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'gw_ri_rs_non_periodic'
56
58
59CONTAINS
60
61! **************************************************************************************************
62!> \brief GW calculation using RI-RS formalism for molecules
63!> \param qs_env ...
64!> \param bs_env Band-structure environment containing GW parameters.
65! **************************************************************************************************
66 SUBROUTINE gw_calc_ri_rs_non_periodic(qs_env, bs_env)
67
68 TYPE(qs_environment_type), POINTER :: qs_env
69 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
70
71 CHARACTER(LEN=*), PARAMETER :: routinen = 'gw_calc_ri_rs_non_periodic'
72
73 INTEGER :: handle
74 TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:) :: fm_sigma_x_gamma, fm_w_time
75
76 CALL timeset(routinen, handle)
77
78 ! Build the common grid, phi and Z representation with the system's boundary conditions.
79 CALL ensure_ri_rs_representation(qs_env, bs_env)
80 IF (bs_env%unit_nr > 0) WRITE (bs_env%unit_nr, '(A)') ' '
81 CALL print_ri_rs_memory_estimate(bs_env)
82
83 CALL mp_print_mem_per_rank(bs_env%para_env, bs_env%unit_nr, &
84 label='Memory per MPI process after computing Z_lP:')
85
86 ! ==============================================================================
87 ! 4. Polarizability matrix χ on the imaginary-time grid
88 ! G^occ_µλ(i|τ|) = Σ_n^occ C_µn e^(-|(ϵ_n-ϵ_F)τ|) C_λn
89 ! G^vir_µλ(i|τ|) = Σ_n^vir C_µn e^(-|(ϵ_n-ϵ_F)τ|) C_λn
90 ! G^occ_ll'(i|τ|) = Σ_µν ϕ_µ(r_l) G^occ_µν ϕ_ν(r_l') (G^vir analogous)
91 ! χ_ll'(iτ) = G^occ_ll'(i|τ|) ∘ G^vir_ll'(i|τ|) (element-wise)
92 ! χ_PQ(iτ) = Σ_ll' Z_lP χ_ll'(iτ) Z_l'Q
93 ! ==============================================================================
94 CALL get_mat_chi_gamma_tau(bs_env, bs_env%mat_chi_Gamma_tau, bs_env%ri_rs%cutoff_radius_v_w)
95
96 ! ==============================================================================
97 ! 5. Screened Coulomb interaction W (RI basis)
98 ! χ_PQ(iτ) -> χ_PQ(iω) -> ε_PQ(iω) -> W_PQ(iω) -> W_PQ(iτ)
99 ! ==============================================================================
100 CALL compute_w(bs_env, qs_env, bs_env%mat_chi_Gamma_tau, fm_w_time)
101
102 ! ==============================================================================
103 ! 6. Exact-exchange self-energy Σ^x
104 ! D_µν = Σ_n^occ C_µn C_νn (density matrix)
105 ! D_ll' = Σ_µν ϕ_µ(r_l) D_µν ϕ_ν(r_l')
106 ! V^tr_ll' = Σ_PQ Z_lP V^tr_PQ Z_l'Q (truncated Coulomb)
107 ! Σ^x_ll' = D_ll' ∘ V^tr_ll'
108 ! Σ^x_λσ(k=0) = -Σ_ll' ϕ_λ(r_l) Σ^x_ll' ϕ_σ(r_l')
109 ! ==============================================================================
110 CALL compute_sigma_x(bs_env, qs_env, fm_sigma_x_gamma, bs_env%ri_rs%cutoff_radius_v_w)
111
112 ! ==============================================================================
113 ! 7. Correlation self-energy Σ^c and quasiparticle energies, iterated
114 ! until eigenvalue self-consistency if the &EVGW0 section is given and
115 ! done in a single pass for G0W0.
116 !
117 ! (a) W_ll'(iτ) = Σ_PQ Z_lP W^MIC_PQ(iτ) Z_l'Q
118 ! Σ^c_ll'(iτ) = -G^occ_ll'(i|τ|) ∘ W_ll'(iτ), τ < 0
119 ! Σ^c_ll'(iτ) = G^vir_ll'(i|τ|) ∘ W_ll'(iτ), τ > 0
120 ! Σ^c_λσ(iτ) = Σ_ll' ϕ_λ(r_l) Σ^c_ll'(iτ) ϕ_σ(r_l')
121 ! (b) Σ^c_λσ(iτ) -> Σ^c_nn(ϵ)
122 ! ϵ_n^GW,(i) = ϵ_n^DFT + Σ^c_nn[G^(i-1),W](ϵ_n^GW,(i)) + Σ^x_nn - v^xc_nn
123 ! ==============================================================================
124 CALL compute_sigma_c_and_qp_energies(bs_env, fm_w_time, fm_sigma_x_gamma)
125
126 CALL de_init_bs_env(qs_env, bs_env)
127
128 CALL timestop(handle)
129
130 END SUBROUTINE gw_calc_ri_rs_non_periodic
131
132! **************************************************************************************************
133!> \brief Correlation self-energy and quasiparticle energies, iterated to eigenvalue
134!> self-consistency in G (evGW0).
135!>
136!> For G0W0 this runs once with G^(0) built from the DFT eigenvalues. For evGW0 the
137!> Green's function is rebuilt from the quasiparticle energies of all states until the
138!> quasiparticle HOMO, LUMO and HOMO-LUMO gap change by less than EPS_ITER between two
139!> cycles, or MAX_ITER cycles are spent. W, Σ^x and everything computed before this
140!> routine stay frozen: they either do not depend on the eigenvalues at all (Σ^x is G
141!> at τ = 0, a pure density matrix) or are held fixed by construction in GW0. The
142!> imaginary-time grid is fixed as well, since W(iτ) lives on it.
143!>
144!> \param bs_env ...
145!> \param fm_W_time ...
146!> \param fm_Sigma_x_Gamma ...
147! **************************************************************************************************
148 SUBROUTINE compute_sigma_c_and_qp_energies(bs_env, fm_W_time, fm_Sigma_x_Gamma)
149
150 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
151 TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:) :: fm_w_time, fm_sigma_x_gamma
152
153 CHARACTER(LEN=*), PARAMETER :: routinen = 'compute_Sigma_c_and_QP_energies'
154
155 INTEGER :: handle, i_iter, n_iter
156 LOGICAL :: converged
157 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :) :: eigenval_scf_gamma_dft
158 REAL(kind=dp), DIMENSION(2) :: e_fermi_dft
159 REAL(kind=dp), DIMENSION(3, 2) :: band_prev
160 TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:, :, :) :: fm_sigma_c_gamma_time
161
162 CALL timeset(routinen, handle)
163
164 converged = .false.
165
166 CALL init_evgw0(bs_env, n_iter, band_prev, eigenval_scf_gamma_dft, e_fermi_dft)
167
168 ! evGW0 self-consistency loop; for G0W0, loop is terminated after one iteration
169 DO i_iter = 1, n_iter
170
171 ! W_ll'(iτ) = Σ_PQ Z_lP W^MIC_PQ(iτ) Z_l'Q
172 ! Σ^c_ll'(iτ) = -G^occ_ll'(i|τ|) ∘ W_ll'(iτ), τ < 0
173 ! Σ^c_ll'(iτ) = G^vir_ll'(i|τ|) ∘ W_ll'(iτ), τ > 0
174 ! Σ^c_λσ(iτ) = Σ_ll' ϕ_λ(r_l) Σ^c_ll'(iτ) ϕ_σ(r_l')
175 CALL compute_sigma_c(bs_env, fm_w_time, fm_sigma_c_gamma_time, &
176 bs_env%ri_rs%cutoff_radius_v_w, keep_w_and_files=.true.)
177
178 ! Σ^c_λσ(iτ) -> Σ^c_nn(ϵ)
179 ! ϵ_n^GW,(i) = ϵ_n^DFT + Σ^c_nn[G^(i-1),W](ϵ_n^GW,(i)) + Σ^x_nn - v^xc_nn
180 CALL compute_qp_energies(bs_env, fm_sigma_x_gamma, fm_sigma_c_gamma_time, i_iter)
181
182 IF (bs_env%gw_flavour == g0w0) EXIT
183
184 CALL print_evgw0_band_edges(bs_env, band_prev, i_iter, n_iter, converged)
185
186 IF (i_iter == n_iter .OR. converged) EXIT
187
188 ! eigenvalues ϵ_n to be updated in G:
189 ! G^occ_µλ(i|τ|) = Σ_n^occ C_µn e^(-|(ϵ_n-ϵ_F)τ|) C_λn
190 ! G^vir_µλ(i|τ|) = Σ_n^vir C_µn e^(-|(ϵ_n-ϵ_F)τ|) C_λn
191 CALL update_eigenvalues_g(bs_env)
192
193 END DO
194
195 CALL cp_fm_release(fm_w_time)
196
197 CALL reset_and_clean_bs_env(bs_env, eigenval_scf_gamma_dft, e_fermi_dft, fm_sigma_x_gamma)
198
199 CALL delete_unnecessary_files(bs_env)
200
201 CALL timestop(handle)
202
203 END SUBROUTINE compute_sigma_c_and_qp_energies
204
205! **************************************************************************************************
206!> \brief Sets up the evGW0 eigenvalue self-consistency loop: the cycle count, the eigenvalues
207!> the first Green's function is built from, and the DFT reference that the loop
208!> overwrites. A G0W0 run reduces to a single cycle and needs none of it.
209!> \param bs_env ...
210!> \param n_iter ...
211!> \param band_prev ...
212!> \param eigenval_scf_Gamma_dft ...
213!> \param e_fermi_dft ...
214! **************************************************************************************************
215 SUBROUTINE init_evgw0(bs_env, n_iter, band_prev, eigenval_scf_Gamma_dft, e_fermi_dft)
216
217 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
218 INTEGER, INTENT(OUT) :: n_iter
219 REAL(kind=dp), DIMENSION(3, 2), INTENT(OUT) :: band_prev
220 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :), &
221 INTENT(OUT) :: eigenval_scf_gamma_dft
222 REAL(kind=dp), DIMENSION(2), INTENT(OUT) :: e_fermi_dft
223
224 CHARACTER(LEN=*), PARAMETER :: routinen = 'init_evGW0'
225
226 INTEGER :: handle
227
228 CALL timeset(routinen, handle)
229
230 n_iter = bs_env%evgw0_n_iter
231 band_prev(:, :) = 0.0_dp
232 e_fermi_dft(:) = 0.0_dp
233
234 IF (bs_env%gw_flavour == evgw0) THEN
235
236 ! eigenvalues currently in G; the first cycle starts is a plain G0W0 step
237 bs_env%eigenval_evGW0(:, :, :) = bs_env%eigenval_scf(:, :, :)
238 ! the loop overwrites these; post-GW printing expects the DFT values back
239 ALLOCATE (eigenval_scf_gamma_dft, source=bs_env%eigenval_scf_Gamma)
240 e_fermi_dft(:) = bs_env%e_fermi(:)
241 END IF
242
243 CALL timestop(handle)
244
245 END SUBROUTINE init_evgw0
246
247! **************************************************************************************************
248!> \brief Feeds the quasiparticle energies of the current evGW0 cycle back into the Green's
249!> function used by the next one, and re-centres the Fermi level between the new
250!> quasiparticle HOMO and LUMO.
251!> \param bs_env ...
252! **************************************************************************************************
253 SUBROUTINE update_eigenvalues_g(bs_env)
254
255 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
256
257 CHARACTER(LEN=*), PARAMETER :: routinen = 'update_eigenvalues_G'
258
259 INTEGER :: handle, i_mo, ispin
260
261 CALL timeset(routinen, handle)
262
263 ! record this cycle's evGW0 result; it is also what the next Green's function is built from
264 bs_env%eigenval_evGW0(:, :, :) = bs_env%eigenval_GW(:, :, :)
265
266 DO ispin = 1, bs_env%n_spin
267 ! Update all physical states; exclude linear-dependency placeholders.
268 DO i_mo = 1, bs_env%n_mo_retained
269 bs_env%eigenval_scf_Gamma(i_mo, ispin) = bs_env%eigenval_GW(i_mo, 1, ispin)
270 END DO
271 bs_env%e_fermi(ispin) = &
272 0.5_dp*(bs_env%eigenval_GW(bs_env%n_occ(ispin), 1, ispin) + &
273 bs_env%eigenval_GW(bs_env%n_occ(ispin) + 1, 1, ispin))
274 END DO
275
276 CALL timestop(handle)
277
278 END SUBROUTINE update_eigenvalues_g
279
280! **************************************************************************************************
281!> \brief Restores the DFT reference that the evGW0 loop overwrote and cleanup
282!> \param bs_env ...
283!> \param eigenval_scf_Gamma_dft ...
284!> \param e_fermi_dft ...
285!> \param fm_Sigma_x_Gamma ..
286! **************************************************************************************************
287 SUBROUTINE reset_and_clean_bs_env(bs_env, eigenval_scf_Gamma_dft, e_fermi_dft, fm_Sigma_x_Gamma)
288
289 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
290 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :), &
291 INTENT(INOUT) :: eigenval_scf_gamma_dft
292 REAL(kind=dp), DIMENSION(2), INTENT(IN) :: e_fermi_dft
293 TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:) :: fm_sigma_x_gamma
294
295 CHARACTER(LEN=*), PARAMETER :: routinen = 'reset_and_clean_bs_env'
296
297 INTEGER :: handle
298
299 CALL timeset(routinen, handle)
300
301 IF (bs_env%gw_flavour == evgw0) THEN
302 ! Update array with final evGW0 result
303 bs_env%eigenval_evGW0(:, :, :) = bs_env%eigenval_GW(:, :, :)
304 ! put the DFT reference back for the post-GW DOS/band-edge printing
305 bs_env%eigenval_scf_Gamma(:, :) = eigenval_scf_gamma_dft(:, :)
306 bs_env%e_fermi(:) = e_fermi_dft(:)
307 DEALLOCATE (eigenval_scf_gamma_dft)
308 CALL cp_fm_release(fm_sigma_x_gamma)
309 END IF
310
311 CALL timestop(handle)
312
313 END SUBROUTINE reset_and_clean_bs_env
314
315! **************************************************************************************************
316!> \brief Print the quasiparticle HOMO, LUMO and HOMO-LUMO gap of the current evGW0 cycle
317!> \param bs_env ...
318!> \param band_prev ...
319!> \param i_iter ...
320!> \param n_iter ...
321!> \param converged ...
322! **************************************************************************************************
323 SUBROUTINE print_evgw0_band_edges(bs_env, band_prev, i_iter, n_iter, converged)
324
325 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
326 REAL(kind=dp), DIMENSION(3, 2), INTENT(INOUT) :: band_prev
327 INTEGER, INTENT(IN) :: i_iter, n_iter
328 LOGICAL, INTENT(OUT) :: converged
329
330 CHARACTER(LEN=*), PARAMETER :: routinen = 'print_evGW0_band_edges'
331
332 INTEGER :: handle, homo, ispin, u
333 REAL(kind=dp) :: max_delta
334 REAL(kind=dp), DIMENSION(3) :: band
335
336 CALL timeset(routinen, handle)
337
338 u = bs_env%unit_nr
339
340 converged = (i_iter > 1)
341 max_delta = 0.0_dp
342
343 IF (u > 0) THEN
344 WRITE (u, '(A)') ' '
345 WRITE (u, '(T2,A)') repeat('-', 79)
346 WRITE (u, '(T2,A,I4,A,I4)') 'evGW0 cycle', i_iter, ' /', n_iter
347 WRITE (u, '(T2,A)') repeat('-', 79)
348 END IF
349
350 DO ispin = 1, bs_env%n_spin
351
352 homo = bs_env%n_occ(ispin)
353 band(1) = bs_env%eigenval_GW(homo, 1, ispin)
354 band(2) = bs_env%eigenval_GW(homo + 1, 1, ispin)
355 band(3) = band(2) - band(1)
356
357 IF (i_iter > 1) THEN
358 max_delta = max(max_delta, maxval(abs(band(:) - band_prev(:, ispin))))
359 END IF
360
361 IF (u > 0) THEN
362 IF (bs_env%n_spin == 2) WRITE (u, '(T2,A,I0)') 'Spin ', ispin
363 WRITE (u, '(T2,A,T61,F20.3)') 'evGW0 HOMO (eV)', band(1)*evolt
364 WRITE (u, '(T2,A,T61,F20.3)') 'evGW0 LUMO (eV)', band(2)*evolt
365 WRITE (u, '(T2,A,T61,F20.3)') 'evGW0 HOMO-LUMO gap (eV)', band(3)*evolt
366 END IF
367
368 band_prev(:, ispin) = band(:)
369
370 END DO
371
372 IF (i_iter > 1) THEN
373 converged = (max_delta < bs_env%evgw0_eps_iter)
374 IF (u > 0) WRITE (u, '(T2,A,T61,F20.6)') 'Max. change to previous cycle (eV)', &
375 max_delta*evolt
376 END IF
377
378 IF (u > 0) WRITE (u, '(T2,A)') repeat('-', 79)
379
380 IF (converged) THEN
381 IF (u > 0) THEN
382 WRITE (u, '(A)') ' '
383 WRITE (u, '(T2,A,I4,A)') &
384 'evGW0 eigenvalue self-consistency reached in', i_iter, ' cycles.'
385 WRITE (u, '(A)') ' '
386 END IF
387 ELSE IF (i_iter == n_iter) THEN
388 CALL cp_warn(__location__, &
389 "The evGW0 eigenvalue self-consistency cycle did not converge "// &
390 "within MAX_ITER cycles. The reported quasiparticle energies are "// &
391 "those of the last cycle.")
392 END IF
393
394 CALL timestop(handle)
395
396 END SUBROUTINE print_evgw0_band_edges
397
398! **************************************************************************************************
399!> \brief Estimates and prints per-process memory requirements for the RI-RS GW calculation.
400!> \param bs_env ...
401! **************************************************************************************************
402 SUBROUTINE print_ri_rs_memory_estimate(bs_env)
403
404 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
405
406 CHARACTER(LEN=*), PARAMETER :: routinen = 'print_ri_rs_memory_estimate'
407
408 CHARACTER(LEN=max_line_length) :: msg
409 INTEGER :: handle, ipan, n_grid_total, n_procs, &
410 n_ri, pan_rows, pan_width
411 INTEGER(KIND=int_8) :: nze_tmpl
412 INTEGER, ALLOCATABLE, DIMENSION(:) :: pan_first, pan_last
413 INTEGER, DIMENSION(:), POINTER :: r_blk_sizes
414 LOGICAL :: use_cutoff
415 LOGICAL, ALLOCATABLE, DIMENSION(:) :: grid_used
416 REAL(kind=dp) :: mem_avail_gb, mem_pan_gb, mem_panels_gb, &
417 mem_z_lp_gb
418
419 CALL timeset(routinen, handle)
420
421 n_grid_total = bs_env%ri_rs%n_grid_points
422 CALL dbcsr_get_info(bs_env%ri_rs%mat_phi_mu_l, row_blk_size=r_blk_sizes)
423 cpassert(sum(r_blk_sizes) == n_grid_total)
424 n_ri = bs_env%n_RI
425 n_procs = bs_env%para_env%num_pe
426
427 ! Z_lP upper bound: dense n_grid × n_RI, distributed evenly across all ranks.
428 ! The actual sparse Z_lP is smaller due to the per-atom locality cutoff.
429 mem_z_lp_gb = real(n_grid_total, dp)*real(n_ri, dp)*8.0_dp/ &
430 REAL(n_procs, dp)*1.0e-9_dp
431
432 ! Peak panel memory during Σ^c: two G panels (A_occ, A_vir) + one W panel plus the
433 ! grid × RI / grid × AO intermediates. With the CUTOFF_RADIUS_RL_W restriction the panel
434 ! matrices only allocate the geo-template blocks, so use the same nze-aware model as the
435 ! panel planner (panel_mem_estimate_GB); without the cutoff, dense panel_rows × n_grid.
436 ! Plus the n_RI × n_RI W_aux matrix. Distributed over n_procs ranks.
437 use_cutoff = bs_env%ri_rs%cutoff_radius_v_w > 0.0_dp .AND. &
438 ALLOCATED(bs_env%ri_rs%chunk_centroids)
439 CALL resolve_grid_panels(bs_env%ri_rs, bs_env%para_env, bs_env%dbcsr_msg_elem_limit, &
440 pan_first, pan_last, bs_env%ri_rs%cutoff_radius_v_w)
441 mem_panels_gb = 0.0_dp
442 DO ipan = 1, SIZE(pan_first)
443 pan_rows = sum(r_blk_sizes(pan_first(ipan):pan_last(ipan)))
444 IF (use_cutoff) THEN
445 CALL mask_grid_blocks_near_panel(bs_env%ri_rs%chunk_centroids, pan_first(ipan), &
446 pan_last(ipan), bs_env%ri_rs%cutoff_radius_v_w, &
447 grid_used)
448 pan_width = sum(r_blk_sizes, mask=grid_used)
449 CALL panel_template_elems(r_blk_sizes, bs_env%ri_rs%chunk_centroids, &
450 grid_used, pan_first(ipan), pan_last(ipan), &
451 bs_env%ri_rs%cutoff_radius_v_w, nze_tmpl)
452 ELSE
453 pan_width = n_grid_total
454 nze_tmpl = int(pan_rows, int_8)*int(pan_width, int_8)
455 END IF
456 CALL panel_mem_estimate_gb(nze_tmpl, pan_rows, pan_width, n_grid_total, &
457 n_ri, bs_env%n_ao, n_procs, mem_pan_gb)
458 mem_panels_gb = max(mem_panels_gb, mem_pan_gb)
459 END DO
460 mem_panels_gb = mem_panels_gb + &
461 REAL(n_ri, dp)*REAL(n_ri, dp)*8.0_dp/REAL(n_procs, dp)*1.0e-9_dp
462
463 ! Available memory per process = node MemLikelyFree / ranks-per-node, min across ranks
464 ! (0 on non-Linux => warnings suppressed below).
465 CALL mp_mem_avail_per_rank_gb(bs_env%para_env, mem_avail_gb)
466
467 IF (bs_env%unit_nr > 0) THEN
468 WRITE (bs_env%unit_nr, '(A)') ' '
469 WRITE (bs_env%unit_nr, '(T2,A)') 'RI-RS memory estimate per MPI process:'
470 WRITE (bs_env%unit_nr, '(T4,A,F37.2,A)') &
471 'Available memory per process (system)', mem_avail_gb, ' GB'
472 WRITE (bs_env%unit_nr, '(T4,A,F18.2,A)') &
473 'Required for Z_lP (dense upper bound; actual is sparser)', mem_z_lp_gb, ' GB'
474 WRITE (bs_env%unit_nr, '(T4,A,F25.2,A)') &
475 'Required for χ, W, Σ panels (peak per panel step)', mem_panels_gb, ' GB'
476 IF (bs_env%ri_rs%Z_lP_exists .AND. .NOT. bs_env%auto_ri%enabled) THEN
477 WRITE (bs_env%unit_nr, '(T4,A)') 'Z_lP fitting skipped (matrix read from restart)'
478 END IF
479
480 END IF
481
482 IF (mem_avail_gb > 0.0_dp .AND. mem_z_lp_gb > mem_avail_gb) THEN
483 WRITE (msg, '(A,F0.2,A,F0.2,A)') &
484 "The estimated memory for Z_lP, ", mem_z_lp_gb, " GB per process, exceeds the "// &
485 "available ", mem_avail_gb, " GB. Z_lP (n_grid x n_RI) is distributed across all "// &
486 "MPI ranks, so add nodes or use fewer MPI ranks per node."
487 cpwarn(trim(msg))
488 END IF
489
490 IF (mem_avail_gb > 0.0_dp .AND. mem_panels_gb > mem_avail_gb) THEN
491 WRITE (msg, '(A,F0.2,A,F0.2,A)') &
492 "The estimated peak memory of the chi/W/Sigma panels, ", mem_panels_gb, &
493 " GB per process, exceeds the available ", mem_avail_gb, " GB. Panel memory "// &
494 "scales roughly as 3*panel_size*n_grid/n_procs, so add nodes, use fewer MPI ranks "// &
495 "per node."
496 cpwarn(trim(msg))
497 END IF
498
499 CALL timestop(handle)
500
501 END SUBROUTINE print_ri_rs_memory_estimate
502
503! **************************************************************************************************
504!> \brief Σ^c_λσ(iτ) -> Σ^c_nn(ϵ) and the quasi-particle levels of the non-periodic RI-RS path,
505!> ϵ_n^GW = ϵ_n^DFT + Σ^c_nn(ϵ_n^GW) + Σ^x_nn - v^xc_nn.
506!> \param bs_env ...
507!> \param fm_Sigma_x_Gamma ...
508!> \param fm_Sigma_c_Gamma_time ...
509!> \param i_iter ...
510! **************************************************************************************************
511 SUBROUTINE compute_qp_energies(bs_env, fm_Sigma_x_Gamma, fm_Sigma_c_Gamma_time, i_iter)
512
513 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
514 TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:) :: fm_sigma_x_gamma
515 TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:, :, :) :: fm_sigma_c_gamma_time
516 INTEGER, INTENT(IN) :: i_iter
517
518 CHARACTER(LEN=*), PARAMETER :: routinen = 'compute_QP_energies'
519
520 COMPLEX(KIND=dp), ALLOCATABLE, DIMENSION(:, :) :: sigma_c_n_freq
521 INTEGER :: handle, ispin, j_t
522 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: sigma_x_n, v_xc_n
523 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :, :) :: sigma_c_n_time
524 TYPE(cp_fm_type) :: fm_ks, fm_mos, fm_s, fm_work
525
526 CALL timeset(routinen, handle)
527
528 CALL cp_fm_create(fm_ks, bs_env%fm_s_Gamma%matrix_struct)
529 CALL cp_fm_create(fm_s, bs_env%fm_s_Gamma%matrix_struct)
530 CALL cp_fm_create(fm_mos, bs_env%fm_s_Gamma%matrix_struct)
531 CALL cp_fm_create(fm_work, bs_env%fm_s_Gamma%matrix_struct)
532
533 ALLOCATE (v_xc_n(bs_env%n_ao), sigma_x_n(bs_env%n_ao))
534 ALLOCATE (sigma_c_n_time(bs_env%n_ao, bs_env%num_time_freq_points, 2))
535 ALLOCATE (sigma_c_n_freq(bs_env%n_ao, bs_env%num_freq_points_fit))
536
537 DO ispin = 1, bs_env%n_spin
538
539 ! 1. Roothaan-Hall H^KS_µν C_νn = S_µν C_νn ϵ_n
540 CALL cp_fm_to_fm(bs_env%fm_ks_Gamma(ispin), fm_ks)
541 CALL cp_fm_to_fm(bs_env%fm_s_Gamma, fm_s)
542 CALL cp_fm_geeig(fm_ks, fm_s, fm_mos, bs_env%eigenval_scf(:, 1, ispin), fm_work)
543
544 ! 2. v^xc_µν -> v^xc_nn and Σ^x_µν -> Σ^x_nn
545 CALL to_gamma_and_mo_real(v_xc_n, bs_env%fm_V_xc_Gamma(ispin), fm_mos)
546 CALL to_gamma_and_mo_real(sigma_x_n, fm_sigma_x_gamma(ispin), fm_mos)
547
548 ! 3. Σ^c_µν(+/-i|τ_j|) -> Σ^c_nn(+/-i|τ_j|)
549 DO j_t = 1, bs_env%num_time_freq_points
550 CALL to_gamma_and_mo_real(sigma_c_n_time(:, j_t, positive_time), &
551 fm_sigma_c_gamma_time(j_t, positive_time, ispin), fm_mos)
552 CALL to_gamma_and_mo_real(sigma_c_n_time(:, j_t, negative_time), &
553 fm_sigma_c_gamma_time(j_t, negative_time, ispin), fm_mos)
554 END DO
555
556 ! 4. Σ^c_nn(iτ) -> Σ^c_nn(iω)
557 CALL transform_time_to_frequency(bs_env%time_frequency_grid_sigma, sigma_c_n_time, sigma_c_n_freq)
558 sigma_c_n_freq(1:bs_env%n_occ(ispin), :) = conjg(sigma_c_n_freq(1:bs_env%n_occ(ispin), :))
559
560 ! 5. Analytic continuation Σ^c_nn(iω) -> Σ^c_nn(ϵ) and the QP levels
561 CALL analyt_conti_and_print(bs_env, sigma_c_n_freq, sigma_x_n, v_xc_n, &
562 bs_env%eigenval_scf(:, 1, ispin), 1, ispin, i_iter)
563
564 END DO ! ispin
565
566 CALL get_all_vbm_cbm_bandgaps(bs_env)
567
568 IF (bs_env%gw_flavour == g0w0) CALL cp_fm_release(fm_sigma_x_gamma)
569 CALL cp_fm_release(fm_sigma_c_gamma_time)
570
571 CALL cp_fm_release(fm_ks)
572 CALL cp_fm_release(fm_s)
573 CALL cp_fm_release(fm_mos)
574 CALL cp_fm_release(fm_work)
575
576 CALL timestop(handle)
577
578 END SUBROUTINE compute_qp_energies
579
580! **************************************************************************************************
581!> \brief AO -> MO transform of a Γ-point matrix
582!> \param array_n ...
583!> \param fm_Gamma ...
584!> \param fm_mos ...
585! **************************************************************************************************
586 SUBROUTINE to_gamma_and_mo_real(array_n, fm_Gamma, fm_mos)
587
588 REAL(kind=dp), DIMENSION(:) :: array_n
589 TYPE(cp_fm_type) :: fm_gamma, fm_mos
590
591 CHARACTER(LEN=*), PARAMETER :: routinen = 'to_Gamma_and_mo_real'
592
593 INTEGER :: handle
594 TYPE(cp_fm_type) :: fm_mo
595
596 CALL timeset(routinen, handle)
597
598 CALL cp_fm_create(fm_mo, fm_gamma%matrix_struct)
599
600 ! A_nn' = Σ_μν C_μn A_μν C_νn'
601 CALL fm_contract_aba(fm_mos, fm_gamma, fm_mo)
602
603 CALL cp_fm_get_diag(fm_mo, array_n)
604
605 CALL cp_fm_release(fm_mo)
606
607 CALL timestop(handle)
608
609 END SUBROUTINE to_gamma_and_mo_real
610
611END MODULE gw_ri_rs_non_periodic
subroutine, public dbcsr_get_info(matrix, nblkrows_total, nblkcols_total, nfullrows_total, nfullcols_total, nblkrows_local, nblkcols_local, nfullrows_local, nfullcols_local, my_prow, my_pcol, local_rows, local_cols, proc_row_dist, proc_col_dist, row_blk_size, col_blk_size, row_blk_offset, col_blk_offset, distribution, name, matrix_type, group)
...
used for collecting some of the diagonalization schemes available for cp_fm_type. cp_fm_power also mo...
Definition cp_fm_diag.F:17
subroutine, public cp_fm_geeig(amatrix, bmatrix, eigenvectors, eigenvalues, work)
General Eigenvalue Problem AX = BXE. Use cuSOLVERMp directly when requested and large enough; otherwi...
represent a full matrix distributed on many processors
Definition cp_fm_types.F:15
subroutine, public cp_fm_get_diag(matrix, diag, n_active)
returns the diagonal elements of a fm
subroutine, public cp_fm_create(matrix, matrix_struct, name, nrow, ncol, set_zero)
creates a new full matrix with the given structure
Coulomb matrices and screened interactions for imaginary-time GW.
subroutine, public compute_w(bs_env, qs_env, mat_chi_gamma_tau, fm_w_time)
Computes the screened Coulomb interaction on the imaginary-time grid, entirely in the RI auxiliary (P...
Shared RI-RS polarizability and self-energy assembly.
subroutine, public compute_sigma_c(bs_env, fm_w_time, fm_sigma_c_gamma_time, cutoff, keep_w_and_files)
Computes the correlation part of the GW self-energy on the imaginary-time grid: Σ^c_λσ(iτ<0) = -Σ_ll'...
subroutine, public get_mat_chi_gamma_tau(bs_env, mat_chi_gamma_tau, cutoff)
Computes χ_PQ(iτ) from the occupied and virtual Green's functions.
subroutine, public compute_sigma_x(bs_env, qs_env, fm_sigma_x_gamma, cutoff)
Computes the exact-exchange part of the GW self-energy: D_μν = Σ_n^occ C_μn C_νn (density matrix = G^...
GW using RI-RS Approximation for molecules.
subroutine, public gw_calc_ri_rs_non_periodic(qs_env, bs_env)
GW calculation using RI-RS formalism for molecules.
Routines from paper [Graml2024].
subroutine, public delete_unnecessary_files(bs_env)
...
Full-matrix operations not provided by the CP2K FM packages.
Definition gw_utils_fm.F:13
subroutine, public de_init_bs_env(qs_env, bs_env)
Releases the memory-heavy GW intermediates that cannot be freed in bs_env_release,...
Definition gw_utils.F:3562
subroutine, public analyt_conti_and_print(bs_env, sigma_c_ikp_n_freq, sigma_x_ikp_n, v_xc_ikp_n, eigenval_scf, ikp, ispin, i_iter)
...
Definition gw_utils.F:3653
collects all constants needed in input so that they can be used without circular dependencies
integer, parameter, public g0w0
integer, parameter, public evgw0
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public max_line_length
Definition kinds.F:59
integer, parameter, public int_8
Definition kinds.F:54
integer, parameter, public dp
Definition kinds.F:34
Interface to the message passing library MPI.
subroutine, public mp_mem_avail_per_rank_gb(comm, mem_avail_gb)
Memory that is currently free on the node, per MPI rank of that node, in GB.
subroutine, public mp_print_mem_per_rank(comm, unit_nr, label)
Prints the memory available to and used by a single MPI rank at the moment of the call....
Definition of physical constants:
Definition physcon.F:68
real(kind=dp), parameter, public evolt
Definition physcon.F:183
subroutine, public get_all_vbm_cbm_bandgaps(bs_env)
...
DBCSR collocation, layouts and panel contractions for real-space resolution of the identity.
subroutine, public resolve_grid_panels(ri_rs, para_env, msg_elem_limit, pan_first, pan_last, cutoff)
Resolve and cache grid-panel boundaries for RI-RS streaming contractions.
subroutine, public panel_template_elems(r_blk_sizes, centroids, used, blk0, blk1, cutoff, nze_tmpl)
Exact allocated-element count of the geo template of panel [blk0, blk1]: the very same per-block-pair...
subroutine, public panel_mem_estimate_gb(nze_tmpl, pan_rows, width, n_grid_total, n_ri, n_ao, n_procs, mem_gb)
Per-rank peak memory (GB) of one panel step of the neighborhood-restricted contractions: up to three ...
subroutine, public mask_grid_blocks_near_panel(centroids, blk0, blk1, cutoff, used)
Marks the grid blocks whose centroid lies within cutoff of the bounding box of the panel [blk0,...
Builds the shared RI-RS grid, AO collocation and fitting representation.
Definition ri_rs_setup.F:15
subroutine, public ensure_ri_rs_representation(qs_env, bs_env)
Populate the RI-RS grid, AO collocation and auxiliary fitting coefficients once. Periodic systems use...
Definition ri_rs_setup.F:79
Definition and construction of time/frequency grids for correlation methods.
subroutine, public transform_time_to_frequency(grid, samples_tau, values_omega)
Transform real positive/negative-time samples to complex positive-frequency values....
integer, parameter, public negative_time
integer, parameter, public positive_time
represent a full matrix