209#include "./base/base_uses.f90"
217 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'energy_corrections'
238 LOGICAL,
INTENT(IN),
OPTIONAL :: ec_init, calculate_forces
240 CHARACTER(len=*),
PARAMETER :: routinen =
'energy_correction'
242 INTEGER :: handle, unit_nr
243 LOGICAL :: my_calc_forces
250 CALL timeset(routinen, handle)
253 IF (logger%para_env%is_source())
THEN
265 IF (.NOT. ec_env%do_skip)
THEN
267 ec_env%should_update = .true.
268 IF (
PRESENT(ec_init)) ec_env%should_update = ec_init
270 my_calc_forces = .false.
271 IF (
PRESENT(calculate_forces)) my_calc_forces = calculate_forces
273 IF (ec_env%should_update)
THEN
274 ec_env%old_etotal = 0.0_dp
275 ec_env%etotal = 0.0_dp
276 ec_env%eband = 0.0_dp
277 ec_env%ehartree = 0.0_dp
281 ec_env%edispersion = 0.0_dp
282 ec_env%exc_aux_fit = 0.0_dp
285 ec_env%ehartree_1c = 0.0_dp
286 ec_env%exc1_aux_fit = 0.0_dp
290 ec_env%old_etotal = energy%total
294 IF (my_calc_forces)
THEN
295 IF (unit_nr > 0)
THEN
296 WRITE (unit_nr,
'(T2,A,A,A,A,A)')
"!", repeat(
"-", 25), &
297 " Energy Correction Forces ", repeat(
"-", 26),
"!"
299 CALL get_qs_env(qs_env, force=ks_force, virial=virial)
303 IF (unit_nr > 0)
THEN
304 WRITE (unit_nr,
'(T2,A,A,A,A,A)')
"!", repeat(
"-", 29), &
305 " Energy Correction ", repeat(
"-", 29),
"!"
310 CALL energy_correction_low(qs_env, ec_env, my_calc_forces, unit_nr)
313 IF (ec_env%should_update)
THEN
314 energy%nonscf_correction = ec_env%etotal - ec_env%old_etotal
315 energy%total = ec_env%etotal
318 IF (.NOT. my_calc_forces .AND. unit_nr > 0)
THEN
319 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Energy Correction ", energy%nonscf_correction
321 IF (unit_nr > 0)
THEN
322 WRITE (unit_nr,
'(T2,A,A,A)')
"!", repeat(
"-", 77),
"!"
329 IF (unit_nr > 0)
THEN
330 WRITE (unit_nr,
'(T2,A,A,A)')
"!", repeat(
"-", 77),
"!"
331 WRITE (unit_nr,
'(T2,A,A,A,A,A)')
"!", repeat(
"-", 26), &
332 " Skip Energy Correction ", repeat(
"-", 27),
"!"
333 WRITE (unit_nr,
'(T2,A,A,A)')
"!", repeat(
"-", 77),
"!"
338 CALL timestop(handle)
353 SUBROUTINE energy_correction_low(qs_env, ec_env, calculate_forces, unit_nr)
356 LOGICAL,
INTENT(IN) :: calculate_forces
357 INTEGER,
INTENT(IN) :: unit_nr
359 INTEGER :: ispin, nkind, nspins
360 LOGICAL :: debug_f, gapw, gapw_xc
361 REAL(kind=
dp) :: eps_fit, exc
369 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
371 IF (ec_env%should_update)
THEN
372 CALL ec_build_neighborlist(qs_env, ec_env)
378 ec_env%vtau_rspace, &
379 ec_env%vadmm_rspace, &
380 ec_env%ehartree, exc, &
381 vadmm_tau_rspace=ec_env%vadmm_tau_rspace)
383 ec_env%local_rho_set_admm, ec_env%vh_rspace)
385 SELECT CASE (ec_env%energy_functional)
388 CALL ec_build_core_hamiltonian(qs_env, ec_env)
389 CALL ec_build_ks_matrix(qs_env, ec_env)
392 cpassert(.NOT. ec_env%do_kpoints)
395 NULLIFY (ec_env%mao_coef)
396 CALL mao_generate_basis(qs_env, ec_env%mao_coef, ref_basis_set=
"HARRIS", molecular=.true., &
397 max_iter=ec_env%mao_max_iter, eps_grad=ec_env%mao_eps_grad, &
398 eps1_mao=ec_env%mao_eps1, iolevel=ec_env%mao_iolevel, unit_nr=unit_nr)
401 CALL ec_ks_solver(qs_env, ec_env)
403 CALL evaluate_ec_core_matrix_traces(qs_env, ec_env)
405 IF (ec_env%write_harris_wfn)
THEN
406 CALL harris_wfn_output(qs_env, ec_env, unit_nr)
410 cpassert(.NOT. ec_env%do_kpoints)
413 CALL ec_dc_energy(qs_env, ec_env, calculate_forces=.false.)
418 CALL ec_build_ks_matrix(qs_env, ec_env)
421 cpassert(.NOT. ec_env%do_kpoints)
426 cpabort(
"unknown energy correction")
430 CALL ec_disp(qs_env, ec_env, calculate_forces=.false.)
433 CALL ec_energy(ec_env, unit_nr)
437 IF (calculate_forces)
THEN
439 debug_f = ec_env%debug_forces .OR. ec_env%debug_stress
441 CALL get_qs_env(qs_env=qs_env, dft_control=dft_control)
442 nspins = dft_control%nspins
443 gapw = dft_control%qs_control%gapw
444 gapw_xc = dft_control%qs_control%gapw_xc
445 IF (gapw .OR. gapw_xc)
THEN
447 qs_kind_set=qs_kind_set, particle_set=particle_set)
448 NULLIFY (oce, sap_oce)
449 CALL get_qs_env(qs_env=qs_env, oce=oce, sap_oce=sap_oce)
452 eps_fit = dft_control%qs_control%gapw_control%eps_fit
458 CALL ec_disp(qs_env, ec_env, calculate_forces=.true.)
460 SELECT CASE (ec_env%energy_functional)
463 CALL ec_build_core_hamiltonian_force(qs_env, ec_env, &
467 CALL ec_build_ks_matrix_force(qs_env, ec_env)
468 IF (ec_env%debug_external)
THEN
469 CALL write_response_interface(qs_env, ec_env)
470 CALL init_response_deriv(qs_env, ec_env)
475 cpassert(.NOT. ec_env%do_kpoints)
478 CALL ec_dc_energy(qs_env, ec_env, calculate_forces=.true.)
480 CALL ec_build_core_hamiltonian_force(qs_env, ec_env, &
484 CALL ec_dc_build_ks_matrix_force(qs_env, ec_env)
485 IF (ec_env%debug_external)
THEN
486 CALL write_response_interface(qs_env, ec_env)
487 CALL init_response_deriv(qs_env, ec_env)
492 cpassert(.NOT. ec_env%do_kpoints)
494 CALL init_response_deriv(qs_env, ec_env)
497 ec_env%matrix_w(1, 1)%matrix, unit_nr, &
498 ec_env%debug_forces, ec_env%debug_stress)
501 cpabort(
"unknown energy correction")
504 IF (ec_env%do_error)
THEN
505 ALLOCATE (ec_env%cpref(nspins))
507 CALL cp_fm_create(ec_env%cpref(ispin), ec_env%cpmos(ispin)%matrix_struct)
508 CALL cp_fm_to_fm(ec_env%cpmos(ispin), ec_env%cpref(ispin))
518 cpassert(
ASSOCIATED(pw_env))
519 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
520 ALLOCATE (ec_env%rhoz_r(nspins))
522 CALL auxbas_pw_pool%create_pw(ec_env%rhoz_r(ispin))
526 vh_rspace=ec_env%vh_rspace, &
527 vxc_rspace=ec_env%vxc_rspace, &
528 vtau_rspace=ec_env%vtau_rspace, &
529 vadmm_rspace=ec_env%vadmm_rspace, &
530 vadmm_tau_rspace=ec_env%vadmm_tau_rspace, &
531 matrix_hz=ec_env%matrix_hz, &
532 matrix_pz=ec_env%matrix_z, &
533 matrix_pz_admm=ec_env%z_admm, &
534 matrix_wz=ec_env%matrix_wz, &
535 rhopz_r=ec_env%rhoz_r, &
536 zehartree=ec_env%ehartree, &
538 zexc_aux_fit=ec_env%exc_aux_fit, &
539 p_env=ec_env%p_env, &
542 CALL output_response_deriv(qs_env, ec_env, unit_nr)
544 CALL ec_properties(qs_env, ec_env)
546 IF (ec_env%do_error)
THEN
547 CALL response_force_error(qs_env, ec_env, unit_nr)
551 IF (
ASSOCIATED(ec_env%rhoout_r))
THEN
553 CALL auxbas_pw_pool%give_back_pw(ec_env%rhoout_r(ispin))
555 DEALLOCATE (ec_env%rhoout_r)
557 IF (
ASSOCIATED(ec_env%rhoz_r))
THEN
559 CALL auxbas_pw_pool%give_back_pw(ec_env%rhoz_r(ispin))
561 DEALLOCATE (ec_env%rhoz_r)
577 END SUBROUTINE energy_correction_low
585 SUBROUTINE write_response_interface(qs_env, ec_env)
592 NULLIFY (trexio_section)
596 CALL write_trexio(qs_env, trexio_section, ec_env%matrix_hz)
598 END SUBROUTINE write_response_interface
606 SUBROUTINE init_response_deriv(qs_env, ec_env)
616 ALLOCATE (ec_env%rf(3, natom))
619 CALL get_qs_env(qs_env, force=force, virial=virial)
621 CALL get_qs_env(qs_env, atomic_kind_set=atomic_kind_set)
624 IF (virial%pv_availability .AND. (.NOT. virial%pv_numer))
THEN
625 ec_env%rpv = virial%pv_virial
628 END SUBROUTINE init_response_deriv
637 SUBROUTINE output_response_deriv(qs_env, ec_env, unit_nr)
640 INTEGER,
INTENT(IN) :: unit_nr
642 CHARACTER(LEN=default_string_length) :: unit_string
643 INTEGER :: funit, ia, natom
644 REAL(kind=
dp) :: evol, fconv
645 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: ftot
653 IF (
ASSOCIATED(ec_env%rf))
THEN
655 ALLOCATE (ftot(3, natom))
657 CALL get_qs_env(qs_env, force=force, virial=virial, para_env=para_env)
659 CALL get_qs_env(qs_env, atomic_kind_set=atomic_kind_set)
661 ec_env%rf(1:3, 1:natom) = ftot(1:3, 1:natom) - ec_env%rf(1:3, 1:natom)
662 CALL para_env%sum(ec_env%rf)
665 IF (virial%pv_availability .AND. (.NOT. virial%pv_numer))
THEN
666 ec_env%rpv = virial%pv_virial - ec_env%rpv
667 CALL para_env%sum(ec_env%rpv)
669 evol = ec_env%exc + ec_env%exc_aux_fit + 2.0_dp*ec_env%ehartree
670 ec_env%rpv(1, 1) = ec_env%rpv(1, 1) - evol
671 ec_env%rpv(2, 2) = ec_env%rpv(2, 2) - evol
672 ec_env%rpv(3, 3) = ec_env%rpv(3, 3) - evol
675 CALL get_qs_env(qs_env, particle_set=particle_set, cell=cell)
679 IF (unit_nr > 0)
THEN
680 WRITE (unit_nr,
'(/,T2,A)')
"Write EXTERNAL Response Derivative: "//trim(ec_env%exresult_fn)
682 CALL open_file(ec_env%exresult_fn, file_status=
"REPLACE", file_form=
"FORMATTED", &
683 file_action=
"WRITE", unit_number=funit)
684 WRITE (funit,
"(T8,A,T58,A)")
"COORDINATES [Bohr]",
"RESPONSE FORCES [Hartree/Bohr]"
686 WRITE (funit,
"(2(3F15.8,5x))") particle_set(ia)%r(1:3), ec_env%rf(1:3, ia)
689 WRITE (funit,
"(T8,A,T58,A)")
"CELL [Bohr]",
"RESPONSE PRESSURE [GPa]"
691 WRITE (funit,
"(3F15.8,5x,3F15.8)") cell%hmat(ia, 1:3), -fconv*ec_env%rpv(ia, 1:3)
698 END SUBROUTINE output_response_deriv
707 SUBROUTINE evaluate_ec_core_matrix_traces(qs_env, ec_env)
711 CHARACTER(LEN=*),
PARAMETER :: routinen =
'evaluate_ec_core_matrix_traces'
717 CALL timeset(routinen, handle)
720 CALL get_qs_env(qs_env, dft_control=dft_control, energy=energy)
723 CALL calculate_ptrace(ec_env%matrix_h, ec_env%matrix_p, energy%core, dft_control%nspins)
726 CALL calculate_ptrace(ec_env%matrix_t, ec_env%matrix_p, energy%kinetic, dft_control%nspins)
728 CALL timestop(handle)
730 END SUBROUTINE evaluate_ec_core_matrix_traces
743 SUBROUTINE ec_dc_energy(qs_env, ec_env, calculate_forces)
746 LOGICAL,
INTENT(IN) :: calculate_forces
748 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ec_dc_energy'
750 CHARACTER(LEN=default_string_length) :: headline
751 INTEGER :: handle, ispin, nspins
752 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_h, matrix_p, matrix_s, matrix_w
758 CALL timeset(routinen, handle)
760 NULLIFY (dft_control, ks_env, matrix_h, matrix_p, matrix_s, matrix_w, rho)
762 dft_control=dft_control, &
764 matrix_h_kp=matrix_h, &
765 matrix_s_kp=matrix_s, &
766 matrix_w_kp=matrix_w, &
769 nspins = dft_control%nspins
774 matrix_name=
"OVERLAP MATRIX", &
775 basis_type_a=
"HARRIS", &
776 basis_type_b=
"HARRIS", &
777 sab_nl=ec_env%sab_orb)
782 headline =
"CORE HAMILTONIAN MATRIX"
783 ALLOCATE (ec_env%matrix_h(1, 1)%matrix)
784 CALL dbcsr_create(ec_env%matrix_h(1, 1)%matrix, name=trim(headline), &
785 template=matrix_s(1, 1)%matrix, matrix_type=dbcsr_type_symmetric)
787 CALL dbcsr_copy(ec_env%matrix_h(1, 1)%matrix, matrix_h(1, 1)%matrix)
792 headline =
"DENSITY MATRIX"
794 ALLOCATE (ec_env%matrix_p(ispin, 1)%matrix)
795 CALL dbcsr_create(ec_env%matrix_p(ispin, 1)%matrix, name=trim(headline), &
796 template=matrix_s(1, 1)%matrix, matrix_type=dbcsr_type_symmetric)
798 CALL dbcsr_copy(ec_env%matrix_p(ispin, 1)%matrix, matrix_p(ispin, 1)%matrix)
801 IF (calculate_forces)
THEN
806 headline =
"ENERGY-WEIGHTED DENSITY MATRIX"
808 ALLOCATE (ec_env%matrix_w(ispin, 1)%matrix)
809 CALL dbcsr_create(ec_env%matrix_w(ispin, 1)%matrix, name=trim(headline), &
810 template=matrix_s(1, 1)%matrix, matrix_type=dbcsr_type_symmetric)
812 CALL dbcsr_copy(ec_env%matrix_w(ispin, 1)%matrix, matrix_w(ispin, 1)%matrix)
819 ec_env%ekTS = energy%ktS
822 ec_env%efield_nuclear = 0.0_dp
823 ec_env%efield_elec = 0.0_dp
826 CALL timestop(handle)
828 END SUBROUTINE ec_dc_energy
839 SUBROUTINE ec_dc_build_ks_matrix_force(qs_env, ec_env)
843 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ec_dc_build_ks_matrix_force'
845 CHARACTER(LEN=default_string_length) :: basis_type, unit_string
846 INTEGER :: handle, i, iounit, ispin, natom, nspins
847 LOGICAL :: debug_forces, debug_stress, do_ec_hfx, &
848 gapw, gapw_xc, use_virial
849 REAL(
dp) :: dummy_real, dummy_real2(2), ehartree, &
850 ehartree_1c, eovrl, exc, exc1, fconv
851 REAL(
dp),
ALLOCATABLE,
DIMENSION(:, :) :: ftot
852 REAL(
dp),
DIMENSION(3) :: fodeb, fodeb2
853 REAL(kind=
dp),
DIMENSION(3, 3) :: h_stress, pv_loc, stdeb, sttot
858 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_s, scrm
859 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_p
873 TYPE(
pw_r3d_rs_type),
DIMENSION(:),
POINTER :: rho_r, v_rspace, v_rspace_in, &
876 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
878 TYPE(
qs_rho_type),
POINTER :: rho, rho1, rho_struct, rho_xc
883 CALL timeset(routinen, handle)
885 debug_forces = ec_env%debug_forces
886 debug_stress = ec_env%debug_stress
889 IF (logger%para_env%is_source())
THEN
895 NULLIFY (atomic_kind_set, cell, dft_control, force, ks_env, &
896 matrix_p, matrix_s, para_env, pw_env, rho, sab_orb, virial)
899 dft_control=dft_control, &
908 cpassert(
ASSOCIATED(pw_env))
910 nspins = dft_control%nspins
911 use_virial = virial%pv_availability .AND. (.NOT. virial%pv_numer)
913 fconv = 1.0e-9_dp*
pascal/cell%deth
914 IF (debug_stress .AND. use_virial)
THEN
915 sttot = virial%pv_virial
919 gapw = dft_control%qs_control%gapw
920 gapw_xc = dft_control%qs_control%gapw_xc
922 cpassert(
ASSOCIATED(rho_xc))
924 IF (gapw .OR. gapw_xc)
THEN
926 cpabort(
"DC-DFT + GAPW + Stress NYA")
933 NULLIFY (hartree_local, local_rho_set)
934 IF (gapw .OR. gapw_xc)
THEN
936 atomic_kind_set=atomic_kind_set, &
937 qs_kind_set=qs_kind_set)
940 qs_kind_set, dft_control, para_env)
943 CALL init_rho0(local_rho_set, qs_env, dft_control%qs_control%gapw_control)
949 CALL get_qs_env(qs_env=qs_env, oce=oce, sab_orb=sab_orb)
951 qs_kind_set, oce, sab_orb, para_env)
955 NULLIFY (auxbas_pw_pool, poisson_env)
957 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool, &
958 poisson_env=poisson_env)
961 CALL auxbas_pw_pool%create_pw(v_hartree_gspace)
962 CALL auxbas_pw_pool%create_pw(rho_tot_gspace)
963 CALL auxbas_pw_pool%create_pw(v_hartree_rspace)
972 h_stress(:, :) = 0.0_dp
974 density=rho_tot_gspace, &
976 vhartree=v_hartree_gspace, &
979 virial%pv_ehartree = virial%pv_ehartree + h_stress/real(para_env%num_pe,
dp)
980 virial%pv_virial = virial%pv_virial + h_stress/real(para_env%num_pe,
dp)
982 IF (debug_stress)
THEN
983 stdeb = fconv*(h_stress/real(para_env%num_pe,
dp))
984 CALL para_env%sum(stdeb)
985 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
994 CALL pw_transfer(v_hartree_gspace, v_hartree_rspace)
995 CALL pw_scale(v_hartree_rspace, v_hartree_rspace%pw_grid%dvol)
999 ALLOCATE (ec_env%rhoout_r(nspins))
1000 DO ispin = 1, nspins
1001 CALL auxbas_pw_pool%create_pw(ec_env%rhoout_r(ispin))
1002 CALL pw_copy(rho_r(ispin), ec_env%rhoout_r(ispin))
1007 IF (debug_forces) fodeb(1:3) = force(1)%rho_core(1:3, 1)
1008 IF (debug_stress .AND. use_virial) stdeb = virial%pv_ehartree
1009 CALL integrate_v_core_rspace(v_hartree_rspace, qs_env)
1010 IF (debug_forces)
THEN
1011 fodeb(1:3) = force(1)%rho_core(1:3, 1) - fodeb(1:3)
1012 CALL para_env%sum(fodeb)
1013 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Vtot*dncore", fodeb
1015 IF (debug_stress .AND. use_virial)
THEN
1016 stdeb = fconv*(virial%pv_ehartree - stdeb)
1017 CALL para_env%sum(stdeb)
1018 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1024 NULLIFY (v_rspace, v_tau_rspace)
1027 IF (use_virial) virial%pv_calculate = .true.
1031 CALL get_qs_env(qs_env=qs_env, rho_xc=rho_struct)
1033 CALL get_qs_env(qs_env=qs_env, rho=rho_struct)
1035 CALL qs_vxc_create(ks_env=ks_env, rho_struct=rho_struct, xc_section=ec_env%xc_section, &
1036 vxc_rho=v_rspace, vxc_tau=v_tau_rspace, exc=exc, just_energy=.false.)
1038 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
1039 IF (debug_stress .AND. use_virial) stdeb = virial%pv_virial
1044 IF (debug_forces)
THEN
1045 fodeb(1:3) = force(1)%rho_elec(1:3, 1) - fodeb(1:3)
1046 CALL para_env%sum(fodeb)
1047 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Fxc*dw ", fodeb
1049 IF (debug_stress .AND. use_virial)
THEN
1050 stdeb = fconv*(virial%pv_virial - stdeb)
1051 CALL para_env%sum(stdeb)
1052 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1056 IF (.NOT.
ASSOCIATED(v_rspace))
THEN
1057 ALLOCATE (v_rspace(nspins))
1058 DO ispin = 1, nspins
1059 CALL auxbas_pw_pool%create_pw(v_rspace(ispin))
1064 IF (use_virial)
THEN
1065 virial%pv_exc = virial%pv_exc - virial%pv_xc
1066 virial%pv_virial = virial%pv_virial - virial%pv_xc
1073 DO ispin = 1, nspins
1074 ALLOCATE (scrm(ispin)%matrix)
1075 CALL dbcsr_create(scrm(ispin)%matrix, template=ec_env%matrix_ks(ispin, 1)%matrix)
1076 CALL dbcsr_copy(scrm(ispin)%matrix, ec_env%matrix_ks(ispin, 1)%matrix)
1077 CALL dbcsr_set(scrm(ispin)%matrix, 0.0_dp)
1080 pw_grid => v_hartree_rspace%pw_grid
1081 ALLOCATE (v_rspace_in(nspins))
1082 DO ispin = 1, nspins
1083 CALL v_rspace_in(ispin)%create(pw_grid)
1087 DO ispin = 1, nspins
1089 CALL pw_transfer(ec_env%vxc_rspace(ispin), v_rspace_in(ispin))
1090 IF (.NOT. gapw_xc)
THEN
1094 CALL pw_axpy(ec_env%vh_rspace, v_rspace_in(ispin))
1104 IF ((gapw .OR. gapw_xc) .AND. ec_env%do_ec_admm)
THEN
1108 cpabort(
"GAPW HFX ADMM + Energy Correction NYA")
1112 IF (debug_forces) fodeb(1:3) = force(1)%fock_4c(1:3, 1)
1113 IF (debug_forces) fodeb2(1:3) = force(1)%overlap_admm(1:3, 1)
1120 hfx_sections=ec_hfx_sections, &
1121 x_data=ec_env%x_data, &
1123 do_admm=ec_env%do_ec_admm, &
1124 calc_forces=.true., &
1125 reuse_hfx=ec_env%reuse_hfx, &
1126 do_im_time=.false., &
1127 e_ex_from_gw=dummy_real, &
1128 e_admm_from_gw=dummy_real2, &
1131 IF (debug_forces)
THEN
1132 fodeb(1:3) = force(1)%fock_4c(1:3, 1) - fodeb(1:3)
1133 CALL para_env%sum(fodeb)
1134 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: P*hfx_DC ", fodeb
1136 fodeb2(1:3) = force(1)%overlap_admm(1:3, 1) - fodeb2(1:3)
1137 CALL para_env%sum(fodeb2)
1138 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: P*hfx_DC*S ", fodeb2
1140 IF (debug_stress .AND. use_virial)
THEN
1141 stdeb = -1.0_dp*fconv*virial%pv_fock_4c
1142 CALL para_env%sum(stdeb)
1143 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1151 IF (use_virial)
THEN
1152 pv_loc = virial%pv_virial
1155 basis_type =
"HARRIS"
1156 IF (gapw .OR. gapw_xc)
THEN
1157 task_list => ec_env%task_list_soft
1159 task_list => ec_env%task_list
1162 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
1163 IF (debug_stress .AND. use_virial) stdeb = virial%pv_virial
1165 DO ispin = 1, nspins
1167 CALL pw_scale(v_rspace(ispin), v_rspace(ispin)%pw_grid%dvol)
1170 CALL integrate_v_rspace(v_rspace=v_rspace(ispin), &
1172 pmat=matrix_p(ispin, 1), &
1174 calculate_forces=.true., &
1175 basis_type=basis_type, &
1176 task_list_external=task_list)
1178 CALL integrate_v_rspace(v_rspace=v_hartree_rspace, &
1180 pmat=matrix_p(ispin, 1), &
1182 calculate_forces=.true., &
1183 basis_type=basis_type, &
1184 task_list_external=ec_env%task_list)
1186 CALL pw_axpy(v_hartree_rspace, v_rspace(ispin))
1188 CALL integrate_v_rspace(v_rspace=v_rspace(ispin), &
1190 pmat=matrix_p(ispin, 1), &
1192 calculate_forces=.true., &
1193 basis_type=basis_type, &
1194 task_list_external=task_list)
1198 IF (debug_forces)
THEN
1199 fodeb(1:3) = force(1)%rho_elec(1:3, 1) - fodeb(1:3)
1200 CALL para_env%sum(fodeb)
1201 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Pout*dVhxc ", fodeb
1203 IF (debug_stress .AND. use_virial)
THEN
1204 stdeb = fconv*(virial%pv_virial - stdeb)
1205 CALL para_env%sum(stdeb)
1206 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1210 IF (
ASSOCIATED(v_tau_rspace))
THEN
1211 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
1212 IF (debug_stress .AND. use_virial) stdeb = virial%pv_virial
1213 DO ispin = 1, nspins
1214 CALL pw_scale(v_tau_rspace(ispin), v_tau_rspace(ispin)%pw_grid%dvol)
1216 CALL integrate_v_rspace(v_rspace=v_tau_rspace(ispin), &
1218 pmat=matrix_p(ispin, 1), &
1220 calculate_forces=.true., &
1221 compute_tau=.true., &
1222 basis_type=basis_type, &
1223 task_list_external=task_list)
1226 IF (debug_forces)
THEN
1227 fodeb(1:3) = force(1)%rho_elec(1:3, 1) - fodeb(1:3)
1228 CALL para_env%sum(fodeb)
1229 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Pout*dVhxc_tau ", fodeb
1231 IF (debug_stress .AND. use_virial)
THEN
1232 stdeb = fconv*(virial%pv_virial - stdeb)
1233 CALL para_env%sum(stdeb)
1234 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1239 IF (gapw .OR. gapw_xc)
THEN
1242 rho_atom_set_external=local_rho_set%rho_atom_set, &
1243 xc_section_external=ec_env%xc_section)
1246 IF (debug_forces) fodeb(1:3) = force(1)%g0s_Vh_elec(1:3, 1)
1248 calculate_forces=.true., local_rho_set=local_rho_set)
1249 IF (debug_forces)
THEN
1250 fodeb(1:3) = force(1)%g0s_Vh_elec(1:3, 1) - fodeb(1:3)
1251 CALL para_env%sum(fodeb)
1252 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: P*g0s_Vh_elec ", fodeb
1254 ehartree_1c = 0.0_dp
1255 CALL vh_1c_gg_integrals(qs_env, ehartree_1c, hartree_local%ecoul_1c, local_rho_set, &
1256 para_env, tddft=.false., core_2nd=.false.)
1259 IF (gapw .OR. gapw_xc)
THEN
1261 IF (debug_forces) fodeb(1:3) = force(1)%vhxc_atom(1:3, 1)
1263 rho_atom_external=local_rho_set%rho_atom_set)
1264 IF (debug_forces)
THEN
1265 fodeb(1:3) = force(1)%vhxc_atom(1:3, 1) - fodeb(1:3)
1266 CALL para_env%sum(fodeb)
1267 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: P*vhxc_atom ", fodeb
1272 IF (use_virial)
THEN
1273 virial%pv_ehartree = virial%pv_ehartree + (virial%pv_virial - pv_loc)
1292 NULLIFY (ec_env%matrix_hz)
1294 DO ispin = 1, nspins
1295 ALLOCATE (ec_env%matrix_hz(ispin)%matrix)
1296 CALL dbcsr_create(ec_env%matrix_hz(ispin)%matrix, template=matrix_s(1)%matrix)
1297 CALL dbcsr_copy(ec_env%matrix_hz(ispin)%matrix, matrix_s(1)%matrix)
1298 CALL dbcsr_set(ec_env%matrix_hz(ispin)%matrix, 0.0_dp)
1301 DO ispin = 1, nspins
1304 CALL pw_axpy(v_rspace_in(ispin), v_rspace(ispin), -1.0_dp)
1307 DO ispin = 1, nspins
1308 CALL integrate_v_rspace(v_rspace=v_rspace(ispin), &
1309 hmat=ec_env%matrix_hz(ispin), &
1310 pmat=matrix_p(ispin, 1), &
1312 calculate_forces=.false., &
1313 basis_type=basis_type, &
1314 task_list_external=task_list)
1318 IF (dft_control%use_kinetic_energy_density)
THEN
1321 IF (.NOT.
ASSOCIATED(v_tau_rspace))
THEN
1322 ALLOCATE (v_tau_rspace(nspins))
1323 DO ispin = 1, nspins
1324 CALL auxbas_pw_pool%create_pw(v_tau_rspace(ispin))
1325 CALL pw_zero(v_tau_rspace(ispin))
1329 DO ispin = 1, nspins
1331 IF (
ASSOCIATED(ec_env%vtau_rspace))
THEN
1332 CALL pw_axpy(ec_env%vtau_rspace(ispin), v_tau_rspace(ispin), -1.0_dp)
1335 CALL integrate_v_rspace(v_rspace=v_tau_rspace(ispin), &
1336 hmat=ec_env%matrix_hz(ispin), &
1337 pmat=matrix_p(ispin, 1), &
1339 calculate_forces=.false., compute_tau=.true., &
1340 basis_type=basis_type, &
1341 task_list_external=task_list)
1345 IF (gapw .OR. gapw_xc)
THEN
1348 CALL update_ks_atom(qs_env, ec_env%matrix_hz, matrix_p, .false., &
1349 rho_atom_external=local_rho_set%rho_atom_set, kintegral=1.0_dp)
1351 CALL update_ks_atom(qs_env, ec_env%matrix_hz, matrix_p, .false., &
1352 rho_atom_external=ec_env%local_rho_set%rho_atom_set, kintegral=-1.0_dp)
1359 ext_hfx_section=ec_hfx_sections, &
1360 x_data=ec_env%x_data, &
1361 recalc_integrals=.false., &
1362 do_admm=ec_env%do_ec_admm, &
1365 reuse_hfx=ec_env%reuse_hfx)
1368 IF (debug_forces) fodeb(1:3) = force(1)%core_overlap(1:3, 1)
1369 IF (debug_stress .AND. use_virial) stdeb = virial%pv_ecore_overlap
1371 IF (debug_forces)
THEN
1372 fodeb(1:3) = force(1)%core_overlap(1:3, 1) - fodeb(1:3)
1373 CALL para_env%sum(fodeb)
1374 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: CoreOverlap", fodeb
1376 IF (debug_stress .AND. use_virial)
THEN
1377 stdeb = fconv*(stdeb - virial%pv_ecore_overlap)
1378 CALL para_env%sum(stdeb)
1379 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1383 IF (debug_forces)
THEN
1384 CALL get_qs_env(qs_env, natom=natom, atomic_kind_set=atomic_kind_set)
1385 ALLOCATE (ftot(3, natom))
1387 fodeb(1:3) = ftot(1:3, 1)
1389 CALL para_env%sum(fodeb)
1390 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Force Explicit", fodeb
1394 IF (gapw .OR. gapw_xc)
THEN
1402 DO ispin = 1, nspins
1403 CALL auxbas_pw_pool%give_back_pw(v_rspace(ispin))
1404 CALL auxbas_pw_pool%give_back_pw(v_rspace_in(ispin))
1405 IF (
ASSOCIATED(v_tau_rspace))
THEN
1406 CALL auxbas_pw_pool%give_back_pw(v_tau_rspace(ispin))
1410 DEALLOCATE (v_rspace, v_rspace_in)
1411 IF (
ASSOCIATED(v_tau_rspace))
DEALLOCATE (v_tau_rspace)
1413 CALL auxbas_pw_pool%give_back_pw(rho_tot_gspace)
1414 CALL auxbas_pw_pool%give_back_pw(v_hartree_gspace)
1415 CALL auxbas_pw_pool%give_back_pw(v_hartree_rspace)
1419 IF (use_virial)
THEN
1420 IF (qs_env%energy_correction)
THEN
1421 ec_env%ehartree = ehartree
1426 IF (debug_stress .AND. use_virial)
THEN
1428 stdeb = -1.0_dp*fconv*ehartree
1429 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1432 stdeb = -1.0_dp*fconv*exc
1433 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1442 CALL para_env%sum(virdeb%pv_overlap)
1443 CALL para_env%sum(virdeb%pv_ekinetic)
1444 CALL para_env%sum(virdeb%pv_ppl)
1445 CALL para_env%sum(virdeb%pv_ppnl)
1446 CALL para_env%sum(virdeb%pv_ecore_overlap)
1447 CALL para_env%sum(virdeb%pv_ehartree)
1448 CALL para_env%sum(virdeb%pv_exc)
1449 CALL para_env%sum(virdeb%pv_exx)
1450 CALL para_env%sum(virdeb%pv_vdw)
1451 CALL para_env%sum(virdeb%pv_mp2)
1452 CALL para_env%sum(virdeb%pv_nlcc)
1453 CALL para_env%sum(virdeb%pv_gapw)
1454 CALL para_env%sum(virdeb%pv_lrigpw)
1455 CALL para_env%sum(virdeb%pv_virial)
1460 virdeb%pv_ehartree(i, i) = virdeb%pv_ehartree(i, i) - 2.0_dp*ehartree
1461 virdeb%pv_virial(i, i) = virdeb%pv_virial(i, i) - exc &
1463 virdeb%pv_exc(i, i) = virdeb%pv_exc(i, i) - exc
1469 CALL para_env%sum(sttot)
1470 stdeb = fconv*(virdeb%pv_virial - sttot)
1471 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1474 stdeb = fconv*(virdeb%pv_virial)
1475 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1485 CALL timestop(handle)
1487 END SUBROUTINE ec_dc_build_ks_matrix_force
1495 SUBROUTINE ec_disp(qs_env, ec_env, calculate_forces)
1496 TYPE(qs_environment_type),
POINTER :: qs_env
1497 TYPE(energy_correction_type),
POINTER :: ec_env
1498 LOGICAL,
INTENT(IN) :: calculate_forces
1500 REAL(kind=dp) :: edisp, egcp
1503 CALL calculate_dispersion_pairpot(qs_env, ec_env%dispersion_env, edisp, calculate_forces)
1504 IF (.NOT. calculate_forces)
THEN
1505 ec_env%edispersion = ec_env%edispersion + edisp + egcp
1508 END SUBROUTINE ec_disp
1517 SUBROUTINE ec_build_core_hamiltonian(qs_env, ec_env)
1518 TYPE(qs_environment_type),
POINTER :: qs_env
1519 TYPE(energy_correction_type),
POINTER :: ec_env
1521 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ec_build_core_hamiltonian'
1523 CHARACTER(LEN=default_string_length) :: basis_type
1524 INTEGER :: handle, img, nder, nhfimg, nimages
1525 LOGICAL :: calculate_forces, use_virial
1526 TYPE(atomic_kind_type),
DIMENSION(:),
POINTER :: atomic_kind_set
1527 TYPE(dbcsr_type),
POINTER :: smat
1528 TYPE(dft_control_type),
POINTER :: dft_control
1529 TYPE(neighbor_list_set_p_type),
DIMENSION(:), &
1530 POINTER :: sab_orb, sac_ae, sac_ppl, sap_ppnl
1531 TYPE(particle_type),
DIMENSION(:),
POINTER :: particle_set
1532 TYPE(qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
1533 TYPE(qs_ks_env_type),
POINTER :: ks_env
1535 CALL timeset(routinen, handle)
1537 NULLIFY (atomic_kind_set, dft_control, ks_env, particle_set, &
1540 CALL get_qs_env(qs_env=qs_env, &
1541 atomic_kind_set=atomic_kind_set, &
1542 dft_control=dft_control, &
1543 particle_set=particle_set, &
1544 qs_kind_set=qs_kind_set, &
1548 nimages = dft_control%nimages
1549 IF (nimages /= 1)
THEN
1550 cpabort(
"K-points for Harris functional not implemented")
1554 IF (dft_control%qs_control%gapw .OR. dft_control%qs_control%gapw_xc)
THEN
1555 cpabort(
"Harris functional for GAPW not implemented")
1559 use_virial = .false.
1560 calculate_forces = .false.
1563 NULLIFY (sab_orb, sac_ae, sac_ppl, sap_ppnl)
1564 sab_orb => ec_env%sab_orb
1565 sac_ae => ec_env%sac_ae
1566 sac_ppl => ec_env%sac_ppl
1567 sap_ppnl => ec_env%sap_ppnl
1569 basis_type =
"HARRIS"
1573 CALL build_overlap_matrix(ks_env, matrixkp_s=ec_env%matrix_s, &
1574 matrix_name=
"OVERLAP MATRIX", &
1575 basis_type_a=basis_type, &
1576 basis_type_b=basis_type, &
1577 sab_nl=sab_orb, ext_kpoints=ec_env%kpoints)
1578 CALL build_kinetic_matrix(ks_env, matrixkp_t=ec_env%matrix_t, &
1579 matrix_name=
"KINETIC ENERGY MATRIX", &
1580 basis_type=basis_type, &
1581 sab_nl=sab_orb, ext_kpoints=ec_env%kpoints)
1584 nhfimg =
SIZE(ec_env%matrix_s, 2)
1585 CALL dbcsr_allocate_matrix_set(ec_env%matrix_h, 1, nhfimg)
1587 ALLOCATE (ec_env%matrix_h(1, img)%matrix)
1588 smat => ec_env%matrix_s(1, img)%matrix
1589 CALL dbcsr_create(ec_env%matrix_h(1, img)%matrix, template=smat)
1590 CALL cp_dbcsr_alloc_block_from_nbl(ec_env%matrix_h(1, img)%matrix, sab_orb)
1595 CALL dbcsr_copy(ec_env%matrix_h(1, img)%matrix, ec_env%matrix_t(1, img)%matrix, &
1596 keep_sparsity=.true., name=
"CORE HAMILTONIAN MATRIX")
1599 CALL core_matrices(qs_env, ec_env%matrix_h, ec_env%matrix_p, calculate_forces, nder, &
1600 ec_env=ec_env, ec_env_matrices=.true., ext_kpoints=ec_env%kpoints, &
1601 basis_type=basis_type)
1604 ec_env%efield_nuclear = 0.0_dp
1605 CALL ec_efield_local_operator(qs_env, ec_env, calculate_forces)
1607 CALL timestop(handle)
1609 END SUBROUTINE ec_build_core_hamiltonian
1620 SUBROUTINE ec_build_ks_matrix(qs_env, ec_env)
1621 TYPE(qs_environment_type),
POINTER :: qs_env
1622 TYPE(energy_correction_type),
POINTER :: ec_env
1624 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ec_build_ks_matrix'
1626 CHARACTER(LEN=default_string_length) :: headline
1627 INTEGER :: handle, img, iounit, ispin, natom, &
1628 nhfimg, nimages, nspins
1629 LOGICAL :: calculate_forces, &
1630 do_adiabatic_rescaling, do_ec_hfx, &
1631 gapw, gapw_xc, hfx_treat_lsd_in_core, &
1633 REAL(dp) :: dummy_real, dummy_real2(2), eexc, eh1c, &
1635 TYPE(admm_type),
POINTER :: admm_env
1636 TYPE(atomic_kind_type),
DIMENSION(:),
POINTER :: atomic_kind_set
1637 TYPE(cp_logger_type),
POINTER :: logger
1638 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: ks_mat, ps_mat
1639 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: rho_ao_kp
1640 TYPE(dbcsr_type),
POINTER :: smat
1641 TYPE(dft_control_type),
POINTER :: dft_control
1642 TYPE(hartree_local_type),
POINTER :: hartree_local
1643 TYPE(local_rho_type),
POINTER :: local_rho_set_ec
1644 TYPE(mp_para_env_type),
POINTER :: para_env
1645 TYPE(neighbor_list_set_p_type),
DIMENSION(:), &
1647 TYPE(oce_matrix_type),
POINTER :: oce
1648 TYPE(pw_env_type),
POINTER :: pw_env
1649 TYPE(pw_pool_type),
POINTER :: auxbas_pw_pool
1650 TYPE(pw_r3d_rs_type),
DIMENSION(:),
POINTER :: rho_r, tau_r, v_rspace, v_tau_rspace
1651 TYPE(qs_energy_type),
POINTER :: energy
1652 TYPE(qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
1653 TYPE(qs_ks_env_type),
POINTER :: ks_env
1654 TYPE(qs_rho_type),
POINTER :: rho, rho_xc
1655 TYPE(section_vals_type),
POINTER :: adiabatic_rescaling_section, &
1656 ec_hfx_sections, ec_section
1658 CALL timeset(routinen, handle)
1660 logger => cp_get_default_logger()
1661 IF (logger%para_env%is_source())
THEN
1662 iounit = cp_logger_get_default_unit_nr(logger, local=.true.)
1668 NULLIFY (auxbas_pw_pool, dft_control, energy, ks_env, rho, rho_r, tau_r)
1669 CALL get_qs_env(qs_env=qs_env, &
1670 dft_control=dft_control, &
1672 rho=rho, rho_xc=rho_xc)
1673 nspins = dft_control%nspins
1674 nimages = dft_control%nimages
1675 calculate_forces = .false.
1676 use_virial = .false.
1678 gapw = dft_control%qs_control%gapw
1679 gapw_xc = dft_control%qs_control%gapw_xc
1682 IF (
ASSOCIATED(ec_env%matrix_ks))
CALL dbcsr_deallocate_matrix_set(ec_env%matrix_ks)
1683 nhfimg =
SIZE(ec_env%matrix_s, 2)
1684 dft_control%nimages = nhfimg
1685 CALL dbcsr_allocate_matrix_set(ec_env%matrix_ks, nspins, nhfimg)
1686 DO ispin = 1, nspins
1687 headline =
"KOHN-SHAM MATRIX"
1689 ALLOCATE (ec_env%matrix_ks(ispin, img)%matrix)
1690 smat => ec_env%matrix_s(1, img)%matrix
1691 CALL dbcsr_create(ec_env%matrix_ks(ispin, img)%matrix, name=trim(headline), &
1692 template=smat, matrix_type=dbcsr_type_symmetric)
1693 CALL cp_dbcsr_alloc_block_from_nbl(ec_env%matrix_ks(ispin, img)%matrix, &
1695 CALL dbcsr_set(ec_env%matrix_ks(ispin, img)%matrix, 0.0_dp)
1700 CALL get_qs_env(qs_env=qs_env, pw_env=pw_env)
1701 cpassert(
ASSOCIATED(pw_env))
1704 ec_section => section_vals_get_subs_vals(qs_env%input,
"DFT%ENERGY_CORRECTION")
1705 ec_hfx_sections => section_vals_get_subs_vals(ec_section,
"XC%HF")
1706 CALL section_vals_get(ec_hfx_sections, explicit=do_ec_hfx)
1711 adiabatic_rescaling_section => section_vals_get_subs_vals(ec_section,
"XC%ADIABATIC_RESCALING")
1712 CALL section_vals_get(adiabatic_rescaling_section, explicit=do_adiabatic_rescaling)
1713 IF (do_adiabatic_rescaling)
THEN
1714 CALL cp_abort(__location__,
"Adiabatic rescaling NYI for energy correction")
1716 CALL section_vals_val_get(ec_hfx_sections,
"TREAT_LSD_IN_CORE", l_val=hfx_treat_lsd_in_core)
1717 IF (hfx_treat_lsd_in_core)
THEN
1718 CALL cp_abort(__location__,
"HFX_TREAT_LSD_IN_CORE NYI for energy correction")
1720 IF (ec_env%do_kpoints)
THEN
1721 CALL cp_abort(__location__,
"HFX and K-points NYI for energy correction")
1725 IF (dft_control%do_admm)
THEN
1726 IF (dft_control%do_admm_mo)
THEN
1727 cpassert(.NOT. qs_env%run_rtp)
1728 CALL admm_mo_calc_rho_aux(qs_env)
1729 ELSEIF (dft_control%do_admm_dm)
THEN
1730 CALL admm_dm_calc_rho_aux(qs_env)
1737 CALL get_qs_env(qs_env, energy=energy)
1738 CALL calculate_exx(qs_env=qs_env, &
1740 hfx_sections=ec_hfx_sections, &
1741 x_data=ec_env%x_data, &
1743 do_admm=ec_env%do_ec_admm, &
1744 calc_forces=.false., &
1745 reuse_hfx=ec_env%reuse_hfx, &
1746 do_im_time=.false., &
1747 e_ex_from_gw=dummy_real, &
1748 e_admm_from_gw=dummy_real2, &
1752 ec_env%ex = energy%ex
1754 IF (ec_env%do_ec_admm)
THEN
1755 ec_env%exc_aux_fit = energy%exc_aux_fit + energy%exc
1761 ks_mat => ec_env%matrix_ks(:, 1)
1762 CALL add_exx_to_rhs(rhs=ks_mat, &
1764 ext_hfx_section=ec_hfx_sections, &
1765 x_data=ec_env%x_data, &
1766 recalc_integrals=.false., &
1767 do_admm=ec_env%do_ec_admm, &
1770 reuse_hfx=ec_env%reuse_hfx)
1775 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
1776 NULLIFY (v_rspace, v_tau_rspace)
1777 IF (dft_control%qs_control%gapw_xc)
THEN
1778 CALL qs_vxc_create(ks_env=ks_env, rho_struct=rho_xc, xc_section=ec_env%xc_section, &
1779 vxc_rho=v_rspace, vxc_tau=v_tau_rspace, exc=eexc, just_energy=.false.)
1781 CALL qs_vxc_create(ks_env=ks_env, rho_struct=rho, xc_section=ec_env%xc_section, &
1782 vxc_rho=v_rspace, vxc_tau=v_tau_rspace, exc=eexc, just_energy=.false.)
1785 IF (.NOT.
ASSOCIATED(v_rspace))
THEN
1786 ALLOCATE (v_rspace(nspins))
1787 DO ispin = 1, nspins
1788 CALL auxbas_pw_pool%create_pw(v_rspace(ispin))
1789 CALL pw_zero(v_rspace(ispin))
1794 CALL qs_rho_get(rho, rho_r=rho_r)
1795 IF (
ASSOCIATED(v_tau_rspace))
THEN
1796 CALL qs_rho_get(rho, tau_r=tau_r)
1798 DO ispin = 1, nspins
1800 CALL pw_scale(v_rspace(ispin), v_rspace(ispin)%pw_grid%dvol)
1801 CALL pw_axpy(ec_env%vh_rspace, v_rspace(ispin))
1803 ks_mat => ec_env%matrix_ks(ispin, :)
1804 CALL integrate_v_rspace(v_rspace=v_rspace(ispin), &
1807 calculate_forces=.false., &
1808 basis_type=
"HARRIS", &
1809 task_list_external=ec_env%task_list)
1811 IF (
ASSOCIATED(v_tau_rspace))
THEN
1813 CALL pw_scale(v_tau_rspace(ispin), v_tau_rspace(ispin)%pw_grid%dvol)
1814 CALL integrate_v_rspace(v_rspace=v_tau_rspace(ispin), &
1817 calculate_forces=.false., &
1818 compute_tau=.true., &
1819 basis_type=
"HARRIS", &
1820 task_list_external=ec_env%task_list)
1824 evhxc = evhxc + pw_integral_ab(rho_r(ispin), v_rspace(ispin))/ &
1825 v_rspace(1)%pw_grid%dvol
1826 IF (
ASSOCIATED(v_tau_rspace))
THEN
1827 evhxc = evhxc + pw_integral_ab(tau_r(ispin), v_tau_rspace(ispin))/ &
1828 v_tau_rspace(ispin)%pw_grid%dvol
1833 IF (gapw .OR. gapw_xc)
THEN
1835 IF (ec_env%basis_inconsistent)
THEN
1836 cpabort(
"Energy corrction [GAPW] only with BASIS=ORBITAL possible")
1839 NULLIFY (hartree_local, local_rho_set_ec)
1840 CALL get_qs_env(qs_env, para_env=para_env, &
1841 atomic_kind_set=atomic_kind_set, &
1842 qs_kind_set=qs_kind_set)
1843 CALL local_rho_set_create(local_rho_set_ec)
1844 CALL allocate_rho_atom_internals(local_rho_set_ec%rho_atom_set, atomic_kind_set, &
1845 qs_kind_set, dft_control, para_env)
1847 CALL get_qs_env(qs_env, natom=natom)
1848 CALL init_rho0(local_rho_set_ec, qs_env, dft_control%qs_control%gapw_control)
1849 CALL rho0_s_grid_create(pw_env, local_rho_set_ec%rho0_mpole)
1850 CALL hartree_local_create(hartree_local)
1851 CALL init_coulomb_local(hartree_local, natom)
1854 CALL get_qs_env(qs_env=qs_env, oce=oce, sab_orb=sab)
1855 CALL qs_rho_get(rho, rho_ao_kp=rho_ao_kp)
1856 CALL calculate_rho_atom_coeff(qs_env, rho_ao_kp, local_rho_set_ec%rho_atom_set, &
1857 qs_kind_set, oce, sab, para_env)
1858 CALL prepare_gapw_den(qs_env, local_rho_set_ec, do_rho0=gapw)
1860 CALL calculate_vxc_atom(qs_env, .false., exc1=exc1, xc_section_external=ec_env%xc_section, &
1861 rho_atom_set_external=local_rho_set_ec%rho_atom_set)
1865 CALL vh_1c_gg_integrals(qs_env, eh1c, hartree_local%ecoul_1c, local_rho_set_ec, para_env, .false.)
1866 CALL integrate_vhg0_rspace(qs_env, ec_env%vh_rspace, para_env, calculate_forces=.false., &
1867 local_rho_set=local_rho_set_ec)
1868 ec_env%ehartree_1c = eh1c
1870 IF (dft_control%do_admm)
THEN
1871 CALL get_qs_env(qs_env, admm_env=admm_env)
1872 IF (admm_env%aux_exch_func /= do_admm_aux_exch_func_none)
THEN
1874 cpabort(
"GAPW HFX ADMM + Energy Correction NYA")
1878 ks_mat => ec_env%matrix_ks(:, 1)
1879 ps_mat => ec_env%matrix_p(:, 1)
1880 CALL update_ks_atom(qs_env, ks_mat, ps_mat, forces=.false., &
1881 rho_atom_external=local_rho_set_ec%rho_atom_set)
1883 CALL local_rho_set_release(local_rho_set_ec)
1885 CALL hartree_local_release(hartree_local)
1891 DO ispin = 1, nspins
1892 CALL auxbas_pw_pool%give_back_pw(v_rspace(ispin))
1893 IF (
ASSOCIATED(v_tau_rspace))
THEN
1894 CALL auxbas_pw_pool%give_back_pw(v_tau_rspace(ispin))
1897 DEALLOCATE (v_rspace)
1898 IF (
ASSOCIATED(v_tau_rspace))
DEALLOCATE (v_tau_rspace)
1905 DO ispin = 1, nspins
1907 CALL dbcsr_add(ec_env%matrix_ks(ispin, img)%matrix, ec_env%matrix_h(1, img)%matrix, &
1908 alpha_scalar=1.0_dp, beta_scalar=1.0_dp)
1909 CALL dbcsr_filter(ec_env%matrix_ks(ispin, img)%matrix, &
1910 dft_control%qs_control%eps_filter_matrix)
1914 dft_control%nimages = nimages
1916 CALL timestop(handle)
1918 END SUBROUTINE ec_build_ks_matrix
1930 SUBROUTINE ec_build_core_hamiltonian_force(qs_env, ec_env, matrix_p, matrix_s, matrix_w)
1931 TYPE(qs_environment_type),
POINTER :: qs_env
1932 TYPE(energy_correction_type),
POINTER :: ec_env
1933 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_p, matrix_s, matrix_w
1935 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ec_build_core_hamiltonian_force'
1937 CHARACTER(LEN=default_string_length) :: basis_type
1938 INTEGER :: handle, img, iounit, nder, nhfimg, &
1940 LOGICAL :: calculate_forces, debug_forces, &
1941 debug_stress, use_virial
1942 REAL(kind=dp) :: fconv
1943 REAL(kind=dp),
DIMENSION(3) :: fodeb
1944 REAL(kind=dp),
DIMENSION(3, 3) :: stdeb, sttot
1945 TYPE(cell_type),
POINTER :: cell
1946 TYPE(cp_logger_type),
POINTER :: logger
1947 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: scrm
1948 TYPE(dft_control_type),
POINTER :: dft_control
1949 TYPE(mp_para_env_type),
POINTER :: para_env
1950 TYPE(neighbor_list_set_p_type),
DIMENSION(:), &
1952 TYPE(qs_force_type),
DIMENSION(:),
POINTER :: force
1953 TYPE(qs_ks_env_type),
POINTER :: ks_env
1954 TYPE(virial_type),
POINTER :: virial
1956 CALL timeset(routinen, handle)
1958 debug_forces = ec_env%debug_forces
1959 debug_stress = ec_env%debug_stress
1961 logger => cp_get_default_logger()
1962 IF (logger%para_env%is_source())
THEN
1963 iounit = cp_logger_get_default_unit_nr(logger, local=.true.)
1968 calculate_forces = .true.
1970 basis_type =
"HARRIS"
1973 NULLIFY (cell, dft_control, force, ks_env, para_env, virial)
1974 CALL get_qs_env(qs_env=qs_env, &
1976 dft_control=dft_control, &
1979 para_env=para_env, &
1981 nimages = dft_control%nimages
1982 IF (nimages /= 1)
THEN
1983 cpabort(
"K-points for Harris functional not implemented")
1986 IF (dft_control%qs_control%gapw .OR. dft_control%qs_control%gapw_xc)
THEN
1987 IF (ec_env%energy_functional == ec_functional_harris)
THEN
1988 cpabort(
"Harris functional for GAPW not implemented")
1993 use_virial = virial%pv_availability .AND. (.NOT. virial%pv_numer)
1995 fconv = 1.0e-9_dp*pascal/cell%deth
1996 IF (debug_stress .AND. use_virial)
THEN
1997 sttot = virial%pv_virial
2001 sab_orb => ec_env%sab_orb
2004 nhfimg =
SIZE(matrix_s, 2)
2006 CALL dbcsr_allocate_matrix_set(scrm, 1, nhfimg)
2008 ALLOCATE (scrm(1, img)%matrix)
2009 CALL dbcsr_create(scrm(1, img)%matrix, template=matrix_s(1, img)%matrix)
2010 CALL cp_dbcsr_alloc_block_from_nbl(scrm(1, img)%matrix, sab_orb)
2014 IF (
SIZE(matrix_p, 1) == 2)
THEN
2016 CALL dbcsr_add(matrix_w(1, img)%matrix, matrix_w(2, img)%matrix, &
2017 alpha_scalar=1.0_dp, beta_scalar=1.0_dp)
2022 IF (debug_forces) fodeb(1:3) = force(1)%overlap(1:3, 1)
2023 IF (debug_stress .AND. use_virial) stdeb = virial%pv_overlap
2024 CALL build_overlap_matrix(ks_env, matrixkp_s=scrm, &
2025 matrix_name=
"OVERLAP MATRIX", &
2026 basis_type_a=basis_type, &
2027 basis_type_b=basis_type, &
2028 sab_nl=sab_orb, calculate_forces=.true., &
2029 matrixkp_p=matrix_w, ext_kpoints=ec_env%kpoints)
2031 IF (debug_forces)
THEN
2032 fodeb(1:3) = force(1)%overlap(1:3, 1) - fodeb(1:3)
2033 CALL para_env%sum(fodeb)
2034 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Wout*dS ", fodeb
2036 IF (debug_stress .AND. use_virial)
THEN
2037 stdeb = fconv*(virial%pv_overlap - stdeb)
2038 CALL para_env%sum(stdeb)
2039 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2040 'STRESS| Wout*dS', one_third_sum_diag(stdeb), det_3x3(stdeb)
2043 CALL kinetic_energy_matrix(qs_env, matrixkp_t=scrm, matrix_p=matrix_p, &
2044 calculate_forces=.true., sab_orb=sab_orb, &
2045 basis_type=basis_type, ext_kpoints=ec_env%kpoints, &
2046 debug_forces=debug_forces, debug_stress=debug_stress)
2048 CALL core_matrices(qs_env, scrm, matrix_p, calculate_forces, nder, &
2049 ec_env=ec_env, ec_env_matrices=.false., basis_type=basis_type, &
2050 ext_kpoints=ec_env%kpoints, &
2051 debug_forces=debug_forces, debug_stress=debug_stress)
2054 ec_env%efield_nuclear = 0.0_dp
2055 IF (calculate_forces .AND. debug_forces) fodeb(1:3) = force(1)%efield(1:3, 1)
2056 CALL ec_efield_local_operator(qs_env, ec_env, calculate_forces)
2057 IF (calculate_forces .AND. debug_forces)
THEN
2058 fodeb(1:3) = force(1)%efield(1:3, 1) - fodeb(1:3)
2059 CALL para_env%sum(fodeb)
2060 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Pout*dEfield", fodeb
2062 IF (debug_stress .AND. use_virial)
THEN
2063 stdeb = fconv*(virial%pv_virial - sttot)
2064 CALL para_env%sum(stdeb)
2065 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2066 'STRESS| Stress Pout*dHcore ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2067 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))")
' '
2071 CALL dbcsr_deallocate_matrix_set(scrm)
2073 CALL timestop(handle)
2075 END SUBROUTINE ec_build_core_hamiltonian_force
2086 SUBROUTINE ec_build_ks_matrix_force(qs_env, ec_env)
2087 TYPE(qs_environment_type),
POINTER :: qs_env
2088 TYPE(energy_correction_type),
POINTER :: ec_env
2090 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ec_build_ks_matrix_force'
2092 CHARACTER(LEN=default_string_length) :: unit_string
2093 INTEGER :: handle, i, img, iounit, ispin, natom, &
2094 nhfimg, nimages, nspins
2095 LOGICAL :: debug_forces, debug_stress, do_ec_hfx, &
2097 REAL(dp) :: dehartree, dummy_real, dummy_real2(2), &
2098 eexc, ehartree, eovrl, exc, fconv
2099 REAL(dp),
ALLOCATABLE,
DIMENSION(:, :) :: ftot
2100 REAL(dp),
DIMENSION(3) :: fodeb
2101 REAL(kind=dp),
DIMENSION(3, 3) :: h_stress, pv_loc, stdeb, sttot
2102 TYPE(atomic_kind_type),
DIMENSION(:),
POINTER :: atomic_kind_set
2103 TYPE(cell_type),
POINTER :: cell
2104 TYPE(cp_logger_type),
POINTER :: logger
2105 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_ks, rho_ao, scrmat
2106 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_p, matrix_s, scrm
2107 TYPE(dft_control_type),
POINTER :: dft_control
2108 TYPE(mp_para_env_type),
POINTER :: para_env
2109 TYPE(neighbor_list_set_p_type),
DIMENSION(:), &
2111 TYPE(pw_c1d_gs_type) :: rho_tot_gspace, rhodn_tot_gspace, &
2113 TYPE(pw_c1d_gs_type),
DIMENSION(:),
POINTER :: rho_g, rhoout_g
2114 TYPE(pw_c1d_gs_type),
POINTER :: rho_core
2115 TYPE(pw_env_type),
POINTER :: pw_env
2116 TYPE(pw_poisson_type),
POINTER :: poisson_env
2117 TYPE(pw_pool_type),
POINTER :: auxbas_pw_pool
2118 TYPE(pw_r3d_rs_type) :: dv_hartree_rspace, v_hartree_rspace, &
2120 TYPE(pw_r3d_rs_type),
DIMENSION(:),
POINTER :: rho_r, rhoout_r, tau_r, tauout_r, &
2121 v_rspace, v_tau_rspace, v_xc, v_xc_tau
2122 TYPE(qs_force_type),
DIMENSION(:),
POINTER :: force
2123 TYPE(qs_ks_env_type),
POINTER :: ks_env
2124 TYPE(qs_rho_type),
POINTER :: rho
2125 TYPE(section_vals_type),
POINTER :: ec_hfx_sections, xc_section
2126 TYPE(virial_type),
POINTER :: virial
2128 CALL timeset(routinen, handle)
2130 debug_forces = ec_env%debug_forces
2131 debug_stress = ec_env%debug_stress
2133 logger => cp_get_default_logger()
2134 IF (logger%para_env%is_source())
THEN
2135 iounit = cp_logger_get_default_unit_nr(logger, local=.true.)
2141 NULLIFY (atomic_kind_set, cell, dft_control, force, ks_env, &
2142 matrix_ks, matrix_p, matrix_s, para_env, rho, rho_core, &
2143 rho_g, rho_r, sab_orb, tau_r, virial)
2144 CALL get_qs_env(qs_env=qs_env, &
2146 dft_control=dft_control, &
2149 matrix_ks=matrix_ks, &
2150 para_env=para_env, &
2155 nspins = dft_control%nspins
2156 use_virial = virial%pv_availability .AND. (.NOT. virial%pv_numer)
2160 fconv = cp_unit_from_cp2k(1.0_dp/cell%deth, trim(unit_string))
2162 IF (debug_stress .AND. use_virial)
THEN
2163 sttot = virial%pv_virial
2167 CALL get_qs_env(qs_env=qs_env, pw_env=pw_env)
2168 cpassert(
ASSOCIATED(pw_env))
2170 NULLIFY (auxbas_pw_pool, poisson_env)
2172 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool, &
2173 poisson_env=poisson_env)
2176 CALL auxbas_pw_pool%create_pw(v_hartree_gspace)
2177 CALL auxbas_pw_pool%create_pw(rhodn_tot_gspace)
2178 CALL auxbas_pw_pool%create_pw(v_hartree_rspace)
2180 CALL pw_transfer(ec_env%vh_rspace, v_hartree_rspace)
2185 CALL qs_rho_get(rho, rho_r=rho_r, rho_g=rho_g, tau_r=tau_r)
2186 NULLIFY (rhoout_r, rhoout_g)
2187 ALLOCATE (rhoout_r(nspins), rhoout_g(nspins))
2188 DO ispin = 1, nspins
2189 CALL auxbas_pw_pool%create_pw(rhoout_r(ispin))
2190 CALL auxbas_pw_pool%create_pw(rhoout_g(ispin))
2192 CALL auxbas_pw_pool%create_pw(dv_hartree_rspace)
2193 CALL auxbas_pw_pool%create_pw(vtot_rspace)
2196 nhfimg =
SIZE(ec_env%matrix_s, 2)
2197 nimages = dft_control%nimages
2198 dft_control%nimages = nhfimg
2200 CALL pw_zero(rhodn_tot_gspace)
2201 DO ispin = 1, nspins
2202 rho_ao => ec_env%matrix_p(ispin, :)
2203 CALL calculate_rho_elec(ks_env=ks_env, matrix_p_kp=rho_ao, &
2204 rho=rhoout_r(ispin), &
2205 rho_gspace=rhoout_g(ispin), &
2206 basis_type=
"HARRIS", &
2207 task_list_external=ec_env%task_list)
2211 ALLOCATE (ec_env%rhoout_r(nspins))
2212 DO ispin = 1, nspins
2213 CALL auxbas_pw_pool%create_pw(ec_env%rhoout_r(ispin))
2214 CALL pw_copy(rhoout_r(ispin), ec_env%rhoout_r(ispin))
2218 IF (dft_control%use_kinetic_energy_density)
THEN
2220 TYPE(pw_c1d_gs_type) :: tauout_g
2221 ALLOCATE (tauout_r(nspins))
2222 DO ispin = 1, nspins
2223 CALL auxbas_pw_pool%create_pw(tauout_r(ispin))
2225 CALL auxbas_pw_pool%create_pw(tauout_g)
2227 DO ispin = 1, nspins
2228 CALL calculate_rho_elec(ks_env=ks_env, matrix_p=ec_env%matrix_p(ispin, 1)%matrix, &
2229 rho=tauout_r(ispin), &
2230 rho_gspace=tauout_g, &
2231 compute_tau=.true., &
2232 basis_type=
"HARRIS", &
2233 task_list_external=ec_env%task_list)
2236 CALL auxbas_pw_pool%give_back_pw(tauout_g)
2241 dft_control%nimages = nimages
2243 IF (use_virial)
THEN
2246 CALL auxbas_pw_pool%create_pw(rho_tot_gspace)
2249 CALL calc_rho_tot_gspace(rho_tot_gspace, qs_env, rho)
2252 CALL get_qs_env(qs_env=qs_env, rho_core=rho_core)
2253 CALL pw_copy(rho_core, rhodn_tot_gspace)
2254 DO ispin = 1, dft_control%nspins
2255 CALL pw_axpy(rhoout_g(ispin), rhodn_tot_gspace)
2259 h_stress(:, :) = 0.0_dp
2260 CALL pw_poisson_solve(poisson_env, &
2261 density=rho_tot_gspace, &
2262 ehartree=ehartree, &
2263 vhartree=v_hartree_gspace, &
2264 h_stress=h_stress, &
2265 aux_density=rhodn_tot_gspace)
2267 virial%pv_ehartree = virial%pv_ehartree + h_stress/real(para_env%num_pe, dp)
2268 virial%pv_virial = virial%pv_virial + h_stress/real(para_env%num_pe, dp)
2270 IF (debug_stress)
THEN
2271 stdeb = fconv*(h_stress/real(para_env%num_pe, dp))
2272 CALL para_env%sum(stdeb)
2273 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2274 'STRESS| GREEN 1st v_H[n_in]*n_out ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2278 virial%pv_calculate = .true.
2280 NULLIFY (v_rspace, v_tau_rspace)
2281 CALL qs_vxc_create(ks_env=ks_env, rho_struct=rho, xc_section=ec_env%xc_section, &
2282 vxc_rho=v_rspace, vxc_tau=v_tau_rspace, exc=exc, just_energy=.false.)
2285 virial%pv_exc = virial%pv_exc - virial%pv_xc
2286 virial%pv_virial = virial%pv_virial - virial%pv_xc
2288 IF (debug_stress)
THEN
2289 stdeb = -1.0_dp*fconv*virial%pv_xc
2290 CALL para_env%sum(stdeb)
2291 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2292 'STRESS| GGA 1st E_xc[Pin] ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2295 IF (
ASSOCIATED(v_rspace))
THEN
2296 DO ispin = 1, nspins
2297 CALL auxbas_pw_pool%give_back_pw(v_rspace(ispin))
2299 DEALLOCATE (v_rspace)
2301 IF (
ASSOCIATED(v_tau_rspace))
THEN
2302 DO ispin = 1, nspins
2303 CALL auxbas_pw_pool%give_back_pw(v_tau_rspace(ispin))
2305 DEALLOCATE (v_tau_rspace)
2307 CALL pw_zero(rhodn_tot_gspace)
2312 DO ispin = 1, nspins
2313 CALL pw_axpy(rho_r(ispin), rhoout_r(ispin), -1.0_dp)
2314 CALL pw_axpy(rho_g(ispin), rhoout_g(ispin), -1.0_dp)
2315 CALL pw_axpy(rhoout_g(ispin), rhodn_tot_gspace)
2316 IF (dft_control%use_kinetic_energy_density)
CALL pw_axpy(tau_r(ispin), tauout_r(ispin), -1.0_dp)
2320 IF (use_virial)
THEN
2323 h_stress(:, :) = 0.0_dp
2324 CALL pw_poisson_solve(poisson_env, &
2325 density=rhodn_tot_gspace, &
2326 ehartree=dehartree, &
2327 vhartree=v_hartree_gspace, &
2328 h_stress=h_stress, &
2329 aux_density=rho_tot_gspace)
2331 CALL auxbas_pw_pool%give_back_pw(rho_tot_gspace)
2333 virial%pv_ehartree = virial%pv_ehartree + h_stress/real(para_env%num_pe, dp)
2334 virial%pv_virial = virial%pv_virial + h_stress/real(para_env%num_pe, dp)
2336 IF (debug_stress)
THEN
2337 stdeb = fconv*(h_stress/real(para_env%num_pe, dp))
2338 CALL para_env%sum(stdeb)
2339 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2340 'STRESS| GREEN 2nd V_H[dP]*n_in ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2345 CALL pw_poisson_solve(poisson_env, rhodn_tot_gspace, dehartree, &
2349 CALL pw_transfer(v_hartree_gspace, dv_hartree_rspace)
2350 CALL pw_scale(dv_hartree_rspace, dv_hartree_rspace%pw_grid%dvol)
2353 CALL pw_transfer(v_hartree_rspace, vtot_rspace)
2354 CALL pw_axpy(dv_hartree_rspace, vtot_rspace)
2355 IF (debug_forces) fodeb(1:3) = force(1)%rho_core(1:3, 1)
2356 IF (debug_stress .AND. use_virial) stdeb = virial%pv_ehartree
2357 CALL integrate_v_core_rspace(vtot_rspace, qs_env)
2358 IF (debug_forces)
THEN
2359 fodeb(1:3) = force(1)%rho_core(1:3, 1) - fodeb(1:3)
2360 CALL para_env%sum(fodeb)
2361 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Vtot*dncore", fodeb
2363 IF (debug_stress .AND. use_virial)
THEN
2364 stdeb = fconv*(virial%pv_ehartree - stdeb)
2365 CALL para_env%sum(stdeb)
2366 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2367 'STRESS| Vtot*dncore', one_third_sum_diag(stdeb), det_3x3(stdeb)
2373 xc_section => ec_env%xc_section
2375 IF (use_virial) virial%pv_xc = 0.0_dp
2376 NULLIFY (v_xc, v_xc_tau)
2377 CALL create_kernel(qs_env, &
2384 xc_section=xc_section, &
2385 compute_virial=use_virial, &
2386 virial_xc=virial%pv_xc)
2388 IF (use_virial)
THEN
2390 virial%pv_exc = virial%pv_exc + virial%pv_xc
2391 virial%pv_virial = virial%pv_virial + virial%pv_xc
2393 IF (debug_stress .AND. use_virial)
THEN
2394 stdeb = 1.0_dp*fconv*virial%pv_xc
2395 CALL para_env%sum(stdeb)
2396 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2397 'STRESS| GGA 2nd f_Hxc[dP]*Pin ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2400 CALL get_qs_env(qs_env=qs_env, rho=rho, matrix_s_kp=matrix_s)
2401 NULLIFY (ec_env%matrix_hz)
2402 CALL dbcsr_allocate_matrix_set(ec_env%matrix_hz, nspins)
2403 DO ispin = 1, nspins
2404 ALLOCATE (ec_env%matrix_hz(ispin)%matrix)
2405 CALL dbcsr_create(ec_env%matrix_hz(ispin)%matrix, template=matrix_s(1, 1)%matrix)
2406 CALL dbcsr_copy(ec_env%matrix_hz(ispin)%matrix, matrix_s(1, 1)%matrix)
2407 CALL dbcsr_set(ec_env%matrix_hz(ispin)%matrix, 0.0_dp)
2409 CALL qs_rho_get(rho, rho_ao_kp=matrix_p)
2411 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
2412 IF (debug_stress .AND. use_virial) stdeb = virial%pv_virial
2415 IF (use_virial)
THEN
2416 pv_loc = virial%pv_virial
2419 DO ispin = 1, nspins
2420 CALL pw_scale(v_xc(ispin), v_xc(ispin)%pw_grid%dvol)
2421 CALL pw_axpy(dv_hartree_rspace, v_xc(ispin))
2422 CALL integrate_v_rspace(v_rspace=v_xc(ispin), &
2423 hmat=ec_env%matrix_hz(ispin), &
2424 pmat=matrix_p(ispin, 1), &
2426 calculate_forces=.true.)
2429 IF (debug_forces)
THEN
2430 fodeb(1:3) = force(1)%rho_elec(1:3, 1) - fodeb(1:3)
2431 CALL para_env%sum(fodeb)
2432 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Pin*dKdrho", fodeb
2434 IF (debug_stress .AND. use_virial)
THEN
2435 stdeb = fconv*(virial%pv_virial - stdeb)
2436 CALL para_env%sum(stdeb)
2437 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2438 'STRESS| INT 2nd f_Hxc[dP]*Pin ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2441 IF (
ASSOCIATED(v_xc_tau))
THEN
2442 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
2443 IF (debug_stress .AND. use_virial) stdeb = virial%pv_virial
2445 DO ispin = 1, nspins
2446 CALL pw_scale(v_xc_tau(ispin), v_xc_tau(ispin)%pw_grid%dvol)
2447 CALL integrate_v_rspace(v_rspace=v_xc_tau(ispin), &
2448 hmat=ec_env%matrix_hz(ispin), &
2449 pmat=matrix_p(ispin, 1), &
2451 compute_tau=.true., &
2452 calculate_forces=.true.)
2455 IF (debug_forces)
THEN
2456 fodeb(1:3) = force(1)%rho_elec(1:3, 1) - fodeb(1:3)
2457 CALL para_env%sum(fodeb)
2458 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Pin*dKtaudtau", fodeb
2460 IF (debug_stress .AND. use_virial)
THEN
2461 stdeb = fconv*(virial%pv_virial - stdeb)
2462 CALL para_env%sum(stdeb)
2463 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2464 'STRESS| INT 2nd f_xctau[dP]*Pin ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2468 IF (use_virial)
THEN
2469 virial%pv_ehartree = virial%pv_ehartree + (virial%pv_virial - pv_loc)
2473 NULLIFY (v_rspace, v_tau_rspace)
2475 CALL qs_vxc_create(ks_env=ks_env, rho_struct=rho, xc_section=ec_env%xc_section, &
2476 vxc_rho=v_rspace, vxc_tau=v_tau_rspace, exc=eexc, just_energy=.false.)
2478 IF (use_virial)
THEN
2480 IF (
ASSOCIATED(v_rspace))
THEN
2481 DO ispin = 1, nspins
2483 eexc = eexc + pw_integral_ab(rhoout_r(ispin), v_rspace(ispin))
2486 IF (
ASSOCIATED(v_tau_rspace))
THEN
2487 DO ispin = 1, nspins
2489 eexc = eexc + pw_integral_ab(tauout_r(ispin), v_tau_rspace(ispin))
2494 IF (.NOT.
ASSOCIATED(v_rspace))
THEN
2495 ALLOCATE (v_rspace(nspins))
2496 DO ispin = 1, nspins
2497 CALL auxbas_pw_pool%create_pw(v_rspace(ispin))
2498 CALL pw_zero(v_rspace(ispin))
2504 IF (use_virial)
THEN
2505 pv_loc = virial%pv_virial
2508 dft_control%nimages = nhfimg
2512 CALL dbcsr_allocate_matrix_set(scrm, nspins, nhfimg)
2513 DO ispin = 1, nspins
2515 ALLOCATE (scrm(ispin, img)%matrix)
2516 CALL dbcsr_create(scrm(ispin, img)%matrix, template=ec_env%matrix_ks(ispin, img)%matrix)
2517 CALL dbcsr_copy(scrm(ispin, img)%matrix, ec_env%matrix_ks(ispin, img)%matrix)
2518 CALL dbcsr_set(scrm(ispin, img)%matrix, 0.0_dp)
2522 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
2523 IF (debug_stress .AND. use_virial) stdeb = virial%pv_virial
2524 DO ispin = 1, nspins
2526 CALL pw_scale(v_rspace(ispin), v_rspace(ispin)%pw_grid%dvol)
2527 CALL pw_axpy(v_hartree_rspace, v_rspace(ispin))
2529 rho_ao => ec_env%matrix_p(ispin, :)
2530 scrmat => scrm(ispin, :)
2531 CALL integrate_v_rspace(v_rspace=v_rspace(ispin), &
2535 calculate_forces=.true., &
2536 basis_type=
"HARRIS", &
2537 task_list_external=ec_env%task_list)
2540 IF (debug_forces)
THEN
2541 fodeb(1:3) = force(1)%rho_elec(1:3, 1) - fodeb(1:3)
2542 CALL para_env%sum(fodeb)
2543 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Pout*dVhxc ", fodeb
2545 IF (debug_stress .AND. use_virial)
THEN
2546 stdeb = fconv*(virial%pv_virial - stdeb)
2547 CALL para_env%sum(stdeb)
2548 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2549 'STRESS| INT Pout*dVhxc ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2553 IF (use_virial)
THEN
2554 virial%pv_ehartree = virial%pv_ehartree + (virial%pv_virial - pv_loc)
2558 dft_control%nimages = nimages
2560 IF (
ASSOCIATED(v_tau_rspace))
THEN
2561 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
2562 DO ispin = 1, nspins
2564 CALL pw_scale(v_tau_rspace(ispin), v_tau_rspace(ispin)%pw_grid%dvol)
2565 rho_ao => ec_env%matrix_p(ispin, :)
2566 scrmat => scrm(ispin, :)
2567 CALL integrate_v_rspace(v_rspace=v_tau_rspace(ispin), &
2571 calculate_forces=.true., &
2572 compute_tau=.true., &
2573 basis_type=
"HARRIS", &
2574 task_list_external=ec_env%task_list)
2576 IF (debug_forces)
THEN
2577 fodeb(1:3) = force(1)%rho_elec(1:3, 1) - fodeb(1:3)
2578 CALL para_env%sum(fodeb)
2579 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Pout*dVhxc_tau ", fodeb
2588 ec_hfx_sections => section_vals_get_subs_vals(qs_env%input,
"DFT%ENERGY_CORRECTION%XC%HF")
2589 CALL section_vals_get(ec_hfx_sections, explicit=do_ec_hfx)
2593 IF (ec_env%do_kpoints)
THEN
2594 CALL cp_abort(__location__,
"HFX and K-points NYI for energy correction")
2597 IF (debug_forces) fodeb(1:3) = force(1)%fock_4c(1:3, 1)
2598 IF (use_virial) virial%pv_fock_4c = 0.0_dp
2600 CALL calculate_exx(qs_env=qs_env, &
2602 hfx_sections=ec_hfx_sections, &
2603 x_data=ec_env%x_data, &
2605 do_admm=ec_env%do_ec_admm, &
2606 calc_forces=.true., &
2607 reuse_hfx=ec_env%reuse_hfx, &
2608 do_im_time=.false., &
2609 e_ex_from_gw=dummy_real, &
2610 e_admm_from_gw=dummy_real2, &
2613 IF (use_virial)
THEN
2614 virial%pv_exx = virial%pv_exx - virial%pv_fock_4c
2615 virial%pv_virial = virial%pv_virial - virial%pv_fock_4c
2616 virial%pv_calculate = .false.
2618 IF (debug_forces)
THEN
2619 fodeb(1:3) = force(1)%fock_4c(1:3, 1) - fodeb(1:3)
2620 CALL para_env%sum(fodeb)
2621 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Pout*hfx ", fodeb
2623 IF (debug_stress .AND. use_virial)
THEN
2624 stdeb = -1.0_dp*fconv*virial%pv_fock_4c
2625 CALL para_env%sum(stdeb)
2626 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2627 'STRESS| Pout*hfx ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2633 CALL dbcsr_deallocate_matrix_set(scrm)
2636 CALL auxbas_pw_pool%give_back_pw(v_hartree_rspace)
2637 DO ispin = 1, nspins
2638 CALL auxbas_pw_pool%give_back_pw(v_rspace(ispin))
2639 IF (
ASSOCIATED(v_tau_rspace))
THEN
2640 CALL auxbas_pw_pool%give_back_pw(v_tau_rspace(ispin))
2643 IF (
ASSOCIATED(v_tau_rspace))
DEALLOCATE (v_tau_rspace)
2646 IF (debug_forces) fodeb(1:3) = force(1)%core_overlap(1:3, 1)
2647 IF (debug_stress .AND. use_virial) stdeb = virial%pv_ecore_overlap
2648 CALL calculate_ecore_overlap(qs_env, para_env, .true., e_overlap_core=eovrl)
2649 IF (debug_forces)
THEN
2650 fodeb(1:3) = force(1)%core_overlap(1:3, 1) - fodeb(1:3)
2651 CALL para_env%sum(fodeb)
2652 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: CoreOverlap", fodeb
2654 IF (debug_stress .AND. use_virial)
THEN
2655 stdeb = fconv*(stdeb - virial%pv_ecore_overlap)
2656 CALL para_env%sum(stdeb)
2657 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2658 'STRESS| CoreOverlap ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2661 IF (debug_forces)
THEN
2662 CALL get_qs_env(qs_env, natom=natom, atomic_kind_set=atomic_kind_set)
2663 ALLOCATE (ftot(3, natom))
2664 CALL total_qs_force(ftot, force, atomic_kind_set)
2665 fodeb(1:3) = ftot(1:3, 1)
2667 CALL para_env%sum(fodeb)
2668 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Force Explicit", fodeb
2671 DEALLOCATE (v_rspace)
2673 CALL auxbas_pw_pool%give_back_pw(dv_hartree_rspace)
2674 CALL auxbas_pw_pool%give_back_pw(vtot_rspace)
2675 DO ispin = 1, nspins
2676 CALL auxbas_pw_pool%give_back_pw(rhoout_r(ispin))
2677 CALL auxbas_pw_pool%give_back_pw(rhoout_g(ispin))
2678 CALL auxbas_pw_pool%give_back_pw(v_xc(ispin))
2680 DEALLOCATE (rhoout_r, rhoout_g, v_xc)
2681 IF (
ASSOCIATED(tauout_r))
THEN
2682 DO ispin = 1, nspins
2683 CALL auxbas_pw_pool%give_back_pw(tauout_r(ispin))
2685 DEALLOCATE (tauout_r)
2687 IF (
ASSOCIATED(v_xc_tau))
THEN
2688 DO ispin = 1, nspins
2689 CALL auxbas_pw_pool%give_back_pw(v_xc_tau(ispin))
2691 DEALLOCATE (v_xc_tau)
2693 CALL auxbas_pw_pool%give_back_pw(v_hartree_gspace)
2694 CALL auxbas_pw_pool%give_back_pw(rhodn_tot_gspace)
2698 IF (use_virial)
THEN
2699 IF (qs_env%energy_correction)
THEN
2700 ec_env%ehartree = ehartree + dehartree
2701 ec_env%exc = exc + eexc
2705 IF (debug_stress .AND. use_virial)
THEN
2707 stdeb = -1.0_dp*fconv*ehartree
2708 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2709 'STRESS| VOL 1st v_H[n_in]*n_out', one_third_sum_diag(stdeb), det_3x3(stdeb)
2711 stdeb = -1.0_dp*fconv*exc
2712 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2713 'STRESS| VOL 1st E_XC[n_in]', one_third_sum_diag(stdeb), det_3x3(stdeb)
2715 stdeb = -1.0_dp*fconv*dehartree
2716 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2717 'STRESS| VOL 2nd v_H[dP]*n_in', one_third_sum_diag(stdeb), det_3x3(stdeb)
2719 stdeb = -1.0_dp*fconv*eexc
2720 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2721 'STRESS| VOL 2nd v_XC[n_in]*dP', one_third_sum_diag(stdeb), det_3x3(stdeb)
2726 TYPE(virial_type) :: virdeb
2729 CALL para_env%sum(virdeb%pv_overlap)
2730 CALL para_env%sum(virdeb%pv_ekinetic)
2731 CALL para_env%sum(virdeb%pv_ppl)
2732 CALL para_env%sum(virdeb%pv_ppnl)
2733 CALL para_env%sum(virdeb%pv_ecore_overlap)
2734 CALL para_env%sum(virdeb%pv_ehartree)
2735 CALL para_env%sum(virdeb%pv_exc)
2736 CALL para_env%sum(virdeb%pv_exx)
2737 CALL para_env%sum(virdeb%pv_vdw)
2738 CALL para_env%sum(virdeb%pv_mp2)
2739 CALL para_env%sum(virdeb%pv_nlcc)
2740 CALL para_env%sum(virdeb%pv_gapw)
2741 CALL para_env%sum(virdeb%pv_lrigpw)
2742 CALL para_env%sum(virdeb%pv_virial)
2743 CALL symmetrize_virial(virdeb)
2747 virdeb%pv_ehartree(i, i) = virdeb%pv_ehartree(i, i) - 2.0_dp*(ehartree + dehartree)
2748 virdeb%pv_virial(i, i) = virdeb%pv_virial(i, i) - exc - eexc &
2749 - 2.0_dp*(ehartree + dehartree)
2750 virdeb%pv_exc(i, i) = virdeb%pv_exc(i, i) - exc - eexc
2756 CALL para_env%sum(sttot)
2757 stdeb = fconv*(virdeb%pv_virial - sttot)
2758 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2759 'STRESS| Explicit electronic stress ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2761 stdeb = fconv*(virdeb%pv_virial)
2762 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2763 'STRESS| Explicit total stress ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2765 CALL write_stress_tensor_components(virdeb, iounit, cell, unit_string)
2766 CALL write_stress_tensor(virdeb%pv_virial, iounit, cell, unit_string, .false.)
2771 CALL timestop(handle)
2773 END SUBROUTINE ec_build_ks_matrix_force
2783 SUBROUTINE ec_ks_solver(qs_env, ec_env)
2785 TYPE(qs_environment_type),
POINTER :: qs_env
2786 TYPE(energy_correction_type),
POINTER :: ec_env
2788 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ec_ks_solver'
2790 CHARACTER(LEN=default_string_length) :: headline
2791 INTEGER :: handle, img, ispin, nhfimg, nspins
2792 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: ksmat, pmat, smat, wmat
2793 TYPE(dbcsr_type),
POINTER :: tsmat
2794 TYPE(dft_control_type),
POINTER :: dft_control
2796 CALL timeset(routinen, handle)
2798 CALL get_qs_env(qs_env=qs_env, dft_control=dft_control)
2799 nspins = dft_control%nspins
2800 nhfimg =
SIZE(ec_env%matrix_s, 2)
2803 IF (.NOT.
ASSOCIATED(ec_env%matrix_p))
THEN
2804 headline =
"DENSITY MATRIX"
2805 CALL dbcsr_allocate_matrix_set(ec_env%matrix_p, nspins, nhfimg)
2806 DO ispin = 1, nspins
2808 tsmat => ec_env%matrix_s(1, img)%matrix
2809 ALLOCATE (ec_env%matrix_p(ispin, img)%matrix)
2810 CALL dbcsr_create(ec_env%matrix_p(ispin, img)%matrix, &
2811 name=trim(headline), template=tsmat)
2812 CALL cp_dbcsr_alloc_block_from_nbl(ec_env%matrix_p(ispin, img)%matrix, &
2818 IF (.NOT.
ASSOCIATED(ec_env%matrix_w))
THEN
2819 headline =
"ENERGY WEIGHTED DENSITY MATRIX"
2820 CALL dbcsr_allocate_matrix_set(ec_env%matrix_w, nspins, nhfimg)
2821 DO ispin = 1, nspins
2823 tsmat => ec_env%matrix_s(1, img)%matrix
2824 ALLOCATE (ec_env%matrix_w(ispin, img)%matrix)
2825 CALL dbcsr_create(ec_env%matrix_w(ispin, img)%matrix, &
2826 name=trim(headline), template=tsmat)
2827 CALL cp_dbcsr_alloc_block_from_nbl(ec_env%matrix_w(ispin, img)%matrix, &
2833 IF (ec_env%mao)
THEN
2834 CALL mao_create_matrices(ec_env, ksmat, smat, pmat, wmat)
2836 ksmat => ec_env%matrix_ks
2837 smat => ec_env%matrix_s
2838 pmat => ec_env%matrix_p
2839 wmat => ec_env%matrix_w
2842 IF (ec_env%do_kpoints)
THEN
2843 IF (ec_env%ks_solver /= ec_diagonalization)
THEN
2844 CALL cp_abort(__location__,
"Harris functional with k-points "// &
2845 "needs diagonalization solver")
2849 SELECT CASE (ec_env%ks_solver)
2850 CASE (ec_diagonalization)
2851 IF (ec_env%do_kpoints)
THEN
2852 CALL ec_diag_solver_kp(qs_env, ec_env, ksmat, smat, pmat, wmat)
2854 CALL ec_diag_solver_gamma(qs_env, ec_env, ksmat, smat, pmat, wmat)
2857 CALL ec_ot_diag_solver(qs_env, ec_env, ksmat, smat, pmat, wmat)
2858 CASE (ec_matrix_sign, ec_matrix_trs4, ec_matrix_tc2)
2859 CALL ec_ls_init(qs_env, ksmat, smat)
2860 CALL ec_ls_solver(qs_env, pmat, wmat, ec_ls_method=ec_env%ks_solver)
2865 IF (ec_env%mao)
THEN
2866 CALL mao_release_matrices(ec_env, ksmat, smat, pmat, wmat)
2869 CALL timestop(handle)
2871 END SUBROUTINE ec_ks_solver
2884 SUBROUTINE mao_create_matrices(ec_env, ksmat, smat, pmat, wmat)
2886 TYPE(energy_correction_type),
POINTER :: ec_env
2887 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: ksmat, smat, pmat, wmat
2889 CHARACTER(LEN=*),
PARAMETER :: routinen =
'mao_create_matrices'
2891 INTEGER :: handle, ispin, nspins
2892 INTEGER,
DIMENSION(:),
POINTER :: col_blk_sizes
2893 TYPE(dbcsr_distribution_type) :: dbcsr_dist
2894 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: mao_coef
2895 TYPE(dbcsr_type) :: cgmat
2897 CALL timeset(routinen, handle)
2899 mao_coef => ec_env%mao_coef
2901 NULLIFY (ksmat, smat, pmat, wmat)
2902 nspins =
SIZE(ec_env%matrix_ks, 1)
2903 CALL dbcsr_get_info(mao_coef(1)%matrix, col_blk_size=col_blk_sizes, distribution=dbcsr_dist)
2904 CALL dbcsr_allocate_matrix_set(ksmat, nspins, 1)
2905 CALL dbcsr_allocate_matrix_set(smat, nspins, 1)
2906 DO ispin = 1, nspins
2907 ALLOCATE (ksmat(ispin, 1)%matrix)
2908 CALL dbcsr_create(ksmat(ispin, 1)%matrix, dist=dbcsr_dist, name=
"MAO KS mat", &
2909 matrix_type=dbcsr_type_symmetric, row_blk_size=col_blk_sizes, &
2910 col_blk_size=col_blk_sizes)
2911 ALLOCATE (smat(ispin, 1)%matrix)
2912 CALL dbcsr_create(smat(ispin, 1)%matrix, dist=dbcsr_dist, name=
"MAO S mat", &
2913 matrix_type=dbcsr_type_symmetric, row_blk_size=col_blk_sizes, &
2914 col_blk_size=col_blk_sizes)
2917 CALL dbcsr_create(cgmat, name=
"TEMP matrix", template=mao_coef(1)%matrix)
2918 DO ispin = 1, nspins
2919 CALL dbcsr_multiply(
"N",
"N", 1.0_dp, ec_env%matrix_s(1, 1)%matrix, mao_coef(ispin)%matrix, &
2921 CALL dbcsr_multiply(
"T",
"N", 1.0_dp, mao_coef(ispin)%matrix, cgmat, 0.0_dp, smat(ispin, 1)%matrix)
2922 CALL dbcsr_multiply(
"N",
"N", 1.0_dp, ec_env%matrix_ks(1, 1)%matrix, mao_coef(ispin)%matrix, &
2924 CALL dbcsr_multiply(
"T",
"N", 1.0_dp, mao_coef(ispin)%matrix, cgmat, 0.0_dp, ksmat(ispin, 1)%matrix)
2926 CALL dbcsr_release(cgmat)
2928 CALL dbcsr_allocate_matrix_set(pmat, nspins, 1)
2929 DO ispin = 1, nspins
2930 ALLOCATE (pmat(ispin, 1)%matrix)
2931 CALL dbcsr_create(pmat(ispin, 1)%matrix, template=smat(1, 1)%matrix, name=
"MAO P mat")
2932 CALL cp_dbcsr_alloc_block_from_nbl(pmat(ispin, 1)%matrix, ec_env%sab_orb)
2935 CALL dbcsr_allocate_matrix_set(wmat, nspins, 1)
2936 DO ispin = 1, nspins
2937 ALLOCATE (wmat(ispin, 1)%matrix)
2938 CALL dbcsr_create(wmat(ispin, 1)%matrix, template=smat(1, 1)%matrix, name=
"MAO W mat")
2939 CALL cp_dbcsr_alloc_block_from_nbl(wmat(ispin, 1)%matrix, ec_env%sab_orb)
2942 CALL timestop(handle)
2944 END SUBROUTINE mao_create_matrices
2957 SUBROUTINE mao_release_matrices(ec_env, ksmat, smat, pmat, wmat)
2959 TYPE(energy_correction_type),
POINTER :: ec_env
2960 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: ksmat, smat, pmat, wmat
2962 CHARACTER(LEN=*),
PARAMETER :: routinen =
'mao_release_matrices'
2964 INTEGER :: handle, ispin, nspins
2965 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: mao_coef
2966 TYPE(dbcsr_type) :: cgmat
2968 CALL timeset(routinen, handle)
2970 mao_coef => ec_env%mao_coef
2971 nspins =
SIZE(mao_coef, 1)
2974 CALL dbcsr_create(cgmat, name=
"TEMP matrix", template=mao_coef(1)%matrix)
2975 DO ispin = 1, nspins
2976 CALL dbcsr_multiply(
"N",
"N", 1.0_dp, mao_coef(ispin)%matrix, pmat(ispin, 1)%matrix, 0.0_dp, cgmat)
2977 CALL dbcsr_multiply(
"N",
"T", 1.0_dp, mao_coef(ispin)%matrix, cgmat, 0.0_dp, &
2978 ec_env%matrix_p(ispin, 1)%matrix, retain_sparsity=.true.)
2979 CALL dbcsr_multiply(
"N",
"N", 1.0_dp, mao_coef(ispin)%matrix, wmat(ispin, 1)%matrix, 0.0_dp, cgmat)
2980 CALL dbcsr_multiply(
"N",
"T", 1.0_dp, mao_coef(ispin)%matrix, cgmat, 0.0_dp, &
2981 ec_env%matrix_w(ispin, 1)%matrix, retain_sparsity=.true.)
2983 CALL dbcsr_release(cgmat)
2985 CALL dbcsr_deallocate_matrix_set(ksmat)
2986 CALL dbcsr_deallocate_matrix_set(smat)
2987 CALL dbcsr_deallocate_matrix_set(pmat)
2988 CALL dbcsr_deallocate_matrix_set(wmat)
2990 CALL timestop(handle)
2992 END SUBROUTINE mao_release_matrices
3000 SUBROUTINE ec_energy(ec_env, unit_nr)
3001 TYPE(energy_correction_type) :: ec_env
3002 INTEGER,
INTENT(IN) :: unit_nr
3004 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ec_energy'
3006 INTEGER :: handle, nspins
3007 REAL(kind=dp) :: eband, trace
3009 CALL timeset(routinen, handle)
3011 nspins =
SIZE(ec_env%matrix_p, 1)
3012 CALL calculate_ptrace(ec_env%matrix_s, ec_env%matrix_p, trace, nspins)
3013 IF (unit_nr > 0)
WRITE (unit_nr,
'(T3,A,T65,F16.10)')
'Tr[PS] ', trace
3016 SELECT CASE (ec_env%energy_functional)
3017 CASE (ec_functional_harris)
3020 CALL calculate_ptrace(ec_env%matrix_ks, ec_env%matrix_p, eband, nspins, .true.)
3021 ec_env%eband = eband + ec_env%efield_nuclear
3024 ec_env%etotal = ec_env%eband + ec_env%ehartree + ec_env%exc - ec_env%vhxc + ec_env%ekTS + &
3025 ec_env%edispersion - ec_env%ex
3026 IF (unit_nr > 0)
THEN
3027 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Eband ", ec_env%eband
3028 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Ehartree ", ec_env%ehartree
3029 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Exc ", ec_env%exc
3030 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Ex ", ec_env%ex
3031 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Evhxc ", ec_env%vhxc
3032 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Edisp ", ec_env%edispersion
3033 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Entropy ", ec_env%ekTS
3034 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Etotal Harris Functional ", ec_env%etotal
3037 CASE (ec_functional_dc)
3040 CALL calculate_ptrace(ec_env%matrix_h, ec_env%matrix_p, ec_env%ecore, nspins)
3042 ec_env%ecore = ec_env%ecore + ec_env%efield_nuclear
3043 ec_env%etotal = ec_env%ecore + ec_env%ehartree + ec_env%ehartree_1c + &
3044 ec_env%exc + ec_env%exc1 + ec_env%ekTS + ec_env%edispersion + &
3045 ec_env%ex + ec_env%exc_aux_fit + ec_env%exc1_aux_fit
3047 IF (unit_nr > 0)
THEN
3048 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Ecore ", ec_env%ecore
3049 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Ehartree ", ec_env%ehartree + ec_env%ehartree_1c
3050 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Exc ", ec_env%exc + ec_env%exc1
3051 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Ex ", ec_env%ex
3052 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Exc_aux_fit", ec_env%exc_aux_fit + ec_env%exc1_aux_fit
3053 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Edisp ", ec_env%edispersion
3054 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Entropy ", ec_env%ekTS
3055 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Etotal Energy Functional ", ec_env%etotal
3058 CASE (ec_functional_ext)
3060 ec_env%etotal = ec_env%ex
3061 IF (unit_nr > 0)
THEN
3062 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Etotal Energy Functional ", ec_env%etotal
3071 CALL timestop(handle)
3073 END SUBROUTINE ec_energy
3085 SUBROUTINE ec_build_neighborlist(qs_env, ec_env)
3086 TYPE(qs_environment_type),
POINTER :: qs_env
3087 TYPE(energy_correction_type),
POINTER :: ec_env
3089 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ec_build_neighborlist'
3091 INTEGER :: handle, ikind, nimages, nkind, zat
3092 LOGICAL :: all_potential_present, gth_potential_present, paw_atom, paw_atom_present, &
3093 sgp_potential_present, skip_load_balance_distributed
3094 LOGICAL,
ALLOCATABLE,
DIMENSION(:) :: all_present, default_present, &
3095 oce_present, orb_present, ppl_present, &
3097 REAL(dp) :: subcells
3098 REAL(dp),
ALLOCATABLE,
DIMENSION(:) :: all_radius, c_radius, oce_radius, &
3099 orb_radius, ppl_radius, ppnl_radius
3100 REAL(dp),
ALLOCATABLE,
DIMENSION(:, :) :: pair_radius
3101 TYPE(all_potential_type),
POINTER :: all_potential
3102 TYPE(atomic_kind_type),
DIMENSION(:),
POINTER :: atomic_kind_set
3103 TYPE(cell_type),
POINTER :: cell
3104 TYPE(dft_control_type),
POINTER :: dft_control
3105 TYPE(distribution_1d_type),
POINTER :: distribution_1d
3106 TYPE(distribution_2d_type),
POINTER :: distribution_2d
3107 TYPE(gth_potential_type),
POINTER :: gth_potential
3108 TYPE(gto_basis_set_type),
POINTER :: basis_set
3109 TYPE(local_atoms_type),
ALLOCATABLE,
DIMENSION(:) :: atom2d
3110 TYPE(molecule_type),
DIMENSION(:),
POINTER :: molecule_set
3111 TYPE(mp_para_env_type),
POINTER :: para_env
3112 TYPE(neighbor_list_set_p_type),
DIMENSION(:), &
3113 POINTER :: sab_cn, sab_vdw
3114 TYPE(particle_type),
DIMENSION(:),
POINTER :: particle_set
3115 TYPE(paw_proj_set_type),
POINTER :: paw_proj
3116 TYPE(qs_dispersion_type),
POINTER :: dispersion_env
3117 TYPE(qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
3118 TYPE(qs_kind_type),
POINTER :: qs_kind
3119 TYPE(qs_ks_env_type),
POINTER :: ks_env
3120 TYPE(sgp_potential_type),
POINTER :: sgp_potential
3122 CALL timeset(routinen, handle)
3124 CALL get_qs_env(qs_env=qs_env, qs_kind_set=qs_kind_set)
3125 CALL get_qs_kind_set(qs_kind_set, &
3126 paw_atom_present=paw_atom_present, &
3127 all_potential_present=all_potential_present, &
3128 gth_potential_present=gth_potential_present, &
3129 sgp_potential_present=sgp_potential_present)
3130 nkind =
SIZE(qs_kind_set)
3131 ALLOCATE (c_radius(nkind), default_present(nkind))
3132 ALLOCATE (orb_radius(nkind), all_radius(nkind), ppl_radius(nkind), ppnl_radius(nkind))
3133 ALLOCATE (orb_present(nkind), all_present(nkind), ppl_present(nkind), ppnl_present(nkind))
3134 ALLOCATE (pair_radius(nkind, nkind))
3135 ALLOCATE (atom2d(nkind))
3137 CALL get_qs_env(qs_env, &
3138 atomic_kind_set=atomic_kind_set, &
3140 distribution_2d=distribution_2d, &
3141 local_particles=distribution_1d, &
3142 particle_set=particle_set, &
3143 molecule_set=molecule_set)
3145 CALL atom2d_build(atom2d, distribution_1d, distribution_2d, atomic_kind_set, &
3146 molecule_set, .false., particle_set)
3149 CALL get_atomic_kind(atomic_kind_set(ikind), atom_list=atom2d(ikind)%list)
3150 qs_kind => qs_kind_set(ikind)
3151 CALL get_qs_kind(qs_kind=qs_kind, basis_set=basis_set, basis_type=
"HARRIS")
3152 IF (
ASSOCIATED(basis_set))
THEN
3153 orb_present(ikind) = .true.
3154 CALL get_gto_basis_set(gto_basis_set=basis_set, kind_radius=orb_radius(ikind))
3156 orb_present(ikind) = .false.
3157 orb_radius(ikind) = 0.0_dp
3159 CALL get_qs_kind(qs_kind, all_potential=all_potential, &
3160 gth_potential=gth_potential, sgp_potential=sgp_potential)
3161 IF (gth_potential_present .OR. sgp_potential_present)
THEN
3162 IF (
ASSOCIATED(gth_potential))
THEN
3163 CALL get_potential(potential=gth_potential, &
3164 ppl_present=ppl_present(ikind), &
3165 ppl_radius=ppl_radius(ikind), &
3166 ppnl_present=ppnl_present(ikind), &
3167 ppnl_radius=ppnl_radius(ikind))
3168 ELSE IF (
ASSOCIATED(sgp_potential))
THEN
3169 CALL get_potential(potential=sgp_potential, &
3170 ppl_present=ppl_present(ikind), &
3171 ppl_radius=ppl_radius(ikind), &
3172 ppnl_present=ppnl_present(ikind), &
3173 ppnl_radius=ppnl_radius(ikind))
3175 ppl_present(ikind) = .false.
3176 ppl_radius(ikind) = 0.0_dp
3177 ppnl_present(ikind) = .false.
3178 ppnl_radius(ikind) = 0.0_dp
3182 IF (all_potential_present .OR. sgp_potential_present)
THEN
3183 all_present(ikind) = .false.
3184 all_radius(ikind) = 0.0_dp
3185 IF (
ASSOCIATED(all_potential))
THEN
3186 all_present(ikind) = .true.
3187 CALL get_potential(potential=all_potential, core_charge_radius=all_radius(ikind))
3188 ELSE IF (
ASSOCIATED(sgp_potential))
THEN
3189 IF (sgp_potential%ecp_local)
THEN
3190 all_present(ikind) = .true.
3191 CALL get_potential(potential=sgp_potential, core_charge_radius=all_radius(ikind))
3197 CALL section_vals_val_get(qs_env%input,
"DFT%SUBCELLS", r_val=subcells)
3200 CALL pair_radius_setup(orb_present, orb_present, orb_radius, orb_radius, pair_radius)
3201 CALL build_neighbor_lists(ec_env%sab_orb, particle_set, atom2d, cell, pair_radius, &
3202 subcells=subcells, nlname=
"sab_orb")
3204 IF (ec_env%do_kpoints)
THEN
3206 CALL build_neighbor_lists(ec_env%sab_kp, particle_set, atom2d, cell, pair_radius, &
3207 subcells=subcells, nlname=
"sab_kp")
3208 IF (ec_env%do_ec_hfx)
THEN
3209 CALL build_neighbor_lists(ec_env%sab_kp_nosym, particle_set, atom2d, cell, pair_radius, &
3210 subcells=subcells, nlname=
"sab_kp_nosym", symmetric=.false.)
3212 CALL get_qs_env(qs_env=qs_env, para_env=para_env)
3213 CALL kpoint_init_cell_index(ec_env%kpoints, ec_env%sab_kp, para_env, nimages)
3217 IF (all_potential_present .OR. sgp_potential_present)
THEN
3218 IF (any(all_present))
THEN
3219 CALL pair_radius_setup(orb_present, all_present, orb_radius, all_radius, pair_radius)
3220 CALL build_neighbor_lists(ec_env%sac_ae, particle_set, atom2d, cell, pair_radius, &
3221 subcells=subcells, operator_type=
"ABC", nlname=
"sac_ae")
3225 IF (gth_potential_present .OR. sgp_potential_present)
THEN
3226 IF (any(ppl_present))
THEN
3227 CALL pair_radius_setup(orb_present, ppl_present, orb_radius, ppl_radius, pair_radius)
3228 CALL build_neighbor_lists(ec_env%sac_ppl, particle_set, atom2d, cell, pair_radius, &
3229 subcells=subcells, operator_type=
"ABC", nlname=
"sac_ppl")
3232 IF (any(ppnl_present))
THEN
3233 CALL pair_radius_setup(orb_present, ppnl_present, orb_radius, ppnl_radius, pair_radius)
3234 CALL build_neighbor_lists(ec_env%sap_ppnl, particle_set, atom2d, cell, pair_radius, &
3235 subcells=subcells, operator_type=
"ABBA", nlname=
"sap_ppnl")
3240 c_radius(:) = 0.0_dp
3241 dispersion_env => ec_env%dispersion_env
3242 sab_vdw => dispersion_env%sab_vdw
3243 sab_cn => dispersion_env%sab_cn
3244 IF (dispersion_env%type == xc_vdw_fun_pairpot)
THEN
3245 c_radius(:) = dispersion_env%rc_disp
3246 default_present = .true.
3247 CALL pair_radius_setup(default_present, default_present, c_radius, c_radius, pair_radius)
3248 CALL build_neighbor_lists(sab_vdw, particle_set, atom2d, cell, pair_radius, &
3249 subcells=subcells, operator_type=
"PP", nlname=
"sab_vdw")
3250 dispersion_env%sab_vdw => sab_vdw
3251 IF (dispersion_env%pp_type == vdw_pairpot_dftd3 .OR. &
3252 dispersion_env%pp_type == vdw_pairpot_dftd3bj)
THEN
3255 CALL get_atomic_kind(atomic_kind_set(ikind), z=zat)
3256 c_radius(ikind) = 4._dp*ptable(zat)%covalent_radius*bohr
3258 CALL pair_radius_setup(default_present, default_present, c_radius, c_radius, pair_radius)
3259 CALL build_neighbor_lists(sab_cn, particle_set, atom2d, cell, pair_radius, &
3260 subcells=subcells, operator_type=
"PP", nlname=
"sab_cn")
3261 dispersion_env%sab_cn => sab_cn
3266 IF (paw_atom_present)
THEN
3267 IF (paw_atom_present)
THEN
3268 ALLOCATE (oce_present(nkind), oce_radius(nkind))
3273 CALL get_qs_kind(qs_kind_set(ikind), paw_proj_set=paw_proj, paw_atom=paw_atom)
3275 oce_present(ikind) = .true.
3276 CALL get_paw_proj_set(paw_proj_set=paw_proj, rcprj=oce_radius(ikind))
3278 oce_present(ikind) = .false.
3283 IF (any(oce_present))
THEN
3284 CALL pair_radius_setup(orb_present, oce_present, orb_radius, oce_radius, pair_radius)
3285 CALL build_neighbor_lists(ec_env%sap_oce, particle_set, atom2d, cell, pair_radius, &
3286 subcells=subcells, operator_type=
"ABBA", nlname=
"sap_oce")
3288 DEALLOCATE (oce_present, oce_radius)
3292 CALL atom2d_cleanup(atom2d)
3294 DEALLOCATE (orb_present, default_present, all_present, ppl_present, ppnl_present)
3295 DEALLOCATE (orb_radius, all_radius, ppl_radius, ppnl_radius, c_radius)
3296 DEALLOCATE (pair_radius)
3299 CALL get_qs_env(qs_env, ks_env=ks_env, dft_control=dft_control)
3300 skip_load_balance_distributed = dft_control%qs_control%skip_load_balance_distributed
3301 IF (
ASSOCIATED(ec_env%task_list))
CALL deallocate_task_list(ec_env%task_list)
3302 CALL allocate_task_list(ec_env%task_list)
3303 CALL generate_qs_task_list(ks_env, ec_env%task_list, basis_type=
"HARRIS", &
3304 reorder_rs_grid_ranks=.false., &
3305 skip_load_balance_distributed=skip_load_balance_distributed, &
3306 sab_orb_external=ec_env%sab_orb, &
3307 ext_kpoints=ec_env%kpoints)
3309 IF (dft_control%qs_control%gapw .OR. dft_control%qs_control%gapw_xc)
THEN
3310 IF (
ASSOCIATED(ec_env%task_list_soft))
CALL deallocate_task_list(ec_env%task_list_soft)
3311 CALL allocate_task_list(ec_env%task_list_soft)
3312 CALL generate_qs_task_list(ks_env, ec_env%task_list_soft, basis_type=
"HARRIS_SOFT", &
3313 reorder_rs_grid_ranks=.false., &
3314 skip_load_balance_distributed=skip_load_balance_distributed, &
3315 sab_orb_external=ec_env%sab_orb, &
3316 ext_kpoints=ec_env%kpoints)
3319 CALL timestop(handle)
3321 END SUBROUTINE ec_build_neighborlist
3328 SUBROUTINE ec_properties(qs_env, ec_env)
3329 TYPE(qs_environment_type),
POINTER :: qs_env
3330 TYPE(energy_correction_type),
POINTER :: ec_env
3332 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ec_properties'
3334 CHARACTER(LEN=8),
DIMENSION(3) :: rlab
3335 CHARACTER(LEN=default_path_length) :: filename, my_pos_voro
3336 CHARACTER(LEN=default_string_length) :: description
3337 INTEGER :: akind, handle, i, ia, iatom, idir, ikind, iounit, ispin, maxmom, nspins, &
3338 reference, should_print_bqb, should_print_voro, unit_nr, unit_nr_voro
3339 LOGICAL :: append_voro, magnetic, periodic, &
3341 REAL(kind=dp) :: charge, dd, focc, tmp
3342 REAL(kind=dp),
DIMENSION(3) :: cdip, pdip, rcc, rdip, ria, tdip
3343 REAL(kind=dp),
DIMENSION(:),
POINTER :: ref_point
3344 TYPE(atomic_kind_type),
POINTER :: atomic_kind
3345 TYPE(cell_type),
POINTER :: cell
3346 TYPE(cp_logger_type),
POINTER :: logger
3347 TYPE(cp_result_type),
POINTER :: results
3348 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_s, moments
3349 TYPE(dft_control_type),
POINTER :: dft_control
3350 TYPE(distribution_1d_type),
POINTER :: local_particles
3351 TYPE(mp_para_env_type),
POINTER :: para_env
3352 TYPE(particle_type),
DIMENSION(:),
POINTER :: particle_set
3353 TYPE(pw_env_type),
POINTER :: pw_env
3354 TYPE(pw_pool_p_type),
DIMENSION(:),
POINTER :: pw_pools
3355 TYPE(pw_pool_type),
POINTER :: auxbas_pw_pool
3356 TYPE(pw_r3d_rs_type) :: rho_elec_rspace
3357 TYPE(qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
3358 TYPE(section_vals_type),
POINTER :: ec_section, print_key, print_key_bqb, &
3361 CALL timeset(routinen, handle)
3367 logger => cp_get_default_logger()
3368 IF (logger%para_env%is_source())
THEN
3369 iounit = cp_logger_get_default_unit_nr(logger, local=.true.)
3374 NULLIFY (dft_control)
3375 CALL get_qs_env(qs_env, dft_control=dft_control)
3376 nspins = dft_control%nspins
3378 ec_section => section_vals_get_subs_vals(qs_env%input,
"DFT%ENERGY_CORRECTION")
3379 print_key => section_vals_get_subs_vals(section_vals=ec_section, &
3380 subsection_name=
"PRINT%MOMENTS")
3382 IF (btest(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file))
THEN
3384 IF (dft_control%qs_control%gapw .OR. dft_control%qs_control%gapw_xc)
THEN
3385 cpabort(
"Properties for GAPW in EC NYA")
3388 maxmom = section_get_ival(section_vals=ec_section, &
3389 keyword_name=
"PRINT%MOMENTS%MAX_MOMENT")
3390 periodic = section_get_lval(section_vals=ec_section, &
3391 keyword_name=
"PRINT%MOMENTS%PERIODIC")
3392 reference = section_get_ival(section_vals=ec_section, &
3393 keyword_name=
"PRINT%MOMENTS%REFERENCE")
3394 magnetic = section_get_lval(section_vals=ec_section, &
3395 keyword_name=
"PRINT%MOMENTS%MAGNETIC")
3397 CALL section_vals_val_get(ec_section,
"PRINT%MOMENTS%REF_POINT", r_vals=ref_point)
3398 unit_nr = cp_print_key_unit_nr(logger=logger, basis_section=ec_section, &
3399 print_key_path=
"PRINT%MOMENTS", extension=
".dat", &
3400 middle_name=
"moments", log_filename=.false.)
3402 IF (iounit > 0)
THEN
3403 IF (unit_nr /= iounit .AND. unit_nr > 0)
THEN
3404 INQUIRE (unit=unit_nr, name=filename)
3405 WRITE (unit=iounit, fmt=
"(/,T2,A,2(/,T3,A),/)") &
3406 "MOMENTS",
"The electric/magnetic moments are written to file:", &
3409 WRITE (unit=iounit, fmt=
"(/,T2,A)")
"ELECTRIC/MAGNETIC MOMENTS"
3414 cpabort(
"Periodic moments not implemented with EC")
3416 cpassert(maxmom < 2)
3417 cpassert(.NOT. magnetic)
3418 IF (maxmom == 1)
THEN
3419 CALL get_qs_env(qs_env=qs_env, cell=cell, para_env=para_env)
3421 CALL get_reference_point(rcc, qs_env=qs_env, reference=reference, ref_point=ref_point)
3424 CALL get_qs_env(qs_env=qs_env, particle_set=particle_set, &
3425 qs_kind_set=qs_kind_set, local_particles=local_particles)
3426 DO ikind = 1,
SIZE(local_particles%n_el)
3427 DO ia = 1, local_particles%n_el(ikind)
3428 iatom = local_particles%list(ikind)%array(ia)
3430 ria = pbc(particle_set(iatom)%r - rcc, cell) + rcc
3432 atomic_kind => particle_set(iatom)%atomic_kind
3433 CALL get_atomic_kind(atomic_kind, kind_number=akind)
3434 CALL get_qs_kind(qs_kind_set(akind), core_charge=charge)
3435 cdip(1:3) = cdip(1:3) - charge*ria(1:3)
3438 CALL para_env%sum(cdip)
3441 CALL ec_efield_integrals(qs_env, ec_env, rcc)
3444 DO ispin = 1, nspins
3446 CALL dbcsr_dot(ec_env%matrix_p(ispin, 1)%matrix, &
3447 ec_env%efield%dipmat(idir)%matrix, tmp)
3448 pdip(idir) = pdip(idir) + tmp
3453 CALL get_qs_env(qs_env=qs_env, matrix_s=matrix_s)
3455 CALL dbcsr_allocate_matrix_set(moments, 4)
3457 ALLOCATE (moments(i)%matrix)
3458 CALL dbcsr_copy(moments(i)%matrix, matrix_s(1)%matrix,
"Moments")
3459 CALL dbcsr_set(moments(i)%matrix, 0.0_dp)
3461 CALL build_local_moment_matrix(qs_env, moments, 1, ref_point=rcc)
3464 IF (nspins == 2) focc = 1.0_dp
3466 DO ispin = 1, nspins
3468 CALL dbcsr_dot(ec_env%matrix_z(ispin)%matrix, moments(idir)%matrix, tmp)
3469 rdip(idir) = rdip(idir) + tmp
3472 CALL dbcsr_deallocate_matrix_set(moments)
3474 tdip = -(rdip + pdip + cdip)
3475 IF (unit_nr > 0)
THEN
3476 WRITE (unit_nr,
"(T3,A)")
"Dipoles are based on the traditional operator."
3477 dd = sqrt(sum(tdip(1:3)**2))*debye
3478 WRITE (unit_nr,
"(T3,A)")
"Dipole moment [Debye]"
3479 WRITE (unit_nr,
"(T5,3(A,A,F14.8,1X),T60,A,T67,F14.8)") &
3480 (trim(rlab(i)),
"=", tdip(i)*debye, i=1, 3),
"Total=", dd
3485 CALL cp_print_key_finished_output(unit_nr=unit_nr, logger=logger, &
3486 basis_section=ec_section, print_key_path=
"PRINT%MOMENTS")
3487 CALL get_qs_env(qs_env=qs_env, results=results)
3488 description =
"[DIPOLE]"
3489 CALL cp_results_erase(results=results, description=description)
3490 CALL put_results(results=results, description=description, values=tdip(1:3))
3494 print_key_voro => section_vals_get_subs_vals(ec_section,
"PRINT%VORONOI")
3495 print_key_bqb => section_vals_get_subs_vals(ec_section,
"PRINT%E_DENSITY_BQB")
3496 IF (btest(cp_print_key_should_output(logger%iter_info, print_key_voro), cp_p_file))
THEN
3497 should_print_voro = 1
3499 should_print_voro = 0
3501 IF (btest(cp_print_key_should_output(logger%iter_info, print_key_bqb), cp_p_file))
THEN
3502 should_print_bqb = 1
3504 should_print_bqb = 0
3506 IF ((should_print_voro /= 0) .OR. (should_print_bqb /= 0))
THEN
3508 IF (dft_control%qs_control%gapw .OR. dft_control%qs_control%gapw_xc)
THEN
3509 cpabort(
"Properties for GAPW in EC NYA")
3512 CALL get_qs_env(qs_env=qs_env, &
3514 CALL pw_env_get(pw_env=pw_env, &
3515 auxbas_pw_pool=auxbas_pw_pool, &
3517 CALL auxbas_pw_pool%create_pw(pw=rho_elec_rspace)
3519 IF (dft_control%nspins > 1)
THEN
3522 CALL pw_copy(ec_env%rhoout_r(1), rho_elec_rspace)
3523 CALL pw_axpy(ec_env%rhoout_r(2), rho_elec_rspace)
3525 CALL pw_axpy(ec_env%rhoz_r(1), rho_elec_rspace)
3526 CALL pw_axpy(ec_env%rhoz_r(2), rho_elec_rspace)
3530 CALL pw_copy(ec_env%rhoout_r(1), rho_elec_rspace)
3531 CALL pw_axpy(ec_env%rhoz_r(1), rho_elec_rspace)
3534 IF (should_print_voro /= 0)
THEN
3535 CALL section_vals_val_get(print_key_voro,
"OUTPUT_TEXT", l_val=voro_print_txt)
3536 IF (voro_print_txt)
THEN
3537 append_voro = section_get_lval(ec_section,
"PRINT%VORONOI%APPEND")
3538 my_pos_voro =
"REWIND"
3539 IF (append_voro)
THEN
3540 my_pos_voro =
"APPEND"
3542 unit_nr_voro = cp_print_key_unit_nr(logger, ec_section,
"PRINT%VORONOI", extension=
".voronoi", &
3543 file_position=my_pos_voro, log_filename=.false.)
3551 CALL entry_voronoi_or_bqb(should_print_voro, should_print_bqb, print_key_voro, print_key_bqb, &
3552 unit_nr_voro, qs_env, rho_elec_rspace)
3554 CALL auxbas_pw_pool%give_back_pw(rho_elec_rspace)
3556 IF (unit_nr_voro > 0)
THEN
3557 CALL cp_print_key_finished_output(unit_nr_voro, logger, ec_section,
"PRINT%VORONOI")
3562 CALL timestop(handle)
3564 END SUBROUTINE ec_properties
3571 SUBROUTINE harris_wfn_output(qs_env, ec_env, unit_nr)
3572 TYPE(qs_environment_type),
POINTER :: qs_env
3573 TYPE(energy_correction_type),
POINTER :: ec_env
3574 INTEGER,
INTENT(IN) :: unit_nr
3576 CHARACTER(LEN=*),
PARAMETER :: routinen =
'harris_wfn_output'
3578 INTEGER :: handle, ic, ires, ispin, nimages, nsize, &
3580 INTEGER,
DIMENSION(3) :: cell
3581 INTEGER,
DIMENSION(:, :, :),
POINTER :: cell_to_index
3582 TYPE(cp_blacs_env_type),
POINTER :: blacs_env
3583 TYPE(cp_fm_struct_type),
POINTER :: fm_struct
3584 TYPE(cp_fm_type) :: fmat
3585 TYPE(cp_logger_type),
POINTER :: logger
3586 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: denmat
3587 TYPE(mp_para_env_type),
POINTER :: para_env
3588 TYPE(particle_type),
DIMENSION(:),
POINTER :: particle_set
3589 TYPE(qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
3590 TYPE(section_vals_type),
POINTER :: ec_section
3594 CALL timeset(routinen, handle)
3596 logger => cp_get_default_logger()
3598 ec_section => section_vals_get_subs_vals(qs_env%input,
"DFT%ENERGY_CORRECTION")
3599 CALL get_qs_env(qs_env, qs_kind_set=qs_kind_set, particle_set=particle_set)
3601 IF (ec_env%do_kpoints)
THEN
3602 ires = cp_print_key_unit_nr(logger, ec_section,
"PRINT%HARRIS_OUTPUT_WFN", &
3603 extension=
".kp", file_status=
"REPLACE", file_action=
"WRITE", &
3604 file_form=
"UNFORMATTED", middle_name=
"Harris")
3606 CALL write_kpoints_file_header(qs_kind_set, particle_set, ires, basis_type=
"HARRIS")
3608 denmat => ec_env%matrix_p
3609 nspin =
SIZE(denmat, 1)
3610 nimages =
SIZE(denmat, 2)
3611 NULLIFY (cell_to_index)
3612 IF (nimages > 1)
THEN
3613 CALL get_kpoint_info(kpoint=ec_env%kpoints, cell_to_index=cell_to_index)
3615 CALL dbcsr_get_info(denmat(1, 1)%matrix, nfullrows_total=nsize)
3616 NULLIFY (blacs_env, para_env)
3617 CALL get_qs_env(qs_env=qs_env, blacs_env=blacs_env, para_env=para_env)
3619 CALL cp_fm_struct_create(fm_struct, context=blacs_env, nrow_global=nsize, &
3620 ncol_global=nsize, para_env=para_env)
3621 CALL cp_fm_create(fmat, fm_struct)
3622 CALL cp_fm_struct_release(fm_struct)
3625 IF (ires > 0)
WRITE (ires) ispin, nspin, nimages
3627 IF (nimages > 1)
THEN
3628 cell = get_cell(ic, cell_to_index)
3632 IF (ires > 0)
WRITE (ires) ic, cell
3633 CALL copy_dbcsr_to_fm(denmat(ispin, ic)%matrix, fmat)
3634 CALL cp_fm_write_unformatted(fmat, ires)
3638 CALL cp_print_key_finished_output(ires, logger, ec_section,
"PRINT%HARRIS_OUTPUT_WFN")
3639 CALL cp_fm_release(fmat)
3641 CALL cp_warn(__location__, &
3642 "Orbital energy correction potential is an experimental feature. "// &
3643 "Use it with extreme care")
3646 CALL timestop(handle)
3648 END SUBROUTINE harris_wfn_output
3656 SUBROUTINE response_force_error(qs_env, ec_env, unit_nr)
3657 TYPE(qs_environment_type),
POINTER :: qs_env
3658 TYPE(energy_correction_type),
POINTER :: ec_env
3659 INTEGER,
INTENT(IN) :: unit_nr
3661 CHARACTER(LEN=10) :: eformat
3662 INTEGER :: feunit, funit, i, ia, ib, ispin, mref, &
3663 na, nao, natom, nb, norb, nref, &
3665 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: natom_of_kind, rlist, t2cind
3666 LOGICAL :: debug_f, do_resp, is_source
3667 REAL(kind=dp) :: focc, rfac, vres
3668 REAL(kind=dp),
ALLOCATABLE,
DIMENSION(:) :: tvec, yvec
3669 REAL(kind=dp),
ALLOCATABLE,
DIMENSION(:, :) :: eforce, fmlocal, fmreord, smat
3670 REAL(kind=dp),
ALLOCATABLE,
DIMENSION(:, :, :) :: smpforce
3671 TYPE(atomic_kind_type),
DIMENSION(:),
POINTER :: atomic_kind_set
3672 TYPE(cp_fm_struct_type),
POINTER :: fm_struct, fm_struct_mat
3673 TYPE(cp_fm_type) :: hmats
3674 TYPE(cp_fm_type),
DIMENSION(:, :),
POINTER :: rpmos, spmos
3675 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_s
3676 TYPE(dbcsr_type),
POINTER :: mats
3677 TYPE(mp_para_env_type),
POINTER :: para_env
3678 TYPE(qs_force_type),
DIMENSION(:),
POINTER :: ks_force, res_force
3679 TYPE(virial_type) :: res_virial
3680 TYPE(virial_type),
POINTER :: ks_virial
3682 IF (unit_nr > 0)
THEN
3683 WRITE (unit_nr,
'(/,T2,A,A,A,A,A)')
"!", repeat(
"-", 25), &
3684 " Response Force Error Est. ", repeat(
"-", 25),
"!"
3685 SELECT CASE (ec_env%error_method)
3687 WRITE (unit_nr,
'(T2,A)')
" Response Force Error Est. using full RHS"
3689 WRITE (unit_nr,
'(T2,A)')
" Response Force Error Est. using delta RHS"
3691 WRITE (unit_nr,
'(T2,A)')
" Response Force Error Est. using extrapolated RHS"
3692 WRITE (unit_nr,
'(T2,A,E20.10)')
" Extrapolation cutoff:", ec_env%error_cutoff
3693 WRITE (unit_nr,
'(T2,A,I10)')
" Max. extrapolation size:", ec_env%error_subspace
3695 cpabort(
"Unknown Error Estimation Method")
3699 IF (abs(ec_env%orbrot_index) > 1.e-8_dp .OR. ec_env%phase_index > 1.e-8_dp)
THEN
3700 cpabort(
"Response error calculation for rotated orbital sets not implemented")
3703 SELECT CASE (ec_env%energy_functional)
3704 CASE (ec_functional_harris)
3705 cpwarn(
'Response force error calculation not possible for Harris functional.')
3706 CASE (ec_functional_dc)
3707 cpwarn(
'Response force error calculation not possible for DCDFT.')
3708 CASE (ec_functional_ext)
3711 CALL get_qs_env(qs_env, force=ks_force, virial=ks_virial, &
3712 atomic_kind_set=atomic_kind_set)
3713 CALL get_atomic_kind_set(atomic_kind_set=atomic_kind_set, natom_of_kind=natom_of_kind)
3715 CALL allocate_qs_force(res_force, natom_of_kind)
3716 DEALLOCATE (natom_of_kind)
3717 CALL zero_qs_force(res_force)
3718 res_virial = ks_virial
3719 CALL zero_virial(ks_virial, reset=.false.)
3720 CALL set_qs_env(qs_env, force=res_force)
3722 CALL get_qs_env(qs_env, natom=natom)
3723 ALLOCATE (eforce(3, natom))
3725 CALL get_qs_env(qs_env, para_env=para_env)
3726 is_source = para_env%is_source()
3728 nspins =
SIZE(ec_env%mo_occ)
3729 CALL cp_fm_get_info(ec_env%mo_occ(1), nrow_global=nao)
3732 CALL open_file(ec_env%exresperr_fn, file_status=
"OLD", file_action=
"READ", &
3733 file_form=
"FORMATTED", unit_number=funit)
3734 READ (funit,
'(A)') eformat
3735 CALL uppercase(eformat)
3736 READ (funit, *) nsample
3738 CALL para_env%bcast(nsample, para_env%source)
3739 CALL para_env%bcast(eformat, para_env%source)
3741 CALL cp_fm_get_info(ec_env%mo_occ(1), matrix_struct=fm_struct)
3742 CALL cp_fm_struct_create(fm_struct_mat, template_fmstruct=fm_struct, &
3743 nrow_global=nao, ncol_global=nao)
3744 ALLOCATE (fmlocal(nao, nao))
3745 IF (adjustl(trim(eformat)) ==
"TREXIO")
THEN
3746 ALLOCATE (fmreord(nao, nao))
3747 CALL get_t2cindex(qs_env, t2cind)
3749 ALLOCATE (rpmos(nsample, nspins))
3750 ALLOCATE (smpforce(3, natom, nsample))
3754 IF (nspins == 1) focc = 4.0_dp
3755 CALL cp_fm_create(hmats, fm_struct_mat)
3758 DO ispin = 1, nspins
3759 CALL cp_fm_create(rpmos(i, ispin), fm_struct)
3761 READ (funit, *) na, nb
3762 cpassert(na == nao .AND. nb == nao)
3763 READ (funit, *) fmlocal
3767 CALL para_env%bcast(fmlocal)
3769 SELECT CASE (adjustl(trim(eformat)))
3776 fmreord(ia, ib) = fmlocal(t2cind(ia), t2cind(ib))
3779 fmlocal(1:nao, 1:nao) = fmreord(1:nao, 1:nao)
3781 cpabort(
"Error file dE/dC: unknown format")
3784 CALL cp_fm_set_submatrix(hmats, fmlocal, 1, 1, nao, nao)
3785 CALL cp_fm_get_info(rpmos(i, ispin), ncol_global=norb)
3786 CALL parallel_gemm(
'N',
'N', nao, norb, nao, focc, hmats, &
3787 ec_env%mo_occ(ispin), 0.0_dp, rpmos(i, ispin))
3788 IF (ec_env%error_method ==
"D" .OR. ec_env%error_method ==
"E")
THEN
3789 CALL cp_fm_scale_and_add(1.0_dp, rpmos(i, ispin), -1.0_dp, ec_env%cpref(ispin))
3793 CALL cp_fm_struct_release(fm_struct_mat)
3794 IF (adjustl(trim(eformat)) ==
"TREXIO")
THEN
3795 DEALLOCATE (fmreord, t2cind)
3799 CALL close_file(funit)
3802 IF (unit_nr > 0)
THEN
3803 CALL open_file(ec_env%exresult_fn, file_status=
"OLD", file_form=
"FORMATTED", &
3804 file_action=
"WRITE", file_position=
"APPEND", unit_number=feunit)
3805 WRITE (feunit,
"(/,6X,A)")
" Response Forces from error sampling [Hartree/Bohr]"
3807 WRITE (feunit,
"(5X,I8)") i
3809 WRITE (feunit,
"(5X,3F20.12)") ec_env%rf(1:3, ia)
3813 debug_f = ec_env%debug_forces .OR. ec_env%debug_stress
3815 IF (ec_env%error_method ==
"E")
THEN
3816 CALL get_qs_env(qs_env, matrix_s=matrix_s)
3817 mats => matrix_s(1)%matrix
3818 ALLOCATE (spmos(nsample, nspins))
3820 DO ispin = 1, nspins
3821 CALL cp_fm_create(spmos(i, ispin), fm_struct, set_zero=.true.)
3822 CALL cp_dbcsr_sm_fm_multiply(mats, rpmos(i, ispin), spmos(i, ispin), norb)
3827 mref = ec_env%error_subspace
3828 mref = min(mref, nsample)
3830 ALLOCATE (smat(mref, mref), tvec(mref), yvec(mref), rlist(mref))
3833 CALL cp_fm_release(ec_env%cpmos)
3836 IF (unit_nr > 0)
THEN
3837 WRITE (unit_nr,
'(T2,A,I6)')
" Response Force Number ", i
3840 CALL zero_qs_force(res_force)
3841 CALL zero_virial(ks_virial, reset=.false.)
3842 DO ispin = 1, nspins
3843 CALL dbcsr_set(ec_env%matrix_hz(ispin)%matrix, 0.0_dp)
3846 ALLOCATE (ec_env%cpmos(nspins))
3847 DO ispin = 1, nspins
3848 CALL cp_fm_create(ec_env%cpmos(ispin), fm_struct)
3852 IF (ec_env%error_method ==
"F" .OR. ec_env%error_method ==
"D")
THEN
3853 DO ispin = 1, nspins
3854 CALL cp_fm_to_fm(rpmos(i, ispin), ec_env%cpmos(ispin))
3856 ELSE IF (ec_env%error_method ==
"E")
THEN
3857 CALL cp_extrapolate(rpmos, spmos, i, nref, rlist, smat, tvec, yvec, vres)
3858 IF (vres > ec_env%error_cutoff .OR. nref < min(5, mref))
THEN
3859 DO ispin = 1, nspins
3860 CALL cp_fm_to_fm(rpmos(i, ispin), ec_env%cpmos(ispin))
3865 DO ispin = 1, nspins
3866 CALL cp_fm_scale_and_add(1.0_dp, ec_env%cpmos(ispin), &
3867 rfac, rpmos(ia, ispin))
3873 IF (unit_nr > 0)
THEN
3874 WRITE (unit_nr,
'(T2,A,T60,I4,T69,F12.8)') &
3875 " Response Vector Extrapolation [nref|delta] = ", nref, vres
3878 cpabort(
"Unknown Error Estimation Method")
3882 CALL matrix_r_forces(qs_env, ec_env%cpmos, ec_env%mo_occ, &
3883 ec_env%matrix_w(1, 1)%matrix, unit_nr, &
3884 ec_env%debug_forces, ec_env%debug_stress)
3886 CALL response_calculation(qs_env, ec_env, silent=.true.)
3888 CALL response_force(qs_env, &
3889 vh_rspace=ec_env%vh_rspace, &
3890 vxc_rspace=ec_env%vxc_rspace, &
3891 vtau_rspace=ec_env%vtau_rspace, &
3892 vadmm_rspace=ec_env%vadmm_rspace, &
3893 vadmm_tau_rspace=ec_env%vadmm_tau_rspace, &
3894 matrix_hz=ec_env%matrix_hz, &
3895 matrix_pz=ec_env%matrix_z, &
3896 matrix_pz_admm=ec_env%z_admm, &
3897 matrix_wz=ec_env%matrix_wz, &
3898 rhopz_r=ec_env%rhoz_r, &
3899 zehartree=ec_env%ehartree, &
3901 zexc_aux_fit=ec_env%exc_aux_fit, &
3902 p_env=ec_env%p_env, &
3904 CALL total_qs_force(eforce, res_force, atomic_kind_set)
3905 CALL para_env%sum(eforce)
3907 IF (unit_nr > 0)
THEN
3908 WRITE (unit_nr,
'(T2,A)')
" Response Force Calculation is skipped. "
3913 IF (ec_env%error_method ==
"D")
THEN
3914 eforce(1:3, 1:natom) = eforce(1:3, 1:natom) + ec_env%rf(1:3, 1:natom)
3915 smpforce(1:3, 1:natom, i) = eforce(1:3, 1:natom)
3916 ELSE IF (ec_env%error_method ==
"E")
THEN
3920 eforce(1:3, 1:natom) = eforce(1:3, 1:natom) + rfac*smpforce(1:3, 1:natom, ia)
3922 smpforce(1:3, 1:natom, i) = eforce(1:3, 1:natom)
3923 eforce(1:3, 1:natom) = eforce(1:3, 1:natom) + ec_env%rf(1:3, 1:natom)
3924 IF (do_resp .AND. nref < mref)
THEN
3929 smpforce(1:3, 1:natom, i) = eforce(1:3, 1:natom)
3932 IF (unit_nr > 0)
THEN
3933 WRITE (unit_nr, *)
" FORCES"
3935 WRITE (unit_nr,
"(i7,3F11.6,6X,3F11.6)") ia, eforce(1:3, ia), &
3936 (eforce(1:3, ia) - ec_env%rf(1:3, ia))
3940 WRITE (feunit,
"(5X,I8)") i
3942 WRITE (feunit,
"(5X,3F20.12)") eforce(1:3, ia)
3946 CALL cp_fm_release(ec_env%cpmos)
3950 IF (unit_nr > 0)
THEN
3951 CALL close_file(feunit)
3954 DEALLOCATE (smat, tvec, yvec, rlist)
3956 CALL cp_fm_release(hmats)
3957 CALL cp_fm_release(rpmos)
3958 IF (ec_env%error_method ==
"E")
THEN
3959 CALL cp_fm_release(spmos)
3962 DEALLOCATE (eforce, smpforce)
3965 CALL get_qs_env(qs_env, force=res_force, virial=ks_virial)
3966 CALL set_qs_env(qs_env, force=ks_force)
3967 CALL deallocate_qs_force(res_force)
3968 ks_virial = res_virial
3971 cpabort(
"unknown energy correction")
3974 END SUBROUTINE response_force_error
3988 SUBROUTINE cp_extrapolate(rpmos, Spmos, ip, nref, rlist, smat, tvec, yvec, vres)
3989 TYPE(cp_fm_type),
DIMENSION(:, :),
POINTER :: rpmos, spmos
3990 INTEGER,
INTENT(IN) :: ip, nref
3991 INTEGER,
DIMENSION(:),
INTENT(IN) :: rlist
3992 REAL(kind=dp),
DIMENSION(:, :),
INTENT(INOUT) :: smat
3993 REAL(kind=dp),
DIMENSION(:),
INTENT(INOUT) :: tvec, yvec
3994 REAL(kind=dp),
INTENT(OUT) :: vres
3996 INTEGER :: i, ia, j, ja
3997 REAL(kind=dp) :: aval
3998 REAL(kind=dp),
ALLOCATABLE,
DIMENSION(:, :) :: sinv
4006 ALLOCATE (sinv(nref, nref))
4010 tvec(i) = ctrace(rpmos(ip, :), spmos(ia, :))
4013 smat(j, i) = ctrace(rpmos(ja, :), spmos(ia, :))
4014 smat(i, j) = smat(j, i)
4016 smat(i, i) = ctrace(rpmos(ia, :), spmos(ia, :))
4018 aval = ctrace(rpmos(ip, :), spmos(ip, :))
4020 sinv(1:nref, 1:nref) = smat(1:nref, 1:nref)
4021 CALL invmat_symm(sinv(1:nref, 1:nref))
4023 yvec(1:nref) = matmul(sinv(1:nref, 1:nref), tvec(1:nref))
4025 vres = aval - sum(yvec(1:nref)*tvec(1:nref))
4026 vres = sqrt(abs(vres))
4033 END SUBROUTINE cp_extrapolate
4041 FUNCTION ctrace(ca, cb)
4042 TYPE(cp_fm_type),
DIMENSION(:) :: ca, cb
4043 REAL(kind=dp) :: ctrace
4046 REAL(kind=dp) :: trace
4052 CALL cp_fm_trace(ca(is), cb(is), trace)
4053 ctrace = ctrace + trace
4063 SUBROUTINE get_t2cindex(qs_env, t2cind)
4064 TYPE(qs_environment_type),
POINTER :: qs_env
4065 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: t2cind
4067 INTEGER :: i, iatom, ikind, is, iset, ishell, k, l, &
4068 m, natom, nset, nsgf, numshell
4069 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: lshell
4070 INTEGER,
DIMENSION(:),
POINTER :: nshell
4071 INTEGER,
DIMENSION(:, :),
POINTER :: lval
4072 TYPE(gto_basis_set_type),
POINTER :: basis_set
4073 TYPE(particle_type),
DIMENSION(:),
POINTER :: particle_set
4074 TYPE(qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
4078 CALL get_qs_env(qs_env, qs_kind_set=qs_kind_set, particle_set=particle_set, natom=natom)
4079 CALL get_qs_kind_set(qs_kind_set, nshell=numshell, nsgf=nsgf)
4081 ALLOCATE (t2cind(nsgf))
4082 ALLOCATE (lshell(numshell))
4086 CALL get_atomic_kind(particle_set(iatom)%atomic_kind, kind_number=ikind)
4087 CALL get_qs_kind(qs_kind_set(ikind), basis_set=basis_set, basis_type=
"ORB")
4088 CALL get_gto_basis_set(basis_set, nset=nset, nshell=nshell, l=lval)
4090 DO is = 1, nshell(iset)
4099 DO ishell = 1, numshell
4102 m = (-1)**k*floor(real(k, kind=dp)/2.0_dp)
4103 t2cind(i + l + 1 + m) = i + k
4110 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)
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_create(matrix, matrix_struct, name, use_sp, nrow, ncol, set_zero)
creates a new full matrix with the given structure
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...
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 used for Harris functional Kohn-Sham calculation.
subroutine, public create_kernel(qs_env, vxc, vxc_tau, rho, rho1_r, rho1_g, tau1_r, xc_section, compute_virial, virial_xc)
Creation of second derivative xc-potential.
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)
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, 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.
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, 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, 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, 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)
...
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)
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_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...
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)
...
subroutine, public qs_vxc_create(ks_env, rho_struct, xc_section, vxc_rho, vxc_tau, exc, just_energy, edisp, dispersion_env, adiabatic_rescale_factor, pw_env_external, native_skala_atom_force)
calculates and allocates the xc potential, already reducing it to the dependence on rho and the one o...
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.