170 SUBROUTINE fhxc_force(qs_env, ex_env, gs_mos, full_kernel, debug_forces)
177 LOGICAL,
INTENT(IN) :: debug_forces
179 CHARACTER(LEN=*),
PARAMETER :: routinen =
'fhxc_force'
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, &
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
195 TYPE(
cp_fm_type) :: avamat, avcmat, cpscr, cvcmat, vavec, &
197 TYPE(
cp_fm_type),
DIMENSION(:),
POINTER :: cpmos, evect
198 TYPE(
cp_fm_type),
POINTER :: mos, mos2, mosa, mosa2
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
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
213 POINTER :: sab, sab_aux_fit, sab_orb, sap_oce
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, &
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, &
230 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
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, &
240 CALL timeset(routinen, handle)
243 IF (logger%para_env%is_source())
THEN
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)
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
268 needs_tau_response = needs%tau .OR. needs%tau_spin
269 needs_tau_response_aux = .false.
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
278 IF (nspins == 2) focc = 0.5_dp
279 nsev =
SIZE(evect, 1)
283 CALL dbcsr_set(matrix_px1(ispin)%matrix, 0.0_dp)
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)
290 CALL dbcsr_set(matrix_px1_asymm(ispin)%matrix, 0.0_dp)
292 matrix_v=gs_mos(ispin)%mos_active, &
293 matrix_g=evect(ispin), &
294 ncol=nactive(ispin), alpha=2.0_dp*focc, &
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)
301 NULLIFY (hartree_local, local_rho_set, local_rho_set_admm)
302 IF (gapw .OR. gapw_xc)
THEN
303 IF (nspins == 2)
THEN
309 atomic_kind_set=atomic_kind_set, &
310 qs_kind_set=qs_kind_set)
313 qs_kind_set, dft_control, para_env)
316 CALL init_rho0(local_rho_set, qs_env, dft_control%qs_control%gapw_control, &
323 CALL get_qs_env(qs_env=qs_env, oce=oce, sap_oce=sap_oce, sab_orb=sab)
325 CALL get_qs_env(qs_env=qs_env, nkind=nkind, particle_set=particle_set)
327 eps_fit = dft_control%qs_control%gapw_control%eps_fit
332 mpga(1:nsev, 1:1) => matrix_px1(1:nsev)
334 qs_kind_set, oce, sab, para_env)
339 qs_kind_set, dft_control, para_env)
341 qs_kind_set, oce, sab, para_env)
346 qs_kind_set, dft_control, para_env)
348 qs_kind_set, oce, sab, para_env)
350 IF (nspins == 2)
THEN
359 nao_aux = admm_env%nao_aux_fit
360 nao = admm_env%nao_orb
366 1.0_dp, admm_env%A, admm_env%work_orb_orb, 0.0_dp, &
367 admm_env%work_aux_orb)
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.)
374 CALL copy_dbcsr_to_fm(matrix_px1_asymm(ispin)%matrix, admm_env%work_orb_orb)
376 1.0_dp, admm_env%A, admm_env%work_orb_orb, 0.0_dp, &
377 admm_env%work_aux_orb)
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.)
385 IF (admm_env%do_gapw)
THEN
386 IF (do_admm .AND. tddfpt_control%admm_xc_correction)
THEN
390 CALL get_qs_env(qs_env, atomic_kind_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)
397 admm_env%admm_gapw_env%admm_kind_set, &
398 admm_env%admm_gapw_env%oce, sab_aux_fit, para_env)
400 kind_set_external=admm_env%admm_gapw_env%admm_kind_set)
404 admm_env%admm_gapw_env%admm_kind_set, dft_control, para_env)
406 admm_env%admm_gapw_env%admm_kind_set, &
407 admm_env%admm_gapw_env%oce, sab_aux_fit, para_env)
409 kind_set_external=admm_env%admm_gapw_env%admm_kind_set)
413 admm_env%admm_gapw_env%admm_kind_set, dft_control, para_env)
415 admm_env%admm_gapw_env%admm_kind_set, &
416 admm_env%admm_gapw_env%oce, sab_aux_fit, para_env)
418 kind_set_external=admm_env%admm_gapw_env%admm_kind_set)
424 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool, &
425 poisson_env=poisson_env)
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))
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))
440 CALL auxbas_pw_pool%create_pw(rhox_tot_gspace)
445 IF (nspins == 2)
CALL dbcsr_scale(matrix_px1(ispin)%matrix, 2.0_dp)
447 rho=rhox_r(ispin), rho_gspace=rhox_g(ispin), &
449 IF (needs_tau_response)
THEN
451 rho=rhox_tau_r(ispin), rho_gspace=rhox_tau_g(ispin), &
452 soft_valid=gapw, compute_tau=.true.)
455 CALL pw_axpy(rhox_g(ispin), rhox_tot_gspace)
457 IF (nspins == 2)
CALL dbcsr_scale(matrix_px1(ispin)%matrix, 0.5_dp)
461 ALLOCATE (rhoxx_r(nsev), rhoxx_g(nsev))
463 CALL auxbas_pw_pool%create_pw(rhoxx_r(ispin))
464 CALL auxbas_pw_pool%create_pw(rhoxx_g(ispin))
466 IF (needs_tau_response)
THEN
467 ALLOCATE (rhoxx_tau_r(nsev), rhoxx_tau_g(nsev))
469 CALL auxbas_pw_pool%create_pw(rhoxx_tau_r(ispin))
470 CALL auxbas_pw_pool%create_pw(rhoxx_tau_g(ispin))
474 IF (nspins == 2)
CALL dbcsr_scale(matrix_px1(ispin)%matrix, 2.0_dp)
476 rho=rhoxx_r(ispin), rho_gspace=rhoxx_g(ispin), &
478 IF (needs_tau_response)
THEN
480 rho=rhoxx_tau_r(ispin), rho_gspace=rhoxx_tau_g(ispin), &
481 soft_valid=gapw_xc, compute_tau=.true.)
483 IF (nspins == 2)
CALL dbcsr_scale(matrix_px1(ispin)%matrix, 0.5_dp)
487 CALL get_qs_env(qs_env, matrix_s=matrix_s, force=force)
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)
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)
501 CALL pw_transfer(xv_hartree_gspace, xv_hartree_rspace)
502 CALL pw_scale(xv_hartree_rspace, xv_hartree_rspace%pw_grid%dvol)
504 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
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.)
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
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., &
525 IF (nspins == 1)
THEN
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
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
549 IF (full_kernel%do_exck)
THEN
552 NULLIFY (fxc_rho, fxc_tau, gxc_rho, gxc_tau)
553 xc_section => full_kernel%xc_section
557 SELECT CASE (ex_env%xc_kernel_method)
568 cpabort(
"invalid xc_kernel_method")
570 order = ex_env%diff_order
571 eps_delta = ex_env%eps_delta_rho
574 CALL get_qs_env(qs_env=qs_env, ks_env=ks_env, rho_xc=rho)
576 CALL get_qs_env(qs_env=qs_env, ks_env=ks_env, rho=rho)
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.)
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.)
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.)
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.)
608 IF (.NOT. do_sf)
THEN
609 cpabort(
"Analytic 3rd EXC derivatives not available")
611 CALL get_qs_env(qs_env, xcint_weights=weights)
613 fxc_rho, fxc_tau, gxc_rho, gxc_tau, spinflip=do_sf)
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)
620 CALL qs_fgxc_create(ks_env, rho, rhox, xc_section, order, is_rks_triplets, &
621 fxc_rho, fxc_tau, gxc_rho, gxc_tau)
624 cpabort(
"FHXC forces analytic/numeric")
627 IF (nspins == 2)
THEN
629 CALL pw_scale(gxc_rho(ispin), 0.5_dp)
630 IF (
ASSOCIATED(gxc_tau))
CALL pw_scale(gxc_tau(ispin), 0.5_dp)
633 IF (gapw .OR. gapw_xc)
THEN
635 cpabort(
"Analytic 3rd EXC derivatives not available")
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)
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)
647 cpabort(
"FHXC forces analytic/numeric")
651 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
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)
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.)
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
672 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
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.)
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
697 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
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
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
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, &
728 rho_atom_external=local_rho_set_g%rho_atom_set, &
729 kintegral=0.5_dp, kforce=0.25_dp)
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
740 IF (do_admm .AND. tddfpt_control%admm_xc_correction .AND. (tddfpt_control%spinflip /=
tddfpt_sf_col))
THEN
744 IF (.NOT. tddfpt_control%admm_symm)
THEN
745 CALL cp_warn(__location__,
"Forces need symmetric ADMM kernel corrections")
746 cpabort(
"ADMM KERNEL CORRECTION")
748 xc_section => admm_env%xc_section_aux
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
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)
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)
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)
781 ALLOCATE (rhox_r_aux(nsev), rhox_g_aux(nsev))
783 CALL auxbas_pw_pool%create_pw(rhox_r_aux(ispin))
784 CALL auxbas_pw_pool%create_pw(rhox_g_aux(ispin))
786 IF (needs_tau_response_aux)
THEN
787 ALLOCATE (rhox_tau_r_aux(nsev), rhox_tau_g_aux(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))
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
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, &
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.)
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.)
822 cpabort(
"Analytic 3rd derivatives of EXC not available")
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)
829 order, is_rks_triplets, fxc_rho, fxc_tau, gxc_rho, gxc_tau)
832 cpabort(
"FHXC forces analytic/numeric")
836 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
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
850 DEALLOCATE (rhox_aux)
853 CALL auxbas_pw_pool%give_back_pw(rhox_r_aux(ispin))
854 CALL auxbas_pw_pool%give_back_pw(rhox_g_aux(ispin))
856 DEALLOCATE (rhox_r_aux, rhox_g_aux)
857 IF (needs_tau_response_aux)
THEN
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))
862 DEALLOCATE (rhox_tau_r_aux, rhox_tau_g_aux)
865 IF (nspins == 2) fscal = 2.0_dp
867 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
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), &
872 pmat=matrix_px1_admm(ispin), &
873 basis_type=basis_type, &
874 calculate_forces=.true., &
876 task_list_external=task_list)
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
884 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
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), &
890 pmat=matrix_p_admm(ispin), &
891 basis_type=basis_type, &
892 calculate_forces=.true., &
894 task_list_external=task_list)
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
904 IF (admm_env%do_gapw)
THEN
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
911 cpabort(
"Analytic 3rd EXC derivatives not available")
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)
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)
925 cpabort(
"FHXC forces analytic/numeric")
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)
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)
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
947 IF (debug_forces) fodeb(1:3) = force(1)%Vhxc_atom(1:3, 1)
948 IF (nspins == 1)
THEN
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)
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)
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
970 IF (debug_forces) fodeb(1:3) = force(1)%overlap_admm(1:3, 1)
971 fval = 2.0_dp*real(nspins, kind=
dp)
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
978 IF (debug_forces) fodeb(1:3) = force(1)%overlap_admm(1:3, 1)
979 fval = 2.0_dp*real(nspins, kind=
dp)
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
989 IF (nspins == 2) fscal = 2.0_dp
990 nao = admm_env%nao_orb
991 nao_aux = admm_env%nao_aux_fit
997 admm_env%work_aux_orb, nao)
999 1.0_dp, admm_env%A, admm_env%work_aux_orb, 0.0_dp, &
1000 admm_env%work_orb_orb)
1004 CALL dbcsr_add(matrix_fx(ispin)%matrix, dbwork, 1.0_dp, fscal)
1007 admm_env%work_aux_orb, nao)
1009 1.0_dp, admm_env%A, admm_env%work_aux_orb, 0.0_dp, &
1010 admm_env%work_orb_orb)
1013 CALL dbcsr_add(matrix_gx(ispin)%matrix, dbwork, 1.0_dp, fscal)
1024 CALL auxbas_pw_pool%give_back_pw(rhox_r(ispin))
1025 CALL auxbas_pw_pool%give_back_pw(rhox_g(ispin))
1027 DEALLOCATE (rhox_r, rhox_g)
1028 IF (needs_tau_response)
THEN
1030 CALL auxbas_pw_pool%give_back_pw(rhox_tau_r(ispin))
1031 CALL auxbas_pw_pool%give_back_pw(rhox_tau_g(ispin))
1033 DEALLOCATE (rhox_tau_r, rhox_tau_g)
1035 CALL auxbas_pw_pool%give_back_pw(rhox_tot_gspace)
1038 CALL auxbas_pw_pool%give_back_pw(rhoxx_r(ispin))
1039 CALL auxbas_pw_pool%give_back_pw(rhoxx_g(ispin))
1041 DEALLOCATE (rhoxx_r, rhoxx_g)
1042 IF (needs_tau_response)
THEN
1044 CALL auxbas_pw_pool%give_back_pw(rhoxx_tau_r(ispin))
1045 CALL auxbas_pw_pool%give_back_pw(rhoxx_tau_g(ispin))
1047 DEALLOCATE (rhoxx_tau_r, rhoxx_tau_g)
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)
1057 NULLIFY (matrix_hfx, matrix_hfx_asymm)
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)
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)
1072 xc_section => full_kernel%xc_section
1075 cpassert(n_rep_hf == 1)
1079 IF (hfx_treat_lsd_in_core) mspin = nsev
1081 CALL get_qs_env(qs_env=qs_env, x_data=x_data, s_mstruct_changed=s_mstruct_changed)
1082 distribute_fock_matrix = .true.
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)
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)
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)
1102 ALLOCATE (mpe(nsev, 1), mhe(nsev, 1))
1104 mhe(ispin, 1)%matrix => matrix_hfx_admm(ispin)%matrix
1105 mpe(ispin, 1)%matrix => matrix_px1_admm(ispin)%matrix
1107 IF (x_data(1, 1)%do_hfx_ri)
THEN
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)
1116 para_env, s_mstruct_changed, 1, distribute_fock_matrix, &
1117 ispin=ispin, nspins=nsev)
1122 mhe(ispin, 1)%matrix => matrix_hfx_admm_asymm(ispin)%matrix
1123 mpe(ispin, 1)%matrix => matrix_px1_admm_asymm(ispin)%matrix
1125 IF (x_data(1, 1)%do_hfx_ri)
THEN
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)
1134 para_env, s_mstruct_changed, 1, distribute_fock_matrix, &
1135 ispin=ispin, nspins=nsev)
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)
1146 admm_env%work_aux_orb, nao)
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)
1153 CALL dbcsr_add(matrix_hfx(ispin)%matrix, dbwork, 1.0_dp, 1.0_dp)
1156 admm_env%work_aux_orb, nao)
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)
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)
1167 DEALLOCATE (dbwork, dbwork_asymm)
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
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
1180 use_virial = .false.
1182 fval = 2.0_dp*real(nspins, kind=
dp)*0.5_dp
1184 IF (do_sf) fval = fval*2.0_dp
1185 IF (debug_forces) fodeb(1:3) = force(1)%fock_4c(1:3, 1)
1187 mpe(ispin, 1)%matrix => matrix_px1_admm(ispin)%matrix
1189 IF (x_data(1, 1)%do_hfx_ri)
THEN
1191 x_data(1, 1)%general_parameter%fraction, &
1192 rho_ao=mpe, rho_ao_resp=mdum, &
1193 use_virial=use_virial, rescale_factor=fval)
1196 adiabatic_rescale_factor=fval, nspins=nsev)
1199 mpe(ispin, 1)%matrix => matrix_px1_admm_asymm(ispin)%matrix
1201 IF (x_data(1, 1)%do_hfx_ri)
THEN
1203 x_data(1, 1)%general_parameter%fraction, &
1204 rho_ao=mpe, rho_ao_resp=mdum, &
1205 use_virial=use_virial, rescale_factor=fval)
1208 adiabatic_rescale_factor=fval, nspins=
SIZE(mpe, 1))
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
1216 DEALLOCATE (mpe, mhe)
1222 ALLOCATE (mpe(nsev, 1), mhe(nsev, 1))
1224 mhe(ispin, 1)%matrix => matrix_hfx(ispin)%matrix
1225 mpe(ispin, 1)%matrix => matrix_px1(ispin)%matrix
1227 IF (x_data(1, 1)%do_hfx_ri)
THEN
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)
1236 para_env, s_mstruct_changed, 1, distribute_fock_matrix, &
1237 ispin=ispin, nspins=
SIZE(mpe, 1))
1243 mhe(ispin, 1)%matrix => matrix_hfx_asymm(ispin)%matrix
1244 mpe(ispin, 1)%matrix => matrix_px1_asymm(ispin)%matrix
1246 IF (x_data(1, 1)%do_hfx_ri)
THEN
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)
1255 para_env, s_mstruct_changed, 1, distribute_fock_matrix, &
1256 ispin=ispin, nspins=
SIZE(mpe, 1))
1260 use_virial = .false.
1262 fval = 2.0_dp*real(nspins, kind=
dp)*0.5_dp
1264 IF (do_sf) fval = fval*2.0_dp
1265 IF (debug_forces) fodeb(1:3) = force(1)%fock_4c(1:3, 1)
1267 mpe(ispin, 1)%matrix => matrix_px1(ispin)%matrix
1269 IF (x_data(1, 1)%do_hfx_ri)
THEN
1271 x_data(1, 1)%general_parameter%fraction, &
1272 rho_ao=mpe, rho_ao_resp=mdum, &
1273 use_virial=use_virial, rescale_factor=fval)
1276 adiabatic_rescale_factor=fval, nspins=
SIZE(mpe, 1))
1279 mpe(ispin, 1)%matrix => matrix_px1_asymm(ispin)%matrix
1281 IF (x_data(1, 1)%do_hfx_ri)
THEN
1283 x_data(1, 1)%general_parameter%fraction, &
1284 rho_ao=mpe, rho_ao_resp=mdum, &
1285 use_virial=use_virial, rescale_factor=fval)
1288 adiabatic_rescale_factor=fval, nspins=
SIZE(mpe, 1))
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
1296 DEALLOCATE (mpe, mhe)
1298 fval = 2.0_dp*real(nspins, kind=
dp)*0.5_dp
1300 IF (do_sf) fval = fval*2.0_dp
1303 CALL dbcsr_scale(matrix_hfx_asymm(ispin)%matrix, fval)
1307 IF (gapw .OR. gapw_xc)
THEN
1316 IF (admm_env%do_gapw)
THEN
1317 IF (tddfpt_control%admm_xc_correction)
THEN
1329 cpabort(
"HFXSR not implemented")
1333 cpabort(
"HFXLR not implemented")
1337 NULLIFY (matrix_wx1)
1339 cpmos => ex_env%cpmos
1341 IF (nspins == 2) focc = 1.0_dp
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
1357 DO ispin = 1, nspins
1359 IF (nactive(ispin) == norb(ispin))
THEN
1361 DO ia = 1, nactive(ispin)
1362 cpassert(ia == gs_mos(ispin)%index_active(ia))
1369 IF (.NOT. do_sf)
THEN
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
1378 CALL cp_fm_create(cpscr, gs_mos(ispin)%mos_active%matrix_struct,
"cpscr", set_zero=.true.)
1380 CALL cp_fm_get_info(gs_mos(ispin)%mos_occ, matrix_struct=fm_struct, nrow_global=nao)
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))
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")
1390 ALLOCATE (matrix_wx1(ispin)%matrix)
1391 CALL dbcsr_create(matrix=matrix_wx1(ispin)%matrix, template=matrix_s(1)%matrix)
1393 CALL dbcsr_set(matrix_wx1(ispin)%matrix, 0.0_dp)
1396 IF (.NOT. (is_rks_triplets .OR. do_sf))
THEN
1398 cpscr, nactive(ispin), alpha=focc, beta=1.0_dp)
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)
1408 ncol=norb(ispin), alpha=2.0_dp, symmetry_mode=1)
1415 IF (.NOT. (do_sf .AND. (ispin == 2)))
THEN
1418 cpscr, nactive(ispin), alpha=focc, beta=1.0_dp)
1421 IF (.NOT. (do_sf .AND. (ispin == 1)))
THEN
1424 norb(ispin), alpha=1.0_dp, beta=0.0_dp)
1426 CALL parallel_gemm(
"T",
"N", nactive(spin), norb(ispin), nao, 1.0_dp, &
1427 mosa, vcvec, 0.0_dp, avcmat)
1429 CALL parallel_gemm(
"N",
"N", nao, norb(ispin), nactive(spin), 1.0_dp, &
1430 evect(spin), avcmat, 0.0_dp, vcvec)
1433 norb(ispin), alpha=-focc, beta=1.0_dp)
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)
1444 cpmos(ispin), norb(ispin), alpha=focc, beta=1.0_dp)
1448 alpha=1.0_dp, beta=0.0_dp)
1450 CALL parallel_gemm(
"T",
"N", norb(ispin), norb(ispin), nao, 1.0_dp, gs_mos(ispin)%mos_occ, vcvec, 0.0_dp, cvcmat)
1452 CALL parallel_gemm(
"N",
"N", nao, norb(ispin), norb(ispin), 1.0_dp, gs_mos(ispin)%mos_occ, cvcmat, 0.0_dp, vcvec)
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)
1461 IF (.NOT. (do_sf .AND. (ispin == 2)))
THEN
1464 cpscr, nactive(spin), alpha=focc, beta=1.0_dp)
1467 cpscr, nactive(spin), alpha=focc, beta=1.0_dp)
1471 IF (.NOT. (do_sf .AND. (ispin == 1)))
THEN
1474 alpha=1.0_dp, beta=0.0_dp)
1477 alpha=1.0_dp, beta=1.0_dp)
1479 CALL parallel_gemm(
"T",
"N", nactive(spin), norb(ispin), nao, 1.0_dp, &
1480 mosa, vcvec, 0.0_dp, avcmat)
1482 CALL parallel_gemm(
"N",
"N", nao, norb(ispin), nactive(spin), 1.0_dp, &
1483 evect(spin), avcmat, 0.0_dp, vcvec)
1486 norb(ispin), alpha=-focc, beta=1.0_dp)
1490 ncol=norb(ispin), alpha=2.0_dp, symmetry_mode=1)
1495 DO ia = 1, nactive(ispin)
1496 ib = gs_mos(ispin)%index_active(ia)
1500 CALL cp_fm_geadd(1.0_dp,
"N", cpscr, 1.0_dp, cpmos(ispin))
1511 IF (.NOT. (is_rks_triplets .OR. do_sf))
THEN
1515 ex_env%matrix_wx1 => matrix_wx1
1525 CALL timestop(handle)
1539 SUBROUTINE stda_force(qs_env, ex_env, gs_mos, stda_env, sub_env, work, debug_forces)
1548 LOGICAL,
INTENT(IN) :: debug_forces
1550 CHARACTER(len=*),
PARAMETER :: routinen =
'stda_force'
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, &
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
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
1577 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: gamma_matrix, matrix_plo, matrix_s, &
1586 POINTER :: n_list, sab_orb
1589 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
1595 CALL timeset(routinen, handle)
1597 cpassert(
ASSOCIATED(ex_env))
1598 cpassert(
ASSOCIATED(gs_mos))
1601 IF (logger%para_env%is_source())
THEN
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)
1615 nactive(:) = stda_env%nactive(:)
1618 IF (nspins == 2) spinfac = 1.0_dp
1619 NULLIFY (matrix_wx1)
1621 NULLIFY (matrix_plo)
1624 IF (nspins == 1 .AND. is_rks_triplets)
THEN
1625 do_coulomb = .false.
1629 do_ewald = stda_control%do_ewald
1631 CALL get_qs_env(qs_env, para_env=para_env, force=force)
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)
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)
1644 ALLOCATE (xtransformed(nspins))
1645 DO ispin = 1, nspins
1647 ct => work%ctransformed(ispin)
1649 CALL cp_fm_create(matrix=xtransformed(ispin), matrix_struct=fmstruct, name=
"XTRANSFORMED")
1653 ALLOCATE (tcharge(natom), gtcharge(natom, 4))
1655 cpmos => ex_env%cpmos
1657 DO ispin = 1, nspins
1658 ct => work%ctransformed(ispin)
1659 CALL cp_fm_get_info(ct, matrix_struct=fmstruct, nrow_global=nsgf)
1664 ALLOCATE (matrix_wx1(ispin)%matrix)
1665 CALL dbcsr_create(matrix=matrix_wx1(ispin)%matrix, template=matrix_s(1)%matrix)
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)
1671 CALL dbcsr_set(matrix_plo(ispin)%matrix, 0.0_dp)
1675 IF (do_coulomb)
THEN
1677 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
1680 DO jspin = 1, nspins
1681 ctjspin => work%ctransformed(jspin)
1683 CALL cp_fm_get_info(ctjspin, matrix_struct=fmstructjspin, nrow_global=nsgf)
1692 DO is = first_sgf(ia), last_sgf(ia)
1693 tcharge(ia) = tcharge(ia) + tv(is)
1703 NULLIFY (gamma_matrix)
1704 CALL setup_gamma(qs_env, stda_env, sub_env, gamma_matrix, ndim=4)
1705 tempmat => gamma_matrix(1)%matrix
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)
1716 row=iatom, col=jatom, block=gab, found=found)
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)
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)
1737 gtcharge, tcharge, calculate_forces, virial, use_virial)
1739 IF (para_env%is_source())
THEN
1740 gtcharge(:, 1) = gtcharge(:, 1) - 2._dp*alpha*
oorootpi*tcharge(:)
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
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
1760 CALL para_env%sum(gtcharge(:, 1))
1765 DO is = first_sgf(ia), last_sgf(ia)
1766 tv(is) = gtcharge(ia, 1)
1771 ikind = kind_of(iatom)
1772 atom_i = atom_of_kind(iatom)
1774 fij(i) = spinfac*spinfac*gtcharge(iatom, i + 1)*tcharge(iatom)
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)
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
1786 norb = nactive(ispin)
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")
1795 ct => work%ctransformed(ispin)
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)
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)
1812 CALL parallel_gemm(
'N',
'N', nsgf, nsgf, nsgf, spinfac, work%S_eigenvectors, t1matrix, &
1815 matrix_g=work%S_eigenvectors, ncol=nsgf, alpha=2.0_dp, symmetry_mode=1)
1817 DEALLOCATE (ucmatrix)
1819 DEALLOCATE (uxmatrix)
1828 ct => work%ctransformed(ispin)
1832 CALL cp_fm_get_info(cvec, matrix_struct=fmstruct, nrow_global=nao)
1836 ncol_global=norb, para_env=fmstruct%para_env)
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)
1842 nactive(ispin), alpha=-2.0_dp*spinfac, beta=1.0_dp)
1846 matrix_g=vcvec, ncol=norb, alpha=2.0_dp*alpha, symmetry_mode=1)
1853 IF (stda_env%do_exchange)
THEN
1855 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
1857 norb = nactive(ispin)
1859 tempmat => work%shalf
1860 CALL dbcsr_create(pdens, template=tempmat, matrix_type=dbcsr_type_no_symmetry)
1862 ct => work%ctransformed(ispin)
1865 1.0_dp, keep_sparsity=.false.)
1869 bp = stda_env%beta_param
1870 hfx = stda_env%hfx_fraction
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
1882 IF (hfx > 0.0_dp)
THEN
1883 gabr = (1._dp/(rbeta + (hfx*eta)**(-bp)))**(1._dp/bp)
1885 IF (dr < 1.0e-6_dp)
THEN
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
1899 dgabr = -1.0_dp/dr**3
1900 dgabr = sum(pblock**2)*dgabr
1902 atom_i = atom_of_kind(iatom)
1903 atom_j = atom_of_kind(jatom)
1905 fij(i) = dgabr*rij(i)
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)
1915 pblock = gabr*pblock
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")
1931 ct => work%ctransformed(ispin)
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)
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)
1945 CALL parallel_gemm(
'N',
'N', nsgf, nsgf, nsgf, -1.0_dp, work%S_eigenvectors, t1matrix, &
1948 matrix_g=work%S_eigenvectors, ncol=nsgf, alpha=2.0_dp, symmetry_mode=1)
1950 DEALLOCATE (ucmatrix)
1952 DEALLOCATE (uxmatrix)
1960 alpha=-xfac, beta=1.0_dp)
1962 CALL cp_fm_get_info(cvec, matrix_struct=fmstruct, nrow_global=nao)
1968 ncol_global=norb, para_env=fmstruct%para_env)
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)
1974 norb, alpha=xfac, beta=1.0_dp)
1976 IF (nspins == 2)
THEN
1983 ncol=norb, alpha=2.0_dp*alpha, symmetry_mode=1)
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
2003 DEALLOCATE (tcharge, gtcharge)
2004 DEALLOCATE (first_sgf, last_sgf)
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)
2013 IF (debug_forces) fodeb(1:3) = force(1)%overlap(1:3, 1)
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)
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
2028 ex_env%matrix_wx1 => matrix_wx1
2030 CALL timestop(handle)