83 SUBROUTINE build_tnadd_mat(kg_env, matrix_p, force, virial, calculate_forces, use_virial, &
84 qs_kind_set, atomic_kind_set, particle_set, sab_orb, dbcsr_dist)
90 LOGICAL,
INTENT(IN) :: calculate_forces
99 CHARACTER(LEN=*),
PARAMETER :: routinen =
'build_tnadd_mat'
100 INTEGER,
PARAMETER :: nexp_max = 10
102 INTEGER :: atom_a, atom_b, atom_c, handle, i, iatom, icol, ikind, img, imol, inode, irow, &
103 iset, jatom, jkind, jmol, jset, katom, kkind, kmol, last_iatom, last_jatom, ldai, ldsab, &
104 maxco, maxder, maxl, maxlgto, maxnset, maxpol, maxsgf, mepos, natom, ncoa, ncob, nder, &
105 ngau, nkind, npol, nseta, nsetb, nthread, sgfa, sgfb
106 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: atom_of_kind
107 INTEGER,
DIMENSION(:),
POINTER :: atom_to_molecule, col_blk_sizes, la_max, &
108 la_min, lb_max, lb_min, npgfa, npgfb, &
109 nsgfa, nsgfb, row_blk_sizes
110 INTEGER,
DIMENSION(:, :),
POINTER :: first_sgfa, first_sgfb
111 INTEGER,
DIMENSION(nexp_max) :: nct
112 LOGICAL :: found, new_atom_pair
113 REAL(kind=
dp) :: dab, dac, dbc, f0, radius
114 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: work
115 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :, :) :: ppl_fwork, ppl_work
116 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :, :, :) :: hab, pab
117 REAL(kind=
dp),
DIMENSION(3) :: force_a, force_b, rab, rac, rbc
118 REAL(kind=
dp),
DIMENSION(:),
POINTER :: alpha, set_radius_a, set_radius_b
119 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: ccval, cval, h_block, p_block, rpgfa, &
120 rpgfb, sphi_a, sphi_b, zeta, zetb
126 DIMENSION(:),
POINTER :: ap_iterator, nl_iterator
130 IF (calculate_forces)
THEN
131 CALL timeset(routinen//
"_forces", handle)
133 CALL timeset(routinen, handle)
137 IF (
ASSOCIATED(kg_env%tnadd_mat))
THEN
140 sac_kin => kg_env%sac_kin
141 atom_to_molecule => kg_env%atom_to_molecule
143 nkind =
SIZE(atomic_kind_set)
144 natom =
SIZE(particle_set)
148 IF (calculate_forces)
THEN
150 IF (
SIZE(matrix_p, 1) == 2)
THEN
151 DO img = 1,
SIZE(matrix_p, 2)
152 CALL dbcsr_add(matrix_p(1, img)%matrix, matrix_p(2, img)%matrix, &
153 alpha_scalar=1.0_dp, beta_scalar=1.0_dp)
154 CALL dbcsr_add(matrix_p(2, img)%matrix, matrix_p(1, img)%matrix, &
155 alpha_scalar=-2.0_dp, beta_scalar=1.0_dp)
164 CALL get_qs_kind_set(qs_kind_set, maxpol=maxpol, maxco=maxco, maxlgto=maxlgto, &
165 maxsgf=maxsgf, maxnset=maxnset)
167 maxl = max(maxlgto, maxpol)
170 ldsab = max(maxco,
ncoset(maxpol), maxsgf, maxpol)
171 ldai =
ncoset(maxl + nder + 1)
173 ALLOCATE (basis_set_list(nkind))
175 CALL get_qs_kind(qs_kind_set(ikind), basis_set=basis_set_a)
176 IF (
ASSOCIATED(basis_set_a))
THEN
177 basis_set_list(ikind)%gto_basis_set => basis_set_a
179 NULLIFY (basis_set_list(ikind)%gto_basis_set)
184 ALLOCATE (row_blk_sizes(natom), col_blk_sizes(natom))
191 ALLOCATE (matrix_kg(1)%matrix)
193 name=
"Nonadditive kinetic energy potential", &
194 dist=dbcsr_dist, matrix_type=dbcsr_type_symmetric, &
195 row_blk_size=row_blk_sizes, col_blk_size=col_blk_sizes, &
198 CALL dbcsr_set(matrix_kg(1)%matrix, 0.0_dp)
228 ALLOCATE (hab(ldsab, ldsab, maxnset, maxnset), work(ldsab, ldsab*maxder))
229 ldai =
ncoset(2*maxlgto + 2*nder)
230 ALLOCATE (ppl_work(ldai, ldai, max(maxder, 2*maxlgto + 2*nder + 1)))
231 IF (calculate_forces)
THEN
232 ALLOCATE (pab(maxco, maxco, maxnset, maxnset))
234 ALLOCATE (ppl_fwork(ldai, ldai, maxder))
241 CALL get_iterator_info(nl_iterator, mepos=mepos, ikind=ikind, jkind=jkind, inode=inode, &
242 iatom=iatom, jatom=jatom, r=rab)
244 basis_set_a => basis_set_list(ikind)%gto_basis_set
245 IF (.NOT.
ASSOCIATED(basis_set_a)) cycle
246 basis_set_b => basis_set_list(jkind)%gto_basis_set
247 IF (.NOT.
ASSOCIATED(basis_set_b)) cycle
249 atom_a = atom_of_kind(iatom)
250 atom_b = atom_of_kind(jatom)
251 imol = atom_to_molecule(iatom)
252 jmol = atom_to_molecule(jatom)
253 cpassert(imol == jmol)
256 first_sgfa => basis_set_a%first_sgf
257 la_max => basis_set_a%lmax
258 la_min => basis_set_a%lmin
259 npgfa => basis_set_a%npgf
260 nseta = basis_set_a%nset
261 nsgfa => basis_set_a%nsgf_set
262 rpgfa => basis_set_a%pgf_radius
263 set_radius_a => basis_set_a%set_radius
264 sphi_a => basis_set_a%sphi
265 zeta => basis_set_a%zet
267 first_sgfb => basis_set_b%first_sgf
268 lb_max => basis_set_b%lmax
269 lb_min => basis_set_b%lmin
270 npgfb => basis_set_b%npgf
271 nsetb = basis_set_b%nset
272 nsgfb => basis_set_b%nsgf_set
273 rpgfb => basis_set_b%pgf_radius
274 set_radius_b => basis_set_b%set_radius
275 sphi_b => basis_set_b%sphi
276 zetb => basis_set_b%zet
278 dab = sqrt(sum(rab*rab))
280 IF (iatom == last_iatom .AND. jatom == last_jatom)
THEN
281 new_atom_pair = .false.
283 new_atom_pair = .true.
289 IF (iatom == jatom)
THEN
296 IF (new_atom_pair)
THEN
297 IF (iatom <= jatom)
THEN
306 IF (
ASSOCIATED(h_block))
THEN
307 IF (calculate_forces)
THEN
308 cpassert(
SIZE(matrix_p, 2) == 1)
311 IF (
ASSOCIATED(p_block))
THEN
313 ncoa = npgfa(iset)*
ncoset(la_max(iset))
314 sgfa = first_sgfa(1, iset)
316 ncob = npgfb(jset)*
ncoset(lb_max(jset))
317 sgfb = first_sgfb(1, jset)
320 IF (iatom <= jatom)
THEN
321 CALL dgemm(
"N",
"N", ncoa, nsgfb(jset), nsgfa(iset), &
322 1.0_dp, sphi_a(1, sgfa),
SIZE(sphi_a, 1), &
323 p_block(sgfa, sgfb),
SIZE(p_block, 1), &
324 0.0_dp, work(1, 1),
SIZE(work, 1))
326 CALL dgemm(
"N",
"T", ncoa, nsgfb(jset), nsgfa(iset), &
327 1.0_dp, sphi_a(1, sgfa),
SIZE(sphi_a, 1), &
328 p_block(sgfb, sgfa),
SIZE(p_block, 1), &
329 0.0_dp, work(1, 1),
SIZE(work, 1))
332 CALL dgemm(
"N",
"T", ncoa, ncob, nsgfb(jset), &
333 1.0_dp, work(1, 1),
SIZE(work, 1), &
334 sphi_b(1, sgfb),
SIZE(sphi_b, 1), &
335 0.0_dp, pab(1, 1, iset, jset),
SIZE(pab, 1))
348 CALL get_qs_kind(qs_kind_set(kkind), tnadd_potential=tnadd_potential)
349 IF (.NOT.
ASSOCIATED(tnadd_potential)) cycle
351 alpha=alpha, cval=cval, ngau=ngau, npol=npol, radius=radius)
353 ALLOCATE (ccval(npol, ngau))
354 ccval(1:npol, 1:ngau) = transpose(cval(1:ngau, 1:npol))
363 kmol = atom_to_molecule(katom)
364 IF (kmol == imol) cycle
366 dac = sqrt(sum(rac*rac))
367 rbc(:) = rac(:) - rab(:)
368 dbc = sqrt(sum(rbc*rbc))
369 IF ((maxval(set_radius_a(:)) + radius < dac) .OR. &
370 (maxval(set_radius_b(:)) + radius < dbc))
THEN
375 IF (set_radius_a(iset) + radius < dac) cycle
376 ncoa = npgfa(iset)*
ncoset(la_max(iset))
377 sgfa = first_sgfa(1, iset)
379 IF (set_radius_b(jset) + radius < dbc) cycle
380 ncob = npgfb(jset)*
ncoset(lb_max(jset))
381 sgfb = first_sgfb(1, jset)
382 IF (set_radius_a(iset) + set_radius_b(jset) < dab) cycle
384 IF (calculate_forces)
THEN
387 la_max(iset), la_min(iset), npgfa(iset), &
388 rpgfa(:, iset), zeta(:, iset), &
389 lb_max(jset), lb_min(jset), npgfb(jset), &
390 rpgfb(:, jset), zetb(:, jset), &
391 ngau, alpha, nct, ccval, radius, &
392 rab, dab, rac, dac, rbc, dbc, &
393 hab(:, :, iset, jset), ppl_work, pab(:, :, iset, jset), &
394 force_a, force_b, ppl_fwork)
398 atom_c = atom_of_kind(katom)
401 force(ikind)%kinetic(1, atom_a) = force(ikind)%kinetic(1, atom_a) + f0*force_a(1)
402 force(ikind)%kinetic(2, atom_a) = force(ikind)%kinetic(2, atom_a) + f0*force_a(2)
403 force(ikind)%kinetic(3, atom_a) = force(ikind)%kinetic(3, atom_a) + f0*force_a(3)
404 force(kkind)%kinetic(1, atom_c) = force(kkind)%kinetic(1, atom_c) - f0*force_a(1)
405 force(kkind)%kinetic(2, atom_c) = force(kkind)%kinetic(2, atom_c) - f0*force_a(2)
406 force(kkind)%kinetic(3, atom_c) = force(kkind)%kinetic(3, atom_c) - f0*force_a(3)
408 force(jkind)%kinetic(1, atom_b) = force(jkind)%kinetic(1, atom_b) + f0*force_b(1)
409 force(jkind)%kinetic(2, atom_b) = force(jkind)%kinetic(2, atom_b) + f0*force_b(2)
410 force(jkind)%kinetic(3, atom_b) = force(jkind)%kinetic(3, atom_b) + f0*force_b(3)
411 force(kkind)%kinetic(1, atom_c) = force(kkind)%kinetic(1, atom_c) - f0*force_b(1)
412 force(kkind)%kinetic(2, atom_c) = force(kkind)%kinetic(2, atom_c) - f0*force_b(2)
413 force(kkind)%kinetic(3, atom_c) = force(kkind)%kinetic(3, atom_c) - f0*force_b(3)
423 la_max(iset), la_min(iset), npgfa(iset), &
424 rpgfa(:, iset), zeta(:, iset), &
425 lb_max(jset), lb_min(jset), npgfb(jset), &
426 rpgfb(:, jset), zetb(:, jset), &
427 ngau, alpha, nct, ccval, radius, &
428 rab, dab, rac, dac, rbc, dbc, hab(:, :, iset, jset), ppl_work)
438 ncoa = npgfa(iset)*
ncoset(la_max(iset))
439 sgfa = first_sgfa(1, iset)
441 ncob = npgfb(jset)*
ncoset(lb_max(jset))
442 sgfb = first_sgfb(1, jset)
444 CALL dgemm(
"N",
"N", ncoa, nsgfb(jset), ncob, &
445 1.0_dp, hab(1, 1, iset, jset),
SIZE(hab, 1), &
446 sphi_b(1, sgfb),
SIZE(sphi_b, 1), &
447 0.0_dp, work(1, 1),
SIZE(work, 1))
450 IF (iatom <= jatom)
THEN
451 CALL dgemm(
"T",
"N", nsgfa(iset), nsgfb(jset), ncoa, &
452 1.0_dp, sphi_a(1, sgfa),
SIZE(sphi_a, 1), &
453 work(1, 1),
SIZE(work, 1), &
454 1.0_dp, h_block(sgfa, sgfb),
SIZE(h_block, 1))
456 CALL dgemm(
"T",
"N", nsgfb(jset), nsgfa(iset), ncoa, &
457 1.0_dp, work(1, 1),
SIZE(work, 1), &
458 sphi_a(1, sgfa),
SIZE(sphi_a, 1), &
459 1.0_dp, h_block(sgfb, sgfa),
SIZE(h_block, 1))
467 DEALLOCATE (hab, work, ppl_work)
469 IF (calculate_forces)
THEN
470 DEALLOCATE (pab, ppl_fwork)
478 DO i = 1,
SIZE(matrix_kg)
481 kg_env%tnadd_mat => matrix_kg
483 DEALLOCATE (basis_set_list)
485 IF (calculate_forces)
THEN
488 IF (
SIZE(matrix_p, 1) == 2)
THEN
489 DO img = 1,
SIZE(matrix_p, 2)
490 CALL dbcsr_add(matrix_p(1, img)%matrix, matrix_p(2, img)%matrix, &
491 alpha_scalar=0.5_dp, beta_scalar=0.5_dp)
492 CALL dbcsr_add(matrix_p(2, img)%matrix, matrix_p(1, img)%matrix, &
493 alpha_scalar=-1.0_dp, beta_scalar=1.0_dp)
498 CALL timestop(handle)
subroutine, public get_qs_kind(qs_kind, basis_set, basis_type, ncgf, nsgf, all_potential, tnadd_potential, gth_potential, sgp_potential, upf_potential, se_parameter, dftb_parameter, xtb_parameter, dftb3_param, zatom, zeff, elec_conf, mao, lmax_dftb, alpha_core_charge, ccore_charge, core_charge, core_charge_radius, paw_proj_set, paw_atom, hard_radius, hard0_radius, max_rad_local, covalent_radius, vdw_radius, gpw_type_forced, harmonics, max_iso_not0, max_s_harm, grid_atom, ngrid_ang, ngrid_rad, lmax_rho0, dft_plus_u_atom, l_of_dft_plus_u, n_of_dft_plus_u, u_minus_j, u_of_dft_plus_u, j_of_dft_plus_u, alpha_of_dft_plus_u, beta_of_dft_plus_u, j0_of_dft_plus_u, occupation_of_dft_plus_u, dispersion, bs_occupation, magnetization, no_optimize, addel, laddel, naddel, orbitals, max_scf, eps_scf, smear, u_ramping, u_minus_j_target, eps_u_ramping, init_u_ramping_each_scf, reltmat, ghost, floating, name, element_symbol, pao_basis_size, pao_model_file, pao_potentials, pao_descriptors, nelec)
Get attributes of an atomic kind.