815 SUBROUTINE response_force(qs_env, vh_rspace, vxc_rspace, vtau_rspace, vadmm_rspace, &
816 matrix_hz, matrix_pz, matrix_pz_admm, matrix_wz, &
817 zehartree, zexc, zexc_aux_fit, rhopz_r, p_env, ex_env, debug)
820 TYPE(
pw_r3d_rs_type),
DIMENSION(:),
POINTER :: vxc_rspace, vtau_rspace, vadmm_rspace
821 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_hz, matrix_pz, matrix_pz_admm, &
823 REAL(kind=
dp),
OPTIONAL :: zehartree, zexc, zexc_aux_fit
825 INTENT(INOUT),
OPTIONAL :: rhopz_r
828 LOGICAL,
INTENT(IN),
OPTIONAL :: debug
830 CHARACTER(LEN=*),
PARAMETER :: routinen =
'response_force'
832 CHARACTER(LEN=default_string_length) :: basis_type, unitstr
833 INTEGER :: handle, iounit, ispin, mspin, myfun, &
834 n_rep_hf, nao, nao_aux, natom, nder, &
836 LOGICAL :: debug_forces, debug_stress, distribute_fock_matrix, do_ex, do_hfx, gapw, gapw_xc, &
837 hfx_treat_lsd_in_core, resp_only, s_mstruct_changed, use_virial
838 REAL(kind=
dp) :: eh1, ehartree, ekin_mol, eps_filter, &
839 exc, exc_aux_fit, fconv, focc, &
840 hartree_gs, hartree_t
841 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: ftot1, ftot2, ftot3
842 REAL(kind=
dp),
DIMENSION(2) :: total_rho_gs, total_rho_t
843 REAL(kind=
dp),
DIMENSION(3) :: fodeb
844 REAL(kind=
dp),
DIMENSION(3, 3) :: h_stress, pv_loc, stdeb, sttot, sttot2
850 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_ht, matrix_pd, matrix_pza, &
852 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_h, matrix_p, mhd, mhx, mhy, mhz, &
853 mpa2, mpd, mpz, scrm2
857 TYPE(
hfx_type),
DIMENSION(:, :),
POINTER :: x_data
859 TYPE(
local_rho_type),
POINTER :: local_rho_set_f, local_rho_set_gs, &
860 local_rho_set_t, local_rho_set_vxc, &
865 POINTER :: sab_aux_fit, sab_orb
868 TYPE(
pw_c1d_gs_type) :: rho_tot_gspace, rho_tot_gspace_gs, rho_tot_gspace_t, &
869 rhoz_tot_gspace, v_hartree_gspace_gs, v_hartree_gspace_t, zv_hartree_gspace
870 TYPE(
pw_c1d_gs_type),
DIMENSION(:),
POINTER :: rho_g_aux, rho_g_gs, rho_g_t, rhoz_g, &
871 rhoz_g_aux, rhoz_g_xc
876 TYPE(
pw_r3d_rs_type) :: v_hartree_rspace_gs, v_hartree_rspace_t, &
877 vhxc_rspace, zv_hartree_rspace
878 TYPE(
pw_r3d_rs_type),
DIMENSION(:),
POINTER :: rho_r_aux, rho_r_gs, rho_r_t, rhoz_r, &
879 rhoz_r_aux, rhoz_r_xc, tau_r_aux, &
880 tauz_r, tauz_r_xc, v_xc, v_xc_tau
882 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
884 TYPE(
qs_rho_type),
POINTER :: rho, rho_aux_fit, rho_xc
889 CALL timeset(routinen, handle)
891 IF (
PRESENT(debug))
THEN
895 debug_forces = .false.
896 debug_stress = .false.
900 IF (logger%para_env%is_source())
THEN
907 IF (
PRESENT(ex_env)) do_ex = .true.
909 cpassert(
PRESENT(p_env))
912 NULLIFY (ks_env, sab_orb, virial)
917 dft_control=dft_control, &
921 nspins = dft_control%nspins
922 gapw = dft_control%qs_control%gapw
923 gapw_xc = dft_control%qs_control%gapw_xc
925 IF (debug_forces)
THEN
926 CALL get_qs_env(qs_env, natom=natom, atomic_kind_set=atomic_kind_set)
927 ALLOCATE (ftot1(3, natom))
932 use_virial = virial%pv_availability .AND. (.NOT. virial%pv_numer)
934 IF (use_virial .AND. do_ex)
THEN
935 CALL cp_abort(__location__,
"Stress Tensor not available for TDDFT calculations.")
938 fconv = 1.0e-9_dp*
pascal/cell%deth
939 IF (debug_stress .AND. use_virial)
THEN
940 sttot = virial%pv_virial
950 ALLOCATE (mpa(ispin)%matrix)
951 CALL dbcsr_create(mpa(ispin)%matrix, template=p_env%p1(ispin)%matrix)
952 CALL dbcsr_copy(mpa(ispin)%matrix, p_env%p1(ispin)%matrix)
953 CALL dbcsr_add(mpa(ispin)%matrix, ex_env%matrix_pe(ispin)%matrix, 1.0_dp, 1.0_dp)
954 CALL dbcsr_set(matrix_hz(ispin)%matrix, 0.0_dp)
959 ALLOCATE (matrix_ht(ispin)%matrix)
960 CALL dbcsr_create(matrix_ht(ispin)%matrix, template=matrix_hz(ispin)%matrix)
961 CALL dbcsr_copy(matrix_ht(ispin)%matrix, matrix_hz(ispin)%matrix)
962 CALL dbcsr_set(matrix_ht(ispin)%matrix, 0.0_dp)
973 mpa2(1:nspins, 1:1) => mpa(1:nspins)
975 matrix_name=
"KINETIC ENERGY MATRIX", &
977 sab_orb=sab_orb, calculate_forces=.true., &
978 debug_forces=debug_forces, debug_stress=debug_stress)
982 CALL get_qs_env(qs_env=qs_env, matrix_s=matrix_s)
986 ALLOCATE (scrm(ispin)%matrix)
987 CALL dbcsr_create(scrm(ispin)%matrix, template=matrix_s(1)%matrix)
988 CALL dbcsr_copy(scrm(ispin)%matrix, matrix_s(1)%matrix)
989 CALL dbcsr_set(scrm(ispin)%matrix, 0.0_dp)
992 CALL get_qs_env(qs_env, qs_kind_set=qs_kind_set, particle_set=particle_set, &
993 atomic_kind_set=atomic_kind_set)
995 ALLOCATE (matrix_p(nspins, 1), matrix_h(nspins, 1))
997 matrix_p(ispin, 1)%matrix => mpa(ispin)%matrix
998 matrix_h(ispin, 1)%matrix => scrm(ispin)%matrix
1000 matrix_h(1, 1)%matrix => scrm(1)%matrix
1003 CALL core_matrices(qs_env, matrix_h, matrix_p, .true., nder, &
1004 debug_forces=debug_forces, debug_stress=debug_stress)
1008 IF (dft_control%qs_control%do_kg)
THEN
1010 CALL get_qs_env(qs_env=qs_env, kg_env=kg_env, dbcsr_dist=dbcsr_dist)
1012 IF (use_virial)
THEN
1013 pv_loc = virial%pv_virial
1016 IF (debug_forces) fodeb(1:3) = force(1)%kinetic(1:3, 1)
1017 IF (debug_stress .AND. use_virial) stdeb = virial%pv_virial
1018 CALL build_tnadd_mat(kg_env=kg_env, matrix_p=matrix_p, force=force, virial=virial, &
1019 calculate_forces=.true., use_virial=use_virial, &
1020 qs_kind_set=qs_kind_set, atomic_kind_set=atomic_kind_set, &
1021 particle_set=particle_set, sab_orb=sab_orb, dbcsr_dist=dbcsr_dist)
1022 IF (debug_forces)
THEN
1023 fodeb(1:3) = force(1)%kinetic(1:3, 1) - fodeb(1:3)
1024 CALL para_env%sum(fodeb)
1025 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Pz*dTnadd ", fodeb
1027 IF (debug_stress .AND. use_virial)
THEN
1028 stdeb = fconv*(virial%pv_virial - stdeb)
1029 CALL para_env%sum(stdeb)
1030 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1035 IF (use_virial)
THEN
1036 virial%pv_ekinetic = virial%pv_ekinetic + (virial%pv_virial - pv_loc)
1042 DEALLOCATE (matrix_h)
1043 DEALLOCATE (matrix_p)
1051 DO ispin = 1, nspins
1052 ALLOCATE (scrm(ispin)%matrix)
1053 CALL dbcsr_create(scrm(ispin)%matrix, template=matrix_pz(1)%matrix)
1054 CALL dbcsr_copy(scrm(ispin)%matrix, matrix_pz(ispin)%matrix)
1055 CALL dbcsr_set(scrm(ispin)%matrix, 0.0_dp)
1058 IF (debug_forces)
THEN
1059 ALLOCATE (ftot2(3, natom))
1061 fodeb(1:3) = ftot2(1:3, 1) - ftot1(1:3, 1)
1062 CALL para_env%sum(fodeb)
1063 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Pz*dHcore", fodeb
1065 IF (debug_stress .AND. use_virial)
THEN
1066 stdeb = fconv*(virial%pv_virial - sttot)
1067 CALL para_env%sum(stdeb)
1068 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1071 sttot2 = virial%pv_virial
1079 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool, poisson_env=poisson_env)
1081 IF (dft_control%do_admm)
THEN
1083 xc_section => admm_env%xc_section_primary
1090 IF (gapw .OR. gapw_xc)
THEN
1091 NULLIFY (oce, sab_orb)
1092 CALL get_qs_env(qs_env=qs_env, oce=oce, sab_orb=sab_orb)
1094 NULLIFY (local_rho_set_gs)
1099 qs_kind_set, dft_control, para_env)
1100 CALL init_rho0(local_rho_set_gs, qs_env, dft_control%qs_control%gapw_control)
1103 qs_kind_set, oce, sab_orb, para_env)
1106 NULLIFY (local_rho_set_t)
1109 qs_kind_set, dft_control, para_env)
1110 CALL init_rho0(local_rho_set_t, qs_env, dft_control%qs_control%gapw_control, &
1114 qs_kind_set, oce, sab_orb, para_env)
1118 ALLOCATE (rho_r_gs(nspins), rho_g_gs(nspins))
1119 DO ispin = 1, nspins
1120 CALL auxbas_pw_pool%create_pw(rho_r_gs(ispin))
1121 CALL auxbas_pw_pool%create_pw(rho_g_gs(ispin))
1123 CALL auxbas_pw_pool%create_pw(rho_tot_gspace_gs)
1125 total_rho_gs = 0.0_dp
1126 CALL pw_zero(rho_tot_gspace_gs)
1127 DO ispin = 1, nspins
1129 rho=rho_r_gs(ispin), &
1130 rho_gspace=rho_g_gs(ispin), &
1131 soft_valid=(gapw .OR. gapw_xc), &
1132 total_rho=total_rho_gs(ispin))
1133 CALL pw_axpy(rho_g_gs(ispin), rho_tot_gspace_gs)
1138 CALL pw_axpy(local_rho_set_gs%rho0_mpole%rho0_s_gs, rho_tot_gspace_gs)
1139 IF (dft_control%qs_control%gapw_control%nopaw_as_gpw)
THEN
1140 CALL get_qs_env(qs_env=qs_env, rho_core=rho_core)
1141 CALL pw_axpy(rho_core, rho_tot_gspace_gs)
1144 CALL auxbas_pw_pool%create_pw(v_hartree_gspace_gs)
1145 CALL auxbas_pw_pool%create_pw(v_hartree_rspace_gs)
1146 NULLIFY (hartree_local_gs)
1149 CALL pw_poisson_solve(poisson_env, rho_tot_gspace_gs, hartree_gs, v_hartree_gspace_gs)
1150 CALL pw_transfer(v_hartree_gspace_gs, v_hartree_rspace_gs)
1151 CALL pw_scale(v_hartree_rspace_gs, v_hartree_rspace_gs%pw_grid%dvol)
1158 cpassert(.NOT. use_virial)
1159 IF (debug_forces) fodeb(1:3) = force(1)%g0s_Vh_elec(1:3, 1)
1160 CALL vh_1c_gg_integrals(qs_env, hartree_gs, hartree_local_gs%ecoul_1c, local_rho_set_t, para_env, tddft=.true., &
1161 local_rho_set_2nd=local_rho_set_gs, core_2nd=.false.)
1164 local_rho_set=local_rho_set_t, local_rho_set_2nd=local_rho_set_gs)
1165 IF (debug_forces)
THEN
1166 fodeb(1:3) = force(1)%g0s_Vh_elec(1:3, 1) - fodeb(1:3)
1167 CALL para_env%sum(fodeb)
1168 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: (T+Dz)*dVh[D^GS]PAWg0", fodeb
1171 IF (gapw .OR. gapw_xc)
THEN
1174 NULLIFY (local_rho_set_vxc)
1177 qs_kind_set, dft_control, para_env)
1179 qs_kind_set, oce, sab_orb, para_env)
1182 CALL calculate_vxc_atom(qs_env, .false., exc1=hartree_gs, xc_section_external=xc_section, &
1183 rho_atom_set_external=local_rho_set_vxc%rho_atom_set)
1187 CALL auxbas_pw_pool%create_pw(vhxc_rspace)
1191 IF (use_virial)
THEN
1192 pv_loc = virial%pv_virial
1195 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
1196 IF (debug_stress .AND. use_virial) stdeb = virial%pv_virial
1197 IF (gapw .OR. gapw_xc)
THEN
1199 DO ispin = 1, nspins
1202 CALL pw_transfer(v_hartree_rspace_gs, vhxc_rspace)
1203 ELSEIF (gapw_xc)
THEN
1206 CALL integrate_v_rspace(v_rspace=vhxc_rspace, &
1207 hmat=scrm(ispin), pmat=mpa(ispin), &
1208 qs_env=qs_env, gapw=gapw, &
1209 calculate_forces=.true.)
1212 DO ispin = 1, nspins
1214 CALL pw_axpy(vxc_rspace(ispin), vhxc_rspace)
1215 CALL integrate_v_rspace(v_rspace=vhxc_rspace, &
1216 hmat=scrm(ispin), pmat=mpa(ispin), &
1217 qs_env=qs_env, gapw=(gapw .OR. gapw_xc), &
1218 calculate_forces=.true.)
1222 DO ispin = 1, nspins
1224 CALL pw_axpy(vxc_rspace(ispin), vhxc_rspace)
1225 CALL integrate_v_rspace(v_rspace=vhxc_rspace, &
1226 hmat=scrm(ispin), pmat=mpa(ispin), &
1227 qs_env=qs_env, gapw=gapw, calculate_forces=.true.)
1231 IF (debug_forces)
THEN
1232 fodeb(1:3) = force(1)%rho_elec(1:3, 1) - fodeb(1:3)
1233 CALL para_env%sum(fodeb)
1234 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: (T+Dz)*dVhxc[D^GS] ", fodeb
1236 IF (debug_stress .AND. use_virial)
THEN
1237 stdeb = fconv*(virial%pv_virial - pv_loc)
1238 CALL para_env%sum(stdeb)
1239 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1243 IF (gapw .OR. gapw_xc)
THEN
1246 IF (debug_forces) fodeb(1:3) = force(1)%Vhxc_atom(1:3, 1)
1247 IF (gapw)
CALL update_ks_atom(qs_env, scrm, mpa, forces=.true., tddft=.false., &
1248 rho_atom_external=local_rho_set_gs%rho_atom_set)
1250 rho_atom_external=local_rho_set_vxc%rho_atom_set)
1251 IF (debug_forces)
THEN
1252 fodeb(1:3) = force(1)%Vhxc_atom(1:3, 1) - fodeb(1:3)
1253 CALL para_env%sum(fodeb)
1254 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: (T+Dz)*dVhxc[D^GS]PAW ", fodeb
1263 CALL auxbas_pw_pool%give_back_pw(v_hartree_gspace_gs)
1264 CALL auxbas_pw_pool%give_back_pw(v_hartree_rspace_gs)
1266 CALL auxbas_pw_pool%give_back_pw(rho_tot_gspace_gs)
1267 IF (
ASSOCIATED(rho_r_gs))
THEN
1268 DO ispin = 1, nspins
1269 CALL auxbas_pw_pool%give_back_pw(rho_r_gs(ispin))
1271 DEALLOCATE (rho_r_gs)
1273 IF (
ASSOCIATED(rho_g_gs))
THEN
1274 DO ispin = 1, nspins
1275 CALL auxbas_pw_pool%give_back_pw(rho_g_gs(ispin))
1277 DEALLOCATE (rho_g_gs)
1281 IF (
ASSOCIATED(vtau_rspace))
THEN
1282 cpassert(.NOT. (gapw .OR. gapw_xc))
1283 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
1284 IF (debug_stress .AND. use_virial) stdeb = virial%pv_virial
1285 DO ispin = 1, nspins
1286 CALL integrate_v_rspace(v_rspace=vtau_rspace(ispin), &
1287 hmat=scrm(ispin), pmat=mpa(ispin), &
1288 qs_env=qs_env, gapw=(gapw .OR. gapw_xc), &
1289 calculate_forces=.true., compute_tau=.true.)
1291 IF (debug_forces)
THEN
1292 fodeb(1:3) = force(1)%rho_elec(1:3, 1) - fodeb(1:3)
1293 CALL para_env%sum(fodeb)
1294 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Pz*dVxc_tau ", fodeb
1296 IF (debug_stress .AND. use_virial)
THEN
1297 stdeb = fconv*(virial%pv_virial - pv_loc)
1298 CALL para_env%sum(stdeb)
1299 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1303 CALL auxbas_pw_pool%give_back_pw(vhxc_rspace)
1306 IF (use_virial)
THEN
1307 virial%pv_ehartree = virial%pv_ehartree + (virial%pv_virial - pv_loc)
1312 IF (dft_control%qs_control%do_kg)
THEN
1317 IF (use_virial)
THEN
1318 pv_loc = virial%pv_virial
1321 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
1324 ekin_mol=ekin_mol, &
1325 calc_force=.true., &
1326 do_kernel=.false., &
1328 IF (debug_forces)
THEN
1329 fodeb(1:3) = force(1)%rho_elec(1:3, 1) - fodeb(1:3)
1330 CALL para_env%sum(fodeb)
1331 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Pz*dVkg ", fodeb
1333 IF (debug_stress .AND. use_virial)
THEN
1336 stdeb = 1.0_dp*fconv*ekin_mol
1337 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1340 stdeb = fconv*(virial%pv_virial - pv_loc)
1341 CALL para_env%sum(stdeb)
1342 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1345 stdeb = fconv*virial%pv_xc
1346 CALL para_env%sum(stdeb)
1347 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1350 IF (use_virial)
THEN
1352 virial%pv_ehartree = virial%pv_ehartree + (virial%pv_virial - pv_loc)
1363 ALLOCATE (rhoz_r(nspins), rhoz_g(nspins))
1364 DO ispin = 1, nspins
1365 CALL auxbas_pw_pool%create_pw(rhoz_r(ispin))
1366 CALL auxbas_pw_pool%create_pw(rhoz_g(ispin))
1368 CALL auxbas_pw_pool%create_pw(rhoz_tot_gspace)
1369 CALL auxbas_pw_pool%create_pw(zv_hartree_rspace)
1370 CALL auxbas_pw_pool%create_pw(zv_hartree_gspace)
1373 DO ispin = 1, nspins
1375 rho=rhoz_r(ispin), rho_gspace=rhoz_g(ispin), &
1377 CALL pw_axpy(rhoz_g(ispin), rhoz_tot_gspace)
1381 ALLOCATE (rhoz_r_xc(nspins), rhoz_g_xc(nspins))
1382 DO ispin = 1, nspins
1383 CALL auxbas_pw_pool%create_pw(rhoz_r_xc(ispin))
1384 CALL auxbas_pw_pool%create_pw(rhoz_g_xc(ispin))
1386 DO ispin = 1, nspins
1388 rho=rhoz_r_xc(ispin), rho_gspace=rhoz_g_xc(ispin), &
1393 IF (
ASSOCIATED(vtau_rspace))
THEN
1394 cpassert(.NOT. (gapw .OR. gapw_xc))
1397 ALLOCATE (tauz_r(nspins))
1398 CALL auxbas_pw_pool%create_pw(work_g)
1399 DO ispin = 1, nspins
1400 CALL auxbas_pw_pool%create_pw(tauz_r(ispin))
1402 rho=tauz_r(ispin), rho_gspace=work_g, &
1405 CALL auxbas_pw_pool%give_back_pw(work_g)
1410 IF (
PRESENT(rhopz_r))
THEN
1411 DO ispin = 1, nspins
1412 CALL pw_copy(rhoz_r(ispin), rhopz_r(ispin))
1419 IF (use_virial)
THEN
1422 CALL auxbas_pw_pool%create_pw(rho_tot_gspace)
1427 h_stress(:, :) = 0.0_dp
1435 density=rhoz_tot_gspace, &
1436 ehartree=ehartree, &
1437 vhartree=zv_hartree_gspace, &
1438 h_stress=h_stress, &
1439 aux_density=rho_tot_gspace)
1441 CALL auxbas_pw_pool%give_back_pw(rho_tot_gspace)
1444 virial%pv_ehartree = virial%pv_ehartree + 2.0_dp*h_stress/real(para_env%num_pe,
dp)
1445 virial%pv_virial = virial%pv_virial + 2.0_dp*h_stress/real(para_env%num_pe,
dp)
1447 IF (debug_stress)
THEN
1448 stdeb = -1.0_dp*fconv*ehartree
1449 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1451 stdeb = -1.0_dp*fconv*ehartree
1452 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1454 stdeb = fconv*(h_stress/real(para_env%num_pe,
dp))
1455 CALL para_env%sum(stdeb)
1456 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1458 stdeb = fconv*(h_stress/real(para_env%num_pe,
dp))
1459 CALL para_env%sum(stdeb)
1460 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1467 DO ispin = 1, nspins
1469 vxc_rspace(ispin)%pw_grid%dvol
1471 IF (
ASSOCIATED(vtau_rspace))
THEN
1472 DO ispin = 1, nspins
1474 vtau_rspace(ispin)%pw_grid%dvol
1479 IF (dft_control%qs_control%do_kg)
THEN
1482 exc = exc - ekin_mol
1486 IF (debug_stress)
THEN
1487 stdeb = -1.0_dp*fconv*exc
1488 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1497 CALL pw_axpy(local_rho_set_t%rho0_mpole%rho0_s_gs, rhoz_tot_gspace)
1499 CALL pw_poisson_solve(poisson_env, rhoz_tot_gspace, ehartree, zv_hartree_gspace)
1502 IF (gapw .OR. gapw_xc)
THEN
1506 IF (debug_forces) fodeb(1:3) = force(1)%rho_core(1:3, 1)
1507 IF (debug_stress .AND. use_virial) stdeb = virial%pv_ehartree
1508 CALL pw_transfer(zv_hartree_gspace, zv_hartree_rspace)
1509 CALL pw_scale(zv_hartree_rspace, zv_hartree_rspace%pw_grid%dvol)
1511 CALL integrate_v_core_rspace(zv_hartree_rspace, qs_env)
1512 IF (debug_forces)
THEN
1513 fodeb(1:3) = force(1)%rho_core(1:3, 1) - fodeb(1:3)
1514 CALL para_env%sum(fodeb)
1515 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Vh(rhoz)*dncore ", fodeb
1517 IF (debug_stress .AND. use_virial)
THEN
1518 stdeb = fconv*(virial%pv_ehartree - stdeb)
1519 CALL para_env%sum(stdeb)
1520 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1526 CALL get_qs_env(qs_env=qs_env, rho_xc=rho_xc)
1530 IF (dft_control%do_admm)
THEN
1532 xc_section => admm_env%xc_section_primary
1537 IF (use_virial)
THEN
1538 virial%pv_xc = 0.0_dp
1541 NULLIFY (v_xc, v_xc_tau)
1544 rho=rho_xc, rho1_r=rhoz_r_xc, rho1_g=rhoz_g_xc, tau1_r=tauz_r_xc, &
1545 xc_section=xc_section, compute_virial=use_virial, virial_xc=virial%pv_xc)
1548 rho=rho, rho1_r=rhoz_r, rho1_g=rhoz_g, tau1_r=tauz_r, &
1549 xc_section=xc_section, compute_virial=use_virial, virial_xc=virial%pv_xc)
1552 IF (gapw .OR. gapw_xc)
THEN
1554 NULLIFY (local_rho_set_t)
1557 qs_kind_set, dft_control, para_env)
1558 CALL init_rho0(local_rho_set_t, qs_env, dft_control%qs_control%gapw_control, &
1562 qs_kind_set, oce, sab_orb, para_env)
1564 NULLIFY (local_rho_set_gs)
1567 qs_kind_set, dft_control, para_env)
1568 CALL init_rho0(local_rho_set_gs, qs_env, dft_control%qs_control%gapw_control)
1571 qs_kind_set, oce, sab_orb, para_env)
1574 ALLOCATE (rho_r_t(nspins), rho_g_t(nspins))
1575 DO ispin = 1, nspins
1576 CALL auxbas_pw_pool%create_pw(rho_r_t(ispin))
1577 CALL auxbas_pw_pool%create_pw(rho_g_t(ispin))
1579 CALL auxbas_pw_pool%create_pw(rho_tot_gspace_t)
1580 total_rho_t = 0.0_dp
1581 CALL pw_zero(rho_tot_gspace_t)
1582 DO ispin = 1, nspins
1584 rho=rho_r_t(ispin), &
1585 rho_gspace=rho_g_t(ispin), &
1587 total_rho=total_rho_t(ispin))
1588 CALL pw_axpy(rho_g_t(ispin), rho_tot_gspace_t)
1592 CALL pw_axpy(local_rho_set_t%rho0_mpole%rho0_s_gs, rho_tot_gspace_t)
1594 CALL auxbas_pw_pool%create_pw(v_hartree_gspace_t)
1595 CALL auxbas_pw_pool%create_pw(v_hartree_rspace_t)
1596 NULLIFY (hartree_local_t)
1599 CALL pw_poisson_solve(poisson_env, rho_tot_gspace_t, hartree_t, v_hartree_gspace_t)
1600 CALL pw_transfer(v_hartree_gspace_t, v_hartree_rspace_t)
1601 CALL pw_scale(v_hartree_rspace_t, v_hartree_rspace_t%pw_grid%dvol)
1603 IF (debug_forces) fodeb(1:3) = force(1)%g0s_Vh_elec(1:3, 1)
1604 CALL vh_1c_gg_integrals(qs_env, hartree_t, hartree_local_t%ecoul_1c, local_rho_set_gs, para_env, tddft=.false., &
1605 local_rho_set_2nd=local_rho_set_t, core_2nd=.true.)
1607 local_rho_set=local_rho_set_gs, local_rho_set_2nd=local_rho_set_t)
1608 IF (debug_forces)
THEN
1609 fodeb(1:3) = force(1)%g0s_Vh_elec(1:3, 1) - fodeb(1:3)
1610 CALL para_env%sum(fodeb)
1611 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Vh(T)*dncore PAWg0", fodeb
1616 IF (gapw .OR. gapw_xc)
THEN
1620 NULLIFY (local_rho_set_f)
1623 qs_kind_set, dft_control, para_env)
1625 qs_kind_set, oce, sab_orb, para_env)
1629 local_rho_set_f%rho_atom_set, &
1630 qs_env, xc_section, para_env, &
1636 IF (use_virial)
THEN
1637 virial%pv_exc = virial%pv_exc + virial%pv_xc
1638 virial%pv_virial = virial%pv_virial + virial%pv_xc
1641 IF (debug_stress .AND. use_virial)
THEN
1642 stdeb = 1.0_dp*fconv*virial%pv_xc
1643 CALL para_env%sum(stdeb)
1644 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1649 IF (use_virial)
THEN
1650 pv_loc = virial%pv_virial
1655 IF (debug_stress .AND. use_virial) stdeb = virial%pv_virial
1657 DO ispin = 1, nspins
1658 CALL pw_scale(v_xc(ispin), v_xc(ispin)%pw_grid%dvol)
1660 IF ((.NOT. (gapw)) .AND. (.NOT. gapw_xc))
THEN
1661 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
1662 DO ispin = 1, nspins
1663 CALL pw_axpy(zv_hartree_rspace, v_xc(ispin))
1664 CALL integrate_v_rspace(qs_env=qs_env, &
1665 v_rspace=v_xc(ispin), &
1666 hmat=matrix_hz(ispin), &
1667 pmat=matrix_p(ispin, 1), &
1669 calculate_forces=.true.)
1671 IF (debug_forces)
THEN
1672 fodeb(1:3) = force(1)%rho_elec(1:3, 1) - fodeb(1:3)
1673 CALL para_env%sum(fodeb)
1674 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Pin*dKhxc*rhoz ", fodeb
1677 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
1679 DO ispin = 1, nspins
1680 CALL integrate_v_rspace(qs_env=qs_env, &
1681 v_rspace=v_xc(ispin), &
1682 hmat=matrix_hz(ispin), &
1683 pmat=matrix_p(ispin, 1), &
1685 calculate_forces=.true.)
1689 DO ispin = 1, nspins
1692 CALL pw_axpy(v_hartree_rspace_t, v_xc(ispin))
1693 ELSEIF (gapw_xc)
THEN
1694 CALL pw_axpy(zv_hartree_rspace, v_xc(ispin))
1696 CALL integrate_v_rspace(qs_env=qs_env, &
1697 v_rspace=v_xc(ispin), &
1698 hmat=matrix_ht(ispin), &
1699 pmat=matrix_p(ispin, 1), &
1701 calculate_forces=.true.)
1703 IF (debug_forces)
THEN
1704 fodeb(1:3) = force(1)%rho_elec(1:3, 1) - fodeb(1:3)
1705 CALL para_env%sum(fodeb)
1706 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Pin*dKhxc*rhoz ", fodeb
1710 IF (gapw .OR. gapw_xc)
THEN
1713 IF (debug_forces) fodeb(1:3) = force(1)%Vhxc_atom(1:3, 1)
1714 CALL update_ks_atom(qs_env, matrix_hz, matrix_p, forces=.true., tddft=.false., &
1715 rho_atom_external=local_rho_set_f%rho_atom_set)
1716 IF (debug_forces)
THEN
1717 fodeb(1:3) = force(1)%Vhxc_atom(1:3, 1) - fodeb(1:3)
1718 CALL para_env%sum(fodeb)
1719 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: P^GS*dKxc*(Dz+T) PAW", fodeb
1724 IF (debug_forces) fodeb(1:3) = force(1)%Vhxc_atom(1:3, 1)
1725 CALL update_ks_atom(qs_env, matrix_ht, matrix_p, forces=.true., tddft=.false., &
1726 rho_atom_external=local_rho_set_t%rho_atom_set)
1727 IF (debug_forces)
THEN
1728 fodeb(1:3) = force(1)%Vhxc_atom(1:3, 1) - fodeb(1:3)
1729 CALL para_env%sum(fodeb)
1730 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: P^GS*dKh*(Dz+T) PAW", fodeb
1734 DO ispin = 1, nspins
1735 CALL dbcsr_add(matrix_hz(ispin)%matrix, matrix_ht(ispin)%matrix, 1.0_dp, 1.0_dp)
1746 CALL auxbas_pw_pool%give_back_pw(v_hartree_gspace_t)
1747 CALL auxbas_pw_pool%give_back_pw(v_hartree_rspace_t)
1749 CALL auxbas_pw_pool%give_back_pw(rho_tot_gspace_t)
1750 DO ispin = 1, nspins
1751 CALL auxbas_pw_pool%give_back_pw(rho_r_t(ispin))
1752 CALL auxbas_pw_pool%give_back_pw(rho_g_t(ispin))
1754 DEALLOCATE (rho_r_t, rho_g_t)
1757 IF (debug_stress .AND. use_virial)
THEN
1758 stdeb = fconv*(virial%pv_virial - stdeb)
1759 CALL para_env%sum(stdeb)
1760 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1764 IF (
ASSOCIATED(v_xc_tau))
THEN
1765 cpassert(.NOT. (gapw .OR. gapw_xc))
1766 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
1767 IF (debug_stress .AND. use_virial) stdeb = virial%pv_virial
1768 DO ispin = 1, nspins
1769 CALL pw_scale(v_xc_tau(ispin), v_xc_tau(ispin)%pw_grid%dvol)
1770 CALL integrate_v_rspace(qs_env=qs_env, &
1771 v_rspace=v_xc_tau(ispin), &
1772 hmat=matrix_hz(ispin), &
1773 pmat=matrix_p(ispin, 1), &
1774 compute_tau=.true., &
1775 gapw=(gapw .OR. gapw_xc), &
1776 calculate_forces=.true.)
1778 IF (debug_forces)
THEN
1779 fodeb(1:3) = force(1)%rho_elec(1:3, 1) - fodeb(1:3)
1780 CALL para_env%sum(fodeb)
1781 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Pin*dKtau*tauz ", fodeb
1784 IF (debug_stress .AND. use_virial)
THEN
1785 stdeb = fconv*(virial%pv_virial - stdeb)
1786 CALL para_env%sum(stdeb)
1787 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1791 IF (use_virial)
THEN
1792 virial%pv_ehartree = virial%pv_ehartree + (virial%pv_virial - pv_loc)
1797 IF (dft_control%qs_control%do_kg)
THEN
1800 IF (use_virial)
THEN
1801 pv_loc = virial%pv_virial
1804 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
1805 IF (use_virial) virial%pv_xc = 0.0_dp
1807 ks_matrix=matrix_hz, &
1808 ekin_mol=ekin_mol, &
1809 calc_force=.true., &
1813 IF (debug_forces)
THEN
1814 fodeb(1:3) = force(1)%rho_elec(1:3, 1) - fodeb(1:3)
1815 CALL para_env%sum(fodeb)
1816 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Pin*d(Kkg)*rhoz ", fodeb
1818 IF (debug_stress .AND. use_virial)
THEN
1819 stdeb = fconv*(virial%pv_virial - pv_loc)
1820 CALL para_env%sum(stdeb)
1821 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1824 stdeb = fconv*(virial%pv_xc)
1825 CALL para_env%sum(stdeb)
1826 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1831 IF (use_virial)
THEN
1833 virial%pv_ehartree = virial%pv_ehartree + (virial%pv_virial - pv_loc)
1836 virial%pv_exc = virial%pv_exc - virial%pv_xc
1837 virial%pv_virial = virial%pv_virial - virial%pv_xc
1838 virial%pv_xc = 0.0_dp
1842 CALL auxbas_pw_pool%give_back_pw(rhoz_tot_gspace)
1843 CALL auxbas_pw_pool%give_back_pw(zv_hartree_gspace)
1844 CALL auxbas_pw_pool%give_back_pw(zv_hartree_rspace)
1845 DO ispin = 1, nspins
1846 CALL auxbas_pw_pool%give_back_pw(rhoz_r(ispin))
1847 CALL auxbas_pw_pool%give_back_pw(rhoz_g(ispin))
1848 CALL auxbas_pw_pool%give_back_pw(v_xc(ispin))
1850 DEALLOCATE (rhoz_r, rhoz_g, v_xc)
1852 DO ispin = 1, nspins
1853 CALL auxbas_pw_pool%give_back_pw(rhoz_r_xc(ispin))
1854 CALL auxbas_pw_pool%give_back_pw(rhoz_g_xc(ispin))
1856 DEALLOCATE (rhoz_r_xc, rhoz_g_xc)
1858 IF (
ASSOCIATED(v_xc_tau))
THEN
1859 DO ispin = 1, nspins
1860 CALL auxbas_pw_pool%give_back_pw(tauz_r(ispin))
1861 CALL auxbas_pw_pool%give_back_pw(v_xc_tau(ispin))
1863 DEALLOCATE (tauz_r, v_xc_tau)
1865 IF (debug_forces)
THEN
1866 ALLOCATE (ftot3(3, natom))
1868 fodeb(1:3) = ftot3(1:3, 1) - ftot2(1:3, 1)
1869 CALL para_env%sum(fodeb)
1870 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Pin*V(rhoz)", fodeb
1879 IF (dft_control%do_admm)
THEN
1881 exc_aux_fit = 0.0_dp
1885 NULLIFY (mpz, mhz, mhx, mhy)
1889 CALL get_admm_env(admm_env, rho_aux_fit=rho_aux_fit, matrix_s_aux_fit=scrm, &
1890 task_list_aux_fit=task_list_aux_fit)
1892 NULLIFY (mpz, mhz, mhx, mhy)
1896 DO ispin = 1, nspins
1897 ALLOCATE (mhx(ispin, 1)%matrix)
1898 CALL dbcsr_create(mhx(ispin, 1)%matrix, template=scrm(1)%matrix)
1899 CALL dbcsr_copy(mhx(ispin, 1)%matrix, scrm(1)%matrix)
1900 CALL dbcsr_set(mhx(ispin, 1)%matrix, 0.0_dp)
1901 ALLOCATE (mhy(ispin, 1)%matrix)
1902 CALL dbcsr_create(mhy(ispin, 1)%matrix, template=scrm(1)%matrix)
1903 CALL dbcsr_copy(mhy(ispin, 1)%matrix, scrm(1)%matrix)
1904 CALL dbcsr_set(mhy(ispin, 1)%matrix, 0.0_dp)
1905 ALLOCATE (mpz(ispin, 1)%matrix)
1907 CALL dbcsr_create(mpz(ispin, 1)%matrix, template=p_env%p1_admm(ispin)%matrix)
1908 CALL dbcsr_copy(mpz(ispin, 1)%matrix, p_env%p1_admm(ispin)%matrix)
1909 CALL dbcsr_add(mpz(ispin, 1)%matrix, ex_env%matrix_pe_admm(ispin)%matrix, &
1912 CALL dbcsr_create(mpz(ispin, 1)%matrix, template=matrix_pz_admm(ispin)%matrix)
1913 CALL dbcsr_copy(mpz(ispin, 1)%matrix, matrix_pz_admm(ispin)%matrix)
1917 xc_section => admm_env%xc_section_aux
1920 IF (use_virial)
THEN
1921 pv_loc = virial%pv_virial
1924 basis_type =
"AUX_FIT"
1925 task_list => task_list_aux_fit
1926 IF (admm_env%do_gapw)
THEN
1927 basis_type =
"AUX_FIT_SOFT"
1928 task_list => admm_env%admm_gapw_env%task_list
1931 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
1932 IF (debug_stress .AND. use_virial) stdeb = virial%pv_virial
1933 DO ispin = 1, nspins
1934 CALL integrate_v_rspace(v_rspace=vadmm_rspace(ispin), &
1935 hmat=mhx(ispin, 1), pmat=mpz(ispin, 1), &
1936 qs_env=qs_env, calculate_forces=.true., &
1937 basis_type=basis_type, task_list_external=task_list)
1939 IF (debug_forces)
THEN
1940 fodeb(1:3) = force(1)%rho_elec(1:3, 1) - fodeb(1:3)
1941 CALL para_env%sum(fodeb)
1942 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Pz*Vxc(rho_admm)", fodeb
1944 IF (debug_stress .AND. use_virial)
THEN
1945 stdeb = fconv*(virial%pv_virial - pv_loc)
1946 CALL para_env%sum(stdeb)
1947 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
1951 IF (use_virial)
THEN
1952 virial%pv_ehartree = virial%pv_ehartree + (virial%pv_virial - pv_loc)
1955 IF (admm_env%do_gapw)
THEN
1957 IF (debug_forces) fodeb(1:3) = force(1)%Vhxc_atom(1:3, 1)
1958 CALL update_ks_atom(qs_env, mhx(:, 1), mpz(:, 1), forces=.true., tddft=.false., &
1959 rho_atom_external=admm_env%admm_gapw_env%local_rho_set%rho_atom_set, &
1960 kind_set_external=admm_env%admm_gapw_env%admm_kind_set, &
1961 oce_external=admm_env%admm_gapw_env%oce, &
1962 sab_external=sab_aux_fit)
1963 IF (debug_forces)
THEN
1964 fodeb(1:3) = force(1)%Vhxc_atom(1:3, 1) - fodeb(1:3)
1965 CALL para_env%sum(fodeb)
1966 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Pz*Vxc(rho_admm)PAW", fodeb
1970 NULLIFY (rho_g_aux, rho_r_aux, tau_r_aux)
1971 CALL qs_rho_get(rho_aux_fit, rho_r=rho_r_aux, rho_g=rho_g_aux, tau_r=tau_r_aux)
1973 NULLIFY (rhoz_g_aux, rhoz_r_aux)
1974 ALLOCATE (rhoz_r_aux(nspins), rhoz_g_aux(nspins))
1975 DO ispin = 1, nspins
1976 CALL auxbas_pw_pool%create_pw(rhoz_r_aux(ispin))
1977 CALL auxbas_pw_pool%create_pw(rhoz_g_aux(ispin))
1979 DO ispin = 1, nspins
1981 rho=rhoz_r_aux(ispin), rho_gspace=rhoz_g_aux(ispin), &
1982 basis_type=basis_type, task_list_external=task_list)
1986 IF (use_virial)
THEN
1990 DO ispin = 1, nspins
1991 exc_aux_fit = exc_aux_fit +
pw_integral_ab(rhoz_r_aux(ispin), vadmm_rspace(ispin))/ &
1992 vadmm_rspace(ispin)%pw_grid%dvol
1995 IF (debug_stress)
THEN
1996 stdeb = -1.0_dp*fconv*exc_aux_fit
1997 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T43,2(1X,ES19.11))") &
2005 IF (use_virial) virial%pv_xc = 0.0_dp
2011 rho1_r=rhoz_r_aux, &
2012 rho1_g=rhoz_g_aux, &
2014 xc_section=xc_section, &
2015 compute_virial=use_virial, &
2016 virial_xc=virial%pv_xc)
2019 IF (use_virial)
THEN
2020 virial%pv_exc = virial%pv_exc + virial%pv_xc
2021 virial%pv_virial = virial%pv_virial + virial%pv_xc
2024 IF (debug_stress .AND. use_virial)
THEN
2025 stdeb = 1.0_dp*fconv*virial%pv_xc
2026 CALL para_env%sum(stdeb)
2027 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2031 CALL qs_rho_get(rho_aux_fit, rho_ao_kp=matrix_p)
2033 IF (use_virial)
THEN
2034 virial%pv_ehartree = virial%pv_ehartree + (virial%pv_virial - pv_loc)
2036 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
2037 IF (debug_stress .AND. use_virial) stdeb = virial%pv_virial
2038 DO ispin = 1, nspins
2039 CALL dbcsr_set(mhy(ispin, 1)%matrix, 0.0_dp)
2040 CALL pw_scale(v_xc(ispin), v_xc(ispin)%pw_grid%dvol)
2041 CALL integrate_v_rspace(qs_env=qs_env, v_rspace=v_xc(ispin), &
2042 hmat=mhy(ispin, 1), pmat=matrix_p(ispin, 1), &
2043 calculate_forces=.true., &
2044 basis_type=basis_type, task_list_external=task_list)
2046 IF (debug_forces)
THEN
2047 fodeb(1:3) = force(1)%rho_elec(1:3, 1) - fodeb(1:3)
2048 CALL para_env%sum(fodeb)
2049 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Pin*dK*rhoz_admm ", fodeb
2051 IF (debug_stress .AND. use_virial)
THEN
2052 stdeb = fconv*(virial%pv_virial - pv_loc)
2053 CALL para_env%sum(stdeb)
2054 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2058 IF (use_virial)
THEN
2059 virial%pv_ehartree = virial%pv_ehartree + (virial%pv_virial - pv_loc)
2061 DO ispin = 1, nspins
2062 CALL auxbas_pw_pool%give_back_pw(v_xc(ispin))
2063 CALL auxbas_pw_pool%give_back_pw(rhoz_r_aux(ispin))
2064 CALL auxbas_pw_pool%give_back_pw(rhoz_g_aux(ispin))
2066 DEALLOCATE (v_xc, rhoz_r_aux, rhoz_g_aux)
2068 IF (admm_env%do_gapw)
THEN
2071 admm_env%admm_gapw_env%admm_kind_set, dft_control, para_env)
2073 admm_env%admm_gapw_env%admm_kind_set, &
2074 admm_env%admm_gapw_env%oce, sab_aux_fit, para_env)
2076 do_rho0=.false., kind_set_external=admm_env%admm_gapw_env%admm_kind_set)
2079 local_rhoz_set_admm%rho_atom_set, &
2080 qs_env, xc_section, para_env, do_triplet=.false., &
2081 kind_set_external=admm_env%admm_gapw_env%admm_kind_set)
2083 IF (debug_forces) fodeb(1:3) = force(1)%Vhxc_atom(1:3, 1)
2084 CALL update_ks_atom(qs_env, mhy(:, 1), matrix_p(:, 1), forces=.true., tddft=.false., &
2085 rho_atom_external=local_rhoz_set_admm%rho_atom_set, &
2086 kind_set_external=admm_env%admm_gapw_env%admm_kind_set, &
2087 oce_external=admm_env%admm_gapw_env%oce, &
2088 sab_external=sab_aux_fit)
2089 IF (debug_forces)
THEN
2090 fodeb(1:3) = force(1)%Vhxc_atom(1:3, 1) - fodeb(1:3)
2091 CALL para_env%sum(fodeb)
2092 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Pin*dK*rhoz_admm[PAW] ", fodeb
2097 nao = admm_env%nao_orb
2098 nao_aux = admm_env%nao_aux_fit
2100 CALL dbcsr_create(dbwork, template=matrix_hz(1)%matrix)
2101 DO ispin = 1, nspins
2103 admm_env%work_aux_orb, nao)
2105 1.0_dp, admm_env%A, admm_env%work_aux_orb, 0.0_dp, &
2106 admm_env%work_orb_orb)
2107 CALL dbcsr_copy(dbwork, matrix_hz(ispin)%matrix)
2110 CALL dbcsr_add(matrix_hz(ispin)%matrix, dbwork, 1.0_dp, 1.0_dp)
2127 cpassert(n_rep_hf == 1)
2131 IF (hfx_treat_lsd_in_core) mspin = nspins
2132 IF (use_virial) virial%pv_fock_4c = 0.0_dp
2134 CALL get_qs_env(qs_env=qs_env, rho=rho, x_data=x_data, &
2135 s_mstruct_changed=s_mstruct_changed)
2136 distribute_fock_matrix = .true.
2141 IF (dft_control%do_admm)
THEN
2142 CALL get_qs_env(qs_env=qs_env, admm_env=admm_env)
2143 CALL get_admm_env(admm_env, matrix_s_aux_fit=scrm, rho_aux_fit=rho_aux_fit)
2144 CALL qs_rho_get(rho_aux_fit, rho_ao_kp=matrix_p)
2145 NULLIFY (mpz, mhz, mpd, mhd)
2150 DO ispin = 1, nspins
2151 ALLOCATE (mhz(ispin, 1)%matrix, mhd(ispin, 1)%matrix)
2152 CALL dbcsr_create(mhz(ispin, 1)%matrix, template=scrm(1)%matrix)
2153 CALL dbcsr_create(mhd(ispin, 1)%matrix, template=scrm(1)%matrix)
2154 CALL dbcsr_copy(mhz(ispin, 1)%matrix, scrm(1)%matrix)
2155 CALL dbcsr_copy(mhd(ispin, 1)%matrix, scrm(1)%matrix)
2156 CALL dbcsr_set(mhz(ispin, 1)%matrix, 0.0_dp)
2157 CALL dbcsr_set(mhd(ispin, 1)%matrix, 0.0_dp)
2158 ALLOCATE (mpz(ispin, 1)%matrix)
2160 CALL dbcsr_create(mpz(ispin, 1)%matrix, template=scrm(1)%matrix)
2161 CALL dbcsr_copy(mpz(ispin, 1)%matrix, p_env%p1_admm(ispin)%matrix)
2162 CALL dbcsr_add(mpz(ispin, 1)%matrix, ex_env%matrix_pe_admm(ispin)%matrix, &
2165 CALL dbcsr_create(mpz(ispin, 1)%matrix, template=scrm(1)%matrix)
2166 CALL dbcsr_copy(mpz(ispin, 1)%matrix, matrix_pz_admm(ispin)%matrix)
2168 mpd(ispin, 1)%matrix => matrix_p(ispin, 1)%matrix
2171 IF (x_data(1, 1)%do_hfx_ri)
THEN
2174 CALL hfx_ri_update_ks(qs_env, x_data(1, 1)%ri_data, mhz, eh1, rho_ao=mpz, &
2175 geometry_did_change=s_mstruct_changed, nspins=nspins, &
2176 hf_fraction=x_data(1, 1)%general_parameter%fraction)
2179 CALL hfx_ri_update_ks(qs_env, x_data(1, 1)%ri_data, mhd, eh1, rho_ao=mpd, &
2180 geometry_did_change=s_mstruct_changed, nspins=nspins, &
2181 hf_fraction=x_data(1, 1)%general_parameter%fraction)
2187 para_env, s_mstruct_changed, 1, distribute_fock_matrix, &
2193 para_env, s_mstruct_changed, 1, distribute_fock_matrix, &
2199 cpassert(
ASSOCIATED(admm_env%work_aux_orb))
2200 cpassert(
ASSOCIATED(admm_env%work_orb_orb))
2201 nao = admm_env%nao_orb
2202 nao_aux = admm_env%nao_aux_fit
2204 CALL dbcsr_create(dbwork, template=matrix_hz(1)%matrix)
2205 DO ispin = 1, nspins
2207 admm_env%work_aux_orb, nao)
2209 1.0_dp, admm_env%A, admm_env%work_aux_orb, 0.0_dp, &
2210 admm_env%work_orb_orb)
2211 CALL dbcsr_copy(dbwork, matrix_hz(ispin)%matrix)
2214 CALL dbcsr_add(matrix_hz(ispin)%matrix, dbwork, 1.0_dp, 1.0_dp)
2219 IF (debug_forces) fodeb(1:3) = force(1)%overlap_admm(1:3, 1)
2220 IF (
ASSOCIATED(mhx) .AND.
ASSOCIATED(mhy))
THEN
2221 DO ispin = 1, nspins
2222 CALL dbcsr_add(mhd(ispin, 1)%matrix, mhx(ispin, 1)%matrix, 1.0_dp, 1.0_dp)
2223 CALL dbcsr_add(mhz(ispin, 1)%matrix, mhy(ispin, 1)%matrix, 1.0_dp, 1.0_dp)
2229 IF (debug_forces)
THEN
2230 fodeb(1:3) = force(1)%overlap_admm(1:3, 1) - fodeb(1:3)
2231 CALL para_env%sum(fodeb)
2232 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Pz*hfx*S' ", fodeb
2237 IF (
ASSOCIATED(mhx) .AND.
ASSOCIATED(mhy))
THEN
2246 ALLOCATE (mpz(nspins, 1), mhz(nspins, 1))
2247 DO ispin = 1, nspins
2248 mhz(ispin, 1)%matrix => matrix_hz(ispin)%matrix
2249 mpz(ispin, 1)%matrix => mpa(ispin)%matrix
2252 IF (x_data(1, 1)%do_hfx_ri)
THEN
2255 CALL hfx_ri_update_ks(qs_env, x_data(1, 1)%ri_data, mhz, eh1, rho_ao=mpz, &
2256 geometry_did_change=s_mstruct_changed, nspins=nspins, &
2257 hf_fraction=x_data(1, 1)%general_parameter%fraction)
2262 para_env, s_mstruct_changed, 1, distribute_fock_matrix, &
2266 DEALLOCATE (mhz, mpz)
2274 IF (debug_forces) fodeb(1:3) = force(1)%fock_4c(1:3, 1)
2275 IF (dft_control%do_admm)
THEN
2279 CALL qs_rho_get(rho_aux_fit, rho_ao_kp=matrix_p)
2280 NULLIFY (matrix_pza)
2282 DO ispin = 1, nspins
2283 ALLOCATE (matrix_pza(ispin)%matrix)
2285 CALL dbcsr_create(matrix_pza(ispin)%matrix, template=p_env%p1_admm(ispin)%matrix)
2286 CALL dbcsr_copy(matrix_pza(ispin)%matrix, p_env%p1_admm(ispin)%matrix)
2287 CALL dbcsr_add(matrix_pza(ispin)%matrix, ex_env%matrix_pe_admm(ispin)%matrix, &
2290 CALL dbcsr_create(matrix_pza(ispin)%matrix, template=matrix_pz_admm(ispin)%matrix)
2291 CALL dbcsr_copy(matrix_pza(ispin)%matrix, matrix_pz_admm(ispin)%matrix)
2294 IF (x_data(1, 1)%do_hfx_ri)
THEN
2297 x_data(1, 1)%general_parameter%fraction, &
2298 rho_ao=matrix_p, rho_ao_resp=matrix_pza, &
2299 use_virial=use_virial, resp_only=resp_only)
2302 1, use_virial, resp_only=resp_only)
2310 IF (x_data(1, 1)%do_hfx_ri)
THEN
2313 x_data(1, 1)%general_parameter%fraction, &
2314 rho_ao=matrix_p, rho_ao_resp=mpa, &
2315 use_virial=use_virial, resp_only=resp_only)
2318 1, use_virial, resp_only=resp_only)
2322 IF (use_virial)
THEN
2323 virial%pv_exx = virial%pv_exx - virial%pv_fock_4c
2324 virial%pv_virial = virial%pv_virial - virial%pv_fock_4c
2325 virial%pv_calculate = .false.
2328 IF (debug_forces)
THEN
2329 fodeb(1:3) = force(1)%fock_4c(1:3, 1) - fodeb(1:3)
2330 CALL para_env%sum(fodeb)
2331 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Pz*hfx ", fodeb
2333 IF (debug_stress .AND. use_virial)
THEN
2334 stdeb = -1.0_dp*fconv*virial%pv_fock_4c
2335 CALL para_env%sum(stdeb)
2336 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2343 IF (use_virial)
THEN
2345 zehartree = zehartree + 2.0_dp*ehartree
2348 IF (dft_control%do_admm)
THEN
2349 zexc_aux_fit = zexc_aux_fit + exc_aux_fit
2356 IF (dft_control%qs_control%do_ls_scf)
THEN
2358 eps_filter = dft_control%qs_control%eps_filter_matrix
2359 CALL calculate_whz_ao_matrix(qs_env, matrix_hz, matrix_wz, eps_filter)
2362 matrix_wz => p_env%w1
2365 IF (nspins == 1) focc = 2.0_dp
2367 DO ispin = 1, nspins
2368 CALL get_mo_set(mo_set=mos(ispin), homo=nocc)
2370 matrix_wz(ispin)%matrix, focc, nocc)
2373 IF (nspins == 2)
THEN
2374 CALL dbcsr_add(matrix_wz(1)%matrix, matrix_wz(2)%matrix, &
2375 alpha_scalar=1.0_dp, beta_scalar=1.0_dp)
2378 IF (debug_forces) fodeb(1:3) = force(1)%overlap(1:3, 1)
2379 IF (debug_stress .AND. use_virial) stdeb = virial%pv_overlap
2382 matrix_name=
"OVERLAP MATRIX", &
2383 basis_type_a=
"ORB", basis_type_b=
"ORB", &
2384 sab_nl=sab_orb, calculate_forces=.true., &
2385 matrix_p=matrix_wz(1)%matrix)
2387 IF (
SIZE(matrix_wz, 1) == 2)
THEN
2388 CALL dbcsr_add(matrix_wz(1)%matrix, matrix_wz(2)%matrix, &
2389 alpha_scalar=1.0_dp, beta_scalar=-1.0_dp)
2392 IF (debug_forces)
THEN
2393 fodeb(1:3) = force(1)%overlap(1:3, 1) - fodeb(1:3)
2394 CALL para_env%sum(fodeb)
2395 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Wz*dS ", fodeb
2397 IF (debug_stress .AND. use_virial)
THEN
2398 stdeb = fconv*(virial%pv_overlap - stdeb)
2399 CALL para_env%sum(stdeb)
2400 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2405 IF (debug_forces)
THEN
2407 fodeb(1:3) = ftot2(1:3, 1) - ftot1(1:3, 1)
2408 CALL para_env%sum(fodeb)
2409 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Response Force", fodeb
2410 fodeb(1:3) = ftot2(1:3, 1)
2411 CALL para_env%sum(fodeb)
2412 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Total Force ", fodeb
2413 DEALLOCATE (ftot1, ftot2, ftot3)
2415 IF (debug_stress .AND. use_virial)
THEN
2416 stdeb = fconv*(virial%pv_virial - sttot)
2417 CALL para_env%sum(stdeb)
2418 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2420 stdeb = fconv*(virial%pv_virial)
2421 CALL para_env%sum(stdeb)
2422 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,A,T41,2(1X,ES19.11))") &
2424 IF (iounit > 0)
WRITE (unit=iounit, fmt=
"(T2,3(1X,ES19.11))") &
2425 stdeb(1, 1), stdeb(2, 2), stdeb(3, 3)
2434 CALL timestop(handle)