50#include "./base/base_uses.f90"
56 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'atom_fit'
61 REAL(KIND=
dp),
DIMENSION(:, :, :),
POINTER :: wfn => null()
77 SUBROUTINE atom_fit_density(atom, num_gto, norder, iunit, agto, powell_section, results)
79 INTEGER,
INTENT(IN) :: num_gto, norder, iunit
80 REAL(kind=
dp),
DIMENSION(:),
OPTIONAL :: agto
82 REAL(kind=
dp),
DIMENSION(:),
OPTIONAL :: results
85 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: co, pe
86 REAL(kind=
dp),
DIMENSION(2) :: x
90 ALLOCATE (co(num_gto), pe(num_gto))
96 atom%state%maxl_occ,
atom%state%maxn_occ)
99 density%op =
fourpi*density%op
100 IF (norder /= 0)
THEN
101 density%op = density%op*
atom%basis%grid%rad**norder
104 IF (
PRESENT(agto))
THEN
105 cpassert(num_gto <=
SIZE(agto))
106 pe(1:num_gto) = agto(1:num_gto)
112 IF (
PRESENT(powell_section))
THEN
117 ostate%rhoend = 1.e-8_dp
118 ostate%rhobeg = 5.e-2_dp
126 WRITE (iunit,
'(/," POWELL| Start optimization procedure")')
128 n10 = ostate%maxfun/10
132 IF (ostate%state == 2)
THEN
133 pe(1:num_gto) = [(x(1)*x(2)**i, i=1, num_gto)]
134 CALL density_fit(density%op, density%grid, num_gto, pe, co, ostate%f)
137 IF (ostate%state == -1)
EXIT
141 IF (mod(ostate%nf, n10) == 0 .AND. iunit > 0)
THEN
142 WRITE (iunit,
'(" POWELL| Reached",i4,"% of maximal function calls")') &
143 int(real(ostate%nf,
dp)/real(ostate%maxfun,
dp)*100._dp)
150 pe(1:num_gto) = [(x(1)*x(2)**i, i=1, num_gto)]
153 CALL density_fit(density%op, density%grid, num_gto, pe, co, ostate%f)
157 IF (iunit > 0 .AND. .NOT.
PRESENT(agto))
THEN
158 WRITE (iunit,
'(" POWELL| Number of function evaluations",T71,I10)') ostate%nf
159 WRITE (iunit,
'(" POWELL| Final value of function",T61,G20.10)') ostate%fopt
160 WRITE (iunit,
'(" Optimized representation of density using a Geometrical Gaussian basis")')
161 WRITE (iunit,
'(A,I3,/,T10,A,F10.6,T48,A,F10.6)')
" Number of Gaussians:", num_gto, &
162 "Starting exponent:", x(1),
"Proportionality factor:", x(2)
163 WRITE (iunit,
'(A)')
" Expansion coefficients"
164 WRITE (iunit,
'(4F20.10)') co(1:num_gto)
167 IF (
PRESENT(results))
THEN
168 IF (
PRESENT(agto))
THEN
169 cpassert(
SIZE(results) >= num_gto)
170 results(1:num_gto) = co(1:num_gto)
172 cpassert(
SIZE(results) >= num_gto + 2)
175 results(3:2 + num_gto) = co(1:num_gto)
191 TYPE(
atom_p_type),
DIMENSION(:, :),
POINTER :: atom_info
193 LOGICAL,
INTENT(IN) :: pptype
194 INTEGER,
INTENT(IN) :: iunit
197 INTEGER :: i, j, k, l, ll, m, n, n10, nl, nr, zval
198 INTEGER,
ALLOCATABLE,
DIMENSION(:, :) :: xtob
199 LOGICAL :: explicit, mult, penalty
200 REAL(kind=
dp) :: al, crad, ear, fopt, pf, rk
201 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: x
202 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: wem
203 REAL(kind=
dp),
DIMENSION(:),
POINTER :: w
207 SELECT CASE (basis%basis_type)
211 IF (basis%geometrical)
THEN
214 x(1) = sqrt(basis%aval)
215 x(2) = sqrt(basis%cval)
217 ll = maxval(basis%nprim(:))
218 ALLOCATE (xtob(ll, 0:
lmat))
220 ll = sum(basis%nprim(:))
225 DO i = 1, basis%nprim(l)
228 IF (abs(basis%am(i, l) - x(k)) < 1.e-6_dp)
THEN
235 x(ll) = basis%am(i, l)
241 DO i = 1, ostate%nvar
242 x(i) = sqrt(log(1._dp + x(i)))
247 ll = maxval(basis%nbas(:))
248 ALLOCATE (xtob(ll, 0:
lmat))
250 ll = sum(basis%nbas(:))
255 DO i = 1, basis%nbas(l)
257 x(ll) = basis%as(i, l)
262 DO i = 1, ostate%nvar
263 x(i) = sqrt(log(1._dp + x(i)))
271 n =
SIZE(atom_info, 1)
272 m =
SIZE(atom_info, 2)
278 DO i = 1, min(
SIZE(w), n)
279 wem(i, :) = w(i)*wem(i, :)
285 DO i = 1, min(
SIZE(w), m)
286 wem(:, i) = w(i)*wem(:, i)
290 DO i = 1,
SIZE(atom_info, 1)
291 DO j = 1,
SIZE(atom_info, 2)
292 atom_info(i, j)%atom%weight = wem(i, j)
303 WRITE (iunit,
'(/," POWELL| Start optimization procedure")')
304 WRITE (iunit,
'(/," POWELL| Total number of parameters in optimization",T71,I10)') ostate%nvar
306 n10 = max(ostate%maxfun/100, 1)
312 IF (ostate%state == 2)
THEN
313 SELECT CASE (basis%basis_type)
317 IF (basis%geometrical)
THEN
320 DO i = 1, basis%nbas(l)
321 ll = i - 1 + basis%start(l)
322 basis%am(i, l) = x(1)*x(1)*(x(2)*x(2))**(ll)
325 basis%aval = x(1)*x(1)
326 basis%cval = x(2)*x(2)
329 DO i = 1, basis%nprim(l)
330 al = x(xtob(i, l))**2
331 basis%am(i, l) = exp(al) - 1._dp
340 DO i = 1, basis%nbas(l)
343 rk = basis%grid%rad(k)
344 ear = exp(-al*basis%grid%rad(k)**2)
345 basis%bf(k, i, l) = rk**l*ear
346 basis%dbf(k, i, l) = (real(l,
dp)*rk**(l - 1) - 2._dp*al*rk**(l + 1))*ear
347 basis%ddbf(k, i, l) = (real(l*(l - 1),
dp)*rk**(l - 2) - &
348 2._dp*al*real(2*l + 1,
dp)*rk**(l) + 4._dp*al*rk**(l + 2))*ear
354 DO i = 1, basis%nbas(l)
355 al = x(xtob(i, l))**2
356 basis%as(i, l) = exp(al) - 1._dp
364 DO i = 1, basis%nbas(l)
367 pf = (2._dp*al)**nl*sqrt(2._dp*al/
fac(2*nl))
369 rk = basis%grid%rad(k)
370 ear = rk**(nl - 1)*exp(-al*rk)
371 basis%bf(k, i, l) = pf*ear
372 basis%dbf(k, i, l) = pf*(real(nl - 1,
dp)/rk - al)*ear
373 basis%ddbf(k, i, l) = pf*(real((nl - 2)*(nl - 1),
dp)/rk/rk &
374 - al*real(2*(nl - 1),
dp)/rk + al*al)*ear
379 CALL basis_fit(atom_info, basis, pptype, ostate%f, 0, penalty)
380 fopt = min(fopt, ostate%f)
383 IF (ostate%state == -1)
EXIT
387 IF (ostate%nf == 2 .AND. iunit > 0)
THEN
388 WRITE (iunit,
'(" POWELL| Initial value of function",T61,F20.10)') ostate%f
390 IF (mod(ostate%nf, n10) == 0 .AND. iunit > 0)
THEN
391 WRITE (iunit,
'(" POWELL| Reached",i4,"% of maximal function calls",T61,F20.10)') &
392 int(real(ostate%nf,
dp)/real(ostate%maxfun,
dp)*100._dp), fopt
401 WRITE (iunit,
'(" POWELL| Number of function evaluations",T71,I10)') ostate%nf
402 WRITE (iunit,
'(" POWELL| Final value of function",T61,F20.10)') ostate%fopt
404 SELECT CASE (basis%basis_type)
408 IF (basis%geometrical)
THEN
411 DO i = 1, basis%nbas(l)
412 ll = i - 1 + basis%start(l)
413 basis%am(i, l) = x(1)*x(1)*(x(2)*x(2))**(ll)
416 basis%aval = x(1)*x(1)
417 basis%cval = x(2)*x(2)
420 DO i = 1, basis%nprim(l)
421 al = x(xtob(i, l))**2
422 basis%am(i, l) = exp(al) - 1._dp
431 DO i = 1, basis%nbas(l)
434 rk = basis%grid%rad(k)
435 ear = exp(-al*basis%grid%rad(k)**2)
436 basis%bf(k, i, l) = rk**l*ear
437 basis%dbf(k, i, l) = (real(l,
dp)*rk**(l - 1) - 2._dp*al*rk**(l + 1))*ear
438 basis%ddbf(k, i, l) = (real(l*(l - 1),
dp)*rk**(l - 2) - &
439 2._dp*al*real(2*l + 1,
dp)*rk**(l) + 4._dp*al*rk**(l + 2))*ear
445 DO i = 1, basis%nprim(l)
446 al = x(xtob(i, l))**2
447 basis%as(i, l) = exp(al) - 1._dp
455 DO i = 1, basis%nbas(l)
458 pf = (2._dp*al)**nl*sqrt(2._dp*al/
fac(2*nl))
460 rk = basis%grid%rad(k)
461 ear = rk**(nl - 1)*exp(-al*rk)
462 basis%bf(k, i, l) = pf*ear
463 basis%dbf(k, i, l) = pf*(real(nl - 1,
dp)/rk - al)*ear
464 basis%ddbf(k, i, l) = pf*(real((nl - 2)*(nl - 1),
dp)/rk/rk &
465 - al*real(2*(nl - 1),
dp)/rk + al*al)*ear
476 IF (
ALLOCATED(xtob))
THEN
480 SELECT CASE (basis%basis_type)
484 zval = atom_info(1, 1)%atom%z
504 TYPE(
atom_p_type),
DIMENSION(:, :),
POINTER :: atom_info, atom_refs
506 INTEGER,
INTENT(IN) :: iunit
509 LOGICAL,
PARAMETER :: debug = .false.
511 CHARACTER(len=2) :: pc1, pc2, pct
512 INTEGER :: i, i1, i2, iw, j, j1, j2, k, l, m, n, &
513 n10, np, nre, nreinit, ntarget
514 INTEGER,
ALLOCATABLE,
DIMENSION(:, :) :: xtob
515 INTEGER,
DIMENSION(0:lmat) :: ncore
516 LOGICAL :: explicit, noopt_nlcc, preopt_nlcc
517 REAL(kind=
dp) :: afun, charge, de, deig, drho, dx, eig, fopt, oc, pchg, peig, pv, rcm, rcov, &
518 rmax, semicore_level, step_size_scaling, t_ener, t_psir0, t_semi, t_valence, t_virt, &
519 w_ener, w_node, w_psir0, w_semi, w_valence, w_virt, wtot
520 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: x, xi
521 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: wem
522 REAL(kind=
dp),
ALLOCATABLE, &
523 DIMENSION(:, :, :, :, :) :: dener, pval
524 REAL(kind=
dp),
DIMENSION(:),
POINTER :: w
527 TYPE(wfn_init),
DIMENSION(:, :),
POINTER :: wfn_guess
556 n =
SIZE(atom_info, 1)
557 m =
SIZE(atom_info, 2)
560 ALLOCATE (pval(8, 10, 0:
lmat, m, n))
561 ALLOCATE (dener(2, m, m, n, n))
564 ALLOCATE (wfn_guess(n, m))
567 atom => atom_info(i, j)%atom
568 NULLIFY (wfn_guess(i, j)%wfn)
570 i1 =
SIZE(
atom%orbitals%wfn, 1)
571 i2 =
SIZE(
atom%orbitals%wfn, 2)
572 ALLOCATE (wfn_guess(i, j)%wfn(i1, i2, 0:
lmat))
580 DO i = 1, min(
SIZE(w), n)
581 wem(i, :) = w(i)*wem(i, :)
587 DO i = 1, min(
SIZE(w), m)
588 wem(:, i) = w(i)*wem(:, i)
593 CALL open_file(file_name=
"POWELL_RESULT", file_status=
"UNKNOWN", file_action=
"WRITE", unit_number=iw)
596 IF (ppot%gth_pot%nlcc)
THEN
597 CALL opt_nlcc_param(atom_info, atom_refs, ppot%gth_pot, iunit, preopt_nlcc)
600 preopt_nlcc = .false.
605 CALL get_pseudo_param(xi, ostate%nvar, ppot%gth_pot, noopt_nlcc)
606 ALLOCATE (x(ostate%nvar))
607 x(1:ostate%nvar) = xi(1:ostate%nvar)
616 WRITE (iunit,
'(/," POWELL| Start optimization procedure")')
617 WRITE (iunit,
'(/," POWELL| Total number of parameters in optimization",T71,I10)') ostate%nvar
619 n10 = max(ostate%maxfun/100, 1)
621 rcov =
ptable(atom_refs(1, 1)%atom%z)%covalent_radius*
bohr*rcm
625 DO i = 1,
SIZE(atom_info, 1)
626 DO j = 1,
SIZE(atom_info, 2)
627 atom => atom_info(i, j)%atom
629 dener(2, j, j, i, i) = atom_refs(i, j)%atom%energy%etot
630 IF (
atom%state%multiplicity == -1)
THEN
632 atom%weight = wem(i, j)
635 np =
atom%state%maxn_calc(l)
637 CALL atom_orbital_max(rmax, atom_refs(i, j)%atom%orbitals%wfn(:, ncore(l) + k, l), &
638 rcov, l, atom_refs(i, j)%atom%basis)
639 atom%orbitals%rcmax(k, l, 1) = max(rcov, rmax)
641 atom%orbitals%rcmax(k, l, 1), l, atom_refs(i, j)%atom%basis)
642 atom%orbitals%refene(k, l, 1) = atom_refs(i, j)%atom%orbitals%ener(ncore(l) + k, l)
643 atom%orbitals%refchg(k, l, 1) = charge
644 IF (k >
atom%state%maxn_occ(l))
THEN
645 IF (k <=
atom%state%maxn_occ(l) + 1)
THEN
646 atom%orbitals%wrefene(k, l, 1) = w_virt
647 atom%orbitals%wrefchg(k, l, 1) = w_virt/100._dp
648 atom%orbitals%crefene(k, l, 1) = t_virt
649 atom%orbitals%reftype(k, l, 1) =
"U1"
650 ntarget = ntarget + 2
651 wtot = wtot +
atom%weight*(w_virt + w_virt/100._dp)
653 atom%orbitals%wrefene(k, l, 1) = w_virt/100._dp
654 atom%orbitals%wrefchg(k, l, 1) = 0._dp
655 atom%orbitals%crefene(k, l, 1) = t_virt*10._dp
656 atom%orbitals%reftype(k, l, 1) =
"U2"
657 ntarget = ntarget + 1
658 wtot = wtot +
atom%weight*w_virt/100._dp
660 ELSEIF (k <
atom%state%maxn_occ(l))
THEN
661 atom%orbitals%wrefene(k, l, 1) = w_semi
662 atom%orbitals%wrefchg(k, l, 1) = w_semi/100._dp
663 atom%orbitals%crefene(k, l, 1) = t_semi
664 atom%orbitals%reftype(k, l, 1) =
"SC"
665 ntarget = ntarget + 2
666 wtot = wtot +
atom%weight*(w_semi + w_semi/100._dp)
668 IF (abs(
atom%state%occupation(l, k) - real(4*l + 2, kind=
dp)) < 0.01_dp .AND. &
669 abs(
atom%orbitals%refene(k, l, 1)) > semicore_level)
THEN
671 atom%orbitals%wrefene(k, l, 1) = w_semi
672 atom%orbitals%wrefchg(k, l, 1) = w_semi/100._dp
673 atom%orbitals%crefene(k, l, 1) = t_semi
674 atom%orbitals%reftype(k, l, 1) =
"SC"
675 wtot = wtot +
atom%weight*(w_semi + w_semi/100._dp)
677 atom%orbitals%wrefene(k, l, 1) = w_valence
678 atom%orbitals%wrefchg(k, l, 1) = w_valence/100._dp
679 atom%orbitals%crefene(k, l, 1) = t_valence
680 atom%orbitals%reftype(k, l, 1) =
"VA"
681 wtot = wtot +
atom%weight*(w_valence + w_valence/100._dp)
684 atom%orbitals%tpsir0(k, 1) = t_psir0
685 atom%orbitals%wpsir0(k, 1) = w_psir0
686 wtot = wtot +
atom%weight*w_psir0
688 ntarget = ntarget + 2
692 atom%orbitals%refnod(k, l, 1) = real(k - 1, kind=
dp)
694 IF (k == 1 .AND.
atom%state%occupation(l, k) /= 0._dp)
THEN
695 atom%orbitals%wrefnod(k, l, 1) = w_node
696 wtot = wtot +
atom%weight*w_node
702 atom%weight = wem(i, j)
705 np =
atom%state%maxn_calc(l)
707 CALL atom_orbital_max(rmax, atom_refs(i, j)%atom%orbitals%wfna(:, ncore(l) + k, l), &
708 rcov, l, atom_refs(i, j)%atom%basis)
709 atom%orbitals%rcmax(k, l, 1) = max(rcov, rmax)
710 CALL atom_orbital_max(rmax, atom_refs(i, j)%atom%orbitals%wfnb(:, ncore(l) + k, l), &
711 rcov, l, atom_refs(i, j)%atom%basis)
712 atom%orbitals%rcmax(k, l, 2) = max(rcov, rmax)
714 atom%orbitals%rcmax(k, l, 1), l, atom_refs(i, j)%atom%basis)
715 atom%orbitals%refene(k, l, 1) = atom_refs(i, j)%atom%orbitals%enera(ncore(l) + k, l)
716 atom%orbitals%refchg(k, l, 1) = charge
718 atom%orbitals%rcmax(k, l, 1), l, atom_refs(i, j)%atom%basis)
719 atom%orbitals%refene(k, l, 2) = atom_refs(i, j)%atom%orbitals%enerb(ncore(l) + k, l)
720 atom%orbitals%refchg(k, l, 2) = charge
722 IF (k >
atom%state%maxn_occ(l))
THEN
723 IF (k <=
atom%state%maxn_occ(l) + 1)
THEN
724 atom%orbitals%wrefene(k, l, 1:2) = w_virt
725 atom%orbitals%wrefchg(k, l, 1:2) = w_virt/100._dp
726 atom%orbitals%crefene(k, l, 1:2) = t_virt
727 atom%orbitals%reftype(k, l, 1:2) =
"U1"
728 ntarget = ntarget + 4
729 wtot = wtot +
atom%weight*2._dp*(w_virt + w_virt/100._dp)
731 atom%orbitals%wrefene(k, l, 1:2) = w_virt/100._dp
732 atom%orbitals%wrefchg(k, l, 1:2) = 0._dp
733 atom%orbitals%crefene(k, l, 1:2) = t_virt*10.0_dp
734 atom%orbitals%reftype(k, l, 1:2) =
"U2"
735 wtot = wtot +
atom%weight*2._dp*w_virt/100._dp
736 ntarget = ntarget + 2
738 ELSEIF (k <
atom%state%maxn_occ(l))
THEN
739 atom%orbitals%wrefene(k, l, 1:2) = w_semi
740 atom%orbitals%wrefchg(k, l, 1:2) = w_semi/100._dp
741 atom%orbitals%crefene(k, l, 1:2) = t_semi
742 atom%orbitals%reftype(k, l, 1:2) =
"SC"
743 ntarget = ntarget + 4
744 wtot = wtot +
atom%weight*2._dp*(w_semi + w_semi/100._dp)
746 IF (abs(
atom%state%occupation(l, k) - real(2*l + 1, kind=
dp)) < 0.01_dp .AND. &
747 abs(
atom%orbitals%refene(k, l, 1)) > semicore_level)
THEN
748 atom%orbitals%wrefene(k, l, 1:2) = w_semi
749 atom%orbitals%wrefchg(k, l, 1:2) = w_semi/100._dp
750 atom%orbitals%crefene(k, l, 1:2) = t_semi
751 atom%orbitals%reftype(k, l, 1:2) =
"SC"
752 wtot = wtot +
atom%weight*2._dp*(w_semi + w_semi/100._dp)
754 atom%orbitals%wrefene(k, l, 1:2) = w_valence
755 atom%orbitals%wrefchg(k, l, 1:2) = w_valence/100._dp
756 atom%orbitals%crefene(k, l, 1:2) = t_valence
757 atom%orbitals%reftype(k, l, 1:2) =
"VA"
758 wtot = wtot +
atom%weight*2._dp*(w_valence + w_valence/100._dp)
760 ntarget = ntarget + 4
762 atom%orbitals%tpsir0(k, 1:2) = t_psir0
763 atom%orbitals%wpsir0(k, 1:2) = w_psir0
764 wtot = wtot +
atom%weight*2._dp*w_psir0
769 atom%orbitals%refnod(k, l, 1:2) = real(k - 1, kind=
dp)
771 IF (k == 1 .AND.
atom%state%occa(l, k) /= 0._dp)
THEN
772 atom%orbitals%wrefnod(k, l, 1) = w_node
773 wtot = wtot +
atom%weight*w_node
775 IF (k == 1 .AND.
atom%state%occb(l, k) /= 0._dp)
THEN
776 atom%orbitals%wrefnod(k, l, 2) = w_node
777 wtot = wtot +
atom%weight*w_node
787 DO j1 = 1,
SIZE(atom_info, 2)
788 DO j2 = 1,
SIZE(atom_info, 2)
789 DO i1 = 1,
SIZE(atom_info, 1)
790 DO i2 = 1,
SIZE(atom_info, 1)
791 IF ((j1 > j2) .OR. (j1 == j2 .AND. i1 >= i2)) cycle
792 dener(2, j1, j2, i1, i2) = dener(2, j1, j1, i1, i1) - dener(2, j2, j2, i2, i2)
801 ALLOCATE (xi(ostate%nvar))
804 CALL put_pseudo_param(x, ppot%gth_pot, noopt_nlcc)
805 CALL pseudo_fit(atom_info, wfn_guess, ppot, ostate%f, wtot, pval, dener, w_ener, t_ener, .true.)
807 WRITE (iunit,
'(/," POWELL| Initial errors of target values")')
809 DO i = 1,
SIZE(atom_info, 1)
810 DO j = 1,
SIZE(atom_info, 2)
811 atom => atom_info(i, j)%atom
814 wfn_guess(i, j)%wfn =
atom%orbitals%wfn
816 WRITE (iunit,
'(/," Reference configuration ",T31,i5,T50," Method number ",T76,i5)') i, j
817 IF (
atom%state%multiplicity == -1)
THEN
819 WRITE (iunit,
'(" L N Occupation Eigenvalue [eV] dE [eV] dCharge ")')
821 np =
atom%state%maxn_calc(l)
824 oc =
atom%state%occupation(l, k)
825 eig =
atom%orbitals%ener(k, l)
826 deig = eig -
atom%orbitals%refene(k, l, 1)
827 peig = pval(1, k, l, j, i)/afun*100._dp
828 IF (pval(5, k, l, j, i) > 0.5_dp)
THEN
831 WRITE (pc1,
"(I2)") nint(peig)
834 atom%orbitals%rcmax(k, l, 1), l,
atom%basis)
835 drho = charge -
atom%orbitals%refchg(k, l, 1)
836 pchg = pval(2, k, l, j, i)/afun*100._dp
837 IF (pval(6, k, l, j, i) > 0.5_dp)
THEN
840 WRITE (pc2,
"(I2)") min(nint(pchg), 99)
842 pct =
atom%orbitals%reftype(k, l, 1)
843 WRITE (iunit,
'(I5,I5,F14.2,F21.10,A3,F11.6,"[",A2,"]",F13.6,"[",A2,"]")') &
844 l, k, oc, eig*
evolt, pct, deig*
evolt, pc1, drho, pc2
850 WRITE (iunit,
'(" L N Spin Occupation Eigenvalue [eV] dE [eV] dCharge ")')
852 np =
atom%state%maxn_calc(l)
855 oc =
atom%state%occa(l, k)
856 eig =
atom%orbitals%enera(k, l)
857 deig = eig -
atom%orbitals%refene(k, l, 1)
858 peig = pval(1, k, l, j, i)/afun*100._dp
859 IF (pval(5, k, l, j, i) > 0.5_dp)
THEN
862 WRITE (pc1,
"(I2)") nint(peig)
865 charge,
atom%orbitals%wfna(:, k, l),
atom%orbitals%rcmax(k, l, 1), l,
atom%basis)
866 drho = charge -
atom%orbitals%refchg(k, l, 1)
867 pchg = pval(2, k, l, j, i)/afun*100._dp
868 IF (pval(6, k, l, j, i) > 0.5_dp)
THEN
871 WRITE (pc2,
"(I2)") min(nint(pchg), 99)
873 pct =
atom%orbitals%reftype(k, l, 1)
874 WRITE (iunit,
'(I5,I5,2X,A5,F11.2,F19.10,A3,F10.6,"[",A2,"]",F12.6,"[",A2,"]")') &
875 l, k,
"alpha", oc, eig*
evolt, pct, deig*
evolt, pc1, drho, pc2
876 oc =
atom%state%occb(l, k)
877 eig =
atom%orbitals%enerb(k, l)
878 deig = eig -
atom%orbitals%refene(k, l, 2)
879 peig = pval(3, k, l, j, i)/afun*100._dp
880 IF (pval(7, k, l, j, i) > 0.5_dp)
THEN
883 WRITE (pc1,
"(I2)") nint(peig)
886 charge,
atom%orbitals%wfnb(:, k, l),
atom%orbitals%rcmax(k, l, 2), l,
atom%basis)
887 drho = charge -
atom%orbitals%refchg(k, l, 2)
888 pchg = pval(4, k, l, j, i)/afun*100._dp
889 IF (pval(8, k, l, j, i) > 0.5_dp)
THEN
892 WRITE (pc2,
"(I2)") min(nint(pchg), 99)
894 pct =
atom%orbitals%reftype(k, l, 2)
895 WRITE (iunit,
'(I5,I5,2X,A5,F11.2,F19.10,A3,F10.6,"[",A2,"]",F12.6,"[",A2,"]")') &
896 l, k,
" beta", oc, eig*
evolt, pct, deig*
evolt, pc1, drho, pc2
907 WRITE (iunit,
'(" Method/Econf 1 "," Method/Econf 2"," Delta Energy "," Error Energy "," Target")')
908 DO j1 = 1,
SIZE(atom_info, 2)
909 DO j2 = 1,
SIZE(atom_info, 2)
910 DO i1 = 1,
SIZE(atom_info, 1)
911 DO i2 = 1,
SIZE(atom_info, 1)
912 IF ((j1 > j2) .OR. (j1 == j2 .AND. i1 >= i2)) cycle
913 IF (abs(dener(1, j1, j1, i1, i1)) < 0.000001_dp) cycle
914 IF (abs(dener(2, j1, j1, i1, i1)) < 0.000001_dp) cycle
915 IF (abs(dener(1, j2, j2, i2, i2)) < 0.000001_dp) cycle
916 IF (abs(dener(2, j2, j2, i2, i2)) < 0.000001_dp) cycle
917 de = dener(2, j1, j2, i1, i2) - dener(1, j1, j2, i1, i2)
918 WRITE (iunit,
'(i6,i6,i10,i6,5X,F16.6,F19.6,F12.6)') &
919 j1, i1, j2, i2, dener(2, j1, j2, i1, i2), de, t_ener
927 WRITE (iunit,
'(" Number of target values reached: ",T69,i5," of ",i3)') &
928 int(sum(pval(5:8, :, :, :, :))), ntarget
933 WRITE (iunit,
'(" POWELL| Start optimization",I4," of total",I4,T60,"rhobeg = ",F12.8)') &
934 nre, nreinit, ostate%rhobeg
940 IF (ostate%state == 2)
THEN
941 CALL put_pseudo_param(x, ppot%gth_pot, noopt_nlcc)
942 CALL pseudo_fit(atom_info, wfn_guess, ppot, ostate%f, wtot, pval, dener, w_ener, t_ener, .false.)
943 fopt = min(fopt, ostate%f)
946 IF (ostate%state == -1)
EXIT
950 IF (ostate%nf == 2 .AND. iunit > 0)
THEN
951 WRITE (iunit,
'(" POWELL| Initial value of function",T61,F20.10)') ostate%f
953 IF (mod(ostate%nf, n10) == 0 .AND. iunit > 0 .AND. ostate%nf > 2)
THEN
954 WRITE (iunit,
'(" POWELL| Reached",i4,"% of maximal function calls",T61,F20.10)') &
955 int(real(ostate%nf,
dp)/real(ostate%maxfun,
dp)*100._dp), fopt
956 CALL put_pseudo_param(ostate%xopt, ppot%gth_pot, noopt_nlcc)
960 IF (fopt < 1.e-12_dp)
EXIT
963 WRITE (iw, *) ostate%nf, ostate%f, x(1:ostate%nvar)
968 dx = sqrt(sum((ostate%xopt(:) - xi(:))**2)/real(ostate%nvar, kind=
dp))
970 WRITE (iunit,
'(" POWELL| RMS average of variables",T69,F12.10)') dx
974 CALL put_pseudo_param(x, ppot%gth_pot, noopt_nlcc)
977 IF ((dx*dx) < ostate%rhoend)
EXIT
978 ostate%rhobeg = step_size_scaling*ostate%rhobeg
983 WRITE (iunit,
'(" POWELL| Number of function evaluations",T71,I10)') ostate%nf
984 WRITE (iunit,
'(" POWELL| Final value of function",T61,F20.10)') ostate%fopt
986 CALL put_pseudo_param(x, ppot%gth_pot, noopt_nlcc)
987 CALL pseudo_fit(atom_info, wfn_guess, ppot, ostate%f, wtot, pval, dener, w_ener, t_ener, .false.)
990 WRITE (iunit,
'(/," POWELL| Final errors of target values")')
991 DO i = 1,
SIZE(atom_info, 1)
992 DO j = 1,
SIZE(atom_info, 2)
993 atom => atom_info(i, j)%atom
995 WRITE (iunit,
'(/," Reference configuration ",T31,i5,T50," Method number ",T76,i5)') i, j
996 IF (
atom%state%multiplicity == -1)
THEN
998 WRITE (iunit,
'(" L N Occupation Eigenvalue [eV] dE [eV] dCharge ")')
1000 np =
atom%state%maxn_calc(l)
1003 oc =
atom%state%occupation(l, k)
1004 eig =
atom%orbitals%ener(k, l)
1005 deig = eig -
atom%orbitals%refene(k, l, 1)
1006 peig = pval(1, k, l, j, i)/afun*100._dp
1007 IF (pval(5, k, l, j, i) > 0.5_dp)
THEN
1010 WRITE (pc1,
"(I2)") nint(peig)
1013 charge,
atom%orbitals%wfn(:, k, l),
atom%orbitals%rcmax(k, l, 1), l,
atom%basis)
1014 drho = charge -
atom%orbitals%refchg(k, l, 1)
1015 pchg = pval(2, k, l, j, i)/afun*100._dp
1016 IF (pval(6, k, l, j, i) > 0.5_dp)
THEN
1019 WRITE (pc2,
"(I2)") min(nint(pchg), 99)
1021 pct =
atom%orbitals%reftype(k, l, 1)
1022 WRITE (iunit,
'(I5,I5,F14.2,F21.10,A3,F11.6,"[",A2,"]",F13.6,"[",A2,"]")') &
1023 l, k, oc, eig*
evolt, pct, deig*
evolt, pc1, drho, pc2
1027 np =
atom%state%maxn_calc(0)
1030 IF (abs(
atom%orbitals%tpsir0(k, 1)) > 1.e-14_dp)
THEN
1031 IF (abs(pv) > abs(
atom%orbitals%tpsir0(k, 1)))
THEN
1034 pv = 10._dp*(abs(pv) - abs(
atom%orbitals%tpsir0(k, 1)))
1036 pchg =
atom%weight*
atom%orbitals%wpsir0(k, 1)*pv*pv/afun
1038 pchg =
atom%weight*
atom%orbitals%wpsir0(k, 1)*pv*pv/afun*100._dp
1040 WRITE (iunit,
'(" s-states"," N=",I5,T40,"Wavefunction at r=0:",T64,F13.6,"[",I2,"]")') &
1045 WRITE (iunit,
'(" L N Spin Occupation Eigenvalue [eV] dE [eV] dCharge ")')
1047 np =
atom%state%maxn_calc(l)
1050 oc =
atom%state%occa(l, k)
1051 eig =
atom%orbitals%enera(k, l)
1052 deig = eig -
atom%orbitals%refene(k, l, 1)
1053 peig = pval(1, k, l, j, i)/afun*100._dp
1054 IF (pval(5, k, l, j, i) > 0.5_dp)
THEN
1057 WRITE (pc1,
"(I2)") nint(peig)
1060 charge,
atom%orbitals%wfna(:, k, l),
atom%orbitals%rcmax(k, l, 1), l,
atom%basis)
1061 drho = charge -
atom%orbitals%refchg(k, l, 1)
1062 pchg = pval(2, k, l, j, i)/afun*100._dp
1063 IF (pval(6, k, l, j, i) > 0.5_dp)
THEN
1066 WRITE (pc2,
"(I2)") min(nint(pchg), 99)
1068 pct =
atom%orbitals%reftype(k, l, 1)
1069 WRITE (iunit,
'(I5,I5,A,F11.2,F20.10,A3,F10.6,"[",A2,"]",F11.6,"[",A2,"]")') &
1070 l, k,
" alpha", oc, eig*
evolt, pct, deig*
evolt, pc1, drho, pc2
1071 oc =
atom%state%occb(l, k)
1072 eig =
atom%orbitals%enerb(k, l)
1073 deig = eig -
atom%orbitals%refene(k, l, 2)
1074 peig = pval(3, k, l, j, i)/afun*100._dp
1075 IF (pval(7, k, l, j, i) > 0.5_dp)
THEN
1078 WRITE (pc1,
"(I2)") nint(peig)
1081 charge,
atom%orbitals%wfnb(:, k, l),
atom%orbitals%rcmax(k, l, 2), l,
atom%basis)
1082 drho = charge -
atom%orbitals%refchg(k, l, 2)
1083 pchg = pval(4, k, l, j, i)/afun*100._dp
1084 IF (pval(8, k, l, j, i) > 0.5_dp)
THEN
1087 WRITE (pc2,
"(I2)") min(nint(pchg), 99)
1089 pct =
atom%orbitals%reftype(k, l, 2)
1090 WRITE (iunit,
'(I5,I5,A,F11.2,F20.10,A3,F10.6,"[",A2,"]",F11.6,"[",A2,"]")') &
1091 l, k,
" beta", oc, eig*
evolt, pct, deig*
evolt, pc1, drho, pc2
1095 np =
atom%state%maxn_calc(0)
1098 IF (abs(
atom%orbitals%tpsir0(k, 1)) > 1.e-14_dp)
THEN
1099 IF (abs(pv) > abs(
atom%orbitals%tpsir0(k, 1)))
THEN
1102 pv = 10._dp*(abs(pv) - abs(
atom%orbitals%tpsir0(k, 1)))
1104 pchg =
atom%weight*
atom%orbitals%wpsir0(k, 1)*pv*pv/afun
1106 pchg =
atom%weight*
atom%orbitals%wpsir0(k, 1)*pv*pv/afun*100._dp
1108 WRITE (iunit,
'(" s-states"," N=",I5,T35,"Alpha Wavefunction at r=0:",T64,F13.6,"[",I2,"]")') &
1112 IF (abs(
atom%orbitals%tpsir0(k, 2)) > 1.e-14_dp)
THEN
1113 IF (abs(pv) > abs(
atom%orbitals%tpsir0(k, 2)))
THEN
1116 pv = 10._dp*(abs(pv) - abs(
atom%orbitals%tpsir0(k, 2)))
1118 pchg =
atom%weight*
atom%orbitals%wpsir0(k, 2)*pv*pv/afun
1120 pchg =
atom%weight*
atom%orbitals%wpsir0(k, 2)*pv*pv/afun*100._dp
1122 WRITE (iunit,
'(" s-states"," N=",I5,T36,"Beta Wavefunction at r=0:",T64,F13.6,"[",I2,"]")') &
1132 WRITE (iunit,
'(" Method/Econf 1 "," Method/Econf 2"," Delta Energy "," Error Energy "," Target")')
1133 DO j1 = 1,
SIZE(atom_info, 2)
1134 DO j2 = 1,
SIZE(atom_info, 2)
1135 DO i1 = 1,
SIZE(atom_info, 1)
1136 DO i2 = 1,
SIZE(atom_info, 1)
1137 IF ((j1 > j2) .OR. (j1 == j2 .AND. i1 >= i2)) cycle
1138 IF (abs(dener(1, j1, j1, i1, i1)) < 0.000001_dp) cycle
1139 IF (abs(dener(2, j1, j1, i1, i1)) < 0.000001_dp) cycle
1140 IF (abs(dener(1, j2, j2, i2, i2)) < 0.000001_dp) cycle
1141 IF (abs(dener(2, j2, j2, i2, i2)) < 0.000001_dp) cycle
1142 de = dener(2, j1, j2, i1, i2) - dener(1, j1, j2, i1, i2)
1143 WRITE (iunit,
'(i6,i6,i10,i6,5X,F16.6,F19.6,F12.6)') j1, i1, j2, i2, dener(2, j1, j2, i1, i2), de, t_ener
1151 WRITE (iunit,
'(/," Number of target values reached: ",T69,i5," of ",i3)') int(sum(pval(5:8, :, :, :, :))), ntarget
1155 DEALLOCATE (x, pval, dener)
1157 DO i = 1,
SIZE(wfn_guess, 1)
1158 DO j = 1,
SIZE(wfn_guess, 2)
1159 IF (
ASSOCIATED(wfn_guess(i, j)%wfn))
THEN
1160 DEALLOCATE (wfn_guess(i, j)%wfn)
1164 DEALLOCATE (wfn_guess)
1166 IF (
ALLOCATED(xtob))
THEN
1184 SUBROUTINE opt_nlcc_param(atom_info, atom_refs, gthpot, iunit, preopt_nlcc)
1185 TYPE(
atom_p_type),
DIMENSION(:, :),
POINTER :: atom_info, atom_refs
1187 INTEGER,
INTENT(in) :: iunit
1188 LOGICAL,
INTENT(in) :: preopt_nlcc
1190 INTEGER :: i, im, j, k, method
1191 REAL(kind=
dp) :: rcov, zcore, zrc, zrch
1193 TYPE(
opgrid_type),
POINTER :: corden, den, den1, den2, density
1194 TYPE(
opmat_type),
POINTER :: denmat, dma, dmb
1196 cpassert(gthpot%nlcc)
1199 WRITE (iunit,
'(/," Core density information")')
1200 WRITE (iunit,
'(A,T37,A,T55,A,T75,A)')
" State Density:",
"Full",
"Rcov/2",
"Rcov/4"
1203 rcov =
ptable(atom_refs(1, 1)%atom%z)%covalent_radius*
bohr
1204 atom => atom_info(1, 1)%atom
1209 DO i = 1,
SIZE(atom_info, 1)
1210 DO j = 1,
SIZE(atom_info, 2)
1211 atom => atom_info(i, j)%atom
1212 aref => atom_refs(i, j)%atom
1214 NULLIFY (den, denmat)
1218 method =
atom%method_type
1219 SELECT CASE (method)
1222 atom%basis%nbas,
atom%state%core, &
1223 aref%state%maxl_occ, aref%state%maxn_occ)
1229 atom%basis%nbas,
atom%state%core, &
1230 aref%state%maxl_occ, aref%state%maxn_occ)
1232 atom%basis%nbas,
atom%state%core, &
1233 aref%state%maxl_occ, aref%state%maxn_occ)
1234 denmat%op = 0.5_dp*(dma%op + dmb%op)
1244 CALL atom_density(den%op, denmat%op,
atom%basis, aref%state%maxl_occ, typ=
"RHO")
1245 density%op = density%op + den%op
1248 NULLIFY (den1, den2)
1253 DO k = 1,
atom%basis%grid%nr
1254 IF (
atom%basis%grid%rad(k) < 0.50_dp*rcov)
THEN
1255 den1%op(k) = den%op(k)
1257 IF (
atom%basis%grid%rad(k) < 0.25_dp*rcov)
THEN
1258 den2%op(k) = den%op(k)
1270 WRITE (iunit,
'(2I5,T31,F10.4,T51,F10.4,T71,F10.4)') i, j, zcore, zrc, zrch
1275 density%op = density%op/real(im, kind=
dp)
1277 IF (preopt_nlcc)
THEN
1278 gthpot%nexp_nlcc = 1
1280 gthpot%cval_nlcc = 0._dp
1281 gthpot%alpha_nlcc = 0._dp
1282 gthpot%nct_nlcc(1) = 1
1283 gthpot%cval_nlcc(1, 1) = 1.0_dp
1284 gthpot%alpha_nlcc(1) = gthpot%rc
1288 DO k = 1,
atom%basis%grid%nr
1289 IF (
atom%basis%grid%rad(k) > 0.25_dp*rcov)
THEN
1290 corden%op(k) = 0.0_dp
1295 gthpot%cval_nlcc(1, 1) = zrch/zrc
1300 END SUBROUTINE opt_nlcc_param
1311 SUBROUTINE density_fit(density, grid, n, pe, co, aerr)
1312 REAL(
dp),
DIMENSION(:),
INTENT(IN) :: density
1314 INTEGER,
INTENT(IN) :: n
1315 REAL(
dp),
DIMENSION(:),
INTENT(IN) :: pe
1316 REAL(
dp),
DIMENSION(:),
INTENT(INOUT) :: co
1317 REAL(
dp),
INTENT(OUT) :: aerr
1319 INTEGER :: i, info, ip, iq, k, nr
1320 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: ipiv
1321 REAL(
dp) :: a, rk, zval
1322 REAL(
dp),
ALLOCATABLE,
DIMENSION(:) :: den, uval
1323 REAL(
dp),
ALLOCATABLE,
DIMENSION(:, :) :: bf, smat, tval
1326 ALLOCATE (bf(nr, n), den(nr))
1333 bf(k, i) = exp(-a*rk**2)
1341 ALLOCATE (tval(n + 1, 1), uval(n), smat(n + 1, n + 1))
1343 uval(i) = (
pi/pe(i))**1.5_dp
1346 tval(n + 1, 1) = zval
1350 smat(ip, iq) = (
pi/(pe(ip) + pe(iq)))**1.5_dp
1353 smat(1:n, n + 1) = uval(1:n)
1354 smat(n + 1, 1:n) = uval(1:n)
1355 smat(n + 1, n + 1) = 0._dp
1357 ALLOCATE (ipiv(n + 1))
1358 CALL dgesv(n + 1, 1, smat, n + 1, ipiv, tval, n + 1, info)
1361 co(1:n) = tval(1:n, 1)
1366 den(:) = den(:) + co(i)*bf(:, i)
1369 den(:) = (den(:) - density(:))**2
1372 DEALLOCATE (bf, den)
1374 DEALLOCATE (tval, uval, smat)
1376 END SUBROUTINE density_fit
1386 SUBROUTINE basis_fit(atom_info, basis, pptype, afun, iw, penalty)
1387 TYPE(
atom_p_type),
DIMENSION(:, :),
POINTER :: atom_info
1389 LOGICAL,
INTENT(IN) :: pptype
1390 REAL(
dp),
INTENT(OUT) :: afun
1391 INTEGER,
INTENT(IN) :: iw
1392 LOGICAL,
INTENT(IN) :: penalty
1394 INTEGER :: do_eric, do_erie, i, im, in, l, nm, nn, &
1396 LOGICAL :: eri_c, eri_e
1397 REAL(kind=
dp) :: amin
1404 nn =
SIZE(atom_info, 1)
1405 nm =
SIZE(atom_info, 2)
1414 atom => atom_info(in, im)%atom
1415 IF (pptype .EQV.
atom%pp_calc)
THEN
1416 pot =>
atom%potential
1417 zval = atom_info(in, im)%atom%z
1418 reltyp = atom_info(in, im)%atom%relativistic
1419 do_eric = atom_info(in, im)%atom%coulomb_integral_type
1420 do_erie = atom_info(in, im)%atom%exchange_integral_type
1426 IF (
ASSOCIATED(pot))
EXIT
1429 CALL atom_int_setup(atint, basis, potential=pot, eri_coulomb=eri_c, eri_exchange=eri_e)
1433 NULLIFY (atint%tzora, atint%hdkh)
1443 atom => atom_info(in, im)%atom
1445 IF (pptype .EQV.
atom%pp_calc)
THEN
1449 afun = afun +
atom%energy%etot*
atom%weight
1458 DO i = 1, basis%nbas(l) - 1
1459 amin = minval(abs(basis%am(i, l) - basis%am(i + 1:basis%nbas(l), l)))
1460 amin = amin/basis%am(i, l)
1461 afun = afun + 10._dp*exp(-(20._dp*amin)**4)
1472 END SUBROUTINE basis_fit
1486 SUBROUTINE pseudo_fit(atom_info, wfn_guess, ppot, afun, wtot, pval, dener, wen, ten, init)
1487 TYPE(
atom_p_type),
DIMENSION(:, :),
POINTER :: atom_info
1488 TYPE(wfn_init),
DIMENSION(:, :),
POINTER :: wfn_guess
1490 REAL(
dp),
INTENT(OUT) :: afun
1491 REAL(
dp),
INTENT(IN) :: wtot
1492 REAL(
dp),
DIMENSION(:, :, 0:, :, :),
INTENT(INOUT) :: pval
1493 REAL(
dp),
DIMENSION(:, :, :, :, :),
INTENT(INOUT) :: dener
1494 REAL(
dp),
INTENT(IN) :: wen, ten
1495 LOGICAL,
INTENT(IN) :: init
1497 INTEGER :: i, i1, i2, j, j1, j2, k, l, n, node
1498 LOGICAL :: converged, noguess, shift
1499 REAL(kind=
dp) :: charge, de, fde, pv, rcov, rcov1, rcov2, &
1506 dener(1, :, :, :, :) = 0._dp
1508 noguess = .NOT. init
1510 pp_int => atom_info(1, 1)%atom%integrals
1514 DO i = 1,
SIZE(atom_info, 1)
1515 DO j = 1,
SIZE(atom_info, 2)
1516 atom => atom_info(i, j)%atom
1519 atom%orbitals%wfn = wfn_guess(i, j)%wfn
1523 IF (.NOT. converged)
THEN
1525 IF (.NOT. shift)
THEN
1526 atom%orbitals%ener(:, :) = 1.5_dp*
atom%orbitals%ener(:, :) + 0.5_dp
1529 dener(1, j, j, i, i) =
atom%energy%etot
1530 DO l = 0,
atom%state%maxl_calc
1531 n =
atom%state%maxn_calc(l)
1533 IF (
atom%state%multiplicity == -1)
THEN
1535 rcov =
atom%orbitals%rcmax(k, l, 1)
1536 tv =
atom%orbitals%crefene(k, l, 1)
1537 de = abs(
atom%orbitals%ener(k, l) -
atom%orbitals%refene(k, l, 1))
1538 fde = get_error_value(de, tv)
1539 IF (fde < 1.e-8) pval(5, k, l, j, i) = 1._dp
1540 pv =
atom%weight*
atom%orbitals%wrefene(k, l, 1)*fde
1542 pval(1, k, l, j, i) = pv
1543 IF (
atom%orbitals%wrefchg(k, l, 1) > 0._dp)
THEN
1545 de = abs(charge -
atom%orbitals%refchg(k, l, 1))
1546 fde = get_error_value(de, 25._dp*tv)
1547 IF (fde < 1.e-8) pval(6, k, l, j, i) = 1._dp
1548 pv =
atom%weight*
atom%orbitals%wrefchg(k, l, 1)*fde
1550 pval(2, k, l, j, i) = pv
1552 IF (
atom%orbitals%wrefnod(k, l, 1) > 0._dp)
THEN
1554 afun = afun +
atom%weight*
atom%orbitals%wrefnod(k, l, 1)* &
1555 abs(real(node,
dp) -
atom%orbitals%refnod(k, l, 1))
1558 IF (
atom%orbitals%wpsir0(k, 1) > 0._dp)
THEN
1560 IF (abs(
atom%orbitals%tpsir0(k, 1)) > 1.e-14_dp)
THEN
1561 IF (abs(pv) > abs(
atom%orbitals%tpsir0(k, 1)))
THEN
1564 pv = 10._dp*(abs(pv) - abs(
atom%orbitals%tpsir0(k, 1)))
1566 pv =
atom%weight*
atom%orbitals%wpsir0(k, 1)*pv*pv
1568 pv =
atom%weight*
atom%orbitals%wpsir0(k, 1)*pv*pv*100._dp
1575 rcov1 =
atom%orbitals%rcmax(k, l, 1)
1576 rcov2 =
atom%orbitals%rcmax(k, l, 2)
1577 tv =
atom%orbitals%crefene(k, l, 1)
1578 de = abs(
atom%orbitals%enera(k, l) -
atom%orbitals%refene(k, l, 1))
1579 fde = get_error_value(de, tv)
1580 IF (fde < 1.e-8) pval(5, k, l, j, i) = 1._dp
1581 pv =
atom%weight*
atom%orbitals%wrefene(k, l, 1)*fde
1583 pval(1, k, l, j, i) = pv
1584 tv =
atom%orbitals%crefene(k, l, 2)
1585 de = abs(
atom%orbitals%enerb(k, l) -
atom%orbitals%refene(k, l, 2))
1586 fde = get_error_value(de, tv)
1587 IF (fde < 1.e-8) pval(7, k, l, j, i) = 1._dp
1588 pv =
atom%weight*
atom%orbitals%wrefene(k, l, 2)*fde
1590 pval(3, k, l, j, i) = pv
1591 IF (
atom%orbitals%wrefchg(k, l, 1) > 0._dp)
THEN
1593 de = abs(charge -
atom%orbitals%refchg(k, l, 1))
1594 fde = get_error_value(de, 25._dp*tv)
1595 IF (fde < 1.e-8) pval(6, k, l, j, i) = 1._dp
1596 pv =
atom%weight*
atom%orbitals%wrefchg(k, l, 1)*fde
1598 pval(2, k, l, j, i) = pv
1600 IF (
atom%orbitals%wrefchg(k, l, 2) > 0._dp)
THEN
1602 de = abs(charge -
atom%orbitals%refchg(k, l, 2))
1603 fde = get_error_value(de, 25._dp*tv)
1604 IF (fde < 1.e-8) pval(8, k, l, j, i) = 1._dp
1605 pv =
atom%weight*
atom%orbitals%wrefchg(k, l, 2)*fde
1607 pval(4, k, l, j, i) = pv
1609 IF (
atom%orbitals%wrefnod(k, l, 1) > 0._dp)
THEN
1611 afun = afun +
atom%weight*
atom%orbitals%wrefnod(k, l, 1)* &
1612 abs(real(node,
dp) -
atom%orbitals%refnod(k, l, 1))
1614 IF (
atom%orbitals%wrefnod(k, l, 2) > 0._dp)
THEN
1616 afun = afun +
atom%weight*
atom%orbitals%wrefnod(k, l, 2)* &
1617 abs(real(node,
dp) -
atom%orbitals%refnod(k, l, 2))
1620 IF (
atom%orbitals%wpsir0(k, 1) > 0._dp)
THEN
1622 IF (abs(
atom%orbitals%tpsir0(k, 1)) > 1.e-14_dp)
THEN
1623 IF (abs(pv) > abs(
atom%orbitals%tpsir0(k, 1)))
THEN
1626 pv = 10._dp*(abs(pv) - abs(
atom%orbitals%tpsir0(k, 1)))
1628 pv =
atom%weight*
atom%orbitals%wpsir0(k, 1)*pv*pv
1630 pv =
atom%weight*
atom%orbitals%wpsir0(k, 1)*pv*pv*100._dp
1634 IF (
atom%orbitals%wpsir0(k, 2) > 0._dp)
THEN
1636 IF (abs(
atom%orbitals%tpsir0(k, 2)) > 1.e-14_dp)
THEN
1637 IF (abs(pv) > abs(
atom%orbitals%tpsir0(k, 2)))
THEN
1640 pv = 10._dp*(abs(pv) - abs(
atom%orbitals%tpsir0(k, 2)))
1642 pv =
atom%weight*
atom%orbitals%wpsir0(k, 2)*pv*pv
1644 pv =
atom%weight*
atom%orbitals%wpsir0(k, 2)*pv*pv*100._dp
1657 DO j1 = 1,
SIZE(atom_info, 2)
1658 DO j2 = 1,
SIZE(atom_info, 2)
1659 DO i1 = 1,
SIZE(atom_info, 1)
1660 DO i2 = i1 + 1,
SIZE(atom_info, 1)
1661 IF ((j1 > j2) .OR. (j1 == j2 .AND. i1 >= i2)) cycle
1662 dener(1, j1, j2, i1, i2) = dener(1, j1, j1, i1, i1) - dener(1, j2, j2, i2, i2)
1663 de = abs(dener(2, j1, j2, i1, i2) - dener(1, j1, j2, i1, i2))
1664 fde = get_error_value(de, ten)
1665 afun = afun + wen*fde
1674 END SUBROUTINE pseudo_fit
1681 FUNCTION get_error_value(fval, ftarget)
RESULT(errval)
1682 REAL(kind=
dp),
INTENT(in) :: fval, ftarget
1683 REAL(kind=
dp) :: errval
1685 cpassert(fval >= 0.0_dp)
1687 IF (fval <= ftarget)
THEN
1690 errval = (fval - ftarget)/max(ftarget, 1.e-10_dp)
1691 errval = errval*errval
1694 END FUNCTION get_error_value
1702 SUBROUTINE get_pseudo_param(pvec, nval, gthpot, noopt_nlcc)
1703 REAL(kind=
dp),
DIMENSION(:),
INTENT(out) :: pvec
1704 INTEGER,
INTENT(out) :: nval
1706 LOGICAL,
INTENT(in) :: noopt_nlcc
1708 INTEGER :: i, ival, j, l, n
1710 IF (gthpot%lsdpot)
THEN
1713 DO j = 1, gthpot%nexp_lsd
1715 pvec(ival) = rcpro(-1, gthpot%alpha_lsd(j))
1716 DO i = 1, gthpot%nct_lsd(j)
1718 pvec(ival) = gthpot%cval_lsd(i, j)
1724 pvec(ival) = rcpro(-1, gthpot%rc)
1725 DO i = 1, gthpot%ncl
1727 pvec(ival) = gthpot%cl(i)
1729 IF (gthpot%lpotextended)
THEN
1730 DO j = 1, gthpot%nexp_lpot
1732 pvec(ival) = rcpro(-1, gthpot%alpha_lpot(j))
1733 DO i = 1, gthpot%nct_lpot(j)
1735 pvec(ival) = gthpot%cval_lpot(i, j)
1739 IF (gthpot%nlcc .AND. (.NOT. noopt_nlcc))
THEN
1740 DO j = 1, gthpot%nexp_nlcc
1742 pvec(ival) = rcpro(-1, gthpot%alpha_nlcc(j))
1743 DO i = 1, gthpot%nct_nlcc(j)
1745 pvec(ival) = gthpot%cval_nlcc(i, j)
1750 IF (gthpot%nl(l) > 0)
THEN
1752 pvec(ival) = rcpro(-1, gthpot%rcnl(l))
1756 IF (gthpot%nl(l) > 0)
THEN
1761 pvec(ival) = gthpot%hnl(i, j, l)
1769 END SUBROUTINE get_pseudo_param
1777 SUBROUTINE put_pseudo_param(pvec, gthpot, noopt_nlcc)
1778 REAL(kind=
dp),
DIMENSION(:),
INTENT(in) :: pvec
1780 LOGICAL,
INTENT(in) :: noopt_nlcc
1782 INTEGER :: i, ival, j, l, n
1784 IF (gthpot%lsdpot)
THEN
1786 DO j = 1, gthpot%nexp_lsd
1788 gthpot%alpha_lsd(j) = rcpro(1, pvec(ival))
1789 DO i = 1, gthpot%nct_lsd(j)
1791 gthpot%cval_lsd(i, j) = pvec(ival)
1796 gthpot%rc = rcpro(1, pvec(ival))
1797 DO i = 1, gthpot%ncl
1799 gthpot%cl(i) = pvec(ival)
1801 IF (gthpot%lpotextended)
THEN
1802 DO j = 1, gthpot%nexp_lpot
1804 gthpot%alpha_lpot(j) = rcpro(1, pvec(ival))
1805 DO i = 1, gthpot%nct_lpot(j)
1807 gthpot%cval_lpot(i, j) = pvec(ival)
1811 IF (gthpot%nlcc .AND. (.NOT. noopt_nlcc))
THEN
1812 DO j = 1, gthpot%nexp_nlcc
1814 gthpot%alpha_nlcc(j) = rcpro(1, pvec(ival))
1815 DO i = 1, gthpot%nct_nlcc(j)
1817 gthpot%cval_nlcc(i, j) = pvec(ival)
1822 IF (gthpot%nl(l) > 0)
THEN
1824 gthpot%rcnl(l) = rcpro(1, pvec(ival))
1828 IF (gthpot%nl(l) > 0)
THEN
1833 gthpot%hnl(i, j, l) = pvec(ival)
1840 END SUBROUTINE put_pseudo_param
1850 FUNCTION rcpro(id, xval)
RESULT(yval)
1851 INTEGER,
INTENT(IN) :: id
1852 REAL(
dp),
INTENT(IN) :: xval
1858 yval = 2.0_dp*tanh(0.1_dp*xval)**2
1859 ELSE IF (id == -1)
THEN
1860 x1 = sqrt(xval/2.0_dp)
1861 cpassert(x1 <= 1._dp)
1862 x2 = 0.5_dp*log((1._dp + x1)/(1._dp - x1))
1880 INTEGER,
INTENT(IN) :: num_gau, num_pol, iunit
1882 REAL(kind=
dp),
DIMENSION(:),
OPTIONAL :: results
1884 REAL(kind=
dp),
PARAMETER :: t23 = 2._dp/3._dp
1886 INTEGER :: i, ig, ip, iw, j, n10
1887 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: x
1888 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: co
1894 cpassert(num_pol*num_gau > 0)
1896 ALLOCATE (co(num_pol + 1, num_gau), x(num_pol*num_gau + num_gau))
1903 atom%state%maxl_occ,
atom%state%maxn_occ)
1906 density%op = t23*(0.3_dp*(3.0_dp*
pi*
pi)**t23)*density%op**t23
1910 ostate%nvar = num_pol*num_gau + num_gau
1912 co(1, i) = 0.5_dp + real(i - 1, kind=
dp)
1914 DO j = 3, num_pol + 1
1918 CALL putvar(x, co, num_pol, num_gau)
1920 IF (
PRESENT(powell_section))
THEN
1925 ostate%rhoend = 1.e-8_dp
1926 ostate%rhobeg = 5.e-2_dp
1927 ostate%maxfun = 1000
1934 WRITE (iunit,
'(/," ",13("*")," Approximated Nonadditive Kinetic Energy Functional ",14("*"))')
1935 WRITE (iunit,
'(" POWELL| Start optimization procedure")')
1941 IF (ostate%state == 2)
THEN
1942 CALL getvar(x, co, num_pol, num_gau)
1943 CALL kgpot_fit(density, num_gau, num_pol, co, ostate%f)
1946 IF (ostate%state == -1)
EXIT
1950 IF (mod(ostate%nf, n10) == 0 .AND. iunit > 0)
THEN
1951 WRITE (iunit,
'(" POWELL| Reached",i4,"% of maximal function calls",T66,G15.7)') &
1952 int(real(ostate%nf,
dp)/real(ostate%maxfun,
dp)*100._dp), ostate%fopt
1959 CALL getvar(x, co, num_pol, num_gau)
1964 WRITE (iunit,
'(" POWELL| Number of function evaluations",T71,I10)') ostate%nf
1965 WRITE (iunit,
'(" POWELL| Final value of function",T61,G20.10)') ostate%fopt
1966 WRITE (iunit,
'(" Optimized local potential of approximated nonadditive kinetic energy functional")')
1968 WRITE (iunit,
'(I2,T15,"Gaussian polynomial expansion",T66,"Rc=",F12.4)') ig, co(1, ig)
1969 WRITE (iunit,
'(T15,"Coefficients",T33,4F12.4)') (co(1 + ip, ig), ip=1, num_pol)
1973 CALL open_file(file_name=
"FIT_RESULT", file_status=
"UNKNOWN", file_action=
"WRITE", unit_number=iw)
1975 WRITE (iw, *) num_gau, num_pol
1977 WRITE (iw,
'(T10,F12.4,6X,4F12.4)') (co(ip, ig), ip=1, num_pol + 1)
1981 IF (
PRESENT(results))
THEN
1982 cpassert(
SIZE(results) >=
SIZE(x))
1998 SUBROUTINE kgpot_fit(kgpot, ng, np, cval, aerr)
2000 INTEGER,
INTENT(IN) :: ng, np
2001 REAL(
dp),
DIMENSION(:, :),
INTENT(INOUT) :: cval
2002 REAL(
dp),
INTENT(OUT) :: aerr
2004 INTEGER :: i, ig, ip, n
2005 REAL(kind=
dp) :: pc, rc
2006 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: pval
2013 rc = kgpot%grid%rad(i)/cval(1, ig)
2016 pc = pc + cval(ip + 1, ig)*rc**(2*ip - 2)
2018 pval(i) = pval(i) + pc*exp(-0.5_dp*rc*rc)
2021 pval(1:n) = (pval(1:n) - kgpot%op(1:n))**2
2022 aerr =
fourpi*sum(pval(1:n)*kgpot%grid%wr(1:n))
2026 END SUBROUTINE kgpot_fit
2035 PURE SUBROUTINE getvar(xvar, cvar, np, ng)
2036 REAL(kind=
dp),
DIMENSION(:),
INTENT(in) :: xvar
2037 REAL(kind=
dp),
DIMENSION(:, :),
INTENT(inout) :: cvar
2038 INTEGER,
INTENT(IN) :: np, ng
2040 INTEGER :: ig, ii, ip
2045 cvar(1, ig) = xvar(ii)
2048 cvar(ip + 1, ig) = xvar(ii)**2
2052 END SUBROUTINE getvar
2061 PURE SUBROUTINE putvar(xvar, cvar, np, ng)
2062 REAL(kind=
dp),
DIMENSION(:),
INTENT(inout) :: xvar
2063 REAL(kind=
dp),
DIMENSION(:, :),
INTENT(in) :: cvar
2064 INTEGER,
INTENT(IN) :: np, ng
2066 INTEGER :: ig, ii, ip
2071 xvar(ii) = cvar(1, ig)
2074 xvar(ii) = sqrt(abs(cvar(ip + 1, ig)))
2078 END SUBROUTINE putvar
subroutine, public calculate_atom(atom, iw, noguess, converged)
General routine to perform electronic structure atomic calculations.
routines that fit parameters for /from atomic calculations
subroutine, public atom_fit_pseudo(atom_info, atom_refs, ppot, iunit, powell_section)
...
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.
subroutine, public atom_fit_kgpot(atom, num_gau, num_pol, iunit, powell_section, results)
...
subroutine, public atom_fit_basis(atom_info, basis, pptype, iunit, powell_section)
...
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).
Routines that print various information about an atomic kind.
subroutine, public atom_print_basis(atom_basis, iw, title)
Print atomic basis set.
subroutine, public atom_print_basis_file(atom_basis, wfn)
Print the optimized atomic basis set into a file.
subroutine, public atom_write_pseudo_param(gthpot, iunit)
Print GTH pseudo-potential parameters.
Define the atom type and its sub types.
integer, parameter, public gto_basis
integer, parameter, public sto_basis
subroutine, public release_opmat(opmat)
...
subroutine, public release_opgrid(opgrid)
...
integer, parameter, public lmat
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 create_opmat(opmat, n, lmax)
...
subroutine, public create_opgrid(opgrid, grid)
...
Some basic routines for atomic calculations.
subroutine, public atom_condnumber(basis, crad, iw)
Print condition numbers of the given atomic basis set.
pure subroutine, public atom_denmat(pmat, wfn, nbas, occ, maxl, maxn)
Calculate a density matrix using atomic orbitals.
pure subroutine, public atom_orbital_charge(charge, wfn, rcov, l, basis)
...
pure logical function, public atom_consistent_method(method, multiplicity)
Check that the atomic multiplicity is consistent with the electronic structure method.
subroutine, public atom_core_density(corden, potential, typ, rr)
...
pure integer function, dimension(0:lmat), public get_maxn_occ(occupation)
Return the maximum principal quantum number of occupied orbitals.
subroutine, public atom_density(density, pmat, basis, maxl, typ, rr)
Map the electron density on an atomic radial grid.
pure subroutine, public atom_orbital_max(rmax, wfn, rcov, l, basis)
...
subroutine, public atom_completeness(basis, zv, iw)
Estimate completeness of the given atomic basis set.
pure subroutine, public atom_orbital_nodes(node, wfn, rcov, l, basis)
...
pure subroutine, public atom_wfnr0(value, wfn, basis)
...
Utility routines to open and close files. Tracking of preconnections.
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.
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.
Defines the basic variable types.
integer, parameter, public dp
Definition of mathematical constants and functions.
real(kind=dp), parameter, public pi
real(kind=dp), parameter, public fourpi
real(kind=dp), dimension(0:maxfac), parameter, public fac
Periodic Table related data definitions.
type(atom), dimension(0:nelem), public ptable
Definition of physical constants:
real(kind=dp), parameter, public evolt
real(kind=dp), parameter, public bohr
subroutine, public powell_optimize(n, x, optstate)
...
Provides all information about a basis set.
Provides all information about a pseudopotential.
Provides all information about an atomic kind.