212#include "./base/base_uses.f90"
220 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'energy_corrections'
241 LOGICAL,
INTENT(IN),
OPTIONAL :: ec_init, calculate_forces
243 CHARACTER(len=*),
PARAMETER :: routinen =
'energy_correction'
245 INTEGER :: handle, unit_nr
246 LOGICAL :: my_calc_forces
253 CALL timeset(routinen, handle)
256 IF (logger%para_env%is_source())
THEN
268 IF (.NOT. ec_env%do_skip)
THEN
270 ec_env%should_update = .true.
271 IF (
PRESENT(ec_init)) ec_env%should_update = ec_init
273 my_calc_forces = .false.
274 IF (
PRESENT(calculate_forces)) my_calc_forces = calculate_forces
276 IF (ec_env%should_update)
THEN
277 ec_env%old_etotal = 0.0_dp
278 ec_env%etotal = 0.0_dp
279 ec_env%eband = 0.0_dp
280 ec_env%ehartree = 0.0_dp
284 ec_env%edispersion = 0.0_dp
285 ec_env%exc_aux_fit = 0.0_dp
288 ec_env%ehartree_1c = 0.0_dp
289 ec_env%exc1_aux_fit = 0.0_dp
293 ec_env%old_etotal = energy%total
297 IF (my_calc_forces)
THEN
298 IF (unit_nr > 0)
THEN
299 WRITE (unit_nr,
'(T2,A,A,A,A,A)')
"!", repeat(
"-", 25), &
300 " Energy Correction Forces ", repeat(
"-", 26),
"!"
302 CALL get_qs_env(qs_env, force=ks_force, virial=virial)
306 IF (unit_nr > 0)
THEN
307 WRITE (unit_nr,
'(T2,A,A,A,A,A)')
"!", repeat(
"-", 29), &
308 " Energy Correction ", repeat(
"-", 29),
"!"
313 CALL energy_correction_low(qs_env, ec_env, my_calc_forces, unit_nr)
316 IF (ec_env%should_update)
THEN
317 energy%nonscf_correction = ec_env%etotal - ec_env%old_etotal
318 energy%total = ec_env%etotal
321 IF (.NOT. my_calc_forces .AND. unit_nr > 0)
THEN
322 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Energy Correction ", energy%nonscf_correction
324 IF (unit_nr > 0)
THEN
325 WRITE (unit_nr,
'(T2,A,A,A)')
"!", repeat(
"-", 77),
"!"
332 IF (unit_nr > 0)
THEN
333 WRITE (unit_nr,
'(T2,A,A,A)')
"!", repeat(
"-", 77),
"!"
334 WRITE (unit_nr,
'(T2,A,A,A,A,A)')
"!", repeat(
"-", 26), &
335 " Skip Energy Correction ", repeat(
"-", 27),
"!"
336 WRITE (unit_nr,
'(T2,A,A,A)')
"!", repeat(
"-", 77),
"!"
341 CALL timestop(handle)
356 SUBROUTINE energy_correction_low(qs_env, ec_env, calculate_forces, unit_nr)
359 LOGICAL,
INTENT(IN) :: calculate_forces
360 INTEGER,
INTENT(IN) :: unit_nr
362 INTEGER :: ispin, nkind, nspins
363 LOGICAL :: debug_f, gapw, gapw_xc
364 REAL(kind=
dp) :: eps_fit, exc
372 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
374 IF (ec_env%should_update)
THEN
375 CALL ec_build_neighborlist(qs_env, ec_env)
381 ec_env%vtau_rspace, &
382 ec_env%vadmm_rspace, &
383 ec_env%ehartree, exc, &
384 vadmm_tau_rspace=ec_env%vadmm_tau_rspace)
386 ec_env%local_rho_set_admm, ec_env%vh_rspace)
388 SELECT CASE (ec_env%energy_functional)
391 CALL ec_build_core_hamiltonian(qs_env, ec_env)
392 CALL ec_build_ks_matrix(qs_env, ec_env)
395 cpassert(.NOT. ec_env%do_kpoints)
398 NULLIFY (ec_env%mao_coef)
400 max_iter=ec_env%mao_max_iter, eps_grad=ec_env%mao_eps_grad, &
401 eps1_mao=ec_env%mao_eps1, iolevel=ec_env%mao_iolevel, unit_nr=unit_nr)
404 CALL ec_ks_solver(qs_env, ec_env)
406 CALL evaluate_ec_core_matrix_traces(qs_env, ec_env)
408 IF (ec_env%write_harris_wfn)
THEN
409 CALL harris_wfn_output(qs_env, ec_env, unit_nr)
413 cpassert(.NOT. ec_env%do_kpoints)
416 CALL ec_dc_energy(qs_env, ec_env, calculate_forces=.false.)
421 CALL ec_build_ks_matrix(qs_env, ec_env)
424 cpassert(.NOT. ec_env%do_kpoints)
429 cpabort(
"unknown energy correction")
433 CALL ec_disp(qs_env, ec_env, calculate_forces=.false.)
436 CALL ec_energy(ec_env, unit_nr)
440 IF (calculate_forces)
THEN
442 debug_f = ec_env%debug_forces .OR. ec_env%debug_stress
444 CALL get_qs_env(qs_env=qs_env, dft_control=dft_control)
445 nspins = dft_control%nspins
446 gapw = dft_control%qs_control%gapw
447 gapw_xc = dft_control%qs_control%gapw_xc
448 IF (gapw .OR. gapw_xc)
THEN
450 qs_kind_set=qs_kind_set, particle_set=particle_set)
451 NULLIFY (oce, sap_oce)
452 CALL get_qs_env(qs_env=qs_env, oce=oce, sap_oce=sap_oce)
455 eps_fit = dft_control%qs_control%gapw_control%eps_fit
461 CALL ec_disp(qs_env, ec_env, calculate_forces=.true.)
463 SELECT CASE (ec_env%energy_functional)
466 CALL ec_build_core_hamiltonian_force(qs_env, ec_env, &
470 CALL ec_build_ks_matrix_force(qs_env, ec_env)
471 IF (ec_env%debug_external)
THEN
472 CALL write_response_interface(qs_env, ec_env)
473 CALL init_response_deriv(qs_env, ec_env)
478 cpassert(.NOT. ec_env%do_kpoints)
481 CALL ec_dc_energy(qs_env, ec_env, calculate_forces=.true.)
483 CALL ec_build_core_hamiltonian_force(qs_env, ec_env, &
487 CALL ec_dc_build_ks_matrix_force(qs_env, ec_env)
488 IF (ec_env%debug_external)
THEN
489 CALL write_response_interface(qs_env, ec_env)
490 CALL init_response_deriv(qs_env, ec_env)
495 cpassert(.NOT. ec_env%do_kpoints)
497 CALL init_response_deriv(qs_env, ec_env)
500 ec_env%matrix_w(1, 1)%matrix, unit_nr, &
501 ec_env%debug_forces, ec_env%debug_stress)
504 cpabort(
"unknown energy correction")
507 IF (ec_env%do_error)
THEN
508 ALLOCATE (ec_env%cpref(nspins))
510 CALL cp_fm_create(ec_env%cpref(ispin), ec_env%cpmos(ispin)%matrix_struct)
511 CALL cp_fm_to_fm(ec_env%cpmos(ispin), ec_env%cpref(ispin))
521 cpassert(
ASSOCIATED(pw_env))
522 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
523 ALLOCATE (ec_env%rhoz_r(nspins))
525 CALL auxbas_pw_pool%create_pw(ec_env%rhoz_r(ispin))
529 vh_rspace=ec_env%vh_rspace, &
530 vxc_rspace=ec_env%vxc_rspace, &
531 vtau_rspace=ec_env%vtau_rspace, &
532 vadmm_rspace=ec_env%vadmm_rspace, &
533 vadmm_tau_rspace=ec_env%vadmm_tau_rspace, &
534 matrix_hz=ec_env%matrix_hz, &
535 matrix_pz=ec_env%matrix_z, &
536 matrix_pz_admm=ec_env%z_admm, &
537 matrix_wz=ec_env%matrix_wz, &
538 rhopz_r=ec_env%rhoz_r, &
539 zehartree=ec_env%ehartree, &
541 zexc_aux_fit=ec_env%exc_aux_fit, &
542 p_env=ec_env%p_env, &
545 CALL output_response_deriv(qs_env, ec_env, unit_nr)
547 CALL ec_properties(qs_env, ec_env)
549 IF (ec_env%do_error)
THEN
550 CALL response_force_error(qs_env, ec_env, unit_nr)
554 IF (
ASSOCIATED(ec_env%rhoout_r))
THEN
556 CALL auxbas_pw_pool%give_back_pw(ec_env%rhoout_r(ispin))
558 DEALLOCATE (ec_env%rhoout_r)
560 IF (
ASSOCIATED(ec_env%rhoz_r))
THEN
562 CALL auxbas_pw_pool%give_back_pw(ec_env%rhoz_r(ispin))
564 DEALLOCATE (ec_env%rhoz_r)
580 END SUBROUTINE energy_correction_low
588 SUBROUTINE write_response_interface(qs_env, ec_env)
595 NULLIFY (trexio_section)
599 CALL write_trexio(qs_env, trexio_section, ec_env%matrix_hz)
601 END SUBROUTINE write_response_interface
609 SUBROUTINE init_response_deriv(qs_env, ec_env)
619 ALLOCATE (ec_env%rf(3, natom))
622 CALL get_qs_env(qs_env, force=force, virial=virial)
624 CALL get_qs_env(qs_env, atomic_kind_set=atomic_kind_set)
627 IF (virial%pv_availability .AND. (.NOT. virial%pv_numer))
THEN
628 ec_env%rpv = virial%pv_virial
631 END SUBROUTINE init_response_deriv
640 SUBROUTINE output_response_deriv(qs_env, ec_env, unit_nr)
643 INTEGER,
INTENT(IN) :: unit_nr
645 CHARACTER(LEN=default_string_length) :: unit_string
646 INTEGER :: funit, ia, natom
647 REAL(kind=
dp) :: evol, fconv
648 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: ftot
656 IF (
ASSOCIATED(ec_env%rf))
THEN
658 ALLOCATE (ftot(3, natom))
660 CALL get_qs_env(qs_env, force=force, virial=virial, para_env=para_env)
662 CALL get_qs_env(qs_env, atomic_kind_set=atomic_kind_set)
664 ec_env%rf(1:3, 1:natom) = ftot(1:3, 1:natom) - ec_env%rf(1:3, 1:natom)
665 CALL para_env%sum(ec_env%rf)
668 IF (virial%pv_availability .AND. (.NOT. virial%pv_numer))
THEN
669 ec_env%rpv = virial%pv_virial - ec_env%rpv
670 CALL para_env%sum(ec_env%rpv)
672 evol = ec_env%exc + ec_env%exc_aux_fit + 2.0_dp*ec_env%ehartree
673 ec_env%rpv(1, 1) = ec_env%rpv(1, 1) - evol
674 ec_env%rpv(2, 2) = ec_env%rpv(2, 2) - evol
675 ec_env%rpv(3, 3) = ec_env%rpv(3, 3) - evol
678 CALL get_qs_env(qs_env, particle_set=particle_set, cell=cell)
682 IF (unit_nr > 0)
THEN
683 WRITE (unit_nr,
'(/,T2,A)')
"Write EXTERNAL Response Derivative: "//trim(ec_env%exresult_fn)
685 CALL open_file(ec_env%exresult_fn, file_status=
"REPLACE", file_form=
"FORMATTED", &
686 file_action=
"WRITE", unit_number=funit)
687 WRITE (funit,
"(T8,A,T58,A)")
"COORDINATES [Bohr]",
"RESPONSE FORCES [Hartree/Bohr]"
689 WRITE (funit,
"(2(3F15.8,5x))") particle_set(ia)%r(1:3), ec_env%rf(1:3, ia)
692 WRITE (funit,
"(T8,A,T58,A)")
"CELL [Bohr]",
"RESPONSE PRESSURE [GPa]"
694 WRITE (funit,
"(3F15.8,5x,3F15.8)") cell%hmat(ia, 1:3), -fconv*ec_env%rpv(ia, 1:3)
701 END SUBROUTINE output_response_deriv
710 SUBROUTINE evaluate_ec_core_matrix_traces(qs_env, ec_env)
714 CHARACTER(LEN=*),
PARAMETER :: routinen =
'evaluate_ec_core_matrix_traces'
720 CALL timeset(routinen, handle)
723 CALL get_qs_env(qs_env, dft_control=dft_control, energy=energy)
726 CALL calculate_ptrace(ec_env%matrix_h, ec_env%matrix_p, energy%core, dft_control%nspins)
729 CALL calculate_ptrace(ec_env%matrix_t, ec_env%matrix_p, energy%kinetic, dft_control%nspins)
731 CALL timestop(handle)
733 END SUBROUTINE evaluate_ec_core_matrix_traces
746 SUBROUTINE ec_dc_energy(qs_env, ec_env, calculate_forces)
749 LOGICAL,
INTENT(IN) :: calculate_forces
751 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ec_dc_energy'
753 CHARACTER(LEN=default_string_length) :: headline
754 INTEGER :: handle, ispin, nspins
755 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_h, matrix_p, matrix_s, matrix_w
761 CALL timeset(routinen, handle)
763 NULLIFY (dft_control, ks_env, matrix_h, matrix_p, matrix_s, matrix_w, rho)
765 dft_control=dft_control, &
767 matrix_h_kp=matrix_h, &
768 matrix_s_kp=matrix_s, &
769 matrix_w_kp=matrix_w, &
772 nspins = dft_control%nspins
777 matrix_name=
"OVERLAP MATRIX", &
778 basis_type_a=
"HARRIS", &
779 basis_type_b=
"HARRIS", &
780 sab_nl=ec_env%sab_orb)
785 headline =
"CORE HAMILTONIAN MATRIX"
786 ALLOCATE (ec_env%matrix_h(1, 1)%matrix)
787 CALL dbcsr_create(ec_env%matrix_h(1, 1)%matrix, name=trim(headline), &
788 template=matrix_s(1, 1)%matrix, matrix_type=dbcsr_type_symmetric)
790 CALL dbcsr_copy(ec_env%matrix_h(1, 1)%matrix, matrix_h(1, 1)%matrix)
795 headline =
"DENSITY MATRIX"
797 ALLOCATE (ec_env%matrix_p(ispin, 1)%matrix)
798 CALL dbcsr_create(ec_env%matrix_p(ispin, 1)%matrix, name=trim(headline), &
799 template=matrix_s(1, 1)%matrix, matrix_type=dbcsr_type_symmetric)
801 CALL dbcsr_copy(ec_env%matrix_p(ispin, 1)%matrix, matrix_p(ispin, 1)%matrix)
804 IF (calculate_forces)
THEN
809 headline =
"ENERGY-WEIGHTED DENSITY MATRIX"
811 ALLOCATE (ec_env%matrix_w(ispin, 1)%matrix)
812 CALL dbcsr_create(ec_env%matrix_w(ispin, 1)%matrix, name=trim(headline), &
813 template=matrix_s(1, 1)%matrix, matrix_type=dbcsr_type_symmetric)
815 CALL dbcsr_copy(ec_env%matrix_w(ispin, 1)%matrix, matrix_w(ispin, 1)%matrix)
822 ec_env%ekTS = energy%ktS
825 ec_env%efield_nuclear = 0.0_dp
826 ec_env%efield_elec = 0.0_dp
829 CALL timestop(handle)
831 END SUBROUTINE ec_dc_energy
842 SUBROUTINE ec_dc_build_ks_matrix_force(qs_env, ec_env)
846 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ec_dc_build_ks_matrix_force'
848 CHARACTER(LEN=default_string_length) :: basis_type, unit_string
849 INTEGER :: handle, i, iounit, ispin, natom, nspins
850 LOGICAL :: debug_forces, debug_stress, do_ec_hfx, &
851 gapw, gapw_xc, use_virial
852 REAL(
dp) :: dummy_real, dummy_real2(2), ehartree, &
853 ehartree_1c, eovrl, exc, exc1, fconv
854 REAL(
dp),
ALLOCATABLE,
DIMENSION(:, :) :: ftot
855 REAL(
dp),
DIMENSION(3) :: fodeb, fodeb2
856 REAL(kind=
dp),
DIMENSION(3, 3) :: h_stress, pv_loc, stdeb, sttot
861 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_s, scrm
862 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_p
876 TYPE(
pw_r3d_rs_type),
DIMENSION(:),
POINTER :: rho_r, v_rspace, v_rspace_in, &
879 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
881 TYPE(
qs_rho_type),
POINTER :: rho, rho1, rho_struct, rho_xc
886 CALL timeset(routinen, handle)
888 debug_forces = ec_env%debug_forces
889 debug_stress = ec_env%debug_stress
892 IF (logger%para_env%is_source())
THEN
898 NULLIFY (atomic_kind_set, cell, dft_control, force, ks_env, &
899 matrix_p, matrix_s, para_env, pw_env, rho, sab_orb, virial)
902 dft_control=dft_control, &
911 cpassert(
ASSOCIATED(pw_env))
913 nspins = dft_control%nspins
914 use_virial = virial%pv_availability .AND. (.NOT. virial%pv_numer)
916 fconv = 1.0e-9_dp*
pascal/cell%deth
917 IF (debug_stress .AND. use_virial)
THEN
918 sttot = virial%pv_virial
922 gapw = dft_control%qs_control%gapw
923 gapw_xc = dft_control%qs_control%gapw_xc
925 cpassert(
ASSOCIATED(rho_xc))
927 IF (gapw .OR. gapw_xc)
THEN
929 cpabort(
"DC-DFT + GAPW + Stress NYA")
936 NULLIFY (hartree_local, local_rho_set)
937 IF (gapw .OR. gapw_xc)
THEN
939 atomic_kind_set=atomic_kind_set, &
940 qs_kind_set=qs_kind_set)
943 qs_kind_set, dft_control, para_env)
946 CALL init_rho0(local_rho_set, qs_env, dft_control%qs_control%gapw_control)
952 CALL get_qs_env(qs_env=qs_env, oce=oce, sab_orb=sab_orb)
954 qs_kind_set, oce, sab_orb, para_env)
958 NULLIFY (auxbas_pw_pool, poisson_env)
960 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool, &
961 poisson_env=poisson_env)
964 CALL auxbas_pw_pool%create_pw(v_hartree_gspace)
965 CALL auxbas_pw_pool%create_pw(rho_tot_gspace)
966 CALL auxbas_pw_pool%create_pw(v_hartree_rspace)
975 h_stress(:, :) = 0.0_dp
977 density=rho_tot_gspace, &
979 vhartree=v_hartree_gspace, &
982 virial%pv_ehartree = virial%pv_ehartree + h_stress/real(para_env%num_pe,
dp)
983 virial%pv_virial = virial%pv_virial + h_stress/real(para_env%num_pe,
dp)
985 IF (debug_stress)
THEN
986 stdeb = fconv*(h_stress/real(para_env%num_pe,
dp))
987 CALL para_env%sum(stdeb)
988 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
997 CALL pw_transfer(v_hartree_gspace, v_hartree_rspace)
998 CALL pw_scale(v_hartree_rspace, v_hartree_rspace%pw_grid%dvol)
1002 ALLOCATE (ec_env%rhoout_r(nspins))
1003 DO ispin = 1, nspins
1004 CALL auxbas_pw_pool%create_pw(ec_env%rhoout_r(ispin))
1005 CALL pw_copy(rho_r(ispin), ec_env%rhoout_r(ispin))
1010 IF (debug_forces) fodeb(1:3) = force(1)%rho_core(1:3, 1)
1011 IF (debug_stress .AND. use_virial) stdeb = virial%pv_ehartree
1012 CALL integrate_v_core_rspace(v_hartree_rspace, qs_env)
1013 IF (debug_forces)
THEN
1014 fodeb(1:3) = force(1)%rho_core(1:3, 1) - fodeb(1:3)
1015 CALL para_env%sum(fodeb)
1016 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Vtot*dncore", fodeb
1018 IF (debug_stress .AND. use_virial)
THEN
1019 stdeb = fconv*(virial%pv_ehartree - stdeb)
1020 CALL para_env%sum(stdeb)
1021 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1027 NULLIFY (v_rspace, v_tau_rspace)
1030 IF (use_virial) virial%pv_calculate = .true.
1034 CALL get_qs_env(qs_env=qs_env, rho_xc=rho_struct)
1036 CALL get_qs_env(qs_env=qs_env, rho=rho_struct)
1038 CALL qs_vxc_create(ks_env=ks_env, rho_struct=rho_struct, xc_section=ec_env%xc_section, &
1039 vxc_rho=v_rspace, vxc_tau=v_tau_rspace, exc=exc, just_energy=.false.)
1041 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
1042 IF (debug_stress .AND. use_virial) stdeb = virial%pv_virial
1047 IF (debug_forces)
THEN
1048 fodeb(1:3) = force(1)%rho_elec(1:3, 1) - fodeb(1:3)
1049 CALL para_env%sum(fodeb)
1050 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Fxc*dw ", fodeb
1052 IF (debug_stress .AND. use_virial)
THEN
1053 stdeb = fconv*(virial%pv_virial - stdeb)
1054 CALL para_env%sum(stdeb)
1055 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1059 IF (.NOT.
ASSOCIATED(v_rspace))
THEN
1060 ALLOCATE (v_rspace(nspins))
1061 DO ispin = 1, nspins
1062 CALL auxbas_pw_pool%create_pw(v_rspace(ispin))
1067 IF (use_virial)
THEN
1068 virial%pv_exc = virial%pv_exc - virial%pv_xc
1069 virial%pv_virial = virial%pv_virial - virial%pv_xc
1076 DO ispin = 1, nspins
1077 ALLOCATE (scrm(ispin)%matrix)
1078 CALL dbcsr_create(scrm(ispin)%matrix, template=ec_env%matrix_ks(ispin, 1)%matrix)
1079 CALL dbcsr_copy(scrm(ispin)%matrix, ec_env%matrix_ks(ispin, 1)%matrix)
1080 CALL dbcsr_set(scrm(ispin)%matrix, 0.0_dp)
1083 pw_grid => v_hartree_rspace%pw_grid
1084 ALLOCATE (v_rspace_in(nspins))
1085 DO ispin = 1, nspins
1086 CALL v_rspace_in(ispin)%create(pw_grid)
1090 DO ispin = 1, nspins
1092 CALL pw_transfer(ec_env%vxc_rspace(ispin), v_rspace_in(ispin))
1093 IF (.NOT. gapw_xc)
THEN
1097 CALL pw_axpy(ec_env%vh_rspace, v_rspace_in(ispin))
1107 IF ((gapw .OR. gapw_xc) .AND. ec_env%do_ec_admm)
THEN
1111 cpabort(
"GAPW HFX ADMM + Energy Correction NYA")
1115 IF (debug_forces) fodeb(1:3) = force(1)%fock_4c(1:3, 1)
1116 IF (debug_forces) fodeb2(1:3) = force(1)%overlap_admm(1:3, 1)
1123 hfx_sections=ec_hfx_sections, &
1124 x_data=ec_env%x_data, &
1126 do_admm=ec_env%do_ec_admm, &
1127 calc_forces=.true., &
1128 reuse_hfx=ec_env%reuse_hfx, &
1129 do_im_time=.false., &
1130 e_ex_from_gw=dummy_real, &
1131 e_admm_from_gw=dummy_real2, &
1134 IF (debug_forces)
THEN
1135 fodeb(1:3) = force(1)%fock_4c(1:3, 1) - fodeb(1:3)
1136 CALL para_env%sum(fodeb)
1137 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: P*hfx_DC ", fodeb
1139 fodeb2(1:3) = force(1)%overlap_admm(1:3, 1) - fodeb2(1:3)
1140 CALL para_env%sum(fodeb2)
1141 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: P*hfx_DC*S ", fodeb2
1143 IF (debug_stress .AND. use_virial)
THEN
1144 stdeb = -1.0_dp*fconv*virial%pv_fock_4c
1145 CALL para_env%sum(stdeb)
1146 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1154 IF (use_virial)
THEN
1155 pv_loc = virial%pv_virial
1158 basis_type =
"HARRIS"
1159 IF (gapw .OR. gapw_xc)
THEN
1160 task_list => ec_env%task_list_soft
1162 task_list => ec_env%task_list
1165 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
1166 IF (debug_stress .AND. use_virial) stdeb = virial%pv_virial
1168 DO ispin = 1, nspins
1170 CALL pw_scale(v_rspace(ispin), v_rspace(ispin)%pw_grid%dvol)
1173 CALL integrate_v_rspace(v_rspace=v_rspace(ispin), &
1175 pmat=matrix_p(ispin, 1), &
1177 calculate_forces=.true., &
1178 basis_type=basis_type, &
1179 task_list_external=task_list)
1181 CALL integrate_v_rspace(v_rspace=v_hartree_rspace, &
1183 pmat=matrix_p(ispin, 1), &
1185 calculate_forces=.true., &
1186 basis_type=basis_type, &
1187 task_list_external=ec_env%task_list)
1189 CALL pw_axpy(v_hartree_rspace, v_rspace(ispin))
1191 CALL integrate_v_rspace(v_rspace=v_rspace(ispin), &
1193 pmat=matrix_p(ispin, 1), &
1195 calculate_forces=.true., &
1196 basis_type=basis_type, &
1197 task_list_external=task_list)
1201 IF (debug_forces)
THEN
1202 fodeb(1:3) = force(1)%rho_elec(1:3, 1) - fodeb(1:3)
1203 CALL para_env%sum(fodeb)
1204 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Pout*dVhxc ", fodeb
1206 IF (debug_stress .AND. use_virial)
THEN
1207 stdeb = fconv*(virial%pv_virial - stdeb)
1208 CALL para_env%sum(stdeb)
1209 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1213 IF (
ASSOCIATED(v_tau_rspace))
THEN
1214 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
1215 IF (debug_stress .AND. use_virial) stdeb = virial%pv_virial
1216 DO ispin = 1, nspins
1217 CALL pw_scale(v_tau_rspace(ispin), v_tau_rspace(ispin)%pw_grid%dvol)
1219 CALL integrate_v_rspace(v_rspace=v_tau_rspace(ispin), &
1221 pmat=matrix_p(ispin, 1), &
1223 calculate_forces=.true., &
1224 compute_tau=.true., &
1225 basis_type=basis_type, &
1226 task_list_external=task_list)
1229 IF (debug_forces)
THEN
1230 fodeb(1:3) = force(1)%rho_elec(1:3, 1) - fodeb(1:3)
1231 CALL para_env%sum(fodeb)
1232 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Pout*dVhxc_tau ", fodeb
1234 IF (debug_stress .AND. use_virial)
THEN
1235 stdeb = fconv*(virial%pv_virial - stdeb)
1236 CALL para_env%sum(stdeb)
1237 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1242 IF (gapw .OR. gapw_xc)
THEN
1245 rho_atom_set_external=local_rho_set%rho_atom_set, &
1246 xc_section_external=ec_env%xc_section)
1249 IF (debug_forces) fodeb(1:3) = force(1)%g0s_Vh_elec(1:3, 1)
1251 calculate_forces=.true., local_rho_set=local_rho_set)
1252 IF (debug_forces)
THEN
1253 fodeb(1:3) = force(1)%g0s_Vh_elec(1:3, 1) - fodeb(1:3)
1254 CALL para_env%sum(fodeb)
1255 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: P*g0s_Vh_elec ", fodeb
1257 ehartree_1c = 0.0_dp
1258 CALL vh_1c_gg_integrals(qs_env, ehartree_1c, hartree_local%ecoul_1c, local_rho_set, &
1259 para_env, tddft=.false., core_2nd=.false.)
1262 IF (gapw .OR. gapw_xc)
THEN
1264 IF (debug_forces) fodeb(1:3) = force(1)%vhxc_atom(1:3, 1)
1266 rho_atom_external=local_rho_set%rho_atom_set)
1267 IF (debug_forces)
THEN
1268 fodeb(1:3) = force(1)%vhxc_atom(1:3, 1) - fodeb(1:3)
1269 CALL para_env%sum(fodeb)
1270 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: P*vhxc_atom ", fodeb
1275 IF (use_virial)
THEN
1276 virial%pv_ehartree = virial%pv_ehartree + (virial%pv_virial - pv_loc)
1295 NULLIFY (ec_env%matrix_hz)
1297 DO ispin = 1, nspins
1298 ALLOCATE (ec_env%matrix_hz(ispin)%matrix)
1299 CALL dbcsr_create(ec_env%matrix_hz(ispin)%matrix, template=matrix_s(1)%matrix)
1300 CALL dbcsr_copy(ec_env%matrix_hz(ispin)%matrix, matrix_s(1)%matrix)
1301 CALL dbcsr_set(ec_env%matrix_hz(ispin)%matrix, 0.0_dp)
1304 DO ispin = 1, nspins
1307 CALL pw_axpy(v_rspace_in(ispin), v_rspace(ispin), -1.0_dp)
1310 DO ispin = 1, nspins
1311 CALL integrate_v_rspace(v_rspace=v_rspace(ispin), &
1312 hmat=ec_env%matrix_hz(ispin), &
1313 pmat=matrix_p(ispin, 1), &
1315 calculate_forces=.false., &
1316 basis_type=basis_type, &
1317 task_list_external=task_list)
1321 IF (dft_control%use_kinetic_energy_density)
THEN
1324 IF (.NOT.
ASSOCIATED(v_tau_rspace))
THEN
1325 ALLOCATE (v_tau_rspace(nspins))
1326 DO ispin = 1, nspins
1327 CALL auxbas_pw_pool%create_pw(v_tau_rspace(ispin))
1328 CALL pw_zero(v_tau_rspace(ispin))
1332 DO ispin = 1, nspins
1334 IF (
ASSOCIATED(ec_env%vtau_rspace))
THEN
1335 CALL pw_axpy(ec_env%vtau_rspace(ispin), v_tau_rspace(ispin), -1.0_dp)
1338 CALL integrate_v_rspace(v_rspace=v_tau_rspace(ispin), &
1339 hmat=ec_env%matrix_hz(ispin), &
1340 pmat=matrix_p(ispin, 1), &
1342 calculate_forces=.false., compute_tau=.true., &
1343 basis_type=basis_type, &
1344 task_list_external=task_list)
1348 IF (gapw .OR. gapw_xc)
THEN
1351 CALL update_ks_atom(qs_env, ec_env%matrix_hz, matrix_p, .false., &
1352 rho_atom_external=local_rho_set%rho_atom_set, kintegral=1.0_dp)
1354 CALL update_ks_atom(qs_env, ec_env%matrix_hz, matrix_p, .false., &
1355 rho_atom_external=ec_env%local_rho_set%rho_atom_set, kintegral=-1.0_dp)
1362 ext_hfx_section=ec_hfx_sections, &
1363 x_data=ec_env%x_data, &
1364 recalc_integrals=.false., &
1365 do_admm=ec_env%do_ec_admm, &
1368 reuse_hfx=ec_env%reuse_hfx)
1371 IF (debug_forces) fodeb(1:3) = force(1)%core_overlap(1:3, 1)
1372 IF (debug_stress .AND. use_virial) stdeb = virial%pv_ecore_overlap
1374 IF (debug_forces)
THEN
1375 fodeb(1:3) = force(1)%core_overlap(1:3, 1) - fodeb(1:3)
1376 CALL para_env%sum(fodeb)
1377 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: CoreOverlap", fodeb
1379 IF (debug_stress .AND. use_virial)
THEN
1380 stdeb = fconv*(stdeb - virial%pv_ecore_overlap)
1381 CALL para_env%sum(stdeb)
1382 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1386 IF (debug_forces)
THEN
1387 CALL get_qs_env(qs_env, natom=natom, atomic_kind_set=atomic_kind_set)
1388 ALLOCATE (ftot(3, natom))
1390 fodeb(1:3) = ftot(1:3, 1)
1392 CALL para_env%sum(fodeb)
1393 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Force Explicit", fodeb
1397 IF (gapw .OR. gapw_xc)
THEN
1405 DO ispin = 1, nspins
1406 CALL auxbas_pw_pool%give_back_pw(v_rspace(ispin))
1407 CALL auxbas_pw_pool%give_back_pw(v_rspace_in(ispin))
1408 IF (
ASSOCIATED(v_tau_rspace))
THEN
1409 CALL auxbas_pw_pool%give_back_pw(v_tau_rspace(ispin))
1413 DEALLOCATE (v_rspace, v_rspace_in)
1414 IF (
ASSOCIATED(v_tau_rspace))
DEALLOCATE (v_tau_rspace)
1416 CALL auxbas_pw_pool%give_back_pw(rho_tot_gspace)
1417 CALL auxbas_pw_pool%give_back_pw(v_hartree_gspace)
1418 CALL auxbas_pw_pool%give_back_pw(v_hartree_rspace)
1422 IF (use_virial)
THEN
1423 IF (qs_env%energy_correction)
THEN
1424 ec_env%ehartree = ehartree
1429 IF (debug_stress .AND. use_virial)
THEN
1431 stdeb = -1.0_dp*fconv*ehartree
1432 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1435 stdeb = -1.0_dp*fconv*exc
1436 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1445 CALL para_env%sum(virdeb%pv_overlap)
1446 CALL para_env%sum(virdeb%pv_ekinetic)
1447 CALL para_env%sum(virdeb%pv_ppl)
1448 CALL para_env%sum(virdeb%pv_ppnl)
1449 CALL para_env%sum(virdeb%pv_ecore_overlap)
1450 CALL para_env%sum(virdeb%pv_ehartree)
1451 CALL para_env%sum(virdeb%pv_exc)
1452 CALL para_env%sum(virdeb%pv_exx)
1453 CALL para_env%sum(virdeb%pv_vdw)
1454 CALL para_env%sum(virdeb%pv_mp2)
1455 CALL para_env%sum(virdeb%pv_nlcc)
1456 CALL para_env%sum(virdeb%pv_gapw)
1457 CALL para_env%sum(virdeb%pv_lrigpw)
1458 CALL para_env%sum(virdeb%pv_virial)
1463 virdeb%pv_ehartree(i, i) = virdeb%pv_ehartree(i, i) - 2.0_dp*ehartree
1464 virdeb%pv_virial(i, i) = virdeb%pv_virial(i, i) - exc &
1466 virdeb%pv_exc(i, i) = virdeb%pv_exc(i, i) - exc
1472 CALL para_env%sum(sttot)
1473 stdeb = fconv*(virdeb%pv_virial - sttot)
1474 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1477 stdeb = fconv*(virdeb%pv_virial)
1478 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1488 CALL timestop(handle)
1490 END SUBROUTINE ec_dc_build_ks_matrix_force
1498 SUBROUTINE ec_disp(qs_env, ec_env, calculate_forces)
1499 TYPE(qs_environment_type),
POINTER :: qs_env
1500 TYPE(energy_correction_type),
POINTER :: ec_env
1501 LOGICAL,
INTENT(IN) :: calculate_forces
1503 REAL(kind=dp) :: edisp, egcp
1506 CALL calculate_dispersion_pairpot(qs_env, ec_env%dispersion_env, edisp, calculate_forces)
1507 IF (.NOT. calculate_forces)
THEN
1508 ec_env%edispersion = ec_env%edispersion + edisp + egcp
1511 END SUBROUTINE ec_disp
1520 SUBROUTINE ec_build_core_hamiltonian(qs_env, ec_env)
1521 TYPE(qs_environment_type),
POINTER :: qs_env
1522 TYPE(energy_correction_type),
POINTER :: ec_env
1524 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ec_build_core_hamiltonian'
1526 CHARACTER(LEN=default_string_length) :: basis_type
1527 INTEGER :: handle, img, nder, nhfimg, nimages
1528 LOGICAL :: calculate_forces, use_virial
1529 TYPE(atomic_kind_type),
DIMENSION(:),
POINTER :: atomic_kind_set
1530 TYPE(dbcsr_type),
POINTER :: smat
1531 TYPE(dft_control_type),
POINTER :: dft_control
1532 TYPE(neighbor_list_set_p_type),
DIMENSION(:), &
1533 POINTER :: sab_orb, sac_ae, sac_ppl, sap_ppnl
1534 TYPE(particle_type),
DIMENSION(:),
POINTER :: particle_set
1535 TYPE(qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
1536 TYPE(qs_ks_env_type),
POINTER :: ks_env
1538 CALL timeset(routinen, handle)
1540 NULLIFY (atomic_kind_set, dft_control, ks_env, particle_set, &
1543 CALL get_qs_env(qs_env=qs_env, &
1544 atomic_kind_set=atomic_kind_set, &
1545 dft_control=dft_control, &
1546 particle_set=particle_set, &
1547 qs_kind_set=qs_kind_set, &
1551 nimages = dft_control%nimages
1552 IF (nimages /= 1)
THEN
1553 cpabort(
"K-points for Harris functional not implemented")
1557 IF (dft_control%qs_control%gapw .OR. dft_control%qs_control%gapw_xc)
THEN
1558 cpabort(
"Harris functional for GAPW not implemented")
1562 use_virial = .false.
1563 calculate_forces = .false.
1566 NULLIFY (sab_orb, sac_ae, sac_ppl, sap_ppnl)
1567 sab_orb => ec_env%sab_orb
1568 sac_ae => ec_env%sac_ae
1569 sac_ppl => ec_env%sac_ppl
1570 sap_ppnl => ec_env%sap_ppnl
1572 basis_type =
"HARRIS"
1576 CALL build_overlap_matrix(ks_env, matrixkp_s=ec_env%matrix_s, &
1577 matrix_name=
"OVERLAP MATRIX", &
1578 basis_type_a=basis_type, &
1579 basis_type_b=basis_type, &
1580 sab_nl=sab_orb, ext_kpoints=ec_env%kpoints)
1581 CALL build_kinetic_matrix(ks_env, matrixkp_t=ec_env%matrix_t, &
1582 matrix_name=
"KINETIC ENERGY MATRIX", &
1583 basis_type=basis_type, &
1584 sab_nl=sab_orb, ext_kpoints=ec_env%kpoints)
1587 nhfimg =
SIZE(ec_env%matrix_s, 2)
1588 CALL dbcsr_allocate_matrix_set(ec_env%matrix_h, 1, nhfimg)
1590 ALLOCATE (ec_env%matrix_h(1, img)%matrix)
1591 smat => ec_env%matrix_s(1, img)%matrix
1592 CALL dbcsr_create(ec_env%matrix_h(1, img)%matrix, template=smat)
1593 CALL cp_dbcsr_alloc_block_from_nbl(ec_env%matrix_h(1, img)%matrix, sab_orb)
1598 CALL dbcsr_copy(ec_env%matrix_h(1, img)%matrix, ec_env%matrix_t(1, img)%matrix, &
1599 keep_sparsity=.true., name=
"CORE HAMILTONIAN MATRIX")
1602 CALL core_matrices(qs_env, ec_env%matrix_h, ec_env%matrix_p, calculate_forces, nder, &
1603 ec_env=ec_env, ec_env_matrices=.true., ext_kpoints=ec_env%kpoints, &
1604 basis_type=basis_type)
1607 ec_env%efield_nuclear = 0.0_dp
1608 CALL ec_efield_local_operator(qs_env, ec_env, calculate_forces)
1610 CALL timestop(handle)
1612 END SUBROUTINE ec_build_core_hamiltonian
1623 SUBROUTINE ec_build_ks_matrix(qs_env, ec_env)
1624 TYPE(qs_environment_type),
POINTER :: qs_env
1625 TYPE(energy_correction_type),
POINTER :: ec_env
1627 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ec_build_ks_matrix'
1629 CHARACTER(LEN=default_string_length) :: headline
1630 INTEGER :: handle, img, iounit, ispin, natom, &
1631 nhfimg, nimages, nspins
1632 LOGICAL :: calculate_forces, &
1633 do_adiabatic_rescaling, do_ec_hfx, &
1634 gapw, gapw_xc, hfx_treat_lsd_in_core, &
1636 REAL(dp) :: dummy_real, dummy_real2(2), eexc, eh1c, &
1638 TYPE(admm_type),
POINTER :: admm_env
1639 TYPE(atomic_kind_type),
DIMENSION(:),
POINTER :: atomic_kind_set
1640 TYPE(cp_logger_type),
POINTER :: logger
1641 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: ks_mat, ps_mat
1642 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: rho_ao_kp
1643 TYPE(dbcsr_type),
POINTER :: smat
1644 TYPE(dft_control_type),
POINTER :: dft_control
1645 TYPE(hartree_local_type),
POINTER :: hartree_local
1646 TYPE(local_rho_type),
POINTER :: local_rho_set_ec
1647 TYPE(mp_para_env_type),
POINTER :: para_env
1648 TYPE(neighbor_list_set_p_type),
DIMENSION(:), &
1650 TYPE(oce_matrix_type),
POINTER :: oce
1651 TYPE(pw_env_type),
POINTER :: pw_env
1652 TYPE(pw_pool_type),
POINTER :: auxbas_pw_pool
1653 TYPE(pw_r3d_rs_type),
DIMENSION(:),
POINTER :: rho_r, tau_r, v_rspace, v_tau_rspace
1654 TYPE(qs_energy_type),
POINTER :: energy
1655 TYPE(qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
1656 TYPE(qs_ks_env_type),
POINTER :: ks_env
1657 TYPE(qs_rho_type),
POINTER :: rho, rho_xc
1658 TYPE(section_vals_type),
POINTER :: adiabatic_rescaling_section, &
1659 ec_hfx_sections, ec_section
1661 CALL timeset(routinen, handle)
1663 logger => cp_get_default_logger()
1664 IF (logger%para_env%is_source())
THEN
1665 iounit = cp_logger_get_default_unit_nr(logger, local=.true.)
1671 NULLIFY (auxbas_pw_pool, dft_control, energy, ks_env, rho, rho_r, tau_r)
1672 CALL get_qs_env(qs_env=qs_env, &
1673 dft_control=dft_control, &
1675 rho=rho, rho_xc=rho_xc)
1676 nspins = dft_control%nspins
1677 nimages = dft_control%nimages
1678 calculate_forces = .false.
1679 use_virial = .false.
1681 gapw = dft_control%qs_control%gapw
1682 gapw_xc = dft_control%qs_control%gapw_xc
1685 IF (
ASSOCIATED(ec_env%matrix_ks))
CALL dbcsr_deallocate_matrix_set(ec_env%matrix_ks)
1686 nhfimg =
SIZE(ec_env%matrix_s, 2)
1687 dft_control%nimages = nhfimg
1688 CALL dbcsr_allocate_matrix_set(ec_env%matrix_ks, nspins, nhfimg)
1689 DO ispin = 1, nspins
1690 headline =
"KOHN-SHAM MATRIX"
1692 ALLOCATE (ec_env%matrix_ks(ispin, img)%matrix)
1693 smat => ec_env%matrix_s(1, img)%matrix
1694 CALL dbcsr_create(ec_env%matrix_ks(ispin, img)%matrix, name=trim(headline), &
1695 template=smat, matrix_type=dbcsr_type_symmetric)
1696 CALL cp_dbcsr_alloc_block_from_nbl(ec_env%matrix_ks(ispin, img)%matrix, &
1698 CALL dbcsr_set(ec_env%matrix_ks(ispin, img)%matrix, 0.0_dp)
1703 CALL get_qs_env(qs_env=qs_env, pw_env=pw_env)
1704 cpassert(
ASSOCIATED(pw_env))
1707 ec_section => section_vals_get_subs_vals(qs_env%input,
"DFT%ENERGY_CORRECTION")
1708 ec_hfx_sections => section_vals_get_subs_vals(ec_section,
"XC%HF")
1709 CALL section_vals_get(ec_hfx_sections, explicit=do_ec_hfx)
1714 adiabatic_rescaling_section => section_vals_get_subs_vals(ec_section,
"XC%ADIABATIC_RESCALING")
1715 CALL section_vals_get(adiabatic_rescaling_section, explicit=do_adiabatic_rescaling)
1716 IF (do_adiabatic_rescaling)
THEN
1717 CALL cp_abort(__location__,
"Adiabatic rescaling NYI for energy correction")
1719 CALL section_vals_val_get(ec_hfx_sections,
"TREAT_LSD_IN_CORE", l_val=hfx_treat_lsd_in_core)
1720 IF (hfx_treat_lsd_in_core)
THEN
1721 CALL cp_abort(__location__,
"HFX_TREAT_LSD_IN_CORE NYI for energy correction")
1723 IF (ec_env%do_kpoints)
THEN
1724 CALL cp_abort(__location__,
"HFX and K-points NYI for energy correction")
1728 IF (dft_control%do_admm)
THEN
1729 IF (dft_control%do_admm_mo)
THEN
1730 cpassert(.NOT. qs_env%run_rtp)
1731 CALL admm_mo_calc_rho_aux(qs_env)
1732 ELSE IF (dft_control%do_admm_dm)
THEN
1733 CALL admm_dm_calc_rho_aux(qs_env)
1740 CALL get_qs_env(qs_env, energy=energy)
1741 CALL calculate_exx(qs_env=qs_env, &
1743 hfx_sections=ec_hfx_sections, &
1744 x_data=ec_env%x_data, &
1746 do_admm=ec_env%do_ec_admm, &
1747 calc_forces=.false., &
1748 reuse_hfx=ec_env%reuse_hfx, &
1749 do_im_time=.false., &
1750 e_ex_from_gw=dummy_real, &
1751 e_admm_from_gw=dummy_real2, &
1755 ec_env%ex = energy%ex
1757 IF (ec_env%do_ec_admm)
THEN
1758 ec_env%exc_aux_fit = energy%exc_aux_fit + energy%exc
1764 ks_mat => ec_env%matrix_ks(:, 1)
1765 CALL add_exx_to_rhs(rhs=ks_mat, &
1767 ext_hfx_section=ec_hfx_sections, &
1768 x_data=ec_env%x_data, &
1769 recalc_integrals=.false., &
1770 do_admm=ec_env%do_ec_admm, &
1773 reuse_hfx=ec_env%reuse_hfx)
1778 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
1779 NULLIFY (v_rspace, v_tau_rspace)
1780 IF (dft_control%qs_control%gapw_xc)
THEN
1781 CALL qs_vxc_create(ks_env=ks_env, rho_struct=rho_xc, xc_section=ec_env%xc_section, &
1782 vxc_rho=v_rspace, vxc_tau=v_tau_rspace, exc=eexc, just_energy=.false.)
1784 CALL qs_vxc_create(ks_env=ks_env, rho_struct=rho, xc_section=ec_env%xc_section, &
1785 vxc_rho=v_rspace, vxc_tau=v_tau_rspace, exc=eexc, just_energy=.false.)
1788 IF (.NOT.
ASSOCIATED(v_rspace))
THEN
1789 ALLOCATE (v_rspace(nspins))
1790 DO ispin = 1, nspins
1791 CALL auxbas_pw_pool%create_pw(v_rspace(ispin))
1792 CALL pw_zero(v_rspace(ispin))
1797 CALL qs_rho_get(rho, rho_r=rho_r)
1798 IF (
ASSOCIATED(v_tau_rspace))
THEN
1799 CALL qs_rho_get(rho, tau_r=tau_r)
1801 DO ispin = 1, nspins
1803 CALL pw_scale(v_rspace(ispin), v_rspace(ispin)%pw_grid%dvol)
1804 CALL pw_axpy(ec_env%vh_rspace, v_rspace(ispin))
1806 ks_mat => ec_env%matrix_ks(ispin, :)
1807 CALL integrate_v_rspace(v_rspace=v_rspace(ispin), &
1810 calculate_forces=.false., &
1811 basis_type=
"HARRIS", &
1812 task_list_external=ec_env%task_list)
1814 IF (
ASSOCIATED(v_tau_rspace))
THEN
1816 CALL pw_scale(v_tau_rspace(ispin), v_tau_rspace(ispin)%pw_grid%dvol)
1817 CALL integrate_v_rspace(v_rspace=v_tau_rspace(ispin), &
1820 calculate_forces=.false., &
1821 compute_tau=.true., &
1822 basis_type=
"HARRIS", &
1823 task_list_external=ec_env%task_list)
1827 evhxc = evhxc + pw_integral_ab(rho_r(ispin), v_rspace(ispin))/ &
1828 v_rspace(1)%pw_grid%dvol
1829 IF (
ASSOCIATED(v_tau_rspace))
THEN
1830 evhxc = evhxc + pw_integral_ab(tau_r(ispin), v_tau_rspace(ispin))/ &
1831 v_tau_rspace(ispin)%pw_grid%dvol
1836 IF (gapw .OR. gapw_xc)
THEN
1838 IF (ec_env%basis_inconsistent)
THEN
1839 cpabort(
"Energy corrction [GAPW] only with BASIS=ORBITAL possible")
1842 NULLIFY (hartree_local, local_rho_set_ec)
1843 CALL get_qs_env(qs_env, para_env=para_env, &
1844 atomic_kind_set=atomic_kind_set, &
1845 qs_kind_set=qs_kind_set)
1846 CALL local_rho_set_create(local_rho_set_ec)
1847 CALL allocate_rho_atom_internals(local_rho_set_ec%rho_atom_set, atomic_kind_set, &
1848 qs_kind_set, dft_control, para_env)
1850 CALL get_qs_env(qs_env, natom=natom)
1851 CALL init_rho0(local_rho_set_ec, qs_env, dft_control%qs_control%gapw_control)
1852 CALL rho0_s_grid_create(pw_env, local_rho_set_ec%rho0_mpole)
1853 CALL hartree_local_create(hartree_local)
1854 CALL init_coulomb_local(hartree_local, natom)
1857 CALL get_qs_env(qs_env=qs_env, oce=oce, sab_orb=sab)
1858 CALL qs_rho_get(rho, rho_ao_kp=rho_ao_kp)
1859 CALL calculate_rho_atom_coeff(qs_env, rho_ao_kp, local_rho_set_ec%rho_atom_set, &
1860 qs_kind_set, oce, sab, para_env)
1861 CALL prepare_gapw_den(qs_env, local_rho_set_ec, do_rho0=gapw)
1863 CALL calculate_vxc_atom(qs_env, .false., exc1=exc1, xc_section_external=ec_env%xc_section, &
1864 rho_atom_set_external=local_rho_set_ec%rho_atom_set)
1868 CALL vh_1c_gg_integrals(qs_env, eh1c, hartree_local%ecoul_1c, local_rho_set_ec, para_env, .false.)
1869 CALL integrate_vhg0_rspace(qs_env, ec_env%vh_rspace, para_env, calculate_forces=.false., &
1870 local_rho_set=local_rho_set_ec)
1871 ec_env%ehartree_1c = eh1c
1873 IF (dft_control%do_admm)
THEN
1874 CALL get_qs_env(qs_env, admm_env=admm_env)
1875 IF (admm_env%aux_exch_func /= do_admm_aux_exch_func_none)
THEN
1877 cpabort(
"GAPW HFX ADMM + Energy Correction NYA")
1881 ks_mat => ec_env%matrix_ks(:, 1)
1882 ps_mat => ec_env%matrix_p(:, 1)
1883 CALL update_ks_atom(qs_env, ks_mat, ps_mat, forces=.false., &
1884 rho_atom_external=local_rho_set_ec%rho_atom_set)
1886 CALL local_rho_set_release(local_rho_set_ec)
1888 CALL hartree_local_release(hartree_local)
1894 DO ispin = 1, nspins
1895 CALL auxbas_pw_pool%give_back_pw(v_rspace(ispin))
1896 IF (
ASSOCIATED(v_tau_rspace))
THEN
1897 CALL auxbas_pw_pool%give_back_pw(v_tau_rspace(ispin))
1900 DEALLOCATE (v_rspace)
1901 IF (
ASSOCIATED(v_tau_rspace))
DEALLOCATE (v_tau_rspace)
1908 DO ispin = 1, nspins
1910 CALL dbcsr_add(ec_env%matrix_ks(ispin, img)%matrix, ec_env%matrix_h(1, img)%matrix, &
1911 alpha_scalar=1.0_dp, beta_scalar=1.0_dp)
1912 CALL dbcsr_filter(ec_env%matrix_ks(ispin, img)%matrix, &
1913 dft_control%qs_control%eps_filter_matrix)
1917 dft_control%nimages = nimages
1919 CALL timestop(handle)
1921 END SUBROUTINE ec_build_ks_matrix
1933 SUBROUTINE ec_build_core_hamiltonian_force(qs_env, ec_env, matrix_p, matrix_s, matrix_w)
1934 TYPE(qs_environment_type),
POINTER :: qs_env
1935 TYPE(energy_correction_type),
POINTER :: ec_env
1936 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_p, matrix_s, matrix_w
1938 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ec_build_core_hamiltonian_force'
1940 CHARACTER(LEN=default_string_length) :: basis_type
1941 INTEGER :: handle, img, iounit, nder, nhfimg, &
1943 LOGICAL :: calculate_forces, debug_forces, &
1944 debug_stress, use_virial
1945 REAL(kind=dp) :: fconv
1946 REAL(kind=dp),
DIMENSION(3) :: fodeb
1947 REAL(kind=dp),
DIMENSION(3, 3) :: stdeb, sttot
1948 TYPE(cell_type),
POINTER :: cell
1949 TYPE(cp_logger_type),
POINTER :: logger
1950 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: scrm
1951 TYPE(dft_control_type),
POINTER :: dft_control
1952 TYPE(mp_para_env_type),
POINTER :: para_env
1953 TYPE(neighbor_list_set_p_type),
DIMENSION(:), &
1955 TYPE(qs_force_type),
DIMENSION(:),
POINTER :: force
1956 TYPE(qs_ks_env_type),
POINTER :: ks_env
1957 TYPE(virial_type),
POINTER :: virial
1959 CALL timeset(routinen, handle)
1961 debug_forces = ec_env%debug_forces
1962 debug_stress = ec_env%debug_stress
1964 logger => cp_get_default_logger()
1965 IF (logger%para_env%is_source())
THEN
1966 iounit = cp_logger_get_default_unit_nr(logger, local=.true.)
1971 calculate_forces = .true.
1973 basis_type =
"HARRIS"
1976 NULLIFY (cell, dft_control, force, ks_env, para_env, virial)
1977 CALL get_qs_env(qs_env=qs_env, &
1979 dft_control=dft_control, &
1982 para_env=para_env, &
1984 nimages = dft_control%nimages
1985 IF (nimages /= 1)
THEN
1986 cpabort(
"K-points for Harris functional not implemented")
1989 IF (dft_control%qs_control%gapw .OR. dft_control%qs_control%gapw_xc)
THEN
1990 IF (ec_env%energy_functional == ec_functional_harris)
THEN
1991 cpabort(
"Harris functional for GAPW not implemented")
1996 use_virial = virial%pv_availability .AND. (.NOT. virial%pv_numer)
1998 fconv = 1.0e-9_dp*pascal/cell%deth
1999 IF (debug_stress .AND. use_virial)
THEN
2000 sttot = virial%pv_virial
2004 sab_orb => ec_env%sab_orb
2007 nhfimg =
SIZE(matrix_s, 2)
2009 CALL dbcsr_allocate_matrix_set(scrm, 1, nhfimg)
2011 ALLOCATE (scrm(1, img)%matrix)
2012 CALL dbcsr_create(scrm(1, img)%matrix, template=matrix_s(1, img)%matrix)
2013 CALL cp_dbcsr_alloc_block_from_nbl(scrm(1, img)%matrix, sab_orb)
2017 IF (
SIZE(matrix_p, 1) == 2)
THEN
2019 CALL dbcsr_add(matrix_w(1, img)%matrix, matrix_w(2, img)%matrix, &
2020 alpha_scalar=1.0_dp, beta_scalar=1.0_dp)
2025 IF (debug_forces) fodeb(1:3) = force(1)%overlap(1:3, 1)
2026 IF (debug_stress .AND. use_virial) stdeb = virial%pv_overlap
2027 CALL build_overlap_matrix(ks_env, matrixkp_s=scrm, &
2028 matrix_name=
"OVERLAP MATRIX", &
2029 basis_type_a=basis_type, &
2030 basis_type_b=basis_type, &
2031 sab_nl=sab_orb, calculate_forces=.true., &
2032 matrixkp_p=matrix_w, ext_kpoints=ec_env%kpoints)
2034 IF (debug_forces)
THEN
2035 fodeb(1:3) = force(1)%overlap(1:3, 1) - fodeb(1:3)
2036 CALL para_env%sum(fodeb)
2037 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Wout*dS ", fodeb
2039 IF (debug_stress .AND. use_virial)
THEN
2040 stdeb = fconv*(virial%pv_overlap - stdeb)
2041 CALL para_env%sum(stdeb)
2042 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2043 'STRESS| Wout*dS', one_third_sum_diag(stdeb), det_3x3(stdeb)
2046 CALL kinetic_energy_matrix(qs_env, matrixkp_t=scrm, matrix_p=matrix_p, &
2047 calculate_forces=.true., sab_orb=sab_orb, &
2048 basis_type=basis_type, ext_kpoints=ec_env%kpoints, &
2049 debug_forces=debug_forces, debug_stress=debug_stress)
2051 CALL core_matrices(qs_env, scrm, matrix_p, calculate_forces, nder, &
2052 ec_env=ec_env, ec_env_matrices=.false., basis_type=basis_type, &
2053 ext_kpoints=ec_env%kpoints, &
2054 debug_forces=debug_forces, debug_stress=debug_stress)
2057 ec_env%efield_nuclear = 0.0_dp
2058 IF (calculate_forces .AND. debug_forces) fodeb(1:3) = force(1)%efield(1:3, 1)
2059 CALL ec_efield_local_operator(qs_env, ec_env, calculate_forces)
2060 IF (calculate_forces .AND. debug_forces)
THEN
2061 fodeb(1:3) = force(1)%efield(1:3, 1) - fodeb(1:3)
2062 CALL para_env%sum(fodeb)
2063 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Pout*dEfield", fodeb
2065 IF (debug_stress .AND. use_virial)
THEN
2066 stdeb = fconv*(virial%pv_virial - sttot)
2067 CALL para_env%sum(stdeb)
2068 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2069 'STRESS| Stress Pout*dHcore ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2070 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))")
' '
2074 CALL dbcsr_deallocate_matrix_set(scrm)
2076 CALL timestop(handle)
2078 END SUBROUTINE ec_build_core_hamiltonian_force
2089 SUBROUTINE ec_build_ks_matrix_force(qs_env, ec_env)
2090 TYPE(qs_environment_type),
POINTER :: qs_env
2091 TYPE(energy_correction_type),
POINTER :: ec_env
2093 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ec_build_ks_matrix_force'
2095 CHARACTER(LEN=default_string_length) :: unit_string
2096 INTEGER :: handle, i, img, iounit, ispin, natom, &
2097 nhfimg, nimages, nspins
2098 LOGICAL :: debug_forces, debug_stress, do_ec_hfx, &
2100 REAL(dp) :: dehartree, dummy_real, dummy_real2(2), &
2101 eexc, ehartree, eovrl, exc, fconv
2102 REAL(dp),
ALLOCATABLE,
DIMENSION(:, :) :: ftot
2103 REAL(dp),
DIMENSION(3) :: fodeb
2104 REAL(kind=dp),
DIMENSION(3, 3) :: h_stress, pv_loc, stdeb, sttot
2105 TYPE(atomic_kind_type),
DIMENSION(:),
POINTER :: atomic_kind_set
2106 TYPE(cell_type),
POINTER :: cell
2107 TYPE(cp_logger_type),
POINTER :: logger
2108 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_ks, rho_ao, scrmat
2109 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_p, matrix_s, scrm
2110 TYPE(dft_control_type),
POINTER :: dft_control
2111 TYPE(mp_para_env_type),
POINTER :: para_env
2112 TYPE(neighbor_list_set_p_type),
DIMENSION(:), &
2114 TYPE(pw_c1d_gs_type) :: rho_tot_gspace, rhodn_tot_gspace, &
2116 TYPE(pw_c1d_gs_type),
DIMENSION(:),
POINTER :: rho_g, rhoout_g
2117 TYPE(pw_c1d_gs_type),
POINTER :: rho_core
2118 TYPE(pw_env_type),
POINTER :: pw_env
2119 TYPE(pw_poisson_type),
POINTER :: poisson_env
2120 TYPE(pw_pool_type),
POINTER :: auxbas_pw_pool
2121 TYPE(pw_r3d_rs_type) :: dv_hartree_rspace, v_hartree_rspace, &
2123 TYPE(pw_r3d_rs_type),
DIMENSION(:),
POINTER :: rho_r, rhoout_r, tau_r, tauout_r, &
2124 v_rspace, v_tau_rspace, v_xc, v_xc_tau
2125 TYPE(qs_force_type),
DIMENSION(:),
POINTER :: force
2126 TYPE(qs_ks_env_type),
POINTER :: ks_env
2127 TYPE(qs_rho_type),
POINTER :: rho, rhoout
2128 TYPE(rho_atom_type),
DIMENSION(:),
POINTER :: rho0_atom_set, rho1_atom_set
2129 TYPE(section_vals_type),
POINTER :: ec_hfx_sections, xc_section
2130 TYPE(virial_type),
POINTER :: virial
2132 CALL timeset(routinen, handle)
2134 debug_forces = ec_env%debug_forces
2135 debug_stress = ec_env%debug_stress
2137 logger => cp_get_default_logger()
2138 IF (logger%para_env%is_source())
THEN
2139 iounit = cp_logger_get_default_unit_nr(logger, local=.true.)
2145 NULLIFY (atomic_kind_set, cell, dft_control, force, ks_env, &
2146 matrix_ks, matrix_p, matrix_s, para_env, rho, rho_core, &
2147 rho_g, rho_r, sab_orb, tau_r, virial)
2148 CALL get_qs_env(qs_env=qs_env, &
2150 dft_control=dft_control, &
2153 matrix_ks=matrix_ks, &
2154 para_env=para_env, &
2159 nspins = dft_control%nspins
2160 use_virial = virial%pv_availability .AND. (.NOT. virial%pv_numer)
2164 fconv = cp_unit_from_cp2k(1.0_dp/cell%deth, trim(unit_string))
2166 IF (debug_stress .AND. use_virial)
THEN
2167 sttot = virial%pv_virial
2171 CALL get_qs_env(qs_env=qs_env, pw_env=pw_env)
2172 cpassert(
ASSOCIATED(pw_env))
2174 NULLIFY (auxbas_pw_pool, poisson_env)
2176 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool, &
2177 poisson_env=poisson_env)
2180 CALL auxbas_pw_pool%create_pw(v_hartree_gspace)
2181 CALL auxbas_pw_pool%create_pw(rhodn_tot_gspace)
2182 CALL auxbas_pw_pool%create_pw(v_hartree_rspace)
2184 CALL pw_transfer(ec_env%vh_rspace, v_hartree_rspace)
2189 CALL qs_rho_get(rho, rho_r=rho_r, rho_g=rho_g, tau_r=tau_r)
2190 NULLIFY (rhoout_r, rhoout_g)
2191 ALLOCATE (rhoout_r(nspins), rhoout_g(nspins))
2192 DO ispin = 1, nspins
2193 CALL auxbas_pw_pool%create_pw(rhoout_r(ispin))
2194 CALL auxbas_pw_pool%create_pw(rhoout_g(ispin))
2196 CALL auxbas_pw_pool%create_pw(dv_hartree_rspace)
2197 CALL auxbas_pw_pool%create_pw(vtot_rspace)
2200 nhfimg =
SIZE(ec_env%matrix_s, 2)
2201 nimages = dft_control%nimages
2202 dft_control%nimages = nhfimg
2204 CALL pw_zero(rhodn_tot_gspace)
2205 DO ispin = 1, nspins
2206 rho_ao => ec_env%matrix_p(ispin, :)
2207 CALL calculate_rho_elec(ks_env=ks_env, matrix_p_kp=rho_ao, &
2208 rho=rhoout_r(ispin), &
2209 rho_gspace=rhoout_g(ispin), &
2210 basis_type=
"HARRIS", &
2211 task_list_external=ec_env%task_list)
2215 ALLOCATE (ec_env%rhoout_r(nspins))
2216 DO ispin = 1, nspins
2217 CALL auxbas_pw_pool%create_pw(ec_env%rhoout_r(ispin))
2218 CALL pw_copy(rhoout_r(ispin), ec_env%rhoout_r(ispin))
2222 IF (dft_control%use_kinetic_energy_density)
THEN
2224 TYPE(pw_c1d_gs_type) :: tauout_g
2225 ALLOCATE (tauout_r(nspins))
2226 DO ispin = 1, nspins
2227 CALL auxbas_pw_pool%create_pw(tauout_r(ispin))
2229 CALL auxbas_pw_pool%create_pw(tauout_g)
2231 DO ispin = 1, nspins
2232 CALL calculate_rho_elec(ks_env=ks_env, matrix_p=ec_env%matrix_p(ispin, 1)%matrix, &
2233 rho=tauout_r(ispin), &
2234 rho_gspace=tauout_g, &
2235 compute_tau=.true., &
2236 basis_type=
"HARRIS", &
2237 task_list_external=ec_env%task_list)
2240 CALL auxbas_pw_pool%give_back_pw(tauout_g)
2245 dft_control%nimages = nimages
2247 IF (use_virial)
THEN
2250 CALL auxbas_pw_pool%create_pw(rho_tot_gspace)
2253 CALL calc_rho_tot_gspace(rho_tot_gspace, qs_env, rho)
2256 CALL get_qs_env(qs_env=qs_env, rho_core=rho_core)
2257 CALL pw_copy(rho_core, rhodn_tot_gspace)
2258 DO ispin = 1, dft_control%nspins
2259 CALL pw_axpy(rhoout_g(ispin), rhodn_tot_gspace)
2263 h_stress(:, :) = 0.0_dp
2264 CALL pw_poisson_solve(poisson_env, &
2265 density=rho_tot_gspace, &
2266 ehartree=ehartree, &
2267 vhartree=v_hartree_gspace, &
2268 h_stress=h_stress, &
2269 aux_density=rhodn_tot_gspace)
2271 virial%pv_ehartree = virial%pv_ehartree + h_stress/real(para_env%num_pe, dp)
2272 virial%pv_virial = virial%pv_virial + h_stress/real(para_env%num_pe, dp)
2274 IF (debug_stress)
THEN
2275 stdeb = fconv*(h_stress/real(para_env%num_pe, dp))
2276 CALL para_env%sum(stdeb)
2277 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2278 'STRESS| GREEN 1st v_H[n_in]*n_out ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2282 virial%pv_calculate = .true.
2284 NULLIFY (v_rspace, v_tau_rspace)
2285 CALL qs_vxc_create(ks_env=ks_env, rho_struct=rho, xc_section=ec_env%xc_section, &
2286 vxc_rho=v_rspace, vxc_tau=v_tau_rspace, exc=exc, just_energy=.false.)
2289 virial%pv_exc = virial%pv_exc - virial%pv_xc
2290 virial%pv_virial = virial%pv_virial - virial%pv_xc
2292 IF (debug_stress)
THEN
2293 stdeb = -1.0_dp*fconv*virial%pv_xc
2294 CALL para_env%sum(stdeb)
2295 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2296 'STRESS| GGA 1st E_xc[Pin] ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2299 IF (
ASSOCIATED(v_rspace))
THEN
2300 DO ispin = 1, nspins
2301 CALL auxbas_pw_pool%give_back_pw(v_rspace(ispin))
2303 DEALLOCATE (v_rspace)
2305 IF (
ASSOCIATED(v_tau_rspace))
THEN
2306 DO ispin = 1, nspins
2307 CALL auxbas_pw_pool%give_back_pw(v_tau_rspace(ispin))
2309 DEALLOCATE (v_tau_rspace)
2311 CALL pw_zero(rhodn_tot_gspace)
2316 DO ispin = 1, nspins
2317 CALL pw_axpy(rho_r(ispin), rhoout_r(ispin), -1.0_dp)
2318 CALL pw_axpy(rho_g(ispin), rhoout_g(ispin), -1.0_dp)
2319 CALL pw_axpy(rhoout_g(ispin), rhodn_tot_gspace)
2320 IF (dft_control%use_kinetic_energy_density)
CALL pw_axpy(tau_r(ispin), tauout_r(ispin), -1.0_dp)
2324 IF (use_virial)
THEN
2327 h_stress(:, :) = 0.0_dp
2328 CALL pw_poisson_solve(poisson_env, &
2329 density=rhodn_tot_gspace, &
2330 ehartree=dehartree, &
2331 vhartree=v_hartree_gspace, &
2332 h_stress=h_stress, &
2333 aux_density=rho_tot_gspace)
2335 CALL auxbas_pw_pool%give_back_pw(rho_tot_gspace)
2337 virial%pv_ehartree = virial%pv_ehartree + h_stress/real(para_env%num_pe, dp)
2338 virial%pv_virial = virial%pv_virial + h_stress/real(para_env%num_pe, dp)
2340 IF (debug_stress)
THEN
2341 stdeb = fconv*(h_stress/real(para_env%num_pe, dp))
2342 CALL para_env%sum(stdeb)
2343 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2344 'STRESS| GREEN 2nd V_H[dP]*n_in ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2349 CALL pw_poisson_solve(poisson_env, rhodn_tot_gspace, dehartree, &
2353 CALL pw_transfer(v_hartree_gspace, dv_hartree_rspace)
2354 CALL pw_scale(dv_hartree_rspace, dv_hartree_rspace%pw_grid%dvol)
2357 CALL pw_transfer(v_hartree_rspace, vtot_rspace)
2358 CALL pw_axpy(dv_hartree_rspace, vtot_rspace)
2359 IF (debug_forces) fodeb(1:3) = force(1)%rho_core(1:3, 1)
2360 IF (debug_stress .AND. use_virial) stdeb = virial%pv_ehartree
2361 CALL integrate_v_core_rspace(vtot_rspace, qs_env)
2362 IF (debug_forces)
THEN
2363 fodeb(1:3) = force(1)%rho_core(1:3, 1) - fodeb(1:3)
2364 CALL para_env%sum(fodeb)
2365 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Vtot*dncore", fodeb
2367 IF (debug_stress .AND. use_virial)
THEN
2368 stdeb = fconv*(virial%pv_ehartree - stdeb)
2369 CALL para_env%sum(stdeb)
2370 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2371 'STRESS| Vtot*dncore', one_third_sum_diag(stdeb), det_3x3(stdeb)
2377 xc_section => ec_env%xc_section
2379 IF (use_virial) virial%pv_xc = 0.0_dp
2380 NULLIFY (v_xc, v_xc_tau)
2381 NULLIFY (rho0_atom_set, rho1_atom_set)
2383 CALL qs_rho_create(rhoout)
2384 IF (
ASSOCIATED(rhoout_r))
THEN
2385 CALL qs_rho_set(rhoout, rho_r=rhoout_r, rho_r_valid=.true.)
2387 IF (
ASSOCIATED(rhoout_g))
THEN
2388 CALL qs_rho_set(rhoout, rho_g=rhoout_g, rho_g_valid=.true.)
2390 IF (
ASSOCIATED(tauout_r))
THEN
2391 CALL qs_rho_set(rhoout, tau_r=tauout_r, tau_r_valid=.true.)
2394 CALL qs_fxc_create(qs_env, rho, rhoout, rho0_atom_set, xc_section, .false., &
2395 v_xc, v_xc_tau, rho1_atom_set, &
2396 compute_virial=use_virial, virial_xc=virial%pv_xc)
2400 IF (use_virial)
THEN
2402 virial%pv_exc = virial%pv_exc + virial%pv_xc
2403 virial%pv_virial = virial%pv_virial + virial%pv_xc
2405 IF (debug_stress .AND. use_virial)
THEN
2406 stdeb = 1.0_dp*fconv*virial%pv_xc
2407 CALL para_env%sum(stdeb)
2408 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2409 'STRESS| GGA 2nd f_Hxc[dP]*Pin ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2412 CALL get_qs_env(qs_env=qs_env, rho=rho, matrix_s_kp=matrix_s)
2413 NULLIFY (ec_env%matrix_hz)
2414 CALL dbcsr_allocate_matrix_set(ec_env%matrix_hz, nspins)
2415 DO ispin = 1, nspins
2416 ALLOCATE (ec_env%matrix_hz(ispin)%matrix)
2417 CALL dbcsr_create(ec_env%matrix_hz(ispin)%matrix, template=matrix_s(1, 1)%matrix)
2418 CALL dbcsr_copy(ec_env%matrix_hz(ispin)%matrix, matrix_s(1, 1)%matrix)
2419 CALL dbcsr_set(ec_env%matrix_hz(ispin)%matrix, 0.0_dp)
2421 CALL qs_rho_get(rho, rho_ao_kp=matrix_p)
2423 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
2424 IF (debug_stress .AND. use_virial) stdeb = virial%pv_virial
2427 IF (use_virial)
THEN
2428 pv_loc = virial%pv_virial
2431 DO ispin = 1, nspins
2432 CALL pw_scale(v_xc(ispin), v_xc(ispin)%pw_grid%dvol)
2433 CALL pw_axpy(dv_hartree_rspace, v_xc(ispin))
2434 CALL integrate_v_rspace(v_rspace=v_xc(ispin), &
2435 hmat=ec_env%matrix_hz(ispin), &
2436 pmat=matrix_p(ispin, 1), &
2438 calculate_forces=.true.)
2441 IF (debug_forces)
THEN
2442 fodeb(1:3) = force(1)%rho_elec(1:3, 1) - fodeb(1:3)
2443 CALL para_env%sum(fodeb)
2444 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Pin*dKdrho", fodeb
2446 IF (debug_stress .AND. use_virial)
THEN
2447 stdeb = fconv*(virial%pv_virial - stdeb)
2448 CALL para_env%sum(stdeb)
2449 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2450 'STRESS| INT 2nd f_Hxc[dP]*Pin ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2453 IF (
ASSOCIATED(v_xc_tau))
THEN
2454 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
2455 IF (debug_stress .AND. use_virial) stdeb = virial%pv_virial
2457 DO ispin = 1, nspins
2458 CALL pw_scale(v_xc_tau(ispin), v_xc_tau(ispin)%pw_grid%dvol)
2459 CALL integrate_v_rspace(v_rspace=v_xc_tau(ispin), &
2460 hmat=ec_env%matrix_hz(ispin), &
2461 pmat=matrix_p(ispin, 1), &
2463 compute_tau=.true., &
2464 calculate_forces=.true.)
2467 IF (debug_forces)
THEN
2468 fodeb(1:3) = force(1)%rho_elec(1:3, 1) - fodeb(1:3)
2469 CALL para_env%sum(fodeb)
2470 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Pin*dKtaudtau", fodeb
2472 IF (debug_stress .AND. use_virial)
THEN
2473 stdeb = fconv*(virial%pv_virial - stdeb)
2474 CALL para_env%sum(stdeb)
2475 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2476 'STRESS| INT 2nd f_xctau[dP]*Pin ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2480 IF (use_virial)
THEN
2481 virial%pv_ehartree = virial%pv_ehartree + (virial%pv_virial - pv_loc)
2485 NULLIFY (v_rspace, v_tau_rspace)
2487 CALL qs_vxc_create(ks_env=ks_env, rho_struct=rho, xc_section=ec_env%xc_section, &
2488 vxc_rho=v_rspace, vxc_tau=v_tau_rspace, exc=eexc, just_energy=.false.)
2490 IF (use_virial)
THEN
2492 IF (
ASSOCIATED(v_rspace))
THEN
2493 DO ispin = 1, nspins
2495 eexc = eexc + pw_integral_ab(rhoout_r(ispin), v_rspace(ispin))
2498 IF (
ASSOCIATED(v_tau_rspace))
THEN
2499 DO ispin = 1, nspins
2501 eexc = eexc + pw_integral_ab(tauout_r(ispin), v_tau_rspace(ispin))
2506 IF (.NOT.
ASSOCIATED(v_rspace))
THEN
2507 ALLOCATE (v_rspace(nspins))
2508 DO ispin = 1, nspins
2509 CALL auxbas_pw_pool%create_pw(v_rspace(ispin))
2510 CALL pw_zero(v_rspace(ispin))
2516 IF (use_virial)
THEN
2517 pv_loc = virial%pv_virial
2520 dft_control%nimages = nhfimg
2524 CALL dbcsr_allocate_matrix_set(scrm, nspins, nhfimg)
2525 DO ispin = 1, nspins
2527 ALLOCATE (scrm(ispin, img)%matrix)
2528 CALL dbcsr_create(scrm(ispin, img)%matrix, template=ec_env%matrix_ks(ispin, img)%matrix)
2529 CALL dbcsr_copy(scrm(ispin, img)%matrix, ec_env%matrix_ks(ispin, img)%matrix)
2530 CALL dbcsr_set(scrm(ispin, img)%matrix, 0.0_dp)
2534 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
2535 IF (debug_stress .AND. use_virial) stdeb = virial%pv_virial
2536 DO ispin = 1, nspins
2538 CALL pw_scale(v_rspace(ispin), v_rspace(ispin)%pw_grid%dvol)
2539 CALL pw_axpy(v_hartree_rspace, v_rspace(ispin))
2541 rho_ao => ec_env%matrix_p(ispin, :)
2542 scrmat => scrm(ispin, :)
2543 CALL integrate_v_rspace(v_rspace=v_rspace(ispin), &
2547 calculate_forces=.true., &
2548 basis_type=
"HARRIS", &
2549 task_list_external=ec_env%task_list)
2552 IF (debug_forces)
THEN
2553 fodeb(1:3) = force(1)%rho_elec(1:3, 1) - fodeb(1:3)
2554 CALL para_env%sum(fodeb)
2555 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Pout*dVhxc ", fodeb
2557 IF (debug_stress .AND. use_virial)
THEN
2558 stdeb = fconv*(virial%pv_virial - stdeb)
2559 CALL para_env%sum(stdeb)
2560 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2561 'STRESS| INT Pout*dVhxc ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2565 IF (use_virial)
THEN
2566 virial%pv_ehartree = virial%pv_ehartree + (virial%pv_virial - pv_loc)
2570 dft_control%nimages = nimages
2572 IF (
ASSOCIATED(v_tau_rspace))
THEN
2573 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
2574 DO ispin = 1, nspins
2576 CALL pw_scale(v_tau_rspace(ispin), v_tau_rspace(ispin)%pw_grid%dvol)
2577 rho_ao => ec_env%matrix_p(ispin, :)
2578 scrmat => scrm(ispin, :)
2579 CALL integrate_v_rspace(v_rspace=v_tau_rspace(ispin), &
2583 calculate_forces=.true., &
2584 compute_tau=.true., &
2585 basis_type=
"HARRIS", &
2586 task_list_external=ec_env%task_list)
2588 IF (debug_forces)
THEN
2589 fodeb(1:3) = force(1)%rho_elec(1:3, 1) - fodeb(1:3)
2590 CALL para_env%sum(fodeb)
2591 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Pout*dVhxc_tau ", fodeb
2600 ec_hfx_sections => section_vals_get_subs_vals(qs_env%input,
"DFT%ENERGY_CORRECTION%XC%HF")
2601 CALL section_vals_get(ec_hfx_sections, explicit=do_ec_hfx)
2605 IF (ec_env%do_kpoints)
THEN
2606 CALL cp_abort(__location__,
"HFX and K-points NYI for energy correction")
2609 IF (debug_forces) fodeb(1:3) = force(1)%fock_4c(1:3, 1)
2610 IF (use_virial) virial%pv_fock_4c = 0.0_dp
2612 CALL calculate_exx(qs_env=qs_env, &
2614 hfx_sections=ec_hfx_sections, &
2615 x_data=ec_env%x_data, &
2617 do_admm=ec_env%do_ec_admm, &
2618 calc_forces=.true., &
2619 reuse_hfx=ec_env%reuse_hfx, &
2620 do_im_time=.false., &
2621 e_ex_from_gw=dummy_real, &
2622 e_admm_from_gw=dummy_real2, &
2625 IF (use_virial)
THEN
2626 virial%pv_exx = virial%pv_exx - virial%pv_fock_4c
2627 virial%pv_virial = virial%pv_virial - virial%pv_fock_4c
2628 virial%pv_calculate = .false.
2630 IF (debug_forces)
THEN
2631 fodeb(1:3) = force(1)%fock_4c(1:3, 1) - fodeb(1:3)
2632 CALL para_env%sum(fodeb)
2633 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Pout*hfx ", fodeb
2635 IF (debug_stress .AND. use_virial)
THEN
2636 stdeb = -1.0_dp*fconv*virial%pv_fock_4c
2637 CALL para_env%sum(stdeb)
2638 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2639 'STRESS| Pout*hfx ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2645 CALL dbcsr_deallocate_matrix_set(scrm)
2648 CALL auxbas_pw_pool%give_back_pw(v_hartree_rspace)
2649 DO ispin = 1, nspins
2650 CALL auxbas_pw_pool%give_back_pw(v_rspace(ispin))
2651 IF (
ASSOCIATED(v_tau_rspace))
THEN
2652 CALL auxbas_pw_pool%give_back_pw(v_tau_rspace(ispin))
2655 IF (
ASSOCIATED(v_tau_rspace))
DEALLOCATE (v_tau_rspace)
2658 IF (debug_forces) fodeb(1:3) = force(1)%core_overlap(1:3, 1)
2659 IF (debug_stress .AND. use_virial) stdeb = virial%pv_ecore_overlap
2660 CALL calculate_ecore_overlap(qs_env, para_env, .true., e_overlap_core=eovrl)
2661 IF (debug_forces)
THEN
2662 fodeb(1:3) = force(1)%core_overlap(1:3, 1) - fodeb(1:3)
2663 CALL para_env%sum(fodeb)
2664 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: CoreOverlap", fodeb
2666 IF (debug_stress .AND. use_virial)
THEN
2667 stdeb = fconv*(stdeb - virial%pv_ecore_overlap)
2668 CALL para_env%sum(stdeb)
2669 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2670 'STRESS| CoreOverlap ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2673 IF (debug_forces)
THEN
2674 CALL get_qs_env(qs_env, natom=natom, atomic_kind_set=atomic_kind_set)
2675 ALLOCATE (ftot(3, natom))
2676 CALL total_qs_force(ftot, force, atomic_kind_set)
2677 fodeb(1:3) = ftot(1:3, 1)
2679 CALL para_env%sum(fodeb)
2680 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Force Explicit", fodeb
2683 DEALLOCATE (v_rspace)
2685 CALL auxbas_pw_pool%give_back_pw(dv_hartree_rspace)
2686 CALL auxbas_pw_pool%give_back_pw(vtot_rspace)
2687 DO ispin = 1, nspins
2688 CALL auxbas_pw_pool%give_back_pw(rhoout_r(ispin))
2689 CALL auxbas_pw_pool%give_back_pw(rhoout_g(ispin))
2690 CALL auxbas_pw_pool%give_back_pw(v_xc(ispin))
2692 DEALLOCATE (rhoout_r, rhoout_g, v_xc)
2693 IF (
ASSOCIATED(tauout_r))
THEN
2694 DO ispin = 1, nspins
2695 CALL auxbas_pw_pool%give_back_pw(tauout_r(ispin))
2697 DEALLOCATE (tauout_r)
2699 IF (
ASSOCIATED(v_xc_tau))
THEN
2700 DO ispin = 1, nspins
2701 CALL auxbas_pw_pool%give_back_pw(v_xc_tau(ispin))
2703 DEALLOCATE (v_xc_tau)
2705 CALL auxbas_pw_pool%give_back_pw(v_hartree_gspace)
2706 CALL auxbas_pw_pool%give_back_pw(rhodn_tot_gspace)
2710 IF (use_virial)
THEN
2711 IF (qs_env%energy_correction)
THEN
2712 ec_env%ehartree = ehartree + dehartree
2713 ec_env%exc = exc + eexc
2717 IF (debug_stress .AND. use_virial)
THEN
2719 stdeb = -1.0_dp*fconv*ehartree
2720 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2721 'STRESS| VOL 1st v_H[n_in]*n_out', one_third_sum_diag(stdeb), det_3x3(stdeb)
2723 stdeb = -1.0_dp*fconv*exc
2724 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2725 'STRESS| VOL 1st E_XC[n_in]', one_third_sum_diag(stdeb), det_3x3(stdeb)
2727 stdeb = -1.0_dp*fconv*dehartree
2728 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2729 'STRESS| VOL 2nd v_H[dP]*n_in', one_third_sum_diag(stdeb), det_3x3(stdeb)
2731 stdeb = -1.0_dp*fconv*eexc
2732 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2733 'STRESS| VOL 2nd v_XC[n_in]*dP', one_third_sum_diag(stdeb), det_3x3(stdeb)
2738 TYPE(virial_type) :: virdeb
2741 CALL para_env%sum(virdeb%pv_overlap)
2742 CALL para_env%sum(virdeb%pv_ekinetic)
2743 CALL para_env%sum(virdeb%pv_ppl)
2744 CALL para_env%sum(virdeb%pv_ppnl)
2745 CALL para_env%sum(virdeb%pv_ecore_overlap)
2746 CALL para_env%sum(virdeb%pv_ehartree)
2747 CALL para_env%sum(virdeb%pv_exc)
2748 CALL para_env%sum(virdeb%pv_exx)
2749 CALL para_env%sum(virdeb%pv_vdw)
2750 CALL para_env%sum(virdeb%pv_mp2)
2751 CALL para_env%sum(virdeb%pv_nlcc)
2752 CALL para_env%sum(virdeb%pv_gapw)
2753 CALL para_env%sum(virdeb%pv_lrigpw)
2754 CALL para_env%sum(virdeb%pv_virial)
2755 CALL symmetrize_virial(virdeb)
2759 virdeb%pv_ehartree(i, i) = virdeb%pv_ehartree(i, i) - 2.0_dp*(ehartree + dehartree)
2760 virdeb%pv_virial(i, i) = virdeb%pv_virial(i, i) - exc - eexc &
2761 - 2.0_dp*(ehartree + dehartree)
2762 virdeb%pv_exc(i, i) = virdeb%pv_exc(i, i) - exc - eexc
2768 CALL para_env%sum(sttot)
2769 stdeb = fconv*(virdeb%pv_virial - sttot)
2770 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2771 'STRESS| Explicit electronic stress ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2773 stdeb = fconv*(virdeb%pv_virial)
2774 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2775 'STRESS| Explicit total stress ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2777 CALL write_stress_tensor_components(virdeb, iounit, cell, unit_string)
2778 CALL write_stress_tensor(virdeb%pv_virial, iounit, cell, unit_string, .false.)
2783 CALL timestop(handle)
2785 END SUBROUTINE ec_build_ks_matrix_force
2795 SUBROUTINE ec_ks_solver(qs_env, ec_env)
2797 TYPE(qs_environment_type),
POINTER :: qs_env
2798 TYPE(energy_correction_type),
POINTER :: ec_env
2800 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ec_ks_solver'
2802 CHARACTER(LEN=default_string_length) :: headline
2803 INTEGER :: handle, img, ispin, nhfimg, nspins
2804 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: ksmat, pmat, smat, wmat
2805 TYPE(dbcsr_type),
POINTER :: tsmat
2806 TYPE(dft_control_type),
POINTER :: dft_control
2808 CALL timeset(routinen, handle)
2810 CALL get_qs_env(qs_env=qs_env, dft_control=dft_control)
2811 nspins = dft_control%nspins
2812 nhfimg =
SIZE(ec_env%matrix_s, 2)
2815 IF (.NOT.
ASSOCIATED(ec_env%matrix_p))
THEN
2816 headline =
"DENSITY MATRIX"
2817 CALL dbcsr_allocate_matrix_set(ec_env%matrix_p, nspins, nhfimg)
2818 DO ispin = 1, nspins
2820 tsmat => ec_env%matrix_s(1, img)%matrix
2821 ALLOCATE (ec_env%matrix_p(ispin, img)%matrix)
2822 CALL dbcsr_create(ec_env%matrix_p(ispin, img)%matrix, &
2823 name=trim(headline), template=tsmat)
2824 CALL cp_dbcsr_alloc_block_from_nbl(ec_env%matrix_p(ispin, img)%matrix, &
2830 IF (.NOT.
ASSOCIATED(ec_env%matrix_w))
THEN
2831 headline =
"ENERGY WEIGHTED DENSITY MATRIX"
2832 CALL dbcsr_allocate_matrix_set(ec_env%matrix_w, nspins, nhfimg)
2833 DO ispin = 1, nspins
2835 tsmat => ec_env%matrix_s(1, img)%matrix
2836 ALLOCATE (ec_env%matrix_w(ispin, img)%matrix)
2837 CALL dbcsr_create(ec_env%matrix_w(ispin, img)%matrix, &
2838 name=trim(headline), template=tsmat)
2839 CALL cp_dbcsr_alloc_block_from_nbl(ec_env%matrix_w(ispin, img)%matrix, &
2845 IF (ec_env%mao)
THEN
2846 CALL mao_create_matrices(ec_env, ksmat, smat, pmat, wmat)
2848 ksmat => ec_env%matrix_ks
2849 smat => ec_env%matrix_s
2850 pmat => ec_env%matrix_p
2851 wmat => ec_env%matrix_w
2854 IF (ec_env%do_kpoints)
THEN
2855 IF (ec_env%ks_solver /= ec_diagonalization)
THEN
2856 CALL cp_abort(__location__,
"Harris functional with k-points "// &
2857 "needs diagonalization solver")
2861 SELECT CASE (ec_env%ks_solver)
2862 CASE (ec_diagonalization)
2863 IF (ec_env%do_kpoints)
THEN
2864 CALL ec_diag_solver_kp(qs_env, ec_env, ksmat, smat, pmat, wmat)
2866 CALL ec_diag_solver_gamma(qs_env, ec_env, ksmat, smat, pmat, wmat)
2869 CALL ec_ot_diag_solver(qs_env, ec_env, ksmat, smat, pmat, wmat)
2870 CASE (ec_matrix_sign, ec_matrix_trs4, ec_matrix_tc2)
2871 CALL ec_ls_init(qs_env, ksmat, smat)
2872 CALL ec_ls_solver(qs_env, pmat, wmat, ec_ls_method=ec_env%ks_solver)
2874 cpabort(
"Option invalid or unavailable for ec_env%ks_solver")
2877 IF (ec_env%mao)
THEN
2878 CALL mao_release_matrices(ec_env, ksmat, smat, pmat, wmat)
2881 CALL timestop(handle)
2883 END SUBROUTINE ec_ks_solver
2896 SUBROUTINE mao_create_matrices(ec_env, ksmat, smat, pmat, wmat)
2898 TYPE(energy_correction_type),
POINTER :: ec_env
2899 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: ksmat, smat, pmat, wmat
2901 CHARACTER(LEN=*),
PARAMETER :: routinen =
'mao_create_matrices'
2903 INTEGER :: handle, ispin, nspins
2904 INTEGER,
DIMENSION(:),
POINTER :: col_blk_sizes
2905 TYPE(dbcsr_distribution_type) :: dbcsr_dist
2906 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: mao_coef
2907 TYPE(dbcsr_type) :: cgmat
2909 CALL timeset(routinen, handle)
2911 mao_coef => ec_env%mao_coef
2913 NULLIFY (ksmat, smat, pmat, wmat)
2914 nspins =
SIZE(ec_env%matrix_ks, 1)
2915 CALL dbcsr_get_info(mao_coef(1)%matrix, col_blk_size=col_blk_sizes, distribution=dbcsr_dist)
2916 CALL dbcsr_allocate_matrix_set(ksmat, nspins, 1)
2917 CALL dbcsr_allocate_matrix_set(smat, nspins, 1)
2918 DO ispin = 1, nspins
2919 ALLOCATE (ksmat(ispin, 1)%matrix)
2920 CALL dbcsr_create(ksmat(ispin, 1)%matrix, dist=dbcsr_dist, name=
"MAO KS mat", &
2921 matrix_type=dbcsr_type_symmetric, row_blk_size=col_blk_sizes, &
2922 col_blk_size=col_blk_sizes)
2923 ALLOCATE (smat(ispin, 1)%matrix)
2924 CALL dbcsr_create(smat(ispin, 1)%matrix, dist=dbcsr_dist, name=
"MAO S mat", &
2925 matrix_type=dbcsr_type_symmetric, row_blk_size=col_blk_sizes, &
2926 col_blk_size=col_blk_sizes)
2929 CALL dbcsr_create(cgmat, name=
"TEMP matrix", template=mao_coef(1)%matrix)
2930 DO ispin = 1, nspins
2931 CALL dbcsr_multiply(
"N",
"N", 1.0_dp, ec_env%matrix_s(1, 1)%matrix, mao_coef(ispin)%matrix, &
2933 CALL dbcsr_multiply(
"T",
"N", 1.0_dp, mao_coef(ispin)%matrix, cgmat, 0.0_dp, smat(ispin, 1)%matrix)
2934 CALL dbcsr_multiply(
"N",
"N", 1.0_dp, ec_env%matrix_ks(1, 1)%matrix, mao_coef(ispin)%matrix, &
2936 CALL dbcsr_multiply(
"T",
"N", 1.0_dp, mao_coef(ispin)%matrix, cgmat, 0.0_dp, ksmat(ispin, 1)%matrix)
2938 CALL dbcsr_release(cgmat)
2940 CALL dbcsr_allocate_matrix_set(pmat, nspins, 1)
2941 DO ispin = 1, nspins
2942 ALLOCATE (pmat(ispin, 1)%matrix)
2943 CALL dbcsr_create(pmat(ispin, 1)%matrix, template=smat(1, 1)%matrix, name=
"MAO P mat")
2944 CALL cp_dbcsr_alloc_block_from_nbl(pmat(ispin, 1)%matrix, ec_env%sab_orb)
2947 CALL dbcsr_allocate_matrix_set(wmat, nspins, 1)
2948 DO ispin = 1, nspins
2949 ALLOCATE (wmat(ispin, 1)%matrix)
2950 CALL dbcsr_create(wmat(ispin, 1)%matrix, template=smat(1, 1)%matrix, name=
"MAO W mat")
2951 CALL cp_dbcsr_alloc_block_from_nbl(wmat(ispin, 1)%matrix, ec_env%sab_orb)
2954 CALL timestop(handle)
2956 END SUBROUTINE mao_create_matrices
2969 SUBROUTINE mao_release_matrices(ec_env, ksmat, smat, pmat, wmat)
2971 TYPE(energy_correction_type),
POINTER :: ec_env
2972 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: ksmat, smat, pmat, wmat
2974 CHARACTER(LEN=*),
PARAMETER :: routinen =
'mao_release_matrices'
2976 INTEGER :: handle, ispin, nspins
2977 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: mao_coef
2978 TYPE(dbcsr_type) :: cgmat
2980 CALL timeset(routinen, handle)
2982 mao_coef => ec_env%mao_coef
2983 nspins =
SIZE(mao_coef, 1)
2986 CALL dbcsr_create(cgmat, name=
"TEMP matrix", template=mao_coef(1)%matrix)
2987 DO ispin = 1, nspins
2988 CALL dbcsr_multiply(
"N",
"N", 1.0_dp, mao_coef(ispin)%matrix, pmat(ispin, 1)%matrix, 0.0_dp, cgmat)
2989 CALL dbcsr_multiply(
"N",
"T", 1.0_dp, mao_coef(ispin)%matrix, cgmat, 0.0_dp, &
2990 ec_env%matrix_p(ispin, 1)%matrix, retain_sparsity=.true.)
2991 CALL dbcsr_multiply(
"N",
"N", 1.0_dp, mao_coef(ispin)%matrix, wmat(ispin, 1)%matrix, 0.0_dp, cgmat)
2992 CALL dbcsr_multiply(
"N",
"T", 1.0_dp, mao_coef(ispin)%matrix, cgmat, 0.0_dp, &
2993 ec_env%matrix_w(ispin, 1)%matrix, retain_sparsity=.true.)
2995 CALL dbcsr_release(cgmat)
2997 CALL dbcsr_deallocate_matrix_set(ksmat)
2998 CALL dbcsr_deallocate_matrix_set(smat)
2999 CALL dbcsr_deallocate_matrix_set(pmat)
3000 CALL dbcsr_deallocate_matrix_set(wmat)
3002 CALL timestop(handle)
3004 END SUBROUTINE mao_release_matrices
3012 SUBROUTINE ec_energy(ec_env, unit_nr)
3013 TYPE(energy_correction_type) :: ec_env
3014 INTEGER,
INTENT(IN) :: unit_nr
3016 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ec_energy'
3018 INTEGER :: handle, nspins
3019 REAL(kind=dp) :: eband, trace
3021 CALL timeset(routinen, handle)
3023 nspins =
SIZE(ec_env%matrix_p, 1)
3024 CALL calculate_ptrace(ec_env%matrix_s, ec_env%matrix_p, trace, nspins)
3025 IF (unit_nr > 0)
WRITE (unit_nr,
'(T3,A,T65,F16.10)')
'Tr[PS] ', trace
3028 SELECT CASE (ec_env%energy_functional)
3029 CASE (ec_functional_harris)
3032 CALL calculate_ptrace(ec_env%matrix_ks, ec_env%matrix_p, eband, nspins, .true.)
3033 ec_env%eband = eband + ec_env%efield_nuclear
3036 ec_env%etotal = ec_env%eband + ec_env%ehartree + ec_env%exc - ec_env%vhxc + ec_env%ekTS + &
3037 ec_env%edispersion - ec_env%ex
3038 IF (unit_nr > 0)
THEN
3039 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Eband ", ec_env%eband
3040 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Ehartree ", ec_env%ehartree
3041 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Exc ", ec_env%exc
3042 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Ex ", ec_env%ex
3043 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Evhxc ", ec_env%vhxc
3044 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Edisp ", ec_env%edispersion
3045 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Entropy ", ec_env%ekTS
3046 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Etotal Harris Functional ", ec_env%etotal
3049 CASE (ec_functional_dc)
3052 CALL calculate_ptrace(ec_env%matrix_h, ec_env%matrix_p, ec_env%ecore, nspins)
3054 ec_env%ecore = ec_env%ecore + ec_env%efield_nuclear
3055 ec_env%etotal = ec_env%ecore + ec_env%ehartree + ec_env%ehartree_1c + &
3056 ec_env%exc + ec_env%exc1 + ec_env%ekTS + ec_env%edispersion + &
3057 ec_env%ex + ec_env%exc_aux_fit + ec_env%exc1_aux_fit
3059 IF (unit_nr > 0)
THEN
3060 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Ecore ", ec_env%ecore
3061 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Ehartree ", ec_env%ehartree + ec_env%ehartree_1c
3062 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Exc ", ec_env%exc + ec_env%exc1
3063 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Ex ", ec_env%ex
3064 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Exc_aux_fit", ec_env%exc_aux_fit + ec_env%exc1_aux_fit
3065 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Edisp ", ec_env%edispersion
3066 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Entropy ", ec_env%ekTS
3067 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Etotal Energy Functional ", ec_env%etotal
3070 CASE (ec_functional_ext)
3072 ec_env%etotal = ec_env%ex
3073 IF (unit_nr > 0)
THEN
3074 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Etotal Energy Functional ", ec_env%etotal
3079 cpabort(
"Option invalid or unavailable for ec_env%energy_functional")
3083 CALL timestop(handle)
3085 END SUBROUTINE ec_energy
3097 SUBROUTINE ec_build_neighborlist(qs_env, ec_env)
3098 TYPE(qs_environment_type),
POINTER :: qs_env
3099 TYPE(energy_correction_type),
POINTER :: ec_env
3101 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ec_build_neighborlist'
3103 INTEGER :: handle, ikind, nimages, nkind, zat
3104 LOGICAL :: all_potential_present, gth_potential_present, paw_atom, paw_atom_present, &
3105 sgp_potential_present, skip_load_balance_distributed
3106 LOGICAL,
ALLOCATABLE,
DIMENSION(:) :: all_present, default_present, &
3107 oce_present, orb_present, ppl_present, &
3109 REAL(dp) :: subcells
3110 REAL(dp),
ALLOCATABLE,
DIMENSION(:) :: all_radius, c_radius, oce_radius, &
3111 orb_radius, ppl_radius, ppnl_radius
3112 REAL(dp),
ALLOCATABLE,
DIMENSION(:, :) :: pair_radius
3113 TYPE(all_potential_type),
POINTER :: all_potential
3114 TYPE(atomic_kind_type),
DIMENSION(:),
POINTER :: atomic_kind_set
3115 TYPE(cell_type),
POINTER :: cell
3116 TYPE(dft_control_type),
POINTER :: dft_control
3117 TYPE(distribution_1d_type),
POINTER :: distribution_1d
3118 TYPE(distribution_2d_type),
POINTER :: distribution_2d
3119 TYPE(gth_potential_type),
POINTER :: gth_potential
3120 TYPE(gto_basis_set_type),
POINTER :: basis_set
3121 TYPE(local_atoms_type),
ALLOCATABLE,
DIMENSION(:) :: atom2d
3122 TYPE(molecule_type),
DIMENSION(:),
POINTER :: molecule_set
3123 TYPE(mp_para_env_type),
POINTER :: para_env
3124 TYPE(neighbor_list_set_p_type),
DIMENSION(:), &
3125 POINTER :: sab_cn, sab_vdw
3126 TYPE(particle_type),
DIMENSION(:),
POINTER :: particle_set
3127 TYPE(paw_proj_set_type),
POINTER :: paw_proj
3128 TYPE(qs_dispersion_type),
POINTER :: dispersion_env
3129 TYPE(qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
3130 TYPE(qs_kind_type),
POINTER :: qs_kind
3131 TYPE(qs_ks_env_type),
POINTER :: ks_env
3132 TYPE(sgp_potential_type),
POINTER :: sgp_potential
3134 CALL timeset(routinen, handle)
3136 CALL get_qs_env(qs_env=qs_env, qs_kind_set=qs_kind_set)
3137 CALL get_qs_kind_set(qs_kind_set, &
3138 paw_atom_present=paw_atom_present, &
3139 all_potential_present=all_potential_present, &
3140 gth_potential_present=gth_potential_present, &
3141 sgp_potential_present=sgp_potential_present)
3142 nkind =
SIZE(qs_kind_set)
3143 ALLOCATE (c_radius(nkind), default_present(nkind))
3144 ALLOCATE (orb_radius(nkind), all_radius(nkind), ppl_radius(nkind), ppnl_radius(nkind))
3145 ALLOCATE (orb_present(nkind), all_present(nkind), ppl_present(nkind), ppnl_present(nkind))
3146 ALLOCATE (pair_radius(nkind, nkind))
3147 ALLOCATE (atom2d(nkind))
3149 CALL get_qs_env(qs_env, &
3150 atomic_kind_set=atomic_kind_set, &
3152 distribution_2d=distribution_2d, &
3153 local_particles=distribution_1d, &
3154 particle_set=particle_set, &
3155 molecule_set=molecule_set)
3157 CALL atom2d_build(atom2d, distribution_1d, distribution_2d, atomic_kind_set, &
3158 molecule_set, .false., particle_set)
3161 CALL get_atomic_kind(atomic_kind_set(ikind), atom_list=atom2d(ikind)%list)
3162 qs_kind => qs_kind_set(ikind)
3163 CALL get_qs_kind(qs_kind=qs_kind, basis_set=basis_set, basis_type=
"HARRIS")
3164 IF (
ASSOCIATED(basis_set))
THEN
3165 orb_present(ikind) = .true.
3166 CALL get_gto_basis_set(gto_basis_set=basis_set, kind_radius=orb_radius(ikind))
3168 orb_present(ikind) = .false.
3169 orb_radius(ikind) = 0.0_dp
3171 CALL get_qs_kind(qs_kind, all_potential=all_potential, &
3172 gth_potential=gth_potential, sgp_potential=sgp_potential)
3173 IF (gth_potential_present .OR. sgp_potential_present)
THEN
3174 IF (
ASSOCIATED(gth_potential))
THEN
3175 CALL get_potential(potential=gth_potential, &
3176 ppl_present=ppl_present(ikind), &
3177 ppl_radius=ppl_radius(ikind), &
3178 ppnl_present=ppnl_present(ikind), &
3179 ppnl_radius=ppnl_radius(ikind))
3180 ELSE IF (
ASSOCIATED(sgp_potential))
THEN
3181 CALL get_potential(potential=sgp_potential, &
3182 ppl_present=ppl_present(ikind), &
3183 ppl_radius=ppl_radius(ikind), &
3184 ppnl_present=ppnl_present(ikind), &
3185 ppnl_radius=ppnl_radius(ikind))
3187 ppl_present(ikind) = .false.
3188 ppl_radius(ikind) = 0.0_dp
3189 ppnl_present(ikind) = .false.
3190 ppnl_radius(ikind) = 0.0_dp
3194 IF (all_potential_present .OR. sgp_potential_present)
THEN
3195 all_present(ikind) = .false.
3196 all_radius(ikind) = 0.0_dp
3197 IF (
ASSOCIATED(all_potential))
THEN
3198 all_present(ikind) = .true.
3199 CALL get_potential(potential=all_potential, core_charge_radius=all_radius(ikind))
3200 ELSE IF (
ASSOCIATED(sgp_potential))
THEN
3201 IF (sgp_potential%ecp_local)
THEN
3202 all_present(ikind) = .true.
3203 CALL get_potential(potential=sgp_potential, core_charge_radius=all_radius(ikind))
3209 CALL section_vals_val_get(qs_env%input,
"DFT%SUBCELLS", r_val=subcells)
3212 CALL pair_radius_setup(orb_present, orb_present, orb_radius, orb_radius, pair_radius)
3213 CALL build_neighbor_lists(ec_env%sab_orb, particle_set, atom2d, cell, pair_radius, &
3214 subcells=subcells, nlname=
"sab_orb")
3216 IF (ec_env%do_kpoints)
THEN
3218 CALL build_neighbor_lists(ec_env%sab_kp, particle_set, atom2d, cell, pair_radius, &
3219 subcells=subcells, nlname=
"sab_kp")
3220 IF (ec_env%do_ec_hfx)
THEN
3221 CALL build_neighbor_lists(ec_env%sab_kp_nosym, particle_set, atom2d, cell, pair_radius, &
3222 subcells=subcells, nlname=
"sab_kp_nosym", symmetric=.false.)
3224 CALL get_qs_env(qs_env=qs_env, para_env=para_env)
3225 CALL kpoint_init_cell_index(ec_env%kpoints, ec_env%sab_kp, para_env, nimages)
3229 IF (all_potential_present .OR. sgp_potential_present)
THEN
3230 IF (any(all_present))
THEN
3231 CALL pair_radius_setup(orb_present, all_present, orb_radius, all_radius, pair_radius)
3232 CALL build_neighbor_lists(ec_env%sac_ae, particle_set, atom2d, cell, pair_radius, &
3233 subcells=subcells, operator_type=
"ABC", nlname=
"sac_ae")
3237 IF (gth_potential_present .OR. sgp_potential_present)
THEN
3238 IF (any(ppl_present))
THEN
3239 CALL pair_radius_setup(orb_present, ppl_present, orb_radius, ppl_radius, pair_radius)
3240 CALL build_neighbor_lists(ec_env%sac_ppl, particle_set, atom2d, cell, pair_radius, &
3241 subcells=subcells, operator_type=
"ABC", nlname=
"sac_ppl")
3244 IF (any(ppnl_present))
THEN
3245 CALL pair_radius_setup(orb_present, ppnl_present, orb_radius, ppnl_radius, pair_radius)
3246 CALL build_neighbor_lists(ec_env%sap_ppnl, particle_set, atom2d, cell, pair_radius, &
3247 subcells=subcells, operator_type=
"ABBA", nlname=
"sap_ppnl")
3252 c_radius(:) = 0.0_dp
3253 dispersion_env => ec_env%dispersion_env
3254 sab_vdw => dispersion_env%sab_vdw
3255 sab_cn => dispersion_env%sab_cn
3256 IF (dispersion_env%type == xc_vdw_fun_pairpot)
THEN
3257 c_radius(:) = dispersion_env%rc_disp
3258 default_present = .true.
3259 CALL pair_radius_setup(default_present, default_present, c_radius, c_radius, pair_radius)
3260 CALL build_neighbor_lists(sab_vdw, particle_set, atom2d, cell, pair_radius, &
3261 subcells=subcells, operator_type=
"PP", nlname=
"sab_vdw")
3262 dispersion_env%sab_vdw => sab_vdw
3263 IF (dispersion_env%pp_type == vdw_pairpot_dftd3 .OR. &
3264 dispersion_env%pp_type == vdw_pairpot_dftd3bj)
THEN
3267 CALL get_atomic_kind(atomic_kind_set(ikind), z=zat)
3268 c_radius(ikind) = 4._dp*ptable(zat)%covalent_radius*bohr
3270 CALL pair_radius_setup(default_present, default_present, c_radius, c_radius, pair_radius)
3271 CALL build_neighbor_lists(sab_cn, particle_set, atom2d, cell, pair_radius, &
3272 subcells=subcells, operator_type=
"PP", nlname=
"sab_cn")
3273 dispersion_env%sab_cn => sab_cn
3278 IF (paw_atom_present)
THEN
3279 IF (paw_atom_present)
THEN
3280 ALLOCATE (oce_present(nkind), oce_radius(nkind))
3285 CALL get_qs_kind(qs_kind_set(ikind), paw_proj_set=paw_proj, paw_atom=paw_atom)
3287 oce_present(ikind) = .true.
3288 CALL get_paw_proj_set(paw_proj_set=paw_proj, rcprj=oce_radius(ikind))
3290 oce_present(ikind) = .false.
3295 IF (any(oce_present))
THEN
3296 CALL pair_radius_setup(orb_present, oce_present, orb_radius, oce_radius, pair_radius)
3297 CALL build_neighbor_lists(ec_env%sap_oce, particle_set, atom2d, cell, pair_radius, &
3298 subcells=subcells, operator_type=
"ABBA", nlname=
"sap_oce")
3300 DEALLOCATE (oce_present, oce_radius)
3304 CALL atom2d_cleanup(atom2d)
3306 DEALLOCATE (orb_present, default_present, all_present, ppl_present, ppnl_present)
3307 DEALLOCATE (orb_radius, all_radius, ppl_radius, ppnl_radius, c_radius)
3308 DEALLOCATE (pair_radius)
3311 CALL get_qs_env(qs_env, ks_env=ks_env, dft_control=dft_control)
3312 skip_load_balance_distributed = dft_control%qs_control%skip_load_balance_distributed
3313 IF (
ASSOCIATED(ec_env%task_list))
CALL deallocate_task_list(ec_env%task_list)
3314 CALL allocate_task_list(ec_env%task_list)
3315 CALL generate_qs_task_list(ks_env, ec_env%task_list, basis_type=
"HARRIS", &
3316 reorder_rs_grid_ranks=.false., &
3317 skip_load_balance_distributed=skip_load_balance_distributed, &
3318 sab_orb_external=ec_env%sab_orb, &
3319 ext_kpoints=ec_env%kpoints)
3321 IF (dft_control%qs_control%gapw .OR. dft_control%qs_control%gapw_xc)
THEN
3322 IF (
ASSOCIATED(ec_env%task_list_soft))
CALL deallocate_task_list(ec_env%task_list_soft)
3323 CALL allocate_task_list(ec_env%task_list_soft)
3324 CALL generate_qs_task_list(ks_env, ec_env%task_list_soft, basis_type=
"HARRIS_SOFT", &
3325 reorder_rs_grid_ranks=.false., &
3326 skip_load_balance_distributed=skip_load_balance_distributed, &
3327 sab_orb_external=ec_env%sab_orb, &
3328 ext_kpoints=ec_env%kpoints)
3331 CALL timestop(handle)
3333 END SUBROUTINE ec_build_neighborlist
3340 SUBROUTINE ec_properties(qs_env, ec_env)
3341 TYPE(qs_environment_type),
POINTER :: qs_env
3342 TYPE(energy_correction_type),
POINTER :: ec_env
3344 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ec_properties'
3346 CHARACTER(LEN=8),
DIMENSION(3) :: rlab
3347 CHARACTER(LEN=default_path_length) :: filename, my_pos_voro
3348 CHARACTER(LEN=default_string_length) :: description
3349 INTEGER :: akind, handle, i, ia, iatom, idir, ikind, iounit, ispin, maxmom, nspins, &
3350 reference, should_print_bqb, should_print_voro, unit_nr, unit_nr_voro
3351 LOGICAL :: append_voro, magnetic, periodic, &
3353 REAL(kind=dp) :: charge, dd, focc, tmp
3354 REAL(kind=dp),
DIMENSION(3) :: cdip, pdip, rcc, rdip, ria, tdip
3355 REAL(kind=dp),
DIMENSION(:),
POINTER :: ref_point
3356 TYPE(atomic_kind_type),
POINTER :: atomic_kind
3357 TYPE(cell_type),
POINTER :: cell
3358 TYPE(cp_logger_type),
POINTER :: logger
3359 TYPE(cp_result_type),
POINTER :: results
3360 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_s, moments
3361 TYPE(dft_control_type),
POINTER :: dft_control
3362 TYPE(distribution_1d_type),
POINTER :: local_particles
3363 TYPE(mp_para_env_type),
POINTER :: para_env
3364 TYPE(particle_type),
DIMENSION(:),
POINTER :: particle_set
3365 TYPE(pw_env_type),
POINTER :: pw_env
3366 TYPE(pw_pool_p_type),
DIMENSION(:),
POINTER :: pw_pools
3367 TYPE(pw_pool_type),
POINTER :: auxbas_pw_pool
3368 TYPE(pw_r3d_rs_type) :: rho_elec_rspace
3369 TYPE(qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
3370 TYPE(section_vals_type),
POINTER :: ec_section, print_key, print_key_bqb, &
3373 CALL timeset(routinen, handle)
3379 logger => cp_get_default_logger()
3380 IF (logger%para_env%is_source())
THEN
3381 iounit = cp_logger_get_default_unit_nr(logger, local=.true.)
3386 NULLIFY (dft_control)
3387 CALL get_qs_env(qs_env, dft_control=dft_control)
3388 nspins = dft_control%nspins
3390 ec_section => section_vals_get_subs_vals(qs_env%input,
"DFT%ENERGY_CORRECTION")
3391 print_key => section_vals_get_subs_vals(section_vals=ec_section, &
3392 subsection_name=
"PRINT%MOMENTS")
3394 IF (btest(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file))
THEN
3396 IF (dft_control%qs_control%gapw .OR. dft_control%qs_control%gapw_xc)
THEN
3397 cpabort(
"Properties for GAPW in EC NYA")
3400 maxmom = section_get_ival(section_vals=ec_section, &
3401 keyword_name=
"PRINT%MOMENTS%MAX_MOMENT")
3402 periodic = section_get_lval(section_vals=ec_section, &
3403 keyword_name=
"PRINT%MOMENTS%PERIODIC")
3404 reference = section_get_ival(section_vals=ec_section, &
3405 keyword_name=
"PRINT%MOMENTS%REFERENCE")
3406 magnetic = section_get_lval(section_vals=ec_section, &
3407 keyword_name=
"PRINT%MOMENTS%MAGNETIC")
3409 CALL section_vals_val_get(ec_section,
"PRINT%MOMENTS%REF_POINT", r_vals=ref_point)
3410 unit_nr = cp_print_key_unit_nr(logger=logger, basis_section=ec_section, &
3411 print_key_path=
"PRINT%MOMENTS", extension=
".dat", &
3412 middle_name=
"moments", log_filename=.false.)
3414 IF (iounit > 0)
THEN
3415 IF (unit_nr /= iounit .AND. unit_nr > 0)
THEN
3416 INQUIRE (unit=unit_nr, name=filename)
3417 WRITE (unit=iounit, fmt=
"(/,T2,A,2(/,T3,A),/)") &
3418 "MOMENTS",
"The electric/magnetic moments are written to file:", &
3421 WRITE (unit=iounit, fmt=
"(/,T2,A)")
"ELECTRIC/MAGNETIC MOMENTS"
3426 cpabort(
"Periodic moments not implemented with EC")
3428 cpassert(maxmom < 2)
3429 cpassert(.NOT. magnetic)
3430 IF (maxmom == 1)
THEN
3431 CALL get_qs_env(qs_env=qs_env, cell=cell, para_env=para_env)
3433 CALL get_reference_point(rcc, qs_env=qs_env, reference=reference, ref_point=ref_point)
3436 CALL get_qs_env(qs_env=qs_env, particle_set=particle_set, &
3437 qs_kind_set=qs_kind_set, local_particles=local_particles)
3438 DO ikind = 1,
SIZE(local_particles%n_el)
3439 DO ia = 1, local_particles%n_el(ikind)
3440 iatom = local_particles%list(ikind)%array(ia)
3442 ria = pbc(particle_set(iatom)%r - rcc, cell) + rcc
3444 atomic_kind => particle_set(iatom)%atomic_kind
3445 CALL get_atomic_kind(atomic_kind, kind_number=akind)
3446 CALL get_qs_kind(qs_kind_set(akind), core_charge=charge)
3447 cdip(1:3) = cdip(1:3) - charge*ria(1:3)
3450 CALL para_env%sum(cdip)
3453 CALL ec_efield_integrals(qs_env, ec_env, rcc)
3456 DO ispin = 1, nspins
3458 CALL dbcsr_dot(ec_env%matrix_p(ispin, 1)%matrix, &
3459 ec_env%efield%dipmat(idir)%matrix, tmp)
3460 pdip(idir) = pdip(idir) + tmp
3465 CALL get_qs_env(qs_env=qs_env, matrix_s=matrix_s)
3467 CALL dbcsr_allocate_matrix_set(moments, 4)
3469 ALLOCATE (moments(i)%matrix)
3470 CALL dbcsr_copy(moments(i)%matrix, matrix_s(1)%matrix,
"Moments")
3471 CALL dbcsr_set(moments(i)%matrix, 0.0_dp)
3473 CALL build_local_moment_matrix(qs_env, moments, 1, ref_point=rcc)
3476 IF (nspins == 2) focc = 1.0_dp
3478 DO ispin = 1, nspins
3480 CALL dbcsr_dot(ec_env%matrix_z(ispin)%matrix, moments(idir)%matrix, tmp)
3481 rdip(idir) = rdip(idir) + tmp
3484 CALL dbcsr_deallocate_matrix_set(moments)
3486 tdip = -(rdip + pdip + cdip)
3487 IF (unit_nr > 0)
THEN
3488 WRITE (unit_nr,
"(T3,A)")
"Dipoles are based on the traditional operator."
3489 dd = sqrt(sum(tdip(1:3)**2))*debye
3490 WRITE (unit_nr,
"(T3,A)")
"Dipole moment [Debye]"
3491 WRITE (unit_nr,
"(T5,3(A,A,F14.8,1X),T60,A,T67,F14.8)") &
3492 (trim(rlab(i)),
"=", tdip(i)*debye, i=1, 3),
"Total=", dd
3497 CALL cp_print_key_finished_output(unit_nr=unit_nr, logger=logger, &
3498 basis_section=ec_section, print_key_path=
"PRINT%MOMENTS")
3499 CALL get_qs_env(qs_env=qs_env, results=results)
3500 description =
"[DIPOLE]"
3501 CALL cp_results_erase(results=results, description=description)
3502 CALL put_results(results=results, description=description, values=tdip(1:3))
3506 print_key_voro => section_vals_get_subs_vals(ec_section,
"PRINT%VORONOI")
3507 print_key_bqb => section_vals_get_subs_vals(ec_section,
"PRINT%E_DENSITY_BQB")
3508 IF (btest(cp_print_key_should_output(logger%iter_info, print_key_voro), cp_p_file))
THEN
3509 should_print_voro = 1
3511 should_print_voro = 0
3513 IF (btest(cp_print_key_should_output(logger%iter_info, print_key_bqb), cp_p_file))
THEN
3514 should_print_bqb = 1
3516 should_print_bqb = 0
3518 IF ((should_print_voro /= 0) .OR. (should_print_bqb /= 0))
THEN
3520 IF (dft_control%qs_control%gapw .OR. dft_control%qs_control%gapw_xc)
THEN
3521 cpabort(
"Properties for GAPW in EC NYA")
3524 CALL get_qs_env(qs_env=qs_env, &
3526 CALL pw_env_get(pw_env=pw_env, &
3527 auxbas_pw_pool=auxbas_pw_pool, &
3529 CALL auxbas_pw_pool%create_pw(pw=rho_elec_rspace)
3531 IF (dft_control%nspins > 1)
THEN
3534 CALL pw_copy(ec_env%rhoout_r(1), rho_elec_rspace)
3535 CALL pw_axpy(ec_env%rhoout_r(2), rho_elec_rspace)
3537 CALL pw_axpy(ec_env%rhoz_r(1), rho_elec_rspace)
3538 CALL pw_axpy(ec_env%rhoz_r(2), rho_elec_rspace)
3542 CALL pw_copy(ec_env%rhoout_r(1), rho_elec_rspace)
3543 CALL pw_axpy(ec_env%rhoz_r(1), rho_elec_rspace)
3546 IF (should_print_voro /= 0)
THEN
3547 CALL section_vals_val_get(print_key_voro,
"OUTPUT_TEXT", l_val=voro_print_txt)
3548 IF (voro_print_txt)
THEN
3549 append_voro = section_get_lval(ec_section,
"PRINT%VORONOI%APPEND")
3550 my_pos_voro =
"REWIND"
3551 IF (append_voro)
THEN
3552 my_pos_voro =
"APPEND"
3554 unit_nr_voro = cp_print_key_unit_nr(logger, ec_section,
"PRINT%VORONOI", extension=
".voronoi", &
3555 file_position=my_pos_voro, log_filename=.false.)
3563 CALL entry_voronoi_or_bqb(should_print_voro, should_print_bqb, print_key_voro, print_key_bqb, &
3564 unit_nr_voro, qs_env, rho_elec_rspace)
3566 CALL auxbas_pw_pool%give_back_pw(rho_elec_rspace)
3568 IF (unit_nr_voro > 0)
THEN
3569 CALL cp_print_key_finished_output(unit_nr_voro, logger, ec_section,
"PRINT%VORONOI")
3574 CALL timestop(handle)
3576 END SUBROUTINE ec_properties
3583 SUBROUTINE harris_wfn_output(qs_env, ec_env, unit_nr)
3584 TYPE(qs_environment_type),
POINTER :: qs_env
3585 TYPE(energy_correction_type),
POINTER :: ec_env
3586 INTEGER,
INTENT(IN) :: unit_nr
3588 CHARACTER(LEN=*),
PARAMETER :: routinen =
'harris_wfn_output'
3590 INTEGER :: handle, ic, ires, ispin, nimages, nsize, &
3592 INTEGER,
DIMENSION(3) :: cell
3593 INTEGER,
DIMENSION(:, :, :),
POINTER :: cell_to_index
3594 TYPE(cp_blacs_env_type),
POINTER :: blacs_env
3595 TYPE(cp_fm_struct_type),
POINTER :: fm_struct
3596 TYPE(cp_fm_type) :: fmat
3597 TYPE(cp_logger_type),
POINTER :: logger
3598 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: denmat
3599 TYPE(mp_para_env_type),
POINTER :: para_env
3600 TYPE(particle_type),
DIMENSION(:),
POINTER :: particle_set
3601 TYPE(qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
3602 TYPE(section_vals_type),
POINTER :: ec_section
3606 CALL timeset(routinen, handle)
3608 logger => cp_get_default_logger()
3610 ec_section => section_vals_get_subs_vals(qs_env%input,
"DFT%ENERGY_CORRECTION")
3611 CALL get_qs_env(qs_env, qs_kind_set=qs_kind_set, particle_set=particle_set)
3613 IF (ec_env%do_kpoints)
THEN
3614 ires = cp_print_key_unit_nr(logger, ec_section,
"PRINT%HARRIS_OUTPUT_WFN", &
3615 extension=
".kp", file_status=
"REPLACE", file_action=
"WRITE", &
3616 file_form=
"UNFORMATTED", middle_name=
"Harris")
3618 CALL write_kpoints_file_header(qs_kind_set, particle_set, ires, basis_type=
"HARRIS")
3620 denmat => ec_env%matrix_p
3621 nspin =
SIZE(denmat, 1)
3622 nimages =
SIZE(denmat, 2)
3623 NULLIFY (cell_to_index)
3624 IF (nimages > 1)
THEN
3625 CALL get_kpoint_info(kpoint=ec_env%kpoints, cell_to_index=cell_to_index)
3627 CALL dbcsr_get_info(denmat(1, 1)%matrix, nfullrows_total=nsize)
3628 NULLIFY (blacs_env, para_env)
3629 CALL get_qs_env(qs_env=qs_env, blacs_env=blacs_env, para_env=para_env)
3631 CALL cp_fm_struct_create(fm_struct, context=blacs_env, nrow_global=nsize, &
3632 ncol_global=nsize, para_env=para_env)
3633 CALL cp_fm_create(fmat, fm_struct)
3634 CALL cp_fm_struct_release(fm_struct)
3637 IF (ires > 0)
WRITE (ires) ispin, nspin, nimages
3639 IF (nimages > 1)
THEN
3640 cell = get_cell(ic, cell_to_index)
3644 IF (ires > 0)
WRITE (ires) ic, cell
3645 CALL copy_dbcsr_to_fm(denmat(ispin, ic)%matrix, fmat)
3646 CALL cp_fm_write_unformatted(fmat, ires)
3650 CALL cp_print_key_finished_output(ires, logger, ec_section,
"PRINT%HARRIS_OUTPUT_WFN")
3651 CALL cp_fm_release(fmat)
3653 CALL cp_warn(__location__, &
3654 "Orbital energy correction potential is an experimental feature. "// &
3655 "Use it with extreme care")
3658 CALL timestop(handle)
3660 END SUBROUTINE harris_wfn_output
3668 SUBROUTINE response_force_error(qs_env, ec_env, unit_nr)
3669 TYPE(qs_environment_type),
POINTER :: qs_env
3670 TYPE(energy_correction_type),
POINTER :: ec_env
3671 INTEGER,
INTENT(IN) :: unit_nr
3673 CHARACTER(LEN=10) :: eformat
3674 INTEGER :: feunit, funit, i, ia, ib, ispin, mref, &
3675 na, nao, natom, nb, norb, nref, &
3677 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: natom_of_kind, rlist, t2cind
3678 LOGICAL :: debug_f, do_resp, is_source
3679 REAL(kind=dp) :: focc, rfac, vres
3680 REAL(kind=dp),
ALLOCATABLE,
DIMENSION(:) :: tvec, yvec
3681 REAL(kind=dp),
ALLOCATABLE,
DIMENSION(:, :) :: eforce, fmlocal, fmreord, smat
3682 REAL(kind=dp),
ALLOCATABLE,
DIMENSION(:, :, :) :: smpforce
3683 TYPE(atomic_kind_type),
DIMENSION(:),
POINTER :: atomic_kind_set
3684 TYPE(cp_fm_struct_type),
POINTER :: fm_struct, fm_struct_mat
3685 TYPE(cp_fm_type) :: hmats
3686 TYPE(cp_fm_type),
DIMENSION(:, :),
POINTER :: rpmos, spmos
3687 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_s
3688 TYPE(dbcsr_type),
POINTER :: mats
3689 TYPE(mp_para_env_type),
POINTER :: para_env
3690 TYPE(qs_force_type),
DIMENSION(:),
POINTER :: ks_force, res_force
3691 TYPE(virial_type) :: res_virial
3692 TYPE(virial_type),
POINTER :: ks_virial
3694 IF (unit_nr > 0)
THEN
3695 WRITE (unit_nr,
'(/,T2,A,A,A,A,A)')
"!", repeat(
"-", 25), &
3696 " Response Force Error Est. ", repeat(
"-", 25),
"!"
3697 SELECT CASE (ec_env%error_method)
3699 WRITE (unit_nr,
'(T2,A)')
" Response Force Error Est. using full RHS"
3701 WRITE (unit_nr,
'(T2,A)')
" Response Force Error Est. using delta RHS"
3703 WRITE (unit_nr,
'(T2,A)')
" Response Force Error Est. using extrapolated RHS"
3704 WRITE (unit_nr,
'(T2,A,E20.10)')
" Extrapolation cutoff:", ec_env%error_cutoff
3705 WRITE (unit_nr,
'(T2,A,I10)')
" Max. extrapolation size:", ec_env%error_subspace
3707 cpabort(
"Unknown Error Estimation Method")
3711 IF (abs(ec_env%orbrot_index) > 1.e-8_dp .OR. ec_env%phase_index > 1.e-8_dp)
THEN
3712 cpabort(
"Response error calculation for rotated orbital sets not implemented")
3715 SELECT CASE (ec_env%energy_functional)
3716 CASE (ec_functional_harris)
3717 cpwarn(
'Response force error calculation not possible for Harris functional.')
3718 CASE (ec_functional_dc)
3719 cpwarn(
'Response force error calculation not possible for DCDFT.')
3720 CASE (ec_functional_ext)
3723 CALL get_qs_env(qs_env, force=ks_force, virial=ks_virial, &
3724 atomic_kind_set=atomic_kind_set)
3725 CALL get_atomic_kind_set(atomic_kind_set=atomic_kind_set, natom_of_kind=natom_of_kind)
3727 CALL allocate_qs_force(res_force, natom_of_kind)
3728 DEALLOCATE (natom_of_kind)
3729 CALL zero_qs_force(res_force)
3730 res_virial = ks_virial
3731 CALL zero_virial(ks_virial, reset=.false.)
3732 CALL set_qs_env(qs_env, force=res_force)
3734 CALL get_qs_env(qs_env, natom=natom)
3735 ALLOCATE (eforce(3, natom))
3737 CALL get_qs_env(qs_env, para_env=para_env)
3738 is_source = para_env%is_source()
3740 nspins =
SIZE(ec_env%mo_occ)
3741 CALL cp_fm_get_info(ec_env%mo_occ(1), nrow_global=nao)
3744 CALL open_file(ec_env%exresperr_fn, file_status=
"OLD", file_action=
"READ", &
3745 file_form=
"FORMATTED", unit_number=funit)
3746 READ (funit,
'(A)') eformat
3747 CALL uppercase(eformat)
3748 READ (funit, *) nsample
3750 CALL para_env%bcast(nsample, para_env%source)
3751 CALL para_env%bcast(eformat, para_env%source)
3753 CALL cp_fm_get_info(ec_env%mo_occ(1), matrix_struct=fm_struct)
3754 CALL cp_fm_struct_create(fm_struct_mat, template_fmstruct=fm_struct, &
3755 nrow_global=nao, ncol_global=nao)
3756 ALLOCATE (fmlocal(nao, nao))
3757 IF (adjustl(trim(eformat)) ==
"TREXIO")
THEN
3758 ALLOCATE (fmreord(nao, nao))
3759 CALL get_t2cindex(qs_env, t2cind)
3761 ALLOCATE (rpmos(nsample, nspins))
3762 ALLOCATE (smpforce(3, natom, nsample))
3766 IF (nspins == 1) focc = 4.0_dp
3767 CALL cp_fm_create(hmats, fm_struct_mat)
3770 DO ispin = 1, nspins
3771 CALL cp_fm_create(rpmos(i, ispin), fm_struct)
3773 READ (funit, *) na, nb
3774 cpassert(na == nao .AND. nb == nao)
3775 READ (funit, *) fmlocal
3779 CALL para_env%bcast(fmlocal)
3781 SELECT CASE (adjustl(trim(eformat)))
3788 fmreord(ia, ib) = fmlocal(t2cind(ia), t2cind(ib))
3791 fmlocal(1:nao, 1:nao) = fmreord(1:nao, 1:nao)
3793 cpabort(
"Error file dE/dC: unknown format")
3796 CALL cp_fm_set_submatrix(hmats, fmlocal, 1, 1, nao, nao)
3797 CALL cp_fm_get_info(rpmos(i, ispin), ncol_global=norb)
3798 CALL parallel_gemm(
'N',
'N', nao, norb, nao, focc, hmats, &
3799 ec_env%mo_occ(ispin), 0.0_dp, rpmos(i, ispin))
3800 IF (ec_env%error_method ==
"D" .OR. ec_env%error_method ==
"E")
THEN
3801 CALL cp_fm_scale_and_add(1.0_dp, rpmos(i, ispin), -1.0_dp, ec_env%cpref(ispin))
3805 CALL cp_fm_struct_release(fm_struct_mat)
3806 IF (adjustl(trim(eformat)) ==
"TREXIO")
THEN
3807 DEALLOCATE (fmreord, t2cind)
3811 CALL close_file(funit)
3814 IF (unit_nr > 0)
THEN
3815 CALL open_file(ec_env%exresult_fn, file_status=
"OLD", file_form=
"FORMATTED", &
3816 file_action=
"WRITE", file_position=
"APPEND", unit_number=feunit)
3817 WRITE (feunit,
"(/,6X,A)")
" Response Forces from error sampling [Hartree/Bohr]"
3819 WRITE (feunit,
"(5X,I8)") i
3821 WRITE (feunit,
"(5X,3F20.12)") ec_env%rf(1:3, ia)
3825 debug_f = ec_env%debug_forces .OR. ec_env%debug_stress
3827 IF (ec_env%error_method ==
"E")
THEN
3828 CALL get_qs_env(qs_env, matrix_s=matrix_s)
3829 mats => matrix_s(1)%matrix
3830 ALLOCATE (spmos(nsample, nspins))
3832 DO ispin = 1, nspins
3833 CALL cp_fm_create(spmos(i, ispin), fm_struct, set_zero=.true.)
3834 CALL cp_dbcsr_sm_fm_multiply(mats, rpmos(i, ispin), spmos(i, ispin), norb)
3839 mref = ec_env%error_subspace
3840 mref = min(mref, nsample)
3842 ALLOCATE (smat(mref, mref), tvec(mref), yvec(mref), rlist(mref))
3845 CALL cp_fm_release(ec_env%cpmos)
3848 IF (unit_nr > 0)
THEN
3849 WRITE (unit_nr,
'(T2,A,I6)')
" Response Force Number ", i
3852 CALL zero_qs_force(res_force)
3853 CALL zero_virial(ks_virial, reset=.false.)
3854 DO ispin = 1, nspins
3855 CALL dbcsr_set(ec_env%matrix_hz(ispin)%matrix, 0.0_dp)
3858 ALLOCATE (ec_env%cpmos(nspins))
3859 DO ispin = 1, nspins
3860 CALL cp_fm_create(ec_env%cpmos(ispin), fm_struct)
3864 IF (ec_env%error_method ==
"F" .OR. ec_env%error_method ==
"D")
THEN
3865 DO ispin = 1, nspins
3866 CALL cp_fm_to_fm(rpmos(i, ispin), ec_env%cpmos(ispin))
3868 ELSE IF (ec_env%error_method ==
"E")
THEN
3869 CALL cp_extrapolate(rpmos, spmos, i, nref, rlist, smat, tvec, yvec, vres)
3870 IF (vres > ec_env%error_cutoff .OR. nref < min(5, mref))
THEN
3871 DO ispin = 1, nspins
3872 CALL cp_fm_to_fm(rpmos(i, ispin), ec_env%cpmos(ispin))
3877 DO ispin = 1, nspins
3878 CALL cp_fm_scale_and_add(1.0_dp, ec_env%cpmos(ispin), &
3879 rfac, rpmos(ia, ispin))
3885 IF (unit_nr > 0)
THEN
3886 WRITE (unit_nr,
'(T2,A,T60,I4,T69,F12.8)') &
3887 " Response Vector Extrapolation [nref|delta] = ", nref, vres
3890 cpabort(
"Unknown Error Estimation Method")
3894 CALL matrix_r_forces(qs_env, ec_env%cpmos, ec_env%mo_occ, &
3895 ec_env%matrix_w(1, 1)%matrix, unit_nr, &
3896 ec_env%debug_forces, ec_env%debug_stress)
3898 CALL response_calculation(qs_env, ec_env, silent=.true.)
3900 CALL response_force(qs_env, &
3901 vh_rspace=ec_env%vh_rspace, &
3902 vxc_rspace=ec_env%vxc_rspace, &
3903 vtau_rspace=ec_env%vtau_rspace, &
3904 vadmm_rspace=ec_env%vadmm_rspace, &
3905 vadmm_tau_rspace=ec_env%vadmm_tau_rspace, &
3906 matrix_hz=ec_env%matrix_hz, &
3907 matrix_pz=ec_env%matrix_z, &
3908 matrix_pz_admm=ec_env%z_admm, &
3909 matrix_wz=ec_env%matrix_wz, &
3910 rhopz_r=ec_env%rhoz_r, &
3911 zehartree=ec_env%ehartree, &
3913 zexc_aux_fit=ec_env%exc_aux_fit, &
3914 p_env=ec_env%p_env, &
3916 CALL total_qs_force(eforce, res_force, atomic_kind_set)
3917 CALL para_env%sum(eforce)
3919 IF (unit_nr > 0)
THEN
3920 WRITE (unit_nr,
'(T2,A)')
" Response Force Calculation is skipped. "
3925 IF (ec_env%error_method ==
"D")
THEN
3926 eforce(1:3, 1:natom) = eforce(1:3, 1:natom) + ec_env%rf(1:3, 1:natom)
3927 smpforce(1:3, 1:natom, i) = eforce(1:3, 1:natom)
3928 ELSE IF (ec_env%error_method ==
"E")
THEN
3932 eforce(1:3, 1:natom) = eforce(1:3, 1:natom) + rfac*smpforce(1:3, 1:natom, ia)
3934 smpforce(1:3, 1:natom, i) = eforce(1:3, 1:natom)
3935 eforce(1:3, 1:natom) = eforce(1:3, 1:natom) + ec_env%rf(1:3, 1:natom)
3936 IF (do_resp .AND. nref < mref)
THEN
3941 smpforce(1:3, 1:natom, i) = eforce(1:3, 1:natom)
3944 IF (unit_nr > 0)
THEN
3945 WRITE (unit_nr, *)
" FORCES"
3947 WRITE (unit_nr,
"(i7,3F11.6,6X,3F11.6)") ia, eforce(1:3, ia), &
3948 (eforce(1:3, ia) - ec_env%rf(1:3, ia))
3952 WRITE (feunit,
"(5X,I8)") i
3954 WRITE (feunit,
"(5X,3F20.12)") eforce(1:3, ia)
3958 CALL cp_fm_release(ec_env%cpmos)
3962 IF (unit_nr > 0)
THEN
3963 CALL close_file(feunit)
3966 DEALLOCATE (smat, tvec, yvec, rlist)
3968 CALL cp_fm_release(hmats)
3969 CALL cp_fm_release(rpmos)
3970 IF (ec_env%error_method ==
"E")
THEN
3971 CALL cp_fm_release(spmos)
3974 DEALLOCATE (eforce, smpforce)
3977 CALL get_qs_env(qs_env, force=res_force, virial=ks_virial)
3978 CALL set_qs_env(qs_env, force=ks_force)
3979 CALL deallocate_qs_force(res_force)
3980 ks_virial = res_virial
3983 cpabort(
"unknown energy correction")
3986 END SUBROUTINE response_force_error
4000 SUBROUTINE cp_extrapolate(rpmos, Spmos, ip, nref, rlist, smat, tvec, yvec, vres)
4001 TYPE(cp_fm_type),
DIMENSION(:, :),
POINTER :: rpmos, spmos
4002 INTEGER,
INTENT(IN) :: ip, nref
4003 INTEGER,
DIMENSION(:),
INTENT(IN) :: rlist
4004 REAL(kind=dp),
DIMENSION(:, :),
INTENT(INOUT) :: smat
4005 REAL(kind=dp),
DIMENSION(:),
INTENT(INOUT) :: tvec, yvec
4006 REAL(kind=dp),
INTENT(OUT) :: vres
4008 INTEGER :: i, ia, j, ja
4009 REAL(kind=dp) :: aval
4010 REAL(kind=dp),
ALLOCATABLE,
DIMENSION(:, :) :: sinv
4018 ALLOCATE (sinv(nref, nref))
4022 tvec(i) = ctrace(rpmos(ip, :), spmos(ia, :))
4025 smat(j, i) = ctrace(rpmos(ja, :), spmos(ia, :))
4026 smat(i, j) = smat(j, i)
4028 smat(i, i) = ctrace(rpmos(ia, :), spmos(ia, :))
4030 aval = ctrace(rpmos(ip, :), spmos(ip, :))
4032 sinv(1:nref, 1:nref) = smat(1:nref, 1:nref)
4033 CALL invmat_symm(sinv(1:nref, 1:nref))
4035 yvec(1:nref) = matmul(sinv(1:nref, 1:nref), tvec(1:nref))
4037 vres = aval - sum(yvec(1:nref)*tvec(1:nref))
4038 vres = sqrt(abs(vres))
4045 END SUBROUTINE cp_extrapolate
4053 FUNCTION ctrace(ca, cb)
4054 TYPE(cp_fm_type),
DIMENSION(:) :: ca, cb
4055 REAL(kind=dp) :: ctrace
4058 REAL(kind=dp) :: trace
4064 CALL cp_fm_trace(ca(is), cb(is), trace)
4065 ctrace = ctrace + trace
4075 SUBROUTINE get_t2cindex(qs_env, t2cind)
4076 TYPE(qs_environment_type),
POINTER :: qs_env
4077 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: t2cind
4079 INTEGER :: i, iatom, ikind, is, iset, ishell, k, l, &
4080 m, natom, nset, nsgf, numshell
4081 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: lshell
4082 INTEGER,
DIMENSION(:),
POINTER :: nshell
4083 INTEGER,
DIMENSION(:, :),
POINTER :: lval
4084 TYPE(gto_basis_set_type),
POINTER :: basis_set
4085 TYPE(particle_type),
DIMENSION(:),
POINTER :: particle_set
4086 TYPE(qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
4090 CALL get_qs_env(qs_env, qs_kind_set=qs_kind_set, particle_set=particle_set, natom=natom)
4091 CALL get_qs_kind_set(qs_kind_set, nshell=numshell, nsgf=nsgf)
4093 ALLOCATE (t2cind(nsgf))
4094 ALLOCATE (lshell(numshell))
4098 CALL get_atomic_kind(particle_set(iatom)%atomic_kind, kind_number=ikind)
4099 CALL get_qs_kind(qs_kind_set(ikind), basis_set=basis_set, basis_type=
"ORB")
4100 CALL get_gto_basis_set(basis_set, nset=nset, nshell=nshell, l=lval)
4102 DO is = 1, nshell(iset)
4111 DO ishell = 1, numshell
4114 m = (-1)**k*floor(real(k, kind=dp)/2.0_dp)
4115 t2cind(i + l + 1 + m) = i + k
4122 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. Tracking of preconnections.
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, 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.