LCOV - code coverage report
Current view: top level - src - input_cp2k_external.F (source / functions) Coverage Total Hit
Test: CP2K Regtests (git:06f838d) Lines: 100.0 % 74 74
Test Date: 2026-06-05 07:04:50 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 function that build the input sections for external [potential, density VXC]
      10              : !> \par History
      11              : !>      10.2005 moved out of input_cp2k [fawzi]
      12              : !>      10.2020 moved out of input_cp2k_dft [JGH]
      13              : !> \author fawzi
      14              : ! **************************************************************************************************
      15              : MODULE input_cp2k_external
      16              :    USE bibliography,                    ONLY: Tozer1996,&
      17              :                                               Zhao1994
      18              :    USE input_constants,                 ONLY: use_coulomb,&
      19              :                                               use_diff,&
      20              :                                               use_no
      21              :    USE input_keyword_types,             ONLY: keyword_create,&
      22              :                                               keyword_release,&
      23              :                                               keyword_type
      24              :    USE input_section_types,             ONLY: section_add_keyword,&
      25              :                                               section_add_subsection,&
      26              :                                               section_create,&
      27              :                                               section_release,&
      28              :                                               section_type
      29              :    USE input_val_types,                 ONLY: char_t,&
      30              :                                               lchar_t,&
      31              :                                               real_t
      32              :    USE kinds,                           ONLY: dp
      33              :    USE string_utilities,                ONLY: s2a
      34              : #include "./base/base_uses.f90"
      35              : 
      36              :    IMPLICIT NONE
      37              :    PRIVATE
      38              : 
      39              :    CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'input_cp2k_external'
      40              : 
      41              :    PUBLIC :: create_ext_pot_section, create_ext_den_section, create_ext_vxc_section
      42              : 
      43              : CONTAINS
      44              : 
      45              : ! **************************************************************************************************
      46              : !> \brief Creates the section for applying an electrostatic external potential
      47              : !> \param section ...
      48              : !> \date 12.2009
      49              : !> \author teo
      50              : ! **************************************************************************************************
      51        10278 :    SUBROUTINE create_ext_pot_section(section)
      52              :       TYPE(section_type), POINTER                        :: section
      53              : 
      54              :       TYPE(keyword_type), POINTER                        :: keyword
      55              :       TYPE(section_type), POINTER                        :: subsection
      56              : 
      57        10278 :       CPASSERT(.NOT. ASSOCIATED(section))
      58              :       CALL section_create(section, __LOCATION__, name="EXTERNAL_POTENTIAL", &
      59              :                           description="Section controlling the presence of an electrostatic "// &
      60              :                           "external potential dependent on the atomic positions (X,Y,Z). "// &
      61              :                           "As the external potential is currently applied via a grid, "// &
      62              :                           "it only works with DFT based methods (GPW/GAPW) that already use "// &
      63              :                           "a grid based approach to solve the Poisson equation.", &
      64        10278 :                           n_keywords=7, n_subsections=0, repeats=.FALSE.)
      65        10278 :       NULLIFY (keyword, subsection)
      66              : 
      67              :       CALL keyword_create(keyword, __LOCATION__, name="FUNCTION", &
      68              :                           description="Specifies the functional form in mathematical notation. Variables must be the atomic "// &
      69              :                           "coordinates (X,Y,Z) of the grid.", usage="FUNCTION  X^2+Y^2+Z^2+LOG(ABS(X+Y))", &
      70        10278 :                           type_of_var=lchar_t, n_var=1)
      71        10278 :       CALL section_add_keyword(section, keyword)
      72        10278 :       CALL keyword_release(keyword)
      73              : 
      74              :       CALL keyword_create(keyword, __LOCATION__, name="PARAMETERS", &
      75              :                           description="Defines the parameters of the functional form", &
      76              :                           usage="PARAMETERS a b D", type_of_var=char_t, &
      77        10278 :                           n_var=-1, repeats=.TRUE.)
      78        10278 :       CALL section_add_keyword(section, keyword)
      79        10278 :       CALL keyword_release(keyword)
      80              : 
      81              :       CALL keyword_create(keyword, __LOCATION__, name="VALUES", &
      82              :                           description="Defines the values of parameter of the functional form", &
      83              :                           usage="VALUES ", type_of_var=real_t, &
      84        10278 :                           n_var=-1, repeats=.TRUE., unit_str="internal_cp2k")
      85        10278 :       CALL section_add_keyword(section, keyword)
      86        10278 :       CALL keyword_release(keyword)
      87              : 
      88              :       CALL keyword_create(keyword, __LOCATION__, name="UNITS", &
      89              :                           description="Optionally, allows to define valid CP2K unit strings for each parameter value. "// &
      90              :                           "It is assumed that the corresponding parameter value is specified in this unit.", &
      91              :                           usage="UNITS angstrom eV*angstrom^-1 angstrom^1 K", type_of_var=char_t, &
      92        10278 :                           n_var=-1, repeats=.TRUE.)
      93        10278 :       CALL section_add_keyword(section, keyword)
      94        10278 :       CALL keyword_release(keyword)
      95              : 
      96              :       CALL keyword_create(keyword, __LOCATION__, name="STATIC", &
      97              :                           description="Specifies the external potential as STATIC or time dependent. At the moment "// &
      98              :                           "only static potentials are implemented.", &
      99        10278 :                           usage="STATIC T", default_l_val=.TRUE., lone_keyword_l_val=.TRUE.)
     100        10278 :       CALL section_add_keyword(section, keyword)
     101        10278 :       CALL keyword_release(keyword)
     102              : 
     103              :       CALL keyword_create(keyword, __LOCATION__, name="DX", &
     104              :                           description="Parameter used for computing the derivative with the Ridders' method.", &
     105        10278 :                           usage="DX <REAL>", default_r_val=0.1_dp, unit_str="bohr")
     106        10278 :       CALL section_add_keyword(section, keyword)
     107        10278 :       CALL keyword_release(keyword)
     108              : 
     109              :       CALL keyword_create(keyword, __LOCATION__, name="ERROR_LIMIT", &
     110              :                           description="Checks that the error in computing the derivative is not larger than "// &
     111              :                           "the value set; in case error is larger a warning message is printed.", &
     112        10278 :                           usage="ERROR_LIMIT <REAL>", default_r_val=1.0E-12_dp)
     113        10278 :       CALL section_add_keyword(section, keyword)
     114        10278 :       CALL keyword_release(keyword)
     115              : 
     116              :       !keyword for reading the external potential from cube file
     117              :       CALL keyword_create(keyword, __LOCATION__, name="READ_FROM_CUBE", &
     118              :                           description="Switch for reading the external potential from file pot.cube. The values "// &
     119              :                           "of the potential must be on the grid points of the realspace grid. "// &
     120              :                           "Whitespace-separated cube values are accepted. If adjacent values are written "// &
     121              :                           "without whitespace, each value must occupy a 13-character E13.5 field, as in "// &
     122              :                           "CP2K-generated cube files.", &
     123        10278 :                           usage="READ_FROM_CUBE T", default_l_val=.FALSE., lone_keyword_l_val=.TRUE.)
     124        10278 :       CALL section_add_keyword(section, keyword)
     125        10278 :       CALL keyword_release(keyword)
     126              : 
     127              :       !keyword for scaling the external potential that is read from file by a constant factor
     128              :       CALL keyword_create(keyword, __LOCATION__, name="SCALING_FACTOR", &
     129              :                           description="A factor for scaling the the external potential that is read from file. "// &
     130              :                           "The value of the potential at each grid point is multiplied by this factor.", &
     131        10278 :                           usage="SCALING_FACTOR <REAL>", default_r_val=1.0_dp)
     132        10278 :       CALL section_add_keyword(section, keyword)
     133        10278 :       CALL keyword_release(keyword)
     134              : 
     135        10278 :       CALL create_maxwell_section(subsection)
     136        10278 :       CALL section_add_subsection(section, subsection)
     137        10278 :       CALL section_release(subsection)
     138              : 
     139        10278 :    END SUBROUTINE create_ext_pot_section
     140              : 
     141              : ! **************************************************************************************************
     142              : !> \brief Creates the section for applying an electrostatic external potential
     143              : !> \param section ...
     144              : !> \date 12.2009
     145              : !> \author teo
     146              : ! **************************************************************************************************
     147        10278 :    SUBROUTINE create_maxwell_section(section)
     148              :       TYPE(section_type), POINTER                        :: section
     149              : 
     150              :       TYPE(keyword_type), POINTER                        :: keyword
     151              : 
     152        10278 :       CPASSERT(.NOT. ASSOCIATED(section))
     153              :       CALL section_create(section, __LOCATION__, name="MAXWELL", &
     154              :                           description="Section controlling the calculation of an electrostatic "// &
     155              :                           "external potential calculated from Maxwell equations. ", &
     156        10278 :                           n_keywords=1, n_subsections=0, repeats=.FALSE.)
     157        10278 :       NULLIFY (keyword)
     158              : 
     159              :       CALL keyword_create(keyword, __LOCATION__, name="TEST_LOGICAL", &
     160              :                           description="Test for logical value", &
     161        10278 :                           usage="TEST_LOGICAL T", default_l_val=.FALSE., lone_keyword_l_val=.TRUE.)
     162        10278 :       CALL section_add_keyword(section, keyword)
     163        10278 :       CALL keyword_release(keyword)
     164              : 
     165              :       CALL keyword_create(keyword, __LOCATION__, name="TEST_REAL", &
     166              :                           description="TEST for Real", &
     167        10278 :                           usage="TEST_REAL <REAL>", default_r_val=1.0_dp)
     168        10278 :       CALL section_add_keyword(section, keyword)
     169        10278 :       CALL keyword_release(keyword)
     170              : 
     171              :       CALL keyword_create(keyword, __LOCATION__, name="TEST_INTEGER", &
     172              :                           description="TEST for Int", &
     173        10278 :                           usage="TEST_INTEGER <INT>", default_i_val=0)
     174        10278 :       CALL section_add_keyword(section, keyword)
     175        10278 :       CALL keyword_release(keyword)
     176              : 
     177        10278 :    END SUBROUTINE create_maxwell_section
     178              : 
     179              : ! **************************************************************************************************
     180              : !> \brief ZMP Creates the section for reading user supplied external density
     181              : !> \param section ...
     182              : !> \date 03.2011
     183              : !> \author D. Varsano [daniele.varsano@nano.cnr.it]
     184              : ! **************************************************************************************************
     185        10278 :    SUBROUTINE create_ext_den_section(section)
     186              :       TYPE(section_type), POINTER                        :: section
     187              : 
     188              :       TYPE(keyword_type), POINTER                        :: keyword
     189              : 
     190        10278 :       CPASSERT(.NOT. ASSOCIATED(section))
     191              :       CALL section_create(section, __LOCATION__, name="EXTERNAL_DENSITY", &
     192              :                           description="Section for the use of the ZMP technique on external densities.", &
     193              :                           n_keywords=4, n_subsections=0, repeats=.FALSE., &
     194        30834 :                           citations=[Zhao1994, Tozer1996])
     195        10278 :       NULLIFY (keyword)
     196              : 
     197              :       CALL keyword_create(keyword, __LOCATION__, name="FILE_DENSITY", &
     198              :                           description="Specifies the filename containing the target density in *.cube format. "// &
     199              :                           "In the MGRID section it must be imposed NGRID 1, as it works with only "// &
     200              :                           "one grid. The number of points in each direction, and the spacing must "// &
     201              :                           "be previously defined choosing the plane waves cut-off in section MGRID "// &
     202              :                           "keyword CUTOFF, and the cube dimension in section SUBSYS / CELL / keyword ABC", &
     203              :                           usage="FILE_DENSITY <FILENAME>", &
     204        10278 :                           type_of_var=char_t, default_c_val="RHO_O.dat", n_var=-1)
     205        10278 :       CALL section_add_keyword(section, keyword)
     206        10278 :       CALL keyword_release(keyword)
     207              : 
     208              :       CALL keyword_create(keyword, __LOCATION__, name="LAMBDA", &
     209              :                           description="Lagrange multiplier defined in the constraint ZMP method. When starting, use "// &
     210              :                           "small values when starting from scratch (around 5,10). Then gradually increase "// &
     211              :                           "the values depending, restarting from the previous calculation with the smaller "// &
     212              :                           "value. To choose the progressive values of LAMBDA look at the convergence of the "// &
     213              :                           "eigenvalues.", &
     214        10278 :                           usage="LAMBDA <REAL>", default_r_val=10.0_dp)
     215        10278 :       CALL section_add_keyword(section, keyword)
     216        10278 :       CALL keyword_release(keyword)
     217              : 
     218              :       CALL keyword_create(keyword, __LOCATION__, name="ZMP_CONSTRAINT", &
     219              :                           description="Specify which kind of constraint to solve the ZMP equation. The COULOMB default "// &
     220              :                           "option is more stable.", &
     221              :                           usage="ZMP_CONSTRAINT <CHAR>", &
     222              :                           enum_c_vals=s2a("COULOMB", "DIFF", "NONE"), &
     223              :                           enum_i_vals=[use_coulomb, use_diff, use_no], &
     224              :                           enum_desc=s2a("Coulomb constraint, integral of [rho_0(r)-rho(r)]/|r-r'|", &
     225              :                                         "Simple constraint, [rho_0(r)-rho(r)]", &
     226              :                                         "No constrain imposed"), &
     227        10278 :                           default_i_val=use_coulomb)
     228        10278 :       CALL section_add_keyword(section, keyword)
     229        10278 :       CALL keyword_release(keyword)
     230              : 
     231              :       CALL keyword_create(keyword, __LOCATION__, name="FERMI_AMALDI", &
     232              :                           description="Add the Fermi-Amaldi contribution to the Hartree potential. "// &
     233              :                           "It leads to a more stable convergence.", &
     234              :                           usage="FERMI_AMALDI <LOGICAL>", &
     235              :                           repeats=.FALSE., &
     236              :                           n_var=1, &
     237        10278 :                           default_l_val=.TRUE., lone_keyword_l_val=.TRUE.)
     238        10278 :       CALL section_add_keyword(section, keyword)
     239        10278 :       CALL keyword_release(keyword)
     240              : 
     241        10278 :    END SUBROUTINE create_ext_den_section
     242              : 
     243              : ! **************************************************************************************************
     244              : !> \brief ZMP Creates the section for creating the external v_xc
     245              : !> \param section ...
     246              : !> \date 03.2011
     247              : !> \author D. Varsano [daniele.varsano@nano.cnr.it]
     248              : ! **************************************************************************************************
     249        10278 :    SUBROUTINE create_ext_vxc_section(section)
     250              :       TYPE(section_type), POINTER                        :: section
     251              : 
     252              :       TYPE(keyword_type), POINTER                        :: keyword
     253              : 
     254        10278 :       CPASSERT(.NOT. ASSOCIATED(section))
     255              :       CALL section_create(section, __LOCATION__, name="EXTERNAL_VXC", &
     256              :                           description="SCF convergence with external v_xc calculated through previous ZMP "// &
     257              :                           "calculation", &
     258        10278 :                           n_keywords=1, n_subsections=0, repeats=.FALSE.)
     259        10278 :       NULLIFY (keyword)
     260              : 
     261              :       CALL keyword_create(keyword, __LOCATION__, name="FILE_VXC", &
     262              :                           description="The *.cube filename containing the v_xc potential. This works only "// &
     263              :                           "with NGRID 1 imposed in the MGRID section. The number of points in each "// &
     264              :                           "direction, and the spacing must equal to those previously used in the ZMP "// &
     265              :                           "calculation and defined through the plane wave cut-off and the cube dimension "// &
     266              :                           "respectively set in section MGRID / keyword CUTOFF, and in section SUBSYS / "// &
     267              :                           "CELL / keyword ABC", &
     268              :                           usage="FILE_VXC <FILENAME>", &
     269        10278 :                           type_of_var=char_t, default_c_val="VXC_O.dat", n_var=-1)
     270        10278 :       CALL section_add_keyword(section, keyword)
     271        10278 :       CALL keyword_release(keyword)
     272        10278 :    END SUBROUTINE create_ext_vxc_section
     273              : 
     274              : END MODULE input_cp2k_external
        

Generated by: LCOV version 2.0-1