Line data Source code
1 : !--------------------------------------------------------------------------------------------------!
2 : ! CP2K: A general program to perform molecular dynamics simulations !
3 : ! Copyright 2000-2026 CP2K developers group <https://cp2k.org> !
4 : ! !
5 : ! SPDX-License-Identifier: GPL-2.0-or-later !
6 : !--------------------------------------------------------------------------------------------------!
7 :
8 : MODULE qs_tddfpt2_properties
9 : USE atomic_kind_types, ONLY: atomic_kind_type
10 : USE bibliography, ONLY: Martin2003,&
11 : cite_reference
12 : USE bse_print, ONLY: print_exciton_descriptors
13 : USE bse_properties, ONLY: exciton_descr_type,&
14 : get_exciton_descriptors
15 : USE bse_util, ONLY: get_multipoles_mo
16 : USE cell_types, ONLY: cell_type
17 : USE cp_blacs_env, ONLY: cp_blacs_env_type
18 : USE cp_cfm_basic_linalg, ONLY: cp_cfm_solve
19 : USE cp_cfm_types, ONLY: cp_cfm_create,&
20 : cp_cfm_release,&
21 : cp_cfm_set_all,&
22 : cp_cfm_to_fm,&
23 : cp_cfm_type,&
24 : cp_fm_to_cfm
25 : USE cp_control_types, ONLY: dft_control_type,&
26 : tddfpt2_control_type
27 : USE cp_dbcsr_api, ONLY: &
28 : dbcsr_copy, dbcsr_get_block_p, dbcsr_get_info, dbcsr_init_p, dbcsr_iterator_blocks_left, &
29 : dbcsr_iterator_next_block, dbcsr_iterator_start, dbcsr_iterator_stop, dbcsr_iterator_type, &
30 : dbcsr_p_type, dbcsr_type
31 : USE cp_dbcsr_operations, ONLY: copy_dbcsr_to_fm,&
32 : copy_fm_to_dbcsr,&
33 : cp_dbcsr_sm_fm_multiply,&
34 : dbcsr_allocate_matrix_set,&
35 : dbcsr_deallocate_matrix_set
36 : USE cp_fm_basic_linalg, ONLY: cp_fm_scale,&
37 : cp_fm_scale_and_add,&
38 : cp_fm_trace
39 : USE cp_fm_diag, ONLY: choose_eigv_solver,&
40 : cp_fm_geeig
41 : USE cp_fm_struct, ONLY: cp_fm_struct_create,&
42 : cp_fm_struct_release,&
43 : cp_fm_struct_type
44 : USE cp_fm_types, ONLY: cp_fm_create,&
45 : cp_fm_get_info,&
46 : cp_fm_release,&
47 : cp_fm_set_all,&
48 : cp_fm_to_fm,&
49 : cp_fm_to_fm_submat_general,&
50 : cp_fm_type,&
51 : cp_fm_vectorsnorm
52 : USE cp_log_handling, ONLY: cp_get_default_logger,&
53 : cp_logger_get_default_io_unit,&
54 : cp_logger_type
55 : USE cp_output_handling, ONLY: cp_p_file,&
56 : cp_print_key_finished_output,&
57 : cp_print_key_should_output,&
58 : cp_print_key_unit_nr
59 : USE cp_realspace_grid_cube, ONLY: cp_pw_to_cube
60 : USE input_constants, ONLY: no_sf_tddfpt,&
61 : tddfpt_dipole_berry,&
62 : tddfpt_dipole_length,&
63 : tddfpt_dipole_scf_moment,&
64 : tddfpt_dipole_velocity,&
65 : tddfpt_dipole_velocity_old
66 : USE input_section_types, ONLY: section_vals_get_subs_vals,&
67 : section_vals_type,&
68 : section_vals_val_get
69 : USE kinds, ONLY: default_path_length,&
70 : dp,&
71 : int_8
72 : USE mathconstants, ONLY: twopi,&
73 : z_one,&
74 : z_zero
75 : USE message_passing, ONLY: mp_comm_type,&
76 : mp_para_env_type,&
77 : mp_request_type
78 : USE molden_utils, ONLY: write_mos_molden
79 : USE moments_utils, ONLY: get_reference_point
80 : USE parallel_gemm_api, ONLY: parallel_gemm
81 : USE particle_list_types, ONLY: particle_list_type
82 : USE particle_types, ONLY: particle_type
83 : USE physcon, ONLY: evolt
84 : USE pw_env_types, ONLY: pw_env_get,&
85 : pw_env_type
86 : USE pw_poisson_types, ONLY: pw_poisson_type
87 : USE pw_pool_types, ONLY: pw_pool_p_type,&
88 : pw_pool_type
89 : USE pw_types, ONLY: pw_c1d_gs_type,&
90 : pw_r3d_rs_type
91 : USE qs_collocate_density, ONLY: calculate_wavefunction
92 : USE qs_environment_types, ONLY: get_qs_env,&
93 : qs_environment_type
94 : USE qs_kind_types, ONLY: qs_kind_type
95 : USE qs_ks_types, ONLY: qs_ks_env_type
96 : USE qs_mo_types, ONLY: allocate_mo_set,&
97 : deallocate_mo_set,&
98 : get_mo_set,&
99 : init_mo_set,&
100 : mo_set_type,&
101 : set_mo_set
102 : USE qs_moments, ONLY: build_berry_moment_matrix,&
103 : build_local_moment_matrix
104 : USE qs_neighbor_list_types, ONLY: neighbor_list_set_p_type
105 : USE qs_overlap, ONLY: build_overlap_matrix
106 : USE qs_subsys_types, ONLY: qs_subsys_get,&
107 : qs_subsys_type
108 : USE qs_tddfpt2_types, ONLY: tddfpt_ground_state_mos
109 : USE string_utilities, ONLY: integer_to_string
110 : USE util, ONLY: sort
111 : #include "./base/base_uses.f90"
112 :
113 : IMPLICIT NONE
114 :
115 : PRIVATE
116 :
117 : CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_tddfpt2_properties'
118 :
119 : ! number of first derivative components (3: d/dx, d/dy, d/dz)
120 : INTEGER, PARAMETER, PRIVATE :: nderivs = 3
121 : INTEGER, PARAMETER, PRIVATE :: maxspins = 2
122 :
123 : PUBLIC :: tddfpt_dipole_operator, tddfpt_print_summary, tddfpt_print_excitation_analysis, &
124 : tddfpt_print_nto_analysis, tddfpt_print_exciton_descriptors
125 :
126 : ! **************************************************************************************************
127 :
128 : CONTAINS
129 :
130 : ! **************************************************************************************************
131 : !> \brief Compute the action of the dipole operator on the ground state wave function.
132 : !> \param dipole_op_mos_occ 2-D array [x,y,z ; spin] of matrices where to put the computed quantity
133 : !> (allocated and initialised on exit)
134 : !> \param tddfpt_control TDDFPT control parameters
135 : !> \param gs_mos molecular orbitals optimised for the ground state
136 : !> \param qs_env Quickstep environment
137 : !> \par History
138 : !> * 05.2016 created as 'tddfpt_print_summary' [Sergey Chulkov]
139 : !> * 06.2018 dipole operator based on the Berry-phase formula [Sergey Chulkov]
140 : !> * 08.2018 splited of from 'tddfpt_print_summary' and merged with code from 'tddfpt'
141 : !> [Sergey Chulkov]
142 : !> \note \parblock
143 : !> Adapted version of the subroutine find_contributions() which was originally created
144 : !> by Thomas Chassaing on 02.2005.
145 : !>
146 : !> The relation between dipole integrals in velocity and length forms are the following:
147 : !> \f[<\psi_i|\nabla|\psi_a> = <\psi_i|\vec{r}|\hat{H}\psi_a> - <\hat{H}\psi_i|\vec{r}|\psi_a>
148 : !> = (\epsilon_a - \epsilon_i) <\psi_i|\vec{r}|\psi_a> .\f],
149 : !> due to the commutation identity:
150 : !> \f[\vec{r}\hat{H} - \hat{H}\vec{r} = [\vec{r},\hat{H}] = [\vec{r},-1/2 \nabla^2] = \nabla\f] .
151 : !> \endparblock
152 : ! **************************************************************************************************
153 1450 : SUBROUTINE tddfpt_dipole_operator(dipole_op_mos_occ, tddfpt_control, gs_mos, qs_env)
154 : TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:, :), &
155 : INTENT(inout) :: dipole_op_mos_occ
156 : TYPE(tddfpt2_control_type), POINTER :: tddfpt_control
157 : TYPE(tddfpt_ground_state_mos), DIMENSION(:), &
158 : INTENT(in) :: gs_mos
159 : TYPE(qs_environment_type), POINTER :: qs_env
160 :
161 : CHARACTER(LEN=*), PARAMETER :: routineN = 'tddfpt_dipole_operator'
162 :
163 : INTEGER :: handle, i_cos_sin, icol, ideriv, irow, &
164 : ispin, jderiv, nao, ncols_local, &
165 : ndim_periodic, nrows_local, nspins
166 1450 : INTEGER, DIMENSION(:), POINTER :: col_indices, row_indices
167 : INTEGER, DIMENSION(maxspins) :: nmo_occ, nmo_virt
168 : REAL(kind=dp) :: eval_occ
169 : REAL(kind=dp), CONTIGUOUS, DIMENSION(:, :), &
170 1450 : POINTER :: local_data_ediff, local_data_wfm
171 : REAL(kind=dp), DIMENSION(3) :: kvec, reference_point
172 : TYPE(cell_type), POINTER :: cell
173 : TYPE(cp_blacs_env_type), POINTER :: blacs_env
174 1450 : TYPE(cp_cfm_type), ALLOCATABLE, DIMENSION(:) :: gamma_00, gamma_inv_00
175 : TYPE(cp_fm_struct_type), POINTER :: fm_struct
176 : TYPE(cp_fm_type) :: ediff_inv, wfm_ao_ao, wfm_mo_virt_mo_occ
177 1450 : TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:) :: S_mos_virt
178 1450 : TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:, :) :: dBerry_mos_occ, gamma_real_imag, opvec
179 1450 : TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: berry_cossin_xyz, matrix_s, rRc_xyz, scrm
180 : TYPE(dft_control_type), POINTER :: dft_control
181 : TYPE(neighbor_list_set_p_type), DIMENSION(:), &
182 1450 : POINTER :: sab_orb
183 : TYPE(pw_env_type), POINTER :: pw_env
184 : TYPE(pw_poisson_type), POINTER :: poisson_env
185 : TYPE(qs_ks_env_type), POINTER :: ks_env
186 :
187 1450 : CALL timeset(routineN, handle)
188 :
189 1450 : NULLIFY (blacs_env, cell, matrix_s, pw_env)
190 1450 : CALL get_qs_env(qs_env, blacs_env=blacs_env, cell=cell, matrix_s=matrix_s, pw_env=pw_env)
191 :
192 1450 : nspins = SIZE(gs_mos)
193 1450 : CALL dbcsr_get_info(matrix_s(1)%matrix, nfullrows_total=nao)
194 3114 : DO ispin = 1, nspins
195 1664 : nmo_occ(ispin) = SIZE(gs_mos(ispin)%evals_occ)
196 3114 : nmo_virt(ispin) = SIZE(gs_mos(ispin)%evals_virt)
197 : END DO
198 :
199 : ! +++ allocate dipole operator matrices (must be deallocated elsewhere)
200 11006 : ALLOCATE (dipole_op_mos_occ(nderivs, nspins))
201 3114 : DO ispin = 1, nspins
202 1664 : CALL cp_fm_get_info(gs_mos(ispin)%mos_occ, matrix_struct=fm_struct)
203 :
204 8106 : DO ideriv = 1, nderivs
205 6656 : CALL cp_fm_create(dipole_op_mos_occ(ideriv, ispin), fm_struct)
206 : END DO
207 : END DO
208 :
209 : ! +++ allocate work matrices
210 6014 : ALLOCATE (S_mos_virt(nspins))
211 3114 : DO ispin = 1, nspins
212 1664 : CALL cp_fm_get_info(gs_mos(ispin)%mos_virt, matrix_struct=fm_struct)
213 1664 : CALL cp_fm_create(S_mos_virt(ispin), fm_struct)
214 : CALL cp_dbcsr_sm_fm_multiply(matrix_s(1)%matrix, &
215 : gs_mos(ispin)%mos_virt, &
216 : S_mos_virt(ispin), &
217 3114 : ncol=nmo_virt(ispin), alpha=1.0_dp, beta=0.0_dp)
218 : END DO
219 :
220 : ! check that the chosen dipole operator is consistent with the periodic boundary conditions used
221 1450 : CALL pw_env_get(pw_env, poisson_env=poisson_env)
222 5800 : ndim_periodic = COUNT(poisson_env%parameters%periodic == 1)
223 :
224 : ! select default for dipole form
225 1450 : IF (tddfpt_control%dipole_form == 0) THEN
226 662 : CALL get_qs_env(qs_env, dft_control=dft_control)
227 662 : IF (dft_control%qs_control%xtb) THEN
228 44 : IF (ndim_periodic == 0) THEN
229 0 : tddfpt_control%dipole_form = tddfpt_dipole_length
230 : ELSE
231 44 : tddfpt_control%dipole_form = tddfpt_dipole_velocity
232 : END IF
233 : ELSE
234 618 : tddfpt_control%dipole_form = tddfpt_dipole_velocity
235 : END IF
236 : END IF
237 :
238 1454 : SELECT CASE (tddfpt_control%dipole_form)
239 : CASE (tddfpt_dipole_berry)
240 4 : IF (ndim_periodic /= 3) THEN
241 : CALL cp_warn(__LOCATION__, &
242 : "Fully periodic Poisson solver (PERIODIC xyz) "// &
243 : "or a large supercell in non-periodic directions is needed "// &
244 0 : "for oscillator strengths based on the Berry phase formula")
245 : END IF
246 :
247 4 : NULLIFY (berry_cossin_xyz)
248 : ! index: 1 = Re[exp(-i * G_t * t)],
249 : ! 2 = Im[exp(-i * G_t * t)];
250 : ! t = x,y,z
251 4 : CALL dbcsr_allocate_matrix_set(berry_cossin_xyz, 2)
252 :
253 12 : DO i_cos_sin = 1, 2
254 8 : CALL dbcsr_init_p(berry_cossin_xyz(i_cos_sin)%matrix)
255 12 : CALL dbcsr_copy(berry_cossin_xyz(i_cos_sin)%matrix, matrix_s(1)%matrix)
256 : END DO
257 :
258 : ! +++ allocate berry-phase-related work matrices
259 72 : ALLOCATE (gamma_00(nspins), gamma_inv_00(nspins), gamma_real_imag(2, nspins), opvec(2, nspins))
260 32 : ALLOCATE (dBerry_mos_occ(nderivs, nspins))
261 10 : DO ispin = 1, nspins
262 6 : NULLIFY (fm_struct)
263 : CALL cp_fm_struct_create(fm_struct, nrow_global=nmo_occ(ispin), &
264 6 : ncol_global=nmo_occ(ispin), context=blacs_env)
265 :
266 6 : CALL cp_cfm_create(gamma_00(ispin), fm_struct)
267 6 : CALL cp_cfm_create(gamma_inv_00(ispin), fm_struct)
268 :
269 18 : DO i_cos_sin = 1, 2
270 18 : CALL cp_fm_create(gamma_real_imag(i_cos_sin, ispin), fm_struct)
271 : END DO
272 6 : CALL cp_fm_struct_release(fm_struct)
273 :
274 : ! G_real C_0, G_imag C_0
275 6 : CALL cp_fm_get_info(gs_mos(ispin)%mos_occ, matrix_struct=fm_struct)
276 18 : DO i_cos_sin = 1, 2
277 18 : CALL cp_fm_create(opvec(i_cos_sin, ispin), fm_struct)
278 : END DO
279 :
280 : ! dBerry * C_0
281 28 : DO ideriv = 1, nderivs
282 18 : CALL cp_fm_create(dBerry_mos_occ(ideriv, ispin), fm_struct)
283 24 : CALL cp_fm_set_all(dBerry_mos_occ(ideriv, ispin), 0.0_dp)
284 : END DO
285 : END DO
286 :
287 16 : DO ideriv = 1, nderivs
288 48 : kvec(:) = twopi*cell%h_inv(ideriv, :)
289 : CALL build_berry_moment_matrix(qs_env, berry_cossin_xyz(1)%matrix, &
290 12 : berry_cossin_xyz(2)%matrix, kvec)
291 :
292 34 : DO ispin = 1, nspins
293 : ! i_cos_sin = 1: cos (real) component; opvec(1) = gamma_real C_0
294 : ! i_cos_sin = 2: sin (imaginary) component; opvec(2) = gamma_imag C_0
295 54 : DO i_cos_sin = 1, 2
296 : CALL cp_dbcsr_sm_fm_multiply(berry_cossin_xyz(i_cos_sin)%matrix, &
297 : gs_mos(ispin)%mos_occ, &
298 : opvec(i_cos_sin, ispin), &
299 54 : ncol=nmo_occ(ispin), alpha=1.0_dp, beta=0.0_dp)
300 : END DO
301 :
302 : CALL parallel_gemm('T', 'N', nmo_occ(ispin), nmo_occ(ispin), nao, &
303 : 1.0_dp, gs_mos(ispin)%mos_occ, opvec(1, ispin), &
304 18 : 0.0_dp, gamma_real_imag(1, ispin))
305 :
306 : CALL parallel_gemm('T', 'N', nmo_occ(ispin), nmo_occ(ispin), nao, &
307 : -1.0_dp, gs_mos(ispin)%mos_occ, opvec(2, ispin), &
308 18 : 0.0_dp, gamma_real_imag(2, ispin))
309 :
310 : CALL cp_fm_to_cfm(msourcer=gamma_real_imag(1, ispin), &
311 : msourcei=gamma_real_imag(2, ispin), &
312 18 : mtarget=gamma_00(ispin))
313 :
314 : ! gamma_inv_00 = Q = [C_0^T (gamma_real - i gamma_imag) C_0] ^ {-1}
315 18 : CALL cp_cfm_set_all(gamma_inv_00(ispin), z_zero, z_one)
316 18 : CALL cp_cfm_solve(gamma_00(ispin), gamma_inv_00(ispin))
317 :
318 : CALL cp_cfm_to_fm(msource=gamma_inv_00(ispin), &
319 : mtargetr=gamma_real_imag(1, ispin), &
320 18 : mtargeti=gamma_real_imag(2, ispin))
321 :
322 : ! dBerry_mos_occ is identical to dBerry_psi0 from qs_linres_op % polar_operators()
323 : CALL parallel_gemm("N", "N", nao, nmo_occ(ispin), nmo_occ(ispin), &
324 : 1.0_dp, opvec(1, ispin), gamma_real_imag(2, ispin), &
325 18 : 0.0_dp, dipole_op_mos_occ(1, ispin))
326 : CALL parallel_gemm("N", "N", nao, nmo_occ(ispin), nmo_occ(ispin), &
327 : -1.0_dp, opvec(2, ispin), gamma_real_imag(1, ispin), &
328 18 : 1.0_dp, dipole_op_mos_occ(1, ispin))
329 :
330 84 : DO jderiv = 1, nderivs
331 : CALL cp_fm_scale_and_add(1.0_dp, dBerry_mos_occ(jderiv, ispin), &
332 72 : cell%hmat(jderiv, ideriv), dipole_op_mos_occ(1, ispin))
333 : END DO
334 : END DO
335 : END DO
336 :
337 : ! --- release berry-phase-related work matrices
338 4 : CALL cp_fm_release(opvec)
339 4 : CALL cp_fm_release(gamma_real_imag)
340 10 : DO ispin = nspins, 1, -1
341 6 : CALL cp_cfm_release(gamma_inv_00(ispin))
342 10 : CALL cp_cfm_release(gamma_00(ispin))
343 : END DO
344 4 : DEALLOCATE (gamma_00, gamma_inv_00)
345 4 : CALL dbcsr_deallocate_matrix_set(berry_cossin_xyz)
346 :
347 : ! trans_dipole = 2|e|/|G_mu| * Tr Imag(evects^T * (gamma_real - i gamma_imag) * C_0 * gamma_inv_00) +
348 : ! 2|e|/|G_mu| * Tr Imag(C_0^T * (gamma_real - i gamma_imag) * evects * gamma_inv_00) ,
349 : !
350 : ! Taking into account the symmetry of the matrices 'gamma_real' and 'gamma_imag' and the fact
351 : ! that the response wave-function is a real-valued function, the above expression can be simplified as
352 : ! trans_dipole = 4|e|/|G_mu| * Tr Imag(evects^T * (gamma_real - i gamma_imag) * C_0 * gamma_inv_00)
353 : !
354 : ! 1/|G_mu| = |lattice_vector_mu| / (2*pi) .
355 10 : DO ispin = 1, nspins
356 :
357 28 : DO ideriv = 1, nderivs
358 24 : CALL cp_fm_to_fm(dBerry_mos_occ(ideriv, ispin), dipole_op_mos_occ(ideriv, ispin))
359 : END DO
360 : END DO
361 :
362 4 : CALL cp_fm_release(wfm_ao_ao)
363 4 : CALL cp_fm_release(dBerry_mos_occ)
364 :
365 : CASE (tddfpt_dipole_length)
366 20 : IF (ndim_periodic /= 0) THEN
367 : CALL cp_warn(__LOCATION__, &
368 : "Non-periodic Poisson solver (PERIODIC none) "// &
369 : "or a large supercell approach is needed "// &
370 4 : "for oscillator strengths based on the length operator")
371 : END IF
372 :
373 : ! compute components of the dipole operator in the length form
374 20 : NULLIFY (rRc_xyz)
375 20 : CALL dbcsr_allocate_matrix_set(rRc_xyz, nderivs)
376 :
377 80 : DO ideriv = 1, nderivs
378 60 : CALL dbcsr_init_p(rRc_xyz(ideriv)%matrix)
379 80 : CALL dbcsr_copy(rRc_xyz(ideriv)%matrix, matrix_s(1)%matrix)
380 : END DO
381 :
382 : CALL get_reference_point(reference_point, qs_env=qs_env, &
383 : reference=tddfpt_control%dipole_reference, &
384 20 : ref_point=tddfpt_control%dipole_ref_point)
385 :
386 : CALL build_local_moment_matrix(qs_env, rRc_xyz, 1, ref_point=reference_point, &
387 20 : all_images=.TRUE.)
388 :
389 42 : DO ispin = 1, nspins
390 :
391 108 : DO ideriv = 1, nderivs
392 : CALL cp_dbcsr_sm_fm_multiply(rRc_xyz(ideriv)%matrix, &
393 : gs_mos(ispin)%mos_occ, &
394 : dipole_op_mos_occ(ideriv, ispin), &
395 88 : ncol=nmo_occ(ispin), alpha=1.0_dp, beta=0.0_dp)
396 : END DO
397 :
398 : END DO
399 :
400 20 : CALL dbcsr_deallocate_matrix_set(rRc_xyz)
401 :
402 : CASE (tddfpt_dipole_velocity)
403 : ! generate overlap derivatives
404 1422 : CALL get_qs_env(qs_env, ks_env=ks_env, sab_orb=sab_orb)
405 1422 : NULLIFY (scrm)
406 : CALL build_overlap_matrix(ks_env, matrix_s=scrm, nderivative=1, &
407 : basis_type_a="ORB", basis_type_b="ORB", &
408 1422 : sab_nl=sab_orb)
409 :
410 3052 : DO ispin = 1, nspins
411 6520 : DO ideriv = 1, nderivs
412 : CALL cp_dbcsr_sm_fm_multiply(scrm(ideriv + 1)%matrix, &
413 : gs_mos(ispin)%mos_occ, &
414 : dipole_op_mos_occ(ideriv, ispin), &
415 6520 : ncol=nmo_occ(ispin), alpha=1.0_dp, beta=0.0_dp)
416 : END DO
417 :
418 3052 : CALL cp_fm_release(wfm_mo_virt_mo_occ)
419 : END DO
420 1422 : CALL dbcsr_deallocate_matrix_set(scrm)
421 :
422 : CASE (tddfpt_dipole_velocity_old)
423 : ! generate overlap derivatives
424 4 : CALL get_qs_env(qs_env, ks_env=ks_env, sab_orb=sab_orb)
425 4 : NULLIFY (scrm)
426 : CALL build_overlap_matrix(ks_env, matrix_s=scrm, nderivative=1, &
427 : basis_type_a="ORB", basis_type_b="ORB", &
428 4 : sab_nl=sab_orb)
429 :
430 10 : DO ispin = 1, nspins
431 6 : NULLIFY (fm_struct)
432 : CALL cp_fm_struct_create(fm_struct, nrow_global=nmo_virt(ispin), &
433 6 : ncol_global=nmo_occ(ispin), context=blacs_env)
434 6 : CALL cp_fm_create(ediff_inv, fm_struct)
435 6 : CALL cp_fm_create(wfm_mo_virt_mo_occ, fm_struct)
436 6 : CALL cp_fm_struct_release(fm_struct)
437 :
438 : CALL cp_fm_get_info(ediff_inv, nrow_local=nrows_local, ncol_local=ncols_local, &
439 6 : row_indices=row_indices, col_indices=col_indices, local_data=local_data_ediff)
440 6 : CALL cp_fm_get_info(wfm_mo_virt_mo_occ, local_data=local_data_wfm)
441 :
442 : !$OMP PARALLEL DO DEFAULT(NONE), &
443 : !$OMP PRIVATE(eval_occ, icol, irow), &
444 6 : !$OMP SHARED(col_indices, gs_mos, ispin, local_data_ediff, ncols_local, nrows_local, row_indices)
445 : DO icol = 1, ncols_local
446 : ! E_occ_i ; imo_occ = col_indices(icol)
447 : eval_occ = gs_mos(ispin)%evals_occ(col_indices(icol))
448 :
449 : DO irow = 1, nrows_local
450 : ! ediff_inv_weights(a, i) = 1.0 / (E_virt_a - E_occ_i)
451 : ! imo_virt = row_indices(irow)
452 : local_data_ediff(irow, icol) = 1.0_dp/(gs_mos(ispin)%evals_virt(row_indices(irow)) - eval_occ)
453 : END DO
454 : END DO
455 : !$OMP END PARALLEL DO
456 :
457 24 : DO ideriv = 1, nderivs
458 : CALL cp_dbcsr_sm_fm_multiply(scrm(ideriv + 1)%matrix, &
459 : gs_mos(ispin)%mos_occ, &
460 : dipole_op_mos_occ(ideriv, ispin), &
461 18 : ncol=nmo_occ(ispin), alpha=1.0_dp, beta=0.0_dp)
462 :
463 : CALL parallel_gemm('T', 'N', nmo_virt(ispin), nmo_occ(ispin), nao, &
464 : 1.0_dp, gs_mos(ispin)%mos_virt, dipole_op_mos_occ(ideriv, ispin), &
465 18 : 0.0_dp, wfm_mo_virt_mo_occ)
466 :
467 : ! in-place element-wise (Schur) product;
468 : ! avoid allocation of a temporary [nmo_virt x nmo_occ] matrix which is needed
469 : ! for cp_fm_schur_product() subroutine call
470 :
471 : !$OMP PARALLEL DO DEFAULT(NONE), &
472 : !$OMP PRIVATE(icol, irow), &
473 18 : !$OMP SHARED(ispin, local_data_ediff, local_data_wfm, ncols_local, nrows_local)
474 : DO icol = 1, ncols_local
475 : DO irow = 1, nrows_local
476 : local_data_wfm(irow, icol) = local_data_wfm(irow, icol)*local_data_ediff(irow, icol)
477 : END DO
478 : END DO
479 : !$OMP END PARALLEL DO
480 :
481 : CALL parallel_gemm('N', 'N', nao, nmo_occ(ispin), nmo_virt(ispin), &
482 : 1.0_dp, S_mos_virt(ispin), wfm_mo_virt_mo_occ, &
483 24 : 0.0_dp, dipole_op_mos_occ(ideriv, ispin))
484 : END DO
485 :
486 6 : CALL cp_fm_release(wfm_mo_virt_mo_occ)
487 22 : CALL cp_fm_release(ediff_inv)
488 : END DO
489 4 : CALL dbcsr_deallocate_matrix_set(scrm)
490 :
491 : CASE DEFAULT
492 1450 : CPABORT("Unimplemented form of the dipole operator")
493 : END SELECT
494 :
495 : ! --- release work matrices
496 1450 : CALL cp_fm_release(S_mos_virt)
497 :
498 1450 : CALL timestop(handle)
499 4350 : END SUBROUTINE tddfpt_dipole_operator
500 :
501 : ! **************************************************************************************************
502 : !> \brief Print final TDDFPT excitation energies and oscillator strengths.
503 : !> \param log_unit output unit
504 : !> \param evects TDDFPT trial vectors (SIZE(evects,1) -- number of spins;
505 : !> SIZE(evects,2) -- number of excited states to print)
506 : !> \param evals TDDFPT eigenvalues
507 : !> \param gs_mos ...
508 : !> \param ostrength TDDFPT oscillator strength
509 : !> \param mult multiplicity
510 : !> \param dipole_op_mos_occ action of the dipole operator on the ground state wave function
511 : !> [x,y,z ; spin]
512 : !> \param dipole_form ...
513 : !> \par History
514 : !> * 05.2016 created [Sergey Chulkov]
515 : !> * 06.2016 transition dipole moments and oscillator strengths [Sergey Chulkov]
516 : !> * 07.2016 spin-unpolarised electron density [Sergey Chulkov]
517 : !> * 08.2018 compute 'dipole_op_mos_occ' in a separate subroutine [Sergey Chulkov]
518 : !> \note \parblock
519 : !> Adapted version of the subroutine find_contributions() which was originally created
520 : !> by Thomas Chassaing on 02.2005.
521 : !>
522 : !> Transition dipole moment along direction 'd' is computed as following:
523 : !> \f[ t_d(spin) = Tr[evects^T dipole\_op\_mos\_occ(d, spin)] .\f]
524 : !> \endparblock
525 : ! **************************************************************************************************
526 2920 : SUBROUTINE tddfpt_print_summary(log_unit, evects, evals, gs_mos, ostrength, mult, &
527 1460 : dipole_op_mos_occ, dipole_form)
528 : INTEGER, INTENT(in) :: log_unit
529 : TYPE(cp_fm_type), DIMENSION(:, :), INTENT(in) :: evects
530 : REAL(kind=dp), DIMENSION(:), INTENT(in) :: evals
531 : TYPE(tddfpt_ground_state_mos), DIMENSION(:), &
532 : POINTER :: gs_mos
533 : REAL(kind=dp), DIMENSION(:), INTENT(inout) :: ostrength
534 : INTEGER, INTENT(in) :: mult
535 : TYPE(cp_fm_type), DIMENSION(:, :), INTENT(in) :: dipole_op_mos_occ
536 : INTEGER, INTENT(in) :: dipole_form
537 :
538 : CHARACTER(LEN=*), PARAMETER :: routineN = 'tddfpt_print_summary'
539 :
540 : CHARACTER(len=1) :: lsd_str
541 : CHARACTER(len=20) :: mult_str
542 : INTEGER :: handle, i, ideriv, ispin, istate, j, &
543 : nactive, nao, nocc, nspins, nstates
544 : REAL(kind=dp) :: osc_strength
545 1460 : REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :, :) :: trans_dipoles
546 : TYPE(cp_fm_struct_type), POINTER :: matrix_struct
547 : TYPE(cp_fm_type) :: dipact
548 :
549 1460 : CALL timeset(routineN, handle)
550 :
551 1460 : nspins = SIZE(evects, 1)
552 1460 : nstates = SIZE(evects, 2)
553 :
554 1460 : IF (nspins > 1) THEN
555 188 : lsd_str = 'U'
556 : ELSE
557 1272 : lsd_str = 'R'
558 : END IF
559 :
560 : ! *** summary header ***
561 1460 : IF (log_unit > 0) THEN
562 730 : CALL integer_to_string(mult, mult_str)
563 730 : WRITE (log_unit, '(/,1X,A1,A,1X,A)') lsd_str, "-TDDFPT states of multiplicity", TRIM(mult_str)
564 732 : SELECT CASE (dipole_form)
565 : CASE (tddfpt_dipole_berry)
566 2 : WRITE (log_unit, '(1X,A,/)') "Transition dipoles calculated using Berry operator formulation"
567 : CASE (tddfpt_dipole_length)
568 14 : WRITE (log_unit, '(1X,A,/)') "Transition dipoles calculated using length formulation"
569 : CASE (tddfpt_dipole_velocity)
570 712 : WRITE (log_unit, '(1X,A,/)') "Transition dipoles calculated using velocity formulation"
571 : CASE (tddfpt_dipole_velocity_old)
572 2 : WRITE (log_unit, '(1X,A,/)') "Transition dipoles calculated using old velocity formulation"
573 : CASE (tddfpt_dipole_scf_moment)
574 0 : WRITE (log_unit, '(1X,A,/)') "Transition dipoles calculated using SCF-MO moment formulation"
575 : CASE DEFAULT
576 730 : CPABORT("Unimplemented form of the dipole operator")
577 : END SELECT
578 :
579 730 : WRITE (log_unit, '(T10,A,T19,A,T37,A,T69,A)') "State", "Excitation", &
580 1460 : "Transition dipole (a.u.)", "Oscillator"
581 730 : WRITE (log_unit, '(T10,A,T19,A,T37,A,T49,A,T61,A,T67,A)') "number", "energy (eV)", &
582 1460 : "x", "y", "z", "strength (a.u.)"
583 730 : WRITE (log_unit, '(T10,72("-"))')
584 : END IF
585 :
586 : ! transition dipole moment
587 5840 : ALLOCATE (trans_dipoles(nstates, nderivs, nspins))
588 1460 : trans_dipoles(:, :, :) = 0.0_dp
589 :
590 : ! nspins == 1 .AND. mult == 3 : spin-flip transitions are forbidden due to symmetry reasons
591 1460 : IF (nspins > 1 .OR. mult == 1) THEN
592 2644 : DO ispin = 1, nspins
593 1416 : CALL cp_fm_get_info(dipole_op_mos_occ(1, ispin), nrow_global=nao, ncol_global=nocc)
594 1416 : CALL cp_fm_get_info(evects(ispin, 1), ncol_global=nactive)
595 2644 : IF (nocc == nactive) THEN
596 5600 : DO ideriv = 1, nderivs
597 : CALL cp_fm_trace(evects(ispin, :), dipole_op_mos_occ(ideriv, ispin), &
598 5600 : trans_dipoles(:, ideriv, ispin))
599 : END DO
600 : ELSE ! res
601 16 : CALL cp_fm_get_info(evects(ispin, 1), matrix_struct=matrix_struct)
602 16 : CALL cp_fm_create(dipact, matrix_struct)
603 64 : DO ideriv = 1, nderivs
604 144 : DO i = 1, nactive
605 96 : j = gs_mos(ispin)%index_active(i)
606 : CALL cp_fm_to_fm(dipole_op_mos_occ(ideriv, ispin), dipact, &
607 144 : ncol=1, source_start=j, target_start=i)
608 : END DO
609 64 : CALL cp_fm_trace(evects(ispin, :), dipact, trans_dipoles(:, ideriv, ispin))
610 : END DO
611 16 : CALL cp_fm_release(dipact)
612 : END IF
613 : END DO
614 :
615 1228 : IF (nspins == 1) THEN
616 11138 : trans_dipoles(:, :, 1) = SQRT(2.0_dp)*trans_dipoles(:, :, 1)
617 : ELSE
618 2612 : trans_dipoles(:, :, 1) = trans_dipoles(:, :, 1) + trans_dipoles(:, :, 2)
619 : END IF
620 : END IF
621 :
622 : ! *** summary information ***
623 5164 : DO istate = 1, nstates
624 :
625 3716 : SELECT CASE (dipole_form)
626 : CASE (tddfpt_dipole_berry)
627 48 : osc_strength = 2.0_dp/3.0_dp*evals(istate)*SUM(trans_dipoles(istate, :, 1)**2)
628 : CASE (tddfpt_dipole_length)
629 416 : osc_strength = 2.0_dp/3.0_dp*evals(istate)*SUM(trans_dipoles(istate, :, 1)**2)
630 : CASE (tddfpt_dipole_velocity)
631 14304 : osc_strength = 2.0_dp/3.0_dp/evals(istate)*SUM(trans_dipoles(istate, :, 1)**2)
632 : CASE (tddfpt_dipole_velocity_old)
633 48 : osc_strength = 2.0_dp/3.0_dp*evals(istate)*SUM(trans_dipoles(istate, :, 1)**2)
634 : CASE DEFAULT
635 3704 : CPABORT("Unimplemented form of the dipole operator")
636 : END SELECT
637 :
638 3704 : ostrength(istate) = osc_strength
639 5164 : IF (log_unit > 0) THEN
640 : WRITE (log_unit, '(1X,A,T9,I7,T19,F11.5,T31,3(1X,ES11.4E2),T69,ES12.5E2)') &
641 1852 : "TDDFPT|", istate, evals(istate)*evolt, trans_dipoles(istate, 1:nderivs, 1), osc_strength
642 : END IF
643 : END DO
644 :
645 : ! punch a checksum for the regs
646 1460 : IF (log_unit > 0) THEN
647 2582 : WRITE (log_unit, '(/,T2,A,E16.8)') 'TDDFPT : CheckSum E = ', SQRT(SUM(evals**2))
648 2582 : WRITE (log_unit, '(/,T2,A,E16.8)') 'TDDFPT : CheckSum F = ', SQRT(SUM(ostrength**2))
649 : END IF
650 :
651 1460 : DEALLOCATE (trans_dipoles)
652 :
653 1460 : CALL timestop(handle)
654 1460 : END SUBROUTINE tddfpt_print_summary
655 :
656 : ! **************************************************************************************************
657 : !> \brief Print excitation analysis.
658 : !> \param log_unit output unit
659 : !> \param evects TDDFPT trial vectors (SIZE(evects,1) -- number of spins;
660 : !> SIZE(evects,2) -- number of excited states to print)
661 : !> \param evals TDDFPT eigenvalues
662 : !> \param gs_mos molecular orbitals optimised for the ground state
663 : !> \param matrix_s overlap matrix
664 : !> \param spinflip ...
665 : !> \param min_amplitude the smallest excitation amplitude to print
666 : !> \par History
667 : !> * 05.2016 created as 'tddfpt_print_summary' [Sergey Chulkov]
668 : !> * 08.2018 splited of from 'tddfpt_print_summary' [Sergey Chulkov]
669 : ! **************************************************************************************************
670 1460 : SUBROUTINE tddfpt_print_excitation_analysis(log_unit, evects, evals, gs_mos, matrix_s, spinflip, &
671 : min_amplitude)
672 : INTEGER, INTENT(in) :: log_unit
673 : TYPE(cp_fm_type), DIMENSION(:, :), INTENT(in) :: evects
674 : REAL(kind=dp), DIMENSION(:), INTENT(in) :: evals
675 : TYPE(tddfpt_ground_state_mos), DIMENSION(:), &
676 : INTENT(in) :: gs_mos
677 : TYPE(dbcsr_type), POINTER :: matrix_s
678 : INTEGER :: spinflip
679 : REAL(kind=dp), INTENT(in) :: min_amplitude
680 :
681 : CHARACTER(LEN=*), PARAMETER :: routineN = 'tddfpt_print_excitation_analysis'
682 :
683 : CHARACTER(len=5) :: spin_label, spin_label2
684 : INTEGER :: handle, icol, iproc, irow, ispin, &
685 : istate, nao, ncols_local, nrows_local, &
686 : nspins, nstates, spin2, state_spin, &
687 : state_spin2
688 : INTEGER(kind=int_8) :: iexc, imo_act, imo_occ, imo_virt, ind, &
689 : nexcs, nexcs_local, nexcs_max_local, &
690 : nmo_virt_occ, nmo_virt_occ_alpha
691 1460 : INTEGER(kind=int_8), ALLOCATABLE, DIMENSION(:) :: inds_local, inds_recv, nexcs_recv
692 : INTEGER(kind=int_8), DIMENSION(1) :: nexcs_send
693 : INTEGER(kind=int_8), DIMENSION(maxspins) :: nactive8, nmo_occ8, nmo_virt8
694 1460 : INTEGER, ALLOCATABLE, DIMENSION(:) :: inds
695 1460 : INTEGER, DIMENSION(:), POINTER :: col_indices, row_indices
696 : INTEGER, DIMENSION(maxspins) :: nactive, nmo_occ, nmo_virt
697 : LOGICAL :: do_exc_analysis
698 1460 : REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: weights_local, weights_neg_abs_recv, &
699 1460 : weights_recv
700 : REAL(kind=dp), CONTIGUOUS, DIMENSION(:, :), &
701 1460 : POINTER :: local_data
702 : TYPE(cp_blacs_env_type), POINTER :: blacs_env
703 : TYPE(cp_fm_struct_type), POINTER :: fm_struct
704 1460 : TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:) :: S_mos_virt, weights_fm
705 : TYPE(mp_para_env_type), POINTER :: para_env
706 : TYPE(mp_request_type) :: send_handler, send_handler2
707 1460 : TYPE(mp_request_type), ALLOCATABLE, DIMENSION(:) :: recv_handlers, recv_handlers2
708 :
709 1460 : CALL timeset(routineN, handle)
710 :
711 1460 : nspins = SIZE(gs_mos, 1)
712 1460 : nstates = SIZE(evects, 2)
713 1460 : do_exc_analysis = min_amplitude < 1.0_dp
714 :
715 1460 : CALL cp_fm_get_info(gs_mos(1)%mos_occ, context=blacs_env, para_env=para_env)
716 1460 : CALL dbcsr_get_info(matrix_s, nfullrows_total=nao)
717 :
718 3134 : DO ispin = 1, nspins
719 1674 : nactive(ispin) = gs_mos(ispin)%nmo_active
720 : nactive8(ispin) = INT(nactive(ispin), kind=int_8)
721 1674 : nmo_occ(ispin) = SIZE(gs_mos(ispin)%evals_occ)
722 1674 : nmo_virt(ispin) = SIZE(gs_mos(ispin)%evals_virt)
723 1674 : nmo_occ8(ispin) = SIZE(gs_mos(ispin)%evals_occ, kind=int_8)
724 3134 : nmo_virt8(ispin) = SIZE(gs_mos(ispin)%evals_virt, kind=int_8)
725 : END DO
726 :
727 : ! *** excitation analysis ***
728 1460 : IF (do_exc_analysis) THEN
729 1460 : CPASSERT(log_unit <= 0 .OR. para_env%is_source())
730 1460 : nmo_virt_occ_alpha = INT(nmo_virt(1), int_8)*INT(nmo_occ(1), int_8)
731 :
732 1460 : IF (log_unit > 0) THEN
733 730 : WRITE (log_unit, "(1X,A)") "", &
734 730 : "-------------------------------------------------------------------------------", &
735 730 : "- Excitation analysis -", &
736 1460 : "-------------------------------------------------------------------------------"
737 730 : WRITE (log_unit, '(8X,A,T27,A,T49,A,T69,A)') "State", "Occupied", "Virtual", "Excitation"
738 730 : WRITE (log_unit, '(8X,A,T28,A,T49,A,T69,A)') "number", "orbital", "orbital", "amplitude"
739 730 : WRITE (log_unit, '(1X,79("-"))')
740 :
741 730 : IF (nspins == 1) THEN
742 623 : state_spin = 1
743 623 : state_spin2 = 2
744 623 : spin_label = ' '
745 623 : spin_label2 = ' '
746 107 : ELSE IF (spinflip /= no_sf_tddfpt) THEN
747 13 : state_spin = 1
748 13 : state_spin2 = 2
749 13 : spin_label = '(alp)'
750 13 : spin_label2 = '(bet)'
751 : END IF
752 : END IF
753 :
754 9136 : ALLOCATE (S_mos_virt(SIZE(evects, 1)), weights_fm(SIZE(evects, 1)))
755 3108 : DO ispin = 1, SIZE(evects, 1)
756 1648 : IF (spinflip == no_sf_tddfpt) THEN
757 : spin2 = ispin
758 : ELSE
759 26 : spin2 = 2
760 : END IF
761 1648 : CALL cp_fm_get_info(gs_mos(spin2)%mos_virt, matrix_struct=fm_struct)
762 1648 : CALL cp_fm_create(S_mos_virt(ispin), fm_struct)
763 : CALL cp_dbcsr_sm_fm_multiply(matrix_s, &
764 : gs_mos(spin2)%mos_virt, &
765 : S_mos_virt(ispin), &
766 1648 : ncol=nmo_virt(spin2), alpha=1.0_dp, beta=0.0_dp)
767 :
768 1648 : NULLIFY (fm_struct)
769 : CALL cp_fm_struct_create(fm_struct, nrow_global=nmo_virt(spin2), ncol_global=nactive(ispin), &
770 1648 : context=blacs_env)
771 1648 : CALL cp_fm_create(weights_fm(ispin), fm_struct)
772 1648 : CALL cp_fm_set_all(weights_fm(ispin), 0.0_dp)
773 3108 : CALL cp_fm_struct_release(fm_struct)
774 : END DO
775 :
776 3108 : nexcs_max_local = 0
777 3108 : DO ispin = 1, SIZE(evects, 1)
778 1648 : CALL cp_fm_get_info(weights_fm(ispin), nrow_local=nrows_local, ncol_local=ncols_local)
779 3108 : nexcs_max_local = nexcs_max_local + INT(nrows_local, int_8)*INT(ncols_local, int_8)
780 : END DO
781 :
782 5840 : ALLOCATE (weights_local(nexcs_max_local), inds_local(nexcs_max_local))
783 :
784 5164 : DO istate = 1, nstates
785 8028 : nexcs_local = 0
786 8028 : nmo_virt_occ = 0
787 :
788 : ! analyse matrix elements locally and transfer only significant
789 : ! excitations to the master node for subsequent ordering
790 8028 : DO ispin = 1, SIZE(evects, 1)
791 4324 : IF (spinflip == no_sf_tddfpt) THEN
792 : spin2 = ispin
793 : ELSE
794 110 : spin2 = 2
795 : END IF
796 : ! compute excitation amplitudes
797 : CALL parallel_gemm('T', 'N', nmo_virt(spin2), nactive(ispin), nao, 1.0_dp, S_mos_virt(ispin), &
798 4324 : evects(ispin, istate), 0.0_dp, weights_fm(ispin))
799 :
800 : CALL cp_fm_get_info(weights_fm(ispin), nrow_local=nrows_local, ncol_local=ncols_local, &
801 4324 : row_indices=row_indices, col_indices=col_indices, local_data=local_data)
802 :
803 : ! locate single excitations with significant amplitudes (>= min_amplitude)
804 23738 : DO icol = 1, ncols_local
805 239791 : DO irow = 1, nrows_local
806 235467 : IF (ABS(local_data(irow, icol)) >= min_amplitude) THEN
807 : ! number of non-negligible excitations
808 2959 : nexcs_local = nexcs_local + 1
809 : ! excitation amplitude
810 2959 : weights_local(nexcs_local) = local_data(irow, icol)
811 : ! index of single excitation (ivirt, iocc, ispin) in compressed form
812 : inds_local(nexcs_local) = nmo_virt_occ + INT(row_indices(irow), int_8) + &
813 2959 : INT(col_indices(icol) - 1, int_8)*nmo_virt8(spin2)
814 : END IF
815 : END DO
816 : END DO
817 :
818 12352 : nmo_virt_occ = nmo_virt_occ + nmo_virt8(spin2)*nmo_occ8(ispin)
819 : END DO
820 :
821 3704 : IF (para_env%is_source()) THEN
822 : ! master node
823 18520 : ALLOCATE (nexcs_recv(para_env%num_pe), recv_handlers(para_env%num_pe), recv_handlers2(para_env%num_pe))
824 :
825 : ! collect number of non-negligible excitations from other nodes
826 5556 : DO iproc = 1, para_env%num_pe
827 5556 : IF (iproc - 1 /= para_env%mepos) THEN
828 1852 : CALL para_env%irecv(nexcs_recv(iproc:iproc), iproc - 1, recv_handlers(iproc), 0)
829 : ELSE
830 1852 : nexcs_recv(iproc) = nexcs_local
831 : END IF
832 : END DO
833 :
834 5556 : DO iproc = 1, para_env%num_pe
835 5556 : IF (iproc - 1 /= para_env%mepos) THEN
836 1852 : CALL recv_handlers(iproc)%wait()
837 : END IF
838 : END DO
839 :
840 : ! compute total number of non-negligible excitations
841 1852 : nexcs = 0
842 5556 : DO iproc = 1, para_env%num_pe
843 5556 : nexcs = nexcs + nexcs_recv(iproc)
844 : END DO
845 :
846 : ! receive indices and amplitudes of selected excitations
847 7408 : ALLOCATE (weights_recv(nexcs), weights_neg_abs_recv(nexcs))
848 7408 : ALLOCATE (inds_recv(nexcs), inds(nexcs))
849 :
850 5556 : nmo_virt_occ = 0
851 5556 : DO iproc = 1, para_env%num_pe
852 5556 : IF (nexcs_recv(iproc) > 0) THEN
853 1944 : IF (iproc - 1 /= para_env%mepos) THEN
854 : ! excitation amplitudes
855 : CALL para_env%irecv(weights_recv(nmo_virt_occ + 1:nmo_virt_occ + nexcs_recv(iproc)), &
856 257 : iproc - 1, recv_handlers(iproc), 1)
857 : ! compressed indices
858 : CALL para_env%irecv(inds_recv(nmo_virt_occ + 1:nmo_virt_occ + nexcs_recv(iproc)), &
859 257 : iproc - 1, recv_handlers2(iproc), 2)
860 : ELSE
861 : ! data on master node
862 4348 : weights_recv(nmo_virt_occ + 1:nmo_virt_occ + nexcs_recv(iproc)) = weights_local(1:nexcs_recv(iproc))
863 4348 : inds_recv(nmo_virt_occ + 1:nmo_virt_occ + nexcs_recv(iproc)) = inds_local(1:nexcs_recv(iproc))
864 : END IF
865 :
866 1944 : nmo_virt_occ = nmo_virt_occ + nexcs_recv(iproc)
867 : END IF
868 : END DO
869 :
870 5556 : DO iproc = 1, para_env%num_pe
871 5556 : IF (iproc - 1 /= para_env%mepos .AND. nexcs_recv(iproc) > 0) THEN
872 257 : CALL recv_handlers(iproc)%wait()
873 257 : CALL recv_handlers2(iproc)%wait()
874 : END IF
875 : END DO
876 :
877 1852 : DEALLOCATE (nexcs_recv, recv_handlers, recv_handlers2)
878 : ELSE
879 : ! working node: send the number of selected excited states to the master node
880 1852 : nexcs_send(1) = nexcs_local
881 1852 : CALL para_env%isend(nexcs_send, para_env%source, send_handler, 0)
882 1852 : CALL send_handler%wait()
883 :
884 1852 : IF (nexcs_local > 0) THEN
885 : ! send excitation amplitudes
886 257 : CALL para_env%isend(weights_local(1:nexcs_local), para_env%source, send_handler, 1)
887 : ! send compressed indices
888 257 : CALL para_env%isend(inds_local(1:nexcs_local), para_env%source, send_handler2, 2)
889 :
890 257 : CALL send_handler%wait()
891 257 : CALL send_handler2%wait()
892 : END IF
893 : END IF
894 :
895 : ! sort non-negligible excitations on the master node according to their amplitudes,
896 : ! uncompress indices and print summary information
897 3704 : IF (para_env%is_source() .AND. log_unit > 0) THEN
898 4811 : weights_neg_abs_recv(:) = -ABS(weights_recv)
899 1852 : CALL sort(weights_neg_abs_recv, INT(nexcs), inds)
900 :
901 1852 : WRITE (log_unit, '(T7,I8,F10.5,A)') istate, evals(istate)*evolt, " eV"
902 :
903 : ! This reinitialization is needed to prevent the intel fortran compiler from introduce
904 : ! a bug when using optimization level 3 flag
905 1852 : state_spin = 1
906 1852 : state_spin2 = 1
907 1852 : IF (spinflip /= no_sf_tddfpt) THEN
908 55 : state_spin = 1
909 55 : state_spin2 = 2
910 : END IF
911 4811 : DO iexc = 1, nexcs
912 2959 : ind = inds_recv(inds(iexc)) - 1
913 2959 : IF ((nspins > 1) .AND. (spinflip == no_sf_tddfpt)) THEN
914 636 : IF (ind < nmo_virt_occ_alpha) THEN
915 286 : state_spin = 1
916 286 : state_spin2 = 1
917 286 : spin_label = '(alp)'
918 286 : spin_label2 = '(alp)'
919 : ELSE
920 350 : state_spin = 2
921 350 : state_spin2 = 2
922 350 : ind = ind - nmo_virt_occ_alpha
923 350 : spin_label = '(bet)'
924 350 : spin_label2 = '(bet)'
925 : END IF
926 : END IF
927 2959 : imo_act = ind/nmo_virt8(state_spin2) + 1
928 2959 : imo_occ = gs_mos(state_spin)%index_active(imo_act)
929 2959 : imo_virt = MOD(ind, nmo_virt8(state_spin2)) + 1
930 :
931 2959 : WRITE (log_unit, '(T27,I8,1X,A5,T48,I8,1X,A5,T70,F9.6)') imo_occ, spin_label, &
932 7770 : nmo_occ8(state_spin2) + imo_virt, spin_label2, weights_recv(inds(iexc))
933 : END DO
934 : END IF
935 :
936 : ! deallocate temporary arrays
937 5164 : IF (para_env%is_source()) THEN
938 1852 : DEALLOCATE (weights_recv, weights_neg_abs_recv, inds_recv, inds)
939 : END IF
940 : END DO
941 :
942 1460 : DEALLOCATE (weights_local, inds_local)
943 1460 : IF (log_unit > 0) THEN
944 : WRITE (log_unit, "(1X,A)") &
945 730 : "-------------------------------------------------------------------------------"
946 : END IF
947 : END IF
948 :
949 1460 : CALL cp_fm_release(weights_fm)
950 1460 : CALL cp_fm_release(S_mos_virt)
951 :
952 1460 : CALL timestop(handle)
953 :
954 2920 : END SUBROUTINE tddfpt_print_excitation_analysis
955 :
956 : ! **************************************************************************************************
957 : !> \brief Print natural transition orbital analysis.
958 : !> \param qs_env Information on Kinds and Particles
959 : !> \param evects TDDFPT trial vectors (SIZE(evects,1) -- number of spins;
960 : !> SIZE(evects,2) -- number of excited states to print)
961 : !> \param evals TDDFPT eigenvalues
962 : !> \param ostrength ...
963 : !> \param gs_mos molecular orbitals optimised for the ground state
964 : !> \param matrix_s overlap matrix
965 : !> \param print_section ...
966 : !> \par History
967 : !> * 06.2019 created [JGH]
968 : ! **************************************************************************************************
969 1460 : SUBROUTINE tddfpt_print_nto_analysis(qs_env, evects, evals, ostrength, gs_mos, matrix_s, print_section)
970 : TYPE(qs_environment_type), POINTER :: qs_env
971 : TYPE(cp_fm_type), DIMENSION(:, :), INTENT(in) :: evects
972 : REAL(kind=dp), DIMENSION(:), INTENT(in) :: evals, ostrength
973 : TYPE(tddfpt_ground_state_mos), DIMENSION(:), &
974 : INTENT(in) :: gs_mos
975 : TYPE(dbcsr_type), POINTER :: matrix_s
976 : TYPE(section_vals_type), POINTER :: print_section
977 :
978 : CHARACTER(LEN=*), PARAMETER :: routineN = 'tddfpt_print_nto_analysis'
979 : INTEGER, PARAMETER :: ntomax = 10
980 :
981 : CHARACTER(LEN=20), DIMENSION(2) :: nto_name
982 : INTEGER :: handle, i, ia, icg, iounit, ispin, &
983 : istate, j, nao, nlist, nmax, nmo, &
984 : nnto, nspins, nstates
985 : INTEGER, DIMENSION(2) :: iv
986 : INTEGER, DIMENSION(2, ntomax) :: ia_index
987 1460 : INTEGER, DIMENSION(:), POINTER :: slist, stride
988 : LOGICAL :: append_cube, cube_file, explicit
989 : REAL(KIND=dp) :: os_threshold, sume, threshold
990 1460 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:) :: eigvals
991 1460 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :) :: eigenvalues
992 : REAL(KIND=dp), DIMENSION(ntomax) :: ia_eval
993 : TYPE(cell_type), POINTER :: cell
994 : TYPE(cp_fm_struct_type), POINTER :: fm_mo_struct, fm_struct
995 : TYPE(cp_fm_type) :: Sev, smat, tmat, wmat, work, wvec
996 1460 : TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:) :: teig
997 : TYPE(cp_logger_type), POINTER :: logger
998 1460 : TYPE(mo_set_type), ALLOCATABLE, DIMENSION(:) :: nto_set
999 1460 : TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
1000 1460 : TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
1001 : TYPE(section_vals_type), POINTER :: molden_section, nto_section
1002 :
1003 1460 : CALL timeset(routineN, handle)
1004 :
1005 1460 : logger => cp_get_default_logger()
1006 1460 : iounit = cp_logger_get_default_io_unit(logger)
1007 :
1008 1460 : IF (BTEST(cp_print_key_should_output(logger%iter_info, print_section, &
1009 : "NTO_ANALYSIS"), cp_p_file)) THEN
1010 :
1011 224 : CALL cite_reference(Martin2003)
1012 :
1013 224 : CALL section_vals_val_get(print_section, "NTO_ANALYSIS%THRESHOLD", r_val=threshold)
1014 224 : CALL section_vals_val_get(print_section, "NTO_ANALYSIS%INTENSITY_THRESHOLD", r_val=os_threshold)
1015 224 : CALL section_vals_val_get(print_section, "NTO_ANALYSIS%STATE_LIST", EXPLICIT=explicit)
1016 :
1017 224 : IF (explicit) THEN
1018 4 : CALL section_vals_val_get(print_section, "NTO_ANALYSIS%STATE_LIST", i_vals=slist)
1019 4 : nlist = SIZE(slist)
1020 : ELSE
1021 : nlist = 0
1022 : END IF
1023 :
1024 224 : IF (iounit > 0) THEN
1025 112 : WRITE (iounit, "(1X,A)") "", &
1026 112 : "-------------------------------------------------------------------------------", &
1027 112 : "- Natural Orbital analysis -", &
1028 224 : "-------------------------------------------------------------------------------"
1029 : END IF
1030 :
1031 224 : nspins = SIZE(evects, 1)
1032 224 : nstates = SIZE(evects, 2)
1033 224 : CALL dbcsr_get_info(matrix_s, nfullrows_total=nao)
1034 :
1035 548 : DO istate = 1, nstates
1036 324 : IF (os_threshold > ostrength(istate)) THEN
1037 54 : IF (iounit > 0) THEN
1038 27 : WRITE (iounit, "(1X,A,I6)") " Skipping state ", istate
1039 : END IF
1040 : CYCLE
1041 : END IF
1042 270 : IF (nlist > 0) THEN
1043 0 : IF (.NOT. ANY(slist == istate)) THEN
1044 0 : IF (iounit > 0) THEN
1045 0 : WRITE (iounit, "(1X,A,I6)") " Skipping state ", istate
1046 : END IF
1047 : CYCLE
1048 : END IF
1049 : END IF
1050 270 : IF (iounit > 0) THEN
1051 135 : WRITE (iounit, "(1X,A,I6,T30,F10.5,A)") " STATE NR. ", istate, evals(istate)*evolt, " eV"
1052 : END IF
1053 : nmax = 0
1054 546 : DO ispin = 1, nspins
1055 276 : CALL cp_fm_get_info(evects(ispin, istate), matrix_struct=fm_struct, ncol_global=nmo)
1056 546 : nmax = MAX(nmax, nmo)
1057 : END DO
1058 1080 : ALLOCATE (eigenvalues(nmax, nspins))
1059 270 : eigenvalues = 0.0_dp
1060 : ! SET 1: Hole states
1061 : ! SET 2: Particle states
1062 270 : nto_name(1) = 'Hole_states'
1063 270 : nto_name(2) = 'Particle_states'
1064 810 : ALLOCATE (nto_set(2))
1065 810 : DO i = 1, 2
1066 540 : CALL allocate_mo_set(nto_set(i), nao, ntomax, 0, 0.0_dp, 1.0_dp, 0.0_dp)
1067 540 : CALL cp_fm_get_info(evects(1, istate), matrix_struct=fm_struct)
1068 : CALL cp_fm_struct_create(fmstruct=fm_mo_struct, template_fmstruct=fm_struct, &
1069 540 : ncol_global=ntomax)
1070 540 : CALL cp_fm_create(tmat, fm_mo_struct)
1071 540 : CALL init_mo_set(nto_set(i), fm_ref=tmat, name=nto_name(i))
1072 540 : CALL cp_fm_release(tmat)
1073 1350 : CALL cp_fm_struct_release(fm_mo_struct)
1074 : END DO
1075 : !
1076 1086 : ALLOCATE (teig(nspins))
1077 : ! hole states
1078 : ! Diagonalize X(T)*S*X
1079 546 : DO ispin = 1, nspins
1080 : ASSOCIATE (ev => evects(ispin, istate))
1081 276 : CALL cp_fm_get_info(ev, matrix_struct=fm_struct, ncol_global=nmo)
1082 276 : CALL cp_fm_create(Sev, fm_struct)
1083 : CALL cp_fm_struct_create(fmstruct=fm_mo_struct, template_fmstruct=fm_struct, &
1084 276 : nrow_global=nmo, ncol_global=nmo)
1085 276 : CALL cp_fm_create(tmat, fm_mo_struct)
1086 276 : CALL cp_fm_create(teig(ispin), fm_mo_struct)
1087 276 : CALL cp_dbcsr_sm_fm_multiply(matrix_s, ev, Sev, ncol=nmo, alpha=1.0_dp, beta=0.0_dp)
1088 276 : CALL parallel_gemm('T', 'N', nmo, nmo, nao, 1.0_dp, ev, Sev, 0.0_dp, tmat)
1089 : END ASSOCIATE
1090 :
1091 276 : CALL choose_eigv_solver(tmat, teig(ispin), eigenvalues(1:nmo, ispin))
1092 :
1093 276 : CALL cp_fm_struct_release(fm_mo_struct)
1094 276 : CALL cp_fm_release(tmat)
1095 1098 : CALL cp_fm_release(Sev)
1096 : END DO
1097 : ! find major determinants i->a
1098 270 : ia_index = 0
1099 270 : sume = 0.0_dp
1100 270 : nnto = 0
1101 326 : DO i = 1, ntomax
1102 3452 : iv = MAXLOC(eigenvalues)
1103 326 : ia_eval(i) = eigenvalues(iv(1), iv(2))
1104 978 : ia_index(1:2, i) = iv(1:2)
1105 326 : sume = sume + ia_eval(i)
1106 326 : eigenvalues(iv(1), iv(2)) = 0.0_dp
1107 326 : nnto = nnto + 1
1108 326 : IF (sume > threshold) EXIT
1109 : END DO
1110 : ! store hole states
1111 270 : CALL set_mo_set(nto_set(1), nmo=nnto)
1112 596 : DO i = 1, nnto
1113 326 : ia = ia_index(1, i)
1114 326 : ispin = ia_index(2, i)
1115 326 : CALL cp_fm_get_info(gs_mos(ispin)%mos_occ, ncol_global=nmo)
1116 326 : CALL cp_fm_get_info(teig(ispin), matrix_struct=fm_struct)
1117 : CALL cp_fm_struct_create(fmstruct=fm_mo_struct, template_fmstruct=fm_struct, &
1118 326 : nrow_global=nmo, ncol_global=1)
1119 326 : CALL cp_fm_create(tmat, fm_mo_struct)
1120 326 : CALL cp_fm_struct_release(fm_mo_struct)
1121 326 : CALL cp_fm_get_info(gs_mos(1)%mos_occ, matrix_struct=fm_struct)
1122 : CALL cp_fm_struct_create(fmstruct=fm_mo_struct, template_fmstruct=fm_struct, &
1123 326 : ncol_global=1)
1124 326 : CALL cp_fm_create(wvec, fm_mo_struct)
1125 326 : CALL cp_fm_struct_release(fm_mo_struct)
1126 326 : CALL cp_fm_to_fm(teig(ispin), tmat, 1, ia, 1)
1127 : CALL parallel_gemm('N', 'N', nao, 1, nmo, 1.0_dp, gs_mos(ispin)%mos_occ, &
1128 326 : tmat, 0.0_dp, wvec)
1129 326 : CALL cp_fm_to_fm(wvec, nto_set(1)%mo_coeff, 1, 1, i)
1130 326 : CALL cp_fm_release(wvec)
1131 1574 : CALL cp_fm_release(tmat)
1132 : END DO
1133 : ! particle states
1134 : ! Solve generalized eigenvalue equation: (S*X)*(S*X)(T)*v = lambda*S*v
1135 270 : CALL set_mo_set(nto_set(2), nmo=nnto)
1136 546 : DO ispin = 1, nspins
1137 : ASSOCIATE (ev => evects(ispin, istate))
1138 276 : CALL cp_fm_get_info(ev, matrix_struct=fm_struct, nrow_global=nao, ncol_global=nmo)
1139 828 : ALLOCATE (eigvals(nao))
1140 276 : eigvals = 0.0_dp
1141 276 : CALL cp_fm_create(Sev, fm_struct)
1142 552 : CALL cp_dbcsr_sm_fm_multiply(matrix_s, ev, Sev, ncol=nmo, alpha=1.0_dp, beta=0.0_dp)
1143 : END ASSOCIATE
1144 : CALL cp_fm_struct_create(fmstruct=fm_mo_struct, template_fmstruct=fm_struct, &
1145 276 : nrow_global=nao, ncol_global=nao)
1146 276 : CALL cp_fm_create(tmat, fm_mo_struct)
1147 276 : CALL cp_fm_create(smat, fm_mo_struct)
1148 276 : CALL cp_fm_create(wmat, fm_mo_struct)
1149 276 : CALL cp_fm_create(work, fm_mo_struct)
1150 276 : CALL cp_fm_struct_release(fm_mo_struct)
1151 276 : CALL copy_dbcsr_to_fm(matrix_s, smat)
1152 276 : CALL parallel_gemm('N', 'T', nao, nao, nmo, 1.0_dp, Sev, Sev, 0.0_dp, tmat)
1153 276 : CALL cp_fm_geeig(tmat, smat, wmat, eigvals, work)
1154 610 : DO i = 1, nnto
1155 610 : IF (ispin == ia_index(2, i)) THEN
1156 326 : icg = 0
1157 7982 : DO j = 1, nao
1158 7982 : IF (ABS(eigvals(j) - ia_eval(i)) < 1.E-6_dp) THEN
1159 326 : icg = j
1160 326 : EXIT
1161 : END IF
1162 : END DO
1163 326 : IF (icg == 0) THEN
1164 : CALL cp_warn(__LOCATION__, &
1165 0 : "Could not locate particle state associated with hole state.")
1166 : ELSE
1167 326 : CALL cp_fm_to_fm(wmat, nto_set(2)%mo_coeff, 1, icg, i)
1168 : END IF
1169 : END IF
1170 : END DO
1171 276 : DEALLOCATE (eigvals)
1172 276 : CALL cp_fm_release(Sev)
1173 276 : CALL cp_fm_release(tmat)
1174 276 : CALL cp_fm_release(smat)
1175 276 : CALL cp_fm_release(wmat)
1176 822 : CALL cp_fm_release(work)
1177 : END DO
1178 : ! print
1179 270 : IF (iounit > 0) THEN
1180 135 : sume = 0.0_dp
1181 298 : DO i = 1, nnto
1182 163 : sume = sume + ia_eval(i)
1183 : WRITE (iounit, "(T6,A,i2,T30,A,i1,T42,A,F8.5,T63,A,F8.5)") &
1184 163 : "Particle-Hole state:", i, " Spin:", ia_index(2, i), &
1185 461 : "Eigenvalue:", ia_eval(i), " Sum Eigv:", sume
1186 : END DO
1187 : END IF
1188 : ! Cube and Molden files
1189 270 : nto_section => section_vals_get_subs_vals(print_section, "NTO_ANALYSIS")
1190 270 : CALL section_vals_val_get(nto_section, "CUBE_FILES", l_val=cube_file)
1191 270 : CALL section_vals_val_get(nto_section, "STRIDE", i_vals=stride)
1192 270 : CALL section_vals_val_get(nto_section, "APPEND", l_val=append_cube)
1193 270 : IF (cube_file) THEN
1194 8 : CALL print_nto_cubes(qs_env, nto_set, istate, stride, append_cube, nto_section)
1195 : END IF
1196 270 : CALL get_qs_env(qs_env, qs_kind_set=qs_kind_set, particle_set=particle_set, cell=cell)
1197 270 : molden_section => section_vals_get_subs_vals(print_section, "MOS_MOLDEN")
1198 270 : CALL write_mos_molden(nto_set, qs_kind_set, particle_set, molden_section, cell=cell, qs_env=qs_env)
1199 : !
1200 270 : DEALLOCATE (eigenvalues)
1201 270 : CALL cp_fm_release(teig)
1202 : !
1203 810 : DO i = 1, 2
1204 810 : CALL deallocate_mo_set(nto_set(i))
1205 : END DO
1206 1034 : DEALLOCATE (nto_set)
1207 : END DO
1208 :
1209 224 : IF (iounit > 0) THEN
1210 : WRITE (iounit, "(1X,A)") &
1211 112 : "-------------------------------------------------------------------------------"
1212 : END IF
1213 :
1214 : END IF
1215 :
1216 1460 : CALL timestop(handle)
1217 :
1218 2920 : END SUBROUTINE tddfpt_print_nto_analysis
1219 :
1220 : ! **************************************************************************************************
1221 : !> \brief Print exciton descriptors, cf. Mewes et al., JCTC 14, 710-725 (2018)
1222 : !> \param log_unit output unit
1223 : !> \param evects TDDFPT trial vectors (SIZE(evects,1) -- number of spins;
1224 : !> SIZE(evects,2) -- number of excited states to print)
1225 : !> \param gs_mos molecular orbitals optimised for the ground state
1226 : !> \param matrix_s overlap matrix
1227 : !> \param do_directional_exciton_descriptors flag for computing descriptors for each (cartesian) direction
1228 : !> \param do_directional_exciton_crosscorrelation flag for adding the crosscorrelation matrix to the directional descriptors
1229 : !> \param qs_env Information on particles/geometry
1230 : !> \par History
1231 : !> * 12.2024 created as 'tddfpt_print_exciton_descriptors' [Maximilian Graml]
1232 : ! **************************************************************************************************
1233 2 : SUBROUTINE tddfpt_print_exciton_descriptors(log_unit, evects, gs_mos, matrix_s, &
1234 : do_directional_exciton_descriptors, &
1235 : do_directional_exciton_crosscorrelation, qs_env)
1236 : INTEGER, INTENT(in) :: log_unit
1237 : TYPE(cp_fm_type), DIMENSION(:, :), INTENT(in) :: evects
1238 : TYPE(tddfpt_ground_state_mos), DIMENSION(:), &
1239 : INTENT(in) :: gs_mos
1240 : TYPE(dbcsr_type), POINTER :: matrix_s
1241 : LOGICAL, INTENT(IN) :: do_directional_exciton_descriptors, &
1242 : do_directional_exciton_crosscorrelation
1243 : TYPE(qs_environment_type), INTENT(IN), POINTER :: qs_env
1244 :
1245 : CHARACTER(LEN=*), PARAMETER :: routineN = 'tddfpt_print_exciton_descriptors'
1246 :
1247 : CHARACTER(LEN=4) :: prefix_output
1248 : INTEGER :: handle, ispin, istate, n_moments_quad, &
1249 : nactive, nao, nspins, nstates
1250 : INTEGER, DIMENSION(maxspins) :: nmo_occ, nmo_virt
1251 : LOGICAL :: print_checkvalue
1252 2 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:) :: ref_point_multipole
1253 : TYPE(cp_blacs_env_type), POINTER :: blacs_env
1254 : TYPE(cp_fm_struct_type), POINTER :: fm_struct_mo_coeff, &
1255 : fm_struct_S_mos_virt, fm_struct_X_ia_n
1256 2 : TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:) :: eigvec_X_ia_n, fm_multipole_ab, &
1257 2 : fm_multipole_ai, fm_multipole_ij, &
1258 2 : S_mos_virt
1259 2 : TYPE(cp_fm_type), DIMENSION(:), POINTER :: mo_coeff
1260 : TYPE(exciton_descr_type), ALLOCATABLE, &
1261 2 : DIMENSION(:) :: exc_descr
1262 :
1263 2 : CALL timeset(routineN, handle)
1264 :
1265 2 : nspins = SIZE(evects, 1)
1266 2 : nstates = SIZE(evects, 2)
1267 :
1268 2 : CPASSERT(nspins == 1) ! Other spins are not yet implemented for exciton descriptors
1269 :
1270 2 : CALL cp_fm_get_info(gs_mos(1)%mos_occ, context=blacs_env)
1271 2 : CALL dbcsr_get_info(matrix_s, nfullrows_total=nao)
1272 :
1273 4 : DO ispin = 1, nspins
1274 2 : nmo_occ(ispin) = SIZE(gs_mos(ispin)%evals_occ)
1275 4 : nmo_virt(ispin) = SIZE(gs_mos(ispin)%evals_virt)
1276 : END DO
1277 :
1278 : ! Prepare fm with all MO coefficents, i.e. nao x nao
1279 8 : ALLOCATE (mo_coeff(nspins))
1280 : CALL cp_fm_struct_create(fm_struct_mo_coeff, nrow_global=nao, ncol_global=nao, &
1281 2 : context=blacs_env)
1282 4 : DO ispin = 1, nspins
1283 2 : CALL cp_fm_create(mo_coeff(ispin), fm_struct_mo_coeff)
1284 : CALL cp_fm_to_fm_submat_general(gs_mos(ispin)%mos_occ, &
1285 : mo_coeff(ispin), &
1286 : nao, &
1287 : nmo_occ(ispin), &
1288 : 1, &
1289 : 1, &
1290 : 1, &
1291 : 1, &
1292 2 : blacs_env)
1293 : CALL cp_fm_to_fm_submat_general(gs_mos(ispin)%mos_virt, &
1294 : mo_coeff(ispin), &
1295 : nao, &
1296 : nmo_virt(ispin), &
1297 : 1, &
1298 : 1, &
1299 : 1, &
1300 : nmo_occ(ispin) + 1, &
1301 4 : blacs_env)
1302 : END DO
1303 2 : CALL cp_fm_struct_release(fm_struct_mo_coeff)
1304 :
1305 : ! Compute multipole moments
1306 : ! fm_multipole_XY have structure inherited by libint, i.e. x, y, z, xx, xy, xz, yy, yz, zz
1307 2 : n_moments_quad = 9
1308 2 : ALLOCATE (ref_point_multipole(3))
1309 20 : ALLOCATE (fm_multipole_ij(n_moments_quad))
1310 20 : ALLOCATE (fm_multipole_ab(n_moments_quad))
1311 20 : ALLOCATE (fm_multipole_ai(n_moments_quad))
1312 :
1313 : CALL get_multipoles_mo(fm_multipole_ai, fm_multipole_ij, fm_multipole_ab, &
1314 : qs_env, mo_coeff, ref_point_multipole, 2, &
1315 2 : nmo_occ(1), nmo_virt(1), blacs_env)
1316 :
1317 2 : CALL cp_fm_release(mo_coeff)
1318 :
1319 : ! Compute eigenvector X of the Casida equation from trial vectors
1320 10 : ALLOCATE (S_mos_virt(nspins), eigvec_X_ia_n(nspins))
1321 4 : DO ispin = 1, nspins
1322 2 : CALL cp_fm_get_info(gs_mos(ispin)%mos_virt, matrix_struct=fm_struct_S_mos_virt)
1323 2 : CALL cp_fm_create(S_mos_virt(ispin), fm_struct_S_mos_virt)
1324 2 : NULLIFY (fm_struct_S_mos_virt)
1325 : CALL cp_dbcsr_sm_fm_multiply(matrix_s, &
1326 : gs_mos(ispin)%mos_virt, &
1327 : S_mos_virt(ispin), &
1328 2 : ncol=nmo_virt(ispin), alpha=1.0_dp, beta=0.0_dp)
1329 :
1330 : CALL cp_fm_struct_create(fm_struct_X_ia_n, nrow_global=nmo_occ(ispin), ncol_global=nmo_virt(ispin), &
1331 2 : context=blacs_env)
1332 2 : CALL cp_fm_create(eigvec_X_ia_n(ispin), fm_struct_X_ia_n)
1333 4 : CALL cp_fm_struct_release(fm_struct_X_ia_n)
1334 : END DO
1335 172 : ALLOCATE (exc_descr(nstates))
1336 12 : DO istate = 1, nstates
1337 22 : DO ispin = 1, nspins
1338 10 : CALL cp_fm_set_all(eigvec_X_ia_n(ispin), 0.0_dp)
1339 : ! compute eigenvectors X of the TDA equation
1340 : ! Reshuffle multiplication from
1341 : ! X_ai = S_ma ^T * C_mi
1342 : ! to
1343 : ! X_ia = C_mi ^T * S_ma
1344 : ! for compatibility with the structure needed for get_exciton_descriptors of bse_properties.F
1345 10 : CALL cp_fm_get_info(evects(ispin, istate), ncol_global=nactive)
1346 10 : IF (nactive /= nmo_occ(ispin)) THEN
1347 : CALL cp_abort(__LOCATION__, &
1348 0 : "Reduced active space excitations not implemented")
1349 : END IF
1350 : CALL parallel_gemm('T', 'N', nmo_occ(ispin), nmo_virt(ispin), nao, 1.0_dp, &
1351 10 : evects(ispin, istate), S_mos_virt(ispin), 0.0_dp, eigvec_X_ia_n(ispin))
1352 :
1353 : CALL get_exciton_descriptors(exc_descr, eigvec_X_ia_n(ispin), &
1354 : fm_multipole_ij, fm_multipole_ab, &
1355 : fm_multipole_ai, &
1356 30 : istate, nmo_occ(ispin), nmo_virt(ispin))
1357 : END DO
1358 : END DO
1359 2 : CALL cp_fm_release(eigvec_X_ia_n)
1360 2 : CALL cp_fm_release(S_mos_virt)
1361 2 : CALL cp_fm_release(fm_multipole_ai)
1362 2 : CALL cp_fm_release(fm_multipole_ij)
1363 2 : CALL cp_fm_release(fm_multipole_ab)
1364 :
1365 : ! Actual printing
1366 2 : print_checkvalue = .TRUE.
1367 2 : prefix_output = ' '
1368 : CALL print_exciton_descriptors(exc_descr, ref_point_multipole, log_unit, &
1369 : nstates, print_checkvalue, do_directional_exciton_descriptors, &
1370 2 : do_directional_exciton_crosscorrelation, prefix_output, qs_env)
1371 :
1372 2 : DEALLOCATE (ref_point_multipole)
1373 2 : DEALLOCATE (exc_descr)
1374 :
1375 2 : CALL timestop(handle)
1376 :
1377 6 : END SUBROUTINE tddfpt_print_exciton_descriptors
1378 :
1379 : ! **************************************************************************************************
1380 : !> \brief ...
1381 : !> \param vin ...
1382 : !> \param vout ...
1383 : !> \param mos_occ ...
1384 : !> \param matrix_s ...
1385 : ! **************************************************************************************************
1386 0 : SUBROUTINE project_vector(vin, vout, mos_occ, matrix_s)
1387 : TYPE(dbcsr_type) :: vin, vout
1388 : TYPE(cp_fm_type), INTENT(IN) :: mos_occ
1389 : TYPE(dbcsr_type), POINTER :: matrix_s
1390 :
1391 : CHARACTER(LEN=*), PARAMETER :: routineN = 'project_vector'
1392 :
1393 : INTEGER :: handle, nao, nmo
1394 : REAL(KIND=dp) :: norm(1)
1395 : TYPE(cp_fm_struct_type), POINTER :: fm_struct, fm_vec_struct
1396 : TYPE(cp_fm_type) :: csvec, svec, vec
1397 :
1398 0 : CALL timeset(routineN, handle)
1399 :
1400 0 : CALL cp_fm_get_info(mos_occ, matrix_struct=fm_struct, nrow_global=nao, ncol_global=nmo)
1401 : CALL cp_fm_struct_create(fmstruct=fm_vec_struct, template_fmstruct=fm_struct, &
1402 0 : nrow_global=nao, ncol_global=1)
1403 0 : CALL cp_fm_create(vec, fm_vec_struct)
1404 0 : CALL cp_fm_create(svec, fm_vec_struct)
1405 0 : CALL cp_fm_struct_release(fm_vec_struct)
1406 : CALL cp_fm_struct_create(fmstruct=fm_vec_struct, template_fmstruct=fm_struct, &
1407 0 : nrow_global=nmo, ncol_global=1)
1408 0 : CALL cp_fm_create(csvec, fm_vec_struct)
1409 0 : CALL cp_fm_struct_release(fm_vec_struct)
1410 :
1411 0 : CALL copy_dbcsr_to_fm(vin, vec)
1412 0 : CALL cp_dbcsr_sm_fm_multiply(matrix_s, vec, svec, ncol=1, alpha=1.0_dp, beta=0.0_dp)
1413 0 : CALL parallel_gemm('T', 'N', nmo, 1, nao, 1.0_dp, mos_occ, svec, 0.0_dp, csvec)
1414 0 : CALL parallel_gemm('N', 'N', nao, 1, nmo, -1.0_dp, mos_occ, csvec, 1.0_dp, vec)
1415 0 : CALL cp_fm_vectorsnorm(vec, norm)
1416 0 : CPASSERT(norm(1) > 1.e-14_dp)
1417 0 : norm(1) = SQRT(1._dp/norm(1))
1418 0 : CALL cp_fm_scale(norm(1), vec)
1419 0 : CALL copy_fm_to_dbcsr(vec, vout, keep_sparsity=.FALSE.)
1420 :
1421 0 : CALL cp_fm_release(csvec)
1422 0 : CALL cp_fm_release(svec)
1423 0 : CALL cp_fm_release(vec)
1424 :
1425 0 : CALL timestop(handle)
1426 :
1427 0 : END SUBROUTINE project_vector
1428 :
1429 : ! **************************************************************************************************
1430 : !> \brief ...
1431 : !> \param va ...
1432 : !> \param vb ...
1433 : !> \param res ...
1434 : ! **************************************************************************************************
1435 0 : SUBROUTINE vec_product(va, vb, res)
1436 : TYPE(dbcsr_type) :: va, vb
1437 : REAL(KIND=dp), INTENT(OUT) :: res
1438 :
1439 : CHARACTER(LEN=*), PARAMETER :: routineN = 'vec_product'
1440 :
1441 : INTEGER :: handle, icol, irow
1442 : LOGICAL :: found
1443 0 : REAL(KIND=dp), DIMENSION(:, :), POINTER :: vba, vbb
1444 : TYPE(dbcsr_iterator_type) :: iter
1445 : TYPE(mp_comm_type) :: group
1446 :
1447 0 : CALL timeset(routineN, handle)
1448 :
1449 0 : res = 0.0_dp
1450 :
1451 0 : CALL dbcsr_get_info(va, group=group)
1452 0 : CALL dbcsr_iterator_start(iter, va)
1453 0 : DO WHILE (dbcsr_iterator_blocks_left(iter))
1454 0 : CALL dbcsr_iterator_next_block(iter, irow, icol, vba)
1455 0 : CALL dbcsr_get_block_p(vb, row=irow, col=icol, block=vbb, found=found)
1456 0 : res = res + SUM(vba*vbb)
1457 0 : CPASSERT(found)
1458 : END DO
1459 0 : CALL dbcsr_iterator_stop(iter)
1460 0 : CALL group%sum(res)
1461 :
1462 0 : CALL timestop(handle)
1463 :
1464 0 : END SUBROUTINE vec_product
1465 :
1466 : ! **************************************************************************************************
1467 : !> \brief ...
1468 : !> \param qs_env ...
1469 : !> \param mos ...
1470 : !> \param istate ...
1471 : !> \param stride ...
1472 : !> \param append_cube ...
1473 : !> \param print_section ...
1474 : ! **************************************************************************************************
1475 8 : SUBROUTINE print_nto_cubes(qs_env, mos, istate, stride, append_cube, print_section)
1476 :
1477 : TYPE(qs_environment_type), POINTER :: qs_env
1478 : TYPE(mo_set_type), DIMENSION(:), INTENT(IN) :: mos
1479 : INTEGER, INTENT(IN) :: istate
1480 : INTEGER, DIMENSION(:), POINTER :: stride
1481 : LOGICAL, INTENT(IN) :: append_cube
1482 : TYPE(section_vals_type), POINTER :: print_section
1483 :
1484 : CHARACTER(LEN=default_path_length) :: filename, my_pos_cube, title
1485 : INTEGER :: i, iset, nmo, unit_nr
1486 : LOGICAL :: mpi_io
1487 8 : TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
1488 : TYPE(cell_type), POINTER :: cell
1489 : TYPE(cp_fm_type), POINTER :: mo_coeff
1490 : TYPE(cp_logger_type), POINTER :: logger
1491 : TYPE(dft_control_type), POINTER :: dft_control
1492 : TYPE(particle_list_type), POINTER :: particles
1493 8 : TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
1494 : TYPE(pw_c1d_gs_type) :: wf_g
1495 : TYPE(pw_env_type), POINTER :: pw_env
1496 8 : TYPE(pw_pool_p_type), DIMENSION(:), POINTER :: pw_pools
1497 : TYPE(pw_pool_type), POINTER :: auxbas_pw_pool
1498 : TYPE(pw_r3d_rs_type) :: wf_r
1499 8 : TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
1500 : TYPE(qs_subsys_type), POINTER :: subsys
1501 :
1502 16 : logger => cp_get_default_logger()
1503 :
1504 8 : CALL get_qs_env(qs_env=qs_env, dft_control=dft_control, pw_env=pw_env)
1505 8 : CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool, pw_pools=pw_pools)
1506 8 : CALL auxbas_pw_pool%create_pw(wf_r)
1507 8 : CALL auxbas_pw_pool%create_pw(wf_g)
1508 :
1509 8 : CALL get_qs_env(qs_env, subsys=subsys)
1510 8 : CALL qs_subsys_get(subsys, particles=particles)
1511 :
1512 8 : my_pos_cube = "REWIND"
1513 8 : IF (append_cube) THEN
1514 0 : my_pos_cube = "APPEND"
1515 : END IF
1516 :
1517 : CALL get_qs_env(qs_env=qs_env, &
1518 : atomic_kind_set=atomic_kind_set, &
1519 : qs_kind_set=qs_kind_set, &
1520 : cell=cell, &
1521 8 : particle_set=particle_set)
1522 :
1523 24 : DO iset = 1, 2
1524 16 : CALL get_mo_set(mo_set=mos(iset), mo_coeff=mo_coeff, nmo=nmo)
1525 44 : DO i = 1, nmo
1526 : CALL calculate_wavefunction(mo_coeff, i, wf_r, wf_g, atomic_kind_set, qs_kind_set, &
1527 20 : cell, dft_control, particle_set, pw_env)
1528 20 : IF (iset == 1) THEN
1529 10 : WRITE (filename, '(a4,I3.3,I2.2,a11)') "NTO_STATE", istate, i, "_Hole_State"
1530 10 : ELSE IF (iset == 2) THEN
1531 10 : WRITE (filename, '(a4,I3.3,I2.2,a15)') "NTO_STATE", istate, i, "_Particle_State"
1532 : END IF
1533 20 : mpi_io = .TRUE.
1534 : unit_nr = cp_print_key_unit_nr(logger, print_section, '', extension=".cube", &
1535 : middle_name=TRIM(filename), file_position=my_pos_cube, &
1536 20 : log_filename=.FALSE., ignore_should_output=.TRUE., mpi_io=mpi_io)
1537 20 : IF (iset == 1) THEN
1538 10 : WRITE (title, *) "Natural Transition Orbital Hole State", i
1539 10 : ELSE IF (iset == 2) THEN
1540 10 : WRITE (title, *) "Natural Transition Orbital Particle State", i
1541 : END IF
1542 20 : CALL cp_pw_to_cube(wf_r, unit_nr, title, particles=particles, stride=stride, mpi_io=mpi_io)
1543 : CALL cp_print_key_finished_output(unit_nr, logger, print_section, '', &
1544 36 : ignore_should_output=.TRUE., mpi_io=mpi_io)
1545 : END DO
1546 : END DO
1547 :
1548 8 : CALL auxbas_pw_pool%give_back_pw(wf_g)
1549 8 : CALL auxbas_pw_pool%give_back_pw(wf_r)
1550 :
1551 8 : END SUBROUTINE print_nto_cubes
1552 :
1553 : END MODULE qs_tddfpt2_properties
|