LCOV - code coverage report
Current view: top level - src - input_cp2k_nnp.F (source / functions) Hit Total Coverage
Test: CP2K Regtests (git:2fce0f8) Lines: 69 69 100.0 %
Date: 2024-12-21 06:28:57 Functions: 3 3 100.0 %

          Line data    Source code
       1             : !--------------------------------------------------------------------------------------------------!
       2             : !   CP2K: A general program to perform molecular dynamics simulations                              !
       3             : !   Copyright 2000-2024 CP2K developers group <https://cp2k.org>                                   !
       4             : !                                                                                                  !
       5             : !   SPDX-License-Identifier: GPL-2.0-or-later                                                      !
       6             : !--------------------------------------------------------------------------------------------------!
       7             : 
       8             : ! **************************************************************************************************
       9             : !> \brief  Creates the NNP section of the input
      10             : !> \author Christoph Schran (christoph.schran@rub.de)
      11             : !> \date   2020-10-10
      12             : ! **************************************************************************************************
      13             : MODULE input_cp2k_nnp
      14             : 
      15             :    USE bibliography,                    ONLY: Behler2007,&
      16             :                                               Behler2011,&
      17             :                                               Schran2020a,&
      18             :                                               Schran2020b
      19             :    USE cp_output_handling,              ONLY: cp_print_key_section_create,&
      20             :                                               medium_print_level
      21             :    USE cp_units,                        ONLY: cp_unit_to_cp2k
      22             :    USE input_keyword_types,             ONLY: keyword_create,&
      23             :                                               keyword_release,&
      24             :                                               keyword_type
      25             :    USE input_section_types,             ONLY: section_add_keyword,&
      26             :                                               section_add_subsection,&
      27             :                                               section_create,&
      28             :                                               section_release,&
      29             :                                               section_type
      30             :    USE input_val_types,                 ONLY: char_t,&
      31             :                                               real_t
      32             :    USE kinds,                           ONLY: dp
      33             : #include "./base/base_uses.f90"
      34             : 
      35             :    IMPLICIT NONE
      36             :    PRIVATE
      37             : 
      38             :    LOGICAL, PRIVATE, PARAMETER :: debug_this_module = .TRUE.
      39             :    CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'input_cp2k_nnp'
      40             : 
      41             :    PUBLIC :: create_nnp_section
      42             : 
      43             : CONTAINS
      44             : 
      45             : ! **************************************************************************************************
      46             : !> \brief Create the input section for NNP
      47             : !> \param section the section to create
      48             : !> \date   2020-10-10
      49             : !> \author Christoph Schran (christoph.schran@rub.de)
      50             : ! **************************************************************************************************
      51        9174 :    SUBROUTINE create_nnp_section(section)
      52             :       TYPE(section_type), POINTER                        :: section
      53             : 
      54             :       TYPE(keyword_type), POINTER                        :: keyword
      55             :       TYPE(section_type), POINTER                        :: subsection, subsubsection
      56             : 
      57        9174 :       CPASSERT(.NOT. ASSOCIATED(section))
      58             :       CALL section_create(section, __LOCATION__, name="NNP", &
      59             :                           description="This section contains all information to run a "// &
      60             :                           "Neural Network Potential (NNP) calculation.", &
      61             :                           n_keywords=3, n_subsections=3, repeats=.FALSE., &
      62       45870 :                           citations=(/Behler2007, Behler2011, Schran2020a, Schran2020b/))
      63             : 
      64        9174 :       NULLIFY (subsection, subsubsection, keyword)
      65             : 
      66             :       CALL keyword_create(keyword, __LOCATION__, name="NNP_INPUT_FILE_NAME", &
      67             :                           description="File containing the input information for "// &
      68             :                           "the setup of the NNP (n2p2/RuNNer format).", &
      69        9174 :                           repeats=.FALSE., default_lc_val="input.nn")
      70        9174 :       CALL section_add_keyword(section, keyword)
      71        9174 :       CALL keyword_release(keyword)
      72             :       CALL keyword_create(keyword, __LOCATION__, name="SCALE_FILE_NAME", &
      73             :                           description="File containing the scaling information for "// &
      74             :                           "the symmetry functions of the NNP.", &
      75        9174 :                           repeats=.FALSE., default_lc_val="scaling.data")
      76        9174 :       CALL section_add_keyword(section, keyword)
      77        9174 :       CALL keyword_release(keyword)
      78             : 
      79             :       ! BIAS subsection
      80             :       CALL section_create(subsection, __LOCATION__, name="BIAS", &
      81             :                           description="Section to bias the committee disagreement (sigma) by "// &
      82             :                           "E = 0.5 * K_B * (sigma - SIGMA_0)**2, if sigma > SIGMA_0.", &
      83             :                           n_keywords=2, n_subsections=0, repeats=.FALSE., &
      84       18348 :                           citations=(/Schran2020b/))
      85             :       CALL keyword_create(keyword, __LOCATION__, name="K_B", &
      86             :                           description="Harmonic spring constant of the bias potential [1/hartree].", &
      87             :                           repeats=.FALSE., &
      88             :                           n_var=1, &
      89             :                           type_of_var=real_t, &
      90             :                           default_r_val=cp_unit_to_cp2k(value=0.1_dp, unit_str="hartree^-1"), &
      91             :                           unit_str="hartree^-1", &
      92        9174 :                           usage="K_B [hartree^-1] 0.1")
      93        9174 :       CALL section_add_keyword(subsection, keyword)
      94        9174 :       CALL keyword_release(keyword)
      95             :       CALL keyword_create(keyword, __LOCATION__, name="SIGMA_0", &
      96             :                           description="Shift of the harmonic bias potential.", &
      97             :                           repeats=.FALSE., &
      98             :                           n_var=1, &
      99             :                           type_of_var=real_t, &
     100             :                           default_r_val=cp_unit_to_cp2k(value=0.1_dp, unit_str="hartree"), &
     101             :                           unit_str="hartree", &
     102        9174 :                           usage="SIGMA_0 [hartree] 0.1")
     103        9174 :       CALL section_add_keyword(subsection, keyword)
     104        9174 :       CALL keyword_release(keyword)
     105             :       CALL keyword_create(keyword, __LOCATION__, name="ALIGN_NNP_ENERGIES", &
     106             :                           description="Remove PES shifts within the committee by "// &
     107             :                           "subtracting energy for each committee member. Provide "// &
     108             :                           "one number per C-NNP member.", &
     109             :                           repeats=.FALSE., &
     110             :                           n_var=-1, &
     111             :                           type_of_var=real_t, &
     112        9174 :                           usage="ALIGN_NNP_ENERGIES <REAL> <REAL> ... <REAL>")
     113        9174 :       CALL section_add_keyword(subsection, keyword)
     114        9174 :       CALL keyword_release(keyword)
     115             :       ! print bias subsubsection:
     116        9174 :       CALL create_nnp_bias_print_section(subsubsection)
     117        9174 :       CALL section_add_subsection(subsection, subsubsection)
     118        9174 :       CALL section_release(subsubsection)
     119             : 
     120        9174 :       CALL section_add_subsection(section, subsection)
     121        9174 :       CALL section_release(subsection)
     122             :       ! end BIAS subsection
     123             : 
     124             :       CALL section_create(subsection, __LOCATION__, name="MODEL", &
     125             :                           description="Section for a single NNP model. "// &
     126             :                           "If this section is repeated, a committee model (C-NNP) "// &
     127             :                           "is used where the NNP members share the same symmetry functions.", &
     128        9174 :                           n_keywords=1, n_subsections=0, repeats=.TRUE.)
     129             :       CALL keyword_create(keyword, __LOCATION__, name="WEIGHTS", &
     130             :                           description="File containing the weights for the "// &
     131             :                           "artificial neural networks of the NNP. "// &
     132             :                           "The specified name is extended by .XXX.data", &
     133        9174 :                           repeats=.FALSE., default_lc_val="weights")
     134        9174 :       CALL section_add_keyword(subsection, keyword)
     135        9174 :       CALL keyword_release(keyword)
     136        9174 :       CALL section_add_subsection(section, subsection)
     137        9174 :       CALL section_release(subsection)
     138             : 
     139        9174 :       CALL create_nnp_print_section(subsection)
     140        9174 :       CALL section_add_subsection(section, subsection)
     141        9174 :       CALL section_release(subsection)
     142             : 
     143        9174 :    END SUBROUTINE create_nnp_section
     144             : 
     145             : ! **************************************************************************************************
     146             : !> \brief Creates the print section for the nnp subsection
     147             : !> \param section the section to create
     148             : !> \date   2020-10-10
     149             : !> \author Christoph Schran (christoph.schran@rub.de)
     150             : ! **************************************************************************************************
     151        9174 :    SUBROUTINE create_nnp_print_section(section)
     152             :       TYPE(section_type), POINTER                        :: section
     153             : 
     154             :       TYPE(keyword_type), POINTER                        :: keyword
     155             :       TYPE(section_type), POINTER                        :: print_key
     156             : 
     157        9174 :       CPASSERT(.NOT. ASSOCIATED(section))
     158             :       CALL section_create(section, __LOCATION__, name="PRINT", &
     159             :                           description="Section of possible print options in NNP code.", &
     160        9174 :                           n_keywords=0, n_subsections=5, repeats=.FALSE.)
     161             : 
     162        9174 :       NULLIFY (print_key, keyword)
     163             : 
     164             :       CALL cp_print_key_section_create(print_key, __LOCATION__, "ENERGIES", &
     165             :                                        description="Controls the printing of the NNP energies.", &
     166        9174 :                                        print_level=medium_print_level, common_iter_levels=1)
     167        9174 :       CALL section_add_subsection(section, print_key)
     168        9174 :       CALL section_release(print_key)
     169             : 
     170             :       CALL cp_print_key_section_create(print_key, __LOCATION__, "FORCES", &
     171             :                                        description="Controls the printing of the NNP forces.", &
     172        9174 :                                        print_level=medium_print_level, common_iter_levels=1)
     173        9174 :       CALL section_add_subsection(section, print_key)
     174        9174 :       CALL section_release(print_key)
     175             : 
     176             :       CALL cp_print_key_section_create(print_key, __LOCATION__, "FORCES_SIGMA", &
     177             :                                        description="Controls the printing of the STD per atom of the NNP forces.", &
     178        9174 :                                        print_level=medium_print_level, common_iter_levels=1)
     179        9174 :       CALL section_add_subsection(section, print_key)
     180        9174 :       CALL section_release(print_key)
     181             : 
     182             :       CALL cp_print_key_section_create(print_key, __LOCATION__, "EXTRAPOLATION", &
     183             :                                        description="If activated, output structures with extrapolation "// &
     184             :                                        "warning in xyz-format", &
     185        9174 :                                        print_level=medium_print_level, common_iter_levels=1)
     186        9174 :       CALL section_add_subsection(section, print_key)
     187        9174 :       CALL section_release(print_key)
     188             : 
     189             :       CALL cp_print_key_section_create(print_key, __LOCATION__, "SUM_FORCE", &
     190             :                                        description="If activated, output summed force over specified atoms. "// &
     191             :                                        "Used in Green-Kubo relation for friction at liquid-solid interfaces.", &
     192        9174 :                                        print_level=medium_print_level, common_iter_levels=1)
     193             : 
     194             :       CALL keyword_create(keyword, __LOCATION__, name="ATOM_LIST", &
     195             :                           description="List of atoms over which to calculate summed force", &
     196             :                           usage="ATOM_LISTS {O} {H} .. {X}", repeats=.FALSE., &
     197        9174 :                           n_var=-1, type_of_var=char_t)
     198        9174 :       CALL section_add_keyword(print_key, keyword)
     199        9174 :       CALL keyword_release(keyword)
     200             : 
     201        9174 :       CALL section_add_subsection(section, print_key)
     202        9174 :       CALL section_release(print_key)
     203             : 
     204        9174 :    END SUBROUTINE create_nnp_print_section
     205             : 
     206             : ! **************************************************************************************************
     207             : !> \brief Creates the print section for the nnp bias subsubsection
     208             : !> \param section the section to create
     209             : !> \date   2020-10-10
     210             : !> \author Christoph Schran (christoph.schran@rub.de)
     211             : ! **************************************************************************************************
     212        9174 :    SUBROUTINE create_nnp_bias_print_section(section)
     213             :       TYPE(section_type), POINTER                        :: section
     214             : 
     215             :       TYPE(section_type), POINTER                        :: print_key
     216             : 
     217        9174 :       CPASSERT(.NOT. ASSOCIATED(section))
     218             :       CALL section_create(section, __LOCATION__, name="PRINT", &
     219             :                           description="Section of possible print options in NNP code.", &
     220        9174 :                           n_keywords=0, n_subsections=3, repeats=.FALSE.)
     221             : 
     222        9174 :       NULLIFY (print_key)
     223             : 
     224             :       CALL cp_print_key_section_create(print_key, __LOCATION__, "BIAS_ENERGY", &
     225             :                                        description="Controls the printing of the BIAS energy.", &
     226        9174 :                                        print_level=medium_print_level, common_iter_levels=1)
     227        9174 :       CALL section_add_subsection(section, print_key)
     228        9174 :       CALL section_release(print_key)
     229             : 
     230             :       CALL cp_print_key_section_create(print_key, __LOCATION__, "BIAS_FORCES", &
     231             :                                        description="Controls the printing of the BIAS forces.", &
     232        9174 :                                        print_level=medium_print_level, common_iter_levels=1)
     233        9174 :       CALL section_add_subsection(section, print_key)
     234        9174 :       CALL section_release(print_key)
     235             : 
     236        9174 :    END SUBROUTINE create_nnp_bias_print_section
     237             : 
     238             : END MODULE input_cp2k_nnp

Generated by: LCOV version 1.15