Line data Source code
1 : !--------------------------------------------------------------------------------------------------!
2 : ! CP2K: A general program to perform molecular dynamics simulations !
3 : ! Copyright 2000-2024 CP2K developers group <https://cp2k.org> !
4 : ! !
5 : ! SPDX-License-Identifier: GPL-2.0-or-later !
6 : !--------------------------------------------------------------------------------------------------!
7 :
8 : ! **************************************************************************************************
9 : !> \brief Calculation of Overlap and Hamiltonian matrices in xTB
10 : !> Reference: Stefan Grimme, Christoph Bannwarth, Philip Shushkov
11 : !> JCTC 13, 1989-2009, (2017)
12 : !> DOI: 10.1021/acs.jctc.7b00118
13 : !> \author JGH
14 : ! **************************************************************************************************
15 : MODULE xtb_matrices
16 : USE ai_contraction, ONLY: block_add,&
17 : contraction
18 : USE ai_overlap, ONLY: overlap_ab
19 : USE atomic_kind_types, ONLY: atomic_kind_type,&
20 : get_atomic_kind,&
21 : get_atomic_kind_set
22 : USE atprop_types, ONLY: atprop_array_init,&
23 : atprop_type
24 : USE basis_set_types, ONLY: gto_basis_set_p_type,&
25 : gto_basis_set_type
26 : USE block_p_types, ONLY: block_p_type
27 : USE cp_blacs_env, ONLY: cp_blacs_env_type
28 : USE cp_control_types, ONLY: dft_control_type,&
29 : xtb_control_type
30 : USE cp_dbcsr_api, ONLY: &
31 : dbcsr_add, dbcsr_copy, dbcsr_create, dbcsr_dot, dbcsr_finalize, dbcsr_get_block_p, &
32 : dbcsr_multiply, dbcsr_p_type, dbcsr_type
33 : USE cp_dbcsr_cp2k_link, ONLY: cp_dbcsr_alloc_block_from_nbl
34 : USE cp_dbcsr_operations, ONLY: dbcsr_allocate_matrix_set,&
35 : dbcsr_deallocate_matrix_set
36 : USE cp_dbcsr_output, ONLY: cp_dbcsr_write_sparse_matrix
37 : USE cp_log_handling, ONLY: cp_get_default_logger,&
38 : cp_logger_get_default_io_unit,&
39 : cp_logger_type,&
40 : cp_to_string
41 : USE cp_output_handling, ONLY: cp_p_file,&
42 : cp_print_key_finished_output,&
43 : cp_print_key_should_output,&
44 : cp_print_key_unit_nr
45 : USE efield_tb_methods, ONLY: efield_tb_matrix
46 : USE ewald_environment_types, ONLY: ewald_env_get,&
47 : ewald_environment_type
48 : USE fparser, ONLY: evalfd,&
49 : finalizef
50 : USE input_section_types, ONLY: section_vals_get_subs_vals,&
51 : section_vals_type,&
52 : section_vals_val_get
53 : USE kinds, ONLY: default_string_length,&
54 : dp
55 : USE kpoint_types, ONLY: get_kpoint_info,&
56 : kpoint_type
57 : USE message_passing, ONLY: mp_para_env_type
58 : USE mulliken, ONLY: ao_charges
59 : USE orbital_pointers, ONLY: ncoset
60 : USE pair_potential, ONLY: init_genpot
61 : USE pair_potential_types, ONLY: not_initialized,&
62 : pair_potential_p_type,&
63 : pair_potential_pp_create,&
64 : pair_potential_pp_release,&
65 : pair_potential_pp_type,&
66 : pair_potential_single_clean,&
67 : pair_potential_single_copy,&
68 : pair_potential_single_type
69 : USE pair_potential_util, ONLY: ener_pot
70 : USE particle_types, ONLY: particle_type
71 : USE qs_charge_mixing, ONLY: charge_mixing
72 : USE qs_condnum, ONLY: overlap_condnum
73 : USE qs_dispersion_pairpot, ONLY: d3_cnumber,&
74 : dcnum_distribute,&
75 : dcnum_type
76 : USE qs_dispersion_types, ONLY: qs_dispersion_type
77 : USE qs_energy_types, ONLY: qs_energy_type
78 : USE qs_environment_types, ONLY: get_qs_env,&
79 : qs_environment_type
80 : USE qs_force_types, ONLY: qs_force_type
81 : USE qs_integral_utils, ONLY: basis_set_list_setup,&
82 : get_memory_usage
83 : USE qs_kind_types, ONLY: get_qs_kind,&
84 : get_qs_kind_set,&
85 : qs_kind_type
86 : USE qs_ks_types, ONLY: get_ks_env,&
87 : qs_ks_env_type,&
88 : set_ks_env
89 : USE qs_mo_types, ONLY: get_mo_set,&
90 : mo_set_type
91 : USE qs_neighbor_list_types, ONLY: get_iterator_info,&
92 : neighbor_list_iterate,&
93 : neighbor_list_iterator_create,&
94 : neighbor_list_iterator_p_type,&
95 : neighbor_list_iterator_release,&
96 : neighbor_list_set_p_type
97 : USE qs_overlap, ONLY: create_sab_matrix
98 : USE qs_rho_types, ONLY: qs_rho_get,&
99 : qs_rho_type
100 : USE qs_scf_types, ONLY: qs_scf_env_type
101 : USE string_utilities, ONLY: compress,&
102 : uppercase
103 : USE virial_methods, ONLY: virial_pair_force
104 : USE virial_types, ONLY: virial_type
105 : USE xtb_coulomb, ONLY: build_xtb_coulomb
106 : USE xtb_parameters, ONLY: xtb_set_kab
107 : USE xtb_types, ONLY: get_xtb_atom_param,&
108 : xtb_atom_type
109 : #include "./base/base_uses.f90"
110 :
111 : IMPLICIT NONE
112 :
113 : TYPE neighbor_atoms_type
114 : REAL(KIND=dp), DIMENSION(:, :), POINTER :: coord => NULL()
115 : REAL(KIND=dp), DIMENSION(:), POINTER :: rab => NULL()
116 : INTEGER, DIMENSION(:), POINTER :: katom => NULL()
117 : END TYPE neighbor_atoms_type
118 :
119 : PRIVATE
120 :
121 : CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'xtb_matrices'
122 :
123 : PUBLIC :: build_xtb_matrices, build_xtb_ks_matrix, xtb_hab_force
124 :
125 : CONTAINS
126 :
127 : ! **************************************************************************************************
128 : !> \brief ...
129 : !> \param qs_env ...
130 : !> \param para_env ...
131 : !> \param calculate_forces ...
132 : ! **************************************************************************************************
133 3184 : SUBROUTINE build_xtb_matrices(qs_env, para_env, calculate_forces)
134 :
135 : TYPE(qs_environment_type), POINTER :: qs_env
136 : TYPE(mp_para_env_type), POINTER :: para_env
137 : LOGICAL, INTENT(IN) :: calculate_forces
138 :
139 : CHARACTER(LEN=*), PARAMETER :: routineN = 'build_xtb_matrices'
140 :
141 : INTEGER :: after, atom_a, atom_b, atom_c, handle, i, iatom, ic, icol, ikind, img, ir, irow, &
142 : iset, iw, j, jatom, jkind, jset, katom, kkind, la, lb, ldsab, lmaxa, lmaxb, maxder, maxs, &
143 : n1, n2, na, natom, natorb_a, natorb_b, nb, ncoa, ncob, nderivatives, nimg, nkind, nsa, &
144 : nsb, nseta, nsetb, nshell, sgfa, sgfb, za, zat, zb
145 6368 : INTEGER, ALLOCATABLE, DIMENSION(:) :: atom_of_kind, atomnumber, kind_of
146 : INTEGER, DIMENSION(25) :: laoa, laob, lval, naoa, naob
147 : INTEGER, DIMENSION(3) :: cell
148 3184 : INTEGER, DIMENSION(:), POINTER :: la_max, la_min, lb_max, lb_min, npgfa, &
149 3184 : npgfb, nsgfa, nsgfb
150 3184 : INTEGER, DIMENSION(:, :), POINTER :: first_sgfa, first_sgfb
151 3184 : INTEGER, DIMENSION(:, :, :), POINTER :: cell_to_index
152 : LOGICAL :: defined, diagblock, do_nonbonded, floating_a, found, ghost_a, norml1, norml2, &
153 : omit_headers, use_arnoldi, use_virial, xb_inter
154 3184 : LOGICAL, ALLOCATABLE, DIMENSION(:) :: floating, ghost
155 : REAL(KIND=dp) :: alphaa, alphab, derepij, dfp, dhij, dr, drk, drx, ena, enb, enonbonded, &
156 : erep, erepij, etaa, etab, exb, f0, f1, fen, fhua, fhub, fhud, foab, hij, k2sh, kab, kcnd, &
157 : kcnp, kcns, kd, ken, kf, kg, kia, kjb, kp, ks, ksp, kx2, kxr, rcova, rcovab, rcovb, rrab, &
158 : zneffa, zneffb
159 6368 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:) :: cnumbers, kx
160 6368 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :) :: dfblock, huckel, kcnlk, owork, rcab
161 3184 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :, :) :: oint, sint
162 3184 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :, :, :) :: kijab
163 : REAL(KIND=dp), DIMENSION(0:3) :: kl
164 : REAL(KIND=dp), DIMENSION(2) :: condnum
165 : REAL(KIND=dp), DIMENSION(3) :: fdik, fdika, fdikb, force_ab, force_rr, &
166 : rij, rik
167 : REAL(KIND=dp), DIMENSION(5) :: dpia, dpib, hena, henb, kappaa, kappab, &
168 : kpolya, kpolyb, pia, pib
169 3184 : REAL(KIND=dp), DIMENSION(:), POINTER :: set_radius_a, set_radius_b
170 3184 : REAL(KIND=dp), DIMENSION(:, :), POINTER :: fblock, pblock, rpgfa, rpgfb, sblock, &
171 3184 : scon_a, scon_b, wblock, zeta, zetb
172 3184 : TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
173 : TYPE(atprop_type), POINTER :: atprop
174 12736 : TYPE(block_p_type), DIMENSION(2:4) :: dsblocks
175 : TYPE(cp_blacs_env_type), POINTER :: blacs_env
176 : TYPE(cp_logger_type), POINTER :: logger
177 3184 : TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: matrix_h, matrix_p, matrix_s, matrix_w
178 3184 : TYPE(dcnum_type), ALLOCATABLE, DIMENSION(:) :: dcnum
179 : TYPE(dft_control_type), POINTER :: dft_control
180 3184 : TYPE(gto_basis_set_p_type), DIMENSION(:), POINTER :: basis_set_list
181 : TYPE(gto_basis_set_type), POINTER :: basis_set_a, basis_set_b
182 : TYPE(kpoint_type), POINTER :: kpoints
183 : TYPE(neighbor_atoms_type), ALLOCATABLE, &
184 3184 : DIMENSION(:) :: neighbor_atoms
185 : TYPE(neighbor_list_iterator_p_type), &
186 3184 : DIMENSION(:), POINTER :: nl_iterator
187 : TYPE(neighbor_list_set_p_type), DIMENSION(:), &
188 3184 : POINTER :: sab_orb, sab_xb, sab_xtb_nonbond
189 3184 : TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
190 : TYPE(qs_dispersion_type), POINTER :: dispersion_env
191 : TYPE(qs_energy_type), POINTER :: energy
192 3184 : TYPE(qs_force_type), DIMENSION(:), POINTER :: force
193 3184 : TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
194 : TYPE(qs_ks_env_type), POINTER :: ks_env
195 : TYPE(qs_rho_type), POINTER :: rho
196 : TYPE(virial_type), POINTER :: virial
197 : TYPE(xtb_atom_type), POINTER :: xtb_atom_a, xtb_atom_b
198 : TYPE(xtb_control_type), POINTER :: xtb_control
199 :
200 3184 : CALL timeset(routineN, handle)
201 :
202 3184 : NULLIFY (logger, virial, atprop)
203 3184 : logger => cp_get_default_logger()
204 :
205 3184 : NULLIFY (matrix_h, matrix_s, matrix_p, matrix_w, atomic_kind_set, &
206 3184 : qs_kind_set, sab_orb, ks_env)
207 :
208 : CALL get_qs_env(qs_env=qs_env, &
209 : ks_env=ks_env, &
210 : energy=energy, &
211 : atomic_kind_set=atomic_kind_set, &
212 : qs_kind_set=qs_kind_set, &
213 : matrix_h_kp=matrix_h, &
214 : matrix_s_kp=matrix_s, &
215 : atprop=atprop, &
216 : dft_control=dft_control, &
217 3184 : sab_orb=sab_orb)
218 :
219 3184 : nkind = SIZE(atomic_kind_set)
220 3184 : xtb_control => dft_control%qs_control%xtb_control
221 3184 : xb_inter = xtb_control%xb_interaction
222 3184 : do_nonbonded = xtb_control%do_nonbonded
223 3184 : nimg = dft_control%nimages
224 3184 : nderivatives = 0
225 3184 : IF (calculate_forces) nderivatives = 1
226 3184 : IF (dft_control%tddfpt2_control%enabled) nderivatives = 1
227 3184 : maxder = ncoset(nderivatives)
228 :
229 3184 : IF (xb_inter) energy%xtb_xb_inter = 0.0_dp
230 3184 : IF (do_nonbonded) energy%xtb_nonbonded = 0.0_dp
231 :
232 : ! global parameters (Table 2 from Ref.)
233 3184 : ks = xtb_control%ks
234 3184 : kp = xtb_control%kp
235 3184 : kd = xtb_control%kd
236 3184 : ksp = xtb_control%ksp
237 3184 : k2sh = xtb_control%k2sh
238 3184 : kg = xtb_control%kg
239 3184 : kf = xtb_control%kf
240 3184 : kcns = xtb_control%kcns
241 3184 : kcnp = xtb_control%kcnp
242 3184 : kcnd = xtb_control%kcnd
243 3184 : ken = xtb_control%ken
244 3184 : kxr = xtb_control%kxr
245 3184 : kx2 = xtb_control%kx2
246 :
247 3184 : NULLIFY (particle_set)
248 3184 : CALL get_qs_env(qs_env=qs_env, particle_set=particle_set)
249 3184 : natom = SIZE(particle_set)
250 3184 : CALL get_atomic_kind_set(atomic_kind_set=atomic_kind_set, atom_of_kind=atom_of_kind)
251 3184 : CALL get_qs_kind_set(qs_kind_set=qs_kind_set, maxsgf=maxs, basis_type="ORB")
252 :
253 3184 : IF (calculate_forces) THEN
254 428 : NULLIFY (rho, force, matrix_w)
255 : CALL get_qs_env(qs_env=qs_env, &
256 : rho=rho, matrix_w_kp=matrix_w, &
257 428 : virial=virial, force=force)
258 428 : CALL qs_rho_get(rho, rho_ao_kp=matrix_p)
259 :
260 428 : IF (SIZE(matrix_p, 1) == 2) THEN
261 432 : DO img = 1, nimg
262 : CALL dbcsr_add(matrix_p(1, img)%matrix, matrix_p(2, img)%matrix, &
263 414 : alpha_scalar=1.0_dp, beta_scalar=1.0_dp)
264 : CALL dbcsr_add(matrix_w(1, img)%matrix, matrix_w(2, img)%matrix, &
265 432 : alpha_scalar=1.0_dp, beta_scalar=1.0_dp)
266 : END DO
267 : END IF
268 806 : use_virial = virial%pv_availability .AND. (.NOT. virial%pv_numer)
269 : END IF
270 : ! atomic energy decomposition
271 3184 : IF (atprop%energy) THEN
272 36 : CALL atprop_array_init(atprop%atecc, natom)
273 : END IF
274 :
275 3184 : NULLIFY (cell_to_index)
276 3184 : IF (nimg > 1) THEN
277 336 : CALL get_ks_env(ks_env=ks_env, kpoints=kpoints)
278 336 : CALL get_kpoint_info(kpoint=kpoints, cell_to_index=cell_to_index)
279 : END IF
280 :
281 : ! set up basis set lists
282 17380 : ALLOCATE (basis_set_list(nkind))
283 3184 : CALL basis_set_list_setup(basis_set_list, "ORB", qs_kind_set)
284 :
285 : ! allocate overlap matrix
286 3184 : CALL dbcsr_allocate_matrix_set(matrix_s, maxder, nimg)
287 : CALL create_sab_matrix(ks_env, matrix_s, "xTB OVERLAP MATRIX", basis_set_list, basis_set_list, &
288 3184 : sab_orb, .TRUE.)
289 3184 : CALL set_ks_env(ks_env, matrix_s_kp=matrix_s)
290 :
291 : ! initialize H matrix
292 3184 : CALL dbcsr_allocate_matrix_set(matrix_h, 1, nimg)
293 50004 : DO img = 1, nimg
294 46820 : ALLOCATE (matrix_h(1, img)%matrix)
295 : CALL dbcsr_create(matrix_h(1, img)%matrix, template=matrix_s(1, 1)%matrix, &
296 46820 : name="HAMILTONIAN MATRIX")
297 50004 : CALL cp_dbcsr_alloc_block_from_nbl(matrix_h(1, img)%matrix, sab_orb)
298 : END DO
299 3184 : CALL set_ks_env(ks_env, matrix_h_kp=matrix_h)
300 :
301 : ! Calculate coordination numbers
302 : ! needed for effective atomic energy levels (Eq. 12)
303 : ! code taken from D3 dispersion energy
304 9552 : ALLOCATE (cnumbers(natom))
305 31458 : cnumbers = 0._dp
306 3184 : IF (calculate_forces) THEN
307 5074 : ALLOCATE (dcnum(natom))
308 4218 : dcnum(:)%neighbors = 0
309 4218 : DO iatom = 1, natom
310 4218 : ALLOCATE (dcnum(iatom)%nlist(10), dcnum(iatom)%dvals(10), dcnum(iatom)%rik(3, 10))
311 : END DO
312 : ELSE
313 5512 : ALLOCATE (dcnum(1))
314 : END IF
315 :
316 15920 : ALLOCATE (ghost(nkind), floating(nkind), atomnumber(nkind))
317 11012 : DO ikind = 1, nkind
318 7828 : CALL get_atomic_kind(atomic_kind_set(ikind), z=za)
319 7828 : CALL get_qs_kind(qs_kind_set(ikind), ghost=ghost_a, floating=floating_a)
320 7828 : ghost(ikind) = ghost_a
321 7828 : floating(ikind) = floating_a
322 18840 : atomnumber(ikind) = za
323 : END DO
324 3184 : CALL get_qs_env(qs_env=qs_env, dispersion_env=dispersion_env)
325 : CALL d3_cnumber(qs_env, dispersion_env, cnumbers, dcnum, ghost, floating, atomnumber, &
326 3184 : calculate_forces, .FALSE.)
327 3184 : DEALLOCATE (ghost, floating, atomnumber)
328 3184 : CALL para_env%sum(cnumbers)
329 3184 : IF (calculate_forces) THEN
330 428 : CALL dcnum_distribute(dcnum, para_env)
331 : END IF
332 :
333 : ! Calculate Huckel parameters
334 : ! Eq 12
335 : ! huckel(nshell,natom)
336 9552 : ALLOCATE (kcnlk(0:3, nkind))
337 11012 : DO ikind = 1, nkind
338 7828 : CALL get_atomic_kind(atomic_kind_set(ikind), z=za)
339 11012 : IF (metal(za)) THEN
340 250 : kcnlk(0:3, ikind) = 0.0_dp
341 7778 : ELSEIF (early3d(za)) THEN
342 0 : kcnlk(0, ikind) = kcns
343 0 : kcnlk(1, ikind) = kcnp
344 0 : kcnlk(2, ikind) = 0.005_dp
345 0 : kcnlk(3, ikind) = 0.0_dp
346 : ELSE
347 7778 : kcnlk(0, ikind) = kcns
348 7778 : kcnlk(1, ikind) = kcnp
349 7778 : kcnlk(2, ikind) = kcnd
350 7778 : kcnlk(3, ikind) = 0.0_dp
351 : END IF
352 : END DO
353 9552 : ALLOCATE (huckel(5, natom))
354 3184 : CALL get_atomic_kind_set(atomic_kind_set=atomic_kind_set, kind_of=kind_of)
355 31458 : DO iatom = 1, natom
356 28274 : ikind = kind_of(iatom)
357 28274 : CALL get_qs_kind(qs_kind_set(ikind), xtb_parameter=xtb_atom_a)
358 28274 : CALL get_xtb_atom_param(xtb_atom_a, nshell=nshell, lval=lval, hen=hena)
359 169644 : huckel(:, iatom) = 0.0_dp
360 116834 : DO i = 1, nshell
361 85376 : huckel(i, iatom) = hena(i)*(1._dp + kcnlk(lval(i), ikind)*cnumbers(iatom))
362 : END DO
363 : END DO
364 :
365 : ! Calculate KAB parameters and Huckel parameters and electronegativity correction
366 3184 : kl(0) = ks
367 3184 : kl(1) = kp
368 3184 : kl(2) = kd
369 3184 : kl(3) = 0.0_dp
370 19104 : ALLOCATE (kijab(maxs, maxs, nkind, nkind))
371 595064 : kijab = 0.0_dp
372 11012 : DO ikind = 1, nkind
373 7828 : CALL get_qs_kind(qs_kind_set(ikind), xtb_parameter=xtb_atom_a)
374 7828 : CALL get_xtb_atom_param(xtb_atom_a, defined=defined, natorb=natorb_a)
375 7828 : IF (.NOT. defined .OR. natorb_a < 1) CYCLE
376 7826 : CALL get_xtb_atom_param(xtb_atom_a, z=za, nao=naoa, lao=laoa, electronegativity=ena)
377 40562 : DO jkind = 1, nkind
378 21724 : CALL get_qs_kind(qs_kind_set(jkind), xtb_parameter=xtb_atom_b)
379 21724 : CALL get_xtb_atom_param(xtb_atom_b, defined=defined, natorb=natorb_b)
380 21724 : IF (.NOT. defined .OR. natorb_b < 1) CYCLE
381 21722 : CALL get_xtb_atom_param(xtb_atom_b, z=zb, nao=naob, lao=laob, electronegativity=enb)
382 : ! get Fen = (1+ken*deltaEN^2)
383 21722 : fen = 1.0_dp + ken*(ena - enb)**2
384 : ! Kab
385 21722 : kab = xtb_set_kab(za, zb, xtb_control)
386 128010 : DO j = 1, natorb_b
387 76736 : lb = laob(j)
388 76736 : nb = naob(j)
389 390334 : DO i = 1, natorb_a
390 291874 : la = laoa(i)
391 291874 : na = naoa(i)
392 291874 : kia = kl(la)
393 291874 : kjb = kl(lb)
394 291874 : IF (zb == 1 .AND. nb == 2) kjb = k2sh
395 291874 : IF (za == 1 .AND. na == 2) kia = k2sh
396 368610 : IF ((zb == 1 .AND. nb == 2) .OR. (za == 1 .AND. na == 2)) THEN
397 48328 : kijab(i, j, ikind, jkind) = 0.5_dp*(kia + kjb)
398 : ELSE
399 243546 : IF ((la == 0 .AND. lb == 1) .OR. (la == 1 .AND. lb == 0)) THEN
400 83676 : kijab(i, j, ikind, jkind) = ksp*kab*fen
401 : ELSE
402 159870 : kijab(i, j, ikind, jkind) = 0.5_dp*(kia + kjb)*kab*fen
403 : END IF
404 : END IF
405 : END DO
406 : END DO
407 : END DO
408 : END DO
409 :
410 3184 : IF (xb_inter) THEN
411 : ! list of neighbor atoms for XB term
412 17380 : ALLOCATE (neighbor_atoms(nkind))
413 11012 : DO ikind = 1, nkind
414 7828 : NULLIFY (neighbor_atoms(ikind)%coord)
415 7828 : NULLIFY (neighbor_atoms(ikind)%rab)
416 7828 : NULLIFY (neighbor_atoms(ikind)%katom)
417 7828 : CALL get_atomic_kind(atomic_kind_set(ikind), z=zat, natom=na)
418 11012 : IF (zat == 17 .OR. zat == 35 .OR. zat == 53 .OR. zat == 85) THEN
419 174 : ALLOCATE (neighbor_atoms(ikind)%coord(3, na))
420 290 : neighbor_atoms(ikind)%coord(1:3, 1:na) = 0.0_dp
421 174 : ALLOCATE (neighbor_atoms(ikind)%rab(na))
422 116 : neighbor_atoms(ikind)%rab(1:na) = HUGE(0.0_dp)
423 174 : ALLOCATE (neighbor_atoms(ikind)%katom(na))
424 116 : neighbor_atoms(ikind)%katom(1:na) = 0
425 : END IF
426 : END DO
427 : ! kx parameters
428 6368 : ALLOCATE (kx(nkind))
429 11012 : DO ikind = 1, nkind
430 7828 : CALL get_qs_kind(qs_kind_set(ikind), xtb_parameter=xtb_atom_a)
431 11012 : CALL get_xtb_atom_param(xtb_atom_a, kx=kx(ikind))
432 : END DO
433 : !
434 12736 : ALLOCATE (rcab(nkind, nkind))
435 11012 : DO ikind = 1, nkind
436 7828 : CALL get_qs_kind(qs_kind_set(ikind), xtb_parameter=xtb_atom_a)
437 7828 : CALL get_xtb_atom_param(xtb_atom_a, rcov=rcova)
438 32740 : DO jkind = 1, nkind
439 21728 : CALL get_qs_kind(qs_kind_set(jkind), xtb_parameter=xtb_atom_b)
440 21728 : CALL get_xtb_atom_param(xtb_atom_b, rcov=rcovb)
441 29556 : rcab(ikind, jkind) = kxr*(rcova + rcovb)
442 : END DO
443 : END DO
444 : !
445 3184 : CALL get_qs_env(qs_env=qs_env, sab_xb=sab_xb)
446 : END IF
447 :
448 : ! initialize repulsion energy
449 3184 : erep = 0._dp
450 :
451 : ! loop over all atom pairs with a non-zero overlap (sab_orb)
452 3184 : CALL neighbor_list_iterator_create(nl_iterator, sab_orb)
453 943739 : DO WHILE (neighbor_list_iterate(nl_iterator) == 0)
454 : CALL get_iterator_info(nl_iterator, ikind=ikind, jkind=jkind, &
455 940555 : iatom=iatom, jatom=jatom, r=rij, cell=cell)
456 940555 : CALL get_qs_kind(qs_kind_set(ikind), xtb_parameter=xtb_atom_a)
457 940555 : CALL get_xtb_atom_param(xtb_atom_a, defined=defined, natorb=natorb_a)
458 940555 : IF (.NOT. defined .OR. natorb_a < 1) CYCLE
459 940555 : CALL get_qs_kind(qs_kind_set(jkind), xtb_parameter=xtb_atom_b)
460 940555 : CALL get_xtb_atom_param(xtb_atom_b, defined=defined, natorb=natorb_b)
461 940555 : IF (.NOT. defined .OR. natorb_b < 1) CYCLE
462 :
463 3762220 : dr = SQRT(SUM(rij(:)**2))
464 :
465 : ! neighbor atom for XB term
466 940555 : IF (xb_inter .AND. (dr > 1.e-3_dp)) THEN
467 926113 : IF (ASSOCIATED(neighbor_atoms(ikind)%rab)) THEN
468 250 : atom_a = atom_of_kind(iatom)
469 250 : IF (dr < neighbor_atoms(ikind)%rab(atom_a)) THEN
470 91 : neighbor_atoms(ikind)%rab(atom_a) = dr
471 364 : neighbor_atoms(ikind)%coord(1:3, atom_a) = rij(1:3)
472 91 : neighbor_atoms(ikind)%katom(atom_a) = jatom
473 : END IF
474 : END IF
475 926113 : IF (ASSOCIATED(neighbor_atoms(jkind)%rab)) THEN
476 287 : atom_b = atom_of_kind(jatom)
477 287 : IF (dr < neighbor_atoms(jkind)%rab(atom_b)) THEN
478 94 : neighbor_atoms(jkind)%rab(atom_b) = dr
479 376 : neighbor_atoms(jkind)%coord(1:3, atom_b) = -rij(1:3)
480 94 : neighbor_atoms(jkind)%katom(atom_b) = iatom
481 : END IF
482 : END IF
483 : END IF
484 :
485 : ! atomic parameters
486 : CALL get_xtb_atom_param(xtb_atom_a, z=za, nao=naoa, lao=laoa, rcov=rcova, eta=etaa, &
487 : lmax=lmaxa, nshell=nsa, alpha=alphaa, zneff=zneffa, kpoly=kpolya, &
488 940555 : kappa=kappaa, hen=hena)
489 : CALL get_xtb_atom_param(xtb_atom_b, z=zb, nao=naob, lao=laob, rcov=rcovb, eta=etab, &
490 : lmax=lmaxb, nshell=nsb, alpha=alphab, zneff=zneffb, kpoly=kpolyb, &
491 940555 : kappa=kappab, hen=henb)
492 :
493 940555 : IF (nimg == 1) THEN
494 : ic = 1
495 : ELSE
496 241506 : ic = cell_to_index(cell(1), cell(2), cell(3))
497 241506 : CPASSERT(ic > 0)
498 : END IF
499 :
500 940555 : icol = MAX(iatom, jatom)
501 940555 : irow = MIN(iatom, jatom)
502 940555 : NULLIFY (sblock, fblock)
503 : CALL dbcsr_get_block_p(matrix=matrix_s(1, ic)%matrix, &
504 940555 : row=irow, col=icol, BLOCK=sblock, found=found)
505 940555 : CPASSERT(found)
506 : CALL dbcsr_get_block_p(matrix=matrix_h(1, ic)%matrix, &
507 940555 : row=irow, col=icol, BLOCK=fblock, found=found)
508 940555 : CPASSERT(found)
509 :
510 940555 : IF (calculate_forces) THEN
511 193498 : NULLIFY (pblock)
512 : CALL dbcsr_get_block_p(matrix=matrix_p(1, ic)%matrix, &
513 193498 : row=irow, col=icol, block=pblock, found=found)
514 193498 : CPASSERT(ASSOCIATED(pblock))
515 193498 : NULLIFY (wblock)
516 : CALL dbcsr_get_block_p(matrix=matrix_w(1, ic)%matrix, &
517 193498 : row=irow, col=icol, block=wblock, found=found)
518 193498 : CPASSERT(ASSOCIATED(wblock))
519 773992 : DO i = 2, 4
520 580494 : NULLIFY (dsblocks(i)%block)
521 : CALL dbcsr_get_block_p(matrix=matrix_s(i, ic)%matrix, &
522 580494 : row=irow, col=icol, BLOCK=dsblocks(i)%block, found=found)
523 773992 : CPASSERT(found)
524 : END DO
525 : END IF
526 :
527 : ! overlap
528 940555 : basis_set_a => basis_set_list(ikind)%gto_basis_set
529 940555 : IF (.NOT. ASSOCIATED(basis_set_a)) CYCLE
530 940555 : basis_set_b => basis_set_list(jkind)%gto_basis_set
531 940555 : IF (.NOT. ASSOCIATED(basis_set_b)) CYCLE
532 940555 : atom_a = atom_of_kind(iatom)
533 940555 : atom_b = atom_of_kind(jatom)
534 : ! basis ikind
535 940555 : first_sgfa => basis_set_a%first_sgf
536 940555 : la_max => basis_set_a%lmax
537 940555 : la_min => basis_set_a%lmin
538 940555 : npgfa => basis_set_a%npgf
539 940555 : nseta = basis_set_a%nset
540 940555 : nsgfa => basis_set_a%nsgf_set
541 940555 : rpgfa => basis_set_a%pgf_radius
542 940555 : set_radius_a => basis_set_a%set_radius
543 940555 : scon_a => basis_set_a%scon
544 940555 : zeta => basis_set_a%zet
545 : ! basis jkind
546 940555 : first_sgfb => basis_set_b%first_sgf
547 940555 : lb_max => basis_set_b%lmax
548 940555 : lb_min => basis_set_b%lmin
549 940555 : npgfb => basis_set_b%npgf
550 940555 : nsetb = basis_set_b%nset
551 940555 : nsgfb => basis_set_b%nsgf_set
552 940555 : rpgfb => basis_set_b%pgf_radius
553 940555 : set_radius_b => basis_set_b%set_radius
554 940555 : scon_b => basis_set_b%scon
555 940555 : zetb => basis_set_b%zet
556 :
557 940555 : ldsab = get_memory_usage(qs_kind_set, "ORB", "ORB")
558 7524440 : ALLOCATE (oint(ldsab, ldsab, maxder), owork(ldsab, ldsab))
559 4702775 : ALLOCATE (sint(natorb_a, natorb_b, maxder))
560 33934923 : sint = 0.0_dp
561 :
562 2906698 : DO iset = 1, nseta
563 1966143 : ncoa = npgfa(iset)*ncoset(la_max(iset))
564 1966143 : n1 = npgfa(iset)*(ncoset(la_max(iset)) - ncoset(la_min(iset) - 1))
565 1966143 : sgfa = first_sgfa(1, iset)
566 7092079 : DO jset = 1, nsetb
567 4185381 : IF (set_radius_a(iset) + set_radius_b(jset) < dr) CYCLE
568 3550035 : ncob = npgfb(jset)*ncoset(lb_max(jset))
569 3550035 : n2 = npgfb(jset)*(ncoset(lb_max(jset)) - ncoset(lb_min(jset) - 1))
570 3550035 : sgfb = first_sgfb(1, jset)
571 3550035 : IF (calculate_forces) THEN
572 : CALL overlap_ab(la_max(iset), la_min(iset), npgfa(iset), rpgfa(:, iset), zeta(:, iset), &
573 : lb_max(jset), lb_min(jset), npgfb(jset), rpgfb(:, jset), zetb(:, jset), &
574 736677 : rij, sab=oint(:, :, 1), dab=oint(:, :, 2:4))
575 : ELSE
576 : CALL overlap_ab(la_max(iset), la_min(iset), npgfa(iset), rpgfa(:, iset), zeta(:, iset), &
577 : lb_max(jset), lb_min(jset), npgfb(jset), rpgfb(:, jset), zetb(:, jset), &
578 2813358 : rij, sab=oint(:, :, 1))
579 : END IF
580 : ! Contraction
581 : CALL contraction(oint(:, :, 1), owork, ca=scon_a(:, sgfa:), na=n1, ma=nsgfa(iset), &
582 3550035 : cb=scon_b(:, sgfb:), nb=n2, mb=nsgfb(jset), fscale=1.0_dp, trans=.FALSE.)
583 3550035 : CALL block_add("IN", owork, nsgfa(iset), nsgfb(jset), sint(:, :, 1), sgfa, sgfb, trans=.FALSE.)
584 5516178 : IF (calculate_forces) THEN
585 2946708 : DO i = 2, 4
586 : CALL contraction(oint(:, :, i), owork, ca=scon_a(:, sgfa:), na=n1, ma=nsgfa(iset), &
587 2210031 : cb=scon_b(:, sgfb:), nb=n2, mb=nsgfb(jset), fscale=1.0_dp, trans=.FALSE.)
588 2946708 : CALL block_add("IN", owork, nsgfa(iset), nsgfb(jset), sint(:, :, i), sgfa, sgfb, trans=.FALSE.)
589 : END DO
590 : END IF
591 : END DO
592 : END DO
593 : ! forces W matrix
594 940555 : IF (calculate_forces) THEN
595 773992 : DO i = 1, 3
596 773992 : IF (iatom <= jatom) THEN
597 8160408 : force_ab(i) = SUM(sint(:, :, i + 1)*wblock(:, :))
598 : ELSE
599 6149439 : force_ab(i) = SUM(sint(:, :, i + 1)*TRANSPOSE(wblock(:, :)))
600 : END IF
601 : END DO
602 193498 : f1 = 2.0_dp
603 773992 : force(ikind)%overlap(:, atom_a) = force(ikind)%overlap(:, atom_a) - f1*force_ab(:)
604 773992 : force(jkind)%overlap(:, atom_b) = force(jkind)%overlap(:, atom_b) + f1*force_ab(:)
605 193498 : IF (use_virial .AND. dr > 1.e-3_dp) THEN
606 99969 : IF (iatom == jatom) f1 = 1.0_dp
607 99969 : CALL virial_pair_force(virial%pv_virial, -f1, force_ab, rij)
608 99969 : IF (atprop%stress) THEN
609 64044 : CALL virial_pair_force(atprop%atstress(:, :, iatom), -0.5_dp*f1, force_ab, rij)
610 64044 : CALL virial_pair_force(atprop%atstress(:, :, jatom), -0.5_dp*f1, force_ab, rij)
611 : END IF
612 : END IF
613 : END IF
614 : ! update S matrix
615 940555 : IF (iatom <= jatom) THEN
616 9328748 : sblock(:, :) = sblock(:, :) + sint(:, :, 1)
617 : ELSE
618 7331711 : sblock(:, :) = sblock(:, :) + TRANSPOSE(sint(:, :, 1))
619 : END IF
620 940555 : IF (calculate_forces) THEN
621 773992 : DO i = 2, 4
622 773992 : IF (iatom <= jatom) THEN
623 8160408 : dsblocks(i)%block(:, :) = dsblocks(i)%block(:, :) + sint(:, :, i)
624 : ELSE
625 6108969 : dsblocks(i)%block(:, :) = dsblocks(i)%block(:, :) - TRANSPOSE(sint(:, :, i))
626 : END IF
627 : END DO
628 : END IF
629 :
630 : ! Calculate Pi = Pia * Pib (Eq. 11)
631 940555 : rcovab = rcova + rcovb
632 940555 : rrab = SQRT(dr/rcovab)
633 2906698 : DO i = 1, nsa
634 2906698 : pia(i) = 1._dp + kpolya(i)*rrab
635 : END DO
636 2906703 : DO i = 1, nsb
637 2906703 : pib(i) = 1._dp + kpolyb(i)*rrab
638 : END DO
639 940555 : IF (calculate_forces) THEN
640 193498 : IF (dr > 1.e-6_dp) THEN
641 191450 : drx = 0.5_dp/rrab/rcovab
642 : ELSE
643 : drx = 0.0_dp
644 : END IF
645 616081 : dpia(1:nsa) = drx*kpolya(1:nsa)
646 616083 : dpib(1:nsb) = drx*kpolyb(1:nsb)
647 : END IF
648 :
649 : ! diagonal block
650 940555 : diagblock = .FALSE.
651 940555 : IF (iatom == jatom .AND. dr < 0.001_dp) diagblock = .TRUE.
652 : !
653 : ! Eq. 10
654 : !
655 : IF (diagblock) THEN
656 58521 : DO i = 1, natorb_a
657 44079 : na = naoa(i)
658 58521 : fblock(i, i) = fblock(i, i) + huckel(na, iatom)
659 : END DO
660 : ELSE
661 3890236 : DO j = 1, natorb_b
662 2964123 : nb = naob(j)
663 16540796 : DO i = 1, natorb_a
664 12650560 : na = naoa(i)
665 12650560 : hij = 0.5_dp*(huckel(na, iatom) + huckel(nb, jatom))*pia(na)*pib(nb)
666 15614683 : IF (iatom <= jatom) THEN
667 7080170 : fblock(i, j) = fblock(i, j) + hij*sint(i, j, 1)*kijab(i, j, ikind, jkind)
668 : ELSE
669 5570390 : fblock(j, i) = fblock(j, i) + hij*sint(i, j, 1)*kijab(i, j, ikind, jkind)
670 : END IF
671 : END DO
672 : END DO
673 : END IF
674 940555 : IF (calculate_forces) THEN
675 193498 : f0 = 1.0_dp
676 193498 : IF (irow == iatom) f0 = -1.0_dp
677 : ! Derivative wrt coordination number
678 193498 : fhua = 0.0_dp
679 193498 : fhub = 0.0_dp
680 193498 : fhud = 0.0_dp
681 193498 : IF (diagblock) THEN
682 8280 : DO i = 1, natorb_a
683 6232 : la = laoa(i)
684 6232 : na = naoa(i)
685 8280 : fhud = fhud + pblock(i, i)*kcnlk(la, ikind)*hena(na)
686 : END DO
687 : ELSE
688 902491 : DO j = 1, natorb_b
689 711041 : lb = laob(j)
690 711041 : nb = naob(j)
691 4736811 : DO i = 1, natorb_a
692 3834320 : la = laoa(i)
693 3834320 : na = naoa(i)
694 3834320 : hij = 0.5_dp*pia(na)*pib(nb)
695 4545361 : IF (iatom <= jatom) THEN
696 2205265 : fhua = fhua + hij*kijab(i, j, ikind, jkind)*sint(i, j, 1)*pblock(i, j)*kcnlk(la, ikind)*hena(na)
697 2205265 : fhub = fhub + hij*kijab(i, j, ikind, jkind)*sint(i, j, 1)*pblock(i, j)*kcnlk(lb, jkind)*henb(nb)
698 : ELSE
699 1629055 : fhua = fhua + hij*kijab(i, j, ikind, jkind)*sint(i, j, 1)*pblock(j, i)*kcnlk(la, ikind)*hena(na)
700 1629055 : fhub = fhub + hij*kijab(i, j, ikind, jkind)*sint(i, j, 1)*pblock(j, i)*kcnlk(lb, jkind)*henb(nb)
701 : END IF
702 : END DO
703 : END DO
704 191450 : IF (iatom /= jatom) THEN
705 172110 : fhua = 2.0_dp*fhua
706 172110 : fhub = 2.0_dp*fhub
707 : END IF
708 : END IF
709 : ! iatom
710 193498 : atom_a = atom_of_kind(iatom)
711 10886952 : DO i = 1, dcnum(iatom)%neighbors
712 10693454 : katom = dcnum(iatom)%nlist(i)
713 10693454 : kkind = kind_of(katom)
714 10693454 : atom_c = atom_of_kind(katom)
715 42773816 : rik = dcnum(iatom)%rik(:, i)
716 42773816 : drk = SQRT(SUM(rik(:)**2))
717 10886952 : IF (drk > 1.e-3_dp) THEN
718 42773816 : fdika(:) = fhua*dcnum(iatom)%dvals(i)*rik(:)/drk
719 42773816 : force(ikind)%all_potential(:, atom_a) = force(ikind)%all_potential(:, atom_a) - fdika(:)
720 42773816 : force(kkind)%all_potential(:, atom_c) = force(kkind)%all_potential(:, atom_c) + fdika(:)
721 42773816 : fdikb(:) = fhud*dcnum(iatom)%dvals(i)*rik(:)/drk
722 42773816 : force(ikind)%all_potential(:, atom_a) = force(ikind)%all_potential(:, atom_a) - fdikb(:)
723 42773816 : force(kkind)%all_potential(:, atom_c) = force(kkind)%all_potential(:, atom_c) + fdikb(:)
724 10693454 : IF (use_virial) THEN
725 20544948 : fdik = fdika + fdikb
726 5136237 : CALL virial_pair_force(virial%pv_virial, -1._dp, fdik, rik)
727 5136237 : IF (atprop%stress) THEN
728 1477368 : CALL virial_pair_force(atprop%atstress(:, :, iatom), -0.5_dp, fdik, rik)
729 1477368 : CALL virial_pair_force(atprop%atstress(:, :, katom), -0.5_dp, fdik, rik)
730 : END IF
731 : END IF
732 : END IF
733 : END DO
734 : ! jatom
735 193498 : atom_b = atom_of_kind(jatom)
736 10881412 : DO i = 1, dcnum(jatom)%neighbors
737 10687914 : katom = dcnum(jatom)%nlist(i)
738 10687914 : kkind = kind_of(katom)
739 10687914 : atom_c = atom_of_kind(katom)
740 42751656 : rik = dcnum(jatom)%rik(:, i)
741 42751656 : drk = SQRT(SUM(rik(:)**2))
742 10881412 : IF (drk > 1.e-3_dp) THEN
743 42751656 : fdik(:) = fhub*dcnum(jatom)%dvals(i)*rik(:)/drk
744 42751656 : force(jkind)%all_potential(:, atom_b) = force(jkind)%all_potential(:, atom_b) - fdik(:)
745 42751656 : force(kkind)%all_potential(:, atom_c) = force(kkind)%all_potential(:, atom_c) + fdik(:)
746 10687914 : IF (use_virial) THEN
747 5134568 : CALL virial_pair_force(virial%pv_virial, -1._dp, fdik, rik)
748 5134568 : IF (atprop%stress) THEN
749 1476450 : CALL virial_pair_force(atprop%atstress(:, :, iatom), -0.5_dp, fdik, rik)
750 1476450 : CALL virial_pair_force(atprop%atstress(:, :, katom), -0.5_dp, fdik, rik)
751 : END IF
752 : END IF
753 : END IF
754 : END DO
755 193498 : IF (diagblock) THEN
756 2048 : force_ab = 0._dp
757 : ELSE
758 : ! force from R dendent Huckel element
759 191450 : n1 = SIZE(fblock, 1)
760 191450 : n2 = SIZE(fblock, 2)
761 765800 : ALLOCATE (dfblock(n1, n2))
762 4723321 : dfblock = 0.0_dp
763 902491 : DO j = 1, natorb_b
764 711041 : lb = laob(j)
765 711041 : nb = naob(j)
766 4736811 : DO i = 1, natorb_a
767 3834320 : la = laoa(i)
768 3834320 : na = naoa(i)
769 3834320 : dhij = 0.5_dp*(huckel(na, iatom) + huckel(nb, jatom))*(dpia(na)*pib(nb) + pia(na)*dpib(nb))
770 4545361 : IF (iatom <= jatom) THEN
771 2205265 : dfblock(i, j) = dfblock(i, j) + dhij*sint(i, j, 1)*kijab(i, j, ikind, jkind)
772 : ELSE
773 1629055 : dfblock(j, i) = dfblock(j, i) + dhij*sint(i, j, 1)*kijab(i, j, ikind, jkind)
774 : END IF
775 : END DO
776 : END DO
777 4723321 : dfp = f0*SUM(dfblock(:, :)*pblock(:, :))
778 765800 : DO ir = 1, 3
779 574350 : foab = 2.0_dp*dfp*rij(ir)/dr
780 : ! force from overlap matrix contribution to H
781 2707473 : DO j = 1, natorb_b
782 2133123 : lb = laob(j)
783 2133123 : nb = naob(j)
784 14210433 : DO i = 1, natorb_a
785 11502960 : la = laoa(i)
786 11502960 : na = naoa(i)
787 11502960 : hij = 0.5_dp*(huckel(na, iatom) + huckel(nb, jatom))*pia(na)*pib(nb)
788 13636083 : IF (iatom <= jatom) THEN
789 6615795 : foab = foab + 2.0_dp*hij*sint(i, j, ir + 1)*pblock(i, j)*kijab(i, j, ikind, jkind)
790 : ELSE
791 4887165 : foab = foab - 2.0_dp*hij*sint(i, j, ir + 1)*pblock(j, i)*kijab(i, j, ikind, jkind)
792 : END IF
793 : END DO
794 : END DO
795 765800 : force_ab(ir) = foab
796 : END DO
797 191450 : DEALLOCATE (dfblock)
798 : END IF
799 : END IF
800 :
801 940555 : IF (calculate_forces) THEN
802 193498 : atom_a = atom_of_kind(iatom)
803 193498 : atom_b = atom_of_kind(jatom)
804 499303 : IF (irow == iatom) force_ab = -force_ab
805 773992 : force(ikind)%all_potential(:, atom_a) = force(ikind)%all_potential(:, atom_a) - force_ab(:)
806 773992 : force(jkind)%all_potential(:, atom_b) = force(jkind)%all_potential(:, atom_b) + force_ab(:)
807 193498 : IF (use_virial) THEN
808 100601 : f1 = 1.0_dp
809 100601 : IF (iatom == jatom) f1 = 0.5_dp
810 100601 : CALL virial_pair_force(virial%pv_virial, -f1, force_ab, rij)
811 100601 : IF (atprop%stress) THEN
812 64548 : CALL virial_pair_force(atprop%atstress(:, :, iatom), -0.5_dp*f1, force_ab, rij)
813 64548 : CALL virial_pair_force(atprop%atstress(:, :, jatom), -0.5_dp*f1, force_ab, rij)
814 : END IF
815 : END IF
816 : END IF
817 :
818 940555 : DEALLOCATE (oint, owork, sint)
819 :
820 : ! repulsive potential
821 5646514 : IF (dr > 0.001_dp) THEN
822 926113 : erepij = zneffa*zneffb/dr*EXP(-SQRT(alphaa*alphab)*dr**kf)
823 926113 : erep = erep + erepij
824 926113 : IF (atprop%energy) THEN
825 128088 : atprop%atecc(iatom) = atprop%atecc(iatom) + 0.5_dp*erepij
826 128088 : atprop%atecc(jatom) = atprop%atecc(jatom) + 0.5_dp*erepij
827 : END IF
828 926113 : IF (calculate_forces .AND. (iatom /= jatom .OR. dr > 0.001_dp)) THEN
829 191450 : derepij = -(1.0_dp/dr + SQRT(alphaa*alphab)*kf*dr**(kf - 1.0_dp))*erepij
830 191450 : force_rr(1) = derepij*rij(1)/dr
831 191450 : force_rr(2) = derepij*rij(2)/dr
832 191450 : force_rr(3) = derepij*rij(3)/dr
833 191450 : atom_a = atom_of_kind(iatom)
834 191450 : atom_b = atom_of_kind(jatom)
835 765800 : force(ikind)%repulsive(:, atom_a) = force(ikind)%repulsive(:, atom_a) - force_rr(:)
836 765800 : force(jkind)%repulsive(:, atom_b) = force(jkind)%repulsive(:, atom_b) + force_rr(:)
837 191450 : IF (use_virial) THEN
838 99969 : f1 = 1.0_dp
839 99969 : IF (iatom == jatom) f1 = 0.5_dp
840 99969 : CALL virial_pair_force(virial%pv_virial, -f1, force_rr, rij)
841 99969 : IF (atprop%stress) THEN
842 64044 : CALL virial_pair_force(atprop%atstress(:, :, iatom), -0.5_dp*f1, force_rr, rij)
843 64044 : CALL virial_pair_force(atprop%atstress(:, :, jatom), -0.5_dp*f1, force_rr, rij)
844 : END IF
845 : END IF
846 : END IF
847 : END IF
848 :
849 : END DO
850 3184 : CALL neighbor_list_iterator_release(nl_iterator)
851 :
852 6368 : DO i = 1, SIZE(matrix_h, 1)
853 53188 : DO img = 1, nimg
854 46820 : CALL dbcsr_finalize(matrix_h(i, img)%matrix)
855 50004 : CALL dbcsr_finalize(matrix_s(i, img)%matrix)
856 : END DO
857 : END DO
858 :
859 3184 : exb = 0.0_dp
860 3184 : IF (xb_inter) THEN
861 3184 : CALL xb_neighbors(neighbor_atoms, para_env)
862 : CALL xb_interaction(exb, neighbor_atoms, atom_of_kind, kind_of, sab_xb, kx, kx2, rcab, &
863 3184 : calculate_forces, use_virial, force, virial, atprop)
864 : END IF
865 :
866 3184 : enonbonded = 0.0_dp
867 3184 : IF (do_nonbonded) THEN
868 : ! nonbonded interactions
869 34 : NULLIFY (sab_xtb_nonbond)
870 34 : CALL get_qs_env(qs_env=qs_env, sab_xtb_nonbond=sab_xtb_nonbond)
871 : CALL nonbonded_correction(enonbonded, force, qs_env, xtb_control, sab_xtb_nonbond, &
872 34 : atomic_kind_set, calculate_forces, use_virial, virial, atprop, atom_of_kind)
873 : END IF
874 : ! set repulsive energy
875 3184 : erep = erep + exb + enonbonded
876 3184 : IF (xb_inter) THEN
877 3184 : CALL para_env%sum(exb)
878 3184 : energy%xtb_xb_inter = exb
879 : END IF
880 3184 : IF (do_nonbonded) THEN
881 34 : CALL para_env%sum(enonbonded)
882 34 : energy%xtb_nonbonded = enonbonded
883 : END IF
884 3184 : CALL para_env%sum(erep)
885 3184 : energy%repulsive = erep
886 :
887 : ! deallocate coordination numbers
888 3184 : DEALLOCATE (cnumbers)
889 3184 : IF (calculate_forces) THEN
890 4218 : DO iatom = 1, natom
891 4218 : DEALLOCATE (dcnum(iatom)%nlist, dcnum(iatom)%dvals, dcnum(iatom)%rik)
892 : END DO
893 : END IF
894 3184 : DEALLOCATE (dcnum)
895 :
896 : ! deallocate Huckel parameters
897 3184 : DEALLOCATE (huckel)
898 : ! deallocate KAB parameters
899 3184 : DEALLOCATE (kijab)
900 :
901 3184 : CALL section_vals_val_get(qs_env%input, "DFT%PRINT%AO_MATRICES%OMIT_HEADERS", l_val=omit_headers)
902 3184 : IF (BTEST(cp_print_key_should_output(logger%iter_info, &
903 : qs_env%input, "DFT%PRINT%AO_MATRICES/CORE_HAMILTONIAN"), cp_p_file)) THEN
904 : iw = cp_print_key_unit_nr(logger, qs_env%input, "DFT%PRINT%AO_MATRICES/CORE_HAMILTONIAN", &
905 0 : extension=".Log")
906 0 : CALL section_vals_val_get(qs_env%input, "DFT%PRINT%AO_MATRICES%NDIGITS", i_val=after)
907 0 : after = MIN(MAX(after, 1), 16)
908 0 : DO img = 1, nimg
909 : CALL cp_dbcsr_write_sparse_matrix(matrix_h(1, img)%matrix, 4, after, qs_env, para_env, &
910 0 : output_unit=iw, omit_headers=omit_headers)
911 : END DO
912 0 : CALL cp_print_key_finished_output(iw, logger, qs_env%input, "DFT%PRINT%AO_MATRICES/CORE_HAMILTONIAN")
913 : END IF
914 :
915 3184 : IF (BTEST(cp_print_key_should_output(logger%iter_info, &
916 : qs_env%input, "DFT%PRINT%AO_MATRICES/OVERLAP"), cp_p_file)) THEN
917 : iw = cp_print_key_unit_nr(logger, qs_env%input, "DFT%PRINT%AO_MATRICES/OVERLAP", &
918 0 : extension=".Log")
919 0 : CALL section_vals_val_get(qs_env%input, "DFT%PRINT%AO_MATRICES%NDIGITS", i_val=after)
920 0 : after = MIN(MAX(after, 1), 16)
921 0 : DO img = 1, nimg
922 : CALL cp_dbcsr_write_sparse_matrix(matrix_s(1, img)%matrix, 4, after, qs_env, para_env, &
923 0 : output_unit=iw, omit_headers=omit_headers)
924 0 : IF (BTEST(cp_print_key_should_output(logger%iter_info, &
925 0 : qs_env%input, "DFT%PRINT%AO_MATRICES/DERIVATIVES"), cp_p_file)) THEN
926 0 : DO i = 2, SIZE(matrix_s, 1)
927 : CALL cp_dbcsr_write_sparse_matrix(matrix_s(i, img)%matrix, 4, after, qs_env, para_env, &
928 0 : output_unit=iw, omit_headers=omit_headers)
929 : END DO
930 : END IF
931 : END DO
932 0 : CALL cp_print_key_finished_output(iw, logger, qs_env%input, "DFT%PRINT%AO_MATRICES/OVERLAP")
933 : END IF
934 :
935 : ! *** Overlap condition number
936 3184 : IF (.NOT. calculate_forces) THEN
937 2756 : IF (cp_print_key_should_output(logger%iter_info, qs_env%input, &
938 : "DFT%PRINT%OVERLAP_CONDITION") .NE. 0) THEN
939 : iw = cp_print_key_unit_nr(logger, qs_env%input, "DFT%PRINT%OVERLAP_CONDITION", &
940 4 : extension=".Log")
941 4 : CALL section_vals_val_get(qs_env%input, "DFT%PRINT%OVERLAP_CONDITION%1-NORM", l_val=norml1)
942 4 : CALL section_vals_val_get(qs_env%input, "DFT%PRINT%OVERLAP_CONDITION%DIAGONALIZATION", l_val=norml2)
943 4 : CALL section_vals_val_get(qs_env%input, "DFT%PRINT%OVERLAP_CONDITION%ARNOLDI", l_val=use_arnoldi)
944 4 : CALL get_qs_env(qs_env=qs_env, blacs_env=blacs_env)
945 4 : CALL overlap_condnum(matrix_s, condnum, iw, norml1, norml2, use_arnoldi, blacs_env)
946 : END IF
947 : END IF
948 :
949 3184 : DEALLOCATE (basis_set_list)
950 3184 : IF (calculate_forces) THEN
951 428 : IF (SIZE(matrix_p, 1) == 2) THEN
952 432 : DO img = 1, nimg
953 : CALL dbcsr_add(matrix_p(1, img)%matrix, matrix_p(2, img)%matrix, alpha_scalar=1.0_dp, &
954 432 : beta_scalar=-1.0_dp)
955 : END DO
956 : END IF
957 : END IF
958 :
959 3184 : IF (xb_inter) THEN
960 11012 : DO ikind = 1, nkind
961 7828 : IF (ASSOCIATED(neighbor_atoms(ikind)%coord)) THEN
962 58 : DEALLOCATE (neighbor_atoms(ikind)%coord)
963 : END IF
964 7828 : IF (ASSOCIATED(neighbor_atoms(ikind)%rab)) THEN
965 58 : DEALLOCATE (neighbor_atoms(ikind)%rab)
966 : END IF
967 11012 : IF (ASSOCIATED(neighbor_atoms(ikind)%katom)) THEN
968 58 : DEALLOCATE (neighbor_atoms(ikind)%katom)
969 : END IF
970 : END DO
971 3184 : DEALLOCATE (neighbor_atoms)
972 3184 : DEALLOCATE (kx, rcab)
973 : END IF
974 :
975 3184 : CALL timestop(handle)
976 :
977 15920 : END SUBROUTINE build_xtb_matrices
978 :
979 : ! **************************************************************************************************
980 : !> \brief ...
981 : !> \param qs_env ...
982 : !> \param p_matrix ...
983 : ! **************************************************************************************************
984 16 : SUBROUTINE xtb_hab_force(qs_env, p_matrix)
985 :
986 : TYPE(qs_environment_type), POINTER :: qs_env
987 : TYPE(dbcsr_type), POINTER :: p_matrix
988 :
989 : CHARACTER(LEN=*), PARAMETER :: routineN = 'xtb_hab_force'
990 :
991 : INTEGER :: atom_a, atom_b, atom_c, handle, i, iatom, ic, icol, ikind, img, ir, irow, iset, &
992 : j, jatom, jkind, jset, katom, kkind, la, lb, ldsab, lmaxa, lmaxb, maxder, maxs, n1, n2, &
993 : na, natom, natorb_a, natorb_b, nb, ncoa, ncob, nderivatives, nimg, nkind, nsa, nsb, &
994 : nseta, nsetb, nshell, sgfa, sgfb, za, zb
995 32 : INTEGER, ALLOCATABLE, DIMENSION(:) :: atom_of_kind, atomnumber, kind_of
996 : INTEGER, DIMENSION(25) :: laoa, laob, lval, naoa, naob
997 : INTEGER, DIMENSION(3) :: cell
998 16 : INTEGER, DIMENSION(:), POINTER :: la_max, la_min, lb_max, lb_min, npgfa, &
999 16 : npgfb, nsgfa, nsgfb
1000 16 : INTEGER, DIMENSION(:, :), POINTER :: first_sgfa, first_sgfb
1001 : LOGICAL :: defined, diagblock, floating_a, found, &
1002 : ghost_a, use_virial
1003 16 : LOGICAL, ALLOCATABLE, DIMENSION(:) :: floating, ghost
1004 : REAL(KIND=dp) :: alphaa, alphab, dfp, dhij, dr, drk, drx, ena, enb, etaa, etab, f0, fen, &
1005 : fhua, fhub, fhud, foab, hij, k2sh, kab, kcnd, kcnp, kcns, kd, ken, kf, kg, kia, kjb, kp, &
1006 : ks, ksp, kx2, kxr, rcova, rcovab, rcovb, rrab, zneffa, zneffb
1007 16 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:) :: cnumbers
1008 32 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :) :: dfblock, huckel, kcnlk, owork
1009 16 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :, :) :: oint, sint
1010 16 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :, :, :) :: kijab
1011 : REAL(KIND=dp), DIMENSION(0:3) :: kl
1012 : REAL(KIND=dp), DIMENSION(3) :: fdik, fdika, fdikb, force_ab, rij, rik
1013 : REAL(KIND=dp), DIMENSION(5) :: dpia, dpib, hena, henb, kappaa, kappab, &
1014 : kpolya, kpolyb, pia, pib
1015 16 : REAL(KIND=dp), DIMENSION(:), POINTER :: set_radius_a, set_radius_b
1016 16 : REAL(KIND=dp), DIMENSION(:, :), POINTER :: fblock, pblock, rpgfa, rpgfb, sblock, &
1017 16 : scon_a, scon_b, zeta, zetb
1018 16 : TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
1019 64 : TYPE(block_p_type), DIMENSION(2:4) :: dsblocks
1020 : TYPE(cp_logger_type), POINTER :: logger
1021 16 : TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: matrix_h, matrix_s
1022 16 : TYPE(dcnum_type), ALLOCATABLE, DIMENSION(:) :: dcnum
1023 : TYPE(dft_control_type), POINTER :: dft_control
1024 16 : TYPE(gto_basis_set_p_type), DIMENSION(:), POINTER :: basis_set_list
1025 : TYPE(gto_basis_set_type), POINTER :: basis_set_a, basis_set_b
1026 : TYPE(mp_para_env_type), POINTER :: para_env
1027 : TYPE(neighbor_list_iterator_p_type), &
1028 16 : DIMENSION(:), POINTER :: nl_iterator
1029 : TYPE(neighbor_list_set_p_type), DIMENSION(:), &
1030 16 : POINTER :: sab_orb
1031 16 : TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
1032 : TYPE(qs_dispersion_type), POINTER :: dispersion_env
1033 16 : TYPE(qs_force_type), DIMENSION(:), POINTER :: force
1034 16 : TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
1035 : TYPE(qs_ks_env_type), POINTER :: ks_env
1036 : TYPE(xtb_atom_type), POINTER :: xtb_atom_a, xtb_atom_b
1037 : TYPE(xtb_control_type), POINTER :: xtb_control
1038 :
1039 16 : CALL timeset(routineN, handle)
1040 :
1041 16 : NULLIFY (logger)
1042 16 : logger => cp_get_default_logger()
1043 :
1044 16 : NULLIFY (matrix_h, matrix_s, atomic_kind_set, qs_kind_set, sab_orb)
1045 :
1046 : CALL get_qs_env(qs_env=qs_env, &
1047 : atomic_kind_set=atomic_kind_set, &
1048 : qs_kind_set=qs_kind_set, &
1049 : dft_control=dft_control, &
1050 : para_env=para_env, &
1051 16 : sab_orb=sab_orb)
1052 :
1053 16 : nkind = SIZE(atomic_kind_set)
1054 16 : xtb_control => dft_control%qs_control%xtb_control
1055 16 : nimg = dft_control%nimages
1056 16 : nderivatives = 1
1057 16 : maxder = ncoset(nderivatives)
1058 :
1059 : ! global parameters (Table 2 from Ref.)
1060 16 : ks = xtb_control%ks
1061 16 : kp = xtb_control%kp
1062 16 : kd = xtb_control%kd
1063 16 : ksp = xtb_control%ksp
1064 16 : k2sh = xtb_control%k2sh
1065 16 : kg = xtb_control%kg
1066 16 : kf = xtb_control%kf
1067 16 : kcns = xtb_control%kcns
1068 16 : kcnp = xtb_control%kcnp
1069 16 : kcnd = xtb_control%kcnd
1070 16 : ken = xtb_control%ken
1071 16 : kxr = xtb_control%kxr
1072 16 : kx2 = xtb_control%kx2
1073 :
1074 16 : NULLIFY (particle_set)
1075 16 : CALL get_qs_env(qs_env=qs_env, particle_set=particle_set)
1076 16 : natom = SIZE(particle_set)
1077 16 : CALL get_atomic_kind_set(atomic_kind_set=atomic_kind_set, atom_of_kind=atom_of_kind)
1078 16 : CALL get_qs_kind_set(qs_kind_set=qs_kind_set, maxsgf=maxs, basis_type="ORB")
1079 :
1080 16 : NULLIFY (force)
1081 16 : CALL get_qs_env(qs_env=qs_env, force=force)
1082 16 : use_virial = .FALSE.
1083 16 : CPASSERT(nimg == 1)
1084 :
1085 : ! set up basis set lists
1086 86 : ALLOCATE (basis_set_list(nkind))
1087 16 : CALL basis_set_list_setup(basis_set_list, "ORB", qs_kind_set)
1088 :
1089 : ! allocate overlap matrix
1090 16 : CALL get_qs_env(qs_env=qs_env, ks_env=ks_env)
1091 16 : CALL dbcsr_allocate_matrix_set(matrix_s, maxder, nimg)
1092 : CALL create_sab_matrix(ks_env, matrix_s, "xTB OVERLAP MATRIX", basis_set_list, basis_set_list, &
1093 16 : sab_orb, .TRUE.)
1094 : ! initialize H matrix
1095 16 : CALL dbcsr_allocate_matrix_set(matrix_h, 1, nimg)
1096 32 : DO img = 1, nimg
1097 16 : ALLOCATE (matrix_h(1, img)%matrix)
1098 : CALL dbcsr_create(matrix_h(1, img)%matrix, template=matrix_s(1, 1)%matrix, &
1099 16 : name="HAMILTONIAN MATRIX")
1100 32 : CALL cp_dbcsr_alloc_block_from_nbl(matrix_h(1, img)%matrix, sab_orb)
1101 : END DO
1102 :
1103 : ! Calculate coordination numbers
1104 : ! needed for effective atomic energy levels (Eq. 12)
1105 : ! code taken from D3 dispersion energy
1106 48 : ALLOCATE (cnumbers(natom))
1107 256 : cnumbers = 0._dp
1108 288 : ALLOCATE (dcnum(natom))
1109 256 : dcnum(:)%neighbors = 0
1110 256 : DO iatom = 1, natom
1111 256 : ALLOCATE (dcnum(iatom)%nlist(10), dcnum(iatom)%dvals(10), dcnum(iatom)%rik(3, 10))
1112 : END DO
1113 :
1114 80 : ALLOCATE (ghost(nkind), floating(nkind), atomnumber(nkind))
1115 54 : DO ikind = 1, nkind
1116 38 : CALL get_atomic_kind(atomic_kind_set(ikind), z=za)
1117 38 : CALL get_qs_kind(qs_kind_set(ikind), ghost=ghost_a, floating=floating_a)
1118 38 : ghost(ikind) = ghost_a
1119 38 : floating(ikind) = floating_a
1120 92 : atomnumber(ikind) = za
1121 : END DO
1122 16 : CALL get_qs_env(qs_env=qs_env, dispersion_env=dispersion_env)
1123 : CALL d3_cnumber(qs_env, dispersion_env, cnumbers, dcnum, ghost, floating, atomnumber, &
1124 16 : .TRUE., .FALSE.)
1125 16 : DEALLOCATE (ghost, floating, atomnumber)
1126 16 : CALL para_env%sum(cnumbers)
1127 16 : CALL dcnum_distribute(dcnum, para_env)
1128 :
1129 : ! Calculate Huckel parameters
1130 : ! Eq 12
1131 : ! huckel(nshell,natom)
1132 48 : ALLOCATE (kcnlk(0:3, nkind))
1133 54 : DO ikind = 1, nkind
1134 38 : CALL get_atomic_kind(atomic_kind_set(ikind), z=za)
1135 54 : IF (metal(za)) THEN
1136 0 : kcnlk(0:3, ikind) = 0.0_dp
1137 38 : ELSEIF (early3d(za)) THEN
1138 0 : kcnlk(0, ikind) = kcns
1139 0 : kcnlk(1, ikind) = kcnp
1140 0 : kcnlk(2, ikind) = 0.005_dp
1141 0 : kcnlk(3, ikind) = 0.0_dp
1142 : ELSE
1143 38 : kcnlk(0, ikind) = kcns
1144 38 : kcnlk(1, ikind) = kcnp
1145 38 : kcnlk(2, ikind) = kcnd
1146 38 : kcnlk(3, ikind) = 0.0_dp
1147 : END IF
1148 : END DO
1149 48 : ALLOCATE (huckel(5, natom))
1150 16 : CALL get_atomic_kind_set(atomic_kind_set=atomic_kind_set, kind_of=kind_of)
1151 256 : DO iatom = 1, natom
1152 240 : ikind = kind_of(iatom)
1153 240 : CALL get_qs_kind(qs_kind_set(ikind), xtb_parameter=xtb_atom_a)
1154 240 : CALL get_xtb_atom_param(xtb_atom_a, nshell=nshell, lval=lval, hen=hena)
1155 1440 : huckel(:, iatom) = 0.0_dp
1156 976 : DO i = 1, nshell
1157 720 : huckel(i, iatom) = hena(i)*(1._dp + kcnlk(lval(i), ikind)*cnumbers(iatom))
1158 : END DO
1159 : END DO
1160 :
1161 : ! Calculate KAB parameters and Huckel parameters and electronegativity correction
1162 16 : kl(0) = ks
1163 16 : kl(1) = kp
1164 16 : kl(2) = kd
1165 16 : kl(3) = 0.0_dp
1166 96 : ALLOCATE (kijab(maxs, maxs, nkind, nkind))
1167 2028 : kijab = 0.0_dp
1168 54 : DO ikind = 1, nkind
1169 38 : CALL get_qs_kind(qs_kind_set(ikind), xtb_parameter=xtb_atom_a)
1170 38 : CALL get_xtb_atom_param(xtb_atom_a, defined=defined, natorb=natorb_a)
1171 38 : IF (.NOT. defined .OR. natorb_a < 1) CYCLE
1172 38 : CALL get_xtb_atom_param(xtb_atom_a, z=za, nao=naoa, lao=laoa, electronegativity=ena)
1173 186 : DO jkind = 1, nkind
1174 94 : CALL get_qs_kind(qs_kind_set(jkind), xtb_parameter=xtb_atom_b)
1175 94 : CALL get_xtb_atom_param(xtb_atom_b, defined=defined, natorb=natorb_b)
1176 94 : IF (.NOT. defined .OR. natorb_b < 1) CYCLE
1177 94 : CALL get_xtb_atom_param(xtb_atom_b, z=zb, nao=naob, lao=laob, electronegativity=enb)
1178 : ! get Fen = (1+ken*deltaEN^2)
1179 94 : fen = 1.0_dp + ken*(ena - enb)**2
1180 : ! Kab
1181 94 : kab = xtb_set_kab(za, zb, xtb_control)
1182 526 : DO j = 1, natorb_b
1183 300 : lb = laob(j)
1184 300 : nb = naob(j)
1185 1354 : DO i = 1, natorb_a
1186 960 : la = laoa(i)
1187 960 : na = naoa(i)
1188 960 : kia = kl(la)
1189 960 : kjb = kl(lb)
1190 960 : IF (zb == 1 .AND. nb == 2) kjb = k2sh
1191 960 : IF (za == 1 .AND. na == 2) kia = k2sh
1192 1260 : IF ((zb == 1 .AND. nb == 2) .OR. (za == 1 .AND. na == 2)) THEN
1193 224 : kijab(i, j, ikind, jkind) = 0.5_dp*(kia + kjb)
1194 : ELSE
1195 736 : IF ((la == 0 .AND. lb == 1) .OR. (la == 1 .AND. lb == 0)) THEN
1196 336 : kijab(i, j, ikind, jkind) = ksp*kab*fen
1197 : ELSE
1198 400 : kijab(i, j, ikind, jkind) = 0.5_dp*(kia + kjb)*kab*fen
1199 : END IF
1200 : END IF
1201 : END DO
1202 : END DO
1203 : END DO
1204 : END DO
1205 :
1206 : ! loop over all atom pairs with a non-zero overlap (sab_orb)
1207 16 : CALL neighbor_list_iterator_create(nl_iterator, sab_orb)
1208 13003 : DO WHILE (neighbor_list_iterate(nl_iterator) == 0)
1209 : CALL get_iterator_info(nl_iterator, ikind=ikind, jkind=jkind, &
1210 12987 : iatom=iatom, jatom=jatom, r=rij, cell=cell)
1211 12987 : CALL get_qs_kind(qs_kind_set(ikind), xtb_parameter=xtb_atom_a)
1212 12987 : CALL get_xtb_atom_param(xtb_atom_a, defined=defined, natorb=natorb_a)
1213 12987 : IF (.NOT. defined .OR. natorb_a < 1) CYCLE
1214 12987 : CALL get_qs_kind(qs_kind_set(jkind), xtb_parameter=xtb_atom_b)
1215 12987 : CALL get_xtb_atom_param(xtb_atom_b, defined=defined, natorb=natorb_b)
1216 12987 : IF (.NOT. defined .OR. natorb_b < 1) CYCLE
1217 :
1218 51948 : dr = SQRT(SUM(rij(:)**2))
1219 :
1220 : ! atomic parameters
1221 : CALL get_xtb_atom_param(xtb_atom_a, z=za, nao=naoa, lao=laoa, rcov=rcova, eta=etaa, &
1222 : lmax=lmaxa, nshell=nsa, alpha=alphaa, zneff=zneffa, kpoly=kpolya, &
1223 12987 : kappa=kappaa, hen=hena)
1224 : CALL get_xtb_atom_param(xtb_atom_b, z=zb, nao=naob, lao=laob, rcov=rcovb, eta=etab, &
1225 : lmax=lmaxb, nshell=nsb, alpha=alphab, zneff=zneffb, kpoly=kpolyb, &
1226 12987 : kappa=kappab, hen=henb)
1227 :
1228 12987 : ic = 1
1229 :
1230 12987 : icol = MAX(iatom, jatom)
1231 12987 : irow = MIN(iatom, jatom)
1232 12987 : NULLIFY (sblock, fblock)
1233 : CALL dbcsr_get_block_p(matrix=matrix_s(1, ic)%matrix, &
1234 12987 : row=irow, col=icol, BLOCK=sblock, found=found)
1235 12987 : CPASSERT(found)
1236 : CALL dbcsr_get_block_p(matrix=matrix_h(1, ic)%matrix, &
1237 12987 : row=irow, col=icol, BLOCK=fblock, found=found)
1238 12987 : CPASSERT(found)
1239 :
1240 12987 : NULLIFY (pblock)
1241 : CALL dbcsr_get_block_p(matrix=p_matrix, &
1242 12987 : row=irow, col=icol, block=pblock, found=found)
1243 12987 : CPASSERT(ASSOCIATED(pblock))
1244 51948 : DO i = 2, 4
1245 38961 : NULLIFY (dsblocks(i)%block)
1246 : CALL dbcsr_get_block_p(matrix=matrix_s(i, ic)%matrix, &
1247 38961 : row=irow, col=icol, BLOCK=dsblocks(i)%block, found=found)
1248 51948 : CPASSERT(found)
1249 : END DO
1250 :
1251 : ! overlap
1252 12987 : basis_set_a => basis_set_list(ikind)%gto_basis_set
1253 12987 : IF (.NOT. ASSOCIATED(basis_set_a)) CYCLE
1254 12987 : basis_set_b => basis_set_list(jkind)%gto_basis_set
1255 12987 : IF (.NOT. ASSOCIATED(basis_set_b)) CYCLE
1256 12987 : atom_a = atom_of_kind(iatom)
1257 12987 : atom_b = atom_of_kind(jatom)
1258 : ! basis ikind
1259 12987 : first_sgfa => basis_set_a%first_sgf
1260 12987 : la_max => basis_set_a%lmax
1261 12987 : la_min => basis_set_a%lmin
1262 12987 : npgfa => basis_set_a%npgf
1263 12987 : nseta = basis_set_a%nset
1264 12987 : nsgfa => basis_set_a%nsgf_set
1265 12987 : rpgfa => basis_set_a%pgf_radius
1266 12987 : set_radius_a => basis_set_a%set_radius
1267 12987 : scon_a => basis_set_a%scon
1268 12987 : zeta => basis_set_a%zet
1269 : ! basis jkind
1270 12987 : first_sgfb => basis_set_b%first_sgf
1271 12987 : lb_max => basis_set_b%lmax
1272 12987 : lb_min => basis_set_b%lmin
1273 12987 : npgfb => basis_set_b%npgf
1274 12987 : nsetb = basis_set_b%nset
1275 12987 : nsgfb => basis_set_b%nsgf_set
1276 12987 : rpgfb => basis_set_b%pgf_radius
1277 12987 : set_radius_b => basis_set_b%set_radius
1278 12987 : scon_b => basis_set_b%scon
1279 12987 : zetb => basis_set_b%zet
1280 :
1281 12987 : ldsab = get_memory_usage(qs_kind_set, "ORB", "ORB")
1282 103896 : ALLOCATE (oint(ldsab, ldsab, maxder), owork(ldsab, ldsab))
1283 64935 : ALLOCATE (sint(natorb_a, natorb_b, maxder))
1284 515591 : sint = 0.0_dp
1285 :
1286 38961 : DO iset = 1, nseta
1287 25974 : ncoa = npgfa(iset)*ncoset(la_max(iset))
1288 25974 : n1 = npgfa(iset)*(ncoset(la_max(iset)) - ncoset(la_min(iset) - 1))
1289 25974 : sgfa = first_sgfa(1, iset)
1290 90909 : DO jset = 1, nsetb
1291 51948 : IF (set_radius_a(iset) + set_radius_b(jset) < dr) CYCLE
1292 45815 : ncob = npgfb(jset)*ncoset(lb_max(jset))
1293 45815 : n2 = npgfb(jset)*(ncoset(lb_max(jset)) - ncoset(lb_min(jset) - 1))
1294 45815 : sgfb = first_sgfb(1, jset)
1295 : CALL overlap_ab(la_max(iset), la_min(iset), npgfa(iset), rpgfa(:, iset), zeta(:, iset), &
1296 : lb_max(jset), lb_min(jset), npgfb(jset), rpgfb(:, jset), zetb(:, jset), &
1297 45815 : rij, sab=oint(:, :, 1), dab=oint(:, :, 2:4))
1298 : ! Contraction
1299 255049 : DO i = 1, 4
1300 : CALL contraction(oint(:, :, i), owork, ca=scon_a(:, sgfa:), na=n1, ma=nsgfa(iset), &
1301 183260 : cb=scon_b(:, sgfb:), nb=n2, mb=nsgfb(jset), fscale=1.0_dp, trans=.FALSE.)
1302 235208 : CALL block_add("IN", owork, nsgfa(iset), nsgfb(jset), sint(:, :, i), sgfa, sgfb, trans=.FALSE.)
1303 : END DO
1304 : END DO
1305 : END DO
1306 : ! update S matrix
1307 12987 : IF (iatom <= jatom) THEN
1308 61008 : sblock(:, :) = sblock(:, :) + sint(:, :, 1)
1309 : ELSE
1310 59865 : sblock(:, :) = sblock(:, :) + TRANSPOSE(sint(:, :, 1))
1311 : END IF
1312 51948 : DO i = 2, 4
1313 51948 : IF (iatom <= jatom) THEN
1314 183024 : dsblocks(i)%block(:, :) = dsblocks(i)%block(:, :) + sint(:, :, i)
1315 : ELSE
1316 179595 : dsblocks(i)%block(:, :) = dsblocks(i)%block(:, :) - TRANSPOSE(sint(:, :, i))
1317 : END IF
1318 : END DO
1319 :
1320 : ! Calculate Pi = Pia * Pib (Eq. 11)
1321 12987 : rcovab = rcova + rcovb
1322 12987 : rrab = SQRT(dr/rcovab)
1323 38961 : DO i = 1, nsa
1324 38961 : pia(i) = 1._dp + kpolya(i)*rrab
1325 : END DO
1326 38961 : DO i = 1, nsb
1327 38961 : pib(i) = 1._dp + kpolyb(i)*rrab
1328 : END DO
1329 12987 : IF (dr > 1.e-6_dp) THEN
1330 12867 : drx = 0.5_dp/rrab/rcovab
1331 : ELSE
1332 : drx = 0.0_dp
1333 : END IF
1334 38961 : dpia(1:nsa) = drx*kpolya(1:nsa)
1335 38961 : dpib(1:nsb) = drx*kpolyb(1:nsb)
1336 :
1337 : ! diagonal block
1338 12987 : diagblock = .FALSE.
1339 12987 : IF (iatom == jatom .AND. dr < 0.001_dp) diagblock = .TRUE.
1340 : !
1341 : ! Eq. 10
1342 : !
1343 : IF (diagblock) THEN
1344 444 : DO i = 1, natorb_a
1345 324 : na = naoa(i)
1346 444 : fblock(i, i) = fblock(i, i) + huckel(na, iatom)
1347 : END DO
1348 : ELSE
1349 44819 : DO j = 1, natorb_b
1350 31952 : nb = naob(j)
1351 124223 : DO i = 1, natorb_a
1352 79404 : na = naoa(i)
1353 79404 : hij = 0.5_dp*(huckel(na, iatom) + huckel(nb, jatom))*pia(na)*pib(nb)
1354 111356 : IF (iatom <= jatom) THEN
1355 39648 : fblock(i, j) = fblock(i, j) + hij*sint(i, j, 1)*kijab(i, j, ikind, jkind)
1356 : ELSE
1357 39756 : fblock(j, i) = fblock(j, i) + hij*sint(i, j, 1)*kijab(i, j, ikind, jkind)
1358 : END IF
1359 : END DO
1360 : END DO
1361 : END IF
1362 :
1363 12987 : f0 = 1.0_dp
1364 12987 : IF (irow == iatom) f0 = -1.0_dp
1365 : ! Derivative wrt coordination number
1366 12987 : fhua = 0.0_dp
1367 12987 : fhub = 0.0_dp
1368 12987 : fhud = 0.0_dp
1369 12987 : IF (diagblock) THEN
1370 444 : DO i = 1, natorb_a
1371 324 : la = laoa(i)
1372 324 : na = naoa(i)
1373 444 : fhud = fhud + pblock(i, i)*kcnlk(la, ikind)*hena(na)
1374 : END DO
1375 : ELSE
1376 44819 : DO j = 1, natorb_b
1377 31952 : lb = laob(j)
1378 31952 : nb = naob(j)
1379 124223 : DO i = 1, natorb_a
1380 79404 : la = laoa(i)
1381 79404 : na = naoa(i)
1382 79404 : hij = 0.5_dp*pia(na)*pib(nb)
1383 111356 : IF (iatom <= jatom) THEN
1384 39648 : fhua = fhua + hij*kijab(i, j, ikind, jkind)*sint(i, j, 1)*pblock(i, j)*kcnlk(la, ikind)*hena(na)
1385 39648 : fhub = fhub + hij*kijab(i, j, ikind, jkind)*sint(i, j, 1)*pblock(i, j)*kcnlk(lb, jkind)*henb(nb)
1386 : ELSE
1387 39756 : fhua = fhua + hij*kijab(i, j, ikind, jkind)*sint(i, j, 1)*pblock(j, i)*kcnlk(la, ikind)*hena(na)
1388 39756 : fhub = fhub + hij*kijab(i, j, ikind, jkind)*sint(i, j, 1)*pblock(j, i)*kcnlk(lb, jkind)*henb(nb)
1389 : END IF
1390 : END DO
1391 : END DO
1392 12867 : IF (iatom /= jatom) THEN
1393 12825 : fhua = 2.0_dp*fhua
1394 12825 : fhub = 2.0_dp*fhub
1395 : END IF
1396 : END IF
1397 : ! iatom
1398 12987 : atom_a = atom_of_kind(iatom)
1399 305732 : DO i = 1, dcnum(iatom)%neighbors
1400 292745 : katom = dcnum(iatom)%nlist(i)
1401 292745 : kkind = kind_of(katom)
1402 292745 : atom_c = atom_of_kind(katom)
1403 1170980 : rik = dcnum(iatom)%rik(:, i)
1404 1170980 : drk = SQRT(SUM(rik(:)**2))
1405 305732 : IF (drk > 1.e-3_dp) THEN
1406 1170980 : fdika(:) = fhua*dcnum(iatom)%dvals(i)*rik(:)/drk
1407 1170980 : force(ikind)%all_potential(:, atom_a) = force(ikind)%all_potential(:, atom_a) - fdika(:)
1408 1170980 : force(kkind)%all_potential(:, atom_c) = force(kkind)%all_potential(:, atom_c) + fdika(:)
1409 1170980 : fdikb(:) = fhud*dcnum(iatom)%dvals(i)*rik(:)/drk
1410 1170980 : force(ikind)%all_potential(:, atom_a) = force(ikind)%all_potential(:, atom_a) - fdikb(:)
1411 1170980 : force(kkind)%all_potential(:, atom_c) = force(kkind)%all_potential(:, atom_c) + fdikb(:)
1412 : END IF
1413 : END DO
1414 : ! jatom
1415 12987 : atom_b = atom_of_kind(jatom)
1416 304187 : DO i = 1, dcnum(jatom)%neighbors
1417 291200 : katom = dcnum(jatom)%nlist(i)
1418 291200 : kkind = kind_of(katom)
1419 291200 : atom_c = atom_of_kind(katom)
1420 1164800 : rik = dcnum(jatom)%rik(:, i)
1421 1164800 : drk = SQRT(SUM(rik(:)**2))
1422 304187 : IF (drk > 1.e-3_dp) THEN
1423 1164800 : fdik(:) = fhub*dcnum(jatom)%dvals(i)*rik(:)/drk
1424 1164800 : force(jkind)%all_potential(:, atom_b) = force(jkind)%all_potential(:, atom_b) - fdik(:)
1425 1164800 : force(kkind)%all_potential(:, atom_c) = force(kkind)%all_potential(:, atom_c) + fdik(:)
1426 : END IF
1427 : END DO
1428 12987 : IF (diagblock) THEN
1429 120 : force_ab = 0._dp
1430 : ELSE
1431 : ! force from R dendent Huckel element
1432 12867 : n1 = SIZE(fblock, 1)
1433 12867 : n2 = SIZE(fblock, 2)
1434 51468 : ALLOCATE (dfblock(n1, n2))
1435 119445 : dfblock = 0.0_dp
1436 44819 : DO j = 1, natorb_b
1437 31952 : lb = laob(j)
1438 31952 : nb = naob(j)
1439 124223 : DO i = 1, natorb_a
1440 79404 : la = laoa(i)
1441 79404 : na = naoa(i)
1442 79404 : dhij = 0.5_dp*(huckel(na, iatom) + huckel(nb, jatom))*(dpia(na)*pib(nb) + pia(na)*dpib(nb))
1443 111356 : IF (iatom <= jatom) THEN
1444 39648 : dfblock(i, j) = dfblock(i, j) + dhij*sint(i, j, 1)*kijab(i, j, ikind, jkind)
1445 : ELSE
1446 39756 : dfblock(j, i) = dfblock(j, i) + dhij*sint(i, j, 1)*kijab(i, j, ikind, jkind)
1447 : END IF
1448 : END DO
1449 : END DO
1450 119445 : dfp = f0*SUM(dfblock(:, :)*pblock(:, :))
1451 51468 : DO ir = 1, 3
1452 38601 : foab = 2.0_dp*dfp*rij(ir)/dr
1453 : ! force from overlap matrix contribution to H
1454 134457 : DO j = 1, natorb_b
1455 95856 : lb = laob(j)
1456 95856 : nb = naob(j)
1457 372669 : DO i = 1, natorb_a
1458 238212 : la = laoa(i)
1459 238212 : na = naoa(i)
1460 238212 : hij = 0.5_dp*(huckel(na, iatom) + huckel(nb, jatom))*pia(na)*pib(nb)
1461 334068 : IF (iatom <= jatom) THEN
1462 118944 : foab = foab + 2.0_dp*hij*sint(i, j, ir + 1)*pblock(i, j)*kijab(i, j, ikind, jkind)
1463 : ELSE
1464 119268 : foab = foab - 2.0_dp*hij*sint(i, j, ir + 1)*pblock(j, i)*kijab(i, j, ikind, jkind)
1465 : END IF
1466 : END DO
1467 : END DO
1468 51468 : force_ab(ir) = foab
1469 : END DO
1470 12867 : DEALLOCATE (dfblock)
1471 : END IF
1472 :
1473 12987 : atom_a = atom_of_kind(iatom)
1474 12987 : atom_b = atom_of_kind(jatom)
1475 32565 : IF (irow == iatom) force_ab = -force_ab
1476 51948 : force(ikind)%all_potential(:, atom_a) = force(ikind)%all_potential(:, atom_a) - force_ab(:)
1477 51948 : force(jkind)%all_potential(:, atom_b) = force(jkind)%all_potential(:, atom_b) + force_ab(:)
1478 :
1479 77938 : DEALLOCATE (oint, owork, sint)
1480 :
1481 : END DO
1482 16 : CALL neighbor_list_iterator_release(nl_iterator)
1483 :
1484 32 : DO i = 1, SIZE(matrix_h, 1)
1485 48 : DO img = 1, nimg
1486 16 : CALL dbcsr_finalize(matrix_h(i, img)%matrix)
1487 32 : CALL dbcsr_finalize(matrix_s(i, img)%matrix)
1488 : END DO
1489 : END DO
1490 16 : CALL dbcsr_deallocate_matrix_set(matrix_s)
1491 16 : CALL dbcsr_deallocate_matrix_set(matrix_h)
1492 :
1493 : ! deallocate coordination numbers
1494 16 : DEALLOCATE (cnumbers)
1495 256 : DO iatom = 1, natom
1496 256 : DEALLOCATE (dcnum(iatom)%nlist, dcnum(iatom)%dvals, dcnum(iatom)%rik)
1497 : END DO
1498 16 : DEALLOCATE (dcnum)
1499 :
1500 : ! deallocate Huckel parameters
1501 16 : DEALLOCATE (huckel)
1502 : ! deallocate KAB parameters
1503 16 : DEALLOCATE (kijab)
1504 :
1505 16 : DEALLOCATE (basis_set_list)
1506 :
1507 16 : CALL timestop(handle)
1508 :
1509 64 : END SUBROUTINE xtb_hab_force
1510 :
1511 : ! **************************************************************************************************
1512 : !> \brief ...
1513 : !> \param qs_env ...
1514 : !> \param calculate_forces ...
1515 : !> \param just_energy ...
1516 : !> \param ext_ks_matrix ...
1517 : ! **************************************************************************************************
1518 23022 : SUBROUTINE build_xtb_ks_matrix(qs_env, calculate_forces, just_energy, ext_ks_matrix)
1519 : TYPE(qs_environment_type), POINTER :: qs_env
1520 : LOGICAL, INTENT(in) :: calculate_forces, just_energy
1521 : TYPE(dbcsr_p_type), DIMENSION(:), OPTIONAL, &
1522 : POINTER :: ext_ks_matrix
1523 :
1524 : CHARACTER(len=*), PARAMETER :: routineN = 'build_xtb_ks_matrix'
1525 :
1526 : INTEGER :: atom_a, handle, iatom, ikind, img, &
1527 : iounit, is, ispin, na, natom, natorb, &
1528 : nimg, nkind, ns, nsgf, nspins
1529 : INTEGER, DIMENSION(25) :: lao
1530 : INTEGER, DIMENSION(5) :: occ
1531 : LOGICAL :: do_efield, pass_check
1532 : REAL(KIND=dp) :: achrg, chmax, pc_ener, qmmm_el
1533 23022 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:) :: mcharge
1534 23022 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :) :: aocg, charges
1535 23022 : TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
1536 : TYPE(cp_logger_type), POINTER :: logger
1537 23022 : TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_p1, mo_derivs, p_matrix
1538 23022 : TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: ks_matrix, matrix_h, matrix_p, matrix_s
1539 : TYPE(dbcsr_type), POINTER :: mo_coeff, s_matrix
1540 : TYPE(dft_control_type), POINTER :: dft_control
1541 : TYPE(mp_para_env_type), POINTER :: para_env
1542 23022 : TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
1543 : TYPE(qs_energy_type), POINTER :: energy
1544 23022 : TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
1545 : TYPE(qs_ks_env_type), POINTER :: ks_env
1546 : TYPE(qs_rho_type), POINTER :: rho
1547 : TYPE(qs_scf_env_type), POINTER :: scf_env
1548 : TYPE(section_vals_type), POINTER :: scf_section
1549 : TYPE(xtb_atom_type), POINTER :: xtb_kind
1550 :
1551 23022 : CALL timeset(routineN, handle)
1552 :
1553 23022 : NULLIFY (dft_control, logger, scf_section, matrix_p, particle_set, ks_env, &
1554 23022 : ks_matrix, rho, energy)
1555 23022 : CPASSERT(ASSOCIATED(qs_env))
1556 :
1557 23022 : logger => cp_get_default_logger()
1558 23022 : iounit = cp_logger_get_default_io_unit(logger)
1559 :
1560 : CALL get_qs_env(qs_env, &
1561 : dft_control=dft_control, &
1562 : atomic_kind_set=atomic_kind_set, &
1563 : qs_kind_set=qs_kind_set, &
1564 : matrix_h_kp=matrix_h, &
1565 : para_env=para_env, &
1566 : ks_env=ks_env, &
1567 : matrix_ks_kp=ks_matrix, &
1568 : rho=rho, &
1569 23022 : energy=energy)
1570 :
1571 23022 : IF (PRESENT(ext_ks_matrix)) THEN
1572 : ! remap pointer to allow for non-kpoint external ks matrix
1573 : ! ext_ks_matrix is used in linear response code
1574 16 : ns = SIZE(ext_ks_matrix)
1575 16 : ks_matrix(1:ns, 1:1) => ext_ks_matrix(1:ns)
1576 : END IF
1577 :
1578 23022 : energy%hartree = 0.0_dp
1579 23022 : energy%qmmm_el = 0.0_dp
1580 23022 : energy%efield = 0.0_dp
1581 :
1582 23022 : scf_section => section_vals_get_subs_vals(qs_env%input, "DFT%SCF")
1583 23022 : nspins = dft_control%nspins
1584 23022 : nimg = dft_control%nimages
1585 23022 : CPASSERT(ASSOCIATED(matrix_h))
1586 23022 : CPASSERT(ASSOCIATED(rho))
1587 69066 : CPASSERT(SIZE(ks_matrix) > 0)
1588 :
1589 48196 : DO ispin = 1, nspins
1590 434180 : DO img = 1, nimg
1591 : ! copy the core matrix into the fock matrix
1592 411158 : CALL dbcsr_copy(ks_matrix(ispin, img)%matrix, matrix_h(1, img)%matrix)
1593 : END DO
1594 : END DO
1595 :
1596 23022 : IF (dft_control%apply_period_efield .OR. dft_control%apply_efield .OR. &
1597 : dft_control%apply_efield_field) THEN
1598 : do_efield = .TRUE.
1599 : ELSE
1600 17128 : do_efield = .FALSE.
1601 : END IF
1602 :
1603 23022 : IF (dft_control%qs_control%xtb_control%coulomb_interaction .OR. do_efield) THEN
1604 : ! Mulliken charges
1605 21140 : CALL get_qs_env(qs_env=qs_env, particle_set=particle_set, matrix_s_kp=matrix_s)
1606 21140 : CALL qs_rho_get(rho, rho_ao_kp=matrix_p)
1607 21140 : natom = SIZE(particle_set)
1608 105700 : ALLOCATE (mcharge(natom), charges(natom, 5))
1609 1146460 : charges = 0.0_dp
1610 21140 : nkind = SIZE(atomic_kind_set)
1611 21140 : CALL get_qs_kind_set(qs_kind_set, maxsgf=nsgf)
1612 84560 : ALLOCATE (aocg(nsgf, natom))
1613 1091650 : aocg = 0.0_dp
1614 21140 : IF (nimg > 1) THEN
1615 2644 : CALL ao_charges(matrix_p, matrix_s, aocg, para_env)
1616 : ELSE
1617 18496 : p_matrix => matrix_p(:, 1)
1618 18496 : s_matrix => matrix_s(1, 1)%matrix
1619 18496 : CALL ao_charges(p_matrix, s_matrix, aocg, para_env)
1620 : END IF
1621 76966 : DO ikind = 1, nkind
1622 55826 : CALL get_atomic_kind(atomic_kind_set(ikind), natom=na)
1623 55826 : CALL get_qs_kind(qs_kind_set(ikind), xtb_parameter=xtb_kind)
1624 55826 : CALL get_xtb_atom_param(xtb_kind, natorb=natorb, lao=lao, occupation=occ)
1625 336716 : DO iatom = 1, na
1626 203924 : atom_a = atomic_kind_set(ikind)%atom_list(iatom)
1627 1223544 : charges(atom_a, :) = REAL(occ(:), KIND=dp)
1628 909952 : DO is = 1, natorb
1629 650202 : ns = lao(is) + 1
1630 854126 : charges(atom_a, ns) = charges(atom_a, ns) - aocg(is, atom_a)
1631 : END DO
1632 : END DO
1633 : END DO
1634 21140 : DEALLOCATE (aocg)
1635 : ! charge mixing
1636 21140 : IF (dft_control%qs_control%do_ls_scf) THEN
1637 : !
1638 : ELSE
1639 20932 : CALL get_qs_env(qs_env=qs_env, scf_env=scf_env)
1640 : CALL charge_mixing(scf_env%mixing_method, scf_env%mixing_store, &
1641 20932 : charges, para_env, scf_env%iter_count)
1642 : END IF
1643 :
1644 246204 : DO iatom = 1, natom
1645 1246566 : mcharge(iatom) = SUM(charges(iatom, :))
1646 : END DO
1647 : END IF
1648 :
1649 23022 : IF (dft_control%qs_control%xtb_control%coulomb_interaction) THEN
1650 : CALL build_xtb_coulomb(qs_env, ks_matrix, rho, charges, mcharge, energy, &
1651 21140 : calculate_forces, just_energy)
1652 : END IF
1653 :
1654 23022 : IF (do_efield) THEN
1655 5894 : CALL efield_tb_matrix(qs_env, ks_matrix, rho, mcharge, energy, calculate_forces, just_energy)
1656 : END IF
1657 :
1658 23022 : IF (dft_control%qs_control%xtb_control%coulomb_interaction) THEN
1659 21140 : IF (dft_control%qs_control%xtb_control%check_atomic_charges) THEN
1660 20282 : pass_check = .TRUE.
1661 73410 : DO ikind = 1, nkind
1662 53128 : CALL get_atomic_kind(atomic_kind_set(ikind), natom=na)
1663 53128 : CALL get_qs_kind(qs_kind_set(ikind), xtb_parameter=xtb_kind)
1664 53128 : CALL get_xtb_atom_param(xtb_kind, chmax=chmax)
1665 326138 : DO iatom = 1, na
1666 199600 : atom_a = atomic_kind_set(ikind)%atom_list(iatom)
1667 199600 : achrg = mcharge(atom_a)
1668 252728 : IF (ABS(achrg) > chmax) THEN
1669 0 : IF (iounit > 0) THEN
1670 0 : WRITE (iounit, "(A,A,I3,I6,A,F4.2,A,F6.2)") " Charge outside chemical range:", &
1671 0 : " Kind Atom=", ikind, atom_a, " Limit=", chmax, " Charge=", achrg
1672 : END IF
1673 : pass_check = .FALSE.
1674 : END IF
1675 : END DO
1676 : END DO
1677 20282 : IF (.NOT. pass_check) THEN
1678 : CALL cp_warn(__LOCATION__, "Atomic charges outside chemical range were detected."// &
1679 : " Switch-off CHECK_ATOMIC_CHARGES keyword in the &xTB section"// &
1680 0 : " if you want to force to continue the calculation.")
1681 0 : CPABORT("xTB Charges")
1682 : END IF
1683 : END IF
1684 : END IF
1685 :
1686 23022 : IF (dft_control%qs_control%xtb_control%coulomb_interaction .OR. do_efield) THEN
1687 21140 : DEALLOCATE (mcharge, charges)
1688 : END IF
1689 :
1690 23022 : IF (qs_env%qmmm) THEN
1691 5146 : CPASSERT(SIZE(ks_matrix, 2) == 1)
1692 10292 : DO ispin = 1, nspins
1693 : ! If QM/MM sumup the 1el Hamiltonian
1694 : CALL dbcsr_add(ks_matrix(ispin, 1)%matrix, qs_env%ks_qmmm_env%matrix_h(1)%matrix, &
1695 5146 : 1.0_dp, 1.0_dp)
1696 5146 : CALL qs_rho_get(rho, rho_ao=matrix_p1)
1697 : ! Compute QM/MM Energy
1698 : CALL dbcsr_dot(qs_env%ks_qmmm_env%matrix_h(1)%matrix, &
1699 5146 : matrix_p1(ispin)%matrix, qmmm_el)
1700 10292 : energy%qmmm_el = energy%qmmm_el + qmmm_el
1701 : END DO
1702 5146 : pc_ener = qs_env%ks_qmmm_env%pc_ener
1703 5146 : energy%qmmm_el = energy%qmmm_el + pc_ener
1704 : END IF
1705 :
1706 : energy%total = energy%core + energy%hartree + energy%efield + energy%qmmm_el + &
1707 23022 : energy%repulsive + energy%dispersion + energy%dftb3
1708 :
1709 : iounit = cp_print_key_unit_nr(logger, scf_section, "PRINT%DETAILED_ENERGY", &
1710 23022 : extension=".scfLog")
1711 23022 : IF (iounit > 0) THEN
1712 : WRITE (UNIT=iounit, FMT="(/,(T9,A,T60,F20.10))") &
1713 0 : "Repulsive pair potential energy: ", energy%repulsive, &
1714 0 : "Zeroth order Hamiltonian energy: ", energy%core, &
1715 0 : "Charge fluctuation energy: ", energy%hartree, &
1716 0 : "London dispersion energy: ", energy%dispersion
1717 0 : IF (dft_control%qs_control%xtb_control%xb_interaction) &
1718 : WRITE (UNIT=iounit, FMT="(T9,A,T60,F20.10)") &
1719 0 : "Correction for halogen bonding: ", energy%xtb_xb_inter
1720 0 : IF (dft_control%qs_control%xtb_control%do_nonbonded) &
1721 : WRITE (UNIT=iounit, FMT="(T9,A,T60,F20.10)") &
1722 0 : "Correction for nonbonded interactions: ", energy%xtb_nonbonded
1723 0 : IF (ABS(energy%efield) > 1.e-12_dp) THEN
1724 : WRITE (UNIT=iounit, FMT="(T9,A,T60,F20.10)") &
1725 0 : "Electric field interaction energy: ", energy%efield
1726 : END IF
1727 : WRITE (UNIT=iounit, FMT="(T9,A,T60,F20.10)") &
1728 0 : "DFTB3 3rd Order Energy Correction ", energy%dftb3
1729 0 : IF (qs_env%qmmm) THEN
1730 : WRITE (UNIT=iounit, FMT="(T9,A,T60,F20.10)") &
1731 0 : "QM/MM Electrostatic energy: ", energy%qmmm_el
1732 : END IF
1733 : END IF
1734 : CALL cp_print_key_finished_output(iounit, logger, scf_section, &
1735 23022 : "PRINT%DETAILED_ENERGY")
1736 : ! here we compute dE/dC if needed. Assumes dE/dC is H_{ks}C
1737 23022 : IF (qs_env%requires_mo_derivs .AND. .NOT. just_energy) THEN
1738 7236 : CPASSERT(SIZE(ks_matrix, 2) == 1)
1739 : BLOCK
1740 7236 : TYPE(mo_set_type), DIMENSION(:), POINTER :: mo_array
1741 7236 : CALL get_qs_env(qs_env, mo_derivs=mo_derivs, mos=mo_array)
1742 14520 : DO ispin = 1, SIZE(mo_derivs)
1743 7284 : CALL get_mo_set(mo_set=mo_array(ispin), mo_coeff_b=mo_coeff)
1744 7284 : IF (.NOT. mo_array(ispin)%use_mo_coeff_b) THEN
1745 0 : CPABORT("")
1746 : END IF
1747 : CALL dbcsr_multiply('n', 'n', 1.0_dp, ks_matrix(ispin, 1)%matrix, mo_coeff, &
1748 14520 : 0.0_dp, mo_derivs(ispin)%matrix)
1749 : END DO
1750 : END BLOCK
1751 : END IF
1752 :
1753 23022 : CALL timestop(handle)
1754 :
1755 46044 : END SUBROUTINE build_xtb_ks_matrix
1756 :
1757 : ! **************************************************************************************************
1758 : !> \brief Distributes the neighbor atom information to all processors
1759 : !>
1760 : !> \param neighbor_atoms ...
1761 : !> \param para_env ...
1762 : !> \par History
1763 : !> 1.2019 JGH
1764 : !> \version 1.1
1765 : ! **************************************************************************************************
1766 3184 : SUBROUTINE xb_neighbors(neighbor_atoms, para_env)
1767 : TYPE(neighbor_atoms_type), DIMENSION(:), &
1768 : INTENT(INOUT) :: neighbor_atoms
1769 : TYPE(mp_para_env_type), POINTER :: para_env
1770 :
1771 : INTEGER :: iatom, ikind, natom, nkind
1772 3184 : INTEGER, ALLOCATABLE, DIMENSION(:) :: matom
1773 3184 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:) :: dmloc
1774 3184 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :) :: coord
1775 :
1776 3184 : nkind = SIZE(neighbor_atoms)
1777 11012 : DO ikind = 1, nkind
1778 11012 : IF (ASSOCIATED(neighbor_atoms(ikind)%rab)) THEN
1779 58 : natom = SIZE(neighbor_atoms(ikind)%rab)
1780 406 : ALLOCATE (dmloc(2*natom), matom(natom), coord(3, natom))
1781 174 : dmloc = 0.0_dp
1782 116 : DO iatom = 1, natom
1783 58 : dmloc(2*iatom - 1) = neighbor_atoms(ikind)%rab(iatom)
1784 116 : dmloc(2*iatom) = REAL(para_env%mepos, KIND=dp)
1785 : END DO
1786 58 : CALL para_env%minloc(dmloc)
1787 290 : coord = 0.0_dp
1788 116 : matom = 0
1789 116 : DO iatom = 1, natom
1790 58 : neighbor_atoms(ikind)%rab(iatom) = dmloc(2*iatom - 1)
1791 116 : IF (NINT(dmloc(2*iatom)) == para_env%mepos) THEN
1792 116 : coord(1:3, iatom) = neighbor_atoms(ikind)%coord(1:3, iatom)
1793 29 : matom(iatom) = neighbor_atoms(ikind)%katom(iatom)
1794 : END IF
1795 : END DO
1796 58 : CALL para_env%sum(coord)
1797 290 : neighbor_atoms(ikind)%coord(1:3, :) = coord(1:3, :)
1798 58 : CALL para_env%sum(matom)
1799 116 : neighbor_atoms(ikind)%katom(:) = matom(:)
1800 58 : DEALLOCATE (dmloc, matom, coord)
1801 : END IF
1802 : END DO
1803 :
1804 3184 : END SUBROUTINE xb_neighbors
1805 : ! **************************************************************************************************
1806 : !> \brief Computes a correction for nonbonded interactions based on a generic potential
1807 : !>
1808 : !> \param enonbonded energy contribution
1809 : !> \param force ...
1810 : !> \param qs_env ...
1811 : !> \param xtb_control ...
1812 : !> \param sab_xtb_nonbond ...
1813 : !> \param atomic_kind_set ...
1814 : !> \param calculate_forces ...
1815 : !> \param use_virial ...
1816 : !> \param virial ...
1817 : !> \param atprop ...
1818 : !> \param atom_of_kind ..
1819 : !> \par History
1820 : !> 12.2018 JGH
1821 : !> \version 1.1
1822 : ! **************************************************************************************************
1823 68 : SUBROUTINE nonbonded_correction(enonbonded, force, qs_env, xtb_control, sab_xtb_nonbond, &
1824 34 : atomic_kind_set, calculate_forces, use_virial, virial, atprop, atom_of_kind)
1825 : REAL(dp), INTENT(INOUT) :: enonbonded
1826 : TYPE(qs_force_type), DIMENSION(:), INTENT(INOUT), &
1827 : POINTER :: force
1828 : TYPE(qs_environment_type), POINTER :: qs_env
1829 : TYPE(xtb_control_type), POINTER :: xtb_control
1830 : TYPE(neighbor_list_set_p_type), DIMENSION(:), &
1831 : INTENT(IN), POINTER :: sab_xtb_nonbond
1832 : TYPE(atomic_kind_type), DIMENSION(:), INTENT(IN), &
1833 : POINTER :: atomic_kind_set
1834 : LOGICAL, INTENT(IN) :: calculate_forces, use_virial
1835 : TYPE(virial_type), INTENT(IN), POINTER :: virial
1836 : TYPE(atprop_type), INTENT(IN), POINTER :: atprop
1837 : INTEGER, DIMENSION(:), INTENT(IN) :: atom_of_kind
1838 :
1839 : CHARACTER(len=*), PARAMETER :: routineN = 'nonbonded_correction'
1840 :
1841 : CHARACTER(LEN=default_string_length) :: def_error, this_error
1842 : INTEGER :: atom_i, atom_j, handle, iatom, ikind, &
1843 : jatom, jkind, kk, ntype
1844 : INTEGER, DIMENSION(3) :: cell
1845 : LOGICAL :: do_ewald
1846 : REAL(KIND=dp) :: dedf, dr, dx, energy_cutoff, err, fval, &
1847 : lerr, rcut
1848 : REAL(KIND=dp), DIMENSION(3) :: fij, rij
1849 : TYPE(ewald_environment_type), POINTER :: ewald_env
1850 : TYPE(neighbor_list_iterator_p_type), &
1851 34 : DIMENSION(:), POINTER :: nl_iterator
1852 : TYPE(pair_potential_p_type), POINTER :: nonbonded
1853 : TYPE(pair_potential_pp_type), POINTER :: potparm
1854 : TYPE(pair_potential_single_type), POINTER :: pot
1855 : TYPE(section_vals_type), POINTER :: nonbonded_section
1856 :
1857 34 : CALL timeset(routineN, handle)
1858 :
1859 : NULLIFY (nonbonded)
1860 34 : NULLIFY (potparm)
1861 34 : NULLIFY (ewald_env)
1862 34 : nonbonded => xtb_control%nonbonded
1863 34 : do_ewald = xtb_control%do_ewald
1864 34 : CALL get_qs_env(qs_env=qs_env, ewald_env=ewald_env)
1865 :
1866 34 : ntype = SIZE(atomic_kind_set)
1867 34 : CALL pair_potential_pp_create(potparm, ntype)
1868 : !Assign input and potential info to potparm_nonbond
1869 34 : CALL force_field_pack_nonbond_pot_correction(atomic_kind_set, nonbonded, potparm, ewald_env, do_ewald)
1870 : !Initialize genetic potential
1871 34 : CALL init_genpot(potparm, ntype)
1872 :
1873 34 : NULLIFY (pot)
1874 34 : enonbonded = 0._dp
1875 34 : energy_cutoff = 0._dp
1876 :
1877 34 : CALL neighbor_list_iterator_create(nl_iterator, sab_xtb_nonbond)
1878 227 : DO WHILE (neighbor_list_iterate(nl_iterator) == 0)
1879 : CALL get_iterator_info(nl_iterator, ikind=ikind, jkind=jkind, &
1880 193 : iatom=iatom, jatom=jatom, r=rij, cell=cell)
1881 193 : pot => potparm%pot(ikind, jkind)%pot
1882 193 : dr = SQRT(rij(1)**2 + rij(2)**2 + rij(3)**2)
1883 193 : rcut = SQRT(pot%rcutsq)
1884 193 : IF (dr <= rcut .AND. dr > 1.E-3_dp) THEN
1885 25 : fval = 1.0_dp
1886 25 : IF (ikind == jkind) fval = 0.5_dp
1887 : ! splines not implemented
1888 25 : enonbonded = enonbonded + fval*ener_pot(pot, dr, energy_cutoff)
1889 25 : IF (atprop%energy) THEN
1890 16 : atprop%atecc(iatom) = atprop%atecc(iatom) + 0.5_dp*fval*ener_pot(pot, dr, energy_cutoff)
1891 16 : atprop%atecc(jatom) = atprop%atecc(jatom) + 0.5_dp*fval*ener_pot(pot, dr, energy_cutoff)
1892 : END IF
1893 : END IF
1894 :
1895 193 : IF (calculate_forces) THEN
1896 :
1897 93 : kk = SIZE(pot%type)
1898 93 : IF (kk /= 1) THEN
1899 0 : CALL cp_warn(__LOCATION__, "Generic potential with type > 1 not implemented.")
1900 0 : CPABORT("pot type")
1901 : END IF
1902 : ! rmin and rmax and rcut
1903 93 : IF ((pot%set(kk)%rmin /= not_initialized) .AND. (dr < pot%set(kk)%rmin)) CYCLE
1904 : ! An upper boundary for the potential definition was defined
1905 93 : IF ((pot%set(kk)%rmax /= not_initialized) .AND. (dr >= pot%set(kk)%rmax)) CYCLE
1906 : ! If within limits let's compute the potential...
1907 93 : IF (dr <= rcut .AND. dr > 1.E-3_dp) THEN
1908 :
1909 9 : NULLIFY (nonbonded_section)
1910 9 : nonbonded_section => section_vals_get_subs_vals(qs_env%input, "DFT%QS%xTB%NONBONDED")
1911 9 : CALL section_vals_val_get(nonbonded_section, "DX", r_val=dx)
1912 9 : CALL section_vals_val_get(nonbonded_section, "ERROR_LIMIT", r_val=lerr)
1913 :
1914 9 : dedf = fval*evalfd(pot%set(kk)%gp%myid, 1, pot%set(kk)%gp%values, dx, err)
1915 9 : IF (ABS(err) > lerr) THEN
1916 1 : WRITE (this_error, "(A,G12.6,A)") "(", err, ")"
1917 1 : WRITE (def_error, "(A,G12.6,A)") "(", lerr, ")"
1918 1 : CALL compress(this_error, .TRUE.)
1919 1 : CALL compress(def_error, .TRUE.)
1920 : CALL cp_warn(__LOCATION__, &
1921 : 'ASSERTION (cond) failed at line '//cp_to_string(__LINE__)// &
1922 : ' Error '//TRIM(this_error)//' in computing numerical derivatives larger then'// &
1923 1 : TRIM(def_error)//' .')
1924 : END IF
1925 :
1926 9 : atom_i = atom_of_kind(iatom)
1927 9 : atom_j = atom_of_kind(jatom)
1928 :
1929 36 : fij(1:3) = dedf*rij(1:3)/pot%set(kk)%gp%values(1)
1930 :
1931 36 : force(ikind)%repulsive(:, atom_i) = force(ikind)%repulsive(:, atom_i) - fij(:)
1932 36 : force(jkind)%repulsive(:, atom_j) = force(jkind)%repulsive(:, atom_j) + fij(:)
1933 :
1934 9 : IF (use_virial) THEN
1935 8 : CALL virial_pair_force(virial%pv_virial, -1._dp, fij, rij)
1936 8 : IF (atprop%stress) THEN
1937 8 : CALL virial_pair_force(atprop%atstress(:, :, iatom), -0.5_dp, fij, rij)
1938 8 : CALL virial_pair_force(atprop%atstress(:, :, jatom), -0.5_dp, fij, rij)
1939 : END IF
1940 : END IF
1941 :
1942 : END IF
1943 : END IF
1944 193 : NULLIFY (pot)
1945 : END DO
1946 34 : CALL neighbor_list_iterator_release(nl_iterator)
1947 34 : CALL finalizef()
1948 :
1949 34 : IF (ASSOCIATED(potparm)) THEN
1950 34 : CALL pair_potential_pp_release(potparm)
1951 : END IF
1952 :
1953 34 : CALL timestop(handle)
1954 :
1955 34 : END SUBROUTINE nonbonded_correction
1956 : ! **************************************************************************************************
1957 : !> \brief ...
1958 : !> \param atomic_kind_set ...
1959 : !> \param nonbonded ...
1960 : !> \param potparm ...
1961 : !> \param ewald_env ...
1962 : !> \param do_ewald ...
1963 : ! **************************************************************************************************
1964 34 : SUBROUTINE force_field_pack_nonbond_pot_correction(atomic_kind_set, nonbonded, potparm, ewald_env, do_ewald)
1965 :
1966 : ! routine based on force_field_pack_nonbond
1967 : TYPE(atomic_kind_type), DIMENSION(:), INTENT(IN), &
1968 : POINTER :: atomic_kind_set
1969 : TYPE(pair_potential_p_type), INTENT(IN), POINTER :: nonbonded
1970 : TYPE(pair_potential_pp_type), INTENT(INOUT), &
1971 : POINTER :: potparm
1972 : TYPE(ewald_environment_type), INTENT(IN), POINTER :: ewald_env
1973 : LOGICAL, INTENT(IN) :: do_ewald
1974 :
1975 : CHARACTER(LEN=default_string_length) :: name_atm_a, name_atm_a_local, &
1976 : name_atm_b, name_atm_b_local
1977 : INTEGER :: ikind, ingp, iw, jkind
1978 : LOGICAL :: found
1979 : REAL(KIND=dp) :: ewald_rcut
1980 : TYPE(atomic_kind_type), POINTER :: atomic_kind
1981 : TYPE(cp_logger_type), POINTER :: logger
1982 : TYPE(pair_potential_single_type), POINTER :: pot
1983 :
1984 34 : NULLIFY (pot, logger)
1985 :
1986 34 : logger => cp_get_default_logger()
1987 34 : iw = cp_logger_get_default_io_unit(logger)
1988 :
1989 170 : DO ikind = 1, SIZE(atomic_kind_set)
1990 136 : atomic_kind => atomic_kind_set(ikind)
1991 136 : CALL get_atomic_kind(atomic_kind=atomic_kind, name=name_atm_a_local)
1992 510 : DO jkind = ikind, SIZE(atomic_kind_set)
1993 340 : atomic_kind => atomic_kind_set(jkind)
1994 340 : CALL get_atomic_kind(atomic_kind=atomic_kind, name=name_atm_b_local)
1995 340 : found = .FALSE.
1996 340 : name_atm_a = name_atm_a_local
1997 340 : name_atm_b = name_atm_b_local
1998 340 : CALL uppercase(name_atm_a)
1999 340 : CALL uppercase(name_atm_b)
2000 340 : pot => potparm%pot(ikind, jkind)%pot
2001 340 : IF (ASSOCIATED(nonbonded)) THEN
2002 680 : DO ingp = 1, SIZE(nonbonded%pot)
2003 340 : IF ((TRIM(nonbonded%pot(ingp)%pot%at1) == "*") .OR. &
2004 : (TRIM(nonbonded%pot(ingp)%pot%at2) == "*")) CYCLE
2005 :
2006 : !IF (iw > 0) WRITE (iw, *) "TESTING ", TRIM(name_atm_a), TRIM(name_atm_b), &
2007 : ! " with ", TRIM(nonbonded%pot(ingp)%pot%at1), &
2008 : ! TRIM(nonbonded%pot(ingp)%pot%at2)
2009 : IF ((((name_atm_a) == (nonbonded%pot(ingp)%pot%at1)) .AND. &
2010 340 : ((name_atm_b) == (nonbonded%pot(ingp)%pot%at2))) .OR. &
2011 : (((name_atm_b) == (nonbonded%pot(ingp)%pot%at1)) .AND. &
2012 340 : ((name_atm_a) == (nonbonded%pot(ingp)%pot%at2)))) THEN
2013 34 : CALL pair_potential_single_copy(nonbonded%pot(ingp)%pot, pot)
2014 : ! multiple potential not implemented, simply overwriting
2015 34 : IF (found) &
2016 : CALL cp_warn(__LOCATION__, &
2017 : "Multiple NONBONDED declaration: "//TRIM(name_atm_a)// &
2018 0 : " and "//TRIM(name_atm_b)//" OVERWRITING! ")
2019 : !IF (iw > 0) WRITE (iw, *) " FOUND ", TRIM(name_atm_a), " ", TRIM(name_atm_b)
2020 : found = .TRUE.
2021 : END IF
2022 : END DO
2023 : END IF
2024 476 : IF (.NOT. found) THEN
2025 306 : CALL pair_potential_single_clean(pot)
2026 : !IF (iw > 0) WRITE (iw, *) " NOTFOUND ", TRIM(name_atm_a), " ", TRIM(name_atm_b)
2027 : END IF
2028 : END DO !jkind
2029 : END DO !ikind
2030 :
2031 : ! Cutoff is defined always as the maximum between the FF and Ewald
2032 34 : IF (do_ewald) THEN
2033 16 : CALL ewald_env_get(ewald_env, rcut=ewald_rcut)
2034 16 : pot%rcutsq = MAX(pot%rcutsq, ewald_rcut*ewald_rcut)
2035 : !IF (iw > 0) WRITE (iw, *) " RCUT ", SQRT(pot%rcutsq), ewald_rcut
2036 : END IF
2037 :
2038 34 : END SUBROUTINE force_field_pack_nonbond_pot_correction
2039 : ! **************************************************************************************************
2040 : !> \brief Computes the interaction term between Br/I/At and donor atoms
2041 : !>
2042 : !> \param exb ...
2043 : !> \param neighbor_atoms ...
2044 : !> \param atom_of_kind ...
2045 : !> \param kind_of ...
2046 : !> \param sab_xb ...
2047 : !> \param kx ...
2048 : !> \param kx2 ...
2049 : !> \param rcab ...
2050 : !> \param calculate_forces ...
2051 : !> \param use_virial ...
2052 : !> \param force ...
2053 : !> \param virial ...
2054 : !> \param atprop ...
2055 : !> \par History
2056 : !> 12.2018 JGH
2057 : !> \version 1.1
2058 : ! **************************************************************************************************
2059 3184 : SUBROUTINE xb_interaction(exb, neighbor_atoms, atom_of_kind, kind_of, sab_xb, kx, kx2, rcab, &
2060 : calculate_forces, use_virial, force, virial, atprop)
2061 : REAL(dp), INTENT(INOUT) :: exb
2062 : TYPE(neighbor_atoms_type), DIMENSION(:), &
2063 : INTENT(IN) :: neighbor_atoms
2064 : INTEGER, DIMENSION(:), INTENT(IN) :: atom_of_kind, kind_of
2065 : TYPE(neighbor_list_set_p_type), DIMENSION(:), &
2066 : POINTER :: sab_xb
2067 : REAL(dp), DIMENSION(:), INTENT(IN) :: kx
2068 : REAL(dp), INTENT(IN) :: kx2
2069 : REAL(dp), DIMENSION(:, :), INTENT(IN) :: rcab
2070 : LOGICAL, INTENT(IN) :: calculate_forces, use_virial
2071 : TYPE(qs_force_type), DIMENSION(:), POINTER :: force
2072 : TYPE(virial_type), POINTER :: virial
2073 : TYPE(atprop_type), POINTER :: atprop
2074 :
2075 : INTEGER :: atom_a, atom_b, atom_c, iatom, ikind, &
2076 : jatom, jkind, katom, kkind
2077 : INTEGER, DIMENSION(3) :: cell
2078 : REAL(KIND=dp) :: alp, aterm, cosa, daterm, ddab, ddax, &
2079 : ddbx, ddr, ddr12, ddr6, deval, dr, &
2080 : drab, drax, drbx, eval, xy
2081 : REAL(KIND=dp), DIMENSION(3) :: fia, fij, fja, ria, rij, rja
2082 : TYPE(neighbor_list_iterator_p_type), &
2083 3184 : DIMENSION(:), POINTER :: nl_iterator
2084 :
2085 : ! exonent in angular term
2086 3184 : alp = 6.0_dp
2087 : ! loop over all atom pairs
2088 3184 : CALL neighbor_list_iterator_create(nl_iterator, sab_xb)
2089 3196 : DO WHILE (neighbor_list_iterate(nl_iterator) == 0)
2090 : CALL get_iterator_info(nl_iterator, ikind=ikind, jkind=jkind, &
2091 12 : iatom=iatom, jatom=jatom, r=rij, cell=cell)
2092 : ! ikind, iatom : Halogen
2093 : ! jkind, jatom : Donor
2094 12 : atom_a = atom_of_kind(iatom)
2095 12 : katom = neighbor_atoms(ikind)%katom(atom_a)
2096 12 : IF (katom == 0) CYCLE
2097 12 : dr = SQRT(rij(1)**2 + rij(2)**2 + rij(3)**2)
2098 12 : ddr = rcab(ikind, jkind)/dr
2099 12 : ddr6 = ddr**6
2100 12 : ddr12 = ddr6*ddr6
2101 12 : eval = kx(ikind)*(ddr12 - kx2*ddr6)/(1.0_dp + ddr12)
2102 : ! angle
2103 48 : ria(1:3) = neighbor_atoms(ikind)%coord(1:3, atom_a)
2104 48 : rja(1:3) = rij(1:3) - ria(1:3)
2105 12 : drax = ria(1)**2 + ria(2)**2 + ria(3)**2
2106 12 : drbx = dr*dr
2107 12 : drab = rja(1)**2 + rja(2)**2 + rja(3)**2
2108 12 : xy = SQRT(drbx*drax)
2109 : ! cos angle B-X-A
2110 12 : cosa = (drbx + drax - drab)/xy
2111 12 : aterm = (0.5_dp - 0.25_dp*cosa)**alp
2112 : !
2113 12 : exb = exb + aterm*eval
2114 12 : IF (atprop%energy) THEN
2115 0 : atprop%atecc(iatom) = atprop%atecc(iatom) + 0.5_dp*aterm*eval
2116 0 : atprop%atecc(jatom) = atprop%atecc(jatom) + 0.5_dp*aterm*eval
2117 : END IF
2118 : !
2119 3196 : IF (calculate_forces) THEN
2120 6 : kkind = kind_of(katom)
2121 6 : atom_b = atom_of_kind(jatom)
2122 6 : atom_c = atom_of_kind(katom)
2123 : !
2124 6 : deval = 6.0_dp*kx(ikind)*ddr6*(kx2*ddr12 + 2.0_dp*ddr6 - kx2)/(1.0_dp + ddr12)**2
2125 6 : deval = -rcab(ikind, jkind)*deval/(dr*dr)/ddr
2126 24 : fij(1:3) = aterm*deval*rij(1:3)/dr
2127 24 : force(ikind)%repulsive(:, atom_a) = force(ikind)%repulsive(:, atom_a) - fij(:)
2128 24 : force(jkind)%repulsive(:, atom_b) = force(jkind)%repulsive(:, atom_b) + fij(:)
2129 6 : IF (use_virial) THEN
2130 0 : CALL virial_pair_force(virial%pv_virial, -1._dp, fij, rij)
2131 0 : IF (atprop%stress) THEN
2132 0 : CALL virial_pair_force(atprop%atstress(:, :, iatom), -0.5_dp, fij, rij)
2133 0 : CALL virial_pair_force(atprop%atstress(:, :, jatom), -0.5_dp, fij, rij)
2134 : END IF
2135 : END IF
2136 : !
2137 6 : fij(1:3) = 0.0_dp
2138 6 : fia(1:3) = 0.0_dp
2139 6 : fja(1:3) = 0.0_dp
2140 6 : daterm = -0.25_dp*alp*(0.5_dp - 0.25_dp*cosa)**(alp - 1.0_dp)
2141 6 : ddbx = 0.5_dp*(drab - drax + drbx)/xy/drbx
2142 6 : ddax = 0.5_dp*(drab + drax - drbx)/xy/drax
2143 6 : ddab = -1._dp/xy
2144 24 : fij(1:3) = 2.0_dp*daterm*ddbx*rij(1:3)*eval
2145 24 : fia(1:3) = 2.0_dp*daterm*ddax*ria(1:3)*eval
2146 24 : fja(1:3) = 2.0_dp*daterm*ddab*rja(1:3)*eval
2147 24 : force(ikind)%repulsive(:, atom_a) = force(ikind)%repulsive(:, atom_a) - fij(:) - fia(:)
2148 24 : force(jkind)%repulsive(:, atom_b) = force(jkind)%repulsive(:, atom_b) + fij(:) + fja(:)
2149 24 : force(kkind)%repulsive(:, atom_c) = force(kkind)%repulsive(:, atom_c) + fia(:) - fja(:)
2150 6 : IF (use_virial) THEN
2151 0 : CALL virial_pair_force(virial%pv_virial, -1._dp, fij, rij)
2152 0 : CALL virial_pair_force(virial%pv_virial, -1._dp, fia, ria)
2153 0 : CALL virial_pair_force(virial%pv_virial, -1._dp, fja, rja)
2154 0 : IF (atprop%stress) THEN
2155 0 : CALL virial_pair_force(atprop%atstress(:, :, iatom), -0.5_dp, fij, rij)
2156 0 : CALL virial_pair_force(atprop%atstress(:, :, jatom), -0.5_dp, fij, rij)
2157 0 : CALL virial_pair_force(atprop%atstress(:, :, iatom), -0.5_dp, fia, ria)
2158 0 : CALL virial_pair_force(atprop%atstress(:, :, katom), -0.5_dp, fia, ria)
2159 0 : CALL virial_pair_force(atprop%atstress(:, :, jatom), -0.5_dp, fja, rja)
2160 0 : CALL virial_pair_force(atprop%atstress(:, :, katom), -0.5_dp, fja, rja)
2161 : END IF
2162 : END IF
2163 : END IF
2164 : END DO
2165 3184 : CALL neighbor_list_iterator_release(nl_iterator)
2166 :
2167 3184 : END SUBROUTINE xb_interaction
2168 :
2169 : ! **************************************************************************************************
2170 : !> \brief ...
2171 : !> \param z ...
2172 : !> \return ...
2173 : ! **************************************************************************************************
2174 7866 : FUNCTION metal(z) RESULT(ismetal)
2175 : INTEGER :: z
2176 : LOGICAL :: ismetal
2177 :
2178 7866 : SELECT CASE (z)
2179 : CASE DEFAULT
2180 7816 : ismetal = .TRUE.
2181 : CASE (1:2, 6:10, 14:18, 32:36, 50:54, 82:86)
2182 7866 : ismetal = .FALSE.
2183 : END SELECT
2184 :
2185 7866 : END FUNCTION metal
2186 :
2187 : ! **************************************************************************************************
2188 : !> \brief ...
2189 : !> \param z ...
2190 : !> \return ...
2191 : ! **************************************************************************************************
2192 7816 : FUNCTION early3d(z) RESULT(isearly3d)
2193 : INTEGER :: z
2194 : LOGICAL :: isearly3d
2195 :
2196 7816 : isearly3d = .FALSE.
2197 7816 : IF (z >= 21 .AND. z <= 24) isearly3d = .TRUE.
2198 :
2199 7816 : END FUNCTION early3d
2200 :
2201 0 : END MODULE xtb_matrices
2202 :
|