LCOV - code coverage report
Current view: top level - src - input_optimize_input.F (source / functions) Coverage Total Hit
Test: CP2K Regtests (git:936074a) Lines: 100.0 % 97 97
Test Date: 2025-12-04 06:27:48 Functions: 100.0 % 1 1

            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              : !> \brief builds the input structure for optimize_input
      10              : !> \par History
      11              : !>      09.2010 created [Joost VandeVondele]
      12              : !> \author Joost VandeVondele
      13              : ! **************************************************************************************************
      14              : MODULE input_optimize_input
      15              :    USE cp_output_handling, ONLY: cp_print_key_section_create, &
      16              :                                  low_print_level
      17              :    USE input_constants, ONLY: opt_force_matching
      18              :    USE input_keyword_types, ONLY: keyword_create, &
      19              :                                   keyword_release, &
      20              :                                   keyword_type
      21              :    USE input_section_types, ONLY: section_add_keyword, &
      22              :                                   section_add_subsection, &
      23              :                                   section_create, &
      24              :                                   section_release, &
      25              :                                   section_type
      26              :    USE input_val_types, ONLY: char_t, &
      27              :                               real_t
      28              :    USE kinds, ONLY: dp
      29              :    USE string_utilities, ONLY: s2a
      30              : #include "./base/base_uses.f90"
      31              : 
      32              :    IMPLICIT NONE
      33              :    PRIVATE
      34              : 
      35              :    CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'input_optimize_input'
      36              :    PUBLIC :: create_optimize_input_section
      37              : 
      38              : CONTAINS
      39              : 
      40              : ! **************************************************************************************************
      41              : !> \brief creates the optimize_input section
      42              : !> \param section ...
      43              : !> \author Joost VandeVondele
      44              : ! **************************************************************************************************
      45         9284 :    SUBROUTINE create_optimize_input_section(section)
      46              :       TYPE(section_type), POINTER                        :: section
      47              : 
      48              :       TYPE(keyword_type), POINTER                        :: keyword
      49              :       TYPE(section_type), POINTER                        :: sub_section, subsubsection
      50              : 
      51         9284 :       CPASSERT(.NOT. ASSOCIATED(section))
      52              :       CALL section_create(section, __LOCATION__, name="OPTIMIZE_INPUT", &
      53              :                           description="describes an input optimization job, in which parameters in input files get optimized.", &
      54         9284 :                           repeats=.FALSE.)
      55         9284 :       NULLIFY (keyword)
      56              : 
      57              :       CALL keyword_create(keyword, __LOCATION__, name="METHOD", &
      58              :                           description="What kind of input optimization to perform.", &
      59              :                           usage="METHOD FORCE_MATCHING", &
      60              :                           enum_c_vals=s2a("FORCE_MATCHING"), &
      61              :                           enum_desc=s2a("Perform a force matching minimization."), &
      62              :                           enum_i_vals=[opt_force_matching], &
      63         9284 :                           default_i_val=opt_force_matching)
      64         9284 :       CALL section_add_keyword(section, keyword)
      65         9284 :       CALL keyword_release(keyword)
      66              : 
      67              :       CALL keyword_create(keyword, __LOCATION__, name="ACCURACY", &
      68              :                           description="Final accuracy requested in optimization (RHOEND)", &
      69              :                           usage="ACCURACY 0.00001", &
      70         9284 :                           default_r_val=1.e-5_dp)
      71         9284 :       CALL section_add_keyword(section, keyword)
      72         9284 :       CALL keyword_release(keyword)
      73              : 
      74              :       CALL keyword_create(keyword, __LOCATION__, name="STEP_SIZE", &
      75              :                           description="Initial step size for search algorithm (RHOBEG)", &
      76              :                           usage="STEP_SIZE 0.005", &
      77         9284 :                           default_r_val=0.05_dp)
      78         9284 :       CALL section_add_keyword(section, keyword)
      79         9284 :       CALL keyword_release(keyword)
      80              : 
      81              :       CALL keyword_create(keyword, __LOCATION__, name="MAX_FUN", &
      82              :                           description="Maximum number of function evaluations", &
      83              :                           usage="MAX_FUN 1000", &
      84         9284 :                           default_i_val=5000)
      85         9284 :       CALL section_add_keyword(section, keyword)
      86         9284 :       CALL keyword_release(keyword)
      87              : 
      88              :       CALL keyword_create(keyword, __LOCATION__, name="ITER_START_VAL", &
      89              :                           description="Used for restarting, starting value of the iteration", &
      90              :                           usage="ITER_START_VAL 0", &
      91         9284 :                           default_i_val=0)
      92         9284 :       CALL section_add_keyword(section, keyword)
      93         9284 :       CALL keyword_release(keyword)
      94              : 
      95              :       CALL keyword_create(keyword, __LOCATION__, name="RANDOMIZE_VARIABLES", &
      96              :                           description="Percentage randomization of the free variables applied initially", &
      97              :                           usage="RANDOMIZE_VARIABLES 20", &
      98         9284 :                           default_r_val=0.00_dp)
      99         9284 :       CALL section_add_keyword(section, keyword)
     100         9284 :       CALL keyword_release(keyword)
     101              : 
     102              :       !
     103              :       ! variables section
     104              :       !
     105              : 
     106         9284 :       NULLIFY (sub_section)
     107              :       CALL section_create(sub_section, __LOCATION__, name="VARIABLE", &
     108              :                           description="Defines initial values for variables and their labels", &
     109         9284 :                           n_subsections=0, repeats=.TRUE.)
     110              : 
     111              :       CALL keyword_create(keyword, __LOCATION__, name="VALUE", &
     112              :                           description="Initial value of the variable", &
     113              :                           usage="VALUE 0.0", &
     114         9284 :                           type_of_var=real_t, unit_str="internal_cp2k")
     115         9284 :       CALL section_add_keyword(sub_section, keyword)
     116         9284 :       CALL keyword_release(keyword)
     117              : 
     118              :       CALL keyword_create(keyword, __LOCATION__, name="FIXED", &
     119              :                           description="Is this variable fixed or should it be optimized.", &
     120              :                           usage="FIXED", &
     121         9284 :                           default_l_val=.FALSE., lone_keyword_l_val=.TRUE.)
     122         9284 :       CALL section_add_keyword(sub_section, keyword)
     123         9284 :       CALL keyword_release(keyword)
     124              : 
     125              :       CALL keyword_create(keyword, __LOCATION__, name="LABEL", &
     126              :                           description="The label used in the input file, i.e. ${LABEL} will be replaced by the VALUE specified.", &
     127              :                           usage="LABEL PRM01", &
     128         9284 :                           type_of_var=char_t)
     129         9284 :       CALL section_add_keyword(sub_section, keyword)
     130         9284 :       CALL keyword_release(keyword)
     131              : 
     132         9284 :       CALL section_add_subsection(section, sub_section)
     133         9284 :       CALL section_release(sub_section)
     134              : 
     135              :       !
     136              :       ! force matching sub sectiong
     137              :       !
     138              : 
     139         9284 :       NULLIFY (sub_section)
     140              :       CALL section_create(sub_section, __LOCATION__, name="FORCE_MATCHING", &
     141              :                           description="Specify the force matching input.", &
     142         9284 :                           repeats=.TRUE.)
     143              : 
     144              :       CALL keyword_create(keyword, __LOCATION__, name="OPTIMIZE_FILE_NAME", &
     145              :                           description="the filename of the input file which contains the parameters to be optimized", &
     146              :                           usage="OPTIMIZE_FILE_NAME my_input.inp", &
     147         9284 :                           default_lc_val="")
     148         9284 :       CALL section_add_keyword(sub_section, keyword)
     149         9284 :       CALL keyword_release(keyword)
     150              : 
     151              :       CALL keyword_create(keyword, __LOCATION__, name="REF_TRAJ_FILE_NAME", &
     152              :                           description="the filename of the reference coordinates.", &
     153              :                           usage="REF_TRAJ_FILE_NAME pos.xyz", &
     154         9284 :                           default_lc_val="")
     155         9284 :       CALL section_add_keyword(sub_section, keyword)
     156         9284 :       CALL keyword_release(keyword)
     157              : 
     158              :       CALL keyword_create(keyword, __LOCATION__, name="REF_FORCE_FILE_NAME", &
     159              :                           description="the filename of the reference forces, should also contain the energy", &
     160              :                           usage="REF_FORCE_FILE_NAME frc.xyz", &
     161         9284 :                           default_lc_val="")
     162         9284 :       CALL section_add_keyword(sub_section, keyword)
     163         9284 :       CALL keyword_release(keyword)
     164              : 
     165              :       CALL keyword_create(keyword, __LOCATION__, name="REF_CELL_FILE_NAME", &
     166              :                           description="the filename of the reference cell", &
     167              :                           usage="REF_CELL_FILE_NAME project.cell", &
     168         9284 :                           default_lc_val="")
     169         9284 :       CALL section_add_keyword(sub_section, keyword)
     170         9284 :       CALL keyword_release(keyword)
     171              : 
     172              :       CALL keyword_create(keyword, __LOCATION__, name="GROUP_SIZE", &
     173              :                           description="Gives the preferred size of a working group, "// &
     174              :                           "groups will always be equal or larger than this size. "// &
     175              :                           "Usually this should take the number of cores per socket into account for good performance.", &
     176         9284 :                           usage="group_size 2", default_i_val=6)
     177         9284 :       CALL section_add_keyword(sub_section, keyword)
     178         9284 :       CALL keyword_release(keyword)
     179              : 
     180              :       CALL keyword_create(keyword, __LOCATION__, name="FRAME_START", &
     181              :                           description="starting frame to be used from the reference trajectory", &
     182         9284 :                           usage="FRAME_START 1", default_i_val=1)
     183         9284 :       CALL section_add_keyword(sub_section, keyword)
     184         9284 :       CALL keyword_release(keyword)
     185              : 
     186              :       CALL keyword_create(keyword, __LOCATION__, name="FRAME_STOP", &
     187              :                           description="final frame to be used from the reference trajectory (all=-1)", &
     188         9284 :                           usage="FRAME_STOP -1", default_i_val=-1)
     189         9284 :       CALL section_add_keyword(sub_section, keyword)
     190         9284 :       CALL keyword_release(keyword)
     191              : 
     192              :       CALL keyword_create(keyword, __LOCATION__, name="FRAME_STRIDE", &
     193              :                           description="stride when using the reference trajectory", &
     194         9284 :                           usage="FRAME_STRIDE 1", default_i_val=1)
     195         9284 :       CALL section_add_keyword(sub_section, keyword)
     196         9284 :       CALL keyword_release(keyword)
     197              : 
     198              :       CALL keyword_create(keyword, __LOCATION__, name="FRAME_COUNT", &
     199              :                           description="Use at most FRAME_COUNT frames from the reference trajectory, "// &
     200              :                           "adjusting the stride to have them as fas apart as possible (all=-1).", &
     201         9284 :                           usage="FRAME_COUNT 100", default_i_val=-1)
     202         9284 :       CALL section_add_keyword(sub_section, keyword)
     203         9284 :       CALL keyword_release(keyword)
     204              : 
     205              :       CALL keyword_create(keyword, __LOCATION__, name="ENERGY_WEIGHT", &
     206              :                           description="Relative weight of the energy RMSD vs the force RMSD", &
     207         9284 :                           usage="ENERGY_WEIGHT 0.1", default_r_val=0.1_dp)
     208         9284 :       CALL section_add_keyword(sub_section, keyword)
     209         9284 :       CALL keyword_release(keyword)
     210              : 
     211              :       CALL keyword_create(keyword, __LOCATION__, name="SHIFT_AVERAGE", &
     212              :                           description="Shift averages of the energies before computing energy RMSD.", &
     213         9284 :                           usage="SHIFT_AVERAGE", default_l_val=.FALSE., lone_keyword_l_val=.TRUE.)
     214         9284 :       CALL section_add_keyword(sub_section, keyword)
     215         9284 :       CALL keyword_release(keyword)
     216              : 
     217              :       CALL keyword_create(keyword, __LOCATION__, name="SHIFT_QM", &
     218              :                           description="Shift of the reference energies applied before computing energy RMSD.", &
     219         9284 :                           usage="SHIFT_QM -17.0", default_r_val=0.0_dp)
     220         9284 :       CALL section_add_keyword(sub_section, keyword)
     221         9284 :       CALL keyword_release(keyword)
     222              : 
     223              :       CALL keyword_create(keyword, __LOCATION__, name="SHIFT_MM", &
     224              :                           description="Shift of the fit energies applied before computing energy RMSD.", &
     225         9284 :                           usage="SHIFT_MM 0.0", default_r_val=0.0_dp)
     226         9284 :       CALL section_add_keyword(sub_section, keyword)
     227         9284 :       CALL keyword_release(keyword)
     228              : 
     229         9284 :       NULLIFY (subsubsection)
     230              :       CALL cp_print_key_section_create(subsubsection, __LOCATION__, "COMPARE_ENERGIES", &
     231              :                                        description="A comparison of energies between fit and reference", &
     232         9284 :                                        print_level=low_print_level, filename="compare_energies", common_iter_levels=1)
     233         9284 :       CALL section_add_subsection(sub_section, subsubsection)
     234         9284 :       CALL section_release(subsubsection)
     235              : 
     236         9284 :       NULLIFY (subsubsection)
     237              :       CALL cp_print_key_section_create(subsubsection, __LOCATION__, "COMPARE_FORCES", &
     238              :                                        description="A comparison of forces between fit and reference", &
     239         9284 :                                        print_level=low_print_level, filename="compare_forces", common_iter_levels=1)
     240         9284 :       CALL section_add_subsection(sub_section, subsubsection)
     241         9284 :       CALL section_release(subsubsection)
     242              : 
     243         9284 :       CALL section_add_subsection(section, sub_section)
     244         9284 :       CALL section_release(sub_section)
     245              : 
     246         9284 :       NULLIFY (subsubsection)
     247              :       CALL cp_print_key_section_create(subsubsection, __LOCATION__, "HISTORY", &
     248              :                                        description="writes a history of the function value and parameters", &
     249         9284 :                                        print_level=low_print_level, filename="history", common_iter_levels=1)
     250         9284 :       CALL section_add_subsection(section, subsubsection)
     251         9284 :       CALL section_release(subsubsection)
     252              : 
     253              :       CALL cp_print_key_section_create(subsubsection, __LOCATION__, "RESTART", &
     254              :                                        description="writes an input file that can be used to restart ", &
     255         9284 :                                        print_level=low_print_level, filename="optimize", common_iter_levels=1)
     256              :       CALL keyword_create(keyword, __LOCATION__, name="BACKUP_COPIES", &
     257              :                           description="Specifies the maximum number of backup copies.", &
     258              :                           usage="BACKUP_COPIES {int}", &
     259         9284 :                           default_i_val=1)
     260         9284 :       CALL section_add_keyword(subsubsection, keyword)
     261         9284 :       CALL keyword_release(keyword)
     262         9284 :       CALL section_add_subsection(section, subsubsection)
     263         9284 :       CALL section_release(subsubsection)
     264              : 
     265         9284 :    END SUBROUTINE create_optimize_input_section
     266              : 
     267              : END MODULE input_optimize_input
     268              : 
        

Generated by: LCOV version 2.0-1