LCOV - code coverage report
Current view: top level - src - input_cp2k_force_eval.F (source / functions) Coverage Total Hit
Test: CP2K Regtests (git:cccd2f3) Lines: 100.0 % 139 139
Test Date: 2026-05-06 07:07:47 Functions: 100.0 % 4 4

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

Generated by: LCOV version 2.0-1