(git:ed6f26b)
Loading...
Searching...
No Matches
qs_gcp_method.F
Go to the documentation of this file.
1!--------------------------------------------------------------------------------------------------!
2! CP2K: A general program to perform molecular dynamics simulations !
3! Copyright 2000-2025 CP2K developers group <https://cp2k.org> !
4! !
5! SPDX-License-Identifier: GPL-2.0-or-later !
6!--------------------------------------------------------------------------------------------------!
7
8! **************************************************************************************************
9!> \brief Calculation of gCP pair potentials
10!> \author JGH
11! **************************************************************************************************
13 USE ai_overlap, ONLY: overlap_ab
18 USE cell_types, ONLY: cell_type
20 USE kinds, ONLY: dp
23 USE physcon, ONLY: kcalmol
27 USE qs_gcp_types, ONLY: qs_gcp_type
36 USE virial_types, ONLY: virial_type
37#include "./base/base_uses.f90"
38
39 IMPLICIT NONE
40
41 PRIVATE
42
43 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_gcp_method'
44
45 PUBLIC :: calculate_gcp_pairpot
46
47! **************************************************************************************************
48
49CONTAINS
50
51! **************************************************************************************************
52!> \brief ...
53!> \param qs_env ...
54!> \param gcp_env ...
55!> \param energy ...
56!> \param calculate_forces ...
57!> \param ategcp ...
58!> \note
59!> \note energy_correction_type: also add gcp_env and egcp to the type
60!> \note
61! **************************************************************************************************
62 SUBROUTINE calculate_gcp_pairpot(qs_env, gcp_env, energy, calculate_forces, ategcp)
63
64 TYPE(qs_environment_type), POINTER :: qs_env
65 TYPE(qs_gcp_type), POINTER :: gcp_env
66 REAL(kind=dp), INTENT(OUT) :: energy
67 LOGICAL, INTENT(IN) :: calculate_forces
68 REAL(kind=dp), DIMENSION(:), OPTIONAL :: ategcp
69
70 CHARACTER(LEN=*), PARAMETER :: routinen = 'calculate_gcp_pairpot'
71
72 INTEGER :: atom_a, atom_b, handle, i, iatom, ikind, &
73 jatom, jkind, mepos, natom, nkind, &
74 nsto, unit_nr
75 INTEGER, ALLOCATABLE, DIMENSION(:) :: atom_of_kind, kind_of, ngcpat
76 LOGICAL :: atenergy, atex, use_virial, verbose
77 REAL(kind=dp) :: eama, eamb, egcp, expab, fac, fda, fdb, &
78 gnorm, nvirta, nvirtb, rcc, sint, sqa, &
79 sqb
80 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: egcpat
81 REAL(kind=dp), DIMENSION(3) :: dsint, fdij, rij
82 REAL(kind=dp), DIMENSION(3, 3) :: dvirial
83 REAL(kind=dp), DIMENSION(6) :: cla, clb, rcut, zeta, zetb
84 REAL(kind=dp), DIMENSION(6, 6) :: sab
85 REAL(kind=dp), DIMENSION(6, 6, 3) :: dab
86 REAL(kind=dp), DIMENSION(:), POINTER :: atener
87 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
88 TYPE(atprop_type), POINTER :: atprop
89 TYPE(cell_type), POINTER :: cell
90 TYPE(mp_para_env_type), POINTER :: para_env
92 DIMENSION(:), POINTER :: nl_iterator
93 TYPE(neighbor_list_set_p_type), DIMENSION(:), &
94 POINTER :: sab_gcp
95 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
96 TYPE(qs_force_type), DIMENSION(:), POINTER :: force
97 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
98 TYPE(virial_type), POINTER :: virial
99
100 energy = 0._dp
101 IF (.NOT. gcp_env%do_gcp) RETURN
102
103 CALL timeset(routinen, handle)
104
105 NULLIFY (atomic_kind_set, qs_kind_set, particle_set, sab_gcp)
106
107 CALL get_qs_env(qs_env=qs_env, atomic_kind_set=atomic_kind_set, qs_kind_set=qs_kind_set, &
108 cell=cell, virial=virial, para_env=para_env, atprop=atprop)
109 nkind = SIZE(atomic_kind_set)
110 NULLIFY (particle_set)
111 CALL get_qs_env(qs_env=qs_env, particle_set=particle_set)
112 natom = SIZE(particle_set)
113
114 verbose = gcp_env%verbose
115 IF (verbose) THEN
117 ELSE
118 unit_nr = -1
119 END IF
120 ! atomic energy and stress arrays
121 atenergy = atprop%energy
122 IF (atenergy) THEN
123 CALL atprop_array_init(atprop%ategcp, natom)
124 atener => atprop%ategcp
125 END IF
126 ! external atomic energy
127 atex = .false.
128 IF (PRESENT(ategcp)) atex = .true.
129
130 IF (unit_nr > 0) THEN
131 WRITE (unit_nr, *)
132 WRITE (unit_nr, *) " Pair potential geometrical counterpoise (gCP) calculation"
133 WRITE (unit_nr, *)
134 WRITE (unit_nr, "(T15,A,T74,F7.4)") " Gloabal Parameters: sigma = ", gcp_env%sigma, &
135 " alpha = ", gcp_env%alpha, &
136 " beta = ", gcp_env%beta, &
137 " eta = ", gcp_env%eta
138 WRITE (unit_nr, *)
139 WRITE (unit_nr, "(T31,4(A5,10X))") " kind", "nvirt", "Emiss", " asto"
140 DO ikind = 1, nkind
141 WRITE (unit_nr, "(T31,i5,F15.1,F15.4,F15.4)") ikind, gcp_env%gcp_kind(ikind)%nbvirt, &
142 gcp_env%gcp_kind(ikind)%eamiss, gcp_env%gcp_kind(ikind)%asto
143 END DO
144 WRITE (unit_nr, *)
145 END IF
146
147 IF (calculate_forces) THEN
148 NULLIFY (force)
149 CALL get_qs_env(qs_env=qs_env, force=force)
150 ALLOCATE (atom_of_kind(natom), kind_of(natom))
151 CALL get_atomic_kind_set(atomic_kind_set, atom_of_kind=atom_of_kind, kind_of=kind_of)
152 use_virial = virial%pv_availability .AND. (.NOT. virial%pv_numer)
153 IF (use_virial) dvirial = virial%pv_virial
154 END IF
155
156 ! include all integrals in the list
157 rcut = 1.e6_dp
158
159 egcp = 0.0_dp
160 IF (verbose) THEN
161 ALLOCATE (egcpat(natom), ngcpat(natom))
162 egcpat = 0.0_dp
163 ngcpat = 0
164 END IF
165
166 nsto = 6
167 DO ikind = 1, nkind
168 cpassert(nsto == SIZE(gcp_env%gcp_kind(jkind)%al))
169 END DO
170
171 sab_gcp => gcp_env%sab_gcp
172 CALL neighbor_list_iterator_create(nl_iterator, sab_gcp)
173 DO WHILE (neighbor_list_iterate(nl_iterator) == 0)
174
175 CALL get_iterator_info(nl_iterator, mepos=mepos, ikind=ikind, jkind=jkind, iatom=iatom, jatom=jatom, r=rij)
176
177 rcc = sqrt(rij(1)*rij(1) + rij(2)*rij(2) + rij(3)*rij(3))
178 IF (rcc > 1.e-6_dp) THEN
179 fac = 1._dp
180 IF (iatom == jatom) fac = 0.5_dp
181 nvirta = gcp_env%gcp_kind(ikind)%nbvirt
182 nvirtb = gcp_env%gcp_kind(jkind)%nbvirt
183 eama = gcp_env%gcp_kind(ikind)%eamiss
184 eamb = gcp_env%gcp_kind(jkind)%eamiss
185 expab = exp(-gcp_env%alpha*rcc**gcp_env%beta)
186 zeta(1:nsto) = gcp_env%gcp_kind(ikind)%al(1:nsto)
187 zetb(1:nsto) = gcp_env%gcp_kind(jkind)%al(1:nsto)
188 cla(1:nsto) = gcp_env%gcp_kind(ikind)%cl(1:nsto)
189 clb(1:nsto) = gcp_env%gcp_kind(jkind)%cl(1:nsto)
190 IF (calculate_forces) THEN
191 CALL overlap_ab(0, 0, nsto, rcut, zeta, 0, 0, nsto, rcut, zetb, rij, sab, dab)
192 DO i = 1, 3
193 dsint(i) = sum(cla*matmul(dab(:, :, i), clb))
194 END DO
195 ELSE
196 CALL overlap_ab(0, 0, nsto, rcut, zeta, 0, 0, nsto, rcut, zetb, rij, sab)
197 END IF
198 sint = sum(cla*matmul(sab, clb))
199 IF (sint < 1.e-16_dp) cycle
200 sqa = sqrt(sint*nvirta)
201 sqb = sqrt(sint*nvirtb)
202 IF (sqb > 1.e-12_dp) THEN
203 fda = gcp_env%sigma*eama*expab/sqb
204 ELSE
205 fda = 0.0_dp
206 END IF
207 IF (sqa > 1.e-12_dp) THEN
208 fdb = gcp_env%sigma*eamb*expab/sqa
209 ELSE
210 fdb = 0.0_dp
211 END IF
212 egcp = egcp + fac*(fda + fdb)
213 IF (verbose) THEN
214 egcpat(iatom) = egcpat(iatom) + fac*fda
215 egcpat(jatom) = egcpat(jatom) + fac*fdb
216 ngcpat(iatom) = ngcpat(iatom) + 1
217 ngcpat(jatom) = ngcpat(jatom) + 1
218 END IF
219 IF (calculate_forces) THEN
220 fdij = -fac*(fda + fdb)*(gcp_env%alpha*gcp_env%beta*rcc**(gcp_env%beta - 1.0_dp)*rij(1:3)/rcc)
221 IF (sqa > 1.e-12_dp) THEN
222 fdij = fdij + 0.25_dp*fac*fdb/(sqa*sqa)*dsint(1:3)
223 END IF
224 IF (sqb > 1.e-12_dp) THEN
225 fdij = fdij + 0.25_dp*fac*fda/(sqb*sqb)*dsint(1:3)
226 END IF
227 atom_a = atom_of_kind(iatom)
228 atom_b = atom_of_kind(jatom)
229 force(ikind)%gcp(:, atom_a) = force(ikind)%gcp(:, atom_a) - fdij(:)
230 force(jkind)%gcp(:, atom_b) = force(jkind)%gcp(:, atom_b) + fdij(:)
231 IF (use_virial) THEN
232 CALL virial_pair_force(virial%pv_virial, -1._dp, fdij, rij)
233 END IF
234 END IF
235 IF (atenergy) THEN
236 atener(iatom) = atener(iatom) + fda*fac
237 atener(jatom) = atener(jatom) + fdb*fac
238 END IF
239 IF (atex) THEN
240 ategcp(iatom) = ategcp(iatom) + fda*fac
241 ategcp(jatom) = ategcp(jatom) + fdb*fac
242 END IF
243 END IF
244 END DO
245
246 CALL neighbor_list_iterator_release(nl_iterator)
247
248 ! set gCP energy
249 CALL para_env%sum(egcp)
250 energy = egcp
251 IF (verbose) THEN
252 CALL para_env%sum(egcpat)
253 CALL para_env%sum(ngcpat)
254 END IF
255
256 IF (unit_nr > 0) THEN
257 WRITE (unit_nr, "(T15,A,T61,F20.10)") " Total gCP energy [au] :", egcp
258 WRITE (unit_nr, "(T15,A,T61,F20.10)") " Total gCP energy [kcal] :", egcp*kcalmol
259 WRITE (unit_nr, *)
260 WRITE (unit_nr, "(T19,A)") " gCP atomic energy contributions"
261 WRITE (unit_nr, "(T19,A,T60,A20)") " # sites", " BSSE [kcal/mol]"
262 DO i = 1, natom
263 WRITE (unit_nr, "(12X,I8,10X,I8,T61,F20.10)") i, ngcpat(i), egcpat(i)*kcalmol
264 END DO
265 END IF
266 IF (calculate_forces) THEN
267 IF (unit_nr > 0) THEN
268 WRITE (unit_nr, *) " gCP Forces "
269 WRITE (unit_nr, *) " Atom Kind Forces "
270 END IF
271 gnorm = 0._dp
272 DO iatom = 1, natom
273 ikind = kind_of(iatom)
274 atom_a = atom_of_kind(iatom)
275 fdij(1:3) = force(ikind)%gcp(:, atom_a)
276 CALL para_env%sum(fdij)
277 gnorm = gnorm + sum(abs(fdij))
278 IF (unit_nr > 0) WRITE (unit_nr, "(i5,i7,3F20.14)") iatom, ikind, fdij
279 END DO
280 IF (unit_nr > 0) THEN
281 WRITE (unit_nr, *)
282 WRITE (unit_nr, *) " |G| = ", gnorm
283 WRITE (unit_nr, *)
284 END IF
285 IF (use_virial) THEN
286 dvirial = virial%pv_virial - dvirial
287 CALL para_env%sum(dvirial)
288 IF (unit_nr > 0) THEN
289 WRITE (unit_nr, *) " Stress Tensor (gCP)"
290 WRITE (unit_nr, "(3G20.12)") dvirial
291 WRITE (unit_nr, *) " Tr(P)/3 : ", (dvirial(1, 1) + dvirial(2, 2) + dvirial(3, 3))/3._dp
292 WRITE (unit_nr, *)
293 END IF
294 END IF
295 END IF
296 IF (verbose) THEN
297 DEALLOCATE (egcpat, ngcpat)
298 END IF
299
300 CALL timestop(handle)
301
302 END SUBROUTINE calculate_gcp_pairpot
303
304! **************************************************************************************************
305
306END MODULE qs_gcp_method
static GRID_HOST_DEVICE double fac(const int i)
Factorial function, e.g. fac(5) = 5! = 120.
Definition grid_common.h:51
Calculation of the overlap integrals over Cartesian Gaussian-type functions.
Definition ai_overlap.F:18
subroutine, public overlap_ab(la_max, la_min, npgfa, rpgfa, zeta, lb_max, lb_min, npgfb, rpgfb, zetb, rab, sab, dab, ddab)
Calculation of the two-center overlap integrals [a|b] over Cartesian Gaussian-type functions....
Definition ai_overlap.F:680
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.
Holds information on atomic properties.
subroutine, public atprop_array_init(atarray, natom)
...
Handles all functions related to the CELL.
Definition cell_types.F:15
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...
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
Interface to the message passing library MPI.
Define the data structure for the particle information.
Definition of physical constants:
Definition physcon.F:68
real(kind=dp), parameter, public kcalmol
Definition physcon.F:171
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.
Calculation of gCP pair potentials.
subroutine, public calculate_gcp_pairpot(qs_env, gcp_env, energy, calculate_forces, ategcp)
...
Definition of gCP types for DFT calculations.
Define the quickstep kind type and their sub types.
Define the neighbor list data types and the corresponding functionality.
subroutine, public neighbor_list_iterator_create(iterator_set, nl, search, nthread)
Neighbor list iterator functions.
subroutine, public neighbor_list_iterator_release(iterator_set)
...
integer function, public neighbor_list_iterate(iterator_set, mepos)
...
subroutine, public get_iterator_info(iterator_set, mepos, ikind, jkind, nkind, ilist, nlist, inode, nnode, iatom, jatom, r, cell)
...
pure subroutine, public virial_pair_force(pv_virial, f0, force, rab)
Computes the contribution to the stress tensor from two-body pair-wise forces.
Provides all information about an atomic kind.
type for the atomic properties
Type defining parameters related to the simulation cell.
Definition cell_types.F:55
stores all the informations relevant to an mpi environment
Provides all information about a quickstep kind.