(git:b77b4be)
Loading...
Searching...
No Matches
qs_dispersion_d2.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 D2 dispersion
10!> \author JGH
11! **************************************************************************************************
13
19 USE cell_types, ONLY: cell_type
20 USE kinds, ONLY: dp
21 USE physcon, ONLY: bohr,&
22 kjmol
28 USE qs_kind_types, ONLY: get_qs_kind,&
37 USE virial_types, ONLY: virial_type
38#include "./base/base_uses.f90"
39
40 IMPLICIT NONE
41
42 PRIVATE
43
44 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_dispersion_d2'
45
47
48! **************************************************************************************************
49
50CONTAINS
51
52! **************************************************************************************************
53!> \brief ...
54!> \param qs_env ...
55!> \param dispersion_env ...
56!> \param evdw ...
57!> \param calculate_forces ...
58!> \param atevdw ...
59! **************************************************************************************************
60 SUBROUTINE calculate_dispersion_d2_pairpot(qs_env, dispersion_env, evdw, calculate_forces, atevdw)
61
62 TYPE(qs_environment_type), POINTER :: qs_env
63 TYPE(qs_dispersion_type), POINTER :: dispersion_env
64 REAL(kind=dp), INTENT(OUT) :: evdw
65 LOGICAL, INTENT(IN) :: calculate_forces
66 REAL(kind=dp), DIMENSION(:), OPTIONAL :: atevdw
67
68 CHARACTER(LEN=*), PARAMETER :: routinen = 'calculate_dispersion_d2_pairpot'
69
70 INTEGER :: atom_a, atom_b, handle, iatom, ikind, &
71 jatom, jkind, mepos, natom, nkind, &
72 num_pe, za, zb
73 INTEGER, ALLOCATABLE, DIMENSION(:) :: atom_of_kind, atomnumber, kind_of
74 LOGICAL :: atenergy, atex, floating_a, ghost_a, &
75 use_virial
76 LOGICAL, ALLOCATABLE, DIMENSION(:) :: dodisp, floating, ghost
77 REAL(kind=dp) :: c6, dd, devdw, dfdmp, dr, er, fac, fdmp, &
78 rcc, rcut, s6, xp
79 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: c6d2, radd2
80 REAL(kind=dp), DIMENSION(3) :: fdij, rij
81 REAL(kind=dp), DIMENSION(3, 3) :: pv_virial_thread
82 REAL(kind=dp), DIMENSION(:), POINTER :: atener
83 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
84 TYPE(atprop_type), POINTER :: atprop
85 TYPE(cell_type), POINTER :: cell
87 DIMENSION(:), POINTER :: nl_iterator
88 TYPE(neighbor_list_set_p_type), DIMENSION(:), &
89 POINTER :: sab_vdw
90 TYPE(qs_atom_dispersion_type), POINTER :: disp_a
91 TYPE(qs_force_type), DIMENSION(:), POINTER :: force
92 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
93 TYPE(virial_type), POINTER :: virial
94
95 CALL timeset(routinen, handle)
96
97 evdw = 0._dp
98
99 NULLIFY (atomic_kind_set, qs_kind_set, sab_vdw)
100
101 CALL get_qs_env(qs_env=qs_env, nkind=nkind, natom=natom, atomic_kind_set=atomic_kind_set, &
102 qs_kind_set=qs_kind_set, cell=cell, virial=virial, atprop=atprop)
103
104 ! atomic energy and stress arrays
105 atenergy = atprop%energy
106 IF (atenergy) THEN
107 CALL atprop_array_init(atprop%atevdw, natom)
108 atener => atprop%atevdw
109 END IF
110 ! external atomic energy
111 atex = .false.
112 IF (PRESENT(atevdw)) THEN
113 atex = .true.
114 END IF
115
116 NULLIFY (force)
117 CALL get_qs_env(qs_env=qs_env, force=force)
118 CALL get_atomic_kind_set(atomic_kind_set, atom_of_kind=atom_of_kind, kind_of=kind_of)
119 use_virial = virial%pv_availability .AND. (.NOT. virial%pv_numer)
120 pv_virial_thread(:, :) = 0._dp
121
122 ALLOCATE (dodisp(nkind), ghost(nkind), floating(nkind), atomnumber(nkind), c6d2(nkind), radd2(nkind))
123 DO ikind = 1, nkind
124 CALL get_atomic_kind(atomic_kind_set(ikind), z=za)
125 CALL get_qs_kind(qs_kind_set(ikind), dispersion=disp_a, ghost=ghost_a, floating=floating_a)
126 dodisp(ikind) = disp_a%defined
127 ghost(ikind) = ghost_a
128 floating(ikind) = floating_a
129 atomnumber(ikind) = za
130 c6d2(ikind) = disp_a%c6
131 radd2(ikind) = disp_a%vdw_radii
132 END DO
133
134 rcut = 2._dp*dispersion_env%rc_disp
135 s6 = dispersion_env%scaling
136 dd = dispersion_env%exp_pre
137
138 sab_vdw => dispersion_env%sab_vdw
139 num_pe = 1
140 CALL neighbor_list_iterator_create(nl_iterator, sab_vdw, nthread=num_pe)
141
142 mepos = 0
143 DO WHILE (neighbor_list_iterate(nl_iterator, mepos=mepos) == 0)
144 CALL get_iterator_info(nl_iterator, mepos=mepos, ikind=ikind, jkind=jkind, iatom=iatom, jatom=jatom, r=rij)
145
146 IF (ghost(ikind) .OR. ghost(jkind) .OR. floating(ikind) .OR. floating(jkind)) cycle
147
148 IF (.NOT. (dodisp(ikind) .AND. dodisp(jkind))) cycle
149
150 za = atomnumber(ikind)
151 zb = atomnumber(jkind)
152 ! vdW potential
153 dr = sqrt(sum(rij(:)**2))
154 IF (dr <= rcut) THEN
155 fac = 1._dp
156 IF (iatom == jatom) fac = 0.5_dp
157 IF (dr > 0.001_dp) THEN
158 c6 = sqrt(c6d2(ikind)*c6d2(jkind))
159 rcc = radd2(ikind) + radd2(jkind)
160 er = exp(-dd*(dr/rcc - 1._dp))
161 fdmp = 1._dp/(1._dp + er)
162 xp = s6*c6/dr**6
163 evdw = evdw - xp*fdmp*fac
164 IF (calculate_forces) THEN
165 dfdmp = dd/rcc*er*fdmp*fdmp
166 devdw = -xp*(-6._dp*fdmp/dr + dfdmp)
167 fdij(:) = devdw*rij(:)/dr*fac
168 atom_a = atom_of_kind(iatom)
169 atom_b = atom_of_kind(jatom)
170 force(ikind)%dispersion(:, atom_a) = force(ikind)%dispersion(:, atom_a) - fdij(:)
171 force(jkind)%dispersion(:, atom_b) = force(jkind)%dispersion(:, atom_b) + fdij(:)
172 IF (use_virial) THEN
173 CALL virial_pair_force(pv_virial_thread, -1._dp, fdij, rij)
174 END IF
175 END IF
176 IF (atenergy) THEN
177 atener(iatom) = atener(iatom) - 0.5_dp*xp*fdmp*fac
178 atener(jatom) = atener(jatom) - 0.5_dp*xp*fdmp*fac
179 END IF
180 IF (atex) THEN
181 atevdw(iatom) = atevdw(iatom) - 0.5_dp*xp*fdmp*fac
182 atevdw(jatom) = atevdw(jatom) - 0.5_dp*xp*fdmp*fac
183 END IF
184 END IF
185 END IF
186
187 END DO
188
189 virial%pv_virial = virial%pv_virial + pv_virial_thread
190
191 CALL neighbor_list_iterator_release(nl_iterator)
192
193 DEALLOCATE (dodisp, ghost, floating, atomnumber, radd2, c6d2)
194
195 CALL timestop(handle)
196
198
199! **************************************************************************************************
200!> \brief ...
201!> \param z ...
202!> \param c6 ...
203!> \param r ...
204!> \param found ...
205! **************************************************************************************************
206 SUBROUTINE dftd2_param(z, c6, r, found)
207
208 INTEGER, INTENT(in) :: z
209 REAL(kind=dp), INTENT(inout) :: c6, r
210 LOGICAL, INTENT(inout) :: found
211
212 REAL(kind=dp), DIMENSION(54), PARAMETER :: c6val = (/0.14_dp, 0.08_dp, 1.61_dp, 1.61_dp, &
213 3.13_dp, 1.75_dp, 1.23_dp, 0.70_dp, 0.75_dp, 0.63_dp, 5.71_dp, 5.71_dp, 10.79_dp, 9.23_dp,&
214 7.84_dp, 5.57_dp, 5.07_dp, 4.61_dp, 10.80_dp, 10.80_dp, 10.80_dp, 10.80_dp, 10.80_dp, &
215 10.80_dp, 10.80_dp, 10.80_dp, 10.80_dp, 10.80_dp, 10.80_dp, 10.80_dp, 16.99_dp, 17.10_dp, &
216 16.37_dp, 12.64_dp, 12.47_dp, 12.01_dp, 24.67_dp, 24.67_dp, 24.67_dp, 24.67_dp, 24.67_dp, &
217 24.67_dp, 24.67_dp, 24.67_dp, 24.67_dp, 24.67_dp, 24.67_dp, 24.67_dp, 37.32_dp, 38.71_dp, &
218 38.44_dp, 31.74_dp, 31.50_dp, 29.99_dp/)
219 REAL(kind=dp), DIMENSION(54), PARAMETER :: rval = (/1.001_dp, 1.012_dp, 0.825_dp, 1.408_dp, &
220 1.485_dp, 1.452_dp, 1.397_dp, 1.342_dp, 1.287_dp, 1.243_dp, 1.144_dp, 1.364_dp, 1.639_dp, &
221 1.716_dp, 1.705_dp, 1.683_dp, 1.639_dp, 1.595_dp, 1.485_dp, 1.474_dp, 1.562_dp, 1.562_dp, &
222 1.562_dp, 1.562_dp, 1.562_dp, 1.562_dp, 1.562_dp, 1.562_dp, 1.562_dp, 1.562_dp, 1.650_dp, &
223 1.727_dp, 1.760_dp, 1.771_dp, 1.749_dp, 1.727_dp, 1.628_dp, 1.606_dp, 1.639_dp, 1.639_dp, &
224 1.639_dp, 1.639_dp, 1.639_dp, 1.639_dp, 1.639_dp, 1.639_dp, 1.639_dp, 1.639_dp, 1.672_dp, &
225 1.804_dp, 1.881_dp, 1.892_dp, 1.892_dp, 1.881_dp/)
226
227!
228! GRIMME DISPERSION PARAMETERS
229! Stefan Grimme, Semiempirical GGA-Type Density Functional Constructed
230! with a Long-Range Dispersion Correction, J. Comp. Chem. 27: 1787-1799 (2006)
231! doi:10.1002/jcc.20495
232!
233! Conversion factor [Jnm^6mol^-1] -> [a.u.] : 17.34527758021901
234! Conversion factor [A] -> [a.u.] : 1.889726132885643
235!
236! C6 values in [Jnm^6/mol]
237! vdW radii [A]
238
239 IF (z > 0 .AND. z <= 54) THEN
240 found = .true.
241 c6 = c6val(z)*1000._dp*bohr**6/kjmol
242 r = rval(z)*bohr
243 ELSE
244 found = .false.
245 END IF
246
247 END SUBROUTINE dftd2_param
248
249! **************************************************************************************************
250
251END MODULE qs_dispersion_d2
static GRID_HOST_DEVICE double fac(const int i)
Factorial function, e.g. fac(5) = 5! = 120.
Definition grid_common.h:51
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.
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.
Holds information on atomic properties.
subroutine, public atprop_array_init(atarray, natom)
...
Handles all functions related to the CELL.
Definition cell_types.F:15
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
Definition of physical constants:
Definition physcon.F:68
real(kind=dp), parameter, public kjmol
Definition physcon.F:168
real(kind=dp), parameter, public bohr
Definition physcon.F:147
Calculation of D2 dispersion.
subroutine, public calculate_dispersion_d2_pairpot(qs_env, dispersion_env, evdw, calculate_forces, atevdw)
...
subroutine, public dftd2_param(z, c6, r, found)
...
Definition of disperson types for DFT calculations.
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.
Define the quickstep kind type and their sub types.
subroutine, public get_qs_kind(qs_kind, basis_set, basis_type, ncgf, nsgf, all_potential, tnadd_potential, gth_potential, sgp_potential, upf_potential, se_parameter, dftb_parameter, xtb_parameter, dftb3_param, zatom, zeff, elec_conf, mao, lmax_dftb, alpha_core_charge, ccore_charge, core_charge, core_charge_radius, paw_proj_set, paw_atom, hard_radius, hard0_radius, max_rad_local, covalent_radius, vdw_radius, gpw_type_forced, harmonics, max_iso_not0, max_s_harm, grid_atom, ngrid_ang, ngrid_rad, lmax_rho0, dft_plus_u_atom, l_of_dft_plus_u, n_of_dft_plus_u, u_minus_j, u_of_dft_plus_u, j_of_dft_plus_u, alpha_of_dft_plus_u, beta_of_dft_plus_u, j0_of_dft_plus_u, occupation_of_dft_plus_u, dispersion, bs_occupation, magnetization, no_optimize, addel, laddel, naddel, orbitals, max_scf, eps_scf, smear, u_ramping, u_minus_j_target, eps_u_ramping, init_u_ramping_each_scf, reltmat, ghost, floating, name, element_symbol, pao_basis_size, pao_model_file, pao_potentials, pao_descriptors, nelec)
Get attributes of an atomic kind.
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
Provides all information about a quickstep kind.