(git:495eafe)
Loading...
Searching...
No Matches
qs_tddfpt2_fhxc_forces.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
11 USE admm_types, ONLY: admm_type,&
15 USE cell_types, ONLY: cell_type,&
16 pbc
20 USE cp_dbcsr_api, ONLY: &
25 dbcsr_type_antisymmetric, dbcsr_type_no_symmetry
42 USE cp_fm_types, ONLY: cp_fm_create,&
64 USE hfx_ri, ONLY: hfx_ri_update_forces,&
66 USE hfx_types, ONLY: hfx_type
79 USE kinds, ONLY: default_string_length,&
80 dp
81 USE mathconstants, ONLY: oorootpi
86 USE pw_env_types, ONLY: pw_env_get,&
88 USE pw_methods, ONLY: pw_axpy,&
89 pw_scale,&
95 USE pw_types, ONLY: pw_c1d_gs_type,&
102 USE qs_fxc, ONLY: qs_fgxc_analytic,&
107 USE qs_integrate_potential, ONLY: integrate_v_rspace
109 USE qs_kind_types, ONLY: qs_kind_type
110 USE qs_ks_atom, ONLY: update_ks_atom
111 USE qs_ks_types, ONLY: qs_ks_env_type
117 USE qs_oce_types, ONLY: allocate_oce_set,&
123 USE qs_rho0_methods, ONLY: init_rho0
127 USE qs_rho_types, ONLY: qs_rho_create,&
128 qs_rho_get,&
129 qs_rho_set,&
140 USE util, ONLY: get_limit
141 USE virial_types, ONLY: virial_type
144#include "./base/base_uses.f90"
145
146 IMPLICIT NONE
147
148 PRIVATE
149
150 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_tddfpt2_fhxc_forces'
151
152 PUBLIC :: fhxc_force, stda_force
153
154! **************************************************************************************************
155
156CONTAINS
157
158! **************************************************************************************************
159!> \brief Calculate direct tddft forces. Calculate the three last terms of the response vector
160!> in equation 49 and the first term of \Lambda_munu in equation 51 in
161!> J. Chem. Theory Comput. 2022, 18, 7, 4186–4202 (https://doi.org/10.1021/acs.jctc.2c00144)
162!> \param qs_env Holds all system information relevant for the calculation.
163!> \param ex_env Holds the response vector ex_env%cpmos and Lambda ex_env%matrix_wx1.
164!> \param gs_mos MO coefficients of the ground state.
165!> \param full_kernel ...
166!> \param debug_forces ...
167!> \par History
168!> * 01.2020 screated [JGH]
169! **************************************************************************************************
170 SUBROUTINE fhxc_force(qs_env, ex_env, gs_mos, full_kernel, debug_forces)
171
172 TYPE(qs_environment_type), POINTER :: qs_env
173 TYPE(excited_energy_type), POINTER :: ex_env
174 TYPE(tddfpt_ground_state_mos), DIMENSION(:), &
175 POINTER :: gs_mos
176 TYPE(full_kernel_env_type), INTENT(IN) :: full_kernel
177 LOGICAL, INTENT(IN) :: debug_forces
178
179 CHARACTER(LEN=*), PARAMETER :: routinen = 'fhxc_force'
180
181 CHARACTER(LEN=default_string_length) :: basis_type
182 INTEGER :: handle, ia, ib, iounit, ispin, mspin, &
183 myfun, n_rep_hf, nactive(2), nao, &
184 nao_aux, natom, nkind, norb(2), nsev, &
185 nspins, order, spin
186 LOGICAL :: distribute_fock_matrix, do_admm, do_analytic, do_hfx, do_hfxlr, do_hfxsr, &
187 do_numeric, do_res, do_sf, gapw, gapw_xc, hfx_treat_lsd_in_core, is_rks_triplets, &
188 needs_tau_response, needs_tau_response_aux, s_mstruct_changed, use_virial
189 REAL(kind=dp) :: eh1, eh1c, eps_delta, eps_fit, focc, &
190 fscal, fval, kval, xehartree
191 REAL(kind=dp), DIMENSION(3) :: fodeb
192 TYPE(admm_type), POINTER :: admm_env
193 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
194 TYPE(cp_fm_struct_type), POINTER :: fm_struct
195 TYPE(cp_fm_type) :: avamat, avcmat, cpscr, cvcmat, vavec, &
196 vcvec
197 TYPE(cp_fm_type), DIMENSION(:), POINTER :: cpmos, evect
198 TYPE(cp_fm_type), POINTER :: mos, mos2, mosa, mosa2
199 TYPE(cp_logger_type), POINTER :: logger
200 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_fx, matrix_gx, matrix_hfx, &
201 matrix_hfx_admm, matrix_hfx_admm_asymm, matrix_hfx_asymm, matrix_hx, matrix_p, &
202 matrix_p_admm, matrix_px1, matrix_px1_admm, matrix_px1_admm_asymm, matrix_px1_asymm, &
203 matrix_s, matrix_s_aux_fit, matrix_wx1, mdum, mfx, mgx
204 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: mhe, mpe, mpga
205 TYPE(dbcsr_type), POINTER :: dbwork, dbwork_asymm
206 TYPE(dft_control_type), POINTER :: dft_control
207 TYPE(hartree_local_type), POINTER :: hartree_local
208 TYPE(hfx_type), DIMENSION(:, :), POINTER :: x_data
209 TYPE(local_rho_type), POINTER :: local_rho_set, local_rho_set_admm, local_rho_set_f, &
210 local_rho_set_f_admm, local_rho_set_g, local_rho_set_g_admm
211 TYPE(mp_para_env_type), POINTER :: para_env
212 TYPE(neighbor_list_set_p_type), DIMENSION(:), &
213 POINTER :: sab, sab_aux_fit, sab_orb, sap_oce
214 TYPE(oce_matrix_type), POINTER :: oce
215 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
216 TYPE(pw_c1d_gs_type) :: rhox_tot_gspace, xv_hartree_gspace
217 TYPE(pw_c1d_gs_type), DIMENSION(:), POINTER :: rho_g_aux, rhox_g, rhox_g_aux, &
218 rhox_tau_g, rhox_tau_g_aux, rhoxx_g, &
219 rhoxx_tau_g
220 TYPE(pw_env_type), POINTER :: pw_env
221 TYPE(pw_poisson_type), POINTER :: poisson_env
222 TYPE(pw_pool_type), POINTER :: auxbas_pw_pool
223 TYPE(pw_r3d_rs_type) :: xv_hartree_rspace
224 TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER :: fxc_rho, fxc_tau, gxc_rho, gxc_tau, &
225 rho_r_aux, rhox_r, rhox_r_aux, &
226 rhox_tau_r, rhox_tau_r_aux, rhoxx_r, &
227 rhoxx_tau_r
228 TYPE(pw_r3d_rs_type), POINTER :: weights
229 TYPE(qs_force_type), DIMENSION(:), POINTER :: force
230 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
231 TYPE(qs_ks_env_type), POINTER :: ks_env
232 TYPE(qs_rho_type), POINTER :: rho, rho_aux_fit, rhox, rhox_aux
233 TYPE(rho_atom_type), DIMENSION(:), POINTER :: rho_atom_set, rho_atom_set_f, &
234 rho_atom_set_g
235 TYPE(section_vals_type), POINTER :: hfx_section, xc_fun_section, xc_section
236 TYPE(task_list_type), POINTER :: task_list
237 TYPE(tddfpt2_control_type), POINTER :: tddfpt_control
238 TYPE(xc_rho_cflags_type) :: needs
239
240 CALL timeset(routinen, handle)
241
242 logger => cp_get_default_logger()
243 IF (logger%para_env%is_source()) THEN
244 iounit = cp_logger_get_default_unit_nr(logger, local=.true.)
245 ELSE
246 iounit = -1
247 END IF
248
249 CALL get_qs_env(qs_env, dft_control=dft_control)
250 tddfpt_control => dft_control%tddfpt2_control
251 nspins = dft_control%nspins
252 is_rks_triplets = tddfpt_control%rks_triplets .AND. (nspins == 1)
253 IF (tddfpt_control%spinflip == no_sf_tddfpt) THEN
254 do_sf = .false.
255 ELSE
256 do_sf = .true.
257 END IF
258 cpassert(tddfpt_control%kernel == tddfpt_kernel_full)
259 do_hfx = tddfpt_control%do_hfx
260 do_hfxsr = tddfpt_control%do_hfxsr
261 do_hfxlr = tddfpt_control%do_hfxlr
262 do_admm = tddfpt_control%do_admm
263 gapw = dft_control%qs_control%gapw
264 gapw_xc = dft_control%qs_control%gapw_xc
265 xc_section => full_kernel%xc_section
266 xc_fun_section => section_vals_get_subs_vals(xc_section, "XC_FUNCTIONAL")
267 needs = xc_functionals_get_needs(xc_fun_section, (nspins == 2), .true.)
268 needs_tau_response = needs%tau .OR. needs%tau_spin
269 needs_tau_response_aux = .false.
270
271 evect => ex_env%evect
272 matrix_px1 => ex_env%matrix_px1
273 matrix_px1_admm => ex_env%matrix_px1_admm
274 matrix_px1_asymm => ex_env%matrix_px1_asymm
275 matrix_px1_admm_asymm => ex_env%matrix_px1_admm_asymm
276
277 focc = 1.0_dp
278 IF (nspins == 2) focc = 0.5_dp
279 nsev = SIZE(evect, 1)
280 DO ispin = 1, nsev
281 CALL cp_fm_get_info(evect(ispin), ncol_global=nactive(ispin))
282 ! Calculate (C*X^T + X*C^T)/2
283 CALL dbcsr_set(matrix_px1(ispin)%matrix, 0.0_dp)
284 CALL cp_dbcsr_plus_fm_fm_t(matrix_px1(ispin)%matrix, &
285 matrix_v=evect(ispin), &
286 matrix_g=gs_mos(ispin)%mos_active, &
287 ncol=nactive(ispin), alpha=2.0_dp*focc, symmetry_mode=1)
288
289 ! Calculate (C*X^T - X*C^T)/2
290 CALL dbcsr_set(matrix_px1_asymm(ispin)%matrix, 0.0_dp)
291 CALL cp_dbcsr_plus_fm_fm_t(matrix_px1_asymm(ispin)%matrix, &
292 matrix_v=gs_mos(ispin)%mos_active, &
293 matrix_g=evect(ispin), &
294 ncol=nactive(ispin), alpha=2.0_dp*focc, &
295 symmetry_mode=-1)
296 END DO
297 !
298 CALL get_qs_env(qs_env, ks_env=ks_env, pw_env=pw_env, para_env=para_env)
299 CALL get_qs_env(qs_env, xcint_weights=weights)
300 !
301 NULLIFY (hartree_local, local_rho_set, local_rho_set_admm)
302 IF (gapw .OR. gapw_xc) THEN
303 IF (nspins == 2) THEN
304 DO ispin = 1, nsev
305 CALL dbcsr_scale(matrix_px1(ispin)%matrix, 2.0_dp)
306 END DO
307 END IF
308 CALL get_qs_env(qs_env, &
309 atomic_kind_set=atomic_kind_set, &
310 qs_kind_set=qs_kind_set)
311 CALL local_rho_set_create(local_rho_set)
312 CALL allocate_rho_atom_internals(local_rho_set%rho_atom_set, atomic_kind_set, &
313 qs_kind_set, dft_control, para_env)
314 IF (gapw) THEN
315 CALL get_qs_env(qs_env, natom=natom)
316 CALL init_rho0(local_rho_set, qs_env, dft_control%qs_control%gapw_control, &
317 zcore=0.0_dp)
318 CALL rho0_s_grid_create(pw_env, local_rho_set%rho0_mpole)
319 CALL hartree_local_create(hartree_local)
320 CALL init_coulomb_local(hartree_local, natom)
321 END IF
322
323 CALL get_qs_env(qs_env=qs_env, oce=oce, sap_oce=sap_oce, sab_orb=sab)
324 CALL create_oce_set(oce)
325 CALL get_qs_env(qs_env=qs_env, nkind=nkind, particle_set=particle_set)
326 CALL allocate_oce_set(oce, nkind)
327 eps_fit = dft_control%qs_control%gapw_control%eps_fit
328 CALL build_oce_matrices(oce%intac, .true., 1, qs_kind_set, particle_set, &
329 sap_oce, eps_fit)
330 CALL set_qs_env(qs_env, oce=oce)
331
332 mpga(1:nsev, 1:1) => matrix_px1(1:nsev)
333 CALL calculate_rho_atom_coeff(qs_env, mpga, local_rho_set%rho_atom_set, &
334 qs_kind_set, oce, sab, para_env)
335 CALL prepare_gapw_den(qs_env, local_rho_set, do_rho0=gapw)
336 !
337 CALL local_rho_set_create(local_rho_set_f)
338 CALL allocate_rho_atom_internals(local_rho_set_f%rho_atom_set, atomic_kind_set, &
339 qs_kind_set, dft_control, para_env)
340 CALL calculate_rho_atom_coeff(qs_env, mpga, local_rho_set_f%rho_atom_set, &
341 qs_kind_set, oce, sab, para_env)
342 CALL prepare_gapw_den(qs_env, local_rho_set_f, do_rho0=.false.)
343 !
344 CALL local_rho_set_create(local_rho_set_g)
345 CALL allocate_rho_atom_internals(local_rho_set_g%rho_atom_set, atomic_kind_set, &
346 qs_kind_set, dft_control, para_env)
347 CALL calculate_rho_atom_coeff(qs_env, mpga, local_rho_set_g%rho_atom_set, &
348 qs_kind_set, oce, sab, para_env)
349 CALL prepare_gapw_den(qs_env, local_rho_set_g, do_rho0=.false.)
350 IF (nspins == 2) THEN
351 DO ispin = 1, nsev
352 CALL dbcsr_scale(matrix_px1(ispin)%matrix, 0.5_dp)
353 END DO
354 END IF
355 END IF
356 !
357 IF (do_admm) THEN
358 CALL get_qs_env(qs_env, admm_env=admm_env)
359 nao_aux = admm_env%nao_aux_fit
360 nao = admm_env%nao_orb
361 ! Fit the symmetrized and antisymmetrized matrices
362 DO ispin = 1, nsev
363
364 CALL copy_dbcsr_to_fm(matrix_px1(ispin)%matrix, admm_env%work_orb_orb)
365 CALL parallel_gemm('N', 'N', nao_aux, nao, nao, &
366 1.0_dp, admm_env%A, admm_env%work_orb_orb, 0.0_dp, &
367 admm_env%work_aux_orb)
368 CALL parallel_gemm('N', 'T', nao_aux, nao_aux, nao, &
369 1.0_dp, admm_env%work_aux_orb, admm_env%A, 0.0_dp, &
370 admm_env%work_aux_aux)
371 CALL copy_fm_to_dbcsr(admm_env%work_aux_aux, matrix_px1_admm(ispin)%matrix, &
372 keep_sparsity=.true.)
373
374 CALL copy_dbcsr_to_fm(matrix_px1_asymm(ispin)%matrix, admm_env%work_orb_orb)
375 CALL parallel_gemm('N', 'N', nao_aux, nao, nao, &
376 1.0_dp, admm_env%A, admm_env%work_orb_orb, 0.0_dp, &
377 admm_env%work_aux_orb)
378 CALL parallel_gemm('N', 'T', nao_aux, nao_aux, nao, &
379 1.0_dp, admm_env%work_aux_orb, admm_env%A, 0.0_dp, &
380 admm_env%work_aux_aux)
381 CALL copy_fm_to_dbcsr(admm_env%work_aux_aux, matrix_px1_admm_asymm(ispin)%matrix, &
382 keep_sparsity=.true.)
383 END DO
384 !
385 IF (admm_env%do_gapw) THEN
386 IF (do_admm .AND. tddfpt_control%admm_xc_correction) THEN
387 IF (admm_env%aux_exch_func == do_admm_aux_exch_func_none) THEN
388 ! nothing to do
389 ELSE
390 CALL get_qs_env(qs_env, atomic_kind_set=atomic_kind_set)
391 CALL local_rho_set_create(local_rho_set_admm)
392 CALL allocate_rho_atom_internals(local_rho_set_admm%rho_atom_set, atomic_kind_set, &
393 admm_env%admm_gapw_env%admm_kind_set, dft_control, para_env)
394 mpga(1:nsev, 1:1) => matrix_px1_admm(1:nsev)
395 CALL get_admm_env(admm_env, sab_aux_fit=sab_aux_fit)
396 CALL calculate_rho_atom_coeff(qs_env, mpga, local_rho_set_admm%rho_atom_set, &
397 admm_env%admm_gapw_env%admm_kind_set, &
398 admm_env%admm_gapw_env%oce, sab_aux_fit, para_env)
399 CALL prepare_gapw_den(qs_env, local_rho_set_admm, do_rho0=.false., &
400 kind_set_external=admm_env%admm_gapw_env%admm_kind_set)
401 !
402 CALL local_rho_set_create(local_rho_set_f_admm)
403 CALL allocate_rho_atom_internals(local_rho_set_f_admm%rho_atom_set, atomic_kind_set, &
404 admm_env%admm_gapw_env%admm_kind_set, dft_control, para_env)
405 CALL calculate_rho_atom_coeff(qs_env, mpga, local_rho_set_f_admm%rho_atom_set, &
406 admm_env%admm_gapw_env%admm_kind_set, &
407 admm_env%admm_gapw_env%oce, sab_aux_fit, para_env)
408 CALL prepare_gapw_den(qs_env, local_rho_set_f_admm, do_rho0=.false., &
409 kind_set_external=admm_env%admm_gapw_env%admm_kind_set)
410 !
411 CALL local_rho_set_create(local_rho_set_g_admm)
412 CALL allocate_rho_atom_internals(local_rho_set_g_admm%rho_atom_set, atomic_kind_set, &
413 admm_env%admm_gapw_env%admm_kind_set, dft_control, para_env)
414 CALL calculate_rho_atom_coeff(qs_env, mpga, local_rho_set_g_admm%rho_atom_set, &
415 admm_env%admm_gapw_env%admm_kind_set, &
416 admm_env%admm_gapw_env%oce, sab_aux_fit, para_env)
417 CALL prepare_gapw_den(qs_env, local_rho_set_g_admm, do_rho0=.false., &
418 kind_set_external=admm_env%admm_gapw_env%admm_kind_set)
419 END IF
420 END IF
421 END IF
422 END IF
423 !
424 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool, &
425 poisson_env=poisson_env)
426
427 NULLIFY (rhox_tau_g, rhox_tau_r, rhoxx_tau_g, rhoxx_tau_r)
428 ALLOCATE (rhox_r(nsev), rhox_g(nsev))
429 DO ispin = 1, SIZE(evect, 1)
430 CALL auxbas_pw_pool%create_pw(rhox_r(ispin))
431 CALL auxbas_pw_pool%create_pw(rhox_g(ispin))
432 END DO
433 IF (needs_tau_response) THEN
434 ALLOCATE (rhox_tau_r(nsev), rhox_tau_g(nsev))
435 DO ispin = 1, SIZE(evect, 1)
436 CALL auxbas_pw_pool%create_pw(rhox_tau_r(ispin))
437 CALL auxbas_pw_pool%create_pw(rhox_tau_g(ispin))
438 END DO
439 END IF
440 CALL auxbas_pw_pool%create_pw(rhox_tot_gspace)
441
442 CALL pw_zero(rhox_tot_gspace)
443 DO ispin = 1, nsev
444 ! Calculate gridpoint values of the density associated to 2*matrix_px1 = C*X^T + X*C^T
445 IF (nspins == 2) CALL dbcsr_scale(matrix_px1(ispin)%matrix, 2.0_dp)
446 CALL calculate_rho_elec(ks_env=ks_env, matrix_p=matrix_px1(ispin)%matrix, &
447 rho=rhox_r(ispin), rho_gspace=rhox_g(ispin), &
448 soft_valid=gapw)
449 IF (needs_tau_response) THEN
450 CALL calculate_rho_elec(ks_env=ks_env, matrix_p=matrix_px1(ispin)%matrix, &
451 rho=rhox_tau_r(ispin), rho_gspace=rhox_tau_g(ispin), &
452 soft_valid=gapw, compute_tau=.true.)
453 END IF
454 ! rhox_tot_gspace contains the values on the grid points of rhox = sum_munu 4D^X_munu*mu(r)*nu(r)
455 CALL pw_axpy(rhox_g(ispin), rhox_tot_gspace)
456 ! Recover matrix_px1 = (C*X^T + X*C^T)/2
457 IF (nspins == 2) CALL dbcsr_scale(matrix_px1(ispin)%matrix, 0.5_dp)
458 END DO
459
460 IF (gapw_xc) THEN
461 ALLOCATE (rhoxx_r(nsev), rhoxx_g(nsev))
462 DO ispin = 1, nsev
463 CALL auxbas_pw_pool%create_pw(rhoxx_r(ispin))
464 CALL auxbas_pw_pool%create_pw(rhoxx_g(ispin))
465 END DO
466 IF (needs_tau_response) THEN
467 ALLOCATE (rhoxx_tau_r(nsev), rhoxx_tau_g(nsev))
468 DO ispin = 1, nsev
469 CALL auxbas_pw_pool%create_pw(rhoxx_tau_r(ispin))
470 CALL auxbas_pw_pool%create_pw(rhoxx_tau_g(ispin))
471 END DO
472 END IF
473 DO ispin = 1, nsev
474 IF (nspins == 2) CALL dbcsr_scale(matrix_px1(ispin)%matrix, 2.0_dp)
475 CALL calculate_rho_elec(ks_env=ks_env, matrix_p=matrix_px1(ispin)%matrix, &
476 rho=rhoxx_r(ispin), rho_gspace=rhoxx_g(ispin), &
477 soft_valid=gapw_xc)
478 IF (needs_tau_response) THEN
479 CALL calculate_rho_elec(ks_env=ks_env, matrix_p=matrix_px1(ispin)%matrix, &
480 rho=rhoxx_tau_r(ispin), rho_gspace=rhoxx_tau_g(ispin), &
481 soft_valid=gapw_xc, compute_tau=.true.)
482 END IF
483 IF (nspins == 2) CALL dbcsr_scale(matrix_px1(ispin)%matrix, 0.5_dp)
484 END DO
485 END IF
486
487 CALL get_qs_env(qs_env, matrix_s=matrix_s, force=force)
488
489 IF (.NOT. (is_rks_triplets .OR. do_sf)) THEN
490 CALL auxbas_pw_pool%create_pw(xv_hartree_rspace)
491 CALL auxbas_pw_pool%create_pw(xv_hartree_gspace)
492 ! calculate associated hartree potential
493 IF (gapw) THEN
494 CALL pw_axpy(local_rho_set%rho0_mpole%rho0_s_gs, rhox_tot_gspace)
495 IF (ASSOCIATED(local_rho_set%rho0_mpole%rhoz_cneo_s_gs)) THEN
496 CALL pw_axpy(local_rho_set%rho0_mpole%rhoz_cneo_s_gs, rhox_tot_gspace)
497 END IF
498 END IF
499 CALL pw_poisson_solve(poisson_env, rhox_tot_gspace, xehartree, &
500 xv_hartree_gspace)
501 CALL pw_transfer(xv_hartree_gspace, xv_hartree_rspace)
502 CALL pw_scale(xv_hartree_rspace, xv_hartree_rspace%pw_grid%dvol)
503 !
504 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
505 NULLIFY (matrix_hx)
506 CALL dbcsr_allocate_matrix_set(matrix_hx, nspins)
507 DO ispin = 1, nspins
508 ALLOCATE (matrix_hx(ispin)%matrix)
509 CALL dbcsr_create(matrix_hx(ispin)%matrix, template=matrix_s(1)%matrix)
510 CALL dbcsr_copy(matrix_hx(ispin)%matrix, matrix_s(1)%matrix)
511 CALL dbcsr_set(matrix_hx(ispin)%matrix, 0.0_dp)
512 CALL integrate_v_rspace(qs_env=qs_env, v_rspace=xv_hartree_rspace, &
513 pmat=matrix_px1(ispin), hmat=matrix_hx(ispin), &
514 gapw=gapw, calculate_forces=.true.)
515 END DO
516 IF (debug_forces) THEN
517 fodeb(1:3) = force(1)%rho_elec(1:3, 1) - fodeb(1:3)
518 CALL para_env%sum(fodeb)
519 IF (iounit > 0) WRITE (iounit, "(T3,A,T33,3F16.8)") "DEBUG:: Dx*dKh[Dx] ", fodeb
520 END IF
521 IF (gapw) THEN
522 IF (debug_forces) fodeb(1:3) = force(1)%g0s_Vh_elec(1:3, 1)
523 CALL vh_1c_gg_integrals(qs_env, eh1c, hartree_local%ecoul_1c, local_rho_set, para_env, tddft=.true., &
524 core_2nd=.true.)
525 IF (nspins == 1) THEN
526 kval = 1.0_dp
527 ELSE
528 kval = 0.5_dp
529 END IF
530 CALL integrate_vhg0_rspace(qs_env, xv_hartree_rspace, para_env, calculate_forces=.true., &
531 local_rho_set=local_rho_set, kforce=kval)
532 IF (debug_forces) THEN
533 fodeb(1:3) = force(1)%g0s_Vh_elec(1:3, 1) - fodeb(1:3)
534 CALL para_env%sum(fodeb)
535 IF (iounit > 0) WRITE (iounit, "(T3,A,T33,3F16.8)") "DEBUG:: Dx*dKh[Dx]PAWg0", fodeb
536 END IF
537 IF (debug_forces) fodeb(1:3) = force(1)%Vhxc_atom(1:3, 1)
538 CALL update_ks_atom(qs_env, matrix_hx, matrix_px1, forces=.true., &
539 rho_atom_external=local_rho_set%rho_atom_set)
540 IF (debug_forces) THEN
541 fodeb(1:3) = force(1)%Vhxc_atom(1:3, 1) - fodeb(1:3)
542 CALL para_env%sum(fodeb)
543 IF (iounit > 0) WRITE (iounit, "(T3,A,T33,3F16.8)") "DEBUG:: Dx*dKh[Dx]PAW", fodeb
544 END IF
545 END IF
546 END IF
547
548 ! XC
549 IF (full_kernel%do_exck) THEN
550 cpabort("NYA")
551 END IF
552 NULLIFY (fxc_rho, fxc_tau, gxc_rho, gxc_tau)
553 xc_section => full_kernel%xc_section
554 CALL section_vals_val_get(xc_section, "XC_FUNCTIONAL%_SECTION_PARAMETERS_", &
555 i_val=myfun)
556 IF (.NOT. ((myfun == xc_none) .OR. (tddfpt_control%spinflip == tddfpt_sf_col))) THEN
557 SELECT CASE (ex_env%xc_kernel_method)
559 do_analytic = .true.
560 do_numeric = .true.
562 do_analytic = .true.
563 do_numeric = .false.
565 do_analytic = .false.
566 do_numeric = .true.
567 CASE DEFAULT
568 cpabort("invalid xc_kernel_method")
569 END SELECT
570 order = ex_env%diff_order
571 eps_delta = ex_env%eps_delta_rho
572
573 IF (gapw_xc) THEN
574 CALL get_qs_env(qs_env=qs_env, ks_env=ks_env, rho_xc=rho)
575 ELSE
576 CALL get_qs_env(qs_env=qs_env, ks_env=ks_env, rho=rho)
577 END IF
578 CALL qs_rho_get(rho, rho_ao=matrix_p)
579 NULLIFY (rhox)
580 ALLOCATE (rhox)
581 ! Create rhox object to collect all information on matrix_px1, including its values on the
582 ! grid points
583 CALL qs_rho_create(rhox)
584 IF (gapw_xc) THEN
585 IF (needs_tau_response) THEN
586 CALL qs_rho_set(rho_struct=rhox, rho_ao=matrix_px1, rho_r=rhoxx_r, rho_g=rhoxx_g, &
587 tau_r=rhoxx_tau_r, tau_g=rhoxx_tau_g, &
588 rho_r_valid=.true., rho_g_valid=.true., &
589 tau_r_valid=.true., tau_g_valid=.true.)
590 ELSE
591 CALL qs_rho_set(rho_struct=rhox, rho_ao=matrix_px1, rho_r=rhoxx_r, rho_g=rhoxx_g, &
592 rho_r_valid=.true., rho_g_valid=.true.)
593 END IF
594 ELSE
595 IF (needs_tau_response) THEN
596 CALL qs_rho_set(rho_struct=rhox, rho_ao=matrix_px1, rho_r=rhox_r, rho_g=rhox_g, &
597 tau_r=rhox_tau_r, tau_g=rhox_tau_g, &
598 rho_r_valid=.true., rho_g_valid=.true., &
599 tau_r_valid=.true., tau_g_valid=.true.)
600 ELSE
601 CALL qs_rho_set(rho_struct=rhox, rho_ao=matrix_px1, rho_r=rhox_r, rho_g=rhox_g, &
602 rho_r_valid=.true., rho_g_valid=.true.)
603 END IF
604 END IF
605 ! Calculate the exchange-correlation kernel derivative contribution, notice that for open-shell
606 ! rhox_r contains a factor of 2!
607 IF (do_analytic .AND. .NOT. do_numeric) THEN
608 IF (.NOT. do_sf) THEN
609 cpabort("Analytic 3rd EXC derivatives not available")
610 ELSE !TODO
611 CALL get_qs_env(qs_env, xcint_weights=weights)
612 CALL qs_fgxc_analytic(rho, rhox, xc_section, weights, auxbas_pw_pool, &
613 fxc_rho, fxc_tau, gxc_rho, gxc_tau, spinflip=do_sf)
614 END IF
615 ELSEIF (do_numeric) THEN
616 IF (do_analytic) THEN
617 CALL qs_fgxc_gdiff(ks_env, rho, rhox, xc_section, order, eps_delta, is_rks_triplets, &
618 weights, fxc_rho, fxc_tau, gxc_rho, gxc_tau, spinflip=do_sf)
619 ELSE
620 CALL qs_fgxc_create(ks_env, rho, rhox, xc_section, order, is_rks_triplets, &
621 fxc_rho, fxc_tau, gxc_rho, gxc_tau)
622 END IF
623 ELSE
624 cpabort("FHXC forces analytic/numeric")
625 END IF
626
627 IF (nspins == 2) THEN
628 DO ispin = 1, nspins
629 CALL pw_scale(gxc_rho(ispin), 0.5_dp)
630 IF (ASSOCIATED(gxc_tau)) CALL pw_scale(gxc_tau(ispin), 0.5_dp)
631 END DO
632 END IF
633 IF (gapw .OR. gapw_xc) THEN
634 IF (do_analytic .AND. .NOT. do_numeric) THEN
635 cpabort("Analytic 3rd EXC derivatives not available")
636 ELSEIF (do_numeric) THEN
637 IF (do_analytic) THEN
638 CALL gfxc_atom_diff(qs_env, ex_env%local_rho_set%rho_atom_set, &
639 local_rho_set_f%rho_atom_set, local_rho_set_g%rho_atom_set, &
640 qs_kind_set, xc_section, is_rks_triplets, order, eps_delta)
641 ELSE
642 CALL calculate_gfxc_atom(qs_env, ex_env%local_rho_set%rho_atom_set, &
643 local_rho_set_f%rho_atom_set, local_rho_set_g%rho_atom_set, &
644 qs_kind_set, xc_section, is_rks_triplets, order)
645 END IF
646 ELSE
647 cpabort("FHXC forces analytic/numeric")
648 END IF
649 END IF
650
651 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
652 NULLIFY (matrix_fx)
653 CALL dbcsr_allocate_matrix_set(matrix_fx, SIZE(fxc_rho))
654 DO ispin = 1, SIZE(fxc_rho, 1)
655 ALLOCATE (matrix_fx(ispin)%matrix)
656 CALL dbcsr_create(matrix_fx(ispin)%matrix, template=matrix_s(1)%matrix)
657 CALL dbcsr_copy(matrix_fx(ispin)%matrix, matrix_s(1)%matrix)
658 CALL dbcsr_set(matrix_fx(ispin)%matrix, 0.0_dp)
659 CALL pw_scale(fxc_rho(ispin), fxc_rho(ispin)%pw_grid%dvol)
660 ! Calculate 2sum_sigmatau<munu|fxc|sigmatau>D^X_sigmatau
661 ! fxc_rho here containes a factor of 2
662 CALL integrate_v_rspace(qs_env=qs_env, v_rspace=fxc_rho(ispin), &
663 pmat=matrix_px1(ispin), hmat=matrix_fx(ispin), &
664 gapw=(gapw .OR. gapw_xc), calculate_forces=.true.)
665 END DO
666 IF (debug_forces) THEN
667 fodeb(1:3) = force(1)%rho_elec(1:3, 1) - fodeb(1:3)
668 CALL para_env%sum(fodeb)
669 IF (iounit > 0) WRITE (iounit, "(T3,A,T33,3F16.8)") "DEBUG:: Dx*dfxc[Dx] ", fodeb
670 END IF
671
672 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
673 NULLIFY (matrix_gx)
674 CALL dbcsr_allocate_matrix_set(matrix_gx, nspins)
675 ! Calculate exchange-correlation kernel derivative 2<D^X D^X|gxc|mu nu>
676 ! gxc comes with a factor of 4, so a factor of 1/2 is introduced
677 DO ispin = 1, nspins
678 ALLOCATE (matrix_gx(ispin)%matrix)
679 CALL dbcsr_create(matrix_gx(ispin)%matrix, template=matrix_s(1)%matrix)
680 CALL dbcsr_copy(matrix_gx(ispin)%matrix, matrix_s(1)%matrix)
681 CALL dbcsr_set(matrix_gx(ispin)%matrix, 0.0_dp)
682 CALL pw_scale(gxc_rho(ispin), gxc_rho(ispin)%pw_grid%dvol)
683 CALL pw_scale(gxc_rho(ispin), 0.5_dp)
684 CALL integrate_v_rspace(qs_env=qs_env, v_rspace=gxc_rho(ispin), &
685 pmat=matrix_p(ispin), hmat=matrix_gx(ispin), &
686 gapw=(gapw .OR. gapw_xc), calculate_forces=.true.)
687 CALL dbcsr_scale(matrix_gx(ispin)%matrix, 2.0_dp)
688 END DO
689 IF (debug_forces) THEN
690 fodeb(1:3) = force(1)%rho_elec(1:3, 1) - fodeb(1:3)
691 CALL para_env%sum(fodeb)
692 IF (iounit > 0) WRITE (iounit, "(T3,A,T33,3F16.8)") "DEBUG:: Dx*dgxc[Dx]", fodeb
693 END IF
694 CALL qs_fgxc_release(ks_env, fxc_rho, fxc_tau, gxc_rho, gxc_tau)
695
696 ! grid weight contribution to forces
697 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
698 CALL accint_weight_force(qs_env, rho, rhox, 2, xc_section, is_rks_triplets)
699 IF (debug_forces) THEN
700 fodeb(1:3) = force(1)%rho_elec(1:3, 1) - fodeb(1:3)
701 CALL para_env%sum(fodeb)
702 IF (iounit > 0) WRITE (iounit, "(T3,A,T33,3F16.8)") "DEBUG:: Dx*fxc[Dx]*dw", fodeb
703 END IF
704
705 ! Well, this is a hack :-(
706 ! When qs_rho_set() was called on rhox it assumed ownership of the passed arrays.
707 ! However, these arrays actually belong to ex_env. Hence, we can not call qs_rho_release()
708 ! because this would release the arrays. Instead we're simply going to deallocate rhox.
709 DEALLOCATE (rhox)
710
711 IF (gapw .OR. gapw_xc) THEN
712 IF (debug_forces) fodeb(1:3) = force(1)%Vhxc_atom(1:3, 1)
713 CALL update_ks_atom(qs_env, matrix_fx, matrix_px1, forces=.true., tddft=.true., &
714 rho_atom_external=local_rho_set_f%rho_atom_set, &
715 kintegral=1.0_dp, kforce=1.0_dp)
716 IF (debug_forces) THEN
717 fodeb(1:3) = force(1)%Vhxc_atom(1:3, 1) - fodeb(1:3)
718 CALL para_env%sum(fodeb)
719 IF (iounit > 0) WRITE (iounit, "(T3,A,T33,3F16.8)") "DEBUG:: Dx*dfxc[Dx]PAW ", fodeb
720 END IF
721 IF (debug_forces) fodeb(1:3) = force(1)%Vhxc_atom(1:3, 1)
722 IF (nspins == 1) THEN
723 CALL update_ks_atom(qs_env, matrix_gx, matrix_p, forces=.true., tddft=.true., &
724 rho_atom_external=local_rho_set_g%rho_atom_set, &
725 kscale=0.5_dp)
726 ELSE
727 CALL update_ks_atom(qs_env, matrix_gx, matrix_p, forces=.true., &
728 rho_atom_external=local_rho_set_g%rho_atom_set, &
729 kintegral=0.5_dp, kforce=0.25_dp)
730 END IF
731 IF (debug_forces) THEN
732 fodeb(1:3) = force(1)%Vhxc_atom(1:3, 1) - fodeb(1:3)
733 CALL para_env%sum(fodeb)
734 IF (iounit > 0) WRITE (iounit, "(T3,A,T33,3F16.8)") "DEBUG:: Dx*dgxc[Dx]PAW ", fodeb
735 END IF
736 END IF
737 END IF
738
739 ! ADMM XC correction Exc[rho_admm]
740 IF (do_admm .AND. tddfpt_control%admm_xc_correction .AND. (tddfpt_control%spinflip /= tddfpt_sf_col)) THEN
741 IF (admm_env%aux_exch_func == do_admm_aux_exch_func_none) THEN
742 ! nothing to do
743 ELSE
744 IF (.NOT. tddfpt_control%admm_symm) THEN
745 CALL cp_warn(__location__, "Forces need symmetric ADMM kernel corrections")
746 cpabort("ADMM KERNEL CORRECTION")
747 END IF
748 xc_section => admm_env%xc_section_aux
749 xc_fun_section => section_vals_get_subs_vals(xc_section, "XC_FUNCTIONAL")
750 needs = xc_functionals_get_needs(xc_fun_section, (nspins == 2), .true.)
751 needs_tau_response_aux = needs%tau .OR. needs%tau_spin
752 CALL get_admm_env(admm_env, rho_aux_fit=rho_aux_fit, matrix_s_aux_fit=matrix_s_aux_fit, &
753 task_list_aux_fit=task_list)
754 basis_type = "AUX_FIT"
755 IF (admm_env%do_gapw) THEN
756 basis_type = "AUX_FIT_SOFT"
757 task_list => admm_env%admm_gapw_env%task_list
758 END IF
759 !
760 NULLIFY (mfx, mgx)
761 CALL dbcsr_allocate_matrix_set(mfx, nsev)
762 CALL dbcsr_allocate_matrix_set(mgx, nspins)
763 DO ispin = 1, nsev
764 ALLOCATE (mfx(ispin)%matrix)
765 CALL dbcsr_create(mfx(ispin)%matrix, template=matrix_s_aux_fit(1)%matrix)
766 CALL dbcsr_copy(mfx(ispin)%matrix, matrix_s_aux_fit(1)%matrix)
767 CALL dbcsr_set(mfx(ispin)%matrix, 0.0_dp)
768 END DO
769 DO ispin = 1, nspins
770 ALLOCATE (mgx(ispin)%matrix)
771 CALL dbcsr_create(mgx(ispin)%matrix, template=matrix_s_aux_fit(1)%matrix)
772 CALL dbcsr_copy(mgx(ispin)%matrix, matrix_s_aux_fit(1)%matrix)
773 CALL dbcsr_set(mgx(ispin)%matrix, 0.0_dp)
774 END DO
775
776 ! ADMM density and response density
777 NULLIFY (rho_g_aux, rho_r_aux, rhox_g_aux, rhox_r_aux, rhox_tau_g_aux, rhox_tau_r_aux)
778 CALL qs_rho_get(rho_aux_fit, rho_r=rho_r_aux, rho_g=rho_g_aux)
779 CALL qs_rho_get(rho_aux_fit, rho_ao=matrix_p_admm)
780 ! rhox_aux
781 ALLOCATE (rhox_r_aux(nsev), rhox_g_aux(nsev))
782 DO ispin = 1, nsev
783 CALL auxbas_pw_pool%create_pw(rhox_r_aux(ispin))
784 CALL auxbas_pw_pool%create_pw(rhox_g_aux(ispin))
785 END DO
786 IF (needs_tau_response_aux) THEN
787 ALLOCATE (rhox_tau_r_aux(nsev), rhox_tau_g_aux(nsev))
788 DO ispin = 1, nsev
789 CALL auxbas_pw_pool%create_pw(rhox_tau_r_aux(ispin))
790 CALL auxbas_pw_pool%create_pw(rhox_tau_g_aux(ispin))
791 END DO
792 END IF
793 DO ispin = 1, nsev
794 CALL calculate_rho_elec(ks_env=ks_env, matrix_p=matrix_px1_admm(ispin)%matrix, &
795 rho=rhox_r_aux(ispin), rho_gspace=rhox_g_aux(ispin), &
796 basis_type=basis_type, &
797 task_list_external=task_list)
798 IF (needs_tau_response_aux) THEN
799 CALL calculate_rho_elec(ks_env=ks_env, matrix_p=matrix_px1_admm(ispin)%matrix, &
800 rho=rhox_tau_r_aux(ispin), &
801 rho_gspace=rhox_tau_g_aux(ispin), &
802 basis_type=basis_type, task_list_external=task_list, &
803 compute_tau=.true.)
804 END IF
805 END DO
806 !
807 NULLIFY (rhox_aux)
808 ALLOCATE (rhox_aux)
809 CALL qs_rho_create(rhox_aux)
810 IF (needs_tau_response_aux) THEN
811 CALL qs_rho_set(rho_struct=rhox_aux, rho_ao=matrix_px1_admm, &
812 rho_r=rhox_r_aux, rho_g=rhox_g_aux, &
813 tau_r=rhox_tau_r_aux, tau_g=rhox_tau_g_aux, &
814 rho_r_valid=.true., rho_g_valid=.true., &
815 tau_r_valid=.true., tau_g_valid=.true.)
816 ELSE
817 CALL qs_rho_set(rho_struct=rhox_aux, rho_ao=matrix_px1_admm, &
818 rho_r=rhox_r_aux, rho_g=rhox_g_aux, &
819 rho_r_valid=.true., rho_g_valid=.true.)
820 END IF
821 IF (do_analytic .AND. .NOT. do_numeric) THEN
822 cpabort("Analytic 3rd derivatives of EXC not available")
823 ELSEIF (do_numeric) THEN
824 IF (do_analytic) THEN
825 CALL qs_fgxc_gdiff(ks_env, rho_aux_fit, rhox_aux, xc_section, order, eps_delta, &
826 is_rks_triplets, weights, fxc_rho, fxc_tau, gxc_rho, gxc_tau)
827 ELSE
828 CALL qs_fgxc_create(ks_env, rho_aux_fit, rhox_aux, xc_section, &
829 order, is_rks_triplets, fxc_rho, fxc_tau, gxc_rho, gxc_tau)
830 END IF
831 ELSE
832 cpabort("FHXC forces analytic/numeric")
833 END IF
834
835 ! grid weight contribution to forces ADMM XC correction term
836 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
837 !
838 CALL accint_weight_force(qs_env, rho_aux_fit, rhox_aux, 2, xc_section, is_rks_triplets)
839 !
840 IF (debug_forces) THEN
841 fodeb(1:3) = force(1)%rho_elec(1:3, 1) - fodeb(1:3)
842 CALL para_env%sum(fodeb)
843 IF (iounit > 0) WRITE (iounit, "(T3,A,T33,3F16.8)") "DEBUG:: Dx_admm*fxc[Dx_admm]*dw", fodeb
844 END IF
845
846 ! Well, this is a hack :-(
847 ! When qs_rho_set() was called on rhox_aux it assumed ownership of the passed arrays.
848 ! However, these arrays actually belong to ex_env. Hence, we can not call qs_rho_release()
849 ! because this would release the arrays. Instead we're simply going to deallocate rhox_aux.
850 DEALLOCATE (rhox_aux)
851
852 DO ispin = 1, nsev
853 CALL auxbas_pw_pool%give_back_pw(rhox_r_aux(ispin))
854 CALL auxbas_pw_pool%give_back_pw(rhox_g_aux(ispin))
855 END DO
856 DEALLOCATE (rhox_r_aux, rhox_g_aux)
857 IF (needs_tau_response_aux) THEN
858 DO ispin = 1, nsev
859 CALL auxbas_pw_pool%give_back_pw(rhox_tau_r_aux(ispin))
860 CALL auxbas_pw_pool%give_back_pw(rhox_tau_g_aux(ispin))
861 END DO
862 DEALLOCATE (rhox_tau_r_aux, rhox_tau_g_aux)
863 END IF
864 fscal = 1.0_dp
865 IF (nspins == 2) fscal = 2.0_dp
866 !
867 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
868 DO ispin = 1, nsev
869 CALL pw_scale(fxc_rho(ispin), fxc_rho(ispin)%pw_grid%dvol)
870 CALL integrate_v_rspace(qs_env=qs_env, v_rspace=fxc_rho(ispin), &
871 hmat=mfx(ispin), &
872 pmat=matrix_px1_admm(ispin), &
873 basis_type=basis_type, &
874 calculate_forces=.true., &
875 force_adm=fscal, &
876 task_list_external=task_list)
877 END DO
878 IF (debug_forces) THEN
879 fodeb(1:3) = force(1)%rho_elec(1:3, 1) - fodeb(1:3)
880 CALL para_env%sum(fodeb)
881 IF (iounit > 0) WRITE (iounit, "(T3,A,T33,3F16.8)") "DEBUG:: Dx*dfxc[Dx]ADMM", fodeb
882 END IF
883
884 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
885 DO ispin = 1, nsev
886 CALL pw_scale(gxc_rho(ispin), gxc_rho(ispin)%pw_grid%dvol)
887 CALL pw_scale(gxc_rho(ispin), 0.5_dp)
888 CALL integrate_v_rspace(qs_env=qs_env, v_rspace=gxc_rho(ispin), &
889 hmat=mgx(ispin), &
890 pmat=matrix_p_admm(ispin), &
891 basis_type=basis_type, &
892 calculate_forces=.true., &
893 force_adm=fscal, &
894 task_list_external=task_list)
895 CALL dbcsr_scale(mgx(ispin)%matrix, 2.0_dp)
896 END DO
897 IF (debug_forces) THEN
898 fodeb(1:3) = force(1)%rho_elec(1:3, 1) - fodeb(1:3)
899 CALL para_env%sum(fodeb)
900 IF (iounit > 0) WRITE (iounit, "(T3,A,T33,3F16.8)") "DEBUG:: Dx*dgxc[Dx]ADMM", fodeb
901 END IF
902 CALL qs_fgxc_release(ks_env, fxc_rho, fxc_tau, gxc_rho, gxc_tau)
903 !
904 IF (admm_env%do_gapw) THEN
905 CALL get_admm_env(admm_env, sab_aux_fit=sab_aux_fit)
906 rho_atom_set => admm_env%admm_gapw_env%local_rho_set%rho_atom_set
907 rho_atom_set_f => local_rho_set_f_admm%rho_atom_set
908 rho_atom_set_g => local_rho_set_g_admm%rho_atom_set
909
910 IF (do_analytic .AND. .NOT. do_numeric) THEN
911 cpabort("Analytic 3rd EXC derivatives not available")
912 ELSEIF (do_numeric) THEN
913 IF (do_analytic) THEN
914 CALL gfxc_atom_diff(qs_env, rho_atom_set, &
915 rho_atom_set_f, rho_atom_set_g, &
916 admm_env%admm_gapw_env%admm_kind_set, xc_section, &
917 is_rks_triplets, order, eps_delta)
918 ELSE
919 CALL calculate_gfxc_atom(qs_env, rho_atom_set, &
920 rho_atom_set_f, rho_atom_set_g, &
921 admm_env%admm_gapw_env%admm_kind_set, xc_section, &
922 is_rks_triplets, order)
923 END IF
924 ELSE
925 cpabort("FHXC forces analytic/numeric")
926 END IF
927
928 IF (debug_forces) fodeb(1:3) = force(1)%Vhxc_atom(1:3, 1)
929 IF (nspins == 1) THEN
930 CALL update_ks_atom(qs_env, mfx, matrix_px1_admm, forces=.true., &
931 rho_atom_external=rho_atom_set_f, &
932 kind_set_external=admm_env%admm_gapw_env%admm_kind_set, &
933 oce_external=admm_env%admm_gapw_env%oce, sab_external=sab_aux_fit, &
934 kintegral=2.0_dp, kforce=0.5_dp)
935 ELSE
936 CALL update_ks_atom(qs_env, mfx, matrix_px1_admm, forces=.true., &
937 rho_atom_external=rho_atom_set_f, &
938 kind_set_external=admm_env%admm_gapw_env%admm_kind_set, &
939 oce_external=admm_env%admm_gapw_env%oce, sab_external=sab_aux_fit, &
940 kintegral=2.0_dp, kforce=1.0_dp)
941 END IF
942 IF (debug_forces) THEN
943 fodeb(1:3) = force(1)%Vhxc_atom(1:3, 1) - fodeb(1:3)
944 CALL para_env%sum(fodeb)
945 IF (iounit > 0) WRITE (iounit, "(T3,A,T33,3F16.8)") "DEBUG:: Dx*dfxc[Dx]ADMM-PAW ", fodeb
946 END IF
947 IF (debug_forces) fodeb(1:3) = force(1)%Vhxc_atom(1:3, 1)
948 IF (nspins == 1) THEN
949 CALL update_ks_atom(qs_env, mgx, matrix_p, forces=.true., &
950 rho_atom_external=rho_atom_set_g, &
951 kind_set_external=admm_env%admm_gapw_env%admm_kind_set, &
952 oce_external=admm_env%admm_gapw_env%oce, sab_external=sab_aux_fit, &
953 kintegral=1.0_dp, kforce=0.5_dp)
954 ELSE
955 CALL update_ks_atom(qs_env, mgx, matrix_p, forces=.true., &
956 rho_atom_external=rho_atom_set_g, &
957 kind_set_external=admm_env%admm_gapw_env%admm_kind_set, &
958 oce_external=admm_env%admm_gapw_env%oce, sab_external=sab_aux_fit, &
959 kintegral=1.0_dp, kforce=1.0_dp)
960 END IF
961 IF (debug_forces) THEN
962 fodeb(1:3) = force(1)%Vhxc_atom(1:3, 1) - fodeb(1:3)
963 CALL para_env%sum(fodeb)
964 IF (iounit > 0) WRITE (iounit, "(T3,A,T33,3F16.8)") "DEBUG:: Dx*dgxc[Dx]ADMM-PAW ", fodeb
965 END IF
966 END IF
967 !
968 ! A' fx A - Forces
969 !
970 IF (debug_forces) fodeb(1:3) = force(1)%overlap_admm(1:3, 1)
971 fval = 2.0_dp*real(nspins, kind=dp)
972 CALL admm_projection_derivative(qs_env, mfx, matrix_px1, fval)
973 IF (debug_forces) THEN
974 fodeb(1:3) = force(1)%overlap_admm(1:3, 1) - fodeb(1:3)
975 CALL para_env%sum(fodeb)
976 IF (iounit > 0) WRITE (iounit, "(T3,A,T33,3F16.8)") "DEBUG:: P*dfXC(P)*S' ", fodeb
977 END IF
978 IF (debug_forces) fodeb(1:3) = force(1)%overlap_admm(1:3, 1)
979 fval = 2.0_dp*real(nspins, kind=dp)
980 CALL admm_projection_derivative(qs_env, mgx, matrix_p, fval)
981 IF (debug_forces) THEN
982 fodeb(1:3) = force(1)%overlap_admm(1:3, 1) - fodeb(1:3)
983 CALL para_env%sum(fodeb)
984 IF (iounit > 0) WRITE (iounit, "(T3,A,T33,3F16.8)") "DEBUG:: P*dgXC(P)*S' ", fodeb
985 END IF
986 !
987 ! Add ADMM fx/gx to the full basis fx/gx
988 fscal = 1.0_dp
989 IF (nspins == 2) fscal = 2.0_dp
990 nao = admm_env%nao_orb
991 nao_aux = admm_env%nao_aux_fit
992 ALLOCATE (dbwork)
993 CALL dbcsr_create(dbwork, template=matrix_fx(1)%matrix)
994 DO ispin = 1, nsev
995 ! fx
996 CALL cp_dbcsr_sm_fm_multiply(mfx(ispin)%matrix, admm_env%A, &
997 admm_env%work_aux_orb, nao)
998 CALL parallel_gemm('T', 'N', nao, nao, nao_aux, &
999 1.0_dp, admm_env%A, admm_env%work_aux_orb, 0.0_dp, &
1000 admm_env%work_orb_orb)
1001 CALL dbcsr_copy(dbwork, matrix_fx(1)%matrix)
1002 CALL dbcsr_set(dbwork, 0.0_dp)
1003 CALL copy_fm_to_dbcsr(admm_env%work_orb_orb, dbwork, keep_sparsity=.true.)
1004 CALL dbcsr_add(matrix_fx(ispin)%matrix, dbwork, 1.0_dp, fscal)
1005 ! gx
1006 CALL cp_dbcsr_sm_fm_multiply(mgx(ispin)%matrix, admm_env%A, &
1007 admm_env%work_aux_orb, nao)
1008 CALL parallel_gemm('T', 'N', nao, nao, nao_aux, &
1009 1.0_dp, admm_env%A, admm_env%work_aux_orb, 0.0_dp, &
1010 admm_env%work_orb_orb)
1011 CALL dbcsr_set(dbwork, 0.0_dp)
1012 CALL copy_fm_to_dbcsr(admm_env%work_orb_orb, dbwork, keep_sparsity=.true.)
1013 CALL dbcsr_add(matrix_gx(ispin)%matrix, dbwork, 1.0_dp, fscal)
1014 END DO
1015 CALL dbcsr_release(dbwork)
1016 DEALLOCATE (dbwork)
1019
1020 END IF
1021 END IF
1022
1023 DO ispin = 1, nsev
1024 CALL auxbas_pw_pool%give_back_pw(rhox_r(ispin))
1025 CALL auxbas_pw_pool%give_back_pw(rhox_g(ispin))
1026 END DO
1027 DEALLOCATE (rhox_r, rhox_g)
1028 IF (needs_tau_response) THEN
1029 DO ispin = 1, nsev
1030 CALL auxbas_pw_pool%give_back_pw(rhox_tau_r(ispin))
1031 CALL auxbas_pw_pool%give_back_pw(rhox_tau_g(ispin))
1032 END DO
1033 DEALLOCATE (rhox_tau_r, rhox_tau_g)
1034 END IF
1035 CALL auxbas_pw_pool%give_back_pw(rhox_tot_gspace)
1036 IF (gapw_xc) THEN
1037 DO ispin = 1, nsev
1038 CALL auxbas_pw_pool%give_back_pw(rhoxx_r(ispin))
1039 CALL auxbas_pw_pool%give_back_pw(rhoxx_g(ispin))
1040 END DO
1041 DEALLOCATE (rhoxx_r, rhoxx_g)
1042 IF (needs_tau_response) THEN
1043 DO ispin = 1, nsev
1044 CALL auxbas_pw_pool%give_back_pw(rhoxx_tau_r(ispin))
1045 CALL auxbas_pw_pool%give_back_pw(rhoxx_tau_g(ispin))
1046 END DO
1047 DEALLOCATE (rhoxx_tau_r, rhoxx_tau_g)
1048 END IF
1049 END IF
1050 IF (.NOT. (is_rks_triplets .OR. do_sf)) THEN
1051 CALL auxbas_pw_pool%give_back_pw(xv_hartree_rspace)
1052 CALL auxbas_pw_pool%give_back_pw(xv_hartree_gspace)
1053 END IF
1054
1055 ! HFX
1056 IF (do_hfx) THEN
1057 NULLIFY (matrix_hfx, matrix_hfx_asymm)
1058 CALL dbcsr_allocate_matrix_set(matrix_hfx, nsev)
1059 CALL dbcsr_allocate_matrix_set(matrix_hfx_asymm, nsev)
1060 DO ispin = 1, nsev
1061 ALLOCATE (matrix_hfx(ispin)%matrix)
1062 CALL dbcsr_create(matrix_hfx(ispin)%matrix, template=matrix_s(1)%matrix)
1063 CALL dbcsr_copy(matrix_hfx(ispin)%matrix, matrix_s(1)%matrix)
1064 CALL dbcsr_set(matrix_hfx(ispin)%matrix, 0.0_dp)
1065
1066 ALLOCATE (matrix_hfx_asymm(ispin)%matrix)
1067 CALL dbcsr_create(matrix_hfx_asymm(ispin)%matrix, template=matrix_s(1)%matrix, &
1068 matrix_type=dbcsr_type_antisymmetric)
1069 CALL dbcsr_complete_redistribute(matrix_hfx(ispin)%matrix, matrix_hfx_asymm(ispin)%matrix)
1070 END DO
1071 !
1072 xc_section => full_kernel%xc_section
1073 hfx_section => section_vals_get_subs_vals(xc_section, "HF")
1074 CALL section_vals_get(hfx_section, n_repetition=n_rep_hf)
1075 cpassert(n_rep_hf == 1)
1076 CALL section_vals_val_get(hfx_section, "TREAT_LSD_IN_CORE", l_val=hfx_treat_lsd_in_core, &
1077 i_rep_section=1)
1078 mspin = 1
1079 IF (hfx_treat_lsd_in_core) mspin = nsev
1080 !
1081 CALL get_qs_env(qs_env=qs_env, x_data=x_data, s_mstruct_changed=s_mstruct_changed)
1082 distribute_fock_matrix = .true.
1083 !
1084 IF (do_admm) THEN
1085 CALL get_admm_env(qs_env%admm_env, matrix_s_aux_fit=matrix_s_aux_fit)
1086 NULLIFY (matrix_hfx_admm, matrix_hfx_admm_asymm)
1087 CALL dbcsr_allocate_matrix_set(matrix_hfx_admm, nsev)
1088 CALL dbcsr_allocate_matrix_set(matrix_hfx_admm_asymm, nsev)
1089 DO ispin = 1, nsev
1090 ALLOCATE (matrix_hfx_admm(ispin)%matrix)
1091 CALL dbcsr_create(matrix_hfx_admm(ispin)%matrix, template=matrix_s_aux_fit(1)%matrix)
1092 CALL dbcsr_copy(matrix_hfx_admm(ispin)%matrix, matrix_s_aux_fit(1)%matrix)
1093 CALL dbcsr_set(matrix_hfx_admm(ispin)%matrix, 0.0_dp)
1094
1095 ALLOCATE (matrix_hfx_admm_asymm(ispin)%matrix)
1096 CALL dbcsr_create(matrix_hfx_admm_asymm(ispin)%matrix, template=matrix_s_aux_fit(1)%matrix, &
1097 matrix_type=dbcsr_type_antisymmetric)
1098 CALL dbcsr_complete_redistribute(matrix_hfx_admm(ispin)%matrix, matrix_hfx_admm_asymm(ispin)%matrix)
1099 END DO
1100 !
1101 NULLIFY (mpe, mhe)
1102 ALLOCATE (mpe(nsev, 1), mhe(nsev, 1))
1103 DO ispin = 1, nsev
1104 mhe(ispin, 1)%matrix => matrix_hfx_admm(ispin)%matrix
1105 mpe(ispin, 1)%matrix => matrix_px1_admm(ispin)%matrix
1106 END DO
1107 IF (x_data(1, 1)%do_hfx_ri) THEN
1108 eh1 = 0.0_dp
1109 CALL hfx_ri_update_ks(qs_env, x_data(1, 1)%ri_data, mhe, eh1, rho_ao=mpe, &
1110 geometry_did_change=s_mstruct_changed, nspins=nspins, &
1111 hf_fraction=x_data(1, 1)%general_parameter%fraction)
1112 ELSE
1113 DO ispin = 1, mspin
1114 eh1 = 0.0
1115 CALL integrate_four_center(qs_env, x_data, mhe, eh1, mpe, hfx_section, &
1116 para_env, s_mstruct_changed, 1, distribute_fock_matrix, &
1117 ispin=ispin, nspins=nsev)
1118 END DO
1119 END IF
1120 !anti-symmetric density
1121 DO ispin = 1, nsev
1122 mhe(ispin, 1)%matrix => matrix_hfx_admm_asymm(ispin)%matrix
1123 mpe(ispin, 1)%matrix => matrix_px1_admm_asymm(ispin)%matrix
1124 END DO
1125 IF (x_data(1, 1)%do_hfx_ri) THEN
1126 eh1 = 0.0_dp
1127 CALL hfx_ri_update_ks(qs_env, x_data(1, 1)%ri_data, mhe, eh1, rho_ao=mpe, &
1128 geometry_did_change=s_mstruct_changed, nspins=nspins, &
1129 hf_fraction=x_data(1, 1)%general_parameter%fraction)
1130 ELSE
1131 DO ispin = 1, mspin
1132 eh1 = 0.0
1133 CALL integrate_four_center(qs_env, x_data, mhe, eh1, mpe, hfx_section, &
1134 para_env, s_mstruct_changed, 1, distribute_fock_matrix, &
1135 ispin=ispin, nspins=nsev)
1136 END DO
1137 END IF
1138 !
1139 nao = admm_env%nao_orb
1140 nao_aux = admm_env%nao_aux_fit
1141 ALLOCATE (dbwork, dbwork_asymm)
1142 CALL dbcsr_create(dbwork, template=matrix_hfx(1)%matrix)
1143 CALL dbcsr_create(dbwork_asymm, template=matrix_hfx(1)%matrix, matrix_type=dbcsr_type_antisymmetric)
1144 DO ispin = 1, nsev
1145 CALL cp_dbcsr_sm_fm_multiply(matrix_hfx_admm(ispin)%matrix, admm_env%A, &
1146 admm_env%work_aux_orb, nao)
1147 CALL parallel_gemm('T', 'N', nao, nao, nao_aux, &
1148 1.0_dp, admm_env%A, admm_env%work_aux_orb, 0.0_dp, &
1149 admm_env%work_orb_orb)
1150 CALL dbcsr_copy(dbwork, matrix_hfx(1)%matrix)
1151 CALL dbcsr_set(dbwork, 0.0_dp)
1152 CALL copy_fm_to_dbcsr(admm_env%work_orb_orb, dbwork, keep_sparsity=.true.)
1153 CALL dbcsr_add(matrix_hfx(ispin)%matrix, dbwork, 1.0_dp, 1.0_dp)
1154 !anti-symmetric case
1155 CALL cp_dbcsr_sm_fm_multiply(matrix_hfx_admm_asymm(ispin)%matrix, admm_env%A, &
1156 admm_env%work_aux_orb, nao)
1157 CALL parallel_gemm('T', 'N', nao, nao, nao_aux, &
1158 1.0_dp, admm_env%A, admm_env%work_aux_orb, 0.0_dp, &
1159 admm_env%work_orb_orb)
1160 CALL dbcsr_copy(dbwork_asymm, matrix_hfx_asymm(1)%matrix)
1161 CALL dbcsr_set(dbwork_asymm, 0.0_dp)
1162 CALL copy_fm_to_dbcsr(admm_env%work_orb_orb, dbwork_asymm, keep_sparsity=.true.)
1163 CALL dbcsr_add(matrix_hfx_asymm(ispin)%matrix, dbwork_asymm, 1.0_dp, 1.0_dp)
1164 END DO
1165 CALL dbcsr_release(dbwork)
1166 CALL dbcsr_release(dbwork_asymm)
1167 DEALLOCATE (dbwork, dbwork_asymm)
1168 ! forces
1169 ! ADMM Projection force
1170 IF (debug_forces) fodeb(1:3) = force(1)%overlap_admm(1:3, 1)
1171 fval = 4.0_dp*real(nspins, kind=dp)*0.5_dp !0.5 for symm/anti-symm
1172 CALL admm_projection_derivative(qs_env, matrix_hfx_admm, matrix_px1, fval)
1173 CALL admm_projection_derivative(qs_env, matrix_hfx_admm_asymm, matrix_px1_asymm, fval)
1174 IF (debug_forces) THEN
1175 fodeb(1:3) = force(1)%overlap_admm(1:3, 1) - fodeb(1:3)
1176 CALL para_env%sum(fodeb)
1177 IF (iounit > 0) WRITE (iounit, "(T3,A,T33,3F16.8)") "DEBUG:: P*Hx(P)*S' ", fodeb
1178 END IF
1179 !
1180 use_virial = .false.
1181 NULLIFY (mdum)
1182 fval = 2.0_dp*real(nspins, kind=dp)*0.5_dp !0.5 factor because of symemtry/anti-symmetry
1183 ! For SF TDDFT integrate_four_center and derivatives_four_center routines introduce a factor of 1/2
1184 IF (do_sf) fval = fval*2.0_dp
1185 IF (debug_forces) fodeb(1:3) = force(1)%fock_4c(1:3, 1)
1186 DO ispin = 1, nsev
1187 mpe(ispin, 1)%matrix => matrix_px1_admm(ispin)%matrix
1188 END DO
1189 IF (x_data(1, 1)%do_hfx_ri) THEN
1190 CALL hfx_ri_update_forces(qs_env, x_data(1, 1)%ri_data, nspins, &
1191 x_data(1, 1)%general_parameter%fraction, &
1192 rho_ao=mpe, rho_ao_resp=mdum, &
1193 use_virial=use_virial, rescale_factor=fval)
1194 ELSE
1195 CALL derivatives_four_center(qs_env, mpe, mdum, hfx_section, para_env, 1, use_virial, &
1196 adiabatic_rescale_factor=fval, nspins=nsev)
1197 END IF
1198 DO ispin = 1, nsev
1199 mpe(ispin, 1)%matrix => matrix_px1_admm_asymm(ispin)%matrix
1200 END DO
1201 IF (x_data(1, 1)%do_hfx_ri) THEN
1202 CALL hfx_ri_update_forces(qs_env, x_data(1, 1)%ri_data, nspins, &
1203 x_data(1, 1)%general_parameter%fraction, &
1204 rho_ao=mpe, rho_ao_resp=mdum, &
1205 use_virial=use_virial, rescale_factor=fval)
1206 ELSE
1207 CALL derivatives_four_center(qs_env, mpe, mdum, hfx_section, para_env, 1, use_virial, &
1208 adiabatic_rescale_factor=fval, nspins=SIZE(mpe, 1))
1209 END IF
1210 IF (debug_forces) THEN
1211 fodeb(1:3) = force(1)%fock_4c(1:3, 1) - fodeb(1:3)
1212 CALL para_env%sum(fodeb)
1213 IF (iounit > 0) WRITE (iounit, "(T3,A,T33,3F16.8)") "DEBUG:: Dx*dhfx'*Dx ", fodeb
1214 END IF
1215 !
1216 DEALLOCATE (mpe, mhe)
1217 !
1218 CALL dbcsr_deallocate_matrix_set(matrix_hfx_admm)
1219 CALL dbcsr_deallocate_matrix_set(matrix_hfx_admm_asymm)
1220 ELSE
1221 NULLIFY (mpe, mhe)
1222 ALLOCATE (mpe(nsev, 1), mhe(nsev, 1))
1223 DO ispin = 1, nsev
1224 mhe(ispin, 1)%matrix => matrix_hfx(ispin)%matrix
1225 mpe(ispin, 1)%matrix => matrix_px1(ispin)%matrix
1226 END DO
1227 IF (x_data(1, 1)%do_hfx_ri) THEN
1228 eh1 = 0.0_dp
1229 CALL hfx_ri_update_ks(qs_env, x_data(1, 1)%ri_data, mhe, eh1, rho_ao=mpe, &
1230 geometry_did_change=s_mstruct_changed, nspins=nspins, &
1231 hf_fraction=x_data(1, 1)%general_parameter%fraction)
1232 ELSE
1233 DO ispin = 1, mspin
1234 eh1 = 0.0
1235 CALL integrate_four_center(qs_env, x_data, mhe, eh1, mpe, hfx_section, &
1236 para_env, s_mstruct_changed, 1, distribute_fock_matrix, &
1237 ispin=ispin, nspins=SIZE(mpe, 1))
1238 END DO
1239 END IF
1240
1241 !anti-symmetric density matrix
1242 DO ispin = 1, nsev
1243 mhe(ispin, 1)%matrix => matrix_hfx_asymm(ispin)%matrix
1244 mpe(ispin, 1)%matrix => matrix_px1_asymm(ispin)%matrix
1245 END DO
1246 IF (x_data(1, 1)%do_hfx_ri) THEN
1247 eh1 = 0.0_dp
1248 CALL hfx_ri_update_ks(qs_env, x_data(1, 1)%ri_data, mhe, eh1, rho_ao=mpe, &
1249 geometry_did_change=s_mstruct_changed, nspins=nspins, &
1250 hf_fraction=x_data(1, 1)%general_parameter%fraction)
1251 ELSE
1252 DO ispin = 1, mspin
1253 eh1 = 0.0
1254 CALL integrate_four_center(qs_env, x_data, mhe, eh1, mpe, hfx_section, &
1255 para_env, s_mstruct_changed, 1, distribute_fock_matrix, &
1256 ispin=ispin, nspins=SIZE(mpe, 1))
1257 END DO
1258 END IF
1259 ! forces
1260 use_virial = .false.
1261 NULLIFY (mdum)
1262 fval = 2.0_dp*real(nspins, kind=dp)*0.5_dp !extra 0.5 factor because of symmetry/antisymemtry
1263 ! For SF TDDFT integrate_four_center and derivatives_four_center routines introduce a factor of 1/2
1264 IF (do_sf) fval = fval*2.0_dp
1265 IF (debug_forces) fodeb(1:3) = force(1)%fock_4c(1:3, 1)
1266 DO ispin = 1, nsev
1267 mpe(ispin, 1)%matrix => matrix_px1(ispin)%matrix
1268 END DO
1269 IF (x_data(1, 1)%do_hfx_ri) THEN
1270 CALL hfx_ri_update_forces(qs_env, x_data(1, 1)%ri_data, nspins, &
1271 x_data(1, 1)%general_parameter%fraction, &
1272 rho_ao=mpe, rho_ao_resp=mdum, &
1273 use_virial=use_virial, rescale_factor=fval)
1274 ELSE
1275 CALL derivatives_four_center(qs_env, mpe, mdum, hfx_section, para_env, 1, use_virial, &
1276 adiabatic_rescale_factor=fval, nspins=SIZE(mpe, 1))
1277 END IF
1278 DO ispin = 1, nsev
1279 mpe(ispin, 1)%matrix => matrix_px1_asymm(ispin)%matrix
1280 END DO
1281 IF (x_data(1, 1)%do_hfx_ri) THEN
1282 CALL hfx_ri_update_forces(qs_env, x_data(1, 1)%ri_data, nspins, &
1283 x_data(1, 1)%general_parameter%fraction, &
1284 rho_ao=mpe, rho_ao_resp=mdum, &
1285 use_virial=use_virial, rescale_factor=fval)
1286 ELSE
1287 CALL derivatives_four_center(qs_env, mpe, mdum, hfx_section, para_env, 1, use_virial, &
1288 adiabatic_rescale_factor=fval, nspins=SIZE(mpe, 1))
1289 END IF
1290 IF (debug_forces) THEN
1291 fodeb(1:3) = force(1)%fock_4c(1:3, 1) - fodeb(1:3)
1292 CALL para_env%sum(fodeb)
1293 IF (iounit > 0) WRITE (iounit, "(T3,A,T33,3F16.8)") "DEBUG:: Dx*dhfx*Dx ", fodeb
1294 END IF
1295 !
1296 DEALLOCATE (mpe, mhe)
1297 END IF
1298 fval = 2.0_dp*real(nspins, kind=dp)*0.5_dp !extra 0.5 because of symm/antisymm
1299 ! For SF TDDFT integrate_four_center and derivatives_four_center routines introduce a factor of 1/2
1300 IF (do_sf) fval = fval*2.0_dp
1301 DO ispin = 1, nsev
1302 CALL dbcsr_scale(matrix_hfx(ispin)%matrix, fval)
1303 CALL dbcsr_scale(matrix_hfx_asymm(ispin)%matrix, fval)
1304 END DO
1305 END IF
1306
1307 IF (gapw .OR. gapw_xc) THEN
1308 CALL local_rho_set_release(local_rho_set)
1309 CALL local_rho_set_release(local_rho_set_f)
1310 CALL local_rho_set_release(local_rho_set_g)
1311 IF (gapw) THEN
1312 CALL hartree_local_release(hartree_local)
1313 END IF
1314 END IF
1315 IF (do_admm) THEN
1316 IF (admm_env%do_gapw) THEN
1317 IF (tddfpt_control%admm_xc_correction) THEN
1318 IF (qs_env%admm_env%aux_exch_func /= do_admm_aux_exch_func_none) THEN
1319 CALL local_rho_set_release(local_rho_set_admm)
1320 CALL local_rho_set_release(local_rho_set_f_admm)
1321 CALL local_rho_set_release(local_rho_set_g_admm)
1322 END IF
1323 END IF
1324 END IF
1325 END IF
1326
1327 ! HFX short range
1328 IF (do_hfxsr) THEN
1329 cpabort("HFXSR not implemented")
1330 END IF
1331 ! HFX long range
1332 IF (do_hfxlr) THEN
1333 cpabort("HFXLR not implemented")
1334 END IF
1335
1336 CALL get_qs_env(qs_env, sab_orb=sab_orb)
1337 NULLIFY (matrix_wx1)
1338 CALL dbcsr_allocate_matrix_set(matrix_wx1, nspins)
1339 cpmos => ex_env%cpmos
1340 focc = 2.0_dp
1341 IF (nspins == 2) focc = 1.0_dp
1342
1343 ! Initialize mos and dimensions of occupied space
1344 ! In the following comments mos is referred to as Ca and mos2 as Cb
1345 spin = 1
1346 mos => gs_mos(1)%mos_occ
1347 mosa => gs_mos(1)%mos_active
1348 norb(1) = gs_mos(1)%nmo_occ
1349 nactive(1) = gs_mos(1)%nmo_active
1350 IF (nspins == 2) THEN
1351 mos2 => gs_mos(2)%mos_occ
1352 mosa2 => gs_mos(2)%mos_active
1353 norb(2) = gs_mos(2)%nmo_occ
1354 nactive(2) = gs_mos(2)%nmo_active
1355 END IF
1356 ! Build response vector, Eq. 49, and the third term of \Lamda_munu, Eq. 51
1357 DO ispin = 1, nspins
1358
1359 IF (nactive(ispin) == norb(ispin)) THEN
1360 do_res = .false.
1361 DO ia = 1, nactive(ispin)
1362 cpassert(ia == gs_mos(ispin)%index_active(ia))
1363 END DO
1364 ELSE
1365 do_res = .true.
1366 END IF
1367
1368 ! Initialize mos and dimensions of occupied space
1369 IF (.NOT. do_sf) THEN
1370 spin = ispin
1371 mos => gs_mos(ispin)%mos_occ
1372 mos2 => gs_mos(ispin)%mos_occ
1373 mosa => gs_mos(ispin)%mos_active
1374 mosa2 => gs_mos(ispin)%mos_active
1375 END IF
1376
1377 ! Create working fields for the response vector
1378 CALL cp_fm_create(cpscr, gs_mos(ispin)%mos_active%matrix_struct, "cpscr", set_zero=.true.)
1379 !
1380 CALL cp_fm_get_info(gs_mos(ispin)%mos_occ, matrix_struct=fm_struct, nrow_global=nao)
1381 !
1382 CALL cp_fm_create(avamat, fm_struct, nrow=nactive(spin), ncol=nactive(spin))
1383 CALL cp_fm_create(avcmat, fm_struct, nrow=nactive(spin), ncol=norb(spin))
1384 CALL cp_fm_create(cvcmat, fm_struct, nrow=norb(spin), ncol=norb(spin))
1385 !
1386 CALL cp_fm_create(vcvec, gs_mos(ispin)%mos_occ%matrix_struct, "vcvec")
1387 CALL cp_fm_create(vavec, gs_mos(ispin)%mos_active%matrix_struct, "vavec")
1388
1389 ! Allocate and initialize the Lambda matrix
1390 ALLOCATE (matrix_wx1(ispin)%matrix)
1391 CALL dbcsr_create(matrix=matrix_wx1(ispin)%matrix, template=matrix_s(1)%matrix)
1392 CALL cp_dbcsr_alloc_block_from_nbl(matrix_wx1(ispin)%matrix, sab_orb)
1393 CALL dbcsr_set(matrix_wx1(ispin)%matrix, 0.0_dp)
1394
1395 ! Add Hartree contributions to the perturbation vector
1396 IF (.NOT. (is_rks_triplets .OR. do_sf)) THEN
1397 CALL cp_dbcsr_sm_fm_multiply(matrix_hx(ispin)%matrix, evect(ispin), &
1398 cpscr, nactive(ispin), alpha=focc, beta=1.0_dp)
1399 CALL cp_dbcsr_sm_fm_multiply(matrix_hx(ispin)%matrix, mos, vcvec, norb(ispin), &
1400 alpha=1.0_dp, beta=0.0_dp)
1401 CALL parallel_gemm("T", "N", nactive(ispin), norb(ispin), nao, 1.0_dp, &
1402 mosa, vcvec, 0.0_dp, avcmat)
1403 CALL parallel_gemm("N", "N", nao, norb(ispin), nactive(ispin), 1.0_dp, &
1404 evect(ispin), avcmat, 0.0_dp, vcvec)
1405 CALL cp_dbcsr_sm_fm_multiply(matrix_s(1)%matrix, vcvec, cpmos(ispin), norb(ispin), alpha=-focc, beta=1.0_dp)
1406 !
1407 CALL cp_dbcsr_plus_fm_fm_t(matrix_wx1(ispin)%matrix, matrix_v=mos, matrix_g=vcvec, &
1408 ncol=norb(ispin), alpha=2.0_dp, symmetry_mode=1)
1409 END IF
1410 ! Add exchange-correlation kernel and exchange-correlation kernel derivative contributions to the response vector
1411 IF ((myfun /= xc_none) .AND. (tddfpt_control%spinflip /= tddfpt_sf_col)) THEN
1412
1413 ! XC Kernel contributions
1414 ! For spin-flip excitations this is the only contribution to the alpha response vector
1415 IF (.NOT. (do_sf .AND. (ispin == 2))) THEN
1416 ! F*X
1417 CALL cp_dbcsr_sm_fm_multiply(matrix_fx(spin)%matrix, evect(spin), &
1418 cpscr, nactive(ispin), alpha=focc, beta=1.0_dp)
1419 END IF
1420 ! For spin-flip excitations this is the only contribution to the beta response vector
1421 IF (.NOT. (do_sf .AND. (ispin == 1))) THEN
1422 ! F*Cb
1423 CALL cp_dbcsr_sm_fm_multiply(matrix_fx(spin)%matrix, mos2, vcvec, &
1424 norb(ispin), alpha=1.0_dp, beta=0.0_dp)
1425 ! Ca^T*F*Cb
1426 CALL parallel_gemm("T", "N", nactive(spin), norb(ispin), nao, 1.0_dp, &
1427 mosa, vcvec, 0.0_dp, avcmat)
1428 ! X*Ca^T*F*Cb
1429 CALL parallel_gemm("N", "N", nao, norb(ispin), nactive(spin), 1.0_dp, &
1430 evect(spin), avcmat, 0.0_dp, vcvec)
1431 ! -S*X*Ca^T*F*Cb
1432 CALL cp_dbcsr_sm_fm_multiply(matrix_s(1)%matrix, vcvec, cpmos(ispin), &
1433 norb(ispin), alpha=-focc, beta=1.0_dp)
1434 ! Add contributions to the \Lambda_munu for the perturbed overlap matrix term, third term of Eq. 51
1435 ! 2X*Ca^T*F*Cb*Cb^T
1436 CALL cp_dbcsr_plus_fm_fm_t(matrix_wx1(ispin)%matrix, matrix_v=vcvec, matrix_g=gs_mos(ispin)%mos_occ, &
1437 ncol=norb(ispin), alpha=2.0_dp, symmetry_mode=1)
1438 END IF
1439 !
1440
1441 ! XC g (third functional derivative) contributions
1442 ! g*Ca*focc
1443 CALL cp_dbcsr_sm_fm_multiply(matrix_gx(ispin)%matrix, gs_mos(ispin)%mos_occ, &
1444 cpmos(ispin), norb(ispin), alpha=focc, beta=1.0_dp)
1445 ! Add contributions to the \Lambda_munu for the perturbed overlap matrix term, third term of Eq. 51
1446 ! g*Ca
1447 CALL cp_dbcsr_sm_fm_multiply(matrix_gx(ispin)%matrix, gs_mos(ispin)%mos_occ, vcvec, norb(ispin), &
1448 alpha=1.0_dp, beta=0.0_dp)
1449 ! Ca^T*g*Ca
1450 CALL parallel_gemm("T", "N", norb(ispin), norb(ispin), nao, 1.0_dp, gs_mos(ispin)%mos_occ, vcvec, 0.0_dp, cvcmat)
1451 ! Ca*Ca^T*g*Ca
1452 CALL parallel_gemm("N", "N", nao, norb(ispin), norb(ispin), 1.0_dp, gs_mos(ispin)%mos_occ, cvcmat, 0.0_dp, vcvec)
1453 ! Ca*Ca^T*g*Ca*Ca^T
1454 CALL cp_dbcsr_plus_fm_fm_t(matrix_wx1(ispin)%matrix, matrix_v=vcvec, matrix_g=gs_mos(ispin)%mos_occ, &
1455 ncol=norb(ispin), alpha=1.0_dp, symmetry_mode=1)
1456 !
1457 END IF
1458 ! Add Fock contributions to the response vector
1459 IF (do_hfx) THEN
1460 ! For spin-flip excitations this is the only contribution to the alpha response vector
1461 IF (.NOT. (do_sf .AND. (ispin == 2))) THEN
1462 ! F^sym*X
1463 CALL cp_dbcsr_sm_fm_multiply(matrix_hfx(spin)%matrix, evect(spin), &
1464 cpscr, nactive(spin), alpha=focc, beta=1.0_dp)
1465 ! F^asym*X
1466 CALL cp_dbcsr_sm_fm_multiply(matrix_hfx_asymm(spin)%matrix, evect(spin), &
1467 cpscr, nactive(spin), alpha=focc, beta=1.0_dp)
1468 END IF
1469
1470 ! For spin-flip excitations this is the only contribution to the beta response vector
1471 IF (.NOT. (do_sf .AND. (ispin == 1))) THEN
1472 ! F^sym*Cb
1473 CALL cp_dbcsr_sm_fm_multiply(matrix_hfx(spin)%matrix, mos2, vcvec, norb(ispin), &
1474 alpha=1.0_dp, beta=0.0_dp)
1475 ! -F^asym*Cb
1476 CALL cp_dbcsr_sm_fm_multiply(matrix_hfx_asymm(spin)%matrix, mos2, vcvec, norb(ispin), &
1477 alpha=1.0_dp, beta=1.0_dp)
1478 ! Ca^T*F*Cb
1479 CALL parallel_gemm("T", "N", nactive(spin), norb(ispin), nao, 1.0_dp, &
1480 mosa, vcvec, 0.0_dp, avcmat)
1481 ! X*Ca^T*F*Cb
1482 CALL parallel_gemm("N", "N", nao, norb(ispin), nactive(spin), 1.0_dp, &
1483 evect(spin), avcmat, 0.0_dp, vcvec)
1484 ! -S*X*Ca^T*F*Cb
1485 CALL cp_dbcsr_sm_fm_multiply(matrix_s(1)%matrix, vcvec, cpmos(ispin), &
1486 norb(ispin), alpha=-focc, beta=1.0_dp)
1487 ! Add contributions to the \Lambda_munu for the perturbed overlap matrix term, third term of Eq. 51
1488 ! 2X*Ca^T*F*Cb*Cb^T
1489 CALL cp_dbcsr_plus_fm_fm_t(matrix_wx1(ispin)%matrix, matrix_v=vcvec, matrix_g=mos2, &
1490 ncol=norb(ispin), alpha=2.0_dp, symmetry_mode=1)
1491 END IF
1492 END IF
1493 !
1494 IF (do_res) THEN
1495 DO ia = 1, nactive(ispin)
1496 ib = gs_mos(ispin)%index_active(ia)
1497 CALL cp_fm_add_columns(cpscr, cpmos(ispin), 1, 1.0_dp, ia, ib)
1498 END DO
1499 ELSE
1500 CALL cp_fm_geadd(1.0_dp, "N", cpscr, 1.0_dp, cpmos(ispin))
1501 END IF
1502 !
1503 CALL cp_fm_release(cpscr)
1504 CALL cp_fm_release(avamat)
1505 CALL cp_fm_release(avcmat)
1506 CALL cp_fm_release(cvcmat)
1507 CALL cp_fm_release(vcvec)
1508 CALL cp_fm_release(vavec)
1509 END DO
1510
1511 IF (.NOT. (is_rks_triplets .OR. do_sf)) THEN
1512 CALL dbcsr_deallocate_matrix_set(matrix_hx)
1513 END IF
1514 IF (ASSOCIATED(ex_env%matrix_wx1)) CALL dbcsr_deallocate_matrix_set(ex_env%matrix_wx1)
1515 ex_env%matrix_wx1 => matrix_wx1
1516 IF (.NOT. ((myfun == xc_none) .OR. (tddfpt_control%spinflip == tddfpt_sf_col))) THEN
1517 CALL dbcsr_deallocate_matrix_set(matrix_fx)
1518 CALL dbcsr_deallocate_matrix_set(matrix_gx)
1519 END IF
1520 IF (do_hfx) THEN
1521 CALL dbcsr_deallocate_matrix_set(matrix_hfx)
1522 CALL dbcsr_deallocate_matrix_set(matrix_hfx_asymm)
1523 END IF
1524
1525 CALL timestop(handle)
1526
1527 END SUBROUTINE fhxc_force
1528
1529! **************************************************************************************************
1530!> \brief Simplified Tamm Dancoff approach (sTDA). Kernel contribution to forces
1531!> \param qs_env ...
1532!> \param ex_env ...
1533!> \param gs_mos ...
1534!> \param stda_env ...
1535!> \param sub_env ...
1536!> \param work ...
1537!> \param debug_forces ...
1538! **************************************************************************************************
1539 SUBROUTINE stda_force(qs_env, ex_env, gs_mos, stda_env, sub_env, work, debug_forces)
1540
1541 TYPE(qs_environment_type), POINTER :: qs_env
1542 TYPE(excited_energy_type), POINTER :: ex_env
1543 TYPE(tddfpt_ground_state_mos), DIMENSION(:), &
1544 POINTER :: gs_mos
1545 TYPE(stda_env_type), POINTER :: stda_env
1546 TYPE(tddfpt_subgroup_env_type) :: sub_env
1547 TYPE(tddfpt_work_matrices) :: work
1548 LOGICAL, INTENT(IN) :: debug_forces
1549
1550 CHARACTER(len=*), PARAMETER :: routinen = 'stda_force'
1551
1552 INTEGER :: atom_i, atom_j, ewald_type, handle, i, &
1553 ia, iatom, idimk, ikind, iounit, is, &
1554 ispin, jatom, jkind, jspin, nao, &
1555 natom, norb, nsgf, nspins
1556 INTEGER, ALLOCATABLE, DIMENSION(:) :: atom_of_kind, first_sgf, kind_of, &
1557 last_sgf
1558 INTEGER, DIMENSION(2) :: nactive, nlim
1559 LOGICAL :: calculate_forces, do_coulomb, do_ewald, &
1560 found, is_rks_triplets, use_virial
1561 REAL(kind=dp) :: alpha, bp, dgabr, dr, eta, fdim, gabr, &
1562 hfx, rbeta, spinfac, xfac
1563 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: tcharge, tv
1564 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :) :: gtcharge
1565 REAL(kind=dp), DIMENSION(3) :: fij, fodeb, rij
1566 REAL(kind=dp), DIMENSION(:, :), POINTER :: gab, pblock
1567 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
1568 TYPE(cell_type), POINTER :: cell
1569 TYPE(cp_fm_struct_type), POINTER :: fmstruct, fmstruct_mat, fmstructjspin
1570 TYPE(cp_fm_type) :: cvcmat, cvec, cvecjspin, t0matrix, &
1571 t1matrix, vcvec, xvec
1572 TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:) :: xtransformed
1573 TYPE(cp_fm_type), DIMENSION(:), POINTER :: cpmos, x
1574 TYPE(cp_fm_type), POINTER :: ct, ctjspin, ucmatrix, uxmatrix
1575 TYPE(cp_logger_type), POINTER :: logger
1576 TYPE(dbcsr_iterator_type) :: iter
1577 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: gamma_matrix, matrix_plo, matrix_s, &
1578 matrix_wx1, scrm
1579 TYPE(dbcsr_type) :: pdens, ptrans
1580 TYPE(dbcsr_type), POINTER :: tempmat
1581 TYPE(dft_control_type), POINTER :: dft_control
1582 TYPE(ewald_environment_type), POINTER :: ewald_env
1583 TYPE(ewald_pw_type), POINTER :: ewald_pw
1584 TYPE(mp_para_env_type), POINTER :: para_env
1585 TYPE(neighbor_list_set_p_type), DIMENSION(:), &
1586 POINTER :: n_list, sab_orb
1587 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
1588 TYPE(qs_force_type), DIMENSION(:), POINTER :: force
1589 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
1590 TYPE(qs_ks_env_type), POINTER :: ks_env
1591 TYPE(stda_control_type), POINTER :: stda_control
1592 TYPE(tddfpt2_control_type), POINTER :: tddfpt_control
1593 TYPE(virial_type), POINTER :: virial
1594
1595 CALL timeset(routinen, handle)
1596
1597 cpassert(ASSOCIATED(ex_env))
1598 cpassert(ASSOCIATED(gs_mos))
1599
1600 logger => cp_get_default_logger()
1601 IF (logger%para_env%is_source()) THEN
1602 iounit = cp_logger_get_default_unit_nr(logger, local=.true.)
1603 ELSE
1604 iounit = -1
1605 END IF
1606
1607 CALL get_qs_env(qs_env, dft_control=dft_control)
1608 tddfpt_control => dft_control%tddfpt2_control
1609 stda_control => tddfpt_control%stda_control
1610 nspins = dft_control%nspins
1611 is_rks_triplets = tddfpt_control%rks_triplets .AND. (nspins == 1)
1612
1613 x => ex_env%evect
1614
1615 nactive(:) = stda_env%nactive(:)
1616 xfac = 2.0_dp
1617 spinfac = 2.0_dp
1618 IF (nspins == 2) spinfac = 1.0_dp
1619 NULLIFY (matrix_wx1)
1620 CALL dbcsr_allocate_matrix_set(matrix_wx1, nspins)
1621 NULLIFY (matrix_plo)
1622 CALL dbcsr_allocate_matrix_set(matrix_plo, nspins)
1623
1624 IF (nspins == 1 .AND. is_rks_triplets) THEN
1625 do_coulomb = .false.
1626 ELSE
1627 do_coulomb = .true.
1628 END IF
1629 do_ewald = stda_control%do_ewald
1630
1631 CALL get_qs_env(qs_env, para_env=para_env, force=force)
1632
1633 CALL get_qs_env(qs_env, natom=natom, cell=cell, &
1634 particle_set=particle_set, qs_kind_set=qs_kind_set)
1635 ALLOCATE (first_sgf(natom))
1636 ALLOCATE (last_sgf(natom))
1637 CALL get_particle_set(particle_set, qs_kind_set, first_sgf=first_sgf, last_sgf=last_sgf)
1638
1639 CALL get_qs_env(qs_env, ks_env=ks_env, matrix_s=matrix_s, sab_orb=sab_orb, atomic_kind_set=atomic_kind_set)
1640 CALL get_atomic_kind_set(atomic_kind_set=atomic_kind_set, kind_of=kind_of, atom_of_kind=atom_of_kind)
1641
1642 ! calculate Loewdin transformed Davidson trial vector tilde(X)=S^1/2*X
1643 ! and tilde(tilde(X))=S^1/2_A*tilde(X)_A
1644 ALLOCATE (xtransformed(nspins))
1645 DO ispin = 1, nspins
1646 NULLIFY (fmstruct)
1647 ct => work%ctransformed(ispin)
1648 CALL cp_fm_get_info(ct, matrix_struct=fmstruct)
1649 CALL cp_fm_create(matrix=xtransformed(ispin), matrix_struct=fmstruct, name="XTRANSFORMED")
1650 END DO
1651 CALL get_lowdin_x(work%shalf, x, xtransformed)
1652
1653 ALLOCATE (tcharge(natom), gtcharge(natom, 4))
1654
1655 cpmos => ex_env%cpmos
1656
1657 DO ispin = 1, nspins
1658 ct => work%ctransformed(ispin)
1659 CALL cp_fm_get_info(ct, matrix_struct=fmstruct, nrow_global=nsgf)
1660 ALLOCATE (tv(nsgf))
1661 CALL cp_fm_create(cvec, fmstruct)
1662 CALL cp_fm_create(xvec, fmstruct)
1663 !
1664 ALLOCATE (matrix_wx1(ispin)%matrix)
1665 CALL dbcsr_create(matrix=matrix_wx1(ispin)%matrix, template=matrix_s(1)%matrix)
1666 CALL cp_dbcsr_alloc_block_from_nbl(matrix_wx1(ispin)%matrix, sab_orb)
1667 CALL dbcsr_set(matrix_wx1(ispin)%matrix, 0.0_dp)
1668 ALLOCATE (matrix_plo(ispin)%matrix)
1669 CALL dbcsr_create(matrix=matrix_plo(ispin)%matrix, template=matrix_s(1)%matrix)
1670 CALL cp_dbcsr_alloc_block_from_nbl(matrix_plo(ispin)%matrix, sab_orb)
1671 CALL dbcsr_set(matrix_plo(ispin)%matrix, 0.0_dp)
1672 !
1673 ! *** Coulomb contribution
1674 !
1675 IF (do_coulomb) THEN
1676 !
1677 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
1678 !
1679 tcharge(:) = 0.0_dp
1680 DO jspin = 1, nspins
1681 ctjspin => work%ctransformed(jspin)
1682 CALL cp_fm_get_info(ctjspin, matrix_struct=fmstructjspin)
1683 CALL cp_fm_get_info(ctjspin, matrix_struct=fmstructjspin, nrow_global=nsgf)
1684 CALL cp_fm_create(cvecjspin, fmstructjspin)
1685 ! CV(mu,j) = CT(mu,j)*XT(mu,j)
1686 CALL cp_fm_schur_product(ctjspin, xtransformed(jspin), cvecjspin)
1687 ! TV(mu) = SUM_j CV(mu,j)
1688 CALL cp_fm_vectorssum(cvecjspin, tv, "R")
1689 ! contract charges
1690 ! TC(a) = SUM_(mu of a) TV(mu)
1691 DO ia = 1, natom
1692 DO is = first_sgf(ia), last_sgf(ia)
1693 tcharge(ia) = tcharge(ia) + tv(is)
1694 END DO
1695 END DO
1696 CALL cp_fm_release(cvecjspin)
1697 END DO !jspin
1698 ! Apply tcharge*gab -> gtcharge
1699 ! gT(b) = SUM_a g(a,b)*TC(a)
1700 ! gab = work%gamma_exchange(1)%matrix
1701 gtcharge = 0.0_dp
1702 ! short range contribution
1703 NULLIFY (gamma_matrix)
1704 CALL setup_gamma(qs_env, stda_env, sub_env, gamma_matrix, ndim=4)
1705 tempmat => gamma_matrix(1)%matrix
1706 CALL dbcsr_iterator_start(iter, tempmat)
1707 DO WHILE (dbcsr_iterator_blocks_left(iter))
1708 CALL dbcsr_iterator_next_block(iter, iatom, jatom, gab)
1709 gtcharge(iatom, 1) = gtcharge(iatom, 1) + gab(1, 1)*tcharge(jatom)
1710 IF (iatom /= jatom) THEN
1711 gtcharge(jatom, 1) = gtcharge(jatom, 1) + gab(1, 1)*tcharge(iatom)
1712 END IF
1713 DO idimk = 2, 4
1714 fdim = -1.0_dp
1715 CALL dbcsr_get_block_p(matrix=gamma_matrix(idimk)%matrix, &
1716 row=iatom, col=jatom, block=gab, found=found)
1717 IF (found) THEN
1718 gtcharge(iatom, idimk) = gtcharge(iatom, idimk) + gab(1, 1)*tcharge(jatom)
1719 IF (iatom /= jatom) THEN
1720 gtcharge(jatom, idimk) = gtcharge(jatom, idimk) + fdim*gab(1, 1)*tcharge(iatom)
1721 END IF
1722 END IF
1723 END DO
1724 END DO
1725 CALL dbcsr_iterator_stop(iter)
1726 CALL dbcsr_deallocate_matrix_set(gamma_matrix)
1727 ! Ewald long range contribution
1728 IF (do_ewald) THEN
1729 ewald_env => work%ewald_env
1730 ewald_pw => work%ewald_pw
1731 CALL ewald_env_get(ewald_env, alpha=alpha, ewald_type=ewald_type)
1732 CALL get_qs_env(qs_env=qs_env, sab_orb=n_list, virial=virial)
1733 use_virial = .false.
1734 calculate_forces = .false.
1735 CALL tb_ewald_overlap(gtcharge, tcharge, alpha, n_list, virial, use_virial)
1736 CALL tb_spme_evaluate(ewald_env, ewald_pw, particle_set, cell, &
1737 gtcharge, tcharge, calculate_forces, virial, use_virial)
1738 ! add self charge interaction contribution
1739 IF (para_env%is_source()) THEN
1740 gtcharge(:, 1) = gtcharge(:, 1) - 2._dp*alpha*oorootpi*tcharge(:)
1741 END IF
1742 ELSE
1743 nlim = get_limit(natom, para_env%num_pe, para_env%mepos)
1744 DO iatom = nlim(1), nlim(2)
1745 DO jatom = 1, iatom - 1
1746 rij = particle_set(iatom)%r - particle_set(jatom)%r
1747 rij = pbc(rij, cell)
1748 dr = sqrt(sum(rij(:)**2))
1749 IF (dr > 1.e-6_dp) THEN
1750 gtcharge(iatom, 1) = gtcharge(iatom, 1) + tcharge(jatom)/dr
1751 gtcharge(jatom, 1) = gtcharge(jatom, 1) + tcharge(iatom)/dr
1752 DO idimk = 2, 4
1753 gtcharge(iatom, idimk) = gtcharge(iatom, idimk) + rij(idimk - 1)*tcharge(jatom)/dr**3
1754 gtcharge(jatom, idimk) = gtcharge(jatom, idimk) - rij(idimk - 1)*tcharge(iatom)/dr**3
1755 END DO
1756 END IF
1757 END DO
1758 END DO
1759 END IF
1760 CALL para_env%sum(gtcharge(:, 1))
1761 ! expand charges
1762 ! TV(mu) = TC(a of mu)
1763 tv(1:nsgf) = 0.0_dp
1764 DO ia = 1, natom
1765 DO is = first_sgf(ia), last_sgf(ia)
1766 tv(is) = gtcharge(ia, 1)
1767 END DO
1768 END DO
1769 !
1770 DO iatom = 1, natom
1771 ikind = kind_of(iatom)
1772 atom_i = atom_of_kind(iatom)
1773 DO i = 1, 3
1774 fij(i) = spinfac*spinfac*gtcharge(iatom, i + 1)*tcharge(iatom)
1775 END DO
1776 force(ikind)%rho_elec(1, atom_i) = force(ikind)%rho_elec(1, atom_i) - fij(1)
1777 force(ikind)%rho_elec(2, atom_i) = force(ikind)%rho_elec(2, atom_i) - fij(2)
1778 force(ikind)%rho_elec(3, atom_i) = force(ikind)%rho_elec(3, atom_i) - fij(3)
1779 END DO
1780 !
1781 IF (debug_forces) THEN
1782 fodeb(1:3) = force(1)%rho_elec(1:3, 1) - fodeb(1:3)
1783 CALL para_env%sum(fodeb)
1784 IF (iounit > 0) WRITE (iounit, "(T3,A,T33,3F16.8)") "DEBUG:: Coul[X] ", fodeb
1785 END IF
1786 norb = nactive(ispin)
1787 ! forces from Lowdin charge derivative
1788 CALL cp_fm_get_info(work%S_C0_C0T(ispin), matrix_struct=fmstruct)
1789 CALL cp_fm_create(t0matrix, matrix_struct=fmstruct, name="T0 SCRATCH")
1790 CALL cp_fm_create(t1matrix, matrix_struct=fmstruct, name="T1 SCRATCH")
1791 ALLOCATE (ucmatrix)
1792 CALL fm_pool_create_fm(work%fm_pool_ao_mo_active(ispin)%pool, ucmatrix)
1793 ALLOCATE (uxmatrix)
1794 CALL fm_pool_create_fm(work%fm_pool_ao_mo_active(ispin)%pool, uxmatrix)
1795 ct => work%ctransformed(ispin)
1796 CALL cp_fm_to_fm(ct, cvec)
1797 CALL cp_fm_row_scale(cvec, tv)
1798 CALL parallel_gemm('T', 'N', nsgf, norb, nsgf, 1.0_dp, work%S_eigenvectors, &
1799 cvec, 0.0_dp, ucmatrix)
1800 CALL parallel_gemm('T', 'N', nsgf, norb, nsgf, 1.0_dp, work%S_eigenvectors, &
1801 x(ispin), 0.0_dp, uxmatrix)
1802 CALL parallel_gemm('N', 'T', nsgf, nsgf, norb, 1.0_dp, uxmatrix, ucmatrix, 0.0_dp, t0matrix)
1803 CALL cp_fm_to_fm(xtransformed(ispin), cvec)
1804 CALL cp_fm_row_scale(cvec, tv)
1805 CALL parallel_gemm('T', 'N', nsgf, norb, nsgf, 1.0_dp, work%S_eigenvectors, &
1806 cvec, 0.0_dp, uxmatrix)
1807 CALL parallel_gemm('T', 'N', nsgf, norb, nsgf, 1.0_dp, work%S_eigenvectors, &
1808 gs_mos(ispin)%mos_occ, 0.0_dp, ucmatrix)
1809 CALL parallel_gemm('N', 'T', nsgf, nsgf, norb, 1.0_dp, ucmatrix, uxmatrix, 1.0_dp, t0matrix)
1810 CALL cp_fm_schur_product(work%slambda, t0matrix, t1matrix)
1811 !
1812 CALL parallel_gemm('N', 'N', nsgf, nsgf, nsgf, spinfac, work%S_eigenvectors, t1matrix, &
1813 0.0_dp, t0matrix)
1814 CALL cp_dbcsr_plus_fm_fm_t(matrix_plo(ispin)%matrix, matrix_v=t0matrix, &
1815 matrix_g=work%S_eigenvectors, ncol=nsgf, alpha=2.0_dp, symmetry_mode=1)
1816 CALL fm_pool_give_back_fm(work%fm_pool_ao_mo_active(ispin)%pool, ucmatrix)
1817 DEALLOCATE (ucmatrix)
1818 CALL fm_pool_give_back_fm(work%fm_pool_ao_mo_active(ispin)%pool, uxmatrix)
1819 DEALLOCATE (uxmatrix)
1820 CALL cp_fm_release(t0matrix)
1821 CALL cp_fm_release(t1matrix)
1822 !
1823 ! CV(mu,i) = TV(mu)*XT(mu,i)
1824 CALL cp_fm_to_fm(xtransformed(ispin), cvec)
1825 CALL cp_fm_row_scale(cvec, tv)
1826 CALL cp_dbcsr_sm_fm_multiply(work%shalf, cvec, cpmos(ispin), norb, 2.0_dp*spinfac, 1.0_dp)
1827 ! CV(mu,i) = TV(mu)*CT(mu,i)
1828 ct => work%ctransformed(ispin)
1829 CALL cp_fm_to_fm(ct, cvec)
1830 CALL cp_fm_row_scale(cvec, tv)
1831 ! Shalf(nu,mu)*CV(mu,i)
1832 CALL cp_fm_get_info(cvec, matrix_struct=fmstruct, nrow_global=nao)
1833 CALL cp_fm_create(vcvec, fmstruct)
1834 CALL cp_dbcsr_sm_fm_multiply(work%shalf, cvec, vcvec, norb, 1.0_dp, 0.0_dp)
1835 CALL cp_fm_struct_create(fmstruct_mat, context=fmstruct%context, nrow_global=norb, &
1836 ncol_global=norb, para_env=fmstruct%para_env)
1837 CALL cp_fm_create(cvcmat, fmstruct_mat)
1838 CALL cp_fm_struct_release(fmstruct_mat)
1839 CALL parallel_gemm("T", "N", norb, norb, nao, 1.0_dp, gs_mos(ispin)%mos_occ, vcvec, 0.0_dp, cvcmat)
1840 CALL parallel_gemm("N", "N", nao, norb, norb, 1.0_dp, x(ispin), cvcmat, 0.0_dp, vcvec)
1841 CALL cp_dbcsr_sm_fm_multiply(matrix_s(1)%matrix, vcvec, cpmos(ispin), &
1842 nactive(ispin), alpha=-2.0_dp*spinfac, beta=1.0_dp)
1843 ! wx1
1844 alpha = 2.0_dp
1845 CALL cp_dbcsr_plus_fm_fm_t(matrix_wx1(ispin)%matrix, matrix_v=gs_mos(ispin)%mos_occ, &
1846 matrix_g=vcvec, ncol=norb, alpha=2.0_dp*alpha, symmetry_mode=1)
1847 CALL cp_fm_release(vcvec)
1848 CALL cp_fm_release(cvcmat)
1849 END IF
1850 !
1851 ! *** Exchange contribution
1852 !
1853 IF (stda_env%do_exchange) THEN
1854 !
1855 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
1856 !
1857 norb = nactive(ispin)
1858 !
1859 tempmat => work%shalf
1860 CALL dbcsr_create(pdens, template=tempmat, matrix_type=dbcsr_type_no_symmetry)
1861 ! P(nu,mu) = SUM_j XT(nu,j)*CT(mu,j)
1862 ct => work%ctransformed(ispin)
1863 CALL dbcsr_set(pdens, 0.0_dp)
1864 CALL cp_dbcsr_plus_fm_fm_t(pdens, xtransformed(ispin), ct, nactive(ispin), &
1865 1.0_dp, keep_sparsity=.false.)
1866 CALL dbcsr_filter(pdens, stda_env%eps_td_filter)
1867 ! Apply PP*gab -> PP; gab = gamma_coulomb
1868 ! P(nu,mu) = P(nu,mu)*g(a of nu,b of mu)
1869 bp = stda_env%beta_param
1870 hfx = stda_env%hfx_fraction
1871 CALL dbcsr_iterator_start(iter, pdens)
1872 DO WHILE (dbcsr_iterator_blocks_left(iter))
1873 CALL dbcsr_iterator_next_block(iter, iatom, jatom, pblock)
1874 rij = particle_set(iatom)%r - particle_set(jatom)%r
1875 rij = pbc(rij, cell)
1876 dr = sqrt(sum(rij(:)**2))
1877 ikind = kind_of(iatom)
1878 jkind = kind_of(jatom)
1879 eta = (stda_env%kind_param_set(ikind)%kind_param%hardness_param + &
1880 stda_env%kind_param_set(jkind)%kind_param%hardness_param)/2.0_dp
1881 rbeta = dr**bp
1882 IF (hfx > 0.0_dp) THEN
1883 gabr = (1._dp/(rbeta + (hfx*eta)**(-bp)))**(1._dp/bp)
1884 ELSE
1885 IF (dr < 1.0e-6_dp) THEN
1886 gabr = 0.0_dp
1887 ELSE
1888 gabr = 1._dp/dr
1889 END IF
1890 END IF
1891 ! gabr = (1._dp/(rbeta + (hfx*eta)**(-bp)))**(1._dp/bp)
1892 ! forces
1893 IF (dr > 1.0e-6_dp) THEN
1894 IF (hfx > 0.0_dp) THEN
1895 dgabr = -(1._dp/bp)*(1._dp/(rbeta + (hfx*eta)**(-bp)))**(1._dp/bp + 1._dp)
1896 dgabr = bp*rbeta/dr**2*dgabr
1897 dgabr = sum(pblock**2)*dgabr
1898 ELSE
1899 dgabr = -1.0_dp/dr**3
1900 dgabr = sum(pblock**2)*dgabr
1901 END IF
1902 atom_i = atom_of_kind(iatom)
1903 atom_j = atom_of_kind(jatom)
1904 DO i = 1, 3
1905 fij(i) = dgabr*rij(i)
1906 END DO
1907 force(ikind)%rho_elec(1, atom_i) = force(ikind)%rho_elec(1, atom_i) - fij(1)
1908 force(ikind)%rho_elec(2, atom_i) = force(ikind)%rho_elec(2, atom_i) - fij(2)
1909 force(ikind)%rho_elec(3, atom_i) = force(ikind)%rho_elec(3, atom_i) - fij(3)
1910 force(jkind)%rho_elec(1, atom_j) = force(jkind)%rho_elec(1, atom_j) + fij(1)
1911 force(jkind)%rho_elec(2, atom_j) = force(jkind)%rho_elec(2, atom_j) + fij(2)
1912 force(jkind)%rho_elec(3, atom_j) = force(jkind)%rho_elec(3, atom_j) + fij(3)
1913 END IF
1914 !
1915 pblock = gabr*pblock
1916 END DO
1917 CALL dbcsr_iterator_stop(iter)
1918 !
1919 ! Transpose pdens matrix
1920 CALL dbcsr_create(ptrans, template=pdens)
1921 CALL dbcsr_transposed(ptrans, pdens)
1922 !
1923 ! forces from Lowdin charge derivative
1924 CALL cp_fm_get_info(work%S_C0_C0T(ispin), matrix_struct=fmstruct)
1925 CALL cp_fm_create(t0matrix, matrix_struct=fmstruct, name="T0 SCRATCH")
1926 CALL cp_fm_create(t1matrix, matrix_struct=fmstruct, name="T1 SCRATCH")
1927 ALLOCATE (ucmatrix)
1928 CALL fm_pool_create_fm(work%fm_pool_ao_mo_active(ispin)%pool, ucmatrix)
1929 ALLOCATE (uxmatrix)
1930 CALL fm_pool_create_fm(work%fm_pool_ao_mo_active(ispin)%pool, uxmatrix)
1931 ct => work%ctransformed(ispin)
1932 CALL cp_dbcsr_sm_fm_multiply(pdens, ct, cvec, norb, 1.0_dp, 0.0_dp)
1933 CALL parallel_gemm('T', 'N', nsgf, norb, nsgf, 1.0_dp, work%S_eigenvectors, &
1934 cvec, 0.0_dp, ucmatrix)
1935 CALL parallel_gemm('T', 'N', nsgf, norb, nsgf, 1.0_dp, work%S_eigenvectors, &
1936 x(ispin), 0.0_dp, uxmatrix)
1937 CALL parallel_gemm('N', 'T', nsgf, nsgf, norb, 1.0_dp, uxmatrix, ucmatrix, 0.0_dp, t0matrix)
1938 CALL cp_dbcsr_sm_fm_multiply(ptrans, xtransformed(ispin), cvec, norb, 1.0_dp, 0.0_dp)
1939 CALL parallel_gemm('T', 'N', nsgf, norb, nsgf, 1.0_dp, work%S_eigenvectors, &
1940 cvec, 0.0_dp, uxmatrix)
1941 CALL parallel_gemm('T', 'N', nsgf, norb, nsgf, 1.0_dp, work%S_eigenvectors, &
1942 gs_mos(ispin)%mos_occ, 0.0_dp, ucmatrix)
1943 CALL parallel_gemm('N', 'T', nsgf, nsgf, norb, 1.0_dp, ucmatrix, uxmatrix, 1.0_dp, t0matrix)
1944 CALL cp_fm_schur_product(work%slambda, t0matrix, t1matrix)
1945 CALL parallel_gemm('N', 'N', nsgf, nsgf, nsgf, -1.0_dp, work%S_eigenvectors, t1matrix, &
1946 0.0_dp, t0matrix)
1947 CALL cp_dbcsr_plus_fm_fm_t(matrix_plo(ispin)%matrix, matrix_v=t0matrix, &
1948 matrix_g=work%S_eigenvectors, ncol=nsgf, alpha=2.0_dp, symmetry_mode=1)
1949 CALL fm_pool_give_back_fm(work%fm_pool_ao_mo_active(ispin)%pool, ucmatrix)
1950 DEALLOCATE (ucmatrix)
1951 CALL fm_pool_give_back_fm(work%fm_pool_ao_mo_active(ispin)%pool, uxmatrix)
1952 DEALLOCATE (uxmatrix)
1953 CALL cp_fm_release(t0matrix)
1954 CALL cp_fm_release(t1matrix)
1955
1956 ! RHS contribution to response matrix
1957 ! CV(nu,i) = P(nu,mu)*XT(mu,i)
1958 CALL cp_dbcsr_sm_fm_multiply(ptrans, xtransformed(ispin), cvec, norb, 1.0_dp, 0.0_dp)
1959 CALL cp_dbcsr_sm_fm_multiply(work%shalf, cvec, cpmos(ispin), norb, &
1960 alpha=-xfac, beta=1.0_dp)
1961 !
1962 CALL cp_fm_get_info(cvec, matrix_struct=fmstruct, nrow_global=nao)
1963 CALL cp_fm_create(vcvec, fmstruct)
1964 ! CV(nu,i) = P(nu,mu)*CT(mu,i)
1965 CALL cp_dbcsr_sm_fm_multiply(ptrans, ct, cvec, norb, 1.0_dp, 0.0_dp)
1966 CALL cp_dbcsr_sm_fm_multiply(work%shalf, cvec, vcvec, norb, 1.0_dp, 0.0_dp)
1967 CALL cp_fm_struct_create(fmstruct_mat, context=fmstruct%context, nrow_global=norb, &
1968 ncol_global=norb, para_env=fmstruct%para_env)
1969 CALL cp_fm_create(cvcmat, fmstruct_mat)
1970 CALL cp_fm_struct_release(fmstruct_mat)
1971 CALL parallel_gemm("T", "N", norb, norb, nao, 1.0_dp, gs_mos(ispin)%mos_occ, vcvec, 0.0_dp, cvcmat)
1972 CALL parallel_gemm("N", "N", nao, norb, norb, 1.0_dp, x(ispin), cvcmat, 0.0_dp, vcvec)
1973 CALL cp_dbcsr_sm_fm_multiply(matrix_s(1)%matrix, vcvec, cpmos(ispin), &
1974 norb, alpha=xfac, beta=1.0_dp)
1975 ! wx1
1976 IF (nspins == 2) THEN
1977 alpha = -2.0_dp
1978 ELSE
1979 alpha = -1.0_dp
1980 END IF
1981 CALL cp_dbcsr_plus_fm_fm_t(matrix_wx1(ispin)%matrix, matrix_v=gs_mos(ispin)%mos_occ, &
1982 matrix_g=vcvec, &
1983 ncol=norb, alpha=2.0_dp*alpha, symmetry_mode=1)
1984 CALL cp_fm_release(vcvec)
1985 CALL cp_fm_release(cvcmat)
1986 !
1987 CALL dbcsr_release(pdens)
1988 CALL dbcsr_release(ptrans)
1989 !
1990 IF (debug_forces) THEN
1991 fodeb(1:3) = force(1)%rho_elec(1:3, 1) - fodeb(1:3)
1992 CALL para_env%sum(fodeb)
1993 IF (iounit > 0) WRITE (iounit, "(T3,A,T33,3F16.8)") "DEBUG:: Exch[X] ", fodeb
1994 END IF
1995 END IF
1996 !
1997 CALL cp_fm_release(cvec)
1998 CALL cp_fm_release(xvec)
1999 DEALLOCATE (tv)
2000 END DO
2001
2002 CALL cp_fm_release(xtransformed)
2003 DEALLOCATE (tcharge, gtcharge)
2004 DEALLOCATE (first_sgf, last_sgf)
2005
2006 ! Lowdin forces
2007 IF (nspins == 2) THEN
2008 CALL dbcsr_add(matrix_plo(1)%matrix, matrix_plo(2)%matrix, &
2009 alpha_scalar=1.0_dp, beta_scalar=1.0_dp)
2010 END IF
2011 CALL dbcsr_scale(matrix_plo(1)%matrix, -1.0_dp)
2012 NULLIFY (scrm)
2013 IF (debug_forces) fodeb(1:3) = force(1)%overlap(1:3, 1)
2014 CALL build_overlap_matrix(ks_env, matrix_s=scrm, &
2015 matrix_name="OVERLAP MATRIX", &
2016 basis_type_a="ORB", basis_type_b="ORB", &
2017 sab_nl=sab_orb, calculate_forces=.true., &
2018 matrix_p=matrix_plo(1)%matrix)
2020 CALL dbcsr_deallocate_matrix_set(matrix_plo)
2021 IF (debug_forces) THEN
2022 fodeb(1:3) = force(1)%overlap(1:3, 1) - fodeb(1:3)
2023 CALL para_env%sum(fodeb)
2024 IF (iounit > 0) WRITE (iounit, "(T3,A,T33,3F16.8)") "DEBUG:: Lowdin ", fodeb
2025 END IF
2026
2027 IF (ASSOCIATED(ex_env%matrix_wx1)) CALL dbcsr_deallocate_matrix_set(ex_env%matrix_wx1)
2028 ex_env%matrix_wx1 => matrix_wx1
2029
2030 CALL timestop(handle)
2031
2032 END SUBROUTINE stda_force
2033
2034! **************************************************************************************************
2035
2036END MODULE qs_tddfpt2_fhxc_forces
subroutine, public accint_weight_force(qs_env, rho, rho1, order, xc_section, triplet, force_scale)
...
Contains ADMM methods which require molecular orbitals.
subroutine, public admm_projection_derivative(qs_env, matrix_hz, matrix_pz, fval)
Calculate derivatives terms from overlap matrices.
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.
subroutine, public get_atomic_kind_set(atomic_kind_set, atom_of_kind, kind_of, natom_of_kind, maxatom, natom, nshell, fist_potential_present, shell_present, shell_adiabatic, shell_check_distance, damping_present)
Get attributes of an atomic kind set.
Handles all functions related to the CELL.
Definition cell_types.F:15
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
subroutine, public dbcsr_transposed(transposed, normal, shallow_data_copy, transpose_distribution, use_distribution)
...
subroutine, public dbcsr_scale(matrix, alpha_scalar)
...
subroutine, public dbcsr_iterator_next_block(iterator, row, column, block, block_number_argument_has_been_removed, row_size, col_size, row_offset, col_offset)
...
logical function, public dbcsr_iterator_blocks_left(iterator)
...
subroutine, public dbcsr_iterator_stop(iterator)
...
subroutine, public dbcsr_copy(matrix_b, matrix_a, name, keep_sparsity, keep_imaginary)
...
subroutine, public dbcsr_get_block_p(matrix, row, col, block, found, row_size, col_size)
...
subroutine, public dbcsr_filter(matrix, eps)
...
subroutine, public dbcsr_iterator_start(iterator, matrix, shared, dynamic, dynamic_byrows)
...
subroutine, public dbcsr_set(matrix, alpha)
...
subroutine, public dbcsr_release(matrix)
...
subroutine, public dbcsr_complete_redistribute(matrix, redist)
...
subroutine, public dbcsr_add(matrix_a, matrix_b, alpha_scalar, beta_scalar)
...
DBCSR operations in CP2K.
subroutine, public cp_dbcsr_sm_fm_multiply(matrix, fm_in, fm_out, ncol, alpha, beta)
multiply a dbcsr with a fm matrix
subroutine, public copy_dbcsr_to_fm(matrix, fm)
Copy a DBCSR matrix to a BLACS matrix.
subroutine, public cp_dbcsr_plus_fm_fm_t(sparse_matrix, matrix_v, matrix_g, ncol, alpha, keep_sparsity, symmetry_mode)
performs the multiplication sparse_matrix+dense_mat*dens_mat^T if matrix_g is not explicitly given,...
subroutine, public copy_fm_to_dbcsr(fm, matrix, keep_sparsity)
Copy a BLACS matrix to a dbcsr matrix.
Basic linear algebra operations for full matrices.
subroutine, public cp_fm_row_scale(matrixa, scaling)
scales row i of matrix a with scaling(i)
subroutine, public cp_fm_add_columns(msource, mtarget, ncol, alpha, source_start, target_start)
Add (and scale) a subset of columns of a fm to a fm b = alpha*a + b.
subroutine, public cp_fm_geadd(alpha, trans, matrix_a, beta, matrix_b)
interface to BLACS geadd: matrix_b = beta*matrix_b + alpha*opt(matrix_a) where opt(matrix_a) can be e...
subroutine, public cp_fm_schur_product(matrix_a, matrix_b, matrix_c)
computes the schur product of two matrices c_ij = a_ij * b_ij
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
subroutine, public fm_pool_give_back_fm(pool, element)
returns the element to 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_vectorssum(matrix, sum_array, dir)
summing up all the elements along the matrix's i-th index or
subroutine, public cp_fm_create(matrix, matrix_struct, name, use_sp, nrow, ncol, set_zero)
creates a new full matrix with the given structure
various routines to log and control the output. The idea is that decisions about where to log should ...
recursive integer function, public cp_logger_get_default_unit_nr(logger, local, skip_not_ionode)
asks the default unit number of the given logger. try to use cp_logger_get_unit_nr
type(cp_logger_type) function, pointer, public cp_get_default_logger()
returns the default logger
subroutine, public ewald_env_get(ewald_env, ewald_type, alpha, eps_pol, epsilon, gmax, ns_max, o_spline, group, para_env, poisson_section, precs, rcut, do_multipoles, max_multipole, do_ipol, max_ipol_iter, interaction_cutoffs, cell_hmat)
Purpose: Get the EWALD environment.
Calculation of Ewald contributions in DFTB.
subroutine, public tb_ewald_overlap(gmcharge, mcharge, alpha, n_list, virial, use_virial)
...
subroutine, public tb_spme_evaluate(ewald_env, ewald_pw, particle_set, box, gmcharge, mcharge, calculate_forces, virial, use_virial)
...
Types for excited states potential energies.
subroutine, public init_coulomb_local(hartree_local, natom)
...
subroutine, public vh_1c_gg_integrals(qs_env, energy_hartree_1c, ecoul_1c, local_rho_set, para_env, tddft, local_rho_set_2nd, core_2nd)
Calculates one center GAPW Hartree energies and matrix elements Hartree potentials are input Takes po...
subroutine, public hartree_local_release(hartree_local)
...
subroutine, public hartree_local_create(hartree_local)
...
Routines to calculate derivatives with respect to basis function origin.
subroutine, public derivatives_four_center(qs_env, rho_ao, rho_ao_resp, hfx_section, para_env, irep, use_virial, adiabatic_rescale_factor, resp_only, external_x_data, nspins)
computes four center derivatives for a full basis set and updates the forcesfock_4c arrays....
Routines to calculate HFX energy and potential.
subroutine, public integrate_four_center(qs_env, x_data, ks_matrix, ehfx, rho_ao, hfx_section, para_env, geometry_did_change, irep, distribute_fock_matrix, ispin, nspins)
computes four center integrals for a full basis set and updates the Kohn-Sham-Matrix and energy....
RI-methods for HFX.
Definition hfx_ri.F:12
subroutine, public hfx_ri_update_ks(qs_env, ri_data, ks_matrix, ehfx, mos, rho_ao, geometry_did_change, nspins, hf_fraction)
...
Definition hfx_ri.F:1041
subroutine, public hfx_ri_update_forces(qs_env, ri_data, nspins, hf_fraction, rho_ao, rho_ao_resp, mos, use_virial, resp_only, rescale_factor)
the general routine that calls the relevant force code
Definition hfx_ri.F:3044
Types and set/get functions for HFX.
Definition hfx_types.F:15
collects all constants needed in input so that they can be used without circular dependencies
integer, parameter, public do_analytic
integer, parameter, public tddfpt_sf_col
integer, parameter, public xc_kernel_method_best
integer, parameter, public xc_kernel_method_analytic
integer, parameter, public do_admm_aux_exch_func_none
integer, parameter, public tddfpt_kernel_full
integer, parameter, public xc_kernel_method_numeric
integer, parameter, public do_numeric
integer, parameter, public no_sf_tddfpt
integer, parameter, public xc_none
objects that represent the structure of input sections and the data contained in an input section
recursive type(section_vals_type) function, pointer, public section_vals_get_subs_vals(section_vals, subsection_name, i_rep_section, can_return_null)
returns the values of the requested subsection
subroutine, public section_vals_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
integer, parameter, public default_string_length
Definition kinds.F:57
Definition of mathematical constants and functions.
real(kind=dp), parameter, public oorootpi
Interface to the message passing library MPI.
basic linear algebra operations for full matrixes
Define methods related to particle_type.
subroutine, public get_particle_set(particle_set, qs_kind_set, first_sgf, last_sgf, nsgf, nmao, basis)
Get the components of a particle set.
Define the data structure for the particle information.
container for various plainwaves related things
subroutine, public pw_env_get(pw_env, pw_pools, cube_info, gridlevel_info, auxbas_pw_pool, auxbas_grid, auxbas_rs_desc, auxbas_rs_grid, rs_descs, rs_grids, xc_pw_pool, vdw_pw_pool, poisson_env, interp_section)
returns the various attributes of the pw env
functions related to the poisson solver on regular grids
Manages a pool of grids (to be used for example as tmp objects), but can also be used to instantiate ...
Calculate the plane wave density by collocating the primitive Gaussian functions (pgf).
subroutine, public calculate_rho_elec(matrix_p, matrix_p_kp, rho, rho_gspace, total_rho, ks_env, soft_valid, compute_tau, compute_grad, basis_type, der_type, idir, task_list_external, pw_env_external)
computes the density corresponding to a given density matrix on the grid
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 set_qs_env(qs_env, super_cell, mos, qmmm, qmmm_periodic, mimic, ewald_env, ewald_pw, mpools, rho_external, external_vxc, mask, scf_control, rel_control, qs_charges, ks_env, ks_qmmm_env, wf_history, scf_env, active_space, input, oce, rho_atom_set, rho0_atom_set, rho0_mpole, run_rtp, rtp, rhoz_set, rhoz_tot, ecoul_1c, has_unit_metric, requires_mo_derivs, mo_derivs, mo_loc_history, efield, rhoz_cneo_set, linres_control, xas_env, cp_ddapc_env, cp_ddapc_ewald, outer_scf_history, outer_scf_ihistory, x_data, et_coupling, dftb_potential, se_taper, se_store_int_env, se_nddo_mpole, se_nonbond_env, admm_env, ls_scf_env, do_transport, transport_env, lri_env, lri_density, exstate_env, ec_env, dispersion_env, harris_env, gcp_env, mp2_env, bs_env, kg_env, force, kpoints, wanniercentres, almo_scf_env, gradient_history, variable_history, embed_pot, spin_embed_pot, polar_env, mos_last_converged, eeq, rhs, do_rixs, tb_tblite)
Set the QUICKSTEP environment.
https://en.wikipedia.org/wiki/Finite_difference_coefficient
Definition qs_fxc.F:27
subroutine, public qs_fgxc_create(ks_env, rho0_struct, rho1_struct, xc_section, accuracy, is_triplet, fxc_rho, fxc_tau, gxc_rho, gxc_tau)
...
Definition qs_fxc.F:629
subroutine, public qs_fgxc_gdiff(ks_env, rho0_struct, rho1_struct, xc_section, accuracy, epsrho, is_triplet, weights, fxc_rho, fxc_tau, gxc_rho, gxc_tau, spinflip)
...
Definition qs_fxc.F:462
subroutine, public qs_fgxc_release(ks_env, fxc_rho, fxc_tau, gxc_rho, gxc_tau)
...
Definition qs_fxc.F:758
subroutine, public qs_fgxc_analytic(rho0_struct, rho1_struct, xc_section, weights, pw_pool, fxc_rho, fxc_tau, gxc_rho, gxc_tau, spinflip)
Calculates the values at the grid points in real space (r_i), of the second and third functional deri...
Definition qs_fxc.F:307
subroutine, public prepare_gapw_den(qs_env, local_rho_set, do_rho0, kind_set_external, pw_env_sub)
...
Integrate single or product functions over a potential on a RS grid.
Define the quickstep kind type and their sub types.
routines that build the Kohn-Sham matrix contributions coming from local atomic densities
Definition qs_ks_atom.F:12
subroutine, public update_ks_atom(qs_env, ksmat, pmat, forces, tddft, rho_atom_external, kind_set_external, oce_external, sab_external, kscale, kintegral, kforce, fscale)
The correction to the KS matrix due to the GAPW local terms to the hartree and XC contributions is he...
Definition qs_ks_atom.F:110
subroutine, public local_rho_set_create(local_rho_set)
...
subroutine, public local_rho_set_release(local_rho_set)
...
Define the neighbor list data types and the corresponding functionality.
Routines for the construction of the coefficients for the expansion of the atomic densities rho1_hard...
subroutine, public build_oce_matrices(intac, calculate_forces, nder, qs_kind_set, particle_set, sap_oce, eps_fit)
Set up the sparse matrix for the coefficients of one center expansions This routine uses the same log...
subroutine, public allocate_oce_set(oce_set, nkind)
Allocate and initialize the matrix set of oce coefficients.
subroutine, public create_oce_set(oce_set)
...
Calculation of overlap matrix, its derivatives and forces.
Definition qs_overlap.F:19
subroutine, public build_overlap_matrix(ks_env, matrix_s, matrixkp_s, matrix_name, nderivative, basis_type_a, basis_type_b, sab_nl, calculate_forces, matrix_p, matrixkp_p, ext_kpoints)
Calculation of the overlap matrix over Cartesian Gaussian functions.
Definition qs_overlap.F:121
subroutine, public rho0_s_grid_create(pw_env, rho0_mpole)
...
subroutine, public integrate_vhg0_rspace(qs_env, v_rspace, para_env, calculate_forces, local_rho_set, local_rho_set_2nd, atener, kforce, my_pools, my_rs_descs)
...
subroutine, public init_rho0(local_rho_set, qs_env, gapw_control, zcore)
...
subroutine, public allocate_rho_atom_internals(rho_atom_set, atomic_kind_set, qs_kind_set, dft_control, para_env)
...
subroutine, public calculate_rho_atom_coeff(qs_env, rho_ao, rho_atom_set, qs_kind_set, oce, sab, para_env)
...
superstucture that hold various representations of the density and keeps track of which ones are vali...
subroutine, public qs_rho_set(rho_struct, rho_ao, rho_ao_im, rho_ao_kp, rho_ao_im_kp, rho_r, drho_r, rho_g, drho_g, tau_r, tau_g, rho_r_valid, drho_r_valid, rho_g_valid, drho_g_valid, tau_r_valid, tau_g_valid, tot_rho_r, tot_rho_g, rho_r_sccs, soft_valid, complex_rho_ao)
...
subroutine, public qs_rho_get(rho_struct, rho_ao, rho_ao_im, rho_ao_kp, rho_ao_im_kp, rho_r, drho_r, rho_g, drho_g, tau_r, tau_g, rho_r_valid, drho_r_valid, rho_g_valid, drho_g_valid, tau_r_valid, tau_g_valid, tot_rho_r, tot_rho_g, rho_r_sccs, soft_valid, complex_rho_ao)
returns info about the density described by this object. If some representation is not available an e...
subroutine, public qs_rho_create(rho)
Allocates a new instance of rho.
subroutine, public stda_force(qs_env, ex_env, gs_mos, stda_env, sub_env, work, debug_forces)
Simplified Tamm Dancoff approach (sTDA). Kernel contribution to forces.
subroutine, public fhxc_force(qs_env, ex_env, gs_mos, full_kernel, debug_forces)
Calculate direct tddft forces. Calculate the three last terms of the response vector in equation 49 a...
Simplified Tamm Dancoff approach (sTDA).
Simplified Tamm Dancoff approach (sTDA).
subroutine, public get_lowdin_x(shalf, xvec, xt)
Calculate Lowdin transformed Davidson trial vector X shalf (dbcsr), xvec, xt (fm) are defined in the ...
subroutine, public setup_gamma(qs_env, stda_env, sub_env, gamma_matrix, ndim)
Calculate sTDA exchange-type contributions.
routines that build the integrals of the Vxc potential calculated for the atomic density in the basis...
Definition qs_vxc_atom.F:12
subroutine, public calculate_gfxc_atom(qs_env, rho0_atom_set, rho1_atom_set, rho2_atom_set, kind_set, xc_section, is_triplet, accuracy)
...
subroutine, public gfxc_atom_diff(qs_env, rho0_atom_set, rho1_atom_set, rho2_atom_set, kind_set, xc_section, is_triplet, accuracy, epsrho)
...
types for task lists
All kind of helpful little routines.
Definition util.F:14
pure integer function, dimension(2), public get_limit(m, n, me)
divide m entries into n parts, return size of part me
Definition util.F:333
type(xc_rho_cflags_type) function, public xc_functionals_get_needs(functionals, lsd, calc_potential)
...
contains the structure
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
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 some data used in construction of Kohn-Sham matrix
Definition hfx_types.F:511
stores all the informations relevant to an mpi environment
contained for different pw related things
environment for the poisson solver
Manages a pool of grids (to be used for example as tmp objects), but can also be used to instantiate ...
Collection of variables required to evaluate adiabatic TDDFPT kernel.
Provides all information about a quickstep kind.
calculation environment to calculate the ks matrix, holds all the needed vars. assumes that the core ...
keeps the density in various representations, keeping track of which ones are valid.
Ground state molecular orbitals.
Set of temporary ("work") matrices.
contains a flag for each component of xc_rho_set, so that you can use it to tell which components you...