195#include "./base/base_uses.f90"
203 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'energy_corrections'
224 LOGICAL,
INTENT(IN),
OPTIONAL :: ec_init, calculate_forces
226 CHARACTER(len=*),
PARAMETER :: routinen =
'energy_correction'
228 INTEGER :: handle, unit_nr
229 LOGICAL :: my_calc_forces
236 CALL timeset(routinen, handle)
239 IF (logger%para_env%is_source())
THEN
251 IF (.NOT. ec_env%do_skip)
THEN
253 ec_env%should_update = .true.
254 IF (
PRESENT(ec_init)) ec_env%should_update = ec_init
256 my_calc_forces = .false.
257 IF (
PRESENT(calculate_forces)) my_calc_forces = calculate_forces
259 IF (ec_env%should_update)
THEN
260 ec_env%old_etotal = 0.0_dp
261 ec_env%etotal = 0.0_dp
262 ec_env%eband = 0.0_dp
263 ec_env%ehartree = 0.0_dp
267 ec_env%edispersion = 0.0_dp
268 ec_env%exc_aux_fit = 0.0_dp
272 ec_env%old_etotal = energy%total
276 IF (my_calc_forces)
THEN
277 IF (unit_nr > 0)
THEN
278 WRITE (unit_nr,
'(T2,A,A,A,A,A)')
"!", repeat(
"-", 25), &
279 " Energy Correction Forces ", repeat(
"-", 26),
"!"
281 CALL get_qs_env(qs_env, force=ks_force, virial=virial)
285 IF (unit_nr > 0)
THEN
286 WRITE (unit_nr,
'(T2,A,A,A,A,A)')
"!", repeat(
"-", 29), &
287 " Energy Correction ", repeat(
"-", 29),
"!"
292 CALL energy_correction_low(qs_env, ec_env, my_calc_forces, unit_nr)
295 IF (ec_env%should_update)
THEN
296 energy%nonscf_correction = ec_env%etotal - ec_env%old_etotal
297 energy%total = ec_env%etotal
300 IF (.NOT. my_calc_forces .AND. unit_nr > 0)
THEN
301 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Energy Correction ", energy%nonscf_correction
303 IF (unit_nr > 0)
THEN
304 WRITE (unit_nr,
'(T2,A,A,A)')
"!", repeat(
"-", 77),
"!"
311 IF (unit_nr > 0)
THEN
312 WRITE (unit_nr,
'(T2,A,A,A)')
"!", repeat(
"-", 77),
"!"
313 WRITE (unit_nr,
'(T2,A,A,A,A,A)')
"!", repeat(
"-", 26), &
314 " Skip Energy Correction ", repeat(
"-", 27),
"!"
315 WRITE (unit_nr,
'(T2,A,A,A)')
"!", repeat(
"-", 77),
"!"
320 CALL timestop(handle)
335 SUBROUTINE energy_correction_low(qs_env, ec_env, calculate_forces, unit_nr)
338 LOGICAL,
INTENT(IN) :: calculate_forces
339 INTEGER,
INTENT(IN) :: unit_nr
341 INTEGER :: ispin, nspins
348 IF (ec_env%should_update)
THEN
349 CALL ec_build_neighborlist(qs_env, ec_env)
353 ec_env%vtau_rspace, &
354 ec_env%vadmm_rspace, &
355 ec_env%ehartree, exc)
357 SELECT CASE (ec_env%energy_functional)
360 CALL ec_build_core_hamiltonian(qs_env, ec_env)
361 CALL ec_build_ks_matrix(qs_env, ec_env)
366 NULLIFY (ec_env%mao_coef)
367 CALL mao_generate_basis(qs_env, ec_env%mao_coef, ref_basis_set=
"HARRIS", molecular=.true., &
368 max_iter=ec_env%mao_max_iter, eps_grad=ec_env%mao_eps_grad, &
369 eps1_mao=ec_env%mao_eps1, iolevel=ec_env%mao_iolevel, unit_nr=unit_nr)
372 CALL ec_ks_solver(qs_env, ec_env)
374 CALL evaluate_ec_core_matrix_traces(qs_env, ec_env)
379 CALL ec_dc_energy(qs_env, ec_env, calculate_forces=.false.)
384 CALL ec_build_ks_matrix(qs_env, ec_env)
391 cpabort(
"unknown energy correction")
395 CALL ec_disp(qs_env, ec_env, calculate_forces=.false.)
398 CALL ec_energy(ec_env, unit_nr)
402 IF (calculate_forces)
THEN
404 debug_f = ec_env%debug_forces .OR. ec_env%debug_stress
406 CALL ec_disp(qs_env, ec_env, calculate_forces=.true.)
408 SELECT CASE (ec_env%energy_functional)
411 CALL ec_build_core_hamiltonian_force(qs_env, ec_env, &
415 CALL ec_build_ks_matrix_force(qs_env, ec_env)
416 IF (ec_env%debug_external)
THEN
417 CALL write_response_interface(qs_env, ec_env)
418 CALL init_response_deriv(qs_env, ec_env)
425 CALL ec_dc_energy(qs_env, ec_env, calculate_forces=.true.)
427 CALL ec_build_core_hamiltonian_force(qs_env, ec_env, &
431 CALL ec_dc_build_ks_matrix_force(qs_env, ec_env)
432 IF (ec_env%debug_external)
THEN
433 CALL write_response_interface(qs_env, ec_env)
434 CALL init_response_deriv(qs_env, ec_env)
439 CALL init_response_deriv(qs_env, ec_env)
443 cpabort(
"unknown energy correction")
450 CALL get_qs_env(qs_env=qs_env, dft_control=dft_control, pw_env=pw_env)
451 nspins = dft_control%nspins
453 cpassert(
ASSOCIATED(pw_env))
454 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
455 ALLOCATE (ec_env%rhoz_r(nspins))
457 CALL auxbas_pw_pool%create_pw(ec_env%rhoz_r(ispin))
461 vh_rspace=ec_env%vh_rspace, &
462 vxc_rspace=ec_env%vxc_rspace, &
463 vtau_rspace=ec_env%vtau_rspace, &
464 vadmm_rspace=ec_env%vadmm_rspace, &
465 matrix_hz=ec_env%matrix_hz, &
466 matrix_pz=ec_env%matrix_z, &
467 matrix_pz_admm=ec_env%z_admm, &
468 matrix_wz=ec_env%matrix_wz, &
469 rhopz_r=ec_env%rhoz_r, &
470 zehartree=ec_env%ehartree, &
472 zexc_aux_fit=ec_env%exc_aux_fit, &
473 p_env=ec_env%p_env, &
476 CALL output_response_deriv(qs_env, ec_env, unit_nr)
478 CALL ec_properties(qs_env, ec_env)
481 IF (
ASSOCIATED(ec_env%rhoout_r))
THEN
483 CALL auxbas_pw_pool%give_back_pw(ec_env%rhoout_r(ispin))
485 DEALLOCATE (ec_env%rhoout_r)
487 IF (
ASSOCIATED(ec_env%rhoz_r))
THEN
489 CALL auxbas_pw_pool%give_back_pw(ec_env%rhoz_r(ispin))
491 DEALLOCATE (ec_env%rhoz_r)
507 END SUBROUTINE energy_correction_low
515 SUBROUTINE write_response_interface(qs_env, ec_env)
522 NULLIFY (trexio_section)
526 CALL write_trexio(qs_env, trexio_section, ec_env%matrix_hz)
528 END SUBROUTINE write_response_interface
536 SUBROUTINE init_response_deriv(qs_env, ec_env)
546 ALLOCATE (ec_env%rf(3, natom), ec_env%rferror(3, natom))
548 ec_env%rferror = 0.0_dp
550 ec_env%rpverror = 0.0_dp
551 CALL get_qs_env(qs_env, force=force, virial=virial)
553 CALL get_qs_env(qs_env, atomic_kind_set=atomic_kind_set)
556 IF (virial%pv_availability .AND. (.NOT. virial%pv_numer))
THEN
557 ec_env%rpv = virial%pv_virial
560 END SUBROUTINE init_response_deriv
569 SUBROUTINE output_response_deriv(qs_env, ec_env, unit_nr)
572 INTEGER,
INTENT(IN) :: unit_nr
574 CHARACTER(LEN=default_string_length) :: unit_string
575 INTEGER :: funit, ia, natom
576 REAL(kind=
dp) :: fconv
577 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: ftot
585 IF (
ASSOCIATED(ec_env%rf))
THEN
587 ALLOCATE (ftot(3, natom))
589 CALL get_qs_env(qs_env, force=force, virial=virial, para_env=para_env)
591 CALL get_qs_env(qs_env, atomic_kind_set=atomic_kind_set)
593 ec_env%rf(1:3, 1:natom) = ftot(1:3, 1:natom) - ec_env%rf(1:3, 1:natom)
594 CALL para_env%sum(ec_env%rf)
597 IF (virial%pv_availability .AND. (.NOT. virial%pv_numer))
THEN
598 ec_env%rpv = virial%pv_virial - ec_env%rpv
599 CALL para_env%sum(ec_env%rpv)
602 CALL get_qs_env(qs_env, particle_set=particle_set, cell=cell)
606 IF (unit_nr > 0)
THEN
607 WRITE (unit_nr,
'(T2,A)')
"Write EXTERNAL Response Derivative: "//trim(ec_env%exresult_fn)
609 CALL open_file(ec_env%exresult_fn, file_status=
"REPLACE", file_form=
"FORMATTED", &
610 file_action=
"WRITE", unit_number=funit)
611 WRITE (funit, *)
" COORDINATES // RESPONSE FORCES // ERRORS "
612 WRITE (funit, *)
" [Bohr] // [Hartree/Bohr] // "
614 WRITE (funit,
"(3(3F15.8,5x))") particle_set(ia)%r(1:3), &
615 ec_env%rf(1:3, ia), ec_env%rferror(1:3, ia)
618 WRITE (funit, *)
" CELL // RESPONSE PRESSURE // ERRORS "
619 WRITE (funit, *)
" [Bohr] // [GPa] // "
621 WRITE (funit,
"(3F15.8,5x,3F15.8,5x,3F15.8)") cell%hmat(ia, 1:3), &
622 fconv*ec_env%rpv(ia, 1:3), ec_env%rpverror(ia, 1:3)
629 END SUBROUTINE output_response_deriv
638 SUBROUTINE evaluate_ec_core_matrix_traces(qs_env, ec_env)
642 CHARACTER(LEN=*),
PARAMETER :: routinen =
'evaluate_ec_core_matrix_traces'
648 CALL timeset(routinen, handle)
651 CALL get_qs_env(qs_env, dft_control=dft_control, energy=energy)
654 CALL calculate_ptrace(ec_env%matrix_h, ec_env%matrix_p, energy%core, dft_control%nspins)
657 CALL calculate_ptrace(ec_env%matrix_t, ec_env%matrix_p, energy%kinetic, dft_control%nspins)
659 CALL timestop(handle)
661 END SUBROUTINE evaluate_ec_core_matrix_traces
674 SUBROUTINE ec_dc_energy(qs_env, ec_env, calculate_forces)
677 LOGICAL,
INTENT(IN) :: calculate_forces
679 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ec_dc_energy'
681 CHARACTER(LEN=default_string_length) :: headline
682 INTEGER :: handle, ispin, nspins
683 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_h, matrix_p, matrix_s, matrix_w
688 CALL timeset(routinen, handle)
690 NULLIFY (dft_control, ks_env, matrix_h, matrix_p, matrix_s, matrix_w, rho)
692 dft_control=dft_control, &
694 matrix_h_kp=matrix_h, &
695 matrix_s_kp=matrix_s, &
696 matrix_w_kp=matrix_w, &
699 nspins = dft_control%nspins
704 matrix_name=
"OVERLAP MATRIX", &
705 basis_type_a=
"HARRIS", &
706 basis_type_b=
"HARRIS", &
707 sab_nl=ec_env%sab_orb)
712 headline =
"CORE HAMILTONIAN MATRIX"
713 ALLOCATE (ec_env%matrix_h(1, 1)%matrix)
714 CALL dbcsr_create(ec_env%matrix_h(1, 1)%matrix, name=trim(headline), &
715 template=matrix_s(1, 1)%matrix, matrix_type=dbcsr_type_symmetric)
717 CALL dbcsr_copy(ec_env%matrix_h(1, 1)%matrix, matrix_h(1, 1)%matrix)
722 headline =
"DENSITY MATRIX"
724 ALLOCATE (ec_env%matrix_p(ispin, 1)%matrix)
725 CALL dbcsr_create(ec_env%matrix_p(ispin, 1)%matrix, name=trim(headline), &
726 template=matrix_s(1, 1)%matrix, matrix_type=dbcsr_type_symmetric)
728 CALL dbcsr_copy(ec_env%matrix_p(ispin, 1)%matrix, matrix_p(ispin, 1)%matrix)
731 IF (calculate_forces)
THEN
736 headline =
"ENERGY-WEIGHTED DENSITY MATRIX"
738 ALLOCATE (ec_env%matrix_w(ispin, 1)%matrix)
739 CALL dbcsr_create(ec_env%matrix_w(ispin, 1)%matrix, name=trim(headline), &
740 template=matrix_s(1, 1)%matrix, matrix_type=dbcsr_type_symmetric)
742 CALL dbcsr_copy(ec_env%matrix_w(ispin, 1)%matrix, matrix_w(ispin, 1)%matrix)
748 ec_env%efield_nuclear = 0.0_dp
749 ec_env%efield_elec = 0.0_dp
752 CALL timestop(handle)
754 END SUBROUTINE ec_dc_energy
765 SUBROUTINE ec_dc_build_ks_matrix_force(qs_env, ec_env)
769 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ec_dc_build_ks_matrix_force'
771 CHARACTER(LEN=default_string_length) :: unit_string
772 INTEGER :: handle, i, iounit, ispin, natom, nspins
773 LOGICAL :: debug_forces, debug_stress, do_ec_hfx, &
775 REAL(
dp) :: dummy_real, dummy_real2(2), ehartree, &
777 REAL(
dp),
ALLOCATABLE,
DIMENSION(:, :) :: ftot
778 REAL(
dp),
DIMENSION(3) :: fodeb, fodeb2
779 REAL(kind=
dp),
DIMENSION(3, 3) :: h_stress, pv_loc, stdeb, sttot
783 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_ks, matrix_s, scrm
784 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_p
795 TYPE(
pw_r3d_rs_type),
DIMENSION(:),
POINTER :: rho_r, v_rspace, v_rspace_in, &
803 CALL timeset(routinen, handle)
805 debug_forces = ec_env%debug_forces
806 debug_stress = ec_env%debug_stress
809 IF (logger%para_env%is_source())
THEN
815 NULLIFY (atomic_kind_set, cell, dft_control, force, ks_env, matrix_ks, &
816 matrix_p, matrix_s, para_env, pw_env, rho, sab_orb, virial)
819 dft_control=dft_control, &
822 matrix_ks=matrix_ks, &
829 cpassert(
ASSOCIATED(pw_env))
831 nspins = dft_control%nspins
832 use_virial = virial%pv_availability .AND. (.NOT. virial%pv_numer)
834 fconv = 1.0e-9_dp*
pascal/cell%deth
835 IF (debug_stress .AND. use_virial)
THEN
836 sttot = virial%pv_virial
842 NULLIFY (auxbas_pw_pool, poisson_env)
844 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool, &
845 poisson_env=poisson_env)
848 CALL auxbas_pw_pool%create_pw(v_hartree_gspace)
849 CALL auxbas_pw_pool%create_pw(rho_tot_gspace)
850 CALL auxbas_pw_pool%create_pw(v_hartree_rspace)
859 h_stress(:, :) = 0.0_dp
861 density=rho_tot_gspace, &
863 vhartree=v_hartree_gspace, &
866 virial%pv_ehartree = virial%pv_ehartree + h_stress/real(para_env%num_pe,
dp)
867 virial%pv_virial = virial%pv_virial + h_stress/real(para_env%num_pe,
dp)
869 IF (debug_stress)
THEN
870 stdeb = fconv*(h_stress/real(para_env%num_pe,
dp))
871 CALL para_env%sum(stdeb)
872 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
881 CALL pw_transfer(v_hartree_gspace, v_hartree_rspace)
882 CALL pw_scale(v_hartree_rspace, v_hartree_rspace%pw_grid%dvol)
886 ALLOCATE (ec_env%rhoout_r(nspins))
888 CALL auxbas_pw_pool%create_pw(ec_env%rhoout_r(ispin))
889 CALL pw_copy(rho_r(ispin), ec_env%rhoout_r(ispin))
894 IF (debug_forces) fodeb(1:3) = force(1)%rho_core(1:3, 1)
895 IF (debug_stress .AND. use_virial) stdeb = virial%pv_ehartree
896 CALL integrate_v_core_rspace(v_hartree_rspace, qs_env)
897 IF (debug_forces)
THEN
898 fodeb(1:3) = force(1)%rho_core(1:3, 1) - fodeb(1:3)
899 CALL para_env%sum(fodeb)
900 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Vtot*dncore", fodeb
902 IF (debug_stress .AND. use_virial)
THEN
903 stdeb = fconv*(virial%pv_ehartree - stdeb)
904 CALL para_env%sum(stdeb)
905 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
911 NULLIFY (v_rspace, v_tau_rspace)
914 IF (use_virial) virial%pv_calculate = .true.
917 CALL qs_vxc_create(ks_env=ks_env, rho_struct=rho, xc_section=ec_env%xc_section, &
918 vxc_rho=v_rspace, vxc_tau=v_tau_rspace, exc=exc, just_energy=.false.)
920 IF (.NOT.
ASSOCIATED(v_rspace))
THEN
921 ALLOCATE (v_rspace(nspins))
923 CALL auxbas_pw_pool%create_pw(v_rspace(ispin))
929 virial%pv_exc = virial%pv_exc - virial%pv_xc
930 virial%pv_virial = virial%pv_virial - virial%pv_xc
938 ALLOCATE (scrm(ispin)%matrix)
939 CALL dbcsr_create(scrm(ispin)%matrix, template=ec_env%matrix_ks(ispin, 1)%matrix)
940 CALL dbcsr_copy(scrm(ispin)%matrix, ec_env%matrix_ks(ispin, 1)%matrix)
941 CALL dbcsr_set(scrm(ispin)%matrix, 0.0_dp)
944 pw_grid => v_hartree_rspace%pw_grid
945 ALLOCATE (v_rspace_in(nspins))
947 CALL v_rspace_in(ispin)%create(pw_grid)
953 CALL pw_transfer(ec_env%vxc_rspace(ispin), v_rspace_in(ispin))
955 CALL pw_axpy(ec_env%vh_rspace, v_rspace_in(ispin))
966 IF (debug_forces) fodeb(1:3) = force(1)%fock_4c(1:3, 1)
967 IF (debug_forces) fodeb2(1:3) = force(1)%overlap_admm(1:3, 1)
974 hfx_sections=ec_hfx_sections, &
975 x_data=ec_env%x_data, &
977 do_admm=ec_env%do_ec_admm, &
978 calc_forces=.true., &
979 reuse_hfx=ec_env%reuse_hfx, &
980 do_im_time=.false., &
981 e_ex_from_gw=dummy_real, &
982 e_admm_from_gw=dummy_real2, &
985 IF (debug_forces)
THEN
986 fodeb(1:3) = force(1)%fock_4c(1:3, 1) - fodeb(1:3)
987 CALL para_env%sum(fodeb)
988 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: P*hfx_DC ", fodeb
990 fodeb2(1:3) = force(1)%overlap_admm(1:3, 1) - fodeb2(1:3)
991 CALL para_env%sum(fodeb2)
992 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: P*hfx_DC*S ", fodeb2
994 IF (debug_stress .AND. use_virial)
THEN
995 stdeb = -1.0_dp*fconv*virial%pv_fock_4c
996 CALL para_env%sum(stdeb)
997 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1007 IF (use_virial)
THEN
1008 pv_loc = virial%pv_virial
1011 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
1012 IF (debug_stress .AND. use_virial) stdeb = virial%pv_virial
1014 DO ispin = 1, nspins
1016 CALL pw_scale(v_rspace(ispin), v_rspace(ispin)%pw_grid%dvol)
1017 CALL pw_axpy(v_hartree_rspace, v_rspace(ispin))
1019 CALL integrate_v_rspace(v_rspace=v_rspace(ispin), &
1021 pmat=matrix_p(ispin, 1), &
1023 calculate_forces=.true., &
1024 basis_type=
"HARRIS", &
1025 task_list_external=ec_env%task_list)
1028 IF (debug_forces)
THEN
1029 fodeb(1:3) = force(1)%rho_elec(1:3, 1) - fodeb(1:3)
1030 CALL para_env%sum(fodeb)
1031 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Pout*dVhxc ", fodeb
1033 IF (debug_stress .AND. use_virial)
THEN
1034 stdeb = fconv*(virial%pv_virial - stdeb)
1035 CALL para_env%sum(stdeb)
1036 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1040 IF (
ASSOCIATED(v_tau_rspace))
THEN
1041 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
1042 IF (debug_stress .AND. use_virial) stdeb = virial%pv_virial
1043 DO ispin = 1, nspins
1044 CALL pw_scale(v_tau_rspace(ispin), v_tau_rspace(ispin)%pw_grid%dvol)
1046 CALL integrate_v_rspace(v_rspace=v_tau_rspace(ispin), &
1048 pmat=matrix_p(ispin, 1), &
1050 calculate_forces=.true., &
1051 compute_tau=.true., &
1052 basis_type=
"HARRIS", &
1053 task_list_external=ec_env%task_list)
1056 IF (debug_forces)
THEN
1057 fodeb(1:3) = force(1)%rho_elec(1:3, 1) - fodeb(1:3)
1058 CALL para_env%sum(fodeb)
1059 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Pout*dVhxc_tau ", fodeb
1061 IF (debug_stress .AND. use_virial)
THEN
1062 stdeb = fconv*(virial%pv_virial - stdeb)
1063 CALL para_env%sum(stdeb)
1064 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1070 IF (use_virial)
THEN
1071 virial%pv_ehartree = virial%pv_ehartree + (virial%pv_virial - pv_loc)
1090 NULLIFY (ec_env%matrix_hz)
1092 DO ispin = 1, nspins
1093 ALLOCATE (ec_env%matrix_hz(ispin)%matrix)
1094 CALL dbcsr_create(ec_env%matrix_hz(ispin)%matrix, template=matrix_s(1)%matrix)
1095 CALL dbcsr_copy(ec_env%matrix_hz(ispin)%matrix, matrix_s(1)%matrix)
1096 CALL dbcsr_set(ec_env%matrix_hz(ispin)%matrix, 0.0_dp)
1099 DO ispin = 1, nspins
1102 CALL pw_axpy(v_rspace_in(ispin), v_rspace(ispin), -1.0_dp)
1105 DO ispin = 1, nspins
1106 CALL integrate_v_rspace(v_rspace=v_rspace(ispin), &
1107 hmat=ec_env%matrix_hz(ispin), &
1108 pmat=matrix_p(ispin, 1), &
1110 calculate_forces=.false., &
1111 basis_type=
"HARRIS", &
1112 task_list_external=ec_env%task_list)
1116 IF (dft_control%use_kinetic_energy_density)
THEN
1119 IF (.NOT.
ASSOCIATED(v_tau_rspace))
THEN
1120 ALLOCATE (v_tau_rspace(nspins))
1121 DO ispin = 1, nspins
1122 CALL auxbas_pw_pool%create_pw(v_tau_rspace(ispin))
1123 CALL pw_zero(v_tau_rspace(ispin))
1127 DO ispin = 1, nspins
1129 IF (
ASSOCIATED(ec_env%vtau_rspace))
THEN
1130 CALL pw_axpy(ec_env%vtau_rspace(ispin), v_tau_rspace(ispin), -1.0_dp)
1133 CALL integrate_v_rspace(v_rspace=v_tau_rspace(ispin), &
1134 hmat=ec_env%matrix_hz(ispin), &
1135 pmat=matrix_p(ispin, 1), &
1137 calculate_forces=.false., compute_tau=.true., &
1138 basis_type=
"HARRIS", &
1139 task_list_external=ec_env%task_list)
1147 ext_hfx_section=ec_hfx_sections, &
1148 x_data=ec_env%x_data, &
1149 recalc_integrals=.false., &
1150 do_admm=ec_env%do_ec_admm, &
1153 reuse_hfx=ec_env%reuse_hfx)
1156 IF (debug_forces) fodeb(1:3) = force(1)%core_overlap(1:3, 1)
1157 IF (debug_stress .AND. use_virial) stdeb = virial%pv_ecore_overlap
1159 IF (debug_forces)
THEN
1160 fodeb(1:3) = force(1)%core_overlap(1:3, 1) - fodeb(1:3)
1161 CALL para_env%sum(fodeb)
1162 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: CoreOverlap", fodeb
1164 IF (debug_stress .AND. use_virial)
THEN
1165 stdeb = fconv*(stdeb - virial%pv_ecore_overlap)
1166 CALL para_env%sum(stdeb)
1167 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1171 IF (debug_forces)
THEN
1172 CALL get_qs_env(qs_env, natom=natom, atomic_kind_set=atomic_kind_set)
1173 ALLOCATE (ftot(3, natom))
1175 fodeb(1:3) = ftot(1:3, 1)
1177 CALL para_env%sum(fodeb)
1178 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Force Explicit", fodeb
1182 DO ispin = 1, nspins
1183 CALL auxbas_pw_pool%give_back_pw(v_rspace(ispin))
1184 CALL auxbas_pw_pool%give_back_pw(v_rspace_in(ispin))
1185 IF (
ASSOCIATED(v_tau_rspace))
THEN
1186 CALL auxbas_pw_pool%give_back_pw(v_tau_rspace(ispin))
1190 DEALLOCATE (v_rspace, v_rspace_in)
1191 IF (
ASSOCIATED(v_tau_rspace))
DEALLOCATE (v_tau_rspace)
1193 CALL auxbas_pw_pool%give_back_pw(rho_tot_gspace)
1194 CALL auxbas_pw_pool%give_back_pw(v_hartree_gspace)
1195 CALL auxbas_pw_pool%give_back_pw(v_hartree_rspace)
1199 IF (use_virial)
THEN
1200 IF (qs_env%energy_correction)
THEN
1201 ec_env%ehartree = ehartree
1206 IF (debug_stress .AND. use_virial)
THEN
1208 stdeb = -1.0_dp*fconv*ehartree
1209 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1212 stdeb = -1.0_dp*fconv*exc
1213 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1222 CALL para_env%sum(virdeb%pv_overlap)
1223 CALL para_env%sum(virdeb%pv_ekinetic)
1224 CALL para_env%sum(virdeb%pv_ppl)
1225 CALL para_env%sum(virdeb%pv_ppnl)
1226 CALL para_env%sum(virdeb%pv_ecore_overlap)
1227 CALL para_env%sum(virdeb%pv_ehartree)
1228 CALL para_env%sum(virdeb%pv_exc)
1229 CALL para_env%sum(virdeb%pv_exx)
1230 CALL para_env%sum(virdeb%pv_vdw)
1231 CALL para_env%sum(virdeb%pv_mp2)
1232 CALL para_env%sum(virdeb%pv_nlcc)
1233 CALL para_env%sum(virdeb%pv_gapw)
1234 CALL para_env%sum(virdeb%pv_lrigpw)
1235 CALL para_env%sum(virdeb%pv_virial)
1240 virdeb%pv_ehartree(i, i) = virdeb%pv_ehartree(i, i) - 2.0_dp*ehartree
1241 virdeb%pv_virial(i, i) = virdeb%pv_virial(i, i) - exc &
1243 virdeb%pv_exc(i, i) = virdeb%pv_exc(i, i) - exc
1249 CALL para_env%sum(sttot)
1250 stdeb = fconv*(virdeb%pv_virial - sttot)
1251 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1254 stdeb = fconv*(virdeb%pv_virial)
1255 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1265 CALL timestop(handle)
1267 END SUBROUTINE ec_dc_build_ks_matrix_force
1275 SUBROUTINE ec_disp(qs_env, ec_env, calculate_forces)
1276 TYPE(qs_environment_type),
POINTER :: qs_env
1277 TYPE(energy_correction_type),
POINTER :: ec_env
1278 LOGICAL,
INTENT(IN) :: calculate_forces
1280 REAL(kind=dp) :: edisp
1282 CALL calculate_dispersion_pairpot(qs_env, ec_env%dispersion_env, edisp, calculate_forces)
1283 IF (.NOT. calculate_forces) ec_env%edispersion = ec_env%edispersion + edisp
1285 END SUBROUTINE ec_disp
1294 SUBROUTINE ec_build_core_hamiltonian(qs_env, ec_env)
1295 TYPE(qs_environment_type),
POINTER :: qs_env
1296 TYPE(energy_correction_type),
POINTER :: ec_env
1298 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ec_build_core_hamiltonian'
1300 INTEGER :: handle, nder, nimages
1301 INTEGER,
DIMENSION(:, :, :),
POINTER :: cell_to_index
1302 LOGICAL :: calculate_forces, use_virial
1303 REAL(kind=dp) :: eps_ppnl
1304 TYPE(atomic_kind_type),
DIMENSION(:),
POINTER :: atomic_kind_set
1305 TYPE(dft_control_type),
POINTER :: dft_control
1306 TYPE(neighbor_list_set_p_type),
DIMENSION(:), &
1307 POINTER :: sab_orb, sac_ae, sac_ppl, sap_ppnl
1308 TYPE(particle_type),
DIMENSION(:),
POINTER :: particle_set
1309 TYPE(qs_force_type),
DIMENSION(:),
POINTER :: force
1310 TYPE(qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
1311 TYPE(qs_ks_env_type),
POINTER :: ks_env
1312 TYPE(virial_type),
POINTER :: virial
1314 CALL timeset(routinen, handle)
1316 NULLIFY (atomic_kind_set, cell_to_index, dft_control, ks_env, particle_set, qs_kind_set, virial)
1318 CALL get_qs_env(qs_env=qs_env, &
1319 atomic_kind_set=atomic_kind_set, &
1320 dft_control=dft_control, &
1321 particle_set=particle_set, &
1322 qs_kind_set=qs_kind_set, &
1326 nimages = dft_control%nimages
1327 IF (nimages /= 1)
THEN
1328 cpabort(
"K-points for Harris functional not implemented")
1332 IF (dft_control%qs_control%gapw .OR. dft_control%qs_control%gapw_xc)
THEN
1333 cpabort(
"Harris functional for GAPW not implemented")
1337 use_virial = .false.
1338 calculate_forces = .false.
1341 NULLIFY (sab_orb, sac_ae, sac_ppl, sap_ppnl)
1342 sab_orb => ec_env%sab_orb
1343 sac_ppl => ec_env%sac_ppl
1344 sap_ppnl => ec_env%sap_ppnl
1348 CALL build_overlap_matrix(ks_env, matrixkp_s=ec_env%matrix_s, &
1349 matrix_name=
"OVERLAP MATRIX", &
1350 basis_type_a=
"HARRIS", &
1351 basis_type_b=
"HARRIS", &
1353 CALL build_kinetic_matrix(ks_env, matrixkp_t=ec_env%matrix_t, &
1354 matrix_name=
"KINETIC ENERGY MATRIX", &
1355 basis_type=
"HARRIS", &
1359 CALL dbcsr_allocate_matrix_set(ec_env%matrix_h, 1, 1)
1360 ALLOCATE (ec_env%matrix_h(1, 1)%matrix)
1361 CALL dbcsr_create(ec_env%matrix_h(1, 1)%matrix, template=ec_env%matrix_s(1, 1)%matrix)
1362 CALL cp_dbcsr_alloc_block_from_nbl(ec_env%matrix_h(1, 1)%matrix, sab_orb)
1365 CALL dbcsr_copy(ec_env%matrix_h(1, 1)%matrix, ec_env%matrix_t(1, 1)%matrix, &
1366 keep_sparsity=.true., name=
"CORE HAMILTONIAN MATRIX")
1369 IF (
ASSOCIATED(sac_ae))
THEN
1370 cpabort(
"ECP/AE not available for energy corrections")
1373 CALL build_core_ae(ec_env%matrix_h, ec_env%matrix_p, force, &
1374 virial, calculate_forces, use_virial, nder, &
1375 qs_kind_set, atomic_kind_set, particle_set, sab_orb, sac_ae, &
1376 nimages, cell_to_index)
1379 IF (
ASSOCIATED(sac_ppl))
THEN
1380 CALL build_core_ppl(ec_env%matrix_h, ec_env%matrix_p, force, &
1381 virial, calculate_forces, use_virial, nder, &
1382 qs_kind_set, atomic_kind_set, particle_set, sab_orb, sac_ppl, &
1383 nimages, cell_to_index,
"HARRIS")
1387 eps_ppnl = dft_control%qs_control%eps_ppnl
1388 IF (
ASSOCIATED(sap_ppnl))
THEN
1389 CALL build_core_ppnl(ec_env%matrix_h, ec_env%matrix_p, force, &
1390 virial, calculate_forces, use_virial, nder, &
1391 qs_kind_set, atomic_kind_set, particle_set, sab_orb, sap_ppnl, &
1392 eps_ppnl, nimages, cell_to_index,
"HARRIS")
1396 ec_env%efield_nuclear = 0.0_dp
1397 CALL ec_efield_local_operator(qs_env, ec_env, calculate_forces)
1399 CALL timestop(handle)
1401 END SUBROUTINE ec_build_core_hamiltonian
1412 SUBROUTINE ec_build_ks_matrix(qs_env, ec_env)
1413 TYPE(qs_environment_type),
POINTER :: qs_env
1414 TYPE(energy_correction_type),
POINTER :: ec_env
1416 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ec_build_ks_matrix'
1418 CHARACTER(LEN=default_string_length) :: headline
1419 INTEGER :: handle, iounit, ispin, nspins
1420 LOGICAL :: calculate_forces, &
1421 do_adiabatic_rescaling, do_ec_hfx, &
1422 hfx_treat_lsd_in_core, use_virial
1423 REAL(dp) :: dummy_real, dummy_real2(2), eexc, evhxc, &
1425 TYPE(cp_logger_type),
POINTER :: logger
1426 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: ks_mat
1427 TYPE(dft_control_type),
POINTER :: dft_control
1428 TYPE(pw_env_type),
POINTER :: pw_env
1429 TYPE(pw_pool_type),
POINTER :: auxbas_pw_pool
1430 TYPE(pw_r3d_rs_type),
DIMENSION(:),
POINTER :: rho_r, tau_r, v_rspace, v_tau_rspace
1431 TYPE(qs_energy_type),
POINTER :: energy
1432 TYPE(qs_ks_env_type),
POINTER :: ks_env
1433 TYPE(qs_rho_type),
POINTER :: rho
1434 TYPE(section_vals_type),
POINTER :: adiabatic_rescaling_section, &
1435 ec_hfx_sections, ec_section
1437 CALL timeset(routinen, handle)
1439 logger => cp_get_default_logger()
1440 IF (logger%para_env%is_source())
THEN
1441 iounit = cp_logger_get_default_unit_nr(logger, local=.true.)
1447 NULLIFY (auxbas_pw_pool, dft_control, energy, ks_env, rho, rho_r, tau_r)
1448 CALL get_qs_env(qs_env=qs_env, &
1449 dft_control=dft_control, &
1452 nspins = dft_control%nspins
1453 calculate_forces = .false.
1454 use_virial = .false.
1457 IF (
ASSOCIATED(ec_env%matrix_ks))
CALL dbcsr_deallocate_matrix_set(ec_env%matrix_ks)
1458 CALL dbcsr_allocate_matrix_set(ec_env%matrix_ks, nspins, 1)
1459 DO ispin = 1, nspins
1460 headline =
"KOHN-SHAM MATRIX"
1461 ALLOCATE (ec_env%matrix_ks(ispin, 1)%matrix)
1462 CALL dbcsr_create(ec_env%matrix_ks(ispin, 1)%matrix, name=trim(headline), &
1463 template=ec_env%matrix_s(1, 1)%matrix, matrix_type=dbcsr_type_symmetric)
1464 CALL cp_dbcsr_alloc_block_from_nbl(ec_env%matrix_ks(ispin, 1)%matrix, ec_env%sab_orb)
1465 CALL dbcsr_set(ec_env%matrix_ks(ispin, 1)%matrix, 0.0_dp)
1469 CALL get_qs_env(qs_env=qs_env, pw_env=pw_env)
1470 cpassert(
ASSOCIATED(pw_env))
1473 ec_section => section_vals_get_subs_vals(qs_env%input,
"DFT%ENERGY_CORRECTION")
1474 ec_hfx_sections => section_vals_get_subs_vals(ec_section,
"XC%HF")
1475 CALL section_vals_get(ec_hfx_sections, explicit=do_ec_hfx)
1480 adiabatic_rescaling_section => section_vals_get_subs_vals(ec_section,
"XC%ADIABATIC_RESCALING")
1481 CALL section_vals_get(adiabatic_rescaling_section, explicit=do_adiabatic_rescaling)
1482 IF (do_adiabatic_rescaling)
THEN
1483 CALL cp_abort(__location__,
"Adiabatic rescaling NYI for energy correction")
1485 CALL section_vals_val_get(ec_hfx_sections,
"TREAT_LSD_IN_CORE", l_val=hfx_treat_lsd_in_core)
1486 IF (hfx_treat_lsd_in_core)
THEN
1487 CALL cp_abort(__location__,
"HFX_TREAT_LSD_IN_CORE NYI for energy correction")
1491 IF (dft_control%do_admm)
THEN
1493 IF (dft_control%do_admm_mo)
THEN
1494 IF (qs_env%run_rtp)
THEN
1495 CALL rtp_admm_calc_rho_aux(qs_env)
1497 CALL admm_mo_calc_rho_aux(qs_env)
1499 ELSEIF (dft_control%do_admm_dm)
THEN
1500 CALL admm_dm_calc_rho_aux(qs_env)
1507 CALL get_qs_env(qs_env, energy=energy)
1508 CALL calculate_exx(qs_env=qs_env, &
1510 hfx_sections=ec_hfx_sections, &
1511 x_data=ec_env%x_data, &
1513 do_admm=ec_env%do_ec_admm, &
1514 calc_forces=.false., &
1515 reuse_hfx=ec_env%reuse_hfx, &
1516 do_im_time=.false., &
1517 e_ex_from_gw=dummy_real, &
1518 e_admm_from_gw=dummy_real2, &
1522 ec_env%ex = energy%ex
1524 IF (ec_env%do_ec_admm)
THEN
1525 ec_env%exc_aux_fit = energy%exc_aux_fit + energy%exc
1531 ks_mat => ec_env%matrix_ks(:, 1)
1532 CALL add_exx_to_rhs(rhs=ks_mat, &
1534 ext_hfx_section=ec_hfx_sections, &
1535 x_data=ec_env%x_data, &
1536 recalc_integrals=.false., &
1537 do_admm=ec_env%do_ec_admm, &
1540 reuse_hfx=ec_env%reuse_hfx)
1545 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
1546 NULLIFY (v_rspace, v_tau_rspace)
1547 CALL qs_vxc_create(ks_env=ks_env, rho_struct=rho, xc_section=ec_env%xc_section, &
1548 vxc_rho=v_rspace, vxc_tau=v_tau_rspace, exc=eexc, just_energy=.false.)
1550 IF (.NOT.
ASSOCIATED(v_rspace))
THEN
1551 ALLOCATE (v_rspace(nspins))
1552 DO ispin = 1, nspins
1553 CALL auxbas_pw_pool%create_pw(v_rspace(ispin))
1554 CALL pw_zero(v_rspace(ispin))
1559 CALL qs_rho_get(rho, rho_r=rho_r)
1560 IF (
ASSOCIATED(v_tau_rspace))
THEN
1561 CALL qs_rho_get(rho, tau_r=tau_r)
1563 DO ispin = 1, nspins
1565 CALL pw_scale(v_rspace(ispin), v_rspace(ispin)%pw_grid%dvol)
1566 CALL pw_axpy(ec_env%vh_rspace, v_rspace(ispin))
1568 CALL integrate_v_rspace(v_rspace=v_rspace(ispin), &
1569 hmat=ec_env%matrix_ks(ispin, 1), &
1571 calculate_forces=.false., &
1572 basis_type=
"HARRIS", &
1573 task_list_external=ec_env%task_list)
1575 IF (
ASSOCIATED(v_tau_rspace))
THEN
1577 CALL pw_scale(v_tau_rspace(ispin), v_tau_rspace(ispin)%pw_grid%dvol)
1578 CALL integrate_v_rspace(v_rspace=v_tau_rspace(ispin), &
1579 hmat=ec_env%matrix_ks(ispin, 1), &
1581 calculate_forces=.false., &
1582 compute_tau=.true., &
1583 basis_type=
"HARRIS", &
1584 task_list_external=ec_env%task_list)
1588 evhxc = evhxc + pw_integral_ab(rho_r(ispin), v_rspace(ispin))/ &
1589 v_rspace(1)%pw_grid%dvol
1590 IF (
ASSOCIATED(v_tau_rspace))
THEN
1591 evhxc = evhxc + pw_integral_ab(tau_r(ispin), v_tau_rspace(ispin))/ &
1592 v_tau_rspace(ispin)%pw_grid%dvol
1598 DO ispin = 1, nspins
1599 CALL auxbas_pw_pool%give_back_pw(v_rspace(ispin))
1600 IF (
ASSOCIATED(v_tau_rspace))
THEN
1601 CALL auxbas_pw_pool%give_back_pw(v_tau_rspace(ispin))
1604 DEALLOCATE (v_rspace)
1605 IF (
ASSOCIATED(v_tau_rspace))
DEALLOCATE (v_tau_rspace)
1612 DO ispin = 1, nspins
1613 CALL dbcsr_add(ec_env%matrix_ks(ispin, 1)%matrix, ec_env%matrix_h(1, 1)%matrix, &
1614 alpha_scalar=1.0_dp, beta_scalar=1.0_dp)
1615 CALL dbcsr_filter(ec_env%matrix_ks(ispin, 1)%matrix, &
1616 dft_control%qs_control%eps_filter_matrix)
1619 CALL timestop(handle)
1621 END SUBROUTINE ec_build_ks_matrix
1633 SUBROUTINE ec_build_core_hamiltonian_force(qs_env, ec_env, matrix_p, matrix_s, matrix_w)
1634 TYPE(qs_environment_type),
POINTER :: qs_env
1635 TYPE(energy_correction_type),
POINTER :: ec_env
1636 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_p, matrix_s, matrix_w
1638 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ec_build_core_hamiltonian_force'
1640 INTEGER :: handle, iounit, nder, nimages
1641 INTEGER,
DIMENSION(:, :, :),
POINTER :: cell_to_index
1642 LOGICAL :: calculate_forces, debug_forces, &
1643 debug_stress, use_virial
1644 REAL(kind=dp) :: eps_ppnl, fconv
1645 REAL(kind=dp),
DIMENSION(3) :: fodeb
1646 REAL(kind=dp),
DIMENSION(3, 3) :: stdeb, sttot
1647 TYPE(atomic_kind_type),
DIMENSION(:),
POINTER :: atomic_kind_set
1648 TYPE(cell_type),
POINTER :: cell
1649 TYPE(cp_logger_type),
POINTER :: logger
1650 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: scrm
1651 TYPE(dft_control_type),
POINTER :: dft_control
1652 TYPE(mp_para_env_type),
POINTER :: para_env
1653 TYPE(neighbor_list_set_p_type),
DIMENSION(:), &
1654 POINTER :: sab_orb, sac_ppl, sap_ppnl
1655 TYPE(particle_type),
DIMENSION(:),
POINTER :: particle_set
1656 TYPE(qs_force_type),
DIMENSION(:),
POINTER :: force
1657 TYPE(qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
1658 TYPE(qs_ks_env_type),
POINTER :: ks_env
1659 TYPE(virial_type),
POINTER :: virial
1661 CALL timeset(routinen, handle)
1663 debug_forces = ec_env%debug_forces
1664 debug_stress = ec_env%debug_stress
1666 logger => cp_get_default_logger()
1667 IF (logger%para_env%is_source())
THEN
1668 iounit = cp_logger_get_default_unit_nr(logger, local=.true.)
1673 calculate_forces = .true.
1676 NULLIFY (cell, dft_control, force, ks_env, para_env, virial)
1677 CALL get_qs_env(qs_env=qs_env, &
1679 dft_control=dft_control, &
1682 para_env=para_env, &
1684 nimages = dft_control%nimages
1685 IF (nimages /= 1)
THEN
1686 cpabort(
"K-points for Harris functional not implemented")
1690 use_virial = virial%pv_availability .AND. (.NOT. virial%pv_numer)
1692 fconv = 1.0e-9_dp*pascal/cell%deth
1693 IF (debug_stress .AND. use_virial)
THEN
1694 sttot = virial%pv_virial
1698 IF (dft_control%qs_control%gapw .OR. dft_control%qs_control%gapw_xc)
THEN
1699 cpabort(
"Harris functional for GAPW not implemented")
1703 NULLIFY (sab_orb, sac_ppl, sap_ppnl)
1704 sab_orb => ec_env%sab_orb
1705 sac_ppl => ec_env%sac_ppl
1706 sap_ppnl => ec_env%sap_ppnl
1710 CALL dbcsr_allocate_matrix_set(scrm, 1, 1)
1711 ALLOCATE (scrm(1, 1)%matrix)
1712 CALL dbcsr_create(scrm(1, 1)%matrix, template=matrix_s(1, 1)%matrix)
1713 CALL cp_dbcsr_alloc_block_from_nbl(scrm(1, 1)%matrix, sab_orb)
1716 IF (
SIZE(matrix_p, 1) == 2)
THEN
1717 CALL dbcsr_add(matrix_p(1, 1)%matrix, matrix_p(2, 1)%matrix, &
1718 alpha_scalar=1.0_dp, beta_scalar=1.0_dp)
1719 CALL dbcsr_add(matrix_w(1, 1)%matrix, matrix_w(2, 1)%matrix, &
1720 alpha_scalar=1.0_dp, beta_scalar=1.0_dp)
1724 IF (debug_forces) fodeb(1:3) = force(1)%overlap(1:3, 1)
1725 IF (debug_stress .AND. use_virial) stdeb = virial%pv_overlap
1726 CALL build_overlap_matrix(ks_env, matrixkp_s=scrm, &
1727 matrix_name=
"OVERLAP MATRIX", &
1728 basis_type_a=
"HARRIS", &
1729 basis_type_b=
"HARRIS", &
1730 sab_nl=sab_orb, calculate_forces=.true., &
1731 matrixkp_p=matrix_w)
1733 IF (debug_forces)
THEN
1734 fodeb(1:3) = force(1)%overlap(1:3, 1) - fodeb(1:3)
1735 CALL para_env%sum(fodeb)
1736 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Wout*dS ", fodeb
1737 fodeb(1:3) = force(1)%kinetic(1:3, 1)
1739 IF (debug_stress .AND. use_virial)
THEN
1740 stdeb = fconv*(virial%pv_overlap - stdeb)
1741 CALL para_env%sum(stdeb)
1742 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1743 'STRESS| Wout*dS', one_third_sum_diag(stdeb), det_3x3(stdeb)
1744 stdeb = virial%pv_ekinetic
1746 CALL build_kinetic_matrix(ks_env, matrixkp_t=scrm, &
1747 matrix_name=
"KINETIC ENERGY MATRIX", &
1748 basis_type=
"HARRIS", &
1749 sab_nl=sab_orb, calculate_forces=.true., &
1750 matrixkp_p=matrix_p)
1751 IF (debug_forces)
THEN
1752 fodeb(1:3) = force(1)%kinetic(1:3, 1) - fodeb(1:3)
1753 CALL para_env%sum(fodeb)
1754 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Pout*dT ", fodeb
1756 IF (debug_stress .AND. use_virial)
THEN
1757 stdeb = fconv*(virial%pv_ekinetic - stdeb)
1758 CALL para_env%sum(stdeb)
1759 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1760 'STRESS| Pout*dT', one_third_sum_diag(stdeb), det_3x3(stdeb)
1762 IF (
SIZE(matrix_p, 1) == 2)
THEN
1763 CALL dbcsr_add(matrix_p(1, 1)%matrix, matrix_p(2, 1)%matrix, &
1764 alpha_scalar=1.0_dp, beta_scalar=-1.0_dp)
1768 NULLIFY (atomic_kind_set, particle_set, qs_kind_set)
1769 CALL get_qs_env(qs_env=qs_env, qs_kind_set=qs_kind_set, particle_set=particle_set, &
1770 atomic_kind_set=atomic_kind_set)
1772 IF (
ASSOCIATED(sac_ppl))
THEN
1773 IF (calculate_forces .AND. debug_forces) fodeb(1:3) = force(1)%gth_ppl(1:3, 1)
1774 IF (debug_stress .AND. use_virial) stdeb = virial%pv_ppl
1775 CALL build_core_ppl(scrm, matrix_p, force, &
1776 virial, calculate_forces, use_virial, nder, &
1777 qs_kind_set, atomic_kind_set, particle_set, sab_orb, sac_ppl, &
1778 nimages, cell_to_index,
"HARRIS")
1779 IF (calculate_forces .AND. debug_forces)
THEN
1780 fodeb(1:3) = force(1)%gth_ppl(1:3, 1) - fodeb(1:3)
1781 CALL para_env%sum(fodeb)
1782 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Pout*dH_PPL ", fodeb
1784 IF (debug_stress .AND. use_virial)
THEN
1785 stdeb = fconv*(virial%pv_ppl - stdeb)
1786 CALL para_env%sum(stdeb)
1787 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1788 'STRESS| Pout*dH_PPL', one_third_sum_diag(stdeb), det_3x3(stdeb)
1793 eps_ppnl = dft_control%qs_control%eps_ppnl
1794 IF (
ASSOCIATED(sap_ppnl))
THEN
1795 IF (calculate_forces .AND. debug_forces) fodeb(1:3) = force(1)%gth_ppnl(1:3, 1)
1796 IF (debug_stress .AND. use_virial) stdeb = virial%pv_ppnl
1797 CALL build_core_ppnl(scrm, matrix_p, force, &
1798 virial, calculate_forces, use_virial, nder, &
1799 qs_kind_set, atomic_kind_set, particle_set, &
1800 sab_orb, sap_ppnl, eps_ppnl, &
1801 nimages, cell_to_index,
"HARRIS")
1802 IF (calculate_forces .AND. debug_forces)
THEN
1803 fodeb(1:3) = force(1)%gth_ppnl(1:3, 1) - fodeb(1:3)
1804 CALL para_env%sum(fodeb)
1805 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Pout*dH_PPNL", fodeb
1807 IF (debug_stress .AND. use_virial)
THEN
1808 stdeb = fconv*(virial%pv_ppnl - stdeb)
1809 CALL para_env%sum(stdeb)
1810 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1811 'STRESS| Pout*dH_PPNL', one_third_sum_diag(stdeb), det_3x3(stdeb)
1816 ec_env%efield_nuclear = 0.0_dp
1817 IF (calculate_forces .AND. debug_forces) fodeb(1:3) = force(1)%efield(1:3, 1)
1818 CALL ec_efield_local_operator(qs_env, ec_env, calculate_forces)
1819 IF (calculate_forces .AND. debug_forces)
THEN
1820 fodeb(1:3) = force(1)%efield(1:3, 1) - fodeb(1:3)
1821 CALL para_env%sum(fodeb)
1822 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Pout*dEfield", fodeb
1824 IF (debug_stress .AND. use_virial)
THEN
1825 stdeb = fconv*(virial%pv_virial - sttot)
1826 CALL para_env%sum(stdeb)
1827 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1828 'STRESS| Stress Pout*dHcore ', one_third_sum_diag(stdeb), det_3x3(stdeb)
1829 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))")
' '
1833 CALL dbcsr_deallocate_matrix_set(scrm)
1835 CALL timestop(handle)
1837 END SUBROUTINE ec_build_core_hamiltonian_force
1848 SUBROUTINE ec_build_ks_matrix_force(qs_env, ec_env)
1849 TYPE(qs_environment_type),
POINTER :: qs_env
1850 TYPE(energy_correction_type),
POINTER :: ec_env
1852 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ec_build_ks_matrix_force'
1854 CHARACTER(LEN=default_string_length) :: unit_string
1855 INTEGER :: handle, i, iounit, ispin, natom, nspins
1856 LOGICAL :: debug_forces, debug_stress, do_ec_hfx, &
1858 REAL(dp) :: dehartree, dummy_real, dummy_real2(2), &
1859 eexc, ehartree, eovrl, exc, fconv
1860 REAL(dp),
ALLOCATABLE,
DIMENSION(:, :) :: ftot
1861 REAL(dp),
DIMENSION(3) :: fodeb
1862 REAL(kind=dp),
DIMENSION(3, 3) :: h_stress, pv_loc, stdeb, sttot
1863 TYPE(atomic_kind_type),
DIMENSION(:),
POINTER :: atomic_kind_set
1864 TYPE(cell_type),
POINTER :: cell
1865 TYPE(cp_logger_type),
POINTER :: logger
1866 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_ks, scrm
1867 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_p, matrix_s
1868 TYPE(dft_control_type),
POINTER :: dft_control
1869 TYPE(mp_para_env_type),
POINTER :: para_env
1870 TYPE(neighbor_list_set_p_type),
DIMENSION(:), &
1872 TYPE(pw_c1d_gs_type) :: rho_tot_gspace, rhodn_tot_gspace, &
1874 TYPE(pw_c1d_gs_type),
DIMENSION(:),
POINTER :: rho_g, rhoout_g
1875 TYPE(pw_c1d_gs_type),
POINTER :: rho_core
1876 TYPE(pw_env_type),
POINTER :: pw_env
1877 TYPE(pw_poisson_type),
POINTER :: poisson_env
1878 TYPE(pw_pool_type),
POINTER :: auxbas_pw_pool
1879 TYPE(pw_r3d_rs_type) :: dv_hartree_rspace, v_hartree_rspace, &
1881 TYPE(pw_r3d_rs_type),
DIMENSION(:),
POINTER :: rho_r, rhoout_r, tau_r, tauout_r, &
1882 v_rspace, v_tau_rspace, v_xc, v_xc_tau
1883 TYPE(qs_force_type),
DIMENSION(:),
POINTER :: force
1884 TYPE(qs_ks_env_type),
POINTER :: ks_env
1885 TYPE(qs_rho_type),
POINTER :: rho
1886 TYPE(section_vals_type),
POINTER :: ec_hfx_sections, xc_section
1887 TYPE(virial_type),
POINTER :: virial
1889 CALL timeset(routinen, handle)
1891 debug_forces = ec_env%debug_forces
1892 debug_stress = ec_env%debug_stress
1894 logger => cp_get_default_logger()
1895 IF (logger%para_env%is_source())
THEN
1896 iounit = cp_logger_get_default_unit_nr(logger, local=.true.)
1902 NULLIFY (atomic_kind_set, cell, dft_control, force, ks_env, &
1903 matrix_ks, matrix_p, matrix_s, para_env, rho, rho_core, &
1904 rho_g, rho_r, sab_orb, tau_r, virial)
1905 CALL get_qs_env(qs_env=qs_env, &
1907 dft_control=dft_control, &
1910 matrix_ks=matrix_ks, &
1911 para_env=para_env, &
1916 nspins = dft_control%nspins
1917 use_virial = virial%pv_availability .AND. (.NOT. virial%pv_numer)
1921 fconv = cp_unit_from_cp2k(1.0_dp/cell%deth, trim(unit_string))
1923 IF (debug_stress .AND. use_virial)
THEN
1924 sttot = virial%pv_virial
1928 CALL get_qs_env(qs_env=qs_env, pw_env=pw_env)
1929 cpassert(
ASSOCIATED(pw_env))
1931 NULLIFY (auxbas_pw_pool, poisson_env)
1933 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool, &
1934 poisson_env=poisson_env)
1937 CALL auxbas_pw_pool%create_pw(v_hartree_gspace)
1938 CALL auxbas_pw_pool%create_pw(rhodn_tot_gspace)
1939 CALL auxbas_pw_pool%create_pw(v_hartree_rspace)
1941 CALL pw_transfer(ec_env%vh_rspace, v_hartree_rspace)
1946 CALL qs_rho_get(rho, rho_r=rho_r, rho_g=rho_g, tau_r=tau_r)
1947 NULLIFY (rhoout_r, rhoout_g)
1948 ALLOCATE (rhoout_r(nspins), rhoout_g(nspins))
1949 DO ispin = 1, nspins
1950 CALL auxbas_pw_pool%create_pw(rhoout_r(ispin))
1951 CALL auxbas_pw_pool%create_pw(rhoout_g(ispin))
1953 CALL auxbas_pw_pool%create_pw(dv_hartree_rspace)
1954 CALL auxbas_pw_pool%create_pw(vtot_rspace)
1956 CALL pw_zero(rhodn_tot_gspace)
1957 DO ispin = 1, nspins
1958 CALL calculate_rho_elec(ks_env=ks_env, matrix_p=ec_env%matrix_p(ispin, 1)%matrix, &
1959 rho=rhoout_r(ispin), &
1960 rho_gspace=rhoout_g(ispin), &
1961 basis_type=
"HARRIS", &
1962 task_list_external=ec_env%task_list)
1966 ALLOCATE (ec_env%rhoout_r(nspins))
1967 DO ispin = 1, nspins
1968 CALL auxbas_pw_pool%create_pw(ec_env%rhoout_r(ispin))
1969 CALL pw_copy(rhoout_r(ispin), ec_env%rhoout_r(ispin))
1973 IF (dft_control%use_kinetic_energy_density)
THEN
1975 TYPE(pw_c1d_gs_type) :: tauout_g
1976 ALLOCATE (tauout_r(nspins))
1977 DO ispin = 1, nspins
1978 CALL auxbas_pw_pool%create_pw(tauout_r(ispin))
1980 CALL auxbas_pw_pool%create_pw(tauout_g)
1982 DO ispin = 1, nspins
1983 CALL calculate_rho_elec(ks_env=ks_env, matrix_p=ec_env%matrix_p(ispin, 1)%matrix, &
1984 rho=tauout_r(ispin), &
1985 rho_gspace=tauout_g, &
1986 compute_tau=.true., &
1987 basis_type=
"HARRIS", &
1988 task_list_external=ec_env%task_list)
1991 CALL auxbas_pw_pool%give_back_pw(tauout_g)
1995 IF (use_virial)
THEN
1998 CALL auxbas_pw_pool%create_pw(rho_tot_gspace)
2001 CALL calc_rho_tot_gspace(rho_tot_gspace, qs_env, rho)
2004 CALL get_qs_env(qs_env=qs_env, rho_core=rho_core)
2005 CALL pw_copy(rho_core, rhodn_tot_gspace)
2006 DO ispin = 1, dft_control%nspins
2007 CALL pw_axpy(rhoout_g(ispin), rhodn_tot_gspace)
2011 h_stress(:, :) = 0.0_dp
2012 CALL pw_poisson_solve(poisson_env, &
2013 density=rho_tot_gspace, &
2014 ehartree=ehartree, &
2015 vhartree=v_hartree_gspace, &
2016 h_stress=h_stress, &
2017 aux_density=rhodn_tot_gspace)
2019 virial%pv_ehartree = virial%pv_ehartree + h_stress/real(para_env%num_pe, dp)
2020 virial%pv_virial = virial%pv_virial + h_stress/real(para_env%num_pe, dp)
2022 IF (debug_stress)
THEN
2023 stdeb = fconv*(h_stress/real(para_env%num_pe, dp))
2024 CALL para_env%sum(stdeb)
2025 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2026 'STRESS| GREEN 1st v_H[n_in]*n_out ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2030 virial%pv_calculate = .true.
2032 NULLIFY (v_rspace, v_tau_rspace)
2033 CALL qs_vxc_create(ks_env=ks_env, rho_struct=rho, xc_section=ec_env%xc_section, &
2034 vxc_rho=v_rspace, vxc_tau=v_tau_rspace, exc=exc, just_energy=.false.)
2037 virial%pv_exc = virial%pv_exc - virial%pv_xc
2038 virial%pv_virial = virial%pv_virial - virial%pv_xc
2040 IF (debug_stress)
THEN
2041 stdeb = -1.0_dp*fconv*virial%pv_xc
2042 CALL para_env%sum(stdeb)
2043 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2044 'STRESS| GGA 1st E_xc[Pin] ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2047 IF (
ASSOCIATED(v_rspace))
THEN
2048 DO ispin = 1, nspins
2049 CALL auxbas_pw_pool%give_back_pw(v_rspace(ispin))
2051 DEALLOCATE (v_rspace)
2053 IF (
ASSOCIATED(v_tau_rspace))
THEN
2054 DO ispin = 1, nspins
2055 CALL auxbas_pw_pool%give_back_pw(v_tau_rspace(ispin))
2057 DEALLOCATE (v_tau_rspace)
2059 CALL pw_zero(rhodn_tot_gspace)
2064 DO ispin = 1, nspins
2065 CALL pw_axpy(rho_r(ispin), rhoout_r(ispin), -1.0_dp)
2066 CALL pw_axpy(rho_g(ispin), rhoout_g(ispin), -1.0_dp)
2067 CALL pw_axpy(rhoout_g(ispin), rhodn_tot_gspace)
2068 IF (dft_control%use_kinetic_energy_density)
CALL pw_axpy(tau_r(ispin), tauout_r(ispin), -1.0_dp)
2072 IF (use_virial)
THEN
2075 h_stress(:, :) = 0.0_dp
2076 CALL pw_poisson_solve(poisson_env, &
2077 density=rhodn_tot_gspace, &
2078 ehartree=dehartree, &
2079 vhartree=v_hartree_gspace, &
2080 h_stress=h_stress, &
2081 aux_density=rho_tot_gspace)
2083 CALL auxbas_pw_pool%give_back_pw(rho_tot_gspace)
2085 virial%pv_ehartree = virial%pv_ehartree + h_stress/real(para_env%num_pe, dp)
2086 virial%pv_virial = virial%pv_virial + h_stress/real(para_env%num_pe, dp)
2088 IF (debug_stress)
THEN
2089 stdeb = fconv*(h_stress/real(para_env%num_pe, dp))
2090 CALL para_env%sum(stdeb)
2091 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2092 'STRESS| GREEN 2nd V_H[dP]*n_in ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2097 CALL pw_poisson_solve(poisson_env, rhodn_tot_gspace, dehartree, &
2101 CALL pw_transfer(v_hartree_gspace, dv_hartree_rspace)
2102 CALL pw_scale(dv_hartree_rspace, dv_hartree_rspace%pw_grid%dvol)
2105 CALL pw_transfer(v_hartree_rspace, vtot_rspace)
2106 CALL pw_axpy(dv_hartree_rspace, vtot_rspace)
2107 IF (debug_forces) fodeb(1:3) = force(1)%rho_core(1:3, 1)
2108 IF (debug_stress .AND. use_virial) stdeb = virial%pv_ehartree
2109 CALL integrate_v_core_rspace(vtot_rspace, qs_env)
2110 IF (debug_forces)
THEN
2111 fodeb(1:3) = force(1)%rho_core(1:3, 1) - fodeb(1:3)
2112 CALL para_env%sum(fodeb)
2113 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Vtot*dncore", fodeb
2115 IF (debug_stress .AND. use_virial)
THEN
2116 stdeb = fconv*(virial%pv_ehartree - stdeb)
2117 CALL para_env%sum(stdeb)
2118 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2119 'STRESS| Vtot*dncore', one_third_sum_diag(stdeb), det_3x3(stdeb)
2125 xc_section => ec_env%xc_section
2127 IF (use_virial) virial%pv_xc = 0.0_dp
2128 NULLIFY (v_xc, v_xc_tau)
2129 CALL create_kernel(qs_env, &
2136 xc_section=xc_section, &
2137 compute_virial=use_virial, &
2138 virial_xc=virial%pv_xc)
2140 IF (use_virial)
THEN
2142 virial%pv_exc = virial%pv_exc + virial%pv_xc
2143 virial%pv_virial = virial%pv_virial + virial%pv_xc
2145 IF (debug_stress .AND. use_virial)
THEN
2146 stdeb = 1.0_dp*fconv*virial%pv_xc
2147 CALL para_env%sum(stdeb)
2148 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2149 'STRESS| GGA 2nd f_Hxc[dP]*Pin ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2152 CALL get_qs_env(qs_env=qs_env, rho=rho, matrix_s_kp=matrix_s)
2153 NULLIFY (ec_env%matrix_hz)
2154 CALL dbcsr_allocate_matrix_set(ec_env%matrix_hz, nspins)
2155 DO ispin = 1, nspins
2156 ALLOCATE (ec_env%matrix_hz(ispin)%matrix)
2157 CALL dbcsr_create(ec_env%matrix_hz(ispin)%matrix, template=matrix_s(1, 1)%matrix)
2158 CALL dbcsr_copy(ec_env%matrix_hz(ispin)%matrix, matrix_s(1, 1)%matrix)
2159 CALL dbcsr_set(ec_env%matrix_hz(ispin)%matrix, 0.0_dp)
2161 CALL qs_rho_get(rho, rho_ao_kp=matrix_p)
2163 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
2164 IF (debug_stress .AND. use_virial) stdeb = virial%pv_virial
2167 IF (use_virial)
THEN
2168 pv_loc = virial%pv_virial
2171 DO ispin = 1, nspins
2172 CALL pw_scale(v_xc(ispin), v_xc(ispin)%pw_grid%dvol)
2173 CALL pw_axpy(dv_hartree_rspace, v_xc(ispin))
2174 CALL integrate_v_rspace(v_rspace=v_xc(ispin), &
2175 hmat=ec_env%matrix_hz(ispin), &
2176 pmat=matrix_p(ispin, 1), &
2178 calculate_forces=.true.)
2181 IF (debug_forces)
THEN
2182 fodeb(1:3) = force(1)%rho_elec(1:3, 1) - fodeb(1:3)
2183 CALL para_env%sum(fodeb)
2184 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Pin*dKdrho", fodeb
2186 IF (debug_stress .AND. use_virial)
THEN
2187 stdeb = fconv*(virial%pv_virial - stdeb)
2188 CALL para_env%sum(stdeb)
2189 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2190 'STRESS| INT 2nd f_Hxc[dP]*Pin ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2193 IF (
ASSOCIATED(v_xc_tau))
THEN
2194 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
2195 IF (debug_stress .AND. use_virial) stdeb = virial%pv_virial
2197 DO ispin = 1, nspins
2198 CALL pw_scale(v_xc_tau(ispin), v_xc_tau(ispin)%pw_grid%dvol)
2199 CALL integrate_v_rspace(v_rspace=v_xc_tau(ispin), &
2200 hmat=ec_env%matrix_hz(ispin), &
2201 pmat=matrix_p(ispin, 1), &
2203 compute_tau=.true., &
2204 calculate_forces=.true.)
2207 IF (debug_forces)
THEN
2208 fodeb(1:3) = force(1)%rho_elec(1:3, 1) - fodeb(1:3)
2209 CALL para_env%sum(fodeb)
2210 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Pin*dKtaudtau", fodeb
2212 IF (debug_stress .AND. use_virial)
THEN
2213 stdeb = fconv*(virial%pv_virial - stdeb)
2214 CALL para_env%sum(stdeb)
2215 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2216 'STRESS| INT 2nd f_xctau[dP]*Pin ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2220 IF (use_virial)
THEN
2221 virial%pv_ehartree = virial%pv_ehartree + (virial%pv_virial - pv_loc)
2226 CALL dbcsr_allocate_matrix_set(scrm, nspins)
2227 DO ispin = 1, nspins
2228 ALLOCATE (scrm(ispin)%matrix)
2229 CALL dbcsr_create(scrm(ispin)%matrix, template=ec_env%matrix_ks(ispin, 1)%matrix)
2230 CALL dbcsr_copy(scrm(ispin)%matrix, ec_env%matrix_ks(ispin, 1)%matrix)
2231 CALL dbcsr_set(scrm(ispin)%matrix, 0.0_dp)
2235 NULLIFY (v_rspace, v_tau_rspace)
2237 CALL qs_vxc_create(ks_env=ks_env, rho_struct=rho, xc_section=ec_env%xc_section, &
2238 vxc_rho=v_rspace, vxc_tau=v_tau_rspace, exc=eexc, just_energy=.false.)
2240 IF (use_virial)
THEN
2242 IF (
ASSOCIATED(v_rspace))
THEN
2243 DO ispin = 1, nspins
2245 eexc = eexc + pw_integral_ab(rhoout_r(ispin), v_rspace(ispin))
2248 IF (
ASSOCIATED(v_tau_rspace))
THEN
2249 DO ispin = 1, nspins
2251 eexc = eexc + pw_integral_ab(tauout_r(ispin), v_tau_rspace(ispin))
2256 IF (.NOT.
ASSOCIATED(v_rspace))
THEN
2257 ALLOCATE (v_rspace(nspins))
2258 DO ispin = 1, nspins
2259 CALL auxbas_pw_pool%create_pw(v_rspace(ispin))
2260 CALL pw_zero(v_rspace(ispin))
2266 IF (use_virial)
THEN
2267 pv_loc = virial%pv_virial
2270 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
2271 IF (debug_stress .AND. use_virial) stdeb = virial%pv_virial
2272 DO ispin = 1, nspins
2274 CALL pw_scale(v_rspace(ispin), v_rspace(ispin)%pw_grid%dvol)
2275 CALL pw_axpy(v_hartree_rspace, v_rspace(ispin))
2277 CALL integrate_v_rspace(v_rspace=v_rspace(ispin), &
2279 pmat=ec_env%matrix_p(ispin, 1), &
2281 calculate_forces=.true., &
2282 basis_type=
"HARRIS", &
2283 task_list_external=ec_env%task_list)
2286 IF (debug_forces)
THEN
2287 fodeb(1:3) = force(1)%rho_elec(1:3, 1) - fodeb(1:3)
2288 CALL para_env%sum(fodeb)
2289 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Pout*dVhxc ", fodeb
2291 IF (debug_stress .AND. use_virial)
THEN
2292 stdeb = fconv*(virial%pv_virial - stdeb)
2293 CALL para_env%sum(stdeb)
2294 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2295 'STRESS| INT Pout*dVhxc ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2299 IF (use_virial)
THEN
2300 virial%pv_ehartree = virial%pv_ehartree + (virial%pv_virial - pv_loc)
2303 IF (
ASSOCIATED(v_tau_rspace))
THEN
2304 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
2305 DO ispin = 1, nspins
2307 CALL pw_scale(v_tau_rspace(ispin), v_tau_rspace(ispin)%pw_grid%dvol)
2308 CALL integrate_v_rspace(v_rspace=v_tau_rspace(ispin), &
2310 pmat=ec_env%matrix_p(ispin, 1), &
2312 calculate_forces=.true., &
2313 compute_tau=.true., &
2314 basis_type=
"HARRIS", &
2315 task_list_external=ec_env%task_list)
2317 IF (debug_forces)
THEN
2318 fodeb(1:3) = force(1)%rho_elec(1:3, 1) - fodeb(1:3)
2319 CALL para_env%sum(fodeb)
2320 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Pout*dVhxc_tau ", fodeb
2329 ec_hfx_sections => section_vals_get_subs_vals(qs_env%input,
"DFT%ENERGY_CORRECTION%XC%HF")
2330 CALL section_vals_get(ec_hfx_sections, explicit=do_ec_hfx)
2334 IF (debug_forces) fodeb(1:3) = force(1)%fock_4c(1:3, 1)
2335 IF (use_virial) virial%pv_fock_4c = 0.0_dp
2337 CALL calculate_exx(qs_env=qs_env, &
2339 hfx_sections=ec_hfx_sections, &
2340 x_data=ec_env%x_data, &
2342 do_admm=ec_env%do_ec_admm, &
2343 calc_forces=.true., &
2344 reuse_hfx=ec_env%reuse_hfx, &
2345 do_im_time=.false., &
2346 e_ex_from_gw=dummy_real, &
2347 e_admm_from_gw=dummy_real2, &
2350 IF (use_virial)
THEN
2351 virial%pv_exx = virial%pv_exx - virial%pv_fock_4c
2352 virial%pv_virial = virial%pv_virial - virial%pv_fock_4c
2353 virial%pv_calculate = .false.
2355 IF (debug_forces)
THEN
2356 fodeb(1:3) = force(1)%fock_4c(1:3, 1) - fodeb(1:3)
2357 CALL para_env%sum(fodeb)
2358 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Pout*hfx ", fodeb
2360 IF (debug_stress .AND. use_virial)
THEN
2361 stdeb = -1.0_dp*fconv*virial%pv_fock_4c
2362 CALL para_env%sum(stdeb)
2363 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2364 'STRESS| Pout*hfx ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2372 CALL dbcsr_deallocate_matrix_set(scrm)
2375 CALL auxbas_pw_pool%give_back_pw(v_hartree_rspace)
2376 DO ispin = 1, nspins
2377 CALL auxbas_pw_pool%give_back_pw(v_rspace(ispin))
2378 IF (
ASSOCIATED(v_tau_rspace))
THEN
2379 CALL auxbas_pw_pool%give_back_pw(v_tau_rspace(ispin))
2382 IF (
ASSOCIATED(v_tau_rspace))
DEALLOCATE (v_tau_rspace)
2385 IF (debug_forces) fodeb(1:3) = force(1)%core_overlap(1:3, 1)
2386 IF (debug_stress .AND. use_virial) stdeb = virial%pv_ecore_overlap
2387 CALL calculate_ecore_overlap(qs_env, para_env, .true., e_overlap_core=eovrl)
2388 IF (debug_forces)
THEN
2389 fodeb(1:3) = force(1)%core_overlap(1:3, 1) - fodeb(1:3)
2390 CALL para_env%sum(fodeb)
2391 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: CoreOverlap", fodeb
2393 IF (debug_stress .AND. use_virial)
THEN
2394 stdeb = fconv*(stdeb - virial%pv_ecore_overlap)
2395 CALL para_env%sum(stdeb)
2396 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2397 'STRESS| CoreOverlap ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2400 IF (debug_forces)
THEN
2401 CALL get_qs_env(qs_env, natom=natom, atomic_kind_set=atomic_kind_set)
2402 ALLOCATE (ftot(3, natom))
2403 CALL total_qs_force(ftot, force, atomic_kind_set)
2404 fodeb(1:3) = ftot(1:3, 1)
2406 CALL para_env%sum(fodeb)
2407 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Force Explicit", fodeb
2410 DEALLOCATE (v_rspace)
2412 CALL auxbas_pw_pool%give_back_pw(dv_hartree_rspace)
2413 CALL auxbas_pw_pool%give_back_pw(vtot_rspace)
2414 DO ispin = 1, nspins
2415 CALL auxbas_pw_pool%give_back_pw(rhoout_r(ispin))
2416 CALL auxbas_pw_pool%give_back_pw(rhoout_g(ispin))
2417 CALL auxbas_pw_pool%give_back_pw(v_xc(ispin))
2419 DEALLOCATE (rhoout_r, rhoout_g, v_xc)
2420 IF (
ASSOCIATED(tauout_r))
THEN
2421 DO ispin = 1, nspins
2422 CALL auxbas_pw_pool%give_back_pw(tauout_r(ispin))
2424 DEALLOCATE (tauout_r)
2426 IF (
ASSOCIATED(v_xc_tau))
THEN
2427 DO ispin = 1, nspins
2428 CALL auxbas_pw_pool%give_back_pw(v_xc_tau(ispin))
2430 DEALLOCATE (v_xc_tau)
2432 CALL auxbas_pw_pool%give_back_pw(v_hartree_gspace)
2433 CALL auxbas_pw_pool%give_back_pw(rhodn_tot_gspace)
2437 IF (use_virial)
THEN
2438 IF (qs_env%energy_correction)
THEN
2439 ec_env%ehartree = ehartree + dehartree
2440 ec_env%exc = exc + eexc
2444 IF (debug_stress .AND. use_virial)
THEN
2446 stdeb = -1.0_dp*fconv*ehartree
2447 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2448 'STRESS| VOL 1st v_H[n_in]*n_out', one_third_sum_diag(stdeb), det_3x3(stdeb)
2450 stdeb = -1.0_dp*fconv*exc
2451 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2452 'STRESS| VOL 1st E_XC[n_in]', one_third_sum_diag(stdeb), det_3x3(stdeb)
2454 stdeb = -1.0_dp*fconv*dehartree
2455 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2456 'STRESS| VOL 2nd v_H[dP]*n_in', one_third_sum_diag(stdeb), det_3x3(stdeb)
2458 stdeb = -1.0_dp*fconv*eexc
2459 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2460 'STRESS| VOL 2nd v_XC[n_in]*dP', one_third_sum_diag(stdeb), det_3x3(stdeb)
2465 TYPE(virial_type) :: virdeb
2468 CALL para_env%sum(virdeb%pv_overlap)
2469 CALL para_env%sum(virdeb%pv_ekinetic)
2470 CALL para_env%sum(virdeb%pv_ppl)
2471 CALL para_env%sum(virdeb%pv_ppnl)
2472 CALL para_env%sum(virdeb%pv_ecore_overlap)
2473 CALL para_env%sum(virdeb%pv_ehartree)
2474 CALL para_env%sum(virdeb%pv_exc)
2475 CALL para_env%sum(virdeb%pv_exx)
2476 CALL para_env%sum(virdeb%pv_vdw)
2477 CALL para_env%sum(virdeb%pv_mp2)
2478 CALL para_env%sum(virdeb%pv_nlcc)
2479 CALL para_env%sum(virdeb%pv_gapw)
2480 CALL para_env%sum(virdeb%pv_lrigpw)
2481 CALL para_env%sum(virdeb%pv_virial)
2482 CALL symmetrize_virial(virdeb)
2486 virdeb%pv_ehartree(i, i) = virdeb%pv_ehartree(i, i) - 2.0_dp*(ehartree + dehartree)
2487 virdeb%pv_virial(i, i) = virdeb%pv_virial(i, i) - exc - eexc &
2488 - 2.0_dp*(ehartree + dehartree)
2489 virdeb%pv_exc(i, i) = virdeb%pv_exc(i, i) - exc - eexc
2495 CALL para_env%sum(sttot)
2496 stdeb = fconv*(virdeb%pv_virial - sttot)
2497 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2498 'STRESS| Explicit electronic stress ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2500 stdeb = fconv*(virdeb%pv_virial)
2501 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2502 'STRESS| Explicit total stress ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2504 CALL write_stress_tensor_components(virdeb, iounit, cell, unit_string)
2505 CALL write_stress_tensor(virdeb%pv_virial, iounit, cell, unit_string, .false.)
2510 CALL timestop(handle)
2512 END SUBROUTINE ec_build_ks_matrix_force
2522 SUBROUTINE ec_ks_solver(qs_env, ec_env)
2524 TYPE(qs_environment_type),
POINTER :: qs_env
2525 TYPE(energy_correction_type),
POINTER :: ec_env
2527 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ec_ks_solver'
2529 CHARACTER(LEN=default_string_length) :: headline
2530 INTEGER :: handle, ispin, nspins
2531 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: ksmat, pmat, smat, wmat
2532 TYPE(dft_control_type),
POINTER :: dft_control
2534 CALL timeset(routinen, handle)
2536 CALL get_qs_env(qs_env=qs_env, dft_control=dft_control)
2537 nspins = dft_control%nspins
2540 IF (.NOT.
ASSOCIATED(ec_env%matrix_p))
THEN
2541 headline =
"DENSITY MATRIX"
2542 CALL dbcsr_allocate_matrix_set(ec_env%matrix_p, nspins, 1)
2543 DO ispin = 1, nspins
2544 ALLOCATE (ec_env%matrix_p(ispin, 1)%matrix)
2545 CALL dbcsr_create(ec_env%matrix_p(ispin, 1)%matrix, name=trim(headline), &
2546 template=ec_env%matrix_s(1, 1)%matrix)
2547 CALL cp_dbcsr_alloc_block_from_nbl(ec_env%matrix_p(ispin, 1)%matrix, ec_env%sab_orb)
2551 IF (.NOT.
ASSOCIATED(ec_env%matrix_w))
THEN
2552 headline =
"ENERGY WEIGHTED DENSITY MATRIX"
2553 CALL dbcsr_allocate_matrix_set(ec_env%matrix_w, nspins, 1)
2554 DO ispin = 1, nspins
2555 ALLOCATE (ec_env%matrix_w(ispin, 1)%matrix)
2556 CALL dbcsr_create(ec_env%matrix_w(ispin, 1)%matrix, name=trim(headline), &
2557 template=ec_env%matrix_s(1, 1)%matrix)
2558 CALL cp_dbcsr_alloc_block_from_nbl(ec_env%matrix_w(ispin, 1)%matrix, ec_env%sab_orb)
2562 IF (ec_env%mao)
THEN
2563 CALL mao_create_matrices(ec_env, ksmat, smat, pmat, wmat)
2565 ksmat => ec_env%matrix_ks
2566 smat => ec_env%matrix_s
2567 pmat => ec_env%matrix_p
2568 wmat => ec_env%matrix_w
2571 SELECT CASE (ec_env%ks_solver)
2572 CASE (ec_diagonalization)
2573 CALL ec_diag_solver(qs_env, ksmat, smat, pmat, wmat)
2575 CALL ec_ot_diag_solver(qs_env, ec_env, ksmat, smat, pmat, wmat)
2576 CASE (ec_matrix_sign, ec_matrix_trs4, ec_matrix_tc2)
2577 CALL ec_ls_init(qs_env, ksmat, smat)
2578 CALL ec_ls_solver(qs_env, pmat, wmat, ec_ls_method=ec_env%ks_solver)
2583 IF (ec_env%mao)
THEN
2584 CALL mao_release_matrices(ec_env, ksmat, smat, pmat, wmat)
2587 CALL timestop(handle)
2589 END SUBROUTINE ec_ks_solver
2602 SUBROUTINE mao_create_matrices(ec_env, ksmat, smat, pmat, wmat)
2604 TYPE(energy_correction_type),
POINTER :: ec_env
2605 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: ksmat, smat, pmat, wmat
2607 CHARACTER(LEN=*),
PARAMETER :: routinen =
'mao_create_matrices'
2609 INTEGER :: handle, ispin, nspins
2610 INTEGER,
DIMENSION(:),
POINTER :: col_blk_sizes
2611 TYPE(dbcsr_distribution_type) :: dbcsr_dist
2612 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: mao_coef
2613 TYPE(dbcsr_type) :: cgmat
2615 CALL timeset(routinen, handle)
2617 mao_coef => ec_env%mao_coef
2619 NULLIFY (ksmat, smat, pmat, wmat)
2620 nspins =
SIZE(ec_env%matrix_ks, 1)
2621 CALL dbcsr_get_info(mao_coef(1)%matrix, col_blk_size=col_blk_sizes, distribution=dbcsr_dist)
2622 CALL dbcsr_allocate_matrix_set(ksmat, nspins, 1)
2623 CALL dbcsr_allocate_matrix_set(smat, nspins, 1)
2624 DO ispin = 1, nspins
2625 ALLOCATE (ksmat(ispin, 1)%matrix)
2626 CALL dbcsr_create(ksmat(ispin, 1)%matrix, dist=dbcsr_dist, name=
"MAO KS mat", &
2627 matrix_type=dbcsr_type_symmetric, row_blk_size=col_blk_sizes, &
2628 col_blk_size=col_blk_sizes)
2629 ALLOCATE (smat(ispin, 1)%matrix)
2630 CALL dbcsr_create(smat(ispin, 1)%matrix, dist=dbcsr_dist, name=
"MAO S mat", &
2631 matrix_type=dbcsr_type_symmetric, row_blk_size=col_blk_sizes, &
2632 col_blk_size=col_blk_sizes)
2635 CALL dbcsr_create(cgmat, name=
"TEMP matrix", template=mao_coef(1)%matrix)
2636 DO ispin = 1, nspins
2637 CALL dbcsr_multiply(
"N",
"N", 1.0_dp, ec_env%matrix_s(1, 1)%matrix, mao_coef(ispin)%matrix, &
2639 CALL dbcsr_multiply(
"T",
"N", 1.0_dp, mao_coef(ispin)%matrix, cgmat, 0.0_dp, smat(ispin, 1)%matrix)
2640 CALL dbcsr_multiply(
"N",
"N", 1.0_dp, ec_env%matrix_ks(1, 1)%matrix, mao_coef(ispin)%matrix, &
2642 CALL dbcsr_multiply(
"T",
"N", 1.0_dp, mao_coef(ispin)%matrix, cgmat, 0.0_dp, ksmat(ispin, 1)%matrix)
2644 CALL dbcsr_release(cgmat)
2646 CALL dbcsr_allocate_matrix_set(pmat, nspins, 1)
2647 DO ispin = 1, nspins
2648 ALLOCATE (pmat(ispin, 1)%matrix)
2649 CALL dbcsr_create(pmat(ispin, 1)%matrix, template=smat(1, 1)%matrix, name=
"MAO P mat")
2650 CALL cp_dbcsr_alloc_block_from_nbl(pmat(ispin, 1)%matrix, ec_env%sab_orb)
2653 CALL dbcsr_allocate_matrix_set(wmat, nspins, 1)
2654 DO ispin = 1, nspins
2655 ALLOCATE (wmat(ispin, 1)%matrix)
2656 CALL dbcsr_create(wmat(ispin, 1)%matrix, template=smat(1, 1)%matrix, name=
"MAO W mat")
2657 CALL cp_dbcsr_alloc_block_from_nbl(wmat(ispin, 1)%matrix, ec_env%sab_orb)
2660 CALL timestop(handle)
2662 END SUBROUTINE mao_create_matrices
2675 SUBROUTINE mao_release_matrices(ec_env, ksmat, smat, pmat, wmat)
2677 TYPE(energy_correction_type),
POINTER :: ec_env
2678 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: ksmat, smat, pmat, wmat
2680 CHARACTER(LEN=*),
PARAMETER :: routinen =
'mao_release_matrices'
2682 INTEGER :: handle, ispin, nspins
2683 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: mao_coef
2684 TYPE(dbcsr_type) :: cgmat
2686 CALL timeset(routinen, handle)
2688 mao_coef => ec_env%mao_coef
2689 nspins =
SIZE(mao_coef, 1)
2692 CALL dbcsr_create(cgmat, name=
"TEMP matrix", template=mao_coef(1)%matrix)
2693 DO ispin = 1, nspins
2694 CALL dbcsr_multiply(
"N",
"N", 1.0_dp, mao_coef(ispin)%matrix, pmat(ispin, 1)%matrix, 0.0_dp, cgmat)
2695 CALL dbcsr_multiply(
"N",
"T", 1.0_dp, mao_coef(ispin)%matrix, cgmat, 0.0_dp, &
2696 ec_env%matrix_p(ispin, 1)%matrix, retain_sparsity=.true.)
2697 CALL dbcsr_multiply(
"N",
"N", 1.0_dp, mao_coef(ispin)%matrix, wmat(ispin, 1)%matrix, 0.0_dp, cgmat)
2698 CALL dbcsr_multiply(
"N",
"T", 1.0_dp, mao_coef(ispin)%matrix, cgmat, 0.0_dp, &
2699 ec_env%matrix_w(ispin, 1)%matrix, retain_sparsity=.true.)
2701 CALL dbcsr_release(cgmat)
2703 CALL dbcsr_deallocate_matrix_set(ksmat)
2704 CALL dbcsr_deallocate_matrix_set(smat)
2705 CALL dbcsr_deallocate_matrix_set(pmat)
2706 CALL dbcsr_deallocate_matrix_set(wmat)
2708 CALL timestop(handle)
2710 END SUBROUTINE mao_release_matrices
2723 SUBROUTINE ec_diag_solver(qs_env, matrix_ks, matrix_s, matrix_p, matrix_w)
2725 TYPE(qs_environment_type),
POINTER :: qs_env
2726 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_ks, matrix_s, matrix_p, matrix_w
2728 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ec_diag_solver'
2730 INTEGER :: handle, ispin, nmo(2), nsize, nspins
2731 REAL(kind=dp) :: eps_filter, focc(2)
2732 REAL(kind=dp),
ALLOCATABLE,
DIMENSION(:) :: eigenvalues
2733 TYPE(cp_blacs_env_type),
POINTER :: blacs_env
2734 TYPE(cp_fm_struct_type),
POINTER :: fm_struct
2735 TYPE(cp_fm_type) :: fm_ks, fm_mo, fm_ortho
2736 TYPE(dbcsr_type),
POINTER :: buf1_dbcsr, buf2_dbcsr, buf3_dbcsr, &
2737 ortho_dbcsr, ref_matrix
2738 TYPE(dft_control_type),
POINTER :: dft_control
2739 TYPE(mp_para_env_type),
POINTER :: para_env
2741 CALL timeset(routinen, handle)
2743 NULLIFY (blacs_env, para_env)
2744 CALL get_qs_env(qs_env=qs_env, blacs_env=blacs_env, para_env=para_env)
2746 CALL get_qs_env(qs_env=qs_env, dft_control=dft_control)
2747 eps_filter = dft_control%qs_control%eps_filter_matrix
2748 nspins = dft_control%nspins
2751 CALL get_qs_env(qs_env=qs_env, nelectron_spin=nmo)
2753 IF (nspins == 1)
THEN
2758 CALL dbcsr_get_info(matrix_ks(1, 1)%matrix, nfullrows_total=nsize)
2759 ALLOCATE (eigenvalues(nsize))
2761 NULLIFY (fm_struct, ref_matrix)
2762 CALL cp_fm_struct_create(fm_struct, context=blacs_env, nrow_global=nsize, &
2763 ncol_global=nsize, para_env=para_env)
2764 CALL cp_fm_create(fm_ortho, fm_struct)
2765 CALL cp_fm_create(fm_ks, fm_struct)
2766 CALL cp_fm_create(fm_mo, fm_struct)
2767 CALL cp_fm_struct_release(fm_struct)
2770 ref_matrix => matrix_s(1, 1)%matrix
2771 NULLIFY (ortho_dbcsr, buf1_dbcsr, buf2_dbcsr, buf3_dbcsr)
2772 CALL dbcsr_init_p(ortho_dbcsr)
2773 CALL dbcsr_create(ortho_dbcsr, template=ref_matrix, &
2774 matrix_type=dbcsr_type_no_symmetry)
2775 CALL dbcsr_init_p(buf1_dbcsr)
2776 CALL dbcsr_create(buf1_dbcsr, template=ref_matrix, &
2777 matrix_type=dbcsr_type_no_symmetry)
2778 CALL dbcsr_init_p(buf2_dbcsr)
2779 CALL dbcsr_create(buf2_dbcsr, template=ref_matrix, &
2780 matrix_type=dbcsr_type_no_symmetry)
2781 CALL dbcsr_init_p(buf3_dbcsr)
2782 CALL dbcsr_create(buf3_dbcsr, template=ref_matrix, &
2783 matrix_type=dbcsr_type_no_symmetry)
2785 ref_matrix => matrix_s(1, 1)%matrix
2786 CALL copy_dbcsr_to_fm(ref_matrix, fm_ortho)
2787 CALL cp_fm_cholesky_decompose(fm_ortho)
2788 CALL cp_fm_triangular_invert(fm_ortho)
2789 CALL cp_fm_set_all(fm_ks, 0.0_dp)
2790 CALL cp_fm_to_fm_triangular(fm_ortho, fm_ks,
"U")
2791 CALL copy_fm_to_dbcsr(fm_ks, ortho_dbcsr)
2792 DO ispin = 1, nspins
2794 CALL dbcsr_desymmetrize(matrix_ks(ispin, 1)%matrix, buf1_dbcsr)
2795 CALL dbcsr_multiply(
"N",
"N", 1.0_dp, buf1_dbcsr, ortho_dbcsr, &
2796 0.0_dp, buf2_dbcsr, filter_eps=eps_filter)
2797 CALL dbcsr_multiply(
"T",
"N", 1.0_dp, ortho_dbcsr, buf2_dbcsr, &
2798 0.0_dp, buf1_dbcsr, filter_eps=eps_filter)
2800 CALL copy_dbcsr_to_fm(buf1_dbcsr, fm_ks)
2801 CALL choose_eigv_solver(fm_ks, fm_mo, eigenvalues)
2803 CALL copy_fm_to_dbcsr(fm_mo, buf1_dbcsr)
2804 CALL dbcsr_multiply(
"N",
"N", 1.0_dp, ortho_dbcsr, buf1_dbcsr, &
2805 0.0_dp, buf2_dbcsr, filter_eps=eps_filter)
2807 CALL dbcsr_set(matrix_p(ispin, 1)%matrix, 0.0_dp)
2808 CALL dbcsr_multiply(
"N",
"T", focc(ispin), buf2_dbcsr, buf2_dbcsr, &
2809 1.0_dp, matrix_p(ispin, 1)%matrix, &
2810 retain_sparsity=.true., last_k=nmo(ispin))
2813 CALL dbcsr_set(matrix_w(ispin, 1)%matrix, 0.0_dp)
2814 CALL cp_fm_column_scale(fm_mo, eigenvalues)
2815 CALL copy_fm_to_dbcsr(fm_mo, buf1_dbcsr)
2816 CALL dbcsr_multiply(
"N",
"N", 1.0_dp, ortho_dbcsr, buf1_dbcsr, &
2817 0.0_dp, buf3_dbcsr, filter_eps=eps_filter)
2818 CALL dbcsr_multiply(
"N",
"T", focc(ispin), buf2_dbcsr, buf3_dbcsr, &
2819 1.0_dp, matrix_w(ispin, 1)%matrix, &
2820 retain_sparsity=.true., last_k=nmo(ispin))
2823 CALL cp_fm_release(fm_ks)
2824 CALL cp_fm_release(fm_mo)
2825 CALL cp_fm_release(fm_ortho)
2826 CALL dbcsr_release(ortho_dbcsr)
2827 CALL dbcsr_release(buf1_dbcsr)
2828 CALL dbcsr_release(buf2_dbcsr)
2829 CALL dbcsr_release(buf3_dbcsr)
2830 DEALLOCATE (ortho_dbcsr, buf1_dbcsr, buf2_dbcsr, buf3_dbcsr)
2831 DEALLOCATE (eigenvalues)
2833 CALL timestop(handle)
2835 END SUBROUTINE ec_diag_solver
2843 SUBROUTINE ec_energy(ec_env, unit_nr)
2844 TYPE(energy_correction_type) :: ec_env
2845 INTEGER,
INTENT(IN) :: unit_nr
2847 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ec_energy'
2849 INTEGER :: handle, ispin, nspins
2850 REAL(kind=dp) :: eband, trace
2852 CALL timeset(routinen, handle)
2854 nspins =
SIZE(ec_env%matrix_p, 1)
2855 DO ispin = 1, nspins
2856 CALL dbcsr_dot(ec_env%matrix_p(ispin, 1)%matrix, ec_env%matrix_s(1, 1)%matrix, trace)
2857 IF (unit_nr > 0)
WRITE (unit_nr,
'(T3,A,T65,F16.10)')
'Tr[PS] ', trace
2861 SELECT CASE (ec_env%energy_functional)
2862 CASE (ec_functional_harris)
2866 DO ispin = 1, nspins
2867 CALL dbcsr_dot(ec_env%matrix_ks(ispin, 1)%matrix, ec_env%matrix_p(ispin, 1)%matrix, trace)
2868 eband = eband + trace
2870 ec_env%eband = eband + ec_env%efield_nuclear
2873 ec_env%etotal = ec_env%eband + ec_env%ehartree + ec_env%exc - ec_env%vhxc + ec_env%edispersion - ec_env%ex
2874 IF (unit_nr > 0)
THEN
2875 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Eband ", ec_env%eband
2876 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Ehartree ", ec_env%ehartree
2877 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Exc ", ec_env%exc
2878 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Ex ", ec_env%ex
2879 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Evhxc ", ec_env%vhxc
2880 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Edisp ", ec_env%edispersion
2881 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Etotal Harris Functional ", ec_env%etotal
2884 CASE (ec_functional_dc)
2887 CALL calculate_ptrace(ec_env%matrix_h, ec_env%matrix_p, ec_env%ecore,
SIZE(ec_env%matrix_p, 1))
2889 ec_env%ecore = ec_env%ecore + ec_env%efield_nuclear
2890 ec_env%etotal = ec_env%ecore + ec_env%ehartree + ec_env%exc + ec_env%edispersion &
2891 + ec_env%ex + ec_env%exc_aux_fit
2893 IF (unit_nr > 0)
THEN
2894 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Ecore ", ec_env%ecore
2895 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Ehartree ", ec_env%ehartree
2896 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Exc ", ec_env%exc
2897 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Ex ", ec_env%ex
2898 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Exc_aux_fit", ec_env%exc_aux_fit
2899 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Edisp ", ec_env%edispersion
2900 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Etotal Energy Functional ", ec_env%etotal
2903 CASE (ec_functional_ext)
2905 ec_env%etotal = ec_env%ex
2906 IF (unit_nr > 0)
THEN
2907 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Etotal Energy Functional ", ec_env%etotal
2916 CALL timestop(handle)
2918 END SUBROUTINE ec_energy
2930 SUBROUTINE ec_build_neighborlist(qs_env, ec_env)
2931 TYPE(qs_environment_type),
POINTER :: qs_env
2932 TYPE(energy_correction_type),
POINTER :: ec_env
2934 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ec_build_neighborlist'
2936 INTEGER :: handle, ikind, nkind, zat
2937 LOGICAL :: gth_potential_present, &
2938 sgp_potential_present, &
2939 skip_load_balance_distributed
2940 LOGICAL,
ALLOCATABLE,
DIMENSION(:) :: default_present, orb_present, &
2941 ppl_present, ppnl_present
2942 REAL(dp) :: subcells
2943 REAL(dp),
ALLOCATABLE,
DIMENSION(:) :: c_radius, orb_radius, ppl_radius, &
2945 REAL(dp),
ALLOCATABLE,
DIMENSION(:, :) :: pair_radius
2946 TYPE(atomic_kind_type),
DIMENSION(:),
POINTER :: atomic_kind_set
2947 TYPE(cell_type),
POINTER :: cell
2948 TYPE(dft_control_type),
POINTER :: dft_control
2949 TYPE(distribution_1d_type),
POINTER :: distribution_1d
2950 TYPE(distribution_2d_type),
POINTER :: distribution_2d
2951 TYPE(gth_potential_type),
POINTER :: gth_potential
2952 TYPE(gto_basis_set_type),
POINTER :: basis_set
2953 TYPE(local_atoms_type),
ALLOCATABLE,
DIMENSION(:) :: atom2d
2954 TYPE(molecule_type),
DIMENSION(:),
POINTER :: molecule_set
2955 TYPE(neighbor_list_set_p_type),
DIMENSION(:), &
2956 POINTER :: sab_cn, sab_vdw
2957 TYPE(particle_type),
DIMENSION(:),
POINTER :: particle_set
2958 TYPE(qs_dispersion_type),
POINTER :: dispersion_env
2959 TYPE(qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
2960 TYPE(qs_kind_type),
POINTER :: qs_kind
2961 TYPE(qs_ks_env_type),
POINTER :: ks_env
2962 TYPE(sgp_potential_type),
POINTER :: sgp_potential
2964 CALL timeset(routinen, handle)
2966 CALL get_qs_env(qs_env=qs_env, qs_kind_set=qs_kind_set)
2967 CALL get_qs_kind_set(qs_kind_set, gth_potential_present=gth_potential_present, &
2968 sgp_potential_present=sgp_potential_present)
2969 nkind =
SIZE(qs_kind_set)
2970 ALLOCATE (c_radius(nkind), default_present(nkind))
2971 ALLOCATE (orb_radius(nkind), ppl_radius(nkind), ppnl_radius(nkind))
2972 ALLOCATE (orb_present(nkind), ppl_present(nkind), ppnl_present(nkind))
2973 ALLOCATE (pair_radius(nkind, nkind))
2974 ALLOCATE (atom2d(nkind))
2976 CALL get_qs_env(qs_env, &
2977 atomic_kind_set=atomic_kind_set, &
2979 distribution_2d=distribution_2d, &
2980 local_particles=distribution_1d, &
2981 particle_set=particle_set, &
2982 molecule_set=molecule_set)
2984 CALL atom2d_build(atom2d, distribution_1d, distribution_2d, atomic_kind_set, &
2985 molecule_set, .false., particle_set)
2988 CALL get_atomic_kind(atomic_kind_set(ikind), atom_list=atom2d(ikind)%list)
2989 qs_kind => qs_kind_set(ikind)
2990 CALL get_qs_kind(qs_kind=qs_kind, basis_set=basis_set, basis_type=
"HARRIS")
2991 IF (
ASSOCIATED(basis_set))
THEN
2992 orb_present(ikind) = .true.
2993 CALL get_gto_basis_set(gto_basis_set=basis_set, kind_radius=orb_radius(ikind))
2995 orb_present(ikind) = .false.
2996 orb_radius(ikind) = 0.0_dp
2998 CALL get_qs_kind(qs_kind, gth_potential=gth_potential, sgp_potential=sgp_potential)
2999 IF (gth_potential_present .OR. sgp_potential_present)
THEN
3000 IF (
ASSOCIATED(gth_potential))
THEN
3001 CALL get_potential(potential=gth_potential, &
3002 ppl_present=ppl_present(ikind), &
3003 ppl_radius=ppl_radius(ikind), &
3004 ppnl_present=ppnl_present(ikind), &
3005 ppnl_radius=ppnl_radius(ikind))
3006 ELSE IF (
ASSOCIATED(sgp_potential))
THEN
3007 CALL get_potential(potential=sgp_potential, &
3008 ppl_present=ppl_present(ikind), &
3009 ppl_radius=ppl_radius(ikind), &
3010 ppnl_present=ppnl_present(ikind), &
3011 ppnl_radius=ppnl_radius(ikind))
3013 ppl_present(ikind) = .false.
3014 ppl_radius(ikind) = 0.0_dp
3015 ppnl_present(ikind) = .false.
3016 ppnl_radius(ikind) = 0.0_dp
3021 CALL section_vals_val_get(qs_env%input,
"DFT%SUBCELLS", r_val=subcells)
3024 CALL pair_radius_setup(orb_present, orb_present, orb_radius, orb_radius, pair_radius)
3025 CALL build_neighbor_lists(ec_env%sab_orb, particle_set, atom2d, cell, pair_radius, &
3026 subcells=subcells, nlname=
"sab_orb")
3028 IF (gth_potential_present .OR. sgp_potential_present)
THEN
3029 IF (any(ppl_present))
THEN
3030 CALL pair_radius_setup(orb_present, ppl_present, orb_radius, ppl_radius, pair_radius)
3031 CALL build_neighbor_lists(ec_env%sac_ppl, particle_set, atom2d, cell, pair_radius, &
3032 subcells=subcells, operator_type=
"ABC", nlname=
"sac_ppl")
3035 IF (any(ppnl_present))
THEN
3036 CALL pair_radius_setup(orb_present, ppnl_present, orb_radius, ppnl_radius, pair_radius)
3037 CALL build_neighbor_lists(ec_env%sap_ppnl, particle_set, atom2d, cell, pair_radius, &
3038 subcells=subcells, operator_type=
"ABBA", nlname=
"sap_ppnl")
3043 c_radius(:) = 0.0_dp
3044 dispersion_env => ec_env%dispersion_env
3045 sab_vdw => dispersion_env%sab_vdw
3046 sab_cn => dispersion_env%sab_cn
3047 IF (dispersion_env%type == xc_vdw_fun_pairpot)
THEN
3048 c_radius(:) = dispersion_env%rc_disp
3049 default_present = .true.
3050 CALL pair_radius_setup(default_present, default_present, c_radius, c_radius, pair_radius)
3051 CALL build_neighbor_lists(sab_vdw, particle_set, atom2d, cell, pair_radius, &
3052 subcells=subcells, operator_type=
"PP", nlname=
"sab_vdw")
3053 dispersion_env%sab_vdw => sab_vdw
3054 IF (dispersion_env%pp_type == vdw_pairpot_dftd3 .OR. &
3055 dispersion_env%pp_type == vdw_pairpot_dftd3bj)
THEN
3058 CALL get_atomic_kind(atomic_kind_set(ikind), z=zat)
3059 c_radius(ikind) = 4._dp*ptable(zat)%covalent_radius*bohr
3061 CALL pair_radius_setup(default_present, default_present, c_radius, c_radius, pair_radius)
3062 CALL build_neighbor_lists(sab_cn, particle_set, atom2d, cell, pair_radius, &
3063 subcells=subcells, operator_type=
"PP", nlname=
"sab_cn")
3064 dispersion_env%sab_cn => sab_cn
3069 CALL atom2d_cleanup(atom2d)
3071 DEALLOCATE (orb_present, default_present, ppl_present, ppnl_present)
3072 DEALLOCATE (orb_radius, ppl_radius, ppnl_radius, c_radius)
3073 DEALLOCATE (pair_radius)
3076 CALL get_qs_env(qs_env, ks_env=ks_env, dft_control=dft_control)
3077 skip_load_balance_distributed = dft_control%qs_control%skip_load_balance_distributed
3078 IF (
ASSOCIATED(ec_env%task_list))
CALL deallocate_task_list(ec_env%task_list)
3079 CALL allocate_task_list(ec_env%task_list)
3080 CALL generate_qs_task_list(ks_env, ec_env%task_list, &
3081 reorder_rs_grid_ranks=.false., soft_valid=.false., &
3082 skip_load_balance_distributed=skip_load_balance_distributed, &
3083 basis_type=
"HARRIS", sab_orb_external=ec_env%sab_orb)
3085 CALL timestop(handle)
3087 END SUBROUTINE ec_build_neighborlist
3094 SUBROUTINE ec_properties(qs_env, ec_env)
3095 TYPE(qs_environment_type),
POINTER :: qs_env
3096 TYPE(energy_correction_type),
POINTER :: ec_env
3098 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ec_properties'
3100 CHARACTER(LEN=8),
DIMENSION(3) :: rlab
3101 CHARACTER(LEN=default_path_length) :: filename, my_pos_voro
3102 CHARACTER(LEN=default_string_length) :: description
3103 INTEGER :: akind, handle, i, ia, iatom, idir, ikind, iounit, ispin, maxmom, nspins, &
3104 reference, should_print_bqb, should_print_voro, unit_nr, unit_nr_voro
3105 LOGICAL :: append_voro, magnetic, periodic, &
3107 REAL(kind=dp) :: charge, dd, focc, tmp
3108 REAL(kind=dp),
DIMENSION(3) :: cdip, pdip, rcc, rdip, ria, tdip
3109 REAL(kind=dp),
DIMENSION(:),
POINTER :: ref_point
3110 TYPE(atomic_kind_type),
POINTER :: atomic_kind
3111 TYPE(cell_type),
POINTER :: cell
3112 TYPE(cp_logger_type),
POINTER :: logger
3113 TYPE(cp_result_type),
POINTER :: results
3114 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_s, moments
3115 TYPE(dft_control_type),
POINTER :: dft_control
3116 TYPE(distribution_1d_type),
POINTER :: local_particles
3117 TYPE(mp_para_env_type),
POINTER :: para_env
3118 TYPE(particle_type),
DIMENSION(:),
POINTER :: particle_set
3119 TYPE(pw_env_type),
POINTER :: pw_env
3120 TYPE(pw_pool_p_type),
DIMENSION(:),
POINTER :: pw_pools
3121 TYPE(pw_pool_type),
POINTER :: auxbas_pw_pool
3122 TYPE(pw_r3d_rs_type) :: rho_elec_rspace
3123 TYPE(qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
3124 TYPE(section_vals_type),
POINTER :: ec_section, print_key, print_key_bqb, &
3127 CALL timeset(routinen, handle)
3133 logger => cp_get_default_logger()
3134 IF (logger%para_env%is_source())
THEN
3135 iounit = cp_logger_get_default_unit_nr(logger, local=.true.)
3140 NULLIFY (dft_control)
3141 CALL get_qs_env(qs_env, dft_control=dft_control)
3142 nspins = dft_control%nspins
3144 ec_section => section_vals_get_subs_vals(qs_env%input,
"DFT%ENERGY_CORRECTION")
3145 print_key => section_vals_get_subs_vals(section_vals=ec_section, &
3146 subsection_name=
"PRINT%MOMENTS")
3148 IF (btest(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file))
THEN
3150 maxmom = section_get_ival(section_vals=ec_section, &
3151 keyword_name=
"PRINT%MOMENTS%MAX_MOMENT")
3152 periodic = section_get_lval(section_vals=ec_section, &
3153 keyword_name=
"PRINT%MOMENTS%PERIODIC")
3154 reference = section_get_ival(section_vals=ec_section, &
3155 keyword_name=
"PRINT%MOMENTS%REFERENCE")
3156 magnetic = section_get_lval(section_vals=ec_section, &
3157 keyword_name=
"PRINT%MOMENTS%MAGNETIC")
3159 CALL section_vals_val_get(ec_section,
"PRINT%MOMENTS%REF_POINT", r_vals=ref_point)
3160 unit_nr = cp_print_key_unit_nr(logger=logger, basis_section=ec_section, &
3161 print_key_path=
"PRINT%MOMENTS", extension=
".dat", &
3162 middle_name=
"moments", log_filename=.false.)
3164 IF (iounit > 0)
THEN
3165 IF (unit_nr /= iounit .AND. unit_nr > 0)
THEN
3166 INQUIRE (unit=unit_nr, name=filename)
3167 WRITE (unit=iounit, fmt=
"(/,T2,A,2(/,T3,A),/)") &
3168 "MOMENTS",
"The electric/magnetic moments are written to file:", &
3171 WRITE (unit=iounit, fmt=
"(/,T2,A)")
"ELECTRIC/MAGNETIC MOMENTS"
3176 cpabort(
"Periodic moments not implemented with EC")
3178 cpassert(maxmom < 2)
3179 cpassert(.NOT. magnetic)
3180 IF (maxmom == 1)
THEN
3181 CALL get_qs_env(qs_env=qs_env, cell=cell, para_env=para_env)
3183 CALL get_reference_point(rcc, qs_env=qs_env, reference=reference, ref_point=ref_point)
3186 CALL get_qs_env(qs_env=qs_env, particle_set=particle_set, &
3187 qs_kind_set=qs_kind_set, local_particles=local_particles)
3188 DO ikind = 1,
SIZE(local_particles%n_el)
3189 DO ia = 1, local_particles%n_el(ikind)
3190 iatom = local_particles%list(ikind)%array(ia)
3192 ria = pbc(particle_set(iatom)%r - rcc, cell) + rcc
3194 atomic_kind => particle_set(iatom)%atomic_kind
3195 CALL get_atomic_kind(atomic_kind, kind_number=akind)
3196 CALL get_qs_kind(qs_kind_set(akind), core_charge=charge)
3197 cdip(1:3) = cdip(1:3) - charge*ria(1:3)
3200 CALL para_env%sum(cdip)
3203 CALL ec_efield_integrals(qs_env, ec_env, rcc)
3206 DO ispin = 1, nspins
3208 CALL dbcsr_dot(ec_env%matrix_p(ispin, 1)%matrix, &
3209 ec_env%efield%dipmat(idir)%matrix, tmp)
3210 pdip(idir) = pdip(idir) + tmp
3215 CALL get_qs_env(qs_env=qs_env, matrix_s=matrix_s)
3217 CALL dbcsr_allocate_matrix_set(moments, 4)
3219 ALLOCATE (moments(i)%matrix)
3220 CALL dbcsr_copy(moments(i)%matrix, matrix_s(1)%matrix,
"Moments")
3221 CALL dbcsr_set(moments(i)%matrix, 0.0_dp)
3223 CALL build_local_moment_matrix(qs_env, moments, 1, ref_point=rcc)
3226 IF (nspins == 2) focc = 1.0_dp
3228 DO ispin = 1, nspins
3230 CALL dbcsr_dot(ec_env%matrix_z(ispin)%matrix, moments(idir)%matrix, tmp)
3231 rdip(idir) = rdip(idir) + tmp
3234 CALL dbcsr_deallocate_matrix_set(moments)
3236 tdip = -(rdip + pdip + cdip)
3237 IF (unit_nr > 0)
THEN
3238 WRITE (unit_nr,
"(T3,A)")
"Dipoles are based on the traditional operator."
3239 dd = sqrt(sum(tdip(1:3)**2))*debye
3240 WRITE (unit_nr,
"(T3,A)")
"Dipole moment [Debye]"
3241 WRITE (unit_nr,
"(T5,3(A,A,F14.8,1X),T60,A,T67,F14.8)") &
3242 (trim(rlab(i)),
"=", tdip(i)*debye, i=1, 3),
"Total=", dd
3247 CALL cp_print_key_finished_output(unit_nr=unit_nr, logger=logger, &
3248 basis_section=ec_section, print_key_path=
"PRINT%MOMENTS")
3249 CALL get_qs_env(qs_env=qs_env, results=results)
3250 description =
"[DIPOLE]"
3251 CALL cp_results_erase(results=results, description=description)
3252 CALL put_results(results=results, description=description, values=tdip(1:3))
3256 print_key_voro => section_vals_get_subs_vals(ec_section,
"PRINT%VORONOI")
3257 print_key_bqb => section_vals_get_subs_vals(ec_section,
"PRINT%E_DENSITY_BQB")
3258 IF (btest(cp_print_key_should_output(logger%iter_info, print_key_voro), cp_p_file))
THEN
3259 should_print_voro = 1
3261 should_print_voro = 0
3263 IF (btest(cp_print_key_should_output(logger%iter_info, print_key_bqb), cp_p_file))
THEN
3264 should_print_bqb = 1
3266 should_print_bqb = 0
3268 IF ((should_print_voro /= 0) .OR. (should_print_bqb /= 0))
THEN
3270 CALL get_qs_env(qs_env=qs_env, &
3272 CALL pw_env_get(pw_env=pw_env, &
3273 auxbas_pw_pool=auxbas_pw_pool, &
3275 CALL auxbas_pw_pool%create_pw(pw=rho_elec_rspace)
3277 IF (dft_control%nspins > 1)
THEN
3280 CALL pw_copy(ec_env%rhoout_r(1), rho_elec_rspace)
3281 CALL pw_axpy(ec_env%rhoout_r(2), rho_elec_rspace)
3283 CALL pw_axpy(ec_env%rhoz_r(1), rho_elec_rspace)
3284 CALL pw_axpy(ec_env%rhoz_r(2), rho_elec_rspace)
3288 CALL pw_copy(ec_env%rhoout_r(1), rho_elec_rspace)
3289 CALL pw_axpy(ec_env%rhoz_r(1), rho_elec_rspace)
3292 IF (should_print_voro /= 0)
THEN
3293 CALL section_vals_val_get(print_key_voro,
"OUTPUT_TEXT", l_val=voro_print_txt)
3294 IF (voro_print_txt)
THEN
3295 append_voro = section_get_lval(ec_section,
"PRINT%VORONOI%APPEND")
3296 my_pos_voro =
"REWIND"
3297 IF (append_voro)
THEN
3298 my_pos_voro =
"APPEND"
3300 unit_nr_voro = cp_print_key_unit_nr(logger, ec_section,
"PRINT%VORONOI", extension=
".voronoi", &
3301 file_position=my_pos_voro, log_filename=.false.)
3309 CALL entry_voronoi_or_bqb(should_print_voro, should_print_bqb, print_key_voro, print_key_bqb, &
3310 unit_nr_voro, qs_env, rho_elec_rspace)
3312 CALL auxbas_pw_pool%give_back_pw(rho_elec_rspace)
3314 IF (unit_nr_voro > 0)
THEN
3315 CALL cp_print_key_finished_output(unit_nr_voro, logger, ec_section,
"PRINT%VORONOI")
3320 CALL timestop(handle)
3322 END SUBROUTINE ec_properties
3335 SUBROUTINE ec_ls_init(qs_env, matrix_ks, matrix_s)
3336 TYPE(qs_environment_type),
POINTER :: qs_env
3337 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_ks, matrix_s
3339 CHARACTER(len=*),
PARAMETER :: routinen =
'ec_ls_init'
3341 INTEGER :: handle, ispin, nspins
3342 TYPE(dft_control_type),
POINTER :: dft_control
3343 TYPE(energy_correction_type),
POINTER :: ec_env
3344 TYPE(ls_scf_env_type),
POINTER :: ls_env
3346 CALL timeset(routinen, handle)
3348 CALL get_qs_env(qs_env=qs_env, &
3349 dft_control=dft_control, &
3351 nspins = dft_control%nspins
3352 ls_env => ec_env%ls_env
3355 CALL matrix_ls_create(matrix_ls=ls_env%matrix_s, matrix_qs=matrix_s(1, 1)%matrix, &
3356 ls_mstruct=ls_env%ls_mstruct)
3358 IF (
ALLOCATED(ls_env%matrix_p))
THEN
3359 DO ispin = 1,
SIZE(ls_env%matrix_p)
3360 CALL dbcsr_release(ls_env%matrix_p(ispin))
3363 ALLOCATE (ls_env%matrix_p(nspins))
3366 DO ispin = 1, nspins
3367 CALL dbcsr_create(ls_env%matrix_p(ispin), template=ls_env%matrix_s, &
3368 matrix_type=dbcsr_type_no_symmetry)
3371 ALLOCATE (ls_env%matrix_ks(nspins))
3372 DO ispin = 1, nspins
3373 CALL dbcsr_create(ls_env%matrix_ks(ispin), template=ls_env%matrix_s, &
3374 matrix_type=dbcsr_type_no_symmetry)
3378 CALL ls_scf_init_matrix_s(matrix_s(1, 1)%matrix, ls_env)
3382 DO ispin = 1, nspins
3383 CALL matrix_qs_to_ls(matrix_ls=ls_env%matrix_ks(ispin), &
3384 matrix_qs=matrix_ks(ispin, 1)%matrix, &
3385 ls_mstruct=ls_env%ls_mstruct, &
3389 CALL timestop(handle)
3391 END SUBROUTINE ec_ls_init
3407 SUBROUTINE ec_ls_solver(qs_env, matrix_p, matrix_w, ec_ls_method)
3408 TYPE(qs_environment_type),
POINTER :: qs_env
3409 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_p, matrix_w
3410 INTEGER,
INTENT(IN) :: ec_ls_method
3412 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ec_ls_solver'
3414 INTEGER :: handle, ispin, nelectron_spin_real, &
3416 INTEGER,
DIMENSION(2) :: nmo
3417 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: wmat
3418 TYPE(dbcsr_type),
ALLOCATABLE,
DIMENSION(:) :: matrix_ks_deviation
3419 TYPE(dft_control_type),
POINTER :: dft_control
3420 TYPE(energy_correction_type),
POINTER :: ec_env
3421 TYPE(ls_scf_env_type),
POINTER :: ls_env
3422 TYPE(mp_para_env_type),
POINTER :: para_env
3424 CALL timeset(routinen, handle)
3427 CALL get_qs_env(qs_env, &
3428 dft_control=dft_control, &
3430 nspins = dft_control%nspins
3431 ec_env => qs_env%ec_env
3432 ls_env => ec_env%ls_env
3435 CALL get_qs_env(qs_env=qs_env, nelectron_spin=nmo)
3436 IF (nspins == 1) nmo(1) = nmo(1)/2
3437 ls_env%homo_spin(:) = 0.0_dp
3438 ls_env%lumo_spin(:) = 0.0_dp
3440 ALLOCATE (matrix_ks_deviation(nspins))
3441 DO ispin = 1, nspins
3442 CALL dbcsr_create(matrix_ks_deviation(ispin), template=ls_env%matrix_ks(ispin))
3443 CALL dbcsr_set(matrix_ks_deviation(ispin), 0.0_dp)
3447 IF (ls_env%has_s_preconditioner)
THEN
3448 DO ispin = 1, nspins
3449 CALL apply_matrix_preconditioner(ls_env%matrix_ks(ispin),
"forward", &
3450 ls_env%matrix_bs_sqrt, ls_env%matrix_bs_sqrt_inv)
3452 CALL dbcsr_filter(ls_env%matrix_ks(ispin), ls_env%eps_filter)
3456 DO ispin = 1, nspins
3457 nelectron_spin_real = ls_env%nelectron_spin(ispin)
3458 IF (ls_env%nspins == 1) nelectron_spin_real = nelectron_spin_real/2
3460 SELECT CASE (ec_ls_method)
3461 CASE (ec_matrix_sign)
3462 CALL density_matrix_sign(ls_env%matrix_p(ispin), &
3463 ls_env%mu_spin(ispin), &
3465 ls_env%sign_method, &
3466 ls_env%sign_order, &
3467 ls_env%matrix_ks(ispin), &
3469 ls_env%matrix_s_inv, &
3470 nelectron_spin_real, &
3473 CASE (ec_matrix_trs4)
3474 CALL density_matrix_trs4( &
3475 ls_env%matrix_p(ispin), &
3476 ls_env%matrix_ks(ispin), &
3477 ls_env%matrix_s_sqrt_inv, &
3478 nelectron_spin_real, &
3479 ec_env%eps_default, &
3480 ls_env%homo_spin(ispin), &
3481 ls_env%lumo_spin(ispin), &
3482 ls_env%mu_spin(ispin), &
3483 matrix_ks_deviation=matrix_ks_deviation(ispin), &
3484 dynamic_threshold=ls_env%dynamic_threshold, &
3485 eps_lanczos=ls_env%eps_lanczos, &
3486 max_iter_lanczos=ls_env%max_iter_lanczos)
3488 CASE (ec_matrix_tc2)
3489 CALL density_matrix_tc2( &
3490 ls_env%matrix_p(ispin), &
3491 ls_env%matrix_ks(ispin), &
3492 ls_env%matrix_s_sqrt_inv, &
3493 nelectron_spin_real, &
3494 ec_env%eps_default, &
3495 ls_env%homo_spin(ispin), &
3496 ls_env%lumo_spin(ispin), &
3497 non_monotonic=ls_env%non_monotonic, &
3498 eps_lanczos=ls_env%eps_lanczos, &
3499 max_iter_lanczos=ls_env%max_iter_lanczos)
3506 IF (ls_env%has_s_preconditioner)
THEN
3507 DO ispin = 1, nspins
3509 CALL apply_matrix_preconditioner(ls_env%matrix_p(ispin),
"forward", &
3510 ls_env%matrix_bs_sqrt, ls_env%matrix_bs_sqrt_inv)
3512 CALL dbcsr_filter(ls_env%matrix_p(ispin), ls_env%eps_filter)
3517 IF (nspins == 1)
CALL dbcsr_scale(ls_env%matrix_p(1), 2.0_dp)
3519 IF (ls_env%report_all_sparsities)
CALL post_scf_sparsities(ls_env)
3523 DO ispin = 1, nspins
3524 CALL matrix_ls_to_qs(matrix_qs=matrix_p(ispin, 1)%matrix, &
3525 matrix_ls=ls_env%matrix_p(ispin), &
3526 ls_mstruct=ls_env%ls_mstruct, &
3530 wmat => matrix_w(:, 1)
3531 CALL calculate_w_matrix_ls(wmat, ec_env%ls_env)
3534 CALL dbcsr_release(ls_env%matrix_s)
3535 IF (ls_env%has_s_preconditioner)
THEN
3536 CALL dbcsr_release(ls_env%matrix_bs_sqrt)
3537 CALL dbcsr_release(ls_env%matrix_bs_sqrt_inv)
3539 IF (ls_env%needs_s_inv)
THEN
3540 CALL dbcsr_release(ls_env%matrix_s_inv)
3542 IF (ls_env%use_s_sqrt)
THEN
3543 CALL dbcsr_release(ls_env%matrix_s_sqrt)
3544 CALL dbcsr_release(ls_env%matrix_s_sqrt_inv)
3547 DO ispin = 1,
SIZE(ls_env%matrix_ks)
3548 CALL dbcsr_release(ls_env%matrix_ks(ispin))
3550 DEALLOCATE (ls_env%matrix_ks)
3552 DO ispin = 1, nspins
3553 CALL dbcsr_release(matrix_ks_deviation(ispin))
3555 DEALLOCATE (matrix_ks_deviation)
3557 CALL timestop(handle)
3559 END SUBROUTINE ec_ls_solver
3577 SUBROUTINE ec_ot_diag_solver(qs_env, ec_env, matrix_ks, matrix_s, matrix_p, matrix_w)
3578 TYPE(qs_environment_type),
POINTER :: qs_env
3579 TYPE(energy_correction_type),
POINTER :: ec_env
3580 TYPE(dbcsr_p_type),
DIMENSION(:, :),
INTENT(IN), &
3581 POINTER :: matrix_ks, matrix_s
3582 TYPE(dbcsr_p_type),
DIMENSION(:, :), &
3583 INTENT(INOUT),
POINTER :: matrix_p, matrix_w
3585 CHARACTER(len=*),
PARAMETER :: routinen =
'ec_ot_diag_solver'
3587 INTEGER :: handle, homo, ikind, iounit, ispin, &
3588 max_iter, nao, nkind, nmo, nspins
3589 INTEGER,
DIMENSION(2) :: nelectron_spin
3590 REAL(kind=dp),
DIMENSION(:),
POINTER :: eigenvalues
3591 TYPE(atomic_kind_type),
DIMENSION(:),
POINTER :: atomic_kind_set
3592 TYPE(cp_blacs_env_type),
POINTER :: blacs_env
3593 TYPE(cp_fm_type) :: sv
3594 TYPE(cp_fm_type),
POINTER :: mo_coeff
3595 TYPE(cp_logger_type),
POINTER :: logger
3596 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: p_rmpv
3597 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: rho_ao
3598 TYPE(dft_control_type),
POINTER :: dft_control
3599 TYPE(gto_basis_set_type),
POINTER :: basis_set, harris_basis
3600 TYPE(mo_set_type),
DIMENSION(:),
POINTER :: mos
3601 TYPE(mp_para_env_type),
POINTER :: para_env
3602 TYPE(particle_type),
DIMENSION(:),
POINTER :: particle_set
3603 TYPE(preconditioner_type),
POINTER :: local_preconditioner
3604 TYPE(qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
3605 TYPE(qs_kind_type),
POINTER :: qs_kind
3606 TYPE(qs_rho_type),
POINTER :: rho
3608 CALL timeset(routinen, handle)
3610 logger => cp_get_default_logger()
3611 iounit = cp_logger_get_default_unit_nr(logger)
3613 cpassert(
ASSOCIATED(qs_env))
3614 cpassert(
ASSOCIATED(ec_env))
3615 cpassert(
ASSOCIATED(matrix_ks))
3616 cpassert(
ASSOCIATED(matrix_s))
3617 cpassert(
ASSOCIATED(matrix_p))
3618 cpassert(
ASSOCIATED(matrix_w))
3620 CALL get_qs_env(qs_env=qs_env, &
3621 atomic_kind_set=atomic_kind_set, &
3622 blacs_env=blacs_env, &
3623 dft_control=dft_control, &
3624 nelectron_spin=nelectron_spin, &
3625 para_env=para_env, &
3626 particle_set=particle_set, &
3627 qs_kind_set=qs_kind_set)
3628 nspins = dft_control%nspins
3635 IF (dft_control%qs_control%do_ls_scf)
THEN
3636 CALL ec_mos_init(qs_env, matrix_s(1, 1)%matrix)
3639 CALL get_qs_env(qs_env, mos=mos)
3646 CALL get_qs_env(qs_env, qs_kind_set=qs_kind_set, nkind=nkind)
3647 CALL uppercase(ec_env%basis)
3651 IF (ec_env%basis ==
"HARRIS")
THEN
3653 qs_kind => qs_kind_set(ikind)
3655 CALL get_qs_kind(qs_kind=qs_kind, basis_set=basis_set, basis_type=
"ORB")
3657 CALL get_qs_kind(qs_kind=qs_kind, basis_set=harris_basis, basis_type=
"HARRIS")
3659 IF (basis_set%name .NE. harris_basis%name)
THEN
3660 cpabort(
"OT-Diag initial guess: Harris and ground state need to use the same basis")
3665 IF (ec_env%mao)
THEN
3666 cpabort(
"OT-Diag initial guess: not implemented for MAOs")
3670 SELECT CASE (ec_env%ec_initial_guess)
3673 p_rmpv => matrix_p(:, 1)
3675 CALL calculate_atomic_block_dm(p_rmpv, matrix_s(1, 1)%matrix, atomic_kind_set, qs_kind_set, &
3676 nspins, nelectron_spin, iounit, para_env)
3680 CALL get_qs_env(qs_env, rho=rho)
3681 CALL qs_rho_get(rho, rho_ao_kp=rho_ao)
3682 p_rmpv => rho_ao(:, 1)
3685 cpabort(
"Unknown inital guess for OT-Diagonalization (Harris functional)")
3688 DO ispin = 1, nspins
3689 CALL get_mo_set(mo_set=mos(ispin), &
3690 mo_coeff=mo_coeff, &
3696 CALL cp_fm_set_all(mo_coeff, 0.0_dp)
3697 CALL cp_fm_init_random(mo_coeff, nmo)
3699 CALL cp_fm_create(sv, mo_coeff%matrix_struct,
"SV")
3702 CALL cp_dbcsr_sm_fm_multiply(matrix_s(1, 1)%matrix, mo_coeff, sv, nmo)
3703 CALL cp_dbcsr_sm_fm_multiply(p_rmpv(ispin)%matrix, sv, mo_coeff, homo)
3704 CALL cp_fm_release(sv)
3707 CALL make_basis_sm(mo_coeff, nmo, matrix_s(1, 1)%matrix)
3711 NULLIFY (local_preconditioner)
3712 ALLOCATE (local_preconditioner)
3713 CALL init_preconditioner(local_preconditioner, para_env=para_env, &
3714 blacs_env=blacs_env)
3715 DO ispin = 1, nspins
3716 CALL make_preconditioner(local_preconditioner, &
3717 precon_type=ot_precond_full_single_inverse, &
3718 solver_type=ot_precond_solver_default, &
3719 matrix_h=matrix_ks(ispin, 1)%matrix, &
3720 matrix_s=matrix_s(ispin, 1)%matrix, &
3721 convert_precond_to_dbcsr=.true., &
3722 mo_set=mos(ispin), energy_gap=0.2_dp)
3724 CALL get_mo_set(mos(ispin), &
3725 mo_coeff=mo_coeff, &
3726 eigenvalues=eigenvalues, &
3729 CALL ot_eigensolver(matrix_h=matrix_ks(ispin, 1)%matrix, &
3730 matrix_s=matrix_s(1, 1)%matrix, &
3731 matrix_c_fm=mo_coeff, &
3733 eps_gradient=ec_env%eps_default, &
3734 iter_max=max_iter, &
3736 CALL calculate_subspace_eigenvalues(mo_coeff, matrix_ks(ispin, 1)%matrix, &
3737 evals_arg=eigenvalues, do_rotation=.true.)
3740 CALL destroy_preconditioner(local_preconditioner)
3741 DEALLOCATE (local_preconditioner)
3744 CALL copy_fm_to_dbcsr(mos(ispin)%mo_coeff, &
3745 mos(ispin)%mo_coeff_b)
3749 DO ispin = 1, nspins
3750 CALL calculate_density_matrix(mos(ispin), matrix_p(ispin, 1)%matrix)
3752 CALL calculate_w_matrix(mos(ispin), matrix_w(ispin, 1)%matrix)
3756 IF (dft_control%qs_control%do_ls_scf)
THEN
3757 DO ispin = 1, nspins
3758 CALL deallocate_mo_set(mos(ispin))
3760 IF (
ASSOCIATED(qs_env%mos))
THEN
3761 DO ispin = 1,
SIZE(qs_env%mos)
3762 CALL deallocate_mo_set(qs_env%mos(ispin))
3764 DEALLOCATE (qs_env%mos)
3768 CALL timestop(handle)
3770 END SUBROUTINE ec_ot_diag_solver
Contains ADMM methods which only require the density matrix.
subroutine, public admm_dm_calc_rho_aux(qs_env)
Entry methods: Calculates auxiliary density matrix from primary one.
Contains ADMM methods which require molecular orbitals.
subroutine, public admm_mo_calc_rho_aux(qs_env)
...
Define the atomic kind types and their sub types.
subroutine, public get_atomic_kind(atomic_kind, fist_potential, element_symbol, name, mass, kind_number, natom, atom_list, rcov, rvdw, z, qeff, apol, cpol, mm_radius, shell, shell_active, damping)
Get attributes of an atomic kind.
subroutine, public get_gto_basis_set(gto_basis_set, name, aliases, norm_type, kind_radius, ncgf, nset, nsgf, cgf_symbol, sgf_symbol, norm_cgf, set_radius, lmax, lmin, lx, ly, lz, m, ncgf_set, npgf, nsgf_set, nshell, cphi, pgf_radius, sphi, scon, zet, first_cgf, first_sgf, l, last_cgf, last_sgf, n, gcc, maxco, maxl, maxpgf, maxsgf_set, maxshell, maxso, nco_sum, npgf_sum, nshell_sum, maxder, short_kind_radius, npgf_seg_sum)
...
collects all references to literature in CP2K as new algorithms / method are included from literature...
integer, save, public belleflamme2023
Handles all functions related to the CELL.
Calculation of the nuclear attraction contribution to the core Hamiltonian <a|erfc|b> :we only calcul...
subroutine, public build_core_ae(matrix_h, matrix_p, force, virial, calculate_forces, use_virial, nder, qs_kind_set, atomic_kind_set, particle_set, sab_orb, sac_ae, nimages, cell_to_index, atcore)
...
Calculation of the local pseudopotential contribution to the core Hamiltonian <a|V(local)|b> = <a|Sum...
subroutine, public build_core_ppl(matrix_h, matrix_p, force, virial, calculate_forces, use_virial, nder, qs_kind_set, atomic_kind_set, particle_set, sab_orb, sac_ppl, nimages, cell_to_index, basis_type, deltar, atcore)
...
Calculation of the non-local pseudopotential contribution to the core Hamiltonian <a|V(non-local)|b> ...
subroutine, public build_core_ppnl(matrix_h, matrix_p, force, virial, calculate_forces, use_virial, nder, qs_kind_set, atomic_kind_set, particle_set, sab_orb, sap_ppnl, eps_ppnl, nimages, cell_to_index, basis_type, deltar, matrix_l, atcore)
...
methods related to the blacs parallel environment
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
subroutine, public dbcsr_scale(matrix, alpha_scalar)
...
subroutine, public dbcsr_desymmetrize(matrix_a, matrix_b)
...
subroutine, public dbcsr_copy(matrix_b, matrix_a, name, keep_sparsity, keep_imaginary)
...
subroutine, public dbcsr_multiply(transa, transb, alpha, matrix_a, matrix_b, beta, matrix_c, first_row, last_row, first_column, last_column, first_k, last_k, retain_sparsity, filter_eps, flop)
...
subroutine, public dbcsr_get_info(matrix, nblkrows_total, nblkcols_total, nfullrows_total, nfullcols_total, nblkrows_local, nblkcols_local, nfullrows_local, nfullcols_local, my_prow, my_pcol, local_rows, local_cols, proc_row_dist, proc_col_dist, row_blk_size, col_blk_size, row_blk_offset, col_blk_offset, distribution, name, matrix_type, group)
...
subroutine, public dbcsr_init_p(matrix)
...
subroutine, public dbcsr_filter(matrix, eps)
...
subroutine, public dbcsr_set(matrix, alpha)
...
subroutine, public dbcsr_release(matrix)
...
subroutine, public dbcsr_add(matrix_a, matrix_b, alpha_scalar, beta_scalar)
...
subroutine, public dbcsr_dot(matrix_a, matrix_b, trace)
Computes the dot product of two matrices, also known as the trace of their matrix product.
Routines that link DBCSR and CP2K concepts together.
subroutine, public cp_dbcsr_alloc_block_from_nbl(matrix, sab_orb, desymmetrize)
allocate the blocks of a dbcsr based on the neighbor list
DBCSR operations in CP2K.
subroutine, public cp_dbcsr_sm_fm_multiply(matrix, fm_in, fm_out, ncol, alpha, beta)
multiply a dbcsr with a fm matrix
subroutine, public copy_dbcsr_to_fm(matrix, fm)
Copy a DBCSR matrix to a BLACS matrix.
subroutine, public copy_fm_to_dbcsr(fm, matrix, keep_sparsity)
Copy a BLACS matrix to a dbcsr matrix.
Utility routines to open and close files. Tracking of preconnections.
subroutine, public open_file(file_name, file_status, file_form, file_action, file_position, file_pad, unit_number, debug, skip_get_unit_number, file_access)
Opens the requested file using a free unit number.
subroutine, public close_file(unit_number, file_status, keep_preconnection)
Close an open file given by its logical unit number. Optionally, keep the file and unit preconnected.
Basic linear algebra operations for full matrices.
subroutine, public cp_fm_column_scale(matrixa, scaling)
scales column i of matrix a with scaling(i)
subroutine, public cp_fm_triangular_invert(matrix_a, uplo_tr)
inverts a triangular matrix
various cholesky decomposition related routines
subroutine, public cp_fm_cholesky_decompose(matrix, n, info_out)
used to replace a symmetric positive def. matrix M with its cholesky decomposition U: M = U^T * U,...
used for collecting some of the diagonalization schemes available for cp_fm_type. cp_fm_power also mo...
subroutine, public choose_eigv_solver(matrix, eigenvectors, eigenvalues, info)
Choose the Eigensolver depending on which library is available ELPA seems to be unstable for small sy...
represent the structure of a full matrix
subroutine, public cp_fm_struct_create(fmstruct, para_env, context, nrow_global, ncol_global, nrow_block, ncol_block, descriptor, first_p_pos, local_leading_dimension, template_fmstruct, square_blocks, force_block)
allocates and initializes a full matrix structure
subroutine, public cp_fm_struct_release(fmstruct)
releases a full matrix structure
represent a full matrix distributed on many processors
subroutine, public cp_fm_set_all(matrix, alpha, beta)
set all elements of a matrix to the same value, and optionally the diagonal to a different one
subroutine, public cp_fm_init_random(matrix, ncol, start_col)
fills a matrix with random numbers
subroutine, public cp_fm_to_fm_triangular(msource, mtarget, uplo)
copy just a triangular matrix
subroutine, public cp_fm_create(matrix, matrix_struct, name, use_sp)
creates a new full matrix with the given structure
various routines to log and control the output. The idea is that decisions about where to log should ...
recursive integer function, public cp_logger_get_default_unit_nr(logger, local, skip_not_ionode)
asks the default unit number of the given logger. try to use cp_logger_get_unit_nr
type(cp_logger_type) function, pointer, public cp_get_default_logger()
returns the default logger
routines to handle the output, The idea is to remove the decision of wheter to output and what to out...
integer function, public cp_print_key_unit_nr(logger, basis_section, print_key_path, extension, middle_name, local, log_filename, ignore_should_output, file_form, file_position, file_action, file_status, do_backup, on_file, is_new_file, mpi_io, fout)
...
subroutine, public cp_print_key_finished_output(unit_nr, logger, basis_section, print_key_path, local, ignore_should_output, on_file, mpi_io)
should be called after you finish working with a unit obtained with cp_print_key_unit_nr,...
integer, parameter, public cp_p_file
integer function, public cp_print_key_should_output(iteration_info, basis_section, print_key_path, used_print_key, first_time)
returns what should be done with the given property if btest(res,cp_p_store) then the property should...
set of type/routines to handle the storage of results in force_envs
subroutine, public cp_results_erase(results, description, nval)
erase a part of result_list
set of type/routines to handle the storage of results in force_envs
real(kind=dp) function, public cp_unit_from_cp2k(value, unit_str, defaults, power)
converts from the internal cp2k units to the given unit
stores a lists of integer that are local to a processor. The idea is that these integers represent ob...
stores a mapping of 2D info (e.g. matrix) on a 2D processor distribution (i.e. blacs grid) where cpus...
lower level routines for linear scaling SCF
subroutine, public density_matrix_trs4(matrix_p, matrix_ks, matrix_s_sqrt_inv, nelectron, threshold, e_homo, e_lumo, e_mu, dynamic_threshold, matrix_ks_deviation, max_iter_lanczos, eps_lanczos, converged, iounit)
compute the density matrix using a trace-resetting algorithm
subroutine, public ls_scf_init_matrix_s(matrix_s, ls_scf_env)
initialize S matrix related properties (sqrt, inverse...) Might be factored-out since this seems comm...
subroutine, public apply_matrix_preconditioner(matrix, direction, matrix_bs_sqrt, matrix_bs_sqrt_inv)
apply a preconditioner either forward (precondition) inv(sqrt(bs)) * A * inv(sqrt(bs)) backward (rest...
subroutine, public density_matrix_sign(matrix_p, mu, fixed_mu, sign_method, sign_order, matrix_ks, matrix_s, matrix_s_inv, nelectron, threshold, sign_symmetric, submatrix_sign_method, matrix_s_sqrt_inv)
compute the density matrix with a trace that is close to nelectron. take a mu as input,...
subroutine, public density_matrix_tc2(matrix_p, matrix_ks, matrix_s_sqrt_inv, nelectron, threshold, e_homo, e_lumo, non_monotonic, eps_lanczos, max_iter_lanczos, iounit)
compute the density matrix using a non monotonic trace conserving algorithm based on SIAM DOI....
Routines for a linear scaling quickstep SCF run based on the density matrix, with a focus on the inte...
subroutine, public matrix_ls_to_qs(matrix_qs, matrix_ls, ls_mstruct, covariant, keep_sparsity)
second link to QS, copy a LS matrix to QS matrix used to isolate QS style matrices from LS style will...
subroutine, public matrix_ls_create(matrix_ls, matrix_qs, ls_mstruct)
create a matrix for use (and as a template) in ls based on a qs template
subroutine, public matrix_qs_to_ls(matrix_ls, matrix_qs, ls_mstruct, covariant)
first link to QS, copy a QS matrix to LS matrix used to isolate QS style matrices from LS style will ...
Types needed for a linear scaling quickstep SCF run based on the density matrix.
Routines for a linear scaling quickstep SCF run based on the density matrix.
subroutine, public post_scf_sparsities(ls_scf_env)
Report on the sparsities of various interesting matrices.
subroutine, public calculate_w_matrix_ls(matrix_w, ls_scf_env)
Compute matrix_w as needed for the forces.
Calculates the energy contribution and the mo_derivative of a static electric field (nonperiodic)
subroutine, public ec_efield_local_operator(qs_env, ec_env, calculate_forces)
...
subroutine, public ec_efield_integrals(qs_env, ec_env, rpoint)
...
Types needed for a for a Energy Correction.
Routines for an external energy correction on top of a Kohn-Sham calculation.
subroutine, public ec_ext_energy(qs_env, ec_env, calculate_forces)
External energy method.
Routines used for Harris functional Kohn-Sham calculation.
subroutine, public ec_mos_init(qs_env, matrix_s)
Allocate and initiate molecular orbitals environment.
subroutine, public create_kernel(qs_env, vxc, vxc_tau, rho, rho1_r, rho1_g, tau1_r, xc_section, compute_virial, virial_xc)
Creation of second derivative xc-potential.
Routines for an energy correction on top of a Kohn-Sham calculation.
subroutine, public energy_correction(qs_env, ec_init, calculate_forces)
Energy Correction to a Kohn-Sham simulation Available energy corrections: (1) Harris energy functiona...
Definition of the atomic potential types.
Routines to calculate EXX in RPA and energy correction methods.
subroutine, public calculate_exx(qs_env, unit_nr, hfx_sections, x_data, do_gw, do_admm, calc_forces, reuse_hfx, do_im_time, e_ex_from_gw, e_admm_from_gw, t3)
...
subroutine, public add_exx_to_rhs(rhs, qs_env, ext_hfx_section, x_data, recalc_integrals, do_admm, do_ec, do_exx, reuse_hfx)
Add the EXX contribution to the RHS of the Z-vector equation, namely the HF Hamiltonian.
Defines the basic variable types.
integer, parameter, public dp
integer, parameter, public default_string_length
integer, parameter, public default_path_length
Calculate MAO's and analyze wavefunctions.
subroutine, public mao_generate_basis(qs_env, mao_coef, ref_basis_set, pmat_external, smat_external, molecular, max_iter, eps_grad, nmao_external, eps1_mao, iolevel, unit_nr)
...
Collection of simple mathematical functions and subroutines.
Interface to the message passing library MPI.
Define the data structure for the molecule information.
Calculates the moment integrals <a|r^m|b>
subroutine, public get_reference_point(rpoint, drpoint, qs_env, fist_env, reference, ref_point, ifirst, ilast)
...
Define the data structure for the particle information.
Periodic Table related data definitions.
type(atom), dimension(0:nelem), public ptable
Definition of physical constants:
real(kind=dp), parameter, public pascal
real(kind=dp), parameter, public bohr
real(kind=dp), parameter, public debye
subroutine, public init_preconditioner(preconditioner_env, para_env, blacs_env)
...
subroutine, public destroy_preconditioner(preconditioner_env)
...
computes preconditioners, and implements methods to apply them currently used in qs_ot
subroutine, public make_preconditioner(preconditioner_env, precon_type, solver_type, matrix_h, matrix_s, matrix_t, mo_set, energy_gap, convert_precond_to_dbcsr, chol_type)
...
container for various plainwaves related things
subroutine, public pw_env_get(pw_env, pw_pools, cube_info, gridlevel_info, auxbas_pw_pool, auxbas_grid, auxbas_rs_desc, auxbas_rs_grid, rs_descs, rs_grids, xc_pw_pool, vdw_pw_pool, poisson_env, interp_section)
returns the various attributes of the pw env
functions related to the poisson solver on regular grids
Manages a pool of grids (to be used for example as tmp objects), but can also be used to instantiate ...
Routine to return block diagonal density matrix. Blocks correspond to the atomic densities.
subroutine, public calculate_atomic_block_dm(pmatrix, matrix_s, atomic_kind_set, qs_kind_set, nspin, nelectron_spin, ounit, para_env)
returns a block diagonal density matrix. Blocks correspond to the atomic densities.
Calculate the plane wave density by collocating the primitive Gaussian functions (pgf).
subroutine, public calculate_rho_elec(matrix_p, matrix_p_kp, rho, rho_gspace, total_rho, ks_env, soft_valid, compute_tau, compute_grad, basis_type, der_type, idir, task_list_external, pw_env_external)
computes the density corresponding to a given density matrix on the grid
Calculation of the energies concerning the core charge distribution.
subroutine, public calculate_ecore_overlap(qs_env, para_env, calculate_forces, molecular, e_overlap_core, atecc)
Calculate the overlap energy of the core charge distribution.
collects routines that calculate density matrices
Calculation of dispersion using pair potentials.
subroutine, public calculate_dispersion_pairpot(qs_env, dispersion_env, energy, calculate_forces, atevdw)
...
Definition of disperson types for DFT calculations.
subroutine, public get_qs_env(qs_env, atomic_kind_set, qs_kind_set, cell, super_cell, cell_ref, use_ref_cell, kpoints, dft_control, mos, sab_orb, sab_all, qmmm, qmmm_periodic, sac_ae, sac_ppl, sac_lri, sap_ppnl, sab_vdw, sab_scp, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, sab_xb, sab_xtb_pp, sab_xtb_nonbond, sab_almo, sab_kp, sab_kp_nosym, particle_set, energy, force, matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, run_rtp, rtp, matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_ks_im_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, matrix_s_ri_aux_kp, matrix_s, matrix_s_ri_aux, matrix_w, matrix_p_mp2, matrix_p_mp2_admm, rho, rho_xc, pw_env, ewald_env, ewald_pw, active_space, mpools, input, para_env, blacs_env, scf_control, rel_control, kinetic, qs_charges, vppl, rho_core, rho_nlcc, rho_nlcc_g, ks_env, ks_qmmm_env, wf_history, scf_env, local_particles, local_molecules, distribution_2d, dbcsr_dist, molecule_kind_set, molecule_set, subsys, cp_subsys, oce, local_rho_set, rho_atom_set, task_list, task_list_soft, rho0_atom_set, rho0_mpole, rhoz_set, ecoul_1c, rho0_s_rs, rho0_s_gs, do_kpoints, has_unit_metric, requires_mo_derivs, mo_derivs, mo_loc_history, nkind, natom, nelectron_total, nelectron_spin, efield, neighbor_list_id, linres_control, xas_env, virial, cp_ddapc_env, cp_ddapc_ewald, outer_scf_history, outer_scf_ihistory, x_data, et_coupling, dftb_potential, results, se_taper, se_store_int_env, se_nddo_mpole, se_nonbond_env, admm_env, lri_env, lri_density, exstate_env, ec_env, harris_env, dispersion_env, gcp_env, vee, rho_external, external_vxc, mask, mp2_env, bs_env, kg_env, wanniercentres, atprop, ls_scf_env, do_transport, transport_env, v_hartree_rspace, s_mstruct_changed, rho_changed, potential_changed, forces_up_to_date, mscfg_env, almo_scf_env, gradient_history, variable_history, embed_pot, spin_embed_pot, polar_env, mos_last_converged, eeq, rhs, tb_tblite)
Get the QUICKSTEP environment.
subroutine, public zero_qs_force(qs_force)
Initialize a Quickstep force data structure.
subroutine, public total_qs_force(force, qs_force, atomic_kind_set)
Get current total force.
Integrate single or product functions over a potential on a RS grid.
Define the quickstep kind type and their sub types.
subroutine, public get_qs_kind(qs_kind, basis_set, basis_type, ncgf, nsgf, all_potential, tnadd_potential, gth_potential, sgp_potential, upf_potential, se_parameter, dftb_parameter, xtb_parameter, dftb3_param, zatom, zeff, elec_conf, mao, lmax_dftb, alpha_core_charge, ccore_charge, core_charge, core_charge_radius, paw_proj_set, paw_atom, hard_radius, hard0_radius, max_rad_local, covalent_radius, vdw_radius, gpw_type_forced, harmonics, max_iso_not0, max_s_harm, grid_atom, ngrid_ang, ngrid_rad, lmax_rho0, dft_plus_u_atom, l_of_dft_plus_u, n_of_dft_plus_u, u_minus_j, u_of_dft_plus_u, j_of_dft_plus_u, alpha_of_dft_plus_u, beta_of_dft_plus_u, j0_of_dft_plus_u, occupation_of_dft_plus_u, dispersion, bs_occupation, magnetization, no_optimize, addel, laddel, naddel, orbitals, max_scf, eps_scf, smear, u_ramping, u_minus_j_target, eps_u_ramping, init_u_ramping_each_scf, reltmat, ghost, floating, name, element_symbol, pao_basis_size, pao_model_file, pao_potentials, pao_descriptors, nelec)
Get attributes of an atomic kind.
subroutine, public get_qs_kind_set(qs_kind_set, all_potential_present, tnadd_potential_present, gth_potential_present, sgp_potential_present, paw_atom_present, dft_plus_u_atom_present, maxcgf, maxsgf, maxco, maxco_proj, maxgtops, maxlgto, maxlprj, maxnset, maxsgf_set, ncgf, npgf, nset, nsgf, nshell, maxpol, maxlppl, maxlppnl, maxppnl, nelectron, maxder, max_ngrid_rad, max_sph_harm, maxg_iso_not0, lmax_rho0, basis_rcut, basis_type, total_zeff_corr, npgf_seg)
Get attributes of an atomic kind set.
Calculation of kinetic energy matrix and forces.
subroutine, public build_kinetic_matrix(ks_env, matrix_t, matrixkp_t, matrix_name, basis_type, sab_nl, calculate_forces, matrix_p, matrixkp_p, eps_filter, nderivative)
Calculation of the kinetic energy matrix over Cartesian Gaussian functions.
routines that build the Kohn-Sham matrix (i.e calculate the coulomb and xc parts
subroutine, public calc_rho_tot_gspace(rho_tot_gspace, qs_env, rho, skip_nuclear_density)
...
Calculate the KS reference potentials.
subroutine, public ks_ref_potential(qs_env, vh_rspace, vxc_rspace, vtau_rspace, vadmm_rspace, ehartree, exc, h_stress)
calculate the Kohn-Sham reference potential
collects routines that perform operations directly related to MOs
subroutine, public make_basis_sm(vmatrix, ncol, matrix_s)
returns an S-orthonormal basis v (v^T S v ==1)
Definition and initialisation of the mo data type.
subroutine, public deallocate_mo_set(mo_set)
Deallocate a wavefunction data structure.
subroutine, public get_mo_set(mo_set, maxocc, homo, lfomo, nao, nelectron, n_el_f, nmo, eigenvalues, occupation_numbers, mo_coeff, mo_coeff_b, uniform_occupation, kts, mu, flexible_electron_count)
Get the components of a MO set data structure.
Calculates the moment integrals <a|r^m|b> and <a|r x d/dr|b>
subroutine, public build_local_moment_matrix(qs_env, moments, nmoments, ref_point, ref_points, basis_type)
...
Define the neighbor list data types and the corresponding functionality.
Generate the atomic neighbor lists.
subroutine, public atom2d_cleanup(atom2d)
free the internals of atom2d
subroutine, public pair_radius_setup(present_a, present_b, radius_a, radius_b, pair_radius, prmin)
...
subroutine, public build_neighbor_lists(ab_list, particle_set, atom, cell, pair_radius, subcells, mic, symmetric, molecular, subset_of_mol, current_subset, operator_type, nlname, atomb_to_keep)
Build simple pair neighbor lists.
subroutine, public atom2d_build(atom2d, distribution_1d, distribution_2d, atomic_kind_set, molecule_set, molecule_only, particle_set)
Build some distribution structure of atoms, refactored from build_qs_neighbor_lists.
an eigen-space solver for the generalised symmetric eigenvalue problem for sparse matrices,...
subroutine, public ot_eigensolver(matrix_h, matrix_s, matrix_orthogonal_space_fm, matrix_c_fm, preconditioner, eps_gradient, iter_max, size_ortho_space, silent, ot_settings)
...
Calculation of overlap matrix, its derivatives and forces.
subroutine, public build_overlap_matrix(ks_env, matrix_s, matrixkp_s, matrix_name, nderivative, basis_type_a, basis_type_b, sab_nl, calculate_forces, matrix_p, matrixkp_p)
Calculation of the overlap matrix over Cartesian Gaussian functions.
superstucture that hold various representations of the density and keeps track of which ones are vali...
subroutine, public qs_rho_get(rho_struct, rho_ao, rho_ao_im, rho_ao_kp, rho_ao_im_kp, rho_r, drho_r, rho_g, drho_g, tau_r, tau_g, rho_r_valid, drho_r_valid, rho_g_valid, drho_g_valid, tau_r_valid, tau_g_valid, tot_rho_r, tot_rho_g, rho_r_sccs, soft_valid, complex_rho_ao)
returns info about the density described by this object. If some representation is not available an e...
subroutine, public qs_vxc_create(ks_env, rho_struct, xc_section, vxc_rho, vxc_tau, exc, just_energy, edisp, dispersion_env, adiabatic_rescale_factor, pw_env_external)
calculates and allocates the xc potential, already reducing it to the dependence on rho and the one o...
Calculate the CPKS equation and the resulting forces.
subroutine, public response_force(qs_env, vh_rspace, vxc_rspace, vtau_rspace, vadmm_rspace, matrix_hz, matrix_pz, matrix_pz_admm, matrix_wz, zehartree, zexc, zexc_aux_fit, rhopz_r, p_env, ex_env, debug)
...
subroutine, public response_calculation(qs_env, ec_env)
Initializes solver of linear response equation for energy correction.
Utilities for rtp in combination with admm methods adapted routines from admm_method (author Manuel G...
subroutine, public rtp_admm_calc_rho_aux(qs_env)
Compute the ADMM density matrix in case of rtp (complex MO's)
Utilities for string manipulations.
elemental subroutine, public uppercase(string)
Convert all lower case characters in a string to upper case.
generate the tasks lists used by collocate and integrate routines
subroutine, public generate_qs_task_list(ks_env, task_list, reorder_rs_grid_ranks, skip_load_balance_distributed, soft_valid, basis_type, pw_env_external, sab_orb_external)
...
subroutine, public deallocate_task_list(task_list)
deallocates the components and the object itself
subroutine, public allocate_task_list(task_list)
allocates and initialised the components of the task_list_type
The module to read/write TREX IO files for interfacing CP2K with other programs.
subroutine, public write_trexio(qs_env, trexio_section, energy_derivative)
Write a trexio file.
subroutine, public write_stress_tensor(pv_virial, iw, cell, unit_string, numerical)
Print stress tensor to output file.
subroutine, public write_stress_tensor_components(virial, iw, cell, unit_string)
...
pure real(kind=dp) function, public one_third_sum_diag(a)
...
subroutine, public zero_virial(virial, reset)
...
subroutine, public symmetrize_virial(virial)
Symmetrize the virial components.
Interface for Voronoi Integration and output of BQB files.
subroutine, public entry_voronoi_or_bqb(do_voro, do_bqb, input_voro, input_bqb, unit_voro, qs_env, rspace_pw)
Does a Voronoi integration of density or stores the density to compressed BQB format.
Provides all information about an atomic kind.
Type defining parameters related to the simulation cell.
represent a blacs multidimensional parallel environment (for the mpi corrispective see cp_paratypes/m...
keeps the information about the structure of a full matrix
type of a logger, at the moment it contains just a print level starting at which level it should be l...
contains arbitrary information which need to be stored
structure to store local (to a processor) ordered lists of integers.
distributes pairs on a 2d grid of processors
Contains information on the energy correction functional for KG.
stores all the informations relevant to an mpi environment
contained for different pw related things
environment for the poisson solver
to create arrays of pools
Manages a pool of grids (to be used for example as tmp objects), but can also be used to instantiate ...
Provides all information about a quickstep kind.
calculation environment to calculate the ks matrix, holds all the needed vars. assumes that the core ...
keeps the density in various representations, keeping track of which ones are valid.