LCOV - code coverage report
Current view: top level - src - input_cp2k_check.F (source / functions) Coverage Total Hit
Test: CP2K Regtests (git:9ccafda) Lines: 91.8 % 635 583
Test Date: 2026-10-15 00:55:44 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        89636 :    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        22409 :       CALL timeset(routineN, handle)
      83        22409 :       CPASSERT(ASSOCIATED(input_file))
      84        22409 :       CPASSERT(input_file%ref_count > 0)
      85              :       ! ext_restart
      86        22409 :       IF (PRESENT(output_unit)) THEN
      87        22409 :          CALL handle_ext_restart(input_declaration, input_file, para_env, output_unit)
      88              :       END IF
      89              : 
      90              :       ! checks on force_eval section
      91        22409 :       sections => section_vals_get_subs_vals(input_file, "FORCE_EVAL")
      92        22409 :       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        22409 :       section2 => section_vals_get_subs_vals(input_file, "MOTION%MD%RESPA")
      96        22409 :       CALL section_vals_get(section2, explicit=explicit)
      97        44248 :       DO iforce_eval = 1, nforce_eval
      98              :          section3 => section_vals_get_subs_vals(sections, "MIXED", &
      99        22109 :                                                 i_rep_section=iforce_eval)
     100        22109 :          CALL section_vals_get(section3, explicit=explicit_mix)
     101        44248 :          IF (explicit_mix) EXIT
     102              :       END DO
     103        44874 :       DO iforce_eval = 1, nforce_eval
     104              :          section4 => section_vals_get_subs_vals(sections, "EMBED", &
     105        22513 :                                                 i_rep_section=iforce_eval)
     106        22513 :          CALL section_vals_get(section4, explicit=explicit_embed)
     107        44874 :          IF (explicit_embed) EXIT
     108              :       END DO
     109              :       ! also allow multiple force_eval for NEGF run
     110        22409 :       CALL section_vals_val_get(input_file, "GLOBAL%RUN_TYPE", i_val=run_type)
     111              : 
     112        22409 :       IF (((explicit .AND. (nforce_eval == 1)) .OR. (.NOT. explicit .AND. (nforce_eval > 1))) .AND. run_type /= negf_run) THEN
     113          318 :          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        45114 :       DO iforce_eval = 1, nforce_eval
     122        22705 :          section => section_vals_get_subs_vals3(sections, "DFT", i_rep_section=iforce_eval)
     123              :          ! xc: expand and fix default for tddfpt
     124        22705 :          section1 => section_vals_get_subs_vals(section, "XC")
     125        22705 :          section2 => section_vals_get_subs_vals(section, "XC%XC_FUNCTIONAL")
     126        22705 :          CALL xc_functionals_expand(section2, section1)
     127        22705 :          section1 => section_vals_get_subs_vals(section, "XAS_TDP%KERNEL")
     128        22705 :          section2 => section_vals_get_subs_vals(section, "XAS_TDP%KERNEL%XC_FUNCTIONAL")
     129        22705 :          CALL xc_functionals_expand(section2, section1)
     130        22705 :          section1 => section_vals_get_subs_vals(sections, "PROPERTIES%RIXS%XAS_TDP%KERNEL")
     131        22705 :          section2 => section_vals_get_subs_vals(sections, "PROPERTIES%RIXS%XAS_TDP%KERNEL%XC_FUNCTIONAL")
     132        22705 :          CALL xc_functionals_expand(section2, section1)
     133        22705 :          section1 => section_vals_get_subs_vals(section, "ACTIVE_SPACE%XC")
     134        22705 :          section2 => section_vals_get_subs_vals(section, "ACTIVE_SPACE%XC%XC_FUNCTIONAL")
     135        22705 :          CALL xc_functionals_expand(section2, section1)
     136        45114 :          CALL check_properties_bse(sections, iforce_eval)
     137              :       END DO
     138              : 
     139              :       ! additional checks for a MiMiC run
     140        22409 :       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        22409 :       CALL timestop(handle)
     166        22409 :    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        45494 :    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        22705 :       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        22705 :       NULLIFY (bs_sec, bse_sec, dft_sec, gw_sec, nkp_grid_dos, properties_sec, subsys_sec)
     187        45410 :       properties_sec => section_vals_get_subs_vals3(force_env_sections, "PROPERTIES", i_rep_section=iforce_eval)
     188        22705 :       bse_sec => section_vals_get_subs_vals(properties_sec, "BSE")
     189        22705 :       CALL section_vals_get(bse_sec, explicit=do_bse)
     190        22705 :       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        22705 :    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        93536 :    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        93536 :                                 i_val=shortcut)
     256              : 
     257        93536 :       ifun = 0
     258        93536 :       nfun = 0
     259        10589 :       DO
     260       104125 :          ifun = ifun + 1
     261       104125 :          xc_fun => section_vals_get_subs_vals2(functionals, i_section=ifun)
     262       104125 :          IF (.NOT. ASSOCIATED(xc_fun)) EXIT
     263        10589 :          nfun = nfun + 1
     264              :       END DO
     265              : !
     266        93536 :       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          406 :       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          406 :                                    l_val=.TRUE.)
     278              :          CALL section_vals_val_set(functionals, "PBE%SCALE_X", &
     279          406 :                                    r_val=0.75_dp)
     280              :          CALL section_vals_val_set(functionals, "PBE%SCALE_C", &
     281          406 :                                    r_val=1.0_dp)
     282              :          ! Hartree Fock Exact Exchange
     283              :          CALL section_vals_val_set(xc_section, "HF%FRACTION", &
     284          406 :                                    r_val=0.25_dp)
     285              :          CALL section_vals_val_set(functionals, "_SECTION_PARAMETERS_", &
     286          406 :                                    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          440 :                                    l_val=.TRUE.)
     341              :          CALL section_vals_val_set(functionals, "LYP%_SECTION_PARAMETERS_", &
     342          440 :                                    l_val=.TRUE.)
     343              :          CALL section_vals_val_set(functionals, "_SECTION_PARAMETERS_", &
     344          440 :                                    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         2327 :                                    l_val=.TRUE.)
     355              :          CALL section_vals_val_set(functionals, "_SECTION_PARAMETERS_", &
     356         2327 :                                    i_val=xc_funct_no_shortcut)
     357              :       CASE (xc_funct_pbe)
     358              :          CALL section_vals_val_set(functionals, "PBE%_SECTION_PARAMETERS_", &
     359         2319 :                                    l_val=.TRUE.)
     360              :          CALL section_vals_val_set(functionals, "_SECTION_PARAMETERS_", &
     361         2319 :                                    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        93536 :          CPABORT("unknown shortcut "//TRIM(ADJUSTL(cp_to_string(shortcut))))
     388              :       END SELECT
     389        93536 :    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        22409 :    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        22409 :       CALL timeset(routineN, handle)
     413              :       ! Handle restart file
     414        22409 :       r_section => section_vals_get_subs_vals(input_file, "EXT_RESTART")
     415        22409 :       CALL section_vals_val_get(r_section, "RESTART_FILE_NAME", c_val=r_file_path)
     416              : 
     417        22409 :       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          224 :                DIMENSION(:), POINTER                           :: restarted_infos
     423              :             INTEGER                                            :: ensemble, i_rep_val, &
     424              :                                                                   iforce_eval, myi, n_rep_val, &
     425              :                                                                   nforce_eval1, nforce_eval2
     426          224 :             INTEGER, DIMENSION(:), POINTER                     :: ivec, iwalkers_status, iwork, &
     427          224 :                                                                   rwalkers_status
     428              :             LOGICAL                                            :: bsse_check, check, explicit1, explicit2, &
     429              :                                                                   flag, flag2, qmmm_check, subsys_check
     430              :             REAL(KIND=dp)                                      :: myt
     431          224 :             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          224 :             NULLIFY (restarted_infos, iwalkers_status, rwalkers_status, vec, ivec, work, iwork)
     437          224 :             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          224 :                NULLIFY (restart_file)
     444          224 :                CALL section_vals_create(restart_file, input_declaration)
     445          224 :                CALL parser_create(cpparser, file_name=r_file_path, para_env=para_env)
     446          224 :                CALL cp_unit_set_create(default_units, "OUTPUT")
     447              :                CALL section_vals_parse(restart_file, cpparser, root_section=.FALSE., &
     448          224 :                                        default_units=default_units)
     449          224 :                CALL cp_unit_set_release(default_units)
     450         3360 :                CALL parser_release(cpparser)
     451              :             END BLOCK
     452              : 
     453              :             ! Restart and input files same number of force_env sections
     454          224 :             sections1 => section_vals_get_subs_vals(restart_file, "FORCE_EVAL")
     455          224 :             CALL section_vals_get(sections1, n_repetition=nforce_eval1)
     456          224 :             sections2 => section_vals_get_subs_vals(input_file, "FORCE_EVAL")
     457          224 :             CALL section_vals_get(sections2, n_repetition=nforce_eval2)
     458          224 :             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          224 :             CALL handle_defaults_restart(r_section)
     463              : 
     464              :             ! Real restart of force_evals
     465          464 :             DO iforce_eval = 1, nforce_eval1
     466              :                section1 => section_vals_get_subs_vals3(sections1, "SUBSYS", &
     467          240 :                                                        i_rep_section=iforce_eval)
     468              :                section2 => section_vals_get_subs_vals3(sections2, "SUBSYS", &
     469          240 :                                                        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          240 :                subsys_check = (ASSOCIATED(section1) .EQV. ASSOCIATED(section2))
     474          240 :                IF (subsys_check) THEN
     475          240 :                   IF (ASSOCIATED(section1)) THEN
     476          240 :                      CALL section_vals_val_get(r_section, "RESTART_CELL", l_val=flag)
     477          240 :                      IF (flag) THEN
     478          218 :                         section => section_vals_get_subs_vals(section1, "CELL")
     479          218 :                         CALL section_vals_set_subs_vals(section2, "CELL", section)
     480          218 :                         CALL set_restart_info("CELL", restarted_infos)
     481              :                      END IF
     482              : 
     483          240 :                      CALL section_vals_val_get(r_section, "RESTART_POS", l_val=flag)
     484          240 :                      IF (flag) THEN
     485          228 :                         section => section_vals_get_subs_vals(section1, "COORD")
     486          228 :                         CALL section_vals_set_subs_vals(section2, "COORD", section)
     487          228 :                         CALL set_restart_info("COORDINATES", restarted_infos)
     488              :                         ! Copy over also the information on the multiple_unit_cell
     489          228 :                         CALL section_vals_val_get(section1, "TOPOLOGY%MULTIPLE_UNIT_CELL", i_vals=ivec)
     490          228 :                         ALLOCATE (iwork(3))
     491         1596 :                         iwork = ivec
     492          228 :                         CALL section_vals_val_set(section2, "TOPOLOGY%MULTIPLE_UNIT_CELL", i_vals_ptr=iwork)
     493              :                      END IF
     494              : 
     495          240 :                      CALL section_vals_val_get(r_section, "RESTART_RANDOMG", l_val=flag)
     496          240 :                      IF (flag) THEN
     497          208 :                         section => section_vals_get_subs_vals(section1, "RNG_INIT")
     498          208 :                         CALL section_vals_set_subs_vals(section2, "RNG_INIT", section)
     499          208 :                         CALL set_restart_info("RANDOM NUMBER GENERATOR", restarted_infos)
     500              :                      END IF
     501              : 
     502          240 :                      CALL section_vals_val_get(r_section, "RESTART_VEL", l_val=flag)
     503          240 :                      IF (flag) THEN
     504          222 :                         section => section_vals_get_subs_vals(section1, "VELOCITY")
     505          222 :                         CALL section_vals_set_subs_vals(section2, "VELOCITY", section)
     506          222 :                         CALL set_restart_info("VELOCITIES", restarted_infos)
     507              :                      END IF
     508              : 
     509              :                      ! Core-Shell information "restarted" only when strictly necessary
     510          240 :                      CALL section_vals_val_get(r_section, "RESTART_SHELL_POS", l_val=flag)
     511          240 :                      IF (flag) THEN
     512          228 :                         section => section_vals_get_subs_vals(section1, "SHELL_COORD")
     513          228 :                         CALL section_vals_set_subs_vals(section2, "SHELL_COORD", section)
     514          228 :                         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          240 :                      CALL section_vals_val_get(r_section, "RESTART_CORE_POS", l_val=flag)
     519          240 :                      IF (flag) THEN
     520          228 :                         section => section_vals_get_subs_vals(section1, "CORE_COORD")
     521          228 :                         CALL section_vals_set_subs_vals(section2, "CORE_COORD", section)
     522          228 :                         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          240 :                      CALL section_vals_val_get(r_section, "RESTART_SHELL_VELOCITY", l_val=flag)
     527          240 :                      IF (flag) THEN
     528          228 :                         section => section_vals_get_subs_vals(section1, "SHELL_VELOCITY")
     529          228 :                         CALL section_vals_set_subs_vals(section2, "SHELL_VELOCITY", section)
     530          228 :                         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          240 :                      CALL section_vals_val_get(r_section, "RESTART_CORE_VELOCITY", l_val=flag)
     535          240 :                      IF (flag) THEN
     536          228 :                         section => section_vals_get_subs_vals(section1, "CORE_VELOCITY")
     537          228 :                         CALL section_vals_set_subs_vals(section2, "CORE_VELOCITY", section)
     538          228 :                         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          240 :                CALL section_vals_val_get(r_section, "RESTART_QMMM", l_val=flag)
     551          240 :                section1 => section_vals_get_subs_vals3(sections1, "QMMM", i_rep_section=iforce_eval)
     552          240 :                section2 => section_vals_get_subs_vals3(sections2, "QMMM", i_rep_section=iforce_eval)
     553          240 :                CALL section_vals_get(section1, explicit=explicit1)
     554          240 :                CALL section_vals_get(section2, explicit=explicit2)
     555          240 :                qmmm_check = (explicit1 .AND. explicit2)
     556          240 :                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          240 :                CALL section_vals_val_get(r_section, "RESTART_BSSE", l_val=flag)
     565          240 :                section1 => section_vals_get_subs_vals3(sections1, "BSSE", i_rep_section=iforce_eval)
     566          240 :                section2 => section_vals_get_subs_vals3(sections2, "BSSE", i_rep_section=iforce_eval)
     567          240 :                CALL section_vals_get(section1, explicit=explicit1)
     568          240 :                CALL section_vals_get(section2, explicit=explicit2)
     569          240 :                bsse_check = (explicit1 .AND. explicit2)
     570         1424 :                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          224 :             CALL section_vals_val_get(r_section, "RESTART_COUNTERS", l_val=flag)
     578          224 :             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          210 :                IF (check_restart(input_file, restart_file, "MOTION%GEO_OPT")) THEN
     590              :                   ! GEO_OPT
     591           18 :                   CALL section_vals_val_get(restart_file, "MOTION%GEO_OPT%STEP_START_VAL", i_val=myi)
     592           18 :                   CALL section_vals_val_set(input_file, "MOTION%GEO_OPT%STEP_START_VAL", i_val=myi)
     593           18 :                   CALL set_restart_info("GEO_OPT COUNTERS", restarted_infos)
     594              :                   ! ROT_OPT
     595           18 :                   IF (check_restart(input_file, restart_file, "MOTION%GEO_OPT%TRANSITION_STATE%DIMER%ROT_OPT")) THEN
     596              :                      CALL section_vals_val_get(restart_file, "MOTION%GEO_OPT%TRANSITION_STATE%DIMER%ROT_OPT%STEP_START_VAL", &
     597            2 :                                                i_val=myi)
     598              :                      CALL section_vals_val_set(input_file, "MOTION%GEO_OPT%TRANSITION_STATE%DIMER%ROT_OPT%STEP_START_VAL", &
     599            2 :                                                i_val=myi)
     600            2 :                      CALL set_restart_info("ROT_OPT COUNTERS", restarted_infos)
     601              :                   END IF
     602              :                END IF
     603              :                !
     604          210 :                IF (check_restart(input_file, restart_file, "MOTION%GEO_OPT")) THEN
     605              :                   ! CELL_OPT
     606           18 :                   CALL section_vals_val_get(restart_file, "MOTION%CELL_OPT%STEP_START_VAL", i_val=myi)
     607           18 :                   CALL section_vals_val_set(input_file, "MOTION%CELL_OPT%STEP_START_VAL", i_val=myi)
     608           18 :                   CALL set_restart_info("CELL_OPT COUNTERS", restarted_infos)
     609              :                END IF
     610              :                !
     611          210 :                IF (check_restart(input_file, restart_file, "OPTIMIZE_INPUT")) THEN
     612            2 :                   CALL section_vals_val_get(restart_file, "OPTIMIZE_INPUT%ITER_START_VAL", i_val=myi)
     613            2 :                   CALL section_vals_val_set(input_file, "OPTIMIZE_INPUT%ITER_START_VAL", i_val=myi)
     614            2 :                   CALL set_restart_info("OPTIMIZE_INPUT ITERATION NUMBER", restarted_infos)
     615              :                END IF
     616              :                !
     617          210 :                IF (check_restart(input_file, restart_file, "MOTION%PINT")) THEN
     618              :                   ! PINT
     619           10 :                   CALL section_vals_val_get(restart_file, "MOTION%PINT%ITERATION", i_val=myi)
     620           10 :                   CALL section_vals_val_set(input_file, "MOTION%PINT%ITERATION", i_val=myi)
     621           10 :                   CALL set_restart_info("PINT ITERATION NUMBER", restarted_infos)
     622              :                END IF
     623              :                !
     624          210 :                CALL section_vals_val_get(r_section, "RESTART_METADYNAMICS", l_val=flag2)
     625          210 :                IF (flag2 .AND. check_restart(input_file, restart_file, "MOTION%FREE_ENERGY%METADYN")) THEN
     626              :                   CALL section_vals_val_get(restart_file, &
     627           12 :                                             "MOTION%FREE_ENERGY%METADYN%STEP_START_VAL", i_val=myi)
     628              :                   CALL section_vals_val_set(input_file, &
     629           12 :                                             "MOTION%FREE_ENERGY%METADYN%STEP_START_VAL", i_val=myi)
     630              :                   CALL section_vals_val_get(restart_file, &
     631           12 :                                             "MOTION%FREE_ENERGY%METADYN%NHILLS_START_VAL", i_val=myi)
     632              :                   CALL section_vals_val_set(input_file, &
     633           12 :                                             "MOTION%FREE_ENERGY%METADYN%NHILLS_START_VAL", i_val=myi)
     634              :                   !RG Adaptive hills
     635              :                   CALL section_vals_val_get(restart_file, &
     636           12 :                                             "MOTION%FREE_ENERGY%METADYN%OLD_HILL_NUMBER", i_val=myi)
     637              :                   CALL section_vals_val_set(input_file, &
     638           12 :                                             "MOTION%FREE_ENERGY%METADYN%OLD_HILL_NUMBER", i_val=myi)
     639              :                   CALL section_vals_val_get(restart_file, &
     640           12 :                                             "MOTION%FREE_ENERGY%METADYN%OLD_HILL_STEP", i_val=myi)
     641              :                   CALL section_vals_val_set(input_file, &
     642           12 :                                             "MOTION%FREE_ENERGY%METADYN%OLD_HILL_STEP", i_val=myi)
     643              :                   !RG Adaptive hills
     644           12 :                   CALL set_restart_info("METADYNAMIC COUNTERS", restarted_infos)
     645              :                END IF
     646              :             END IF
     647              : 
     648          224 :             CALL section_vals_val_get(r_section, "RESTART_AVERAGES", l_val=flag)
     649          224 :             IF (flag) THEN
     650          212 :                IF (check_restart(input_file, restart_file, "MOTION%MD")) THEN
     651          174 :                   rep_sections => section_vals_get_subs_vals(restart_file, "MOTION%MD%AVERAGES%RESTART_AVERAGES")
     652          174 :                   CALL section_vals_set_subs_vals(input_file, "MOTION%MD%AVERAGES%RESTART_AVERAGES", rep_sections)
     653          174 :                   CALL set_restart_info("MD AVERAGES", restarted_infos)
     654              :                END IF
     655              :             END IF
     656              : 
     657          224 :             CALL section_vals_val_get(r_section, "RESTART_BAND", l_val=flag)
     658          224 :             IF (flag .AND. check_restart(input_file, restart_file, "MOTION%BAND")) THEN
     659            6 :                rep_sections => section_vals_get_subs_vals(restart_file, "MOTION%BAND%REPLICA")
     660            6 :                CALL section_vals_set_subs_vals(input_file, "MOTION%BAND%REPLICA", rep_sections)
     661            6 :                CALL set_restart_info("BAND CALCULATION", restarted_infos)
     662              :             END IF
     663              : 
     664          224 :             CALL section_vals_val_get(r_section, "RESTART_OPTIMIZE_INPUT_VARIABLES", l_val=flag)
     665          224 :             IF (flag .AND. check_restart(input_file, restart_file, "OPTIMIZE_INPUT%VARIABLE")) THEN
     666            2 :                rep_sections => section_vals_get_subs_vals(restart_file, "OPTIMIZE_INPUT%VARIABLE")
     667            2 :                CALL section_vals_set_subs_vals(input_file, "OPTIMIZE_INPUT%VARIABLE", rep_sections)
     668            2 :                CALL set_restart_info("OPTIMIZE_INPUT: VARIABLES", restarted_infos)
     669              :             END IF
     670              : 
     671          224 :             CALL section_vals_val_get(r_section, "RESTART_BAROSTAT", l_val=flag)
     672          224 :             IF (flag .AND. check_restart(input_file, restart_file, "MOTION%MD%BAROSTAT")) THEN
     673              :                section => section_vals_get_subs_vals(restart_file, &
     674           22 :                                                      "MOTION%MD%BAROSTAT%MASS")
     675              :                CALL section_vals_set_subs_vals(input_file, "MOTION%MD%BAROSTAT%MASS", &
     676           22 :                                                section)
     677              :                section => section_vals_get_subs_vals(restart_file, &
     678           22 :                                                      "MOTION%MD%BAROSTAT%VELOCITY")
     679              :                CALL section_vals_set_subs_vals(input_file, "MOTION%MD%BAROSTAT%VELOCITY", &
     680           22 :                                                section)
     681           22 :                CALL set_restart_info("BAROSTAT", restarted_infos)
     682              :             END IF
     683              : 
     684          224 :             flag = check_restart(input_file, restart_file, "MOTION%MD")
     685          224 :             IF (flag) THEN
     686          176 :                CALL section_vals_val_get(input_file, "MOTION%MD%ENSEMBLE", i_val=ensemble)
     687          176 :                IF (ensemble == npt_i_ensemble .OR. ensemble == npt_f_ensemble .OR. ensemble == npt_ia_ensemble) THEN
     688           32 :                   CALL section_vals_val_get(r_section, "RESTART_BAROSTAT_THERMOSTAT", l_val=flag)
     689           32 :                   check = check_restart(input_file, restart_file, "MOTION%MD%BAROSTAT")
     690              :                   CALL restart_thermostat(flag, input_file, restart_file, "MOTION%MD%BAROSTAT%THERMOSTAT", &
     691           32 :                                           check=check)
     692           32 :                   IF (flag .AND. check) CALL set_restart_info("THERMOSTAT OF BAROSTAT", restarted_infos)
     693              :                END IF
     694              :             END IF
     695              : 
     696          224 :             check = check_restart(input_file, restart_file, "MOTION%MD%SHELL")
     697          224 :             IF (check) THEN
     698           18 :                CALL section_vals_val_get(r_section, "RESTART_SHELL_THERMOSTAT", l_val=flag)
     699           18 :                CALL restart_thermostat(flag, input_file, restart_file, "MOTION%MD%SHELL%THERMOSTAT")
     700           18 :                CALL set_restart_info("SHELL THERMOSTAT", restarted_infos)
     701              :             END IF
     702              : 
     703          224 :             CALL section_vals_val_get(r_section, "RESTART_THERMOSTAT", l_val=flag)
     704          224 :             CALL restart_thermostat(flag, input_file, restart_file, "MOTION%MD%THERMOSTAT")
     705          224 :             IF (flag) CALL set_restart_info("PARTICLE THERMOSTAT", restarted_infos)
     706              : 
     707          224 :             CALL section_vals_val_get(r_section, "RESTART_CONSTRAINT", l_val=flag)
     708          224 :             IF (flag .AND. check_restart(input_file, restart_file, "MOTION%CONSTRAINT")) THEN
     709           38 :                section => section_vals_get_subs_vals(restart_file, "MOTION%CONSTRAINT")
     710           38 :                CALL section_vals_set_subs_vals(input_file, "MOTION%CONSTRAINT", section)
     711           38 :                CALL set_restart_info("CONSTRAINTS/RESTRAINTS", restarted_infos)
     712              :             END IF
     713              : 
     714          224 :             CALL section_vals_val_get(r_section, "RESTART_METADYNAMICS", l_val=flag)
     715          224 :             IF (flag .AND. check_restart(input_file, restart_file, "MOTION%FREE_ENERGY%METADYN")) THEN
     716              :                section => section_vals_get_subs_vals(restart_file, &
     717           12 :                                                      "MOTION%FREE_ENERGY%METADYN%SPAWNED_HILLS_POS")
     718              :                CALL section_vals_set_subs_vals(input_file, "MOTION%FREE_ENERGY%METADYN%SPAWNED_HILLS_POS", &
     719           12 :                                                section)
     720              :                section => section_vals_get_subs_vals(restart_file, &
     721           12 :                                                      "MOTION%FREE_ENERGY%METADYN%SPAWNED_HILLS_SCALE")
     722              :                CALL section_vals_set_subs_vals(input_file, "MOTION%FREE_ENERGY%METADYN%SPAWNED_HILLS_SCALE", &
     723           12 :                                                section)
     724              :                section => section_vals_get_subs_vals(restart_file, &
     725           12 :                                                      "MOTION%FREE_ENERGY%METADYN%SPAWNED_HILLS_HEIGHT")
     726              :                CALL section_vals_set_subs_vals(input_file, "MOTION%FREE_ENERGY%METADYN%SPAWNED_HILLS_HEIGHT", &
     727           12 :                                                section)
     728              :                section => section_vals_get_subs_vals(restart_file, &
     729           12 :                                                      "MOTION%FREE_ENERGY%METADYN%SPAWNED_HILLS_INVDT")
     730              :                CALL section_vals_set_subs_vals(input_file, "MOTION%FREE_ENERGY%METADYN%SPAWNED_HILLS_INVDT", &
     731           12 :                                                section)
     732              :                ! Extended Lagrangian
     733              :                section => section_vals_get_subs_vals(restart_file, &
     734           12 :                                                      "MOTION%FREE_ENERGY%METADYN%EXT_LAGRANGE_SS0")
     735              :                CALL section_vals_set_subs_vals(input_file, "MOTION%FREE_ENERGY%METADYN%EXT_LAGRANGE_SS0", &
     736           12 :                                                section)
     737              :                section => section_vals_get_subs_vals(restart_file, &
     738           12 :                                                      "MOTION%FREE_ENERGY%METADYN%EXT_LAGRANGE_VVP")
     739              :                CALL section_vals_set_subs_vals(input_file, "MOTION%FREE_ENERGY%METADYN%EXT_LAGRANGE_VVP", &
     740           12 :                                                section)
     741              :                section => section_vals_get_subs_vals(restart_file, &
     742           12 :                                                      "MOTION%FREE_ENERGY%METADYN%EXT_LAGRANGE_SS")
     743              :                CALL section_vals_set_subs_vals(input_file, "MOTION%FREE_ENERGY%METADYN%EXT_LAGRANGE_SS", &
     744           12 :                                                section)
     745              :                section => section_vals_get_subs_vals(restart_file, &
     746           12 :                                                      "MOTION%FREE_ENERGY%METADYN%EXT_LAGRANGE_FS")
     747              :                CALL section_vals_set_subs_vals(input_file, "MOTION%FREE_ENERGY%METADYN%EXT_LAGRANGE_FS", &
     748           12 :                                                section)
     749           12 :                CALL set_restart_info("METADYNAMICS", restarted_infos)
     750              :             END IF
     751              : 
     752          224 :             CALL section_vals_val_get(r_section, "RESTART_TEMPERATURE_ANNEALING", l_val=flag)
     753          224 :             IF (flag .AND. check_restart(input_file, restart_file, "MOTION%MD")) THEN
     754            2 :                CALL section_vals_val_get(input_file, "MOTION%MD%TEMPERATURE_ANNEALING", r_val=myt, explicit=explicit1)
     755            2 :                IF ((.NOT. explicit1) .OR. (ABS(1._dp - myt) <= 1.E-10_dp)) THEN
     756              :                   CALL cp_warn(__LOCATION__, &
     757              :                                "I'm about to override the input temperature "// &
     758              :                                "with the temperature found in external restart "// &
     759            0 :                                "but TEMPERATURE_ANNEALING isn't explicitly given or it is set to 1.")
     760              :                END IF
     761            2 :                CALL section_vals_val_get(restart_file, "MOTION%MD%TEMPERATURE", r_val=myt, explicit=explicit1)
     762            2 :                IF (explicit1) THEN
     763            2 :                   CALL section_vals_val_get(input_file, "MOTION%MD%TEMPERATURE", r_val=myt)
     764              :                ELSE
     765              :                   CALL cp_warn(__LOCATION__, &
     766              :                                "I'm not going to override the input temperature "// &
     767            0 :                                "since the temperature isn't explicitly given in the external restart.")
     768              :                END IF
     769              :             END IF
     770              : 
     771          224 :             CALL section_vals_val_get(r_section, "RESTART_WALKERS", l_val=flag)
     772          224 :             IF (flag .AND. check_restart(input_file, restart_file, "MOTION%FREE_ENERGY%METADYN%MULTIPLE_WALKERS")) THEN
     773              :                CALL section_vals_val_get(restart_file, "MOTION%FREE_ENERGY%METADYN%MULTIPLE_WALKERS%WALKERS_STATUS", &
     774            4 :                                          i_vals=rwalkers_status)
     775           12 :                ALLOCATE (iwalkers_status(SIZE(rwalkers_status)))
     776           20 :                iwalkers_status = rwalkers_status
     777              :                CALL section_vals_val_set(input_file, "MOTION%FREE_ENERGY%METADYN%MULTIPLE_WALKERS%WALKERS_STATUS", &
     778            4 :                                          i_vals_ptr=iwalkers_status)
     779            4 :                CALL set_restart_info("WALKERS INFO", restarted_infos)
     780              :             END IF
     781              : 
     782          224 :             CALL section_vals_val_get(r_section, "RESTART_DIMER", l_val=flag)
     783          224 :             IF (flag .AND. check_restart(input_file, restart_file, "MOTION%GEO_OPT%TRANSITION_STATE%DIMER")) THEN
     784              :                section => section_vals_get_subs_vals(restart_file, &
     785            2 :                                                      "MOTION%GEO_OPT%TRANSITION_STATE%DIMER%DIMER_VECTOR")
     786              :                CALL section_vals_set_subs_vals(input_file, "MOTION%GEO_OPT%TRANSITION_STATE%DIMER%DIMER_VECTOR", &
     787            2 :                                                section)
     788            2 :                CALL set_restart_info("DIMER TRANSITION STATE SEARCH", restarted_infos)
     789              :             END IF
     790              : 
     791          224 :             CALL section_vals_val_get(r_section, "CUSTOM_PATH", n_rep_val=n_rep_val)
     792          224 :             DO i_rep_val = 1, n_rep_val
     793            0 :                CALL section_vals_val_get(r_section, "CUSTOM_PATH", i_rep_val=i_rep_val, c_val=path)
     794          224 :                IF (path /= " ") THEN
     795            0 :                   section => section_vals_get_subs_vals(restart_file, path)
     796            0 :                   CALL section_vals_set_subs_vals(input_file, path, section)
     797            0 :                   CALL set_restart_info("USER RESTART: "//TRIM(path), restarted_infos)
     798              :                END IF
     799              :             END DO
     800              : 
     801          224 :             CALL section_vals_val_get(r_section, "RESTART_RTP", l_val=flag)
     802              :             !          IF(flag.AND.check_restart(input_file, restart_file, "FORCE_EVAL%DFT%REAL_TIME_PROPAGATION")) THEN
     803          224 :             IF (flag) THEN
     804              :                section => section_vals_get_subs_vals(restart_file, &
     805          212 :                                                      "FORCE_EVAL%DFT%REAL_TIME_PROPAGATION")
     806          212 :                CALL section_vals_val_get(section, "INITIAL_WFN", i_val=myi)
     807              :                CALL section_vals_val_set(input_file, "FORCE_EVAL%DFT%REAL_TIME_PROPAGATION%INITIAL_WFN", &
     808          212 :                                          i_val=myi)
     809          212 :                CALL set_restart_info("REAL TIME PROPAGATION", restarted_infos)
     810              :             END IF
     811              : 
     812              :             ! PIMD
     813          224 :             CALL section_vals_val_get(r_section, "RESTART_PINT_POS", l_val=flag)
     814          224 :             IF (flag) THEN
     815          218 :                section => section_vals_get_subs_vals(restart_file, "MOTION%PINT%BEADS%COORD")
     816          218 :                CALL section_vals_set_subs_vals(input_file, "MOTION%PINT%BEADS%COORD", section)
     817          218 :                CALL set_restart_info("PINT BEAD POSITIONS", restarted_infos)
     818              :             END IF
     819          224 :             CALL section_vals_val_get(r_section, "RESTART_PINT_VEL", l_val=flag)
     820          224 :             IF (flag) THEN
     821          218 :                section => section_vals_get_subs_vals(restart_file, "MOTION%PINT%BEADS%VELOCITY")
     822          218 :                CALL section_vals_set_subs_vals(input_file, "MOTION%PINT%BEADS%VELOCITY", section)
     823          218 :                CALL set_restart_info("PINT BEAD VELOCITIES", restarted_infos)
     824              :             END IF
     825          224 :             CALL section_vals_val_get(r_section, "RESTART_PINT_NOSE", l_val=flag)
     826          224 :             IF (flag) THEN
     827          218 :                section => section_vals_get_subs_vals(restart_file, "MOTION%PINT%NOSE%COORD")
     828          218 :                CALL section_vals_set_subs_vals(input_file, "MOTION%PINT%NOSE%COORD", section)
     829          218 :                section => section_vals_get_subs_vals(restart_file, "MOTION%PINT%NOSE%VELOCITY")
     830          218 :                CALL section_vals_set_subs_vals(input_file, "MOTION%PINT%NOSE%VELOCITY", section)
     831          218 :                CALL set_restart_info("PINT NOSE THERMOSTAT", restarted_infos)
     832              :             END IF
     833          224 :             CALL section_vals_val_get(r_section, "RESTART_PINT_GLE", l_val=flag)
     834          224 :             IF (flag) THEN
     835          212 :                section => section_vals_get_subs_vals(restart_file, "MOTION%PINT%GLE")
     836          212 :                CALL section_vals_set_subs_vals(input_file, "MOTION%PINT%GLE", section)
     837          212 :                CALL set_restart_info("PINT GLE THERMOSTAT", restarted_infos)
     838              :             END IF
     839              : 
     840              :             ! PIMC
     841              :             !
     842          224 :             CALL section_vals_val_get(r_section, "RESTART_HELIUM_POS", l_val=flag)
     843          224 :             IF (flag) THEN
     844              :                CALL section_vals_val_get(input_file, "MOTION%PINT%HELIUM%NUM_ENV", &
     845          218 :                                          explicit=explicit1)
     846          218 :                IF (.NOT. explicit1) THEN
     847          212 :                   CALL section_vals_val_get(restart_file, "MOTION%PINT%HELIUM%NUM_ENV", i_val=myi)
     848          212 :                   CALL section_vals_val_set(input_file, "MOTION%PINT%HELIUM%NUM_ENV", i_val=myi)
     849              :                END IF
     850          218 :                section => section_vals_get_subs_vals(restart_file, "MOTION%PINT%HELIUM%COORD")
     851          218 :                CALL section_vals_set_subs_vals(input_file, "MOTION%PINT%HELIUM%COORD", section)
     852          218 :                CALL set_restart_info("HELIUM BEAD POSITIONS", restarted_infos)
     853              :             END IF
     854              :             !
     855          224 :             CALL section_vals_val_get(r_section, "RESTART_HELIUM_PERMUTATION", l_val=flag)
     856          224 :             IF (flag) THEN
     857              :                CALL section_vals_val_get(input_file, "MOTION%PINT%HELIUM%NUM_ENV", &
     858          218 :                                          explicit=explicit1)
     859          218 :                IF (.NOT. explicit1) THEN
     860            0 :                   CALL section_vals_val_get(restart_file, "MOTION%PINT%HELIUM%NUM_ENV", i_val=myi)
     861            0 :                   CALL section_vals_val_set(input_file, "MOTION%PINT%HELIUM%NUM_ENV", i_val=myi)
     862              :                END IF
     863          218 :                section => section_vals_get_subs_vals(restart_file, "MOTION%PINT%HELIUM%PERM")
     864          218 :                CALL section_vals_set_subs_vals(input_file, "MOTION%PINT%HELIUM%PERM", section)
     865          218 :                CALL set_restart_info("HELIUM PERMUTATION STATE", restarted_infos)
     866              :             END IF
     867              :             !
     868          224 :             CALL section_vals_val_get(r_section, "RESTART_HELIUM_FORCE", l_val=flag)
     869          224 :             IF (flag) THEN
     870              :                CALL section_vals_val_get(input_file, "MOTION%PINT%HELIUM%NUM_ENV", &
     871          214 :                                          explicit=explicit1)
     872          214 :                IF (.NOT. explicit1) THEN
     873            0 :                   CALL section_vals_val_get(restart_file, "MOTION%PINT%HELIUM%NUM_ENV", i_val=myi)
     874            0 :                   CALL section_vals_val_set(input_file, "MOTION%PINT%HELIUM%NUM_ENV", i_val=myi)
     875              :                END IF
     876          214 :                section => section_vals_get_subs_vals(restart_file, "MOTION%PINT%HELIUM%FORCE")
     877          214 :                CALL section_vals_set_subs_vals(input_file, "MOTION%PINT%HELIUM%FORCE", section)
     878          214 :                CALL set_restart_info("HELIUM FORCES ON SOLUTE", restarted_infos)
     879              :             END IF
     880              :             !
     881          224 :             CALL section_vals_val_get(r_section, "RESTART_HELIUM_RNG", l_val=flag)
     882          224 :             IF (flag) THEN
     883              :                CALL section_vals_val_get(input_file, "MOTION%PINT%HELIUM%NUM_ENV", &
     884          218 :                                          explicit=explicit1)
     885          218 :                IF (.NOT. explicit1) THEN
     886            0 :                   CALL section_vals_val_get(restart_file, "MOTION%PINT%HELIUM%NUM_ENV", i_val=myi)
     887            0 :                   CALL section_vals_val_set(input_file, "MOTION%PINT%HELIUM%NUM_ENV", i_val=myi)
     888              :                END IF
     889          218 :                section => section_vals_get_subs_vals(restart_file, "MOTION%PINT%HELIUM%RNG_STATE")
     890          218 :                CALL section_vals_set_subs_vals(input_file, "MOTION%PINT%HELIUM%RNG_STATE", section)
     891          218 :                CALL set_restart_info("HELIUM RNG STATE", restarted_infos)
     892              :             END IF
     893              :             !
     894              :             !
     895          224 :             CALL section_vals_val_get(r_section, "RESTART_HELIUM_DENSITIES", l_val=flag)
     896          224 :             IF (flag) THEN
     897              :                CALL section_vals_val_get(input_file, "MOTION%PINT%HELIUM%NUM_ENV", &
     898            0 :                                          explicit=explicit1)
     899            0 :                IF (.NOT. explicit1) THEN
     900            0 :                   CALL section_vals_val_get(restart_file, "MOTION%PINT%HELIUM%NUM_ENV", i_val=myi)
     901            0 :                   CALL section_vals_val_set(input_file, "MOTION%PINT%HELIUM%NUM_ENV", i_val=myi)
     902              :                END IF
     903            0 :                section => section_vals_get_subs_vals(restart_file, "MOTION%PINT%HELIUM%RHO")
     904            0 :                CALL section_vals_set_subs_vals(input_file, "MOTION%PINT%HELIUM%RHO", section)
     905            0 :                CALL set_restart_info("HELIUM DENSITIES", restarted_infos)
     906              :             END IF
     907              :             !
     908          224 :             CALL section_vals_val_set(r_section, "RESTART_FILE_NAME", c_val=" ")
     909          224 :             CALL section_vals_release(restart_file)
     910              :             CALL release_restart_info(restarted_infos, r_file_path, binary_restart_file, &
     911         6048 :                                       output_unit)
     912              :          END BLOCK
     913              :       END IF
     914        22409 :       CALL timestop(handle)
     915        22409 :    END SUBROUTINE handle_ext_restart
     916              : 
     917              : ! **************************************************************************************************
     918              : !> \brief store information on the restarted quantities
     919              : !> \param label ...
     920              : !> \param restarted_infos ...
     921              : !> \author Teodoro Laino [tlaino] 09.2008 - University of Zurich
     922              : ! **************************************************************************************************
     923         3662 :    SUBROUTINE set_restart_info(label, restarted_infos)
     924              : 
     925              :       CHARACTER(LEN=*), INTENT(IN)                       :: label
     926              :       CHARACTER(LEN=default_string_length), &
     927              :          DIMENSION(:), POINTER                           :: restarted_infos
     928              : 
     929              :       INTEGER                                            :: isize
     930              : 
     931         3662 :       isize = 0
     932         3440 :       IF (ASSOCIATED(restarted_infos)) isize = SIZE(restarted_infos)
     933         3662 :       isize = isize + 1
     934         3662 :       CALL reallocate(restarted_infos, 1, isize)
     935         3662 :       restarted_infos(isize) = TRIM(label)
     936              : 
     937         3662 :    END SUBROUTINE set_restart_info
     938              : 
     939              : ! **************************************************************************************************
     940              : !> \brief dumps on output the information on the information effectively restarted
     941              : !> \param restarted_infos ...
     942              : !> \param r_file_path ...
     943              : !> \param binary_restart_file ...
     944              : !> \param output_unit ...
     945              : !> \author Teodoro Laino [tlaino] 09.2008 - University of Zurich
     946              : ! **************************************************************************************************
     947          224 :    SUBROUTINE release_restart_info(restarted_infos, r_file_path, &
     948              :                                    binary_restart_file, output_unit)
     949              :       CHARACTER(LEN=default_string_length), &
     950              :          DIMENSION(:), POINTER                           :: restarted_infos
     951              :       CHARACTER(LEN=*), INTENT(IN)                       :: r_file_path, binary_restart_file
     952              :       INTEGER, INTENT(IN)                                :: output_unit
     953              : 
     954              :       INTEGER                                            :: i, j
     955              : 
     956          224 :       IF (output_unit > 0 .AND. ASSOCIATED(restarted_infos)) THEN
     957          111 :          WRITE (output_unit, '(1X,79("*"))')
     958          111 :          WRITE (output_unit, '(1X,"*",T30,A,T80,"*")') " RESTART INFORMATION "
     959          111 :          WRITE (output_unit, '(1X,79("*"))')
     960          111 :          WRITE (output_unit, '(1X,"*",T80,"*")')
     961          111 :          i = 1
     962          111 :          WRITE (output_unit, '(1X,"*",A,T26,A,T80,"*")') "    RESTART FILE NAME:  ", &
     963          222 :             r_file_path(53*(i - 1) + 1:53*i)
     964          111 :          DO i = 2, CEILING(REAL(LEN_TRIM(r_file_path), KIND=dp)/53.0_dp)
     965          111 :             WRITE (output_unit, '(T1,1X,"*",T26,A,T80,"*")') r_file_path(53*(i - 1) + 1:53*i)
     966              :          END DO
     967          111 :          IF (LEN_TRIM(binary_restart_file) > 0) THEN
     968           23 :             i = 1
     969           23 :             WRITE (output_unit, '(1X,"*",A,T26,A,T80,"*")') "  BINARY RESTART FILE:  ", &
     970           46 :                binary_restart_file(53*(i - 1) + 1:53*i)
     971           23 :             DO i = 2, CEILING(REAL(LEN_TRIM(binary_restart_file), KIND=dp)/53.0_dp)
     972           23 :                WRITE (output_unit, '(T1,1X,"*",T26,A,T80,"*")') binary_restart_file(53*(i - 1) + 1:53*i)
     973              :             END DO
     974              :          END IF
     975          111 :          WRITE (output_unit, '(1X,"*",T80,"*")')
     976          111 :          WRITE (output_unit, '(1X,"*", A,T80,"*")') " RESTARTED QUANTITIES:  "
     977         1942 :          DO j = 1, SIZE(restarted_infos)
     978         3773 :             DO i = 1, CEILING(REAL(LEN_TRIM(restarted_infos(j)), KIND=dp)/53.0_dp)
     979         3662 :                WRITE (output_unit, '(T1,1X,"*",T26,A,T80,"*")') restarted_infos(j) (53*(i - 1) + 1:53*i)
     980              :             END DO
     981              :          END DO
     982          111 :          WRITE (output_unit, '(1X,79("*"),/)')
     983              :       END IF
     984          224 :       IF (ASSOCIATED(restarted_infos)) THEN
     985          222 :          DEALLOCATE (restarted_infos)
     986              :       END IF
     987          224 :    END SUBROUTINE release_restart_info
     988              : 
     989              : ! **************************************************************************************************
     990              : !> \brief Possibly restart thermostats information
     991              : !> \param flag ...
     992              : !> \param input_file the input file to initialize
     993              : !> \param restart_file ...
     994              : !> \param path ...
     995              : !> \param check ...
     996              : !> \author Teodoro Laino [tlaino] 10.2007- University of Zurich
     997              : ! **************************************************************************************************
     998          274 :    SUBROUTINE restart_thermostat(flag, input_file, restart_file, path, check)
     999              :       LOGICAL, INTENT(IN)                                :: flag
    1000              :       TYPE(section_vals_type), POINTER                   :: input_file, restart_file
    1001              :       CHARACTER(LEN=*), INTENT(IN)                       :: path
    1002              :       LOGICAL, INTENT(IN), OPTIONAL                      :: check
    1003              : 
    1004              :       INTEGER                                            :: input_region, input_type, &
    1005              :                                                             restart_region, restart_type
    1006              :       LOGICAL                                            :: check_loc, skip_other_checks
    1007              :       TYPE(section_vals_type), POINTER                   :: section
    1008              : 
    1009          274 :       check_loc = check_restart(input_file, restart_file, TRIM(path))
    1010          274 :       skip_other_checks = PRESENT(check)
    1011          274 :       IF (skip_other_checks) check_loc = check
    1012          274 :       IF (flag .AND. check_loc) THEN
    1013              :          ! Let's check if the thermostat type is different otherwise it does not make any
    1014              :          ! sense to do any kind of restart
    1015          134 :          CALL section_vals_val_get(input_file, TRIM(path)//"%TYPE", i_val=input_type)
    1016          134 :          CALL section_vals_val_get(restart_file, TRIM(path)//"%TYPE", i_val=restart_type)
    1017              : 
    1018          134 :          IF (input_type == do_thermo_same_as_part) THEN
    1019           18 :             CALL section_vals_val_get(input_file, "MOTION%MD%THERMOSTAT%TYPE", i_val=input_type)
    1020              :          END IF
    1021              : 
    1022          134 :          IF (skip_other_checks) THEN
    1023           20 :             input_region = do_region_global
    1024           20 :             restart_region = do_region_global
    1025              :          ELSE
    1026              :             ! Also the regions must be the same..
    1027          114 :             CALL section_vals_val_get(input_file, TRIM(path)//"%REGION", i_val=input_region)
    1028          114 :             CALL section_vals_val_get(restart_file, TRIM(path)//"%REGION", i_val=restart_region)
    1029              :          END IF
    1030              : 
    1031          134 :          IF ((input_type == restart_type) .AND. (input_region == restart_region)) THEN
    1032          110 :             SELECT CASE (input_type)
    1033              :             CASE (do_thermo_nose)
    1034          110 :                section => section_vals_get_subs_vals(restart_file, TRIM(path)//"%NOSE%COORD")
    1035          110 :                CALL section_vals_set_subs_vals(input_file, TRIM(path)//"%NOSE%COORD", section)
    1036              : 
    1037          110 :                section => section_vals_get_subs_vals(restart_file, TRIM(path)//"%NOSE%VELOCITY")
    1038          110 :                CALL section_vals_set_subs_vals(input_file, TRIM(path)//"%NOSE%VELOCITY", section)
    1039              : 
    1040          110 :                section => section_vals_get_subs_vals(restart_file, TRIM(path)//"%NOSE%MASS")
    1041          110 :                CALL section_vals_set_subs_vals(input_file, TRIM(path)//"%NOSE%MASS", section)
    1042              : 
    1043          110 :                section => section_vals_get_subs_vals(restart_file, TRIM(path)//"%NOSE%FORCE")
    1044          110 :                CALL section_vals_set_subs_vals(input_file, TRIM(path)//"%NOSE%FORCE", section)
    1045              :             CASE (do_thermo_csvr)
    1046           22 :                section => section_vals_get_subs_vals(restart_file, TRIM(path)//"%CSVR%THERMOSTAT_ENERGY")
    1047           22 :                CALL section_vals_set_subs_vals(input_file, TRIM(path)//"%CSVR%THERMOSTAT_ENERGY", section)
    1048           22 :                section => section_vals_get_subs_vals(restart_file, TRIM(path)//"%CSVR%RNG_INIT")
    1049           22 :                CALL section_vals_set_subs_vals(input_file, TRIM(path)//"%CSVR%RNG_INIT", section)
    1050              :             CASE (do_thermo_gle)
    1051            2 :                section => section_vals_get_subs_vals(restart_file, TRIM(path)//"%GLE%THERMOSTAT_ENERGY")
    1052            2 :                CALL section_vals_set_subs_vals(input_file, TRIM(path)//"%GLE%THERMOSTAT_ENERGY", section)
    1053            2 :                section => section_vals_get_subs_vals(restart_file, TRIM(path)//"%GLE%RNG_INIT")
    1054            2 :                CALL section_vals_set_subs_vals(input_file, TRIM(path)//"%GLE%RNG_INIT", section)
    1055            2 :                section => section_vals_get_subs_vals(restart_file, TRIM(path)//"%GLE%S")
    1056            2 :                CALL section_vals_set_subs_vals(input_file, TRIM(path)//"%GLE%S", section)
    1057              :             CASE (do_thermo_al)
    1058            0 :                section => section_vals_get_subs_vals(restart_file, TRIM(path)//"%AD_LANGEVIN%CHI")
    1059            0 :                CALL section_vals_set_subs_vals(input_file, TRIM(path)//"%AD_LANGEVIN%CHI", section)
    1060            0 :                section => section_vals_get_subs_vals(restart_file, TRIM(path)//"%AD_LANGEVIN%MASS")
    1061          134 :                CALL section_vals_set_subs_vals(input_file, TRIM(path)//"%AD_LANGEVIN%MASS", section)
    1062              :             END SELECT
    1063              :          ELSE
    1064            0 :             IF (input_type /= restart_type) THEN
    1065              :                CALL cp_warn(__LOCATION__, &
    1066              :                             "Requested to restart thermostat: "//TRIM(path)//". The thermostat "// &
    1067              :                             "specified in the input file and the information present in the restart "// &
    1068              :                             "file do not match the same type of thermostat! Restarting is not possible! "// &
    1069            0 :                             "Thermostat will not be restarted! ")
    1070              :             END IF
    1071            0 :             IF (input_region /= restart_region) THEN
    1072              :                CALL cp_warn(__LOCATION__, &
    1073              :                             "Requested to restart thermostat: "//TRIM(path)//". The thermostat "// &
    1074              :                             "specified in the input file and the information present in the restart "// &
    1075              :                             "file do not match the same type of REGION! Restarting is not possible! "// &
    1076            0 :                             "Thermostat will not be restarted! ")
    1077              :             END IF
    1078              :          END IF
    1079              :       END IF
    1080          274 :    END SUBROUTINE restart_thermostat
    1081              : 
    1082              : ! **************************************************************************************************
    1083              : !> \brief Checks if there are the proper conditions to do a restart
    1084              : !> \param input_file the input file to initialize
    1085              : !> \param restart_file ...
    1086              : !> \param tag_section ...
    1087              : !> \return ...
    1088              : !> \author teo
    1089              : ! **************************************************************************************************
    1090        13836 :    FUNCTION check_restart(input_file, restart_file, tag_section) RESULT(do_restart)
    1091              :       TYPE(section_vals_type), POINTER                   :: input_file, restart_file
    1092              :       CHARACTER(LEN=*), INTENT(IN)                       :: tag_section
    1093              :       LOGICAL                                            :: do_restart
    1094              : 
    1095              :       CHARACTER(len=*), PARAMETER                        :: routineN = 'check_restart'
    1096              : 
    1097              :       INTEGER                                            :: handle
    1098              :       LOGICAL                                            :: explicit1, explicit2
    1099              :       TYPE(section_vals_type), POINTER                   :: work_section
    1100              : 
    1101         4612 :       CALL timeset(routineN, handle)
    1102         4612 :       NULLIFY (work_section)
    1103         4612 :       work_section => section_vals_get_subs_vals(input_file, TRIM(tag_section))
    1104         4612 :       CALL section_vals_get(work_section, explicit=explicit1)
    1105         4612 :       work_section => section_vals_get_subs_vals(restart_file, TRIM(tag_section))
    1106         4612 :       CALL section_vals_get(work_section, explicit=explicit2)
    1107              : 
    1108         4612 :       do_restart = explicit1 .AND. explicit2
    1109         4612 :       CALL timestop(handle)
    1110         4612 :    END FUNCTION check_restart
    1111              : 
    1112              : ! **************************************************************************************************
    1113              : !> \brief Removes section used to restart a calculation from an
    1114              : !>      input file in memory
    1115              : !> \param input_file the input file to initialize
    1116              : !> \author teo
    1117              : ! **************************************************************************************************
    1118         7292 :    SUBROUTINE remove_restart_info(input_file)
    1119              :       TYPE(section_vals_type), POINTER                   :: input_file
    1120              : 
    1121              :       CHARACTER(len=*), PARAMETER :: routineN = 'remove_restart_info'
    1122              : 
    1123              :       INTEGER                                            :: handle, iforce_eval, nforce_eval1
    1124              :       LOGICAL                                            :: explicit1
    1125              :       TYPE(section_vals_type), POINTER                   :: md_section, motion_section, section1, &
    1126              :                                                             section_to_delete, sections1, &
    1127              :                                                             work_section
    1128              : 
    1129         1823 :       CALL timeset(routineN, handle)
    1130              : 
    1131         1823 :       NULLIFY (work_section)
    1132         1823 :       section_to_delete => section_vals_get_subs_vals(input_file, "EXT_RESTART")
    1133         1823 :       CALL section_vals_remove_values(section_to_delete)
    1134         1823 :       sections1 => section_vals_get_subs_vals(input_file, "FORCE_EVAL")
    1135         1823 :       CALL section_vals_get(sections1, n_repetition=nforce_eval1)
    1136              : 
    1137         3756 :       DO iforce_eval = 1, nforce_eval1
    1138         1933 :          section1 => section_vals_get_subs_vals3(sections1, "SUBSYS", i_rep_section=iforce_eval)
    1139         1933 :          section_to_delete => section_vals_get_subs_vals(section1, "COORD")
    1140         1933 :          CALL section_vals_remove_values(section_to_delete)
    1141         1933 :          section_to_delete => section_vals_get_subs_vals(section1, "VELOCITY")
    1142         3756 :          CALL section_vals_remove_values(section_to_delete)
    1143              :       END DO
    1144              : 
    1145         1823 :       motion_section => section_vals_get_subs_vals(input_file, "MOTION")
    1146         1823 :       md_section => section_vals_get_subs_vals(motion_section, "MD")
    1147         1823 :       CALL section_vals_get(md_section, explicit=explicit1)
    1148         1823 :       IF (explicit1) THEN
    1149         1763 :          CALL section_vals_val_unset(md_section, "STEP_START_VAL")
    1150         1763 :          CALL section_vals_val_unset(md_section, "TIME_START_VAL")
    1151         1763 :          CALL section_vals_val_unset(md_section, "ECONS_START_VAL")
    1152              :       END IF
    1153         1823 :       work_section => section_vals_get_subs_vals(motion_section, "FREE_ENERGY%METADYN")
    1154         1823 :       CALL section_vals_get(work_section, explicit=explicit1)
    1155         1823 :       IF (explicit1) THEN
    1156          166 :          CALL section_vals_val_unset(motion_section, "FREE_ENERGY%METADYN%STEP_START_VAL")
    1157          166 :          CALL section_vals_val_unset(motion_section, "FREE_ENERGY%METADYN%NHILLS_START_VAL")
    1158              :       END IF
    1159         1823 :       section_to_delete => section_vals_get_subs_vals(motion_section, "BAND%REPLICA")
    1160         1823 :       CALL section_vals_remove_values(section_to_delete)
    1161         1823 :       section_to_delete => section_vals_get_subs_vals(md_section, "AVERAGES%RESTART_AVERAGES")
    1162         1823 :       CALL section_vals_remove_values(section_to_delete)
    1163         1823 :       section_to_delete => section_vals_get_subs_vals(md_section, "THERMOSTAT%NOSE%COORD")
    1164         1823 :       CALL section_vals_remove_values(section_to_delete)
    1165         1823 :       section_to_delete => section_vals_get_subs_vals(md_section, "THERMOSTAT%NOSE%VELOCITY")
    1166         1823 :       CALL section_vals_remove_values(section_to_delete)
    1167         1823 :       section_to_delete => section_vals_get_subs_vals(md_section, "THERMOSTAT%NOSE%MASS")
    1168         1823 :       CALL section_vals_remove_values(section_to_delete)
    1169         1823 :       section_to_delete => section_vals_get_subs_vals(md_section, "THERMOSTAT%NOSE%FORCE")
    1170         1823 :       CALL section_vals_remove_values(section_to_delete)
    1171         1823 :       section_to_delete => section_vals_get_subs_vals(md_section, "BAROSTAT%MASS")
    1172         1823 :       CALL section_vals_remove_values(section_to_delete)
    1173         1823 :       section_to_delete => section_vals_get_subs_vals(md_section, "BAROSTAT%VELOCITY")
    1174         1823 :       CALL section_vals_remove_values(section_to_delete)
    1175         1823 :       section_to_delete => section_vals_get_subs_vals(md_section, "BAROSTAT%THERMOSTAT%NOSE%COORD")
    1176         1823 :       CALL section_vals_remove_values(section_to_delete)
    1177         1823 :       section_to_delete => section_vals_get_subs_vals(md_section, "BAROSTAT%THERMOSTAT%NOSE%VELOCITY")
    1178         1823 :       CALL section_vals_remove_values(section_to_delete)
    1179         1823 :       section_to_delete => section_vals_get_subs_vals(md_section, "BAROSTAT%THERMOSTAT%NOSE%MASS")
    1180         1823 :       CALL section_vals_remove_values(section_to_delete)
    1181         1823 :       section_to_delete => section_vals_get_subs_vals(md_section, "BAROSTAT%THERMOSTAT%NOSE%FORCE")
    1182         1823 :       CALL section_vals_remove_values(section_to_delete)
    1183         1823 :       section_to_delete => section_vals_get_subs_vals(md_section, "SHELL%THERMOSTAT%NOSE%COORD")
    1184         1823 :       CALL section_vals_remove_values(section_to_delete)
    1185         1823 :       section_to_delete => section_vals_get_subs_vals(md_section, "SHELL%THERMOSTAT%NOSE%VELOCITY")
    1186         1823 :       CALL section_vals_remove_values(section_to_delete)
    1187         1823 :       section_to_delete => section_vals_get_subs_vals(md_section, "SHELL%THERMOSTAT%NOSE%MASS")
    1188         1823 :       CALL section_vals_remove_values(section_to_delete)
    1189         1823 :       section_to_delete => section_vals_get_subs_vals(md_section, "SHELL%THERMOSTAT%NOSE%FORCE")
    1190         1823 :       CALL section_vals_remove_values(section_to_delete)
    1191              :       ! Constrained/Restrained section
    1192         1823 :       section_to_delete => section_vals_get_subs_vals(motion_section, "CONSTRAINT%FIX_ATOM_RESTART")
    1193         1823 :       CALL section_vals_remove_values(section_to_delete)
    1194         1823 :       section_to_delete => section_vals_get_subs_vals(motion_section, "CONSTRAINT%COLVAR_RESTART")
    1195         1823 :       CALL section_vals_remove_values(section_to_delete)
    1196              :       ! Free energies restarts
    1197         1823 :       section_to_delete => section_vals_get_subs_vals(motion_section, "FREE_ENERGY%METADYN%SPAWNED_HILLS_POS")
    1198         1823 :       CALL section_vals_remove_values(section_to_delete)
    1199         1823 :       section_to_delete => section_vals_get_subs_vals(motion_section, "FREE_ENERGY%METADYN%SPAWNED_HILLS_SCALE")
    1200         1823 :       CALL section_vals_remove_values(section_to_delete)
    1201         1823 :       section_to_delete => section_vals_get_subs_vals(motion_section, "FREE_ENERGY%METADYN%SPAWNED_HILLS_HEIGHT")
    1202         1823 :       CALL section_vals_remove_values(section_to_delete)
    1203         1823 :       section_to_delete => section_vals_get_subs_vals(motion_section, "FREE_ENERGY%METADYN%SPAWNED_HILLS_INVDT")
    1204         1823 :       CALL section_vals_remove_values(section_to_delete)
    1205         1823 :       section_to_delete => section_vals_get_subs_vals(motion_section, "FREE_ENERGY%METADYN%EXT_LAGRANGE_SS0")
    1206         1823 :       CALL section_vals_remove_values(section_to_delete)
    1207         1823 :       section_to_delete => section_vals_get_subs_vals(motion_section, "FREE_ENERGY%METADYN%EXT_LAGRANGE_VVP")
    1208         1823 :       CALL section_vals_remove_values(section_to_delete)
    1209         1823 :       section_to_delete => section_vals_get_subs_vals(motion_section, "FREE_ENERGY%METADYN%EXT_LAGRANGE_SS")
    1210         1823 :       CALL section_vals_remove_values(section_to_delete)
    1211         1823 :       section_to_delete => section_vals_get_subs_vals(motion_section, "FREE_ENERGY%METADYN%EXT_LAGRANGE_FS")
    1212         1823 :       CALL section_vals_remove_values(section_to_delete)
    1213         1823 :       CALL timestop(handle)
    1214         1823 :    END SUBROUTINE remove_restart_info
    1215              : 
    1216              : ! **************************************************************************************************
    1217              : !> \brief This subroutine controls the defaults for the restartable quantities..
    1218              : !> \param r_section ...
    1219              : !> \author teo - University of Zurich - 09.2007 [tlaino]
    1220              : ! **************************************************************************************************
    1221          448 :    SUBROUTINE handle_defaults_restart(r_section)
    1222              :       TYPE(section_vals_type), POINTER                   :: r_section
    1223              : 
    1224              :       CHARACTER(len=*), PARAMETER :: routineN = 'handle_defaults_restart'
    1225              : 
    1226              :       INTEGER                                            :: handle, ik, nval
    1227              :       LOGICAL                                            :: restart_default
    1228              :       TYPE(keyword_type), POINTER                        :: keyword
    1229              :       TYPE(section_type), POINTER                        :: section
    1230              : 
    1231          224 :       CALL timeset(routineN, handle)
    1232          224 :       NULLIFY (keyword, section)
    1233          224 :       CALL section_vals_get(r_section, section=section)
    1234          224 :       CALL section_vals_val_get(r_section, "RESTART_DEFAULT", l_val=restart_default)
    1235         9184 :       DO ik = -1, section%n_keywords
    1236         8960 :          keyword => section%keywords(ik)%keyword
    1237         9184 :          IF (ASSOCIATED(keyword)) THEN
    1238         8512 :             IF (keyword%type_of_var == logical_t .AND. keyword%names(1) (1:8) == "RESTART_") THEN
    1239         7840 :                IF (TRIM(keyword%names(1)) == "RESTART_DEFAULT") CYCLE
    1240         7616 :                CALL section_vals_val_get(r_section, keyword%names(1), n_rep_val=nval)
    1241         7616 :                IF (nval == 0) THEN
    1242              :                   ! User didn't specify any value, use the value of the RESTART_DEFAULT keyword..
    1243         6608 :                   CALL section_vals_val_set(r_section, keyword%names(1), l_val=restart_default)
    1244              :                END IF
    1245              :             END IF
    1246              :          END IF
    1247              :       END DO
    1248          224 :       CALL timestop(handle)
    1249              : 
    1250          224 :    END SUBROUTINE handle_defaults_restart
    1251              : 
    1252              : END MODULE input_cp2k_check
        

Generated by: LCOV version 2.0-1