195#include "./base/base_uses.f90"
203 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'energy_corrections'
224 LOGICAL,
INTENT(IN),
OPTIONAL :: ec_init, calculate_forces
226 CHARACTER(len=*),
PARAMETER :: routinen =
'energy_correction'
228 INTEGER :: handle, unit_nr
229 LOGICAL :: my_calc_forces
236 CALL timeset(routinen, handle)
239 IF (logger%para_env%is_source())
THEN
251 IF (.NOT. ec_env%do_skip)
THEN
253 ec_env%should_update = .true.
254 IF (
PRESENT(ec_init)) ec_env%should_update = ec_init
256 my_calc_forces = .false.
257 IF (
PRESENT(calculate_forces)) my_calc_forces = calculate_forces
259 IF (ec_env%should_update)
THEN
260 ec_env%old_etotal = 0.0_dp
261 ec_env%etotal = 0.0_dp
262 ec_env%eband = 0.0_dp
263 ec_env%ehartree = 0.0_dp
267 ec_env%edispersion = 0.0_dp
268 ec_env%exc_aux_fit = 0.0_dp
272 ec_env%old_etotal = energy%total
276 IF (my_calc_forces)
THEN
277 IF (unit_nr > 0)
THEN
278 WRITE (unit_nr,
'(T2,A,A,A,A,A)')
"!", repeat(
"-", 25), &
279 " Energy Correction Forces ", repeat(
"-", 26),
"!"
281 CALL get_qs_env(qs_env, force=ks_force, virial=virial)
285 IF (unit_nr > 0)
THEN
286 WRITE (unit_nr,
'(T2,A,A,A,A,A)')
"!", repeat(
"-", 29), &
287 " Energy Correction ", repeat(
"-", 29),
"!"
292 CALL energy_correction_low(qs_env, ec_env, my_calc_forces, unit_nr)
295 IF (ec_env%should_update)
THEN
296 energy%nonscf_correction = ec_env%etotal - ec_env%old_etotal
297 energy%total = ec_env%etotal
300 IF (.NOT. my_calc_forces .AND. unit_nr > 0)
THEN
301 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Energy Correction ", energy%nonscf_correction
303 IF (unit_nr > 0)
THEN
304 WRITE (unit_nr,
'(T2,A,A,A)')
"!", repeat(
"-", 77),
"!"
311 IF (unit_nr > 0)
THEN
312 WRITE (unit_nr,
'(T2,A,A,A)')
"!", repeat(
"-", 77),
"!"
313 WRITE (unit_nr,
'(T2,A,A,A,A,A)')
"!", repeat(
"-", 26), &
314 " Skip Energy Correction ", repeat(
"-", 27),
"!"
315 WRITE (unit_nr,
'(T2,A,A,A)')
"!", repeat(
"-", 77),
"!"
320 CALL timestop(handle)
335 SUBROUTINE energy_correction_low(qs_env, ec_env, calculate_forces, unit_nr)
338 LOGICAL,
INTENT(IN) :: calculate_forces
339 INTEGER,
INTENT(IN) :: unit_nr
341 INTEGER :: ispin, nspins
348 IF (ec_env%should_update)
THEN
349 CALL ec_build_neighborlist(qs_env, ec_env)
353 ec_env%vtau_rspace, &
354 ec_env%vadmm_rspace, &
355 ec_env%ehartree, exc)
357 SELECT CASE (ec_env%energy_functional)
360 CALL ec_build_core_hamiltonian(qs_env, ec_env)
361 CALL ec_build_ks_matrix(qs_env, ec_env)
366 NULLIFY (ec_env%mao_coef)
367 CALL mao_generate_basis(qs_env, ec_env%mao_coef, ref_basis_set=
"HARRIS", molecular=.true., &
368 max_iter=ec_env%mao_max_iter, eps_grad=ec_env%mao_eps_grad, &
369 eps1_mao=ec_env%mao_eps1, iolevel=ec_env%mao_iolevel, unit_nr=unit_nr)
372 CALL ec_ks_solver(qs_env, ec_env)
374 CALL evaluate_ec_core_matrix_traces(qs_env, ec_env)
379 CALL ec_dc_energy(qs_env, ec_env, calculate_forces=.false.)
384 CALL ec_build_ks_matrix(qs_env, ec_env)
391 cpabort(
"unknown energy correction")
395 CALL ec_disp(qs_env, ec_env, calculate_forces=.false.)
398 CALL ec_energy(ec_env, unit_nr)
402 IF (calculate_forces)
THEN
404 debug_f = ec_env%debug_forces .OR. ec_env%debug_stress
406 CALL ec_disp(qs_env, ec_env, calculate_forces=.true.)
408 SELECT CASE (ec_env%energy_functional)
411 CALL ec_build_core_hamiltonian_force(qs_env, ec_env, &
415 CALL ec_build_ks_matrix_force(qs_env, ec_env)
416 IF (ec_env%debug_external)
THEN
417 CALL write_response_interface(qs_env, ec_env)
418 CALL init_response_deriv(qs_env, ec_env)
425 CALL ec_dc_energy(qs_env, ec_env, calculate_forces=.true.)
427 CALL ec_build_core_hamiltonian_force(qs_env, ec_env, &
431 CALL ec_dc_build_ks_matrix_force(qs_env, ec_env)
432 IF (ec_env%debug_external)
THEN
433 CALL write_response_interface(qs_env, ec_env)
434 CALL init_response_deriv(qs_env, ec_env)
440 CALL init_response_deriv(qs_env, ec_env)
443 cpabort(
"unknown energy correction")
450 CALL get_qs_env(qs_env=qs_env, dft_control=dft_control, pw_env=pw_env)
451 nspins = dft_control%nspins
453 cpassert(
ASSOCIATED(pw_env))
454 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
455 ALLOCATE (ec_env%rhoz_r(nspins))
457 CALL auxbas_pw_pool%create_pw(ec_env%rhoz_r(ispin))
461 vh_rspace=ec_env%vh_rspace, &
462 vxc_rspace=ec_env%vxc_rspace, &
463 vtau_rspace=ec_env%vtau_rspace, &
464 vadmm_rspace=ec_env%vadmm_rspace, &
465 matrix_hz=ec_env%matrix_hz, &
466 matrix_pz=ec_env%matrix_z, &
467 matrix_pz_admm=ec_env%z_admm, &
468 matrix_wz=ec_env%matrix_wz, &
469 rhopz_r=ec_env%rhoz_r, &
470 zehartree=ec_env%ehartree, &
472 zexc_aux_fit=ec_env%exc_aux_fit, &
473 p_env=ec_env%p_env, &
476 CALL output_response_deriv(qs_env, ec_env, unit_nr)
478 CALL ec_properties(qs_env, ec_env)
481 IF (
ASSOCIATED(ec_env%rhoout_r))
THEN
483 CALL auxbas_pw_pool%give_back_pw(ec_env%rhoout_r(ispin))
485 DEALLOCATE (ec_env%rhoout_r)
487 IF (
ASSOCIATED(ec_env%rhoz_r))
THEN
489 CALL auxbas_pw_pool%give_back_pw(ec_env%rhoz_r(ispin))
491 DEALLOCATE (ec_env%rhoz_r)
507 END SUBROUTINE energy_correction_low
515 SUBROUTINE write_response_interface(qs_env, ec_env)
522 NULLIFY (trexio_section)
528 END SUBROUTINE write_response_interface
536 SUBROUTINE init_response_deriv(qs_env, ec_env)
546 ALLOCATE (ec_env%rf(3, natom), ec_env%rferror(3, natom))
548 ec_env%rferror = 0.0_dp
550 ec_env%rpverror = 0.0_dp
551 CALL get_qs_env(qs_env, force=force, virial=virial)
553 CALL get_qs_env(qs_env, atomic_kind_set=atomic_kind_set)
556 IF (virial%pv_availability .AND. (.NOT. virial%pv_numer))
THEN
557 ec_env%rpv = virial%pv_virial
560 END SUBROUTINE init_response_deriv
569 SUBROUTINE output_response_deriv(qs_env, ec_env, unit_nr)
572 INTEGER,
INTENT(IN) :: unit_nr
574 INTEGER :: funit, ia, natom
575 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: ftot
582 IF (
ASSOCIATED(ec_env%rf))
THEN
584 ALLOCATE (ftot(3, natom))
586 CALL get_qs_env(qs_env, force=force, virial=virial)
588 CALL get_qs_env(qs_env, atomic_kind_set=atomic_kind_set)
590 ec_env%rf(1:3, 1:natom) = ftot(1:3, 1:natom) - ec_env%rf(1:3, 1:natom)
593 IF (virial%pv_availability .AND. (.NOT. virial%pv_numer))
THEN
594 ec_env%rpv = virial%pv_virial - ec_env%rpv
597 CALL get_qs_env(qs_env, particle_set=particle_set, cell=cell)
598 IF (unit_nr > 0)
THEN
599 WRITE (unit_nr,
'(T2,A)')
"Write EXTERNAL Response Derivative: "//trim(ec_env%exresult_fn)
601 CALL open_file(ec_env%exresult_fn, file_status=
"REPLACE", file_form=
"FORMATTED", &
602 file_action=
"WRITE", unit_number=funit)
603 WRITE (funit, *)
" COORDINATES // RESPONSE FORCES // ERRORS "
605 WRITE (funit,
"(3(3F15.8,5x))") particle_set(ia)%r(1:3), &
606 ec_env%rf(1:3, ia), ec_env%rferror(1:3, ia)
609 WRITE (funit, *)
" CELL // RESPONSE PRESSURE // ERRORS "
611 WRITE (funit,
"(3F15.8,5x,3F15.8,5x,3F15.8)") cell%hmat(ia, 1:3), &
612 ec_env%rpv(ia, 1:3), ec_env%rpverror(ia, 1:3)
619 END SUBROUTINE output_response_deriv
628 SUBROUTINE evaluate_ec_core_matrix_traces(qs_env, ec_env)
632 CHARACTER(LEN=*),
PARAMETER :: routinen =
'evaluate_ec_core_matrix_traces'
638 CALL timeset(routinen, handle)
641 CALL get_qs_env(qs_env, dft_control=dft_control, energy=energy)
644 CALL calculate_ptrace(ec_env%matrix_h, ec_env%matrix_p, energy%core, dft_control%nspins)
647 CALL calculate_ptrace(ec_env%matrix_t, ec_env%matrix_p, energy%kinetic, dft_control%nspins)
649 CALL timestop(handle)
651 END SUBROUTINE evaluate_ec_core_matrix_traces
664 SUBROUTINE ec_dc_energy(qs_env, ec_env, calculate_forces)
667 LOGICAL,
INTENT(IN) :: calculate_forces
669 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ec_dc_energy'
671 CHARACTER(LEN=default_string_length) :: headline
672 INTEGER :: handle, ispin, nspins
673 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_h, matrix_p, matrix_s, matrix_w
678 CALL timeset(routinen, handle)
680 NULLIFY (dft_control, ks_env, matrix_h, matrix_p, matrix_s, matrix_w, rho)
682 dft_control=dft_control, &
684 matrix_h_kp=matrix_h, &
685 matrix_s_kp=matrix_s, &
686 matrix_w_kp=matrix_w, &
689 nspins = dft_control%nspins
694 matrix_name=
"OVERLAP MATRIX", &
695 basis_type_a=
"HARRIS", &
696 basis_type_b=
"HARRIS", &
697 sab_nl=ec_env%sab_orb)
702 headline =
"CORE HAMILTONIAN MATRIX"
703 ALLOCATE (ec_env%matrix_h(1, 1)%matrix)
704 CALL dbcsr_create(ec_env%matrix_h(1, 1)%matrix, name=trim(headline), &
705 template=matrix_s(1, 1)%matrix, matrix_type=dbcsr_type_symmetric)
707 CALL dbcsr_copy(ec_env%matrix_h(1, 1)%matrix, matrix_h(1, 1)%matrix)
712 headline =
"DENSITY MATRIX"
714 ALLOCATE (ec_env%matrix_p(ispin, 1)%matrix)
715 CALL dbcsr_create(ec_env%matrix_p(ispin, 1)%matrix, name=trim(headline), &
716 template=matrix_s(1, 1)%matrix, matrix_type=dbcsr_type_symmetric)
718 CALL dbcsr_copy(ec_env%matrix_p(ispin, 1)%matrix, matrix_p(ispin, 1)%matrix)
721 IF (calculate_forces)
THEN
726 headline =
"ENERGY-WEIGHTED DENSITY MATRIX"
728 ALLOCATE (ec_env%matrix_w(ispin, 1)%matrix)
729 CALL dbcsr_create(ec_env%matrix_w(ispin, 1)%matrix, name=trim(headline), &
730 template=matrix_s(1, 1)%matrix, matrix_type=dbcsr_type_symmetric)
732 CALL dbcsr_copy(ec_env%matrix_w(ispin, 1)%matrix, matrix_w(ispin, 1)%matrix)
738 ec_env%efield_nuclear = 0.0_dp
739 ec_env%efield_elec = 0.0_dp
742 CALL timestop(handle)
744 END SUBROUTINE ec_dc_energy
755 SUBROUTINE ec_dc_build_ks_matrix_force(qs_env, ec_env)
759 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ec_dc_build_ks_matrix_force'
761 CHARACTER(LEN=default_string_length) :: unit_string
762 INTEGER :: handle, i, iounit, ispin, natom, nspins
763 LOGICAL :: debug_forces, debug_stress, do_ec_hfx, &
765 REAL(
dp) :: dummy_real, dummy_real2(2), ehartree, &
767 REAL(
dp),
ALLOCATABLE,
DIMENSION(:, :) :: ftot
768 REAL(
dp),
DIMENSION(3) :: fodeb, fodeb2
769 REAL(kind=
dp),
DIMENSION(3, 3) :: h_stress, pv_loc, stdeb, sttot
773 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_ks, matrix_s, scrm
774 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_p
785 TYPE(
pw_r3d_rs_type),
DIMENSION(:),
POINTER :: rho_r, v_rspace, v_rspace_in, &
793 CALL timeset(routinen, handle)
795 debug_forces = ec_env%debug_forces
796 debug_stress = ec_env%debug_stress
799 IF (logger%para_env%is_source())
THEN
805 NULLIFY (atomic_kind_set, cell, dft_control, force, ks_env, matrix_ks, &
806 matrix_p, matrix_s, para_env, pw_env, rho, sab_orb, virial)
809 dft_control=dft_control, &
812 matrix_ks=matrix_ks, &
819 cpassert(
ASSOCIATED(pw_env))
821 nspins = dft_control%nspins
822 use_virial = virial%pv_availability .AND. (.NOT. virial%pv_numer)
824 fconv = 1.0e-9_dp*
pascal/cell%deth
825 IF (debug_stress .AND. use_virial)
THEN
826 sttot = virial%pv_virial
832 NULLIFY (auxbas_pw_pool, poisson_env)
834 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool, &
835 poisson_env=poisson_env)
838 CALL auxbas_pw_pool%create_pw(v_hartree_gspace)
839 CALL auxbas_pw_pool%create_pw(rho_tot_gspace)
840 CALL auxbas_pw_pool%create_pw(v_hartree_rspace)
849 h_stress(:, :) = 0.0_dp
851 density=rho_tot_gspace, &
853 vhartree=v_hartree_gspace, &
856 virial%pv_ehartree = virial%pv_ehartree + h_stress/real(para_env%num_pe,
dp)
857 virial%pv_virial = virial%pv_virial + h_stress/real(para_env%num_pe,
dp)
859 IF (debug_stress)
THEN
860 stdeb = fconv*(h_stress/real(para_env%num_pe,
dp))
861 CALL para_env%sum(stdeb)
862 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
871 CALL pw_transfer(v_hartree_gspace, v_hartree_rspace)
872 CALL pw_scale(v_hartree_rspace, v_hartree_rspace%pw_grid%dvol)
876 ALLOCATE (ec_env%rhoout_r(nspins))
878 CALL auxbas_pw_pool%create_pw(ec_env%rhoout_r(ispin))
879 CALL pw_copy(rho_r(ispin), ec_env%rhoout_r(ispin))
884 IF (debug_forces) fodeb(1:3) = force(1)%rho_core(1:3, 1)
885 IF (debug_stress .AND. use_virial) stdeb = virial%pv_ehartree
886 CALL integrate_v_core_rspace(v_hartree_rspace, qs_env)
887 IF (debug_forces)
THEN
888 fodeb(1:3) = force(1)%rho_core(1:3, 1) - fodeb(1:3)
889 CALL para_env%sum(fodeb)
890 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Vtot*dncore", fodeb
892 IF (debug_stress .AND. use_virial)
THEN
893 stdeb = fconv*(virial%pv_ehartree - stdeb)
894 CALL para_env%sum(stdeb)
895 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
901 NULLIFY (v_rspace, v_tau_rspace)
904 IF (use_virial) virial%pv_calculate = .true.
907 CALL qs_vxc_create(ks_env=ks_env, rho_struct=rho, xc_section=ec_env%xc_section, &
908 vxc_rho=v_rspace, vxc_tau=v_tau_rspace, exc=exc, just_energy=.false.)
910 IF (.NOT.
ASSOCIATED(v_rspace))
THEN
911 ALLOCATE (v_rspace(nspins))
913 CALL auxbas_pw_pool%create_pw(v_rspace(ispin))
919 virial%pv_exc = virial%pv_exc - virial%pv_xc
920 virial%pv_virial = virial%pv_virial - virial%pv_xc
928 ALLOCATE (scrm(ispin)%matrix)
929 CALL dbcsr_create(scrm(ispin)%matrix, template=ec_env%matrix_ks(ispin, 1)%matrix)
930 CALL dbcsr_copy(scrm(ispin)%matrix, ec_env%matrix_ks(ispin, 1)%matrix)
931 CALL dbcsr_set(scrm(ispin)%matrix, 0.0_dp)
934 pw_grid => v_hartree_rspace%pw_grid
935 ALLOCATE (v_rspace_in(nspins))
937 CALL v_rspace_in(ispin)%create(pw_grid)
943 CALL pw_transfer(ec_env%vxc_rspace(ispin), v_rspace_in(ispin))
945 CALL pw_axpy(ec_env%vh_rspace, v_rspace_in(ispin))
956 IF (debug_forces) fodeb(1:3) = force(1)%fock_4c(1:3, 1)
957 IF (debug_forces) fodeb2(1:3) = force(1)%overlap_admm(1:3, 1)
964 hfx_sections=ec_hfx_sections, &
965 x_data=ec_env%x_data, &
967 do_admm=ec_env%do_ec_admm, &
968 calc_forces=.true., &
969 reuse_hfx=ec_env%reuse_hfx, &
970 do_im_time=.false., &
971 e_ex_from_gw=dummy_real, &
972 e_admm_from_gw=dummy_real2, &
975 IF (debug_forces)
THEN
976 fodeb(1:3) = force(1)%fock_4c(1:3, 1) - fodeb(1:3)
977 CALL para_env%sum(fodeb)
978 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: P*hfx_DC ", fodeb
980 fodeb2(1:3) = force(1)%overlap_admm(1:3, 1) - fodeb2(1:3)
981 CALL para_env%sum(fodeb2)
982 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: P*hfx_DC*S ", fodeb2
984 IF (debug_stress .AND. use_virial)
THEN
985 stdeb = -1.0_dp*fconv*virial%pv_fock_4c
986 CALL para_env%sum(stdeb)
987 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
998 pv_loc = virial%pv_virial
1001 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
1002 IF (debug_stress .AND. use_virial) stdeb = virial%pv_virial
1004 DO ispin = 1, nspins
1006 CALL pw_scale(v_rspace(ispin), v_rspace(ispin)%pw_grid%dvol)
1007 CALL pw_axpy(v_hartree_rspace, v_rspace(ispin))
1009 CALL integrate_v_rspace(v_rspace=v_rspace(ispin), &
1011 pmat=matrix_p(ispin, 1), &
1013 calculate_forces=.true., &
1014 basis_type=
"HARRIS", &
1015 task_list_external=ec_env%task_list)
1018 IF (debug_forces)
THEN
1019 fodeb(1:3) = force(1)%rho_elec(1:3, 1) - fodeb(1:3)
1020 CALL para_env%sum(fodeb)
1021 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Pout*dVhxc ", fodeb
1023 IF (debug_stress .AND. use_virial)
THEN
1024 stdeb = fconv*(virial%pv_virial - stdeb)
1025 CALL para_env%sum(stdeb)
1026 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1030 IF (
ASSOCIATED(v_tau_rspace))
THEN
1031 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
1032 IF (debug_stress .AND. use_virial) stdeb = virial%pv_virial
1033 DO ispin = 1, nspins
1034 CALL pw_scale(v_tau_rspace(ispin), v_tau_rspace(ispin)%pw_grid%dvol)
1036 CALL integrate_v_rspace(v_rspace=v_tau_rspace(ispin), &
1038 pmat=matrix_p(ispin, 1), &
1040 calculate_forces=.true., &
1041 compute_tau=.true., &
1042 basis_type=
"HARRIS", &
1043 task_list_external=ec_env%task_list)
1046 IF (debug_forces)
THEN
1047 fodeb(1:3) = force(1)%rho_elec(1:3, 1) - fodeb(1:3)
1048 CALL para_env%sum(fodeb)
1049 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Pout*dVhxc_tau ", fodeb
1051 IF (debug_stress .AND. use_virial)
THEN
1052 stdeb = fconv*(virial%pv_virial - stdeb)
1053 CALL para_env%sum(stdeb)
1054 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1060 IF (use_virial)
THEN
1061 virial%pv_ehartree = virial%pv_ehartree + (virial%pv_virial - pv_loc)
1080 NULLIFY (ec_env%matrix_hz)
1082 DO ispin = 1, nspins
1083 ALLOCATE (ec_env%matrix_hz(ispin)%matrix)
1084 CALL dbcsr_create(ec_env%matrix_hz(ispin)%matrix, template=matrix_s(1)%matrix)
1085 CALL dbcsr_copy(ec_env%matrix_hz(ispin)%matrix, matrix_s(1)%matrix)
1086 CALL dbcsr_set(ec_env%matrix_hz(ispin)%matrix, 0.0_dp)
1089 DO ispin = 1, nspins
1092 CALL pw_axpy(v_rspace_in(ispin), v_rspace(ispin), -1.0_dp)
1095 DO ispin = 1, nspins
1096 CALL integrate_v_rspace(v_rspace=v_rspace(ispin), &
1097 hmat=ec_env%matrix_hz(ispin), &
1098 pmat=matrix_p(ispin, 1), &
1100 calculate_forces=.false., &
1101 basis_type=
"HARRIS", &
1102 task_list_external=ec_env%task_list)
1106 IF (dft_control%use_kinetic_energy_density)
THEN
1109 IF (.NOT.
ASSOCIATED(v_tau_rspace))
THEN
1110 ALLOCATE (v_tau_rspace(nspins))
1111 DO ispin = 1, nspins
1112 CALL auxbas_pw_pool%create_pw(v_tau_rspace(ispin))
1113 CALL pw_zero(v_tau_rspace(ispin))
1117 DO ispin = 1, nspins
1119 IF (
ASSOCIATED(ec_env%vtau_rspace))
THEN
1120 CALL pw_axpy(ec_env%vtau_rspace(ispin), v_tau_rspace(ispin), -1.0_dp)
1123 CALL integrate_v_rspace(v_rspace=v_tau_rspace(ispin), &
1124 hmat=ec_env%matrix_hz(ispin), &
1125 pmat=matrix_p(ispin, 1), &
1127 calculate_forces=.false., compute_tau=.true., &
1128 basis_type=
"HARRIS", &
1129 task_list_external=ec_env%task_list)
1137 ext_hfx_section=ec_hfx_sections, &
1138 x_data=ec_env%x_data, &
1139 recalc_integrals=.false., &
1140 do_admm=ec_env%do_ec_admm, &
1143 reuse_hfx=ec_env%reuse_hfx)
1146 IF (debug_forces) fodeb(1:3) = force(1)%core_overlap(1:3, 1)
1147 IF (debug_stress .AND. use_virial) stdeb = virial%pv_ecore_overlap
1149 IF (debug_forces)
THEN
1150 fodeb(1:3) = force(1)%core_overlap(1:3, 1) - fodeb(1:3)
1151 CALL para_env%sum(fodeb)
1152 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: CoreOverlap", fodeb
1154 IF (debug_stress .AND. use_virial)
THEN
1155 stdeb = fconv*(stdeb - virial%pv_ecore_overlap)
1156 CALL para_env%sum(stdeb)
1157 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1161 IF (debug_forces)
THEN
1162 CALL get_qs_env(qs_env, natom=natom, atomic_kind_set=atomic_kind_set)
1163 ALLOCATE (ftot(3, natom))
1165 fodeb(1:3) = ftot(1:3, 1)
1167 CALL para_env%sum(fodeb)
1168 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Force Explicit", fodeb
1172 DO ispin = 1, nspins
1173 CALL auxbas_pw_pool%give_back_pw(v_rspace(ispin))
1174 CALL auxbas_pw_pool%give_back_pw(v_rspace_in(ispin))
1175 IF (
ASSOCIATED(v_tau_rspace))
THEN
1176 CALL auxbas_pw_pool%give_back_pw(v_tau_rspace(ispin))
1180 DEALLOCATE (v_rspace, v_rspace_in)
1181 IF (
ASSOCIATED(v_tau_rspace))
DEALLOCATE (v_tau_rspace)
1183 CALL auxbas_pw_pool%give_back_pw(rho_tot_gspace)
1184 CALL auxbas_pw_pool%give_back_pw(v_hartree_gspace)
1185 CALL auxbas_pw_pool%give_back_pw(v_hartree_rspace)
1189 IF (use_virial)
THEN
1190 IF (qs_env%energy_correction)
THEN
1191 ec_env%ehartree = ehartree
1196 IF (debug_stress .AND. use_virial)
THEN
1198 stdeb = -1.0_dp*fconv*ehartree
1199 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1202 stdeb = -1.0_dp*fconv*exc
1203 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1212 CALL para_env%sum(virdeb%pv_overlap)
1213 CALL para_env%sum(virdeb%pv_ekinetic)
1214 CALL para_env%sum(virdeb%pv_ppl)
1215 CALL para_env%sum(virdeb%pv_ppnl)
1216 CALL para_env%sum(virdeb%pv_ecore_overlap)
1217 CALL para_env%sum(virdeb%pv_ehartree)
1218 CALL para_env%sum(virdeb%pv_exc)
1219 CALL para_env%sum(virdeb%pv_exx)
1220 CALL para_env%sum(virdeb%pv_vdw)
1221 CALL para_env%sum(virdeb%pv_mp2)
1222 CALL para_env%sum(virdeb%pv_nlcc)
1223 CALL para_env%sum(virdeb%pv_gapw)
1224 CALL para_env%sum(virdeb%pv_lrigpw)
1225 CALL para_env%sum(virdeb%pv_virial)
1230 virdeb%pv_ehartree(i, i) = virdeb%pv_ehartree(i, i) - 2.0_dp*ehartree
1231 virdeb%pv_virial(i, i) = virdeb%pv_virial(i, i) - exc &
1233 virdeb%pv_exc(i, i) = virdeb%pv_exc(i, i) - exc
1239 CALL para_env%sum(sttot)
1240 stdeb = fconv*(virdeb%pv_virial - sttot)
1241 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1244 stdeb = fconv*(virdeb%pv_virial)
1245 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1255 CALL timestop(handle)
1257 END SUBROUTINE ec_dc_build_ks_matrix_force
1265 SUBROUTINE ec_disp(qs_env, ec_env, calculate_forces)
1266 TYPE(qs_environment_type),
POINTER :: qs_env
1267 TYPE(energy_correction_type),
POINTER :: ec_env
1268 LOGICAL,
INTENT(IN) :: calculate_forces
1270 REAL(kind=dp) :: edisp
1272 CALL calculate_dispersion_pairpot(qs_env, ec_env%dispersion_env, edisp, calculate_forces)
1273 IF (.NOT. calculate_forces) ec_env%edispersion = ec_env%edispersion + edisp
1275 END SUBROUTINE ec_disp
1284 SUBROUTINE ec_build_core_hamiltonian(qs_env, ec_env)
1285 TYPE(qs_environment_type),
POINTER :: qs_env
1286 TYPE(energy_correction_type),
POINTER :: ec_env
1288 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ec_build_core_hamiltonian'
1290 INTEGER :: handle, nder, nimages
1291 INTEGER,
DIMENSION(:, :, :),
POINTER :: cell_to_index
1292 LOGICAL :: calculate_forces, use_virial
1293 REAL(kind=dp) :: eps_ppnl
1294 TYPE(atomic_kind_type),
DIMENSION(:),
POINTER :: atomic_kind_set
1295 TYPE(dft_control_type),
POINTER :: dft_control
1296 TYPE(neighbor_list_set_p_type),
DIMENSION(:), &
1297 POINTER :: sab_orb, sac_ae, sac_ppl, sap_ppnl
1298 TYPE(particle_type),
DIMENSION(:),
POINTER :: particle_set
1299 TYPE(qs_force_type),
DIMENSION(:),
POINTER :: force
1300 TYPE(qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
1301 TYPE(qs_ks_env_type),
POINTER :: ks_env
1302 TYPE(virial_type),
POINTER :: virial
1304 CALL timeset(routinen, handle)
1306 NULLIFY (atomic_kind_set, cell_to_index, dft_control, ks_env, particle_set, qs_kind_set, virial)
1308 CALL get_qs_env(qs_env=qs_env, &
1309 atomic_kind_set=atomic_kind_set, &
1310 dft_control=dft_control, &
1311 particle_set=particle_set, &
1312 qs_kind_set=qs_kind_set, &
1316 nimages = dft_control%nimages
1317 IF (nimages /= 1)
THEN
1318 cpabort(
"K-points for Harris functional not implemented")
1322 IF (dft_control%qs_control%gapw .OR. dft_control%qs_control%gapw_xc)
THEN
1323 cpabort(
"Harris functional for GAPW not implemented")
1327 use_virial = .false.
1328 calculate_forces = .false.
1331 NULLIFY (sab_orb, sac_ae, sac_ppl, sap_ppnl)
1332 sab_orb => ec_env%sab_orb
1333 sac_ppl => ec_env%sac_ppl
1334 sap_ppnl => ec_env%sap_ppnl
1338 CALL build_overlap_matrix(ks_env, matrixkp_s=ec_env%matrix_s, &
1339 matrix_name=
"OVERLAP MATRIX", &
1340 basis_type_a=
"HARRIS", &
1341 basis_type_b=
"HARRIS", &
1343 CALL build_kinetic_matrix(ks_env, matrixkp_t=ec_env%matrix_t, &
1344 matrix_name=
"KINETIC ENERGY MATRIX", &
1345 basis_type=
"HARRIS", &
1349 CALL dbcsr_allocate_matrix_set(ec_env%matrix_h, 1, 1)
1350 ALLOCATE (ec_env%matrix_h(1, 1)%matrix)
1351 CALL dbcsr_create(ec_env%matrix_h(1, 1)%matrix, template=ec_env%matrix_s(1, 1)%matrix)
1352 CALL cp_dbcsr_alloc_block_from_nbl(ec_env%matrix_h(1, 1)%matrix, sab_orb)
1355 CALL dbcsr_copy(ec_env%matrix_h(1, 1)%matrix, ec_env%matrix_t(1, 1)%matrix, &
1356 keep_sparsity=.true., name=
"CORE HAMILTONIAN MATRIX")
1359 IF (
ASSOCIATED(sac_ae))
THEN
1360 cpabort(
"ECP/AE not available for energy corrections")
1363 CALL build_core_ae(ec_env%matrix_h, ec_env%matrix_p, force, &
1364 virial, calculate_forces, use_virial, nder, &
1365 qs_kind_set, atomic_kind_set, particle_set, sab_orb, sac_ae, &
1366 nimages, cell_to_index)
1369 IF (
ASSOCIATED(sac_ppl))
THEN
1370 CALL build_core_ppl(ec_env%matrix_h, ec_env%matrix_p, force, &
1371 virial, calculate_forces, use_virial, nder, &
1372 qs_kind_set, atomic_kind_set, particle_set, sab_orb, sac_ppl, &
1373 nimages, cell_to_index,
"HARRIS")
1377 eps_ppnl = dft_control%qs_control%eps_ppnl
1378 IF (
ASSOCIATED(sap_ppnl))
THEN
1379 CALL build_core_ppnl(ec_env%matrix_h, ec_env%matrix_p, force, &
1380 virial, calculate_forces, use_virial, nder, &
1381 qs_kind_set, atomic_kind_set, particle_set, sab_orb, sap_ppnl, &
1382 eps_ppnl, nimages, cell_to_index,
"HARRIS")
1386 ec_env%efield_nuclear = 0.0_dp
1387 CALL ec_efield_local_operator(qs_env, ec_env, calculate_forces)
1389 CALL timestop(handle)
1391 END SUBROUTINE ec_build_core_hamiltonian
1402 SUBROUTINE ec_build_ks_matrix(qs_env, ec_env)
1403 TYPE(qs_environment_type),
POINTER :: qs_env
1404 TYPE(energy_correction_type),
POINTER :: ec_env
1406 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ec_build_ks_matrix'
1408 CHARACTER(LEN=default_string_length) :: headline
1409 INTEGER :: handle, iounit, ispin, nspins
1410 LOGICAL :: calculate_forces, &
1411 do_adiabatic_rescaling, do_ec_hfx, &
1412 hfx_treat_lsd_in_core, use_virial
1413 REAL(dp) :: dummy_real, dummy_real2(2), eexc, evhxc, &
1415 TYPE(cp_logger_type),
POINTER :: logger
1416 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: ks_mat
1417 TYPE(dft_control_type),
POINTER :: dft_control
1418 TYPE(pw_env_type),
POINTER :: pw_env
1419 TYPE(pw_pool_type),
POINTER :: auxbas_pw_pool
1420 TYPE(pw_r3d_rs_type),
DIMENSION(:),
POINTER :: rho_r, tau_r, v_rspace, v_tau_rspace
1421 TYPE(qs_energy_type),
POINTER :: energy
1422 TYPE(qs_ks_env_type),
POINTER :: ks_env
1423 TYPE(qs_rho_type),
POINTER :: rho
1424 TYPE(section_vals_type),
POINTER :: adiabatic_rescaling_section, &
1425 ec_hfx_sections, ec_section
1427 CALL timeset(routinen, handle)
1429 logger => cp_get_default_logger()
1430 IF (logger%para_env%is_source())
THEN
1431 iounit = cp_logger_get_default_unit_nr(logger, local=.true.)
1437 NULLIFY (auxbas_pw_pool, dft_control, energy, ks_env, rho, rho_r, tau_r)
1438 CALL get_qs_env(qs_env=qs_env, &
1439 dft_control=dft_control, &
1442 nspins = dft_control%nspins
1443 calculate_forces = .false.
1444 use_virial = .false.
1447 IF (
ASSOCIATED(ec_env%matrix_ks))
CALL dbcsr_deallocate_matrix_set(ec_env%matrix_ks)
1448 CALL dbcsr_allocate_matrix_set(ec_env%matrix_ks, nspins, 1)
1449 DO ispin = 1, nspins
1450 headline =
"KOHN-SHAM MATRIX"
1451 ALLOCATE (ec_env%matrix_ks(ispin, 1)%matrix)
1452 CALL dbcsr_create(ec_env%matrix_ks(ispin, 1)%matrix, name=trim(headline), &
1453 template=ec_env%matrix_s(1, 1)%matrix, matrix_type=dbcsr_type_symmetric)
1454 CALL cp_dbcsr_alloc_block_from_nbl(ec_env%matrix_ks(ispin, 1)%matrix, ec_env%sab_orb)
1455 CALL dbcsr_set(ec_env%matrix_ks(ispin, 1)%matrix, 0.0_dp)
1459 CALL get_qs_env(qs_env=qs_env, pw_env=pw_env)
1460 cpassert(
ASSOCIATED(pw_env))
1463 ec_section => section_vals_get_subs_vals(qs_env%input,
"DFT%ENERGY_CORRECTION")
1464 ec_hfx_sections => section_vals_get_subs_vals(ec_section,
"XC%HF")
1465 CALL section_vals_get(ec_hfx_sections, explicit=do_ec_hfx)
1470 adiabatic_rescaling_section => section_vals_get_subs_vals(ec_section,
"XC%ADIABATIC_RESCALING")
1471 CALL section_vals_get(adiabatic_rescaling_section, explicit=do_adiabatic_rescaling)
1472 IF (do_adiabatic_rescaling)
THEN
1473 CALL cp_abort(__location__,
"Adiabatic rescaling NYI for energy correction")
1475 CALL section_vals_val_get(ec_hfx_sections,
"TREAT_LSD_IN_CORE", l_val=hfx_treat_lsd_in_core)
1476 IF (hfx_treat_lsd_in_core)
THEN
1477 CALL cp_abort(__location__,
"HFX_TREAT_LSD_IN_CORE NYI for energy correction")
1481 IF (dft_control%do_admm)
THEN
1483 IF (dft_control%do_admm_mo)
THEN
1484 IF (qs_env%run_rtp)
THEN
1485 CALL rtp_admm_calc_rho_aux(qs_env)
1487 CALL admm_mo_calc_rho_aux(qs_env)
1489 ELSEIF (dft_control%do_admm_dm)
THEN
1490 CALL admm_dm_calc_rho_aux(qs_env)
1497 CALL get_qs_env(qs_env, energy=energy)
1498 CALL calculate_exx(qs_env=qs_env, &
1500 hfx_sections=ec_hfx_sections, &
1501 x_data=ec_env%x_data, &
1503 do_admm=ec_env%do_ec_admm, &
1504 calc_forces=.false., &
1505 reuse_hfx=ec_env%reuse_hfx, &
1506 do_im_time=.false., &
1507 e_ex_from_gw=dummy_real, &
1508 e_admm_from_gw=dummy_real2, &
1512 ec_env%ex = energy%ex
1514 IF (ec_env%do_ec_admm)
THEN
1515 ec_env%exc_aux_fit = energy%exc_aux_fit + energy%exc
1521 ks_mat => ec_env%matrix_ks(:, 1)
1522 CALL add_exx_to_rhs(rhs=ks_mat, &
1524 ext_hfx_section=ec_hfx_sections, &
1525 x_data=ec_env%x_data, &
1526 recalc_integrals=.false., &
1527 do_admm=ec_env%do_ec_admm, &
1530 reuse_hfx=ec_env%reuse_hfx)
1535 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
1536 NULLIFY (v_rspace, v_tau_rspace)
1537 CALL qs_vxc_create(ks_env=ks_env, rho_struct=rho, xc_section=ec_env%xc_section, &
1538 vxc_rho=v_rspace, vxc_tau=v_tau_rspace, exc=eexc, just_energy=.false.)
1540 IF (.NOT.
ASSOCIATED(v_rspace))
THEN
1541 ALLOCATE (v_rspace(nspins))
1542 DO ispin = 1, nspins
1543 CALL auxbas_pw_pool%create_pw(v_rspace(ispin))
1544 CALL pw_zero(v_rspace(ispin))
1549 CALL qs_rho_get(rho, rho_r=rho_r)
1550 IF (
ASSOCIATED(v_tau_rspace))
THEN
1551 CALL qs_rho_get(rho, tau_r=tau_r)
1553 DO ispin = 1, nspins
1555 CALL pw_scale(v_rspace(ispin), v_rspace(ispin)%pw_grid%dvol)
1556 CALL pw_axpy(ec_env%vh_rspace, v_rspace(ispin))
1558 CALL integrate_v_rspace(v_rspace=v_rspace(ispin), &
1559 hmat=ec_env%matrix_ks(ispin, 1), &
1561 calculate_forces=.false., &
1562 basis_type=
"HARRIS", &
1563 task_list_external=ec_env%task_list)
1565 IF (
ASSOCIATED(v_tau_rspace))
THEN
1567 CALL pw_scale(v_tau_rspace(ispin), v_tau_rspace(ispin)%pw_grid%dvol)
1568 CALL integrate_v_rspace(v_rspace=v_tau_rspace(ispin), &
1569 hmat=ec_env%matrix_ks(ispin, 1), &
1571 calculate_forces=.false., &
1572 compute_tau=.true., &
1573 basis_type=
"HARRIS", &
1574 task_list_external=ec_env%task_list)
1578 evhxc = evhxc + pw_integral_ab(rho_r(ispin), v_rspace(ispin))/ &
1579 v_rspace(1)%pw_grid%dvol
1580 IF (
ASSOCIATED(v_tau_rspace))
THEN
1581 evhxc = evhxc + pw_integral_ab(tau_r(ispin), v_tau_rspace(ispin))/ &
1582 v_tau_rspace(ispin)%pw_grid%dvol
1588 DO ispin = 1, nspins
1589 CALL auxbas_pw_pool%give_back_pw(v_rspace(ispin))
1590 IF (
ASSOCIATED(v_tau_rspace))
THEN
1591 CALL auxbas_pw_pool%give_back_pw(v_tau_rspace(ispin))
1594 DEALLOCATE (v_rspace)
1595 IF (
ASSOCIATED(v_tau_rspace))
DEALLOCATE (v_tau_rspace)
1602 DO ispin = 1, nspins
1603 CALL dbcsr_add(ec_env%matrix_ks(ispin, 1)%matrix, ec_env%matrix_h(1, 1)%matrix, &
1604 alpha_scalar=1.0_dp, beta_scalar=1.0_dp)
1605 CALL dbcsr_filter(ec_env%matrix_ks(ispin, 1)%matrix, &
1606 dft_control%qs_control%eps_filter_matrix)
1609 CALL timestop(handle)
1611 END SUBROUTINE ec_build_ks_matrix
1623 SUBROUTINE ec_build_core_hamiltonian_force(qs_env, ec_env, matrix_p, matrix_s, matrix_w)
1624 TYPE(qs_environment_type),
POINTER :: qs_env
1625 TYPE(energy_correction_type),
POINTER :: ec_env
1626 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_p, matrix_s, matrix_w
1628 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ec_build_core_hamiltonian_force'
1630 INTEGER :: handle, iounit, nder, nimages
1631 INTEGER,
DIMENSION(:, :, :),
POINTER :: cell_to_index
1632 LOGICAL :: calculate_forces, debug_forces, &
1633 debug_stress, use_virial
1634 REAL(kind=dp) :: eps_ppnl, fconv
1635 REAL(kind=dp),
DIMENSION(3) :: fodeb
1636 REAL(kind=dp),
DIMENSION(3, 3) :: stdeb, sttot
1637 TYPE(atomic_kind_type),
DIMENSION(:),
POINTER :: atomic_kind_set
1638 TYPE(cell_type),
POINTER :: cell
1639 TYPE(cp_logger_type),
POINTER :: logger
1640 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: scrm
1641 TYPE(dft_control_type),
POINTER :: dft_control
1642 TYPE(mp_para_env_type),
POINTER :: para_env
1643 TYPE(neighbor_list_set_p_type),
DIMENSION(:), &
1644 POINTER :: sab_orb, sac_ppl, sap_ppnl
1645 TYPE(particle_type),
DIMENSION(:),
POINTER :: particle_set
1646 TYPE(qs_force_type),
DIMENSION(:),
POINTER :: force
1647 TYPE(qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
1648 TYPE(qs_ks_env_type),
POINTER :: ks_env
1649 TYPE(virial_type),
POINTER :: virial
1651 CALL timeset(routinen, handle)
1653 debug_forces = ec_env%debug_forces
1654 debug_stress = ec_env%debug_stress
1656 logger => cp_get_default_logger()
1657 IF (logger%para_env%is_source())
THEN
1658 iounit = cp_logger_get_default_unit_nr(logger, local=.true.)
1663 calculate_forces = .true.
1666 NULLIFY (cell, dft_control, force, ks_env, para_env, virial)
1667 CALL get_qs_env(qs_env=qs_env, &
1669 dft_control=dft_control, &
1672 para_env=para_env, &
1674 nimages = dft_control%nimages
1675 IF (nimages /= 1)
THEN
1676 cpabort(
"K-points for Harris functional not implemented")
1680 use_virial = virial%pv_availability .AND. (.NOT. virial%pv_numer)
1682 fconv = 1.0e-9_dp*pascal/cell%deth
1683 IF (debug_stress .AND. use_virial)
THEN
1684 sttot = virial%pv_virial
1688 IF (dft_control%qs_control%gapw .OR. dft_control%qs_control%gapw_xc)
THEN
1689 cpabort(
"Harris functional for GAPW not implemented")
1693 NULLIFY (sab_orb, sac_ppl, sap_ppnl)
1694 sab_orb => ec_env%sab_orb
1695 sac_ppl => ec_env%sac_ppl
1696 sap_ppnl => ec_env%sap_ppnl
1700 CALL dbcsr_allocate_matrix_set(scrm, 1, 1)
1701 ALLOCATE (scrm(1, 1)%matrix)
1702 CALL dbcsr_create(scrm(1, 1)%matrix, template=matrix_s(1, 1)%matrix)
1703 CALL cp_dbcsr_alloc_block_from_nbl(scrm(1, 1)%matrix, sab_orb)
1706 IF (
SIZE(matrix_p, 1) == 2)
THEN
1707 CALL dbcsr_add(matrix_p(1, 1)%matrix, matrix_p(2, 1)%matrix, &
1708 alpha_scalar=1.0_dp, beta_scalar=1.0_dp)
1709 CALL dbcsr_add(matrix_w(1, 1)%matrix, matrix_w(2, 1)%matrix, &
1710 alpha_scalar=1.0_dp, beta_scalar=1.0_dp)
1714 IF (debug_forces) fodeb(1:3) = force(1)%overlap(1:3, 1)
1715 IF (debug_stress .AND. use_virial) stdeb = virial%pv_overlap
1716 CALL build_overlap_matrix(ks_env, matrixkp_s=scrm, &
1717 matrix_name=
"OVERLAP MATRIX", &
1718 basis_type_a=
"HARRIS", &
1719 basis_type_b=
"HARRIS", &
1720 sab_nl=sab_orb, calculate_forces=.true., &
1721 matrixkp_p=matrix_w)
1723 IF (debug_forces)
THEN
1724 fodeb(1:3) = force(1)%overlap(1:3, 1) - fodeb(1:3)
1725 CALL para_env%sum(fodeb)
1726 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Wout*dS ", fodeb
1727 fodeb(1:3) = force(1)%kinetic(1:3, 1)
1729 IF (debug_stress .AND. use_virial)
THEN
1730 stdeb = fconv*(virial%pv_overlap - stdeb)
1731 CALL para_env%sum(stdeb)
1732 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1733 'STRESS| Wout*dS', one_third_sum_diag(stdeb), det_3x3(stdeb)
1734 stdeb = virial%pv_ekinetic
1736 CALL build_kinetic_matrix(ks_env, matrixkp_t=scrm, &
1737 matrix_name=
"KINETIC ENERGY MATRIX", &
1738 basis_type=
"HARRIS", &
1739 sab_nl=sab_orb, calculate_forces=.true., &
1740 matrixkp_p=matrix_p)
1741 IF (debug_forces)
THEN
1742 fodeb(1:3) = force(1)%kinetic(1:3, 1) - fodeb(1:3)
1743 CALL para_env%sum(fodeb)
1744 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Pout*dT ", fodeb
1746 IF (debug_stress .AND. use_virial)
THEN
1747 stdeb = fconv*(virial%pv_ekinetic - stdeb)
1748 CALL para_env%sum(stdeb)
1749 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1750 'STRESS| Pout*dT', one_third_sum_diag(stdeb), det_3x3(stdeb)
1752 IF (
SIZE(matrix_p, 1) == 2)
THEN
1753 CALL dbcsr_add(matrix_p(1, 1)%matrix, matrix_p(2, 1)%matrix, &
1754 alpha_scalar=1.0_dp, beta_scalar=-1.0_dp)
1758 NULLIFY (atomic_kind_set, particle_set, qs_kind_set)
1759 CALL get_qs_env(qs_env=qs_env, qs_kind_set=qs_kind_set, particle_set=particle_set, &
1760 atomic_kind_set=atomic_kind_set)
1762 IF (
ASSOCIATED(sac_ppl))
THEN
1763 IF (calculate_forces .AND. debug_forces) fodeb(1:3) = force(1)%gth_ppl(1:3, 1)
1764 IF (debug_stress .AND. use_virial) stdeb = virial%pv_ppl
1765 CALL build_core_ppl(scrm, matrix_p, force, &
1766 virial, calculate_forces, use_virial, nder, &
1767 qs_kind_set, atomic_kind_set, particle_set, sab_orb, sac_ppl, &
1768 nimages, cell_to_index,
"HARRIS")
1769 IF (calculate_forces .AND. debug_forces)
THEN
1770 fodeb(1:3) = force(1)%gth_ppl(1:3, 1) - fodeb(1:3)
1771 CALL para_env%sum(fodeb)
1772 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Pout*dH_PPL ", fodeb
1774 IF (debug_stress .AND. use_virial)
THEN
1775 stdeb = fconv*(virial%pv_ppl - stdeb)
1776 CALL para_env%sum(stdeb)
1777 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1778 'STRESS| Pout*dH_PPL', one_third_sum_diag(stdeb), det_3x3(stdeb)
1783 eps_ppnl = dft_control%qs_control%eps_ppnl
1784 IF (
ASSOCIATED(sap_ppnl))
THEN
1785 IF (calculate_forces .AND. debug_forces) fodeb(1:3) = force(1)%gth_ppnl(1:3, 1)
1786 IF (debug_stress .AND. use_virial) stdeb = virial%pv_ppnl
1787 CALL build_core_ppnl(scrm, matrix_p, force, &
1788 virial, calculate_forces, use_virial, nder, &
1789 qs_kind_set, atomic_kind_set, particle_set, &
1790 sab_orb, sap_ppnl, eps_ppnl, &
1791 nimages, cell_to_index,
"HARRIS")
1792 IF (calculate_forces .AND. debug_forces)
THEN
1793 fodeb(1:3) = force(1)%gth_ppnl(1:3, 1) - fodeb(1:3)
1794 CALL para_env%sum(fodeb)
1795 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Pout*dH_PPNL", fodeb
1797 IF (debug_stress .AND. use_virial)
THEN
1798 stdeb = fconv*(virial%pv_ppnl - stdeb)
1799 CALL para_env%sum(stdeb)
1800 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1801 'STRESS| Pout*dH_PPNL', one_third_sum_diag(stdeb), det_3x3(stdeb)
1806 ec_env%efield_nuclear = 0.0_dp
1807 IF (calculate_forces .AND. debug_forces) fodeb(1:3) = force(1)%efield(1:3, 1)
1808 CALL ec_efield_local_operator(qs_env, ec_env, calculate_forces)
1809 IF (calculate_forces .AND. debug_forces)
THEN
1810 fodeb(1:3) = force(1)%efield(1:3, 1) - fodeb(1:3)
1811 CALL para_env%sum(fodeb)
1812 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Pout*dEfield", fodeb
1814 IF (debug_stress .AND. use_virial)
THEN
1815 stdeb = fconv*(virial%pv_virial - sttot)
1816 CALL para_env%sum(stdeb)
1817 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1818 'STRESS| Stress Pout*dHcore ', one_third_sum_diag(stdeb), det_3x3(stdeb)
1819 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))")
' '
1823 CALL dbcsr_deallocate_matrix_set(scrm)
1825 CALL timestop(handle)
1827 END SUBROUTINE ec_build_core_hamiltonian_force
1838 SUBROUTINE ec_build_ks_matrix_force(qs_env, ec_env)
1839 TYPE(qs_environment_type),
POINTER :: qs_env
1840 TYPE(energy_correction_type),
POINTER :: ec_env
1842 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ec_build_ks_matrix_force'
1844 CHARACTER(LEN=default_string_length) :: unit_string
1845 INTEGER :: handle, i, iounit, ispin, natom, nspins
1846 LOGICAL :: debug_forces, debug_stress, do_ec_hfx, &
1848 REAL(dp) :: dehartree, dummy_real, dummy_real2(2), &
1849 eexc, ehartree, eovrl, exc, fconv
1850 REAL(dp),
ALLOCATABLE,
DIMENSION(:, :) :: ftot
1851 REAL(dp),
DIMENSION(3) :: fodeb
1852 REAL(kind=dp),
DIMENSION(3, 3) :: h_stress, pv_loc, stdeb, sttot
1853 TYPE(atomic_kind_type),
DIMENSION(:),
POINTER :: atomic_kind_set
1854 TYPE(cell_type),
POINTER :: cell
1855 TYPE(cp_logger_type),
POINTER :: logger
1856 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_ks, scrm
1857 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_p, matrix_s
1858 TYPE(dft_control_type),
POINTER :: dft_control
1859 TYPE(mp_para_env_type),
POINTER :: para_env
1860 TYPE(neighbor_list_set_p_type),
DIMENSION(:), &
1862 TYPE(pw_c1d_gs_type) :: rho_tot_gspace, rhodn_tot_gspace, &
1864 TYPE(pw_c1d_gs_type),
DIMENSION(:),
POINTER :: rho_g, rhoout_g
1865 TYPE(pw_c1d_gs_type),
POINTER :: rho_core
1866 TYPE(pw_env_type),
POINTER :: pw_env
1867 TYPE(pw_poisson_type),
POINTER :: poisson_env
1868 TYPE(pw_pool_type),
POINTER :: auxbas_pw_pool
1869 TYPE(pw_r3d_rs_type) :: dv_hartree_rspace, v_hartree_rspace, &
1871 TYPE(pw_r3d_rs_type),
DIMENSION(:),
POINTER :: rho_r, rhoout_r, tau_r, tauout_r, &
1872 v_rspace, v_tau_rspace, v_xc, v_xc_tau
1873 TYPE(qs_force_type),
DIMENSION(:),
POINTER :: force
1874 TYPE(qs_ks_env_type),
POINTER :: ks_env
1875 TYPE(qs_rho_type),
POINTER :: rho
1876 TYPE(section_vals_type),
POINTER :: ec_hfx_sections, xc_section
1877 TYPE(virial_type),
POINTER :: virial
1879 CALL timeset(routinen, handle)
1881 debug_forces = ec_env%debug_forces
1882 debug_stress = ec_env%debug_stress
1884 logger => cp_get_default_logger()
1885 IF (logger%para_env%is_source())
THEN
1886 iounit = cp_logger_get_default_unit_nr(logger, local=.true.)
1892 NULLIFY (atomic_kind_set, cell, dft_control, force, ks_env, &
1893 matrix_ks, matrix_p, matrix_s, para_env, rho, rho_core, &
1894 rho_g, rho_r, sab_orb, tau_r, virial)
1895 CALL get_qs_env(qs_env=qs_env, &
1897 dft_control=dft_control, &
1900 matrix_ks=matrix_ks, &
1901 para_env=para_env, &
1906 nspins = dft_control%nspins
1907 use_virial = virial%pv_availability .AND. (.NOT. virial%pv_numer)
1911 fconv = cp_unit_from_cp2k(1.0_dp/cell%deth, trim(unit_string))
1913 IF (debug_stress .AND. use_virial)
THEN
1914 sttot = virial%pv_virial
1918 CALL get_qs_env(qs_env=qs_env, pw_env=pw_env)
1919 cpassert(
ASSOCIATED(pw_env))
1921 NULLIFY (auxbas_pw_pool, poisson_env)
1923 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool, &
1924 poisson_env=poisson_env)
1927 CALL auxbas_pw_pool%create_pw(v_hartree_gspace)
1928 CALL auxbas_pw_pool%create_pw(rhodn_tot_gspace)
1929 CALL auxbas_pw_pool%create_pw(v_hartree_rspace)
1931 CALL pw_transfer(ec_env%vh_rspace, v_hartree_rspace)
1936 CALL qs_rho_get(rho, rho_r=rho_r, rho_g=rho_g, tau_r=tau_r)
1937 NULLIFY (rhoout_r, rhoout_g)
1938 ALLOCATE (rhoout_r(nspins), rhoout_g(nspins))
1939 DO ispin = 1, nspins
1940 CALL auxbas_pw_pool%create_pw(rhoout_r(ispin))
1941 CALL auxbas_pw_pool%create_pw(rhoout_g(ispin))
1943 CALL auxbas_pw_pool%create_pw(dv_hartree_rspace)
1944 CALL auxbas_pw_pool%create_pw(vtot_rspace)
1946 CALL pw_zero(rhodn_tot_gspace)
1947 DO ispin = 1, nspins
1948 CALL calculate_rho_elec(ks_env=ks_env, matrix_p=ec_env%matrix_p(ispin, 1)%matrix, &
1949 rho=rhoout_r(ispin), &
1950 rho_gspace=rhoout_g(ispin), &
1951 basis_type=
"HARRIS", &
1952 task_list_external=ec_env%task_list)
1956 ALLOCATE (ec_env%rhoout_r(nspins))
1957 DO ispin = 1, nspins
1958 CALL auxbas_pw_pool%create_pw(ec_env%rhoout_r(ispin))
1959 CALL pw_copy(rhoout_r(ispin), ec_env%rhoout_r(ispin))
1963 IF (dft_control%use_kinetic_energy_density)
THEN
1965 TYPE(pw_c1d_gs_type) :: tauout_g
1966 ALLOCATE (tauout_r(nspins))
1967 DO ispin = 1, nspins
1968 CALL auxbas_pw_pool%create_pw(tauout_r(ispin))
1970 CALL auxbas_pw_pool%create_pw(tauout_g)
1972 DO ispin = 1, nspins
1973 CALL calculate_rho_elec(ks_env=ks_env, matrix_p=ec_env%matrix_p(ispin, 1)%matrix, &
1974 rho=tauout_r(ispin), &
1975 rho_gspace=tauout_g, &
1976 compute_tau=.true., &
1977 basis_type=
"HARRIS", &
1978 task_list_external=ec_env%task_list)
1981 CALL auxbas_pw_pool%give_back_pw(tauout_g)
1985 IF (use_virial)
THEN
1988 CALL auxbas_pw_pool%create_pw(rho_tot_gspace)
1991 CALL calc_rho_tot_gspace(rho_tot_gspace, qs_env, rho)
1994 CALL get_qs_env(qs_env=qs_env, rho_core=rho_core)
1995 CALL pw_copy(rho_core, rhodn_tot_gspace)
1996 DO ispin = 1, dft_control%nspins
1997 CALL pw_axpy(rhoout_g(ispin), rhodn_tot_gspace)
2001 h_stress(:, :) = 0.0_dp
2002 CALL pw_poisson_solve(poisson_env, &
2003 density=rho_tot_gspace, &
2004 ehartree=ehartree, &
2005 vhartree=v_hartree_gspace, &
2006 h_stress=h_stress, &
2007 aux_density=rhodn_tot_gspace)
2009 virial%pv_ehartree = virial%pv_ehartree + h_stress/real(para_env%num_pe, dp)
2010 virial%pv_virial = virial%pv_virial + h_stress/real(para_env%num_pe, dp)
2012 IF (debug_stress)
THEN
2013 stdeb = fconv*(h_stress/real(para_env%num_pe, dp))
2014 CALL para_env%sum(stdeb)
2015 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2016 'STRESS| GREEN 1st v_H[n_in]*n_out ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2020 virial%pv_calculate = .true.
2022 NULLIFY (v_rspace, v_tau_rspace)
2023 CALL qs_vxc_create(ks_env=ks_env, rho_struct=rho, xc_section=ec_env%xc_section, &
2024 vxc_rho=v_rspace, vxc_tau=v_tau_rspace, exc=exc, just_energy=.false.)
2027 virial%pv_exc = virial%pv_exc - virial%pv_xc
2028 virial%pv_virial = virial%pv_virial - virial%pv_xc
2030 IF (debug_stress)
THEN
2031 stdeb = -1.0_dp*fconv*virial%pv_xc
2032 CALL para_env%sum(stdeb)
2033 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2034 'STRESS| GGA 1st E_xc[Pin] ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2037 IF (
ASSOCIATED(v_rspace))
THEN
2038 DO ispin = 1, nspins
2039 CALL auxbas_pw_pool%give_back_pw(v_rspace(ispin))
2041 DEALLOCATE (v_rspace)
2043 IF (
ASSOCIATED(v_tau_rspace))
THEN
2044 DO ispin = 1, nspins
2045 CALL auxbas_pw_pool%give_back_pw(v_tau_rspace(ispin))
2047 DEALLOCATE (v_tau_rspace)
2049 CALL pw_zero(rhodn_tot_gspace)
2054 DO ispin = 1, nspins
2055 CALL pw_axpy(rho_r(ispin), rhoout_r(ispin), -1.0_dp)
2056 CALL pw_axpy(rho_g(ispin), rhoout_g(ispin), -1.0_dp)
2057 CALL pw_axpy(rhoout_g(ispin), rhodn_tot_gspace)
2058 IF (dft_control%use_kinetic_energy_density)
CALL pw_axpy(tau_r(ispin), tauout_r(ispin), -1.0_dp)
2062 IF (use_virial)
THEN
2065 h_stress(:, :) = 0.0_dp
2066 CALL pw_poisson_solve(poisson_env, &
2067 density=rhodn_tot_gspace, &
2068 ehartree=dehartree, &
2069 vhartree=v_hartree_gspace, &
2070 h_stress=h_stress, &
2071 aux_density=rho_tot_gspace)
2073 CALL auxbas_pw_pool%give_back_pw(rho_tot_gspace)
2075 virial%pv_ehartree = virial%pv_ehartree + h_stress/real(para_env%num_pe, dp)
2076 virial%pv_virial = virial%pv_virial + h_stress/real(para_env%num_pe, dp)
2078 IF (debug_stress)
THEN
2079 stdeb = fconv*(h_stress/real(para_env%num_pe, dp))
2080 CALL para_env%sum(stdeb)
2081 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2082 'STRESS| GREEN 2nd V_H[dP]*n_in ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2087 CALL pw_poisson_solve(poisson_env, rhodn_tot_gspace, dehartree, &
2091 CALL pw_transfer(v_hartree_gspace, dv_hartree_rspace)
2092 CALL pw_scale(dv_hartree_rspace, dv_hartree_rspace%pw_grid%dvol)
2095 CALL pw_transfer(v_hartree_rspace, vtot_rspace)
2096 CALL pw_axpy(dv_hartree_rspace, vtot_rspace)
2097 IF (debug_forces) fodeb(1:3) = force(1)%rho_core(1:3, 1)
2098 IF (debug_stress .AND. use_virial) stdeb = virial%pv_ehartree
2099 CALL integrate_v_core_rspace(vtot_rspace, qs_env)
2100 IF (debug_forces)
THEN
2101 fodeb(1:3) = force(1)%rho_core(1:3, 1) - fodeb(1:3)
2102 CALL para_env%sum(fodeb)
2103 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Vtot*dncore", fodeb
2105 IF (debug_stress .AND. use_virial)
THEN
2106 stdeb = fconv*(virial%pv_ehartree - stdeb)
2107 CALL para_env%sum(stdeb)
2108 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2109 'STRESS| Vtot*dncore', one_third_sum_diag(stdeb), det_3x3(stdeb)
2115 xc_section => ec_env%xc_section
2117 IF (use_virial) virial%pv_xc = 0.0_dp
2118 NULLIFY (v_xc, v_xc_tau)
2119 CALL create_kernel(qs_env, &
2126 xc_section=xc_section, &
2127 compute_virial=use_virial, &
2128 virial_xc=virial%pv_xc)
2130 IF (use_virial)
THEN
2132 virial%pv_exc = virial%pv_exc + virial%pv_xc
2133 virial%pv_virial = virial%pv_virial + virial%pv_xc
2135 IF (debug_stress .AND. use_virial)
THEN
2136 stdeb = 1.0_dp*fconv*virial%pv_xc
2137 CALL para_env%sum(stdeb)
2138 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2139 'STRESS| GGA 2nd f_Hxc[dP]*Pin ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2142 CALL get_qs_env(qs_env=qs_env, rho=rho, matrix_s_kp=matrix_s)
2143 NULLIFY (ec_env%matrix_hz)
2144 CALL dbcsr_allocate_matrix_set(ec_env%matrix_hz, nspins)
2145 DO ispin = 1, nspins
2146 ALLOCATE (ec_env%matrix_hz(ispin)%matrix)
2147 CALL dbcsr_create(ec_env%matrix_hz(ispin)%matrix, template=matrix_s(1, 1)%matrix)
2148 CALL dbcsr_copy(ec_env%matrix_hz(ispin)%matrix, matrix_s(1, 1)%matrix)
2149 CALL dbcsr_set(ec_env%matrix_hz(ispin)%matrix, 0.0_dp)
2151 CALL qs_rho_get(rho, rho_ao_kp=matrix_p)
2153 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
2154 IF (debug_stress .AND. use_virial) stdeb = virial%pv_virial
2157 IF (use_virial)
THEN
2158 pv_loc = virial%pv_virial
2161 DO ispin = 1, nspins
2162 CALL pw_scale(v_xc(ispin), v_xc(ispin)%pw_grid%dvol)
2163 CALL pw_axpy(dv_hartree_rspace, v_xc(ispin))
2164 CALL integrate_v_rspace(v_rspace=v_xc(ispin), &
2165 hmat=ec_env%matrix_hz(ispin), &
2166 pmat=matrix_p(ispin, 1), &
2168 calculate_forces=.true.)
2171 IF (debug_forces)
THEN
2172 fodeb(1:3) = force(1)%rho_elec(1:3, 1) - fodeb(1:3)
2173 CALL para_env%sum(fodeb)
2174 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Pin*dKdrho", fodeb
2176 IF (debug_stress .AND. use_virial)
THEN
2177 stdeb = fconv*(virial%pv_virial - stdeb)
2178 CALL para_env%sum(stdeb)
2179 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2180 'STRESS| INT 2nd f_Hxc[dP]*Pin ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2183 IF (
ASSOCIATED(v_xc_tau))
THEN
2184 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
2185 IF (debug_stress .AND. use_virial) stdeb = virial%pv_virial
2187 DO ispin = 1, nspins
2188 CALL pw_scale(v_xc_tau(ispin), v_xc_tau(ispin)%pw_grid%dvol)
2189 CALL integrate_v_rspace(v_rspace=v_xc_tau(ispin), &
2190 hmat=ec_env%matrix_hz(ispin), &
2191 pmat=matrix_p(ispin, 1), &
2193 compute_tau=.true., &
2194 calculate_forces=.true.)
2197 IF (debug_forces)
THEN
2198 fodeb(1:3) = force(1)%rho_elec(1:3, 1) - fodeb(1:3)
2199 CALL para_env%sum(fodeb)
2200 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Pin*dKtaudtau", fodeb
2202 IF (debug_stress .AND. use_virial)
THEN
2203 stdeb = fconv*(virial%pv_virial - stdeb)
2204 CALL para_env%sum(stdeb)
2205 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2206 'STRESS| INT 2nd f_xctau[dP]*Pin ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2210 IF (use_virial)
THEN
2211 virial%pv_ehartree = virial%pv_ehartree + (virial%pv_virial - pv_loc)
2216 CALL dbcsr_allocate_matrix_set(scrm, nspins)
2217 DO ispin = 1, nspins
2218 ALLOCATE (scrm(ispin)%matrix)
2219 CALL dbcsr_create(scrm(ispin)%matrix, template=ec_env%matrix_ks(ispin, 1)%matrix)
2220 CALL dbcsr_copy(scrm(ispin)%matrix, ec_env%matrix_ks(ispin, 1)%matrix)
2221 CALL dbcsr_set(scrm(ispin)%matrix, 0.0_dp)
2225 NULLIFY (v_rspace, v_tau_rspace)
2227 CALL qs_vxc_create(ks_env=ks_env, rho_struct=rho, xc_section=ec_env%xc_section, &
2228 vxc_rho=v_rspace, vxc_tau=v_tau_rspace, exc=eexc, just_energy=.false.)
2230 IF (use_virial)
THEN
2232 IF (
ASSOCIATED(v_rspace))
THEN
2233 DO ispin = 1, nspins
2235 eexc = eexc + pw_integral_ab(rhoout_r(ispin), v_rspace(ispin))
2238 IF (
ASSOCIATED(v_tau_rspace))
THEN
2239 DO ispin = 1, nspins
2241 eexc = eexc + pw_integral_ab(tauout_r(ispin), v_tau_rspace(ispin))
2246 IF (.NOT.
ASSOCIATED(v_rspace))
THEN
2247 ALLOCATE (v_rspace(nspins))
2248 DO ispin = 1, nspins
2249 CALL auxbas_pw_pool%create_pw(v_rspace(ispin))
2250 CALL pw_zero(v_rspace(ispin))
2256 IF (use_virial)
THEN
2257 pv_loc = virial%pv_virial
2260 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
2261 IF (debug_stress .AND. use_virial) stdeb = virial%pv_virial
2262 DO ispin = 1, nspins
2264 CALL pw_scale(v_rspace(ispin), v_rspace(ispin)%pw_grid%dvol)
2265 CALL pw_axpy(v_hartree_rspace, v_rspace(ispin))
2267 CALL integrate_v_rspace(v_rspace=v_rspace(ispin), &
2269 pmat=ec_env%matrix_p(ispin, 1), &
2271 calculate_forces=.true., &
2272 basis_type=
"HARRIS", &
2273 task_list_external=ec_env%task_list)
2276 IF (debug_forces)
THEN
2277 fodeb(1:3) = force(1)%rho_elec(1:3, 1) - fodeb(1:3)
2278 CALL para_env%sum(fodeb)
2279 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Pout*dVhxc ", fodeb
2281 IF (debug_stress .AND. use_virial)
THEN
2282 stdeb = fconv*(virial%pv_virial - stdeb)
2283 CALL para_env%sum(stdeb)
2284 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2285 'STRESS| INT Pout*dVhxc ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2289 IF (use_virial)
THEN
2290 virial%pv_ehartree = virial%pv_ehartree + (virial%pv_virial - pv_loc)
2293 IF (
ASSOCIATED(v_tau_rspace))
THEN
2294 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
2295 DO ispin = 1, nspins
2297 CALL pw_scale(v_tau_rspace(ispin), v_tau_rspace(ispin)%pw_grid%dvol)
2298 CALL integrate_v_rspace(v_rspace=v_tau_rspace(ispin), &
2300 pmat=ec_env%matrix_p(ispin, 1), &
2302 calculate_forces=.true., &
2303 compute_tau=.true., &
2304 basis_type=
"HARRIS", &
2305 task_list_external=ec_env%task_list)
2307 IF (debug_forces)
THEN
2308 fodeb(1:3) = force(1)%rho_elec(1:3, 1) - fodeb(1:3)
2309 CALL para_env%sum(fodeb)
2310 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Pout*dVhxc_tau ", fodeb
2319 ec_hfx_sections => section_vals_get_subs_vals(qs_env%input,
"DFT%ENERGY_CORRECTION%XC%HF")
2320 CALL section_vals_get(ec_hfx_sections, explicit=do_ec_hfx)
2324 IF (debug_forces) fodeb(1:3) = force(1)%fock_4c(1:3, 1)
2325 IF (use_virial) virial%pv_fock_4c = 0.0_dp
2327 CALL calculate_exx(qs_env=qs_env, &
2329 hfx_sections=ec_hfx_sections, &
2330 x_data=ec_env%x_data, &
2332 do_admm=ec_env%do_ec_admm, &
2333 calc_forces=.true., &
2334 reuse_hfx=ec_env%reuse_hfx, &
2335 do_im_time=.false., &
2336 e_ex_from_gw=dummy_real, &
2337 e_admm_from_gw=dummy_real2, &
2340 IF (use_virial)
THEN
2341 virial%pv_exx = virial%pv_exx - virial%pv_fock_4c
2342 virial%pv_virial = virial%pv_virial - virial%pv_fock_4c
2343 virial%pv_calculate = .false.
2345 IF (debug_forces)
THEN
2346 fodeb(1:3) = force(1)%fock_4c(1:3, 1) - fodeb(1:3)
2347 CALL para_env%sum(fodeb)
2348 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Pout*hfx ", fodeb
2350 IF (debug_stress .AND. use_virial)
THEN
2351 stdeb = -1.0_dp*fconv*virial%pv_fock_4c
2352 CALL para_env%sum(stdeb)
2353 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2354 'STRESS| Pout*hfx ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2362 CALL dbcsr_deallocate_matrix_set(scrm)
2365 CALL auxbas_pw_pool%give_back_pw(v_hartree_rspace)
2366 DO ispin = 1, nspins
2367 CALL auxbas_pw_pool%give_back_pw(v_rspace(ispin))
2368 IF (
ASSOCIATED(v_tau_rspace))
THEN
2369 CALL auxbas_pw_pool%give_back_pw(v_tau_rspace(ispin))
2372 IF (
ASSOCIATED(v_tau_rspace))
DEALLOCATE (v_tau_rspace)
2375 IF (debug_forces) fodeb(1:3) = force(1)%core_overlap(1:3, 1)
2376 IF (debug_stress .AND. use_virial) stdeb = virial%pv_ecore_overlap
2377 CALL calculate_ecore_overlap(qs_env, para_env, .true., e_overlap_core=eovrl)
2378 IF (debug_forces)
THEN
2379 fodeb(1:3) = force(1)%core_overlap(1:3, 1) - fodeb(1:3)
2380 CALL para_env%sum(fodeb)
2381 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: CoreOverlap", fodeb
2383 IF (debug_stress .AND. use_virial)
THEN
2384 stdeb = fconv*(stdeb - virial%pv_ecore_overlap)
2385 CALL para_env%sum(stdeb)
2386 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2387 'STRESS| CoreOverlap ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2390 IF (debug_forces)
THEN
2391 CALL get_qs_env(qs_env, natom=natom, atomic_kind_set=atomic_kind_set)
2392 ALLOCATE (ftot(3, natom))
2393 CALL total_qs_force(ftot, force, atomic_kind_set)
2394 fodeb(1:3) = ftot(1:3, 1)
2396 CALL para_env%sum(fodeb)
2397 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Force Explicit", fodeb
2400 DEALLOCATE (v_rspace)
2402 CALL auxbas_pw_pool%give_back_pw(dv_hartree_rspace)
2403 CALL auxbas_pw_pool%give_back_pw(vtot_rspace)
2404 DO ispin = 1, nspins
2405 CALL auxbas_pw_pool%give_back_pw(rhoout_r(ispin))
2406 CALL auxbas_pw_pool%give_back_pw(rhoout_g(ispin))
2407 CALL auxbas_pw_pool%give_back_pw(v_xc(ispin))
2409 DEALLOCATE (rhoout_r, rhoout_g, v_xc)
2410 IF (
ASSOCIATED(tauout_r))
THEN
2411 DO ispin = 1, nspins
2412 CALL auxbas_pw_pool%give_back_pw(tauout_r(ispin))
2414 DEALLOCATE (tauout_r)
2416 IF (
ASSOCIATED(v_xc_tau))
THEN
2417 DO ispin = 1, nspins
2418 CALL auxbas_pw_pool%give_back_pw(v_xc_tau(ispin))
2420 DEALLOCATE (v_xc_tau)
2422 CALL auxbas_pw_pool%give_back_pw(v_hartree_gspace)
2423 CALL auxbas_pw_pool%give_back_pw(rhodn_tot_gspace)
2427 IF (use_virial)
THEN
2428 IF (qs_env%energy_correction)
THEN
2429 ec_env%ehartree = ehartree + dehartree
2430 ec_env%exc = exc + eexc
2434 IF (debug_stress .AND. use_virial)
THEN
2436 stdeb = -1.0_dp*fconv*ehartree
2437 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2438 'STRESS| VOL 1st v_H[n_in]*n_out', one_third_sum_diag(stdeb), det_3x3(stdeb)
2440 stdeb = -1.0_dp*fconv*exc
2441 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2442 'STRESS| VOL 1st E_XC[n_in]', one_third_sum_diag(stdeb), det_3x3(stdeb)
2444 stdeb = -1.0_dp*fconv*dehartree
2445 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2446 'STRESS| VOL 2nd v_H[dP]*n_in', one_third_sum_diag(stdeb), det_3x3(stdeb)
2448 stdeb = -1.0_dp*fconv*eexc
2449 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2450 'STRESS| VOL 2nd v_XC[n_in]*dP', one_third_sum_diag(stdeb), det_3x3(stdeb)
2455 TYPE(virial_type) :: virdeb
2458 CALL para_env%sum(virdeb%pv_overlap)
2459 CALL para_env%sum(virdeb%pv_ekinetic)
2460 CALL para_env%sum(virdeb%pv_ppl)
2461 CALL para_env%sum(virdeb%pv_ppnl)
2462 CALL para_env%sum(virdeb%pv_ecore_overlap)
2463 CALL para_env%sum(virdeb%pv_ehartree)
2464 CALL para_env%sum(virdeb%pv_exc)
2465 CALL para_env%sum(virdeb%pv_exx)
2466 CALL para_env%sum(virdeb%pv_vdw)
2467 CALL para_env%sum(virdeb%pv_mp2)
2468 CALL para_env%sum(virdeb%pv_nlcc)
2469 CALL para_env%sum(virdeb%pv_gapw)
2470 CALL para_env%sum(virdeb%pv_lrigpw)
2471 CALL para_env%sum(virdeb%pv_virial)
2472 CALL symmetrize_virial(virdeb)
2476 virdeb%pv_ehartree(i, i) = virdeb%pv_ehartree(i, i) - 2.0_dp*(ehartree + dehartree)
2477 virdeb%pv_virial(i, i) = virdeb%pv_virial(i, i) - exc - eexc &
2478 - 2.0_dp*(ehartree + dehartree)
2479 virdeb%pv_exc(i, i) = virdeb%pv_exc(i, i) - exc - eexc
2485 CALL para_env%sum(sttot)
2486 stdeb = fconv*(virdeb%pv_virial - sttot)
2487 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2488 'STRESS| Explicit electronic stress ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2490 stdeb = fconv*(virdeb%pv_virial)
2491 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2492 'STRESS| Explicit total stress ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2494 CALL write_stress_tensor_components(virdeb, iounit, cell, unit_string)
2495 CALL write_stress_tensor(virdeb%pv_virial, iounit, cell, unit_string, .false.)
2500 CALL timestop(handle)
2502 END SUBROUTINE ec_build_ks_matrix_force
2512 SUBROUTINE ec_ks_solver(qs_env, ec_env)
2514 TYPE(qs_environment_type),
POINTER :: qs_env
2515 TYPE(energy_correction_type),
POINTER :: ec_env
2517 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ec_ks_solver'
2519 CHARACTER(LEN=default_string_length) :: headline
2520 INTEGER :: handle, ispin, nspins
2521 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: ksmat, pmat, smat, wmat
2522 TYPE(dft_control_type),
POINTER :: dft_control
2524 CALL timeset(routinen, handle)
2526 CALL get_qs_env(qs_env=qs_env, dft_control=dft_control)
2527 nspins = dft_control%nspins
2530 IF (.NOT.
ASSOCIATED(ec_env%matrix_p))
THEN
2531 headline =
"DENSITY MATRIX"
2532 CALL dbcsr_allocate_matrix_set(ec_env%matrix_p, nspins, 1)
2533 DO ispin = 1, nspins
2534 ALLOCATE (ec_env%matrix_p(ispin, 1)%matrix)
2535 CALL dbcsr_create(ec_env%matrix_p(ispin, 1)%matrix, name=trim(headline), &
2536 template=ec_env%matrix_s(1, 1)%matrix)
2537 CALL cp_dbcsr_alloc_block_from_nbl(ec_env%matrix_p(ispin, 1)%matrix, ec_env%sab_orb)
2541 IF (.NOT.
ASSOCIATED(ec_env%matrix_w))
THEN
2542 headline =
"ENERGY WEIGHTED DENSITY MATRIX"
2543 CALL dbcsr_allocate_matrix_set(ec_env%matrix_w, nspins, 1)
2544 DO ispin = 1, nspins
2545 ALLOCATE (ec_env%matrix_w(ispin, 1)%matrix)
2546 CALL dbcsr_create(ec_env%matrix_w(ispin, 1)%matrix, name=trim(headline), &
2547 template=ec_env%matrix_s(1, 1)%matrix)
2548 CALL cp_dbcsr_alloc_block_from_nbl(ec_env%matrix_w(ispin, 1)%matrix, ec_env%sab_orb)
2552 IF (ec_env%mao)
THEN
2553 CALL mao_create_matrices(ec_env, ksmat, smat, pmat, wmat)
2555 ksmat => ec_env%matrix_ks
2556 smat => ec_env%matrix_s
2557 pmat => ec_env%matrix_p
2558 wmat => ec_env%matrix_w
2561 SELECT CASE (ec_env%ks_solver)
2562 CASE (ec_diagonalization)
2563 CALL ec_diag_solver(qs_env, ksmat, smat, pmat, wmat)
2565 CALL ec_ot_diag_solver(qs_env, ec_env, ksmat, smat, pmat, wmat)
2566 CASE (ec_matrix_sign, ec_matrix_trs4, ec_matrix_tc2)
2567 CALL ec_ls_init(qs_env, ksmat, smat)
2568 CALL ec_ls_solver(qs_env, pmat, wmat, ec_ls_method=ec_env%ks_solver)
2573 IF (ec_env%mao)
THEN
2574 CALL mao_release_matrices(ec_env, ksmat, smat, pmat, wmat)
2577 CALL timestop(handle)
2579 END SUBROUTINE ec_ks_solver
2592 SUBROUTINE mao_create_matrices(ec_env, ksmat, smat, pmat, wmat)
2594 TYPE(energy_correction_type),
POINTER :: ec_env
2595 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: ksmat, smat, pmat, wmat
2597 CHARACTER(LEN=*),
PARAMETER :: routinen =
'mao_create_matrices'
2599 INTEGER :: handle, ispin, nspins
2600 INTEGER,
DIMENSION(:),
POINTER :: col_blk_sizes
2601 TYPE(dbcsr_distribution_type) :: dbcsr_dist
2602 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: mao_coef
2603 TYPE(dbcsr_type) :: cgmat
2605 CALL timeset(routinen, handle)
2607 mao_coef => ec_env%mao_coef
2609 NULLIFY (ksmat, smat, pmat, wmat)
2610 nspins =
SIZE(ec_env%matrix_ks, 1)
2611 CALL dbcsr_get_info(mao_coef(1)%matrix, col_blk_size=col_blk_sizes, distribution=dbcsr_dist)
2612 CALL dbcsr_allocate_matrix_set(ksmat, nspins, 1)
2613 CALL dbcsr_allocate_matrix_set(smat, nspins, 1)
2614 DO ispin = 1, nspins
2615 ALLOCATE (ksmat(ispin, 1)%matrix)
2616 CALL dbcsr_create(ksmat(ispin, 1)%matrix, dist=dbcsr_dist, name=
"MAO KS mat", &
2617 matrix_type=dbcsr_type_symmetric, row_blk_size=col_blk_sizes, &
2618 col_blk_size=col_blk_sizes)
2619 ALLOCATE (smat(ispin, 1)%matrix)
2620 CALL dbcsr_create(smat(ispin, 1)%matrix, dist=dbcsr_dist, name=
"MAO S mat", &
2621 matrix_type=dbcsr_type_symmetric, row_blk_size=col_blk_sizes, &
2622 col_blk_size=col_blk_sizes)
2625 CALL dbcsr_create(cgmat, name=
"TEMP matrix", template=mao_coef(1)%matrix)
2626 DO ispin = 1, nspins
2627 CALL dbcsr_multiply(
"N",
"N", 1.0_dp, ec_env%matrix_s(1, 1)%matrix, mao_coef(ispin)%matrix, &
2629 CALL dbcsr_multiply(
"T",
"N", 1.0_dp, mao_coef(ispin)%matrix, cgmat, 0.0_dp, smat(ispin, 1)%matrix)
2630 CALL dbcsr_multiply(
"N",
"N", 1.0_dp, ec_env%matrix_ks(1, 1)%matrix, mao_coef(ispin)%matrix, &
2632 CALL dbcsr_multiply(
"T",
"N", 1.0_dp, mao_coef(ispin)%matrix, cgmat, 0.0_dp, ksmat(ispin, 1)%matrix)
2634 CALL dbcsr_release(cgmat)
2636 CALL dbcsr_allocate_matrix_set(pmat, nspins, 1)
2637 DO ispin = 1, nspins
2638 ALLOCATE (pmat(ispin, 1)%matrix)
2639 CALL dbcsr_create(pmat(ispin, 1)%matrix, template=smat(1, 1)%matrix, name=
"MAO P mat")
2640 CALL cp_dbcsr_alloc_block_from_nbl(pmat(ispin, 1)%matrix, ec_env%sab_orb)
2643 CALL dbcsr_allocate_matrix_set(wmat, nspins, 1)
2644 DO ispin = 1, nspins
2645 ALLOCATE (wmat(ispin, 1)%matrix)
2646 CALL dbcsr_create(wmat(ispin, 1)%matrix, template=smat(1, 1)%matrix, name=
"MAO W mat")
2647 CALL cp_dbcsr_alloc_block_from_nbl(wmat(ispin, 1)%matrix, ec_env%sab_orb)
2650 CALL timestop(handle)
2652 END SUBROUTINE mao_create_matrices
2665 SUBROUTINE mao_release_matrices(ec_env, ksmat, smat, pmat, wmat)
2667 TYPE(energy_correction_type),
POINTER :: ec_env
2668 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: ksmat, smat, pmat, wmat
2670 CHARACTER(LEN=*),
PARAMETER :: routinen =
'mao_release_matrices'
2672 INTEGER :: handle, ispin, nspins
2673 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: mao_coef
2674 TYPE(dbcsr_type) :: cgmat
2676 CALL timeset(routinen, handle)
2678 mao_coef => ec_env%mao_coef
2679 nspins =
SIZE(mao_coef, 1)
2682 CALL dbcsr_create(cgmat, name=
"TEMP matrix", template=mao_coef(1)%matrix)
2683 DO ispin = 1, nspins
2684 CALL dbcsr_multiply(
"N",
"N", 1.0_dp, mao_coef(ispin)%matrix, pmat(ispin, 1)%matrix, 0.0_dp, cgmat)
2685 CALL dbcsr_multiply(
"N",
"T", 1.0_dp, mao_coef(ispin)%matrix, cgmat, 0.0_dp, &
2686 ec_env%matrix_p(ispin, 1)%matrix, retain_sparsity=.true.)
2687 CALL dbcsr_multiply(
"N",
"N", 1.0_dp, mao_coef(ispin)%matrix, wmat(ispin, 1)%matrix, 0.0_dp, cgmat)
2688 CALL dbcsr_multiply(
"N",
"T", 1.0_dp, mao_coef(ispin)%matrix, cgmat, 0.0_dp, &
2689 ec_env%matrix_w(ispin, 1)%matrix, retain_sparsity=.true.)
2691 CALL dbcsr_release(cgmat)
2693 CALL dbcsr_deallocate_matrix_set(ksmat)
2694 CALL dbcsr_deallocate_matrix_set(smat)
2695 CALL dbcsr_deallocate_matrix_set(pmat)
2696 CALL dbcsr_deallocate_matrix_set(wmat)
2698 CALL timestop(handle)
2700 END SUBROUTINE mao_release_matrices
2713 SUBROUTINE ec_diag_solver(qs_env, matrix_ks, matrix_s, matrix_p, matrix_w)
2715 TYPE(qs_environment_type),
POINTER :: qs_env
2716 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_ks, matrix_s, matrix_p, matrix_w
2718 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ec_diag_solver'
2720 INTEGER :: handle, ispin, nmo(2), nsize, nspins
2721 REAL(kind=dp) :: eps_filter, focc(2)
2722 REAL(kind=dp),
ALLOCATABLE,
DIMENSION(:) :: eigenvalues
2723 TYPE(cp_blacs_env_type),
POINTER :: blacs_env
2724 TYPE(cp_fm_struct_type),
POINTER :: fm_struct
2725 TYPE(cp_fm_type) :: fm_ks, fm_mo, fm_ortho
2726 TYPE(dbcsr_type),
POINTER :: buf1_dbcsr, buf2_dbcsr, buf3_dbcsr, &
2727 ortho_dbcsr, ref_matrix
2728 TYPE(dft_control_type),
POINTER :: dft_control
2729 TYPE(mp_para_env_type),
POINTER :: para_env
2731 CALL timeset(routinen, handle)
2733 NULLIFY (blacs_env, para_env)
2734 CALL get_qs_env(qs_env=qs_env, blacs_env=blacs_env, para_env=para_env)
2736 CALL get_qs_env(qs_env=qs_env, dft_control=dft_control)
2737 eps_filter = dft_control%qs_control%eps_filter_matrix
2738 nspins = dft_control%nspins
2741 CALL get_qs_env(qs_env=qs_env, nelectron_spin=nmo)
2743 IF (nspins == 1)
THEN
2748 CALL dbcsr_get_info(matrix_ks(1, 1)%matrix, nfullrows_total=nsize)
2749 ALLOCATE (eigenvalues(nsize))
2751 NULLIFY (fm_struct, ref_matrix)
2752 CALL cp_fm_struct_create(fm_struct, context=blacs_env, nrow_global=nsize, &
2753 ncol_global=nsize, para_env=para_env)
2754 CALL cp_fm_create(fm_ortho, fm_struct)
2755 CALL cp_fm_create(fm_ks, fm_struct)
2756 CALL cp_fm_create(fm_mo, fm_struct)
2757 CALL cp_fm_struct_release(fm_struct)
2760 ref_matrix => matrix_s(1, 1)%matrix
2761 NULLIFY (ortho_dbcsr, buf1_dbcsr, buf2_dbcsr, buf3_dbcsr)
2762 CALL dbcsr_init_p(ortho_dbcsr)
2763 CALL dbcsr_create(ortho_dbcsr, template=ref_matrix, &
2764 matrix_type=dbcsr_type_no_symmetry)
2765 CALL dbcsr_init_p(buf1_dbcsr)
2766 CALL dbcsr_create(buf1_dbcsr, template=ref_matrix, &
2767 matrix_type=dbcsr_type_no_symmetry)
2768 CALL dbcsr_init_p(buf2_dbcsr)
2769 CALL dbcsr_create(buf2_dbcsr, template=ref_matrix, &
2770 matrix_type=dbcsr_type_no_symmetry)
2771 CALL dbcsr_init_p(buf3_dbcsr)
2772 CALL dbcsr_create(buf3_dbcsr, template=ref_matrix, &
2773 matrix_type=dbcsr_type_no_symmetry)
2775 ref_matrix => matrix_s(1, 1)%matrix
2776 CALL copy_dbcsr_to_fm(ref_matrix, fm_ortho)
2777 CALL cp_fm_cholesky_decompose(fm_ortho)
2778 CALL cp_fm_triangular_invert(fm_ortho)
2779 CALL cp_fm_set_all(fm_ks, 0.0_dp)
2780 CALL cp_fm_to_fm_triangular(fm_ortho, fm_ks,
"U")
2781 CALL copy_fm_to_dbcsr(fm_ks, ortho_dbcsr)
2782 DO ispin = 1, nspins
2784 CALL dbcsr_desymmetrize(matrix_ks(ispin, 1)%matrix, buf1_dbcsr)
2785 CALL dbcsr_multiply(
"N",
"N", 1.0_dp, buf1_dbcsr, ortho_dbcsr, &
2786 0.0_dp, buf2_dbcsr, filter_eps=eps_filter)
2787 CALL dbcsr_multiply(
"T",
"N", 1.0_dp, ortho_dbcsr, buf2_dbcsr, &
2788 0.0_dp, buf1_dbcsr, filter_eps=eps_filter)
2790 CALL copy_dbcsr_to_fm(buf1_dbcsr, fm_ks)
2791 CALL choose_eigv_solver(fm_ks, fm_mo, eigenvalues)
2793 CALL copy_fm_to_dbcsr(fm_mo, buf1_dbcsr)
2794 CALL dbcsr_multiply(
"N",
"N", 1.0_dp, ortho_dbcsr, buf1_dbcsr, &
2795 0.0_dp, buf2_dbcsr, filter_eps=eps_filter)
2797 CALL dbcsr_set(matrix_p(ispin, 1)%matrix, 0.0_dp)
2798 CALL dbcsr_multiply(
"N",
"T", focc(ispin), buf2_dbcsr, buf2_dbcsr, &
2799 1.0_dp, matrix_p(ispin, 1)%matrix, &
2800 retain_sparsity=.true., last_k=nmo(ispin))
2803 CALL dbcsr_set(matrix_w(ispin, 1)%matrix, 0.0_dp)
2804 CALL cp_fm_column_scale(fm_mo, eigenvalues)
2805 CALL copy_fm_to_dbcsr(fm_mo, buf1_dbcsr)
2806 CALL dbcsr_multiply(
"N",
"N", 1.0_dp, ortho_dbcsr, buf1_dbcsr, &
2807 0.0_dp, buf3_dbcsr, filter_eps=eps_filter)
2808 CALL dbcsr_multiply(
"N",
"T", focc(ispin), buf2_dbcsr, buf3_dbcsr, &
2809 1.0_dp, matrix_w(ispin, 1)%matrix, &
2810 retain_sparsity=.true., last_k=nmo(ispin))
2813 CALL cp_fm_release(fm_ks)
2814 CALL cp_fm_release(fm_mo)
2815 CALL cp_fm_release(fm_ortho)
2816 CALL dbcsr_release(ortho_dbcsr)
2817 CALL dbcsr_release(buf1_dbcsr)
2818 CALL dbcsr_release(buf2_dbcsr)
2819 CALL dbcsr_release(buf3_dbcsr)
2820 DEALLOCATE (ortho_dbcsr, buf1_dbcsr, buf2_dbcsr, buf3_dbcsr)
2821 DEALLOCATE (eigenvalues)
2823 CALL timestop(handle)
2825 END SUBROUTINE ec_diag_solver
2833 SUBROUTINE ec_energy(ec_env, unit_nr)
2834 TYPE(energy_correction_type) :: ec_env
2835 INTEGER,
INTENT(IN) :: unit_nr
2837 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ec_energy'
2839 INTEGER :: handle, ispin, nspins
2840 REAL(kind=dp) :: eband, trace
2842 CALL timeset(routinen, handle)
2844 nspins =
SIZE(ec_env%matrix_p, 1)
2845 DO ispin = 1, nspins
2846 CALL dbcsr_dot(ec_env%matrix_p(ispin, 1)%matrix, ec_env%matrix_s(1, 1)%matrix, trace)
2847 IF (unit_nr > 0)
WRITE (unit_nr,
'(T3,A,T65,F16.10)')
'Tr[PS] ', trace
2851 SELECT CASE (ec_env%energy_functional)
2852 CASE (ec_functional_harris)
2856 DO ispin = 1, nspins
2857 CALL dbcsr_dot(ec_env%matrix_ks(ispin, 1)%matrix, ec_env%matrix_p(ispin, 1)%matrix, trace)
2858 eband = eband + trace
2860 ec_env%eband = eband + ec_env%efield_nuclear
2863 ec_env%etotal = ec_env%eband + ec_env%ehartree + ec_env%exc - ec_env%vhxc + ec_env%edispersion - ec_env%ex
2864 IF (unit_nr > 0)
THEN
2865 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Eband ", ec_env%eband
2866 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Ehartree ", ec_env%ehartree
2867 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Exc ", ec_env%exc
2868 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Ex ", ec_env%ex
2869 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Evhxc ", ec_env%vhxc
2870 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Edisp ", ec_env%edispersion
2871 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Etotal Harris Functional ", ec_env%etotal
2874 CASE (ec_functional_dc)
2877 CALL calculate_ptrace(ec_env%matrix_h, ec_env%matrix_p, ec_env%ecore,
SIZE(ec_env%matrix_p, 1))
2879 ec_env%ecore = ec_env%ecore + ec_env%efield_nuclear
2880 ec_env%etotal = ec_env%ecore + ec_env%ehartree + ec_env%exc + ec_env%edispersion &
2881 + ec_env%ex + ec_env%exc_aux_fit
2883 IF (unit_nr > 0)
THEN
2884 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Ecore ", ec_env%ecore
2885 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Ehartree ", ec_env%ehartree
2886 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Exc ", ec_env%exc
2887 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Ex ", ec_env%ex
2888 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Exc_aux_fit", ec_env%exc_aux_fit
2889 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Edisp ", ec_env%edispersion
2890 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Etotal Energy Functional ", ec_env%etotal
2893 CASE (ec_functional_ext)
2895 ec_env%etotal = ec_env%ex
2896 IF (unit_nr > 0)
THEN
2897 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Etotal Energy Functional ", ec_env%etotal
2906 CALL timestop(handle)
2908 END SUBROUTINE ec_energy
2920 SUBROUTINE ec_build_neighborlist(qs_env, ec_env)
2921 TYPE(qs_environment_type),
POINTER :: qs_env
2922 TYPE(energy_correction_type),
POINTER :: ec_env
2924 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ec_build_neighborlist'
2926 INTEGER :: handle, ikind, nkind, zat
2927 LOGICAL :: gth_potential_present, &
2928 sgp_potential_present, &
2929 skip_load_balance_distributed
2930 LOGICAL,
ALLOCATABLE,
DIMENSION(:) :: default_present, orb_present, &
2931 ppl_present, ppnl_present
2932 REAL(dp) :: subcells
2933 REAL(dp),
ALLOCATABLE,
DIMENSION(:) :: c_radius, orb_radius, ppl_radius, &
2935 REAL(dp),
ALLOCATABLE,
DIMENSION(:, :) :: pair_radius
2936 TYPE(atomic_kind_type),
DIMENSION(:),
POINTER :: atomic_kind_set
2937 TYPE(cell_type),
POINTER :: cell
2938 TYPE(dft_control_type),
POINTER :: dft_control
2939 TYPE(distribution_1d_type),
POINTER :: distribution_1d
2940 TYPE(distribution_2d_type),
POINTER :: distribution_2d
2941 TYPE(gth_potential_type),
POINTER :: gth_potential
2942 TYPE(gto_basis_set_type),
POINTER :: basis_set
2943 TYPE(local_atoms_type),
ALLOCATABLE,
DIMENSION(:) :: atom2d
2944 TYPE(molecule_type),
DIMENSION(:),
POINTER :: molecule_set
2945 TYPE(neighbor_list_set_p_type),
DIMENSION(:), &
2946 POINTER :: sab_cn, sab_vdw
2947 TYPE(particle_type),
DIMENSION(:),
POINTER :: particle_set
2948 TYPE(qs_dispersion_type),
POINTER :: dispersion_env
2949 TYPE(qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
2950 TYPE(qs_kind_type),
POINTER :: qs_kind
2951 TYPE(qs_ks_env_type),
POINTER :: ks_env
2952 TYPE(sgp_potential_type),
POINTER :: sgp_potential
2954 CALL timeset(routinen, handle)
2956 CALL get_qs_env(qs_env=qs_env, qs_kind_set=qs_kind_set)
2957 CALL get_qs_kind_set(qs_kind_set, gth_potential_present=gth_potential_present, &
2958 sgp_potential_present=sgp_potential_present)
2959 nkind =
SIZE(qs_kind_set)
2960 ALLOCATE (c_radius(nkind), default_present(nkind))
2961 ALLOCATE (orb_radius(nkind), ppl_radius(nkind), ppnl_radius(nkind))
2962 ALLOCATE (orb_present(nkind), ppl_present(nkind), ppnl_present(nkind))
2963 ALLOCATE (pair_radius(nkind, nkind))
2964 ALLOCATE (atom2d(nkind))
2966 CALL get_qs_env(qs_env, &
2967 atomic_kind_set=atomic_kind_set, &
2969 distribution_2d=distribution_2d, &
2970 local_particles=distribution_1d, &
2971 particle_set=particle_set, &
2972 molecule_set=molecule_set)
2974 CALL atom2d_build(atom2d, distribution_1d, distribution_2d, atomic_kind_set, &
2975 molecule_set, .false., particle_set)
2978 CALL get_atomic_kind(atomic_kind_set(ikind), atom_list=atom2d(ikind)%list)
2979 qs_kind => qs_kind_set(ikind)
2980 CALL get_qs_kind(qs_kind=qs_kind, basis_set=basis_set, basis_type=
"HARRIS")
2981 IF (
ASSOCIATED(basis_set))
THEN
2982 orb_present(ikind) = .true.
2983 CALL get_gto_basis_set(gto_basis_set=basis_set, kind_radius=orb_radius(ikind))
2985 orb_present(ikind) = .false.
2986 orb_radius(ikind) = 0.0_dp
2988 CALL get_qs_kind(qs_kind, gth_potential=gth_potential, sgp_potential=sgp_potential)
2989 IF (gth_potential_present .OR. sgp_potential_present)
THEN
2990 IF (
ASSOCIATED(gth_potential))
THEN
2991 CALL get_potential(potential=gth_potential, &
2992 ppl_present=ppl_present(ikind), &
2993 ppl_radius=ppl_radius(ikind), &
2994 ppnl_present=ppnl_present(ikind), &
2995 ppnl_radius=ppnl_radius(ikind))
2996 ELSE IF (
ASSOCIATED(sgp_potential))
THEN
2997 CALL get_potential(potential=sgp_potential, &
2998 ppl_present=ppl_present(ikind), &
2999 ppl_radius=ppl_radius(ikind), &
3000 ppnl_present=ppnl_present(ikind), &
3001 ppnl_radius=ppnl_radius(ikind))
3003 ppl_present(ikind) = .false.
3004 ppl_radius(ikind) = 0.0_dp
3005 ppnl_present(ikind) = .false.
3006 ppnl_radius(ikind) = 0.0_dp
3011 CALL section_vals_val_get(qs_env%input,
"DFT%SUBCELLS", r_val=subcells)
3014 CALL pair_radius_setup(orb_present, orb_present, orb_radius, orb_radius, pair_radius)
3015 CALL build_neighbor_lists(ec_env%sab_orb, particle_set, atom2d, cell, pair_radius, &
3016 subcells=subcells, nlname=
"sab_orb")
3018 IF (gth_potential_present .OR. sgp_potential_present)
THEN
3019 IF (any(ppl_present))
THEN
3020 CALL pair_radius_setup(orb_present, ppl_present, orb_radius, ppl_radius, pair_radius)
3021 CALL build_neighbor_lists(ec_env%sac_ppl, particle_set, atom2d, cell, pair_radius, &
3022 subcells=subcells, operator_type=
"ABC", nlname=
"sac_ppl")
3025 IF (any(ppnl_present))
THEN
3026 CALL pair_radius_setup(orb_present, ppnl_present, orb_radius, ppnl_radius, pair_radius)
3027 CALL build_neighbor_lists(ec_env%sap_ppnl, particle_set, atom2d, cell, pair_radius, &
3028 subcells=subcells, operator_type=
"ABBA", nlname=
"sap_ppnl")
3033 c_radius(:) = 0.0_dp
3034 dispersion_env => ec_env%dispersion_env
3035 sab_vdw => dispersion_env%sab_vdw
3036 sab_cn => dispersion_env%sab_cn
3037 IF (dispersion_env%type == xc_vdw_fun_pairpot)
THEN
3038 c_radius(:) = dispersion_env%rc_disp
3039 default_present = .true.
3040 CALL pair_radius_setup(default_present, default_present, c_radius, c_radius, pair_radius)
3041 CALL build_neighbor_lists(sab_vdw, particle_set, atom2d, cell, pair_radius, &
3042 subcells=subcells, operator_type=
"PP", nlname=
"sab_vdw")
3043 dispersion_env%sab_vdw => sab_vdw
3044 IF (dispersion_env%pp_type == vdw_pairpot_dftd3 .OR. &
3045 dispersion_env%pp_type == vdw_pairpot_dftd3bj)
THEN
3048 CALL get_atomic_kind(atomic_kind_set(ikind), z=zat)
3049 c_radius(ikind) = 4._dp*ptable(zat)%covalent_radius*bohr
3051 CALL pair_radius_setup(default_present, default_present, c_radius, c_radius, pair_radius)
3052 CALL build_neighbor_lists(sab_cn, particle_set, atom2d, cell, pair_radius, &
3053 subcells=subcells, operator_type=
"PP", nlname=
"sab_cn")
3054 dispersion_env%sab_cn => sab_cn
3059 CALL atom2d_cleanup(atom2d)
3061 DEALLOCATE (orb_present, default_present, ppl_present, ppnl_present)
3062 DEALLOCATE (orb_radius, ppl_radius, ppnl_radius, c_radius)
3063 DEALLOCATE (pair_radius)
3066 CALL get_qs_env(qs_env, ks_env=ks_env, dft_control=dft_control)
3067 skip_load_balance_distributed = dft_control%qs_control%skip_load_balance_distributed
3068 IF (
ASSOCIATED(ec_env%task_list))
CALL deallocate_task_list(ec_env%task_list)
3069 CALL allocate_task_list(ec_env%task_list)
3070 CALL generate_qs_task_list(ks_env, ec_env%task_list, &
3071 reorder_rs_grid_ranks=.false., soft_valid=.false., &
3072 skip_load_balance_distributed=skip_load_balance_distributed, &
3073 basis_type=
"HARRIS", sab_orb_external=ec_env%sab_orb)
3075 CALL timestop(handle)
3077 END SUBROUTINE ec_build_neighborlist
3084 SUBROUTINE ec_properties(qs_env, ec_env)
3085 TYPE(qs_environment_type),
POINTER :: qs_env
3086 TYPE(energy_correction_type),
POINTER :: ec_env
3088 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ec_properties'
3090 CHARACTER(LEN=8),
DIMENSION(3) :: rlab
3091 CHARACTER(LEN=default_path_length) :: filename, my_pos_voro
3092 CHARACTER(LEN=default_string_length) :: description
3093 INTEGER :: akind, handle, i, ia, iatom, idir, ikind, iounit, ispin, maxmom, nspins, &
3094 reference, should_print_bqb, should_print_voro, unit_nr, unit_nr_voro
3095 LOGICAL :: append_voro, magnetic, periodic, &
3097 REAL(kind=dp) :: charge, dd, focc, tmp
3098 REAL(kind=dp),
DIMENSION(3) :: cdip, pdip, rcc, rdip, ria, tdip
3099 REAL(kind=dp),
DIMENSION(:),
POINTER :: ref_point
3100 TYPE(atomic_kind_type),
POINTER :: atomic_kind
3101 TYPE(cell_type),
POINTER :: cell
3102 TYPE(cp_logger_type),
POINTER :: logger
3103 TYPE(cp_result_type),
POINTER :: results
3104 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_s, moments
3105 TYPE(dft_control_type),
POINTER :: dft_control
3106 TYPE(distribution_1d_type),
POINTER :: local_particles
3107 TYPE(mp_para_env_type),
POINTER :: para_env
3108 TYPE(particle_type),
DIMENSION(:),
POINTER :: particle_set
3109 TYPE(pw_env_type),
POINTER :: pw_env
3110 TYPE(pw_pool_p_type),
DIMENSION(:),
POINTER :: pw_pools
3111 TYPE(pw_pool_type),
POINTER :: auxbas_pw_pool
3112 TYPE(pw_r3d_rs_type) :: rho_elec_rspace
3113 TYPE(qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
3114 TYPE(section_vals_type),
POINTER :: ec_section, print_key, print_key_bqb, &
3117 CALL timeset(routinen, handle)
3123 logger => cp_get_default_logger()
3124 IF (logger%para_env%is_source())
THEN
3125 iounit = cp_logger_get_default_unit_nr(logger, local=.true.)
3130 NULLIFY (dft_control)
3131 CALL get_qs_env(qs_env, dft_control=dft_control)
3132 nspins = dft_control%nspins
3134 ec_section => section_vals_get_subs_vals(qs_env%input,
"DFT%ENERGY_CORRECTION")
3135 print_key => section_vals_get_subs_vals(section_vals=ec_section, &
3136 subsection_name=
"PRINT%MOMENTS")
3138 IF (btest(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file))
THEN
3140 maxmom = section_get_ival(section_vals=ec_section, &
3141 keyword_name=
"PRINT%MOMENTS%MAX_MOMENT")
3142 periodic = section_get_lval(section_vals=ec_section, &
3143 keyword_name=
"PRINT%MOMENTS%PERIODIC")
3144 reference = section_get_ival(section_vals=ec_section, &
3145 keyword_name=
"PRINT%MOMENTS%REFERENCE")
3146 magnetic = section_get_lval(section_vals=ec_section, &
3147 keyword_name=
"PRINT%MOMENTS%MAGNETIC")
3149 CALL section_vals_val_get(ec_section,
"PRINT%MOMENTS%REF_POINT", r_vals=ref_point)
3150 unit_nr = cp_print_key_unit_nr(logger=logger, basis_section=ec_section, &
3151 print_key_path=
"PRINT%MOMENTS", extension=
".dat", &
3152 middle_name=
"moments", log_filename=.false.)
3154 IF (iounit > 0)
THEN
3155 IF (unit_nr /= iounit .AND. unit_nr > 0)
THEN
3156 INQUIRE (unit=unit_nr, name=filename)
3157 WRITE (unit=iounit, fmt=
"(/,T2,A,2(/,T3,A),/)") &
3158 "MOMENTS",
"The electric/magnetic moments are written to file:", &
3161 WRITE (unit=iounit, fmt=
"(/,T2,A)")
"ELECTRIC/MAGNETIC MOMENTS"
3166 cpabort(
"Periodic moments not implemented with EC")
3168 cpassert(maxmom < 2)
3169 cpassert(.NOT. magnetic)
3170 IF (maxmom == 1)
THEN
3171 CALL get_qs_env(qs_env=qs_env, cell=cell, para_env=para_env)
3173 CALL get_reference_point(rcc, qs_env=qs_env, reference=reference, ref_point=ref_point)
3176 CALL get_qs_env(qs_env=qs_env, particle_set=particle_set, &
3177 qs_kind_set=qs_kind_set, local_particles=local_particles)
3178 DO ikind = 1,
SIZE(local_particles%n_el)
3179 DO ia = 1, local_particles%n_el(ikind)
3180 iatom = local_particles%list(ikind)%array(ia)
3182 ria = pbc(particle_set(iatom)%r - rcc, cell) + rcc
3184 atomic_kind => particle_set(iatom)%atomic_kind
3185 CALL get_atomic_kind(atomic_kind, kind_number=akind)
3186 CALL get_qs_kind(qs_kind_set(akind), core_charge=charge)
3187 cdip(1:3) = cdip(1:3) - charge*ria(1:3)
3190 CALL para_env%sum(cdip)
3193 CALL ec_efield_integrals(qs_env, ec_env, rcc)
3196 DO ispin = 1, nspins
3198 CALL dbcsr_dot(ec_env%matrix_p(ispin, 1)%matrix, &
3199 ec_env%efield%dipmat(idir)%matrix, tmp)
3200 pdip(idir) = pdip(idir) + tmp
3205 CALL get_qs_env(qs_env=qs_env, matrix_s=matrix_s)
3207 CALL dbcsr_allocate_matrix_set(moments, 4)
3209 ALLOCATE (moments(i)%matrix)
3210 CALL dbcsr_copy(moments(i)%matrix, matrix_s(1)%matrix,
"Moments")
3211 CALL dbcsr_set(moments(i)%matrix, 0.0_dp)
3213 CALL build_local_moment_matrix(qs_env, moments, 1, ref_point=rcc)
3216 IF (nspins == 2) focc = 1.0_dp
3218 DO ispin = 1, nspins
3220 CALL dbcsr_dot(ec_env%matrix_z(ispin)%matrix, moments(idir)%matrix, tmp)
3221 rdip(idir) = rdip(idir) + tmp
3224 CALL dbcsr_deallocate_matrix_set(moments)
3226 tdip = -(rdip + pdip + cdip)
3227 IF (unit_nr > 0)
THEN
3228 WRITE (unit_nr,
"(T3,A)")
"Dipoles are based on the traditional operator."
3229 dd = sqrt(sum(tdip(1:3)**2))*debye
3230 WRITE (unit_nr,
"(T3,A)")
"Dipole moment [Debye]"
3231 WRITE (unit_nr,
"(T5,3(A,A,F14.8,1X),T60,A,T67,F14.8)") &
3232 (trim(rlab(i)),
"=", tdip(i)*debye, i=1, 3),
"Total=", dd
3237 CALL cp_print_key_finished_output(unit_nr=unit_nr, logger=logger, &
3238 basis_section=ec_section, print_key_path=
"PRINT%MOMENTS")
3239 CALL get_qs_env(qs_env=qs_env, results=results)
3240 description =
"[DIPOLE]"
3241 CALL cp_results_erase(results=results, description=description)
3242 CALL put_results(results=results, description=description, values=tdip(1:3))
3246 print_key_voro => section_vals_get_subs_vals(ec_section,
"PRINT%VORONOI")
3247 print_key_bqb => section_vals_get_subs_vals(ec_section,
"PRINT%E_DENSITY_BQB")
3248 IF (btest(cp_print_key_should_output(logger%iter_info, print_key_voro), cp_p_file))
THEN
3249 should_print_voro = 1
3251 should_print_voro = 0
3253 IF (btest(cp_print_key_should_output(logger%iter_info, print_key_bqb), cp_p_file))
THEN
3254 should_print_bqb = 1
3256 should_print_bqb = 0
3258 IF ((should_print_voro /= 0) .OR. (should_print_bqb /= 0))
THEN
3260 CALL get_qs_env(qs_env=qs_env, &
3262 CALL pw_env_get(pw_env=pw_env, &
3263 auxbas_pw_pool=auxbas_pw_pool, &
3265 CALL auxbas_pw_pool%create_pw(pw=rho_elec_rspace)
3267 IF (dft_control%nspins > 1)
THEN
3270 CALL pw_copy(ec_env%rhoout_r(1), rho_elec_rspace)
3271 CALL pw_axpy(ec_env%rhoout_r(2), rho_elec_rspace)
3273 CALL pw_axpy(ec_env%rhoz_r(1), rho_elec_rspace)
3274 CALL pw_axpy(ec_env%rhoz_r(2), rho_elec_rspace)
3278 CALL pw_copy(ec_env%rhoout_r(1), rho_elec_rspace)
3279 CALL pw_axpy(ec_env%rhoz_r(1), rho_elec_rspace)
3282 IF (should_print_voro /= 0)
THEN
3283 CALL section_vals_val_get(print_key_voro,
"OUTPUT_TEXT", l_val=voro_print_txt)
3284 IF (voro_print_txt)
THEN
3285 append_voro = section_get_lval(ec_section,
"PRINT%VORONOI%APPEND")
3286 my_pos_voro =
"REWIND"
3287 IF (append_voro)
THEN
3288 my_pos_voro =
"APPEND"
3290 unit_nr_voro = cp_print_key_unit_nr(logger, ec_section,
"PRINT%VORONOI", extension=
".voronoi", &
3291 file_position=my_pos_voro, log_filename=.false.)
3299 CALL entry_voronoi_or_bqb(should_print_voro, should_print_bqb, print_key_voro, print_key_bqb, &
3300 unit_nr_voro, qs_env, rho_elec_rspace)
3302 CALL auxbas_pw_pool%give_back_pw(rho_elec_rspace)
3304 IF (unit_nr_voro > 0)
THEN
3305 CALL cp_print_key_finished_output(unit_nr_voro, logger, ec_section,
"PRINT%VORONOI")
3310 CALL timestop(handle)
3312 END SUBROUTINE ec_properties
3325 SUBROUTINE ec_ls_init(qs_env, matrix_ks, matrix_s)
3326 TYPE(qs_environment_type),
POINTER :: qs_env
3327 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_ks, matrix_s
3329 CHARACTER(len=*),
PARAMETER :: routinen =
'ec_ls_init'
3331 INTEGER :: handle, ispin, nspins
3332 TYPE(dft_control_type),
POINTER :: dft_control
3333 TYPE(energy_correction_type),
POINTER :: ec_env
3334 TYPE(ls_scf_env_type),
POINTER :: ls_env
3336 CALL timeset(routinen, handle)
3338 CALL get_qs_env(qs_env=qs_env, &
3339 dft_control=dft_control, &
3341 nspins = dft_control%nspins
3342 ls_env => ec_env%ls_env
3345 CALL matrix_ls_create(matrix_ls=ls_env%matrix_s, matrix_qs=matrix_s(1, 1)%matrix, &
3346 ls_mstruct=ls_env%ls_mstruct)
3348 IF (
ALLOCATED(ls_env%matrix_p))
THEN
3349 DO ispin = 1,
SIZE(ls_env%matrix_p)
3350 CALL dbcsr_release(ls_env%matrix_p(ispin))
3353 ALLOCATE (ls_env%matrix_p(nspins))
3356 DO ispin = 1, nspins
3357 CALL dbcsr_create(ls_env%matrix_p(ispin), template=ls_env%matrix_s, &
3358 matrix_type=dbcsr_type_no_symmetry)
3361 ALLOCATE (ls_env%matrix_ks(nspins))
3362 DO ispin = 1, nspins
3363 CALL dbcsr_create(ls_env%matrix_ks(ispin), template=ls_env%matrix_s, &
3364 matrix_type=dbcsr_type_no_symmetry)
3368 CALL ls_scf_init_matrix_s(matrix_s(1, 1)%matrix, ls_env)
3372 DO ispin = 1, nspins
3373 CALL matrix_qs_to_ls(matrix_ls=ls_env%matrix_ks(ispin), &
3374 matrix_qs=matrix_ks(ispin, 1)%matrix, &
3375 ls_mstruct=ls_env%ls_mstruct, &
3379 CALL timestop(handle)
3381 END SUBROUTINE ec_ls_init
3397 SUBROUTINE ec_ls_solver(qs_env, matrix_p, matrix_w, ec_ls_method)
3398 TYPE(qs_environment_type),
POINTER :: qs_env
3399 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_p, matrix_w
3400 INTEGER,
INTENT(IN) :: ec_ls_method
3402 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ec_ls_solver'
3404 INTEGER :: handle, ispin, nelectron_spin_real, &
3406 INTEGER,
DIMENSION(2) :: nmo
3407 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: wmat
3408 TYPE(dbcsr_type),
ALLOCATABLE,
DIMENSION(:) :: matrix_ks_deviation
3409 TYPE(dft_control_type),
POINTER :: dft_control
3410 TYPE(energy_correction_type),
POINTER :: ec_env
3411 TYPE(ls_scf_env_type),
POINTER :: ls_env
3412 TYPE(mp_para_env_type),
POINTER :: para_env
3414 CALL timeset(routinen, handle)
3417 CALL get_qs_env(qs_env, &
3418 dft_control=dft_control, &
3420 nspins = dft_control%nspins
3421 ec_env => qs_env%ec_env
3422 ls_env => ec_env%ls_env
3425 CALL get_qs_env(qs_env=qs_env, nelectron_spin=nmo)
3426 IF (nspins == 1) nmo(1) = nmo(1)/2
3427 ls_env%homo_spin(:) = 0.0_dp
3428 ls_env%lumo_spin(:) = 0.0_dp
3430 ALLOCATE (matrix_ks_deviation(nspins))
3431 DO ispin = 1, nspins
3432 CALL dbcsr_create(matrix_ks_deviation(ispin), template=ls_env%matrix_ks(ispin))
3433 CALL dbcsr_set(matrix_ks_deviation(ispin), 0.0_dp)
3437 IF (ls_env%has_s_preconditioner)
THEN
3438 DO ispin = 1, nspins
3439 CALL apply_matrix_preconditioner(ls_env%matrix_ks(ispin),
"forward", &
3440 ls_env%matrix_bs_sqrt, ls_env%matrix_bs_sqrt_inv)
3442 CALL dbcsr_filter(ls_env%matrix_ks(ispin), ls_env%eps_filter)
3446 DO ispin = 1, nspins
3447 nelectron_spin_real = ls_env%nelectron_spin(ispin)
3448 IF (ls_env%nspins == 1) nelectron_spin_real = nelectron_spin_real/2
3450 SELECT CASE (ec_ls_method)
3451 CASE (ec_matrix_sign)
3452 CALL density_matrix_sign(ls_env%matrix_p(ispin), &
3453 ls_env%mu_spin(ispin), &
3455 ls_env%sign_method, &
3456 ls_env%sign_order, &
3457 ls_env%matrix_ks(ispin), &
3459 ls_env%matrix_s_inv, &
3460 nelectron_spin_real, &
3463 CASE (ec_matrix_trs4)
3464 CALL density_matrix_trs4( &
3465 ls_env%matrix_p(ispin), &
3466 ls_env%matrix_ks(ispin), &
3467 ls_env%matrix_s_sqrt_inv, &
3468 nelectron_spin_real, &
3469 ec_env%eps_default, &
3470 ls_env%homo_spin(ispin), &
3471 ls_env%lumo_spin(ispin), &
3472 ls_env%mu_spin(ispin), &
3473 matrix_ks_deviation=matrix_ks_deviation(ispin), &
3474 dynamic_threshold=ls_env%dynamic_threshold, &
3475 eps_lanczos=ls_env%eps_lanczos, &
3476 max_iter_lanczos=ls_env%max_iter_lanczos)
3478 CASE (ec_matrix_tc2)
3479 CALL density_matrix_tc2( &
3480 ls_env%matrix_p(ispin), &
3481 ls_env%matrix_ks(ispin), &
3482 ls_env%matrix_s_sqrt_inv, &
3483 nelectron_spin_real, &
3484 ec_env%eps_default, &
3485 ls_env%homo_spin(ispin), &
3486 ls_env%lumo_spin(ispin), &
3487 non_monotonic=ls_env%non_monotonic, &
3488 eps_lanczos=ls_env%eps_lanczos, &
3489 max_iter_lanczos=ls_env%max_iter_lanczos)
3496 IF (ls_env%has_s_preconditioner)
THEN
3497 DO ispin = 1, nspins
3499 CALL apply_matrix_preconditioner(ls_env%matrix_p(ispin),
"forward", &
3500 ls_env%matrix_bs_sqrt, ls_env%matrix_bs_sqrt_inv)
3502 CALL dbcsr_filter(ls_env%matrix_p(ispin), ls_env%eps_filter)
3507 IF (nspins == 1)
CALL dbcsr_scale(ls_env%matrix_p(1), 2.0_dp)
3509 IF (ls_env%report_all_sparsities)
CALL post_scf_sparsities(ls_env)
3513 DO ispin = 1, nspins
3514 CALL matrix_ls_to_qs(matrix_qs=matrix_p(ispin, 1)%matrix, &
3515 matrix_ls=ls_env%matrix_p(ispin), &
3516 ls_mstruct=ls_env%ls_mstruct, &
3520 wmat => matrix_w(:, 1)
3521 CALL calculate_w_matrix_ls(wmat, ec_env%ls_env)
3524 CALL dbcsr_release(ls_env%matrix_s)
3525 IF (ls_env%has_s_preconditioner)
THEN
3526 CALL dbcsr_release(ls_env%matrix_bs_sqrt)
3527 CALL dbcsr_release(ls_env%matrix_bs_sqrt_inv)
3529 IF (ls_env%needs_s_inv)
THEN
3530 CALL dbcsr_release(ls_env%matrix_s_inv)
3532 IF (ls_env%use_s_sqrt)
THEN
3533 CALL dbcsr_release(ls_env%matrix_s_sqrt)
3534 CALL dbcsr_release(ls_env%matrix_s_sqrt_inv)
3537 DO ispin = 1,
SIZE(ls_env%matrix_ks)
3538 CALL dbcsr_release(ls_env%matrix_ks(ispin))
3540 DEALLOCATE (ls_env%matrix_ks)
3542 DO ispin = 1, nspins
3543 CALL dbcsr_release(matrix_ks_deviation(ispin))
3545 DEALLOCATE (matrix_ks_deviation)
3547 CALL timestop(handle)
3549 END SUBROUTINE ec_ls_solver
3567 SUBROUTINE ec_ot_diag_solver(qs_env, ec_env, matrix_ks, matrix_s, matrix_p, matrix_w)
3568 TYPE(qs_environment_type),
POINTER :: qs_env
3569 TYPE(energy_correction_type),
POINTER :: ec_env
3570 TYPE(dbcsr_p_type),
DIMENSION(:, :),
INTENT(IN), &
3571 POINTER :: matrix_ks, matrix_s
3572 TYPE(dbcsr_p_type),
DIMENSION(:, :), &
3573 INTENT(INOUT),
POINTER :: matrix_p, matrix_w
3575 CHARACTER(len=*),
PARAMETER :: routinen =
'ec_ot_diag_solver'
3577 INTEGER :: handle, homo, ikind, iounit, ispin, &
3578 max_iter, nao, nkind, nmo, nspins
3579 INTEGER,
DIMENSION(2) :: nelectron_spin
3580 REAL(kind=dp),
DIMENSION(:),
POINTER :: eigenvalues
3581 TYPE(atomic_kind_type),
DIMENSION(:),
POINTER :: atomic_kind_set
3582 TYPE(cp_blacs_env_type),
POINTER :: blacs_env
3583 TYPE(cp_fm_type) :: sv
3584 TYPE(cp_fm_type),
POINTER :: mo_coeff
3585 TYPE(cp_logger_type),
POINTER :: logger
3586 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: p_rmpv
3587 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: rho_ao
3588 TYPE(dft_control_type),
POINTER :: dft_control
3589 TYPE(gto_basis_set_type),
POINTER :: basis_set, harris_basis
3590 TYPE(mo_set_type),
DIMENSION(:),
POINTER :: mos
3591 TYPE(mp_para_env_type),
POINTER :: para_env
3592 TYPE(particle_type),
DIMENSION(:),
POINTER :: particle_set
3593 TYPE(preconditioner_type),
POINTER :: local_preconditioner
3594 TYPE(qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
3595 TYPE(qs_kind_type),
POINTER :: qs_kind
3596 TYPE(qs_rho_type),
POINTER :: rho
3598 CALL timeset(routinen, handle)
3600 logger => cp_get_default_logger()
3601 iounit = cp_logger_get_default_unit_nr(logger)
3603 cpassert(
ASSOCIATED(qs_env))
3604 cpassert(
ASSOCIATED(ec_env))
3605 cpassert(
ASSOCIATED(matrix_ks))
3606 cpassert(
ASSOCIATED(matrix_s))
3607 cpassert(
ASSOCIATED(matrix_p))
3608 cpassert(
ASSOCIATED(matrix_w))
3610 CALL get_qs_env(qs_env=qs_env, &
3611 atomic_kind_set=atomic_kind_set, &
3612 blacs_env=blacs_env, &
3613 dft_control=dft_control, &
3614 nelectron_spin=nelectron_spin, &
3615 para_env=para_env, &
3616 particle_set=particle_set, &
3617 qs_kind_set=qs_kind_set)
3618 nspins = dft_control%nspins
3625 IF (dft_control%qs_control%do_ls_scf)
THEN
3626 CALL ec_mos_init(qs_env, matrix_s(1, 1)%matrix)
3629 CALL get_qs_env(qs_env, mos=mos)
3636 CALL get_qs_env(qs_env, qs_kind_set=qs_kind_set, nkind=nkind)
3637 CALL uppercase(ec_env%basis)
3641 IF (ec_env%basis ==
"HARRIS")
THEN
3643 qs_kind => qs_kind_set(ikind)
3645 CALL get_qs_kind(qs_kind=qs_kind, basis_set=basis_set, basis_type=
"ORB")
3647 CALL get_qs_kind(qs_kind=qs_kind, basis_set=harris_basis, basis_type=
"HARRIS")
3649 IF (basis_set%name .NE. harris_basis%name)
THEN
3650 cpabort(
"OT-Diag initial guess: Harris and ground state need to use the same basis")
3655 IF (ec_env%mao)
THEN
3656 cpabort(
"OT-Diag initial guess: not implemented for MAOs")
3660 SELECT CASE (ec_env%ec_initial_guess)
3663 p_rmpv => matrix_p(:, 1)
3665 CALL calculate_atomic_block_dm(p_rmpv, matrix_s(1, 1)%matrix, atomic_kind_set, qs_kind_set, &
3666 nspins, nelectron_spin, iounit, para_env)
3670 CALL get_qs_env(qs_env, rho=rho)
3671 CALL qs_rho_get(rho, rho_ao_kp=rho_ao)
3672 p_rmpv => rho_ao(:, 1)
3675 cpabort(
"Unknown inital guess for OT-Diagonalization (Harris functional)")
3678 DO ispin = 1, nspins
3679 CALL get_mo_set(mo_set=mos(ispin), &
3680 mo_coeff=mo_coeff, &
3686 CALL cp_fm_set_all(mo_coeff, 0.0_dp)
3687 CALL cp_fm_init_random(mo_coeff, nmo)
3689 CALL cp_fm_create(sv, mo_coeff%matrix_struct,
"SV")
3692 CALL cp_dbcsr_sm_fm_multiply(matrix_s(1, 1)%matrix, mo_coeff, sv, nmo)
3693 CALL cp_dbcsr_sm_fm_multiply(p_rmpv(ispin)%matrix, sv, mo_coeff, homo)
3694 CALL cp_fm_release(sv)
3697 CALL make_basis_sm(mo_coeff, nmo, matrix_s(1, 1)%matrix)
3701 NULLIFY (local_preconditioner)
3702 ALLOCATE (local_preconditioner)
3703 CALL init_preconditioner(local_preconditioner, para_env=para_env, &
3704 blacs_env=blacs_env)
3705 DO ispin = 1, nspins
3706 CALL make_preconditioner(local_preconditioner, &
3707 precon_type=ot_precond_full_single_inverse, &
3708 solver_type=ot_precond_solver_default, &
3709 matrix_h=matrix_ks(ispin, 1)%matrix, &
3710 matrix_s=matrix_s(ispin, 1)%matrix, &
3711 convert_precond_to_dbcsr=.true., &
3712 mo_set=mos(ispin), energy_gap=0.2_dp)
3714 CALL get_mo_set(mos(ispin), &
3715 mo_coeff=mo_coeff, &
3716 eigenvalues=eigenvalues, &
3719 CALL ot_eigensolver(matrix_h=matrix_ks(ispin, 1)%matrix, &
3720 matrix_s=matrix_s(1, 1)%matrix, &
3721 matrix_c_fm=mo_coeff, &
3723 eps_gradient=ec_env%eps_default, &
3724 iter_max=max_iter, &
3726 CALL calculate_subspace_eigenvalues(mo_coeff, matrix_ks(ispin, 1)%matrix, &
3727 evals_arg=eigenvalues, do_rotation=.true.)
3730 CALL destroy_preconditioner(local_preconditioner)
3731 DEALLOCATE (local_preconditioner)
3734 CALL copy_fm_to_dbcsr(mos(ispin)%mo_coeff, &
3735 mos(ispin)%mo_coeff_b)
3739 DO ispin = 1, nspins
3740 CALL calculate_density_matrix(mos(ispin), matrix_p(ispin, 1)%matrix)
3742 CALL calculate_w_matrix(mos(ispin), matrix_w(ispin, 1)%matrix)
3746 IF (dft_control%qs_control%do_ls_scf)
THEN
3747 DO ispin = 1, nspins
3748 CALL deallocate_mo_set(mos(ispin))
3750 IF (
ASSOCIATED(qs_env%mos))
THEN
3751 DO ispin = 1,
SIZE(qs_env%mos)
3752 CALL deallocate_mo_set(qs_env%mos(ispin))
3754 DEALLOCATE (qs_env%mos)
3758 CALL timestop(handle)
3760 END SUBROUTINE ec_ot_diag_solver
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)
...
Define the atomic kind types and their sub types.
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)
...
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.
Calculation of the nuclear attraction contribution to the core Hamiltonian <a|erfc|b> :we only calcul...
subroutine, public build_core_ae(matrix_h, matrix_p, force, virial, calculate_forces, use_virial, nder, qs_kind_set, atomic_kind_set, particle_set, sab_orb, sac_ae, nimages, cell_to_index, atcore)
...
Calculation of the local pseudopotential contribution to the core Hamiltonian <a|V(local)|b> = <a|Sum...
subroutine, public build_core_ppl(matrix_h, matrix_p, force, virial, calculate_forces, use_virial, nder, qs_kind_set, atomic_kind_set, particle_set, sab_orb, sac_ppl, nimages, cell_to_index, basis_type, deltar, atcore)
...
Calculation of the non-local pseudopotential contribution to the core Hamiltonian <a|V(non-local)|b> ...
subroutine, public build_core_ppnl(matrix_h, matrix_p, force, virial, calculate_forces, use_virial, nder, qs_kind_set, atomic_kind_set, particle_set, sab_orb, sap_ppnl, eps_ppnl, nimages, cell_to_index, basis_type, deltar, matrix_l, atcore)
...
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_scale(matrix, alpha_scalar)
...
subroutine, public dbcsr_desymmetrize(matrix_a, matrix_b)
...
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_init_p(matrix)
...
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.
subroutine, public copy_fm_to_dbcsr(fm, matrix, keep_sparsity)
Copy a BLACS matrix to a dbcsr 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_column_scale(matrixa, scaling)
scales column i of matrix a with scaling(i)
subroutine, public cp_fm_triangular_invert(matrix_a, uplo_tr)
inverts a triangular matrix
various cholesky decomposition related routines
subroutine, public cp_fm_cholesky_decompose(matrix, n, info_out)
used to replace a symmetric positive def. matrix M with its cholesky decomposition U: M = U^T * U,...
used for collecting some of the diagonalization schemes available for cp_fm_type. cp_fm_power also mo...
subroutine, public choose_eigv_solver(matrix, eigenvectors, eigenvalues, info)
Choose the Eigensolver depending on which library is available ELPA seems to be unstable for small sy...
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_set_all(matrix, alpha, beta)
set all elements of a matrix to the same value, and optionally the diagonal to a different one
subroutine, public cp_fm_init_random(matrix, ncol, start_col)
fills a matrix with random numbers
subroutine, public cp_fm_to_fm_triangular(msource, mtarget, uplo)
copy just a triangular matrix
subroutine, public cp_fm_create(matrix, matrix_struct, name, use_sp)
creates a new full matrix with the given structure
various routines to log and control the output. The idea is that decisions about where to log should ...
recursive integer function, public cp_logger_get_default_unit_nr(logger, local, skip_not_ionode)
asks the default unit number of the given logger. try to use cp_logger_get_unit_nr
type(cp_logger_type) function, pointer, public cp_get_default_logger()
returns the default logger
routines to handle the output, The idea is to remove the decision of wheter to output and what to out...
integer function, public cp_print_key_unit_nr(logger, basis_section, print_key_path, extension, middle_name, local, log_filename, ignore_should_output, file_form, file_position, file_action, file_status, do_backup, on_file, is_new_file, mpi_io, fout)
...
subroutine, public cp_print_key_finished_output(unit_nr, logger, basis_section, print_key_path, local, ignore_should_output, on_file, mpi_io)
should be called after you finish working with a unit obtained with cp_print_key_unit_nr,...
integer, parameter, public cp_p_file
integer function, public cp_print_key_should_output(iteration_info, basis_section, print_key_path, used_print_key, first_time)
returns what should be done with the given property if btest(res,cp_p_store) then the property should...
set of type/routines to handle the storage of results in force_envs
subroutine, public cp_results_erase(results, description, nval)
erase a part of result_list
set of type/routines to handle the storage of results in force_envs
real(kind=dp) function, public cp_unit_from_cp2k(value, unit_str, defaults, power)
converts from the internal cp2k units to the given unit
stores a lists of integer that are local to a processor. The idea is that these integers represent ob...
stores a mapping of 2D info (e.g. matrix) on a 2D processor distribution (i.e. blacs grid) where cpus...
lower level routines for linear scaling SCF
subroutine, public density_matrix_trs4(matrix_p, matrix_ks, matrix_s_sqrt_inv, nelectron, threshold, e_homo, e_lumo, e_mu, dynamic_threshold, matrix_ks_deviation, max_iter_lanczos, eps_lanczos, converged, iounit)
compute the density matrix using a trace-resetting algorithm
subroutine, public ls_scf_init_matrix_s(matrix_s, ls_scf_env)
initialize S matrix related properties (sqrt, inverse...) Might be factored-out since this seems comm...
subroutine, public apply_matrix_preconditioner(matrix, direction, matrix_bs_sqrt, matrix_bs_sqrt_inv)
apply a preconditioner either forward (precondition) inv(sqrt(bs)) * A * inv(sqrt(bs)) backward (rest...
subroutine, public density_matrix_sign(matrix_p, mu, fixed_mu, sign_method, sign_order, matrix_ks, matrix_s, matrix_s_inv, nelectron, threshold, sign_symmetric, submatrix_sign_method, matrix_s_sqrt_inv)
compute the density matrix with a trace that is close to nelectron. take a mu as input,...
subroutine, public density_matrix_tc2(matrix_p, matrix_ks, matrix_s_sqrt_inv, nelectron, threshold, e_homo, e_lumo, non_monotonic, eps_lanczos, max_iter_lanczos, iounit)
compute the density matrix using a non monotonic trace conserving algorithm based on SIAM DOI....
Routines for a linear scaling quickstep SCF run based on the density matrix, with a focus on the inte...
subroutine, public matrix_ls_to_qs(matrix_qs, matrix_ls, ls_mstruct, covariant, keep_sparsity)
second link to QS, copy a LS matrix to QS matrix used to isolate QS style matrices from LS style will...
subroutine, public matrix_ls_create(matrix_ls, matrix_qs, ls_mstruct)
create a matrix for use (and as a template) in ls based on a qs template
subroutine, public matrix_qs_to_ls(matrix_ls, matrix_qs, ls_mstruct, covariant)
first link to QS, copy a QS matrix to LS matrix used to isolate QS style matrices from LS style will ...
Types needed for a linear scaling quickstep SCF run based on the density matrix.
Routines for a linear scaling quickstep SCF run based on the density matrix.
subroutine, public post_scf_sparsities(ls_scf_env)
Report on the sparsities of various interesting matrices.
subroutine, public calculate_w_matrix_ls(matrix_w, ls_scf_env)
Compute matrix_w as needed for the forces.
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.
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.
Routines used for Harris functional Kohn-Sham calculation.
subroutine, public ec_mos_init(qs_env, matrix_s)
Allocate and initiate molecular orbitals environment.
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.
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
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.
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)
...
Define the data structure for the particle information.
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
subroutine, public init_preconditioner(preconditioner_env, para_env, blacs_env)
...
subroutine, public destroy_preconditioner(preconditioner_env)
...
computes preconditioners, and implements methods to apply them currently used in qs_ot
subroutine, public make_preconditioner(preconditioner_env, precon_type, solver_type, matrix_h, matrix_s, matrix_t, mo_set, energy_gap, convert_precond_to_dbcsr, chol_type)
...
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 ...
Routine to return block diagonal density matrix. Blocks correspond to the atomic densities.
subroutine, public calculate_atomic_block_dm(pmatrix, matrix_s, atomic_kind_set, qs_kind_set, nspin, nelectron_spin, ounit, para_env)
returns a block diagonal density matrix. Blocks correspond to the atomic densities.
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.
collects routines that calculate density matrices
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, 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, 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, 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, ecoul_1c, rho0_s_rs, rho0_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)
Get the QUICKSTEP environment.
subroutine, public zero_qs_force(qs_force)
Initialize a Quickstep force data structure.
subroutine, public total_qs_force(force, qs_force, atomic_kind_set)
Get current total force.
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, 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, 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)
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, eps_filter, nderivative)
Calculation of the kinetic energy matrix over Cartesian Gaussian functions.
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(qs_env, vh_rspace, vxc_rspace, vtau_rspace, vadmm_rspace, ehartree, exc, h_stress)
calculate the Kohn-Sham reference potential
collects routines that perform operations directly related to MOs
subroutine, public make_basis_sm(vmatrix, ncol, matrix_s)
returns an S-orthonormal basis v (v^T S v ==1)
Definition and initialisation of the mo data type.
subroutine, public deallocate_mo_set(mo_set)
Deallocate a wavefunction data structure.
subroutine, public get_mo_set(mo_set, maxocc, homo, lfomo, nao, nelectron, n_el_f, nmo, eigenvalues, occupation_numbers, mo_coeff, mo_coeff_b, uniform_occupation, kts, mu, flexible_electron_count)
Get the components of a MO set data structure.
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.
an eigen-space solver for the generalised symmetric eigenvalue problem for sparse matrices,...
subroutine, public ot_eigensolver(matrix_h, matrix_s, matrix_orthogonal_space_fm, matrix_c_fm, preconditioner, eps_gradient, iter_max, size_ortho_space, silent, ot_settings)
...
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)
Calculation of the overlap matrix over Cartesian Gaussian functions.
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...
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)
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, 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)
Initializes solver of linear response equation for energy correction.
Utilities for rtp in combination with admm methods adapted routines from admm_method (author Manuel G...
subroutine, public rtp_admm_calc_rho_aux(qs_env)
Compute the ADMM density matrix in case of rtp (complex MO's)
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, reorder_rs_grid_ranks, skip_load_balance_distributed, soft_valid, basis_type, pw_env_external, sab_orb_external)
...
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.
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.