160 integrate_v_core_rspace,&
213#include "./base/base_uses.f90"
221 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'energy_corrections'
242 LOGICAL,
INTENT(IN),
OPTIONAL :: ec_init, calculate_forces
244 CHARACTER(len=*),
PARAMETER :: routinen =
'energy_correction'
246 INTEGER :: handle, unit_nr
247 LOGICAL :: my_calc_forces
254 CALL timeset(routinen, handle)
257 IF (logger%para_env%is_source())
THEN
269 IF (.NOT. ec_env%do_skip)
THEN
271 ec_env%should_update = .true.
272 IF (
PRESENT(ec_init)) ec_env%should_update = ec_init
274 my_calc_forces = .false.
275 IF (
PRESENT(calculate_forces)) my_calc_forces = calculate_forces
277 IF (ec_env%should_update)
THEN
278 ec_env%old_etotal = 0.0_dp
279 ec_env%etotal = 0.0_dp
280 ec_env%eband = 0.0_dp
281 ec_env%ehartree = 0.0_dp
285 ec_env%edispersion = 0.0_dp
286 ec_env%exc_aux_fit = 0.0_dp
289 ec_env%ehartree_1c = 0.0_dp
290 ec_env%exc1_aux_fit = 0.0_dp
294 ec_env%old_etotal = energy%total
298 IF (my_calc_forces)
THEN
299 IF (unit_nr > 0)
THEN
300 WRITE (unit_nr,
'(T2,A,A,A,A,A)')
"!", repeat(
"-", 25), &
301 " Energy Correction Forces ", repeat(
"-", 26),
"!"
303 CALL get_qs_env(qs_env, force=ks_force, virial=virial)
307 IF (unit_nr > 0)
THEN
308 WRITE (unit_nr,
'(T2,A,A,A,A,A)')
"!", repeat(
"-", 29), &
309 " Energy Correction ", repeat(
"-", 29),
"!"
314 CALL energy_correction_low(qs_env, ec_env, my_calc_forces, unit_nr)
317 IF (ec_env%should_update)
THEN
318 energy%nonscf_correction = ec_env%etotal - ec_env%old_etotal
319 energy%total = ec_env%etotal
322 IF (.NOT. my_calc_forces .AND. unit_nr > 0)
THEN
323 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Energy Correction ", energy%nonscf_correction
325 IF (unit_nr > 0)
THEN
326 WRITE (unit_nr,
'(T2,A,A,A)')
"!", repeat(
"-", 77),
"!"
333 IF (unit_nr > 0)
THEN
334 WRITE (unit_nr,
'(T2,A,A,A)')
"!", repeat(
"-", 77),
"!"
335 WRITE (unit_nr,
'(T2,A,A,A,A,A)')
"!", repeat(
"-", 26), &
336 " Skip Energy Correction ", repeat(
"-", 27),
"!"
337 WRITE (unit_nr,
'(T2,A,A,A)')
"!", repeat(
"-", 77),
"!"
342 CALL timestop(handle)
357 SUBROUTINE energy_correction_low(qs_env, ec_env, calculate_forces, unit_nr)
360 LOGICAL,
INTENT(IN) :: calculate_forces
361 INTEGER,
INTENT(IN) :: unit_nr
363 INTEGER :: ispin, nkind, nspins
364 LOGICAL :: debug_f, gapw, gapw_xc
365 REAL(kind=
dp) :: eps_fit, exc
373 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
375 IF (ec_env%should_update)
THEN
376 CALL ec_build_neighborlist(qs_env, ec_env)
382 ec_env%vtau_rspace, &
383 ec_env%vadmm_rspace, &
384 ec_env%ehartree, exc, &
385 vadmm_tau_rspace=ec_env%vadmm_tau_rspace)
387 ec_env%local_rho_set_admm, ec_env%vh_rspace)
389 SELECT CASE (ec_env%energy_functional)
392 CALL ec_build_core_hamiltonian(qs_env, ec_env)
393 CALL ec_build_ks_matrix(qs_env, ec_env)
396 cpassert(.NOT. ec_env%do_kpoints)
399 NULLIFY (ec_env%mao_coef)
401 max_iter=ec_env%mao_max_iter, eps_grad=ec_env%mao_eps_grad, &
402 eps1_mao=ec_env%mao_eps1, iolevel=ec_env%mao_iolevel, unit_nr=unit_nr)
405 CALL ec_ks_solver(qs_env, ec_env)
407 CALL evaluate_ec_core_matrix_traces(qs_env, ec_env)
409 IF (ec_env%write_harris_wfn)
THEN
410 CALL harris_wfn_output(qs_env, ec_env, unit_nr)
414 cpassert(.NOT. ec_env%do_kpoints)
417 CALL ec_dc_energy(qs_env, ec_env, calculate_forces=.false.)
422 CALL ec_build_ks_matrix(qs_env, ec_env)
425 cpassert(.NOT. ec_env%do_kpoints)
430 cpabort(
"unknown energy correction")
434 CALL ec_disp(qs_env, ec_env, calculate_forces=.false.)
437 CALL ec_energy(ec_env, unit_nr)
441 IF (calculate_forces)
THEN
443 debug_f = ec_env%debug_forces .OR. ec_env%debug_stress
445 CALL get_qs_env(qs_env=qs_env, dft_control=dft_control)
446 nspins = dft_control%nspins
447 gapw = dft_control%qs_control%gapw
448 gapw_xc = dft_control%qs_control%gapw_xc
449 IF (gapw .OR. gapw_xc)
THEN
451 qs_kind_set=qs_kind_set, particle_set=particle_set)
452 NULLIFY (oce, sap_oce)
453 CALL get_qs_env(qs_env=qs_env, oce=oce, sap_oce=sap_oce)
456 eps_fit = dft_control%qs_control%gapw_control%eps_fit
462 CALL ec_disp(qs_env, ec_env, calculate_forces=.true.)
464 SELECT CASE (ec_env%energy_functional)
467 CALL ec_build_core_hamiltonian_force(qs_env, ec_env, &
471 CALL ec_build_ks_matrix_force(qs_env, ec_env)
472 IF (ec_env%debug_external)
THEN
473 CALL write_response_interface(qs_env, ec_env)
474 CALL init_response_deriv(qs_env, ec_env)
479 cpassert(.NOT. ec_env%do_kpoints)
482 CALL ec_dc_energy(qs_env, ec_env, calculate_forces=.true.)
484 CALL ec_build_core_hamiltonian_force(qs_env, ec_env, &
488 CALL ec_dc_build_ks_matrix_force(qs_env, ec_env)
489 IF (ec_env%debug_external)
THEN
490 CALL write_response_interface(qs_env, ec_env)
491 CALL init_response_deriv(qs_env, ec_env)
496 cpassert(.NOT. ec_env%do_kpoints)
498 CALL init_response_deriv(qs_env, ec_env)
501 ec_env%matrix_w(1, 1)%matrix, unit_nr, &
502 ec_env%debug_forces, ec_env%debug_stress)
505 cpabort(
"unknown energy correction")
508 IF (ec_env%do_error)
THEN
509 ALLOCATE (ec_env%cpref(nspins))
511 CALL cp_fm_create(ec_env%cpref(ispin), ec_env%cpmos(ispin)%matrix_struct)
512 CALL cp_fm_to_fm(ec_env%cpmos(ispin), ec_env%cpref(ispin))
522 cpassert(
ASSOCIATED(pw_env))
523 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
524 ALLOCATE (ec_env%rhoz_r(nspins))
526 CALL auxbas_pw_pool%create_pw(ec_env%rhoz_r(ispin))
530 vh_rspace=ec_env%vh_rspace, &
531 vxc_rspace=ec_env%vxc_rspace, &
532 vtau_rspace=ec_env%vtau_rspace, &
533 vadmm_rspace=ec_env%vadmm_rspace, &
534 vadmm_tau_rspace=ec_env%vadmm_tau_rspace, &
535 matrix_hz=ec_env%matrix_hz, &
536 matrix_pz=ec_env%matrix_z, &
537 matrix_pz_admm=ec_env%z_admm, &
538 matrix_wz=ec_env%matrix_wz, &
539 rhopz_r=ec_env%rhoz_r, &
540 zehartree=ec_env%ehartree, &
542 zexc_aux_fit=ec_env%exc_aux_fit, &
543 p_env=ec_env%p_env, &
546 CALL output_response_deriv(qs_env, ec_env, unit_nr)
548 CALL ec_properties(qs_env, ec_env)
550 IF (ec_env%do_error)
THEN
551 CALL response_force_error(qs_env, ec_env, unit_nr)
555 IF (
ASSOCIATED(ec_env%rhoout_r))
THEN
557 CALL auxbas_pw_pool%give_back_pw(ec_env%rhoout_r(ispin))
559 DEALLOCATE (ec_env%rhoout_r)
561 IF (
ASSOCIATED(ec_env%rhoz_r))
THEN
563 CALL auxbas_pw_pool%give_back_pw(ec_env%rhoz_r(ispin))
565 DEALLOCATE (ec_env%rhoz_r)
581 END SUBROUTINE energy_correction_low
589 SUBROUTINE write_response_interface(qs_env, ec_env)
596 NULLIFY (trexio_section)
600 CALL write_trexio(qs_env, trexio_section, ec_env%matrix_hz)
602 END SUBROUTINE write_response_interface
610 SUBROUTINE init_response_deriv(qs_env, ec_env)
620 ALLOCATE (ec_env%rf(3, natom))
623 CALL get_qs_env(qs_env, force=force, virial=virial)
625 CALL get_qs_env(qs_env, atomic_kind_set=atomic_kind_set)
628 IF (virial%pv_availability .AND. (.NOT. virial%pv_numer))
THEN
629 ec_env%rpv = virial%pv_virial
632 END SUBROUTINE init_response_deriv
641 SUBROUTINE output_response_deriv(qs_env, ec_env, unit_nr)
644 INTEGER,
INTENT(IN) :: unit_nr
646 CHARACTER(LEN=default_string_length) :: unit_string
647 INTEGER :: funit, ia, natom
648 REAL(kind=
dp) :: evol, fconv
649 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: ftot
657 IF (
ASSOCIATED(ec_env%rf))
THEN
659 ALLOCATE (ftot(3, natom))
661 CALL get_qs_env(qs_env, force=force, virial=virial, para_env=para_env)
663 CALL get_qs_env(qs_env, atomic_kind_set=atomic_kind_set)
665 ec_env%rf(1:3, 1:natom) = ftot(1:3, 1:natom) - ec_env%rf(1:3, 1:natom)
666 CALL para_env%sum(ec_env%rf)
669 IF (virial%pv_availability .AND. (.NOT. virial%pv_numer))
THEN
670 ec_env%rpv = virial%pv_virial - ec_env%rpv
671 CALL para_env%sum(ec_env%rpv)
673 evol = ec_env%exc + ec_env%exc_aux_fit + 2.0_dp*ec_env%ehartree
674 ec_env%rpv(1, 1) = ec_env%rpv(1, 1) - evol
675 ec_env%rpv(2, 2) = ec_env%rpv(2, 2) - evol
676 ec_env%rpv(3, 3) = ec_env%rpv(3, 3) - evol
679 CALL get_qs_env(qs_env, particle_set=particle_set, cell=cell)
683 IF (unit_nr > 0)
THEN
684 WRITE (unit_nr,
'(/,T2,A)')
"Write EXTERNAL Response Derivative: "//trim(ec_env%exresult_fn)
686 CALL open_file(ec_env%exresult_fn, file_status=
"REPLACE", file_form=
"FORMATTED", &
687 file_action=
"WRITE", unit_number=funit)
688 WRITE (funit,
"(T8,A,T58,A)")
"COORDINATES [Bohr]",
"RESPONSE FORCES [Hartree/Bohr]"
690 WRITE (funit,
"(2(3F15.8,5x))") particle_set(ia)%r(1:3), ec_env%rf(1:3, ia)
693 WRITE (funit,
"(T8,A,T58,A)")
"CELL [Bohr]",
"RESPONSE PRESSURE [GPa]"
695 WRITE (funit,
"(3F15.8,5x,3F15.8)") cell%hmat(ia, 1:3), -fconv*ec_env%rpv(ia, 1:3)
702 END SUBROUTINE output_response_deriv
711 SUBROUTINE evaluate_ec_core_matrix_traces(qs_env, ec_env)
715 CHARACTER(LEN=*),
PARAMETER :: routinen =
'evaluate_ec_core_matrix_traces'
721 CALL timeset(routinen, handle)
724 CALL get_qs_env(qs_env, dft_control=dft_control, energy=energy)
727 CALL calculate_ptrace(ec_env%matrix_h, ec_env%matrix_p, energy%core, dft_control%nspins)
730 CALL calculate_ptrace(ec_env%matrix_t, ec_env%matrix_p, energy%kinetic, dft_control%nspins)
732 CALL timestop(handle)
734 END SUBROUTINE evaluate_ec_core_matrix_traces
747 SUBROUTINE ec_dc_energy(qs_env, ec_env, calculate_forces)
750 LOGICAL,
INTENT(IN) :: calculate_forces
752 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ec_dc_energy'
754 CHARACTER(LEN=default_string_length) :: headline
755 INTEGER :: handle, ispin, nspins
756 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_h, matrix_p, matrix_s, matrix_w
762 CALL timeset(routinen, handle)
764 NULLIFY (dft_control, ks_env, matrix_h, matrix_p, matrix_s, matrix_w, rho)
766 dft_control=dft_control, &
768 matrix_h_kp=matrix_h, &
769 matrix_s_kp=matrix_s, &
770 matrix_w_kp=matrix_w, &
773 nspins = dft_control%nspins
778 matrix_name=
"OVERLAP MATRIX", &
779 basis_type_a=
"HARRIS", &
780 basis_type_b=
"HARRIS", &
781 sab_nl=ec_env%sab_orb)
786 headline =
"CORE HAMILTONIAN MATRIX"
787 ALLOCATE (ec_env%matrix_h(1, 1)%matrix)
788 CALL dbcsr_create(ec_env%matrix_h(1, 1)%matrix, name=trim(headline), &
789 template=matrix_s(1, 1)%matrix, matrix_type=dbcsr_type_symmetric)
791 CALL dbcsr_copy(ec_env%matrix_h(1, 1)%matrix, matrix_h(1, 1)%matrix)
796 headline =
"DENSITY MATRIX"
798 ALLOCATE (ec_env%matrix_p(ispin, 1)%matrix)
799 CALL dbcsr_create(ec_env%matrix_p(ispin, 1)%matrix, name=trim(headline), &
800 template=matrix_s(1, 1)%matrix, matrix_type=dbcsr_type_symmetric)
802 CALL dbcsr_copy(ec_env%matrix_p(ispin, 1)%matrix, matrix_p(ispin, 1)%matrix)
805 IF (calculate_forces)
THEN
810 headline =
"ENERGY-WEIGHTED DENSITY MATRIX"
812 ALLOCATE (ec_env%matrix_w(ispin, 1)%matrix)
813 CALL dbcsr_create(ec_env%matrix_w(ispin, 1)%matrix, name=trim(headline), &
814 template=matrix_s(1, 1)%matrix, matrix_type=dbcsr_type_symmetric)
816 CALL dbcsr_copy(ec_env%matrix_w(ispin, 1)%matrix, matrix_w(ispin, 1)%matrix)
823 ec_env%ekTS = energy%ktS
826 ec_env%efield_nuclear = 0.0_dp
827 ec_env%efield_elec = 0.0_dp
830 CALL timestop(handle)
832 END SUBROUTINE ec_dc_energy
843 SUBROUTINE ec_dc_build_ks_matrix_force(qs_env, ec_env)
847 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ec_dc_build_ks_matrix_force'
849 CHARACTER(LEN=default_string_length) :: basis_type, unit_string
850 INTEGER :: handle, i, iounit, ispin, natom, nspins
851 LOGICAL :: debug_forces, debug_stress, do_ec_hfx, &
852 gapw, gapw_xc, use_virial
853 REAL(
dp) :: dummy_real, dummy_real2(2), edisp, &
854 ehartree, ehartree_1c, eovrl, exc, &
856 REAL(
dp),
ALLOCATABLE,
DIMENSION(:, :) :: ftot
857 REAL(
dp),
DIMENSION(3) :: fodeb, fodeb2
858 REAL(kind=
dp),
DIMENSION(3, 3) :: h_stress, pv_loc, stdeb, sttot
863 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_s, scrm
864 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_p
878 TYPE(
pw_r3d_rs_type),
DIMENSION(:),
POINTER :: rho_r, v_rspace, v_rspace_in, &
882 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
884 TYPE(
qs_rho_type),
POINTER :: rho, rho1, rho_struct, rho_xc
889 CALL timeset(routinen, handle)
891 debug_forces = ec_env%debug_forces
892 debug_stress = ec_env%debug_stress
895 IF (logger%para_env%is_source())
THEN
901 NULLIFY (atomic_kind_set, cell, dft_control, force, ks_env, &
902 matrix_p, matrix_s, para_env, pw_env, rho, rho_nlcc, sab_orb, virial)
905 dft_control=dft_control, &
915 cpassert(
ASSOCIATED(pw_env))
917 nspins = dft_control%nspins
918 use_virial = virial%pv_availability .AND. (.NOT. virial%pv_numer)
920 fconv = 1.0e-9_dp*
pascal/cell%deth
921 IF (debug_stress .AND. use_virial)
THEN
922 sttot = virial%pv_virial
926 gapw = dft_control%qs_control%gapw
927 gapw_xc = dft_control%qs_control%gapw_xc
929 cpassert(
ASSOCIATED(rho_xc))
931 IF (gapw .OR. gapw_xc)
THEN
933 cpabort(
"DC-DFT + GAPW + Stress NYA")
940 NULLIFY (hartree_local, local_rho_set)
941 IF (gapw .OR. gapw_xc)
THEN
943 atomic_kind_set=atomic_kind_set, &
944 qs_kind_set=qs_kind_set)
947 qs_kind_set, dft_control, para_env)
950 CALL init_rho0(local_rho_set, qs_env, dft_control%qs_control%gapw_control)
956 CALL get_qs_env(qs_env=qs_env, oce=oce, sab_orb=sab_orb)
958 qs_kind_set, oce, sab_orb, para_env)
962 NULLIFY (auxbas_pw_pool, poisson_env)
964 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool, &
965 poisson_env=poisson_env)
968 CALL auxbas_pw_pool%create_pw(v_hartree_gspace)
969 CALL auxbas_pw_pool%create_pw(rho_tot_gspace)
970 CALL auxbas_pw_pool%create_pw(v_hartree_rspace)
979 h_stress(:, :) = 0.0_dp
981 density=rho_tot_gspace, &
983 vhartree=v_hartree_gspace, &
986 virial%pv_ehartree = virial%pv_ehartree + h_stress/real(para_env%num_pe,
dp)
987 virial%pv_virial = virial%pv_virial + h_stress/real(para_env%num_pe,
dp)
989 IF (debug_stress)
THEN
990 stdeb = fconv*(h_stress/real(para_env%num_pe,
dp))
991 CALL para_env%sum(stdeb)
992 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1001 CALL pw_transfer(v_hartree_gspace, v_hartree_rspace)
1002 CALL pw_scale(v_hartree_rspace, v_hartree_rspace%pw_grid%dvol)
1006 ALLOCATE (ec_env%rhoout_r(nspins))
1007 DO ispin = 1, nspins
1008 CALL auxbas_pw_pool%create_pw(ec_env%rhoout_r(ispin))
1009 CALL pw_copy(rho_r(ispin), ec_env%rhoout_r(ispin))
1014 IF (debug_forces) fodeb(1:3) = force(1)%rho_core(1:3, 1)
1015 IF (debug_stress .AND. use_virial) stdeb = virial%pv_ehartree
1016 CALL integrate_v_core_rspace(v_hartree_rspace, qs_env)
1017 IF (debug_forces)
THEN
1018 fodeb(1:3) = force(1)%rho_core(1:3, 1) - fodeb(1:3)
1019 CALL para_env%sum(fodeb)
1020 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Vtot*dncore", fodeb
1022 IF (debug_stress .AND. use_virial)
THEN
1023 stdeb = fconv*(virial%pv_ehartree - stdeb)
1024 CALL para_env%sum(stdeb)
1025 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1031 NULLIFY (v_rspace, v_tau_rspace)
1034 IF (use_virial) virial%pv_calculate = .true.
1038 CALL get_qs_env(qs_env=qs_env, rho_xc=rho_struct)
1040 CALL get_qs_env(qs_env=qs_env, rho=rho_struct)
1042 CALL qs_vxc_create(ks_env=ks_env, rho_struct=rho_struct, xc_section=ec_env%xc_section, &
1043 vxc_rho=v_rspace, vxc_tau=v_tau_rspace, exc=exc, just_energy=.false., &
1044 edisp=edisp, dispersion_env=ec_env%dispersion_env)
1046 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
1047 IF (debug_stress .AND. use_virial) stdeb = virial%pv_virial
1052 IF (debug_forces)
THEN
1053 fodeb(1:3) = force(1)%rho_elec(1:3, 1) - fodeb(1:3)
1054 CALL para_env%sum(fodeb)
1055 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Fxc*dw ", fodeb
1057 IF (debug_stress .AND. use_virial)
THEN
1058 stdeb = fconv*(virial%pv_virial - stdeb)
1059 CALL para_env%sum(stdeb)
1060 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1064 IF (.NOT.
ASSOCIATED(v_rspace))
THEN
1065 ALLOCATE (v_rspace(nspins))
1066 DO ispin = 1, nspins
1067 CALL auxbas_pw_pool%create_pw(v_rspace(ispin))
1072 IF (use_virial)
THEN
1073 virial%pv_exc = virial%pv_exc - virial%pv_xc
1074 virial%pv_virial = virial%pv_virial - virial%pv_xc
1081 DO ispin = 1, nspins
1082 ALLOCATE (scrm(ispin)%matrix)
1083 CALL dbcsr_create(scrm(ispin)%matrix, template=ec_env%matrix_ks(ispin, 1)%matrix)
1084 CALL dbcsr_copy(scrm(ispin)%matrix, ec_env%matrix_ks(ispin, 1)%matrix)
1085 CALL dbcsr_set(scrm(ispin)%matrix, 0.0_dp)
1088 pw_grid => v_hartree_rspace%pw_grid
1089 ALLOCATE (v_rspace_in(nspins))
1090 DO ispin = 1, nspins
1091 CALL v_rspace_in(ispin)%create(pw_grid)
1095 DO ispin = 1, nspins
1097 CALL pw_transfer(ec_env%vxc_rspace(ispin), v_rspace_in(ispin))
1098 IF (.NOT. gapw_xc)
THEN
1102 CALL pw_axpy(ec_env%vh_rspace, v_rspace_in(ispin))
1112 IF ((gapw .OR. gapw_xc) .AND. ec_env%do_ec_admm)
THEN
1116 cpabort(
"GAPW HFX ADMM + Energy Correction NYA")
1120 IF (debug_forces) fodeb(1:3) = force(1)%fock_4c(1:3, 1)
1121 IF (debug_forces) fodeb2(1:3) = force(1)%overlap_admm(1:3, 1)
1128 hfx_sections=ec_hfx_sections, &
1129 x_data=ec_env%x_data, &
1131 do_admm=ec_env%do_ec_admm, &
1132 calc_forces=.true., &
1133 reuse_hfx=ec_env%reuse_hfx, &
1134 do_im_time=.false., &
1135 e_ex_from_gw=dummy_real, &
1136 e_admm_from_gw=dummy_real2, &
1139 IF (debug_forces)
THEN
1140 fodeb(1:3) = force(1)%fock_4c(1:3, 1) - fodeb(1:3)
1141 CALL para_env%sum(fodeb)
1142 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: P*hfx_DC ", fodeb
1144 fodeb2(1:3) = force(1)%overlap_admm(1:3, 1) - fodeb2(1:3)
1145 CALL para_env%sum(fodeb2)
1146 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: P*hfx_DC*S ", fodeb2
1148 IF (debug_stress .AND. use_virial)
THEN
1149 stdeb = -1.0_dp*fconv*virial%pv_fock_4c
1150 CALL para_env%sum(stdeb)
1151 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1159 IF (use_virial)
THEN
1160 pv_loc = virial%pv_virial
1163 IF (
ASSOCIATED(rho_nlcc))
THEN
1164 DO ispin = 1, nspins
1165 CALL integrate_rho_nlcc(v_rspace(ispin), qs_env, &
1166 debug_forces, debug_stress,
"dnlcc*dVxc")
1170 basis_type =
"HARRIS"
1171 IF (gapw .OR. gapw_xc)
THEN
1172 task_list => ec_env%task_list_soft
1174 task_list => ec_env%task_list
1177 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
1178 IF (debug_stress .AND. use_virial) stdeb = virial%pv_virial
1180 DO ispin = 1, nspins
1182 CALL pw_scale(v_rspace(ispin), v_rspace(ispin)%pw_grid%dvol)
1185 CALL integrate_v_rspace(v_rspace=v_rspace(ispin), &
1187 pmat=matrix_p(ispin, 1), &
1189 calculate_forces=.true., &
1190 basis_type=basis_type, &
1191 task_list_external=task_list)
1193 CALL integrate_v_rspace(v_rspace=v_hartree_rspace, &
1195 pmat=matrix_p(ispin, 1), &
1197 calculate_forces=.true., &
1198 basis_type=basis_type, &
1199 task_list_external=ec_env%task_list)
1201 CALL pw_axpy(v_hartree_rspace, v_rspace(ispin))
1203 CALL integrate_v_rspace(v_rspace=v_rspace(ispin), &
1205 pmat=matrix_p(ispin, 1), &
1207 calculate_forces=.true., &
1208 basis_type=basis_type, &
1209 task_list_external=task_list)
1213 IF (debug_forces)
THEN
1214 fodeb(1:3) = force(1)%rho_elec(1:3, 1) - fodeb(1:3)
1215 CALL para_env%sum(fodeb)
1216 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Pout*dVhxc ", fodeb
1218 IF (debug_stress .AND. use_virial)
THEN
1219 stdeb = fconv*(virial%pv_virial - stdeb)
1220 CALL para_env%sum(stdeb)
1221 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1225 IF (
ASSOCIATED(v_tau_rspace))
THEN
1226 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
1227 IF (debug_stress .AND. use_virial) stdeb = virial%pv_virial
1228 DO ispin = 1, nspins
1229 CALL pw_scale(v_tau_rspace(ispin), v_tau_rspace(ispin)%pw_grid%dvol)
1231 CALL integrate_v_rspace(v_rspace=v_tau_rspace(ispin), &
1233 pmat=matrix_p(ispin, 1), &
1235 calculate_forces=.true., &
1236 compute_tau=.true., &
1237 basis_type=basis_type, &
1238 task_list_external=task_list)
1241 IF (debug_forces)
THEN
1242 fodeb(1:3) = force(1)%rho_elec(1:3, 1) - fodeb(1:3)
1243 CALL para_env%sum(fodeb)
1244 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Pout*dVhxc_tau ", fodeb
1246 IF (debug_stress .AND. use_virial)
THEN
1247 stdeb = fconv*(virial%pv_virial - stdeb)
1248 CALL para_env%sum(stdeb)
1249 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1254 IF (gapw .OR. gapw_xc)
THEN
1257 rho_atom_set_external=local_rho_set%rho_atom_set, &
1258 xc_section_external=ec_env%xc_section)
1261 IF (debug_forces) fodeb(1:3) = force(1)%g0s_Vh_elec(1:3, 1)
1263 calculate_forces=.true., local_rho_set=local_rho_set)
1264 IF (debug_forces)
THEN
1265 fodeb(1:3) = force(1)%g0s_Vh_elec(1:3, 1) - fodeb(1:3)
1266 CALL para_env%sum(fodeb)
1267 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: P*g0s_Vh_elec ", fodeb
1269 ehartree_1c = 0.0_dp
1270 CALL vh_1c_gg_integrals(qs_env, ehartree_1c, hartree_local%ecoul_1c, local_rho_set, &
1271 para_env, tddft=.false., core_2nd=.false.)
1274 IF (gapw .OR. gapw_xc)
THEN
1276 IF (debug_forces) fodeb(1:3) = force(1)%vhxc_atom(1:3, 1)
1278 rho_atom_external=local_rho_set%rho_atom_set)
1279 IF (debug_forces)
THEN
1280 fodeb(1:3) = force(1)%vhxc_atom(1:3, 1) - fodeb(1:3)
1281 CALL para_env%sum(fodeb)
1282 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: P*vhxc_atom ", fodeb
1287 IF (use_virial)
THEN
1288 virial%pv_ehartree = virial%pv_ehartree + (virial%pv_virial - pv_loc)
1307 NULLIFY (ec_env%matrix_hz)
1309 DO ispin = 1, nspins
1310 ALLOCATE (ec_env%matrix_hz(ispin)%matrix)
1311 CALL dbcsr_create(ec_env%matrix_hz(ispin)%matrix, template=matrix_s(1)%matrix)
1312 CALL dbcsr_copy(ec_env%matrix_hz(ispin)%matrix, matrix_s(1)%matrix)
1313 CALL dbcsr_set(ec_env%matrix_hz(ispin)%matrix, 0.0_dp)
1316 DO ispin = 1, nspins
1319 CALL pw_axpy(v_rspace_in(ispin), v_rspace(ispin), -1.0_dp)
1322 DO ispin = 1, nspins
1323 CALL integrate_v_rspace(v_rspace=v_rspace(ispin), &
1324 hmat=ec_env%matrix_hz(ispin), &
1325 pmat=matrix_p(ispin, 1), &
1327 calculate_forces=.false., &
1328 basis_type=basis_type, &
1329 task_list_external=task_list)
1333 IF (dft_control%use_kinetic_energy_density)
THEN
1336 IF (.NOT.
ASSOCIATED(v_tau_rspace))
THEN
1337 ALLOCATE (v_tau_rspace(nspins))
1338 DO ispin = 1, nspins
1339 CALL auxbas_pw_pool%create_pw(v_tau_rspace(ispin))
1340 CALL pw_zero(v_tau_rspace(ispin))
1344 DO ispin = 1, nspins
1346 IF (
ASSOCIATED(ec_env%vtau_rspace))
THEN
1347 CALL pw_axpy(ec_env%vtau_rspace(ispin), v_tau_rspace(ispin), -1.0_dp)
1350 CALL integrate_v_rspace(v_rspace=v_tau_rspace(ispin), &
1351 hmat=ec_env%matrix_hz(ispin), &
1352 pmat=matrix_p(ispin, 1), &
1354 calculate_forces=.false., compute_tau=.true., &
1355 basis_type=basis_type, &
1356 task_list_external=task_list)
1360 IF (gapw .OR. gapw_xc)
THEN
1363 CALL update_ks_atom(qs_env, ec_env%matrix_hz, matrix_p, .false., &
1364 rho_atom_external=local_rho_set%rho_atom_set, kintegral=1.0_dp)
1366 CALL update_ks_atom(qs_env, ec_env%matrix_hz, matrix_p, .false., &
1367 rho_atom_external=ec_env%local_rho_set%rho_atom_set, kintegral=-1.0_dp)
1374 ext_hfx_section=ec_hfx_sections, &
1375 x_data=ec_env%x_data, &
1376 recalc_integrals=.false., &
1377 do_admm=ec_env%do_ec_admm, &
1380 reuse_hfx=ec_env%reuse_hfx)
1383 IF (debug_forces) fodeb(1:3) = force(1)%core_overlap(1:3, 1)
1384 IF (debug_stress .AND. use_virial) stdeb = virial%pv_ecore_overlap
1386 IF (debug_forces)
THEN
1387 fodeb(1:3) = force(1)%core_overlap(1:3, 1) - fodeb(1:3)
1388 CALL para_env%sum(fodeb)
1389 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: CoreOverlap", fodeb
1391 IF (debug_stress .AND. use_virial)
THEN
1392 stdeb = fconv*(stdeb - virial%pv_ecore_overlap)
1393 CALL para_env%sum(stdeb)
1394 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1398 IF (debug_forces)
THEN
1399 CALL get_qs_env(qs_env, natom=natom, atomic_kind_set=atomic_kind_set)
1400 ALLOCATE (ftot(3, natom))
1402 fodeb(1:3) = ftot(1:3, 1)
1404 CALL para_env%sum(fodeb)
1405 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Force Explicit", fodeb
1409 IF (gapw .OR. gapw_xc)
THEN
1417 DO ispin = 1, nspins
1418 CALL auxbas_pw_pool%give_back_pw(v_rspace(ispin))
1419 CALL auxbas_pw_pool%give_back_pw(v_rspace_in(ispin))
1420 IF (
ASSOCIATED(v_tau_rspace))
THEN
1421 CALL auxbas_pw_pool%give_back_pw(v_tau_rspace(ispin))
1425 DEALLOCATE (v_rspace, v_rspace_in)
1426 IF (
ASSOCIATED(v_tau_rspace))
DEALLOCATE (v_tau_rspace)
1428 CALL auxbas_pw_pool%give_back_pw(rho_tot_gspace)
1429 CALL auxbas_pw_pool%give_back_pw(v_hartree_gspace)
1430 CALL auxbas_pw_pool%give_back_pw(v_hartree_rspace)
1434 IF (use_virial)
THEN
1435 IF (qs_env%energy_correction)
THEN
1436 ec_env%ehartree = ehartree
1438 IF (edisp /= 0.0_dp) ec_env%edispersion = edisp
1442 IF (debug_stress .AND. use_virial)
THEN
1444 stdeb = -1.0_dp*fconv*ehartree
1445 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1448 stdeb = -1.0_dp*fconv*exc
1449 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1458 CALL para_env%sum(virdeb%pv_overlap)
1459 CALL para_env%sum(virdeb%pv_ekinetic)
1460 CALL para_env%sum(virdeb%pv_ppl)
1461 CALL para_env%sum(virdeb%pv_ppnl)
1462 CALL para_env%sum(virdeb%pv_ecore_overlap)
1463 CALL para_env%sum(virdeb%pv_ehartree)
1464 CALL para_env%sum(virdeb%pv_exc)
1465 CALL para_env%sum(virdeb%pv_exx)
1466 CALL para_env%sum(virdeb%pv_vdw)
1467 CALL para_env%sum(virdeb%pv_mp2)
1468 CALL para_env%sum(virdeb%pv_nlcc)
1469 CALL para_env%sum(virdeb%pv_gapw)
1470 CALL para_env%sum(virdeb%pv_lrigpw)
1471 CALL para_env%sum(virdeb%pv_virial)
1476 virdeb%pv_ehartree(i, i) = virdeb%pv_ehartree(i, i) - 2.0_dp*ehartree
1477 virdeb%pv_virial(i, i) = virdeb%pv_virial(i, i) - exc &
1479 virdeb%pv_exc(i, i) = virdeb%pv_exc(i, i) - exc
1485 CALL para_env%sum(sttot)
1486 stdeb = fconv*(virdeb%pv_virial - sttot)
1487 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1490 stdeb = fconv*(virdeb%pv_virial)
1491 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1501 CALL timestop(handle)
1503 END SUBROUTINE ec_dc_build_ks_matrix_force
1511 SUBROUTINE ec_disp(qs_env, ec_env, calculate_forces)
1512 TYPE(qs_environment_type),
POINTER :: qs_env
1513 TYPE(energy_correction_type),
POINTER :: ec_env
1514 LOGICAL,
INTENT(IN) :: calculate_forces
1516 REAL(kind=dp) :: edisp, egcp
1519 CALL calculate_dispersion_pairpot(qs_env, ec_env%dispersion_env, edisp, calculate_forces)
1520 IF (.NOT. calculate_forces)
THEN
1521 ec_env%edispersion = ec_env%edispersion + edisp + egcp
1524 END SUBROUTINE ec_disp
1533 SUBROUTINE ec_build_core_hamiltonian(qs_env, ec_env)
1534 TYPE(qs_environment_type),
POINTER :: qs_env
1535 TYPE(energy_correction_type),
POINTER :: ec_env
1537 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ec_build_core_hamiltonian'
1539 CHARACTER(LEN=default_string_length) :: basis_type
1540 INTEGER :: handle, img, nder, nhfimg, nimages
1541 LOGICAL :: calculate_forces, use_virial
1542 TYPE(atomic_kind_type),
DIMENSION(:),
POINTER :: atomic_kind_set
1543 TYPE(dbcsr_type),
POINTER :: smat
1544 TYPE(dft_control_type),
POINTER :: dft_control
1545 TYPE(neighbor_list_set_p_type),
DIMENSION(:), &
1546 POINTER :: sab_orb, sac_ae, sac_ppl, sap_ppnl
1547 TYPE(particle_type),
DIMENSION(:),
POINTER :: particle_set
1548 TYPE(qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
1549 TYPE(qs_ks_env_type),
POINTER :: ks_env
1551 CALL timeset(routinen, handle)
1553 NULLIFY (atomic_kind_set, dft_control, ks_env, particle_set, &
1556 CALL get_qs_env(qs_env=qs_env, &
1557 atomic_kind_set=atomic_kind_set, &
1558 dft_control=dft_control, &
1559 particle_set=particle_set, &
1560 qs_kind_set=qs_kind_set, &
1564 nimages = dft_control%nimages
1565 IF (nimages /= 1)
THEN
1566 cpabort(
"K-points for Harris functional not implemented")
1570 IF (dft_control%qs_control%gapw .OR. dft_control%qs_control%gapw_xc)
THEN
1571 cpabort(
"Harris functional for GAPW not implemented")
1575 use_virial = .false.
1576 calculate_forces = .false.
1579 NULLIFY (sab_orb, sac_ae, sac_ppl, sap_ppnl)
1580 sab_orb => ec_env%sab_orb
1581 sac_ae => ec_env%sac_ae
1582 sac_ppl => ec_env%sac_ppl
1583 sap_ppnl => ec_env%sap_ppnl
1585 basis_type =
"HARRIS"
1589 CALL build_overlap_matrix(ks_env, matrixkp_s=ec_env%matrix_s, &
1590 matrix_name=
"OVERLAP MATRIX", &
1591 basis_type_a=basis_type, &
1592 basis_type_b=basis_type, &
1593 sab_nl=sab_orb, ext_kpoints=ec_env%kpoints)
1594 CALL build_kinetic_matrix(ks_env, matrixkp_t=ec_env%matrix_t, &
1595 matrix_name=
"KINETIC ENERGY MATRIX", &
1596 basis_type=basis_type, &
1597 sab_nl=sab_orb, ext_kpoints=ec_env%kpoints)
1600 nhfimg =
SIZE(ec_env%matrix_s, 2)
1601 CALL dbcsr_allocate_matrix_set(ec_env%matrix_h, 1, nhfimg)
1603 ALLOCATE (ec_env%matrix_h(1, img)%matrix)
1604 smat => ec_env%matrix_s(1, img)%matrix
1605 CALL dbcsr_create(ec_env%matrix_h(1, img)%matrix, template=smat)
1606 CALL cp_dbcsr_alloc_block_from_nbl(ec_env%matrix_h(1, img)%matrix, sab_orb)
1611 CALL dbcsr_copy(ec_env%matrix_h(1, img)%matrix, ec_env%matrix_t(1, img)%matrix, &
1612 keep_sparsity=.true., name=
"CORE HAMILTONIAN MATRIX")
1615 CALL core_matrices(qs_env, ec_env%matrix_h, ec_env%matrix_p, calculate_forces, nder, &
1616 ec_env=ec_env, ec_env_matrices=.true., ext_kpoints=ec_env%kpoints, &
1617 basis_type=basis_type)
1620 ec_env%efield_nuclear = 0.0_dp
1621 CALL ec_efield_local_operator(qs_env, ec_env, calculate_forces)
1623 CALL timestop(handle)
1625 END SUBROUTINE ec_build_core_hamiltonian
1636 SUBROUTINE ec_build_ks_matrix(qs_env, ec_env)
1637 TYPE(qs_environment_type),
POINTER :: qs_env
1638 TYPE(energy_correction_type),
POINTER :: ec_env
1640 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ec_build_ks_matrix'
1642 CHARACTER(LEN=default_string_length) :: headline
1643 INTEGER :: handle, img, iounit, ispin, natom, &
1644 nhfimg, nimages, nspins
1645 LOGICAL :: calculate_forces, &
1646 do_adiabatic_rescaling, do_ec_hfx, &
1647 gapw, gapw_xc, hfx_treat_lsd_in_core, &
1649 REAL(dp) :: dummy_real, dummy_real2(2), edisp, eexc, &
1650 eh1c, evhxc, exc1, t3
1651 TYPE(admm_type),
POINTER :: admm_env
1652 TYPE(atomic_kind_type),
DIMENSION(:),
POINTER :: atomic_kind_set
1653 TYPE(cp_logger_type),
POINTER :: logger
1654 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: ks_mat, ps_mat
1655 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: rho_ao_kp
1656 TYPE(dbcsr_type),
POINTER :: smat
1657 TYPE(dft_control_type),
POINTER :: dft_control
1658 TYPE(hartree_local_type),
POINTER :: hartree_local
1659 TYPE(local_rho_type),
POINTER :: local_rho_set_ec
1660 TYPE(mp_para_env_type),
POINTER :: para_env
1661 TYPE(neighbor_list_set_p_type),
DIMENSION(:), &
1663 TYPE(oce_matrix_type),
POINTER :: oce
1664 TYPE(pw_env_type),
POINTER :: pw_env
1665 TYPE(pw_pool_type),
POINTER :: auxbas_pw_pool
1666 TYPE(pw_r3d_rs_type),
DIMENSION(:),
POINTER :: rho_r, tau_r, v_rspace, v_tau_rspace
1667 TYPE(qs_energy_type),
POINTER :: energy
1668 TYPE(qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
1669 TYPE(qs_ks_env_type),
POINTER :: ks_env
1670 TYPE(qs_rho_type),
POINTER :: rho, rho_xc
1671 TYPE(section_vals_type),
POINTER :: adiabatic_rescaling_section, &
1672 ec_hfx_sections, ec_section
1674 CALL timeset(routinen, handle)
1676 logger => cp_get_default_logger()
1677 IF (logger%para_env%is_source())
THEN
1678 iounit = cp_logger_get_default_unit_nr(logger, local=.true.)
1684 NULLIFY (auxbas_pw_pool, dft_control, energy, ks_env, rho, rho_r, tau_r)
1685 CALL get_qs_env(qs_env=qs_env, &
1686 dft_control=dft_control, &
1688 rho=rho, rho_xc=rho_xc)
1689 nspins = dft_control%nspins
1690 nimages = dft_control%nimages
1691 calculate_forces = .false.
1692 use_virial = .false.
1694 gapw = dft_control%qs_control%gapw
1695 gapw_xc = dft_control%qs_control%gapw_xc
1698 IF (
ASSOCIATED(ec_env%matrix_ks))
CALL dbcsr_deallocate_matrix_set(ec_env%matrix_ks)
1699 nhfimg =
SIZE(ec_env%matrix_s, 2)
1700 dft_control%nimages = nhfimg
1701 CALL dbcsr_allocate_matrix_set(ec_env%matrix_ks, nspins, nhfimg)
1702 DO ispin = 1, nspins
1703 headline =
"KOHN-SHAM MATRIX"
1705 ALLOCATE (ec_env%matrix_ks(ispin, img)%matrix)
1706 smat => ec_env%matrix_s(1, img)%matrix
1707 CALL dbcsr_create(ec_env%matrix_ks(ispin, img)%matrix, name=trim(headline), &
1708 template=smat, matrix_type=dbcsr_type_symmetric)
1709 CALL cp_dbcsr_alloc_block_from_nbl(ec_env%matrix_ks(ispin, img)%matrix, &
1711 CALL dbcsr_set(ec_env%matrix_ks(ispin, img)%matrix, 0.0_dp)
1716 CALL get_qs_env(qs_env=qs_env, pw_env=pw_env)
1717 cpassert(
ASSOCIATED(pw_env))
1720 ec_section => section_vals_get_subs_vals(qs_env%input,
"DFT%ENERGY_CORRECTION")
1721 ec_hfx_sections => section_vals_get_subs_vals(ec_section,
"XC%HF")
1722 CALL section_vals_get(ec_hfx_sections, explicit=do_ec_hfx)
1727 adiabatic_rescaling_section => section_vals_get_subs_vals(ec_section,
"XC%ADIABATIC_RESCALING")
1728 CALL section_vals_get(adiabatic_rescaling_section, explicit=do_adiabatic_rescaling)
1729 IF (do_adiabatic_rescaling)
THEN
1730 CALL cp_abort(__location__,
"Adiabatic rescaling NYI for energy correction")
1732 CALL section_vals_val_get(ec_hfx_sections,
"TREAT_LSD_IN_CORE", l_val=hfx_treat_lsd_in_core)
1733 IF (hfx_treat_lsd_in_core)
THEN
1734 CALL cp_abort(__location__,
"HFX_TREAT_LSD_IN_CORE NYI for energy correction")
1736 IF (ec_env%do_kpoints)
THEN
1737 CALL cp_abort(__location__,
"HFX and K-points NYI for energy correction")
1741 IF (dft_control%do_admm)
THEN
1742 IF (dft_control%do_admm_mo)
THEN
1743 cpassert(.NOT. qs_env%run_rtp)
1744 CALL admm_mo_calc_rho_aux(qs_env)
1745 ELSE IF (dft_control%do_admm_dm)
THEN
1746 CALL admm_dm_calc_rho_aux(qs_env)
1753 CALL get_qs_env(qs_env, energy=energy)
1754 CALL calculate_exx(qs_env=qs_env, &
1756 hfx_sections=ec_hfx_sections, &
1757 x_data=ec_env%x_data, &
1759 do_admm=ec_env%do_ec_admm, &
1760 calc_forces=.false., &
1761 reuse_hfx=ec_env%reuse_hfx, &
1762 do_im_time=.false., &
1763 e_ex_from_gw=dummy_real, &
1764 e_admm_from_gw=dummy_real2, &
1768 ec_env%ex = energy%ex
1770 IF (ec_env%do_ec_admm)
THEN
1771 ec_env%exc_aux_fit = energy%exc_aux_fit + energy%exc
1777 ks_mat => ec_env%matrix_ks(:, 1)
1778 CALL add_exx_to_rhs(rhs=ks_mat, &
1780 ext_hfx_section=ec_hfx_sections, &
1781 x_data=ec_env%x_data, &
1782 recalc_integrals=.false., &
1783 do_admm=ec_env%do_ec_admm, &
1786 reuse_hfx=ec_env%reuse_hfx)
1791 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
1792 NULLIFY (v_rspace, v_tau_rspace)
1793 IF (dft_control%qs_control%gapw_xc)
THEN
1794 CALL qs_vxc_create(ks_env=ks_env, rho_struct=rho_xc, xc_section=ec_env%xc_section, &
1795 vxc_rho=v_rspace, vxc_tau=v_tau_rspace, exc=eexc, just_energy=.false., &
1796 edisp=edisp, dispersion_env=ec_env%dispersion_env)
1798 CALL qs_vxc_create(ks_env=ks_env, rho_struct=rho, xc_section=ec_env%xc_section, &
1799 vxc_rho=v_rspace, vxc_tau=v_tau_rspace, exc=eexc, just_energy=.false., &
1800 edisp=edisp, dispersion_env=ec_env%dispersion_env)
1803 IF (.NOT.
ASSOCIATED(v_rspace))
THEN
1804 ALLOCATE (v_rspace(nspins))
1805 DO ispin = 1, nspins
1806 CALL auxbas_pw_pool%create_pw(v_rspace(ispin))
1807 CALL pw_zero(v_rspace(ispin))
1812 CALL qs_rho_get(rho, rho_r=rho_r)
1813 IF (
ASSOCIATED(v_tau_rspace))
THEN
1814 CALL qs_rho_get(rho, tau_r=tau_r)
1816 DO ispin = 1, nspins
1818 CALL pw_scale(v_rspace(ispin), v_rspace(ispin)%pw_grid%dvol)
1819 CALL pw_axpy(ec_env%vh_rspace, v_rspace(ispin))
1821 ks_mat => ec_env%matrix_ks(ispin, :)
1822 CALL integrate_v_rspace(v_rspace=v_rspace(ispin), &
1825 calculate_forces=.false., &
1826 basis_type=
"HARRIS", &
1827 task_list_external=ec_env%task_list)
1829 IF (
ASSOCIATED(v_tau_rspace))
THEN
1831 CALL pw_scale(v_tau_rspace(ispin), v_tau_rspace(ispin)%pw_grid%dvol)
1832 CALL integrate_v_rspace(v_rspace=v_tau_rspace(ispin), &
1835 calculate_forces=.false., &
1836 compute_tau=.true., &
1837 basis_type=
"HARRIS", &
1838 task_list_external=ec_env%task_list)
1842 evhxc = evhxc + pw_integral_ab(rho_r(ispin), v_rspace(ispin))/ &
1843 v_rspace(1)%pw_grid%dvol
1844 IF (
ASSOCIATED(v_tau_rspace))
THEN
1845 evhxc = evhxc + pw_integral_ab(tau_r(ispin), v_tau_rspace(ispin))/ &
1846 v_tau_rspace(ispin)%pw_grid%dvol
1851 IF (gapw .OR. gapw_xc)
THEN
1853 IF (ec_env%basis_inconsistent)
THEN
1854 cpabort(
"Energy corrction [GAPW] only with BASIS=ORBITAL possible")
1857 NULLIFY (hartree_local, local_rho_set_ec)
1858 CALL get_qs_env(qs_env, para_env=para_env, &
1859 atomic_kind_set=atomic_kind_set, &
1860 qs_kind_set=qs_kind_set)
1861 CALL local_rho_set_create(local_rho_set_ec)
1862 CALL allocate_rho_atom_internals(local_rho_set_ec%rho_atom_set, atomic_kind_set, &
1863 qs_kind_set, dft_control, para_env)
1865 CALL get_qs_env(qs_env, natom=natom)
1866 CALL init_rho0(local_rho_set_ec, qs_env, dft_control%qs_control%gapw_control)
1867 CALL rho0_s_grid_create(pw_env, local_rho_set_ec%rho0_mpole)
1868 CALL hartree_local_create(hartree_local)
1869 CALL init_coulomb_local(hartree_local, natom)
1872 CALL get_qs_env(qs_env=qs_env, oce=oce, sab_orb=sab)
1873 CALL qs_rho_get(rho, rho_ao_kp=rho_ao_kp)
1874 CALL calculate_rho_atom_coeff(qs_env, rho_ao_kp, local_rho_set_ec%rho_atom_set, &
1875 qs_kind_set, oce, sab, para_env)
1876 CALL prepare_gapw_den(qs_env, local_rho_set_ec, do_rho0=gapw)
1878 CALL calculate_vxc_atom(qs_env, .false., exc1=exc1, xc_section_external=ec_env%xc_section, &
1879 rho_atom_set_external=local_rho_set_ec%rho_atom_set)
1883 CALL vh_1c_gg_integrals(qs_env, eh1c, hartree_local%ecoul_1c, local_rho_set_ec, para_env, .false.)
1884 CALL integrate_vhg0_rspace(qs_env, ec_env%vh_rspace, para_env, calculate_forces=.false., &
1885 local_rho_set=local_rho_set_ec)
1886 ec_env%ehartree_1c = eh1c
1888 IF (dft_control%do_admm)
THEN
1889 CALL get_qs_env(qs_env, admm_env=admm_env)
1890 IF (admm_env%aux_exch_func /= do_admm_aux_exch_func_none)
THEN
1892 cpabort(
"GAPW HFX ADMM + Energy Correction NYA")
1896 ks_mat => ec_env%matrix_ks(:, 1)
1897 ps_mat => ec_env%matrix_p(:, 1)
1898 CALL update_ks_atom(qs_env, ks_mat, ps_mat, forces=.false., &
1899 rho_atom_external=local_rho_set_ec%rho_atom_set)
1901 CALL local_rho_set_release(local_rho_set_ec)
1903 CALL hartree_local_release(hartree_local)
1909 DO ispin = 1, nspins
1910 CALL auxbas_pw_pool%give_back_pw(v_rspace(ispin))
1911 IF (
ASSOCIATED(v_tau_rspace))
THEN
1912 CALL auxbas_pw_pool%give_back_pw(v_tau_rspace(ispin))
1915 DEALLOCATE (v_rspace)
1916 IF (
ASSOCIATED(v_tau_rspace))
DEALLOCATE (v_tau_rspace)
1920 IF (edisp /= 0.0_dp) ec_env%edispersion = edisp
1924 DO ispin = 1, nspins
1926 CALL dbcsr_add(ec_env%matrix_ks(ispin, img)%matrix, ec_env%matrix_h(1, img)%matrix, &
1927 alpha_scalar=1.0_dp, beta_scalar=1.0_dp)
1928 CALL dbcsr_filter(ec_env%matrix_ks(ispin, img)%matrix, &
1929 dft_control%qs_control%eps_filter_matrix)
1933 dft_control%nimages = nimages
1935 CALL timestop(handle)
1937 END SUBROUTINE ec_build_ks_matrix
1949 SUBROUTINE ec_build_core_hamiltonian_force(qs_env, ec_env, matrix_p, matrix_s, matrix_w)
1950 TYPE(qs_environment_type),
POINTER :: qs_env
1951 TYPE(energy_correction_type),
POINTER :: ec_env
1952 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_p, matrix_s, matrix_w
1954 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ec_build_core_hamiltonian_force'
1956 CHARACTER(LEN=default_string_length) :: basis_type
1957 INTEGER :: handle, img, iounit, nder, nhfimg, &
1959 LOGICAL :: calculate_forces, debug_forces, &
1960 debug_stress, use_virial
1961 REAL(kind=dp) :: fconv
1962 REAL(kind=dp),
DIMENSION(3) :: fodeb
1963 REAL(kind=dp),
DIMENSION(3, 3) :: stdeb, sttot
1964 TYPE(cell_type),
POINTER :: cell
1965 TYPE(cp_logger_type),
POINTER :: logger
1966 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: scrm
1967 TYPE(dft_control_type),
POINTER :: dft_control
1968 TYPE(mp_para_env_type),
POINTER :: para_env
1969 TYPE(neighbor_list_set_p_type),
DIMENSION(:), &
1971 TYPE(qs_force_type),
DIMENSION(:),
POINTER :: force
1972 TYPE(qs_ks_env_type),
POINTER :: ks_env
1973 TYPE(virial_type),
POINTER :: virial
1975 CALL timeset(routinen, handle)
1977 debug_forces = ec_env%debug_forces
1978 debug_stress = ec_env%debug_stress
1980 logger => cp_get_default_logger()
1981 IF (logger%para_env%is_source())
THEN
1982 iounit = cp_logger_get_default_unit_nr(logger, local=.true.)
1987 calculate_forces = .true.
1989 basis_type =
"HARRIS"
1992 NULLIFY (cell, dft_control, force, ks_env, para_env, virial)
1993 CALL get_qs_env(qs_env=qs_env, &
1995 dft_control=dft_control, &
1998 para_env=para_env, &
2000 nimages = dft_control%nimages
2001 IF (nimages /= 1)
THEN
2002 cpabort(
"K-points for Harris functional not implemented")
2005 IF (dft_control%qs_control%gapw .OR. dft_control%qs_control%gapw_xc)
THEN
2006 IF (ec_env%energy_functional == ec_functional_harris)
THEN
2007 cpabort(
"Harris functional for GAPW not implemented")
2012 use_virial = virial%pv_availability .AND. (.NOT. virial%pv_numer)
2014 fconv = 1.0e-9_dp*pascal/cell%deth
2015 IF (debug_stress .AND. use_virial)
THEN
2016 sttot = virial%pv_virial
2020 sab_orb => ec_env%sab_orb
2023 nhfimg =
SIZE(matrix_s, 2)
2025 CALL dbcsr_allocate_matrix_set(scrm, 1, nhfimg)
2027 ALLOCATE (scrm(1, img)%matrix)
2028 CALL dbcsr_create(scrm(1, img)%matrix, template=matrix_s(1, img)%matrix)
2029 CALL cp_dbcsr_alloc_block_from_nbl(scrm(1, img)%matrix, sab_orb)
2033 IF (
SIZE(matrix_p, 1) == 2)
THEN
2035 CALL dbcsr_add(matrix_w(1, img)%matrix, matrix_w(2, img)%matrix, &
2036 alpha_scalar=1.0_dp, beta_scalar=1.0_dp)
2041 IF (debug_forces) fodeb(1:3) = force(1)%overlap(1:3, 1)
2042 IF (debug_stress .AND. use_virial) stdeb = virial%pv_overlap
2043 CALL build_overlap_matrix(ks_env, matrixkp_s=scrm, &
2044 matrix_name=
"OVERLAP MATRIX", &
2045 basis_type_a=basis_type, &
2046 basis_type_b=basis_type, &
2047 sab_nl=sab_orb, calculate_forces=.true., &
2048 matrixkp_p=matrix_w, ext_kpoints=ec_env%kpoints)
2050 IF (debug_forces)
THEN
2051 fodeb(1:3) = force(1)%overlap(1:3, 1) - fodeb(1:3)
2052 CALL para_env%sum(fodeb)
2053 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Wout*dS ", fodeb
2055 IF (debug_stress .AND. use_virial)
THEN
2056 stdeb = fconv*(virial%pv_overlap - stdeb)
2057 CALL para_env%sum(stdeb)
2058 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2059 'STRESS| Wout*dS', one_third_sum_diag(stdeb), det_3x3(stdeb)
2062 CALL kinetic_energy_matrix(qs_env, matrixkp_t=scrm, matrix_p=matrix_p, &
2063 calculate_forces=.true., sab_orb=sab_orb, &
2064 basis_type=basis_type, ext_kpoints=ec_env%kpoints, &
2065 debug_forces=debug_forces, debug_stress=debug_stress)
2067 CALL core_matrices(qs_env, scrm, matrix_p, calculate_forces, nder, &
2068 ec_env=ec_env, ec_env_matrices=.false., basis_type=basis_type, &
2069 ext_kpoints=ec_env%kpoints, &
2070 debug_forces=debug_forces, debug_stress=debug_stress)
2073 ec_env%efield_nuclear = 0.0_dp
2074 IF (calculate_forces .AND. debug_forces) fodeb(1:3) = force(1)%efield(1:3, 1)
2075 CALL ec_efield_local_operator(qs_env, ec_env, calculate_forces)
2076 IF (calculate_forces .AND. debug_forces)
THEN
2077 fodeb(1:3) = force(1)%efield(1:3, 1) - fodeb(1:3)
2078 CALL para_env%sum(fodeb)
2079 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Pout*dEfield", fodeb
2081 IF (debug_stress .AND. use_virial)
THEN
2082 stdeb = fconv*(virial%pv_virial - sttot)
2083 CALL para_env%sum(stdeb)
2084 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2085 'STRESS| Stress Pout*dHcore ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2086 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))")
' '
2090 CALL dbcsr_deallocate_matrix_set(scrm)
2092 CALL timestop(handle)
2094 END SUBROUTINE ec_build_core_hamiltonian_force
2105 SUBROUTINE ec_build_ks_matrix_force(qs_env, ec_env)
2106 TYPE(qs_environment_type),
POINTER :: qs_env
2107 TYPE(energy_correction_type),
POINTER :: ec_env
2109 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ec_build_ks_matrix_force'
2111 CHARACTER(LEN=default_string_length) :: unit_string
2112 INTEGER :: handle, i, img, iounit, ispin, natom, &
2113 nhfimg, nimages, nspins
2114 LOGICAL :: debug_forces, debug_stress, do_ec_hfx, &
2116 REAL(dp) :: dehartree, dummy_real, dummy_real2(2), &
2117 edisp, eexc, ehartree, eovrl, exc, &
2119 REAL(dp),
ALLOCATABLE,
DIMENSION(:, :) :: ftot
2120 REAL(dp),
DIMENSION(3) :: fodeb
2121 REAL(kind=dp),
DIMENSION(3, 3) :: h_stress, pv_loc, stdeb, sttot
2122 TYPE(atomic_kind_type),
DIMENSION(:),
POINTER :: atomic_kind_set
2123 TYPE(cell_type),
POINTER :: cell
2124 TYPE(cp_logger_type),
POINTER :: logger
2125 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_ks, rho_ao, scrmat
2126 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_p, matrix_s, scrm
2127 TYPE(dft_control_type),
POINTER :: dft_control
2128 TYPE(mp_para_env_type),
POINTER :: para_env
2129 TYPE(neighbor_list_set_p_type),
DIMENSION(:), &
2131 TYPE(pw_c1d_gs_type) :: rho_tot_gspace, rhodn_tot_gspace, &
2133 TYPE(pw_c1d_gs_type),
DIMENSION(:),
POINTER :: rho_g, rhoout_g
2134 TYPE(pw_c1d_gs_type),
POINTER :: rho_core
2135 TYPE(pw_env_type),
POINTER :: pw_env
2136 TYPE(pw_poisson_type),
POINTER :: poisson_env
2137 TYPE(pw_pool_type),
POINTER :: auxbas_pw_pool
2138 TYPE(pw_r3d_rs_type) :: dv_hartree_rspace, v_hartree_rspace, &
2140 TYPE(pw_r3d_rs_type),
DIMENSION(:),
POINTER :: rho_r, rhoout_r, tau_r, tauout_r, &
2141 v_rspace, v_tau_rspace, v_xc, v_xc_tau
2142 TYPE(pw_r3d_rs_type),
POINTER :: rho_nlcc
2143 TYPE(qs_force_type),
DIMENSION(:),
POINTER :: force
2144 TYPE(qs_ks_env_type),
POINTER :: ks_env
2145 TYPE(qs_rho_type),
POINTER :: rho, rhoout
2146 TYPE(rho_atom_type),
DIMENSION(:),
POINTER :: rho0_atom_set, rho1_atom_set
2147 TYPE(section_vals_type),
POINTER :: ec_hfx_sections, xc_section
2148 TYPE(virial_type),
POINTER :: virial
2150 CALL timeset(routinen, handle)
2152 debug_forces = ec_env%debug_forces
2153 debug_stress = ec_env%debug_stress
2155 logger => cp_get_default_logger()
2156 IF (logger%para_env%is_source())
THEN
2157 iounit = cp_logger_get_default_unit_nr(logger, local=.true.)
2163 NULLIFY (atomic_kind_set, cell, dft_control, force, ks_env, &
2164 matrix_ks, matrix_p, matrix_s, para_env, rho, rho_core, &
2165 rho_g, rho_r, rho_nlcc, sab_orb, tau_r, virial)
2166 CALL get_qs_env(qs_env=qs_env, &
2168 dft_control=dft_control, &
2171 matrix_ks=matrix_ks, &
2172 para_env=para_env, &
2174 rho_nlcc=rho_nlcc, &
2178 nspins = dft_control%nspins
2179 use_virial = virial%pv_availability .AND. (.NOT. virial%pv_numer)
2183 fconv = cp_unit_from_cp2k(1.0_dp/cell%deth, trim(unit_string))
2185 IF (debug_stress .AND. use_virial)
THEN
2186 sttot = virial%pv_virial
2190 CALL get_qs_env(qs_env=qs_env, pw_env=pw_env)
2191 cpassert(
ASSOCIATED(pw_env))
2193 NULLIFY (auxbas_pw_pool, poisson_env)
2195 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool, &
2196 poisson_env=poisson_env)
2199 CALL auxbas_pw_pool%create_pw(v_hartree_gspace)
2200 CALL auxbas_pw_pool%create_pw(rhodn_tot_gspace)
2201 CALL auxbas_pw_pool%create_pw(v_hartree_rspace)
2203 CALL pw_transfer(ec_env%vh_rspace, v_hartree_rspace)
2208 CALL qs_rho_get(rho, rho_r=rho_r, rho_g=rho_g, tau_r=tau_r)
2209 NULLIFY (rhoout_r, rhoout_g)
2210 ALLOCATE (rhoout_r(nspins), rhoout_g(nspins))
2211 DO ispin = 1, nspins
2212 CALL auxbas_pw_pool%create_pw(rhoout_r(ispin))
2213 CALL auxbas_pw_pool%create_pw(rhoout_g(ispin))
2215 CALL auxbas_pw_pool%create_pw(dv_hartree_rspace)
2216 CALL auxbas_pw_pool%create_pw(vtot_rspace)
2219 nhfimg =
SIZE(ec_env%matrix_s, 2)
2220 nimages = dft_control%nimages
2221 dft_control%nimages = nhfimg
2223 CALL pw_zero(rhodn_tot_gspace)
2224 DO ispin = 1, nspins
2225 rho_ao => ec_env%matrix_p(ispin, :)
2226 CALL calculate_rho_elec(ks_env=ks_env, matrix_p_kp=rho_ao, &
2227 rho=rhoout_r(ispin), &
2228 rho_gspace=rhoout_g(ispin), &
2229 basis_type=
"HARRIS", &
2230 task_list_external=ec_env%task_list)
2234 ALLOCATE (ec_env%rhoout_r(nspins))
2235 DO ispin = 1, nspins
2236 CALL auxbas_pw_pool%create_pw(ec_env%rhoout_r(ispin))
2237 CALL pw_copy(rhoout_r(ispin), ec_env%rhoout_r(ispin))
2241 IF (dft_control%use_kinetic_energy_density)
THEN
2243 TYPE(pw_c1d_gs_type) :: tauout_g
2244 ALLOCATE (tauout_r(nspins))
2245 DO ispin = 1, nspins
2246 CALL auxbas_pw_pool%create_pw(tauout_r(ispin))
2248 CALL auxbas_pw_pool%create_pw(tauout_g)
2250 DO ispin = 1, nspins
2251 CALL calculate_rho_elec(ks_env=ks_env, matrix_p=ec_env%matrix_p(ispin, 1)%matrix, &
2252 rho=tauout_r(ispin), &
2253 rho_gspace=tauout_g, &
2254 compute_tau=.true., &
2255 basis_type=
"HARRIS", &
2256 task_list_external=ec_env%task_list)
2259 CALL auxbas_pw_pool%give_back_pw(tauout_g)
2264 dft_control%nimages = nimages
2266 IF (use_virial)
THEN
2269 CALL auxbas_pw_pool%create_pw(rho_tot_gspace)
2272 CALL calc_rho_tot_gspace(rho_tot_gspace, qs_env, rho)
2275 CALL get_qs_env(qs_env=qs_env, rho_core=rho_core)
2276 CALL pw_copy(rho_core, rhodn_tot_gspace)
2277 DO ispin = 1, dft_control%nspins
2278 CALL pw_axpy(rhoout_g(ispin), rhodn_tot_gspace)
2282 h_stress(:, :) = 0.0_dp
2283 CALL pw_poisson_solve(poisson_env, &
2284 density=rho_tot_gspace, &
2285 ehartree=ehartree, &
2286 vhartree=v_hartree_gspace, &
2287 h_stress=h_stress, &
2288 aux_density=rhodn_tot_gspace)
2290 virial%pv_ehartree = virial%pv_ehartree + h_stress/real(para_env%num_pe, dp)
2291 virial%pv_virial = virial%pv_virial + h_stress/real(para_env%num_pe, dp)
2293 IF (debug_stress)
THEN
2294 stdeb = fconv*(h_stress/real(para_env%num_pe, dp))
2295 CALL para_env%sum(stdeb)
2296 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2297 'STRESS| GREEN 1st v_H[n_in]*n_out ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2301 virial%pv_calculate = .true.
2303 NULLIFY (v_rspace, v_tau_rspace)
2304 CALL qs_vxc_create(ks_env=ks_env, rho_struct=rho, xc_section=ec_env%xc_section, &
2305 vxc_rho=v_rspace, vxc_tau=v_tau_rspace, exc=exc, just_energy=.false., &
2306 edisp=edisp, dispersion_env=ec_env%dispersion_env)
2309 virial%pv_exc = virial%pv_exc - virial%pv_xc
2310 virial%pv_virial = virial%pv_virial - virial%pv_xc
2312 IF (debug_stress)
THEN
2313 stdeb = -1.0_dp*fconv*virial%pv_xc
2314 CALL para_env%sum(stdeb)
2315 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2316 'STRESS| GGA 1st E_xc[Pin] ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2319 IF (
ASSOCIATED(v_rspace))
THEN
2320 DO ispin = 1, nspins
2321 CALL auxbas_pw_pool%give_back_pw(v_rspace(ispin))
2323 DEALLOCATE (v_rspace)
2325 IF (
ASSOCIATED(v_tau_rspace))
THEN
2326 DO ispin = 1, nspins
2327 CALL auxbas_pw_pool%give_back_pw(v_tau_rspace(ispin))
2329 DEALLOCATE (v_tau_rspace)
2331 CALL pw_zero(rhodn_tot_gspace)
2336 DO ispin = 1, nspins
2337 CALL pw_axpy(rho_r(ispin), rhoout_r(ispin), -1.0_dp)
2338 CALL pw_axpy(rho_g(ispin), rhoout_g(ispin), -1.0_dp)
2339 CALL pw_axpy(rhoout_g(ispin), rhodn_tot_gspace)
2340 IF (dft_control%use_kinetic_energy_density)
CALL pw_axpy(tau_r(ispin), tauout_r(ispin), -1.0_dp)
2344 IF (use_virial)
THEN
2347 h_stress(:, :) = 0.0_dp
2348 CALL pw_poisson_solve(poisson_env, &
2349 density=rhodn_tot_gspace, &
2350 ehartree=dehartree, &
2351 vhartree=v_hartree_gspace, &
2352 h_stress=h_stress, &
2353 aux_density=rho_tot_gspace)
2355 CALL auxbas_pw_pool%give_back_pw(rho_tot_gspace)
2357 virial%pv_ehartree = virial%pv_ehartree + h_stress/real(para_env%num_pe, dp)
2358 virial%pv_virial = virial%pv_virial + h_stress/real(para_env%num_pe, dp)
2360 IF (debug_stress)
THEN
2361 stdeb = fconv*(h_stress/real(para_env%num_pe, dp))
2362 CALL para_env%sum(stdeb)
2363 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2364 'STRESS| GREEN 2nd V_H[dP]*n_in ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2369 CALL pw_poisson_solve(poisson_env, rhodn_tot_gspace, dehartree, &
2373 CALL pw_transfer(v_hartree_gspace, dv_hartree_rspace)
2374 CALL pw_scale(dv_hartree_rspace, dv_hartree_rspace%pw_grid%dvol)
2377 CALL pw_transfer(v_hartree_rspace, vtot_rspace)
2378 CALL pw_axpy(dv_hartree_rspace, vtot_rspace)
2379 IF (debug_forces) fodeb(1:3) = force(1)%rho_core(1:3, 1)
2380 IF (debug_stress .AND. use_virial) stdeb = virial%pv_ehartree
2381 CALL integrate_v_core_rspace(vtot_rspace, qs_env)
2382 IF (debug_forces)
THEN
2383 fodeb(1:3) = force(1)%rho_core(1:3, 1) - fodeb(1:3)
2384 CALL para_env%sum(fodeb)
2385 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Vtot*dncore", fodeb
2387 IF (debug_stress .AND. use_virial)
THEN
2388 stdeb = fconv*(virial%pv_ehartree - stdeb)
2389 CALL para_env%sum(stdeb)
2390 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2391 'STRESS| Vtot*dncore', one_third_sum_diag(stdeb), det_3x3(stdeb)
2397 xc_section => ec_env%xc_section
2399 IF (use_virial) virial%pv_xc = 0.0_dp
2400 NULLIFY (v_xc, v_xc_tau)
2401 NULLIFY (rho0_atom_set, rho1_atom_set)
2403 CALL qs_rho_create(rhoout)
2404 IF (
ASSOCIATED(rhoout_r))
THEN
2405 CALL qs_rho_set(rhoout, rho_r=rhoout_r, rho_r_valid=.true.)
2407 IF (
ASSOCIATED(rhoout_g))
THEN
2408 CALL qs_rho_set(rhoout, rho_g=rhoout_g, rho_g_valid=.true.)
2410 IF (
ASSOCIATED(tauout_r))
THEN
2411 CALL qs_rho_set(rhoout, tau_r=tauout_r, tau_r_valid=.true.)
2414 CALL qs_fxc_create(qs_env, rho, rhoout, rho0_atom_set, xc_section, .false., &
2415 v_xc, v_xc_tau, rho1_atom_set, &
2416 dispersion_env=ec_env%dispersion_env, &
2417 compute_virial=use_virial, virial_xc=virial%pv_xc)
2421 IF (use_virial)
THEN
2423 virial%pv_exc = virial%pv_exc + virial%pv_xc
2424 virial%pv_virial = virial%pv_virial + virial%pv_xc
2426 IF (debug_stress .AND. use_virial)
THEN
2427 stdeb = 1.0_dp*fconv*virial%pv_xc
2428 CALL para_env%sum(stdeb)
2429 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2430 'STRESS| GGA 2nd f_Hxc[dP]*Pin ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2433 IF (
ASSOCIATED(rho_nlcc))
THEN
2434 DO ispin = 1, nspins
2435 CALL integrate_rho_nlcc(v_xc(ispin), qs_env, &
2436 debug_forces, debug_stress,
"dnlcc*dVxc")
2440 CALL get_qs_env(qs_env=qs_env, rho=rho, matrix_s_kp=matrix_s)
2441 NULLIFY (ec_env%matrix_hz)
2442 CALL dbcsr_allocate_matrix_set(ec_env%matrix_hz, nspins)
2443 DO ispin = 1, nspins
2444 ALLOCATE (ec_env%matrix_hz(ispin)%matrix)
2445 CALL dbcsr_create(ec_env%matrix_hz(ispin)%matrix, template=matrix_s(1, 1)%matrix)
2446 CALL dbcsr_copy(ec_env%matrix_hz(ispin)%matrix, matrix_s(1, 1)%matrix)
2447 CALL dbcsr_set(ec_env%matrix_hz(ispin)%matrix, 0.0_dp)
2449 CALL qs_rho_get(rho, rho_ao_kp=matrix_p)
2451 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
2452 IF (debug_stress .AND. use_virial) stdeb = virial%pv_virial
2455 IF (use_virial)
THEN
2456 pv_loc = virial%pv_virial
2459 DO ispin = 1, nspins
2460 CALL pw_scale(v_xc(ispin), v_xc(ispin)%pw_grid%dvol)
2461 CALL pw_axpy(dv_hartree_rspace, v_xc(ispin))
2462 CALL integrate_v_rspace(v_rspace=v_xc(ispin), &
2463 hmat=ec_env%matrix_hz(ispin), &
2464 pmat=matrix_p(ispin, 1), &
2466 calculate_forces=.true.)
2469 IF (debug_forces)
THEN
2470 fodeb(1:3) = force(1)%rho_elec(1:3, 1) - fodeb(1:3)
2471 CALL para_env%sum(fodeb)
2472 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Pin*dKdrho", fodeb
2474 IF (debug_stress .AND. use_virial)
THEN
2475 stdeb = fconv*(virial%pv_virial - stdeb)
2476 CALL para_env%sum(stdeb)
2477 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2478 'STRESS| INT 2nd f_Hxc[dP]*Pin ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2481 IF (
ASSOCIATED(v_xc_tau))
THEN
2482 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
2483 IF (debug_stress .AND. use_virial) stdeb = virial%pv_virial
2485 DO ispin = 1, nspins
2486 CALL pw_scale(v_xc_tau(ispin), v_xc_tau(ispin)%pw_grid%dvol)
2487 CALL integrate_v_rspace(v_rspace=v_xc_tau(ispin), &
2488 hmat=ec_env%matrix_hz(ispin), &
2489 pmat=matrix_p(ispin, 1), &
2491 compute_tau=.true., &
2492 calculate_forces=.true.)
2495 IF (debug_forces)
THEN
2496 fodeb(1:3) = force(1)%rho_elec(1:3, 1) - fodeb(1:3)
2497 CALL para_env%sum(fodeb)
2498 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Pin*dKtaudtau", fodeb
2500 IF (debug_stress .AND. use_virial)
THEN
2501 stdeb = fconv*(virial%pv_virial - stdeb)
2502 CALL para_env%sum(stdeb)
2503 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2504 'STRESS| INT 2nd f_xctau[dP]*Pin ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2508 IF (use_virial)
THEN
2509 virial%pv_ehartree = virial%pv_ehartree + (virial%pv_virial - pv_loc)
2513 NULLIFY (v_rspace, v_tau_rspace)
2515 CALL qs_vxc_create(ks_env=ks_env, rho_struct=rho, xc_section=ec_env%xc_section, &
2516 vxc_rho=v_rspace, vxc_tau=v_tau_rspace, exc=eexc, just_energy=.false., &
2517 edisp=edisp, dispersion_env=ec_env%dispersion_env)
2518 IF (edisp /= 0.0_dp) eexc = eexc + edisp
2520 IF (
ASSOCIATED(rho_nlcc))
THEN
2521 DO ispin = 1, nspins
2522 CALL integrate_rho_nlcc(v_rspace(ispin), qs_env, &
2523 debug_forces, debug_stress,
"dnlcc*dVxc")
2527 IF (use_virial)
THEN
2529 IF (
ASSOCIATED(v_rspace))
THEN
2530 DO ispin = 1, nspins
2532 eexc = eexc + pw_integral_ab(rhoout_r(ispin), v_rspace(ispin))
2535 IF (
ASSOCIATED(v_tau_rspace))
THEN
2536 DO ispin = 1, nspins
2538 eexc = eexc + pw_integral_ab(tauout_r(ispin), v_tau_rspace(ispin))
2543 IF (.NOT.
ASSOCIATED(v_rspace))
THEN
2544 ALLOCATE (v_rspace(nspins))
2545 DO ispin = 1, nspins
2546 CALL auxbas_pw_pool%create_pw(v_rspace(ispin))
2547 CALL pw_zero(v_rspace(ispin))
2553 IF (use_virial)
THEN
2554 pv_loc = virial%pv_virial
2557 dft_control%nimages = nhfimg
2561 CALL dbcsr_allocate_matrix_set(scrm, nspins, nhfimg)
2562 DO ispin = 1, nspins
2564 ALLOCATE (scrm(ispin, img)%matrix)
2565 CALL dbcsr_create(scrm(ispin, img)%matrix, template=ec_env%matrix_ks(ispin, img)%matrix)
2566 CALL dbcsr_copy(scrm(ispin, img)%matrix, ec_env%matrix_ks(ispin, img)%matrix)
2567 CALL dbcsr_set(scrm(ispin, img)%matrix, 0.0_dp)
2571 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
2572 IF (debug_stress .AND. use_virial) stdeb = virial%pv_virial
2573 DO ispin = 1, nspins
2575 CALL pw_scale(v_rspace(ispin), v_rspace(ispin)%pw_grid%dvol)
2576 CALL pw_axpy(v_hartree_rspace, v_rspace(ispin))
2578 rho_ao => ec_env%matrix_p(ispin, :)
2579 scrmat => scrm(ispin, :)
2580 CALL integrate_v_rspace(v_rspace=v_rspace(ispin), &
2584 calculate_forces=.true., &
2585 basis_type=
"HARRIS", &
2586 task_list_external=ec_env%task_list)
2589 IF (debug_forces)
THEN
2590 fodeb(1:3) = force(1)%rho_elec(1:3, 1) - fodeb(1:3)
2591 CALL para_env%sum(fodeb)
2592 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Pout*dVhxc ", fodeb
2594 IF (debug_stress .AND. use_virial)
THEN
2595 stdeb = fconv*(virial%pv_virial - stdeb)
2596 CALL para_env%sum(stdeb)
2597 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2598 'STRESS| INT Pout*dVhxc ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2602 IF (use_virial)
THEN
2603 virial%pv_ehartree = virial%pv_ehartree + (virial%pv_virial - pv_loc)
2607 dft_control%nimages = nimages
2609 IF (
ASSOCIATED(v_tau_rspace))
THEN
2610 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
2611 DO ispin = 1, nspins
2613 CALL pw_scale(v_tau_rspace(ispin), v_tau_rspace(ispin)%pw_grid%dvol)
2614 rho_ao => ec_env%matrix_p(ispin, :)
2615 scrmat => scrm(ispin, :)
2616 CALL integrate_v_rspace(v_rspace=v_tau_rspace(ispin), &
2620 calculate_forces=.true., &
2621 compute_tau=.true., &
2622 basis_type=
"HARRIS", &
2623 task_list_external=ec_env%task_list)
2625 IF (debug_forces)
THEN
2626 fodeb(1:3) = force(1)%rho_elec(1:3, 1) - fodeb(1:3)
2627 CALL para_env%sum(fodeb)
2628 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Pout*dVhxc_tau ", fodeb
2637 ec_hfx_sections => section_vals_get_subs_vals(qs_env%input,
"DFT%ENERGY_CORRECTION%XC%HF")
2638 CALL section_vals_get(ec_hfx_sections, explicit=do_ec_hfx)
2642 IF (ec_env%do_kpoints)
THEN
2643 CALL cp_abort(__location__,
"HFX and K-points NYI for energy correction")
2646 IF (debug_forces) fodeb(1:3) = force(1)%fock_4c(1:3, 1)
2647 IF (use_virial) virial%pv_fock_4c = 0.0_dp
2649 CALL calculate_exx(qs_env=qs_env, &
2651 hfx_sections=ec_hfx_sections, &
2652 x_data=ec_env%x_data, &
2654 do_admm=ec_env%do_ec_admm, &
2655 calc_forces=.true., &
2656 reuse_hfx=ec_env%reuse_hfx, &
2657 do_im_time=.false., &
2658 e_ex_from_gw=dummy_real, &
2659 e_admm_from_gw=dummy_real2, &
2662 IF (use_virial)
THEN
2663 virial%pv_exx = virial%pv_exx - virial%pv_fock_4c
2664 virial%pv_virial = virial%pv_virial - virial%pv_fock_4c
2665 virial%pv_calculate = .false.
2667 IF (debug_forces)
THEN
2668 fodeb(1:3) = force(1)%fock_4c(1:3, 1) - fodeb(1:3)
2669 CALL para_env%sum(fodeb)
2670 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Pout*hfx ", fodeb
2672 IF (debug_stress .AND. use_virial)
THEN
2673 stdeb = -1.0_dp*fconv*virial%pv_fock_4c
2674 CALL para_env%sum(stdeb)
2675 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2676 'STRESS| Pout*hfx ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2682 CALL dbcsr_deallocate_matrix_set(scrm)
2685 CALL auxbas_pw_pool%give_back_pw(v_hartree_rspace)
2686 DO ispin = 1, nspins
2687 CALL auxbas_pw_pool%give_back_pw(v_rspace(ispin))
2688 IF (
ASSOCIATED(v_tau_rspace))
THEN
2689 CALL auxbas_pw_pool%give_back_pw(v_tau_rspace(ispin))
2692 IF (
ASSOCIATED(v_tau_rspace))
DEALLOCATE (v_tau_rspace)
2695 IF (debug_forces) fodeb(1:3) = force(1)%core_overlap(1:3, 1)
2696 IF (debug_stress .AND. use_virial) stdeb = virial%pv_ecore_overlap
2697 CALL calculate_ecore_overlap(qs_env, para_env, .true., e_overlap_core=eovrl)
2698 IF (debug_forces)
THEN
2699 fodeb(1:3) = force(1)%core_overlap(1:3, 1) - fodeb(1:3)
2700 CALL para_env%sum(fodeb)
2701 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: CoreOverlap", fodeb
2703 IF (debug_stress .AND. use_virial)
THEN
2704 stdeb = fconv*(stdeb - virial%pv_ecore_overlap)
2705 CALL para_env%sum(stdeb)
2706 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2707 'STRESS| CoreOverlap ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2710 IF (debug_forces)
THEN
2711 CALL get_qs_env(qs_env, natom=natom, atomic_kind_set=atomic_kind_set)
2712 ALLOCATE (ftot(3, natom))
2713 CALL total_qs_force(ftot, force, atomic_kind_set)
2714 fodeb(1:3) = ftot(1:3, 1)
2716 CALL para_env%sum(fodeb)
2717 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Force Explicit", fodeb
2720 DEALLOCATE (v_rspace)
2722 CALL auxbas_pw_pool%give_back_pw(dv_hartree_rspace)
2723 CALL auxbas_pw_pool%give_back_pw(vtot_rspace)
2724 DO ispin = 1, nspins
2725 CALL auxbas_pw_pool%give_back_pw(rhoout_r(ispin))
2726 CALL auxbas_pw_pool%give_back_pw(rhoout_g(ispin))
2727 CALL auxbas_pw_pool%give_back_pw(v_xc(ispin))
2729 DEALLOCATE (rhoout_r, rhoout_g, v_xc)
2730 IF (
ASSOCIATED(tauout_r))
THEN
2731 DO ispin = 1, nspins
2732 CALL auxbas_pw_pool%give_back_pw(tauout_r(ispin))
2734 DEALLOCATE (tauout_r)
2736 IF (
ASSOCIATED(v_xc_tau))
THEN
2737 DO ispin = 1, nspins
2738 CALL auxbas_pw_pool%give_back_pw(v_xc_tau(ispin))
2740 DEALLOCATE (v_xc_tau)
2742 CALL auxbas_pw_pool%give_back_pw(v_hartree_gspace)
2743 CALL auxbas_pw_pool%give_back_pw(rhodn_tot_gspace)
2747 IF (use_virial)
THEN
2748 IF (qs_env%energy_correction)
THEN
2749 ec_env%ehartree = ehartree + dehartree
2750 ec_env%exc = exc + eexc
2754 IF (debug_stress .AND. use_virial)
THEN
2756 stdeb = -1.0_dp*fconv*ehartree
2757 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2758 'STRESS| VOL 1st v_H[n_in]*n_out', one_third_sum_diag(stdeb), det_3x3(stdeb)
2760 stdeb = -1.0_dp*fconv*exc
2761 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2762 'STRESS| VOL 1st E_XC[n_in]', one_third_sum_diag(stdeb), det_3x3(stdeb)
2764 stdeb = -1.0_dp*fconv*dehartree
2765 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2766 'STRESS| VOL 2nd v_H[dP]*n_in', one_third_sum_diag(stdeb), det_3x3(stdeb)
2768 stdeb = -1.0_dp*fconv*eexc
2769 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2770 'STRESS| VOL 2nd v_XC[n_in]*dP', one_third_sum_diag(stdeb), det_3x3(stdeb)
2775 TYPE(virial_type) :: virdeb
2778 CALL para_env%sum(virdeb%pv_overlap)
2779 CALL para_env%sum(virdeb%pv_ekinetic)
2780 CALL para_env%sum(virdeb%pv_ppl)
2781 CALL para_env%sum(virdeb%pv_ppnl)
2782 CALL para_env%sum(virdeb%pv_ecore_overlap)
2783 CALL para_env%sum(virdeb%pv_ehartree)
2784 CALL para_env%sum(virdeb%pv_exc)
2785 CALL para_env%sum(virdeb%pv_exx)
2786 CALL para_env%sum(virdeb%pv_vdw)
2787 CALL para_env%sum(virdeb%pv_mp2)
2788 CALL para_env%sum(virdeb%pv_nlcc)
2789 CALL para_env%sum(virdeb%pv_gapw)
2790 CALL para_env%sum(virdeb%pv_lrigpw)
2791 CALL para_env%sum(virdeb%pv_virial)
2792 CALL symmetrize_virial(virdeb)
2796 virdeb%pv_ehartree(i, i) = virdeb%pv_ehartree(i, i) - 2.0_dp*(ehartree + dehartree)
2797 virdeb%pv_virial(i, i) = virdeb%pv_virial(i, i) - exc - eexc &
2798 - 2.0_dp*(ehartree + dehartree)
2799 virdeb%pv_exc(i, i) = virdeb%pv_exc(i, i) - exc - eexc
2805 CALL para_env%sum(sttot)
2806 stdeb = fconv*(virdeb%pv_virial - sttot)
2807 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2808 'STRESS| Explicit electronic stress ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2810 stdeb = fconv*(virdeb%pv_virial)
2811 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2812 'STRESS| Explicit total stress ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2814 CALL write_stress_tensor_components(virdeb, iounit, cell, unit_string)
2815 CALL write_stress_tensor(virdeb%pv_virial, iounit, cell, unit_string, .false.)
2820 CALL timestop(handle)
2822 END SUBROUTINE ec_build_ks_matrix_force
2832 SUBROUTINE ec_ks_solver(qs_env, ec_env)
2834 TYPE(qs_environment_type),
POINTER :: qs_env
2835 TYPE(energy_correction_type),
POINTER :: ec_env
2837 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ec_ks_solver'
2839 CHARACTER(LEN=default_string_length) :: headline
2840 INTEGER :: handle, img, ispin, nhfimg, nspins
2841 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: ksmat, pmat, smat, wmat
2842 TYPE(dbcsr_type),
POINTER :: tsmat
2843 TYPE(dft_control_type),
POINTER :: dft_control
2845 CALL timeset(routinen, handle)
2847 CALL get_qs_env(qs_env=qs_env, dft_control=dft_control)
2848 nspins = dft_control%nspins
2849 nhfimg =
SIZE(ec_env%matrix_s, 2)
2852 IF (.NOT.
ASSOCIATED(ec_env%matrix_p))
THEN
2853 headline =
"DENSITY MATRIX"
2854 CALL dbcsr_allocate_matrix_set(ec_env%matrix_p, nspins, nhfimg)
2855 DO ispin = 1, nspins
2857 tsmat => ec_env%matrix_s(1, img)%matrix
2858 ALLOCATE (ec_env%matrix_p(ispin, img)%matrix)
2859 CALL dbcsr_create(ec_env%matrix_p(ispin, img)%matrix, &
2860 name=trim(headline), template=tsmat)
2861 CALL cp_dbcsr_alloc_block_from_nbl(ec_env%matrix_p(ispin, img)%matrix, &
2867 IF (.NOT.
ASSOCIATED(ec_env%matrix_w))
THEN
2868 headline =
"ENERGY WEIGHTED DENSITY MATRIX"
2869 CALL dbcsr_allocate_matrix_set(ec_env%matrix_w, nspins, nhfimg)
2870 DO ispin = 1, nspins
2872 tsmat => ec_env%matrix_s(1, img)%matrix
2873 ALLOCATE (ec_env%matrix_w(ispin, img)%matrix)
2874 CALL dbcsr_create(ec_env%matrix_w(ispin, img)%matrix, &
2875 name=trim(headline), template=tsmat)
2876 CALL cp_dbcsr_alloc_block_from_nbl(ec_env%matrix_w(ispin, img)%matrix, &
2882 IF (ec_env%mao)
THEN
2883 CALL mao_create_matrices(ec_env, ksmat, smat, pmat, wmat)
2885 ksmat => ec_env%matrix_ks
2886 smat => ec_env%matrix_s
2887 pmat => ec_env%matrix_p
2888 wmat => ec_env%matrix_w
2891 IF (ec_env%do_kpoints)
THEN
2892 IF (ec_env%ks_solver /= ec_diagonalization)
THEN
2893 CALL cp_abort(__location__,
"Harris functional with k-points "// &
2894 "needs diagonalization solver")
2898 SELECT CASE (ec_env%ks_solver)
2899 CASE (ec_diagonalization)
2900 IF (ec_env%do_kpoints)
THEN
2901 CALL ec_diag_solver_kp(qs_env, ec_env, ksmat, smat, pmat, wmat)
2903 CALL ec_diag_solver_gamma(qs_env, ec_env, ksmat, smat, pmat, wmat)
2906 CALL ec_ot_diag_solver(qs_env, ec_env, ksmat, smat, pmat, wmat)
2907 CASE (ec_matrix_sign, ec_matrix_trs4, ec_matrix_tc2)
2908 CALL ec_ls_init(qs_env, ksmat, smat)
2909 CALL ec_ls_solver(qs_env, pmat, wmat, ec_ls_method=ec_env%ks_solver)
2911 cpabort(
"Option invalid or unavailable for ec_env%ks_solver")
2914 IF (ec_env%mao)
THEN
2915 CALL mao_release_matrices(ec_env, ksmat, smat, pmat, wmat)
2918 CALL timestop(handle)
2920 END SUBROUTINE ec_ks_solver
2933 SUBROUTINE mao_create_matrices(ec_env, ksmat, smat, pmat, wmat)
2935 TYPE(energy_correction_type),
POINTER :: ec_env
2936 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: ksmat, smat, pmat, wmat
2938 CHARACTER(LEN=*),
PARAMETER :: routinen =
'mao_create_matrices'
2940 INTEGER :: handle, ispin, nspins
2941 INTEGER,
DIMENSION(:),
POINTER :: col_blk_sizes
2942 TYPE(dbcsr_distribution_type) :: dbcsr_dist
2943 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: mao_coef
2944 TYPE(dbcsr_type) :: cgmat
2946 CALL timeset(routinen, handle)
2948 mao_coef => ec_env%mao_coef
2950 NULLIFY (ksmat, smat, pmat, wmat)
2951 nspins =
SIZE(ec_env%matrix_ks, 1)
2952 CALL dbcsr_get_info(mao_coef(1)%matrix, col_blk_size=col_blk_sizes, distribution=dbcsr_dist)
2953 CALL dbcsr_allocate_matrix_set(ksmat, nspins, 1)
2954 CALL dbcsr_allocate_matrix_set(smat, nspins, 1)
2955 DO ispin = 1, nspins
2956 ALLOCATE (ksmat(ispin, 1)%matrix)
2957 CALL dbcsr_create(ksmat(ispin, 1)%matrix, dist=dbcsr_dist, name=
"MAO KS mat", &
2958 matrix_type=dbcsr_type_symmetric, row_blk_size=col_blk_sizes, &
2959 col_blk_size=col_blk_sizes)
2960 ALLOCATE (smat(ispin, 1)%matrix)
2961 CALL dbcsr_create(smat(ispin, 1)%matrix, dist=dbcsr_dist, name=
"MAO S mat", &
2962 matrix_type=dbcsr_type_symmetric, row_blk_size=col_blk_sizes, &
2963 col_blk_size=col_blk_sizes)
2966 CALL dbcsr_create(cgmat, name=
"TEMP matrix", template=mao_coef(1)%matrix)
2967 DO ispin = 1, nspins
2968 CALL dbcsr_multiply(
"N",
"N", 1.0_dp, ec_env%matrix_s(1, 1)%matrix, mao_coef(ispin)%matrix, &
2970 CALL dbcsr_multiply(
"T",
"N", 1.0_dp, mao_coef(ispin)%matrix, cgmat, 0.0_dp, smat(ispin, 1)%matrix)
2971 CALL dbcsr_multiply(
"N",
"N", 1.0_dp, ec_env%matrix_ks(1, 1)%matrix, mao_coef(ispin)%matrix, &
2973 CALL dbcsr_multiply(
"T",
"N", 1.0_dp, mao_coef(ispin)%matrix, cgmat, 0.0_dp, ksmat(ispin, 1)%matrix)
2975 CALL dbcsr_release(cgmat)
2977 CALL dbcsr_allocate_matrix_set(pmat, nspins, 1)
2978 DO ispin = 1, nspins
2979 ALLOCATE (pmat(ispin, 1)%matrix)
2980 CALL dbcsr_create(pmat(ispin, 1)%matrix, template=smat(1, 1)%matrix, name=
"MAO P mat")
2981 CALL cp_dbcsr_alloc_block_from_nbl(pmat(ispin, 1)%matrix, ec_env%sab_orb)
2984 CALL dbcsr_allocate_matrix_set(wmat, nspins, 1)
2985 DO ispin = 1, nspins
2986 ALLOCATE (wmat(ispin, 1)%matrix)
2987 CALL dbcsr_create(wmat(ispin, 1)%matrix, template=smat(1, 1)%matrix, name=
"MAO W mat")
2988 CALL cp_dbcsr_alloc_block_from_nbl(wmat(ispin, 1)%matrix, ec_env%sab_orb)
2991 CALL timestop(handle)
2993 END SUBROUTINE mao_create_matrices
3006 SUBROUTINE mao_release_matrices(ec_env, ksmat, smat, pmat, wmat)
3008 TYPE(energy_correction_type),
POINTER :: ec_env
3009 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: ksmat, smat, pmat, wmat
3011 CHARACTER(LEN=*),
PARAMETER :: routinen =
'mao_release_matrices'
3013 INTEGER :: handle, ispin, nspins
3014 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: mao_coef
3015 TYPE(dbcsr_type) :: cgmat
3017 CALL timeset(routinen, handle)
3019 mao_coef => ec_env%mao_coef
3020 nspins =
SIZE(mao_coef, 1)
3023 CALL dbcsr_create(cgmat, name=
"TEMP matrix", template=mao_coef(1)%matrix)
3024 DO ispin = 1, nspins
3025 CALL dbcsr_multiply(
"N",
"N", 1.0_dp, mao_coef(ispin)%matrix, pmat(ispin, 1)%matrix, 0.0_dp, cgmat)
3026 CALL dbcsr_multiply(
"N",
"T", 1.0_dp, mao_coef(ispin)%matrix, cgmat, 0.0_dp, &
3027 ec_env%matrix_p(ispin, 1)%matrix, retain_sparsity=.true.)
3028 CALL dbcsr_multiply(
"N",
"N", 1.0_dp, mao_coef(ispin)%matrix, wmat(ispin, 1)%matrix, 0.0_dp, cgmat)
3029 CALL dbcsr_multiply(
"N",
"T", 1.0_dp, mao_coef(ispin)%matrix, cgmat, 0.0_dp, &
3030 ec_env%matrix_w(ispin, 1)%matrix, retain_sparsity=.true.)
3032 CALL dbcsr_release(cgmat)
3034 CALL dbcsr_deallocate_matrix_set(ksmat)
3035 CALL dbcsr_deallocate_matrix_set(smat)
3036 CALL dbcsr_deallocate_matrix_set(pmat)
3037 CALL dbcsr_deallocate_matrix_set(wmat)
3039 CALL timestop(handle)
3041 END SUBROUTINE mao_release_matrices
3049 SUBROUTINE ec_energy(ec_env, unit_nr)
3050 TYPE(energy_correction_type) :: ec_env
3051 INTEGER,
INTENT(IN) :: unit_nr
3053 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ec_energy'
3055 INTEGER :: handle, nspins
3056 REAL(kind=dp) :: eband, trace
3058 CALL timeset(routinen, handle)
3060 nspins =
SIZE(ec_env%matrix_p, 1)
3061 CALL calculate_ptrace(ec_env%matrix_s, ec_env%matrix_p, trace, nspins)
3062 IF (unit_nr > 0)
WRITE (unit_nr,
'(T3,A,T65,F16.10)')
'Tr[PS] ', trace
3065 SELECT CASE (ec_env%energy_functional)
3066 CASE (ec_functional_harris)
3069 CALL calculate_ptrace(ec_env%matrix_ks, ec_env%matrix_p, eband, nspins, .true.)
3070 ec_env%eband = eband + ec_env%efield_nuclear
3073 ec_env%etotal = ec_env%eband + ec_env%ehartree + ec_env%exc - ec_env%vhxc + ec_env%ekTS + &
3074 ec_env%edispersion - ec_env%ex
3075 IF (unit_nr > 0)
THEN
3076 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Eband ", ec_env%eband
3077 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Ehartree ", ec_env%ehartree
3078 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Exc ", ec_env%exc
3079 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Ex ", ec_env%ex
3080 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Evhxc ", ec_env%vhxc
3081 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Edisp ", ec_env%edispersion
3082 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Entropy ", ec_env%ekTS
3083 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Etotal Harris Functional ", ec_env%etotal
3086 CASE (ec_functional_dc)
3089 CALL calculate_ptrace(ec_env%matrix_h, ec_env%matrix_p, ec_env%ecore, nspins)
3091 ec_env%ecore = ec_env%ecore + ec_env%efield_nuclear
3092 ec_env%etotal = ec_env%ecore + ec_env%ehartree + ec_env%ehartree_1c + &
3093 ec_env%exc + ec_env%exc1 + ec_env%ekTS + ec_env%edispersion + &
3094 ec_env%ex + ec_env%exc_aux_fit + ec_env%exc1_aux_fit
3096 IF (unit_nr > 0)
THEN
3097 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Ecore ", ec_env%ecore
3098 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Ehartree ", ec_env%ehartree + ec_env%ehartree_1c
3099 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Exc ", ec_env%exc + ec_env%exc1
3100 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Ex ", ec_env%ex
3101 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Exc_aux_fit", ec_env%exc_aux_fit + ec_env%exc1_aux_fit
3102 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Edisp ", ec_env%edispersion
3103 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Entropy ", ec_env%ekTS
3104 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Etotal Energy Functional ", ec_env%etotal
3107 CASE (ec_functional_ext)
3109 ec_env%etotal = ec_env%ex
3110 IF (unit_nr > 0)
THEN
3111 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Etotal Energy Functional ", ec_env%etotal
3116 cpabort(
"Option invalid or unavailable for ec_env%energy_functional")
3120 CALL timestop(handle)
3122 END SUBROUTINE ec_energy
3134 SUBROUTINE ec_build_neighborlist(qs_env, ec_env)
3135 TYPE(qs_environment_type),
POINTER :: qs_env
3136 TYPE(energy_correction_type),
POINTER :: ec_env
3138 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ec_build_neighborlist'
3140 INTEGER :: handle, ikind, nimages, nkind, zat
3141 LOGICAL :: all_potential_present, gth_potential_present, paw_atom, paw_atom_present, &
3142 sgp_potential_present, skip_load_balance_distributed
3143 LOGICAL,
ALLOCATABLE,
DIMENSION(:) :: all_present, default_present, &
3144 oce_present, orb_present, ppl_present, &
3146 REAL(dp) :: subcells
3147 REAL(dp),
ALLOCATABLE,
DIMENSION(:) :: all_radius, c_radius, oce_radius, &
3148 orb_radius, ppl_radius, ppnl_radius
3149 REAL(dp),
ALLOCATABLE,
DIMENSION(:, :) :: pair_radius
3150 TYPE(all_potential_type),
POINTER :: all_potential
3151 TYPE(atomic_kind_type),
DIMENSION(:),
POINTER :: atomic_kind_set
3152 TYPE(cell_type),
POINTER :: cell
3153 TYPE(dft_control_type),
POINTER :: dft_control
3154 TYPE(distribution_1d_type),
POINTER :: distribution_1d
3155 TYPE(distribution_2d_type),
POINTER :: distribution_2d
3156 TYPE(gth_potential_type),
POINTER :: gth_potential
3157 TYPE(gto_basis_set_type),
POINTER :: basis_set
3158 TYPE(local_atoms_type),
ALLOCATABLE,
DIMENSION(:) :: atom2d
3159 TYPE(molecule_type),
DIMENSION(:),
POINTER :: molecule_set
3160 TYPE(mp_para_env_type),
POINTER :: para_env
3161 TYPE(neighbor_list_set_p_type),
DIMENSION(:), &
3162 POINTER :: sab_cn, sab_vdw
3163 TYPE(particle_type),
DIMENSION(:),
POINTER :: particle_set
3164 TYPE(paw_proj_set_type),
POINTER :: paw_proj
3165 TYPE(qs_dispersion_type),
POINTER :: dispersion_env
3166 TYPE(qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
3167 TYPE(qs_kind_type),
POINTER :: qs_kind
3168 TYPE(qs_ks_env_type),
POINTER :: ks_env
3169 TYPE(sgp_potential_type),
POINTER :: sgp_potential
3171 CALL timeset(routinen, handle)
3173 CALL get_qs_env(qs_env=qs_env, qs_kind_set=qs_kind_set)
3174 CALL get_qs_kind_set(qs_kind_set, &
3175 paw_atom_present=paw_atom_present, &
3176 all_potential_present=all_potential_present, &
3177 gth_potential_present=gth_potential_present, &
3178 sgp_potential_present=sgp_potential_present)
3179 nkind =
SIZE(qs_kind_set)
3180 ALLOCATE (c_radius(nkind), default_present(nkind))
3181 ALLOCATE (orb_radius(nkind), all_radius(nkind), ppl_radius(nkind), ppnl_radius(nkind))
3182 ALLOCATE (orb_present(nkind), all_present(nkind), ppl_present(nkind), ppnl_present(nkind))
3183 ALLOCATE (pair_radius(nkind, nkind))
3184 ALLOCATE (atom2d(nkind))
3186 CALL get_qs_env(qs_env, &
3187 atomic_kind_set=atomic_kind_set, &
3189 distribution_2d=distribution_2d, &
3190 local_particles=distribution_1d, &
3191 particle_set=particle_set, &
3192 molecule_set=molecule_set)
3194 CALL atom2d_build(atom2d, distribution_1d, distribution_2d, atomic_kind_set, &
3195 molecule_set, .false., particle_set)
3198 CALL get_atomic_kind(atomic_kind_set(ikind), atom_list=atom2d(ikind)%list)
3199 qs_kind => qs_kind_set(ikind)
3200 CALL get_qs_kind(qs_kind=qs_kind, basis_set=basis_set, basis_type=
"HARRIS")
3201 IF (
ASSOCIATED(basis_set))
THEN
3202 orb_present(ikind) = .true.
3203 CALL get_gto_basis_set(gto_basis_set=basis_set, kind_radius=orb_radius(ikind))
3205 orb_present(ikind) = .false.
3206 orb_radius(ikind) = 0.0_dp
3208 CALL get_qs_kind(qs_kind, all_potential=all_potential, &
3209 gth_potential=gth_potential, sgp_potential=sgp_potential)
3210 IF (gth_potential_present .OR. sgp_potential_present)
THEN
3211 IF (
ASSOCIATED(gth_potential))
THEN
3212 CALL get_potential(potential=gth_potential, &
3213 ppl_present=ppl_present(ikind), &
3214 ppl_radius=ppl_radius(ikind), &
3215 ppnl_present=ppnl_present(ikind), &
3216 ppnl_radius=ppnl_radius(ikind))
3217 ELSE IF (
ASSOCIATED(sgp_potential))
THEN
3218 CALL get_potential(potential=sgp_potential, &
3219 ppl_present=ppl_present(ikind), &
3220 ppl_radius=ppl_radius(ikind), &
3221 ppnl_present=ppnl_present(ikind), &
3222 ppnl_radius=ppnl_radius(ikind))
3224 ppl_present(ikind) = .false.
3225 ppl_radius(ikind) = 0.0_dp
3226 ppnl_present(ikind) = .false.
3227 ppnl_radius(ikind) = 0.0_dp
3231 IF (all_potential_present .OR. sgp_potential_present)
THEN
3232 all_present(ikind) = .false.
3233 all_radius(ikind) = 0.0_dp
3234 IF (
ASSOCIATED(all_potential))
THEN
3235 all_present(ikind) = .true.
3236 CALL get_potential(potential=all_potential, core_charge_radius=all_radius(ikind))
3237 ELSE IF (
ASSOCIATED(sgp_potential))
THEN
3238 IF (sgp_potential%ecp_local)
THEN
3239 all_present(ikind) = .true.
3240 CALL get_potential(potential=sgp_potential, core_charge_radius=all_radius(ikind))
3246 CALL section_vals_val_get(qs_env%input,
"DFT%SUBCELLS", r_val=subcells)
3249 CALL pair_radius_setup(orb_present, orb_present, orb_radius, orb_radius, pair_radius)
3250 CALL build_neighbor_lists(ec_env%sab_orb, particle_set, atom2d, cell, pair_radius, &
3251 subcells=subcells, nlname=
"sab_orb")
3253 IF (ec_env%do_kpoints)
THEN
3255 CALL build_neighbor_lists(ec_env%sab_kp, particle_set, atom2d, cell, pair_radius, &
3256 subcells=subcells, nlname=
"sab_kp")
3257 IF (ec_env%do_ec_hfx)
THEN
3258 CALL build_neighbor_lists(ec_env%sab_kp_nosym, particle_set, atom2d, cell, pair_radius, &
3259 subcells=subcells, nlname=
"sab_kp_nosym", symmetric=.false.)
3261 CALL get_qs_env(qs_env=qs_env, para_env=para_env)
3262 CALL kpoint_init_cell_index(ec_env%kpoints, ec_env%sab_kp, para_env, nimages)
3266 IF (all_potential_present .OR. sgp_potential_present)
THEN
3267 IF (any(all_present))
THEN
3268 CALL pair_radius_setup(orb_present, all_present, orb_radius, all_radius, pair_radius)
3269 CALL build_neighbor_lists(ec_env%sac_ae, particle_set, atom2d, cell, pair_radius, &
3270 subcells=subcells, operator_type=
"ABC", nlname=
"sac_ae")
3274 IF (gth_potential_present .OR. sgp_potential_present)
THEN
3275 IF (any(ppl_present))
THEN
3276 CALL pair_radius_setup(orb_present, ppl_present, orb_radius, ppl_radius, pair_radius)
3277 CALL build_neighbor_lists(ec_env%sac_ppl, particle_set, atom2d, cell, pair_radius, &
3278 subcells=subcells, operator_type=
"ABC", nlname=
"sac_ppl")
3281 IF (any(ppnl_present))
THEN
3282 CALL pair_radius_setup(orb_present, ppnl_present, orb_radius, ppnl_radius, pair_radius)
3283 CALL build_neighbor_lists(ec_env%sap_ppnl, particle_set, atom2d, cell, pair_radius, &
3284 subcells=subcells, operator_type=
"ABBA", nlname=
"sap_ppnl")
3289 c_radius(:) = 0.0_dp
3290 dispersion_env => ec_env%dispersion_env
3291 sab_vdw => dispersion_env%sab_vdw
3292 sab_cn => dispersion_env%sab_cn
3293 IF (dispersion_env%type == xc_vdw_fun_pairpot)
THEN
3294 c_radius(:) = dispersion_env%rc_disp
3295 default_present = .true.
3296 CALL pair_radius_setup(default_present, default_present, c_radius, c_radius, pair_radius)
3297 CALL build_neighbor_lists(sab_vdw, particle_set, atom2d, cell, pair_radius, &
3298 subcells=subcells, operator_type=
"PP", nlname=
"sab_vdw")
3299 dispersion_env%sab_vdw => sab_vdw
3300 IF (dispersion_env%pp_type == vdw_pairpot_dftd3 .OR. &
3301 dispersion_env%pp_type == vdw_pairpot_dftd3bj)
THEN
3304 CALL get_atomic_kind(atomic_kind_set(ikind), z=zat)
3305 c_radius(ikind) = 4._dp*ptable(zat)%covalent_radius*bohr
3307 CALL pair_radius_setup(default_present, default_present, c_radius, c_radius, pair_radius)
3308 CALL build_neighbor_lists(sab_cn, particle_set, atom2d, cell, pair_radius, &
3309 subcells=subcells, operator_type=
"PP", nlname=
"sab_cn")
3310 dispersion_env%sab_cn => sab_cn
3315 IF (paw_atom_present)
THEN
3316 IF (paw_atom_present)
THEN
3317 ALLOCATE (oce_present(nkind), oce_radius(nkind))
3322 CALL get_qs_kind(qs_kind_set(ikind), paw_proj_set=paw_proj, paw_atom=paw_atom)
3324 oce_present(ikind) = .true.
3325 CALL get_paw_proj_set(paw_proj_set=paw_proj, rcprj=oce_radius(ikind))
3327 oce_present(ikind) = .false.
3332 IF (any(oce_present))
THEN
3333 CALL pair_radius_setup(orb_present, oce_present, orb_radius, oce_radius, pair_radius)
3334 CALL build_neighbor_lists(ec_env%sap_oce, particle_set, atom2d, cell, pair_radius, &
3335 subcells=subcells, operator_type=
"ABBA", nlname=
"sap_oce")
3337 DEALLOCATE (oce_present, oce_radius)
3341 CALL atom2d_cleanup(atom2d)
3343 DEALLOCATE (orb_present, default_present, all_present, ppl_present, ppnl_present)
3344 DEALLOCATE (orb_radius, all_radius, ppl_radius, ppnl_radius, c_radius)
3345 DEALLOCATE (pair_radius)
3348 CALL get_qs_env(qs_env, ks_env=ks_env, dft_control=dft_control)
3349 skip_load_balance_distributed = dft_control%qs_control%skip_load_balance_distributed
3350 IF (
ASSOCIATED(ec_env%task_list))
CALL deallocate_task_list(ec_env%task_list)
3351 CALL allocate_task_list(ec_env%task_list)
3352 CALL generate_qs_task_list(ks_env, ec_env%task_list, basis_type=
"HARRIS", &
3353 reorder_rs_grid_ranks=.false., &
3354 skip_load_balance_distributed=skip_load_balance_distributed, &
3355 sab_orb_external=ec_env%sab_orb, &
3356 ext_kpoints=ec_env%kpoints)
3358 IF (dft_control%qs_control%gapw .OR. dft_control%qs_control%gapw_xc)
THEN
3359 IF (
ASSOCIATED(ec_env%task_list_soft))
CALL deallocate_task_list(ec_env%task_list_soft)
3360 CALL allocate_task_list(ec_env%task_list_soft)
3361 CALL generate_qs_task_list(ks_env, ec_env%task_list_soft, basis_type=
"HARRIS_SOFT", &
3362 reorder_rs_grid_ranks=.false., &
3363 skip_load_balance_distributed=skip_load_balance_distributed, &
3364 sab_orb_external=ec_env%sab_orb, &
3365 ext_kpoints=ec_env%kpoints)
3368 CALL timestop(handle)
3370 END SUBROUTINE ec_build_neighborlist
3377 SUBROUTINE ec_properties(qs_env, ec_env)
3378 TYPE(qs_environment_type),
POINTER :: qs_env
3379 TYPE(energy_correction_type),
POINTER :: ec_env
3381 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ec_properties'
3383 CHARACTER(LEN=8),
DIMENSION(3) :: rlab
3384 CHARACTER(LEN=default_path_length) :: filename, my_pos_voro
3385 CHARACTER(LEN=default_string_length) :: description
3386 INTEGER :: akind, handle, i, ia, iatom, idir, ikind, iounit, ispin, maxmom, nspins, &
3387 reference, should_print_bqb, should_print_voro, unit_nr, unit_nr_voro
3388 LOGICAL :: append_voro, magnetic, periodic, &
3390 REAL(kind=dp) :: charge, dd, focc, tmp
3391 REAL(kind=dp),
DIMENSION(3) :: cdip, pdip, rcc, rdip, ria, tdip
3392 REAL(kind=dp),
DIMENSION(:),
POINTER :: ref_point
3393 TYPE(atomic_kind_type),
POINTER :: atomic_kind
3394 TYPE(cell_type),
POINTER :: cell
3395 TYPE(cp_logger_type),
POINTER :: logger
3396 TYPE(cp_result_type),
POINTER :: results
3397 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_s, moments
3398 TYPE(dft_control_type),
POINTER :: dft_control
3399 TYPE(distribution_1d_type),
POINTER :: local_particles
3400 TYPE(mp_para_env_type),
POINTER :: para_env
3401 TYPE(particle_type),
DIMENSION(:),
POINTER :: particle_set
3402 TYPE(pw_env_type),
POINTER :: pw_env
3403 TYPE(pw_pool_p_type),
DIMENSION(:),
POINTER :: pw_pools
3404 TYPE(pw_pool_type),
POINTER :: auxbas_pw_pool
3405 TYPE(pw_r3d_rs_type) :: rho_elec_rspace
3406 TYPE(qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
3407 TYPE(section_vals_type),
POINTER :: ec_section, print_key, print_key_bqb, &
3410 CALL timeset(routinen, handle)
3416 logger => cp_get_default_logger()
3417 IF (logger%para_env%is_source())
THEN
3418 iounit = cp_logger_get_default_unit_nr(logger, local=.true.)
3423 NULLIFY (dft_control)
3424 CALL get_qs_env(qs_env, dft_control=dft_control)
3425 nspins = dft_control%nspins
3427 ec_section => section_vals_get_subs_vals(qs_env%input,
"DFT%ENERGY_CORRECTION")
3428 print_key => section_vals_get_subs_vals(section_vals=ec_section, &
3429 subsection_name=
"PRINT%MOMENTS")
3431 IF (btest(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file))
THEN
3433 IF (dft_control%qs_control%gapw .OR. dft_control%qs_control%gapw_xc)
THEN
3434 cpabort(
"Properties for GAPW in EC NYA")
3437 maxmom = section_get_ival(section_vals=ec_section, &
3438 keyword_name=
"PRINT%MOMENTS%MAX_MOMENT")
3439 periodic = section_get_lval(section_vals=ec_section, &
3440 keyword_name=
"PRINT%MOMENTS%PERIODIC")
3441 reference = section_get_ival(section_vals=ec_section, &
3442 keyword_name=
"PRINT%MOMENTS%REFERENCE")
3443 magnetic = section_get_lval(section_vals=ec_section, &
3444 keyword_name=
"PRINT%MOMENTS%MAGNETIC")
3446 CALL section_vals_val_get(ec_section,
"PRINT%MOMENTS%REF_POINT", r_vals=ref_point)
3447 unit_nr = cp_print_key_unit_nr(logger=logger, basis_section=ec_section, &
3448 print_key_path=
"PRINT%MOMENTS", extension=
".dat", &
3449 middle_name=
"moments", log_filename=.false.)
3451 IF (iounit > 0)
THEN
3452 IF (unit_nr /= iounit .AND. unit_nr > 0)
THEN
3453 INQUIRE (unit=unit_nr, name=filename)
3454 WRITE (unit=iounit, fmt=
"(/,T2,A,2(/,T3,A),/)") &
3455 "MOMENTS",
"The electric/magnetic moments are written to file:", &
3458 WRITE (unit=iounit, fmt=
"(/,T2,A)")
"ELECTRIC/MAGNETIC MOMENTS"
3463 cpabort(
"Periodic moments not implemented with EC")
3465 cpassert(maxmom < 2)
3466 cpassert(.NOT. magnetic)
3467 IF (maxmom == 1)
THEN
3468 CALL get_qs_env(qs_env=qs_env, cell=cell, para_env=para_env)
3470 CALL get_reference_point(rcc, qs_env=qs_env, reference=reference, ref_point=ref_point)
3473 CALL get_qs_env(qs_env=qs_env, particle_set=particle_set, &
3474 qs_kind_set=qs_kind_set, local_particles=local_particles)
3475 DO ikind = 1,
SIZE(local_particles%n_el)
3476 DO ia = 1, local_particles%n_el(ikind)
3477 iatom = local_particles%list(ikind)%array(ia)
3479 ria = pbc(particle_set(iatom)%r - rcc, cell) + rcc
3481 atomic_kind => particle_set(iatom)%atomic_kind
3482 CALL get_atomic_kind(atomic_kind, kind_number=akind)
3483 CALL get_qs_kind(qs_kind_set(akind), core_charge=charge)
3484 cdip(1:3) = cdip(1:3) - charge*ria(1:3)
3487 CALL para_env%sum(cdip)
3490 CALL ec_efield_integrals(qs_env, ec_env, rcc)
3493 DO ispin = 1, nspins
3495 CALL dbcsr_dot(ec_env%matrix_p(ispin, 1)%matrix, &
3496 ec_env%efield%dipmat(idir)%matrix, tmp)
3497 pdip(idir) = pdip(idir) + tmp
3502 CALL get_qs_env(qs_env=qs_env, matrix_s=matrix_s)
3504 CALL dbcsr_allocate_matrix_set(moments, 4)
3506 ALLOCATE (moments(i)%matrix)
3507 CALL dbcsr_copy(moments(i)%matrix, matrix_s(1)%matrix,
"Moments")
3508 CALL dbcsr_set(moments(i)%matrix, 0.0_dp)
3510 CALL build_local_moment_matrix(qs_env, moments, 1, ref_point=rcc)
3513 IF (nspins == 2) focc = 1.0_dp
3515 DO ispin = 1, nspins
3517 CALL dbcsr_dot(ec_env%matrix_z(ispin)%matrix, moments(idir)%matrix, tmp)
3518 rdip(idir) = rdip(idir) + tmp
3521 CALL dbcsr_deallocate_matrix_set(moments)
3523 tdip = -(rdip + pdip + cdip)
3524 IF (unit_nr > 0)
THEN
3525 WRITE (unit_nr,
"(T3,A)")
"Dipoles are based on the traditional operator."
3526 dd = sqrt(sum(tdip(1:3)**2))*debye
3527 WRITE (unit_nr,
"(T3,A)")
"Dipole moment [Debye]"
3528 WRITE (unit_nr,
"(T5,3(A,A,F14.8,1X),T60,A,T67,F14.8)") &
3529 (trim(rlab(i)),
"=", tdip(i)*debye, i=1, 3),
"Total=", dd
3534 CALL cp_print_key_finished_output(unit_nr=unit_nr, logger=logger, &
3535 basis_section=ec_section, print_key_path=
"PRINT%MOMENTS")
3536 CALL get_qs_env(qs_env=qs_env, results=results)
3537 description =
"[DIPOLE]"
3538 CALL cp_results_erase(results=results, description=description)
3539 CALL put_results(results=results, description=description, values=tdip(1:3))
3543 print_key_voro => section_vals_get_subs_vals(ec_section,
"PRINT%VORONOI")
3544 print_key_bqb => section_vals_get_subs_vals(ec_section,
"PRINT%E_DENSITY_BQB")
3545 IF (btest(cp_print_key_should_output(logger%iter_info, print_key_voro), cp_p_file))
THEN
3546 should_print_voro = 1
3548 should_print_voro = 0
3550 IF (btest(cp_print_key_should_output(logger%iter_info, print_key_bqb), cp_p_file))
THEN
3551 should_print_bqb = 1
3553 should_print_bqb = 0
3555 IF ((should_print_voro /= 0) .OR. (should_print_bqb /= 0))
THEN
3557 IF (dft_control%qs_control%gapw .OR. dft_control%qs_control%gapw_xc)
THEN
3558 cpabort(
"Properties for GAPW in EC NYA")
3561 CALL get_qs_env(qs_env=qs_env, &
3563 CALL pw_env_get(pw_env=pw_env, &
3564 auxbas_pw_pool=auxbas_pw_pool, &
3566 CALL auxbas_pw_pool%create_pw(pw=rho_elec_rspace)
3568 IF (dft_control%nspins > 1)
THEN
3571 CALL pw_copy(ec_env%rhoout_r(1), rho_elec_rspace)
3572 CALL pw_axpy(ec_env%rhoout_r(2), rho_elec_rspace)
3574 CALL pw_axpy(ec_env%rhoz_r(1), rho_elec_rspace)
3575 CALL pw_axpy(ec_env%rhoz_r(2), rho_elec_rspace)
3579 CALL pw_copy(ec_env%rhoout_r(1), rho_elec_rspace)
3580 CALL pw_axpy(ec_env%rhoz_r(1), rho_elec_rspace)
3583 IF (should_print_voro /= 0)
THEN
3584 CALL section_vals_val_get(print_key_voro,
"OUTPUT_TEXT", l_val=voro_print_txt)
3585 IF (voro_print_txt)
THEN
3586 append_voro = section_get_lval(ec_section,
"PRINT%VORONOI%APPEND")
3587 my_pos_voro =
"REWIND"
3588 IF (append_voro)
THEN
3589 my_pos_voro =
"APPEND"
3591 unit_nr_voro = cp_print_key_unit_nr(logger, ec_section,
"PRINT%VORONOI", extension=
".voronoi", &
3592 file_position=my_pos_voro, log_filename=.false.)
3600 CALL entry_voronoi_or_bqb(should_print_voro, should_print_bqb, print_key_voro, print_key_bqb, &
3601 unit_nr_voro, qs_env, rho_elec_rspace)
3603 CALL auxbas_pw_pool%give_back_pw(rho_elec_rspace)
3605 IF (unit_nr_voro > 0)
THEN
3606 CALL cp_print_key_finished_output(unit_nr_voro, logger, ec_section,
"PRINT%VORONOI")
3611 CALL timestop(handle)
3613 END SUBROUTINE ec_properties
3620 SUBROUTINE harris_wfn_output(qs_env, ec_env, unit_nr)
3621 TYPE(qs_environment_type),
POINTER :: qs_env
3622 TYPE(energy_correction_type),
POINTER :: ec_env
3623 INTEGER,
INTENT(IN) :: unit_nr
3625 CHARACTER(LEN=*),
PARAMETER :: routinen =
'harris_wfn_output'
3627 INTEGER :: handle, ic, ires, ispin, nimages, nsize, &
3629 INTEGER,
DIMENSION(3) :: cell
3630 INTEGER,
DIMENSION(:, :, :),
POINTER :: cell_to_index
3631 TYPE(cp_blacs_env_type),
POINTER :: blacs_env
3632 TYPE(cp_fm_struct_type),
POINTER :: fm_struct
3633 TYPE(cp_fm_type) :: fmat
3634 TYPE(cp_logger_type),
POINTER :: logger
3635 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: denmat
3636 TYPE(mp_para_env_type),
POINTER :: para_env
3637 TYPE(particle_type),
DIMENSION(:),
POINTER :: particle_set
3638 TYPE(qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
3639 TYPE(section_vals_type),
POINTER :: ec_section
3643 CALL timeset(routinen, handle)
3645 logger => cp_get_default_logger()
3647 ec_section => section_vals_get_subs_vals(qs_env%input,
"DFT%ENERGY_CORRECTION")
3648 CALL get_qs_env(qs_env, qs_kind_set=qs_kind_set, particle_set=particle_set)
3650 IF (ec_env%do_kpoints)
THEN
3651 ires = cp_print_key_unit_nr(logger, ec_section,
"PRINT%HARRIS_OUTPUT_WFN", &
3652 extension=
".kp", file_status=
"REPLACE", file_action=
"WRITE", &
3653 file_form=
"UNFORMATTED", middle_name=
"Harris")
3655 CALL write_kpoints_file_header(qs_kind_set, particle_set, ires, basis_type=
"HARRIS")
3657 denmat => ec_env%matrix_p
3658 nspin =
SIZE(denmat, 1)
3659 nimages =
SIZE(denmat, 2)
3660 NULLIFY (cell_to_index)
3661 IF (nimages > 1)
THEN
3662 CALL get_kpoint_info(kpoint=ec_env%kpoints, cell_to_index=cell_to_index)
3664 CALL dbcsr_get_info(denmat(1, 1)%matrix, nfullrows_total=nsize)
3665 NULLIFY (blacs_env, para_env)
3666 CALL get_qs_env(qs_env=qs_env, blacs_env=blacs_env, para_env=para_env)
3668 CALL cp_fm_struct_create(fm_struct, context=blacs_env, nrow_global=nsize, &
3669 ncol_global=nsize, para_env=para_env)
3670 CALL cp_fm_create(fmat, fm_struct)
3671 CALL cp_fm_struct_release(fm_struct)
3674 IF (ires > 0)
WRITE (ires) ispin, nspin, nimages
3676 IF (nimages > 1)
THEN
3677 cell = get_cell(ic, cell_to_index)
3681 IF (ires > 0)
WRITE (ires) ic, cell
3682 CALL copy_dbcsr_to_fm(denmat(ispin, ic)%matrix, fmat)
3683 CALL cp_fm_write_unformatted(fmat, ires)
3687 CALL cp_print_key_finished_output(ires, logger, ec_section,
"PRINT%HARRIS_OUTPUT_WFN")
3688 CALL cp_fm_release(fmat)
3690 CALL cp_warn(__location__, &
3691 "Orbital energy correction potential is an experimental feature. "// &
3692 "Use it with extreme care")
3695 CALL timestop(handle)
3697 END SUBROUTINE harris_wfn_output
3705 SUBROUTINE response_force_error(qs_env, ec_env, unit_nr)
3706 TYPE(qs_environment_type),
POINTER :: qs_env
3707 TYPE(energy_correction_type),
POINTER :: ec_env
3708 INTEGER,
INTENT(IN) :: unit_nr
3710 CHARACTER(LEN=10) :: eformat
3711 INTEGER :: feunit, funit, i, ia, ib, ispin, mref, &
3712 na, nao, natom, nb, norb, nref, &
3714 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: natom_of_kind, rlist, t2cind
3715 LOGICAL :: debug_f, do_resp, is_source
3716 REAL(kind=dp) :: focc, rfac, vres
3717 REAL(kind=dp),
ALLOCATABLE,
DIMENSION(:) :: tvec, yvec
3718 REAL(kind=dp),
ALLOCATABLE,
DIMENSION(:, :) :: eforce, fmlocal, fmreord, smat
3719 REAL(kind=dp),
ALLOCATABLE,
DIMENSION(:, :, :) :: smpforce
3720 TYPE(atomic_kind_type),
DIMENSION(:),
POINTER :: atomic_kind_set
3721 TYPE(cp_fm_struct_type),
POINTER :: fm_struct, fm_struct_mat
3722 TYPE(cp_fm_type) :: hmats
3723 TYPE(cp_fm_type),
DIMENSION(:, :),
POINTER :: rpmos, spmos
3724 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_s
3725 TYPE(dbcsr_type),
POINTER :: mats
3726 TYPE(mp_para_env_type),
POINTER :: para_env
3727 TYPE(qs_force_type),
DIMENSION(:),
POINTER :: ks_force, res_force
3728 TYPE(virial_type) :: res_virial
3729 TYPE(virial_type),
POINTER :: ks_virial
3731 IF (unit_nr > 0)
THEN
3732 WRITE (unit_nr,
'(/,T2,A,A,A,A,A)')
"!", repeat(
"-", 25), &
3733 " Response Force Error Est. ", repeat(
"-", 25),
"!"
3734 SELECT CASE (ec_env%error_method)
3736 WRITE (unit_nr,
'(T2,A)')
" Response Force Error Est. using full RHS"
3738 WRITE (unit_nr,
'(T2,A)')
" Response Force Error Est. using delta RHS"
3740 WRITE (unit_nr,
'(T2,A)')
" Response Force Error Est. using extrapolated RHS"
3741 WRITE (unit_nr,
'(T2,A,E20.10)')
" Extrapolation cutoff:", ec_env%error_cutoff
3742 WRITE (unit_nr,
'(T2,A,I10)')
" Max. extrapolation size:", ec_env%error_subspace
3744 cpabort(
"Unknown Error Estimation Method")
3748 IF (abs(ec_env%orbrot_index) > 1.e-8_dp .OR. ec_env%phase_index > 1.e-8_dp)
THEN
3749 cpabort(
"Response error calculation for rotated orbital sets not implemented")
3752 SELECT CASE (ec_env%energy_functional)
3753 CASE (ec_functional_harris)
3754 cpwarn(
'Response force error calculation not possible for Harris functional.')
3755 CASE (ec_functional_dc)
3756 cpwarn(
'Response force error calculation not possible for DCDFT.')
3757 CASE (ec_functional_ext)
3760 CALL get_qs_env(qs_env, force=ks_force, virial=ks_virial, &
3761 atomic_kind_set=atomic_kind_set)
3762 CALL get_atomic_kind_set(atomic_kind_set=atomic_kind_set, natom_of_kind=natom_of_kind)
3764 CALL allocate_qs_force(res_force, natom_of_kind)
3765 DEALLOCATE (natom_of_kind)
3766 CALL zero_qs_force(res_force)
3767 res_virial = ks_virial
3768 CALL zero_virial(ks_virial, reset=.false.)
3769 CALL set_qs_env(qs_env, force=res_force)
3771 CALL get_qs_env(qs_env, natom=natom)
3772 ALLOCATE (eforce(3, natom))
3774 CALL get_qs_env(qs_env, para_env=para_env)
3775 is_source = para_env%is_source()
3777 nspins =
SIZE(ec_env%mo_occ)
3778 CALL cp_fm_get_info(ec_env%mo_occ(1), nrow_global=nao)
3781 CALL open_file(ec_env%exresperr_fn, file_status=
"OLD", file_action=
"READ", &
3782 file_form=
"FORMATTED", unit_number=funit)
3783 READ (funit,
'(A)') eformat
3784 CALL uppercase(eformat)
3785 READ (funit, *) nsample
3787 CALL para_env%bcast(nsample, para_env%source)
3788 CALL para_env%bcast(eformat, para_env%source)
3790 CALL cp_fm_get_info(ec_env%mo_occ(1), matrix_struct=fm_struct)
3791 CALL cp_fm_struct_create(fm_struct_mat, template_fmstruct=fm_struct, &
3792 nrow_global=nao, ncol_global=nao)
3793 ALLOCATE (fmlocal(nao, nao))
3794 IF (adjustl(trim(eformat)) ==
"TREXIO")
THEN
3795 ALLOCATE (fmreord(nao, nao))
3796 CALL get_t2cindex(qs_env, t2cind)
3798 ALLOCATE (rpmos(nsample, nspins))
3799 ALLOCATE (smpforce(3, natom, nsample))
3803 IF (nspins == 1) focc = 4.0_dp
3804 CALL cp_fm_create(hmats, fm_struct_mat)
3807 DO ispin = 1, nspins
3808 CALL cp_fm_create(rpmos(i, ispin), fm_struct)
3810 READ (funit, *) na, nb
3811 cpassert(na == nao .AND. nb == nao)
3812 READ (funit, *) fmlocal
3816 CALL para_env%bcast(fmlocal)
3818 SELECT CASE (adjustl(trim(eformat)))
3825 fmreord(ia, ib) = fmlocal(t2cind(ia), t2cind(ib))
3828 fmlocal(1:nao, 1:nao) = fmreord(1:nao, 1:nao)
3830 cpabort(
"Error file dE/dC: unknown format")
3833 CALL cp_fm_set_submatrix(hmats, fmlocal, 1, 1, nao, nao)
3834 CALL cp_fm_get_info(rpmos(i, ispin), ncol_global=norb)
3835 CALL parallel_gemm(
'N',
'N', nao, norb, nao, focc, hmats, &
3836 ec_env%mo_occ(ispin), 0.0_dp, rpmos(i, ispin))
3837 IF (ec_env%error_method ==
"D" .OR. ec_env%error_method ==
"E")
THEN
3838 CALL cp_fm_scale_and_add(1.0_dp, rpmos(i, ispin), -1.0_dp, ec_env%cpref(ispin))
3842 CALL cp_fm_struct_release(fm_struct_mat)
3843 IF (adjustl(trim(eformat)) ==
"TREXIO")
THEN
3844 DEALLOCATE (fmreord, t2cind)
3848 CALL close_file(funit)
3851 IF (unit_nr > 0)
THEN
3852 CALL open_file(ec_env%exresult_fn, file_status=
"OLD", file_form=
"FORMATTED", &
3853 file_action=
"WRITE", file_position=
"APPEND", unit_number=feunit)
3854 WRITE (feunit,
"(/,6X,A)")
" Response Forces from error sampling [Hartree/Bohr]"
3856 WRITE (feunit,
"(5X,I8)") i
3858 WRITE (feunit,
"(5X,3F20.12)") ec_env%rf(1:3, ia)
3862 debug_f = ec_env%debug_forces .OR. ec_env%debug_stress
3864 IF (ec_env%error_method ==
"E")
THEN
3865 CALL get_qs_env(qs_env, matrix_s=matrix_s)
3866 mats => matrix_s(1)%matrix
3867 ALLOCATE (spmos(nsample, nspins))
3869 DO ispin = 1, nspins
3870 CALL cp_fm_create(spmos(i, ispin), fm_struct, set_zero=.true.)
3871 CALL cp_dbcsr_sm_fm_multiply(mats, rpmos(i, ispin), spmos(i, ispin), norb)
3876 mref = ec_env%error_subspace
3877 mref = min(mref, nsample)
3879 ALLOCATE (smat(mref, mref), tvec(mref), yvec(mref), rlist(mref))
3882 CALL cp_fm_release(ec_env%cpmos)
3885 IF (unit_nr > 0)
THEN
3886 WRITE (unit_nr,
'(T2,A,I6)')
" Response Force Number ", i
3889 CALL zero_qs_force(res_force)
3890 CALL zero_virial(ks_virial, reset=.false.)
3891 DO ispin = 1, nspins
3892 CALL dbcsr_set(ec_env%matrix_hz(ispin)%matrix, 0.0_dp)
3895 ALLOCATE (ec_env%cpmos(nspins))
3896 DO ispin = 1, nspins
3897 CALL cp_fm_create(ec_env%cpmos(ispin), fm_struct)
3901 IF (ec_env%error_method ==
"F" .OR. ec_env%error_method ==
"D")
THEN
3902 DO ispin = 1, nspins
3903 CALL cp_fm_to_fm(rpmos(i, ispin), ec_env%cpmos(ispin))
3905 ELSE IF (ec_env%error_method ==
"E")
THEN
3906 CALL cp_extrapolate(rpmos, spmos, i, nref, rlist, smat, tvec, yvec, vres)
3907 IF (vres > ec_env%error_cutoff .OR. nref < min(5, mref))
THEN
3908 DO ispin = 1, nspins
3909 CALL cp_fm_to_fm(rpmos(i, ispin), ec_env%cpmos(ispin))
3914 DO ispin = 1, nspins
3915 CALL cp_fm_scale_and_add(1.0_dp, ec_env%cpmos(ispin), &
3916 rfac, rpmos(ia, ispin))
3922 IF (unit_nr > 0)
THEN
3923 WRITE (unit_nr,
'(T2,A,T60,I4,T69,F12.8)') &
3924 " Response Vector Extrapolation [nref|delta] = ", nref, vres
3927 cpabort(
"Unknown Error Estimation Method")
3931 CALL matrix_r_forces(qs_env, ec_env%cpmos, ec_env%mo_occ, &
3932 ec_env%matrix_w(1, 1)%matrix, unit_nr, &
3933 ec_env%debug_forces, ec_env%debug_stress)
3935 CALL response_calculation(qs_env, ec_env, silent=.true.)
3937 CALL response_force(qs_env, &
3938 vh_rspace=ec_env%vh_rspace, &
3939 vxc_rspace=ec_env%vxc_rspace, &
3940 vtau_rspace=ec_env%vtau_rspace, &
3941 vadmm_rspace=ec_env%vadmm_rspace, &
3942 vadmm_tau_rspace=ec_env%vadmm_tau_rspace, &
3943 matrix_hz=ec_env%matrix_hz, &
3944 matrix_pz=ec_env%matrix_z, &
3945 matrix_pz_admm=ec_env%z_admm, &
3946 matrix_wz=ec_env%matrix_wz, &
3947 rhopz_r=ec_env%rhoz_r, &
3948 zehartree=ec_env%ehartree, &
3950 zexc_aux_fit=ec_env%exc_aux_fit, &
3951 p_env=ec_env%p_env, &
3953 CALL total_qs_force(eforce, res_force, atomic_kind_set)
3954 CALL para_env%sum(eforce)
3956 IF (unit_nr > 0)
THEN
3957 WRITE (unit_nr,
'(T2,A)')
" Response Force Calculation is skipped. "
3962 IF (ec_env%error_method ==
"D")
THEN
3963 eforce(1:3, 1:natom) = eforce(1:3, 1:natom) + ec_env%rf(1:3, 1:natom)
3964 smpforce(1:3, 1:natom, i) = eforce(1:3, 1:natom)
3965 ELSE IF (ec_env%error_method ==
"E")
THEN
3969 eforce(1:3, 1:natom) = eforce(1:3, 1:natom) + rfac*smpforce(1:3, 1:natom, ia)
3971 smpforce(1:3, 1:natom, i) = eforce(1:3, 1:natom)
3972 eforce(1:3, 1:natom) = eforce(1:3, 1:natom) + ec_env%rf(1:3, 1:natom)
3973 IF (do_resp .AND. nref < mref)
THEN
3978 smpforce(1:3, 1:natom, i) = eforce(1:3, 1:natom)
3981 IF (unit_nr > 0)
THEN
3982 WRITE (unit_nr, *)
" FORCES"
3984 WRITE (unit_nr,
"(i7,3F11.6,6X,3F11.6)") ia, eforce(1:3, ia), &
3985 (eforce(1:3, ia) - ec_env%rf(1:3, ia))
3989 WRITE (feunit,
"(5X,I8)") i
3991 WRITE (feunit,
"(5X,3F20.12)") eforce(1:3, ia)
3995 CALL cp_fm_release(ec_env%cpmos)
3999 IF (unit_nr > 0)
THEN
4000 CALL close_file(feunit)
4003 DEALLOCATE (smat, tvec, yvec, rlist)
4005 CALL cp_fm_release(hmats)
4006 CALL cp_fm_release(rpmos)
4007 IF (ec_env%error_method ==
"E")
THEN
4008 CALL cp_fm_release(spmos)
4011 DEALLOCATE (eforce, smpforce)
4014 CALL get_qs_env(qs_env, force=res_force, virial=ks_virial)
4015 CALL set_qs_env(qs_env, force=ks_force)
4016 CALL deallocate_qs_force(res_force)
4017 ks_virial = res_virial
4020 cpabort(
"unknown energy correction")
4023 END SUBROUTINE response_force_error
4037 SUBROUTINE cp_extrapolate(rpmos, Spmos, ip, nref, rlist, smat, tvec, yvec, vres)
4038 TYPE(cp_fm_type),
DIMENSION(:, :),
POINTER :: rpmos, spmos
4039 INTEGER,
INTENT(IN) :: ip, nref
4040 INTEGER,
DIMENSION(:),
INTENT(IN) :: rlist
4041 REAL(kind=dp),
DIMENSION(:, :),
INTENT(INOUT) :: smat
4042 REAL(kind=dp),
DIMENSION(:),
INTENT(INOUT) :: tvec, yvec
4043 REAL(kind=dp),
INTENT(OUT) :: vres
4045 INTEGER :: i, ia, j, ja
4046 REAL(kind=dp) :: aval
4047 REAL(kind=dp),
ALLOCATABLE,
DIMENSION(:, :) :: sinv
4055 ALLOCATE (sinv(nref, nref))
4059 tvec(i) = ctrace(rpmos(ip, :), spmos(ia, :))
4062 smat(j, i) = ctrace(rpmos(ja, :), spmos(ia, :))
4063 smat(i, j) = smat(j, i)
4065 smat(i, i) = ctrace(rpmos(ia, :), spmos(ia, :))
4067 aval = ctrace(rpmos(ip, :), spmos(ip, :))
4069 sinv(1:nref, 1:nref) = smat(1:nref, 1:nref)
4070 CALL invmat_symm(sinv(1:nref, 1:nref))
4072 yvec(1:nref) = matmul(sinv(1:nref, 1:nref), tvec(1:nref))
4074 vres = aval - sum(yvec(1:nref)*tvec(1:nref))
4075 vres = sqrt(abs(vres))
4082 END SUBROUTINE cp_extrapolate
4090 FUNCTION ctrace(ca, cb)
4091 TYPE(cp_fm_type),
DIMENSION(:) :: ca, cb
4092 REAL(kind=dp) :: ctrace
4095 REAL(kind=dp) :: trace
4101 CALL cp_fm_trace(ca(is), cb(is), trace)
4102 ctrace = ctrace + trace
4112 SUBROUTINE get_t2cindex(qs_env, t2cind)
4113 TYPE(qs_environment_type),
POINTER :: qs_env
4114 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: t2cind
4116 INTEGER :: i, iatom, ikind, is, iset, ishell, k, l, &
4117 m, natom, nset, nsgf, numshell
4118 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: lshell
4119 INTEGER,
DIMENSION(:),
POINTER :: nshell
4120 INTEGER,
DIMENSION(:, :),
POINTER :: lval
4121 TYPE(gto_basis_set_type),
POINTER :: basis_set
4122 TYPE(particle_type),
DIMENSION(:),
POINTER :: particle_set
4123 TYPE(qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
4127 CALL get_qs_env(qs_env, qs_kind_set=qs_kind_set, particle_set=particle_set, natom=natom)
4128 CALL get_qs_kind_set(qs_kind_set, nshell=numshell, nsgf=nsgf)
4130 ALLOCATE (t2cind(nsgf))
4131 ALLOCATE (lshell(numshell))
4135 CALL get_atomic_kind(particle_set(iatom)%atomic_kind, kind_number=ikind)
4136 CALL get_qs_kind(qs_kind_set(ikind), basis_set=basis_set, basis_type=
"ORB")
4137 CALL get_gto_basis_set(basis_set, nset=nset, nshell=nshell, l=lval)
4139 DO is = 1, nshell(iset)
4148 DO ishell = 1, numshell
4151 m = (-1)**k*floor(real(k, kind=dp)/2.0_dp)
4152 t2cind(i + l + 1 + m) = i + k
4159 END SUBROUTINE get_t2cindex
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_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(qs_env)
...
Types and set/get functions for auxiliary density matrix methods.
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.
subroutine, public get_atomic_kind(atomic_kind, fist_potential, element_symbol, name, mass, kind_number, natom, atom_list, rcov, rvdw, z, qeff, apol, cpol, mm_radius, shell, shell_active, damping)
Get attributes of an atomic kind.
subroutine, public get_gto_basis_set(gto_basis_set, name, aliases, norm_type, kind_radius, ncgf, nset, nsgf, cgf_symbol, sgf_symbol, norm_cgf, set_radius, lmax, lmin, lx, ly, lz, m, ncgf_set, npgf, nsgf_set, nshell, cphi, pgf_radius, sphi, scon, zet, first_cgf, first_sgf, l, last_cgf, last_sgf, n, gcc, maxco, maxl, maxpgf, maxsgf_set, maxshell, maxso, nco_sum, npgf_sum, nshell_sum, maxder, short_kind_radius, npgf_seg_sum, ccon)
...
collects all references to literature in CP2K as new algorithms / method are included from literature...
integer, save, public belleflamme2023
Handles all functions related to the CELL.
methods related to the blacs parallel environment
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)
...
subroutine, public dbcsr_dot(matrix_a, matrix_b, trace)
Computes the dot product of two matrices, also known as the trace of their matrix product.
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 cp_dbcsr_sm_fm_multiply(matrix, fm_in, fm_out, ncol, alpha, beta)
multiply a dbcsr with a fm matrix
subroutine, public copy_dbcsr_to_fm(matrix, fm, plan)
Copy a DBCSR matrix to a BLACS matrix.
Utility routines to open and close files.
subroutine, public open_file(file_name, file_status, file_form, file_action, file_position, file_pad, unit_number, debug, skip_get_unit_number, file_access)
Opens the requested file using a free unit number.
subroutine, public close_file(unit_number, file_status, keep_preconnection)
Close an open file given by its logical unit number. Optionally, keep the file and unit preconnected.
Basic linear algebra operations for full matrices.
subroutine, public cp_fm_scale_and_add(alpha, matrix_a, beta, matrix_b)
calc A <- alpha*A + beta*B optimized for alpha == 1.0 (just add beta*B) and beta == 0....
represent the structure of a full matrix
subroutine, public cp_fm_struct_create(fmstruct, para_env, context, nrow_global, ncol_global, nrow_block, ncol_block, descriptor, first_p_pos, local_leading_dimension, template_fmstruct, square_blocks, force_block)
allocates and initializes a full matrix structure
subroutine, public cp_fm_struct_release(fmstruct)
releases a full matrix structure
represent a full matrix distributed on many processors
subroutine, public cp_fm_get_info(matrix, name, nrow_global, ncol_global, nrow_block, ncol_block, nrow_local, ncol_local, row_indices, col_indices, local_data, context, nrow_locals, ncol_locals, matrix_struct, para_env)
returns all kind of information about the full matrix
subroutine, public cp_fm_write_unformatted(fm, unit)
...
subroutine, public cp_fm_set_submatrix(fm, new_values, start_row, start_col, n_rows, n_cols, alpha, beta, transpose)
sets a submatrix of a full matrix fm(start_row:start_row+n_rows,start_col:start_col+n_cols) = alpha*o...
subroutine, public cp_fm_create(matrix, matrix_struct, name, nrow, ncol, set_zero)
creates a new full matrix with the given structure
various routines to log and control the output. The idea is that decisions about where to log should ...
recursive integer function, public cp_logger_get_default_unit_nr(logger, local, skip_not_ionode)
asks the default unit number of the given logger. try to use cp_logger_get_unit_nr
type(cp_logger_type) function, pointer, public cp_get_default_logger()
returns the default logger
routines to handle the output, The idea is to remove the decision of wheter to output and what to out...
integer function, public cp_print_key_unit_nr(logger, basis_section, print_key_path, extension, middle_name, local, log_filename, ignore_should_output, file_form, file_position, file_action, file_status, do_backup, on_file, is_new_file, mpi_io, fout)
...
subroutine, public cp_print_key_finished_output(unit_nr, logger, basis_section, print_key_path, local, ignore_should_output, on_file, mpi_io)
should be called after you finish working with a unit obtained with cp_print_key_unit_nr,...
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...
set of type/routines to handle the storage of results in force_envs
subroutine, public cp_results_erase(results, description, nval)
erase a part of result_list
set of type/routines to handle the storage of results in force_envs
real(kind=dp) function, public cp_unit_from_cp2k(value, unit_str, defaults, power)
converts from the internal cp2k units to the given unit
stores a lists of integer that are local to a processor. The idea is that these integers represent ob...
stores a mapping of 2D info (e.g. matrix) on a 2D processor distribution (i.e. blacs grid) where cpus...
Routines for an energy correction on top of a Kohn-Sham calculation.
subroutine, public ec_diag_solver_gamma(qs_env, ec_env, matrix_ks, matrix_s, matrix_p, matrix_w)
Solve KS equation using diagonalization.
subroutine, public ec_ot_diag_solver(qs_env, ec_env, matrix_ks, matrix_s, matrix_p, matrix_w)
Use OT-diagonalziation to obtain density matrix from Harris Kohn-Sham matrix Initial guess of density...
subroutine, public ec_ls_solver(qs_env, matrix_p, matrix_w, ec_ls_method)
Solve the Harris functional by linear scaling density purification scheme, instead of the diagonaliza...
subroutine, public ec_diag_solver_kp(qs_env, ec_env, matrix_ks, matrix_s, matrix_p, matrix_w)
Solve Kpoint-KS equation using diagonalization.
subroutine, public ec_ls_init(qs_env, matrix_ks, matrix_s)
Solve the Harris functional by linear scaling density purification scheme, instead of the diagonaliza...
Calculates the energy contribution and the mo_derivative of a static electric field (nonperiodic).
subroutine, public ec_efield_local_operator(qs_env, ec_env, calculate_forces)
...
subroutine, public ec_efield_integrals(qs_env, ec_env, rpoint)
...
Types needed for a for a Energy Correction.
subroutine, public ec_env_potential_release(ec_env)
...
Routines for an external energy correction on top of a Kohn-Sham calculation.
subroutine, public ec_ext_energy(qs_env, ec_env, calculate_forces)
External energy method.
subroutine, public matrix_r_forces(qs_env, cpmos, mo_occ, matrix_r, unit_nr, debug_forces, debug_stress)
...
Routines for an energy correction on top of a Kohn-Sham calculation.
subroutine, public energy_correction(qs_env, ec_init, calculate_forces)
Energy Correction to a Kohn-Sham simulation Available energy corrections: (1) Harris energy functiona...
Definition of the atomic potential types.
subroutine, public init_coulomb_local(hartree_local, natom)
...
subroutine, public vh_1c_gg_integrals(qs_env, energy_hartree_1c, ecoul_1c, local_rho_set, para_env, tddft, local_rho_set_2nd, core_2nd)
Calculates one center GAPW Hartree energies and matrix elements Hartree potentials are input Takes po...
subroutine, public hartree_local_release(hartree_local)
...
subroutine, public hartree_local_create(hartree_local)
...
Routines to calculate EXX in RPA and energy correction methods.
subroutine, public calculate_exx(qs_env, unit_nr, hfx_sections, x_data, do_gw, do_admm, calc_forces, reuse_hfx, do_im_time, e_ex_from_gw, e_admm_from_gw, t3)
...
subroutine, public add_exx_to_rhs(rhs, qs_env, ext_hfx_section, x_data, recalc_integrals, do_admm, do_ec, do_exx, reuse_hfx)
Add the EXX contribution to the RHS of the Z-vector equation, namely the HF Hamiltonian.
Defines the basic variable types.
integer, parameter, public dp
integer, parameter, public default_string_length
integer, parameter, public default_path_length
Restart file for k point calculations.
subroutine, public write_kpoints_file_header(qs_kind_set, particle_set, ires, basis_type)
...
integer function, dimension(3), public get_cell(ic, cell_to_index)
...
Routines needed for kpoint calculation.
subroutine, public kpoint_init_cell_index(kpoint, sab_nl, para_env, nimages)
Generates the mapping of cell indices and linear RS index CELL (0,0,0) is always mapped to index 1.
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, lattice_fft)
Retrieve information from a kpoint environment.
Calculate MAO's and analyze wavefunctions.
subroutine, public mao_generate_basis(qs_env, mao_coef, ref_basis_set, pmat_external, smat_external, molecular, max_iter, eps_grad, nmao_external, eps1_mao, iolevel, unit_nr)
...
Collection of simple mathematical functions and subroutines.
subroutine, public invmat_symm(a, potrf, uplo)
returns inverse of real symmetric, positive definite matrix
Interface to the message passing library MPI.
Define the data structure for the molecule information.
Calculates the moment integrals <a|r^m|b>.
subroutine, public get_reference_point(rpoint, drpoint, qs_env, fist_env, reference, ref_point, ifirst, ilast)
...
basic linear algebra operations for full matrixes
Define the data structure for the particle information.
subroutine, public get_paw_proj_set(paw_proj_set, csprj, chprj, first_prj, first_prjs, last_prj, local_oce_sphi_h, local_oce_sphi_s, maxl, ncgauprj, nsgauprj, nsatbas, nsotot, nprj, o2nindex, n2oindex, rcprj, rzetprj, zisomin, zetprj)
Get informations about a paw projectors set.
Periodic Table related data definitions.
type(atom), dimension(0:nelem), public ptable
Definition of physical constants:
real(kind=dp), parameter, public pascal
real(kind=dp), parameter, public bohr
real(kind=dp), parameter, public debye
container for various plainwaves related things
subroutine, public pw_env_get(pw_env, pw_pools, cube_info, gridlevel_info, auxbas_pw_pool, auxbas_grid, auxbas_rs_desc, auxbas_rs_grid, rs_descs, rs_grids, xc_pw_pool, vdw_pw_pool, poisson_env, interp_section)
returns the various attributes of the pw env
functions related to the poisson solver on regular grids
Manages a pool of grids (to be used for example as tmp objects), but can also be used to instantiate ...
Calculate the plane wave density by collocating the primitive Gaussian functions (pgf).
subroutine, public calculate_rho_elec(matrix_p, matrix_p_kp, rho, rho_gspace, total_rho, ks_env, soft_valid, compute_tau, compute_grad, basis_type, der_type, idir, task_list_external, pw_env_external)
computes the density corresponding to a given density matrix on the grid
Calculation of the energies concerning the core charge distribution.
subroutine, public calculate_ecore_overlap(qs_env, para_env, calculate_forces, molecular, e_overlap_core, atecc)
Calculate the overlap energy of the core charge distribution.
Calculation of the core Hamiltonian integral matrix <a|H|b> over Cartesian Gaussian-type functions.
subroutine, public core_matrices(qs_env, matrix_h, matrix_p, calculate_forces, nder, ec_env, dcdr_env, ec_env_matrices, ext_kpoints, basis_type, debug_forces, debug_stress, atcore)
...
subroutine, public kinetic_energy_matrix(qs_env, matrixkp_t, matrix_t, matrix_p, ext_kpoints, matrix_name, calculate_forces, nderivative, sab_orb, eps_filter, basis_type, debug_forces, debug_stress)
Calculate kinetic energy matrix and possible relativistic correction.
Calculation of dispersion using pair potentials.
subroutine, public calculate_dispersion_pairpot(qs_env, dispersion_env, energy, calculate_forces, atevdw)
...
Definition of disperson types for DFT calculations.
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, matrix_vhxc, rho, rho_xc, pw_env, ewald_env, ewald_pw, active_space, mpools, input, para_env, blacs_env, scf_control, rel_control, kinetic, qs_charges, vppl, xcint_weights, rho_core, rho_nlcc, rho_nlcc_g, ks_env, ks_qmmm_env, wf_history, scf_env, local_particles, local_molecules, distribution_2d, dbcsr_dist, molecule_kind_set, molecule_set, subsys, cp_subsys, oce, local_rho_set, rho_atom_set, task_list, task_list_soft, rho0_atom_set, rho0_mpole, rhoz_set, rhoz_cneo_set, ecoul_1c, rho0_s_rs, rho0_s_gs, rhoz_cneo_s_rs, rhoz_cneo_s_gs, do_kpoints, has_unit_metric, requires_mo_derivs, mo_derivs, mo_loc_history, nkind, natom, nelectron_total, nelectron_spin, efield, neighbor_list_id, linres_control, xas_env, virial, cp_ddapc_env, cp_ddapc_ewald, outer_scf_history, outer_scf_ihistory, x_data, et_coupling, dftb_potential, results, se_taper, se_store_int_env, se_nddo_mpole, se_nonbond_env, admm_env, lri_env, lri_density, exstate_env, ec_env, harris_env, dispersion_env, gcp_env, vee, rho_external, external_vxc, mask, mp2_env, bs_env, kg_env, wanniercentres, atprop, ls_scf_env, do_transport, transport_env, v_hartree_rspace, s_mstruct_changed, rho_changed, potential_changed, forces_up_to_date, mscfg_env, almo_scf_env, gradient_history, variable_history, embed_pot, spin_embed_pot, polar_env, mos_last_converged, eeq, rhs, do_rixs, tb_tblite)
Get the QUICKSTEP environment.
subroutine, public set_qs_env(qs_env, super_cell, mos, qmmm, qmmm_periodic, mimic, ewald_env, ewald_pw, mpools, rho_external, external_vxc, mask, scf_control, rel_control, qs_charges, ks_env, ks_qmmm_env, wf_history, scf_env, active_space, input, oce, rho_atom_set, rho0_atom_set, rho0_mpole, run_rtp, rtp, rhoz_set, rhoz_tot, ecoul_1c, has_unit_metric, requires_mo_derivs, mo_derivs, mo_loc_history, efield, rhoz_cneo_set, linres_control, xas_env, cp_ddapc_env, cp_ddapc_ewald, outer_scf_history, outer_scf_ihistory, x_data, et_coupling, dftb_potential, se_taper, se_store_int_env, se_nddo_mpole, se_nonbond_env, admm_env, ls_scf_env, do_transport, transport_env, lri_env, lri_density, exstate_env, ec_env, dispersion_env, harris_env, gcp_env, mp2_env, bs_env, kg_env, force, kpoints, wanniercentres, almo_scf_env, gradient_history, variable_history, embed_pot, spin_embed_pot, polar_env, mos_last_converged, eeq, rhs, do_rixs, tb_tblite)
Set the QUICKSTEP environment.
subroutine, public deallocate_qs_force(qs_force)
Deallocate a Quickstep force data structure.
subroutine, public zero_qs_force(qs_force)
Initialize a Quickstep force data structure.
subroutine, public allocate_qs_force(qs_force, natom_of_kind)
Allocate a Quickstep force data structure.
subroutine, public total_qs_force(force, qs_force, atomic_kind_set)
Get current total force.
Setup Routine for Fxc Potentials.
subroutine, public qs_fxc_create(qs_env, rho0_struct, rho1_struct, rho0_atom_set, xc_section, do_onecenter, fxc_rho, fxc_tau, rho1_atom_set, do_scale, is_triplet, spinflip, no_weights, uf_grid_results, pw_env_ext, kind_set_external, para_env_external, dispersion_env, compute_virial, virial_xc)
...
subroutine, public prepare_gapw_den(qs_env, local_rho_set, do_rho0, kind_set_external, pw_env_sub)
...
Integrate single or product functions over a potential on a RS grid.
Define the quickstep kind type and their sub types.
subroutine, public get_qs_kind(qs_kind, basis_set, basis_type, ncgf, nsgf, all_potential, tnadd_potential, gth_potential, sgp_potential, upf_potential, cneo_potential, se_parameter, dftb_parameter, xtb_parameter, dftb3_param, zatom, zeff, elec_conf, mao, lmax_dftb, alpha_core_charge, ccore_charge, core_charge, core_charge_radius, paw_proj_set, paw_atom, hard_radius, hard0_radius, max_rad_local, covalent_radius, vdw_radius, gpw_type_forced, harmonics, max_iso_not0, max_s_harm, grid_atom, ngrid_ang, ngrid_rad, lmax_rho0, dft_plus_u_atom, l_of_dft_plus_u, n_of_dft_plus_u, u_minus_j, hund_j, u_of_dft_plus_u, j_of_dft_plus_u, alpha_of_dft_plus_u, beta_of_dft_plus_u, j0_of_dft_plus_u, occupation_of_dft_plus_u, dispersion, bs_occupation, magnetization, no_optimize, addel, laddel, naddel, orbitals, max_scf, eps_scf, smear, u_ramping, u_minus_j_target, eps_u_ramping, proj_shell_charge, lr_atom, do_mtlr, u_j_loop, ao_coef, init_u_ramping_each_scf, reltmat, ghost, monovalent, floating, name, element_symbol, pao_basis_size, pao_model_file, pao_potentials, pao_descriptors, nelec)
Get attributes of an atomic kind.
subroutine, public get_qs_kind_set(qs_kind_set, all_potential_present, tnadd_potential_present, gth_potential_present, sgp_potential_present, paw_atom_present, dft_plus_u_atom_present, maxcgf, maxsgf, maxco, maxco_proj, maxgtops, maxlgto, maxlprj, maxnset, maxsgf_set, ncgf, npgf, nset, nsgf, nshell, maxpol, maxlppl, maxlppnl, maxppnl, nelectron, maxder, max_ngrid_rad, max_sph_harm, maxg_iso_not0, lmax_rho0, basis_rcut, do_mtlr_present, basis_type, total_zeff_corr, npgf_seg, cneo_potential_present, nkind_q, natom_q)
Get attributes of an atomic kind set.
Calculation of kinetic energy matrix and forces.
subroutine, public build_kinetic_matrix(ks_env, matrix_t, matrixkp_t, matrix_name, basis_type, sab_nl, calculate_forces, matrix_p, matrixkp_p, ext_kpoints, eps_filter, nderivative)
Calculation of the kinetic energy matrix over Cartesian Gaussian functions.
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 calc_rho_tot_gspace(rho_tot_gspace, qs_env, rho, skip_nuclear_density)
...
Calculate the KS reference potentials.
subroutine, public ks_ref_potential_atom(qs_env, local_rho_set, local_rho_set_admm, v_hartree_rspace)
calculate the Kohn-Sham GAPW reference potentials
subroutine, public ks_ref_potential(qs_env, vh_rspace, vxc_rspace, vtau_rspace, vadmm_rspace, ehartree, exc, h_stress, vadmm_tau_rspace)
calculate the Kohn-Sham reference potential
subroutine, public local_rho_set_create(local_rho_set)
...
subroutine, public local_rho_set_release(local_rho_set)
...
Calculates the moment integrals <a|r^m|b> and <a|r x d/dr|b>.
subroutine, public build_local_moment_matrix(qs_env, moments, nmoments, ref_point, ref_points, basis_type, all_images, minimum_image, neighbor_image, first_component)
...
Define the neighbor list data types and the corresponding functionality.
Generate the atomic neighbor lists.
subroutine, public atom2d_cleanup(atom2d)
free the internals of atom2d
subroutine, public pair_radius_setup(present_a, present_b, radius_a, radius_b, pair_radius, prmin)
...
subroutine, public build_neighbor_lists(ab_list, particle_set, atom, cell, pair_radius, subcells, mic, symmetric, molecular, subset_of_mol, current_subset, operator_type, nlname, atomb_to_keep, stable_images)
Build simple pair neighbor lists.
subroutine, public atom2d_build(atom2d, distribution_1d, distribution_2d, atomic_kind_set, molecule_set, molecule_only, particle_set)
Build some distribution structure of atoms, refactored from build_qs_neighbor_lists.
Routines for the construction of the coefficients for the expansion of the atomic densities rho1_hard...
subroutine, public build_oce_matrices(intac, calculate_forces, nder, qs_kind_set, particle_set, sap_oce, eps_fit)
Set up the sparse matrix for the coefficients of one center expansions This routine uses the same log...
subroutine, public allocate_oce_set(oce_set, nkind)
Allocate and initialize the matrix set of oce coefficients.
subroutine, public create_oce_set(oce_set)
...
Calculation of overlap matrix, its derivatives and forces.
subroutine, public build_overlap_matrix(ks_env, matrix_s, matrixkp_s, matrix_name, nderivative, basis_type_a, basis_type_b, sab_nl, calculate_forces, matrix_p, matrixkp_p, ext_kpoints)
Calculation of the overlap matrix over Cartesian Gaussian functions.
subroutine, public rho0_s_grid_create(pw_env, rho0_mpole)
...
subroutine, public integrate_vhg0_rspace(qs_env, v_rspace, para_env, calculate_forces, local_rho_set, local_rho_set_2nd, atener, kforce, my_pools, my_rs_descs)
...
subroutine, public init_rho0(local_rho_set, qs_env, gapw_control, zcore)
...
subroutine, public allocate_rho_atom_internals(rho_atom_set, atomic_kind_set, qs_kind_set, dft_control, para_env)
...
subroutine, public calculate_rho_atom_coeff(qs_env, rho_ao, rho_atom_set, qs_kind_set, oce, sab, para_env)
...
superstucture that hold various representations of the density and keeps track of which ones are vali...
subroutine, public qs_rho_set(rho_struct, rho_ao, rho_ao_im, rho_ao_kp, rho_ao_im_kp, rho_r, drho_r, rho_g, drho_g, tau_r, tau_g, rho_r_valid, drho_r_valid, rho_g_valid, drho_g_valid, tau_r_valid, tau_g_valid, tot_rho_r, tot_rho_g, rho_r_sccs, soft_valid, complex_rho_ao)
...
subroutine, public qs_rho_get(rho_struct, rho_ao, rho_ao_im, rho_ao_kp, rho_ao_im_kp, rho_r, drho_r, rho_g, drho_g, tau_r, tau_g, rho_r_valid, drho_r_valid, rho_g_valid, drho_g_valid, tau_r_valid, tau_g_valid, tot_rho_r, tot_rho_g, rho_r_sccs, soft_valid, complex_rho_ao)
returns info about the density described by this object. If some representation is not available an e...
subroutine, public qs_rho_create(rho)
Allocates a new instance of rho.
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, composite_vxc_rho, composite_vxc_tau, composite_reference_active, direct_valence_atom_grid, atom_composite_grid)
...
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, qs_env_external, native_gapw_composite_override, native_skala_defer_to_atom_composite)
calculates and allocates the xc potential, already reducing it to the dependence on rho and the one o...
Calculate the CPKS equation and the resulting forces.
subroutine, public response_force(qs_env, vh_rspace, vxc_rspace, vtau_rspace, vadmm_rspace, vadmm_tau_rspace, matrix_hz, matrix_pz, matrix_pz_admm, matrix_wz, zehartree, zexc, zexc_aux_fit, rhopz_r, p_env, ex_env, debug)
...
subroutine, public response_calculation(qs_env, ec_env, silent)
Initializes solver of linear response equation for energy correction.
Utilities for string manipulations.
elemental subroutine, public uppercase(string)
Convert all lower case characters in a string to upper case.
generate the tasks lists used by collocate and integrate routines
subroutine, public generate_qs_task_list(ks_env, task_list, basis_type, reorder_rs_grid_ranks, skip_load_balance_distributed, pw_env_external, sab_orb_external, ext_kpoints)
...
subroutine, public deallocate_task_list(task_list)
deallocates the components and the object itself
subroutine, public allocate_task_list(task_list)
allocates and initialised the components of the task_list_type
The module to read/write TREX IO files for interfacing CP2K with other programs.
subroutine, public write_trexio(qs_env, trexio_section, energy_derivative)
Write a trexio file.
subroutine, public write_stress_tensor(pv_virial, iw, cell, unit_string, numerical)
Print stress tensor to output file.
subroutine, public write_stress_tensor_components(virial, iw, cell, unit_string)
...
pure real(kind=dp) function, public one_third_sum_diag(a)
...
subroutine, public zero_virial(virial, reset)
...
subroutine, public symmetrize_virial(virial)
Symmetrize the virial components.
Interface for Voronoi Integration and output of BQB files.
subroutine, public entry_voronoi_or_bqb(do_voro, do_bqb, input_voro, input_bqb, unit_voro, qs_env, rspace_pw)
Does a Voronoi integration of density or stores the density to compressed BQB format.
stores some data used in wavefunction fitting
Provides all information about an atomic kind.
Type defining parameters related to the simulation cell.
represent a blacs multidimensional parallel environment (for the mpi corrispective see cp_paratypes/m...
keeps the information about the structure of a full matrix
type of a logger, at the moment it contains just a print level starting at which level it should be l...
contains arbitrary information which need to be stored
structure to store local (to a processor) ordered lists of integers.
distributes pairs on a 2d grid of processors
Contains information on the energy correction functional for KG.
stores all the informations relevant to an mpi environment
contained for different pw related things
environment for the poisson solver
to create arrays of pools
Manages a pool of grids (to be used for example as tmp objects), but can also be used to instantiate ...
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.