LCOV - code coverage report
Current view: top level - src - gw_ri_rs_small_cell_full_kp.F (source / functions) Coverage Total Hit
Test: CP2K Regtests (git:1be8651) Lines: 42.4 % 125 53
Test Date: 2026-11-24 01:22:08 Functions: 60.0 % 5 3

            Line data    Source code
       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 Fully periodic small-cell GW using RI-RS and explicit full k-point sampling.
      10              : !> \author Jan Wilhelm (with help of ChatGPT, GPT-6 Sol and GPT-6 Astra)
      11              : ! **************************************************************************************************
      12              : MODULE gw_ri_rs_small_cell_full_kp
      13              :    USE gw_ri_rs_small_cell_full_kp_types,ONLY: gwkp_type
      14              :    USE gw_ri_rs_small_cell_full_kp_utils,ONLY: compute_Sigma_x,&
      15              :                                               compute_W0,&
      16              :                                               compute_g_and_chi,&
      17              :                                               compute_sigma_c_from_w_pq,&
      18              :                                               prepare_ri_rs,&
      19              :                                               release_gw_work
      20              :    USE gw_utils,                        ONLY: analyt_conti_and_print,&
      21              :                                               de_init_bs_env,&
      22              :                                               gw_qp_summary_type
      23              :    USE input_constants,                 ONLY: evGW0
      24              :    USE kinds,                           ONLY: dp
      25              :    USE physcon,                         ONLY: evolt
      26              :    USE post_scf_bandstructure_types,    ONLY: band_edges_type,&
      27              :                                               post_scf_bandstructure_type
      28              :    USE post_scf_bandstructure_utils,    ONLY: get_VBM_CBM_bandgaps,&
      29              :                                               get_all_VBM_CBM_bandgaps
      30              :    USE qs_environment_types,            ONLY: qs_environment_type
      31              :    USE time_frequency_grids,            ONLY: transform_time_to_frequency
      32              : #include "./base/base_uses.f90"
      33              : 
      34              :    IMPLICIT NONE
      35              :    PRIVATE
      36              : 
      37              :    CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'gw_ri_rs_small_cell_full_kp'
      38              : 
      39              :    PUBLIC :: gw_calc_ri_rs_small_cell_full_kp
      40              : 
      41              : CONTAINS
      42              : 
      43              : ! **************************************************************************************************
      44              : !> \brief Periodic RI-RS GW from the converged SCF orbitals and eigenvalues.
      45              : !>
      46              : !> l,l′ label real-space points r_l,r_l′; μ labels AOs, n bands, σ spins, P,Q RI functions.
      47              : !> k samples the SCF mesh, q transfers momentum, and R,T are lattice vectors.
      48              : !> All phases use Cartesian vectors. ψ_nkσ(r_l) is a sampled Bloch orbital;
      49              : !> C_μn(k,σ) is its AO coefficient. σ sums over the two physical spin channels.
      50              : !>
      51              : !>  (1) ϕ_μ(k,r_l) = Σ_R exp(ik·R) ϕ_μ(r_l-R),
      52              : !>      ψ_nkσ(r_l) = Σ_μ ϕ_μ(k,r_l) C_μn(k,σ).
      53              : !>
      54              : !>  (2) ρ_l(r) = Σ_μR ϕ_μ(r_l-R) ϕ_μ(r-R),
      55              : !>      D_ll′(T) = ρ_l(r_l′+T)²,
      56              : !>      d_lP(T) = ∫dr ∫dr′ ρ_l(r)² m(r-r′) P(r′-T),
      57              : !>      D_ll′(q) = Σ_T exp(iq·T) D_ll′(T),
      58              : !>      d_lP(q) = Σ_T exp(iq·T) d_lP(T),
      59              : !>      S_l(q) = D_ll(q)^(-1/2),
      60              : !>      D̂_ll′(q) = S_l(q) D_ll′(q) S_l′(q),  d̂_lP(q) = S_l(q) d_lP(q),
      61              : !>      [D̂(q) + ηI] z_P(q) = d̂_P(q),  Z_lP(q) = S_l(q) z_lP(q).
      62              : !>      P(r) is an RI basis function, m(r-r′) the selected RI fitting kernel,
      63              : !>      and η = RI_RS/TIKHONOV.
      64              : !>
      65              : !>  (3) G^occ/vir_ll′(k,iτ;σ) = Σ_n∈occ/vir ψ_nkσ(r_l) ψ_nkσ(r_l′)*
      66              : !>                                          × exp(-|ε_nkσ-ε_Fσ| τ),  τ≥0.
      67              : !>
      68              : !>  (4) G^occ/vir_ll′(R,iτ;σ) = Re[Σ_k w_k exp(-ik·R) G^occ/vir_ll′(k,iτ;σ)].
      69              : !>
      70              : !>  (5) χ_ll′(R,iτ) = Σ_σ G^occ_ll′(R,iτ;σ) G^vir_ll′(R,iτ;σ),
      71              : !>      χ_ll′(q,iτ) = Σ_R exp(iq·R) χ_ll′(R,iτ).
      72              : !>
      73              : !>  (6) χ_ll′(q,iω_j) = Σ_t C_jt χ_ll′(q,iτ_t),
      74              : !>      χ_PQ(q,iω_j) = Σ_ll′ Z_lP(q)* χ_ll′(q,iω_j) Z_l′Q(q).
      75              : !>      C_jt supplies the imaginary-time Fourier transformation by cosine quadrature.
      76              : !>
      77              : !>  (7) K(q) = M(q)⁻¹ V(q)½,
      78              : !>      ε_PQ(q,iω) = δ_PQ + Σ_P′Q′ K_P′P(q)* χ_P′Q′(q,iω) K_Q′Q(q),
      79              : !>      Wᶜ_PQ(q,iω) = Σ_P′Q′ K_PP′(q) [ε⁻¹_P′Q′(q,iω)-δ_P′Q′] K_QQ′(q)*.
      80              : !>      M is the RI fitting metric and V the Coulomb matrix.
      81              : !>
      82              : !>  (8) Wᶜ_ll′(q,iτ) = Σ_PQ Z_lP(q) Wᶜ_PQ(q,iτ) Z_l′Q(q)*,
      83              : !>      Wᶜ_ll′(R,iτ) = Re[Σ_q w_q exp(-iq·R) Wᶜ_ll′(q,iτ)] + ΔWᶜ_Γ,ll′(R,iτ).
      84              : !>
      85              : !>  (9) V_ll′(q) = Σ_PQ Z_lP(q) [K(q)K(q)†]_PQ Z_l′Q(q)*,
      86              : !>      V_ll′(R) = Re[Σ_q w_q exp(-iq·R) V_ll′(q)] + ΔV_Γ,ll′(R),
      87              : !>      Σˣ_ll′(R;σ) = -G^occ_ll′(R,0;σ) V_ll′(R).
      88              : !>
      89              : !> (10) Σˣ_ll′(k;σ) = Σ_R exp(ik·R) Σˣ_ll′(R;σ),
      90              : !>      Σˣ_nkσ = Σ_ll′ ψ_nkσ(r_l)* Σˣ_ll′(k;σ) ψ_nkσ(r_l′).
      91              : !>
      92              : !> (11) Σᶜ_ll′(R,-iτ;σ) = -G^occ_ll′(R,iτ;σ) Wᶜ_ll′(R,iτ),
      93              : !>      Σᶜ_ll′(R,+iτ;σ) = +G^vir_ll′(R,iτ;σ) Wᶜ_ll′(R,iτ).
      94              : !>
      95              : !> (12) Σᶜ_ll′(k,±iτ;σ) = Σ_R exp(ik·R) Σᶜ_ll′(R,±iτ;σ),
      96              : !>      Σᶜ_nkσ(±iτ) = Σ_ll′ ψ_nkσ(r_l)* Σᶜ_ll′(k,±iτ;σ) ψ_nkσ(r_l′),
      97              : !>      Σᶜ_nkσ(iω) = ∫_0^∞ dτ [exp(iωτ)Σᶜ_nkσ(+iτ)+exp(-iωτ)Σᶜ_nkσ(-iτ)].
      98              : !>      Analytic continuation gives Σᶜ at real energies for the quasiparticle equation.
      99              : !>
     100              : !> (13) ε^GW_nkσ = ε^DFT_nkσ + Σˣ_nkσ + Re Σᶜ_nkσ(ε^GW_nkσ) - vˣᶜ_nkσ.
     101              : !>      evGW₀ updates the energies entering G while retaining Wᶜ from the first cycle.
     102              : !>
     103              : !> Γ-point corrections are included as ΔWᶜ_Γ and ΔV_Γ; their construction is not shown here:
     104              : !> compute_G_and_chi prepares ΔWᶜ_Γ through gamma_point_correction.
     105              : !> compute_Sigma_c_from_W_PQ adds it to Wᶜ before forming Σᶜ.
     106              : !> compute_Sigma_x_from_V computes and applies ΔV_Γ via singular_head_cell_factors.
     107              : !>
     108              : !> \param qs_env Quickstep environment containing the converged SCF state.
     109              : !> \param bs_env Band-structure settings, orbitals, and quasiparticle results.
     110              : ! **************************************************************************************************
     111           14 :    SUBROUTINE gw_calc_ri_rs_small_cell_full_kp(qs_env, bs_env)
     112              :       TYPE(qs_environment_type), POINTER                 :: qs_env
     113              :       TYPE(post_scf_bandstructure_type), POINTER         :: bs_env
     114              : 
     115              :       CHARACTER(LEN=*), PARAMETER :: routineN = 'gw_calc_ri_rs_small_cell_full_kp'
     116              : 
     117              :       INTEGER                                            :: handle
     118              :       TYPE(gwkp_type), POINTER                           :: gwkp_env
     119              : 
     120           14 :       CALL timeset(routineN, handle)
     121              : 
     122           14 :       gwkp_env => bs_env%gwkp_env
     123              : 
     124              :       ! Sample AO/Bloch orbitals and fit the auxiliary functions: Eqs. (1)-(2).
     125           14 :       CALL prepare_ri_rs(bs_env, gwkp_env)
     126              : 
     127              :       ! G^occ/vir_ll′(R,iτ), χ_ll′(R,iτ), and χ_PQ(q,iω): Eqs. (3)-(6).
     128           14 :       CALL compute_G_and_chi(qs_env, bs_env, gwkp_env)
     129              : 
     130              :       ! Screen the Coulomb interaction and transform Wᶜ to imaginary time: Eqs. (7)-(8).
     131           14 :       CALL compute_W0(qs_env, bs_env, gwkp_env)
     132              : 
     133              :       ! Σˣ_ll′(R) and its projection onto target Bloch states: Eqs. (9)-(10).
     134           14 :       CALL compute_Sigma_x(bs_env, gwkp_env)
     135              : 
     136              :       ! Σᶜ_ll′(R,iτ), band projection, and quasiparticle equation: Eqs. (11)-(13).
     137           14 :       CALL compute_Sigma_c_and_QP(bs_env, gwkp_env)
     138              : 
     139           14 :       CALL release_gw_work(bs_env)
     140           14 :       NULLIFY (gwkp_env)
     141              : 
     142           14 :       CALL de_init_bs_env(qs_env, bs_env)
     143              : 
     144           14 :       CALL timestop(handle)
     145              : 
     146           14 :    END SUBROUTINE gw_calc_ri_rs_small_cell_full_kp
     147              : 
     148              : ! **************************************************************************************************
     149              : !> \brief Iterate Σᶜ and the QP equation, Eqs. (11)-(13), with fixed W₀.
     150              : !> G₀W₀ uses one cycle; evGW₀ feeds the QP energies back into G on the SCF mesh.
     151              : !> \param bs_env Band-structure settings and physical results.
     152              : !> \param gwkp_env Temporary periodic GW work data.
     153              : ! **************************************************************************************************
     154           14 :    SUBROUTINE compute_Sigma_c_and_QP(bs_env, gwkp_env)
     155              :       TYPE(post_scf_bandstructure_type), POINTER         :: bs_env
     156              :       TYPE(gwkp_type), INTENT(INOUT)                     :: gwkp_env
     157              : 
     158              :       CHARACTER(LEN=*), PARAMETER :: routineN = 'compute_Sigma_c_and_QP'
     159              : 
     160              :       INTEGER                                            :: handle, i_iter, ispin, n_mo, nkp
     161              :       REAL(dp)                                           :: cbm, e_fermi_scf(2), max_delta, vbm
     162           14 :       REAL(dp), ALLOCATABLE                              :: eigenvalues_G_next(:, :, :)
     163              : 
     164           14 :       CALL timeset(routineN, handle)
     165              : 
     166           14 :       nkp = bs_env%nkp_scf_desymm
     167           14 :       n_mo = bs_env%n_mo_retained
     168           42 :       e_fermi_scf = bs_env%e_fermi
     169           14 :       IF (bs_env%gw_flavour == evGW0) ALLOCATE (eigenvalues_G_next(n_mo, nkp, bs_env%n_spin))
     170              : 
     171              :       ! G₀W₀ takes one cycle. evGW₀ updates G on the SCF mesh while W₀ stays fixed.
     172           14 :       DO i_iter = 1, bs_env%evgw0_n_iter
     173           14 :          CALL compute_Sigma_c_from_W_PQ(bs_env, gwkp_env)
     174              :          CALL compute_QP_energies(bs_env, gwkp_env%sigma_x_bands, &
     175           14 :                                   gwkp_env%sigma_c_bands, i_iter)
     176           14 :          IF (bs_env%evgw0_n_iter == 1) EXIT
     177              : 
     178            0 :          IF (i_iter == 1) CALL print_first_cycle_band_edges(bs_env)
     179            0 :          CALL eigenvalues_for_evGW0_G(bs_env, eigenvalues_G_next)
     180              :          max_delta = MAXVAL(ABS(eigenvalues_G_next - &
     181            0 :                                 bs_env%eigenval_evGW0(1:n_mo, 1:nkp, 1:bs_env%n_spin)))
     182            0 :          IF (bs_env%unit_nr > 0) WRITE (bs_env%unit_nr, '(T2,A,I3,A,I3,A,T66,F12.4,A)') &
     183            0 :             'evGW0 cycle ', i_iter, ' / ', bs_env%evgw0_n_iter, &
     184            0 :             ' Max G eigenvalue change:', max_delta*evolt, ' eV'
     185            0 :          IF (max_delta < bs_env%evgw0_eps_iter) EXIT
     186            0 :          IF (i_iter == bs_env%evgw0_n_iter) THEN
     187            0 :             IF (bs_env%unit_nr > 0) WRITE (bs_env%unit_nr, '(T2,A)') &
     188            0 :                'evGW0 reached MAX_ITER before eigenvalue convergence.'
     189              :             EXIT
     190              :          END IF
     191              : 
     192            0 :          bs_env%eigenval_evGW0(1:n_mo, 1:nkp, 1:bs_env%n_spin) = eigenvalues_G_next
     193            0 :          gwkp_env%eigenvalues_G(1:n_mo, 1:nkp, 1:bs_env%n_spin) = eigenvalues_G_next
     194           14 :          DO ispin = 1, bs_env%n_spin
     195            0 :             vbm = MAXVAL(eigenvalues_G_next(bs_env%n_occ(ispin), :, ispin))
     196            0 :             cbm = MINVAL(eigenvalues_G_next(bs_env%n_occ(ispin) + 1, :, ispin))
     197            0 :             bs_env%e_fermi(ispin) = 0.5_dp*(vbm + cbm)
     198              :          END DO
     199              :       END DO
     200              : 
     201           14 :       CALL get_all_VBM_CBM_bandgaps(bs_env)
     202           14 :       IF (bs_env%gw_flavour == evGW0) bs_env%eigenval_evGW0(:, :, :) = bs_env%eigenval_GW
     203              :       ! G used an updated energy origin; subsequent post-SCF stages retain the SCF reference.
     204           42 :       bs_env%e_fermi = e_fermi_scf
     205              : 
     206           14 :       CALL timestop(handle)
     207              : 
     208           14 :    END SUBROUTINE compute_Sigma_c_and_QP
     209              : 
     210              : ! **************************************************************************************************
     211              : !> \brief Print scalar G0W0 extrema over the SCF mesh and requested band path.
     212              : !> The first QP solution is reported before updating G; W remains W0 throughout.
     213              : !> \param bs_env ...
     214              : ! **************************************************************************************************
     215            0 :    SUBROUTINE print_first_cycle_band_edges(bs_env)
     216              :       TYPE(post_scf_bandstructure_type), POINTER         :: bs_env
     217              : 
     218              :       CHARACTER(LEN=*), PARAMETER :: routineN = 'print_first_cycle_band_edges'
     219              : 
     220              :       INTEGER                                            :: handle, u
     221              :       TYPE(band_edges_type)                              :: band_edges
     222              : 
     223            0 :       CALL timeset(routineN, handle)
     224              : 
     225            0 :       CALL get_VBM_CBM_bandgaps(band_edges, bs_env%eigenval_GW, bs_env)
     226            0 :       u = bs_env%unit_nr
     227            0 :       IF (u > 0) THEN
     228            0 :          WRITE (u, '(T2,A)') 'G0W0 from the first evGW0 cycle (without SOC):'
     229            0 :          WRITE (u, '(T2,A,T61,F20.3)') 'G0W0 valence band maximum (eV):', band_edges%VBM*evolt
     230            0 :          WRITE (u, '(T2,A,T61,F20.3)') 'G0W0 conduction band minimum (eV):', band_edges%CBM*evolt
     231            0 :          WRITE (u, '(T2,A,T61,F20.3)') 'G0W0 indirect band gap (eV):', band_edges%IDBG*evolt
     232            0 :          WRITE (u, '(T2,A,T61,F20.3)') 'G0W0 direct band gap (eV):', band_edges%DBG*evolt
     233              :       END IF
     234              : 
     235            0 :       CALL timestop(handle)
     236              : 
     237            0 :    END SUBROUTINE print_first_cycle_band_edges
     238              : 
     239              : ! **************************************************************************************************
     240              : !> \brief Build the eigenvalues used by the next Green function from the current QP solution.
     241              : !> The 5 eV windows use the DFT VBM/CBM on the full SCF mesh, separately for each spin.
     242              : !> Outside them, a mean shift of the window states is applied at each k point and spin.
     243              : !> If a window is empty at one k point, its nearest band supplies the shift.
     244              : !> This approximation never changes the quasiparticle energies or the final band structure.
     245              : !> \param bs_env ...
     246              : !> \param eigenvalues_G_next ...
     247              : ! **************************************************************************************************
     248            0 :    SUBROUTINE eigenvalues_for_evGW0_G(bs_env, eigenvalues_G_next)
     249              :       TYPE(post_scf_bandstructure_type), POINTER         :: bs_env
     250              :       REAL(KIND=dp), INTENT(OUT)                         :: eigenvalues_G_next(:, :, :)
     251              : 
     252              :       CHARACTER(LEN=*), PARAMETER :: routineN = 'eigenvalues_for_evGW0_G'
     253              :       REAL(KIND=dp), PARAMETER                           :: window_ev = 5.0_dp
     254              : 
     255              :       INTEGER                                            :: handle, iband, ikp, ispin, n_mo, &
     256              :                                                             n_window, nkp, nocc
     257              :       REAL(KIND=dp)                                      :: cbm_dft, dft_energy, lower_limit, &
     258              :                                                             mean_shift, qp_energy, upper_limit, &
     259              :                                                             vbm_dft
     260              : 
     261            0 :       CALL timeset(routineN, handle)
     262              : 
     263            0 :       nkp = bs_env%nkp_scf_desymm
     264            0 :       n_mo = bs_env%n_mo_retained
     265            0 :       CPASSERT(bs_env%nkp_bs_and_DOS >= nkp)
     266            0 :       CPASSERT(n_mo > 0 .AND. n_mo <= bs_env%n_ao)
     267            0 :       CPASSERT(ALL(bs_env%n_occ(1:bs_env%n_spin) > 0))
     268            0 :       CPASSERT(ALL(bs_env%n_occ(1:bs_env%n_spin) < n_mo))
     269            0 :       DO ispin = 1, bs_env%n_spin
     270            0 :          nocc = bs_env%n_occ(ispin)
     271            0 :          vbm_dft = MAXVAL(bs_env%eigenval_scf(nocc, 1:nkp, ispin))
     272            0 :          cbm_dft = MINVAL(bs_env%eigenval_scf(nocc + 1, 1:nkp, ispin))
     273            0 :          lower_limit = vbm_dft - window_ev/evolt
     274            0 :          upper_limit = cbm_dft + window_ev/evolt
     275            0 :          DO ikp = 1, nkp
     276              :             mean_shift = 0.0_dp
     277              :             n_window = 0
     278            0 :             DO iband = 1, nocc
     279            0 :                dft_energy = bs_env%eigenval_scf(iband, ikp, ispin)
     280            0 :                IF (dft_energy < lower_limit) CYCLE
     281            0 :                qp_energy = bs_env%eigenval_GW(iband, ikp, ispin)
     282            0 :                eigenvalues_G_next(iband, ikp, ispin) = qp_energy
     283            0 :                mean_shift = mean_shift + qp_energy - dft_energy
     284            0 :                n_window = n_window + 1
     285              :             END DO
     286            0 :             IF (n_window > 0) THEN
     287            0 :                mean_shift = mean_shift/REAL(n_window, KIND=dp)
     288              :             ELSE
     289              :                mean_shift = bs_env%eigenval_GW(nocc, ikp, ispin) - &
     290            0 :                             bs_env%eigenval_scf(nocc, ikp, ispin)
     291              :             END IF
     292            0 :             DO iband = 1, nocc
     293            0 :                dft_energy = bs_env%eigenval_scf(iband, ikp, ispin)
     294            0 :                IF (dft_energy >= lower_limit) CYCLE
     295            0 :                eigenvalues_G_next(iband, ikp, ispin) = dft_energy + mean_shift
     296              :             END DO
     297              : 
     298              :             mean_shift = 0.0_dp
     299              :             n_window = 0
     300            0 :             DO iband = nocc + 1, n_mo
     301            0 :                dft_energy = bs_env%eigenval_scf(iband, ikp, ispin)
     302            0 :                IF (dft_energy > upper_limit) CYCLE
     303            0 :                qp_energy = bs_env%eigenval_GW(iband, ikp, ispin)
     304            0 :                eigenvalues_G_next(iband, ikp, ispin) = qp_energy
     305            0 :                mean_shift = mean_shift + qp_energy - dft_energy
     306            0 :                n_window = n_window + 1
     307              :             END DO
     308            0 :             IF (n_window > 0) THEN
     309            0 :                mean_shift = mean_shift/REAL(n_window, KIND=dp)
     310              :             ELSE
     311              :                mean_shift = bs_env%eigenval_GW(nocc + 1, ikp, ispin) - &
     312            0 :                             bs_env%eigenval_scf(nocc + 1, ikp, ispin)
     313              :             END IF
     314            0 :             DO iband = nocc + 1, n_mo
     315            0 :                dft_energy = bs_env%eigenval_scf(iband, ikp, ispin)
     316            0 :                IF (dft_energy <= upper_limit) CYCLE
     317            0 :                eigenvalues_G_next(iband, ikp, ispin) = dft_energy + mean_shift
     318              :             END DO
     319              :          END DO
     320              :       END DO
     321              : 
     322            0 :       CALL timestop(handle)
     323              : 
     324            0 :    END SUBROUTINE eigenvalues_for_evGW0_G
     325              : 
     326              : ! **************************************************************************************************
     327              : !> \brief Transform band self-energies and solve the quasiparticle equations.
     328              : !> \param bs_env ...
     329              : !> \param sigma_x_bands ...
     330              : !> \param sigma_c_bands ...
     331              : !> \param i_iter Local GW cycle used in the spectrum output.
     332              : ! **************************************************************************************************
     333           14 :    SUBROUTINE compute_QP_energies(bs_env, sigma_x_bands, sigma_c_bands, i_iter)
     334              :       TYPE(post_scf_bandstructure_type), POINTER         :: bs_env
     335              :       REAL(KIND=dp), INTENT(IN)                          :: sigma_x_bands(:, :, :), &
     336              :                                                             sigma_c_bands(:, :, :, :, :)
     337              :       INTEGER, INTENT(IN)                                :: i_iter
     338              : 
     339              :       CHARACTER(LEN=*), PARAMETER :: routineN = 'compute_QP_energies'
     340              : 
     341              :       COMPLEX(KIND=dp), ALLOCATABLE                      :: Sigma_c_ikp_n_freq(:, :)
     342              :       INTEGER                                            :: handle, ikp, ispin
     343              :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:)           :: Sigma_x_ikp_n
     344              :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :, :)     :: Sigma_c_ikp_n_time
     345              :       TYPE(gw_qp_summary_type)                           :: qp_summary
     346              : 
     347           14 :       CALL timeset(routineN, handle)
     348           14 :       CPASSERT(SIZE(sigma_x_bands, 1) == bs_env%n_ao)
     349           14 :       CPASSERT(SIZE(sigma_x_bands, 2) == bs_env%nkp_bs_and_DOS)
     350           14 :       CPASSERT(SIZE(sigma_x_bands, 3) == bs_env%n_spin)
     351           14 :       CPASSERT(SIZE(sigma_c_bands, 1) == bs_env%n_ao)
     352           14 :       CPASSERT(SIZE(sigma_c_bands, 2) == bs_env%nkp_bs_and_DOS)
     353           14 :       CPASSERT(SIZE(sigma_c_bands, 3) == bs_env%num_time_freq_points)
     354           14 :       CPASSERT(SIZE(sigma_c_bands, 4) == 2)
     355           14 :       CPASSERT(SIZE(sigma_c_bands, 5) == bs_env%n_spin)
     356              : 
     357           42 :       ALLOCATE (Sigma_x_ikp_n(bs_env%n_ao))
     358           70 :       ALLOCATE (Sigma_c_ikp_n_time(bs_env%n_ao, bs_env%num_time_freq_points, 2))
     359           56 :       ALLOCATE (Sigma_c_ikp_n_freq(bs_env%n_ao, bs_env%num_freq_points_fit))
     360              : 
     361           14 :       qp_summary%n_kpoints = bs_env%nkp_bs_and_DOS
     362           28 :       DO ispin = 1, bs_env%n_spin
     363              : 
     364          318 :          DO ikp = 1, bs_env%nkp_bs_and_DOS
     365              : 
     366              :             ! 1. Σ^x_nn(k) and Σ^c_nn(k,±i|τ_j|), projected in compute_Sigma_x / compute_Sigma_c
     367         1822 :             Sigma_x_ikp_n(:) = sigma_x_bands(:, ikp, ispin)
     368       109990 :             Sigma_c_ikp_n_time(:, :, :) = sigma_c_bands(:, ikp, :, :, ispin)
     369              : 
     370              :             ! 2. Σ^c_nn(k_i,iω) = ∫ from -∞ to ∞ dτ e^-iωτ Σ^c_nn(k_i,iτ)
     371          290 :             CALL transform_time_to_frequency(bs_env%time_frequency_grid_sigma, Sigma_c_ikp_n_time, Sigma_c_ikp_n_freq)
     372        16354 :             Sigma_c_ikp_n_freq(1:bs_env%n_occ(ispin), :) = CONJG(Sigma_c_ikp_n_freq(1:bs_env%n_occ(ispin), :))
     373              : 
     374              :             ! 3. Analytic continuation Σ^c_nn(k_i,iω) -> Σ^c_nn(k_i,ϵ) and
     375              :             !    ϵ_nk_i^GW = ϵ_nk_i^DFT + Σ^c_nn(k_i,ϵ) + Σ^x_nn(k_i) - v^xc_nn(k_i)
     376              :             CALL analyt_conti_and_print(bs_env, &
     377              :                                         Sigma_c_ikp_n_freq, &
     378              :                                         Sigma_x_ikp_n, &
     379              :                                         bs_env%v_xc_n(:, ikp, ispin), &
     380          304 :                                         bs_env%eigenval_scf(:, ikp, ispin), ikp, ispin, qp_summary, i_iter)
     381              : 
     382              :          END DO ! ikp
     383              : 
     384              :       END DO ! ispin
     385              : 
     386           14 :       CALL timestop(handle)
     387              : 
     388           28 :    END SUBROUTINE compute_QP_energies
     389              : 
     390              : END MODULE gw_ri_rs_small_cell_full_kp
        

Generated by: LCOV version 2.0-1