LCOV - code coverage report
Current view: top level - src - input_cp2k_force_eval.F (source / functions) Hit Total Coverage
Test: CP2K Regtests (git:b8e0b09) Lines: 130 130 100.0 %
Date: 2024-08-31 06:31:37 Functions: 4 4 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 builds the input structure for the FORCE_EVAL section of cp2k
      10             : !> \par History
      11             : !>      06.2004 created [fawzi]
      12             : !> \author fawzi
      13             : ! **************************************************************************************************
      14             : MODULE input_cp2k_force_eval
      15             :    USE cp_output_handling,              ONLY: add_last_numeric,&
      16             :                                               cp_print_key_section_create,&
      17             :                                               debug_print_level,&
      18             :                                               high_print_level,&
      19             :                                               low_print_level,&
      20             :                                               medium_print_level
      21             :    USE cp_units,                        ONLY: cp_unit_to_cp2k
      22             :    USE input_constants,                 ONLY: &
      23             :         do_eip, do_embed, do_fist, do_ipi, do_mixed, do_nnp, do_qmmm, do_qs, do_sirius, &
      24             :         do_stress_analytical, do_stress_diagonal_anal, do_stress_diagonal_numer, do_stress_none, &
      25             :         do_stress_numerical, numerical
      26             :    USE input_cp2k_dft,                  ONLY: create_bsse_section,&
      27             :                                               create_dft_section
      28             :    USE input_cp2k_eip,                  ONLY: create_eip_section
      29             :    USE input_cp2k_embed,                ONLY: create_embed_section
      30             :    USE input_cp2k_mixed,                ONLY: create_mix_section
      31             :    USE input_cp2k_mm,                   ONLY: create_mm_section
      32             :    USE input_cp2k_nnp,                  ONLY: create_nnp_section
      33             :    USE input_cp2k_properties_dft,       ONLY: create_properties_section
      34             :    USE input_cp2k_pwdft,                ONLY: create_pwdft_section
      35             :    USE input_cp2k_qmmm,                 ONLY: create_qmmm_section
      36             :    USE input_cp2k_subsys,               ONLY: create_subsys_section
      37             :    USE input_keyword_types,             ONLY: keyword_create,&
      38             :                                               keyword_release,&
      39             :                                               keyword_type
      40             :    USE input_section_types,             ONLY: section_add_keyword,&
      41             :                                               section_add_subsection,&
      42             :                                               section_create,&
      43             :                                               section_release,&
      44             :                                               section_type
      45             :    USE input_val_types,                 ONLY: char_t,&
      46             :                                               integer_t,&
      47             :                                               lchar_t,&
      48             :                                               real_t
      49             :    USE kinds,                           ONLY: dp
      50             :    USE string_utilities,                ONLY: s2a
      51             : #include "./base/base_uses.f90"
      52             : 
      53             :    IMPLICIT NONE
      54             :    PRIVATE
      55             : 
      56             :    LOGICAL, PRIVATE, PARAMETER :: debug_this_module = .TRUE.
      57             :    CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'input_cp2k_force_eval'
      58             : 
      59             :    PUBLIC :: create_force_eval_section
      60             : 
      61             : CONTAINS
      62             : 
      63             : ! **************************************************************************************************
      64             : !> \brief creates the force_eval section
      65             : !> \param section the section to be created
      66             : !> \author fawzi
      67             : ! **************************************************************************************************
      68        8428 :    SUBROUTINE create_force_eval_section(section)
      69             :       TYPE(section_type), POINTER                        :: section
      70             : 
      71             :       TYPE(keyword_type), POINTER                        :: keyword
      72             :       TYPE(section_type), POINTER                        :: subsection
      73             : 
      74        8428 :       CPASSERT(.NOT. ASSOCIATED(section))
      75             :       CALL section_create(section, __LOCATION__, name="force_eval", &
      76             :                           description="parameters needed to calculate energy and forces and"// &
      77             :                           " describe the system you want to analyze.", &
      78        8428 :                           n_keywords=1, n_subsections=10, repeats=.TRUE.)
      79             : 
      80        8428 :       NULLIFY (subsection)
      81        8428 :       NULLIFY (keyword)
      82             :       CALL keyword_create(keyword, __LOCATION__, name="METHOD", &
      83             :                           description="Which method should be used to compute forces", &
      84             :                           usage="METHOD <STRING>", &
      85             :                           enum_c_vals=s2a("QS", &
      86             :                                           "SIRIUS", &
      87             :                                           "FIST", &
      88             :                                           "QMMM", &
      89             :                                           "EIP", &
      90             :                                           "QUICKSTEP", &
      91             :                                           "NNP", &
      92             :                                           "MIXED", &
      93             :                                           "EMBED", &
      94             :                                           "IPI"), &
      95             :                           enum_desc=s2a("Alias for QUICKSTEP", &
      96             :                                         "PW DFT using the SIRIUS library", &
      97             :                                         "Molecular Mechanics", &
      98             :                                         "Hybrid quantum classical", &
      99             :                                         "Empirical Interatomic Potential", &
     100             :                                         "Electronic structure methods (DFT, ...)", &
     101             :                                         "Neural Network Potentials", &
     102             :                                         "Use a combination of two of the above", &
     103             :                                         "Perform an embedded calculation", &
     104             :                                         "Recieve forces from i–PI client"), &
     105             :                           enum_i_vals=(/do_qs, do_sirius, do_fist, do_qmmm, do_eip, do_qs, do_nnp, do_mixed, do_embed, do_ipi/), &
     106        8428 :                           default_i_val=do_qs)
     107        8428 :       CALL section_add_keyword(section, keyword)
     108        8428 :       CALL keyword_release(keyword)
     109             : 
     110             :       CALL keyword_create(keyword, __LOCATION__, name="STRESS_TENSOR", &
     111             :                           description="Controls the calculation of the stress tensor. The combinations defined below"// &
     112             :                           " are not implemented for all methods.", &
     113             :                           usage="stress_tensor (NONE|ANALYTICAL|NUMERICAL|DIAGONAL_ANA|DIAGONAL_NUM)", &
     114             :                           default_i_val=do_stress_none, &
     115             :                           enum_c_vals=s2a("NONE", "ANALYTICAL", "NUMERICAL", "DIAGONAL_ANALYTICAL", "DIAGONAL_NUMERICAL"), &
     116             :                           enum_i_vals=(/do_stress_none, do_stress_analytical, do_stress_numerical, &
     117             :                                         do_stress_diagonal_anal, do_stress_diagonal_numer/), &
     118             :                           enum_desc=s2a("Do not compute stress tensor", &
     119             :                                         "Compute the stress tensor analytically (if available).", &
     120             :                                         "Compute the stress tensor numerically.", &
     121             :                                         "Compute the diagonal part only of the stress tensor analytically (if available).", &
     122        8428 :                                         "Compute the diagonal part only of the stress tensor numerically"))
     123             : 
     124        8428 :       CALL section_add_keyword(section, keyword)
     125        8428 :       CALL keyword_release(keyword)
     126             : 
     127        8428 :       CALL create_ext_pot_section(subsection)
     128        8428 :       CALL section_add_subsection(section, subsection)
     129        8428 :       CALL section_release(subsection)
     130             : 
     131        8428 :       CALL create_rescale_force_section(subsection)
     132        8428 :       CALL section_add_subsection(section, subsection)
     133        8428 :       CALL section_release(subsection)
     134             : 
     135        8428 :       CALL create_mix_section(subsection)
     136        8428 :       CALL section_add_subsection(section, subsection)
     137        8428 :       CALL section_release(subsection)
     138             : 
     139        8428 :       CALL create_embed_section(subsection)
     140        8428 :       CALL section_add_subsection(section, subsection)
     141        8428 :       CALL section_release(subsection)
     142             : 
     143        8428 :       CALL create_dft_section(subsection)
     144        8428 :       CALL section_add_subsection(section, subsection)
     145        8428 :       CALL section_release(subsection)
     146             : 
     147        8428 :       CALL create_pwdft_section(subsection)
     148        8428 :       CALL section_add_subsection(section, subsection)
     149        8428 :       CALL section_release(subsection)
     150             : 
     151        8428 :       CALL create_mm_section(subsection)
     152        8428 :       CALL section_add_subsection(section, subsection)
     153        8428 :       CALL section_release(subsection)
     154             : 
     155        8428 :       CALL create_nnp_section(subsection)
     156        8428 :       CALL section_add_subsection(section, subsection)
     157        8428 :       CALL section_release(subsection)
     158             : 
     159        8428 :       CALL create_qmmm_section(subsection)
     160        8428 :       CALL section_add_subsection(section, subsection)
     161        8428 :       CALL section_release(subsection)
     162             : 
     163        8428 :       CALL create_eip_section(subsection)
     164        8428 :       CALL section_add_subsection(section, subsection)
     165        8428 :       CALL section_release(subsection)
     166             : 
     167        8428 :       CALL create_bsse_section(subsection)
     168        8428 :       CALL section_add_subsection(section, subsection)
     169        8428 :       CALL section_release(subsection)
     170             : 
     171        8428 :       CALL create_subsys_section(subsection)
     172        8428 :       CALL section_add_subsection(section, subsection)
     173        8428 :       CALL section_release(subsection)
     174             : 
     175        8428 :       CALL create_properties_section(subsection)
     176        8428 :       CALL section_add_subsection(section, subsection)
     177        8428 :       CALL section_release(subsection)
     178             : 
     179        8428 :       CALL create_f_env_print_section(subsection)
     180        8428 :       CALL section_add_subsection(section, subsection)
     181        8428 :       CALL section_release(subsection)
     182             : 
     183        8428 :    END SUBROUTINE create_force_eval_section
     184             : 
     185             : ! **************************************************************************************************
     186             : !> \brief Creates the section for applying an external potential
     187             : !> \param section ...
     188             : !> \date 03.2008
     189             : !> \author teo
     190             : ! **************************************************************************************************
     191        8428 :    SUBROUTINE create_ext_pot_section(section)
     192             :       TYPE(section_type), POINTER                        :: section
     193             : 
     194             :       TYPE(keyword_type), POINTER                        :: keyword
     195             : 
     196        8428 :       CPASSERT(.NOT. ASSOCIATED(section))
     197             :       CALL section_create(section, __LOCATION__, name="EXTERNAL_POTENTIAL", &
     198             :                           description="Section controlling the presence of an external potential dependent "// &
     199             :                           "on the atomic positions (X,Y,Z)", &
     200        8428 :                           n_keywords=7, n_subsections=0, repeats=.TRUE.)
     201        8428 :       NULLIFY (keyword)
     202             : 
     203             :       CALL keyword_create(keyword, __LOCATION__, name="ATOMS_LIST", &
     204             :                           description="Specifies the atoms on which the external potential will act", &
     205             :                           usage="ATOMS_LIST {INT} {INT} ..", repeats=.TRUE., &
     206        8428 :                           n_var=-1, type_of_var=integer_t)
     207        8428 :       CALL section_add_keyword(section, keyword)
     208        8428 :       CALL keyword_release(keyword)
     209             : 
     210             :       CALL keyword_create(keyword, __LOCATION__, name="FUNCTION", &
     211             :                           description="Specifies the functional form in mathematical notation. Variables must be the atomic "// &
     212             :                           "coordinates (X,Y,Z).", usage="FUNCTION  X^2+Y^2+Z^2+LOG(ABS(X+Y))", &
     213        8428 :                           type_of_var=lchar_t, n_var=1)
     214        8428 :       CALL section_add_keyword(section, keyword)
     215        8428 :       CALL keyword_release(keyword)
     216             : 
     217             :       CALL keyword_create(keyword, __LOCATION__, name="PARAMETERS", &
     218             :                           description="Defines the parameters of the functional form", &
     219             :                           usage="PARAMETERS a b D", type_of_var=char_t, &
     220        8428 :                           n_var=-1, repeats=.TRUE.)
     221        8428 :       CALL section_add_keyword(section, keyword)
     222        8428 :       CALL keyword_release(keyword)
     223             : 
     224             :       CALL keyword_create(keyword, __LOCATION__, name="VALUES", &
     225             :                           description="Defines the values of  parameter of the functional form", &
     226             :                           usage="VALUES ", type_of_var=real_t, &
     227        8428 :                           n_var=-1, repeats=.TRUE., unit_str="internal_cp2k")
     228        8428 :       CALL section_add_keyword(section, keyword)
     229        8428 :       CALL keyword_release(keyword)
     230             : 
     231             :       CALL keyword_create(keyword, __LOCATION__, name="UNITS", &
     232             :                           description="Optionally, allows to define valid CP2K unit strings for each parameter value. "// &
     233             :                           "It is assumed that the corresponding parameter value is specified in this unit.", &
     234             :                           usage="UNITS angstrom eV*angstrom^-1 angstrom^1 K", type_of_var=char_t, &
     235        8428 :                           n_var=-1, repeats=.TRUE.)
     236        8428 :       CALL section_add_keyword(section, keyword)
     237        8428 :       CALL keyword_release(keyword)
     238             : 
     239             :       CALL keyword_create(keyword, __LOCATION__, name="DX", &
     240             :                           description="Parameter used for computing the derivative with the Ridders' method.", &
     241        8428 :                           usage="DX <REAL>", default_r_val=0.1_dp, unit_str="bohr")
     242        8428 :       CALL section_add_keyword(section, keyword)
     243        8428 :       CALL keyword_release(keyword)
     244             : 
     245             :       CALL keyword_create(keyword, __LOCATION__, name="ERROR_LIMIT", &
     246             :                           description="Checks that the error in computing the derivative is not larger than "// &
     247             :                           "the value set; in case error is larger a warning message is printed.", &
     248        8428 :                           usage="ERROR_LIMIT <REAL>", default_r_val=1.0E-12_dp)
     249        8428 :       CALL section_add_keyword(section, keyword)
     250        8428 :       CALL keyword_release(keyword)
     251             : 
     252        8428 :    END SUBROUTINE create_ext_pot_section
     253             : 
     254             : ! **************************************************************************************************
     255             : !> \brief Creates the section controlling the rescaling of forces
     256             : !> \param section the section to create
     257             : !> \author teo
     258             : ! **************************************************************************************************
     259        8428 :    SUBROUTINE create_rescale_force_section(section)
     260             :       TYPE(section_type), POINTER                        :: section
     261             : 
     262             :       TYPE(keyword_type), POINTER                        :: keyword
     263             : 
     264        8428 :       CPASSERT(.NOT. ASSOCIATED(section))
     265             :       CALL section_create(section, __LOCATION__, name="RESCALE_FORCES", &
     266             :                           description="Section controlling the rescaling of forces. Useful when"// &
     267             :                           " starting from quite bad geometries with unphysically large forces.", &
     268        8428 :                           n_keywords=1, n_subsections=0, repeats=.FALSE.)
     269        8428 :       NULLIFY (keyword)
     270             : 
     271             :       CALL keyword_create(keyword, __LOCATION__, name="MAX_FORCE", &
     272             :                           description="Specify the Maximum Values of the force. If the force"// &
     273             :                           " of one atom exceed this value it's rescaled to the MAX_FORCE"// &
     274             :                           " value.", &
     275             :                           default_r_val=cp_unit_to_cp2k(value=50.0_dp, &
     276             :                                                         unit_str="kcalmol*angstrom^-1"), &
     277        8428 :                           unit_str="hartree*bohr^-1")
     278        8428 :       CALL section_add_keyword(section, keyword)
     279        8428 :       CALL keyword_release(keyword)
     280             : 
     281        8428 :    END SUBROUTINE create_rescale_force_section
     282             : 
     283             : ! **************************************************************************************************
     284             : !> \brief ...
     285             : !> \param section ...
     286             : !> \author fawzi
     287             : ! **************************************************************************************************
     288        8428 :    SUBROUTINE create_f_env_print_section(section)
     289             :       TYPE(section_type), POINTER                        :: section
     290             : 
     291             :       TYPE(keyword_type), POINTER                        :: keyword
     292             :       TYPE(section_type), POINTER                        :: print_key
     293             : 
     294        8428 :       NULLIFY (keyword)
     295        8428 :       NULLIFY (print_key)
     296             : 
     297        8428 :       CPASSERT(.NOT. ASSOCIATED(section))
     298             : 
     299             :       CALL section_create(section, __LOCATION__, name="PRINT", &
     300             :                           description="Properties that you want to output and that are common to all methods", &
     301        8428 :                           n_keywords=0, n_subsections=5, repeats=.FALSE.)
     302             : 
     303             :       CALL cp_print_key_section_create(print_key, __LOCATION__, "PROGRAM_RUN_INFO", &
     304             :                                        description="Controls the printing of basic information generated by force_eval", &
     305        8428 :                                        print_level=low_print_level, add_last=add_last_numeric, filename="__STD_OUT__")
     306        8428 :       CALL section_add_subsection(section, print_key)
     307        8428 :       CALL section_release(print_key)
     308             : 
     309             :       CALL cp_print_key_section_create(print_key, __LOCATION__, "FORCES", &
     310             :                                        description="Controls the printing of the forces after each force evaluation", &
     311        8428 :                                        print_level=high_print_level, filename="__STD_OUT__")
     312             :       CALL keyword_create(keyword, __LOCATION__, &
     313             :                           name="NDIGITS", &
     314             :                           description="Specifies the number of digits used "// &
     315             :                           "for the printing of the forces", &
     316             :                           usage="NDIGITS 6", &
     317             :                           default_i_val=8, &
     318        8428 :                           repeats=.FALSE.)
     319        8428 :       CALL section_add_keyword(print_key, keyword)
     320        8428 :       CALL keyword_release(keyword)
     321        8428 :       CALL section_add_subsection(section, print_key)
     322        8428 :       CALL section_release(print_key)
     323             : 
     324             :       CALL cp_print_key_section_create( &
     325             :          print_key, __LOCATION__, "GRID_INFORMATION", &
     326             :          description="Controls the printing of information regarding the PW and RS grid structures.", &
     327        8428 :          print_level=medium_print_level, filename="__STD_OUT__")
     328        8428 :       CALL section_add_subsection(section, print_key)
     329        8428 :       CALL section_release(print_key)
     330             : 
     331             :       CALL cp_print_key_section_create(print_key, __LOCATION__, "TOTAL_NUMBERS", &
     332             :                                        description="Controls the printing of the total number of atoms, kinds,...", &
     333        8428 :                                        print_level=low_print_level, filename="__STD_OUT__")
     334        8428 :       CALL section_add_subsection(section, print_key)
     335        8428 :       CALL section_release(print_key)
     336             : 
     337             :       CALL cp_print_key_section_create(print_key, __LOCATION__, "DISTRIBUTION", &
     338             :                                        description="Controls the printing of the distribution of molecules, atoms, ...", &
     339        8428 :                                        print_level=high_print_level, filename="__STD_OUT__")
     340        8428 :       CALL section_add_subsection(section, print_key)
     341        8428 :       CALL section_release(print_key)
     342             : 
     343             :       CALL cp_print_key_section_create(print_key, __LOCATION__, "DISTRIBUTION2D", &
     344             :                                        description="Controls the printing of the distribution of matrix blocks, ...", &
     345        8428 :                                        print_level=high_print_level, filename="__STD_OUT__")
     346        8428 :       CALL section_add_subsection(section, print_key)
     347        8428 :       CALL section_release(print_key)
     348             : 
     349             :       CALL cp_print_key_section_create(print_key, __LOCATION__, "DISTRIBUTION1D", &
     350             :                                        description="Each node prints out its distribution info ...", &
     351        8428 :                                        print_level=high_print_level, filename="__STD_OUT__")
     352        8428 :       CALL section_add_subsection(section, print_key)
     353        8428 :       CALL section_release(print_key)
     354             : 
     355             :       CALL cp_print_key_section_create(print_key, __LOCATION__, "STRESS_TENSOR", &
     356             :                                        description="Controls the printing of the stress tensor", &
     357        8428 :                                        print_level=high_print_level, filename="__STD_OUT__")
     358             :       CALL keyword_create(keyword, __LOCATION__, &
     359             :                           name="COMPONENTS", &
     360             :                           description="Print all GPW/GAPW components contributing to the stress tensor", &
     361             :                           usage="COMPONENTS", &
     362             :                           default_l_val=.FALSE., &
     363        8428 :                           lone_keyword_l_val=.TRUE.)
     364        8428 :       CALL section_add_keyword(print_key, keyword)
     365        8428 :       CALL keyword_release(keyword)
     366        8428 :       CALL section_add_subsection(section, print_key)
     367        8428 :       CALL section_release(print_key)
     368             : 
     369             :       CALL cp_print_key_section_create(print_key, __LOCATION__, "GRRM", &
     370             :                                        description="Controls the printing of the GRRM interface file", &
     371        8428 :                                        print_level=debug_print_level + 1, filename="CP2K_GRRM")
     372        8428 :       CALL section_add_subsection(section, print_key)
     373        8428 :       CALL section_release(print_key)
     374             : 
     375             :       CALL cp_print_key_section_create(print_key, __LOCATION__, "SCINE", &
     376             :                                        description="Controls the printing of the SCINE interface file", &
     377        8428 :                                        print_level=debug_print_level + 1, filename="")
     378        8428 :       CALL section_add_subsection(section, print_key)
     379        8428 :       CALL section_release(print_key)
     380             : 
     381        8428 :    END SUBROUTINE create_f_env_print_section
     382             : 
     383             : END MODULE input_cp2k_force_eval

Generated by: LCOV version 1.15