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_methods
9 : USE admm_methods, ONLY: admm_fit_mo_coeffs
10 : USE admm_types, ONLY: admm_type,&
11 : get_admm_env
12 : USE atomic_kind_types, ONLY: atomic_kind_type
13 : USE bibliography, ONLY: Grimme2013,&
14 : Grimme2016,&
15 : Hernandez2025,&
16 : Iannuzzi2005,&
17 : cite_reference
18 : USE cell_types, ONLY: cell_type
19 : USE cp_blacs_env, ONLY: cp_blacs_env_type
20 : USE cp_cfm_types, ONLY: cp_cfm_copy_general,&
21 : cp_cfm_create,&
22 : cp_cfm_get_element,&
23 : cp_cfm_release,&
24 : cp_cfm_type,&
25 : cp_fm_to_cfm
26 : USE cp_control_types, ONLY: dft_control_type,&
27 : rixs_control_type,&
28 : tddfpt2_control_type
29 : USE cp_dbcsr_api, ONLY: dbcsr_p_type
30 : USE cp_dbcsr_operations, ONLY: dbcsr_deallocate_matrix_set
31 : USE cp_fm_pool_types, ONLY: fm_pool_create_fm
32 : USE cp_fm_struct, ONLY: cp_fm_struct_create,&
33 : cp_fm_struct_release,&
34 : cp_fm_struct_type
35 : USE cp_fm_types, ONLY: cp_fm_create,&
36 : cp_fm_get_info,&
37 : cp_fm_release,&
38 : cp_fm_to_fm,&
39 : cp_fm_to_fm_submat,&
40 : cp_fm_type
41 : USE cp_log_handling, ONLY: cp_get_default_logger,&
42 : cp_logger_get_default_io_unit,&
43 : cp_logger_type
44 : USE cp_output_handling, ONLY: cp_add_iter_level,&
45 : cp_iterate,&
46 : cp_print_key_finished_output,&
47 : cp_print_key_unit_nr,&
48 : cp_rm_iter_level
49 : USE exstates_types, ONLY: excited_energy_type
50 : USE header, ONLY: tddfpt_header,&
51 : tddfpt_soc_header
52 : USE hfx_admm_utils, ONLY: aux_admm_init
53 : USE hfx_types, ONLY: compare_hfx_sections,&
54 : hfx_create
55 : USE input_constants, ONLY: &
56 : do_admm_aux_exch_func_none, do_admm_basis_projection, do_admm_exch_scaling_none, &
57 : do_admm_purify_none, do_potential_truncated, no_sf_tddfpt, oe_none, &
58 : tddfpt_dipole_scf_moment, tddfpt_dipole_velocity, tddfpt_kernel_full, tddfpt_kernel_none, &
59 : tddfpt_kernel_stda, tddfpt_sf_col, tddfpt_sf_noncol
60 : USE input_section_types, ONLY: section_vals_get,&
61 : section_vals_get_subs_vals,&
62 : section_vals_type,&
63 : section_vals_val_get,&
64 : section_vals_val_set
65 : USE kinds, ONLY: dp
66 : USE kpoint_transform, ONLY: rskp_prepared_transform_type,&
67 : rskp_transform_evaluate,&
68 : rskp_transform_prepare,&
69 : rskp_transform_release
70 : USE kpoint_types, ONLY: get_kpoint_info,&
71 : kpoint_env_p_type,&
72 : kpoint_env_type,&
73 : kpoint_type
74 : USE lri_environment_methods, ONLY: lri_print_stat
75 : USE lri_environment_types, ONLY: lri_density_release,&
76 : lri_env_release
77 : USE machine, ONLY: m_flush
78 : USE mathconstants, ONLY: z_one,&
79 : z_zero
80 : USE message_passing, ONLY: mp_para_env_type
81 : USE min_basis_set, ONLY: create_minbas_set
82 : USE parallel_gemm_api, ONLY: parallel_gemm
83 : USE particle_types, ONLY: particle_type
84 : USE physcon, ONLY: evolt
85 : USE qs_environment_types, ONLY: get_qs_env,&
86 : qs_environment_type
87 : USE qs_kernel_methods, ONLY: create_fxc_kernel,&
88 : create_kernel_env
89 : USE qs_kernel_types, ONLY: full_kernel_env_type,&
90 : kernel_env_type,&
91 : release_kernel_env
92 : USE qs_kind_types, ONLY: qs_kind_type
93 : USE qs_ks_types, ONLY: qs_ks_env_type
94 : USE qs_mo_types, ONLY: get_mo_set,&
95 : mo_set_type
96 : USE qs_moments, ONLY: qs_moment_kpoints_scf_mos
97 : USE qs_neighbor_list_types, ONLY: neighbor_list_set_p_type
98 : USE qs_overlap, ONLY: build_overlap_matrix
99 : USE qs_rho_types, ONLY: qs_rho_type
100 : USE qs_scf_methods, ONLY: eigensolver
101 : USE qs_scf_types, ONLY: qs_scf_env_type
102 : USE qs_tddfpt2_assign, ONLY: assign_state
103 : USE qs_tddfpt2_densities, ONLY: tddfpt_construct_aux_fit_density,&
104 : tddfpt_construct_ground_state_orb_density
105 : USE qs_tddfpt2_eigensolver, ONLY: tddfpt_davidson_solver,&
106 : tddfpt_orthogonalize_psi1_psi0,&
107 : tddfpt_orthonormalize_psi1_psi1
108 : USE qs_tddfpt2_forces, ONLY: tddfpt_forces_main
109 : USE qs_tddfpt2_fprint, ONLY: tddfpt_print_forces
110 : USE qs_tddfpt2_lri_utils, ONLY: tddfpt2_lri_init
111 : USE qs_tddfpt2_properties, ONLY: tddfpt_dipole_operator,&
112 : tddfpt_print_excitation_analysis,&
113 : tddfpt_print_exciton_descriptors,&
114 : tddfpt_print_nto_analysis,&
115 : tddfpt_print_summary
116 : USE qs_tddfpt2_restart, ONLY: tddfpt_read_restart,&
117 : tddfpt_write_newtonx_output,&
118 : tddfpt_write_restart
119 : USE qs_tddfpt2_smearing_methods, ONLY: tddfpt_smeared_occupation
120 : USE qs_tddfpt2_soc, ONLY: tddfpt_soc
121 : USE qs_tddfpt2_stda_types, ONLY: allocate_stda_env,&
122 : deallocate_stda_env,&
123 : stda_env_type,&
124 : stda_init_param
125 : USE qs_tddfpt2_stda_utils, ONLY: get_lowdin_mo_coefficients,&
126 : stda_init_matrices
127 : USE qs_tddfpt2_subgroups, ONLY: tddfpt_sub_env_init,&
128 : tddfpt_sub_env_release,&
129 : tddfpt_subgroup_env_type
130 : USE qs_tddfpt2_types, ONLY: hfxsr_create_work_matrices,&
131 : stda_create_work_matrices,&
132 : tddfpt_create_work_matrices,&
133 : tddfpt_ground_state_mos,&
134 : tddfpt_release_work_matrices,&
135 : tddfpt_work_matrices
136 : USE qs_tddfpt2_utils, ONLY: tddfpt_guess_vectors,&
137 : tddfpt_init_mos,&
138 : tddfpt_oecorr,&
139 : tddfpt_release_ground_state_mos
140 : USE rixs_types, ONLY: rixs_env_type,&
141 : tddfpt2_valence_type
142 : USE string_utilities, ONLY: integer_to_string
143 : USE util, ONLY: sort
144 : USE xc_write_output, ONLY: xc_write
145 : #include "./base/base_uses.f90"
146 :
147 : IMPLICIT NONE
148 :
149 : PRIVATE
150 :
151 : CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_tddfpt2_methods'
152 :
153 : LOGICAL, PARAMETER, PRIVATE :: debug_this_module = .FALSE.
154 : ! number of first derivative components (3: d/dx, d/dy, d/dz)
155 : INTEGER, PARAMETER, PRIVATE :: nderivs = 3
156 : INTEGER, PARAMETER, PRIVATE :: maxspins = 2
157 :
158 : PUBLIC :: tddfpt, tddfpt_energies, tddfpt_input
159 :
160 : ! **************************************************************************************************
161 :
162 : CONTAINS
163 :
164 : ! **************************************************************************************************
165 : !> \brief Perform TDDFPT calculation. If calc_forces then it also builds the response vector for the
166 : !> Z-vector method and calculates some contributions to the force
167 : !> \param qs_env Quickstep environment
168 : !> \param calc_forces ...
169 : !> \param rixs_env ...
170 : !> \par History
171 : !> * 05.2016 created [Sergey Chulkov]
172 : !> * 06.2016 refactored to be used with Davidson eigensolver [Sergey Chulkov]
173 : !> * 03.2017 cleaned and refactored [Sergey Chulkov]
174 : !> \note Based on the subroutines tddfpt_env_init(), and tddfpt_env_deallocate().
175 : ! **************************************************************************************************
176 1444 : SUBROUTINE tddfpt(qs_env, calc_forces, rixs_env)
177 : TYPE(qs_environment_type), POINTER :: qs_env
178 : LOGICAL, INTENT(IN) :: calc_forces
179 : TYPE(rixs_env_type), OPTIONAL, POINTER :: rixs_env
180 :
181 : CHARACTER(LEN=*), PARAMETER :: routineN = 'tddfpt'
182 :
183 : INTEGER :: handle, ispin, istate, log_unit, mult, &
184 : my_state, nao, nocc, nspins, &
185 : nstate_max, nstates, nvirt, old_state
186 : INTEGER, DIMENSION(maxspins) :: nactive
187 : LOGICAL :: do_admm, do_exck, do_hfx, do_hfxlr, &
188 : do_hfxsr, do_kpoints, do_rixs, do_sf, &
189 : do_soc, lmult_tmp, state_change
190 : REAL(kind=dp) :: gsmin, gsval, xsval
191 1444 : REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: evals, ostrength
192 1444 : TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
193 : TYPE(cell_type), POINTER :: cell
194 : TYPE(cp_blacs_env_type), POINTER :: blacs_env
195 : TYPE(cp_fm_struct_type), POINTER :: matrix_struct
196 1444 : TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:) :: my_active, my_mos
197 1444 : TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:, :) :: dipole_op_mos_occ, evects, S_evects
198 : TYPE(cp_logger_type), POINTER :: logger
199 1444 : TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_ks, matrix_ks_oep, matrix_s, &
200 1444 : matrix_s_aux_fit, &
201 1444 : matrix_s_aux_fit_vs_orb
202 : TYPE(dft_control_type), POINTER :: dft_control
203 : TYPE(excited_energy_type), POINTER :: ex_env
204 : TYPE(full_kernel_env_type), TARGET :: full_kernel_env, kernel_env_admm_aux
205 : TYPE(kernel_env_type) :: kernel_env
206 1444 : TYPE(mo_set_type), DIMENSION(:), POINTER :: mos, mos_aux_fit
207 : TYPE(mp_para_env_type), POINTER :: para_env
208 1444 : TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
209 1444 : TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
210 : TYPE(qs_scf_env_type), POINTER :: scf_env
211 : TYPE(rixs_control_type), POINTER :: rixs_control
212 : TYPE(section_vals_type), POINTER :: hfxsr_section, kernel_section, &
213 : lri_section, soc_section, &
214 : tddfpt_print_section, tddfpt_section, &
215 : xc_section
216 : TYPE(stda_env_type), TARGET :: stda_kernel
217 : TYPE(tddfpt2_control_type), POINTER :: tddfpt_control
218 : TYPE(tddfpt2_valence_type), POINTER :: valence_state
219 : TYPE(tddfpt_ground_state_mos), DIMENSION(:), &
220 1444 : POINTER :: gs_mos
221 1444 : TYPE(tddfpt_subgroup_env_type) :: sub_env
222 1444 : TYPE(tddfpt_work_matrices) :: work_matrices
223 :
224 1444 : CALL timeset(routineN, handle)
225 :
226 1444 : NULLIFY (logger)
227 1444 : logger => cp_get_default_logger()
228 :
229 1444 : NULLIFY (tddfpt_section, tddfpt_control)
230 :
231 : CALL get_qs_env(qs_env, &
232 : dft_control=dft_control, &
233 1444 : do_rixs=do_rixs)
234 1444 : do_kpoints = dft_control%nimages > 1
235 :
236 1444 : IF (do_rixs) THEN
237 16 : tddfpt_section => section_vals_get_subs_vals(qs_env%input, "PROPERTIES%RIXS%TDDFPT")
238 16 : NULLIFY (rixs_control, valence_state)
239 16 : rixs_control => dft_control%rixs_control
240 16 : tddfpt_control => rixs_control%tddfpt2_control
241 16 : valence_state => rixs_env%valence_state
242 : ELSE
243 1428 : tddfpt_section => section_vals_get_subs_vals(qs_env%input, "PROPERTIES%TDDFPT")
244 1428 : tddfpt_control => dft_control%tddfpt2_control
245 : END IF
246 :
247 : ! input section print/xc
248 : CALL tddfpt_input(qs_env, tddfpt_section, tddfpt_control, do_hfx, do_admm, do_exck, &
249 : do_hfxsr, do_hfxlr, xc_section, tddfpt_print_section, &
250 1444 : lri_section, hfxsr_section)
251 :
252 : log_unit = cp_print_key_unit_nr(logger, tddfpt_print_section, "PROGRAM_BANNER", &
253 1444 : extension=".tddfptLog")
254 :
255 1444 : tddfpt_control%do_hfx = do_hfx
256 1444 : tddfpt_control%do_admm = do_admm
257 1444 : tddfpt_control%do_hfxsr = do_hfxsr
258 1444 : tddfpt_control%hfxsr_primbas = 0
259 1444 : tddfpt_control%hfxsr_re_int = .TRUE.
260 1444 : tddfpt_control%do_hfxlr = do_hfxlr
261 1444 : tddfpt_control%do_exck = do_exck
262 1444 : do_sf = tddfpt_control%spinflip /= no_sf_tddfpt
263 1444 : IF (do_sf) CALL cite_reference(Hernandez2025)
264 1444 : IF (tddfpt_control%do_hfxlr) THEN
265 6 : kernel_section => section_vals_get_subs_vals(tddfpt_section, "XC%HFX_KERNEL%HFXLR")
266 6 : CALL section_vals_val_get(kernel_section, "RCUT", r_val=tddfpt_control%hfxlr_rcut)
267 6 : CALL section_vals_val_get(kernel_section, "SCALE", r_val=tddfpt_control%hfxlr_scale)
268 : END IF
269 :
270 1444 : soc_section => section_vals_get_subs_vals(tddfpt_section, "SOC")
271 1444 : CALL section_vals_get(soc_section, explicit=do_soc)
272 :
273 1444 : IF (do_soc) THEN
274 : ! start with multiplicity that is not specified in input
275 : ! so that excited-state gradient is for multiplicity given in input
276 10 : lmult_tmp = tddfpt_control%rks_triplets
277 10 : tddfpt_control%rks_triplets = .NOT. (tddfpt_control%rks_triplets)
278 : END IF
279 :
280 1444 : CALL cite_reference(Iannuzzi2005)
281 1444 : IF (tddfpt_control%kernel == tddfpt_kernel_stda) THEN
282 426 : CALL cite_reference(Grimme2013)
283 426 : CALL cite_reference(Grimme2016)
284 : END IF
285 :
286 1444 : CALL tddfpt_header(log_unit)
287 1444 : CALL kernel_info(log_unit, dft_control, tddfpt_control, xc_section)
288 :
289 1444 : IF (do_kpoints) THEN
290 8 : IF (calc_forces) THEN
291 0 : CPABORT("TDDFPT forces are not implemented for k-points")
292 : END IF
293 8 : IF (do_rixs) THEN
294 0 : CPABORT("RIXS/TDDFPT is not implemented for k-points")
295 : END IF
296 8 : IF (do_soc) THEN
297 0 : CPABORT("TDDFPT-SOC is not implemented for k-points")
298 : END IF
299 8 : CALL tddfpt_kpoint_independent_particle(qs_env, logger, tddfpt_control)
300 : CALL cp_print_key_finished_output(log_unit, &
301 : logger, &
302 : tddfpt_print_section, &
303 8 : "PROGRAM_BANNER")
304 8 : CALL timestop(handle)
305 8 : RETURN
306 : END IF
307 :
308 : CALL get_qs_env(qs_env, &
309 : blacs_env=blacs_env, &
310 : cell=cell, &
311 : matrix_ks=matrix_ks, &
312 : matrix_s=matrix_s, &
313 : mos=mos, &
314 1436 : scf_env=scf_env)
315 :
316 : ! obtain occupied and virtual (unoccupied) ground-state Kohn-Sham orbitals
317 1436 : NULLIFY (gs_mos)
318 1436 : CALL tddfpt_init_mos(qs_env, gs_mos, log_unit)
319 :
320 : ! obtain smeared occupation numbers
321 1436 : IF (tddfpt_control%do_smearing) THEN
322 2 : CALL tddfpt_smeared_occupation(qs_env, gs_mos, log_unit)
323 : END IF
324 :
325 : ! obtain corrected KS-matrix
326 1436 : CALL tddfpt_oecorr(qs_env, gs_mos, matrix_ks_oep)
327 :
328 1436 : IF ((tddfpt_control%do_lrigpw) .AND. &
329 : (tddfpt_control%kernel /= tddfpt_kernel_full)) THEN
330 0 : CALL cp_abort(__LOCATION__, "LRI only implemented for full kernel")
331 : END IF
332 :
333 1436 : IF (ASSOCIATED(matrix_ks_oep)) matrix_ks => matrix_ks_oep
334 :
335 : ! determine active orbitals
336 : ! default is all occupied MOs
337 1436 : CALL init_res_method(qs_env, gs_mos, tddfpt_control, tddfpt_section, log_unit)
338 :
339 : ! components of the dipole operator
340 : CALL tddfpt_dipole_operator(dipole_op_mos_occ, &
341 : tddfpt_control, &
342 : gs_mos, &
343 1436 : qs_env)
344 :
345 1436 : nspins = SIZE(gs_mos)
346 : ! multiplicity of molecular system
347 1436 : IF (nspins > 1) THEN
348 210 : mult = ABS(SIZE(gs_mos(1)%evals_occ) - SIZE(gs_mos(2)%evals_occ)) + 1
349 210 : IF (mult > 2) THEN
350 34 : CALL cp_warn(__LOCATION__, "There is a convergence issue for multiplicity >= 3")
351 : END IF
352 : ELSE
353 1226 : IF (tddfpt_control%rks_triplets) THEN
354 204 : mult = 3
355 : ELSE
356 1022 : mult = 1
357 : END IF
358 : END IF
359 :
360 : ! split mpi communicator
361 9036 : ALLOCATE (my_mos(nspins), my_active(nspins))
362 3082 : DO ispin = 1, nspins
363 1646 : my_mos(ispin) = gs_mos(ispin)%mos_occ
364 3082 : my_active(ispin) = gs_mos(ispin)%mos_active
365 : END DO
366 : CALL tddfpt_sub_env_init(sub_env, qs_env, &
367 : mos_occ=my_mos(:), mos_active=my_active(:), &
368 1436 : kernel=tddfpt_control%kernel)
369 1436 : DEALLOCATE (my_mos, my_active)
370 :
371 1436 : IF (tddfpt_control%kernel == tddfpt_kernel_full) THEN
372 : ! create environment for Full Kernel
373 886 : IF (dft_control%qs_control%xtb) THEN
374 0 : CPABORT("TDDFPT: xTB only works with sTDA Kernel")
375 : END IF
376 :
377 886 : IF (tddfpt_control%do_hfxsr) THEN
378 4 : kernel_section => section_vals_get_subs_vals(tddfpt_section, "XC%HFX_KERNEL")
379 : CALL section_vals_val_get(kernel_section, "HFXSR_PRIMBAS", &
380 4 : i_val=tddfpt_control%hfxsr_primbas)
381 : ! basis set
382 : CALL create_minbas_set(qs_env, log_unit, basis_type="TDA_HFX", &
383 4 : primitive=tddfpt_control%hfxsr_primbas)
384 : ! admm control
385 16 : ALLOCATE (full_kernel_env%admm_control)
386 4 : full_kernel_env%admm_control%purification_method = do_admm_purify_none
387 : full_kernel_env%admm_control%method = do_admm_basis_projection
388 : full_kernel_env%admm_control%scaling_model = do_admm_exch_scaling_none
389 4 : full_kernel_env%admm_control%aux_exch_func = do_admm_aux_exch_func_none
390 : ! hfx section
391 4 : full_kernel_env%hfxsr_section => hfxsr_section
392 : !
393 : CALL aux_admm_init(qs_env, mos, full_kernel_env%admm_env, &
394 4 : full_kernel_env%admm_control, "TDA_HFX")
395 : CALL get_admm_env(full_kernel_env%admm_env, mos_aux_fit=mos_aux_fit, &
396 : matrix_s_aux_fit=matrix_s_aux_fit, &
397 4 : matrix_s_aux_fit_vs_orb=matrix_s_aux_fit_vs_orb)
398 : CALL admm_fit_mo_coeffs(full_kernel_env%admm_env, matrix_s_aux_fit, &
399 4 : matrix_s_aux_fit_vs_orb, mos, mos_aux_fit, .TRUE.)
400 : ! x_data
401 : CALL get_qs_env(qs_env, cell=cell, atomic_kind_set=atomic_kind_set, &
402 : qs_kind_set=qs_kind_set, particle_set=particle_set, &
403 4 : para_env=para_env)
404 : CALL hfx_create(full_kernel_env%x_data, para_env, hfxsr_section, atomic_kind_set, &
405 4 : qs_kind_set, particle_set, dft_control, cell, orb_basis="TDA_HFX")
406 : END IF
407 :
408 : ! allocate pools and work matrices
409 886 : nstates = tddfpt_control%nstates
410 : !! Too many states can lead to Problems
411 : !! You should be warned if there are more states
412 : !! than occ-virt Combinations!!
413 886 : CALL cp_fm_get_info(gs_mos(1)%mos_occ, ncol_global=nocc)
414 886 : IF (tddfpt_control%spinflip == no_sf_tddfpt) THEN
415 860 : CALL cp_fm_get_info(gs_mos(1)%mos_virt, ncol_global=nvirt)
416 : ELSE
417 26 : CALL cp_fm_get_info(gs_mos(2)%mos_virt, ncol_global=nvirt)
418 : END IF
419 886 : nstate_max = nocc*nvirt
420 886 : IF (nstates > nstate_max) THEN
421 0 : CPWARN("NUMBER OF EXCITED STATES COULD LEAD TO PROBLEMS!")
422 0 : CPWARN("Experimental: CHANGED NSTATES TO ITS MAXIMUM VALUE!")
423 0 : nstates = nstate_max
424 0 : tddfpt_control%nstates = nstate_max
425 : END IF
426 : CALL tddfpt_create_work_matrices(work_matrices, gs_mos, nstates, &
427 886 : do_hfx, do_admm, do_hfxlr, do_exck, do_sf, qs_env, sub_env)
428 :
429 : ! create full_kernel and admm_kernel within tddfpt_energies
430 886 : kernel_env%full_kernel => full_kernel_env
431 886 : kernel_env%admm_kernel => kernel_env_admm_aux
432 886 : NULLIFY (kernel_env%stda_kernel)
433 886 : IF (do_hfxsr) THEN
434 : ! work matrices for SR HFX
435 4 : CALL hfxsr_create_work_matrices(work_matrices, qs_env, full_kernel_env%admm_env)
436 : END IF
437 886 : IF (do_hfxlr) THEN
438 : ! calculate S_half and Lowdin MO coefficients
439 6 : CALL get_lowdin_mo_coefficients(qs_env, sub_env, work_matrices)
440 : END IF
441 550 : ELSE IF (tddfpt_control%kernel == tddfpt_kernel_stda) THEN
442 : ! setup for kernel_stda outside tddfpt_energies
443 426 : CALL cp_fm_get_info(gs_mos(1)%mos_occ, nrow_global=nao)
444 1278 : nactive = tddfpt_control%nactive
445 426 : CALL allocate_stda_env(qs_env, stda_kernel, nao, nactive)
446 : ! sTDA parameters
447 426 : CALL stda_init_param(qs_env, stda_kernel, tddfpt_control%stda_control)
448 : ! allocate pools and work matrices
449 426 : nstates = tddfpt_control%nstates
450 426 : CALL stda_create_work_matrices(work_matrices, gs_mos, nstates, qs_env, sub_env)
451 : !
452 : CALL stda_init_matrices(qs_env, stda_kernel, sub_env, &
453 426 : work_matrices, tddfpt_control)
454 : !
455 426 : kernel_env%stda_kernel => stda_kernel
456 426 : NULLIFY (kernel_env%full_kernel)
457 426 : NULLIFY (kernel_env%admm_kernel)
458 124 : ELSE IF (tddfpt_control%kernel == tddfpt_kernel_none) THEN
459 : ! allocate pools and work matrices
460 124 : nstates = tddfpt_control%nstates
461 124 : CALL stda_create_work_matrices(work_matrices, gs_mos, nstates, qs_env, sub_env)
462 124 : NULLIFY (kernel_env%full_kernel)
463 124 : NULLIFY (kernel_env%admm_kernel)
464 124 : NULLIFY (kernel_env%stda_kernel)
465 : END IF
466 :
467 1436 : IF (do_sf) THEN
468 : ! only alpha -> beta excitations are considered in spin-flip TDDFT
469 298 : ALLOCATE (evects(1, nstates))
470 : ELSE
471 13352 : ALLOCATE (evects(nspins, nstates))
472 : END IF
473 4308 : ALLOCATE (evals(nstates))
474 13676 : ALLOCATE (S_evects(SIZE(evects, 1), nstates))
475 :
476 5094 : DO istate = 1, nstates
477 9368 : DO ispin = 1, SIZE(evects, 1)
478 : CALL fm_pool_create_fm( &
479 : work_matrices%fm_pool_ao_mo_active(ispin)%pool, &
480 7932 : S_evects(ispin, istate))
481 : END DO
482 : END DO
483 :
484 1436 : IF (.NOT. do_soc) THEN
485 : ! compute tddfpt excitation energies of multiplicity mult
486 : CALL tddfpt_energies(qs_env, nstates, nspins, work_matrices, &
487 : tddfpt_control, logger, tddfpt_print_section, evects, evals, &
488 : gs_mos, tddfpt_section, S_evects, matrix_s, kernel_env, matrix_ks, &
489 : sub_env, ostrength, dipole_op_mos_occ, mult, xc_section, full_kernel_env, &
490 1426 : kernel_env_admm_aux)
491 : ELSE
492 : CALL tddfpt_soc_energies(qs_env, nstates, work_matrices, &
493 : tddfpt_control, logger, tddfpt_print_section, &
494 : evects, evals, ostrength, &
495 : gs_mos, tddfpt_section, S_evects, matrix_s, kernel_env, matrix_ks, &
496 : sub_env, dipole_op_mos_occ, lmult_tmp, xc_section, full_kernel_env, &
497 10 : kernel_env_admm_aux)
498 : END IF
499 :
500 : !print forces for selected states
501 1436 : IF (calc_forces) THEN
502 : CALL tddfpt_print_forces(qs_env, evects, evals, ostrength, &
503 : tddfpt_print_section, gs_mos, &
504 684 : kernel_env, sub_env, work_matrices)
505 : END IF
506 :
507 : ! excited state potential energy surface
508 1436 : IF (qs_env%excited_state) THEN
509 1198 : IF (sub_env%is_split) THEN
510 : CALL cp_abort(__LOCATION__, &
511 : "Excited state forces not possible when states"// &
512 0 : " are distributed to different CPU pools.")
513 : END IF
514 : ! for gradients unshifted KS matrix
515 1198 : IF (ASSOCIATED(matrix_ks_oep)) CALL get_qs_env(qs_env, matrix_ks=matrix_ks)
516 1198 : CALL get_qs_env(qs_env, exstate_env=ex_env)
517 1198 : state_change = .FALSE.
518 1198 : IF (ex_env%state > 0) THEN
519 1190 : my_state = ex_env%state
520 8 : ELSE IF (ex_env%state < 0) THEN
521 : ! state following
522 32 : ALLOCATE (my_mos(nspins))
523 16 : DO ispin = 1, nspins
524 16 : my_mos(ispin) = gs_mos(ispin)%mos_occ
525 : END DO
526 8 : my_state = ABS(ex_env%state)
527 8 : CALL assign_state(qs_env, matrix_s, evects, my_mos, ex_env%wfn_history, my_state)
528 8 : DEALLOCATE (my_mos)
529 8 : IF (my_state /= ABS(ex_env%state)) THEN
530 0 : state_change = .TRUE.
531 0 : old_state = ABS(ex_env%state)
532 : END IF
533 8 : ex_env%state = -my_state
534 : ELSE
535 : CALL cp_warn(__LOCATION__, &
536 0 : "Active excited state not assigned. Use the first state.")
537 0 : my_state = 1
538 : END IF
539 1198 : CPASSERT(my_state > 0)
540 1198 : IF (my_state > nstates) THEN
541 : CALL cp_warn(__LOCATION__, &
542 0 : "There were not enough excited states calculated.")
543 0 : CPABORT("excited state potential energy surface")
544 : END IF
545 : !
546 : ! energy
547 1198 : ex_env%evalue = evals(my_state)
548 : ! excitation vector
549 1198 : CALL cp_fm_release(ex_env%evect)
550 4930 : ALLOCATE (ex_env%evect(SIZE(evects, 1)))
551 2534 : DO ispin = 1, SIZE(evects, 1)
552 : CALL cp_fm_get_info(matrix=evects(ispin, 1), &
553 1336 : matrix_struct=matrix_struct)
554 1336 : CALL cp_fm_create(ex_env%evect(ispin), matrix_struct)
555 2534 : CALL cp_fm_to_fm(evects(ispin, my_state), ex_env%evect(ispin))
556 : END DO
557 :
558 1198 : IF (log_unit > 0) THEN
559 599 : gsval = ex_env%wfn_history%gsval
560 599 : gsmin = ex_env%wfn_history%gsmin
561 599 : xsval = ex_env%wfn_history%xsval
562 599 : WRITE (log_unit, "(1X,A,T40,F10.6,A,T62,F10.6,A)") "Ground state orbital alignment:", &
563 1198 : gsmin, "[MinVal]", gsval, "[Average]"
564 599 : WRITE (log_unit, "(1X,A,T71,F10.6)") "Excitation vector alignment:", xsval
565 599 : IF (state_change) THEN
566 : WRITE (log_unit, "(1X,A,I5,T60,A14,T76,I5)") &
567 0 : "Target state has been changed from state ", &
568 0 : old_state, " to new state ", my_state
569 : END IF
570 599 : WRITE (log_unit, "(1X,A,I4,A,F12.5,A)") "Calculate properties for state:", &
571 1198 : my_state, " with excitation energy ", ex_env%evalue*evolt, " eV"
572 : END IF
573 :
574 : ! Calculate response vector
575 1198 : IF (calc_forces) THEN
576 : CALL tddfpt_forces_main(qs_env, gs_mos, ex_env, kernel_env, &
577 682 : sub_env, work_matrices)
578 : END IF
579 : END IF
580 :
581 : ! share evals, evects and mo_coefs with rixs
582 1436 : IF (do_rixs) THEN
583 : ! copy evals
584 16 : valence_state%nstates = nstates
585 48 : ALLOCATE (valence_state%evals(SIZE(evals)))
586 70 : valence_state%evals(:) = evals(:)
587 :
588 192 : ALLOCATE (valence_state%evects(nspins, nstates))
589 68 : ALLOCATE (valence_state%mos_active(nspins))
590 36 : DO ispin = 1, nspins
591 : ! copy evects
592 94 : DO istate = 1, nstates
593 : CALL cp_fm_get_info(matrix=evects(ispin, istate), &
594 74 : matrix_struct=matrix_struct)
595 74 : CALL cp_fm_create(valence_state%evects(ispin, istate), matrix_struct)
596 94 : CALL cp_fm_to_fm(evects(ispin, istate), valence_state%evects(ispin, istate))
597 : END DO
598 : ! copy mos_occ
599 : CALL cp_fm_get_info(matrix=gs_mos(ispin)%mos_active, &
600 20 : matrix_struct=matrix_struct)
601 20 : CALL cp_fm_create(valence_state%mos_active(ispin), matrix_struct)
602 36 : CALL cp_fm_to_fm(gs_mos(ispin)%mos_active, valence_state%mos_active(ispin))
603 : END DO
604 : END IF
605 :
606 : ! clean up
607 1436 : CALL cp_fm_release(evects)
608 1436 : CALL cp_fm_release(S_evects)
609 :
610 : CALL cp_print_key_finished_output(log_unit, &
611 : logger, &
612 : tddfpt_print_section, &
613 1436 : "PROGRAM_BANNER")
614 :
615 1436 : DEALLOCATE (evals, ostrength)
616 :
617 1436 : IF (tddfpt_control%kernel == tddfpt_kernel_full) THEN
618 886 : IF (do_admm) CALL release_kernel_env(kernel_env%admm_kernel)
619 886 : IF (tddfpt_control%do_lrigpw) THEN
620 10 : CALL lri_env_release(kernel_env%full_kernel%lri_env)
621 10 : DEALLOCATE (kernel_env%full_kernel%lri_env)
622 10 : CALL lri_density_release(kernel_env%full_kernel%lri_density)
623 10 : DEALLOCATE (kernel_env%full_kernel%lri_density)
624 : END IF
625 886 : CALL release_kernel_env(kernel_env%full_kernel)
626 550 : ELSE IF (tddfpt_control%kernel == tddfpt_kernel_stda) THEN
627 426 : CALL deallocate_stda_env(stda_kernel)
628 124 : ELSE IF (tddfpt_control%kernel == tddfpt_kernel_none) THEN
629 : !
630 : ELSE
631 0 : CPABORT('Unknown kernel type')
632 : END IF
633 1436 : CALL tddfpt_release_work_matrices(work_matrices, sub_env)
634 1436 : CALL tddfpt_sub_env_release(sub_env)
635 :
636 1436 : CALL cp_fm_release(dipole_op_mos_occ)
637 :
638 3082 : DO ispin = nspins, 1, -1
639 3082 : CALL tddfpt_release_ground_state_mos(gs_mos(ispin))
640 : END DO
641 1436 : DEALLOCATE (gs_mos)
642 :
643 1436 : IF (ASSOCIATED(matrix_ks_oep)) THEN
644 30 : CALL dbcsr_deallocate_matrix_set(matrix_ks_oep)
645 : END IF
646 :
647 1436 : CALL timestop(handle)
648 :
649 10108 : END SUBROUTINE tddfpt
650 :
651 : ! **************************************************************************************************
652 : !> \brief TDDFPT input
653 : !> \param qs_env Quickstep environment
654 : !> \param tddfpt_section ...
655 : !> \param tddfpt_control ...
656 : !> \param do_hfx ...
657 : !> \param do_admm ...
658 : !> \param do_exck ...
659 : !> \param do_hfxsr ...
660 : !> \param do_hfxlr ...
661 : !> \param xc_section ...
662 : !> \param tddfpt_print_section ...
663 : !> \param lri_section ...
664 : !> \param hfxsr_section ...
665 : ! **************************************************************************************************
666 1444 : SUBROUTINE tddfpt_input(qs_env, tddfpt_section, tddfpt_control, do_hfx, do_admm, do_exck, &
667 : do_hfxsr, do_hfxlr, xc_section, tddfpt_print_section, lri_section, &
668 : hfxsr_section)
669 : TYPE(qs_environment_type), POINTER :: qs_env
670 : TYPE(section_vals_type), POINTER :: tddfpt_section
671 : TYPE(tddfpt2_control_type), POINTER :: tddfpt_control
672 : LOGICAL, INTENT(INOUT) :: do_hfx, do_admm, do_exck, do_hfxsr, &
673 : do_hfxlr
674 : TYPE(section_vals_type), POINTER :: xc_section, tddfpt_print_section, &
675 : lri_section, hfxsr_section
676 :
677 : CHARACTER(len=20) :: nstates_str
678 : LOGICAL :: exar, exf, exgcp, exhf, exhfxk, exk, &
679 : explicit, explicit_root, expot, exvdw, &
680 : exwfn, found, same_hfx, use_real_wfn
681 : REAL(kind=dp) :: C_hf
682 : TYPE(dft_control_type), POINTER :: dft_control
683 : TYPE(kpoint_type), POINTER :: kpoints
684 : TYPE(section_vals_type), POINTER :: hfx_section, hfx_section_gs, input, &
685 : print_sub, xc_root, xc_sub
686 :
687 1444 : NULLIFY (dft_control, input, kpoints)
688 1444 : CALL get_qs_env(qs_env, dft_control=dft_control, input=input, kpoints=kpoints)
689 :
690 1444 : IF (dft_control%nimages > 1) THEN
691 8 : IF (tddfpt_control%kernel /= tddfpt_kernel_none) THEN
692 0 : CPABORT("TDDFPT with k-points currently supports only KERNEL NONE")
693 : END IF
694 8 : CALL get_kpoint_info(kpoints, use_real_wfn=use_real_wfn)
695 8 : IF (use_real_wfn) THEN
696 0 : CPABORT("K-point TDDFPT requires complex wavefunctions")
697 : END IF
698 8 : IF (tddfpt_control%spinflip /= no_sf_tddfpt) THEN
699 0 : CPABORT("Spin-flip TDDFPT is not implemented for k-points")
700 : END IF
701 8 : IF (tddfpt_control%do_smearing) THEN
702 0 : CPABORT("Smeared-occupation TDDFPT is not implemented for k-points")
703 : END IF
704 8 : IF (tddfpt_control%oe_corr /= oe_none) THEN
705 0 : CPABORT("Orbital-energy-corrected TDDFPT is not implemented for k-points")
706 : END IF
707 : IF (tddfpt_control%dipole_form /= 0 .AND. &
708 8 : tddfpt_control%dipole_form /= tddfpt_dipole_velocity .AND. &
709 : tddfpt_control%dipole_form /= tddfpt_dipole_scf_moment) THEN
710 0 : CPABORT("K-point TDDFPT supports only velocity-form or SCF_MOMENT transition dipoles")
711 : END IF
712 : END IF
713 :
714 1444 : IF (tddfpt_control%nstates <= 0) THEN
715 0 : CALL integer_to_string(tddfpt_control%nstates, nstates_str)
716 : CALL cp_warn(__LOCATION__, "TDDFPT calculation was requested for "// &
717 0 : TRIM(nstates_str)//" excited states: nothing to do.")
718 0 : RETURN
719 : END IF
720 :
721 1444 : NULLIFY (tddfpt_print_section)
722 1444 : tddfpt_print_section => section_vals_get_subs_vals(tddfpt_section, "PRINT")
723 :
724 1444 : IF (dft_control%nimages > 1) THEN
725 8 : IF (tddfpt_control%do_exciton_descriptors .OR. &
726 : tddfpt_control%do_directional_exciton_descriptors) THEN
727 0 : CPABORT("Exciton descriptors are not implemented for k-point TDDFPT")
728 : END IF
729 8 : print_sub => section_vals_get_subs_vals(tddfpt_print_section, "NTO_ANALYSIS")
730 8 : CALL section_vals_get(print_sub, explicit=explicit)
731 8 : IF (explicit) CPABORT("NTO analysis is not implemented for k-point TDDFPT")
732 8 : print_sub => section_vals_get_subs_vals(tddfpt_print_section, "NAMD_PRINT")
733 8 : CALL section_vals_get(print_sub, explicit=explicit)
734 8 : IF (explicit) CPABORT("NAMD_PRINT is not implemented for k-point TDDFPT")
735 : END IF
736 :
737 1444 : IF (tddfpt_control%kernel == tddfpt_kernel_full) THEN
738 886 : NULLIFY (xc_root)
739 886 : xc_root => section_vals_get_subs_vals(tddfpt_section, "XC")
740 886 : CALL section_vals_get(xc_root, explicit=explicit_root)
741 886 : NULLIFY (xc_section)
742 886 : IF (explicit_root) THEN
743 : ! No ADIABATIC_RESCALING option possible
744 502 : NULLIFY (xc_sub)
745 502 : xc_sub => section_vals_get_subs_vals(xc_root, "ADIABATIC_RESCALING")
746 502 : CALL section_vals_get(xc_sub, explicit=exar)
747 502 : IF (exar) THEN
748 0 : CALL cp_warn(__LOCATION__, "TDDFPT Kernel with ADIABATIC_RESCALING not possible.")
749 0 : CPABORT("TDDFPT Input")
750 : END IF
751 : ! No GCP_POTENTIAL option possible
752 502 : NULLIFY (xc_sub)
753 502 : xc_sub => section_vals_get_subs_vals(xc_root, "GCP_POTENTIAL")
754 502 : CALL section_vals_get(xc_sub, explicit=exgcp)
755 502 : IF (exgcp) THEN
756 0 : CALL cp_warn(__LOCATION__, "TDDFPT Kernel with GCP_POTENTIAL not possible.")
757 0 : CPABORT("TDDFPT Input")
758 : END IF
759 : ! No VDW_POTENTIAL option possible
760 502 : NULLIFY (xc_sub)
761 502 : xc_sub => section_vals_get_subs_vals(xc_root, "VDW_POTENTIAL")
762 502 : CALL section_vals_get(xc_sub, explicit=exvdw)
763 502 : IF (exvdw) THEN
764 0 : CALL cp_warn(__LOCATION__, "TDDFPT Kernel with VDW_POTENTIAL not possible.")
765 0 : CPABORT("TDDFPT Input")
766 : END IF
767 : ! No WF_CORRELATION option possible
768 502 : NULLIFY (xc_sub)
769 502 : xc_sub => section_vals_get_subs_vals(xc_root, "WF_CORRELATION")
770 502 : CALL section_vals_get(xc_sub, explicit=exwfn)
771 502 : IF (exwfn) THEN
772 0 : CALL cp_warn(__LOCATION__, "TDDFPT Kernel with WF_CORRELATION not possible.")
773 0 : CPABORT("TDDFPT Input")
774 : END IF
775 : ! No XC_POTENTIAL option possible
776 502 : NULLIFY (xc_sub)
777 502 : xc_sub => section_vals_get_subs_vals(xc_root, "XC_POTENTIAL")
778 502 : CALL section_vals_get(xc_sub, explicit=expot)
779 502 : IF (expot) THEN
780 0 : CALL cp_warn(__LOCATION__, "TDDFPT Kernel with XC_POTENTIAL not possible.")
781 0 : CPABORT("TDDFPT Input")
782 : END IF
783 : !
784 502 : NULLIFY (xc_sub)
785 502 : xc_sub => section_vals_get_subs_vals(xc_root, "XC_FUNCTIONAL")
786 502 : CALL section_vals_get(xc_sub, explicit=exf)
787 502 : NULLIFY (xc_sub)
788 502 : xc_sub => section_vals_get_subs_vals(xc_root, "XC_KERNEL")
789 502 : CALL section_vals_get(xc_sub, explicit=exk)
790 502 : IF ((exf .AND. exk) .OR. .NOT. (exf .OR. exk)) THEN
791 0 : CALL cp_warn(__LOCATION__, "TDDFPT Kernel needs XC_FUNCTIONAL or XC_KERNEL section.")
792 0 : CPABORT("TDDFPT Input")
793 : END IF
794 502 : NULLIFY (xc_sub)
795 502 : xc_sub => section_vals_get_subs_vals(xc_root, "HF")
796 502 : CALL section_vals_get(xc_sub, explicit=exhf)
797 502 : NULLIFY (xc_sub)
798 502 : xc_sub => section_vals_get_subs_vals(xc_root, "HFX_KERNEL")
799 502 : CALL section_vals_get(xc_sub, explicit=exhfxk)
800 : !
801 502 : xc_section => xc_root
802 502 : hfx_section => section_vals_get_subs_vals(xc_section, "HF")
803 502 : CALL section_vals_get(hfx_section, explicit=do_hfx)
804 502 : IF (do_hfx) THEN
805 24 : CALL section_vals_val_get(hfx_section, "FRACTION", r_val=C_hf)
806 24 : do_hfx = (C_hf /= 0.0_dp)
807 : END IF
808 : !TDDFPT only works if the kernel has the same HF section as the DFT%XC one
809 502 : IF (do_hfx) THEN
810 24 : hfx_section_gs => section_vals_get_subs_vals(input, "DFT%XC%HF")
811 24 : CALL compare_hfx_sections(hfx_section, hfx_section_gs, same_hfx)
812 24 : IF (.NOT. same_hfx) THEN
813 0 : CPABORT("TDDFPT Kernel must use the same HF section as DFT%XC or no HF at all.")
814 : END IF
815 : END IF
816 :
817 502 : do_admm = do_hfx .AND. dft_control%do_admm
818 502 : IF (do_admm) THEN
819 : ! 'admm_env%xc_section_primary' and 'admm_env%xc_section_aux' need to be redefined
820 : CALL cp_abort(__LOCATION__, &
821 : "ADMM is not implemented for a TDDFT kernel XC-functional which is different from "// &
822 0 : "the one used for the ground-state calculation. A ground-state 'admm_env' cannot be reused.")
823 : END IF
824 : ! SET HFX_KERNEL and/or XC_KERNEL
825 502 : IF (exk) THEN
826 12 : do_exck = .TRUE.
827 : ELSE
828 490 : do_exck = .FALSE.
829 : END IF
830 502 : IF (exhfxk) THEN
831 6 : xc_sub => section_vals_get_subs_vals(xc_root, "HFX_KERNEL")
832 6 : CALL section_vals_val_get(xc_sub, "DO_HFXSR", l_val=do_hfxsr)
833 6 : xc_sub => section_vals_get_subs_vals(xc_root, "HFX_KERNEL%HFXLR")
834 6 : CALL section_vals_get(xc_sub, explicit=do_hfxlr)
835 : ELSE
836 496 : do_hfxsr = .FALSE.
837 496 : do_hfxlr = .FALSE.
838 : END IF
839 : ELSE
840 384 : xc_section => section_vals_get_subs_vals(input, "DFT%XC")
841 384 : hfx_section => section_vals_get_subs_vals(xc_section, "HF")
842 384 : CALL section_vals_get(hfx_section, explicit=do_hfx)
843 384 : IF (do_hfx) THEN
844 274 : CALL section_vals_val_get(hfx_section, "FRACTION", r_val=C_hf)
845 274 : do_hfx = (C_hf /= 0.0_dp)
846 : END IF
847 384 : do_admm = do_hfx .AND. dft_control%do_admm
848 384 : do_exck = .FALSE.
849 384 : do_hfxsr = .FALSE.
850 384 : do_hfxlr = .FALSE.
851 : END IF
852 : ELSE
853 558 : do_hfx = .FALSE.
854 558 : do_admm = .FALSE.
855 558 : do_exck = .FALSE.
856 558 : do_hfxsr = .FALSE.
857 558 : do_hfxlr = .FALSE.
858 : END IF
859 :
860 : ! reset rks_triplets if UKS is in use
861 1444 : IF (tddfpt_control%rks_triplets .AND. dft_control%nspins > 1) THEN
862 10 : tddfpt_control%rks_triplets = .FALSE.
863 10 : CALL cp_warn(__LOCATION__, "Keyword RKS_TRIPLETS has been ignored for spin-polarised calculations")
864 : END IF
865 :
866 : ! lri input
867 1444 : IF (tddfpt_control%do_lrigpw) THEN
868 10 : lri_section => section_vals_get_subs_vals(tddfpt_section, "LRIGPW")
869 : END IF
870 :
871 : ! set defaults for short range HFX
872 1444 : NULLIFY (hfxsr_section)
873 1444 : IF (do_hfxsr) THEN
874 4 : hfxsr_section => section_vals_get_subs_vals(tddfpt_section, "XC%HFX_KERNEL%HF")
875 4 : CALL section_vals_get(hfxsr_section, explicit=found)
876 4 : IF (.NOT. found) THEN
877 0 : CPABORT("HFXSR option needs &HF section defined")
878 : END IF
879 4 : CALL section_vals_val_get(hfxsr_section, "INTERACTION_POTENTIAL%POTENTIAL_TYPE", explicit=found)
880 4 : IF (.NOT. found) THEN
881 : CALL section_vals_val_set(hfxsr_section, "INTERACTION_POTENTIAL%POTENTIAL_TYPE", &
882 4 : i_val=do_potential_truncated)
883 : END IF
884 4 : CALL section_vals_val_get(hfxsr_section, "INTERACTION_POTENTIAL%CUTOFF_RADIUS", explicit=found)
885 4 : IF (.NOT. found) THEN
886 4 : CALL section_vals_val_set(hfxsr_section, "INTERACTION_POTENTIAL%CUTOFF_RADIUS", r_val=7.5589_dp)
887 : END IF
888 4 : CALL section_vals_val_get(hfxsr_section, "RI%_SECTION_PARAMETERS_", l_val=found)
889 4 : IF (found) THEN
890 0 : CALL cp_abort(__LOCATION__, "Short range TDA kernel with RI not possible")
891 : END IF
892 : END IF
893 :
894 : END SUBROUTINE tddfpt_input
895 :
896 : ! **************************************************************************************************
897 : !> \brief ...
898 : !> \param log_unit ...
899 : !> \param dft_control ...
900 : !> \param tddfpt_control ...
901 : !> \param xc_section ...
902 : ! **************************************************************************************************
903 1444 : SUBROUTINE kernel_info(log_unit, dft_control, tddfpt_control, xc_section)
904 : INTEGER, INTENT(IN) :: log_unit
905 : TYPE(dft_control_type), POINTER :: dft_control
906 : TYPE(tddfpt2_control_type), POINTER :: tddfpt_control
907 : TYPE(section_vals_type), POINTER :: xc_section
908 :
909 : CHARACTER(LEN=4) :: ktype
910 : LOGICAL :: lsd
911 :
912 1444 : lsd = (dft_control%nspins > 1)
913 1444 : IF (tddfpt_control%kernel == tddfpt_kernel_full) THEN
914 886 : ktype = "FULL"
915 886 : IF (log_unit > 0) THEN
916 443 : WRITE (log_unit, "(T2,A,T77,A4)") "KERNEL|", TRIM(ktype)
917 443 : CALL xc_write(log_unit, xc_section, lsd)
918 443 : IF (tddfpt_control%do_hfx) THEN
919 149 : IF (tddfpt_control%do_admm) THEN
920 87 : WRITE (log_unit, "(T2,A,T62,A19)") "KERNEL|", "ADMM Exact Exchange"
921 87 : IF (tddfpt_control%admm_xc_correction) THEN
922 67 : WRITE (log_unit, "(T2,A,T60,A21)") "KERNEL|", "Apply ADMM Kernel XC Correction"
923 : END IF
924 87 : IF (tddfpt_control%admm_symm) THEN
925 87 : WRITE (log_unit, "(T2,A,T60,A21)") "KERNEL|", "Symmetric ADMM Kernel"
926 : END IF
927 : ELSE
928 62 : WRITE (log_unit, "(T2,A,T67,A14)") "KERNEL|", "Exact Exchange"
929 : END IF
930 : END IF
931 443 : IF (tddfpt_control%do_hfxsr) THEN
932 2 : WRITE (log_unit, "(T2,A,T43,A38)") "KERNEL|", "Short range HFX approximation"
933 : END IF
934 443 : IF (tddfpt_control%do_hfxlr) THEN
935 3 : WRITE (log_unit, "(T2,A,T43,A38)") "KERNEL|", "Long range HFX approximation"
936 : END IF
937 443 : IF (tddfpt_control%do_lrigpw) THEN
938 5 : WRITE (log_unit, "(T2,A,T42,A39)") "KERNEL|", "LRI approximation of transition density"
939 : END IF
940 : END IF
941 558 : ELSE IF (tddfpt_control%kernel == tddfpt_kernel_stda) THEN
942 426 : ktype = "sTDA"
943 426 : IF (log_unit > 0) THEN
944 213 : WRITE (log_unit, "(T2,A,T77,A4)") "KERNEL|", TRIM(ktype)
945 213 : IF (tddfpt_control%stda_control%do_ewald) THEN
946 53 : WRITE (log_unit, "(T2,A,T78,A3)") "KERNEL| Coulomb term uses Ewald summation"
947 : ELSE
948 160 : WRITE (log_unit, "(T2,A,T78,A3)") "KERNEL| Coulomb term uses direct summation (MIC)"
949 : END IF
950 213 : IF (tddfpt_control%stda_control%do_exchange) THEN
951 197 : WRITE (log_unit, "(T2,A,T78,A3)") "KERNEL| Exact exchange term", "YES"
952 197 : WRITE (log_unit, "(T2,A,T71,F10.3)") "KERNEL| Short range HFX fraction:", &
953 394 : tddfpt_control%stda_control%hfx_fraction
954 : ELSE
955 16 : WRITE (log_unit, "(T2,A,T79,A2)") "KERNEL| Exact exchange term", "NO"
956 : END IF
957 213 : WRITE (log_unit, "(T2,A,T66,E15.3)") "KERNEL| Transition density filter", &
958 426 : tddfpt_control%stda_control%eps_td_filter
959 : END IF
960 132 : ELSE IF (tddfpt_control%kernel == tddfpt_kernel_none) THEN
961 132 : ktype = "NONE"
962 132 : IF (log_unit > 0) THEN
963 66 : WRITE (log_unit, "(T2,A,T77,A4)") "KERNEL|", TRIM(ktype)
964 : END IF
965 : ELSE
966 : !CPABORT("Unknown kernel")
967 : END IF
968 : !
969 1444 : IF (log_unit > 0) THEN
970 722 : IF (tddfpt_control%rks_triplets) THEN
971 102 : WRITE (log_unit, "(T2,A,T74,A7)") "KERNEL| Spin symmetry of excitations", "Triplet"
972 620 : ELSE IF (lsd) THEN
973 : ! Spin-conserving excitations where requested
974 105 : IF (tddfpt_control%spinflip == no_sf_tddfpt) THEN
975 92 : WRITE (log_unit, "(T2,A,T69,A12)") "KERNEL| Spin symmetry of excitations", "Unrestricted"
976 : ! Spin-flip excitations with collinear exchange-correlation kernel requested
977 13 : ELSE IF (tddfpt_control%spinflip == tddfpt_sf_col) THEN
978 5 : WRITE (log_unit, "(T2,A,T72,A9)") "KERNEL| Spin flip", "Collinear"
979 : ! Spin-flip excitations with noncollinear exchange-correlation kernel requested
980 8 : ELSE IF (tddfpt_control%spinflip == tddfpt_sf_noncol) THEN
981 8 : WRITE (log_unit, "(T2,A,T69,A12)") "KERNEL| Spin flip", "Noncollinear"
982 : END IF
983 : ELSE
984 515 : WRITE (log_unit, "(T2,A,T74,A7)") "KERNEL| Spin symmetry of excitations", "Singlet"
985 : END IF
986 722 : WRITE (log_unit, "(T2,A,T73,I8)") "TDDFPT| Number of states calculated", tddfpt_control%nstates
987 722 : WRITE (log_unit, "(T2,A,T73,I8)") "TDDFPT| Number of Davidson iterations", tddfpt_control%niters
988 722 : WRITE (log_unit, "(T2,A,T66,E15.3)") "TDDFPT| Davidson iteration convergence", tddfpt_control%conv
989 722 : WRITE (log_unit, "(T2,A,T73,I8)") "TDDFPT| Max. number of Krylov space vectors", tddfpt_control%nkvs
990 : END IF
991 :
992 1444 : END SUBROUTINE kernel_info
993 :
994 : ! **************************************************************************************************
995 : !> \brief Print independent-particle vertical transitions for k-point calculations.
996 : !> \param qs_env ...
997 : !> \param logger ...
998 : !> \param tddfpt_control ...
999 : ! **************************************************************************************************
1000 8 : SUBROUTINE tddfpt_kpoint_independent_particle(qs_env, logger, tddfpt_control)
1001 : TYPE(qs_environment_type), POINTER :: qs_env
1002 : TYPE(cp_logger_type), POINTER :: logger
1003 : TYPE(tddfpt2_control_type), POINTER :: tddfpt_control
1004 :
1005 : CHARACTER(LEN=*), PARAMETER :: routineN = 'tddfpt_kpoint_independent_particle'
1006 :
1007 : COMPLEX(KIND=dp) :: moment_element
1008 : COMPLEX(KIND=dp), ALLOCATABLE, &
1009 8 : DIMENSION(:, :, :, :, :) :: kpoint_dipole
1010 : INTEGER :: handle, ideriv, ikp, ikp_local, iocc, ispin, istate, itrans, ivirt, log_unit, &
1011 : nao, nkp, nkp_local, nspins, nstates, ntrans_kpoint, ntrans_spin, ntrans_total, &
1012 : spin_offset, trans_index
1013 8 : INTEGER, ALLOCATABLE, DIMENSION(:) :: inds
1014 : INTEGER, DIMENSION(2) :: kp_range
1015 : INTEGER, DIMENSION(maxspins) :: homo_spin, nao_spin, nmo_spin, nvirt_spin
1016 : LOGICAL :: my_kpgrp, use_real_wfn, &
1017 : use_scf_moment_dipoles
1018 : REAL(kind=dp) :: checksum, dipole_im, dipole_re, fsum, &
1019 : gap, oscillator_factor, spin_factor
1020 8 : REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: eigenvalues_kp, evals, &
1021 16 : oscillator_strength, transition_energy
1022 8 : REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :) :: transition_dipole_im, &
1023 8 : transition_dipole_re
1024 16 : REAL(kind=dp), DIMENSION(:), POINTER :: eigenvalues, wkp
1025 : REAL(kind=dp), DIMENSION(nderivs) :: transition_dipole_abs
1026 : TYPE(cp_blacs_env_type), POINTER :: blacs_env, blacs_env_all
1027 : TYPE(cp_cfm_type) :: cfm_empty, cfm_mo_coeff_global, &
1028 : cfm_moment, cfm_operator, cfm_work
1029 : TYPE(cp_cfm_type), POINTER :: cmo_coeff_source
1030 : TYPE(cp_fm_struct_type), POINTER :: fm_struct
1031 : TYPE(cp_fm_type) :: fm_operator_imag, fm_operator_real
1032 8 : TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: overlap_deriv
1033 : TYPE(dft_control_type), POINTER :: dft_control
1034 8 : TYPE(kpoint_env_p_type), DIMENSION(:), POINTER :: kp_env
1035 : TYPE(kpoint_env_type), POINTER :: kp
1036 : TYPE(kpoint_type), POINTER :: kpoints
1037 8 : TYPE(mo_set_type), DIMENSION(:), POINTER :: mos_kp
1038 : TYPE(mp_para_env_type), POINTER :: para_env, para_env_inter_kp, para_env_kp
1039 : TYPE(neighbor_list_set_p_type), DIMENSION(:), &
1040 8 : POINTER :: sab_kp, sab_orb
1041 : TYPE(qs_ks_env_type), POINTER :: ks_env
1042 32 : TYPE(rskp_prepared_transform_type) :: transform
1043 :
1044 8 : CALL timeset(routineN, handle)
1045 :
1046 8 : NULLIFY (blacs_env, blacs_env_all, cmo_coeff_source, dft_control, &
1047 8 : eigenvalues, fm_struct, kp, kp_env, kpoints, ks_env, &
1048 8 : mos_kp, overlap_deriv, para_env, para_env_inter_kp, para_env_kp, &
1049 8 : sab_kp, sab_orb, wkp)
1050 : CALL get_qs_env(qs_env, dft_control=dft_control, kpoints=kpoints, ks_env=ks_env, &
1051 8 : sab_orb=sab_orb)
1052 8 : CPASSERT(ASSOCIATED(kpoints))
1053 :
1054 : CALL get_kpoint_info(kpoints, nkp=nkp, kp_range=kp_range, kp_env=kp_env, &
1055 : para_env=para_env, blacs_env_all=blacs_env_all, &
1056 : para_env_inter_kp=para_env_inter_kp, para_env_kp=para_env_kp, &
1057 8 : blacs_env=blacs_env, wkp=wkp, sab_nl=sab_kp, use_real_wfn=use_real_wfn)
1058 8 : IF (use_real_wfn) CPABORT("K-point TDDFPT requires complex wavefunctions")
1059 8 : CPASSERT(ASSOCIATED(para_env))
1060 8 : CPASSERT(ASSOCIATED(para_env_inter_kp))
1061 8 : CPASSERT(ASSOCIATED(para_env_kp))
1062 8 : CPASSERT(ASSOCIATED(blacs_env_all))
1063 8 : CPASSERT(ASSOCIATED(blacs_env))
1064 8 : CPASSERT(ASSOCIATED(kp_env))
1065 8 : CPASSERT(ASSOCIATED(ks_env))
1066 8 : CPASSERT(ASSOCIATED(sab_orb))
1067 8 : CPASSERT(ASSOCIATED(sab_kp))
1068 :
1069 8 : nspins = dft_control%nspins
1070 8 : nmo_spin = 0
1071 8 : homo_spin = 0
1072 8 : nao_spin = 0
1073 8 : nkp_local = MAX(0, kp_range(2) - kp_range(1) + 1)
1074 8 : IF (nkp_local > 0) THEN
1075 8 : kp => kp_env(1)%kpoint_env
1076 8 : mos_kp => kp%mos
1077 8 : CPASSERT(ASSOCIATED(mos_kp))
1078 8 : CPASSERT(SIZE(mos_kp) == nspins)
1079 16 : DO ispin = 1, nspins
1080 : CALL get_mo_set(mos_kp(ispin), nmo=nmo_spin(ispin), homo=homo_spin(ispin), &
1081 16 : nao=nao_spin(ispin))
1082 : END DO
1083 : END IF
1084 8 : CALL para_env%max(nmo_spin)
1085 8 : CALL para_env%max(homo_spin)
1086 8 : CALL para_env%max(nao_spin)
1087 :
1088 8 : ntrans_kpoint = 0
1089 16 : DO ispin = 1, nspins
1090 8 : nvirt_spin(ispin) = nmo_spin(ispin) - homo_spin(ispin)
1091 8 : IF (homo_spin(ispin) <= 0 .OR. nvirt_spin(ispin) <= 0) THEN
1092 0 : CPABORT("At least one occupied and one unoccupied MO are required for k-point TDDFPT")
1093 : END IF
1094 16 : ntrans_kpoint = ntrans_kpoint + homo_spin(ispin)*nvirt_spin(ispin)
1095 : END DO
1096 8 : ntrans_total = nkp*ntrans_kpoint
1097 8 : IF (ntrans_total <= 0) THEN
1098 0 : CPABORT("No independent-particle k-point transitions available")
1099 : END IF
1100 :
1101 : ALLOCATE (transition_energy(ntrans_total), transition_dipole_re(ntrans_total, nderivs), &
1102 : transition_dipole_im(ntrans_total, nderivs), oscillator_strength(ntrans_total), &
1103 72 : inds(ntrans_total))
1104 8 : transition_energy = 0.0_dp
1105 8 : transition_dipole_re = 0.0_dp
1106 8 : transition_dipole_im = 0.0_dp
1107 8 : oscillator_strength = 0.0_dp
1108 8 : use_scf_moment_dipoles = (tddfpt_control%dipole_form == tddfpt_dipole_scf_moment)
1109 8 : IF (use_scf_moment_dipoles) THEN
1110 : CALL cp_warn(__LOCATION__, "SCF_MOMENT k-point dipoles use direct SCF MO matrix "// &
1111 2 : "elements; compare folded energy blocks, not individual degenerate states.")
1112 2 : CALL qs_moment_kpoints_scf_mos(qs_env, kpoint_dipole)
1113 : END IF
1114 :
1115 : IF (.NOT. use_scf_moment_dipoles) THEN
1116 : CALL build_overlap_matrix(ks_env, matrixkp_s=overlap_deriv, nderivative=1, &
1117 : basis_type_a="ORB", basis_type_b="ORB", sab_nl=sab_orb, &
1118 6 : ext_kpoints=kpoints)
1119 : CALL cp_fm_struct_create(fm_struct, nrow_global=MAXVAL(nao_spin), &
1120 30 : ncol_global=MAXVAL(nao_spin), para_env=para_env, context=blacs_env_all)
1121 : CALL rskp_transform_prepare(transform, overlap_deriv, [2, 3, 4], sab_kp, kpoints%cell_to_index, &
1122 : fm_struct, para_env, para_env_kp, para_env_inter_kp, &
1123 6 : kpoints%rskp_transform, kpoints%xkp, kpoints%nkp_grid, kpoints%kp_dist)
1124 6 : CALL cp_fm_struct_release(fm_struct)
1125 : END IF
1126 :
1127 22 : DO ikp = 1, nkp
1128 14 : my_kpgrp = (ikp >= kp_range(1) .AND. ikp <= kp_range(2))
1129 : IF (my_kpgrp) THEN
1130 8 : ikp_local = ikp - kp_range(1) + 1
1131 8 : kp => kp_env(ikp_local)%kpoint_env
1132 8 : mos_kp => kp%mos
1133 : ELSE
1134 14 : NULLIFY (kp, mos_kp)
1135 : END IF
1136 14 : spin_offset = 0
1137 36 : DO ispin = 1, nspins
1138 14 : nao = nao_spin(ispin)
1139 42 : ALLOCATE (eigenvalues_kp(nmo_spin(ispin)))
1140 14 : eigenvalues_kp = 0.0_dp
1141 :
1142 14 : IF (.NOT. use_scf_moment_dipoles) THEN
1143 : CALL cp_fm_struct_create(fm_struct, nrow_global=nao, ncol_global=nmo_spin(ispin), &
1144 10 : para_env=para_env, context=blacs_env_all)
1145 10 : CALL cp_cfm_create(cfm_mo_coeff_global, fm_struct)
1146 10 : CALL cp_cfm_create(cfm_work, fm_struct)
1147 10 : CALL cp_fm_struct_release(fm_struct)
1148 : CALL cp_fm_struct_create(fm_struct, nrow_global=nmo_spin(ispin), &
1149 : ncol_global=nmo_spin(ispin), para_env=para_env, &
1150 10 : context=blacs_env_all)
1151 10 : CALL cp_cfm_create(cfm_moment, fm_struct)
1152 10 : CALL cp_fm_struct_release(fm_struct)
1153 : CALL cp_fm_struct_create(fm_struct, nrow_global=nao, ncol_global=nao, &
1154 10 : para_env=para_env, context=blacs_env_all)
1155 10 : CALL cp_cfm_create(cfm_operator, fm_struct)
1156 10 : CALL cp_fm_create(fm_operator_real, fm_struct)
1157 10 : CALL cp_fm_create(fm_operator_imag, fm_struct)
1158 10 : CALL cp_fm_struct_release(fm_struct)
1159 : END IF
1160 :
1161 14 : IF (my_kpgrp) THEN
1162 8 : CALL get_mo_set(mos_kp(ispin), eigenvalues=eigenvalues)
1163 8 : CPASSERT(ASSOCIATED(eigenvalues))
1164 8 : IF (para_env_kp%is_source()) THEN
1165 42 : eigenvalues_kp(1:nmo_spin(ispin)) = eigenvalues(1:nmo_spin(ispin))
1166 : END IF
1167 8 : IF (.NOT. use_scf_moment_dipoles) THEN
1168 6 : cmo_coeff_source => mos_kp(ispin)%cmo_coeff
1169 : END IF
1170 6 : ELSE IF (.NOT. use_scf_moment_dipoles) THEN
1171 : NULLIFY (cmo_coeff_source)
1172 : END IF
1173 : IF (.NOT. use_scf_moment_dipoles) THEN
1174 10 : IF (ASSOCIATED(cmo_coeff_source)) THEN
1175 6 : CALL cp_cfm_copy_general(cmo_coeff_source, cfm_mo_coeff_global, para_env)
1176 : ELSE
1177 4 : CALL cp_cfm_copy_general(cfm_empty, cfm_mo_coeff_global, para_env)
1178 : END IF
1179 : END IF
1180 14 : CALL para_env%sum(eigenvalues_kp)
1181 :
1182 14 : spin_factor = 1.0_dp
1183 14 : IF (nspins == 1) THEN
1184 14 : IF (tddfpt_control%rks_triplets) THEN
1185 : spin_factor = 0.0_dp
1186 : ELSE
1187 14 : spin_factor = 2.0_dp
1188 : END IF
1189 : END IF
1190 :
1191 56 : DO ideriv = 1, nderivs
1192 42 : IF (.NOT. use_scf_moment_dipoles) THEN
1193 : ! Keep the existing transpose convention: these terms form C^T A C.
1194 : CALL rskp_transform_evaluate(transform, ideriv, ikp, kpoints%xkp, &
1195 30 : fm_operator_real, fm_operator_imag)
1196 30 : CALL cp_fm_to_cfm(fm_operator_real, fm_operator_imag, cfm_operator)
1197 : CALL parallel_gemm("N", "N", nao, nmo_spin(ispin), nao, z_one, cfm_operator, &
1198 30 : cfm_mo_coeff_global, z_zero, cfm_work)
1199 : CALL parallel_gemm("T", "N", nmo_spin(ispin), nmo_spin(ispin), nao, z_one, &
1200 30 : cfm_mo_coeff_global, cfm_work, z_zero, cfm_moment)
1201 : END IF
1202 :
1203 98 : DO iocc = 1, homo_spin(ispin)
1204 252 : DO ivirt = homo_spin(ispin) + 1, nmo_spin(ispin)
1205 : trans_index = (ikp - 1)*ntrans_kpoint + spin_offset + &
1206 168 : (iocc - 1)*nvirt_spin(ispin) + ivirt - homo_spin(ispin)
1207 168 : gap = eigenvalues_kp(ivirt) - eigenvalues_kp(iocc)
1208 168 : IF (gap <= 0.0_dp) THEN
1209 0 : CPABORT("K-point TDDFPT requires positive occupied-virtual energy gaps")
1210 : END IF
1211 168 : IF (use_scf_moment_dipoles) THEN
1212 48 : oscillator_factor = SQRT(spin_factor*wkp(ikp))
1213 48 : dipole_re = REAL(kpoint_dipole(ispin, ikp, ideriv, iocc, ivirt), KIND=dp)
1214 48 : dipole_im = AIMAG(kpoint_dipole(ispin, ikp, ideriv, iocc, ivirt))
1215 : ELSE
1216 120 : oscillator_factor = SQRT(spin_factor*wkp(ikp))/gap
1217 120 : CALL cp_cfm_get_element(cfm_moment, ivirt, iocc, moment_element)
1218 120 : dipole_re = REAL(moment_element, KIND=dp)
1219 120 : dipole_im = AIMAG(moment_element)
1220 : END IF
1221 168 : transition_dipole_re(trans_index, ideriv) = oscillator_factor*dipole_re
1222 210 : transition_dipole_im(trans_index, ideriv) = oscillator_factor*dipole_im
1223 : END DO
1224 : END DO
1225 : END DO
1226 :
1227 28 : DO iocc = 1, homo_spin(ispin)
1228 84 : DO ivirt = homo_spin(ispin) + 1, nmo_spin(ispin)
1229 : trans_index = (ikp - 1)*ntrans_kpoint + spin_offset + &
1230 56 : (iocc - 1)*nvirt_spin(ispin) + ivirt - homo_spin(ispin)
1231 56 : transition_energy(trans_index) = eigenvalues_kp(ivirt) - eigenvalues_kp(iocc)
1232 : oscillator_strength(trans_index) = 2.0_dp/3.0_dp*transition_energy(trans_index)* &
1233 : SUM(transition_dipole_re(trans_index, :)**2 + &
1234 238 : transition_dipole_im(trans_index, :)**2)
1235 : END DO
1236 : END DO
1237 14 : IF (.NOT. use_scf_moment_dipoles) THEN
1238 10 : CALL cp_cfm_release(cfm_moment)
1239 10 : CALL cp_cfm_release(cfm_operator)
1240 10 : CALL cp_cfm_release(cfm_work)
1241 10 : CALL cp_cfm_release(cfm_mo_coeff_global)
1242 10 : CALL cp_fm_release(fm_operator_real)
1243 10 : CALL cp_fm_release(fm_operator_imag)
1244 : END IF
1245 14 : DEALLOCATE (eigenvalues_kp)
1246 28 : spin_offset = spin_offset + homo_spin(ispin)*nvirt_spin(ispin)
1247 : END DO
1248 : END DO
1249 :
1250 64 : IF (ANY(transition_energy <= 0.0_dp)) THEN
1251 0 : CPABORT("K-point TDDFPT KERNEL NONE requires positive occupied-virtual energy gaps")
1252 : END IF
1253 :
1254 8 : CALL sort(transition_energy, ntrans_total, inds)
1255 8 : nstates = MIN(tddfpt_control%nstates, ntrans_total)
1256 8 : IF (tddfpt_control%nstates > ntrans_total) THEN
1257 0 : CPWARN("Requested more TDDFPT states than independent-particle k-point transitions")
1258 : END IF
1259 :
1260 24 : ALLOCATE (evals(nstates))
1261 22 : evals(1:nstates) = transition_energy(1:nstates)
1262 22 : checksum = SQRT(SUM(evals**2))
1263 :
1264 8 : log_unit = cp_logger_get_default_io_unit(logger)
1265 8 : IF (log_unit > 0) THEN
1266 4 : WRITE (log_unit, "(1X,A)") "", &
1267 4 : "-------------------------------------------------------------------------------", &
1268 4 : "- TDDFPT K-point Independent-particle Transitions -", &
1269 8 : "-------------------------------------------------------------------------------"
1270 : WRITE (log_unit, "(1X,A)") &
1271 4 : "Only KERNEL NONE is active for k-point TDDFPT; transition dipole magnitudes are shown."
1272 4 : WRITE (log_unit, '(/,T10,A,T19,A,T37,A,T69,A)') "State", "Excitation", &
1273 8 : "Transition dipole (a.u.)", "Oscillator"
1274 4 : WRITE (log_unit, '(T10,A,T19,A,T37,A,T49,A,T61,A,T67,A)') "number", "energy (eV)", &
1275 8 : "x", "y", "z", "strength (a.u.)"
1276 4 : WRITE (log_unit, '(T10,72("-"))')
1277 : END IF
1278 :
1279 8 : fsum = 0.0_dp
1280 22 : DO istate = 1, nstates
1281 14 : itrans = inds(istate) - 1
1282 14 : ikp = itrans/ntrans_kpoint + 1
1283 14 : itrans = MOD(itrans, ntrans_kpoint)
1284 14 : spin_offset = 0
1285 14 : DO ispin = 1, nspins
1286 14 : ntrans_spin = homo_spin(ispin)*nvirt_spin(ispin)
1287 14 : IF (itrans < spin_offset + ntrans_spin) THEN
1288 14 : itrans = itrans - spin_offset
1289 14 : iocc = itrans/nvirt_spin(ispin) + 1
1290 14 : ivirt = MOD(itrans, nvirt_spin(ispin)) + homo_spin(ispin) + 1
1291 14 : EXIT
1292 : END IF
1293 0 : spin_offset = spin_offset + ntrans_spin
1294 : END DO
1295 :
1296 22 : IF (log_unit > 0) THEN
1297 : transition_dipole_abs(1:nderivs) = &
1298 : SQRT(transition_dipole_re(inds(istate), 1:nderivs)**2 + &
1299 28 : transition_dipole_im(inds(istate), 1:nderivs)**2)
1300 : WRITE (log_unit, '(1X,A,T9,I7,T19,F11.5,T31,3(1X,ES11.4E2),T69,ES12.5E2)') &
1301 7 : "TDDFPT|", istate, evals(istate)*evolt, transition_dipole_abs, &
1302 14 : oscillator_strength(inds(istate))
1303 7 : fsum = fsum + oscillator_strength(inds(istate))**2
1304 : WRITE (log_unit, '(1X,A,T18,I7,T28,I7,T38,I7,T50,I7,T62,I7,T74,F10.5)') &
1305 7 : "TDDFPT_KPOINT|", istate, ikp, ispin, iocc, ivirt, wkp(ikp)
1306 : END IF
1307 : END DO
1308 :
1309 8 : IF (log_unit > 0) THEN
1310 4 : WRITE (log_unit, '(/,T2,A,E16.8)') 'TDDFPT : CheckSum E = ', checksum
1311 4 : WRITE (log_unit, '(T2,A,E16.8)') 'TDDFPT : CheckSum F = ', SQRT(fsum)
1312 : WRITE (log_unit, "(1X,A)") &
1313 4 : "-------------------------------------------------------------------------------"
1314 : END IF
1315 :
1316 8 : IF (use_scf_moment_dipoles) THEN
1317 2 : DEALLOCATE (kpoint_dipole)
1318 : ELSE
1319 6 : CALL rskp_transform_release(transform)
1320 6 : CALL dbcsr_deallocate_matrix_set(overlap_deriv)
1321 : END IF
1322 :
1323 0 : DEALLOCATE (evals, inds, oscillator_strength, transition_dipole_im, transition_dipole_re, &
1324 8 : transition_energy)
1325 :
1326 8 : CALL timestop(handle)
1327 :
1328 24 : END SUBROUTINE tddfpt_kpoint_independent_particle
1329 :
1330 : ! **************************************************************************************************
1331 : !> \brief The energy calculation has been moved to its own subroutine
1332 : !> \param qs_env ...
1333 : !> \param nstates ...
1334 : !> \param nspins ...
1335 : !> \param work_matrices ...
1336 : !> \param tddfpt_control ...
1337 : !> \param logger ...
1338 : !> \param tddfpt_print_section ...
1339 : !> \param evects ...
1340 : !> \param evals ...
1341 : !> \param gs_mos ...
1342 : !> \param tddfpt_section ...
1343 : !> \param S_evects ...
1344 : !> \param matrix_s ...
1345 : !> \param kernel_env ...
1346 : !> \param matrix_ks ...
1347 : !> \param sub_env ...
1348 : !> \param ostrength ...
1349 : !> \param dipole_op_mos_occ ...
1350 : !> \param mult ...
1351 : !> \param xc_section ...
1352 : !> \param full_kernel_env ...
1353 : !> \param kernel_env_admm_aux ...
1354 : ! **************************************************************************************************
1355 1446 : SUBROUTINE tddfpt_energies(qs_env, nstates, nspins, work_matrices, &
1356 : tddfpt_control, logger, tddfpt_print_section, evects, evals, &
1357 : gs_mos, tddfpt_section, S_evects, matrix_s, kernel_env, matrix_ks, &
1358 : sub_env, ostrength, dipole_op_mos_occ, mult, xc_section, full_kernel_env, &
1359 : kernel_env_admm_aux)
1360 :
1361 : TYPE(qs_environment_type), POINTER :: qs_env
1362 : INTEGER :: nstates, nspins
1363 : TYPE(tddfpt_work_matrices) :: work_matrices
1364 : TYPE(tddfpt2_control_type), POINTER :: tddfpt_control
1365 : TYPE(cp_logger_type), POINTER :: logger
1366 : TYPE(section_vals_type), POINTER :: tddfpt_print_section
1367 : TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:, :) :: evects
1368 : REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: evals
1369 : TYPE(tddfpt_ground_state_mos), DIMENSION(:), &
1370 : POINTER :: gs_mos
1371 : TYPE(section_vals_type), POINTER :: tddfpt_section
1372 : TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:, :) :: S_evects
1373 : TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_s
1374 : TYPE(kernel_env_type) :: kernel_env
1375 : TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_ks
1376 : TYPE(tddfpt_subgroup_env_type) :: sub_env
1377 : REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: ostrength
1378 : TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:, :) :: dipole_op_mos_occ
1379 : INTEGER :: mult
1380 : TYPE(section_vals_type), POINTER :: xc_section
1381 : TYPE(full_kernel_env_type), TARGET :: full_kernel_env, kernel_env_admm_aux
1382 :
1383 : CHARACTER(LEN=*), PARAMETER :: routineN = 'tddfpt_energies'
1384 :
1385 : CHARACTER(len=20) :: nstates_str
1386 : INTEGER :: energy_unit, handle, iter, log_unit, &
1387 : niters, nocc, nstate_max, &
1388 : nstates_read, nvirt
1389 : LOGICAL :: do_admm, do_exck, do_soc, explicit
1390 : REAL(kind=dp) :: conv
1391 : TYPE(admm_type), POINTER :: admm_env
1392 : TYPE(cp_blacs_env_type), POINTER :: blacs_env
1393 1446 : TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_ks_oep
1394 : TYPE(dft_control_type), POINTER :: dft_control
1395 : TYPE(qs_rho_type), POINTER :: rho0_struct
1396 : TYPE(section_vals_type), POINTER :: lri_section, namd_print_section, &
1397 : soc_section
1398 :
1399 1446 : CALL timeset(routineN, handle)
1400 :
1401 1446 : CALL get_qs_env(qs_env, dft_control=dft_control)
1402 :
1403 1446 : NULLIFY (admm_env, matrix_ks_oep)
1404 1446 : do_admm = tddfpt_control%do_admm
1405 1446 : IF (do_admm) CALL get_qs_env(qs_env, admm_env=admm_env)
1406 :
1407 : ! setup for full_kernel and admm_kernel within tddfpt_energies due to dependence on multiplicity
1408 1446 : IF (tddfpt_control%kernel == tddfpt_kernel_full) THEN
1409 :
1410 : CALL tddfpt_construct_ground_state_orb_density( &
1411 : rho_orb_struct=work_matrices%rho_orb_struct_sub, &
1412 : rho_xc_struct=work_matrices%rho_xc_struct_sub, &
1413 : is_rks_triplets=tddfpt_control%rks_triplets, &
1414 : qs_env=qs_env, sub_env=sub_env, &
1415 896 : wfm_rho_orb=work_matrices%rho_ao_orb_fm_sub)
1416 896 : IF (dft_control%qs_control%gapw_xc) THEN
1417 72 : rho0_struct => work_matrices%rho_xc_struct_sub
1418 : ELSE
1419 824 : rho0_struct => work_matrices%rho_orb_struct_sub
1420 : END IF
1421 :
1422 896 : IF (do_admm) THEN
1423 : ! Full kernel with ADMM
1424 174 : IF (tddfpt_control%admm_xc_correction) THEN
1425 : CALL create_kernel_env(kernel_env=full_kernel_env, &
1426 : rho_struct_sub=rho0_struct, &
1427 : xc_section=admm_env%xc_section_primary, &
1428 : is_rks_triplets=tddfpt_control%rks_triplets, &
1429 134 : sub_env=sub_env, qs_env=qs_env)
1430 : ELSE
1431 : CALL create_kernel_env(kernel_env=full_kernel_env, &
1432 : rho_struct_sub=rho0_struct, &
1433 : xc_section=xc_section, &
1434 : is_rks_triplets=tddfpt_control%rks_triplets, &
1435 40 : sub_env=sub_env, qs_env=qs_env)
1436 : END IF
1437 :
1438 : CALL tddfpt_construct_aux_fit_density( &
1439 : rho_orb_struct=work_matrices%rho_orb_struct_sub, &
1440 : rho_aux_fit_struct=work_matrices%rho_aux_fit_struct_sub, &
1441 : local_rho_set=sub_env%local_rho_set_admm, &
1442 : qs_env=qs_env, sub_env=sub_env, &
1443 : wfm_rho_orb=work_matrices%rho_ao_orb_fm_sub, &
1444 : wfm_rho_aux_fit=work_matrices%rho_ao_aux_fit_fm_sub, &
1445 174 : wfm_aux_orb=work_matrices%wfm_aux_orb_sub)
1446 :
1447 : CALL create_kernel_env(kernel_env=kernel_env_admm_aux, &
1448 : rho_struct_sub=work_matrices%rho_aux_fit_struct_sub, &
1449 : xc_section=admm_env%xc_section_aux, &
1450 : is_rks_triplets=tddfpt_control%rks_triplets, &
1451 174 : sub_env=sub_env, qs_env=qs_env)
1452 174 : kernel_env%full_kernel => full_kernel_env
1453 174 : kernel_env%admm_kernel => kernel_env_admm_aux
1454 : ELSE
1455 : ! Full kernel
1456 : CALL create_kernel_env(kernel_env=full_kernel_env, &
1457 : rho_struct_sub=rho0_struct, &
1458 : xc_section=xc_section, &
1459 : is_rks_triplets=tddfpt_control%rks_triplets, &
1460 722 : sub_env=sub_env, qs_env=qs_env)
1461 722 : kernel_env%full_kernel => full_kernel_env
1462 722 : NULLIFY (kernel_env%admm_kernel)
1463 : END IF
1464 : ! Fxc from kernel definition
1465 896 : do_exck = tddfpt_control%do_exck
1466 896 : kernel_env%full_kernel%do_exck = do_exck
1467 : ! initilize xc kernel
1468 896 : IF (do_exck) THEN
1469 : CALL create_fxc_kernel(work_matrices%rho_orb_struct_sub, work_matrices%fxc_rspace_sub, &
1470 12 : xc_section, tddfpt_control%rks_triplets, sub_env, qs_env)
1471 : END IF
1472 : END IF
1473 :
1474 : ! lri input
1475 1446 : IF (tddfpt_control%do_lrigpw) THEN
1476 10 : lri_section => section_vals_get_subs_vals(tddfpt_section, "LRIGPW")
1477 : CALL tddfpt2_lri_init(qs_env, kernel_env, lri_section, &
1478 10 : tddfpt_print_section)
1479 : END IF
1480 :
1481 : !! Too many states can lead to Problems
1482 : !! You should be warned if there are more states
1483 : !! than occ-virt Combinations!!
1484 1446 : CALL cp_fm_get_info(gs_mos(1)%mos_occ, ncol_global=nocc)
1485 1446 : IF (tddfpt_control%spinflip == no_sf_tddfpt) THEN
1486 1420 : CALL cp_fm_get_info(gs_mos(1)%mos_virt, ncol_global=nvirt)
1487 : ELSE
1488 26 : CALL cp_fm_get_info(gs_mos(2)%mos_virt, ncol_global=nvirt)
1489 : END IF
1490 1446 : nstate_max = nocc*nvirt
1491 1446 : IF ((SIZE(gs_mos, 1) == 2) .AND. (tddfpt_control%spinflip == no_sf_tddfpt)) THEN
1492 184 : CALL cp_fm_get_info(gs_mos(2)%mos_occ, ncol_global=nocc)
1493 184 : CALL cp_fm_get_info(gs_mos(2)%mos_virt, ncol_global=nvirt)
1494 184 : nstate_max = nocc*nvirt + nstate_max
1495 : END IF
1496 1446 : IF (nstates > nstate_max) THEN
1497 0 : CPWARN("NUMBER OF EXCITED STATES COULD LEAD TO PROBLEMS!")
1498 0 : CPWARN("Experimental: CHANGED NSTATES TO ITS MAXIMUM VALUE!")
1499 0 : nstates = nstate_max
1500 : END IF
1501 :
1502 1446 : soc_section => section_vals_get_subs_vals(tddfpt_section, "SOC")
1503 1446 : CALL section_vals_get(soc_section, explicit=do_soc)
1504 :
1505 : ! reuse Ritz vectors from the previous calculation if available
1506 1446 : IF (tddfpt_control%is_restart .AND. .NOT. do_soc) THEN
1507 6 : CALL get_qs_env(qs_env, blacs_env=blacs_env)
1508 :
1509 : nstates_read = tddfpt_read_restart( &
1510 : evects=evects, &
1511 : evals=evals, &
1512 : gs_mos=gs_mos, &
1513 : logger=logger, &
1514 : tddfpt_section=tddfpt_section, &
1515 : tddfpt_print_section=tddfpt_print_section, &
1516 : fm_pool_ao_mo_active=work_matrices%fm_pool_ao_mo_active, &
1517 6 : blacs_env_global=blacs_env)
1518 : ELSE
1519 : nstates_read = 0
1520 : END IF
1521 :
1522 : ! build the list of missed singly excited states and sort them in ascending order
1523 : ! according to their excitation energies
1524 : log_unit = cp_print_key_unit_nr(logger, tddfpt_print_section, &
1525 1446 : "GUESS_VECTORS", extension=".tddfptLog")
1526 : CALL tddfpt_guess_vectors(evects=evects, evals=evals, &
1527 : gs_mos=gs_mos, log_unit=log_unit, tddfpt_control=tddfpt_control, &
1528 : fm_pool_ao_mo_active=work_matrices%fm_pool_ao_mo_active, &
1529 1446 : qs_env=qs_env, nspins=nspins)
1530 : CALL cp_print_key_finished_output(log_unit, logger, &
1531 1446 : tddfpt_print_section, "GUESS_VECTORS")
1532 :
1533 : CALL tddfpt_orthogonalize_psi1_psi0(evects, work_matrices%S_C0_C0T, qs_env, &
1534 1446 : gs_mos, evals, tddfpt_control, work_matrices%S_C0)
1535 1446 : CALL tddfpt_orthonormalize_psi1_psi1(evects, nstates, S_evects, matrix_s(1)%matrix)
1536 :
1537 1446 : niters = tddfpt_control%niters
1538 1446 : IF (niters > 0) THEN
1539 : log_unit = cp_print_key_unit_nr(logger, tddfpt_print_section, &
1540 1446 : "ITERATION_INFO", extension=".tddfptLog")
1541 : energy_unit = cp_print_key_unit_nr(logger, &
1542 : tddfpt_print_section, &
1543 : "DETAILED_ENERGY", &
1544 1446 : extension=".tddfptLog")
1545 :
1546 1446 : IF (log_unit > 0) THEN
1547 723 : WRITE (log_unit, "(1X,A)") "", &
1548 723 : "-------------------------------------------------------------------------------", &
1549 723 : "- TDDFPT WAVEFUNCTION OPTIMIZATION -", &
1550 1446 : "-------------------------------------------------------------------------------"
1551 :
1552 723 : WRITE (log_unit, '(/,T11,A,T27,A,T40,A,T62,A)') "Step", "Time", "Convergence", "Conv. states"
1553 723 : WRITE (log_unit, '(1X,79("-"))')
1554 : END IF
1555 :
1556 1446 : CALL cp_add_iter_level(logger, "TDDFT_SCF")
1557 :
1558 : DO
1559 : ! *** perform Davidson iterations ***
1560 : conv = tddfpt_davidson_solver( &
1561 : evects=evects, &
1562 : evals=evals, &
1563 : S_evects=S_evects, &
1564 : gs_mos=gs_mos, &
1565 : tddfpt_control=tddfpt_control, &
1566 : matrix_ks=matrix_ks, &
1567 : qs_env=qs_env, &
1568 : kernel_env=kernel_env, &
1569 : sub_env=sub_env, &
1570 : logger=logger, &
1571 : iter_unit=log_unit, &
1572 : energy_unit=energy_unit, &
1573 : tddfpt_print_section=tddfpt_print_section, &
1574 1536 : work_matrices=work_matrices)
1575 :
1576 : ! at this point at least one of the following conditions are met:
1577 : ! a) convergence criteria has been achieved;
1578 : ! b) maximum number of iterations has been reached;
1579 : ! c) Davidson iterations must be restarted due to lack of Krylov vectors
1580 :
1581 1536 : CALL cp_iterate(logger%iter_info, increment=0, iter_nr_out=iter)
1582 : ! terminate the loop if either (a) or (b) is true ...
1583 1536 : IF ((conv <= tddfpt_control%conv) .OR. iter >= niters) EXIT
1584 :
1585 : ! ... otherwise restart Davidson iterations
1586 90 : evals = 0.0_dp
1587 1536 : IF (log_unit > 0) THEN
1588 45 : WRITE (log_unit, '(1X,25("-"),1X,A,1X,25("-"))') "Restart Davidson iterations"
1589 45 : CALL m_flush(log_unit)
1590 : END IF
1591 : END DO
1592 :
1593 : ! write TDDFPT restart file at the last iteration if requested to do so
1594 1446 : CALL cp_iterate(logger%iter_info, increment=0, last=.TRUE.)
1595 : CALL tddfpt_write_restart(evects=evects, &
1596 : evals=evals, &
1597 : gs_mos=gs_mos, &
1598 : logger=logger, &
1599 1446 : tddfpt_print_section=tddfpt_print_section)
1600 :
1601 1446 : CALL cp_rm_iter_level(logger, "TDDFT_SCF")
1602 :
1603 : ! print convergence summary
1604 1446 : IF (log_unit > 0) THEN
1605 723 : CALL integer_to_string(iter, nstates_str)
1606 723 : IF (conv <= tddfpt_control%conv) THEN
1607 723 : WRITE (log_unit, "(1X,A)") "", &
1608 723 : "-------------------------------------------------------------------------------", &
1609 723 : "- TDDFPT run converged in "//TRIM(nstates_str)//" iteration(s) ", &
1610 1446 : "-------------------------------------------------------------------------------"
1611 : ELSE
1612 0 : WRITE (log_unit, "(1X,A)") "", &
1613 0 : "-------------------------------------------------------------------------------", &
1614 0 : "- TDDFPT run did NOT converge after "//TRIM(nstates_str)//" iteration(s) ", &
1615 0 : "-------------------------------------------------------------------------------"
1616 : END IF
1617 : END IF
1618 :
1619 : CALL cp_print_key_finished_output(energy_unit, logger, &
1620 1446 : tddfpt_print_section, "DETAILED_ENERGY")
1621 : CALL cp_print_key_finished_output(log_unit, logger, &
1622 1446 : tddfpt_print_section, "ITERATION_INFO")
1623 : ELSE
1624 : CALL cp_warn(__LOCATION__, &
1625 0 : "Skipping TDDFPT wavefunction optimization")
1626 : END IF
1627 :
1628 : IF (ASSOCIATED(matrix_ks_oep)) THEN
1629 : IF (tddfpt_control%dipole_form == tddfpt_dipole_velocity) THEN
1630 : CALL cp_warn(__LOCATION__, &
1631 : "Transition dipole moments and oscillator strengths are likely to be incorrect "// &
1632 : "when computed using an orbital energy correction XC-potential together with "// &
1633 : "the velocity form of dipole transition integrals")
1634 : END IF
1635 : END IF
1636 :
1637 : ! *** print summary information ***
1638 1446 : log_unit = cp_logger_get_default_io_unit(logger)
1639 :
1640 : namd_print_section => section_vals_get_subs_vals( &
1641 : tddfpt_print_section, &
1642 1446 : "NAMD_PRINT")
1643 1446 : CALL section_vals_get(namd_print_section, explicit=explicit)
1644 1446 : IF (explicit) THEN
1645 : CALL tddfpt_write_newtonx_output(evects, &
1646 : evals, &
1647 : gs_mos, &
1648 : logger, &
1649 : tddfpt_print_section, &
1650 : matrix_s(1)%matrix, &
1651 : S_evects, &
1652 2 : sub_env)
1653 : END IF
1654 4338 : ALLOCATE (ostrength(nstates))
1655 1446 : ostrength = 0.0_dp
1656 : CALL tddfpt_print_summary(log_unit, &
1657 : evects, &
1658 : evals, &
1659 : gs_mos, &
1660 : ostrength, &
1661 : mult, &
1662 : dipole_op_mos_occ, &
1663 1446 : tddfpt_control%dipole_form)
1664 : CALL tddfpt_print_excitation_analysis( &
1665 : log_unit, &
1666 : evects, &
1667 : evals, &
1668 : gs_mos, &
1669 : matrix_s(1)%matrix, &
1670 : tddfpt_control%spinflip, &
1671 1446 : min_amplitude=tddfpt_control%min_excitation_amplitude)
1672 : CALL tddfpt_print_nto_analysis(qs_env, &
1673 : evects, evals, &
1674 : ostrength, &
1675 : gs_mos, &
1676 : matrix_s(1)%matrix, &
1677 1446 : tddfpt_print_section)
1678 1446 : IF (tddfpt_control%do_exciton_descriptors) THEN
1679 : CALL tddfpt_print_exciton_descriptors( &
1680 : log_unit, &
1681 : evects, &
1682 : gs_mos, &
1683 : matrix_s(1)%matrix, &
1684 : tddfpt_control%do_directional_exciton_descriptors, &
1685 : tddfpt_control%do_directional_exciton_crosscorrelation, &
1686 2 : qs_env)
1687 : END IF
1688 :
1689 1446 : IF (tddfpt_control%do_lrigpw) THEN
1690 : CALL lri_print_stat(qs_env, &
1691 : ltddfpt=.TRUE., &
1692 10 : tddfpt_lri_env=kernel_env%full_kernel%lri_env)
1693 : END IF
1694 :
1695 1446 : CALL timestop(handle)
1696 5784 : END SUBROUTINE tddfpt_energies
1697 :
1698 : ! **************************************************************************************************
1699 : !> \brief Perform singlet and triplet computations for subsequent TDDFPT-SOC calculation.
1700 : !> \param qs_env Quickstep environment
1701 : !> \param nstates number of requested exited states
1702 : !> \param work_matrices ...
1703 : !> \param tddfpt_control ...
1704 : !> \param logger ...
1705 : !> \param tddfpt_print_section ...
1706 : !> \param evects Eigenvector of the requested multiplicity
1707 : !> \param evals Eigenvalue of the requested multiplicity
1708 : !> \param ostrength Oscillatorstrength
1709 : !> \param gs_mos ...
1710 : !> \param tddfpt_section ...
1711 : !> \param S_evects ...
1712 : !> \param matrix_s ...
1713 : !> \param kernel_env ...
1714 : !> \param matrix_ks ...
1715 : !> \param sub_env ...
1716 : !> \param dipole_op_mos_occ ...
1717 : !> \param lmult_tmp ...
1718 : !> \param xc_section ...
1719 : !> \param full_kernel_env ...
1720 : !> \param kernel_env_admm_aux ...
1721 : !> \par History
1722 : !> * 02.2023 created [Jan-Robert Vogt]
1723 : !> \note Based on tddfpt2_methods and xas_tdp_utils.
1724 : !> \note only the values of one multiplicity will be passed back for force calculations!
1725 : ! **************************************************************************************************
1726 :
1727 10 : SUBROUTINE tddfpt_soc_energies(qs_env, nstates, work_matrices, &
1728 : tddfpt_control, logger, tddfpt_print_section, &
1729 : evects, evals, ostrength, &
1730 : gs_mos, tddfpt_section, S_evects, matrix_s, kernel_env, matrix_ks, &
1731 : sub_env, dipole_op_mos_occ, lmult_tmp, xc_section, full_kernel_env, &
1732 : kernel_env_admm_aux)
1733 :
1734 : TYPE(qs_environment_type), INTENT(IN), POINTER :: qs_env
1735 : INTEGER, INTENT(in) :: nstates
1736 : TYPE(tddfpt_work_matrices) :: work_matrices
1737 : TYPE(tddfpt2_control_type), POINTER :: tddfpt_control
1738 : TYPE(cp_logger_type), POINTER :: logger
1739 : TYPE(section_vals_type), POINTER :: tddfpt_print_section
1740 : TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:, :) :: evects
1741 : REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: evals, ostrength
1742 : TYPE(tddfpt_ground_state_mos), DIMENSION(:), &
1743 : POINTER :: gs_mos
1744 : TYPE(section_vals_type), POINTER :: tddfpt_section
1745 : TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:, :) :: S_evects
1746 : TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_s
1747 : TYPE(kernel_env_type) :: kernel_env
1748 : TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_ks
1749 : TYPE(tddfpt_subgroup_env_type) :: sub_env
1750 : TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:, :) :: dipole_op_mos_occ
1751 : LOGICAL, INTENT(in) :: lmult_tmp
1752 : TYPE(section_vals_type), POINTER :: xc_section
1753 : TYPE(full_kernel_env_type), TARGET :: full_kernel_env, kernel_env_admm_aux
1754 :
1755 : CHARACTER(LEN=*), PARAMETER :: routineN = 'tddfpt_soc_energies'
1756 :
1757 : INTEGER :: handle, ispin, istate, log_unit, mult, &
1758 : nspins
1759 : LOGICAL :: do_sf
1760 10 : REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: evals_mult, ostrength_mult
1761 10 : TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:, :) :: evects_mult
1762 :
1763 10 : CALL timeset(routineN, handle)
1764 :
1765 : log_unit = cp_print_key_unit_nr(logger, tddfpt_print_section, &
1766 : "PROGRAM_BANNER", &
1767 10 : extension=".tddfptLog")
1768 10 : CALL tddfpt_soc_header(log_unit)
1769 :
1770 10 : nspins = SIZE(gs_mos)
1771 96 : ALLOCATE (evects_mult(nspins, nstates))
1772 30 : ALLOCATE (evals_mult(nstates))
1773 10 : do_sf = tddfpt_control%spinflip /= no_sf_tddfpt
1774 :
1775 : ! First multiplicity
1776 10 : IF (lmult_tmp) THEN
1777 2 : IF (log_unit > 0) THEN
1778 1 : WRITE (log_unit, "(1X,A)") "", &
1779 1 : "-------------------------------------------------------------------------------", &
1780 1 : "- TDDFPT SINGLET ENERGIES -", &
1781 2 : "-------------------------------------------------------------------------------"
1782 : END IF
1783 2 : mult = 1
1784 : ELSE
1785 8 : IF (log_unit > 0) THEN
1786 4 : WRITE (log_unit, "(1X,A)") "", &
1787 4 : "-------------------------------------------------------------------------------", &
1788 4 : "- TDDFPT TRIPLET ENERGIES -", &
1789 8 : "-------------------------------------------------------------------------------"
1790 : END IF
1791 8 : mult = 3
1792 : END IF
1793 :
1794 : CALL tddfpt_energies(qs_env, nstates, nspins, work_matrices, tddfpt_control, logger, &
1795 : tddfpt_print_section, evects_mult, evals_mult, &
1796 : gs_mos, tddfpt_section, S_evects, matrix_s, &
1797 : kernel_env, matrix_ks, sub_env, ostrength_mult, &
1798 : dipole_op_mos_occ, mult, xc_section, full_kernel_env, &
1799 10 : kernel_env_admm_aux)
1800 :
1801 : ! Clean up in between for full kernel
1802 10 : IF (tddfpt_control%kernel == tddfpt_kernel_full) THEN
1803 10 : IF (tddfpt_control%do_admm) CALL release_kernel_env(kernel_env%admm_kernel)
1804 10 : CALL release_kernel_env(kernel_env%full_kernel)
1805 10 : CALL tddfpt_release_work_matrices(work_matrices, sub_env)
1806 : CALL tddfpt_create_work_matrices(work_matrices, gs_mos, nstates, &
1807 : tddfpt_control%do_hfx, &
1808 : tddfpt_control%do_admm, tddfpt_control%do_hfxlr, &
1809 10 : tddfpt_control%do_exck, do_sf, qs_env, sub_env)
1810 : END IF
1811 :
1812 38 : DO istate = 1, nstates
1813 66 : DO ispin = 1, nspins
1814 56 : CALL cp_fm_release(S_evects(ispin, istate))
1815 : END DO
1816 : END DO
1817 :
1818 38 : DO istate = 1, nstates
1819 66 : DO ispin = 1, nspins
1820 : CALL fm_pool_create_fm( &
1821 : work_matrices%fm_pool_ao_mo_active(ispin)%pool, &
1822 56 : S_evects(ispin, istate))
1823 : END DO
1824 : END DO
1825 :
1826 10 : tddfpt_control%rks_triplets = lmult_tmp
1827 :
1828 : ! Second multiplicity
1829 10 : IF (lmult_tmp) THEN
1830 2 : IF (log_unit > 0) THEN
1831 1 : WRITE (log_unit, "(1X,A)") "", &
1832 1 : " singlet excitations finished ", &
1833 1 : " ", &
1834 1 : "-------------------------------------------------------------------------------", &
1835 1 : "- TDDFPT TRIPLET ENERGIES -", &
1836 2 : "-------------------------------------------------------------------------------"
1837 : END IF !log_unit
1838 2 : mult = 3
1839 : ELSE
1840 8 : IF (log_unit > 0) THEN
1841 4 : WRITE (log_unit, "(1X,A)") "", &
1842 4 : " triplet excitations finished ", &
1843 4 : " ", &
1844 4 : "-------------------------------------------------------------------------------", &
1845 4 : "- TDDFPT SINGLET ENERGIES -", &
1846 8 : "-------------------------------------------------------------------------------"
1847 : END IF !log_unit
1848 8 : mult = 1
1849 : END IF
1850 :
1851 : CALL tddfpt_energies(qs_env, nstates, nspins, work_matrices, tddfpt_control, logger, &
1852 : tddfpt_print_section, evects, evals, &
1853 : gs_mos, tddfpt_section, S_evects, matrix_s, &
1854 : kernel_env, matrix_ks, sub_env, ostrength, &
1855 : dipole_op_mos_occ, mult, xc_section, full_kernel_env, &
1856 10 : kernel_env_admm_aux)
1857 :
1858 : ! Compute perturbative SOC correction
1859 : ! Order should always be singlet triplet in tddfpt_soc
1860 10 : IF (lmult_tmp) THEN
1861 2 : CALL tddfpt_soc(qs_env, evals_mult, evals, evects_mult, evects, gs_mos) !mult=singlet
1862 : ELSE
1863 8 : CALL tddfpt_soc(qs_env, evals, evals_mult, evects, evects_mult, gs_mos) !mult=triplet
1864 : END IF
1865 :
1866 : ! deallocate the additional multiplicity
1867 20 : DO ispin = 1, SIZE(evects_mult, 1)
1868 48 : DO istate = 1, SIZE(evects_mult, 2)
1869 38 : CALL cp_fm_release(evects_mult(ispin, istate))
1870 : END DO
1871 : END DO
1872 10 : DEALLOCATE (evects_mult, evals_mult, ostrength_mult)
1873 :
1874 10 : CALL timestop(handle)
1875 :
1876 20 : END SUBROUTINE tddfpt_soc_energies
1877 :
1878 : ! **************************************************************************************************
1879 : !> \brief ...
1880 : !> \param qs_env ...
1881 : !> \param gs_mos ...
1882 : !> \param tddfpt_control ...
1883 : !> \param tddfpt_section ...
1884 : !> \param iounit ...
1885 : ! **************************************************************************************************
1886 1436 : SUBROUTINE init_res_method(qs_env, gs_mos, tddfpt_control, tddfpt_section, iounit)
1887 :
1888 : TYPE(qs_environment_type), POINTER :: qs_env
1889 : TYPE(tddfpt_ground_state_mos), DIMENSION(:), &
1890 : POINTER :: gs_mos
1891 : TYPE(tddfpt2_control_type), POINTER :: tddfpt_control
1892 : TYPE(section_vals_type), POINTER :: tddfpt_section
1893 : INTEGER, INTENT(IN) :: iounit
1894 :
1895 : CHARACTER(LEN=*), PARAMETER :: routineN = 'init_res_method'
1896 :
1897 : INTEGER :: handle, i, io, ispin, nao, nmo, nmol, &
1898 : nspins
1899 1436 : INTEGER, ALLOCATABLE, DIMENSION(:, :) :: orblist
1900 1436 : INTEGER, DIMENSION(:), POINTER :: mollist
1901 : LOGICAL :: do_res, do_sf, ew1, ew2, ew3, ewcut, lms
1902 : REAL(KIND=dp) :: eclow, ecup, eint, emo
1903 1436 : REAL(KIND=dp), DIMENSION(:), POINTER :: rvint
1904 : TYPE(cp_blacs_env_type), POINTER :: blacs_env
1905 : TYPE(cp_fm_struct_type), POINTER :: fm_struct
1906 : TYPE(section_vals_type), POINTER :: res_section
1907 :
1908 1436 : CALL timeset(routineN, handle)
1909 :
1910 1436 : res_section => section_vals_get_subs_vals(tddfpt_section, "REDUCED_EXCITATION_SPACE")
1911 1436 : CALL section_vals_val_get(res_section, "_SECTION_PARAMETERS_", l_val=do_res)
1912 :
1913 : ! spin flip TDA
1914 1436 : IF (tddfpt_control%spinflip == no_sf_tddfpt) THEN
1915 : do_sf = .FALSE.
1916 : ELSE
1917 26 : do_sf = .TRUE.
1918 : END IF
1919 :
1920 1436 : nspins = SIZE(gs_mos)
1921 1436 : IF (.NOT. do_res) THEN
1922 3050 : DO ispin = 1, nspins
1923 1630 : nmo = gs_mos(ispin)%nmo_occ
1924 1630 : tddfpt_control%nactive(ispin) = nmo
1925 1630 : gs_mos(ispin)%nmo_active = nmo
1926 4890 : ALLOCATE (gs_mos(ispin)%index_active(nmo))
1927 11306 : DO i = 1, nmo
1928 9886 : gs_mos(ispin)%index_active(i) = i
1929 : END DO
1930 : END DO
1931 : ELSE
1932 16 : IF (iounit > 0) THEN
1933 8 : WRITE (iounit, "(/,1X,27('='),A,26('='))") ' REDUCED EXCITATION SPACE '
1934 : END IF
1935 16 : CALL section_vals_val_get(res_section, "ENERGY_WINDOW", explicit=ew1)
1936 16 : CALL section_vals_val_get(res_section, "UPPER_ENERGY_CUTOFF", explicit=ew2)
1937 16 : CALL section_vals_val_get(res_section, "LOWER_ENERGY_CUTOFF", explicit=ew3)
1938 16 : ewcut = (ew1 .OR. ew2 .OR. ew3)
1939 16 : CALL section_vals_val_get(res_section, "MOLECULE_LIST", explicit=lms)
1940 :
1941 16 : CALL section_vals_val_get(res_section, "ENERGY_WINDOW", r_vals=rvint)
1942 16 : CPASSERT(SIZE(rvint) == 2)
1943 16 : eclow = rvint(1)
1944 16 : ecup = rvint(2)
1945 16 : CALL section_vals_val_get(res_section, "UPPER_ENERGY_CUTOFF", r_val=eint)
1946 16 : ecup = MIN(ecup, eint)
1947 16 : CALL section_vals_val_get(res_section, "LOWER_ENERGY_CUTOFF", r_val=eint)
1948 16 : eclow = MAX(eclow, eint)
1949 16 : IF (ewcut .AND. (iounit > 0)) THEN
1950 8 : IF (eclow < -1.E8_dp .AND. ecup > 1.E8_dp) THEN
1951 : WRITE (iounit, "(1X,A,T51,A10,T71,A10)") &
1952 0 : 'Orbital Energy Window [eV]', " -Inf", " Inf"
1953 : ELSE IF (eclow < -1.E8_dp) THEN
1954 : WRITE (iounit, "(1X,A,T51,A10,T71,F10.4)") &
1955 3 : 'Orbital Energy Window [eV]', " -Inf", evolt*ecup
1956 5 : ELSE IF (ecup > 1.E8_dp) THEN
1957 : WRITE (iounit, "(1X,A,T51,F10.4,T71,A10)") &
1958 1 : 'Orbital Energy Window [eV]', evolt*eclow, " Inf"
1959 : ELSE
1960 : WRITE (iounit, "(1X,A,T51,F10.4,T71,F10.4)") &
1961 4 : 'Orbital Energy Window [eV]', evolt*eclow, evolt*ecup
1962 : END IF
1963 : END IF
1964 :
1965 16 : nmol = 0
1966 16 : IF (lms) THEN
1967 0 : CALL section_vals_val_get(res_section, "MOLECULE_LIST", i_vals=mollist)
1968 0 : nmol = SIZE(mollist)
1969 0 : WRITE (iounit, "(1X,A)") 'List of Selected Molecules'
1970 0 : WRITE (iounit, "(1X,15(I5))") mollist(1:nmol)
1971 : END IF
1972 :
1973 32 : DO ispin = 1, nspins
1974 32 : tddfpt_control%nactive(ispin) = gs_mos(ispin)%nmo_occ
1975 : END DO
1976 48 : nmo = MAXVAL(tddfpt_control%nactive)
1977 64 : ALLOCATE (orblist(nmo, nspins))
1978 16 : orblist = 0
1979 :
1980 16 : IF (lms) THEN
1981 : ! ignore for now
1982 0 : orblist = 1
1983 0 : DO ispin = 1, nspins
1984 0 : CPASSERT(.NOT. ASSOCIATED(gs_mos(ispin)%evals_occ_matrix))
1985 : END DO
1986 16 : ELSE IF (ewcut) THEN
1987 : ! Filter orbitals wrt energy window
1988 32 : DO ispin = 1, nspins
1989 122 : DO i = 1, gs_mos(ispin)%nmo_occ
1990 90 : emo = gs_mos(ispin)%evals_occ(i)
1991 106 : IF (emo > eclow .AND. emo < ecup) orblist(i, ispin) = 1
1992 : END DO
1993 : END DO
1994 : ELSE
1995 0 : orblist = 1
1996 : END IF
1997 :
1998 : ! count active orbitals
1999 122 : nmo = SUM(orblist)
2000 16 : IF (nmo == 0) THEN
2001 0 : CPABORT("RSE TDA: no active orbitals selected.")
2002 : END IF
2003 32 : DO ispin = 1, nspins
2004 106 : nmo = SUM(orblist(:, ispin))
2005 16 : tddfpt_control%nactive(ispin) = nmo
2006 16 : gs_mos(ispin)%nmo_active = nmo
2007 48 : ALLOCATE (gs_mos(ispin)%index_active(nmo))
2008 16 : io = 0
2009 122 : DO i = 1, SIZE(ORBLIST, 1)
2010 106 : IF (orblist(i, ispin) == 1) THEN
2011 32 : io = io + 1
2012 32 : gs_mos(ispin)%index_active(io) = i
2013 : END IF
2014 : END DO
2015 : END DO
2016 16 : DEALLOCATE (orblist)
2017 :
2018 16 : IF (lms) THEN
2019 : ! output information
2020 : ELSE
2021 16 : IF (iounit > 0) THEN
2022 8 : WRITE (iounit, "(1X,A)") 'List of Selected States'
2023 8 : IF (nspins == 1) THEN
2024 8 : WRITE (iounit, "(A,T67,A)") ' Active State Orbital', 'Orbital Energy'
2025 24 : DO i = 1, gs_mos(1)%nmo_active
2026 16 : io = gs_mos(1)%index_active(i)
2027 24 : WRITE (iounit, "(T8,I6,T21,I6,T61,F20.4)") i, io, gs_mos(1)%evals_occ(io)*evolt
2028 : END DO
2029 : ELSE
2030 0 : DO ispin = 1, nspins
2031 0 : WRITE (iounit, "(1X,A,I2)") 'Spin ', ispin
2032 0 : WRITE (iounit, "(A,T67,A)") ' Active State Orbital', 'Orbital Energy'
2033 0 : DO i = 1, gs_mos(ispin)%nmo_active
2034 0 : io = gs_mos(ispin)%index_active(i)
2035 0 : WRITE (iounit, "(T8,I6,T21,I6,T61,F20.4)") i, io, gs_mos(ispin)%evals_occ(io)*evolt
2036 : END DO
2037 : END DO
2038 : END IF
2039 : END IF
2040 : END IF
2041 :
2042 16 : IF (do_sf) THEN
2043 0 : CPABORT("Restricted Active Space with spin flip TDA NYA")
2044 : END IF
2045 :
2046 64 : IF (iounit > 0) THEN
2047 8 : WRITE (iounit, "(1X,79('='))")
2048 : END IF
2049 : END IF
2050 :
2051 : ! Allocate mos_active
2052 3082 : DO ispin = 1, nspins
2053 1646 : CALL get_qs_env(qs_env, blacs_env=blacs_env)
2054 1646 : CALL cp_fm_get_info(gs_mos(ispin)%mos_occ, nrow_global=nao)
2055 1646 : nmo = gs_mos(ispin)%nmo_active
2056 : CALL cp_fm_struct_create(fm_struct, template_fmstruct=gs_mos(ispin)%mos_occ%matrix_struct, &
2057 1646 : ncol_global=nmo, context=blacs_env)
2058 1646 : NULLIFY (gs_mos(ispin)%mos_active)
2059 1646 : ALLOCATE (gs_mos(ispin)%mos_active)
2060 1646 : CALL cp_fm_create(gs_mos(ispin)%mos_active, fm_struct)
2061 1646 : CALL cp_fm_struct_release(fm_struct)
2062 : ! copy the active orbitals
2063 4728 : IF (gs_mos(ispin)%nmo_active == gs_mos(ispin)%nmo_occ) THEN
2064 9886 : DO i = 1, gs_mos(ispin)%nmo_active
2065 9886 : CPASSERT(i == gs_mos(ispin)%index_active(i))
2066 : END DO
2067 : CALL cp_fm_to_fm_submat(gs_mos(ispin)%mos_occ, gs_mos(ispin)%mos_active, &
2068 1630 : nao, nmo, 1, 1, 1, 1)
2069 : ELSE
2070 48 : DO i = 1, gs_mos(ispin)%nmo_active
2071 32 : io = gs_mos(ispin)%index_active(i)
2072 : CALL cp_fm_to_fm_submat(gs_mos(ispin)%mos_occ, gs_mos(ispin)%mos_active, &
2073 48 : nao, 1, 1, io, 1, i)
2074 : END DO
2075 : END IF
2076 : END DO
2077 :
2078 1436 : CALL timestop(handle)
2079 :
2080 1436 : END SUBROUTINE init_res_method
2081 :
2082 : END MODULE qs_tddfpt2_methods
|