201#include "./base/base_uses.f90"
209 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'energy_corrections'
230 LOGICAL,
INTENT(IN),
OPTIONAL :: ec_init, calculate_forces
232 CHARACTER(len=*),
PARAMETER :: routinen =
'energy_correction'
234 INTEGER :: handle, unit_nr
235 LOGICAL :: my_calc_forces
242 CALL timeset(routinen, handle)
245 IF (logger%para_env%is_source())
THEN
257 IF (.NOT. ec_env%do_skip)
THEN
259 ec_env%should_update = .true.
260 IF (
PRESENT(ec_init)) ec_env%should_update = ec_init
262 my_calc_forces = .false.
263 IF (
PRESENT(calculate_forces)) my_calc_forces = calculate_forces
265 IF (ec_env%should_update)
THEN
266 ec_env%old_etotal = 0.0_dp
267 ec_env%etotal = 0.0_dp
268 ec_env%eband = 0.0_dp
269 ec_env%ehartree = 0.0_dp
273 ec_env%edispersion = 0.0_dp
274 ec_env%exc_aux_fit = 0.0_dp
278 ec_env%old_etotal = energy%total
282 IF (my_calc_forces)
THEN
283 IF (unit_nr > 0)
THEN
284 WRITE (unit_nr,
'(T2,A,A,A,A,A)')
"!", repeat(
"-", 25), &
285 " Energy Correction Forces ", repeat(
"-", 26),
"!"
287 CALL get_qs_env(qs_env, force=ks_force, virial=virial)
291 IF (unit_nr > 0)
THEN
292 WRITE (unit_nr,
'(T2,A,A,A,A,A)')
"!", repeat(
"-", 29), &
293 " Energy Correction ", repeat(
"-", 29),
"!"
298 CALL energy_correction_low(qs_env, ec_env, my_calc_forces, unit_nr)
301 IF (ec_env%should_update)
THEN
302 energy%nonscf_correction = ec_env%etotal - ec_env%old_etotal
303 energy%total = ec_env%etotal
306 IF (.NOT. my_calc_forces .AND. unit_nr > 0)
THEN
307 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Energy Correction ", energy%nonscf_correction
309 IF (unit_nr > 0)
THEN
310 WRITE (unit_nr,
'(T2,A,A,A)')
"!", repeat(
"-", 77),
"!"
317 IF (unit_nr > 0)
THEN
318 WRITE (unit_nr,
'(T2,A,A,A)')
"!", repeat(
"-", 77),
"!"
319 WRITE (unit_nr,
'(T2,A,A,A,A,A)')
"!", repeat(
"-", 26), &
320 " Skip Energy Correction ", repeat(
"-", 27),
"!"
321 WRITE (unit_nr,
'(T2,A,A,A)')
"!", repeat(
"-", 77),
"!"
326 CALL timestop(handle)
341 SUBROUTINE energy_correction_low(qs_env, ec_env, calculate_forces, unit_nr)
344 LOGICAL,
INTENT(IN) :: calculate_forces
345 INTEGER,
INTENT(IN) :: unit_nr
347 INTEGER :: ispin, nkind, nspins
348 LOGICAL :: debug_f, gapw, gapw_xc
349 REAL(kind=
dp) :: eps_fit, exc
357 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
359 IF (ec_env%should_update)
THEN
360 CALL ec_build_neighborlist(qs_env, ec_env)
364 ec_env%vtau_rspace, &
365 ec_env%vadmm_rspace, &
366 ec_env%ehartree, exc)
368 SELECT CASE (ec_env%energy_functional)
371 CALL ec_build_core_hamiltonian(qs_env, ec_env)
372 CALL ec_build_ks_matrix(qs_env, ec_env)
377 NULLIFY (ec_env%mao_coef)
378 CALL mao_generate_basis(qs_env, ec_env%mao_coef, ref_basis_set=
"HARRIS", molecular=.true., &
379 max_iter=ec_env%mao_max_iter, eps_grad=ec_env%mao_eps_grad, &
380 eps1_mao=ec_env%mao_eps1, iolevel=ec_env%mao_iolevel, unit_nr=unit_nr)
383 CALL ec_ks_solver(qs_env, ec_env)
385 CALL evaluate_ec_core_matrix_traces(qs_env, ec_env)
390 CALL ec_dc_energy(qs_env, ec_env, calculate_forces=.false.)
395 CALL ec_build_ks_matrix(qs_env, ec_env)
402 cpabort(
"unknown energy correction")
406 CALL ec_disp(qs_env, ec_env, calculate_forces=.false.)
409 CALL ec_energy(ec_env, unit_nr)
413 IF (calculate_forces)
THEN
415 debug_f = ec_env%debug_forces .OR. ec_env%debug_stress
417 CALL ec_disp(qs_env, ec_env, calculate_forces=.true.)
419 SELECT CASE (ec_env%energy_functional)
422 CALL ec_build_core_hamiltonian_force(qs_env, ec_env, &
426 CALL ec_build_ks_matrix_force(qs_env, ec_env)
427 IF (ec_env%debug_external)
THEN
428 CALL write_response_interface(qs_env, ec_env)
429 CALL init_response_deriv(qs_env, ec_env)
436 CALL ec_dc_energy(qs_env, ec_env, calculate_forces=.true.)
438 CALL ec_build_core_hamiltonian_force(qs_env, ec_env, &
442 CALL ec_dc_build_ks_matrix_force(qs_env, ec_env)
443 IF (ec_env%debug_external)
THEN
444 CALL write_response_interface(qs_env, ec_env)
445 CALL init_response_deriv(qs_env, ec_env)
450 CALL init_response_deriv(qs_env, ec_env)
454 cpabort(
"unknown energy correction")
457 CALL get_qs_env(qs_env=qs_env, dft_control=dft_control)
458 nspins = dft_control%nspins
459 gapw = dft_control%qs_control%gapw
460 gapw_xc = dft_control%qs_control%gapw_xc
461 IF (gapw .OR. gapw_xc)
THEN
463 qs_kind_set=qs_kind_set, particle_set=particle_set)
464 CALL get_qs_env(qs_env=qs_env, oce=oce, sap_oce=sap_oce)
467 eps_fit = dft_control%qs_control%gapw_control%eps_fit
479 cpassert(
ASSOCIATED(pw_env))
480 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
481 ALLOCATE (ec_env%rhoz_r(nspins))
483 CALL auxbas_pw_pool%create_pw(ec_env%rhoz_r(ispin))
487 vh_rspace=ec_env%vh_rspace, &
488 vxc_rspace=ec_env%vxc_rspace, &
489 vtau_rspace=ec_env%vtau_rspace, &
490 vadmm_rspace=ec_env%vadmm_rspace, &
491 matrix_hz=ec_env%matrix_hz, &
492 matrix_pz=ec_env%matrix_z, &
493 matrix_pz_admm=ec_env%z_admm, &
494 matrix_wz=ec_env%matrix_wz, &
495 rhopz_r=ec_env%rhoz_r, &
496 zehartree=ec_env%ehartree, &
498 zexc_aux_fit=ec_env%exc_aux_fit, &
499 p_env=ec_env%p_env, &
502 CALL output_response_deriv(qs_env, ec_env, unit_nr)
504 CALL ec_properties(qs_env, ec_env)
507 IF (
ASSOCIATED(ec_env%rhoout_r))
THEN
509 CALL auxbas_pw_pool%give_back_pw(ec_env%rhoout_r(ispin))
511 DEALLOCATE (ec_env%rhoout_r)
513 IF (
ASSOCIATED(ec_env%rhoz_r))
THEN
515 CALL auxbas_pw_pool%give_back_pw(ec_env%rhoz_r(ispin))
517 DEALLOCATE (ec_env%rhoz_r)
533 END SUBROUTINE energy_correction_low
541 SUBROUTINE write_response_interface(qs_env, ec_env)
548 NULLIFY (trexio_section)
552 CALL write_trexio(qs_env, trexio_section, ec_env%matrix_hz)
554 END SUBROUTINE write_response_interface
562 SUBROUTINE init_response_deriv(qs_env, ec_env)
572 ALLOCATE (ec_env%rf(3, natom))
575 CALL get_qs_env(qs_env, force=force, virial=virial)
577 CALL get_qs_env(qs_env, atomic_kind_set=atomic_kind_set)
580 IF (virial%pv_availability .AND. (.NOT. virial%pv_numer))
THEN
581 ec_env%rpv = virial%pv_virial
584 END SUBROUTINE init_response_deriv
593 SUBROUTINE output_response_deriv(qs_env, ec_env, unit_nr)
596 INTEGER,
INTENT(IN) :: unit_nr
598 CHARACTER(LEN=default_string_length) :: unit_string
599 INTEGER :: funit, ia, natom
600 REAL(kind=
dp) :: evol, fconv
601 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: ftot
609 IF (
ASSOCIATED(ec_env%rf))
THEN
611 ALLOCATE (ftot(3, natom))
613 CALL get_qs_env(qs_env, force=force, virial=virial, para_env=para_env)
615 CALL get_qs_env(qs_env, atomic_kind_set=atomic_kind_set)
617 ec_env%rf(1:3, 1:natom) = ftot(1:3, 1:natom) - ec_env%rf(1:3, 1:natom)
618 CALL para_env%sum(ec_env%rf)
621 IF (virial%pv_availability .AND. (.NOT. virial%pv_numer))
THEN
622 ec_env%rpv = virial%pv_virial - ec_env%rpv
623 CALL para_env%sum(ec_env%rpv)
625 evol = ec_env%exc + ec_env%exc_aux_fit + 2.0_dp*ec_env%ehartree
626 ec_env%rpv(1, 1) = ec_env%rpv(1, 1) - evol
627 ec_env%rpv(2, 2) = ec_env%rpv(2, 2) - evol
628 ec_env%rpv(3, 3) = ec_env%rpv(3, 3) - evol
631 CALL get_qs_env(qs_env, particle_set=particle_set, cell=cell)
635 IF (unit_nr > 0)
THEN
636 WRITE (unit_nr,
'(T2,A)')
"Write EXTERNAL Response Derivative: "//trim(ec_env%exresult_fn)
638 CALL open_file(ec_env%exresult_fn, file_status=
"REPLACE", file_form=
"FORMATTED", &
639 file_action=
"WRITE", unit_number=funit)
640 WRITE (funit,
"(T8,A,T58,A)")
"COORDINATES [Bohr]",
"RESPONSE FORCES [Hartree/Bohr]"
642 WRITE (funit,
"(2(3F15.8,5x))") particle_set(ia)%r(1:3), ec_env%rf(1:3, ia)
645 WRITE (funit,
"(T8,A,T58,A)")
"CELL [Bohr]",
"RESPONSE PRESSURE [GPa]"
647 WRITE (funit,
"(3F15.8,5x,3F15.8)") cell%hmat(ia, 1:3), -fconv*ec_env%rpv(ia, 1:3)
654 END SUBROUTINE output_response_deriv
663 SUBROUTINE evaluate_ec_core_matrix_traces(qs_env, ec_env)
667 CHARACTER(LEN=*),
PARAMETER :: routinen =
'evaluate_ec_core_matrix_traces'
673 CALL timeset(routinen, handle)
676 CALL get_qs_env(qs_env, dft_control=dft_control, energy=energy)
679 CALL calculate_ptrace(ec_env%matrix_h, ec_env%matrix_p, energy%core, dft_control%nspins)
682 CALL calculate_ptrace(ec_env%matrix_t, ec_env%matrix_p, energy%kinetic, dft_control%nspins)
684 CALL timestop(handle)
686 END SUBROUTINE evaluate_ec_core_matrix_traces
699 SUBROUTINE ec_dc_energy(qs_env, ec_env, calculate_forces)
702 LOGICAL,
INTENT(IN) :: calculate_forces
704 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ec_dc_energy'
706 CHARACTER(LEN=default_string_length) :: headline
707 INTEGER :: handle, ispin, nspins
708 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_h, matrix_p, matrix_s, matrix_w
713 CALL timeset(routinen, handle)
715 NULLIFY (dft_control, ks_env, matrix_h, matrix_p, matrix_s, matrix_w, rho)
717 dft_control=dft_control, &
719 matrix_h_kp=matrix_h, &
720 matrix_s_kp=matrix_s, &
721 matrix_w_kp=matrix_w, &
724 nspins = dft_control%nspins
729 matrix_name=
"OVERLAP MATRIX", &
730 basis_type_a=
"HARRIS", &
731 basis_type_b=
"HARRIS", &
732 sab_nl=ec_env%sab_orb)
737 headline =
"CORE HAMILTONIAN MATRIX"
738 ALLOCATE (ec_env%matrix_h(1, 1)%matrix)
739 CALL dbcsr_create(ec_env%matrix_h(1, 1)%matrix, name=trim(headline), &
740 template=matrix_s(1, 1)%matrix, matrix_type=dbcsr_type_symmetric)
742 CALL dbcsr_copy(ec_env%matrix_h(1, 1)%matrix, matrix_h(1, 1)%matrix)
747 headline =
"DENSITY MATRIX"
749 ALLOCATE (ec_env%matrix_p(ispin, 1)%matrix)
750 CALL dbcsr_create(ec_env%matrix_p(ispin, 1)%matrix, name=trim(headline), &
751 template=matrix_s(1, 1)%matrix, matrix_type=dbcsr_type_symmetric)
753 CALL dbcsr_copy(ec_env%matrix_p(ispin, 1)%matrix, matrix_p(ispin, 1)%matrix)
756 IF (calculate_forces)
THEN
761 headline =
"ENERGY-WEIGHTED DENSITY MATRIX"
763 ALLOCATE (ec_env%matrix_w(ispin, 1)%matrix)
764 CALL dbcsr_create(ec_env%matrix_w(ispin, 1)%matrix, name=trim(headline), &
765 template=matrix_s(1, 1)%matrix, matrix_type=dbcsr_type_symmetric)
767 CALL dbcsr_copy(ec_env%matrix_w(ispin, 1)%matrix, matrix_w(ispin, 1)%matrix)
773 ec_env%efield_nuclear = 0.0_dp
774 ec_env%efield_elec = 0.0_dp
777 CALL timestop(handle)
779 END SUBROUTINE ec_dc_energy
790 SUBROUTINE ec_dc_build_ks_matrix_force(qs_env, ec_env)
794 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ec_dc_build_ks_matrix_force'
796 CHARACTER(LEN=default_string_length) :: unit_string
797 INTEGER :: handle, i, iounit, ispin, natom, nspins
798 LOGICAL :: debug_forces, debug_stress, do_ec_hfx, &
800 REAL(
dp) :: dummy_real, dummy_real2(2), ehartree, &
802 REAL(
dp),
ALLOCATABLE,
DIMENSION(:, :) :: ftot
803 REAL(
dp),
DIMENSION(3) :: fodeb, fodeb2
804 REAL(kind=
dp),
DIMENSION(3, 3) :: h_stress, pv_loc, stdeb, sttot
808 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_ks, matrix_s, scrm
809 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_p
820 TYPE(
pw_r3d_rs_type),
DIMENSION(:),
POINTER :: rho_r, v_rspace, v_rspace_in, &
828 CALL timeset(routinen, handle)
830 debug_forces = ec_env%debug_forces
831 debug_stress = ec_env%debug_stress
834 IF (logger%para_env%is_source())
THEN
840 NULLIFY (atomic_kind_set, cell, dft_control, force, ks_env, matrix_ks, &
841 matrix_p, matrix_s, para_env, pw_env, rho, sab_orb, virial)
844 dft_control=dft_control, &
847 matrix_ks=matrix_ks, &
854 cpassert(
ASSOCIATED(pw_env))
856 nspins = dft_control%nspins
857 use_virial = virial%pv_availability .AND. (.NOT. virial%pv_numer)
859 fconv = 1.0e-9_dp*
pascal/cell%deth
860 IF (debug_stress .AND. use_virial)
THEN
861 sttot = virial%pv_virial
867 NULLIFY (auxbas_pw_pool, poisson_env)
869 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool, &
870 poisson_env=poisson_env)
873 CALL auxbas_pw_pool%create_pw(v_hartree_gspace)
874 CALL auxbas_pw_pool%create_pw(rho_tot_gspace)
875 CALL auxbas_pw_pool%create_pw(v_hartree_rspace)
884 h_stress(:, :) = 0.0_dp
886 density=rho_tot_gspace, &
888 vhartree=v_hartree_gspace, &
891 virial%pv_ehartree = virial%pv_ehartree + h_stress/real(para_env%num_pe,
dp)
892 virial%pv_virial = virial%pv_virial + h_stress/real(para_env%num_pe,
dp)
894 IF (debug_stress)
THEN
895 stdeb = fconv*(h_stress/real(para_env%num_pe,
dp))
896 CALL para_env%sum(stdeb)
897 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
906 CALL pw_transfer(v_hartree_gspace, v_hartree_rspace)
907 CALL pw_scale(v_hartree_rspace, v_hartree_rspace%pw_grid%dvol)
911 ALLOCATE (ec_env%rhoout_r(nspins))
913 CALL auxbas_pw_pool%create_pw(ec_env%rhoout_r(ispin))
914 CALL pw_copy(rho_r(ispin), ec_env%rhoout_r(ispin))
919 IF (debug_forces) fodeb(1:3) = force(1)%rho_core(1:3, 1)
920 IF (debug_stress .AND. use_virial) stdeb = virial%pv_ehartree
921 CALL integrate_v_core_rspace(v_hartree_rspace, qs_env)
922 IF (debug_forces)
THEN
923 fodeb(1:3) = force(1)%rho_core(1:3, 1) - fodeb(1:3)
924 CALL para_env%sum(fodeb)
925 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Vtot*dncore", fodeb
927 IF (debug_stress .AND. use_virial)
THEN
928 stdeb = fconv*(virial%pv_ehartree - stdeb)
929 CALL para_env%sum(stdeb)
930 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
936 NULLIFY (v_rspace, v_tau_rspace)
939 IF (use_virial) virial%pv_calculate = .true.
942 CALL qs_vxc_create(ks_env=ks_env, rho_struct=rho, xc_section=ec_env%xc_section, &
943 vxc_rho=v_rspace, vxc_tau=v_tau_rspace, exc=exc, just_energy=.false.)
945 IF (.NOT.
ASSOCIATED(v_rspace))
THEN
946 ALLOCATE (v_rspace(nspins))
948 CALL auxbas_pw_pool%create_pw(v_rspace(ispin))
954 virial%pv_exc = virial%pv_exc - virial%pv_xc
955 virial%pv_virial = virial%pv_virial - virial%pv_xc
963 ALLOCATE (scrm(ispin)%matrix)
964 CALL dbcsr_create(scrm(ispin)%matrix, template=ec_env%matrix_ks(ispin, 1)%matrix)
965 CALL dbcsr_copy(scrm(ispin)%matrix, ec_env%matrix_ks(ispin, 1)%matrix)
966 CALL dbcsr_set(scrm(ispin)%matrix, 0.0_dp)
969 pw_grid => v_hartree_rspace%pw_grid
970 ALLOCATE (v_rspace_in(nspins))
972 CALL v_rspace_in(ispin)%create(pw_grid)
978 CALL pw_transfer(ec_env%vxc_rspace(ispin), v_rspace_in(ispin))
980 CALL pw_axpy(ec_env%vh_rspace, v_rspace_in(ispin))
991 IF (debug_forces) fodeb(1:3) = force(1)%fock_4c(1:3, 1)
992 IF (debug_forces) fodeb2(1:3) = force(1)%overlap_admm(1:3, 1)
999 hfx_sections=ec_hfx_sections, &
1000 x_data=ec_env%x_data, &
1002 do_admm=ec_env%do_ec_admm, &
1003 calc_forces=.true., &
1004 reuse_hfx=ec_env%reuse_hfx, &
1005 do_im_time=.false., &
1006 e_ex_from_gw=dummy_real, &
1007 e_admm_from_gw=dummy_real2, &
1010 IF (debug_forces)
THEN
1011 fodeb(1:3) = force(1)%fock_4c(1:3, 1) - fodeb(1:3)
1012 CALL para_env%sum(fodeb)
1013 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: P*hfx_DC ", fodeb
1015 fodeb2(1:3) = force(1)%overlap_admm(1:3, 1) - fodeb2(1:3)
1016 CALL para_env%sum(fodeb2)
1017 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: P*hfx_DC*S ", fodeb2
1019 IF (debug_stress .AND. use_virial)
THEN
1020 stdeb = -1.0_dp*fconv*virial%pv_fock_4c
1021 CALL para_env%sum(stdeb)
1022 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1032 IF (use_virial)
THEN
1033 pv_loc = virial%pv_virial
1036 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
1037 IF (debug_stress .AND. use_virial) stdeb = virial%pv_virial
1039 DO ispin = 1, nspins
1041 CALL pw_scale(v_rspace(ispin), v_rspace(ispin)%pw_grid%dvol)
1042 CALL pw_axpy(v_hartree_rspace, v_rspace(ispin))
1044 CALL integrate_v_rspace(v_rspace=v_rspace(ispin), &
1046 pmat=matrix_p(ispin, 1), &
1048 calculate_forces=.true., &
1049 basis_type=
"HARRIS", &
1050 task_list_external=ec_env%task_list)
1053 IF (debug_forces)
THEN
1054 fodeb(1:3) = force(1)%rho_elec(1:3, 1) - fodeb(1:3)
1055 CALL para_env%sum(fodeb)
1056 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Pout*dVhxc ", fodeb
1058 IF (debug_stress .AND. use_virial)
THEN
1059 stdeb = fconv*(virial%pv_virial - stdeb)
1060 CALL para_env%sum(stdeb)
1061 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1065 IF (
ASSOCIATED(v_tau_rspace))
THEN
1066 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
1067 IF (debug_stress .AND. use_virial) stdeb = virial%pv_virial
1068 DO ispin = 1, nspins
1069 CALL pw_scale(v_tau_rspace(ispin), v_tau_rspace(ispin)%pw_grid%dvol)
1071 CALL integrate_v_rspace(v_rspace=v_tau_rspace(ispin), &
1073 pmat=matrix_p(ispin, 1), &
1075 calculate_forces=.true., &
1076 compute_tau=.true., &
1077 basis_type=
"HARRIS", &
1078 task_list_external=ec_env%task_list)
1081 IF (debug_forces)
THEN
1082 fodeb(1:3) = force(1)%rho_elec(1:3, 1) - fodeb(1:3)
1083 CALL para_env%sum(fodeb)
1084 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Pout*dVhxc_tau ", fodeb
1086 IF (debug_stress .AND. use_virial)
THEN
1087 stdeb = fconv*(virial%pv_virial - stdeb)
1088 CALL para_env%sum(stdeb)
1089 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1095 IF (use_virial)
THEN
1096 virial%pv_ehartree = virial%pv_ehartree + (virial%pv_virial - pv_loc)
1115 NULLIFY (ec_env%matrix_hz)
1117 DO ispin = 1, nspins
1118 ALLOCATE (ec_env%matrix_hz(ispin)%matrix)
1119 CALL dbcsr_create(ec_env%matrix_hz(ispin)%matrix, template=matrix_s(1)%matrix)
1120 CALL dbcsr_copy(ec_env%matrix_hz(ispin)%matrix, matrix_s(1)%matrix)
1121 CALL dbcsr_set(ec_env%matrix_hz(ispin)%matrix, 0.0_dp)
1124 DO ispin = 1, nspins
1127 CALL pw_axpy(v_rspace_in(ispin), v_rspace(ispin), -1.0_dp)
1130 DO ispin = 1, nspins
1131 CALL integrate_v_rspace(v_rspace=v_rspace(ispin), &
1132 hmat=ec_env%matrix_hz(ispin), &
1133 pmat=matrix_p(ispin, 1), &
1135 calculate_forces=.false., &
1136 basis_type=
"HARRIS", &
1137 task_list_external=ec_env%task_list)
1141 IF (dft_control%use_kinetic_energy_density)
THEN
1144 IF (.NOT.
ASSOCIATED(v_tau_rspace))
THEN
1145 ALLOCATE (v_tau_rspace(nspins))
1146 DO ispin = 1, nspins
1147 CALL auxbas_pw_pool%create_pw(v_tau_rspace(ispin))
1148 CALL pw_zero(v_tau_rspace(ispin))
1152 DO ispin = 1, nspins
1154 IF (
ASSOCIATED(ec_env%vtau_rspace))
THEN
1155 CALL pw_axpy(ec_env%vtau_rspace(ispin), v_tau_rspace(ispin), -1.0_dp)
1158 CALL integrate_v_rspace(v_rspace=v_tau_rspace(ispin), &
1159 hmat=ec_env%matrix_hz(ispin), &
1160 pmat=matrix_p(ispin, 1), &
1162 calculate_forces=.false., compute_tau=.true., &
1163 basis_type=
"HARRIS", &
1164 task_list_external=ec_env%task_list)
1172 ext_hfx_section=ec_hfx_sections, &
1173 x_data=ec_env%x_data, &
1174 recalc_integrals=.false., &
1175 do_admm=ec_env%do_ec_admm, &
1178 reuse_hfx=ec_env%reuse_hfx)
1181 IF (debug_forces) fodeb(1:3) = force(1)%core_overlap(1:3, 1)
1182 IF (debug_stress .AND. use_virial) stdeb = virial%pv_ecore_overlap
1184 IF (debug_forces)
THEN
1185 fodeb(1:3) = force(1)%core_overlap(1:3, 1) - fodeb(1:3)
1186 CALL para_env%sum(fodeb)
1187 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: CoreOverlap", fodeb
1189 IF (debug_stress .AND. use_virial)
THEN
1190 stdeb = fconv*(stdeb - virial%pv_ecore_overlap)
1191 CALL para_env%sum(stdeb)
1192 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1196 IF (debug_forces)
THEN
1197 CALL get_qs_env(qs_env, natom=natom, atomic_kind_set=atomic_kind_set)
1198 ALLOCATE (ftot(3, natom))
1200 fodeb(1:3) = ftot(1:3, 1)
1202 CALL para_env%sum(fodeb)
1203 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Force Explicit", fodeb
1207 DO ispin = 1, nspins
1208 CALL auxbas_pw_pool%give_back_pw(v_rspace(ispin))
1209 CALL auxbas_pw_pool%give_back_pw(v_rspace_in(ispin))
1210 IF (
ASSOCIATED(v_tau_rspace))
THEN
1211 CALL auxbas_pw_pool%give_back_pw(v_tau_rspace(ispin))
1215 DEALLOCATE (v_rspace, v_rspace_in)
1216 IF (
ASSOCIATED(v_tau_rspace))
DEALLOCATE (v_tau_rspace)
1218 CALL auxbas_pw_pool%give_back_pw(rho_tot_gspace)
1219 CALL auxbas_pw_pool%give_back_pw(v_hartree_gspace)
1220 CALL auxbas_pw_pool%give_back_pw(v_hartree_rspace)
1224 IF (use_virial)
THEN
1225 IF (qs_env%energy_correction)
THEN
1226 ec_env%ehartree = ehartree
1231 IF (debug_stress .AND. use_virial)
THEN
1233 stdeb = -1.0_dp*fconv*ehartree
1234 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1237 stdeb = -1.0_dp*fconv*exc
1238 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1247 CALL para_env%sum(virdeb%pv_overlap)
1248 CALL para_env%sum(virdeb%pv_ekinetic)
1249 CALL para_env%sum(virdeb%pv_ppl)
1250 CALL para_env%sum(virdeb%pv_ppnl)
1251 CALL para_env%sum(virdeb%pv_ecore_overlap)
1252 CALL para_env%sum(virdeb%pv_ehartree)
1253 CALL para_env%sum(virdeb%pv_exc)
1254 CALL para_env%sum(virdeb%pv_exx)
1255 CALL para_env%sum(virdeb%pv_vdw)
1256 CALL para_env%sum(virdeb%pv_mp2)
1257 CALL para_env%sum(virdeb%pv_nlcc)
1258 CALL para_env%sum(virdeb%pv_gapw)
1259 CALL para_env%sum(virdeb%pv_lrigpw)
1260 CALL para_env%sum(virdeb%pv_virial)
1265 virdeb%pv_ehartree(i, i) = virdeb%pv_ehartree(i, i) - 2.0_dp*ehartree
1266 virdeb%pv_virial(i, i) = virdeb%pv_virial(i, i) - exc &
1268 virdeb%pv_exc(i, i) = virdeb%pv_exc(i, i) - exc
1274 CALL para_env%sum(sttot)
1275 stdeb = fconv*(virdeb%pv_virial - sttot)
1276 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1279 stdeb = fconv*(virdeb%pv_virial)
1280 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1290 CALL timestop(handle)
1292 END SUBROUTINE ec_dc_build_ks_matrix_force
1300 SUBROUTINE ec_disp(qs_env, ec_env, calculate_forces)
1301 TYPE(qs_environment_type),
POINTER :: qs_env
1302 TYPE(energy_correction_type),
POINTER :: ec_env
1303 LOGICAL,
INTENT(IN) :: calculate_forces
1305 REAL(kind=dp) :: edisp
1307 CALL calculate_dispersion_pairpot(qs_env, ec_env%dispersion_env, edisp, calculate_forces)
1308 IF (.NOT. calculate_forces) ec_env%edispersion = ec_env%edispersion + edisp
1310 END SUBROUTINE ec_disp
1319 SUBROUTINE ec_build_core_hamiltonian(qs_env, ec_env)
1320 TYPE(qs_environment_type),
POINTER :: qs_env
1321 TYPE(energy_correction_type),
POINTER :: ec_env
1323 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ec_build_core_hamiltonian'
1325 INTEGER :: handle, nder, nimages
1326 INTEGER,
DIMENSION(:, :, :),
POINTER :: cell_to_index
1327 LOGICAL :: calculate_forces, use_virial
1328 REAL(kind=dp) :: eps_ppnl
1329 TYPE(atomic_kind_type),
DIMENSION(:),
POINTER :: atomic_kind_set
1330 TYPE(dft_control_type),
POINTER :: dft_control
1331 TYPE(neighbor_list_set_p_type),
DIMENSION(:), &
1332 POINTER :: sab_orb, sac_ae, sac_ppl, sap_ppnl
1333 TYPE(particle_type),
DIMENSION(:),
POINTER :: particle_set
1334 TYPE(qs_force_type),
DIMENSION(:),
POINTER :: force
1335 TYPE(qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
1336 TYPE(qs_ks_env_type),
POINTER :: ks_env
1337 TYPE(virial_type),
POINTER :: virial
1339 CALL timeset(routinen, handle)
1341 NULLIFY (atomic_kind_set, cell_to_index, dft_control, ks_env, particle_set, qs_kind_set, virial)
1343 CALL get_qs_env(qs_env=qs_env, &
1344 atomic_kind_set=atomic_kind_set, &
1345 dft_control=dft_control, &
1346 particle_set=particle_set, &
1347 qs_kind_set=qs_kind_set, &
1351 nimages = dft_control%nimages
1352 IF (nimages /= 1)
THEN
1353 cpabort(
"K-points for Harris functional not implemented")
1357 IF (dft_control%qs_control%gapw .OR. dft_control%qs_control%gapw_xc)
THEN
1358 cpabort(
"Harris functional for GAPW not implemented")
1362 use_virial = .false.
1363 calculate_forces = .false.
1366 NULLIFY (sab_orb, sac_ae, sac_ppl, sap_ppnl)
1367 sab_orb => ec_env%sab_orb
1368 sac_ae => ec_env%sac_ae
1369 sac_ppl => ec_env%sac_ppl
1370 sap_ppnl => ec_env%sap_ppnl
1374 CALL build_overlap_matrix(ks_env, matrixkp_s=ec_env%matrix_s, &
1375 matrix_name=
"OVERLAP MATRIX", &
1376 basis_type_a=
"HARRIS", &
1377 basis_type_b=
"HARRIS", &
1379 CALL build_kinetic_matrix(ks_env, matrixkp_t=ec_env%matrix_t, &
1380 matrix_name=
"KINETIC ENERGY MATRIX", &
1381 basis_type=
"HARRIS", &
1385 CALL dbcsr_allocate_matrix_set(ec_env%matrix_h, 1, 1)
1386 ALLOCATE (ec_env%matrix_h(1, 1)%matrix)
1387 CALL dbcsr_create(ec_env%matrix_h(1, 1)%matrix, template=ec_env%matrix_s(1, 1)%matrix)
1388 CALL cp_dbcsr_alloc_block_from_nbl(ec_env%matrix_h(1, 1)%matrix, sab_orb)
1391 CALL dbcsr_copy(ec_env%matrix_h(1, 1)%matrix, ec_env%matrix_t(1, 1)%matrix, &
1392 keep_sparsity=.true., name=
"CORE HAMILTONIAN MATRIX")
1395 IF (
ASSOCIATED(sac_ae))
THEN
1396 CALL build_core_ae(ec_env%matrix_h, ec_env%matrix_p, force, &
1397 virial, calculate_forces, use_virial, nder, &
1398 qs_kind_set, atomic_kind_set, particle_set, sab_orb, sac_ae, &
1399 nimages, cell_to_index,
"HARRIS")
1402 IF (
ASSOCIATED(sac_ppl))
THEN
1403 CALL build_core_ppl(ec_env%matrix_h, ec_env%matrix_p, force, &
1404 virial, calculate_forces, use_virial, nder, &
1405 qs_kind_set, atomic_kind_set, particle_set, sab_orb, sac_ppl, &
1406 nimages, cell_to_index,
"HARRIS")
1410 eps_ppnl = dft_control%qs_control%eps_ppnl
1411 IF (
ASSOCIATED(sap_ppnl))
THEN
1412 CALL build_core_ppnl(ec_env%matrix_h, ec_env%matrix_p, force, &
1413 virial, calculate_forces, use_virial, nder, &
1414 qs_kind_set, atomic_kind_set, particle_set, sab_orb, sap_ppnl, &
1415 eps_ppnl, nimages, cell_to_index,
"HARRIS")
1419 ec_env%efield_nuclear = 0.0_dp
1420 CALL ec_efield_local_operator(qs_env, ec_env, calculate_forces)
1422 CALL timestop(handle)
1424 END SUBROUTINE ec_build_core_hamiltonian
1435 SUBROUTINE ec_build_ks_matrix(qs_env, ec_env)
1436 TYPE(qs_environment_type),
POINTER :: qs_env
1437 TYPE(energy_correction_type),
POINTER :: ec_env
1439 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ec_build_ks_matrix'
1441 CHARACTER(LEN=default_string_length) :: headline
1442 INTEGER :: handle, iounit, ispin, nspins
1443 LOGICAL :: calculate_forces, &
1444 do_adiabatic_rescaling, do_ec_hfx, &
1445 hfx_treat_lsd_in_core, use_virial
1446 REAL(dp) :: dummy_real, dummy_real2(2), eexc, evhxc, &
1448 TYPE(cp_logger_type),
POINTER :: logger
1449 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: ks_mat
1450 TYPE(dft_control_type),
POINTER :: dft_control
1451 TYPE(pw_env_type),
POINTER :: pw_env
1452 TYPE(pw_pool_type),
POINTER :: auxbas_pw_pool
1453 TYPE(pw_r3d_rs_type),
DIMENSION(:),
POINTER :: rho_r, tau_r, v_rspace, v_tau_rspace
1454 TYPE(qs_energy_type),
POINTER :: energy
1455 TYPE(qs_ks_env_type),
POINTER :: ks_env
1456 TYPE(qs_rho_type),
POINTER :: rho
1457 TYPE(section_vals_type),
POINTER :: adiabatic_rescaling_section, &
1458 ec_hfx_sections, ec_section
1460 CALL timeset(routinen, handle)
1462 logger => cp_get_default_logger()
1463 IF (logger%para_env%is_source())
THEN
1464 iounit = cp_logger_get_default_unit_nr(logger, local=.true.)
1470 NULLIFY (auxbas_pw_pool, dft_control, energy, ks_env, rho, rho_r, tau_r)
1471 CALL get_qs_env(qs_env=qs_env, &
1472 dft_control=dft_control, &
1475 nspins = dft_control%nspins
1476 calculate_forces = .false.
1477 use_virial = .false.
1480 IF (
ASSOCIATED(ec_env%matrix_ks))
CALL dbcsr_deallocate_matrix_set(ec_env%matrix_ks)
1481 CALL dbcsr_allocate_matrix_set(ec_env%matrix_ks, nspins, 1)
1482 DO ispin = 1, nspins
1483 headline =
"KOHN-SHAM MATRIX"
1484 ALLOCATE (ec_env%matrix_ks(ispin, 1)%matrix)
1485 CALL dbcsr_create(ec_env%matrix_ks(ispin, 1)%matrix, name=trim(headline), &
1486 template=ec_env%matrix_s(1, 1)%matrix, matrix_type=dbcsr_type_symmetric)
1487 CALL cp_dbcsr_alloc_block_from_nbl(ec_env%matrix_ks(ispin, 1)%matrix, ec_env%sab_orb)
1488 CALL dbcsr_set(ec_env%matrix_ks(ispin, 1)%matrix, 0.0_dp)
1492 CALL get_qs_env(qs_env=qs_env, pw_env=pw_env)
1493 cpassert(
ASSOCIATED(pw_env))
1496 ec_section => section_vals_get_subs_vals(qs_env%input,
"DFT%ENERGY_CORRECTION")
1497 ec_hfx_sections => section_vals_get_subs_vals(ec_section,
"XC%HF")
1498 CALL section_vals_get(ec_hfx_sections, explicit=do_ec_hfx)
1503 adiabatic_rescaling_section => section_vals_get_subs_vals(ec_section,
"XC%ADIABATIC_RESCALING")
1504 CALL section_vals_get(adiabatic_rescaling_section, explicit=do_adiabatic_rescaling)
1505 IF (do_adiabatic_rescaling)
THEN
1506 CALL cp_abort(__location__,
"Adiabatic rescaling NYI for energy correction")
1508 CALL section_vals_val_get(ec_hfx_sections,
"TREAT_LSD_IN_CORE", l_val=hfx_treat_lsd_in_core)
1509 IF (hfx_treat_lsd_in_core)
THEN
1510 CALL cp_abort(__location__,
"HFX_TREAT_LSD_IN_CORE NYI for energy correction")
1514 IF (dft_control%do_admm)
THEN
1516 IF (dft_control%do_admm_mo)
THEN
1517 IF (qs_env%run_rtp)
THEN
1518 CALL rtp_admm_calc_rho_aux(qs_env)
1520 CALL admm_mo_calc_rho_aux(qs_env)
1522 ELSEIF (dft_control%do_admm_dm)
THEN
1523 CALL admm_dm_calc_rho_aux(qs_env)
1530 CALL get_qs_env(qs_env, energy=energy)
1531 CALL calculate_exx(qs_env=qs_env, &
1533 hfx_sections=ec_hfx_sections, &
1534 x_data=ec_env%x_data, &
1536 do_admm=ec_env%do_ec_admm, &
1537 calc_forces=.false., &
1538 reuse_hfx=ec_env%reuse_hfx, &
1539 do_im_time=.false., &
1540 e_ex_from_gw=dummy_real, &
1541 e_admm_from_gw=dummy_real2, &
1545 ec_env%ex = energy%ex
1547 IF (ec_env%do_ec_admm)
THEN
1548 ec_env%exc_aux_fit = energy%exc_aux_fit + energy%exc
1554 ks_mat => ec_env%matrix_ks(:, 1)
1555 CALL add_exx_to_rhs(rhs=ks_mat, &
1557 ext_hfx_section=ec_hfx_sections, &
1558 x_data=ec_env%x_data, &
1559 recalc_integrals=.false., &
1560 do_admm=ec_env%do_ec_admm, &
1563 reuse_hfx=ec_env%reuse_hfx)
1568 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
1569 NULLIFY (v_rspace, v_tau_rspace)
1570 CALL qs_vxc_create(ks_env=ks_env, rho_struct=rho, xc_section=ec_env%xc_section, &
1571 vxc_rho=v_rspace, vxc_tau=v_tau_rspace, exc=eexc, just_energy=.false.)
1573 IF (.NOT.
ASSOCIATED(v_rspace))
THEN
1574 ALLOCATE (v_rspace(nspins))
1575 DO ispin = 1, nspins
1576 CALL auxbas_pw_pool%create_pw(v_rspace(ispin))
1577 CALL pw_zero(v_rspace(ispin))
1582 CALL qs_rho_get(rho, rho_r=rho_r)
1583 IF (
ASSOCIATED(v_tau_rspace))
THEN
1584 CALL qs_rho_get(rho, tau_r=tau_r)
1586 DO ispin = 1, nspins
1588 CALL pw_scale(v_rspace(ispin), v_rspace(ispin)%pw_grid%dvol)
1589 CALL pw_axpy(ec_env%vh_rspace, v_rspace(ispin))
1591 CALL integrate_v_rspace(v_rspace=v_rspace(ispin), &
1592 hmat=ec_env%matrix_ks(ispin, 1), &
1594 calculate_forces=.false., &
1595 basis_type=
"HARRIS", &
1596 task_list_external=ec_env%task_list)
1598 IF (
ASSOCIATED(v_tau_rspace))
THEN
1600 CALL pw_scale(v_tau_rspace(ispin), v_tau_rspace(ispin)%pw_grid%dvol)
1601 CALL integrate_v_rspace(v_rspace=v_tau_rspace(ispin), &
1602 hmat=ec_env%matrix_ks(ispin, 1), &
1604 calculate_forces=.false., &
1605 compute_tau=.true., &
1606 basis_type=
"HARRIS", &
1607 task_list_external=ec_env%task_list)
1611 evhxc = evhxc + pw_integral_ab(rho_r(ispin), v_rspace(ispin))/ &
1612 v_rspace(1)%pw_grid%dvol
1613 IF (
ASSOCIATED(v_tau_rspace))
THEN
1614 evhxc = evhxc + pw_integral_ab(tau_r(ispin), v_tau_rspace(ispin))/ &
1615 v_tau_rspace(ispin)%pw_grid%dvol
1621 DO ispin = 1, nspins
1622 CALL auxbas_pw_pool%give_back_pw(v_rspace(ispin))
1623 IF (
ASSOCIATED(v_tau_rspace))
THEN
1624 CALL auxbas_pw_pool%give_back_pw(v_tau_rspace(ispin))
1627 DEALLOCATE (v_rspace)
1628 IF (
ASSOCIATED(v_tau_rspace))
DEALLOCATE (v_tau_rspace)
1635 DO ispin = 1, nspins
1636 CALL dbcsr_add(ec_env%matrix_ks(ispin, 1)%matrix, ec_env%matrix_h(1, 1)%matrix, &
1637 alpha_scalar=1.0_dp, beta_scalar=1.0_dp)
1638 CALL dbcsr_filter(ec_env%matrix_ks(ispin, 1)%matrix, &
1639 dft_control%qs_control%eps_filter_matrix)
1642 CALL timestop(handle)
1644 END SUBROUTINE ec_build_ks_matrix
1656 SUBROUTINE ec_build_core_hamiltonian_force(qs_env, ec_env, matrix_p, matrix_s, matrix_w)
1657 TYPE(qs_environment_type),
POINTER :: qs_env
1658 TYPE(energy_correction_type),
POINTER :: ec_env
1659 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_p, matrix_s, matrix_w
1661 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ec_build_core_hamiltonian_force'
1663 INTEGER :: handle, iounit, nder, nimages
1664 INTEGER,
DIMENSION(:, :, :),
POINTER :: cell_to_index
1665 LOGICAL :: calculate_forces, debug_forces, &
1666 debug_stress, use_virial
1667 REAL(kind=dp) :: eps_ppnl, fconv
1668 REAL(kind=dp),
DIMENSION(3) :: fodeb
1669 REAL(kind=dp),
DIMENSION(3, 3) :: stdeb, sttot
1670 TYPE(atomic_kind_type),
DIMENSION(:),
POINTER :: atomic_kind_set
1671 TYPE(cell_type),
POINTER :: cell
1672 TYPE(cp_logger_type),
POINTER :: logger
1673 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: scrm
1674 TYPE(dft_control_type),
POINTER :: dft_control
1675 TYPE(mp_para_env_type),
POINTER :: para_env
1676 TYPE(neighbor_list_set_p_type),
DIMENSION(:), &
1677 POINTER :: sab_orb, sac_ae, sac_ppl, sap_ppnl
1678 TYPE(particle_type),
DIMENSION(:),
POINTER :: particle_set
1679 TYPE(qs_force_type),
DIMENSION(:),
POINTER :: force
1680 TYPE(qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
1681 TYPE(qs_ks_env_type),
POINTER :: ks_env
1682 TYPE(virial_type),
POINTER :: virial
1684 CALL timeset(routinen, handle)
1686 debug_forces = ec_env%debug_forces
1687 debug_stress = ec_env%debug_stress
1689 logger => cp_get_default_logger()
1690 IF (logger%para_env%is_source())
THEN
1691 iounit = cp_logger_get_default_unit_nr(logger, local=.true.)
1696 calculate_forces = .true.
1699 NULLIFY (cell, dft_control, force, ks_env, para_env, virial)
1700 CALL get_qs_env(qs_env=qs_env, &
1702 dft_control=dft_control, &
1705 para_env=para_env, &
1707 nimages = dft_control%nimages
1708 IF (nimages /= 1)
THEN
1709 cpabort(
"K-points for Harris functional not implemented")
1713 use_virial = virial%pv_availability .AND. (.NOT. virial%pv_numer)
1715 fconv = 1.0e-9_dp*pascal/cell%deth
1716 IF (debug_stress .AND. use_virial)
THEN
1717 sttot = virial%pv_virial
1721 IF (dft_control%qs_control%gapw .OR. dft_control%qs_control%gapw_xc)
THEN
1722 IF (ec_env%energy_functional == ec_functional_harris)
THEN
1723 cpabort(
"Harris functional for GAPW not implemented")
1728 NULLIFY (sab_orb, sac_ppl, sap_ppnl)
1729 sab_orb => ec_env%sab_orb
1730 sac_ae => ec_env%sac_ae
1731 sac_ppl => ec_env%sac_ppl
1732 sap_ppnl => ec_env%sap_ppnl
1736 CALL dbcsr_allocate_matrix_set(scrm, 1, 1)
1737 ALLOCATE (scrm(1, 1)%matrix)
1738 CALL dbcsr_create(scrm(1, 1)%matrix, template=matrix_s(1, 1)%matrix)
1739 CALL cp_dbcsr_alloc_block_from_nbl(scrm(1, 1)%matrix, sab_orb)
1742 IF (
SIZE(matrix_p, 1) == 2)
THEN
1743 CALL dbcsr_add(matrix_p(1, 1)%matrix, matrix_p(2, 1)%matrix, &
1744 alpha_scalar=1.0_dp, beta_scalar=1.0_dp)
1745 CALL dbcsr_add(matrix_w(1, 1)%matrix, matrix_w(2, 1)%matrix, &
1746 alpha_scalar=1.0_dp, beta_scalar=1.0_dp)
1750 IF (debug_forces) fodeb(1:3) = force(1)%overlap(1:3, 1)
1751 IF (debug_stress .AND. use_virial) stdeb = virial%pv_overlap
1752 CALL build_overlap_matrix(ks_env, matrixkp_s=scrm, &
1753 matrix_name=
"OVERLAP MATRIX", &
1754 basis_type_a=
"HARRIS", &
1755 basis_type_b=
"HARRIS", &
1756 sab_nl=sab_orb, calculate_forces=.true., &
1757 matrixkp_p=matrix_w)
1759 IF (debug_forces)
THEN
1760 fodeb(1:3) = force(1)%overlap(1:3, 1) - fodeb(1:3)
1761 CALL para_env%sum(fodeb)
1762 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Wout*dS ", fodeb
1763 fodeb(1:3) = force(1)%kinetic(1:3, 1)
1765 IF (debug_stress .AND. use_virial)
THEN
1766 stdeb = fconv*(virial%pv_overlap - stdeb)
1767 CALL para_env%sum(stdeb)
1768 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1769 'STRESS| Wout*dS', one_third_sum_diag(stdeb), det_3x3(stdeb)
1770 stdeb = virial%pv_ekinetic
1772 CALL build_kinetic_matrix(ks_env, matrixkp_t=scrm, &
1773 matrix_name=
"KINETIC ENERGY MATRIX", &
1774 basis_type=
"HARRIS", &
1775 sab_nl=sab_orb, calculate_forces=.true., &
1776 matrixkp_p=matrix_p)
1777 IF (debug_forces)
THEN
1778 fodeb(1:3) = force(1)%kinetic(1:3, 1) - fodeb(1:3)
1779 CALL para_env%sum(fodeb)
1780 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Pout*dT ", fodeb
1782 IF (debug_stress .AND. use_virial)
THEN
1783 stdeb = fconv*(virial%pv_ekinetic - stdeb)
1784 CALL para_env%sum(stdeb)
1785 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1786 'STRESS| Pout*dT', one_third_sum_diag(stdeb), det_3x3(stdeb)
1788 IF (
SIZE(matrix_p, 1) == 2)
THEN
1789 CALL dbcsr_add(matrix_p(1, 1)%matrix, matrix_p(2, 1)%matrix, &
1790 alpha_scalar=1.0_dp, beta_scalar=-1.0_dp)
1794 NULLIFY (atomic_kind_set, particle_set, qs_kind_set)
1795 CALL get_qs_env(qs_env=qs_env, qs_kind_set=qs_kind_set, particle_set=particle_set, &
1796 atomic_kind_set=atomic_kind_set)
1798 IF (
ASSOCIATED(sac_ae))
THEN
1799 IF (calculate_forces .AND. debug_forces) fodeb(1:3) = force(1)%all_potential(1:3, 1)
1800 IF (debug_stress .AND. use_virial) stdeb = virial%pv_ppl
1801 CALL build_core_ae(scrm, matrix_p, force, &
1802 virial, calculate_forces, use_virial, nder, &
1803 qs_kind_set, atomic_kind_set, particle_set, sab_orb, sac_ae, &
1804 nimages, cell_to_index,
"HARRIS")
1805 IF (calculate_forces .AND. debug_forces)
THEN
1806 fodeb(1:3) = force(1)%all_potential(1:3, 1) - fodeb(1:3)
1807 CALL para_env%sum(fodeb)
1808 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Pout*dHae ", fodeb
1810 IF (debug_stress .AND. use_virial)
THEN
1811 stdeb = fconv*(virial%pv_ppl - stdeb)
1812 CALL para_env%sum(stdeb)
1813 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1814 'STRESS| Pout*dHae ', one_third_sum_diag(stdeb), det_3x3(stdeb)
1818 IF (
ASSOCIATED(sac_ppl))
THEN
1819 IF (calculate_forces .AND. debug_forces) fodeb(1:3) = force(1)%gth_ppl(1:3, 1)
1820 IF (debug_stress .AND. use_virial) stdeb = virial%pv_ppl
1821 CALL build_core_ppl(scrm, matrix_p, force, &
1822 virial, calculate_forces, use_virial, nder, &
1823 qs_kind_set, atomic_kind_set, particle_set, sab_orb, sac_ppl, &
1824 nimages, cell_to_index,
"HARRIS")
1825 IF (calculate_forces .AND. debug_forces)
THEN
1826 fodeb(1:3) = force(1)%gth_ppl(1:3, 1) - fodeb(1:3)
1827 CALL para_env%sum(fodeb)
1828 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Pout*dH_PPL ", fodeb
1830 IF (debug_stress .AND. use_virial)
THEN
1831 stdeb = fconv*(virial%pv_ppl - stdeb)
1832 CALL para_env%sum(stdeb)
1833 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1834 'STRESS| Pout*dH_PPL', one_third_sum_diag(stdeb), det_3x3(stdeb)
1839 eps_ppnl = dft_control%qs_control%eps_ppnl
1840 IF (
ASSOCIATED(sap_ppnl))
THEN
1841 IF (calculate_forces .AND. debug_forces) fodeb(1:3) = force(1)%gth_ppnl(1:3, 1)
1842 IF (debug_stress .AND. use_virial) stdeb = virial%pv_ppnl
1843 CALL build_core_ppnl(scrm, matrix_p, force, &
1844 virial, calculate_forces, use_virial, nder, &
1845 qs_kind_set, atomic_kind_set, particle_set, &
1846 sab_orb, sap_ppnl, eps_ppnl, &
1847 nimages, cell_to_index,
"HARRIS")
1848 IF (calculate_forces .AND. debug_forces)
THEN
1849 fodeb(1:3) = force(1)%gth_ppnl(1:3, 1) - fodeb(1:3)
1850 CALL para_env%sum(fodeb)
1851 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Pout*dH_PPNL", fodeb
1853 IF (debug_stress .AND. use_virial)
THEN
1854 stdeb = fconv*(virial%pv_ppnl - stdeb)
1855 CALL para_env%sum(stdeb)
1856 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1857 'STRESS| Pout*dH_PPNL', one_third_sum_diag(stdeb), det_3x3(stdeb)
1862 ec_env%efield_nuclear = 0.0_dp
1863 IF (calculate_forces .AND. debug_forces) fodeb(1:3) = force(1)%efield(1:3, 1)
1864 CALL ec_efield_local_operator(qs_env, ec_env, calculate_forces)
1865 IF (calculate_forces .AND. debug_forces)
THEN
1866 fodeb(1:3) = force(1)%efield(1:3, 1) - fodeb(1:3)
1867 CALL para_env%sum(fodeb)
1868 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Pout*dEfield", fodeb
1870 IF (debug_stress .AND. use_virial)
THEN
1871 stdeb = fconv*(virial%pv_virial - sttot)
1872 CALL para_env%sum(stdeb)
1873 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1874 'STRESS| Stress Pout*dHcore ', one_third_sum_diag(stdeb), det_3x3(stdeb)
1875 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))")
' '
1879 CALL dbcsr_deallocate_matrix_set(scrm)
1881 CALL timestop(handle)
1883 END SUBROUTINE ec_build_core_hamiltonian_force
1894 SUBROUTINE ec_build_ks_matrix_force(qs_env, ec_env)
1895 TYPE(qs_environment_type),
POINTER :: qs_env
1896 TYPE(energy_correction_type),
POINTER :: ec_env
1898 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ec_build_ks_matrix_force'
1900 CHARACTER(LEN=default_string_length) :: unit_string
1901 INTEGER :: handle, i, iounit, ispin, natom, nspins
1902 LOGICAL :: debug_forces, debug_stress, do_ec_hfx, &
1904 REAL(dp) :: dehartree, dummy_real, dummy_real2(2), &
1905 eexc, ehartree, eovrl, exc, fconv
1906 REAL(dp),
ALLOCATABLE,
DIMENSION(:, :) :: ftot
1907 REAL(dp),
DIMENSION(3) :: fodeb
1908 REAL(kind=dp),
DIMENSION(3, 3) :: h_stress, pv_loc, stdeb, sttot
1909 TYPE(atomic_kind_type),
DIMENSION(:),
POINTER :: atomic_kind_set
1910 TYPE(cell_type),
POINTER :: cell
1911 TYPE(cp_logger_type),
POINTER :: logger
1912 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_ks, scrm
1913 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_p, matrix_s
1914 TYPE(dft_control_type),
POINTER :: dft_control
1915 TYPE(mp_para_env_type),
POINTER :: para_env
1916 TYPE(neighbor_list_set_p_type),
DIMENSION(:), &
1918 TYPE(pw_c1d_gs_type) :: rho_tot_gspace, rhodn_tot_gspace, &
1920 TYPE(pw_c1d_gs_type),
DIMENSION(:),
POINTER :: rho_g, rhoout_g
1921 TYPE(pw_c1d_gs_type),
POINTER :: rho_core
1922 TYPE(pw_env_type),
POINTER :: pw_env
1923 TYPE(pw_poisson_type),
POINTER :: poisson_env
1924 TYPE(pw_pool_type),
POINTER :: auxbas_pw_pool
1925 TYPE(pw_r3d_rs_type) :: dv_hartree_rspace, v_hartree_rspace, &
1927 TYPE(pw_r3d_rs_type),
DIMENSION(:),
POINTER :: rho_r, rhoout_r, tau_r, tauout_r, &
1928 v_rspace, v_tau_rspace, v_xc, v_xc_tau
1929 TYPE(qs_force_type),
DIMENSION(:),
POINTER :: force
1930 TYPE(qs_ks_env_type),
POINTER :: ks_env
1931 TYPE(qs_rho_type),
POINTER :: rho
1932 TYPE(section_vals_type),
POINTER :: ec_hfx_sections, xc_section
1933 TYPE(virial_type),
POINTER :: virial
1935 CALL timeset(routinen, handle)
1937 debug_forces = ec_env%debug_forces
1938 debug_stress = ec_env%debug_stress
1940 logger => cp_get_default_logger()
1941 IF (logger%para_env%is_source())
THEN
1942 iounit = cp_logger_get_default_unit_nr(logger, local=.true.)
1948 NULLIFY (atomic_kind_set, cell, dft_control, force, ks_env, &
1949 matrix_ks, matrix_p, matrix_s, para_env, rho, rho_core, &
1950 rho_g, rho_r, sab_orb, tau_r, virial)
1951 CALL get_qs_env(qs_env=qs_env, &
1953 dft_control=dft_control, &
1956 matrix_ks=matrix_ks, &
1957 para_env=para_env, &
1962 nspins = dft_control%nspins
1963 use_virial = virial%pv_availability .AND. (.NOT. virial%pv_numer)
1967 fconv = cp_unit_from_cp2k(1.0_dp/cell%deth, trim(unit_string))
1969 IF (debug_stress .AND. use_virial)
THEN
1970 sttot = virial%pv_virial
1974 CALL get_qs_env(qs_env=qs_env, pw_env=pw_env)
1975 cpassert(
ASSOCIATED(pw_env))
1977 NULLIFY (auxbas_pw_pool, poisson_env)
1979 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool, &
1980 poisson_env=poisson_env)
1983 CALL auxbas_pw_pool%create_pw(v_hartree_gspace)
1984 CALL auxbas_pw_pool%create_pw(rhodn_tot_gspace)
1985 CALL auxbas_pw_pool%create_pw(v_hartree_rspace)
1987 CALL pw_transfer(ec_env%vh_rspace, v_hartree_rspace)
1992 CALL qs_rho_get(rho, rho_r=rho_r, rho_g=rho_g, tau_r=tau_r)
1993 NULLIFY (rhoout_r, rhoout_g)
1994 ALLOCATE (rhoout_r(nspins), rhoout_g(nspins))
1995 DO ispin = 1, nspins
1996 CALL auxbas_pw_pool%create_pw(rhoout_r(ispin))
1997 CALL auxbas_pw_pool%create_pw(rhoout_g(ispin))
1999 CALL auxbas_pw_pool%create_pw(dv_hartree_rspace)
2000 CALL auxbas_pw_pool%create_pw(vtot_rspace)
2002 CALL pw_zero(rhodn_tot_gspace)
2003 DO ispin = 1, nspins
2004 CALL calculate_rho_elec(ks_env=ks_env, matrix_p=ec_env%matrix_p(ispin, 1)%matrix, &
2005 rho=rhoout_r(ispin), &
2006 rho_gspace=rhoout_g(ispin), &
2007 basis_type=
"HARRIS", &
2008 task_list_external=ec_env%task_list)
2012 ALLOCATE (ec_env%rhoout_r(nspins))
2013 DO ispin = 1, nspins
2014 CALL auxbas_pw_pool%create_pw(ec_env%rhoout_r(ispin))
2015 CALL pw_copy(rhoout_r(ispin), ec_env%rhoout_r(ispin))
2019 IF (dft_control%use_kinetic_energy_density)
THEN
2021 TYPE(pw_c1d_gs_type) :: tauout_g
2022 ALLOCATE (tauout_r(nspins))
2023 DO ispin = 1, nspins
2024 CALL auxbas_pw_pool%create_pw(tauout_r(ispin))
2026 CALL auxbas_pw_pool%create_pw(tauout_g)
2028 DO ispin = 1, nspins
2029 CALL calculate_rho_elec(ks_env=ks_env, matrix_p=ec_env%matrix_p(ispin, 1)%matrix, &
2030 rho=tauout_r(ispin), &
2031 rho_gspace=tauout_g, &
2032 compute_tau=.true., &
2033 basis_type=
"HARRIS", &
2034 task_list_external=ec_env%task_list)
2037 CALL auxbas_pw_pool%give_back_pw(tauout_g)
2041 IF (use_virial)
THEN
2044 CALL auxbas_pw_pool%create_pw(rho_tot_gspace)
2047 CALL calc_rho_tot_gspace(rho_tot_gspace, qs_env, rho)
2050 CALL get_qs_env(qs_env=qs_env, rho_core=rho_core)
2051 CALL pw_copy(rho_core, rhodn_tot_gspace)
2052 DO ispin = 1, dft_control%nspins
2053 CALL pw_axpy(rhoout_g(ispin), rhodn_tot_gspace)
2057 h_stress(:, :) = 0.0_dp
2058 CALL pw_poisson_solve(poisson_env, &
2059 density=rho_tot_gspace, &
2060 ehartree=ehartree, &
2061 vhartree=v_hartree_gspace, &
2062 h_stress=h_stress, &
2063 aux_density=rhodn_tot_gspace)
2065 virial%pv_ehartree = virial%pv_ehartree + h_stress/real(para_env%num_pe, dp)
2066 virial%pv_virial = virial%pv_virial + h_stress/real(para_env%num_pe, dp)
2068 IF (debug_stress)
THEN
2069 stdeb = fconv*(h_stress/real(para_env%num_pe, dp))
2070 CALL para_env%sum(stdeb)
2071 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2072 'STRESS| GREEN 1st v_H[n_in]*n_out ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2076 virial%pv_calculate = .true.
2078 NULLIFY (v_rspace, v_tau_rspace)
2079 CALL qs_vxc_create(ks_env=ks_env, rho_struct=rho, xc_section=ec_env%xc_section, &
2080 vxc_rho=v_rspace, vxc_tau=v_tau_rspace, exc=exc, just_energy=.false.)
2083 virial%pv_exc = virial%pv_exc - virial%pv_xc
2084 virial%pv_virial = virial%pv_virial - virial%pv_xc
2086 IF (debug_stress)
THEN
2087 stdeb = -1.0_dp*fconv*virial%pv_xc
2088 CALL para_env%sum(stdeb)
2089 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2090 'STRESS| GGA 1st E_xc[Pin] ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2093 IF (
ASSOCIATED(v_rspace))
THEN
2094 DO ispin = 1, nspins
2095 CALL auxbas_pw_pool%give_back_pw(v_rspace(ispin))
2097 DEALLOCATE (v_rspace)
2099 IF (
ASSOCIATED(v_tau_rspace))
THEN
2100 DO ispin = 1, nspins
2101 CALL auxbas_pw_pool%give_back_pw(v_tau_rspace(ispin))
2103 DEALLOCATE (v_tau_rspace)
2105 CALL pw_zero(rhodn_tot_gspace)
2110 DO ispin = 1, nspins
2111 CALL pw_axpy(rho_r(ispin), rhoout_r(ispin), -1.0_dp)
2112 CALL pw_axpy(rho_g(ispin), rhoout_g(ispin), -1.0_dp)
2113 CALL pw_axpy(rhoout_g(ispin), rhodn_tot_gspace)
2114 IF (dft_control%use_kinetic_energy_density)
CALL pw_axpy(tau_r(ispin), tauout_r(ispin), -1.0_dp)
2118 IF (use_virial)
THEN
2121 h_stress(:, :) = 0.0_dp
2122 CALL pw_poisson_solve(poisson_env, &
2123 density=rhodn_tot_gspace, &
2124 ehartree=dehartree, &
2125 vhartree=v_hartree_gspace, &
2126 h_stress=h_stress, &
2127 aux_density=rho_tot_gspace)
2129 CALL auxbas_pw_pool%give_back_pw(rho_tot_gspace)
2131 virial%pv_ehartree = virial%pv_ehartree + h_stress/real(para_env%num_pe, dp)
2132 virial%pv_virial = virial%pv_virial + h_stress/real(para_env%num_pe, dp)
2134 IF (debug_stress)
THEN
2135 stdeb = fconv*(h_stress/real(para_env%num_pe, dp))
2136 CALL para_env%sum(stdeb)
2137 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2138 'STRESS| GREEN 2nd V_H[dP]*n_in ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2143 CALL pw_poisson_solve(poisson_env, rhodn_tot_gspace, dehartree, &
2147 CALL pw_transfer(v_hartree_gspace, dv_hartree_rspace)
2148 CALL pw_scale(dv_hartree_rspace, dv_hartree_rspace%pw_grid%dvol)
2151 CALL pw_transfer(v_hartree_rspace, vtot_rspace)
2152 CALL pw_axpy(dv_hartree_rspace, vtot_rspace)
2153 IF (debug_forces) fodeb(1:3) = force(1)%rho_core(1:3, 1)
2154 IF (debug_stress .AND. use_virial) stdeb = virial%pv_ehartree
2155 CALL integrate_v_core_rspace(vtot_rspace, qs_env)
2156 IF (debug_forces)
THEN
2157 fodeb(1:3) = force(1)%rho_core(1:3, 1) - fodeb(1:3)
2158 CALL para_env%sum(fodeb)
2159 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Vtot*dncore", fodeb
2161 IF (debug_stress .AND. use_virial)
THEN
2162 stdeb = fconv*(virial%pv_ehartree - stdeb)
2163 CALL para_env%sum(stdeb)
2164 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2165 'STRESS| Vtot*dncore', one_third_sum_diag(stdeb), det_3x3(stdeb)
2171 xc_section => ec_env%xc_section
2173 IF (use_virial) virial%pv_xc = 0.0_dp
2174 NULLIFY (v_xc, v_xc_tau)
2175 CALL create_kernel(qs_env, &
2182 xc_section=xc_section, &
2183 compute_virial=use_virial, &
2184 virial_xc=virial%pv_xc)
2186 IF (use_virial)
THEN
2188 virial%pv_exc = virial%pv_exc + virial%pv_xc
2189 virial%pv_virial = virial%pv_virial + virial%pv_xc
2191 IF (debug_stress .AND. use_virial)
THEN
2192 stdeb = 1.0_dp*fconv*virial%pv_xc
2193 CALL para_env%sum(stdeb)
2194 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2195 'STRESS| GGA 2nd f_Hxc[dP]*Pin ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2198 CALL get_qs_env(qs_env=qs_env, rho=rho, matrix_s_kp=matrix_s)
2199 NULLIFY (ec_env%matrix_hz)
2200 CALL dbcsr_allocate_matrix_set(ec_env%matrix_hz, nspins)
2201 DO ispin = 1, nspins
2202 ALLOCATE (ec_env%matrix_hz(ispin)%matrix)
2203 CALL dbcsr_create(ec_env%matrix_hz(ispin)%matrix, template=matrix_s(1, 1)%matrix)
2204 CALL dbcsr_copy(ec_env%matrix_hz(ispin)%matrix, matrix_s(1, 1)%matrix)
2205 CALL dbcsr_set(ec_env%matrix_hz(ispin)%matrix, 0.0_dp)
2207 CALL qs_rho_get(rho, rho_ao_kp=matrix_p)
2209 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
2210 IF (debug_stress .AND. use_virial) stdeb = virial%pv_virial
2213 IF (use_virial)
THEN
2214 pv_loc = virial%pv_virial
2217 DO ispin = 1, nspins
2218 CALL pw_scale(v_xc(ispin), v_xc(ispin)%pw_grid%dvol)
2219 CALL pw_axpy(dv_hartree_rspace, v_xc(ispin))
2220 CALL integrate_v_rspace(v_rspace=v_xc(ispin), &
2221 hmat=ec_env%matrix_hz(ispin), &
2222 pmat=matrix_p(ispin, 1), &
2224 calculate_forces=.true.)
2227 IF (debug_forces)
THEN
2228 fodeb(1:3) = force(1)%rho_elec(1:3, 1) - fodeb(1:3)
2229 CALL para_env%sum(fodeb)
2230 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Pin*dKdrho", fodeb
2232 IF (debug_stress .AND. use_virial)
THEN
2233 stdeb = fconv*(virial%pv_virial - stdeb)
2234 CALL para_env%sum(stdeb)
2235 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2236 'STRESS| INT 2nd f_Hxc[dP]*Pin ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2239 IF (
ASSOCIATED(v_xc_tau))
THEN
2240 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
2241 IF (debug_stress .AND. use_virial) stdeb = virial%pv_virial
2243 DO ispin = 1, nspins
2244 CALL pw_scale(v_xc_tau(ispin), v_xc_tau(ispin)%pw_grid%dvol)
2245 CALL integrate_v_rspace(v_rspace=v_xc_tau(ispin), &
2246 hmat=ec_env%matrix_hz(ispin), &
2247 pmat=matrix_p(ispin, 1), &
2249 compute_tau=.true., &
2250 calculate_forces=.true.)
2253 IF (debug_forces)
THEN
2254 fodeb(1:3) = force(1)%rho_elec(1:3, 1) - fodeb(1:3)
2255 CALL para_env%sum(fodeb)
2256 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Pin*dKtaudtau", fodeb
2258 IF (debug_stress .AND. use_virial)
THEN
2259 stdeb = fconv*(virial%pv_virial - stdeb)
2260 CALL para_env%sum(stdeb)
2261 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2262 'STRESS| INT 2nd f_xctau[dP]*Pin ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2266 IF (use_virial)
THEN
2267 virial%pv_ehartree = virial%pv_ehartree + (virial%pv_virial - pv_loc)
2272 CALL dbcsr_allocate_matrix_set(scrm, nspins)
2273 DO ispin = 1, nspins
2274 ALLOCATE (scrm(ispin)%matrix)
2275 CALL dbcsr_create(scrm(ispin)%matrix, template=ec_env%matrix_ks(ispin, 1)%matrix)
2276 CALL dbcsr_copy(scrm(ispin)%matrix, ec_env%matrix_ks(ispin, 1)%matrix)
2277 CALL dbcsr_set(scrm(ispin)%matrix, 0.0_dp)
2281 NULLIFY (v_rspace, v_tau_rspace)
2283 CALL qs_vxc_create(ks_env=ks_env, rho_struct=rho, xc_section=ec_env%xc_section, &
2284 vxc_rho=v_rspace, vxc_tau=v_tau_rspace, exc=eexc, just_energy=.false.)
2286 IF (use_virial)
THEN
2288 IF (
ASSOCIATED(v_rspace))
THEN
2289 DO ispin = 1, nspins
2291 eexc = eexc + pw_integral_ab(rhoout_r(ispin), v_rspace(ispin))
2294 IF (
ASSOCIATED(v_tau_rspace))
THEN
2295 DO ispin = 1, nspins
2297 eexc = eexc + pw_integral_ab(tauout_r(ispin), v_tau_rspace(ispin))
2302 IF (.NOT.
ASSOCIATED(v_rspace))
THEN
2303 ALLOCATE (v_rspace(nspins))
2304 DO ispin = 1, nspins
2305 CALL auxbas_pw_pool%create_pw(v_rspace(ispin))
2306 CALL pw_zero(v_rspace(ispin))
2312 IF (use_virial)
THEN
2313 pv_loc = virial%pv_virial
2316 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
2317 IF (debug_stress .AND. use_virial) stdeb = virial%pv_virial
2318 DO ispin = 1, nspins
2320 CALL pw_scale(v_rspace(ispin), v_rspace(ispin)%pw_grid%dvol)
2321 CALL pw_axpy(v_hartree_rspace, v_rspace(ispin))
2323 CALL integrate_v_rspace(v_rspace=v_rspace(ispin), &
2325 pmat=ec_env%matrix_p(ispin, 1), &
2327 calculate_forces=.true., &
2328 basis_type=
"HARRIS", &
2329 task_list_external=ec_env%task_list)
2332 IF (debug_forces)
THEN
2333 fodeb(1:3) = force(1)%rho_elec(1:3, 1) - fodeb(1:3)
2334 CALL para_env%sum(fodeb)
2335 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Pout*dVhxc ", fodeb
2337 IF (debug_stress .AND. use_virial)
THEN
2338 stdeb = fconv*(virial%pv_virial - stdeb)
2339 CALL para_env%sum(stdeb)
2340 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2341 'STRESS| INT Pout*dVhxc ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2345 IF (use_virial)
THEN
2346 virial%pv_ehartree = virial%pv_ehartree + (virial%pv_virial - pv_loc)
2349 IF (
ASSOCIATED(v_tau_rspace))
THEN
2350 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
2351 DO ispin = 1, nspins
2353 CALL pw_scale(v_tau_rspace(ispin), v_tau_rspace(ispin)%pw_grid%dvol)
2354 CALL integrate_v_rspace(v_rspace=v_tau_rspace(ispin), &
2356 pmat=ec_env%matrix_p(ispin, 1), &
2358 calculate_forces=.true., &
2359 compute_tau=.true., &
2360 basis_type=
"HARRIS", &
2361 task_list_external=ec_env%task_list)
2363 IF (debug_forces)
THEN
2364 fodeb(1:3) = force(1)%rho_elec(1:3, 1) - fodeb(1:3)
2365 CALL para_env%sum(fodeb)
2366 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Pout*dVhxc_tau ", fodeb
2375 ec_hfx_sections => section_vals_get_subs_vals(qs_env%input,
"DFT%ENERGY_CORRECTION%XC%HF")
2376 CALL section_vals_get(ec_hfx_sections, explicit=do_ec_hfx)
2380 IF (debug_forces) fodeb(1:3) = force(1)%fock_4c(1:3, 1)
2381 IF (use_virial) virial%pv_fock_4c = 0.0_dp
2383 CALL calculate_exx(qs_env=qs_env, &
2385 hfx_sections=ec_hfx_sections, &
2386 x_data=ec_env%x_data, &
2388 do_admm=ec_env%do_ec_admm, &
2389 calc_forces=.true., &
2390 reuse_hfx=ec_env%reuse_hfx, &
2391 do_im_time=.false., &
2392 e_ex_from_gw=dummy_real, &
2393 e_admm_from_gw=dummy_real2, &
2396 IF (use_virial)
THEN
2397 virial%pv_exx = virial%pv_exx - virial%pv_fock_4c
2398 virial%pv_virial = virial%pv_virial - virial%pv_fock_4c
2399 virial%pv_calculate = .false.
2401 IF (debug_forces)
THEN
2402 fodeb(1:3) = force(1)%fock_4c(1:3, 1) - fodeb(1:3)
2403 CALL para_env%sum(fodeb)
2404 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Pout*hfx ", fodeb
2406 IF (debug_stress .AND. use_virial)
THEN
2407 stdeb = -1.0_dp*fconv*virial%pv_fock_4c
2408 CALL para_env%sum(stdeb)
2409 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2410 'STRESS| Pout*hfx ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2418 CALL dbcsr_deallocate_matrix_set(scrm)
2421 CALL auxbas_pw_pool%give_back_pw(v_hartree_rspace)
2422 DO ispin = 1, nspins
2423 CALL auxbas_pw_pool%give_back_pw(v_rspace(ispin))
2424 IF (
ASSOCIATED(v_tau_rspace))
THEN
2425 CALL auxbas_pw_pool%give_back_pw(v_tau_rspace(ispin))
2428 IF (
ASSOCIATED(v_tau_rspace))
DEALLOCATE (v_tau_rspace)
2431 IF (debug_forces) fodeb(1:3) = force(1)%core_overlap(1:3, 1)
2432 IF (debug_stress .AND. use_virial) stdeb = virial%pv_ecore_overlap
2433 CALL calculate_ecore_overlap(qs_env, para_env, .true., e_overlap_core=eovrl)
2434 IF (debug_forces)
THEN
2435 fodeb(1:3) = force(1)%core_overlap(1:3, 1) - fodeb(1:3)
2436 CALL para_env%sum(fodeb)
2437 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: CoreOverlap", fodeb
2439 IF (debug_stress .AND. use_virial)
THEN
2440 stdeb = fconv*(stdeb - virial%pv_ecore_overlap)
2441 CALL para_env%sum(stdeb)
2442 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2443 'STRESS| CoreOverlap ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2446 IF (debug_forces)
THEN
2447 CALL get_qs_env(qs_env, natom=natom, atomic_kind_set=atomic_kind_set)
2448 ALLOCATE (ftot(3, natom))
2449 CALL total_qs_force(ftot, force, atomic_kind_set)
2450 fodeb(1:3) = ftot(1:3, 1)
2452 CALL para_env%sum(fodeb)
2453 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Force Explicit", fodeb
2456 DEALLOCATE (v_rspace)
2458 CALL auxbas_pw_pool%give_back_pw(dv_hartree_rspace)
2459 CALL auxbas_pw_pool%give_back_pw(vtot_rspace)
2460 DO ispin = 1, nspins
2461 CALL auxbas_pw_pool%give_back_pw(rhoout_r(ispin))
2462 CALL auxbas_pw_pool%give_back_pw(rhoout_g(ispin))
2463 CALL auxbas_pw_pool%give_back_pw(v_xc(ispin))
2465 DEALLOCATE (rhoout_r, rhoout_g, v_xc)
2466 IF (
ASSOCIATED(tauout_r))
THEN
2467 DO ispin = 1, nspins
2468 CALL auxbas_pw_pool%give_back_pw(tauout_r(ispin))
2470 DEALLOCATE (tauout_r)
2472 IF (
ASSOCIATED(v_xc_tau))
THEN
2473 DO ispin = 1, nspins
2474 CALL auxbas_pw_pool%give_back_pw(v_xc_tau(ispin))
2476 DEALLOCATE (v_xc_tau)
2478 CALL auxbas_pw_pool%give_back_pw(v_hartree_gspace)
2479 CALL auxbas_pw_pool%give_back_pw(rhodn_tot_gspace)
2483 IF (use_virial)
THEN
2484 IF (qs_env%energy_correction)
THEN
2485 ec_env%ehartree = ehartree + dehartree
2486 ec_env%exc = exc + eexc
2490 IF (debug_stress .AND. use_virial)
THEN
2492 stdeb = -1.0_dp*fconv*ehartree
2493 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2494 'STRESS| VOL 1st v_H[n_in]*n_out', one_third_sum_diag(stdeb), det_3x3(stdeb)
2496 stdeb = -1.0_dp*fconv*exc
2497 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2498 'STRESS| VOL 1st E_XC[n_in]', one_third_sum_diag(stdeb), det_3x3(stdeb)
2500 stdeb = -1.0_dp*fconv*dehartree
2501 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2502 'STRESS| VOL 2nd v_H[dP]*n_in', one_third_sum_diag(stdeb), det_3x3(stdeb)
2504 stdeb = -1.0_dp*fconv*eexc
2505 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2506 'STRESS| VOL 2nd v_XC[n_in]*dP', one_third_sum_diag(stdeb), det_3x3(stdeb)
2511 TYPE(virial_type) :: virdeb
2514 CALL para_env%sum(virdeb%pv_overlap)
2515 CALL para_env%sum(virdeb%pv_ekinetic)
2516 CALL para_env%sum(virdeb%pv_ppl)
2517 CALL para_env%sum(virdeb%pv_ppnl)
2518 CALL para_env%sum(virdeb%pv_ecore_overlap)
2519 CALL para_env%sum(virdeb%pv_ehartree)
2520 CALL para_env%sum(virdeb%pv_exc)
2521 CALL para_env%sum(virdeb%pv_exx)
2522 CALL para_env%sum(virdeb%pv_vdw)
2523 CALL para_env%sum(virdeb%pv_mp2)
2524 CALL para_env%sum(virdeb%pv_nlcc)
2525 CALL para_env%sum(virdeb%pv_gapw)
2526 CALL para_env%sum(virdeb%pv_lrigpw)
2527 CALL para_env%sum(virdeb%pv_virial)
2528 CALL symmetrize_virial(virdeb)
2532 virdeb%pv_ehartree(i, i) = virdeb%pv_ehartree(i, i) - 2.0_dp*(ehartree + dehartree)
2533 virdeb%pv_virial(i, i) = virdeb%pv_virial(i, i) - exc - eexc &
2534 - 2.0_dp*(ehartree + dehartree)
2535 virdeb%pv_exc(i, i) = virdeb%pv_exc(i, i) - exc - eexc
2541 CALL para_env%sum(sttot)
2542 stdeb = fconv*(virdeb%pv_virial - sttot)
2543 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2544 'STRESS| Explicit electronic stress ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2546 stdeb = fconv*(virdeb%pv_virial)
2547 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2548 'STRESS| Explicit total stress ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2550 CALL write_stress_tensor_components(virdeb, iounit, cell, unit_string)
2551 CALL write_stress_tensor(virdeb%pv_virial, iounit, cell, unit_string, .false.)
2556 CALL timestop(handle)
2558 END SUBROUTINE ec_build_ks_matrix_force
2568 SUBROUTINE ec_ks_solver(qs_env, ec_env)
2570 TYPE(qs_environment_type),
POINTER :: qs_env
2571 TYPE(energy_correction_type),
POINTER :: ec_env
2573 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ec_ks_solver'
2575 CHARACTER(LEN=default_string_length) :: headline
2576 INTEGER :: handle, ispin, nspins
2577 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: ksmat, pmat, smat, wmat
2578 TYPE(dft_control_type),
POINTER :: dft_control
2580 CALL timeset(routinen, handle)
2582 CALL get_qs_env(qs_env=qs_env, dft_control=dft_control)
2583 nspins = dft_control%nspins
2586 IF (.NOT.
ASSOCIATED(ec_env%matrix_p))
THEN
2587 headline =
"DENSITY MATRIX"
2588 CALL dbcsr_allocate_matrix_set(ec_env%matrix_p, nspins, 1)
2589 DO ispin = 1, nspins
2590 ALLOCATE (ec_env%matrix_p(ispin, 1)%matrix)
2591 CALL dbcsr_create(ec_env%matrix_p(ispin, 1)%matrix, name=trim(headline), &
2592 template=ec_env%matrix_s(1, 1)%matrix)
2593 CALL cp_dbcsr_alloc_block_from_nbl(ec_env%matrix_p(ispin, 1)%matrix, ec_env%sab_orb)
2597 IF (.NOT.
ASSOCIATED(ec_env%matrix_w))
THEN
2598 headline =
"ENERGY WEIGHTED DENSITY MATRIX"
2599 CALL dbcsr_allocate_matrix_set(ec_env%matrix_w, nspins, 1)
2600 DO ispin = 1, nspins
2601 ALLOCATE (ec_env%matrix_w(ispin, 1)%matrix)
2602 CALL dbcsr_create(ec_env%matrix_w(ispin, 1)%matrix, name=trim(headline), &
2603 template=ec_env%matrix_s(1, 1)%matrix)
2604 CALL cp_dbcsr_alloc_block_from_nbl(ec_env%matrix_w(ispin, 1)%matrix, ec_env%sab_orb)
2608 IF (ec_env%mao)
THEN
2609 CALL mao_create_matrices(ec_env, ksmat, smat, pmat, wmat)
2611 ksmat => ec_env%matrix_ks
2612 smat => ec_env%matrix_s
2613 pmat => ec_env%matrix_p
2614 wmat => ec_env%matrix_w
2617 SELECT CASE (ec_env%ks_solver)
2618 CASE (ec_diagonalization)
2619 CALL ec_diag_solver(qs_env, ksmat, smat, pmat, wmat)
2621 CALL ec_ot_diag_solver(qs_env, ec_env, ksmat, smat, pmat, wmat)
2622 CASE (ec_matrix_sign, ec_matrix_trs4, ec_matrix_tc2)
2623 CALL ec_ls_init(qs_env, ksmat, smat)
2624 CALL ec_ls_solver(qs_env, pmat, wmat, ec_ls_method=ec_env%ks_solver)
2629 IF (ec_env%mao)
THEN
2630 CALL mao_release_matrices(ec_env, ksmat, smat, pmat, wmat)
2633 CALL timestop(handle)
2635 END SUBROUTINE ec_ks_solver
2648 SUBROUTINE mao_create_matrices(ec_env, ksmat, smat, pmat, wmat)
2650 TYPE(energy_correction_type),
POINTER :: ec_env
2651 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: ksmat, smat, pmat, wmat
2653 CHARACTER(LEN=*),
PARAMETER :: routinen =
'mao_create_matrices'
2655 INTEGER :: handle, ispin, nspins
2656 INTEGER,
DIMENSION(:),
POINTER :: col_blk_sizes
2657 TYPE(dbcsr_distribution_type) :: dbcsr_dist
2658 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: mao_coef
2659 TYPE(dbcsr_type) :: cgmat
2661 CALL timeset(routinen, handle)
2663 mao_coef => ec_env%mao_coef
2665 NULLIFY (ksmat, smat, pmat, wmat)
2666 nspins =
SIZE(ec_env%matrix_ks, 1)
2667 CALL dbcsr_get_info(mao_coef(1)%matrix, col_blk_size=col_blk_sizes, distribution=dbcsr_dist)
2668 CALL dbcsr_allocate_matrix_set(ksmat, nspins, 1)
2669 CALL dbcsr_allocate_matrix_set(smat, nspins, 1)
2670 DO ispin = 1, nspins
2671 ALLOCATE (ksmat(ispin, 1)%matrix)
2672 CALL dbcsr_create(ksmat(ispin, 1)%matrix, dist=dbcsr_dist, name=
"MAO KS mat", &
2673 matrix_type=dbcsr_type_symmetric, row_blk_size=col_blk_sizes, &
2674 col_blk_size=col_blk_sizes)
2675 ALLOCATE (smat(ispin, 1)%matrix)
2676 CALL dbcsr_create(smat(ispin, 1)%matrix, dist=dbcsr_dist, name=
"MAO S mat", &
2677 matrix_type=dbcsr_type_symmetric, row_blk_size=col_blk_sizes, &
2678 col_blk_size=col_blk_sizes)
2681 CALL dbcsr_create(cgmat, name=
"TEMP matrix", template=mao_coef(1)%matrix)
2682 DO ispin = 1, nspins
2683 CALL dbcsr_multiply(
"N",
"N", 1.0_dp, ec_env%matrix_s(1, 1)%matrix, mao_coef(ispin)%matrix, &
2685 CALL dbcsr_multiply(
"T",
"N", 1.0_dp, mao_coef(ispin)%matrix, cgmat, 0.0_dp, smat(ispin, 1)%matrix)
2686 CALL dbcsr_multiply(
"N",
"N", 1.0_dp, ec_env%matrix_ks(1, 1)%matrix, mao_coef(ispin)%matrix, &
2688 CALL dbcsr_multiply(
"T",
"N", 1.0_dp, mao_coef(ispin)%matrix, cgmat, 0.0_dp, ksmat(ispin, 1)%matrix)
2690 CALL dbcsr_release(cgmat)
2692 CALL dbcsr_allocate_matrix_set(pmat, nspins, 1)
2693 DO ispin = 1, nspins
2694 ALLOCATE (pmat(ispin, 1)%matrix)
2695 CALL dbcsr_create(pmat(ispin, 1)%matrix, template=smat(1, 1)%matrix, name=
"MAO P mat")
2696 CALL cp_dbcsr_alloc_block_from_nbl(pmat(ispin, 1)%matrix, ec_env%sab_orb)
2699 CALL dbcsr_allocate_matrix_set(wmat, nspins, 1)
2700 DO ispin = 1, nspins
2701 ALLOCATE (wmat(ispin, 1)%matrix)
2702 CALL dbcsr_create(wmat(ispin, 1)%matrix, template=smat(1, 1)%matrix, name=
"MAO W mat")
2703 CALL cp_dbcsr_alloc_block_from_nbl(wmat(ispin, 1)%matrix, ec_env%sab_orb)
2706 CALL timestop(handle)
2708 END SUBROUTINE mao_create_matrices
2721 SUBROUTINE mao_release_matrices(ec_env, ksmat, smat, pmat, wmat)
2723 TYPE(energy_correction_type),
POINTER :: ec_env
2724 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: ksmat, smat, pmat, wmat
2726 CHARACTER(LEN=*),
PARAMETER :: routinen =
'mao_release_matrices'
2728 INTEGER :: handle, ispin, nspins
2729 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: mao_coef
2730 TYPE(dbcsr_type) :: cgmat
2732 CALL timeset(routinen, handle)
2734 mao_coef => ec_env%mao_coef
2735 nspins =
SIZE(mao_coef, 1)
2738 CALL dbcsr_create(cgmat, name=
"TEMP matrix", template=mao_coef(1)%matrix)
2739 DO ispin = 1, nspins
2740 CALL dbcsr_multiply(
"N",
"N", 1.0_dp, mao_coef(ispin)%matrix, pmat(ispin, 1)%matrix, 0.0_dp, cgmat)
2741 CALL dbcsr_multiply(
"N",
"T", 1.0_dp, mao_coef(ispin)%matrix, cgmat, 0.0_dp, &
2742 ec_env%matrix_p(ispin, 1)%matrix, retain_sparsity=.true.)
2743 CALL dbcsr_multiply(
"N",
"N", 1.0_dp, mao_coef(ispin)%matrix, wmat(ispin, 1)%matrix, 0.0_dp, cgmat)
2744 CALL dbcsr_multiply(
"N",
"T", 1.0_dp, mao_coef(ispin)%matrix, cgmat, 0.0_dp, &
2745 ec_env%matrix_w(ispin, 1)%matrix, retain_sparsity=.true.)
2747 CALL dbcsr_release(cgmat)
2749 CALL dbcsr_deallocate_matrix_set(ksmat)
2750 CALL dbcsr_deallocate_matrix_set(smat)
2751 CALL dbcsr_deallocate_matrix_set(pmat)
2752 CALL dbcsr_deallocate_matrix_set(wmat)
2754 CALL timestop(handle)
2756 END SUBROUTINE mao_release_matrices
2769 SUBROUTINE ec_diag_solver(qs_env, matrix_ks, matrix_s, matrix_p, matrix_w)
2771 TYPE(qs_environment_type),
POINTER :: qs_env
2772 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_ks, matrix_s, matrix_p, matrix_w
2774 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ec_diag_solver'
2776 INTEGER :: handle, ispin, nmo(2), nsize, nspins
2777 REAL(kind=dp) :: eps_filter, focc(2)
2778 REAL(kind=dp),
ALLOCATABLE,
DIMENSION(:) :: eigenvalues
2779 TYPE(cp_blacs_env_type),
POINTER :: blacs_env
2780 TYPE(cp_fm_struct_type),
POINTER :: fm_struct
2781 TYPE(cp_fm_type) :: fm_ks, fm_mo, fm_ortho
2782 TYPE(dbcsr_type),
POINTER :: buf1_dbcsr, buf2_dbcsr, buf3_dbcsr, &
2783 ortho_dbcsr, ref_matrix
2784 TYPE(dft_control_type),
POINTER :: dft_control
2785 TYPE(mp_para_env_type),
POINTER :: para_env
2787 CALL timeset(routinen, handle)
2789 NULLIFY (blacs_env, para_env)
2790 CALL get_qs_env(qs_env=qs_env, blacs_env=blacs_env, para_env=para_env)
2792 CALL get_qs_env(qs_env=qs_env, dft_control=dft_control)
2793 eps_filter = dft_control%qs_control%eps_filter_matrix
2794 nspins = dft_control%nspins
2797 CALL get_qs_env(qs_env=qs_env, nelectron_spin=nmo)
2799 IF (nspins == 1)
THEN
2804 CALL dbcsr_get_info(matrix_ks(1, 1)%matrix, nfullrows_total=nsize)
2805 ALLOCATE (eigenvalues(nsize))
2807 NULLIFY (fm_struct, ref_matrix)
2808 CALL cp_fm_struct_create(fm_struct, context=blacs_env, nrow_global=nsize, &
2809 ncol_global=nsize, para_env=para_env)
2810 CALL cp_fm_create(fm_ortho, fm_struct)
2811 CALL cp_fm_create(fm_ks, fm_struct)
2812 CALL cp_fm_create(fm_mo, fm_struct)
2813 CALL cp_fm_struct_release(fm_struct)
2816 ref_matrix => matrix_s(1, 1)%matrix
2817 NULLIFY (ortho_dbcsr, buf1_dbcsr, buf2_dbcsr, buf3_dbcsr)
2818 CALL dbcsr_init_p(ortho_dbcsr)
2819 CALL dbcsr_create(ortho_dbcsr, template=ref_matrix, &
2820 matrix_type=dbcsr_type_no_symmetry)
2821 CALL dbcsr_init_p(buf1_dbcsr)
2822 CALL dbcsr_create(buf1_dbcsr, template=ref_matrix, &
2823 matrix_type=dbcsr_type_no_symmetry)
2824 CALL dbcsr_init_p(buf2_dbcsr)
2825 CALL dbcsr_create(buf2_dbcsr, template=ref_matrix, &
2826 matrix_type=dbcsr_type_no_symmetry)
2827 CALL dbcsr_init_p(buf3_dbcsr)
2828 CALL dbcsr_create(buf3_dbcsr, template=ref_matrix, &
2829 matrix_type=dbcsr_type_no_symmetry)
2831 ref_matrix => matrix_s(1, 1)%matrix
2832 CALL copy_dbcsr_to_fm(ref_matrix, fm_ortho)
2833 CALL cp_fm_cholesky_decompose(fm_ortho)
2834 CALL cp_fm_triangular_invert(fm_ortho)
2835 CALL cp_fm_set_all(fm_ks, 0.0_dp)
2836 CALL cp_fm_to_fm_triangular(fm_ortho, fm_ks,
"U")
2837 CALL copy_fm_to_dbcsr(fm_ks, ortho_dbcsr)
2838 DO ispin = 1, nspins
2840 CALL dbcsr_desymmetrize(matrix_ks(ispin, 1)%matrix, buf1_dbcsr)
2841 CALL dbcsr_multiply(
"N",
"N", 1.0_dp, buf1_dbcsr, ortho_dbcsr, &
2842 0.0_dp, buf2_dbcsr, filter_eps=eps_filter)
2843 CALL dbcsr_multiply(
"T",
"N", 1.0_dp, ortho_dbcsr, buf2_dbcsr, &
2844 0.0_dp, buf1_dbcsr, filter_eps=eps_filter)
2846 CALL copy_dbcsr_to_fm(buf1_dbcsr, fm_ks)
2847 CALL choose_eigv_solver(fm_ks, fm_mo, eigenvalues)
2849 CALL copy_fm_to_dbcsr(fm_mo, buf1_dbcsr)
2850 CALL dbcsr_multiply(
"N",
"N", 1.0_dp, ortho_dbcsr, buf1_dbcsr, &
2851 0.0_dp, buf2_dbcsr, filter_eps=eps_filter)
2853 CALL dbcsr_set(matrix_p(ispin, 1)%matrix, 0.0_dp)
2854 CALL dbcsr_multiply(
"N",
"T", focc(ispin), buf2_dbcsr, buf2_dbcsr, &
2855 1.0_dp, matrix_p(ispin, 1)%matrix, &
2856 retain_sparsity=.true., last_k=nmo(ispin))
2859 CALL dbcsr_set(matrix_w(ispin, 1)%matrix, 0.0_dp)
2860 CALL cp_fm_column_scale(fm_mo, eigenvalues)
2861 CALL copy_fm_to_dbcsr(fm_mo, buf1_dbcsr)
2862 CALL dbcsr_multiply(
"N",
"N", 1.0_dp, ortho_dbcsr, buf1_dbcsr, &
2863 0.0_dp, buf3_dbcsr, filter_eps=eps_filter)
2864 CALL dbcsr_multiply(
"N",
"T", focc(ispin), buf2_dbcsr, buf3_dbcsr, &
2865 1.0_dp, matrix_w(ispin, 1)%matrix, &
2866 retain_sparsity=.true., last_k=nmo(ispin))
2869 CALL cp_fm_release(fm_ks)
2870 CALL cp_fm_release(fm_mo)
2871 CALL cp_fm_release(fm_ortho)
2872 CALL dbcsr_release(ortho_dbcsr)
2873 CALL dbcsr_release(buf1_dbcsr)
2874 CALL dbcsr_release(buf2_dbcsr)
2875 CALL dbcsr_release(buf3_dbcsr)
2876 DEALLOCATE (ortho_dbcsr, buf1_dbcsr, buf2_dbcsr, buf3_dbcsr)
2877 DEALLOCATE (eigenvalues)
2879 CALL timestop(handle)
2881 END SUBROUTINE ec_diag_solver
2889 SUBROUTINE ec_energy(ec_env, unit_nr)
2890 TYPE(energy_correction_type) :: ec_env
2891 INTEGER,
INTENT(IN) :: unit_nr
2893 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ec_energy'
2895 INTEGER :: handle, ispin, nspins
2896 REAL(kind=dp) :: eband, trace
2898 CALL timeset(routinen, handle)
2900 nspins =
SIZE(ec_env%matrix_p, 1)
2901 DO ispin = 1, nspins
2902 CALL dbcsr_dot(ec_env%matrix_p(ispin, 1)%matrix, ec_env%matrix_s(1, 1)%matrix, trace)
2903 IF (unit_nr > 0)
WRITE (unit_nr,
'(T3,A,T65,F16.10)')
'Tr[PS] ', trace
2907 SELECT CASE (ec_env%energy_functional)
2908 CASE (ec_functional_harris)
2912 DO ispin = 1, nspins
2913 CALL dbcsr_dot(ec_env%matrix_ks(ispin, 1)%matrix, ec_env%matrix_p(ispin, 1)%matrix, trace)
2914 eband = eband + trace
2916 ec_env%eband = eband + ec_env%efield_nuclear
2919 ec_env%etotal = ec_env%eband + ec_env%ehartree + ec_env%exc - ec_env%vhxc + ec_env%edispersion - ec_env%ex
2920 IF (unit_nr > 0)
THEN
2921 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Eband ", ec_env%eband
2922 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Ehartree ", ec_env%ehartree
2923 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Exc ", ec_env%exc
2924 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Ex ", ec_env%ex
2925 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Evhxc ", ec_env%vhxc
2926 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Edisp ", ec_env%edispersion
2927 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Etotal Harris Functional ", ec_env%etotal
2930 CASE (ec_functional_dc)
2933 CALL calculate_ptrace(ec_env%matrix_h, ec_env%matrix_p, ec_env%ecore,
SIZE(ec_env%matrix_p, 1))
2935 ec_env%ecore = ec_env%ecore + ec_env%efield_nuclear
2936 ec_env%etotal = ec_env%ecore + ec_env%ehartree + ec_env%exc + ec_env%edispersion &
2937 + ec_env%ex + ec_env%exc_aux_fit
2939 IF (unit_nr > 0)
THEN
2940 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Ecore ", ec_env%ecore
2941 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Ehartree ", ec_env%ehartree
2942 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Exc ", ec_env%exc
2943 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Ex ", ec_env%ex
2944 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Exc_aux_fit", ec_env%exc_aux_fit
2945 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Edisp ", ec_env%edispersion
2946 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Etotal Energy Functional ", ec_env%etotal
2949 CASE (ec_functional_ext)
2951 ec_env%etotal = ec_env%ex
2952 IF (unit_nr > 0)
THEN
2953 WRITE (unit_nr,
'(T3,A,T56,F25.15)')
"Etotal Energy Functional ", ec_env%etotal
2962 CALL timestop(handle)
2964 END SUBROUTINE ec_energy
2976 SUBROUTINE ec_build_neighborlist(qs_env, ec_env)
2977 TYPE(qs_environment_type),
POINTER :: qs_env
2978 TYPE(energy_correction_type),
POINTER :: ec_env
2980 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ec_build_neighborlist'
2982 INTEGER :: handle, ikind, nkind, zat
2983 LOGICAL :: all_potential_present, &
2984 gth_potential_present, &
2985 sgp_potential_present, &
2986 skip_load_balance_distributed
2987 LOGICAL,
ALLOCATABLE,
DIMENSION(:) :: all_present, default_present, &
2988 orb_present, ppl_present, ppnl_present
2989 REAL(dp) :: subcells
2990 REAL(dp),
ALLOCATABLE,
DIMENSION(:) :: all_radius, c_radius, orb_radius, &
2991 ppl_radius, ppnl_radius
2992 REAL(dp),
ALLOCATABLE,
DIMENSION(:, :) :: pair_radius
2993 TYPE(all_potential_type),
POINTER :: all_potential
2994 TYPE(atomic_kind_type),
DIMENSION(:),
POINTER :: atomic_kind_set
2995 TYPE(cell_type),
POINTER :: cell
2996 TYPE(dft_control_type),
POINTER :: dft_control
2997 TYPE(distribution_1d_type),
POINTER :: distribution_1d
2998 TYPE(distribution_2d_type),
POINTER :: distribution_2d
2999 TYPE(gth_potential_type),
POINTER :: gth_potential
3000 TYPE(gto_basis_set_type),
POINTER :: basis_set
3001 TYPE(local_atoms_type),
ALLOCATABLE,
DIMENSION(:) :: atom2d
3002 TYPE(molecule_type),
DIMENSION(:),
POINTER :: molecule_set
3003 TYPE(neighbor_list_set_p_type),
DIMENSION(:), &
3004 POINTER :: sab_cn, sab_vdw
3005 TYPE(particle_type),
DIMENSION(:),
POINTER :: particle_set
3006 TYPE(qs_dispersion_type),
POINTER :: dispersion_env
3007 TYPE(qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
3008 TYPE(qs_kind_type),
POINTER :: qs_kind
3009 TYPE(qs_ks_env_type),
POINTER :: ks_env
3010 TYPE(sgp_potential_type),
POINTER :: sgp_potential
3012 CALL timeset(routinen, handle)
3014 CALL get_qs_env(qs_env=qs_env, qs_kind_set=qs_kind_set)
3015 CALL get_qs_kind_set(qs_kind_set, all_potential_present=all_potential_present, &
3016 gth_potential_present=gth_potential_present, &
3017 sgp_potential_present=sgp_potential_present)
3018 nkind =
SIZE(qs_kind_set)
3019 ALLOCATE (c_radius(nkind), default_present(nkind))
3020 ALLOCATE (orb_radius(nkind), all_radius(nkind), ppl_radius(nkind), ppnl_radius(nkind))
3021 ALLOCATE (orb_present(nkind), all_present(nkind), ppl_present(nkind), ppnl_present(nkind))
3022 ALLOCATE (pair_radius(nkind, nkind))
3023 ALLOCATE (atom2d(nkind))
3025 CALL get_qs_env(qs_env, &
3026 atomic_kind_set=atomic_kind_set, &
3028 distribution_2d=distribution_2d, &
3029 local_particles=distribution_1d, &
3030 particle_set=particle_set, &
3031 molecule_set=molecule_set)
3033 CALL atom2d_build(atom2d, distribution_1d, distribution_2d, atomic_kind_set, &
3034 molecule_set, .false., particle_set)
3037 CALL get_atomic_kind(atomic_kind_set(ikind), atom_list=atom2d(ikind)%list)
3038 qs_kind => qs_kind_set(ikind)
3039 CALL get_qs_kind(qs_kind=qs_kind, basis_set=basis_set, basis_type=
"HARRIS")
3040 IF (
ASSOCIATED(basis_set))
THEN
3041 orb_present(ikind) = .true.
3042 CALL get_gto_basis_set(gto_basis_set=basis_set, kind_radius=orb_radius(ikind))
3044 orb_present(ikind) = .false.
3045 orb_radius(ikind) = 0.0_dp
3047 CALL get_qs_kind(qs_kind, all_potential=all_potential, &
3048 gth_potential=gth_potential, sgp_potential=sgp_potential)
3049 IF (gth_potential_present .OR. sgp_potential_present)
THEN
3050 IF (
ASSOCIATED(gth_potential))
THEN
3051 CALL get_potential(potential=gth_potential, &
3052 ppl_present=ppl_present(ikind), &
3053 ppl_radius=ppl_radius(ikind), &
3054 ppnl_present=ppnl_present(ikind), &
3055 ppnl_radius=ppnl_radius(ikind))
3056 ELSE IF (
ASSOCIATED(sgp_potential))
THEN
3057 CALL get_potential(potential=sgp_potential, &
3058 ppl_present=ppl_present(ikind), &
3059 ppl_radius=ppl_radius(ikind), &
3060 ppnl_present=ppnl_present(ikind), &
3061 ppnl_radius=ppnl_radius(ikind))
3063 ppl_present(ikind) = .false.
3064 ppl_radius(ikind) = 0.0_dp
3065 ppnl_present(ikind) = .false.
3066 ppnl_radius(ikind) = 0.0_dp
3070 IF (all_potential_present .OR. sgp_potential_present)
THEN
3071 all_present(ikind) = .false.
3072 all_radius(ikind) = 0.0_dp
3073 IF (
ASSOCIATED(all_potential))
THEN
3074 all_present(ikind) = .true.
3075 CALL get_potential(potential=all_potential, core_charge_radius=all_radius(ikind))
3076 ELSE IF (
ASSOCIATED(sgp_potential))
THEN
3077 IF (sgp_potential%ecp_local)
THEN
3078 all_present(ikind) = .true.
3079 CALL get_potential(potential=sgp_potential, core_charge_radius=all_radius(ikind))
3085 CALL section_vals_val_get(qs_env%input,
"DFT%SUBCELLS", r_val=subcells)
3088 CALL pair_radius_setup(orb_present, orb_present, orb_radius, orb_radius, pair_radius)
3089 CALL build_neighbor_lists(ec_env%sab_orb, particle_set, atom2d, cell, pair_radius, &
3090 subcells=subcells, nlname=
"sab_orb")
3092 IF (all_potential_present .OR. sgp_potential_present)
THEN
3093 IF (any(all_present))
THEN
3094 CALL pair_radius_setup(orb_present, all_present, orb_radius, all_radius, pair_radius)
3095 CALL build_neighbor_lists(ec_env%sac_ae, particle_set, atom2d, cell, pair_radius, &
3096 subcells=subcells, operator_type=
"ABC", nlname=
"sac_ae")
3100 IF (gth_potential_present .OR. sgp_potential_present)
THEN
3101 IF (any(ppl_present))
THEN
3102 CALL pair_radius_setup(orb_present, ppl_present, orb_radius, ppl_radius, pair_radius)
3103 CALL build_neighbor_lists(ec_env%sac_ppl, particle_set, atom2d, cell, pair_radius, &
3104 subcells=subcells, operator_type=
"ABC", nlname=
"sac_ppl")
3107 IF (any(ppnl_present))
THEN
3108 CALL pair_radius_setup(orb_present, ppnl_present, orb_radius, ppnl_radius, pair_radius)
3109 CALL build_neighbor_lists(ec_env%sap_ppnl, particle_set, atom2d, cell, pair_radius, &
3110 subcells=subcells, operator_type=
"ABBA", nlname=
"sap_ppnl")
3115 c_radius(:) = 0.0_dp
3116 dispersion_env => ec_env%dispersion_env
3117 sab_vdw => dispersion_env%sab_vdw
3118 sab_cn => dispersion_env%sab_cn
3119 IF (dispersion_env%type == xc_vdw_fun_pairpot)
THEN
3120 c_radius(:) = dispersion_env%rc_disp
3121 default_present = .true.
3122 CALL pair_radius_setup(default_present, default_present, c_radius, c_radius, pair_radius)
3123 CALL build_neighbor_lists(sab_vdw, particle_set, atom2d, cell, pair_radius, &
3124 subcells=subcells, operator_type=
"PP", nlname=
"sab_vdw")
3125 dispersion_env%sab_vdw => sab_vdw
3126 IF (dispersion_env%pp_type == vdw_pairpot_dftd3 .OR. &
3127 dispersion_env%pp_type == vdw_pairpot_dftd3bj)
THEN
3130 CALL get_atomic_kind(atomic_kind_set(ikind), z=zat)
3131 c_radius(ikind) = 4._dp*ptable(zat)%covalent_radius*bohr
3133 CALL pair_radius_setup(default_present, default_present, c_radius, c_radius, pair_radius)
3134 CALL build_neighbor_lists(sab_cn, particle_set, atom2d, cell, pair_radius, &
3135 subcells=subcells, operator_type=
"PP", nlname=
"sab_cn")
3136 dispersion_env%sab_cn => sab_cn
3141 CALL atom2d_cleanup(atom2d)
3143 DEALLOCATE (orb_present, default_present, all_present, ppl_present, ppnl_present)
3144 DEALLOCATE (orb_radius, all_radius, ppl_radius, ppnl_radius, c_radius)
3145 DEALLOCATE (pair_radius)
3148 CALL get_qs_env(qs_env, ks_env=ks_env, dft_control=dft_control)
3149 skip_load_balance_distributed = dft_control%qs_control%skip_load_balance_distributed
3150 IF (
ASSOCIATED(ec_env%task_list))
CALL deallocate_task_list(ec_env%task_list)
3151 CALL allocate_task_list(ec_env%task_list)
3152 CALL generate_qs_task_list(ks_env, ec_env%task_list, &
3153 reorder_rs_grid_ranks=.false., soft_valid=.false., &
3154 skip_load_balance_distributed=skip_load_balance_distributed, &
3155 basis_type=
"HARRIS", sab_orb_external=ec_env%sab_orb)
3157 CALL timestop(handle)
3159 END SUBROUTINE ec_build_neighborlist
3166 SUBROUTINE ec_properties(qs_env, ec_env)
3167 TYPE(qs_environment_type),
POINTER :: qs_env
3168 TYPE(energy_correction_type),
POINTER :: ec_env
3170 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ec_properties'
3172 CHARACTER(LEN=8),
DIMENSION(3) :: rlab
3173 CHARACTER(LEN=default_path_length) :: filename, my_pos_voro
3174 CHARACTER(LEN=default_string_length) :: description
3175 INTEGER :: akind, handle, i, ia, iatom, idir, ikind, iounit, ispin, maxmom, nspins, &
3176 reference, should_print_bqb, should_print_voro, unit_nr, unit_nr_voro
3177 LOGICAL :: append_voro, magnetic, periodic, &
3179 REAL(kind=dp) :: charge, dd, focc, tmp
3180 REAL(kind=dp),
DIMENSION(3) :: cdip, pdip, rcc, rdip, ria, tdip
3181 REAL(kind=dp),
DIMENSION(:),
POINTER :: ref_point
3182 TYPE(atomic_kind_type),
POINTER :: atomic_kind
3183 TYPE(cell_type),
POINTER :: cell
3184 TYPE(cp_logger_type),
POINTER :: logger
3185 TYPE(cp_result_type),
POINTER :: results
3186 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_s, moments
3187 TYPE(dft_control_type),
POINTER :: dft_control
3188 TYPE(distribution_1d_type),
POINTER :: local_particles
3189 TYPE(mp_para_env_type),
POINTER :: para_env
3190 TYPE(particle_type),
DIMENSION(:),
POINTER :: particle_set
3191 TYPE(pw_env_type),
POINTER :: pw_env
3192 TYPE(pw_pool_p_type),
DIMENSION(:),
POINTER :: pw_pools
3193 TYPE(pw_pool_type),
POINTER :: auxbas_pw_pool
3194 TYPE(pw_r3d_rs_type) :: rho_elec_rspace
3195 TYPE(qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
3196 TYPE(section_vals_type),
POINTER :: ec_section, print_key, print_key_bqb, &
3199 CALL timeset(routinen, handle)
3205 logger => cp_get_default_logger()
3206 IF (logger%para_env%is_source())
THEN
3207 iounit = cp_logger_get_default_unit_nr(logger, local=.true.)
3212 NULLIFY (dft_control)
3213 CALL get_qs_env(qs_env, dft_control=dft_control)
3214 nspins = dft_control%nspins
3216 ec_section => section_vals_get_subs_vals(qs_env%input,
"DFT%ENERGY_CORRECTION")
3217 print_key => section_vals_get_subs_vals(section_vals=ec_section, &
3218 subsection_name=
"PRINT%MOMENTS")
3220 IF (btest(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file))
THEN
3222 maxmom = section_get_ival(section_vals=ec_section, &
3223 keyword_name=
"PRINT%MOMENTS%MAX_MOMENT")
3224 periodic = section_get_lval(section_vals=ec_section, &
3225 keyword_name=
"PRINT%MOMENTS%PERIODIC")
3226 reference = section_get_ival(section_vals=ec_section, &
3227 keyword_name=
"PRINT%MOMENTS%REFERENCE")
3228 magnetic = section_get_lval(section_vals=ec_section, &
3229 keyword_name=
"PRINT%MOMENTS%MAGNETIC")
3231 CALL section_vals_val_get(ec_section,
"PRINT%MOMENTS%REF_POINT", r_vals=ref_point)
3232 unit_nr = cp_print_key_unit_nr(logger=logger, basis_section=ec_section, &
3233 print_key_path=
"PRINT%MOMENTS", extension=
".dat", &
3234 middle_name=
"moments", log_filename=.false.)
3236 IF (iounit > 0)
THEN
3237 IF (unit_nr /= iounit .AND. unit_nr > 0)
THEN
3238 INQUIRE (unit=unit_nr, name=filename)
3239 WRITE (unit=iounit, fmt=
"(/,T2,A,2(/,T3,A),/)") &
3240 "MOMENTS",
"The electric/magnetic moments are written to file:", &
3243 WRITE (unit=iounit, fmt=
"(/,T2,A)")
"ELECTRIC/MAGNETIC MOMENTS"
3248 cpabort(
"Periodic moments not implemented with EC")
3250 cpassert(maxmom < 2)
3251 cpassert(.NOT. magnetic)
3252 IF (maxmom == 1)
THEN
3253 CALL get_qs_env(qs_env=qs_env, cell=cell, para_env=para_env)
3255 CALL get_reference_point(rcc, qs_env=qs_env, reference=reference, ref_point=ref_point)
3258 CALL get_qs_env(qs_env=qs_env, particle_set=particle_set, &
3259 qs_kind_set=qs_kind_set, local_particles=local_particles)
3260 DO ikind = 1,
SIZE(local_particles%n_el)
3261 DO ia = 1, local_particles%n_el(ikind)
3262 iatom = local_particles%list(ikind)%array(ia)
3264 ria = pbc(particle_set(iatom)%r - rcc, cell) + rcc
3266 atomic_kind => particle_set(iatom)%atomic_kind
3267 CALL get_atomic_kind(atomic_kind, kind_number=akind)
3268 CALL get_qs_kind(qs_kind_set(akind), core_charge=charge)
3269 cdip(1:3) = cdip(1:3) - charge*ria(1:3)
3272 CALL para_env%sum(cdip)
3275 CALL ec_efield_integrals(qs_env, ec_env, rcc)
3278 DO ispin = 1, nspins
3280 CALL dbcsr_dot(ec_env%matrix_p(ispin, 1)%matrix, &
3281 ec_env%efield%dipmat(idir)%matrix, tmp)
3282 pdip(idir) = pdip(idir) + tmp
3287 CALL get_qs_env(qs_env=qs_env, matrix_s=matrix_s)
3289 CALL dbcsr_allocate_matrix_set(moments, 4)
3291 ALLOCATE (moments(i)%matrix)
3292 CALL dbcsr_copy(moments(i)%matrix, matrix_s(1)%matrix,
"Moments")
3293 CALL dbcsr_set(moments(i)%matrix, 0.0_dp)
3295 CALL build_local_moment_matrix(qs_env, moments, 1, ref_point=rcc)
3298 IF (nspins == 2) focc = 1.0_dp
3300 DO ispin = 1, nspins
3302 CALL dbcsr_dot(ec_env%matrix_z(ispin)%matrix, moments(idir)%matrix, tmp)
3303 rdip(idir) = rdip(idir) + tmp
3306 CALL dbcsr_deallocate_matrix_set(moments)
3308 tdip = -(rdip + pdip + cdip)
3309 IF (unit_nr > 0)
THEN
3310 WRITE (unit_nr,
"(T3,A)")
"Dipoles are based on the traditional operator."
3311 dd = sqrt(sum(tdip(1:3)**2))*debye
3312 WRITE (unit_nr,
"(T3,A)")
"Dipole moment [Debye]"
3313 WRITE (unit_nr,
"(T5,3(A,A,F14.8,1X),T60,A,T67,F14.8)") &
3314 (trim(rlab(i)),
"=", tdip(i)*debye, i=1, 3),
"Total=", dd
3319 CALL cp_print_key_finished_output(unit_nr=unit_nr, logger=logger, &
3320 basis_section=ec_section, print_key_path=
"PRINT%MOMENTS")
3321 CALL get_qs_env(qs_env=qs_env, results=results)
3322 description =
"[DIPOLE]"
3323 CALL cp_results_erase(results=results, description=description)
3324 CALL put_results(results=results, description=description, values=tdip(1:3))
3328 print_key_voro => section_vals_get_subs_vals(ec_section,
"PRINT%VORONOI")
3329 print_key_bqb => section_vals_get_subs_vals(ec_section,
"PRINT%E_DENSITY_BQB")
3330 IF (btest(cp_print_key_should_output(logger%iter_info, print_key_voro), cp_p_file))
THEN
3331 should_print_voro = 1
3333 should_print_voro = 0
3335 IF (btest(cp_print_key_should_output(logger%iter_info, print_key_bqb), cp_p_file))
THEN
3336 should_print_bqb = 1
3338 should_print_bqb = 0
3340 IF ((should_print_voro /= 0) .OR. (should_print_bqb /= 0))
THEN
3342 CALL get_qs_env(qs_env=qs_env, &
3344 CALL pw_env_get(pw_env=pw_env, &
3345 auxbas_pw_pool=auxbas_pw_pool, &
3347 CALL auxbas_pw_pool%create_pw(pw=rho_elec_rspace)
3349 IF (dft_control%nspins > 1)
THEN
3352 CALL pw_copy(ec_env%rhoout_r(1), rho_elec_rspace)
3353 CALL pw_axpy(ec_env%rhoout_r(2), rho_elec_rspace)
3355 CALL pw_axpy(ec_env%rhoz_r(1), rho_elec_rspace)
3356 CALL pw_axpy(ec_env%rhoz_r(2), rho_elec_rspace)
3360 CALL pw_copy(ec_env%rhoout_r(1), rho_elec_rspace)
3361 CALL pw_axpy(ec_env%rhoz_r(1), rho_elec_rspace)
3364 IF (should_print_voro /= 0)
THEN
3365 CALL section_vals_val_get(print_key_voro,
"OUTPUT_TEXT", l_val=voro_print_txt)
3366 IF (voro_print_txt)
THEN
3367 append_voro = section_get_lval(ec_section,
"PRINT%VORONOI%APPEND")
3368 my_pos_voro =
"REWIND"
3369 IF (append_voro)
THEN
3370 my_pos_voro =
"APPEND"
3372 unit_nr_voro = cp_print_key_unit_nr(logger, ec_section,
"PRINT%VORONOI", extension=
".voronoi", &
3373 file_position=my_pos_voro, log_filename=.false.)
3381 CALL entry_voronoi_or_bqb(should_print_voro, should_print_bqb, print_key_voro, print_key_bqb, &
3382 unit_nr_voro, qs_env, rho_elec_rspace)
3384 CALL auxbas_pw_pool%give_back_pw(rho_elec_rspace)
3386 IF (unit_nr_voro > 0)
THEN
3387 CALL cp_print_key_finished_output(unit_nr_voro, logger, ec_section,
"PRINT%VORONOI")
3392 CALL timestop(handle)
3394 END SUBROUTINE ec_properties
3407 SUBROUTINE ec_ls_init(qs_env, matrix_ks, matrix_s)
3408 TYPE(qs_environment_type),
POINTER :: qs_env
3409 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_ks, matrix_s
3411 CHARACTER(len=*),
PARAMETER :: routinen =
'ec_ls_init'
3413 INTEGER :: handle, ispin, nspins
3414 TYPE(dft_control_type),
POINTER :: dft_control
3415 TYPE(energy_correction_type),
POINTER :: ec_env
3416 TYPE(ls_scf_env_type),
POINTER :: ls_env
3418 CALL timeset(routinen, handle)
3420 CALL get_qs_env(qs_env=qs_env, &
3421 dft_control=dft_control, &
3423 nspins = dft_control%nspins
3424 ls_env => ec_env%ls_env
3427 CALL matrix_ls_create(matrix_ls=ls_env%matrix_s, matrix_qs=matrix_s(1, 1)%matrix, &
3428 ls_mstruct=ls_env%ls_mstruct)
3430 IF (
ALLOCATED(ls_env%matrix_p))
THEN
3431 DO ispin = 1,
SIZE(ls_env%matrix_p)
3432 CALL dbcsr_release(ls_env%matrix_p(ispin))
3435 ALLOCATE (ls_env%matrix_p(nspins))
3438 DO ispin = 1, nspins
3439 CALL dbcsr_create(ls_env%matrix_p(ispin), template=ls_env%matrix_s, &
3440 matrix_type=dbcsr_type_no_symmetry)
3443 ALLOCATE (ls_env%matrix_ks(nspins))
3444 DO ispin = 1, nspins
3445 CALL dbcsr_create(ls_env%matrix_ks(ispin), template=ls_env%matrix_s, &
3446 matrix_type=dbcsr_type_no_symmetry)
3450 CALL ls_scf_init_matrix_s(matrix_s(1, 1)%matrix, ls_env)
3454 DO ispin = 1, nspins
3455 CALL matrix_qs_to_ls(matrix_ls=ls_env%matrix_ks(ispin), &
3456 matrix_qs=matrix_ks(ispin, 1)%matrix, &
3457 ls_mstruct=ls_env%ls_mstruct, &
3461 CALL timestop(handle)
3463 END SUBROUTINE ec_ls_init
3479 SUBROUTINE ec_ls_solver(qs_env, matrix_p, matrix_w, ec_ls_method)
3480 TYPE(qs_environment_type),
POINTER :: qs_env
3481 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_p, matrix_w
3482 INTEGER,
INTENT(IN) :: ec_ls_method
3484 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ec_ls_solver'
3486 INTEGER :: handle, ispin, nelectron_spin_real, &
3488 INTEGER,
DIMENSION(2) :: nmo
3489 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: wmat
3490 TYPE(dbcsr_type),
ALLOCATABLE,
DIMENSION(:) :: matrix_ks_deviation
3491 TYPE(dft_control_type),
POINTER :: dft_control
3492 TYPE(energy_correction_type),
POINTER :: ec_env
3493 TYPE(ls_scf_env_type),
POINTER :: ls_env
3494 TYPE(mp_para_env_type),
POINTER :: para_env
3496 CALL timeset(routinen, handle)
3499 CALL get_qs_env(qs_env, &
3500 dft_control=dft_control, &
3502 nspins = dft_control%nspins
3503 ec_env => qs_env%ec_env
3504 ls_env => ec_env%ls_env
3507 CALL get_qs_env(qs_env=qs_env, nelectron_spin=nmo)
3508 IF (nspins == 1) nmo(1) = nmo(1)/2
3509 ls_env%homo_spin(:) = 0.0_dp
3510 ls_env%lumo_spin(:) = 0.0_dp
3512 ALLOCATE (matrix_ks_deviation(nspins))
3513 DO ispin = 1, nspins
3514 CALL dbcsr_create(matrix_ks_deviation(ispin), template=ls_env%matrix_ks(ispin))
3515 CALL dbcsr_set(matrix_ks_deviation(ispin), 0.0_dp)
3519 IF (ls_env%has_s_preconditioner)
THEN
3520 DO ispin = 1, nspins
3521 CALL apply_matrix_preconditioner(ls_env%matrix_ks(ispin),
"forward", &
3522 ls_env%matrix_bs_sqrt, ls_env%matrix_bs_sqrt_inv)
3524 CALL dbcsr_filter(ls_env%matrix_ks(ispin), ls_env%eps_filter)
3528 DO ispin = 1, nspins
3529 nelectron_spin_real = ls_env%nelectron_spin(ispin)
3530 IF (ls_env%nspins == 1) nelectron_spin_real = nelectron_spin_real/2
3532 SELECT CASE (ec_ls_method)
3533 CASE (ec_matrix_sign)
3534 CALL density_matrix_sign(ls_env%matrix_p(ispin), &
3535 ls_env%mu_spin(ispin), &
3537 ls_env%sign_method, &
3538 ls_env%sign_order, &
3539 ls_env%matrix_ks(ispin), &
3541 ls_env%matrix_s_inv, &
3542 nelectron_spin_real, &
3545 CASE (ec_matrix_trs4)
3546 CALL density_matrix_trs4( &
3547 ls_env%matrix_p(ispin), &
3548 ls_env%matrix_ks(ispin), &
3549 ls_env%matrix_s_sqrt_inv, &
3550 nelectron_spin_real, &
3551 ec_env%eps_default, &
3552 ls_env%homo_spin(ispin), &
3553 ls_env%lumo_spin(ispin), &
3554 ls_env%mu_spin(ispin), &
3555 matrix_ks_deviation=matrix_ks_deviation(ispin), &
3556 dynamic_threshold=ls_env%dynamic_threshold, &
3557 eps_lanczos=ls_env%eps_lanczos, &
3558 max_iter_lanczos=ls_env%max_iter_lanczos)
3560 CASE (ec_matrix_tc2)
3561 CALL density_matrix_tc2( &
3562 ls_env%matrix_p(ispin), &
3563 ls_env%matrix_ks(ispin), &
3564 ls_env%matrix_s_sqrt_inv, &
3565 nelectron_spin_real, &
3566 ec_env%eps_default, &
3567 ls_env%homo_spin(ispin), &
3568 ls_env%lumo_spin(ispin), &
3569 non_monotonic=ls_env%non_monotonic, &
3570 eps_lanczos=ls_env%eps_lanczos, &
3571 max_iter_lanczos=ls_env%max_iter_lanczos)
3578 IF (ls_env%has_s_preconditioner)
THEN
3579 DO ispin = 1, nspins
3581 CALL apply_matrix_preconditioner(ls_env%matrix_p(ispin),
"forward", &
3582 ls_env%matrix_bs_sqrt, ls_env%matrix_bs_sqrt_inv)
3584 CALL dbcsr_filter(ls_env%matrix_p(ispin), ls_env%eps_filter)
3589 IF (nspins == 1)
CALL dbcsr_scale(ls_env%matrix_p(1), 2.0_dp)
3591 IF (ls_env%report_all_sparsities)
CALL post_scf_sparsities(ls_env)
3595 DO ispin = 1, nspins
3596 CALL matrix_ls_to_qs(matrix_qs=matrix_p(ispin, 1)%matrix, &
3597 matrix_ls=ls_env%matrix_p(ispin), &
3598 ls_mstruct=ls_env%ls_mstruct, &
3602 wmat => matrix_w(:, 1)
3603 CALL calculate_w_matrix_ls(wmat, ec_env%ls_env)
3606 CALL dbcsr_release(ls_env%matrix_s)
3607 IF (ls_env%has_s_preconditioner)
THEN
3608 CALL dbcsr_release(ls_env%matrix_bs_sqrt)
3609 CALL dbcsr_release(ls_env%matrix_bs_sqrt_inv)
3611 IF (ls_env%needs_s_inv)
THEN
3612 CALL dbcsr_release(ls_env%matrix_s_inv)
3614 IF (ls_env%use_s_sqrt)
THEN
3615 CALL dbcsr_release(ls_env%matrix_s_sqrt)
3616 CALL dbcsr_release(ls_env%matrix_s_sqrt_inv)
3619 DO ispin = 1,
SIZE(ls_env%matrix_ks)
3620 CALL dbcsr_release(ls_env%matrix_ks(ispin))
3622 DEALLOCATE (ls_env%matrix_ks)
3624 DO ispin = 1, nspins
3625 CALL dbcsr_release(matrix_ks_deviation(ispin))
3627 DEALLOCATE (matrix_ks_deviation)
3629 CALL timestop(handle)
3631 END SUBROUTINE ec_ls_solver
3649 SUBROUTINE ec_ot_diag_solver(qs_env, ec_env, matrix_ks, matrix_s, matrix_p, matrix_w)
3650 TYPE(qs_environment_type),
POINTER :: qs_env
3651 TYPE(energy_correction_type),
POINTER :: ec_env
3652 TYPE(dbcsr_p_type),
DIMENSION(:, :),
INTENT(IN), &
3653 POINTER :: matrix_ks, matrix_s
3654 TYPE(dbcsr_p_type),
DIMENSION(:, :), &
3655 INTENT(INOUT),
POINTER :: matrix_p, matrix_w
3657 CHARACTER(len=*),
PARAMETER :: routinen =
'ec_ot_diag_solver'
3659 INTEGER :: handle, homo, ikind, iounit, ispin, &
3660 max_iter, nao, nkind, nmo, nspins
3661 INTEGER,
DIMENSION(2) :: nelectron_spin
3662 REAL(kind=dp),
DIMENSION(:),
POINTER :: eigenvalues
3663 TYPE(atomic_kind_type),
DIMENSION(:),
POINTER :: atomic_kind_set
3664 TYPE(cp_blacs_env_type),
POINTER :: blacs_env
3665 TYPE(cp_fm_type) :: sv
3666 TYPE(cp_fm_type),
POINTER :: mo_coeff
3667 TYPE(cp_logger_type),
POINTER :: logger
3668 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: p_rmpv
3669 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: rho_ao
3670 TYPE(dft_control_type),
POINTER :: dft_control
3671 TYPE(gto_basis_set_type),
POINTER :: basis_set, harris_basis
3672 TYPE(mo_set_type),
DIMENSION(:),
POINTER :: mos
3673 TYPE(mp_para_env_type),
POINTER :: para_env
3674 TYPE(particle_type),
DIMENSION(:),
POINTER :: particle_set
3675 TYPE(preconditioner_type),
POINTER :: local_preconditioner
3676 TYPE(qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
3677 TYPE(qs_kind_type),
POINTER :: qs_kind
3678 TYPE(qs_rho_type),
POINTER :: rho
3680 CALL timeset(routinen, handle)
3682 logger => cp_get_default_logger()
3683 iounit = cp_logger_get_default_unit_nr(logger)
3685 cpassert(
ASSOCIATED(qs_env))
3686 cpassert(
ASSOCIATED(ec_env))
3687 cpassert(
ASSOCIATED(matrix_ks))
3688 cpassert(
ASSOCIATED(matrix_s))
3689 cpassert(
ASSOCIATED(matrix_p))
3690 cpassert(
ASSOCIATED(matrix_w))
3692 CALL get_qs_env(qs_env=qs_env, &
3693 atomic_kind_set=atomic_kind_set, &
3694 blacs_env=blacs_env, &
3695 dft_control=dft_control, &
3696 nelectron_spin=nelectron_spin, &
3697 para_env=para_env, &
3698 particle_set=particle_set, &
3699 qs_kind_set=qs_kind_set)
3700 nspins = dft_control%nspins
3707 IF (dft_control%qs_control%do_ls_scf)
THEN
3708 CALL ec_mos_init(qs_env, matrix_s(1, 1)%matrix)
3711 CALL get_qs_env(qs_env, mos=mos)
3718 CALL get_qs_env(qs_env, qs_kind_set=qs_kind_set, nkind=nkind)
3719 CALL uppercase(ec_env%basis)
3723 IF (ec_env%basis ==
"HARRIS")
THEN
3725 qs_kind => qs_kind_set(ikind)
3727 CALL get_qs_kind(qs_kind=qs_kind, basis_set=basis_set, basis_type=
"ORB")
3729 CALL get_qs_kind(qs_kind=qs_kind, basis_set=harris_basis, basis_type=
"HARRIS")
3731 IF (basis_set%name .NE. harris_basis%name)
THEN
3732 cpabort(
"OT-Diag initial guess: Harris and ground state need to use the same basis")
3737 IF (ec_env%mao)
THEN
3738 cpabort(
"OT-Diag initial guess: not implemented for MAOs")
3742 SELECT CASE (ec_env%ec_initial_guess)
3745 p_rmpv => matrix_p(:, 1)
3747 CALL calculate_atomic_block_dm(p_rmpv, matrix_s(1, 1)%matrix, atomic_kind_set, qs_kind_set, &
3748 nspins, nelectron_spin, iounit, para_env)
3752 CALL get_qs_env(qs_env, rho=rho)
3753 CALL qs_rho_get(rho, rho_ao_kp=rho_ao)
3754 p_rmpv => rho_ao(:, 1)
3757 cpabort(
"Unknown inital guess for OT-Diagonalization (Harris functional)")
3760 DO ispin = 1, nspins
3761 CALL get_mo_set(mo_set=mos(ispin), &
3762 mo_coeff=mo_coeff, &
3768 CALL cp_fm_set_all(mo_coeff, 0.0_dp)
3769 CALL cp_fm_init_random(mo_coeff, nmo)
3771 CALL cp_fm_create(sv, mo_coeff%matrix_struct,
"SV")
3774 CALL cp_dbcsr_sm_fm_multiply(matrix_s(1, 1)%matrix, mo_coeff, sv, nmo)
3775 CALL cp_dbcsr_sm_fm_multiply(p_rmpv(ispin)%matrix, sv, mo_coeff, homo)
3776 CALL cp_fm_release(sv)
3779 CALL make_basis_sm(mo_coeff, nmo, matrix_s(1, 1)%matrix)
3783 NULLIFY (local_preconditioner)
3784 ALLOCATE (local_preconditioner)
3785 CALL init_preconditioner(local_preconditioner, para_env=para_env, &
3786 blacs_env=blacs_env)
3787 DO ispin = 1, nspins
3788 CALL make_preconditioner(local_preconditioner, &
3789 precon_type=ot_precond_full_single_inverse, &
3790 solver_type=ot_precond_solver_default, &
3791 matrix_h=matrix_ks(ispin, 1)%matrix, &
3792 matrix_s=matrix_s(ispin, 1)%matrix, &
3793 convert_precond_to_dbcsr=.true., &
3794 mo_set=mos(ispin), energy_gap=0.2_dp)
3796 CALL get_mo_set(mos(ispin), &
3797 mo_coeff=mo_coeff, &
3798 eigenvalues=eigenvalues, &
3801 CALL ot_eigensolver(matrix_h=matrix_ks(ispin, 1)%matrix, &
3802 matrix_s=matrix_s(1, 1)%matrix, &
3803 matrix_c_fm=mo_coeff, &
3805 eps_gradient=ec_env%eps_default, &
3806 iter_max=max_iter, &
3808 CALL calculate_subspace_eigenvalues(mo_coeff, matrix_ks(ispin, 1)%matrix, &
3809 evals_arg=eigenvalues, do_rotation=.true.)
3812 CALL destroy_preconditioner(local_preconditioner)
3813 DEALLOCATE (local_preconditioner)
3816 CALL copy_fm_to_dbcsr(mos(ispin)%mo_coeff, &
3817 mos(ispin)%mo_coeff_b)
3821 DO ispin = 1, nspins
3822 CALL calculate_density_matrix(mos(ispin), matrix_p(ispin, 1)%matrix)
3824 CALL calculate_w_matrix(mos(ispin), matrix_w(ispin, 1)%matrix)
3828 IF (dft_control%qs_control%do_ls_scf)
THEN
3829 DO ispin = 1, nspins
3830 CALL deallocate_mo_set(mos(ispin))
3832 IF (
ASSOCIATED(qs_env%mos))
THEN
3833 DO ispin = 1,
SIZE(qs_env%mos)
3834 CALL deallocate_mo_set(qs_env%mos(ispin))
3836 DEALLOCATE (qs_env%mos)
3840 CALL timestop(handle)
3842 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, basis_type, 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 set_qs_env(qs_env, super_cell, mos, qmmm, qmmm_periodic, ewald_env, ewald_pw, mpools, rho_external, external_vxc, mask, scf_control, rel_control, qs_charges, ks_env, ks_qmmm_env, wf_history, scf_env, active_space, input, oce, rho_atom_set, rho0_atom_set, rho0_mpole, run_rtp, rtp, rhoz_set, rhoz_tot, ecoul_1c, has_unit_metric, requires_mo_derivs, mo_derivs, mo_loc_history, efield, linres_control, xas_env, cp_ddapc_env, cp_ddapc_ewald, outer_scf_history, outer_scf_ihistory, x_data, et_coupling, dftb_potential, se_taper, se_store_int_env, se_nddo_mpole, se_nonbond_env, admm_env, ls_scf_env, do_transport, transport_env, lri_env, lri_density, exstate_env, ec_env, dispersion_env, harris_env, gcp_env, mp2_env, bs_env, kg_env, force, kpoints, wanniercentres, almo_scf_env, gradient_history, variable_history, embed_pot, spin_embed_pot, polar_env, mos_last_converged, eeq, rhs, tb_tblite)
Set the QUICKSTEP environment.
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.
Routines for the construction of the coefficients for the expansion of the atomic densities rho1_hard...
subroutine, public build_oce_matrices(intac, calculate_forces, nder, qs_kind_set, particle_set, sap_oce, eps_fit)
Set up the sparse matrix for the coefficients of one center expansions This routine uses the same log...
subroutine, public allocate_oce_set(oce_set, nkind)
Allocate and initialize the matrix set of oce coefficients.
subroutine, public create_oce_set(oce_set)
...
an eigen-space solver for the generalised symmetric eigenvalue problem for sparse matrices,...
subroutine, public ot_eigensolver(matrix_h, matrix_s, matrix_orthogonal_space_fm, matrix_c_fm, preconditioner, eps_gradient, iter_max, size_ortho_space, silent, ot_settings)
...
Calculation of overlap matrix, its derivatives and forces.
subroutine, public build_overlap_matrix(ks_env, matrix_s, matrixkp_s, matrix_name, nderivative, basis_type_a, basis_type_b, sab_nl, calculate_forces, matrix_p, matrixkp_p)
Calculation of the overlap matrix over Cartesian Gaussian functions.
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.