LCOV - code coverage report
Current view: top level - src - force_fields_input.F (source / functions) Hit Total Coverage
Test: CP2K Regtests (git:3130539) Lines: 1331 1447 92.0 %
Date: 2025-05-14 06:57:18 Functions: 38 42 90.5 %

          Line data    Source code
       1             : !--------------------------------------------------------------------------------------------------!
       2             : !   CP2K: A general program to perform molecular dynamics simulations                              !
       3             : !   Copyright 2000-2025 CP2K developers group <https://cp2k.org>                                   !
       4             : !                                                                                                  !
       5             : !   SPDX-License-Identifier: GPL-2.0-or-later                                                      !
       6             : !--------------------------------------------------------------------------------------------------!
       7             : 
       8             : ! **************************************************************************************************
       9             : !> \par History
      10             : !>      Subroutine input_torsions changed (DG) 05-Dec-2000
      11             : !>      Output formats changed (DG) 05-Dec-2000
      12             : !>      JGH (26-01-2002) : force field parameters stored in tables, not in
      13             : !>        matrices. Input changed to have parameters labeled by the position
      14             : !>        and not atom pairs (triples etc)
      15             : !>      Teo (11.2005) : Moved all information on force field  pair_potential to
      16             : !>                      a much lighter memory structure
      17             : !>      Teo 09.2006   : Split all routines force_field I/O in a separate file
      18             : !> \author CJM
      19             : ! **************************************************************************************************
      20             : MODULE force_fields_input
      21             :    USE ace_wrapper,                     ONLY: ace_model_initialize,&
      22             :                                               ace_model_type
      23             :    USE bibliography,                    ONLY: Clabaut2020,&
      24             :                                               Clabaut2021,&
      25             :                                               Siepmann1995,&
      26             :                                               Tersoff1988,&
      27             :                                               Tosi1964a,&
      28             :                                               Tosi1964b,&
      29             :                                               Yamada2000,&
      30             :                                               cite_reference
      31             :    USE cp_files,                        ONLY: discover_file
      32             :    USE cp_linked_list_input,            ONLY: cp_sll_val_next,&
      33             :                                               cp_sll_val_type
      34             :    USE cp_log_handling,                 ONLY: cp_get_default_logger,&
      35             :                                               cp_logger_type,&
      36             :                                               cp_to_string
      37             :    USE cp_output_handling,              ONLY: cp_print_key_finished_output,&
      38             :                                               cp_print_key_unit_nr
      39             :    USE cp_parser_methods,               ONLY: parser_get_next_line
      40             :    USE cp_parser_types,                 ONLY: cp_parser_type,&
      41             :                                               parser_create,&
      42             :                                               parser_release
      43             :    USE cp_units,                        ONLY: cp_unit_to_cp2k
      44             :    USE damping_dipole_types,            ONLY: damping_info_type
      45             :    USE force_field_kind_types,          ONLY: do_ff_amber,&
      46             :                                               do_ff_charmm,&
      47             :                                               do_ff_g87,&
      48             :                                               do_ff_g96,&
      49             :                                               do_ff_opls,&
      50             :                                               do_ff_undef,&
      51             :                                               legendre_data_type
      52             :    USE force_field_types,               ONLY: force_field_type,&
      53             :                                               input_info_type
      54             :    USE force_fields_util,               ONLY: get_generic_info
      55             :    USE input_section_types,             ONLY: section_vals_get,&
      56             :                                               section_vals_get_subs_vals,&
      57             :                                               section_vals_list_get,&
      58             :                                               section_vals_type,&
      59             :                                               section_vals_val_get
      60             :    USE input_val_types,                 ONLY: val_get,&
      61             :                                               val_type
      62             :    USE kinds,                           ONLY: default_path_length,&
      63             :                                               default_string_length,&
      64             :                                               dp
      65             :    USE mathconstants,                   ONLY: pi
      66             :    USE mathlib,                         ONLY: invert_matrix
      67             :    USE memory_utilities,                ONLY: reallocate
      68             :    USE message_passing,                 ONLY: mp_para_env_type
      69             :    USE pair_potential_types,            ONLY: &
      70             :         ace_type, allegro_pot_type, allegro_type, b4_type, bm_type, deepmd_type, &
      71             :         do_potential_single_allocation, ea_type, eam_pot_type, ft_pot_type, ft_type, ftd_type, &
      72             :         gal21_type, gal_type, gp_type, gw_type, ip_type, ipbv_pot_type, lj_charmm_type, &
      73             :         nequip_pot_type, nequip_type, no_potential_single_allocation, pair_potential_p_type, &
      74             :         pair_potential_reallocate, potential_single_allocation, quip_type, siepmann_type, &
      75             :         tab_pot_type, tab_type, tersoff_type, wl_type
      76             :    USE shell_potential_types,           ONLY: shell_p_create,&
      77             :                                               shell_p_type
      78             :    USE string_utilities,                ONLY: uppercase
      79             :    USE torch_api,                       ONLY: torch_allow_tf32,&
      80             :                                               torch_model_read_metadata
      81             : #include "./base/base_uses.f90"
      82             : 
      83             :    IMPLICIT NONE
      84             : 
      85             :    CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'force_fields_input'
      86             : 
      87             :    PRIVATE
      88             :    PUBLIC :: read_force_field_section, &
      89             :              read_lj_section, &
      90             :              read_wl_section, &
      91             :              read_gd_section, &
      92             :              read_gp_section, &
      93             :              read_chrg_section
      94             : 
      95             : CONTAINS
      96             : 
      97             : ! **************************************************************************************************
      98             : !> \brief Reads the force_field input section
      99             : !> \param ff_section ...
     100             : !> \param mm_section ...
     101             : !> \param ff_type ...
     102             : !> \param para_env ...
     103             : !> \author teo
     104             : ! **************************************************************************************************
     105       37002 :    SUBROUTINE read_force_field_section1(ff_section, mm_section, ff_type, para_env)
     106             :       TYPE(section_vals_type), POINTER                   :: ff_section, mm_section
     107             :       TYPE(force_field_type), INTENT(INOUT)              :: ff_type
     108             :       TYPE(mp_para_env_type), POINTER                    :: para_env
     109             : 
     110             :       CHARACTER(LEN=default_string_length), &
     111        2643 :          DIMENSION(:), POINTER                           :: atm_names
     112             :       INTEGER :: nace, nallegro, nb4, nbends, nbm, nbmhft, nbmhftd, nbonds, nchg, ndeepmd, neam, &
     113             :          ngal, ngal21, ngd, ngp, nimpr, nipbv, nlj, nnequip, nopbend, nquip, nshell, nsiepmann, &
     114             :          ntab, ntersoff, ntors, ntot, nubs, nwl
     115             :       LOGICAL                                            :: explicit, unique_spline
     116             :       REAL(KIND=dp)                                      :: min_eps_spline_allowed
     117             :       TYPE(input_info_type), POINTER                     :: inp_info
     118             :       TYPE(section_vals_type), POINTER                   :: tmp_section, tmp_section2
     119             : 
     120             :       INTEGER::i
     121             : 
     122        2643 :       NULLIFY (tmp_section, tmp_section2)
     123        2643 :       inp_info => ff_type%inp_info
     124        2643 :       CALL section_vals_val_get(ff_section, "PARMTYPE", i_val=ff_type%ff_type)
     125        2643 :       CALL section_vals_val_get(ff_section, "EI_SCALE14", r_val=ff_type%ei_scale14)
     126        2643 :       CALL section_vals_val_get(ff_section, "VDW_SCALE14", r_val=ff_type%vdw_scale14)
     127        2643 :       CALL section_vals_val_get(ff_section, "SPLINE%RCUT_NB", r_val=ff_type%rcut_nb)
     128        2643 :       CALL section_vals_val_get(ff_section, "SPLINE%R0_NB", r_val=ff_type%rlow_nb)
     129        2643 :       CALL section_vals_val_get(ff_section, "SPLINE%EPS_SPLINE", r_val=ff_type%eps_spline)
     130        2643 :       CALL section_vals_val_get(ff_section, "SPLINE%EMAX_SPLINE", r_val=ff_type%emax_spline)
     131        2643 :       CALL section_vals_val_get(ff_section, "SPLINE%EMAX_ACCURACY", r_val=ff_type%max_energy)
     132        2643 :       CALL section_vals_val_get(ff_section, "SPLINE%NPOINTS", i_val=ff_type%npoints)
     133        2643 :       CALL section_vals_val_get(ff_section, "IGNORE_MISSING_CRITICAL_PARAMS", l_val=ff_type%ignore_missing_critical)
     134        2643 :       CPASSERT(ff_type%max_energy <= ff_type%emax_spline)
     135             :       ! Read the parameter file name only if the force field type requires it..
     136        3549 :       SELECT CASE (ff_type%ff_type)
     137             :       CASE (do_ff_charmm, do_ff_amber, do_ff_g96, do_ff_g87)
     138         906 :          CALL section_vals_val_get(ff_section, "PARM_FILE_NAME", c_val=ff_type%ff_file_name)
     139         906 :          IF (TRIM(ff_type%ff_file_name) == "") &
     140           0 :             CPABORT("Force Field Parameter's filename is empty! Please check your input file.")
     141             :       CASE (do_ff_undef)
     142             :          ! Do Nothing
     143             :       CASE DEFAULT
     144        2643 :          CPABORT("Force field type not implemented")
     145             :       END SELECT
     146             :       ! Numerical Accuracy:
     147             :       ! the factors here should depend on the energy and on the shape of each potential mapped
     148             :       ! with splines. this would make everything un-necessarily complicated. Let's just be safe
     149             :       ! and assume that we cannot achieve an accuracy on the spline 2 orders of magnitude more
     150             :       ! than the smallest representable number (taking into account also the max_energy for the
     151             :       ! spline generation
     152        2643 :       min_eps_spline_allowed = 20.0_dp*MAX(ff_type%max_energy, 10.0_dp)*EPSILON(0.0_dp)
     153        2643 :       IF (ff_type%eps_spline < min_eps_spline_allowed) THEN
     154             :          CALL cp_warn(__LOCATION__, &
     155             :                       "Requested spline accuracy ("//TRIM(cp_to_string(ff_type%eps_spline))//" ) "// &
     156             :                       "is smaller than the minimum value allowed ("//TRIM(cp_to_string(min_eps_spline_allowed))// &
     157             :                       " ) with the present machine precision ("//TRIM(cp_to_string(EPSILON(0.0_dp)))//" ). "// &
     158           0 :                       "New EPS_SPLINE value ("//TRIM(cp_to_string(min_eps_spline_allowed))//" ). ")
     159           0 :          ff_type%eps_spline = min_eps_spline_allowed
     160             :       END IF
     161        2643 :       CALL section_vals_val_get(ff_section, "SHIFT_CUTOFF", l_val=ff_type%shift_cutoff)
     162        2643 :       CALL section_vals_val_get(ff_section, "SPLINE%UNIQUE_SPLINE", l_val=unique_spline)
     163             :       ! Single spline
     164        2643 :       potential_single_allocation = no_potential_single_allocation
     165        2643 :       IF (unique_spline) potential_single_allocation = do_potential_single_allocation
     166             : 
     167        2643 :       CALL section_vals_val_get(ff_section, "MULTIPLE_POTENTIAL", l_val=ff_type%multiple_potential)
     168        2643 :       CALL section_vals_val_get(ff_section, "DO_NONBONDED", l_val=ff_type%do_nonbonded)
     169        2643 :       CALL section_vals_val_get(ff_section, "DO_ELECTROSTATICS", l_val=ff_type%do_electrostatics)
     170        2643 :       tmp_section => section_vals_get_subs_vals(ff_section, "NONBONDED")
     171        2643 :       CALL section_vals_get(tmp_section, explicit=explicit)
     172        2643 :       IF (explicit .AND. ff_type%do_nonbonded) THEN
     173        1737 :          tmp_section2 => section_vals_get_subs_vals(tmp_section, "LENNARD-JONES")
     174        1737 :          CALL section_vals_get(tmp_section2, explicit=explicit, n_repetition=nlj)
     175        1737 :          ntot = 0
     176        1737 :          IF (explicit) THEN
     177         974 :             CALL pair_potential_reallocate(inp_info%nonbonded, 1, ntot + nlj, lj_charmm=.TRUE.)
     178         974 :             CALL read_lj_section(inp_info%nonbonded, tmp_section2, ntot)
     179             :          END IF
     180             : 
     181        1737 :          tmp_section2 => section_vals_get_subs_vals(tmp_section, "WILLIAMS")
     182        1737 :          CALL section_vals_get(tmp_section2, explicit=explicit, n_repetition=nwl)
     183        1737 :          ntot = nlj
     184        1737 :          IF (explicit) THEN
     185         373 :             CALL pair_potential_reallocate(inp_info%nonbonded, 1, ntot + nwl, williams=.TRUE.)
     186         373 :             CALL read_wl_section(inp_info%nonbonded, tmp_section2, ntot)
     187             :          END IF
     188             : 
     189        1737 :          tmp_section2 => section_vals_get_subs_vals(tmp_section, "EAM")
     190        1737 :          CALL section_vals_get(tmp_section2, explicit=explicit, n_repetition=neam)
     191        1737 :          ntot = nlj + nwl
     192        1737 :          IF (explicit) THEN
     193          12 :             CALL pair_potential_reallocate(inp_info%nonbonded, 1, ntot + neam, eam=.TRUE.)
     194          12 :             CALL read_eam_section(inp_info%nonbonded, tmp_section2, ntot, para_env, mm_section)
     195             :          END IF
     196             : 
     197        1737 :          tmp_section2 => section_vals_get_subs_vals(tmp_section, "GOODWIN")
     198        1737 :          CALL section_vals_get(tmp_section2, explicit=explicit, n_repetition=ngd)
     199        1737 :          ntot = nlj + nwl + neam
     200        1737 :          IF (explicit) THEN
     201           0 :             CALL pair_potential_reallocate(inp_info%nonbonded, 1, ntot + ngd, goodwin=.TRUE.)
     202           0 :             CALL read_gd_section(inp_info%nonbonded, tmp_section2, ntot)
     203             :          END IF
     204             : 
     205        1737 :          tmp_section2 => section_vals_get_subs_vals(tmp_section, "IPBV")
     206        1737 :          CALL section_vals_get(tmp_section2, explicit=explicit, n_repetition=nipbv)
     207        1737 :          ntot = nlj + nwl + neam + ngd
     208        1737 :          IF (explicit) THEN
     209          16 :             CALL pair_potential_reallocate(inp_info%nonbonded, 1, ntot + nipbv, ipbv=.TRUE.)
     210          16 :             CALL read_ipbv_section(inp_info%nonbonded, tmp_section2, ntot)
     211             :          END IF
     212             : 
     213        1737 :          tmp_section2 => section_vals_get_subs_vals(tmp_section, "BMHFT")
     214        1737 :          CALL section_vals_get(tmp_section2, explicit=explicit, n_repetition=nbmhft)
     215        1737 :          ntot = nlj + nwl + neam + ngd + nipbv
     216        1737 :          IF (explicit) THEN
     217           4 :             CALL pair_potential_reallocate(inp_info%nonbonded, 1, ntot + nbmhft, bmhft=.TRUE.)
     218           4 :             CALL read_bmhft_section(inp_info%nonbonded, tmp_section2, ntot)
     219             :          END IF
     220             : 
     221        1737 :          tmp_section2 => section_vals_get_subs_vals(tmp_section, "BMHFTD")
     222        1737 :          CALL section_vals_get(tmp_section2, explicit=explicit, n_repetition=nbmhftd)
     223        1737 :          ntot = nlj + nwl + neam + ngd + nipbv + nbmhft
     224        1737 :          IF (explicit) THEN
     225          18 :             CALL pair_potential_reallocate(inp_info%nonbonded, 1, ntot + nbmhftd, bmhftd=.TRUE.)
     226          18 :             CALL read_bmhftd_section(inp_info%nonbonded, tmp_section2, ntot)
     227             :          END IF
     228             : 
     229        1737 :          tmp_section2 => section_vals_get_subs_vals(tmp_section, "BUCK4RANGES")
     230        1737 :          CALL section_vals_get(tmp_section2, explicit=explicit, n_repetition=nb4)
     231        1737 :          ntot = nlj + nwl + neam + ngd + nipbv + nbmhft + nbmhftd
     232        1737 :          IF (explicit) THEN
     233         262 :             CALL pair_potential_reallocate(inp_info%nonbonded, 1, ntot + nb4, buck4r=.TRUE.)
     234         262 :             CALL read_b4_section(inp_info%nonbonded, tmp_section2, ntot)
     235             :          END IF
     236             : 
     237        1737 :          tmp_section2 => section_vals_get_subs_vals(tmp_section, "BUCKMORSE")
     238        1737 :          CALL section_vals_get(tmp_section2, explicit=explicit, n_repetition=nbm)
     239        1737 :          ntot = nlj + nwl + neam + ngd + nipbv + nbmhft + nbmhftd + nb4
     240        1737 :          IF (explicit) THEN
     241           6 :             CALL pair_potential_reallocate(inp_info%nonbonded, 1, ntot + nbm, buckmo=.TRUE.)
     242           6 :             CALL read_bm_section(inp_info%nonbonded, tmp_section2, ntot)
     243             :          END IF
     244             : 
     245        1737 :          tmp_section2 => section_vals_get_subs_vals(tmp_section, "GENPOT")
     246        1737 :          CALL section_vals_get(tmp_section2, explicit=explicit, n_repetition=ngp)
     247        1737 :          ntot = nlj + nwl + neam + ngd + nipbv + nbmhft + nbmhftd + nb4 + nbm
     248        1737 :          IF (explicit) THEN
     249         308 :             CALL pair_potential_reallocate(inp_info%nonbonded, 1, ntot + ngp, gp=.TRUE.)
     250         308 :             CALL read_gp_section(inp_info%nonbonded, tmp_section2, ntot)
     251             :          END IF
     252        1737 :          tmp_section2 => section_vals_get_subs_vals(tmp_section, "TERSOFF")
     253        1737 :          CALL section_vals_get(tmp_section2, explicit=explicit, n_repetition=ntersoff)
     254        1737 :          ntot = nlj + nwl + neam + ngd + nipbv + nbmhft + nbmhftd + nb4 + nbm + ngp
     255        1737 :          IF (explicit) THEN
     256          40 :             CALL pair_potential_reallocate(inp_info%nonbonded, 1, ntot + ntersoff, tersoff=.TRUE.)
     257          40 :             CALL read_tersoff_section(inp_info%nonbonded, tmp_section2, ntot, tmp_section2)
     258             :          END IF
     259             : 
     260        1737 :          tmp_section2 => section_vals_get_subs_vals(tmp_section, "GAL19")
     261        1737 :          CALL section_vals_get(tmp_section2, explicit=explicit, n_repetition=ngal)
     262        1737 :          ntot = nlj + nwl + neam + ngd + nipbv + nbmhft + nbmhftd + nb4 + nbm + ngp + ntersoff
     263        1737 :          IF (explicit) THEN
     264           1 :             CALL pair_potential_reallocate(inp_info%nonbonded, 1, ntot + ngal, gal=.TRUE.)
     265           1 :             CALL read_gal_section(inp_info%nonbonded, tmp_section2, ntot, tmp_section2)
     266             :          END IF
     267             : 
     268        1737 :          tmp_section2 => section_vals_get_subs_vals(tmp_section, "GAL21")
     269        1737 :          CALL section_vals_get(tmp_section2, explicit=explicit, n_repetition=ngal21)
     270        1737 :          ntot = nlj + nwl + neam + ngd + nipbv + nbmhft + nbmhftd + nb4 + nbm + ngp + ntersoff + ngal
     271        1737 :          IF (explicit) THEN
     272           1 :             CALL pair_potential_reallocate(inp_info%nonbonded, 1, ntot + ngal21, gal21=.TRUE.)
     273           1 :             CALL read_gal21_section(inp_info%nonbonded, tmp_section2, ntot, tmp_section2)
     274             :          END IF
     275             : 
     276        1737 :          tmp_section2 => section_vals_get_subs_vals(tmp_section, "SIEPMANN")
     277        1737 :          CALL section_vals_get(tmp_section2, explicit=explicit, n_repetition=nsiepmann)
     278        1737 :          ntot = nlj + nwl + neam + ngd + nipbv + nbmhft + nbmhftd + nb4 + nbm + ngp + ntersoff + ngal + ngal21
     279        1737 :          IF (explicit) THEN
     280           5 :             CALL pair_potential_reallocate(inp_info%nonbonded, 1, ntot + nsiepmann, siepmann=.TRUE.)
     281           5 :             CALL read_siepmann_section(inp_info%nonbonded, tmp_section2, ntot, tmp_section2)
     282             :          END IF
     283             : 
     284        1737 :          tmp_section2 => section_vals_get_subs_vals(tmp_section, "quip")
     285        1737 :          CALL section_vals_get(tmp_section2, explicit=explicit, n_repetition=nquip)
     286        1737 :          ntot = nlj + nwl + neam + ngd + nipbv + nbmhft + nbmhftd + nb4 + nbm + ngp + ntersoff + ngal + ngal21 + nsiepmann
     287        1737 :          IF (explicit) THEN
     288           0 :             CALL pair_potential_reallocate(inp_info%nonbonded, 1, ntot + nquip, quip=.TRUE.)
     289           0 :             CALL read_quip_section(inp_info%nonbonded, tmp_section2, ntot)
     290             :          END IF
     291             : 
     292        1737 :          tmp_section2 => section_vals_get_subs_vals(tmp_section, "nequip")
     293        1737 :          CALL section_vals_get(tmp_section2, explicit=explicit, n_repetition=nnequip)
     294             :          ntot = nlj + nwl + neam + ngd + nipbv + nbmhft + nbmhftd + nb4 + nbm + ngp + ntersoff + ngal + ngal21 + nsiepmann + &
     295        1737 :                 nquip
     296        1737 :          IF (explicit) THEN
     297             :             ! avoid repeating the nequip section for each pair
     298           4 :             CALL section_vals_val_get(tmp_section2, "ATOMS", c_vals=atm_names)
     299           4 :             nnequip = nnequip - 1 + SIZE(atm_names) + (SIZE(atm_names)*SIZE(atm_names) - SIZE(atm_names))/2
     300           4 :             CALL pair_potential_reallocate(inp_info%nonbonded, 1, ntot + nnequip, nequip=.TRUE.)
     301           4 :             CALL read_nequip_section(inp_info%nonbonded, tmp_section2, ntot)
     302             :          END IF
     303             : 
     304        1737 :          tmp_section2 => section_vals_get_subs_vals(tmp_section, "allegro")
     305        1737 :          CALL section_vals_get(tmp_section2, explicit=explicit, n_repetition=nallegro)
     306             :          ntot = nlj + nwl + neam + ngd + nipbv + nbmhft + nbmhftd + nb4 + nbm + ngp + ntersoff + ngal + ngal21 + nsiepmann + &
     307        1737 :                 nquip + nnequip
     308        1737 :          IF (explicit) THEN
     309             :             ! avoid repeating the allegro section for each pair
     310           4 :             CALL section_vals_val_get(tmp_section2, "ATOMS", c_vals=atm_names)
     311           4 :             nallegro = nallegro - 1 + SIZE(atm_names) + (SIZE(atm_names)*SIZE(atm_names) - SIZE(atm_names))/2
     312           4 :             CALL pair_potential_reallocate(inp_info%nonbonded, 1, ntot + nallegro, allegro=.TRUE.)
     313           4 :             CALL read_allegro_section(inp_info%nonbonded, tmp_section2, ntot)
     314             :          END IF
     315             : 
     316        1737 :          tmp_section2 => section_vals_get_subs_vals(tmp_section, "TABPOT")
     317        1737 :          CALL section_vals_get(tmp_section2, explicit=explicit, n_repetition=ntab)
     318             :          ntot = nlj + nwl + neam + ngd + nipbv + nbmhft + nbmhftd + nb4 + nbm + ngp + ntersoff + ngal + ngal21 + nsiepmann + &
     319        1737 :                 nquip + nnequip + nallegro
     320        1737 :          IF (explicit) THEN
     321           8 :             CALL pair_potential_reallocate(inp_info%nonbonded, 1, ntot + ntab, tab=.TRUE.)
     322           8 :             CALL read_tabpot_section(inp_info%nonbonded, tmp_section2, ntot, para_env, mm_section)
     323             :          END IF
     324             : 
     325        1737 :          tmp_section2 => section_vals_get_subs_vals(tmp_section, "DEEPMD")
     326        1737 :          CALL section_vals_get(tmp_section2, explicit=explicit, n_repetition=ndeepmd)
     327             :          ntot = nlj + nwl + neam + ngd + nipbv + nbmhft + nbmhftd + nb4 + nbm + ngp + ntersoff + ngal + ngal21 + nsiepmann + &
     328        1737 :                 nquip + nnequip + nallegro + ntab
     329        1737 :          IF (explicit) THEN
     330             :             ! avoid repeating the deepmd section for each pair
     331           2 :             CALL section_vals_val_get(tmp_section2, "ATOMS", c_vals=atm_names)
     332           2 :             ndeepmd = ndeepmd - 1 + SIZE(atm_names) + (SIZE(atm_names)*SIZE(atm_names) - SIZE(atm_names))/2
     333           2 :             CALL pair_potential_reallocate(inp_info%nonbonded, 1, ntot + ndeepmd, deepmd=.TRUE.)
     334           2 :             CALL read_deepmd_section(inp_info%nonbonded, tmp_section2, ntot)
     335             :          END IF
     336             : 
     337        1737 :          tmp_section2 => section_vals_get_subs_vals(tmp_section, "ACE")
     338        1737 :          CALL section_vals_get(tmp_section2, explicit=explicit, n_repetition=nace)
     339             :          ntot = nlj + nwl + neam + ngd + nipbv + nbmhft + nbmhftd + nb4 + nbm + ngp + ntersoff + ngal + ngal21 + nsiepmann + &
     340        1737 :                 nquip + nnequip + nallegro + ntab + ndeepmd
     341        1737 :          IF (explicit) THEN
     342             :             ! avoid repeating the ace section for each pair
     343           6 :             CALL section_vals_val_get(tmp_section2, "ATOMS", c_vals=atm_names)
     344           6 :             nace = nace - 1 + SIZE(atm_names) + (SIZE(atm_names)*SIZE(atm_names) - SIZE(atm_names))/2
     345           6 :             CALL pair_potential_reallocate(inp_info%nonbonded, 1, ntot + nace, ace=.TRUE.)
     346           6 :             CALL read_ace_section(inp_info%nonbonded, tmp_section2, ntot)
     347             :          END IF
     348             : 
     349             :       END IF
     350             : 
     351        2643 :       tmp_section => section_vals_get_subs_vals(ff_section, "NONBONDED14")
     352        2643 :       CALL section_vals_get(tmp_section, explicit=explicit)
     353        2643 :       IF (explicit .AND. ff_type%do_nonbonded) THEN
     354         274 :          tmp_section2 => section_vals_get_subs_vals(tmp_section, "LENNARD-JONES")
     355         274 :          CALL section_vals_get(tmp_section2, explicit=explicit, n_repetition=nlj)
     356         274 :          ntot = 0
     357         274 :          IF (explicit) THEN
     358          12 :             CALL pair_potential_reallocate(inp_info%nonbonded14, 1, ntot + nlj, lj_charmm=.TRUE.)
     359          12 :             CALL read_lj_section(inp_info%nonbonded14, tmp_section2, ntot)
     360             :          END IF
     361         274 :          tmp_section2 => section_vals_get_subs_vals(tmp_section, "WILLIAMS")
     362         274 :          CALL section_vals_get(tmp_section2, explicit=explicit, n_repetition=nwl)
     363         274 :          ntot = nlj
     364         274 :          IF (explicit) THEN
     365           0 :             CALL pair_potential_reallocate(inp_info%nonbonded14, 1, ntot + nwl, williams=.TRUE.)
     366           0 :             CALL read_wl_section(inp_info%nonbonded14, tmp_section2, ntot)
     367             :          END IF
     368         274 :          tmp_section2 => section_vals_get_subs_vals(tmp_section, "GOODWIN")
     369         274 :          CALL section_vals_get(tmp_section2, explicit=explicit, n_repetition=ngd)
     370         274 :          ntot = nlj + nwl
     371         274 :          IF (explicit) THEN
     372           0 :             CALL pair_potential_reallocate(inp_info%nonbonded14, 1, ntot + ngd, goodwin=.TRUE.)
     373           0 :             CALL read_gd_section(inp_info%nonbonded14, tmp_section2, ntot)
     374             :          END IF
     375         274 :          tmp_section2 => section_vals_get_subs_vals(tmp_section, "GENPOT")
     376         274 :          CALL section_vals_get(tmp_section2, explicit=explicit, n_repetition=ngp)
     377         274 :          ntot = nlj + nwl + ngd
     378         274 :          IF (explicit) THEN
     379         262 :             CALL pair_potential_reallocate(inp_info%nonbonded14, 1, ntot + ngp, gp=.TRUE.)
     380         262 :             CALL read_gp_section(inp_info%nonbonded14, tmp_section2, ntot)
     381             :          END IF
     382             :       END IF
     383             : 
     384        2643 :       tmp_section => section_vals_get_subs_vals(ff_section, "CHARGE")
     385        2643 :       CALL section_vals_get(tmp_section, explicit=explicit, n_repetition=nchg)
     386        2643 :       IF (explicit) THEN
     387        2075 :          ntot = 0
     388        2075 :          CALL reallocate(inp_info%charge_atm, 1, nchg)
     389        2075 :          CALL reallocate(inp_info%charge, 1, nchg)
     390        2075 :          CALL read_chrg_section(inp_info%charge_atm, inp_info%charge, tmp_section, ntot)
     391             :       END IF
     392        2643 :       tmp_section => section_vals_get_subs_vals(ff_section, "DIPOLE")
     393        2643 :       CALL section_vals_get(tmp_section, explicit=explicit, n_repetition=nchg)
     394        2643 :       IF (explicit) THEN
     395          34 :          ntot = 0
     396          34 :          CALL reallocate(inp_info%apol_atm, 1, nchg)
     397          34 :          CALL reallocate(inp_info%apol, 1, nchg)
     398             :          CALL read_apol_section(inp_info%apol_atm, inp_info%apol, inp_info%damping_list, &
     399          34 :                                 tmp_section, ntot)
     400             :       END IF
     401        2643 :       tmp_section => section_vals_get_subs_vals(ff_section, "QUADRUPOLE")
     402        2643 :       CALL section_vals_get(tmp_section, explicit=explicit, n_repetition=nchg)
     403        2643 :       IF (explicit) THEN
     404           0 :          ntot = 0
     405           0 :          CALL reallocate(inp_info%cpol_atm, 1, nchg)
     406           0 :          CALL reallocate(inp_info%cpol, 1, nchg)
     407           0 :          CALL read_cpol_section(inp_info%cpol_atm, inp_info%cpol, tmp_section, ntot)
     408             :       END IF
     409        2643 :       tmp_section => section_vals_get_subs_vals(ff_section, "SHELL")
     410        2643 :       CALL section_vals_get(tmp_section, explicit=explicit, n_repetition=nshell)
     411        2643 :       IF (explicit) THEN
     412         256 :          ntot = 0
     413         256 :          CALL shell_p_create(inp_info%shell_list, nshell)
     414         256 :          CALL read_shell_section(inp_info%shell_list, tmp_section, ntot)
     415             :       END IF
     416             : 
     417        2643 :       tmp_section => section_vals_get_subs_vals(ff_section, "BOND")
     418        2643 :       CALL section_vals_get(tmp_section, explicit=explicit, n_repetition=nbonds)
     419        2643 :       IF (explicit) THEN
     420         973 :          ntot = 0
     421         973 :          CALL reallocate(inp_info%bond_kind, 1, nbonds)
     422         973 :          CALL reallocate(inp_info%bond_a, 1, nbonds)
     423         973 :          CALL reallocate(inp_info%bond_b, 1, nbonds)
     424         973 :          CALL reallocate(inp_info%bond_k, 1, 3, 1, nbonds)
     425         973 :          CALL reallocate(inp_info%bond_r0, 1, nbonds)
     426         973 :          CALL reallocate(inp_info%bond_cs, 1, nbonds)
     427             :          CALL read_bonds_section(inp_info%bond_kind, inp_info%bond_a, inp_info%bond_b, inp_info%bond_k, &
     428         973 :                                  inp_info%bond_r0, inp_info%bond_cs, tmp_section, ntot)
     429             :       END IF
     430        2643 :       tmp_section => section_vals_get_subs_vals(ff_section, "BEND")
     431        2643 :       CALL section_vals_get(tmp_section, explicit=explicit, n_repetition=nbends)
     432        2643 :       IF (explicit) THEN
     433         937 :          ntot = 0
     434         937 :          CALL reallocate(inp_info%bend_kind, 1, nbends)
     435         937 :          CALL reallocate(inp_info%bend_a, 1, nbends)
     436         937 :          CALL reallocate(inp_info%bend_b, 1, nbends)
     437         937 :          CALL reallocate(inp_info%bend_c, 1, nbends)
     438         937 :          CALL reallocate(inp_info%bend_k, 1, nbends)
     439         937 :          CALL reallocate(inp_info%bend_theta0, 1, nbends)
     440         937 :          CALL reallocate(inp_info%bend_cb, 1, nbends)
     441         937 :          CALL reallocate(inp_info%bend_r012, 1, nbends)
     442         937 :          CALL reallocate(inp_info%bend_r032, 1, nbends)
     443         937 :          CALL reallocate(inp_info%bend_kbs12, 1, nbends)
     444         937 :          CALL reallocate(inp_info%bend_kbs32, 1, nbends)
     445         937 :          CALL reallocate(inp_info%bend_kss, 1, nbends)
     446         937 :          IF (ASSOCIATED(inp_info%bend_legendre)) THEN
     447           0 :             DO i = 1, SIZE(inp_info%bend_legendre)
     448           0 :                IF (ASSOCIATED(inp_info%bend_legendre(i)%coeffs)) THEN
     449           0 :                   DEALLOCATE (inp_info%bend_legendre(i)%coeffs)
     450           0 :                   NULLIFY (inp_info%bend_legendre(i)%coeffs)
     451             :                END IF
     452             :             END DO
     453           0 :             DEALLOCATE (inp_info%bend_legendre)
     454             :             NULLIFY (inp_info%bend_legendre)
     455             :          END IF
     456        4928 :          ALLOCATE (inp_info%bend_legendre(1:nbends))
     457        3054 :          DO i = 1, SIZE(inp_info%bend_legendre(1:nbends))
     458        2117 :             NULLIFY (inp_info%bend_legendre(i)%coeffs)
     459        3054 :             inp_info%bend_legendre(i)%order = 0
     460             :          END DO
     461             :          CALL read_bends_section(inp_info%bend_kind, inp_info%bend_a, inp_info%bend_b, inp_info%bend_c, &
     462             :                                  inp_info%bend_k, inp_info%bend_theta0, inp_info%bend_cb, &
     463             :                                  inp_info%bend_r012, inp_info%bend_r032, inp_info%bend_kbs12, &
     464             :                                  inp_info%bend_kbs32, inp_info%bend_kss, &
     465         937 :                                  inp_info%bend_legendre, tmp_section, ntot)
     466             :       END IF
     467        2643 :       tmp_section => section_vals_get_subs_vals(ff_section, "BEND")
     468        2643 :       CALL section_vals_get(tmp_section, explicit=explicit, n_repetition=nubs)
     469        2643 :       IF (explicit) THEN
     470         937 :          ntot = 0
     471         937 :          CALL reallocate(inp_info%ub_kind, 1, nubs)
     472         937 :          CALL reallocate(inp_info%ub_a, 1, nubs)
     473         937 :          CALL reallocate(inp_info%ub_b, 1, nubs)
     474         937 :          CALL reallocate(inp_info%ub_c, 1, nubs)
     475         937 :          CALL reallocate(inp_info%ub_k, 1, 3, 1, nubs)
     476         937 :          CALL reallocate(inp_info%ub_r0, 1, nubs)
     477             :          CALL read_ubs_section(inp_info%ub_kind, inp_info%ub_a, inp_info%ub_b, inp_info%ub_c, &
     478         937 :                                inp_info%ub_k, inp_info%ub_r0, tmp_section, ntot)
     479             :       END IF
     480        2643 :       tmp_section => section_vals_get_subs_vals(ff_section, "TORSION")
     481        2643 :       CALL section_vals_get(tmp_section, explicit=explicit, n_repetition=ntors)
     482        2643 :       IF (explicit) THEN
     483           6 :          ntot = 0
     484           6 :          CALL reallocate(inp_info%torsion_kind, 1, ntors)
     485           6 :          CALL reallocate(inp_info%torsion_a, 1, ntors)
     486           6 :          CALL reallocate(inp_info%torsion_b, 1, ntors)
     487           6 :          CALL reallocate(inp_info%torsion_c, 1, ntors)
     488           6 :          CALL reallocate(inp_info%torsion_d, 1, ntors)
     489           6 :          CALL reallocate(inp_info%torsion_k, 1, ntors)
     490           6 :          CALL reallocate(inp_info%torsion_m, 1, ntors)
     491           6 :          CALL reallocate(inp_info%torsion_phi0, 1, ntors)
     492             :          CALL read_torsions_section(inp_info%torsion_kind, inp_info%torsion_a, inp_info%torsion_b, &
     493             :                                     inp_info%torsion_c, inp_info%torsion_d, inp_info%torsion_k, inp_info%torsion_phi0, &
     494           6 :                                     inp_info%torsion_m, tmp_section, ntot)
     495             :       END IF
     496             : 
     497        2643 :       tmp_section => section_vals_get_subs_vals(ff_section, "IMPROPER")
     498        2643 :       CALL section_vals_get(tmp_section, explicit=explicit, n_repetition=nimpr)
     499        2643 :       IF (explicit) THEN
     500           8 :          ntot = 0
     501           8 :          CALL reallocate(inp_info%impr_kind, 1, nimpr)
     502           8 :          CALL reallocate(inp_info%impr_a, 1, nimpr)
     503           8 :          CALL reallocate(inp_info%impr_b, 1, nimpr)
     504           8 :          CALL reallocate(inp_info%impr_c, 1, nimpr)
     505           8 :          CALL reallocate(inp_info%impr_d, 1, nimpr)
     506           8 :          CALL reallocate(inp_info%impr_k, 1, nimpr)
     507           8 :          CALL reallocate(inp_info%impr_phi0, 1, nimpr)
     508             :          CALL read_improper_section(inp_info%impr_kind, inp_info%impr_a, inp_info%impr_b, &
     509             :                                     inp_info%impr_c, inp_info%impr_d, inp_info%impr_k, inp_info%impr_phi0, &
     510           8 :                                     tmp_section, ntot)
     511             :       END IF
     512             : 
     513        2643 :       tmp_section => section_vals_get_subs_vals(ff_section, "OPBEND")
     514        2643 :       CALL section_vals_get(tmp_section, explicit=explicit, n_repetition=nopbend)
     515        2643 :       IF (explicit) THEN
     516           2 :          ntot = 0
     517           2 :          CALL reallocate(inp_info%opbend_kind, 1, nopbend)
     518           2 :          CALL reallocate(inp_info%opbend_a, 1, nopbend)
     519           2 :          CALL reallocate(inp_info%opbend_b, 1, nopbend)
     520           2 :          CALL reallocate(inp_info%opbend_c, 1, nopbend)
     521           2 :          CALL reallocate(inp_info%opbend_d, 1, nopbend)
     522           2 :          CALL reallocate(inp_info%opbend_k, 1, nopbend)
     523           2 :          CALL reallocate(inp_info%opbend_phi0, 1, nopbend)
     524             :          CALL read_opbend_section(inp_info%opbend_kind, inp_info%opbend_a, inp_info%opbend_b, &
     525             :                                   inp_info%opbend_c, inp_info%opbend_d, inp_info%opbend_k, inp_info%opbend_phi0, &
     526           2 :                                   tmp_section, ntot)
     527             :       END IF
     528             : 
     529        2643 :    END SUBROUTINE read_force_field_section1
     530             : 
     531             : ! **************************************************************************************************
     532             : !> \brief Set up of the IPBV force fields
     533             : !> \param at1 ...
     534             : !> \param at2 ...
     535             : !> \param ipbv ...
     536             : !> \author teo
     537             : ! **************************************************************************************************
     538          48 :    SUBROUTINE set_IPBV_ff(at1, at2, ipbv)
     539             :       CHARACTER(LEN=*), INTENT(IN)                       :: at1, at2
     540             :       TYPE(ipbv_pot_type), POINTER                       :: ipbv
     541             : 
     542          48 :       IF ((at1(1:1) == 'O') .AND. (at2(1:1) == 'O')) THEN
     543          16 :          ipbv%rcore = 0.9_dp ! a.u.
     544          16 :          ipbv%m = -1.2226442563398141E+11_dp ! Kelvin/a.u.
     545          16 :          ipbv%b = 1.1791292385486696E+11_dp ! Hartree
     546             : 
     547             :          ! Hartree*a.u.^2
     548          16 :          ipbv%a(2) = 4.786380682394_dp
     549          16 :          ipbv%a(3) = -1543.407053545_dp
     550          16 :          ipbv%a(4) = 88783.31188529_dp
     551          16 :          ipbv%a(5) = -2361200.155376_dp
     552          16 :          ipbv%a(6) = 35940504.84679_dp
     553          16 :          ipbv%a(7) = -339762743.6358_dp
     554          16 :          ipbv%a(8) = 2043874926.466_dp
     555          16 :          ipbv%a(9) = -7654856796.383_dp
     556          16 :          ipbv%a(10) = 16195251405.65_dp
     557          16 :          ipbv%a(11) = -13140392992.18_dp
     558          16 :          ipbv%a(12) = -9285572894.245_dp
     559          16 :          ipbv%a(13) = 8756947519.029_dp
     560          16 :          ipbv%a(14) = 15793297761.67_dp
     561          16 :          ipbv%a(15) = 12917180227.21_dp
     562          32 :       ELSEIF (((at1(1:1) == 'O') .AND. (at2(1:1) == 'H')) .OR. &
     563             :               ((at1(1:1) == 'H') .AND. (at2(1:1) == 'O'))) THEN
     564          16 :          ipbv%rcore = 2.95_dp ! a.u.
     565             : 
     566          16 :          ipbv%m = -0.004025691139759147_dp ! Hartree/a.u.
     567          16 :          ipbv%b = -2.193731138097428_dp ! Hartree
     568             :          ! Hartree*a.u.^2
     569          16 :          ipbv%a(2) = -195.7716013277_dp
     570          16 :          ipbv%a(3) = 15343.78613395_dp
     571          16 :          ipbv%a(4) = -530864.4586516_dp
     572          16 :          ipbv%a(5) = 10707934.39058_dp
     573          16 :          ipbv%a(6) = -140099704.7890_dp
     574          16 :          ipbv%a(7) = 1250943273.785_dp
     575          16 :          ipbv%a(8) = -7795458330.676_dp
     576          16 :          ipbv%a(9) = 33955897217.31_dp
     577          16 :          ipbv%a(10) = -101135640744.0_dp
     578          16 :          ipbv%a(11) = 193107995718.7_dp
     579          16 :          ipbv%a(12) = -193440560940.0_dp
     580          16 :          ipbv%a(13) = -4224406093.918E0_dp
     581          16 :          ipbv%a(14) = 217192386506.5E0_dp
     582          16 :          ipbv%a(15) = -157581228915.5_dp
     583          16 :       ELSEIF ((at1(1:1) == 'H') .AND. (at2(1:1) == 'H')) THEN
     584          16 :          ipbv%rcore = 3.165_dp ! a.u.
     585          16 :          ipbv%m = 0.002639704108787555_dp ! Hartree/a.u.
     586          16 :          ipbv%b = -0.2735482611857583_dp ! Hartree
     587             :          ! Hartree*a.u.^2
     588          16 :          ipbv%a(2) = -26.29456010782_dp
     589          16 :          ipbv%a(3) = 2373.352548248_dp
     590          16 :          ipbv%a(4) = -93880.43551360_dp
     591          16 :          ipbv%a(5) = 2154624.884809_dp
     592          16 :          ipbv%a(6) = -31965151.34955_dp
     593          16 :          ipbv%a(7) = 322781785.3278_dp
     594          16 :          ipbv%a(8) = -2271097368.668_dp
     595          16 :          ipbv%a(9) = 11169163192.90_dp
     596          16 :          ipbv%a(10) = -37684457778.47_dp
     597          16 :          ipbv%a(11) = 82562104256.03_dp
     598          16 :          ipbv%a(12) = -100510435213.4_dp
     599          16 :          ipbv%a(13) = 24570342714.65E0_dp
     600          16 :          ipbv%a(14) = 88766181532.94E0_dp
     601          16 :          ipbv%a(15) = -79705131323.98_dp
     602             :       ELSE
     603           0 :          CPABORT("IPBV only for WATER")
     604             :       END IF
     605          48 :    END SUBROUTINE set_IPBV_ff
     606             : 
     607             : ! **************************************************************************************************
     608             : !> \brief Set up of the BMHFT force fields
     609             : !> \param at1 ...
     610             : !> \param at2 ...
     611             : !> \param ft ...
     612             : !> \author teo
     613             : ! **************************************************************************************************
     614          12 :    SUBROUTINE set_BMHFT_ff(at1, at2, ft)
     615             :       CHARACTER(LEN=*), INTENT(IN)                       :: at1, at2
     616             :       TYPE(ft_pot_type), POINTER                         :: ft
     617             : 
     618          12 :       ft%b = cp_unit_to_cp2k(3.1545_dp, "angstrom^-1")
     619          12 :       IF ((at1(1:2) == 'NA') .AND. (at2(1:2) == 'NA')) THEN
     620           4 :          ft%a = cp_unit_to_cp2k(424.097_dp, "eV")
     621           4 :          ft%c = cp_unit_to_cp2k(1.05_dp, "eV*angstrom^6")
     622           4 :          ft%d = cp_unit_to_cp2k(0.499_dp, "eV*angstrom^8")
     623           8 :       ELSEIF (((at1(1:2) == 'NA') .AND. (at2(1:2) == 'CL')) .OR. &
     624             :               ((at1(1:2) == 'CL') .AND. (at2(1:2) == 'NA'))) THEN
     625           4 :          ft%a = cp_unit_to_cp2k(1256.31_dp, "eV")
     626           4 :          ft%c = cp_unit_to_cp2k(7.00_dp, "eV*angstrom^6")
     627           4 :          ft%d = cp_unit_to_cp2k(8.676_dp, "eV*angstrom^8")
     628           4 :       ELSEIF ((at1(1:2) == 'CL') .AND. (at2(1:2) == 'CL')) THEN
     629           4 :          ft%a = cp_unit_to_cp2k(3488.998_dp, "eV")
     630           4 :          ft%c = cp_unit_to_cp2k(72.50_dp, "eV*angstrom^6")
     631           4 :          ft%d = cp_unit_to_cp2k(145.427_dp, "eV*angstrom^8")
     632             :       ELSE
     633           0 :          CPABORT("BMHFT only for NaCl")
     634             :       END IF
     635             : 
     636          12 :    END SUBROUTINE set_BMHFT_ff
     637             : 
     638             : ! **************************************************************************************************
     639             : !> \brief Set up of the BMHFTD force fields
     640             : !> \author Mathieu Salanne 05.2010
     641             : ! **************************************************************************************************
     642           0 :    SUBROUTINE set_BMHFTD_ff()
     643             : 
     644           0 :       CPABORT("No default parameters present for BMHFTD")
     645             : 
     646           0 :    END SUBROUTINE set_BMHFTD_ff
     647             : 
     648             : ! **************************************************************************************************
     649             : !> \brief Reads the EAM section
     650             : !> \param nonbonded ...
     651             : !> \param section ...
     652             : !> \param start ...
     653             : !> \param para_env ...
     654             : !> \param mm_section ...
     655             : !> \author teo
     656             : ! **************************************************************************************************
     657          12 :    SUBROUTINE read_eam_section(nonbonded, section, start, para_env, mm_section)
     658             :       TYPE(pair_potential_p_type), POINTER               :: nonbonded
     659             :       TYPE(section_vals_type), POINTER                   :: section
     660             :       INTEGER, INTENT(IN)                                :: start
     661             :       TYPE(mp_para_env_type), POINTER                    :: para_env
     662             :       TYPE(section_vals_type), POINTER                   :: mm_section
     663             : 
     664             :       CHARACTER(LEN=default_string_length), &
     665          12 :          DIMENSION(:), POINTER                           :: atm_names
     666             :       INTEGER                                            :: isec, n_items
     667             : 
     668          12 :       CALL section_vals_get(section, n_repetition=n_items)
     669          32 :       DO isec = 1, n_items
     670          20 :          CALL section_vals_val_get(section, "ATOMS", i_rep_section=isec, c_vals=atm_names)
     671             : 
     672          40 :          nonbonded%pot(start + isec)%pot%type = ea_type
     673          20 :          nonbonded%pot(start + isec)%pot%at1 = atm_names(1)
     674          20 :          nonbonded%pot(start + isec)%pot%at2 = atm_names(2)
     675          20 :          CALL uppercase(nonbonded%pot(start + isec)%pot%at1)
     676          20 :          CALL uppercase(nonbonded%pot(start + isec)%pot%at2)
     677             :          CALL section_vals_val_get(section, "PARM_FILE_NAME", i_rep_section=isec, &
     678          20 :                                    c_val=nonbonded%pot(start + isec)%pot%set(1)%eam%eam_file_name)
     679          20 :          CALL read_eam_data(nonbonded%pot(start + isec)%pot%set(1)%eam, para_env, mm_section)
     680          32 :          nonbonded%pot(start + isec)%pot%rcutsq = nonbonded%pot(start + isec)%pot%set(1)%eam%acutal**2
     681             :       END DO
     682          12 :    END SUBROUTINE read_eam_section
     683             : 
     684             : ! **************************************************************************************
     685             : !> \brief Reads the ACE section
     686             : !> \param nonbonded ...
     687             : !> \param section ...
     688             : !> \param start ...
     689             : ! **************************************************************************************************
     690           6 :    SUBROUTINE read_ace_section(nonbonded, section, start)
     691             :       TYPE(pair_potential_p_type), POINTER               :: nonbonded
     692             :       TYPE(section_vals_type), POINTER                   :: section
     693             :       INTEGER, INTENT(IN)                                :: start
     694             : 
     695           6 :       CHARACTER(LEN=2), ALLOCATABLE, DIMENSION(:)        :: ace_atype_symbol
     696             :       CHARACTER(LEN=default_path_length)                 :: ace_filename
     697             :       CHARACTER(LEN=default_string_length)               :: ace_file_name
     698             :       CHARACTER(LEN=default_string_length), &
     699           6 :          DIMENSION(:), POINTER                           :: atm_names
     700             :       INTEGER                                            :: ace_ntype, isec, jsec, n_items
     701           6 :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :)        :: rcutall
     702           6 :       TYPE(ace_model_type)                               :: model
     703             : 
     704             :       n_items = 1
     705           6 :       isec = 1
     706           6 :       n_items = isec*n_items
     707           6 :       CALL section_vals_val_get(section, "ATOMS", c_vals=atm_names)
     708             : 
     709           6 :       ace_ntype = SIZE(atm_names)
     710          30 :       ALLOCATE (ace_atype_symbol(ace_ntype), rcutall(ace_ntype, ace_ntype))
     711          18 :       DO isec = 1, ace_ntype
     712          18 :          ace_atype_symbol(isec) = atm_names(isec) (1:2)
     713             :       END DO
     714           6 :       CALL section_vals_val_get(section, "POT_FILE_NAME", c_val=ace_file_name)
     715             : 
     716           6 :       ace_filename = discover_file(ace_file_name)
     717             : 
     718             : #if defined(__ACE)
     719             :       ! need ace_model_initialize()  here somewhere to get rcut
     720             :       CALL ace_model_initialize(ntypec=ace_ntype, symbolc=ace_atype_symbol, &
     721           6 :                                 fname=TRIM(ace_filename), rcutc=rcutall, model=model)
     722             : #else
     723             :       CPABORT("CP2K was compiled without ACE library.")
     724             : #endif
     725             : 
     726          18 :       DO isec = 1, SIZE(atm_names)
     727          36 :          DO jsec = isec, SIZE(atm_names)
     728          36 :             nonbonded%pot(start + n_items)%pot%type = ace_type
     729          18 :             nonbonded%pot(start + n_items)%pot%at1 = atm_names(isec)
     730          18 :             nonbonded%pot(start + n_items)%pot%at2 = atm_names(jsec)
     731          18 :             CALL uppercase(nonbonded%pot(start + n_items)%pot%at1)
     732          18 :             CALL uppercase(nonbonded%pot(start + n_items)%pot%at2)
     733             : 
     734          18 :             nonbonded%pot(start + n_items)%pot%set(1)%ace%ace_file_name = ace_filename
     735          18 :             nonbonded%pot(start + n_items)%pot%set(1)%ace%atom_ace_type = isec
     736          18 :             nonbonded%pot(start + n_items)%pot%set(1)%ace%model = model
     737             : 
     738             :             !using rcutall(isec,jsec) instead of maxval(rcutall) TODO check that
     739             :             !it shouldn't be jsec,isec?
     740          18 :             nonbonded%pot(start + n_items)%pot%rcutsq = cp_unit_to_cp2k(rcutall(isec, jsec), "angstrom")**2
     741             : 
     742          30 :             n_items = n_items + 1
     743             :          END DO
     744             :       END DO
     745          12 :    END SUBROUTINE read_ace_section
     746             : 
     747             : ! **************************************************************************************
     748             : !> \brief Reads the DEEPMD section
     749             : !> \param nonbonded ...
     750             : !> \param section ...
     751             : !> \param start ...
     752             : !> \author teo
     753             : ! **************************************************************************************************
     754           2 :    SUBROUTINE read_deepmd_section(nonbonded, section, start)
     755             :       TYPE(pair_potential_p_type), POINTER               :: nonbonded
     756             :       TYPE(section_vals_type), POINTER                   :: section
     757             :       INTEGER, INTENT(IN)                                :: start
     758             : 
     759             :       CHARACTER(LEN=default_string_length)               :: deepmd_file_name
     760             :       CHARACTER(LEN=default_string_length), &
     761           2 :          DIMENSION(:), POINTER                           :: atm_names
     762             :       INTEGER                                            :: isec, jsec, n_items
     763           2 :       INTEGER, DIMENSION(:), POINTER                     :: atm_deepmd_types
     764             : 
     765             :       n_items = 1
     766           2 :       isec = 1
     767           2 :       n_items = isec*n_items
     768           2 :       CALL section_vals_val_get(section, "ATOMS", c_vals=atm_names)
     769           2 :       CALL section_vals_val_get(section, "ATOMS_DEEPMD_TYPE", i_vals=atm_deepmd_types)
     770           2 :       CALL section_vals_val_get(section, "POT_FILE_NAME", c_val=deepmd_file_name)
     771             : 
     772           6 :       DO isec = 1, SIZE(atm_names)
     773          12 :          DO jsec = isec, SIZE(atm_names)
     774          12 :             nonbonded%pot(start + n_items)%pot%type = deepmd_type
     775           6 :             nonbonded%pot(start + n_items)%pot%at1 = atm_names(isec)
     776           6 :             nonbonded%pot(start + n_items)%pot%at2 = atm_names(jsec)
     777           6 :             CALL uppercase(nonbonded%pot(start + n_items)%pot%at1)
     778           6 :             CALL uppercase(nonbonded%pot(start + n_items)%pot%at2)
     779             : 
     780           6 :             nonbonded%pot(start + n_items)%pot%set(1)%deepmd%deepmd_file_name = discover_file(deepmd_file_name)
     781           6 :             nonbonded%pot(start + n_items)%pot%set(1)%deepmd%atom_deepmd_type = atm_deepmd_types(isec)
     782           6 :             nonbonded%pot(start + n_items)%pot%rcutsq = 0.0_dp
     783          10 :             n_items = n_items + 1
     784             :          END DO
     785             :       END DO
     786           2 :    END SUBROUTINE read_deepmd_section
     787             : 
     788             : ! **************************************************************************************************
     789             : !> \brief Reads the QUIP section
     790             : !> \param nonbonded ...
     791             : !> \param section ...
     792             : !> \param start ...
     793             : !> \author teo
     794             : ! **************************************************************************************************
     795           0 :    SUBROUTINE read_quip_section(nonbonded, section, start)
     796             :       TYPE(pair_potential_p_type), POINTER               :: nonbonded
     797             :       TYPE(section_vals_type), POINTER                   :: section
     798             :       INTEGER, INTENT(IN)                                :: start
     799             : 
     800             :       CHARACTER(LEN=default_string_length), &
     801           0 :          DIMENSION(:), POINTER                           :: args_str, atm_names
     802             :       INTEGER                                            :: is, isec, n_calc_args, n_items
     803             : 
     804           0 :       CALL section_vals_get(section, n_repetition=n_items)
     805           0 :       DO isec = 1, n_items
     806           0 :          CALL section_vals_val_get(section, "ATOMS", i_rep_section=isec, c_vals=atm_names)
     807             : 
     808           0 :          nonbonded%pot(start + isec)%pot%type = quip_type
     809           0 :          nonbonded%pot(start + isec)%pot%at1 = atm_names(1)
     810           0 :          nonbonded%pot(start + isec)%pot%at2 = atm_names(2)
     811           0 :          CALL uppercase(nonbonded%pot(start + isec)%pot%at1)
     812           0 :          CALL uppercase(nonbonded%pot(start + isec)%pot%at2)
     813             :          CALL section_vals_val_get(section, "PARM_FILE_NAME", i_rep_section=isec, &
     814           0 :                                    c_val=nonbonded%pot(start + isec)%pot%set(1)%quip%quip_file_name)
     815             :          CALL section_vals_val_get(section, "INIT_ARGS", i_rep_section=isec, &
     816           0 :                                    c_vals=args_str)
     817           0 :          nonbonded%pot(start + isec)%pot%set(1)%quip%init_args = ""
     818           0 :          DO is = 1, SIZE(args_str)
     819             :             nonbonded%pot(start + isec)%pot%set(1)%quip%init_args = &
     820             :                TRIM(nonbonded%pot(start + isec)%pot%set(1)%quip%init_args)// &
     821           0 :                " "//TRIM(args_str(is))
     822             :          END DO ! is
     823             :          CALL section_vals_val_get(section, "CALC_ARGS", i_rep_section=isec, &
     824           0 :                                    n_rep_val=n_calc_args)
     825           0 :          IF (n_calc_args > 0) THEN
     826             :             CALL section_vals_val_get(section, "CALC_ARGS", i_rep_section=isec, &
     827           0 :                                       c_vals=args_str)
     828           0 :             DO is = 1, SIZE(args_str)
     829             :                nonbonded%pot(start + isec)%pot%set(1)%quip%calc_args = &
     830             :                   TRIM(nonbonded%pot(start + isec)%pot%set(1)%quip%calc_args)// &
     831           0 :                   " "//TRIM(args_str(is))
     832             :             END DO ! is
     833             :          END IF
     834           0 :          nonbonded%pot(start + isec)%pot%rcutsq = 0.0_dp
     835             :       END DO
     836           0 :    END SUBROUTINE read_quip_section
     837             : 
     838             : ! **************************************************************************************************
     839             : !> \brief Reads the NEQUIP section
     840             : !> \param nonbonded ...
     841             : !> \param section ...
     842             : !> \param start ...
     843             : !> \author Gabriele Tocci
     844             : ! **************************************************************************************************
     845           4 :    SUBROUTINE read_nequip_section(nonbonded, section, start)
     846             :       TYPE(pair_potential_p_type), POINTER               :: nonbonded
     847             :       TYPE(section_vals_type), POINTER                   :: section
     848             :       INTEGER, INTENT(IN)                                :: start
     849             : 
     850             :       CHARACTER(LEN=default_string_length)               :: nequip_file_name, unit_cell, &
     851             :                                                             unit_coords, unit_energy, unit_forces
     852             :       CHARACTER(LEN=default_string_length), &
     853           4 :          DIMENSION(:), POINTER                           :: atm_names
     854             :       INTEGER                                            :: isec, jsec, n_items
     855           4 :       TYPE(nequip_pot_type)                              :: nequip
     856             : 
     857             :       n_items = 1
     858           4 :       isec = 1
     859           4 :       n_items = isec*n_items
     860           4 :       CALL section_vals_val_get(section, "ATOMS", c_vals=atm_names)
     861           4 :       CALL section_vals_val_get(section, "PARM_FILE_NAME", c_val=nequip_file_name)
     862           4 :       CALL section_vals_val_get(section, "UNIT_COORDS", c_val=unit_coords)
     863           4 :       CALL section_vals_val_get(section, "UNIT_ENERGY", c_val=unit_energy)
     864           4 :       CALL section_vals_val_get(section, "UNIT_FORCES", c_val=unit_forces)
     865           4 :       CALL section_vals_val_get(section, "UNIT_CELL", c_val=unit_cell)
     866             : 
     867             :       ! Since reading nequip metadata is expensive we do it only once.
     868           4 :       nequip%nequip_file_name = discover_file(nequip_file_name)
     869           4 :       nequip%unit_coords = unit_coords
     870           4 :       nequip%unit_forces = unit_forces
     871           4 :       nequip%unit_energy = unit_energy
     872           4 :       nequip%unit_cell = unit_cell
     873           4 :       CALL read_nequip_data(nequip)
     874           4 :       CALL check_cp2k_atom_names_in_torch(atm_names, nequip%type_names_torch)
     875             : 
     876          12 :       DO isec = 1, SIZE(atm_names)
     877          24 :          DO jsec = isec, SIZE(atm_names)
     878          24 :             nonbonded%pot(start + n_items)%pot%type = nequip_type
     879          12 :             nonbonded%pot(start + n_items)%pot%at1 = atm_names(isec)
     880          12 :             nonbonded%pot(start + n_items)%pot%at2 = atm_names(jsec)
     881          12 :             CALL uppercase(nonbonded%pot(start + n_items)%pot%at1)
     882          12 :             CALL uppercase(nonbonded%pot(start + n_items)%pot%at2)
     883          12 :             nonbonded%pot(start + n_items)%pot%set(1)%nequip = nequip
     884          12 :             nonbonded%pot(start + n_items)%pot%rcutsq = nequip%rcutsq
     885          20 :             n_items = n_items + 1
     886             :          END DO
     887             :       END DO
     888             : 
     889           8 :    END SUBROUTINE read_nequip_section
     890             : 
     891             : ! **************************************************************************************************
     892             : !> \brief Reads the ALLEGRO section
     893             : !> \param nonbonded ...
     894             : !> \param section ...
     895             : !> \param start ...
     896             : !> \author Gabriele Tocci
     897             : ! **************************************************************************************************
     898           4 :    SUBROUTINE read_allegro_section(nonbonded, section, start)
     899             :       TYPE(pair_potential_p_type), POINTER               :: nonbonded
     900             :       TYPE(section_vals_type), POINTER                   :: section
     901             :       INTEGER, INTENT(IN)                                :: start
     902             : 
     903             :       CHARACTER(LEN=default_string_length)               :: allegro_file_name, unit_cell, &
     904             :                                                             unit_coords, unit_energy, unit_forces
     905             :       CHARACTER(LEN=default_string_length), &
     906           4 :          DIMENSION(:), POINTER                           :: atm_names
     907             :       INTEGER                                            :: isec, jsec, n_items
     908           4 :       TYPE(allegro_pot_type)                             :: allegro
     909             : 
     910             :       n_items = 1
     911           4 :       isec = 1
     912           4 :       n_items = isec*n_items
     913           4 :       CALL section_vals_val_get(section, "ATOMS", c_vals=atm_names)
     914           4 :       CALL section_vals_val_get(section, "PARM_FILE_NAME", c_val=allegro_file_name)
     915           4 :       CALL section_vals_val_get(section, "UNIT_COORDS", c_val=unit_coords)
     916           4 :       CALL section_vals_val_get(section, "UNIT_ENERGY", c_val=unit_energy)
     917           4 :       CALL section_vals_val_get(section, "UNIT_FORCES", c_val=unit_forces)
     918           4 :       CALL section_vals_val_get(section, "UNIT_CELL", c_val=unit_cell)
     919             : 
     920             :       ! Since reading allegro metadata is expensive we do it only once.
     921           4 :       allegro%allegro_file_name = discover_file(allegro_file_name)
     922           4 :       allegro%unit_coords = unit_coords
     923           4 :       allegro%unit_forces = unit_forces
     924           4 :       allegro%unit_energy = unit_energy
     925           4 :       allegro%unit_cell = unit_cell
     926           4 :       CALL read_allegro_data(allegro)
     927           4 :       CALL check_cp2k_atom_names_in_torch(atm_names, allegro%type_names_torch)
     928             : 
     929          10 :       DO isec = 1, SIZE(atm_names)
     930          18 :          DO jsec = isec, SIZE(atm_names)
     931          16 :             nonbonded%pot(start + n_items)%pot%type = allegro_type
     932           8 :             nonbonded%pot(start + n_items)%pot%at1 = atm_names(isec)
     933           8 :             nonbonded%pot(start + n_items)%pot%at2 = atm_names(jsec)
     934           8 :             CALL uppercase(nonbonded%pot(start + n_items)%pot%at1)
     935           8 :             CALL uppercase(nonbonded%pot(start + n_items)%pot%at2)
     936           8 :             nonbonded%pot(start + n_items)%pot%set(1)%allegro = allegro
     937           8 :             nonbonded%pot(start + n_items)%pot%rcutsq = allegro%rcutsq
     938          14 :             n_items = n_items + 1
     939             :          END DO
     940             :       END DO
     941           8 :    END SUBROUTINE read_allegro_section
     942             : 
     943             : ! **************************************************************************************************
     944             : !> \brief Reads the LJ section
     945             : !> \param nonbonded ...
     946             : !> \param section ...
     947             : !> \param start ...
     948             : !> \author teo
     949             : ! **************************************************************************************************
     950        1004 :    SUBROUTINE read_lj_section(nonbonded, section, start)
     951             :       TYPE(pair_potential_p_type), POINTER               :: nonbonded
     952             :       TYPE(section_vals_type), POINTER                   :: section
     953             :       INTEGER, INTENT(IN)                                :: start
     954             : 
     955             :       CHARACTER(LEN=default_string_length), &
     956        1004 :          DIMENSION(:), POINTER                           :: atm_names
     957             :       INTEGER                                            :: isec, n_items, n_rep
     958             :       REAL(KIND=dp)                                      :: epsilon, rcut, sigma
     959             : 
     960        1004 :       CALL section_vals_get(section, n_repetition=n_items)
     961        4790 :       DO isec = 1, n_items
     962        3786 :          CALL section_vals_val_get(section, "ATOMS", i_rep_section=isec, c_vals=atm_names)
     963        3786 :          CALL section_vals_val_get(section, "EPSILON", i_rep_section=isec, r_val=epsilon)
     964        3786 :          CALL section_vals_val_get(section, "SIGMA", i_rep_section=isec, r_val=sigma)
     965        3786 :          CALL section_vals_val_get(section, "RCUT", i_rep_section=isec, r_val=rcut)
     966             : 
     967        7572 :          nonbonded%pot(start + isec)%pot%type = lj_charmm_type
     968        3786 :          nonbonded%pot(start + isec)%pot%at1 = atm_names(1)
     969        3786 :          nonbonded%pot(start + isec)%pot%at2 = atm_names(2)
     970        3786 :          CALL uppercase(nonbonded%pot(start + isec)%pot%at1)
     971        3786 :          CALL uppercase(nonbonded%pot(start + isec)%pot%at2)
     972        3786 :          nonbonded%pot(start + isec)%pot%set(1)%lj%epsilon = epsilon
     973        3786 :          nonbonded%pot(start + isec)%pot%set(1)%lj%sigma6 = sigma**6
     974        3786 :          nonbonded%pot(start + isec)%pot%set(1)%lj%sigma12 = sigma**12
     975        3786 :          nonbonded%pot(start + isec)%pot%rcutsq = rcut*rcut
     976             :          !
     977        3786 :          CALL section_vals_val_get(section, "RMIN", i_rep_section=isec, n_rep_val=n_rep)
     978        3786 :          IF (n_rep == 1) CALL section_vals_val_get(section, "RMIN", i_rep_section=isec, &
     979           2 :                                                    r_val=nonbonded%pot(start + isec)%pot%set(1)%rmin)
     980        3786 :          CALL section_vals_val_get(section, "RMAX", i_rep_section=isec, n_rep_val=n_rep)
     981        3786 :          IF (n_rep == 1) CALL section_vals_val_get(section, "RMAX", i_rep_section=isec, &
     982       12364 :                                                    r_val=nonbonded%pot(start + isec)%pot%set(1)%rmax)
     983             :       END DO
     984        1004 :    END SUBROUTINE read_lj_section
     985             : 
     986             : ! **************************************************************************************************
     987             : !> \brief Reads the WILLIAMS section
     988             : !> \param nonbonded ...
     989             : !> \param section ...
     990             : !> \param start ...
     991             : !> \author teo
     992             : ! **************************************************************************************************
     993         375 :    SUBROUTINE read_wl_section(nonbonded, section, start)
     994             :       TYPE(pair_potential_p_type), POINTER               :: nonbonded
     995             :       TYPE(section_vals_type), POINTER                   :: section
     996             :       INTEGER, INTENT(IN)                                :: start
     997             : 
     998             :       CHARACTER(LEN=default_string_length), &
     999         375 :          DIMENSION(:), POINTER                           :: atm_names
    1000             :       INTEGER                                            :: isec, n_items, n_rep
    1001             :       REAL(KIND=dp)                                      :: a, b, c, rcut
    1002             : 
    1003         375 :       CALL section_vals_get(section, n_repetition=n_items)
    1004        1386 :       DO isec = 1, n_items
    1005        1011 :          CALL section_vals_val_get(section, "ATOMS", i_rep_section=isec, c_vals=atm_names)
    1006        1011 :          CALL section_vals_val_get(section, "A", i_rep_section=isec, r_val=a)
    1007        1011 :          CALL section_vals_val_get(section, "B", i_rep_section=isec, r_val=b)
    1008        1011 :          CALL section_vals_val_get(section, "C", i_rep_section=isec, r_val=c)
    1009        1011 :          CALL section_vals_val_get(section, "RCUT", i_rep_section=isec, r_val=rcut)
    1010             : 
    1011        2022 :          nonbonded%pot(start + isec)%pot%type = wl_type
    1012        1011 :          nonbonded%pot(start + isec)%pot%at1 = atm_names(1)
    1013        1011 :          nonbonded%pot(start + isec)%pot%at2 = atm_names(2)
    1014        1011 :          CALL uppercase(nonbonded%pot(start + isec)%pot%at1)
    1015        1011 :          CALL uppercase(nonbonded%pot(start + isec)%pot%at2)
    1016        1011 :          nonbonded%pot(start + isec)%pot%set(1)%willis%a = a
    1017        1011 :          nonbonded%pot(start + isec)%pot%set(1)%willis%b = b
    1018        1011 :          nonbonded%pot(start + isec)%pot%set(1)%willis%c = c
    1019        1011 :          nonbonded%pot(start + isec)%pot%rcutsq = rcut*rcut
    1020             :          !
    1021        1011 :          CALL section_vals_val_get(section, "RMIN", i_rep_section=isec, n_rep_val=n_rep)
    1022        1011 :          IF (n_rep == 1) CALL section_vals_val_get(section, "RMIN", i_rep_section=isec, &
    1023           0 :                                                    r_val=nonbonded%pot(start + isec)%pot%set(1)%rmin)
    1024        1011 :          CALL section_vals_val_get(section, "RMAX", i_rep_section=isec, n_rep_val=n_rep)
    1025        1011 :          IF (n_rep == 1) CALL section_vals_val_get(section, "RMAX", i_rep_section=isec, &
    1026        3408 :                                                    r_val=nonbonded%pot(start + isec)%pot%set(1)%rmax)
    1027             :       END DO
    1028         375 :    END SUBROUTINE read_wl_section
    1029             : 
    1030             : ! **************************************************************************************************
    1031             : !> \brief Reads the GOODWIN section
    1032             : !> \param nonbonded ...
    1033             : !> \param section ...
    1034             : !> \param start ...
    1035             : !> \author teo
    1036             : ! **************************************************************************************************
    1037           0 :    SUBROUTINE read_gd_section(nonbonded, section, start)
    1038             :       TYPE(pair_potential_p_type), POINTER               :: nonbonded
    1039             :       TYPE(section_vals_type), POINTER                   :: section
    1040             :       INTEGER, INTENT(IN)                                :: start
    1041             : 
    1042             :       CHARACTER(LEN=default_string_length), &
    1043           0 :          DIMENSION(:), POINTER                           :: atm_names
    1044             :       INTEGER                                            :: isec, m, mc, n_items, n_rep
    1045             :       REAL(KIND=dp)                                      :: d, dc, rcut, vr0
    1046             : 
    1047           0 :       CALL section_vals_get(section, n_repetition=n_items)
    1048           0 :       DO isec = 1, n_items
    1049           0 :          CALL section_vals_val_get(section, "ATOMS", i_rep_section=isec, c_vals=atm_names)
    1050           0 :          CALL section_vals_val_get(section, "VR0", i_rep_section=isec, r_val=vr0)
    1051           0 :          CALL section_vals_val_get(section, "D", i_rep_section=isec, r_val=d)
    1052           0 :          CALL section_vals_val_get(section, "DC", i_rep_section=isec, r_val=dc)
    1053           0 :          CALL section_vals_val_get(section, "M", i_rep_section=isec, i_val=m)
    1054           0 :          CALL section_vals_val_get(section, "MC", i_rep_section=isec, i_val=mc)
    1055           0 :          CALL section_vals_val_get(section, "RCUT", i_rep_section=isec, r_val=rcut)
    1056             : 
    1057           0 :          nonbonded%pot(start + isec)%pot%type = gw_type
    1058           0 :          nonbonded%pot(start + isec)%pot%at1 = atm_names(1)
    1059           0 :          nonbonded%pot(start + isec)%pot%at2 = atm_names(2)
    1060           0 :          CALL uppercase(nonbonded%pot(start + isec)%pot%at1)
    1061           0 :          CALL uppercase(nonbonded%pot(start + isec)%pot%at2)
    1062           0 :          nonbonded%pot(start + isec)%pot%set(1)%goodwin%vr0 = vr0
    1063           0 :          nonbonded%pot(start + isec)%pot%set(1)%goodwin%d = d
    1064           0 :          nonbonded%pot(start + isec)%pot%set(1)%goodwin%dc = dc
    1065           0 :          nonbonded%pot(start + isec)%pot%set(1)%goodwin%m = m
    1066           0 :          nonbonded%pot(start + isec)%pot%set(1)%goodwin%mc = mc
    1067           0 :          nonbonded%pot(start + isec)%pot%rcutsq = rcut*rcut
    1068             :          !
    1069           0 :          CALL section_vals_val_get(section, "RMIN", i_rep_section=isec, n_rep_val=n_rep)
    1070           0 :          IF (n_rep == 1) CALL section_vals_val_get(section, "RMIN", i_rep_section=isec, &
    1071           0 :                                                    r_val=nonbonded%pot(start + isec)%pot%set(1)%rmin)
    1072           0 :          CALL section_vals_val_get(section, "RMAX", i_rep_section=isec, n_rep_val=n_rep)
    1073           0 :          IF (n_rep == 1) CALL section_vals_val_get(section, "RMAX", i_rep_section=isec, &
    1074           0 :                                                    r_val=nonbonded%pot(start + isec)%pot%set(1)%rmax)
    1075             :       END DO
    1076           0 :    END SUBROUTINE read_gd_section
    1077             : 
    1078             : ! **************************************************************************************************
    1079             : !> \brief Reads the IPBV section
    1080             : !> \param nonbonded ...
    1081             : !> \param section ...
    1082             : !> \param start ...
    1083             : !> \author teo
    1084             : ! **************************************************************************************************
    1085          16 :    SUBROUTINE read_ipbv_section(nonbonded, section, start)
    1086             :       TYPE(pair_potential_p_type), POINTER               :: nonbonded
    1087             :       TYPE(section_vals_type), POINTER                   :: section
    1088             :       INTEGER, INTENT(IN)                                :: start
    1089             : 
    1090             :       CHARACTER(LEN=default_string_length), &
    1091          16 :          DIMENSION(:), POINTER                           :: atm_names
    1092             :       INTEGER                                            :: isec, n_items, n_rep
    1093             :       REAL(KIND=dp)                                      :: rcut
    1094             : 
    1095          16 :       CALL section_vals_get(section, n_repetition=n_items)
    1096          64 :       DO isec = 1, n_items
    1097          48 :          CALL section_vals_val_get(section, "ATOMS", i_rep_section=isec, c_vals=atm_names)
    1098          96 :          nonbonded%pot(start + isec)%pot%type = ip_type
    1099          48 :          nonbonded%pot(start + isec)%pot%at1 = atm_names(1)
    1100          48 :          nonbonded%pot(start + isec)%pot%at2 = atm_names(2)
    1101          48 :          CALL uppercase(nonbonded%pot(start + isec)%pot%at1)
    1102          48 :          CALL uppercase(nonbonded%pot(start + isec)%pot%at2)
    1103             :          CALL set_IPBV_ff(nonbonded%pot(start + isec)%pot%at1, nonbonded%pot(start + isec)%pot%at2, &
    1104          48 :                           nonbonded%pot(start + isec)%pot%set(1)%ipbv)
    1105          48 :          CALL section_vals_val_get(section, "RCUT", i_rep_section=isec, r_val=rcut)
    1106          48 :          nonbonded%pot(start + isec)%pot%rcutsq = rcut**2
    1107             :          !
    1108          48 :          CALL section_vals_val_get(section, "RMIN", i_rep_section=isec, n_rep_val=n_rep)
    1109          48 :          IF (n_rep == 1) CALL section_vals_val_get(section, "RMIN", i_rep_section=isec, &
    1110           0 :                                                    r_val=nonbonded%pot(start + isec)%pot%set(1)%rmin)
    1111          48 :          CALL section_vals_val_get(section, "RMAX", i_rep_section=isec, n_rep_val=n_rep)
    1112          48 :          IF (n_rep == 1) CALL section_vals_val_get(section, "RMAX", i_rep_section=isec, &
    1113         112 :                                                    r_val=nonbonded%pot(start + isec)%pot%set(1)%rmax)
    1114             :       END DO
    1115          16 :    END SUBROUTINE read_ipbv_section
    1116             : 
    1117             : ! **************************************************************************************************
    1118             : !> \brief Reads the BMHFT section
    1119             : !> \param nonbonded ...
    1120             : !> \param section ...
    1121             : !> \param start ...
    1122             : !> \author teo
    1123             : ! **************************************************************************************************
    1124           4 :    SUBROUTINE read_bmhft_section(nonbonded, section, start)
    1125             :       TYPE(pair_potential_p_type), POINTER               :: nonbonded
    1126             :       TYPE(section_vals_type), POINTER                   :: section
    1127             :       INTEGER, INTENT(IN)                                :: start
    1128             : 
    1129             :       CHARACTER(LEN=default_string_length), DIMENSION(2) :: map_atoms
    1130             :       CHARACTER(LEN=default_string_length), &
    1131           4 :          DIMENSION(:), POINTER                           :: atm_names
    1132             :       INTEGER                                            :: i, isec, n_items, n_rep
    1133             :       REAL(KIND=dp)                                      :: rcut
    1134             : 
    1135           4 :       CALL section_vals_get(section, n_repetition=n_items)
    1136          16 :       DO isec = 1, n_items
    1137          12 :          CALL cite_reference(Tosi1964a)
    1138          12 :          CALL cite_reference(Tosi1964b)
    1139          12 :          CALL section_vals_val_get(section, "ATOMS", i_rep_section=isec, c_vals=atm_names)
    1140          24 :          nonbonded%pot(start + isec)%pot%type = ft_type
    1141          12 :          nonbonded%pot(start + isec)%pot%at1 = atm_names(1)
    1142          12 :          nonbonded%pot(start + isec)%pot%at2 = atm_names(2)
    1143          12 :          CALL uppercase(nonbonded%pot(start + isec)%pot%at1)
    1144          12 :          CALL uppercase(nonbonded%pot(start + isec)%pot%at2)
    1145             : 
    1146          12 :          CALL section_vals_val_get(section, "A", i_rep_section=isec, n_rep_val=i)
    1147          12 :          IF (i == 1) THEN
    1148             :             CALL section_vals_val_get(section, "A", i_rep_section=isec, &
    1149           0 :                                       r_val=nonbonded%pot(start + isec)%pot%set(1)%ft%a)
    1150             :             CALL section_vals_val_get(section, "B", i_rep_section=isec, &
    1151           0 :                                       r_val=nonbonded%pot(start + isec)%pot%set(1)%ft%b)
    1152             :             CALL section_vals_val_get(section, "C", i_rep_section=isec, &
    1153           0 :                                       r_val=nonbonded%pot(start + isec)%pot%set(1)%ft%c)
    1154             :             CALL section_vals_val_get(section, "D", i_rep_section=isec, &
    1155           0 :                                       r_val=nonbonded%pot(start + isec)%pot%set(1)%ft%d)
    1156             :          ELSE
    1157          12 :             CALL section_vals_val_get(section, "MAP_ATOMS", i_rep_section=isec, c_vals=atm_names)
    1158          36 :             map_atoms = atm_names
    1159          12 :             CALL uppercase(map_atoms(1))
    1160          12 :             CALL uppercase(map_atoms(2))
    1161          12 :             CALL set_BMHFT_ff(map_atoms(1), map_atoms(2), nonbonded%pot(start + isec)%pot%set(1)%ft)
    1162             :          END IF
    1163          12 :          CALL section_vals_val_get(section, "RCUT", i_rep_section=isec, r_val=rcut)
    1164          12 :          nonbonded%pot(start + isec)%pot%rcutsq = rcut**2
    1165             :          !
    1166          12 :          CALL section_vals_val_get(section, "RMIN", i_rep_section=isec, n_rep_val=n_rep)
    1167          12 :          IF (n_rep == 1) CALL section_vals_val_get(section, "RMIN", i_rep_section=isec, &
    1168           0 :                                                    r_val=nonbonded%pot(start + isec)%pot%set(1)%rmin)
    1169          12 :          CALL section_vals_val_get(section, "RMAX", i_rep_section=isec, n_rep_val=n_rep)
    1170          12 :          IF (n_rep == 1) CALL section_vals_val_get(section, "RMAX", i_rep_section=isec, &
    1171          40 :                                                    r_val=nonbonded%pot(start + isec)%pot%set(1)%rmax)
    1172             :       END DO
    1173           4 :    END SUBROUTINE read_bmhft_section
    1174             : 
    1175             : ! **************************************************************************************************
    1176             : !> \brief Reads the BMHFTD section
    1177             : !> \param nonbonded ...
    1178             : !> \param section ...
    1179             : !> \param start ...
    1180             : !> \author Mathieu Salanne 05.2010
    1181             : ! **************************************************************************************************
    1182          18 :    SUBROUTINE read_bmhftd_section(nonbonded, section, start)
    1183             :       TYPE(pair_potential_p_type), POINTER               :: nonbonded
    1184             :       TYPE(section_vals_type), POINTER                   :: section
    1185             :       INTEGER, INTENT(IN)                                :: start
    1186             : 
    1187             :       CHARACTER(LEN=default_string_length), DIMENSION(2) :: map_atoms
    1188             :       CHARACTER(LEN=default_string_length), &
    1189          18 :          DIMENSION(:), POINTER                           :: atm_names
    1190             :       INTEGER                                            :: i, isec, n_items, n_rep
    1191             :       REAL(KIND=dp)                                      :: rcut
    1192          18 :       REAL(KIND=dp), DIMENSION(:), POINTER               :: bd_vals
    1193             : 
    1194          18 :       NULLIFY (bd_vals)
    1195             : 
    1196          18 :       CALL section_vals_get(section, n_repetition=n_items)
    1197             : 
    1198          84 :       DO isec = 1, n_items
    1199          66 :          CALL cite_reference(Tosi1964a)
    1200          66 :          CALL cite_reference(Tosi1964b)
    1201          66 :          CALL section_vals_val_get(section, "ATOMS", i_rep_section=isec, c_vals=atm_names)
    1202         132 :          nonbonded%pot(start + isec)%pot%type = ftd_type
    1203          66 :          nonbonded%pot(start + isec)%pot%at1 = atm_names(1)
    1204          66 :          nonbonded%pot(start + isec)%pot%at2 = atm_names(2)
    1205          66 :          CALL uppercase(nonbonded%pot(start + isec)%pot%at1)
    1206          66 :          CALL uppercase(nonbonded%pot(start + isec)%pot%at2)
    1207             : 
    1208          66 :          CALL section_vals_val_get(section, "A", i_rep_section=isec, n_rep_val=i)
    1209          66 :          IF (i == 1) THEN
    1210             :             CALL section_vals_val_get(section, "A", i_rep_section=isec, &
    1211          66 :                                       r_val=nonbonded%pot(start + isec)%pot%set(1)%ftd%a)
    1212             :             CALL section_vals_val_get(section, "B", i_rep_section=isec, &
    1213          66 :                                       r_val=nonbonded%pot(start + isec)%pot%set(1)%ftd%b)
    1214             :             CALL section_vals_val_get(section, "C", i_rep_section=isec, &
    1215          66 :                                       r_val=nonbonded%pot(start + isec)%pot%set(1)%ftd%c)
    1216             :             CALL section_vals_val_get(section, "D", i_rep_section=isec, &
    1217          66 :                                       r_val=nonbonded%pot(start + isec)%pot%set(1)%ftd%d)
    1218          66 :             CALL section_vals_val_get(section, "BD", i_rep_section=isec, r_vals=bd_vals)
    1219          66 :             IF (ASSOCIATED(bd_vals)) THEN
    1220          66 :                SELECT CASE (SIZE(bd_vals))
    1221             :                CASE (0)
    1222           0 :                   CPABORT("No values specified for parameter BD in section &BMHFTD")
    1223             :                CASE (1)
    1224         186 :                   nonbonded%pot(start + isec)%pot%set(1)%ftd%bd(1:2) = bd_vals(1)
    1225             :                CASE (2)
    1226          24 :                   nonbonded%pot(start + isec)%pot%set(1)%ftd%bd(1:2) = bd_vals(1:2)
    1227             :                CASE DEFAULT
    1228          66 :                   CPABORT("Too many values specified for parameter BD in section &BMHFTD")
    1229             :                END SELECT
    1230             :             ELSE
    1231           0 :                CPABORT("Parameter BD in section &BMHFTD was not specified")
    1232             :             END IF
    1233             :          ELSE
    1234           0 :             CALL section_vals_val_get(section, "MAP_ATOMS", i_rep_section=isec, c_vals=atm_names)
    1235           0 :             map_atoms = atm_names
    1236           0 :             CALL uppercase(map_atoms(1))
    1237           0 :             CALL uppercase(map_atoms(2))
    1238           0 :             CALL set_BMHFTD_ff()
    1239             :          END IF
    1240          66 :          CALL section_vals_val_get(section, "RCUT", i_rep_section=isec, r_val=rcut)
    1241          66 :          nonbonded%pot(start + isec)%pot%rcutsq = rcut**2
    1242             :          !
    1243          66 :          CALL section_vals_val_get(section, "RMIN", i_rep_section=isec, n_rep_val=n_rep)
    1244          66 :          IF (n_rep == 1) CALL section_vals_val_get(section, "RMIN", i_rep_section=isec, &
    1245           0 :                                                    r_val=nonbonded%pot(start + isec)%pot%set(1)%rmin)
    1246          66 :          CALL section_vals_val_get(section, "RMAX", i_rep_section=isec, n_rep_val=n_rep)
    1247          66 :          IF (n_rep == 1) CALL section_vals_val_get(section, "RMAX", i_rep_section=isec, &
    1248         216 :                                                    r_val=nonbonded%pot(start + isec)%pot%set(1)%rmax)
    1249             :       END DO
    1250          18 :    END SUBROUTINE read_bmhftd_section
    1251             : 
    1252             : ! **************************************************************************************************
    1253             : !> \brief Reads the Buckingham 4 Ranges potential section
    1254             : !> \param nonbonded ...
    1255             : !> \param section ...
    1256             : !> \param start ...
    1257             : !> \par History
    1258             : !>      MK (11.11.2010): Automatic fit of the (default) polynomial coefficients
    1259             : !> \author MI,MK
    1260             : ! **************************************************************************************************
    1261         262 :    SUBROUTINE read_b4_section(nonbonded, section, start)
    1262             : 
    1263             :       TYPE(pair_potential_p_type), POINTER               :: nonbonded
    1264             :       TYPE(section_vals_type), POINTER                   :: section
    1265             :       INTEGER, INTENT(IN)                                :: start
    1266             : 
    1267             :       CHARACTER(LEN=default_string_length), &
    1268         262 :          DIMENSION(:), POINTER                           :: atm_names
    1269             :       INTEGER                                            :: i, ir, isec, n_items, n_rep, np1, np2
    1270             :       LOGICAL                                            :: explicit_poly1, explicit_poly2
    1271             :       REAL(KIND=dp)                                      :: a, b, c, eval_error, r1, r2, r3, rcut
    1272             :       REAL(KIND=dp), DIMENSION(10)                       :: v, x
    1273             :       REAL(KIND=dp), DIMENSION(10, 10)                   :: p, p_inv
    1274         262 :       REAL(KIND=dp), DIMENSION(:), POINTER               :: coeff1, coeff2, list
    1275             : 
    1276         262 :       NULLIFY (coeff1)
    1277         262 :       NULLIFY (coeff2)
    1278             : 
    1279         262 :       CALL section_vals_get(section, n_repetition=n_items)
    1280             : 
    1281         524 :       DO isec = 1, n_items
    1282         262 :          CALL section_vals_val_get(section, "ATOMS", i_rep_section=isec, c_vals=atm_names)
    1283         262 :          CALL section_vals_val_get(section, "A", i_rep_section=isec, r_val=a)
    1284         262 :          CALL section_vals_val_get(section, "B", i_rep_section=isec, r_val=b)
    1285         262 :          CALL section_vals_val_get(section, "C", i_rep_section=isec, r_val=c)
    1286         262 :          CALL section_vals_val_get(section, "R1", i_rep_section=isec, r_val=r1)
    1287         262 :          CALL section_vals_val_get(section, "R2", i_rep_section=isec, r_val=r2)
    1288         262 :          CALL section_vals_val_get(section, "R3", i_rep_section=isec, r_val=r3)
    1289         262 :          CALL section_vals_val_get(section, "POLY1", explicit=explicit_poly1, n_rep_val=n_rep)
    1290             :          ! Check if polynomial coefficients were specified for range 2 and 3 explicitly
    1291         262 :          IF (explicit_poly1) THEN
    1292          84 :             np1 = 0
    1293         168 :             DO ir = 1, n_rep
    1294          84 :                NULLIFY (list)
    1295          84 :                CALL section_vals_val_get(section, "POLY1", i_rep_val=ir, r_vals=list)
    1296         168 :                IF (ASSOCIATED(list)) THEN
    1297          84 :                   CALL reallocate(coeff1, 0, np1 + SIZE(list) - 1)
    1298         588 :                   DO i = 1, SIZE(list)
    1299         588 :                      coeff1(i + np1 - 1) = list(i)
    1300             :                   END DO
    1301          84 :                   np1 = np1 + SIZE(list)
    1302             :                END IF
    1303             :             END DO
    1304             :          END IF
    1305         262 :          CALL section_vals_val_get(section, "POLY2", explicit=explicit_poly2, n_rep_val=n_rep)
    1306         262 :          IF (explicit_poly2) THEN
    1307          84 :             np2 = 0
    1308         168 :             DO ir = 1, n_rep
    1309          84 :                NULLIFY (list)
    1310          84 :                CALL section_vals_val_get(section, "POLY2", i_rep_val=ir, r_vals=list)
    1311         168 :                IF (ASSOCIATED(list)) THEN
    1312          84 :                   CALL reallocate(coeff2, 0, np2 + SIZE(list) - 1)
    1313         420 :                   DO i = 1, SIZE(list)
    1314         420 :                      coeff2(i + np2 - 1) = list(i)
    1315             :                   END DO
    1316          84 :                   np2 = np2 + SIZE(list)
    1317             :                END IF
    1318             :             END DO
    1319             :          END IF
    1320             :          ! Default is a 5th/3rd-order polynomial fit
    1321         262 :          IF ((.NOT. explicit_poly1) .OR. (.NOT. explicit_poly2)) THEN
    1322             :             ! Build matrix p and vector v to calculate the polynomial coefficients
    1323             :             ! in the vector x from p*x = v
    1324         178 :             p(:, :) = 0.0_dp
    1325             :             ! Row 1: Match the 5th-order polynomial and the potential at r1
    1326         178 :             p(1, 1) = 1.0_dp
    1327        1068 :             DO i = 2, 6
    1328        1068 :                p(1, i) = p(1, i - 1)*r1
    1329             :             END DO
    1330             :             ! Row 2: Match the first derivatives of the 5th-order polynomial and the potential at r1
    1331        1068 :             DO i = 2, 6
    1332        1068 :                p(2, i) = REAL(i - 1, KIND=dp)*p(1, i - 1)
    1333             :             END DO
    1334             :             ! Row 3: Match the second derivatives of the 5th-order polynomial and the potential at r1
    1335         890 :             DO i = 3, 6
    1336         890 :                p(3, i) = REAL(i - 1, KIND=dp)*p(2, i - 1)
    1337             :             END DO
    1338             :             ! Row 4: Match the 5th-order and the 3rd-order polynomials at r2
    1339         178 :             p(4, 1) = 1.0_dp
    1340        1068 :             DO i = 2, 6
    1341        1068 :                p(4, i) = p(4, i - 1)*r2
    1342             :             END DO
    1343         178 :             p(4, 7) = -1.0_dp
    1344         712 :             DO i = 8, 10
    1345         712 :                p(4, i) = p(4, i - 1)*r2
    1346             :             END DO
    1347             :             ! Row 5: Match the first derivatives of the 5th-order and the 3rd-order polynomials at r2
    1348        1068 :             DO i = 2, 6
    1349        1068 :                p(5, i) = REAL(i - 1, KIND=dp)*p(4, i - 1)
    1350             :             END DO
    1351         712 :             DO i = 8, 10
    1352         712 :                p(5, i) = REAL(i - 7, KIND=dp)*p(4, i - 1)
    1353             :             END DO
    1354             :             ! Row 6: Match the second derivatives of the 5th-order and the 3rd-order polynomials at r2
    1355         890 :             DO i = 3, 6
    1356         890 :                p(6, i) = REAL(i - 1, KIND=dp)*p(5, i - 1)
    1357             :             END DO
    1358         534 :             DO i = 9, 10
    1359         534 :                p(6, i) = REAL(i - 7, KIND=dp)*p(5, i - 1)
    1360             :             END DO
    1361             :             ! Row 7: Minimum at r2, ie. the first derivative of the 3rd-order polynomial has to be zero at r2
    1362         712 :             DO i = 8, 10
    1363         712 :                p(7, i) = -p(5, i)
    1364             :             END DO
    1365             :             ! Row 8: Match the 3rd-order polynomial and the potential at r3
    1366         178 :             p(8, 7) = 1.0_dp
    1367         712 :             DO i = 8, 10
    1368         712 :                p(8, i) = p(8, i - 1)*r3
    1369             :             END DO
    1370             :             ! Row 9: Match the first derivatives of the 3rd-order polynomial and the potential at r3
    1371         712 :             DO i = 8, 10
    1372         712 :                p(9, i) = REAL(i - 7, KIND=dp)*p(8, i - 1)
    1373             :             END DO
    1374             :             ! Row 10: Match the second derivatives of the 3rd-order polynomial and the potential at r3
    1375         534 :             DO i = 9, 10
    1376         534 :                p(10, i) = REAL(i - 7, KIND=dp)*p(9, i - 1)
    1377             :             END DO
    1378             :             ! Build the vector v
    1379         178 :             v(1) = a*EXP(-b*r1)
    1380         178 :             v(2) = -b*v(1)
    1381         178 :             v(3) = -b*v(2)
    1382         890 :             v(4:7) = 0.0_dp
    1383         178 :             v(8) = -c/p(8, 10)**2 ! = -c/r3**6
    1384         178 :             v(9) = -6.0_dp*v(8)/r3
    1385         178 :             v(10) = -7.0_dp*v(9)/r3
    1386             :             ! Calculate p_inv the inverse of the matrix p
    1387         178 :             p_inv(:, :) = 0.0_dp
    1388         178 :             CALL invert_matrix(p, p_inv, eval_error)
    1389         178 :             IF (eval_error >= 1.0E-8_dp) &
    1390             :                CALL cp_warn(__LOCATION__, &
    1391             :                             "The polynomial fit for the BUCK4RANGES potential is only accurate to "// &
    1392           0 :                             TRIM(cp_to_string(eval_error)))
    1393             :             ! Get the 6 coefficients of the 5th-order polynomial -> x(1:6)
    1394             :             ! and the 4 coefficients of the 3rd-order polynomial -> x(7:10)
    1395       19758 :             x(:) = MATMUL(p_inv(:, :), v(:))
    1396             :          ELSE
    1397          84 :             x(:) = 0.0_dp
    1398             :          END IF
    1399             : 
    1400         262 :          CALL section_vals_val_get(section, "RCUT", i_rep_section=isec, r_val=rcut)
    1401             : 
    1402         524 :          nonbonded%pot(start + isec)%pot%type = b4_type
    1403         262 :          nonbonded%pot(start + isec)%pot%at1 = atm_names(1)
    1404         262 :          nonbonded%pot(start + isec)%pot%at2 = atm_names(2)
    1405         262 :          CALL uppercase(nonbonded%pot(start + isec)%pot%at1)
    1406         262 :          CALL uppercase(nonbonded%pot(start + isec)%pot%at2)
    1407         262 :          nonbonded%pot(start + isec)%pot%set(1)%buck4r%a = a
    1408         262 :          nonbonded%pot(start + isec)%pot%set(1)%buck4r%b = b
    1409         262 :          nonbonded%pot(start + isec)%pot%set(1)%buck4r%c = c
    1410         262 :          nonbonded%pot(start + isec)%pot%set(1)%buck4r%r1 = r1
    1411         262 :          nonbonded%pot(start + isec)%pot%set(1)%buck4r%r2 = r2
    1412         262 :          nonbonded%pot(start + isec)%pot%set(1)%buck4r%r3 = r3
    1413         262 :          IF ((.NOT. explicit_poly1) .OR. (.NOT. explicit_poly2)) THEN
    1414         178 :             nonbonded%pot(start + isec)%pot%set(1)%buck4r%npoly1 = 5
    1415        1246 :             nonbonded%pot(start + isec)%pot%set(1)%buck4r%poly1(0:5) = x(1:6)
    1416         178 :             nonbonded%pot(start + isec)%pot%set(1)%buck4r%npoly2 = 3
    1417         890 :             nonbonded%pot(start + isec)%pot%set(1)%buck4r%poly2(0:3) = x(7:10)
    1418             :          ELSE
    1419          84 :             nonbonded%pot(start + isec)%pot%set(1)%buck4r%npoly1 = np1 - 1
    1420          84 :             CPASSERT(np1 - 1 <= 10)
    1421        1092 :             nonbonded%pot(start + isec)%pot%set(1)%buck4r%poly1(0:np1 - 1) = coeff1(0:np1 - 1)
    1422          84 :             nonbonded%pot(start + isec)%pot%set(1)%buck4r%npoly2 = np2 - 1
    1423          84 :             CPASSERT(np2 - 1 <= 10)
    1424         756 :             nonbonded%pot(start + isec)%pot%set(1)%buck4r%poly2(0:np2 - 1) = coeff2(0:np2 - 1)
    1425             :          END IF
    1426         262 :          nonbonded%pot(start + isec)%pot%rcutsq = rcut*rcut
    1427             : 
    1428         262 :          IF (ASSOCIATED(coeff1)) THEN
    1429          84 :             DEALLOCATE (coeff1)
    1430             :          END IF
    1431         262 :          IF (ASSOCIATED(coeff2)) THEN
    1432          84 :             DEALLOCATE (coeff2)
    1433             :          END IF
    1434         262 :          CALL section_vals_val_get(section, "RMIN", i_rep_section=isec, n_rep_val=n_rep)
    1435         262 :          IF (n_rep == 1) CALL section_vals_val_get(section, "RMIN", i_rep_section=isec, &
    1436           0 :                                                    r_val=nonbonded%pot(start + isec)%pot%set(1)%rmin)
    1437         262 :          CALL section_vals_val_get(section, "RMAX", i_rep_section=isec, n_rep_val=n_rep)
    1438         262 :          IF (n_rep == 1) CALL section_vals_val_get(section, "RMAX", i_rep_section=isec, &
    1439        1572 :                                                    r_val=nonbonded%pot(start + isec)%pot%set(1)%rmax)
    1440             :       END DO
    1441             : 
    1442         262 :    END SUBROUTINE read_b4_section
    1443             : 
    1444             : ! **************************************************************************************************
    1445             : !> \brief Reads the GENPOT - generic potential section
    1446             : !> \param nonbonded ...
    1447             : !> \param section ...
    1448             : !> \param start ...
    1449             : !> \author Teodoro Laino - 10.2006
    1450             : ! **************************************************************************************************
    1451         576 :    SUBROUTINE read_gp_section(nonbonded, section, start)
    1452             :       TYPE(pair_potential_p_type), POINTER               :: nonbonded
    1453             :       TYPE(section_vals_type), POINTER                   :: section
    1454             :       INTEGER, INTENT(IN)                                :: start
    1455             : 
    1456             :       CHARACTER(LEN=default_string_length), &
    1457         576 :          DIMENSION(:), POINTER                           :: atm_names
    1458             :       INTEGER                                            :: isec, n_items, n_rep
    1459             :       REAL(KIND=dp)                                      :: rcut
    1460             : 
    1461         576 :       CALL section_vals_get(section, n_repetition=n_items)
    1462        3794 :       DO isec = 1, n_items
    1463        3218 :          NULLIFY (atm_names)
    1464        3218 :          CALL section_vals_val_get(section, "ATOMS", i_rep_section=isec, c_vals=atm_names)
    1465        3218 :          CALL section_vals_val_get(section, "RCUT", i_rep_section=isec, r_val=rcut)
    1466        6436 :          nonbonded%pot(start + isec)%pot%type = gp_type
    1467        3218 :          nonbonded%pot(start + isec)%pot%at1 = atm_names(1)
    1468        3218 :          nonbonded%pot(start + isec)%pot%at2 = atm_names(2)
    1469        3218 :          nonbonded%pot(start + isec)%pot%rcutsq = rcut*rcut
    1470        3218 :          CALL uppercase(nonbonded%pot(start + isec)%pot%at1)
    1471        3218 :          CALL uppercase(nonbonded%pot(start + isec)%pot%at2)
    1472             :          ! Parse the genpot info
    1473             :          CALL get_generic_info(section, "FUNCTION", nonbonded%pot(start + isec)%pot%set(1)%gp%potential, &
    1474             :                                nonbonded%pot(start + isec)%pot%set(1)%gp%parameters, &
    1475             :                                nonbonded%pot(start + isec)%pot%set(1)%gp%values, &
    1476        3218 :                                size_variables=1, i_rep_sec=isec)
    1477        3218 :          nonbonded%pot(start + isec)%pot%set(1)%gp%variables = nonbonded%pot(start + isec)%pot%set(1)%gp%parameters(1)
    1478             :          !
    1479        3218 :          CALL section_vals_val_get(section, "RMIN", i_rep_section=isec, n_rep_val=n_rep)
    1480        3218 :          IF (n_rep == 1) CALL section_vals_val_get(section, "RMIN", i_rep_section=isec, &
    1481          21 :                                                    r_val=nonbonded%pot(start + isec)%pot%set(1)%rmin)
    1482        3218 :          CALL section_vals_val_get(section, "RMAX", i_rep_section=isec, n_rep_val=n_rep)
    1483        3218 :          IF (n_rep == 1) CALL section_vals_val_get(section, "RMAX", i_rep_section=isec, &
    1484       10251 :                                                    r_val=nonbonded%pot(start + isec)%pot%set(1)%rmax)
    1485             :       END DO
    1486         576 :    END SUBROUTINE read_gp_section
    1487             : 
    1488             : ! **************************************************************************************************
    1489             : !> \brief Reads the tersoff section
    1490             : !> \param nonbonded ...
    1491             : !> \param section ...
    1492             : !> \param start ...
    1493             : !> \param tersoff_section ...
    1494             : !> \author ikuo
    1495             : ! **************************************************************************************************
    1496          40 :    SUBROUTINE read_tersoff_section(nonbonded, section, start, tersoff_section)
    1497             :       TYPE(pair_potential_p_type), POINTER               :: nonbonded
    1498             :       TYPE(section_vals_type), POINTER                   :: section
    1499             :       INTEGER, INTENT(IN)                                :: start
    1500             :       TYPE(section_vals_type), POINTER                   :: tersoff_section
    1501             : 
    1502             :       CHARACTER(LEN=default_string_length), &
    1503          40 :          DIMENSION(:), POINTER                           :: atm_names
    1504             :       INTEGER                                            :: isec, n_items, n_rep
    1505             :       REAL(KIND=dp)                                      :: rcut, rcutsq
    1506             : 
    1507          40 :       CALL section_vals_get(section, n_repetition=n_items)
    1508          84 :       DO isec = 1, n_items
    1509          44 :          CALL cite_reference(Tersoff1988)
    1510          44 :          CALL section_vals_val_get(section, "ATOMS", i_rep_section=isec, c_vals=atm_names)
    1511             : 
    1512          88 :          nonbonded%pot(start + isec)%pot%type = tersoff_type
    1513          44 :          nonbonded%pot(start + isec)%pot%at1 = atm_names(1)
    1514          44 :          nonbonded%pot(start + isec)%pot%at2 = atm_names(2)
    1515          44 :          CALL uppercase(nonbonded%pot(start + isec)%pot%at1)
    1516          44 :          CALL uppercase(nonbonded%pot(start + isec)%pot%at2)
    1517             : 
    1518             :          CALL section_vals_val_get(tersoff_section, "A", i_rep_section=isec, &
    1519          44 :                                    r_val=nonbonded%pot(start + isec)%pot%set(1)%tersoff%A)
    1520             :          CALL section_vals_val_get(tersoff_section, "B", i_rep_section=isec, &
    1521          44 :                                    r_val=nonbonded%pot(start + isec)%pot%set(1)%tersoff%B)
    1522             :          CALL section_vals_val_get(tersoff_section, "lambda1", i_rep_section=isec, &
    1523          44 :                                    r_val=nonbonded%pot(start + isec)%pot%set(1)%tersoff%lambda1)
    1524             :          CALL section_vals_val_get(tersoff_section, "lambda2", i_rep_section=isec, &
    1525          44 :                                    r_val=nonbonded%pot(start + isec)%pot%set(1)%tersoff%lambda2)
    1526             :          CALL section_vals_val_get(tersoff_section, "alpha", i_rep_section=isec, &
    1527          44 :                                    r_val=nonbonded%pot(start + isec)%pot%set(1)%tersoff%alpha)
    1528             :          CALL section_vals_val_get(tersoff_section, "beta", i_rep_section=isec, &
    1529          44 :                                    r_val=nonbonded%pot(start + isec)%pot%set(1)%tersoff%beta)
    1530             :          CALL section_vals_val_get(tersoff_section, "n", i_rep_section=isec, &
    1531          44 :                                    r_val=nonbonded%pot(start + isec)%pot%set(1)%tersoff%n)
    1532             :          CALL section_vals_val_get(tersoff_section, "c", i_rep_section=isec, &
    1533          44 :                                    r_val=nonbonded%pot(start + isec)%pot%set(1)%tersoff%c)
    1534             :          CALL section_vals_val_get(tersoff_section, "d", i_rep_section=isec, &
    1535          44 :                                    r_val=nonbonded%pot(start + isec)%pot%set(1)%tersoff%d)
    1536             :          CALL section_vals_val_get(tersoff_section, "h", i_rep_section=isec, &
    1537          44 :                                    r_val=nonbonded%pot(start + isec)%pot%set(1)%tersoff%h)
    1538             :          CALL section_vals_val_get(tersoff_section, "lambda3", i_rep_section=isec, &
    1539          44 :                                    r_val=nonbonded%pot(start + isec)%pot%set(1)%tersoff%lambda3)
    1540             :          CALL section_vals_val_get(tersoff_section, "bigR", i_rep_section=isec, &
    1541          44 :                                    r_val=nonbonded%pot(start + isec)%pot%set(1)%tersoff%bigR)
    1542             :          CALL section_vals_val_get(tersoff_section, "bigD", i_rep_section=isec, &
    1543          44 :                                    r_val=nonbonded%pot(start + isec)%pot%set(1)%tersoff%bigD)
    1544             : 
    1545             :          rcutsq = (nonbonded%pot(start + isec)%pot%set(1)%tersoff%bigR + &
    1546          44 :                    nonbonded%pot(start + isec)%pot%set(1)%tersoff%bigD)**2
    1547          44 :          nonbonded%pot(start + isec)%pot%set(1)%tersoff%rcutsq = rcutsq
    1548          44 :          nonbonded%pot(start + isec)%pot%rcutsq = rcutsq
    1549             : 
    1550             :          ! In case it is defined override the standard specification of RCUT
    1551          44 :          CALL section_vals_val_get(tersoff_section, "RCUT", i_rep_section=isec, n_rep_val=n_rep)
    1552          84 :          IF (n_rep == 1) THEN
    1553          26 :             CALL section_vals_val_get(tersoff_section, "RCUT", i_rep_section=isec, r_val=rcut)
    1554          26 :             nonbonded%pot(start + isec)%pot%rcutsq = rcut**2
    1555             :          END IF
    1556             :       END DO
    1557          40 :    END SUBROUTINE read_tersoff_section
    1558             : 
    1559             : ! **************************************************************************************************
    1560             : !> \brief Reads the gal19 section
    1561             : !> \param nonbonded ...
    1562             : !> \param section ...
    1563             : !> \param start ...
    1564             : !> \param gal_section ...
    1565             : !> \author Clabaut Paul
    1566             : ! **************************************************************************************************
    1567           1 :    SUBROUTINE read_gal_section(nonbonded, section, start, gal_section)
    1568             :       TYPE(pair_potential_p_type), POINTER               :: nonbonded
    1569             :       TYPE(section_vals_type), POINTER                   :: section
    1570             :       INTEGER, INTENT(IN)                                :: start
    1571             :       TYPE(section_vals_type), POINTER                   :: gal_section
    1572             : 
    1573             :       CHARACTER(LEN=default_string_length), &
    1574           1 :          DIMENSION(:), POINTER                           :: atm_names
    1575             :       INTEGER                                            :: iatom, isec, n_items, n_rep, nval
    1576             :       LOGICAL                                            :: is_ok
    1577             :       REAL(KIND=dp)                                      :: rcut, rval
    1578           1 :       REAL(KIND=dp), DIMENSION(:), POINTER               :: rvalues
    1579             :       TYPE(cp_sll_val_type), POINTER                     :: list
    1580             :       TYPE(section_vals_type), POINTER                   :: subsection
    1581             :       TYPE(val_type), POINTER                            :: val
    1582             : 
    1583           1 :       CALL section_vals_get(section, n_repetition=n_items)
    1584           2 :       DO isec = 1, n_items
    1585           1 :          CALL cite_reference(Clabaut2020)
    1586           1 :          CALL section_vals_val_get(section, "ATOMS", i_rep_section=isec, c_vals=atm_names)
    1587             : 
    1588           2 :          nonbonded%pot(start + isec)%pot%type = gal_type
    1589           1 :          nonbonded%pot(start + isec)%pot%at1 = atm_names(1)
    1590           1 :          nonbonded%pot(start + isec)%pot%at2 = atm_names(2)
    1591           1 :          CALL uppercase(nonbonded%pot(start + isec)%pot%at1)
    1592           1 :          CALL uppercase(nonbonded%pot(start + isec)%pot%at2)
    1593             : 
    1594           1 :          CALL section_vals_val_get(section, "METALS", i_rep_section=isec, c_vals=atm_names)
    1595           1 :          nonbonded%pot(start + isec)%pot%set(1)%gal%met1 = atm_names(1)
    1596           1 :          nonbonded%pot(start + isec)%pot%set(1)%gal%met2 = atm_names(2)
    1597             : 
    1598             :          CALL section_vals_val_get(gal_section, "epsilon", i_rep_section=isec, &
    1599           1 :                                    r_val=nonbonded%pot(start + isec)%pot%set(1)%gal%epsilon)
    1600             :          CALL section_vals_val_get(gal_section, "bxy", i_rep_section=isec, &
    1601           1 :                                    r_val=nonbonded%pot(start + isec)%pot%set(1)%gal%bxy)
    1602             :          CALL section_vals_val_get(gal_section, "bz", i_rep_section=isec, &
    1603           1 :                                    r_val=nonbonded%pot(start + isec)%pot%set(1)%gal%bz)
    1604             : 
    1605           1 :          CALL section_vals_val_get(gal_section, "r", i_rep_section=isec, r_vals=rvalues)
    1606           1 :          nonbonded%pot(start + isec)%pot%set(1)%gal%r1 = rvalues(1)
    1607           1 :          nonbonded%pot(start + isec)%pot%set(1)%gal%r2 = rvalues(2)
    1608             : 
    1609             :          CALL section_vals_val_get(gal_section, "a1", i_rep_section=isec, &
    1610           1 :                                    r_val=nonbonded%pot(start + isec)%pot%set(1)%gal%a1)
    1611             :          CALL section_vals_val_get(gal_section, "a2", i_rep_section=isec, &
    1612           1 :                                    r_val=nonbonded%pot(start + isec)%pot%set(1)%gal%a2)
    1613             :          CALL section_vals_val_get(gal_section, "a3", i_rep_section=isec, &
    1614           1 :                                    r_val=nonbonded%pot(start + isec)%pot%set(1)%gal%a3)
    1615             :          CALL section_vals_val_get(gal_section, "a4", i_rep_section=isec, &
    1616           1 :                                    r_val=nonbonded%pot(start + isec)%pot%set(1)%gal%a4)
    1617             :          CALL section_vals_val_get(gal_section, "A", i_rep_section=isec, &
    1618           1 :                                    r_val=nonbonded%pot(start + isec)%pot%set(1)%gal%a)
    1619             :          CALL section_vals_val_get(gal_section, "B", i_rep_section=isec, &
    1620           1 :                                    r_val=nonbonded%pot(start + isec)%pot%set(1)%gal%b)
    1621             :          CALL section_vals_val_get(gal_section, "C", i_rep_section=isec, &
    1622           1 :                                    r_val=nonbonded%pot(start + isec)%pot%set(1)%gal%c)
    1623           1 :          NULLIFY (list)
    1624           1 :          subsection => section_vals_get_subs_vals(section, "GCN", i_rep_section=isec)
    1625           1 :          CALL section_vals_val_get(subsection, "_DEFAULT_KEYWORD_", n_rep_val=nval)
    1626           3 :          ALLOCATE (nonbonded%pot(start + isec)%pot%set(1)%gal%gcn(nval))
    1627           1 :          CALL section_vals_list_get(subsection, "_DEFAULT_KEYWORD_", list=list)
    1628         871 :          DO iatom = 1, nval
    1629             :             ! we use only the first default_string_length characters of each line
    1630         870 :             is_ok = cp_sll_val_next(list, val)
    1631         870 :             CALL val_get(val, r_val=rval)
    1632             :             ! assign values
    1633         871 :             nonbonded%pot(start + isec)%pot%set(1)%gal%gcn(iatom) = rval
    1634             :          END DO
    1635             : 
    1636             :          CALL section_vals_val_get(gal_section, "Fit_express", i_rep_section=isec, &
    1637           1 :                                    l_val=nonbonded%pot(start + isec)%pot%set(1)%gal%express)
    1638             : 
    1639             :          ! ! In case it is defined override the standard specification of RCUT
    1640           1 :          CALL section_vals_val_get(gal_section, "RCUT", i_rep_section=isec, n_rep_val=n_rep)
    1641           3 :          IF (n_rep == 1) THEN
    1642           1 :             CALL section_vals_val_get(gal_section, "RCUT", i_rep_section=isec, r_val=rcut)
    1643           1 :             nonbonded%pot(start + isec)%pot%rcutsq = rcut**2
    1644           1 :             nonbonded%pot(start + isec)%pot%set(1)%gal%rcutsq = rcut**2
    1645             :          END IF
    1646             :       END DO
    1647           1 :    END SUBROUTINE read_gal_section
    1648             : 
    1649             : ! **************************************************************************************************
    1650             : !> \brief Reads the gal21 section
    1651             : !> \param nonbonded ...
    1652             : !> \param section ...
    1653             : !> \param start ...
    1654             : !> \param gal21_section ...
    1655             : !> \author Clabaut Paul
    1656             : ! **************************************************************************************************
    1657           1 :    SUBROUTINE read_gal21_section(nonbonded, section, start, gal21_section)
    1658             :       TYPE(pair_potential_p_type), POINTER               :: nonbonded
    1659             :       TYPE(section_vals_type), POINTER                   :: section
    1660             :       INTEGER, INTENT(IN)                                :: start
    1661             :       TYPE(section_vals_type), POINTER                   :: gal21_section
    1662             : 
    1663             :       CHARACTER(LEN=default_string_length), &
    1664           1 :          DIMENSION(:), POINTER                           :: atm_names
    1665             :       INTEGER                                            :: iatom, isec, n_items, n_rep, nval
    1666             :       LOGICAL                                            :: is_ok
    1667             :       REAL(KIND=dp)                                      :: rcut, rval
    1668           1 :       REAL(KIND=dp), DIMENSION(:), POINTER               :: rvalues
    1669             :       TYPE(cp_sll_val_type), POINTER                     :: list
    1670             :       TYPE(section_vals_type), POINTER                   :: subsection
    1671             :       TYPE(val_type), POINTER                            :: val
    1672             : 
    1673           1 :       CALL section_vals_get(section, n_repetition=n_items)
    1674           2 :       DO isec = 1, n_items
    1675           1 :          CALL cite_reference(Clabaut2021)
    1676           1 :          CALL section_vals_val_get(section, "ATOMS", i_rep_section=isec, c_vals=atm_names)
    1677             : 
    1678           2 :          nonbonded%pot(start + isec)%pot%type = gal21_type
    1679           1 :          nonbonded%pot(start + isec)%pot%at1 = atm_names(1)
    1680           1 :          nonbonded%pot(start + isec)%pot%at2 = atm_names(2)
    1681           1 :          CALL uppercase(nonbonded%pot(start + isec)%pot%at1)
    1682           1 :          CALL uppercase(nonbonded%pot(start + isec)%pot%at2)
    1683             : 
    1684           1 :          CALL section_vals_val_get(section, "METALS", i_rep_section=isec, c_vals=atm_names)
    1685           1 :          nonbonded%pot(start + isec)%pot%set(1)%gal21%met1 = atm_names(1)
    1686           1 :          nonbonded%pot(start + isec)%pot%set(1)%gal21%met2 = atm_names(2)
    1687             : 
    1688           1 :          CALL section_vals_val_get(gal21_section, "epsilon", i_rep_section=isec, r_vals=rvalues)
    1689           1 :          nonbonded%pot(start + isec)%pot%set(1)%gal21%epsilon1 = rvalues(1)
    1690           1 :          nonbonded%pot(start + isec)%pot%set(1)%gal21%epsilon2 = rvalues(2)
    1691           1 :          nonbonded%pot(start + isec)%pot%set(1)%gal21%epsilon3 = rvalues(3)
    1692             : 
    1693           1 :          CALL section_vals_val_get(gal21_section, "bxy", i_rep_section=isec, r_vals=rvalues)
    1694           1 :          nonbonded%pot(start + isec)%pot%set(1)%gal21%bxy1 = rvalues(1)
    1695           1 :          nonbonded%pot(start + isec)%pot%set(1)%gal21%bxy2 = rvalues(2)
    1696             : 
    1697           1 :          CALL section_vals_val_get(gal21_section, "bz", i_rep_section=isec, r_vals=rvalues)
    1698           1 :          nonbonded%pot(start + isec)%pot%set(1)%gal21%bz1 = rvalues(1)
    1699           1 :          nonbonded%pot(start + isec)%pot%set(1)%gal21%bz2 = rvalues(2)
    1700             : 
    1701           1 :          CALL section_vals_val_get(gal21_section, "r", i_rep_section=isec, r_vals=rvalues)
    1702           1 :          nonbonded%pot(start + isec)%pot%set(1)%gal21%r1 = rvalues(1)
    1703           1 :          nonbonded%pot(start + isec)%pot%set(1)%gal21%r2 = rvalues(2)
    1704             : 
    1705           1 :          CALL section_vals_val_get(gal21_section, "a1", i_rep_section=isec, r_vals=rvalues)
    1706           1 :          nonbonded%pot(start + isec)%pot%set(1)%gal21%a11 = rvalues(1)
    1707           1 :          nonbonded%pot(start + isec)%pot%set(1)%gal21%a12 = rvalues(2)
    1708           1 :          nonbonded%pot(start + isec)%pot%set(1)%gal21%a13 = rvalues(3)
    1709             : 
    1710           1 :          CALL section_vals_val_get(gal21_section, "a2", i_rep_section=isec, r_vals=rvalues)
    1711           1 :          nonbonded%pot(start + isec)%pot%set(1)%gal21%a21 = rvalues(1)
    1712           1 :          nonbonded%pot(start + isec)%pot%set(1)%gal21%a22 = rvalues(2)
    1713           1 :          nonbonded%pot(start + isec)%pot%set(1)%gal21%a23 = rvalues(3)
    1714             : 
    1715           1 :          CALL section_vals_val_get(gal21_section, "a3", i_rep_section=isec, r_vals=rvalues)
    1716           1 :          nonbonded%pot(start + isec)%pot%set(1)%gal21%a31 = rvalues(1)
    1717           1 :          nonbonded%pot(start + isec)%pot%set(1)%gal21%a32 = rvalues(2)
    1718           1 :          nonbonded%pot(start + isec)%pot%set(1)%gal21%a33 = rvalues(3)
    1719             : 
    1720           1 :          CALL section_vals_val_get(gal21_section, "a4", i_rep_section=isec, r_vals=rvalues)
    1721           1 :          nonbonded%pot(start + isec)%pot%set(1)%gal21%a41 = rvalues(1)
    1722           1 :          nonbonded%pot(start + isec)%pot%set(1)%gal21%a42 = rvalues(2)
    1723           1 :          nonbonded%pot(start + isec)%pot%set(1)%gal21%a43 = rvalues(3)
    1724             : 
    1725           1 :          CALL section_vals_val_get(gal21_section, "A", i_rep_section=isec, r_vals=rvalues)
    1726           1 :          nonbonded%pot(start + isec)%pot%set(1)%gal21%AO1 = rvalues(1)
    1727           1 :          nonbonded%pot(start + isec)%pot%set(1)%gal21%AO2 = rvalues(2)
    1728             : 
    1729           1 :          CALL section_vals_val_get(gal21_section, "B", i_rep_section=isec, r_vals=rvalues)
    1730           1 :          nonbonded%pot(start + isec)%pot%set(1)%gal21%BO1 = rvalues(1)
    1731           1 :          nonbonded%pot(start + isec)%pot%set(1)%gal21%BO2 = rvalues(2)
    1732             : 
    1733             :          CALL section_vals_val_get(gal21_section, "C", i_rep_section=isec, &
    1734           1 :                                    r_val=nonbonded%pot(start + isec)%pot%set(1)%gal21%c)
    1735             : 
    1736           1 :          CALL section_vals_val_get(gal21_section, "AH", i_rep_section=isec, r_vals=rvalues)
    1737           1 :          nonbonded%pot(start + isec)%pot%set(1)%gal21%AH1 = rvalues(1)
    1738           1 :          nonbonded%pot(start + isec)%pot%set(1)%gal21%AH2 = rvalues(2)
    1739             : 
    1740           1 :          CALL section_vals_val_get(gal21_section, "BH", i_rep_section=isec, r_vals=rvalues)
    1741           1 :          nonbonded%pot(start + isec)%pot%set(1)%gal21%BH1 = rvalues(1)
    1742           1 :          nonbonded%pot(start + isec)%pot%set(1)%gal21%BH2 = rvalues(2)
    1743             : 
    1744           1 :          NULLIFY (list)
    1745           1 :          subsection => section_vals_get_subs_vals(section, "GCN", i_rep_section=isec)
    1746           1 :          CALL section_vals_val_get(subsection, "_DEFAULT_KEYWORD_", n_rep_val=nval)
    1747           3 :          ALLOCATE (nonbonded%pot(start + isec)%pot%set(1)%gal21%gcn(nval))
    1748           1 :          CALL section_vals_list_get(subsection, "_DEFAULT_KEYWORD_", list=list)
    1749         871 :          DO iatom = 1, nval
    1750             :             ! we use only the first default_string_length characters of each line
    1751         870 :             is_ok = cp_sll_val_next(list, val)
    1752         870 :             CALL val_get(val, r_val=rval)
    1753             :             ! assign values
    1754         871 :             nonbonded%pot(start + isec)%pot%set(1)%gal21%gcn(iatom) = rval
    1755             :          END DO
    1756             : 
    1757             :          CALL section_vals_val_get(gal21_section, "Fit_express", i_rep_section=isec, &
    1758           1 :                                    l_val=nonbonded%pot(start + isec)%pot%set(1)%gal21%express)
    1759             : 
    1760             :          ! ! In case it is defined override the standard specification of RCUT
    1761           1 :          CALL section_vals_val_get(gal21_section, "RCUT", i_rep_section=isec, n_rep_val=n_rep)
    1762           3 :          IF (n_rep == 1) THEN
    1763           1 :             CALL section_vals_val_get(gal21_section, "RCUT", i_rep_section=isec, r_val=rcut)
    1764           1 :             nonbonded%pot(start + isec)%pot%rcutsq = rcut**2
    1765           1 :             nonbonded%pot(start + isec)%pot%set(1)%gal21%rcutsq = rcut**2
    1766             :          END IF
    1767             :       END DO
    1768           1 :    END SUBROUTINE read_gal21_section
    1769             : 
    1770             : ! **************************************************************************************************
    1771             : !> \brief Reads the siepmann section
    1772             : !> \param nonbonded ...
    1773             : !> \param section ...
    1774             : !> \param start ...
    1775             : !> \param siepmann_section ...
    1776             : !> \author Dorothea Golze
    1777             : ! **************************************************************************************************
    1778           5 :    SUBROUTINE read_siepmann_section(nonbonded, section, start, siepmann_section)
    1779             :       TYPE(pair_potential_p_type), POINTER               :: nonbonded
    1780             :       TYPE(section_vals_type), POINTER                   :: section
    1781             :       INTEGER, INTENT(IN)                                :: start
    1782             :       TYPE(section_vals_type), POINTER                   :: siepmann_section
    1783             : 
    1784             :       CHARACTER(LEN=default_string_length), &
    1785           5 :          DIMENSION(:), POINTER                           :: atm_names
    1786             :       INTEGER                                            :: isec, n_items, n_rep
    1787             :       REAL(KIND=dp)                                      :: rcut
    1788             : 
    1789           5 :       CALL section_vals_get(section, n_repetition=n_items)
    1790          10 :       DO isec = 1, n_items
    1791           5 :          CALL cite_reference(Siepmann1995)
    1792           5 :          CALL section_vals_val_get(section, "ATOMS", i_rep_section=isec, c_vals=atm_names)
    1793             : 
    1794          10 :          nonbonded%pot(start + isec)%pot%type = siepmann_type
    1795           5 :          nonbonded%pot(start + isec)%pot%at1 = atm_names(1)
    1796           5 :          nonbonded%pot(start + isec)%pot%at2 = atm_names(2)
    1797           5 :          CALL uppercase(nonbonded%pot(start + isec)%pot%at1)
    1798           5 :          CALL uppercase(nonbonded%pot(start + isec)%pot%at2)
    1799             : 
    1800             :          CALL section_vals_val_get(siepmann_section, "B", i_rep_section=isec, &
    1801           5 :                                    r_val=nonbonded%pot(start + isec)%pot%set(1)%siepmann%B)
    1802             :          CALL section_vals_val_get(siepmann_section, "D", i_rep_section=isec, &
    1803           5 :                                    r_val=nonbonded%pot(start + isec)%pot%set(1)%siepmann%D)
    1804             :          CALL section_vals_val_get(siepmann_section, "E", i_rep_section=isec, &
    1805           5 :                                    r_val=nonbonded%pot(start + isec)%pot%set(1)%siepmann%E)
    1806             :          CALL section_vals_val_get(siepmann_section, "F", i_rep_section=isec, &
    1807           5 :                                    r_val=nonbonded%pot(start + isec)%pot%set(1)%siepmann%F)
    1808             :          CALL section_vals_val_get(siepmann_section, "beta", i_rep_section=isec, &
    1809           5 :                                    r_val=nonbonded%pot(start + isec)%pot%set(1)%siepmann%beta)
    1810             :          CALL section_vals_val_get(siepmann_section, "ALLOW_OH_FORMATION", i_rep_section=isec, &
    1811           5 :                                    l_val=nonbonded%pot(start + isec)%pot%set(1)%siepmann%allow_oh_formation)
    1812             :          CALL section_vals_val_get(siepmann_section, "ALLOW_H3O_FORMATION", i_rep_section=isec, &
    1813           5 :                                    l_val=nonbonded%pot(start + isec)%pot%set(1)%siepmann%allow_h3o_formation)
    1814             :          CALL section_vals_val_get(siepmann_section, "ALLOW_O_FORMATION", i_rep_section=isec, &
    1815           5 :                                    l_val=nonbonded%pot(start + isec)%pot%set(1)%siepmann%allow_o_formation)
    1816             : 
    1817             :          ! ! In case it is defined override the standard specification of RCUT
    1818           5 :          CALL section_vals_val_get(siepmann_section, "RCUT", i_rep_section=isec, n_rep_val=n_rep)
    1819          10 :          IF (n_rep == 1) THEN
    1820           5 :             CALL section_vals_val_get(siepmann_section, "RCUT", i_rep_section=isec, r_val=rcut)
    1821           5 :             nonbonded%pot(start + isec)%pot%rcutsq = rcut**2
    1822           5 :             nonbonded%pot(start + isec)%pot%set(1)%siepmann%rcutsq = rcut**2
    1823             :          END IF
    1824             :       END DO
    1825           5 :    END SUBROUTINE read_siepmann_section
    1826             : 
    1827             : ! **************************************************************************************************
    1828             : !> \brief Reads the Buckingham plus Morse potential section
    1829             : !> \param nonbonded ...
    1830             : !> \param section ...
    1831             : !> \param start ...
    1832             : !> \author MI
    1833             : ! **************************************************************************************************
    1834           6 :    SUBROUTINE read_bm_section(nonbonded, section, start)
    1835             :       TYPE(pair_potential_p_type), POINTER               :: nonbonded
    1836             :       TYPE(section_vals_type), POINTER                   :: section
    1837             :       INTEGER, INTENT(IN)                                :: start
    1838             : 
    1839             :       CHARACTER(LEN=default_string_length), &
    1840           6 :          DIMENSION(:), POINTER                           :: atm_names
    1841             :       INTEGER                                            :: isec, n_items, n_rep
    1842             :       REAL(KIND=dp)                                      :: a1, a2, b1, b2, beta, c, d, f0, r0, rcut
    1843             : 
    1844           6 :       CALL section_vals_get(section, n_repetition=n_items)
    1845          20 :       DO isec = 1, n_items
    1846          14 :          CALL cite_reference(Yamada2000)
    1847          14 :          CALL section_vals_val_get(section, "ATOMS", i_rep_section=isec, c_vals=atm_names)
    1848          14 :          CALL section_vals_val_get(section, "F0", i_rep_section=isec, r_val=f0)
    1849          14 :          CALL section_vals_val_get(section, "A1", i_rep_section=isec, r_val=a1)
    1850          14 :          CALL section_vals_val_get(section, "A2", i_rep_section=isec, r_val=a2)
    1851          14 :          CALL section_vals_val_get(section, "B1", i_rep_section=isec, r_val=b1)
    1852          14 :          CALL section_vals_val_get(section, "B2", i_rep_section=isec, r_val=b2)
    1853          14 :          CALL section_vals_val_get(section, "C", i_rep_section=isec, r_val=c)
    1854          14 :          CALL section_vals_val_get(section, "D", i_rep_section=isec, r_val=d)
    1855          14 :          CALL section_vals_val_get(section, "R0", i_rep_section=isec, r_val=r0)
    1856          14 :          CALL section_vals_val_get(section, "Beta", i_rep_section=isec, r_val=beta)
    1857          14 :          CALL section_vals_val_get(section, "RCUT", i_rep_section=isec, r_val=rcut)
    1858             : 
    1859          28 :          nonbonded%pot(start + isec)%pot%type = bm_type
    1860          14 :          nonbonded%pot(start + isec)%pot%at1 = atm_names(1)
    1861          14 :          nonbonded%pot(start + isec)%pot%at2 = atm_names(2)
    1862          14 :          CALL uppercase(nonbonded%pot(start + isec)%pot%at1)
    1863          14 :          CALL uppercase(nonbonded%pot(start + isec)%pot%at2)
    1864          14 :          nonbonded%pot(start + isec)%pot%set(1)%buckmo%f0 = f0
    1865          14 :          nonbonded%pot(start + isec)%pot%set(1)%buckmo%a1 = a1
    1866          14 :          nonbonded%pot(start + isec)%pot%set(1)%buckmo%a2 = a2
    1867          14 :          nonbonded%pot(start + isec)%pot%set(1)%buckmo%b1 = b1
    1868          14 :          nonbonded%pot(start + isec)%pot%set(1)%buckmo%b2 = b2
    1869          14 :          nonbonded%pot(start + isec)%pot%set(1)%buckmo%c = c
    1870          14 :          nonbonded%pot(start + isec)%pot%set(1)%buckmo%d = d
    1871          14 :          nonbonded%pot(start + isec)%pot%set(1)%buckmo%r0 = r0
    1872          14 :          nonbonded%pot(start + isec)%pot%set(1)%buckmo%beta = beta
    1873          14 :          nonbonded%pot(start + isec)%pot%rcutsq = rcut*rcut
    1874             :          !
    1875          14 :          CALL section_vals_val_get(section, "RMIN", i_rep_section=isec, n_rep_val=n_rep)
    1876          14 :          IF (n_rep == 1) CALL section_vals_val_get(section, "RMIN", i_rep_section=isec, &
    1877           0 :                                                    r_val=nonbonded%pot(start + isec)%pot%set(1)%rmin)
    1878          14 :          CALL section_vals_val_get(section, "RMAX", i_rep_section=isec, n_rep_val=n_rep)
    1879          14 :          IF (n_rep == 1) CALL section_vals_val_get(section, "RMAX", i_rep_section=isec, &
    1880          48 :                                                    r_val=nonbonded%pot(start + isec)%pot%set(1)%rmax)
    1881             :       END DO
    1882           6 :    END SUBROUTINE read_bm_section
    1883             : 
    1884             : ! **************************************************************************************************
    1885             : !> \brief Reads the TABPOT section
    1886             : !> \param nonbonded ...
    1887             : !> \param section ...
    1888             : !> \param start ...
    1889             : !> \param para_env ...
    1890             : !> \param mm_section ...
    1891             : !> \author Alex Mironenko, Da Teng
    1892             : ! **************************************************************************************************
    1893           8 :    SUBROUTINE read_tabpot_section(nonbonded, section, start, para_env, mm_section)
    1894             :       TYPE(pair_potential_p_type), POINTER               :: nonbonded
    1895             :       TYPE(section_vals_type), POINTER                   :: section
    1896             :       INTEGER, INTENT(IN)                                :: start
    1897             :       TYPE(mp_para_env_type), POINTER                    :: para_env
    1898             :       TYPE(section_vals_type), POINTER                   :: mm_section
    1899             : 
    1900             :       CHARACTER(LEN=default_string_length), &
    1901           8 :          DIMENSION(:), POINTER                           :: atm_names
    1902             :       INTEGER                                            :: isec, n_items
    1903             : 
    1904           8 :       CALL section_vals_get(section, n_repetition=n_items)
    1905          32 :       DO isec = 1, n_items
    1906          24 :          CALL section_vals_val_get(section, "ATOMS", i_rep_section=isec, c_vals=atm_names)
    1907          48 :          nonbonded%pot(start + isec)%pot%type = tab_type
    1908          24 :          nonbonded%pot(start + isec)%pot%at1 = atm_names(1)
    1909          24 :          nonbonded%pot(start + isec)%pot%at2 = atm_names(2)
    1910          24 :          CALL uppercase(nonbonded%pot(start + isec)%pot%at1)
    1911          24 :          CALL uppercase(nonbonded%pot(start + isec)%pot%at2)
    1912             :          CALL section_vals_val_get(section, "PARM_FILE_NAME", i_rep_section=isec, &
    1913          24 :                                    c_val=nonbonded%pot(start + isec)%pot%set(1)%tab%tabpot_file_name)
    1914          24 :          CALL read_tabpot_data(nonbonded%pot(start + isec)%pot%set(1)%tab, para_env, mm_section)
    1915          32 :          nonbonded%pot(start + isec)%pot%set(1)%tab%index = isec
    1916             :       END DO
    1917           8 :    END SUBROUTINE read_tabpot_section
    1918             : 
    1919             : ! **************************************************************************************************
    1920             : !> \brief Reads the CHARGE section
    1921             : !> \param charge_atm ...
    1922             : !> \param charge ...
    1923             : !> \param section ...
    1924             : !> \param start ...
    1925             : !> \author teo
    1926             : ! **************************************************************************************************
    1927        2105 :    SUBROUTINE read_chrg_section(charge_atm, charge, section, start)
    1928             :       CHARACTER(LEN=default_string_length), &
    1929             :          DIMENSION(:), POINTER                           :: charge_atm
    1930             :       REAL(KIND=dp), DIMENSION(:), POINTER               :: charge
    1931             :       TYPE(section_vals_type), POINTER                   :: section
    1932             :       INTEGER, INTENT(IN)                                :: start
    1933             : 
    1934             :       CHARACTER(LEN=default_string_length)               :: atm_name
    1935             :       INTEGER                                            :: isec, n_items
    1936             : 
    1937        2105 :       CALL section_vals_get(section, n_repetition=n_items)
    1938        7258 :       DO isec = 1, n_items
    1939        5153 :          CALL section_vals_val_get(section, "ATOM", i_rep_section=isec, c_val=atm_name)
    1940        5153 :          charge_atm(start + isec) = atm_name
    1941        5153 :          CALL uppercase(charge_atm(start + isec))
    1942        7258 :          CALL section_vals_val_get(section, "CHARGE", i_rep_section=isec, r_val=charge(start + isec))
    1943             :       END DO
    1944        2105 :    END SUBROUTINE read_chrg_section
    1945             : 
    1946             : ! **************************************************************************************************
    1947             : !> \brief Reads the POLARIZABILITY section
    1948             : !> \param apol_atm ...
    1949             : !> \param apol ...
    1950             : !> \param damping_list ...
    1951             : !> \param section ...
    1952             : !> \param start ...
    1953             : !> \author Marcel Baer
    1954             : ! **************************************************************************************************
    1955          34 :    SUBROUTINE read_apol_section(apol_atm, apol, damping_list, section, &
    1956             :                                 start)
    1957             :       CHARACTER(LEN=default_string_length), &
    1958             :          DIMENSION(:), POINTER                           :: apol_atm
    1959             :       REAL(KIND=dp), DIMENSION(:), POINTER               :: apol
    1960             :       TYPE(damping_info_type), DIMENSION(:), POINTER     :: damping_list
    1961             :       TYPE(section_vals_type), POINTER                   :: section
    1962             :       INTEGER, INTENT(IN)                                :: start
    1963             : 
    1964             :       CHARACTER(LEN=default_string_length)               :: atm_name
    1965             :       INTEGER                                            :: isec, isec_damp, n_damp, n_items, &
    1966             :                                                             start_damp, tmp_damp
    1967             :       TYPE(section_vals_type), POINTER                   :: tmp_section
    1968             : 
    1969          34 :       CALL section_vals_get(section, n_repetition=n_items)
    1970          34 :       NULLIFY (tmp_section)
    1971          34 :       n_damp = 0
    1972             : ! *** Counts number of DIPOLE%DAMPING sections ****
    1973         102 :       DO isec = 1, n_items
    1974             :          tmp_section => section_vals_get_subs_vals(section, "DAMPING", &
    1975          68 :                                                    i_rep_section=isec)
    1976          68 :          CALL section_vals_get(tmp_section, n_repetition=tmp_damp)
    1977         102 :          n_damp = n_damp + tmp_damp
    1978             : 
    1979             :       END DO
    1980             : 
    1981          34 :       IF (n_damp > 0) THEN
    1982          42 :          ALLOCATE (damping_list(1:n_damp))
    1983             :       END IF
    1984             : 
    1985             : ! *** Reads DIPOLE sections *****
    1986          34 :       start_damp = 0
    1987         102 :       DO isec = 1, n_items
    1988          68 :          CALL section_vals_val_get(section, "ATOM", i_rep_section=isec, c_val=atm_name)
    1989          68 :          apol_atm(start + isec) = atm_name
    1990          68 :          CALL uppercase(apol_atm(start + isec))
    1991          68 :          CALL section_vals_val_get(section, "APOL", i_rep_section=isec, r_val=apol(start + isec))
    1992             : 
    1993             :          tmp_section => section_vals_get_subs_vals(section, "DAMPING", &
    1994          68 :                                                    i_rep_section=isec)
    1995          68 :          CALL section_vals_get(tmp_section, n_repetition=tmp_damp)
    1996          80 :          DO isec_damp = 1, tmp_damp
    1997          12 :             damping_list(start_damp + isec_damp)%atm_name1 = apol_atm(start + isec)
    1998             :             CALL section_vals_val_get(tmp_section, "ATOM", i_rep_section=isec_damp, &
    1999          12 :                                       c_val=atm_name)
    2000          12 :             damping_list(start_damp + isec_damp)%atm_name2 = atm_name
    2001          12 :             CALL uppercase(damping_list(start_damp + isec_damp)%atm_name2)
    2002             :             CALL section_vals_val_get(tmp_section, "TYPE", i_rep_section=isec_damp, &
    2003          12 :                                       c_val=atm_name)
    2004          12 :             damping_list(start_damp + isec_damp)%dtype = atm_name
    2005          12 :             CALL uppercase(damping_list(start_damp + isec_damp)%dtype)
    2006             : 
    2007             :             CALL section_vals_val_get(tmp_section, "ORDER", i_rep_section=isec_damp, &
    2008          12 :                                       i_val=damping_list(start_damp + isec_damp)%order)
    2009             :             CALL section_vals_val_get(tmp_section, "BIJ", i_rep_section=isec_damp, &
    2010          12 :                                       r_val=damping_list(start_damp + isec_damp)%bij)
    2011             :             CALL section_vals_val_get(tmp_section, "CIJ", i_rep_section=isec_damp, &
    2012          80 :                                       r_val=damping_list(start_damp + isec_damp)%cij)
    2013             :          END DO
    2014         170 :          start_damp = start_damp + tmp_damp
    2015             : 
    2016             :       END DO
    2017             : 
    2018          34 :    END SUBROUTINE read_apol_section
    2019             : 
    2020             : ! **************************************************************************************************
    2021             : !> \brief Reads the QUADRUPOLE POLARIZABILITY section
    2022             : !> \param cpol_atm ...
    2023             : !> \param cpol ...
    2024             : !> \param section ...
    2025             : !> \param start ...
    2026             : !> \author Marcel Baer
    2027             : ! **************************************************************************************************
    2028           0 :    SUBROUTINE read_cpol_section(cpol_atm, cpol, section, start)
    2029             :       CHARACTER(LEN=default_string_length), &
    2030             :          DIMENSION(:), POINTER                           :: cpol_atm
    2031             :       REAL(KIND=dp), DIMENSION(:), POINTER               :: cpol
    2032             :       TYPE(section_vals_type), POINTER                   :: section
    2033             :       INTEGER, INTENT(IN)                                :: start
    2034             : 
    2035             :       CHARACTER(LEN=default_string_length)               :: atm_name
    2036             :       INTEGER                                            :: isec, n_items
    2037             : 
    2038           0 :       CALL section_vals_get(section, n_repetition=n_items)
    2039           0 :       DO isec = 1, n_items
    2040           0 :          CALL section_vals_val_get(section, "ATOM", i_rep_section=isec, c_val=atm_name)
    2041           0 :          cpol_atm(start + isec) = atm_name
    2042           0 :          CALL uppercase(cpol_atm(start + isec))
    2043           0 :          CALL section_vals_val_get(section, "CPOL", i_rep_section=isec, r_val=cpol(start + isec))
    2044             :       END DO
    2045           0 :    END SUBROUTINE read_cpol_section
    2046             : 
    2047             : ! **************************************************************************************************
    2048             : !> \brief Reads the SHELL section
    2049             : !> \param shell_list ...
    2050             : !> \param section ...
    2051             : !> \param start ...
    2052             : !> \author Marcella Iannuzzi
    2053             : ! **************************************************************************************************
    2054         256 :    SUBROUTINE read_shell_section(shell_list, section, start)
    2055             : 
    2056             :       TYPE(shell_p_type), DIMENSION(:), POINTER          :: shell_list
    2057             :       TYPE(section_vals_type), POINTER                   :: section
    2058             :       INTEGER, INTENT(IN)                                :: start
    2059             : 
    2060             :       CHARACTER(LEN=default_string_length)               :: atm_name
    2061             :       INTEGER                                            :: i_rep, n_rep
    2062             :       REAL(dp)                                           :: ccharge, cutoff, k, maxdist, mfrac, &
    2063             :                                                             scharge
    2064             : 
    2065         256 :       CALL section_vals_get(section, n_repetition=n_rep)
    2066             : 
    2067         706 :       DO i_rep = 1, n_rep
    2068             :          CALL section_vals_val_get(section, "_SECTION_PARAMETERS_", &
    2069         450 :                                    c_val=atm_name, i_rep_section=i_rep)
    2070         450 :          CALL uppercase(atm_name)
    2071         450 :          shell_list(start + i_rep)%atm_name = atm_name
    2072         450 :          CALL section_vals_val_get(section, "CORE_CHARGE", i_rep_section=i_rep, r_val=ccharge)
    2073         450 :          shell_list(start + i_rep)%shell%charge_core = ccharge
    2074         450 :          CALL section_vals_val_get(section, "SHELL_CHARGE", i_rep_section=i_rep, r_val=scharge)
    2075         450 :          shell_list(start + i_rep)%shell%charge_shell = scharge
    2076         450 :          CALL section_vals_val_get(section, "MASS_FRACTION", i_rep_section=i_rep, r_val=mfrac)
    2077         450 :          shell_list(start + i_rep)%shell%massfrac = mfrac
    2078         450 :          CALL section_vals_val_get(section, "K2_SPRING", i_rep_section=i_rep, r_val=k)
    2079         450 :          IF (k < 0.0_dp) THEN
    2080             :             CALL cp_abort(__LOCATION__, &
    2081             :                           "An invalid value was specified for the force constant k2 of the core-shell "// &
    2082           0 :                           "spring potential")
    2083             :          END IF
    2084         450 :          shell_list(start + i_rep)%shell%k2_spring = k
    2085         450 :          CALL section_vals_val_get(section, "K4_SPRING", i_rep_section=i_rep, r_val=k)
    2086         450 :          IF (k < 0.0_dp) THEN
    2087             :             CALL cp_abort(__LOCATION__, &
    2088             :                           "An invalid value was specified for the force constant k4 of the core-shell "// &
    2089           0 :                           "spring potential")
    2090             :          END IF
    2091         450 :          shell_list(start + i_rep)%shell%k4_spring = k
    2092         450 :          CALL section_vals_val_get(section, "MAX_DISTANCE", i_rep_section=i_rep, r_val=maxdist)
    2093         450 :          shell_list(start + i_rep)%shell%max_dist = maxdist
    2094         450 :          CALL section_vals_val_get(section, "SHELL_CUTOFF", i_rep_section=i_rep, r_val=cutoff)
    2095        1606 :          shell_list(start + i_rep)%shell%shell_cutoff = cutoff
    2096             :       END DO
    2097             : 
    2098         256 :    END SUBROUTINE read_shell_section
    2099             : 
    2100             : ! **************************************************************************************************
    2101             : !> \brief Reads the BONDS section
    2102             : !> \param bond_kind ...
    2103             : !> \param bond_a ...
    2104             : !> \param bond_b ...
    2105             : !> \param bond_k ...
    2106             : !> \param bond_r0 ...
    2107             : !> \param bond_cs ...
    2108             : !> \param section ...
    2109             : !> \param start ...
    2110             : !> \author teo
    2111             : ! **************************************************************************************************
    2112         973 :    SUBROUTINE read_bonds_section(bond_kind, bond_a, bond_b, bond_k, bond_r0, bond_cs, section, start)
    2113             :       INTEGER, DIMENSION(:), POINTER                     :: bond_kind
    2114             :       CHARACTER(LEN=default_string_length), &
    2115             :          DIMENSION(:), POINTER                           :: bond_a, bond_b
    2116             :       REAL(KIND=dp), DIMENSION(:, :), POINTER            :: bond_k
    2117             :       REAL(KIND=dp), DIMENSION(:), POINTER               :: bond_r0, bond_cs
    2118             :       TYPE(section_vals_type), POINTER                   :: section
    2119             :       INTEGER, INTENT(IN)                                :: start
    2120             : 
    2121             :       CHARACTER(LEN=default_string_length), &
    2122         973 :          DIMENSION(:), POINTER                           :: atm_names
    2123             :       INTEGER                                            :: isec, k, n_items
    2124         973 :       REAL(KIND=dp), DIMENSION(:), POINTER               :: Kvals
    2125             : 
    2126         973 :       NULLIFY (Kvals, atm_names)
    2127         973 :       CALL section_vals_get(section, n_repetition=n_items)
    2128        2822 :       DO isec = 1, n_items
    2129        1849 :          CALL section_vals_val_get(section, "KIND", i_rep_section=isec, i_val=bond_kind(start + isec))
    2130        1849 :          CALL section_vals_val_get(section, "ATOMS", i_rep_section=isec, c_vals=atm_names)
    2131        1849 :          bond_a(start + isec) = atm_names(1)
    2132        1849 :          bond_b(start + isec) = atm_names(2)
    2133        1849 :          CALL uppercase(bond_a(start + isec))
    2134        1849 :          CALL uppercase(bond_b(start + isec))
    2135        1849 :          CALL section_vals_val_get(section, "K", i_rep_section=isec, r_vals=Kvals)
    2136        1849 :          CPASSERT(SIZE(Kvals) <= 3)
    2137        7396 :          bond_k(:, start + isec) = 0.0_dp
    2138        3736 :          DO k = 1, SIZE(Kvals)
    2139        3736 :             bond_k(k, start + isec) = Kvals(k)
    2140             :          END DO
    2141        1849 :          CALL section_vals_val_get(section, "R0", i_rep_section=isec, r_val=bond_r0(start + isec))
    2142        2822 :          CALL section_vals_val_get(section, "CS", i_rep_section=isec, r_val=bond_cs(start + isec))
    2143             :       END DO
    2144         973 :    END SUBROUTINE read_bonds_section
    2145             : 
    2146             : ! **************************************************************************************************
    2147             : !> \brief Reads the BENDS section
    2148             : !> \param bend_kind ...
    2149             : !> \param bend_a ...
    2150             : !> \param bend_b ...
    2151             : !> \param bend_c ...
    2152             : !> \param bend_k ...
    2153             : !> \param bend_theta0 ...
    2154             : !> \param bend_cb ...
    2155             : !> \param bend_r012 ...
    2156             : !> \param bend_r032 ...
    2157             : !> \param bend_kbs12 ...
    2158             : !> \param bend_kbs32 ...
    2159             : !> \param bend_kss ...
    2160             : !> \param bend_legendre ...
    2161             : !> \param section ...
    2162             : !> \param start ...
    2163             : !> \author teo
    2164             : ! **************************************************************************************************
    2165         937 :    SUBROUTINE read_bends_section(bend_kind, bend_a, bend_b, bend_c, bend_k, bend_theta0, bend_cb, &
    2166             :                                  bend_r012, bend_r032, bend_kbs12, bend_kbs32, bend_kss, bend_legendre, &
    2167             :                                  section, start)
    2168             :       INTEGER, DIMENSION(:), POINTER                     :: bend_kind
    2169             :       CHARACTER(LEN=default_string_length), &
    2170             :          DIMENSION(:), POINTER                           :: bend_a, bend_b, bend_c
    2171             :       REAL(KIND=dp), DIMENSION(:), POINTER               :: bend_k, bend_theta0, bend_cb, bend_r012, &
    2172             :                                                             bend_r032, bend_kbs12, bend_kbs32, &
    2173             :                                                             bend_kss
    2174             :       TYPE(legendre_data_type), DIMENSION(:), POINTER    :: bend_legendre
    2175             :       TYPE(section_vals_type), POINTER                   :: section
    2176             :       INTEGER, INTENT(IN)                                :: start
    2177             : 
    2178             :       CHARACTER(LEN=default_string_length), &
    2179         937 :          DIMENSION(:), POINTER                           :: atm_names
    2180             :       INTEGER                                            :: isec, k, n_items, n_rep
    2181         937 :       REAL(KIND=dp), DIMENSION(:), POINTER               :: Kvals, r_values
    2182             : 
    2183         937 :       NULLIFY (Kvals, atm_names)
    2184         937 :       CALL section_vals_get(section, n_repetition=n_items)
    2185        3054 :       bend_legendre%order = 0
    2186        3054 :       DO isec = 1, n_items
    2187        2117 :          CALL section_vals_val_get(section, "KIND", i_rep_section=isec, i_val=bend_kind(start + isec))
    2188        2117 :          CALL section_vals_val_get(section, "ATOMS", i_rep_section=isec, c_vals=atm_names)
    2189        2117 :          bend_a(start + isec) = atm_names(1)
    2190        2117 :          bend_b(start + isec) = atm_names(2)
    2191        2117 :          bend_c(start + isec) = atm_names(3)
    2192        2117 :          CALL uppercase(bend_a(start + isec))
    2193        2117 :          CALL uppercase(bend_b(start + isec))
    2194        2117 :          CALL uppercase(bend_c(start + isec))
    2195        2117 :          CALL section_vals_val_get(section, "K", i_rep_section=isec, r_vals=Kvals)
    2196        2117 :          CPASSERT(SIZE(Kvals) == 1)
    2197        2117 :          bend_k(start + isec) = Kvals(1)
    2198        2117 :          CALL section_vals_val_get(section, "THETA0", i_rep_section=isec, r_val=bend_theta0(start + isec))
    2199        2117 :          CALL section_vals_val_get(section, "CB", i_rep_section=isec, r_val=bend_cb(start + isec))
    2200        2117 :          CALL section_vals_val_get(section, "R012", i_rep_section=isec, r_val=bend_r012(start + isec))
    2201        2117 :          CALL section_vals_val_get(section, "R032", i_rep_section=isec, r_val=bend_r032(start + isec))
    2202        2117 :          CALL section_vals_val_get(section, "KBS12", i_rep_section=isec, r_val=bend_kbs12(start + isec))
    2203        2117 :          CALL section_vals_val_get(section, "KBS32", i_rep_section=isec, r_val=bend_kbs32(start + isec))
    2204        2117 :          CALL section_vals_val_get(section, "KSS", i_rep_section=isec, r_val=bend_kss(start + isec))
    2205             :          ! get legendre based data
    2206        2117 :          CALL section_vals_val_get(section, "LEGENDRE", i_rep_section=isec, n_rep_val=n_rep)
    2207        5171 :          DO k = 1, n_rep
    2208        2117 :             CALL section_vals_val_get(section, "LEGENDRE", i_rep_val=k, r_vals=r_values, i_rep_section=isec)
    2209        2117 :             bend_legendre(start + isec)%order = SIZE(r_values)
    2210        2117 :             IF (ASSOCIATED(bend_legendre(start + isec)%coeffs)) THEN
    2211           0 :                DEALLOCATE (bend_legendre(start + isec)%coeffs)
    2212             :             END IF
    2213        6351 :             ALLOCATE (bend_legendre(start + isec)%coeffs(bend_legendre(start + isec)%order))
    2214       10665 :             bend_legendre(start + isec)%coeffs = r_values
    2215             :          END DO
    2216             :       END DO
    2217         937 :    END SUBROUTINE read_bends_section
    2218             : 
    2219             : ! **************************************************************************************************
    2220             : !> \brief ...
    2221             : !> \param ub_kind ...
    2222             : !> \param ub_a ...
    2223             : !> \param ub_b ...
    2224             : !> \param ub_c ...
    2225             : !> \param ub_k ...
    2226             : !> \param ub_r0 ...
    2227             : !> \param section ...
    2228             : !> \param start ...
    2229             : ! **************************************************************************************************
    2230         937 :    SUBROUTINE read_ubs_section(ub_kind, ub_a, ub_b, ub_c, ub_k, ub_r0, section, start)
    2231             :       INTEGER, DIMENSION(:), POINTER                     :: ub_kind
    2232             :       CHARACTER(LEN=default_string_length), &
    2233             :          DIMENSION(:), POINTER                           :: ub_a, ub_b, ub_c
    2234             :       REAL(KIND=dp), DIMENSION(:, :), POINTER            :: ub_k
    2235             :       REAL(KIND=dp), DIMENSION(:), POINTER               :: ub_r0
    2236             :       TYPE(section_vals_type), POINTER                   :: section
    2237             :       INTEGER, INTENT(IN)                                :: start
    2238             : 
    2239             :       CHARACTER(LEN=default_string_length), &
    2240         937 :          DIMENSION(:), POINTER                           :: atm_names
    2241             :       INTEGER                                            :: isec, k, n_items
    2242             :       LOGICAL                                            :: explicit
    2243         937 :       REAL(KIND=dp), DIMENSION(:), POINTER               :: Kvals
    2244             :       TYPE(section_vals_type), POINTER                   :: subsection
    2245             : 
    2246         937 :       NULLIFY (atm_names)
    2247         937 :       CALL section_vals_get(section, n_repetition=n_items)
    2248        3054 :       DO isec = 1, n_items
    2249        2117 :          subsection => section_vals_get_subs_vals(section, "UB", i_rep_section=isec)
    2250        2117 :          CALL section_vals_get(subsection, explicit=explicit)
    2251        3054 :          IF (explicit) THEN
    2252           4 :             CALL section_vals_val_get(subsection, "KIND", i_val=ub_kind(start + isec))
    2253           4 :             CALL section_vals_val_get(section, "ATOMS", i_rep_section=isec, c_vals=atm_names)
    2254           4 :             ub_a(start + isec) = atm_names(1)
    2255           4 :             ub_b(start + isec) = atm_names(2)
    2256           4 :             ub_c(start + isec) = atm_names(3)
    2257           4 :             CALL uppercase(ub_a(start + isec))
    2258           4 :             CALL uppercase(ub_b(start + isec))
    2259           4 :             CALL uppercase(ub_c(start + isec))
    2260           4 :             CALL section_vals_val_get(subsection, "K", r_vals=Kvals)
    2261           4 :             CPASSERT(SIZE(Kvals) <= 3)
    2262          16 :             ub_k(:, start + isec) = 0.0_dp
    2263          12 :             DO k = 1, SIZE(Kvals)
    2264          12 :                ub_k(k, start + isec) = Kvals(k)
    2265             :             END DO
    2266           4 :             CALL section_vals_val_get(subsection, "R0", r_val=ub_r0(start + isec))
    2267             :          END IF
    2268             :       END DO
    2269         937 :    END SUBROUTINE read_ubs_section
    2270             : 
    2271             : ! **************************************************************************************************
    2272             : !> \brief Reads the TORSIONS section
    2273             : !> \param torsion_kind ...
    2274             : !> \param torsion_a ...
    2275             : !> \param torsion_b ...
    2276             : !> \param torsion_c ...
    2277             : !> \param torsion_d ...
    2278             : !> \param torsion_k ...
    2279             : !> \param torsion_phi0 ...
    2280             : !> \param torsion_m ...
    2281             : !> \param section ...
    2282             : !> \param start ...
    2283             : !> \author teo
    2284             : ! **************************************************************************************************
    2285           6 :    SUBROUTINE read_torsions_section(torsion_kind, torsion_a, torsion_b, torsion_c, torsion_d, torsion_k, &
    2286             :                                     torsion_phi0, torsion_m, section, start)
    2287             :       INTEGER, DIMENSION(:), POINTER                     :: torsion_kind
    2288             :       CHARACTER(LEN=default_string_length), &
    2289             :          DIMENSION(:), POINTER                           :: torsion_a, torsion_b, torsion_c, &
    2290             :                                                             torsion_d
    2291             :       REAL(KIND=dp), DIMENSION(:), POINTER               :: torsion_k, torsion_phi0
    2292             :       INTEGER, DIMENSION(:), POINTER                     :: torsion_m
    2293             :       TYPE(section_vals_type), POINTER                   :: section
    2294             :       INTEGER, INTENT(IN)                                :: start
    2295             : 
    2296             :       CHARACTER(LEN=default_string_length), &
    2297           6 :          DIMENSION(:), POINTER                           :: atm_names
    2298             :       INTEGER                                            :: isec, n_items
    2299             : 
    2300           6 :       NULLIFY (atm_names)
    2301           6 :       CALL section_vals_get(section, n_repetition=n_items)
    2302          44 :       DO isec = 1, n_items
    2303          38 :          CALL section_vals_val_get(section, "KIND", i_rep_section=isec, i_val=torsion_kind(start + isec))
    2304          38 :          CALL section_vals_val_get(section, "ATOMS", i_rep_section=isec, c_vals=atm_names)
    2305          38 :          torsion_a(start + isec) = atm_names(1)
    2306          38 :          torsion_b(start + isec) = atm_names(2)
    2307          38 :          torsion_c(start + isec) = atm_names(3)
    2308          38 :          torsion_d(start + isec) = atm_names(4)
    2309          38 :          CALL uppercase(torsion_a(start + isec))
    2310          38 :          CALL uppercase(torsion_b(start + isec))
    2311          38 :          CALL uppercase(torsion_c(start + isec))
    2312          38 :          CALL uppercase(torsion_d(start + isec))
    2313          38 :          CALL section_vals_val_get(section, "K", i_rep_section=isec, r_val=torsion_k(start + isec))
    2314          38 :          CALL section_vals_val_get(section, "PHI0", i_rep_section=isec, r_val=torsion_phi0(start + isec))
    2315          38 :          CALL section_vals_val_get(section, "M", i_rep_section=isec, i_val=torsion_m(start + isec))
    2316             :          ! Modify parameterisation for OPLS case
    2317          44 :          IF (torsion_kind(start + isec) .EQ. do_ff_opls) THEN
    2318          12 :             IF (torsion_phi0(start + isec) .NE. 0.0_dp) THEN
    2319             :                CALL cp_warn(__LOCATION__, "PHI0 parameter was non-zero "// &
    2320           0 :                             "for an OPLS-type TORSION.  It will be ignored.")
    2321             :             END IF
    2322          12 :             IF (MODULO(torsion_m(start + isec), 2) .EQ. 0) THEN
    2323             :                ! For even M, negate the cosine using a Pi phase factor
    2324           2 :                torsion_phi0(start + isec) = pi
    2325             :             END IF
    2326             :             ! the K parameter appears as K/2 in the OPLS parameterisation
    2327          12 :             torsion_k(start + isec) = torsion_k(start + isec)*0.5_dp
    2328             :          END IF
    2329             :       END DO
    2330           6 :    END SUBROUTINE read_torsions_section
    2331             : 
    2332             : ! **************************************************************************************************
    2333             : !> \brief Reads the IMPROPER section
    2334             : !> \param impr_kind ...
    2335             : !> \param impr_a ...
    2336             : !> \param impr_b ...
    2337             : !> \param impr_c ...
    2338             : !> \param impr_d ...
    2339             : !> \param impr_k ...
    2340             : !> \param impr_phi0 ...
    2341             : !> \param section ...
    2342             : !> \param start ...
    2343             : !> \author louis vanduyfhuys
    2344             : ! **************************************************************************************************
    2345           8 :    SUBROUTINE read_improper_section(impr_kind, impr_a, impr_b, impr_c, impr_d, impr_k, &
    2346             :                                     impr_phi0, section, start)
    2347             :       INTEGER, DIMENSION(:), POINTER                     :: impr_kind
    2348             :       CHARACTER(LEN=default_string_length), &
    2349             :          DIMENSION(:), POINTER                           :: impr_a, impr_b, impr_c, impr_d
    2350             :       REAL(KIND=dp), DIMENSION(:), POINTER               :: impr_k, impr_phi0
    2351             :       TYPE(section_vals_type), POINTER                   :: section
    2352             :       INTEGER, INTENT(IN)                                :: start
    2353             : 
    2354             :       CHARACTER(LEN=default_string_length), &
    2355           8 :          DIMENSION(:), POINTER                           :: atm_names
    2356             :       INTEGER                                            :: isec, n_items
    2357             : 
    2358           8 :       NULLIFY (atm_names)
    2359           8 :       CALL section_vals_get(section, n_repetition=n_items)
    2360          16 :       DO isec = 1, n_items
    2361           8 :          CALL section_vals_val_get(section, "KIND", i_rep_section=isec, i_val=impr_kind(start + isec))
    2362           8 :          CALL section_vals_val_get(section, "ATOMS", i_rep_section=isec, c_vals=atm_names)
    2363           8 :          impr_a(start + isec) = atm_names(1)
    2364           8 :          impr_b(start + isec) = atm_names(2)
    2365           8 :          impr_c(start + isec) = atm_names(3)
    2366           8 :          impr_d(start + isec) = atm_names(4)
    2367           8 :          CALL uppercase(impr_a(start + isec))
    2368           8 :          CALL uppercase(impr_b(start + isec))
    2369           8 :          CALL uppercase(impr_c(start + isec))
    2370           8 :          CALL uppercase(impr_d(start + isec))
    2371           8 :          CALL section_vals_val_get(section, "K", i_rep_section=isec, r_val=impr_k(start + isec))
    2372          16 :          CALL section_vals_val_get(section, "PHI0", i_rep_section=isec, r_val=impr_phi0(start + isec))
    2373             :       END DO
    2374           8 :    END SUBROUTINE read_improper_section
    2375             : 
    2376             : ! **************************************************************************************************
    2377             : !> \brief Reads the OPBEND section
    2378             : !> \param opbend_kind ...
    2379             : !> \param opbend_a ...
    2380             : !> \param opbend_b ...
    2381             : !> \param opbend_c ...
    2382             : !> \param opbend_d ...
    2383             : !> \param opbend_k ...
    2384             : !> \param opbend_phi0 ...
    2385             : !> \param section ...
    2386             : !> \param start ...
    2387             : !> \author louis vanduyfhuys
    2388             : ! **************************************************************************************************
    2389           2 :    SUBROUTINE read_opbend_section(opbend_kind, opbend_a, opbend_b, opbend_c, opbend_d, opbend_k, &
    2390             :                                   opbend_phi0, section, start)
    2391             :       INTEGER, DIMENSION(:), POINTER                     :: opbend_kind
    2392             :       CHARACTER(LEN=default_string_length), &
    2393             :          DIMENSION(:), POINTER                           :: opbend_a, opbend_b, opbend_c, opbend_d
    2394             :       REAL(KIND=dp), DIMENSION(:), POINTER               :: opbend_k, opbend_phi0
    2395             :       TYPE(section_vals_type), POINTER                   :: section
    2396             :       INTEGER, INTENT(IN)                                :: start
    2397             : 
    2398             :       CHARACTER(LEN=default_string_length), &
    2399           2 :          DIMENSION(:), POINTER                           :: atm_names
    2400             :       INTEGER                                            :: isec, n_items
    2401             : 
    2402           2 :       NULLIFY (atm_names)
    2403           2 :       CALL section_vals_get(section, n_repetition=n_items)
    2404           4 :       DO isec = 1, n_items
    2405           2 :          CALL section_vals_val_get(section, "KIND", i_rep_section=isec, i_val=opbend_kind(start + isec))
    2406           2 :          CALL section_vals_val_get(section, "ATOMS", i_rep_section=isec, c_vals=atm_names)
    2407           2 :          opbend_a(start + isec) = atm_names(1)
    2408           2 :          opbend_b(start + isec) = atm_names(2)
    2409           2 :          opbend_c(start + isec) = atm_names(3)
    2410           2 :          opbend_d(start + isec) = atm_names(4)
    2411           2 :          CALL uppercase(opbend_a(start + isec))
    2412           2 :          CALL uppercase(opbend_b(start + isec))
    2413           2 :          CALL uppercase(opbend_c(start + isec))
    2414           2 :          CALL uppercase(opbend_d(start + isec))
    2415           2 :          CALL section_vals_val_get(section, "K", i_rep_section=isec, r_val=opbend_k(start + isec))
    2416           4 :          CALL section_vals_val_get(section, "PHI0", i_rep_section=isec, r_val=opbend_phi0(start + isec))
    2417             :       END DO
    2418           2 :    END SUBROUTINE read_opbend_section
    2419             : 
    2420             : ! **************************************************************************************************
    2421             : !> \brief Reads the force_field input section
    2422             : !> \param ff_type ...
    2423             : !> \param para_env ...
    2424             : !> \param mm_section ...
    2425             : !> \par History
    2426             : !>      JGH (30.11.2001) : moved determination of setup variables to
    2427             : !>                         molecule_input
    2428             : !> \author CJM
    2429             : ! **************************************************************************************************
    2430        2643 :    SUBROUTINE read_force_field_section(ff_type, para_env, mm_section)
    2431             :       TYPE(force_field_type), INTENT(INOUT)              :: ff_type
    2432             :       TYPE(mp_para_env_type), POINTER                    :: para_env
    2433             :       TYPE(section_vals_type), POINTER                   :: mm_section
    2434             : 
    2435             :       TYPE(section_vals_type), POINTER                   :: ff_section
    2436             : 
    2437             :       NULLIFY (ff_section)
    2438        2643 :       ff_section => section_vals_get_subs_vals(mm_section, "FORCEFIELD")
    2439        2643 :       CALL read_force_field_section1(ff_section, mm_section, ff_type, para_env)
    2440        2643 :    END SUBROUTINE read_force_field_section
    2441             : 
    2442             : ! **************************************************************************************************
    2443             : !> \brief reads EAM potential from library
    2444             : !> \param eam ...
    2445             : !> \param para_env ...
    2446             : !> \param mm_section ...
    2447             : ! **************************************************************************************************
    2448          40 :    SUBROUTINE read_eam_data(eam, para_env, mm_section)
    2449             :       TYPE(eam_pot_type), POINTER                        :: eam
    2450             :       TYPE(mp_para_env_type), POINTER                    :: para_env
    2451             :       TYPE(section_vals_type), POINTER                   :: mm_section
    2452             : 
    2453             :       CHARACTER(len=*), PARAMETER                        :: routineN = 'read_eam_data'
    2454             : 
    2455             :       INTEGER                                            :: handle, i, iw
    2456             :       TYPE(cp_logger_type), POINTER                      :: logger
    2457             :       TYPE(cp_parser_type)                               :: parser
    2458             : 
    2459          20 :       CALL timeset(routineN, handle)
    2460          20 :       NULLIFY (logger)
    2461          20 :       logger => cp_get_default_logger()
    2462             :       iw = cp_print_key_unit_nr(logger, mm_section, "PRINT%FF_INFO", &
    2463          20 :                                 extension=".mmLog")
    2464          20 :       IF (iw > 0) WRITE (iw, *) "Reading EAM data from: ", TRIM(eam%eam_file_name)
    2465          20 :       CALL parser_create(parser, TRIM(eam%eam_file_name), para_env=para_env)
    2466             : 
    2467          20 :       CALL parser_get_next_line(parser, 1)
    2468          20 :       IF (iw > 0) WRITE (iw, *) "Title: ", parser%input_line
    2469             : 
    2470          20 :       CALL parser_get_next_line(parser, 2)
    2471          20 :       READ (parser%input_line, *) eam%drar, eam%drhoar, eam%acutal, eam%npoints
    2472          20 :       eam%drar = cp_unit_to_cp2k(eam%drar, "angstrom")
    2473          20 :       eam%acutal = cp_unit_to_cp2k(eam%acutal, "angstrom")
    2474             :       ! Relocating arrays with the right size
    2475          20 :       CALL reallocate(eam%rho, 1, eam%npoints)
    2476          20 :       CALL reallocate(eam%rhop, 1, eam%npoints)
    2477          20 :       CALL reallocate(eam%rval, 1, eam%npoints)
    2478          20 :       CALL reallocate(eam%rhoval, 1, eam%npoints)
    2479          20 :       CALL reallocate(eam%phi, 1, eam%npoints)
    2480          20 :       CALL reallocate(eam%phip, 1, eam%npoints)
    2481          20 :       CALL reallocate(eam%frho, 1, eam%npoints)
    2482          20 :       CALL reallocate(eam%frhop, 1, eam%npoints)
    2483             :       ! Reading density and derivative of density (with respect to r)
    2484       64020 :       DO i = 1, eam%npoints
    2485       64000 :          CALL parser_get_next_line(parser, 1)
    2486       64000 :          READ (parser%input_line, *) eam%rho(i), eam%rhop(i)
    2487       64000 :          eam%rhop(i) = cp_unit_to_cp2k(eam%rhop(i), "angstrom^-1")
    2488       64000 :          eam%rval(i) = REAL(i - 1, KIND=dp)*eam%drar
    2489       64020 :          eam%rhoval(i) = REAL(i - 1, KIND=dp)*eam%drhoar
    2490             :       END DO
    2491             :       ! Reading pair potential PHI and its derivative (with respect to r)
    2492       64020 :       DO i = 1, eam%npoints
    2493       64000 :          CALL parser_get_next_line(parser, 1)
    2494       64000 :          READ (parser%input_line, *) eam%phi(i), eam%phip(i)
    2495       64000 :          eam%phi(i) = cp_unit_to_cp2k(eam%phi(i), "eV")
    2496       64020 :          eam%phip(i) = cp_unit_to_cp2k(eam%phip(i), "eV*angstrom^-1")
    2497             :       END DO
    2498             :       ! Reading embedded function and its derivative (with respect to density)
    2499       64020 :       DO i = 1, eam%npoints
    2500       64000 :          CALL parser_get_next_line(parser, 1)
    2501       64000 :          READ (parser%input_line, *) eam%frho(i), eam%frhop(i)
    2502       64000 :          eam%frho(i) = cp_unit_to_cp2k(eam%frho(i), "eV")
    2503       64020 :          eam%frhop(i) = cp_unit_to_cp2k(eam%frhop(i), "eV")
    2504             :       END DO
    2505             : 
    2506          20 :       IF (iw > 0) WRITE (iw, *) "Finished EAM data"
    2507          20 :       CALL parser_release(parser)
    2508          20 :       CALL cp_print_key_finished_output(iw, logger, mm_section, "PRINT%FF_INFO")
    2509          20 :       CALL timestop(handle)
    2510             : 
    2511          60 :    END SUBROUTINE read_eam_data
    2512             : 
    2513             : ! **************************************************************************************************
    2514             : !> \brief reads NequIP potential from .pth file
    2515             : !> \param nequip ...
    2516             : !> \author Gabriele Tocci
    2517             : ! **************************************************************************************************
    2518           4 :    SUBROUTINE read_nequip_data(nequip)
    2519             :       TYPE(nequip_pot_type)                              :: nequip
    2520             : 
    2521             :       CHARACTER(len=*), PARAMETER                        :: routineN = 'read_nequip_data'
    2522             :       CHARACTER(LEN=1), PARAMETER                        :: delimiter = ' '
    2523             : 
    2524           4 :       CHARACTER(LEN=100), ALLOCATABLE, DIMENSION(:)      :: tokenized_string
    2525             :       CHARACTER(LEN=default_path_length)                 :: allow_tf32_str, cutoff_str, &
    2526             :                                                             default_dtype, model_dtype, types_str
    2527             :       INTEGER                                            :: handle
    2528             :       LOGICAL                                            :: allow_tf32, found
    2529             : 
    2530           4 :       CALL timeset(routineN, handle)
    2531             : 
    2532           4 :       INQUIRE (FILE=nequip%nequip_file_name, EXIST=found)
    2533           4 :       IF (.NOT. found) THEN
    2534             :          CALL cp_abort(__LOCATION__, &
    2535             :                        "Nequip model file <"//TRIM(nequip%nequip_file_name)// &
    2536           0 :                        "> not found.")
    2537             :       END IF
    2538             : 
    2539           4 :       nequip%nequip_version = torch_model_read_metadata(nequip%nequip_file_name, "nequip_version")
    2540           4 :       cutoff_str = torch_model_read_metadata(nequip%nequip_file_name, "r_max")
    2541           4 :       types_str = torch_model_read_metadata(nequip%nequip_file_name, "type_names")
    2542           4 :       CALL tokenize_string(TRIM(types_str), delimiter, tokenized_string)
    2543             : 
    2544           4 :       IF (ALLOCATED(nequip%type_names_torch)) THEN
    2545           0 :          DEALLOCATE (nequip%type_names_torch)
    2546             :       END IF
    2547          12 :       ALLOCATE (nequip%type_names_torch(SIZE(tokenized_string)))
    2548             : 
    2549          12 :       nequip%type_names_torch(:) = tokenized_string(:)
    2550             : 
    2551           4 :       READ (cutoff_str, *) nequip%rcutsq
    2552           4 :       nequip%rcutsq = cp_unit_to_cp2k(nequip%rcutsq, nequip%unit_coords)
    2553           4 :       nequip%rcutsq = nequip%rcutsq*nequip%rcutsq
    2554           4 :       nequip%unit_coords_val = cp_unit_to_cp2k(nequip%unit_coords_val, nequip%unit_coords)
    2555           4 :       nequip%unit_forces_val = cp_unit_to_cp2k(nequip%unit_forces_val, nequip%unit_forces)
    2556           4 :       nequip%unit_energy_val = cp_unit_to_cp2k(nequip%unit_energy_val, nequip%unit_energy)
    2557           4 :       nequip%unit_cell_val = cp_unit_to_cp2k(nequip%unit_cell_val, nequip%unit_cell)
    2558             : 
    2559           4 :       default_dtype = torch_model_read_metadata(nequip%nequip_file_name, "default_dtype")
    2560           4 :       model_dtype = torch_model_read_metadata(nequip%nequip_file_name, "model_dtype")
    2561           4 :       IF (TRIM(default_dtype) == "float32" .AND. TRIM(model_dtype) == "float32") THEN
    2562           2 :          nequip%do_nequip_sp = .TRUE.
    2563           2 :       ELSE IF (TRIM(default_dtype) == "float64" .AND. TRIM(model_dtype) == "float64") THEN
    2564           2 :          nequip%do_nequip_sp = .FALSE.
    2565             :       ELSE
    2566             :          CALL cp_abort(__LOCATION__, &
    2567             :                        "Both default_dtype and model_dtype should be either float32 or float64. Currently, default_dtype is <"// &
    2568           0 :                        TRIM(default_dtype)//"> and model_dtype is <"//TRIM(model_dtype)//">.")
    2569             :       END IF
    2570             : 
    2571           4 :       allow_tf32_str = torch_model_read_metadata(nequip%nequip_file_name, "allow_tf32")
    2572           4 :       allow_tf32 = (TRIM(allow_tf32_str) == "1")
    2573           4 :       IF (TRIM(allow_tf32_str) /= "1" .AND. TRIM(allow_tf32_str) /= "0") THEN
    2574             :          CALL cp_abort(__LOCATION__, &
    2575             :                        "The value for allow_tf32 <"//TRIM(allow_tf32_str)// &
    2576           0 :                        "> is not supported. Check the .yaml and .pth files.")
    2577             :       END IF
    2578           4 :       CALL torch_allow_tf32(allow_tf32)
    2579             : 
    2580           4 :       CALL timestop(handle)
    2581           8 :    END SUBROUTINE read_nequip_data
    2582             : 
    2583             : ! **************************************************************************************************
    2584             : !> \brief reads ALLEGRO potential from .pth file
    2585             : !> \param allegro ...
    2586             : !> \author Gabriele Tocci
    2587             : ! **************************************************************************************************
    2588           4 :    SUBROUTINE read_allegro_data(allegro)
    2589             :       TYPE(allegro_pot_type)                             :: allegro
    2590             : 
    2591             :       CHARACTER(len=*), PARAMETER                        :: routineN = 'read_allegro_data'
    2592             :       CHARACTER(LEN=1), PARAMETER                        :: delimiter = ' '
    2593             : 
    2594           4 :       CHARACTER(LEN=100), ALLOCATABLE, DIMENSION(:)      :: tokenized_string
    2595             :       CHARACTER(LEN=default_path_length)                 :: allow_tf32_str, cutoff_str, &
    2596             :                                                             default_dtype, model_dtype, types_str
    2597             :       INTEGER                                            :: handle
    2598             :       LOGICAL                                            :: allow_tf32, found
    2599             : 
    2600           4 :       CALL timeset(routineN, handle)
    2601             : 
    2602           4 :       INQUIRE (FILE=allegro%allegro_file_name, EXIST=found)
    2603           4 :       IF (.NOT. found) THEN
    2604             :          CALL cp_abort(__LOCATION__, &
    2605             :                        "Allegro model file <"//TRIM(allegro%allegro_file_name)// &
    2606           0 :                        "> not found.")
    2607             :       END IF
    2608             : 
    2609           4 :       allegro%nequip_version = torch_model_read_metadata(allegro%allegro_file_name, "nequip_version")
    2610           4 :       IF (allegro%nequip_version == "") THEN
    2611             :          CALL cp_abort(__LOCATION__, &
    2612             :                        "Allegro model file <"//TRIM(allegro%allegro_file_name)// &
    2613           0 :                        "> has not been deployed; did you forget to run `nequip-deploy`?")
    2614             :       END IF
    2615           4 :       cutoff_str = torch_model_read_metadata(allegro%allegro_file_name, "r_max")
    2616           4 :       types_str = torch_model_read_metadata(allegro%allegro_file_name, "type_names")
    2617           4 :       CALL tokenize_string(TRIM(types_str), delimiter, tokenized_string)
    2618             : 
    2619           4 :       IF (ALLOCATED(allegro%type_names_torch)) THEN
    2620           0 :          DEALLOCATE (allegro%type_names_torch)
    2621             :       END IF
    2622          12 :       ALLOCATE (allegro%type_names_torch(SIZE(tokenized_string)))
    2623          12 :       allegro%type_names_torch(:) = tokenized_string(:)
    2624             : 
    2625           4 :       READ (cutoff_str, *) allegro%rcutsq
    2626           4 :       allegro%rcutsq = cp_unit_to_cp2k(allegro%rcutsq, allegro%unit_coords)
    2627           4 :       allegro%rcutsq = allegro%rcutsq*allegro%rcutsq
    2628           4 :       allegro%unit_coords_val = cp_unit_to_cp2k(allegro%unit_coords_val, allegro%unit_coords)
    2629           4 :       allegro%unit_forces_val = cp_unit_to_cp2k(allegro%unit_forces_val, allegro%unit_forces)
    2630           4 :       allegro%unit_energy_val = cp_unit_to_cp2k(allegro%unit_energy_val, allegro%unit_energy)
    2631           4 :       allegro%unit_cell_val = cp_unit_to_cp2k(allegro%unit_cell_val, allegro%unit_cell)
    2632             : 
    2633           4 :       default_dtype = torch_model_read_metadata(allegro%allegro_file_name, "default_dtype")
    2634           4 :       model_dtype = torch_model_read_metadata(allegro%allegro_file_name, "model_dtype")
    2635           4 :       IF (TRIM(default_dtype) == "float32" .AND. TRIM(model_dtype) == "float32") THEN
    2636           2 :          allegro%do_allegro_sp = .TRUE.
    2637           2 :       ELSE IF (TRIM(default_dtype) == "float64" .AND. TRIM(model_dtype) == "float64") THEN
    2638           2 :          allegro%do_allegro_sp = .FALSE.
    2639             :       ELSE
    2640             :          CALL cp_abort(__LOCATION__, &
    2641             :                        "Both default_dtype and model_dtype should be either float32 or float64. Currently, default_dtype is <"// &
    2642           0 :                        TRIM(default_dtype)//"> and model_dtype is <"//TRIM(model_dtype)//">.")
    2643             :       END IF
    2644             : 
    2645           4 :       allow_tf32_str = torch_model_read_metadata(allegro%allegro_file_name, "allow_tf32")
    2646           4 :       allow_tf32 = (TRIM(allow_tf32_str) == "1")
    2647           4 :       IF (TRIM(allow_tf32_str) /= "1" .AND. TRIM(allow_tf32_str) /= "0") THEN
    2648             :          CALL cp_abort(__LOCATION__, &
    2649             :                        "The value for allow_tf32 <"//TRIM(allow_tf32_str)// &
    2650           0 :                        "> is not supported. Check the .yaml and .pth files.")
    2651             :       END IF
    2652           4 :       CALL torch_allow_tf32(allow_tf32)
    2653             : 
    2654           4 :       CALL timestop(handle)
    2655           8 :    END SUBROUTINE read_allegro_data
    2656             : 
    2657             : ! **************************************************************************************************
    2658             : !> \brief returns tokenized string of kinds from .pth file
    2659             : !> \param element ...
    2660             : !> \param delimiter ...
    2661             : !> \param tokenized_array ...
    2662             : !> \author Maria Bilichenko
    2663             : ! **************************************************************************************************
    2664           8 :    SUBROUTINE tokenize_string(element, delimiter, tokenized_array)
    2665             :       CHARACTER(LEN=*), INTENT(IN)                       :: element
    2666             :       CHARACTER(LEN=1), INTENT(IN)                       :: delimiter
    2667             :       CHARACTER(LEN=100), ALLOCATABLE, DIMENSION(:), &
    2668             :          INTENT(OUT)                                     :: tokenized_array
    2669             : 
    2670             :       CHARACTER(LEN=100)                                 :: temp_kinds
    2671             :       INTEGER                                            :: end_pos, i, num_elements, start
    2672           8 :       LOGICAL, ALLOCATABLE, DIMENSION(:)                 :: delim_positions
    2673             : 
    2674             :       ! Find positions of delimiter within element
    2675          24 :       ALLOCATE (delim_positions(LEN(element)))
    2676          34 :       delim_positions = .FALSE.
    2677             : 
    2678          34 :       DO i = 1, LEN(element)
    2679          34 :          IF (element(i:i) == delimiter) delim_positions(i) = .TRUE.
    2680             :       END DO
    2681             : 
    2682          34 :       num_elements = COUNT(delim_positions) + 1
    2683             : 
    2684          24 :       ALLOCATE (tokenized_array(num_elements))
    2685             : 
    2686           8 :       start = 1
    2687          24 :       DO i = 1, num_elements
    2688          74 :          IF (LEN(element) < 3 .AND. COUNT(delim_positions) == 0) THEN ! if there is 1 kind only and it has one or two
    2689             :             !characters (C or Cl) the end_pos will be the index of the last character (1 or 2)
    2690             :             end_pos = LEN(element)
    2691             :          ELSE ! else, the end_pos is determined by the index of the space - 1
    2692          14 :             end_pos = find_end_pos(start, delim_positions)
    2693             :          END IF
    2694          16 :          temp_kinds = element(start:end_pos)
    2695          16 :          IF (TRIM(temp_kinds) /= '') THEN
    2696          16 :             tokenized_array(i) = temp_kinds
    2697             :          END IF
    2698          24 :          start = end_pos + 2
    2699             :       END DO
    2700           8 :       DEALLOCATE (delim_positions)
    2701           8 :    END SUBROUTINE tokenize_string
    2702             : 
    2703             : ! **************************************************************************************************
    2704             : !> \brief finds the position of the atom by the spacing
    2705             : !> \param start ...
    2706             : !> \param delim_positions ...
    2707             : !> \return ...
    2708             : !> \author Maria Bilichenko
    2709             : ! **************************************************************************************************
    2710          14 :    INTEGER FUNCTION find_end_pos(start, delim_positions)
    2711             :       INTEGER, INTENT(IN)                                :: start
    2712             :       LOGICAL, DIMENSION(:), INTENT(IN)                  :: delim_positions
    2713             : 
    2714             :       INTEGER                                            :: end_pos, i
    2715             : 
    2716          14 :       end_pos = start
    2717          28 :       DO i = start, SIZE(delim_positions)
    2718          28 :          IF (delim_positions(i)) THEN
    2719           8 :             end_pos = i - 1
    2720           8 :             EXIT
    2721             :          END IF
    2722             :       END DO
    2723             : 
    2724          14 :       find_end_pos = end_pos
    2725          14 :    END FUNCTION find_end_pos
    2726             : 
    2727             : ! **************************************************************************************************
    2728             : !> \brief checks if all the ATOMS from *.inp file are available in *.pth file
    2729             : !> \param cp2k_inp_atom_types ...
    2730             : !> \param torch_atom_types ...
    2731             : !> \author Maria Bilichenko
    2732             : ! **************************************************************************************************
    2733           8 :    SUBROUTINE check_cp2k_atom_names_in_torch(cp2k_inp_atom_types, torch_atom_types)
    2734             :       CHARACTER(LEN=*), DIMENSION(:), INTENT(IN)         :: cp2k_inp_atom_types, torch_atom_types
    2735             : 
    2736             :       INTEGER                                            :: i, j
    2737             :       LOGICAL                                            :: found
    2738             : 
    2739          22 :       DO i = 1, SIZE(cp2k_inp_atom_types)
    2740          14 :          found = .FALSE.
    2741          22 :          DO j = 1, SIZE(torch_atom_types)
    2742          22 :             IF (TRIM(cp2k_inp_atom_types(i)) == TRIM(torch_atom_types(j))) THEN
    2743             :                found = .TRUE.
    2744             :                EXIT
    2745             :             END IF
    2746             :          END DO
    2747          22 :          IF (.NOT. found) THEN
    2748             :             CALL cp_abort(__LOCATION__, &
    2749             :                           "Atom "//TRIM(cp2k_inp_atom_types(i))// &
    2750           0 :                           " is defined in the CP2K input file but is missing in the torch model file")
    2751             :          END IF
    2752             :       END DO
    2753           8 :    END SUBROUTINE check_cp2k_atom_names_in_torch
    2754             : 
    2755             : ! **************************************************************************************************
    2756             : !> \brief reads TABPOT potential from file
    2757             : !> \param tab ...
    2758             : !> \param para_env ...
    2759             : !> \param mm_section ...
    2760             : !> \author Da Teng, Alex Mironenko
    2761             : ! **************************************************************************************************
    2762          48 :    SUBROUTINE read_tabpot_data(tab, para_env, mm_section)
    2763             :       TYPE(tab_pot_type), POINTER                        :: tab
    2764             :       TYPE(mp_para_env_type), POINTER                    :: para_env
    2765             :       TYPE(section_vals_type), POINTER                   :: mm_section
    2766             : 
    2767             :       CHARACTER(len=*), PARAMETER                        :: routineN = 'read_tabpot_data'
    2768             : 
    2769             :       CHARACTER                                          :: d1, d2
    2770             :       INTEGER                                            :: d, handle, i, iw
    2771             :       TYPE(cp_logger_type), POINTER                      :: logger
    2772             :       TYPE(cp_parser_type)                               :: parser
    2773             : 
    2774          24 :       CALL timeset(routineN, handle)
    2775          24 :       NULLIFY (logger)
    2776          24 :       logger => cp_get_default_logger()
    2777             :       iw = cp_print_key_unit_nr(logger, mm_section, "PRINT%FF_INFO", &
    2778          24 :                                 extension=".mmLog")
    2779          24 :       IF (iw > 0) WRITE (iw, *) "Reading TABPOT data from: ", TRIM(tab%tabpot_file_name)
    2780          24 :       CALL parser_create(parser, TRIM(tab%tabpot_file_name), para_env=para_env)
    2781          24 :       CALL parser_get_next_line(parser, 1)
    2782          24 :       IF (iw > 0) WRITE (iw, *) "Title: ", parser%input_line
    2783          24 :       CALL parser_get_next_line(parser, 1)
    2784             : 
    2785             :       ! example format: N 1000 R 1.00 20.0
    2786             :       ! Assume the data is evenly spaced
    2787          24 :       READ (parser%input_line, *) d1, tab%npoints, d2, tab%dr, tab%rcut
    2788             : 
    2789             :       ! Relocating arrays with the right size
    2790          24 :       CALL reallocate(tab%r, 1, tab%npoints)
    2791          24 :       CALL reallocate(tab%e, 1, tab%npoints)
    2792          24 :       CALL reallocate(tab%f, 1, tab%npoints)
    2793             : 
    2794             :       ! Reading r, e, f
    2795       21912 :       DO i = 1, tab%npoints
    2796       21888 :          CALL parser_get_next_line(parser, 1)
    2797       21888 :          READ (parser%input_line, *) d, tab%r(i), tab%e(i), tab%f(i)
    2798       21888 :          tab%r(i) = cp_unit_to_cp2k(tab%r(i), "angstrom")
    2799       21888 :          tab%e(i) = cp_unit_to_cp2k(tab%e(i), "kcalmol")
    2800       21912 :          tab%f(i) = cp_unit_to_cp2k(tab%f(i), "kcalmol*angstrom^-1")
    2801             :       END DO
    2802             : 
    2803          24 :       tab%dr = tab%r(2) - tab%r(1)
    2804          24 :       tab%rcut = cp_unit_to_cp2k(tab%rcut, "angstrom")
    2805             : 
    2806          24 :       IF (iw > 0) WRITE (iw, *) "Finished TABPOT data"
    2807          24 :       CALL parser_release(parser)
    2808          24 :       CALL cp_print_key_finished_output(iw, logger, mm_section, "PRINT%FF_INFO")
    2809          24 :       CALL timestop(handle)
    2810          72 :    END SUBROUTINE read_tabpot_data
    2811             : END MODULE force_fields_input

Generated by: LCOV version 1.15