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

            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 Declares the input for global optimization
      10              : !> \author Ole Schuett
      11              : ! **************************************************************************************************
      12              : MODULE glbopt_input
      13              :    USE bibliography,                    ONLY: Goedecker2004
      14              :    USE cp_output_handling,              ONLY: cp_print_key_section_create,&
      15              :                                               low_print_level
      16              :    USE input_constants,                 ONLY: glbopt_do_mincrawl,&
      17              :                                               glbopt_do_minhop
      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: integer_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 = 'glbopt_input'
      36              : 
      37              :    PUBLIC :: glbopt_declare_input
      38              : 
      39              : CONTAINS
      40              : 
      41              : ! **************************************************************************************************
      42              : !> \brief Declares the SWARM%GLOBAL_OPT input section
      43              : !> \param swarm_section ...
      44              : !> \author Ole Schuett
      45              : ! **************************************************************************************************
      46         9284 :    SUBROUTINE glbopt_declare_input(swarm_section)
      47              :       TYPE(section_type), POINTER                        :: swarm_section
      48              : 
      49              :       TYPE(keyword_type), POINTER                        :: keyword
      50              :       TYPE(section_type), POINTER                        :: glbopt_section, printkey
      51              : 
      52         9284 :       NULLIFY (glbopt_section, keyword, printkey)
      53              : 
      54              :       CALL section_create(glbopt_section, __LOCATION__, name="GLOBAL_OPT", &
      55              :                           description="Section to control global geometry optimizations.", &
      56         9284 :                           repeats=.FALSE.)
      57              : 
      58              :       CALL keyword_create(keyword, __LOCATION__, name="METHOD", &
      59              :                           description="Methods to use for optimization.", &
      60              :                           default_i_val=glbopt_do_minhop, &
      61              :                           enum_c_vals=s2a("MINIMA_HOPPING", "MINIMA_CRAWLING"), &
      62              :                           enum_desc=s2a("Runs Minima-Hopping algorithm.", &
      63              :                                         "Runs Minima-Crawling algorithm."), &
      64         9284 :                           enum_i_vals=[glbopt_do_minhop, glbopt_do_mincrawl])
      65         9284 :       CALL section_add_keyword(glbopt_section, keyword)
      66         9284 :       CALL keyword_release(keyword)
      67              : 
      68              :       CALL keyword_create(keyword, __LOCATION__, name="E_TARGET", &
      69              :                           description="Target Energy, the optimization will quit once a lower potential energy is reached.", &
      70         9284 :                           default_r_val=-1*HUGE(1.0_dp), type_of_var=real_t, unit_str="hartree")
      71         9284 :       CALL section_add_keyword(glbopt_section, keyword)
      72         9284 :       CALL keyword_release(keyword)
      73              : 
      74              :       CALL keyword_create(keyword, __LOCATION__, name="MD_BUMPS_MAX", &
      75              :                           description="Number of bumps in potential energy after which MD runs ends.", &
      76         9284 :                           type_of_var=integer_t, default_i_val=3)
      77         9284 :       CALL section_add_keyword(glbopt_section, keyword)
      78         9284 :       CALL keyword_release(keyword)
      79              : 
      80              :       CALL keyword_create(keyword, __LOCATION__, name="BUMP_STEPS_UPWARDS", &
      81              :                           description="Number of MD steps with potential energy increases required for a bump.", &
      82         9284 :                           type_of_var=integer_t, default_i_val=2)
      83         9284 :       CALL section_add_keyword(glbopt_section, keyword)
      84         9284 :       CALL keyword_release(keyword)
      85              : 
      86              :       CALL keyword_create(keyword, __LOCATION__, name="BUMP_STEPS_DOWNWARDS", &
      87              :                           description="Number of MD steps with potential energy decreases required for a bump.", &
      88         9284 :                           type_of_var=integer_t, default_i_val=2)
      89         9284 :       CALL section_add_keyword(glbopt_section, keyword)
      90         9284 :       CALL keyword_release(keyword)
      91              : 
      92              :       CALL keyword_create(keyword, __LOCATION__, name="FRAGMENTATION_THRESHOLD", &
      93              :                           description="Threshold for atom distance used for detecting fragmentation of clusters.", &
      94         9284 :                           default_r_val=2.0_dp, unit_str="angstrom", type_of_var=real_t)
      95         9284 :       CALL section_add_keyword(glbopt_section, keyword)
      96         9284 :       CALL keyword_release(keyword)
      97              : 
      98              :       !CALL keyword_create(keyword, __LOCATION__, name="MD_ADAPTIVE_TIMESTEP",&
      99              :       !     description="Make MD timesteps longer for lower temperatures.", &
     100              :       !     default_r_val=0.0_dp, type_of_var=real_t)
     101              :       !CALL section_add_keyword(glbopt_section, keyword)
     102              :       !CALL keyword_release(keyword)
     103              : 
     104              :       CALL cp_print_key_section_create( &
     105              :          printkey, __LOCATION__, "PROGRESS_TRAJECTORY", &
     106              :          description="Printkey to control the writting of the progress trajectory. "// &
     107              :          "This trajectory contains the minima, which are lower in energy than the by then lowerest.", &
     108              :          print_level=low_print_level, common_iter_levels=1, &
     109         9284 :          filename="", unit_str="angstrom")
     110         9284 :       CALL section_add_subsection(glbopt_section, printkey)
     111         9284 :       CALL section_release(printkey)
     112              : 
     113         9284 :       CALL history_declare_input(glbopt_section)
     114         9284 :       CALL minhop_declare_input(glbopt_section)
     115         9284 :       CALL mincrawl_declare_input(glbopt_section)
     116              : 
     117         9284 :       CALL section_add_subsection(swarm_section, glbopt_section)
     118         9284 :       CALL section_release(glbopt_section)
     119         9284 :    END SUBROUTINE glbopt_declare_input
     120              : 
     121              : ! **************************************************************************************************
     122              : !> \brief Declares the SWARM%GLOBAL_OPT%HISTORY input section
     123              : !> \param glbopt_section ...
     124              : !> \author Ole Schuett
     125              : ! **************************************************************************************************
     126         9284 :    SUBROUTINE history_declare_input(glbopt_section)
     127              :       TYPE(section_type), POINTER                        :: glbopt_section
     128              : 
     129              :       TYPE(keyword_type), POINTER                        :: keyword
     130              :       TYPE(section_type), POINTER                        :: history_section
     131              : 
     132         9284 :       NULLIFY (history_section, keyword)
     133              : 
     134              :       CALL section_create(history_section, __LOCATION__, name="HISTORY", &
     135              :                           description="Section controlling the history of visited minima and "// &
     136              :                           "how minima are recognized at a later point.", &
     137         9284 :                           repeats=.FALSE.)
     138              : 
     139              :       CALL keyword_create(keyword, __LOCATION__, name="ENERGY_PRECISION", &
     140              :                           description="If the difference of two energies is below this threshold "// &
     141              :                           "they are considert equal.", &
     142         9284 :                           default_r_val=1.0e-5_dp, type_of_var=real_t)
     143         9284 :       CALL section_add_keyword(history_section, keyword)
     144         9284 :       CALL keyword_release(keyword)
     145              : 
     146              :       CALL keyword_create(keyword, __LOCATION__, name="FINGERPRINT_PRECISION", &
     147              :                           description="If the euclidean distance of two fingerprints is below "// &
     148              :                           "this threshold, they are considert equal.", &
     149         9284 :                           default_r_val=1.0e-2_dp, type_of_var=real_t)
     150         9284 :       CALL section_add_keyword(history_section, keyword)
     151         9284 :       CALL keyword_release(keyword)
     152              : 
     153         9284 :       CALL section_add_subsection(glbopt_section, history_section)
     154         9284 :       CALL section_release(history_section)
     155         9284 :    END SUBROUTINE history_declare_input
     156              : 
     157              : ! **************************************************************************************************
     158              : !> \brief Declares the SWARM%GLOBAL_OPT%MINIMA_HOPPING input section
     159              : !> \param glbopt_section ...
     160              : !> \author Ole Schuett
     161              : ! **************************************************************************************************
     162         9284 :    SUBROUTINE minhop_declare_input(glbopt_section)
     163              :       TYPE(section_type), POINTER                        :: glbopt_section
     164              : 
     165              :       TYPE(keyword_type), POINTER                        :: keyword
     166              :       TYPE(section_type), POINTER                        :: minhop_section
     167              : 
     168         9284 :       NULLIFY (minhop_section, keyword)
     169              : 
     170              :       CALL section_create(minhop_section, __LOCATION__, name="MINIMA_HOPPING", &
     171              :                           description="Section controlling the Minima Hopping method.", &
     172              :                           citations=[Goedecker2004], &
     173        18568 :                           repeats=.FALSE.)
     174              : 
     175              :       CALL keyword_create(keyword, __LOCATION__, name="BETA_1", &
     176              :                           description="Factor used to increase temperature when escape failed, "// &
     177              :                           "should be larger than 1.", &
     178         9284 :                           default_r_val=1.1_dp, type_of_var=real_t)
     179         9284 :       CALL section_add_keyword(minhop_section, keyword)
     180         9284 :       CALL keyword_release(keyword)
     181              : 
     182              :       CALL keyword_create(keyword, __LOCATION__, name="BETA_2", &
     183              :                           description="Factor used to increase temperature when escape found "// &
     184              :                           "known minima, should be larger than 1.", &
     185         9284 :                           default_r_val=1.1_dp, type_of_var=real_t)
     186         9284 :       CALL section_add_keyword(minhop_section, keyword)
     187         9284 :       CALL keyword_release(keyword)
     188              : 
     189              :       CALL keyword_create(keyword, __LOCATION__, name="BETA_3", &
     190              :                           description="Factor used to decrease temperature when escape succeeded, "// &
     191              :                           "should be smaller than 1.", &
     192         9284 :                           default_r_val=1.0/1.1_dp, type_of_var=real_t)
     193         9284 :       CALL section_add_keyword(minhop_section, keyword)
     194         9284 :       CALL keyword_release(keyword)
     195              : 
     196              :       CALL keyword_create(keyword, __LOCATION__, name="ALPHA_1", &
     197              :                           description="Factor used to decrease acceptance energy, when minima was accepted, "// &
     198              :                           "should be smaller than 1.", &
     199         9284 :                           default_r_val=0.98_dp, type_of_var=real_t)
     200         9284 :       CALL section_add_keyword(minhop_section, keyword)
     201         9284 :       CALL keyword_release(keyword)
     202              : 
     203              :       CALL keyword_create(keyword, __LOCATION__, name="ALPHA_2", &
     204              :                           description="Factor used to increase acceptance energy, when minima was rejected, "// &
     205              :                           "should be larger than 1.", &
     206         9284 :                           default_r_val=1.0/0.98_dp, type_of_var=real_t)
     207         9284 :       CALL section_add_keyword(minhop_section, keyword)
     208         9284 :       CALL keyword_release(keyword)
     209              : 
     210              :       CALL keyword_create(keyword, __LOCATION__, name="E_ACCEPT_INIT", &
     211              :                           description="Initial value of acceptance energy", &
     212         9284 :                           default_r_val=0.005_dp, type_of_var=real_t, unit_str="hartree")
     213         9284 :       CALL section_add_keyword(minhop_section, keyword)
     214         9284 :       CALL keyword_release(keyword)
     215              : 
     216              :       CALL keyword_create(keyword, __LOCATION__, name="TEMPERATURE_INIT", &
     217              :                           description="Initially temperature in Kelvin", &
     218         9284 :                           default_r_val=100.0_dp, type_of_var=real_t)
     219         9284 :       CALL section_add_keyword(minhop_section, keyword)
     220         9284 :       CALL keyword_release(keyword)
     221              : 
     222              :       CALL keyword_create(keyword, __LOCATION__, name="SHARE_HISTORY", &
     223              :                           description="If set all worker will use a single share history of visited minima.", &
     224         9284 :                           default_l_val=.FALSE., lone_keyword_l_val=.TRUE.)
     225         9284 :       CALL section_add_keyword(minhop_section, keyword)
     226         9284 :       CALL keyword_release(keyword)
     227              : 
     228         9284 :       CALL section_add_subsection(glbopt_section, minhop_section)
     229         9284 :       CALL section_release(minhop_section)
     230         9284 :    END SUBROUTINE minhop_declare_input
     231              : 
     232              : ! **************************************************************************************************
     233              : !> \brief Declares the SWARM%GLOBAL_OPT%MINIMA_CRAWLING input section
     234              : !> \param glbopt_section ...
     235              : !> \author Ole Schuett
     236              : ! **************************************************************************************************
     237         9284 :    SUBROUTINE mincrawl_declare_input(glbopt_section)
     238              :       TYPE(section_type), POINTER                        :: glbopt_section
     239              : 
     240              :       TYPE(keyword_type), POINTER                        :: keyword
     241              :       TYPE(section_type), POINTER                        :: mincrawl_section, printkey
     242              : 
     243         9284 :       NULLIFY (mincrawl_section, keyword, printkey)
     244              : 
     245              :       CALL section_create(mincrawl_section, __LOCATION__, name="MINIMA_CRAWLING", &
     246              :                           description="Section controls Minima Crawling run.", &
     247         9284 :                           repeats=.FALSE.)
     248              : 
     249              :       CALL keyword_create(keyword, __LOCATION__, name="TEMPSTEP_BASE", &
     250              :                           description="Base used to calculate temperature steps base**n", &
     251         9284 :                           default_r_val=1.1_dp, type_of_var=real_t)
     252         9284 :       CALL section_add_keyword(mincrawl_section, keyword)
     253         9284 :       CALL keyword_release(keyword)
     254              : 
     255              :       CALL keyword_create(keyword, __LOCATION__, name="TEMPSTEP_MAX", &
     256              :                           description="Maximum number of temperature steps.", &
     257         9284 :                           default_i_val=100, type_of_var=integer_t)
     258         9284 :       CALL section_add_keyword(mincrawl_section, keyword)
     259         9284 :       CALL keyword_release(keyword)
     260              : 
     261              :       CALL keyword_create(keyword, __LOCATION__, name="TEMPDIST_UPDATE_WIDTH", &
     262              :                           description="Width of gaussian used to update temperature distribution.", &
     263         9284 :                           default_r_val=2.0_dp, type_of_var=real_t)
     264         9284 :       CALL section_add_keyword(mincrawl_section, keyword)
     265         9284 :       CALL keyword_release(keyword)
     266              : 
     267              :       CALL keyword_create(keyword, __LOCATION__, name="TEMPDIST_UPDATE_HEIGHT", &
     268              :                           description="Height of gaussian used to update temperature distribution.", &
     269         9284 :                           default_r_val=0.1_dp, type_of_var=real_t)
     270         9284 :       CALL section_add_keyword(mincrawl_section, keyword)
     271         9284 :       CALL keyword_release(keyword)
     272              : 
     273              :       CALL keyword_create(keyword, __LOCATION__, name="TEMPERATURE_INIT", &
     274              :                           description="Initial temperature in Kelvin", &
     275         9284 :                           default_r_val=100.0_dp, type_of_var=real_t)
     276         9284 :       CALL section_add_keyword(mincrawl_section, keyword)
     277         9284 :       CALL keyword_release(keyword)
     278              : 
     279              :       CALL keyword_create(keyword, __LOCATION__, name="TEMPDIST_INIT_WIDTH", &
     280              :                           description="Initial width of temperature distribution.", &
     281         9284 :                           default_r_val=5.0_dp, type_of_var=real_t)
     282         9284 :       CALL section_add_keyword(mincrawl_section, keyword)
     283         9284 :       CALL keyword_release(keyword)
     284              : 
     285              :       CALL keyword_create(keyword, __LOCATION__, name="WORKER_PER_MINIMA", &
     286              :                           description="Maximum number of active workers per Minima.", &
     287         9284 :                           default_i_val=3, type_of_var=integer_t)
     288         9284 :       CALL section_add_keyword(mincrawl_section, keyword)
     289         9284 :       CALL keyword_release(keyword)
     290              : 
     291              :       CALL keyword_create(keyword, __LOCATION__, name="ESCAPE_HISTORY_LENGTH", &
     292              :                           description="Number of escapes averaged for scoring of minima.", &
     293         9284 :                           default_i_val=10, type_of_var=integer_t)
     294         9284 :       CALL section_add_keyword(mincrawl_section, keyword)
     295         9284 :       CALL keyword_release(keyword)
     296              : 
     297              :       CALL cp_print_key_section_create(printkey, __LOCATION__, "MINIMA_TRAJECTORY", &
     298              :                                        description="Printkey to control the writting of the minima trajectory. "// &
     299              :                                        "This trajectory contains all encountered local minima.", &
     300              :                                        print_level=low_print_level, common_iter_levels=1, &
     301         9284 :                                        filename="", unit_str="angstrom")
     302         9284 :       CALL section_add_subsection(mincrawl_section, printkey)
     303         9284 :       CALL section_release(printkey)
     304              : 
     305         9284 :       CALL section_add_subsection(glbopt_section, mincrawl_section)
     306         9284 :       CALL section_release(mincrawl_section)
     307         9284 :    END SUBROUTINE mincrawl_declare_input
     308              : 
     309              : END MODULE glbopt_input
     310              : 
        

Generated by: LCOV version 2.0-1