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