227#include "./base/base_uses.f90"
235 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'energy_corrections'
256 LOGICAL,
INTENT(IN),
OPTIONAL :: ec_init, calculate_forces
258 CHARACTER(len=*),
PARAMETER :: routinen =
'energy_correction'
260 INTEGER :: handle, unit_nr
261 LOGICAL :: my_calc_forces
268 CALL timeset(routinen, handle)
271 IF (logger%para_env%is_source())
THEN
283 IF (.NOT. ec_env%do_skip)
THEN
285 ec_env%should_update = .true.
286 IF (
PRESENT(ec_init)) ec_env%should_update = ec_init
288 my_calc_forces = .false.
289 IF (
PRESENT(calculate_forces)) my_calc_forces = calculate_forces
291 IF (ec_env%should_update)
THEN
292 ec_env%old_etotal = 0.0_dp
293 ec_env%etotal = 0.0_dp
294 ec_env%eband = 0.0_dp
295 ec_env%ehartree = 0.0_dp
299 ec_env%edispersion = 0.0_dp
300 ec_env%exc_aux_fit = 0.0_dp
302 ec_env%ehartree_1c = 0.0_dp
303 ec_env%exc1_aux_fit = 0.0_dp
307 ec_env%old_etotal = energy%total
311 IF (my_calc_forces)
THEN
312 IF (unit_nr > 0)
THEN
313 WRITE (unit_nr,
'(T2,A,A,A,A,A)')
"!", repeat(
"-", 25), &
314 " Energy Correction Forces ", repeat(
"-", 26),
"!"
316 CALL get_qs_env(qs_env, force=ks_force, virial=virial)
320 IF (unit_nr > 0)
THEN
321 WRITE (unit_nr,
'(T2,A,A,A,A,A)')
"!", repeat(
"-", 29), &
322 " Energy Correction ", repeat(
"-", 29),
"!"
327 CALL energy_correction_low(qs_env, ec_env, my_calc_forces, unit_nr)
330 IF (ec_env%should_update)
THEN
331 energy%nonscf_correction = ec_env%etotal - ec_env%old_etotal
332 energy%total = ec_env%etotal
335 IF (.NOT. my_calc_forces .AND. unit_nr > 0)
THEN
336 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Energy Correction ", energy%nonscf_correction
338 IF (unit_nr > 0)
THEN
339 WRITE (unit_nr,
'(T2,A,A,A)')
"!", repeat(
"-", 77),
"!"
346 IF (unit_nr > 0)
THEN
347 WRITE (unit_nr,
'(T2,A,A,A)')
"!", repeat(
"-", 77),
"!"
348 WRITE (unit_nr,
'(T2,A,A,A,A,A)')
"!", repeat(
"-", 26), &
349 " Skip Energy Correction ", repeat(
"-", 27),
"!"
350 WRITE (unit_nr,
'(T2,A,A,A)')
"!", repeat(
"-", 77),
"!"
355 CALL timestop(handle)
370 SUBROUTINE energy_correction_low(qs_env, ec_env, calculate_forces, unit_nr)
373 LOGICAL,
INTENT(IN) :: calculate_forces
374 INTEGER,
INTENT(IN) :: unit_nr
376 INTEGER :: ispin, nkind, nspins
377 LOGICAL :: debug_f, gapw, gapw_xc
378 REAL(kind=
dp) :: eps_fit, exc
386 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
388 IF (ec_env%should_update)
THEN
389 CALL ec_build_neighborlist(qs_env, ec_env)
395 ec_env%vtau_rspace, &
396 ec_env%vadmm_rspace, &
397 ec_env%ehartree, exc)
401 SELECT CASE (ec_env%energy_functional)
404 CALL ec_build_core_hamiltonian(qs_env, ec_env)
405 CALL ec_build_ks_matrix(qs_env, ec_env)
410 NULLIFY (ec_env%mao_coef)
411 CALL mao_generate_basis(qs_env, ec_env%mao_coef, ref_basis_set=
"HARRIS", molecular=.true., &
412 max_iter=ec_env%mao_max_iter, eps_grad=ec_env%mao_eps_grad, &
413 eps1_mao=ec_env%mao_eps1, iolevel=ec_env%mao_iolevel, unit_nr=unit_nr)
416 CALL ec_ks_solver(qs_env, ec_env)
418 CALL evaluate_ec_core_matrix_traces(qs_env, ec_env)
423 CALL ec_dc_energy(qs_env, ec_env, calculate_forces=.false.)
428 CALL ec_build_ks_matrix(qs_env, ec_env)
435 cpabort(
"unknown energy correction")
439 CALL ec_disp(qs_env, ec_env, calculate_forces=.false.)
442 CALL ec_energy(ec_env, unit_nr)
446 IF (calculate_forces)
THEN
448 debug_f = ec_env%debug_forces .OR. ec_env%debug_stress
450 CALL get_qs_env(qs_env=qs_env, dft_control=dft_control)
451 nspins = dft_control%nspins
452 gapw = dft_control%qs_control%gapw
453 gapw_xc = dft_control%qs_control%gapw_xc
454 IF (gapw .OR. gapw_xc)
THEN
456 qs_kind_set=qs_kind_set, particle_set=particle_set)
457 NULLIFY (oce, sap_oce)
458 CALL get_qs_env(qs_env=qs_env, oce=oce, sap_oce=sap_oce)
461 eps_fit = dft_control%qs_control%gapw_control%eps_fit
467 CALL ec_disp(qs_env, ec_env, calculate_forces=.true.)
469 SELECT CASE (ec_env%energy_functional)
472 CALL ec_build_core_hamiltonian_force(qs_env, ec_env, &
476 CALL ec_build_ks_matrix_force(qs_env, ec_env)
477 IF (ec_env%debug_external)
THEN
478 CALL write_response_interface(qs_env, ec_env)
479 CALL init_response_deriv(qs_env, ec_env)
486 CALL ec_dc_energy(qs_env, ec_env, calculate_forces=.true.)
488 CALL ec_build_core_hamiltonian_force(qs_env, ec_env, &
492 CALL ec_dc_build_ks_matrix_force(qs_env, ec_env)
493 IF (ec_env%debug_external)
THEN
494 CALL write_response_interface(qs_env, ec_env)
495 CALL init_response_deriv(qs_env, ec_env)
501 CALL init_response_deriv(qs_env, ec_env)
504 ec_env%matrix_w(1, 1)%matrix, unit_nr, &
505 ec_env%debug_forces, ec_env%debug_stress)
508 cpabort(
"unknown energy correction")
511 IF (ec_env%do_error)
THEN
512 ALLOCATE (ec_env%cpref(nspins))
514 CALL cp_fm_create(ec_env%cpref(ispin), ec_env%cpmos(ispin)%matrix_struct)
515 CALL cp_fm_to_fm(ec_env%cpmos(ispin), ec_env%cpref(ispin))
525 cpassert(
ASSOCIATED(pw_env))
526 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
527 ALLOCATE (ec_env%rhoz_r(nspins))
529 CALL auxbas_pw_pool%create_pw(ec_env%rhoz_r(ispin))
533 vh_rspace=ec_env%vh_rspace, &
534 vxc_rspace=ec_env%vxc_rspace, &
535 vtau_rspace=ec_env%vtau_rspace, &
536 vadmm_rspace=ec_env%vadmm_rspace, &
537 matrix_hz=ec_env%matrix_hz, &
538 matrix_pz=ec_env%matrix_z, &
539 matrix_pz_admm=ec_env%z_admm, &
540 matrix_wz=ec_env%matrix_wz, &
541 rhopz_r=ec_env%rhoz_r, &
542 zehartree=ec_env%ehartree, &
544 zexc_aux_fit=ec_env%exc_aux_fit, &
545 p_env=ec_env%p_env, &
548 CALL output_response_deriv(qs_env, ec_env, unit_nr)
550 CALL ec_properties(qs_env, ec_env)
552 IF (ec_env%do_error)
THEN
553 CALL response_force_error(qs_env, ec_env, unit_nr)
557 IF (
ASSOCIATED(ec_env%rhoout_r))
THEN
559 CALL auxbas_pw_pool%give_back_pw(ec_env%rhoout_r(ispin))
561 DEALLOCATE (ec_env%rhoout_r)
563 IF (
ASSOCIATED(ec_env%rhoz_r))
THEN
565 CALL auxbas_pw_pool%give_back_pw(ec_env%rhoz_r(ispin))
567 DEALLOCATE (ec_env%rhoz_r)
583 END SUBROUTINE energy_correction_low
591 SUBROUTINE write_response_interface(qs_env, ec_env)
598 NULLIFY (trexio_section)
602 CALL write_trexio(qs_env, trexio_section, ec_env%matrix_hz)
604 END SUBROUTINE write_response_interface
612 SUBROUTINE init_response_deriv(qs_env, ec_env)
622 ALLOCATE (ec_env%rf(3, natom))
625 CALL get_qs_env(qs_env, force=force, virial=virial)
627 CALL get_qs_env(qs_env, atomic_kind_set=atomic_kind_set)
630 IF (virial%pv_availability .AND. (.NOT. virial%pv_numer))
THEN
631 ec_env%rpv = virial%pv_virial
634 END SUBROUTINE init_response_deriv
643 SUBROUTINE output_response_deriv(qs_env, ec_env, unit_nr)
646 INTEGER,
INTENT(IN) :: unit_nr
648 CHARACTER(LEN=default_string_length) :: unit_string
649 INTEGER :: funit, ia, natom
650 REAL(kind=
dp) :: evol, fconv
651 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: ftot
659 IF (
ASSOCIATED(ec_env%rf))
THEN
661 ALLOCATE (ftot(3, natom))
663 CALL get_qs_env(qs_env, force=force, virial=virial, para_env=para_env)
665 CALL get_qs_env(qs_env, atomic_kind_set=atomic_kind_set)
667 ec_env%rf(1:3, 1:natom) = ftot(1:3, 1:natom) - ec_env%rf(1:3, 1:natom)
668 CALL para_env%sum(ec_env%rf)
671 IF (virial%pv_availability .AND. (.NOT. virial%pv_numer))
THEN
672 ec_env%rpv = virial%pv_virial - ec_env%rpv
673 CALL para_env%sum(ec_env%rpv)
675 evol = ec_env%exc + ec_env%exc_aux_fit + 2.0_dp*ec_env%ehartree
676 ec_env%rpv(1, 1) = ec_env%rpv(1, 1) - evol
677 ec_env%rpv(2, 2) = ec_env%rpv(2, 2) - evol
678 ec_env%rpv(3, 3) = ec_env%rpv(3, 3) - evol
681 CALL get_qs_env(qs_env, particle_set=particle_set, cell=cell)
685 IF (unit_nr > 0)
THEN
686 WRITE (unit_nr,
'(/,T2,A)')
"Write EXTERNAL Response Derivative: "//trim(ec_env%exresult_fn)
688 CALL open_file(ec_env%exresult_fn, file_status=
"REPLACE", file_form=
"FORMATTED", &
689 file_action=
"WRITE", unit_number=funit)
690 WRITE (funit,
"(T8,A,T58,A)")
"COORDINATES [Bohr]",
"RESPONSE FORCES [Hartree/Bohr]"
692 WRITE (funit,
"(2(3F15.8,5x))") particle_set(ia)%r(1:3), ec_env%rf(1:3, ia)
695 WRITE (funit,
"(T8,A,T58,A)")
"CELL [Bohr]",
"RESPONSE PRESSURE [GPa]"
697 WRITE (funit,
"(3F15.8,5x,3F15.8)") cell%hmat(ia, 1:3), -fconv*ec_env%rpv(ia, 1:3)
704 END SUBROUTINE output_response_deriv
713 SUBROUTINE evaluate_ec_core_matrix_traces(qs_env, ec_env)
717 CHARACTER(LEN=*),
PARAMETER :: routinen =
'evaluate_ec_core_matrix_traces'
723 CALL timeset(routinen, handle)
726 CALL get_qs_env(qs_env, dft_control=dft_control, energy=energy)
729 CALL calculate_ptrace(ec_env%matrix_h, ec_env%matrix_p, energy%core, dft_control%nspins)
732 CALL calculate_ptrace(ec_env%matrix_t, ec_env%matrix_p, energy%kinetic, dft_control%nspins)
734 CALL timestop(handle)
736 END SUBROUTINE evaluate_ec_core_matrix_traces
749 SUBROUTINE ec_dc_energy(qs_env, ec_env, calculate_forces)
752 LOGICAL,
INTENT(IN) :: calculate_forces
754 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ec_dc_energy'
756 CHARACTER(LEN=default_string_length) :: headline
757 INTEGER :: handle, ispin, nspins
758 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_h, matrix_p, matrix_s, matrix_w
763 CALL timeset(routinen, handle)
765 NULLIFY (dft_control, ks_env, matrix_h, matrix_p, matrix_s, matrix_w, rho)
767 dft_control=dft_control, &
769 matrix_h_kp=matrix_h, &
770 matrix_s_kp=matrix_s, &
771 matrix_w_kp=matrix_w, &
774 nspins = dft_control%nspins
779 matrix_name=
"OVERLAP MATRIX", &
780 basis_type_a=
"HARRIS", &
781 basis_type_b=
"HARRIS", &
782 sab_nl=ec_env%sab_orb)
787 headline =
"CORE HAMILTONIAN MATRIX"
788 ALLOCATE (ec_env%matrix_h(1, 1)%matrix)
789 CALL dbcsr_create(ec_env%matrix_h(1, 1)%matrix, name=trim(headline), &
790 template=matrix_s(1, 1)%matrix, matrix_type=dbcsr_type_symmetric)
792 CALL dbcsr_copy(ec_env%matrix_h(1, 1)%matrix, matrix_h(1, 1)%matrix)
797 headline =
"DENSITY MATRIX"
799 ALLOCATE (ec_env%matrix_p(ispin, 1)%matrix)
800 CALL dbcsr_create(ec_env%matrix_p(ispin, 1)%matrix, name=trim(headline), &
801 template=matrix_s(1, 1)%matrix, matrix_type=dbcsr_type_symmetric)
803 CALL dbcsr_copy(ec_env%matrix_p(ispin, 1)%matrix, matrix_p(ispin, 1)%matrix)
806 IF (calculate_forces)
THEN
811 headline =
"ENERGY-WEIGHTED DENSITY MATRIX"
813 ALLOCATE (ec_env%matrix_w(ispin, 1)%matrix)
814 CALL dbcsr_create(ec_env%matrix_w(ispin, 1)%matrix, name=trim(headline), &
815 template=matrix_s(1, 1)%matrix, matrix_type=dbcsr_type_symmetric)
817 CALL dbcsr_copy(ec_env%matrix_w(ispin, 1)%matrix, matrix_w(ispin, 1)%matrix)
823 ec_env%efield_nuclear = 0.0_dp
824 ec_env%efield_elec = 0.0_dp
827 CALL timestop(handle)
829 END SUBROUTINE ec_dc_energy
840 SUBROUTINE ec_dc_build_ks_matrix_force(qs_env, ec_env)
844 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ec_dc_build_ks_matrix_force'
846 CHARACTER(LEN=default_string_length) :: basis_type, unit_string
847 INTEGER :: handle, i, iounit, ispin, natom, nspins
848 LOGICAL :: debug_forces, debug_stress, do_ec_hfx, &
849 gapw, gapw_xc, use_virial
850 REAL(
dp) :: dummy_real, dummy_real2(2), ehartree, &
851 ehartree_1c, eovrl, exc, exc1, fconv
852 REAL(
dp),
ALLOCATABLE,
DIMENSION(:, :) :: ftot
853 REAL(
dp),
DIMENSION(3) :: fodeb, fodeb2
854 REAL(kind=
dp),
DIMENSION(3, 3) :: h_stress, pv_loc, stdeb, sttot
859 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_s, scrm
860 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_p
874 TYPE(
pw_r3d_rs_type),
DIMENSION(:),
POINTER :: rho_r, v_rspace, v_rspace_in, &
877 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
879 TYPE(
qs_rho_type),
POINTER :: rho, rho1, rho_struct, rho_xc
884 CALL timeset(routinen, handle)
886 debug_forces = ec_env%debug_forces
887 debug_stress = ec_env%debug_stress
890 IF (logger%para_env%is_source())
THEN
896 NULLIFY (atomic_kind_set, cell, dft_control, force, ks_env, &
897 matrix_p, matrix_s, para_env, pw_env, rho, sab_orb, virial)
900 dft_control=dft_control, &
909 cpassert(
ASSOCIATED(pw_env))
911 nspins = dft_control%nspins
912 use_virial = virial%pv_availability .AND. (.NOT. virial%pv_numer)
914 fconv = 1.0e-9_dp*
pascal/cell%deth
915 IF (debug_stress .AND. use_virial)
THEN
916 sttot = virial%pv_virial
920 gapw = dft_control%qs_control%gapw
921 gapw_xc = dft_control%qs_control%gapw_xc
923 cpassert(
ASSOCIATED(rho_xc))
925 IF (gapw .OR. gapw_xc)
THEN
927 cpabort(
"DC-DFT + GAPW + Stress NYA")
934 NULLIFY (hartree_local, local_rho_set)
935 IF (gapw .OR. gapw_xc)
THEN
937 atomic_kind_set=atomic_kind_set, &
938 qs_kind_set=qs_kind_set)
941 qs_kind_set, dft_control, para_env)
944 CALL init_rho0(local_rho_set, qs_env, dft_control%qs_control%gapw_control)
950 CALL get_qs_env(qs_env=qs_env, oce=oce, sab_orb=sab_orb)
952 qs_kind_set, oce, sab_orb, para_env)
956 NULLIFY (auxbas_pw_pool, poisson_env)
958 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool, &
959 poisson_env=poisson_env)
962 CALL auxbas_pw_pool%create_pw(v_hartree_gspace)
963 CALL auxbas_pw_pool%create_pw(rho_tot_gspace)
964 CALL auxbas_pw_pool%create_pw(v_hartree_rspace)
973 h_stress(:, :) = 0.0_dp
975 density=rho_tot_gspace, &
977 vhartree=v_hartree_gspace, &
980 virial%pv_ehartree = virial%pv_ehartree + h_stress/real(para_env%num_pe,
dp)
981 virial%pv_virial = virial%pv_virial + h_stress/real(para_env%num_pe,
dp)
983 IF (debug_stress)
THEN
984 stdeb = fconv*(h_stress/real(para_env%num_pe,
dp))
985 CALL para_env%sum(stdeb)
986 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
995 CALL pw_transfer(v_hartree_gspace, v_hartree_rspace)
996 CALL pw_scale(v_hartree_rspace, v_hartree_rspace%pw_grid%dvol)
1000 ALLOCATE (ec_env%rhoout_r(nspins))
1001 DO ispin = 1, nspins
1002 CALL auxbas_pw_pool%create_pw(ec_env%rhoout_r(ispin))
1003 CALL pw_copy(rho_r(ispin), ec_env%rhoout_r(ispin))
1008 IF (debug_forces) fodeb(1:3) = force(1)%rho_core(1:3, 1)
1009 IF (debug_stress .AND. use_virial) stdeb = virial%pv_ehartree
1010 CALL integrate_v_core_rspace(v_hartree_rspace, qs_env)
1011 IF (debug_forces)
THEN
1012 fodeb(1:3) = force(1)%rho_core(1:3, 1) - fodeb(1:3)
1013 CALL para_env%sum(fodeb)
1014 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Vtot*dncore", fodeb
1016 IF (debug_stress .AND. use_virial)
THEN
1017 stdeb = fconv*(virial%pv_ehartree - stdeb)
1018 CALL para_env%sum(stdeb)
1019 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1025 NULLIFY (v_rspace, v_tau_rspace)
1028 IF (use_virial) virial%pv_calculate = .true.
1032 CALL get_qs_env(qs_env=qs_env, rho_xc=rho_struct)
1034 CALL get_qs_env(qs_env=qs_env, rho=rho_struct)
1036 CALL qs_vxc_create(ks_env=ks_env, rho_struct=rho_struct, xc_section=ec_env%xc_section, &
1037 vxc_rho=v_rspace, vxc_tau=v_tau_rspace, exc=exc, just_energy=.false.)
1039 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
1040 IF (debug_stress .AND. use_virial) stdeb = virial%pv_virial
1045 IF (debug_forces)
THEN
1046 fodeb(1:3) = force(1)%rho_elec(1:3, 1) - fodeb(1:3)
1047 CALL para_env%sum(fodeb)
1048 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Fxc*dw ", fodeb
1050 IF (debug_stress .AND. use_virial)
THEN
1051 stdeb = fconv*(virial%pv_virial - stdeb)
1052 CALL para_env%sum(stdeb)
1053 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1057 IF (.NOT.
ASSOCIATED(v_rspace))
THEN
1058 ALLOCATE (v_rspace(nspins))
1059 DO ispin = 1, nspins
1060 CALL auxbas_pw_pool%create_pw(v_rspace(ispin))
1065 IF (use_virial)
THEN
1066 virial%pv_exc = virial%pv_exc - virial%pv_xc
1067 virial%pv_virial = virial%pv_virial - virial%pv_xc
1074 DO ispin = 1, nspins
1075 ALLOCATE (scrm(ispin)%matrix)
1076 CALL dbcsr_create(scrm(ispin)%matrix, template=ec_env%matrix_ks(ispin, 1)%matrix)
1077 CALL dbcsr_copy(scrm(ispin)%matrix, ec_env%matrix_ks(ispin, 1)%matrix)
1078 CALL dbcsr_set(scrm(ispin)%matrix, 0.0_dp)
1081 pw_grid => v_hartree_rspace%pw_grid
1082 ALLOCATE (v_rspace_in(nspins))
1083 DO ispin = 1, nspins
1084 CALL v_rspace_in(ispin)%create(pw_grid)
1088 DO ispin = 1, nspins
1090 CALL pw_transfer(ec_env%vxc_rspace(ispin), v_rspace_in(ispin))
1091 IF (.NOT. gapw_xc)
THEN
1095 CALL pw_axpy(ec_env%vh_rspace, v_rspace_in(ispin))
1105 IF ((gapw .OR. gapw_xc) .AND. ec_env%do_ec_admm)
THEN
1109 cpabort(
"GAPW HFX ADMM + Energy Correction NYA")
1113 IF (debug_forces) fodeb(1:3) = force(1)%fock_4c(1:3, 1)
1114 IF (debug_forces) fodeb2(1:3) = force(1)%overlap_admm(1:3, 1)
1121 hfx_sections=ec_hfx_sections, &
1122 x_data=ec_env%x_data, &
1124 do_admm=ec_env%do_ec_admm, &
1125 calc_forces=.true., &
1126 reuse_hfx=ec_env%reuse_hfx, &
1127 do_im_time=.false., &
1128 e_ex_from_gw=dummy_real, &
1129 e_admm_from_gw=dummy_real2, &
1132 IF (debug_forces)
THEN
1133 fodeb(1:3) = force(1)%fock_4c(1:3, 1) - fodeb(1:3)
1134 CALL para_env%sum(fodeb)
1135 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: P*hfx_DC ", fodeb
1137 fodeb2(1:3) = force(1)%overlap_admm(1:3, 1) - fodeb2(1:3)
1138 CALL para_env%sum(fodeb2)
1139 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: P*hfx_DC*S ", fodeb2
1141 IF (debug_stress .AND. use_virial)
THEN
1142 stdeb = -1.0_dp*fconv*virial%pv_fock_4c
1143 CALL para_env%sum(stdeb)
1144 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1152 IF (use_virial)
THEN
1153 pv_loc = virial%pv_virial
1156 basis_type =
"HARRIS"
1157 IF (gapw .OR. gapw_xc)
THEN
1158 task_list => ec_env%task_list_soft
1160 task_list => ec_env%task_list
1163 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
1164 IF (debug_stress .AND. use_virial) stdeb = virial%pv_virial
1166 DO ispin = 1, nspins
1168 CALL pw_scale(v_rspace(ispin), v_rspace(ispin)%pw_grid%dvol)
1171 CALL integrate_v_rspace(v_rspace=v_rspace(ispin), &
1173 pmat=matrix_p(ispin, 1), &
1175 calculate_forces=.true., &
1176 basis_type=basis_type, &
1177 task_list_external=task_list)
1179 CALL integrate_v_rspace(v_rspace=v_hartree_rspace, &
1181 pmat=matrix_p(ispin, 1), &
1183 calculate_forces=.true., &
1184 basis_type=basis_type, &
1185 task_list_external=ec_env%task_list)
1187 CALL pw_axpy(v_hartree_rspace, v_rspace(ispin))
1189 CALL integrate_v_rspace(v_rspace=v_rspace(ispin), &
1191 pmat=matrix_p(ispin, 1), &
1193 calculate_forces=.true., &
1194 basis_type=basis_type, &
1195 task_list_external=task_list)
1199 IF (debug_forces)
THEN
1200 fodeb(1:3) = force(1)%rho_elec(1:3, 1) - fodeb(1:3)
1201 CALL para_env%sum(fodeb)
1202 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Pout*dVhxc ", fodeb
1204 IF (debug_stress .AND. use_virial)
THEN
1205 stdeb = fconv*(virial%pv_virial - stdeb)
1206 CALL para_env%sum(stdeb)
1207 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1211 IF (
ASSOCIATED(v_tau_rspace))
THEN
1212 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
1213 IF (debug_stress .AND. use_virial) stdeb = virial%pv_virial
1214 DO ispin = 1, nspins
1215 CALL pw_scale(v_tau_rspace(ispin), v_tau_rspace(ispin)%pw_grid%dvol)
1217 CALL integrate_v_rspace(v_rspace=v_tau_rspace(ispin), &
1219 pmat=matrix_p(ispin, 1), &
1221 calculate_forces=.true., &
1222 compute_tau=.true., &
1223 basis_type=basis_type, &
1224 task_list_external=task_list)
1227 IF (debug_forces)
THEN
1228 fodeb(1:3) = force(1)%rho_elec(1:3, 1) - fodeb(1:3)
1229 CALL para_env%sum(fodeb)
1230 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Pout*dVhxc_tau ", fodeb
1232 IF (debug_stress .AND. use_virial)
THEN
1233 stdeb = fconv*(virial%pv_virial - stdeb)
1234 CALL para_env%sum(stdeb)
1235 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1240 IF (gapw .OR. gapw_xc)
THEN
1243 rho_atom_set_external=local_rho_set%rho_atom_set, &
1244 xc_section_external=ec_env%xc_section)
1247 IF (debug_forces) fodeb(1:3) = force(1)%g0s_Vh_elec(1:3, 1)
1249 calculate_forces=.true., local_rho_set=local_rho_set)
1250 IF (debug_forces)
THEN
1251 fodeb(1:3) = force(1)%g0s_Vh_elec(1:3, 1) - fodeb(1:3)
1252 CALL para_env%sum(fodeb)
1253 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: P*g0s_Vh_elec ", fodeb
1255 ehartree_1c = 0.0_dp
1256 CALL vh_1c_gg_integrals(qs_env, ehartree_1c, hartree_local%ecoul_1c, local_rho_set, &
1257 para_env, tddft=.false., core_2nd=.false.)
1260 IF (gapw .OR. gapw_xc)
THEN
1262 IF (debug_forces) fodeb(1:3) = force(1)%vhxc_atom(1:3, 1)
1264 rho_atom_external=local_rho_set%rho_atom_set)
1265 IF (debug_forces)
THEN
1266 fodeb(1:3) = force(1)%vhxc_atom(1:3, 1) - fodeb(1:3)
1267 CALL para_env%sum(fodeb)
1268 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: P*vhxc_atom ", fodeb
1273 IF (use_virial)
THEN
1274 virial%pv_ehartree = virial%pv_ehartree + (virial%pv_virial - pv_loc)
1293 NULLIFY (ec_env%matrix_hz)
1295 DO ispin = 1, nspins
1296 ALLOCATE (ec_env%matrix_hz(ispin)%matrix)
1297 CALL dbcsr_create(ec_env%matrix_hz(ispin)%matrix, template=matrix_s(1)%matrix)
1298 CALL dbcsr_copy(ec_env%matrix_hz(ispin)%matrix, matrix_s(1)%matrix)
1299 CALL dbcsr_set(ec_env%matrix_hz(ispin)%matrix, 0.0_dp)
1302 DO ispin = 1, nspins
1305 CALL pw_axpy(v_rspace_in(ispin), v_rspace(ispin), -1.0_dp)
1308 DO ispin = 1, nspins
1309 CALL integrate_v_rspace(v_rspace=v_rspace(ispin), &
1310 hmat=ec_env%matrix_hz(ispin), &
1311 pmat=matrix_p(ispin, 1), &
1313 calculate_forces=.false., &
1314 basis_type=basis_type, &
1315 task_list_external=task_list)
1319 IF (dft_control%use_kinetic_energy_density)
THEN
1322 IF (.NOT.
ASSOCIATED(v_tau_rspace))
THEN
1323 ALLOCATE (v_tau_rspace(nspins))
1324 DO ispin = 1, nspins
1325 CALL auxbas_pw_pool%create_pw(v_tau_rspace(ispin))
1326 CALL pw_zero(v_tau_rspace(ispin))
1330 DO ispin = 1, nspins
1332 IF (
ASSOCIATED(ec_env%vtau_rspace))
THEN
1333 CALL pw_axpy(ec_env%vtau_rspace(ispin), v_tau_rspace(ispin), -1.0_dp)
1336 CALL integrate_v_rspace(v_rspace=v_tau_rspace(ispin), &
1337 hmat=ec_env%matrix_hz(ispin), &
1338 pmat=matrix_p(ispin, 1), &
1340 calculate_forces=.false., compute_tau=.true., &
1341 basis_type=basis_type, &
1342 task_list_external=task_list)
1346 IF (gapw .OR. gapw_xc)
THEN
1349 CALL update_ks_atom(qs_env, ec_env%matrix_hz, matrix_p, .false., &
1350 rho_atom_external=local_rho_set%rho_atom_set, kintegral=1.0_dp)
1352 CALL update_ks_atom(qs_env, ec_env%matrix_hz, matrix_p, .false., &
1353 rho_atom_external=ec_env%local_rho_set%rho_atom_set, kintegral=-1.0_dp)
1360 ext_hfx_section=ec_hfx_sections, &
1361 x_data=ec_env%x_data, &
1362 recalc_integrals=.false., &
1363 do_admm=ec_env%do_ec_admm, &
1366 reuse_hfx=ec_env%reuse_hfx)
1369 IF (debug_forces) fodeb(1:3) = force(1)%core_overlap(1:3, 1)
1370 IF (debug_stress .AND. use_virial) stdeb = virial%pv_ecore_overlap
1372 IF (debug_forces)
THEN
1373 fodeb(1:3) = force(1)%core_overlap(1:3, 1) - fodeb(1:3)
1374 CALL para_env%sum(fodeb)
1375 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: CoreOverlap", fodeb
1377 IF (debug_stress .AND. use_virial)
THEN
1378 stdeb = fconv*(stdeb - virial%pv_ecore_overlap)
1379 CALL para_env%sum(stdeb)
1380 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1384 IF (debug_forces)
THEN
1385 CALL get_qs_env(qs_env, natom=natom, atomic_kind_set=atomic_kind_set)
1386 ALLOCATE (ftot(3, natom))
1388 fodeb(1:3) = ftot(1:3, 1)
1390 CALL para_env%sum(fodeb)
1391 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Force Explicit", fodeb
1395 IF (gapw .OR. gapw_xc)
THEN
1403 DO ispin = 1, nspins
1404 CALL auxbas_pw_pool%give_back_pw(v_rspace(ispin))
1405 CALL auxbas_pw_pool%give_back_pw(v_rspace_in(ispin))
1406 IF (
ASSOCIATED(v_tau_rspace))
THEN
1407 CALL auxbas_pw_pool%give_back_pw(v_tau_rspace(ispin))
1411 DEALLOCATE (v_rspace, v_rspace_in)
1412 IF (
ASSOCIATED(v_tau_rspace))
DEALLOCATE (v_tau_rspace)
1414 CALL auxbas_pw_pool%give_back_pw(rho_tot_gspace)
1415 CALL auxbas_pw_pool%give_back_pw(v_hartree_gspace)
1416 CALL auxbas_pw_pool%give_back_pw(v_hartree_rspace)
1420 IF (use_virial)
THEN
1421 IF (qs_env%energy_correction)
THEN
1422 ec_env%ehartree = ehartree
1427 IF (debug_stress .AND. use_virial)
THEN
1429 stdeb = -1.0_dp*fconv*ehartree
1430 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1433 stdeb = -1.0_dp*fconv*exc
1434 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1443 CALL para_env%sum(virdeb%pv_overlap)
1444 CALL para_env%sum(virdeb%pv_ekinetic)
1445 CALL para_env%sum(virdeb%pv_ppl)
1446 CALL para_env%sum(virdeb%pv_ppnl)
1447 CALL para_env%sum(virdeb%pv_ecore_overlap)
1448 CALL para_env%sum(virdeb%pv_ehartree)
1449 CALL para_env%sum(virdeb%pv_exc)
1450 CALL para_env%sum(virdeb%pv_exx)
1451 CALL para_env%sum(virdeb%pv_vdw)
1452 CALL para_env%sum(virdeb%pv_mp2)
1453 CALL para_env%sum(virdeb%pv_nlcc)
1454 CALL para_env%sum(virdeb%pv_gapw)
1455 CALL para_env%sum(virdeb%pv_lrigpw)
1456 CALL para_env%sum(virdeb%pv_virial)
1461 virdeb%pv_ehartree(i, i) = virdeb%pv_ehartree(i, i) - 2.0_dp*ehartree
1462 virdeb%pv_virial(i, i) = virdeb%pv_virial(i, i) - exc &
1464 virdeb%pv_exc(i, i) = virdeb%pv_exc(i, i) - exc
1470 CALL para_env%sum(sttot)
1471 stdeb = fconv*(virdeb%pv_virial - sttot)
1472 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1475 stdeb = fconv*(virdeb%pv_virial)
1476 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1486 CALL timestop(handle)
1488 END SUBROUTINE ec_dc_build_ks_matrix_force
1496 SUBROUTINE ec_disp(qs_env, ec_env, calculate_forces)
1497 TYPE(qs_environment_type),
POINTER :: qs_env
1498 TYPE(energy_correction_type),
POINTER :: ec_env
1499 LOGICAL,
INTENT(IN) :: calculate_forces
1501 REAL(kind=dp) :: edisp, egcp
1504 CALL calculate_dispersion_pairpot(qs_env, ec_env%dispersion_env, edisp, calculate_forces)
1505 IF (.NOT. calculate_forces)
THEN
1506 ec_env%edispersion = ec_env%edispersion + edisp + egcp
1509 END SUBROUTINE ec_disp
1518 SUBROUTINE ec_build_core_hamiltonian(qs_env, ec_env)
1519 TYPE(qs_environment_type),
POINTER :: qs_env
1520 TYPE(energy_correction_type),
POINTER :: ec_env
1522 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ec_build_core_hamiltonian'
1524 CHARACTER(LEN=default_string_length) :: basis_type
1525 INTEGER :: handle, nder, nimages
1526 LOGICAL :: calculate_forces, use_virial
1527 TYPE(atomic_kind_type),
DIMENSION(:),
POINTER :: atomic_kind_set
1528 TYPE(dft_control_type),
POINTER :: dft_control
1529 TYPE(neighbor_list_set_p_type),
DIMENSION(:), &
1530 POINTER :: sab_orb, sac_ae, sac_ppl, sap_ppnl
1531 TYPE(particle_type),
DIMENSION(:),
POINTER :: particle_set
1532 TYPE(qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
1533 TYPE(qs_ks_env_type),
POINTER :: ks_env
1535 CALL timeset(routinen, handle)
1537 NULLIFY (atomic_kind_set, dft_control, ks_env, particle_set, &
1540 CALL get_qs_env(qs_env=qs_env, &
1541 atomic_kind_set=atomic_kind_set, &
1542 dft_control=dft_control, &
1543 particle_set=particle_set, &
1544 qs_kind_set=qs_kind_set, &
1548 nimages = dft_control%nimages
1549 IF (nimages /= 1)
THEN
1550 cpabort(
"K-points for Harris functional not implemented")
1554 IF (dft_control%qs_control%gapw .OR. dft_control%qs_control%gapw_xc)
THEN
1555 cpabort(
"Harris functional for GAPW not implemented")
1559 use_virial = .false.
1560 calculate_forces = .false.
1563 NULLIFY (sab_orb, sac_ae, sac_ppl, sap_ppnl)
1564 sab_orb => ec_env%sab_orb
1565 sac_ae => ec_env%sac_ae
1566 sac_ppl => ec_env%sac_ppl
1567 sap_ppnl => ec_env%sap_ppnl
1569 basis_type =
"HARRIS"
1573 CALL build_overlap_matrix(ks_env, matrixkp_s=ec_env%matrix_s, &
1574 matrix_name=
"OVERLAP MATRIX", &
1575 basis_type_a=basis_type, &
1576 basis_type_b=basis_type, &
1578 CALL build_kinetic_matrix(ks_env, matrixkp_t=ec_env%matrix_t, &
1579 matrix_name=
"KINETIC ENERGY MATRIX", &
1580 basis_type=basis_type, &
1584 CALL dbcsr_allocate_matrix_set(ec_env%matrix_h, 1, 1)
1585 ALLOCATE (ec_env%matrix_h(1, 1)%matrix)
1586 CALL dbcsr_create(ec_env%matrix_h(1, 1)%matrix, template=ec_env%matrix_s(1, 1)%matrix)
1587 CALL cp_dbcsr_alloc_block_from_nbl(ec_env%matrix_h(1, 1)%matrix, sab_orb)
1590 CALL dbcsr_copy(ec_env%matrix_h(1, 1)%matrix, ec_env%matrix_t(1, 1)%matrix, &
1591 keep_sparsity=.true., name=
"CORE HAMILTONIAN MATRIX")
1593 CALL core_matrices(qs_env, ec_env%matrix_h, ec_env%matrix_p, calculate_forces, nder, &
1594 ec_env=ec_env, ec_env_matrices=.true., basis_type=basis_type)
1597 ec_env%efield_nuclear = 0.0_dp
1598 CALL ec_efield_local_operator(qs_env, ec_env, calculate_forces)
1600 CALL timestop(handle)
1602 END SUBROUTINE ec_build_core_hamiltonian
1613 SUBROUTINE ec_build_ks_matrix(qs_env, ec_env)
1614 TYPE(qs_environment_type),
POINTER :: qs_env
1615 TYPE(energy_correction_type),
POINTER :: ec_env
1617 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ec_build_ks_matrix'
1619 CHARACTER(LEN=default_string_length) :: headline
1620 INTEGER :: handle, iounit, ispin, natom, nspins
1621 LOGICAL :: calculate_forces, &
1622 do_adiabatic_rescaling, do_ec_hfx, &
1623 gapw, gapw_xc, hfx_treat_lsd_in_core, &
1625 REAL(dp) :: dummy_real, dummy_real2(2), eexc, eh1c, &
1627 TYPE(admm_type),
POINTER :: admm_env
1628 TYPE(atomic_kind_type),
DIMENSION(:),
POINTER :: atomic_kind_set
1629 TYPE(cp_logger_type),
POINTER :: logger
1630 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: ks_mat, ps_mat
1631 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: rho_ao_kp
1632 TYPE(dft_control_type),
POINTER :: dft_control
1633 TYPE(hartree_local_type),
POINTER :: hartree_local
1634 TYPE(local_rho_type),
POINTER :: local_rho_set_ec
1635 TYPE(mp_para_env_type),
POINTER :: para_env
1636 TYPE(neighbor_list_set_p_type),
DIMENSION(:), &
1638 TYPE(oce_matrix_type),
POINTER :: oce
1639 TYPE(pw_env_type),
POINTER :: pw_env
1640 TYPE(pw_pool_type),
POINTER :: auxbas_pw_pool
1641 TYPE(pw_r3d_rs_type),
DIMENSION(:),
POINTER :: rho_r, tau_r, v_rspace, v_tau_rspace
1642 TYPE(qs_energy_type),
POINTER :: energy
1643 TYPE(qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
1644 TYPE(qs_ks_env_type),
POINTER :: ks_env
1645 TYPE(qs_rho_type),
POINTER :: rho, rho_xc
1646 TYPE(section_vals_type),
POINTER :: adiabatic_rescaling_section, &
1647 ec_hfx_sections, ec_section
1649 CALL timeset(routinen, handle)
1651 logger => cp_get_default_logger()
1652 IF (logger%para_env%is_source())
THEN
1653 iounit = cp_logger_get_default_unit_nr(logger, local=.true.)
1659 NULLIFY (auxbas_pw_pool, dft_control, energy, ks_env, rho, rho_r, tau_r)
1660 CALL get_qs_env(qs_env=qs_env, &
1661 dft_control=dft_control, &
1663 rho=rho, rho_xc=rho_xc)
1664 nspins = dft_control%nspins
1665 calculate_forces = .false.
1666 use_virial = .false.
1668 gapw = dft_control%qs_control%gapw
1669 gapw_xc = dft_control%qs_control%gapw_xc
1672 IF (
ASSOCIATED(ec_env%matrix_ks))
CALL dbcsr_deallocate_matrix_set(ec_env%matrix_ks)
1673 CALL dbcsr_allocate_matrix_set(ec_env%matrix_ks, nspins, 1)
1674 DO ispin = 1, nspins
1675 headline =
"KOHN-SHAM MATRIX"
1676 ALLOCATE (ec_env%matrix_ks(ispin, 1)%matrix)
1677 CALL dbcsr_create(ec_env%matrix_ks(ispin, 1)%matrix, name=trim(headline), &
1678 template=ec_env%matrix_s(1, 1)%matrix, matrix_type=dbcsr_type_symmetric)
1679 CALL cp_dbcsr_alloc_block_from_nbl(ec_env%matrix_ks(ispin, 1)%matrix, ec_env%sab_orb)
1680 CALL dbcsr_set(ec_env%matrix_ks(ispin, 1)%matrix, 0.0_dp)
1684 CALL get_qs_env(qs_env=qs_env, pw_env=pw_env)
1685 cpassert(
ASSOCIATED(pw_env))
1688 ec_section => section_vals_get_subs_vals(qs_env%input,
"DFT%ENERGY_CORRECTION")
1689 ec_hfx_sections => section_vals_get_subs_vals(ec_section,
"XC%HF")
1690 CALL section_vals_get(ec_hfx_sections, explicit=do_ec_hfx)
1695 adiabatic_rescaling_section => section_vals_get_subs_vals(ec_section,
"XC%ADIABATIC_RESCALING")
1696 CALL section_vals_get(adiabatic_rescaling_section, explicit=do_adiabatic_rescaling)
1697 IF (do_adiabatic_rescaling)
THEN
1698 CALL cp_abort(__location__,
"Adiabatic rescaling NYI for energy correction")
1700 CALL section_vals_val_get(ec_hfx_sections,
"TREAT_LSD_IN_CORE", l_val=hfx_treat_lsd_in_core)
1701 IF (hfx_treat_lsd_in_core)
THEN
1702 CALL cp_abort(__location__,
"HFX_TREAT_LSD_IN_CORE NYI for energy correction")
1706 IF (dft_control%do_admm)
THEN
1707 IF (dft_control%do_admm_mo)
THEN
1708 cpassert(.NOT. qs_env%run_rtp)
1709 CALL admm_mo_calc_rho_aux(qs_env)
1710 ELSEIF (dft_control%do_admm_dm)
THEN
1711 CALL admm_dm_calc_rho_aux(qs_env)
1718 CALL get_qs_env(qs_env, energy=energy)
1719 CALL calculate_exx(qs_env=qs_env, &
1721 hfx_sections=ec_hfx_sections, &
1722 x_data=ec_env%x_data, &
1724 do_admm=ec_env%do_ec_admm, &
1725 calc_forces=.false., &
1726 reuse_hfx=ec_env%reuse_hfx, &
1727 do_im_time=.false., &
1728 e_ex_from_gw=dummy_real, &
1729 e_admm_from_gw=dummy_real2, &
1733 ec_env%ex = energy%ex
1735 IF (ec_env%do_ec_admm)
THEN
1736 ec_env%exc_aux_fit = energy%exc_aux_fit + energy%exc
1742 ks_mat => ec_env%matrix_ks(:, 1)
1743 CALL add_exx_to_rhs(rhs=ks_mat, &
1745 ext_hfx_section=ec_hfx_sections, &
1746 x_data=ec_env%x_data, &
1747 recalc_integrals=.false., &
1748 do_admm=ec_env%do_ec_admm, &
1751 reuse_hfx=ec_env%reuse_hfx)
1756 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
1757 NULLIFY (v_rspace, v_tau_rspace)
1758 IF (dft_control%qs_control%gapw_xc)
THEN
1759 CALL qs_vxc_create(ks_env=ks_env, rho_struct=rho_xc, xc_section=ec_env%xc_section, &
1760 vxc_rho=v_rspace, vxc_tau=v_tau_rspace, exc=eexc, just_energy=.false.)
1762 CALL qs_vxc_create(ks_env=ks_env, rho_struct=rho, xc_section=ec_env%xc_section, &
1763 vxc_rho=v_rspace, vxc_tau=v_tau_rspace, exc=eexc, just_energy=.false.)
1766 IF (.NOT.
ASSOCIATED(v_rspace))
THEN
1767 ALLOCATE (v_rspace(nspins))
1768 DO ispin = 1, nspins
1769 CALL auxbas_pw_pool%create_pw(v_rspace(ispin))
1770 CALL pw_zero(v_rspace(ispin))
1775 CALL qs_rho_get(rho, rho_r=rho_r)
1776 IF (
ASSOCIATED(v_tau_rspace))
THEN
1777 CALL qs_rho_get(rho, tau_r=tau_r)
1779 DO ispin = 1, nspins
1781 CALL pw_scale(v_rspace(ispin), v_rspace(ispin)%pw_grid%dvol)
1782 CALL pw_axpy(ec_env%vh_rspace, v_rspace(ispin))
1784 CALL integrate_v_rspace(v_rspace=v_rspace(ispin), &
1785 hmat=ec_env%matrix_ks(ispin, 1), &
1787 calculate_forces=.false., &
1788 basis_type=
"HARRIS", &
1789 task_list_external=ec_env%task_list)
1791 IF (
ASSOCIATED(v_tau_rspace))
THEN
1793 CALL pw_scale(v_tau_rspace(ispin), v_tau_rspace(ispin)%pw_grid%dvol)
1794 CALL integrate_v_rspace(v_rspace=v_tau_rspace(ispin), &
1795 hmat=ec_env%matrix_ks(ispin, 1), &
1797 calculate_forces=.false., &
1798 compute_tau=.true., &
1799 basis_type=
"HARRIS", &
1800 task_list_external=ec_env%task_list)
1804 evhxc = evhxc + pw_integral_ab(rho_r(ispin), v_rspace(ispin))/ &
1805 v_rspace(1)%pw_grid%dvol
1806 IF (
ASSOCIATED(v_tau_rspace))
THEN
1807 evhxc = evhxc + pw_integral_ab(tau_r(ispin), v_tau_rspace(ispin))/ &
1808 v_tau_rspace(ispin)%pw_grid%dvol
1813 IF (gapw .OR. gapw_xc)
THEN
1815 IF (ec_env%basis_inconsistent)
THEN
1816 cpabort(
"Energy corrction [GAPW] only with BASIS=ORBITAL possible")
1819 NULLIFY (hartree_local, local_rho_set_ec)
1820 CALL get_qs_env(qs_env, para_env=para_env, &
1821 atomic_kind_set=atomic_kind_set, &
1822 qs_kind_set=qs_kind_set)
1823 CALL local_rho_set_create(local_rho_set_ec)
1824 CALL allocate_rho_atom_internals(local_rho_set_ec%rho_atom_set, atomic_kind_set, &
1825 qs_kind_set, dft_control, para_env)
1827 CALL get_qs_env(qs_env, natom=natom)
1828 CALL init_rho0(local_rho_set_ec, qs_env, dft_control%qs_control%gapw_control)
1829 CALL rho0_s_grid_create(pw_env, local_rho_set_ec%rho0_mpole)
1830 CALL hartree_local_create(hartree_local)
1831 CALL init_coulomb_local(hartree_local, natom)
1834 CALL get_qs_env(qs_env=qs_env, oce=oce, sab_orb=sab)
1835 CALL qs_rho_get(rho, rho_ao_kp=rho_ao_kp)
1836 CALL calculate_rho_atom_coeff(qs_env, rho_ao_kp, local_rho_set_ec%rho_atom_set, &
1837 qs_kind_set, oce, sab, para_env)
1838 CALL prepare_gapw_den(qs_env, local_rho_set_ec, do_rho0=gapw)
1840 CALL calculate_vxc_atom(qs_env, .false., exc1=exc1, xc_section_external=ec_env%xc_section, &
1841 rho_atom_set_external=local_rho_set_ec%rho_atom_set)
1845 CALL vh_1c_gg_integrals(qs_env, eh1c, hartree_local%ecoul_1c, local_rho_set_ec, para_env, .false.)
1846 CALL integrate_vhg0_rspace(qs_env, ec_env%vh_rspace, para_env, calculate_forces=.false., &
1847 local_rho_set=local_rho_set_ec)
1848 ec_env%ehartree_1c = eh1c
1850 IF (dft_control%do_admm)
THEN
1851 CALL get_qs_env(qs_env, admm_env=admm_env)
1852 IF (admm_env%aux_exch_func /= do_admm_aux_exch_func_none)
THEN
1854 cpabort(
"GAPW HFX ADMM + Energy Correction NYA")
1858 ks_mat => ec_env%matrix_ks(:, 1)
1859 ps_mat => ec_env%matrix_p(:, 1)
1860 CALL update_ks_atom(qs_env, ks_mat, ps_mat, forces=.false., &
1861 rho_atom_external=local_rho_set_ec%rho_atom_set)
1863 CALL local_rho_set_release(local_rho_set_ec)
1865 CALL hartree_local_release(hartree_local)
1871 DO ispin = 1, nspins
1872 CALL auxbas_pw_pool%give_back_pw(v_rspace(ispin))
1873 IF (
ASSOCIATED(v_tau_rspace))
THEN
1874 CALL auxbas_pw_pool%give_back_pw(v_tau_rspace(ispin))
1877 DEALLOCATE (v_rspace)
1878 IF (
ASSOCIATED(v_tau_rspace))
DEALLOCATE (v_tau_rspace)
1885 DO ispin = 1, nspins
1886 CALL dbcsr_add(ec_env%matrix_ks(ispin, 1)%matrix, ec_env%matrix_h(1, 1)%matrix, &
1887 alpha_scalar=1.0_dp, beta_scalar=1.0_dp)
1888 CALL dbcsr_filter(ec_env%matrix_ks(ispin, 1)%matrix, &
1889 dft_control%qs_control%eps_filter_matrix)
1892 CALL timestop(handle)
1894 END SUBROUTINE ec_build_ks_matrix
1906 SUBROUTINE ec_build_core_hamiltonian_force(qs_env, ec_env, matrix_p, matrix_s, matrix_w)
1907 TYPE(qs_environment_type),
POINTER :: qs_env
1908 TYPE(energy_correction_type),
POINTER :: ec_env
1909 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_p, matrix_s, matrix_w
1911 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ec_build_core_hamiltonian_force'
1913 CHARACTER(LEN=default_string_length) :: basis_type
1914 INTEGER :: handle, iounit, nder, nimages
1915 LOGICAL :: calculate_forces, debug_forces, &
1916 debug_stress, use_virial
1917 REAL(kind=dp) :: fconv
1918 REAL(kind=dp),
DIMENSION(3) :: fodeb
1919 REAL(kind=dp),
DIMENSION(3, 3) :: stdeb, sttot
1920 TYPE(cell_type),
POINTER :: cell
1921 TYPE(cp_logger_type),
POINTER :: logger
1922 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: scrm
1923 TYPE(dft_control_type),
POINTER :: dft_control
1924 TYPE(mp_para_env_type),
POINTER :: para_env
1925 TYPE(neighbor_list_set_p_type),
DIMENSION(:), &
1927 TYPE(qs_force_type),
DIMENSION(:),
POINTER :: force
1928 TYPE(qs_ks_env_type),
POINTER :: ks_env
1929 TYPE(virial_type),
POINTER :: virial
1931 CALL timeset(routinen, handle)
1933 debug_forces = ec_env%debug_forces
1934 debug_stress = ec_env%debug_stress
1936 logger => cp_get_default_logger()
1937 IF (logger%para_env%is_source())
THEN
1938 iounit = cp_logger_get_default_unit_nr(logger, local=.true.)
1943 calculate_forces = .true.
1945 basis_type =
"HARRIS"
1948 NULLIFY (cell, dft_control, force, ks_env, para_env, virial)
1949 CALL get_qs_env(qs_env=qs_env, &
1951 dft_control=dft_control, &
1954 para_env=para_env, &
1956 nimages = dft_control%nimages
1957 IF (nimages /= 1)
THEN
1958 cpabort(
"K-points for Harris functional not implemented")
1961 IF (dft_control%qs_control%gapw .OR. dft_control%qs_control%gapw_xc)
THEN
1962 IF (ec_env%energy_functional == ec_functional_harris)
THEN
1963 cpabort(
"Harris functional for GAPW not implemented")
1968 use_virial = virial%pv_availability .AND. (.NOT. virial%pv_numer)
1970 fconv = 1.0e-9_dp*pascal/cell%deth
1971 IF (debug_stress .AND. use_virial)
THEN
1972 sttot = virial%pv_virial
1976 sab_orb => ec_env%sab_orb
1980 CALL dbcsr_allocate_matrix_set(scrm, 1, 1)
1981 ALLOCATE (scrm(1, 1)%matrix)
1982 CALL dbcsr_create(scrm(1, 1)%matrix, template=matrix_s(1, 1)%matrix)
1983 CALL cp_dbcsr_alloc_block_from_nbl(scrm(1, 1)%matrix, sab_orb)
1986 IF (
SIZE(matrix_p, 1) == 2)
THEN
1987 CALL dbcsr_add(matrix_w(1, 1)%matrix, matrix_w(2, 1)%matrix, &
1988 alpha_scalar=1.0_dp, beta_scalar=1.0_dp)
1992 IF (debug_forces) fodeb(1:3) = force(1)%overlap(1:3, 1)
1993 IF (debug_stress .AND. use_virial) stdeb = virial%pv_overlap
1994 CALL build_overlap_matrix(ks_env, matrixkp_s=scrm, &
1995 matrix_name=
"OVERLAP MATRIX", &
1996 basis_type_a=basis_type, &
1997 basis_type_b=basis_type, &
1998 sab_nl=sab_orb, calculate_forces=.true., &
1999 matrixkp_p=matrix_w)
2001 IF (debug_forces)
THEN
2002 fodeb(1:3) = force(1)%overlap(1:3, 1) - fodeb(1:3)
2003 CALL para_env%sum(fodeb)
2004 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Wout*dS ", fodeb
2006 IF (debug_stress .AND. use_virial)
THEN
2007 stdeb = fconv*(virial%pv_overlap - stdeb)
2008 CALL para_env%sum(stdeb)
2009 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2010 'STRESS| Wout*dS', one_third_sum_diag(stdeb), det_3x3(stdeb)
2013 CALL kinetic_energy_matrix(qs_env, matrixkp_t=scrm, matrix_p=matrix_p, &
2014 calculate_forces=.true., &
2016 basis_type=basis_type, &
2017 debug_forces=debug_forces, debug_stress=debug_stress)
2019 CALL core_matrices(qs_env, scrm, matrix_p, calculate_forces, nder, &
2020 ec_env=ec_env, ec_env_matrices=.false., basis_type=basis_type, &
2021 debug_forces=debug_forces, debug_stress=debug_stress)
2024 ec_env%efield_nuclear = 0.0_dp
2025 IF (calculate_forces .AND. debug_forces) fodeb(1:3) = force(1)%efield(1:3, 1)
2026 CALL ec_efield_local_operator(qs_env, ec_env, calculate_forces)
2027 IF (calculate_forces .AND. debug_forces)
THEN
2028 fodeb(1:3) = force(1)%efield(1:3, 1) - fodeb(1:3)
2029 CALL para_env%sum(fodeb)
2030 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Pout*dEfield", fodeb
2032 IF (debug_stress .AND. use_virial)
THEN
2033 stdeb = fconv*(virial%pv_virial - sttot)
2034 CALL para_env%sum(stdeb)
2035 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2036 'STRESS| Stress Pout*dHcore ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2037 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))")
' '
2041 CALL dbcsr_deallocate_matrix_set(scrm)
2043 CALL timestop(handle)
2045 END SUBROUTINE ec_build_core_hamiltonian_force
2056 SUBROUTINE ec_build_ks_matrix_force(qs_env, ec_env)
2057 TYPE(qs_environment_type),
POINTER :: qs_env
2058 TYPE(energy_correction_type),
POINTER :: ec_env
2060 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ec_build_ks_matrix_force'
2062 CHARACTER(LEN=default_string_length) :: unit_string
2063 INTEGER :: handle, i, iounit, ispin, natom, nspins
2064 LOGICAL :: debug_forces, debug_stress, do_ec_hfx, &
2066 REAL(dp) :: dehartree, dummy_real, dummy_real2(2), &
2067 eexc, ehartree, eovrl, exc, fconv
2068 REAL(dp),
ALLOCATABLE,
DIMENSION(:, :) :: ftot
2069 REAL(dp),
DIMENSION(3) :: fodeb
2070 REAL(kind=dp),
DIMENSION(3, 3) :: h_stress, pv_loc, stdeb, sttot
2071 TYPE(atomic_kind_type),
DIMENSION(:),
POINTER :: atomic_kind_set
2072 TYPE(cell_type),
POINTER :: cell
2073 TYPE(cp_logger_type),
POINTER :: logger
2074 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_ks, scrm
2075 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_p, matrix_s
2076 TYPE(dft_control_type),
POINTER :: dft_control
2077 TYPE(mp_para_env_type),
POINTER :: para_env
2078 TYPE(neighbor_list_set_p_type),
DIMENSION(:), &
2080 TYPE(pw_c1d_gs_type) :: rho_tot_gspace, rhodn_tot_gspace, &
2082 TYPE(pw_c1d_gs_type),
DIMENSION(:),
POINTER :: rho_g, rhoout_g
2083 TYPE(pw_c1d_gs_type),
POINTER :: rho_core
2084 TYPE(pw_env_type),
POINTER :: pw_env
2085 TYPE(pw_poisson_type),
POINTER :: poisson_env
2086 TYPE(pw_pool_type),
POINTER :: auxbas_pw_pool
2087 TYPE(pw_r3d_rs_type) :: dv_hartree_rspace, v_hartree_rspace, &
2089 TYPE(pw_r3d_rs_type),
DIMENSION(:),
POINTER :: rho_r, rhoout_r, tau_r, tauout_r, &
2090 v_rspace, v_tau_rspace, v_xc, v_xc_tau
2091 TYPE(qs_force_type),
DIMENSION(:),
POINTER :: force
2092 TYPE(qs_ks_env_type),
POINTER :: ks_env
2093 TYPE(qs_rho_type),
POINTER :: rho
2094 TYPE(section_vals_type),
POINTER :: ec_hfx_sections, xc_section
2095 TYPE(virial_type),
POINTER :: virial
2097 CALL timeset(routinen, handle)
2099 debug_forces = ec_env%debug_forces
2100 debug_stress = ec_env%debug_stress
2102 logger => cp_get_default_logger()
2103 IF (logger%para_env%is_source())
THEN
2104 iounit = cp_logger_get_default_unit_nr(logger, local=.true.)
2110 NULLIFY (atomic_kind_set, cell, dft_control, force, ks_env, &
2111 matrix_ks, matrix_p, matrix_s, para_env, rho, rho_core, &
2112 rho_g, rho_r, sab_orb, tau_r, virial)
2113 CALL get_qs_env(qs_env=qs_env, &
2115 dft_control=dft_control, &
2118 matrix_ks=matrix_ks, &
2119 para_env=para_env, &
2124 nspins = dft_control%nspins
2125 use_virial = virial%pv_availability .AND. (.NOT. virial%pv_numer)
2129 fconv = cp_unit_from_cp2k(1.0_dp/cell%deth, trim(unit_string))
2131 IF (debug_stress .AND. use_virial)
THEN
2132 sttot = virial%pv_virial
2136 CALL get_qs_env(qs_env=qs_env, pw_env=pw_env)
2137 cpassert(
ASSOCIATED(pw_env))
2139 NULLIFY (auxbas_pw_pool, poisson_env)
2141 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool, &
2142 poisson_env=poisson_env)
2145 CALL auxbas_pw_pool%create_pw(v_hartree_gspace)
2146 CALL auxbas_pw_pool%create_pw(rhodn_tot_gspace)
2147 CALL auxbas_pw_pool%create_pw(v_hartree_rspace)
2149 CALL pw_transfer(ec_env%vh_rspace, v_hartree_rspace)
2154 CALL qs_rho_get(rho, rho_r=rho_r, rho_g=rho_g, tau_r=tau_r)
2155 NULLIFY (rhoout_r, rhoout_g)
2156 ALLOCATE (rhoout_r(nspins), rhoout_g(nspins))
2157 DO ispin = 1, nspins
2158 CALL auxbas_pw_pool%create_pw(rhoout_r(ispin))
2159 CALL auxbas_pw_pool%create_pw(rhoout_g(ispin))
2161 CALL auxbas_pw_pool%create_pw(dv_hartree_rspace)
2162 CALL auxbas_pw_pool%create_pw(vtot_rspace)
2164 CALL pw_zero(rhodn_tot_gspace)
2165 DO ispin = 1, nspins
2166 CALL calculate_rho_elec(ks_env=ks_env, matrix_p=ec_env%matrix_p(ispin, 1)%matrix, &
2167 rho=rhoout_r(ispin), &
2168 rho_gspace=rhoout_g(ispin), &
2169 basis_type=
"HARRIS", &
2170 task_list_external=ec_env%task_list)
2174 ALLOCATE (ec_env%rhoout_r(nspins))
2175 DO ispin = 1, nspins
2176 CALL auxbas_pw_pool%create_pw(ec_env%rhoout_r(ispin))
2177 CALL pw_copy(rhoout_r(ispin), ec_env%rhoout_r(ispin))
2181 IF (dft_control%use_kinetic_energy_density)
THEN
2183 TYPE(pw_c1d_gs_type) :: tauout_g
2184 ALLOCATE (tauout_r(nspins))
2185 DO ispin = 1, nspins
2186 CALL auxbas_pw_pool%create_pw(tauout_r(ispin))
2188 CALL auxbas_pw_pool%create_pw(tauout_g)
2190 DO ispin = 1, nspins
2191 CALL calculate_rho_elec(ks_env=ks_env, matrix_p=ec_env%matrix_p(ispin, 1)%matrix, &
2192 rho=tauout_r(ispin), &
2193 rho_gspace=tauout_g, &
2194 compute_tau=.true., &
2195 basis_type=
"HARRIS", &
2196 task_list_external=ec_env%task_list)
2199 CALL auxbas_pw_pool%give_back_pw(tauout_g)
2203 IF (use_virial)
THEN
2206 CALL auxbas_pw_pool%create_pw(rho_tot_gspace)
2209 CALL calc_rho_tot_gspace(rho_tot_gspace, qs_env, rho)
2212 CALL get_qs_env(qs_env=qs_env, rho_core=rho_core)
2213 CALL pw_copy(rho_core, rhodn_tot_gspace)
2214 DO ispin = 1, dft_control%nspins
2215 CALL pw_axpy(rhoout_g(ispin), rhodn_tot_gspace)
2219 h_stress(:, :) = 0.0_dp
2220 CALL pw_poisson_solve(poisson_env, &
2221 density=rho_tot_gspace, &
2222 ehartree=ehartree, &
2223 vhartree=v_hartree_gspace, &
2224 h_stress=h_stress, &
2225 aux_density=rhodn_tot_gspace)
2227 virial%pv_ehartree = virial%pv_ehartree + h_stress/real(para_env%num_pe, dp)
2228 virial%pv_virial = virial%pv_virial + h_stress/real(para_env%num_pe, dp)
2230 IF (debug_stress)
THEN
2231 stdeb = fconv*(h_stress/real(para_env%num_pe, dp))
2232 CALL para_env%sum(stdeb)
2233 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2234 'STRESS| GREEN 1st v_H[n_in]*n_out ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2238 virial%pv_calculate = .true.
2240 NULLIFY (v_rspace, v_tau_rspace)
2241 CALL qs_vxc_create(ks_env=ks_env, rho_struct=rho, xc_section=ec_env%xc_section, &
2242 vxc_rho=v_rspace, vxc_tau=v_tau_rspace, exc=exc, just_energy=.false.)
2245 virial%pv_exc = virial%pv_exc - virial%pv_xc
2246 virial%pv_virial = virial%pv_virial - virial%pv_xc
2248 IF (debug_stress)
THEN
2249 stdeb = -1.0_dp*fconv*virial%pv_xc
2250 CALL para_env%sum(stdeb)
2251 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2252 'STRESS| GGA 1st E_xc[Pin] ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2255 IF (
ASSOCIATED(v_rspace))
THEN
2256 DO ispin = 1, nspins
2257 CALL auxbas_pw_pool%give_back_pw(v_rspace(ispin))
2259 DEALLOCATE (v_rspace)
2261 IF (
ASSOCIATED(v_tau_rspace))
THEN
2262 DO ispin = 1, nspins
2263 CALL auxbas_pw_pool%give_back_pw(v_tau_rspace(ispin))
2265 DEALLOCATE (v_tau_rspace)
2267 CALL pw_zero(rhodn_tot_gspace)
2272 DO ispin = 1, nspins
2273 CALL pw_axpy(rho_r(ispin), rhoout_r(ispin), -1.0_dp)
2274 CALL pw_axpy(rho_g(ispin), rhoout_g(ispin), -1.0_dp)
2275 CALL pw_axpy(rhoout_g(ispin), rhodn_tot_gspace)
2276 IF (dft_control%use_kinetic_energy_density)
CALL pw_axpy(tau_r(ispin), tauout_r(ispin), -1.0_dp)
2280 IF (use_virial)
THEN
2283 h_stress(:, :) = 0.0_dp
2284 CALL pw_poisson_solve(poisson_env, &
2285 density=rhodn_tot_gspace, &
2286 ehartree=dehartree, &
2287 vhartree=v_hartree_gspace, &
2288 h_stress=h_stress, &
2289 aux_density=rho_tot_gspace)
2291 CALL auxbas_pw_pool%give_back_pw(rho_tot_gspace)
2293 virial%pv_ehartree = virial%pv_ehartree + h_stress/real(para_env%num_pe, dp)
2294 virial%pv_virial = virial%pv_virial + h_stress/real(para_env%num_pe, dp)
2296 IF (debug_stress)
THEN
2297 stdeb = fconv*(h_stress/real(para_env%num_pe, dp))
2298 CALL para_env%sum(stdeb)
2299 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2300 'STRESS| GREEN 2nd V_H[dP]*n_in ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2305 CALL pw_poisson_solve(poisson_env, rhodn_tot_gspace, dehartree, &
2309 CALL pw_transfer(v_hartree_gspace, dv_hartree_rspace)
2310 CALL pw_scale(dv_hartree_rspace, dv_hartree_rspace%pw_grid%dvol)
2313 CALL pw_transfer(v_hartree_rspace, vtot_rspace)
2314 CALL pw_axpy(dv_hartree_rspace, vtot_rspace)
2315 IF (debug_forces) fodeb(1:3) = force(1)%rho_core(1:3, 1)
2316 IF (debug_stress .AND. use_virial) stdeb = virial%pv_ehartree
2317 CALL integrate_v_core_rspace(vtot_rspace, qs_env)
2318 IF (debug_forces)
THEN
2319 fodeb(1:3) = force(1)%rho_core(1:3, 1) - fodeb(1:3)
2320 CALL para_env%sum(fodeb)
2321 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Vtot*dncore", fodeb
2323 IF (debug_stress .AND. use_virial)
THEN
2324 stdeb = fconv*(virial%pv_ehartree - stdeb)
2325 CALL para_env%sum(stdeb)
2326 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2327 'STRESS| Vtot*dncore', one_third_sum_diag(stdeb), det_3x3(stdeb)
2333 xc_section => ec_env%xc_section
2335 IF (use_virial) virial%pv_xc = 0.0_dp
2336 NULLIFY (v_xc, v_xc_tau)
2337 CALL create_kernel(qs_env, &
2344 xc_section=xc_section, &
2345 compute_virial=use_virial, &
2346 virial_xc=virial%pv_xc)
2348 IF (use_virial)
THEN
2350 virial%pv_exc = virial%pv_exc + virial%pv_xc
2351 virial%pv_virial = virial%pv_virial + virial%pv_xc
2353 IF (debug_stress .AND. use_virial)
THEN
2354 stdeb = 1.0_dp*fconv*virial%pv_xc
2355 CALL para_env%sum(stdeb)
2356 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2357 'STRESS| GGA 2nd f_Hxc[dP]*Pin ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2360 CALL get_qs_env(qs_env=qs_env, rho=rho, matrix_s_kp=matrix_s)
2361 NULLIFY (ec_env%matrix_hz)
2362 CALL dbcsr_allocate_matrix_set(ec_env%matrix_hz, nspins)
2363 DO ispin = 1, nspins
2364 ALLOCATE (ec_env%matrix_hz(ispin)%matrix)
2365 CALL dbcsr_create(ec_env%matrix_hz(ispin)%matrix, template=matrix_s(1, 1)%matrix)
2366 CALL dbcsr_copy(ec_env%matrix_hz(ispin)%matrix, matrix_s(1, 1)%matrix)
2367 CALL dbcsr_set(ec_env%matrix_hz(ispin)%matrix, 0.0_dp)
2369 CALL qs_rho_get(rho, rho_ao_kp=matrix_p)
2371 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
2372 IF (debug_stress .AND. use_virial) stdeb = virial%pv_virial
2375 IF (use_virial)
THEN
2376 pv_loc = virial%pv_virial
2379 DO ispin = 1, nspins
2380 CALL pw_scale(v_xc(ispin), v_xc(ispin)%pw_grid%dvol)
2381 CALL pw_axpy(dv_hartree_rspace, v_xc(ispin))
2382 CALL integrate_v_rspace(v_rspace=v_xc(ispin), &
2383 hmat=ec_env%matrix_hz(ispin), &
2384 pmat=matrix_p(ispin, 1), &
2386 calculate_forces=.true.)
2389 IF (debug_forces)
THEN
2390 fodeb(1:3) = force(1)%rho_elec(1:3, 1) - fodeb(1:3)
2391 CALL para_env%sum(fodeb)
2392 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Pin*dKdrho", fodeb
2394 IF (debug_stress .AND. use_virial)
THEN
2395 stdeb = fconv*(virial%pv_virial - stdeb)
2396 CALL para_env%sum(stdeb)
2397 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2398 'STRESS| INT 2nd f_Hxc[dP]*Pin ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2401 IF (
ASSOCIATED(v_xc_tau))
THEN
2402 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
2403 IF (debug_stress .AND. use_virial) stdeb = virial%pv_virial
2405 DO ispin = 1, nspins
2406 CALL pw_scale(v_xc_tau(ispin), v_xc_tau(ispin)%pw_grid%dvol)
2407 CALL integrate_v_rspace(v_rspace=v_xc_tau(ispin), &
2408 hmat=ec_env%matrix_hz(ispin), &
2409 pmat=matrix_p(ispin, 1), &
2411 compute_tau=.true., &
2412 calculate_forces=.true.)
2415 IF (debug_forces)
THEN
2416 fodeb(1:3) = force(1)%rho_elec(1:3, 1) - fodeb(1:3)
2417 CALL para_env%sum(fodeb)
2418 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Pin*dKtaudtau", fodeb
2420 IF (debug_stress .AND. use_virial)
THEN
2421 stdeb = fconv*(virial%pv_virial - stdeb)
2422 CALL para_env%sum(stdeb)
2423 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2424 'STRESS| INT 2nd f_xctau[dP]*Pin ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2428 IF (use_virial)
THEN
2429 virial%pv_ehartree = virial%pv_ehartree + (virial%pv_virial - pv_loc)
2434 CALL dbcsr_allocate_matrix_set(scrm, nspins)
2435 DO ispin = 1, nspins
2436 ALLOCATE (scrm(ispin)%matrix)
2437 CALL dbcsr_create(scrm(ispin)%matrix, template=ec_env%matrix_ks(ispin, 1)%matrix)
2438 CALL dbcsr_copy(scrm(ispin)%matrix, ec_env%matrix_ks(ispin, 1)%matrix)
2439 CALL dbcsr_set(scrm(ispin)%matrix, 0.0_dp)
2443 NULLIFY (v_rspace, v_tau_rspace)
2445 CALL qs_vxc_create(ks_env=ks_env, rho_struct=rho, xc_section=ec_env%xc_section, &
2446 vxc_rho=v_rspace, vxc_tau=v_tau_rspace, exc=eexc, just_energy=.false.)
2448 IF (use_virial)
THEN
2450 IF (
ASSOCIATED(v_rspace))
THEN
2451 DO ispin = 1, nspins
2453 eexc = eexc + pw_integral_ab(rhoout_r(ispin), v_rspace(ispin))
2456 IF (
ASSOCIATED(v_tau_rspace))
THEN
2457 DO ispin = 1, nspins
2459 eexc = eexc + pw_integral_ab(tauout_r(ispin), v_tau_rspace(ispin))
2464 IF (.NOT.
ASSOCIATED(v_rspace))
THEN
2465 ALLOCATE (v_rspace(nspins))
2466 DO ispin = 1, nspins
2467 CALL auxbas_pw_pool%create_pw(v_rspace(ispin))
2468 CALL pw_zero(v_rspace(ispin))
2474 IF (use_virial)
THEN
2475 pv_loc = virial%pv_virial
2478 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
2479 IF (debug_stress .AND. use_virial) stdeb = virial%pv_virial
2480 DO ispin = 1, nspins
2482 CALL pw_scale(v_rspace(ispin), v_rspace(ispin)%pw_grid%dvol)
2483 CALL pw_axpy(v_hartree_rspace, v_rspace(ispin))
2485 CALL integrate_v_rspace(v_rspace=v_rspace(ispin), &
2487 pmat=ec_env%matrix_p(ispin, 1), &
2489 calculate_forces=.true., &
2490 basis_type=
"HARRIS", &
2491 task_list_external=ec_env%task_list)
2494 IF (debug_forces)
THEN
2495 fodeb(1:3) = force(1)%rho_elec(1:3, 1) - fodeb(1:3)
2496 CALL para_env%sum(fodeb)
2497 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Pout*dVhxc ", fodeb
2499 IF (debug_stress .AND. use_virial)
THEN
2500 stdeb = fconv*(virial%pv_virial - stdeb)
2501 CALL para_env%sum(stdeb)
2502 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2503 'STRESS| INT Pout*dVhxc ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2507 IF (use_virial)
THEN
2508 virial%pv_ehartree = virial%pv_ehartree + (virial%pv_virial - pv_loc)
2511 IF (
ASSOCIATED(v_tau_rspace))
THEN
2512 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
2513 DO ispin = 1, nspins
2515 CALL pw_scale(v_tau_rspace(ispin), v_tau_rspace(ispin)%pw_grid%dvol)
2516 CALL integrate_v_rspace(v_rspace=v_tau_rspace(ispin), &
2518 pmat=ec_env%matrix_p(ispin, 1), &
2520 calculate_forces=.true., &
2521 compute_tau=.true., &
2522 basis_type=
"HARRIS", &
2523 task_list_external=ec_env%task_list)
2525 IF (debug_forces)
THEN
2526 fodeb(1:3) = force(1)%rho_elec(1:3, 1) - fodeb(1:3)
2527 CALL para_env%sum(fodeb)
2528 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Pout*dVhxc_tau ", fodeb
2537 ec_hfx_sections => section_vals_get_subs_vals(qs_env%input,
"DFT%ENERGY_CORRECTION%XC%HF")
2538 CALL section_vals_get(ec_hfx_sections, explicit=do_ec_hfx)
2542 IF (debug_forces) fodeb(1:3) = force(1)%fock_4c(1:3, 1)
2543 IF (use_virial) virial%pv_fock_4c = 0.0_dp
2545 CALL calculate_exx(qs_env=qs_env, &
2547 hfx_sections=ec_hfx_sections, &
2548 x_data=ec_env%x_data, &
2550 do_admm=ec_env%do_ec_admm, &
2551 calc_forces=.true., &
2552 reuse_hfx=ec_env%reuse_hfx, &
2553 do_im_time=.false., &
2554 e_ex_from_gw=dummy_real, &
2555 e_admm_from_gw=dummy_real2, &
2558 IF (use_virial)
THEN
2559 virial%pv_exx = virial%pv_exx - virial%pv_fock_4c
2560 virial%pv_virial = virial%pv_virial - virial%pv_fock_4c
2561 virial%pv_calculate = .false.
2563 IF (debug_forces)
THEN
2564 fodeb(1:3) = force(1)%fock_4c(1:3, 1) - fodeb(1:3)
2565 CALL para_env%sum(fodeb)
2566 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Pout*hfx ", fodeb
2568 IF (debug_stress .AND. use_virial)
THEN
2569 stdeb = -1.0_dp*fconv*virial%pv_fock_4c
2570 CALL para_env%sum(stdeb)
2571 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2572 'STRESS| Pout*hfx ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2578 CALL dbcsr_deallocate_matrix_set(scrm)
2581 CALL auxbas_pw_pool%give_back_pw(v_hartree_rspace)
2582 DO ispin = 1, nspins
2583 CALL auxbas_pw_pool%give_back_pw(v_rspace(ispin))
2584 IF (
ASSOCIATED(v_tau_rspace))
THEN
2585 CALL auxbas_pw_pool%give_back_pw(v_tau_rspace(ispin))
2588 IF (
ASSOCIATED(v_tau_rspace))
DEALLOCATE (v_tau_rspace)
2591 IF (debug_forces) fodeb(1:3) = force(1)%core_overlap(1:3, 1)
2592 IF (debug_stress .AND. use_virial) stdeb = virial%pv_ecore_overlap
2593 CALL calculate_ecore_overlap(qs_env, para_env, .true., e_overlap_core=eovrl)
2594 IF (debug_forces)
THEN
2595 fodeb(1:3) = force(1)%core_overlap(1:3, 1) - fodeb(1:3)
2596 CALL para_env%sum(fodeb)
2597 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: CoreOverlap", fodeb
2599 IF (debug_stress .AND. use_virial)
THEN
2600 stdeb = fconv*(stdeb - virial%pv_ecore_overlap)
2601 CALL para_env%sum(stdeb)
2602 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2603 'STRESS| CoreOverlap ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2606 IF (debug_forces)
THEN
2607 CALL get_qs_env(qs_env, natom=natom, atomic_kind_set=atomic_kind_set)
2608 ALLOCATE (ftot(3, natom))
2609 CALL total_qs_force(ftot, force, atomic_kind_set)
2610 fodeb(1:3) = ftot(1:3, 1)
2612 CALL para_env%sum(fodeb)
2613 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Force Explicit", fodeb
2616 DEALLOCATE (v_rspace)
2618 CALL auxbas_pw_pool%give_back_pw(dv_hartree_rspace)
2619 CALL auxbas_pw_pool%give_back_pw(vtot_rspace)
2620 DO ispin = 1, nspins
2621 CALL auxbas_pw_pool%give_back_pw(rhoout_r(ispin))
2622 CALL auxbas_pw_pool%give_back_pw(rhoout_g(ispin))
2623 CALL auxbas_pw_pool%give_back_pw(v_xc(ispin))
2625 DEALLOCATE (rhoout_r, rhoout_g, v_xc)
2626 IF (
ASSOCIATED(tauout_r))
THEN
2627 DO ispin = 1, nspins
2628 CALL auxbas_pw_pool%give_back_pw(tauout_r(ispin))
2630 DEALLOCATE (tauout_r)
2632 IF (
ASSOCIATED(v_xc_tau))
THEN
2633 DO ispin = 1, nspins
2634 CALL auxbas_pw_pool%give_back_pw(v_xc_tau(ispin))
2636 DEALLOCATE (v_xc_tau)
2638 CALL auxbas_pw_pool%give_back_pw(v_hartree_gspace)
2639 CALL auxbas_pw_pool%give_back_pw(rhodn_tot_gspace)
2643 IF (use_virial)
THEN
2644 IF (qs_env%energy_correction)
THEN
2645 ec_env%ehartree = ehartree + dehartree
2646 ec_env%exc = exc + eexc
2650 IF (debug_stress .AND. use_virial)
THEN
2652 stdeb = -1.0_dp*fconv*ehartree
2653 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2654 'STRESS| VOL 1st v_H[n_in]*n_out', one_third_sum_diag(stdeb), det_3x3(stdeb)
2656 stdeb = -1.0_dp*fconv*exc
2657 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2658 'STRESS| VOL 1st E_XC[n_in]', one_third_sum_diag(stdeb), det_3x3(stdeb)
2660 stdeb = -1.0_dp*fconv*dehartree
2661 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2662 'STRESS| VOL 2nd v_H[dP]*n_in', one_third_sum_diag(stdeb), det_3x3(stdeb)
2664 stdeb = -1.0_dp*fconv*eexc
2665 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2666 'STRESS| VOL 2nd v_XC[n_in]*dP', one_third_sum_diag(stdeb), det_3x3(stdeb)
2671 TYPE(virial_type) :: virdeb
2674 CALL para_env%sum(virdeb%pv_overlap)
2675 CALL para_env%sum(virdeb%pv_ekinetic)
2676 CALL para_env%sum(virdeb%pv_ppl)
2677 CALL para_env%sum(virdeb%pv_ppnl)
2678 CALL para_env%sum(virdeb%pv_ecore_overlap)
2679 CALL para_env%sum(virdeb%pv_ehartree)
2680 CALL para_env%sum(virdeb%pv_exc)
2681 CALL para_env%sum(virdeb%pv_exx)
2682 CALL para_env%sum(virdeb%pv_vdw)
2683 CALL para_env%sum(virdeb%pv_mp2)
2684 CALL para_env%sum(virdeb%pv_nlcc)
2685 CALL para_env%sum(virdeb%pv_gapw)
2686 CALL para_env%sum(virdeb%pv_lrigpw)
2687 CALL para_env%sum(virdeb%pv_virial)
2688 CALL symmetrize_virial(virdeb)
2692 virdeb%pv_ehartree(i, i) = virdeb%pv_ehartree(i, i) - 2.0_dp*(ehartree + dehartree)
2693 virdeb%pv_virial(i, i) = virdeb%pv_virial(i, i) - exc - eexc &
2694 - 2.0_dp*(ehartree + dehartree)
2695 virdeb%pv_exc(i, i) = virdeb%pv_exc(i, i) - exc - eexc
2701 CALL para_env%sum(sttot)
2702 stdeb = fconv*(virdeb%pv_virial - sttot)
2703 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2704 'STRESS| Explicit electronic stress ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2706 stdeb = fconv*(virdeb%pv_virial)
2707 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2708 'STRESS| Explicit total stress ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2710 CALL write_stress_tensor_components(virdeb, iounit, cell, unit_string)
2711 CALL write_stress_tensor(virdeb%pv_virial, iounit, cell, unit_string, .false.)
2716 CALL timestop(handle)
2718 END SUBROUTINE ec_build_ks_matrix_force
2728 SUBROUTINE ec_ks_solver(qs_env, ec_env)
2730 TYPE(qs_environment_type),
POINTER :: qs_env
2731 TYPE(energy_correction_type),
POINTER :: ec_env
2733 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ec_ks_solver'
2735 CHARACTER(LEN=default_string_length) :: headline
2736 INTEGER :: handle, ispin, nspins
2737 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: ksmat, pmat, smat, wmat
2738 TYPE(dft_control_type),
POINTER :: dft_control
2740 CALL timeset(routinen, handle)
2742 CALL get_qs_env(qs_env=qs_env, dft_control=dft_control)
2743 nspins = dft_control%nspins
2746 IF (.NOT.
ASSOCIATED(ec_env%matrix_p))
THEN
2747 headline =
"DENSITY MATRIX"
2748 CALL dbcsr_allocate_matrix_set(ec_env%matrix_p, nspins, 1)
2749 DO ispin = 1, nspins
2750 ALLOCATE (ec_env%matrix_p(ispin, 1)%matrix)
2751 CALL dbcsr_create(ec_env%matrix_p(ispin, 1)%matrix, name=trim(headline), &
2752 template=ec_env%matrix_s(1, 1)%matrix)
2753 CALL cp_dbcsr_alloc_block_from_nbl(ec_env%matrix_p(ispin, 1)%matrix, ec_env%sab_orb)
2757 IF (.NOT.
ASSOCIATED(ec_env%matrix_w))
THEN
2758 headline =
"ENERGY WEIGHTED DENSITY MATRIX"
2759 CALL dbcsr_allocate_matrix_set(ec_env%matrix_w, nspins, 1)
2760 DO ispin = 1, nspins
2761 ALLOCATE (ec_env%matrix_w(ispin, 1)%matrix)
2762 CALL dbcsr_create(ec_env%matrix_w(ispin, 1)%matrix, name=trim(headline), &
2763 template=ec_env%matrix_s(1, 1)%matrix)
2764 CALL cp_dbcsr_alloc_block_from_nbl(ec_env%matrix_w(ispin, 1)%matrix, ec_env%sab_orb)
2768 IF (ec_env%mao)
THEN
2769 CALL mao_create_matrices(ec_env, ksmat, smat, pmat, wmat)
2771 ksmat => ec_env%matrix_ks
2772 smat => ec_env%matrix_s
2773 pmat => ec_env%matrix_p
2774 wmat => ec_env%matrix_w
2777 SELECT CASE (ec_env%ks_solver)
2778 CASE (ec_diagonalization)
2779 CALL ec_diag_solver(qs_env, ksmat, smat, pmat, wmat)
2781 CALL ec_ot_diag_solver(qs_env, ec_env, ksmat, smat, pmat, wmat)
2782 CASE (ec_matrix_sign, ec_matrix_trs4, ec_matrix_tc2)
2783 CALL ec_ls_init(qs_env, ksmat, smat)
2784 CALL ec_ls_solver(qs_env, pmat, wmat, ec_ls_method=ec_env%ks_solver)
2789 IF (ec_env%mao)
THEN
2790 CALL mao_release_matrices(ec_env, ksmat, smat, pmat, wmat)
2793 CALL timestop(handle)
2795 END SUBROUTINE ec_ks_solver
2808 SUBROUTINE mao_create_matrices(ec_env, ksmat, smat, pmat, wmat)
2810 TYPE(energy_correction_type),
POINTER :: ec_env
2811 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: ksmat, smat, pmat, wmat
2813 CHARACTER(LEN=*),
PARAMETER :: routinen =
'mao_create_matrices'
2815 INTEGER :: handle, ispin, nspins
2816 INTEGER,
DIMENSION(:),
POINTER :: col_blk_sizes
2817 TYPE(dbcsr_distribution_type) :: dbcsr_dist
2818 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: mao_coef
2819 TYPE(dbcsr_type) :: cgmat
2821 CALL timeset(routinen, handle)
2823 mao_coef => ec_env%mao_coef
2825 NULLIFY (ksmat, smat, pmat, wmat)
2826 nspins =
SIZE(ec_env%matrix_ks, 1)
2827 CALL dbcsr_get_info(mao_coef(1)%matrix, col_blk_size=col_blk_sizes, distribution=dbcsr_dist)
2828 CALL dbcsr_allocate_matrix_set(ksmat, nspins, 1)
2829 CALL dbcsr_allocate_matrix_set(smat, nspins, 1)
2830 DO ispin = 1, nspins
2831 ALLOCATE (ksmat(ispin, 1)%matrix)
2832 CALL dbcsr_create(ksmat(ispin, 1)%matrix, dist=dbcsr_dist, name=
"MAO KS mat", &
2833 matrix_type=dbcsr_type_symmetric, row_blk_size=col_blk_sizes, &
2834 col_blk_size=col_blk_sizes)
2835 ALLOCATE (smat(ispin, 1)%matrix)
2836 CALL dbcsr_create(smat(ispin, 1)%matrix, dist=dbcsr_dist, name=
"MAO S mat", &
2837 matrix_type=dbcsr_type_symmetric, row_blk_size=col_blk_sizes, &
2838 col_blk_size=col_blk_sizes)
2841 CALL dbcsr_create(cgmat, name=
"TEMP matrix", template=mao_coef(1)%matrix)
2842 DO ispin = 1, nspins
2843 CALL dbcsr_multiply(
"N",
"N", 1.0_dp, ec_env%matrix_s(1, 1)%matrix, mao_coef(ispin)%matrix, &
2845 CALL dbcsr_multiply(
"T",
"N", 1.0_dp, mao_coef(ispin)%matrix, cgmat, 0.0_dp, smat(ispin, 1)%matrix)
2846 CALL dbcsr_multiply(
"N",
"N", 1.0_dp, ec_env%matrix_ks(1, 1)%matrix, mao_coef(ispin)%matrix, &
2848 CALL dbcsr_multiply(
"T",
"N", 1.0_dp, mao_coef(ispin)%matrix, cgmat, 0.0_dp, ksmat(ispin, 1)%matrix)
2850 CALL dbcsr_release(cgmat)
2852 CALL dbcsr_allocate_matrix_set(pmat, nspins, 1)
2853 DO ispin = 1, nspins
2854 ALLOCATE (pmat(ispin, 1)%matrix)
2855 CALL dbcsr_create(pmat(ispin, 1)%matrix, template=smat(1, 1)%matrix, name=
"MAO P mat")
2856 CALL cp_dbcsr_alloc_block_from_nbl(pmat(ispin, 1)%matrix, ec_env%sab_orb)
2859 CALL dbcsr_allocate_matrix_set(wmat, nspins, 1)
2860 DO ispin = 1, nspins
2861 ALLOCATE (wmat(ispin, 1)%matrix)
2862 CALL dbcsr_create(wmat(ispin, 1)%matrix, template=smat(1, 1)%matrix, name=
"MAO W mat")
2863 CALL cp_dbcsr_alloc_block_from_nbl(wmat(ispin, 1)%matrix, ec_env%sab_orb)
2866 CALL timestop(handle)
2868 END SUBROUTINE mao_create_matrices
2881 SUBROUTINE mao_release_matrices(ec_env, ksmat, smat, pmat, wmat)
2883 TYPE(energy_correction_type),
POINTER :: ec_env
2884 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: ksmat, smat, pmat, wmat
2886 CHARACTER(LEN=*),
PARAMETER :: routinen =
'mao_release_matrices'
2888 INTEGER :: handle, ispin, nspins
2889 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: mao_coef
2890 TYPE(dbcsr_type) :: cgmat
2892 CALL timeset(routinen, handle)
2894 mao_coef => ec_env%mao_coef
2895 nspins =
SIZE(mao_coef, 1)
2898 CALL dbcsr_create(cgmat, name=
"TEMP matrix", template=mao_coef(1)%matrix)
2899 DO ispin = 1, nspins
2900 CALL dbcsr_multiply(
"N",
"N", 1.0_dp, mao_coef(ispin)%matrix, pmat(ispin, 1)%matrix, 0.0_dp, cgmat)
2901 CALL dbcsr_multiply(
"N",
"T", 1.0_dp, mao_coef(ispin)%matrix, cgmat, 0.0_dp, &
2902 ec_env%matrix_p(ispin, 1)%matrix, retain_sparsity=.true.)
2903 CALL dbcsr_multiply(
"N",
"N", 1.0_dp, mao_coef(ispin)%matrix, wmat(ispin, 1)%matrix, 0.0_dp, cgmat)
2904 CALL dbcsr_multiply(
"N",
"T", 1.0_dp, mao_coef(ispin)%matrix, cgmat, 0.0_dp, &
2905 ec_env%matrix_w(ispin, 1)%matrix, retain_sparsity=.true.)
2907 CALL dbcsr_release(cgmat)
2909 CALL dbcsr_deallocate_matrix_set(ksmat)
2910 CALL dbcsr_deallocate_matrix_set(smat)
2911 CALL dbcsr_deallocate_matrix_set(pmat)
2912 CALL dbcsr_deallocate_matrix_set(wmat)
2914 CALL timestop(handle)
2916 END SUBROUTINE mao_release_matrices
2929 SUBROUTINE ec_diag_solver(qs_env, matrix_ks, matrix_s, matrix_p, matrix_w)
2931 TYPE(qs_environment_type),
POINTER :: qs_env
2932 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_ks, matrix_s, matrix_p, matrix_w
2934 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ec_diag_solver'
2936 INTEGER :: handle, ispin, nmo(2), nsize, nspins
2937 REAL(kind=dp) :: eps_filter, focc(2)
2938 REAL(kind=dp),
ALLOCATABLE,
DIMENSION(:) :: eigenvalues
2939 TYPE(cp_blacs_env_type),
POINTER :: blacs_env
2940 TYPE(cp_fm_struct_type),
POINTER :: fm_struct
2941 TYPE(cp_fm_type) :: fm_ks, fm_mo, fm_ortho
2942 TYPE(dbcsr_type),
POINTER :: buf1_dbcsr, buf2_dbcsr, buf3_dbcsr, &
2943 ortho_dbcsr, ref_matrix
2944 TYPE(dft_control_type),
POINTER :: dft_control
2945 TYPE(mp_para_env_type),
POINTER :: para_env
2947 CALL timeset(routinen, handle)
2949 NULLIFY (blacs_env, para_env)
2950 CALL get_qs_env(qs_env=qs_env, blacs_env=blacs_env, para_env=para_env)
2952 CALL get_qs_env(qs_env=qs_env, dft_control=dft_control)
2953 eps_filter = dft_control%qs_control%eps_filter_matrix
2954 nspins = dft_control%nspins
2957 CALL get_qs_env(qs_env=qs_env, nelectron_spin=nmo)
2959 IF (nspins == 1)
THEN
2964 CALL dbcsr_get_info(matrix_ks(1, 1)%matrix, nfullrows_total=nsize)
2965 ALLOCATE (eigenvalues(nsize))
2967 NULLIFY (fm_struct, ref_matrix)
2968 CALL cp_fm_struct_create(fm_struct, context=blacs_env, nrow_global=nsize, &
2969 ncol_global=nsize, para_env=para_env)
2970 CALL cp_fm_create(fm_ortho, fm_struct)
2971 CALL cp_fm_create(fm_ks, fm_struct)
2972 CALL cp_fm_create(fm_mo, fm_struct)
2973 CALL cp_fm_struct_release(fm_struct)
2976 ref_matrix => matrix_s(1, 1)%matrix
2977 NULLIFY (ortho_dbcsr, buf1_dbcsr, buf2_dbcsr, buf3_dbcsr)
2978 CALL dbcsr_init_p(ortho_dbcsr)
2979 CALL dbcsr_create(ortho_dbcsr, template=ref_matrix, &
2980 matrix_type=dbcsr_type_no_symmetry)
2981 CALL dbcsr_init_p(buf1_dbcsr)
2982 CALL dbcsr_create(buf1_dbcsr, template=ref_matrix, &
2983 matrix_type=dbcsr_type_no_symmetry)
2984 CALL dbcsr_init_p(buf2_dbcsr)
2985 CALL dbcsr_create(buf2_dbcsr, template=ref_matrix, &
2986 matrix_type=dbcsr_type_no_symmetry)
2987 CALL dbcsr_init_p(buf3_dbcsr)
2988 CALL dbcsr_create(buf3_dbcsr, template=ref_matrix, &
2989 matrix_type=dbcsr_type_no_symmetry)
2991 ref_matrix => matrix_s(1, 1)%matrix
2992 CALL copy_dbcsr_to_fm(ref_matrix, fm_ortho)
2993 CALL cp_fm_cholesky_decompose(fm_ortho)
2994 CALL cp_fm_triangular_invert(fm_ortho)
2995 CALL cp_fm_set_all(fm_ks, 0.0_dp)
2996 CALL cp_fm_to_fm_triangular(fm_ortho, fm_ks,
"U")
2997 CALL copy_fm_to_dbcsr(fm_ks, ortho_dbcsr)
2998 DO ispin = 1, nspins
3000 CALL dbcsr_desymmetrize(matrix_ks(ispin, 1)%matrix, buf1_dbcsr)
3001 CALL dbcsr_multiply(
"N",
"N", 1.0_dp, buf1_dbcsr, ortho_dbcsr, &
3002 0.0_dp, buf2_dbcsr, filter_eps=eps_filter)
3003 CALL dbcsr_multiply(
"T",
"N", 1.0_dp, ortho_dbcsr, buf2_dbcsr, &
3004 0.0_dp, buf1_dbcsr, filter_eps=eps_filter)
3006 CALL copy_dbcsr_to_fm(buf1_dbcsr, fm_ks)
3007 CALL choose_eigv_solver(fm_ks, fm_mo, eigenvalues)
3009 CALL copy_fm_to_dbcsr(fm_mo, buf1_dbcsr)
3010 CALL dbcsr_multiply(
"N",
"N", 1.0_dp, ortho_dbcsr, buf1_dbcsr, &
3011 0.0_dp, buf2_dbcsr, filter_eps=eps_filter)
3013 CALL dbcsr_set(matrix_p(ispin, 1)%matrix, 0.0_dp)
3014 CALL dbcsr_multiply(
"N",
"T", focc(ispin), buf2_dbcsr, buf2_dbcsr, &
3015 1.0_dp, matrix_p(ispin, 1)%matrix, &
3016 retain_sparsity=.true., last_k=nmo(ispin))
3019 CALL dbcsr_set(matrix_w(ispin, 1)%matrix, 0.0_dp)
3020 CALL cp_fm_column_scale(fm_mo, eigenvalues)
3021 CALL copy_fm_to_dbcsr(fm_mo, buf1_dbcsr)
3022 CALL dbcsr_multiply(
"N",
"N", 1.0_dp, ortho_dbcsr, buf1_dbcsr, &
3023 0.0_dp, buf3_dbcsr, filter_eps=eps_filter)
3024 CALL dbcsr_multiply(
"N",
"T", focc(ispin), buf2_dbcsr, buf3_dbcsr, &
3025 1.0_dp, matrix_w(ispin, 1)%matrix, &
3026 retain_sparsity=.true., last_k=nmo(ispin))
3029 CALL cp_fm_release(fm_ks)
3030 CALL cp_fm_release(fm_mo)
3031 CALL cp_fm_release(fm_ortho)
3032 CALL dbcsr_release(ortho_dbcsr)
3033 CALL dbcsr_release(buf1_dbcsr)
3034 CALL dbcsr_release(buf2_dbcsr)
3035 CALL dbcsr_release(buf3_dbcsr)
3036 DEALLOCATE (ortho_dbcsr, buf1_dbcsr, buf2_dbcsr, buf3_dbcsr)
3037 DEALLOCATE (eigenvalues)
3039 CALL timestop(handle)
3041 END SUBROUTINE ec_diag_solver
3049 SUBROUTINE ec_energy(ec_env, unit_nr)
3050 TYPE(energy_correction_type) :: ec_env
3051 INTEGER,
INTENT(IN) :: unit_nr
3053 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ec_energy'
3055 INTEGER :: handle, ispin, nspins
3056 REAL(kind=dp) :: eband, trace
3058 CALL timeset(routinen, handle)
3060 nspins =
SIZE(ec_env%matrix_p, 1)
3061 DO ispin = 1, nspins
3062 CALL dbcsr_dot(ec_env%matrix_p(ispin, 1)%matrix, ec_env%matrix_s(1, 1)%matrix, trace)
3063 IF (unit_nr > 0)
WRITE (unit_nr,
'(T3,A,T65,F16.10)')
'Tr[PS] ', trace
3067 SELECT CASE (ec_env%energy_functional)
3068 CASE (ec_functional_harris)
3072 DO ispin = 1, nspins
3073 CALL dbcsr_dot(ec_env%matrix_ks(ispin, 1)%matrix, ec_env%matrix_p(ispin, 1)%matrix, trace)
3074 eband = eband + trace
3076 ec_env%eband = eband + ec_env%efield_nuclear
3079 ec_env%etotal = ec_env%eband + ec_env%ehartree + ec_env%exc - ec_env%vhxc + ec_env%edispersion - ec_env%ex
3080 IF (unit_nr > 0)
THEN
3081 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Eband ", ec_env%eband
3082 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Ehartree ", ec_env%ehartree
3083 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Exc ", ec_env%exc
3084 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Ex ", ec_env%ex
3085 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Evhxc ", ec_env%vhxc
3086 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Edisp ", ec_env%edispersion
3087 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Etotal Harris Functional ", ec_env%etotal
3090 CASE (ec_functional_dc)
3093 CALL calculate_ptrace(ec_env%matrix_h, ec_env%matrix_p, ec_env%ecore,
SIZE(ec_env%matrix_p, 1))
3095 ec_env%ecore = ec_env%ecore + ec_env%efield_nuclear
3096 ec_env%etotal = ec_env%ecore + ec_env%ehartree + ec_env%ehartree_1c + &
3097 ec_env%exc + ec_env%exc1 + ec_env%edispersion + &
3098 ec_env%ex + ec_env%exc_aux_fit + ec_env%exc1_aux_fit
3100 IF (unit_nr > 0)
THEN
3101 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Ecore ", ec_env%ecore
3102 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Ehartree ", ec_env%ehartree + ec_env%ehartree_1c
3103 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Exc ", ec_env%exc + ec_env%exc1
3104 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Ex ", ec_env%ex
3105 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Exc_aux_fit", ec_env%exc_aux_fit + ec_env%exc1_aux_fit
3106 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Edisp ", ec_env%edispersion
3107 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Etotal Energy Functional ", ec_env%etotal
3110 CASE (ec_functional_ext)
3112 ec_env%etotal = ec_env%ex
3113 IF (unit_nr > 0)
THEN
3114 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Etotal Energy Functional ", ec_env%etotal
3123 CALL timestop(handle)
3125 END SUBROUTINE ec_energy
3137 SUBROUTINE ec_build_neighborlist(qs_env, ec_env)
3138 TYPE(qs_environment_type),
POINTER :: qs_env
3139 TYPE(energy_correction_type),
POINTER :: ec_env
3141 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ec_build_neighborlist'
3143 INTEGER :: handle, ikind, nkind, zat
3144 LOGICAL :: all_potential_present, gth_potential_present, paw_atom, paw_atom_present, &
3145 sgp_potential_present, skip_load_balance_distributed
3146 LOGICAL,
ALLOCATABLE,
DIMENSION(:) :: all_present, default_present, &
3147 oce_present, orb_present, ppl_present, &
3149 REAL(dp) :: subcells
3150 REAL(dp),
ALLOCATABLE,
DIMENSION(:) :: all_radius, c_radius, oce_radius, &
3151 orb_radius, ppl_radius, ppnl_radius
3152 REAL(dp),
ALLOCATABLE,
DIMENSION(:, :) :: pair_radius
3153 TYPE(all_potential_type),
POINTER :: all_potential
3154 TYPE(atomic_kind_type),
DIMENSION(:),
POINTER :: atomic_kind_set
3155 TYPE(cell_type),
POINTER :: cell
3156 TYPE(dft_control_type),
POINTER :: dft_control
3157 TYPE(distribution_1d_type),
POINTER :: distribution_1d
3158 TYPE(distribution_2d_type),
POINTER :: distribution_2d
3159 TYPE(gth_potential_type),
POINTER :: gth_potential
3160 TYPE(gto_basis_set_type),
POINTER :: basis_set
3161 TYPE(local_atoms_type),
ALLOCATABLE,
DIMENSION(:) :: atom2d
3162 TYPE(molecule_type),
DIMENSION(:),
POINTER :: molecule_set
3163 TYPE(neighbor_list_set_p_type),
DIMENSION(:), &
3164 POINTER :: sab_cn, sab_vdw
3165 TYPE(particle_type),
DIMENSION(:),
POINTER :: particle_set
3166 TYPE(paw_proj_set_type),
POINTER :: paw_proj
3167 TYPE(qs_dispersion_type),
POINTER :: dispersion_env
3168 TYPE(qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
3169 TYPE(qs_kind_type),
POINTER :: qs_kind
3170 TYPE(qs_ks_env_type),
POINTER :: ks_env
3171 TYPE(sgp_potential_type),
POINTER :: sgp_potential
3173 CALL timeset(routinen, handle)
3175 CALL get_qs_env(qs_env=qs_env, qs_kind_set=qs_kind_set)
3176 CALL get_qs_kind_set(qs_kind_set, &
3177 paw_atom_present=paw_atom_present, &
3178 all_potential_present=all_potential_present, &
3179 gth_potential_present=gth_potential_present, &
3180 sgp_potential_present=sgp_potential_present)
3181 nkind =
SIZE(qs_kind_set)
3182 ALLOCATE (c_radius(nkind), default_present(nkind))
3183 ALLOCATE (orb_radius(nkind), all_radius(nkind), ppl_radius(nkind), ppnl_radius(nkind))
3184 ALLOCATE (orb_present(nkind), all_present(nkind), ppl_present(nkind), ppnl_present(nkind))
3185 ALLOCATE (pair_radius(nkind, nkind))
3186 ALLOCATE (atom2d(nkind))
3188 CALL get_qs_env(qs_env, &
3189 atomic_kind_set=atomic_kind_set, &
3191 distribution_2d=distribution_2d, &
3192 local_particles=distribution_1d, &
3193 particle_set=particle_set, &
3194 molecule_set=molecule_set)
3196 CALL atom2d_build(atom2d, distribution_1d, distribution_2d, atomic_kind_set, &
3197 molecule_set, .false., particle_set)
3200 CALL get_atomic_kind(atomic_kind_set(ikind), atom_list=atom2d(ikind)%list)
3201 qs_kind => qs_kind_set(ikind)
3202 CALL get_qs_kind(qs_kind=qs_kind, basis_set=basis_set, basis_type=
"HARRIS")
3203 IF (
ASSOCIATED(basis_set))
THEN
3204 orb_present(ikind) = .true.
3205 CALL get_gto_basis_set(gto_basis_set=basis_set, kind_radius=orb_radius(ikind))
3207 orb_present(ikind) = .false.
3208 orb_radius(ikind) = 0.0_dp
3210 CALL get_qs_kind(qs_kind, all_potential=all_potential, &
3211 gth_potential=gth_potential, sgp_potential=sgp_potential)
3212 IF (gth_potential_present .OR. sgp_potential_present)
THEN
3213 IF (
ASSOCIATED(gth_potential))
THEN
3214 CALL get_potential(potential=gth_potential, &
3215 ppl_present=ppl_present(ikind), &
3216 ppl_radius=ppl_radius(ikind), &
3217 ppnl_present=ppnl_present(ikind), &
3218 ppnl_radius=ppnl_radius(ikind))
3219 ELSE IF (
ASSOCIATED(sgp_potential))
THEN
3220 CALL get_potential(potential=sgp_potential, &
3221 ppl_present=ppl_present(ikind), &
3222 ppl_radius=ppl_radius(ikind), &
3223 ppnl_present=ppnl_present(ikind), &
3224 ppnl_radius=ppnl_radius(ikind))
3226 ppl_present(ikind) = .false.
3227 ppl_radius(ikind) = 0.0_dp
3228 ppnl_present(ikind) = .false.
3229 ppnl_radius(ikind) = 0.0_dp
3233 IF (all_potential_present .OR. sgp_potential_present)
THEN
3234 all_present(ikind) = .false.
3235 all_radius(ikind) = 0.0_dp
3236 IF (
ASSOCIATED(all_potential))
THEN
3237 all_present(ikind) = .true.
3238 CALL get_potential(potential=all_potential, core_charge_radius=all_radius(ikind))
3239 ELSE IF (
ASSOCIATED(sgp_potential))
THEN
3240 IF (sgp_potential%ecp_local)
THEN
3241 all_present(ikind) = .true.
3242 CALL get_potential(potential=sgp_potential, core_charge_radius=all_radius(ikind))
3248 CALL section_vals_val_get(qs_env%input,
"DFT%SUBCELLS", r_val=subcells)
3251 CALL pair_radius_setup(orb_present, orb_present, orb_radius, orb_radius, pair_radius)
3252 CALL build_neighbor_lists(ec_env%sab_orb, particle_set, atom2d, cell, pair_radius, &
3253 subcells=subcells, nlname=
"sab_orb")
3255 IF (all_potential_present .OR. sgp_potential_present)
THEN
3256 IF (any(all_present))
THEN
3257 CALL pair_radius_setup(orb_present, all_present, orb_radius, all_radius, pair_radius)
3258 CALL build_neighbor_lists(ec_env%sac_ae, particle_set, atom2d, cell, pair_radius, &
3259 subcells=subcells, operator_type=
"ABC", nlname=
"sac_ae")
3263 IF (gth_potential_present .OR. sgp_potential_present)
THEN
3264 IF (any(ppl_present))
THEN
3265 CALL pair_radius_setup(orb_present, ppl_present, orb_radius, ppl_radius, pair_radius)
3266 CALL build_neighbor_lists(ec_env%sac_ppl, particle_set, atom2d, cell, pair_radius, &
3267 subcells=subcells, operator_type=
"ABC", nlname=
"sac_ppl")
3270 IF (any(ppnl_present))
THEN
3271 CALL pair_radius_setup(orb_present, ppnl_present, orb_radius, ppnl_radius, pair_radius)
3272 CALL build_neighbor_lists(ec_env%sap_ppnl, particle_set, atom2d, cell, pair_radius, &
3273 subcells=subcells, operator_type=
"ABBA", nlname=
"sap_ppnl")
3278 c_radius(:) = 0.0_dp
3279 dispersion_env => ec_env%dispersion_env
3280 sab_vdw => dispersion_env%sab_vdw
3281 sab_cn => dispersion_env%sab_cn
3282 IF (dispersion_env%type == xc_vdw_fun_pairpot)
THEN
3283 c_radius(:) = dispersion_env%rc_disp
3284 default_present = .true.
3285 CALL pair_radius_setup(default_present, default_present, c_radius, c_radius, pair_radius)
3286 CALL build_neighbor_lists(sab_vdw, particle_set, atom2d, cell, pair_radius, &
3287 subcells=subcells, operator_type=
"PP", nlname=
"sab_vdw")
3288 dispersion_env%sab_vdw => sab_vdw
3289 IF (dispersion_env%pp_type == vdw_pairpot_dftd3 .OR. &
3290 dispersion_env%pp_type == vdw_pairpot_dftd3bj)
THEN
3293 CALL get_atomic_kind(atomic_kind_set(ikind), z=zat)
3294 c_radius(ikind) = 4._dp*ptable(zat)%covalent_radius*bohr
3296 CALL pair_radius_setup(default_present, default_present, c_radius, c_radius, pair_radius)
3297 CALL build_neighbor_lists(sab_cn, particle_set, atom2d, cell, pair_radius, &
3298 subcells=subcells, operator_type=
"PP", nlname=
"sab_cn")
3299 dispersion_env%sab_cn => sab_cn
3304 IF (paw_atom_present)
THEN
3305 IF (paw_atom_present)
THEN
3306 ALLOCATE (oce_present(nkind), oce_radius(nkind))
3311 CALL get_qs_kind(qs_kind_set(ikind), paw_proj_set=paw_proj, paw_atom=paw_atom)
3313 oce_present(ikind) = .true.
3314 CALL get_paw_proj_set(paw_proj_set=paw_proj, rcprj=oce_radius(ikind))
3316 oce_present(ikind) = .false.
3321 IF (any(oce_present))
THEN
3322 CALL pair_radius_setup(orb_present, oce_present, orb_radius, oce_radius, pair_radius)
3323 CALL build_neighbor_lists(ec_env%sap_oce, particle_set, atom2d, cell, pair_radius, &
3324 subcells=subcells, operator_type=
"ABBA", nlname=
"sap_oce")
3326 DEALLOCATE (oce_present, oce_radius)
3330 CALL atom2d_cleanup(atom2d)
3332 DEALLOCATE (orb_present, default_present, all_present, ppl_present, ppnl_present)
3333 DEALLOCATE (orb_radius, all_radius, ppl_radius, ppnl_radius, c_radius)
3334 DEALLOCATE (pair_radius)
3337 CALL get_qs_env(qs_env, ks_env=ks_env, dft_control=dft_control)
3338 skip_load_balance_distributed = dft_control%qs_control%skip_load_balance_distributed
3339 IF (
ASSOCIATED(ec_env%task_list))
CALL deallocate_task_list(ec_env%task_list)
3340 CALL allocate_task_list(ec_env%task_list)
3341 CALL generate_qs_task_list(ks_env, ec_env%task_list, basis_type=
"HARRIS", &
3342 reorder_rs_grid_ranks=.false., &
3343 skip_load_balance_distributed=skip_load_balance_distributed, &
3344 sab_orb_external=ec_env%sab_orb)
3346 IF (dft_control%qs_control%gapw .OR. dft_control%qs_control%gapw_xc)
THEN
3347 IF (
ASSOCIATED(ec_env%task_list_soft))
CALL deallocate_task_list(ec_env%task_list_soft)
3348 CALL allocate_task_list(ec_env%task_list_soft)
3349 CALL generate_qs_task_list(ks_env, ec_env%task_list_soft, basis_type=
"HARRIS_SOFT", &
3350 reorder_rs_grid_ranks=.false., &
3351 skip_load_balance_distributed=skip_load_balance_distributed, &
3352 sab_orb_external=ec_env%sab_orb)
3355 CALL timestop(handle)
3357 END SUBROUTINE ec_build_neighborlist
3364 SUBROUTINE ec_properties(qs_env, ec_env)
3365 TYPE(qs_environment_type),
POINTER :: qs_env
3366 TYPE(energy_correction_type),
POINTER :: ec_env
3368 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ec_properties'
3370 CHARACTER(LEN=8),
DIMENSION(3) :: rlab
3371 CHARACTER(LEN=default_path_length) :: filename, my_pos_voro
3372 CHARACTER(LEN=default_string_length) :: description
3373 INTEGER :: akind, handle, i, ia, iatom, idir, ikind, iounit, ispin, maxmom, nspins, &
3374 reference, should_print_bqb, should_print_voro, unit_nr, unit_nr_voro
3375 LOGICAL :: append_voro, magnetic, periodic, &
3377 REAL(kind=dp) :: charge, dd, focc, tmp
3378 REAL(kind=dp),
DIMENSION(3) :: cdip, pdip, rcc, rdip, ria, tdip
3379 REAL(kind=dp),
DIMENSION(:),
POINTER :: ref_point
3380 TYPE(atomic_kind_type),
POINTER :: atomic_kind
3381 TYPE(cell_type),
POINTER :: cell
3382 TYPE(cp_logger_type),
POINTER :: logger
3383 TYPE(cp_result_type),
POINTER :: results
3384 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_s, moments
3385 TYPE(dft_control_type),
POINTER :: dft_control
3386 TYPE(distribution_1d_type),
POINTER :: local_particles
3387 TYPE(mp_para_env_type),
POINTER :: para_env
3388 TYPE(particle_type),
DIMENSION(:),
POINTER :: particle_set
3389 TYPE(pw_env_type),
POINTER :: pw_env
3390 TYPE(pw_pool_p_type),
DIMENSION(:),
POINTER :: pw_pools
3391 TYPE(pw_pool_type),
POINTER :: auxbas_pw_pool
3392 TYPE(pw_r3d_rs_type) :: rho_elec_rspace
3393 TYPE(qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
3394 TYPE(section_vals_type),
POINTER :: ec_section, print_key, print_key_bqb, &
3397 CALL timeset(routinen, handle)
3403 logger => cp_get_default_logger()
3404 IF (logger%para_env%is_source())
THEN
3405 iounit = cp_logger_get_default_unit_nr(logger, local=.true.)
3410 NULLIFY (dft_control)
3411 CALL get_qs_env(qs_env, dft_control=dft_control)
3412 nspins = dft_control%nspins
3414 ec_section => section_vals_get_subs_vals(qs_env%input,
"DFT%ENERGY_CORRECTION")
3415 print_key => section_vals_get_subs_vals(section_vals=ec_section, &
3416 subsection_name=
"PRINT%MOMENTS")
3418 IF (btest(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file))
THEN
3420 IF (dft_control%qs_control%gapw .OR. dft_control%qs_control%gapw_xc)
THEN
3421 cpabort(
"Properties for GAPW in EC NYA")
3424 maxmom = section_get_ival(section_vals=ec_section, &
3425 keyword_name=
"PRINT%MOMENTS%MAX_MOMENT")
3426 periodic = section_get_lval(section_vals=ec_section, &
3427 keyword_name=
"PRINT%MOMENTS%PERIODIC")
3428 reference = section_get_ival(section_vals=ec_section, &
3429 keyword_name=
"PRINT%MOMENTS%REFERENCE")
3430 magnetic = section_get_lval(section_vals=ec_section, &
3431 keyword_name=
"PRINT%MOMENTS%MAGNETIC")
3433 CALL section_vals_val_get(ec_section,
"PRINT%MOMENTS%REF_POINT", r_vals=ref_point)
3434 unit_nr = cp_print_key_unit_nr(logger=logger, basis_section=ec_section, &
3435 print_key_path=
"PRINT%MOMENTS", extension=
".dat", &
3436 middle_name=
"moments", log_filename=.false.)
3438 IF (iounit > 0)
THEN
3439 IF (unit_nr /= iounit .AND. unit_nr > 0)
THEN
3440 INQUIRE (unit=unit_nr, name=filename)
3441 WRITE (unit=iounit, fmt=
"(/,T2,A,2(/,T3,A),/)") &
3442 "MOMENTS",
"The electric/magnetic moments are written to file:", &
3445 WRITE (unit=iounit, fmt=
"(/,T2,A)")
"ELECTRIC/MAGNETIC MOMENTS"
3450 cpabort(
"Periodic moments not implemented with EC")
3452 cpassert(maxmom < 2)
3453 cpassert(.NOT. magnetic)
3454 IF (maxmom == 1)
THEN
3455 CALL get_qs_env(qs_env=qs_env, cell=cell, para_env=para_env)
3457 CALL get_reference_point(rcc, qs_env=qs_env, reference=reference, ref_point=ref_point)
3460 CALL get_qs_env(qs_env=qs_env, particle_set=particle_set, &
3461 qs_kind_set=qs_kind_set, local_particles=local_particles)
3462 DO ikind = 1,
SIZE(local_particles%n_el)
3463 DO ia = 1, local_particles%n_el(ikind)
3464 iatom = local_particles%list(ikind)%array(ia)
3466 ria = pbc(particle_set(iatom)%r - rcc, cell) + rcc
3468 atomic_kind => particle_set(iatom)%atomic_kind
3469 CALL get_atomic_kind(atomic_kind, kind_number=akind)
3470 CALL get_qs_kind(qs_kind_set(akind), core_charge=charge)
3471 cdip(1:3) = cdip(1:3) - charge*ria(1:3)
3474 CALL para_env%sum(cdip)
3477 CALL ec_efield_integrals(qs_env, ec_env, rcc)
3480 DO ispin = 1, nspins
3482 CALL dbcsr_dot(ec_env%matrix_p(ispin, 1)%matrix, &
3483 ec_env%efield%dipmat(idir)%matrix, tmp)
3484 pdip(idir) = pdip(idir) + tmp
3489 CALL get_qs_env(qs_env=qs_env, matrix_s=matrix_s)
3491 CALL dbcsr_allocate_matrix_set(moments, 4)
3493 ALLOCATE (moments(i)%matrix)
3494 CALL dbcsr_copy(moments(i)%matrix, matrix_s(1)%matrix,
"Moments")
3495 CALL dbcsr_set(moments(i)%matrix, 0.0_dp)
3497 CALL build_local_moment_matrix(qs_env, moments, 1, ref_point=rcc)
3500 IF (nspins == 2) focc = 1.0_dp
3502 DO ispin = 1, nspins
3504 CALL dbcsr_dot(ec_env%matrix_z(ispin)%matrix, moments(idir)%matrix, tmp)
3505 rdip(idir) = rdip(idir) + tmp
3508 CALL dbcsr_deallocate_matrix_set(moments)
3510 tdip = -(rdip + pdip + cdip)
3511 IF (unit_nr > 0)
THEN
3512 WRITE (unit_nr,
"(T3,A)")
"Dipoles are based on the traditional operator."
3513 dd = sqrt(sum(tdip(1:3)**2))*debye
3514 WRITE (unit_nr,
"(T3,A)")
"Dipole moment [Debye]"
3515 WRITE (unit_nr,
"(T5,3(A,A,F14.8,1X),T60,A,T67,F14.8)") &
3516 (trim(rlab(i)),
"=", tdip(i)*debye, i=1, 3),
"Total=", dd
3521 CALL cp_print_key_finished_output(unit_nr=unit_nr, logger=logger, &
3522 basis_section=ec_section, print_key_path=
"PRINT%MOMENTS")
3523 CALL get_qs_env(qs_env=qs_env, results=results)
3524 description =
"[DIPOLE]"
3525 CALL cp_results_erase(results=results, description=description)
3526 CALL put_results(results=results, description=description, values=tdip(1:3))
3530 print_key_voro => section_vals_get_subs_vals(ec_section,
"PRINT%VORONOI")
3531 print_key_bqb => section_vals_get_subs_vals(ec_section,
"PRINT%E_DENSITY_BQB")
3532 IF (btest(cp_print_key_should_output(logger%iter_info, print_key_voro), cp_p_file))
THEN
3533 should_print_voro = 1
3535 should_print_voro = 0
3537 IF (btest(cp_print_key_should_output(logger%iter_info, print_key_bqb), cp_p_file))
THEN
3538 should_print_bqb = 1
3540 should_print_bqb = 0
3542 IF ((should_print_voro /= 0) .OR. (should_print_bqb /= 0))
THEN
3544 IF (dft_control%qs_control%gapw .OR. dft_control%qs_control%gapw_xc)
THEN
3545 cpabort(
"Properties for GAPW in EC NYA")
3548 CALL get_qs_env(qs_env=qs_env, &
3550 CALL pw_env_get(pw_env=pw_env, &
3551 auxbas_pw_pool=auxbas_pw_pool, &
3553 CALL auxbas_pw_pool%create_pw(pw=rho_elec_rspace)
3555 IF (dft_control%nspins > 1)
THEN
3558 CALL pw_copy(ec_env%rhoout_r(1), rho_elec_rspace)
3559 CALL pw_axpy(ec_env%rhoout_r(2), rho_elec_rspace)
3561 CALL pw_axpy(ec_env%rhoz_r(1), rho_elec_rspace)
3562 CALL pw_axpy(ec_env%rhoz_r(2), rho_elec_rspace)
3566 CALL pw_copy(ec_env%rhoout_r(1), rho_elec_rspace)
3567 CALL pw_axpy(ec_env%rhoz_r(1), rho_elec_rspace)
3570 IF (should_print_voro /= 0)
THEN
3571 CALL section_vals_val_get(print_key_voro,
"OUTPUT_TEXT", l_val=voro_print_txt)
3572 IF (voro_print_txt)
THEN
3573 append_voro = section_get_lval(ec_section,
"PRINT%VORONOI%APPEND")
3574 my_pos_voro =
"REWIND"
3575 IF (append_voro)
THEN
3576 my_pos_voro =
"APPEND"
3578 unit_nr_voro = cp_print_key_unit_nr(logger, ec_section,
"PRINT%VORONOI", extension=
".voronoi", &
3579 file_position=my_pos_voro, log_filename=.false.)
3587 CALL entry_voronoi_or_bqb(should_print_voro, should_print_bqb, print_key_voro, print_key_bqb, &
3588 unit_nr_voro, qs_env, rho_elec_rspace)
3590 CALL auxbas_pw_pool%give_back_pw(rho_elec_rspace)
3592 IF (unit_nr_voro > 0)
THEN
3593 CALL cp_print_key_finished_output(unit_nr_voro, logger, ec_section,
"PRINT%VORONOI")
3598 CALL timestop(handle)
3600 END SUBROUTINE ec_properties
3613 SUBROUTINE ec_ls_init(qs_env, matrix_ks, matrix_s)
3614 TYPE(qs_environment_type),
POINTER :: qs_env
3615 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_ks, matrix_s
3617 CHARACTER(len=*),
PARAMETER :: routinen =
'ec_ls_init'
3619 INTEGER :: handle, ispin, nspins
3620 TYPE(dft_control_type),
POINTER :: dft_control
3621 TYPE(energy_correction_type),
POINTER :: ec_env
3622 TYPE(ls_scf_env_type),
POINTER :: ls_env
3624 CALL timeset(routinen, handle)
3626 CALL get_qs_env(qs_env=qs_env, &
3627 dft_control=dft_control, &
3629 nspins = dft_control%nspins
3630 ls_env => ec_env%ls_env
3633 CALL matrix_ls_create(matrix_ls=ls_env%matrix_s, matrix_qs=matrix_s(1, 1)%matrix, &
3634 ls_mstruct=ls_env%ls_mstruct)
3636 IF (
ALLOCATED(ls_env%matrix_p))
THEN
3637 DO ispin = 1,
SIZE(ls_env%matrix_p)
3638 CALL dbcsr_release(ls_env%matrix_p(ispin))
3641 ALLOCATE (ls_env%matrix_p(nspins))
3644 DO ispin = 1, nspins
3645 CALL dbcsr_create(ls_env%matrix_p(ispin), template=ls_env%matrix_s, &
3646 matrix_type=dbcsr_type_no_symmetry)
3649 ALLOCATE (ls_env%matrix_ks(nspins))
3650 DO ispin = 1, nspins
3651 CALL dbcsr_create(ls_env%matrix_ks(ispin), template=ls_env%matrix_s, &
3652 matrix_type=dbcsr_type_no_symmetry)
3656 CALL ls_scf_init_matrix_s(matrix_s(1, 1)%matrix, ls_env)
3660 DO ispin = 1, nspins
3661 CALL matrix_qs_to_ls(matrix_ls=ls_env%matrix_ks(ispin), &
3662 matrix_qs=matrix_ks(ispin, 1)%matrix, &
3663 ls_mstruct=ls_env%ls_mstruct, &
3667 CALL timestop(handle)
3669 END SUBROUTINE ec_ls_init
3685 SUBROUTINE ec_ls_solver(qs_env, matrix_p, matrix_w, ec_ls_method)
3686 TYPE(qs_environment_type),
POINTER :: qs_env
3687 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_p, matrix_w
3688 INTEGER,
INTENT(IN) :: ec_ls_method
3690 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ec_ls_solver'
3692 INTEGER :: handle, ispin, nelectron_spin_real, &
3694 INTEGER,
DIMENSION(2) :: nmo
3695 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: wmat
3696 TYPE(dbcsr_type),
ALLOCATABLE,
DIMENSION(:) :: matrix_ks_deviation
3697 TYPE(dft_control_type),
POINTER :: dft_control
3698 TYPE(energy_correction_type),
POINTER :: ec_env
3699 TYPE(ls_scf_env_type),
POINTER :: ls_env
3700 TYPE(mp_para_env_type),
POINTER :: para_env
3702 CALL timeset(routinen, handle)
3705 CALL get_qs_env(qs_env, &
3706 dft_control=dft_control, &
3708 nspins = dft_control%nspins
3709 ec_env => qs_env%ec_env
3710 ls_env => ec_env%ls_env
3713 CALL get_qs_env(qs_env=qs_env, nelectron_spin=nmo)
3714 IF (nspins == 1) nmo(1) = nmo(1)/2
3715 ls_env%homo_spin(:) = 0.0_dp
3716 ls_env%lumo_spin(:) = 0.0_dp
3718 ALLOCATE (matrix_ks_deviation(nspins))
3719 DO ispin = 1, nspins
3720 CALL dbcsr_create(matrix_ks_deviation(ispin), template=ls_env%matrix_ks(ispin))
3721 CALL dbcsr_set(matrix_ks_deviation(ispin), 0.0_dp)
3725 IF (ls_env%has_s_preconditioner)
THEN
3726 DO ispin = 1, nspins
3727 CALL apply_matrix_preconditioner(ls_env%matrix_ks(ispin),
"forward", &
3728 ls_env%matrix_bs_sqrt, ls_env%matrix_bs_sqrt_inv)
3730 CALL dbcsr_filter(ls_env%matrix_ks(ispin), ls_env%eps_filter)
3734 DO ispin = 1, nspins
3735 nelectron_spin_real = ls_env%nelectron_spin(ispin)
3736 IF (ls_env%nspins == 1) nelectron_spin_real = nelectron_spin_real/2
3738 SELECT CASE (ec_ls_method)
3739 CASE (ec_matrix_sign)
3740 CALL density_matrix_sign(ls_env%matrix_p(ispin), &
3741 ls_env%mu_spin(ispin), &
3743 ls_env%sign_method, &
3744 ls_env%sign_order, &
3745 ls_env%matrix_ks(ispin), &
3747 ls_env%matrix_s_inv, &
3748 nelectron_spin_real, &
3751 CASE (ec_matrix_trs4)
3752 CALL density_matrix_trs4( &
3753 ls_env%matrix_p(ispin), &
3754 ls_env%matrix_ks(ispin), &
3755 ls_env%matrix_s_sqrt_inv, &
3756 nelectron_spin_real, &
3757 ec_env%eps_default, &
3758 ls_env%homo_spin(ispin), &
3759 ls_env%lumo_spin(ispin), &
3760 ls_env%mu_spin(ispin), &
3761 matrix_ks_deviation=matrix_ks_deviation(ispin), &
3762 dynamic_threshold=ls_env%dynamic_threshold, &
3763 eps_lanczos=ls_env%eps_lanczos, &
3764 max_iter_lanczos=ls_env%max_iter_lanczos)
3766 CASE (ec_matrix_tc2)
3767 CALL density_matrix_tc2( &
3768 ls_env%matrix_p(ispin), &
3769 ls_env%matrix_ks(ispin), &
3770 ls_env%matrix_s_sqrt_inv, &
3771 nelectron_spin_real, &
3772 ec_env%eps_default, &
3773 ls_env%homo_spin(ispin), &
3774 ls_env%lumo_spin(ispin), &
3775 non_monotonic=ls_env%non_monotonic, &
3776 eps_lanczos=ls_env%eps_lanczos, &
3777 max_iter_lanczos=ls_env%max_iter_lanczos)
3784 IF (ls_env%has_s_preconditioner)
THEN
3785 DO ispin = 1, nspins
3787 CALL apply_matrix_preconditioner(ls_env%matrix_p(ispin),
"forward", &
3788 ls_env%matrix_bs_sqrt, ls_env%matrix_bs_sqrt_inv)
3790 CALL dbcsr_filter(ls_env%matrix_p(ispin), ls_env%eps_filter)
3795 IF (nspins == 1)
CALL dbcsr_scale(ls_env%matrix_p(1), 2.0_dp)
3797 IF (ls_env%report_all_sparsities)
CALL post_scf_sparsities(ls_env)
3801 DO ispin = 1, nspins
3802 CALL matrix_ls_to_qs(matrix_qs=matrix_p(ispin, 1)%matrix, &
3803 matrix_ls=ls_env%matrix_p(ispin), &
3804 ls_mstruct=ls_env%ls_mstruct, &
3808 wmat => matrix_w(:, 1)
3809 CALL calculate_w_matrix_ls(wmat, ec_env%ls_env)
3812 CALL dbcsr_release(ls_env%matrix_s)
3813 IF (ls_env%has_s_preconditioner)
THEN
3814 CALL dbcsr_release(ls_env%matrix_bs_sqrt)
3815 CALL dbcsr_release(ls_env%matrix_bs_sqrt_inv)
3817 IF (ls_env%needs_s_inv)
THEN
3818 CALL dbcsr_release(ls_env%matrix_s_inv)
3820 IF (ls_env%use_s_sqrt)
THEN
3821 CALL dbcsr_release(ls_env%matrix_s_sqrt)
3822 CALL dbcsr_release(ls_env%matrix_s_sqrt_inv)
3825 DO ispin = 1,
SIZE(ls_env%matrix_ks)
3826 CALL dbcsr_release(ls_env%matrix_ks(ispin))
3828 DEALLOCATE (ls_env%matrix_ks)
3830 DO ispin = 1, nspins
3831 CALL dbcsr_release(matrix_ks_deviation(ispin))
3833 DEALLOCATE (matrix_ks_deviation)
3835 CALL timestop(handle)
3837 END SUBROUTINE ec_ls_solver
3855 SUBROUTINE ec_ot_diag_solver(qs_env, ec_env, matrix_ks, matrix_s, matrix_p, matrix_w)
3856 TYPE(qs_environment_type),
POINTER :: qs_env
3857 TYPE(energy_correction_type),
POINTER :: ec_env
3858 TYPE(dbcsr_p_type),
DIMENSION(:, :),
INTENT(IN), &
3859 POINTER :: matrix_ks, matrix_s
3860 TYPE(dbcsr_p_type),
DIMENSION(:, :), &
3861 INTENT(INOUT),
POINTER :: matrix_p, matrix_w
3863 CHARACTER(len=*),
PARAMETER :: routinen =
'ec_ot_diag_solver'
3865 INTEGER :: handle, homo, ikind, iounit, ispin, &
3866 max_iter, nao, nkind, nmo, nspins
3867 INTEGER,
DIMENSION(2) :: nelectron_spin
3868 REAL(kind=dp),
DIMENSION(:),
POINTER :: eigenvalues
3869 TYPE(atomic_kind_type),
DIMENSION(:),
POINTER :: atomic_kind_set
3870 TYPE(cp_blacs_env_type),
POINTER :: blacs_env
3871 TYPE(cp_fm_type) :: sv
3872 TYPE(cp_fm_type),
POINTER :: mo_coeff
3873 TYPE(cp_logger_type),
POINTER :: logger
3874 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: p_rmpv
3875 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: rho_ao
3876 TYPE(dft_control_type),
POINTER :: dft_control
3877 TYPE(gto_basis_set_type),
POINTER :: basis_set, harris_basis
3878 TYPE(mo_set_type),
DIMENSION(:),
POINTER :: mos
3879 TYPE(mp_para_env_type),
POINTER :: para_env
3880 TYPE(particle_type),
DIMENSION(:),
POINTER :: particle_set
3881 TYPE(preconditioner_type),
POINTER :: local_preconditioner
3882 TYPE(qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
3883 TYPE(qs_kind_type),
POINTER :: qs_kind
3884 TYPE(qs_rho_type),
POINTER :: rho
3886 CALL timeset(routinen, handle)
3888 logger => cp_get_default_logger()
3889 iounit = cp_logger_get_default_unit_nr(logger)
3891 cpassert(
ASSOCIATED(qs_env))
3892 cpassert(
ASSOCIATED(ec_env))
3893 cpassert(
ASSOCIATED(matrix_ks))
3894 cpassert(
ASSOCIATED(matrix_s))
3895 cpassert(
ASSOCIATED(matrix_p))
3896 cpassert(
ASSOCIATED(matrix_w))
3898 CALL get_qs_env(qs_env=qs_env, &
3899 atomic_kind_set=atomic_kind_set, &
3900 blacs_env=blacs_env, &
3901 dft_control=dft_control, &
3902 nelectron_spin=nelectron_spin, &
3903 para_env=para_env, &
3904 particle_set=particle_set, &
3905 qs_kind_set=qs_kind_set)
3906 nspins = dft_control%nspins
3913 IF (dft_control%qs_control%do_ls_scf)
THEN
3914 CALL ec_mos_init(qs_env, matrix_s(1, 1)%matrix)
3917 CALL get_qs_env(qs_env, mos=mos)
3924 CALL get_qs_env(qs_env, qs_kind_set=qs_kind_set, nkind=nkind)
3925 CALL uppercase(ec_env%basis)
3929 IF (ec_env%basis ==
"HARRIS")
THEN
3931 qs_kind => qs_kind_set(ikind)
3933 CALL get_qs_kind(qs_kind=qs_kind, basis_set=basis_set, basis_type=
"ORB")
3935 CALL get_qs_kind(qs_kind=qs_kind, basis_set=harris_basis, basis_type=
"HARRIS")
3937 IF (basis_set%name /= harris_basis%name)
THEN
3938 cpabort(
"OT-Diag initial guess: Harris and ground state need to use the same basis")
3943 IF (ec_env%mao)
THEN
3944 cpabort(
"OT-Diag initial guess: not implemented for MAOs")
3948 SELECT CASE (ec_env%ec_initial_guess)
3951 p_rmpv => matrix_p(:, 1)
3953 CALL calculate_atomic_block_dm(p_rmpv, matrix_s(1, 1)%matrix, atomic_kind_set, qs_kind_set, &
3954 nspins, nelectron_spin, iounit, para_env)
3958 CALL get_qs_env(qs_env, rho=rho)
3959 CALL qs_rho_get(rho, rho_ao_kp=rho_ao)
3960 p_rmpv => rho_ao(:, 1)
3963 cpabort(
"Unknown inital guess for OT-Diagonalization (Harris functional)")
3966 DO ispin = 1, nspins
3967 CALL get_mo_set(mo_set=mos(ispin), &
3968 mo_coeff=mo_coeff, &
3974 CALL cp_fm_set_all(mo_coeff, 0.0_dp)
3975 CALL cp_fm_init_random(mo_coeff, nmo)
3977 CALL cp_fm_create(sv, mo_coeff%matrix_struct,
"SV")
3980 CALL cp_dbcsr_sm_fm_multiply(matrix_s(1, 1)%matrix, mo_coeff, sv, nmo)
3981 CALL cp_dbcsr_sm_fm_multiply(p_rmpv(ispin)%matrix, sv, mo_coeff, homo)
3982 CALL cp_fm_release(sv)
3985 CALL make_basis_sm(mo_coeff, nmo, matrix_s(1, 1)%matrix)
3989 NULLIFY (local_preconditioner)
3990 ALLOCATE (local_preconditioner)
3991 CALL init_preconditioner(local_preconditioner, para_env=para_env, &
3992 blacs_env=blacs_env)
3993 DO ispin = 1, nspins
3994 CALL make_preconditioner(local_preconditioner, &
3995 precon_type=ot_precond_full_single_inverse, &
3996 solver_type=ot_precond_solver_default, &
3997 matrix_h=matrix_ks(ispin, 1)%matrix, &
3998 matrix_s=matrix_s(ispin, 1)%matrix, &
3999 convert_precond_to_dbcsr=.true., &
4000 mo_set=mos(ispin), energy_gap=0.2_dp)
4002 CALL get_mo_set(mos(ispin), &
4003 mo_coeff=mo_coeff, &
4004 eigenvalues=eigenvalues, &
4007 CALL ot_eigensolver(matrix_h=matrix_ks(ispin, 1)%matrix, &
4008 matrix_s=matrix_s(1, 1)%matrix, &
4009 matrix_c_fm=mo_coeff, &
4011 eps_gradient=ec_env%eps_default, &
4012 iter_max=max_iter, &
4014 CALL calculate_subspace_eigenvalues(mo_coeff, matrix_ks(ispin, 1)%matrix, &
4015 evals_arg=eigenvalues, do_rotation=.true.)
4018 CALL destroy_preconditioner(local_preconditioner)
4019 DEALLOCATE (local_preconditioner)
4022 CALL copy_fm_to_dbcsr(mos(ispin)%mo_coeff, &
4023 mos(ispin)%mo_coeff_b)
4027 DO ispin = 1, nspins
4028 CALL calculate_density_matrix(mos(ispin), matrix_p(ispin, 1)%matrix)
4030 CALL calculate_w_matrix(mos(ispin), matrix_w(ispin, 1)%matrix)
4034 IF (dft_control%qs_control%do_ls_scf)
THEN
4035 DO ispin = 1, nspins
4036 CALL deallocate_mo_set(mos(ispin))
4038 IF (
ASSOCIATED(qs_env%mos))
THEN
4039 DO ispin = 1,
SIZE(qs_env%mos)
4040 CALL deallocate_mo_set(qs_env%mos(ispin))
4042 DEALLOCATE (qs_env%mos)
4046 CALL timestop(handle)
4048 END SUBROUTINE ec_ot_diag_solver
4056 SUBROUTINE response_force_error(qs_env, ec_env, unit_nr)
4057 TYPE(qs_environment_type),
POINTER :: qs_env
4058 TYPE(energy_correction_type),
POINTER :: ec_env
4059 INTEGER,
INTENT(IN) :: unit_nr
4061 CHARACTER(LEN=10) :: eformat
4062 INTEGER :: feunit, funit, i, ia, ib, ispin, mref, &
4063 na, nao, natom, nb, norb, nref, &
4065 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: natom_of_kind, rlist, t2cind
4066 LOGICAL :: debug_f, do_resp, is_source
4067 REAL(kind=dp) :: focc, rfac, vres
4068 REAL(kind=dp),
ALLOCATABLE,
DIMENSION(:) :: tvec, yvec
4069 REAL(kind=dp),
ALLOCATABLE,
DIMENSION(:, :) :: eforce, fmlocal, fmreord, smat
4070 REAL(kind=dp),
ALLOCATABLE,
DIMENSION(:, :, :) :: smpforce
4071 TYPE(atomic_kind_type),
DIMENSION(:),
POINTER :: atomic_kind_set
4072 TYPE(cp_fm_struct_type),
POINTER :: fm_struct, fm_struct_mat
4073 TYPE(cp_fm_type) :: hmats
4074 TYPE(cp_fm_type),
DIMENSION(:, :),
POINTER :: rpmos, spmos
4075 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_s
4076 TYPE(dbcsr_type),
POINTER :: mats
4077 TYPE(mp_para_env_type),
POINTER :: para_env
4078 TYPE(qs_force_type),
DIMENSION(:),
POINTER :: ks_force, res_force
4079 TYPE(virial_type) :: res_virial
4080 TYPE(virial_type),
POINTER :: ks_virial
4082 IF (unit_nr > 0)
THEN
4083 WRITE (unit_nr,
'(/,T2,A,A,A,A,A)')
"!", repeat(
"-", 25), &
4084 " Response Force Error Est. ", repeat(
"-", 25),
"!"
4085 SELECT CASE (ec_env%error_method)
4087 WRITE (unit_nr,
'(T2,A)')
" Response Force Error Est. using full RHS"
4089 WRITE (unit_nr,
'(T2,A)')
" Response Force Error Est. using delta RHS"
4091 WRITE (unit_nr,
'(T2,A)')
" Response Force Error Est. using extrapolated RHS"
4092 WRITE (unit_nr,
'(T2,A,E20.10)')
" Extrapolation cutoff:", ec_env%error_cutoff
4093 WRITE (unit_nr,
'(T2,A,I10)')
" Max. extrapolation size:", ec_env%error_subspace
4095 cpabort(
"Unknown Error Estimation Method")
4099 IF (abs(ec_env%orbrot_index) > 1.e-8_dp .OR. ec_env%phase_index > 1.e-8_dp)
THEN
4100 cpabort(
"Response error calculation for rotated orbital sets not implemented")
4103 SELECT CASE (ec_env%energy_functional)
4104 CASE (ec_functional_harris)
4105 cpwarn(
'Response force error calculation not possible for Harris functional.')
4106 CASE (ec_functional_dc)
4107 cpwarn(
'Response force error calculation not possible for DCDFT.')
4108 CASE (ec_functional_ext)
4111 CALL get_qs_env(qs_env, force=ks_force, virial=ks_virial, &
4112 atomic_kind_set=atomic_kind_set)
4113 CALL get_atomic_kind_set(atomic_kind_set=atomic_kind_set, natom_of_kind=natom_of_kind)
4115 CALL allocate_qs_force(res_force, natom_of_kind)
4116 DEALLOCATE (natom_of_kind)
4117 CALL zero_qs_force(res_force)
4118 res_virial = ks_virial
4119 CALL zero_virial(ks_virial, reset=.false.)
4120 CALL set_qs_env(qs_env, force=res_force)
4122 CALL get_qs_env(qs_env, natom=natom)
4123 ALLOCATE (eforce(3, natom))
4125 CALL get_qs_env(qs_env, para_env=para_env)
4126 is_source = para_env%is_source()
4128 nspins =
SIZE(ec_env%mo_occ)
4129 CALL cp_fm_get_info(ec_env%mo_occ(1), nrow_global=nao)
4132 CALL open_file(ec_env%exresperr_fn, file_status=
"OLD", file_action=
"READ", &
4133 file_form=
"FORMATTED", unit_number=funit)
4134 READ (funit,
'(A)') eformat
4135 CALL uppercase(eformat)
4136 READ (funit, *) nsample
4138 CALL para_env%bcast(nsample, para_env%source)
4139 CALL para_env%bcast(eformat, para_env%source)
4141 CALL cp_fm_get_info(ec_env%mo_occ(1), matrix_struct=fm_struct)
4142 CALL cp_fm_struct_create(fm_struct_mat, template_fmstruct=fm_struct, &
4143 nrow_global=nao, ncol_global=nao)
4144 ALLOCATE (fmlocal(nao, nao))
4145 IF (adjustl(trim(eformat)) ==
"TREXIO")
THEN
4146 ALLOCATE (fmreord(nao, nao))
4147 CALL get_t2cindex(qs_env, t2cind)
4149 ALLOCATE (rpmos(nsample, nspins))
4150 ALLOCATE (smpforce(3, natom, nsample))
4154 IF (nspins == 1) focc = 4.0_dp
4155 CALL cp_fm_create(hmats, fm_struct_mat)
4158 DO ispin = 1, nspins
4159 CALL cp_fm_create(rpmos(i, ispin), fm_struct)
4161 READ (funit, *) na, nb
4162 cpassert(na == nao .AND. nb == nao)
4163 READ (funit, *) fmlocal
4167 CALL para_env%bcast(fmlocal)
4169 SELECT CASE (adjustl(trim(eformat)))
4176 fmreord(ia, ib) = fmlocal(t2cind(ia), t2cind(ib))
4179 fmlocal(1:nao, 1:nao) = fmreord(1:nao, 1:nao)
4181 cpabort(
"Error file dE/dC: unknown format")
4184 CALL cp_fm_set_submatrix(hmats, fmlocal, 1, 1, nao, nao)
4185 CALL cp_fm_get_info(rpmos(i, ispin), ncol_global=norb)
4186 CALL parallel_gemm(
'N',
'N', nao, norb, nao, focc, hmats, &
4187 ec_env%mo_occ(ispin), 0.0_dp, rpmos(i, ispin))
4188 IF (ec_env%error_method ==
"D" .OR. ec_env%error_method ==
"E")
THEN
4189 CALL cp_fm_scale_and_add(1.0_dp, rpmos(i, ispin), -1.0_dp, ec_env%cpref(ispin))
4193 CALL cp_fm_struct_release(fm_struct_mat)
4194 IF (adjustl(trim(eformat)) ==
"TREXIO")
THEN
4195 DEALLOCATE (fmreord, t2cind)
4199 CALL close_file(funit)
4202 IF (unit_nr > 0)
THEN
4203 CALL open_file(ec_env%exresult_fn, file_status=
"OLD", file_form=
"FORMATTED", &
4204 file_action=
"WRITE", file_position=
"APPEND", unit_number=feunit)
4205 WRITE (feunit,
"(/,6X,A)")
" Response Forces from error sampling [Hartree/Bohr]"
4207 WRITE (feunit,
"(5X,I8)") i
4209 WRITE (feunit,
"(5X,3F20.12)") ec_env%rf(1:3, ia)
4213 debug_f = ec_env%debug_forces .OR. ec_env%debug_stress
4215 IF (ec_env%error_method ==
"E")
THEN
4216 CALL get_qs_env(qs_env, matrix_s=matrix_s)
4217 mats => matrix_s(1)%matrix
4218 ALLOCATE (spmos(nsample, nspins))
4220 DO ispin = 1, nspins
4221 CALL cp_fm_create(spmos(i, ispin), fm_struct, set_zero=.true.)
4222 CALL cp_dbcsr_sm_fm_multiply(mats, rpmos(i, ispin), spmos(i, ispin), norb)
4227 mref = ec_env%error_subspace
4228 mref = min(mref, nsample)
4230 ALLOCATE (smat(mref, mref), tvec(mref), yvec(mref), rlist(mref))
4233 CALL cp_fm_release(ec_env%cpmos)
4236 IF (unit_nr > 0)
THEN
4237 WRITE (unit_nr,
'(T2,A,I6)')
" Response Force Number ", i
4240 CALL zero_qs_force(res_force)
4241 CALL zero_virial(ks_virial, reset=.false.)
4242 DO ispin = 1, nspins
4243 CALL dbcsr_set(ec_env%matrix_hz(ispin)%matrix, 0.0_dp)
4246 ALLOCATE (ec_env%cpmos(nspins))
4247 DO ispin = 1, nspins
4248 CALL cp_fm_create(ec_env%cpmos(ispin), fm_struct)
4252 IF (ec_env%error_method ==
"F" .OR. ec_env%error_method ==
"D")
THEN
4253 DO ispin = 1, nspins
4254 CALL cp_fm_to_fm(rpmos(i, ispin), ec_env%cpmos(ispin))
4256 ELSE IF (ec_env%error_method ==
"E")
THEN
4257 CALL cp_extrapolate(rpmos, spmos, i, nref, rlist, smat, tvec, yvec, vres)
4258 IF (vres > ec_env%error_cutoff .OR. nref < min(5, mref))
THEN
4259 DO ispin = 1, nspins
4260 CALL cp_fm_to_fm(rpmos(i, ispin), ec_env%cpmos(ispin))
4265 DO ispin = 1, nspins
4266 CALL cp_fm_scale_and_add(1.0_dp, ec_env%cpmos(ispin), &
4267 rfac, rpmos(ia, ispin))
4273 IF (unit_nr > 0)
THEN
4274 WRITE (unit_nr,
'(T2,A,T60,I4,T69,F12.8)') &
4275 " Response Vector Extrapolation [nref|delta] = ", nref, vres
4278 cpabort(
"Unknown Error Estimation Method")
4282 CALL matrix_r_forces(qs_env, ec_env%cpmos, ec_env%mo_occ, &
4283 ec_env%matrix_w(1, 1)%matrix, unit_nr, &
4284 ec_env%debug_forces, ec_env%debug_stress)
4286 CALL response_calculation(qs_env, ec_env, silent=.true.)
4288 CALL response_force(qs_env, &
4289 vh_rspace=ec_env%vh_rspace, &
4290 vxc_rspace=ec_env%vxc_rspace, &
4291 vtau_rspace=ec_env%vtau_rspace, &
4292 vadmm_rspace=ec_env%vadmm_rspace, &
4293 matrix_hz=ec_env%matrix_hz, &
4294 matrix_pz=ec_env%matrix_z, &
4295 matrix_pz_admm=ec_env%z_admm, &
4296 matrix_wz=ec_env%matrix_wz, &
4297 rhopz_r=ec_env%rhoz_r, &
4298 zehartree=ec_env%ehartree, &
4300 zexc_aux_fit=ec_env%exc_aux_fit, &
4301 p_env=ec_env%p_env, &
4303 CALL total_qs_force(eforce, res_force, atomic_kind_set)
4304 CALL para_env%sum(eforce)
4306 IF (unit_nr > 0)
THEN
4307 WRITE (unit_nr,
'(T2,A)')
" Response Force Calculation is skipped. "
4312 IF (ec_env%error_method ==
"D")
THEN
4313 eforce(1:3, 1:natom) = eforce(1:3, 1:natom) + ec_env%rf(1:3, 1:natom)
4314 smpforce(1:3, 1:natom, i) = eforce(1:3, 1:natom)
4315 ELSE IF (ec_env%error_method ==
"E")
THEN
4319 eforce(1:3, 1:natom) = eforce(1:3, 1:natom) + rfac*smpforce(1:3, 1:natom, ia)
4321 smpforce(1:3, 1:natom, i) = eforce(1:3, 1:natom)
4322 eforce(1:3, 1:natom) = eforce(1:3, 1:natom) + ec_env%rf(1:3, 1:natom)
4323 IF (do_resp .AND. nref < mref)
THEN
4328 smpforce(1:3, 1:natom, i) = eforce(1:3, 1:natom)
4331 IF (unit_nr > 0)
THEN
4332 WRITE (unit_nr, *)
" FORCES"
4334 WRITE (unit_nr,
"(i7,3F11.6,6X,3F11.6)") ia, eforce(1:3, ia), &
4335 (eforce(1:3, ia) - ec_env%rf(1:3, ia))
4339 WRITE (feunit,
"(5X,I8)") i
4341 WRITE (feunit,
"(5X,3F20.12)") eforce(1:3, ia)
4345 CALL cp_fm_release(ec_env%cpmos)
4349 IF (unit_nr > 0)
THEN
4350 CALL close_file(feunit)
4353 DEALLOCATE (smat, tvec, yvec, rlist)
4355 CALL cp_fm_release(hmats)
4356 CALL cp_fm_release(rpmos)
4357 IF (ec_env%error_method ==
"E")
THEN
4358 CALL cp_fm_release(spmos)
4361 DEALLOCATE (eforce, smpforce)
4364 CALL get_qs_env(qs_env, force=res_force, virial=ks_virial)
4365 CALL set_qs_env(qs_env, force=ks_force)
4366 CALL deallocate_qs_force(res_force)
4367 ks_virial = res_virial
4370 cpabort(
"unknown energy correction")
4373 END SUBROUTINE response_force_error
4387 SUBROUTINE cp_extrapolate(rpmos, Spmos, ip, nref, rlist, smat, tvec, yvec, vres)
4388 TYPE(cp_fm_type),
DIMENSION(:, :),
POINTER :: rpmos, spmos
4389 INTEGER,
INTENT(IN) :: ip, nref
4390 INTEGER,
DIMENSION(:),
INTENT(IN) :: rlist
4391 REAL(kind=dp),
DIMENSION(:, :),
INTENT(INOUT) :: smat
4392 REAL(kind=dp),
DIMENSION(:),
INTENT(INOUT) :: tvec, yvec
4393 REAL(kind=dp),
INTENT(OUT) :: vres
4395 INTEGER :: i, ia, j, ja
4396 REAL(kind=dp) :: aval
4397 REAL(kind=dp),
ALLOCATABLE,
DIMENSION(:, :) :: sinv
4405 ALLOCATE (sinv(nref, nref))
4409 tvec(i) = ctrace(rpmos(ip, :), spmos(ia, :))
4412 smat(j, i) = ctrace(rpmos(ja, :), spmos(ia, :))
4413 smat(i, j) = smat(j, i)
4415 smat(i, i) = ctrace(rpmos(ia, :), spmos(ia, :))
4417 aval = ctrace(rpmos(ip, :), spmos(ip, :))
4419 sinv(1:nref, 1:nref) = smat(1:nref, 1:nref)
4420 CALL invmat_symm(sinv(1:nref, 1:nref))
4422 yvec(1:nref) = matmul(sinv(1:nref, 1:nref), tvec(1:nref))
4424 vres = aval - sum(yvec(1:nref)*tvec(1:nref))
4425 vres = sqrt(abs(vres))
4432 END SUBROUTINE cp_extrapolate
4440 FUNCTION ctrace(ca, cb)
4441 TYPE(cp_fm_type),
DIMENSION(:) :: ca, cb
4442 REAL(kind=dp) :: ctrace
4445 REAL(kind=dp) :: trace
4451 CALL cp_fm_trace(ca(is), cb(is), trace)
4452 ctrace = ctrace + trace
4462 SUBROUTINE get_t2cindex(qs_env, t2cind)
4463 TYPE(qs_environment_type),
POINTER :: qs_env
4464 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: t2cind
4466 INTEGER :: i, iatom, ikind, is, iset, ishell, k, l, &
4467 m, natom, nset, nsgf, numshell
4468 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: lshell
4469 INTEGER,
DIMENSION(:),
POINTER :: nshell
4470 INTEGER,
DIMENSION(:, :),
POINTER :: lval
4471 TYPE(gto_basis_set_type),
POINTER :: basis_set
4472 TYPE(particle_type),
DIMENSION(:),
POINTER :: particle_set
4473 TYPE(qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
4477 CALL get_qs_env(qs_env, qs_kind_set=qs_kind_set, particle_set=particle_set, natom=natom)
4478 CALL get_qs_kind_set(qs_kind_set, nshell=numshell, nsgf=nsgf)
4480 ALLOCATE (t2cind(nsgf))
4481 ALLOCATE (lshell(numshell))
4485 CALL get_atomic_kind(particle_set(iatom)%atomic_kind, kind_number=ikind)
4486 CALL get_qs_kind(qs_kind_set(ikind), basis_set=basis_set, basis_type=
"ORB")
4487 CALL get_gto_basis_set(basis_set, nset=nset, nshell=nshell, l=lval)
4489 DO is = 1, nshell(iset)
4498 DO ishell = 1, numshell
4501 m = (-1)**k*floor(real(k, kind=dp)/2.0_dp)
4502 t2cind(i + l + 1 + m) = i + k
4509 END SUBROUTINE get_t2cindex
subroutine, public accint_weight_force(qs_env, rho, rho1, order, xc_section, triplet)
...
Contains ADMM methods which only require the density matrix.
subroutine, public admm_dm_calc_rho_aux(qs_env)
Entry methods: Calculates auxiliary density matrix from primary one.
Contains ADMM methods which require molecular orbitals.
subroutine, public admm_mo_calc_rho_aux(qs_env)
...
Types and set/get functions for auxiliary density matrix methods.
Define the atomic kind types and their sub types.
subroutine, public get_atomic_kind_set(atomic_kind_set, atom_of_kind, kind_of, natom_of_kind, maxatom, natom, nshell, fist_potential_present, shell_present, shell_adiabatic, shell_check_distance, damping_present)
Get attributes of an atomic kind set.
subroutine, public get_atomic_kind(atomic_kind, fist_potential, element_symbol, name, mass, kind_number, natom, atom_list, rcov, rvdw, z, qeff, apol, cpol, mm_radius, shell, shell_active, damping)
Get attributes of an atomic kind.
subroutine, public get_gto_basis_set(gto_basis_set, name, aliases, norm_type, kind_radius, ncgf, nset, nsgf, cgf_symbol, sgf_symbol, norm_cgf, set_radius, lmax, lmin, lx, ly, lz, m, ncgf_set, npgf, nsgf_set, nshell, cphi, pgf_radius, sphi, scon, zet, first_cgf, first_sgf, l, last_cgf, last_sgf, n, gcc, maxco, maxl, maxpgf, maxsgf_set, maxshell, maxso, nco_sum, npgf_sum, nshell_sum, maxder, short_kind_radius, npgf_seg_sum)
...
collects all references to literature in CP2K as new algorithms / method are included from literature...
integer, save, public belleflamme2023
Handles all functions related to the CELL.
methods related to the blacs parallel environment
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
subroutine, public dbcsr_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_scale_and_add(alpha, matrix_a, beta, matrix_b)
calc A <- alpha*A + beta*B optimized for alpha == 1.0 (just add beta*B) and beta == 0....
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_get_info(matrix, name, nrow_global, ncol_global, nrow_block, ncol_block, nrow_local, ncol_local, row_indices, col_indices, local_data, context, nrow_locals, ncol_locals, matrix_struct, para_env)
returns all kind of information about the full matrix
subroutine, public cp_fm_create(matrix, matrix_struct, name, use_sp, nrow, ncol, set_zero)
creates a new full matrix with the given structure
subroutine, public cp_fm_set_submatrix(fm, new_values, start_row, start_col, n_rows, n_cols, alpha, beta, transpose)
sets a submatrix of a full matrix fm(start_row:start_row+n_rows,start_col:start_col+n_cols) = alpha*o...
subroutine, public cp_fm_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
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.
subroutine, public ec_env_potential_release(ec_env)
...
Routines for an external energy correction on top of a Kohn-Sham calculation.
subroutine, public ec_ext_energy(qs_env, ec_env, calculate_forces)
External energy method.
subroutine, public matrix_r_forces(qs_env, cpmos, mo_occ, matrix_r, unit_nr, debug_forces, debug_stress)
...
Routines used for Harris functional Kohn-Sham calculation.
subroutine, public 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.
subroutine, public init_coulomb_local(hartree_local, natom)
...
subroutine, public vh_1c_gg_integrals(qs_env, energy_hartree_1c, ecoul_1c, local_rho_set, para_env, tddft, local_rho_set_2nd, core_2nd)
Calculates one center GAPW Hartree energies and matrix elements Hartree potentials are input Takes po...
subroutine, public hartree_local_release(hartree_local)
...
subroutine, public hartree_local_create(hartree_local)
...
Routines to calculate EXX in RPA and energy correction methods.
subroutine, public calculate_exx(qs_env, unit_nr, hfx_sections, x_data, do_gw, do_admm, calc_forces, reuse_hfx, do_im_time, e_ex_from_gw, e_admm_from_gw, t3)
...
subroutine, public add_exx_to_rhs(rhs, qs_env, ext_hfx_section, x_data, recalc_integrals, do_admm, do_ec, do_exx, reuse_hfx)
Add the EXX contribution to the RHS of the Z-vector equation, namely the HF Hamiltonian.
Defines the basic variable types.
integer, parameter, public dp
integer, parameter, public default_string_length
integer, parameter, public default_path_length
Calculate MAO's and analyze wavefunctions.
subroutine, public mao_generate_basis(qs_env, mao_coef, ref_basis_set, pmat_external, smat_external, molecular, max_iter, eps_grad, nmao_external, eps1_mao, iolevel, unit_nr)
...
Collection of simple mathematical functions and subroutines.
subroutine, public invmat_symm(a, potrf, uplo)
returns inverse of real symmetric, positive definite matrix
Interface to the message passing library MPI.
Define the data structure for the molecule information.
Calculates the moment integrals <a|r^m|b>
subroutine, public get_reference_point(rpoint, drpoint, qs_env, fist_env, reference, ref_point, ifirst, ilast)
...
basic linear algebra operations for full matrixes
Define the data structure for the particle information.
subroutine, public get_paw_proj_set(paw_proj_set, csprj, chprj, first_prj, first_prjs, last_prj, local_oce_sphi_h, local_oce_sphi_s, maxl, ncgauprj, nsgauprj, nsatbas, nsotot, nprj, o2nindex, n2oindex, rcprj, rzetprj, zisomin, zetprj)
Get informations about a paw projectors set.
Periodic Table related data definitions.
type(atom), dimension(0:nelem), public ptable
Definition of physical constants:
real(kind=dp), parameter, public pascal
real(kind=dp), parameter, public bohr
real(kind=dp), parameter, public debye
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.
Calculation of the core Hamiltonian integral matrix <a|H|b> over Cartesian Gaussian-type functions.
subroutine, public kinetic_energy_matrix(qs_env, matrixkp_t, matrix_t, matrix_p, matrix_name, calculate_forces, nderivative, sab_orb, eps_filter, basis_type, debug_forces, debug_stress)
Calculate kinetic energy matrix and possible relativistic correction.
subroutine, public core_matrices(qs_env, matrix_h, matrix_p, calculate_forces, nder, ec_env, dcdr_env, ec_env_matrices, basis_type, debug_forces, debug_stress, atcore)
...
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, mimic, sac_ae, sac_ppl, sac_lri, sap_ppnl, sab_vdw, sab_scp, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, sab_xb, sab_xtb_pp, sab_xtb_nonbond, sab_almo, sab_kp, sab_kp_nosym, sab_cneo, particle_set, energy, force, matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, run_rtp, rtp, matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_ks_im_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, matrix_s_ri_aux_kp, matrix_s, matrix_s_ri_aux, matrix_w, matrix_p_mp2, matrix_p_mp2_admm, rho, rho_xc, pw_env, ewald_env, ewald_pw, active_space, mpools, input, para_env, blacs_env, scf_control, rel_control, kinetic, qs_charges, vppl, xcint_weights, rho_core, rho_nlcc, rho_nlcc_g, ks_env, ks_qmmm_env, wf_history, scf_env, local_particles, local_molecules, distribution_2d, dbcsr_dist, molecule_kind_set, molecule_set, subsys, cp_subsys, oce, local_rho_set, rho_atom_set, task_list, task_list_soft, rho0_atom_set, rho0_mpole, rhoz_set, rhoz_cneo_set, ecoul_1c, rho0_s_rs, rho0_s_gs, rhoz_cneo_s_rs, rhoz_cneo_s_gs, do_kpoints, has_unit_metric, requires_mo_derivs, mo_derivs, mo_loc_history, nkind, natom, nelectron_total, nelectron_spin, efield, neighbor_list_id, linres_control, xas_env, virial, cp_ddapc_env, cp_ddapc_ewald, outer_scf_history, outer_scf_ihistory, x_data, et_coupling, dftb_potential, results, se_taper, se_store_int_env, se_nddo_mpole, se_nonbond_env, admm_env, lri_env, lri_density, exstate_env, ec_env, harris_env, dispersion_env, gcp_env, vee, rho_external, external_vxc, mask, mp2_env, bs_env, kg_env, wanniercentres, atprop, ls_scf_env, do_transport, transport_env, v_hartree_rspace, s_mstruct_changed, rho_changed, potential_changed, forces_up_to_date, mscfg_env, almo_scf_env, gradient_history, variable_history, embed_pot, spin_embed_pot, polar_env, mos_last_converged, eeq, rhs, do_rixs, tb_tblite)
Get the QUICKSTEP environment.
subroutine, public set_qs_env(qs_env, super_cell, mos, qmmm, qmmm_periodic, mimic, ewald_env, ewald_pw, mpools, rho_external, external_vxc, mask, scf_control, rel_control, qs_charges, ks_env, ks_qmmm_env, wf_history, scf_env, active_space, input, oce, rho_atom_set, rho0_atom_set, rho0_mpole, run_rtp, rtp, rhoz_set, rhoz_tot, ecoul_1c, has_unit_metric, requires_mo_derivs, mo_derivs, mo_loc_history, efield, rhoz_cneo_set, linres_control, xas_env, cp_ddapc_env, cp_ddapc_ewald, outer_scf_history, outer_scf_ihistory, x_data, et_coupling, dftb_potential, se_taper, se_store_int_env, se_nddo_mpole, se_nonbond_env, admm_env, ls_scf_env, do_transport, transport_env, lri_env, lri_density, exstate_env, ec_env, dispersion_env, harris_env, gcp_env, mp2_env, bs_env, kg_env, force, kpoints, wanniercentres, almo_scf_env, gradient_history, variable_history, embed_pot, spin_embed_pot, polar_env, mos_last_converged, eeq, rhs, do_rixs, tb_tblite)
Set the QUICKSTEP environment.
subroutine, public deallocate_qs_force(qs_force)
Deallocate a Quickstep force data structure.
subroutine, public zero_qs_force(qs_force)
Initialize a Quickstep force data structure.
subroutine, public allocate_qs_force(qs_force, natom_of_kind)
Allocate a Quickstep force data structure.
subroutine, public total_qs_force(force, qs_force, atomic_kind_set)
Get current total force.
subroutine, public prepare_gapw_den(qs_env, local_rho_set, do_rho0, kind_set_external, pw_env_sub)
...
Integrate single or product functions over a potential on a RS grid.
Define the quickstep kind type and their sub types.
subroutine, public get_qs_kind(qs_kind, basis_set, basis_type, ncgf, nsgf, all_potential, tnadd_potential, gth_potential, sgp_potential, upf_potential, cneo_potential, se_parameter, dftb_parameter, xtb_parameter, dftb3_param, zatom, zeff, elec_conf, mao, lmax_dftb, alpha_core_charge, ccore_charge, core_charge, core_charge_radius, paw_proj_set, paw_atom, hard_radius, hard0_radius, max_rad_local, covalent_radius, vdw_radius, gpw_type_forced, harmonics, max_iso_not0, max_s_harm, grid_atom, ngrid_ang, ngrid_rad, lmax_rho0, dft_plus_u_atom, l_of_dft_plus_u, n_of_dft_plus_u, u_minus_j, u_of_dft_plus_u, j_of_dft_plus_u, alpha_of_dft_plus_u, beta_of_dft_plus_u, j0_of_dft_plus_u, occupation_of_dft_plus_u, dispersion, bs_occupation, magnetization, no_optimize, addel, laddel, naddel, orbitals, max_scf, eps_scf, smear, u_ramping, u_minus_j_target, eps_u_ramping, init_u_ramping_each_scf, reltmat, ghost, monovalent, floating, name, element_symbol, pao_basis_size, pao_model_file, pao_potentials, pao_descriptors, nelec)
Get attributes of an atomic kind.
subroutine, public get_qs_kind_set(qs_kind_set, all_potential_present, tnadd_potential_present, gth_potential_present, sgp_potential_present, paw_atom_present, dft_plus_u_atom_present, maxcgf, maxsgf, maxco, maxco_proj, maxgtops, maxlgto, maxlprj, maxnset, maxsgf_set, ncgf, npgf, nset, nsgf, nshell, maxpol, maxlppl, maxlppnl, maxppnl, nelectron, maxder, max_ngrid_rad, max_sph_harm, maxg_iso_not0, lmax_rho0, basis_rcut, basis_type, total_zeff_corr, npgf_seg, cneo_potential_present, nkind_q, natom_q)
Get attributes of an atomic kind set.
Calculation of kinetic energy matrix and forces.
subroutine, public build_kinetic_matrix(ks_env, matrix_t, matrixkp_t, matrix_name, basis_type, sab_nl, calculate_forces, matrix_p, matrixkp_p, eps_filter, nderivative)
Calculation of the kinetic energy matrix over Cartesian Gaussian functions.
routines that build the Kohn-Sham matrix contributions coming from local atomic densities
subroutine, public update_ks_atom(qs_env, ksmat, pmat, forces, tddft, rho_atom_external, kind_set_external, oce_external, sab_external, kscale, kintegral, kforce, fscale)
The correction to the KS matrix due to the GAPW local terms to the hartree and XC contributions is he...
routines that build the Kohn-Sham matrix (i.e calculate the coulomb and xc parts
subroutine, public calc_rho_tot_gspace(rho_tot_gspace, qs_env, rho, skip_nuclear_density)
...
Calculate the KS reference potentials.
subroutine, public ks_ref_potential(qs_env, vh_rspace, vxc_rspace, vtau_rspace, vadmm_rspace, ehartree, exc, h_stress)
calculate the Kohn-Sham reference potential
subroutine, public ks_ref_potential_atom(qs_env, local_rho_set, local_rho_set_admm, v_hartree_rspace)
calculate the Kohn-Sham GAPW reference potentials
subroutine, public local_rho_set_create(local_rho_set)
...
subroutine, public local_rho_set_release(local_rho_set)
...
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.
Routines for the construction of the coefficients for the expansion of the atomic densities rho1_hard...
subroutine, public build_oce_matrices(intac, calculate_forces, nder, qs_kind_set, particle_set, sap_oce, eps_fit)
Set up the sparse matrix for the coefficients of one center expansions This routine uses the same log...
subroutine, public allocate_oce_set(oce_set, nkind)
Allocate and initialize the matrix set of oce coefficients.
subroutine, public create_oce_set(oce_set)
...
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.
subroutine, public rho0_s_grid_create(pw_env, rho0_mpole)
...
subroutine, public integrate_vhg0_rspace(qs_env, v_rspace, para_env, calculate_forces, local_rho_set, local_rho_set_2nd, atener, kforce, my_pools, my_rs_descs)
...
subroutine, public init_rho0(local_rho_set, qs_env, gapw_control, zcore)
...
subroutine, public allocate_rho_atom_internals(rho_atom_set, atomic_kind_set, qs_kind_set, dft_control, para_env)
...
subroutine, public calculate_rho_atom_coeff(qs_env, rho_ao, rho_atom_set, qs_kind_set, oce, sab, para_env)
...
superstucture that hold various representations of the density and keeps track of which ones are vali...
subroutine, public qs_rho_get(rho_struct, rho_ao, rho_ao_im, rho_ao_kp, rho_ao_im_kp, rho_r, drho_r, rho_g, drho_g, tau_r, tau_g, rho_r_valid, drho_r_valid, rho_g_valid, drho_g_valid, tau_r_valid, tau_g_valid, tot_rho_r, tot_rho_g, rho_r_sccs, soft_valid, complex_rho_ao)
returns info about the density described by this object. If some representation is not available an e...
routines that build the integrals of the Vxc potential calculated for the atomic density in the basis...
subroutine, public calculate_vxc_atom(qs_env, energy_only, exc1, adiabatic_rescale_factor, kind_set_external, rho_atom_set_external, xc_section_external)
...
subroutine, public qs_vxc_create(ks_env, rho_struct, xc_section, vxc_rho, vxc_tau, exc, just_energy, edisp, dispersion_env, adiabatic_rescale_factor, pw_env_external)
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, silent)
Initializes solver of linear response equation for energy correction.
Utilities for string manipulations.
elemental subroutine, public uppercase(string)
Convert all lower case characters in a string to upper case.
generate the tasks lists used by collocate and integrate routines
subroutine, public generate_qs_task_list(ks_env, task_list, basis_type, reorder_rs_grid_ranks, skip_load_balance_distributed, pw_env_external, sab_orb_external)
...
subroutine, public deallocate_task_list(task_list)
deallocates the components and the object itself
subroutine, public allocate_task_list(task_list)
allocates and initialised the components of the task_list_type
The module to read/write TREX IO files for interfacing CP2K with other programs.
subroutine, public write_trexio(qs_env, trexio_section, energy_derivative)
Write a trexio file.
subroutine, public write_stress_tensor(pv_virial, iw, cell, unit_string, numerical)
Print stress tensor to output file.
subroutine, public write_stress_tensor_components(virial, iw, cell, unit_string)
...
pure real(kind=dp) function, public one_third_sum_diag(a)
...
subroutine, public zero_virial(virial, reset)
...
subroutine, public symmetrize_virial(virial)
Symmetrize the virial components.
Interface for Voronoi Integration and output of BQB files.
subroutine, public entry_voronoi_or_bqb(do_voro, do_bqb, input_voro, input_bqb, unit_voro, qs_env, rspace_pw)
Does a Voronoi integration of density or stores the density to compressed BQB format.
stores some data used in wavefunction fitting
Provides all information about an atomic kind.
Type defining parameters related to the simulation cell.
represent a blacs multidimensional parallel environment (for the mpi corrispective see cp_paratypes/m...
keeps the information about the structure of a full matrix
type of a logger, at the moment it contains just a print level starting at which level it should be l...
contains arbitrary information which need to be stored
structure to store local (to a processor) ordered lists of integers.
distributes pairs on a 2d grid of processors
Contains information on the energy correction functional for KG.
stores all the informations relevant to an mpi environment
contained for different pw related things
environment for the poisson solver
to create arrays of pools
Manages a pool of grids (to be used for example as tmp objects), but can also be used to instantiate ...
Provides all information about a quickstep kind.
calculation environment to calculate the ks matrix, holds all the needed vars. assumes that the core ...
keeps the density in various representations, keeping track of which ones are valid.