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 : !> 10.2026 applied create_function_section to create_ext_pot_section [Zilong He]
14 : !> \author fawzi
15 : ! **************************************************************************************************
16 : MODULE input_cp2k_external
17 : USE bibliography, ONLY: Tozer1996,&
18 : Zhao1994
19 : USE generic_function_input, ONLY: create_function_section
20 : USE input_constants, ONLY: use_coulomb,&
21 : use_diff,&
22 : use_no
23 : USE input_keyword_types, ONLY: keyword_create,&
24 : keyword_release,&
25 : keyword_type
26 : USE input_section_types, ONLY: section_add_keyword,&
27 : section_add_subsection,&
28 : section_create,&
29 : section_release,&
30 : section_type
31 : USE input_val_types, ONLY: char_t
32 : USE kinds, ONLY: dp
33 : USE string_utilities, ONLY: newline,&
34 : s2a
35 : #include "./base/base_uses.f90"
36 :
37 : IMPLICIT NONE
38 : PRIVATE
39 :
40 : CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'input_cp2k_external'
41 :
42 : PUBLIC :: create_ext_pot_section, create_ext_den_section, create_ext_vxc_section
43 :
44 : CONTAINS
45 :
46 : ! **************************************************************************************************
47 : !> \brief Creates the section for applying an electrostatic external potential
48 : !> \param section ...
49 : !> \date 12.2009
50 : !> \par This is for FORCE_EVAL/DFT/EXTERNAL_POTENTIAL and applicable to Quickstep DFT only,
51 : !> corresponding to get_external_potential in qs_external_potential.F.
52 : !> Not to be confused with FORCE_EVAL/EXTERNAL_POTENTIAL, which is created separately
53 : !> in input_cp2k_force_eval.F and applicable to any force method.
54 : !> \author teo
55 : ! **************************************************************************************************
56 1481 : SUBROUTINE create_ext_pot_section(section)
57 : TYPE(section_type), POINTER :: section
58 :
59 : TYPE(keyword_type), POINTER :: keyword
60 : TYPE(section_type), POINTER :: subsection
61 :
62 1481 : CPASSERT(.NOT. ASSOCIATED(section))
63 :
64 : CALL create_function_section(section, "EXTERNAL_POTENTIAL", "FUNCTION", &
65 : description="Section controlling the presence of an electrostatic "// &
66 : "external potential dependent on the atomic positions (X,Y,Z). "// &
67 : "As the external potential is currently applied via a grid, "// &
68 : "it only works with DFT based methods (GPW/GAPW) that already use "// &
69 : "a grid-based approach to solve the Poisson equation. Not to be "// &
70 : "confused with other similar sections:"//newline//newline// &
71 : "* FORCE_EVAL/EXTERNAL_POTENTIAL, which is applicable to general "// &
72 : "force methods and is not grid-based;"//newline// &
73 : "* FORCE_EVAL/DFT/EFIELD, which is for finite, time-dependent "// &
74 : "electric field in DFT;"//newline// &
75 : "* FORCE_EVAL/DFT/PERIODIC_EFIELD, which is for finite periodic "// &
76 : "electric field using the Berry phase approach in DFT.", &
77 5924 : do_deriv=.TRUE., input_variables=["X", "Y", "Z"])
78 1481 : NULLIFY (keyword, subsection)
79 :
80 : CALL keyword_create(keyword, __LOCATION__, name="STATIC", &
81 : description="Specifies the external potential as STATIC or time dependent. At the moment "// &
82 : "only static potentials are implemented.", &
83 1481 : usage="STATIC T", default_l_val=.TRUE., lone_keyword_l_val=.TRUE.)
84 1481 : CALL section_add_keyword(section, keyword)
85 1481 : CALL keyword_release(keyword)
86 :
87 : !keyword for reading the external potential from cube file
88 : CALL keyword_create(keyword, __LOCATION__, name="READ_FROM_CUBE", &
89 : description="Switch for reading the external potential from file pot.cube. The values "// &
90 : "of the potential must be on the grid points of the realspace grid. "// &
91 : "Whitespace-separated cube values are accepted. If adjacent values are written "// &
92 : "without whitespace, each value must occupy a 13-character E13.5 field.", &
93 1481 : usage="READ_FROM_CUBE T", default_l_val=.FALSE., lone_keyword_l_val=.TRUE.)
94 1481 : CALL section_add_keyword(section, keyword)
95 1481 : CALL keyword_release(keyword)
96 :
97 : !keyword for scaling the external potential that is read from file by a constant factor
98 : CALL keyword_create(keyword, __LOCATION__, name="SCALING_FACTOR", &
99 : description="A factor for scaling the the external potential that is read from file. "// &
100 : "The value of the potential at each grid point is multiplied by this factor.", &
101 1481 : usage="SCALING_FACTOR <REAL>", default_r_val=1.0_dp)
102 1481 : CALL section_add_keyword(section, keyword)
103 1481 : CALL keyword_release(keyword)
104 :
105 1481 : CALL create_maxwell_section(subsection)
106 1481 : CALL section_add_subsection(section, subsection)
107 1481 : CALL section_release(subsection)
108 :
109 1481 : END SUBROUTINE create_ext_pot_section
110 :
111 : ! **************************************************************************************************
112 : !> \brief Creates the section for applying an electrostatic external potential
113 : !> \param section ...
114 : !> \date 12.2009
115 : !> \author teo
116 : ! **************************************************************************************************
117 1481 : SUBROUTINE create_maxwell_section(section)
118 : TYPE(section_type), POINTER :: section
119 :
120 : TYPE(keyword_type), POINTER :: keyword
121 :
122 1481 : CPASSERT(.NOT. ASSOCIATED(section))
123 : CALL section_create(section, __LOCATION__, name="MAXWELL", &
124 : description="Section controlling the calculation of an electrostatic "// &
125 : "external potential calculated from Maxwell equations. ", &
126 1481 : n_keywords=1, n_subsections=0, repeats=.FALSE.)
127 1481 : NULLIFY (keyword)
128 :
129 : CALL keyword_create(keyword, __LOCATION__, name="TEST_LOGICAL", &
130 : description="Test for logical value", &
131 1481 : usage="TEST_LOGICAL T", default_l_val=.FALSE., lone_keyword_l_val=.TRUE.)
132 1481 : CALL section_add_keyword(section, keyword)
133 1481 : CALL keyword_release(keyword)
134 :
135 : CALL keyword_create(keyword, __LOCATION__, name="TEST_REAL", &
136 : description="TEST for Real", &
137 1481 : usage="TEST_REAL <REAL>", default_r_val=1.0_dp)
138 1481 : CALL section_add_keyword(section, keyword)
139 1481 : CALL keyword_release(keyword)
140 :
141 : CALL keyword_create(keyword, __LOCATION__, name="TEST_INTEGER", &
142 : description="TEST for Int", &
143 1481 : usage="TEST_INTEGER <INT>", default_i_val=0)
144 1481 : CALL section_add_keyword(section, keyword)
145 1481 : CALL keyword_release(keyword)
146 :
147 1481 : END SUBROUTINE create_maxwell_section
148 :
149 : ! **************************************************************************************************
150 : !> \brief ZMP Creates the section for reading user supplied external density
151 : !> \param section ...
152 : !> \date 03.2011
153 : !> \author D. Varsano [daniele.varsano@nano.cnr.it]
154 : ! **************************************************************************************************
155 1481 : SUBROUTINE create_ext_den_section(section)
156 : TYPE(section_type), POINTER :: section
157 :
158 : TYPE(keyword_type), POINTER :: keyword
159 :
160 1481 : CPASSERT(.NOT. ASSOCIATED(section))
161 : CALL section_create(section, __LOCATION__, name="EXTERNAL_DENSITY", &
162 : description="Section for the use of the ZMP technique on external densities.", &
163 : n_keywords=4, n_subsections=0, repeats=.FALSE., &
164 4443 : citations=[Zhao1994, Tozer1996])
165 1481 : NULLIFY (keyword)
166 :
167 : CALL keyword_create(keyword, __LOCATION__, name="FILE_DENSITY", &
168 : description="Specifies the filename containing the target density in *.cube format. "// &
169 : "In the MGRID section it must be imposed NGRID 1, as it works with only "// &
170 : "one grid. The number of points in each direction, and the spacing must "// &
171 : "be previously defined choosing the plane waves cut-off in section MGRID "// &
172 : "keyword CUTOFF, and the cube dimension in section SUBSYS / CELL / keyword ABC", &
173 : usage="FILE_DENSITY <FILENAME>", &
174 1481 : type_of_var=char_t, default_c_val="RHO_O.dat", n_var=-1)
175 1481 : CALL section_add_keyword(section, keyword)
176 1481 : CALL keyword_release(keyword)
177 :
178 : CALL keyword_create(keyword, __LOCATION__, name="LAMBDA", &
179 : description="Lagrange multiplier defined in the constraint ZMP method. When starting, use "// &
180 : "small values when starting from scratch (around 5,10). Then gradually increase "// &
181 : "the values depending, restarting from the previous calculation with the smaller "// &
182 : "value. To choose the progressive values of LAMBDA look at the convergence of the "// &
183 : "eigenvalues.", &
184 1481 : usage="LAMBDA <REAL>", default_r_val=10.0_dp)
185 1481 : CALL section_add_keyword(section, keyword)
186 1481 : CALL keyword_release(keyword)
187 :
188 : CALL keyword_create(keyword, __LOCATION__, name="ZMP_CONSTRAINT", &
189 : description="Specify which kind of constraint to solve the ZMP equation. The COULOMB default "// &
190 : "option is more stable.", &
191 : usage="ZMP_CONSTRAINT <CHAR>", &
192 : enum_c_vals=s2a("COULOMB", "DIFF", "NONE"), &
193 : enum_i_vals=[use_coulomb, use_diff, use_no], &
194 : enum_desc=s2a("Coulomb constraint, integral of [rho_0(r)-rho(r)]/|r-r'|", &
195 : "Simple constraint, [rho_0(r)-rho(r)]", &
196 : "No constrain imposed"), &
197 1481 : default_i_val=use_coulomb)
198 1481 : CALL section_add_keyword(section, keyword)
199 1481 : CALL keyword_release(keyword)
200 :
201 : CALL keyword_create(keyword, __LOCATION__, name="FERMI_AMALDI", &
202 : description="Add the Fermi-Amaldi contribution to the Hartree potential. "// &
203 : "It leads to a more stable convergence.", &
204 : usage="FERMI_AMALDI <LOGICAL>", &
205 : repeats=.FALSE., &
206 : n_var=1, &
207 1481 : default_l_val=.TRUE., lone_keyword_l_val=.TRUE.)
208 1481 : CALL section_add_keyword(section, keyword)
209 1481 : CALL keyword_release(keyword)
210 :
211 1481 : END SUBROUTINE create_ext_den_section
212 :
213 : ! **************************************************************************************************
214 : !> \brief ZMP Creates the section for creating the external v_xc
215 : !> \param section ...
216 : !> \date 03.2011
217 : !> \author D. Varsano [daniele.varsano@nano.cnr.it]
218 : ! **************************************************************************************************
219 1481 : SUBROUTINE create_ext_vxc_section(section)
220 : TYPE(section_type), POINTER :: section
221 :
222 : TYPE(keyword_type), POINTER :: keyword
223 :
224 1481 : CPASSERT(.NOT. ASSOCIATED(section))
225 : CALL section_create(section, __LOCATION__, name="EXTERNAL_VXC", &
226 : description="SCF convergence with external v_xc calculated through previous ZMP "// &
227 : "calculation", &
228 1481 : n_keywords=1, n_subsections=0, repeats=.FALSE.)
229 1481 : NULLIFY (keyword)
230 :
231 : CALL keyword_create(keyword, __LOCATION__, name="FILE_VXC", &
232 : description="The *.cube filename containing the v_xc potential. This works only "// &
233 : "with NGRID 1 imposed in the MGRID section. The number of points in each "// &
234 : "direction, and the spacing must equal to those previously used in the ZMP "// &
235 : "calculation and defined through the plane wave cut-off and the cube dimension "// &
236 : "respectively set in section MGRID / keyword CUTOFF, and in section SUBSYS / "// &
237 : "CELL / keyword ABC", &
238 : usage="FILE_VXC <FILENAME>", &
239 1481 : type_of_var=char_t, default_c_val="VXC_O.dat", n_var=-1)
240 1481 : CALL section_add_keyword(section, keyword)
241 1481 : CALL keyword_release(keyword)
242 1481 : END SUBROUTINE create_ext_vxc_section
243 :
244 : END MODULE input_cp2k_external
|