(git:50ddb19)
Loading...
Searching...
No Matches
xtb_ehess_force.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 forces for Coulomb contributions in response xTB
10!> \author JGH
11! **************************************************************************************************
15 USE cell_types, ONLY: cell_type,&
16 get_cell,&
17 pbc
20 USE cp_dbcsr_api, ONLY: &
32 USE kinds, ONLY: dp
33 USE mathconstants, ONLY: oorootpi,&
34 pi
45 USE qs_kind_types, ONLY: get_qs_kind,&
53 USE qs_rho_types, ONLY: qs_rho_type
54 USE virial_types, ONLY: virial_type
55 USE xtb_coulomb, ONLY: dgamma_rab_sr,&
58 USE xtb_types, ONLY: get_xtb_atom_param,&
60#include "./base/base_uses.f90"
61
62 IMPLICIT NONE
63
64 PRIVATE
65
66 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'xtb_ehess_force'
67
68 PUBLIC :: calc_xtb_ehess_force
69
70! **************************************************************************************************
71
72CONTAINS
73
74! **************************************************************************************************
75!> \brief ...
76!> \param qs_env ...
77!> \param matrix_p0 ...
78!> \param matrix_p1 ...
79!> \param charges0 ...
80!> \param mcharge0 ...
81!> \param charges1 ...
82!> \param mcharge1 ...
83!> \param debug_forces ...
84! **************************************************************************************************
85 SUBROUTINE calc_xtb_ehess_force(qs_env, matrix_p0, matrix_p1, charges0, mcharge0, &
86 charges1, mcharge1, debug_forces)
87
88 TYPE(qs_environment_type), POINTER :: qs_env
89 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_p0, matrix_p1
90 REAL(kind=dp), DIMENSION(:, :), INTENT(in) :: charges0
91 REAL(kind=dp), DIMENSION(:), INTENT(in) :: mcharge0
92 REAL(kind=dp), DIMENSION(:, :), INTENT(in) :: charges1
93 REAL(kind=dp), DIMENSION(:), INTENT(in) :: mcharge1
94 LOGICAL, INTENT(IN) :: debug_forces
95
96 CHARACTER(len=*), PARAMETER :: routinen = 'calc_xtb_ehess_force'
97
98 INTEGER :: atom_i, atom_j, ewald_type, handle, i, ia, iatom, icol, ikind, iounit, irow, j, &
99 jatom, jkind, la, lb, lmaxa, lmaxb, natom, natorb_a, natorb_b, ni, nimg, nj, nkind, nmat, &
100 za, zb
101 INTEGER, ALLOCATABLE, DIMENSION(:) :: atom_of_kind, kind_of
102 INTEGER, DIMENSION(25) :: laoa, laob
103 INTEGER, DIMENSION(3) :: cellind, periodic
104 LOGICAL :: calculate_forces, defined, do_ewald, &
105 found, just_energy, use_virial
106 REAL(kind=dp) :: alpha, deth, dr, etaa, etab, fi, gmij0, &
107 gmij1, kg, rcut, rcuta, rcutb
108 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: xgamma
109 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :) :: gammab, gcij0, gcij1, gmcharge0, &
110 gmcharge1
111 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :, :) :: gchrg0, gchrg1
112 REAL(kind=dp), DIMENSION(3) :: fij, fodeb, rij
113 REAL(kind=dp), DIMENSION(5) :: kappaa, kappab
114 REAL(kind=dp), DIMENSION(:, :), POINTER :: dsblock, pblock0, pblock1, sblock
115 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
116 TYPE(cell_type), POINTER :: cell
117 TYPE(cp_logger_type), POINTER :: logger
118 TYPE(dbcsr_iterator_type) :: iter
119 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: matrix_s
120 TYPE(dft_control_type), POINTER :: dft_control
121 TYPE(distribution_1d_type), POINTER :: local_particles
122 TYPE(ewald_environment_type), POINTER :: ewald_env
123 TYPE(ewald_pw_type), POINTER :: ewald_pw
124 TYPE(mp_para_env_type), POINTER :: para_env
126 DIMENSION(:), POINTER :: nl_iterator
127 TYPE(neighbor_list_set_p_type), DIMENSION(:), &
128 POINTER :: n_list
129 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
130 TYPE(qs_energy_type), POINTER :: energy
131 TYPE(qs_force_type), DIMENSION(:), POINTER :: force
132 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
133 TYPE(qs_rho_type), POINTER :: rho
134 TYPE(virial_type), POINTER :: virial
135 TYPE(xtb_atom_type), POINTER :: xtb_atom_a, xtb_atom_b, xtb_kind
136 TYPE(xtb_control_type), POINTER :: xtb_control
137
138 CALL timeset(routinen, handle)
139
140 logger => cp_get_default_logger()
141 IF (logger%para_env%is_source()) THEN
142 iounit = cp_logger_get_default_unit_nr(logger, local=.true.)
143 ELSE
144 iounit = -1
145 END IF
146
147 cpassert(ASSOCIATED(matrix_p1))
148
149 CALL get_qs_env(qs_env, &
150 qs_kind_set=qs_kind_set, &
151 particle_set=particle_set, &
152 cell=cell, &
153 rho=rho, &
154 energy=energy, &
155 virial=virial, &
156 dft_control=dft_control)
157
158 xtb_control => dft_control%qs_control%xtb_control
159
160 calculate_forces = .true.
161 just_energy = .false.
162 use_virial = .false.
163 nmat = 4
164 nimg = dft_control%nimages
165 IF (nimg > 1) THEN
166 cpabort('xTB-sTDA forces for k-points not available')
167 END IF
168
169 CALL get_qs_env(qs_env, nkind=nkind, natom=natom)
170 ALLOCATE (gchrg0(natom, 5, nmat))
171 gchrg0 = 0._dp
172 ALLOCATE (gmcharge0(natom, nmat))
173 gmcharge0 = 0._dp
174 ALLOCATE (gchrg1(natom, 5, nmat))
175 gchrg1 = 0._dp
176 ALLOCATE (gmcharge1(natom, nmat))
177 gmcharge1 = 0._dp
178
179 ! short range contribution (gamma)
180 ! loop over all atom pairs (sab_xtbe)
181 kg = xtb_control%kg
182 NULLIFY (n_list)
183 CALL get_qs_env(qs_env=qs_env, sab_xtbe=n_list)
184 CALL neighbor_list_iterator_create(nl_iterator, n_list)
185 DO WHILE (neighbor_list_iterate(nl_iterator) == 0)
186 CALL get_iterator_info(nl_iterator, ikind=ikind, jkind=jkind, &
187 iatom=iatom, jatom=jatom, r=rij, cell=cellind)
188 CALL get_qs_kind(qs_kind_set(ikind), xtb_parameter=xtb_atom_a)
189 CALL get_xtb_atom_param(xtb_atom_a, defined=defined, natorb=natorb_a)
190 IF (.NOT. defined .OR. natorb_a < 1) cycle
191 CALL get_qs_kind(qs_kind_set(jkind), xtb_parameter=xtb_atom_b)
192 CALL get_xtb_atom_param(xtb_atom_b, defined=defined, natorb=natorb_b)
193 IF (.NOT. defined .OR. natorb_b < 1) cycle
194 ! atomic parameters
195 CALL get_xtb_atom_param(xtb_atom_a, eta=etaa, lmax=lmaxa, kappa=kappaa, rcut=rcuta)
196 CALL get_xtb_atom_param(xtb_atom_b, eta=etab, lmax=lmaxb, kappa=kappab, rcut=rcutb)
197 ! gamma matrix
198 ni = lmaxa + 1
199 nj = lmaxb + 1
200 ALLOCATE (gammab(ni, nj))
201 rcut = rcuta + rcutb
202 dr = sqrt(sum(rij(:)**2))
203 CALL gamma_rab_sr(gammab, dr, ni, kappaa, etaa, nj, kappab, etab, kg, rcut)
204 gchrg0(iatom, 1:ni, 1) = gchrg0(iatom, 1:ni, 1) + matmul(gammab, charges0(jatom, 1:nj))
205 gchrg1(iatom, 1:ni, 1) = gchrg1(iatom, 1:ni, 1) + matmul(gammab, charges1(jatom, 1:nj))
206 IF (iatom /= jatom) THEN
207 gchrg0(jatom, 1:nj, 1) = gchrg0(jatom, 1:nj, 1) + matmul(charges0(iatom, 1:ni), gammab)
208 gchrg1(jatom, 1:nj, 1) = gchrg1(jatom, 1:nj, 1) + matmul(charges1(iatom, 1:ni), gammab)
209 END IF
210 IF (dr > 1.e-6_dp) THEN
211 CALL dgamma_rab_sr(gammab, dr, ni, kappaa, etaa, nj, kappab, etab, kg, rcut)
212 DO i = 1, 3
213 gchrg0(iatom, 1:ni, i + 1) = gchrg0(iatom, 1:ni, i + 1) &
214 + matmul(gammab, charges0(jatom, 1:nj))*rij(i)/dr
215 gchrg1(iatom, 1:ni, i + 1) = gchrg1(iatom, 1:ni, i + 1) &
216 + matmul(gammab, charges1(jatom, 1:nj))*rij(i)/dr
217 IF (iatom /= jatom) THEN
218 gchrg0(jatom, 1:nj, i + 1) = gchrg0(jatom, 1:nj, i + 1) &
219 - matmul(charges0(iatom, 1:ni), gammab)*rij(i)/dr
220 gchrg1(jatom, 1:nj, i + 1) = gchrg1(jatom, 1:nj, i + 1) &
221 - matmul(charges1(iatom, 1:ni), gammab)*rij(i)/dr
222 END IF
223 END DO
224 END IF
225 DEALLOCATE (gammab)
226 END DO
227 CALL neighbor_list_iterator_release(nl_iterator)
228
229 ! 1/R contribution
230
231 IF (xtb_control%coulomb_lr) THEN
232 do_ewald = xtb_control%do_ewald
233 IF (do_ewald) THEN
234 ! Ewald sum
235 NULLIFY (ewald_env, ewald_pw)
236 CALL get_qs_env(qs_env=qs_env, &
237 ewald_env=ewald_env, ewald_pw=ewald_pw)
238 CALL get_cell(cell=cell, periodic=periodic, deth=deth)
239 CALL ewald_env_get(ewald_env, alpha=alpha, ewald_type=ewald_type)
240 CALL get_qs_env(qs_env=qs_env, sab_tbe=n_list)
241 CALL tb_ewald_overlap(gmcharge0, mcharge0, alpha, n_list, virial, use_virial)
242 CALL tb_ewald_overlap(gmcharge1, mcharge1, alpha, n_list, virial, use_virial)
243 SELECT CASE (ewald_type)
244 CASE DEFAULT
245 cpabort("Invalid Ewald type")
246 CASE (do_ewald_none)
247 cpabort("Not allowed with DFTB")
248 CASE (do_ewald_ewald)
249 cpabort("Standard Ewald not implemented in DFTB")
250 CASE (do_ewald_pme)
251 cpabort("PME not implemented in DFTB")
252 CASE (do_ewald_spme)
253 CALL tb_spme_zforce(ewald_env, ewald_pw, particle_set, cell, gmcharge0, mcharge0)
254 CALL tb_spme_zforce(ewald_env, ewald_pw, particle_set, cell, gmcharge1, mcharge1)
255 END SELECT
256 ELSE
257 ! direct sum
258 CALL get_qs_env(qs_env=qs_env, local_particles=local_particles)
259 DO ikind = 1, SIZE(local_particles%n_el)
260 DO ia = 1, local_particles%n_el(ikind)
261 iatom = local_particles%list(ikind)%array(ia)
262 DO jatom = 1, iatom - 1
263 rij = particle_set(iatom)%r - particle_set(jatom)%r
264 rij = pbc(rij, cell)
265 dr = sqrt(sum(rij(:)**2))
266 IF (dr > 1.e-6_dp) THEN
267 gmcharge0(iatom, 1) = gmcharge0(iatom, 1) + mcharge0(jatom)/dr
268 gmcharge0(jatom, 1) = gmcharge0(jatom, 1) + mcharge0(iatom)/dr
269 gmcharge1(iatom, 1) = gmcharge1(iatom, 1) + mcharge1(jatom)/dr
270 gmcharge1(jatom, 1) = gmcharge1(jatom, 1) + mcharge1(iatom)/dr
271 DO i = 2, nmat
272 gmcharge0(iatom, i) = gmcharge0(iatom, i) + rij(i - 1)*mcharge0(jatom)/dr**3
273 gmcharge0(jatom, i) = gmcharge0(jatom, i) - rij(i - 1)*mcharge0(iatom)/dr**3
274 gmcharge1(iatom, i) = gmcharge1(iatom, i) + rij(i - 1)*mcharge1(jatom)/dr**3
275 gmcharge1(jatom, i) = gmcharge1(jatom, i) - rij(i - 1)*mcharge1(iatom)/dr**3
276 END DO
277 END IF
278 END DO
279 END DO
280 END DO
281 cpassert(.NOT. use_virial)
282 END IF
283 END IF
284
285 ! global sum of gamma*p arrays
286 CALL get_qs_env(qs_env=qs_env, &
287 atomic_kind_set=atomic_kind_set, &
288 force=force, para_env=para_env)
289 CALL para_env%sum(gmcharge0(:, 1))
290 CALL para_env%sum(gchrg0(:, :, 1))
291 CALL para_env%sum(gmcharge1(:, 1))
292 CALL para_env%sum(gchrg1(:, :, 1))
293
294 IF (xtb_control%coulomb_lr) THEN
295 IF (do_ewald) THEN
296 ! add self charge interaction and background charge contribution
297 gmcharge0(:, 1) = gmcharge0(:, 1) - 2._dp*alpha*oorootpi*mcharge0(:)
298 IF (any(periodic(:) == 1)) THEN
299 gmcharge0(:, 1) = gmcharge0(:, 1) - pi/alpha**2/deth
300 END IF
301 gmcharge1(:, 1) = gmcharge1(:, 1) - 2._dp*alpha*oorootpi*mcharge1(:)
302 IF (any(periodic(:) == 1)) THEN
303 gmcharge1(:, 1) = gmcharge1(:, 1) - pi/alpha**2/deth
304 END IF
305 END IF
306 END IF
307
308 CALL get_atomic_kind_set(atomic_kind_set=atomic_kind_set, &
309 kind_of=kind_of, &
310 atom_of_kind=atom_of_kind)
311
312 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
313 DO iatom = 1, natom
314 ikind = kind_of(iatom)
315 atom_i = atom_of_kind(iatom)
316 CALL get_qs_kind(qs_kind_set(ikind), xtb_parameter=xtb_kind)
317 CALL get_xtb_atom_param(xtb_kind, lmax=ni)
318 ni = ni + 1
319 ! short range
320 fij = 0.0_dp
321 DO i = 1, 3
322 fij(i) = sum(charges0(iatom, 1:ni)*gchrg1(iatom, 1:ni, i + 1)) + &
323 sum(charges1(iatom, 1:ni)*gchrg0(iatom, 1:ni, i + 1))
324 END DO
325 force(ikind)%rho_elec(1, atom_i) = force(ikind)%rho_elec(1, atom_i) - fij(1)
326 force(ikind)%rho_elec(2, atom_i) = force(ikind)%rho_elec(2, atom_i) - fij(2)
327 force(ikind)%rho_elec(3, atom_i) = force(ikind)%rho_elec(3, atom_i) - fij(3)
328 ! long range
329 fij = 0.0_dp
330 DO i = 1, 3
331 fij(i) = gmcharge1(iatom, i + 1)*mcharge0(iatom) + &
332 gmcharge0(iatom, i + 1)*mcharge1(iatom)
333 END DO
334 force(ikind)%rho_elec(1, atom_i) = force(ikind)%rho_elec(1, atom_i) - fij(1)
335 force(ikind)%rho_elec(2, atom_i) = force(ikind)%rho_elec(2, atom_i) - fij(2)
336 force(ikind)%rho_elec(3, atom_i) = force(ikind)%rho_elec(3, atom_i) - fij(3)
337 END DO
338 IF (debug_forces) THEN
339 fodeb(1:3) = force(1)%rho_elec(1:3, 1) - fodeb(1:3)
340 CALL para_env%sum(fodeb)
341 IF (iounit > 0) WRITE (iounit, "(T3,A,T33,3F16.8)") "DEBUG:: P*dH[Pz] ", fodeb
342 END IF
343
344 CALL get_qs_env(qs_env=qs_env, matrix_s_kp=matrix_s)
345
346 IF (SIZE(matrix_p0) == 2) THEN
347 CALL dbcsr_add(matrix_p0(1)%matrix, matrix_p0(2)%matrix, &
348 alpha_scalar=1.0_dp, beta_scalar=1.0_dp)
349 CALL dbcsr_add(matrix_p1(1)%matrix, matrix_p1(2)%matrix, &
350 alpha_scalar=1.0_dp, beta_scalar=1.0_dp)
351 END IF
352
353 ! no k-points; all matrices have been transformed to periodic bsf
354 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
355 CALL dbcsr_iterator_start(iter, matrix_s(1, 1)%matrix)
356 DO WHILE (dbcsr_iterator_blocks_left(iter))
357 CALL dbcsr_iterator_next_block(iter, irow, icol, sblock)
358 ikind = kind_of(irow)
359 jkind = kind_of(icol)
360
361 ! atomic parameters
362 CALL get_qs_kind(qs_kind_set(ikind), xtb_parameter=xtb_atom_a)
363 CALL get_qs_kind(qs_kind_set(jkind), xtb_parameter=xtb_atom_b)
364 CALL get_xtb_atom_param(xtb_atom_a, z=za, lao=laoa)
365 CALL get_xtb_atom_param(xtb_atom_b, z=zb, lao=laob)
366
367 ni = SIZE(sblock, 1)
368 nj = SIZE(sblock, 2)
369 ALLOCATE (gcij0(ni, nj))
370 ALLOCATE (gcij1(ni, nj))
371 DO i = 1, ni
372 DO j = 1, nj
373 la = laoa(i) + 1
374 lb = laob(j) + 1
375 gcij0(i, j) = 0.5_dp*(gchrg0(irow, la, 1) + gchrg0(icol, lb, 1))
376 gcij1(i, j) = 0.5_dp*(gchrg1(irow, la, 1) + gchrg1(icol, lb, 1))
377 END DO
378 END DO
379 gmij0 = 0.5_dp*(gmcharge0(irow, 1) + gmcharge0(icol, 1))
380 gmij1 = 0.5_dp*(gmcharge1(irow, 1) + gmcharge1(icol, 1))
381 atom_i = atom_of_kind(irow)
382 atom_j = atom_of_kind(icol)
383 NULLIFY (pblock0)
384 CALL dbcsr_get_block_p(matrix=matrix_p0(1)%matrix, &
385 row=irow, col=icol, block=pblock0, found=found)
386 cpassert(found)
387 NULLIFY (pblock1)
388 CALL dbcsr_get_block_p(matrix=matrix_p1(1)%matrix, &
389 row=irow, col=icol, block=pblock1, found=found)
390 cpassert(found)
391 DO i = 1, 3
392 NULLIFY (dsblock)
393 CALL dbcsr_get_block_p(matrix=matrix_s(1 + i, 1)%matrix, &
394 row=irow, col=icol, block=dsblock, found=found)
395 cpassert(found)
396 ! short range
397 fi = -2.0_dp*sum(pblock0*dsblock*gcij1) - 2.0_dp*sum(pblock1*dsblock*gcij0)
398 force(ikind)%rho_elec(i, atom_i) = force(ikind)%rho_elec(i, atom_i) + fi
399 force(jkind)%rho_elec(i, atom_j) = force(jkind)%rho_elec(i, atom_j) - fi
400 ! long range
401 fi = -2.0_dp*gmij1*sum(pblock0*dsblock) - 2.0_dp*gmij0*sum(pblock1*dsblock)
402 force(ikind)%rho_elec(i, atom_i) = force(ikind)%rho_elec(i, atom_i) + fi
403 force(jkind)%rho_elec(i, atom_j) = force(jkind)%rho_elec(i, atom_j) - fi
404 END DO
405 DEALLOCATE (gcij0, gcij1)
406 END DO
407 CALL dbcsr_iterator_stop(iter)
408 IF (debug_forces) THEN
409 fodeb(1:3) = force(1)%rho_elec(1:3, 1) - fodeb(1:3)
410 CALL para_env%sum(fodeb)
411 IF (iounit > 0) WRITE (iounit, "(T3,A,T33,3F16.8)") "DEBUG:: Pz*H[P]*dS ", fodeb
412 END IF
413
414 IF (xtb_control%tb3_interaction) THEN
415 CALL get_qs_env(qs_env, nkind=nkind)
416 ALLOCATE (xgamma(nkind))
417 DO ikind = 1, nkind
418 CALL get_qs_kind(qs_kind_set(ikind), xtb_parameter=xtb_kind)
419 CALL get_xtb_atom_param(xtb_kind, xgamma=xgamma(ikind))
420 END DO
421 ! Diagonal 3rd order correction (DFTB3)
422 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
423 CALL dftb3_diagonal_hessian_force(qs_env, mcharge0, mcharge1, &
424 matrix_p0(1)%matrix, matrix_p1(1)%matrix, xgamma)
425 IF (debug_forces) THEN
426 fodeb(1:3) = force(1)%rho_elec(1:3, 1) - fodeb(1:3)
427 CALL para_env%sum(fodeb)
428 IF (iounit > 0) WRITE (iounit, "(T3,A,T33,3F16.8)") "DEBUG:: Pz*H3[P] ", fodeb
429 END IF
430 DEALLOCATE (xgamma)
431 END IF
432
433 IF (SIZE(matrix_p0) == 2) THEN
434 CALL dbcsr_add(matrix_p0(1)%matrix, matrix_p0(2)%matrix, &
435 alpha_scalar=1.0_dp, beta_scalar=-1.0_dp)
436 CALL dbcsr_add(matrix_p1(1)%matrix, matrix_p1(2)%matrix, &
437 alpha_scalar=1.0_dp, beta_scalar=-1.0_dp)
438 END IF
439
440 IF (xtb_control%do_spinpol) THEN
441 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
442 !
443 CALL xtb_spinpol_hforce(qs_env, matrix_p0, matrix_p1)
444 !
445 IF (debug_forces) THEN
446 fodeb(1:3) = force(1)%rho_elec(1:3, 1) - fodeb(1:3)
447 CALL para_env%sum(fodeb)
448 IF (iounit > 0) WRITE (iounit, "(T3,A,T33,3F16.8)") "DEBUG:: Pz*Hspin[P] ", fodeb
449 END IF
450 END IF
451
452 ! QMMM
453 IF (qs_env%qmmm .AND. qs_env%qmmm_periodic) THEN
454 cpabort("Not Available")
455 END IF
456
457 DEALLOCATE (gmcharge0, gchrg0, gmcharge1, gchrg1)
458
459 CALL timestop(handle)
460
461 END SUBROUTINE calc_xtb_ehess_force
462
463! **************************************************************************************************
464!> \brief ...
465!> \param qs_env ...
466!> \param mcharge0 ...
467!> \param mcharge1 ...
468!> \param matrixp0 ...
469!> \param matrixp1 ...
470!> \param xgamma ...
471! **************************************************************************************************
472 SUBROUTINE dftb3_diagonal_hessian_force(qs_env, mcharge0, mcharge1, &
473 matrixp0, matrixp1, xgamma)
474
475 TYPE(qs_environment_type), POINTER :: qs_env
476 REAL(dp), DIMENSION(:) :: mcharge0, mcharge1
477 TYPE(dbcsr_type), POINTER :: matrixp0, matrixp1
478 REAL(dp), DIMENSION(:) :: xgamma
479
480 CHARACTER(len=*), PARAMETER :: routinen = 'dftb3_diagonal_hessian_force'
481
482 INTEGER :: atom_i, atom_j, handle, i, icol, ikind, &
483 irow, jkind
484 INTEGER, ALLOCATABLE, DIMENSION(:) :: atom_of_kind, kind_of
485 LOGICAL :: found
486 REAL(kind=dp) :: fi, gmijp, gmijq, ui, uj
487 REAL(kind=dp), DIMENSION(:, :), POINTER :: dsblock, p0block, p1block, sblock
488 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
489 TYPE(dbcsr_iterator_type) :: iter
490 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_s
491 TYPE(qs_force_type), DIMENSION(:), POINTER :: force
492
493 CALL timeset(routinen, handle)
494 CALL get_qs_env(qs_env=qs_env, matrix_s=matrix_s)
495 CALL get_qs_env(qs_env=qs_env, atomic_kind_set=atomic_kind_set)
496 CALL get_atomic_kind_set(atomic_kind_set=atomic_kind_set, &
497 kind_of=kind_of, atom_of_kind=atom_of_kind)
498 CALL get_qs_env(qs_env=qs_env, force=force)
499 ! no k-points; all matrices have been transformed to periodic bsf
500 CALL dbcsr_iterator_start(iter, matrix_s(1)%matrix)
501 DO WHILE (dbcsr_iterator_blocks_left(iter))
502 CALL dbcsr_iterator_next_block(iter, irow, icol, sblock)
503 ikind = kind_of(irow)
504 atom_i = atom_of_kind(irow)
505 ui = xgamma(ikind)
506 jkind = kind_of(icol)
507 atom_j = atom_of_kind(icol)
508 uj = xgamma(jkind)
509 !
510 gmijp = ui*mcharge0(irow)*mcharge1(irow) + uj*mcharge0(icol)*mcharge1(icol)
511 gmijq = 0.5_dp*ui*mcharge0(irow)**2 + 0.5_dp*uj*mcharge0(icol)**2
512 !
513 NULLIFY (p0block)
514 CALL dbcsr_get_block_p(matrix=matrixp0, &
515 row=irow, col=icol, block=p0block, found=found)
516 cpassert(found)
517 NULLIFY (p1block)
518 CALL dbcsr_get_block_p(matrix=matrixp1, &
519 row=irow, col=icol, block=p1block, found=found)
520 cpassert(found)
521 DO i = 1, 3
522 NULLIFY (dsblock)
523 CALL dbcsr_get_block_p(matrix=matrix_s(1 + i)%matrix, &
524 row=irow, col=icol, block=dsblock, found=found)
525 cpassert(found)
526 fi = gmijp*sum(p0block*dsblock) + gmijq*sum(p1block*dsblock)
527 force(ikind)%rho_elec(i, atom_i) = force(ikind)%rho_elec(i, atom_i) + fi
528 force(jkind)%rho_elec(i, atom_j) = force(jkind)%rho_elec(i, atom_j) - fi
529 END DO
530 END DO
531 CALL dbcsr_iterator_stop(iter)
532
533 CALL timestop(handle)
534
535 END SUBROUTINE dftb3_diagonal_hessian_force
536
537END MODULE xtb_ehess_force
538
Define the atomic kind types and their sub types.
subroutine, public get_atomic_kind_set(atomic_kind_set, atom_of_kind, kind_of, natom_of_kind, maxatom, natom, nshell, fist_potential_present, shell_present, shell_adiabatic, shell_check_distance, damping_present)
Get attributes of an atomic kind set.
Handles all functions related to the CELL.
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:233
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)
...
various routines to log and control the output. The idea is that decisions about where to log should ...
recursive integer function, public cp_logger_get_default_unit_nr(logger, local, skip_not_ionode)
asks the default unit number of the given logger. try to use cp_logger_get_unit_nr
type(cp_logger_type) function, pointer, public cp_get_default_logger()
returns the default logger
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_spme_zforce(ewald_env, ewald_pw, particle_set, box, gmcharge, mcharge)
...
subroutine, public tb_ewald_overlap(gmcharge, mcharge, alpha, n_list, virial, use_virial)
...
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
Definition of mathematical constants and functions.
real(kind=dp), parameter, public oorootpi
real(kind=dp), parameter, public pi
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
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, matrix_vhxc, 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, hund_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, proj_shell_charge, lr_atom, do_mtlr, u_j_loop, ao_coef, 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...
Calculation of Coulomb contributions in xTB.
Definition xtb_coulomb.F:12
subroutine, public gamma_rab_sr(gmat, rab, nla, kappaa, etaa, nlb, kappab, etab, kg, rcut)
Computes the short-range gamma parameter from Nataga-Mishimoto-Ohno-Klopman formula for xTB WARNING: ...
subroutine, public dgamma_rab_sr(dgmat, rab, nla, kappaa, etaa, nlb, kappab, etab, kg, rcut)
Computes the derivative of the short-range gamma parameter from Nataga-Mishimoto-Ohno-Klopman formula...
Calculation of forces for Coulomb contributions in response xTB.
subroutine, public calc_xtb_ehess_force(qs_env, matrix_p0, matrix_p1, charges0, mcharge0, charges1, mcharge1, debug_forces)
...
Calculation of Spin Polarisation contributions in xTB.
Definition xtb_spinpol.F:12
subroutine, public xtb_spinpol_hforce(qs_env, matrix_p0, matrix_p1)
...
Definition of the xTB parameter types.
Definition xtb_types.F:20
subroutine, public get_xtb_atom_param(xtb_parameter, symbol, aname, typ, defined, z, zeff, natorb, lmax, nao, lao, rcut, rcov, kx, eta, xgamma, alpha, zneff, nshell, nval, lval, kpoly, kappa, wall, hen, zeta, xi, kappa0, alpg, occupation, electronegativity, chmax, en, kqat2, kcn, kq)
...
Definition xtb_types.F:203
Provides all information about an atomic kind.
Type defining parameters related to the simulation cell.
Definition cell_types.F:60
type of a logger, at the moment it contains just a print level starting at which level it should be l...
structure to store local (to a processor) ordered lists of integers.
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.