(git:4c55286)
Loading...
Searching...
No Matches
qs_tddfpt2_methods.F
Go to the documentation of this file.
1!--------------------------------------------------------------------------------------------------!
2! CP2K: A general program to perform molecular dynamics simulations !
3! Copyright 2000-2026 CP2K developers group <https://cp2k.org> !
4! !
5! SPDX-License-Identifier: GPL-2.0-or-later !
6!--------------------------------------------------------------------------------------------------!
7
10 USE admm_types, ONLY: admm_type,&
13 USE bibliography, ONLY: grimme2013,&
17 cite_reference
18 USE cell_types, ONLY: cell_type
23 USE cp_dbcsr_api, ONLY: dbcsr_p_type
29 USE cp_fm_types, ONLY: cp_fm_create,&
44 USE header, ONLY: tddfpt_header,&
49 USE input_constants, ONLY: &
58 USE kinds, ONLY: dp
62 USE machine, ONLY: m_flush
66 USE physcon, ONLY: evolt
75 USE qs_mo_types, ONLY: mo_set_type
96 USE qs_tddfpt2_soc, ONLY: tddfpt_soc
116 USE rixs_types, ONLY: rixs_env_type,&
119 USE xc_write_output, ONLY: xc_write
120#include "./base/base_uses.f90"
121
122 IMPLICIT NONE
123
124 PRIVATE
125
126 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_tddfpt2_methods'
127
128 LOGICAL, PARAMETER, PRIVATE :: debug_this_module = .false.
129 ! number of first derivative components (3: d/dx, d/dy, d/dz)
130 INTEGER, PARAMETER, PRIVATE :: nderivs = 3
131 INTEGER, PARAMETER, PRIVATE :: maxspins = 2
132
134
135! **************************************************************************************************
136
137CONTAINS
138
139! **************************************************************************************************
140!> \brief Perform TDDFPT calculation. If calc_forces then it also builds the response vector for the
141!> Z-vector method and calculates some contributions to the force
142!> \param qs_env Quickstep environment
143!> \param calc_forces ...
144!> \param rixs_env ...
145!> \par History
146!> * 05.2016 created [Sergey Chulkov]
147!> * 06.2016 refactored to be used with Davidson eigensolver [Sergey Chulkov]
148!> * 03.2017 cleaned and refactored [Sergey Chulkov]
149!> \note Based on the subroutines tddfpt_env_init(), and tddfpt_env_deallocate().
150! **************************************************************************************************
151 SUBROUTINE tddfpt(qs_env, calc_forces, rixs_env)
152 TYPE(qs_environment_type), POINTER :: qs_env
153 LOGICAL, INTENT(IN) :: calc_forces
154 TYPE(rixs_env_type), OPTIONAL, POINTER :: rixs_env
155
156 CHARACTER(LEN=*), PARAMETER :: routinen = 'tddfpt'
157
158 INTEGER :: handle, ispin, istate, log_unit, mult, &
159 my_state, nao, nocc, nspins, &
160 nstate_max, nstates, nvirt, old_state
161 INTEGER, DIMENSION(maxspins) :: nactive
162 LOGICAL :: do_admm, do_exck, do_hfx, do_hfxlr, &
163 do_hfxsr, do_rixs, do_sf, do_soc, &
164 lmult_tmp, state_change
165 REAL(kind=dp) :: gsmin, gsval, xsval
166 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: evals, ostrength
167 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
168 TYPE(cell_type), POINTER :: cell
169 TYPE(cp_blacs_env_type), POINTER :: blacs_env
170 TYPE(cp_fm_struct_type), POINTER :: matrix_struct
171 TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:) :: my_active, my_mos
172 TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:, :) :: dipole_op_mos_occ, evects, s_evects
173 TYPE(cp_logger_type), POINTER :: logger
174 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_ks, matrix_ks_oep, matrix_s, &
175 matrix_s_aux_fit, &
176 matrix_s_aux_fit_vs_orb
177 TYPE(dft_control_type), POINTER :: dft_control
178 TYPE(excited_energy_type), POINTER :: ex_env
179 TYPE(full_kernel_env_type), TARGET :: full_kernel_env, kernel_env_admm_aux
180 TYPE(kernel_env_type) :: kernel_env
181 TYPE(mo_set_type), DIMENSION(:), POINTER :: mos, mos_aux_fit
182 TYPE(mp_para_env_type), POINTER :: para_env
183 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
184 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
185 TYPE(qs_scf_env_type), POINTER :: scf_env
186 TYPE(rixs_control_type), POINTER :: rixs_control
187 TYPE(section_vals_type), POINTER :: hfxsr_section, kernel_section, &
188 lri_section, soc_section, &
189 tddfpt_print_section, tddfpt_section, &
190 xc_section
191 TYPE(stda_env_type), TARGET :: stda_kernel
192 TYPE(tddfpt2_control_type), POINTER :: tddfpt_control
193 TYPE(tddfpt2_valence_type), POINTER :: valence_state
194 TYPE(tddfpt_ground_state_mos), DIMENSION(:), &
195 POINTER :: gs_mos
196 TYPE(tddfpt_subgroup_env_type) :: sub_env
197 TYPE(tddfpt_work_matrices) :: work_matrices
198
199 CALL timeset(routinen, handle)
200
201 NULLIFY (logger)
202 logger => cp_get_default_logger()
203
204 NULLIFY (tddfpt_section, tddfpt_control)
205
206 CALL get_qs_env(qs_env, &
207 blacs_env=blacs_env, &
208 cell=cell, &
209 dft_control=dft_control, &
210 matrix_ks=matrix_ks, &
211 matrix_s=matrix_s, &
212 mos=mos, &
213 scf_env=scf_env, &
214 do_rixs=do_rixs)
215
216 IF (do_rixs) THEN
217 tddfpt_section => section_vals_get_subs_vals(qs_env%input, "PROPERTIES%RIXS%TDDFPT")
218 NULLIFY (rixs_control, valence_state)
219 rixs_control => dft_control%rixs_control
220 tddfpt_control => rixs_control%tddfpt2_control
221 valence_state => rixs_env%valence_state
222 ELSE
223 tddfpt_section => section_vals_get_subs_vals(qs_env%input, "PROPERTIES%TDDFPT")
224 tddfpt_control => dft_control%tddfpt2_control
225 END IF
226
227 ! input section print/xc
228 CALL tddfpt_input(qs_env, tddfpt_section, tddfpt_control, do_hfx, do_admm, do_exck, &
229 do_hfxsr, do_hfxlr, xc_section, tddfpt_print_section, &
230 lri_section, hfxsr_section)
231
232 log_unit = cp_print_key_unit_nr(logger, tddfpt_print_section, "PROGRAM_BANNER", &
233 extension=".tddfptLog")
234
235 tddfpt_control%do_hfx = do_hfx
236 tddfpt_control%do_admm = do_admm
237 tddfpt_control%do_hfxsr = do_hfxsr
238 tddfpt_control%hfxsr_primbas = 0
239 tddfpt_control%hfxsr_re_int = .true.
240 tddfpt_control%do_hfxlr = do_hfxlr
241 tddfpt_control%do_exck = do_exck
242 do_sf = tddfpt_control%spinflip /= no_sf_tddfpt
243 IF (do_sf) CALL cite_reference(hernandez2025)
244 IF (tddfpt_control%do_hfxlr) THEN
245 kernel_section => section_vals_get_subs_vals(tddfpt_section, "XC%HFX_KERNEL%HFXLR")
246 CALL section_vals_val_get(kernel_section, "RCUT", r_val=tddfpt_control%hfxlr_rcut)
247 CALL section_vals_val_get(kernel_section, "SCALE", r_val=tddfpt_control%hfxlr_scale)
248 END IF
249
250 soc_section => section_vals_get_subs_vals(tddfpt_section, "SOC")
251 CALL section_vals_get(soc_section, explicit=do_soc)
252
253 IF (do_soc) THEN
254 ! start with multiplicity that is not specified in input
255 ! so that excited-state gradient is for multiplicity given in input
256 lmult_tmp = tddfpt_control%rks_triplets
257 tddfpt_control%rks_triplets = .NOT. (tddfpt_control%rks_triplets)
258 END IF
259
260 CALL cite_reference(iannuzzi2005)
261 IF (tddfpt_control%kernel == tddfpt_kernel_stda) THEN
262 CALL cite_reference(grimme2013)
263 CALL cite_reference(grimme2016)
264 END IF
265
266 CALL tddfpt_header(log_unit)
267 CALL kernel_info(log_unit, dft_control, tddfpt_control, xc_section)
268
269 ! obtain occupied and virtual (unoccupied) ground-state Kohn-Sham orbitals
270 NULLIFY (gs_mos)
271 CALL tddfpt_init_mos(qs_env, gs_mos, log_unit)
272
273 ! obtain smeared occupation numbers
274 IF (tddfpt_control%do_smearing) THEN
275 CALL tddfpt_smeared_occupation(qs_env, gs_mos, log_unit)
276 END IF
277
278 ! obtain corrected KS-matrix
279 CALL tddfpt_oecorr(qs_env, gs_mos, matrix_ks_oep)
280
281 IF ((tddfpt_control%do_lrigpw) .AND. &
282 (tddfpt_control%kernel /= tddfpt_kernel_full)) THEN
283 CALL cp_abort(__location__, "LRI only implemented for full kernel")
284 END IF
285
286 IF (ASSOCIATED(matrix_ks_oep)) matrix_ks => matrix_ks_oep
287
288 ! determine active orbitals
289 ! default is all occupied MOs
290 CALL init_res_method(qs_env, gs_mos, tddfpt_control, tddfpt_section, log_unit)
291
292 ! components of the dipole operator
293 CALL tddfpt_dipole_operator(dipole_op_mos_occ, &
294 tddfpt_control, &
295 gs_mos, &
296 qs_env)
297
298 nspins = SIZE(gs_mos)
299 ! multiplicity of molecular system
300 IF (nspins > 1) THEN
301 mult = abs(SIZE(gs_mos(1)%evals_occ) - SIZE(gs_mos(2)%evals_occ)) + 1
302 IF (mult > 2) &
303 CALL cp_warn(__location__, "There is a convergence issue for multiplicity >= 3")
304 ELSE
305 IF (tddfpt_control%rks_triplets) THEN
306 mult = 3
307 ELSE
308 mult = 1
309 END IF
310 END IF
311
312 ! split mpi communicator
313 ALLOCATE (my_mos(nspins), my_active(nspins))
314 DO ispin = 1, nspins
315 my_mos(ispin) = gs_mos(ispin)%mos_occ
316 my_active(ispin) = gs_mos(ispin)%mos_active
317 END DO
318 CALL tddfpt_sub_env_init(sub_env, qs_env, &
319 mos_occ=my_mos(:), mos_active=my_active(:), &
320 kernel=tddfpt_control%kernel)
321 DEALLOCATE (my_mos, my_active)
322
323 IF (tddfpt_control%kernel == tddfpt_kernel_full) THEN
324 ! create environment for Full Kernel
325 IF (dft_control%qs_control%xtb) THEN
326 cpabort("TDDFPT: xTB only works with sTDA Kernel")
327 END IF
328
329 IF (tddfpt_control%do_hfxsr) THEN
330 kernel_section => section_vals_get_subs_vals(tddfpt_section, "XC%HFX_KERNEL")
331 CALL section_vals_val_get(kernel_section, "HFXSR_PRIMBAS", &
332 i_val=tddfpt_control%hfxsr_primbas)
333 ! basis set
334 CALL create_minbas_set(qs_env, log_unit, basis_type="TDA_HFX", &
335 primitive=tddfpt_control%hfxsr_primbas)
336 ! admm control
337 ALLOCATE (full_kernel_env%admm_control)
338 full_kernel_env%admm_control%purification_method = do_admm_purify_none
339 full_kernel_env%admm_control%method = do_admm_basis_projection
340 full_kernel_env%admm_control%scaling_model = do_admm_exch_scaling_none
341 full_kernel_env%admm_control%aux_exch_func = do_admm_aux_exch_func_none
342 ! hfx section
343 full_kernel_env%hfxsr_section => hfxsr_section
344 !
345 CALL aux_admm_init(qs_env, mos, full_kernel_env%admm_env, &
346 full_kernel_env%admm_control, "TDA_HFX")
347 CALL get_admm_env(full_kernel_env%admm_env, mos_aux_fit=mos_aux_fit, &
348 matrix_s_aux_fit=matrix_s_aux_fit, &
349 matrix_s_aux_fit_vs_orb=matrix_s_aux_fit_vs_orb)
350 CALL admm_fit_mo_coeffs(full_kernel_env%admm_env, matrix_s_aux_fit, &
351 matrix_s_aux_fit_vs_orb, mos, mos_aux_fit, .true.)
352 ! x_data
353 CALL get_qs_env(qs_env, cell=cell, atomic_kind_set=atomic_kind_set, &
354 qs_kind_set=qs_kind_set, particle_set=particle_set, &
355 para_env=para_env)
356 CALL hfx_create(full_kernel_env%x_data, para_env, hfxsr_section, atomic_kind_set, &
357 qs_kind_set, particle_set, dft_control, cell, orb_basis="TDA_HFX")
358 END IF
359
360 ! allocate pools and work matrices
361 nstates = tddfpt_control%nstates
362 !! Too many states can lead to Problems
363 !! You should be warned if there are more states
364 !! than occ-virt Combinations!!
365 CALL cp_fm_get_info(gs_mos(1)%mos_occ, ncol_global=nocc)
366 IF (tddfpt_control%spinflip == no_sf_tddfpt) THEN
367 CALL cp_fm_get_info(gs_mos(1)%mos_virt, ncol_global=nvirt)
368 ELSE
369 CALL cp_fm_get_info(gs_mos(2)%mos_virt, ncol_global=nvirt)
370 END IF
371 nstate_max = nocc*nvirt
372 IF (nstates > nstate_max) THEN
373 cpwarn("NUMBER OF EXCITED STATES COULD LEAD TO PROBLEMS!")
374 cpwarn("Experimental: CHANGED NSTATES TO ITS MAXIMUM VALUE!")
375 nstates = nstate_max
376 tddfpt_control%nstates = nstate_max
377 END IF
378 CALL tddfpt_create_work_matrices(work_matrices, gs_mos, nstates, &
379 do_hfx, do_admm, do_hfxlr, do_exck, do_sf, qs_env, sub_env)
380
381 ! create full_kernel and admm_kernel within tddfpt_energies
382 kernel_env%full_kernel => full_kernel_env
383 kernel_env%admm_kernel => kernel_env_admm_aux
384 NULLIFY (kernel_env%stda_kernel)
385 IF (do_hfxsr) THEN
386 ! work matrices for SR HFX
387 CALL hfxsr_create_work_matrices(work_matrices, qs_env, full_kernel_env%admm_env)
388 END IF
389 IF (do_hfxlr) THEN
390 ! calculate S_half and Lowdin MO coefficients
391 CALL get_lowdin_mo_coefficients(qs_env, sub_env, work_matrices)
392 END IF
393 ELSE IF (tddfpt_control%kernel == tddfpt_kernel_stda) THEN
394 ! setup for kernel_stda outside tddfpt_energies
395 CALL cp_fm_get_info(gs_mos(1)%mos_occ, nrow_global=nao)
396 nactive = tddfpt_control%nactive
397 CALL allocate_stda_env(qs_env, stda_kernel, nao, nactive)
398 ! sTDA parameters
399 CALL stda_init_param(qs_env, stda_kernel, tddfpt_control%stda_control)
400 ! allocate pools and work matrices
401 nstates = tddfpt_control%nstates
402 CALL stda_create_work_matrices(work_matrices, gs_mos, nstates, qs_env, sub_env)
403 !
404 CALL stda_init_matrices(qs_env, stda_kernel, sub_env, &
405 work_matrices, tddfpt_control)
406 !
407 kernel_env%stda_kernel => stda_kernel
408 NULLIFY (kernel_env%full_kernel)
409 NULLIFY (kernel_env%admm_kernel)
410 ELSE IF (tddfpt_control%kernel == tddfpt_kernel_none) THEN
411 ! allocate pools and work matrices
412 nstates = tddfpt_control%nstates
413 CALL stda_create_work_matrices(work_matrices, gs_mos, nstates, qs_env, sub_env)
414 NULLIFY (kernel_env%full_kernel)
415 NULLIFY (kernel_env%admm_kernel)
416 NULLIFY (kernel_env%stda_kernel)
417 END IF
418
419 IF (do_sf) THEN
420 ! only alpha -> beta excitations are considered in spin-flip TDDFT
421 ALLOCATE (evects(1, nstates))
422 ELSE
423 ALLOCATE (evects(nspins, nstates))
424 END IF
425 ALLOCATE (evals(nstates))
426 ALLOCATE (s_evects(SIZE(evects, 1), nstates))
427
428 DO istate = 1, nstates
429 DO ispin = 1, SIZE(evects, 1)
430 CALL fm_pool_create_fm( &
431 work_matrices%fm_pool_ao_mo_active(ispin)%pool, &
432 s_evects(ispin, istate))
433 END DO
434 END DO
435
436 IF (.NOT. do_soc) THEN
437 ! compute tddfpt excitation energies of multiplicity mult
438 CALL tddfpt_energies(qs_env, nstates, nspins, work_matrices, &
439 tddfpt_control, logger, tddfpt_print_section, evects, evals, &
440 gs_mos, tddfpt_section, s_evects, matrix_s, kernel_env, matrix_ks, &
441 sub_env, ostrength, dipole_op_mos_occ, mult, xc_section, full_kernel_env, &
442 kernel_env_admm_aux)
443 ELSE
444 CALL tddfpt_soc_energies(qs_env, nstates, work_matrices, &
445 tddfpt_control, logger, tddfpt_print_section, &
446 evects, evals, ostrength, &
447 gs_mos, tddfpt_section, s_evects, matrix_s, kernel_env, matrix_ks, &
448 sub_env, dipole_op_mos_occ, lmult_tmp, xc_section, full_kernel_env, &
449 kernel_env_admm_aux)
450 END IF
451
452 !print forces for selected states
453 IF (calc_forces) THEN
454 CALL tddfpt_print_forces(qs_env, evects, evals, ostrength, &
455 tddfpt_print_section, gs_mos, &
456 kernel_env, sub_env, work_matrices)
457 END IF
458
459 ! excited state potential energy surface
460 IF (qs_env%excited_state) THEN
461 IF (sub_env%is_split) THEN
462 CALL cp_abort(__location__, &
463 "Excited state forces not possible when states"// &
464 " are distributed to different CPU pools.")
465 END IF
466 ! for gradients unshifted KS matrix
467 IF (ASSOCIATED(matrix_ks_oep)) CALL get_qs_env(qs_env, matrix_ks=matrix_ks)
468 CALL get_qs_env(qs_env, exstate_env=ex_env)
469 state_change = .false.
470 IF (ex_env%state > 0) THEN
471 my_state = ex_env%state
472 ELSEIF (ex_env%state < 0) THEN
473 ! state following
474 ALLOCATE (my_mos(nspins))
475 DO ispin = 1, nspins
476 my_mos(ispin) = gs_mos(ispin)%mos_occ
477 END DO
478 my_state = abs(ex_env%state)
479 CALL assign_state(qs_env, matrix_s, evects, my_mos, ex_env%wfn_history, my_state)
480 DEALLOCATE (my_mos)
481 IF (my_state /= abs(ex_env%state)) THEN
482 state_change = .true.
483 old_state = abs(ex_env%state)
484 END IF
485 ex_env%state = -my_state
486 ELSE
487 CALL cp_warn(__location__, &
488 "Active excited state not assigned. Use the first state.")
489 my_state = 1
490 END IF
491 cpassert(my_state > 0)
492 IF (my_state > nstates) THEN
493 CALL cp_warn(__location__, &
494 "There were not enough excited states calculated.")
495 cpabort("excited state potential energy surface")
496 END IF
497 !
498 ! energy
499 ex_env%evalue = evals(my_state)
500 ! excitation vector
501 CALL cp_fm_release(ex_env%evect)
502 ALLOCATE (ex_env%evect(SIZE(evects, 1)))
503 DO ispin = 1, SIZE(evects, 1)
504 CALL cp_fm_get_info(matrix=evects(ispin, 1), &
505 matrix_struct=matrix_struct)
506 CALL cp_fm_create(ex_env%evect(ispin), matrix_struct)
507 CALL cp_fm_to_fm(evects(ispin, my_state), ex_env%evect(ispin))
508 END DO
509
510 IF (log_unit > 0) THEN
511 gsval = ex_env%wfn_history%gsval
512 gsmin = ex_env%wfn_history%gsmin
513 xsval = ex_env%wfn_history%xsval
514 WRITE (log_unit, "(1X,A,T40,F10.6,A,T62,F10.6,A)") "Ground state orbital alignment:", &
515 gsmin, "[MinVal]", gsval, "[Average]"
516 WRITE (log_unit, "(1X,A,T71,F10.6)") "Excitation vector alignment:", xsval
517 IF (state_change) THEN
518 WRITE (log_unit, "(1X,A,I5,T60,A14,T76,I5)") &
519 "Target state has been changed from state ", &
520 old_state, " to new state ", my_state
521 END IF
522 WRITE (log_unit, "(1X,A,I4,A,F12.5,A)") "Calculate properties for state:", &
523 my_state, " with excitation energy ", ex_env%evalue*evolt, " eV"
524 END IF
525
526 ! Calculate response vector
527 IF (calc_forces) THEN
528 CALL tddfpt_forces_main(qs_env, gs_mos, ex_env, kernel_env, &
529 sub_env, work_matrices)
530 END IF
531 END IF
532
533 ! share evals, evects and mo_coefs with rixs
534 IF (do_rixs) THEN
535 ! copy evals
536 valence_state%nstates = nstates
537 ALLOCATE (valence_state%evals(SIZE(evals)))
538 valence_state%evals(:) = evals(:)
539
540 ALLOCATE (valence_state%evects(nspins, nstates))
541 ALLOCATE (valence_state%mos_active(nspins))
542 DO ispin = 1, nspins
543 ! copy evects
544 DO istate = 1, nstates
545 CALL cp_fm_get_info(matrix=evects(ispin, istate), &
546 matrix_struct=matrix_struct)
547 CALL cp_fm_create(valence_state%evects(ispin, istate), matrix_struct)
548 CALL cp_fm_to_fm(evects(ispin, istate), valence_state%evects(ispin, istate))
549 END DO
550 ! copy mos_occ
551 CALL cp_fm_get_info(matrix=gs_mos(ispin)%mos_active, &
552 matrix_struct=matrix_struct)
553 CALL cp_fm_create(valence_state%mos_active(ispin), matrix_struct)
554 CALL cp_fm_to_fm(gs_mos(ispin)%mos_active, valence_state%mos_active(ispin))
555 END DO
556 END IF
557
558 ! clean up
559 CALL cp_fm_release(evects)
560 CALL cp_fm_release(s_evects)
561
562 CALL cp_print_key_finished_output(log_unit, &
563 logger, &
564 tddfpt_print_section, &
565 "PROGRAM_BANNER")
566
567 DEALLOCATE (evals, ostrength)
568
569 IF (tddfpt_control%kernel == tddfpt_kernel_full) THEN
570 IF (do_admm) CALL release_kernel_env(kernel_env%admm_kernel)
571 IF (tddfpt_control%do_lrigpw) THEN
572 CALL lri_env_release(kernel_env%full_kernel%lri_env)
573 DEALLOCATE (kernel_env%full_kernel%lri_env)
574 CALL lri_density_release(kernel_env%full_kernel%lri_density)
575 DEALLOCATE (kernel_env%full_kernel%lri_density)
576 END IF
577 CALL release_kernel_env(kernel_env%full_kernel)
578 ELSE IF (tddfpt_control%kernel == tddfpt_kernel_stda) THEN
579 CALL deallocate_stda_env(stda_kernel)
580 ELSE IF (tddfpt_control%kernel == tddfpt_kernel_none) THEN
581 !
582 ELSE
583 cpabort('Unknown kernel type')
584 END IF
585 CALL tddfpt_release_work_matrices(work_matrices, sub_env)
586 CALL tddfpt_sub_env_release(sub_env)
587
588 CALL cp_fm_release(dipole_op_mos_occ)
589
590 DO ispin = nspins, 1, -1
591 CALL tddfpt_release_ground_state_mos(gs_mos(ispin))
592 END DO
593 DEALLOCATE (gs_mos)
594
595 IF (ASSOCIATED(matrix_ks_oep)) &
596 CALL dbcsr_deallocate_matrix_set(matrix_ks_oep)
597
598 CALL timestop(handle)
599
600 END SUBROUTINE tddfpt
601
602! **************************************************************************************************
603!> \brief TDDFPT input
604!> \param qs_env Quickstep environment
605!> \param tddfpt_section ...
606!> \param tddfpt_control ...
607!> \param do_hfx ...
608!> \param do_admm ...
609!> \param do_exck ...
610!> \param do_hfxsr ...
611!> \param do_hfxlr ...
612!> \param xc_section ...
613!> \param tddfpt_print_section ...
614!> \param lri_section ...
615!> \param hfxsr_section ...
616! **************************************************************************************************
617 SUBROUTINE tddfpt_input(qs_env, tddfpt_section, tddfpt_control, do_hfx, do_admm, do_exck, &
618 do_hfxsr, do_hfxlr, xc_section, tddfpt_print_section, lri_section, &
619 hfxsr_section)
620 TYPE(qs_environment_type), POINTER :: qs_env
621 TYPE(section_vals_type), POINTER :: tddfpt_section
622 TYPE(tddfpt2_control_type), POINTER :: tddfpt_control
623 LOGICAL, INTENT(INOUT) :: do_hfx, do_admm, do_exck, do_hfxsr, &
624 do_hfxlr
625 TYPE(section_vals_type), POINTER :: xc_section, tddfpt_print_section, &
626 lri_section, hfxsr_section
627
628 CHARACTER(len=20) :: nstates_str
629 LOGICAL :: exar, exf, exgcp, exhf, exhfxk, exk, &
630 explicit_root, expot, exvdw, exwfn, &
631 found, same_hfx
632 REAL(kind=dp) :: c_hf
633 TYPE(dft_control_type), POINTER :: dft_control
634 TYPE(section_vals_type), POINTER :: hfx_section, hfx_section_gs, input, &
635 xc_root, xc_sub
636
637 NULLIFY (dft_control, input)
638 CALL get_qs_env(qs_env, dft_control=dft_control, input=input)
639
640 ! no k-points
641 IF (dft_control%nimages > 1) cpabort("k-points not implemented for TDDFPT")
642
643 IF (tddfpt_control%nstates <= 0) THEN
644 CALL integer_to_string(tddfpt_control%nstates, nstates_str)
645 CALL cp_warn(__location__, "TDDFPT calculation was requested for "// &
646 trim(nstates_str)//" excited states: nothing to do.")
647 RETURN
648 END IF
649
650 NULLIFY (tddfpt_print_section)
651 tddfpt_print_section => section_vals_get_subs_vals(tddfpt_section, "PRINT")
652
653 IF (tddfpt_control%kernel == tddfpt_kernel_full) THEN
654 NULLIFY (xc_root)
655 xc_root => section_vals_get_subs_vals(tddfpt_section, "XC")
656 CALL section_vals_get(xc_root, explicit=explicit_root)
657 NULLIFY (xc_section)
658 IF (explicit_root) THEN
659 ! No ADIABATIC_RESCALING option possible
660 NULLIFY (xc_sub)
661 xc_sub => section_vals_get_subs_vals(xc_root, "ADIABATIC_RESCALING")
662 CALL section_vals_get(xc_sub, explicit=exar)
663 IF (exar) THEN
664 CALL cp_warn(__location__, "TDDFPT Kernel with ADIABATIC_RESCALING not possible.")
665 cpabort("TDDFPT Input")
666 END IF
667 ! No GCP_POTENTIAL option possible
668 NULLIFY (xc_sub)
669 xc_sub => section_vals_get_subs_vals(xc_root, "GCP_POTENTIAL")
670 CALL section_vals_get(xc_sub, explicit=exgcp)
671 IF (exgcp) THEN
672 CALL cp_warn(__location__, "TDDFPT Kernel with GCP_POTENTIAL not possible.")
673 cpabort("TDDFPT Input")
674 END IF
675 ! No VDW_POTENTIAL option possible
676 NULLIFY (xc_sub)
677 xc_sub => section_vals_get_subs_vals(xc_root, "VDW_POTENTIAL")
678 CALL section_vals_get(xc_sub, explicit=exvdw)
679 IF (exvdw) THEN
680 CALL cp_warn(__location__, "TDDFPT Kernel with VDW_POTENTIAL not possible.")
681 cpabort("TDDFPT Input")
682 END IF
683 ! No WF_CORRELATION option possible
684 NULLIFY (xc_sub)
685 xc_sub => section_vals_get_subs_vals(xc_root, "WF_CORRELATION")
686 CALL section_vals_get(xc_sub, explicit=exwfn)
687 IF (exwfn) THEN
688 CALL cp_warn(__location__, "TDDFPT Kernel with WF_CORRELATION not possible.")
689 cpabort("TDDFPT Input")
690 END IF
691 ! No XC_POTENTIAL option possible
692 NULLIFY (xc_sub)
693 xc_sub => section_vals_get_subs_vals(xc_root, "XC_POTENTIAL")
694 CALL section_vals_get(xc_sub, explicit=expot)
695 IF (expot) THEN
696 CALL cp_warn(__location__, "TDDFPT Kernel with XC_POTENTIAL not possible.")
697 cpabort("TDDFPT Input")
698 END IF
699 !
700 NULLIFY (xc_sub)
701 xc_sub => section_vals_get_subs_vals(xc_root, "XC_FUNCTIONAL")
702 CALL section_vals_get(xc_sub, explicit=exf)
703 NULLIFY (xc_sub)
704 xc_sub => section_vals_get_subs_vals(xc_root, "XC_KERNEL")
705 CALL section_vals_get(xc_sub, explicit=exk)
706 IF ((exf .AND. exk) .OR. .NOT. (exf .OR. exk)) THEN
707 CALL cp_warn(__location__, "TDDFPT Kernel needs XC_FUNCTIONAL or XC_KERNEL section.")
708 cpabort("TDDFPT Input")
709 END IF
710 NULLIFY (xc_sub)
711 xc_sub => section_vals_get_subs_vals(xc_root, "HF")
712 CALL section_vals_get(xc_sub, explicit=exhf)
713 NULLIFY (xc_sub)
714 xc_sub => section_vals_get_subs_vals(xc_root, "HFX_KERNEL")
715 CALL section_vals_get(xc_sub, explicit=exhfxk)
716 !
717 xc_section => xc_root
718 hfx_section => section_vals_get_subs_vals(xc_section, "HF")
719 CALL section_vals_get(hfx_section, explicit=do_hfx)
720 IF (do_hfx) THEN
721 CALL section_vals_val_get(hfx_section, "FRACTION", r_val=c_hf)
722 do_hfx = (c_hf /= 0.0_dp)
723 END IF
724 !TDDFPT only works if the kernel has the same HF section as the DFT%XC one
725 IF (do_hfx) THEN
726 hfx_section_gs => section_vals_get_subs_vals(input, "DFT%XC%HF")
727 CALL compare_hfx_sections(hfx_section, hfx_section_gs, same_hfx)
728 IF (.NOT. same_hfx) THEN
729 cpabort("TDDFPT Kernel must use the same HF section as DFT%XC or no HF at all.")
730 END IF
731 END IF
732
733 do_admm = do_hfx .AND. dft_control%do_admm
734 IF (do_admm) THEN
735 ! 'admm_env%xc_section_primary' and 'admm_env%xc_section_aux' need to be redefined
736 CALL cp_abort(__location__, &
737 "ADMM is not implemented for a TDDFT kernel XC-functional which is different from "// &
738 "the one used for the ground-state calculation. A ground-state 'admm_env' cannot be reused.")
739 END IF
740 ! SET HFX_KERNEL and/or XC_KERNEL
741 IF (exk) THEN
742 do_exck = .true.
743 ELSE
744 do_exck = .false.
745 END IF
746 IF (exhfxk) THEN
747 xc_sub => section_vals_get_subs_vals(xc_root, "HFX_KERNEL")
748 CALL section_vals_val_get(xc_sub, "DO_HFXSR", l_val=do_hfxsr)
749 xc_sub => section_vals_get_subs_vals(xc_root, "HFX_KERNEL%HFXLR")
750 CALL section_vals_get(xc_sub, explicit=do_hfxlr)
751 ELSE
752 do_hfxsr = .false.
753 do_hfxlr = .false.
754 END IF
755 ELSE
756 xc_section => section_vals_get_subs_vals(input, "DFT%XC")
757 hfx_section => section_vals_get_subs_vals(xc_section, "HF")
758 CALL section_vals_get(hfx_section, explicit=do_hfx)
759 IF (do_hfx) THEN
760 CALL section_vals_val_get(hfx_section, "FRACTION", r_val=c_hf)
761 do_hfx = (c_hf /= 0.0_dp)
762 END IF
763 do_admm = do_hfx .AND. dft_control%do_admm
764 do_exck = .false.
765 do_hfxsr = .false.
766 do_hfxlr = .false.
767 END IF
768 ELSE
769 do_hfx = .false.
770 do_admm = .false.
771 do_exck = .false.
772 do_hfxsr = .false.
773 do_hfxlr = .false.
774 END IF
775
776 ! reset rks_triplets if UKS is in use
777 IF (tddfpt_control%rks_triplets .AND. dft_control%nspins > 1) THEN
778 tddfpt_control%rks_triplets = .false.
779 CALL cp_warn(__location__, "Keyword RKS_TRIPLETS has been ignored for spin-polarised calculations")
780 END IF
781
782 ! lri input
783 IF (tddfpt_control%do_lrigpw) THEN
784 lri_section => section_vals_get_subs_vals(tddfpt_section, "LRIGPW")
785 END IF
786
787 ! set defaults for short range HFX
788 NULLIFY (hfxsr_section)
789 IF (do_hfxsr) THEN
790 hfxsr_section => section_vals_get_subs_vals(tddfpt_section, "XC%HFX_KERNEL%HF")
791 CALL section_vals_get(hfxsr_section, explicit=found)
792 IF (.NOT. found) THEN
793 cpabort("HFXSR option needs &HF section defined")
794 END IF
795 CALL section_vals_val_get(hfxsr_section, "INTERACTION_POTENTIAL%POTENTIAL_TYPE", explicit=found)
796 IF (.NOT. found) THEN
797 CALL section_vals_val_set(hfxsr_section, "INTERACTION_POTENTIAL%POTENTIAL_TYPE", &
799 END IF
800 CALL section_vals_val_get(hfxsr_section, "INTERACTION_POTENTIAL%CUTOFF_RADIUS", explicit=found)
801 IF (.NOT. found) THEN
802 CALL section_vals_val_set(hfxsr_section, "INTERACTION_POTENTIAL%CUTOFF_RADIUS", r_val=7.5589_dp)
803 END IF
804 CALL section_vals_val_get(hfxsr_section, "RI%_SECTION_PARAMETERS_", l_val=found)
805 IF (found) THEN
806 CALL cp_abort(__location__, "Short range TDA kernel with RI not possible")
807 END IF
808 END IF
809
810 END SUBROUTINE tddfpt_input
811
812! **************************************************************************************************
813!> \brief ...
814!> \param log_unit ...
815!> \param dft_control ...
816!> \param tddfpt_control ...
817!> \param xc_section ...
818! **************************************************************************************************
819 SUBROUTINE kernel_info(log_unit, dft_control, tddfpt_control, xc_section)
820 INTEGER, INTENT(IN) :: log_unit
821 TYPE(dft_control_type), POINTER :: dft_control
822 TYPE(tddfpt2_control_type), POINTER :: tddfpt_control
823 TYPE(section_vals_type), POINTER :: xc_section
824
825 CHARACTER(LEN=4) :: ktype
826 LOGICAL :: lsd
827
828 lsd = (dft_control%nspins > 1)
829 IF (tddfpt_control%kernel == tddfpt_kernel_full) THEN
830 ktype = "FULL"
831 IF (log_unit > 0) THEN
832 WRITE (log_unit, "(T2,A,T77,A4)") "KERNEL|", trim(ktype)
833 CALL xc_write(log_unit, xc_section, lsd)
834 IF (tddfpt_control%do_hfx) THEN
835 IF (tddfpt_control%do_admm) THEN
836 WRITE (log_unit, "(T2,A,T62,A19)") "KERNEL|", "ADMM Exact Exchange"
837 IF (tddfpt_control%admm_xc_correction) THEN
838 WRITE (log_unit, "(T2,A,T60,A21)") "KERNEL|", "Apply ADMM Kernel XC Correction"
839 END IF
840 IF (tddfpt_control%admm_symm) THEN
841 WRITE (log_unit, "(T2,A,T60,A21)") "KERNEL|", "Symmetric ADMM Kernel"
842 END IF
843 ELSE
844 WRITE (log_unit, "(T2,A,T67,A14)") "KERNEL|", "Exact Exchange"
845 END IF
846 END IF
847 IF (tddfpt_control%do_hfxsr) THEN
848 WRITE (log_unit, "(T2,A,T43,A38)") "KERNEL|", "Short range HFX approximation"
849 END IF
850 IF (tddfpt_control%do_hfxlr) THEN
851 WRITE (log_unit, "(T2,A,T43,A38)") "KERNEL|", "Long range HFX approximation"
852 END IF
853 IF (tddfpt_control%do_lrigpw) THEN
854 WRITE (log_unit, "(T2,A,T42,A39)") "KERNEL|", "LRI approximation of transition density"
855 END IF
856 END IF
857 ELSE IF (tddfpt_control%kernel == tddfpt_kernel_stda) THEN
858 ktype = "sTDA"
859 IF (log_unit > 0) THEN
860 WRITE (log_unit, "(T2,A,T77,A4)") "KERNEL|", trim(ktype)
861 IF (tddfpt_control%stda_control%do_ewald) THEN
862 WRITE (log_unit, "(T2,A,T78,A3)") "KERNEL| Coulomb term uses Ewald summation"
863 ELSE
864 WRITE (log_unit, "(T2,A,T78,A3)") "KERNEL| Coulomb term uses direct summation (MIC)"
865 END IF
866 IF (tddfpt_control%stda_control%do_exchange) THEN
867 WRITE (log_unit, "(T2,A,T78,A3)") "KERNEL| Exact exchange term", "YES"
868 WRITE (log_unit, "(T2,A,T71,F10.3)") "KERNEL| Short range HFX fraction:", &
869 tddfpt_control%stda_control%hfx_fraction
870 ELSE
871 WRITE (log_unit, "(T2,A,T79,A2)") "KERNEL| Exact exchange term", "NO"
872 END IF
873 WRITE (log_unit, "(T2,A,T66,E15.3)") "KERNEL| Transition density filter", &
874 tddfpt_control%stda_control%eps_td_filter
875 END IF
876 ELSE IF (tddfpt_control%kernel == tddfpt_kernel_none) THEN
877 ktype = "NONE"
878 IF (log_unit > 0) THEN
879 WRITE (log_unit, "(T2,A,T77,A4)") "KERNEL|", trim(ktype)
880 END IF
881 ELSE
882 !CPABORT("Unknown kernel")
883 END IF
884 !
885 IF (log_unit > 0) THEN
886 IF (tddfpt_control%rks_triplets) THEN
887 WRITE (log_unit, "(T2,A,T74,A7)") "KERNEL| Spin symmetry of excitations", "Triplet"
888 ELSE IF (lsd) THEN
889 ! Spin-conserving excitations where requested
890 IF (tddfpt_control%spinflip == no_sf_tddfpt) THEN
891 WRITE (log_unit, "(T2,A,T69,A12)") "KERNEL| Spin symmetry of excitations", "Unrestricted"
892 ! Spin-flip excitations with collinear exchange-correlation kernel requested
893 ELSE IF (tddfpt_control%spinflip == tddfpt_sf_col) THEN
894 WRITE (log_unit, "(T2,A,T72,A9)") "KERNEL| Spin flip", "Collinear"
895 ! Spin-flip excitations with noncollinear exchange-correlation kernel requested
896 ELSE IF (tddfpt_control%spinflip == tddfpt_sf_noncol) THEN
897 WRITE (log_unit, "(T2,A,T69,A12)") "KERNEL| Spin flip", "Noncollinear"
898 END IF
899 ELSE
900 WRITE (log_unit, "(T2,A,T74,A7)") "KERNEL| Spin symmetry of excitations", "Singlet"
901 END IF
902 WRITE (log_unit, "(T2,A,T73,I8)") "TDDFPT| Number of states calculated", tddfpt_control%nstates
903 WRITE (log_unit, "(T2,A,T73,I8)") "TDDFPT| Number of Davidson iterations", tddfpt_control%niters
904 WRITE (log_unit, "(T2,A,T66,E15.3)") "TDDFPT| Davidson iteration convergence", tddfpt_control%conv
905 WRITE (log_unit, "(T2,A,T73,I8)") "TDDFPT| Max. number of Krylov space vectors", tddfpt_control%nkvs
906 END IF
907
908 END SUBROUTINE kernel_info
909
910! **************************************************************************************************
911!> \brief The energy calculation has been moved to its own subroutine
912!> \param qs_env ...
913!> \param nstates ...
914!> \param nspins ...
915!> \param work_matrices ...
916!> \param tddfpt_control ...
917!> \param logger ...
918!> \param tddfpt_print_section ...
919!> \param evects ...
920!> \param evals ...
921!> \param gs_mos ...
922!> \param tddfpt_section ...
923!> \param S_evects ...
924!> \param matrix_s ...
925!> \param kernel_env ...
926!> \param matrix_ks ...
927!> \param sub_env ...
928!> \param ostrength ...
929!> \param dipole_op_mos_occ ...
930!> \param mult ...
931!> \param xc_section ...
932!> \param full_kernel_env ...
933!> \param kernel_env_admm_aux ...
934! **************************************************************************************************
935 SUBROUTINE tddfpt_energies(qs_env, nstates, nspins, work_matrices, &
936 tddfpt_control, logger, tddfpt_print_section, evects, evals, &
937 gs_mos, tddfpt_section, S_evects, matrix_s, kernel_env, matrix_ks, &
938 sub_env, ostrength, dipole_op_mos_occ, mult, xc_section, full_kernel_env, &
939 kernel_env_admm_aux)
940
941 TYPE(qs_environment_type), POINTER :: qs_env
942 INTEGER :: nstates, nspins
943 TYPE(tddfpt_work_matrices) :: work_matrices
944 TYPE(tddfpt2_control_type), POINTER :: tddfpt_control
945 TYPE(cp_logger_type), POINTER :: logger
946 TYPE(section_vals_type), POINTER :: tddfpt_print_section
947 TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:, :) :: evects
948 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: evals
949 TYPE(tddfpt_ground_state_mos), DIMENSION(:), &
950 POINTER :: gs_mos
951 TYPE(section_vals_type), POINTER :: tddfpt_section
952 TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:, :) :: s_evects
953 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_s
954 TYPE(kernel_env_type) :: kernel_env
955 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_ks
956 TYPE(tddfpt_subgroup_env_type) :: sub_env
957 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: ostrength
958 TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:, :) :: dipole_op_mos_occ
959 INTEGER :: mult
960 TYPE(section_vals_type), POINTER :: xc_section
961 TYPE(full_kernel_env_type), TARGET :: full_kernel_env, kernel_env_admm_aux
962
963 CHARACTER(LEN=*), PARAMETER :: routinen = 'tddfpt_energies'
964
965 CHARACTER(len=20) :: nstates_str
966 INTEGER :: energy_unit, handle, iter, log_unit, &
967 niters, nocc, nstate_max, &
968 nstates_read, nvirt
969 LOGICAL :: do_admm, do_exck, do_soc, explicit
970 REAL(kind=dp) :: conv
971 TYPE(admm_type), POINTER :: admm_env
972 TYPE(cp_blacs_env_type), POINTER :: blacs_env
973 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_ks_oep
974 TYPE(section_vals_type), POINTER :: lri_section, namd_print_section, &
975 soc_section
976
977 CALL timeset(routinen, handle)
978
979 NULLIFY (admm_env, matrix_ks_oep)
980 do_admm = tddfpt_control%do_admm
981 IF (do_admm) CALL get_qs_env(qs_env, admm_env=admm_env)
982
983 ! setup for full_kernel and admm_kernel within tddfpt_energies due to dependence on multiplicity
984 IF (tddfpt_control%kernel == tddfpt_kernel_full) THEN
985
987 rho_orb_struct=work_matrices%rho_orb_struct_sub, &
988 rho_xc_struct=work_matrices%rho_xc_struct_sub, &
989 is_rks_triplets=tddfpt_control%rks_triplets, &
990 qs_env=qs_env, sub_env=sub_env, &
991 wfm_rho_orb=work_matrices%rho_ao_orb_fm_sub)
992
993 IF (do_admm) THEN
994 ! Full kernel with ADMM
995 IF (tddfpt_control%admm_xc_correction) THEN
996 CALL create_kernel_env(kernel_env=full_kernel_env, &
997 rho_struct_sub=work_matrices%rho_orb_struct_sub, &
998 xc_section=admm_env%xc_section_primary, &
999 is_rks_triplets=tddfpt_control%rks_triplets, &
1000 sub_env=sub_env)
1001 ELSE
1002 CALL create_kernel_env(kernel_env=full_kernel_env, &
1003 rho_struct_sub=work_matrices%rho_orb_struct_sub, &
1004 xc_section=xc_section, &
1005 is_rks_triplets=tddfpt_control%rks_triplets, &
1006 sub_env=sub_env)
1007 END IF
1008
1010 rho_orb_struct=work_matrices%rho_orb_struct_sub, &
1011 rho_aux_fit_struct=work_matrices%rho_aux_fit_struct_sub, &
1012 local_rho_set=sub_env%local_rho_set_admm, &
1013 qs_env=qs_env, sub_env=sub_env, &
1014 wfm_rho_orb=work_matrices%rho_ao_orb_fm_sub, &
1015 wfm_rho_aux_fit=work_matrices%rho_ao_aux_fit_fm_sub, &
1016 wfm_aux_orb=work_matrices%wfm_aux_orb_sub)
1017
1018 CALL create_kernel_env(kernel_env=kernel_env_admm_aux, &
1019 rho_struct_sub=work_matrices%rho_aux_fit_struct_sub, &
1020 xc_section=admm_env%xc_section_aux, &
1021 is_rks_triplets=tddfpt_control%rks_triplets, &
1022 sub_env=sub_env)
1023 kernel_env%full_kernel => full_kernel_env
1024 kernel_env%admm_kernel => kernel_env_admm_aux
1025 ELSE
1026 ! Full kernel
1027 CALL create_kernel_env(kernel_env=full_kernel_env, &
1028 rho_struct_sub=work_matrices%rho_orb_struct_sub, &
1029 xc_section=xc_section, &
1030 is_rks_triplets=tddfpt_control%rks_triplets, &
1031 sub_env=sub_env)
1032 kernel_env%full_kernel => full_kernel_env
1033 NULLIFY (kernel_env%admm_kernel)
1034 END IF
1035 ! Fxc from kernel definition
1036 do_exck = tddfpt_control%do_exck
1037 kernel_env%full_kernel%do_exck = do_exck
1038 ! initilize xc kernel
1039 IF (do_exck) THEN
1040 CALL create_fxc_kernel(work_matrices%rho_orb_struct_sub, work_matrices%fxc_rspace_sub, &
1041 xc_section, tddfpt_control%rks_triplets, sub_env, qs_env)
1042 END IF
1043 END IF
1044
1045 ! lri input
1046 IF (tddfpt_control%do_lrigpw) THEN
1047 lri_section => section_vals_get_subs_vals(tddfpt_section, "LRIGPW")
1048 CALL tddfpt2_lri_init(qs_env, kernel_env, lri_section, &
1049 tddfpt_print_section)
1050 END IF
1051
1052 !! Too many states can lead to Problems
1053 !! You should be warned if there are more states
1054 !! than occ-virt Combinations!!
1055 CALL cp_fm_get_info(gs_mos(1)%mos_occ, ncol_global=nocc)
1056 IF (tddfpt_control%spinflip == no_sf_tddfpt) THEN
1057 CALL cp_fm_get_info(gs_mos(1)%mos_virt, ncol_global=nvirt)
1058 ELSE
1059 CALL cp_fm_get_info(gs_mos(2)%mos_virt, ncol_global=nvirt)
1060 END IF
1061 nstate_max = nocc*nvirt
1062 IF ((SIZE(gs_mos, 1) == 2) .AND. (tddfpt_control%spinflip == no_sf_tddfpt)) THEN
1063 CALL cp_fm_get_info(gs_mos(2)%mos_occ, ncol_global=nocc)
1064 CALL cp_fm_get_info(gs_mos(2)%mos_virt, ncol_global=nvirt)
1065 nstate_max = nocc*nvirt + nstate_max
1066 END IF
1067 IF (nstates > nstate_max) THEN
1068 cpwarn("NUMBER OF EXCITED STATES COULD LEAD TO PROBLEMS!")
1069 cpwarn("Experimental: CHANGED NSTATES TO ITS MAXIMUM VALUE!")
1070 nstates = nstate_max
1071 END IF
1072
1073 soc_section => section_vals_get_subs_vals(tddfpt_section, "SOC")
1074 CALL section_vals_get(soc_section, explicit=do_soc)
1075
1076 ! reuse Ritz vectors from the previous calculation if available
1077 IF (tddfpt_control%is_restart .AND. .NOT. do_soc) THEN
1078 CALL get_qs_env(qs_env, blacs_env=blacs_env)
1079
1080 nstates_read = tddfpt_read_restart( &
1081 evects=evects, &
1082 evals=evals, &
1083 gs_mos=gs_mos, &
1084 logger=logger, &
1085 tddfpt_section=tddfpt_section, &
1086 tddfpt_print_section=tddfpt_print_section, &
1087 fm_pool_ao_mo_active=work_matrices%fm_pool_ao_mo_active, &
1088 blacs_env_global=blacs_env)
1089 ELSE
1090 nstates_read = 0
1091 END IF
1092
1093 ! build the list of missed singly excited states and sort them in ascending order
1094 ! according to their excitation energies
1095 log_unit = cp_print_key_unit_nr(logger, tddfpt_print_section, &
1096 "GUESS_VECTORS", extension=".tddfptLog")
1097 CALL tddfpt_guess_vectors(evects=evects, evals=evals, &
1098 gs_mos=gs_mos, log_unit=log_unit, tddfpt_control=tddfpt_control, &
1099 fm_pool_ao_mo_active=work_matrices%fm_pool_ao_mo_active, &
1100 qs_env=qs_env, nspins=nspins)
1101 CALL cp_print_key_finished_output(log_unit, logger, &
1102 tddfpt_print_section, "GUESS_VECTORS")
1103
1104 CALL tddfpt_orthogonalize_psi1_psi0(evects, work_matrices%S_C0_C0T, qs_env, &
1105 gs_mos, evals, tddfpt_control, work_matrices%S_C0)
1106 CALL tddfpt_orthonormalize_psi1_psi1(evects, nstates, s_evects, matrix_s(1)%matrix)
1107
1108 niters = tddfpt_control%niters
1109 IF (niters > 0) THEN
1110 log_unit = cp_print_key_unit_nr(logger, tddfpt_print_section, &
1111 "ITERATION_INFO", extension=".tddfptLog")
1112 energy_unit = cp_print_key_unit_nr(logger, &
1113 tddfpt_print_section, &
1114 "DETAILED_ENERGY", &
1115 extension=".tddfptLog")
1116
1117 IF (log_unit > 0) THEN
1118 WRITE (log_unit, "(1X,A)") "", &
1119 "-------------------------------------------------------------------------------", &
1120 "- TDDFPT WAVEFUNCTION OPTIMIZATION -", &
1121 "-------------------------------------------------------------------------------"
1122
1123 WRITE (log_unit, '(/,T11,A,T27,A,T40,A,T62,A)') "Step", "Time", "Convergence", "Conv. states"
1124 WRITE (log_unit, '(1X,79("-"))')
1125 END IF
1126
1127 CALL cp_add_iter_level(logger%iter_info, "TDDFT_SCF")
1128
1129 DO
1130 ! *** perform Davidson iterations ***
1131 conv = tddfpt_davidson_solver( &
1132 evects=evects, &
1133 evals=evals, &
1134 s_evects=s_evects, &
1135 gs_mos=gs_mos, &
1136 tddfpt_control=tddfpt_control, &
1137 matrix_ks=matrix_ks, &
1138 qs_env=qs_env, &
1139 kernel_env=kernel_env, &
1140 sub_env=sub_env, &
1141 logger=logger, &
1142 iter_unit=log_unit, &
1143 energy_unit=energy_unit, &
1144 tddfpt_print_section=tddfpt_print_section, &
1145 work_matrices=work_matrices)
1146
1147 ! at this point at least one of the following conditions are met:
1148 ! a) convergence criteria has been achieved;
1149 ! b) maximum number of iterations has been reached;
1150 ! c) Davidson iterations must be restarted due to lack of Krylov vectors
1151
1152 CALL cp_iterate(logger%iter_info, increment=0, iter_nr_out=iter)
1153 ! terminate the loop if either (a) or (b) is true ...
1154 IF ((conv <= tddfpt_control%conv) .OR. iter >= niters) EXIT
1155
1156 ! ... otherwise restart Davidson iterations
1157 evals = 0.0_dp
1158 IF (log_unit > 0) THEN
1159 WRITE (log_unit, '(1X,25("-"),1X,A,1X,25("-"))') "Restart Davidson iterations"
1160 CALL m_flush(log_unit)
1161 END IF
1162 END DO
1163
1164 ! write TDDFPT restart file at the last iteration if requested to do so
1165 CALL cp_iterate(logger%iter_info, increment=0, last=.true.)
1166 CALL tddfpt_write_restart(evects=evects, &
1167 evals=evals, &
1168 gs_mos=gs_mos, &
1169 logger=logger, &
1170 tddfpt_print_section=tddfpt_print_section)
1171
1172 CALL cp_rm_iter_level(logger%iter_info, "TDDFT_SCF")
1173
1174 ! print convergence summary
1175 IF (log_unit > 0) THEN
1176 CALL integer_to_string(iter, nstates_str)
1177 IF (conv <= tddfpt_control%conv) THEN
1178 WRITE (log_unit, "(1X,A)") "", &
1179 "-------------------------------------------------------------------------------", &
1180 "- TDDFPT run converged in "//trim(nstates_str)//" iteration(s) ", &
1181 "-------------------------------------------------------------------------------"
1182 ELSE
1183 WRITE (log_unit, "(1X,A)") "", &
1184 "-------------------------------------------------------------------------------", &
1185 "- TDDFPT run did NOT converge after "//trim(nstates_str)//" iteration(s) ", &
1186 "-------------------------------------------------------------------------------"
1187 END IF
1188 END IF
1189
1190 CALL cp_print_key_finished_output(energy_unit, logger, &
1191 tddfpt_print_section, "DETAILED_ENERGY")
1192 CALL cp_print_key_finished_output(log_unit, logger, &
1193 tddfpt_print_section, "ITERATION_INFO")
1194 ELSE
1195 CALL cp_warn(__location__, &
1196 "Skipping TDDFPT wavefunction optimization")
1197 END IF
1198
1199 IF (ASSOCIATED(matrix_ks_oep)) THEN
1200 IF (tddfpt_control%dipole_form == tddfpt_dipole_velocity) THEN
1201 CALL cp_warn(__location__, &
1202 "Transition dipole moments and oscillator strengths are likely to be incorrect "// &
1203 "when computed using an orbital energy correction XC-potential together with "// &
1204 "the velocity form of dipole transition integrals")
1205 END IF
1206 END IF
1207
1208 ! *** print summary information ***
1209 log_unit = cp_logger_get_default_io_unit(logger)
1210
1211 namd_print_section => section_vals_get_subs_vals( &
1212 tddfpt_print_section, &
1213 "NAMD_PRINT")
1214 CALL section_vals_get(namd_print_section, explicit=explicit)
1215 IF (explicit) THEN
1216 CALL tddfpt_write_newtonx_output(evects, &
1217 evals, &
1218 gs_mos, &
1219 logger, &
1220 tddfpt_print_section, &
1221 matrix_s(1)%matrix, &
1222 s_evects, &
1223 sub_env)
1224 END IF
1225 ALLOCATE (ostrength(nstates))
1226 ostrength = 0.0_dp
1227 CALL tddfpt_print_summary(log_unit, &
1228 evects, &
1229 evals, &
1230 gs_mos, &
1231 ostrength, &
1232 mult, &
1233 dipole_op_mos_occ, &
1234 tddfpt_control%dipole_form)
1236 log_unit, &
1237 evects, &
1238 evals, &
1239 gs_mos, &
1240 matrix_s(1)%matrix, &
1241 tddfpt_control%spinflip, &
1242 min_amplitude=tddfpt_control%min_excitation_amplitude)
1243 CALL tddfpt_print_nto_analysis(qs_env, &
1244 evects, evals, &
1245 ostrength, &
1246 gs_mos, &
1247 matrix_s(1)%matrix, &
1248 tddfpt_print_section)
1249 IF (tddfpt_control%do_exciton_descriptors) THEN
1251 log_unit, &
1252 evects, &
1253 gs_mos, &
1254 matrix_s(1)%matrix, &
1255 tddfpt_control%do_directional_exciton_descriptors, &
1256 qs_env)
1257 END IF
1258
1259 IF (tddfpt_control%do_lrigpw) THEN
1260 CALL lri_print_stat(qs_env, &
1261 ltddfpt=.true., &
1262 tddfpt_lri_env=kernel_env%full_kernel%lri_env)
1263 END IF
1264
1265 CALL timestop(handle)
1266 END SUBROUTINE tddfpt_energies
1267
1268! **************************************************************************************************
1269!> \brief Perform singlet and triplet computations for subsequent TDDFPT-SOC calculation.
1270!> \param qs_env Quickstep environment
1271!> \param nstates number of requested exited states
1272!> \param work_matrices ...
1273!> \param tddfpt_control ...
1274!> \param logger ...
1275!> \param tddfpt_print_section ...
1276!> \param evects Eigenvector of the requested multiplicity
1277!> \param evals Eigenvalue of the requested multiplicity
1278!> \param ostrength Oscillatorstrength
1279!> \param gs_mos ...
1280!> \param tddfpt_section ...
1281!> \param S_evects ...
1282!> \param matrix_s ...
1283!> \param kernel_env ...
1284!> \param matrix_ks ...
1285!> \param sub_env ...
1286!> \param dipole_op_mos_occ ...
1287!> \param lmult_tmp ...
1288!> \param xc_section ...
1289!> \param full_kernel_env ...
1290!> \param kernel_env_admm_aux ...
1291!> \par History
1292!> * 02.2023 created [Jan-Robert Vogt]
1293!> \note Based on tddfpt2_methods and xas_tdp_utils.
1294!> \note only the values of one multiplicity will be passed back for force calculations!
1295! **************************************************************************************************
1296
1297 SUBROUTINE tddfpt_soc_energies(qs_env, nstates, work_matrices, &
1298 tddfpt_control, logger, tddfpt_print_section, &
1299 evects, evals, ostrength, &
1300 gs_mos, tddfpt_section, S_evects, matrix_s, kernel_env, matrix_ks, &
1301 sub_env, dipole_op_mos_occ, lmult_tmp, xc_section, full_kernel_env, &
1302 kernel_env_admm_aux)
1303
1304 TYPE(qs_environment_type), INTENT(IN), POINTER :: qs_env
1305 INTEGER, INTENT(in) :: nstates
1306 TYPE(tddfpt_work_matrices) :: work_matrices
1307 TYPE(tddfpt2_control_type), POINTER :: tddfpt_control
1308 TYPE(cp_logger_type), POINTER :: logger
1309 TYPE(section_vals_type), POINTER :: tddfpt_print_section
1310 TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:, :) :: evects
1311 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: evals, ostrength
1312 TYPE(tddfpt_ground_state_mos), DIMENSION(:), &
1313 POINTER :: gs_mos
1314 TYPE(section_vals_type), POINTER :: tddfpt_section
1315 TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:, :) :: s_evects
1316 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_s
1317 TYPE(kernel_env_type) :: kernel_env
1318 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_ks
1319 TYPE(tddfpt_subgroup_env_type) :: sub_env
1320 TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:, :) :: dipole_op_mos_occ
1321 LOGICAL, INTENT(in) :: lmult_tmp
1322 TYPE(section_vals_type), POINTER :: xc_section
1323 TYPE(full_kernel_env_type), TARGET :: full_kernel_env, kernel_env_admm_aux
1324
1325 CHARACTER(LEN=*), PARAMETER :: routinen = 'tddfpt_soc_energies'
1326
1327 INTEGER :: handle, ispin, istate, log_unit, mult, &
1328 nspins
1329 LOGICAL :: do_sf
1330 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: evals_mult, ostrength_mult
1331 TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:, :) :: evects_mult
1332
1333 CALL timeset(routinen, handle)
1334
1335 log_unit = cp_print_key_unit_nr(logger, tddfpt_print_section, &
1336 "PROGRAM_BANNER", &
1337 extension=".tddfptLog")
1338 CALL tddfpt_soc_header(log_unit)
1339
1340 nspins = SIZE(gs_mos)
1341 ALLOCATE (evects_mult(nspins, nstates))
1342 ALLOCATE (evals_mult(nstates))
1343 do_sf = tddfpt_control%spinflip /= no_sf_tddfpt
1344
1345 ! First multiplicity
1346 IF (lmult_tmp) THEN
1347 IF (log_unit > 0) THEN
1348 WRITE (log_unit, "(1X,A)") "", &
1349 "-------------------------------------------------------------------------------", &
1350 "- TDDFPT SINGLET ENERGIES -", &
1351 "-------------------------------------------------------------------------------"
1352 END IF
1353 mult = 1
1354 ELSE
1355 IF (log_unit > 0) THEN
1356 WRITE (log_unit, "(1X,A)") "", &
1357 "-------------------------------------------------------------------------------", &
1358 "- TDDFPT TRIPLET ENERGIES -", &
1359 "-------------------------------------------------------------------------------"
1360 END IF
1361 mult = 3
1362 END IF
1363
1364 CALL tddfpt_energies(qs_env, nstates, nspins, work_matrices, tddfpt_control, logger, &
1365 tddfpt_print_section, evects_mult, evals_mult, &
1366 gs_mos, tddfpt_section, s_evects, matrix_s, &
1367 kernel_env, matrix_ks, sub_env, ostrength_mult, &
1368 dipole_op_mos_occ, mult, xc_section, full_kernel_env, &
1369 kernel_env_admm_aux)
1370
1371 ! Clean up in between for full kernel
1372 IF (tddfpt_control%kernel == tddfpt_kernel_full) THEN
1373 IF (tddfpt_control%do_admm) CALL release_kernel_env(kernel_env%admm_kernel)
1374 CALL release_kernel_env(kernel_env%full_kernel)
1375 CALL tddfpt_release_work_matrices(work_matrices, sub_env)
1376 CALL tddfpt_create_work_matrices(work_matrices, gs_mos, nstates, &
1377 tddfpt_control%do_hfx, &
1378 tddfpt_control%do_admm, tddfpt_control%do_hfxlr, &
1379 tddfpt_control%do_exck, do_sf, qs_env, sub_env)
1380 END IF
1381
1382 DO istate = 1, nstates
1383 DO ispin = 1, nspins
1384 CALL cp_fm_release(s_evects(ispin, istate))
1385 END DO
1386 END DO
1387
1388 DO istate = 1, nstates
1389 DO ispin = 1, nspins
1390 CALL fm_pool_create_fm( &
1391 work_matrices%fm_pool_ao_mo_active(ispin)%pool, &
1392 s_evects(ispin, istate))
1393 END DO
1394 END DO
1395
1396 tddfpt_control%rks_triplets = lmult_tmp
1397
1398 ! Second multiplicity
1399 IF (lmult_tmp) THEN
1400 IF (log_unit > 0) THEN
1401 WRITE (log_unit, "(1X,A)") "", &
1402 " singlet excitations finished ", &
1403 " ", &
1404 "-------------------------------------------------------------------------------", &
1405 "- TDDFPT TRIPLET ENERGIES -", &
1406 "-------------------------------------------------------------------------------"
1407 END IF !log_unit
1408 mult = 3
1409 ELSE
1410 IF (log_unit > 0) THEN
1411 WRITE (log_unit, "(1X,A)") "", &
1412 " triplet excitations finished ", &
1413 " ", &
1414 "-------------------------------------------------------------------------------", &
1415 "- TDDFPT SINGLET ENERGIES -", &
1416 "-------------------------------------------------------------------------------"
1417 END IF !log_unit
1418 mult = 1
1419 END IF
1420
1421 CALL tddfpt_energies(qs_env, nstates, nspins, work_matrices, tddfpt_control, logger, &
1422 tddfpt_print_section, evects, evals, &
1423 gs_mos, tddfpt_section, s_evects, matrix_s, &
1424 kernel_env, matrix_ks, sub_env, ostrength, &
1425 dipole_op_mos_occ, mult, xc_section, full_kernel_env, &
1426 kernel_env_admm_aux)
1427
1428 ! Compute perturbative SOC correction
1429 ! Order should always be singlet triplet in tddfpt_soc
1430 IF (lmult_tmp) THEN
1431 CALL tddfpt_soc(qs_env, evals_mult, evals, evects_mult, evects, gs_mos) !mult=singlet
1432 ELSE
1433 CALL tddfpt_soc(qs_env, evals, evals_mult, evects, evects_mult, gs_mos) !mult=triplet
1434 END IF
1435
1436 ! deallocate the additional multiplicity
1437 DO ispin = 1, SIZE(evects_mult, 1)
1438 DO istate = 1, SIZE(evects_mult, 2)
1439 CALL cp_fm_release(evects_mult(ispin, istate))
1440 END DO
1441 END DO
1442 DEALLOCATE (evects_mult, evals_mult, ostrength_mult)
1443
1444 CALL timestop(handle)
1445
1446 END SUBROUTINE tddfpt_soc_energies
1447
1448! **************************************************************************************************
1449!> \brief ...
1450!> \param qs_env ...
1451!> \param gs_mos ...
1452!> \param tddfpt_control ...
1453!> \param tddfpt_section ...
1454!> \param iounit ...
1455! **************************************************************************************************
1456 SUBROUTINE init_res_method(qs_env, gs_mos, tddfpt_control, tddfpt_section, iounit)
1457
1458 TYPE(qs_environment_type), POINTER :: qs_env
1459 TYPE(tddfpt_ground_state_mos), DIMENSION(:), &
1460 POINTER :: gs_mos
1461 TYPE(tddfpt2_control_type), POINTER :: tddfpt_control
1462 TYPE(section_vals_type), POINTER :: tddfpt_section
1463 INTEGER, INTENT(IN) :: iounit
1464
1465 CHARACTER(LEN=*), PARAMETER :: routinen = 'init_res_method'
1466
1467 INTEGER :: handle, i, io, ispin, nao, nmo, nmol, &
1468 nspins
1469 INTEGER, ALLOCATABLE, DIMENSION(:, :) :: orblist
1470 INTEGER, DIMENSION(:), POINTER :: mollist
1471 LOGICAL :: do_res, do_sf, ew1, ew2, ew3, ewcut, lms
1472 REAL(kind=dp) :: eclow, ecup, eint, emo
1473 REAL(kind=dp), DIMENSION(:), POINTER :: rvint
1474 TYPE(cp_blacs_env_type), POINTER :: blacs_env
1475 TYPE(cp_fm_struct_type), POINTER :: fm_struct
1476 TYPE(section_vals_type), POINTER :: res_section
1477
1478 CALL timeset(routinen, handle)
1479
1480 res_section => section_vals_get_subs_vals(tddfpt_section, "REDUCED_EXCITATION_SPACE")
1481 CALL section_vals_val_get(res_section, "_SECTION_PARAMETERS_", l_val=do_res)
1482
1483 ! spin flip TDA
1484 IF (tddfpt_control%spinflip == no_sf_tddfpt) THEN
1485 do_sf = .false.
1486 ELSE
1487 do_sf = .true.
1488 END IF
1489
1490 nspins = SIZE(gs_mos)
1491 IF (.NOT. do_res) THEN
1492 DO ispin = 1, nspins
1493 nmo = gs_mos(ispin)%nmo_occ
1494 tddfpt_control%nactive(ispin) = nmo
1495 gs_mos(ispin)%nmo_active = nmo
1496 ALLOCATE (gs_mos(ispin)%index_active(nmo))
1497 DO i = 1, nmo
1498 gs_mos(ispin)%index_active(i) = i
1499 END DO
1500 END DO
1501 ELSE
1502 IF (iounit > 0) THEN
1503 WRITE (iounit, "(/,1X,27('='),A,26('='))") ' REDUCED EXCITATION SPACE '
1504 END IF
1505 CALL section_vals_val_get(res_section, "ENERGY_WINDOW", explicit=ew1)
1506 CALL section_vals_val_get(res_section, "UPPER_ENERGY_CUTOFF", explicit=ew2)
1507 CALL section_vals_val_get(res_section, "LOWER_ENERGY_CUTOFF", explicit=ew3)
1508 ewcut = (ew1 .OR. ew2 .OR. ew3)
1509 CALL section_vals_val_get(res_section, "MOLECULE_LIST", explicit=lms)
1510
1511 CALL section_vals_val_get(res_section, "ENERGY_WINDOW", r_vals=rvint)
1512 cpassert(SIZE(rvint) == 2)
1513 eclow = rvint(1)
1514 ecup = rvint(2)
1515 CALL section_vals_val_get(res_section, "UPPER_ENERGY_CUTOFF", r_val=eint)
1516 ecup = min(ecup, eint)
1517 CALL section_vals_val_get(res_section, "LOWER_ENERGY_CUTOFF", r_val=eint)
1518 eclow = max(eclow, eint)
1519 IF (ewcut .AND. (iounit > 0)) THEN
1520 IF (eclow < -1.e8_dp .AND. ecup > 1.e8_dp) THEN
1521 WRITE (iounit, "(1X,A,T51,A10,T71,A10)") &
1522 'Orbital Energy Window [eV]', " -Inf", " Inf"
1523 ELSE IF (eclow < -1.e8_dp) THEN
1524 WRITE (iounit, "(1X,A,T51,A10,T71,F10.4)") &
1525 'Orbital Energy Window [eV]', " -Inf", evolt*ecup
1526 ELSE IF (ecup > 1.e8_dp) THEN
1527 WRITE (iounit, "(1X,A,T51,F10.4,T71,A10)") &
1528 'Orbital Energy Window [eV]', evolt*eclow, " Inf"
1529 ELSE
1530 WRITE (iounit, "(1X,A,T51,F10.4,T71,F10.4)") &
1531 'Orbital Energy Window [eV]', evolt*eclow, evolt*ecup
1532 END IF
1533 END IF
1534
1535 nmol = 0
1536 IF (lms) THEN
1537 CALL section_vals_val_get(res_section, "MOLECULE_LIST", i_vals=mollist)
1538 nmol = SIZE(mollist)
1539 WRITE (iounit, "(1X,A)") 'List of Selected Molecules'
1540 WRITE (iounit, "(1X,15(I5))") mollist(1:nmol)
1541 END IF
1542
1543 DO ispin = 1, nspins
1544 tddfpt_control%nactive(ispin) = gs_mos(ispin)%nmo_occ
1545 END DO
1546 nmo = maxval(tddfpt_control%nactive)
1547 ALLOCATE (orblist(nmo, nspins))
1548 orblist = 0
1549
1550 IF (lms) THEN
1551 ! ignore for now
1552 orblist = 1
1553 DO ispin = 1, nspins
1554 cpassert(.NOT. ASSOCIATED(gs_mos(ispin)%evals_occ_matrix))
1555 END DO
1556 ELSEIF (ewcut) THEN
1557 ! Filter orbitals wrt energy window
1558 DO ispin = 1, nspins
1559 DO i = 1, gs_mos(ispin)%nmo_occ
1560 emo = gs_mos(ispin)%evals_occ(i)
1561 IF (emo > eclow .AND. emo < ecup) orblist(i, ispin) = 1
1562 END DO
1563 END DO
1564 ELSE
1565 orblist = 1
1566 END IF
1567
1568 ! count active orbitals
1569 nmo = sum(orblist)
1570 IF (nmo == 0) THEN
1571 cpabort("RSE TDA: no active orbitals selected.")
1572 END IF
1573 DO ispin = 1, nspins
1574 nmo = sum(orblist(:, ispin))
1575 tddfpt_control%nactive(ispin) = nmo
1576 gs_mos(ispin)%nmo_active = nmo
1577 ALLOCATE (gs_mos(ispin)%index_active(nmo))
1578 io = 0
1579 DO i = 1, SIZE(orblist, 1)
1580 IF (orblist(i, ispin) == 1) THEN
1581 io = io + 1
1582 gs_mos(ispin)%index_active(io) = i
1583 END IF
1584 END DO
1585 END DO
1586 DEALLOCATE (orblist)
1587
1588 IF (lms) THEN
1589 ! output information
1590 ELSE
1591 IF (iounit > 0) THEN
1592 WRITE (iounit, "(1X,A)") 'List of Selected States'
1593 IF (nspins == 1) THEN
1594 WRITE (iounit, "(A,T67,A)") ' Active State Orbital', 'Orbital Energy'
1595 DO i = 1, gs_mos(1)%nmo_active
1596 io = gs_mos(1)%index_active(i)
1597 WRITE (iounit, "(T8,I6,T21,I6,T61,F20.4)") i, io, gs_mos(1)%evals_occ(io)*evolt
1598 END DO
1599 ELSE
1600 DO ispin = 1, nspins
1601 WRITE (iounit, "(1X,A,I2)") 'Spin ', ispin
1602 WRITE (iounit, "(A,T67,A)") ' Active State Orbital', 'Orbital Energy'
1603 DO i = 1, gs_mos(ispin)%nmo_active
1604 io = gs_mos(ispin)%index_active(i)
1605 WRITE (iounit, "(T8,I6,T21,I6,T61,F20.4)") i, io, gs_mos(ispin)%evals_occ(io)*evolt
1606 END DO
1607 END DO
1608 END IF
1609 END IF
1610 END IF
1611
1612 IF (do_sf) THEN
1613 cpabort("Restricted Active Space with spin flip TDA NYA")
1614 END IF
1615
1616 IF (iounit > 0) THEN
1617 WRITE (iounit, "(1X,79('='))")
1618 END IF
1619 END IF
1620
1621 ! Allocate mos_active
1622 DO ispin = 1, nspins
1623 CALL get_qs_env(qs_env, blacs_env=blacs_env)
1624 CALL cp_fm_get_info(gs_mos(ispin)%mos_occ, nrow_global=nao)
1625 nmo = gs_mos(ispin)%nmo_active
1626 CALL cp_fm_struct_create(fm_struct, template_fmstruct=gs_mos(ispin)%mos_occ%matrix_struct, &
1627 ncol_global=nmo, context=blacs_env)
1628 NULLIFY (gs_mos(ispin)%mos_active)
1629 ALLOCATE (gs_mos(ispin)%mos_active)
1630 CALL cp_fm_create(gs_mos(ispin)%mos_active, fm_struct)
1631 CALL cp_fm_struct_release(fm_struct)
1632 ! copy the active orbitals
1633 IF (gs_mos(ispin)%nmo_active == gs_mos(ispin)%nmo_occ) THEN
1634 DO i = 1, gs_mos(ispin)%nmo_active
1635 cpassert(i == gs_mos(ispin)%index_active(i))
1636 END DO
1637 CALL cp_fm_to_fm_submat(gs_mos(ispin)%mos_occ, gs_mos(ispin)%mos_active, &
1638 nao, nmo, 1, 1, 1, 1)
1639 ELSE
1640 DO i = 1, gs_mos(ispin)%nmo_active
1641 io = gs_mos(ispin)%index_active(i)
1642 CALL cp_fm_to_fm_submat(gs_mos(ispin)%mos_occ, gs_mos(ispin)%mos_active, &
1643 nao, 1, 1, io, 1, i)
1644 END DO
1645 END IF
1646 END DO
1647
1648 CALL timestop(handle)
1649
1650 END SUBROUTINE init_res_method
1651
1652END MODULE qs_tddfpt2_methods
Contains ADMM methods which require molecular orbitals.
subroutine, public admm_fit_mo_coeffs(admm_env, matrix_s_aux_fit, matrix_s_mixed, mos, mos_aux_fit, geometry_did_change)
...
Types and set/get functions for auxiliary density matrix methods.
Definition admm_types.F:15
subroutine, public get_admm_env(admm_env, mo_derivs_aux_fit, mos_aux_fit, sab_aux_fit, sab_aux_fit_asymm, sab_aux_fit_vs_orb, matrix_s_aux_fit, matrix_s_aux_fit_kp, matrix_s_aux_fit_vs_orb, matrix_s_aux_fit_vs_orb_kp, task_list_aux_fit, matrix_ks_aux_fit, matrix_ks_aux_fit_kp, matrix_ks_aux_fit_im, matrix_ks_aux_fit_dft, matrix_ks_aux_fit_hfx, matrix_ks_aux_fit_dft_kp, matrix_ks_aux_fit_hfx_kp, rho_aux_fit, rho_aux_fit_buffer, admm_dm)
Get routine for the ADMM env.
Definition admm_types.F:593
Define the atomic kind types and their sub types.
collects all references to literature in CP2K as new algorithms / method are included from literature...
integer, save, public grimme2016
integer, save, public iannuzzi2005
integer, save, public hernandez2025
integer, save, public grimme2013
Handles all functions related to the CELL.
Definition cell_types.F:15
methods related to the blacs parallel environment
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
DBCSR operations in CP2K.
pool for for elements that are retained and released
subroutine, public fm_pool_create_fm(pool, element, name)
returns an element, allocating it if none is in the pool
represent the structure of a full matrix
subroutine, public cp_fm_struct_create(fmstruct, para_env, context, nrow_global, ncol_global, nrow_block, ncol_block, descriptor, first_p_pos, local_leading_dimension, template_fmstruct, square_blocks, force_block)
allocates and initializes a full matrix structure
subroutine, public cp_fm_struct_release(fmstruct)
releases a full matrix structure
represent a full matrix distributed on many processors
Definition cp_fm_types.F:15
subroutine, public cp_fm_get_info(matrix, name, nrow_global, ncol_global, nrow_block, ncol_block, nrow_local, ncol_local, row_indices, col_indices, local_data, context, nrow_locals, ncol_locals, matrix_struct, para_env)
returns all kind of information about the full matrix
subroutine, public cp_fm_create(matrix, matrix_struct, name, use_sp, nrow, ncol, set_zero)
creates a new full matrix with the given structure
subroutine, public cp_fm_to_fm_submat(msource, mtarget, nrow, ncol, s_firstrow, s_firstcol, t_firstrow, t_firstcol)
copy just a part ot the matrix
various routines to log and control the output. The idea is that decisions about where to log should ...
integer function, public cp_logger_get_default_io_unit(logger)
returns the unit nr for the ionode (-1 on all other processors) skips as well checks if the procs cal...
type(cp_logger_type) function, pointer, public cp_get_default_logger()
returns the default logger
routines to handle the output, The idea is to remove the decision of wheter to output and what to out...
integer function, public cp_print_key_unit_nr(logger, basis_section, print_key_path, extension, middle_name, local, log_filename, ignore_should_output, file_form, file_position, file_action, file_status, do_backup, on_file, is_new_file, mpi_io, fout)
...
subroutine, public cp_print_key_finished_output(unit_nr, logger, basis_section, print_key_path, local, ignore_should_output, on_file, mpi_io)
should be called after you finish working with a unit obtained with cp_print_key_unit_nr,...
subroutine, public cp_iterate(iteration_info, last, iter_nr, increment, iter_nr_out)
adds one to the actual iteration
subroutine, public cp_rm_iter_level(iteration_info, level_name, n_rlevel_att)
Removes an iteration level.
subroutine, public cp_add_iter_level(iteration_info, level_name, n_rlevel_new)
Adds an iteration level.
Types for excited states potential energies.
subroutine, public tddfpt_header(iw)
...
Definition header.F:122
subroutine, public tddfpt_soc_header(iw)
...
Definition header.F:143
Utilities for hfx and admm methods.
subroutine, public aux_admm_init(qs_env, mos, admm_env, admm_control, basis_type)
Minimal setup routine for admm_env No forces No k-points No DFT correction terms.
Types and set/get functions for HFX.
Definition hfx_types.F:15
subroutine, public hfx_create(x_data, para_env, hfx_section, atomic_kind_set, qs_kind_set, particle_set, dft_control, cell, orb_basis, ri_basis, nelectron_total, nkp_grid)
This routine allocates and initializes all types in hfx_data
Definition hfx_types.F:596
subroutine, public compare_hfx_sections(hfx_section1, hfx_section2, is_identical, same_except_frac)
Compares the non-technical parts of two HFX input section and check whether they are the same Ignore ...
Definition hfx_types.F:2963
collects all constants needed in input so that they can be used without circular dependencies
integer, parameter, public do_admm_purify_none
integer, parameter, public tddfpt_sf_col
integer, parameter, public tddfpt_kernel_none
integer, parameter, public do_admm_basis_projection
integer, parameter, public do_admm_aux_exch_func_none
integer, parameter, public tddfpt_dipole_velocity
integer, parameter, public do_potential_truncated
integer, parameter, public tddfpt_kernel_full
integer, parameter, public tddfpt_sf_noncol
integer, parameter, public tddfpt_kernel_stda
integer, parameter, public no_sf_tddfpt
integer, parameter, public do_admm_exch_scaling_none
objects that represent the structure of input sections and the data contained in an input section
subroutine, public section_vals_val_set(section_vals, keyword_name, i_rep_section, i_rep_val, val, l_val, i_val, r_val, c_val, l_vals_ptr, i_vals_ptr, r_vals_ptr, c_vals_ptr)
sets the requested value
recursive type(section_vals_type) function, pointer, public section_vals_get_subs_vals(section_vals, subsection_name, i_rep_section, can_return_null)
returns the values of the requested subsection
subroutine, public section_vals_get(section_vals, ref_count, n_repetition, n_subs_vals_rep, section, explicit)
returns various attributes about the section_vals
subroutine, public section_vals_val_get(section_vals, keyword_name, i_rep_section, i_rep_val, n_rep_val, val, l_val, i_val, r_val, c_val, l_vals, i_vals, r_vals, c_vals, explicit)
returns the requested value
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
Calculates integral matrices for LRIGPW method lri : local resolution of the identity.
subroutine, public lri_print_stat(qs_env, ltddfpt, tddfpt_lri_env)
...
contains the types and subroutines for dealing with the lri_env lri : local resolution of the identit...
subroutine, public lri_density_release(lri_density)
releases the given lri_density
subroutine, public lri_env_release(lri_env)
releases the given lri_env
Machine interface based on Fortran 2003 and POSIX.
Definition machine.F:17
subroutine, public m_flush(lunit)
flushes units if the &GLOBAL flag is set accordingly
Definition machine.F:136
Interface to the message passing library MPI.
generate or use from input minimal basis set
subroutine, public create_minbas_set(qs_env, unit_nr, basis_type, primitive)
...
Define the data structure for the particle information.
Definition of physical constants:
Definition physcon.F:68
real(kind=dp), parameter, public evolt
Definition physcon.F:183
subroutine, public get_qs_env(qs_env, atomic_kind_set, qs_kind_set, cell, super_cell, cell_ref, use_ref_cell, kpoints, dft_control, mos, sab_orb, sab_all, qmmm, qmmm_periodic, mimic, sac_ae, sac_ppl, sac_lri, sap_ppnl, sab_vdw, sab_scp, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, sab_xb, sab_xtb_pp, sab_xtb_nonbond, sab_almo, sab_kp, sab_kp_nosym, sab_cneo, particle_set, energy, force, matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, run_rtp, rtp, matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_ks_im_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, matrix_s_ri_aux_kp, matrix_s, matrix_s_ri_aux, matrix_w, matrix_p_mp2, matrix_p_mp2_admm, rho, rho_xc, pw_env, ewald_env, ewald_pw, active_space, mpools, input, para_env, blacs_env, scf_control, rel_control, kinetic, qs_charges, vppl, xcint_weights, rho_core, rho_nlcc, rho_nlcc_g, ks_env, ks_qmmm_env, wf_history, scf_env, local_particles, local_molecules, distribution_2d, dbcsr_dist, molecule_kind_set, molecule_set, subsys, cp_subsys, oce, local_rho_set, rho_atom_set, task_list, task_list_soft, rho0_atom_set, rho0_mpole, rhoz_set, rhoz_cneo_set, ecoul_1c, rho0_s_rs, rho0_s_gs, rhoz_cneo_s_rs, rhoz_cneo_s_gs, do_kpoints, has_unit_metric, requires_mo_derivs, mo_derivs, mo_loc_history, nkind, natom, nelectron_total, nelectron_spin, efield, neighbor_list_id, linres_control, xas_env, virial, cp_ddapc_env, cp_ddapc_ewald, outer_scf_history, outer_scf_ihistory, x_data, et_coupling, dftb_potential, results, se_taper, se_store_int_env, se_nddo_mpole, se_nonbond_env, admm_env, lri_env, lri_density, exstate_env, ec_env, harris_env, dispersion_env, gcp_env, vee, rho_external, external_vxc, mask, mp2_env, bs_env, kg_env, wanniercentres, atprop, ls_scf_env, do_transport, transport_env, v_hartree_rspace, s_mstruct_changed, rho_changed, potential_changed, forces_up_to_date, mscfg_env, almo_scf_env, gradient_history, variable_history, embed_pot, spin_embed_pot, polar_env, mos_last_converged, eeq, rhs, do_rixs, tb_tblite)
Get the QUICKSTEP environment.
subroutine, public create_fxc_kernel(rho_struct, fxc_rspace, xc_section, is_rks_triplets, sub_env, qs_env)
Create the xc kernel potential for the approximate Fxc kernel model.
subroutine, public create_kernel_env(kernel_env, xc_section, is_rks_triplets, rho_struct_sub, lsd_singlets, do_excitations, sub_env, qs_env)
Create kernel environment.
subroutine, public release_kernel_env(kernel_env)
Release kernel environment.
Define the quickstep kind type and their sub types.
Definition and initialisation of the mo data type.
Definition qs_mo_types.F:22
groups fairly general SCF methods, so that modules other than qs_scf can use them too split off from ...
subroutine, public eigensolver(matrix_ks_fm, mo_set, ortho, work, cholesky_method, do_level_shift, level_shift, matrix_u_fm, use_jacobi)
Diagonalise the Kohn-Sham matrix to get a new set of MO eigen- vectors and MO eigenvalues....
module that contains the definitions of the scf types
subroutine, public assign_state(qs_env, matrix_s, evects, psi0, wfn_history, my_state)
...
subroutine, public tddfpt_construct_aux_fit_density(rho_orb_struct, rho_aux_fit_struct, local_rho_set, qs_env, sub_env, wfm_rho_orb, wfm_rho_aux_fit, wfm_aux_orb)
Project a charge density expressed in primary basis set into the auxiliary basis set.
subroutine, public tddfpt_construct_ground_state_orb_density(rho_orb_struct, rho_xc_struct, is_rks_triplets, qs_env, sub_env, wfm_rho_orb)
Compute the ground-state charge density expressed in primary basis set.
subroutine, public tddfpt_orthonormalize_psi1_psi1(evects, nvects_new, s_evects, matrix_s)
Make new TDDFPT trial vectors orthonormal to all previous trial vectors.
subroutine, public tddfpt_orthogonalize_psi1_psi0(evects, s_c0_c0t, qs_env, gs_mos, evals, tddfpt_control, s_c0)
Make TDDFPT trial vectors orthogonal to all occupied molecular orbitals.
real(kind=dp) function, public tddfpt_davidson_solver(evects, evals, s_evects, gs_mos, tddfpt_control, matrix_ks, qs_env, kernel_env, sub_env, logger, iter_unit, energy_unit, tddfpt_print_section, work_matrices)
Perform Davidson iterations.
subroutine, public tddfpt_forces_main(qs_env, gs_mos, ex_env, kernel_env, sub_env, work_matrices)
Perform TDDFPT gradient calculation. This routine calculates the response vector R of Eq....
subroutine, public tddfpt_print_forces(qs_env, evects, evals, ostrength, print_section, gs_mos, kernel_env, sub_env, work_matrices)
Calculate and print forces of selected excited states.
subroutine, public tddfpt2_lri_init(qs_env, kernel_env, lri_section, tddfpt_print_section)
Initialize LRI environment, basis, neighborlists and matrices.
subroutine, public tddfpt(qs_env, calc_forces, rixs_env)
Perform TDDFPT calculation. If calc_forces then it also builds the response vector for the Z-vector m...
subroutine, public tddfpt_input(qs_env, tddfpt_section, tddfpt_control, do_hfx, do_admm, do_exck, do_hfxsr, do_hfxlr, xc_section, tddfpt_print_section, lri_section, hfxsr_section)
TDDFPT input.
subroutine, public tddfpt_energies(qs_env, nstates, nspins, work_matrices, tddfpt_control, logger, tddfpt_print_section, evects, evals, gs_mos, tddfpt_section, s_evects, matrix_s, kernel_env, matrix_ks, sub_env, ostrength, dipole_op_mos_occ, mult, xc_section, full_kernel_env, kernel_env_admm_aux)
The energy calculation has been moved to its own subroutine.
subroutine, public tddfpt_dipole_operator(dipole_op_mos_occ, tddfpt_control, gs_mos, qs_env)
Compute the action of the dipole operator on the ground state wave function.
subroutine, public tddfpt_print_nto_analysis(qs_env, evects, evals, ostrength, gs_mos, matrix_s, print_section)
Print natural transition orbital analysis.
subroutine, public tddfpt_print_excitation_analysis(log_unit, evects, evals, gs_mos, matrix_s, spinflip, min_amplitude)
Print excitation analysis.
subroutine, public tddfpt_print_exciton_descriptors(log_unit, evects, gs_mos, matrix_s, do_directional_exciton_descriptors, qs_env)
Print exciton descriptors, cf. Mewes et al., JCTC 14, 710-725 (2018)
subroutine, public tddfpt_print_summary(log_unit, evects, evals, gs_mos, ostrength, mult, dipole_op_mos_occ, dipole_form)
Print final TDDFPT excitation energies and oscillator strengths.
subroutine, public tddfpt_write_newtonx_output(evects, evals, gs_mos, logger, tddfpt_print_section, matrix_s, s_evects, sub_env)
Write Ritz vectors to a binary restart file.
subroutine, public tddfpt_write_restart(evects, evals, gs_mos, logger, tddfpt_print_section)
Write Ritz vectors to a binary restart file.
integer function, public tddfpt_read_restart(evects, evals, gs_mos, logger, tddfpt_section, tddfpt_print_section, fm_pool_ao_mo_active, blacs_env_global)
Initialise initial guess vectors by reading (un-normalised) Ritz vectors from a binary restart file.
subroutine, public tddfpt_smeared_occupation(qs_env, gs_mos, log_unit)
...
subroutine, public tddfpt_soc(qs_env, evals_a, evals_b, evects_a, evects_b, gs_mos)
Perform TDDFPT-SOC calculation.
Simplified Tamm Dancoff approach (sTDA).
subroutine, public stda_init_param(qs_env, stda_kernel, stda_control)
Get the parameters needed for an sTDA calculation.
subroutine, public deallocate_stda_env(stda_kernel)
Deallocate the sTDA environment.
subroutine, public allocate_stda_env(qs_env, stda_kernel, n_ao, nactive)
Allocate the sTDA environment.
Simplified Tamm Dancoff approach (sTDA).
subroutine, public get_lowdin_mo_coefficients(qs_env, sub_env, work)
Calculate Lowdin MO coefficients.
subroutine, public stda_init_matrices(qs_env, stda_kernel, sub_env, work, tddfpt_control)
Calculate sTDA matrices.
subroutine, public tddfpt_sub_env_init(sub_env, qs_env, mos_occ, mos_active, kernel)
Split MPI communicator to create a set of parallel (sub)groups.
subroutine, public tddfpt_sub_env_release(sub_env)
Release parallel group environment.
subroutine, public hfxsr_create_work_matrices(work_matrices, qs_env, admm_env)
Allocate work matrices for hfxsr.
subroutine, public tddfpt_create_work_matrices(work_matrices, gs_mos, nstates, do_hfx, do_admm, do_hfxlr, do_exck, do_sf, qs_env, sub_env)
Allocate work matrices for full kernel.
subroutine, public tddfpt_release_work_matrices(work_matrices, sub_env)
Release work matrices.
subroutine, public stda_create_work_matrices(work_matrices, gs_mos, nstates, qs_env, sub_env)
Allocate work matrices for sTDA kernel.
subroutine, public tddfpt_release_ground_state_mos(gs_mos)
Release molecular orbitals.
subroutine, public tddfpt_oecorr(qs_env, gs_mos, matrix_ks_oep)
Callculate orbital corrected KS matrix for TDDFPT.
subroutine, public tddfpt_guess_vectors(evects, evals, gs_mos, log_unit, tddfpt_control, fm_pool_ao_mo_active, qs_env, nspins)
Generate missed guess vectors.
subroutine, public tddfpt_init_mos(qs_env, gs_mos, iounit)
Prepare MOs for TDDFPT Calculations.
Define Resonant Inelastic XRAY Scattering (RIXS) control type and associated create,...
Definition rixs_types.F:13
Utilities for string manipulations.
subroutine, public integer_to_string(inumber, string)
Converts an integer number to a string. The WRITE statement will return an error message,...
Writes information on XC functionals to output.
subroutine, public xc_write(iounit, xc_section, lsd)
...
stores some data used in wavefunction fitting
Definition admm_types.F:120
Provides all information about an atomic kind.
Type defining parameters related to the simulation cell.
Definition cell_types.F:60
represent a blacs multidimensional parallel environment (for the mpi corrispective see cp_paratypes/m...
keeps the information about the structure of a full matrix
represent a full matrix
type of a logger, at the moment it contains just a print level starting at which level it should be l...
Contains information on the excited states energy.
stores all the informations relevant to an mpi environment
Collection of variables required to evaluate adiabatic TDDFPT kernel.
Type to hold environments for the different kernels.
Provides all information about a quickstep kind.
Ground state molecular orbitals.
Set of temporary ("work") matrices.
Valence state coming from the qs_tddfpt2 routine.
Definition rixs_types.F:40