(git:0d88fc2)
Loading...
Searching...
No Matches
qs_dftb_coulomb.F
Go to the documentation of this file.
1!--------------------------------------------------------------------------------------------------!
2! CP2K: A general program to perform molecular dynamics simulations !
3! Copyright 2000-2026 CP2K developers group <https://cp2k.org> !
4! !
5! SPDX-License-Identifier: GPL-2.0-or-later !
6!--------------------------------------------------------------------------------------------------!
7
8! **************************************************************************************************
9!> \brief Calculation of Coulomb contributions in DFTB
10!> \author JGH
11! **************************************************************************************************
18 USE cell_types, ONLY: cell_type,&
19 get_cell,&
20 pbc
23 USE cp_dbcsr_api, ONLY: dbcsr_add,&
37 USE kinds, ONLY: dp
38 USE kpoint_types, ONLY: get_kpoint_info,&
40 USE mathconstants, ONLY: oorootpi,&
41 pi
58 USE qs_kind_types, ONLY: get_qs_kind,&
66 USE qs_rho_types, ONLY: qs_rho_get,&
68 USE sap_kind_types, ONLY: clist_type,&
72 USE virial_types, ONLY: virial_type
73#include "./base/base_uses.f90"
74
75 IMPLICIT NONE
76
77 PRIVATE
78
79 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_dftb_coulomb'
80
81 ! screening for gamma function
82 REAL(dp), PARAMETER :: tol_gamma = 1.e-4_dp
83 ! small real number
84 REAL(dp), PARAMETER :: rtiny = 1.e-10_dp
85 REAL(KIND=dp), PARAMETER, PRIVATE :: dftb_fd_deriv_step = 1.0e-3_dp
86
88
89CONTAINS
90
91! **************************************************************************************************
92!> \brief ...
93!> \param qs_env ...
94!> \param ks_matrix ...
95!> \param rho ...
96!> \param mcharge ...
97!> \param energy ...
98!> \param calculate_forces ...
99!> \param just_energy ...
100! **************************************************************************************************
101 SUBROUTINE build_dftb_coulomb(qs_env, ks_matrix, rho, mcharge, energy, &
102 calculate_forces, just_energy)
103
104 TYPE(qs_environment_type), POINTER :: qs_env
105 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: ks_matrix
106 TYPE(qs_rho_type), POINTER :: rho
107 REAL(dp), DIMENSION(:) :: mcharge
108 TYPE(qs_energy_type), POINTER :: energy
109 LOGICAL, INTENT(in) :: calculate_forces, just_energy
110
111 CHARACTER(len=*), PARAMETER :: routinen = 'build_dftb_coulomb'
112
113 INTEGER :: atom_i, atom_j, ewald_type, handle, i, ia, iac, iatom, ic, icol, ikind, img, &
114 irow, is, jatom, jkind, llm, lmaxi, lmaxj, n1, n2, natom, natorb_a, natorb_b, ngrd, &
115 ngrdcut, nimg, nkind, nmat
116 INTEGER, ALLOCATABLE, DIMENSION(:) :: atom_of_kind, kind_of
117 INTEGER, DIMENSION(3) :: cellind, periodic
118 INTEGER, DIMENSION(:, :, :), POINTER :: cell_to_index
119 LOGICAL :: defined, defined_a, defined_b, do_ewald, &
120 do_gamma_stress, found, hb_sr_damp, &
121 use_virial
122 REAL(kind=dp) :: alpha, background, ddr, deth, dgam, &
123 dgrd, dr, drm, drp, fi, ga, gb, gmat, &
124 gmij, gmij_virial, hb_para, zeff
125 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: xgamma, zeffk
126 REAL(kind=dp), DIMENSION(0:3) :: eta_a, eta_b
127 REAL(kind=dp), DIMENSION(3) :: drij, fij, rij
128 REAL(kind=dp), DIMENSION(:, :), POINTER :: dsblock, dsblock_vir, dsblockm_vir, &
129 gmcharge, ksblock, pblock, sblock, &
130 smatij, smatji
131 REAL(kind=dp), DIMENSION(:, :, :), POINTER :: dsint
132 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
133 TYPE(atprop_type), POINTER :: atprop
134 TYPE(cell_type), POINTER :: cell
135 TYPE(dbcsr_iterator_type) :: iter
136 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: matrix_p, matrix_s
137 TYPE(dft_control_type), POINTER :: dft_control
138 TYPE(distribution_1d_type), POINTER :: local_particles
139 TYPE(ewald_environment_type), POINTER :: ewald_env
140 TYPE(ewald_pw_type), POINTER :: ewald_pw
141 TYPE(kpoint_type), POINTER :: kpoints
142 TYPE(mp_para_env_type), POINTER :: para_env
144 DIMENSION(:), POINTER :: nl_iterator
145 TYPE(neighbor_list_set_p_type), DIMENSION(:), &
146 POINTER :: n_list
147 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
148 TYPE(qs_dftb_atom_type), POINTER :: dftb_kind, dftb_kind_a, dftb_kind_b
149 TYPE(qs_dftb_pairpot_type), DIMENSION(:, :), &
150 POINTER :: dftb_potential
151 TYPE(qs_dftb_pairpot_type), POINTER :: dftb_param_ij, dftb_param_ji
152 TYPE(qs_force_type), DIMENSION(:), POINTER :: force
153 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
154 TYPE(sap_int_type), DIMENSION(:), POINTER :: sap_int
155 TYPE(virial_type), POINTER :: virial
156
157 CALL timeset(routinen, handle)
158
159 NULLIFY (matrix_p, matrix_s, virial, atprop, dft_control)
160
161 use_virial = .false.
162
163 IF (calculate_forces) THEN
164 nmat = 4
165 ELSE
166 nmat = 1
167 END IF
168
169 CALL get_qs_env(qs_env, nkind=nkind, natom=natom)
170 ALLOCATE (gmcharge(natom, nmat))
171 gmcharge = 0._dp
172
173 CALL get_qs_env(qs_env, &
174 particle_set=particle_set, &
175 cell=cell, &
176 virial=virial, &
177 atprop=atprop, &
178 dft_control=dft_control, &
179 atomic_kind_set=atomic_kind_set, &
180 qs_kind_set=qs_kind_set, &
181 force=force, para_env=para_env)
182
183 IF (calculate_forces) THEN
184 use_virial = virial%pv_availability .AND. (.NOT. virial%pv_numer)
185 END IF
186
187 NULLIFY (dftb_potential)
188 CALL get_qs_env(qs_env=qs_env, dftb_potential=dftb_potential)
189 NULLIFY (n_list)
190 CALL get_qs_env(qs_env=qs_env, sab_orb=n_list)
191 CALL neighbor_list_iterator_create(nl_iterator, n_list)
192 DO WHILE (neighbor_list_iterate(nl_iterator) == 0)
193 CALL get_iterator_info(nl_iterator, ikind=ikind, jkind=jkind, &
194 iatom=iatom, jatom=jatom, r=rij, cell=cellind)
195
196 CALL get_qs_kind(qs_kind_set(ikind), dftb_parameter=dftb_kind_a)
197 CALL get_dftb_atom_param(dftb_kind_a, &
198 defined=defined, eta=eta_a, natorb=natorb_a)
199 IF (.NOT. defined .OR. natorb_a < 1) cycle
200 CALL get_qs_kind(qs_kind_set(jkind), dftb_parameter=dftb_kind_b)
201 CALL get_dftb_atom_param(dftb_kind_b, &
202 defined=defined, eta=eta_b, natorb=natorb_b)
203 IF (.NOT. defined .OR. natorb_b < 1) cycle
204
205 ! gamma matrix
206 hb_sr_damp = dft_control%qs_control%dftb_control%hb_sr_damp
207 IF (hb_sr_damp) THEN
208 ! short range correction enabled only when iatom XOR jatom are hydrogens
209 hb_sr_damp = is_hydrogen(particle_set(iatom)%atomic_kind) .NEQV. &
210 is_hydrogen(particle_set(jatom)%atomic_kind)
211 END IF
212 IF (hb_sr_damp) THEN
213 hb_para = dft_control%qs_control%dftb_control%hb_sr_para
214 ELSE
215 hb_para = 0.0_dp
216 END IF
217 ga = eta_a(0)
218 gb = eta_b(0)
219 dr = sqrt(sum(rij(:)**2))
220 gmat = gamma_rab_sr(dr, ga, gb, hb_para)
221 gmcharge(jatom, 1) = gmcharge(jatom, 1) + gmat*mcharge(iatom)
222 IF (iatom /= jatom) THEN
223 gmcharge(iatom, 1) = gmcharge(iatom, 1) + gmat*mcharge(jatom)
224 END IF
225 IF (calculate_forces .AND. (iatom /= jatom .OR. dr > 0.001_dp)) THEN
226 ddr = dftb_fd_deriv_step*dftb_potential(ikind, jkind)%dgrd
227 drp = dr + ddr
228 drm = dr - ddr
229 dgam = 0.5_dp*(gamma_rab_sr(drp, ga, gb, hb_para) - gamma_rab_sr(drm, ga, gb, hb_para))/ddr
230 DO i = 1, 3
231 gmcharge(jatom, i + 1) = gmcharge(jatom, i + 1) - dgam*mcharge(iatom)*rij(i)/dr
232 IF (dr > 0.001_dp) THEN
233 gmcharge(iatom, i + 1) = gmcharge(iatom, i + 1) + dgam*mcharge(jatom)*rij(i)/dr
234 END IF
235 IF (use_virial) THEN
236 fij(i) = -mcharge(iatom)*mcharge(jatom)*dgam*rij(i)/dr
237 END IF
238 END DO
239 IF (use_virial) THEN
240 fi = 1.0_dp
241 IF (iatom == jatom) fi = 0.5_dp
242 CALL virial_pair_force(virial%pv_virial, fi, fij, rij)
243 END IF
244 END IF
245 END DO
246 CALL neighbor_list_iterator_release(nl_iterator)
247
248 IF (atprop%energy) THEN
249 CALL get_qs_env(qs_env=qs_env, particle_set=particle_set)
250 natom = SIZE(particle_set)
251 CALL atprop_array_init(atprop%atecoul, natom)
252 END IF
253
254 ! 1/R contribution
255 do_ewald = dft_control%qs_control%dftb_control%do_ewald
256 IF (do_ewald) THEN
257 ! Ewald sum
258 NULLIFY (ewald_env, ewald_pw)
259 CALL get_qs_env(qs_env=qs_env, &
260 ewald_env=ewald_env, ewald_pw=ewald_pw)
261 CALL get_cell(cell=cell, periodic=periodic, deth=deth)
262 CALL ewald_env_get(ewald_env, alpha=alpha, ewald_type=ewald_type)
263 CALL get_qs_env(qs_env=qs_env, sab_tbe=n_list)
264 CALL tb_ewald_overlap(gmcharge, mcharge, alpha, n_list, virial, use_virial)
265 SELECT CASE (ewald_type)
266 CASE DEFAULT
267 cpabort("Invalid Ewald type")
268 CASE (do_ewald_none)
269 cpabort("Not allowed with DFTB")
270 CASE (do_ewald_ewald)
271 cpabort("Standard Ewald not implemented in DFTB")
272 CASE (do_ewald_pme)
273 cpabort("PME not implemented in DFTB")
274 CASE (do_ewald_spme)
275 CALL tb_spme_evaluate(ewald_env, ewald_pw, particle_set, cell, &
276 gmcharge, mcharge, calculate_forces, virial, use_virial)
277 END SELECT
278 ELSE
279 ! direct sum
280 CALL get_qs_env(qs_env=qs_env, &
281 local_particles=local_particles)
282 DO ikind = 1, SIZE(local_particles%n_el)
283 DO ia = 1, local_particles%n_el(ikind)
284 iatom = local_particles%list(ikind)%array(ia)
285 DO jatom = 1, iatom - 1
286 rij = particle_set(iatom)%r - particle_set(jatom)%r
287 rij = pbc(rij, cell)
288 dr = sqrt(sum(rij(:)**2))
289 gmcharge(iatom, 1) = gmcharge(iatom, 1) + mcharge(jatom)/dr
290 gmcharge(jatom, 1) = gmcharge(jatom, 1) + mcharge(iatom)/dr
291 DO i = 2, nmat
292 gmcharge(iatom, i) = gmcharge(iatom, i) + rij(i - 1)*mcharge(jatom)/dr**3
293 gmcharge(jatom, i) = gmcharge(jatom, i) - rij(i - 1)*mcharge(iatom)/dr**3
294 END DO
295 IF (use_virial .AND. dr > 1.e-6_dp) THEN
296 DO i = 1, 3
297 fij(i) = mcharge(iatom)*mcharge(jatom)*rij(i)/dr**3
298 END DO
299 CALL virial_pair_force(virial%pv_virial, 1.0_dp, fij, rij)
300 END IF
301 END DO
302 END DO
303 END DO
304 END IF
305
306 CALL para_env%sum(gmcharge(:, 1))
307
308 background = 0.0_dp
309 IF (do_ewald) THEN
310 ! add self charge interaction and background charge contribution
311 gmcharge(:, 1) = gmcharge(:, 1) - 2._dp*alpha*oorootpi*mcharge(:)
312 IF (any(periodic(:) == 1)) THEN
313 background = pi/alpha**2/deth
314 END IF
315 END IF
316
317 energy%hartree = energy%hartree + 0.5_dp*sum(mcharge(:)*(gmcharge(:, 1) - background))
318 IF (atprop%energy) THEN
319 CALL get_qs_env(qs_env=qs_env, &
320 local_particles=local_particles)
321 DO ikind = 1, SIZE(local_particles%n_el)
322 CALL get_qs_kind(qs_kind_set(ikind), dftb_parameter=dftb_kind)
323 CALL get_dftb_atom_param(dftb_kind, zeff=zeff)
324 DO ia = 1, local_particles%n_el(ikind)
325 iatom = local_particles%list(ikind)%array(ia)
326 atprop%atecoul(iatom) = atprop%atecoul(iatom) + &
327 0.5_dp*zeff*gmcharge(iatom, 1)
328 END DO
329 END DO
330 END IF
331
332 IF (calculate_forces) THEN
333 CALL get_atomic_kind_set(atomic_kind_set=atomic_kind_set, &
334 kind_of=kind_of, &
335 atom_of_kind=atom_of_kind)
336
337 gmcharge(:, 2) = gmcharge(:, 2)*mcharge(:)
338 gmcharge(:, 3) = gmcharge(:, 3)*mcharge(:)
339 gmcharge(:, 4) = gmcharge(:, 4)*mcharge(:)
340 DO iatom = 1, natom
341 ikind = kind_of(iatom)
342 atom_i = atom_of_kind(iatom)
343 force(ikind)%rho_elec(1, atom_i) = force(ikind)%rho_elec(1, atom_i) - gmcharge(iatom, 2)
344 force(ikind)%rho_elec(2, atom_i) = force(ikind)%rho_elec(2, atom_i) - gmcharge(iatom, 3)
345 force(ikind)%rho_elec(3, atom_i) = force(ikind)%rho_elec(3, atom_i) - gmcharge(iatom, 4)
346 END DO
347 END IF
348
349 do_gamma_stress = .false.
350 IF (.NOT. just_energy .AND. use_virial) THEN
351 IF (dft_control%nimages == 1) do_gamma_stress = .true.
352 END IF
353
354 IF (.NOT. just_energy) THEN
355 CALL get_qs_env(qs_env=qs_env, matrix_s_kp=matrix_s)
356 CALL qs_rho_get(rho, rho_ao_kp=matrix_p)
357
358 nimg = dft_control%nimages
359 NULLIFY (cell_to_index)
360 IF (nimg > 1) THEN
361 NULLIFY (kpoints)
362 CALL get_qs_env(qs_env=qs_env, kpoints=kpoints)
363 CALL get_kpoint_info(kpoint=kpoints, cell_to_index=cell_to_index)
364 END IF
365
366 IF (calculate_forces .AND. SIZE(matrix_p, 1) == 2) THEN
367 DO img = 1, nimg
368 CALL dbcsr_add(matrix_p(1, img)%matrix, matrix_p(2, img)%matrix, &
369 alpha_scalar=1.0_dp, beta_scalar=1.0_dp)
370 END DO
371 END IF
372
373 NULLIFY (sap_int)
374 IF (do_gamma_stress) THEN
375 ! derivative overlap integral (non collapsed)
376 CALL dftb_dsint_list(qs_env, sap_int)
377 END IF
378
379 IF (nimg == 1) THEN
380 ! no k-points; all matrices have been transformed to periodic bsf
381 CALL dbcsr_iterator_start(iter, matrix_s(1, 1)%matrix)
382 DO WHILE (dbcsr_iterator_blocks_left(iter))
383 CALL dbcsr_iterator_next_block(iter, irow, icol, sblock)
384 gmij = 0.5_dp*(gmcharge(irow, 1) + gmcharge(icol, 1))
385 DO is = 1, SIZE(ks_matrix, 1)
386 NULLIFY (ksblock)
387 CALL dbcsr_get_block_p(matrix=ks_matrix(is, 1)%matrix, &
388 row=irow, col=icol, block=ksblock, found=found)
389 cpassert(found)
390 ksblock = ksblock - gmij*sblock
391 END DO
392 IF (calculate_forces) THEN
393 ikind = kind_of(irow)
394 atom_i = atom_of_kind(irow)
395 jkind = kind_of(icol)
396 atom_j = atom_of_kind(icol)
397 NULLIFY (pblock)
398 CALL dbcsr_get_block_p(matrix=matrix_p(1, 1)%matrix, &
399 row=irow, col=icol, block=pblock, found=found)
400 cpassert(found)
401 DO i = 1, 3
402 NULLIFY (dsblock)
403 CALL dbcsr_get_block_p(matrix=matrix_s(1 + i, 1)%matrix, &
404 row=irow, col=icol, block=dsblock, found=found)
405 cpassert(found)
406 fi = -2.0_dp*gmij*sum(pblock*dsblock)
407 force(ikind)%rho_elec(i, atom_i) = force(ikind)%rho_elec(i, atom_i) + fi
408 force(jkind)%rho_elec(i, atom_j) = force(jkind)%rho_elec(i, atom_j) - fi
409 fij(i) = fi
410 END DO
411 END IF
412 END DO
413 CALL dbcsr_iterator_stop(iter)
414 !
415 IF (do_gamma_stress) THEN
416 DO ikind = 1, nkind
417 DO jkind = 1, nkind
418 iac = ikind + nkind*(jkind - 1)
419 IF (.NOT. ASSOCIATED(sap_int(iac)%alist)) cycle
420 DO ia = 1, sap_int(iac)%nalist
421 IF (.NOT. ASSOCIATED(sap_int(iac)%alist(ia)%clist)) cycle
422 iatom = sap_int(iac)%alist(ia)%aatom
423 DO ic = 1, sap_int(iac)%alist(ia)%nclist
424 jatom = sap_int(iac)%alist(ia)%clist(ic)%catom
425 rij = sap_int(iac)%alist(ia)%clist(ic)%rac
426 dr = sqrt(sum(rij(:)**2))
427 IF (dr > 1.e-6_dp) THEN
428 dsint => sap_int(iac)%alist(ia)%clist(ic)%acint
429 gmij = 0.5_dp*(gmcharge(iatom, 1) + gmcharge(jatom, 1))
430 icol = max(iatom, jatom)
431 irow = min(iatom, jatom)
432 NULLIFY (pblock)
433 CALL dbcsr_get_block_p(matrix=matrix_p(1, 1)%matrix, &
434 row=irow, col=icol, block=pblock, found=found)
435 cpassert(found)
436 DO i = 1, 3
437 IF (irow == iatom) THEN
438 fij(i) = -2.0_dp*gmij*sum(pblock*dsint(:, :, i))
439 ELSE
440 fij(i) = -2.0_dp*gmij*sum(transpose(pblock)*dsint(:, :, i))
441 END IF
442 END DO
443 fi = 1.0_dp
444 IF (iatom == jatom) fi = 0.5_dp
445 CALL virial_pair_force(virial%pv_virial, fi, fij, rij)
446 END IF
447 END DO
448 END DO
449 END DO
450 END DO
451 END IF
452 ELSE
453 NULLIFY (n_list)
454 CALL get_qs_env(qs_env=qs_env, sab_orb=n_list)
455 CALL neighbor_list_iterator_create(nl_iterator, n_list)
456 DO WHILE (neighbor_list_iterate(nl_iterator) == 0)
457 CALL get_iterator_info(nl_iterator, ikind=ikind, jkind=jkind, &
458 iatom=iatom, jatom=jatom, r=rij, cell=cellind)
459
460 icol = max(iatom, jatom)
461 irow = min(iatom, jatom)
462 ic = cell_to_index(cellind(1), cellind(2), cellind(3))
463 cpassert(ic > 0)
464
465 gmij = 0.5_dp*(gmcharge(iatom, 1) + gmcharge(jatom, 1))
466
467 NULLIFY (sblock)
468 CALL dbcsr_get_block_p(matrix=matrix_s(1, ic)%matrix, &
469 row=irow, col=icol, block=sblock, found=found)
470 cpassert(found)
471 DO is = 1, SIZE(ks_matrix, 1)
472 NULLIFY (ksblock)
473 CALL dbcsr_get_block_p(matrix=ks_matrix(is, ic)%matrix, &
474 row=irow, col=icol, block=ksblock, found=found)
475 cpassert(found)
476 ksblock = ksblock - gmij*sblock
477 END DO
478
479 IF (calculate_forces) THEN
480 ikind = kind_of(iatom)
481 atom_i = atom_of_kind(iatom)
482 jkind = kind_of(jatom)
483 atom_j = atom_of_kind(jatom)
484 IF (irow == jatom) gmij = -gmij
485 NULLIFY (pblock)
486 CALL dbcsr_get_block_p(matrix=matrix_p(1, ic)%matrix, &
487 row=irow, col=icol, block=pblock, found=found)
488 cpassert(found)
489 DO i = 1, 3
490 NULLIFY (dsblock)
491 CALL dbcsr_get_block_p(matrix=matrix_s(1 + i, ic)%matrix, &
492 row=irow, col=icol, block=dsblock, found=found)
493 cpassert(found)
494 fi = -2.0_dp*gmij*sum(pblock*dsblock)
495 force(ikind)%rho_elec(i, atom_i) = force(ikind)%rho_elec(i, atom_i) + fi
496 force(jkind)%rho_elec(i, atom_j) = force(jkind)%rho_elec(i, atom_j) - fi
497 fij(i) = fi
498 END DO
499 IF (use_virial) THEN
500 ! The image-resolved overlap derivative blocks are matrix oriented. Rebuild the
501 ! atom-oriented derivative for the virial contraction, matching the Gamma path.
502 fij = 0.0_dp
503 CALL get_qs_kind(qs_kind_set(ikind), dftb_parameter=dftb_kind_a)
504 CALL get_dftb_atom_param(dftb_kind_a, &
505 defined=defined_a, lmax=lmaxi, natorb=natorb_a)
506 CALL get_qs_kind(qs_kind_set(jkind), dftb_parameter=dftb_kind_b)
507 CALL get_dftb_atom_param(dftb_kind_b, &
508 defined=defined_b, lmax=lmaxj, natorb=natorb_b)
509 IF (defined_a .AND. defined_b .AND. natorb_a > 0 .AND. natorb_b > 0) THEN
510 dftb_param_ij => dftb_potential(ikind, jkind)
511 dftb_param_ji => dftb_potential(jkind, ikind)
512 ngrd = dftb_param_ij%ngrd
513 ngrdcut = dftb_param_ij%ngrdcut
514 dgrd = dftb_param_ij%dgrd
515 ddr = dgrd*dftb_fd_deriv_step
516 cpassert(dftb_param_ij%llm == dftb_param_ji%llm)
517 llm = dftb_param_ij%llm
518 smatij => dftb_param_ij%smat
519 smatji => dftb_param_ji%smat
520 dr = sqrt(sum(rij(:)**2))
521 IF (nint(dr/dgrd) <= ngrdcut .AND. dr > 1.e-6_dp) THEN
522 n1 = natorb_a
523 n2 = natorb_b
524 ALLOCATE (dsblock_vir(n1, n2), dsblockm_vir(n1, n2))
525 gmij_virial = 0.5_dp*(gmcharge(iatom, 1) + gmcharge(jatom, 1))
526 DO i = 1, 3
527 dsblock_vir = 0._dp
528 dsblockm_vir = 0._dp
529 drij = rij
530 drij(i) = rij(i) - ddr
531 CALL compute_block_sk(dsblockm_vir, smatij, smatji, drij, ngrd, ngrdcut, dgrd, &
532 llm, lmaxi, lmaxj, iatom, iatom)
533 drij(i) = rij(i) + ddr
534 CALL compute_block_sk(dsblock_vir, smatij, smatji, drij, ngrd, ngrdcut, dgrd, &
535 llm, lmaxi, lmaxj, iatom, iatom)
536 dsblock_vir = (dsblock_vir - dsblockm_vir)/(2.0_dp*ddr)
537 IF (irow == iatom) THEN
538 fij(i) = 2.0_dp*gmij_virial*sum(pblock*dsblock_vir)
539 ELSE
540 fij(i) = 2.0_dp*gmij_virial*sum(transpose(pblock)*dsblock_vir)
541 END IF
542 END DO
543 DEALLOCATE (dsblock_vir, dsblockm_vir)
544 fi = 1.0_dp
545 IF (iatom == jatom) fi = 0.5_dp
546 CALL virial_pair_force(virial%pv_virial, fi, fij, rij)
547 END IF
548 END IF
549 END IF
550 END IF
551 END DO
552 CALL neighbor_list_iterator_release(nl_iterator)
553 END IF
554
555 IF (calculate_forces .AND. SIZE(matrix_p, 1) == 2) THEN
556 DO img = 1, nimg
557 CALL dbcsr_add(matrix_p(1, img)%matrix, matrix_p(2, img)%matrix, &
558 alpha_scalar=1.0_dp, beta_scalar=-1.0_dp)
559 END DO
560 END IF
561 END IF
562
563 IF (dft_control%qs_control%dftb_control%dftb3_diagonal) THEN
564 CALL get_qs_env(qs_env, nkind=nkind)
565 ALLOCATE (zeffk(nkind), xgamma(nkind))
566 DO ikind = 1, nkind
567 CALL get_qs_kind(qs_kind_set(ikind), dftb_parameter=dftb_kind)
568 CALL get_dftb_atom_param(dftb_kind, dudq=xgamma(ikind), zeff=zeffk(ikind))
569 END DO
570 ! Diagonal 3rd order correction (DFTB3)
571 CALL build_dftb3_diagonal(qs_env, ks_matrix, rho, mcharge, energy, xgamma, zeffk, &
572 sap_int, calculate_forces, just_energy)
573 DEALLOCATE (zeffk, xgamma)
574 END IF
575
576 ! QMMM
577 IF (qs_env%qmmm .AND. qs_env%qmmm_periodic) THEN
578 CALL build_tb_coulomb_qmqm(qs_env, ks_matrix, rho, mcharge, energy, &
579 calculate_forces, just_energy)
580 END IF
581
582 IF (do_gamma_stress) THEN
583 CALL release_sap_int(sap_int)
584 END IF
585
586 DEALLOCATE (gmcharge)
587
588 CALL timestop(handle)
589
590 END SUBROUTINE build_dftb_coulomb
591
592! **************************************************************************************************
593!> \brief Computes the short-range gamma parameter from exact Coulomb
594!> interaction of normalized exp(-a*r) charge distribution - 1/r
595!> \param r ...
596!> \param ga ...
597!> \param gb ...
598!> \param hb_para ...
599!> \return ...
600!> \par Literature
601!> Elstner et al, PRB 58 (1998) 7260
602!> \par History
603!> 10.2008 Axel Kohlmeyer - adding sr_damp
604!> 08.2014 JGH - adding flexible exponent for damping
605!> \version 1.1
606! **************************************************************************************************
607 FUNCTION gamma_rab_sr(r, ga, gb, hb_para) RESULT(gamma)
608 REAL(dp), INTENT(in) :: r, ga, gb, hb_para
609 REAL(dp) :: gamma
610
611 REAL(dp) :: a, b, fac, g_sum
612
613 gamma = 0.0_dp
614 a = 3.2_dp*ga ! 3.2 = 16/5 in Eq. 18 and ff.
615 b = 3.2_dp*gb
616 g_sum = a + b
617 IF (g_sum < tol_gamma) RETURN ! hardness screening
618 IF (r < rtiny) THEN ! This is for short distances but non-onsite terms
619 ! This gives also correct diagonal elements (a=b, r=0)
620 gamma = 0.5_dp*(a*b/g_sum + (a*b)**2/g_sum**3)
621 RETURN
622 END IF
623 !
624 ! distinguish two cases: Gamma's are very close, e.g. for the same atom type,
625 ! and Gamma's are different
626 !
627 IF (abs(a - b) < rtiny) THEN
628 fac = 1.6_dp*r*a*b/g_sum*(1.0_dp + a*b/g_sum**2)
629 gamma = -(48.0_dp + 33._dp*fac + (9.0_dp + fac)*fac**2)*exp(-fac)/(48._dp*r)
630 ELSE
631 gamma = -exp(-a*r)*(0.5_dp*a*b**4/(a**2 - b**2)**2 - &
632 (b**6 - 3._dp*a**2*b**4)/(r*(a**2 - b**2)**3)) - & ! a-> b
633 exp(-b*r)*(0.5_dp*b*a**4/(b**2 - a**2)**2 - &
634 (a**6 - 3._dp*b**2*a**4)/(r*(b**2 - a**2)**3)) ! b-> a
635 END IF
636 !
637 ! damping function for better short range hydrogen bonds.
638 ! functional form from Hu H. et al., J. Phys. Chem. A 2007, 111, 5685-5691
639 ! according to Elstner M, Theor. Chem. Acc. 2006, 116, 316-325,
640 ! this should only be applied to a-b pairs involving hydrogen.
641 IF (hb_para > 0.0_dp) THEN
642 gamma = gamma*exp(-(0.5_dp*(ga + gb))**hb_para*r*r)
643 END IF
644 END FUNCTION gamma_rab_sr
645
646! **************************************************************************************************
647!> \brief ...
648!> \param qs_env ...
649!> \param sap_int ...
650! **************************************************************************************************
651 SUBROUTINE dftb_dsint_list(qs_env, sap_int)
652
653 TYPE(qs_environment_type), POINTER :: qs_env
654 TYPE(sap_int_type), DIMENSION(:), POINTER :: sap_int
655
656 CHARACTER(LEN=*), PARAMETER :: routinen = 'dftb_dsint_list'
657
658 INTEGER :: handle, i, iac, iatom, ikind, ilist, jatom, jkind, jneighbor, llm, lmaxi, lmaxj, &
659 n1, n2, natorb_a, natorb_b, ngrd, ngrdcut, nkind, nlist, nneighbor
660 INTEGER, DIMENSION(3) :: cell
661 LOGICAL :: defined
662 REAL(kind=dp) :: ddr, dgrd, dr
663 REAL(kind=dp), DIMENSION(3) :: drij, rij
664 REAL(kind=dp), DIMENSION(:, :), POINTER :: dsblock, dsblockm, smatij, smatji
665 TYPE(clist_type), POINTER :: clist
666 TYPE(dft_control_type), POINTER :: dft_control
667 TYPE(dftb_control_type), POINTER :: dftb_control
669 DIMENSION(:), POINTER :: nl_iterator
670 TYPE(neighbor_list_set_p_type), DIMENSION(:), &
671 POINTER :: sab_orb
672 TYPE(qs_dftb_atom_type), POINTER :: dftb_kind_a, dftb_kind_b
673 TYPE(qs_dftb_pairpot_type), DIMENSION(:, :), &
674 POINTER :: dftb_potential
675 TYPE(qs_dftb_pairpot_type), POINTER :: dftb_param_ij, dftb_param_ji
676 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
677
678 CALL timeset(routinen, handle)
679
680 CALL get_qs_env(qs_env=qs_env, nkind=nkind)
681 cpassert(.NOT. ASSOCIATED(sap_int))
682 ALLOCATE (sap_int(nkind*nkind))
683 DO i = 1, nkind*nkind
684 NULLIFY (sap_int(i)%alist, sap_int(i)%asort, sap_int(i)%aindex)
685 sap_int(i)%nalist = 0
686 END DO
687
688 CALL get_qs_env(qs_env=qs_env, &
689 qs_kind_set=qs_kind_set, &
690 dft_control=dft_control, &
691 sab_orb=sab_orb)
692
693 dftb_control => dft_control%qs_control%dftb_control
694
695 NULLIFY (dftb_potential)
696 CALL get_qs_env(qs_env=qs_env, &
697 dftb_potential=dftb_potential)
698
699 ! loop over all atom pairs with a non-zero overlap (sab_orb)
700 CALL neighbor_list_iterator_create(nl_iterator, sab_orb)
701 DO WHILE (neighbor_list_iterate(nl_iterator) == 0)
702 CALL get_iterator_info(nl_iterator, ikind=ikind, jkind=jkind, iatom=iatom, &
703 jatom=jatom, nlist=nlist, ilist=ilist, nnode=nneighbor, &
704 inode=jneighbor, cell=cell, r=rij)
705 iac = ikind + nkind*(jkind - 1)
706 !
707 CALL get_qs_kind(qs_kind_set(ikind), dftb_parameter=dftb_kind_a)
708 CALL get_dftb_atom_param(dftb_kind_a, &
709 defined=defined, lmax=lmaxi, natorb=natorb_a)
710 IF (.NOT. defined .OR. natorb_a < 1) cycle
711 CALL get_qs_kind(qs_kind_set(jkind), dftb_parameter=dftb_kind_b)
712 CALL get_dftb_atom_param(dftb_kind_b, &
713 defined=defined, lmax=lmaxj, natorb=natorb_b)
714 IF (.NOT. defined .OR. natorb_b < 1) cycle
715
716 dr = sqrt(sum(rij(:)**2))
717
718 ! integral list
719 IF (.NOT. ASSOCIATED(sap_int(iac)%alist)) THEN
720 sap_int(iac)%a_kind = ikind
721 sap_int(iac)%p_kind = jkind
722 sap_int(iac)%nalist = nlist
723 ALLOCATE (sap_int(iac)%alist(nlist))
724 DO i = 1, nlist
725 NULLIFY (sap_int(iac)%alist(i)%clist)
726 sap_int(iac)%alist(i)%aatom = 0
727 sap_int(iac)%alist(i)%nclist = 0
728 END DO
729 END IF
730 IF (.NOT. ASSOCIATED(sap_int(iac)%alist(ilist)%clist)) THEN
731 sap_int(iac)%alist(ilist)%aatom = iatom
732 sap_int(iac)%alist(ilist)%nclist = nneighbor
733 ALLOCATE (sap_int(iac)%alist(ilist)%clist(nneighbor))
734 DO i = 1, nneighbor
735 sap_int(iac)%alist(ilist)%clist(i)%catom = 0
736 END DO
737 END IF
738 clist => sap_int(iac)%alist(ilist)%clist(jneighbor)
739 clist%catom = jatom
740 clist%cell = cell
741 clist%rac = rij
742 ALLOCATE (clist%acint(natorb_a, natorb_b, 3))
743 NULLIFY (clist%achint)
744 clist%acint = 0._dp
745 clist%nsgf_cnt = 0
746 NULLIFY (clist%sgf_list)
747
748 ! retrieve information on S matrix
749 dftb_param_ij => dftb_potential(ikind, jkind)
750 dftb_param_ji => dftb_potential(jkind, ikind)
751 ! assume table size and type is symmetric
752 ngrd = dftb_param_ij%ngrd
753 ngrdcut = dftb_param_ij%ngrdcut
754 dgrd = dftb_param_ij%dgrd
755 ddr = dgrd*dftb_fd_deriv_step
756 cpassert(dftb_param_ij%llm == dftb_param_ji%llm)
757 llm = dftb_param_ij%llm
758 smatij => dftb_param_ij%smat
759 smatji => dftb_param_ji%smat
760
761 IF (nint(dr/dgrd) <= ngrdcut) THEN
762 IF (iatom == jatom .AND. dr < 0.001_dp) THEN
763 ! diagonal block
764 ELSE
765 ! off-diagonal block
766 n1 = natorb_a
767 n2 = natorb_b
768 ALLOCATE (dsblock(n1, n2), dsblockm(n1, n2))
769 DO i = 1, 3
770 dsblock = 0._dp
771 dsblockm = 0.0_dp
772 drij = rij
773
774 drij(i) = rij(i) - ddr
775 CALL compute_block_sk(dsblockm, smatij, smatji, drij, ngrd, ngrdcut, dgrd, &
776 llm, lmaxi, lmaxj, iatom, iatom)
777
778 drij(i) = rij(i) + ddr
779 CALL compute_block_sk(dsblock, smatij, smatji, drij, ngrd, ngrdcut, dgrd, &
780 llm, lmaxi, lmaxj, iatom, iatom)
781
782 dsblock = dsblock - dsblockm
783 dsblock = dsblock/(2.0_dp*ddr)
784
785 clist%acint(1:n1, 1:n2, i) = -dsblock(1:n1, 1:n2)
786 END DO
787 DEALLOCATE (dsblock, dsblockm)
788 END IF
789 END IF
790
791 END DO
792 CALL neighbor_list_iterator_release(nl_iterator)
793
794 CALL timestop(handle)
795
796 END SUBROUTINE dftb_dsint_list
797
798END MODULE qs_dftb_coulomb
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.
elemental logical function, public is_hydrogen(atomic_kind)
Determines if the atomic_kind is HYDROGEN.
Holds information on atomic properties.
subroutine, public atprop_array_init(atarray, natom)
...
Handles all functions related to the CELL.
Definition cell_types.F:15
subroutine, public get_cell(cell, alpha, beta, gamma, deth, orthorhombic, abc, periodic, h, h_inv, symmetry_id, tag)
Get informations about a simulation cell.
Definition cell_types.F:210
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
logical function, public dbcsr_iterator_blocks_left(iterator)
...
subroutine, public dbcsr_iterator_stop(iterator)
...
subroutine, public dbcsr_get_block_p(matrix, row, col, block, found, row_size, col_size)
...
subroutine, public dbcsr_iterator_next_block(iterator, row, column, block, block_number_argument_has_been_removed, row_size, col_size, row_offset, col_offset, transposed)
...
subroutine, public dbcsr_iterator_start(iterator, matrix, shared, dynamic, dynamic_byrows)
...
subroutine, public dbcsr_add(matrix_a, matrix_b, alpha_scalar, beta_scalar)
...
stores a lists of integer that are local to a processor. The idea is that these integers represent ob...
subroutine, public ewald_env_get(ewald_env, ewald_type, alpha, eps_pol, epsilon, gmax, ns_max, o_spline, group, para_env, poisson_section, precs, rcut, do_multipoles, max_multipole, do_ipol, max_ipol_iter, interaction_cutoffs, cell_hmat)
Purpose: Get the EWALD environment.
Calculation of Ewald contributions in DFTB.
subroutine, public tb_ewald_overlap(gmcharge, mcharge, alpha, n_list, virial, use_virial)
...
subroutine, public tb_spme_evaluate(ewald_env, ewald_pw, particle_set, box, gmcharge, mcharge, calculate_forces, virial, use_virial)
...
Calculation of the incomplete Gamma function F_n(t) for multi-center integrals over Cartesian Gaussia...
Definition gamma.F:15
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
Types and basic routines needed for a kpoint calculation.
subroutine, public get_kpoint_info(kpoint, kp_scheme, nkp_grid, kp_shift, symmetry, verbose, full_grid, use_real_wfn, eps_geo, parallel_group_size, kp_range, nkp, xkp, wkp, para_env, blacs_env_all, para_env_kp, para_env_inter_kp, blacs_env, kp_env, kp_aux_env, mpools, iogrp, nkp_groups, kp_dist, cell_to_index, index_to_cell, sab_nl, sab_nl_nosym, inversion_symmetry_only, symmetry_backend, symmetry_reduction_method, gamma_centered)
Retrieve information from a kpoint environment.
Definition of mathematical constants and functions.
real(kind=dp), parameter, public oorootpi
real(kind=dp), parameter, public pi
real(kind=dp), dimension(0:maxfac), parameter, public fac
Interface to the message passing library MPI.
Define the data structure for the particle information.
functions related to the poisson solver on regular grids
integer, parameter, public do_ewald_pme
integer, parameter, public do_ewald_ewald
integer, parameter, public do_ewald_none
integer, parameter, public do_ewald_spme
Calculation of QMMM Coulomb contributions in TB.
subroutine, public build_tb_coulomb_qmqm(qs_env, ks_matrix, rho, mcharge, energy, calculate_forces, just_energy)
...
Calculation of DFTB3 Terms.
subroutine, public build_dftb3_diagonal(qs_env, ks_matrix, rho, mcharge, energy, xgamma, zeff, sap_int, calculate_forces, just_energy)
...
Calculation of Coulomb contributions in DFTB.
subroutine, public build_dftb_coulomb(qs_env, ks_matrix, rho, mcharge, energy, calculate_forces, just_energy)
...
real(dp) function, public gamma_rab_sr(r, ga, gb, hb_para)
Computes the short-range gamma parameter from exact Coulomb interaction of normalized exp(-a*r) charg...
Definition of the DFTB parameter types.
Working with the DFTB parameter types.
subroutine, public compute_block_sk(block, smatij, smatji, rij, ngrd, ngrdcut, dgrd, llm, lmaxi, lmaxj, irow, iatom)
...
subroutine, public get_dftb_atom_param(dftb_parameter, name, typ, defined, z, zeff, natorb, lmax, skself, occupation, eta, energy, cutoff, xi, di, rcdisp, dudq)
...
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.
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, cneo_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, monovalent, 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)
...
superstucture that hold various representations of the density and keeps track of which ones are vali...
subroutine, public qs_rho_get(rho_struct, rho_ao, rho_ao_im, rho_ao_kp, rho_ao_im_kp, rho_r, drho_r, rho_g, drho_g, tau_r, tau_g, rho_r_valid, drho_r_valid, rho_g_valid, drho_g_valid, tau_r_valid, tau_g_valid, tot_rho_r, tot_rho_g, rho_r_sccs, soft_valid, complex_rho_ao)
returns info about the density described by this object. If some representation is not available an e...
General overlap type integrals containers.
subroutine, public release_sap_int(sap_int)
...
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:60
structure to store local (to a processor) ordered lists of integers.
Contains information about kpoints.
stores all the informations relevant to an mpi environment
Provides all information about a quickstep kind.
keeps the density in various representations, keeping track of which ones are valid.