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

Generated by: LCOV version 1.15