(git:ed6f26b)
Loading...
Searching...
No Matches
atom_grb.F
Go to the documentation of this file.
1!--------------------------------------------------------------------------------------------------!
2! CP2K: A general program to perform molecular dynamics simulations !
3! Copyright 2000-2025 CP2K developers group <https://cp2k.org> !
4! !
5! SPDX-License-Identifier: GPL-2.0-or-later !
6!--------------------------------------------------------------------------------------------------!
7
8MODULE atom_grb
9 USE ai_onecenter, ONLY: sg_conf,&
20 USE atom_types, ONLY: &
26 USE cp_files, ONLY: close_file,&
28 USE input_constants, ONLY: barrier_conf,&
38 USE kinds, ONLY: default_string_length,&
39 dp
40 USE mathconstants, ONLY: dfac,&
41 rootpi
46 USE periodic_table, ONLY: ptable
47 USE physcon, ONLY: bohr
48 USE powell, ONLY: opt_state_type,&
52#include "./base/base_uses.f90"
53
54 IMPLICIT NONE
55
57 TYPE(atom_basis_type), POINTER :: basis => null()
58 END TYPE basis_p_type
59
60 PRIVATE
61 PUBLIC :: atom_grb_construction
62
63 CHARACTER(len=*), PARAMETER, PRIVATE :: modulen = 'atom_grb'
64
65CONTAINS
66
67! **************************************************************************************************
68!> \brief Construct geometrical response basis set.
69!> \param atom_info information about the atomic kind. Two-dimensional array of size
70!> (electronic-configuration, electronic-structure-method)
71!> \param atom_section ATOM input section
72!> \param iw output file unit
73!> \par History
74!> * 11.2016 created [Juerg Hutter]
75! **************************************************************************************************
76 SUBROUTINE atom_grb_construction(atom_info, atom_section, iw)
77
78 TYPE(atom_p_type), DIMENSION(:, :), POINTER :: atom_info
79 TYPE(section_vals_type), POINTER :: atom_section
80 INTEGER, INTENT(IN) :: iw
81
82 CHARACTER(len=default_string_length) :: abas, basname
83 CHARACTER(len=default_string_length), DIMENSION(1) :: basline
84 CHARACTER(len=default_string_length), DIMENSION(3) :: headline
85 INTEGER :: i, ider, is, iunit, j, k, l, lhomo, ll, &
86 lval, m, maxl, mb, method, mo, n, &
87 nder, ngp, nhomo, nr, num_gto, &
88 num_pol, quadtype, s1, s2
89 INTEGER, DIMENSION(0:7) :: nbas
90 INTEGER, DIMENSION(0:lmat) :: next_bas, next_prim
91 INTEGER, DIMENSION(:), POINTER :: num_bas
92 REAL(kind=dp) :: al, amin, aval, cnum, crad, cradx, cval, delta, dene, ear, emax, &
93 energy_ex(0:lmat), energy_ref, energy_vb(0:lmat), expzet, fhomo, o, prefac, rconf, rk, &
94 rmax, scon, zeta, zval
95 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: ale, alp, rho
96 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :) :: amat
97 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :, :) :: ebasis, pbasis, qbasis, rbasis
98 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :, :, :) :: wfn
99 REAL(kind=dp), DIMENSION(:, :, :), POINTER :: ovlp
100 TYPE(atom_basis_type), POINTER :: basis, basis_grb, basis_ref, basis_vrb
101 TYPE(atom_integrals), POINTER :: atint
102 TYPE(atom_orbitals), POINTER :: orbitals
103 TYPE(atom_state), POINTER :: state
104 TYPE(atom_type), POINTER :: atom, atom_ref, atom_test
105 TYPE(basis_p_type), DIMENSION(0:10) :: vbasis
106 TYPE(section_vals_type), POINTER :: grb_section, powell_section
107
108 IF (iw > 0) WRITE (iw, '(/," ",79("*"),/,T28,A,/," ",79("*"))') "GEOMETRICAL RESPONSE BASIS"
109
110 DO i = 0, 10
111 NULLIFY (vbasis(i)%basis)
112 END DO
113 ! make some basic checks
114 is = SIZE(atom_info)
115 IF (iw > 0 .AND. is > 1) THEN
116 WRITE (iw, '(/,A,/)') " WARNING: Only use first electronic structure/method for basis set generation"
117 END IF
118 atom_ref => atom_info(1, 1)%atom
119
120 ! check method
121 method = atom_ref%method_type
122 SELECT CASE (method)
124 ! restricted methods are okay
126 cpabort("Unrestricted methods not allowed for GRB generation")
127 CASE DEFAULT
128 cpabort("")
129 END SELECT
130
131 ! input for basis optimization
132 grb_section => section_vals_get_subs_vals(atom_section, "PRINT%GEOMETRICAL_RESPONSE_BASIS")
133
134 ! generate an atom type
135 NULLIFY (atom)
137 CALL copy_atom_basics(atom_ref, atom, state=.true., potential=.true., optimization=.true., xc=.true.)
138 ! set confinement potential
139 atom%potential%confinement = .true.
140 atom%potential%conf_type = barrier_conf
141 atom%potential%acon = 200._dp
142 atom%potential%rcon = 4._dp
143 CALL section_vals_val_get(grb_section, "CONFINEMENT", r_val=scon)
144 atom%potential%scon = scon
145 ! generate main block geometrical exponents
146 basis_ref => atom_ref%basis
147 ALLOCATE (basis)
148 NULLIFY (basis%am, basis%cm, basis%as, basis%ns, basis%bf, basis%dbf, basis%ddbf)
149 ! get information on quadrature type and number of grid points
150 ! allocate and initialize the atomic grid
151 NULLIFY (basis%grid)
152 CALL allocate_grid_atom(basis%grid)
153 CALL section_vals_val_get(grb_section, "QUADRATURE", i_val=quadtype)
154 CALL section_vals_val_get(grb_section, "GRID_POINTS", i_val=ngp)
155 IF (ngp <= 0) &
156 cpabort("# point radial grid < 0")
157 CALL create_grid_atom(basis%grid, ngp, 1, 1, 0, quadtype)
158 basis%grid%nr = ngp
159 !
160 maxl = atom%state%maxl_occ
161 basis%basis_type = gto_basis
162 CALL section_vals_val_get(grb_section, "NUM_GTO_CORE", i_val=num_gto)
163 basis%nbas = 0
164 basis%nbas(0:maxl) = num_gto
165 basis%nprim = basis%nbas
166 CALL section_vals_val_get(grb_section, "GEOMETRICAL_FACTOR", r_val=cval)
167 CALL section_vals_val_get(grb_section, "GEO_START_VALUE", r_val=aval)
168 m = maxval(basis%nbas)
169 ALLOCATE (basis%am(m, 0:lmat))
170 basis%am = 0._dp
171 DO l = 0, lmat
172 DO i = 1, basis%nbas(l)
173 ll = i - 1
174 basis%am(i, l) = aval*cval**(ll)
175 END DO
176 END DO
177
178 basis%eps_eig = basis_ref%eps_eig
179 basis%geometrical = .true.
180 basis%aval = aval
181 basis%cval = cval
182 basis%start = 0
183
184 ! initialize basis function on a radial grid
185 nr = basis%grid%nr
186 m = maxval(basis%nbas)
187 ALLOCATE (basis%bf(nr, m, 0:lmat))
188 ALLOCATE (basis%dbf(nr, m, 0:lmat))
189 ALLOCATE (basis%ddbf(nr, m, 0:lmat))
190 basis%bf = 0._dp
191 basis%dbf = 0._dp
192 basis%ddbf = 0._dp
193 DO l = 0, lmat
194 DO i = 1, basis%nbas(l)
195 al = basis%am(i, l)
196 DO k = 1, nr
197 rk = basis%grid%rad(k)
198 ear = exp(-al*basis%grid%rad(k)**2)
199 basis%bf(k, i, l) = rk**l*ear
200 basis%dbf(k, i, l) = (real(l, dp)*rk**(l - 1) - 2._dp*al*rk**(l + 1))*ear
201 basis%ddbf(k, i, l) = (real(l*(l - 1), dp)*rk**(l - 2) - &
202 2._dp*al*real(2*l + 1, dp)*rk**(l) + 4._dp*al*rk**(l + 2))*ear
203 END DO
204 END DO
205 END DO
206
207 NULLIFY (orbitals)
208 mo = maxval(atom%state%maxn_calc)
209 mb = maxval(basis%nbas)
210 CALL create_atom_orbs(orbitals, mb, mo)
211 CALL set_atom(atom, orbitals=orbitals)
212
213 powell_section => section_vals_get_subs_vals(atom_section, "POWELL")
214 CALL atom_fit_grb(atom, basis, iw, powell_section)
215 CALL set_atom(atom, basis=basis)
216
217 ! generate response contractions
218 CALL section_vals_val_get(grb_section, "DELTA_CHARGE", r_val=delta)
219 CALL section_vals_val_get(grb_section, "DERIVATIVES", i_val=nder)
220 IF (iw > 0) THEN
221 WRITE (iw, '(/,A,T76,I5)') " Generate Response Basis Sets with Order ", nder
222 END IF
223
224 state => atom%state
225 ! find HOMO
226 lhomo = -1
227 nhomo = -1
228 emax = -huge(1._dp)
229 DO l = 0, state%maxl_occ
230 DO i = 1, state%maxn_occ(l)
231 IF (atom%orbitals%ener(i, l) > emax) THEN
232 lhomo = l
233 nhomo = i
234 emax = atom%orbitals%ener(i, l)
235 fhomo = state%occupation(l, i)
236 END IF
237 END DO
238 END DO
239
240 s1 = SIZE(atom%orbitals%wfn, 1)
241 s2 = SIZE(atom%orbitals%wfn, 2)
242 ALLOCATE (wfn(s1, s2, 0:lmat, -nder:nder))
243 s2 = maxval(state%maxn_occ) + nder
244 ALLOCATE (rbasis(s1, s2, 0:lmat), qbasis(s1, s2, 0:lmat))
245 rbasis = 0._dp
246 qbasis = 0._dp
247
248 ! calculate integrals
249 ALLOCATE (atint)
250 CALL atom_int_setup(atint, basis, potential=atom%potential, eri_coulomb=.false., eri_exchange=.false.)
251 CALL atom_ppint_setup(atint, basis, potential=atom%potential)
252 IF (atom%pp_calc) THEN
253 NULLIFY (atint%tzora, atint%hdkh)
254 ELSE
255 ! relativistic correction terms
256 CALL atom_relint_setup(atint, basis, atom%relativistic, zcore=real(atom%z, dp))
257 END IF
258 CALL set_atom(atom, integrals=atint)
259
260 CALL calculate_atom(atom, iw=0)
261 DO ider = -nder, nder
262 dene = real(ider, kind=dp)*delta
263 cpassert(fhomo > abs(dene))
264 state%occupation(lhomo, nhomo) = fhomo + dene
265 CALL calculate_atom(atom, iw=0, noguess=.true.)
266 wfn(:, :, :, ider) = atom%orbitals%wfn
267 state%occupation(lhomo, nhomo) = fhomo
268 END DO
269 IF (iw > 0) THEN
270 WRITE (iw, '(A,T76,I5)') " Total number of electronic structure calculations ", 2*nder + 1
271 END IF
272
273 ovlp => atom%integrals%ovlp
274
275 DO l = 0, state%maxl_occ
276 IF (iw > 0) THEN
277 WRITE (iw, '(A,T76,I5)') " Response derivatives for l quantum number ", l
278 END IF
279 ! occupied states
280 DO i = 1, max(state%maxn_occ(l), 1)
281 rbasis(:, i, l) = wfn(:, i, l, 0)
282 END DO
283 ! differentiation
284 DO ider = 1, nder
285 i = max(state%maxn_occ(l), 1)
286 SELECT CASE (ider)
287 CASE (1)
288 rbasis(:, i + 1, l) = 0.5_dp*(wfn(:, i, l, 1) - wfn(:, i, l, -1))/delta
289 CASE (2)
290 rbasis(:, i + 2, l) = 0.25_dp*(wfn(:, i, l, 2) - 2._dp*wfn(:, i, l, 0) + wfn(:, i, l, -2))/delta**2
291 CASE (3)
292 rbasis(:, i + 3, l) = 0.125_dp*(wfn(:, i, l, 3) - 3._dp*wfn(:, i, l, 1) &
293 + 3._dp*wfn(:, i, l, -1) - wfn(:, i, l, -3))/delta**3
294 CASE DEFAULT
295 cpabort("")
296 END SELECT
297 END DO
298
299 ! orthogonalization, use gram-schmidt in order to keep the natural order (semi-core, valence, response) of the wfn.
300 n = state%maxn_occ(l) + nder
301 m = atom%basis%nbas(l)
302 DO i = 1, n
303 DO j = 1, i - 1
304 o = dot_product(rbasis(1:m, j, l), reshape(matmul(ovlp(1:m, 1:m, l), rbasis(1:m, i:i, l)), (/m/)))
305 rbasis(1:m, i, l) = rbasis(1:m, i, l) - o*rbasis(1:m, j, l)
306 END DO
307 o = dot_product(rbasis(1:m, i, l), reshape(matmul(ovlp(1:m, 1:m, l), rbasis(1:m, i:i, l)), (/m/)))
308 rbasis(1:m, i, l) = rbasis(1:m, i, l)/sqrt(o)
309 END DO
310
311 ! check
312 ALLOCATE (amat(n, n))
313 amat(1:n, 1:n) = matmul(transpose(rbasis(1:m, 1:n, l)), matmul(ovlp(1:m, 1:m, l), rbasis(1:m, 1:n, l)))
314 DO i = 1, n
315 amat(i, i) = amat(i, i) - 1._dp
316 END DO
317 IF (maxval(abs(amat)) > 1.e-12) THEN
318 IF (iw > 0) WRITE (iw, '(A,G20.10)') " Orthogonality error ", maxval(abs(amat))
319 END IF
320 DEALLOCATE (amat)
321
322 ! Quickstep normalization
323 expzet = 0.25_dp*real(2*l + 3, dp)
324 prefac = sqrt(rootpi/2._dp**(l + 2)*dfac(2*l + 1))
325 DO i = 1, m
326 zeta = (2._dp*atom%basis%am(i, l))**expzet
327 qbasis(i, 1:n, l) = rbasis(i, 1:n, l)*prefac/zeta
328 END DO
329
330 END DO
331
332 ! check for condition numbers
333 IF (iw > 0) WRITE (iw, '(/,A)') " Condition Number of Valence Response Basis Sets"
336 DO ider = 0, nder
337 NULLIFY (basis_vrb)
338 ALLOCATE (basis_vrb)
339 NULLIFY (basis_vrb%am, basis_vrb%cm, basis_vrb%as, basis_vrb%ns, basis_vrb%bf, &
340 basis_vrb%dbf, basis_vrb%ddbf)
341 ! allocate and initialize the atomic grid
342 NULLIFY (basis_vrb%grid)
343 CALL allocate_grid_atom(basis_vrb%grid)
344 CALL create_grid_atom(basis_vrb%grid, ngp, 1, 1, 0, quadtype)
345 basis_vrb%grid%nr = ngp
346 !
347 basis_vrb%eps_eig = basis_ref%eps_eig
348 basis_vrb%geometrical = .false.
349 basis_vrb%basis_type = cgto_basis
350 basis_vrb%nprim = basis%nprim
351 basis_vrb%nbas = 0
352 DO l = 0, state%maxl_occ
353 basis_vrb%nbas(l) = state%maxn_occ(l) + ider
354 END DO
355 m = maxval(basis_vrb%nprim)
356 n = maxval(basis_vrb%nbas)
357 ALLOCATE (basis_vrb%am(m, 0:lmat))
358 basis_vrb%am = basis%am
359 ! contractions
360 ALLOCATE (basis_vrb%cm(m, n, 0:lmat))
361 DO l = 0, state%maxl_occ
362 m = basis_vrb%nprim(l)
363 n = basis_vrb%nbas(l)
364 basis_vrb%cm(1:m, 1:n, l) = rbasis(1:m, 1:n, l)
365 END DO
366
367 ! initialize basis function on a radial grid
368 nr = basis_vrb%grid%nr
369 m = maxval(basis_vrb%nbas)
370 ALLOCATE (basis_vrb%bf(nr, m, 0:lmat))
371 ALLOCATE (basis_vrb%dbf(nr, m, 0:lmat))
372 ALLOCATE (basis_vrb%ddbf(nr, m, 0:lmat))
373 basis_vrb%bf = 0._dp
374 basis_vrb%dbf = 0._dp
375 basis_vrb%ddbf = 0._dp
376 DO l = 0, lmat
377 DO i = 1, basis_vrb%nprim(l)
378 al = basis_vrb%am(i, l)
379 DO k = 1, nr
380 rk = basis_vrb%grid%rad(k)
381 ear = exp(-al*basis_vrb%grid%rad(k)**2)
382 DO j = 1, basis_vrb%nbas(l)
383 basis_vrb%bf(k, j, l) = basis_vrb%bf(k, j, l) + rk**l*ear*basis_vrb%cm(i, j, l)
384 basis_vrb%dbf(k, j, l) = basis_vrb%dbf(k, j, l) &
385 + (real(l, dp)*rk**(l - 1) - 2._dp*al*rk**(l + 1))*ear*basis_vrb%cm(i, j, l)
386 basis_vrb%ddbf(k, j, l) = basis_vrb%ddbf(k, j, l) + &
387 (real(l*(l - 1), dp)*rk**(l - 2) - 2._dp*al*real(2*l + 1, dp)*rk**(l) + &
388 4._dp*al*rk**(l + 2))*ear*basis_vrb%cm(i, j, l)
389 END DO
390 END DO
391 END DO
392 END DO
393
394 IF (iw > 0) THEN
395 CALL basis_label(abas, basis_vrb%nprim, basis_vrb%nbas)
396 WRITE (iw, '(A,A)') " Basis set ", trim(abas)
397 END IF
398 crad = 2.0_dp*ptable(atom%z)%covalent_radius*bohr
399 cradx = crad*1.00_dp
400 CALL atom_basis_condnum(basis_vrb, cradx, cnum)
401 IF (iw > 0) WRITE (iw, '(T5,A,F15.3,T50,A,F14.4)') " Lattice constant:", cradx, "Condition number:", cnum
402 cradx = crad*1.10_dp
403 CALL atom_basis_condnum(basis_vrb, cradx, cnum)
404 IF (iw > 0) WRITE (iw, '(T5,A,F15.3,T50,A,F14.4)') " Lattice constant:", cradx, "Condition number:", cnum
405 cradx = crad*1.20_dp
406 CALL atom_basis_condnum(basis_vrb, cradx, cnum)
407 IF (iw > 0) WRITE (iw, '(T5,A,F15.3,T50,A,F14.4)') " Lattice constant:", cradx, "Condition number:", cnum
408 vbasis(ider)%basis => basis_vrb
409 END DO
412
413 ! get density maximum
414 ALLOCATE (rho(basis%grid%nr))
415 CALL calculate_atom(atom, iw=0, noguess=.true.)
416 CALL atom_density(rho(:), atom%orbitals%pmat, atom%basis, maxl, typ="RHO")
417 n = sum(maxloc(rho(:)))
418 rmax = basis%grid%rad(n)
419 IF (rmax < 0.1_dp) rmax = 1.0_dp
420 DEALLOCATE (rho)
421
422 ! generate polarization sets
423 maxl = atom%state%maxl_occ
424 CALL section_vals_val_get(grb_section, "NUM_GTO_POLARIZATION", i_val=num_gto)
425 num_pol = num_gto
426 IF (num_gto > 0) THEN
427 IF (iw > 0) THEN
428 WRITE (iw, '(/,A)') " Polarization basis set "
429 END IF
430 ALLOCATE (pbasis(num_gto, num_gto, 0:7), alp(num_gto))
431 pbasis = 0.0_dp
432 ! optimize exponents
433 lval = maxl + 1
434 zval = sqrt(real(2*lval + 2, dp))*real(lval + 1, dp)/(2._dp*rmax)
435 aval = atom%basis%am(1, 0)
436 cval = 2.5_dp
437 rconf = atom%potential%scon
438 CALL atom_fit_pol(zval, rconf, lval, aval, cval, num_gto, iw, powell_section)
439 ! calculate contractions
440 DO i = 1, num_gto
441 alp(i) = aval*cval**(i - 1)
442 END DO
443 ALLOCATE (rho(num_gto))
444 DO l = maxl + 1, min(maxl + num_gto, 7)
445 zval = sqrt(real(2*l + 2, dp))*real(l + 1, dp)/(2._dp*rmax)
446 CALL hydrogenic(zval, rconf, l, alp, num_gto, rho, pbasis(:, :, l))
447 IF (iw > 0) WRITE (iw, '(T5,A,i5,T66,A,F10.4)') &
448 " Polarization basis set contraction for lval=", l, "zval=", zval
449 END DO
450 DEALLOCATE (rho)
451 END IF
452
453 ! generate valence expansion sets
454 maxl = atom%state%maxl_occ
455 CALL section_vals_val_get(grb_section, "NUM_GTO_EXTENDED", i_val=num_gto)
456 CALL section_vals_val_get(grb_section, "EXTENSION_BASIS", i_vals=num_bas)
457 next_bas(0:lmat) = 0
458 IF (num_bas(1) == -1) THEN
459 DO l = 0, maxl
460 next_bas(l) = maxl - l + 1
461 END DO
462 ELSE
463 n = min(SIZE(num_bas, 1), 4)
464 next_bas(0:n - 1) = num_bas(1:n)
465 END IF
466 next_prim = 0
467 DO l = 0, lmat
468 IF (next_bas(l) > 0) next_prim(l) = num_gto
469 END DO
470 IF (iw > 0) THEN
471 CALL basis_label(abas, next_prim, next_bas)
472 WRITE (iw, '(/,A,A)') " Extension basis set ", trim(abas)
473 END IF
474 n = maxval(next_prim)
475 m = maxval(next_bas)
476 ALLOCATE (ebasis(n, n, 0:lmat), ale(n))
477 basis_vrb => vbasis(0)%basis
478 amin = atom%basis%aval/atom%basis%cval**1.5_dp
479 DO i = 1, n
480 ale(i) = amin*atom%basis%cval**(i - 1)
481 END DO
482 ebasis = 0._dp
483 ALLOCATE (rho(n))
484 rconf = 2.0_dp*atom%potential%scon
485 DO l = 0, lmat
486 IF (next_bas(l) < 1) cycle
487 zval = sqrt(real(2*l + 2, dp))*real(l + 1, dp)/(2._dp*rmax)
488 CALL hydrogenic(zval, rconf, l, ale, n, rho, ebasis(:, :, l))
489 IF (iw > 0) WRITE (iw, '(T5,A,i5,T66,A,F10.4)') &
490 " Extension basis set contraction for lval=", l, "zval=", zval
491 END DO
492 DEALLOCATE (rho)
493 ! check for condition numbers
494 IF (iw > 0) WRITE (iw, '(/,A)') " Condition Number of Extended Basis Sets"
497 DO ider = 0, nder
498 NULLIFY (basis_vrb)
499 ALLOCATE (basis_vrb)
500 NULLIFY (basis_vrb%am, basis_vrb%cm, basis_vrb%as, basis_vrb%ns, basis_vrb%bf, &
501 basis_vrb%dbf, basis_vrb%ddbf)
502 ! allocate and initialize the atomic grid
503 NULLIFY (basis_vrb%grid)
504 CALL allocate_grid_atom(basis_vrb%grid)
505 CALL create_grid_atom(basis_vrb%grid, ngp, 1, 1, 0, quadtype)
506 basis_vrb%grid%nr = ngp
507 !
508 basis_vrb%eps_eig = basis_ref%eps_eig
509 basis_vrb%geometrical = .false.
510 basis_vrb%basis_type = cgto_basis
511 basis_vrb%nprim = basis%nprim + next_prim
512 basis_vrb%nbas = 0
513 DO l = 0, state%maxl_occ
514 basis_vrb%nbas(l) = state%maxn_occ(l) + ider + next_bas(l)
515 END DO
516 m = maxval(basis_vrb%nprim)
517 ALLOCATE (basis_vrb%am(m, 0:lmat))
518 ! exponents
519 m = SIZE(basis%am, 1)
520 basis_vrb%am(1:m, :) = basis%am(1:m, :)
521 n = SIZE(ale, 1)
522 DO l = 0, state%maxl_occ
523 basis_vrb%am(m + 1:m + n, l) = ale(1:n)
524 END DO
525 ! contractions
526 m = maxval(basis_vrb%nprim)
527 n = maxval(basis_vrb%nbas)
528 ALLOCATE (basis_vrb%cm(m, n, 0:lmat))
529 basis_vrb%cm = 0.0_dp
530 DO l = 0, state%maxl_occ
531 m = basis%nprim(l)
532 n = state%maxn_occ(l) + ider
533 basis_vrb%cm(1:m, 1:n, l) = rbasis(1:m, 1:n, l)
534 basis_vrb%cm(m + 1:m + next_prim(l), n + 1:n + next_bas(l), l) = ebasis(1:next_prim(l), 1:next_bas(l), l)
535 END DO
536
537 ! initialize basis function on a radial grid
538 nr = basis_vrb%grid%nr
539 m = maxval(basis_vrb%nbas)
540 ALLOCATE (basis_vrb%bf(nr, m, 0:lmat))
541 ALLOCATE (basis_vrb%dbf(nr, m, 0:lmat))
542 ALLOCATE (basis_vrb%ddbf(nr, m, 0:lmat))
543 basis_vrb%bf = 0._dp
544 basis_vrb%dbf = 0._dp
545 basis_vrb%ddbf = 0._dp
546 DO l = 0, lmat
547 DO i = 1, basis_vrb%nprim(l)
548 al = basis_vrb%am(i, l)
549 DO k = 1, nr
550 rk = basis_vrb%grid%rad(k)
551 ear = exp(-al*basis_vrb%grid%rad(k)**2)
552 DO j = 1, basis_vrb%nbas(l)
553 basis_vrb%bf(k, j, l) = basis_vrb%bf(k, j, l) + rk**l*ear*basis_vrb%cm(i, j, l)
554 basis_vrb%dbf(k, j, l) = basis_vrb%dbf(k, j, l) &
555 + (real(l, dp)*rk**(l - 1) - 2._dp*al*rk**(l + 1))*ear*basis_vrb%cm(i, j, l)
556 basis_vrb%ddbf(k, j, l) = basis_vrb%ddbf(k, j, l) + &
557 (real(l*(l - 1), dp)*rk**(l - 2) - 2._dp*al*real(2*l + 1, dp)*rk**(l) + &
558 4._dp*al*rk**(l + 2))*ear*basis_vrb%cm(i, j, l)
559 END DO
560 END DO
561 END DO
562 END DO
563
564 IF (iw > 0) THEN
565 CALL basis_label(abas, basis_vrb%nprim, basis_vrb%nbas)
566 WRITE (iw, '(A,A)') " Basis set ", trim(abas)
567 END IF
568 crad = 2.0_dp*ptable(atom%z)%covalent_radius*bohr
569 cradx = crad*1.00_dp
570 CALL atom_basis_condnum(basis_vrb, cradx, cnum)
571 IF (iw > 0) WRITE (iw, '(T5,A,F15.3,T50,A,F14.4)') " Lattice constant:", cradx, "Condition number:", cnum
572 cradx = crad*1.10_dp
573 CALL atom_basis_condnum(basis_vrb, cradx, cnum)
574 IF (iw > 0) WRITE (iw, '(T5,A,F15.3,T50,A,F14.4)') " Lattice constant:", cradx, "Condition number:", cnum
575 cradx = crad*1.20_dp
576 CALL atom_basis_condnum(basis_vrb, cradx, cnum)
577 IF (iw > 0) WRITE (iw, '(T5,A,F15.3,T50,A,F14.4)') " Lattice constant:", cradx, "Condition number:", cnum
578 vbasis(nder + 1 + ider)%basis => basis_vrb
579 END DO
582
583 ! Tests for energy
584 energy_ref = atom_ref%energy%etot
585 IF (iw > 0) WRITE (iw, '(/,A,A)') " Basis set tests "
586 IF (iw > 0) WRITE (iw, '(T10,A,T59,F22.9)') " Reference Energy [a.u.] ", energy_ref
587 DO ider = 0, 2*nder + 1
588 ! generate an atom type
589 NULLIFY (atom_test)
590 CALL create_atom_type(atom_test)
591 CALL copy_atom_basics(atom_ref, atom_test, state=.true., potential=.true., &
592 optimization=.true., xc=.true.)
593 basis_grb => vbasis(ider)%basis
594 NULLIFY (orbitals)
595 mo = maxval(atom_test%state%maxn_calc)
596 mb = maxval(basis_grb%nbas)
597 CALL create_atom_orbs(orbitals, mb, mo)
598 CALL set_atom(atom_test, orbitals=orbitals, basis=basis_grb)
599 ! calculate integrals
600 ALLOCATE (atint)
601 CALL atom_int_setup(atint, basis_grb, potential=atom_test%potential, eri_coulomb=.false., eri_exchange=.false.)
602 CALL atom_ppint_setup(atint, basis_grb, potential=atom_test%potential)
603 IF (atom_test%pp_calc) THEN
604 NULLIFY (atint%tzora, atint%hdkh)
605 ELSE
606 ! relativistic correction terms
607 CALL atom_relint_setup(atint, basis_grb, atom_test%relativistic, zcore=real(atom_test%z, dp))
608 END IF
609 CALL set_atom(atom_test, integrals=atint)
610 !
611 CALL calculate_atom(atom_test, iw=0)
612 IF (ider <= nder) THEN
613 energy_vb(ider) = atom_test%energy%etot
614 IF (iw > 0) WRITE (iw, '(T10,A,i1,A,T40,F13.9,T59,F22.9)') " GRB (VB)", ider, " Energy [a.u.] ", &
615 energy_ref - energy_vb(ider), energy_vb(ider)
616 ELSE
617 i = ider - nder - 1
618 energy_ex(i) = atom_test%energy%etot
619 IF (iw > 0) WRITE (iw, '(T10,A,i1,A,T40,F13.9,T59,F22.9)') " GRB (EX)", i, " Energy [a.u.] ", &
620 energy_ref - energy_ex(i), energy_ex(i)
621 END IF
622 CALL atom_int_release(atint)
623 CALL atom_ppint_release(atint)
624 CALL atom_relint_release(atint)
625 DEALLOCATE (atom_test%state, atom_test%potential, atint)
626 CALL release_atom_type(atom_test)
627 END DO
628
629 ! Quickstep normalization polarization basis
630 DO l = 0, 7
631 expzet = 0.25_dp*real(2*l + 3, dp)
632 prefac = sqrt(rootpi/2._dp**(l + 2)*dfac(2*l + 1))
633 DO i = 1, num_pol
634 zeta = (2._dp*alp(i))**expzet
635 pbasis(i, 1:num_pol, l) = pbasis(i, 1:num_pol, l)*prefac/zeta
636 END DO
637 END DO
638 ! Quickstep normalization extended basis
639 DO l = 0, lmat
640 expzet = 0.25_dp*real(2*l + 3, dp)
641 prefac = sqrt(rootpi/2._dp**(l + 2)*dfac(2*l + 1))
642 DO i = 1, next_prim(l)
643 zeta = (2._dp*ale(i))**expzet
644 ebasis(i, 1:next_bas(l), l) = ebasis(i, 1:next_bas(l), l)*prefac/zeta
645 END DO
646 END DO
647
648 ! Print basis sets
649 CALL section_vals_val_get(grb_section, "NAME_BODY", c_val=basname)
650 CALL open_file(file_name="GRB_BASIS", file_status="UNKNOWN", file_action="WRITE", unit_number=iunit)
651 ! header info
652 headline = ""
653 headline(1) = "#"
654 headline(2) = "# Generated with CP2K Atom Code"
655 headline(3) = "#"
656 CALL grb_print_basis(header=headline, iunit=iunit)
657 ! valence basis
658 basline(1) = ""
659 WRITE (basline(1), "(T2,A)") adjustl(ptable(atom_ref%z)%symbol)
660 DO ider = 0, nder
661 basline(1) = ""
662 WRITE (basline(1), "(T2,A,T5,A,I1)") adjustl(ptable(atom_ref%z)%symbol), trim(adjustl(basname))//"-VAL-", ider
663 CALL grb_print_basis(header=basline, nprim=vbasis(ider)%basis%nprim(0), nbas=vbasis(ider)%basis%nbas, &
664 al=vbasis(ider)%basis%am(:, 0), gcc=qbasis, iunit=iunit)
665 END DO
666 ! polarization basis
667 maxl = atom_ref%state%maxl_occ
668 DO l = maxl + 1, min(maxl + num_pol, 7)
669 nbas = 0
670 DO i = maxl + 1, l
671 nbas(i) = l - i + 1
672 END DO
673 i = l - maxl
674 basline(1) = ""
675 WRITE (basline(1), "(T2,A,T5,A,I1)") adjustl(ptable(atom_ref%z)%symbol), trim(adjustl(basname))//"-POL-", i
676 CALL grb_print_basis(header=basline, nprim=num_pol, nbas=nbas, al=alp, gcc=pbasis, iunit=iunit)
677 END DO
678 ! extension set
679 IF (sum(next_bas) > 0) THEN
680 basline(1) = ""
681 WRITE (basline(1), "(T2,A,T5,A)") adjustl(ptable(atom_ref%z)%symbol), trim(adjustl(basname))//"-EXT"
682 CALL grb_print_basis(header=basline, nprim=next_prim(0), nbas=next_bas, al=ale, gcc=ebasis, iunit=iunit)
683 END IF
684 !
685 CALL close_file(unit_number=iunit)
686
687 ! clean up
688 IF (ALLOCATED(pbasis)) DEALLOCATE (pbasis)
689 IF (ALLOCATED(alp)) DEALLOCATE (alp)
690 IF (ALLOCATED(ebasis)) DEALLOCATE (ebasis)
691 DEALLOCATE (wfn, rbasis, qbasis, ale)
692
693 DO ider = 0, 10
694 IF (ASSOCIATED(vbasis(ider)%basis)) THEN
695 CALL release_atom_basis(vbasis(ider)%basis)
696 DEALLOCATE (vbasis(ider)%basis)
697 END IF
698 END DO
699
700 CALL atom_int_release(atom%integrals)
701 CALL atom_ppint_release(atom%integrals)
702 CALL atom_relint_release(atom%integrals)
703 CALL release_atom_basis(basis)
704 DEALLOCATE (atom%potential, atom%state, atom%integrals, basis)
706
707 IF (iw > 0) WRITE (iw, '(" ",79("*"))')
708
709 END SUBROUTINE atom_grb_construction
710
711! **************************************************************************************************
712!> \brief Print geometrical response basis set.
713!> \param header banner to print on top of the basis set
714!> \param nprim number of primitive exponents
715!> \param nbas number of basis functions for the given angular momentum
716!> \param al list of the primitive exponents
717!> \param gcc array of contraction coefficients of size
718!> (index-of-the-primitive-exponent, index-of-the-contraction-set, angular-momentum)
719!> \param iunit output file unit
720!> \par History
721!> * 11.2016 created [Juerg Hutter]
722! **************************************************************************************************
723 SUBROUTINE grb_print_basis(header, nprim, nbas, al, gcc, iunit)
724 CHARACTER(len=*), DIMENSION(:), INTENT(IN), &
725 OPTIONAL :: header
726 INTEGER, INTENT(IN), OPTIONAL :: nprim
727 INTEGER, DIMENSION(0:), INTENT(IN), OPTIONAL :: nbas
728 REAL(kind=dp), DIMENSION(:), INTENT(IN), OPTIONAL :: al
729 REAL(kind=dp), DIMENSION(:, :, 0:), INTENT(IN), &
730 OPTIONAL :: gcc
731 INTEGER, INTENT(IN) :: iunit
732
733 INTEGER :: i, j, l, lmax, lmin, nval
734
735 IF (PRESENT(header)) THEN
736 DO i = 1, SIZE(header, 1)
737 IF (header(i) .NE. "") THEN
738 WRITE (iunit, "(A)") trim(header(i))
739 END IF
740 END DO
741 END IF
742
743 IF (PRESENT(nprim)) THEN
744 IF (nprim > 0) THEN
745 cpassert(PRESENT(nbas))
746 cpassert(PRESENT(al))
747 cpassert(PRESENT(gcc))
748
749 DO i = lbound(nbas, 1), ubound(nbas, 1)
750 IF (nbas(i) > 0) THEN
751 lmin = i
752 EXIT
753 END IF
754 END DO
755 DO i = ubound(nbas, 1), lbound(nbas, 1), -1
756 IF (nbas(i) > 0) THEN
757 lmax = i
758 EXIT
759 END IF
760 END DO
761
762 nval = lmax
763 WRITE (iunit, *) " 1"
764 WRITE (iunit, "(40I3)") nval, lmin, lmax, nprim, (nbas(l), l=lmin, lmax)
765 DO i = nprim, 1, -1
766 WRITE (iunit, "(G20.12)", advance="no") al(i)
767 DO l = lmin, lmax
768 DO j = 1, nbas(l)
769 WRITE (iunit, "(F16.10)", advance="no") gcc(i, j, l)
770 END DO
771 END DO
772 WRITE (iunit, *)
773 END DO
774 WRITE (iunit, *)
775 END IF
776 END IF
777
778 END SUBROUTINE grb_print_basis
779
780! **************************************************************************************************
781!> \brief Compose the basis set label:
782!> (np(0)'s'np(1)'p'...) -> [nb(0)'s'nb(1)'p'...] .
783!> \param label basis set label
784!> \param np number of primitive basis functions per angular momentum
785!> \param nb number of contracted basis functions per angular momentum
786!> \par History
787!> * 11.2016 created [Juerg Hutter]
788! **************************************************************************************************
789 SUBROUTINE basis_label(label, np, nb)
790 CHARACTER(len=*), INTENT(out) :: label
791 INTEGER, DIMENSION(0:), INTENT(in) :: np, nb
792
793 INTEGER :: i, l, lmax
794 CHARACTER(len=1), DIMENSION(0:7), PARAMETER :: &
795 lq = (/"s", "p", "d", "f", "g", "h", "i", "k"/)
796
797 label = ""
798 lmax = min(ubound(np, 1), ubound(nb, 1), 7)
799 i = 1
800 label(i:i) = "("
801 DO l = 0, lmax
802 IF (np(l) > 0) THEN
803 i = i + 1
804 IF (np(l) > 9) THEN
805 WRITE (label(i:i + 1), "(I2)") np(l)
806 i = i + 2
807 ELSE
808 WRITE (label(i:i), "(I1)") np(l)
809 i = i + 1
810 END IF
811 label(i:i) = lq(l)
812 END IF
813 END DO
814 i = i + 1
815 label(i:i + 6) = ") --> ["
816 i = i + 6
817 DO l = 0, lmax
818 IF (nb(l) > 0) THEN
819 i = i + 1
820 IF (nb(l) > 9) THEN
821 WRITE (label(i:i + 1), "(I2)") nb(l)
822 i = i + 2
823 ELSE
824 WRITE (label(i:i), "(I1)") nb(l)
825 i = i + 1
826 END IF
827 label(i:i) = lq(l)
828 END IF
829 END DO
830 i = i + 1
831 label(i:i) = "]"
832
833 END SUBROUTINE basis_label
834
835! **************************************************************************************************
836!> \brief Compute the total energy for the given atomic kind and basis set.
837!> \param atom information about the atomic kind
838!> \param basis basis set to fit
839!> \param afun (output) atomic total energy
840!> \param iw output file unit
841!> \par History
842!> * 11.2016 created [Juerg Hutter]
843! **************************************************************************************************
844 SUBROUTINE grb_fit(atom, basis, afun, iw)
845 TYPE(atom_type), POINTER :: atom
846 TYPE(atom_basis_type), POINTER :: basis
847 REAL(dp), INTENT(OUT) :: afun
848 INTEGER, INTENT(IN) :: iw
849
850 INTEGER :: do_eric, do_erie, reltyp, zval
851 LOGICAL :: eri_c, eri_e
852 TYPE(atom_integrals), POINTER :: atint
853 TYPE(atom_potential_type), POINTER :: pot
854
855 ALLOCATE (atint)
856 ! calculate integrals
857 NULLIFY (pot)
858 eri_c = .false.
859 eri_e = .false.
860 pot => atom%potential
861 zval = atom%z
862 reltyp = atom%relativistic
863 do_eric = atom%coulomb_integral_type
864 do_erie = atom%exchange_integral_type
865 IF (do_eric == do_analytic) eri_c = .true.
866 IF (do_erie == do_analytic) eri_e = .true.
867 ! general integrals
868 CALL atom_int_setup(atint, basis, potential=pot, eri_coulomb=eri_c, eri_exchange=eri_e)
869 ! potential
870 CALL atom_ppint_setup(atint, basis, potential=pot)
871 IF (atom%pp_calc) THEN
872 NULLIFY (atint%tzora, atint%hdkh)
873 ELSE
874 ! relativistic correction terms
875 CALL atom_relint_setup(atint, basis, reltyp, zcore=real(zval, dp))
876 END IF
877 CALL set_atom(atom, basis=basis)
878 CALL set_atom(atom, integrals=atint)
879 CALL calculate_atom(atom, iw)
880 afun = atom%energy%etot
881 CALL atom_int_release(atint)
882 CALL atom_ppint_release(atint)
883 CALL atom_relint_release(atint)
884 DEALLOCATE (atint)
885 END SUBROUTINE grb_fit
886
887! **************************************************************************************************
888!> \brief Copy basic information about the atomic kind.
889!> \param atom_ref atom to copy
890!> \param atom new atom to create
891!> \param state also copy electronic state and occupation numbers
892!> \param potential also copy pseudo-potential
893!> \param optimization also copy optimization procedure
894!> \param xc also copy the XC input section
895!> \par History
896!> * 11.2016 created [Juerg Hutter]
897! **************************************************************************************************
898 SUBROUTINE copy_atom_basics(atom_ref, atom, state, potential, optimization, xc)
899 TYPE(atom_type), POINTER :: atom_ref, atom
900 LOGICAL, INTENT(IN), OPTIONAL :: state, potential, optimization, xc
901
902 atom%z = atom_ref%z
903 atom%zcore = atom_ref%zcore
904 atom%pp_calc = atom_ref%pp_calc
905 atom%method_type = atom_ref%method_type
906 atom%relativistic = atom_ref%relativistic
907 atom%coulomb_integral_type = atom_ref%coulomb_integral_type
908 atom%exchange_integral_type = atom_ref%exchange_integral_type
909
910 NULLIFY (atom%potential, atom%state, atom%xc_section)
911 NULLIFY (atom%basis, atom%integrals, atom%orbitals, atom%fmat)
912
913 IF (PRESENT(state)) THEN
914 IF (state) THEN
915 ALLOCATE (atom%state)
916 atom%state = atom_ref%state
917 END IF
918 END IF
919
920 IF (PRESENT(potential)) THEN
921 IF (potential) THEN
922 ALLOCATE (atom%potential)
923 atom%potential = atom_ref%potential
924 END IF
925 END IF
926
927 IF (PRESENT(optimization)) THEN
928 IF (optimization) THEN
929 atom%optimization = atom_ref%optimization
930 END IF
931 END IF
932
933 IF (PRESENT(xc)) THEN
934 IF (xc) THEN
935 atom%xc_section => atom_ref%xc_section
936 END IF
937 END IF
938
939 END SUBROUTINE copy_atom_basics
940
941! **************************************************************************************************
942!> \brief Optimise a geometrical response basis set.
943!> \param atom information about the atomic kind
944!> \param basis basis set to fit
945!> \param iunit output file unit
946!> \param powell_section POWELL input section
947!> \par History
948!> * 11.2016 created [Juerg Hutter]
949! **************************************************************************************************
950 SUBROUTINE atom_fit_grb(atom, basis, iunit, powell_section)
951 TYPE(atom_type), POINTER :: atom
952 TYPE(atom_basis_type), POINTER :: basis
953 INTEGER, INTENT(IN) :: iunit
954 TYPE(section_vals_type), POINTER :: powell_section
955
956 INTEGER :: i, k, l, ll, n10, nr
957 REAL(kind=dp) :: al, cnum, crad, cradx, ear, fopt, rk
958 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: x
959 TYPE(opt_state_type) :: ostate
960
961 cpassert(basis%geometrical)
962
963 CALL section_vals_val_get(powell_section, "ACCURACY", r_val=ostate%rhoend)
964 CALL section_vals_val_get(powell_section, "STEP_SIZE", r_val=ostate%rhobeg)
965 CALL section_vals_val_get(powell_section, "MAX_FUN", i_val=ostate%maxfun)
966
967 ostate%nvar = 2
968 ALLOCATE (x(2))
969 x(1) = sqrt(basis%aval)
970 x(2) = sqrt(basis%cval)
971
972 ostate%nf = 0
973 ostate%iprint = 1
974 ostate%unit = iunit
975
976 ostate%state = 0
977 IF (iunit > 0) THEN
978 WRITE (iunit, '(/," POWELL| Start optimization procedure")')
979 WRITE (iunit, '(" POWELL| Total number of parameters in optimization",T71,I10)') ostate%nvar
980 END IF
981 n10 = max(ostate%maxfun/100, 1)
982
983 fopt = huge(0._dp)
984
985 DO
986
987 IF (ostate%state == 2) THEN
988 basis%am = 0._dp
989 DO l = 0, lmat
990 DO i = 1, basis%nbas(l)
991 ll = i - 1 + basis%start(l)
992 basis%am(i, l) = x(1)*x(1)*(x(2)*x(2))**(ll)
993 END DO
994 END DO
995 basis%aval = x(1)*x(1)
996 basis%cval = x(2)*x(2)
997 basis%bf = 0._dp
998 basis%dbf = 0._dp
999 basis%ddbf = 0._dp
1000 nr = basis%grid%nr
1001 DO l = 0, lmat
1002 DO i = 1, basis%nbas(l)
1003 al = basis%am(i, l)
1004 DO k = 1, nr
1005 rk = basis%grid%rad(k)
1006 ear = exp(-al*basis%grid%rad(k)**2)
1007 basis%bf(k, i, l) = rk**l*ear
1008 basis%dbf(k, i, l) = (real(l, dp)*rk**(l - 1) - 2._dp*al*rk**(l + 1))*ear
1009 basis%ddbf(k, i, l) = (real(l*(l - 1), dp)*rk**(l - 2) - &
1010 2._dp*al*real(2*l + 1, dp)*rk**(l) + 4._dp*al*rk**(l + 2))*ear
1011 END DO
1012 END DO
1013 END DO
1014 CALL grb_fit(atom, basis, ostate%f, 0)
1015 fopt = min(fopt, ostate%f)
1016 END IF
1017
1018 IF (ostate%state == -1) EXIT
1019
1020 CALL powell_optimize(ostate%nvar, x, ostate)
1021
1022 IF (ostate%nf == 2 .AND. iunit > 0) THEN
1023 WRITE (iunit, '(" POWELL| Initial value of function",T61,F20.10)') ostate%f
1024 END IF
1025 IF (mod(ostate%nf, n10) == 0 .AND. iunit > 0) THEN
1026 WRITE (iunit, '(" POWELL| Reached",i4,"% of maximal function calls",T61,F20.10)') &
1027 int(real(ostate%nf, dp)/real(ostate%maxfun, dp)*100._dp), fopt
1028 END IF
1029
1030 END DO
1031
1032 ostate%state = 8
1033 CALL powell_optimize(ostate%nvar, x, ostate)
1034
1035 IF (iunit > 0) THEN
1036 WRITE (iunit, '(" POWELL| Number of function evaluations",T71,I10)') ostate%nf
1037 WRITE (iunit, '(" POWELL| Final value of function",T61,F20.10)') ostate%fopt
1038 END IF
1039 ! x->basis
1040 basis%am = 0._dp
1041 DO l = 0, lmat
1042 DO i = 1, basis%nbas(l)
1043 ll = i - 1 + basis%start(l)
1044 basis%am(i, l) = x(1)*x(1)*(x(2)*x(2))**(ll)
1045 END DO
1046 END DO
1047 basis%aval = x(1)*x(1)
1048 basis%cval = x(2)*x(2)
1049 basis%bf = 0._dp
1050 basis%dbf = 0._dp
1051 basis%ddbf = 0._dp
1052 nr = basis%grid%nr
1053 DO l = 0, lmat
1054 DO i = 1, basis%nbas(l)
1055 al = basis%am(i, l)
1056 DO k = 1, nr
1057 rk = basis%grid%rad(k)
1058 ear = exp(-al*basis%grid%rad(k)**2)
1059 basis%bf(k, i, l) = rk**l*ear
1060 basis%dbf(k, i, l) = (real(l, dp)*rk**(l - 1) - 2._dp*al*rk**(l + 1))*ear
1061 basis%ddbf(k, i, l) = (real(l*(l - 1), dp)*rk**(l - 2) - &
1062 2._dp*al*real(2*l + 1, dp)*rk**(l) + 4._dp*al*rk**(l + 2))*ear
1063 END DO
1064 END DO
1065 END DO
1066
1067 DEALLOCATE (x)
1068
1069 ! final result
1070 IF (iunit > 0) THEN
1071 WRITE (iunit, '(/,A)') " Optimized Geometrical GTO basis set"
1072 WRITE (iunit, '(A,F15.8,T41,A,F15.8)') " Initial exponent: ", basis%aval, &
1073 " Proportionality factor: ", basis%cval
1074 DO l = 0, lmat
1075 WRITE (iunit, '(T41,A,I2,T76,I5)') " Number of exponents for l=", l, basis%nbas(l)
1076 END DO
1077 END IF
1078
1079 IF (iunit > 0) WRITE (iunit, '(/,A)') " Condition number of uncontracted basis set"
1080 crad = 2.0_dp*ptable(atom%z)%covalent_radius*bohr
1083 cradx = crad*1.00_dp
1084 CALL atom_basis_condnum(basis, cradx, cnum)
1085 IF (iunit > 0) WRITE (iunit, '(T5,A,F15.3,T50,A,F14.4)') " Lattice constant:", cradx, "Condition number:", cnum
1086 cradx = crad*1.10_dp
1087 CALL atom_basis_condnum(basis, cradx, cnum)
1088 IF (iunit > 0) WRITE (iunit, '(T5,A,F15.3,T50,A,F14.4)') " Lattice constant:", cradx, "Condition number:", cnum
1089 cradx = crad*1.20_dp
1090 CALL atom_basis_condnum(basis, cradx, cnum)
1091 IF (iunit > 0) WRITE (iunit, '(T5,A,F15.3,T50,A,F14.4)') " Lattice constant:", cradx, "Condition number:", cnum
1094
1095 END SUBROUTINE atom_fit_grb
1096
1097! **************************************************************************************************
1098!> \brief Optimize 'aval' and 'cval' parameters which define the geometrical response basis set.
1099!> \param zval nuclear charge
1100!> \param rconf confinement radius
1101!> \param lval angular momentum
1102!> \param aval (input/output) exponent of the first Gaussian basis function in the series
1103!> \param cval (input/output) factor of geometrical series
1104!> \param nbas number of basis functions
1105!> \param iunit output file unit
1106!> \param powell_section POWELL input section
1107!> \par History
1108!> * 11.2016 created [Juerg Hutter]
1109! **************************************************************************************************
1110 SUBROUTINE atom_fit_pol(zval, rconf, lval, aval, cval, nbas, iunit, powell_section)
1111 REAL(kind=dp), INTENT(IN) :: zval, rconf
1112 INTEGER, INTENT(IN) :: lval
1113 REAL(kind=dp), INTENT(INOUT) :: aval, cval
1114 INTEGER, INTENT(IN) :: nbas, iunit
1115 TYPE(section_vals_type), POINTER :: powell_section
1116
1117 INTEGER :: i, n10
1118 REAL(kind=dp) :: fopt, x(2)
1119 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: am, ener
1120 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :) :: orb
1121 TYPE(opt_state_type) :: ostate
1122
1123 ALLOCATE (am(nbas), ener(nbas), orb(nbas, nbas))
1124
1125 CALL section_vals_val_get(powell_section, "ACCURACY", r_val=ostate%rhoend)
1126 CALL section_vals_val_get(powell_section, "STEP_SIZE", r_val=ostate%rhobeg)
1127 CALL section_vals_val_get(powell_section, "MAX_FUN", i_val=ostate%maxfun)
1128
1129 ostate%nvar = 2
1130 x(1) = sqrt(aval)
1131 x(2) = sqrt(cval)
1132
1133 ostate%nf = 0
1134 ostate%iprint = 1
1135 ostate%unit = iunit
1136
1137 ostate%state = 0
1138 IF (iunit > 0) THEN
1139 WRITE (iunit, '(/," POWELL| Start optimization procedure")')
1140 WRITE (iunit, '(" POWELL| Total number of parameters in optimization",T71,I10)') ostate%nvar
1141 END IF
1142 n10 = max(ostate%maxfun/100, 1)
1143
1144 fopt = huge(0._dp)
1145
1146 DO
1147
1148 IF (ostate%state == 2) THEN
1149 aval = x(1)*x(1)
1150 cval = x(2)*x(2)
1151 DO i = 1, nbas
1152 am(i) = aval*cval**(i - 1)
1153 END DO
1154 CALL hydrogenic(zval, rconf, lval, am, nbas, ener, orb)
1155 ostate%f = ener(1)
1156 fopt = min(fopt, ostate%f)
1157 END IF
1158
1159 IF (ostate%state == -1) EXIT
1160
1161 CALL powell_optimize(ostate%nvar, x, ostate)
1162
1163 IF (ostate%nf == 2 .AND. iunit > 0) THEN
1164 WRITE (iunit, '(" POWELL| Initial value of function",T61,F20.10)') ostate%f
1165 END IF
1166 IF (mod(ostate%nf, n10) == 0 .AND. iunit > 0) THEN
1167 WRITE (iunit, '(" POWELL| Reached",i4,"% of maximal function calls",T61,F20.10)') &
1168 int(real(ostate%nf, dp)/real(ostate%maxfun, dp)*100._dp), fopt
1169 END IF
1170
1171 END DO
1172
1173 ostate%state = 8
1174 CALL powell_optimize(ostate%nvar, x, ostate)
1175
1176 IF (iunit > 0) THEN
1177 WRITE (iunit, '(" POWELL| Number of function evaluations",T71,I10)') ostate%nf
1178 WRITE (iunit, '(" POWELL| Final value of function",T61,F20.10)') ostate%fopt
1179 END IF
1180 ! x->basis
1181 aval = x(1)*x(1)
1182 cval = x(2)*x(2)
1183
1184 ! final result
1185 IF (iunit > 0) THEN
1186 WRITE (iunit, '(/,A,T51,A,T76,I5)') " Optimized Polarization basis set", &
1187 " Number of exponents:", nbas
1188 WRITE (iunit, '(A,F15.8,T41,A,F15.8)') " Initial exponent: ", aval, &
1189 " Proportionality factor: ", cval
1190 END IF
1191
1192 DEALLOCATE (am, ener, orb)
1193
1194 END SUBROUTINE atom_fit_pol
1195
1196! **************************************************************************************************
1197!> \brief Calculate orbitals of a hydrogen-like atom.
1198!> \param zval nuclear charge
1199!> \param rconf confinement radius
1200!> \param lval angular momentum
1201!> \param am list of basis functions' exponents
1202!> \param nbas number of basis functions
1203!> \param ener orbital energies
1204!> \param orb expansion coefficients of atomic wavefunctions
1205!> \par History
1206!> * 11.2016 created [Juerg Hutter]
1207! **************************************************************************************************
1208 SUBROUTINE hydrogenic(zval, rconf, lval, am, nbas, ener, orb)
1209 REAL(kind=dp), INTENT(IN) :: zval, rconf
1210 INTEGER, INTENT(IN) :: lval
1211 REAL(kind=dp), DIMENSION(:), INTENT(IN) :: am
1212 INTEGER, INTENT(IN) :: nbas
1213 REAL(kind=dp), DIMENSION(:), INTENT(OUT) :: ener
1214 REAL(kind=dp), DIMENSION(:, :), INTENT(OUT) :: orb
1215
1216 INTEGER :: info, k, lwork, n
1217 REAL(kind=dp) :: cf
1218 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: w, work
1219 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :) :: confmat, hmat, potmat, smat, tmat
1220
1221 n = nbas
1222 ALLOCATE (smat(n, n), tmat(n, n), potmat(n, n), confmat(n, n), hmat(n, n))
1223 ! calclulate overlap matrix
1224 CALL sg_overlap(smat(1:n, 1:n), lval, am(1:n), am(1:n))
1225 ! calclulate kinetic energy matrix
1226 CALL sg_kinetic(tmat(1:n, 1:n), lval, am(1:n), am(1:n))
1227 ! calclulate core potential matrix
1228 CALL sg_nuclear(potmat(1:n, 1:n), lval, am(1:n), am(1:n))
1229 ! calclulate confinement potential matrix
1230 cf = 0.1_dp
1231 k = 10
1232 CALL sg_conf(confmat, rconf, k, lval, am(1:n), am(1:n))
1233 ! Hamiltionian
1234 hmat(1:n, 1:n) = tmat(1:n, 1:n) - zval*potmat(1:n, 1:n) + cf*confmat(1:n, 1:n)
1235 ! solve
1236 lwork = 100*n
1237 ALLOCATE (w(n), work(lwork))
1238 CALL dsygv(1, "V", "U", n, hmat, n, smat, n, w, work, lwork, info)
1239 cpassert(info == 0)
1240 orb(1:n, 1:n) = hmat(1:n, 1:n)
1241 ener(1:n) = w(1:n)
1242 DEALLOCATE (w, work)
1243 DEALLOCATE (smat, tmat, potmat, confmat, hmat)
1244
1245 END SUBROUTINE hydrogenic
1246
1247END MODULE atom_grb
subroutine, public sg_nuclear(umat, l, pa, pb)
...
subroutine, public sg_kinetic(kmat, l, pa, pb)
...
subroutine, public sg_conf(gmat, rc, k, l, pa, pb)
...
subroutine, public sg_overlap(smat, l, pa, pb)
...
subroutine, public calculate_atom(atom, iw, noguess, converged)
General routine to perform electronic structure atomic calculations.
subroutine, public atom_grb_construction(atom_info, atom_section, iw)
Construct geometrical response basis set.
Definition atom_grb.F:77
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).
Define the atom type and its sub types.
Definition atom_types.F:15
subroutine, public create_atom_type(atom)
...
Definition atom_types.F:944
integer, parameter, public cgto_basis
Definition atom_types.F:69
integer, parameter, public gto_basis
Definition atom_types.F:69
subroutine, public release_atom_type(atom)
...
Definition atom_types.F:968
integer, parameter, public lmat
Definition atom_types.F:67
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:910
subroutine, public create_atom_orbs(orbs, mbas, mo)
...
Some basic routines for atomic calculations.
Definition atom_utils.F:15
subroutine, public atom_density(density, pmat, basis, maxl, typ, rr)
Map the electron density on an atomic radial grid.
Definition atom_utils.F:366
subroutine, public atom_basis_condnum(basis, rad, cnum)
Calculate the condition number of the given atomic basis set.
Definition atom.F:9
Utility routines to open and close files. Tracking of preconnections.
Definition cp_files.F:16
subroutine, public open_file(file_name, file_status, file_form, file_action, file_position, file_pad, unit_number, debug, skip_get_unit_number, file_access)
Opens the requested file using a free unit number.
Definition cp_files.F:308
subroutine, public close_file(unit_number, file_status, keep_preconnection)
Close an open file given by its logical unit number. Optionally, keep the file and unit preconnected.
Definition cp_files.F:119
collects all constants needed in input so that they can be used without circular dependencies
integer, parameter, public do_rhf_atom
integer, parameter, public do_rks_atom
integer, parameter, public do_analytic
integer, parameter, public do_uhf_atom
integer, parameter, public do_uks_atom
integer, parameter, public barrier_conf
integer, parameter, public do_rohf_atom
objects that represent the structure of input sections and the data contained in an input section
recursive type(section_vals_type) function, pointer, public section_vals_get_subs_vals(section_vals, subsection_name, i_rep_section, can_return_null)
returns the values of the requested subsection
subroutine, public section_vals_val_get(section_vals, keyword_name, i_rep_section, i_rep_val, n_rep_val, val, l_val, i_val, r_val, c_val, l_vals, i_vals, r_vals, c_vals, explicit)
returns the requested value
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
integer, parameter, public default_string_length
Definition kinds.F:57
Definition of mathematical constants and functions.
real(kind=dp), dimension(-1:2 *maxfac+1), parameter, public dfac
real(kind=dp), parameter, public rootpi
Provides Cartesian and spherical orbital pointers and indices.
subroutine, public init_orbital_pointers(maxl)
Initialize or update the orbital pointers.
subroutine, public deallocate_orbital_pointers()
Deallocate the orbital pointers.
Calculation of the spherical harmonics and the corresponding orbital transformation matrices.
subroutine, public init_spherical_harmonics(maxl, output_unit)
Initialize or update the orbital transformation matrices.
subroutine, public deallocate_spherical_harmonics()
Deallocate the orbital transformation matrices.
Periodic Table related data definitions.
type(atom), dimension(0:nelem), public ptable
Definition of physical constants:
Definition physcon.F:68
real(kind=dp), parameter, public bohr
Definition physcon.F:147
Definition powell.F:9
subroutine, public powell_optimize(n, x, optstate)
...
Definition powell.F:55
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)
...
Exchange and Correlation functional calculations.
Definition xc.F:17
Provides all information about a basis set.
Definition atom_types.F:78
Holds atomic orbitals and energies.
Definition atom_types.F:234
Provides all information on states and occupation.
Definition atom_types.F:195
Provides all information about an atomic kind.
Definition atom_types.F:290