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