1!--------------------------------------------------------------------------------------------------!
2!   CP2K: A general program to perform molecular dynamics simulations                              !
3!   Copyright (C) 2000 - 2019  CP2K developers group                                               !
4!--------------------------------------------------------------------------------------------------!
5
6! **************************************************************************************************
7!> \brief builds the input structure for the VIBRATIONAL_ANALYSIS module
8!> \par History
9!>      01.2008 [tlaino] Teodoro Laino - University of Zurich
10!>                       Creating an own module for vibrational analysis
11!> \author [tlaino]
12! **************************************************************************************************
13MODULE input_cp2k_vib
14   USE cp_output_handling,              ONLY: add_last_numeric,&
15                                              cp_print_key_section_create,&
16                                              debug_print_level,&
17                                              low_print_level,&
18                                              medium_print_level,&
19                                              silent_print_level
20   USE cp_units,                        ONLY: cp_unit_to_cp2k
21   USE input_constants,                 ONLY: do_rep_blocked,&
22                                              do_rep_interleaved,&
23                                              ms_guess_atomic,&
24                                              ms_guess_bfgs,&
25                                              ms_guess_molden,&
26                                              ms_guess_restart,&
27                                              ms_guess_restart_vec
28   USE input_keyword_types,             ONLY: keyword_create,&
29                                              keyword_release,&
30                                              keyword_type
31   USE input_section_types,             ONLY: section_add_keyword,&
32                                              section_add_subsection,&
33                                              section_create,&
34                                              section_release,&
35                                              section_type
36   USE input_val_types,                 ONLY: integer_t,&
37                                              real_t
38   USE kinds,                           ONLY: dp
39   USE string_utilities,                ONLY: s2a
40#include "../base/base_uses.f90"
41
42   IMPLICIT NONE
43   PRIVATE
44
45   LOGICAL, PRIVATE, PARAMETER :: debug_this_module = .TRUE.
46   CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'input_cp2k_vib'
47
48   PUBLIC :: create_vib_section
49CONTAINS
50
51! **************************************************************************************************
52!> \brief Creates the exteranal restart section
53!> \param section the section to create
54!> \author tlaino
55! **************************************************************************************************
56   SUBROUTINE create_vib_section(section)
57      TYPE(section_type), POINTER                        :: section
58
59      CHARACTER(len=*), PARAMETER :: routineN = 'create_vib_section', &
60         routineP = moduleN//':'//routineN
61
62      TYPE(keyword_type), POINTER                        :: keyword
63      TYPE(section_type), POINTER                        :: subsection
64
65      CPASSERT(.NOT. ASSOCIATED(section))
66      CALL section_create( &
67         section, __LOCATION__, name="VIBRATIONAL_ANALYSIS", &
68         description="Section to setup parameters to perform a Normal Modes, vibrational, or phonon analysis. "// &
69         "Vibrations are computed using finite differences, "// &
70         "which implies a very tight (e.g. 1E-8) threshold is needed for EPS_SCF to get accurate low frequencies. "// &
71         "The analysis assumes a stationary state (minimum or TS),"// &
72         " i.e. tight geometry optimization (MAX_FORCE) is needed as well.", &
73         n_keywords=1, n_subsections=0, repeats=.FALSE.)
74      NULLIFY (keyword, subsection)
75
76      CALL keyword_create(keyword, __LOCATION__, name="DX", &
77                          description="Specify the increment to be used to construct the HESSIAN with "// &
78                          "finite difference method", &
79                          default_r_val=1.0E-2_dp, unit_str="bohr")
80      CALL section_add_keyword(section, keyword)
81      CALL keyword_release(keyword)
82
83      CALL keyword_create(keyword, __LOCATION__, name="NPROC_REP", &
84                          description="Specify the number of processors to be used per replica "// &
85                          "environment (for parallel runs). "// &
86                          "In case of mode selective calculations more than one replica will start"// &
87                          " a block Davidson algorithm to track more than only one frequency", &
88                          default_i_val=1)
89      CALL section_add_keyword(section, keyword)
90      CALL keyword_release(keyword)
91
92      CALL keyword_create(keyword, __LOCATION__, name="PROC_DIST_TYPE", &
93                          description="Specify the topology of the mapping of processors into replicas.", &
94                          usage="PROC_DIST_TYPE (INTERLEAVED|BLOCKED)", &
95                          enum_c_vals=s2a("INTERLEAVED", &
96                                          "BLOCKED"), &
97                          enum_desc=s2a("Interleaved distribution", &
98                                        "Blocked distribution"), &
99                          enum_i_vals=(/do_rep_interleaved, do_rep_blocked/), &
100                          default_i_val=do_rep_blocked)
101      CALL section_add_keyword(section, keyword)
102      CALL keyword_release(keyword)
103
104      CALL keyword_create(keyword, __LOCATION__, name="FULLY_PERIODIC", &
105                          description="Avoids to clean rotations from the Hessian matrix.", &
106                          default_l_val=.FALSE., lone_keyword_l_val=.TRUE.)
107      CALL section_add_keyword(section, keyword)
108      CALL keyword_release(keyword)
109
110      CALL keyword_create(keyword, __LOCATION__, name="INTENSITIES", &
111                          description="Calculation of the IR-Intensities. Calculation of dipoles has to be specified explicitly ", &
112                          default_l_val=.FALSE., lone_keyword_l_val=.TRUE.)
113      CALL section_add_keyword(section, keyword)
114      CALL keyword_release(keyword)
115
116      CALL keyword_create(keyword, __LOCATION__, name="THERMOCHEMISTRY", &
117                          description="Calculation of the thermochemical data. Valid for molecules in the gas phase. ", &
118                          default_l_val=.FALSE., lone_keyword_l_val=.TRUE.)
119      CALL section_add_keyword(section, keyword)
120      CALL keyword_release(keyword)
121
122      CALL keyword_create(keyword, __LOCATION__, name="TC_TEMPERATURE", &
123                          description="Temperature for the calculation of the thermochemical data ", &
124                          usage="tc_temperature 325.0", default_r_val=cp_unit_to_cp2k(value=273.150_dp, unit_str="K"), &
125                          unit_str="K")
126      CALL section_add_keyword(section, keyword)
127      CALL keyword_release(keyword)
128
129      CALL keyword_create(keyword, __LOCATION__, name="TC_PRESSURE", &
130                          description="Pressure for the calculation of the thermochemical data  ", &
131                          default_r_val=cp_unit_to_cp2k(value=101325.0_dp, unit_str="Pa"), unit_str="Pa")
132      CALL section_add_keyword(section, keyword)
133      CALL keyword_release(keyword)
134
135      CALL create_mode_selective_section(subsection)
136      CALL section_add_subsection(section, subsection)
137      CALL section_release(subsection)
138
139      CALL create_print_vib_section(subsection)
140      CALL section_add_subsection(section, subsection)
141      CALL section_release(subsection)
142   END SUBROUTINE create_vib_section
143
144! **************************************************************************************************
145!> \brief Create the print section for VIB
146!> \param section the section to create
147!> \author Teodoro Laino [tlaino] - 10.2008
148! **************************************************************************************************
149   SUBROUTINE create_print_vib_section(section)
150      TYPE(section_type), POINTER                        :: section
151
152      CHARACTER(len=*), PARAMETER :: routineN = 'create_print_vib_section', &
153         routineP = moduleN//':'//routineN
154
155      TYPE(keyword_type), POINTER                        :: keyword
156      TYPE(section_type), POINTER                        :: print_key
157
158      CPASSERT(.NOT. ASSOCIATED(section))
159      CALL section_create(section, __LOCATION__, name="PRINT", &
160                          description="Section controlling the print information during a vibrational "// &
161                          "analysis.", n_keywords=1, n_subsections=0, repeats=.FALSE.)
162      NULLIFY (keyword, print_key)
163
164      CALL cp_print_key_section_create(print_key, __LOCATION__, "BANNER", &
165                                       description="Controls the printing of the vibrational analysis banner", &
166                                       print_level=low_print_level, common_iter_levels=1, &
167                                       filename="__STD_OUT__")
168      CALL section_add_subsection(section, print_key)
169      CALL section_release(print_key)
170
171      CALL cp_print_key_section_create(print_key, __LOCATION__, "PROGRAM_RUN_INFO", &
172                                       description="Controls the printing basic info about the vibrational method", &
173                                       print_level=medium_print_level, add_last=add_last_numeric, filename="__STD_OUT__")
174      CALL section_add_subsection(section, print_key)
175      CALL section_release(print_key)
176
177      CALL cp_print_key_section_create(print_key, __LOCATION__, "MOLDEN_VIB", &
178                                       description="Controls the printing for visualization in molden format", &
179                                       print_level=low_print_level, add_last=add_last_numeric, filename="VIBRATIONS")
180      CALL section_add_subsection(section, print_key)
181      CALL section_release(print_key)
182
183      CALL cp_print_key_section_create(print_key, __LOCATION__, "ROTATIONAL_INFO", &
184                                       description="Controls the printing basic info during the cleaning of the "// &
185                                       "rotational degrees of freedom.", &
186                                       print_level=debug_print_level, add_last=add_last_numeric, filename="__STD_OUT__")
187      ! Print_key keywords
188      CALL keyword_create(keyword, __LOCATION__, name="COORDINATES", &
189                          description="Prints atomic coordinates after rotation", &
190                          default_l_val=.FALSE., lone_keyword_l_val=.TRUE.)
191      CALL section_add_keyword(print_key, keyword)
192      CALL keyword_release(keyword)
193      CALL section_add_subsection(section, print_key)
194      CALL section_release(print_key)
195
196      CALL cp_print_key_section_create(print_key, __LOCATION__, "CARTESIAN_EIGS", &
197                                       description="Controls the printing of Cartesian "// &
198                                       "frequencies and eigenvectors of the Hessian used "// &
199                                       "for initializing ensemble for MD calculations. "// &
200                                       "This should always print to a file, and will not "// &
201                                       "effect the same frequencies and eigenvectors printed "// &
202                                       "in the main vibrational analysis output", &
203                                       print_level=low_print_level, &
204                                       add_last=add_last_numeric, &
205                                       filename="VIBRATIONS")
206      CALL keyword_create(keyword, __LOCATION__, name="BACKUP_COPIES", &
207                          description="Specifies the maximum index of backup copies.", &
208                          usage="BACKUP_COPIES {int}", &
209                          default_i_val=3)
210      CALL section_add_keyword(print_key, keyword)
211      CALL keyword_release(keyword)
212      CALL section_add_subsection(section, print_key)
213      CALL section_release(print_key)
214
215      CALL cp_print_key_section_create(print_key, __LOCATION__, "HESSIAN", &
216                                       description="Write the Hessian matrix from a vibrational analysis calculation "// &
217                                       "into a binary file.", &
218                                       print_level=low_print_level, add_last=add_last_numeric, filename="Hessian")
219      CALL section_add_subsection(section, print_key)
220      CALL section_release(print_key)
221
222   END SUBROUTINE create_print_vib_section
223
224! **************************************************************************************************
225!> \brief Create the input section for MODE selective
226!> \param section the section to create
227!> \author fschiff
228! **************************************************************************************************
229   SUBROUTINE create_mode_selective_section(section)
230      TYPE(section_type), POINTER                        :: section
231
232      CHARACTER(len=*), PARAMETER :: routineN = 'create_mode_selective_section', &
233         routineP = moduleN//':'//routineN
234
235      TYPE(keyword_type), POINTER                        :: keyword
236      TYPE(section_type), POINTER                        :: print_key, subsection
237
238      NULLIFY (keyword, subsection, print_key)
239      CPASSERT(.NOT. ASSOCIATED(section))
240      CALL section_create(section, __LOCATION__, name="MODE_SELECTIVE", &
241                          description="All parameters needed for to run a mode selective vibrational analysis. "// &
242                          "The keywords FREQUENCY, RANGE, and the subsection INVOLVED_ATOMS are mutually exclusive.", &
243                          n_keywords=8, n_subsections=1, repeats=.FALSE.)
244
245      CALL keyword_create(keyword, __LOCATION__, name="FREQUENCY", &
246                          description="value close to the expected value of the frequency to look for. "// &
247                          "If the block Davidson algorithm is applied, the nrep closest frequencies are tracked. ", &
248                          usage="FREQUENCY {REAL}", default_r_val=-1._dp)
249      CALL section_add_keyword(section, keyword)
250      CALL keyword_release(keyword)
251
252      CALL keyword_create(keyword, __LOCATION__, name="RANGE", &
253                          description="Track modes in a given range of frequencies. "// &
254                          "No warranty that the set of frequencies is complete.", &
255                          usage="RANGE {REAL} {REAL}", &
256                          n_var=-1, type_of_var=real_t)
257      CALL section_add_keyword(section, keyword)
258      CALL keyword_release(keyword)
259
260      CALL keyword_create(keyword, __LOCATION__, name="LOWEST_FREQUENCY", &
261                          description="Lowest frequency mode to include when writing output. "// &
262                          "Use a negative value to print imaginary frequencies. "// &
263                          "Useful for visualizing the imaginary frequency along a reaction path coordinate "// &
264                          "Depending on accuracy settings, the output might include spurious low frequency "// &
265                          " imaginary modes which should be visually checked (see MOLDEN_VIB).", &
266                          usage="LOWEST_FREQUENCY <REAL>", default_r_val=0.0_dp)
267      CALL section_add_keyword(section, keyword)
268      CALL keyword_release(keyword)
269
270      CALL keyword_create(keyword, __LOCATION__, name="ATOMS", &
271                          description="Specifies the list of atoms which should be displaced for the Initial guess", &
272                          usage="ATOMS {integer} {integer} .. {integer}", &
273                          n_var=-1, type_of_var=integer_t)
274      CALL section_add_keyword(section, keyword)
275      CALL keyword_release(keyword)
276
277      CALL keyword_create(keyword, __LOCATION__, name="EPS_MAX_VAL", &
278                          description="Convergence criterion for the davidson algorithm. Specifies the maximal value in the "// &
279                          "residuum vectors ", &
280                          usage="EPS_MAX_VAL {REAL}", default_r_val=5.0E-7_dp)
281      CALL section_add_keyword(section, keyword)
282      CALL keyword_release(keyword)
283
284      CALL keyword_create( &
285         keyword, __LOCATION__, name="EPS_NORM", &
286         description="Convergence criterion for the davidson algorithm. Specifies the maximal value of the norm "// &
287         "of the residuum vectors ", &
288         usage="EPS_NORM {REAL}", default_r_val=2.0E-6_dp)
289      CALL section_add_keyword(section, keyword)
290      CALL keyword_release(keyword)
291
292      CALL keyword_create( &
293         keyword, __LOCATION__, name="INITIAL_GUESS", &
294         description="The type of initial guess for the normal modes", &
295         usage="INITIAL_GUESS BFGS_HESS", &
296         default_i_val=ms_guess_atomic, &
297         enum_c_vals=s2a("BFGS_HESS", "ATOMIC", "RESTART", "RESTART_VEC", "MOLDEN_RESTART"), &
298         enum_desc=s2a("get the first displacement vector out of the BFGS approximate Hessian", &
299                       "use random displacements for a set of atoms specified", &
300                       "use data from MS_RESTART as initial guess", &
301                       "use a vector from MS_RESTART, useful if you want to increase accurcy by changing functionals or basis", &
302                       "use the .mol file of a former run, to restart a vector"// &
303                       "(similar to Restart_vec, but a different file FORMAT is used)"), &
304         enum_i_vals=(/ms_guess_bfgs, ms_guess_atomic, ms_guess_restart, ms_guess_restart_vec, ms_guess_molden/))
305      CALL section_add_keyword(section, keyword)
306      CALL keyword_release(keyword)
307
308      CALL keyword_create(keyword, __LOCATION__, name="RESTART_FILE_NAME", &
309                          description="Specifies the name of the file used to create the restarted vectors", &
310                          usage="RESTART_FILE_NAME {filename}", &
311                          default_lc_val="")
312      CALL section_add_keyword(section, keyword)
313      CALL keyword_release(keyword)
314
315      CALL create_involved_atoms_section(subsection)
316      CALL section_add_subsection(section, subsection)
317      CALL section_release(subsection)
318
319      CALL section_create(subsection, __LOCATION__, name="PRINT", &
320                          description="Controls the printing mode selective vibrational analysis", &
321                          n_keywords=0, n_subsections=1, repeats=.TRUE.)
322
323      CALL cp_print_key_section_create(print_key, __LOCATION__, "MS_RESTART", &
324                                       description="Controls the printing of the Mode Selective Restart file.", &
325                                       print_level=silent_print_level, common_iter_levels=1, &
326                                       add_last=add_last_numeric, filename="")
327      CALL section_add_subsection(subsection, print_key)
328      CALL section_release(print_key)
329
330      CALL section_add_subsection(section, subsection)
331      CALL section_release(subsection)
332
333   END SUBROUTINE create_mode_selective_section
334
335! **************************************************************************************************
336!> \brief Create the input section for Ivolved_atoms keyword in mode selective
337!> \param section the section to create
338!> \author fschiff
339! **************************************************************************************************
340   SUBROUTINE create_involved_atoms_section(section)
341      TYPE(section_type), POINTER                        :: section
342
343      CHARACTER(len=*), PARAMETER :: routineN = 'create_involved_atoms_section', &
344         routineP = moduleN//':'//routineN
345
346      TYPE(keyword_type), POINTER                        :: keyword
347
348      NULLIFY (keyword)
349      CPASSERT(.NOT. ASSOCIATED(section))
350      CALL section_create( &
351         section, __LOCATION__, name="INVOLVED_ATOMS", &
352         description="All parameters needed for the tracking of modes dominated by the motion of selected atoms. "// &
353         "Warning, if many atoms are involved, only low frequency modes are detected, "// &
354         "since they are more delocalized and match the tracked eigenvector.", &
355         n_keywords=2, n_subsections=0, repeats=.FALSE.)
356
357      CALL keyword_create( &
358         keyword, __LOCATION__, name="RANGE", &
359         description=" Specifies the range of wavenumbers in which the modes related to the ATOMS have to be tracked. "// &
360         " If not specified frequencies >400cm-1 will be used to avoid tracking of translational or rotational modes", &
361         usage="RANGE {REAL} {REAL}", &
362         n_var=-1, type_of_var=real_t)
363      CALL section_add_keyword(section, keyword)
364      CALL keyword_release(keyword)
365
366      CALL keyword_create( &
367         keyword, __LOCATION__, name="INVOLVED_ATOMS", &
368         description="Specifies the list of atoms on which the tracked eigenvector should have the highest value "// &
369         "similar to looking for the vibration of a set of atoms", &
370         usage="INVOLVED_ATOMS {integer} {integer} .. {integer}", &
371         n_var=-1, type_of_var=integer_t)
372      CALL section_add_keyword(section, keyword)
373      CALL keyword_release(keyword)
374
375   END SUBROUTINE create_involved_atoms_section
376
377END MODULE input_cp2k_vib
378