(git:f664ec6)
Loading...
Searching...
No Matches
bse_main.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 Main routines for GW + Bethe-Salpeter for computing electronic excitations
10!> \par History
11!> 04.2024 created [Maximilian Graml]
12! **************************************************************************************************
13
15
16 USE bse_full_diag, ONLY: create_a,&
17 create_b,&
31 USE cp_fm_types, ONLY: cp_fm_release,&
37 USE input_constants, ONLY: bse_abba,&
38 bse_both,&
44 USE kinds, ONLY: dp
46 USE mp2_types, ONLY: mp2_type
49#include "./base/base_uses.f90"
50
51 IMPLICIT NONE
52
53 PRIVATE
54
55 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'bse_main'
56
57 PUBLIC :: start_bse_calculation
58
59CONTAINS
60
61! **************************************************************************************************
62!> \brief Main subroutine managing BSE calculations
63!> \param fm_mat_S_ia_bse ...
64!> \param fm_mat_S_ij_bse ...
65!> \param fm_mat_S_ab_bse ...
66!> \param fm_mat_Q_static_bse_gemm ...
67!> \param Eigenval ...
68!> \param Eigenval_scf ...
69!> \param homo ...
70!> \param virtual ...
71!> \param dimen_RI ...
72!> \param dimen_RI_red ...
73!> \param bse_lev_virt ...
74!> \param gd_array ...
75!> \param color_sub ...
76!> \param mp2_env ...
77!> \param qs_env ...
78!> \param mo_coeff ...
79!> \param unit_nr ...
80! **************************************************************************************************
81 SUBROUTINE start_bse_calculation(fm_mat_S_ia_bse, fm_mat_S_ij_bse, fm_mat_S_ab_bse, &
82 fm_mat_Q_static_bse_gemm, &
83 Eigenval, Eigenval_scf, &
84 homo, virtual, dimen_RI, dimen_RI_red, bse_lev_virt, &
85 gd_array, color_sub, mp2_env, qs_env, mo_coeff, unit_nr)
86
87 TYPE(cp_fm_type), INTENT(IN) :: fm_mat_s_ia_bse, fm_mat_s_ij_bse, &
88 fm_mat_s_ab_bse
89 TYPE(cp_fm_type), INTENT(INOUT) :: fm_mat_q_static_bse_gemm
90 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :, :), &
91 INTENT(IN) :: eigenval, eigenval_scf
92 INTEGER, DIMENSION(:), INTENT(IN) :: homo, virtual
93 INTEGER, INTENT(IN) :: dimen_ri, dimen_ri_red, bse_lev_virt
94 TYPE(group_dist_d1_type), INTENT(IN) :: gd_array
95 INTEGER, INTENT(IN) :: color_sub
96 TYPE(mp2_type) :: mp2_env
97 TYPE(qs_environment_type), POINTER :: qs_env
98 TYPE(cp_fm_type), DIMENSION(:), INTENT(IN) :: mo_coeff
99 INTEGER, INTENT(IN) :: unit_nr
100
101 CHARACTER(LEN=*), PARAMETER :: routinen = 'start_bse_calculation'
102
103 INTEGER :: handle, homo_red, virtual_red
104 LOGICAL :: my_do_abba, my_do_fulldiag, &
105 my_do_iterat_diag, my_do_tda
106 REAL(kind=dp) :: diag_runtime_est
107 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: eigenval_reduced
108 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :, :) :: b_abq_bse_local, b_bar_iaq_bse_local, &
109 b_bar_ijq_bse_local, b_iaq_bse_local
110 TYPE(cp_fm_type) :: fm_a_bse, fm_b_bse, fm_c_bse, fm_inv_sqrt_a_minus_b, fm_mat_s_ab_trunc, &
111 fm_mat_s_bar_ia_bse, fm_mat_s_bar_ij_bse, fm_mat_s_ia_trunc, fm_mat_s_ij_trunc, &
112 fm_sqrt_a_minus_b
113 TYPE(cp_logger_type), POINTER :: logger
114 TYPE(dft_control_type), POINTER :: dft_control
115 TYPE(mp_para_env_type), POINTER :: para_env
116 TYPE(tddfpt2_control_type), POINTER :: tddfpt_control
117
118 CALL timeset(routinen, handle)
119
120 para_env => fm_mat_s_ia_bse%matrix_struct%para_env
121
122 my_do_fulldiag = .false.
123 my_do_iterat_diag = .false.
124 my_do_tda = .false.
125 my_do_abba = .false.
126 !Method: Iterative or full diagonalization
127 SELECT CASE (mp2_env%bse%bse_diag_method)
128 CASE (bse_iterdiag)
129 my_do_iterat_diag = .true.
130 !MG: Basics of the Davidson solver are implemented, but not rigorously checked.
131 cpabort("Iterative BSE not yet implemented")
132 CASE (bse_fulldiag)
133 my_do_fulldiag = .true.
134 END SELECT
135 !Approximation: TDA and/or full ABBA matrix
136 SELECT CASE (mp2_env%bse%flag_tda)
137 CASE (bse_tda)
138 my_do_tda = .true.
139 CASE (bse_abba)
140 my_do_abba = .true.
141 CASE (bse_both)
142 my_do_tda = .true.
143 my_do_abba = .true.
144 END SELECT
145
146 CALL print_bse_start_flag(my_do_tda, my_do_abba, unit_nr)
147
148 ! Link BSE debug flag against debug print level
149 logger => cp_get_default_logger()
150 IF (logger%iter_info%print_level == debug_print_level) THEN
151 mp2_env%bse%bse_debug_print = .true.
152 END IF
153
154 CALL fm_mat_s_ia_bse%matrix_struct%para_env%sync()
155 ! We apply the BSE cutoffs using the DFT Eigenenergies
156 ! Reduce matrices in case of energy cutoff for occupied and unoccupied in A/B-BSE-matrices
157 CALL truncate_bse_matrices(fm_mat_s_ia_bse, fm_mat_s_ij_bse, fm_mat_s_ab_bse, &
158 fm_mat_s_ia_trunc, fm_mat_s_ij_trunc, fm_mat_s_ab_trunc, &
159 eigenval_scf(:, 1, 1), eigenval(:, 1, 1), eigenval_reduced, &
160 homo(1), virtual(1), dimen_ri, unit_nr, &
161 bse_lev_virt, &
162 homo_red, virtual_red, &
163 mp2_env)
164 ! \bar{B}^P_rs = \sum_R W_PR B^R_rs where B^R_rs = \sum_T [1/sqrt(v)]_RT (T|rs)
165 ! r,s: MO-index, P,R,T: RI-index
166 ! B: fm_mat_S_..., W: fm_mat_Q_...
167 CALL mult_b_with_w(fm_mat_s_ij_trunc, fm_mat_s_ia_trunc, fm_mat_s_bar_ia_bse, &
168 fm_mat_s_bar_ij_bse, fm_mat_q_static_bse_gemm, &
169 dimen_ri_red, homo_red, virtual_red)
170
171 IF (my_do_iterat_diag) THEN
172 CALL fill_local_3c_arrays(fm_mat_s_ab_trunc, fm_mat_s_ia_trunc, &
173 fm_mat_s_bar_ia_bse, fm_mat_s_bar_ij_bse, &
174 b_bar_ijq_bse_local, b_abq_bse_local, b_bar_iaq_bse_local, &
175 b_iaq_bse_local, dimen_ri_red, homo_red, virtual_red, &
176 gd_array, color_sub, para_env)
177 END IF
178
179 CALL adapt_bse_input_params(homo_red, virtual_red, unit_nr, mp2_env, qs_env)
180
181 IF (my_do_fulldiag) THEN
182 ! Quick estimate of memory consumption and runtime of diagonalizations
183 CALL estimate_bse_resources(homo_red, virtual_red, unit_nr, my_do_abba, &
184 para_env, diag_runtime_est)
185 ! Matrix A constructed from GW energies and 3c-B-matrices (cf. subroutine mult_B_with_W)
186 ! A_ia,jb = (ε_a-ε_i) δ_ij δ_ab + α * v_ia,jb - W_ij,ab
187 ! ε_a, ε_i are GW singleparticle energies from Eigenval_reduced
188 ! α is a spin-dependent factor
189 ! v_ia,jb = \sum_P B^P_ia B^P_jb (unscreened Coulomb interaction)
190 ! W_ij,ab = \sum_P \bar{B}^P_ij B^P_ab (screened Coulomb interaction)
191
192 ! For unscreened W matrix, we need fm_mat_S_ij_trunc
193 IF (mp2_env%bse%screening_method == bse_screening_tdhf .OR. &
194 mp2_env%bse%screening_method == bse_screening_alpha) THEN
195 CALL create_a(fm_mat_s_ia_trunc, fm_mat_s_ij_trunc, fm_mat_s_ab_trunc, &
196 fm_a_bse, eigenval_reduced, unit_nr, &
197 homo_red, virtual_red, dimen_ri, mp2_env, &
198 para_env, qs_env)
199 ELSE
200 CALL create_a(fm_mat_s_ia_trunc, fm_mat_s_bar_ij_bse, fm_mat_s_ab_trunc, &
201 fm_a_bse, eigenval_reduced, unit_nr, &
202 homo_red, virtual_red, dimen_ri, mp2_env, &
203 para_env, qs_env)
204 END IF
205 IF (my_do_abba) THEN
206 ! Matrix B constructed from 3c-B-matrices (cf. subroutine mult_B_with_W)
207 ! B_ia,jb = α * v_ia,jb - W_ib,aj
208 ! α is a spin-dependent factor
209 ! v_ia,jb = \sum_P B^P_ia B^P_jb (unscreened Coulomb interaction)
210 ! W_ib,aj = \sum_P \bar{B}^P_ib B^P_aj (screened Coulomb interaction)
211
212 ! For unscreened W matrix, we need fm_mat_S_ia_trunc
213 IF (mp2_env%bse%screening_method == bse_screening_tdhf .OR. &
214 mp2_env%bse%screening_method == bse_screening_alpha) THEN
215 CALL create_b(fm_mat_s_ia_trunc, fm_mat_s_ia_trunc, fm_b_bse, &
216 homo_red, virtual_red, dimen_ri, unit_nr, mp2_env)
217 ELSE
218 CALL create_b(fm_mat_s_ia_trunc, fm_mat_s_bar_ia_bse, fm_b_bse, &
219 homo_red, virtual_red, dimen_ri, unit_nr, mp2_env)
220 END IF
221 ! Construct Matrix C=(A-B)^0.5 (A+B) (A-B)^0.5 to solve full BSE matrix as a hermitian problem
222 ! (cf. Eq. (A7) in F. Furche J. Chem. Phys., Vol. 114, No. 14, (2001)).
223 ! We keep fm_sqrt_A_minus_B and fm_inv_sqrt_A_minus_B for print of singleparticle transitions
224 ! of ABBA as described in Eq. (A10) in F. Furche J. Chem. Phys., Vol. 114, No. 14, (2001).
225 CALL create_hermitian_form_of_abba(fm_a_bse, fm_b_bse, fm_c_bse, &
226 fm_sqrt_a_minus_b, fm_inv_sqrt_a_minus_b, &
227 homo_red, virtual_red, unit_nr, mp2_env, diag_runtime_est)
228 END IF
229 CALL cp_fm_release(fm_b_bse)
230
231 NULLIFY (dft_control, tddfpt_control)
232 CALL get_qs_env(qs_env, dft_control=dft_control)
233 tddfpt_control => dft_control%tddfpt2_control
234 IF ((my_do_tda) .AND. (.NOT. tddfpt_control%do_bse)) THEN
235 ! Solving the hermitian eigenvalue equation A X^n = Ω^n X^n
236 CALL diagonalize_a(fm_a_bse, homo_red, virtual_red, homo(1), &
237 unit_nr, diag_runtime_est, mp2_env, qs_env, mo_coeff)
238 END IF
239 ! Release to avoid faulty use of changed A matrix
240 CALL cp_fm_release(fm_a_bse)
241 IF (my_do_abba) THEN
242 ! Solving eigenvalue equation C Z^n = (Ω^n)^2 Z^n .
243 ! Here, the eigenvectors Z^n relate to X^n via
244 ! Eq. (A10) in F. Furche J. Chem. Phys., Vol. 114, No. 14, (2001).
245 CALL diagonalize_c(fm_c_bse, homo_red, virtual_red, homo(1), &
246 fm_sqrt_a_minus_b, fm_inv_sqrt_a_minus_b, &
247 unit_nr, diag_runtime_est, mp2_env, qs_env, mo_coeff)
248 END IF
249 ! Release to avoid faulty use of changed C matrix
250 CALL cp_fm_release(fm_c_bse)
251 END IF
252
253 CALL deallocate_matrices_bse(fm_mat_s_bar_ia_bse, fm_mat_s_bar_ij_bse, &
254 fm_mat_s_ia_trunc, fm_mat_s_ij_trunc, fm_mat_s_ab_trunc, &
255 fm_mat_q_static_bse_gemm, mp2_env)
256 DEALLOCATE (eigenval_reduced)
257 IF (my_do_iterat_diag) THEN
258 ! Contains untested Block-Davidson algorithm
259 CALL do_subspace_iterations(b_bar_ijq_bse_local, b_abq_bse_local, b_bar_iaq_bse_local, &
260 b_iaq_bse_local, homo(1), virtual(1), mp2_env%bse%bse_spin_config, unit_nr, &
261 eigenval(:, 1, 1), para_env, mp2_env)
262 ! Deallocate local 3c-B-matrices
263 DEALLOCATE (b_bar_ijq_bse_local, b_abq_bse_local, b_bar_iaq_bse_local, b_iaq_bse_local)
264 END IF
265
266 IF (unit_nr > 0) THEN
267 WRITE (unit_nr, '(T2,A4,T7,A53)') 'BSE|', 'The BSE was successfully calculated. Have a nice day!'
268 END IF
269
270 CALL timestop(handle)
271
272 END SUBROUTINE start_bse_calculation
273
274END MODULE bse_main
Routines for the full diagonalization of GW + Bethe-Salpeter for computing electronic excitations.
subroutine, public diagonalize_a(fm_a, homo, virtual, homo_irred, unit_nr, diag_est, mp2_env, qs_env, mo_coeff)
Solving hermitian eigenvalue equation A X^n = Ω^n X^n.
subroutine, public diagonalize_c(fm_c, homo, virtual, homo_irred, fm_sqrt_a_minus_b, fm_inv_sqrt_a_minus_b, unit_nr, diag_est, mp2_env, qs_env, mo_coeff)
Solving eigenvalue equation C Z^n = (Ω^n)^2 Z^n . Here, the eigenvectors Z^n relate to X^n via Eq....
subroutine, public create_b(fm_mat_s_ia_bse, fm_mat_s_bar_ia_bse, fm_b, homo, virtual, dimen_ri, unit_nr, mp2_env)
Matrix B constructed from 3c-B-matrices (cf. subroutine mult_B_with_W) B_ia,jb = α * v_ia,...
subroutine, public create_hermitian_form_of_abba(fm_a, fm_b, fm_c, fm_sqrt_a_minus_b, fm_inv_sqrt_a_minus_b, homo, virtual, unit_nr, mp2_env, diag_est)
Construct Matrix C=(A-B)^0.5 (A+B) (A-B)^0.5 to solve full BSE matrix as a hermitian problem (cf....
subroutine, public create_a(fm_mat_s_ia_bse, fm_mat_s_bar_ij_bse, fm_mat_s_ab_bse, fm_a, eigenval, unit_nr, homo, virtual, dimen_ri, mp2_env, para_env, qs_env)
Matrix A constructed from GW energies and 3c-B-matrices (cf. subroutine mult_B_with_W) A_ia,...
Iterative routines for GW + Bethe-Salpeter for computing electronic excitations.
subroutine, public do_subspace_iterations(b_bar_ijq_bse_local, b_abq_bse_local, b_bar_iaq_bse_local, b_iaq_bse_local, homo, virtual, bse_spin_config, unit_nr, eigenval, para_env, mp2_env)
...
subroutine, public fill_local_3c_arrays(fm_mat_s_ab_bse, fm_mat_s, fm_mat_s_bar_ia_bse, fm_mat_s_bar_ij_bse, b_bar_ijq_bse_local, b_abq_bse_local, b_bar_iaq_bse_local, b_iaq_bse_local, dimen_ri, homo, virtual, gd_array, color_sub, para_env)
...
Main routines for GW + Bethe-Salpeter for computing electronic excitations.
Definition bse_main.F:14
subroutine, public start_bse_calculation(fm_mat_s_ia_bse, fm_mat_s_ij_bse, fm_mat_s_ab_bse, fm_mat_q_static_bse_gemm, eigenval, eigenval_scf, homo, virtual, dimen_ri, dimen_ri_red, bse_lev_virt, gd_array, color_sub, mp2_env, qs_env, mo_coeff, unit_nr)
Main subroutine managing BSE calculations.
Definition bse_main.F:86
Routines for printing information in context of the BSE calculation.
Definition bse_print.F:13
subroutine, public print_bse_start_flag(bse_tda, bse_abba, unit_nr)
...
Definition bse_print.F:53
Auxiliary routines for GW + Bethe-Salpeter for computing electronic excitations.
Definition bse_util.F:13
subroutine, public estimate_bse_resources(homo_red, virtual_red, unit_nr, bse_abba, para_env, diag_runtime_est)
Roughly estimates the needed runtime and memory during the BSE run.
Definition bse_util.F:936
subroutine, public deallocate_matrices_bse(fm_mat_s_bar_ia_bse, fm_mat_s_bar_ij_bse, fm_mat_s_trunc, fm_mat_s_ij_trunc, fm_mat_s_ab_trunc, fm_mat_q_static_bse_gemm, mp2_env)
...
Definition bse_util.F:752
subroutine, public mult_b_with_w(fm_mat_s_ij_bse, fm_mat_s_ia_bse, fm_mat_s_bar_ia_bse, fm_mat_s_bar_ij_bse, fm_mat_q_static_bse_gemm, dimen_ri, homo, virtual)
Multiplies B-matrix (RI-3c-Integrals) with W (screening) to obtain \bar{B}.
Definition bse_util.F:113
subroutine, public adapt_bse_input_params(homo, virtual, unit_nr, mp2_env, qs_env)
Checks BSE input section and adapts them if necessary.
Definition bse_util.F:1520
subroutine, public truncate_bse_matrices(fm_mat_s_ia_bse, fm_mat_s_ij_bse, fm_mat_s_ab_bse, fm_mat_s_trunc, fm_mat_s_ij_trunc, fm_mat_s_ab_trunc, eigenval_scf, eigenval, eigenval_reduced, homo, virtual, dimen_ri, unit_nr, bse_lev_virt, homo_red, virt_red, mp2_env)
Determines indices within the given energy cutoffs and truncates Eigenvalues and matrices.
Definition bse_util.F:1211
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
represent a full matrix distributed on many processors
Definition cp_fm_types.F:15
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...
integer, parameter, public debug_print_level
Types to describe group distributions.
collects all constants needed in input so that they can be used without circular dependencies
integer, parameter, public bse_screening_tdhf
integer, parameter, public bse_iterdiag
integer, parameter, public bse_fulldiag
integer, parameter, public bse_tda
integer, parameter, public bse_both
integer, parameter, public bse_screening_alpha
integer, parameter, public bse_abba
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
Interface to the message passing library MPI.
Types needed for MP2 calculations.
Definition mp2_types.F:14
subroutine, public get_qs_env(qs_env, atomic_kind_set, qs_kind_set, cell, super_cell, cell_ref, use_ref_cell, kpoints, dft_control, mos, sab_orb, sab_all, qmmm, qmmm_periodic, mimic, sac_ae, sac_ppl, sac_lri, sap_ppnl, sab_vdw, sab_scp, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, sab_xb, sab_xtb_pp, sab_xtb_nonbond, sab_almo, sab_kp, sab_kp_nosym, sab_cneo, particle_set, energy, force, matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, run_rtp, rtp, matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_ks_im_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, matrix_s_ri_aux_kp, matrix_s, matrix_s_ri_aux, matrix_w, matrix_p_mp2, matrix_p_mp2_admm, rho, rho_xc, pw_env, ewald_env, ewald_pw, active_space, mpools, input, para_env, blacs_env, scf_control, rel_control, kinetic, qs_charges, vppl, xcint_weights, rho_core, rho_nlcc, rho_nlcc_g, ks_env, ks_qmmm_env, wf_history, scf_env, local_particles, local_molecules, distribution_2d, dbcsr_dist, molecule_kind_set, molecule_set, subsys, cp_subsys, oce, local_rho_set, rho_atom_set, task_list, task_list_soft, rho0_atom_set, rho0_mpole, rhoz_set, rhoz_cneo_set, ecoul_1c, rho0_s_rs, rho0_s_gs, rhoz_cneo_s_rs, rhoz_cneo_s_gs, do_kpoints, has_unit_metric, requires_mo_derivs, mo_derivs, mo_loc_history, nkind, natom, nelectron_total, nelectron_spin, efield, neighbor_list_id, linres_control, xas_env, virial, cp_ddapc_env, cp_ddapc_ewald, outer_scf_history, outer_scf_ihistory, x_data, et_coupling, dftb_potential, results, se_taper, se_store_int_env, se_nddo_mpole, se_nonbond_env, admm_env, lri_env, lri_density, exstate_env, ec_env, harris_env, dispersion_env, gcp_env, vee, rho_external, external_vxc, mask, mp2_env, bs_env, kg_env, wanniercentres, atprop, ls_scf_env, do_transport, transport_env, v_hartree_rspace, s_mstruct_changed, rho_changed, potential_changed, forces_up_to_date, mscfg_env, almo_scf_env, gradient_history, variable_history, embed_pot, spin_embed_pot, polar_env, mos_last_converged, eeq, rhs, do_rixs, tb_tblite)
Get the QUICKSTEP environment.
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...
stores all the informations relevant to an mpi environment