Line data Source code
1 : !--------------------------------------------------------------------------------------------------!
2 : ! CP2K: A general program to perform molecular dynamics simulations !
3 : ! Copyright 2000-2024 CP2K developers group <https://cp2k.org> !
4 : ! !
5 : ! SPDX-License-Identifier: GPL-2.0-or-later !
6 : !--------------------------------------------------------------------------------------------------!
7 :
8 : ! **************************************************************************************************
9 : !> \brief defines types for metadynamics calculation
10 : !> \par History
11 : !> 01.2005 created [fawzi and ale]
12 : ! **************************************************************************************************
13 : MODULE metadynamics_types
14 : USE input_section_types, ONLY: section_vals_type,&
15 : section_vals_val_get
16 : USE kinds, ONLY: default_path_length,&
17 : dp
18 : USE message_passing, ONLY: mp_para_env_release,&
19 : mp_para_env_type
20 : USE parallel_rng_types, ONLY: rng_stream_type
21 : #include "./base/base_uses.f90"
22 :
23 : IMPLICIT NONE
24 :
25 : PRIVATE
26 :
27 : CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'metadynamics_types'
28 :
29 : PUBLIC :: metadyn_create, &
30 : hills_env_type, &
31 : meta_env_type, &
32 : set_meta_env, &
33 : meta_env_release, &
34 : metavar_type, &
35 : multiple_walkers_type
36 :
37 : ! **************************************************************************************************
38 : !> \brief defines types for HILLS
39 : ! **************************************************************************************************
40 : TYPE hills_env_type
41 : LOGICAL :: restart = .FALSE., slow_growth = .FALSE., wtcontrol = .FALSE.
42 : !RG Adaptive hills
43 : REAL(KIND=dp) :: ww = 0.0_dp, min_disp = 0.0_dp, energy = 0.0_dp
44 : INTEGER :: n_hills = -1, nt_hills = -1, min_nt_hills = -1
45 : INTEGER :: old_hill_number = -1, old_hill_step = -1
46 : !RG Adaptive hills
47 : REAL(KIND=dp), DIMENSION(:, :), POINTER :: ss_history => NULL()
48 : REAL(KIND=dp), DIMENSION(:, :), POINTER :: delta_s_history => NULL()
49 : REAL(KIND=dp), DIMENSION(:), POINTER :: ww_history => NULL()
50 : REAL(KIND=dp), DIMENSION(:), POINTER :: invdt_history => NULL()
51 : !Hills tail damping
52 : REAL(KIND=dp) :: tail_cutoff = 0.0_dp
53 : INTEGER :: p_exp = -1, q_exp = -1
54 : END TYPE hills_env_type
55 :
56 : ! **************************************************************************************************
57 : !> \brief defines types for WALLS
58 : ! **************************************************************************************************
59 : TYPE wall_type
60 : INTEGER :: id_type = -1, id_direction = -1
61 : REAL(KIND=dp) :: pos = 0.0_dp, pos0 = 0.0_dp
62 : REAL(KIND=dp) :: k_quadratic = 0.0_dp, k_quartic = 0.0_dp, &
63 : ww_gauss = 0.0_dp, sigma_gauss = 0.0_dp
64 : END TYPE wall_type
65 :
66 : ! **************************************************************************************************
67 : !> \brief defines types for COLVAR used in the metadynamics
68 : ! **************************************************************************************************
69 : TYPE metavar_type
70 : INTEGER :: icolvar = -1
71 : LOGICAL :: do_wall = .FALSE., periodic = .FALSE.
72 : REAL(KIND=dp) :: mass = 0.0_dp, lambda = 0.0_dp, vvp = 0.0_dp
73 : REAL(KIND=dp) :: gamma = 0.0_dp
74 : REAL(KIND=dp) :: epot_s = 0.0_dp, delta_s = 0.0_dp, epot_walls = 0.0_dp
75 : REAL(KIND=dp) :: ss = 0.0_dp, ss0 = 0.0_dp, ff_s = 0.0_dp, ff_hills = 0.0_dp, ff_walls = 0.0_dp
76 : TYPE(wall_type), DIMENSION(:), POINTER :: walls => NULL()
77 : END TYPE metavar_type
78 :
79 : ! **************************************************************************************************
80 : !> \brief defines types for multiple walkers run
81 : ! **************************************************************************************************
82 : TYPE multiple_walkers_type
83 : INTEGER :: n_hills_local = -1
84 : INTEGER :: walker_id = -1
85 : INTEGER :: walkers_tot_nr = -1
86 : INTEGER :: walkers_freq_comm = -1
87 : INTEGER, DIMENSION(:), POINTER :: walkers_status => NULL()
88 : CHARACTER(LEN=default_path_length), &
89 : DIMENSION(:), POINTER :: walkers_file_name => NULL()
90 : END TYPE multiple_walkers_type
91 :
92 : ! **************************************************************************************************
93 : !> \brief defines meta_env type
94 : ! **************************************************************************************************
95 : TYPE meta_env_type
96 : LOGICAL :: do_hills = .FALSE., do_multiple_walkers = .FALSE.
97 : LOGICAL :: extended_lagrange = .FALSE.
98 : LOGICAL :: well_tempered = .FALSE.
99 : LOGICAL :: langevin = .FALSE.
100 : LOGICAL :: use_plumed = .FALSE.
101 : CHARACTER(LEN=default_path_length) :: plumed_input_file = ""
102 : INTEGER :: n_colvar = -1
103 : REAL(KIND=dp) :: ekin_s = 0.0_dp, epot_s = 0.0_dp, dt = 0.0_dp, &
104 : avg_temp = 0.0_dp, epot_walls = 0.0_dp
105 : LOGICAL :: tempcontrol = .FALSE., restart = .FALSE.
106 : REAL(KIND=dp) :: temp_wanted = 0.0_dp, toll_temp = 0.0_dp
107 : REAL(KIND=dp) :: delta_t = 0.0_dp, invdt = 0.0_dp, &
108 : wtgamma = 0.0_dp, wttemperature = 0.0_dp
109 : INTEGER :: n_steps = -1
110 : ! time pointer should never be allocated itself.. that's a quite bad
111 : ! choice derived from the md_env.. So whenever the meta_env type is
112 : ! used the pointer time should be pointer to the high level time counter
113 : REAL(KIND=dp), POINTER :: time => NULL()
114 : TYPE(hills_env_type), POINTER :: hills_env => NULL()
115 : TYPE(metavar_type), POINTER, DIMENSION(:) :: metavar => NULL()
116 : TYPE(multiple_walkers_type), POINTER :: multiple_walkers => NULL()
117 : TYPE(mp_para_env_type), POINTER :: para_env => NULL()
118 : TYPE(section_vals_type), POINTER :: metadyn_section => NULL()
119 : TYPE(rng_stream_type), DIMENSION(:), &
120 : ALLOCATABLE :: rng
121 : INTEGER :: TAMCSteps = -1
122 : REAL(kind=dp) :: zdt = 0.0_dp
123 : END TYPE meta_env_type
124 :
125 : CONTAINS
126 :
127 : ! **************************************************************************************************
128 : !> \brief allocates a metadynamic environment (performs only minimal
129 : !> initialization)
130 : !> \param meta_env the meta env_ that will be allocated
131 : !> \param n_colvar number of collectiva variables
132 : !> \param dt ...
133 : !> \param para_env ...
134 : !> \param metadyn_section ...
135 : !> \par History
136 : !> 04.2004 created
137 : !> 02.2006 Reorganized the structure of the restart for Metadynamics (teo)
138 : !> cleaned the metadynamic type
139 : !> \author - alessandro laio and fawzi mohamed
140 : !> - Teodoro Laino [tlaino] - University of Zurich. 11.2007
141 : !> - Teodoro Laino [tlaino] - University of Zurich. 10.2008
142 : !> Major rewriting and addition of multiple walkers
143 : ! **************************************************************************************************
144 150 : SUBROUTINE metadyn_create(meta_env, n_colvar, dt, para_env, metadyn_section)
145 : TYPE(meta_env_type), INTENT(OUT) :: meta_env
146 : INTEGER, INTENT(in) :: n_colvar
147 : REAL(dp), INTENT(in) :: dt
148 : TYPE(mp_para_env_type), POINTER :: para_env
149 : TYPE(section_vals_type), POINTER :: metadyn_section
150 :
151 : INTEGER :: i
152 : LOGICAL :: do_langevin
153 :
154 : NULLIFY (meta_env%multiple_walkers, &
155 : meta_env%metadyn_section, &
156 : meta_env%time, &
157 : meta_env%hills_env)
158 :
159 : meta_env%use_plumed = .FALSE.
160 150 : meta_env%plumed_input_file = ""
161 150 : meta_env%metadyn_section => metadyn_section
162 150 : meta_env%restart = .TRUE.
163 150 : meta_env%n_colvar = n_colvar
164 150 : meta_env%para_env => para_env
165 150 : CALL para_env%retain()
166 :
167 150 : meta_env%ekin_s = 0.0_dp
168 150 : meta_env%epot_s = 0.0_dp
169 150 : meta_env%epot_walls = 0.0_dp
170 150 : meta_env%n_steps = 0
171 150 : meta_env%dt = dt
172 150 : meta_env%tempcontrol = .FALSE.
173 :
174 : ! Hills_env
175 150 : ALLOCATE (meta_env%hills_env)
176 298 : ALLOCATE (meta_env%hills_env%ss_history(n_colvar, 0))
177 298 : ALLOCATE (meta_env%hills_env%delta_s_history(n_colvar, 0))
178 150 : ALLOCATE (meta_env%hills_env%ww_history(0))
179 150 : ALLOCATE (meta_env%hills_env%invdt_history(0))
180 150 : meta_env%hills_env%n_hills = 0
181 : meta_env%hills_env%energy = 0.0_dp
182 150 : meta_env%hills_env%restart = .TRUE.
183 :
184 : ! Colvar
185 638 : ALLOCATE (meta_env%metavar(n_colvar))
186 340 : DO i = 1, n_colvar
187 190 : NULLIFY (meta_env%metavar(i)%walls)
188 190 : meta_env%metavar(i)%mass = -HUGE(0.0_dp)
189 190 : meta_env%metavar(i)%lambda = -HUGE(0.0_dp)
190 190 : meta_env%metavar(i)%gamma = 0.0_dp
191 190 : meta_env%metavar(i)%ss = 0.0_dp
192 190 : meta_env%metavar(i)%ss0 = 0.0_dp
193 190 : meta_env%metavar(i)%ff_s = 0.0_dp
194 190 : meta_env%metavar(i)%vvp = 0.0_dp
195 190 : meta_env%metavar(i)%epot_s = 0.0_dp
196 190 : meta_env%metavar(i)%epot_walls = 0.0_dp
197 190 : meta_env%metavar(i)%delta_s = 0.0_dp
198 190 : meta_env%metavar(i)%ff_hills = 0.0_dp
199 190 : meta_env%metavar(i)%ff_walls = 0.0_dp
200 190 : meta_env%metavar(i)%do_wall = .FALSE.
201 190 : meta_env%metavar(i)%periodic = .FALSE.
202 340 : meta_env%metavar(i)%icolvar = 0
203 : END DO
204 :
205 : ! Multiple Walkers
206 : CALL section_vals_val_get(metadyn_section, "MULTIPLE_WALKERS%_SECTION_PARAMETERS_", &
207 150 : l_val=meta_env%do_multiple_walkers)
208 150 : IF (meta_env%do_multiple_walkers) THEN
209 8 : ALLOCATE (meta_env%multiple_walkers)
210 :
211 : ! Walkers status and Walkers file name
212 : NULLIFY (meta_env%multiple_walkers%walkers_status, &
213 : meta_env%multiple_walkers%walkers_file_name)
214 8 : meta_env%multiple_walkers%n_hills_local = 0
215 : END IF
216 :
217 150 : CALL section_vals_val_get(metadyn_section, "LANGEVIN", l_val=do_langevin)
218 150 : IF (do_langevin) THEN
219 184 : ALLOCATE (meta_env%rng(meta_env%n_colvar))
220 : END IF
221 150 : END SUBROUTINE metadyn_create
222 :
223 : ! **************************************************************************************************
224 : !> \brief sets the meta_env
225 : !> \param meta_env ...
226 : !> \param time ...
227 : !> \author alessandro laio and fawzi mohamed
228 : ! **************************************************************************************************
229 1786 : SUBROUTINE set_meta_env(meta_env, time)
230 : TYPE(meta_env_type), INTENT(IN), POINTER :: meta_env
231 : REAL(KIND=dp), OPTIONAL, POINTER :: time
232 :
233 1786 : IF (ASSOCIATED(meta_env)) THEN
234 150 : IF (PRESENT(time)) THEN
235 150 : NULLIFY (meta_env%time)
236 150 : meta_env%time => time
237 : END IF
238 : END IF
239 1786 : END SUBROUTINE set_meta_env
240 :
241 : ! **************************************************************************************************
242 : !> \brief releases the meta_env
243 : !> \param meta_env ...
244 : !> \author alessandro laio and fawzi mohamed
245 : ! **************************************************************************************************
246 150 : SUBROUTINE meta_env_release(meta_env)
247 : TYPE(meta_env_type), INTENT(INOUT) :: meta_env
248 :
249 : INTEGER :: i
250 :
251 150 : CALL mp_para_env_release(meta_env%para_env)
252 150 : IF (ASSOCIATED(meta_env%metavar)) THEN
253 340 : DO i = 1, SIZE(meta_env%metavar)
254 340 : IF (ASSOCIATED(meta_env%metavar(i)%walls)) THEN
255 36 : DEALLOCATE (meta_env%metavar(i)%walls)
256 : END IF
257 : END DO
258 150 : DEALLOCATE (meta_env%metavar)
259 : END IF
260 :
261 : ! Hills env
262 150 : CALL hills_env_release(meta_env%hills_env)
263 : ! Walkers type
264 150 : IF (ASSOCIATED(meta_env%multiple_walkers)) THEN
265 8 : IF (ASSOCIATED(meta_env%multiple_walkers%walkers_status)) THEN
266 8 : DEALLOCATE (meta_env%multiple_walkers%walkers_status)
267 : END IF
268 8 : IF (ASSOCIATED(meta_env%multiple_walkers%walkers_file_name)) THEN
269 8 : DEALLOCATE (meta_env%multiple_walkers%walkers_file_name)
270 : END IF
271 8 : DEALLOCATE (meta_env%multiple_walkers)
272 : END IF
273 :
274 : ! Langevin on COLVARS
275 150 : IF (meta_env%langevin) &
276 6 : DEALLOCATE (meta_env%rng)
277 :
278 150 : NULLIFY (meta_env%time)
279 150 : NULLIFY (meta_env%metadyn_section)
280 150 : END SUBROUTINE meta_env_release
281 :
282 : ! **************************************************************************************************
283 : !> \brief releases the hills_env
284 : !> \param hills_env ...
285 : !> \author Teodoro Laino [tlaino] - University of Zurich 10.2008
286 : ! **************************************************************************************************
287 150 : SUBROUTINE hills_env_release(hills_env)
288 : TYPE(hills_env_type), POINTER :: hills_env
289 :
290 150 : IF (ASSOCIATED(hills_env)) THEN
291 150 : IF (ASSOCIATED(hills_env%ss_history)) THEN
292 150 : DEALLOCATE (hills_env%ss_history)
293 : END IF
294 150 : IF (ASSOCIATED(hills_env%delta_s_history)) THEN
295 150 : DEALLOCATE (hills_env%delta_s_history)
296 : END IF
297 150 : IF (ASSOCIATED(hills_env%ww_history)) THEN
298 150 : DEALLOCATE (hills_env%ww_history)
299 : END IF
300 150 : IF (ASSOCIATED(hills_env%invdt_history)) THEN
301 150 : DEALLOCATE (hills_env%invdt_history)
302 : END IF
303 150 : DEALLOCATE (hills_env)
304 : END IF
305 150 : END SUBROUTINE hills_env_release
306 :
307 0 : END MODULE metadynamics_types
|