Line data Source code
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 Routines for computing excitonic properties, e.g. exciton diameter, from the BSE
10 : !> \par History
11 : !> 10.2024 created [Maximilian Graml]
12 : ! **************************************************************************************************
13 : MODULE bse_properties
14 : USE bse_util, ONLY: fm_general_add_bse,&
15 : print_bse_nto_cubes,&
16 : reshuffle_eigvec,&
17 : trace_exciton_descr
18 : USE cp_files, ONLY: close_file,&
19 : open_file
20 : USE cp_fm_basic_linalg, ONLY: cp_fm_scale_and_add,&
21 : cp_fm_trace
22 : USE cp_fm_diag, ONLY: cp_fm_svd
23 : USE cp_fm_struct, ONLY: cp_fm_struct_create,&
24 : cp_fm_struct_release,&
25 : cp_fm_struct_type
26 : USE cp_fm_types, ONLY: cp_fm_create,&
27 : cp_fm_get_submatrix,&
28 : cp_fm_release,&
29 : cp_fm_set_all,&
30 : cp_fm_to_fm,&
31 : cp_fm_to_fm_submat,&
32 : cp_fm_to_fm_submat_general,&
33 : cp_fm_type
34 : USE cp_log_handling, ONLY: cp_get_default_logger,&
35 : cp_logger_get_default_unit_nr,&
36 : cp_logger_type
37 : USE input_section_types, ONLY: section_vals_get_subs_vals,&
38 : section_vals_type,&
39 : section_vals_val_get
40 : USE kinds, ONLY: dp
41 : USE mathconstants, ONLY: pi
42 : USE mp2_types, ONLY: mp2_type
43 : USE parallel_gemm_api, ONLY: parallel_gemm
44 : USE physcon, ONLY: c_light_au,&
45 : evolt
46 : USE qs_environment_types, ONLY: get_qs_env,&
47 : qs_environment_type
48 : USE qs_mo_types, ONLY: allocate_mo_set,&
49 : deallocate_mo_set,&
50 : init_mo_set,&
51 : mo_set_type
52 : #include "./base/base_uses.f90"
53 :
54 : IMPLICIT NONE
55 :
56 : PRIVATE
57 :
58 : CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'bse_properties'
59 :
60 : PUBLIC :: exciton_descr_type
61 :
62 : PUBLIC :: get_exciton_descriptors, get_oscillator_strengths, compute_and_print_absorption_spectrum, &
63 : calculate_NTOs
64 :
65 : ! TYPE definitions for exciton wavefunction descriptors
66 :
67 : TYPE exciton_descr_type
68 : REAL(KIND=dp), DIMENSION(3) :: r_e = 0.0_dp, &
69 : r_h = 0.0_dp, &
70 : r_e_sq = 0.0_dp, &
71 : r_h_sq = 0.0_dp, &
72 : r_e_h = 0.0_dp, &
73 : r_e_shift = 0.0_dp, &
74 : r_h_shift = 0.0_dp, &
75 : cov_e_h = 0.0_dp
76 : REAL(KIND=dp) :: sigma_e = 0.0_dp, &
77 : sigma_h = 0.0_dp, &
78 : cov_e_h_sum = 0.0_dp, &
79 : corr_e_h = 0.0_dp, &
80 : diff_r_abs = 0.0_dp, &
81 : diff_r_sqr = 0.0_dp, &
82 : norm_XpY = 0.0_dp
83 : LOGICAL :: flag_TDA = .FALSE.
84 : END TYPE exciton_descr_type
85 :
86 : CONTAINS
87 :
88 : ! **************************************************************************************************
89 : !> \brief Compute and return BSE dipoles d_r^n = sqrt(2) sum_ia < ψ_i | r | ψ_a > ( X_ia^n + Y_ia^n )
90 : !> and oscillator strengths f^n = 2/3 * Ω^n sum_r∈(x,y,z) ( d_r^n )^2
91 : !> Prelim Ref.: Eqs. (23), (24)
92 : !> in J. Chem. Phys. 152, 044105 (2020); https://doi.org/10.1063/1.5123290
93 : !> \param fm_eigvec_X ...
94 : !> \param Exc_ens ...
95 : !> \param fm_dipole_ai_trunc ...
96 : !> \param trans_mom_bse BSE dipole vectors in real space per excitation level
97 : !> \param oscill_str Oscillator strength per excitation level
98 : !> \param polarizability_residues Residues of polarizability ("tensorial oscillator strength")
99 : !> per excitation level
100 : !> \param mp2_env ...
101 : !> \param homo_red ...
102 : !> \param virtual_red ...
103 : !> \param unit_nr ...
104 : !> \param fm_eigvec_Y ...
105 : ! **************************************************************************************************
106 30 : SUBROUTINE get_oscillator_strengths(fm_eigvec_X, Exc_ens, fm_dipole_ai_trunc, &
107 : trans_mom_bse, oscill_str, polarizability_residues, &
108 : mp2_env, homo_red, virtual_red, unit_nr, &
109 : fm_eigvec_Y)
110 :
111 : TYPE(cp_fm_type), INTENT(IN) :: fm_eigvec_X
112 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:), &
113 : INTENT(IN) :: Exc_ens
114 : TYPE(cp_fm_type), DIMENSION(3) :: fm_dipole_ai_trunc
115 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :, :), &
116 : INTENT(OUT) :: trans_mom_bse
117 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:), &
118 : INTENT(OUT) :: oscill_str
119 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :, :), &
120 : INTENT(OUT) :: polarizability_residues
121 : TYPE(mp2_type), INTENT(IN) :: mp2_env
122 : INTEGER, INTENT(IN) :: homo_red, virtual_red, unit_nr
123 : TYPE(cp_fm_type), INTENT(IN), OPTIONAL :: fm_eigvec_Y
124 :
125 : CHARACTER(LEN=*), PARAMETER :: routineN = 'get_oscillator_strengths'
126 :
127 : INTEGER :: handle, idir, jdir, n
128 : TYPE(cp_fm_struct_type), POINTER :: fm_struct_dipole_MO_trunc_reordered, &
129 : fm_struct_trans_mom_bse
130 : TYPE(cp_fm_type) :: fm_eigvec_XYsum
131 120 : TYPE(cp_fm_type), DIMENSION(3) :: fm_dipole_MO_trunc_reordered, &
132 240 : fm_dipole_per_dir, fm_trans_mom_bse
133 :
134 30 : CALL timeset(routineN, handle)
135 :
136 : CALL cp_fm_struct_create(fm_struct_dipole_MO_trunc_reordered, fm_eigvec_X%matrix_struct%para_env, &
137 30 : fm_eigvec_X%matrix_struct%context, 1, homo_red*virtual_red)
138 : CALL cp_fm_struct_create(fm_struct_trans_mom_bse, fm_eigvec_X%matrix_struct%para_env, &
139 30 : fm_eigvec_X%matrix_struct%context, 1, homo_red*virtual_red)
140 :
141 : ! Include excitonic amplitudes in dipoles, i.e. obtain "BSE dipoles":
142 : ! \vec{D}_n = sqrt(2) * sum_{i,a} \vec{D}_ai (X_{ai}^{(n)} + Y_{ai}^{(n)})
143 :
144 : ! Reorder dipoles in order to execute the sum over i and a by parallel gemm
145 120 : DO idir = 1, 3
146 : CALL cp_fm_create(fm_dipole_MO_trunc_reordered(idir), matrix_struct=fm_struct_dipole_MO_trunc_reordered, &
147 90 : name="dipoles_mo_reordered")
148 90 : CALL cp_fm_set_all(fm_dipole_MO_trunc_reordered(idir), 0.0_dp)
149 : CALL fm_general_add_bse(fm_dipole_MO_trunc_reordered(idir), fm_dipole_ai_trunc(idir), 1.0_dp, &
150 : 1, 1, &
151 : 1, virtual_red, &
152 90 : unit_nr, (/2, 4, 3, 1/), mp2_env)
153 120 : CALL cp_fm_release(fm_dipole_per_dir(idir))
154 : END DO
155 :
156 120 : DO idir = 1, 3
157 : CALL cp_fm_create(fm_trans_mom_bse(idir), matrix_struct=fm_struct_trans_mom_bse, &
158 90 : name="excitonic_dipoles")
159 120 : CALL cp_fm_set_all(fm_trans_mom_bse(idir), 0.0_dp)
160 : END DO
161 :
162 : ! If TDA is invoked, Y is not present as it is simply 0
163 30 : CALL cp_fm_create(fm_eigvec_XYsum, matrix_struct=fm_eigvec_X%matrix_struct, name="excit_amplitude_sum")
164 30 : CALL cp_fm_set_all(fm_eigvec_XYsum, 0.0_dp)
165 30 : CALL cp_fm_to_fm(fm_eigvec_X, fm_eigvec_XYsum)
166 30 : IF (PRESENT(fm_eigvec_Y)) THEN
167 18 : CALL cp_fm_scale_and_add(1.0_dp, fm_eigvec_XYsum, 1.0_dp, fm_eigvec_Y)
168 : END IF
169 120 : DO idir = 1, 3
170 : CALL parallel_gemm('N', 'N', 1, homo_red*virtual_red, homo_red*virtual_red, SQRT(2.0_dp), &
171 120 : fm_dipole_MO_trunc_reordered(idir), fm_eigvec_XYsum, 0.0_dp, fm_trans_mom_bse(idir))
172 : END DO
173 :
174 : ! Get oscillator strengths themselves
175 90 : ALLOCATE (oscill_str(homo_red*virtual_red))
176 90 : ALLOCATE (trans_mom_bse(3, 1, homo_red*virtual_red))
177 90 : ALLOCATE (polarizability_residues(3, 3, homo_red*virtual_red))
178 6830 : trans_mom_bse(:, :, :) = 0.0_dp
179 :
180 : ! Sum over all directions
181 120 : DO idir = 1, 3
182 120 : CALL cp_fm_get_submatrix(fm_trans_mom_bse(idir), trans_mom_bse(idir, :, :))
183 : END DO
184 :
185 1390 : DO n = 1, homo_red*virtual_red
186 5440 : DO idir = 1, 3
187 17680 : DO jdir = 1, 3
188 16320 : polarizability_residues(idir, jdir, n) = 2.0_dp*Exc_ens(n)*trans_mom_bse(idir, 1, n)*trans_mom_bse(jdir, 1, n)
189 : END DO
190 : END DO
191 6830 : oscill_str(n) = 2.0_dp/3.0_dp*Exc_ens(n)*SUM(ABS(trans_mom_bse(:, :, n))**2)
192 : END DO
193 :
194 30 : CALL cp_fm_struct_release(fm_struct_dipole_MO_trunc_reordered)
195 30 : CALL cp_fm_struct_release(fm_struct_trans_mom_bse)
196 120 : DO idir = 1, 3
197 90 : CALL cp_fm_release(fm_dipole_MO_trunc_reordered(idir))
198 90 : CALL cp_fm_release(fm_trans_mom_bse(idir))
199 120 : CALL cp_fm_release(fm_dipole_ai_trunc(idir))
200 : END DO
201 30 : CALL cp_fm_release(fm_eigvec_XYsum)
202 :
203 30 : CALL timestop(handle)
204 :
205 90 : END SUBROUTINE get_oscillator_strengths
206 :
207 : ! **************************************************************************************************
208 : !> \brief Computes and returns absorption spectrum for the frequency range and broadening
209 : !> provided by the user.
210 : !> Prelim Ref.: C. Ullrich, Time-Dependent Density-Functional Theory: Concepts and Applications
211 : !> (Oxford University Press, Oxford, 2012), Eq. 7.51
212 : !> \param oscill_str ...
213 : !> \param polarizability_residues ...
214 : !> \param Exc_ens ...
215 : !> \param info_approximation ...
216 : !> \param unit_nr ...
217 : !> \param mp2_env ...
218 : ! **************************************************************************************************
219 2 : SUBROUTINE compute_and_print_absorption_spectrum(oscill_str, polarizability_residues, Exc_ens, &
220 : info_approximation, unit_nr, mp2_env)
221 :
222 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:), &
223 : INTENT(IN) :: oscill_str
224 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :, :), &
225 : INTENT(IN) :: polarizability_residues
226 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:), &
227 : INTENT(IN) :: Exc_ens
228 : CHARACTER(LEN=10) :: info_approximation
229 : INTEGER, INTENT(IN) :: unit_nr
230 : TYPE(mp2_type), INTENT(INOUT) :: mp2_env
231 :
232 : CHARACTER(LEN=*), PARAMETER :: routineN = 'compute_and_print_absorption_spectrum'
233 :
234 : CHARACTER(LEN=10) :: eta_str, width_eta_format_str
235 : CHARACTER(LEN=40) :: file_name_crosssection, &
236 : file_name_spectrum
237 : INTEGER :: handle, i, idir, j, jdir, k, num_steps, &
238 : unit_nr_file, width_eta
239 : REAL(KIND=dp) :: eta, freq_end, freq_start, freq_step, &
240 : omega
241 2 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :) :: abs_cross_section, abs_spectrum
242 2 : REAL(KIND=dp), DIMENSION(:), POINTER :: eta_list
243 : TYPE(cp_logger_type), POINTER :: logger
244 :
245 2 : CALL timeset(routineN, handle)
246 :
247 2 : freq_step = mp2_env%bse%bse_spectrum_freq_step_size
248 2 : freq_start = mp2_env%bse%bse_spectrum_freq_start
249 2 : freq_end = mp2_env%bse%bse_spectrum_freq_end
250 2 : eta_list => mp2_env%bse%bse_eta_spectrum_list
251 :
252 : ! Calculate number of steps to fit given frequency range
253 2 : num_steps = NINT((freq_end - freq_start)/freq_step) + 1
254 :
255 4 : DO k = 1, SIZE(eta_list)
256 2 : eta = eta_list(k)
257 :
258 : ! Some magic to get a nice formatting of the eta value in filenames
259 2 : width_eta = MAX(1, INT(LOG10(eta)) + 1) + 4
260 2 : WRITE (width_eta_format_str, "(A2,I0,A3)") '(F', width_eta, '.3)'
261 2 : WRITE (eta_str, width_eta_format_str) eta*evolt
262 : ! Filename itself
263 2 : file_name_spectrum = 'BSE'//TRIM(ADJUSTL(info_approximation))//'eta='//TRIM(eta_str)//'.spectrum'
264 2 : file_name_crosssection = 'BSE'//TRIM(ADJUSTL(info_approximation))//'eta='//TRIM(eta_str)//'.crosssection'
265 :
266 : ! First column is frequency in eV, second column is imaginary part of the trace of the polarizability
267 : ! The following 9 columns are the entries of the polarizability tensor
268 6 : ALLOCATE (abs_spectrum(num_steps, 11))
269 22046 : abs_spectrum(:, :) = 0.0_dp
270 : ! Also calculate and print the photoabsorption cross section tensor
271 : ! σ_{µ µ'}(ω) = 4πω Im{α_{µ µ'}(ω)} / c
272 4 : ALLOCATE (abs_cross_section(num_steps, 11))
273 22046 : abs_cross_section(:, :) = 0.0_dp
274 :
275 : ! Calculate the imaginary part of the mean dipole polarizability α_{avg}(ω)
276 : ! which is given by (cf. C. Ullrichs Book on TDDFT, Eq. 7.51)
277 : ! We introduce an additional - due to his convention for charge vs particle density, see also:
278 : ! Computer Physics Communications, 208:149–161, November 2016
279 : ! https://doi.org/10.1016/j.cpc.2016.06.019
280 : ! α_{avg}(ω) = - \sum_{n=1}^{N_exc} \frac{f_n}{(ω+iη)² - (Ω^n)²}
281 : ! and then the imaginary part is (in the limit η -> 0)
282 : ! Im[α_{avg}(ω)] = - \sum_{n=1}^{N_exc} f_n * η / ((ω - Ω^n)² + η²)
283 : ! where f_n are the oscillator strengths and E_exc the excitation energies
284 : ! For the full polarizability tensor, we have
285 : ! α_{µ µ'}(ω) = - \sum_n [2 Ω^n d^n_µ d^n_µ'] / [(ω+iη)^2- (Ω^n)^2]
286 : ! = - \sum_n "polarizability_residues" / [(ω+iη)^2- (Ω^n)^2]
287 2004 : DO i = 1, num_steps
288 2002 : omega = freq_start + (i - 1)*freq_step
289 2002 : abs_spectrum(i, 1) = omega
290 98100 : DO j = 1, SIZE(oscill_str)
291 : abs_spectrum(i, 2) = abs_spectrum(i, 2) - oscill_str(j)* &
292 96096 : AIMAG(1/((omega + CMPLX(0.0, eta, kind=dp))**2 - Exc_ens(j)**2))
293 386386 : DO idir = 1, 3
294 1249248 : DO jdir = 1, 3
295 : ! Factor 2 from formula for tensor is already in the polarizability_residues
296 : ! to follow the same convention as the oscillator strengths
297 : abs_spectrum(i, 2 + (idir - 1)*3 + jdir) = abs_spectrum(i, 2 + (idir - 1)*3 + jdir) &
298 : - polarizability_residues(idir, jdir, j)* &
299 1153152 : AIMAG(1/((omega + CMPLX(0.0, eta, kind=dp))**2 - Exc_ens(j)**2))
300 : END DO
301 : END DO
302 : END DO
303 : END DO
304 :
305 : ! Extract cross section σ from polarizability tensor
306 2004 : DO i = 1, num_steps
307 2002 : omega = abs_spectrum(i, 1)
308 2002 : abs_cross_section(i, 1) = omega
309 22024 : abs_cross_section(i, 2:) = 4.0_dp*pi*abs_spectrum(i, 2:)*omega/c_light_au
310 : END DO
311 :
312 : !For debug runs: Export an entry of the two tensors to allow regtests on spectra
313 2 : IF (mp2_env%bse%bse_debug_print) THEN
314 2 : IF (unit_nr > 0) THEN
315 1 : WRITE (unit_nr, '(T2,A10,T13,A,T65,F16.4)') 'BSE|DEBUG|', &
316 1 : 'Averaged dynamical dipole polarizability at 8.2 eV:', &
317 2 : abs_spectrum(83, 2)
318 1 : WRITE (unit_nr, '(T2,A10,T13,A,T65,F16.4)') 'BSE|DEBUG|', &
319 1 : 'Averaged photoabsorption cross section at 8.2 eV:', &
320 2 : abs_cross_section(83, 2)
321 : END IF
322 : END IF
323 :
324 : ! Print it to file
325 2 : logger => cp_get_default_logger()
326 2 : IF (logger%para_env%is_source()) THEN
327 2 : unit_nr_file = cp_logger_get_default_unit_nr()
328 : ELSE
329 0 : unit_nr_file = -1
330 : END IF
331 :
332 2 : IF (unit_nr_file > 0) THEN
333 : CALL open_file(file_name_crosssection, unit_number=unit_nr_file, &
334 2 : file_status="UNKNOWN", file_action="WRITE")
335 : WRITE (unit_nr_file, '(A,A6)') "# Photoabsorption cross section σ_{µ µ'}(ω) = -4πω/c * Im[ \sum_n "// &
336 2 : "[2 Ω^n d_µ^n d_µ'^n] / [(ω+iη)²- (Ω^n)²] ] from Bethe Salpeter equation for method ", &
337 4 : TRIM(ADJUSTL(info_approximation))
338 2 : WRITE (unit_nr_file, '(A20,1X,10(2X,A20,1X))') "# Frequency (eV)", "σ_{avg}(ω)", "σ_xx(ω)", &
339 2 : "σ_xy(ω)", "σ_xz(ω)", "σ_yx(ω)", "σ_yy(ω)", "σ_yz(ω)", "σ_zx(ω)", &
340 4 : "σ_zy(ω)", "σ_zz(ω)"
341 2004 : DO i = 1, num_steps
342 2004 : WRITE (unit_nr_file, '(11(F20.8,1X))') abs_cross_section(i, 1)*evolt, abs_cross_section(i, 2:11)
343 : END DO
344 2 : CALL close_file(unit_nr_file)
345 : END IF
346 2 : DEALLOCATE (abs_cross_section)
347 :
348 2 : IF (unit_nr_file > 0) THEN
349 : CALL open_file(file_name_spectrum, unit_number=unit_nr_file, &
350 2 : file_status="UNKNOWN", file_action="WRITE")
351 : WRITE (unit_nr_file, '(A,A6)') "# Imaginary part of polarizability α_{µ µ'}(ω) = -\sum_n "// &
352 2 : "[2 Ω^n d_µ^n d_µ'^n] / [(ω+iη)²- (Ω^n)²] from Bethe Salpeter equation for method ", &
353 4 : TRIM(ADJUSTL(info_approximation))
354 2 : WRITE (unit_nr_file, '(A20,1X,10(2X,A20,1X))') "# Frequency (eV)", "Im{α_{avg}(ω)}", "Im{α_xx(ω)}", &
355 2 : "Im{α_xy(ω)}", "Im{α_xz(ω)}", "Im{α_yx(ω)}", "Im{α_yy(ω)}", "Im{α_yz(ω)}", "Im{α_zx(ω)}", &
356 4 : "Im{α_zy(ω)}", "Im{α_zz(ω)}"
357 2004 : DO i = 1, num_steps
358 2004 : WRITE (unit_nr_file, '(11(F20.8,1X))') abs_spectrum(i, 1)*evolt, abs_spectrum(i, 2:11)
359 : END DO
360 2 : CALL close_file(unit_nr_file)
361 : END IF
362 4 : DEALLOCATE (abs_spectrum)
363 : END DO
364 :
365 2 : IF (unit_nr > 0) THEN
366 1 : WRITE (unit_nr, '(T2,A4)') 'BSE|'
367 : WRITE (unit_nr, '(T2,A4,T7,A,A)') &
368 1 : 'BSE|', "Printed optical absorption spectrum to local files, e.g. "
369 : WRITE (unit_nr, '(T2,A4,T7,A)') &
370 1 : 'BSE|', file_name_spectrum
371 : WRITE (unit_nr, '(T2,A4,T7,A,A)') &
372 1 : 'BSE|', "as well as photoabsorption cross section to, e.g. "
373 : WRITE (unit_nr, '(T2,A4,T7,A)') &
374 1 : 'BSE|', file_name_crosssection
375 : WRITE (unit_nr, '(T2,A4,T7,A52)') &
376 1 : 'BSE|', "using the Eq. (7.51) from C. Ullrichs Book on TDDFT:"
377 1 : WRITE (unit_nr, '(T2,A4)') 'BSE|'
378 : WRITE (unit_nr, '(T2,A4,T10,A75)') &
379 1 : 'BSE|', "Im{α_{avg}(ω)} = -Im{\sum_{n=1}^{N_exc} \frac{f_n}{(ω+iη)² - (Ω^n)²}}"
380 1 : WRITE (unit_nr, '(T2,A4)') 'BSE|'
381 : WRITE (unit_nr, '(T2,A4,T7,A)') &
382 1 : 'BSE|', "or for the full polarizability tensor:"
383 : WRITE (unit_nr, '(T2,A4,T10,A)') &
384 1 : 'BSE|', "α_{µ µ'}(ω) = -\sum_n [2 Ω^n d_µ^n d_µ'^n] / [(ω+iη)²- (Ω^n)²]"
385 1 : WRITE (unit_nr, '(T2,A4)') 'BSE|'
386 : WRITE (unit_nr, '(T2,A4,T7,A)') &
387 1 : 'BSE|', "as well as Eq. (7.48):"
388 : WRITE (unit_nr, '(T2,A4,T10,A)') &
389 1 : 'BSE|', "σ_{µ µ'}(ω) = 4πω Im{α_{µ µ'}(ω)} / c"
390 1 : WRITE (unit_nr, '(T2,A4)') 'BSE|'
391 : WRITE (unit_nr, '(T2,A4,T7,A)') &
392 1 : 'BSE|', "with transition moments d_µ^n, oscillator strengths f_n,"
393 : WRITE (unit_nr, '(T2,A4,T7,A)') &
394 1 : 'BSE|', "excitation energies Ω^n and the speed of light c."
395 1 : WRITE (unit_nr, '(T2,A4)') 'BSE|'
396 : WRITE (unit_nr, '(T2,A4,T7,A)') &
397 1 : 'BSE|', "Please note that we adopt an additional minus sign for both quantities,"
398 : WRITE (unit_nr, '(T2,A4,T7,A)') &
399 1 : 'BSE|', "due to the convention for charge vs particle density as done in MolGW:"
400 : WRITE (unit_nr, '(T2,A4,T7,A)') &
401 1 : 'BSE|', "https://doi.org/10.1016/j.cpc.2016.06.019."
402 1 : WRITE (unit_nr, '(T2,A4)') 'BSE|'
403 : END IF
404 :
405 2 : CALL timestop(handle)
406 :
407 4 : END SUBROUTINE
408 :
409 : ! **************************************************************************************************
410 : !> \brief ...
411 : !> \param fm_X ...
412 : !> \param fm_Y ...
413 : !> \param mo_coeff ...
414 : !> \param homo ...
415 : !> \param virtual ...
416 : !> \param info_approximation ...
417 : !> \param oscill_str ...
418 : !> \param qs_env ...
419 : !> \param unit_nr ...
420 : !> \param mp2_env ...
421 : ! **************************************************************************************************
422 4 : SUBROUTINE calculate_NTOs(fm_X, fm_Y, &
423 4 : mo_coeff, homo, virtual, &
424 : info_approximation, &
425 : oscill_str, &
426 : qs_env, unit_nr, mp2_env)
427 :
428 : TYPE(cp_fm_type), INTENT(IN) :: fm_X
429 : TYPE(cp_fm_type), INTENT(IN), OPTIONAL :: fm_Y
430 : TYPE(cp_fm_type), DIMENSION(:), INTENT(IN) :: mo_coeff
431 : INTEGER, INTENT(IN) :: homo, virtual
432 : CHARACTER(LEN=10) :: info_approximation
433 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:) :: oscill_str
434 : TYPE(qs_environment_type), POINTER :: qs_env
435 : INTEGER, INTENT(IN) :: unit_nr
436 : TYPE(mp2_type), INTENT(INOUT) :: mp2_env
437 :
438 : CHARACTER(LEN=*), PARAMETER :: routineN = 'calculate_NTOs'
439 :
440 : CHARACTER(LEN=20), DIMENSION(2) :: nto_name
441 : INTEGER :: handle, homo_irred, i, i_nto, info_svd, &
442 : j, n_exc, n_nto, nao_full, nao_trunc
443 4 : INTEGER, DIMENSION(:), POINTER :: stride
444 : LOGICAL :: append_cube, cube_file
445 4 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:) :: eigval_svd_squ
446 4 : REAL(KIND=dp), DIMENSION(:), POINTER :: eigval_svd
447 : TYPE(cp_fm_struct_type), POINTER :: fm_struct_m, fm_struct_mo_coeff, &
448 : fm_struct_nto_holes, &
449 : fm_struct_nto_particles, &
450 : fm_struct_nto_set
451 : TYPE(cp_fm_type) :: fm_eigvl, fm_eigvr_t, fm_m, fm_mo_coeff, fm_nto_coeff_holes, &
452 : fm_nto_coeff_particles, fm_nto_set, fm_X_ia, fm_Y_ai
453 4 : TYPE(mo_set_type), ALLOCATABLE, DIMENSION(:) :: nto_set
454 : TYPE(section_vals_type), POINTER :: bse_section, input, nto_section
455 :
456 4 : CALL timeset(routineN, handle)
457 : CALL get_qs_env(qs_env=qs_env, &
458 4 : input=input)
459 4 : bse_section => section_vals_get_subs_vals(input, "DFT%XC%WF_CORRELATION%RI_RPA%GW%BSE")
460 :
461 4 : nao_full = qs_env%mos(1)%nao
462 4 : nao_trunc = homo + virtual
463 : ! This is not influenced by the BSE cutoff
464 4 : homo_irred = qs_env%mos(1)%homo
465 : ! M will have a block structure and is quadratic in homo+virtual, i.e.
466 : ! occ virt
467 : ! | 0 X_i,a | occ = homo
468 : ! M = | Y_a,i 0 | virt = virtual
469 : !
470 : ! X and Y are here not the eigenvectors X_ia,n - instead we fix n and reshape the combined ia index
471 : ! Notice the index structure of the lower block, i.e. X is transposed
472 : CALL cp_fm_struct_create(fm_struct_m, &
473 : fm_X%matrix_struct%para_env, fm_X%matrix_struct%context, &
474 4 : nao_trunc, nao_trunc)
475 : CALL cp_fm_struct_create(fm_struct_mo_coeff, &
476 : fm_X%matrix_struct%para_env, fm_X%matrix_struct%context, &
477 4 : nao_full, nao_trunc)
478 : CALL cp_fm_struct_create(fm_struct_nto_holes, &
479 : fm_X%matrix_struct%para_env, fm_X%matrix_struct%context, &
480 4 : nao_full, nao_trunc)
481 : CALL cp_fm_struct_create(fm_struct_nto_particles, &
482 : fm_X%matrix_struct%para_env, fm_X%matrix_struct%context, &
483 4 : nao_full, nao_trunc)
484 :
485 : CALL cp_fm_create(fm_mo_coeff, matrix_struct=fm_struct_mo_coeff, &
486 4 : name="mo_coeff")
487 : ! Here, we take care of possible cutoffs
488 : ! Simply truncating the matrix causes problems with the print function
489 : ! Therefore, we keep the dimension, but set the coefficients of truncated indices to 0
490 : CALL cp_fm_to_fm_submat_general(mo_coeff(1), fm_mo_coeff, &
491 : nao_full, nao_trunc, &
492 : 1, homo_irred - homo + 1, &
493 : 1, 1, &
494 4 : mo_coeff(1)%matrix_struct%context)
495 :
496 : ! Print some information about the NTOs
497 4 : IF (unit_nr > 0) THEN
498 2 : WRITE (unit_nr, '(T2,A4,T7,A)') 'BSE|', &
499 4 : 'The Natural Transition Orbital (NTO) pairs φ_I(r_e) and χ_I(r_h) for a fixed'
500 2 : WRITE (unit_nr, '(T2,A4,T7,A)') 'BSE|', &
501 4 : 'excitation index n are obtained by singular value decomposition of T'
502 2 : WRITE (unit_nr, '(T2,A4)') 'BSE|'
503 2 : WRITE (unit_nr, '(T2,A4,T15,A)') 'BSE|', &
504 4 : ' = (0 X)'
505 2 : IF (PRESENT(fm_Y)) THEN
506 1 : WRITE (unit_nr, '(T2,A4,T15,A)') 'BSE|', &
507 2 : 'T = (Y^T 0)'
508 : ELSE
509 1 : WRITE (unit_nr, '(T2,A4,T15,A)') 'BSE|', &
510 2 : 'T = (0 0)'
511 : END IF
512 2 : WRITE (unit_nr, '(T2,A4)') 'BSE|'
513 2 : WRITE (unit_nr, '(T2,A4,T15,A)') 'BSE|', &
514 4 : 'T = U Λ V^T'
515 2 : WRITE (unit_nr, '(T2,A4,T15,A)') 'BSE|', &
516 4 : 'φ_I(r_e) = \sum_p V_pI ψ_p(r_e)'
517 2 : WRITE (unit_nr, '(T2,A4,T15,A)') 'BSE|', &
518 4 : 'χ_I(r_h) = \sum_p U_pI ψ_p(r_e)'
519 2 : WRITE (unit_nr, '(T2,A4)') 'BSE|'
520 2 : WRITE (unit_nr, '(T2,A4,T7,A)') 'BSE|', &
521 4 : 'where we have introduced'
522 2 : WRITE (unit_nr, '(T2,A4)') 'BSE|'
523 : WRITE (unit_nr, '(T2,A4,T7,A,T20,A)') &
524 2 : 'BSE|', "ψ_p:", "occupied and virtual molecular orbitals,"
525 : WRITE (unit_nr, '(T2,A4,T7,A,T20,A)') &
526 2 : 'BSE|', "φ_I(r_e):", "NTO state for the electron,"
527 : WRITE (unit_nr, '(T2,A4,T7,A,T20,A)') &
528 2 : 'BSE|', "χ_I(r_h):", "NTO state for the hole,"
529 : WRITE (unit_nr, '(T2,A4,T7,A,T20,A)') &
530 2 : 'BSE|', "Λ:", "diagonal matrix of NTO weights λ_I,"
531 2 : WRITE (unit_nr, '(T2,A4)') 'BSE|'
532 2 : WRITE (unit_nr, '(T2,A4,T7,A)') 'BSE|', &
533 4 : "The NTOs are calculated with the following settings:"
534 2 : WRITE (unit_nr, '(T2,A4)') 'BSE|'
535 2 : WRITE (unit_nr, '(T2,A4,T7,A,T71,I10)') 'BSE|', 'Number of excitations, for which NTOs are computed', &
536 4 : mp2_env%bse%num_print_exc_ntos
537 2 : IF (mp2_env%bse%eps_nto_osc_str > 0.0_dp) THEN
538 0 : WRITE (unit_nr, '(T2,A4,T7,A,T71,F10.3)') 'BSE|', 'Threshold for oscillator strength f^n', &
539 0 : mp2_env%bse%eps_nto_osc_str
540 : ELSE
541 2 : WRITE (unit_nr, '(T2,A4,T7,A,T71,A10)') 'BSE|', 'Threshold for oscillator strength f^n', &
542 4 : ADJUSTL("---")
543 : END IF
544 2 : WRITE (unit_nr, '(T2,A4,T7,A,T72,F10.3)') 'BSE|', 'Threshold for NTO weights (λ_I)^2', &
545 4 : mp2_env%bse%eps_nto_eigval
546 : END IF
547 :
548 : ! Write the header of NTO info table
549 4 : IF (unit_nr > 0) THEN
550 2 : WRITE (unit_nr, '(T2,A4)') 'BSE|'
551 2 : IF (.NOT. PRESENT(fm_Y)) THEN
552 1 : WRITE (unit_nr, '(T2,A4,T7,A)') 'BSE|', &
553 2 : 'NTOs from solving the BSE within the TDA:'
554 : ELSE
555 1 : WRITE (unit_nr, '(T2,A4,T7,A)') 'BSE|', &
556 2 : 'NTOs from solving the BSE without the TDA:'
557 : END IF
558 2 : WRITE (unit_nr, '(T2,A4)') 'BSE|'
559 2 : WRITE (unit_nr, '(T2,A4,T8,A12,T22,A8,T33,A14,T62,A)') 'BSE|', &
560 4 : 'Excitation n', "TDA/ABBA", "Index of NTO I", 'NTO weights (λ_I)^2'
561 : END IF
562 :
563 104 : DO j = 1, mp2_env%bse%num_print_exc_ntos
564 100 : n_exc = mp2_env%bse%bse_nto_state_list_final(j)
565 : ! Takes care of unallocated oscill_str array in case of Triplet
566 100 : IF (mp2_env%bse%eps_nto_osc_str > 0.0_dp) THEN
567 : ! Check actual values
568 0 : IF (oscill_str(n_exc) < mp2_env%bse%eps_nto_osc_str) THEN
569 : ! Print skipped levels to table
570 0 : IF (unit_nr > 0) THEN
571 0 : WRITE (unit_nr, '(T2,A4)') 'BSE|'
572 0 : WRITE (unit_nr, '(T2,A4,T8,I12,T24,A6,T42,A39)') 'BSE|', &
573 0 : n_exc, info_approximation, "Skipped (Oscillator strength too small)"
574 : END IF
575 : CYCLE
576 : END IF
577 : END IF
578 :
579 : CALL cp_fm_create(fm_m, matrix_struct=fm_struct_m, &
580 100 : name="single_part_trans_dm")
581 100 : CALL cp_fm_set_all(fm_m, 0.0_dp)
582 :
583 : CALL cp_fm_create(fm_nto_coeff_holes, matrix_struct=fm_struct_nto_holes, &
584 100 : name="nto_coeffs_holes")
585 100 : CALL cp_fm_set_all(fm_nto_coeff_holes, 0.0_dp)
586 :
587 : CALL cp_fm_create(fm_nto_coeff_particles, matrix_struct=fm_struct_nto_particles, &
588 100 : name="nto_coeffs_particles")
589 100 : CALL cp_fm_set_all(fm_nto_coeff_particles, 0.0_dp)
590 :
591 : ! Reshuffle from X_ia,n_exc to X_i,a
592 : CALL reshuffle_eigvec(fm_X, fm_X_ia, homo, virtual, n_exc, &
593 100 : .FALSE., unit_nr, mp2_env)
594 :
595 : ! Copy X to upper block in M, i.e. starting from column homo+1
596 : CALL cp_fm_to_fm_submat(fm_X_ia, fm_m, &
597 : homo, virtual, &
598 : 1, 1, &
599 100 : 1, homo + 1)
600 100 : CALL cp_fm_release(fm_X_ia)
601 : ! Copy Y if present
602 100 : IF (PRESENT(fm_Y)) THEN
603 : ! Reshuffle from Y_ia,n_exc to Y_a,i
604 : CALL reshuffle_eigvec(fm_Y, fm_Y_ai, homo, virtual, n_exc, &
605 50 : .TRUE., unit_nr, mp2_env)
606 :
607 : ! Copy Y^T to lower block in M, i.e. starting from row homo+1
608 : CALL cp_fm_to_fm_submat(fm_Y_ai, fm_m, &
609 : virtual, homo, &
610 : 1, 1, &
611 50 : homo + 1, 1)
612 :
613 50 : CALL cp_fm_release(fm_Y_ai)
614 :
615 : END IF
616 :
617 : ! Now we compute the SVD of M_{occ+virt,occ+virt}, which yields
618 : ! M = U * Lambda * V^T
619 : ! Initialize matrices and arrays to store left/right eigenvectors and singular values
620 : CALL cp_fm_create(matrix=fm_eigvl, &
621 : matrix_struct=fm_m%matrix_struct, &
622 100 : name="LEFT_SINGULAR_MATRIX")
623 100 : CALL cp_fm_set_all(fm_eigvl, alpha=0.0_dp)
624 : CALL cp_fm_create(matrix=fm_eigvr_t, &
625 : matrix_struct=fm_m%matrix_struct, &
626 100 : name="RIGHT_SINGULAR_MATRIX")
627 100 : CALL cp_fm_set_all(fm_eigvr_t, alpha=0.0_dp)
628 :
629 300 : ALLOCATE (eigval_svd(nao_trunc))
630 1700 : eigval_svd(:) = 0.0_dp
631 : info_svd = 0
632 100 : CALL cp_fm_svd(fm_m, fm_eigvl, fm_eigvr_t, eigval_svd, info_svd)
633 604 : IF (info_svd /= 0) THEN
634 0 : IF (unit_nr > 0) THEN
635 : CALL cp_warn(__LOCATION__, &
636 : "SVD for computation of NTOs not successful. "// &
637 0 : "Skipping print of NTOs.")
638 0 : IF (info_svd > 0) THEN
639 : CALL cp_warn(__LOCATION__, &
640 : "PDGESVD detected heterogeneity. "// &
641 0 : "Decreasing number of MPI ranks might solve this issue.")
642 : END IF
643 : END IF
644 : ! Release matrices to avoid memory leaks
645 0 : CALL cp_fm_release(fm_m)
646 0 : CALL cp_fm_release(fm_nto_coeff_holes)
647 0 : CALL cp_fm_release(fm_nto_coeff_particles)
648 : ELSE
649 : ! Rescale singular values as done in Martin2003 (10.1063/1.1558471)
650 200 : ALLOCATE (eigval_svd_squ(nao_trunc))
651 1700 : eigval_svd_squ(:) = eigval_svd(:)**2
652 : ! Sanity check for TDA: In case of TDA, the sum should be \sum_ia |X_ia|^2 = 1
653 100 : IF (.NOT. PRESENT(fm_Y)) THEN
654 850 : IF (ABS(SUM(eigval_svd_squ) - 1) >= 1e-5) THEN
655 0 : CPWARN("Sum of NTO coefficients deviates from 1!")
656 : END IF
657 : END IF
658 :
659 : ! Create NTO coefficients for later print to grid via TDDFT routine
660 : ! Apply U = fm_eigvl to MO coeffs, which yields hole states
661 : CALL parallel_gemm("N", "N", nao_full, nao_trunc, nao_trunc, 1.0_dp, fm_mo_coeff, fm_eigvl, 0.0_dp, &
662 100 : fm_nto_coeff_holes)
663 :
664 : ! Apply V^T = fm_eigvr_t to MO coeffs, which yields particle states
665 : CALL parallel_gemm("N", "T", nao_full, nao_trunc, nao_trunc, 1.0_dp, fm_mo_coeff, fm_eigvr_t, 0.0_dp, &
666 100 : fm_nto_coeff_particles)
667 :
668 : !Release intermediary work matrices
669 100 : CALL cp_fm_release(fm_m)
670 100 : CALL cp_fm_release(fm_eigvl)
671 100 : CALL cp_fm_release(fm_eigvr_t)
672 :
673 : ! Transfer NTO coefficients to sets
674 100 : nto_name(1) = 'Hole_coord'
675 100 : nto_name(2) = 'Particle_coord'
676 300 : ALLOCATE (nto_set(2))
677 : ! Extract number of significant NTOs
678 100 : n_nto = 0
679 320 : DO i_nto = 1, nao_trunc
680 320 : IF (eigval_svd_squ(i_nto) > mp2_env%bse%eps_nto_eigval) THEN
681 220 : n_nto = n_nto + 1
682 : ELSE
683 : ! Since svd orders in descending order, we can exit the loop if smaller
684 : EXIT
685 : END IF
686 : END DO
687 :
688 100 : IF (unit_nr > 0) THEN
689 50 : WRITE (unit_nr, '(T2,A4)') 'BSE|'
690 160 : DO i_nto = 1, n_nto
691 110 : WRITE (unit_nr, '(T2,A4,T8,I12,T24,A6,T41,I6,T71,F10.5)') 'BSE|', &
692 270 : n_exc, info_approximation, i_nto, eigval_svd_squ(i_nto)
693 : END DO
694 : END IF
695 :
696 : CALL cp_fm_struct_create(fm_struct_nto_set, template_fmstruct=fm_struct_nto_holes, &
697 100 : ncol_global=n_nto)
698 100 : CALL cp_fm_create(fm_nto_set, fm_struct_nto_set)
699 300 : DO i = 1, 2
700 200 : CALL allocate_mo_set(nto_set(i), nao_trunc, n_nto, 0, 0.0_dp, 2.0_dp, 0.0_dp)
701 300 : CALL init_mo_set(nto_set(i), fm_ref=fm_nto_set, name=nto_name(i))
702 : END DO
703 100 : CALL cp_fm_release(fm_nto_set)
704 100 : CALL cp_fm_struct_release(fm_struct_nto_set)
705 :
706 : ! Fill NTO sets
707 100 : CALL cp_fm_to_fm(fm_nto_coeff_holes, nto_set(1)%mo_coeff, ncol=n_nto)
708 100 : CALL cp_fm_to_fm(fm_nto_coeff_particles, nto_set(2)%mo_coeff, ncol=n_nto)
709 :
710 : ! Cube files
711 100 : nto_section => section_vals_get_subs_vals(bse_section, "NTO_ANALYSIS")
712 100 : CALL section_vals_val_get(nto_section, "CUBE_FILES", l_val=cube_file)
713 100 : CALL section_vals_val_get(nto_section, "STRIDE", i_vals=stride)
714 100 : CALL section_vals_val_get(nto_section, "APPEND", l_val=append_cube)
715 100 : IF (cube_file) THEN
716 : CALL print_bse_nto_cubes(qs_env, nto_set, n_exc, info_approximation, &
717 0 : stride, append_cube, nto_section)
718 : END IF
719 :
720 100 : CALL cp_fm_release(fm_nto_coeff_holes)
721 100 : CALL cp_fm_release(fm_nto_coeff_particles)
722 100 : DEALLOCATE (eigval_svd)
723 100 : DEALLOCATE (eigval_svd_squ)
724 300 : DO i = 1, 2
725 300 : CALL deallocate_mo_set(nto_set(i))
726 : END DO
727 400 : DEALLOCATE (nto_set)
728 : END IF
729 : END DO
730 :
731 4 : CALL cp_fm_release(fm_mo_coeff)
732 4 : CALL cp_fm_struct_release(fm_struct_m)
733 4 : CALL cp_fm_struct_release(fm_struct_nto_holes)
734 4 : CALL cp_fm_struct_release(fm_struct_nto_particles)
735 4 : CALL cp_fm_struct_release(fm_struct_mo_coeff)
736 :
737 4 : CALL timestop(handle)
738 :
739 8 : END SUBROUTINE calculate_NTOs
740 :
741 : ! **************************************************************************************************
742 : !> \brief ...
743 : !> \param exc_descr Allocated and initialized on exit
744 : !> \param fm_X_ia ...
745 : !> \param fm_multipole_ij_trunc ...
746 : !> \param fm_multipole_ab_trunc ...
747 : !> \param fm_multipole_ai_trunc ...
748 : !> \param i_exc ...
749 : !> \param homo ...
750 : !> \param virtual ...
751 : !> \param fm_Y_ia ...
752 : ! **************************************************************************************************
753 110 : SUBROUTINE get_exciton_descriptors(exc_descr, fm_X_ia, &
754 : fm_multipole_ij_trunc, fm_multipole_ab_trunc, &
755 : fm_multipole_ai_trunc, &
756 : i_exc, homo, virtual, &
757 : fm_Y_ia)
758 :
759 : TYPE(exciton_descr_type), ALLOCATABLE, &
760 : DIMENSION(:) :: exc_descr
761 : TYPE(cp_fm_type), INTENT(IN) :: fm_X_ia
762 : TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:), &
763 : INTENT(IN) :: fm_multipole_ij_trunc, &
764 : fm_multipole_ab_trunc, &
765 : fm_multipole_ai_trunc
766 : INTEGER, INTENT(IN) :: i_exc, homo, virtual
767 : TYPE(cp_fm_type), INTENT(IN), OPTIONAL :: fm_Y_ia
768 :
769 : CHARACTER(LEN=*), PARAMETER :: routineN = 'get_exciton_descriptors'
770 :
771 : INTEGER :: handle, i_dir
772 : INTEGER, DIMENSION(3) :: mask_quadrupole
773 : LOGICAL :: flag_TDA
774 : REAL(KIND=dp) :: norm_X, norm_XpY, norm_Y
775 : REAL(KIND=dp), DIMENSION(3) :: r_e_h_XX, r_e_h_XY, r_e_h_YX, r_e_h_YY, &
776 : r_e_sq_X, r_e_sq_Y, r_e_X, r_e_Y, &
777 : r_h_sq_X, r_h_sq_Y, r_h_X, r_h_Y
778 : TYPE(cp_fm_struct_type), POINTER :: fm_struct_ab, fm_struct_ia
779 : TYPE(cp_fm_type) :: fm_work_ba, fm_work_ia, fm_work_ia_2
780 :
781 110 : CALL timeset(routineN, handle)
782 110 : IF (PRESENT(fm_Y_ia)) THEN
783 : flag_TDA = .FALSE.
784 : ELSE
785 60 : flag_TDA = .TRUE.
786 : END IF
787 :
788 : ! translates 1,2,3 to diagonal entries of quadrupoles xx, yy, zz
789 : ! Ordering in quadrupole moments is x, y, z, xx, xy, xz, yy, yz, zz
790 110 : mask_quadrupole = (/4, 7, 9/)
791 :
792 : CALL cp_fm_struct_create(fm_struct_ia, &
793 110 : context=fm_X_ia%matrix_struct%context, nrow_global=homo, ncol_global=virtual)
794 : CALL cp_fm_struct_create(fm_struct_ab, &
795 110 : context=fm_X_ia%matrix_struct%context, nrow_global=virtual, ncol_global=virtual)
796 :
797 110 : r_e_X(:) = 0.0_dp
798 110 : r_e_Y(:) = 0.0_dp
799 110 : r_h_X(:) = 0.0_dp
800 110 : r_h_Y(:) = 0.0_dp
801 110 : r_e_sq_X(:) = 0.0_dp
802 110 : r_h_sq_X(:) = 0.0_dp
803 110 : r_e_sq_Y(:) = 0.0_dp
804 110 : r_h_sq_Y(:) = 0.0_dp
805 110 : r_e_h_XX(:) = 0.0_dp
806 110 : r_e_h_XY(:) = 0.0_dp
807 110 : r_e_h_YX(:) = 0.0_dp
808 110 : r_e_h_YY(:) = 0.0_dp
809 :
810 : norm_X = 0.0_dp
811 110 : norm_Y = 0.0_dp
812 110 : norm_XpY = 0.0_dp
813 :
814 : ! Initialize values of exciton descriptors
815 440 : exc_descr(i_exc)%r_e(:) = 0.0_dp
816 440 : exc_descr(i_exc)%r_h(:) = 0.0_dp
817 440 : exc_descr(i_exc)%r_e_sq(:) = 0.0_dp
818 440 : exc_descr(i_exc)%r_h_sq(:) = 0.0_dp
819 440 : exc_descr(i_exc)%r_e_h(:) = 0.0_dp
820 :
821 110 : exc_descr(i_exc)%flag_TDA = flag_TDA
822 110 : exc_descr(i_exc)%norm_XpY = 0.0_dp
823 :
824 : ! Norm of X
825 110 : CALL cp_fm_trace(fm_X_ia, fm_X_ia, norm_X)
826 110 : norm_XpY = norm_X
827 : ! Norm of Y
828 110 : IF (.NOT. flag_TDA) THEN
829 50 : CALL cp_fm_trace(fm_Y_ia, fm_Y_ia, norm_Y)
830 50 : norm_XpY = norm_XpY + norm_Y
831 : END IF
832 :
833 110 : exc_descr(i_exc)%norm_XpY = norm_XpY
834 :
835 : ! <r_h>_X = Tr[ X^T µ_ij X + Y µ_ab Y^T ] = X_ai µ_ij X_ja + Y_ia µ_ab Y_bi
836 440 : DO i_dir = 1, 3
837 : ! <r_h>_X = X_ai µ_ij X_ja + ...
838 330 : CALL trace_exciton_descr(fm_X_ia, fm_multipole_ij_trunc(i_dir), fm_X_ia, r_h_X(i_dir))
839 330 : r_h_X(i_dir) = r_h_X(i_dir)/norm_XpY
840 440 : IF (.NOT. flag_TDA) THEN
841 : ! <r_h>_X = ... + Y_ia µ_ab Y_bi
842 150 : CALL trace_exciton_descr(fm_Y_ia, fm_Y_ia, fm_multipole_ab_trunc(i_dir), r_h_Y(i_dir))
843 150 : r_h_Y(i_dir) = r_h_Y(i_dir)/norm_XpY
844 : END IF
845 : END DO
846 440 : exc_descr(i_exc)%r_h(:) = r_h_X(:) + r_h_Y(:)
847 :
848 : ! <r_e>_X = Tr[ X µ_ab X^T + Y^T µ_ij Y ] = X_ia µ_ab X_bi + Y_ai µ_ij Y_ja
849 440 : DO i_dir = 1, 3
850 : ! <r_e>_X = work_ib X_bi + ... = X_ib^T work_ib + ...
851 330 : CALL trace_exciton_descr(fm_X_ia, fm_X_ia, fm_multipole_ab_trunc(i_dir), r_e_X(i_dir))
852 330 : r_e_X(i_dir) = r_e_X(i_dir)/norm_XpY
853 440 : IF (.NOT. flag_TDA) THEN
854 : ! <r_e>_X = ... + Y_ai µ_ij Y_ja
855 150 : CALL trace_exciton_descr(fm_Y_ia, fm_multipole_ij_trunc(i_dir), fm_Y_ia, r_e_Y(i_dir))
856 150 : r_e_Y(i_dir) = r_e_Y(i_dir)/norm_XpY
857 : END IF
858 : END DO
859 440 : exc_descr(i_exc)%r_e(:) = r_e_X(:) + r_e_Y(:)
860 :
861 : ! <r_h^2>_X = Tr[ X^T M_ij X + Y M_ab Y^T ] = X_ai M_ij X_ja + Y_ia M_ab Y_bi
862 440 : DO i_dir = 1, 3
863 : ! <r_h^2>_X = X_ai M_ij X_ja + ...
864 : CALL trace_exciton_descr(fm_X_ia, fm_multipole_ij_trunc(mask_quadrupole(i_dir)), &
865 330 : fm_X_ia, r_h_sq_X(i_dir))
866 330 : r_h_sq_X(i_dir) = r_h_sq_X(i_dir)/norm_XpY
867 440 : IF (.NOT. flag_TDA) THEN
868 : ! <r_h^2>_X = ... + Y_ia M_ab Y_bi
869 : CALL trace_exciton_descr(fm_Y_ia, fm_Y_ia, &
870 150 : fm_multipole_ab_trunc(mask_quadrupole(i_dir)), r_h_sq_Y(i_dir))
871 150 : r_h_sq_Y(i_dir) = r_h_sq_Y(i_dir)/norm_XpY
872 : END IF
873 : END DO
874 440 : exc_descr(i_exc)%r_h_sq(:) = r_h_sq_X(:) + r_h_sq_Y(:)
875 :
876 : ! <r_e^2>_X = Tr[ X M_ab X^T + Y^T M_ij Y ] = X_ia M_ab X_bi + Y_ai M_ij Y_ja
877 440 : DO i_dir = 1, 3
878 : ! <r_e^2>_X = work_ib X_bi + ... = X_ib^T work_ib + ...
879 : CALL trace_exciton_descr(fm_X_ia, fm_X_ia, &
880 330 : fm_multipole_ab_trunc(mask_quadrupole(i_dir)), r_e_sq_X(i_dir))
881 330 : r_e_sq_X(i_dir) = r_e_sq_X(i_dir)/norm_XpY
882 440 : IF (.NOT. flag_TDA) THEN
883 : ! <r_e^2>_X = ... + Y_ai M_ij Y_ja
884 : CALL trace_exciton_descr(fm_Y_ia, fm_multipole_ij_trunc(mask_quadrupole(i_dir)), &
885 150 : fm_Y_ia, r_e_sq_Y(i_dir))
886 150 : r_e_sq_Y(i_dir) = r_e_sq_Y(i_dir)/norm_XpY
887 : END IF
888 : END DO
889 440 : exc_descr(i_exc)%r_e_sq(:) = r_e_sq_X(:) + r_e_sq_Y(:)
890 :
891 : ! <r_h r_e>_X
892 : ! = Tr[ X^T µ_ij X µ_ab + Y^T µ_ij Y µ_ab + X µ_ai Y µ_ai + Y µ_ai X µ_ai]
893 : ! = X_bj µ_ji X_ia µ_ab + Y_bj µ_ji Y_ia µ_ab + X_ia µ_aj Y_jb µ_bi + Y_ia µ_aj X_jb µ_bi
894 110 : CALL cp_fm_create(fm_work_ia, fm_struct_ia)
895 110 : CALL cp_fm_create(fm_work_ia_2, fm_struct_ia)
896 110 : CALL cp_fm_create(fm_work_ba, fm_struct_ab)
897 440 : DO i_dir = 1, 3
898 : ! First term - X^T µ_ij X µ_ab
899 330 : CALL cp_fm_set_all(fm_work_ia, 0.0_dp)
900 330 : CALL cp_fm_set_all(fm_work_ia_2, 0.0_dp)
901 : ! work_ib = X_ia µ_ab
902 : CALL parallel_gemm("N", "N", homo, virtual, virtual, 1.0_dp, &
903 330 : fm_X_ia, fm_multipole_ab_trunc(i_dir), 0.0_dp, fm_work_ia)
904 : ! work_ja_2 = µ_ji work_ia
905 : CALL parallel_gemm("N", "N", homo, virtual, homo, 1.0_dp, &
906 330 : fm_multipole_ij_trunc(i_dir), fm_work_ia, 0.0_dp, fm_work_ia_2)
907 : ! <r_h r_e>_X = work_ia_2 X_bj + ... = X^T work_ia_2 + ...
908 330 : CALL cp_fm_trace(fm_X_ia, fm_work_ia_2, r_e_h_XX(i_dir))
909 330 : r_e_h_XX(i_dir) = r_e_h_XX(i_dir)/norm_XpY
910 440 : IF (.NOT. flag_TDA) THEN
911 : ! Second term - Y^T µ_ij Y µ_ab
912 150 : CALL cp_fm_set_all(fm_work_ia, 0.0_dp)
913 150 : CALL cp_fm_set_all(fm_work_ia_2, 0.0_dp)
914 : ! work_ib = Y_ia µ_ab
915 : CALL parallel_gemm("N", "N", homo, virtual, virtual, 1.0_dp, &
916 150 : fm_Y_ia, fm_multipole_ab_trunc(i_dir), 0.0_dp, fm_work_ia)
917 : ! work_ja_2 = µ_ji work_ia
918 : CALL parallel_gemm("N", "N", homo, virtual, homo, 1.0_dp, &
919 150 : fm_multipole_ij_trunc(i_dir), fm_work_ia, 0.0_dp, fm_work_ia_2)
920 : ! <r_h r_e>_X = work_ia_2 Y_bj + ... = Y^T work_ia_2 + ...
921 150 : CALL cp_fm_trace(fm_Y_ia, fm_work_ia_2, r_e_h_YY(i_dir))
922 150 : r_e_h_YY(i_dir) = r_e_h_YY(i_dir)/norm_XpY
923 :
924 : ! Third term - X µ_ai Y µ_ai = X_ia µ_aj Y_jb µ_bi
925 : ! Reshuffle for usage of trace (where first argument is transposed)
926 : ! = µ_aj Y_jb µ_bi X_ia =
927 : ! \__________/
928 : ! fm_work_ai
929 : ! fm_work_ai = µ_aj Y_jb µ_bi
930 : ! fm_work_ia = µ_ib Y_bj µ_ja
931 : ! \_____/
932 : ! fm_work_ba
933 150 : CALL cp_fm_set_all(fm_work_ba, 0.0_dp)
934 150 : CALL cp_fm_set_all(fm_work_ia, 0.0_dp)
935 : ! fm_work_ba = Y_bj µ_ja
936 : CALL parallel_gemm("T", "T", virtual, virtual, homo, 1.0_dp, &
937 150 : fm_Y_ia, fm_multipole_ai_trunc(i_dir), 0.0_dp, fm_work_ba)
938 : ! fm_work_ia = µ_ib fm_work_ba
939 : CALL parallel_gemm("T", "N", homo, virtual, virtual, 1.0_dp, &
940 150 : fm_multipole_ai_trunc(i_dir), fm_work_ba, 0.0_dp, fm_work_ia)
941 : ! <r_h r_e>_X = ... + X_ia µ_aj Y_jb µ_bi
942 150 : CALL cp_fm_trace(fm_work_ia, fm_X_ia, r_e_h_XY(i_dir))
943 150 : r_e_h_XY(i_dir) = r_e_h_XY(i_dir)/norm_XpY
944 :
945 : ! Fourth term - Y µ_ai X µ_ai = Y_ia µ_aj X_jb µ_bi
946 : ! Reshuffle for usage of trace (where first argument is transposed)
947 : ! = µ_aj X_jb µ_bi Y_ia =
948 : ! \__________/
949 : ! fm_work_ai
950 : ! fm_work_ai = µ_aj X_jb µ_bi
951 : ! fm_work_ia = µ_ib X_bj µ_ja
952 : ! \_____/
953 : ! fm_work_ba
954 150 : CALL cp_fm_set_all(fm_work_ba, 0.0_dp)
955 150 : CALL cp_fm_set_all(fm_work_ia, 0.0_dp)
956 : ! fm_work_ba = Y_bj µ_ja
957 : CALL parallel_gemm("T", "T", virtual, virtual, homo, 1.0_dp, &
958 150 : fm_X_ia, fm_multipole_ai_trunc(i_dir), 0.0_dp, fm_work_ba)
959 : ! fm_work_ia = µ_ib fm_work_ba
960 : CALL parallel_gemm("T", "N", homo, virtual, virtual, 1.0_dp, &
961 150 : fm_multipole_ai_trunc(i_dir), fm_work_ba, 0.0_dp, fm_work_ia)
962 : ! <r_h r_e>_X = ... + X_ia µ_aj Y_jb µ_bi
963 150 : CALL cp_fm_trace(fm_work_ia, fm_Y_ia, r_e_h_YX(i_dir))
964 150 : r_e_h_YX(i_dir) = r_e_h_YX(i_dir)/norm_XpY
965 : END IF
966 : END DO
967 440 : exc_descr(i_exc)%r_e_h(:) = r_e_h_XX(:) + r_e_h_XY(:) + r_e_h_YX(:) + r_e_h_YY(:)
968 :
969 110 : CALL cp_fm_release(fm_work_ia)
970 110 : CALL cp_fm_release(fm_work_ia_2)
971 110 : CALL cp_fm_release(fm_work_ba)
972 :
973 : ! diff_r_abs = |<r_h>_X - <r_e>_X|
974 440 : exc_descr(i_exc)%diff_r_abs = SQRT(SUM((exc_descr(i_exc)%r_h(:) - exc_descr(i_exc)%r_e(:))**2))
975 :
976 : ! σ_e = sqrt( <r_e^2>_X - <r_e>_X^2 )
977 770 : exc_descr(i_exc)%sigma_e = SQRT(SUM(exc_descr(i_exc)%r_e_sq(:)) - SUM(exc_descr(i_exc)%r_e(:)**2))
978 :
979 : ! σ_h = sqrt( <r_h^2>_X - <r_h>_X^2 )
980 770 : exc_descr(i_exc)%sigma_h = SQRT(SUM(exc_descr(i_exc)%r_h_sq(:)) - SUM(exc_descr(i_exc)%r_h(:)**2))
981 :
982 : ! COV(r_e, r_h) = < r_e r_h >_X - < r_e >_X < r_h >_X
983 110 : exc_descr(i_exc)%cov_e_h_sum = 0.0_dp
984 440 : exc_descr(i_exc)%cov_e_h(:) = 0.0_dp
985 440 : DO i_dir = 1, 3
986 : exc_descr(i_exc)%cov_e_h(i_dir) = exc_descr(i_exc)%r_e_h(i_dir) &
987 330 : - exc_descr(i_exc)%r_e(i_dir)*exc_descr(i_exc)%r_h(i_dir)
988 : exc_descr(i_exc)%cov_e_h_sum = exc_descr(i_exc)%cov_e_h_sum + &
989 440 : exc_descr(i_exc)%r_e_h(i_dir) - exc_descr(i_exc)%r_e(i_dir)*exc_descr(i_exc)%r_h(i_dir)
990 : END DO
991 :
992 : ! root-mean-square e-h separation
993 : exc_descr(i_exc)%diff_r_sqr = SQRT(exc_descr(i_exc)%diff_r_abs**2 + &
994 : exc_descr(i_exc)%sigma_e**2 + exc_descr(i_exc)%sigma_h**2 &
995 110 : - 2*exc_descr(i_exc)%cov_e_h_sum)
996 :
997 : ! e-h-correlation coefficient R_eh = COV(r_e, r_h) / ( σ_e σ_h )
998 110 : exc_descr(i_exc)%corr_e_h = exc_descr(i_exc)%cov_e_h_sum/(exc_descr(i_exc)%sigma_e*exc_descr(i_exc)%sigma_h)
999 :
1000 : ! Expectation values of r_e and r_h
1001 440 : exc_descr(i_exc)%r_e_shift(:) = exc_descr(i_exc)%r_e(:)
1002 440 : exc_descr(i_exc)%r_h_shift(:) = exc_descr(i_exc)%r_h(:)
1003 :
1004 110 : CALL cp_fm_struct_release(fm_struct_ia)
1005 110 : CALL cp_fm_struct_release(fm_struct_ab)
1006 :
1007 110 : CALL timestop(handle)
1008 :
1009 330 : END SUBROUTINE get_exciton_descriptors
1010 :
1011 0 : END MODULE bse_properties
|