42#include "./base/base_uses.f90"
47 LOGICAL,
PRIVATE,
PARAMETER :: debug_this_module = .true.
48 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'cp_ddapc_forces'
75 factor, multipole_section, cell, particle_set, radii, dq, charges)
78 LOGICAL,
INTENT(IN) :: apply_qmmm_periodic
79 REAL(kind=
dp),
INTENT(IN) :: factor
83 REAL(kind=
dp),
DIMENSION(:),
POINTER :: radii
84 REAL(kind=
dp),
DIMENSION(:, :, :),
OPTIONAL, &
86 REAL(kind=
dp),
DIMENSION(:),
OPTIONAL,
POINTER :: charges
88 CHARACTER(len=*),
PARAMETER :: routinen =
'ewald_ddapc_force'
90 INTEGER :: handle, idim, ip1, ip2, iparticle1, &
91 iparticle2, k1, k2, k3, n_rep, r1, r2, &
93 INTEGER,
DIMENSION(3) :: gmax, image_cell, rmax, rmin
95 REAL(kind=
dp) :: alpha, eps,
fac, frac_radius, fs, &
96 galpha, gsq, gsqi, ij_fac, q1t, q2t, &
97 r, r2tmp, rcut, rcut2, t1, t2, tol, &
99 REAL(kind=
dp),
DIMENSION(3) :: drvec, g_index, gvec, ra, rvec, svec
100 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: d_el, m
103 NULLIFY (d_el, m, para_env)
104 CALL timeset(routinen, handle)
106 cpassert(
PRESENT(charges))
107 cpassert(
ASSOCIATED(radii))
108 rcut = min(norm2(cell%hmat(:, 1)), norm2(cell%hmat(:, 2)), norm2(cell%hmat(:, 3)))/2.0_dp
114 analyt = analyt .OR. .NOT. cell%orthorhombic .OR. .NOT.
ASSOCIATED(coeff)
119 eps = min(abs(eps), 0.5_dp)
120 tol = sqrt(abs(log(eps*rcut)))
121 alpha = sqrt(abs(log(eps*rcut*tol)))/rcut
122 galpha = 1.0_dp/(4.0_dp*alpha*alpha)
123 tol1 = sqrt(-log(eps*rcut*(2.0_dp*tol*alpha)**2))
124 IF (cell%orthorhombic)
THEN
126 gmax(idim) = nint(0.25_dp + cell%hmat(idim, idim)*alpha*tol1/
pi)
130 gmax(idim) = ceiling(alpha*tol1*norm2(cell%hmat(:, idim))/
pi)
134 ALLOCATE (d_el(3,
SIZE(particle_set)))
136 fac = 1.e0_dp/cell%deth
138 DO iparticle1 = 1,
SIZE(particle_set)
140 IF (mod(iparticle1, para_env%num_pe) /= para_env%mepos) cycle
141 ip1 = (iparticle1 - 1)*
SIZE(radii)
142 q1t = sum(charges(ip1 + 1:ip1 +
SIZE(radii)))
143 DO iparticle2 = 1, iparticle1
145 IF (iparticle1 == iparticle2) ij_fac = 0.5_dp
147 ip2 = (iparticle2 - 1)*
SIZE(radii)
148 q2t = sum(charges(ip2 + 1:ip2 +
SIZE(radii)))
152 rvec = particle_set(iparticle1)%r - particle_set(iparticle2)%r
153 IF (iparticle1 /= iparticle2)
THEN
155 r2tmp = dot_product(ra, ra)
156 IF (r2tmp <= rcut2)
THEN
159 drvec = ra/r*q1t*q2t*factor
160 t2 = -2.0_dp*alpha*exp(-alpha*alpha*r*r)/(r*
rootpi) - t1/r
161 d_el(1:3, iparticle1) = d_el(1:3, iparticle1) - t2*drvec
162 d_el(1:3, iparticle2) = d_el(1:3, iparticle2) + t2*drvec
165 svec = matmul(cell%h_inv, rvec)
167 frac_radius = rcut*norm2(cell%h_inv(idim, :))
168 rmin(idim) = floor(-svec(idim) - frac_radius)
169 rmax(idim) = ceiling(-svec(idim) + frac_radius)
171 DO r1 = rmin(1), rmax(1)
172 DO r2 = rmin(2), rmax(2)
173 DO r3 = rmin(3), rmax(3)
174 IF ((r1 == 0) .AND. (r2 == 0) .AND. (r3 == 0)) cycle
175 image_cell = [r1, r2, r3]
176 ra = rvec + matmul(cell%hmat, real(image_cell, kind=
dp))
177 r2tmp = dot_product(ra, ra)
178 IF (r2tmp <= rcut2)
THEN
181 drvec = ra/r*q1t*q2t*factor*ij_fac
182 t2 = -2.0_dp*alpha*exp(-alpha*alpha*r*r)/(r*
rootpi) - t1/r
183 d_el(1, iparticle1) = d_el(1, iparticle1) - t2*drvec(1)
184 d_el(2, iparticle1) = d_el(2, iparticle1) - t2*drvec(2)
185 d_el(3, iparticle1) = d_el(3, iparticle1) - t2*drvec(3)
186 d_el(1, iparticle2) = d_el(1, iparticle2) + t2*drvec(1)
187 d_el(2, iparticle2) = d_el(2, iparticle2) + t2*drvec(2)
188 d_el(3, iparticle2) = d_el(3, iparticle2) + t2*drvec(3)
198 DO k2 = -gmax(2), gmax(2)
199 DO k3 = -gmax(3), gmax(3)
200 IF (k1 == 0 .AND. k2 == 0 .AND. k3 == 0) cycle
201 fs = 2.0_dp;
IF (k1 == 0) fs = 1.0_dp
202 g_index = [real(k1, kind=
dp), real(k2, kind=
dp), real(k3, kind=
dp)]
203 gvec =
twopi*matmul(transpose(cell%h_inv), g_index)
204 gsq = dot_product(gvec, gvec)
206 t1 =
fac*gsqi*exp(-galpha*gsq)
207 t2 = -sin(dot_product(gvec, rvec))*t1*q1t*q2t*factor*
fourpi
208 d_el(1:3, iparticle1) = d_el(1:3, iparticle1) - t2*gvec
209 d_el(1:3, iparticle2) = d_el(1:3, iparticle2) + t2*gvec
215 d_el(1:3, iparticle1) = d_el(1:3, iparticle1) - gvec
216 d_el(1:3, iparticle2) = d_el(1:3, iparticle2) + gvec
218 IF (iparticle1 /= iparticle2)
THEN
220 r = sqrt(dot_product(ra, ra))
221 t2 = -1.0_dp/(r*r)*factor
223 d_el(1:3, iparticle1) = d_el(1:3, iparticle1) + t2*drvec
224 d_el(1:3, iparticle2) = d_el(1:3, iparticle2) - t2*drvec
229 CALL para_env%sum(d_el)
230 m => qs_env%cp_ddapc_env%Md
231 IF (apply_qmmm_periodic) m => qs_env%cp_ddapc_env%Mr
232 CALL cp_decpl_ddapc_forces(qs_env, m, charges, dq, d_el, particle_set)
234 CALL timestop(handle)
249 SUBROUTINE cp_decpl_ddapc_forces(qs_env, M, charges, dq, d_el, particle_set)
251 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: m
252 REAL(kind=
dp),
DIMENSION(:),
POINTER :: charges
253 REAL(kind=
dp),
DIMENSION(:, :, :),
POINTER :: dq
254 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: d_el
257 CHARACTER(len=*),
PARAMETER :: routinen =
'cp_decpl_ddapc_forces'
259 INTEGER :: handle, i, iatom, ikind, j, k, natom
260 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: atom_of_kind, kind_of
261 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: uv
262 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: chf
268 CALL timeset(routinen, handle)
269 natom =
SIZE(particle_set)
271 atomic_kind_set=atomic_kind_set, &
274 ALLOCATE (chf(3, natom))
276 atom_of_kind=atom_of_kind, &
279 ALLOCATE (uv(
SIZE(m, 1)))
280 uv(:) = matmul(m, charges)
283 chf(j, k) = dot_product(uv, dq(:, k, j))
287 CALL para_env%sum(chf)
289 ikind = kind_of(iatom)
290 i = atom_of_kind(iatom)
291 force(ikind)%ch_pulay(1:3, i) = force(ikind)%ch_pulay(1:3, i) + chf(1:3, iatom) + d_el(1:3, iatom)
295 CALL timestop(handle)
296 END SUBROUTINE cp_decpl_ddapc_forces
308 CHARACTER(len=*),
PARAMETER :: routinen =
'reset_ch_pulay'
310 INTEGER :: handle, ind
313 CALL timeset(routinen, handle)
316 DO ind = 1,
SIZE(force)
317 force(ind)%ch_pulay = 0.0_dp
319 CALL timestop(handle)
339 INTEGER,
INTENT(in) :: n_gauss
340 REAL(kind=
dp),
DIMENSION(:) :: uv
341 REAL(kind=
dp),
DIMENSION(:),
POINTER :: charges
342 REAL(kind=
dp),
INTENT(INOUT) :: energy_res
345 REAL(kind=
dp) :: de, order_p
350 DO i = 1, ddapc_restraint_control%natoms
351 ind = (ddapc_restraint_control%atoms(i) - 1)*n_gauss
352 order_p = order_p + ddapc_restraint_control%coeff(i)*sum(charges(ind + 1:ind + n_gauss))
354 ddapc_restraint_control%ddapc_order_p = order_p
356 SELECT CASE (ddapc_restraint_control%functional_form)
359 energy_res = ddapc_restraint_control%strength*(order_p - ddapc_restraint_control%target)**2.0_dp
362 de = 2.0_dp*ddapc_restraint_control%strength*(order_p - ddapc_restraint_control%target)
363 DO i = 1, ddapc_restraint_control%natoms
364 ind = (ddapc_restraint_control%atoms(i) - 1)*n_gauss
365 uv(ind + 1:ind + n_gauss) = de*ddapc_restraint_control%coeff(i)
368 energy_res = ddapc_restraint_control%strength*(order_p - ddapc_restraint_control%target)
371 DO i = 1, ddapc_restraint_control%natoms
372 ind = (ddapc_restraint_control%atoms(i) - 1)*n_gauss
373 uv(ind + 1:ind + n_gauss) = ddapc_restraint_control%strength*ddapc_restraint_control%coeff(i)
397 n_gauss, particle_set)
401 REAL(kind=
dp),
DIMENSION(:, :, :),
POINTER :: dq
402 REAL(kind=
dp),
DIMENSION(:),
POINTER :: charges
403 INTEGER,
INTENT(in) :: n_gauss
406 CHARACTER(len=*),
PARAMETER :: routinen =
'restraint_functional_force'
408 INTEGER :: handle, i, iatom, ikind, j, k, natom
409 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: atom_of_kind, kind_of
411 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: uv
412 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: chf
418 CALL timeset(routinen, handle)
419 natom =
SIZE(particle_set)
421 atomic_kind_set=atomic_kind_set, &
424 ALLOCATE (chf(3, natom))
426 atom_of_kind=atom_of_kind, &
429 ALLOCATE (uv(
SIZE(dq, 1)))
435 chf(j, k) = dot_product(uv, dq(:, k, j))
439 CALL para_env%sum(chf)
441 ikind = kind_of(iatom)
442 i = atom_of_kind(iatom)
443 force(ikind)%ch_pulay(1:3, i) = force(ikind)%ch_pulay(1:3, i) + chf(1:3, iatom)
447 CALL timestop(handle)
469 REAL(kind=
dp),
DIMENSION(:),
POINTER :: radii
470 REAL(kind=
dp),
DIMENSION(:, :, :),
OPTIONAL, &
472 REAL(kind=
dp),
DIMENSION(:),
OPTIONAL,
POINTER :: charges
474 INTEGER :: i, ip1, ip2, iparticle1, iparticle2, l, &
475 lmax, n_rep1, n_rep2, weight
476 INTEGER,
DIMENSION(:),
POINTER ::
list
477 LOGICAL :: fixed_center
478 REAL(kind=
dp) :: center(3), dcos1(3), dcos2(3), dpos1(3), dpos2(3), eps_in, eps_out, &
479 factor1(3), factor2(3), lr, mass, mycos, pos1, pos1i, pos2, pos2i, ptcos, q1t, q2t, &
480 r1(3), r1s, r2(3), r2s, rs, rvec(3)
481 REAL(kind=
dp),
DIMENSION(:),
POINTER :: pos, r0
482 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: d_el, locp, m
484 fixed_center = .false.
491 IF (n_rep1 /= 0)
THEN
497 IF (n_rep2 /= 0)
THEN
500 ALLOCATE (r0(
SIZE(
list)))
505 r0 = r0 + particle_set(
list(i))%r
507 r0 = r0/real(
SIZE(
list), kind=
dp)
512 r0 = r0 + particle_set(
list(i))%r*particle_set(
list(i))%atomic_kind%mass
513 mass = mass + particle_set(
list(i))%atomic_kind%mass
521 cpassert(n_rep1 /= 0 .OR. n_rep2 /= 0)
523 ALLOCATE (locp(0:lmax,
SIZE(particle_set)))
524 ALLOCATE (pos(
SIZE(particle_set)))
525 ALLOCATE (d_el(3,
SIZE(particle_set)))
528 DO i = 1,
SIZE(particle_set)
529 rvec = particle_set(i)%r - center
530 r2s = dot_product(rvec, rvec)
533 IF (r1s /= 0.0_dp)
THEN
535 locp(l, i) = (r1s**l*real(l + 1, kind=
dp)*(eps_in - eps_out))/ &
536 (rs**(2*l + 1)*eps_in*(real(l, kind=
dp)*eps_in + real(l + 1, kind=
dp)*eps_out))
542 DO iparticle1 = 1,
SIZE(particle_set)
543 ip1 = (iparticle1 - 1)*
SIZE(radii)
544 q1t = sum(charges(ip1 + 1:ip1 +
SIZE(radii)))
545 DO iparticle2 = 1, iparticle1
546 ip2 = (iparticle2 - 1)*
SIZE(radii)
547 q2t = sum(charges(ip2 + 1:ip2 +
SIZE(radii)))
549 r1 = particle_set(iparticle1)%r - center
550 r2 = particle_set(iparticle2)%r - center
551 pos1 = pos(iparticle1)
552 pos2 = pos(iparticle2)
555 IF (pos1*pos2 /= 0.0_dp)
THEN
560 ptcos = dot_product(r1, r2)
561 mycos = ptcos/(pos1*pos2)
562 IF (abs(mycos) > 1.0_dp) mycos = sign(1.0_dp, mycos)
563 dcos1 = (r2*(pos1*pos2) - pos2*dpos1*ptcos)/(pos1*pos2)**2
564 dcos2 = (r1*(pos1*pos2) - pos1*dpos2*ptcos)/(pos1*pos2)**2
567 lr = real(l, kind=
dp)
568 factor1 = factor1 + lr*locp(l, iparticle2)*pos1**(l - 1)*
legendre(mycos, l, 0)*dpos1 &
569 + locp(l, iparticle2)*pos1**l*
dlegendre(mycos, l, 0)*dcos1
570 factor2 = factor2 + lr*locp(l, iparticle1)*pos2**(l - 1)*
legendre(mycos, l, 0)*dpos2 &
571 + locp(l, iparticle1)*pos2**l*
dlegendre(mycos, l, 0)*dcos2
574 factor1 = factor1*q1t*q2t
575 factor2 = factor2*q1t*q2t
576 d_el(1:3, iparticle1) = d_el(1:3, iparticle1) + 0.5_dp*factor1
577 d_el(1:3, iparticle2) = d_el(1:3, iparticle2) + 0.5_dp*factor2
582 m => qs_env%cp_ddapc_env%Ms
583 CALL cp_decpl_ddapc_forces(qs_env, m, charges, dq, d_el, particle_set)
Define the atomic kind types and their sub types.
subroutine, public get_atomic_kind_set(atomic_kind_set, atom_of_kind, kind_of, natom_of_kind, maxatom, natom, nshell, fist_potential_present, shell_present, shell_adiabatic, shell_check_distance, damping_present)
Get attributes of an atomic kind set.
Handles all functions related to the CELL.
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
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 evaluate_restraint_functional(ddapc_restraint_control, n_gauss, uv, charges, energy_res)
computes energy and derivatives given a set of charges
subroutine, public reset_ch_pulay(qs_env)
Evaluation of the pulay forces due to the fitted charge density.
Defines the basic variable types.
integer, parameter, public dp
An array-based list which grows on demand. When the internal array is full, a new array of twice the ...
Definition of mathematical constants and functions.
real(kind=dp), parameter, public pi
real(kind=dp), parameter, public rootpi
real(kind=dp), parameter, public fourpi
real(kind=dp), parameter, public twopi
real(kind=dp), dimension(0:maxfac), parameter, public fac
Interface to the message passing library MPI.
Define the data structure for the particle information.
different utils that are useful to manipulate splines on the regular grid of a pw
real(kind=dp) function, dimension(3), public eval_d_interp_spl3_pbc(vec, pw)
Evaluates the derivatives of the PBC interpolated Spline (pw) function on the generic input vector (v...
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, 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.
Calculate spherical harmonics.
real(kind=dp) function, public legendre(x, l, m)
...
real(kind=dp) function, public dlegendre(x, l, m)
...
Provides all information about an atomic kind.
Type defining parameters related to the simulation cell.
stores all the informations relevant to an mpi environment