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