51#include "./base/base_uses.f90"
56 LOGICAL,
PRIVATE,
PARAMETER :: debug_this_module = .false.
57 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'cp_ddapc'
79 SUBROUTINE qs_ks_ddapc(qs_env, auxbas_pw_pool, rho_tot_gspace, v_hartree_gspace, &
80 v_spin_ddapc_rest_r, energy, calculate_forces, ks_matrix, just_energy)
84 TYPE(
pw_c1d_gs_type),
INTENT(IN) :: rho_tot_gspace, v_hartree_gspace
87 LOGICAL,
INTENT(in) :: calculate_forces
88 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: ks_matrix
89 LOGICAL,
INTENT(in) :: just_energy
91 CHARACTER(LEN=*),
PARAMETER :: routinen =
'qs_ks_ddapc'
93 INTEGER :: ddapc_size, handle, i, my_id
94 LOGICAL :: ddapc_restraint_is_spin, &
95 et_coupling_calc, explicit_potential
102 NULLIFY (v_hartree_rspace, dft_control)
104 CALL timeset(routinen, handle)
108 ddapc_restraint_is_spin = .false.
109 et_coupling_calc = .false.
113 cpassert(
SIZE(ks_matrix, 2) == 1)
116 v_hartree_rspace=v_hartree_rspace, &
117 dft_control=dft_control)
119 IF (dft_control%qs_control%ddapc_restraint)
THEN
120 ddapc_size =
SIZE(dft_control%qs_control%ddapc_restraint_control)
121 IF (
SIZE(energy%ddapc_restraint) .NE. ddapc_size)
THEN
122 DEALLOCATE (energy%ddapc_restraint)
123 ALLOCATE (energy%ddapc_restraint(ddapc_size))
126 DO i = 1,
SIZE(dft_control%qs_control%ddapc_restraint_control)
127 my_id = dft_control%qs_control%ddapc_restraint_control(i)%density_type
128 IF (my_id ==
do_spin_density .OR. ddapc_restraint_is_spin) ddapc_restraint_is_spin = .true.
130 et_coupling_calc = dft_control%qs_control%et_coupling_calc
133 explicit_potential = ddapc_restraint_is_spin .OR. et_coupling_calc
134 dft_control%qs_control%ddapc_explicit_potential = explicit_potential
135 dft_control%qs_control%ddapc_restraint_is_spin = ddapc_restraint_is_spin
136 IF (explicit_potential)
THEN
137 CALL auxbas_pw_pool%create_pw(v_spin_ddapc_rest_g)
138 CALL pw_zero(v_spin_ddapc_rest_g)
139 NULLIFY (v_spin_ddapc_rest_r)
140 ALLOCATE (v_spin_ddapc_rest_r)
141 CALL auxbas_pw_pool%create_pw(v_spin_ddapc_rest_r)
147 CALL cp_ddapc_apply_cd(qs_env, rho_tot_gspace, energy%hartree, v_hartree_gspace, &
148 calculate_forces, itype_of_density=
"FULL DENSITY")
149 IF (dft_control%qs_control%ddapc_restraint)
THEN
152 NULLIFY (ddapc_restraint_control)
153 ddapc_restraint_control => dft_control%qs_control%ddapc_restraint_control(i)
155 CALL cp_ddapc_apply_rs(qs_env, energy%ddapc_restraint(i), v_hartree_gspace, &
156 v_spin_ddapc_rest_g, ddapc_restraint_control, calculate_forces)
159 CALL cp_ddapc_apply_rf(qs_env, rho_tot_gspace, energy%hartree, v_hartree_gspace, &
160 calculate_forces, itype_of_density=
"FULL DENSITY")
163 IF ((.NOT. just_energy) .OR. et_coupling_calc)
THEN
164 CALL pw_transfer(v_hartree_gspace, v_hartree_rspace)
165 CALL pw_scale(v_hartree_rspace, v_hartree_rspace%pw_grid%dvol)
166 IF (explicit_potential)
THEN
167 CALL pw_transfer(v_spin_ddapc_rest_g, v_spin_ddapc_rest_r)
168 CALL pw_scale(v_spin_ddapc_rest_r, v_spin_ddapc_rest_r%pw_grid%dvol)
169 IF (et_coupling_calc)
THEN
170 IF (qs_env%et_coupling%keep_matrix)
THEN
171 IF (qs_env%et_coupling%first_run)
THEN
172 NULLIFY (qs_env%et_coupling%rest_mat(1)%matrix)
173 ALLOCATE (qs_env%et_coupling%rest_mat(1)%matrix)
174 CALL dbcsr_copy(qs_env%et_coupling%rest_mat(1)%matrix, ks_matrix(1, 1)%matrix, &
175 name=
"ET_RESTRAINT_MATRIX_B")
176 CALL dbcsr_set(qs_env%et_coupling%rest_mat(1)%matrix, 0.0_dp)
177 CALL integrate_v_rspace(v_spin_ddapc_rest_r, &
178 hmat=qs_env%et_coupling%rest_mat(1), &
179 qs_env=qs_env, calculate_forces=.false.)
180 qs_env%et_coupling%order_p = &
181 dft_control%qs_control%ddapc_restraint_control(1)%ddapc_order_p
182 qs_env%et_coupling%e1 = dft_control%qs_control%ddapc_restraint_control(1)%strength
183 qs_env%et_coupling%keep_matrix = .false.
185 NULLIFY (qs_env%et_coupling%rest_mat(2)%matrix)
186 ALLOCATE (qs_env%et_coupling%rest_mat(2)%matrix)
187 CALL dbcsr_copy(qs_env%et_coupling%rest_mat(2)%matrix, ks_matrix(1, 1)%matrix, &
188 name=
"ET_RESTRAINT_MATRIX_B")
189 CALL dbcsr_set(qs_env%et_coupling%rest_mat(2)%matrix, 0.0_dp)
190 CALL integrate_v_rspace(v_spin_ddapc_rest_r, &
191 hmat=qs_env%et_coupling%rest_mat(2), &
192 qs_env=qs_env, calculate_forces=.false.)
199 IF (explicit_potential)
THEN
200 CALL auxbas_pw_pool%give_back_pw(v_spin_ddapc_rest_g)
202 CALL timestop(handle)
225 calculate_forces, Itype_of_density)
228 REAL(kind=
dp),
INTENT(INOUT) :: energy
230 LOGICAL,
INTENT(IN),
OPTIONAL :: calculate_forces
231 CHARACTER(LEN=*) :: itype_of_density
233 CHARACTER(len=*),
PARAMETER :: routinen =
'cp_ddapc_apply_CD'
235 INTEGER :: handle, iw
236 LOGICAL :: apply_decpl, need_f
237 REAL(kind=
dp) :: e_decpl, e_recpl
238 REAL(kind=
dp),
DIMENSION(:),
POINTER :: charges, radii
239 REAL(kind=
dp),
DIMENSION(:, :, :),
POINTER :: dq
240 TYPE(
cell_type),
POINTER :: cell, super_cell
244 multipole_section, poisson_section, &
245 qmmm_periodic_section
247 CALL timeset(routinen, handle)
249 IF (
PRESENT(calculate_forces)) need_f = calculate_forces
251 apply_decpl = qs_env%cp_ddapc_ewald%do_decoupling .OR. qs_env%cp_ddapc_ewald%do_qmmm_periodic_decpl
252 IF (apply_decpl)
THEN
254 NULLIFY (multipole_section, &
258 qmmm_periodic_section, &
259 density_fit_section, &
267 input=force_env_section, &
268 particle_set=particle_set, &
270 super_cell=super_cell)
271 cpassert(
ASSOCIATED(qs_env%cp_ddapc_ewald))
276 IF (qs_env%cp_ddapc_ewald%do_decoupling)
THEN
279 IF (qs_env%cp_ddapc_ewald%do_qmmm_periodic_decpl)
THEN
285 extension=
".fitChargeLog")
290 density_fit_section, &
294 ext_rho_tot_g=rho_tot_gspace, &
295 itype_of_density=itype_of_density)
299 density_fit_section, &
302 ext_rho_tot_g=rho_tot_gspace, &
303 itype_of_density=itype_of_density)
307 e_decpl = 0.5_dp*dot_product(charges, matmul(qs_env%cp_ddapc_env%Md, charges))
308 WRITE (iw, fmt=
"(T3,A,T60,F20.10)")
"Decoupling Energy: ", e_decpl
310 IF (qs_env%cp_ddapc_ewald%do_qmmm_periodic_decpl .AND. (iw > 0))
THEN
311 e_recpl = 0.5_dp*dot_product(charges, matmul(qs_env%cp_ddapc_env%Mr, charges))
312 WRITE (iw, fmt=
"(T3,A,T60,F20.10)")
"Recoupling Energy: ", e_recpl
315 density_fit_section, &
317 qs_env%cp_ddapc_env%Mt, &
318 qs_env%cp_ddapc_env%AmI, &
325 .false., 1.0_dp, multipole_section, cell, particle_set, &
327 IF (qs_env%cp_ddapc_ewald%do_qmmm_periodic_decpl)
THEN
329 .true., -1.0_dp, multipole_section, super_cell, particle_set, &
336 IF (
ASSOCIATED(dq))
THEN
342 CALL timestop(handle)
358 SUBROUTINE cp_ddapc_apply_rs(qs_env, energy_res, v_hartree_gspace, &
359 v_spin_ddapc_rest_g, ddapc_restraint_control, calculate_forces)
361 REAL(kind=
dp),
INTENT(INOUT),
OPTIONAL :: energy_res
362 TYPE(
pw_c1d_gs_type),
INTENT(IN) :: v_hartree_gspace, v_spin_ddapc_rest_g
364 LOGICAL,
INTENT(IN),
OPTIONAL :: calculate_forces
366 CHARACTER(len=*),
PARAMETER :: routinen =
'cp_ddapc_apply_RS'
368 INTEGER :: handle, iw, my_id
369 LOGICAL :: apply_restrain, need_f
370 REAL(kind=
dp),
DIMENSION(:),
POINTER :: charges, radii
371 REAL(kind=
dp),
DIMENSION(:, :, :),
POINTER :: dq
372 TYPE(
cell_type),
POINTER :: cell, super_cell
379 CALL timeset(routinen, handle)
380 NULLIFY (dft_control, restraint_section, force_env_section, particle_set, &
381 charges, radii, dq, cell, density_fit_section, super_cell)
385 input=force_env_section, &
386 particle_set=particle_set, &
388 super_cell=super_cell, &
389 dft_control=dft_control)
391 IF (
PRESENT(calculate_forces)) need_f = calculate_forces
392 apply_restrain = dft_control%qs_control%ddapc_restraint
394 IF (apply_restrain)
THEN
399 extension=
".fitChargeLog")
401 my_id = ddapc_restraint_control%density_type
405 density_fit_section, &
406 density_type=my_id, &
413 density_fit_section, &
414 density_type=my_id, &
416 out_radii=radii, iwc=iw)
420 IF ((my_id ==
do_spin_density) .OR. dft_control%qs_control%et_coupling_calc)
THEN
422 particle_set, qs_env%cp_ddapc_env%AmI, radii, charges, &
423 ddapc_restraint_control, energy_res)
426 particle_set, qs_env%cp_ddapc_env%AmI, radii, charges, &
427 ddapc_restraint_control, energy_res)
432 ddapc_restraint_control, &
441 IF (
ASSOCIATED(dq))
THEN
447 CALL timestop(handle)
448 END SUBROUTINE cp_ddapc_apply_rs
462 SUBROUTINE cp_ddapc_apply_rf(qs_env, rho_tot_gspace, energy, &
463 v_hartree_gspace, calculate_forces, Itype_of_density)
466 REAL(kind=
dp),
INTENT(INOUT) :: energy
468 LOGICAL,
INTENT(IN),
OPTIONAL :: calculate_forces
469 CHARACTER(LEN=*) :: itype_of_density
471 CHARACTER(len=*),
PARAMETER :: routinen =
'cp_ddapc_apply_RF'
473 INTEGER :: handle, iw
474 LOGICAL :: apply_solvation, need_f
475 REAL(kind=
dp) :: e_recpl
476 REAL(kind=
dp),
DIMENSION(:),
POINTER :: charges, radii
477 REAL(kind=
dp),
DIMENSION(:, :, :),
POINTER :: dq
478 TYPE(
cell_type),
POINTER :: cell, super_cell
484 CALL timeset(routinen, handle)
486 IF (
PRESENT(calculate_forces)) need_f = calculate_forces
488 apply_solvation = qs_env%cp_ddapc_ewald%do_solvation
489 IF (apply_solvation)
THEN
491 NULLIFY (force_env_section, particle_set, charges, &
492 radii, dq, cell, super_cell)
495 input=force_env_section, &
496 particle_set=particle_set, &
498 super_cell=super_cell)
503 extension=
".fitChargeLog")
509 density_fit_section, &
513 ext_rho_tot_g=rho_tot_gspace, &
514 itype_of_density=itype_of_density)
518 density_fit_section, &
521 ext_rho_tot_g=rho_tot_gspace, &
522 itype_of_density=itype_of_density)
526 e_recpl = 0.5_dp*dot_product(charges, matmul(qs_env%cp_ddapc_env%Ms, charges))
527 WRITE (iw, fmt=
"(T3,A,T60,F20.10)")
"Solvation Energy: ", e_recpl
530 density_fit_section, &
532 qs_env%cp_ddapc_env%Ms, &
533 qs_env%cp_ddapc_env%AmI, &
545 IF (
ASSOCIATED(dq))
THEN
551 CALL timestop(handle)
552 END SUBROUTINE cp_ddapc_apply_rf
collects all references to literature in CP2K as new algorithms / method are included from literature...
integer, save, public blochl1995
Handles all functions related to the CELL.
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
subroutine, public dbcsr_copy(matrix_b, matrix_a, name, keep_sparsity, keep_imaginary)
...
subroutine, public dbcsr_set(matrix, alpha)
...
Density Derived atomic point charges from a QM calculation (see J. Chem. Phys. Vol....
subroutine, public solvation_ddapc_force(qs_env, solvation_section, particle_set, radii, dq, charges)
Evaluates the electrostatic potential due to a simple solvation model Spherical cavity in a dieletric...
recursive subroutine, public ewald_ddapc_force(qs_env, coeff, apply_qmmm_periodic, factor, multipole_section, cell, particle_set, radii, dq, charges)
Evaluates the Ewald term E2 and E3 energy term for the decoupling/coupling of periodic images.
subroutine, public restraint_functional_force(qs_env, ddapc_restraint_control, dq, charges, n_gauss, particle_set)
computes derivatives for DDAPC restraint
subroutine, public reset_ch_pulay(qs_env)
Evaluation of the pulay forces due to the fitted charge density.
Density Derived atomic point charges from a QM calculation (see Bloechl, J. Chem. Phys....
recursive subroutine, public get_ddapc(qs_env, calc_force, density_fit_section, density_type, qout1, qout2, out_radii, dq_out, ext_rho_tot_g, itype_of_density, iwc)
Computes the Density Derived Atomic Point Charges.
subroutine, public modify_hartree_pot(v_hartree_gspace, density_fit_section, particle_set, m, ami, radii, charges)
Modify the Hartree potential.
subroutine, public restraint_functional_potential(v_hartree_gspace, density_fit_section, particle_set, ami, radii, charges, ddapc_restraint_control, energy_res)
modify hartree potential to handle restraints in DDAPC scheme
Density Derived atomic point charges from a QM calculation (see Bloechl, J. Chem. Phys....
subroutine, public cp_ddapc_apply_cd(qs_env, rho_tot_gspace, energy, v_hartree_gspace, calculate_forces, itype_of_density)
Routine to couple/decouple periodic images with the Bloechl scheme.
subroutine, public qs_ks_ddapc(qs_env, auxbas_pw_pool, rho_tot_gspace, v_hartree_gspace, v_spin_ddapc_rest_r, energy, calculate_forces, ks_matrix, just_energy)
Set of methods using DDAPC charges.
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...
integer function, public cp_print_key_unit_nr(logger, basis_section, print_key_path, extension, middle_name, local, log_filename, ignore_should_output, file_form, file_position, file_action, file_status, do_backup, on_file, is_new_file, mpi_io, fout)
...
subroutine, public cp_print_key_finished_output(unit_nr, logger, basis_section, print_key_path, local, ignore_should_output, on_file, mpi_io)
should be called after you finish working with a unit obtained with cp_print_key_unit_nr,...
Defines the basic variable types.
integer, parameter, public dp
Define the data structure for the particle information.
Manages a pool of grids (to be used for example as tmp objects), but can also be used to instantiate ...
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.
Integrate single or product functions over a potential on a RS grid.
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...
Manages a pool of grids (to be used for example as tmp objects), but can also be used to instantiate ...