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 Performs the metadynamics calculation
10 : !> \par History
11 : !> 01.2005 created [fawzi and ale]
12 : !> 11.2007 Teodoro Laino [tlaino] - University of Zurich
13 : ! **************************************************************************************************
14 : MODULE metadynamics_utils
15 : USE cp_files, ONLY: close_file,&
16 : open_file
17 : USE cp_log_handling, ONLY: cp_get_default_logger,&
18 : cp_logger_type,&
19 : cp_to_string
20 : USE cp_output_handling, ONLY: cp_print_key_finished_output,&
21 : cp_print_key_unit_nr
22 : USE cp_subsys_types, ONLY: cp_subsys_type
23 : USE force_env_types, ONLY: force_env_get,&
24 : force_env_type
25 : USE input_constants, ONLY: do_fe_meta,&
26 : do_wall_gaussian,&
27 : do_wall_m,&
28 : do_wall_none,&
29 : do_wall_p,&
30 : do_wall_quadratic,&
31 : do_wall_quartic,&
32 : do_wall_reflective
33 : USE input_cp2k_free_energy, ONLY: create_metavar_section
34 : USE input_enumeration_types, ONLY: enum_i2c,&
35 : enumeration_type
36 : USE input_keyword_types, ONLY: keyword_get,&
37 : keyword_type
38 : USE input_section_types, ONLY: section_get_keyword,&
39 : section_get_subsection,&
40 : section_release,&
41 : section_type,&
42 : section_vals_get,&
43 : section_vals_get_subs_vals,&
44 : section_vals_type,&
45 : section_vals_val_get
46 : USE kinds, ONLY: default_path_length,&
47 : dp
48 : USE machine, ONLY: m_mov
49 : USE message_passing, ONLY: mp_para_env_type
50 : USE metadynamics_types, ONLY: hills_env_type,&
51 : meta_env_type,&
52 : metadyn_create,&
53 : metavar_type,&
54 : multiple_walkers_type
55 : USE physcon, ONLY: kelvin
56 : #include "./base/base_uses.f90"
57 :
58 : IMPLICIT NONE
59 : PRIVATE
60 :
61 : CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'metadynamics_utils'
62 :
63 : PUBLIC :: metadyn_read, &
64 : synchronize_multiple_walkers, &
65 : add_hill_single, &
66 : restart_hills, &
67 : get_meta_iter_level, &
68 : meta_walls
69 :
70 : CONTAINS
71 :
72 : ! **************************************************************************************************
73 : !> \brief reads metadynamics section
74 : !> \param meta_env ...
75 : !> \param force_env ...
76 : !> \param root_section ...
77 : !> \param para_env ...
78 : !> \param fe_section ...
79 : !> \par History
80 : !> 04.2004 created
81 : !> \author Teodoro Laino [tlaino] - University of Zurich. 11.2007
82 : ! **************************************************************************************************
83 21126 : SUBROUTINE metadyn_read(meta_env, force_env, root_section, para_env, fe_section)
84 : TYPE(meta_env_type), POINTER :: meta_env
85 : TYPE(force_env_type), POINTER :: force_env
86 : TYPE(section_vals_type), POINTER :: root_section
87 : TYPE(mp_para_env_type), POINTER :: para_env
88 : TYPE(section_vals_type), OPTIONAL, POINTER :: fe_section
89 :
90 : CHARACTER(len=*), PARAMETER :: routineN = 'metadyn_read'
91 :
92 : CHARACTER(LEN=default_path_length) :: walkers_file_name
93 : INTEGER :: handle, i, id_method, n_colvar, n_rep, &
94 : number_allocated_colvars
95 10563 : INTEGER, DIMENSION(:), POINTER :: walkers_status
96 : LOGICAL :: check, explicit
97 : REAL(kind=dp) :: dt
98 : TYPE(cp_subsys_type), POINTER :: subsys
99 : TYPE(section_vals_type), POINTER :: md_section, metadyn_section, &
100 : metavar_section, walkers_section
101 :
102 10563 : NULLIFY (subsys)
103 10563 : CALL timeset(routineN, handle)
104 :
105 10563 : CALL section_vals_get(fe_section, explicit=explicit)
106 10563 : IF (explicit) THEN
107 168 : number_allocated_colvars = 0
108 168 : CALL force_env_get(force_env, subsys=subsys)
109 168 : IF (ASSOCIATED(subsys%colvar_p)) THEN
110 168 : number_allocated_colvars = SIZE(subsys%colvar_p)
111 : END IF
112 168 : CALL section_vals_val_get(fe_section, "METHOD", i_val=id_method)
113 168 : IF (id_method /= do_fe_meta) THEN
114 14 : CALL timestop(handle)
115 16 : RETURN
116 : END IF
117 154 : metadyn_section => section_vals_get_subs_vals(fe_section, "METADYN")
118 154 : CPASSERT(.NOT. ASSOCIATED(meta_env))
119 :
120 154 : md_section => section_vals_get_subs_vals(root_section, "MOTION%MD")
121 154 : CALL section_vals_val_get(md_section, "TIMESTEP", r_val=dt)
122 :
123 154 : metavar_section => section_vals_get_subs_vals(metadyn_section, "METAVAR")
124 154 : CALL section_vals_get(metavar_section, n_repetition=n_colvar)
125 154 : ALLOCATE (meta_env)
126 : CALL metadyn_create(meta_env, n_colvar=n_colvar, &
127 154 : dt=dt, para_env=para_env, metadyn_section=metadyn_section)
128 :
129 : !Check if using plumed. If so, only get the file name and read nothing else
130 154 : CALL section_vals_val_get(metadyn_section, "USE_PLUMED", l_val=meta_env%use_plumed)
131 154 : IF (meta_env%use_plumed .EQV. .TRUE.) THEN
132 2 : CALL section_vals_val_get(metadyn_section, "PLUMED_INPUT_FILE", c_val=meta_env%plumed_input_file)
133 2 : meta_env%plumed_input_file = TRIM(meta_env%plumed_input_file)//CHAR(0)
134 2 : meta_env%langevin = .FALSE.
135 2 : CALL timestop(handle)
136 2 : RETURN
137 : END IF
138 :
139 152 : CALL section_vals_val_get(metadyn_section, "DO_HILLS", l_val=meta_env%do_hills)
140 152 : CALL section_vals_val_get(metadyn_section, "LAGRANGE", l_val=meta_env%extended_lagrange)
141 152 : CALL section_vals_val_get(metadyn_section, "TAMCSteps", i_val=meta_env%TAMCSteps)
142 152 : IF (meta_env%TAMCSteps < 0) THEN
143 0 : CPABORT("TAMCSteps must be positive!")
144 : END IF
145 152 : CALL section_vals_val_get(metadyn_section, "Timestep", r_val=meta_env%zdt)
146 152 : IF (meta_env%zdt <= 0.0_dp) THEN
147 0 : CPABORT("Timestep must be positive!")
148 : END IF
149 152 : CALL section_vals_val_get(metadyn_section, "WW", r_val=meta_env%hills_env%ww)
150 152 : CALL section_vals_val_get(metadyn_section, "NT_HILLS", i_val=meta_env%hills_env%nt_hills)
151 152 : CALL section_vals_val_get(metadyn_section, "MIN_NT_HILLS", i_val=meta_env%hills_env%min_nt_hills)
152 152 : IF (meta_env%hills_env%nt_hills <= 0) THEN
153 4 : meta_env%hills_env%min_nt_hills = meta_env%hills_env%nt_hills
154 : CALL cp_warn(__LOCATION__, &
155 : "NT_HILLS has a value <= 0; "// &
156 : "Setting MIN_NT_HILLS to the same value! "// &
157 4 : "Overriding input specification!")
158 : END IF
159 152 : check = meta_env%hills_env%nt_hills >= meta_env%hills_env%min_nt_hills
160 152 : IF (.NOT. check) THEN
161 : CALL cp_abort(__LOCATION__, "MIN_NT_HILLS must have a value smaller or equal to NT_HILLS! "// &
162 0 : "Cross check with the input reference!")
163 : END IF
164 : !RG Adaptive hills
165 152 : CALL section_vals_val_get(metadyn_section, "MIN_DISP", r_val=meta_env%hills_env%min_disp)
166 152 : CALL section_vals_val_get(metadyn_section, "OLD_HILL_NUMBER", i_val=meta_env%hills_env%old_hill_number)
167 152 : CALL section_vals_val_get(metadyn_section, "OLD_HILL_STEP", i_val=meta_env%hills_env%old_hill_step)
168 :
169 : !Hills tail damping
170 152 : CALL section_vals_val_get(metadyn_section, "HILL_TAIL_CUTOFF", r_val=meta_env%hills_env%tail_cutoff)
171 152 : CALL section_vals_val_get(metadyn_section, "P_EXPONENT", i_val=meta_env%hills_env%p_exp)
172 152 : CALL section_vals_val_get(metadyn_section, "Q_EXPONENT", i_val=meta_env%hills_env%q_exp)
173 :
174 152 : CALL section_vals_val_get(metadyn_section, "SLOW_GROWTH", l_val=meta_env%hills_env%slow_growth)
175 :
176 : !RG Adaptive hills
177 152 : CALL section_vals_val_get(metadyn_section, "STEP_START_VAL", i_val=meta_env%n_steps)
178 152 : CPASSERT(meta_env%n_steps >= 0)
179 : CALL section_vals_val_get(metadyn_section, "NHILLS_START_VAL", &
180 152 : i_val=meta_env%hills_env%n_hills)
181 152 : CALL section_vals_val_get(metadyn_section, "TEMPERATURE", r_val=meta_env%temp_wanted)
182 152 : CALL section_vals_val_get(metadyn_section, "LANGEVIN", l_val=meta_env%langevin)
183 : CALL section_vals_val_get(metadyn_section, "TEMP_TOL", explicit=meta_env%tempcontrol, &
184 152 : r_val=meta_env%toll_temp)
185 152 : CALL section_vals_val_get(metadyn_section, "WELL_TEMPERED", l_val=meta_env%well_tempered)
186 : CALL section_vals_val_get(metadyn_section, "DELTA_T", explicit=meta_env%hills_env%wtcontrol, &
187 152 : r_val=meta_env%delta_t)
188 : CALL section_vals_val_get(metadyn_section, "WTGAMMA", explicit=check, &
189 152 : r_val=meta_env%wtgamma)
190 152 : IF (meta_env%well_tempered) THEN
191 2 : meta_env%hills_env%wtcontrol = meta_env%hills_env%wtcontrol .OR. check
192 2 : check = meta_env%hills_env%wtcontrol
193 2 : IF (.NOT. check) THEN
194 : CALL cp_abort(__LOCATION__, "When using Well-Tempered metadynamics, "// &
195 0 : "DELTA_T (or WTGAMMA) should be explicitly specified.")
196 : END IF
197 2 : IF (meta_env%extended_lagrange) THEN
198 : CALL cp_abort(__LOCATION__, &
199 0 : "Well-Tempered metadynamics not possible with extended-lagrangian formulation.")
200 : END IF
201 2 : IF (meta_env%hills_env%min_disp > 0.0_dp) THEN
202 : CALL cp_abort(__LOCATION__, &
203 0 : "Well-Tempered metadynamics not possible with Adaptive hills.")
204 : END IF
205 : END IF
206 :
207 : CALL section_vals_val_get(metadyn_section, "COLVAR_AVG_TEMPERATURE_RESTART", &
208 152 : r_val=meta_env%avg_temp)
209 : ! Parsing Metavar Section
210 346 : DO i = 1, n_colvar
211 : CALL metavar_read(meta_env%metavar(i), meta_env%extended_lagrange, &
212 194 : meta_env%langevin, i, metavar_section)
213 194 : check = (meta_env%metavar(i)%icolvar <= number_allocated_colvars)
214 346 : IF (.NOT. check) THEN
215 : CALL cp_abort(__LOCATION__, &
216 : "An error occurred in the specification of COLVAR for METAVAR. "// &
217 : "Specified COLVAR #("//TRIM(ADJUSTL(cp_to_string(meta_env%metavar(i)%icolvar)))//") "// &
218 : "is larger than the maximum number of COLVARS defined in the SUBSYS ("// &
219 0 : TRIM(ADJUSTL(cp_to_string(number_allocated_colvars)))//") !")
220 : END IF
221 : END DO
222 :
223 : ! Parsing the Multiple Walkers Info
224 152 : IF (meta_env%do_multiple_walkers) THEN
225 8 : NULLIFY (walkers_status)
226 8 : walkers_section => section_vals_get_subs_vals(metadyn_section, "MULTIPLE_WALKERS")
227 :
228 : ! General setup for walkers
229 : CALL section_vals_val_get(walkers_section, "WALKER_ID", &
230 8 : i_val=meta_env%multiple_walkers%walker_id)
231 : CALL section_vals_val_get(walkers_section, "NUMBER_OF_WALKERS", &
232 8 : i_val=meta_env%multiple_walkers%walkers_tot_nr)
233 : CALL section_vals_val_get(walkers_section, "WALKER_COMM_FREQUENCY", &
234 8 : i_val=meta_env%multiple_walkers%walkers_freq_comm)
235 :
236 : ! Handle status and file names
237 24 : ALLOCATE (meta_env%multiple_walkers%walkers_status(meta_env%multiple_walkers%walkers_tot_nr))
238 24 : ALLOCATE (meta_env%multiple_walkers%walkers_file_name(meta_env%multiple_walkers%walkers_tot_nr))
239 8 : CALL section_vals_val_get(walkers_section, "WALKERS_STATUS", explicit=explicit)
240 8 : IF (explicit) THEN
241 4 : CALL section_vals_val_get(walkers_section, "WALKERS_STATUS", i_vals=walkers_status)
242 4 : check = (SIZE(walkers_status) == meta_env%multiple_walkers%walkers_tot_nr)
243 4 : IF (.NOT. check) THEN
244 : CALL cp_abort(__LOCATION__, &
245 : "Number of Walkers specified in the input does not match with the "// &
246 : "size of the WALKERS_STATUS. Please check your input and in case "// &
247 : "this is a restart run consider the possibility to switch off the "// &
248 0 : "RESTART_WALKERS in the EXT_RESTART section! ")
249 : END IF
250 20 : meta_env%multiple_walkers%walkers_status = walkers_status
251 : ELSE
252 12 : meta_env%multiple_walkers%walkers_status = 0
253 : END IF
254 : meta_env%multiple_walkers%n_hills_local = &
255 8 : meta_env%multiple_walkers%walkers_status(meta_env%multiple_walkers%walker_id)
256 :
257 : CALL section_vals_val_get(walkers_section, "WALKERS_FILE_NAME%_DEFAULT_KEYWORD_", &
258 8 : n_rep_val=n_rep)
259 8 : check = (n_rep == meta_env%multiple_walkers%walkers_tot_nr)
260 8 : IF (.NOT. check) THEN
261 : CALL cp_abort(__LOCATION__, &
262 : "Number of Walkers specified in the input does not match with the "// &
263 : "number of Walkers File names provided. Please check your input and in case "// &
264 : "this is a restart run consider the possibility to switch off the "// &
265 0 : "RESTART_WALKERS in the EXT_RESTART section! ")
266 : END IF
267 40 : DO i = 1, n_rep
268 : CALL section_vals_val_get(walkers_section, "WALKERS_FILE_NAME%_DEFAULT_KEYWORD_", &
269 16 : i_rep_val=i, c_val=walkers_file_name)
270 24 : meta_env%multiple_walkers%walkers_file_name(i) = walkers_file_name
271 : END DO
272 : END IF
273 :
274 : ! Print Metadynamics Info
275 152 : CALL print_metadyn_info(meta_env, n_colvar, metadyn_section)
276 : END IF
277 :
278 10547 : CALL timestop(handle)
279 :
280 10563 : END SUBROUTINE metadyn_read
281 :
282 : ! **************************************************************************************************
283 : !> \brief prints information on the metadynamics run
284 : !> \param meta_env ...
285 : !> \param n_colvar ...
286 : !> \param metadyn_section ...
287 : !> \author Teodoro Laino [tlaino] - University of Zurich. 10.2008
288 : ! **************************************************************************************************
289 152 : SUBROUTINE print_metadyn_info(meta_env, n_colvar, metadyn_section)
290 : TYPE(meta_env_type), POINTER :: meta_env
291 : INTEGER, INTENT(IN) :: n_colvar
292 : TYPE(section_vals_type), POINTER :: metadyn_section
293 :
294 : CHARACTER(len=*), PARAMETER :: routineN = 'print_metadyn_info'
295 :
296 : CHARACTER(LEN=10) :: my_id, my_tag
297 : INTEGER :: handle, i, iw, j
298 : TYPE(cp_logger_type), POINTER :: logger
299 : TYPE(enumeration_type), POINTER :: enum
300 : TYPE(keyword_type), POINTER :: keyword
301 : TYPE(section_type), POINTER :: section, wall_section, work_section
302 :
303 152 : CALL timeset(routineN, handle)
304 :
305 152 : logger => cp_get_default_logger()
306 : iw = cp_print_key_unit_nr(logger, metadyn_section, &
307 152 : "PRINT%PROGRAM_RUN_INFO", extension=".metadynLog")
308 152 : NULLIFY (section, enum, keyword)
309 152 : CALL create_metavar_section(section)
310 152 : wall_section => section_get_subsection(section, "WALL")
311 152 : IF (iw > 0) THEN
312 76 : WRITE (iw, '( /A )') ' METADYN| Meta Dynamics Protocol '
313 76 : WRITE (iw, '( A,T71,I10)') ' METADYN| Number of interval time steps to spawn hills', &
314 152 : meta_env%hills_env%nt_hills
315 76 : WRITE (iw, '( A,T71,I10)') ' METADYN| Number of previously spawned hills', &
316 152 : meta_env%hills_env%n_hills
317 76 : IF (meta_env%extended_lagrange) THEN
318 28 : WRITE (iw, '( A )') ' METADYN| Extended Lagrangian Scheme '
319 28 : IF (meta_env%tempcontrol) WRITE (iw, '( A,T71,F10.2)') &
320 10 : ' METADYN| Collective Variables Temperature control', meta_env%toll_temp
321 28 : IF (meta_env%langevin) THEN
322 3 : WRITE (iw, '(A,T71)') ' METADYN| Langevin Thermostat in use for COLVAR '
323 3 : WRITE (iw, '(A,T71,F10.4)') ' METADYN| Langevin Thermostat. Target Temperature = ', &
324 6 : meta_env%temp_wanted*kelvin
325 : END IF
326 28 : WRITE (iw, '(A,T71,F10.4)') ' METADYN| COLVARS restarted average temperature ', &
327 56 : meta_env%avg_temp
328 : END IF
329 76 : IF (meta_env%do_hills) THEN
330 60 : WRITE (iw, '( A )') ' METADYN| Spawning the Hills '
331 60 : WRITE (iw, '( A,T71,F10.3)') ' METADYN| Height of the Spawned Gaussian', meta_env%hills_env%ww
332 : !RG Adaptive hills
333 60 : IF (meta_env%hills_env%min_disp > 0.0_dp) THEN
334 2 : WRITE (iw, '(A)') ' METADYN| Adapative meta time step is activated'
335 2 : WRITE (iw, '(A,T71,F10.4)') ' METADYN| Minimum displacement for next hill', &
336 4 : meta_env%hills_env%min_disp
337 : END IF
338 : !RG Adaptive hills
339 : END IF
340 :
341 76 : IF (meta_env%well_tempered) THEN
342 1 : WRITE (iw, '( A )') ' METADYN| Well-Tempered metadynamics '
343 1 : IF (meta_env%delta_t > EPSILON(1._dp)) THEN
344 1 : WRITE (iw, '( A,T71,F10.3)') ' METADYN| Temperature parameter (Delta T) [K]', meta_env%delta_t*kelvin
345 : ELSE
346 0 : WRITE (iw, '( A,T71,F10.3)') ' METADYN| Temperature parameter (gamma)', meta_env%wtgamma
347 : END IF
348 : END IF
349 :
350 76 : IF (meta_env%do_multiple_walkers) THEN
351 4 : WRITE (iw, '( A,T71,A10)') ' METADYN| Multiple Walkers', ' ENABLED'
352 4 : WRITE (iw, '( A,T71,I10)') ' METADYN| Number of Multiple Walkers', &
353 8 : meta_env%multiple_walkers%walkers_tot_nr
354 4 : WRITE (iw, '( A,T71,I10)') ' METADYN| Local Walker ID', &
355 8 : meta_env%multiple_walkers%walker_id
356 4 : WRITE (iw, '( A,T71,I10)') ' METADYN| Walker Communication Frequency', &
357 8 : meta_env%multiple_walkers%walkers_freq_comm
358 12 : DO i = 1, meta_env%multiple_walkers%walkers_tot_nr
359 8 : my_tag = ""
360 8 : IF (i == meta_env%multiple_walkers%walker_id) my_tag = " ( Local )"
361 8 : my_id = '( '//TRIM(ADJUSTL(cp_to_string(i)))//' )'
362 8 : WRITE (iw, '(/,A,T71,A10)') ' WALKERS| Walker ID'//TRIM(my_tag), ADJUSTR(my_id)
363 8 : WRITE (iw, '( A,T71,I10)') ' WALKERS| Number of Hills communicated', &
364 16 : meta_env%multiple_walkers%walkers_status(i)
365 8 : WRITE (iw, '( A,T24,A57)') ' WALKERS| Base Filename', &
366 20 : ADJUSTR(meta_env%multiple_walkers%walkers_file_name(i) (1:57))
367 : END DO
368 4 : WRITE (iw, '(/)')
369 : END IF
370 :
371 76 : WRITE (iw, '( A,T71,I10)') ' METADYN| Number of collective variables', meta_env%n_colvar
372 173 : DO i = 1, n_colvar
373 97 : WRITE (iw, '( A )') ' '//'----------------------------------------------------------------------'
374 97 : WRITE (iw, '( A,T71,I10)') ' METAVARS| Collective Variable Number', meta_env%metavar(i)%icolvar
375 97 : IF (meta_env%extended_lagrange) THEN
376 39 : WRITE (iw, '( A,T71,F10.6)') ' METAVARS| Lambda Parameter', meta_env%metavar(i)%lambda
377 39 : WRITE (iw, '( A,T66,F15.6)') ' METAVARS| Collective Variable Mass', meta_env%metavar(i)%mass
378 : END IF
379 97 : WRITE (iw, '( A,T71,F10.6)') ' METAVARS| Scaling factor', meta_env%metavar(i)%delta_s
380 102 : IF (meta_env%langevin) WRITE (iw, '( A,T71,F10.6)') ' METAVARS| Friction for Langevin Thermostat', &
381 10 : meta_env%metavar(i)%gamma
382 97 : IF (meta_env%metavar(i)%do_wall) THEN
383 18 : WRITE (iw, '( A,T71,I10)') ' METAVARS| Number of Walls present', SIZE(meta_env%metavar(i)%walls)
384 41 : DO j = 1, SIZE(meta_env%metavar(i)%walls)
385 23 : keyword => section_get_keyword(wall_section, "TYPE")
386 23 : CALL keyword_get(keyword, enum=enum)
387 23 : WRITE (iw, '(/,A,5X,I10,T50,A,T70,A11)') ' METAVARS| Wall Number:', j, 'Type of Wall:', &
388 46 : ADJUSTR(TRIM(enum_i2c(enum, meta_env%metavar(i)%walls(j)%id_type)))
389 : ! Type of wall IO
390 23 : SELECT CASE (meta_env%metavar(i)%walls(j)%id_type)
391 : CASE (do_wall_none)
392 : ! Do Nothing
393 4 : CYCLE
394 : CASE (do_wall_reflective)
395 4 : work_section => section_get_subsection(wall_section, "REFLECTIVE")
396 4 : keyword => section_get_keyword(work_section, "DIRECTION")
397 4 : CALL keyword_get(keyword, enum=enum)
398 4 : WRITE (iw, '(A,T70,A11)') ' METAVARS| Wall direction', &
399 8 : ADJUSTR(TRIM(enum_i2c(enum, meta_env%metavar(i)%walls(j)%id_direction)))
400 : CASE (do_wall_quadratic)
401 12 : work_section => section_get_subsection(wall_section, "QUADRATIC")
402 12 : keyword => section_get_keyword(work_section, "DIRECTION")
403 12 : CALL keyword_get(keyword, enum=enum)
404 12 : WRITE (iw, '(A,T70,A11)') ' METAVARS| Wall direction', &
405 24 : ADJUSTR(TRIM(enum_i2c(enum, meta_env%metavar(i)%walls(j)%id_direction)))
406 12 : WRITE (iw, '(A,T70,F11.6)') ' METAVARS| Constant K of the quadratic potential', &
407 24 : meta_env%metavar(i)%walls(j)%k_quadratic
408 : CASE (do_wall_gaussian)
409 3 : WRITE (iw, '(A,T70,F11.6)') ' METAVARS| Height of the Wall Gaussian', &
410 6 : meta_env%metavar(i)%walls(j)%ww_gauss
411 3 : WRITE (iw, '(A,T70,F11.6)') ' METAVARS| Scale of the Wall Gaussian', &
412 29 : meta_env%metavar(i)%walls(j)%sigma_gauss
413 : END SELECT
414 21 : WRITE (iw, '(A,T70,F11.6)') ' METAVARS| Wall location', &
415 60 : meta_env%metavar(i)%walls(j)%pos
416 : END DO
417 : END IF
418 173 : WRITE (iw, '( A )') ' '//'----------------------------------------------------------------------'
419 : END DO
420 : END IF
421 152 : CALL section_release(section)
422 152 : CALL cp_print_key_finished_output(iw, logger, metadyn_section, "PRINT%PROGRAM_RUN_INFO")
423 :
424 152 : CALL timestop(handle)
425 :
426 152 : END SUBROUTINE print_metadyn_info
427 :
428 : ! **************************************************************************************************
429 : !> \brief reads metavar section
430 : !> \param metavar ...
431 : !> \param extended_lagrange ...
432 : !> \param langevin ...
433 : !> \param icol ...
434 : !> \param metavar_section ...
435 : !> \par History
436 : !> 04.2004 created
437 : !> \author alessandro laio and fawzi mohamed
438 : !> Teodoro Laino [tlaino] - University of Zurich. 11.2007
439 : ! **************************************************************************************************
440 388 : SUBROUTINE metavar_read(metavar, extended_lagrange, langevin, icol, metavar_section)
441 : TYPE(metavar_type), INTENT(INOUT) :: metavar
442 : LOGICAL, INTENT(IN) :: extended_lagrange, langevin
443 : INTEGER, INTENT(IN) :: icol
444 : TYPE(section_vals_type), OPTIONAL, POINTER :: metavar_section
445 :
446 : CHARACTER(len=*), PARAMETER :: routineN = 'metavar_read'
447 :
448 : INTEGER :: handle, i, n_walls
449 : TYPE(section_vals_type), POINTER :: wall_section, work_section
450 :
451 194 : CALL timeset(routineN, handle)
452 :
453 194 : CALL section_vals_val_get(metavar_section, "COLVAR", i_rep_section=icol, i_val=metavar%icolvar)
454 194 : CALL section_vals_val_get(metavar_section, "SCALE", i_rep_section=icol, r_val=metavar%delta_s)
455 : ! Walls
456 194 : wall_section => section_vals_get_subs_vals(metavar_section, "WALL", i_rep_section=icol)
457 194 : CALL section_vals_get(wall_section, n_repetition=n_walls)
458 194 : IF (n_walls /= 0) THEN
459 36 : metavar%do_wall = .TRUE.
460 154 : ALLOCATE (metavar%walls(n_walls))
461 82 : DO i = 1, n_walls
462 46 : CALL section_vals_val_get(wall_section, "TYPE", i_rep_section=i, i_val=metavar%walls(i)%id_type)
463 46 : CALL section_vals_val_get(wall_section, "POSITION", i_rep_section=i, r_val=metavar%walls(i)%pos)
464 36 : SELECT CASE (metavar%walls(i)%id_type)
465 : CASE (do_wall_none)
466 : ! Just cycle..
467 8 : CYCLE
468 : CASE (do_wall_reflective)
469 8 : work_section => section_vals_get_subs_vals(wall_section, "REFLECTIVE", i_rep_section=i)
470 8 : CALL section_vals_val_get(work_section, "DIRECTION", i_val=metavar%walls(i)%id_direction)
471 : CASE (do_wall_quadratic)
472 24 : work_section => section_vals_get_subs_vals(wall_section, "QUADRATIC", i_rep_section=i)
473 24 : CALL section_vals_val_get(work_section, "DIRECTION", i_val=metavar%walls(i)%id_direction)
474 24 : CALL section_vals_val_get(work_section, "K", r_val=metavar%walls(i)%k_quadratic)
475 : CASE (do_wall_quartic)
476 4 : work_section => section_vals_get_subs_vals(wall_section, "QUARTIC", i_rep_section=i)
477 4 : CALL section_vals_val_get(work_section, "DIRECTION", i_val=metavar%walls(i)%id_direction)
478 4 : CALL section_vals_val_get(work_section, "K", r_val=metavar%walls(i)%k_quartic)
479 12 : SELECT CASE (metavar%walls(i)%id_direction)
480 : CASE (do_wall_m)
481 2 : metavar%walls(i)%pos0 = metavar%walls(i)%pos + (0.05_dp/metavar%walls(i)%k_quartic**(0.25_dp))
482 : CASE (do_wall_p)
483 4 : metavar%walls(i)%pos0 = metavar%walls(i)%pos - (0.05_dp/metavar%walls(i)%k_quartic**(0.25_dp))
484 : END SELECT
485 : CASE (do_wall_gaussian)
486 6 : work_section => section_vals_get_subs_vals(wall_section, "GAUSSIAN", i_rep_section=i)
487 6 : CALL section_vals_val_get(work_section, "WW", r_val=metavar%walls(i)%ww_gauss)
488 52 : CALL section_vals_val_get(work_section, "SIGMA", r_val=metavar%walls(i)%sigma_gauss)
489 : END SELECT
490 : END DO
491 : END IF
492 : ! Setup few more parameters for extended lagrangian
493 194 : IF (extended_lagrange) THEN
494 78 : CALL section_vals_val_get(metavar_section, "MASS", i_rep_section=icol, r_val=metavar%mass)
495 78 : CALL section_vals_val_get(metavar_section, "LAMBDA", i_rep_section=icol, r_val=metavar%lambda)
496 78 : IF (langevin) THEN
497 10 : CALL section_vals_val_get(metavar_section, "GAMMA", i_rep_section=icol, r_val=metavar%gamma)
498 : END IF
499 : END IF
500 :
501 194 : CALL timestop(handle)
502 :
503 194 : END SUBROUTINE metavar_read
504 :
505 : ! **************************************************************************************************
506 : !> \brief Synchronize with the rest of the walkers
507 : !> \param multiple_walkers ...
508 : !> \param hills_env ...
509 : !> \param colvars ...
510 : !> \param n_colvar ...
511 : !> \param metadyn_section ...
512 : !> \author Teodoro Laino [tlaino] - University of Zurich - 10.2008
513 : ! **************************************************************************************************
514 132 : SUBROUTINE synchronize_multiple_walkers(multiple_walkers, hills_env, colvars, &
515 : n_colvar, metadyn_section)
516 : TYPE(multiple_walkers_type), POINTER :: multiple_walkers
517 : TYPE(hills_env_type), POINTER :: hills_env
518 : TYPE(metavar_type), DIMENSION(:), POINTER :: colvars
519 : INTEGER, INTENT(IN) :: n_colvar
520 : TYPE(section_vals_type), POINTER :: metadyn_section
521 :
522 : CHARACTER(len=*), PARAMETER :: routineN = 'synchronize_multiple_walkers'
523 :
524 : CHARACTER(LEN=default_path_length) :: filename, tmpname
525 : INTEGER :: delta_hills, handle, i, i_hills, ih, iw, &
526 : unit_nr
527 : LOGICAL :: exist
528 : REAL(KIND=dp) :: invdt, ww
529 132 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:) :: delta_s_save, ss0_save
530 132 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :) :: delta_s_ss0_buf
531 : TYPE(cp_logger_type), POINTER :: logger
532 : TYPE(mp_para_env_type), POINTER :: para_env
533 :
534 132 : CALL timeset(routineN, handle)
535 :
536 132 : logger => cp_get_default_logger()
537 132 : para_env => logger%para_env
538 :
539 : ! Locally dump information on file..
540 132 : IF (para_env%is_source()) THEN
541 : ! Generate file name for the specific Hill
542 66 : i = multiple_walkers%walker_id
543 : filename = TRIM(multiple_walkers%walkers_file_name(i))//"_"// &
544 66 : TRIM(ADJUSTL(cp_to_string(multiple_walkers%n_hills_local)))
545 66 : tmpname = TRIM(filename)//".tmp"
546 : CALL open_file(file_name=tmpname, file_status="UNKNOWN", &
547 : file_form="FORMATTED", file_action="WRITE", &
548 66 : file_position="APPEND", unit_number=unit_nr)
549 66 : WRITE (unit_nr, *) hills_env%ww_history(hills_env%n_hills)
550 132 : DO ih = 1, n_colvar
551 66 : WRITE (unit_nr, *) hills_env%ss_history(ih, hills_env%n_hills)
552 132 : WRITE (unit_nr, *) hills_env%delta_s_history(ih, hills_env%n_hills)
553 : END DO
554 66 : IF (hills_env%wtcontrol) WRITE (unit_nr, *) hills_env%invdt_history(hills_env%n_hills)
555 66 : CALL close_file(unit_nr)
556 66 : CALL m_mov(tmpname, filename)
557 : END IF
558 :
559 132 : IF (MODULO(multiple_walkers%n_hills_local, multiple_walkers%walkers_freq_comm) == 0) THEN
560 : ! Store colvars information
561 396 : ALLOCATE (ss0_save(n_colvar))
562 264 : ALLOCATE (delta_s_save(n_colvar))
563 396 : ALLOCATE (delta_s_ss0_buf(2, 0:n_colvar))
564 132 : delta_s_ss0_buf = 0
565 264 : DO i = 1, n_colvar
566 132 : ss0_save(i) = colvars(i)%ss0
567 264 : delta_s_save(i) = colvars(i)%delta_s
568 : END DO
569 :
570 : ! Watch for other walkers's file and update
571 396 : DO i = 1, multiple_walkers%walkers_tot_nr
572 264 : IF (i == multiple_walkers%walker_id) THEN
573 : ! Update local counter
574 132 : multiple_walkers%walkers_status(i) = multiple_walkers%n_hills_local
575 132 : CYCLE
576 : END IF
577 :
578 132 : i_hills = multiple_walkers%walkers_status(i) + 1
579 : filename = TRIM(multiple_walkers%walkers_file_name(i))//"_"// &
580 132 : TRIM(ADJUSTL(cp_to_string(i_hills)))
581 :
582 132 : IF (para_env%is_source()) THEN
583 66 : INQUIRE (FILE=TRIM(filename), EXIST=exist)
584 : END IF
585 132 : CALL para_env%bcast(exist)
586 230 : DO WHILE (exist)
587 : ! Read information from the walker's file
588 : ! We shouldn't care too much about the concurrency of these I/O instructions..
589 : ! In case, they can be fixed in the future..
590 98 : IF (para_env%is_source()) THEN
591 : CALL open_file(file_name=filename, file_status="OLD", &
592 : file_form="FORMATTED", file_action="READ", &
593 49 : file_position="REWIND", unit_number=unit_nr)
594 49 : READ (unit_nr, *) delta_s_ss0_buf(1, 0)
595 98 : DO ih = 1, n_colvar
596 49 : READ (unit_nr, *) delta_s_ss0_buf(1, ih)
597 98 : READ (unit_nr, *) delta_s_ss0_buf(2, ih)
598 : END DO
599 49 : IF (hills_env%wtcontrol) READ (unit_nr, *) delta_s_ss0_buf(2, 0)
600 49 : CALL close_file(unit_nr)
601 : END IF
602 98 : CALL para_env%bcast(delta_s_ss0_buf)
603 98 : ww = delta_s_ss0_buf(1, 0)
604 98 : IF (hills_env%wtcontrol) invdt = delta_s_ss0_buf(2, 0)
605 196 : DO ih = 1, n_colvar
606 98 : colvars(ih)%ss0 = delta_s_ss0_buf(1, ih)
607 196 : colvars(ih)%delta_s = delta_s_ss0_buf(2, ih)
608 : END DO
609 :
610 : ! Add this hill to the history dependent terms
611 98 : IF (hills_env%wtcontrol) THEN
612 0 : CALL add_hill_single(hills_env, colvars, ww, hills_env%n_hills, n_colvar, invdt=invdt)
613 : ELSE
614 98 : CALL add_hill_single(hills_env, colvars, ww, hills_env%n_hills, n_colvar)
615 : END IF
616 :
617 98 : i_hills = i_hills + 1
618 : filename = TRIM(multiple_walkers%walkers_file_name(i))//"_"// &
619 98 : TRIM(ADJUSTL(cp_to_string(i_hills)))
620 98 : IF (para_env%is_source()) THEN
621 49 : INQUIRE (FILE=TRIM(filename), EXIST=exist)
622 : END IF
623 230 : CALL para_env%bcast(exist)
624 : END DO
625 :
626 132 : delta_hills = i_hills - 1 - multiple_walkers%walkers_status(i)
627 132 : multiple_walkers%walkers_status(i) = i_hills - 1
628 : iw = cp_print_key_unit_nr(logger, metadyn_section, "PRINT%PROGRAM_RUN_INFO", &
629 132 : extension=".metadynLog")
630 132 : IF (iw > 0) THEN
631 66 : WRITE (iw, '(T2,A,I0,A,I0,A,I0,A)') 'WALKERS| Walker #', i, '. Reading [', delta_hills, &
632 132 : '] Hills. Total number of Hills acquired [', multiple_walkers%walkers_status(i), ']'
633 : END IF
634 : CALL cp_print_key_finished_output(iw, logger, metadyn_section, &
635 264 : "PRINT%PROGRAM_RUN_INFO")
636 : END DO
637 :
638 : ! Restore colvars information
639 264 : DO i = 1, n_colvar
640 132 : colvars(i)%ss0 = ss0_save(i)
641 264 : colvars(i)%delta_s = delta_s_save(i)
642 : END DO
643 132 : DEALLOCATE (ss0_save)
644 132 : DEALLOCATE (delta_s_save)
645 : END IF
646 :
647 132 : CALL timestop(handle)
648 :
649 132 : END SUBROUTINE synchronize_multiple_walkers
650 :
651 : ! **************************************************************************************************
652 : !> \brief Add a single Hill
653 : !> \param hills_env ...
654 : !> \param colvars ...
655 : !> \param ww ...
656 : !> \param n_hills ...
657 : !> \param n_colvar ...
658 : !> \param invdt ...
659 : !> \author Teodoro Laino [tlaino] - University of Zurich - 10.2008
660 : ! **************************************************************************************************
661 1234 : SUBROUTINE add_hill_single(hills_env, colvars, ww, n_hills, n_colvar, invdt)
662 : TYPE(hills_env_type), POINTER :: hills_env
663 : TYPE(metavar_type), DIMENSION(:), POINTER :: colvars
664 : REAL(KIND=dp), INTENT(IN) :: ww
665 : INTEGER, INTENT(INOUT) :: n_hills
666 : INTEGER, INTENT(IN) :: n_colvar
667 : REAL(KIND=dp), INTENT(IN), OPTIONAL :: invdt
668 :
669 : CHARACTER(len=*), PARAMETER :: routineN = 'add_hill_single'
670 :
671 : INTEGER :: handle, i
672 : LOGICAL :: wtcontrol
673 1234 : REAL(KIND=dp), DIMENSION(:), POINTER :: tnp
674 1234 : REAL(KIND=dp), DIMENSION(:, :), POINTER :: tmp
675 :
676 1234 : CALL timeset(routineN, handle)
677 :
678 1234 : wtcontrol = PRESENT(invdt)
679 1234 : NULLIFY (tmp, tnp)
680 1234 : IF (SIZE(hills_env%ss_history, 2) < n_hills + 1) THEN
681 464 : ALLOCATE (tmp(n_colvar, n_hills + 100))
682 840 : tmp(:, :n_hills) = hills_env%ss_history
683 26916 : tmp(:, n_hills + 1:) = 0.0_dp
684 116 : DEALLOCATE (hills_env%ss_history)
685 116 : hills_env%ss_history => tmp
686 116 : NULLIFY (tmp)
687 : END IF
688 1234 : IF (SIZE(hills_env%delta_s_history, 2) < n_hills + 1) THEN
689 464 : ALLOCATE (tmp(n_colvar, n_hills + 100))
690 840 : tmp(:, :n_hills) = hills_env%delta_s_history
691 26916 : tmp(:, n_hills + 1:) = 0.0_dp
692 116 : DEALLOCATE (hills_env%delta_s_history)
693 116 : hills_env%delta_s_history => tmp
694 116 : NULLIFY (tmp)
695 : END IF
696 1234 : IF (SIZE(hills_env%ww_history) < n_hills + 1) THEN
697 348 : ALLOCATE (tnp(n_hills + 100))
698 504 : tnp(1:n_hills) = hills_env%ww_history
699 11716 : tnp(n_hills + 1:) = 0.0_dp
700 116 : DEALLOCATE (hills_env%ww_history)
701 116 : hills_env%ww_history => tnp
702 116 : NULLIFY (tnp)
703 : END IF
704 1234 : IF (wtcontrol) THEN
705 4 : IF (SIZE(hills_env%invdt_history) < n_hills + 1) THEN
706 6 : ALLOCATE (tnp(n_hills + 100))
707 4 : tnp(1:n_hills) = hills_env%invdt_history
708 202 : tnp(n_hills + 1:) = 0.0_dp
709 2 : DEALLOCATE (hills_env%invdt_history)
710 2 : hills_env%invdt_history => tnp
711 2 : NULLIFY (tnp)
712 : END IF
713 : END IF
714 1234 : n_hills = n_hills + 1
715 : ! Now add the hill
716 2748 : DO i = 1, n_colvar
717 1514 : hills_env%ss_history(i, n_hills) = colvars(i)%ss0
718 2748 : hills_env%delta_s_history(i, n_hills) = colvars(i)%delta_s
719 : END DO
720 1234 : hills_env%ww_history(n_hills) = ww
721 1234 : IF (wtcontrol) hills_env%invdt_history(n_hills) = invdt
722 :
723 1234 : CALL timestop(handle)
724 :
725 1234 : END SUBROUTINE add_hill_single
726 :
727 : ! **************************************************************************************************
728 : !> \brief Restart Hills Information
729 : !> \param ss_history ...
730 : !> \param delta_s_history ...
731 : !> \param ww_history ...
732 : !> \param ww ...
733 : !> \param n_hills ...
734 : !> \param n_colvar ...
735 : !> \param colvars ...
736 : !> \param metadyn_section ...
737 : !> \param invdt_history ...
738 : !> \author Teodoro Laino [tlaino] - University of Zurich - 10.2008
739 : ! **************************************************************************************************
740 240 : SUBROUTINE restart_hills(ss_history, delta_s_history, ww_history, ww, &
741 : n_hills, n_colvar, colvars, metadyn_section, invdt_history)
742 : REAL(KIND=dp), DIMENSION(:, :), POINTER :: ss_history, delta_s_history
743 : REAL(KIND=dp), DIMENSION(:), POINTER :: ww_history
744 : REAL(KIND=dp) :: ww
745 : INTEGER, INTENT(IN) :: n_hills, n_colvar
746 : TYPE(metavar_type), DIMENSION(:), POINTER :: colvars
747 : TYPE(section_vals_type), POINTER :: metadyn_section
748 : REAL(KIND=dp), DIMENSION(:), OPTIONAL, POINTER :: invdt_history
749 :
750 : CHARACTER(len=*), PARAMETER :: routineN = 'restart_hills'
751 :
752 : INTEGER :: handle, i, j, ndum
753 : LOGICAL :: explicit, wtcontrol
754 : REAL(KIND=dp) :: rval
755 120 : REAL(KIND=dp), DIMENSION(:), POINTER :: rvals
756 : TYPE(section_vals_type), POINTER :: hills_history
757 :
758 120 : CALL timeset(routineN, handle)
759 :
760 120 : wtcontrol = PRESENT(invdt_history)
761 120 : NULLIFY (rvals)
762 120 : hills_history => section_vals_get_subs_vals(metadyn_section, "SPAWNED_HILLS_POS")
763 120 : CALL section_vals_get(hills_history, explicit=explicit)
764 120 : IF (explicit) THEN
765 18 : CALL section_vals_val_get(hills_history, "_DEFAULT_KEYWORD_", n_rep_val=ndum)
766 : ! ss_history, delta_s_history, ww_history, invdt_history : deallocate and reallocate with the proper size
767 18 : DEALLOCATE (ss_history)
768 18 : DEALLOCATE (delta_s_history)
769 18 : DEALLOCATE (ww_history)
770 18 : IF (wtcontrol) THEN
771 0 : DEALLOCATE (invdt_history)
772 : END IF
773 : !
774 18 : CPASSERT(n_hills == ndum)
775 72 : ALLOCATE (ss_history(n_colvar, n_hills))
776 54 : ALLOCATE (delta_s_history(n_colvar, n_hills))
777 54 : ALLOCATE (ww_history(n_hills))
778 18 : IF (wtcontrol) THEN
779 0 : ALLOCATE (invdt_history(n_hills))
780 : END IF
781 : !
782 162 : DO i = 1, n_hills
783 : CALL section_vals_val_get(hills_history, "_DEFAULT_KEYWORD_", &
784 144 : i_rep_val=i, r_vals=rvals)
785 144 : CPASSERT(SIZE(rvals) == n_colvar)
786 658 : ss_history(1:n_colvar, i) = rvals
787 : END DO
788 : !
789 18 : hills_history => section_vals_get_subs_vals(metadyn_section, "SPAWNED_HILLS_SCALE")
790 18 : CALL section_vals_get(hills_history, explicit=explicit)
791 18 : IF (explicit) THEN
792 : ! delta_s_history
793 18 : CALL section_vals_val_get(hills_history, "_DEFAULT_KEYWORD_", n_rep_val=ndum)
794 18 : CPASSERT(n_hills == ndum)
795 162 : DO i = 1, n_hills
796 : CALL section_vals_val_get(hills_history, "_DEFAULT_KEYWORD_", &
797 144 : i_rep_val=i, r_vals=rvals)
798 144 : CPASSERT(SIZE(rvals) == n_colvar)
799 658 : delta_s_history(1:n_colvar, i) = rvals
800 : END DO
801 : ELSE
802 : CALL cp_warn(__LOCATION__, &
803 : "Section SPAWNED_HILLS_SCALE is not present! Setting the scales of the "// &
804 0 : "restarted hills according the parameters specified in the input file.")
805 0 : DO i = 1, n_hills
806 0 : DO j = 1, n_colvar
807 0 : delta_s_history(j, i) = colvars(i)%delta_s
808 : END DO
809 : END DO
810 : END IF
811 : !
812 18 : hills_history => section_vals_get_subs_vals(metadyn_section, "SPAWNED_HILLS_HEIGHT")
813 18 : CALL section_vals_get(hills_history, explicit=explicit)
814 18 : IF (explicit) THEN
815 : ! ww_history
816 : CALL section_vals_val_get(hills_history, "_DEFAULT_KEYWORD_", &
817 18 : n_rep_val=ndum)
818 18 : CPASSERT(n_hills == ndum)
819 162 : DO i = 1, n_hills
820 : CALL section_vals_val_get(hills_history, "_DEFAULT_KEYWORD_", &
821 144 : i_rep_val=i, r_val=rval)
822 144 : CPASSERT(SIZE(rvals) == n_colvar)
823 306 : ww_history(i) = rval
824 : END DO
825 : ELSE
826 : CALL cp_warn(__LOCATION__, &
827 : "Section SPAWNED_HILLS_HEIGHT is not present! Setting the height of the"// &
828 0 : " restarted hills according the parameters specified in the input file. ")
829 0 : ww_history = ww
830 : END IF
831 : !
832 18 : hills_history => section_vals_get_subs_vals(metadyn_section, "SPAWNED_HILLS_INVDT")
833 18 : CALL section_vals_get(hills_history, explicit=explicit)
834 72 : IF (wtcontrol) THEN
835 0 : IF (explicit) THEN
836 : ! invdt_history
837 : CALL section_vals_val_get(hills_history, "_DEFAULT_KEYWORD_", &
838 0 : n_rep_val=ndum)
839 0 : CPASSERT(n_hills == ndum)
840 0 : DO i = 1, n_hills
841 : CALL section_vals_val_get(hills_history, "_DEFAULT_KEYWORD_", &
842 0 : i_rep_val=i, r_val=rval)
843 0 : CPASSERT(SIZE(rvals) == n_colvar)
844 0 : invdt_history(i) = rval
845 : END DO
846 : ELSE
847 : CALL cp_warn(__LOCATION__, &
848 : "Section SPAWNED_HILLS_INVDT is not present! Restarting from standard"// &
849 0 : " metadynamics run i.e. setting 1/(Delta T) equal to zero. ")
850 0 : invdt_history = 0._dp
851 : END IF
852 : ELSE
853 18 : IF (explicit) THEN
854 : CALL cp_abort(__LOCATION__, &
855 : "Found section SPAWNED_HILLS_INVDT while restarting a standard metadynamics run..."// &
856 0 : " Cannot restart metadynamics from well-tempered MetaD runs. ")
857 : END IF
858 : END IF
859 : END IF
860 :
861 120 : CALL timestop(handle)
862 :
863 120 : END SUBROUTINE restart_hills
864 :
865 : ! **************************************************************************************************
866 : !> \brief Retrieves the iteration level for the metadynamics loop
867 : !> \param meta_env ...
868 : !> \param iter_nr ...
869 : !> \author Teodoro Laino [tlaino] - University of Zurich - 10.2008
870 : ! **************************************************************************************************
871 12436 : SUBROUTINE get_meta_iter_level(meta_env, iter_nr)
872 : TYPE(meta_env_type), POINTER :: meta_env
873 : INTEGER, INTENT(OUT) :: iter_nr
874 :
875 12436 : IF (meta_env%do_multiple_walkers) THEN
876 540 : iter_nr = meta_env%multiple_walkers%n_hills_local
877 : ELSE
878 11896 : iter_nr = meta_env%hills_env%n_hills
879 : END IF
880 :
881 12436 : END SUBROUTINE get_meta_iter_level
882 :
883 : ! **************************************************************************************************
884 : !> \brief ...
885 : !> \param meta_env ...
886 : !> \par History
887 : !> 11.2007 [created] [tlaino]
888 : !> \author Teodoro Laino - University of Zurich - 11.2007
889 : ! **************************************************************************************************
890 13950 : SUBROUTINE meta_walls(meta_env)
891 : TYPE(meta_env_type), POINTER :: meta_env
892 :
893 : INTEGER :: ih, iwall
894 : REAL(dp) :: ddp, delta_s, dfunc, diff_ss, dp2, &
895 : efunc, ww
896 13950 : TYPE(metavar_type), DIMENSION(:), POINTER :: colvars
897 :
898 13950 : colvars => meta_env%metavar
899 : ! Forces from the Walls
900 28644 : DO ih = 1, SIZE(colvars)
901 28644 : IF (colvars(ih)%do_wall) THEN
902 11276 : colvars(ih)%epot_walls = 0.0_dp
903 11276 : colvars(ih)%ff_walls = 0.0_dp
904 23162 : DO iwall = 1, SIZE(colvars(ih)%walls)
905 11276 : SELECT CASE (colvars(ih)%walls(iwall)%id_type)
906 : CASE (do_wall_reflective, do_wall_none)
907 : ! Do Nothing.. treated in the main metadyn function
908 10564 : CYCLE
909 : CASE (do_wall_quadratic)
910 10564 : diff_ss = colvars(ih)%ss0 - colvars(ih)%walls(iwall)%pos
911 10564 : IF (colvars(ih)%periodic) THEN
912 : ! The difference of a periodic COLVAR is always within [-pi,pi]
913 0 : diff_ss = SIGN(1.0_dp, ASIN(SIN(diff_ss)))*ACOS(COS(diff_ss))
914 : END IF
915 10564 : efunc = colvars(ih)%walls(iwall)%k_quadratic*diff_ss**2
916 10564 : dfunc = 2.0_dp*colvars(ih)%walls(iwall)%k_quadratic*diff_ss
917 21084 : SELECT CASE (colvars(ih)%walls(iwall)%id_direction)
918 : CASE (do_wall_p)
919 10316 : IF (diff_ss > 0.0_dp) THEN
920 170 : colvars(ih)%ff_walls = colvars(ih)%ff_walls - dfunc
921 170 : colvars(ih)%epot_walls = colvars(ih)%epot_walls + efunc
922 : END IF
923 : CASE (do_wall_m)
924 10564 : IF (diff_ss < 0.0_dp) THEN
925 30 : colvars(ih)%ff_walls = colvars(ih)%ff_walls - dfunc
926 30 : colvars(ih)%epot_walls = colvars(ih)%epot_walls + efunc
927 : END IF
928 : END SELECT
929 : CASE (do_wall_quartic)
930 204 : diff_ss = colvars(ih)%ss0 - colvars(ih)%walls(iwall)%pos0
931 204 : IF (colvars(ih)%periodic) THEN
932 : ! The difference of a periodic COLVAR is always within [-pi,pi]
933 0 : diff_ss = SIGN(1.0_dp, ASIN(SIN(diff_ss)))*ACOS(COS(diff_ss))
934 : END IF
935 204 : efunc = colvars(ih)%walls(iwall)%k_quartic*diff_ss*diff_ss**4
936 204 : dfunc = 4.0_dp*colvars(ih)%walls(iwall)%k_quartic*diff_ss**3
937 812 : SELECT CASE (colvars(ih)%walls(iwall)%id_direction)
938 : CASE (do_wall_p)
939 102 : IF (diff_ss > 0.0_dp) THEN
940 46 : colvars(ih)%ff_walls = colvars(ih)%ff_walls - dfunc
941 46 : colvars(ih)%epot_walls = colvars(ih)%epot_walls + efunc
942 : END IF
943 : CASE (do_wall_m)
944 204 : IF (diff_ss < 0.0_dp) THEN
945 54 : colvars(ih)%ff_walls = colvars(ih)%ff_walls - dfunc
946 54 : colvars(ih)%epot_walls = colvars(ih)%epot_walls + efunc
947 : END IF
948 : END SELECT
949 : CASE (do_wall_gaussian)
950 506 : diff_ss = colvars(ih)%ss0 - colvars(ih)%walls(iwall)%pos
951 506 : IF (colvars(ih)%periodic) THEN
952 : ! The difference of a periodic COLVAR is always within [-pi,pi]
953 0 : diff_ss = SIGN(1.0_dp, ASIN(SIN(diff_ss)))*ACOS(COS(diff_ss))
954 : END IF
955 506 : ww = colvars(ih)%walls(iwall)%ww_gauss
956 506 : delta_s = colvars(ih)%walls(iwall)%sigma_gauss
957 506 : ddp = (diff_ss)/delta_s
958 506 : dp2 = ddp**2
959 506 : efunc = ww*EXP(-0.5_dp*dp2)
960 506 : dfunc = -efunc*ddp/delta_s
961 506 : colvars(ih)%ff_walls = colvars(ih)%ff_walls - dfunc
962 12392 : colvars(ih)%epot_walls = colvars(ih)%epot_walls + efunc
963 : END SELECT
964 : END DO
965 : END IF
966 : END DO
967 13950 : END SUBROUTINE meta_walls
968 :
969 : END MODULE metadynamics_utils
|