(git:b279b6b)
tmc_move_handle.F
Go to the documentation of this file.
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 acceptance ratio handling of the different Monte Carlo Moves types
10 !> For each move type and each temperature average acceptance is
11 !> determined.
12 !> For each move is a weight (mv_weight) defined, which defines the
13 !> probability to perform the move.
14 !> We distinguish between moves performed on the exact potential
15 !> (move on the master, energy on the energy worker) and
16 !> NMC moves, which are performed on the worker using the approximate
17 !> potential. The energies are calculated as usual on the energy worker
18 !> with the exact potential.
19 !> The move probabilities to perform a NMC is stored in the NMC move.
20 !> The probilities of the single move types (performed with the
21 !> approximate potential) are only compared within the NMC move
22 !> \par History
23 !> 11.2012 created [Mandes Schoenherr]
24 !> \author Mandes
25 ! **************************************************************************************************
26 
28  USE cp_log_handling, ONLY: cp_to_string
31  section_vals_type,&
33  USE kinds, ONLY: default_string_length,&
34  dp
35  USE mathconstants, ONLY: pi
36  USE physcon, ONLY: au2a => angstrom
37  USE string_utilities, ONLY: uppercase
38  USE tmc_move_types, ONLY: &
42  USE tmc_stati, ONLY: task_type_mc,&
45  USE tmc_tree_types, ONLY: global_tree_type,&
48  tree_type
49  USE tmc_types, ONLY: tmc_param_type
50 #include "../base/base_uses.f90"
51 
52  IMPLICIT NONE
53 
54  PRIVATE
55 
56  CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'tmc_move_handle'
57 
59  PUBLIC :: check_moves
60  PUBLIC :: select_random_move_type
61  PUBLIC :: prob_update, add_mv_prob
62  PUBLIC :: clear_move_probs
63 
64 CONTAINS
65 
66 ! **************************************************************************************************
67 !> \brief initialization of the different moves, with sizes and probabilities
68 !> \param tmc_params ...
69 !> \param tmc_section ...
70 !> \author Mandes 10.2013
71 ! **************************************************************************************************
72  SUBROUTINE read_init_move_types(tmc_params, tmc_section)
73  TYPE(tmc_param_type), POINTER :: tmc_params
74  TYPE(section_vals_type), POINTER :: tmc_section
75 
76  CHARACTER(LEN=default_string_length) :: inp_kind_name
77  INTEGER :: i, i_rep, i_tmp, ind, n_items, &
78  n_nmc_items, n_rep_val, nmc_steps
79  LOGICAL :: explicit, flag
80  REAL(kind=dp) :: delta_x, init_acc_prob, mv_prob, &
81  mv_prob_sum, nmc_init_acc_prob, &
82  nmc_prob, nmc_prob_sum, prob_ex
83  TYPE(section_vals_type), POINTER :: move_type_section, nmc_section
84  TYPE(tmc_move_type), POINTER :: move_types
85 
86  NULLIFY (move_types, move_type_section, nmc_section)
87 
88  n_items = 0
89  n_nmc_items = 0
90  delta_x = 0.0_dp
91  nmc_prob = 0.0_dp
92  mv_prob = 0.0_dp
93  nmc_prob = 0.0_dp
94  mv_prob_sum = 0.0_dp
95  nmc_prob_sum = 0.0_dp
96  prob_ex = 0.0_dp
97  init_acc_prob = 0.0_dp
98 
99  ! the move types on exact potential
100  move_type_section => section_vals_get_subs_vals(tmc_section, "MOVE_TYPE")
101  CALL section_vals_get(move_type_section, explicit=explicit)
102  IF (explicit) THEN
103  CALL section_vals_get(move_type_section, n_repetition=n_items)
104  mv_prob_sum = 0.0_dp
105  DO i_rep = 1, n_items
106  CALL section_vals_val_get(move_type_section, "PROB", i_rep_section=i_rep, &
107  r_val=mv_prob)
108  mv_prob_sum = mv_prob_sum + mv_prob
109  END DO
110  END IF
111 
112  ! get the NMC prameters
113  nmc_section => section_vals_get_subs_vals(tmc_section, "NMC_MOVES")
114  CALL section_vals_get(nmc_section, explicit=explicit)
115  IF (explicit) THEN
116  ! check the approx potential file, already read
117  IF (tmc_params%NMC_inp_file .EQ. "") &
118  cpabort("Please specify a valid approximate potential.")
119 
120  CALL section_vals_val_get(nmc_section, "NR_NMC_STEPS", &
121  i_val=nmc_steps)
122  IF (nmc_steps .LE. 0) &
123  cpabort("Please specify a valid amount of NMC steps (NR_NMC_STEPS {INTEGER}).")
124 
125  CALL section_vals_val_get(nmc_section, "PROB", r_val=nmc_prob)
126 
127  CALL section_vals_val_get(move_type_section, "INIT_ACC_PROB", &
128  r_val=nmc_init_acc_prob)
129  IF (nmc_init_acc_prob .LE. 0.0_dp) &
130  CALL cp_abort(__location__, &
131  "Please select a valid initial acceptance probability (>0.0) "// &
132  "for INIT_ACC_PROB")
133 
134  move_type_section => section_vals_get_subs_vals(nmc_section, "MOVE_TYPE")
135  CALL section_vals_get(move_type_section, n_repetition=n_nmc_items)
136 
137  ! get the NMC move probability sum
138  nmc_prob_sum = 0.0_dp
139  DO i_rep = 1, n_nmc_items
140  CALL section_vals_val_get(move_type_section, "PROB", i_rep_section=i_rep, &
141  r_val=mv_prob)
142  nmc_prob_sum = nmc_prob_sum + mv_prob
143  END DO
144  END IF
145 
146  ! get the total weight/amount of move probabilities
147  mv_prob_sum = mv_prob_sum + nmc_prob
148 
149  IF (n_items + n_nmc_items .GT. 0) THEN
150  ! initilaize the move array with related sizes, probs, etc.
151  CALL move_types_create(tmc_params%move_types, tmc_params%nr_temp)
152 
153  IF (mv_prob_sum .LE. 0.0) &
154  CALL cp_abort(__location__, &
155  "The probabilities to perform the moves are "// &
156  "in total less equal 0")
157 
158  ! get the sizes, probs, etc. for each move type and convert units
159  DO i_tmp = 1, n_items + n_nmc_items
160  ! select the correct section
161  IF (i_tmp .GT. n_items) THEN
162  i_rep = i_tmp - n_items
163  IF (i_rep .EQ. 1) THEN
164  ! set the NMC stuff (approx potential)
165  tmc_params%move_types%mv_weight(mv_type_nmc_moves) = &
166  nmc_prob/real(mv_prob_sum, kind=dp)
167  tmc_params%move_types%mv_size(mv_type_nmc_moves, :) = nmc_steps
168  tmc_params%move_types%acc_prob(mv_type_nmc_moves, :) = nmc_init_acc_prob
169 
170  move_type_section => section_vals_get_subs_vals(tmc_section, "NMC_MOVES%MOVE_TYPE")
171  mv_prob_sum = nmc_prob_sum
172  ! allocate the NMC move types
173  CALL move_types_create(tmc_params%nmc_move_types, tmc_params%nr_temp)
174  move_types => tmc_params%nmc_move_types
175  END IF
176  ELSE
177  ! the moves on exact potential
178  move_type_section => section_vals_get_subs_vals(tmc_section, "MOVE_TYPE")
179  i_rep = i_tmp
180  move_types => tmc_params%move_types
181  END IF
182 
183  CALL section_vals_val_get(move_type_section, "_SECTION_PARAMETERS_", &
184  c_val=inp_kind_name, i_rep_section=i_rep)
185  CALL uppercase(inp_kind_name)
186  CALL section_vals_val_get(move_type_section, "SIZE", i_rep_section=i_rep, &
187  r_val=delta_x)
188  ! move sizes are checked afterwards, because not all moves require a valid move size
189  CALL section_vals_val_get(move_type_section, "PROB", i_rep_section=i_rep, &
190  r_val=mv_prob)
191  IF (mv_prob .LT. 0.0_dp) &
192  CALL cp_abort(__location__, &
193  "Please select a valid move probability (>0.0) "// &
194  "for the move type "//inp_kind_name)
195  CALL section_vals_val_get(move_type_section, "INIT_ACC_PROB", i_rep_section=i_rep, &
196  r_val=init_acc_prob)
197  IF (init_acc_prob .LT. 0.0_dp) &
198  CALL cp_abort(__location__, &
199  "Please select a valid initial acceptance probability (>0.0) "// &
200  "for the move type "//inp_kind_name)
201  ! set the related index and perform unit conversion of move sizes
202  SELECT CASE (inp_kind_name)
203  ! atom / molecule translation
204  CASE ("ATOM_TRANS", "MOL_TRANS")
205  SELECT CASE (inp_kind_name)
206  CASE ("ATOM_TRANS")
207  ind = mv_type_atom_trans
208  CASE ("MOL_TRANS")
209  ind = mv_type_mol_trans
210  CASE DEFAULT
211  cpabort("move type is not defined in the translation types")
212  END SELECT
213  ! convert units
214  SELECT CASE (tmc_params%task_type)
216  delta_x = delta_x/au2a
218  !nothing to do (no unit conversion)
219  CASE DEFAULT
220  cpabort("move type atom / mol trans is not defined for this TMC run type")
221  END SELECT
222  ! molecule rotation
223  CASE ("MOL_ROT")
224  ind = mv_type_mol_rot
225  ! convert units
226  SELECT CASE (tmc_params%task_type)
228  delta_x = delta_x*pi/180.0_dp
229  CASE DEFAULT
230  cpabort("move type MOL_ROT is not defined for this TMC run type")
231  END SELECT
232  ! proton reordering
233  CASE ("PROT_REORDER")
235  ! the move size is not necessary
236  delta_x = 0.0_dp
237  ! Hybrid MC (MD)
238  CASE ("HYBRID_MC")
239  ind = mv_type_md
240  delta_x = delta_x*pi/180.0_dp !input in degree, calculating in rad
241  tmc_params%print_forces = .true.
242  ! parallel tempering swap move
243  CASE ("PT_SWAP")
244  ind = mv_type_swap_conf
245  ! the move size is not necessary
246  delta_x = 0.0_dp
247  IF (tmc_params%nr_temp .LE. 1) THEN
248  ! no configurational swapping if only one temperature
249  mv_prob = 0.0_dp
250  CALL cp_warn(__location__, &
251  "Configurational swap disabled, because "// &
252  "Parallel Tempering requires more than one temperature.")
253  END IF
254  ! volume moves
255  CASE ("VOL_MOVE")
256  ind = mv_type_volume_move
257  ! check the selected pressure
258  IF (tmc_params%pressure .GE. 0.0_dp) THEN
259  delta_x = delta_x/au2a
260  tmc_params%print_cell = .true. ! print the cell sizes by default
261  ELSE
262  CALL cp_warn(__location__, &
263  "no valid pressure defined, but volume move defined. "// &
264  "Consequently, the volume move is disabled.")
265  mv_prob = 0.0_dp
266  END IF
267  ! parallel tempering swap move
268  CASE ("ATOM_SWAP")
269  ind = mv_type_atom_swap
270  ! the move size is not necessary
271  delta_x = 0.0_dp
272  ! select the types of atoms swapped
273  CALL section_vals_val_get(move_type_section, "ATOMS", i_rep_section=i_rep, &
274  n_rep_val=n_rep_val)
275  IF (n_rep_val .GT. 0) THEN
276  ALLOCATE (move_types%atom_lists(n_rep_val))
277  DO i = 1, n_rep_val
278  CALL section_vals_val_get(move_type_section, "ATOMS", &
279  i_rep_section=i_rep, i_rep_val=i, &
280  c_vals=move_types%atom_lists(i)%atoms)
281  IF (SIZE(move_types%atom_lists(i)%atoms) .LE. 1) &
282  cpabort("ATOM_SWAP requires minimum two atom kinds selected. ")
283  END DO
284  END IF
285  ! gaussian adaptation
286  CASE ("GAUSS_ADAPT")
288  init_acc_prob = 0.5_dp
289  CASE DEFAULT
290  cpabort("A unknown move type is selected: "//inp_kind_name)
291  END SELECT
292  ! check for valid move sizes
293  IF (delta_x .LT. 0.0_dp) &
294  CALL cp_abort(__location__, &
295  "Please select a valid move size (>0.0) "// &
296  "for the move type "//inp_kind_name)
297  ! check if not already set
298  IF (move_types%mv_weight(ind) .GT. 0.0) THEN
299  cpabort("TMC: Each move type can be set only once. ")
300  END IF
301 
302  ! set the move size
303  move_types%mv_size(ind, :) = delta_x
304  ! set the probability to perform move
305  move_types%mv_weight(ind) = mv_prob/mv_prob_sum
306  ! set the initial acceptance probability
307  move_types%acc_prob(ind, :) = init_acc_prob
308  END DO
309  ELSE
310  cpabort("No move type selected, please select at least one.")
311  END IF
312  mv_prob_sum = sum(tmc_params%move_types%mv_weight(:))
313  flag = .true.
314  cpassert(abs(mv_prob_sum - 1.0_dp) .LT. 0.01_dp)
315  IF (ASSOCIATED(tmc_params%nmc_move_types)) THEN
316  mv_prob_sum = sum(tmc_params%nmc_move_types%mv_weight(:))
317  cpassert(abs(mv_prob_sum - 1.0_dp) < 10*epsilon(1.0_dp))
318  END IF
319  END SUBROUTINE read_init_move_types
320 
321 ! **************************************************************************************************
322 !> \brief checks if the moves are possible
323 !> \param tmc_params ...
324 !> \param move_types ...
325 !> \param mol_array ...
326 !> \author Mandes 10.2013
327 ! **************************************************************************************************
328  SUBROUTINE check_moves(tmc_params, move_types, mol_array)
329  TYPE(tmc_param_type), POINTER :: tmc_params
330  TYPE(tmc_move_type), POINTER :: move_types
331  INTEGER, DIMENSION(:), POINTER :: mol_array
332 
333  INTEGER :: atom_j, list_i, ref_k
334  LOGICAL :: found
335 
336  cpassert(ASSOCIATED(tmc_params))
337  cpassert(ASSOCIATED(move_types))
338 
339  ! molecule moves need molecule info
340  IF (move_types%mv_weight(mv_type_mol_trans) .GT. 0.0_dp .OR. &
341  move_types%mv_weight(mv_type_mol_rot) .GT. 0.0_dp) THEN
342  ! if there is no molecule information available,
343  ! molecules moves can not be performed
344  IF (mol_array(SIZE(mol_array)) .EQ. SIZE(mol_array)) &
345  CALL cp_abort(__location__, &
346  "molecule move: there is no molecule "// &
347  "information available. Please specify molecules when "// &
348  "using molecule moves.")
349  END IF
350 
351  ! for the atom swap move
352  IF (move_types%mv_weight(mv_type_atom_swap) .GT. 0.0_dp) THEN
353  ! check if the selected atom swaps are possible
354  IF (ASSOCIATED(move_types%atom_lists)) THEN
355  DO list_i = 1, SIZE(move_types%atom_lists(:))
356  DO atom_j = 1, SIZE(move_types%atom_lists(list_i)%atoms(:))
357  ! check if atoms exists
358  found = .false.
359  ref_loop: DO ref_k = 1, SIZE(tmc_params%atoms(:))
360  IF (move_types%atom_lists(list_i)%atoms(atom_j) .EQ. &
361  tmc_params%atoms(ref_k)%name) THEN
362  found = .true.
363  EXIT ref_loop
364  END IF
365  END DO ref_loop
366  IF (.NOT. found) &
367  CALL cp_abort(__location__, &
368  "ATOM_SWAP: The selected atom type ("// &
369  trim(move_types%atom_lists(list_i)%atoms(atom_j))// &
370  ") is not contained in the system. ")
371  ! check if not be swapped with the same atom type
372  IF (any(move_types%atom_lists(list_i)%atoms(atom_j) .EQ. &
373  move_types%atom_lists(list_i)%atoms(atom_j + 1:))) THEN
374  CALL cp_abort(__location__, &
375  "ATOM_SWAP can not swap two atoms of same kind ("// &
376  trim(move_types%atom_lists(list_i)%atoms(atom_j))// &
377  ")")
378  END IF
379  END DO
380  END DO
381  ELSE
382  ! check if there exisit different atoms
383  found = .false.
384  IF (SIZE(tmc_params%atoms(:)) .GT. 1) THEN
385  ref_lop: DO ref_k = 2, SIZE(tmc_params%atoms(:))
386  IF (tmc_params%atoms(1)%name .NE. tmc_params%atoms(ref_k)%name) THEN
387  found = .true.
388  EXIT ref_lop
389  END IF
390  END DO ref_lop
391  END IF
392  IF (.NOT. found) &
393  CALL cp_abort(__location__, &
394  "The system contains only a single atom type,"// &
395  " atom_swap is not possible.")
396  END IF
397  END IF
398  END SUBROUTINE check_moves
399 
400 ! **************************************************************************************************
401 !> \brief deallocating the module variables
402 !> \param tmc_params ...
403 !> \author Mandes 11.2012
404 !> \note deallocating the module variables
405 ! **************************************************************************************************
406  SUBROUTINE finalize_mv_types(tmc_params)
407  TYPE(tmc_param_type), POINTER :: tmc_params
408 
409  cpassert(ASSOCIATED(tmc_params))
410  CALL move_types_release(tmc_params%move_types)
411  IF (ASSOCIATED(tmc_params%nmc_move_types)) &
412  CALL move_types_release(tmc_params%nmc_move_types)
413  END SUBROUTINE finalize_mv_types
414 
415 ! **************************************************************************************************
416 !> \brief routine pronts out the probabilities and sized for each type and
417 !> temperature the output is divided into two parts the init,
418 !> which is printed out at the beginning of the programm and
419 !> .NOT.init which are the probabilites and counter printed out every
420 !> print cycle
421 !> \param init ...
422 !> \param file_io ...
423 !> \param tmc_params ...
424 !> \author Mandes 11.2012
425 ! **************************************************************************************************
426  SUBROUTINE print_move_types(init, file_io, tmc_params)
427  LOGICAL :: init
428  INTEGER :: file_io
429  TYPE(tmc_param_type), POINTER :: tmc_params
430 
431  CHARACTER(LEN=10) :: c_t
432  CHARACTER(LEN=50) :: fmt_c, fmt_i, fmt_r
433  CHARACTER(LEN=500) :: c_a, c_b, c_c, c_d, c_e, c_tit, c_tmp
434  INTEGER :: column_size, move, nr_nmc_moves, temper, &
435  typ
436  LOGICAL :: subbox_out, type_title
437  TYPE(tmc_move_type), POINTER :: move_types
438 
439  NULLIFY (move_types)
440 
441  c_a = ""; c_b = ""; c_c = ""
442  c_d = ""; c_e = ""; c_tit = ""
443  column_size = 10
444  subbox_out = .false.
445  type_title = .false.
446  cpassert(file_io .GT. 0)
447  cpassert(ASSOCIATED(tmc_params%move_types))
448 
449  FLUSH (file_io)
450 
451  IF (.NOT. init .AND. &
452  tmc_params%move_types%mv_weight(mv_type_nmc_moves) .GT. 0 .AND. &
453  any(tmc_params%sub_box_size .GT. 0.0_dp)) subbox_out = .true.
454 
455  ! set the format for each typ to add one column
456  WRITE (fmt_c, '("(A,1X,A", I0, ")")') column_size
457  WRITE (fmt_i, '("(A,1X,I", I0, ")")') column_size
458  WRITE (fmt_r, '("(A,1X,F", I0, ".3)")') column_size
459  !IF(init) &
460  type_title = .true.
461 
462  nr_nmc_moves = 0
463  IF (ASSOCIATED(tmc_params%nmc_move_types)) THEN
464  nr_nmc_moves = SIZE(tmc_params%nmc_move_types%mv_weight(1:))
465  END IF
466 
467  temp_loop: DO temper = 1, tmc_params%nr_temp
468  c_tit = ""; c_a = ""; c_b = ""; c_c = ""
469  IF (init .AND. temper .GT. 1) EXIT temp_loop
470  WRITE (c_t, "(F10.2)") tmc_params%Temp(temper)
471  typ_loop: DO move = 0, SIZE(tmc_params%move_types%mv_weight) + nr_nmc_moves
472  ! the NMC moves
473  IF (move .LE. SIZE(tmc_params%move_types%mv_weight)) THEN
474  typ = move
475  move_types => tmc_params%move_types
476  ELSE
477  typ = move - SIZE(tmc_params%move_types%mv_weight)
478  move_types => tmc_params%nmc_move_types
479  END IF
480  ! total average
481  IF (typ .EQ. 0) THEN
482  ! line start
483  IF (type_title) WRITE (c_tit, trim(fmt_c)) " type temperature |"
484  IF (init) WRITE (c_b, trim(fmt_c)) " I I |"
485  IF (init) WRITE (c_c, trim(fmt_c)) " V V |"
486  IF (.NOT. init) WRITE (c_a, trim(fmt_c)) "probs T="//c_t//" |"
487  IF (.NOT. init) WRITE (c_b, trim(fmt_c)) "counts T="//c_t//" |"
488  IF (.NOT. init) WRITE (c_c, trim(fmt_c)) "nr_acc T="//c_t//" |"
489  IF (subbox_out) THEN
490  WRITE (c_d, trim(fmt_c)) "sb_acc T="//c_t//" |"
491  WRITE (c_e, trim(fmt_c)) "sb_cou T="//c_t//" |"
492  END IF
493  ! overall column
494  IF (type_title) THEN
495  c_tmp = trim(c_tit)
496  WRITE (c_tit, trim(fmt_c)) trim(c_tmp), " trajec"
497  END IF
498  IF (init) THEN
499  c_tmp = trim(c_b)
500  WRITE (c_b, trim(fmt_c)) trim(c_tmp), " weight->"
501  END IF
502  IF (init) THEN
503  c_tmp = trim(c_c)
504  WRITE (c_c, trim(fmt_c)) trim(c_tmp), " size ->"
505  END IF
506  IF (.NOT. init) THEN
507  c_tmp = trim(c_a)
508  WRITE (c_a, trim(fmt_r)) trim(c_tmp), &
509  move_types%acc_prob(typ, temper)
510  END IF
511  IF (.NOT. init) THEN
512  c_tmp = trim(c_b)
513  WRITE (c_b, trim(fmt_i)) trim(c_tmp), &
514  move_types%mv_count(typ, temper)
515  END IF
516  IF (.NOT. init) THEN
517  c_tmp = trim(c_c)
518  WRITE (c_c, trim(fmt_i)) trim(c_tmp), &
519  move_types%acc_count(typ, temper)
520  END IF
521  IF (subbox_out) THEN
522  c_tmp = trim(c_d)
523  WRITE (c_d, trim(fmt_c)) trim(c_tmp), "."
524  c_tmp = trim(c_e)
525  WRITE (c_e, trim(fmt_c)) trim(c_tmp), "."
526  END IF
527  ELSE
528  ! certain move types
529  IF (move_types%mv_weight(typ) .GT. 0.0_dp) THEN
530  ! INIT: the weights in the initialisation output
531  IF (init) THEN
532  c_tmp = trim(c_b)
533  WRITE (c_b, trim(fmt_r)) trim(c_tmp), move_types%mv_weight(typ)
534  END IF
535  ! acc probabilities
536  IF (typ .EQ. mv_type_swap_conf .AND. &
537  temper .EQ. tmc_params%nr_temp) THEN
538  IF (.NOT. init) THEN
539  c_tmp = trim(c_a)
540  WRITE (c_a, trim(fmt_c)) trim(c_tmp), "---"
541  END IF
542  ELSE
543  IF (.NOT. init) THEN
544  c_tmp = trim(c_a)
545  WRITE (c_a, trim(fmt_r)) trim(c_tmp), move_types%acc_prob(typ, temper)
546  END IF
547  END IF
548  IF (.NOT. init) THEN
549  c_tmp = trim(c_b)
550  WRITE (c_b, trim(fmt_i)) trim(c_tmp), move_types%mv_count(typ, temper)
551  END IF
552  IF (.NOT. init) THEN
553  c_tmp = trim(c_c)
554  WRITE (c_c, trim(fmt_i)) trim(c_tmp), move_types%acc_count(typ, temper)
555  END IF
556  ! sub box
557  IF (subbox_out) THEN
558  IF (move .GT. SIZE(tmc_params%move_types%mv_weight)) THEN
559  c_tmp = trim(c_d)
560  WRITE (c_d, trim(fmt_r)) trim(c_tmp), &
561  move_types%subbox_acc_count(typ, temper)/ &
562  REAL(max(1, move_types%subbox_count(typ, temper)), kind=dp)
563  c_tmp = trim(c_e)
564  WRITE (c_e, trim(fmt_i)) trim(c_tmp), &
565  move_types%subbox_count(typ, temper)
566  ELSE
567  c_tmp = trim(c_d)
568  WRITE (c_d, trim(fmt_c)) trim(c_tmp), "-"
569  c_tmp = trim(c_e)
570  WRITE (c_e, trim(fmt_c)) trim(c_tmp), "-"
571  END IF
572  END IF
573 
574  SELECT CASE (typ)
575  CASE (mv_type_atom_trans)
576  IF (type_title) THEN
577  c_tmp = trim(c_tit)
578  WRITE (c_tit, trim(fmt_c)) trim(c_tmp), "atom trans."
579  END IF
580  IF (init) THEN
581  c_tmp = trim(c_c)
582  WRITE (c_c, trim(fmt_r)) trim(c_tmp), &
583  move_types%mv_size(typ, temper)*au2a
584  END IF
585  CASE (mv_type_mol_trans)
586  IF (type_title) THEN
587  c_tmp = trim(c_tit)
588  WRITE (c_tit, trim(fmt_c)) trim(c_tmp), "mol trans"
589  END IF
590  IF (init) THEN
591  c_tmp = trim(c_c)
592  WRITE (c_c, trim(fmt_r)) trim(c_tmp), &
593  move_types%mv_size(typ, temper)*au2a
594  END IF
595  CASE (mv_type_mol_rot)
596  IF (type_title) THEN
597  c_tmp = trim(c_tit)
598  WRITE (c_tit, trim(fmt_c)) trim(c_tmp), "mol rot"
599  END IF
600  IF (init) THEN
601  c_tmp = trim(c_c)
602  WRITE (c_c, trim(fmt_r)) trim(c_tmp), &
603  move_types%mv_size(typ, temper)/(pi/180.0_dp)
604  END IF
605  CASE (mv_type_md)
606  cpwarn("md_time_step and nr md_steps not implemented...")
607 ! IF(type_title) WRITE(c_tit,TRIM(FMT_c)) TRIM(c_tit), "HybridMC"
608 ! IF(init) WRITE(c_c,TRIM(FMT_c)) TRIM(c_c), "s.above"
609 ! IF(init) THEN
610 ! WRITE(file_io,*)" move type: molecular dynamics with file ",NMC_inp_file
611 ! WRITE(file_io,*)" with time step [fs] ",md_time_step*au2fs
612 ! WRITE(file_io,*)" with number of steps ",md_steps
613 ! WRITE(file_io,*)" with velocity changes consists of old vel and ",&
614 ! sin(move_types%mv_size(typ,1))*100.0_dp,"% random Gaussian with variance to temperature,"
615 ! END IF
617  IF (type_title) THEN
618  c_tmp = trim(c_tit)
619  WRITE (c_tit, trim(fmt_c)) trim(c_tmp), "H-Reorder"
620  END IF
621  IF (init) THEN
622  c_tmp = trim(c_c)
623  WRITE (c_c, trim(fmt_c)) trim(c_tmp), "XXX"
624  END IF
625  CASE (mv_type_swap_conf)
626  IF (type_title) THEN
627  c_tmp = trim(c_tit)
628  WRITE (c_tit, trim(fmt_c)) trim(c_tmp), "PT(swap)"
629  END IF
630  IF (init) THEN
631  c_tmp = trim(c_c)
632  WRITE (c_c, trim(fmt_c)) trim(c_tmp), "XXX" !move_types%mv_size(mv_type_swap_conf,1)
633  END IF
634  CASE (mv_type_nmc_moves)
635  IF (type_title) THEN
636  c_tmp = trim(c_tit)
637  WRITE (c_tit, trim(fmt_c)) trim(c_tmp), "NMC:"
638  END IF
639  IF (init) THEN
640  c_tmp = trim(c_c)
641  WRITE (c_c, trim(fmt_i)) trim(c_tmp), &
642  int(move_types%mv_size(typ, temper))
643  END IF
644  CASE (mv_type_volume_move)
645  IF (type_title) THEN
646  c_tmp = trim(c_tit)
647  WRITE (c_tit, trim(fmt_c)) trim(c_tmp), "volume"
648  END IF
649  IF (init) THEN
650  c_tmp = trim(c_c)
651  WRITE (c_c, trim(fmt_r)) trim(c_tmp), &
652  move_types%mv_size(typ, temper)*au2a
653  END IF
654  CASE (mv_type_atom_swap)
655  IF (type_title) THEN
656  c_tmp = trim(c_tit)
657  WRITE (c_tit, trim(fmt_c)) trim(c_tmp), "atom swap"
658  END IF
659  IF (init) THEN
660  c_tmp = trim(c_c)
661  WRITE (c_c, trim(fmt_c)) trim(c_tmp), "XXX"
662  END IF
663  CASE (mv_type_gausian_adapt)
664  IF (type_title) THEN
665  c_tmp = trim(c_tit)
666  WRITE (c_tit, trim(fmt_c)) trim(c_tmp), "gauss adap"
667  END IF
668  IF (init) THEN
669  c_tmp = trim(c_c)
670  WRITE (c_c, trim(fmt_r)) trim(c_tmp), &
671  move_types%mv_size(typ, temper)
672  END IF
673  CASE DEFAULT
674  CALL cp_warn(__location__, &
675  "unknown move type "//cp_to_string(typ)//" with weight"// &
676  cp_to_string(move_types%mv_weight(typ)))
677  END SELECT
678  END IF
679  END IF
680  END DO typ_loop
681  IF (init) WRITE (unit=file_io, fmt="(/,T2,A)") repeat("-", 79)
682  IF (type_title .AND. temper .LE. 1) WRITE (file_io, *) trim(c_tit)
683  IF (.NOT. init) WRITE (file_io, *) trim(c_a)
684  WRITE (file_io, *) trim(c_b)
685  WRITE (file_io, *) trim(c_c)
686  IF (subbox_out) WRITE (file_io, *) trim(c_d)
687  IF (subbox_out) WRITE (file_io, *) trim(c_e)
688  IF (init) WRITE (unit=file_io, fmt="(/,T2,A)") repeat("-", 79)
689  END DO temp_loop
690  END SUBROUTINE print_move_types
691 
692 ! **************************************************************************************************
693 !> \brief adaptation of acceptance probability of every kind of change/move
694 !> and the overall acc prob,
695 !> using the acceptance and rejectance information
696 !> \param move_types structure for storing sizes and probabilities of moves
697 !> \param pt_el global tree element
698 !> \param elem sub tree element
699 !> \param acc input if the element is accepted
700 !> \param subbox logical if move was with respect to the sub box
701 !> \param prob_opt if the average probability should be adapted
702 !> \author Mandes 12.2012
703 ! **************************************************************************************************
704  SUBROUTINE prob_update(move_types, pt_el, elem, acc, subbox, prob_opt)
705  TYPE(tmc_move_type), POINTER :: move_types
706  TYPE(global_tree_type), OPTIONAL, POINTER :: pt_el
707  TYPE(tree_type), OPTIONAL, POINTER :: elem
708  LOGICAL, INTENT(IN), OPTIONAL :: acc, subbox
709  LOGICAL, INTENT(IN) :: prob_opt
710 
711  CHARACTER(LEN=*), PARAMETER :: routinen = 'prob_update'
712 
713  INTEGER :: change_res, change_sb_type, change_type, &
714  conf_moved, handle, mv_type
715 
716  cpassert(ASSOCIATED(move_types))
717  cpassert(.NOT. (PRESENT(pt_el) .AND. PRESENT(subbox)))
718 
719  ! start the timing
720  CALL timeset(routinen, handle)
721 
722  mv_type = -1
723  conf_moved = -1
724 
725  change_type = 0
726  change_res = 0
727  change_sb_type = 0
728  ! updating probability of the trajectory
729  IF (PRESENT(pt_el)) THEN
730  cpassert(ASSOCIATED(pt_el))
731  conf_moved = pt_el%mv_conf
732  SELECT CASE (pt_el%stat)
734  change_res = 1
735  !-- swaped move is not noted in subtree elements
736  IF (pt_el%swaped) THEN
737  mv_type = mv_type_swap_conf
738  change_type = 1
739  END IF
741  change_res = -1
742  !-- swaped move is not noted in subtree elements
743  IF (pt_el%swaped) THEN
744  mv_type = mv_type_swap_conf
745  change_type = -1
746  END IF
747  CASE DEFAULT
748  CALL cp_abort(__location__, &
749  "global elem"//cp_to_string(pt_el%nr)// &
750  "has unknown status"//cp_to_string(pt_el%stat))
751  END SELECT
752  END IF
753 
754  IF (PRESENT(elem)) THEN
755  cpassert(ASSOCIATED(elem))
756  !conf_moved = elem%sub_tree_nr
757  conf_moved = elem%temp_created
758  mv_type = elem%move_type
759  ! for NMC prob update the acceptance is needed
760  cpassert(PRESENT(acc))
761  IF (PRESENT(subbox)) THEN
762  ! only update subbox acceptance
763  IF (acc) &
764  move_types%subbox_acc_count(mv_type, conf_moved) = move_types%subbox_acc_count(mv_type, conf_moved) + 1
765  move_types%subbox_count(mv_type, conf_moved) = move_types%subbox_count(mv_type, conf_moved) + 1
766  ! No more to do
767  change_type = 0
768  change_res = 0
769  conf_moved = 0
770  ! RETURN
771  ELSE
772  ! update move type acceptance
773  IF (acc) THEN
774  change_type = 1
775  ELSE
776  change_type = -1
777  END IF
778  END IF
779  END IF
780 
781  !-- INcrease or DEcrease accaptance rate
782  ! MOVE types
783  IF (change_type .GT. 0) THEN
784  move_types%acc_count(mv_type, conf_moved) = move_types%acc_count(mv_type, conf_moved) + 1
785  END IF
786 
787  ! RESULTs
788  IF (change_res .GT. 0) THEN
789  move_types%acc_count(0, conf_moved) = move_types%acc_count(0, conf_moved) + 1
790  END IF
791 
792  IF (conf_moved .GT. 0) move_types%mv_count(0, conf_moved) = move_types%mv_count(0, conf_moved) + abs(change_res)
793  IF (mv_type .GE. 0 .AND. conf_moved .GT. 0) &
794  move_types%mv_count(mv_type, conf_moved) = move_types%mv_count(mv_type, conf_moved) + abs(change_type)
795 
796  IF (prob_opt) THEN
797  WHERE (move_types%mv_count .GT. 0) &
798  move_types%acc_prob(:, :) = move_types%acc_count(:, :)/real(move_types%mv_count(:, :), kind=dp)
799  END IF
800  ! end the timing
801  CALL timestop(handle)
802  END SUBROUTINE prob_update
803 
804 ! **************************************************************************************************
805 !> \brief add the actual moves to the average probabilities
806 !> \param move_types structure with move counters and probabilities
807 !> \param prob_opt ...
808 !> \param mv_counter move counter for actual performed moves of certain types
809 !> \param acc_counter counters of acceptance for these moves
810 !> \param subbox_counter same for sub box moves
811 !> \param subbox_acc_counter same for sub box moves
812 !> \author Mandes 12.2012
813 ! **************************************************************************************************
814  SUBROUTINE add_mv_prob(move_types, prob_opt, mv_counter, acc_counter, &
815  subbox_counter, subbox_acc_counter)
816  TYPE(tmc_move_type), POINTER :: move_types
817  LOGICAL :: prob_opt
818  INTEGER, DIMENSION(:, :), OPTIONAL :: mv_counter, acc_counter, subbox_counter, &
819  subbox_acc_counter
820 
821  cpassert(ASSOCIATED(move_types))
822  cpassert(PRESENT(mv_counter) .OR. PRESENT(subbox_counter))
823 
824  IF (PRESENT(mv_counter)) THEN
825  cpassert(PRESENT(acc_counter))
826  move_types%mv_count(:, :) = move_types%mv_count(:, :) + mv_counter(:, :)
827  move_types%acc_count(:, :) = move_types%acc_count(:, :) + acc_counter(:, :)
828  IF (prob_opt) THEN
829  WHERE (move_types%mv_count .GT. 0) &
830  move_types%acc_prob(:, :) = move_types%acc_count(:, :)/real(move_types%mv_count(:, :), kind=dp)
831  END IF
832  END IF
833 
834  IF (PRESENT(subbox_counter)) THEN
835  cpassert(PRESENT(subbox_acc_counter))
836  move_types%subbox_count(:, :) = move_types%subbox_count(:, :) + subbox_counter(:, :)
837  move_types%subbox_acc_count(:, :) = move_types%subbox_acc_count(:, :) + subbox_acc_counter(:, :)
838  END IF
839  END SUBROUTINE add_mv_prob
840 
841 ! **************************************************************************************************
842 !> \brief clear the statistics of accepting/rejection moves
843 !> because worker statistics will be add separately on masters counters
844 !> \param move_types counters for acceptance/rejection
845 !> \author Mandes 02.2013
846 ! **************************************************************************************************
847  SUBROUTINE clear_move_probs(move_types)
848  TYPE(tmc_move_type), POINTER :: move_types
849 
850  cpassert(ASSOCIATED(move_types))
851 
852  move_types%acc_prob(:, :) = 0.5_dp
853  move_types%acc_count(:, :) = 0
854  move_types%mv_count(:, :) = 0
855  move_types%subbox_acc_count(:, :) = 0
856  move_types%subbox_count(:, :) = 0
857  END SUBROUTINE clear_move_probs
858 
859 ! **************************************************************************************************
860 !> \brief selects a move type related to the weighings and the entered rnd nr
861 !> \param move_types structure for storing sizes and probabilities of moves
862 !> \param rnd random number
863 !> \return (result) move type
864 !> \author Mandes 12.2012
865 !> \note function returns a possible move type without the PT swap moves
866 !> \note (are selected in global tree, this routine is for sub tree elements)
867 ! **************************************************************************************************
868  FUNCTION select_random_move_type(move_types, rnd) RESULT(mv_type)
869  TYPE(tmc_move_type), POINTER :: move_types
870  REAL(kind=dp) :: rnd
871  INTEGER :: mv_type
872 
873  CHARACTER(LEN=*), PARAMETER :: routinen = 'select_random_move_type'
874 
875  INTEGER :: handle, i
876  REAL(kind=dp) :: rnd_mv, total_moves
877 
878  cpassert(ASSOCIATED(move_types))
879  cpassert(rnd .GE. 0.0_dp .AND. rnd .LT. 1.0_dp)
880 
881  CALL timeset(routinen, handle)
882 
883  total_moves = sum(move_types%mv_weight(2:))
884  rnd_mv = total_moves*rnd
885  mv_type = 0
886  search_loop: DO i = 2, SIZE(move_types%mv_weight(:))
887  IF (sum(move_types%mv_weight(2:i)) .GE. rnd_mv) THEN
888  mv_type = i
889  EXIT search_loop
890  END IF
891  END DO search_loop
892 
893  CALL timestop(handle)
894  END FUNCTION select_random_move_type
895 
896 END MODULE tmc_move_handle
various routines to log and control the output. The idea is that decisions about where to log should ...
objects that represent the structure of input sections and the data contained in an input section
recursive type(section_vals_type) function, pointer, public section_vals_get_subs_vals(section_vals, subsection_name, i_rep_section, can_return_null)
returns the values of the requested subsection
subroutine, public section_vals_get(section_vals, ref_count, n_repetition, n_subs_vals_rep, section, explicit)
returns various attributes about the section_vals
subroutine, public section_vals_val_get(section_vals, keyword_name, i_rep_section, i_rep_val, n_rep_val, val, l_val, i_val, r_val, c_val, l_vals, i_vals, r_vals, c_vals, explicit)
returns the requested value
Defines the basic variable types.
Definition: kinds.F:23
integer, parameter, public dp
Definition: kinds.F:34
integer, parameter, public default_string_length
Definition: kinds.F:57
Definition of mathematical constants and functions.
Definition: mathconstants.F:16
real(kind=dp), parameter, public pi
Definition of physical constants:
Definition: physcon.F:68
real(kind=dp), parameter, public angstrom
Definition: physcon.F:144
Utilities for string manipulations.
elemental subroutine, public uppercase(string)
Convert all lower case characters in a string to upper case.
acceptance ratio handling of the different Monte Carlo Moves types For each move type and each temper...
subroutine, public add_mv_prob(move_types, prob_opt, mv_counter, acc_counter, subbox_counter, subbox_acc_counter)
add the actual moves to the average probabilities
subroutine, public read_init_move_types(tmc_params, tmc_section)
initialization of the different moves, with sizes and probabilities
subroutine, public clear_move_probs(move_types)
clear the statistics of accepting/rejection moves because worker statistics will be add separately on...
subroutine, public finalize_mv_types(tmc_params)
deallocating the module variables
integer function, public select_random_move_type(move_types, rnd)
selects a move type related to the weighings and the entered rnd nr
subroutine, public check_moves(tmc_params, move_types, mol_array)
checks if the moves are possible
subroutine, public prob_update(move_types, pt_el, elem, acc, subbox, prob_opt)
adaptation of acceptance probability of every kind of change/move and the overall acc prob,...
subroutine, public print_move_types(init, file_io, tmc_params)
routine pronts out the probabilities and sized for each type and temperature the output is divided in...
tree nodes creation, searching, deallocation, references etc.
integer, parameter, public mv_type_mol_rot
integer, parameter, public mv_type_volume_move
integer, parameter, public mv_type_proton_reorder
integer, parameter, public mv_type_swap_conf
integer, parameter, public mv_type_md
integer, parameter, public mv_type_mol_trans
subroutine, public move_types_create(move_types, nr_temp)
allocating the module variables
integer, parameter, public mv_type_atom_swap
integer, parameter, public mv_type_gausian_adapt
integer, parameter, public mv_type_atom_trans
integer, parameter, public mv_type_nmc_moves
subroutine, public move_types_release(move_types)
deallocating the module variables
tree nodes creation, searching, deallocation, references etc.
Definition: tmc_stati.F:15
integer, parameter, public task_type_gaussian_adaptation
Definition: tmc_stati.F:47
integer, parameter, public task_type_mc
Definition: tmc_stati.F:44
integer, parameter, public task_type_ideal_gas
Definition: tmc_stati.F:45
module handles definition of the tree nodes for the global and the subtrees binary tree parent elemen...
integer, parameter, public status_accepted_result
integer, parameter, public status_rejected_result
module handles definition of the tree nodes for the global and the subtrees binary tree parent elemen...
Definition: tmc_types.F:32