LCOV - code coverage report
Current view: top level - src - input_cp2k_check.F (source / functions) Coverage Total Hit
Test: CP2K Regtests (git:1be8651) Lines: 90.3 % 647 584
Test Date: 2026-11-24 01:22:08 Functions: 100.0 % 10 10

            Line data    Source code
       1              : !--------------------------------------------------------------------------------------------------!
       2              : !   CP2K: A general program to perform molecular dynamics simulations                              !
       3              : !   Copyright 2000-2026 CP2K developers group <https://cp2k.org>                                   !
       4              : !                                                                                                  !
       5              : !   SPDX-License-Identifier: GPL-2.0-or-later                                                      !
       6              : !--------------------------------------------------------------------------------------------------!
       7              : 
       8              : ! **************************************************************************************************
       9              : !> \brief checks the input and perform some automatic "magic" on it
      10              : !> \par History
      11              : !>      01.2006 created [fawzi]
      12              : !> \author fawzi
      13              : ! **************************************************************************************************
      14              : MODULE input_cp2k_check
      15              :    USE cell_types,                      ONLY: use_perd_none
      16              :    USE cp_log_handling,                 ONLY: cp_to_string
      17              :    USE cp_output_handling,              ONLY: debug_print_level
      18              :    USE cp_parser_types,                 ONLY: cp_parser_type,&
      19              :                                               parser_create,&
      20              :                                               parser_release
      21              :    USE cp_units,                        ONLY: cp_unit_set_create,&
      22              :                                               cp_unit_set_release,&
      23              :                                               cp_unit_set_type
      24              :    USE input_constants,                 ONLY: &
      25              :         do_qs, do_region_global, do_thermo_al, do_thermo_csvr, do_thermo_gle, do_thermo_nose, &
      26              :         do_thermo_same_as_part, mimic_run, negf_run, npt_f_ensemble, npt_i_ensemble, &
      27              :         npt_ia_ensemble, rtp_method_bse, rtp_method_bse_linearized, vdw_nl_LMKLL, xc_funct_b3lyp, &
      28              :         xc_funct_beefvdw, xc_funct_blyp, xc_funct_bp, xc_funct_hcth120, xc_funct_no_shortcut, &
      29              :         xc_funct_olyp, xc_funct_pade, xc_funct_pbe, xc_funct_pbe0, xc_funct_tpss, xc_funct_xwpbe, &
      30              :         xc_none, xc_vdw_fun_nonloc
      31              :    USE input_keyword_types,             ONLY: keyword_type
      32              :    USE input_parsing,                   ONLY: section_vals_parse
      33              :    USE input_section_types,             ONLY: &
      34              :         section_type, section_vals_create, section_vals_get, section_vals_get_subs_vals, &
      35              :         section_vals_get_subs_vals2, section_vals_get_subs_vals3, section_vals_release, &
      36              :         section_vals_remove_values, section_vals_set_subs_vals, section_vals_type, &
      37              :         section_vals_val_get, section_vals_val_set, section_vals_val_unset
      38              :    USE input_val_types,                 ONLY: logical_t
      39              :    USE kinds,                           ONLY: default_path_length,&
      40              :                                               default_string_length,&
      41              :                                               dp
      42              :    USE memory_utilities,                ONLY: reallocate
      43              :    USE message_passing,                 ONLY: mp_para_env_type
      44              :    USE xc_input_constants,              ONLY: do_vwn5
      45              : #include "./base/base_uses.f90"
      46              : 
      47              :    IMPLICIT NONE
      48              :    PRIVATE
      49              : 
      50              :    LOGICAL, PRIVATE, PARAMETER :: debug_this_module = .TRUE.
      51              :    CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'input_cp2k_check'
      52              : 
      53              :    PUBLIC :: check_cp2k_input, xc_functionals_expand, remove_restart_info
      54              : 
      55              : CONTAINS
      56              : 
      57              : ! **************************************************************************************************
      58              : !> \brief performs further checks on an input that parsed successfully
      59              : !> \param input_declaration ...
      60              : !> \param input_file the parsed input
      61              : !> \param para_env ...
      62              : !> \param output_unit ...
      63              : !> \author fawzi
      64              : !> \note
      65              : !>      at the moment does nothing
      66              : ! **************************************************************************************************
      67        91236 :    SUBROUTINE check_cp2k_input(input_declaration, input_file, para_env, output_unit)
      68              :       TYPE(section_type), POINTER                        :: input_declaration
      69              :       TYPE(section_vals_type), POINTER                   :: input_file
      70              :       TYPE(mp_para_env_type), POINTER                    :: para_env
      71              :       INTEGER, INTENT(IN), OPTIONAL                      :: output_unit
      72              : 
      73              :       CHARACTER(len=*), PARAMETER                        :: routineN = 'check_cp2k_input'
      74              : 
      75              :       INTEGER                                            :: force_eval_method, handle, iforce_eval, &
      76              :                                                             nforce_eval, run_type
      77              :       LOGICAL                                            :: apply_ext_potential, do_center, &
      78              :                                                             explicit, explicit_embed, explicit_mix
      79              :       TYPE(section_vals_type), POINTER                   :: section, section1, section2, section3, &
      80              :                                                             section4, sections
      81              : 
      82        22809 :       CALL timeset(routineN, handle)
      83        22809 :       CPASSERT(ASSOCIATED(input_file))
      84        22809 :       CPASSERT(input_file%ref_count > 0)
      85              :       ! ext_restart
      86        22809 :       IF (PRESENT(output_unit)) THEN
      87        22809 :          CALL handle_ext_restart(input_declaration, input_file, para_env, output_unit)
      88              :       END IF
      89              : 
      90              :       ! checks on force_eval section
      91        22809 :       sections => section_vals_get_subs_vals(input_file, "FORCE_EVAL")
      92        22809 :       CALL section_vals_get(sections, n_repetition=nforce_eval)
      93              : 
      94              :       ! multiple force_eval only if present RESPA, or MIXED or EMBED calculation is performed
      95        22809 :       section2 => section_vals_get_subs_vals(input_file, "MOTION%MD%RESPA")
      96        22809 :       CALL section_vals_get(section2, explicit=explicit)
      97        45048 :       DO iforce_eval = 1, nforce_eval
      98              :          section3 => section_vals_get_subs_vals(sections, "MIXED", &
      99        22517 :                                                 i_rep_section=iforce_eval)
     100        22517 :          CALL section_vals_get(section3, explicit=explicit_mix)
     101        45048 :          IF (explicit_mix) EXIT
     102              :       END DO
     103        45690 :       DO iforce_eval = 1, nforce_eval
     104              :          section4 => section_vals_get_subs_vals(sections, "EMBED", &
     105        22929 :                                                 i_rep_section=iforce_eval)
     106        22929 :          CALL section_vals_get(section4, explicit=explicit_embed)
     107        45690 :          IF (explicit_embed) EXIT
     108              :       END DO
     109              :       ! also allow multiple force_eval for NEGF run
     110        22809 :       CALL section_vals_val_get(input_file, "GLOBAL%RUN_TYPE", i_val=run_type)
     111              : 
     112        22809 :       IF (((explicit .AND. (nforce_eval == 1)) .OR. (.NOT. explicit .AND. (nforce_eval > 1))) .AND. run_type /= negf_run) THEN
     113          326 :          IF ((explicit_mix .AND. (nforce_eval == 1)) .OR. (.NOT. explicit_mix .AND. (nforce_eval > 1))) THEN
     114           48 :             IF ((explicit_embed .AND. (nforce_eval == 1)) .OR. (.NOT. explicit_embed .AND. (nforce_eval > 1))) THEN
     115              :                CALL cp_abort(__LOCATION__, &
     116              :                              "Error multiple force_env without RESPA or MIXED or EMBED, or RESPA with one single "// &
     117            0 :                              "or MIXED with only two force_env section.")
     118              :             END IF
     119              :          END IF
     120              :       END IF
     121        45930 :       DO iforce_eval = 1, nforce_eval
     122        23121 :          section => section_vals_get_subs_vals3(sections, "DFT", i_rep_section=iforce_eval)
     123              :          ! xc: expand and fix default for tddfpt
     124        23121 :          section1 => section_vals_get_subs_vals(section, "XC")
     125        23121 :          section2 => section_vals_get_subs_vals(section, "XC%XC_FUNCTIONAL")
     126        23121 :          CALL xc_functionals_expand(section2, section1)
     127        23121 :          section1 => section_vals_get_subs_vals(section, "XAS_TDP%KERNEL")
     128        23121 :          section2 => section_vals_get_subs_vals(section, "XAS_TDP%KERNEL%XC_FUNCTIONAL")
     129        23121 :          CALL xc_functionals_expand(section2, section1)
     130        23121 :          section1 => section_vals_get_subs_vals(sections, "PROPERTIES%RIXS%XAS_TDP%KERNEL")
     131        23121 :          section2 => section_vals_get_subs_vals(sections, "PROPERTIES%RIXS%XAS_TDP%KERNEL%XC_FUNCTIONAL")
     132        23121 :          CALL xc_functionals_expand(section2, section1)
     133        23121 :          section1 => section_vals_get_subs_vals(section, "ACTIVE_SPACE%XC")
     134        23121 :          section2 => section_vals_get_subs_vals(section, "ACTIVE_SPACE%XC%XC_FUNCTIONAL")
     135        23121 :          CALL xc_functionals_expand(section2, section1)
     136        45930 :          CALL check_properties_bse(sections, iforce_eval)
     137              :       END DO
     138              : 
     139              :       ! additional checks for a MiMiC run
     140        22809 :       IF (run_type == mimic_run) THEN
     141              :          ! disable CENTER_COORDINATES
     142              :          CALL section_vals_val_get(sections, "SUBSYS%TOPOLOGY%CENTER_COORDINATES%_SECTION_PARAMETERS_", &
     143            0 :                                    l_val=do_center)
     144            0 :          IF (do_center) THEN
     145              :             CALL section_vals_val_set(sections, &
     146              :                                       "SUBSYS%TOPOLOGY%CENTER_COORDINATES%_SECTION_PARAMETERS_", &
     147            0 :                                       l_val=.FALSE.)
     148            0 :             CPWARN("Turning off CENTER_COORDINATES for a MiMiC run.")
     149              :          END IF
     150              : 
     151              :          ! do not allow the use of external potential
     152            0 :          section => section_vals_get_subs_vals(sections, "DFT%EXTERNAL_POTENTIAL")
     153            0 :          CALL section_vals_get(section, explicit=apply_ext_potential)
     154            0 :          IF (apply_ext_potential) THEN
     155            0 :             CPABORT("The EXTERNAL_POTENTIAL section is not allowed for the MiMiC runtype.")
     156              :          END IF
     157              : 
     158              :          ! force eval methods supported with MiMiC
     159            0 :          CALL section_vals_val_get(sections, "METHOD", i_val=force_eval_method)
     160            0 :          IF (force_eval_method /= do_qs) THEN
     161            0 :             CPABORT("At the moment, only Quickstep method is supported with MiMiC.")
     162              :          END IF
     163              :       END IF
     164              : 
     165        22809 :       CALL timestop(handle)
     166        22809 :    END SUBROUTINE check_cp2k_input
     167              : 
     168              : ! **************************************************************************************************
     169              : !> \brief Refuses, before the SCF, the input combinations PROPERTIES%BSE cannot run: no GW in
     170              : !>        PROPERTIES%BANDSTRUCTURE, its RI_RS, a periodic cell, k-points beyond Gamma, an RTBSE in the
     171              : !>        same run, NTO cubes (the GW releases the SCF grids they are collocated on)
     172              : !> \param force_env_sections the FORCE_EVAL sections
     173              : !> \param iforce_eval the repetition checked
     174              : ! **************************************************************************************************
     175        46326 :    SUBROUTINE check_properties_bse(force_env_sections, iforce_eval)
     176              :       TYPE(section_vals_type), POINTER                   :: force_env_sections
     177              :       INTEGER, INTENT(IN)                                :: iforce_eval
     178              : 
     179              :       INTEGER                                            :: n_special_kp, periodic, print_level_nto, &
     180              :                                                             rtp_method
     181        23121 :       INTEGER, DIMENSION(:), POINTER                     :: nkp_grid_dos
     182              :       LOGICAL                                            :: cube_files, do_bse, do_gw, do_ri_rs
     183              :       TYPE(section_vals_type), POINTER                   :: bs_sec, bse_sec, dft_sec, gw_sec, &
     184              :                                                             properties_sec, subsys_sec
     185              : 
     186        23121 :       NULLIFY (bs_sec, bse_sec, dft_sec, gw_sec, nkp_grid_dos, properties_sec, subsys_sec)
     187        46242 :       properties_sec => section_vals_get_subs_vals3(force_env_sections, "PROPERTIES", i_rep_section=iforce_eval)
     188        23121 :       bse_sec => section_vals_get_subs_vals(properties_sec, "BSE")
     189        23121 :       CALL section_vals_get(bse_sec, explicit=do_bse)
     190        23121 :       IF (.NOT. do_bse) RETURN
     191              : 
     192           12 :       bs_sec => section_vals_get_subs_vals(properties_sec, "BANDSTRUCTURE")
     193           12 :       gw_sec => section_vals_get_subs_vals(bs_sec, "GW")
     194           12 :       CALL section_vals_get(gw_sec, explicit=do_gw)
     195           12 :       IF (.NOT. do_gw) CPABORT("PROPERTIES%BSE needs PROPERTIES%BANDSTRUCTURE%GW")
     196              :       ! the BSE kernel is built from the three-center RI integrals, which RI_RS replaces by a grid
     197           12 :       CALL section_vals_val_get(gw_sec, "RI_RS%_SECTION_PARAMETERS_", l_val=do_ri_rs)
     198           12 :       IF (do_ri_rs) THEN
     199              :          CALL cp_abort(__LOCATION__, &
     200              :                        "PROPERTIES%BSE needs the three-center RI integrals of the GW: remove the "// &
     201            0 :                        "RI_RS subsection from PROPERTIES%BANDSTRUCTURE%GW")
     202              :       END IF
     203           12 :       subsys_sec => section_vals_get_subs_vals3(force_env_sections, "SUBSYS", i_rep_section=iforce_eval)
     204           12 :       CALL section_vals_val_get(subsys_sec, "CELL%PERIODIC", i_val=periodic)
     205           12 :       IF (periodic /= use_perd_none) THEN
     206              :          CALL cp_abort(__LOCATION__, &
     207              :                        "The BSE treats non-periodic systems only: PROPERTIES%BSE needs "// &
     208            0 :                        "PERIODIC NONE in the CELL section")
     209              :       END IF
     210              :       ! the BSE reads the MOs and the GW energies at the Gamma point, the only k-point of a
     211              :       ! non-periodic run unless a band path or a DOS k-grid adds more
     212           12 :       CALL section_vals_val_get(bs_sec, "BANDSTRUCTURE_PATH%SPECIAL_POINT", n_rep_val=n_special_kp)
     213           12 :       CALL section_vals_val_get(bs_sec, "DOS%KPOINTS", i_vals=nkp_grid_dos)
     214           48 :       IF (n_special_kp > 0 .OR. ANY(nkp_grid_dos > 1)) THEN
     215              :          CALL cp_abort(__LOCATION__, &
     216              :                        "PROPERTIES%BSE needs the Gamma point only: remove BANDSTRUCTURE_PATH and "// &
     217            0 :                        "DOS%KPOINTS from PROPERTIES%BANDSTRUCTURE")
     218              :       END IF
     219              :       ! both read the W(0) and the neighbour list the GW keeps, and PROPERTIES%BSE frees them
     220           12 :       dft_sec => section_vals_get_subs_vals3(force_env_sections, "DFT", i_rep_section=iforce_eval)
     221           12 :       CALL section_vals_val_get(dft_sec, "REAL_TIME_PROPAGATION%RTBSE%_SECTION_PARAMETERS_", i_val=rtp_method)
     222           12 :       IF (rtp_method == rtp_method_bse .OR. rtp_method == rtp_method_bse_linearized) THEN
     223              :          CALL cp_abort(__LOCATION__, &
     224              :                        "PROPERTIES%BSE and DFT%REAL_TIME_PROPAGATION%RTBSE may not share a run: "// &
     225            0 :                        "remove one of the two sections")
     226              :       END IF
     227              :       ! the GW releases the SCF grids at its init; the NTO cube writer collocates on them
     228              :       ! (CUBE_FILES defaults to true; the print key's level is the switch, OFF encoded as
     229              :       ! debug_print_level + 1, read as read_bse_section reads it)
     230           12 :       CALL section_vals_val_get(bse_sec, "NTO_ANALYSIS%_SECTION_PARAMETERS_", i_val=print_level_nto)
     231           12 :       CALL section_vals_val_get(bse_sec, "NTO_ANALYSIS%CUBE_FILES", l_val=cube_files)
     232           12 :       IF (print_level_nto /= debug_print_level + 1 .AND. cube_files) THEN
     233              :          CALL cp_abort(__LOCATION__, &
     234              :                        "PROPERTIES%BSE runs after the GW released the SCF grids: set "// &
     235              :                        "NTO_ANALYSIS%CUBE_FILES to F, or write the cubes from the BSE of "// &
     236            0 :                        "XC%WF_CORRELATION%RI_RPA%GW")
     237              :       END IF
     238              : 
     239        23121 :    END SUBROUTINE check_properties_bse
     240              : 
     241              : ! **************************************************************************************************
     242              : !> \brief expand a shortcutted functional section
     243              : !> \param functionals the functional section to expand
     244              : !> \param xc_section ...
     245              : !> \author fawzi
     246              : ! **************************************************************************************************
     247        95225 :    SUBROUTINE xc_functionals_expand(functionals, xc_section)
     248              :       TYPE(section_vals_type), POINTER                   :: functionals, xc_section
     249              : 
     250              :       CHARACTER(LEN=512)                                 :: wrn_msg
     251              :       INTEGER                                            :: ifun, nfun, shortcut
     252              :       TYPE(section_vals_type), POINTER                   :: xc_fun
     253              : 
     254              :       CALL section_vals_val_get(functionals, "_SECTION_PARAMETERS_", &
     255        95225 :                                 i_val=shortcut)
     256              : 
     257        95225 :       ifun = 0
     258        95225 :       nfun = 0
     259        10777 :       DO
     260       106002 :          ifun = ifun + 1
     261       106002 :          xc_fun => section_vals_get_subs_vals2(functionals, i_section=ifun)
     262       106002 :          IF (.NOT. ASSOCIATED(xc_fun)) EXIT
     263        10777 :          nfun = nfun + 1
     264              :       END DO
     265              : !
     266        95225 :       IF (shortcut /= xc_funct_no_shortcut .AND. shortcut /= xc_none .AND. nfun > 0) THEN
     267              :          WRITE (wrn_msg, '(A)') "User requested a shortcut while defining an explicit XC functional. "// &
     268          102 :             "This is not recommended as it could lead to spurious behaviour. Please check input parameters."
     269          102 :          CPWARN(wrn_msg)
     270              :       END IF
     271              : 
     272          418 :       SELECT CASE (shortcut)
     273              :       CASE (xc_funct_no_shortcut, xc_none)
     274              :          ! nothing to expand
     275              :       CASE (xc_funct_pbe0)
     276              :          CALL section_vals_val_set(functionals, "PBE%_SECTION_PARAMETERS_", &
     277          418 :                                    l_val=.TRUE.)
     278              :          CALL section_vals_val_set(functionals, "PBE%SCALE_X", &
     279          418 :                                    r_val=0.75_dp)
     280              :          CALL section_vals_val_set(functionals, "PBE%SCALE_C", &
     281          418 :                                    r_val=1.0_dp)
     282              :          ! Hartree Fock Exact Exchange
     283              :          CALL section_vals_val_set(xc_section, "HF%FRACTION", &
     284          418 :                                    r_val=0.25_dp)
     285              :          CALL section_vals_val_set(functionals, "_SECTION_PARAMETERS_", &
     286          418 :                                    i_val=xc_funct_no_shortcut)
     287              :       CASE (xc_funct_beefvdw)
     288              :          CALL section_vals_val_set(functionals, "PBE%_SECTION_PARAMETERS_", & !40% PBEc
     289            2 :                                    l_val=.TRUE.)
     290              :          CALL section_vals_val_set(functionals, "PBE%SCALE_C", &
     291            2 :                                    r_val=0.3998335231_dp)
     292              :          CALL section_vals_val_set(functionals, "PBE%SCALE_X", & !no PBEx
     293            2 :                                    r_val=0.0000000000_dp)
     294              : 
     295              :          !PW92 correlation functional from libxc is required.
     296              :          !The cp2k-native PW92 gives disagreeing results (in the 0.01E_H
     297              :          !decimal) and yields inconsistent forces in a DEBUG run.
     298              :          !(rk, 6.3.2014)
     299              :          CALL section_vals_val_set(functionals, "LDA_C_PW%_SECTION_PARAMETERS_", & !60%LDA
     300            2 :                                    l_val=.TRUE.)
     301              :          CALL section_vals_val_set(functionals, "LDA_C_PW%SCALE", &
     302            2 :                                    r_val=0.6001664769_dp)
     303              : 
     304              :          CALL section_vals_val_set(functionals, "BEEF%_SECTION_PARAMETERS_", & !BEEF exchange
     305            2 :                                    l_val=.TRUE.)
     306              : 
     307              :          !NONLOCAL, LMKLL.
     308              :          CALL section_vals_val_set(xc_section, "VDW_POTENTIAL%DISPERSION_FUNCTIONAL", &
     309            2 :                                    i_val=xc_vdw_fun_nonloc)
     310              :          CALL section_vals_val_set(xc_section, "VDW_POTENTIAL%NON_LOCAL%TYPE", &
     311            2 :                                    i_val=vdw_nl_LMKLL)
     312              :          CALL section_vals_val_set(functionals, "_SECTION_PARAMETERS_", &
     313            2 :                                    i_val=xc_funct_no_shortcut)
     314              :       CASE (xc_funct_b3lyp)
     315              :          CALL section_vals_val_set(functionals, "BECKE88%_SECTION_PARAMETERS_", &
     316           40 :                                    l_val=.TRUE.)
     317              :          CALL section_vals_val_set(functionals, "BECKE88%SCALE_X", &
     318           40 :                                    r_val=0.72_dp)
     319              :          CALL section_vals_val_set(functionals, "LYP%_SECTION_PARAMETERS_", &
     320           40 :                                    l_val=.TRUE.)
     321              :          CALL section_vals_val_set(functionals, "LYP%SCALE_C", &
     322           40 :                                    r_val=0.81_dp)
     323              :          CALL section_vals_val_set(functionals, "VWN%_SECTION_PARAMETERS_", &
     324           40 :                                    l_val=.TRUE.)
     325              :          CALL section_vals_val_set(functionals, "VWN%FUNCTIONAL_TYPE", &
     326           40 :                                    i_val=do_vwn5)
     327              :          CALL section_vals_val_set(functionals, "VWN%SCALE_C", &
     328           40 :                                    r_val=0.19_dp)
     329              :          CALL section_vals_val_set(functionals, "XALPHA%_SECTION_PARAMETERS_", &
     330           40 :                                    l_val=.TRUE.)
     331              :          CALL section_vals_val_set(functionals, "XALPHA%SCALE_X", &
     332           40 :                                    r_val=0.08_dp)
     333              :          ! Hartree Fock Exact Exchange
     334              :          CALL section_vals_val_set(xc_section, "HF%FRACTION", &
     335           40 :                                    r_val=0.20_dp)
     336              :          CALL section_vals_val_set(functionals, "_SECTION_PARAMETERS_", &
     337           40 :                                    i_val=xc_funct_no_shortcut)
     338              :       CASE (xc_funct_blyp)
     339              :          CALL section_vals_val_set(functionals, "BECKE88%_SECTION_PARAMETERS_", &
     340          450 :                                    l_val=.TRUE.)
     341              :          CALL section_vals_val_set(functionals, "LYP%_SECTION_PARAMETERS_", &
     342          450 :                                    l_val=.TRUE.)
     343              :          CALL section_vals_val_set(functionals, "_SECTION_PARAMETERS_", &
     344          450 :                                    i_val=xc_funct_no_shortcut)
     345              :       CASE (xc_funct_bp)
     346              :          CALL section_vals_val_set(functionals, "BECKE88%_SECTION_PARAMETERS_", &
     347           14 :                                    l_val=.TRUE.)
     348              :          CALL section_vals_val_set(functionals, "P86C%_SECTION_PARAMETERS_", &
     349           14 :                                    l_val=.TRUE.)
     350              :          CALL section_vals_val_set(functionals, "_SECTION_PARAMETERS_", &
     351           14 :                                    i_val=xc_funct_no_shortcut)
     352              :       CASE (xc_funct_pade)
     353              :          CALL section_vals_val_set(functionals, "PADE%_SECTION_PARAMETERS_", &
     354         2375 :                                    l_val=.TRUE.)
     355              :          CALL section_vals_val_set(functionals, "_SECTION_PARAMETERS_", &
     356         2375 :                                    i_val=xc_funct_no_shortcut)
     357              :       CASE (xc_funct_pbe)
     358              :          CALL section_vals_val_set(functionals, "PBE%_SECTION_PARAMETERS_", &
     359         2382 :                                    l_val=.TRUE.)
     360              :          CALL section_vals_val_set(functionals, "_SECTION_PARAMETERS_", &
     361         2382 :                                    i_val=xc_funct_no_shortcut)
     362              :       CASE (xc_funct_xwpbe)
     363              :          CALL section_vals_val_set(functionals, "XWPBE%_SECTION_PARAMETERS_", &
     364            0 :                                    l_val=.TRUE.)
     365              :          CALL section_vals_val_set(functionals, "_SECTION_PARAMETERS_", &
     366            0 :                                    i_val=xc_funct_no_shortcut)
     367              :       CASE (xc_funct_tpss)
     368              :          CALL section_vals_val_set(functionals, "TPSS%_SECTION_PARAMETERS_", &
     369           96 :                                    l_val=.TRUE.)
     370              :          CALL section_vals_val_set(functionals, "_SECTION_PARAMETERS_", &
     371           96 :                                    i_val=xc_funct_no_shortcut)
     372              :       CASE (xc_funct_olyp)
     373              :          CALL section_vals_val_set(functionals, "OPTX%_SECTION_PARAMETERS_", &
     374            6 :                                    l_val=.TRUE.)
     375              :          CALL section_vals_val_set(functionals, "LYP%_SECTION_PARAMETERS_", &
     376            6 :                                    l_val=.TRUE.)
     377              :          CALL section_vals_val_set(functionals, "_SECTION_PARAMETERS_", &
     378            6 :                                    i_val=xc_funct_no_shortcut)
     379              :       CASE (xc_funct_hcth120)
     380              :          CALL section_vals_val_set(functionals, "HCTH%_SECTION_PARAMETERS_", &
     381           14 :                                    l_val=.TRUE.)
     382              :          CALL section_vals_val_set(functionals, "HCTH%PARAMETER_SET", &
     383           14 :                                    i_val=120)
     384              :          CALL section_vals_val_set(functionals, "_SECTION_PARAMETERS_", &
     385           14 :                                    i_val=xc_funct_no_shortcut)
     386              :       CASE default
     387        95225 :          CPABORT("unknown shortcut "//TRIM(ADJUSTL(cp_to_string(shortcut))))
     388              :       END SELECT
     389        95225 :    END SUBROUTINE xc_functionals_expand
     390              : 
     391              : ! **************************************************************************************************
     392              : !> \brief Replaces the requested sections in the input with those found
     393              : !>      in the external restart (EXT_RESTART%RESTART_FILE_NAME).
     394              : !> \param input_declaration ...
     395              : !> \param input_file the input file to initialize
     396              : !> \param para_env ...
     397              : !> \param output_unit ...
     398              : !> \author fawzi
     399              : ! **************************************************************************************************
     400        22809 :    SUBROUTINE handle_ext_restart(input_declaration, input_file, para_env, output_unit)
     401              :       TYPE(section_type), POINTER                        :: input_declaration
     402              :       TYPE(section_vals_type), POINTER                   :: input_file
     403              :       TYPE(mp_para_env_type), POINTER                    :: para_env
     404              :       INTEGER, INTENT(IN)                                :: output_unit
     405              : 
     406              :       CHARACTER(len=*), PARAMETER :: routineN = 'handle_ext_restart'
     407              : 
     408              :       CHARACTER(default_path_length)                     :: r_file_path
     409              :       INTEGER                                            :: handle
     410              :       TYPE(section_vals_type), POINTER                   :: r_section
     411              : 
     412        22809 :       CALL timeset(routineN, handle)
     413              :       ! Handle restart file
     414        22809 :       r_section => section_vals_get_subs_vals(input_file, "EXT_RESTART")
     415        22809 :       CALL section_vals_val_get(r_section, "RESTART_FILE_NAME", c_val=r_file_path)
     416              : 
     417        22809 :       IF (r_file_path /= " ") THEN
     418              :          BLOCK
     419              :             CHARACTER(default_path_length)                     :: binary_restart_file
     420              :             CHARACTER(default_string_length)                   :: path
     421              :             CHARACTER(LEN=default_string_length), &
     422          226 :                DIMENSION(:), POINTER                           :: restarted_infos
     423              :             INTEGER                                            :: ensemble, i_rep_val, &
     424              :                                                                   iforce_eval, myi, n_rep_val, &
     425              :                                                                   nforce_eval1, nforce_eval2
     426          226 :             INTEGER, DIMENSION(:), POINTER                     :: ivec, iwalkers_status, iwork, &
     427          226 :                                                                   rwalkers_status
     428              :             LOGICAL                                            :: bsse_check, check, explicit1, explicit2, &
     429              :                                                                   flag, flag2, qmmm_check, subsys_check
     430              :             REAL(KIND=dp)                                      :: myt
     431          226 :             REAL(KIND=dp), DIMENSION(:), POINTER               :: vec, work
     432              :             TYPE(section_vals_type), POINTER                   :: rep_sections, restart_file, &
     433              :                                                                   section, section1, section2, &
     434              :                                                                   sections1, sections2
     435              : 
     436          226 :             NULLIFY (restarted_infos, iwalkers_status, rwalkers_status, vec, ivec, work, iwork)
     437          226 :             CALL section_vals_val_get(r_section, "BINARY_RESTART_FILE_NAME", c_val=binary_restart_file)
     438              : 
     439              :             BLOCK
     440              :                TYPE(cp_parser_type)                      :: cpparser
     441              :                TYPE(cp_unit_set_type)                   :: default_units
     442              :                ! parse the input
     443          226 :                NULLIFY (restart_file)
     444          226 :                CALL section_vals_create(restart_file, input_declaration)
     445          226 :                CALL parser_create(cpparser, file_name=r_file_path, para_env=para_env)
     446          226 :                CALL cp_unit_set_create(default_units, "OUTPUT")
     447              :                CALL section_vals_parse(restart_file, cpparser, root_section=.FALSE., &
     448          226 :                                        default_units=default_units)
     449          226 :                CALL cp_unit_set_release(default_units)
     450         3616 :                CALL parser_release(cpparser)
     451              :             END BLOCK
     452              : 
     453              :             ! Restart and input files same number of force_env sections
     454          226 :             sections1 => section_vals_get_subs_vals(restart_file, "FORCE_EVAL")
     455          226 :             CALL section_vals_get(sections1, n_repetition=nforce_eval1)
     456          226 :             sections2 => section_vals_get_subs_vals(input_file, "FORCE_EVAL")
     457          226 :             CALL section_vals_get(sections2, n_repetition=nforce_eval2)
     458          226 :             IF (nforce_eval1 /= nforce_eval2) THEN
     459            0 :                CPABORT("Restart and input file MUST have the number of force_env sections")
     460              :             END IF
     461              :             ! Handle default restarts
     462          226 :             CALL handle_defaults_restart(r_section)
     463              : 
     464              :             ! Real restart of force_evals
     465          468 :             DO iforce_eval = 1, nforce_eval1
     466              :                section1 => section_vals_get_subs_vals3(sections1, "SUBSYS", &
     467          242 :                                                        i_rep_section=iforce_eval)
     468              :                section2 => section_vals_get_subs_vals3(sections2, "SUBSYS", &
     469          242 :                                                        i_rep_section=iforce_eval)
     470              :                ! Some care needs to be handled when treating multiple force_eval
     471              :                ! Both subsys need to be consistently associated or not
     472              :                ! Mixed stuff will be rejected for safety reason..
     473          242 :                subsys_check = (ASSOCIATED(section1) .EQV. ASSOCIATED(section2))
     474          242 :                IF (subsys_check) THEN
     475          242 :                   IF (ASSOCIATED(section1)) THEN
     476          242 :                      CALL section_vals_val_get(r_section, "RESTART_CELL", l_val=flag)
     477          242 :                      IF (flag) THEN
     478          220 :                         section => section_vals_get_subs_vals(section1, "CELL")
     479          220 :                         CALL section_vals_set_subs_vals(section2, "CELL", section)
     480          220 :                         CALL set_restart_info("CELL", restarted_infos)
     481              :                      END IF
     482              : 
     483          242 :                      CALL section_vals_val_get(r_section, "RESTART_POS", l_val=flag)
     484          242 :                      IF (flag) THEN
     485          230 :                         section => section_vals_get_subs_vals(section1, "COORD")
     486          230 :                         CALL section_vals_set_subs_vals(section2, "COORD", section)
     487          230 :                         CALL set_restart_info("COORDINATES", restarted_infos)
     488              :                         ! Copy over also the information on the multiple_unit_cell
     489          230 :                         CALL section_vals_val_get(section1, "TOPOLOGY%MULTIPLE_UNIT_CELL", i_vals=ivec)
     490          230 :                         ALLOCATE (iwork(3))
     491         1610 :                         iwork = ivec
     492          230 :                         CALL section_vals_val_set(section2, "TOPOLOGY%MULTIPLE_UNIT_CELL", i_vals_ptr=iwork)
     493              :                      END IF
     494              : 
     495          242 :                      CALL section_vals_val_get(r_section, "RESTART_RANDOMG", l_val=flag)
     496          242 :                      IF (flag) THEN
     497          210 :                         section => section_vals_get_subs_vals(section1, "RNG_INIT")
     498          210 :                         CALL section_vals_set_subs_vals(section2, "RNG_INIT", section)
     499          210 :                         CALL set_restart_info("RANDOM NUMBER GENERATOR", restarted_infos)
     500              :                      END IF
     501              : 
     502          242 :                      CALL section_vals_val_get(r_section, "RESTART_VEL", l_val=flag)
     503          242 :                      IF (flag) THEN
     504          224 :                         section => section_vals_get_subs_vals(section1, "VELOCITY")
     505          224 :                         CALL section_vals_set_subs_vals(section2, "VELOCITY", section)
     506          224 :                         CALL set_restart_info("VELOCITIES", restarted_infos)
     507              :                      END IF
     508              : 
     509              :                      ! Core-Shell information "restarted" only when strictly necessary
     510          242 :                      CALL section_vals_val_get(r_section, "RESTART_SHELL_POS", l_val=flag)
     511          242 :                      IF (flag) THEN
     512          230 :                         section => section_vals_get_subs_vals(section1, "SHELL_COORD")
     513          230 :                         CALL section_vals_set_subs_vals(section2, "SHELL_COORD", section)
     514          230 :                         IF (check_restart(section1, section2, "SHELL_COORD")) THEN
     515           32 :                            CALL set_restart_info("SHELL COORDINATES", restarted_infos)
     516              :                         END IF
     517              :                      END IF
     518          242 :                      CALL section_vals_val_get(r_section, "RESTART_CORE_POS", l_val=flag)
     519          242 :                      IF (flag) THEN
     520          230 :                         section => section_vals_get_subs_vals(section1, "CORE_COORD")
     521          230 :                         CALL section_vals_set_subs_vals(section2, "CORE_COORD", section)
     522          230 :                         IF (check_restart(section1, section2, "CORE_COORD")) THEN
     523           32 :                            CALL set_restart_info("CORE COORDINATES", restarted_infos)
     524              :                         END IF
     525              :                      END IF
     526          242 :                      CALL section_vals_val_get(r_section, "RESTART_SHELL_VELOCITY", l_val=flag)
     527          242 :                      IF (flag) THEN
     528          230 :                         section => section_vals_get_subs_vals(section1, "SHELL_VELOCITY")
     529          230 :                         CALL section_vals_set_subs_vals(section2, "SHELL_VELOCITY", section)
     530          230 :                         IF (check_restart(section1, section2, "SHELL_VELOCITY")) THEN
     531           24 :                            CALL set_restart_info("SHELL VELOCITIES", restarted_infos)
     532              :                         END IF
     533              :                      END IF
     534          242 :                      CALL section_vals_val_get(r_section, "RESTART_CORE_VELOCITY", l_val=flag)
     535          242 :                      IF (flag) THEN
     536          230 :                         section => section_vals_get_subs_vals(section1, "CORE_VELOCITY")
     537          230 :                         CALL section_vals_set_subs_vals(section2, "CORE_VELOCITY", section)
     538          230 :                         IF (check_restart(section1, section2, "CORE_VELOCITY")) THEN
     539           24 :                            CALL set_restart_info("CORE VELOCITIES", restarted_infos)
     540              :                         END IF
     541              :                      END IF
     542              :                   END IF
     543              :                ELSE
     544              :                   CALL cp_abort(__LOCATION__, &
     545              :                                 "Error while reading the restart file. Two force_eval have incompatible"// &
     546              :                                 " subsys.One of them has an allocated subsys while the other has not! Check your"// &
     547            0 :                                 " input file or whether the restart file is compatible with the input!")
     548              :                END IF
     549              :                ! QMMM restarts
     550          242 :                CALL section_vals_val_get(r_section, "RESTART_QMMM", l_val=flag)
     551          242 :                section1 => section_vals_get_subs_vals3(sections1, "QMMM", i_rep_section=iforce_eval)
     552          242 :                section2 => section_vals_get_subs_vals3(sections2, "QMMM", i_rep_section=iforce_eval)
     553          242 :                CALL section_vals_get(section1, explicit=explicit1)
     554          242 :                CALL section_vals_get(section2, explicit=explicit2)
     555          242 :                qmmm_check = (explicit1 .AND. explicit2)
     556          242 :                IF (flag .AND. qmmm_check) THEN
     557            0 :                   CALL set_restart_info("QMMM TRANSLATION VECTOR", restarted_infos)
     558            0 :                   CALL section_vals_val_get(section1, "INITIAL_TRANSLATION_VECTOR", r_vals=vec)
     559            0 :                   ALLOCATE (work(3))
     560            0 :                   work = vec
     561            0 :                   CALL section_vals_val_set(section2, "INITIAL_TRANSLATION_VECTOR", r_vals_ptr=work)
     562              :                END IF
     563              :                ! BSSE restarts
     564          242 :                CALL section_vals_val_get(r_section, "RESTART_BSSE", l_val=flag)
     565          242 :                section1 => section_vals_get_subs_vals3(sections1, "BSSE", i_rep_section=iforce_eval)
     566          242 :                section2 => section_vals_get_subs_vals3(sections2, "BSSE", i_rep_section=iforce_eval)
     567          242 :                CALL section_vals_get(section1, explicit=explicit1)
     568          242 :                CALL section_vals_get(section2, explicit=explicit2)
     569          242 :                bsse_check = (explicit1 .AND. explicit2)
     570         1436 :                IF (flag .AND. bsse_check) THEN
     571            2 :                   section => section_vals_get_subs_vals(section1, "FRAGMENT_ENERGIES")
     572            2 :                   CALL section_vals_set_subs_vals(section2, "FRAGMENT_ENERGIES", section)
     573            2 :                   CALL set_restart_info("BSSE FRAGMENT ENERGIES", restarted_infos)
     574              :                END IF
     575              :             END DO
     576              : 
     577          226 :             CALL section_vals_val_get(r_section, "RESTART_COUNTERS", l_val=flag)
     578          226 :             IF (flag) THEN
     579          210 :                IF (check_restart(input_file, restart_file, "MOTION%MD")) THEN
     580          168 :                   CALL section_vals_val_get(restart_file, "MOTION%MD%STEP_START_VAL", i_val=myi)
     581          168 :                   CALL section_vals_val_set(input_file, "MOTION%MD%STEP_START_VAL", i_val=myi)
     582          168 :                   CALL section_vals_val_get(restart_file, "MOTION%MD%TIME_START_VAL", r_val=myt)
     583          168 :                   CALL section_vals_val_set(input_file, "MOTION%MD%TIME_START_VAL", r_val=myt)
     584          168 :                   CALL section_vals_val_get(restart_file, "MOTION%MD%ECONS_START_VAL", r_val=myt)
     585          168 :                   CALL section_vals_val_set(input_file, "MOTION%MD%ECONS_START_VAL", r_val=myt)
     586          168 :                   CALL set_restart_info("MD COUNTERS", restarted_infos)
     587              :                END IF
     588              :                !
     589              :                ! Electronic extended variable (&MOTION&MD&ELECTRONS): q, p and the potentiostat
     590              :                ! state belong to the trajectory, so they are restored together with the MD counters.
     591              :                ! Without this a continued run silently restarts from the input deck's Q_INIT/P_INIT.
     592              :                ! check_restart requires the section in BOTH decks, so inputs without &ELECTRONS
     593              :                ! are unaffected.
     594          210 :                IF (check_restart(input_file, restart_file, "MOTION%MD%ELECTRONS")) THEN
     595            0 :                   CALL section_vals_val_get(restart_file, "MOTION%MD%ELECTRONS%Q_INIT", r_val=myt)
     596            0 :                   CALL section_vals_val_set(input_file, "MOTION%MD%ELECTRONS%Q_INIT", r_val=myt)
     597            0 :                   CALL section_vals_val_get(restart_file, "MOTION%MD%ELECTRONS%P_INIT", r_val=myt)
     598            0 :                   CALL section_vals_val_set(input_file, "MOTION%MD%ELECTRONS%P_INIT", r_val=myt)
     599              :                   CALL section_vals_val_get(restart_file, "MOTION%MD%ELECTRONS%POTENTIOSTAT_ENERGY", &
     600            0 :                                             r_val=myt)
     601              :                   CALL section_vals_val_set(input_file, "MOTION%MD%ELECTRONS%POTENTIOSTAT_ENERGY", &
     602            0 :                                             r_val=myt)
     603              :                   CALL section_vals_val_get(restart_file, "MOTION%MD%ELECTRONS%CURRENT_FERMI_LEVEL", &
     604            0 :                                             r_val=myt)
     605              :                   CALL section_vals_val_set(input_file, "MOTION%MD%ELECTRONS%CURRENT_FERMI_LEVEL", &
     606            0 :                                             r_val=myt)
     607              :                   CALL section_vals_val_get(restart_file, "MOTION%MD%ELECTRONS%CURRENT_WORKFUNCTION", &
     608            0 :                                             r_val=myt)
     609              :                   CALL section_vals_val_set(input_file, "MOTION%MD%ELECTRONS%CURRENT_WORKFUNCTION", &
     610            0 :                                             r_val=myt)
     611            0 :                   CALL set_restart_info("ELECTRONIC POTENTIOSTAT STATE", restarted_infos)
     612              :                END IF
     613              :                !
     614          210 :                IF (check_restart(input_file, restart_file, "MOTION%GEO_OPT")) THEN
     615              :                   ! GEO_OPT
     616           18 :                   CALL section_vals_val_get(restart_file, "MOTION%GEO_OPT%STEP_START_VAL", i_val=myi)
     617           18 :                   CALL section_vals_val_set(input_file, "MOTION%GEO_OPT%STEP_START_VAL", i_val=myi)
     618           18 :                   CALL set_restart_info("GEO_OPT COUNTERS", restarted_infos)
     619              :                   ! ROT_OPT
     620           18 :                   IF (check_restart(input_file, restart_file, "MOTION%GEO_OPT%TRANSITION_STATE%DIMER%ROT_OPT")) THEN
     621              :                      CALL section_vals_val_get(restart_file, "MOTION%GEO_OPT%TRANSITION_STATE%DIMER%ROT_OPT%STEP_START_VAL", &
     622            2 :                                                i_val=myi)
     623              :                      CALL section_vals_val_set(input_file, "MOTION%GEO_OPT%TRANSITION_STATE%DIMER%ROT_OPT%STEP_START_VAL", &
     624            2 :                                                i_val=myi)
     625            2 :                      CALL set_restart_info("ROT_OPT COUNTERS", restarted_infos)
     626              :                   END IF
     627              :                END IF
     628              :                !
     629          210 :                IF (check_restart(input_file, restart_file, "MOTION%GEO_OPT")) THEN
     630              :                   ! CELL_OPT
     631           18 :                   CALL section_vals_val_get(restart_file, "MOTION%CELL_OPT%STEP_START_VAL", i_val=myi)
     632           18 :                   CALL section_vals_val_set(input_file, "MOTION%CELL_OPT%STEP_START_VAL", i_val=myi)
     633           18 :                   CALL set_restart_info("CELL_OPT COUNTERS", restarted_infos)
     634              :                END IF
     635              :                !
     636          210 :                IF (check_restart(input_file, restart_file, "OPTIMIZE_INPUT")) THEN
     637            2 :                   CALL section_vals_val_get(restart_file, "OPTIMIZE_INPUT%ITER_START_VAL", i_val=myi)
     638            2 :                   CALL section_vals_val_set(input_file, "OPTIMIZE_INPUT%ITER_START_VAL", i_val=myi)
     639            2 :                   CALL set_restart_info("OPTIMIZE_INPUT ITERATION NUMBER", restarted_infos)
     640              :                END IF
     641              :                !
     642          210 :                IF (check_restart(input_file, restart_file, "MOTION%PINT")) THEN
     643              :                   ! PINT
     644           10 :                   CALL section_vals_val_get(restart_file, "MOTION%PINT%ITERATION", i_val=myi)
     645           10 :                   CALL section_vals_val_set(input_file, "MOTION%PINT%ITERATION", i_val=myi)
     646           10 :                   CALL set_restart_info("PINT ITERATION NUMBER", restarted_infos)
     647              :                END IF
     648              :                !
     649          210 :                CALL section_vals_val_get(r_section, "RESTART_METADYNAMICS", l_val=flag2)
     650          210 :                IF (flag2 .AND. check_restart(input_file, restart_file, "MOTION%FREE_ENERGY%METADYN")) THEN
     651              :                   CALL section_vals_val_get(restart_file, &
     652           12 :                                             "MOTION%FREE_ENERGY%METADYN%STEP_START_VAL", i_val=myi)
     653              :                   CALL section_vals_val_set(input_file, &
     654           12 :                                             "MOTION%FREE_ENERGY%METADYN%STEP_START_VAL", i_val=myi)
     655              :                   CALL section_vals_val_get(restart_file, &
     656           12 :                                             "MOTION%FREE_ENERGY%METADYN%NHILLS_START_VAL", i_val=myi)
     657              :                   CALL section_vals_val_set(input_file, &
     658           12 :                                             "MOTION%FREE_ENERGY%METADYN%NHILLS_START_VAL", i_val=myi)
     659              :                   !RG Adaptive hills
     660              :                   CALL section_vals_val_get(restart_file, &
     661           12 :                                             "MOTION%FREE_ENERGY%METADYN%OLD_HILL_NUMBER", i_val=myi)
     662              :                   CALL section_vals_val_set(input_file, &
     663           12 :                                             "MOTION%FREE_ENERGY%METADYN%OLD_HILL_NUMBER", i_val=myi)
     664              :                   CALL section_vals_val_get(restart_file, &
     665           12 :                                             "MOTION%FREE_ENERGY%METADYN%OLD_HILL_STEP", i_val=myi)
     666              :                   CALL section_vals_val_set(input_file, &
     667           12 :                                             "MOTION%FREE_ENERGY%METADYN%OLD_HILL_STEP", i_val=myi)
     668              :                   !RG Adaptive hills
     669           12 :                   CALL set_restart_info("METADYNAMIC COUNTERS", restarted_infos)
     670              :                END IF
     671              :             END IF
     672              : 
     673          226 :             CALL section_vals_val_get(r_section, "RESTART_AVERAGES", l_val=flag)
     674          226 :             IF (flag) THEN
     675          214 :                IF (check_restart(input_file, restart_file, "MOTION%MD")) THEN
     676          174 :                   rep_sections => section_vals_get_subs_vals(restart_file, "MOTION%MD%AVERAGES%RESTART_AVERAGES")
     677          174 :                   CALL section_vals_set_subs_vals(input_file, "MOTION%MD%AVERAGES%RESTART_AVERAGES", rep_sections)
     678          174 :                   CALL set_restart_info("MD AVERAGES", restarted_infos)
     679              :                END IF
     680              :             END IF
     681              : 
     682          226 :             CALL section_vals_val_get(r_section, "RESTART_BAND", l_val=flag)
     683          226 :             IF (flag .AND. check_restart(input_file, restart_file, "MOTION%BAND")) THEN
     684            6 :                rep_sections => section_vals_get_subs_vals(restart_file, "MOTION%BAND%REPLICA")
     685            6 :                CALL section_vals_set_subs_vals(input_file, "MOTION%BAND%REPLICA", rep_sections)
     686            6 :                CALL set_restart_info("BAND CALCULATION", restarted_infos)
     687              :             END IF
     688              : 
     689          226 :             CALL section_vals_val_get(r_section, "RESTART_OPTIMIZE_INPUT_VARIABLES", l_val=flag)
     690          226 :             IF (flag .AND. check_restart(input_file, restart_file, "OPTIMIZE_INPUT%VARIABLE")) THEN
     691            2 :                rep_sections => section_vals_get_subs_vals(restart_file, "OPTIMIZE_INPUT%VARIABLE")
     692            2 :                CALL section_vals_set_subs_vals(input_file, "OPTIMIZE_INPUT%VARIABLE", rep_sections)
     693            2 :                CALL set_restart_info("OPTIMIZE_INPUT: VARIABLES", restarted_infos)
     694              :             END IF
     695              : 
     696          226 :             CALL section_vals_val_get(r_section, "RESTART_BAROSTAT", l_val=flag)
     697          226 :             IF (flag .AND. check_restart(input_file, restart_file, "MOTION%MD%BAROSTAT")) THEN
     698              :                section => section_vals_get_subs_vals(restart_file, &
     699           22 :                                                      "MOTION%MD%BAROSTAT%MASS")
     700              :                CALL section_vals_set_subs_vals(input_file, "MOTION%MD%BAROSTAT%MASS", &
     701           22 :                                                section)
     702              :                section => section_vals_get_subs_vals(restart_file, &
     703           22 :                                                      "MOTION%MD%BAROSTAT%VELOCITY")
     704              :                CALL section_vals_set_subs_vals(input_file, "MOTION%MD%BAROSTAT%VELOCITY", &
     705           22 :                                                section)
     706           22 :                CALL set_restart_info("BAROSTAT", restarted_infos)
     707              :             END IF
     708              : 
     709          226 :             flag = check_restart(input_file, restart_file, "MOTION%MD")
     710          226 :             IF (flag) THEN
     711          176 :                CALL section_vals_val_get(input_file, "MOTION%MD%ENSEMBLE", i_val=ensemble)
     712          176 :                IF (ensemble == npt_i_ensemble .OR. ensemble == npt_f_ensemble .OR. ensemble == npt_ia_ensemble) THEN
     713           32 :                   CALL section_vals_val_get(r_section, "RESTART_BAROSTAT_THERMOSTAT", l_val=flag)
     714           32 :                   check = check_restart(input_file, restart_file, "MOTION%MD%BAROSTAT")
     715              :                   CALL restart_thermostat(flag, input_file, restart_file, "MOTION%MD%BAROSTAT%THERMOSTAT", &
     716           32 :                                           check=check)
     717           32 :                   IF (flag .AND. check) CALL set_restart_info("THERMOSTAT OF BAROSTAT", restarted_infos)
     718              :                END IF
     719              :             END IF
     720              : 
     721          226 :             check = check_restart(input_file, restart_file, "MOTION%MD%SHELL")
     722          226 :             IF (check) THEN
     723           18 :                CALL section_vals_val_get(r_section, "RESTART_SHELL_THERMOSTAT", l_val=flag)
     724           18 :                CALL restart_thermostat(flag, input_file, restart_file, "MOTION%MD%SHELL%THERMOSTAT")
     725           18 :                CALL set_restart_info("SHELL THERMOSTAT", restarted_infos)
     726              :             END IF
     727              : 
     728          226 :             CALL section_vals_val_get(r_section, "RESTART_THERMOSTAT", l_val=flag)
     729          226 :             CALL restart_thermostat(flag, input_file, restart_file, "MOTION%MD%THERMOSTAT")
     730          226 :             IF (flag) CALL set_restart_info("PARTICLE THERMOSTAT", restarted_infos)
     731              : 
     732          226 :             CALL section_vals_val_get(r_section, "RESTART_CONSTRAINT", l_val=flag)
     733          226 :             IF (flag .AND. check_restart(input_file, restart_file, "MOTION%CONSTRAINT")) THEN
     734           38 :                section => section_vals_get_subs_vals(restart_file, "MOTION%CONSTRAINT")
     735           38 :                CALL section_vals_set_subs_vals(input_file, "MOTION%CONSTRAINT", section)
     736           38 :                CALL set_restart_info("CONSTRAINTS/RESTRAINTS", restarted_infos)
     737              :             END IF
     738              : 
     739          226 :             CALL section_vals_val_get(r_section, "RESTART_METADYNAMICS", l_val=flag)
     740          226 :             IF (flag .AND. check_restart(input_file, restart_file, "MOTION%FREE_ENERGY%METADYN")) THEN
     741              :                section => section_vals_get_subs_vals(restart_file, &
     742           12 :                                                      "MOTION%FREE_ENERGY%METADYN%SPAWNED_HILLS_POS")
     743              :                CALL section_vals_set_subs_vals(input_file, "MOTION%FREE_ENERGY%METADYN%SPAWNED_HILLS_POS", &
     744           12 :                                                section)
     745              :                section => section_vals_get_subs_vals(restart_file, &
     746           12 :                                                      "MOTION%FREE_ENERGY%METADYN%SPAWNED_HILLS_SCALE")
     747              :                CALL section_vals_set_subs_vals(input_file, "MOTION%FREE_ENERGY%METADYN%SPAWNED_HILLS_SCALE", &
     748           12 :                                                section)
     749              :                section => section_vals_get_subs_vals(restart_file, &
     750           12 :                                                      "MOTION%FREE_ENERGY%METADYN%SPAWNED_HILLS_HEIGHT")
     751              :                CALL section_vals_set_subs_vals(input_file, "MOTION%FREE_ENERGY%METADYN%SPAWNED_HILLS_HEIGHT", &
     752           12 :                                                section)
     753              :                section => section_vals_get_subs_vals(restart_file, &
     754           12 :                                                      "MOTION%FREE_ENERGY%METADYN%SPAWNED_HILLS_INVDT")
     755              :                CALL section_vals_set_subs_vals(input_file, "MOTION%FREE_ENERGY%METADYN%SPAWNED_HILLS_INVDT", &
     756           12 :                                                section)
     757              :                ! Extended Lagrangian
     758              :                section => section_vals_get_subs_vals(restart_file, &
     759           12 :                                                      "MOTION%FREE_ENERGY%METADYN%EXT_LAGRANGE_SS0")
     760              :                CALL section_vals_set_subs_vals(input_file, "MOTION%FREE_ENERGY%METADYN%EXT_LAGRANGE_SS0", &
     761           12 :                                                section)
     762              :                section => section_vals_get_subs_vals(restart_file, &
     763           12 :                                                      "MOTION%FREE_ENERGY%METADYN%EXT_LAGRANGE_VVP")
     764              :                CALL section_vals_set_subs_vals(input_file, "MOTION%FREE_ENERGY%METADYN%EXT_LAGRANGE_VVP", &
     765           12 :                                                section)
     766              :                section => section_vals_get_subs_vals(restart_file, &
     767           12 :                                                      "MOTION%FREE_ENERGY%METADYN%EXT_LAGRANGE_SS")
     768              :                CALL section_vals_set_subs_vals(input_file, "MOTION%FREE_ENERGY%METADYN%EXT_LAGRANGE_SS", &
     769           12 :                                                section)
     770              :                section => section_vals_get_subs_vals(restart_file, &
     771           12 :                                                      "MOTION%FREE_ENERGY%METADYN%EXT_LAGRANGE_FS")
     772              :                CALL section_vals_set_subs_vals(input_file, "MOTION%FREE_ENERGY%METADYN%EXT_LAGRANGE_FS", &
     773           12 :                                                section)
     774           12 :                CALL set_restart_info("METADYNAMICS", restarted_infos)
     775              :             END IF
     776              : 
     777          226 :             CALL section_vals_val_get(r_section, "RESTART_TEMPERATURE_ANNEALING", l_val=flag)
     778          226 :             IF (flag .AND. check_restart(input_file, restart_file, "MOTION%MD")) THEN
     779            2 :                CALL section_vals_val_get(input_file, "MOTION%MD%TEMPERATURE_ANNEALING", r_val=myt, explicit=explicit1)
     780            2 :                IF ((.NOT. explicit1) .OR. (ABS(1._dp - myt) <= 1.E-10_dp)) THEN
     781              :                   CALL cp_warn(__LOCATION__, &
     782              :                                "I'm about to override the input temperature "// &
     783              :                                "with the temperature found in external restart "// &
     784            0 :                                "but TEMPERATURE_ANNEALING isn't explicitly given or it is set to 1.")
     785              :                END IF
     786            2 :                CALL section_vals_val_get(restart_file, "MOTION%MD%TEMPERATURE", r_val=myt, explicit=explicit1)
     787            2 :                IF (explicit1) THEN
     788            2 :                   CALL section_vals_val_get(input_file, "MOTION%MD%TEMPERATURE", r_val=myt)
     789              :                ELSE
     790              :                   CALL cp_warn(__LOCATION__, &
     791              :                                "I'm not going to override the input temperature "// &
     792            0 :                                "since the temperature isn't explicitly given in the external restart.")
     793              :                END IF
     794              :             END IF
     795              : 
     796          226 :             CALL section_vals_val_get(r_section, "RESTART_WALKERS", l_val=flag)
     797          226 :             IF (flag .AND. check_restart(input_file, restart_file, "MOTION%FREE_ENERGY%METADYN%MULTIPLE_WALKERS")) THEN
     798              :                CALL section_vals_val_get(restart_file, "MOTION%FREE_ENERGY%METADYN%MULTIPLE_WALKERS%WALKERS_STATUS", &
     799            4 :                                          i_vals=rwalkers_status)
     800           12 :                ALLOCATE (iwalkers_status(SIZE(rwalkers_status)))
     801           20 :                iwalkers_status = rwalkers_status
     802              :                CALL section_vals_val_set(input_file, "MOTION%FREE_ENERGY%METADYN%MULTIPLE_WALKERS%WALKERS_STATUS", &
     803            4 :                                          i_vals_ptr=iwalkers_status)
     804            4 :                CALL set_restart_info("WALKERS INFO", restarted_infos)
     805              :             END IF
     806              : 
     807          226 :             CALL section_vals_val_get(r_section, "RESTART_DIMER", l_val=flag)
     808          226 :             IF (flag .AND. check_restart(input_file, restart_file, "MOTION%GEO_OPT%TRANSITION_STATE%DIMER")) THEN
     809              :                section => section_vals_get_subs_vals(restart_file, &
     810            2 :                                                      "MOTION%GEO_OPT%TRANSITION_STATE%DIMER%DIMER_VECTOR")
     811              :                CALL section_vals_set_subs_vals(input_file, "MOTION%GEO_OPT%TRANSITION_STATE%DIMER%DIMER_VECTOR", &
     812            2 :                                                section)
     813            2 :                CALL set_restart_info("DIMER TRANSITION STATE SEARCH", restarted_infos)
     814              :             END IF
     815              : 
     816          226 :             CALL section_vals_val_get(r_section, "CUSTOM_PATH", n_rep_val=n_rep_val)
     817          226 :             DO i_rep_val = 1, n_rep_val
     818            0 :                CALL section_vals_val_get(r_section, "CUSTOM_PATH", i_rep_val=i_rep_val, c_val=path)
     819          226 :                IF (path /= " ") THEN
     820            0 :                   section => section_vals_get_subs_vals(restart_file, path)
     821            0 :                   CALL section_vals_set_subs_vals(input_file, path, section)
     822            0 :                   CALL set_restart_info("USER RESTART: "//TRIM(path), restarted_infos)
     823              :                END IF
     824              :             END DO
     825              : 
     826          226 :             CALL section_vals_val_get(r_section, "RESTART_RTP", l_val=flag)
     827              :             !          IF(flag.AND.check_restart(input_file, restart_file, "FORCE_EVAL%DFT%REAL_TIME_PROPAGATION")) THEN
     828          226 :             IF (flag) THEN
     829              :                section => section_vals_get_subs_vals(restart_file, &
     830          214 :                                                      "FORCE_EVAL%DFT%REAL_TIME_PROPAGATION")
     831          214 :                CALL section_vals_val_get(section, "INITIAL_WFN", i_val=myi)
     832              :                CALL section_vals_val_set(input_file, "FORCE_EVAL%DFT%REAL_TIME_PROPAGATION%INITIAL_WFN", &
     833          214 :                                          i_val=myi)
     834          214 :                CALL set_restart_info("REAL TIME PROPAGATION", restarted_infos)
     835              :             END IF
     836              : 
     837              :             ! PIMD
     838          226 :             CALL section_vals_val_get(r_section, "RESTART_PINT_POS", l_val=flag)
     839          226 :             IF (flag) THEN
     840          220 :                section => section_vals_get_subs_vals(restart_file, "MOTION%PINT%BEADS%COORD")
     841          220 :                CALL section_vals_set_subs_vals(input_file, "MOTION%PINT%BEADS%COORD", section)
     842          220 :                CALL set_restart_info("PINT BEAD POSITIONS", restarted_infos)
     843              :             END IF
     844          226 :             CALL section_vals_val_get(r_section, "RESTART_PINT_VEL", l_val=flag)
     845          226 :             IF (flag) THEN
     846          220 :                section => section_vals_get_subs_vals(restart_file, "MOTION%PINT%BEADS%VELOCITY")
     847          220 :                CALL section_vals_set_subs_vals(input_file, "MOTION%PINT%BEADS%VELOCITY", section)
     848          220 :                CALL set_restart_info("PINT BEAD VELOCITIES", restarted_infos)
     849              :             END IF
     850          226 :             CALL section_vals_val_get(r_section, "RESTART_PINT_NOSE", l_val=flag)
     851          226 :             IF (flag) THEN
     852          220 :                section => section_vals_get_subs_vals(restart_file, "MOTION%PINT%NOSE%COORD")
     853          220 :                CALL section_vals_set_subs_vals(input_file, "MOTION%PINT%NOSE%COORD", section)
     854          220 :                section => section_vals_get_subs_vals(restart_file, "MOTION%PINT%NOSE%VELOCITY")
     855          220 :                CALL section_vals_set_subs_vals(input_file, "MOTION%PINT%NOSE%VELOCITY", section)
     856          220 :                CALL set_restart_info("PINT NOSE THERMOSTAT", restarted_infos)
     857              :             END IF
     858          226 :             CALL section_vals_val_get(r_section, "RESTART_PINT_GLE", l_val=flag)
     859          226 :             IF (flag) THEN
     860          214 :                section => section_vals_get_subs_vals(restart_file, "MOTION%PINT%GLE")
     861          214 :                CALL section_vals_set_subs_vals(input_file, "MOTION%PINT%GLE", section)
     862          214 :                CALL set_restart_info("PINT GLE THERMOSTAT", restarted_infos)
     863              :             END IF
     864              : 
     865              :             ! PIMC
     866              :             !
     867          226 :             CALL section_vals_val_get(r_section, "RESTART_HELIUM_POS", l_val=flag)
     868          226 :             IF (flag) THEN
     869              :                CALL section_vals_val_get(input_file, "MOTION%PINT%HELIUM%NUM_ENV", &
     870          220 :                                          explicit=explicit1)
     871          220 :                IF (.NOT. explicit1) THEN
     872          214 :                   CALL section_vals_val_get(restart_file, "MOTION%PINT%HELIUM%NUM_ENV", i_val=myi)
     873          214 :                   CALL section_vals_val_set(input_file, "MOTION%PINT%HELIUM%NUM_ENV", i_val=myi)
     874              :                END IF
     875          220 :                section => section_vals_get_subs_vals(restart_file, "MOTION%PINT%HELIUM%COORD")
     876          220 :                CALL section_vals_set_subs_vals(input_file, "MOTION%PINT%HELIUM%COORD", section)
     877          220 :                CALL set_restart_info("HELIUM BEAD POSITIONS", restarted_infos)
     878              :             END IF
     879              :             !
     880          226 :             CALL section_vals_val_get(r_section, "RESTART_HELIUM_PERMUTATION", l_val=flag)
     881          226 :             IF (flag) THEN
     882              :                CALL section_vals_val_get(input_file, "MOTION%PINT%HELIUM%NUM_ENV", &
     883          220 :                                          explicit=explicit1)
     884          220 :                IF (.NOT. explicit1) THEN
     885            0 :                   CALL section_vals_val_get(restart_file, "MOTION%PINT%HELIUM%NUM_ENV", i_val=myi)
     886            0 :                   CALL section_vals_val_set(input_file, "MOTION%PINT%HELIUM%NUM_ENV", i_val=myi)
     887              :                END IF
     888          220 :                section => section_vals_get_subs_vals(restart_file, "MOTION%PINT%HELIUM%PERM")
     889          220 :                CALL section_vals_set_subs_vals(input_file, "MOTION%PINT%HELIUM%PERM", section)
     890          220 :                CALL set_restart_info("HELIUM PERMUTATION STATE", restarted_infos)
     891              :             END IF
     892              :             !
     893          226 :             CALL section_vals_val_get(r_section, "RESTART_HELIUM_FORCE", l_val=flag)
     894          226 :             IF (flag) THEN
     895              :                CALL section_vals_val_get(input_file, "MOTION%PINT%HELIUM%NUM_ENV", &
     896          216 :                                          explicit=explicit1)
     897          216 :                IF (.NOT. explicit1) THEN
     898            0 :                   CALL section_vals_val_get(restart_file, "MOTION%PINT%HELIUM%NUM_ENV", i_val=myi)
     899            0 :                   CALL section_vals_val_set(input_file, "MOTION%PINT%HELIUM%NUM_ENV", i_val=myi)
     900              :                END IF
     901          216 :                section => section_vals_get_subs_vals(restart_file, "MOTION%PINT%HELIUM%FORCE")
     902          216 :                CALL section_vals_set_subs_vals(input_file, "MOTION%PINT%HELIUM%FORCE", section)
     903          216 :                CALL set_restart_info("HELIUM FORCES ON SOLUTE", restarted_infos)
     904              :             END IF
     905              :             !
     906          226 :             CALL section_vals_val_get(r_section, "RESTART_HELIUM_RNG", l_val=flag)
     907          226 :             IF (flag) THEN
     908              :                CALL section_vals_val_get(input_file, "MOTION%PINT%HELIUM%NUM_ENV", &
     909          220 :                                          explicit=explicit1)
     910          220 :                IF (.NOT. explicit1) THEN
     911            0 :                   CALL section_vals_val_get(restart_file, "MOTION%PINT%HELIUM%NUM_ENV", i_val=myi)
     912            0 :                   CALL section_vals_val_set(input_file, "MOTION%PINT%HELIUM%NUM_ENV", i_val=myi)
     913              :                END IF
     914          220 :                section => section_vals_get_subs_vals(restart_file, "MOTION%PINT%HELIUM%RNG_STATE")
     915          220 :                CALL section_vals_set_subs_vals(input_file, "MOTION%PINT%HELIUM%RNG_STATE", section)
     916          220 :                CALL set_restart_info("HELIUM RNG STATE", restarted_infos)
     917              :             END IF
     918              :             !
     919              :             !
     920          226 :             CALL section_vals_val_get(r_section, "RESTART_HELIUM_DENSITIES", l_val=flag)
     921          226 :             IF (flag) THEN
     922              :                CALL section_vals_val_get(input_file, "MOTION%PINT%HELIUM%NUM_ENV", &
     923            0 :                                          explicit=explicit1)
     924            0 :                IF (.NOT. explicit1) THEN
     925            0 :                   CALL section_vals_val_get(restart_file, "MOTION%PINT%HELIUM%NUM_ENV", i_val=myi)
     926            0 :                   CALL section_vals_val_set(input_file, "MOTION%PINT%HELIUM%NUM_ENV", i_val=myi)
     927              :                END IF
     928            0 :                section => section_vals_get_subs_vals(restart_file, "MOTION%PINT%HELIUM%RHO")
     929            0 :                CALL section_vals_set_subs_vals(input_file, "MOTION%PINT%HELIUM%RHO", section)
     930            0 :                CALL set_restart_info("HELIUM DENSITIES", restarted_infos)
     931              :             END IF
     932              :             !
     933          226 :             CALL section_vals_val_set(r_section, "RESTART_FILE_NAME", c_val=" ")
     934          226 :             CALL section_vals_release(restart_file)
     935              :             CALL release_restart_info(restarted_infos, r_file_path, binary_restart_file, &
     936         6102 :                                       output_unit)
     937              :          END BLOCK
     938              :       END IF
     939        22809 :       CALL timestop(handle)
     940        22809 :    END SUBROUTINE handle_ext_restart
     941              : 
     942              : ! **************************************************************************************************
     943              : !> \brief store information on the restarted quantities
     944              : !> \param label ...
     945              : !> \param restarted_infos ...
     946              : !> \author Teodoro Laino [tlaino] 09.2008 - University of Zurich
     947              : ! **************************************************************************************************
     948         3690 :    SUBROUTINE set_restart_info(label, restarted_infos)
     949              : 
     950              :       CHARACTER(LEN=*), INTENT(IN)                       :: label
     951              :       CHARACTER(LEN=default_string_length), &
     952              :          DIMENSION(:), POINTER                           :: restarted_infos
     953              : 
     954              :       INTEGER                                            :: isize
     955              : 
     956         3690 :       isize = 0
     957         3466 :       IF (ASSOCIATED(restarted_infos)) isize = SIZE(restarted_infos)
     958         3690 :       isize = isize + 1
     959         3690 :       CALL reallocate(restarted_infos, 1, isize)
     960         3690 :       restarted_infos(isize) = TRIM(label)
     961              : 
     962         3690 :    END SUBROUTINE set_restart_info
     963              : 
     964              : ! **************************************************************************************************
     965              : !> \brief dumps on output the information on the information effectively restarted
     966              : !> \param restarted_infos ...
     967              : !> \param r_file_path ...
     968              : !> \param binary_restart_file ...
     969              : !> \param output_unit ...
     970              : !> \author Teodoro Laino [tlaino] 09.2008 - University of Zurich
     971              : ! **************************************************************************************************
     972          226 :    SUBROUTINE release_restart_info(restarted_infos, r_file_path, &
     973              :                                    binary_restart_file, output_unit)
     974              :       CHARACTER(LEN=default_string_length), &
     975              :          DIMENSION(:), POINTER                           :: restarted_infos
     976              :       CHARACTER(LEN=*), INTENT(IN)                       :: r_file_path, binary_restart_file
     977              :       INTEGER, INTENT(IN)                                :: output_unit
     978              : 
     979              :       INTEGER                                            :: i, j
     980              : 
     981          226 :       IF (output_unit > 0 .AND. ASSOCIATED(restarted_infos)) THEN
     982          112 :          WRITE (output_unit, '(1X,79("*"))')
     983          112 :          WRITE (output_unit, '(1X,"*",T30,A,T80,"*")') " RESTART INFORMATION "
     984          112 :          WRITE (output_unit, '(1X,79("*"))')
     985          112 :          WRITE (output_unit, '(1X,"*",T80,"*")')
     986          112 :          i = 1
     987          112 :          WRITE (output_unit, '(1X,"*",A,T26,A,T80,"*")') "    RESTART FILE NAME:  ", &
     988          224 :             r_file_path(53*(i - 1) + 1:53*i)
     989          112 :          DO i = 2, CEILING(REAL(LEN_TRIM(r_file_path), KIND=dp)/53.0_dp)
     990          112 :             WRITE (output_unit, '(T1,1X,"*",T26,A,T80,"*")') r_file_path(53*(i - 1) + 1:53*i)
     991              :          END DO
     992          112 :          IF (LEN_TRIM(binary_restart_file) > 0) THEN
     993           23 :             i = 1
     994           23 :             WRITE (output_unit, '(1X,"*",A,T26,A,T80,"*")') "  BINARY RESTART FILE:  ", &
     995           46 :                binary_restart_file(53*(i - 1) + 1:53*i)
     996           23 :             DO i = 2, CEILING(REAL(LEN_TRIM(binary_restart_file), KIND=dp)/53.0_dp)
     997           23 :                WRITE (output_unit, '(T1,1X,"*",T26,A,T80,"*")') binary_restart_file(53*(i - 1) + 1:53*i)
     998              :             END DO
     999              :          END IF
    1000          112 :          WRITE (output_unit, '(1X,"*",T80,"*")')
    1001          112 :          WRITE (output_unit, '(1X,"*", A,T80,"*")') " RESTARTED QUANTITIES:  "
    1002         1957 :          DO j = 1, SIZE(restarted_infos)
    1003         3802 :             DO i = 1, CEILING(REAL(LEN_TRIM(restarted_infos(j)), KIND=dp)/53.0_dp)
    1004         3690 :                WRITE (output_unit, '(T1,1X,"*",T26,A,T80,"*")') restarted_infos(j) (53*(i - 1) + 1:53*i)
    1005              :             END DO
    1006              :          END DO
    1007          112 :          WRITE (output_unit, '(1X,79("*"),/)')
    1008              :       END IF
    1009          226 :       IF (ASSOCIATED(restarted_infos)) THEN
    1010          224 :          DEALLOCATE (restarted_infos)
    1011              :       END IF
    1012          226 :    END SUBROUTINE release_restart_info
    1013              : 
    1014              : ! **************************************************************************************************
    1015              : !> \brief Possibly restart thermostats information
    1016              : !> \param flag ...
    1017              : !> \param input_file the input file to initialize
    1018              : !> \param restart_file ...
    1019              : !> \param path ...
    1020              : !> \param check ...
    1021              : !> \author Teodoro Laino [tlaino] 10.2007- University of Zurich
    1022              : ! **************************************************************************************************
    1023          276 :    SUBROUTINE restart_thermostat(flag, input_file, restart_file, path, check)
    1024              :       LOGICAL, INTENT(IN)                                :: flag
    1025              :       TYPE(section_vals_type), POINTER                   :: input_file, restart_file
    1026              :       CHARACTER(LEN=*), INTENT(IN)                       :: path
    1027              :       LOGICAL, INTENT(IN), OPTIONAL                      :: check
    1028              : 
    1029              :       INTEGER                                            :: input_region, input_type, &
    1030              :                                                             restart_region, restart_type
    1031              :       LOGICAL                                            :: check_loc, skip_other_checks
    1032              :       TYPE(section_vals_type), POINTER                   :: section
    1033              : 
    1034          276 :       check_loc = check_restart(input_file, restart_file, TRIM(path))
    1035          276 :       skip_other_checks = PRESENT(check)
    1036          276 :       IF (skip_other_checks) check_loc = check
    1037          276 :       IF (flag .AND. check_loc) THEN
    1038              :          ! Let's check if the thermostat type is different otherwise it does not make any
    1039              :          ! sense to do any kind of restart
    1040          134 :          CALL section_vals_val_get(input_file, TRIM(path)//"%TYPE", i_val=input_type)
    1041          134 :          CALL section_vals_val_get(restart_file, TRIM(path)//"%TYPE", i_val=restart_type)
    1042              : 
    1043          134 :          IF (input_type == do_thermo_same_as_part) THEN
    1044           18 :             CALL section_vals_val_get(input_file, "MOTION%MD%THERMOSTAT%TYPE", i_val=input_type)
    1045              :          END IF
    1046              : 
    1047          134 :          IF (skip_other_checks) THEN
    1048           20 :             input_region = do_region_global
    1049           20 :             restart_region = do_region_global
    1050              :          ELSE
    1051              :             ! Also the regions must be the same..
    1052          114 :             CALL section_vals_val_get(input_file, TRIM(path)//"%REGION", i_val=input_region)
    1053          114 :             CALL section_vals_val_get(restart_file, TRIM(path)//"%REGION", i_val=restart_region)
    1054              :          END IF
    1055              : 
    1056          134 :          IF ((input_type == restart_type) .AND. (input_region == restart_region)) THEN
    1057          110 :             SELECT CASE (input_type)
    1058              :             CASE (do_thermo_nose)
    1059          110 :                section => section_vals_get_subs_vals(restart_file, TRIM(path)//"%NOSE%COORD")
    1060          110 :                CALL section_vals_set_subs_vals(input_file, TRIM(path)//"%NOSE%COORD", section)
    1061              : 
    1062          110 :                section => section_vals_get_subs_vals(restart_file, TRIM(path)//"%NOSE%VELOCITY")
    1063          110 :                CALL section_vals_set_subs_vals(input_file, TRIM(path)//"%NOSE%VELOCITY", section)
    1064              : 
    1065          110 :                section => section_vals_get_subs_vals(restart_file, TRIM(path)//"%NOSE%MASS")
    1066          110 :                CALL section_vals_set_subs_vals(input_file, TRIM(path)//"%NOSE%MASS", section)
    1067              : 
    1068          110 :                section => section_vals_get_subs_vals(restart_file, TRIM(path)//"%NOSE%FORCE")
    1069          110 :                CALL section_vals_set_subs_vals(input_file, TRIM(path)//"%NOSE%FORCE", section)
    1070              :             CASE (do_thermo_csvr)
    1071           22 :                section => section_vals_get_subs_vals(restart_file, TRIM(path)//"%CSVR%THERMOSTAT_ENERGY")
    1072           22 :                CALL section_vals_set_subs_vals(input_file, TRIM(path)//"%CSVR%THERMOSTAT_ENERGY", section)
    1073           22 :                section => section_vals_get_subs_vals(restart_file, TRIM(path)//"%CSVR%RNG_INIT")
    1074           22 :                CALL section_vals_set_subs_vals(input_file, TRIM(path)//"%CSVR%RNG_INIT", section)
    1075              :             CASE (do_thermo_gle)
    1076            2 :                section => section_vals_get_subs_vals(restart_file, TRIM(path)//"%GLE%THERMOSTAT_ENERGY")
    1077            2 :                CALL section_vals_set_subs_vals(input_file, TRIM(path)//"%GLE%THERMOSTAT_ENERGY", section)
    1078            2 :                section => section_vals_get_subs_vals(restart_file, TRIM(path)//"%GLE%RNG_INIT")
    1079            2 :                CALL section_vals_set_subs_vals(input_file, TRIM(path)//"%GLE%RNG_INIT", section)
    1080            2 :                section => section_vals_get_subs_vals(restart_file, TRIM(path)//"%GLE%S")
    1081            2 :                CALL section_vals_set_subs_vals(input_file, TRIM(path)//"%GLE%S", section)
    1082              :             CASE (do_thermo_al)
    1083            0 :                section => section_vals_get_subs_vals(restart_file, TRIM(path)//"%AD_LANGEVIN%CHI")
    1084            0 :                CALL section_vals_set_subs_vals(input_file, TRIM(path)//"%AD_LANGEVIN%CHI", section)
    1085            0 :                section => section_vals_get_subs_vals(restart_file, TRIM(path)//"%AD_LANGEVIN%MASS")
    1086          134 :                CALL section_vals_set_subs_vals(input_file, TRIM(path)//"%AD_LANGEVIN%MASS", section)
    1087              :             END SELECT
    1088              :          ELSE
    1089            0 :             IF (input_type /= restart_type) THEN
    1090              :                CALL cp_warn(__LOCATION__, &
    1091              :                             "Requested to restart thermostat: "//TRIM(path)//". The thermostat "// &
    1092              :                             "specified in the input file and the information present in the restart "// &
    1093              :                             "file do not match the same type of thermostat! Restarting is not possible! "// &
    1094            0 :                             "Thermostat will not be restarted! ")
    1095              :             END IF
    1096            0 :             IF (input_region /= restart_region) THEN
    1097              :                CALL cp_warn(__LOCATION__, &
    1098              :                             "Requested to restart thermostat: "//TRIM(path)//". The thermostat "// &
    1099              :                             "specified in the input file and the information present in the restart "// &
    1100              :                             "file do not match the same type of REGION! Restarting is not possible! "// &
    1101            0 :                             "Thermostat will not be restarted! ")
    1102              :             END IF
    1103              :          END IF
    1104              :       END IF
    1105          276 :    END SUBROUTINE restart_thermostat
    1106              : 
    1107              : ! **************************************************************************************************
    1108              : !> \brief Checks if there are the proper conditions to do a restart
    1109              : !> \param input_file the input file to initialize
    1110              : !> \param restart_file ...
    1111              : !> \param tag_section ...
    1112              : !> \return ...
    1113              : !> \author teo
    1114              : ! **************************************************************************************************
    1115        14556 :    FUNCTION check_restart(input_file, restart_file, tag_section) RESULT(do_restart)
    1116              :       TYPE(section_vals_type), POINTER                   :: input_file, restart_file
    1117              :       CHARACTER(LEN=*), INTENT(IN)                       :: tag_section
    1118              :       LOGICAL                                            :: do_restart
    1119              : 
    1120              :       CHARACTER(len=*), PARAMETER                        :: routineN = 'check_restart'
    1121              : 
    1122              :       INTEGER                                            :: handle
    1123              :       LOGICAL                                            :: explicit1, explicit2
    1124              :       TYPE(section_vals_type), POINTER                   :: work_section
    1125              : 
    1126         4852 :       CALL timeset(routineN, handle)
    1127         4852 :       NULLIFY (work_section)
    1128         4852 :       work_section => section_vals_get_subs_vals(input_file, TRIM(tag_section))
    1129         4852 :       CALL section_vals_get(work_section, explicit=explicit1)
    1130         4852 :       work_section => section_vals_get_subs_vals(restart_file, TRIM(tag_section))
    1131         4852 :       CALL section_vals_get(work_section, explicit=explicit2)
    1132              : 
    1133         4852 :       do_restart = explicit1 .AND. explicit2
    1134         4852 :       CALL timestop(handle)
    1135         4852 :    END FUNCTION check_restart
    1136              : 
    1137              : ! **************************************************************************************************
    1138              : !> \brief Removes section used to restart a calculation from an
    1139              : !>      input file in memory
    1140              : !> \param input_file the input file to initialize
    1141              : !> \author teo
    1142              : ! **************************************************************************************************
    1143         7412 :    SUBROUTINE remove_restart_info(input_file)
    1144              :       TYPE(section_vals_type), POINTER                   :: input_file
    1145              : 
    1146              :       CHARACTER(len=*), PARAMETER :: routineN = 'remove_restart_info'
    1147              : 
    1148              :       INTEGER                                            :: handle, iforce_eval, nforce_eval1
    1149              :       LOGICAL                                            :: explicit1
    1150              :       TYPE(section_vals_type), POINTER                   :: md_section, motion_section, section1, &
    1151              :                                                             section_to_delete, sections1, &
    1152              :                                                             work_section
    1153              : 
    1154         1853 :       CALL timeset(routineN, handle)
    1155              : 
    1156         1853 :       NULLIFY (work_section)
    1157         1853 :       section_to_delete => section_vals_get_subs_vals(input_file, "EXT_RESTART")
    1158         1853 :       CALL section_vals_remove_values(section_to_delete)
    1159         1853 :       sections1 => section_vals_get_subs_vals(input_file, "FORCE_EVAL")
    1160         1853 :       CALL section_vals_get(sections1, n_repetition=nforce_eval1)
    1161              : 
    1162         3824 :       DO iforce_eval = 1, nforce_eval1
    1163         1971 :          section1 => section_vals_get_subs_vals3(sections1, "SUBSYS", i_rep_section=iforce_eval)
    1164         1971 :          section_to_delete => section_vals_get_subs_vals(section1, "COORD")
    1165         1971 :          CALL section_vals_remove_values(section_to_delete)
    1166         1971 :          section_to_delete => section_vals_get_subs_vals(section1, "VELOCITY")
    1167         3824 :          CALL section_vals_remove_values(section_to_delete)
    1168              :       END DO
    1169              : 
    1170         1853 :       motion_section => section_vals_get_subs_vals(input_file, "MOTION")
    1171         1853 :       md_section => section_vals_get_subs_vals(motion_section, "MD")
    1172         1853 :       CALL section_vals_get(md_section, explicit=explicit1)
    1173         1853 :       IF (explicit1) THEN
    1174         1793 :          CALL section_vals_val_unset(md_section, "STEP_START_VAL")
    1175         1793 :          CALL section_vals_val_unset(md_section, "TIME_START_VAL")
    1176         1793 :          CALL section_vals_val_unset(md_section, "ECONS_START_VAL")
    1177              :       END IF
    1178         1853 :       work_section => section_vals_get_subs_vals(motion_section, "FREE_ENERGY%METADYN")
    1179         1853 :       CALL section_vals_get(work_section, explicit=explicit1)
    1180         1853 :       IF (explicit1) THEN
    1181          166 :          CALL section_vals_val_unset(motion_section, "FREE_ENERGY%METADYN%STEP_START_VAL")
    1182          166 :          CALL section_vals_val_unset(motion_section, "FREE_ENERGY%METADYN%NHILLS_START_VAL")
    1183              :       END IF
    1184         1853 :       section_to_delete => section_vals_get_subs_vals(motion_section, "BAND%REPLICA")
    1185         1853 :       CALL section_vals_remove_values(section_to_delete)
    1186         1853 :       section_to_delete => section_vals_get_subs_vals(md_section, "AVERAGES%RESTART_AVERAGES")
    1187         1853 :       CALL section_vals_remove_values(section_to_delete)
    1188         1853 :       section_to_delete => section_vals_get_subs_vals(md_section, "THERMOSTAT%NOSE%COORD")
    1189         1853 :       CALL section_vals_remove_values(section_to_delete)
    1190         1853 :       section_to_delete => section_vals_get_subs_vals(md_section, "THERMOSTAT%NOSE%VELOCITY")
    1191         1853 :       CALL section_vals_remove_values(section_to_delete)
    1192         1853 :       section_to_delete => section_vals_get_subs_vals(md_section, "THERMOSTAT%NOSE%MASS")
    1193         1853 :       CALL section_vals_remove_values(section_to_delete)
    1194         1853 :       section_to_delete => section_vals_get_subs_vals(md_section, "THERMOSTAT%NOSE%FORCE")
    1195         1853 :       CALL section_vals_remove_values(section_to_delete)
    1196         1853 :       section_to_delete => section_vals_get_subs_vals(md_section, "BAROSTAT%MASS")
    1197         1853 :       CALL section_vals_remove_values(section_to_delete)
    1198         1853 :       section_to_delete => section_vals_get_subs_vals(md_section, "BAROSTAT%VELOCITY")
    1199         1853 :       CALL section_vals_remove_values(section_to_delete)
    1200         1853 :       section_to_delete => section_vals_get_subs_vals(md_section, "BAROSTAT%THERMOSTAT%NOSE%COORD")
    1201         1853 :       CALL section_vals_remove_values(section_to_delete)
    1202         1853 :       section_to_delete => section_vals_get_subs_vals(md_section, "BAROSTAT%THERMOSTAT%NOSE%VELOCITY")
    1203         1853 :       CALL section_vals_remove_values(section_to_delete)
    1204         1853 :       section_to_delete => section_vals_get_subs_vals(md_section, "BAROSTAT%THERMOSTAT%NOSE%MASS")
    1205         1853 :       CALL section_vals_remove_values(section_to_delete)
    1206         1853 :       section_to_delete => section_vals_get_subs_vals(md_section, "BAROSTAT%THERMOSTAT%NOSE%FORCE")
    1207         1853 :       CALL section_vals_remove_values(section_to_delete)
    1208         1853 :       section_to_delete => section_vals_get_subs_vals(md_section, "SHELL%THERMOSTAT%NOSE%COORD")
    1209         1853 :       CALL section_vals_remove_values(section_to_delete)
    1210         1853 :       section_to_delete => section_vals_get_subs_vals(md_section, "SHELL%THERMOSTAT%NOSE%VELOCITY")
    1211         1853 :       CALL section_vals_remove_values(section_to_delete)
    1212         1853 :       section_to_delete => section_vals_get_subs_vals(md_section, "SHELL%THERMOSTAT%NOSE%MASS")
    1213         1853 :       CALL section_vals_remove_values(section_to_delete)
    1214         1853 :       section_to_delete => section_vals_get_subs_vals(md_section, "SHELL%THERMOSTAT%NOSE%FORCE")
    1215         1853 :       CALL section_vals_remove_values(section_to_delete)
    1216              :       ! Constrained/Restrained section
    1217         1853 :       section_to_delete => section_vals_get_subs_vals(motion_section, "CONSTRAINT%FIX_ATOM_RESTART")
    1218         1853 :       CALL section_vals_remove_values(section_to_delete)
    1219         1853 :       section_to_delete => section_vals_get_subs_vals(motion_section, "CONSTRAINT%COLVAR_RESTART")
    1220         1853 :       CALL section_vals_remove_values(section_to_delete)
    1221              :       ! Free energies restarts
    1222         1853 :       section_to_delete => section_vals_get_subs_vals(motion_section, "FREE_ENERGY%METADYN%SPAWNED_HILLS_POS")
    1223         1853 :       CALL section_vals_remove_values(section_to_delete)
    1224         1853 :       section_to_delete => section_vals_get_subs_vals(motion_section, "FREE_ENERGY%METADYN%SPAWNED_HILLS_SCALE")
    1225         1853 :       CALL section_vals_remove_values(section_to_delete)
    1226         1853 :       section_to_delete => section_vals_get_subs_vals(motion_section, "FREE_ENERGY%METADYN%SPAWNED_HILLS_HEIGHT")
    1227         1853 :       CALL section_vals_remove_values(section_to_delete)
    1228         1853 :       section_to_delete => section_vals_get_subs_vals(motion_section, "FREE_ENERGY%METADYN%SPAWNED_HILLS_INVDT")
    1229         1853 :       CALL section_vals_remove_values(section_to_delete)
    1230         1853 :       section_to_delete => section_vals_get_subs_vals(motion_section, "FREE_ENERGY%METADYN%EXT_LAGRANGE_SS0")
    1231         1853 :       CALL section_vals_remove_values(section_to_delete)
    1232         1853 :       section_to_delete => section_vals_get_subs_vals(motion_section, "FREE_ENERGY%METADYN%EXT_LAGRANGE_VVP")
    1233         1853 :       CALL section_vals_remove_values(section_to_delete)
    1234         1853 :       section_to_delete => section_vals_get_subs_vals(motion_section, "FREE_ENERGY%METADYN%EXT_LAGRANGE_SS")
    1235         1853 :       CALL section_vals_remove_values(section_to_delete)
    1236         1853 :       section_to_delete => section_vals_get_subs_vals(motion_section, "FREE_ENERGY%METADYN%EXT_LAGRANGE_FS")
    1237         1853 :       CALL section_vals_remove_values(section_to_delete)
    1238         1853 :       CALL timestop(handle)
    1239         1853 :    END SUBROUTINE remove_restart_info
    1240              : 
    1241              : ! **************************************************************************************************
    1242              : !> \brief This subroutine controls the defaults for the restartable quantities..
    1243              : !> \param r_section ...
    1244              : !> \author teo - University of Zurich - 09.2007 [tlaino]
    1245              : ! **************************************************************************************************
    1246          452 :    SUBROUTINE handle_defaults_restart(r_section)
    1247              :       TYPE(section_vals_type), POINTER                   :: r_section
    1248              : 
    1249              :       CHARACTER(len=*), PARAMETER :: routineN = 'handle_defaults_restart'
    1250              : 
    1251              :       INTEGER                                            :: handle, ik, nval
    1252              :       LOGICAL                                            :: restart_default
    1253              :       TYPE(keyword_type), POINTER                        :: keyword
    1254              :       TYPE(section_type), POINTER                        :: section
    1255              : 
    1256          226 :       CALL timeset(routineN, handle)
    1257          226 :       NULLIFY (keyword, section)
    1258          226 :       CALL section_vals_get(r_section, section=section)
    1259          226 :       CALL section_vals_val_get(r_section, "RESTART_DEFAULT", l_val=restart_default)
    1260         9266 :       DO ik = -1, section%n_keywords
    1261         9040 :          keyword => section%keywords(ik)%keyword
    1262         9266 :          IF (ASSOCIATED(keyword)) THEN
    1263         8588 :             IF (keyword%type_of_var == logical_t .AND. keyword%names(1) (1:8) == "RESTART_") THEN
    1264         7910 :                IF (TRIM(keyword%names(1)) == "RESTART_DEFAULT") CYCLE
    1265         7684 :                CALL section_vals_val_get(r_section, keyword%names(1), n_rep_val=nval)
    1266         7684 :                IF (nval == 0) THEN
    1267              :                   ! User didn't specify any value, use the value of the RESTART_DEFAULT keyword..
    1268         6668 :                   CALL section_vals_val_set(r_section, keyword%names(1), l_val=restart_default)
    1269              :                END IF
    1270              :             END IF
    1271              :          END IF
    1272              :       END DO
    1273          226 :       CALL timestop(handle)
    1274              : 
    1275          226 :    END SUBROUTINE handle_defaults_restart
    1276              : 
    1277              : END MODULE input_cp2k_check
        

Generated by: LCOV version 2.0-1