52#include "./base/base_uses.f90"
57 LOGICAL,
PRIVATE,
PARAMETER :: debug_this_module = .true.
58 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'bsse'
82 INTEGER :: i, istart, num_of_conf, num_of_frag
83 INTEGER,
DIMENSION(:, :),
POINTER :: conf
84 LOGICAL :: explicit, should_stop
85 REAL(kind=
dp),
DIMENSION(:),
POINTER :: em
90 NULLIFY (bsse_section, n_frags, em, conf)
92 root_section => force_env%root_section
98 num_of_conf = ishft(1, num_of_frag) - 1
99 ALLOCATE (conf(num_of_conf, num_of_frag))
100 ALLOCATE (em(num_of_conf))
101 CALL gen_nbody_conf(num_of_frag, conf)
103 should_stop = .false.
116 CALL cp_iterate(logger%iter_info, last=.false., iter_nr=istart)
119 DO i = istart + 1, num_of_conf
120 CALL cp_iterate(logger%iter_info, last=(i == num_of_conf), iter_nr=i)
121 CALL eval_bsse_energy(conf(i, :), em(i), force_env, n_frags, &
122 root_section, globenv, should_stop)
123 IF (should_stop)
EXIT
127 IF (should_stop)
EXIT
133 CALL write_bsse_restart(bsse_section, root_section)
135 IF (.NOT. should_stop)
CALL dump_bsse_results(conf, em, num_of_frag, bsse_section)
155 SUBROUTINE eval_bsse_energy(conf, Em, force_env, n_frags, root_section, &
156 globenv, should_stop)
157 INTEGER,
DIMENSION(:),
INTENT(IN) :: conf
158 REAL(kind=
dp),
INTENT(OUT) :: em
162 LOGICAL,
INTENT(OUT) :: should_stop
164 INTEGER :: i, j, k, num_of_sub_conf, num_of_sub_frag
165 INTEGER,
DIMENSION(:, :),
POINTER :: conf_loc
166 REAL(kind=
dp) :: my_energy
167 REAL(kind=
dp),
DIMENSION(:),
POINTER :: em_loc
169 NULLIFY (conf_loc, em_loc)
170 should_stop = .false.
172 num_of_sub_frag = count(conf == 1)
174 IF (num_of_sub_frag == 1)
THEN
175 CALL eval_bsse_energy_low(force_env, conf, conf, n_frags, root_section, globenv, em)
178 num_of_sub_conf = ishft(1, num_of_sub_frag) - 1
179 ALLOCATE (conf_loc(num_of_sub_conf, num_of_sub_frag))
180 ALLOCATE (em_loc(num_of_sub_conf))
182 CALL gen_nbody_conf(num_of_sub_frag, conf_loc)
183 CALL make_plan_conf(conf, conf_loc)
184 DO i = 1, num_of_sub_conf
185 CALL eval_bsse_energy_low(force_env, conf, conf_loc(i, :), n_frags, &
186 root_section, globenv, em_loc(i))
188 IF (should_stop)
EXIT
192 DO i = 1, num_of_sub_conf
193 j = count(conf_loc(i, :) == 1)
194 my_energy = my_energy + (-1.0_dp)**(k + j)*em_loc(i)
198 DEALLOCATE (conf_loc)
201 END SUBROUTINE eval_bsse_energy
217 SUBROUTINE eval_bsse_energy_low(force_env, conf, conf_loc, n_frags, &
218 root_section, globenv, energy)
220 INTEGER,
DIMENSION(:),
INTENT(IN) :: conf, conf_loc
223 REAL(kind=
dp),
INTENT(OUT) :: energy
225 CHARACTER(LEN=default_string_length) :: name
226 CHARACTER(len=default_string_length), &
227 DIMENSION(:),
POINTER :: atom_type
228 INTEGER :: i, ir, isize, j, k, method_name_id, &
229 my_targ, n_rep, num_of_frag, old_size, &
230 present_charge, present_multpl
231 INTEGER,
DIMENSION(:),
POINTER :: atom_index, atom_list, my_conf, tmplist
236 force_env_section, subsys_section
239 cpassert(
SIZE(conf) == num_of_frag)
240 NULLIFY (subsys, particles, para_env, atom_index, atom_type, tmplist, &
242 CALL force_env_get(force_env, force_env_section=force_env_section)
248 ALLOCATE (my_conf(
SIZE(conf)))
250 CALL force_env_get(force_env=force_env, subsys=subsys, para_env=para_env)
253 ALLOCATE (atom_index(isize))
254 DO i = 1, num_of_frag
255 IF (conf(i) == 1)
THEN
264 CALL reallocate(atom_index, 1, isize +
SIZE(tmplist))
265 atom_index(isize + 1:isize +
SIZE(tmplist)) = tmplist
266 isize =
SIZE(atom_index)
269 my_conf(i) = isize - old_size
270 cpassert(conf(i) /= 0)
273 CALL conf_info_setup(present_charge, present_multpl, conf, conf_loc, bsse_section, &
278 ALLOCATE (atom_type(isize))
280 my_targ = atom_index(j)
281 DO k = 1,
SIZE(particles%els)
282 CALL get_atomic_kind(particles%els(k)%atomic_kind, atom_list=atom_list, name=name)
283 IF (any(atom_list == my_targ))
EXIT
287 DO i = 1,
SIZE(conf_loc)
288 IF (my_conf(i) /= 0 .AND. conf_loc(i) == 0)
THEN
289 DO j = sum(my_conf(1:i - 1)) + 1, sum(my_conf(1:i))
290 atom_type(j) = trim(atom_type(j))//
"_ghost"
294 CALL dump_bsse_info(atom_index, atom_type, conf, conf_loc, bsse_section, &
295 present_charge, present_multpl)
300 IF (method_name_id ==
do_qs)
THEN
307 small_para_env=para_env, small_cell=subsys%cell, sub_atom_index=atom_index, &
308 sub_atom_kind_name=atom_type, para_env=para_env, &
309 force_env_section=force_env_section, subsys_section=subsys_section)
313 CALL qs_init(qs_env, para_env, root_section, globenv=globenv, cp_subsys=subsys_loc, &
314 force_env_section=force_env_section, subsys_section=subsys_section, &
315 use_motion_section=.false.)
328 cpabort(
"BSSE calculation is only available for QuickStep method!")
330 DEALLOCATE (atom_index)
331 DEALLOCATE (atom_type)
334 END SUBROUTINE eval_bsse_energy_low
349 SUBROUTINE dump_bsse_info(atom_index, atom_type, conf, conf_loc, bsse_section, &
350 present_charge, present_multpl)
351 INTEGER,
DIMENSION(:),
POINTER :: atom_index
352 CHARACTER(len=default_string_length), &
353 DIMENSION(:),
POINTER :: atom_type
354 INTEGER,
DIMENSION(:),
INTENT(IN) :: conf, conf_loc
355 TYPE(section_vals_type),
POINTER :: bsse_section
356 INTEGER,
INTENT(IN) :: present_charge, present_multpl
358 INTEGER :: i, istat, iw
359 CHARACTER(len=20*SIZE(conf)) :: conf_loc_s, conf_s
360 TYPE(cp_logger_type),
POINTER :: logger
363 logger => cp_get_default_logger()
364 iw = cp_print_key_unit_nr(logger, bsse_section,
"PRINT%PROGRAM_RUN_INFO", &
367 WRITE (conf_s, fmt=
"(1000I0)", iostat=istat) conf
368 IF (istat /= 0) conf_s =
"exceeded"
369 CALL compress(conf_s, full=.true.)
370 WRITE (conf_loc_s, fmt=
"(1000I0)", iostat=istat) conf_loc
371 IF (istat /= 0) conf_loc_s =
"exceeded"
372 CALL compress(conf_loc_s, full=.true.)
374 WRITE (unit=iw, fmt=
"(/,T2,A)") repeat(
"-", 79)
375 WRITE (unit=iw, fmt=
"(T2,A,T80,A)")
"-",
"-"
376 WRITE (unit=iw, fmt=
"(T2,A,T5,A,T30,A,T55,A,T80,A)") &
377 "-",
"BSSE CALCULATION",
"FRAGMENT CONF: "//trim(conf_s),
"FRAGMENT SUBCONF: "//trim(conf_loc_s),
"-"
378 WRITE (unit=iw, fmt=
"(T2,A,T30,A,I6,T55,A,I6,T80,A)")
"-",
"CHARGE =", present_charge,
"MULTIPLICITY =", &
380 WRITE (unit=iw, fmt=
"(T2,A,T80,A)")
"-",
"-"
381 WRITE (unit=iw, fmt=
"(T2,A,T20,A,T60,A,T80,A)")
"-",
"ATOM INDEX",
"ATOM NAME",
"-"
382 WRITE (unit=iw, fmt=
"(T2,A,T20,A,T60,A,T80,A)")
"-",
"----------",
"---------",
"-"
383 DO i = 1,
SIZE(atom_index)
384 WRITE (unit=iw, fmt=
"(T2,A,T20,I6,T61,A,T80,A)")
"-", atom_index(i), trim(atom_type(i)),
"-"
386 WRITE (unit=iw, fmt=
"(T2,A)") repeat(
"-", 79)
388 CALL cp_print_key_finished_output(iw, logger, bsse_section, &
389 "PRINT%PROGRAM_RUN_INFO")
392 END SUBROUTINE dump_bsse_info
406 SUBROUTINE conf_info_setup(present_charge, present_multpl, conf, conf_loc, &
407 bsse_section, dft_section)
408 INTEGER,
INTENT(OUT) :: present_charge, present_multpl
409 INTEGER,
DIMENSION(:),
INTENT(IN) :: conf, conf_loc
410 TYPE(section_vals_type),
POINTER :: bsse_section, dft_section
413 INTEGER,
DIMENSION(:),
POINTER :: glb_conf, sub_conf
415 TYPE(section_vals_type),
POINTER :: configurations
419 NULLIFY (configurations, glb_conf, sub_conf)
421 configurations => section_vals_get_subs_vals(bsse_section,
"CONFIGURATION")
422 CALL section_vals_get(configurations, explicit=explicit, n_repetition=nconf)
425 CALL section_vals_val_get(configurations,
"GLB_CONF", i_rep_section=i, i_vals=glb_conf)
426 IF (
SIZE(glb_conf) /=
SIZE(conf))
THEN
427 CALL cp_abort(__location__, &
428 "GLB_CONF requires a binary description of the configuration. Number of integer "// &
429 "different from the number of fragments defined!")
431 CALL section_vals_val_get(configurations,
"SUB_CONF", i_rep_section=i, i_vals=sub_conf)
432 IF (
SIZE(sub_conf) /=
SIZE(conf))
THEN
433 CALL cp_abort(__location__, &
434 "SUB_CONF requires a binary description of the configuration. Number of integer "// &
435 "different from the number of fragments defined!")
437 IF (all(conf == glb_conf) .AND. all(conf_loc == sub_conf))
THEN
438 CALL section_vals_val_get(configurations,
"CHARGE", i_rep_section=i, &
439 i_val=present_charge)
440 CALL section_vals_val_get(configurations,
"MULTIPLICITY", i_rep_section=i, &
441 i_val=present_multpl)
446 CALL section_vals_val_set(dft_section,
"CHARGE", i_val=present_charge)
447 CALL section_vals_val_set(dft_section,
"MULTIPLICITY", i_val=present_multpl)
448 END SUBROUTINE conf_info_setup
460 SUBROUTINE dump_bsse_results(conf, Em, num_of_frag, bsse_section)
461 INTEGER,
DIMENSION(:, :),
INTENT(IN) :: conf
462 REAL(kind=dp),
DIMENSION(:),
POINTER :: em
463 INTEGER,
INTENT(IN) :: num_of_frag
464 TYPE(section_vals_type),
POINTER :: bsse_section
467 TYPE(cp_logger_type),
POINTER :: logger
470 logger => cp_get_default_logger()
471 iw = cp_print_key_unit_nr(logger, bsse_section,
"PRINT%PROGRAM_RUN_INFO", &
475 WRITE (unit=iw, fmt=
"(/,T2,A)") repeat(
"-", 79)
476 WRITE (unit=iw, fmt=
"(T2,A,T80,A)")
"-",
"-"
477 WRITE (unit=iw, fmt=
"(T2,A,T36,A,T80,A)") &
478 "-",
"BSSE RESULTS",
"-"
479 WRITE (unit=iw, fmt=
"(T2,A,T80,A)")
"-",
"-"
480 WRITE (unit=iw, fmt=
"(T2,A,T20,A,F16.6,T80,A)")
"-",
"CP-corrected Total energy:", sum(em),
"-"
481 WRITE (unit=iw, fmt=
"(T2,A,T80,A)")
"-",
"-"
482 DO i = 1,
SIZE(conf, 1)
484 IF (sum(conf(i - 1, :)) == 1 .AND. sum(conf(i, :)) /= 1)
THEN
485 WRITE (unit=iw, fmt=
"(T2,A,T80,A)")
"-",
"-"
488 WRITE (unit=iw, fmt=
"(T2,A,T24,I3,A,F16.6,T80,A)")
"-", sum(conf(i, :)),
"-body contribution:", em(i),
"-"
490 WRITE (unit=iw, fmt=
"(T2,A,T20,A,F16.6,T80,A)")
"-",
"BSSE-free interaction energy:", sum(em(num_of_frag + 1:)),
"-"
491 WRITE (unit=iw, fmt=
"(T2,A)") repeat(
"-", 79)
494 CALL cp_print_key_finished_output(iw, logger, bsse_section, &
495 "PRINT%PROGRAM_RUN_INFO")
497 END SUBROUTINE dump_bsse_results
507 SUBROUTINE gen_nbody_conf(Num_of_frag, conf)
508 INTEGER,
INTENT(IN) :: num_of_frag
509 INTEGER,
DIMENSION(:, :),
POINTER :: conf
518 DO k = 1, num_of_frag
519 CALL build_nbody_conf(1, num_of_frag, conf, k, my_ind)
521 END SUBROUTINE gen_nbody_conf
531 RECURSIVE SUBROUTINE build_nbody_conf(ldown, lup, conf, k, my_ind)
532 INTEGER,
INTENT(IN) :: ldown, lup
533 INTEGER,
DIMENSION(:, :),
POINTER :: conf
534 INTEGER,
INTENT(IN) :: k
535 INTEGER,
INTENT(INOUT) :: my_ind
537 INTEGER :: i, kloc, my_ind0
543 CALL build_nbody_conf(i + 1, lup, conf, kloc, my_ind)
544 conf(my_ind0 + 1:my_ind, i) = 1
553 END SUBROUTINE build_nbody_conf
560 SUBROUTINE make_plan_conf(main_conf, conf)
561 INTEGER,
DIMENSION(:),
INTENT(IN) :: main_conf
562 INTEGER,
DIMENSION(:, :),
POINTER :: conf
565 INTEGER,
DIMENSION(:, :),
POINTER :: tmp_conf
567 ALLOCATE (tmp_conf(
SIZE(conf, 1),
SIZE(main_conf)))
570 DO i = 1,
SIZE(main_conf)
571 IF (main_conf(i) /= 0)
THEN
573 tmp_conf(:, i) = conf(:, ind)
577 ALLOCATE (conf(
SIZE(tmp_conf, 1),
SIZE(tmp_conf, 2)))
579 DEALLOCATE (tmp_conf)
581 END SUBROUTINE make_plan_conf
591 SUBROUTINE write_bsse_restart(bsse_section, root_section)
593 TYPE(section_vals_type),
POINTER :: bsse_section, root_section
596 TYPE(cp_logger_type),
POINTER :: logger
598 logger => cp_get_default_logger()
599 ires = cp_print_key_unit_nr(logger, bsse_section,
"PRINT%RESTART", &
600 extension=
".restart", do_backup=.false., file_position=
"REWIND")
603 CALL write_restart_header(ires)
604 CALL section_vals_write(root_section, unit_nr=ires, hide_root=.true.)
607 CALL cp_print_key_finished_output(ires, logger, bsse_section, &
610 END SUBROUTINE write_bsse_restart
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.
Module to perform a counterpoise correction (BSSE).
subroutine, public do_bsse_calculation(force_env, globenv)
Perform an COUNTERPOISE CORRECTION (BSSE) For a 2-body system the correction scheme can be represente...
some minimal info about CP2K, including its version and license
subroutine, public write_restart_header(iunit)
Writes the header for the restart file.
Routines to handle the external control of CP2K.
subroutine, public external_control(should_stop, flag, globenv, target_time, start_time, force_check)
External manipulations during a run : when the <PROJECT_NAME>.EXIT_$runtype command is sent the progr...
various routines to log and control the output. The idea is that decisions about where to log should ...
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...
subroutine, public cp_add_iter_level(logger, level_name, n_rlevel_new)
Adds an iteration level.
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,...
subroutine, public cp_iterate(iteration_info, last, iter_nr, increment, iter_nr_out)
adds one to the actual iteration
subroutine, public cp_rm_iter_level(logger, level_name, n_rlevel_att)
Removes an iteration level.
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, file_access)
...
Initialize a small environment for a particular calculation.
subroutine, public create_small_subsys(small_subsys, big_subsys, small_cell, small_para_env, sub_atom_index, sub_atom_kind_name, para_env, force_env_section, subsys_section, ignore_outside_box)
updates the molecule information of the given subsys
types that represent a subsys, i.e. a part of the system
subroutine, public cp_subsys_release(subsys)
releases a subsys (see doc/ReferenceCounting.html)
subroutine, public cp_subsys_get(subsys, ref_count, atomic_kinds, atomic_kind_set, particles, particle_set, local_particles, molecules, molecule_set, molecule_kinds, molecule_kind_set, local_molecules, para_env, colvar_p, shell_particles, core_particles, gci, multipoles, natom, nparticle, ncore, nshell, nkind, atprop, virial, results, cell, cell_ref, use_ref_cell)
returns information about various attributes of the given subsys
Interface for the force calculations.
recursive subroutine, public force_env_get(force_env, in_use, fist_env, qs_env, meta_env, fp_env, subsys, para_env, potential_energy, additional_potential, kinetic_energy, harmonic_shell, kinetic_shell, cell, sub_force_env, qmmm_env, qmmmx_env, eip_env, pwdft_env, globenv, input, force_env_section, method_name_id, root_section, mixed_env, nnp_env, embed_env, ipi_env)
returns various attributes about the force environment
Define type storing the global information of a run. Keep the amount of stored data small....
Defines the basic variable types.
integer, parameter, public dp
integer, parameter, public default_string_length
Utility routines for the memory handling.
Interface to the message passing library MPI.
represent a simple array based list of the given type
Perform a QUICKSTEP wavefunction optimization (single point).
subroutine, public qs_energies(qs_env, consistent_energies, calc_forces)
Driver routine for QUICKSTEP single point wavefunction optimization.
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 qs_env_release(qs_env)
releases the given qs_env (see doc/ReferenceCounting.html)
subroutine, public qs_env_create(qs_env, globenv)
allocates and intitializes a qs_env
subroutine, public qs_init(qs_env, para_env, root_section, globenv, cp_subsys, kpoint_env, qmmm, qmmm_env_qm, force_env_section, subsys_section, use_motion_section, silent, multip, charge)
Read the input and the database files for the setup of the QUICKSTEP environment.
Utilities for string manipulations.
subroutine, public compress(string, full)
Eliminate multiple space characters in a string. If full is .TRUE., then all spaces are eliminated.
type of a logger, at the moment it contains just a print level starting at which level it should be l...
represents a system: atoms, molecules, their pos,vel,...
wrapper to abstract the force evaluation of the various methods
contains the initially parsed file and the initial parallel environment
stores all the informations relevant to an mpi environment
represent a list of objects