115 integrate_v_core_rspace
152#include "./base/base_uses.f90"
158 LOGICAL,
PARAMETER :: debug_this_module = .true.
159 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'qs_ks_methods'
192 print_active, ext_ks_matrix, ext_xc_section)
194 LOGICAL,
INTENT(in) :: calculate_forces, just_energy
195 LOGICAL,
INTENT(IN),
OPTIONAL :: print_active
197 POINTER :: ext_ks_matrix
200 CHARACTER(LEN=*),
PARAMETER :: routinen =
'qs_ks_build_kohn_sham_matrix'
202 CHARACTER(len=default_string_length) :: name
203 INTEGER :: ace_rebuild_frequency, atom_a, handle, &
204 iatom, ikind, img, ispin, natom, &
205 nimages, nspins, output_unit
206 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: atom_of_kind, kind_of
207 LOGICAL :: ace_active, do_adiabatic_rescaling, do_ddapc, do_hfx, do_kpoints, do_ppl, dokp, &
208 gapw, gapw_xc, just_energy_xc, lrigpw, my_print, native_grid_diagnostics, &
209 native_grid_use_cuda, native_skala_restore_exc, rigpw, use_gauxc_matrix, use_virial
210 LOGICAL,
SAVE :: native_grid_cpu_kpoints_warned = .false.
211 REAL(kind=
dp) :: ecore_ppl, edisp, ee_ener, ekin_mol, &
213 native_skala_exc_scf, &
214 native_skala_total_scf, vscale
215 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: native_skala_atom_force
216 REAL(kind=
dp),
DIMENSION(3, 3) :: h_stress, pv_loc
222 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: ksmat, matrix_vxc, mo_derivs
223 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: ks_matrix, ks_matrix_im, matrix_h, &
224 matrix_h_im, matrix_s, matrix_vxc_kp, &
241 TYPE(
pw_r3d_rs_type),
DIMENSION(:),
POINTER :: rho_r, v_rspace_embed, v_rspace_new, &
242 v_rspace_new_aux_fit, v_tau_rspace, &
244 TYPE(
pw_r3d_rs_type),
POINTER :: rho0_s_rs, rho_nlcc, rhoz_cneo_s_rs, v_hartree_rspace, &
245 v_sccs_rspace, v_sic_rspace, v_spin_ddapc_rest_r, vee, vppl_rspace
248 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
250 TYPE(
qs_rho_type),
POINTER :: rho, rho1, rho_struct, rho_xc
252 adiabatic_rescaling_section, &
253 gauxc_section, hfx_sections, input, &
254 scf_section, xc_section
257 CALL timeset(routinen, handle)
258 NULLIFY (admm_env, atomic_kind_set, cell, dft_control, force, logger, mo_derivs, my_rho, &
259 rho_struct, para_env, pw_env, virial, vppl_rspace, &
261 adiabatic_rescaling_section, hfx_sections, input, scf_section, &
262 xc_section, gauxc_section, matrix_h, matrix_h_im, matrix_s, auxbas_pw_pool, poisson_env, &
263 v_rspace_new, v_rspace_new_aux_fit, v_tau_rspace, v_tau_rspace_aux_fit, matrix_vxc, &
265 vee, rho_nlcc, ks_env, ks_matrix, ks_matrix_im, rho, energy, rho_xc, rho_r, rho_ao, &
266 rho_core, particle_set, qs_kind_set, kpoints)
268 cpassert(
ASSOCIATED(qs_env))
272 IF (
PRESENT(print_active)) my_print = print_active
273 use_gauxc_matrix = .false.
274 native_skala_restore_exc = .false.
278 dft_control=dft_control, &
279 matrix_h_kp=matrix_h, &
280 matrix_h_im_kp=matrix_h_im, &
281 matrix_s_kp=matrix_s, &
282 matrix_ks_kp=ks_matrix, &
283 matrix_ks_im_kp=ks_matrix_im, &
284 matrix_vxc=matrix_vxc, &
285 matrix_vxc_kp=matrix_vxc_kp, &
288 atomic_kind_set=atomic_kind_set, &
292 v_hartree_rspace=v_hartree_rspace, &
301 do_kpoints=do_kpoints, &
302 particle_set=particle_set, &
303 qs_kind_set=qs_kind_set, &
306 CALL qs_rho_get(rho, rho_r=rho_r, rho_ao_kp=rho_ao)
308 nimages = dft_control%nimages
309 nspins = dft_control%nspins
312 IF (
PRESENT(ext_ks_matrix)) ks_matrix(1:nspins, 1:1) => ext_ks_matrix(1:nspins)
314 use_virial = virial%pv_availability .AND. (.NOT. virial%pv_numer)
317 CALL section_vals_get(adiabatic_rescaling_section, explicit=do_adiabatic_rescaling)
318 just_energy_xc = just_energy
319 IF (do_adiabatic_rescaling)
THEN
322 just_energy_xc = .true.
325 cpassert(
ASSOCIATED(matrix_h))
326 cpassert(
ASSOCIATED(matrix_s))
327 cpassert(
ASSOCIATED(rho))
328 cpassert(
ASSOCIATED(pw_env))
329 cpassert(
SIZE(ks_matrix, 1) > 0)
333 do_ddapc = dft_control%qs_control%ddapc_restraint .OR. &
334 qs_env%cp_ddapc_ewald%do_decoupling .OR. &
335 qs_env%cp_ddapc_ewald%do_qmmm_periodic_decpl .OR. &
336 qs_env%cp_ddapc_ewald%do_solvation
339 lrigpw = dft_control%qs_control%lrigpw
340 rigpw = dft_control%qs_control%rigpw
342 cpassert(nimages == 1)
344 IF (lrigpw .AND. rigpw)
THEN
345 cpabort(
" LRI and RI are not compatible")
349 gapw = dft_control%qs_control%gapw
350 gapw_xc = dft_control%qs_control%gapw_xc
351 IF (gapw_xc .AND. gapw)
THEN
352 cpabort(
" GAPW and GAPW_XC are not compatible")
354 IF ((gapw .AND. lrigpw) .OR. (gapw_xc .AND. lrigpw))
THEN
355 cpabort(
" GAPW/GAPW_XC and LRIGPW are not compatible")
357 IF ((gapw .AND. rigpw) .OR. (gapw_xc .AND. rigpw))
THEN
358 cpabort(
" GAPW/GAPW_XC and RIGPW are not compatible")
361 do_ppl = dft_control%qs_control%do_ppl_method ==
do_ppl_grid
364 CALL get_qs_env(qs_env=qs_env, vppl=vppl_rspace)
368 cpassert(
ASSOCIATED(rho_xc))
372 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool, poisson_env=poisson_env)
375 cpabort(
"The implicit Poisson solver cannot be used in conjunction with GAPW.")
379 IF (gapw .OR. gapw_xc)
THEN
384 CALL auxbas_pw_pool%create_pw(v_hartree_gspace)
385 CALL auxbas_pw_pool%create_pw(rho_tot_gspace)
389 "PRINT%DETAILED_ENERGY"), &
391 (.NOT. gapw) .AND. (.NOT. gapw_xc) .AND. &
404 IF (qs_env%scf_control%gce%do_gce .AND. .NOT. dft_control%do_pcc)
THEN
405 cpabort(
"GCE requires DFT%PLANAR_COUNTER_CHARGE to define the countercharge plane.")
409 IF (dft_control%do_pcc)
THEN
417 IF (dft_control%do_sccs)
THEN
419 NULLIFY (v_sccs_rspace)
420 ALLOCATE (v_sccs_rspace)
421 CALL auxbas_pw_pool%create_pw(v_sccs_rspace)
424 cpabort(
"The implicit Poisson solver cannot be used together with SCCS.")
427 IF (use_virial .AND. calculate_forces)
THEN
428 CALL sccs(qs_env, rho_tot_gspace, v_hartree_gspace, v_sccs_rspace, &
430 virial%pv_ehartree = virial%pv_ehartree + h_stress/real(para_env%num_pe,
dp)
431 virial%pv_virial = virial%pv_virial + h_stress/real(para_env%num_pe,
dp)
433 CALL sccs(qs_env, rho_tot_gspace, v_hartree_gspace, v_sccs_rspace)
438 IF (use_virial .AND. calculate_forces)
THEN
439 h_stress(:, :) = 0.0_dp
441 v_hartree_gspace, h_stress=h_stress, &
443 virial%pv_ehartree = virial%pv_ehartree + h_stress/real(para_env%num_pe,
dp)
444 virial%pv_virial = virial%pv_virial + h_stress/real(para_env%num_pe,
dp)
447 v_hartree_gspace, rho_core=rho_core)
451 IF (dft_control%do_paep .OR. qs_env%scf_control%gce%do_gce)
THEN
452 CALL pw_transfer(v_hartree_gspace, v_hartree_rspace)
454 qs_env%scf_control%gce%ref_esp, para_env)
459 CALL qs_ks_ddapc(qs_env, auxbas_pw_pool, rho_tot_gspace, v_hartree_gspace, &
460 v_spin_ddapc_rest_r, energy, calculate_forces, ks_matrix, &
463 dft_control%qs_control%ddapc_explicit_potential = .false.
464 dft_control%qs_control%ddapc_restraint_is_spin = .false.
465 IF (.NOT. just_energy)
THEN
466 CALL pw_transfer(v_hartree_gspace, v_hartree_rspace)
467 CALL pw_scale(v_hartree_rspace, v_hartree_rspace%pw_grid%dvol)
470 CALL auxbas_pw_pool%give_back_pw(v_hartree_gspace)
472 IF (dft_control%correct_surf_dip)
THEN
473 IF (dft_control%surf_dip_correct_switch)
THEN
475 energy%hartree = energy%hartree + energy%surf_dipole
480 CALL calc_v_sic_rspace(v_sic_rspace, energy, qs_env, dft_control, rho, poisson_env, &
481 just_energy, calculate_forces, auxbas_pw_pool)
487 IF (dft_control%apply_external_potential)
THEN
493 IF (.NOT. just_energy)
THEN
496 rho0_s_rs=rho0_s_rs, &
497 rhoz_cneo_s_rs=rhoz_cneo_s_rs)
498 cpassert(
ASSOCIATED(rho0_s_rs))
499 IF (
ASSOCIATED(rhoz_cneo_s_rs))
THEN
500 CALL pw_axpy(rhoz_cneo_s_rs, rho0_s_rs)
503 IF (
ASSOCIATED(rhoz_cneo_s_rs))
THEN
504 CALL pw_axpy(rhoz_cneo_s_rs, rho0_s_rs, -1.0_dp)
513 IF (qs_env%qmmm)
THEN
516 v_qmmm=qs_env%ks_qmmm_env%v_qmmm_rspace, &
517 qmmm_energy=energy%qmmm_el)
518 IF (qs_env%qmmm_env_qm%image_charge)
THEN
520 rho_hartree_gspace=rho_tot_gspace, &
522 qmmm_env=qs_env%qmmm_env_qm, &
524 IF (.NOT. just_energy)
THEN
526 v_metal=qs_env%ks_qmmm_env%v_metal_rspace, &
528 IF (calculate_forces)
THEN
530 potential=v_hartree_rspace, coeff=qs_env%image_coeff, &
531 forces=qs_env%qmmm_env_qm%image_charge_pot%image_forcesMM, &
532 qmmm_env=qs_env%qmmm_env_qm, qs_env=qs_env)
535 CALL qs_env%ks_qmmm_env%v_metal_rspace%release()
536 DEALLOCATE (qs_env%ks_qmmm_env%v_metal_rspace)
538 IF (.NOT. just_energy)
THEN
540 v_qmmm=qs_env%ks_qmmm_env%v_qmmm_rspace, scale=1.0_dp)
543 CALL auxbas_pw_pool%give_back_pw(rho_tot_gspace)
546 IF (dft_control%smeagol_control%smeagol_enabled .AND. &
548 cpassert(
ASSOCIATED(dft_control%smeagol_control%aux))
550 dft_control%smeagol_control%aux%HartreeLeadsLeft, &
551 dft_control%smeagol_control%aux%HartreeLeadsRight, &
552 dft_control%smeagol_control%aux%HartreeLeadsBottom, &
553 dft_control%smeagol_control%aux%VBias, &
554 dft_control%smeagol_control%aux%minL, &
555 dft_control%smeagol_control%aux%maxR, &
556 dft_control%smeagol_control%aux%isexplicit_maxR, &
557 dft_control%smeagol_control%aux%isexplicit_HartreeLeadsBottom)
561 IF (dft_control%do_admm)
THEN
562 IF (
PRESENT(ext_xc_section))
THEN
568 IF (dft_control%do_admm_mo)
THEN
569 IF (qs_env%run_rtp)
THEN
578 ELSEIF (dft_control%do_admm_dm)
THEN
584 IF (use_virial .AND. calculate_forces) virial%pv_calculate = .true.
589 IF (dft_control%do_admm)
THEN
591 xc_section => admm_env%xc_section_aux
595 CALL qs_vxc_create(ks_env=ks_env, rho_struct=rho_struct, xc_section=xc_section, &
596 vxc_rho=v_rspace_new_aux_fit, vxc_tau=v_tau_rspace_aux_fit, exc=energy%exc_aux_fit, &
597 just_energy=just_energy_xc)
599 IF (admm_env%do_gapw)
THEN
601 CALL calculate_vxc_atom(qs_env, energy_only=just_energy_xc, exc1=energy%exc1_aux_fit, &
602 kind_set_external=admm_env%admm_gapw_env%admm_kind_set, &
603 xc_section_external=xc_section, &
604 rho_atom_set_external=admm_env%admm_gapw_env%local_rho_set%rho_atom_set, &
605 calculate_forces=calculate_forces)
611 IF (use_virial .AND. calculate_forces)
THEN
614 IF (admm_env%do_admms) vscale = admm_env%gsi(1)**(2.0_dp/3.0_dp)
615 IF (admm_env%do_admmp) vscale = admm_env%gsi(1)**2
616 virial%pv_exc = virial%pv_exc - vscale*virial%pv_xc
617 virial%pv_virial = virial%pv_virial - vscale*virial%pv_xc
620 xc_section => admm_env%xc_section_primary
624 IF (
PRESENT(ext_xc_section)) xc_section => ext_xc_section
628 CALL get_qs_env(qs_env=qs_env, rho_xc=rho_struct)
630 CALL get_qs_env(qs_env=qs_env, rho=rho_struct)
634 IF (dft_control%apply_external_density .OR. dft_control%apply_external_vxc)
THEN
639 IF (dft_control%apply_embed_pot)
THEN
640 NULLIFY (v_rspace_embed)
641 energy%embed_corr = 0.0_dp
643 energy%embed_corr, just_energy)
647 IF (dft_control%use_gauxc)
THEN
650 IF ((.NOT. do_kpoints) .AND. nimages /= 1)
THEN
651 CALL cp_abort(__location__, &
652 "Native SKALA grid evaluation supports multiple images only "// &
653 "for k-point calculations.")
656 cpassert(
ASSOCIATED(kpoints))
658 cpassert(
ASSOCIATED(gauxc_section))
660 IF (.NOT. native_grid_use_cuda)
THEN
661 IF (para_env%mepos == 0 .AND. .NOT. native_grid_cpu_kpoints_warned)
THEN
662 CALL cp_warn(__location__, &
663 "Native SKALA grid evaluation with k-points is using the CPU TorchScript "// &
664 "path. For CPU runs, preload libtorch_cpu.so before OpenBLAS if the "// &
665 "runtime library order is unstable; otherwise use NATIVE_GRID_USE_CUDA T.")
666 native_grid_cpu_kpoints_warned = .true.
670 IF (dft_control%roks)
THEN
671 cpabort(
"Native SKALA grid evaluation does not support ROKS.")
673 IF (dft_control%do_admm)
THEN
674 cpabort(
"Native SKALA grid evaluation does not support ADMM.")
679 native_skala_restore_exc = calculate_forces .AND. .NOT. use_virial
680 IF (native_skala_restore_exc)
THEN
681 native_skala_exc_scf = energy%exc
682 native_skala_total_scf = energy%total
684 IF (calculate_forces)
THEN
685 ALLOCATE (native_skala_atom_force(3, natom))
686 CALL qs_vxc_create(ks_env=ks_env, rho_struct=rho_struct, xc_section=xc_section, &
687 vxc_rho=v_rspace_new, vxc_tau=v_tau_rspace, exc=energy%exc, &
688 edisp=edisp, dispersion_env=qs_env%dispersion_env, &
689 just_energy=just_energy_xc, &
690 native_skala_atom_force=native_skala_atom_force)
691 native_grid_diagnostics = .false.
693 IF (
ASSOCIATED(gauxc_section))
THEN
695 l_val=native_grid_diagnostics)
697 IF (native_grid_diagnostics .AND. para_env%mepos == 0)
THEN
699 IF (output_unit > 0)
THEN
701 WRITE (unit=output_unit, fmt=
"(T2,A,1X,I0,3(1X,ES20.12))") &
702 "SKALA_GPW| Native atom force", iatom, native_skala_atom_force(:, iatom)
706 cpassert(
ASSOCIATED(force))
707 cpassert(
ASSOCIATED(atomic_kind_set))
710 ikind = kind_of(iatom)
711 atom_a = atom_of_kind(iatom)
712 force(ikind)%rho_elec(:, atom_a) = force(ikind)%rho_elec(:, atom_a) + &
713 native_skala_atom_force(:, iatom)
715 DEALLOCATE (atom_of_kind, kind_of, native_skala_atom_force)
717 CALL qs_vxc_create(ks_env=ks_env, rho_struct=rho_struct, xc_section=xc_section, &
718 vxc_rho=v_rspace_new, vxc_tau=v_tau_rspace, exc=energy%exc, &
719 edisp=edisp, dispersion_env=qs_env%dispersion_env, &
720 just_energy=just_energy_xc)
722 IF (native_skala_restore_exc) energy%exc = native_skala_exc_scf
723 IF (gapw .OR. gapw_xc)
THEN
725 xc_section_external=xc_section, &
726 calculate_forces=calculate_forces)
728 IF (edisp /= 0.0_dp) energy%dispersion = edisp
729 IF (qs_env%requires_matrix_vxc .AND.
ASSOCIATED(v_rspace_new))
THEN
732 CALL set_ks_env(ks_env, matrix_vxc_kp=matrix_vxc_kp)
735 CALL set_ks_env(ks_env, matrix_vxc=matrix_vxc)
739 use_gauxc_matrix = .true.
740 CALL apply_gauxc(qs_env, xc_section, calculate_forces)
743 xc_section_external=xc_section, &
744 calculate_forces=calculate_forces)
748 CALL qs_vxc_create(ks_env=ks_env, rho_struct=rho_struct, xc_section=xc_section, &
749 vxc_rho=v_rspace_new, vxc_tau=v_tau_rspace, exc=energy%exc, &
750 edisp=edisp, dispersion_env=qs_env%dispersion_env, &
751 just_energy=just_energy_xc)
752 IF (edisp /= 0.0_dp) energy%dispersion = edisp
753 IF (qs_env%requires_matrix_vxc .AND.
ASSOCIATED(v_rspace_new))
THEN
755 CALL set_ks_env(ks_env, matrix_vxc=matrix_vxc)
758 IF (gapw .OR. gapw_xc)
THEN
760 xc_section_external=xc_section, &
761 calculate_forces=calculate_forces)
767 IF (qs_env%harris_method)
THEN
768 CALL get_qs_env(qs_env, harris_env=harris_env)
773 IF (use_virial .AND. calculate_forces)
THEN
774 virial%pv_exc = virial%pv_exc - virial%pv_xc
775 virial%pv_virial = virial%pv_virial - virial%pv_xc
783 ace_rebuild_frequency = 1
787 IF (
ASSOCIATED(ace_section))
THEN
796 cpabort(
"ACE-HFX for k-points is not implemented yet")
805 just_energy, v_rspace_new, v_tau_rspace, &
806 ace_rebuild_frequency, ext_xc_section=xc_section)
808 CALL hfx_ks_matrix(qs_env, ks_matrix, rho, energy, calculate_forces, &
809 just_energy, v_rspace_new, v_tau_rspace, ext_xc_section=xc_section)
814 IF (do_ppl .AND. calculate_forces)
THEN
817 CALL integrate_ppl_rspace(rho_r(ispin), qs_env)
821 IF (
ASSOCIATED(rho_nlcc) .AND. calculate_forces)
THEN
823 CALL integrate_rho_nlcc(v_rspace_new(ispin), qs_env)
824 IF (dft_control%do_admm)
CALL integrate_rho_nlcc(v_rspace_new_aux_fit(ispin), qs_env)
829 IF (dft_control%qs_control%do_kg .AND. just_energy)
THEN
831 cpassert(nimages == 1)
832 ksmat => ks_matrix(:, 1)
833 CALL kg_ekin_subset(qs_env, ksmat, ekin_mol, calculate_forces, do_kernel=.false.)
836 energy%exc = energy%exc - ekin_mol
841 IF (.NOT. just_energy)
THEN
842 IF (calculate_forces)
THEN
845 (poisson_env%parameters%dielectric_params%dielec_core_correction))
THEN
848 CALL auxbas_pw_pool%create_pw(v_minus_veps)
849 CALL pw_copy(v_hartree_rspace, v_minus_veps)
850 CALL pw_axpy(poisson_env%implicit_env%v_eps, v_minus_veps, -v_hartree_rspace%pw_grid%dvol)
851 CALL integrate_v_core_rspace(v_minus_veps, qs_env)
852 CALL auxbas_pw_pool%give_back_pw(v_minus_veps)
855 CALL integrate_v_core_rspace(v_hartree_rspace, qs_env)
859 IF (.NOT. do_hfx)
THEN
865 CALL dbcsr_copy(ks_matrix(ispin, img)%matrix, matrix_h(1, img)%matrix, name=name)
869 IF (qs_env%run_rtp)
THEN
870 IF (dft_control%rtp_control%velocity_gauge)
THEN
871 cpassert(
ASSOCIATED(matrix_h_im))
872 cpassert(
ASSOCIATED(ks_matrix_im))
876 CALL dbcsr_copy(ks_matrix_im(ispin, img)%matrix, matrix_h_im(1, img)%matrix, name=name)
883 IF (use_virial .AND. calculate_forces)
THEN
884 pv_loc = virial%pv_virial
891 v_rspace_new, v_rspace_new_aux_fit, v_tau_rspace, v_tau_rspace_aux_fit, &
892 v_sic_rspace, v_spin_ddapc_rest_r, v_sccs_rspace, v_rspace_embed, &
893 cdft_control, calculate_forces)
895 IF (use_gauxc_matrix)
THEN
897 CALL get_qs_env(qs_env=qs_env, matrix_vxc_kp=matrix_vxc_kp)
898 cpassert(
ASSOCIATED(matrix_vxc_kp))
901 CALL dbcsr_add(ks_matrix(ispin, img)%matrix, matrix_vxc_kp(ispin, img)%matrix, &
906 CALL get_qs_env(qs_env=qs_env, matrix_vxc=matrix_vxc)
907 cpassert(
ASSOCIATED(matrix_vxc))
908 cpassert(nimages == 1)
910 CALL dbcsr_add(ks_matrix(ispin, 1)%matrix, matrix_vxc(ispin)%matrix, 1.0_dp, 1.0_dp)
915 IF (gapw .OR. gapw_xc)
THEN
916 IF (calculate_forces)
THEN
918 CALL get_qs_env(qs_env=qs_env, rho_xc=rho_struct)
920 CALL get_qs_env(qs_env=qs_env, rho=rho_struct)
923 IF (dft_control%use_gauxc .AND. (gapw .OR. gapw_xc) .AND. &
935 IF (dft_control%do_admm)
THEN
937 xc_section => admm_env%xc_section_aux
940 IF (admm_env%do_admmp)
THEN
941 vscale = admm_env%gsi(1)**2
942 ELSE IF (admm_env%do_admms)
THEN
943 vscale = admm_env%gsi(1)**(2.0_dp/3.0_dp)
950 IF (use_virial .AND. calculate_forces)
THEN
951 virial%pv_ehartree = virial%pv_ehartree + (virial%pv_virial - pv_loc)
953 IF (dft_control%qs_control%do_kg)
THEN
954 cpassert(nimages == 1)
955 ksmat => ks_matrix(:, 1)
957 IF (use_virial .AND. calculate_forces)
THEN
958 pv_loc = virial%pv_virial
961 CALL kg_ekin_subset(qs_env, ksmat, ekin_mol, calculate_forces, do_kernel=.false.)
963 energy%exc = energy%exc - ekin_mol
966 IF (use_virial .AND. calculate_forces)
THEN
969 virial%pv_ehartree = virial%pv_ehartree + (virial%pv_virial - pv_loc)
972 virial%pv_exc = virial%pv_exc + virial%pv_xc
973 virial%pv_virial = virial%pv_virial + virial%pv_xc
974 virial%pv_xc = 0.0_dp
981 cpwarn(
"KS matrix no longer correct. Check possible problems with property calculations!")
985 IF (dft_control%qs_control%ddapc_explicit_potential)
THEN
986 CALL auxbas_pw_pool%give_back_pw(v_spin_ddapc_rest_r)
987 DEALLOCATE (v_spin_ddapc_rest_r)
990 IF (calculate_forces .AND. dft_control%qs_control%cdft)
THEN
991 IF (.NOT. cdft_control%transfer_pot)
THEN
992 DO iatom = 1,
SIZE(cdft_control%group)
993 CALL auxbas_pw_pool%give_back_pw(cdft_control%group(iatom)%weight)
994 DEALLOCATE (cdft_control%group(iatom)%weight)
996 IF (cdft_control%atomic_charges)
THEN
997 DO iatom = 1, cdft_control%natoms
998 CALL auxbas_pw_pool%give_back_pw(cdft_control%charge(iatom))
1000 DEALLOCATE (cdft_control%charge)
1003 cdft_control%becke_control%cavity_confine)
THEN
1004 IF (.NOT.
ASSOCIATED(cdft_control%becke_control%cavity_mat))
THEN
1005 CALL auxbas_pw_pool%give_back_pw(cdft_control%becke_control%cavity)
1007 DEALLOCATE (cdft_control%becke_control%cavity_mat)
1010 IF (
ASSOCIATED(cdft_control%hirshfeld_control%hirshfeld_env%fnorm))
THEN
1011 CALL auxbas_pw_pool%give_back_pw(cdft_control%hirshfeld_control%hirshfeld_env%fnorm)
1014 IF (
ASSOCIATED(cdft_control%charges_fragment))
DEALLOCATE (cdft_control%charges_fragment)
1015 cdft_control%save_pot = .false.
1016 cdft_control%need_pot = .true.
1017 cdft_control%external_control = .false.
1021 IF (dft_control%do_sccs)
THEN
1022 CALL auxbas_pw_pool%give_back_pw(v_sccs_rspace)
1023 DEALLOCATE (v_sccs_rspace)
1027 IF (dft_control%apply_external_potential)
THEN
1030 v_qmmm=vee, scale=-1.0_dp)
1035 CALL get_qs_env(qs_env, ecoul_1c=ecoul_1c, local_rho_set=local_rho_set)
1036 CALL vh_1c_gg_integrals(qs_env, energy%hartree_1c, ecoul_1c, local_rho_set, para_env, tddft=.false., &
1039 energy%core_cneo = 0.0_dp
1040 IF (
ASSOCIATED(local_rho_set%rhoz_cneo_set))
THEN
1041 DO iatom = 1,
SIZE(local_rho_set%rhoz_cneo_set)
1042 energy%core_cneo = energy%core_cneo + local_rho_set%rhoz_cneo_set(iatom)%e_core
1047 IF (gapw .OR. gapw_xc)
THEN
1050 IF (dft_control%do_admm)
THEN
1059 ks_matrix, matrix_s, rho, mulliken_order_p)
1062 IF (dft_control%dft_plus_u)
THEN
1063 IF (just_energy)
THEN
1064 CALL plus_u(qs_env=qs_env)
1066 CALL plus_u(qs_env=qs_env, matrix_h=ks_matrix)
1069 energy%dft_plus_u = 0.0_dp
1073 DO ispin = 1, nspins
1076 dft_control%qs_control%eps_filter_matrix)
1081 IF (dft_control%do_admm_mo)
THEN
1082 IF (qs_env%run_rtp)
THEN
1087 ELSEIF (dft_control%do_admm_dm)
THEN
1098 IF (qs_env%requires_mo_derivs .AND. .NOT. just_energy .AND. .NOT. qs_env%run_rtp)
THEN
1100 cpassert(nimages == 1)
1101 ksmat => ks_matrix(:, 1)
1102 CALL calc_mo_derivatives(qs_env, ksmat, mo_derivs)
1106 IF (calculate_forces .AND. dft_control%do_admm)
THEN
1115 CALL low_spin_roks(energy, qs_env, dft_control, do_hfx, just_energy, &
1116 calculate_forces, auxbas_pw_pool)
1120 calculate_forces, auxbas_pw_pool)
1127 energy, calculate_forces, just_energy)
1132 DO ispin = 1, nspins
1133 ecore_ppl = ecore_ppl +
pw_integral_ab(vppl_rspace, rho_r(ispin))
1135 energy%core = energy%core + ecore_ppl
1140 CALL get_qs_env(qs_env, lri_env=lri_env, lri_density=lri_density)
1141 IF (lri_env%ppl_ri)
THEN
1143 DO ispin = 1, nspins
1144 lri_v_int => lri_density%lri_coefs(ispin)%lri_kinds
1147 energy%core = energy%core + ecore_ppl
1152 energy%total = energy%core_overlap + energy%core_self + energy%core_cneo + energy%core + &
1153 energy%hartree + energy%hartree_1c + energy%exc + energy%exc1 + energy%ex + &
1154 energy%dispersion + energy%gcp + energy%qmmm_el + energy%mulliken + &
1155 sum(energy%ddapc_restraint) + energy%s2_restraint + &
1156 energy%dft_plus_u + energy%kTS + &
1157 energy%efield + energy%efield_core + energy%ee + &
1158 energy%ee_core + energy%exc_aux_fit + energy%image_charge + &
1159 energy%sccs_pol + energy%cdft + energy%exc1_aux_fit
1161 IF (dft_control%apply_embed_pot) energy%total = energy%total + energy%embed_corr
1163 IF (native_skala_restore_exc) energy%total = native_skala_total_scf
1166 cpabort(
"KS energy is an abnormal value (NaN/Inf).")
1173 CALL timestop(handle)
1185 TYPE(pw_c1d_gs_type),
INTENT(INOUT) :: rho_tot_gspace
1186 TYPE(qs_environment_type),
POINTER :: qs_env
1187 TYPE(qs_rho_type),
POINTER :: rho
1188 LOGICAL,
INTENT(IN),
OPTIONAL :: skip_nuclear_density
1192 TYPE(dft_control_type),
POINTER :: dft_control
1193 TYPE(pw_c1d_gs_type),
DIMENSION(:),
POINTER :: rho_g
1194 TYPE(pw_c1d_gs_type),
POINTER :: rho0_s_gs, rho_core, rhoz_cneo_s_gs
1195 TYPE(qs_charges_type),
POINTER :: qs_charges
1198 IF (
PRESENT(skip_nuclear_density)) my_skip = skip_nuclear_density
1200 CALL qs_rho_get(rho, rho_g=rho_g)
1201 CALL get_qs_env(qs_env=qs_env, dft_control=dft_control)
1203 IF (.NOT. my_skip)
THEN
1205 CALL get_qs_env(qs_env=qs_env, rho_core=rho_core)
1206 IF (dft_control%qs_control%gapw)
THEN
1207 NULLIFY (rho0_s_gs, rhoz_cneo_s_gs)
1208 CALL get_qs_env(qs_env=qs_env, rho0_s_gs=rho0_s_gs, rhoz_cneo_s_gs=rhoz_cneo_s_gs)
1209 cpassert(
ASSOCIATED(rho0_s_gs))
1210 CALL pw_copy(rho0_s_gs, rho_tot_gspace)
1211 IF (
ASSOCIATED(rhoz_cneo_s_gs))
THEN
1212 CALL pw_axpy(rhoz_cneo_s_gs, rho_tot_gspace)
1214 IF (dft_control%qs_control%gapw_control%nopaw_as_gpw)
THEN
1215 CALL pw_axpy(rho_core, rho_tot_gspace)
1218 CALL pw_copy(rho_core, rho_tot_gspace)
1220 DO ispin = 1, dft_control%nspins
1221 CALL pw_axpy(rho_g(ispin), rho_tot_gspace)
1223 CALL get_qs_env(qs_env=qs_env, qs_charges=qs_charges)
1224 qs_charges%total_rho_gspace = pw_integrate_function(rho_tot_gspace, isign=-1)
1226 DO ispin = 1, dft_control%nspins
1227 CALL pw_axpy(rho_g(ispin), rho_tot_gspace)
1243 SUBROUTINE calc_mo_derivatives(qs_env, ks_matrix, mo_derivs)
1244 TYPE(qs_environment_type),
POINTER :: qs_env
1245 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: ks_matrix, mo_derivs
1248 LOGICAL :: uniform_occupation
1249 REAL(kind=dp),
DIMENSION(:),
POINTER :: occupation_numbers
1250 TYPE(cp_fm_type),
POINTER :: mo_coeff
1251 TYPE(dbcsr_type) :: mo_derivs2_tmp1, mo_derivs2_tmp2
1252 TYPE(dbcsr_type),
POINTER :: mo_coeff_b
1253 TYPE(dft_control_type),
POINTER :: dft_control
1254 TYPE(mo_set_type),
DIMENSION(:),
POINTER :: mo_array
1256 NULLIFY (dft_control, mo_array, mo_coeff, mo_coeff_b, occupation_numbers)
1258 CALL get_qs_env(qs_env, &
1259 dft_control=dft_control, &
1262 DO ispin = 1,
SIZE(mo_derivs)
1264 CALL get_mo_set(mo_set=mo_array(ispin), mo_coeff=mo_coeff, &
1265 mo_coeff_b=mo_coeff_b, occupation_numbers=occupation_numbers)
1266 CALL dbcsr_multiply(
'n',
'n', 1.0_dp, ks_matrix(ispin)%matrix, mo_coeff_b, &
1267 0.0_dp, mo_derivs(ispin)%matrix)
1269 IF (dft_control%restricted)
THEN
1271 cpassert(ispin == 1)
1272 cpassert(
SIZE(mo_array) == 2)
1277 CALL get_mo_set(mo_set=mo_array(1), uniform_occupation=uniform_occupation)
1278 cpassert(uniform_occupation)
1279 CALL get_mo_set(mo_set=mo_array(2), uniform_occupation=uniform_occupation)
1280 cpassert(uniform_occupation)
1284 CALL get_mo_set(mo_set=mo_array(2), mo_coeff_b=mo_coeff_b)
1285 CALL dbcsr_create(mo_derivs2_tmp1, template=mo_coeff_b)
1288 CALL dbcsr_multiply(
'n',
'n', 1.0_dp, ks_matrix(2)%matrix, mo_coeff_b, 0.0_dp, mo_derivs2_tmp1)
1291 CALL dbcsr_create(mo_derivs2_tmp2, template=mo_derivs(1)%matrix)
1292 CALL dbcsr_set(mo_derivs2_tmp2, 0.0_dp)
1295 CALL dbcsr_copy_columns_hack(mo_derivs2_tmp2, mo_derivs2_tmp1, &
1296 mo_array(2)%nmo, 1, 1, &
1297 para_env=mo_array(1)%mo_coeff%matrix_struct%para_env, &
1298 blacs_env=mo_array(1)%mo_coeff%matrix_struct%context)
1301 CALL dbcsr_add(mo_derivs(1)%matrix, mo_derivs2_tmp2, 1.0_dp, 1.0_dp)
1302 CALL dbcsr_release(mo_derivs2_tmp1)
1303 CALL dbcsr_release(mo_derivs2_tmp2)
1307 IF (dft_control%do_admm_mo)
THEN
1308 CALL calc_admm_mo_derivatives(qs_env, mo_derivs)
1311 END SUBROUTINE calc_mo_derivatives
1329 TYPE(qs_environment_type),
POINTER :: qs_env
1330 LOGICAL,
INTENT(IN),
OPTIONAL :: calculate_forces, just_energy, &
1333 CHARACTER(LEN=*),
PARAMETER :: routinen =
'qs_ks_update_qs_env'
1335 INTEGER :: handle, unit_nr
1336 LOGICAL :: c_forces, do_rebuild, energy_only, &
1337 forces_up_to_date, potential_changed, &
1338 rho_changed, s_mstruct_changed
1339 TYPE(qs_ks_env_type),
POINTER :: ks_env
1342 unit_nr = cp_logger_get_default_io_unit()
1345 energy_only = .false.
1346 IF (
PRESENT(just_energy)) energy_only = just_energy
1347 IF (
PRESENT(calculate_forces)) c_forces = calculate_forces
1350 CALL timeset(routinen//
'_forces', handle)
1352 CALL timeset(routinen, handle)
1355 cpassert(
ASSOCIATED(qs_env))
1357 CALL get_qs_env(qs_env, &
1359 rho_changed=rho_changed, &
1360 s_mstruct_changed=s_mstruct_changed, &
1361 potential_changed=potential_changed, &
1362 forces_up_to_date=forces_up_to_date)
1364 do_rebuild = .false.
1365 do_rebuild = do_rebuild .OR. rho_changed
1366 do_rebuild = do_rebuild .OR. s_mstruct_changed
1367 do_rebuild = do_rebuild .OR. potential_changed
1368 do_rebuild = do_rebuild .OR. (c_forces .AND. .NOT. forces_up_to_date)
1370 IF (do_rebuild)
THEN
1374 CALL set_ks_env(ks_env, potential_changed=.false.)
1377 calculate_forces=c_forces, &
1378 just_energy=energy_only, &
1379 print_active=print_active)
1381 IF (.NOT. energy_only)
THEN
1382 CALL set_ks_env(ks_env, &
1383 rho_changed=.false., &
1384 s_mstruct_changed=.false., &
1385 forces_up_to_date=forces_up_to_date .OR. c_forces)
1389 CALL timestop(handle)
1400 TYPE(qs_environment_type),
POINTER :: qs_env
1401 TYPE(dbcsr_p_type),
DIMENSION(:, :),
OPTIONAL, &
1402 POINTER :: rho_ao_ext
1404 CHARACTER(LEN=*),
PARAMETER :: routinen =
'evaluate_core_matrix_traces'
1407 REAL(kind=dp) :: energy_core_im
1408 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrixkp_h, matrixkp_t, rho_ao_kp
1409 TYPE(dft_control_type),
POINTER :: dft_control
1410 TYPE(qs_energy_type),
POINTER :: energy
1411 TYPE(qs_rho_type),
POINTER :: rho
1413 CALL timeset(routinen, handle)
1414 NULLIFY (energy, rho, dft_control, rho_ao_kp, matrixkp_t, matrixkp_h)
1416 CALL get_qs_env(qs_env, &
1419 dft_control=dft_control, &
1420 kinetic_kp=matrixkp_t, &
1421 matrix_h_kp=matrixkp_h)
1423 IF (
PRESENT(rho_ao_ext))
THEN
1424 rho_ao_kp => rho_ao_ext
1426 CALL qs_rho_get(rho, rho_ao_kp=rho_ao_kp)
1429 CALL calculate_ptrace(matrixkp_h, rho_ao_kp, energy%core, dft_control%nspins)
1432 IF (qs_env%run_rtp)
THEN
1433 IF (dft_control%rtp_control%velocity_gauge)
THEN
1434 CALL get_qs_env(qs_env, matrix_h_im_kp=matrixkp_h)
1435 CALL qs_rho_get(rho, rho_ao_im_kp=rho_ao_kp)
1436 CALL calculate_ptrace(matrixkp_h, rho_ao_kp, energy_core_im, dft_control%nspins)
1437 energy%core = energy%core - energy_core_im
1442 IF (
ASSOCIATED(matrixkp_t)) &
1443 CALL calculate_ptrace(matrixkp_t, rho_ao_kp, energy%kinetic, dft_control%nspins)
1445 CALL timestop(handle)
1457 TYPE(qs_environment_type),
POINTER :: qs_env
1458 LOGICAL,
INTENT(IN) :: calculate_forces, just_energy
1459 LOGICAL,
INTENT(IN),
OPTIONAL :: print_active
1461 CHARACTER(LEN=*),
PARAMETER :: routinen =
'rebuild_ks_matrix'
1464 TYPE(dft_control_type),
POINTER :: dft_control
1466 CALL timeset(routinen, handle)
1467 NULLIFY (dft_control)
1469 CALL get_qs_env(qs_env, dft_control=dft_control)
1471 IF (dft_control%qs_control%semi_empirical)
THEN
1472 CALL build_se_fock_matrix(qs_env, &
1473 calculate_forces=calculate_forces, &
1474 just_energy=just_energy)
1476 ELSEIF (dft_control%qs_control%dftb)
THEN
1477 CALL build_dftb_ks_matrix(qs_env, &
1478 calculate_forces=calculate_forces, &
1479 just_energy=just_energy)
1481 ELSEIF (dft_control%qs_control%xtb)
THEN
1482 IF (dft_control%qs_control%xtb_control%do_tblite)
THEN
1483 CALL build_tblite_ks_matrix(qs_env, &
1484 calculate_forces=calculate_forces, &
1485 just_energy=just_energy)
1487 CALL build_xtb_ks_matrix(qs_env, &
1488 calculate_forces=calculate_forces, &
1489 just_energy=just_energy)
1493 calculate_forces=calculate_forces, &
1494 just_energy=just_energy, &
1495 print_active=print_active)
1498 CALL timestop(handle)
1512 TYPE(qs_environment_type),
POINTER :: qs_env
1513 LOGICAL,
INTENT(in) :: is_complex
1515 CHARACTER(LEN=default_string_length) :: headline
1516 INTEGER :: ic, ispin, nimages, nspins
1517 LOGICAL :: do_kpoints
1518 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_s_kp, matrixkp_im_ks, matrixkp_ks
1519 TYPE(dbcsr_type),
POINTER :: refmatrix
1520 TYPE(dft_control_type),
POINTER :: dft_control
1521 TYPE(kpoint_type),
POINTER :: kpoints
1522 TYPE(neighbor_list_set_p_type),
DIMENSION(:), &
1524 TYPE(qs_ks_env_type),
POINTER :: ks_env
1526 NULLIFY (dft_control, ks_env, matrix_s_kp, sab_orb, matrixkp_ks, refmatrix, matrixkp_im_ks, kpoints)
1528 CALL get_qs_env(qs_env, &
1529 dft_control=dft_control, &
1530 matrix_s_kp=matrix_s_kp, &
1533 do_kpoints=do_kpoints, &
1534 matrix_ks_kp=matrixkp_ks, &
1535 matrix_ks_im_kp=matrixkp_im_ks)
1537 IF (do_kpoints)
THEN
1538 CALL get_kpoint_info(kpoints, sab_nl=sab_orb)
1540 CALL get_qs_env(qs_env, sab_orb=sab_orb)
1543 nspins = dft_control%nspins
1544 nimages = dft_control%nimages
1546 IF (.NOT.
ASSOCIATED(matrixkp_ks))
THEN
1547 CALL dbcsr_allocate_matrix_set(matrixkp_ks, nspins, nimages)
1548 refmatrix => matrix_s_kp(1, 1)%matrix
1549 DO ispin = 1, nspins
1551 IF (nspins > 1)
THEN
1552 IF (ispin == 1)
THEN
1553 headline =
"KOHN-SHAM MATRIX FOR ALPHA SPIN"
1555 headline =
"KOHN-SHAM MATRIX FOR BETA SPIN"
1558 headline =
"KOHN-SHAM MATRIX"
1560 ALLOCATE (matrixkp_ks(ispin, ic)%matrix)
1561 CALL dbcsr_create(matrix=matrixkp_ks(ispin, ic)%matrix, template=refmatrix, &
1562 name=trim(headline), matrix_type=dbcsr_type_symmetric)
1563 CALL cp_dbcsr_alloc_block_from_nbl(matrixkp_ks(ispin, ic)%matrix, sab_orb)
1564 CALL dbcsr_set(matrixkp_ks(ispin, ic)%matrix, 0.0_dp)
1567 CALL set_ks_env(ks_env, matrix_ks_kp=matrixkp_ks)
1570 IF (is_complex)
THEN
1571 IF (.NOT.
ASSOCIATED(matrixkp_im_ks))
THEN
1572 cpassert(nspins ==
SIZE(matrixkp_ks, 1))
1573 cpassert(nimages ==
SIZE(matrixkp_ks, 2))
1574 CALL dbcsr_allocate_matrix_set(matrixkp_im_ks, nspins, nimages)
1575 DO ispin = 1, nspins
1577 IF (nspins > 1)
THEN
1578 IF (ispin == 1)
THEN
1579 headline =
"IMAGINARY KOHN-SHAM MATRIX FOR ALPHA SPIN"
1581 headline =
"IMAGINARY KOHN-SHAM MATRIX FOR BETA SPIN"
1584 headline =
"IMAGINARY KOHN-SHAM MATRIX"
1586 ALLOCATE (matrixkp_im_ks(ispin, ic)%matrix)
1587 refmatrix => matrixkp_ks(ispin, ic)%matrix
1588 CALL dbcsr_create(matrix=matrixkp_im_ks(ispin, ic)%matrix, template=refmatrix, &
1589 name=trim(headline), matrix_type=dbcsr_type_antisymmetric)
1590 CALL cp_dbcsr_alloc_block_from_nbl(matrixkp_im_ks(ispin, ic)%matrix, sab_orb)
1591 CALL dbcsr_set(matrixkp_im_ks(ispin, ic)%matrix, 0.0_dp)
1594 CALL set_ks_env(ks_env, matrix_ks_im_kp=matrixkp_im_ks)
subroutine, public accint_weight_force(qs_env, rho, rho1, order, xc_section, triplet, force_scale)
...
Contains ADMM methods which only require the density matrix.
subroutine, public admm_dm_merge_ks_matrix(qs_env)
Entry methods: Merges auxiliary Kohn-Sham matrix into primary one.
subroutine, public admm_dm_calc_rho_aux(qs_env)
Entry methods: Calculates auxiliary density matrix from primary one.
Contains ADMM methods which require molecular orbitals.
subroutine, public admm_mo_calc_rho_aux_kp(qs_env)
...
subroutine, public admm_mo_merge_ks_matrix(qs_env)
...
subroutine, public admm_update_ks_atom(qs_env, calculate_forces)
Adds the GAPW exchange contribution to the aux_fit ks matrices.
subroutine, public calc_admm_ovlp_forces_kp(qs_env)
Calculate the forces due to the AUX/ORB basis overlap in ADMM, in the KP case.
subroutine, public admm_mo_calc_rho_aux(qs_env)
...
subroutine, public calc_admm_ovlp_forces(qs_env)
Calculate the forces due to the AUX/ORB basis overlap in ADMM.
subroutine, public calc_admm_mo_derivatives(qs_env, mo_derivs)
Calculate the derivative of the AUX_FIT mo, based on the ORB mo_derivs.
Types and set/get functions for auxiliary density matrix methods.
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.
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.
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
subroutine, public dbcsr_copy(matrix_b, matrix_a, name, keep_sparsity, keep_imaginary)
...
subroutine, public dbcsr_multiply(transa, transb, alpha, matrix_a, matrix_b, beta, matrix_c, first_row, last_row, first_column, last_column, first_k, last_k, retain_sparsity, filter_eps, flop)
...
subroutine, public dbcsr_get_info(matrix, nblkrows_total, nblkcols_total, nfullrows_total, nfullcols_total, nblkrows_local, nblkcols_local, nfullrows_local, nfullcols_local, my_prow, my_pcol, local_rows, local_cols, proc_row_dist, proc_col_dist, row_blk_size, col_blk_size, row_blk_offset, col_blk_offset, distribution, name, matrix_type, group)
...
subroutine, public dbcsr_filter(matrix, eps)
...
subroutine, public dbcsr_set(matrix, alpha)
...
subroutine, public dbcsr_release(matrix)
...
subroutine, public dbcsr_add(matrix_a, matrix_b, alpha_scalar, beta_scalar)
...
Routines that link DBCSR and CP2K concepts together.
subroutine, public cp_dbcsr_alloc_block_from_nbl(matrix, sab_orb, desymmetrize)
allocate the blocks of a dbcsr based on the neighbor list
DBCSR operations in CP2K.
subroutine, public dbcsr_copy_columns_hack(matrix_b, matrix_a, ncol, source_start, target_start, para_env, blacs_env)
hack for dbcsr_copy_columns
Density Derived atomic point charges from a QM calculation (see Bloechl, J. Chem. Phys....
subroutine, public qs_ks_ddapc(qs_env, auxbas_pw_pool, rho_tot_gspace, v_hartree_gspace, v_spin_ddapc_rest_r, energy, calculate_forces, ks_matrix, just_energy)
Set of methods using DDAPC charges.
represent a full matrix distributed on many processors
various routines to log and control the output. The idea is that decisions about where to log should ...
integer function, public cp_logger_get_default_io_unit(logger)
returns the unit nr for the ionode (-1 on all other processors) skips as well checks if the procs cal...
type(cp_logger_type) function, pointer, public cp_get_default_logger()
returns the default logger
routines to handle the output, The idea is to remove the decision of wheter to output and what to out...
integer, parameter, public cp_p_file
integer function, public cp_print_key_should_output(iteration_info, basis_section, print_key_path, used_print_key, first_time)
returns what should be done with the given property if btest(res,cp_p_store) then the property should...
Add the DFT+U contribution to the Hamiltonian matrix.
subroutine, public plus_u(qs_env, matrix_h, matrix_w)
Add the DFT+U contribution to the Hamiltonian matrix. Wrapper routine for all "+U" methods.
subroutine, public planar_averaged_v_hartree_3d(v_rspace, dft_control, do_gce, ref_esp, para_env)
calculate the planar averaged real space potential (e.g. Hartree potential) along the surface normal ...
subroutine, public planar_counter_charge(rho_tot_gspace, pcc_env, auxbas_pw_pool)
add the planar counter charge density to the total charge density
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...
Adaptively Compressed Exchange (ACE) operator for HFX. Reference: Lin, J. Chem. Theory Comput....
subroutine, public hfx_ace_ks_matrix(qs_env, ks_matrix, rho, energy, calculate_forces, just_energy, v_rspace_new, v_tau_rspace, ace_rebuild_frequency, ext_xc_section)
Main ACE entry point, replacing hfx_ks_matrix in qs_ks_methods.
Utilities for hfx and admm methods.
subroutine, public hfx_admm_init(qs_env, calculate_forces, ext_xc_section)
...
subroutine, public hfx_ks_matrix(qs_env, matrix_ks, rho, energy, calculate_forces, just_energy, v_rspace_new, v_tau_rspace, ext_xc_section)
Add the hfx contributions to the Hamiltonian.
subroutine, public hfx_ks_matrix_kp(qs_env, matrix_ks, energy, calculate_forces)
Add the HFX K-point contribution to the real-space Hamiltonians.
Routines for a Kim-Gordon-like partitioning into molecular subunits.
subroutine, public kg_ekin_subset(qs_env, ks_matrix, ekin_mol, calc_force, do_kernel, pmat_ext)
Calculates the subsystem Hohenberg-Kohn kinetic energy and the forces.
Defines the basic variable types.
integer, parameter, public dp
integer, parameter, public default_string_length
Types and basic routines needed for a kpoint calculation.
subroutine, public get_kpoint_info(kpoint, kp_scheme, nkp_grid, kp_shift, symmetry, verbose, full_grid, use_real_wfn, eps_geo, parallel_group_size, kp_range, nkp, xkp, wkp, para_env, blacs_env_all, para_env_kp, para_env_inter_kp, blacs_env, kp_env, kp_aux_env, mpools, iogrp, nkp_groups, kp_dist, cell_to_index, index_to_cell, sab_nl, sab_nl_nosym, inversion_symmetry_only, symmetry_backend, symmetry_reduction_method, gamma_centered)
Retrieve information from a kpoint environment.
Calculates integral matrices for LRIGPW method lri : local resolution of the identity.
subroutine, public v_int_ppl_energy(qs_env, lri_v_int, ecore_ppl_ri)
...
contains the types and subroutines for dealing with the lri_env lri : local resolution of the identit...
Collection of simple mathematical functions and subroutines.
logical function, public abnormal_value(a)
determines if a value is not normal (e.g. for Inf and Nan) based on IO to work also under optimizatio...
Interface to the message passing library MPI.
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
integer, parameter, public pw_poisson_implicit
Manages a pool of grids (to be used for example as tmp objects), but can also be used to instantiate ...
Routines for image charge calculation within QM/MM.
subroutine, public calculate_image_pot(v_hartree_rspace, rho_hartree_gspace, energy, qmmm_env, qs_env)
determines coefficients by solving image_matrix*coeff=-pot_const by Gaussian elimination or in an ite...
subroutine, public integrate_potential_devga_rspace(potential, coeff, forces, qmmm_env, qs_env)
calculates the image forces on the MM atoms
subroutine, public add_image_pot_to_hartree_pot(v_hartree, v_metal, qs_env)
Add potential of metal (image charge pot) to Hartree Potential.
Defines CDFT control structures.
container for information about total charges on the grids
Calculation of the energies concerning the core charge distribution.
Calculation of Overlap and Hamiltonian matrices in DFTB.
subroutine, public build_dftb_ks_matrix(qs_env, calculate_forces, just_energy)
...
Calculates the energy contribution and the mo_derivative of a static periodic electric field.
subroutine, public qs_efield_berry_phase(qs_env, just_energy, calculate_forces)
...
Calculates the energy contribution and the mo_derivative of a static electric field (nonperiodic)
subroutine, public qs_efield_local_operator(qs_env, just_energy, calculate_forces)
...
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 prepare_gapw_den(qs_env, local_rho_set, do_rho0, kind_set_external, pw_env_sub)
...
Types needed for a for a Harris model calculation.
Harris method environment setup and handling.
subroutine, public harris_set_potentials(harris_env, vh_rspace, vxc_rspace)
...
Integrate single or product functions over a potential on a RS grid.
Define the quickstep kind type and their sub types.
Set of routines to apply restraints to the KS hamiltonian.
subroutine, public qs_ks_s2_restraint(dft_control, qs_env, matrix_s, energy, calculate_forces, just_energy)
...
subroutine, public qs_ks_mulliken_restraint(energy, dft_control, just_energy, para_env, ks_matrix, matrix_s, rho, mulliken_order_p)
...
subroutine, public qs_ks_cdft_constraint(qs_env, auxbas_pw_pool, calculate_forces, cdft_control)
Apply a CDFT constraint.
routines that build the Kohn-Sham matrix contributions coming from local atomic densities
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...
routines that build the Kohn-Sham matrix (i.e calculate the coulomb and xc parts
subroutine, public rebuild_ks_matrix(qs_env, calculate_forces, just_energy, print_active)
Constructs a new Khon-Sham matrix.
subroutine, public evaluate_core_matrix_traces(qs_env, rho_ao_ext)
Calculates the traces of the core matrices and the density matrix.
subroutine, public qs_ks_update_qs_env(qs_env, calculate_forces, just_energy, print_active)
updates the Kohn Sham matrix of the given qs_env (facility method)
subroutine, public qs_ks_allocate_basics(qs_env, is_complex)
Allocate ks_matrix if necessary, take current overlap matrix as template.
subroutine, public calc_rho_tot_gspace(rho_tot_gspace, qs_env, rho, skip_nuclear_density)
...
subroutine, public qs_ks_build_kohn_sham_matrix(qs_env, calculate_forces, just_energy, print_active, ext_ks_matrix, ext_xc_section)
routine where the real calculations are made: the KS matrix is calculated
subroutine, public qmmm_calculate_energy(qs_env, rho, v_qmmm, qmmm_energy)
Computes the contribution to the total energy of the QM/MM electrostatic coupling.
subroutine, public qmmm_modify_hartree_pot(v_hartree, v_qmmm, scale)
Modify the hartree potential in order to include the QM/MM correction.
subroutine, public set_ks_env(ks_env, v_hartree_rspace, s_mstruct_changed, rho_changed, exc_accint, potential_changed, forces_up_to_date, complex_ks, matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, kinetic, matrix_s, matrix_s_ri_aux, matrix_w, matrix_p_mp2, matrix_p_mp2_admm, matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, matrix_s_ri_aux_kp, matrix_ks_im_kp, vppl, xcint_weights, rho_core, rho_nlcc, rho_nlcc_g, vee, neighbor_list_id, kpoints, sab_orb, sab_all, sac_ae, sac_ppl, sac_lri, sap_ppnl, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, sab_xb, sab_xtb_pp, sab_xtb_nonbond, sab_vdw, sab_scp, sab_almo, sab_kp, sab_kp_nosym, sab_cneo, task_list, task_list_soft, subsys, dft_control, dbcsr_dist, distribution_2d, pw_env, para_env, blacs_env)
...
routines that build the Kohn-Sham matrix (i.e calculate the coulomb and xc parts
subroutine, public print_densities(qs_env, rho)
...
subroutine, public get_embed_potential_energy(qs_env, rho, v_rspace_embed, dft_control, embed_corr, just_energy)
...
subroutine, public compute_matrix_vxc_kp(qs_env, v_rspace, matrix_vxc_kp)
Build the XC potential matrix for k-point/image-resolved KS matrices.
subroutine, public low_spin_roks(energy, qs_env, dft_control, do_hfx, just_energy, calculate_forces, auxbas_pw_pool)
do ROKS calculations yielding low spin states
subroutine, public sum_up_and_integrate(qs_env, ks_matrix, rho, my_rho, vppl_rspace, v_rspace_new, v_rspace_new_aux_fit, v_tau_rspace, v_tau_rspace_aux_fit, v_sic_rspace, v_spin_ddapc_rest_r, v_sccs_rspace, v_rspace_embed, cdft_control, calculate_forces)
Sum up all potentials defined on the grid and integrate.
subroutine, public print_detailed_energy(qs_env, dft_control, input, energy, mulliken_order_p)
Print detailed energies.
subroutine, public calculate_zmp_potential(qs_env, v_rspace_new, rho, exc)
Calculate the ZMP potential and energy as in Zhao, Morrison Parr PRA 50i, 2138 (1994) V_c^\lambda def...
subroutine, public calc_v_sic_rspace(v_sic_rspace, energy, qs_env, dft_control, rho, poisson_env, just_energy, calculate_forces, auxbas_pw_pool)
do sic calculations on the spin density
subroutine, public sic_explicit_orbitals(energy, qs_env, dft_control, poisson_env, just_energy, calculate_forces, auxbas_pw_pool)
do sic calculations on explicit orbitals
subroutine, public compute_matrix_vxc(qs_env, v_rspace, matrix_vxc)
compute matrix_vxc, defined via the potential created by qs_vxc_create ignores things like tau functi...
Definition and initialisation of the mo data type.
subroutine, public get_mo_set(mo_set, maxocc, homo, lfomo, nao, nelectron, n_el_f, nmo, eigenvalues, occupation_numbers, mo_coeff, mo_coeff_b, uniform_occupation, kts, mu, flexible_electron_count)
Get the components of a MO set data structure.
Define the neighbor list data types and the corresponding functionality.
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)
...
superstucture that hold various representations of the density and keeps track of which ones are vali...
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...
Self-consistent continuum solvation (SCCS) model implementation.
subroutine, public sccs(qs_env, rho_tot_gspace, v_hartree_gspace, v_sccs, h_stress)
Self-consistent continuum solvation (SCCS) model implementation.
routines that build the integrals of the Vxc potential calculated for the atomic density in the basis...
subroutine, public calculate_vxc_atom(qs_env, energy_only, exc1, adiabatic_rescale_factor, kind_set_external, rho_atom_set_external, xc_section_external, calculate_forces)
...
subroutine, public qs_vxc_create(ks_env, rho_struct, xc_section, vxc_rho, vxc_tau, exc, just_energy, edisp, dispersion_env, adiabatic_rescale_factor, pw_env_external, native_skala_atom_force)
calculates and allocates the xc potential, already reducing it to the dependence on rho and the one o...
Utilities for rtp in combination with admm methods adapted routines from admm_method (author Manuel G...
subroutine, public rtp_admm_merge_ks_matrix(qs_env)
...
subroutine, public rtp_admm_calc_rho_aux(qs_env)
Compute the ADMM density matrix in case of rtp (complex MO's)
Calculation of the Fock matrix for SE methods.
subroutine, public build_se_fock_matrix(qs_env, calculate_forces, just_energy)
Construction of the Fock matrix for NDDO methods.
Experimental CP2K-native GPW real-space-grid path for SKALA TorchScript models.
subroutine, public ensure_native_skala_grid_scope(xc_section)
Enforce the currently implemented native SKALA GPW input scope.
type(section_vals_type) function, pointer, public get_gauxc_section(xc_section)
Return the first GAUXC functional subsection, if present.
logical function, public xc_section_uses_native_skala_grid(xc_section)
Return true if the GAUXC subsection requests the CP2K-native GPW grid path.
subroutine, public smeagol_shift_v_hartree(v_hartree_rspace, cell, hartreeleadsleft, hartreeleadsright, hartreeleadsbottom, vbias, zleft, zright, isexplicit_zright, isexplicit_bottom)
Align Hatree potential of semi-infinite leads to match bulk-transport calculation and apply external ...
subroutine, public calc_dipsurf_potential(qs_env, energy)
compute the surface dipole and the correction to the hartree potential
subroutine, public build_tblite_ks_matrix(qs_env, calculate_forces, just_energy, ext_ks_matrix)
...
logical function, public gauxc_gapw_has_paw_pseudopotentials(qs_kind_set)
Return whether GauXC GAPW mode sees pseudopotential one-center GAPW kinds.
subroutine, public apply_gauxc(qs_env, xc_section, calculate_forces)
...
Calculation of KS matrix in xTB Reference: Stefan Grimme, Christoph Bannwarth, Philip Shushkov JCTC 1...
subroutine, public build_xtb_ks_matrix(qs_env, calculate_forces, just_energy, ext_ks_matrix)
...
stores some data used in wavefunction fitting
Provides all information about an atomic kind.
Type defining parameters related to the simulation cell.
type of a logger, at the moment it contains just a print level starting at which level it should be l...
Contains information about kpoints.
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 ...
Container for information about total charges on the grids.
Contains information on the Harris method.
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.