(git:47b47fb)
Loading...
Searching...
No Matches
atom_kind_orbitals.F
Go to the documentation of this file.
1!--------------------------------------------------------------------------------------------------!
2! CP2K: A general program to perform molecular dynamics simulations !
3! Copyright 2000-2026 CP2K developers group <https://cp2k.org> !
4! !
5! SPDX-License-Identifier: GPL-2.0-or-later !
6!--------------------------------------------------------------------------------------------------!
7
8! **************************************************************************************************
9!> \brief calculate the orbitals for a given atomic kind type
10! **************************************************************************************************
12 USE ai_onecenter, ONLY: sg_erfc
14 USE atom_fit, ONLY: atom_fit_density
22 USE atom_types, ONLY: &
27 USE atom_utils, ONLY: atom_density,&
38 USE input_constants, ONLY: &
44 USE kinds, ONLY: dp
45 USE mathconstants, ONLY: dfac,&
46 fourpi,&
47 pi
48 USE periodic_table, ONLY: ptable
49 USE physcon, ONLY: bohr
53 USE qs_kind_types, ONLY: get_qs_kind,&
58#include "./base/base_uses.f90"
59
60 IMPLICIT NONE
61
62 PRIVATE
63
64 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'atom_kind_orbitals'
65
68
69! **************************************************************************************************
70
71CONTAINS
72
73! **************************************************************************************************
74!> \brief ...
75!> \param atomic_kind ...
76!> \param qs_kind ...
77!> \param agrid ...
78!> \param iunit ...
79!> \param pmat ...
80!> \param fmat ...
81!> \param density ...
82!> \param wavefunction ...
83!> \param wfninfo ...
84!> \param confine ...
85!> \param xc_section ...
86!> \param nocc ...
87!> \param which_l ...
88!> \param which_n ...
89!> \param proj_shell_charge ...
90!> \param ao_coef ...
91! **************************************************************************************************
92 SUBROUTINE calculate_atomic_orbitals(atomic_kind, qs_kind, agrid, iunit, pmat, fmat, &
93 density, wavefunction, wfninfo, confine, xc_section, nocc, &
94 which_l, which_n, proj_shell_charge, ao_coef)
95 TYPE(atomic_kind_type), INTENT(IN) :: atomic_kind
96 TYPE(qs_kind_type), INTENT(IN) :: qs_kind
97 TYPE(grid_atom_type), OPTIONAL :: agrid
98 INTEGER, INTENT(IN), OPTIONAL :: iunit
99 REAL(kind=dp), DIMENSION(:, :, :), OPTIONAL, &
100 POINTER :: pmat, fmat
101 REAL(kind=dp), DIMENSION(:), OPTIONAL, POINTER :: density
102 REAL(kind=dp), DIMENSION(:, :), OPTIONAL, POINTER :: wavefunction, wfninfo
103 LOGICAL, INTENT(IN), OPTIONAL :: confine
104 TYPE(section_vals_type), OPTIONAL, POINTER :: xc_section
105 INTEGER, DIMENSION(:), OPTIONAL :: nocc
106 INTEGER, INTENT(IN), OPTIONAL :: which_l, which_n
107 REAL(kind=dp), INTENT(IN), OPTIONAL :: proj_shell_charge(4)
108 REAL(kind=dp), DIMENSION(:), INTENT(INOUT), &
109 OPTIONAL, POINTER :: ao_coef
110
111 INTEGER :: i, ii, j, k, k1, k2, l, ll, m, mb, mo, &
112 nr, nset, nsgf, projector_index, &
113 valence_n, z
114 INTEGER, DIMENSION(0:lmat) :: nbb
115 INTEGER, DIMENSION(0:lmat, 10) :: ncalc, ncore, nelem
116 INTEGER, DIMENSION(0:lmat, 100) :: set_index, shell_index
117 INTEGER, DIMENSION(:), POINTER :: nshell
118 INTEGER, DIMENSION(:, :), POINTER :: first_sgf, ls
119 LOGICAL :: ecp_semi_local, ghost, has_pp, uks
120 REAL(kind=dp) :: ok, qleft, scal, take, zeff
121 REAL(kind=dp), DIMENSION(0:lmat, 10) :: occupation_neutral
122 REAL(kind=dp), DIMENSION(0:lmat, 10, 2) :: edelta
123 TYPE(all_potential_type), POINTER :: all_potential
124 TYPE(atom_basis_type), POINTER :: basis
125 TYPE(atom_integrals), POINTER :: integrals
126 TYPE(atom_orbitals), POINTER :: orbitals
127 TYPE(atom_potential_type), POINTER :: potential
128 TYPE(atom_type), POINTER :: atom
129 TYPE(gth_potential_type), POINTER :: gth_potential
130 TYPE(gto_basis_set_type), POINTER :: orb_basis_set
131 TYPE(sgp_potential_type), POINTER :: sgp_potential
132
133 IF (PRESENT(ao_coef) .OR. PRESENT(which_l) .OR. &
134 PRESENT(which_n) .OR. PRESENT(proj_shell_charge)) THEN
135 IF (.NOT. PRESENT(ao_coef) .OR. .NOT. PRESENT(which_l) .OR. &
136 .NOT. PRESENT(which_n) .OR. .NOT. PRESENT(proj_shell_charge)) THEN
137 cpabort("ao_coef, which_l, which_n, and proj_shell_charge must be provided together")
138 END IF
139 END IF
140
141 NULLIFY (atom)
143
144 IF (PRESENT(xc_section)) THEN
145 atom%xc_section => xc_section
146 ELSE
147 NULLIFY (atom%xc_section)
148 END IF
149
150 CALL get_atomic_kind(atomic_kind, z=z)
151 NULLIFY (all_potential, gth_potential, sgp_potential, orb_basis_set)
152 CALL get_qs_kind(qs_kind, zeff=zeff, &
153 basis_set=orb_basis_set, &
154 ghost=ghost, &
155 all_potential=all_potential, &
156 gth_potential=gth_potential, &
157 sgp_potential=sgp_potential)
158
159 has_pp = ASSOCIATED(gth_potential) .OR. ASSOCIATED(sgp_potential)
160
161 atom%z = z
162 CALL set_atom(atom, &
163 pp_calc=has_pp, &
164 do_zmp=.false., &
165 doread=.false., &
166 read_vxc=.false., &
167 relativistic=do_nonrel_atom, &
168 coulomb_integral_type=do_numeric, &
169 exchange_integral_type=do_numeric)
170
171 ALLOCATE (potential, integrals)
172
173 IF (PRESENT(confine)) THEN
174 potential%confinement = confine
175 ELSE
176 IF (ASSOCIATED(gth_potential) .OR. ASSOCIATED(sgp_potential)) THEN
177 potential%confinement = .true.
178 ELSE
179 potential%confinement = .false.
180 END IF
181 END IF
182 potential%conf_type = poly_conf
183 potential%acon = 0.1_dp
184 potential%rcon = 2.0_dp*ptable(z)%vdw_radius*bohr
185 potential%scon = 2.0_dp
186
187 IF (ASSOCIATED(gth_potential)) THEN
188 potential%ppot_type = gth_pseudo
189 CALL get_potential(gth_potential, zeff=zeff)
190 CALL gth_potential_conversion(gth_potential, potential%gth_pot)
191 CALL set_atom(atom, zcore=nint(zeff), potential=potential)
192 ELSE IF (ASSOCIATED(sgp_potential)) THEN
193 CALL get_potential(sgp_potential, ecp_semi_local=ecp_semi_local)
194 IF (ALLOCATED(sgp_potential%upf_data)) THEN
195 potential%ppot_type = upf_pseudo
196 potential%upf_pot = sgp_potential%upf_data
197 ELSE IF (ecp_semi_local) THEN
198 potential%ppot_type = ecp_pseudo
199 CALL ecp_potential_conversion(sgp_potential, potential%ecp_pot)
200 potential%ecp_pot%symbol = ptable(z)%symbol
201 ELSE
202 potential%ppot_type = sgp_pseudo
203 CALL sgp_potential_conversion(sgp_potential, potential%sgp_pot)
204 potential%sgp_pot%symbol = ptable(z)%symbol
205 END IF
206 CALL get_potential(sgp_potential, zeff=zeff)
207 CALL set_atom(atom, zcore=nint(zeff), potential=potential)
208 ELSE
209 potential%ppot_type = no_pseudo
210 CALL set_atom(atom, zcore=z, potential=potential)
211 END IF
212
213 NULLIFY (basis)
214 ALLOCATE (basis)
215
216 CALL set_kind_basis_atomic(basis, orb_basis_set, has_pp, agrid)
217
218 CALL set_atom(atom, basis=basis)
219
220 ! optimization defaults
221 atom%optimization%damping = 0.2_dp
222 atom%optimization%eps_scf = 1.e-6_dp
223 atom%optimization%eps_diis = 100._dp
224 atom%optimization%max_iter = 50
225 atom%optimization%n_diis = 5
226
227 ! set up the electronic state
228 CALL init_atom_electronic_state(atomic_kind=atomic_kind, &
229 qs_kind=qs_kind, &
230 ncalc=ncalc, &
231 ncore=ncore, &
232 nelem=nelem, &
233 edelta=edelta, &
234 rks=PRESENT(ao_coef))
235
236 ! restricted or unrestricted?
237 IF (sum(abs(edelta)) > 0.0_dp) THEN
238 uks = .true.
239 CALL set_atom(atom, method_type=do_uks_atom)
240 ELSE
241 uks = .false.
242 CALL set_atom(atom, method_type=do_rks_atom)
243 END IF
244
245 ALLOCATE (atom%state)
246
247 atom%state%core = 0._dp
248 atom%state%core(0:lmat, 1:7) = real(ncore(0:lmat, 1:7), dp)
249 atom%state%occ = 0._dp
250 IF (uks) THEN
251 atom%state%occ(0:lmat, 1:7) = real(ncalc(0:lmat, 1:7), dp) + &
252 edelta(0:lmat, 1:7, 1) + edelta(0:lmat, 1:7, 2)
253 ELSE
254 atom%state%occ(0:lmat, 1:7) = real(ncalc(0:lmat, 1:7), dp)
255 END IF
256 atom%state%occupation = 0._dp
257 DO l = 0, lmat
258 k = 0
259 DO i = 1, 7
260 IF (ncalc(l, i) > 0) THEN
261 k = k + 1
262 IF (uks) THEN
263 atom%state%occupation(l, k) = real(ncalc(l, i), dp) + &
264 edelta(l, i, 1) + edelta(l, i, 2)
265 atom%state%occa(l, k) = 0.5_dp*real(ncalc(l, i), dp) + edelta(l, i, 1)
266 atom%state%occb(l, k) = 0.5_dp*real(ncalc(l, i), dp) + edelta(l, i, 2)
267 ELSE
268 atom%state%occupation(l, k) = real(ncalc(l, i), dp)
269 END IF
270 END IF
271 END DO
272 ok = real(2*l + 1, kind=dp)
273 IF (uks) THEN
274 DO i = 1, 7
275 atom%state%occ(l, i) = min(atom%state%occ(l, i), 2.0_dp*ok)
276 atom%state%occa(l, i) = min(atom%state%occa(l, i), ok)
277 atom%state%occb(l, i) = min(atom%state%occb(l, i), ok)
278 atom%state%occupation(l, i) = atom%state%occa(l, i) + atom%state%occb(l, i)
279 END DO
280 ELSE
281 DO i = 1, 7
282 atom%state%occ(l, i) = min(atom%state%occ(l, i), 2.0_dp*ok)
283 atom%state%occupation(l, i) = min(atom%state%occupation(l, i), 2.0_dp*ok)
284 END DO
285 END IF
286 END DO
287
288 IF (PRESENT(proj_shell_charge)) THEN
289 ! Save the neutral/original calculated shell list.
290 occupation_neutral(0:lmat, 1:10) = atom%state%occupation(0:lmat, 1:10)
291 IF (uks) THEN
292 CALL cp_abort(__location__, "proj_shell_charge in"// &
293 " calculate_atomic_orbitals is implemented only for RKS")
294 END IF
295 DO l = 0, min(3, lmat)
296 qleft = proj_shell_charge(l + 1)
297 IF (qleft > 0.0_dp) THEN
298 ! Remove electrons from the highest shell in this angular momentum channel.
299 DO k = 7, 1, -1
300 IF (atom%state%occupation(l, k) > 0.0_dp) THEN
301 take = min(qleft, atom%state%occupation(l, k))
302 atom%state%occupation(l, k) = atom%state%occupation(l, k) - take
303 qleft = qleft - take
304 IF (qleft <= 1.0e-12_dp) EXIT
305 END IF
306 END DO
307 IF (qleft > 1.0e-10_dp) THEN
308 CALL cp_abort(__location__, "proj_shell_charge removes"// &
309 " more electrons than available in this angular channel")
310 END IF
311 ! Keep atom%state%occ consistent with atom%state%occupation.
312 qleft = proj_shell_charge(l + 1)
313 DO k = 7, 1, -1
314 IF (atom%state%occ(l, k) > 0.0_dp) THEN
315 take = min(qleft, atom%state%occ(l, k))
316 atom%state%occ(l, k) = atom%state%occ(l, k) - take
317 qleft = qleft - take
318 IF (qleft <= 1.0e-12_dp) EXIT
319 END IF
320 END DO
321 ELSE IF (qleft < 0.0_dp) THEN
322 CALL cp_abort(__location__, "Negative proj_shell_charge"// &
323 " is not supported in this implementation")
324 END IF
325 END DO
326 END IF
327
328 IF (uks) THEN
329 atom%state%multiplicity = nint(abs(sum(atom%state%occa - atom%state%occb)) + 1)
330 ELSE
331 atom%state%multiplicity = -1
332 END IF
333
334 atom%state%maxl_occ = get_maxl_occ(atom%state%occupation)
335 atom%state%maxn_occ = get_maxn_occ(atom%state%occupation)
336 IF (PRESENT(proj_shell_charge)) THEN
337 atom%state%maxl_calc = get_maxl_occ(occupation_neutral)
338 atom%state%maxn_calc = get_maxn_occ(occupation_neutral)
339 ELSE
340 atom%state%maxl_calc = atom%state%maxl_occ
341 atom%state%maxn_calc = atom%state%maxn_occ
342 END IF
343
344 ! total number of occupied orbitals
345 IF (PRESENT(nocc) .AND. ghost) THEN
346 nocc = 0
347 ELSE IF (PRESENT(nocc)) THEN
348 nocc = 0
349 DO l = 0, lmat
350 DO k = 1, 7
351 IF (uks) THEN
352 IF (atom%state%occa(l, k) > 0.0_dp) THEN
353 nocc(1) = nocc(1) + 2*l + 1
354 END IF
355 IF (atom%state%occb(l, k) > 0.0_dp) THEN
356 nocc(2) = nocc(2) + 2*l + 1
357 END IF
358 ELSE
359 IF (atom%state%occupation(l, k) > 0.0_dp) THEN
360 nocc(1) = nocc(1) + 2*l + 1
361 nocc(2) = nocc(2) + 2*l + 1
362 END IF
363 END IF
364 END DO
365 END DO
366 END IF
367
368 ! calculate integrals
369 ! general integrals
370 CALL atom_int_setup(integrals, basis, potential=atom%potential, &
371 eri_coulomb=(atom%coulomb_integral_type == do_analytic), &
372 eri_exchange=(atom%exchange_integral_type == do_analytic))
373 ! potential
374 CALL atom_ppint_setup(integrals, basis, potential=atom%potential)
375 ! relativistic correction terms
376 NULLIFY (integrals%tzora, integrals%hdkh)
377 CALL atom_relint_setup(integrals, basis, atom%relativistic, zcore=real(atom%zcore, dp))
378 CALL set_atom(atom, integrals=integrals)
379
380 NULLIFY (orbitals)
381 mo = maxval(atom%state%maxn_calc)
382 mb = maxval(atom%basis%nbas)
383 CALL create_atom_orbs(orbitals, mb, mo)
384 CALL set_atom(atom, orbitals=orbitals)
385
386 IF (.NOT. ghost) THEN
387 IF (PRESENT(iunit)) THEN
388 CALL calculate_atom(atom, iunit)
389 ELSE
390 CALL calculate_atom(atom, -1)
391 END IF
392 END IF
393 IF (PRESENT(pmat)) THEN
394 ! recover density matrix in CP2K/GPW order and normalization
395 CALL get_gto_basis_set(orb_basis_set, &
396 nset=nset, nshell=nshell, l=ls, nsgf=nsgf, first_sgf=first_sgf)
397 set_index = 0
398 shell_index = 0
399 nbb = 0
400 DO i = 1, nset
401 DO j = 1, nshell(i)
402 l = ls(j, i)
403 IF (l <= lmat) THEN
404 nbb(l) = nbb(l) + 1
405 k = nbb(l)
406 cpassert(k <= 100)
407 set_index(l, k) = i
408 shell_index(l, k) = j
409 END IF
410 END DO
411 END DO
412
413 IF (ASSOCIATED(pmat)) THEN
414 DEALLOCATE (pmat)
415 END IF
416 ALLOCATE (pmat(nsgf, nsgf, 2))
417 pmat = 0._dp
418 IF (.NOT. ghost) THEN
419 DO l = 0, lmat
420 ll = 2*l
421 DO k1 = 1, atom%basis%nbas(l)
422 DO k2 = 1, atom%basis%nbas(l)
423 scal = sqrt(atom%integrals%ovlp(k1, k1, l)*atom%integrals%ovlp(k2, k2, l))/real(2*l + 1, kind=dp)
424 i = first_sgf(shell_index(l, k1), set_index(l, k1))
425 j = first_sgf(shell_index(l, k2), set_index(l, k2))
426 IF (uks) THEN
427 DO m = 0, ll
428 pmat(i + m, j + m, 1) = atom%orbitals%pmata(k1, k2, l)*scal
429 pmat(i + m, j + m, 2) = atom%orbitals%pmatb(k1, k2, l)*scal
430 END DO
431 ELSE
432 DO m = 0, ll
433 pmat(i + m, j + m, 1) = atom%orbitals%pmat(k1, k2, l)*scal
434 END DO
435 END IF
436 END DO
437 END DO
438 END DO
439 IF (uks) THEN
440 pmat(:, :, 1) = pmat(:, :, 1) + pmat(:, :, 2)
441 pmat(:, :, 2) = pmat(:, :, 1) - 2.0_dp*pmat(:, :, 2)
442 END IF
443 END IF
444 END IF
445
446 IF (PRESENT(fmat)) THEN
447 ! recover fock matrix in CP2K/GPW order.
448 ! Caution: Normalization is not take care of, so it's probably weird.
449 CALL get_gto_basis_set(orb_basis_set, &
450 nset=nset, nshell=nshell, l=ls, nsgf=nsgf, first_sgf=first_sgf)
451 set_index = 0
452 shell_index = 0
453 nbb = 0
454 DO i = 1, nset
455 DO j = 1, nshell(i)
456 l = ls(j, i)
457 IF (l <= lmat) THEN
458 nbb(l) = nbb(l) + 1
459 k = nbb(l)
460 cpassert(k <= 100)
461 set_index(l, k) = i
462 shell_index(l, k) = j
463 END IF
464 END DO
465 END DO
466 IF (uks) cpabort("calculate_atomic_orbitals: only RKS is implemented")
467 IF (ASSOCIATED(fmat)) cpabort("fmat already associated")
468 IF (.NOT. ASSOCIATED(atom%fmat)) cpabort("atom%fmat not associated")
469 ALLOCATE (fmat(nsgf, nsgf, 1))
470 fmat = 0.0_dp
471 IF (.NOT. ghost) THEN
472 DO l = 0, lmat
473 ll = 2*l
474 DO k1 = 1, atom%basis%nbas(l)
475 DO k2 = 1, atom%basis%nbas(l)
476 scal = sqrt(atom%integrals%ovlp(k1, k1, l)*atom%integrals%ovlp(k2, k2, l))
477 i = first_sgf(shell_index(l, k1), set_index(l, k1))
478 j = first_sgf(shell_index(l, k2), set_index(l, k2))
479 DO m = 0, ll
480 fmat(i + m, j + m, 1) = atom%fmat%op(k1, k2, l)/scal
481 END DO
482 END DO
483 END DO
484 END DO
485 END IF
486 END IF
487
488 nr = basis%grid%nr
489
490 IF (PRESENT(density)) THEN
491 IF (ASSOCIATED(density)) DEALLOCATE (density)
492 ALLOCATE (density(nr))
493 IF (ghost) THEN
494 density = 0.0_dp
495 ELSE
496 CALL atom_density(density, atom%orbitals%pmat, atom%basis, atom%state%maxl_occ)
497 END IF
498 END IF
499
500 IF (PRESENT(wavefunction)) THEN
501 cpassert(PRESENT(wfninfo))
502 IF (ASSOCIATED(wavefunction)) DEALLOCATE (wavefunction)
503 IF (ASSOCIATED(wfninfo)) DEALLOCATE (wfninfo)
504 mo = sum(atom%state%maxn_occ)
505 ALLOCATE (wavefunction(nr, mo), wfninfo(2, mo))
506 wavefunction = 0.0_dp
507 IF (.NOT. ghost) THEN
508 ii = 0
509 DO l = 0, lmat
510 DO i = 1, atom%state%maxn_occ(l)
511 IF (atom%state%occupation(l, i) > 0.0_dp) THEN
512 ii = ii + 1
513 wfninfo(1, ii) = atom%state%occupation(l, i)
514 wfninfo(2, ii) = real(l, dp)
515 DO j = 1, atom%basis%nbas(l)
516 wavefunction(:, ii) = wavefunction(:, ii) + &
517 atom%orbitals%wfn(j, i, l)*basis%bf(:, j, l)
518 END DO
519 END IF
520 END DO
521 END DO
522 cpassert(mo == ii)
523 END IF
524 END IF
525
526 IF (PRESENT(ao_coef)) THEN
527 cpassert(PRESENT(which_l))
528 cpassert(PRESENT(which_n))
529 cpassert(which_l >= 0 .AND. which_l <= lmat)
530 valence_n = count(ncore(which_l, :) > 0) + which_l + 1
531 projector_index = which_n - valence_n + 1
532 IF (projector_index < 1 .OR. projector_index > SIZE(atom%orbitals%wfn, 2)) THEN
533 CALL cp_abort(__location__, &
534 "The requested tensorial atomic projector N is outside "// &
535 "the available orbital range for the selected L.")
536 END IF
537 IF (ASSOCIATED(ao_coef)) DEALLOCATE (ao_coef)
538 ALLOCATE (ao_coef(SIZE(atom%orbitals%wfn(:, 1, which_l))))
539 ao_coef(:) = atom%orbitals%wfn(:, projector_index, which_l)
540 IF (maxval(abs(ao_coef)) <= 100.0_dp*epsilon(1.0_dp)) THEN
541 CALL cp_abort(__location__, &
542 "The requested atomic projector is zero. Check the "// &
543 "specified N and L quantum numbers.")
544 END IF
545 DO j = 1, SIZE(ao_coef(:))
546 ao_coef(j) = ao_coef(j)*sqrt(atom%integrals%ovlp(j, j, which_l))
547 END DO
548 END IF
549
550 ! clean up
551 CALL atom_int_release(integrals)
552 CALL atom_ppint_release(integrals)
553 CALL atom_relint_release(integrals)
554 CALL release_atom_basis(basis)
555 CALL release_atom_potential(potential)
557
558 DEALLOCATE (potential, basis, integrals)
559
560 END SUBROUTINE calculate_atomic_orbitals
561
562! **************************************************************************************************
563!> \brief ...
564!> \param density ...
565!> \param atomic_kind ...
566!> \param qs_kind ...
567!> \param ngto ...
568!> \param iunit ...
569!> \param optbasis ... Default=T, if basis should be optimized, if not basis is given in input (density)
570!> \param allelectron ...
571!> \param confine ...
572! **************************************************************************************************
573 SUBROUTINE calculate_atomic_density(density, atomic_kind, qs_kind, ngto, iunit, &
574 optbasis, allelectron, confine)
575 REAL(kind=dp), DIMENSION(:, :), INTENT(INOUT) :: density
576 TYPE(atomic_kind_type), POINTER :: atomic_kind
577 TYPE(qs_kind_type), POINTER :: qs_kind
578 INTEGER, INTENT(IN) :: ngto
579 INTEGER, INTENT(IN), OPTIONAL :: iunit
580 LOGICAL, INTENT(IN), OPTIONAL :: optbasis, allelectron, confine
581
582 INTEGER, PARAMETER :: num_gto = 40
583
584 INTEGER :: i, ii, iw, k, l, ll, m, mb, mo, ngp, nn, &
585 nr, quadtype, relativistic, z
586 INTEGER, DIMENSION(0:lmat) :: starti
587 INTEGER, DIMENSION(0:lmat, 10) :: ncalc, ncore, nelem
588 INTEGER, DIMENSION(:), POINTER :: econf
589 LOGICAL :: do_basopt, ecp_semi_local, monovalent
590 REAL(kind=dp) :: al, aval, cc, cval, ear, rk, xx, zeff
591 REAL(kind=dp), DIMENSION(num_gto+2) :: results
592 TYPE(all_potential_type), POINTER :: all_potential
593 TYPE(atom_basis_type), POINTER :: basis
594 TYPE(atom_integrals), POINTER :: integrals
595 TYPE(atom_orbitals), POINTER :: orbitals
596 TYPE(atom_potential_type), POINTER :: potential
597 TYPE(atom_type), POINTER :: atom
598 TYPE(grid_atom_type), POINTER :: grid
599 TYPE(gth_potential_type), POINTER :: gth_potential
600 TYPE(sgp_potential_type), POINTER :: sgp_potential
601
602 NULLIFY (atom)
604
605 CALL get_atomic_kind(atomic_kind, z=z)
606 NULLIFY (all_potential, gth_potential)
607 CALL get_qs_kind(qs_kind, zeff=zeff, &
608 all_potential=all_potential, &
609 gth_potential=gth_potential, &
610 sgp_potential=sgp_potential, &
611 monovalent=monovalent)
612
613 IF (PRESENT(iunit)) THEN
614 iw = iunit
615 ELSE
616 iw = -1
617 END IF
618
619 IF (PRESENT(allelectron)) THEN
620 IF (allelectron) THEN
621 NULLIFY (gth_potential)
622 zeff = z
623 END IF
624 END IF
625
626 do_basopt = .true.
627 IF (PRESENT(optbasis)) THEN
628 do_basopt = optbasis
629 END IF
630
631 cpassert(ngto <= num_gto)
632
633 IF (ASSOCIATED(gth_potential) .OR. ASSOCIATED(sgp_potential)) THEN
634 ! PP calculation are non-relativistic
635 relativistic = do_nonrel_atom
636 ELSE
637 ! AE calculations use DKH2
638 relativistic = do_dkh2_atom
639 END IF
640
641 atom%z = z
642 CALL set_atom(atom, &
643 pp_calc=(ASSOCIATED(gth_potential) .OR. ASSOCIATED(sgp_potential)), &
644 method_type=do_rks_atom, &
645 relativistic=relativistic, &
646 coulomb_integral_type=do_numeric, &
647 exchange_integral_type=do_numeric)
648
649 ALLOCATE (potential, basis, integrals)
650
651 IF (PRESENT(confine)) THEN
652 potential%confinement = confine
653 ELSE
654 IF (ASSOCIATED(gth_potential) .OR. ASSOCIATED(sgp_potential)) THEN
655 potential%confinement = .true.
656 ELSE
657 potential%confinement = .false.
658 END IF
659 END IF
660 potential%conf_type = barrier_conf
661 potential%acon = 200._dp
662 potential%rcon = 4.0_dp
663 potential%scon = 8.0_dp
664
665 IF (ASSOCIATED(gth_potential)) THEN
666 potential%ppot_type = gth_pseudo
667 CALL get_potential(gth_potential, zeff=zeff)
668 CALL gth_potential_conversion(gth_potential, potential%gth_pot)
669 CALL set_atom(atom, zcore=nint(zeff), potential=potential)
670 ELSE IF (ASSOCIATED(sgp_potential)) THEN
671 CALL get_potential(sgp_potential, ecp_semi_local=ecp_semi_local)
672 IF (ALLOCATED(sgp_potential%upf_data)) THEN
673 potential%ppot_type = upf_pseudo
674 potential%upf_pot = sgp_potential%upf_data
675 ELSE IF (ecp_semi_local) THEN
676 potential%ppot_type = ecp_pseudo
677 CALL ecp_potential_conversion(sgp_potential, potential%ecp_pot)
678 potential%ecp_pot%symbol = ptable(z)%symbol
679 ELSE
680 potential%ppot_type = sgp_pseudo
681 CALL sgp_potential_conversion(sgp_potential, potential%sgp_pot)
682 potential%sgp_pot%symbol = ptable(z)%symbol
683 END IF
684 CALL get_potential(sgp_potential, zeff=zeff)
685 CALL set_atom(atom, zcore=nint(zeff), potential=potential)
686 ELSE
687 potential%ppot_type = no_pseudo
688 CALL set_atom(atom, zcore=z, potential=potential)
689 END IF
690
691 ! atomic grid
692 NULLIFY (grid)
693 ngp = 400
694 quadtype = do_gapw_log
695 CALL allocate_grid_atom(grid)
696 CALL create_grid_atom(grid, ngp, 1, 1, 0, quadtype)
697 grid%nr = ngp
698 basis%grid => grid
699
700 NULLIFY (basis%am, basis%cm, basis%as, basis%ns, basis%bf, basis%dbf, basis%ddbf)
701
702 ! fill in the basis data structures
703 basis%eps_eig = 1.e-12_dp
704 basis%basis_type = gto_basis
705 CALL clementi_geobas(z, cval, aval, basis%nbas, starti)
706 basis%nprim = basis%nbas
707 m = maxval(basis%nbas)
708 ALLOCATE (basis%am(m, 0:lmat))
709 basis%am = 0._dp
710 DO l = 0, lmat
711 DO i = 1, basis%nbas(l)
712 ll = i - 1 + starti(l)
713 basis%am(i, l) = aval*cval**(ll)
714 END DO
715 END DO
716
717 basis%geometrical = .true.
718 basis%aval = aval
719 basis%cval = cval
720 basis%start = starti
721
722 ! initialize basis function on a radial grid
723 nr = basis%grid%nr
724 m = maxval(basis%nbas)
725 ALLOCATE (basis%bf(nr, m, 0:lmat))
726 ALLOCATE (basis%dbf(nr, m, 0:lmat))
727 ALLOCATE (basis%ddbf(nr, m, 0:lmat))
728 basis%bf = 0._dp
729 basis%dbf = 0._dp
730 basis%ddbf = 0._dp
731 DO l = 0, lmat
732 DO i = 1, basis%nbas(l)
733 al = basis%am(i, l)
734 DO k = 1, nr
735 rk = basis%grid%rad(k)
736 ear = exp(-al*basis%grid%rad(k)**2)
737 basis%bf(k, i, l) = rk**l*ear
738 basis%dbf(k, i, l) = (real(l, dp)*rk**(l - 1) - 2._dp*al*rk**(l + 1))*ear
739 basis%ddbf(k, i, l) = (real(l*(l - 1), dp)*rk**(l - 2) - &
740 2._dp*al*real(2*l + 1, dp)*rk**(l) + 4._dp*al**2*rk**(l + 2))*ear
741 END DO
742 END DO
743 END DO
744
745 CALL set_atom(atom, basis=basis)
746
747 ! optimization defaults
748 atom%optimization%damping = 0.2_dp
749 atom%optimization%eps_scf = 1.e-6_dp
750 atom%optimization%eps_diis = 100._dp
751 atom%optimization%max_iter = 50
752 atom%optimization%n_diis = 5
753
754 nelem = 0
755 ncore = 0
756 ncalc = 0
757 IF (monovalent) THEN
758 ncalc(0, 1) = 1
759 nelem(0, 1) = 1
760 ELSE IF (ASSOCIATED(gth_potential)) THEN
761 CALL get_potential(gth_potential, elec_conf=econf)
762 CALL set_pseudo_state(econf, z, ncalc, ncore, nelem)
763 ELSE IF (ASSOCIATED(sgp_potential)) THEN
764 CALL get_potential(sgp_potential, elec_conf=econf)
765 CALL set_pseudo_state(econf, z, ncalc, ncore, nelem)
766 ELSE
767 DO l = 0, min(lmat, ubound(ptable(z)%e_conv, 1))
768 ll = 2*(2*l + 1)
769 nn = ptable(z)%e_conv(l)
770 ii = 0
771 DO
772 ii = ii + 1
773 IF (nn <= ll) THEN
774 nelem(l, ii) = nn
775 EXIT
776 ELSE
777 nelem(l, ii) = ll
778 nn = nn - ll
779 END IF
780 END DO
781 END DO
782 ncalc = nelem - ncore
783 END IF
784
785 IF (qs_kind%ghost .OR. qs_kind%floating) THEN
786 nelem = 0
787 ncore = 0
788 ncalc = 0
789 END IF
790
791 ALLOCATE (atom%state)
792
793 atom%state%core = 0._dp
794 atom%state%core(0:lmat, 1:7) = real(ncore(0:lmat, 1:7), dp)
795 atom%state%occ = 0._dp
796 atom%state%occ(0:lmat, 1:7) = real(ncalc(0:lmat, 1:7), dp)
797 atom%state%occupation = 0._dp
798 atom%state%multiplicity = -1
799 DO l = 0, lmat
800 k = 0
801 DO i = 1, 7
802 IF (ncalc(l, i) > 0) THEN
803 k = k + 1
804 atom%state%occupation(l, k) = real(ncalc(l, i), dp)
805 END IF
806 END DO
807 END DO
808
809 atom%state%maxl_occ = get_maxl_occ(atom%state%occupation)
810 atom%state%maxn_occ = get_maxn_occ(atom%state%occupation)
811 atom%state%maxl_calc = atom%state%maxl_occ
812 atom%state%maxn_calc = atom%state%maxn_occ
813
814 ! calculate integrals
815 ! general integrals
816 CALL atom_int_setup(integrals, basis, potential=atom%potential, &
817 eri_coulomb=(atom%coulomb_integral_type == do_analytic), &
818 eri_exchange=(atom%exchange_integral_type == do_analytic))
819 ! potential
820 CALL atom_ppint_setup(integrals, basis, potential=atom%potential)
821 ! relativistic correction terms
822 NULLIFY (integrals%tzora, integrals%hdkh)
823 CALL atom_relint_setup(integrals, basis, atom%relativistic, zcore=real(atom%zcore, dp))
824 CALL set_atom(atom, integrals=integrals)
825
826 NULLIFY (orbitals)
827 mo = maxval(atom%state%maxn_calc)
828 mb = maxval(atom%basis%nbas)
829 CALL create_atom_orbs(orbitals, mb, mo)
830 CALL set_atom(atom, orbitals=orbitals)
831
832 CALL calculate_atom(atom, iw)
833
834 IF (do_basopt) THEN
835 CALL atom_fit_density(atom, ngto, 0, iw, results=results)
836 xx = results(1)
837 cc = results(2)
838 DO i = 1, ngto
839 density(i, 1) = xx*cc**i
840 density(i, 2) = results(2 + i)
841 END DO
842 ELSE
843 CALL atom_fit_density(atom, ngto, 0, iw, agto=density(:, 1), results=results)
844 density(1:ngto, 2) = results(1:ngto)
845 END IF
846
847 ! clean up
848 CALL atom_int_release(integrals)
849 CALL atom_ppint_release(integrals)
850 CALL atom_relint_release(integrals)
851 CALL release_atom_basis(basis)
852 CALL release_atom_potential(potential)
854
855 DEALLOCATE (potential, basis, integrals)
856
857 END SUBROUTINE calculate_atomic_density
858
859! **************************************************************************************************
860!> \brief ...
861!> \param atomic_kind ...
862!> \param qs_kind ...
863!> \param rel_control ...
864!> \param rtmat ...
865! **************************************************************************************************
866 SUBROUTINE calculate_atomic_relkin(atomic_kind, qs_kind, rel_control, rtmat)
867 TYPE(atomic_kind_type), INTENT(IN) :: atomic_kind
868 TYPE(qs_kind_type), INTENT(IN) :: qs_kind
869 TYPE(rel_control_type), POINTER :: rel_control
870 REAL(kind=dp), DIMENSION(:, :), POINTER :: rtmat
871
872 INTEGER :: i, ii, ipgf, j, k, k1, k2, l, ll, m, n, &
873 ngp, nj, nn, nr, ns, nset, nsgf, &
874 quadtype, relativistic, z
875 INTEGER, DIMENSION(0:lmat, 10) :: ncalc, ncore, nelem
876 INTEGER, DIMENSION(0:lmat, 100) :: set_index, shell_index
877 INTEGER, DIMENSION(:), POINTER :: lmax, lmin, npgf, nshell
878 INTEGER, DIMENSION(:, :), POINTER :: first_sgf, last_sgf, ls
879 REAL(kind=dp) :: al, alpha, ear, prefac, rk, zeff
880 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :) :: omat
881 REAL(kind=dp), DIMENSION(:, :), POINTER :: zet
882 REAL(kind=dp), DIMENSION(:, :, :), POINTER :: gcc
883 TYPE(all_potential_type), POINTER :: all_potential
884 TYPE(atom_basis_type), POINTER :: basis
885 TYPE(atom_integrals), POINTER :: integrals
886 TYPE(atom_potential_type), POINTER :: potential
887 TYPE(atom_type), POINTER :: atom
888 TYPE(grid_atom_type), POINTER :: grid
889 TYPE(gto_basis_set_type), POINTER :: orb_basis_set
890
891 IF (rel_control%rel_method == rel_none) RETURN
892
893 NULLIFY (all_potential, orb_basis_set)
894 CALL get_qs_kind(qs_kind, basis_set=orb_basis_set, all_potential=all_potential)
895
896 cpassert(ASSOCIATED(orb_basis_set))
897
898 IF (ASSOCIATED(all_potential)) THEN
899 ! only all electron atoms will get the relativistic correction
900
901 CALL get_atomic_kind(atomic_kind, z=z)
902 CALL get_qs_kind(qs_kind, zeff=zeff)
903 NULLIFY (atom)
905 NULLIFY (atom%xc_section)
906 NULLIFY (atom%orbitals)
907 atom%z = z
908 alpha = sqrt(all_potential%alpha_core_charge)
909
910 ! set the method flag
911 SELECT CASE (rel_control%rel_method)
912 CASE DEFAULT
913 cpabort("Unknown relativistic method for calculate_atomic_relkin")
914 CASE (rel_dkh)
915 SELECT CASE (rel_control%rel_DKH_order)
916 CASE DEFAULT
917 cpabort("Unknown DKH order for calculate_atomic_relkin")
918 CASE (0)
919 relativistic = do_dkh0_atom
920 CASE (1)
921 relativistic = do_dkh1_atom
922 CASE (2)
923 relativistic = do_dkh2_atom
924 CASE (3)
925 relativistic = do_dkh3_atom
926 END SELECT
927 CASE (rel_zora)
928 SELECT CASE (rel_control%rel_zora_type)
929 CASE DEFAULT
930 cpabort("Unknown ZORA type for calculate_atomic_relkin")
931 CASE (rel_zora_full)
932 cpabort("ZORA full not yet implemented in calculate_atomic_relkin")
933 CASE (rel_zora_mp)
934 relativistic = do_zoramp_atom
935 CASE (rel_sczora_mp)
936 relativistic = do_sczoramp_atom
937 END SELECT
938 END SELECT
939
940 CALL set_atom(atom, &
941 pp_calc=.false., &
942 method_type=do_rks_atom, &
943 relativistic=relativistic, &
944 coulomb_integral_type=do_numeric, &
945 exchange_integral_type=do_numeric)
946
947 ALLOCATE (potential, basis, integrals)
948
949 potential%ppot_type = no_pseudo
950 CALL set_atom(atom, zcore=z, potential=potential)
951
952 CALL get_gto_basis_set(orb_basis_set, &
953 nset=nset, nshell=nshell, npgf=npgf, lmin=lmin, lmax=lmax, l=ls, nsgf=nsgf, zet=zet, gcc=gcc, &
954 first_sgf=first_sgf, last_sgf=last_sgf)
955
956 NULLIFY (grid)
957 ngp = 400
958 quadtype = do_gapw_log
959 CALL allocate_grid_atom(grid)
960 CALL create_grid_atom(grid, ngp, 1, 1, 0, quadtype)
961 grid%nr = ngp
962 basis%grid => grid
963
964 NULLIFY (basis%am, basis%cm, basis%as, basis%ns, basis%bf, basis%dbf, basis%ddbf)
965 basis%basis_type = cgto_basis
966 basis%eps_eig = 1.e-12_dp
967
968 ! fill in the basis data structures
969 set_index = 0
970 shell_index = 0
971 basis%nprim = 0
972 basis%nbas = 0
973 DO i = 1, nset
974 DO j = lmin(i), min(lmax(i), lmat)
975 basis%nprim(j) = basis%nprim(j) + npgf(i)
976 END DO
977 DO j = 1, nshell(i)
978 l = ls(j, i)
979 IF (l <= lmat) THEN
980 basis%nbas(l) = basis%nbas(l) + 1
981 k = basis%nbas(l)
982 cpassert(k <= 100)
983 set_index(l, k) = i
984 shell_index(l, k) = j
985 END IF
986 END DO
987 END DO
988
989 nj = maxval(basis%nprim)
990 ns = maxval(basis%nbas)
991 ALLOCATE (basis%am(nj, 0:lmat))
992 basis%am = 0._dp
993 ALLOCATE (basis%cm(nj, ns, 0:lmat))
994 basis%cm = 0._dp
995 DO j = 0, lmat
996 nj = 0
997 ns = 0
998 DO i = 1, nset
999 IF (j >= lmin(i) .AND. j <= lmax(i)) THEN
1000 DO ipgf = 1, npgf(i)
1001 basis%am(nj + ipgf, j) = zet(ipgf, i)
1002 END DO
1003 DO ii = 1, nshell(i)
1004 IF (ls(ii, i) == j) THEN
1005 ns = ns + 1
1006 DO ipgf = 1, npgf(i)
1007 basis%cm(nj + ipgf, ns, j) = gcc(ipgf, ii, i)
1008 END DO
1009 END IF
1010 END DO
1011 nj = nj + npgf(i)
1012 END IF
1013 END DO
1014 END DO
1015
1016 ! Normalization as used in the atomic code
1017 ! We have to undo the Quickstep normalization
1018 DO j = 0, lmat
1019 prefac = 2.0_dp*sqrt(pi/dfac(2*j + 1))
1020 DO ipgf = 1, basis%nprim(j)
1021 DO ii = 1, basis%nbas(j)
1022 basis%cm(ipgf, ii, j) = prefac*basis%cm(ipgf, ii, j)
1023 END DO
1024 END DO
1025 END DO
1026
1027 ! initialize basis function on a radial grid
1028 nr = basis%grid%nr
1029 m = maxval(basis%nbas)
1030 ALLOCATE (basis%bf(nr, m, 0:lmat))
1031 ALLOCATE (basis%dbf(nr, m, 0:lmat))
1032 ALLOCATE (basis%ddbf(nr, m, 0:lmat))
1033
1034 basis%bf = 0._dp
1035 basis%dbf = 0._dp
1036 basis%ddbf = 0._dp
1037 DO l = 0, lmat
1038 DO i = 1, basis%nprim(l)
1039 al = basis%am(i, l)
1040 DO k = 1, nr
1041 rk = basis%grid%rad(k)
1042 ear = exp(-al*basis%grid%rad(k)**2)
1043 DO j = 1, basis%nbas(l)
1044 basis%bf(k, j, l) = basis%bf(k, j, l) + rk**l*ear*basis%cm(i, j, l)
1045 basis%dbf(k, j, l) = basis%dbf(k, j, l) &
1046 + (real(l, dp)*rk**(l - 1) - 2._dp*al*rk**(l + 1))*ear*basis%cm(i, j, l)
1047 basis%ddbf(k, j, l) = basis%ddbf(k, j, l) + &
1048 (real(l*(l - 1), dp)*rk**(l - 2) - 2._dp*al*real(2*l + 1, dp)* &
1049 rk**(l) + 4._dp*al**2*rk**(l + 2))*ear*basis%cm(i, j, l)
1050 END DO
1051 END DO
1052 END DO
1053 END DO
1054
1055 CALL set_atom(atom, basis=basis)
1056
1057 ! optimization defaults
1058 atom%optimization%damping = 0.2_dp
1059 atom%optimization%eps_scf = 1.e-6_dp
1060 atom%optimization%eps_diis = 100._dp
1061 atom%optimization%max_iter = 50
1062 atom%optimization%n_diis = 5
1063
1064 ! electronic state
1065 nelem = 0
1066 ncore = 0
1067 ncalc = 0
1068 DO l = 0, min(lmat, ubound(ptable(z)%e_conv, 1))
1069 ll = 2*(2*l + 1)
1070 nn = ptable(z)%e_conv(l)
1071 ii = 0
1072 DO
1073 ii = ii + 1
1074 IF (nn <= ll) THEN
1075 nelem(l, ii) = nn
1076 EXIT
1077 ELSE
1078 nelem(l, ii) = ll
1079 nn = nn - ll
1080 END IF
1081 END DO
1082 END DO
1083 ncalc = nelem - ncore
1084
1085 IF (qs_kind%ghost .OR. qs_kind%floating) THEN
1086 nelem = 0
1087 ncore = 0
1088 ncalc = 0
1089 END IF
1090
1091 ALLOCATE (atom%state)
1092
1093 atom%state%core = 0._dp
1094 atom%state%core(0:lmat, 1:7) = real(ncore(0:lmat, 1:7), dp)
1095 atom%state%occ = 0._dp
1096 atom%state%occ(0:lmat, 1:7) = real(ncalc(0:lmat, 1:7), dp)
1097 atom%state%occupation = 0._dp
1098 atom%state%multiplicity = -1
1099 DO l = 0, lmat
1100 k = 0
1101 DO i = 1, 7
1102 IF (ncalc(l, i) > 0) THEN
1103 k = k + 1
1104 atom%state%occupation(l, k) = real(ncalc(l, i), dp)
1105 END IF
1106 END DO
1107 END DO
1108
1109 atom%state%maxl_occ = get_maxl_occ(atom%state%occupation)
1110 atom%state%maxn_occ = get_maxn_occ(atom%state%occupation)
1111 atom%state%maxl_calc = atom%state%maxl_occ
1112 atom%state%maxn_calc = atom%state%maxn_occ
1113
1114 ! calculate integrals
1115 ! general integrals
1116 CALL atom_int_setup(integrals, basis)
1117 ! potential
1118 CALL atom_ppint_setup(integrals, basis, potential=atom%potential)
1119 ! relativistic correction terms
1120 NULLIFY (integrals%tzora, integrals%hdkh)
1121 CALL atom_relint_setup(integrals, basis, atom%relativistic, zcore=real(atom%zcore, dp), &
1122 alpha=alpha)
1123 CALL set_atom(atom, integrals=integrals)
1124
1125 ! for DKH we need erfc integrals to correct non-relativistic
1126 integrals%core = 0.0_dp
1127 DO l = 0, lmat
1128 n = integrals%n(l)
1129 m = basis%nprim(l)
1130 ALLOCATE (omat(m, m))
1131
1132 CALL sg_erfc(omat(1:m, 1:m), l, alpha, basis%am(1:m, l), basis%am(1:m, l))
1133 integrals%core(1:n, 1:n, l) = matmul(transpose(basis%cm(1:m, 1:n, l)), &
1134 matmul(omat(1:m, 1:m), basis%cm(1:m, 1:n, l)))
1135
1136 DEALLOCATE (omat)
1137 END DO
1138
1139 ! recover relativistic kinetic matrix in CP2K/GPW order and normalization
1140 IF (ASSOCIATED(rtmat)) THEN
1141 DEALLOCATE (rtmat)
1142 END IF
1143 ALLOCATE (rtmat(nsgf, nsgf))
1144 rtmat = 0._dp
1145 DO l = 0, lmat
1146 ll = 2*l
1147 DO k1 = 1, basis%nbas(l)
1148 DO k2 = 1, basis%nbas(l)
1149 i = first_sgf(shell_index(l, k1), set_index(l, k1))
1150 j = first_sgf(shell_index(l, k2), set_index(l, k2))
1151 SELECT CASE (atom%relativistic)
1152 CASE DEFAULT
1153 cpabort("Unknown relativistic type for calculate_atomic_relkin")
1155 DO m = 0, ll
1156 rtmat(i + m, j + m) = integrals%tzora(k1, k2, l)
1157 END DO
1159 DO m = 0, ll
1160 rtmat(i + m, j + m) = integrals%hdkh(k1, k2, l) - integrals%kin(k1, k2, l) + &
1161 atom%zcore*integrals%core(k1, k2, l)
1162 END DO
1163 END SELECT
1164 END DO
1165 END DO
1166 END DO
1167 DO k1 = 1, nsgf
1168 DO k2 = k1, nsgf
1169 rtmat(k1, k2) = 0.5_dp*(rtmat(k1, k2) + rtmat(k2, k1))
1170 rtmat(k2, k1) = rtmat(k1, k2)
1171 END DO
1172 END DO
1173
1174 ! clean up
1175 CALL atom_int_release(integrals)
1176 CALL atom_ppint_release(integrals)
1177 CALL atom_relint_release(integrals)
1178 CALL release_atom_basis(basis)
1179 CALL release_atom_potential(potential)
1181
1182 DEALLOCATE (potential, basis, integrals)
1183
1184 ELSE
1185
1186 IF (ASSOCIATED(rtmat)) THEN
1187 DEALLOCATE (rtmat)
1188 END IF
1189 NULLIFY (rtmat)
1190
1191 END IF
1192
1193 END SUBROUTINE calculate_atomic_relkin
1194
1195! **************************************************************************************************
1196!> \brief ...
1197!> \param gth_potential ...
1198!> \param gth_atompot ...
1199! **************************************************************************************************
1200 SUBROUTINE gth_potential_conversion(gth_potential, gth_atompot)
1201 TYPE(gth_potential_type), POINTER :: gth_potential
1202 TYPE(atom_gthpot_type) :: gth_atompot
1203
1204 INTEGER :: i, j, l, lm, n, ne, nexp_lpot, nexp_lsd, &
1205 nexp_nlcc
1206 INTEGER, DIMENSION(:), POINTER :: nct_lpot, nct_lsd, nct_nlcc, nppnl, &
1207 ppeconf
1208 LOGICAL :: lpot_present, lsd_present, nlcc_present, &
1209 soc_present
1210 REAL(kind=dp) :: ac, zeff
1211 REAL(kind=dp), DIMENSION(:), POINTER :: alpha_lpot, alpha_lsd, alpha_nlcc, ap, ce
1212 REAL(kind=dp), DIMENSION(:, :), POINTER :: cval_lpot, cval_lsd, cval_nlcc
1213 REAL(kind=dp), DIMENSION(:, :, :), POINTER :: hp, kp
1214
1215 CALL get_potential(gth_potential, &
1216 zeff=zeff, &
1217 elec_conf=ppeconf, &
1218 alpha_core_charge=ac, &
1219 nexp_ppl=ne, &
1220 cexp_ppl=ce, &
1221 lppnl=lm, &
1222 nprj_ppnl=nppnl, &
1223 alpha_ppnl=ap, &
1224 kprj_ppnl=kp, &
1225 hprj_ppnl=hp)
1226
1227 gth_atompot%zion = zeff
1228 gth_atompot%rc = sqrt(0.5_dp/ac)
1229 gth_atompot%ncl = ne
1230 gth_atompot%cl(:) = 0._dp
1231 IF (ac > 0._dp) THEN
1232 DO i = 1, ne
1233 gth_atompot%cl(i) = ce(i)/(2._dp*ac)**(i - 1)
1234 END DO
1235 END IF
1236 !extended type
1237 gth_atompot%lpotextended = .false.
1238 gth_atompot%lsdpot = .false.
1239 gth_atompot%nlcc = .false.
1240 gth_atompot%nexp_lpot = 0
1241 gth_atompot%nexp_lsd = 0
1242 gth_atompot%nexp_nlcc = 0
1243 CALL get_potential(gth_potential, &
1244 lpot_present=lpot_present, &
1245 lsd_present=lsd_present, &
1246 nlcc_present=nlcc_present)
1247 IF (lpot_present) THEN
1248 CALL get_potential(gth_potential, &
1249 nexp_lpot=nexp_lpot, &
1250 alpha_lpot=alpha_lpot, &
1251 nct_lpot=nct_lpot, &
1252 cval_lpot=cval_lpot)
1253 gth_atompot%lpotextended = .true.
1254 gth_atompot%nexp_lpot = nexp_lpot
1255 gth_atompot%alpha_lpot(1:nexp_lpot) = sqrt(0.5_dp/alpha_lpot(1:nexp_lpot))
1256 gth_atompot%nct_lpot(1:nexp_lpot) = nct_lpot(1:nexp_lpot)
1257 DO j = 1, nexp_lpot
1258 ac = alpha_lpot(j)
1259 DO i = 1, 4
1260 gth_atompot%cval_lpot(i, j) = cval_lpot(i, j)/(2._dp*ac)**(i - 1)
1261 END DO
1262 END DO
1263 END IF
1264 IF (lsd_present) THEN
1265 CALL get_potential(gth_potential, &
1266 nexp_lsd=nexp_lsd, &
1267 alpha_lsd=alpha_lsd, &
1268 nct_lsd=nct_lsd, &
1269 cval_lsd=cval_lsd)
1270 gth_atompot%lsdpot = .true.
1271 gth_atompot%nexp_lsd = nexp_lsd
1272 gth_atompot%alpha_lsd(1:nexp_lsd) = sqrt(0.5_dp/alpha_lsd(1:nexp_lsd))
1273 gth_atompot%nct_lsd(1:nexp_lsd) = nct_lsd(1:nexp_lsd)
1274 DO j = 1, nexp_lpot
1275 ac = alpha_lsd(j)
1276 DO i = 1, 4
1277 gth_atompot%cval_lsd(i, j) = cval_lsd(i, j)/(2._dp*ac)**(i - 1)
1278 END DO
1279 END DO
1280 END IF
1281
1282 ! nonlocal part
1283 gth_atompot%nl(:) = 0
1284 gth_atompot%rcnl(:) = 0._dp
1285 gth_atompot%hnl(:, :, :) = 0._dp
1286 DO l = 0, lm
1287 n = nppnl(l)
1288 gth_atompot%nl(l) = n
1289 gth_atompot%rcnl(l) = sqrt(0.5_dp/ap(l))
1290 gth_atompot%hnl(1:n, 1:n, l) = hp(1:n, 1:n, l)
1291 END DO
1292
1293 ! SOC
1294 CALL get_potential(gth_potential, soc_present=soc_present)
1295 gth_atompot%soc = soc_present
1296 gth_atompot%knl = 0.0_dp
1297 IF (soc_present) THEN
1298 DO l = 1, lm
1299 n = nppnl(l)
1300 gth_atompot%knl(1:n, 1:n, l) = kp(1:n, 1:n, l)
1301 END DO
1302 END IF
1303
1304 IF (nlcc_present) THEN
1305 CALL get_potential(gth_potential, &
1306 nexp_nlcc=nexp_nlcc, &
1307 alpha_nlcc=alpha_nlcc, &
1308 nct_nlcc=nct_nlcc, &
1309 cval_nlcc=cval_nlcc)
1310 gth_atompot%nlcc = .true.
1311 gth_atompot%nexp_nlcc = nexp_nlcc
1312 gth_atompot%alpha_nlcc(1:nexp_nlcc) = alpha_nlcc(1:nexp_nlcc)
1313 gth_atompot%nct_nlcc(1:nexp_nlcc) = nct_nlcc(1:nexp_nlcc)
1314 gth_atompot%cval_nlcc(1:4, 1:nexp_nlcc) = cval_nlcc(1:4, 1:nexp_nlcc)
1315 END IF
1316
1317 END SUBROUTINE gth_potential_conversion
1318
1319! **************************************************************************************************
1320!> \brief ...
1321!> \param sgp_potential ...
1322!> \param sgp_atompot ...
1323! **************************************************************************************************
1324 SUBROUTINE sgp_potential_conversion(sgp_potential, sgp_atompot)
1325 TYPE(sgp_potential_type), POINTER :: sgp_potential
1326 TYPE(atom_sgppot_type) :: sgp_atompot
1327
1328 INTEGER :: lm, n
1329 INTEGER, DIMENSION(:), POINTER :: ppeconf
1330 LOGICAL :: nlcc_present
1331 REAL(kind=dp) :: ac, zeff
1332 REAL(kind=dp), DIMENSION(:), POINTER :: ap, ce
1333 REAL(kind=dp), DIMENSION(:, :), POINTER :: hhp
1334 REAL(kind=dp), DIMENSION(:, :, :), POINTER :: ccp
1335
1336 CALL get_potential(sgp_potential, &
1337 name=sgp_atompot%pname, &
1338 zeff=zeff, &
1339 elec_conf=ppeconf, &
1340 core_charge_radius=ac)
1341 sgp_atompot%zion = zeff
1342 sgp_atompot%ac_local = ac
1343 sgp_atompot%econf(0:3) = ppeconf(0:3)
1344 CALL get_potential(sgp_potential, lmax=lm, &
1345 is_nonlocal=sgp_atompot%is_nonlocal, &
1346 n_nonlocal=n, a_nonlocal=ap, h_nonlocal=hhp, c_nonlocal=ccp)
1347 ! nonlocal
1348 sgp_atompot%has_nonlocal = any(sgp_atompot%is_nonlocal)
1349 sgp_atompot%lmax = lm
1350 IF (sgp_atompot%has_nonlocal) THEN
1351 cpassert(n <= SIZE(sgp_atompot%a_nonlocal))
1352 sgp_atompot%n_nonlocal = n
1353 sgp_atompot%a_nonlocal(1:n) = ap(1:n)
1354 sgp_atompot%h_nonlocal(1:n, 0:lm) = hhp(1:n, 0:lm)
1355 ! The atomic solver uses unit-normalized spherical harmonics and
1356 ! radial integrals; undo the SGP storage factor 1/sqrt(4*pi).
1357 sgp_atompot%c_nonlocal(1:n, 1:n, 0:lm) = sqrt(fourpi)*ccp(1:n, 1:n, 0:lm)
1358 END IF
1359 ! local
1360 CALL get_potential(sgp_potential, n_local=n, a_local=ap, c_local=ce)
1361 cpassert(n <= SIZE(sgp_atompot%a_local))
1362 sgp_atompot%n_local = n
1363 sgp_atompot%a_local(1:n) = ap(1:n)
1364 sgp_atompot%c_local(1:n) = ce(1:n)
1365 ! NLCC
1366 CALL get_potential(sgp_potential, has_nlcc=nlcc_present, &
1367 n_nlcc=n, a_nlcc=ap, c_nlcc=ce)
1368 IF (nlcc_present) THEN
1369 sgp_atompot%has_nlcc = .true.
1370 cpassert(n <= SIZE(sgp_atompot%a_nlcc))
1371 sgp_atompot%n_nlcc = n
1372 sgp_atompot%a_nlcc(1:n) = ap(1:n)
1373 sgp_atompot%c_nlcc(1:n) = ce(1:n)
1374 ELSE
1375 sgp_atompot%has_nlcc = .false.
1376 END IF
1377
1378 END SUBROUTINE sgp_potential_conversion
1379
1380! **************************************************************************************************
1381!> \brief ...
1382!> \param sgp_potential ...
1383!> \param ecp_atompot ...
1384! **************************************************************************************************
1385 SUBROUTINE ecp_potential_conversion(sgp_potential, ecp_atompot)
1386 TYPE(sgp_potential_type), POINTER :: sgp_potential
1387 TYPE(atom_ecppot_type) :: ecp_atompot
1388
1389 INTEGER, DIMENSION(:), POINTER :: ppeconf
1390 LOGICAL :: ecp_local, ecp_semi_local
1391 REAL(kind=dp) :: zeff
1392
1393 CALL get_potential(sgp_potential, ecp_local=ecp_local, ecp_semi_local=ecp_semi_local)
1394 cpassert(ecp_semi_local .AND. ecp_local)
1395 CALL get_potential(sgp_potential, &
1396 name=ecp_atompot%pname, &
1397 zeff=zeff, &
1398 elec_conf=ppeconf)
1399 ecp_atompot%zion = zeff
1400 ecp_atompot%econf(0:3) = ppeconf(0:3)
1401 CALL get_potential(sgp_potential, sl_lmax=ecp_atompot%lmax)
1402 ! local
1403 CALL get_potential(sgp_potential, nloc=ecp_atompot%nloc, nrloc=ecp_atompot%nrloc, &
1404 aloc=ecp_atompot%aloc, bloc=ecp_atompot%bloc)
1405 ! nonlocal
1406 CALL get_potential(sgp_potential, npot=ecp_atompot%npot, nrpot=ecp_atompot%nrpot, &
1407 apot=ecp_atompot%apot, bpot=ecp_atompot%bpot)
1408
1409 END SUBROUTINE ecp_potential_conversion
1410! **************************************************************************************************
1411
1412END MODULE atom_kind_orbitals
subroutine, public sg_erfc(umat, l, a, pa, pb)
...
subroutine, public calculate_atom(atom, iw, noguess, converged)
General routine to perform electronic structure atomic calculations.
routines that fit parameters for /from atomic calculations
Definition atom_fit.F:11
subroutine, public atom_fit_density(atom, num_gto, norder, iunit, agto, powell_section, results)
Fit the atomic electron density using a geometrical Gaussian basis set.
Definition atom_fit.F:78
calculate the orbitals for a given atomic kind type
subroutine, public calculate_atomic_relkin(atomic_kind, qs_kind, rel_control, rtmat)
...
subroutine, public sgp_potential_conversion(sgp_potential, sgp_atompot)
...
subroutine, public calculate_atomic_density(density, atomic_kind, qs_kind, ngto, iunit, optbasis, allelectron, confine)
...
subroutine, public gth_potential_conversion(gth_potential, gth_atompot)
...
subroutine, public calculate_atomic_orbitals(atomic_kind, qs_kind, agrid, iunit, pmat, fmat, density, wavefunction, wfninfo, confine, xc_section, nocc, which_l, which_n, proj_shell_charge, ao_coef)
...
Calculate the atomic operator matrices.
subroutine, public atom_ppint_release(integrals)
Release memory allocated for atomic integrals (core electrons).
subroutine, public atom_int_setup(integrals, basis, potential, eri_coulomb, eri_exchange, all_nu)
Set up atomic integrals.
subroutine, public atom_relint_setup(integrals, basis, reltyp, zcore, alpha)
...
subroutine, public atom_relint_release(integrals)
Release memory allocated for atomic integrals (relativistic effects).
subroutine, public atom_ppint_setup(integrals, basis, potential)
...
subroutine, public atom_int_release(integrals)
Release memory allocated for atomic integrals (valence electrons).
subroutine, public set_kind_basis_atomic(basis, orb_basis_set, has_pp, agrid, cp2k_norm)
...
Define the atom type and its sub types.
Definition atom_types.F:15
subroutine, public create_atom_type(atom)
...
Definition atom_types.F:968
integer, parameter, public cgto_basis
Definition atom_types.F:70
integer, parameter, public gto_basis
Definition atom_types.F:70
subroutine, public release_atom_type(atom)
...
Definition atom_types.F:992
subroutine, public release_atom_potential(potential)
...
integer, parameter, public lmat
Definition atom_types.F:68
subroutine, public set_atom(atom, basis, state, integrals, orbitals, potential, zcore, pp_calc, do_zmp, doread, read_vxc, method_type, relativistic, coulomb_integral_type, exchange_integral_type, fmat)
...
subroutine, public release_atom_basis(basis)
...
Definition atom_types.F:934
subroutine, public create_atom_orbs(orbs, mbas, mo)
...
subroutine, public clementi_geobas(zval, cval, aval, ngto, ival)
...
Some basic routines for atomic calculations.
Definition atom_utils.F:15
pure integer function, dimension(0:lmat), public get_maxn_occ(occupation)
Return the maximum principal quantum number of occupied orbitals.
Definition atom_utils.F:300
subroutine, public atom_density(density, pmat, basis, maxl, typ, rr)
Map the electron density on an atomic radial grid.
Definition atom_utils.F:365
pure integer function, public get_maxl_occ(occupation)
Return the maximum orbital quantum number of occupied orbitals.
Definition atom_utils.F:280
Definition atom.F:9
Define the atomic kind types and their sub types.
subroutine, public get_atomic_kind(atomic_kind, fist_potential, element_symbol, name, mass, kind_number, natom, atom_list, rcov, rvdw, z, qeff, apol, cpol, mm_radius, shell, shell_active, damping)
Get attributes of an atomic kind.
subroutine, public get_gto_basis_set(gto_basis_set, name, aliases, norm_type, kind_radius, ncgf, nset, nsgf, cgf_symbol, sgf_symbol, norm_cgf, set_radius, lmax, lmin, lx, ly, lz, m, ncgf_set, npgf, nsgf_set, nshell, cphi, pgf_radius, sphi, scon, zet, first_cgf, first_sgf, l, last_cgf, last_sgf, n, gcc, maxco, maxl, maxpgf, maxsgf_set, maxshell, maxso, nco_sum, npgf_sum, nshell_sum, maxder, short_kind_radius, npgf_seg_sum, ccon)
...
Definition of the atomic potential types.
collects all constants needed in input so that they can be used without circular dependencies
integer, parameter, public rel_zora_full
integer, parameter, public do_rks_atom
integer, parameter, public do_analytic
integer, parameter, public sgp_pseudo
integer, parameter, public do_dkh3_atom
integer, parameter, public gth_pseudo
integer, parameter, public ecp_pseudo
integer, parameter, public do_nonrel_atom
integer, parameter, public do_dkh0_atom
integer, parameter, public rel_zora_mp
integer, parameter, public rel_zora
integer, parameter, public upf_pseudo
integer, parameter, public poly_conf
integer, parameter, public do_dkh2_atom
integer, parameter, public no_pseudo
integer, parameter, public do_uks_atom
integer, parameter, public barrier_conf
integer, parameter, public rel_dkh
integer, parameter, public do_numeric
integer, parameter, public do_zoramp_atom
integer, parameter, public do_gapw_log
integer, parameter, public do_dkh1_atom
integer, parameter, public rel_none
integer, parameter, public rel_sczora_mp
integer, parameter, public do_sczoramp_atom
objects that represent the structure of input sections and the data contained in an input section
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
Definition of mathematical constants and functions.
real(kind=dp), parameter, public pi
real(kind=dp), dimension(-1:2 *maxfac+1), parameter, public dfac
real(kind=dp), parameter, public fourpi
Periodic Table related data definitions.
type(atom), dimension(0:nelem), public ptable
integer, parameter, public nelem
Definition of physical constants:
Definition physcon.F:68
real(kind=dp), parameter, public bohr
Definition physcon.F:147
subroutine, public allocate_grid_atom(grid_atom)
Initialize components of the grid_atom_type structure.
subroutine, public create_grid_atom(grid_atom, nr, na, llmax, ll, quadrature)
...
Define the quickstep kind type and their sub types.
subroutine, public set_pseudo_state(econf, z, ncalc, ncore, nelem)
...
logical function, public has_nlcc(qs_kind_set)
finds if a given qs run needs to use nlcc
subroutine, public get_qs_kind(qs_kind, basis_set, basis_type, ncgf, nsgf, all_potential, tnadd_potential, gth_potential, sgp_potential, upf_potential, cneo_potential, se_parameter, dftb_parameter, xtb_parameter, dftb3_param, zatom, zeff, elec_conf, mao, lmax_dftb, alpha_core_charge, ccore_charge, core_charge, core_charge_radius, paw_proj_set, paw_atom, hard_radius, hard0_radius, max_rad_local, covalent_radius, vdw_radius, gpw_type_forced, harmonics, max_iso_not0, max_s_harm, grid_atom, ngrid_ang, ngrid_rad, lmax_rho0, dft_plus_u_atom, l_of_dft_plus_u, n_of_dft_plus_u, u_minus_j, hund_j, u_of_dft_plus_u, j_of_dft_plus_u, alpha_of_dft_plus_u, beta_of_dft_plus_u, j0_of_dft_plus_u, occupation_of_dft_plus_u, dispersion, bs_occupation, magnetization, no_optimize, addel, laddel, naddel, orbitals, max_scf, eps_scf, smear, u_ramping, u_minus_j_target, eps_u_ramping, proj_shell_charge, lr_atom, do_mtlr, u_j_loop, ao_coef, init_u_ramping_each_scf, reltmat, ghost, monovalent, floating, name, element_symbol, pao_basis_size, pao_model_file, pao_potentials, pao_descriptors, nelec)
Get attributes of an atomic kind.
subroutine, public init_atom_electronic_state(atomic_kind, qs_kind, ncalc, ncore, nelem, edelta, rks)
...
parameters that control a relativistic calculation
Provides all information about a basis set.
Definition atom_types.F:79
Provides all information about a pseudopotential.
Definition atom_types.F:99
Holds atomic orbitals and energies.
Definition atom_types.F:238
Provides all information about an atomic kind.
Definition atom_types.F:294
Provides all information about an atomic kind.
Provides all information about a quickstep kind.
contains the parameters needed by a relativistic calculation