79 CHARACTER(LEN=3) :: cval1
80 CHARACTER(LEN=3*default_string_length) :: message
81 CHARACTER(LEN=60) :: line
82 CHARACTER(LEN=80),
DIMENSION(:),
POINTER :: cval2
83 CHARACTER(LEN=default_string_length) :: description
84 INTEGER :: i, ip, irep, iw, j, k, np, nrep, &
86 LOGICAL :: check_failed, debug_dipole, &
87 debug_forces, debug_polar, &
88 debug_stress_tensor, skip, &
90 LOGICAL,
ALLOCATABLE,
DIMENSION(:, :) :: do_dof_atom_coor
91 LOGICAL,
DIMENSION(3) :: do_dof_dipole
92 REAL(kind=
dp) :: amplitude, dd, de, derr, difference, dx, &
93 eps_no_error_check, errmax, maxerr, &
94 std_value, sum_of_differences
95 REAL(kind=
dp),
DIMENSION(2) :: numer_energy
96 REAL(kind=
dp),
DIMENSION(3) :: dipole_moment, dipole_numer, err, &
98 REAL(kind=
dp),
DIMENSION(3, 2) :: dipn
99 REAL(kind=
dp),
DIMENSION(3, 3) :: polar_analytic, polar_numeric
100 REAL(kind=
dp),
DIMENSION(9) :: pvals
101 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: analyt_forces, numer_forces
109 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
112 NULLIFY (analyt_forces, numer_forces, subsys, particles)
114 root_section => force_env%root_section
116 CALL force_env_get(force_env, para_env=para_env, subsys=subsys, cell=cell)
121 l_val=debug_stress_tensor)
138 r_val=eps_no_error_check)
139 eps_no_error_check = max(eps_no_error_check, epsilon(0.0_dp))
141 l_val=stop_on_mismatch)
145 do_dof_dipole(1) = (index(cval1,
"X") /= 0)
146 do_dof_dipole(2) = (index(cval1,
"Y") /= 0)
147 do_dof_dipole(3) = (index(cval1,
"Z") /= 0)
149 IF (debug_forces)
THEN
150 np = subsys%particles%n_els
151 ALLOCATE (do_dof_atom_coor(3, np))
154 do_dof_atom_coor = .false.
158 READ (cval2(1), fmt=
"(I10)") k
160 do_dof_atom_coor(1, k) = (index(cval2(2),
"X") /= 0)
161 do_dof_atom_coor(2, k) = (index(cval2(2),
"Y") /= 0)
162 do_dof_atom_coor(3, k) = (index(cval2(2),
"Z") /= 0)
165 do_dof_atom_coor = .true.
172 IF (debug_stress_tensor)
THEN
178 SELECT CASE (stress_tensor)
183 CALL cp_warn(__location__,
"Numerical stress tensor was requested in "// &
184 "the FORCE_EVAL section. Nothing to debug!")
187 CALL cp_warn(__location__,
"Stress tensor calculation was not enabled in "// &
188 "the FORCE_EVAL section. Nothing to debug!")
195 TYPE(
virial_type) :: virial_analytical, virial_numerical
203 calc_stress_tensor=.true.)
206 virial_analytical = virial
214 virial_numerical = virial
218 WRITE (unit=iw, fmt=
"((T2,A))") &
219 "DEBUG| Numerical pv_virial [a.u.]"
220 WRITE (unit=iw, fmt=
"((T2,A,T21,3(1X,F19.12)))") &
221 (
"DEBUG|", virial_numerical%pv_virial(i, 1:3), i=1, 3)
222 WRITE (unit=iw, fmt=
"(/,(T2,A))") &
223 "DEBUG| Analytical pv_virial [a.u.]"
224 WRITE (unit=iw, fmt=
"((T2,A,T21,3(1X,F19.12)))") &
225 (
"DEBUG|", virial_analytical%pv_virial(i, 1:3), i=1, 3)
226 WRITE (unit=iw, fmt=
"(/,(T2,A))") &
227 "DEBUG| Difference pv_virial [a.u.]"
228 WRITE (unit=iw, fmt=
"((T2,A,T21,3(1X,F19.12)))") &
229 (
"DEBUG|", virial_numerical%pv_virial(i, 1:3) - virial_analytical%pv_virial(i, 1:3), i=1, 3)
230 WRITE (unit=iw, fmt=
"(T2,A,T61,F20.12)") &
231 "DEBUG| Sum of differences", &
232 sum(abs(virial_numerical%pv_virial(:, :) - virial_analytical%pv_virial(:, :)))
236 check_failed = .false.
238 WRITE (unit=iw, fmt=
"(/T2,A)") &
239 "DEBUG| Relative error pv_virial"
240 WRITE (unit=iw, fmt=
"(T2,A,T61,ES20.8)") &
241 "DEBUG| Threshold value for error check [a.u.]", eps_no_error_check
246 IF (abs(virial_analytical%pv_virial(i, k)) >= eps_no_error_check)
THEN
247 err(k) = 100.0_dp*(virial_numerical%pv_virial(i, k) - virial_analytical%pv_virial(i, k))/ &
248 virial_analytical%pv_virial(i, k)
249 WRITE (unit=line(20*(k - 1) + 1:20*k), fmt=
"(1X,F17.2,A2)") err(k),
" %"
251 WRITE (unit=line(20*(k - 1) + 1:20*k), fmt=
"(17X,A3)")
"- %"
255 WRITE (unit=iw, fmt=
"(T2,A,T21,A60)") &
258 IF (any(abs(err(1:3)) > maxerr)) check_failed = .true.
261 WRITE (unit=iw, fmt=
"(T2,A,T61,F18.2,A2)") &
262 "DEBUG| Maximum accepted error", maxerr,
" %"
264 IF (check_failed)
THEN
265 message =
"A mismatch between the analytical and the numerical "// &
266 "stress tensor has been detected. Check the implementation "// &
267 "of the stress tensor"
268 IF (stop_on_mismatch)
THEN
269 cpabort(trim(message))
271 cpwarn(trim(message))
278 IF (debug_forces)
THEN
280 particles => subsys%particles%els
281 SELECT CASE (force_env%in_use)
283 CALL get_qs_env(force_env%qs_env, qs_kind_set=qs_kind_set)
291 calc_stress_tensor=.false.)
293 IF (
ASSOCIATED(analyt_forces))
DEALLOCATE (analyt_forces)
294 np = subsys%particles%n_els
295 ALLOCATE (analyt_forces(np, 3))
297 analyt_forces(ip, 1:3) = particles(ip)%f(1:3)
300 IF (
ASSOCIATED(numer_forces))
DEALLOCATE (numer_forces)
301 ALLOCATE (numer_forces(subsys%particles%n_els, 3))
304 IF (do_dof_atom_coor(k, ip))
THEN
305 numer_energy = 0.0_dp
306 std_value = particles(ip)%r(k)
308 particles(ip)%r(k) = std_value - (-1.0_dp)**j*dx
309 SELECT CASE (force_env%in_use)
311 CALL get_qs_env(force_env%qs_env, qs_kind_set=qs_kind_set)
318 calc_force=.false., &
319 calc_stress_tensor=.false., &
320 consistent_energies=.true.)
321 CALL force_env_get(force_env, potential_energy=numer_energy(j))
323 particles(ip)%r(k) = std_value
324 numer_forces(ip, k) = -0.5_dp*(numer_energy(1) - numer_energy(2))/dx
326 WRITE (unit=iw, fmt=
"(/,T2,A,T17,A,F7.4,A,T34,A,F7.4,A,T52,A,T68,A)") &
327 "DEBUG| Atom",
"E("//achar(119 + k)//
" +", dx,
")", &
328 "E("//achar(119 + k)//
" -", dx,
")", &
329 "f(numerical)",
"f(analytical)"
330 WRITE (unit=iw, fmt=
"(T2,A,I5,4(1X,F16.8))") &
331 "DEBUG|", ip, numer_energy(1:2), numer_forces(ip, k), analyt_forces(ip, k)
334 numer_forces(ip, k) = 0.0_dp
341 IF (do_dof_atom_coor(k, ip))
THEN
343 IF (abs(analyt_forces(ip, k)) >= eps_no_error_check)
THEN
344 err(k) = 100.0_dp*(numer_forces(ip, k) - analyt_forces(ip, k))/analyt_forces(ip, k)
347 IF (abs(analyt_forces(ip, k)) <= 0.0001_dp) my_maxerr(k) = 5.0_dp*my_maxerr(k)
353 IF (any(do_dof_atom_coor(1:3, ip)))
THEN
354 WRITE (unit=iw, fmt=
"(/,T2,A)") &
355 "DEBUG| Atom Coordinate f(numerical) f(analytical) Difference Error [%]"
358 IF (do_dof_atom_coor(k, ip))
THEN
359 difference = analyt_forces(ip, k) - numer_forces(ip, k)
360 IF (abs(analyt_forces(ip, k)) >= eps_no_error_check)
THEN
361 WRITE (unit=iw, fmt=
"(T2,A,I5,T19,A1,T26,F14.8,T42,F14.8,T57,F12.8,T71,F10.2)") &
362 "DEBUG|", ip, achar(119 + k), numer_forces(ip, k), analyt_forces(ip, k), difference, err(k)
364 WRITE (unit=iw, fmt=
"(T2,A,I5,T19,A1,T26,F14.8,T42,F14.8,T57,F12.8,T80,A1)") &
365 "DEBUG|", ip, achar(119 + k), numer_forces(ip, k), analyt_forces(ip, k), difference,
"-"
370 IF (any(abs(err(1:3)) > my_maxerr(1:3)))
THEN
371 message =
"A mismatch between analytical and numerical forces "// &
372 "has been detected. Check the implementation of the "// &
373 "analytical force calculation"
374 IF (stop_on_mismatch)
THEN
383 WRITE (unit=iw, fmt=
"(/,(T2,A))") &
384 "DEBUG|======================== BEGIN OF SUMMARY ===============================", &
385 "DEBUG| Atom Coordinate f(numerical) f(analytical) Difference Error [%]"
386 sum_of_differences = 0.0_dp
391 IF (do_dof_atom_coor(k, ip))
THEN
392 difference = analyt_forces(ip, k) - numer_forces(ip, k)
393 IF (abs(analyt_forces(ip, k)) >= eps_no_error_check)
THEN
394 err(k) = 100_dp*(numer_forces(ip, k) - analyt_forces(ip, k))/analyt_forces(ip, k)
395 errmax = max(errmax, abs(err(k)))
396 WRITE (unit=iw, fmt=
"(T2,A,I5,T19,A1,T26,F14.8,T42,F14.8,T57,F12.8,T71,F10.2)") &
397 "DEBUG|", ip, achar(119 + k), numer_forces(ip, k), analyt_forces(ip, k), difference, err(k)
399 WRITE (unit=iw, fmt=
"(T2,A,I5,T19,A1,T26,F14.8,T42,F14.8,T57,F12.8,T80,A1)") &
400 "DEBUG|", ip, achar(119 + k), numer_forces(ip, k), analyt_forces(ip, k), difference,
"-"
402 sum_of_differences = sum_of_differences + abs(difference)
406 WRITE (unit=iw, fmt=
"(T2,A,T57,F12.8,T71,F10.2)") &
407 "DEBUG| Sum of differences:", sum_of_differences, errmax
408 WRITE (unit=iw, fmt=
"(T2,A)") &
409 "DEBUG|======================== END OF SUMMARY ================================="
412 IF (
ASSOCIATED(analyt_forces))
DEALLOCATE (analyt_forces)
413 IF (
ASSOCIATED(numer_forces))
DEALLOCATE (numer_forces)
414 DEALLOCATE (do_dof_atom_coor)
417 IF (debug_dipole)
THEN
419 CALL get_qs_env(force_env%qs_env, dft_control=dft_control)
420 poldir = (/0.0_dp, 0.0_dp, 1.0_dp/)
422 CALL set_efield(dft_control, amplitude, poldir)
424 CALL get_qs_env(force_env%qs_env, results=results)
425 description =
"[DIPOLE]"
427 CALL get_results(results, description=description, values=dipole_moment)
429 CALL cp_warn(__location__,
"Debug of dipole moments needs DFT/PRINT/MOMENTS section enabled")
434 IF (do_dof_dipole(k))
THEN
438 poldir = -1.0_dp*poldir
439 CALL set_efield(dft_control, amplitude, poldir)
441 CALL force_env_get(force_env, potential_energy=numer_energy(j))
443 dipole_numer(k) = 0.5_dp*(numer_energy(1) - numer_energy(2))/de
445 dipole_numer(k) = 0.0_dp
449 WRITE (unit=iw, fmt=
"(/,(T2,A))") &
450 "DEBUG|========================= DIPOLE MOMENTS ================================", &
451 "DEBUG| Coordinate D(numerical) D(analytical) Difference Error [%]"
454 IF (do_dof_dipole(k))
THEN
455 dd = dipole_moment(k) - dipole_numer(k)
456 IF (abs(dipole_moment(k)) > eps_no_error_check)
THEN
457 derr = 100._dp*dd/dipole_moment(k)
458 WRITE (unit=iw, fmt=
"(T2,A,T13,A1,T21,F16.8,T38,F16.8,T56,G12.3,T72,F9.3)") &
459 "DEBUG|", achar(119 + k), dipole_numer(k), dipole_moment(k), dd, derr
462 WRITE (unit=iw, fmt=
"(T2,A,T13,A1,T21,F16.8,T38,F16.8,T56,G12.3)") &
463 "DEBUG|", achar(119 + k), dipole_numer(k), dipole_moment(k), dd
467 WRITE (unit=iw, fmt=
"(T2,A,T13,A1,T21,A16,T38,F16.8)") &
468 "DEBUG|", achar(119 + k),
" skipped", dipole_moment(k)
471 WRITE (unit=iw, fmt=
"((T2,A))") &
472 "DEBUG|========================================================================="
473 WRITE (unit=iw, fmt=
"(T2,A,T61,E20.12)")
'DIPOLE : CheckSum =', sum(dipole_moment)
474 IF (any(abs(err(1:3)) > maxerr))
THEN
475 message =
"A mismatch between analytical and numerical dipoles "// &
476 "has been detected. Check the implementation of the "// &
477 "analytical dipole calculation"
478 IF (stop_on_mismatch)
THEN
487 CALL cp_warn(__location__,
"Debug of dipole moments only for Quickstep code available")
491 IF (debug_polar)
THEN
493 CALL get_qs_env(force_env%qs_env, dft_control=dft_control)
494 poldir = (/0.0_dp, 0.0_dp, 1.0_dp/)
496 CALL set_efield(dft_control, amplitude, poldir)
498 CALL get_qs_env(force_env%qs_env, results=results)
499 description =
"[POLAR]"
501 CALL get_results(results, description=description, values=pvals)
502 polar_analytic(1:3, 1:3) = reshape(pvals(1:9), (/3, 3/))
504 CALL cp_warn(__location__,
"Debug of polarizabilities needs PROPERTIES/LINRES/POLAR section enabled")
507 description =
"[DIPOLE]"
509 CALL cp_warn(__location__,
"Debug of polarizabilities need DFT/PRINT/MOMENTS section enabled")
517 poldir = -1.0_dp*poldir
518 CALL set_efield(dft_control, amplitude, poldir)
520 CALL get_results(results, description=description, values=dipn(1:3, j))
522 polar_numeric(1:3, k) = 0.5_dp*(dipn(1:3, 2) - dipn(1:3, 1))/de
525 WRITE (unit=iw, fmt=
"(/,(T2,A))") &
526 "DEBUG|========================= POLARIZABILITY ================================", &
527 "DEBUG| Coordinates P(numerical) P(analytical) Difference Error [%]"
530 dd = polar_analytic(k, j) - polar_numeric(k, j)
531 IF (abs(polar_analytic(k, j)) > eps_no_error_check)
THEN
532 derr = 100._dp*dd/polar_analytic(k, j)
533 WRITE (unit=iw, fmt=
"(T2,A,T12,A1,A1,T21,F16.8,T38,F16.8,T56,G12.3,T72,F9.3)") &
534 "DEBUG|", achar(119 + k), achar(119 + j), polar_numeric(k, j), polar_analytic(k, j), dd, derr
536 WRITE (unit=iw, fmt=
"(T2,A,T12,A1,A1,T21,F16.8,T38,F16.8,T56,G12.3)") &
537 "DEBUG|", achar(119 + k), achar(119 + j), polar_numeric(k, j), polar_analytic(k, j), dd
541 WRITE (unit=iw, fmt=
"((T2,A))") &
542 "DEBUG|========================================================================="
543 WRITE (unit=iw, fmt=
"(T2,A,T61,E20.12)")
' POLAR : CheckSum =', sum(polar_analytic)
546 CALL cp_warn(__location__,
"Debug of polarizabilities only for Quickstep code available")
subroutine, public get_qs_env(qs_env, atomic_kind_set, qs_kind_set, cell, super_cell, cell_ref, use_ref_cell, kpoints, dft_control, mos, sab_orb, sab_all, qmmm, qmmm_periodic, sac_ae, sac_ppl, sac_lri, sap_ppnl, sab_vdw, sab_scp, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, sab_xb, sab_xtb_pp, sab_xtb_nonbond, sab_almo, sab_kp, sab_kp_nosym, particle_set, energy, force, matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, run_rtp, rtp, matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_ks_im_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, matrix_s_ri_aux_kp, matrix_s, matrix_s_ri_aux, matrix_w, matrix_p_mp2, matrix_p_mp2_admm, rho, rho_xc, pw_env, ewald_env, ewald_pw, active_space, mpools, input, para_env, blacs_env, scf_control, rel_control, kinetic, qs_charges, vppl, rho_core, rho_nlcc, rho_nlcc_g, ks_env, ks_qmmm_env, wf_history, scf_env, local_particles, local_molecules, distribution_2d, dbcsr_dist, molecule_kind_set, molecule_set, subsys, cp_subsys, oce, local_rho_set, rho_atom_set, task_list, task_list_soft, rho0_atom_set, rho0_mpole, rhoz_set, ecoul_1c, rho0_s_rs, rho0_s_gs, do_kpoints, has_unit_metric, requires_mo_derivs, mo_derivs, mo_loc_history, nkind, natom, nelectron_total, nelectron_spin, efield, neighbor_list_id, linres_control, xas_env, virial, cp_ddapc_env, cp_ddapc_ewald, outer_scf_history, outer_scf_ihistory, x_data, et_coupling, dftb_potential, results, se_taper, se_store_int_env, se_nddo_mpole, se_nonbond_env, admm_env, lri_env, lri_density, exstate_env, ec_env, harris_env, dispersion_env, gcp_env, vee, rho_external, external_vxc, mask, mp2_env, bs_env, kg_env, wanniercentres, atprop, ls_scf_env, do_transport, transport_env, v_hartree_rspace, s_mstruct_changed, rho_changed, potential_changed, forces_up_to_date, mscfg_env, almo_scf_env, gradient_history, variable_history, embed_pot, spin_embed_pot, polar_env, mos_last_converged, eeq, rhs)
Get the QUICKSTEP environment.