LCOV - code coverage report
Current view: top level - src - topology_input.F (source / functions) Coverage Total Hit
Test: CP2K Regtests (git:c24029e) Lines: 95.8 % 313 300
Test Date: 2026-07-04 06:36:57 Functions: 100.0 % 3 3

            Line data    Source code
       1              : !--------------------------------------------------------------------------------------------------!
       2              : !   CP2K: A general program to perform molecular dynamics simulations                              !
       3              : !   Copyright 2000-2026 CP2K developers group <https://cp2k.org>                                   !
       4              : !                                                                                                  !
       5              : !   SPDX-License-Identifier: GPL-2.0-or-later                                                      !
       6              : !--------------------------------------------------------------------------------------------------!
       7              : 
       8              : ! **************************************************************************************************
       9              : !> \brief Reads the input sections "topology"
      10              : !> \par History
      11              : !>      JGH (26-01-2002) Added read_topology_section
      12              : !> \author JGH
      13              : ! **************************************************************************************************
      14              : MODULE topology_input
      15              :    USE colvar_types,                    ONLY: colvar_clone,&
      16              :                                               colvar_p_type
      17              :    USE cp_log_handling,                 ONLY: cp_logger_get_default_io_unit,&
      18              :                                               cp_to_string
      19              :    USE input_constants,                 ONLY: do_conn_generate,&
      20              :                                               do_conn_mol_set,&
      21              :                                               do_conn_off,&
      22              :                                               do_conn_user,&
      23              :                                               do_constr_none,&
      24              :                                               do_coord_off
      25              :    USE input_section_types,             ONLY: section_vals_get,&
      26              :                                               section_vals_get_subs_vals,&
      27              :                                               section_vals_type,&
      28              :                                               section_vals_val_get,&
      29              :                                               section_vals_val_unset
      30              :    USE kinds,                           ONLY: default_string_length,&
      31              :                                               dp
      32              :    USE memory_utilities,                ONLY: reallocate
      33              :    USE topology_types,                  ONLY: constraint_info_type,&
      34              :                                               topology_parameters_type
      35              : #include "./base/base_uses.f90"
      36              : 
      37              :    IMPLICIT NONE
      38              : 
      39              :    CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'topology_input'
      40              : 
      41              :    PRIVATE
      42              :    PUBLIC :: read_topology_section, read_constraints_section
      43              : 
      44              : CONTAINS
      45              : 
      46              : ! **************************************************************************************************
      47              : !> \brief reads the input section topology
      48              : !> \param topology ...
      49              : !> \param topology_section ...
      50              : !> \par History
      51              : !>      none
      52              : !> \author JGH (26-01-2002)
      53              : ! **************************************************************************************************
      54        10854 :    SUBROUTINE read_topology_section(topology, topology_section)
      55              :       TYPE(topology_parameters_type)                     :: topology
      56              :       TYPE(section_vals_type), POINTER                   :: topology_section
      57              : 
      58              :       CHARACTER(len=*), PARAMETER :: routineN = 'read_topology_section'
      59              : 
      60              :       INTEGER                                            :: handle, ival
      61              : 
      62        10854 :       CALL timeset(routineN, handle)
      63        10854 :       CALL section_vals_val_get(topology_section, "CHARGE_OCCUP", l_val=topology%charge_occup)
      64        10854 :       CALL section_vals_val_get(topology_section, "CHARGE_BETA", l_val=topology%charge_beta)
      65        10854 :       CALL section_vals_val_get(topology_section, "CHARGE_EXTENDED", l_val=topology%charge_extended)
      66        43416 :       ival = COUNT([topology%charge_occup, topology%charge_beta, topology%charge_extended])
      67        10854 :       IF (ival > 1) &
      68            0 :          CPABORT("Only one between <CHARGE_OCCUP,CHARGE_BETA,CHARGE_EXTENDED> can be defined! ")
      69        10854 :       CALL section_vals_val_get(topology_section, "PARA_RES", l_val=topology%para_res)
      70        10854 :       CALL section_vals_val_get(topology_section, "GENERATE%REORDER", l_val=topology%reorder_atom)
      71        10854 :       CALL section_vals_val_get(topology_section, "GENERATE%CREATE_MOLECULES", l_val=topology%create_molecules)
      72        10854 :       CALL section_vals_val_get(topology_section, "MOL_CHECK", l_val=topology%molecules_check)
      73        10854 :       CALL section_vals_val_get(topology_section, "USE_G96_VELOCITY", l_val=topology%use_g96_velocity)
      74        10854 :       CALL section_vals_val_get(topology_section, "COORD_FILE_FORMAT", i_val=topology%coord_type)
      75        12781 :       SELECT CASE (topology%coord_type)
      76              :       CASE (do_coord_off)
      77              :          ! Do Nothing
      78              :       CASE DEFAULT
      79         1927 :          topology%coordinate = .TRUE.
      80        10854 :          CALL section_vals_val_get(topology_section, "COORD_FILE_NAME", c_val=topology%coord_file_name)
      81              :       END SELECT
      82        10854 :       CALL section_vals_val_get(topology_section, "CONN_FILE_FORMAT", i_val=topology%conn_type)
      83        11378 :       SELECT CASE (topology%conn_type)
      84              :       CASE (do_conn_off, do_conn_generate, do_conn_mol_set, do_conn_user)
      85              :          ! Do Nothing
      86              :       CASE DEFAULT
      87        10854 :          CALL section_vals_val_get(topology_section, "CONN_FILE_NAME", c_val=topology%conn_file_name)
      88              :       END SELECT
      89        10854 :       CALL section_vals_val_get(topology_section, "EXCLUDE_VDW", i_val=topology%exclude_vdw)
      90        10854 :       CALL section_vals_val_get(topology_section, "EXCLUDE_EI", i_val=topology%exclude_ei)
      91        10854 :       CALL section_vals_val_get(topology_section, "GENERATE%BONDPARM", i_val=topology%bondparm_type)
      92        10854 :       CALL section_vals_val_get(topology_section, "GENERATE%BONDPARM_FACTOR", r_val=topology%bondparm_factor)
      93        10854 :       CALL timestop(handle)
      94        10854 :    END SUBROUTINE read_topology_section
      95              : 
      96              : ! **************************************************************************************************
      97              : !> \brief Read all the distance parameters. Put them in the
      98              : !>      constraint_distance array.
      99              : !> \param topology ...
     100              : !> \param colvar_p ...
     101              : !> \param constraint_section ...
     102              : !> \par History
     103              : !>      JGH (26-01-2002) Distance parameters are now stored in tables. The position
     104              : !>         within the table is used as handle for the topology
     105              : !>      teo Read the CONSTRAINT section within the new input style
     106              : !> \author teo
     107              : ! **************************************************************************************************
     108        10854 :    SUBROUTINE read_constraints_section(topology, colvar_p, constraint_section)
     109              : 
     110              :       TYPE(topology_parameters_type), INTENT(INOUT)      :: topology
     111              :       TYPE(colvar_p_type), DIMENSION(:), POINTER         :: colvar_p
     112              :       TYPE(section_vals_type), POINTER                   :: constraint_section
     113              : 
     114              :       CHARACTER(LEN=default_string_length), &
     115        10854 :          DIMENSION(:), POINTER                           :: tmpstringlist
     116              :       INTEGER                                            :: icolvar, ig, isize, isize_old, itype, &
     117              :                                                             jg, msize, msize_old, n_rep, ncons, &
     118              :                                                             nrep
     119        10854 :       INTEGER, DIMENSION(:), POINTER                     :: ilist, tmplist
     120              :       LOGICAL                                            :: explicit
     121        10854 :       REAL(KIND=dp), DIMENSION(:), POINTER               :: rlist
     122              :       TYPE(constraint_info_type), POINTER                :: cons_info
     123              :       TYPE(section_vals_type), POINTER                   :: collective_section, fix_atom_section, &
     124              :                                                             g3x3_section, g4x6_section, &
     125              :                                                             hbonds_section, vsite_section
     126              : 
     127        10854 :       cons_info => topology%cons_info
     128        63449 :       IF (ASSOCIATED(constraint_section)) THEN
     129        10519 :          hbonds_section => section_vals_get_subs_vals(constraint_section, "HBONDS")
     130        10519 :          g3x3_section => section_vals_get_subs_vals(constraint_section, "G3X3")
     131        10519 :          g4x6_section => section_vals_get_subs_vals(constraint_section, "G4X6")
     132        10519 :          vsite_section => section_vals_get_subs_vals(constraint_section, "VIRTUAL_SITE")
     133        10519 :          fix_atom_section => section_vals_get_subs_vals(constraint_section, "FIXED_ATOMS")
     134        10519 :          collective_section => section_vals_get_subs_vals(constraint_section, "COLLECTIVE")
     135              :          ! HBONDS
     136        10519 :          CALL section_vals_get(hbonds_section, explicit=topology%const_hydr)
     137              :          CALL check_restraint(hbonds_section, &
     138              :                               is_restraint=cons_info%hbonds_restraint, &
     139              :                               k0=cons_info%hbonds_k0, &
     140        10519 :                               label="HBONDS")
     141              :          ! G3X3
     142        10519 :          CALL section_vals_get(g3x3_section, explicit=explicit, n_repetition=ncons)
     143        10519 :          IF (explicit) THEN
     144          156 :             topology%const_33 = .TRUE.
     145          156 :             cons_info%nconst_g33 = ncons
     146              :             !
     147          468 :             ALLOCATE (cons_info%const_g33_mol(ncons))
     148          468 :             ALLOCATE (cons_info%const_g33_molname(ncons))
     149          312 :             ALLOCATE (cons_info%const_g33_a(ncons))
     150          312 :             ALLOCATE (cons_info%const_g33_b(ncons))
     151          312 :             ALLOCATE (cons_info%const_g33_c(ncons))
     152          468 :             ALLOCATE (cons_info%const_g33_dab(ncons))
     153          312 :             ALLOCATE (cons_info%const_g33_dac(ncons))
     154          312 :             ALLOCATE (cons_info%const_g33_dbc(ncons))
     155          312 :             ALLOCATE (cons_info%g33_intermolecular(ncons))
     156          312 :             ALLOCATE (cons_info%g33_restraint(ncons))
     157          312 :             ALLOCATE (cons_info%g33_k0(ncons))
     158          312 :             ALLOCATE (cons_info%g33_exclude_qm(ncons))
     159          312 :             ALLOCATE (cons_info%g33_exclude_mm(ncons))
     160          316 :             DO ig = 1, ncons
     161              :                CALL check_restraint(g3x3_section, &
     162              :                                     is_restraint=cons_info%g33_restraint(ig), &
     163              :                                     k0=cons_info%g33_k0(ig), &
     164              :                                     i_rep_section=ig, &
     165          160 :                                     label="G3X3")
     166          160 :                cons_info%const_g33_mol(ig) = 0
     167          160 :                cons_info%const_g33_molname(ig) = "UNDEF"
     168              :                ! Exclude QM or MM
     169              :                CALL section_vals_val_get(g3x3_section, "EXCLUDE_QM", i_rep_section=ig, &
     170          160 :                                          l_val=cons_info%g33_exclude_qm(ig))
     171              :                CALL section_vals_val_get(g3x3_section, "EXCLUDE_MM", i_rep_section=ig, &
     172          160 :                                          l_val=cons_info%g33_exclude_mm(ig))
     173              :                ! Intramolecular restraint
     174              :                CALL section_vals_val_get(g3x3_section, "INTERMOLECULAR", i_rep_section=ig, &
     175          160 :                                          l_val=cons_info%g33_intermolecular(ig))
     176              :                ! If it is intramolecular let's unset (in case user did it)
     177              :                ! the molecule and molname field
     178          160 :                IF (cons_info%g33_intermolecular(ig)) THEN
     179            4 :                   CALL section_vals_val_unset(g3x3_section, "MOLECULE", i_rep_section=ig)
     180            4 :                   CALL section_vals_val_unset(g3x3_section, "MOLNAME", i_rep_section=ig)
     181              :                END IF
     182              :                ! Let's tag to which molecule we want to apply constraints
     183              :                CALL section_vals_val_get(g3x3_section, "MOLECULE", i_rep_section=ig, &
     184          160 :                                          n_rep_val=nrep)
     185          160 :                IF (nrep /= 0) THEN
     186              :                   CALL section_vals_val_get(g3x3_section, "MOLECULE", i_rep_section=ig, &
     187          120 :                                             i_val=cons_info%const_g33_mol(ig))
     188              :                END IF
     189              :                CALL section_vals_val_get(g3x3_section, "MOLNAME", i_rep_section=ig, &
     190          160 :                                          n_rep_val=nrep)
     191          160 :                IF (nrep /= 0) THEN
     192              :                   CALL section_vals_val_get(g3x3_section, "MOLNAME", i_rep_section=ig, &
     193           36 :                                             c_val=cons_info%const_g33_molname(ig))
     194              :                END IF
     195          160 :                IF ((cons_info%const_g33_mol(ig) /= 0) .AND. (cons_info%const_g33_molname(ig) /= "UNDEF")) THEN
     196              :                   CALL cp_abort(__LOCATION__, &
     197              :                                 "Invalid G3X3 constraint section "//cp_to_string(ig)//": "// &
     198            0 :                                 "check MOLECULE and MOLNAME setup!")
     199              :                END IF
     200          160 :                IF ((cons_info%const_g33_mol(ig) == 0) .AND. (cons_info%const_g33_molname(ig) == "UNDEF") .AND. &
     201              :                    (.NOT. cons_info%g33_intermolecular(ig))) THEN
     202              :                   CALL cp_abort(__LOCATION__, &
     203              :                                 "Invalid G3X3 constraint section "//cp_to_string(ig)//": "// &
     204            0 :                                 "check MOLECULE and MOLNAME setup!")
     205              :                END IF
     206              :                CALL section_vals_val_get(g3x3_section, "ATOMS", i_rep_section=ig, &
     207          160 :                                          i_vals=ilist)
     208              :                CALL section_vals_val_get(g3x3_section, "DISTANCES", i_rep_section=ig, &
     209          160 :                                          r_vals=rlist)
     210          160 :                cons_info%const_g33_a(ig) = ilist(1)
     211          160 :                cons_info%const_g33_b(ig) = ilist(2)
     212          160 :                cons_info%const_g33_c(ig) = ilist(3)
     213              : 
     214          160 :                cons_info%const_g33_dab(ig) = rlist(1)
     215          160 :                cons_info%const_g33_dac(ig) = rlist(2)
     216          636 :                cons_info%const_g33_dbc(ig) = rlist(3)
     217              :             END DO
     218              :          END IF
     219              :          ! G4X6
     220        10519 :          CALL section_vals_get(g4x6_section, explicit=explicit, n_repetition=ncons)
     221        10519 :          IF (explicit) THEN
     222           16 :             topology%const_46 = .TRUE.
     223           16 :             cons_info%nconst_g46 = ncons
     224              :             !
     225           48 :             ALLOCATE (cons_info%const_g46_mol(ncons))
     226           48 :             ALLOCATE (cons_info%const_g46_molname(ncons))
     227           32 :             ALLOCATE (cons_info%const_g46_a(ncons))
     228           32 :             ALLOCATE (cons_info%const_g46_b(ncons))
     229           32 :             ALLOCATE (cons_info%const_g46_c(ncons))
     230           32 :             ALLOCATE (cons_info%const_g46_d(ncons))
     231           48 :             ALLOCATE (cons_info%const_g46_dab(ncons))
     232           32 :             ALLOCATE (cons_info%const_g46_dac(ncons))
     233           32 :             ALLOCATE (cons_info%const_g46_dbc(ncons))
     234           32 :             ALLOCATE (cons_info%const_g46_dad(ncons))
     235           32 :             ALLOCATE (cons_info%const_g46_dbd(ncons))
     236           32 :             ALLOCATE (cons_info%const_g46_dcd(ncons))
     237           32 :             ALLOCATE (cons_info%g46_intermolecular(ncons))
     238           32 :             ALLOCATE (cons_info%g46_restraint(ncons))
     239           32 :             ALLOCATE (cons_info%g46_k0(ncons))
     240           32 :             ALLOCATE (cons_info%g46_exclude_qm(ncons))
     241           32 :             ALLOCATE (cons_info%g46_exclude_mm(ncons))
     242           32 :             DO ig = 1, ncons
     243              :                CALL check_restraint(g4x6_section, &
     244              :                                     is_restraint=cons_info%g46_restraint(ig), &
     245              :                                     k0=cons_info%g46_k0(ig), &
     246              :                                     i_rep_section=ig, &
     247           16 :                                     label="G4X6")
     248           16 :                cons_info%const_g46_mol(ig) = 0
     249           16 :                cons_info%const_g46_molname(ig) = "UNDEF"
     250              :                ! Exclude QM or MM
     251              :                CALL section_vals_val_get(g4x6_section, "EXCLUDE_QM", i_rep_section=ig, &
     252           16 :                                          l_val=cons_info%g46_exclude_qm(ig))
     253              :                CALL section_vals_val_get(g4x6_section, "EXCLUDE_MM", i_rep_section=ig, &
     254           16 :                                          l_val=cons_info%g46_exclude_mm(ig))
     255              :                ! Intramolecular restraint
     256              :                CALL section_vals_val_get(g4x6_section, "INTERMOLECULAR", i_rep_section=ig, &
     257           16 :                                          l_val=cons_info%g46_intermolecular(ig))
     258              :                ! If it is intramolecular let's unset (in case user did it)
     259              :                ! the molecule and molname field
     260           16 :                IF (cons_info%g46_intermolecular(ig)) THEN
     261            4 :                   CALL section_vals_val_unset(g4x6_section, "MOLECULE", i_rep_section=ig)
     262            4 :                   CALL section_vals_val_unset(g4x6_section, "MOLNAME", i_rep_section=ig)
     263              :                END IF
     264              :                ! Let's tag to which molecule we want to apply constraints
     265              :                CALL section_vals_val_get(g4x6_section, "MOLECULE", i_rep_section=ig, &
     266           16 :                                          n_rep_val=nrep)
     267           16 :                IF (nrep /= 0) THEN
     268              :                   CALL section_vals_val_get(g4x6_section, "MOLECULE", i_rep_section=ig, &
     269            8 :                                             i_val=cons_info%const_g46_mol(ig))
     270              :                END IF
     271              :                CALL section_vals_val_get(g4x6_section, "MOLNAME", i_rep_section=ig, &
     272           16 :                                          n_rep_val=nrep)
     273           16 :                IF (nrep /= 0) THEN
     274              :                   CALL section_vals_val_get(g4x6_section, "MOLNAME", i_rep_section=ig, &
     275            4 :                                             c_val=cons_info%const_g46_molname(ig))
     276              :                END IF
     277           16 :                IF ((cons_info%const_g46_mol(ig) /= 0) .AND. (cons_info%const_g46_molname(ig) /= "UNDEF")) THEN
     278              :                   CALL cp_abort(__LOCATION__, &
     279              :                                 "Invalid G4X6 constraint section "//cp_to_string(ig)//": "// &
     280            0 :                                 "check MOLECULE and MOLNAME setup!")
     281              :                END IF
     282           16 :                IF ((cons_info%const_g46_mol(ig) == 0) .AND. (cons_info%const_g46_molname(ig) == "UNDEF") .AND. &
     283              :                    (.NOT. cons_info%g46_intermolecular(ig))) THEN
     284              :                   CALL cp_abort(__LOCATION__, &
     285              :                                 "Invalid G4X6 constraint section "//cp_to_string(ig)//": "// &
     286            0 :                                 "check MOLECULE and MOLNAME setup!")
     287              :                END IF
     288              :                CALL section_vals_val_get(g4x6_section, "ATOMS", i_rep_section=ig, &
     289           16 :                                          i_vals=ilist)
     290              :                CALL section_vals_val_get(g4x6_section, "DISTANCES", i_rep_section=ig, &
     291           16 :                                          r_vals=rlist)
     292           16 :                cons_info%const_g46_a(ig) = ilist(1)
     293           16 :                cons_info%const_g46_b(ig) = ilist(2)
     294           16 :                cons_info%const_g46_c(ig) = ilist(3)
     295           16 :                cons_info%const_g46_d(ig) = ilist(4)
     296           16 :                cons_info%const_g46_dab(ig) = rlist(1)
     297           16 :                cons_info%const_g46_dac(ig) = rlist(2)
     298           16 :                cons_info%const_g46_dad(ig) = rlist(3)
     299           16 :                cons_info%const_g46_dbc(ig) = rlist(4)
     300           16 :                cons_info%const_g46_dbd(ig) = rlist(5)
     301           64 :                cons_info%const_g46_dcd(ig) = rlist(6)
     302              :             END DO
     303              :          END IF
     304              :          ! virtual
     305        10519 :          CALL section_vals_get(vsite_section, explicit=explicit, n_repetition=ncons)
     306        10519 :          IF (explicit) THEN
     307            8 :             topology%const_vsite = .TRUE.
     308            8 :             cons_info%nconst_vsite = ncons
     309              :             !
     310           24 :             ALLOCATE (cons_info%const_vsite_mol(ncons))
     311           24 :             ALLOCATE (cons_info%const_vsite_molname(ncons))
     312           16 :             ALLOCATE (cons_info%const_vsite_a(ncons))
     313           16 :             ALLOCATE (cons_info%const_vsite_b(ncons))
     314           16 :             ALLOCATE (cons_info%const_vsite_c(ncons))
     315           16 :             ALLOCATE (cons_info%const_vsite_d(ncons))
     316           24 :             ALLOCATE (cons_info%const_vsite_wbc(ncons))
     317           16 :             ALLOCATE (cons_info%const_vsite_wdc(ncons))
     318           16 :             ALLOCATE (cons_info%vsite_intermolecular(ncons))
     319           16 :             ALLOCATE (cons_info%vsite_restraint(ncons))
     320           16 :             ALLOCATE (cons_info%vsite_k0(ncons))
     321           16 :             ALLOCATE (cons_info%vsite_exclude_qm(ncons))
     322           16 :             ALLOCATE (cons_info%vsite_exclude_mm(ncons))
     323           16 :             DO ig = 1, ncons
     324              :                CALL check_restraint(vsite_section, &
     325              :                                     is_restraint=cons_info%vsite_restraint(ig), &
     326              :                                     k0=cons_info%vsite_k0(ig), &
     327              :                                     i_rep_section=ig, &
     328            8 :                                     label="Virtual_SITE")
     329            8 :                cons_info%const_vsite_mol(ig) = 0
     330            8 :                cons_info%const_vsite_molname(ig) = "UNDEF"
     331              :                ! Exclude QM or MM
     332              :                CALL section_vals_val_get(vsite_section, "EXCLUDE_QM", i_rep_section=ig, &
     333            8 :                                          l_val=cons_info%vsite_exclude_qm(ig))
     334              :                CALL section_vals_val_get(vsite_section, "EXCLUDE_MM", i_rep_section=ig, &
     335            8 :                                          l_val=cons_info%vsite_exclude_mm(ig))
     336              :                ! Intramolecular restraint
     337              :                CALL section_vals_val_get(vsite_section, "INTERMOLECULAR", i_rep_section=ig, &
     338            8 :                                          l_val=cons_info%vsite_intermolecular(ig))
     339              :                ! If it is intramolecular let's unset (in case user did it)
     340              :                ! the molecule and molname field
     341            8 :                IF (cons_info%vsite_intermolecular(ig)) THEN
     342            0 :                   CALL section_vals_val_unset(vsite_section, "MOLECULE", i_rep_section=ig)
     343            0 :                   CALL section_vals_val_unset(vsite_section, "MOLNAME", i_rep_section=ig)
     344              :                END IF
     345              :                ! Let's tag to which molecule we want to apply constraints
     346              :                CALL section_vals_val_get(vsite_section, "MOLECULE", i_rep_section=ig, &
     347            8 :                                          n_rep_val=nrep)
     348            8 :                IF (nrep /= 0) THEN
     349              :                   CALL section_vals_val_get(vsite_section, "MOLECULE", i_rep_section=ig, &
     350            8 :                                             i_val=cons_info%const_vsite_mol(ig))
     351              :                END IF
     352              :                CALL section_vals_val_get(vsite_section, "MOLNAME", i_rep_section=ig, &
     353            8 :                                          n_rep_val=nrep)
     354            8 :                IF (nrep /= 0) THEN
     355              :                   CALL section_vals_val_get(vsite_section, "MOLNAME", i_rep_section=ig, &
     356            0 :                                             c_val=cons_info%const_vsite_molname(ig))
     357              :                END IF
     358            8 :                IF ((cons_info%const_vsite_mol(ig) /= 0) .AND. (cons_info%const_vsite_molname(ig) /= "UNDEF")) THEN
     359              :                   CALL cp_abort(__LOCATION__, &
     360              :                                 "Invalid VIRTUAL_SITE constraint section "//cp_to_string(ig)//": "// &
     361            0 :                                 "check MOLECULE and MOLNAME setup!")
     362              :                END IF
     363            8 :                IF ((cons_info%const_vsite_mol(ig) == 0) .AND. (cons_info%const_vsite_molname(ig) == "UNDEF") .AND. &
     364              :                    (.NOT. cons_info%vsite_intermolecular(ig))) THEN
     365              :                   CALL cp_abort(__LOCATION__, &
     366              :                                 "Invalid VIRTUAL_SITE constraint section "//cp_to_string(ig)//": "// &
     367            0 :                                 "check MOLECULE and MOLNAME setup!")
     368              :                END IF
     369              :                CALL section_vals_val_get(vsite_section, "ATOMS", i_rep_section=ig, &
     370            8 :                                          i_vals=ilist)
     371              :                CALL section_vals_val_get(vsite_section, "PARAMETERS", i_rep_section=ig, &
     372            8 :                                          r_vals=rlist)
     373            8 :                cons_info%const_vsite_a(ig) = ilist(1)
     374            8 :                cons_info%const_vsite_b(ig) = ilist(2)
     375            8 :                cons_info%const_vsite_c(ig) = ilist(3)
     376            8 :                cons_info%const_vsite_d(ig) = ilist(4)
     377            8 :                cons_info%const_vsite_wbc(ig) = rlist(1)
     378           32 :                cons_info%const_vsite_wdc(ig) = rlist(2)
     379              :             END DO
     380              :          END IF
     381              :          ! FIXED ATOMS
     382        10519 :          CALL section_vals_get(fix_atom_section, explicit=explicit, n_repetition=ncons)
     383        10519 :          IF (explicit) THEN
     384          110 :             NULLIFY (tmplist, tmpstringlist)
     385          110 :             isize = 0
     386          110 :             msize = 0
     387          110 :             ALLOCATE (cons_info%fixed_atoms(isize))
     388          110 :             ALLOCATE (cons_info%fixed_type(isize))
     389          110 :             ALLOCATE (cons_info%fixed_restraint(isize))
     390          110 :             ALLOCATE (cons_info%fixed_k0(isize))
     391          110 :             ALLOCATE (cons_info%fixed_molnames(msize))
     392          110 :             ALLOCATE (cons_info%fixed_mol_type(isize))
     393          110 :             ALLOCATE (cons_info%fixed_mol_restraint(msize))
     394          110 :             ALLOCATE (cons_info%fixed_mol_k0(msize))
     395          330 :             ALLOCATE (cons_info%fixed_exclude_qm(ncons))
     396          220 :             ALLOCATE (cons_info%fixed_exclude_mm(ncons))
     397          246 :             DO ig = 1, ncons
     398          136 :                isize_old = isize
     399          136 :                msize_old = msize
     400              :                CALL section_vals_val_get(fix_atom_section, "COMPONENTS_TO_FIX", i_rep_section=ig, &
     401          136 :                                          i_val=itype)
     402              :                CALL section_vals_val_get(fix_atom_section, "LIST", i_rep_section=ig, &
     403          136 :                                          n_rep_val=n_rep)
     404          254 :                DO jg = 1, n_rep
     405              :                   CALL section_vals_val_get(fix_atom_section, "LIST", i_rep_section=ig, &
     406          118 :                                             i_rep_val=jg, i_vals=tmplist)
     407          118 :                   CALL reallocate(cons_info%fixed_atoms, 1, isize + SIZE(tmplist))
     408        20142 :                   cons_info%fixed_atoms(isize + 1:isize + SIZE(tmplist)) = tmplist
     409          118 :                   CALL reallocate(cons_info%fixed_restraint, 1, isize + SIZE(tmplist))
     410          118 :                   CALL reallocate(cons_info%fixed_k0, 1, isize + SIZE(tmplist))
     411          118 :                   CALL reallocate(cons_info%fixed_type, 1, isize + SIZE(tmplist))
     412        10130 :                   cons_info%fixed_type(isize + 1:isize + SIZE(tmplist)) = itype
     413          254 :                   isize = SIZE(cons_info%fixed_atoms)
     414              :                END DO
     415              :                !Check for restraints
     416          136 :                IF ((isize - isize_old) > 0) THEN
     417              :                   CALL check_restraint(fix_atom_section, &
     418              :                                        is_restraint=cons_info%fixed_restraint(isize_old + 1), &
     419              :                                        k0=cons_info%fixed_k0(isize_old + 1), &
     420              :                                        i_rep_section=ig, &
     421          112 :                                        label="FIXED ATOM")
     422        10124 :                   cons_info%fixed_restraint(isize_old + 1:isize) = cons_info%fixed_restraint(isize_old + 1)
     423        10124 :                   cons_info%fixed_k0(isize_old + 1:isize) = cons_info%fixed_k0(isize_old + 1)
     424              :                END IF
     425              :                CALL section_vals_val_get(fix_atom_section, "MOLNAME", i_rep_section=ig, &
     426          136 :                                          n_rep_val=n_rep)
     427          136 :                IF (n_rep /= 0) THEN
     428           12 :                   DO jg = 1, n_rep
     429              :                      CALL section_vals_val_get(fix_atom_section, "MOLNAME", i_rep_section=ig, &
     430            6 :                                                i_rep_val=jg, c_vals=tmpstringlist)
     431            6 :                      CALL reallocate(cons_info%fixed_molnames, 1, msize + SIZE(tmpstringlist, 1))
     432            6 :                      CALL reallocate(cons_info%fixed_mol_type, 1, msize + SIZE(tmpstringlist, 1))
     433            6 :                      CALL reallocate(cons_info%fixed_mol_restraint, 1, msize + SIZE(tmpstringlist, 1))
     434            6 :                      CALL reallocate(cons_info%fixed_mol_k0, 1, msize + SIZE(tmpstringlist, 1))
     435           18 :                      cons_info%fixed_molnames(msize + 1:msize + SIZE(tmpstringlist, 1)) = tmpstringlist
     436           12 :                      cons_info%fixed_mol_type(msize + 1:msize + SIZE(tmpstringlist, 1)) = itype
     437           12 :                      msize = SIZE(cons_info%fixed_molnames)
     438              :                   END DO
     439              :                   ! Exclude QM or MM work only if defined MOLNAME
     440            6 :                   CALL reallocate(cons_info%fixed_exclude_qm, 1, msize)
     441            6 :                   CALL reallocate(cons_info%fixed_exclude_mm, 1, msize)
     442              :                   CALL section_vals_val_get(fix_atom_section, "EXCLUDE_QM", i_rep_section=ig, &
     443            6 :                                             l_val=cons_info%fixed_exclude_qm(msize_old + 1))
     444              :                   CALL section_vals_val_get(fix_atom_section, "EXCLUDE_MM", i_rep_section=ig, &
     445            6 :                                             l_val=cons_info%fixed_exclude_mm(msize_old + 1))
     446           12 :                   cons_info%fixed_exclude_qm(msize_old + 1:msize) = cons_info%fixed_exclude_qm(msize_old + 1)
     447           12 :                   cons_info%fixed_exclude_mm(msize_old + 1:msize) = cons_info%fixed_exclude_mm(msize_old + 1)
     448              :                END IF
     449              :                !Check for restraints
     450          136 :                IF (n_rep /= 0) THEN
     451              :                   CALL check_restraint(fix_atom_section, &
     452              :                                        is_restraint=cons_info%fixed_mol_restraint(msize_old + 1), &
     453              :                                        k0=cons_info%fixed_mol_k0(msize_old + 1), &
     454              :                                        i_rep_section=ig, &
     455            6 :                                        label="FIXED ATOM")
     456           12 :                   cons_info%fixed_mol_restraint(msize_old + 1:msize) = cons_info%fixed_mol_restraint(msize_old + 1)
     457           12 :                   cons_info%fixed_mol_k0(msize_old + 1:msize) = cons_info%fixed_mol_k0(msize_old + 1)
     458              :                END IF
     459              :                CALL section_vals_val_get(fix_atom_section, "MM_SUBSYS", i_rep_section=ig, &
     460          136 :                                          n_rep_val=nrep, explicit=explicit)
     461          136 :                IF (nrep == 1 .AND. explicit) THEN
     462           16 :                   CPASSERT(cons_info%freeze_mm == do_constr_none)
     463              :                   CALL section_vals_val_get(fix_atom_section, "MM_SUBSYS", i_val=cons_info%freeze_mm, &
     464           16 :                                             i_rep_section=ig)
     465           16 :                   cons_info%freeze_mm_type = itype
     466              :                END IF
     467              :                CALL section_vals_val_get(fix_atom_section, "QM_SUBSYS", i_rep_section=ig, &
     468          136 :                                          n_rep_val=nrep, explicit=explicit)
     469          136 :                IF (nrep == 1 .AND. explicit) THEN
     470            2 :                   CPASSERT(cons_info%freeze_qm == do_constr_none)
     471              :                   CALL section_vals_val_get(fix_atom_section, "QM_SUBSYS", i_val=cons_info%freeze_qm, &
     472            2 :                                             i_rep_section=ig)
     473            2 :                   cons_info%freeze_qm_type = itype
     474              :                END IF
     475          136 :                IF (cons_info%freeze_mm /= do_constr_none) THEN
     476              :                   CALL check_restraint(fix_atom_section, &
     477              :                                        is_restraint=cons_info%fixed_mm_restraint, &
     478              :                                        k0=cons_info%fixed_mm_k0, &
     479              :                                        i_rep_section=ig, &
     480           28 :                                        label="FIXED ATOM")
     481              :                END IF
     482          790 :                IF (cons_info%freeze_qm /= do_constr_none) THEN
     483              :                   CALL check_restraint(fix_atom_section, &
     484              :                                        is_restraint=cons_info%fixed_qm_restraint, &
     485              :                                        k0=cons_info%fixed_qm_k0, &
     486              :                                        i_rep_section=ig, &
     487            2 :                                        label="FIXED ATOM")
     488              :                END IF
     489              : 
     490              :             END DO
     491              :             IF ((isize /= 0) .OR. (msize /= 0) .OR. &
     492          110 :                 (cons_info%freeze_mm /= do_constr_none) .OR. &
     493              :                 (cons_info%freeze_qm /= do_constr_none)) THEN
     494          110 :                topology%const_atom = .TRUE.
     495              :             END IF
     496              :          END IF
     497              :          ! Collective Constraints
     498        10519 :          CALL section_vals_get(collective_section, explicit=explicit, n_repetition=ncons)
     499        10519 :          IF (explicit) THEN
     500          120 :             topology%const_colv = .TRUE.
     501          390 :             DO ig = 1, ncons
     502          270 :                CALL section_vals_val_get(collective_section, "COLVAR", i_rep_section=ig, i_val=icolvar)
     503          390 :                IF (icolvar > SIZE(colvar_p)) THEN
     504            0 :                   CPABORT("More collective constraints than collective variables specified.")
     505              :                END IF
     506              :             END DO
     507          120 :             cons_info%nconst_colv = ncons
     508          360 :             ALLOCATE (cons_info%const_colv_mol(ncons))
     509          360 :             ALLOCATE (cons_info%const_colv_molname(ncons))
     510          360 :             ALLOCATE (cons_info%const_colv_target(ncons))
     511          240 :             ALLOCATE (cons_info%const_colv_target_growth(ncons))
     512          510 :             ALLOCATE (cons_info%colvar_set(ncons))
     513          240 :             ALLOCATE (cons_info%colv_intermolecular(ncons))
     514          240 :             ALLOCATE (cons_info%colv_restraint(ncons))
     515          240 :             ALLOCATE (cons_info%colv_k0(ncons))
     516          240 :             ALLOCATE (cons_info%colv_exclude_qm(ncons))
     517          240 :             ALLOCATE (cons_info%colv_exclude_mm(ncons))
     518          390 :             DO ig = 1, ncons
     519              :                CALL check_restraint(collective_section, &
     520              :                                     is_restraint=cons_info%colv_restraint(ig), &
     521              :                                     k0=cons_info%colv_k0(ig), &
     522              :                                     i_rep_section=ig, &
     523          270 :                                     label="COLLECTIVE")
     524          270 :                cons_info%const_colv_mol(ig) = 0
     525          270 :                cons_info%const_colv_molname(ig) = "UNDEF"
     526              :                ! Exclude QM or MM
     527              :                CALL section_vals_val_get(collective_section, "EXCLUDE_QM", i_rep_section=ig, &
     528          270 :                                          l_val=cons_info%colv_exclude_qm(ig))
     529              :                CALL section_vals_val_get(collective_section, "EXCLUDE_MM", i_rep_section=ig, &
     530          270 :                                          l_val=cons_info%colv_exclude_mm(ig))
     531              :                ! Intramolecular restraint
     532              :                CALL section_vals_val_get(collective_section, "INTERMOLECULAR", i_rep_section=ig, &
     533          270 :                                          l_val=cons_info%colv_intermolecular(ig))
     534              :                ! If it is intramolecular let's unset (in case user did it)
     535              :                ! the molecule and molname field
     536          270 :                IF (cons_info%colv_intermolecular(ig)) THEN
     537           66 :                   CALL section_vals_val_unset(collective_section, "MOLECULE", i_rep_section=ig)
     538           66 :                   CALL section_vals_val_unset(collective_section, "MOLNAME", i_rep_section=ig)
     539              :                END IF
     540              :                ! Let's tag to which molecule we want to apply constraints
     541              :                CALL section_vals_val_get(collective_section, "MOLECULE", i_rep_section=ig, &
     542          270 :                                          n_rep_val=nrep)
     543          270 :                IF (nrep /= 0) THEN
     544              :                   CALL section_vals_val_get(collective_section, "MOLECULE", i_rep_section=ig, &
     545          160 :                                             i_val=cons_info%const_colv_mol(ig))
     546              :                END IF
     547              :                CALL section_vals_val_get(collective_section, "MOLNAME", i_rep_section=ig, &
     548          270 :                                          n_rep_val=nrep)
     549          270 :                IF (nrep /= 0) THEN
     550              :                   CALL section_vals_val_get(collective_section, "MOLNAME", i_rep_section=ig, &
     551           44 :                                             c_val=cons_info%const_colv_molname(ig))
     552              :                END IF
     553          270 :                IF (((cons_info%const_colv_mol(ig) /= 0) .AND. (cons_info%const_colv_molname(ig) /= "UNDEF"))) THEN
     554            0 :                   CPABORT("Both MOLNAME and MOLECULE specified for CONSTRAINT section. ")
     555              :                END IF
     556          270 :                IF ((cons_info%const_colv_mol(ig) == 0) .AND. (cons_info%const_colv_molname(ig) == "UNDEF") .AND. &
     557              :                    (.NOT. cons_info%colv_intermolecular(ig))) THEN
     558              :                   CALL cp_abort(__LOCATION__, &
     559              :                                 "Constraint section error: you have to specify at least one of the "// &
     560            0 :                                 "following keywords: MOLECULE, MOLNAME or INTERMOLECULAR! ")
     561              :                END IF
     562          270 :                NULLIFY (cons_info%colvar_set(ig)%colvar)
     563              :                CALL section_vals_val_get(collective_section, "COLVAR", i_rep_section=ig, &
     564          270 :                                          i_val=icolvar)
     565              :                CALL colvar_clone(cons_info%colvar_set(ig)%colvar, &
     566          270 :                                  colvar_p(icolvar)%colvar)
     567              :                CALL section_vals_val_get(collective_section, "TARGET", &
     568          270 :                                          n_rep_val=n_rep, i_rep_section=ig)
     569          270 :                IF (n_rep /= 0) THEN
     570              :                   CALL section_vals_val_get(collective_section, "TARGET", &
     571          168 :                                             r_val=cons_info%const_colv_target(ig), i_rep_section=ig)
     572              :                ELSE
     573          102 :                   cons_info%const_colv_target(ig) = -HUGE(0.0_dp)
     574              :                END IF
     575              :                CALL section_vals_val_get(collective_section, "TARGET_GROWTH", &
     576         1470 :                                          r_val=cons_info%const_colv_target_growth(ig), i_rep_section=ig)
     577              :             END DO
     578              :          END IF
     579              :       END IF
     580              : 
     581        10854 :    END SUBROUTINE read_constraints_section
     582              : 
     583              : ! **************************************************************************************************
     584              : !> \brief Reads input and decides if apply restraints instead of constraints
     585              : !> \param cons_section ...
     586              : !> \param is_restraint ...
     587              : !> \param k0 ...
     588              : !> \param i_rep_section ...
     589              : !> \param label ...
     590              : !> \author teo
     591              : ! **************************************************************************************************
     592        22242 :    SUBROUTINE check_restraint(cons_section, is_restraint, k0, i_rep_section, label)
     593              :       TYPE(section_vals_type), POINTER                   :: cons_section
     594              :       LOGICAL, INTENT(OUT)                               :: is_restraint
     595              :       REAL(KIND=dp), INTENT(OUT)                         :: k0
     596              :       INTEGER, INTENT(IN), OPTIONAL                      :: i_rep_section
     597              :       CHARACTER(LEN=*), INTENT(IN)                       :: label
     598              : 
     599              :       CHARACTER(LEN=default_string_length)               :: nlabel
     600              :       INTEGER                                            :: output_unit
     601              :       LOGICAL                                            :: explicit
     602              :       TYPE(section_vals_type), POINTER                   :: restraint_section
     603              : 
     604        11121 :       is_restraint = .FALSE.
     605        11121 :       output_unit = cp_logger_get_default_io_unit()
     606        11121 :       CALL section_vals_get(cons_section, explicit=explicit)
     607        11121 :       IF (explicit) THEN
     608              :          restraint_section => section_vals_get_subs_vals(cons_section, "RESTRAINT", &
     609          618 :                                                          i_rep_section=i_rep_section)
     610          618 :          CALL section_vals_get(restraint_section, explicit=is_restraint)
     611          618 :          IF (is_restraint) THEN
     612          124 :             CALL section_vals_val_get(restraint_section, "K", r_val=k0)
     613          124 :             IF (output_unit > 0) THEN
     614           64 :                nlabel = cp_to_string(i_rep_section)
     615              :                WRITE (output_unit, FMT='(T2,"RESTRAINT|",1X,A,F9.6)') &
     616              :                   "Active restraint on "//label//" section Nr."// &
     617           64 :                   TRIM(nlabel)//". K [a.u.]=", k0
     618              :             END IF
     619              :          END IF
     620              :       END IF
     621        11121 :    END SUBROUTINE check_restraint
     622              : 
     623              : END MODULE topology_input
     624              : 
        

Generated by: LCOV version 2.0-1