(git:ed6f26b)
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-2025 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
87
88CONTAINS
89
90! **************************************************************************************************
91!> \brief ...
92!> \param qs_env ...
93!> \param ks_matrix ...
94!> \param rho ...
95!> \param mcharge ...
96!> \param energy ...
97!> \param calculate_forces ...
98!> \param just_energy ...
99! **************************************************************************************************
100 SUBROUTINE build_dftb_coulomb(qs_env, ks_matrix, rho, mcharge, energy, &
101 calculate_forces, just_energy)
102
103 TYPE(qs_environment_type), POINTER :: qs_env
104 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: ks_matrix
105 TYPE(qs_rho_type), POINTER :: rho
106 REAL(dp), DIMENSION(:) :: mcharge
107 TYPE(qs_energy_type), POINTER :: energy
108 LOGICAL, INTENT(in) :: calculate_forces, just_energy
109
110 CHARACTER(len=*), PARAMETER :: routinen = 'build_dftb_coulomb'
111
112 INTEGER :: atom_i, atom_j, ewald_type, handle, i, ia, iac, iatom, ic, icol, ikind, img, &
113 irow, is, jatom, jkind, natom, natorb_a, natorb_b, nimg, nkind, nmat
114 INTEGER, ALLOCATABLE, DIMENSION(:) :: atom_of_kind, kind_of
115 INTEGER, DIMENSION(3) :: cellind, periodic
116 INTEGER, DIMENSION(:, :, :), POINTER :: cell_to_index
117 LOGICAL :: defined, do_ewald, do_gamma_stress, &
118 found, hb_sr_damp, use_virial
119 REAL(kind=dp) :: alpha, ddr, deth, dgam, dr, drm, drp, &
120 fi, ga, gb, gmat, gmij, hb_para, zeff
121 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: xgamma, zeffk
122 REAL(kind=dp), DIMENSION(0:3) :: eta_a, eta_b
123 REAL(kind=dp), DIMENSION(3) :: fij, rij
124 REAL(kind=dp), DIMENSION(:, :), POINTER :: dsblock, gmcharge, ksblock, pblock, &
125 sblock
126 REAL(kind=dp), DIMENSION(:, :, :), POINTER :: dsint
127 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
128 TYPE(atprop_type), POINTER :: atprop
129 TYPE(cell_type), POINTER :: cell
130 TYPE(dbcsr_iterator_type) :: iter
131 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: matrix_p, matrix_s
132 TYPE(dft_control_type), POINTER :: dft_control
133 TYPE(distribution_1d_type), POINTER :: local_particles
134 TYPE(ewald_environment_type), POINTER :: ewald_env
135 TYPE(ewald_pw_type), POINTER :: ewald_pw
136 TYPE(kpoint_type), POINTER :: kpoints
137 TYPE(mp_para_env_type), POINTER :: para_env
139 DIMENSION(:), POINTER :: nl_iterator
140 TYPE(neighbor_list_set_p_type), DIMENSION(:), &
141 POINTER :: n_list
142 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
143 TYPE(qs_dftb_atom_type), POINTER :: dftb_kind, dftb_kind_a, dftb_kind_b
144 TYPE(qs_dftb_pairpot_type), DIMENSION(:, :), &
145 POINTER :: dftb_potential
146 TYPE(qs_force_type), DIMENSION(:), POINTER :: force
147 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
148 TYPE(sap_int_type), DIMENSION(:), POINTER :: sap_int
149 TYPE(virial_type), POINTER :: virial
150
151 CALL timeset(routinen, handle)
152
153 NULLIFY (matrix_p, matrix_s, virial, atprop, dft_control)
154
155 use_virial = .false.
156
157 IF (calculate_forces) THEN
158 nmat = 4
159 ELSE
160 nmat = 1
161 END IF
162
163 CALL get_qs_env(qs_env, nkind=nkind, natom=natom)
164 ALLOCATE (gmcharge(natom, nmat))
165 gmcharge = 0._dp
166
167 CALL get_qs_env(qs_env, &
168 particle_set=particle_set, &
169 cell=cell, &
170 virial=virial, &
171 atprop=atprop, &
172 dft_control=dft_control, &
173 atomic_kind_set=atomic_kind_set, &
174 qs_kind_set=qs_kind_set, &
175 force=force, para_env=para_env)
176
177 IF (calculate_forces) THEN
178 use_virial = virial%pv_availability .AND. (.NOT. virial%pv_numer)
179 END IF
180
181 NULLIFY (dftb_potential)
182 CALL get_qs_env(qs_env=qs_env, dftb_potential=dftb_potential)
183 NULLIFY (n_list)
184 CALL get_qs_env(qs_env=qs_env, sab_orb=n_list)
185 CALL neighbor_list_iterator_create(nl_iterator, n_list)
186 DO WHILE (neighbor_list_iterate(nl_iterator) == 0)
187 CALL get_iterator_info(nl_iterator, ikind=ikind, jkind=jkind, &
188 iatom=iatom, jatom=jatom, r=rij, cell=cellind)
189
190 CALL get_qs_kind(qs_kind_set(ikind), dftb_parameter=dftb_kind_a)
191 CALL get_dftb_atom_param(dftb_kind_a, &
192 defined=defined, eta=eta_a, natorb=natorb_a)
193 IF (.NOT. defined .OR. natorb_a < 1) cycle
194 CALL get_qs_kind(qs_kind_set(jkind), dftb_parameter=dftb_kind_b)
195 CALL get_dftb_atom_param(dftb_kind_b, &
196 defined=defined, eta=eta_b, natorb=natorb_b)
197 IF (.NOT. defined .OR. natorb_b < 1) cycle
198
199 ! gamma matrix
200 hb_sr_damp = dft_control%qs_control%dftb_control%hb_sr_damp
201 IF (hb_sr_damp) THEN
202 ! short range correction enabled only when iatom XOR jatom are hydrogens
203 hb_sr_damp = is_hydrogen(particle_set(iatom)%atomic_kind) .NEQV. &
204 is_hydrogen(particle_set(jatom)%atomic_kind)
205 END IF
206 IF (hb_sr_damp) THEN
207 hb_para = dft_control%qs_control%dftb_control%hb_sr_para
208 ELSE
209 hb_para = 0.0_dp
210 END IF
211 ga = eta_a(0)
212 gb = eta_b(0)
213 dr = sqrt(sum(rij(:)**2))
214 gmat = gamma_rab_sr(dr, ga, gb, hb_para)
215 gmcharge(jatom, 1) = gmcharge(jatom, 1) + gmat*mcharge(iatom)
216 IF (iatom /= jatom) THEN
217 gmcharge(iatom, 1) = gmcharge(iatom, 1) + gmat*mcharge(jatom)
218 END IF
219 IF (calculate_forces .AND. (iatom /= jatom .OR. dr > 0.001_dp)) THEN
220 ddr = 0.1_dp*dftb_potential(ikind, jkind)%dgrd
221 drp = dr + ddr
222 drm = dr - ddr
223 dgam = 0.5_dp*(gamma_rab_sr(drp, ga, gb, hb_para) - gamma_rab_sr(drm, ga, gb, hb_para))/ddr
224 DO i = 1, 3
225 gmcharge(jatom, i + 1) = gmcharge(jatom, i + 1) - dgam*mcharge(iatom)*rij(i)/dr
226 IF (dr > 0.001_dp) THEN
227 gmcharge(iatom, i + 1) = gmcharge(iatom, i + 1) + dgam*mcharge(jatom)*rij(i)/dr
228 END IF
229 IF (use_virial) THEN
230 fij(i) = -mcharge(iatom)*mcharge(jatom)*dgam*rij(i)/dr
231 END IF
232 END DO
233 IF (use_virial) THEN
234 fi = 1.0_dp
235 IF (iatom == jatom) fi = 0.5_dp
236 CALL virial_pair_force(virial%pv_virial, fi, fij, rij)
237 END IF
238 END IF
239 END DO
240 CALL neighbor_list_iterator_release(nl_iterator)
241
242 IF (atprop%energy) THEN
243 CALL get_qs_env(qs_env=qs_env, particle_set=particle_set)
244 natom = SIZE(particle_set)
245 CALL atprop_array_init(atprop%atecoul, natom)
246 END IF
247
248 ! 1/R contribution
249 do_ewald = dft_control%qs_control%dftb_control%do_ewald
250 IF (do_ewald) THEN
251 ! Ewald sum
252 NULLIFY (ewald_env, ewald_pw)
253 CALL get_qs_env(qs_env=qs_env, &
254 ewald_env=ewald_env, ewald_pw=ewald_pw)
255 CALL get_cell(cell=cell, periodic=periodic, deth=deth)
256 CALL ewald_env_get(ewald_env, alpha=alpha, ewald_type=ewald_type)
257 CALL get_qs_env(qs_env=qs_env, sab_tbe=n_list)
258 CALL tb_ewald_overlap(gmcharge, mcharge, alpha, n_list, virial, use_virial)
259 SELECT CASE (ewald_type)
260 CASE DEFAULT
261 cpabort("Invalid Ewald type")
262 CASE (do_ewald_none)
263 cpabort("Not allowed with DFTB")
264 CASE (do_ewald_ewald)
265 cpabort("Standard Ewald not implemented in DFTB")
266 CASE (do_ewald_pme)
267 cpabort("PME not implemented in DFTB")
268 CASE (do_ewald_spme)
269 CALL tb_spme_evaluate(ewald_env, ewald_pw, particle_set, cell, &
270 gmcharge, mcharge, calculate_forces, virial, use_virial)
271 END SELECT
272 ELSE
273 ! direct sum
274 CALL get_qs_env(qs_env=qs_env, &
275 local_particles=local_particles)
276 DO ikind = 1, SIZE(local_particles%n_el)
277 DO ia = 1, local_particles%n_el(ikind)
278 iatom = local_particles%list(ikind)%array(ia)
279 DO jatom = 1, iatom - 1
280 rij = particle_set(iatom)%r - particle_set(jatom)%r
281 rij = pbc(rij, cell)
282 dr = sqrt(sum(rij(:)**2))
283 gmcharge(iatom, 1) = gmcharge(iatom, 1) + mcharge(jatom)/dr
284 gmcharge(jatom, 1) = gmcharge(jatom, 1) + mcharge(iatom)/dr
285 DO i = 2, nmat
286 gmcharge(iatom, i) = gmcharge(iatom, i) + rij(i - 1)*mcharge(jatom)/dr**3
287 gmcharge(jatom, i) = gmcharge(jatom, i) - rij(i - 1)*mcharge(iatom)/dr**3
288 END DO
289 END DO
290 END DO
291 END DO
292 cpassert(.NOT. use_virial)
293 END IF
294
295 CALL para_env%sum(gmcharge(:, 1))
296
297 IF (do_ewald) THEN
298 ! add self charge interaction and background charge contribution
299 gmcharge(:, 1) = gmcharge(:, 1) - 2._dp*alpha*oorootpi*mcharge(:)
300 IF (any(periodic(:) == 1)) THEN
301 gmcharge(:, 1) = gmcharge(:, 1) - pi/alpha**2/deth
302 END IF
303 END IF
304
305 energy%hartree = energy%hartree + 0.5_dp*sum(mcharge(:)*gmcharge(:, 1))
306 IF (atprop%energy) THEN
307 CALL get_qs_env(qs_env=qs_env, &
308 local_particles=local_particles)
309 DO ikind = 1, SIZE(local_particles%n_el)
310 CALL get_qs_kind(qs_kind_set(ikind), dftb_parameter=dftb_kind)
311 CALL get_dftb_atom_param(dftb_kind, zeff=zeff)
312 DO ia = 1, local_particles%n_el(ikind)
313 iatom = local_particles%list(ikind)%array(ia)
314 atprop%atecoul(iatom) = atprop%atecoul(iatom) + &
315 0.5_dp*zeff*gmcharge(iatom, 1)
316 END DO
317 END DO
318 END IF
319
320 IF (calculate_forces) THEN
321 CALL get_atomic_kind_set(atomic_kind_set=atomic_kind_set, &
322 kind_of=kind_of, &
323 atom_of_kind=atom_of_kind)
324
325 gmcharge(:, 2) = gmcharge(:, 2)*mcharge(:)
326 gmcharge(:, 3) = gmcharge(:, 3)*mcharge(:)
327 gmcharge(:, 4) = gmcharge(:, 4)*mcharge(:)
328 DO iatom = 1, natom
329 ikind = kind_of(iatom)
330 atom_i = atom_of_kind(iatom)
331 force(ikind)%rho_elec(1, atom_i) = force(ikind)%rho_elec(1, atom_i) - gmcharge(iatom, 2)
332 force(ikind)%rho_elec(2, atom_i) = force(ikind)%rho_elec(2, atom_i) - gmcharge(iatom, 3)
333 force(ikind)%rho_elec(3, atom_i) = force(ikind)%rho_elec(3, atom_i) - gmcharge(iatom, 4)
334 END DO
335 END IF
336
337 do_gamma_stress = .false.
338 IF (.NOT. just_energy .AND. use_virial) THEN
339 IF (dft_control%nimages == 1) do_gamma_stress = .true.
340 END IF
341
342 IF (.NOT. just_energy) THEN
343 CALL get_qs_env(qs_env=qs_env, matrix_s_kp=matrix_s)
344 CALL qs_rho_get(rho, rho_ao_kp=matrix_p)
345
346 nimg = dft_control%nimages
347 NULLIFY (cell_to_index)
348 IF (nimg > 1) THEN
349 NULLIFY (kpoints)
350 CALL get_qs_env(qs_env=qs_env, kpoints=kpoints)
351 CALL get_kpoint_info(kpoint=kpoints, cell_to_index=cell_to_index)
352 END IF
353
354 IF (calculate_forces .AND. SIZE(matrix_p, 1) == 2) THEN
355 DO img = 1, nimg
356 CALL dbcsr_add(matrix_p(1, img)%matrix, matrix_p(2, img)%matrix, &
357 alpha_scalar=1.0_dp, beta_scalar=1.0_dp)
358 END DO
359 END IF
360
361 NULLIFY (sap_int)
362 IF (do_gamma_stress) THEN
363 ! derivative overlap integral (non collapsed)
364 CALL dftb_dsint_list(qs_env, sap_int)
365 END IF
366
367 IF (nimg == 1) THEN
368 ! no k-points; all matrices have been transformed to periodic bsf
369 CALL dbcsr_iterator_start(iter, matrix_s(1, 1)%matrix)
370 DO WHILE (dbcsr_iterator_blocks_left(iter))
371 CALL dbcsr_iterator_next_block(iter, irow, icol, sblock)
372 gmij = 0.5_dp*(gmcharge(irow, 1) + gmcharge(icol, 1))
373 DO is = 1, SIZE(ks_matrix, 1)
374 NULLIFY (ksblock)
375 CALL dbcsr_get_block_p(matrix=ks_matrix(is, 1)%matrix, &
376 row=irow, col=icol, block=ksblock, found=found)
377 cpassert(found)
378 ksblock = ksblock - gmij*sblock
379 END DO
380 IF (calculate_forces) THEN
381 ikind = kind_of(irow)
382 atom_i = atom_of_kind(irow)
383 jkind = kind_of(icol)
384 atom_j = atom_of_kind(icol)
385 NULLIFY (pblock)
386 CALL dbcsr_get_block_p(matrix=matrix_p(1, 1)%matrix, &
387 row=irow, col=icol, block=pblock, found=found)
388 cpassert(found)
389 DO i = 1, 3
390 NULLIFY (dsblock)
391 CALL dbcsr_get_block_p(matrix=matrix_s(1 + i, 1)%matrix, &
392 row=irow, col=icol, block=dsblock, found=found)
393 cpassert(found)
394 fi = -2.0_dp*gmij*sum(pblock*dsblock)
395 force(ikind)%rho_elec(i, atom_i) = force(ikind)%rho_elec(i, atom_i) + fi
396 force(jkind)%rho_elec(i, atom_j) = force(jkind)%rho_elec(i, atom_j) - fi
397 fij(i) = fi
398 END DO
399 END IF
400 END DO
401 CALL dbcsr_iterator_stop(iter)
402 !
403 IF (do_gamma_stress) THEN
404 DO ikind = 1, nkind
405 DO jkind = 1, nkind
406 iac = ikind + nkind*(jkind - 1)
407 IF (.NOT. ASSOCIATED(sap_int(iac)%alist)) cycle
408 DO ia = 1, sap_int(iac)%nalist
409 IF (.NOT. ASSOCIATED(sap_int(iac)%alist(ia)%clist)) cycle
410 iatom = sap_int(iac)%alist(ia)%aatom
411 DO ic = 1, sap_int(iac)%alist(ia)%nclist
412 jatom = sap_int(iac)%alist(ia)%clist(ic)%catom
413 rij = sap_int(iac)%alist(ia)%clist(ic)%rac
414 dr = sqrt(sum(rij(:)**2))
415 IF (dr > 1.e-6_dp) THEN
416 dsint => sap_int(iac)%alist(ia)%clist(ic)%acint
417 gmij = 0.5_dp*(gmcharge(iatom, 1) + gmcharge(jatom, 1))
418 icol = max(iatom, jatom)
419 irow = min(iatom, jatom)
420 NULLIFY (pblock)
421 CALL dbcsr_get_block_p(matrix=matrix_p(1, 1)%matrix, &
422 row=irow, col=icol, block=pblock, found=found)
423 cpassert(found)
424 DO i = 1, 3
425 IF (irow == iatom) THEN
426 fij(i) = -2.0_dp*gmij*sum(pblock*dsint(:, :, i))
427 ELSE
428 fij(i) = -2.0_dp*gmij*sum(transpose(pblock)*dsint(:, :, i))
429 END IF
430 END DO
431 fi = 1.0_dp
432 IF (iatom == jatom) fi = 0.5_dp
433 CALL virial_pair_force(virial%pv_virial, fi, fij, rij)
434 END IF
435 END DO
436 END DO
437 END DO
438 END DO
439 END IF
440 ELSE
441 NULLIFY (n_list)
442 CALL get_qs_env(qs_env=qs_env, sab_orb=n_list)
443 CALL neighbor_list_iterator_create(nl_iterator, n_list)
444 DO WHILE (neighbor_list_iterate(nl_iterator) == 0)
445 CALL get_iterator_info(nl_iterator, ikind=ikind, jkind=jkind, &
446 iatom=iatom, jatom=jatom, r=rij, cell=cellind)
447
448 icol = max(iatom, jatom)
449 irow = min(iatom, jatom)
450 ic = cell_to_index(cellind(1), cellind(2), cellind(3))
451 cpassert(ic > 0)
452
453 gmij = 0.5_dp*(gmcharge(iatom, 1) + gmcharge(jatom, 1))
454
455 NULLIFY (sblock)
456 CALL dbcsr_get_block_p(matrix=matrix_s(1, ic)%matrix, &
457 row=irow, col=icol, block=sblock, found=found)
458 cpassert(found)
459 DO is = 1, SIZE(ks_matrix, 1)
460 NULLIFY (ksblock)
461 CALL dbcsr_get_block_p(matrix=ks_matrix(is, ic)%matrix, &
462 row=irow, col=icol, block=ksblock, found=found)
463 cpassert(found)
464 ksblock = ksblock - gmij*sblock
465 END DO
466
467 IF (calculate_forces) THEN
468 ikind = kind_of(iatom)
469 atom_i = atom_of_kind(iatom)
470 jkind = kind_of(jatom)
471 atom_j = atom_of_kind(jatom)
472 IF (irow == jatom) gmij = -gmij
473 NULLIFY (pblock)
474 CALL dbcsr_get_block_p(matrix=matrix_p(1, ic)%matrix, &
475 row=irow, col=icol, block=pblock, found=found)
476 cpassert(found)
477 DO i = 1, 3
478 NULLIFY (dsblock)
479 CALL dbcsr_get_block_p(matrix=matrix_s(1 + i, ic)%matrix, &
480 row=irow, col=icol, block=dsblock, found=found)
481 cpassert(found)
482 fi = -2.0_dp*gmij*sum(pblock*dsblock)
483 force(ikind)%rho_elec(i, atom_i) = force(ikind)%rho_elec(i, atom_i) + fi
484 force(jkind)%rho_elec(i, atom_j) = force(jkind)%rho_elec(i, atom_j) - fi
485 fij(i) = fi
486 END DO
487 IF (use_virial) THEN
488 fi = 1.0_dp
489 IF (iatom == jatom) fi = 0.5_dp
490 CALL virial_pair_force(virial%pv_virial, fi, fij, rij)
491 END IF
492 END IF
493 END DO
494 CALL neighbor_list_iterator_release(nl_iterator)
495 END IF
496
497 IF (calculate_forces .AND. SIZE(matrix_p, 1) == 2) THEN
498 DO img = 1, nimg
499 CALL dbcsr_add(matrix_p(1, img)%matrix, matrix_p(2, img)%matrix, &
500 alpha_scalar=1.0_dp, beta_scalar=-1.0_dp)
501 END DO
502 END IF
503 END IF
504
505 IF (dft_control%qs_control%dftb_control%dftb3_diagonal) THEN
506 CALL get_qs_env(qs_env, nkind=nkind)
507 ALLOCATE (zeffk(nkind), xgamma(nkind))
508 DO ikind = 1, nkind
509 CALL get_qs_kind(qs_kind_set(ikind), dftb_parameter=dftb_kind)
510 CALL get_dftb_atom_param(dftb_kind, dudq=xgamma(ikind), zeff=zeffk(ikind))
511 END DO
512 ! Diagonal 3rd order correction (DFTB3)
513 CALL build_dftb3_diagonal(qs_env, ks_matrix, rho, mcharge, energy, xgamma, zeffk, &
514 sap_int, calculate_forces, just_energy)
515 DEALLOCATE (zeffk, xgamma)
516 END IF
517
518 ! QMMM
519 IF (qs_env%qmmm .AND. qs_env%qmmm_periodic) THEN
520 CALL build_tb_coulomb_qmqm(qs_env, ks_matrix, rho, mcharge, energy, &
521 calculate_forces, just_energy)
522 END IF
523
524 IF (do_gamma_stress) THEN
525 CALL release_sap_int(sap_int)
526 END IF
527
528 DEALLOCATE (gmcharge)
529
530 CALL timestop(handle)
531
532 END SUBROUTINE build_dftb_coulomb
533
534! **************************************************************************************************
535!> \brief Computes the short-range gamma parameter from exact Coulomb
536!> interaction of normalized exp(-a*r) charge distribution - 1/r
537!> \param r ...
538!> \param ga ...
539!> \param gb ...
540!> \param hb_para ...
541!> \return ...
542!> \par Literature
543!> Elstner et al, PRB 58 (1998) 7260
544!> \par History
545!> 10.2008 Axel Kohlmeyer - adding sr_damp
546!> 08.2014 JGH - adding flexible exponent for damping
547!> \version 1.1
548! **************************************************************************************************
549 FUNCTION gamma_rab_sr(r, ga, gb, hb_para) RESULT(gamma)
550 REAL(dp), INTENT(in) :: r, ga, gb, hb_para
551 REAL(dp) :: gamma
552
553 REAL(dp) :: a, b, fac, g_sum
554
555 gamma = 0.0_dp
556 a = 3.2_dp*ga ! 3.2 = 16/5 in Eq. 18 and ff.
557 b = 3.2_dp*gb
558 g_sum = a + b
559 IF (g_sum < tol_gamma) RETURN ! hardness screening
560 IF (r < rtiny) THEN ! This is for short distances but non-onsite terms
561 ! This gives also correct diagonal elements (a=b, r=0)
562 gamma = 0.5_dp*(a*b/g_sum + (a*b)**2/g_sum**3)
563 RETURN
564 END IF
565 !
566 ! distinguish two cases: Gamma's are very close, e.g. for the same atom type,
567 ! and Gamma's are different
568 !
569 IF (abs(a - b) < rtiny) THEN
570 fac = 1.6_dp*r*a*b/g_sum*(1.0_dp + a*b/g_sum**2)
571 gamma = -(48.0_dp + 33._dp*fac + (9.0_dp + fac)*fac**2)*exp(-fac)/(48._dp*r)
572 ELSE
573 gamma = -exp(-a*r)*(0.5_dp*a*b**4/(a**2 - b**2)**2 - &
574 (b**6 - 3._dp*a**2*b**4)/(r*(a**2 - b**2)**3)) - & ! a-> b
575 exp(-b*r)*(0.5_dp*b*a**4/(b**2 - a**2)**2 - &
576 (a**6 - 3._dp*b**2*a**4)/(r*(b**2 - a**2)**3)) ! b-> a
577 END IF
578 !
579 ! damping function for better short range hydrogen bonds.
580 ! functional form from Hu H. et al., J. Phys. Chem. A 2007, 111, 5685-5691
581 ! according to Elstner M, Theor. Chem. Acc. 2006, 116, 316-325,
582 ! this should only be applied to a-b pairs involving hydrogen.
583 IF (hb_para > 0.0_dp) THEN
584 gamma = gamma*exp(-(0.5_dp*(ga + gb))**hb_para*r*r)
585 END IF
586 END FUNCTION gamma_rab_sr
587
588! **************************************************************************************************
589!> \brief ...
590!> \param qs_env ...
591!> \param sap_int ...
592! **************************************************************************************************
593 SUBROUTINE dftb_dsint_list(qs_env, sap_int)
594
595 TYPE(qs_environment_type), POINTER :: qs_env
596 TYPE(sap_int_type), DIMENSION(:), POINTER :: sap_int
597
598 CHARACTER(LEN=*), PARAMETER :: routinen = 'dftb_dsint_list'
599
600 INTEGER :: handle, i, iac, iatom, ikind, ilist, jatom, jkind, jneighbor, llm, lmaxi, lmaxj, &
601 n1, n2, natorb_a, natorb_b, ngrd, ngrdcut, nkind, nlist, nneighbor
602 INTEGER, DIMENSION(3) :: cell
603 LOGICAL :: defined
604 REAL(kind=dp) :: ddr, dgrd, dr
605 REAL(kind=dp), DIMENSION(3) :: drij, rij
606 REAL(kind=dp), DIMENSION(:, :), POINTER :: dsblock, dsblockm, smatij, smatji
607 TYPE(clist_type), POINTER :: clist
608 TYPE(dft_control_type), POINTER :: dft_control
609 TYPE(dftb_control_type), POINTER :: dftb_control
611 DIMENSION(:), POINTER :: nl_iterator
612 TYPE(neighbor_list_set_p_type), DIMENSION(:), &
613 POINTER :: sab_orb
614 TYPE(qs_dftb_atom_type), POINTER :: dftb_kind_a, dftb_kind_b
615 TYPE(qs_dftb_pairpot_type), DIMENSION(:, :), &
616 POINTER :: dftb_potential
617 TYPE(qs_dftb_pairpot_type), POINTER :: dftb_param_ij, dftb_param_ji
618 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
619
620 CALL timeset(routinen, handle)
621
622 CALL get_qs_env(qs_env=qs_env, nkind=nkind)
623 cpassert(.NOT. ASSOCIATED(sap_int))
624 ALLOCATE (sap_int(nkind*nkind))
625 DO i = 1, nkind*nkind
626 NULLIFY (sap_int(i)%alist, sap_int(i)%asort, sap_int(i)%aindex)
627 sap_int(i)%nalist = 0
628 END DO
629
630 CALL get_qs_env(qs_env=qs_env, &
631 qs_kind_set=qs_kind_set, &
632 dft_control=dft_control, &
633 sab_orb=sab_orb)
634
635 dftb_control => dft_control%qs_control%dftb_control
636
637 NULLIFY (dftb_potential)
638 CALL get_qs_env(qs_env=qs_env, &
639 dftb_potential=dftb_potential)
640
641 ! loop over all atom pairs with a non-zero overlap (sab_orb)
642 CALL neighbor_list_iterator_create(nl_iterator, sab_orb)
643 DO WHILE (neighbor_list_iterate(nl_iterator) == 0)
644 CALL get_iterator_info(nl_iterator, ikind=ikind, jkind=jkind, iatom=iatom, &
645 jatom=jatom, nlist=nlist, ilist=ilist, nnode=nneighbor, &
646 inode=jneighbor, cell=cell, r=rij)
647 iac = ikind + nkind*(jkind - 1)
648 !
649 CALL get_qs_kind(qs_kind_set(ikind), dftb_parameter=dftb_kind_a)
650 CALL get_dftb_atom_param(dftb_kind_a, &
651 defined=defined, lmax=lmaxi, natorb=natorb_a)
652 IF (.NOT. defined .OR. natorb_a < 1) cycle
653 CALL get_qs_kind(qs_kind_set(jkind), dftb_parameter=dftb_kind_b)
654 CALL get_dftb_atom_param(dftb_kind_b, &
655 defined=defined, lmax=lmaxj, natorb=natorb_b)
656 IF (.NOT. defined .OR. natorb_b < 1) cycle
657
658 dr = sqrt(sum(rij(:)**2))
659
660 ! integral list
661 IF (.NOT. ASSOCIATED(sap_int(iac)%alist)) THEN
662 sap_int(iac)%a_kind = ikind
663 sap_int(iac)%p_kind = jkind
664 sap_int(iac)%nalist = nlist
665 ALLOCATE (sap_int(iac)%alist(nlist))
666 DO i = 1, nlist
667 NULLIFY (sap_int(iac)%alist(i)%clist)
668 sap_int(iac)%alist(i)%aatom = 0
669 sap_int(iac)%alist(i)%nclist = 0
670 END DO
671 END IF
672 IF (.NOT. ASSOCIATED(sap_int(iac)%alist(ilist)%clist)) THEN
673 sap_int(iac)%alist(ilist)%aatom = iatom
674 sap_int(iac)%alist(ilist)%nclist = nneighbor
675 ALLOCATE (sap_int(iac)%alist(ilist)%clist(nneighbor))
676 DO i = 1, nneighbor
677 sap_int(iac)%alist(ilist)%clist(i)%catom = 0
678 END DO
679 END IF
680 clist => sap_int(iac)%alist(ilist)%clist(jneighbor)
681 clist%catom = jatom
682 clist%cell = cell
683 clist%rac = rij
684 ALLOCATE (clist%acint(natorb_a, natorb_b, 3))
685 NULLIFY (clist%achint)
686 clist%acint = 0._dp
687 clist%nsgf_cnt = 0
688 NULLIFY (clist%sgf_list)
689
690 ! retrieve information on S matrix
691 dftb_param_ij => dftb_potential(ikind, jkind)
692 dftb_param_ji => dftb_potential(jkind, ikind)
693 ! assume table size and type is symmetric
694 ngrd = dftb_param_ij%ngrd
695 ngrdcut = dftb_param_ij%ngrdcut
696 dgrd = dftb_param_ij%dgrd
697 ddr = dgrd*0.1_dp
698 cpassert(dftb_param_ij%llm == dftb_param_ji%llm)
699 llm = dftb_param_ij%llm
700 smatij => dftb_param_ij%smat
701 smatji => dftb_param_ji%smat
702
703 IF (nint(dr/dgrd) <= ngrdcut) THEN
704 IF (iatom == jatom .AND. dr < 0.001_dp) THEN
705 ! diagonal block
706 ELSE
707 ! off-diagonal block
708 n1 = natorb_a
709 n2 = natorb_b
710 ALLOCATE (dsblock(n1, n2), dsblockm(n1, n2))
711 DO i = 1, 3
712 dsblock = 0._dp
713 dsblockm = 0.0_dp
714 drij = rij
715
716 drij(i) = rij(i) - ddr
717 CALL compute_block_sk(dsblockm, smatij, smatji, drij, ngrd, ngrdcut, dgrd, &
718 llm, lmaxi, lmaxj, iatom, iatom)
719
720 drij(i) = rij(i) + ddr
721 CALL compute_block_sk(dsblock, smatij, smatji, drij, ngrd, ngrdcut, dgrd, &
722 llm, lmaxi, lmaxj, iatom, iatom)
723
724 dsblock = dsblock - dsblockm
725 dsblock = dsblock/(2.0_dp*ddr)
726
727 clist%acint(1:n1, 1:n2, i) = -dsblock(1:n1, 1:n2)
728 END DO
729 DEALLOCATE (dsblock, dsblockm)
730 END IF
731 END IF
732
733 END DO
734 CALL neighbor_list_iterator_release(nl_iterator)
735
736 CALL timestop(handle)
737
738 END SUBROUTINE dftb_dsint_list
739
740END MODULE qs_dftb_coulomb
741
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:195
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
subroutine, public dbcsr_iterator_next_block(iterator, row, column, block, block_number_argument_has_been_removed, row_size, col_size, row_offset, col_offset)
...
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_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)
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, 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)
...
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:55
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.