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 module provides variables for the TMC analysis tool
10 : !> \par History
11 : !> 02.2013 created [Mandes Schoenherr]
12 : !> \author Mandes
13 : ! **************************************************************************************************
14 :
15 : MODULE tmc_analysis_types
16 : USE cell_types, ONLY: cell_type
17 : USE kinds, ONLY: default_path_length,&
18 : default_string_length,&
19 : dp
20 : USE tmc_tree_types, ONLY: tree_type
21 : USE tmc_types, ONLY: tmc_atom_type
22 : #include "../base/base_uses.f90"
23 :
24 : IMPLICIT NONE
25 :
26 : PRIVATE
27 :
28 : CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'tmc_analysis_types'
29 :
30 : PUBLIC :: tmc_analysis_env, tmc_ana_list_type
31 : PUBLIC :: tmc_ana_env_create, tmc_ana_env_release
32 : PUBLIC :: tmc_ana_density_create
33 : PUBLIC :: pair_correl_type, tmc_ana_pair_correl_create, &
34 : search_pair_in_list, atom_pairs_type
35 : PUBLIC :: dipole_moment_type, tmc_ana_dipole_moment_create
36 : PUBLIC :: tmc_ana_dipole_analysis_create
37 : PUBLIC :: tmc_ana_displacement_create
38 :
39 : CHARACTER(LEN=default_path_length), PARAMETER, &
40 : PUBLIC :: tmc_ana_density_file_name = "tmc_ana_density.dat"
41 : CHARACTER(LEN=default_path_length), PARAMETER, &
42 : PUBLIC :: tmc_ana_pair_correl_file_name = "tmc_ana_g_r.dat"
43 :
44 : INTEGER, PARAMETER, PUBLIC :: ana_type_default = 0
45 : INTEGER, PARAMETER, PUBLIC :: ana_type_ice = 1
46 : INTEGER, PARAMETER, PUBLIC :: ana_type_sym_xyz = 2
47 :
48 : TYPE tmc_ana_list_type
49 : TYPE(tmc_analysis_env), POINTER :: temp => NULL()
50 : END TYPE tmc_ana_list_type
51 :
52 : TYPE tmc_analysis_env
53 : INTEGER :: io_unit = -1
54 : CHARACTER(len=default_string_length), &
55 : DIMENSION(:), POINTER :: dirs => NULL()
56 : CHARACTER(LEN=default_path_length) :: out_file_prefix = ""
57 : INTEGER :: conf_offset = 0
58 : TYPE(cell_type), POINTER :: cell => NULL()
59 : TYPE(tmc_atom_type), DIMENSION(:), POINTER :: atoms => NULL()
60 : INTEGER :: dim_per_elem = 3
61 : INTEGER :: nr_dim = -1
62 : REAL(KIND=dp) :: temperature = 0.0_dp
63 : TYPE(tree_type), POINTER :: last_elem => NULL()
64 : INTEGER :: from_elem = -1, to_elem = -1
65 : INTEGER :: id_traj = -1, id_cell = -1, id_frc = -1, id_dip = -1, id_ener = -1
66 : INTEGER :: lc_traj = 0, lc_cell = 0, lc_frc = 0, lc_dip = 0, lc_ener = 0
67 : CHARACTER(LEN=default_path_length) :: costum_pos_file_name = ""
68 : CHARACTER(LEN=default_path_length) :: costum_dip_file_name = ""
69 : CHARACTER(LEN=default_path_length) :: costum_cell_file_name = ""
70 : LOGICAL :: restart = .TRUE., restarted = .FALSE.
71 : LOGICAL :: print_test_output = .FALSE.
72 :
73 : TYPE(density_3d_type), POINTER :: density_3d => NULL()
74 : TYPE(pair_correl_type), POINTER :: pair_correl => NULL()
75 : TYPE(dipole_moment_type), POINTER :: dip_mom => NULL()
76 : TYPE(dipole_analysis_type), POINTER :: dip_ana => NULL()
77 : TYPE(displacement_type), POINTER :: displace => NULL()
78 : END TYPE tmc_analysis_env
79 :
80 : TYPE density_3d_type
81 : INTEGER :: conf_counter = 0
82 : INTEGER, DIMENSION(3) :: nr_bins = 0
83 : REAL(KIND=dp) :: sum_vol = 0.0_dp
84 : REAL(KIND=dp) :: sum_vol2 = 0.0_dp
85 : REAL(KIND=dp), DIMENSION(3) :: sum_box_length = 0.0_dp
86 : REAL(KIND=dp), DIMENSION(3) :: sum_box_length2 = 0.0_dp
87 : REAL(KIND=dp), DIMENSION(:, :, :), POINTER :: sum_density => NULL(), sum_dens2 => NULL()
88 : LOGICAL :: print_dens = .TRUE.
89 : END TYPE density_3d_type
90 :
91 : TYPE pair_correl_type
92 : INTEGER :: conf_counter = 0
93 : INTEGER :: nr_bins = 0
94 : REAL(KIND=dp) :: step_length = -1.0_dp
95 : TYPE(atom_pairs_type), DIMENSION(:), POINTER :: pairs => NULL()
96 : REAL(KIND=dp), DIMENSION(:, :), POINTER :: g_r => NULL()
97 : REAL(KIND=dp) :: sum_box_scale(3) = 0.0_dp
98 : END TYPE pair_correl_type
99 :
100 : TYPE atom_pairs_type
101 : CHARACTER(LEN=default_string_length) :: f_n = ""
102 : CHARACTER(LEN=default_string_length) :: s_n = ""
103 : INTEGER :: pair_count = 0
104 : END TYPE atom_pairs_type
105 :
106 : TYPE dipole_moment_type
107 : INTEGER :: conf_counter = 0
108 : TYPE(tmc_atom_type), DIMENSION(:), POINTER :: charges_inp => NULL()
109 : REAL(KIND=dp), DIMENSION(:), POINTER :: charges => NULL()
110 : REAL(KIND=dp), DIMENSION(:), POINTER :: last_dip_cl => NULL()
111 : LOGICAL :: print_cl_dip = .TRUE.
112 : END TYPE dipole_moment_type
113 :
114 : TYPE dipole_analysis_type
115 : REAL(KIND=dp) :: conf_counter = 0
116 : INTEGER :: ana_type = -1
117 : LOGICAL :: print_diel_const_traj = .TRUE.
118 : ! squared dipoles per volume
119 : REAL(KIND=dp) :: mu2_pv_s = 0.0_dp
120 : ! dipole per square root ov volume per direction
121 : REAL(KIND=dp), DIMENSION(:), POINTER :: mu_psv => NULL(), mu_pv => NULL(), mu2_pv => NULL()
122 : ! dipole dipole correlation matrix (per volume)
123 : REAL(KIND=dp), DIMENSION(:, :), POINTER :: mu2_pv_mat => NULL()
124 :
125 : END TYPE dipole_analysis_type
126 :
127 : TYPE displacement_type
128 : INTEGER :: conf_counter = 0
129 : REAL(KIND=dp) :: disp = 0.0_dp
130 : LOGICAL :: print_disp = .TRUE.
131 : END TYPE displacement_type
132 :
133 : CONTAINS
134 :
135 : ! **************************************************************************************************
136 : !> \brief creates a new structure environment for TMC analysis
137 : !> \param tmc_ana structure with parameters for TMC analysis
138 : !> \author Mandes 02.2013
139 : ! **************************************************************************************************
140 18 : SUBROUTINE tmc_ana_env_create(tmc_ana)
141 : TYPE(tmc_analysis_env), POINTER :: tmc_ana
142 :
143 18 : CPASSERT(.NOT. ASSOCIATED(tmc_ana))
144 :
145 18 : ALLOCATE (tmc_ana)
146 :
147 18 : END SUBROUTINE tmc_ana_env_create
148 :
149 : ! **************************************************************************************************
150 : !> \brief releases the structure environment for TMC analysis
151 : !> \param tmc_ana structure with parameters for TMC analysis
152 : !> \author Mandes 02.2013
153 : ! **************************************************************************************************
154 18 : SUBROUTINE tmc_ana_env_release(tmc_ana)
155 : TYPE(tmc_analysis_env), POINTER :: tmc_ana
156 :
157 18 : CPASSERT(ASSOCIATED(tmc_ana))
158 :
159 18 : IF (ASSOCIATED(tmc_ana%dirs)) THEN
160 18 : DEALLOCATE (tmc_ana%dirs)
161 : END IF
162 :
163 18 : IF (ASSOCIATED(tmc_ana%density_3d)) THEN
164 9 : CALL tmc_ana_dens_release(tmc_ana%density_3d)
165 : END IF
166 18 : IF (ASSOCIATED(tmc_ana%pair_correl)) THEN
167 9 : CALL tmc_ana_pair_correl_release(tmc_ana%pair_correl)
168 : END IF
169 :
170 18 : IF (ASSOCIATED(tmc_ana%dip_mom)) THEN
171 9 : CALL tmc_ana_dipole_moment_release(tmc_ana%dip_mom)
172 : END IF
173 :
174 18 : IF (ASSOCIATED(tmc_ana%dip_ana)) THEN
175 0 : CALL tmc_ana_dipole_analysis_release(tmc_ana%dip_ana)
176 : END IF
177 :
178 18 : IF (ASSOCIATED(tmc_ana%displace)) THEN
179 9 : CALL tmc_ana_displacement_release(ana_disp=tmc_ana%displace)
180 : END IF
181 :
182 18 : DEALLOCATE (tmc_ana)
183 :
184 18 : END SUBROUTINE tmc_ana_env_release
185 :
186 : !============================================================================
187 : ! density calculations
188 : !============================================================================
189 :
190 : ! **************************************************************************************************
191 : !> \brief creates a new structure environment for TMC analysis
192 : !> \param ana_dens structure with parameters for TMC density analysis
193 : !> \param nr_bins ...
194 : !> \author Mandes 02.2013
195 : ! **************************************************************************************************
196 9 : SUBROUTINE tmc_ana_density_create(ana_dens, nr_bins)
197 : TYPE(density_3d_type), POINTER :: ana_dens
198 : INTEGER, DIMENSION(3) :: nr_bins
199 :
200 9 : CPASSERT(.NOT. ASSOCIATED(ana_dens))
201 :
202 117 : ALLOCATE (ana_dens)
203 :
204 36 : ana_dens%nr_bins(:) = nr_bins(:)
205 :
206 45 : ALLOCATE (ana_dens%sum_density(nr_bins(1), nr_bins(2), nr_bins(3)))
207 36 : ALLOCATE (ana_dens%sum_dens2(nr_bins(1), nr_bins(2), nr_bins(3)))
208 45 : ana_dens%sum_density = 0.0_dp
209 45 : ana_dens%sum_dens2 = 0.0_dp
210 9 : END SUBROUTINE tmc_ana_density_create
211 :
212 : ! **************************************************************************************************
213 : !> \brief releases the structure environment for TMC analysis
214 : !> \param ana_dens structure with parameters for TMC analysis
215 : !> \author Mandes 02.2013
216 : ! **************************************************************************************************
217 9 : SUBROUTINE tmc_ana_dens_release(ana_dens)
218 : TYPE(density_3d_type), POINTER :: ana_dens
219 :
220 9 : CPASSERT(ASSOCIATED(ana_dens))
221 :
222 9 : DEALLOCATE (ana_dens%sum_density)
223 9 : DEALLOCATE (ana_dens%sum_dens2)
224 9 : DEALLOCATE (ana_dens)
225 9 : END SUBROUTINE tmc_ana_dens_release
226 :
227 : !============================================================================
228 : ! radial distribution function
229 : !============================================================================
230 :
231 : ! **************************************************************************************************
232 : !> \brief creates a new structure environment for TMC analysis
233 : !> \param ana_pair_correl ...
234 : !> \param nr_bins ...
235 : !> \param
236 : !> \author Mandes 02.2013
237 : ! **************************************************************************************************
238 9 : SUBROUTINE tmc_ana_pair_correl_create(ana_pair_correl, nr_bins)
239 : TYPE(pair_correl_type), POINTER :: ana_pair_correl
240 : INTEGER :: nr_bins
241 :
242 9 : CPASSERT(.NOT. ASSOCIATED(ana_pair_correl))
243 45 : ALLOCATE (ana_pair_correl)
244 :
245 9 : ana_pair_correl%nr_bins = nr_bins
246 9 : END SUBROUTINE tmc_ana_pair_correl_create
247 :
248 : ! **************************************************************************************************
249 : !> \brief releases the structure environment for TMC analysis
250 : !> \param ana_pair_correl ...
251 : !> \param
252 : !> \author Mandes 02.2013
253 : ! **************************************************************************************************
254 9 : SUBROUTINE tmc_ana_pair_correl_release(ana_pair_correl)
255 : TYPE(pair_correl_type), POINTER :: ana_pair_correl
256 :
257 9 : CPASSERT(ASSOCIATED(ana_pair_correl))
258 :
259 9 : DEALLOCATE (ana_pair_correl%g_r)
260 9 : DEALLOCATE (ana_pair_correl%pairs)
261 9 : DEALLOCATE (ana_pair_correl)
262 9 : END SUBROUTINE tmc_ana_pair_correl_release
263 :
264 : ! **************************************************************************************************
265 : !> \brief search the pair of two atom types in list
266 : !> \param pair_list ...
267 : !> \param n1 atom names
268 : !> \param n2 atom names
269 : !> \param list_end ...
270 : !> \return ...
271 : !> \author Mandes 02.2013
272 : ! **************************************************************************************************
273 88635 : FUNCTION search_pair_in_list(pair_list, n1, n2, list_end) RESULT(ind)
274 : TYPE(atom_pairs_type), DIMENSION(:), POINTER :: pair_list
275 : CHARACTER(LEN=default_string_length) :: n1, n2
276 : INTEGER, OPTIONAL :: list_end
277 : INTEGER :: ind
278 :
279 : INTEGER :: last, list_nr
280 :
281 88635 : CPASSERT(ASSOCIATED(pair_list))
282 88635 : IF (PRESENT(list_end)) THEN
283 1890 : CPASSERT(list_end <= SIZE(pair_list))
284 1890 : last = list_end
285 : ELSE
286 86745 : last = SIZE(pair_list)
287 : END IF
288 :
289 88635 : ind = -1
290 :
291 173962 : list_search: DO list_nr = 1, last
292 : IF ((pair_list(list_nr)%f_n == n1 .AND. &
293 173935 : pair_list(list_nr)%s_n == n2) .OR. &
294 : (pair_list(list_nr)%f_n == n2 .AND. &
295 27 : pair_list(list_nr)%s_n == n1)) THEN
296 : ind = list_nr
297 : EXIT list_search
298 : END IF
299 : END DO list_search
300 88635 : END FUNCTION search_pair_in_list
301 :
302 : !============================================================================
303 : ! classical cell dipole moment
304 : !============================================================================
305 :
306 : ! **************************************************************************************************
307 : !> \brief creates a new structure environment for TMC analysis
308 : !> \param ana_dip_mom ...
309 : !> \param charge_atm ...
310 : !> \param charge ...
311 : !> \param dim_per_elem ...
312 : !> \param
313 : !> \author Mandes 02.2013
314 : ! **************************************************************************************************
315 9 : SUBROUTINE tmc_ana_dipole_moment_create(ana_dip_mom, charge_atm, charge, &
316 : dim_per_elem)
317 : TYPE(dipole_moment_type), POINTER :: ana_dip_mom
318 : CHARACTER(LEN=default_string_length), POINTER :: charge_atm(:)
319 : REAL(KIND=dp), POINTER :: charge(:)
320 : INTEGER :: dim_per_elem
321 :
322 : INTEGER :: i
323 :
324 9 : CPASSERT(.NOT. ASSOCIATED(ana_dip_mom))
325 9 : ALLOCATE (ana_dip_mom)
326 :
327 45 : ALLOCATE (ana_dip_mom%charges_inp(SIZE(charge)))
328 27 : DO i = 1, SIZE(charge)
329 18 : ana_dip_mom%charges_inp(i)%name = charge_atm(i)
330 27 : ana_dip_mom%charges_inp(i)%mass = charge(i)
331 : END DO
332 :
333 27 : ALLOCATE (ana_dip_mom%last_dip_cl(dim_per_elem))
334 : ! still the initialization routine has to be called
335 :
336 9 : END SUBROUTINE tmc_ana_dipole_moment_create
337 :
338 : ! **************************************************************************************************
339 : !> \brief releases the structure environment for TMC analysis
340 : !> \param ana_dip_mom ...
341 : !> \param
342 : !> \author Mandes 02.2013
343 : ! **************************************************************************************************
344 9 : SUBROUTINE tmc_ana_dipole_moment_release(ana_dip_mom)
345 : TYPE(dipole_moment_type), POINTER :: ana_dip_mom
346 :
347 9 : CPASSERT(ASSOCIATED(ana_dip_mom))
348 :
349 9 : IF (ASSOCIATED(ana_dip_mom%charges_inp)) DEALLOCATE (ana_dip_mom%charges_inp)
350 9 : IF (ASSOCIATED(ana_dip_mom%charges)) DEALLOCATE (ana_dip_mom%charges)
351 9 : DEALLOCATE (ana_dip_mom%last_dip_cl)
352 9 : DEALLOCATE (ana_dip_mom)
353 9 : END SUBROUTINE tmc_ana_dipole_moment_release
354 :
355 : ! **************************************************************************************************
356 : !> \brief creates a new structure environment for TMC analysis
357 : !> \param ana_dip_ana ...
358 : !> \param
359 : !> \author Mandes 02.2013
360 : ! **************************************************************************************************
361 0 : SUBROUTINE tmc_ana_dipole_analysis_create(ana_dip_ana)
362 : TYPE(dipole_analysis_type), POINTER :: ana_dip_ana
363 :
364 0 : CPASSERT(.NOT. ASSOCIATED(ana_dip_ana))
365 0 : ALLOCATE (ana_dip_ana)
366 :
367 0 : ALLOCATE (ana_dip_ana%mu_psv(3))
368 0 : ana_dip_ana%mu_psv = 0.0_dp
369 0 : ALLOCATE (ana_dip_ana%mu_pv(3))
370 0 : ana_dip_ana%mu_pv = 0.0_dp
371 0 : ALLOCATE (ana_dip_ana%mu2_pv(3))
372 0 : ana_dip_ana%mu2_pv = 0.0_dp
373 0 : ALLOCATE (ana_dip_ana%mu2_pv_mat(3, 3))
374 0 : ana_dip_ana%mu2_pv_mat = 0.0_dp
375 0 : END SUBROUTINE tmc_ana_dipole_analysis_create
376 :
377 : ! **************************************************************************************************
378 : !> \brief releases the structure environment for TMC analysis
379 : !> \param ana_dip_ana ...
380 : !> \param
381 : !> \author Mandes 02.2013
382 : ! **************************************************************************************************
383 0 : SUBROUTINE tmc_ana_dipole_analysis_release(ana_dip_ana)
384 : TYPE(dipole_analysis_type), POINTER :: ana_dip_ana
385 :
386 0 : CPASSERT(ASSOCIATED(ana_dip_ana))
387 :
388 0 : DEALLOCATE (ana_dip_ana%mu_psv)
389 0 : DEALLOCATE (ana_dip_ana%mu_pv)
390 0 : DEALLOCATE (ana_dip_ana%mu2_pv)
391 0 : DEALLOCATE (ana_dip_ana%mu2_pv_mat)
392 :
393 0 : DEALLOCATE (ana_dip_ana)
394 0 : END SUBROUTINE tmc_ana_dipole_analysis_release
395 :
396 : !============================================================================
397 : ! particle displacement in cell (from one configuration to the next)
398 : !============================================================================
399 :
400 : ! **************************************************************************************************
401 : !> \brief creates a new structure environment for TMC analysis
402 : !> \param ana_disp ...
403 : !> \param dim_per_elem ...
404 : !> \param
405 : !> \author Mandes 02.2013
406 : ! **************************************************************************************************
407 9 : SUBROUTINE tmc_ana_displacement_create(ana_disp, dim_per_elem)
408 : TYPE(displacement_type), POINTER :: ana_disp
409 : INTEGER :: dim_per_elem
410 :
411 9 : CPASSERT(.NOT. ASSOCIATED(ana_disp))
412 9 : CPASSERT(dim_per_elem > 0)
413 : MARK_USED(dim_per_elem)
414 :
415 9 : ALLOCATE (ana_disp)
416 :
417 9 : END SUBROUTINE tmc_ana_displacement_create
418 :
419 : ! **************************************************************************************************
420 : !> \brief releases a structure environment for TMC analysis
421 : !> \param ana_disp ...
422 : !> \param
423 : !> \author Mandes 02.2013
424 : ! **************************************************************************************************
425 9 : SUBROUTINE tmc_ana_displacement_release(ana_disp)
426 : TYPE(displacement_type), POINTER :: ana_disp
427 :
428 9 : CPASSERT(ASSOCIATED(ana_disp))
429 :
430 9 : DEALLOCATE (ana_disp)
431 9 : END SUBROUTINE tmc_ana_displacement_release
432 0 : END MODULE tmc_analysis_types
|