55#include "../base/base_uses.f90"
60 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'tblite_reference_cli'
74 CHARACTER(LEN=*),
PARAMETER :: routinen =
'tb_reference_cli_compare'
76 CHARACTER(LEN=16) :: solvation_model_name
77 CHARACTER(LEN=32) :: acc_str, charge_str, efield_x_str, efield_y_str, efield_z_str, &
78 etemp_guess_val_str, etemp_str, iter_str, spin_str, spinpol_str
79 CHARACTER(LEN=4*default_path_length+128) :: efield_str, etemp_guess_str, param_str, &
80 post_processing_output_str, post_processing_str, restart_str, solvation_str, verbosity_str
81 CHARACTER(LEN=64*default_path_length) :: command
82 CHARACTER(LEN=8) :: guess, method, solver
83 CHARACTER(LEN=default_path_length) :: file_base, gen_file, grad_file, &
84 json_file, log_file, &
85 post_processing_output_file
86 INTEGER :: handle, iounit, n_periodic, natom, nkp, &
87 reference_iterations, spin
88 INTEGER,
DIMENSION(3) :: periodic
89 LOGICAL :: do_kpoints, have_energy, have_gradient, &
90 have_virial, success, too_large, &
92 REAL(kind=
dp) :: cli_energy, cp_energy, ediff, etemp, &
93 etemp_guess, fmax, fsum, vmax, vsum
94 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: cli_gradient, cli_virial, cp_gradient
95 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: xkp
109 CALL timeset(routinen, handle)
111 NULLIFY (atomic_kind_set, cell, dft_control, energy, force, kpoints, logger, para_env, particle_set, &
112 scf_control, virial, xkp)
113 CALL get_qs_env(qs_env=qs_env, atomic_kind_set=atomic_kind_set, cell=cell, &
114 dft_control=dft_control, energy=energy, force=force, &
115 para_env=para_env, particle_set=particle_set, scf_control=scf_control, &
116 virial=virial, do_kpoints=do_kpoints, kpoints=kpoints)
118 ref = dft_control%qs_control%xtb_control%reference_cli
119 IF (.NOT. ref%enabled)
THEN
120 CALL timestop(handle)
123 IF (.NOT. para_env%is_source())
THEN
124 CALL timestop(handle)
132 verbosity_str =
" --silent"
135 verbosity_str =
" --verbose"
137 IF (ref%solvation_active)
THEN
139 IF (
ASSOCIATED(cell))
CALL get_cell(cell=cell, periodic=periodic)
140 n_periodic = count(periodic == 1)
141 IF (n_periodic == 3)
THEN
142 WRITE (unit=iounit, fmt=
"(/,T2,A)") &
143 "tblite reference CLI implicit solvation is not supported for PERIODIC XYZ."
144 WRITE (unit=iounit, fmt=
"(T2,A)") &
145 "Use PERIODIC NONE for molecular solvation diagnostics, or remove IMPLICIT_SOLVATION."
146 cpabort(
"REFERENCE_CLI implicit solvation is incompatible with PERIODIC XYZ")
147 ELSE IF (n_periodic > 0)
THEN
148 WRITE (unit=iounit, fmt=
"(/,T2,A)") &
149 "WARNING: tblite reference CLI implicit solvation with finite periodicity is diagnostic only."
150 WRITE (unit=iounit, fmt=
"(T2,A,I0,A)") &
151 "The generated native tblite reference geometry has ", n_periodic, &
152 " periodic direction(s); continuum-solvation conventions are primarily molecular."
155 unsupported_kpoints = .false.
156 IF (do_kpoints .AND.
ASSOCIATED(kpoints))
THEN
159 unsupported_kpoints = nkp > 1
160 IF (nkp == 1 .AND.
ASSOCIATED(xkp)) unsupported_kpoints = any(abs(xkp(:, 1)) > 1.0e-12_dp)
162 IF (unsupported_kpoints)
THEN
163 WRITE (unit=iounit, fmt=
"(/,T2,A)") &
164 "tblite reference CLI check skipped: CP2K KPOINTS are active."
165 WRITE (unit=iounit, fmt=
"(T2,A)") &
166 "The native tblite CLI reference path does not reproduce CP2K multi-k-point sampling."
167 IF (ref%stop_on_error)
THEN
168 cpabort(
"tblite reference CLI cannot check CP2K k-point calculations")
170 CALL timestop(handle)
174 WRITE (unit=iounit, fmt=
"(/,T2,A)") &
175 "WARNING: tblite reference CLI cannot reproduce XTB/SCC_MIXER CP2K."
176 WRITE (unit=iounit, fmt=
"(T2,A)") &
177 "The external native tblite run uses tblite's own SCC mixer; only the converged result is compared."
178 IF (ref%stop_on_error) cpabort(
"tblite reference CLI cannot reproduce SCC_MIXER CP2K")
180 natom =
SIZE(particle_set)
181 method = tb_reference_method_name(dft_control%qs_control%xtb_control%tblite_method)
182 guess = tb_reference_guess_name(ref%guess)
183 solver = tb_reference_solver_name(dft_control%qs_control%xtb_control%tblite_mixer_solver)
184 file_base = tb_join_path(ref%work_directory, ref%prefix)
185 gen_file = trim(file_base)//
".gen"
186 grad_file = trim(file_base)//
".grad"
187 json_file = trim(file_base)//
".json"
188 log_file = trim(file_base)//
".log"
189 post_processing_output_file =
""
190 IF (len_trim(ref%grad_file) > 0) grad_file = ref%grad_file
191 IF (len_trim(ref%json_file) > 0) json_file = ref%json_file
192 IF (len_trim(ref%post_processing_output_file) > 0)
THEN
193 post_processing_output_file = ref%post_processing_output_file
196 WRITE (charge_str,
"(I0)") dft_control%charge
197 spin = max(0, dft_control%multiplicity - 1)
198 WRITE (spin_str,
"(I0)") spin
199 WRITE (acc_str,
"(ES16.8)") dft_control%qs_control%xtb_control%tblite_accuracy
200 reference_iterations = dft_control%qs_control%xtb_control%tblite_mixer_iterations
201 WRITE (iter_str,
"(I0)") reference_iterations
203 IF (ref%efield_active)
THEN
204 WRITE (efield_x_str,
"(ES16.8)") ref%efield(1)
205 WRITE (efield_y_str,
"(ES16.8)") ref%efield(2)
206 WRITE (efield_z_str,
"(ES16.8)") ref%efield(3)
207 efield_str =
" --efield "//trim(adjustl(efield_x_str))//
","// &
208 trim(adjustl(efield_y_str))//
","//trim(adjustl(efield_z_str))
211 solvation_model_name =
""
212 IF (ref%solvation_active)
THEN
213 SELECT CASE (ref%solvation_model)
215 solvation_model_name =
"ALPB"
216 solvation_str =
" --alpb "
218 solvation_model_name =
"GBSA"
219 solvation_str =
" --gbsa "
221 solvation_model_name =
"GBE"
222 solvation_str =
" --gbe "
224 solvation_model_name =
"GB"
225 solvation_str =
" --gb "
227 solvation_model_name =
"CPCM"
228 solvation_str =
" --cpcm "
230 cpabort(
"Unknown tblite reference CLI implicit-solvation model")
232 solvation_str = trim(solvation_str)//
" "//trim(tb_shell_quote(ref%solvation_solvent))
233 SELECT CASE (ref%solvation_born_kernel)
236 solvation_str = trim(solvation_str)//
" --born-kernel p16"
238 solvation_str = trim(solvation_str)//
" --born-kernel still"
240 cpabort(
"Unknown tblite reference CLI Born kernel")
242 SELECT CASE (ref%solvation_state)
245 solvation_str = trim(solvation_str)//
" --solv-state bar1mol"
247 solvation_str = trim(solvation_str)//
" --solv-state reference"
249 cpabort(
"Unknown tblite reference CLI solution state")
252 IF (dft_control%qs_control%xtb_control%tblite_mixer_memory /= reference_iterations)
THEN
253 WRITE (unit=iounit, fmt=
"(/,T2,A)") &
254 "WARNING: tblite reference CLI cannot reproduce XTB/TBLITE_MIXER/MEMORY."
255 WRITE (unit=iounit, fmt=
"(T2,A,I0,A,I0,A)") &
256 "The native reference run uses tblite's internal mixer memory tied to --iterations (", &
257 reference_iterations,
"), while CP2K uses MEMORY ", &
258 dft_control%qs_control%xtb_control%tblite_mixer_memory,
"."
259 IF (ref%stop_on_error)
THEN
260 cpabort(
"tblite reference CLI cannot reproduce TBLITE_MIXER/MEMORY")
263 IF (abs(dft_control%qs_control%xtb_control%tblite_mixer_damping - &
265 WRITE (unit=iounit, fmt=
"(/,T2,A)") &
266 "WARNING: tblite reference CLI cannot reproduce XTB/TBLITE_MIXER/DAMPING."
267 WRITE (unit=iounit, fmt=
"(T2,A,F8.4,A,F8.4,A)") &
269 ", while CP2K uses DAMPING ", dft_control%qs_control%xtb_control%tblite_mixer_damping,
"."
270 IF (ref%stop_on_error)
THEN
271 cpabort(
"tblite reference CLI cannot reproduce TBLITE_MIXER/DAMPING")
274 IF (abs(dft_control%qs_control%xtb_control%tblite_mixer_omega0 - &
276 WRITE (unit=iounit, fmt=
"(/,T2,A)") &
277 "WARNING: tblite reference CLI cannot reproduce XTB/TBLITE_MIXER/OMEGA0."
278 WRITE (unit=iounit, fmt=
"(T2,A,ES12.4,A,ES12.4,A)") &
280 ", while CP2K uses OMEGA0 ", dft_control%qs_control%xtb_control%tblite_mixer_omega0,
"."
281 IF (ref%stop_on_error)
THEN
282 cpabort(
"tblite reference CLI cannot reproduce TBLITE_MIXER/OMEGA0")
285 IF (abs(dft_control%qs_control%xtb_control%tblite_mixer_min_weight - &
287 WRITE (unit=iounit, fmt=
"(/,T2,A)") &
288 "WARNING: tblite reference CLI cannot reproduce XTB/TBLITE_MIXER/MIN_WEIGHT."
289 WRITE (unit=iounit, fmt=
"(T2,A,ES12.4,A,ES12.4,A)") &
291 ", while CP2K uses MIN_WEIGHT ", dft_control%qs_control%xtb_control%tblite_mixer_min_weight,
"."
292 IF (ref%stop_on_error)
THEN
293 cpabort(
"tblite reference CLI cannot reproduce TBLITE_MIXER/MIN_WEIGHT")
296 IF (abs(dft_control%qs_control%xtb_control%tblite_mixer_max_weight - &
298 WRITE (unit=iounit, fmt=
"(/,T2,A)") &
299 "WARNING: tblite reference CLI cannot reproduce XTB/TBLITE_MIXER/MAX_WEIGHT."
300 WRITE (unit=iounit, fmt=
"(T2,A,ES12.4,A,ES12.4,A)") &
302 ", while CP2K uses MAX_WEIGHT ", dft_control%qs_control%xtb_control%tblite_mixer_max_weight,
"."
303 IF (ref%stop_on_error)
THEN
304 cpabort(
"tblite reference CLI cannot reproduce TBLITE_MIXER/MAX_WEIGHT")
307 IF (abs(dft_control%qs_control%xtb_control%tblite_mixer_weight_factor - &
309 WRITE (unit=iounit, fmt=
"(/,T2,A)") &
310 "WARNING: tblite reference CLI cannot reproduce XTB/TBLITE_MIXER/WEIGHT_FACTOR."
311 WRITE (unit=iounit, fmt=
"(T2,A,ES12.4,A,ES12.4,A)") &
313 ", while CP2K uses WEIGHT_FACTOR ", &
314 dft_control%qs_control%xtb_control%tblite_mixer_weight_factor,
"."
315 IF (ref%stop_on_error)
THEN
316 cpabort(
"tblite reference CLI cannot reproduce TBLITE_MIXER/WEIGHT_FACTOR")
320 IF (
ASSOCIATED(scf_control))
THEN
321 IF (
ASSOCIATED(scf_control%smear))
THEN
322 IF (scf_control%smear%do_smear)
THEN
325 WRITE (unit=iounit, fmt=
"(/,T2,A,A,A)") &
326 "WARNING: tblite reference CLI cannot reproduce CP2K smearing method ", &
327 trim(tb_reference_smear_method_name(scf_control%smear%method)),
"."
328 WRITE (unit=iounit, fmt=
"(T2,A,F12.3,A)") &
329 "The native reference run uses Fermi-Dirac electronic temperature ", etemp,
" K instead."
334 WRITE (etemp_str,
"(ES16.8)") etemp
337 IF (ref%electronic_temperature_guess > 0.0_dp)
THEN
339 WRITE (etemp_guess_val_str,
"(ES16.8)") etemp_guess
340 etemp_guess_str =
" --etemp-guess "//trim(adjustl(etemp_guess_val_str))
343 IF (len_trim(dft_control%qs_control%xtb_control%tblite_param_file) > 0)
THEN
344 param_str =
" --param "//trim(tb_shell_quote(dft_control%qs_control%xtb_control%tblite_param_file))
347 IF (dft_control%lsd) spinpol_str =
" --spin-polarized"
348 post_processing_str =
""
349 IF (len_trim(ref%post_processing) > 0)
THEN
350 post_processing_str =
" --post-processing "//trim(tb_shell_quote(ref%post_processing))
352 post_processing_output_str =
""
353 IF (len_trim(post_processing_output_file) > 0)
THEN
354 WRITE (unit=iounit, fmt=
"(/,T2,A)") &
355 "WARNING: tblite reference CLI POST_PROCESSING_OUTPUT was requested explicitly."
356 WRITE (unit=iounit, fmt=
"(T2,A)") &
357 "Some tblite 0.5.0 command-line builds document --post-processing-output but do not parse it."
358 post_processing_output_str =
" --post-processing-output "// &
359 trim(tb_shell_quote(post_processing_output_file))
361 restart_str =
" --no-restart"
362 IF (len_trim(ref%restart_file) > 0)
THEN
363 restart_str =
" --restart "//trim(tb_shell_quote(ref%restart_file))
366 CALL tb_write_reference_gen(qs_env, trim(gen_file))
368 command = trim(tb_shell_quote(ref%program_name))//
" run --method "//trim(method)// &
370 trim(spinpol_str)// &
371 " --charge "//trim(adjustl(charge_str))// &
372 " --spin "//trim(adjustl(spin_str))// &
373 " --acc "//trim(adjustl(acc_str))// &
374 " --guess "//trim(guess)// &
375 " --solver "//trim(solver)// &
376 " --iterations "//trim(adjustl(iter_str))// &
377 " --etemp "//trim(adjustl(etemp_str))// &
378 trim(etemp_guess_str)// &
380 trim(solvation_str)// &
381 trim(post_processing_str)// &
382 trim(post_processing_output_str)// &
383 trim(restart_str)// &
384 trim(verbosity_str)//
" --input "//trim(tb_shell_quote(ref%input_format))// &
385 " --grad "//trim(tb_shell_quote(grad_file))// &
386 " --json "//trim(tb_shell_quote(json_file))//
" "//trim(tb_shell_quote(gen_file))// &
387 " > "//trim(tb_shell_quote(log_file))//
" 2>&1"
389 CALL tb_reference_cli_execute(ref,
"run", command, log_file, iounit, success)
390 IF (.NOT. success)
THEN
392 CALL timestop(handle)
396 ALLOCATE (cli_gradient(3, natom), cli_virial(3, 3))
397 CALL tb_read_reference_grad(trim(grad_file), natom, cli_energy, cli_gradient, cli_virial, &
398 have_energy, have_gradient, have_virial)
400 WRITE (unit=iounit, fmt=
"(/,T2,A)")
"tblite reference CLI check"
401 WRITE (unit=iounit, fmt=
"(T2,A,A)")
"Executable: ", trim(ref%program_name)
402 WRITE (unit=iounit, fmt=
"(T2,A,A)")
"Method: ", trim(method)
403 WRITE (unit=iounit, fmt=
"(T2,A,A)")
"Guess: ", trim(guess)
404 WRITE (unit=iounit, fmt=
"(T2,A,A)")
"Solver: ", trim(solver)
405 WRITE (unit=iounit, fmt=
"(T2,A,L1)")
"Spin-pol.: ", dft_control%lsd
406 IF (ref%efield_active)
THEN
407 WRITE (unit=iounit, fmt=
"(T2,A,3ES16.8,A)")
"Efield: ", ref%efield,
" V/Angstrom"
409 IF (ref%solvation_active)
THEN
410 WRITE (unit=iounit, fmt=
"(T2,A,A,1X,A)")
"Solvation: ", trim(solvation_model_name), &
411 trim(ref%solvation_solvent)
413 IF (len_trim(ref%post_processing) > 0)
THEN
414 WRITE (unit=iounit, fmt=
"(T2,A,A)")
"Post proc.: ", trim(ref%post_processing)
416 IF (len_trim(post_processing_output_file) > 0)
THEN
417 WRITE (unit=iounit, fmt=
"(T2,A,A)")
"PP output: ", trim(post_processing_output_file)
419 IF (ref%electronic_temperature_guess > 0.0_dp)
THEN
420 WRITE (unit=iounit, fmt=
"(T2,A,F12.3,A)")
"Guess etemp:", etemp_guess,
" K"
422 WRITE (unit=iounit, fmt=
"(T2,A,A)")
"Grad file: ", trim(grad_file)
423 WRITE (unit=iounit, fmt=
"(T2,A,A)")
"JSON file: ", trim(json_file)
424 WRITE (unit=iounit, fmt=
"(T2,A,A)")
"Log file: ", trim(log_file)
427 IF (ref%check_energy)
THEN
428 IF (have_energy)
THEN
429 cp_energy = energy%total
430 ediff = abs(cp_energy - cli_energy)
431 WRITE (unit=iounit, fmt=
"(T2,A,3ES22.12)") &
432 "Energy CP2K/CLI/absdiff:", cp_energy, cli_energy, ediff
433 too_large = too_large .OR. ediff > ref%error_limit
435 WRITE (unit=iounit, fmt=
"(T2,A)")
"Energy check skipped: no CLI energy found."
439 IF (ref%check_forces)
THEN
440 IF (have_gradient .AND.
ASSOCIATED(force))
THEN
441 ALLOCATE (cp_gradient(3, natom))
443 fsum = sum(abs(cp_gradient - cli_gradient))
444 fmax = maxval(abs(cp_gradient - cli_gradient))
445 WRITE (unit=iounit, fmt=
"(T2,A,2ES22.12)")
"Gradient diff sum/max:", fsum, fmax
446 too_large = too_large .OR. fmax > ref%error_limit
447 DEALLOCATE (cp_gradient)
449 WRITE (unit=iounit, fmt=
"(T2,A)")
"Gradient check skipped: no CLI gradient or CP2K force found."
453 IF (ref%check_virial)
THEN
454 IF (have_virial .AND.
ASSOCIATED(virial))
THEN
457 vsum = sum(abs(-virial%pv_virial - cli_virial))
458 vmax = maxval(abs(-virial%pv_virial - cli_virial))
459 WRITE (unit=iounit, fmt=
"(T2,A,2ES22.12)")
"Virial diff sum/max:", vsum, vmax
460 too_large = too_large .OR. vmax > ref%error_limit
462 WRITE (unit=iounit, fmt=
"(T2,A)")
"Virial check skipped: no CLI virial or CP2K virial found."
467 WRITE (unit=iounit, fmt=
"(T2,A,ES12.4)") &
468 "tblite reference CLI deviation exceeded ERROR_LIMIT = ", ref%error_limit
469 IF (ref%stop_on_error) cpabort(
"tblite reference CLI deviation exceeded ERROR_LIMIT")
472 CALL tb_reference_cli_aux_commands(ref, dft_control, gen_file, file_base, verbosity_str, iounit, success)
474 IF (success .AND. .NOT. too_large)
THEN
475 CALL tb_reference_cleanup(ref, gen_file, grad_file, json_file, log_file, post_processing_output_file)
477 DEALLOCATE (cli_gradient, cli_virial)
479 CALL timestop(handle)
488 FUNCTION tb_reference_method_name(method_id)
RESULT(method)
489 INTEGER,
INTENT(IN) :: method_id
490 CHARACTER(LEN=8) :: method
492 SELECT CASE (method_id)
500 cpabort(
"Unknown tblite reference CLI method")
503 END FUNCTION tb_reference_method_name
510 FUNCTION tb_reference_guess_name(guess_id)
RESULT(guess)
511 INTEGER,
INTENT(IN) :: guess_id
512 CHARACTER(LEN=8) :: guess
514 SELECT CASE (guess_id)
522 cpabort(
"Unknown tblite reference CLI guess")
525 END FUNCTION tb_reference_guess_name
532 FUNCTION tb_reference_solver_name(solver_id)
RESULT(solver)
533 INTEGER,
INTENT(IN) :: solver_id
534 CHARACTER(LEN=8) :: solver
536 SELECT CASE (solver_id)
542 cpabort(
"Unknown tblite reference CLI solver")
545 END FUNCTION tb_reference_solver_name
552 FUNCTION tb_reference_smear_method_name(method_id)
RESULT(method)
553 INTEGER,
INTENT(IN) :: method_id
554 CHARACTER(LEN=24) :: method
556 SELECT CASE (method_id)
558 method =
"FERMI_DIRAC"
560 method =
"ENERGY_WINDOW"
566 method =
"METHFESSEL_PAXTON"
568 method =
"MARZARI_VANDERBILT"
573 END FUNCTION tb_reference_smear_method_name
585 SUBROUTINE tb_reference_cli_aux_commands(ref, dft_control, gen_file, file_base, verbosity_str, iounit, success)
589 CHARACTER(LEN=*),
INTENT(IN) :: gen_file, file_base, verbosity_str
590 INTEGER,
INTENT(IN) :: iounit
591 LOGICAL,
INTENT(OUT) :: success
593 CHARACTER(LEN=32) :: charge_str, efield_x_str, efield_y_str, &
594 efield_z_str, etemp_guess_val_str, &
596 CHARACTER(LEN=4*default_path_length+128) :: copy_str, dry_run_str, efield_str, &
597 etemp_guess_str, grad_str, json_str, &
598 method_str, output_str
599 CHARACTER(LEN=64*default_path_length) :: command
600 CHARACTER(LEN=default_path_length) :: guess_input, log_file
602 LOGICAL :: command_success
603 REAL(kind=
dp) :: etemp_guess
606 WRITE (charge_str,
"(I0)") dft_control%charge
607 spin = max(0, dft_control%multiplicity - 1)
608 WRITE (spin_str,
"(I0)") spin
610 IF (ref%guess_cli%enabled)
THEN
611 guess_input = ref%guess_cli%input_file
612 IF (len_trim(guess_input) == 0) guess_input = gen_file
614 IF (ref%guess_cli%electronic_temperature_guess > 0.0_dp)
THEN
616 WRITE (etemp_guess_val_str,
"(ES16.8)") etemp_guess
617 etemp_guess_str =
" --etemp-guess "//trim(adjustl(etemp_guess_val_str))
620 IF (ref%guess_cli%efield_active)
THEN
621 WRITE (efield_x_str,
"(ES16.8)") ref%guess_cli%efield(1)
622 WRITE (efield_y_str,
"(ES16.8)") ref%guess_cli%efield(2)
623 WRITE (efield_z_str,
"(ES16.8)") ref%guess_cli%efield(3)
624 efield_str =
" --efield "//trim(adjustl(efield_x_str))//
","// &
625 trim(adjustl(efield_y_str))//
","//trim(adjustl(efield_z_str))
628 IF (ref%guess_cli%grad) grad_str =
" --grad"
630 IF (len_trim(ref%guess_cli%json_file) > 0)
THEN
631 json_str =
" --json "//trim(tb_shell_quote(ref%guess_cli%json_file))
633 log_file = trim(file_base)//
".guess.log"
634 command = trim(tb_shell_quote(ref%program_name))// &
635 " guess --charge "//trim(adjustl(charge_str))// &
636 " --spin "//trim(adjustl(spin_str))// &
637 " --method "//trim(tb_reference_guess_name(ref%guess_cli%method))// &
638 " --solver "//trim(tb_reference_solver_name(ref%guess_cli%solver))// &
639 trim(etemp_guess_str)// &
643 trim(verbosity_str)//
" --input "//trim(tb_shell_quote(ref%guess_cli%input_format))// &
644 " "//trim(tb_shell_quote(guess_input))// &
645 " > "//trim(tb_shell_quote(log_file))//
" 2>&1"
646 CALL tb_reference_cli_execute(ref,
"guess", command, log_file, iounit, command_success)
647 success = success .AND. command_success
648 IF (command_success .AND. .NOT. ref%keep_files)
CALL tb_delete_file(log_file)
649 IF (command_success .AND. .NOT. ref%keep_files .AND. len_trim(ref%guess_cli%json_file) > 0)
THEN
650 CALL tb_delete_file(ref%guess_cli%json_file)
654 IF (ref%param_cli%enabled)
THEN
656 IF (ref%param_cli%method_explicit .OR. len_trim(ref%param_cli%input_file) == 0)
THEN
657 method_str =
" --method "// &
658 trim(tb_reference_method_name(merge(ref%param_cli%method, &
659 dft_control%qs_control%xtb_control%tblite_method, &
660 ref%param_cli%method_explicit)))
663 IF (len_trim(ref%param_cli%output_file) > 0)
THEN
664 output_str =
" --output "//trim(tb_shell_quote(ref%param_cli%output_file))
666 log_file = trim(file_base)//
".param.log"
667 command = trim(tb_shell_quote(ref%program_name))//
" param"// &
670 IF (len_trim(ref%param_cli%input_file) > 0)
THEN
671 command = trim(command)//
" "//trim(tb_shell_quote(ref%param_cli%input_file))
673 command = trim(command)//
" > "//trim(tb_shell_quote(log_file))//
" 2>&1"
674 CALL tb_reference_cli_execute(ref,
"param", command, log_file, iounit, command_success)
675 success = success .AND. command_success
676 IF (command_success .AND. .NOT. ref%keep_files)
CALL tb_delete_file(log_file)
677 IF (command_success .AND. .NOT. ref%keep_files .AND. len_trim(ref%param_cli%output_file) > 0)
THEN
678 CALL tb_delete_file(ref%param_cli%output_file)
682 IF (ref%fit_cli%enabled)
THEN
684 IF (ref%fit_cli%dry_run) dry_run_str =
" --dry-run"
686 IF (len_trim(ref%fit_cli%copy_file) > 0)
THEN
687 copy_str =
" --copy "//trim(tb_shell_quote(ref%fit_cli%copy_file))
689 log_file = trim(file_base)//
".fit.log"
690 command = trim(tb_shell_quote(ref%program_name))//
" fit"// &
691 trim(dry_run_str)// &
693 trim(verbosity_str)//
" "//trim(tb_shell_quote(ref%fit_cli%param_file))// &
694 " "//trim(tb_shell_quote(ref%fit_cli%input_file))// &
695 " > "//trim(tb_shell_quote(log_file))//
" 2>&1"
696 CALL tb_reference_cli_execute(ref,
"fit", command, log_file, iounit, command_success)
697 success = success .AND. command_success
698 IF (command_success .AND. .NOT. ref%keep_files)
CALL tb_delete_file(log_file)
699 IF (command_success .AND. .NOT. ref%keep_files .AND. len_trim(ref%fit_cli%copy_file) > 0)
THEN
700 CALL tb_delete_file(ref%fit_cli%copy_file)
704 IF (ref%tagdiff_cli%enabled)
THEN
706 IF (ref%tagdiff_cli%fit) method_str =
" --fit"
707 log_file = trim(file_base)//
".tagdiff.log"
708 command = trim(tb_shell_quote(ref%program_name))//
" tagdiff"// &
709 trim(method_str)//
" "//trim(tb_shell_quote(ref%tagdiff_cli%actual_file))// &
710 " "//trim(tb_shell_quote(ref%tagdiff_cli%reference_file))// &
711 " > "//trim(tb_shell_quote(log_file))//
" 2>&1"
712 CALL tb_reference_cli_execute(ref,
"tagdiff", command, log_file, iounit, command_success)
713 success = success .AND. command_success
714 IF (command_success .AND. .NOT. ref%keep_files)
CALL tb_delete_file(log_file)
717 END SUBROUTINE tb_reference_cli_aux_commands
729 SUBROUTINE tb_reference_cli_execute(ref, label, command, log_file, iounit, success)
732 CHARACTER(LEN=*),
INTENT(IN) :: label, command, log_file
733 INTEGER,
INTENT(IN) :: iounit
734 LOGICAL,
INTENT(OUT) :: success
736 CHARACTER(LEN=default_path_length) :: cmdmsg
737 INTEGER :: cmdstat, exitstat
742 CALL execute_command_line(trim(command), exitstat=exitstat, cmdstat=cmdstat, cmdmsg=cmdmsg)
743 success = cmdstat == 0 .AND. exitstat == 0
744 IF (.NOT. success)
THEN
745 WRITE (unit=iounit, fmt=
"(/,T2,A)")
"tblite reference CLI check failed to run."
746 WRITE (unit=iounit, fmt=
"(T2,A,A)")
"Command: ", trim(command)
747 WRITE (unit=iounit, fmt=
"(T2,A,I0,T32,A,I0)")
"cmdstat:", cmdstat,
"exitstat:", exitstat
748 IF (cmdstat /= 0)
WRITE (unit=iounit, fmt=
"(T2,A,A)")
"Execution error: ", trim(cmdmsg)
749 WRITE (unit=iounit, fmt=
"(T2,A,A)")
"Diagnostic files retained; log: ", trim(log_file)
750 IF (ref%stop_on_error) cpabort(
"tblite reference CLI command failed")
752 WRITE (unit=iounit, fmt=
"(/,T2,A,A)")
"tblite reference CLI command completed: ", &
754 WRITE (unit=iounit, fmt=
"(T2,A,A)")
"Log file: ", trim(log_file)
757 END SUBROUTINE tb_reference_cli_execute
765 FUNCTION tb_join_path(directory, filename)
RESULT(path)
766 CHARACTER(LEN=*),
INTENT(IN) :: directory, filename
767 CHARACTER(LEN=default_path_length) :: path
769 IF (len_trim(directory) == 0 .OR. trim(directory) ==
".")
THEN
770 path = trim(filename)
771 ELSE IF (directory(len_trim(directory):len_trim(directory)) ==
"/")
THEN
772 path = trim(directory)//trim(filename)
774 path = trim(directory)//
"/"//trim(filename)
777 END FUNCTION tb_join_path
784 FUNCTION tb_shell_quote(text)
RESULT(quoted)
785 CHARACTER(LEN=*),
INTENT(IN) :: text
786 CHARACTER(LEN=4*LEN_TRIM(text)+2) :: quoted
792 DO i = 1, len_trim(text)
793 IF (text(i:i) ==
"'")
THEN
796 quoted(pos:pos + 3) =
"'"//achar(92)//
"''"
799 quoted(pos:pos) = text(i:i)
803 quoted(pos:pos) =
"'"
805 END FUNCTION tb_shell_quote
812 SUBROUTINE tb_write_reference_gen(qs_env, filename)
815 CHARACTER(LEN=*),
INTENT(IN) :: filename
817 CHARACTER(LEN=2),
ALLOCATABLE,
DIMENSION(:) :: symbols, unique_symbols
818 INTEGER :: iatom, ikind, natom, nuniq, unit_nr
819 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: species
820 INTEGER,
DIMENSION(3) :: periodic
822 REAL(kind=
dp) :: to_angstrom
826 NULLIFY (cell, particle_set)
827 CALL get_qs_env(qs_env=qs_env, cell=cell, particle_set=particle_set)
829 natom =
SIZE(particle_set)
831 ALLOCATE (symbols(natom), unique_symbols(natom), species(natom))
834 CALL get_atomic_kind(particle_set(iatom)%atomic_kind, element_symbol=symbols(iatom))
837 IF (trim(unique_symbols(ikind)) == trim(symbols(iatom)))
THEN
842 IF (.NOT. found)
THEN
844 unique_symbols(nuniq) = symbols(iatom)
847 species(iatom) = ikind
850 CALL open_file(file_name=filename, unit_number=unit_nr, file_status=
"REPLACE", &
853 CALL get_cell(cell=cell, periodic=periodic)
854 IF (any(periodic == 1))
THEN
855 WRITE (unit=unit_nr, fmt=
"(I0,1X,A)") natom,
"S"
857 WRITE (unit=unit_nr, fmt=
"(I0,1X,A)") natom,
"C"
859 WRITE (unit=unit_nr, fmt=
"(*(A,1X))") (trim(unique_symbols(ikind)), ikind=1, nuniq)
861 WRITE (unit=unit_nr, fmt=
"(I0,1X,I0,3(1X,ES24.16))") &
862 iatom, species(iatom), particle_set(iatom)%r(:)*to_angstrom
864 IF (any(periodic == 1))
THEN
865 WRITE (unit=unit_nr, fmt=
"(3(1X,ES24.16))") 0.0_dp, 0.0_dp, 0.0_dp
867 WRITE (unit=unit_nr, fmt=
"(3(1X,ES24.16))") cell%hmat(:, ikind)*to_angstrom
872 DEALLOCATE (symbols, unique_symbols, species)
874 END SUBROUTINE tb_write_reference_gen
887 SUBROUTINE tb_read_reference_grad(filename, natom, energy, gradient, virial, &
888 have_energy, have_gradient, have_virial)
890 CHARACTER(LEN=*),
INTENT(IN) :: filename
891 INTEGER,
INTENT(IN) :: natom
892 REAL(kind=
dp),
INTENT(OUT) :: energy
893 REAL(kind=
dp),
DIMENSION(:, :),
INTENT(OUT) :: gradient, virial
894 LOGICAL,
INTENT(OUT) :: have_energy, have_gradient, have_virial
896 CHARACTER(LEN=1024) :: line
897 INTEGER :: ios, nread, unit_nr
898 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: values
900 have_energy = .false.
901 have_gradient = .false.
902 have_virial = .false.
908 OPEN (newunit=unit_nr, file=trim(filename), status=
"OLD", action=
"READ", &
909 form=
"FORMATTED", iostat=ios)
913 READ (unit=unit_nr, fmt=
"(A)", iostat=ios) line
915 IF (index(line,
"energy :real:0:") > 0)
THEN
916 READ (unit=unit_nr, fmt=
"(A)", iostat=ios) line
918 READ (line, *, iostat=ios) energy
919 have_energy = ios == 0
921 ELSE IF (index(line,
"gradient :real:2:3,") > 0)
THEN
922 ALLOCATE (values(3*natom))
923 CALL tb_read_real_values(unit_nr, values, nread)
924 IF (nread == 3*natom)
THEN
925 CALL tb_values_to_matrix(values, gradient)
926 have_gradient = .true.
929 ELSE IF (index(line,
"virial :real:2:3,3") > 0)
THEN
931 CALL tb_read_real_values(unit_nr, values, nread)
933 CALL tb_values_to_matrix(values, virial)
941 END SUBROUTINE tb_read_reference_grad
949 SUBROUTINE tb_read_real_values(unit_nr, values, nread)
951 INTEGER,
INTENT(IN) :: unit_nr
952 REAL(kind=
dp),
DIMENSION(:),
INTENT(OUT) :: values
953 INTEGER,
INTENT(OUT) :: nread
955 CHARACTER(LEN=1024) :: line
959 DO WHILE (nread <
SIZE(values))
960 READ (unit=unit_nr, fmt=
"(A)", iostat=ios) line
962 CALL tb_parse_real_line(line, values, nread)
965 END SUBROUTINE tb_read_real_values
973 SUBROUTINE tb_parse_real_line(line, values, nread)
975 CHARACTER(LEN=*),
INTENT(IN) :: line
976 REAL(kind=
dp),
DIMENSION(:),
INTENT(INOUT) :: values
977 INTEGER,
INTENT(INOUT) :: nread
979 CHARACTER(LEN=128) :: token
980 INTEGER :: first, ios, last, pos
983 DO WHILE (pos <= len_trim(line) .AND. nread <
SIZE(values))
984 DO WHILE (pos <= len_trim(line) .AND. index(
" ,[]", line(pos:pos)) > 0)
987 IF (pos > len_trim(line))
EXIT
989 DO WHILE (pos <= len_trim(line) .AND. index(
" ,[]", line(pos:pos)) == 0)
993 token = line(first:last)
994 READ (token, *, iostat=ios) values(nread + 1)
995 IF (ios == 0) nread = nread + 1
998 END SUBROUTINE tb_parse_real_line
1005 SUBROUTINE tb_values_to_matrix(values, matrix)
1007 REAL(kind=
dp),
DIMENSION(:),
INTENT(IN) :: values
1008 REAL(kind=
dp),
DIMENSION(:, :),
INTENT(OUT) :: matrix
1013 DO j = 1,
SIZE(matrix, 2)
1014 DO i = 1,
SIZE(matrix, 1)
1016 matrix(i, j) = values(n)
1020 END SUBROUTINE tb_values_to_matrix
1031 SUBROUTINE tb_reference_cleanup(ref, gen_file, grad_file, json_file, log_file, post_processing_output_file)
1034 CHARACTER(LEN=*),
INTENT(IN) :: gen_file, grad_file, json_file, &
1035 log_file, post_processing_output_file
1037 IF (ref%keep_files)
RETURN
1038 CALL tb_delete_file(gen_file)
1039 CALL tb_delete_file(grad_file)
1040 CALL tb_delete_file(json_file)
1041 CALL tb_delete_file(log_file)
1042 IF (len_trim(post_processing_output_file) > 0)
THEN
1043 CALL tb_delete_file(post_processing_output_file)
1046 END SUBROUTINE tb_reference_cleanup
1052 SUBROUTINE tb_delete_file(filename)
1054 CHARACTER(LEN=*),
INTENT(IN) :: filename
1060 IF (istat /= 0)
RETURN
1062 END SUBROUTINE tb_delete_file
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.
Handles all functions related to the CELL.
subroutine, public get_cell(cell, alpha, beta, gamma, deth, orthorhombic, abc, periodic, h, h_inv, symmetry_id, tag)
Get informations about a simulation cell.
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
Utility routines to open and close files.
subroutine, public open_file(file_name, unit_number, file_status, file_form, file_action, file_position, file_pad, file_access, debug)
Opens a file and returns its logical unit number.
subroutine, public close_file(unit_number, file_status)
Closes an open file given by its logical unit number.
various routines to log and control the output. The idea is that decisions about where to log should ...
integer function, public cp_logger_get_default_io_unit(logger)
returns the unit nr for the ionode (-1 on all other processors) skips as well checks if the procs cal...
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, parameter, public debug_print_level
integer, parameter, public high_print_level
integer, parameter, public silent_print_level
real(kind=dp) function, public cp_unit_from_cp2k(value, unit_str, defaults, power)
converts from the internal cp2k units to the given unit
Defines the basic variable types.
integer, parameter, public dp
integer, parameter, public default_path_length
Types and basic routines needed for a kpoint calculation.
subroutine, public get_kpoint_info(kpoint, kp_scheme, nkp_grid, kp_shift, symmetry, verbose, full_grid, use_real_wfn, eps_geo, parallel_group_size, kp_range, nkp, xkp, wkp, para_env, blacs_env_all, para_env_kp, para_env_inter_kp, blacs_env, kp_env, kp_aux_env, mpools, iogrp, nkp_groups, kp_dist, cell_to_index, index_to_cell, sab_nl, sab_nl_nosym, inversion_symmetry_only, symmetry_backend, symmetry_reduction_method, gamma_centered, lattice_fft)
Retrieve information from a kpoint environment.
Machine interface based on Fortran 2003 and POSIX.
integer function, public m_unlink(path)
...
Interface to the message passing library MPI.
Define the data structure for the particle information.
subroutine, public get_qs_env(qs_env, atomic_kind_set, qs_kind_set, cell, super_cell, cell_ref, use_ref_cell, kpoints, dft_control, mos, sab_orb, sab_all, qmmm, qmmm_periodic, mimic, sac_ae, sac_ppl, sac_lri, sap_ppnl, sab_vdw, sab_scp, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, sab_xb, sab_xtb_pp, sab_xtb_nonbond, sab_almo, sab_kp, sab_kp_nosym, sab_cneo, particle_set, energy, force, matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, run_rtp, rtp, matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_ks_im_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, matrix_s_ri_aux_kp, matrix_s, matrix_s_ri_aux, matrix_w, matrix_p_mp2, matrix_p_mp2_admm, matrix_vhxc, rho, rho_xc, pw_env, ewald_env, ewald_pw, active_space, mpools, input, para_env, blacs_env, scf_control, rel_control, kinetic, qs_charges, vppl, xcint_weights, rho_core, rho_nlcc, rho_nlcc_g, ks_env, ks_qmmm_env, wf_history, scf_env, local_particles, local_molecules, distribution_2d, dbcsr_dist, molecule_kind_set, molecule_set, subsys, cp_subsys, oce, local_rho_set, rho_atom_set, task_list, task_list_soft, rho0_atom_set, rho0_mpole, rhoz_set, rhoz_cneo_set, ecoul_1c, rho0_s_rs, rho0_s_gs, rhoz_cneo_s_rs, rhoz_cneo_s_gs, do_kpoints, has_unit_metric, requires_mo_derivs, mo_derivs, mo_loc_history, nkind, natom, nelectron_total, nelectron_spin, efield, neighbor_list_id, linres_control, xas_env, virial, cp_ddapc_env, cp_ddapc_ewald, outer_scf_history, outer_scf_ihistory, x_data, et_coupling, dftb_potential, results, se_taper, se_store_int_env, se_nddo_mpole, se_nonbond_env, admm_env, lri_env, lri_density, exstate_env, ec_env, harris_env, dispersion_env, gcp_env, vee, rho_external, external_vxc, mask, mp2_env, bs_env, kg_env, wanniercentres, atprop, ls_scf_env, do_transport, transport_env, v_hartree_rspace, s_mstruct_changed, rho_changed, potential_changed, forces_up_to_date, mscfg_env, almo_scf_env, gradient_history, variable_history, embed_pot, spin_embed_pot, polar_env, mos_last_converged, eeq, rhs, do_rixs, tb_tblite)
Get the QUICKSTEP environment.
subroutine, public total_qs_force(force, qs_force, atomic_kind_set)
Get current total force.
parameters that control an scf iteration
Optional native tblite command-line diagnostics.
subroutine, public tb_reference_cli_compare(qs_env)
Run native tblite CLI and compare against CP2K/tblite.
Provides all information about an atomic kind.
Type defining parameters related to the simulation cell.
type of a logger, at the moment it contains just a print level starting at which level it should be l...
Contains information about kpoints.
stores all the informations relevant to an mpi environment