LCOV - code coverage report
Current view: top level - src - atom_pseudo.F (source / functions) Coverage Total Hit
Test: CP2K Regtests (git:8ebf9ad) Lines: 96.2 % 265 255
Test Date: 2026-01-22 06:43:13 Functions: 100.0 % 1 1

            Line data    Source code
       1              : !--------------------------------------------------------------------------------------------------!
       2              : !   CP2K: A general program to perform molecular dynamics simulations                              !
       3              : !   Copyright 2000-2026 CP2K developers group <https://cp2k.org>                                   !
       4              : !                                                                                                  !
       5              : !   SPDX-License-Identifier: GPL-2.0-or-later                                                      !
       6              : !--------------------------------------------------------------------------------------------------!
       7              : 
       8              : ! **************************************************************************************************
       9              : MODULE atom_pseudo
      10              :    USE atom_electronic_structure,       ONLY: calculate_atom
      11              :    USE atom_fit,                        ONLY: atom_fit_pseudo
      12              :    USE atom_operators,                  ONLY: atom_int_release,&
      13              :                                               atom_int_setup,&
      14              :                                               atom_ppint_release,&
      15              :                                               atom_ppint_setup,&
      16              :                                               atom_relint_release,&
      17              :                                               atom_relint_setup
      18              :    USE atom_output,                     ONLY: atom_print_basis,&
      19              :                                               atom_print_info,&
      20              :                                               atom_print_method,&
      21              :                                               atom_print_orbitals,&
      22              :                                               atom_print_potential
      23              :    USE atom_types,                      ONLY: &
      24              :         atom_basis_type, atom_integrals, atom_optimization_type, atom_orbitals, atom_p_type, &
      25              :         atom_potential_type, atom_state, create_atom_orbs, create_atom_type, init_atom_basis, &
      26              :         init_atom_potential, lmat, read_atom_opt_section, release_atom_basis, &
      27              :         release_atom_potential, release_atom_type, set_atom
      28              :    USE atom_utils,                      ONLY: atom_consistent_method,&
      29              :                                               atom_set_occupation,&
      30              :                                               get_maxl_occ,&
      31              :                                               get_maxn_occ
      32              :    USE cp_log_handling,                 ONLY: cp_get_default_logger,&
      33              :                                               cp_logger_type
      34              :    USE cp_output_handling,              ONLY: cp_print_key_finished_output,&
      35              :                                               cp_print_key_unit_nr
      36              :    USE input_constants,                 ONLY: do_analytic,&
      37              :                                               poly_conf
      38              :    USE input_section_types,             ONLY: section_vals_get,&
      39              :                                               section_vals_get_subs_vals,&
      40              :                                               section_vals_type,&
      41              :                                               section_vals_val_get
      42              :    USE kinds,                           ONLY: default_string_length,&
      43              :                                               dp
      44              :    USE periodic_table,                  ONLY: nelem,&
      45              :                                               ptable
      46              :    USE physcon,                         ONLY: bohr
      47              :    USE string_utilities,                ONLY: uppercase
      48              : #include "./base/base_uses.f90"
      49              : 
      50              :    IMPLICIT NONE
      51              :    PRIVATE
      52              :    PUBLIC  :: atom_pseudo_opt
      53              : 
      54              :    CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'atom_pseudo'
      55              : 
      56              : ! **************************************************************************************************
      57              : 
      58              : CONTAINS
      59              : 
      60              : ! **************************************************************************************************
      61              : 
      62              : ! **************************************************************************************************
      63              : !> \brief ...
      64              : !> \param atom_section ...
      65              : ! **************************************************************************************************
      66           28 :    SUBROUTINE atom_pseudo_opt(atom_section)
      67              :       TYPE(section_vals_type), POINTER                   :: atom_section
      68              : 
      69              :       CHARACTER(len=*), PARAMETER                        :: routineN = 'atom_pseudo_opt'
      70              : 
      71              :       CHARACTER(LEN=2)                                   :: elem, refm
      72              :       CHARACTER(LEN=default_string_length), &
      73           28 :          DIMENSION(:), POINTER                           :: tmpstringlist
      74              :       INTEGER                                            :: ads, do_eric, do_erie, handle, i, im, &
      75              :                                                             in, iw, k, l, maxl, mb, method, mo, &
      76              :                                                             n_meth, n_rep, nr_gh, reltyp, zcore, &
      77              :                                                             zval, zz
      78              :       INTEGER, DIMENSION(0:lmat)                         :: maxn
      79           28 :       INTEGER, DIMENSION(:), POINTER                     :: cn
      80              :       LOGICAL                                            :: do_gh, do_ppref, eri_c, eri_e, explicit, &
      81              :                                                             graph, pp_calc
      82              :       REAL(KIND=dp)                                      :: ne, nm
      83              :       REAL(KIND=dp), DIMENSION(0:lmat, 10)               :: pocc
      84              :       TYPE(atom_basis_type), POINTER                     :: ae_basis, pp_basis
      85              :       TYPE(atom_integrals), POINTER                      :: ae_int, pp_int
      86              :       TYPE(atom_optimization_type)                       :: optimization
      87              :       TYPE(atom_orbitals), POINTER                       :: orbitals
      88           28 :       TYPE(atom_p_type), DIMENSION(:, :), POINTER        :: atom_info, atom_refs
      89              :       TYPE(atom_potential_type), POINTER                 :: ae_pot, p_pot
      90              :       TYPE(atom_state), POINTER                          :: state, statepp, stateref
      91              :       TYPE(cp_logger_type), POINTER                      :: logger
      92              :       TYPE(section_vals_type), POINTER                   :: basis_section, method_section, &
      93              :                                                             opt_section, potential_section, &
      94              :                                                             powell_section, xc_section
      95              : 
      96           28 :       CALL timeset(routineN, handle)
      97              : 
      98              :       ! What atom do we calculate
      99           28 :       CALL section_vals_val_get(atom_section, "ATOMIC_NUMBER", i_val=zval)
     100           28 :       CALL section_vals_val_get(atom_section, "ELEMENT", c_val=elem)
     101           28 :       zz = 0
     102          142 :       DO i = 1, nelem
     103          142 :          IF (ptable(i)%symbol == elem) THEN
     104              :             zz = i
     105              :             EXIT
     106              :          END IF
     107              :       END DO
     108           28 :       IF (zz /= 1) zval = zz
     109              : 
     110              :       ! read and set up information on the basis sets
     111         1036 :       ALLOCATE (ae_basis, pp_basis)
     112           28 :       basis_section => section_vals_get_subs_vals(atom_section, "AE_BASIS")
     113           28 :       NULLIFY (ae_basis%grid)
     114           28 :       CALL init_atom_basis(ae_basis, basis_section, zval, "AA")
     115           28 :       NULLIFY (pp_basis%grid)
     116           28 :       basis_section => section_vals_get_subs_vals(atom_section, "PP_BASIS")
     117           28 :       CALL init_atom_basis(pp_basis, basis_section, zval, "AP")
     118              : 
     119              :       ! print general and basis set information
     120           28 :       logger => cp_get_default_logger()
     121           28 :       iw = cp_print_key_unit_nr(logger, atom_section, "PRINT%PROGRAM_BANNER", extension=".log")
     122           28 :       IF (iw > 0) CALL atom_print_info(zval, "Atomic Energy Calculation", iw)
     123           28 :       CALL cp_print_key_finished_output(iw, logger, atom_section, "PRINT%PROGRAM_BANNER")
     124           28 :       iw = cp_print_key_unit_nr(logger, atom_section, "PRINT%BASIS_SET", extension=".log")
     125           28 :       IF (iw > 0) THEN
     126            8 :          CALL atom_print_basis(ae_basis, iw, " All Electron/Reference Basis")
     127            8 :          CALL atom_print_basis(pp_basis, iw, " Pseudopotential Basis")
     128              :       END IF
     129           28 :       CALL cp_print_key_finished_output(iw, logger, atom_section, "PRINT%BASIS_SET")
     130              : 
     131              :       ! check on the reference method
     132           28 :       CALL section_vals_val_get(atom_section, "REFERENCE%METHOD", c_val=refm)
     133           28 :       CALL uppercase(refm)
     134           28 :       do_ppref = (refm == "PP")
     135              : 
     136              :       ! read and setup information on the pseudopotential
     137           28 :       NULLIFY (potential_section)
     138           28 :       potential_section => section_vals_get_subs_vals(atom_section, "POTENTIAL")
     139       301196 :       ALLOCATE (ae_pot, p_pot)
     140           28 :       CALL init_atom_potential(p_pot, potential_section, zval)
     141           28 :       IF (do_ppref) THEN
     142            2 :          potential_section => section_vals_get_subs_vals(atom_section, "REFERENCE%POTENTIAL")
     143            2 :          CALL section_vals_get(potential_section, explicit=explicit)
     144            2 :          CPASSERT(explicit)
     145            2 :          CALL init_atom_potential(ae_pot, potential_section, zval)
     146              :       ELSE
     147           26 :          CALL init_atom_potential(ae_pot, potential_section, -1)
     148              :       END IF
     149           28 :       IF (.NOT. p_pot%confinement .AND. .NOT. ae_pot%confinement) THEN
     150              :          !set default confinement potential
     151           24 :          p_pot%confinement = .TRUE.
     152           24 :          p_pot%conf_type = poly_conf
     153           24 :          p_pot%scon = 2.0_dp
     154           24 :          p_pot%acon = 0.5_dp
     155              :          ! this seems to be the default in the old code
     156           24 :          p_pot%rcon = (2._dp*ptable(zval)%covalent_radius*bohr)**2
     157           24 :          ae_pot%confinement = .TRUE.
     158           24 :          ae_pot%conf_type = poly_conf
     159           24 :          ae_pot%scon = 2.0_dp
     160           24 :          ae_pot%acon = 0.5_dp
     161              :          ! this seems to be the default in the old code
     162           24 :          ae_pot%rcon = (2._dp*ptable(zval)%covalent_radius*bohr)**2
     163              :       END IF
     164              : 
     165              :       ! if the ERI's are calculated analytically, we have to precalculate them
     166           28 :       eri_c = .FALSE.
     167           28 :       CALL section_vals_val_get(atom_section, "COULOMB_INTEGRALS", i_val=do_eric)
     168           28 :       IF (do_eric == do_analytic) eri_c = .TRUE.
     169           28 :       eri_e = .FALSE.
     170           28 :       CALL section_vals_val_get(atom_section, "EXCHANGE_INTEGRALS", i_val=do_erie)
     171           28 :       IF (do_erie == do_analytic) eri_e = .TRUE.
     172           28 :       CALL section_vals_val_get(atom_section, "USE_GAUSS_HERMITE", l_val=do_gh)
     173           28 :       CALL section_vals_val_get(atom_section, "GRID_POINTS_GH", i_val=nr_gh)
     174              : 
     175              :       ! information on the states to be calculated
     176           28 :       CALL section_vals_val_get(atom_section, "MAX_ANGULAR_MOMENTUM", i_val=maxl)
     177           28 :       maxn = 0
     178           28 :       CALL section_vals_val_get(atom_section, "CALCULATE_STATES", i_vals=cn)
     179           56 :       DO in = 1, MIN(SIZE(cn), 4)
     180           56 :          maxn(in - 1) = cn(in)
     181              :       END DO
     182          196 :       DO in = 0, lmat
     183          196 :          maxn(in) = MIN(maxn(in), ae_basis%nbas(in))
     184              :       END DO
     185              : 
     186              :       ! read optimization section
     187           28 :       opt_section => section_vals_get_subs_vals(atom_section, "OPTIMIZATION")
     188           28 :       CALL read_atom_opt_section(optimization, opt_section)
     189              : 
     190              :       ! Check for the total number of electron configurations to be calculated
     191           28 :       CALL section_vals_val_get(atom_section, "ELECTRON_CONFIGURATION", n_rep_val=n_rep)
     192              :       ! Check for the total number of method types to be calculated
     193           28 :       method_section => section_vals_get_subs_vals(atom_section, "METHOD")
     194           28 :       CALL section_vals_get(method_section, n_repetition=n_meth)
     195              : 
     196              :       ! integrals
     197        11900 :       ALLOCATE (ae_int, pp_int)
     198              : 
     199          280 :       ALLOCATE (atom_info(n_rep, n_meth), atom_refs(n_rep, n_meth))
     200              : 
     201           28 :       iw = cp_print_key_unit_nr(logger, atom_section, "PRINT%PROGRAM_BANNER", extension=".log")
     202           28 :       IF (iw > 0) THEN
     203           14 :          WRITE (iw, '(/," ",79("*"))')
     204           14 :          WRITE (iw, '(" ",26("*"),A,25("*"))') " Calculate Reference States "
     205           14 :          WRITE (iw, '(" ",79("*"))')
     206              :       END IF
     207           28 :       CALL cp_print_key_finished_output(iw, logger, atom_section, "PRINT%PROGRAM_BANNER")
     208              : 
     209           56 :       DO in = 1, n_rep
     210           84 :          DO im = 1, n_meth
     211              : 
     212           28 :             NULLIFY (atom_info(in, im)%atom, atom_refs(in, im)%atom)
     213           28 :             CALL create_atom_type(atom_info(in, im)%atom)
     214           28 :             CALL create_atom_type(atom_refs(in, im)%atom)
     215              : 
     216           28 :             atom_info(in, im)%atom%optimization = optimization
     217           28 :             atom_refs(in, im)%atom%optimization = optimization
     218              : 
     219           28 :             atom_info(in, im)%atom%z = zval
     220           28 :             atom_refs(in, im)%atom%z = zval
     221           28 :             xc_section => section_vals_get_subs_vals(method_section, "XC", i_rep_section=im)
     222           28 :             atom_info(in, im)%atom%xc_section => xc_section
     223           28 :             atom_refs(in, im)%atom%xc_section => xc_section
     224              : 
     225        30436 :             ALLOCATE (state, statepp, stateref)
     226              : 
     227              :             ! get the electronic configuration
     228              :             CALL section_vals_val_get(atom_section, "ELECTRON_CONFIGURATION", i_rep_val=in, &
     229           28 :                                       c_vals=tmpstringlist)
     230              :             ! all electron configurations have to be with full core
     231           28 :             pp_calc = INDEX(tmpstringlist(1), "CORE") /= 0
     232           28 :             CPASSERT(.NOT. pp_calc)
     233              : 
     234              :             ! set occupations for the full electronic configuration
     235           28 :             CALL atom_set_occupation(tmpstringlist, state%occ, state%occupation, state%multiplicity)
     236           28 :             state%maxl_occ = get_maxl_occ(state%occ)
     237          196 :             state%maxn_occ = get_maxn_occ(state%occ)
     238              :             ! set number of states to be calculated
     239           28 :             state%maxl_calc = MAX(maxl, state%maxl_occ)
     240           28 :             state%maxl_calc = MIN(lmat, state%maxl_calc)
     241          196 :             state%maxn_calc = 0
     242          102 :             DO k = 0, state%maxl_calc
     243           74 :                ads = 2
     244           74 :                IF (state%maxn_occ(k) == 0) ads = 1
     245           74 :                state%maxn_calc(k) = MAX(maxn(k), state%maxn_occ(k) + ads)
     246          102 :                state%maxn_calc(k) = MIN(state%maxn_calc(k), ae_basis%nbas(k))
     247              :             END DO
     248         1988 :             state%core = 0._dp
     249              : 
     250           28 :             IF (state%multiplicity /= -1) THEN
     251              :                ! set alpha and beta occupations
     252          142 :                state%occa = 0._dp
     253          142 :                state%occb = 0._dp
     254           14 :                DO l = 0, lmat
     255           12 :                   nm = REAL((2*l + 1), KIND=dp)
     256           20 :                   DO k = 1, 10
     257           18 :                      ne = state%occupation(l, k)
     258           18 :                      IF (ne == 0._dp) THEN !empty shell
     259              :                         EXIT !assume there are no holes
     260            6 :                      ELSEIF (ne == 2._dp*nm) THEN !closed shell
     261            4 :                         state%occa(l, k) = nm
     262            4 :                         state%occb(l, k) = nm
     263            2 :                      ELSEIF (state%multiplicity == -2) THEN !High spin case
     264            0 :                         state%occa(l, k) = MIN(ne, nm)
     265            0 :                         state%occb(l, k) = MAX(0._dp, ne - nm)
     266              :                      ELSE
     267            2 :                         state%occa(l, k) = 0.5_dp*(ne + state%multiplicity - 1._dp)
     268            2 :                         state%occb(l, k) = ne - state%occa(l, k)
     269              :                      END IF
     270              :                   END DO
     271              :                END DO
     272              :             END IF
     273              : 
     274              :             ! set occupations for reference calculation
     275           28 :             IF (do_ppref) THEN
     276            2 :                CALL section_vals_val_get(atom_section, "REFERENCE%CORE", explicit=explicit)
     277            2 :                IF (explicit) THEN
     278            0 :                   CALL section_vals_val_get(atom_section, "REFERENCE%CORE", c_vals=tmpstringlist)
     279              :                ELSE
     280            2 :                   CALL section_vals_val_get(atom_section, "CORE", c_vals=tmpstringlist)
     281              :                END IF
     282            2 :                CALL atom_set_occupation(tmpstringlist, stateref%core, pocc)
     283          142 :                zcore = zval - NINT(SUM(stateref%core))
     284            2 :                CALL set_atom(atom_refs(in, im)%atom, zcore=zcore, pp_calc=.TRUE.)
     285              : 
     286          282 :                stateref%occ = state%occ - stateref%core
     287          142 :                stateref%occupation = 0._dp
     288           14 :                DO l = 0, lmat
     289              :                   k = 0
     290          134 :                   DO i = 1, 10
     291          132 :                      IF (stateref%occ(l, i) /= 0._dp) THEN
     292            2 :                         k = k + 1
     293            2 :                         stateref%occupation(l, k) = state%occ(l, i)
     294            2 :                         IF (state%multiplicity /= -1) THEN
     295            0 :                            stateref%occa(l, k) = state%occa(l, i) - stateref%core(l, i)/2
     296            0 :                            stateref%occb(l, k) = state%occb(l, i) - stateref%core(l, i)/2
     297              :                         END IF
     298              :                      END IF
     299              :                   END DO
     300              :                END DO
     301              : 
     302            2 :                stateref%maxl_occ = get_maxl_occ(stateref%occ)
     303           14 :                stateref%maxn_occ = get_maxn_occ(stateref%occ)
     304            2 :                stateref%maxl_calc = state%maxl_calc
     305           14 :                stateref%maxn_calc = 0
     306            2 :                maxn = get_maxn_occ(stateref%core)
     307            6 :                DO k = 0, stateref%maxl_calc
     308            4 :                   stateref%maxn_calc(k) = state%maxn_calc(k) - maxn(k)
     309            6 :                   stateref%maxn_calc(k) = MIN(stateref%maxn_calc(k), ae_basis%nbas(k))
     310              :                END DO
     311            2 :                stateref%multiplicity = state%multiplicity
     312              : 
     313              :             ELSE
     314              : 
     315           26 :                stateref = state
     316           26 :                CALL set_atom(atom_refs(in, im)%atom, zcore=zval, pp_calc=.FALSE.)
     317              : 
     318              :             END IF
     319              : 
     320              :             ! set occupations for pseudopotential calculation
     321           28 :             CALL section_vals_val_get(atom_section, "CORE", c_vals=tmpstringlist)
     322           28 :             CALL atom_set_occupation(tmpstringlist, statepp%core, pocc)
     323         1988 :             zcore = zval - NINT(SUM(statepp%core))
     324           28 :             CALL set_atom(atom_info(in, im)%atom, zcore=zcore, pp_calc=.TRUE.)
     325              : 
     326         3948 :             statepp%occ = state%occ - statepp%core
     327         1988 :             statepp%occupation = 0._dp
     328          196 :             DO l = 0, lmat
     329              :                k = 0
     330         1876 :                DO i = 1, 10
     331         1848 :                   IF (statepp%occ(l, i) /= 0._dp) THEN
     332           48 :                      k = k + 1
     333           48 :                      statepp%occupation(l, k) = state%occ(l, i)
     334           48 :                      IF (state%multiplicity /= -1) THEN
     335            4 :                         statepp%occa(l, k) = state%occa(l, i) - statepp%core(l, i)/2
     336            4 :                         statepp%occb(l, k) = state%occb(l, i) - statepp%core(l, i)/2
     337              :                      END IF
     338              :                   END IF
     339              :                END DO
     340              :             END DO
     341              : 
     342           28 :             statepp%maxl_occ = get_maxl_occ(statepp%occ)
     343          196 :             statepp%maxn_occ = get_maxn_occ(statepp%occ)
     344           28 :             statepp%maxl_calc = state%maxl_calc
     345          196 :             statepp%maxn_calc = 0
     346           28 :             maxn = get_maxn_occ(statepp%core)
     347          102 :             DO k = 0, statepp%maxl_calc
     348           74 :                statepp%maxn_calc(k) = state%maxn_calc(k) - maxn(k)
     349          102 :                statepp%maxn_calc(k) = MIN(statepp%maxn_calc(k), pp_basis%nbas(k))
     350              :             END DO
     351           28 :             statepp%multiplicity = state%multiplicity
     352              : 
     353           28 :             CALL section_vals_val_get(method_section, "METHOD_TYPE", i_val=method, i_rep_section=im)
     354           28 :             CALL section_vals_val_get(method_section, "RELATIVISTIC", i_val=reltyp, i_rep_section=im)
     355           28 :             CALL set_atom(atom_info(in, im)%atom, method_type=method)
     356           28 :             IF (do_ppref) THEN
     357            2 :                CALL set_atom(atom_refs(in, im)%atom, method_type=method)
     358              :             ELSE
     359           26 :                CALL set_atom(atom_refs(in, im)%atom, method_type=method, relativistic=reltyp)
     360              :             END IF
     361              : 
     362              :             ! calculate integrals: pseudopotential basis
     363              :             ! general integrals
     364           28 :             CALL atom_int_setup(pp_int, pp_basis, potential=p_pot, eri_coulomb=eri_c, eri_exchange=eri_e)
     365              :             !
     366           28 :             NULLIFY (pp_int%tzora, pp_int%hdkh)
     367              :             ! potential
     368           28 :             CALL atom_ppint_setup(pp_int, pp_basis, potential=p_pot)
     369              :             !
     370           28 :             CALL set_atom(atom_info(in, im)%atom, basis=pp_basis, integrals=pp_int, potential=p_pot)
     371          364 :             statepp%maxn_calc(:) = MIN(statepp%maxn_calc(:), pp_basis%nbas(:))
     372          196 :             CPASSERT(ALL(state%maxn_calc(:) >= state%maxn_occ))
     373              : 
     374              :             ! calculate integrals: all electron basis
     375              :             ! general integrals
     376              :             CALL atom_int_setup(ae_int, ae_basis, potential=ae_pot, &
     377           28 :                                 eri_coulomb=eri_c, eri_exchange=eri_e)
     378              :             ! potential
     379           28 :             CALL atom_ppint_setup(ae_int, ae_basis, potential=ae_pot)
     380           28 :             IF (do_ppref) THEN
     381            2 :                NULLIFY (ae_int%tzora, ae_int%hdkh)
     382              :             ELSE
     383              :                ! relativistic correction terms
     384           26 :                CALL atom_relint_setup(ae_int, ae_basis, reltyp, zcore=REAL(zval, dp))
     385              :             END IF
     386              :             !
     387           28 :             CALL set_atom(atom_refs(in, im)%atom, basis=ae_basis, integrals=ae_int, potential=ae_pot)
     388          364 :             stateref%maxn_calc(:) = MIN(stateref%maxn_calc(:), ae_basis%nbas(:))
     389          196 :             CPASSERT(ALL(stateref%maxn_calc(:) >= stateref%maxn_occ))
     390              : 
     391              :             CALL set_atom(atom_info(in, im)%atom, coulomb_integral_type=do_eric, &
     392           28 :                           exchange_integral_type=do_erie)
     393              :             CALL set_atom(atom_refs(in, im)%atom, coulomb_integral_type=do_eric, &
     394           28 :                           exchange_integral_type=do_erie)
     395           28 :             atom_info(in, im)%atom%hfx_pot%do_gh = do_gh
     396           28 :             atom_info(in, im)%atom%hfx_pot%nr_gh = nr_gh
     397           28 :             atom_refs(in, im)%atom%hfx_pot%do_gh = do_gh
     398           28 :             atom_refs(in, im)%atom%hfx_pot%nr_gh = nr_gh
     399              : 
     400           28 :             CALL set_atom(atom_info(in, im)%atom, state=statepp)
     401           28 :             NULLIFY (orbitals)
     402          196 :             mo = MAXVAL(statepp%maxn_calc)
     403          196 :             mb = MAXVAL(atom_info(in, im)%atom%basis%nbas)
     404           28 :             CALL create_atom_orbs(orbitals, mb, mo)
     405           28 :             CALL set_atom(atom_info(in, im)%atom, orbitals=orbitals)
     406              : 
     407           28 :             CALL set_atom(atom_refs(in, im)%atom, state=stateref)
     408           28 :             NULLIFY (orbitals)
     409          196 :             mo = MAXVAL(stateref%maxn_calc)
     410          196 :             mb = MAXVAL(atom_refs(in, im)%atom%basis%nbas)
     411           28 :             CALL create_atom_orbs(orbitals, mb, mo)
     412           28 :             CALL set_atom(atom_refs(in, im)%atom, orbitals=orbitals)
     413              : 
     414           28 :             IF (atom_consistent_method(atom_refs(in, im)%atom%method_type, atom_refs(in, im)%atom%state%multiplicity)) THEN
     415              :                !Print method info
     416           28 :                iw = cp_print_key_unit_nr(logger, atom_section, "PRINT%METHOD_INFO", extension=".log")
     417           28 :                CALL atom_print_method(atom_refs(in, im)%atom, iw)
     418           28 :                CALL cp_print_key_finished_output(iw, logger, atom_section, "PRINT%METHOD_INFO")
     419              :                !Calculate the electronic structure
     420           28 :                iw = cp_print_key_unit_nr(logger, atom_section, "PRINT%SCF_INFO", extension=".log")
     421           28 :                CALL calculate_atom(atom_refs(in, im)%atom, iw)
     422           28 :                CALL cp_print_key_finished_output(iw, logger, atom_section, "PRINT%SCF_INFO")
     423              :             END IF
     424           84 :             DEALLOCATE (state)
     425              :          END DO
     426              :       END DO
     427              : 
     428           28 :       iw = cp_print_key_unit_nr(logger, atom_section, "PRINT%FIT_PSEUDO", extension=".log")
     429           28 :       IF (iw > 0) THEN
     430           14 :          WRITE (iw, '(/," ",79("*"))')
     431           14 :          WRITE (iw, '(" ",21("*"),A,21("*"))') " Optimize Pseudopotential Parameters "
     432           14 :          WRITE (iw, '(" ",79("*"))')
     433              :       END IF
     434           28 :       CALL cp_print_key_finished_output(iw, logger, atom_section, "PRINT%FIT_PSEUDO")
     435           28 :       iw = cp_print_key_unit_nr(logger, atom_section, "PRINT%POTENTIAL", extension=".log")
     436           28 :       IF (iw > 0) THEN
     437            0 :          CALL atom_print_potential(p_pot, iw)
     438              :       END IF
     439           28 :       CALL cp_print_key_finished_output(iw, logger, atom_section, "PRINT%POTENTIAL")
     440           28 :       iw = cp_print_key_unit_nr(logger, atom_section, "PRINT%FIT_PSEUDO", extension=".log")
     441           28 :       IF (iw > 0) THEN
     442           14 :          powell_section => section_vals_get_subs_vals(atom_section, "POWELL")
     443           14 :          CALL atom_fit_pseudo(atom_info, atom_refs, p_pot, iw, powell_section)
     444              :       END IF
     445           28 :       CALL cp_print_key_finished_output(iw, logger, atom_section, "PRINT%FIT_PSEUDO")
     446           28 :       iw = cp_print_key_unit_nr(logger, atom_section, "PRINT%POTENTIAL", extension=".log")
     447           28 :       IF (iw > 0) THEN
     448            0 :          CALL atom_print_potential(p_pot, iw)
     449              :       END IF
     450           28 :       CALL cp_print_key_finished_output(iw, logger, atom_section, "PRINT%POTENTIAL")
     451              : 
     452              :       ! Print out the orbitals if requested
     453           28 :       iw = cp_print_key_unit_nr(logger, atom_section, "PRINT%ORBITALS", extension=".log")
     454           28 :       CALL section_vals_val_get(atom_section, "PRINT%ORBITALS%XMGRACE", l_val=graph)
     455           28 :       IF (iw > 0) THEN
     456            0 :          DO in = 1, n_rep
     457            0 :             DO im = 1, n_meth
     458            0 :                CALL atom_print_orbitals(atom_info(in, im)%atom, iw, xmgrace=graph)
     459              :             END DO
     460              :          END DO
     461              :       END IF
     462           28 :       CALL cp_print_key_finished_output(iw, logger, atom_section, "PRINT%ORBITALS")
     463              : 
     464              :       ! clean up
     465           28 :       CALL atom_int_release(ae_int)
     466           28 :       CALL atom_ppint_release(ae_int)
     467           28 :       CALL atom_relint_release(ae_int)
     468              : 
     469           28 :       CALL atom_int_release(pp_int)
     470           28 :       CALL atom_ppint_release(pp_int)
     471           28 :       CALL atom_relint_release(pp_int)
     472              : 
     473           28 :       CALL release_atom_basis(ae_basis)
     474           28 :       CALL release_atom_basis(pp_basis)
     475              : 
     476           28 :       CALL release_atom_potential(p_pot)
     477           28 :       CALL release_atom_potential(ae_pot)
     478              : 
     479           56 :       DO in = 1, n_rep
     480           84 :          DO im = 1, n_meth
     481           28 :             CALL release_atom_type(atom_info(in, im)%atom)
     482           56 :             CALL release_atom_type(atom_refs(in, im)%atom)
     483              :          END DO
     484              :       END DO
     485           28 :       DEALLOCATE (atom_info, atom_refs)
     486              : 
     487           28 :       DEALLOCATE (ae_pot, p_pot, ae_basis, pp_basis, ae_int, pp_int)
     488              : 
     489           28 :       CALL timestop(handle)
     490              : 
     491          196 :    END SUBROUTINE atom_pseudo_opt
     492              : 
     493              : ! **************************************************************************************************
     494              : 
     495              : END MODULE atom_pseudo
        

Generated by: LCOV version 2.0-1