LCOV - code coverage report
Current view: top level - src/subsys - external_potential_types.F (source / functions) Hit Total Coverage
Test: CP2K Regtests (git:20fe009) Lines: 1103 1359 81.2 %
Date: 2022-07-05 19:56:53 Functions: 34 45 75.6 %

          Line data    Source code
       1             : !--------------------------------------------------------------------------------------------------!
       2             : !   CP2K: A general program to perform molecular dynamics simulations                              !
       3             : !   Copyright 2000-2022 CP2K developers group <https://cp2k.org>                                   !
       4             : !                                                                                                  !
       5             : !   SPDX-License-Identifier: GPL-2.0-or-later                                                      !
       6             : !--------------------------------------------------------------------------------------------------!
       7             : 
       8             : ! **************************************************************************************************
       9             : !> \brief Definition of the atomic potential types.
      10             : !> \par History
      11             : !>      GT, 22.09.2002: added elp_potential_types
      12             : !> \author Matthias Krack (04.07.2000)
      13             : ! **************************************************************************************************
      14             : MODULE external_potential_types
      15             :    USE ao_util,                         ONLY: exp_radius
      16             :    USE bibliography,                    ONLY: Goedecker1996,&
      17             :                                               Hartwigsen1998,&
      18             :                                               Krack2000,&
      19             :                                               Krack2005,&
      20             :                                               cite_reference
      21             :    USE cp_linked_list_input,            ONLY: cp_sll_val_next,&
      22             :                                               cp_sll_val_type
      23             :    USE cp_para_types,                   ONLY: cp_para_env_type
      24             :    USE cp_parser_methods,               ONLY: parser_get_next_line,&
      25             :                                               parser_get_object,&
      26             :                                               parser_search_string,&
      27             :                                               parser_test_next_token
      28             :    USE cp_parser_types,                 ONLY: cp_parser_type,&
      29             :                                               parser_create,&
      30             :                                               parser_release
      31             :    USE input_section_types,             ONLY: section_vals_get,&
      32             :                                               section_vals_list_get,&
      33             :                                               section_vals_type,&
      34             :                                               section_vals_val_set
      35             :    USE input_val_types,                 ONLY: val_get,&
      36             :                                               val_type
      37             :    USE kinds,                           ONLY: default_path_length,&
      38             :                                               default_string_length,&
      39             :                                               dp
      40             :    USE mathconstants,                   ONLY: dfac,&
      41             :                                               fac,&
      42             :                                               pi,&
      43             :                                               rootpi
      44             :    USE mathlib,                         ONLY: symmetrize_matrix
      45             :    USE memory_utilities,                ONLY: reallocate
      46             :    USE orbital_pointers,                ONLY: co,&
      47             :                                               coset,&
      48             :                                               init_orbital_pointers,&
      49             :                                               nco,&
      50             :                                               ncoset,&
      51             :                                               nso
      52             :    USE orbital_transformation_matrices, ONLY: orbtramat
      53             :    USE periodic_table,                  ONLY: ptable
      54             :    USE string_utilities,                ONLY: remove_word,&
      55             :                                               uppercase
      56             : #include "../base/base_uses.f90"
      57             : 
      58             :    IMPLICIT NONE
      59             : 
      60             :    PRIVATE
      61             : 
      62             :    ! Global parameters
      63             : 
      64             :    CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'external_potential_types'
      65             : 
      66             :    ! Define the all-electron potential type
      67             : 
      68             :    ! Literature: M. Krack and M. Parrinello,
      69             :    !             Phys. Chem. Chem. Phys. 2, 2105 (2000)
      70             : 
      71             : ! **************************************************************************************************
      72             :    TYPE all_potential_type
      73             :       !MK PRIVATE
      74             :       CHARACTER(LEN=default_string_length)   :: name
      75             :       CHARACTER(LEN=default_string_length), &
      76             :          DIMENSION(2)                      :: description
      77             :       REAL(KIND=dp)                        :: alpha_core_charge, &
      78             :                                               ccore_charge, &
      79             :                                               core_charge_radius, &
      80             :                                               zeff, zeff_correction
      81             :       INTEGER                                :: z
      82             :       INTEGER, DIMENSION(:), POINTER         :: elec_conf
      83             :    END TYPE all_potential_type
      84             : 
      85             :    ! Define the effective charge & inducible dipole potential type (for Fist)
      86             : ! **************************************************************************************************
      87             :    TYPE fist_potential_type
      88             :       PRIVATE
      89             :       CHARACTER(LEN=default_string_length)     :: name
      90             :       CHARACTER(LEN=default_string_length), &
      91             :          DIMENSION(1)                        :: description
      92             :       REAL(KIND=dp)                          :: apol, cpol, mm_radius, qeff, &
      93             :                                                 qmmm_corr_radius, qmmm_radius
      94             : 
      95             :    END TYPE fist_potential_type
      96             : 
      97             : ! **************************************************************************************************
      98             : ! local potential type
      99             : ! V(r) = SUM_i exp(0.5*(r/rci)**2) * ( C1i + C2i (r/rci)**2 + C3i (r/rci)**4 ...)
     100             : ! alpha = 0.5/rci**2
     101             :    TYPE local_potential_type
     102             :       !PRIVATE
     103             :       CHARACTER(LEN=default_string_length)       :: name
     104             :       CHARACTER(LEN=default_string_length), &
     105             :          DIMENSION(4)                          :: description
     106             :       INTEGER                                    :: ngau, npol
     107             :       REAL(KIND=dp)                            :: radius
     108             :       REAL(KIND=dp), DIMENSION(:), POINTER     :: alpha
     109             :       REAL(KIND=dp), DIMENSION(:, :), POINTER   :: cval
     110             :    END TYPE local_potential_type
     111             : 
     112             :    ! Define the GTH potential type
     113             : 
     114             :    ! Literature: - S. Goedecker, M. Teter and J. Hutter,
     115             :    !               Phys. Rev. B 54, 1703 (1996)
     116             :    !             - C. Hartwigsen, S. Goedecker and J. Hutter,
     117             :    !               Phys. Rev. B 58, 3641 (1998)
     118             :    !             - M. Krack,
     119             :    !               Theor. Chem. Acc. 114, 145 (2005)
     120             : 
     121             : ! **************************************************************************************************
     122             :    TYPE gth_potential_type
     123             :       !PRIVATE
     124             :       CHARACTER(LEN=default_string_length)       :: name
     125             :       CHARACTER(LEN=default_string_length)       :: aliases = ""
     126             :       CHARACTER(LEN=default_string_length), &
     127             :          DIMENSION(4)                          :: description
     128             :       REAL(KIND=dp)                            :: alpha_core_charge, &
     129             :                                                   alpha_ppl, ccore_charge, &
     130             :                                                   cerf_ppl, zeff, &
     131             :                                                   core_charge_radius, &
     132             :                                                   ppl_radius, ppnl_radius, &
     133             :                                                   zeff_correction
     134             :       INTEGER                                    :: lppnl, lprj_ppnl_max, &
     135             :                                                     nexp_ppl, nppnl, &
     136             :                                                     nprj_ppnl_max, z
     137             :       REAL(KIND=dp), DIMENSION(:), POINTER     :: alpha_ppnl, cexp_ppl
     138             :       INTEGER, DIMENSION(:), POINTER             :: elec_conf
     139             :       ! nonlocal projectors
     140             :       INTEGER, DIMENSION(:), POINTER             :: nprj_ppnl
     141             :       REAL(KIND=dp), DIMENSION(:, :), POINTER   :: cprj, cprj_ppnl, vprj_ppnl
     142             :       REAL(KIND=dp), DIMENSION(:, :, :), POINTER :: hprj_ppnl
     143             :       ! type extensions
     144             :       ! NLCC
     145             :       LOGICAL                                    :: nlcc
     146             :       INTEGER                                    :: nexp_nlcc
     147             :       REAL(KIND=dp), DIMENSION(:), POINTER     :: alpha_nlcc
     148             :       INTEGER, DIMENSION(:), POINTER             :: nct_nlcc
     149             :       REAL(KIND=dp), DIMENSION(:, :), POINTER   :: cval_nlcc
     150             :       ! LSD potential
     151             :       LOGICAL                                    :: lsdpot
     152             :       INTEGER                                    :: nexp_lsd
     153             :       REAL(KIND=dp), DIMENSION(:), POINTER     :: alpha_lsd
     154             :       INTEGER, DIMENSION(:), POINTER             :: nct_lsd
     155             :       REAL(KIND=dp), DIMENSION(:, :), POINTER   :: cval_lsd
     156             :       ! extended local potential
     157             :       LOGICAL                                    :: lpotextended
     158             :       INTEGER                                    :: nexp_lpot
     159             :       REAL(KIND=dp), DIMENSION(:), POINTER     :: alpha_lpot
     160             :       INTEGER, DIMENSION(:), POINTER             :: nct_lpot
     161             :       REAL(KIND=dp), DIMENSION(:, :), POINTER   :: cval_lpot
     162             : 
     163             :    END TYPE gth_potential_type
     164             : 
     165             : ! **************************************************************************************************
     166             :    TYPE sgp_potential_type
     167             :       CHARACTER(LEN=default_string_length)       :: name
     168             :       CHARACTER(LEN=default_string_length)       :: aliases = ""
     169             :       CHARACTER(LEN=default_string_length), &
     170             :          DIMENSION(4)                            :: description
     171             :       ! CHARGE
     172             :       INTEGER                                    :: z
     173             :       REAL(KIND=dp)                              :: zeff, &
     174             :                                                     zeff_correction
     175             :       REAL(KIND=dp)                              :: alpha_core_charge, &
     176             :                                                     ccore_charge, &
     177             :                                                     core_charge_radius
     178             :       REAL(KIND=dp)                              :: ppl_radius, ppnl_radius
     179             :       INTEGER, DIMENSION(:), POINTER             :: elec_conf
     180             :       ! LOCAL
     181             :       LOGICAL                                    :: ecp_local
     182             :       INTEGER                                    :: n_local
     183             :       REAL(KIND=dp), DIMENSION(:), POINTER       :: a_local => Null()
     184             :       REAL(KIND=dp), DIMENSION(:), POINTER       :: c_local => Null()
     185             :       ! ECP local
     186             :       INTEGER                                    :: nloc ! # terms
     187             :       INTEGER, DIMENSION(1:10)                   :: nrloc ! r**(n-2)
     188             :       REAL(dp), DIMENSION(1:10)                  :: aloc ! coefficient
     189             :       REAL(dp), DIMENSION(1:10)                  :: bloc ! exponent
     190             :       ! NONLOCAL
     191             :       INTEGER                                    :: n_nonlocal
     192             :       INTEGER                                    :: nppnl
     193             :       INTEGER                                    :: lmax
     194             :       LOGICAL, DIMENSION(0:5)                    :: is_nonlocal = .FALSE.
     195             :       REAL(KIND=dp), DIMENSION(:), POINTER       :: a_nonlocal => Null()
     196             :       REAL(KIND=dp), DIMENSION(:, :), POINTER    :: h_nonlocal => Null()
     197             :       REAL(KIND=dp), DIMENSION(:, :, :), POINTER :: c_nonlocal => Null()
     198             :       REAL(KIND=dp), DIMENSION(:, :), POINTER    :: cprj_ppnl
     199             :       REAL(KIND=dp), DIMENSION(:), POINTER       :: vprj_ppnl
     200             :       ! NLCC
     201             :       LOGICAL                                    :: has_nlcc
     202             :       INTEGER                                    :: n_nlcc
     203             :       REAL(KIND=dp), DIMENSION(:), POINTER       :: a_nlcc => Null()
     204             :       REAL(KIND=dp), DIMENSION(:), POINTER       :: c_nlcc => Null()
     205             :    END TYPE sgp_potential_type
     206             : 
     207             : ! **************************************************************************************************
     208             :    TYPE all_potential_p_type
     209             :       TYPE(all_potential_type), POINTER          :: all_potential
     210             :    END TYPE all_potential_p_type
     211             : 
     212             :    TYPE gth_potential_p_type
     213             :       TYPE(gth_potential_type), POINTER          :: gth_potential
     214             :    END TYPE gth_potential_p_type
     215             : 
     216             :    TYPE local_potential_p_type
     217             :       TYPE(local_potential_type), POINTER        :: local_potential
     218             :    END TYPE local_potential_p_type
     219             : 
     220             :    TYPE sgp_potential_p_type
     221             :       TYPE(sgp_potential_type), POINTER          :: sgp_potential
     222             :    END TYPE sgp_potential_p_type
     223             : ! **************************************************************************************************
     224             : 
     225             :    ! Public subroutines
     226             :    PUBLIC :: allocate_potential, &
     227             :              deallocate_potential, &
     228             :              get_potential, &
     229             :              init_potential, &
     230             :              read_potential, &
     231             :              set_potential, &
     232             :              set_default_all_potential, &
     233             :              write_potential, &
     234             :              copy_potential
     235             : 
     236             :    ! Public data types
     237             : 
     238             :    PUBLIC :: all_potential_type, &
     239             :              fist_potential_type, &
     240             :              local_potential_type, &
     241             :              gth_potential_type, &
     242             :              sgp_potential_type
     243             :    PUBLIC :: gth_potential_p_type, &
     244             :              sgp_potential_p_type
     245             : 
     246             :    INTERFACE allocate_potential
     247             :       MODULE PROCEDURE allocate_all_potential, &
     248             :          allocate_fist_potential, &
     249             :          allocate_local_potential, &
     250             :          allocate_gth_potential, &
     251             :          allocate_sgp_potential
     252             :    END INTERFACE
     253             : 
     254             :    INTERFACE deallocate_potential
     255             :       MODULE PROCEDURE deallocate_all_potential, &
     256             :          deallocate_fist_potential, &
     257             :          deallocate_local_potential, &
     258             :          deallocate_sgp_potential, &
     259             :          deallocate_gth_potential
     260             :    END INTERFACE
     261             : 
     262             :    INTERFACE get_potential
     263             :       MODULE PROCEDURE get_all_potential, &
     264             :          get_fist_potential, &
     265             :          get_local_potential, &
     266             :          get_gth_potential, &
     267             :          get_sgp_potential
     268             :    END INTERFACE
     269             : 
     270             :    INTERFACE init_potential
     271             :       MODULE PROCEDURE init_all_potential, &
     272             :          init_gth_potential, &
     273             :          init_sgp_potential
     274             :    END INTERFACE
     275             : 
     276             :    INTERFACE read_potential
     277             :       MODULE PROCEDURE read_all_potential, &
     278             :          read_local_potential, &
     279             :          read_gth_potential
     280             :    END INTERFACE
     281             : 
     282             :    INTERFACE set_potential
     283             :       MODULE PROCEDURE set_all_potential, &
     284             :          set_fist_potential, &
     285             :          set_local_potential, &
     286             :          set_gth_potential, &
     287             :          set_sgp_potential
     288             :    END INTERFACE
     289             : 
     290             :    INTERFACE write_potential
     291             :       MODULE PROCEDURE write_all_potential, &
     292             :          write_local_potential, &
     293             :          write_gth_potential, &
     294             :          write_sgp_potential
     295             :    END INTERFACE
     296             : 
     297             :    INTERFACE copy_potential
     298             :       MODULE PROCEDURE copy_all_potential, &
     299             :          copy_gth_potential, &
     300             :          copy_sgp_potential
     301             :    END INTERFACE
     302             : 
     303             : CONTAINS
     304             : 
     305             : ! **************************************************************************************************
     306             : !> \brief   Allocate an atomic all-electron potential data set.
     307             : !> \param potential ...
     308             : !> \date    25.07.2000,
     309             : !> \author  MK
     310             : !> \version 1.0
     311             : ! **************************************************************************************************
     312        4430 :    SUBROUTINE allocate_all_potential(potential)
     313             :       TYPE(all_potential_type), INTENT(INOUT), POINTER   :: potential
     314             : 
     315        4430 :       IF (ASSOCIATED(potential)) CALL deallocate_potential(potential)
     316             : 
     317        4430 :       ALLOCATE (potential)
     318             : 
     319        4430 :       NULLIFY (potential%elec_conf)
     320             : 
     321        4430 :       potential%description(1) = "All-electron potential"
     322        4430 :       potential%description(2) = "Krack, Parrinello, PCCP 2, 2105 (2000)"
     323             : 
     324        4430 :    END SUBROUTINE allocate_all_potential
     325             : 
     326             : ! **************************************************************************************************
     327             : !> \brief   Allocate an effective charge and inducible dipole potential data set.
     328             : !> \param potential ...
     329             : !> \date    05.03.2010
     330             : !> \author  Toon.Verstraelen@gmail.com
     331             : ! **************************************************************************************************
     332       11130 :    SUBROUTINE allocate_fist_potential(potential)
     333             :       TYPE(fist_potential_type), INTENT(INOUT), POINTER  :: potential
     334             : 
     335       11130 :       IF (ASSOCIATED(potential)) CALL deallocate_potential(potential)
     336             : 
     337       11130 :       ALLOCATE (potential)
     338             : 
     339       11130 :       potential%apol = 0.0_dp
     340       11130 :       potential%cpol = 0.0_dp
     341       11130 :       potential%mm_radius = 0.0_dp
     342       11130 :       potential%qeff = 0.0_dp
     343       11130 :       potential%qmmm_radius = 0.0_dp
     344       11130 :       potential%qmmm_corr_radius = 0.0_dp
     345             : 
     346       11130 :       potential%description(1) = "Effective charge and inducible dipole potential"
     347             : 
     348       11130 :    END SUBROUTINE allocate_fist_potential
     349             : 
     350             : ! **************************************************************************************************
     351             : !> \brief   Allocate an atomic local potential data set.
     352             : !> \param potential ...
     353             : !> \date    24.01.2014
     354             : !> \author  JGH
     355             : !> \version 1.0
     356             : ! **************************************************************************************************
     357          20 :    SUBROUTINE allocate_local_potential(potential)
     358             :       TYPE(local_potential_type), INTENT(INOUT), POINTER :: potential
     359             : 
     360          20 :       IF (ASSOCIATED(potential)) CALL deallocate_potential(potential)
     361             : 
     362          20 :       ALLOCATE (potential)
     363             : 
     364          20 :       NULLIFY (potential%alpha)
     365          20 :       NULLIFY (potential%cval)
     366             : 
     367          20 :       potential%description(1) = "Local short-range pseudopotential"
     368          20 :       potential%ngau = 0
     369          20 :       potential%npol = 0
     370          20 :       potential%radius = 0.0_dp
     371             : 
     372          20 :    END SUBROUTINE allocate_local_potential
     373             : 
     374             : ! **************************************************************************************************
     375             : !> \brief   Allocate an atomic GTH potential data set.
     376             : !> \param potential ...
     377             : !> \date    25.07.2000
     378             : !> \author  MK
     379             : !> \version 1.0
     380             : ! **************************************************************************************************
     381        6887 :    SUBROUTINE allocate_gth_potential(potential)
     382             :       TYPE(gth_potential_type), INTENT(INOUT), POINTER   :: potential
     383             : 
     384        6887 :       IF (ASSOCIATED(potential)) CALL deallocate_potential(potential)
     385             : 
     386        6887 :       ALLOCATE (potential)
     387             : 
     388        6887 :       NULLIFY (potential%alpha_ppnl)
     389        6887 :       NULLIFY (potential%cexp_ppl)
     390        6887 :       NULLIFY (potential%elec_conf)
     391        6887 :       NULLIFY (potential%nprj_ppnl)
     392        6887 :       NULLIFY (potential%cprj)
     393        6887 :       NULLIFY (potential%cprj_ppnl)
     394        6887 :       NULLIFY (potential%vprj_ppnl)
     395        6887 :       NULLIFY (potential%hprj_ppnl)
     396             : 
     397        6887 :       NULLIFY (potential%alpha_lpot)
     398        6887 :       NULLIFY (potential%nct_lpot)
     399        6887 :       NULLIFY (potential%cval_lpot)
     400        6887 :       NULLIFY (potential%alpha_lsd)
     401        6887 :       NULLIFY (potential%nct_lsd)
     402        6887 :       NULLIFY (potential%cval_lsd)
     403        6887 :       NULLIFY (potential%alpha_nlcc)
     404        6887 :       NULLIFY (potential%nct_nlcc)
     405        6887 :       NULLIFY (potential%cval_nlcc)
     406             : 
     407        6887 :       potential%description(1) = "Goedecker-Teter-Hutter pseudopotential"
     408        6887 :       potential%description(2) = "Goedecker et al., PRB 54, 1703 (1996)"
     409        6887 :       potential%description(3) = "Hartwigsen et al., PRB 58, 3641 (1998)"
     410        6887 :       potential%description(4) = "Krack, TCA 114, 145 (2005)"
     411             : 
     412        6887 :    END SUBROUTINE allocate_gth_potential
     413             : 
     414             : ! **************************************************************************************************
     415             : !> \brief   Allocate an atomic SGP potential data set.
     416             : !> \param potential ...
     417             : !> \version 1.0
     418             : ! **************************************************************************************************
     419          12 :    SUBROUTINE allocate_sgp_potential(potential)
     420             :       TYPE(sgp_potential_type), INTENT(INOUT), POINTER   :: potential
     421             : 
     422          12 :       IF (ASSOCIATED(potential)) CALL deallocate_potential(potential)
     423             : 
     424          84 :       ALLOCATE (potential)
     425             : 
     426          12 :       NULLIFY (potential%elec_conf)
     427             :       NULLIFY (potential%a_local)
     428             :       NULLIFY (potential%c_local)
     429             :       NULLIFY (potential%a_nonlocal)
     430             :       NULLIFY (potential%c_nonlocal)
     431             :       NULLIFY (potential%h_nonlocal)
     432             :       NULLIFY (potential%a_nlcc)
     433             :       NULLIFY (potential%c_nlcc)
     434          12 :       NULLIFY (potential%cprj_ppnl)
     435          12 :       NULLIFY (potential%vprj_ppnl)
     436             : 
     437          12 :       potential%name = ""
     438          12 :       potential%aliases = ""
     439          12 :       potential%description(1) = "Separable Gaussian pseudopotential"
     440          12 :       potential%description(2) = "M. Pelissier, N. Komiha, J.P. Daudey, JCC, 9, 298 (1988)"
     441          12 :       potential%description(3) = "create from"
     442          12 :       potential%description(4) = ""
     443             : 
     444          12 :       potential%z = 0
     445          12 :       potential%zeff = 0.0_dp
     446          12 :       potential%zeff_correction = 0.0_dp
     447          12 :       potential%alpha_core_charge = 0.0_dp
     448          12 :       potential%ccore_charge = 0.0_dp
     449          12 :       potential%core_charge_radius = 0.0_dp
     450          12 :       potential%ppl_radius = 0.0_dp
     451          12 :       potential%ppnl_radius = 0.0_dp
     452          12 :       potential%ecp_local = .FALSE.
     453          12 :       potential%n_local = 0
     454          12 :       potential%nloc = 0
     455         132 :       potential%nrloc = 0
     456         132 :       potential%aloc = 0.0_dp
     457         132 :       potential%bloc = 0.0_dp
     458          12 :       potential%n_nonlocal = 0
     459          12 :       potential%nppnl = 0
     460          12 :       potential%lmax = -1
     461          84 :       potential%is_nonlocal = .FALSE.
     462          12 :       potential%has_nlcc = .FALSE.
     463          12 :       potential%n_nlcc = 0
     464             : 
     465          12 :    END SUBROUTINE allocate_sgp_potential
     466             : ! **************************************************************************************************
     467             : !> \brief   Deallocate an atomic all-electron potential data set.
     468             : !> \param potential ...
     469             : !> \date    03.11.2000
     470             : !> \author  MK
     471             : !> \version 1.0
     472             : ! **************************************************************************************************
     473        4428 :    SUBROUTINE deallocate_all_potential(potential)
     474             :       TYPE(all_potential_type), POINTER                  :: potential
     475             : 
     476        4428 :       IF (.NOT. ASSOCIATED(potential)) THEN
     477           0 :          CPABORT("The pointer potential is not associated.")
     478             :       END IF
     479             : 
     480        4428 :       DEALLOCATE (potential%elec_conf)
     481        4428 :       DEALLOCATE (potential)
     482             : 
     483        4428 :    END SUBROUTINE deallocate_all_potential
     484             : 
     485             : ! **************************************************************************************************
     486             : !> \brief   Deallocate an effective charge and inducible dipole potential data set.
     487             : !> \param potential ...
     488             : !> \date    05.03.2010
     489             : !> \author  Toon.Verstraelen@gmail.com
     490             : ! **************************************************************************************************
     491       11130 :    SUBROUTINE deallocate_fist_potential(potential)
     492             :       TYPE(fist_potential_type), POINTER                 :: potential
     493             : 
     494       11130 :       IF (.NOT. ASSOCIATED(potential)) THEN
     495           0 :          CPABORT("The pointer potential is not associated.")
     496             :       END IF
     497             : 
     498             :       ! Nothing exciting here yet.
     499       11130 :       DEALLOCATE (potential)
     500             : 
     501       11130 :    END SUBROUTINE deallocate_fist_potential
     502             : 
     503             : ! **************************************************************************************************
     504             : !> \brief   Deallocate an atomic local potential data set.
     505             : !> \param potential ...
     506             : !> \date    24.01.2014
     507             : !> \author  JGH
     508             : !> \version 1.0
     509             : ! **************************************************************************************************
     510          20 :    SUBROUTINE deallocate_local_potential(potential)
     511             :       TYPE(local_potential_type), POINTER                :: potential
     512             : 
     513          20 :       IF (.NOT. ASSOCIATED(potential)) THEN
     514           0 :          CPABORT("The pointer potential is not associated.")
     515             :       END IF
     516             : 
     517          20 :       IF (ASSOCIATED(potential%alpha)) THEN
     518          20 :          DEALLOCATE (potential%alpha)
     519             :       END IF
     520          20 :       IF (ASSOCIATED(potential%cval)) THEN
     521          20 :          DEALLOCATE (potential%cval)
     522             :       END IF
     523             : 
     524          20 :       DEALLOCATE (potential)
     525             : 
     526          20 :    END SUBROUTINE deallocate_local_potential
     527             : 
     528             : ! **************************************************************************************************
     529             : !> \brief   Deallocate an atomic GTH potential data set.
     530             : !> \param potential ...
     531             : !> \date    03.11.2000
     532             : !> \author  MK
     533             : !> \version 1.0
     534             : ! **************************************************************************************************
     535        6887 :    SUBROUTINE deallocate_gth_potential(potential)
     536             :       TYPE(gth_potential_type), POINTER                  :: potential
     537             : 
     538        6887 :       IF (.NOT. ASSOCIATED(potential)) THEN
     539           0 :          CPABORT("The pointer potential is not associated.")
     540             :       END IF
     541             : 
     542        6887 :       DEALLOCATE (potential%elec_conf)
     543             :       !     *** Deallocate the parameters of the local part ***
     544             : 
     545        6887 :       IF (ASSOCIATED(potential%cexp_ppl)) THEN
     546        6887 :          DEALLOCATE (potential%cexp_ppl)
     547             :       END IF
     548             : 
     549             :       !     *** Deallocate the parameters of the non-local part ***
     550        6887 :       IF (ASSOCIATED(potential%alpha_ppnl)) THEN
     551        3367 :          DEALLOCATE (potential%alpha_ppnl)
     552        3367 :          DEALLOCATE (potential%cprj)
     553        3367 :          DEALLOCATE (potential%cprj_ppnl)
     554        3367 :          DEALLOCATE (potential%hprj_ppnl)
     555        3367 :          DEALLOCATE (potential%nprj_ppnl)
     556        3367 :          DEALLOCATE (potential%vprj_ppnl)
     557             :       END IF
     558             : 
     559        6887 :       IF (ASSOCIATED(potential%alpha_lpot)) THEN
     560           8 :          DEALLOCATE (potential%alpha_lpot)
     561           8 :          DEALLOCATE (potential%nct_lpot)
     562           8 :          DEALLOCATE (potential%cval_lpot)
     563             :       END IF
     564             : 
     565        6887 :       IF (ASSOCIATED(potential%alpha_lsd)) THEN
     566           0 :          DEALLOCATE (potential%alpha_lsd)
     567           0 :          DEALLOCATE (potential%nct_lsd)
     568           0 :          DEALLOCATE (potential%cval_lsd)
     569             :       END IF
     570             : 
     571        6887 :       IF (ASSOCIATED(potential%alpha_nlcc)) THEN
     572          18 :          DEALLOCATE (potential%alpha_nlcc)
     573          18 :          DEALLOCATE (potential%nct_nlcc)
     574          18 :          DEALLOCATE (potential%cval_nlcc)
     575             :       END IF
     576             : 
     577        6887 :       DEALLOCATE (potential)
     578        6887 :    END SUBROUTINE deallocate_gth_potential
     579             : 
     580             : ! **************************************************************************************************
     581             : !> \brief   Deallocate an atomic SGP potential data set.
     582             : !> \param potential ...
     583             : ! **************************************************************************************************
     584          12 :    SUBROUTINE deallocate_sgp_potential(potential)
     585             :       TYPE(sgp_potential_type), POINTER                  :: potential
     586             : 
     587          12 :       IF (.NOT. ASSOCIATED(potential)) THEN
     588           0 :          CPABORT("The pointer potential is not associated.")
     589             :       END IF
     590             : 
     591          12 :       IF (ASSOCIATED(potential%elec_conf)) THEN
     592          12 :          DEALLOCATE (potential%elec_conf)
     593             :       END IF
     594          12 :       IF (ASSOCIATED(potential%a_local)) THEN
     595          12 :          DEALLOCATE (potential%a_local)
     596             :       END IF
     597          12 :       IF (ASSOCIATED(potential%c_local)) THEN
     598          12 :          DEALLOCATE (potential%c_local)
     599             :       END IF
     600             : 
     601          12 :       IF (ASSOCIATED(potential%a_nonlocal)) THEN
     602           6 :          DEALLOCATE (potential%a_nonlocal)
     603             :       END IF
     604          12 :       IF (ASSOCIATED(potential%h_nonlocal)) THEN
     605           6 :          DEALLOCATE (potential%h_nonlocal)
     606             :       END IF
     607          12 :       IF (ASSOCIATED(potential%c_nonlocal)) THEN
     608           6 :          DEALLOCATE (potential%c_nonlocal)
     609             :       END IF
     610          12 :       IF (ASSOCIATED(potential%cprj_ppnl)) THEN
     611           6 :          DEALLOCATE (potential%cprj_ppnl)
     612             :       END IF
     613          12 :       IF (ASSOCIATED(potential%vprj_ppnl)) THEN
     614           6 :          DEALLOCATE (potential%vprj_ppnl)
     615             :       END IF
     616             : 
     617          12 :       IF (ASSOCIATED(potential%a_nlcc)) THEN
     618           0 :          DEALLOCATE (potential%a_nlcc)
     619             :       END IF
     620          12 :       IF (ASSOCIATED(potential%c_nlcc)) THEN
     621           0 :          DEALLOCATE (potential%c_nlcc)
     622             :       END IF
     623             : 
     624          12 :       DEALLOCATE (potential)
     625             : 
     626          12 :    END SUBROUTINE deallocate_sgp_potential
     627             : 
     628             : ! **************************************************************************************************
     629             : !> \brief   Get attributes of an all-electron potential data set.
     630             : !> \param potential ...
     631             : !> \param name ...
     632             : !> \param alpha_core_charge ...
     633             : !> \param ccore_charge ...
     634             : !> \param core_charge_radius ...
     635             : !> \param z ...
     636             : !> \param zeff ...
     637             : !> \param zeff_correction ...
     638             : !> \param elec_conf ...
     639             : !> \date    11.01.2002
     640             : !> \author  MK
     641             : !> \version 1.0
     642             : ! **************************************************************************************************
     643      279398 :    SUBROUTINE get_all_potential(potential, name, alpha_core_charge, &
     644             :                                 ccore_charge, core_charge_radius, z, zeff, &
     645             :                                 zeff_correction, elec_conf)
     646             :       TYPE(all_potential_type), POINTER                  :: potential
     647             :       CHARACTER(LEN=default_string_length), &
     648             :          INTENT(OUT), OPTIONAL                           :: name
     649             :       REAL(KIND=dp), INTENT(OUT), OPTIONAL               :: alpha_core_charge, ccore_charge, &
     650             :                                                             core_charge_radius
     651             :       INTEGER, INTENT(OUT), OPTIONAL                     :: z
     652             :       REAL(KIND=dp), INTENT(OUT), OPTIONAL               :: zeff, zeff_correction
     653             :       INTEGER, DIMENSION(:), OPTIONAL, POINTER           :: elec_conf
     654             : 
     655      279398 :       IF (ASSOCIATED(potential)) THEN
     656             : 
     657      279398 :          IF (PRESENT(name)) name = potential%name
     658      279398 :          IF (PRESENT(alpha_core_charge)) &
     659      120765 :             alpha_core_charge = potential%alpha_core_charge
     660      279398 :          IF (PRESENT(ccore_charge)) ccore_charge = potential%ccore_charge
     661      279398 :          IF (PRESENT(core_charge_radius)) &
     662      132843 :             core_charge_radius = potential%core_charge_radius
     663      279398 :          IF (PRESENT(z)) z = potential%z
     664      279398 :          IF (PRESENT(zeff)) zeff = potential%zeff
     665      279398 :          IF (PRESENT(zeff_correction)) zeff_correction = potential%zeff_correction
     666      279398 :          IF (PRESENT(elec_conf)) elec_conf => potential%elec_conf
     667             : 
     668             :       ELSE
     669             : 
     670           0 :          CPABORT("The pointer potential is not associated.")
     671             : 
     672             :       END IF
     673             : 
     674      279398 :    END SUBROUTINE get_all_potential
     675             : 
     676             : ! **************************************************************************************************
     677             : !> \brief   Get attributes of an effective point charge and inducible dipole
     678             : !>          potential.
     679             : !> \param potential ...
     680             : !> \param name ...
     681             : !> \param apol ...
     682             : !> \param cpol ...
     683             : !> \param mm_radius ...
     684             : !> \param qeff ...
     685             : !> \param qmmm_corr_radius ...
     686             : !> \param qmmm_radius ...
     687             : !> \date    05.03-2010
     688             : !> \author  Toon.Verstraelen@UGent.be
     689             : ! **************************************************************************************************
     690    55775587 :    SUBROUTINE get_fist_potential(potential, name, apol, cpol, mm_radius, qeff, &
     691             :                                  qmmm_corr_radius, qmmm_radius)
     692             :       TYPE(fist_potential_type), POINTER                 :: potential
     693             :       CHARACTER(LEN=default_string_length), &
     694             :          INTENT(OUT), OPTIONAL                           :: name
     695             :       REAL(KIND=dp), INTENT(OUT), OPTIONAL               :: apol, cpol, mm_radius, qeff, &
     696             :                                                             qmmm_corr_radius, qmmm_radius
     697             : 
     698    55775587 :       IF (ASSOCIATED(potential)) THEN
     699             : 
     700    55775587 :          IF (PRESENT(name)) name = potential%name
     701    55775587 :          IF (PRESENT(apol)) apol = potential%apol
     702    55775587 :          IF (PRESENT(cpol)) cpol = potential%cpol
     703    55775587 :          IF (PRESENT(mm_radius)) mm_radius = potential%mm_radius
     704    55775587 :          IF (PRESENT(qeff)) qeff = potential%qeff
     705    55775587 :          IF (PRESENT(qmmm_corr_radius)) qmmm_corr_radius = potential%qmmm_corr_radius
     706    55775587 :          IF (PRESENT(qmmm_radius)) qmmm_radius = potential%qmmm_radius
     707             : 
     708             :       ELSE
     709             : 
     710           0 :          CPABORT("The pointer potential is not associated.")
     711             : 
     712             :       END IF
     713             : 
     714    55775587 :    END SUBROUTINE get_fist_potential
     715             : 
     716             : ! **************************************************************************************************
     717             : !> \brief   Get attributes of an atomic local potential data set.
     718             : !> \param potential ...
     719             : !> \param name ...
     720             : !> \param ngau ...
     721             : !> \param npol ...
     722             : !> \param alpha ...
     723             : !> \param cval ...
     724             : !> \param radius ...
     725             : !> \date    24.01.2014
     726             : !> \author  JGH
     727             : !> \version 1.0
     728             : ! **************************************************************************************************
     729         397 :    SUBROUTINE get_local_potential(potential, name, ngau, npol, alpha, cval, radius)
     730             :       TYPE(local_potential_type), POINTER                :: potential
     731             :       CHARACTER(LEN=default_string_length), &
     732             :          INTENT(OUT), OPTIONAL                           :: name
     733             :       INTEGER, INTENT(OUT), OPTIONAL                     :: ngau, npol
     734             :       REAL(KIND=dp), DIMENSION(:), OPTIONAL, POINTER     :: alpha
     735             :       REAL(KIND=dp), DIMENSION(:, :), OPTIONAL, POINTER  :: cval
     736             :       REAL(KIND=dp), INTENT(OUT), OPTIONAL               :: radius
     737             : 
     738         397 :       IF (ASSOCIATED(potential)) THEN
     739             : 
     740         397 :          IF (PRESENT(name)) name = potential%name
     741         397 :          IF (PRESENT(ngau)) ngau = potential%ngau
     742         397 :          IF (PRESENT(npol)) npol = potential%npol
     743         397 :          IF (PRESENT(alpha)) alpha => potential%alpha
     744         397 :          IF (PRESENT(cval)) cval => potential%cval
     745         397 :          IF (PRESENT(radius)) radius = potential%radius
     746             : 
     747             :       ELSE
     748             : 
     749           0 :          CPABORT("The pointer potential is not associated.")
     750             : 
     751             :       END IF
     752             : 
     753         397 :    END SUBROUTINE get_local_potential
     754             : 
     755             : ! **************************************************************************************************
     756             : !> \brief   Get attributes of a GTH potential data set.
     757             : !> \param potential ...
     758             : !> \param name ...
     759             : !> \param aliases ...
     760             : !> \param alpha_core_charge ...
     761             : !> \param alpha_ppl ...
     762             : !> \param ccore_charge ...
     763             : !> \param cerf_ppl ...
     764             : !> \param core_charge_radius ...
     765             : !> \param ppl_radius ...
     766             : !> \param ppnl_radius ...
     767             : !> \param lppnl ...
     768             : !> \param lprj_ppnl_max ...
     769             : !> \param nexp_ppl ...
     770             : !> \param nppnl ...
     771             : !> \param nprj_ppnl_max ...
     772             : !> \param z ...
     773             : !> \param zeff ...
     774             : !> \param zeff_correction ...
     775             : !> \param ppl_present ...
     776             : !> \param ppnl_present ...
     777             : !> \param alpha_ppnl ...
     778             : !> \param cexp_ppl ...
     779             : !> \param elec_conf ...
     780             : !> \param nprj_ppnl ...
     781             : !> \param cprj ...
     782             : !> \param cprj_ppnl ...
     783             : !> \param vprj_ppnl ...
     784             : !> \param hprj_ppnl ...
     785             : !> \param lpot_present ...
     786             : !> \param nexp_lpot ...
     787             : !> \param alpha_lpot ...
     788             : !> \param nct_lpot ...
     789             : !> \param cval_lpot ...
     790             : !> \param lsd_present ...
     791             : !> \param nexp_lsd ...
     792             : !> \param alpha_lsd ...
     793             : !> \param nct_lsd ...
     794             : !> \param cval_lsd ...
     795             : !> \param nlcc_present ...
     796             : !> \param nexp_nlcc ...
     797             : !> \param alpha_nlcc ...
     798             : !> \param nct_nlcc ...
     799             : !> \param cval_nlcc ...
     800             : !> \date    11.01.2002
     801             : !> \author  MK
     802             : !> \version 1.0
     803             : ! **************************************************************************************************
     804     3544963 :    SUBROUTINE get_gth_potential(potential, name, aliases, alpha_core_charge, &
     805             :                                 alpha_ppl, ccore_charge, cerf_ppl, &
     806             :                                 core_charge_radius, ppl_radius, ppnl_radius, &
     807             :                                 lppnl, lprj_ppnl_max, nexp_ppl, nppnl, &
     808             :                                 nprj_ppnl_max, z, zeff, zeff_correction, &
     809             :                                 ppl_present, ppnl_present, &
     810             :                                 alpha_ppnl, cexp_ppl, elec_conf, nprj_ppnl, cprj, &
     811             :                                 cprj_ppnl, vprj_ppnl, hprj_ppnl, &
     812             :                                 lpot_present, nexp_lpot, alpha_lpot, nct_lpot, cval_lpot, &
     813             :                                 lsd_present, nexp_lsd, alpha_lsd, nct_lsd, cval_lsd, &
     814             :                                 nlcc_present, nexp_nlcc, alpha_nlcc, nct_nlcc, cval_nlcc)
     815             : 
     816             :       TYPE(gth_potential_type), POINTER                  :: potential
     817             :       CHARACTER(LEN=default_string_length), &
     818             :          INTENT(OUT), OPTIONAL                           :: name, aliases
     819             :       REAL(KIND=dp), INTENT(OUT), OPTIONAL               :: alpha_core_charge, alpha_ppl, &
     820             :                                                             ccore_charge, cerf_ppl, &
     821             :                                                             core_charge_radius, ppl_radius, &
     822             :                                                             ppnl_radius
     823             :       INTEGER, INTENT(OUT), OPTIONAL                     :: lppnl, lprj_ppnl_max, nexp_ppl, nppnl, &
     824             :                                                             nprj_ppnl_max, z
     825             :       REAL(KIND=dp), INTENT(OUT), OPTIONAL               :: zeff, zeff_correction
     826             :       LOGICAL, INTENT(OUT), OPTIONAL                     :: ppl_present, ppnl_present
     827             :       REAL(KIND=dp), DIMENSION(:), OPTIONAL, POINTER     :: alpha_ppnl, cexp_ppl
     828             :       INTEGER, DIMENSION(:), OPTIONAL, POINTER           :: elec_conf, nprj_ppnl
     829             :       REAL(KIND=dp), DIMENSION(:, :), OPTIONAL, POINTER  :: cprj, cprj_ppnl, vprj_ppnl
     830             :       REAL(KIND=dp), DIMENSION(:, :, :), OPTIONAL, &
     831             :          POINTER                                         :: hprj_ppnl
     832             :       LOGICAL, INTENT(OUT), OPTIONAL                     :: lpot_present
     833             :       INTEGER, INTENT(OUT), OPTIONAL                     :: nexp_lpot
     834             :       REAL(KIND=dp), DIMENSION(:), OPTIONAL, POINTER     :: alpha_lpot
     835             :       INTEGER, DIMENSION(:), OPTIONAL, POINTER           :: nct_lpot
     836             :       REAL(KIND=dp), DIMENSION(:, :), OPTIONAL, POINTER  :: cval_lpot
     837             :       LOGICAL, INTENT(OUT), OPTIONAL                     :: lsd_present
     838             :       INTEGER, INTENT(OUT), OPTIONAL                     :: nexp_lsd
     839             :       REAL(KIND=dp), DIMENSION(:), OPTIONAL, POINTER     :: alpha_lsd
     840             :       INTEGER, DIMENSION(:), OPTIONAL, POINTER           :: nct_lsd
     841             :       REAL(KIND=dp), DIMENSION(:, :), OPTIONAL, POINTER  :: cval_lsd
     842             :       LOGICAL, INTENT(OUT), OPTIONAL                     :: nlcc_present
     843             :       INTEGER, INTENT(OUT), OPTIONAL                     :: nexp_nlcc
     844             :       REAL(KIND=dp), DIMENSION(:), OPTIONAL, POINTER     :: alpha_nlcc
     845             :       INTEGER, DIMENSION(:), OPTIONAL, POINTER           :: nct_nlcc
     846             :       REAL(KIND=dp), DIMENSION(:, :), OPTIONAL, POINTER  :: cval_nlcc
     847             : 
     848     3544963 :       IF (ASSOCIATED(potential)) THEN
     849             : 
     850     3544963 :          IF (PRESENT(name)) name = potential%name
     851     3544963 :          IF (PRESENT(aliases)) aliases = potential%aliases
     852     3544963 :          IF (PRESENT(alpha_core_charge)) &
     853      141165 :             alpha_core_charge = potential%alpha_core_charge
     854     3544963 :          IF (PRESENT(alpha_ppl)) alpha_ppl = potential%alpha_ppl
     855     3544963 :          IF (PRESENT(ccore_charge)) ccore_charge = potential%ccore_charge
     856     3544963 :          IF (PRESENT(cerf_ppl)) cerf_ppl = potential%cerf_ppl
     857     3544963 :          IF (PRESENT(core_charge_radius)) &
     858       39891 :             core_charge_radius = potential%core_charge_radius
     859     3544963 :          IF (PRESENT(ppl_radius)) ppl_radius = potential%ppl_radius
     860     3544963 :          IF (PRESENT(ppnl_radius)) ppnl_radius = potential%ppnl_radius
     861     3544963 :          IF (PRESENT(lppnl)) lppnl = potential%lppnl
     862     3544963 :          IF (PRESENT(lprj_ppnl_max)) lprj_ppnl_max = potential%lprj_ppnl_max
     863     3544963 :          IF (PRESENT(nexp_ppl)) nexp_ppl = potential%nexp_ppl
     864     3544963 :          IF (PRESENT(nppnl)) nppnl = potential%nppnl
     865     3544963 :          IF (PRESENT(nprj_ppnl_max)) nprj_ppnl_max = potential%nprj_ppnl_max
     866     3544963 :          IF (PRESENT(z)) z = potential%z
     867     3544963 :          IF (PRESENT(zeff)) zeff = potential%zeff
     868     3544963 :          IF (PRESENT(zeff_correction)) zeff_correction = potential%zeff_correction
     869     3544963 :          IF (PRESENT(ppl_present)) ppl_present = (potential%nexp_ppl > 0)
     870     3544963 :          IF (PRESENT(ppnl_present)) ppnl_present = (potential%nppnl > 0)
     871     3544963 :          IF (PRESENT(alpha_ppnl)) alpha_ppnl => potential%alpha_ppnl
     872     3544963 :          IF (PRESENT(cexp_ppl)) cexp_ppl => potential%cexp_ppl
     873     3544963 :          IF (PRESENT(elec_conf)) elec_conf => potential%elec_conf
     874     3544963 :          IF (PRESENT(nprj_ppnl)) nprj_ppnl => potential%nprj_ppnl
     875     3544963 :          IF (PRESENT(cprj)) cprj => potential%cprj
     876     3544963 :          IF (PRESENT(cprj_ppnl)) cprj_ppnl => potential%cprj_ppnl
     877     3544963 :          IF (PRESENT(vprj_ppnl)) vprj_ppnl => potential%vprj_ppnl
     878     3544963 :          IF (PRESENT(hprj_ppnl)) hprj_ppnl => potential%hprj_ppnl
     879             : 
     880     3544963 :          IF (PRESENT(lpot_present)) lpot_present = potential%lpotextended
     881     3544963 :          IF (PRESENT(nexp_lpot)) nexp_lpot = potential%nexp_lpot
     882     3544963 :          IF (PRESENT(alpha_lpot)) alpha_lpot => potential%alpha_lpot
     883     3544963 :          IF (PRESENT(nct_lpot)) nct_lpot => potential%nct_lpot
     884     3544963 :          IF (PRESENT(cval_lpot)) cval_lpot => potential%cval_lpot
     885             : 
     886     3544963 :          IF (PRESENT(lsd_present)) lsd_present = potential%lsdpot
     887     3544963 :          IF (PRESENT(nexp_lsd)) nexp_lsd = potential%nexp_lsd
     888     3544963 :          IF (PRESENT(alpha_lsd)) alpha_lsd => potential%alpha_lsd
     889     3544963 :          IF (PRESENT(nct_lsd)) nct_lsd => potential%nct_lsd
     890     3544963 :          IF (PRESENT(cval_lsd)) cval_lsd => potential%cval_lsd
     891             : 
     892     3544963 :          IF (PRESENT(nlcc_present)) nlcc_present = potential%nlcc
     893     3544963 :          IF (PRESENT(nexp_nlcc)) nexp_nlcc = potential%nexp_nlcc
     894     3544963 :          IF (PRESENT(alpha_nlcc)) alpha_nlcc => potential%alpha_nlcc
     895     3544963 :          IF (PRESENT(nct_nlcc)) nct_nlcc => potential%nct_nlcc
     896     3544963 :          IF (PRESENT(cval_nlcc)) cval_nlcc => potential%cval_nlcc
     897             : 
     898             :       ELSE
     899             : 
     900           0 :          CPABORT("The pointer potential is not associated.")
     901             : 
     902             :       END IF
     903             : 
     904     3544963 :    END SUBROUTINE get_gth_potential
     905             : 
     906             : ! **************************************************************************************************
     907             : !> \brief ...
     908             : !> \param potential ...
     909             : !> \param name ...
     910             : !> \param description ...
     911             : !> \param aliases ...
     912             : !> \param elec_conf ...
     913             : !> \param z ...
     914             : !> \param zeff ...
     915             : !> \param zeff_correction ...
     916             : !> \param alpha_core_charge ...
     917             : !> \param ccore_charge ...
     918             : !> \param core_charge_radius ...
     919             : !> \param ppl_radius ...
     920             : !> \param ppnl_radius ...
     921             : !> \param ppl_present ...
     922             : !> \param ppnl_present ...
     923             : !> \param ecp_local ...
     924             : !> \param n_local ...
     925             : !> \param a_local ...
     926             : !> \param c_local ...
     927             : !> \param nloc ...
     928             : !> \param nrloc ...
     929             : !> \param aloc ...
     930             : !> \param bloc ...
     931             : !> \param n_nonlocal ...
     932             : !> \param nppnl ...
     933             : !> \param lmax ...
     934             : !> \param is_nonlocal ...
     935             : !> \param a_nonlocal ...
     936             : !> \param h_nonlocal ...
     937             : !> \param c_nonlocal ...
     938             : !> \param cprj_ppnl ...
     939             : !> \param vprj_ppnl ...
     940             : !> \param has_nlcc ...
     941             : !> \param n_nlcc ...
     942             : !> \param a_nlcc ...
     943             : !> \param c_nlcc ...
     944             : ! **************************************************************************************************
     945        7773 :    SUBROUTINE get_sgp_potential(potential, name, description, aliases, elec_conf, &
     946             :                                 z, zeff, zeff_correction, alpha_core_charge, &
     947             :                                 ccore_charge, core_charge_radius, &
     948             :                                 ppl_radius, ppnl_radius, ppl_present, ppnl_present, &
     949             :                                 ecp_local, n_local, a_local, c_local, &
     950             :                                 nloc, nrloc, aloc, bloc, &
     951             :                                 n_nonlocal, nppnl, lmax, is_nonlocal, a_nonlocal, h_nonlocal, c_nonlocal, &
     952             :                                 cprj_ppnl, vprj_ppnl, has_nlcc, n_nlcc, a_nlcc, c_nlcc)
     953             : 
     954             :       TYPE(sgp_potential_type), POINTER                  :: potential
     955             :       CHARACTER(LEN=default_string_length), &
     956             :          INTENT(OUT), OPTIONAL                           :: name
     957             :       CHARACTER(LEN=default_string_length), &
     958             :          DIMENSION(4), INTENT(OUT), OPTIONAL             :: description
     959             :       CHARACTER(LEN=default_string_length), &
     960             :          INTENT(OUT), OPTIONAL                           :: aliases
     961             :       INTEGER, DIMENSION(:), OPTIONAL, POINTER           :: elec_conf
     962             :       INTEGER, INTENT(OUT), OPTIONAL                     :: z
     963             :       REAL(KIND=dp), INTENT(OUT), OPTIONAL               :: zeff, zeff_correction, &
     964             :                                                             alpha_core_charge, ccore_charge, &
     965             :                                                             core_charge_radius, ppl_radius, &
     966             :                                                             ppnl_radius
     967             :       LOGICAL, INTENT(OUT), OPTIONAL                     :: ppl_present, ppnl_present, ecp_local
     968             :       INTEGER, INTENT(OUT), OPTIONAL                     :: n_local
     969             :       REAL(KIND=dp), DIMENSION(:), OPTIONAL, POINTER     :: a_local, c_local
     970             :       INTEGER, INTENT(OUT), OPTIONAL                     :: nloc
     971             :       INTEGER, DIMENSION(1:10), INTENT(OUT), OPTIONAL    :: nrloc
     972             :       REAL(dp), DIMENSION(1:10), INTENT(OUT), OPTIONAL   :: aloc, bloc
     973             :       INTEGER, INTENT(OUT), OPTIONAL                     :: n_nonlocal, nppnl, lmax
     974             :       LOGICAL, DIMENSION(0:5), OPTIONAL                  :: is_nonlocal
     975             :       REAL(KIND=dp), DIMENSION(:), OPTIONAL, POINTER     :: a_nonlocal
     976             :       REAL(KIND=dp), DIMENSION(:, :), OPTIONAL, POINTER  :: h_nonlocal
     977             :       REAL(KIND=dp), DIMENSION(:, :, :), OPTIONAL, &
     978             :          POINTER                                         :: c_nonlocal
     979             :       REAL(KIND=dp), DIMENSION(:, :), OPTIONAL, POINTER  :: cprj_ppnl
     980             :       REAL(KIND=dp), DIMENSION(:), OPTIONAL, POINTER     :: vprj_ppnl
     981             :       LOGICAL, INTENT(OUT), OPTIONAL                     :: has_nlcc
     982             :       INTEGER, INTENT(OUT), OPTIONAL                     :: n_nlcc
     983             :       REAL(KIND=dp), DIMENSION(:), OPTIONAL, POINTER     :: a_nlcc, c_nlcc
     984             : 
     985        7773 :       IF (ASSOCIATED(potential)) THEN
     986             : 
     987        7773 :          IF (PRESENT(name)) name = potential%name
     988        7773 :          IF (PRESENT(aliases)) aliases = potential%aliases
     989        7821 :          IF (PRESENT(description)) description = potential%description
     990             : 
     991        7773 :          IF (PRESENT(elec_conf)) elec_conf => potential%elec_conf
     992             : 
     993        7773 :          IF (PRESENT(z)) z = potential%z
     994        7773 :          IF (PRESENT(zeff)) zeff = potential%zeff
     995        7773 :          IF (PRESENT(zeff_correction)) zeff_correction = potential%zeff_correction
     996        7773 :          IF (PRESENT(alpha_core_charge)) alpha_core_charge = potential%alpha_core_charge
     997        7773 :          IF (PRESENT(ccore_charge)) ccore_charge = potential%ccore_charge
     998        7773 :          IF (PRESENT(core_charge_radius)) core_charge_radius = potential%core_charge_radius
     999             : 
    1000        7773 :          IF (PRESENT(ppl_radius)) ppl_radius = potential%ppl_radius
    1001        7773 :          IF (PRESENT(ppnl_radius)) ppnl_radius = potential%ppnl_radius
    1002        7773 :          IF (PRESENT(ppl_present)) THEN
    1003          12 :             ppl_present = (potential%nloc > 0 .OR. potential%n_local > 0)
    1004             :          END IF
    1005        7773 :          IF (PRESENT(ppnl_present)) THEN
    1006          48 :             ppnl_present = ANY(potential%is_nonlocal)
    1007             :          END IF
    1008             : 
    1009        7773 :          IF (PRESENT(ecp_local)) ecp_local = potential%ecp_local
    1010        7773 :          IF (PRESENT(n_local)) n_local = potential%n_local
    1011        7773 :          IF (PRESENT(a_local)) a_local => potential%a_local
    1012        7773 :          IF (PRESENT(c_local)) c_local => potential%c_local
    1013             : 
    1014        7773 :          IF (PRESENT(nloc)) nloc = potential%nloc
    1015        8073 :          IF (PRESENT(nrloc)) nrloc = potential%nrloc
    1016        7773 :          IF (PRESENT(aloc)) aloc = potential%aloc
    1017        7773 :          IF (PRESENT(bloc)) bloc = potential%bloc
    1018             : 
    1019        7773 :          IF (PRESENT(n_nonlocal)) n_nonlocal = potential%n_nonlocal
    1020        7773 :          IF (PRESENT(nppnl)) nppnl = potential%nppnl
    1021        7773 :          IF (PRESENT(lmax)) lmax = potential%lmax
    1022        7917 :          IF (PRESENT(is_nonlocal)) is_nonlocal(:) = potential%is_nonlocal(:)
    1023        7773 :          IF (PRESENT(a_nonlocal)) a_nonlocal => potential%a_nonlocal
    1024        7773 :          IF (PRESENT(c_nonlocal)) c_nonlocal => potential%c_nonlocal
    1025        7773 :          IF (PRESENT(h_nonlocal)) h_nonlocal => potential%h_nonlocal
    1026        7773 :          IF (PRESENT(cprj_ppnl)) cprj_ppnl => potential%cprj_ppnl
    1027        7773 :          IF (PRESENT(vprj_ppnl)) vprj_ppnl => potential%vprj_ppnl
    1028             : 
    1029        7773 :          IF (PRESENT(has_nlcc)) has_nlcc = potential%has_nlcc
    1030        7773 :          IF (PRESENT(n_nlcc)) n_nlcc = potential%n_nlcc
    1031        7773 :          IF (PRESENT(a_nlcc)) a_nlcc => potential%a_nlcc
    1032        7773 :          IF (PRESENT(c_nlcc)) c_nlcc => potential%c_nlcc
    1033             : 
    1034             :       ELSE
    1035             : 
    1036           0 :          CPABORT("The pointer potential is not associated.")
    1037             : 
    1038             :       END IF
    1039             : 
    1040        7773 :    END SUBROUTINE get_sgp_potential
    1041             : 
    1042             : ! **************************************************************************************************
    1043             : !> \brief   Initialise the coefficients of the projectors of the non-local
    1044             : !>          part of the GTH pseudopotential and the transformation matrices
    1045             : !>          for Cartesian overlap integrals between the orbital basis
    1046             : !>          functions and the projector functions.
    1047             : !> \param potential ...
    1048             : !> \date    16.10.2000
    1049             : !> \author  MK
    1050             : !> \version 1.0
    1051             : ! **************************************************************************************************
    1052        3347 :    SUBROUTINE init_cprj_ppnl(potential)
    1053             :       TYPE(gth_potential_type), POINTER                  :: potential
    1054             : 
    1055             :       INTEGER                                            :: cpx, cpy, cpz, cx, cy, cz, ico, iprj, &
    1056             :                                                             iprj_ppnl, l, lp, lprj_ppnl, nprj, px, &
    1057             :                                                             py, pz
    1058             :       REAL(KIND=dp)                                      :: alpha_ppnl, cp
    1059             : 
    1060        3347 :       nprj = 0
    1061             : 
    1062        9873 :       DO l = 0, potential%lppnl
    1063        6526 :          alpha_ppnl = potential%alpha_ppnl(l)
    1064       14210 :          DO iprj_ppnl = 1, potential%nprj_ppnl(l)
    1065        4337 :             lp = iprj_ppnl - 1
    1066        4337 :             lprj_ppnl = l + 2*lp
    1067             :             cp = SQRT(2.0_dp**(2.0_dp*REAL(lprj_ppnl, dp) + 3.5_dp)* &
    1068             :                       alpha_ppnl**(REAL(lprj_ppnl, dp) + 1.5_dp)/ &
    1069        4337 :                       (rootpi*dfac(2*lprj_ppnl + 1)))
    1070        4337 :             potential%cprj_ppnl(iprj_ppnl, l) = cp
    1071        9286 :             DO cx = 0, l
    1072       14913 :                DO cy = 0, l - cx
    1073        5627 :                   cz = l - cx - cy
    1074        5627 :                   iprj = nprj + co(cx, cy, cz)
    1075       16969 :                   DO px = 0, lp
    1076       19219 :                      DO py = 0, lp - px
    1077        7199 :                         pz = lp - px - py
    1078        7199 :                         cpx = cx + 2*px
    1079        7199 :                         cpy = cy + 2*py
    1080        7199 :                         cpz = cz + 2*pz
    1081        7199 :                         ico = coset(cpx, cpy, cpz)
    1082       13592 :                         potential%cprj(ico, iprj) = cp*fac(lp)/(fac(px)*fac(py)*fac(pz))
    1083             :                      END DO
    1084             :                   END DO
    1085             :                END DO
    1086             :             END DO
    1087       10863 :             nprj = nprj + nco(l)
    1088             :          END DO
    1089             :       END DO
    1090             : 
    1091        3347 :    END SUBROUTINE init_cprj_ppnl
    1092             : 
    1093             : ! **************************************************************************************************
    1094             : !> \brief   Initialise a GTH potential data set structure.
    1095             : !> \param potential ...
    1096             : !> \date    27.10.2000
    1097             : !> \author  MK
    1098             : !> \version 1.0
    1099             : ! **************************************************************************************************
    1100        6787 :    SUBROUTINE init_gth_potential(potential)
    1101             :       TYPE(gth_potential_type), POINTER                  :: potential
    1102             : 
    1103        6787 :       IF (.NOT. ASSOCIATED(potential)) RETURN
    1104             : 
    1105        6787 :       IF (potential%nppnl > 0) THEN
    1106             : 
    1107             :          !     *** Initialise the projector coefficients of the    ***
    1108             :          !     *** non-local part of the GTH pseudopotential and   ***
    1109             :          !     *** the transformation matrices "pgf" -> "prj_ppnl" ***
    1110             : 
    1111        3347 :          CALL init_cprj_ppnl(potential)
    1112             : 
    1113             :          !     *** Initialise the h(i,j) projector coefficients of ***
    1114             :          !     *** the non-local part of the GTH pseudopotential   ***
    1115             : 
    1116        3347 :          CALL init_vprj_ppnl(potential)
    1117             : 
    1118             :       END IF
    1119             : 
    1120             :    END SUBROUTINE init_gth_potential
    1121             : 
    1122             : ! **************************************************************************************************
    1123             : !> \brief   Initialise the h(i,j) projector coefficients of the non-local part
    1124             : !>          of the GTH pseudopotential.
    1125             : !> \param potential ...
    1126             : !> \date    24.10.2000
    1127             : !> \author  MK
    1128             : !> \version 1.0
    1129             : ! **************************************************************************************************
    1130        3347 :    SUBROUTINE init_vprj_ppnl(potential)
    1131             :       TYPE(gth_potential_type), POINTER                  :: potential
    1132             : 
    1133             :       INTEGER                                            :: i, ico, iprj, iprj_ppnl, iso, j, jco, &
    1134             :                                                             jprj, jprj_ppnl, l, nprj
    1135             : 
    1136        3347 :       nprj = 0
    1137             : 
    1138        9873 :       DO l = 0, potential%lppnl
    1139       10863 :          DO iprj_ppnl = 1, potential%nprj_ppnl(l)
    1140        4337 :             iprj = nprj + (iprj_ppnl - 1)*nco(l)
    1141       16300 :             DO jprj_ppnl = 1, potential%nprj_ppnl(l)
    1142        5437 :                jprj = nprj + (jprj_ppnl - 1)*nco(l)
    1143       16933 :                DO ico = 1, nco(l)
    1144        7159 :                   i = iprj + ico
    1145       26511 :                   DO jco = 1, nco(l)
    1146       13915 :                      j = jprj + jco
    1147       60981 :                      DO iso = 1, nso(l)
    1148             :                         potential%vprj_ppnl(i, j) = potential%vprj_ppnl(i, j) + &
    1149             :                                                     orbtramat(l)%slm(iso, ico)* &
    1150             :                                                     potential%hprj_ppnl(iprj_ppnl, &
    1151             :                                                                         jprj_ppnl, l)* &
    1152       53822 :                                                     orbtramat(l)%slm(iso, jco)
    1153             :                      END DO
    1154             :                   END DO
    1155             :                END DO
    1156             :             END DO
    1157             :          END DO
    1158        9873 :          nprj = nprj + potential%nprj_ppnl(l)*nco(l)
    1159             :       END DO
    1160             : 
    1161        3347 :    END SUBROUTINE init_vprj_ppnl
    1162             : 
    1163             : ! **************************************************************************************************
    1164             : !> \brief ...
    1165             : !> \param potential ...
    1166             : !> \param itype ...
    1167             : !> \param zeff ...
    1168             : !> \param zeff_correction ...
    1169             : ! **************************************************************************************************
    1170        3030 :    SUBROUTINE init_all_potential(potential, itype, zeff, zeff_correction)
    1171             : 
    1172             :       TYPE(all_potential_type), POINTER                  :: potential
    1173             :       CHARACTER(LEN=*), OPTIONAL                         :: itype
    1174             :       REAL(KIND=dp), OPTIONAL                            :: zeff, zeff_correction
    1175             : 
    1176             :       INTEGER                                            :: dz
    1177             : 
    1178        3030 :       IF (.NOT. ASSOCIATED(potential)) RETURN
    1179             : 
    1180        3030 :       IF (PRESENT(zeff)) potential%zeff = zeff
    1181        3030 :       IF (PRESENT(zeff_correction)) potential%zeff_correction = zeff_correction
    1182        3030 :       dz = potential%z - INT(potential%zeff - potential%zeff_correction)
    1183        1196 :       SELECT CASE (dz)
    1184             :       CASE DEFAULT
    1185             :       CASE (2)
    1186        1196 :          potential%elec_conf(0) = potential%elec_conf(0) - 2
    1187             :       CASE (10)
    1188         314 :          potential%elec_conf(0) = potential%elec_conf(0) - 4
    1189         314 :          potential%elec_conf(1) = potential%elec_conf(1) - 6
    1190             :       CASE (18)
    1191         324 :          potential%elec_conf(0) = potential%elec_conf(0) - 6
    1192         324 :          potential%elec_conf(1) = potential%elec_conf(1) - 12
    1193             :       CASE (28)
    1194         114 :          potential%elec_conf(0) = potential%elec_conf(0) - 6
    1195         114 :          potential%elec_conf(1) = potential%elec_conf(1) - 12
    1196         114 :          potential%elec_conf(2) = potential%elec_conf(2) - 10
    1197             :       CASE (30)
    1198           0 :          potential%elec_conf(0) = potential%elec_conf(0) - 8
    1199           0 :          potential%elec_conf(1) = potential%elec_conf(1) - 12
    1200           0 :          potential%elec_conf(2) = potential%elec_conf(2) - 10
    1201             :       CASE (36)
    1202          88 :          potential%elec_conf(0) = potential%elec_conf(0) - 8
    1203          88 :          potential%elec_conf(1) = potential%elec_conf(1) - 18
    1204          88 :          potential%elec_conf(2) = potential%elec_conf(2) - 10
    1205             :       CASE (46)
    1206          90 :          potential%elec_conf(0) = potential%elec_conf(0) - 8
    1207          90 :          potential%elec_conf(1) = potential%elec_conf(1) - 18
    1208          90 :          potential%elec_conf(2) = potential%elec_conf(2) - 20
    1209             :       CASE (48)
    1210           0 :          potential%elec_conf(0) = potential%elec_conf(0) - 10
    1211           0 :          potential%elec_conf(1) = potential%elec_conf(1) - 18
    1212           0 :          potential%elec_conf(2) = potential%elec_conf(2) - 20
    1213             :       CASE (54)
    1214          18 :          potential%elec_conf(0) = potential%elec_conf(0) - 10
    1215          18 :          potential%elec_conf(1) = potential%elec_conf(1) - 24
    1216          18 :          potential%elec_conf(2) = potential%elec_conf(2) - 20
    1217             :       CASE (68)
    1218          60 :          potential%elec_conf(0) = potential%elec_conf(0) - 10
    1219          60 :          potential%elec_conf(1) = potential%elec_conf(1) - 24
    1220          60 :          potential%elec_conf(2) = potential%elec_conf(2) - 20
    1221          60 :          potential%elec_conf(3) = potential%elec_conf(3) - 14
    1222             :       CASE (78)
    1223          32 :          potential%elec_conf(0) = potential%elec_conf(0) - 10
    1224          32 :          potential%elec_conf(1) = potential%elec_conf(1) - 24
    1225          32 :          potential%elec_conf(2) = potential%elec_conf(2) - 30
    1226          32 :          potential%elec_conf(3) = potential%elec_conf(3) - 14
    1227             :       CASE (80)
    1228           0 :          potential%elec_conf(0) = potential%elec_conf(0) - 12
    1229           0 :          potential%elec_conf(1) = potential%elec_conf(1) - 24
    1230           0 :          potential%elec_conf(2) = potential%elec_conf(2) - 30
    1231           0 :          potential%elec_conf(3) = potential%elec_conf(3) - 14
    1232             :       CASE (86)
    1233           0 :          potential%elec_conf(0) = potential%elec_conf(0) - 12
    1234           0 :          potential%elec_conf(1) = potential%elec_conf(1) - 30
    1235           0 :          potential%elec_conf(2) = potential%elec_conf(2) - 30
    1236           0 :          potential%elec_conf(3) = potential%elec_conf(3) - 14
    1237             :       CASE (100)
    1238           0 :          potential%elec_conf(0) = potential%elec_conf(0) - 12
    1239           0 :          potential%elec_conf(1) = potential%elec_conf(1) - 30
    1240           0 :          potential%elec_conf(2) = potential%elec_conf(2) - 30
    1241        3030 :          potential%elec_conf(3) = potential%elec_conf(3) - 28
    1242             :       END SELECT
    1243             : 
    1244        3030 :       IF (PRESENT(itype)) THEN
    1245        3030 :          IF (itype == "BARE") THEN
    1246        3030 :             potential%description(1) = "Bare Coulomb Potential"
    1247        3030 :             IF (dz > 0) THEN
    1248        2242 :                potential%description(2) = "Valence charge only"
    1249             :             ELSE
    1250         788 :                potential%description(2) = "Full atomic charge"
    1251             :             END IF
    1252             :          END IF
    1253             :       END IF
    1254             : 
    1255             :    END SUBROUTINE init_all_potential
    1256             : ! **************************************************************************************************
    1257             : !> \brief   Initialise a SGP potential data set structure.
    1258             : !> \param potential ...
    1259             : !> \version 1.0
    1260             : ! **************************************************************************************************
    1261          12 :    SUBROUTINE init_sgp_potential(potential)
    1262             :       TYPE(sgp_potential_type), POINTER                  :: potential
    1263             : 
    1264             :       INTEGER                                            :: i1, i2, j1, j2, l, la, lb, n1, n2, nnl, &
    1265             :                                                             nprj
    1266          12 :       INTEGER, ALLOCATABLE, DIMENSION(:, :)              :: ind1, ind2
    1267          12 :       REAL(KIND=dp), DIMENSION(:, :), POINTER            :: cprj, hnl
    1268          12 :       REAL(KIND=dp), DIMENSION(:, :, :), POINTER         :: cn
    1269             : 
    1270          12 :       IF (ASSOCIATED(potential)) THEN
    1271          12 :          IF (potential%nppnl > 0) THEN
    1272             :             !
    1273           6 :             IF (ASSOCIATED(potential%cprj_ppnl)) THEN
    1274           0 :                DEALLOCATE (potential%cprj_ppnl)
    1275             :             END IF
    1276           6 :             nprj = 0
    1277          12 :             DO l = 0, potential%lmax
    1278           6 :                nnl = potential%n_nonlocal
    1279          12 :                IF (potential%is_nonlocal(l)) nprj = nprj + nnl*nso(l)
    1280             :             END DO
    1281          24 :             ALLOCATE (potential%cprj_ppnl(potential%nppnl, nprj))
    1282           6 :             cprj => potential%cprj_ppnl
    1283         438 :             cprj = 0.0_dp
    1284           6 :             cn => potential%c_nonlocal
    1285           6 :             nnl = potential%n_nonlocal
    1286             :             !
    1287           6 :             n1 = 0
    1288          12 :             DO la = 0, potential%lmax
    1289          12 :                n1 = n1 + nnl*nco(la)
    1290             :             END DO
    1291          18 :             ALLOCATE (ind1(n1, 3))
    1292          54 :             n1 = 0
    1293          54 :             DO i1 = 1, nnl
    1294         102 :                DO la = 0, potential%lmax
    1295         144 :                   DO j1 = 1, nco(la)
    1296          48 :                      n1 = n1 + 1
    1297          48 :                      ind1(n1, 1) = la
    1298          48 :                      ind1(n1, 2) = j1
    1299          96 :                      ind1(n1, 3) = i1
    1300             :                   END DO
    1301             :                END DO
    1302             :             END DO
    1303             :             !
    1304             :             n2 = 0
    1305          54 :             DO i2 = 1, nnl
    1306         102 :                DO lb = 0, potential%lmax
    1307          48 :                   IF (.NOT. potential%is_nonlocal(lb)) CYCLE
    1308          96 :                   n2 = n2 + nso(lb)
    1309             :                END DO
    1310             :             END DO
    1311          18 :             ALLOCATE (ind2(n2, 3))
    1312          54 :             n2 = 0
    1313          54 :             DO i2 = 1, nnl
    1314         102 :                DO lb = 0, potential%lmax
    1315          48 :                   IF (.NOT. potential%is_nonlocal(lb)) CYCLE
    1316         144 :                   DO j2 = 1, nso(lb)
    1317          48 :                      n2 = n2 + 1
    1318          48 :                      ind2(n2, 1) = lb
    1319          48 :                      ind2(n2, 2) = j2
    1320          96 :                      ind2(n2, 3) = i2
    1321             :                   END DO
    1322             :                END DO
    1323             :             END DO
    1324             :             !
    1325          54 :             DO n1 = 1, SIZE(ind1, 1)
    1326          48 :                la = ind1(n1, 1)
    1327          48 :                j1 = ind1(n1, 2)
    1328          48 :                i1 = ind1(n1, 3)
    1329         438 :                DO n2 = 1, SIZE(ind2, 1)
    1330         384 :                   lb = ind2(n2, 1)
    1331         384 :                   IF (la /= lb) CYCLE
    1332         384 :                   j2 = ind2(n2, 2)
    1333         384 :                   i2 = ind2(n2, 3)
    1334         432 :                   cprj(n1, n2) = orbtramat(la)%c2s(j2, j1)*cn(i1, i2, la)
    1335             :                END DO
    1336             :             END DO
    1337             :             !
    1338           6 :             hnl => potential%h_nonlocal
    1339           6 :             IF (ASSOCIATED(potential%vprj_ppnl)) THEN
    1340           0 :                DEALLOCATE (potential%vprj_ppnl)
    1341             :             END IF
    1342          18 :             ALLOCATE (potential%vprj_ppnl(nprj))
    1343          54 :             potential%vprj_ppnl = 0.0_dp
    1344          54 :             DO n2 = 1, SIZE(ind2, 1)
    1345          48 :                lb = ind2(n2, 1)
    1346          48 :                i2 = ind2(n2, 3)
    1347          54 :                potential%vprj_ppnl(n2) = hnl(i2, lb)
    1348             :             END DO
    1349             :             !
    1350           6 :             DEALLOCATE (ind1, ind2)
    1351             :          END IF
    1352             :       END IF
    1353             : 
    1354          12 :    END SUBROUTINE init_sgp_potential
    1355             : 
    1356             : ! **************************************************************************************************
    1357             : !> \brief   Read an atomic all-electron potential data set.
    1358             : !> \param element_symbol ...
    1359             : !> \param potential_name ...
    1360             : !> \param potential ...
    1361             : !> \param zeff_correction ...
    1362             : !> \param para_env ...
    1363             : !> \param potential_file_name ...
    1364             : !> \param potential_section ...
    1365             : !> \param update_input ...
    1366             : !> \date    14.05.2000
    1367             : !> \author  MK
    1368             : !> \version 1.0
    1369             : ! **************************************************************************************************
    1370        1852 :    SUBROUTINE read_all_potential(element_symbol, potential_name, potential, zeff_correction, &
    1371             :                                  para_env, potential_file_name, potential_section, update_input)
    1372             : 
    1373             :       CHARACTER(LEN=*), INTENT(IN)                       :: element_symbol, potential_name
    1374             :       TYPE(all_potential_type), POINTER                  :: potential
    1375             :       REAL(KIND=dp)                                      :: zeff_correction
    1376             :       TYPE(cp_para_env_type), POINTER                    :: para_env
    1377             :       CHARACTER(len=default_path_length), INTENT(IN)     :: potential_file_name
    1378             :       TYPE(section_vals_type), POINTER                   :: potential_section
    1379             :       LOGICAL, INTENT(IN)                                :: update_input
    1380             : 
    1381             :       CHARACTER(LEN=240)                                 :: line
    1382             :       CHARACTER(LEN=242)                                 :: line2
    1383             :       CHARACTER(len=5*default_string_length)             :: line_att
    1384         926 :       CHARACTER(LEN=LEN(element_symbol))                 :: symbol
    1385         926 :       CHARACTER(LEN=LEN(element_symbol)+2)               :: symbol2
    1386         926 :       CHARACTER(LEN=LEN(potential_name))                 :: apname
    1387         926 :       CHARACTER(LEN=LEN(potential_name)+2)               :: apname2
    1388             :       INTEGER                                            :: irep, l, strlen1, strlen2
    1389         926 :       INTEGER, DIMENSION(:), POINTER                     :: elec_conf
    1390             :       LOGICAL                                            :: found, is_ok, match, read_from_input
    1391             :       REAL(KIND=dp)                                      :: alpha, r
    1392             :       TYPE(cp_parser_type), POINTER                      :: parser
    1393             :       TYPE(cp_sll_val_type), POINTER                     :: list
    1394             :       TYPE(val_type), POINTER                            :: val
    1395             : 
    1396         926 :       line2 = ""
    1397         926 :       symbol2 = ""
    1398         926 :       apname2 = ""
    1399         926 :       NULLIFY (parser)
    1400         926 :       CALL cite_reference(Krack2000)
    1401             : 
    1402         926 :       potential%name = potential_name
    1403             :       read_from_input = .FALSE.
    1404         926 :       CALL section_vals_get(potential_section, explicit=read_from_input)
    1405         926 :       IF (.NOT. read_from_input) THEN
    1406         912 :          CALL parser_create(parser, potential_file_name, para_env=para_env)
    1407             :       END IF
    1408             : 
    1409             :       !   *** Search for the requested potential in the potential file   ***
    1410             :       !   *** until the potential is found or the end of file is reached ***
    1411             : 
    1412         926 :       apname = potential_name
    1413         926 :       symbol = element_symbol
    1414         926 :       irep = 0
    1415             :       search_loop: DO
    1416        4334 :          IF (read_from_input) THEN
    1417          14 :             NULLIFY (list, val)
    1418          14 :             found = .TRUE.
    1419          14 :             CALL section_vals_list_get(potential_section, "_DEFAULT_KEYWORD_", list=list)
    1420             :          ELSE
    1421        4320 :             CALL parser_search_string(parser, TRIM(apname), .TRUE., found, line)
    1422             :          END IF
    1423        4334 :          IF (found) THEN
    1424        4334 :             CALL uppercase(symbol)
    1425        4334 :             CALL uppercase(apname)
    1426             : 
    1427        4334 :             IF (read_from_input) THEN
    1428             :                match = .TRUE.
    1429             :             ELSE
    1430             :                ! Check both the element symbol and the atomic potential name
    1431        4320 :                match = .FALSE.
    1432        4320 :                CALL uppercase(line)
    1433        4320 :                line2 = " "//line//" "
    1434        4320 :                symbol2 = " "//TRIM(symbol)//" "
    1435        4320 :                apname2 = " "//TRIM(apname)//" "
    1436        4320 :                strlen1 = LEN_TRIM(symbol2) + 1
    1437        4320 :                strlen2 = LEN_TRIM(apname2) + 1
    1438             : 
    1439        4320 :                IF ((INDEX(line2, symbol2(:strlen1)) > 0) .AND. &
    1440         912 :                    (INDEX(line2, apname2(:strlen2)) > 0)) match = .TRUE.
    1441             :             END IF
    1442        4334 :             IF (match) THEN
    1443             :                ! Read the electronic configuration
    1444         926 :                NULLIFY (elec_conf)
    1445         926 :                l = 0
    1446         926 :                CALL reallocate(elec_conf, 0, l)
    1447         926 :                IF (read_from_input) THEN
    1448          14 :                   is_ok = cp_sll_val_next(list, val)
    1449          14 :                   IF (.NOT. is_ok) &
    1450             :                      CALL cp_abort(__LOCATION__, &
    1451           0 :                                    "Error reading the Potential from input file!!")
    1452          14 :                   CALL val_get(val, c_val=line_att)
    1453          14 :                   READ (line_att, *) elec_conf(l)
    1454          14 :                   CALL remove_word(line_att)
    1455          44 :                   DO WHILE (LEN_TRIM(line_att) /= 0)
    1456          30 :                      l = l + 1
    1457          30 :                      CALL reallocate(elec_conf, 0, l)
    1458          30 :                      READ (line_att, *) elec_conf(l)
    1459          44 :                      CALL remove_word(line_att)
    1460             :                   END DO
    1461             :                ELSE
    1462         912 :                   CALL parser_get_object(parser, elec_conf(l), newline=.TRUE.)
    1463        2736 :                   DO WHILE (parser_test_next_token(parser) == "INT")
    1464        1824 :                      l = l + 1
    1465        1824 :                      CALL reallocate(elec_conf, 0, l)
    1466        1824 :                      CALL parser_get_object(parser, elec_conf(l))
    1467             :                   END DO
    1468         912 :                   irep = irep + 1
    1469         912 :                   IF (update_input) THEN
    1470        3624 :                      WRITE (line_att, '(100(1X,I0))') elec_conf
    1471             :                      CALL section_vals_val_set(potential_section, "_DEFAULT_KEYWORD_", i_rep_val=irep, &
    1472         906 :                                                c_val=TRIM(line_att))
    1473             :                   END IF
    1474             :                END IF
    1475             : 
    1476         926 :                CALL reallocate(potential%elec_conf, 0, l)
    1477        6486 :                potential%elec_conf(:) = elec_conf(:)
    1478             : 
    1479         926 :                potential%zeff_correction = zeff_correction
    1480        3706 :                potential%zeff = REAL(SUM(elec_conf), dp) + zeff_correction
    1481             : 
    1482         926 :                DEALLOCATE (elec_conf)
    1483             : 
    1484             :                ! Read r(loc) to define the exponent of the core charge
    1485             :                ! distribution and calculate the corresponding coefficient
    1486             : 
    1487         926 :                IF (read_from_input) THEN
    1488          14 :                   is_ok = cp_sll_val_next(list, val)
    1489          14 :                   IF (.NOT. is_ok) &
    1490             :                      CALL cp_abort(__LOCATION__, &
    1491           0 :                                    "Error reading the Potential from input file!!")
    1492          14 :                   CALL val_get(val, c_val=line_att)
    1493          14 :                   READ (line_att, *) r
    1494             :                ELSE
    1495         912 :                   CALL parser_get_object(parser, r, newline=.TRUE.)
    1496         912 :                   irep = irep + 1
    1497         912 :                   IF (update_input) THEN
    1498         906 :                      WRITE (line_att, '(E24.16)') r
    1499             :                      CALL section_vals_val_set(potential_section, "_DEFAULT_KEYWORD_", i_rep_val=irep, &
    1500         906 :                                                c_val=TRIM(line_att))
    1501             :                   END IF
    1502             :                END IF
    1503         926 :                alpha = 1.0_dp/(2.0_dp*r**2)
    1504             : 
    1505         926 :                potential%alpha_core_charge = alpha
    1506         926 :                potential%ccore_charge = potential%zeff*SQRT((alpha/pi)**3)
    1507             : 
    1508             :                EXIT search_loop
    1509             :             END IF
    1510             :          ELSE
    1511             :             ! Stop program, if the end of file is reached
    1512             :             CALL cp_abort(__LOCATION__, &
    1513             :                           "The requested atomic potential <"// &
    1514             :                           TRIM(potential_name)// &
    1515             :                           "> for element <"// &
    1516             :                           TRIM(symbol)// &
    1517             :                           "> was not found in the potential file <"// &
    1518           0 :                           TRIM(potential_file_name)//">")
    1519             :          END IF
    1520             :       END DO search_loop
    1521             : 
    1522         926 :       IF (.NOT. read_from_input) THEN
    1523             :          ! Dump the potential info the in potential section
    1524         912 :          IF (match .AND. update_input) THEN
    1525         906 :             irep = irep + 1
    1526         906 :             WRITE (line_att, '(A)') "         # Potential name: "//apname2(:strlen2)//" for symbol: "//symbol2(:strlen1)
    1527             :             CALL section_vals_val_set(potential_section, "_DEFAULT_KEYWORD_", i_rep_val=irep, &
    1528         906 :                                       c_val=TRIM(line_att))
    1529         906 :             irep = irep + 1
    1530         906 :             WRITE (line_att, '(A)') "         # Potential read from the potential filename: "//TRIM(potential_file_name)
    1531             :             CALL section_vals_val_set(potential_section, "_DEFAULT_KEYWORD_", i_rep_val=irep, &
    1532         906 :                                       c_val=TRIM(line_att))
    1533             :          END IF
    1534         912 :          CALL parser_release(parser)
    1535             :       END IF
    1536         926 :    END SUBROUTINE read_all_potential
    1537             : 
    1538             : ! **************************************************************************************************
    1539             : !> \brief   Read an atomic local potential data set.
    1540             : !> \param element_symbol ...
    1541             : !> \param potential_name ...
    1542             : !> \param potential ...
    1543             : !> \param para_env ...
    1544             : !> \param potential_file_name ...
    1545             : !> \param potential_section ...
    1546             : !> \param update_input ...
    1547             : !> \date    24.12.2014
    1548             : !> \author  JGH
    1549             : !> \version 1.0
    1550             : ! **************************************************************************************************
    1551          40 :    SUBROUTINE read_local_potential(element_symbol, potential_name, potential, &
    1552             :                                    para_env, potential_file_name, potential_section, update_input)
    1553             : 
    1554             :       CHARACTER(LEN=*), INTENT(IN)                       :: element_symbol, potential_name
    1555             :       TYPE(local_potential_type), POINTER                :: potential
    1556             :       TYPE(cp_para_env_type), POINTER                    :: para_env
    1557             :       CHARACTER(len=default_path_length), INTENT(IN)     :: potential_file_name
    1558             :       TYPE(section_vals_type), POINTER                   :: potential_section
    1559             :       LOGICAL, INTENT(IN)                                :: update_input
    1560             : 
    1561             :       REAL(KIND=dp), PARAMETER                           :: eps_tpot = 1.e-10_dp
    1562             : 
    1563             :       CHARACTER(LEN=240)                                 :: line
    1564             :       CHARACTER(LEN=242)                                 :: line2
    1565             :       CHARACTER(len=5*default_string_length)             :: line_att
    1566          20 :       CHARACTER(LEN=LEN(element_symbol))                 :: symbol
    1567          20 :       CHARACTER(LEN=LEN(element_symbol)+2)               :: symbol2
    1568          20 :       CHARACTER(LEN=LEN(potential_name))                 :: apname
    1569          20 :       CHARACTER(LEN=LEN(potential_name)+2)               :: apname2
    1570             :       INTEGER                                            :: igau, ipol, irep, l, ngau, npol, &
    1571             :                                                             strlen1, strlen2
    1572             :       LOGICAL                                            :: found, is_ok, match, read_from_input
    1573          20 :       REAL(KIND=dp), DIMENSION(:), POINTER               :: alpha
    1574          20 :       REAL(KIND=dp), DIMENSION(:, :), POINTER            :: cval
    1575             :       TYPE(cp_parser_type), POINTER                      :: parser
    1576             :       TYPE(cp_sll_val_type), POINTER                     :: list
    1577             :       TYPE(val_type), POINTER                            :: val
    1578             : 
    1579          20 :       line2 = ""
    1580          20 :       symbol2 = ""
    1581          20 :       apname2 = ""
    1582          20 :       NULLIFY (parser, alpha, cval)
    1583             : 
    1584          20 :       potential%name = potential_name
    1585             :       read_from_input = .FALSE.
    1586          20 :       CALL section_vals_get(potential_section, explicit=read_from_input)
    1587          20 :       IF (.NOT. read_from_input) THEN
    1588          20 :          CALL parser_create(parser, potential_file_name, para_env=para_env)
    1589             :       END IF
    1590             : 
    1591             :       !   *** Search for the requested potential in the potential file   ***
    1592             :       !   *** until the potential is found or the end of file is reached ***
    1593             : 
    1594          20 :       apname = potential_name
    1595          20 :       symbol = element_symbol
    1596          20 :       irep = 0
    1597             :       search_loop: DO
    1598          28 :          IF (read_from_input) THEN
    1599           0 :             NULLIFY (list, val)
    1600           0 :             found = .TRUE.
    1601           0 :             CALL section_vals_list_get(potential_section, "_DEFAULT_KEYWORD_", list=list)
    1602             :          ELSE
    1603          28 :             CALL parser_search_string(parser, TRIM(apname), .TRUE., found, line)
    1604             :          END IF
    1605          28 :          IF (found) THEN
    1606          28 :             CALL uppercase(symbol)
    1607          28 :             CALL uppercase(apname)
    1608             : 
    1609          28 :             IF (read_from_input) THEN
    1610             :                match = .TRUE.
    1611             :             ELSE
    1612             :                ! Check both the element symbol and the atomic potential name
    1613          28 :                match = .FALSE.
    1614          28 :                CALL uppercase(line)
    1615          28 :                line2 = " "//line//" "
    1616          28 :                symbol2 = " "//TRIM(symbol)//" "
    1617          28 :                apname2 = " "//TRIM(apname)//" "
    1618          28 :                strlen1 = LEN_TRIM(symbol2) + 1
    1619          28 :                strlen2 = LEN_TRIM(apname2) + 1
    1620             : 
    1621          28 :                IF ((INDEX(line2, symbol2(:strlen1)) > 0) .AND. &
    1622          20 :                    (INDEX(line2, apname2(:strlen2)) > 0)) match = .TRUE.
    1623             :             END IF
    1624          28 :             IF (match) THEN
    1625             : 
    1626             :                ! Read ngau and npol
    1627          20 :                IF (read_from_input) THEN
    1628           0 :                   is_ok = cp_sll_val_next(list, val)
    1629           0 :                   IF (.NOT. is_ok) &
    1630             :                      CALL cp_abort(__LOCATION__, &
    1631           0 :                                    "Error reading the Potential from input file!!")
    1632           0 :                   CALL val_get(val, c_val=line_att)
    1633           0 :                   READ (line_att, *) ngau, npol
    1634           0 :                   CALL remove_word(line_att)
    1635             :                ELSE
    1636          20 :                   CALL parser_get_object(parser, ngau, newline=.TRUE.)
    1637          20 :                   CALL parser_get_object(parser, npol)
    1638          20 :                   irep = irep + 1
    1639          20 :                   IF (update_input) THEN
    1640          20 :                      WRITE (line_att, '(2(1X,I0))') ngau, npol
    1641             :                      CALL section_vals_val_set(potential_section, "_DEFAULT_KEYWORD_", i_rep_val=irep, &
    1642          20 :                                                c_val=TRIM(line_att))
    1643             :                   END IF
    1644             :                END IF
    1645             : 
    1646          20 :                CALL reallocate(alpha, 1, ngau)
    1647          20 :                CALL reallocate(cval, 1, ngau, 1, npol)
    1648          68 :                DO igau = 1, ngau
    1649          68 :                   IF (read_from_input) THEN
    1650           0 :                      is_ok = cp_sll_val_next(list, val)
    1651           0 :                      IF (.NOT. is_ok) &
    1652             :                         CALL cp_abort(__LOCATION__, &
    1653           0 :                                       "Error reading the Potential from input file!!")
    1654           0 :                      CALL val_get(val, c_val=line_att)
    1655           0 :                      READ (line_att, *) alpha(igau), (cval(igau, ipol), ipol=1, npol)
    1656             :                   ELSE
    1657          48 :                      CALL parser_get_object(parser, alpha(igau), newline=.TRUE.)
    1658         120 :                      DO ipol = 1, npol
    1659         120 :                         CALL parser_get_object(parser, cval(igau, ipol), newline=.FALSE.)
    1660             :                      END DO
    1661          48 :                      irep = irep + 1
    1662          48 :                      IF (update_input) THEN
    1663          48 :                         WRITE (line_att, '(8(E24.16))') alpha(igau), (cval(igau, ipol), ipol=1, npol)
    1664             :                         CALL section_vals_val_set(potential_section, "_DEFAULT_KEYWORD_", i_rep_val=irep, &
    1665          48 :                                                   c_val=TRIM(line_att))
    1666             :                      END IF
    1667             :                   END IF
    1668             :                END DO
    1669          68 :                alpha = 1.0_dp/(2.0_dp*alpha**2)
    1670             : 
    1671          20 :                potential%ngau = ngau
    1672          20 :                potential%npol = npol
    1673             : 
    1674          20 :                potential%alpha => alpha
    1675          20 :                potential%cval => cval
    1676             : 
    1677          20 :                potential%radius = 0.0_dp
    1678          68 :                DO igau = 1, ngau
    1679         140 :                   DO ipol = 1, npol
    1680          72 :                      l = 2*(ipol - 1)
    1681             :                      potential%radius = MAX(potential%radius, &
    1682             :                                             exp_radius(l, alpha(igau), eps_tpot, cval(igau, ipol), &
    1683         120 :                                                        rlow=potential%radius))
    1684             :                   END DO
    1685             :                END DO
    1686             : 
    1687             :                EXIT search_loop
    1688             :             END IF
    1689             :          ELSE
    1690             :             ! Stop program, if the end of file is reached
    1691             :             CALL cp_abort(__LOCATION__, &
    1692             :                           "The requested local atomic potential <"// &
    1693             :                           TRIM(potential_name)// &
    1694             :                           "> for element <"// &
    1695             :                           TRIM(symbol)// &
    1696             :                           "> was not found in the potential file <"// &
    1697           0 :                           TRIM(potential_file_name)//">")
    1698             :          END IF
    1699             :       END DO search_loop
    1700             : 
    1701          20 :       IF (.NOT. read_from_input) THEN
    1702             :          ! Dump the potential info in the potential section
    1703          20 :          IF (match .AND. update_input) THEN
    1704          20 :             irep = irep + 1
    1705          20 :             WRITE (line_att, '(A)') "         # Potential name: "//apname2(:strlen2)//" for symbol: "//symbol2(:strlen1)
    1706             :             CALL section_vals_val_set(potential_section, "_DEFAULT_KEYWORD_", i_rep_val=irep, &
    1707          20 :                                       c_val=TRIM(line_att))
    1708          20 :             irep = irep + 1
    1709          20 :             WRITE (line_att, '(A)') "         # Potential read from the potential filename: "//TRIM(potential_file_name)
    1710             :             CALL section_vals_val_set(potential_section, "_DEFAULT_KEYWORD_", i_rep_val=irep, &
    1711          20 :                                       c_val=TRIM(line_att))
    1712             :          END IF
    1713          20 :          CALL parser_release(parser)
    1714             :       END IF
    1715             : 
    1716          20 :    END SUBROUTINE read_local_potential
    1717             : 
    1718             : ! **************************************************************************************************
    1719             : !> \brief   Read an atomic GTH potential data set.
    1720             : !> \param element_symbol ...
    1721             : !> \param potential_name ...
    1722             : !> \param potential ...
    1723             : !> \param zeff_correction ...
    1724             : !> \param para_env ...
    1725             : !> \param potential_file_name ...
    1726             : !> \param potential_section ...
    1727             : !> \param update_input ...
    1728             : !> \date    14.05.2000
    1729             : !> \par  Literature
    1730             : !>         - S. Goedecker, M. Teter and J. Hutter,
    1731             : !>                Phys. Rev. B 54, 1703 (1996)
    1732             : !>         - C. Hartwigsen, S. Goedecker and J. Hutter,
    1733             : !>                Phys. Rev. B 58, 3641 (1998)
    1734             : !> \author  MK
    1735             : !> \version 1.0
    1736             : ! **************************************************************************************************
    1737       13686 :    SUBROUTINE read_gth_potential(element_symbol, potential_name, potential, zeff_correction, &
    1738             :                                  para_env, potential_file_name, potential_section, update_input)
    1739             : 
    1740             :       CHARACTER(LEN=*), INTENT(IN)                       :: element_symbol, potential_name
    1741             :       TYPE(gth_potential_type), POINTER                  :: potential
    1742             :       REAL(KIND=dp), INTENT(IN)                          :: zeff_correction
    1743             :       TYPE(cp_para_env_type), POINTER                    :: para_env
    1744             :       CHARACTER(len=default_path_length), INTENT(IN)     :: potential_file_name
    1745             :       TYPE(section_vals_type), POINTER                   :: potential_section
    1746             :       LOGICAL, INTENT(IN)                                :: update_input
    1747             : 
    1748             :       CHARACTER(LEN=240)                                 :: line
    1749             :       CHARACTER(LEN=242)                                 :: line2
    1750             :       CHARACTER(len=5*default_string_length)             :: line_att
    1751        6843 :       CHARACTER(LEN=LEN(element_symbol))                 :: symbol
    1752        6843 :       CHARACTER(LEN=LEN(element_symbol)+2)               :: symbol2
    1753        6843 :       CHARACTER(LEN=LEN(potential_name))                 :: apname
    1754        6843 :       CHARACTER(LEN=LEN(potential_name)+2)               :: apname2
    1755             :       INTEGER                                            :: i, ic, ipot, irep, istr, j, l, lppnl, &
    1756             :                                                             lprj_ppnl_max, maxlppl, n, nppnl, &
    1757             :                                                             nprj_ppnl, nprj_ppnl_max, strlen1, &
    1758             :                                                             strlen2
    1759        6843 :       INTEGER, DIMENSION(:), POINTER                     :: elec_conf
    1760             :       LOGICAL                                            :: found, is_ok, match, read_from_input
    1761             :       REAL(KIND=dp)                                      :: alpha, ci, r, rc2
    1762        6843 :       REAL(KIND=dp), DIMENSION(:), POINTER               :: tmp_vals
    1763        6843 :       REAL(KIND=dp), DIMENSION(:, :, :), POINTER         :: hprj_ppnl
    1764             :       TYPE(cp_parser_type), POINTER                      :: parser
    1765             :       TYPE(cp_sll_val_type), POINTER                     :: list
    1766             :       TYPE(val_type), POINTER                            :: val
    1767             : 
    1768        6843 :       line2 = ""
    1769        6843 :       symbol2 = ""
    1770        6843 :       apname2 = ""
    1771        6843 :       NULLIFY (parser, tmp_vals)
    1772        6843 :       CALL cite_reference(Goedecker1996)
    1773        6843 :       CALL cite_reference(Hartwigsen1998)
    1774        6843 :       CALL cite_reference(Krack2005)
    1775             : 
    1776        6843 :       potential%name = potential_name
    1777        6843 :       potential%aliases = potential_name
    1778             :       read_from_input = .FALSE.
    1779        6843 :       CALL section_vals_get(potential_section, explicit=read_from_input)
    1780        6843 :       IF (.NOT. read_from_input) THEN
    1781        6197 :          CALL parser_create(parser, potential_file_name, para_env=para_env)
    1782             :       END IF
    1783             : 
    1784             :       !initialize extended form
    1785        6843 :       potential%lpotextended = .FALSE.
    1786        6843 :       potential%nexp_lpot = 0
    1787        6843 :       potential%lsdpot = .FALSE.
    1788        6843 :       potential%nexp_lsd = 0
    1789        6843 :       potential%nlcc = .FALSE.
    1790        6843 :       potential%nexp_nlcc = 0
    1791             : 
    1792             :       !   *** Search for the requested potential in the potential file   ***
    1793             :       !   *** until the potential is found or the end of file is reached ***
    1794             : 
    1795        6843 :       apname = potential_name
    1796        6843 :       symbol = element_symbol
    1797        6843 :       irep = 0
    1798             :       search_loop: DO
    1799        8717 :          IF (read_from_input) THEN
    1800         646 :             NULLIFY (list, val)
    1801         646 :             found = .TRUE.
    1802         646 :             CALL section_vals_list_get(potential_section, "_DEFAULT_KEYWORD_", list=list)
    1803             :          ELSE
    1804        8071 :             CALL parser_search_string(parser, TRIM(apname), .TRUE., found, line)
    1805             :          END IF
    1806        8717 :          IF (found) THEN
    1807        8717 :             CALL uppercase(symbol)
    1808        8717 :             CALL uppercase(apname)
    1809        8717 :             IF (read_from_input) THEN
    1810             :                match = .TRUE.
    1811             :             ELSE
    1812             :                !       *** Check both the element symbol and the atomic potential name ***
    1813        8071 :                match = .FALSE.
    1814        8071 :                CALL uppercase(line)
    1815        8071 :                line2 = " "//line//" "
    1816        8071 :                symbol2 = " "//TRIM(symbol)//" "
    1817        8071 :                apname2 = " "//TRIM(apname)//" "
    1818        8071 :                strlen1 = LEN_TRIM(symbol2) + 1
    1819        8071 :                strlen2 = LEN_TRIM(apname2) + 1
    1820             : 
    1821        8071 :                i = INDEX(line2, symbol2(:strlen1))
    1822        8071 :                j = INDEX(line2, apname2(:strlen2))
    1823        8071 :                IF (i > 0 .AND. j > 0) THEN
    1824        6197 :                   match = .TRUE.
    1825        6197 :                   i = i + 1 + INDEX(line2(i + 1:), " ")
    1826        6197 :                   potential%aliases = line2(i:) ! copy all names into aliases field
    1827             :                END IF
    1828             :             END IF
    1829        8717 :             IF (match) THEN
    1830             :                !         *** Read the electronic configuration ***
    1831        6843 :                NULLIFY (elec_conf)
    1832        6843 :                l = 0
    1833        6843 :                CALL reallocate(elec_conf, 0, l)
    1834        6843 :                IF (read_from_input) THEN
    1835         646 :                   is_ok = cp_sll_val_next(list, val)
    1836         646 :                   IF (.NOT. is_ok) &
    1837             :                      CALL cp_abort(__LOCATION__, &
    1838           0 :                                    "Error reading the Potential from input file!!")
    1839         646 :                   CALL val_get(val, c_val=line_att)
    1840         646 :                   READ (line_att, *) elec_conf(l)
    1841         646 :                   CALL remove_word(line_att)
    1842         894 :                   DO WHILE (LEN_TRIM(line_att) /= 0)
    1843         248 :                      l = l + 1
    1844         248 :                      CALL reallocate(elec_conf, 0, l)
    1845         248 :                      READ (line_att, *) elec_conf(l)
    1846         894 :                      CALL remove_word(line_att)
    1847             :                   END DO
    1848             :                ELSE
    1849        6197 :                   CALL parser_get_object(parser, elec_conf(l), newline=.TRUE.)
    1850       10650 :                   DO WHILE (parser_test_next_token(parser) == "INT")
    1851        4453 :                      l = l + 1
    1852        4453 :                      CALL reallocate(elec_conf, 0, l)
    1853        4453 :                      CALL parser_get_object(parser, elec_conf(l))
    1854             :                   END DO
    1855        6197 :                   irep = irep + 1
    1856        6197 :                   IF (update_input) THEN
    1857       16781 :                      WRITE (line_att, '(100(1X,I0))') elec_conf
    1858             :                      CALL section_vals_val_set(potential_section, "_DEFAULT_KEYWORD_", i_rep_val=irep, &
    1859        6171 :                                                c_val=TRIM(line_att))
    1860             :                   END IF
    1861             :                END IF
    1862             : 
    1863        6843 :                CALL reallocate(potential%elec_conf, 0, l)
    1864       29931 :                potential%elec_conf(:) = elec_conf(:)
    1865             : 
    1866        6843 :                potential%zeff_correction = zeff_correction
    1867       18387 :                potential%zeff = REAL(SUM(elec_conf), dp) + zeff_correction
    1868             : 
    1869        6843 :                DEALLOCATE (elec_conf)
    1870             : 
    1871             :                !         *** Read r(loc) to define the exponent of the core charge    ***
    1872             :                !         *** distribution and calculate the corresponding coefficient ***
    1873             : 
    1874        6843 :                IF (read_from_input) THEN
    1875         646 :                   is_ok = cp_sll_val_next(list, val)
    1876         646 :                   IF (.NOT. is_ok) &
    1877             :                      CALL cp_abort(__LOCATION__, &
    1878           0 :                                    "Error reading the Potential from input file!!")
    1879         646 :                   CALL val_get(val, c_val=line_att)
    1880         646 :                   READ (line_att, *) r
    1881         646 :                   CALL remove_word(line_att)
    1882             :                ELSE
    1883        6197 :                   line_att = ""
    1884        6197 :                   CALL parser_get_object(parser, r, newline=.TRUE.)
    1885        6197 :                   istr = LEN_TRIM(line_att) + 1
    1886        6197 :                   WRITE (line_att(istr:), '(E24.16)') r
    1887             :                END IF
    1888        6843 :                alpha = 1.0_dp/(2.0_dp*r**2)
    1889             : 
    1890        6843 :                potential%alpha_core_charge = alpha
    1891        6843 :                potential%ccore_charge = potential%zeff*SQRT((alpha/pi)**3)
    1892             : 
    1893        6843 :                potential%alpha_ppl = alpha
    1894        6843 :                potential%cerf_ppl = potential%zeff*SQRT((alpha/pi)**3)
    1895             : 
    1896             :                !         *** Read the parameters for the local part ***
    1897             :                !         *** of the GTH pseudopotential (ppl)       ***
    1898             : 
    1899        6843 :                IF (read_from_input) THEN
    1900         646 :                   READ (line_att, *) n
    1901         646 :                   CALL remove_word(line_att)
    1902             :                ELSE
    1903        6197 :                   CALL parser_get_object(parser, n)
    1904        6197 :                   istr = LEN_TRIM(line_att) + 1
    1905        6197 :                   WRITE (line_att(istr:), '(1X,I0)') n
    1906             :                END IF
    1907        6843 :                potential%nexp_ppl = n
    1908        6843 :                CALL reallocate(potential%cexp_ppl, 1, n)
    1909             : 
    1910       20205 :                DO i = 1, n
    1911       13362 :                   IF (read_from_input) THEN
    1912        1290 :                      READ (line_att, *) ci
    1913        1290 :                      CALL remove_word(line_att)
    1914             :                   ELSE
    1915       12072 :                      CALL parser_get_object(parser, ci)
    1916       12072 :                      istr = LEN_TRIM(line_att) + 1
    1917       12072 :                      WRITE (line_att(istr:), '(E24.16)') ci
    1918             :                   END IF
    1919       13362 :                   rc2 = (2.0_dp*potential%alpha_ppl)
    1920       20205 :                   potential%cexp_ppl(i) = rc2**(i - 1)*ci
    1921             :                END DO
    1922             : 
    1923        6843 :                IF (.NOT. read_from_input) THEN
    1924        6197 :                   irep = irep + 1
    1925        6197 :                   IF (update_input) THEN
    1926             :                      CALL section_vals_val_set(potential_section, "_DEFAULT_KEYWORD_", i_rep_val=irep, &
    1927        6171 :                                                c_val=TRIM(line_att))
    1928             :                   END IF
    1929        6197 :                   line_att = ""
    1930             :                ELSE
    1931         646 :                   IF (LEN_TRIM(line_att) /= 0) THEN
    1932             :                      CALL cp_abort(__LOCATION__, &
    1933           0 :                                    "Error reading the Potential from input file!!")
    1934             :                   END IF
    1935             :                END IF
    1936        6843 :                maxlppl = 2*(n - 1)
    1937             : 
    1938        6843 :                IF (maxlppl > -1) CALL init_orbital_pointers(maxlppl)
    1939             : 
    1940             :                ! Read extended form of GTH pseudopotential
    1941             :                ! local potential, NLCC, LSD potential
    1942        6843 :                IF (read_from_input) THEN
    1943             :                   DO
    1944         652 :                      is_ok = cp_sll_val_next(list, val)
    1945         652 :                      CPASSERT(is_ok)
    1946         652 :                      CALL val_get(val, c_val=line_att)
    1947        1298 :                      IF (INDEX(line_att, "LPOT") /= 0) THEN
    1948           0 :                         potential%lpotextended = .TRUE.
    1949           0 :                         CALL remove_word(line_att)
    1950           0 :                         READ (line_att, *) potential%nexp_lpot
    1951           0 :                         n = potential%nexp_lpot
    1952           0 :                         maxlppl = 2*(n - 1)
    1953           0 :                         IF (maxlppl > -1) CALL init_orbital_pointers(maxlppl)
    1954           0 :                         NULLIFY (potential%alpha_lpot, potential%nct_lpot, potential%cval_lpot)
    1955           0 :                         CALL reallocate(potential%alpha_lpot, 1, n)
    1956           0 :                         CALL reallocate(potential%nct_lpot, 1, n)
    1957           0 :                         CALL reallocate(potential%cval_lpot, 1, 4, 1, n)
    1958           0 :                         DO ipot = 1, potential%nexp_lpot
    1959           0 :                            is_ok = cp_sll_val_next(list, val)
    1960           0 :                            CPASSERT(is_ok)
    1961           0 :                            CALL val_get(val, c_val=line_att)
    1962           0 :                            READ (line_att, *) r
    1963           0 :                            potential%alpha_lpot(ipot) = 0.5_dp/(r*r)
    1964           0 :                            CALL remove_word(line_att)
    1965           0 :                            READ (line_att, *) potential%nct_lpot(ipot)
    1966           0 :                            CALL remove_word(line_att)
    1967           0 :                            DO ic = 1, potential%nct_lpot(ipot)
    1968           0 :                               READ (line_att, *) ci
    1969           0 :                               rc2 = (2._dp*potential%alpha_lpot(ipot))**(ic - 1)
    1970           0 :                               potential%cval_lpot(ic, ipot) = ci*rc2
    1971           0 :                               CALL remove_word(line_att)
    1972             :                            END DO
    1973             :                         END DO
    1974         652 :                      ELSEIF (INDEX(line_att, "NLCC") /= 0) THEN
    1975           6 :                         potential%nlcc = .TRUE.
    1976           6 :                         CALL remove_word(line_att)
    1977           6 :                         READ (line_att, *) potential%nexp_nlcc
    1978           6 :                         n = potential%nexp_nlcc
    1979           6 :                         NULLIFY (potential%alpha_nlcc, potential%nct_nlcc, potential%cval_nlcc)
    1980           6 :                         CALL reallocate(potential%alpha_nlcc, 1, n)
    1981           6 :                         CALL reallocate(potential%nct_nlcc, 1, n)
    1982           6 :                         CALL reallocate(potential%cval_nlcc, 1, 4, 1, n)
    1983          12 :                         DO ipot = 1, potential%nexp_nlcc
    1984           6 :                            is_ok = cp_sll_val_next(list, val)
    1985           6 :                            CPASSERT(is_ok)
    1986           6 :                            CALL val_get(val, c_val=line_att)
    1987           6 :                            READ (line_att, *) potential%alpha_nlcc(ipot)
    1988           6 :                            CALL remove_word(line_att)
    1989           6 :                            READ (line_att, *) potential%nct_nlcc(ipot)
    1990           6 :                            CALL remove_word(line_att)
    1991          22 :                            DO ic = 1, potential%nct_nlcc(ipot)
    1992          10 :                               READ (line_att, *) potential%cval_nlcc(ic, ipot)
    1993             :                               !make it compatible with bigdft style
    1994          10 :                               potential%cval_nlcc(ic, ipot) = potential%cval_nlcc(ic, ipot)/(4.0_dp*pi)
    1995          16 :                               CALL remove_word(line_att)
    1996             :                            END DO
    1997             :                         END DO
    1998         646 :                      ELSEIF (INDEX(line_att, "LSD") /= 0) THEN
    1999           0 :                         potential%lsdpot = .TRUE.
    2000           0 :                         CALL remove_word(line_att)
    2001           0 :                         READ (line_att, *) potential%nexp_lsd
    2002           0 :                         n = potential%nexp_lsd
    2003           0 :                         NULLIFY (potential%alpha_lsd, potential%nct_lsd, potential%cval_lsd)
    2004           0 :                         CALL reallocate(potential%alpha_lsd, 1, n)
    2005           0 :                         CALL reallocate(potential%nct_lsd, 1, n)
    2006           0 :                         CALL reallocate(potential%cval_lsd, 1, 4, 1, n)
    2007           0 :                         DO ipot = 1, potential%nexp_lsd
    2008           0 :                            is_ok = cp_sll_val_next(list, val)
    2009           0 :                            CPASSERT(is_ok)
    2010           0 :                            CALL val_get(val, c_val=line_att)
    2011           0 :                            READ (line_att, *) r
    2012           0 :                            potential%alpha_lsd(ipot) = 0.5_dp/(r*r)
    2013           0 :                            CALL remove_word(line_att)
    2014           0 :                            READ (line_att, *) potential%nct_lsd(ipot)
    2015           0 :                            CALL remove_word(line_att)
    2016           0 :                            DO ic = 1, potential%nct_lsd(ipot)
    2017           0 :                               READ (line_att, *) ci
    2018           0 :                               rc2 = (2._dp*potential%alpha_lsd(ipot))**(ic - 1)
    2019           0 :                               potential%cval_lsd(ic, ipot) = ci*rc2
    2020           0 :                               CALL remove_word(line_att)
    2021             :                            END DO
    2022             :                         END DO
    2023             :                      ELSE
    2024             :                         EXIT
    2025             :                      END IF
    2026             :                   END DO
    2027             :                ELSE
    2028             :                   DO
    2029        6217 :                      CALL parser_get_next_line(parser, 1)
    2030        6217 :                      IF (parser_test_next_token(parser) == "INT") THEN
    2031             :                         EXIT
    2032        6237 :                      ELSEIF (parser_test_next_token(parser) == "STR") THEN
    2033          20 :                         CALL parser_get_object(parser, line)
    2034          20 :                         IF (INDEX(LINE, "LPOT") /= 0) THEN
    2035             :                            ! local potential
    2036           8 :                            potential%lpotextended = .TRUE.
    2037           8 :                            CALL parser_get_object(parser, potential%nexp_lpot)
    2038           8 :                            n = potential%nexp_lpot
    2039           8 :                            NULLIFY (potential%alpha_lpot, potential%nct_lpot, potential%cval_lpot)
    2040           8 :                            CALL reallocate(potential%alpha_lpot, 1, n)
    2041           8 :                            CALL reallocate(potential%nct_lpot, 1, n)
    2042           8 :                            CALL reallocate(potential%cval_lpot, 1, 4, 1, n)
    2043             :                            ! add to input section
    2044           8 :                            irep = irep + 1
    2045           8 :                            IF (update_input) THEN
    2046           8 :                               WRITE (line_att, '(A,1X,I0)') "LPOT", n
    2047             :                               CALL section_vals_val_set(potential_section, "_DEFAULT_KEYWORD_", i_rep_val=irep, &
    2048           8 :                                                         c_val=TRIM(line_att))
    2049             :                            END IF
    2050          20 :                            DO ipot = 1, potential%nexp_lpot
    2051          12 :                               CALL parser_get_object(parser, r, newline=.TRUE.)
    2052          12 :                               potential%alpha_lpot(ipot) = 0.5_dp/(r*r)
    2053          12 :                               CALL parser_get_object(parser, potential%nct_lpot(ipot))
    2054          12 :                               CALL reallocate(tmp_vals, 1, potential%nct_lpot(ipot))
    2055          38 :                               DO ic = 1, potential%nct_lpot(ipot)
    2056          26 :                                  CALL parser_get_object(parser, ci)
    2057          26 :                                  tmp_vals(ic) = ci
    2058          26 :                                  rc2 = (2._dp*potential%alpha_lpot(ipot))**(ic - 1)
    2059          38 :                                  potential%cval_lpot(ic, ipot) = ci*rc2
    2060             :                               END DO
    2061             :                               ! add to input section
    2062          12 :                               irep = irep + 1
    2063          20 :                               IF (update_input) THEN
    2064          12 :                                  WRITE (line_att, '(E24.16,1X,I0,100(1X,E24.16))') r, potential%nct_lpot(ipot), &
    2065          24 :                                     tmp_vals(1:potential%nct_lpot(ipot))
    2066             :                                  CALL section_vals_val_set(potential_section, "_DEFAULT_KEYWORD_", i_rep_val=irep, &
    2067          12 :                                                            c_val=TRIM(line_att))
    2068             :                               END IF
    2069             :                            END DO
    2070          12 :                         ELSEIF (INDEX(LINE, "NLCC") /= 0) THEN
    2071             :                            ! NLCC
    2072          12 :                            potential%nlcc = .TRUE.
    2073          12 :                            CALL parser_get_object(parser, potential%nexp_nlcc)
    2074          12 :                            n = potential%nexp_nlcc
    2075          12 :                            NULLIFY (potential%alpha_nlcc, potential%nct_nlcc, potential%cval_nlcc)
    2076          12 :                            CALL reallocate(potential%alpha_nlcc, 1, n)
    2077          12 :                            CALL reallocate(potential%nct_nlcc, 1, n)
    2078          12 :                            CALL reallocate(potential%cval_nlcc, 1, 4, 1, n)
    2079             :                            ! add to input section
    2080          12 :                            WRITE (line_att, '(A,1X,I0)') "NLCC", n
    2081          12 :                            irep = irep + 1
    2082             :                            CALL section_vals_val_set(potential_section, "_DEFAULT_KEYWORD_", i_rep_val=irep, &
    2083          12 :                                                      c_val=TRIM(line_att))
    2084          24 :                            DO ipot = 1, potential%nexp_nlcc
    2085          12 :                               CALL parser_get_object(parser, potential%alpha_nlcc(ipot), newline=.TRUE.)
    2086          12 :                               CALL parser_get_object(parser, potential%nct_nlcc(ipot))
    2087          12 :                               CALL reallocate(tmp_vals, 1, potential%nct_nlcc(ipot))
    2088          24 :                               DO ic = 1, potential%nct_nlcc(ipot)
    2089          12 :                                  CALL parser_get_object(parser, potential%cval_nlcc(ic, ipot))
    2090          12 :                                  tmp_vals(ic) = potential%cval_nlcc(ic, ipot)
    2091             :                                  !make it compatible with bigdft style
    2092          24 :                                  potential%cval_nlcc(ic, ipot) = potential%cval_nlcc(ic, ipot)/(4.0_dp*pi)
    2093             :                               END DO
    2094             :                               ! add to input section
    2095          12 :                               irep = irep + 1
    2096          24 :                               IF (update_input) THEN
    2097             :                                  WRITE (line_att, '(E24.16,1X,I0,100(1X,E24.16))') &
    2098          12 :                                     potential%alpha_nlcc(ipot), potential%nct_nlcc(ipot), &
    2099          24 :                                     tmp_vals(1:potential%nct_nlcc(ipot))
    2100             :                                  CALL section_vals_val_set(potential_section, "_DEFAULT_KEYWORD_", i_rep_val=irep, &
    2101          12 :                                                            c_val=TRIM(line_att))
    2102             :                               END IF
    2103             :                            END DO
    2104           0 :                         ELSEIF (INDEX(LINE, "LSD") /= 0) THEN
    2105             :                            ! LSD potential
    2106           0 :                            potential%lsdpot = .TRUE.
    2107           0 :                            CALL parser_get_object(parser, potential%nexp_lsd)
    2108           0 :                            n = potential%nexp_lsd
    2109           0 :                            NULLIFY (potential%alpha_lsd, potential%nct_lsd, potential%cval_lsd)
    2110           0 :                            CALL reallocate(potential%alpha_lsd, 1, n)
    2111           0 :                            CALL reallocate(potential%nct_lsd, 1, n)
    2112           0 :                            CALL reallocate(potential%cval_lsd, 1, 4, 1, n)
    2113             :                            ! add to input section
    2114           0 :                            irep = irep + 1
    2115           0 :                            IF (update_input) THEN
    2116           0 :                               WRITE (line_att, '(A,1X,I0)') "LSD", n
    2117             :                               CALL section_vals_val_set(potential_section, "_DEFAULT_KEYWORD_", i_rep_val=irep, &
    2118           0 :                                                         c_val=TRIM(line_att))
    2119             :                            END IF
    2120           0 :                            DO ipot = 1, potential%nexp_lsd
    2121           0 :                               CALL parser_get_object(parser, r, newline=.TRUE.)
    2122           0 :                               potential%alpha_lsd(ipot) = 0.5_dp/(r*r)
    2123           0 :                               CALL parser_get_object(parser, potential%nct_lsd(ipot))
    2124           0 :                               CALL reallocate(tmp_vals, 1, potential%nct_lsd(ipot))
    2125           0 :                               DO ic = 1, potential%nct_lsd(ipot)
    2126           0 :                                  CALL parser_get_object(parser, ci)
    2127           0 :                                  tmp_vals(ic) = ci
    2128           0 :                                  rc2 = (2._dp*potential%alpha_lsd(ipot))**(ic - 1)
    2129           0 :                                  potential%cval_lsd(ic, ipot) = ci*rc2
    2130             :                               END DO
    2131             :                               ! add to input section
    2132           0 :                               irep = irep + 1
    2133           0 :                               IF (update_input) THEN
    2134           0 :                                  WRITE (line_att, '(E24.16,1X,I0,100(1X,E24.16))') r, potential%nct_lsd(ipot), &
    2135           0 :                                     tmp_vals(1:potential%nct_lsd(ipot))
    2136             :                                  CALL section_vals_val_set(potential_section, "_DEFAULT_KEYWORD_", i_rep_val=irep, &
    2137           0 :                                                            c_val=TRIM(line_att))
    2138             :                               END IF
    2139             :                            END DO
    2140             :                         ELSE
    2141             :                            CALL cp_abort(__LOCATION__, &
    2142             :                                          "Syntax error for <"// &
    2143             :                                          TRIM(element_symbol)// &
    2144             :                                          "> in the atomic potential <"// &
    2145             :                                          TRIM(potential_name)// &
    2146             :                                          "> potential file <"// &
    2147             :                                          TRIM(potential_file_name)//">: "// &
    2148             :                                          "Expected LPOT/NLCC/LSD keyword, got: <"// &
    2149           0 :                                          TRIM(line)//">")
    2150             :                         END IF
    2151             :                      ELSE
    2152           0 :                         CALL parser_get_object(parser, line)
    2153             :                         CALL cp_abort(__LOCATION__, &
    2154             :                                       "Syntax error for <"// &
    2155             :                                       TRIM(element_symbol)// &
    2156             :                                       "> in the atomic potential <"// &
    2157             :                                       TRIM(potential_name)// &
    2158             :                                       "> potential file <"// &
    2159             :                                       TRIM(potential_file_name)//">: "// &
    2160             :                                       "Expected LPOT/NLCC/LSD keyword or INTEGER, got: <"// &
    2161          20 :                                       TRIM(line)//">")
    2162             :                      END IF
    2163             :                   END DO
    2164             :                END IF
    2165             :                !         *** Read the parameters for the non-local  ***
    2166             :                !         *** part of the GTH pseudopotential (ppnl) ***
    2167        6843 :                IF (read_from_input) THEN
    2168         646 :                   READ (line_att, *) n
    2169         646 :                   CALL remove_word(line_att)
    2170             :                ELSE
    2171        6197 :                   CALL parser_get_object(parser, n)
    2172        6197 :                   irep = irep + 1
    2173        6197 :                   IF (update_input) THEN
    2174        6171 :                      WRITE (line_att, '(1X,I0)') n
    2175             :                      CALL section_vals_val_set(potential_section, "_DEFAULT_KEYWORD_", i_rep_val=irep, &
    2176        6171 :                                                c_val=TRIM(line_att))
    2177             :                   END IF
    2178             :                END IF
    2179        6843 :                potential%lppnl = n - 1
    2180        6843 :                potential%nppnl = 0
    2181             : 
    2182        6843 :                potential%lprj_ppnl_max = n - 1
    2183        6843 :                potential%nprj_ppnl_max = 0
    2184             : 
    2185        6843 :                IF (n > 0) THEN
    2186             : 
    2187        3347 :                   lppnl = potential%lppnl
    2188        3347 :                   nppnl = potential%nppnl
    2189             : 
    2190        3347 :                   CALL init_orbital_pointers(lppnl)
    2191             : 
    2192        3347 :                   NULLIFY (hprj_ppnl)
    2193             : 
    2194             :                   ! Load the parameter for n non-local projectors
    2195             : 
    2196        3347 :                   CALL reallocate(potential%alpha_ppnl, 0, lppnl)
    2197        3347 :                   CALL reallocate(potential%nprj_ppnl, 0, lppnl)
    2198             : 
    2199        3347 :                   lprj_ppnl_max = -1
    2200        3347 :                   nprj_ppnl_max = 0
    2201             : 
    2202        9873 :                   DO l = 0, lppnl
    2203        6526 :                      IF (read_from_input) THEN
    2204         444 :                         is_ok = cp_sll_val_next(list, val)
    2205         444 :                         IF (.NOT. is_ok) &
    2206             :                            CALL cp_abort(__LOCATION__, &
    2207           0 :                                          "Error reading the Potential from input file!!")
    2208         444 :                         CALL val_get(val, c_val=line_att)
    2209         444 :                         READ (line_att, *) r
    2210         444 :                         CALL remove_word(line_att)
    2211         444 :                         READ (line_att, *) nprj_ppnl
    2212         444 :                         CALL remove_word(line_att)
    2213             :                      ELSE
    2214        6082 :                         line_att = ""
    2215        6082 :                         CALL parser_get_object(parser, r, newline=.TRUE.)
    2216        6082 :                         CALL parser_get_object(parser, nprj_ppnl)
    2217        6082 :                         istr = LEN_TRIM(line_att) + 1
    2218        6082 :                         WRITE (line_att(istr:), '(E24.16,1X,I0)') r, nprj_ppnl
    2219             :                      END IF
    2220        6526 :                      IF (r == 0.0_dp .AND. nprj_ppnl /= 0) THEN
    2221             :                         CALL cp_abort(__LOCATION__, &
    2222             :                                       "An error was detected in the atomic potential <"// &
    2223             :                                       TRIM(potential_name)// &
    2224             :                                       "> potential file <"// &
    2225           0 :                                       TRIM(potential_file_name)//">")
    2226             :                      END IF
    2227        6526 :                      potential%alpha_ppnl(l) = 0.0_dp
    2228        6526 :                      IF (r /= 0.0_dp .AND. n /= 0) potential%alpha_ppnl(l) = 1.0_dp/(2.0_dp*r**2)
    2229        6526 :                      potential%nprj_ppnl(l) = nprj_ppnl
    2230        6526 :                      nppnl = nppnl + nprj_ppnl*nco(l)
    2231        6526 :                      IF (nprj_ppnl > nprj_ppnl_max) THEN
    2232        3347 :                         nprj_ppnl_max = nprj_ppnl
    2233             :                         CALL reallocate(hprj_ppnl, 1, nprj_ppnl_max, &
    2234             :                                         1, nprj_ppnl_max, &
    2235        3347 :                                         0, lppnl)
    2236             :                      END IF
    2237       10863 :                      DO i = 1, nprj_ppnl
    2238        4337 :                         IF (i == 1) THEN
    2239        3819 :                            IF (read_from_input) THEN
    2240         238 :                               READ (line_att, *) hprj_ppnl(i, i, l)
    2241         238 :                               CALL remove_word(line_att)
    2242             :                            ELSE
    2243        3581 :                               CALL parser_get_object(parser, hprj_ppnl(i, i, l))
    2244        3581 :                               istr = LEN_TRIM(line_att) + 1
    2245        3581 :                               WRITE (line_att(istr:), '(E24.16)') hprj_ppnl(i, i, l)
    2246             :                            END IF
    2247             :                         ELSE
    2248         518 :                            IF (read_from_input) THEN
    2249          20 :                               IF (LEN_TRIM(line_att) /= 0) &
    2250             :                                  CALL cp_abort(__LOCATION__, &
    2251           0 :                                                "Error reading the Potential from input file!!")
    2252          20 :                               is_ok = cp_sll_val_next(list, val)
    2253          20 :                               IF (.NOT. is_ok) &
    2254             :                                  CALL cp_abort(__LOCATION__, &
    2255           0 :                                                "Error reading the Potential from input file!!")
    2256          20 :                               CALL val_get(val, c_val=line_att)
    2257          20 :                               READ (line_att, *) hprj_ppnl(i, i, l)
    2258          20 :                               CALL remove_word(line_att)
    2259             :                            ELSE
    2260         498 :                               irep = irep + 1
    2261             :                               CALL section_vals_val_set(potential_section, "_DEFAULT_KEYWORD_", i_rep_val=irep, &
    2262         498 :                                                         c_val=TRIM(line_att))
    2263         498 :                               line_att = ""
    2264         498 :                               CALL parser_get_object(parser, hprj_ppnl(i, i, l), newline=.TRUE.)
    2265         498 :                               istr = LEN_TRIM(line_att) + 1
    2266         498 :                               WRITE (line_att(istr:), '(E24.16)') hprj_ppnl(i, i, l)
    2267             :                            END IF
    2268             :                         END IF
    2269       11413 :                         DO j = i + 1, nprj_ppnl
    2270        4887 :                            IF (read_from_input) THEN
    2271          24 :                               READ (line_att, *) hprj_ppnl(i, j, l)
    2272          24 :                               CALL remove_word(line_att)
    2273             :                            ELSE
    2274         526 :                               CALL parser_get_object(parser, hprj_ppnl(i, j, l))
    2275         526 :                               istr = LEN_TRIM(line_att) + 1
    2276         526 :                               WRITE (line_att(istr:), '(E24.16)') hprj_ppnl(i, j, l)
    2277             :                            END IF
    2278             :                         END DO
    2279             :                      END DO
    2280        6526 :                      IF (.NOT. read_from_input) THEN
    2281        6082 :                         irep = irep + 1
    2282        6082 :                         IF (update_input) THEN
    2283             :                            CALL section_vals_val_set(potential_section, "_DEFAULT_KEYWORD_", i_rep_val=irep, &
    2284        6054 :                                                      c_val=TRIM(line_att))
    2285             :                         END IF
    2286        6082 :                         line_att = ""
    2287             :                      ELSE
    2288         444 :                         IF (LEN_TRIM(line_att) /= 0) THEN
    2289             :                            CALL cp_abort(__LOCATION__, &
    2290           0 :                                          "Error reading the Potential from input file!!")
    2291             :                         END IF
    2292             :                      END IF
    2293        6526 :                      IF (nprj_ppnl > 1) THEN
    2294         486 :                         CALL symmetrize_matrix(hprj_ppnl(:, :, l), "upper_to_lower")
    2295             :                      END IF
    2296        9873 :                      lprj_ppnl_max = MAX(lprj_ppnl_max, l + 2*(nprj_ppnl - 1))
    2297             :                   END DO
    2298             : 
    2299        3347 :                   potential%nppnl = nppnl
    2300        3347 :                   CALL init_orbital_pointers(lprj_ppnl_max)
    2301             : 
    2302        3347 :                   potential%lprj_ppnl_max = lprj_ppnl_max
    2303        3347 :                   potential%nprj_ppnl_max = nprj_ppnl_max
    2304             :                   CALL reallocate(potential%hprj_ppnl, 1, nprj_ppnl_max, &
    2305             :                                   1, nprj_ppnl_max, &
    2306        3347 :                                   0, lppnl)
    2307       50535 :                   potential%hprj_ppnl(:, :, :) = hprj_ppnl(:, :, :)
    2308             : 
    2309        3347 :                   CALL reallocate(potential%cprj, 1, ncoset(lprj_ppnl_max), 1, nppnl)
    2310        3347 :                   CALL reallocate(potential%cprj_ppnl, 1, nprj_ppnl_max, 0, lppnl)
    2311        3347 :                   CALL reallocate(potential%vprj_ppnl, 1, nppnl, 1, nppnl)
    2312             : 
    2313        3347 :                   DEALLOCATE (hprj_ppnl)
    2314             :                END IF
    2315             :                EXIT search_loop
    2316             :             END IF
    2317             :          ELSE
    2318             :             ! Stop program, if the end of file is reached
    2319             :             CALL cp_abort(__LOCATION__, &
    2320             :                           "The requested atomic potential <"// &
    2321             :                           TRIM(potential_name)// &
    2322             :                           "> for element <"// &
    2323             :                           TRIM(symbol)// &
    2324             :                           "> was not found in the potential file <"// &
    2325           0 :                           TRIM(potential_file_name)//">")
    2326             :          END IF
    2327             :       END DO search_loop
    2328             : 
    2329        6843 :       IF (.NOT. read_from_input) THEN
    2330             :          ! Dump the potential info the in potential section
    2331        6197 :          IF (match .AND. update_input) THEN
    2332        6171 :             irep = irep + 1
    2333        6171 :             WRITE (line_att, '(A)') "         # Potential name: "//apname2(:strlen2)//" for symbol: "//symbol2(:strlen1)
    2334             :             CALL section_vals_val_set(potential_section, "_DEFAULT_KEYWORD_", i_rep_val=irep, &
    2335        6171 :                                       c_val=TRIM(line_att))
    2336        6171 :             irep = irep + 1
    2337        6171 :             WRITE (line_att, '(A)') "         # Potential read from the potential filename: "//TRIM(potential_file_name)
    2338             :             CALL section_vals_val_set(potential_section, "_DEFAULT_KEYWORD_", i_rep_val=irep, &
    2339        6171 :                                       c_val=TRIM(line_att))
    2340             :          END IF
    2341        6197 :          CALL parser_release(parser)
    2342             :       END IF
    2343             : 
    2344        6843 :       IF (ASSOCIATED(tmp_vals)) DEALLOCATE (tmp_vals)
    2345             : 
    2346        6843 :    END SUBROUTINE read_gth_potential
    2347             : 
    2348             : ! **************************************************************************************************
    2349             : !> \brief ...
    2350             : !> \param potential ...
    2351             : !> \param z ...
    2352             : !> \param zeff_correction ...
    2353             : ! **************************************************************************************************
    2354        3488 :    SUBROUTINE set_default_all_potential(potential, z, zeff_correction)
    2355             : 
    2356             :       TYPE(all_potential_type), POINTER                  :: potential
    2357             :       INTEGER, INTENT(IN)                                :: z
    2358             :       REAL(KIND=dp)                                      :: zeff_correction
    2359             : 
    2360             :       CHARACTER(LEN=default_string_length)               :: name
    2361             :       INTEGER, DIMENSION(:), POINTER                     :: elec_conf
    2362             :       REAL(KIND=dp)                                      :: alpha, alpha_core_charge, ccore_charge, &
    2363             :                                                             core_charge_radius, r, zeff
    2364             : 
    2365           0 :       ALLOCATE (elec_conf(0:3))
    2366       17440 :       elec_conf(0:3) = ptable(z)%e_conv(0:3)
    2367       17440 :       zeff = REAL(SUM(elec_conf), dp) + zeff_correction
    2368        3488 :       name = ptable(z)%name
    2369             : 
    2370        3488 :       r = ptable(z)%covalent_radius*0.5_dp
    2371        3488 :       r = MAX(r, 0.2_dp)
    2372        3488 :       r = MIN(r, 1.0_dp)
    2373        3488 :       alpha = 1.0_dp/(2.0_dp*r**2)
    2374             : 
    2375        3488 :       core_charge_radius = r
    2376        3488 :       alpha_core_charge = alpha
    2377        3488 :       ccore_charge = zeff*SQRT((alpha/pi)**3)
    2378             : 
    2379             :       CALL set_all_potential(potential, &
    2380             :                              name=name, &
    2381             :                              alpha_core_charge=alpha_core_charge, &
    2382             :                              ccore_charge=ccore_charge, &
    2383             :                              core_charge_radius=core_charge_radius, &
    2384             :                              z=z, &
    2385             :                              zeff=zeff, &
    2386             :                              zeff_correction=zeff_correction, &
    2387        3488 :                              elec_conf=elec_conf)
    2388             : 
    2389        3488 :       DEALLOCATE (elec_conf)
    2390             : 
    2391        3488 :    END SUBROUTINE set_default_all_potential
    2392             : 
    2393             : ! **************************************************************************************************
    2394             : !> \brief   Set the attributes of an all-electron potential data set.
    2395             : !> \param potential ...
    2396             : !> \param name ...
    2397             : !> \param alpha_core_charge ...
    2398             : !> \param ccore_charge ...
    2399             : !> \param core_charge_radius ...
    2400             : !> \param z ...
    2401             : !> \param zeff ...
    2402             : !> \param zeff_correction ...
    2403             : !> \param elec_conf ...
    2404             : !> \date    11.01.2002
    2405             : !> \author  MK
    2406             : !> \version 1.0
    2407             : ! **************************************************************************************************
    2408        9944 :    SUBROUTINE set_all_potential(potential, name, alpha_core_charge, &
    2409             :                                 ccore_charge, core_charge_radius, z, zeff, &
    2410             :                                 zeff_correction, elec_conf)
    2411             : 
    2412             :       TYPE(all_potential_type), POINTER                  :: potential
    2413             :       CHARACTER(LEN=default_string_length), INTENT(IN), &
    2414             :          OPTIONAL                                        :: name
    2415             :       REAL(KIND=dp), INTENT(IN), OPTIONAL                :: alpha_core_charge, ccore_charge, &
    2416             :                                                             core_charge_radius
    2417             :       INTEGER, INTENT(IN), OPTIONAL                      :: z
    2418             :       REAL(KIND=dp), INTENT(IN), OPTIONAL                :: zeff, zeff_correction
    2419             :       INTEGER, DIMENSION(:), OPTIONAL, POINTER           :: elec_conf
    2420             : 
    2421        9944 :       IF (ASSOCIATED(potential)) THEN
    2422             : 
    2423        9944 :          IF (PRESENT(name)) potential%name = name
    2424        9944 :          IF (PRESENT(alpha_core_charge)) &
    2425        3488 :             potential%alpha_core_charge = alpha_core_charge
    2426        9944 :          IF (PRESENT(ccore_charge)) potential%ccore_charge = ccore_charge
    2427        9944 :          IF (PRESENT(core_charge_radius)) &
    2428        7916 :             potential%core_charge_radius = core_charge_radius
    2429        9944 :          IF (PRESENT(z)) potential%z = z
    2430        9944 :          IF (PRESENT(zeff)) potential%zeff = zeff
    2431        9944 :          IF (PRESENT(zeff_correction)) potential%zeff_correction = zeff_correction
    2432        9944 :          IF (PRESENT(elec_conf)) THEN
    2433        3488 :             IF (.NOT. ASSOCIATED(potential%elec_conf)) THEN
    2434        3488 :                CALL reallocate(potential%elec_conf, 0, SIZE(elec_conf) - 1)
    2435             :             END IF
    2436       34880 :             potential%elec_conf(:) = elec_conf(:)
    2437             :          END IF
    2438             : 
    2439             :       ELSE
    2440             : 
    2441           0 :          CPABORT("The pointer potential is not associated")
    2442             : 
    2443             :       END IF
    2444             : 
    2445        9944 :    END SUBROUTINE set_all_potential
    2446             : 
    2447             : ! **************************************************************************************************
    2448             : !> \brief   Set the attributes of an atomic local potential data set.
    2449             : !> \param potential ...
    2450             : !> \param name ...
    2451             : !> \param alpha ...
    2452             : !> \param cval ...
    2453             : !> \param radius ...
    2454             : !> \date    24.01.2014
    2455             : !> \author  JGH
    2456             : !> \version 1.0
    2457             : ! **************************************************************************************************
    2458           0 :    SUBROUTINE set_local_potential(potential, name, alpha, cval, radius)
    2459             : 
    2460             :       TYPE(local_potential_type), POINTER                :: potential
    2461             :       CHARACTER(LEN=default_string_length), INTENT(IN), &
    2462             :          OPTIONAL                                        :: name
    2463             :       REAL(KIND=dp), DIMENSION(:), OPTIONAL, POINTER     :: alpha
    2464             :       REAL(KIND=dp), DIMENSION(:, :), OPTIONAL, POINTER  :: cval
    2465             :       REAL(KIND=dp), INTENT(IN), OPTIONAL                :: radius
    2466             : 
    2467           0 :       IF (ASSOCIATED(potential)) THEN
    2468             : 
    2469           0 :          IF (PRESENT(name)) potential%name = name
    2470           0 :          IF (PRESENT(alpha)) potential%alpha => alpha
    2471           0 :          IF (PRESENT(cval)) potential%cval => cval
    2472           0 :          IF (PRESENT(radius)) potential%radius = radius
    2473             : 
    2474             :       ELSE
    2475             : 
    2476           0 :          CPABORT("The pointer potential is not associated")
    2477             : 
    2478             :       END IF
    2479             : 
    2480           0 :    END SUBROUTINE set_local_potential
    2481             : 
    2482             : ! **************************************************************************************************
    2483             : !> \brief   Set the attributes of an effective charge and inducible point
    2484             : !>          dipole potential data set.
    2485             : !> \param potential ...
    2486             : !> \param apol ...
    2487             : !> \param cpol ...
    2488             : !> \param qeff ...
    2489             : !> \param mm_radius ...
    2490             : !> \param qmmm_corr_radius ...
    2491             : !> \param qmmm_radius ...
    2492             : !> \date    05.03.2010
    2493             : !> \author  Toon.Verstraelen@gmail.com
    2494             : ! **************************************************************************************************
    2495       52677 :    SUBROUTINE set_fist_potential(potential, apol, cpol, qeff, mm_radius, &
    2496             :                                  qmmm_corr_radius, qmmm_radius)
    2497             :       TYPE(fist_potential_type), POINTER                 :: potential
    2498             :       REAL(KIND=dp), INTENT(IN), OPTIONAL                :: apol, cpol, qeff, mm_radius, &
    2499             :                                                             qmmm_corr_radius, qmmm_radius
    2500             : 
    2501       52677 :       IF (ASSOCIATED(potential)) THEN
    2502             : 
    2503       52677 :          IF (PRESENT(apol)) potential%apol = apol
    2504       52677 :          IF (PRESENT(cpol)) potential%cpol = cpol
    2505       52677 :          IF (PRESENT(mm_radius)) potential%mm_radius = mm_radius
    2506       52677 :          IF (PRESENT(qeff)) potential%qeff = qeff
    2507       52677 :          IF (PRESENT(qmmm_corr_radius)) potential%qmmm_corr_radius = qmmm_corr_radius
    2508       52677 :          IF (PRESENT(qmmm_radius)) potential%qmmm_radius = qmmm_radius
    2509             : 
    2510             :       ELSE
    2511             : 
    2512           0 :          CPABORT("The pointer potential is not associated")
    2513             : 
    2514             :       END IF
    2515             : 
    2516       52677 :    END SUBROUTINE set_fist_potential
    2517             : 
    2518             : ! **************************************************************************************************
    2519             : !> \brief   Set the attributes of a GTH potential data set.
    2520             : !> \param potential ...
    2521             : !> \param name ...
    2522             : !> \param alpha_core_charge ...
    2523             : !> \param alpha_ppl ...
    2524             : !> \param ccore_charge ...
    2525             : !> \param cerf_ppl ...
    2526             : !> \param core_charge_radius ...
    2527             : !> \param ppl_radius ...
    2528             : !> \param ppnl_radius ...
    2529             : !> \param lppnl ...
    2530             : !> \param lprj_ppnl_max ...
    2531             : !> \param nexp_ppl ...
    2532             : !> \param nppnl ...
    2533             : !> \param nprj_ppnl_max ...
    2534             : !> \param z ...
    2535             : !> \param zeff ...
    2536             : !> \param zeff_correction ...
    2537             : !> \param alpha_ppnl ...
    2538             : !> \param cexp_ppl ...
    2539             : !> \param elec_conf ...
    2540             : !> \param nprj_ppnl ...
    2541             : !> \param cprj ...
    2542             : !> \param cprj_ppnl ...
    2543             : !> \param vprj_ppnl ...
    2544             : !> \param hprj_ppnl ...
    2545             : !> \date    11.01.2002
    2546             : !> \author  MK
    2547             : !> \version 1.0
    2548             : ! **************************************************************************************************
    2549       16687 :    SUBROUTINE set_gth_potential(potential, name, alpha_core_charge, alpha_ppl, &
    2550             :                                 ccore_charge, cerf_ppl, core_charge_radius, &
    2551             :                                 ppl_radius, ppnl_radius, lppnl, lprj_ppnl_max, &
    2552             :                                 nexp_ppl, nppnl, nprj_ppnl_max, z, zeff, zeff_correction, &
    2553             :                                 alpha_ppnl, cexp_ppl, elec_conf, nprj_ppnl, cprj, cprj_ppnl, &
    2554             :                                 vprj_ppnl, hprj_ppnl)
    2555             :       TYPE(gth_potential_type), POINTER                  :: potential
    2556             :       CHARACTER(LEN=default_string_length), INTENT(IN), &
    2557             :          OPTIONAL                                        :: name
    2558             :       REAL(KIND=dp), INTENT(IN), OPTIONAL                :: alpha_core_charge, alpha_ppl, &
    2559             :                                                             ccore_charge, cerf_ppl, &
    2560             :                                                             core_charge_radius, ppl_radius, &
    2561             :                                                             ppnl_radius
    2562             :       INTEGER, INTENT(IN), OPTIONAL                      :: lppnl, lprj_ppnl_max, nexp_ppl, nppnl, &
    2563             :                                                             nprj_ppnl_max, z
    2564             :       REAL(KIND=dp), INTENT(IN), OPTIONAL                :: zeff, zeff_correction
    2565             :       REAL(KIND=dp), DIMENSION(:), OPTIONAL, POINTER     :: alpha_ppnl, cexp_ppl
    2566             :       INTEGER, DIMENSION(:), OPTIONAL, POINTER           :: elec_conf, nprj_ppnl
    2567             :       REAL(KIND=dp), DIMENSION(:, :), OPTIONAL, POINTER  :: cprj, cprj_ppnl, vprj_ppnl
    2568             :       REAL(KIND=dp), DIMENSION(:, :, :), OPTIONAL, &
    2569             :          POINTER                                         :: hprj_ppnl
    2570             : 
    2571       16687 :       IF (ASSOCIATED(potential)) THEN
    2572             : 
    2573       16687 :          IF (PRESENT(name)) potential%name = name
    2574       16687 :          IF (PRESENT(alpha_core_charge)) &
    2575           0 :             potential%alpha_core_charge = alpha_core_charge
    2576       16687 :          IF (PRESENT(alpha_ppl)) potential%alpha_ppl = alpha_ppl
    2577       16687 :          IF (PRESENT(ccore_charge)) potential%ccore_charge = ccore_charge
    2578       16687 :          IF (PRESENT(cerf_ppl)) potential%cerf_ppl = cerf_ppl
    2579       16687 :          IF (PRESENT(core_charge_radius)) &
    2580        9840 :             potential%core_charge_radius = core_charge_radius
    2581       16687 :          IF (PRESENT(ppl_radius)) potential%ppl_radius = ppl_radius
    2582       16687 :          IF (PRESENT(ppnl_radius)) potential%ppnl_radius = ppnl_radius
    2583       16687 :          IF (PRESENT(lppnl)) potential%lppnl = lppnl
    2584       16687 :          IF (PRESENT(lprj_ppnl_max)) potential%lprj_ppnl_max = lprj_ppnl_max
    2585       16687 :          IF (PRESENT(nexp_ppl)) potential%nexp_ppl = nexp_ppl
    2586       16687 :          IF (PRESENT(nppnl)) potential%nppnl = nppnl
    2587       16687 :          IF (PRESENT(nprj_ppnl_max)) potential%nprj_ppnl_max = nprj_ppnl_max
    2588       16687 :          IF (PRESENT(z)) potential%z = z
    2589       16687 :          IF (PRESENT(zeff)) potential%zeff = zeff
    2590       16687 :          IF (PRESENT(zeff_correction)) potential%zeff_correction = zeff_correction
    2591       16687 :          IF (PRESENT(alpha_ppnl)) potential%alpha_ppnl => alpha_ppnl
    2592       16687 :          IF (PRESENT(cexp_ppl)) potential%cexp_ppl => cexp_ppl
    2593       16687 :          IF (PRESENT(elec_conf)) THEN
    2594           4 :             IF (ASSOCIATED(potential%elec_conf)) THEN
    2595           4 :                DEALLOCATE (potential%elec_conf)
    2596             :             END IF
    2597          12 :             ALLOCATE (potential%elec_conf(0:SIZE(elec_conf) - 1))
    2598          20 :             potential%elec_conf(:) = elec_conf(:)
    2599             :          END IF
    2600       16687 :          IF (PRESENT(nprj_ppnl)) potential%nprj_ppnl => nprj_ppnl
    2601       16687 :          IF (PRESENT(cprj)) potential%cprj => cprj
    2602       16687 :          IF (PRESENT(cprj_ppnl)) potential%cprj_ppnl => cprj_ppnl
    2603       16687 :          IF (PRESENT(vprj_ppnl)) potential%vprj_ppnl => vprj_ppnl
    2604       16687 :          IF (PRESENT(hprj_ppnl)) potential%hprj_ppnl => hprj_ppnl
    2605             : 
    2606             :       ELSE
    2607             : 
    2608           0 :          CPABORT("The pointer potential is not associated")
    2609             : 
    2610             :       END IF
    2611             : 
    2612       16687 :    END SUBROUTINE set_gth_potential
    2613             : 
    2614             : ! **************************************************************************************************
    2615             : !> \brief ...
    2616             : !> \param potential ...
    2617             : !> \param name ...
    2618             : !> \param description ...
    2619             : !> \param aliases ...
    2620             : !> \param elec_conf ...
    2621             : !> \param z ...
    2622             : !> \param zeff ...
    2623             : !> \param zeff_correction ...
    2624             : !> \param alpha_core_charge ...
    2625             : !> \param ccore_charge ...
    2626             : !> \param core_charge_radius ...
    2627             : !> \param ppl_radius ...
    2628             : !> \param ppnl_radius ...
    2629             : !> \param ecp_local ...
    2630             : !> \param n_local ...
    2631             : !> \param a_local ...
    2632             : !> \param c_local ...
    2633             : !> \param nloc ...
    2634             : !> \param nrloc ...
    2635             : !> \param aloc ...
    2636             : !> \param bloc ...
    2637             : !> \param n_nonlocal ...
    2638             : !> \param nppnl ...
    2639             : !> \param lmax ...
    2640             : !> \param is_nonlocal ...
    2641             : !> \param a_nonlocal ...
    2642             : !> \param h_nonlocal ...
    2643             : !> \param c_nonlocal ...
    2644             : !> \param has_nlcc ...
    2645             : !> \param n_nlcc ...
    2646             : !> \param a_nlcc ...
    2647             : !> \param c_nlcc ...
    2648             : ! **************************************************************************************************
    2649          96 :    SUBROUTINE set_sgp_potential(potential, name, description, aliases, elec_conf, &
    2650             :                                 z, zeff, zeff_correction, alpha_core_charge, &
    2651             :                                 ccore_charge, core_charge_radius, &
    2652             :                                 ppl_radius, ppnl_radius, &
    2653             :                                 ecp_local, n_local, a_local, c_local, &
    2654             :                                 nloc, nrloc, aloc, bloc, &
    2655             :                                 n_nonlocal, nppnl, lmax, is_nonlocal, a_nonlocal, h_nonlocal, c_nonlocal, &
    2656             :                                 has_nlcc, n_nlcc, a_nlcc, c_nlcc)
    2657             : 
    2658             :       TYPE(sgp_potential_type), POINTER                  :: potential
    2659             :       CHARACTER(LEN=default_string_length), INTENT(IN), &
    2660             :          OPTIONAL                                        :: name
    2661             :       CHARACTER(LEN=default_string_length), &
    2662             :          DIMENSION(4), INTENT(IN), OPTIONAL              :: description
    2663             :       CHARACTER(LEN=default_string_length), INTENT(IN), &
    2664             :          OPTIONAL                                        :: aliases
    2665             :       INTEGER, DIMENSION(:), OPTIONAL, POINTER           :: elec_conf
    2666             :       INTEGER, INTENT(IN), OPTIONAL                      :: z
    2667             :       REAL(KIND=dp), INTENT(IN), OPTIONAL                :: zeff, zeff_correction, &
    2668             :                                                             alpha_core_charge, ccore_charge, &
    2669             :                                                             core_charge_radius, ppl_radius, &
    2670             :                                                             ppnl_radius
    2671             :       LOGICAL, INTENT(IN), OPTIONAL                      :: ecp_local
    2672             :       INTEGER, INTENT(IN), OPTIONAL                      :: n_local
    2673             :       REAL(KIND=dp), DIMENSION(:), OPTIONAL, POINTER     :: a_local, c_local
    2674             :       INTEGER, INTENT(IN), OPTIONAL                      :: nloc
    2675             :       INTEGER, DIMENSION(1:10), INTENT(IN), OPTIONAL     :: nrloc
    2676             :       REAL(dp), DIMENSION(1:10), INTENT(IN), OPTIONAL    :: aloc, bloc
    2677             :       INTEGER, INTENT(IN), OPTIONAL                      :: n_nonlocal, nppnl, lmax
    2678             :       LOGICAL, DIMENSION(0:5), INTENT(IN), OPTIONAL      :: is_nonlocal
    2679             :       REAL(KIND=dp), DIMENSION(:), OPTIONAL, POINTER     :: a_nonlocal
    2680             :       REAL(KIND=dp), DIMENSION(:, :), OPTIONAL, POINTER  :: h_nonlocal
    2681             :       REAL(KIND=dp), DIMENSION(:, :, :), OPTIONAL, &
    2682             :          POINTER                                         :: c_nonlocal
    2683             :       LOGICAL, INTENT(IN), OPTIONAL                      :: has_nlcc
    2684             :       INTEGER, INTENT(IN), OPTIONAL                      :: n_nlcc
    2685             :       REAL(KIND=dp), DIMENSION(:), OPTIONAL, POINTER     :: a_nlcc, c_nlcc
    2686             : 
    2687          96 :       IF (ASSOCIATED(potential)) THEN
    2688             : 
    2689          96 :          IF (PRESENT(name)) potential%name = name
    2690          96 :          IF (PRESENT(aliases)) potential%aliases = aliases
    2691         144 :          IF (PRESENT(description)) potential%description = description
    2692             : 
    2693          96 :          IF (PRESENT(elec_conf)) THEN
    2694          12 :             IF (ASSOCIATED(potential%elec_conf)) THEN
    2695           0 :                DEALLOCATE (potential%elec_conf)
    2696             :             END IF
    2697          36 :             ALLOCATE (potential%elec_conf(0:SIZE(elec_conf) - 1))
    2698         120 :             potential%elec_conf(:) = elec_conf(:)
    2699             :          END IF
    2700             : 
    2701          96 :          IF (PRESENT(z)) potential%z = z
    2702          96 :          IF (PRESENT(zeff)) potential%zeff = zeff
    2703          96 :          IF (PRESENT(zeff_correction)) potential%zeff_correction = zeff_correction
    2704          96 :          IF (PRESENT(alpha_core_charge)) potential%alpha_core_charge = alpha_core_charge
    2705          96 :          IF (PRESENT(ccore_charge)) potential%ccore_charge = ccore_charge
    2706          96 :          IF (PRESENT(core_charge_radius)) potential%core_charge_radius = core_charge_radius
    2707             : 
    2708          96 :          IF (PRESENT(ppl_radius)) potential%ppl_radius = ppl_radius
    2709          96 :          IF (PRESENT(ppnl_radius)) potential%ppnl_radius = ppnl_radius
    2710             : 
    2711          96 :          IF (PRESENT(ecp_local)) potential%ecp_local = ecp_local
    2712          96 :          IF (PRESENT(n_local)) potential%n_local = n_local
    2713          96 :          IF (PRESENT(a_local)) potential%a_local => a_local
    2714          96 :          IF (PRESENT(c_local)) potential%c_local => c_local
    2715             : 
    2716          96 :          IF (PRESENT(nloc)) potential%nloc = nloc
    2717          96 :          IF (PRESENT(nrloc)) potential%nrloc = nrloc
    2718          96 :          IF (PRESENT(aloc)) potential%aloc = aloc
    2719          96 :          IF (PRESENT(bloc)) potential%bloc = bloc
    2720             : 
    2721          96 :          IF (PRESENT(n_nonlocal)) potential%n_nonlocal = n_nonlocal
    2722          96 :          IF (PRESENT(nppnl)) potential%nppnl = nppnl
    2723          96 :          IF (PRESENT(lmax)) potential%lmax = lmax
    2724         168 :          IF (PRESENT(is_nonlocal)) potential%is_nonlocal(:) = is_nonlocal(:)
    2725          96 :          IF (PRESENT(a_nonlocal)) potential%a_nonlocal => a_nonlocal
    2726          96 :          IF (PRESENT(c_nonlocal)) potential%c_nonlocal => c_nonlocal
    2727          96 :          IF (PRESENT(h_nonlocal)) potential%h_nonlocal => h_nonlocal
    2728             : 
    2729          96 :          IF (PRESENT(has_nlcc)) potential%has_nlcc = has_nlcc
    2730          96 :          IF (PRESENT(n_nlcc)) potential%n_nlcc = n_nlcc
    2731          96 :          IF (PRESENT(a_nlcc)) potential%a_nlcc => a_nlcc
    2732          96 :          IF (PRESENT(c_nlcc)) potential%c_nlcc => c_nlcc
    2733             : 
    2734             :       ELSE
    2735             : 
    2736           0 :          CPABORT("The pointer potential is not associated.")
    2737             : 
    2738             :       END IF
    2739             : 
    2740          96 :    END SUBROUTINE set_sgp_potential
    2741             : 
    2742             : ! **************************************************************************************************
    2743             : !> \brief ...
    2744             : !> \param potential ...
    2745             : !> \param output_unit ...
    2746             : ! **************************************************************************************************
    2747        3422 :    SUBROUTINE write_all_potential(potential, output_unit)
    2748             : 
    2749             :       ! Write an atomic all-electron potential data set to the output unit.
    2750             : 
    2751             :       ! - Creation (09.02.2002,MK)
    2752             : 
    2753             :       TYPE(all_potential_type), POINTER                  :: potential
    2754             :       INTEGER, INTENT(in)                                :: output_unit
    2755             : 
    2756             :       CHARACTER(LEN=20)                                  :: string
    2757             : 
    2758        3422 :       IF (output_unit > 0 .AND. ASSOCIATED(potential)) THEN
    2759             :          WRITE (UNIT=output_unit, FMT="(/,T6,A,T41,A40,/)") &
    2760        1583 :             "AE Potential information for", ADJUSTR(TRIM(potential%name))
    2761             :          WRITE (UNIT=output_unit, FMT="(T8,A,T41,A40)") &
    2762        1583 :             "Description: ", TRIM(potential%description(1)), &
    2763        3166 :             "             ", TRIM(potential%description(2))
    2764             :          WRITE (UNIT=output_unit, FMT="(/,T8,A,T69,F12.6)") &
    2765        1583 :             "Gaussian exponent of the core charge distribution: ", &
    2766        3166 :             potential%alpha_core_charge
    2767        7654 :          WRITE (UNIT=string, FMT="(5I4)") potential%elec_conf
    2768             :          WRITE (UNIT=output_unit, FMT="(T8,A,T61,A20)") &
    2769        1583 :             "Electronic configuration (s p d ...):", &
    2770        3166 :             ADJUSTR(TRIM(string))
    2771             :       END IF
    2772             : 
    2773        3422 :    END SUBROUTINE write_all_potential
    2774             : 
    2775             : ! **************************************************************************************************
    2776             : !> \brief ...
    2777             : !> \param potential ...
    2778             : !> \param output_unit ...
    2779             : ! **************************************************************************************************
    2780        3422 :    SUBROUTINE write_local_potential(potential, output_unit)
    2781             : 
    2782             :       ! Write an atomic local potential data set to the output unit.
    2783             : 
    2784             :       ! - Creation (24.01.2014,JGH)
    2785             : 
    2786             :       TYPE(local_potential_type), POINTER                :: potential
    2787             :       INTEGER, INTENT(in)                                :: output_unit
    2788             : 
    2789             :       INTEGER                                            :: igau, ipol
    2790             : 
    2791        3422 :       IF (output_unit > 0 .AND. ASSOCIATED(potential)) THEN
    2792             :          WRITE (UNIT=output_unit, FMT="(/,T6,A,T41,A40)") &
    2793           2 :             "Local Potential information for", ADJUSTR(TRIM(potential%name))
    2794             :          WRITE (UNIT=output_unit, FMT="(T8,A,T41,A40)") &
    2795           2 :             "Description: ", TRIM(potential%description(1))
    2796           6 :          DO igau = 1, potential%ngau
    2797             :             WRITE (UNIT=output_unit, FMT="(T8,A,F12.6,T50,A,4(T68,I2,F10.4))") &
    2798           4 :                "Exponent: ", potential%alpha(igau), &
    2799          14 :                "Coefficients: ", (2*ipol - 2, potential%cval(igau, ipol), ipol=1, potential%npol)
    2800             :          END DO
    2801             :       END IF
    2802             : 
    2803        3422 :    END SUBROUTINE write_local_potential
    2804             : 
    2805             : ! **************************************************************************************************
    2806             : !> \brief ...
    2807             : !> \param potential ...
    2808             : !> \param output_unit ...
    2809             : ! **************************************************************************************************
    2810        3422 :    SUBROUTINE write_gth_potential(potential, output_unit)
    2811             : 
    2812             :       ! Write an atomic GTH potential data set to the output unit.
    2813             :       ! - Creation (09.02.2002,MK)
    2814             : 
    2815             :       TYPE(gth_potential_type), POINTER                  :: potential
    2816             :       INTEGER, INTENT(in)                                :: output_unit
    2817             : 
    2818             :       CHARACTER(LEN=20)                                  :: string
    2819             :       INTEGER                                            :: i, j, l
    2820             :       REAL(KIND=dp)                                      :: r
    2821             : 
    2822        3422 :       IF (output_unit > 0 .AND. ASSOCIATED(potential)) THEN
    2823             :          WRITE (UNIT=output_unit, FMT="(/,T6,A,T41,A40,/)") &
    2824        1823 :             "GTH Potential information for", ADJUSTR(TRIM(potential%name))
    2825             :          WRITE (UNIT=output_unit, FMT="(T8,A,T41,A40)") &
    2826        1823 :             "Description: ", ADJUSTR(TRIM(potential%description(1))), &
    2827        1823 :             "             ", ADJUSTR(TRIM(potential%description(2))), &
    2828        1823 :             "             ", ADJUSTR(TRIM(potential%description(3))), &
    2829        3646 :             "             ", ADJUSTR(TRIM(potential%description(4)))
    2830             :          WRITE (UNIT=output_unit, FMT="(/,T8,A,T69,F12.6)") &
    2831        1823 :             "Gaussian exponent of the core charge distribution: ", &
    2832        3646 :             potential%alpha_core_charge
    2833        4858 :          WRITE (UNIT=string, FMT="(5I4)") potential%elec_conf
    2834             :          WRITE (UNIT=output_unit, FMT="(T8,A,T61,A20)") &
    2835        1823 :             "Electronic configuration (s p d ...):", &
    2836        3646 :             ADJUSTR(TRIM(string))
    2837             : 
    2838        1823 :          r = 1.0_dp/SQRT(2.0_dp*potential%alpha_ppl)
    2839             : 
    2840             :          WRITE (UNIT=output_unit, FMT="(/,T8,A,/,/,T27,A,/,T21,5F12.6)") &
    2841        1823 :             "Parameters of the local part of the GTH pseudopotential:", &
    2842        1823 :             "rloc        C1          C2          C3          C4", &
    2843        7141 :             r, (potential%cexp_ppl(i)*r**(2*(i - 1)), i=1, potential%nexp_ppl)
    2844             : 
    2845        1823 :          IF (potential%lppnl > -1) THEN
    2846             :             WRITE (UNIT=output_unit, FMT="(/,T8,A,/,/,T20,A,/)") &
    2847         799 :                "Parameters of the non-local part of the GTH pseudopotential:", &
    2848        1598 :                "l      r(l)      h(i,j,l)"
    2849        2357 :             DO l = 0, potential%lppnl
    2850        1558 :                r = SQRT(0.5_dp/potential%alpha_ppnl(l))
    2851             :                WRITE (UNIT=output_unit, FMT="(T19,I2,5F12.6)") &
    2852        2763 :                   l, r, (potential%hprj_ppnl(1, j, l), j=1, potential%nprj_ppnl(l))
    2853        2568 :                DO i = 2, potential%nprj_ppnl(l)
    2854             :                   WRITE (UNIT=output_unit, FMT="(T33,4F12.6)") &
    2855        2215 :                      (potential%hprj_ppnl(i, j, l), j=1, potential%nprj_ppnl(l))
    2856             :                END DO
    2857             :             END DO
    2858             :          END IF
    2859             :       END IF
    2860             : 
    2861        3422 :    END SUBROUTINE write_gth_potential
    2862             : 
    2863             : ! **************************************************************************************************
    2864             : !> \brief ...
    2865             : !> \param potential ...
    2866             : !> \param output_unit ...
    2867             : ! **************************************************************************************************
    2868        3422 :    SUBROUTINE write_sgp_potential(potential, output_unit)
    2869             : 
    2870             :       TYPE(sgp_potential_type), POINTER                  :: potential
    2871             :       INTEGER, INTENT(in)                                :: output_unit
    2872             : 
    2873             :       CHARACTER(LEN=40)                                  :: string
    2874             :       INTEGER                                            :: i, l
    2875             : 
    2876        3422 :       IF (output_unit > 0 .AND. ASSOCIATED(potential)) THEN
    2877             :          WRITE (UNIT=output_unit, FMT="(/,T6,A,T41,A40,/)") &
    2878           0 :             "SGP Potential information for", ADJUSTR(TRIM(potential%name))
    2879             :          WRITE (UNIT=output_unit, FMT="(T8,A,T25,A56)") &
    2880           0 :             "Description: ", ADJUSTR(TRIM(potential%description(1))), &
    2881           0 :             "             ", ADJUSTR(TRIM(potential%description(2))), &
    2882           0 :             "             ", ADJUSTR(TRIM(potential%description(3))), &
    2883           0 :             "             ", ADJUSTR(TRIM(potential%description(4)))
    2884             :          WRITE (UNIT=output_unit, FMT="(/,T8,A,T69,F12.6)") &
    2885           0 :             "Gaussian exponent of the core charge distribution: ", &
    2886           0 :             potential%alpha_core_charge
    2887           0 :          WRITE (UNIT=string, FMT="(10I4)") potential%elec_conf
    2888             :          WRITE (UNIT=output_unit, FMT="(T8,A,T61,A20)") &
    2889           0 :             "Electronic configuration (s p d ...):", &
    2890           0 :             ADJUSTR(TRIM(string))
    2891           0 :          IF (potential%ecp_local) THEN
    2892           0 :             IF (potential%nloc > 0) THEN
    2893           0 :                WRITE (UNIT=output_unit, FMT="(/,T8,'Local pseudopotential')")
    2894           0 :                WRITE (UNIT=output_unit, FMT="(T20,'r**(n-2)',T50,'Coefficient',T73,'Exponent')")
    2895           0 :                DO i = 1, potential%nloc
    2896             :                   WRITE (UNIT=output_unit, FMT="(T20,I5,T47,F14.8,T69,F12.6)") &
    2897           0 :                      potential%nrloc(i), potential%aloc(i), potential%bloc(i)
    2898             :                END DO
    2899             :             END IF
    2900             :          ELSE
    2901           0 :             IF (potential%n_local > 0) THEN
    2902           0 :                WRITE (UNIT=output_unit, FMT="(/,T8,'Local pseudopotential')")
    2903             :                WRITE (UNIT=output_unit, FMT="(T8,A,10(T21,6F10.4,/))") &
    2904           0 :                   'Exponents:', potential%a_local(1:potential%n_local)
    2905             :                WRITE (UNIT=output_unit, FMT="(T8,A,10(T21,6F10.4,/))") &
    2906           0 :                   'Coefficients:', potential%c_local(1:potential%n_local)
    2907             :             END IF
    2908             :          END IF
    2909             :          ! nonlocal PP
    2910           0 :          IF (potential%n_nonlocal > 0) THEN
    2911           0 :             WRITE (UNIT=output_unit, FMT="(/,T8,'Nonlocal pseudopotential')")
    2912           0 :             WRITE (UNIT=output_unit, FMT="(T8,A,T71,I10)") 'Total number of projectors:', potential%nppnl
    2913             :             WRITE (UNIT=output_unit, FMT="(T8,A,10(T21,6F10.4,/))") &
    2914           0 :                'Exponents:', potential%a_nonlocal(1:potential%n_nonlocal)
    2915           0 :             DO l = 0, potential%lmax
    2916           0 :                WRITE (UNIT=output_unit, FMT="(T8,'Coupling for l=',I4)") l
    2917             :                WRITE (UNIT=output_unit, FMT="(10(T21,6F10.4,/))") &
    2918           0 :                   potential%h_nonlocal(1:potential%n_nonlocal, l)
    2919             :             END DO
    2920             :          END IF
    2921             :          !
    2922           0 :          IF (potential%has_nlcc) THEN
    2923           0 :             WRITE (UNIT=output_unit, FMT="(/,T8,'Nonlinear Core Correction')")
    2924             :             WRITE (UNIT=output_unit, FMT="(T8,A,10(T21,6F10.4,/))") &
    2925           0 :                'Exponents:', potential%a_nlcc(1:potential%n_nlcc)
    2926             :             WRITE (UNIT=output_unit, FMT="(T8,A,10(T21,6F10.4,/))") &
    2927           0 :                'Coefficients:', potential%c_nlcc(1:potential%n_nlcc)
    2928             :          END IF
    2929             :       END IF
    2930             : 
    2931        3422 :    END SUBROUTINE write_sgp_potential
    2932             : 
    2933             : ! **************************************************************************************************
    2934             : !> \brief Copy an all_potential_type to a new, unallocated variable
    2935             : !> \param pot_in the input potential to copy
    2936             : !> \param pot_out the newly copied and allocated potential
    2937             : !> \par History: created 12.2019 (A. Bussy)
    2938             : ! **************************************************************************************************
    2939          16 :    SUBROUTINE copy_all_potential(pot_in, pot_out)
    2940             : 
    2941             :       TYPE(all_potential_type), INTENT(IN), POINTER      :: pot_in
    2942             :       TYPE(all_potential_type), INTENT(INOUT), POINTER   :: pot_out
    2943             : 
    2944          16 :       CPASSERT(ASSOCIATED(pot_in))
    2945          16 :       CALL allocate_all_potential(pot_out)
    2946             : 
    2947          16 :       pot_out%name = pot_in%name
    2948          16 :       pot_out%alpha_core_charge = pot_in%alpha_core_charge
    2949          16 :       pot_out%ccore_charge = pot_in%ccore_charge
    2950          16 :       pot_out%core_charge_radius = pot_in%core_charge_radius
    2951          16 :       pot_out%zeff = pot_in%zeff
    2952          16 :       pot_out%zeff_correction = pot_in%zeff_correction
    2953          16 :       pot_out%z = pot_in%z
    2954             : 
    2955          16 :       IF (ASSOCIATED(pot_in%elec_conf)) THEN
    2956          48 :          ALLOCATE (pot_out%elec_conf(LBOUND(pot_in%elec_conf, 1):UBOUND(pot_in%elec_conf, 1)))
    2957         128 :          pot_out%elec_conf(:) = pot_in%elec_conf(:)
    2958             :       END IF
    2959             : 
    2960          16 :    END SUBROUTINE copy_all_potential
    2961             : 
    2962             : ! **************************************************************************************************
    2963             : !> \brief Copy a gth_potential_type to a new, unallocated variable
    2964             : !> \param pot_in the input potential to copy
    2965             : !> \param pot_out the newly copied and allocated potential
    2966             : !> \par History: created 12.2019 (A. Bussy)
    2967             : ! **************************************************************************************************
    2968          44 :    SUBROUTINE copy_gth_potential(pot_in, pot_out)
    2969             : 
    2970             :       TYPE(gth_potential_type), INTENT(IN), POINTER      :: pot_in
    2971             :       TYPE(gth_potential_type), INTENT(INOUT), POINTER   :: pot_out
    2972             : 
    2973          44 :       CPASSERT(ASSOCIATED(pot_in))
    2974          44 :       CALL allocate_gth_potential(pot_out)
    2975             : 
    2976          44 :       pot_out%name = pot_in%name
    2977          44 :       pot_out%aliases = pot_in%aliases
    2978          44 :       pot_out%alpha_core_charge = pot_in%alpha_core_charge
    2979          44 :       pot_out%alpha_ppl = pot_in%alpha_ppl
    2980          44 :       pot_out%ccore_charge = pot_in%ccore_charge
    2981          44 :       pot_out%cerf_ppl = pot_in%cerf_ppl
    2982          44 :       pot_out%zeff = pot_in%zeff
    2983          44 :       pot_out%core_charge_radius = pot_in%core_charge_radius
    2984          44 :       pot_out%ppl_radius = pot_in%ppl_radius
    2985          44 :       pot_out%ppnl_radius = pot_in%ppnl_radius
    2986          44 :       pot_out%zeff_correction = pot_in%zeff_correction
    2987          44 :       pot_out%lppnl = pot_in%lppnl
    2988          44 :       pot_out%lprj_ppnl_max = pot_in%lprj_ppnl_max
    2989          44 :       pot_out%nexp_ppl = pot_in%nexp_ppl
    2990          44 :       pot_out%nppnl = pot_in%nppnl
    2991          44 :       pot_out%nprj_ppnl_max = pot_in%nprj_ppnl_max
    2992          44 :       pot_out%z = pot_in%z
    2993          44 :       pot_out%nlcc = pot_in%nlcc
    2994          44 :       pot_out%nexp_nlcc = pot_in%nexp_nlcc
    2995          44 :       pot_out%lsdpot = pot_in%lsdpot
    2996          44 :       pot_out%nexp_lsd = pot_in%nexp_lsd
    2997          44 :       pot_out%lpotextended = pot_in%lpotextended
    2998          44 :       pot_out%nexp_lpot = pot_in%nexp_lpot
    2999             : 
    3000          44 :       IF (ASSOCIATED(pot_in%alpha_ppnl)) THEN
    3001          60 :          ALLOCATE (pot_out%alpha_ppnl(LBOUND(pot_in%alpha_ppnl, 1):UBOUND(pot_in%alpha_ppnl, 1)))
    3002         120 :          pot_out%alpha_ppnl(:) = pot_in%alpha_ppnl(:)
    3003             :       END IF
    3004          44 :       IF (ASSOCIATED(pot_in%cexp_ppl)) THEN
    3005         132 :          ALLOCATE (pot_out%cexp_ppl(LBOUND(pot_in%cexp_ppl, 1):UBOUND(pot_in%cexp_ppl, 1)))
    3006         264 :          pot_out%cexp_ppl(:) = pot_in%cexp_ppl(:)
    3007             :       END IF
    3008          44 :       IF (ASSOCIATED(pot_in%elec_conf)) THEN
    3009         132 :          ALLOCATE (pot_out%elec_conf(LBOUND(pot_in%elec_conf, 1):UBOUND(pot_in%elec_conf, 1)))
    3010         216 :          pot_out%elec_conf(:) = pot_in%elec_conf(:)
    3011             :       END IF
    3012          44 :       IF (ASSOCIATED(pot_in%nprj_ppnl)) THEN
    3013          60 :          ALLOCATE (pot_out%nprj_ppnl(LBOUND(pot_in%nprj_ppnl, 1):UBOUND(pot_in%nprj_ppnl, 1)))
    3014         120 :          pot_out%nprj_ppnl(:) = pot_in%nprj_ppnl(:)
    3015             :       END IF
    3016          44 :       IF (ASSOCIATED(pot_in%cprj)) THEN
    3017             :          ALLOCATE (pot_out%cprj(LBOUND(pot_in%cprj, 1):UBOUND(pot_in%cprj, 1), &
    3018          80 :                                 LBOUND(pot_in%cprj, 2):UBOUND(pot_in%cprj, 2)))
    3019         120 :          pot_out%cprj(:, :) = pot_in%cprj(:, :)
    3020             :       END IF
    3021          44 :       IF (ASSOCIATED(pot_in%cprj_ppnl)) THEN
    3022             :          ALLOCATE (pot_out%cprj_ppnl(LBOUND(pot_in%cprj_ppnl, 1):UBOUND(pot_in%cprj_ppnl, 1), &
    3023          80 :                                      LBOUND(pot_in%cprj_ppnl, 2):UBOUND(pot_in%cprj_ppnl, 2)))
    3024         200 :          pot_out%cprj_ppnl(:, :) = pot_in%cprj_ppnl(:, :)
    3025             :       END IF
    3026          44 :       IF (ASSOCIATED(pot_in%vprj_ppnl)) THEN
    3027             :          ALLOCATE (pot_out%vprj_ppnl(LBOUND(pot_in%vprj_ppnl, 1):UBOUND(pot_in%vprj_ppnl, 1), &
    3028          80 :                                      LBOUND(pot_in%vprj_ppnl, 2):UBOUND(pot_in%vprj_ppnl, 2)))
    3029         120 :          pot_out%vprj_ppnl(:, :) = pot_in%vprj_ppnl(:, :)
    3030             :       END IF
    3031          44 :       IF (ASSOCIATED(pot_in%hprj_ppnl)) THEN
    3032             :          ALLOCATE (pot_out%hprj_ppnl(LBOUND(pot_in%hprj_ppnl, 1):UBOUND(pot_in%hprj_ppnl, 1), &
    3033             :                                      LBOUND(pot_in%hprj_ppnl, 2):UBOUND(pot_in%hprj_ppnl, 2), &
    3034         100 :                                      LBOUND(pot_in%hprj_ppnl, 3):UBOUND(pot_in%hprj_ppnl, 3)))
    3035         280 :          pot_out%hprj_ppnl(:, :, :) = pot_in%hprj_ppnl(:, :, :)
    3036             :       END IF
    3037          44 :       IF (ASSOCIATED(pot_in%alpha_nlcc)) THEN
    3038           0 :          ALLOCATE (pot_out%alpha_nlcc(LBOUND(pot_in%alpha_nlcc, 1):UBOUND(pot_in%alpha_nlcc, 1)))
    3039           0 :          pot_out%alpha_nlcc(:) = pot_in%alpha_nlcc(:)
    3040             :       END IF
    3041          44 :       IF (ASSOCIATED(pot_in%nct_nlcc)) THEN
    3042           0 :          ALLOCATE (pot_out%nct_nlcc(LBOUND(pot_in%nct_nlcc, 1):UBOUND(pot_in%nct_nlcc, 1)))
    3043           0 :          pot_out%nct_nlcc(:) = pot_in%nct_nlcc(:)
    3044             :       END IF
    3045          44 :       IF (ASSOCIATED(pot_in%cval_nlcc)) THEN
    3046             :          ALLOCATE (pot_out%cval_nlcc(LBOUND(pot_in%cval_nlcc, 1):UBOUND(pot_in%cval_nlcc, 1), &
    3047           0 :                                      LBOUND(pot_in%cval_nlcc, 2):UBOUND(pot_in%cval_nlcc, 2)))
    3048           0 :          pot_out%cval_nlcc(:, :) = pot_in%cval_nlcc(:, :)
    3049             :       END IF
    3050          44 :       IF (ASSOCIATED(pot_in%alpha_lsd)) THEN
    3051           0 :          ALLOCATE (pot_out%alpha_lsd(LBOUND(pot_in%alpha_lsd, 1):UBOUND(pot_in%alpha_lsd, 1)))
    3052           0 :          pot_out%alpha_lsd(:) = pot_in%alpha_lsd(:)
    3053             :       END IF
    3054          44 :       IF (ASSOCIATED(pot_in%nct_lsd)) THEN
    3055           0 :          ALLOCATE (pot_out%nct_lsd(LBOUND(pot_in%nct_lsd, 1):UBOUND(pot_in%nct_lsd, 1)))
    3056           0 :          pot_out%nct_lsd(:) = pot_in%nct_lsd(:)
    3057             :       END IF
    3058          44 :       IF (ASSOCIATED(pot_in%cval_lsd)) THEN
    3059             :          ALLOCATE (pot_out%cval_lsd(LBOUND(pot_in%cval_lsd, 1):UBOUND(pot_in%cval_lsd, 1), &
    3060           0 :                                     LBOUND(pot_in%cval_lsd, 2):UBOUND(pot_in%cval_lsd, 2)))
    3061           0 :          pot_out%cval_lsd(:, :) = pot_in%cval_lsd(:, :)
    3062             :       END IF
    3063          44 :       IF (ASSOCIATED(pot_in%alpha_lpot)) THEN
    3064           0 :          ALLOCATE (pot_out%alpha_lpot(LBOUND(pot_in%alpha_lpot, 1):UBOUND(pot_in%alpha_lpot, 1)))
    3065           0 :          pot_out%alpha_lpot(:) = pot_in%alpha_lpot(:)
    3066             :       END IF
    3067          44 :       IF (ASSOCIATED(pot_in%nct_lpot)) THEN
    3068           0 :          ALLOCATE (pot_out%nct_lpot(LBOUND(pot_in%nct_lpot, 1):UBOUND(pot_in%nct_lpot, 1)))
    3069           0 :          pot_out%nct_lpot(:) = pot_in%nct_lpot(:)
    3070             :       END IF
    3071          44 :       IF (ASSOCIATED(pot_in%cval_lpot)) THEN
    3072             :          ALLOCATE (pot_out%cval_lpot(LBOUND(pot_in%cval_lpot, 1):UBOUND(pot_in%cval_lpot, 1), &
    3073           0 :                                      LBOUND(pot_in%cval_lpot, 2):UBOUND(pot_in%cval_lpot, 2)))
    3074           0 :          pot_out%cval_lpot(:, :) = pot_in%cval_lpot(:, :)
    3075             :       END IF
    3076             : 
    3077          44 :    END SUBROUTINE copy_gth_potential
    3078             : 
    3079             : ! **************************************************************************************************
    3080             : !> \brief Copy a sgp_potential_type to a new, unallocated variable
    3081             : !> \param pot_in the input potential to copy
    3082             : !> \param pot_out the newly copied and allocated potential
    3083             : !> \par History: created 12.2019 (A. Bussy)
    3084             : ! **************************************************************************************************
    3085           0 :    SUBROUTINE copy_sgp_potential(pot_in, pot_out)
    3086             : 
    3087             :       TYPE(sgp_potential_type), INTENT(IN)               :: pot_in
    3088             :       TYPE(sgp_potential_type), INTENT(INOUT), POINTER   :: pot_out
    3089             : 
    3090           0 :       CALL allocate_sgp_potential(pot_out)
    3091             : 
    3092           0 :       pot_out%name = pot_in%name
    3093           0 :       pot_out%aliases = pot_in%aliases
    3094           0 :       pot_out%z = pot_in%z
    3095           0 :       pot_out%zeff = pot_in%zeff
    3096           0 :       pot_out%zeff_correction = pot_in%zeff_correction
    3097           0 :       pot_out%alpha_core_charge = pot_in%alpha_core_charge
    3098           0 :       pot_out%ccore_charge = pot_in%ccore_charge
    3099           0 :       pot_out%core_charge_radius = pot_in%core_charge_radius
    3100           0 :       pot_out%ppl_radius = pot_in%ppl_radius
    3101           0 :       pot_out%ppnl_radius = pot_in%ppnl_radius
    3102           0 :       pot_out%ecp_local = pot_in%ecp_local
    3103           0 :       pot_out%n_local = pot_in%n_local
    3104           0 :       pot_out%nloc = pot_in%nloc
    3105           0 :       pot_out%nrloc = pot_in%nrloc
    3106           0 :       pot_out%aloc = pot_in%aloc
    3107           0 :       pot_out%bloc = pot_in%bloc
    3108           0 :       pot_out%n_nonlocal = pot_in%n_nonlocal
    3109           0 :       pot_out%nppnl = pot_in%nppnl
    3110           0 :       pot_out%lmax = pot_in%lmax
    3111           0 :       pot_out%is_nonlocal = pot_in%is_nonlocal
    3112           0 :       pot_out%has_nlcc = pot_in%has_nlcc
    3113           0 :       pot_out%n_nlcc = pot_in%n_nlcc
    3114             : 
    3115           0 :       IF (ASSOCIATED(pot_in%elec_conf)) THEN
    3116           0 :          ALLOCATE (pot_out%elec_conf(LBOUND(pot_in%elec_conf, 1):UBOUND(pot_in%elec_conf, 1)))
    3117           0 :          pot_out%elec_conf(:) = pot_in%elec_conf(:)
    3118             :       END IF
    3119           0 :       IF (ASSOCIATED(pot_in%a_local)) THEN
    3120           0 :          ALLOCATE (pot_out%a_local(LBOUND(pot_in%a_local, 1):UBOUND(pot_in%a_local, 1)))
    3121           0 :          pot_out%a_local(:) = pot_in%a_local(:)
    3122             :       END IF
    3123           0 :       IF (ASSOCIATED(pot_in%c_local)) THEN
    3124           0 :          ALLOCATE (pot_out%c_local(LBOUND(pot_in%c_local, 1):UBOUND(pot_in%c_local, 1)))
    3125           0 :          pot_out%c_local(:) = pot_in%c_local(:)
    3126             :       END IF
    3127           0 :       IF (ASSOCIATED(pot_in%a_nonlocal)) THEN
    3128           0 :          ALLOCATE (pot_out%a_nonlocal(LBOUND(pot_in%a_nonlocal, 1):UBOUND(pot_in%a_nonlocal, 1)))
    3129           0 :          pot_out%a_nonlocal(:) = pot_in%a_nonlocal(:)
    3130             :       END IF
    3131           0 :       IF (ASSOCIATED(pot_in%h_nonlocal)) THEN
    3132             :          ALLOCATE (pot_out%h_nonlocal(LBOUND(pot_in%h_nonlocal, 1):UBOUND(pot_in%h_nonlocal, 1), &
    3133           0 :                                       LBOUND(pot_in%h_nonlocal, 2):UBOUND(pot_in%h_nonlocal, 2)))
    3134           0 :          pot_out%h_nonlocal(:, :) = pot_in%h_nonlocal(:, :)
    3135             :       END IF
    3136           0 :       IF (ASSOCIATED(pot_in%c_nonlocal)) THEN
    3137             :          ALLOCATE (pot_out%c_nonlocal(LBOUND(pot_in%c_nonlocal, 1):UBOUND(pot_in%c_nonlocal, 1), &
    3138             :                                       LBOUND(pot_in%c_nonlocal, 2):UBOUND(pot_in%c_nonlocal, 2), &
    3139           0 :                                       LBOUND(pot_in%c_nonlocal, 3):UBOUND(pot_in%c_nonlocal, 3)))
    3140           0 :          pot_out%c_nonlocal(:, :, :) = pot_in%c_nonlocal(:, :, :)
    3141             :       END IF
    3142           0 :       IF (ASSOCIATED(pot_in%cprj_ppnl)) THEN
    3143             :          ALLOCATE (pot_out%cprj_ppnl(LBOUND(pot_in%cprj_ppnl, 1):UBOUND(pot_in%cprj_ppnl, 1), &
    3144           0 :                                      LBOUND(pot_in%cprj_ppnl, 2):UBOUND(pot_in%cprj_ppnl, 2)))
    3145           0 :          pot_out%cprj_ppnl(:, :) = pot_in%cprj_ppnl(:, :)
    3146             :       END IF
    3147           0 :       IF (ASSOCIATED(pot_in%vprj_ppnl)) THEN
    3148           0 :          ALLOCATE (pot_out%vprj_ppnl(LBOUND(pot_in%vprj_ppnl, 1):UBOUND(pot_in%vprj_ppnl, 1)))
    3149           0 :          pot_out%vprj_ppnl(:) = pot_in%vprj_ppnl(:)
    3150             :       END IF
    3151           0 :       IF (ASSOCIATED(pot_in%a_nlcc)) THEN
    3152           0 :          ALLOCATE (pot_out%a_nlcc(LBOUND(pot_in%a_nlcc, 1):UBOUND(pot_in%a_nlcc, 1)))
    3153           0 :          pot_out%a_nlcc(:) = pot_in%a_nlcc(:)
    3154             :       END IF
    3155           0 :       IF (ASSOCIATED(pot_in%c_nlcc)) THEN
    3156           0 :          ALLOCATE (pot_out%c_nlcc(LBOUND(pot_in%c_nlcc, 1):UBOUND(pot_in%c_nlcc, 1)))
    3157           0 :          pot_out%c_nlcc(:) = pot_in%c_nlcc(:)
    3158             :       END IF
    3159             : 
    3160           0 :    END SUBROUTINE copy_sgp_potential
    3161             : 
    3162           0 : END MODULE external_potential_types

Generated by: LCOV version 1.15