50 #include "../base/base_uses.f90"
56 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'tmc_move_handle'
73 TYPE(tmc_param_type),
POINTER :: tmc_params
74 TYPE(section_vals_type),
POINTER :: tmc_section
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
86 NULLIFY (move_types, move_type_section, nmc_section)
97 init_acc_prob = 0.0_dp
105 DO i_rep = 1, n_items
108 mv_prob_sum = mv_prob_sum + mv_prob
117 IF (tmc_params%NMC_inp_file .EQ.
"") &
118 cpabort(
"Please specify a valid approximate potential.")
122 IF (nmc_steps .LE. 0) &
123 cpabort(
"Please specify a valid amount of NMC steps (NR_NMC_STEPS {INTEGER}).")
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) "// &
138 nmc_prob_sum = 0.0_dp
139 DO i_rep = 1, n_nmc_items
142 nmc_prob_sum = nmc_prob_sum + mv_prob
147 mv_prob_sum = mv_prob_sum + nmc_prob
149 IF (n_items + n_nmc_items .GT. 0)
THEN
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")
159 DO i_tmp = 1, n_items + n_nmc_items
161 IF (i_tmp .GT. n_items)
THEN
162 i_rep = i_tmp - n_items
163 IF (i_rep .EQ. 1)
THEN
166 nmc_prob/real(mv_prob_sum, kind=
dp)
171 mv_prob_sum = nmc_prob_sum
174 move_types => tmc_params%nmc_move_types
180 move_types => tmc_params%move_types
184 c_val=inp_kind_name, i_rep_section=i_rep)
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)
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)
202 SELECT CASE (inp_kind_name)
204 CASE (
"ATOM_TRANS",
"MOL_TRANS")
205 SELECT CASE (inp_kind_name)
211 cpabort(
"move type is not defined in the translation types")
214 SELECT CASE (tmc_params%task_type)
216 delta_x = delta_x/au2a
220 cpabort(
"move type atom / mol trans is not defined for this TMC run type")
226 SELECT CASE (tmc_params%task_type)
228 delta_x = delta_x*
pi/180.0_dp
230 cpabort(
"move type MOL_ROT is not defined for this TMC run type")
233 CASE (
"PROT_REORDER")
240 delta_x = delta_x*
pi/180.0_dp
241 tmc_params%print_forces = .true.
247 IF (tmc_params%nr_temp .LE. 1)
THEN
250 CALL cp_warn(__location__, &
251 "Configurational swap disabled, because "// &
252 "Parallel Tempering requires more than one temperature.")
258 IF (tmc_params%pressure .GE. 0.0_dp)
THEN
259 delta_x = delta_x/au2a
260 tmc_params%print_cell = .true.
262 CALL cp_warn(__location__, &
263 "no valid pressure defined, but volume move defined. "// &
264 "Consequently, the volume move is disabled.")
275 IF (n_rep_val .GT. 0)
THEN
276 ALLOCATE (move_types%atom_lists(n_rep_val))
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. ")
288 init_acc_prob = 0.5_dp
290 cpabort(
"A unknown move type is selected: "//inp_kind_name)
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)
298 IF (move_types%mv_weight(ind) .GT. 0.0)
THEN
299 cpabort(
"TMC: Each move type can be set only once. ")
303 move_types%mv_size(ind, :) = delta_x
305 move_types%mv_weight(ind) = mv_prob/mv_prob_sum
307 move_types%acc_prob(ind, :) = init_acc_prob
310 cpabort(
"No move type selected, please select at least one.")
312 mv_prob_sum = sum(tmc_params%move_types%mv_weight(:))
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))
329 TYPE(tmc_param_type),
POINTER :: tmc_params
330 TYPE(tmc_move_type),
POINTER :: move_types
331 INTEGER,
DIMENSION(:),
POINTER :: mol_array
333 INTEGER :: atom_j, list_i, ref_k
336 cpassert(
ASSOCIATED(tmc_params))
337 cpassert(
ASSOCIATED(move_types))
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.")
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(:))
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
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. ")
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))// &
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
393 CALL cp_abort(__location__, &
394 "The system contains only a single atom type,"// &
395 " atom_swap is not possible.")
407 TYPE(tmc_param_type),
POINTER :: tmc_params
409 cpassert(
ASSOCIATED(tmc_params))
411 IF (
ASSOCIATED(tmc_params%nmc_move_types)) &
429 TYPE(tmc_param_type),
POINTER :: tmc_params
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, &
436 LOGICAL :: subbox_out, type_title
437 TYPE(tmc_move_type),
POINTER :: move_types
441 c_a =
""; c_b =
""; c_c =
""
442 c_d =
""; c_e =
""; c_tit =
""
446 cpassert(file_io .GT. 0)
447 cpassert(
ASSOCIATED(tmc_params%move_types))
451 IF (.NOT. init .AND. &
453 any(tmc_params%sub_box_size .GT. 0.0_dp)) subbox_out = .true.
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
463 IF (
ASSOCIATED(tmc_params%nmc_move_types))
THEN
464 nr_nmc_moves =
SIZE(tmc_params%nmc_move_types%mv_weight(1:))
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
473 IF (move .LE.
SIZE(tmc_params%move_types%mv_weight))
THEN
475 move_types => tmc_params%move_types
477 typ = move -
SIZE(tmc_params%move_types%mv_weight)
478 move_types => tmc_params%nmc_move_types
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//
" |"
490 WRITE (c_d, trim(fmt_c))
"sb_acc T="//c_t//
" |"
491 WRITE (c_e, trim(fmt_c))
"sb_cou T="//c_t//
" |"
496 WRITE (c_tit, trim(fmt_c)) trim(c_tmp),
" trajec"
500 WRITE (c_b, trim(fmt_c)) trim(c_tmp),
" weight->"
504 WRITE (c_c, trim(fmt_c)) trim(c_tmp),
" size ->"
508 WRITE (c_a, trim(fmt_r)) trim(c_tmp), &
509 move_types%acc_prob(typ, temper)
513 WRITE (c_b, trim(fmt_i)) trim(c_tmp), &
514 move_types%mv_count(typ, temper)
518 WRITE (c_c, trim(fmt_i)) trim(c_tmp), &
519 move_types%acc_count(typ, temper)
523 WRITE (c_d, trim(fmt_c)) trim(c_tmp),
"."
525 WRITE (c_e, trim(fmt_c)) trim(c_tmp),
"."
529 IF (move_types%mv_weight(typ) .GT. 0.0_dp)
THEN
533 WRITE (c_b, trim(fmt_r)) trim(c_tmp), move_types%mv_weight(typ)
537 temper .EQ. tmc_params%nr_temp)
THEN
540 WRITE (c_a, trim(fmt_c)) trim(c_tmp),
"---"
545 WRITE (c_a, trim(fmt_r)) trim(c_tmp), move_types%acc_prob(typ, temper)
550 WRITE (c_b, trim(fmt_i)) trim(c_tmp), move_types%mv_count(typ, temper)
554 WRITE (c_c, trim(fmt_i)) trim(c_tmp), move_types%acc_count(typ, temper)
558 IF (move .GT.
SIZE(tmc_params%move_types%mv_weight))
THEN
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)
564 WRITE (c_e, trim(fmt_i)) trim(c_tmp), &
565 move_types%subbox_count(typ, temper)
568 WRITE (c_d, trim(fmt_c)) trim(c_tmp),
"-"
570 WRITE (c_e, trim(fmt_c)) trim(c_tmp),
"-"
578 WRITE (c_tit, trim(fmt_c)) trim(c_tmp),
"atom trans."
582 WRITE (c_c, trim(fmt_r)) trim(c_tmp), &
583 move_types%mv_size(typ, temper)*au2a
588 WRITE (c_tit, trim(fmt_c)) trim(c_tmp),
"mol trans"
592 WRITE (c_c, trim(fmt_r)) trim(c_tmp), &
593 move_types%mv_size(typ, temper)*au2a
598 WRITE (c_tit, trim(fmt_c)) trim(c_tmp),
"mol rot"
602 WRITE (c_c, trim(fmt_r)) trim(c_tmp), &
603 move_types%mv_size(typ, temper)/(
pi/180.0_dp)
606 cpwarn(
"md_time_step and nr md_steps not implemented...")
619 WRITE (c_tit, trim(fmt_c)) trim(c_tmp),
"H-Reorder"
623 WRITE (c_c, trim(fmt_c)) trim(c_tmp),
"XXX"
628 WRITE (c_tit, trim(fmt_c)) trim(c_tmp),
"PT(swap)"
632 WRITE (c_c, trim(fmt_c)) trim(c_tmp),
"XXX"
637 WRITE (c_tit, trim(fmt_c)) trim(c_tmp),
"NMC:"
641 WRITE (c_c, trim(fmt_i)) trim(c_tmp), &
642 int(move_types%mv_size(typ, temper))
647 WRITE (c_tit, trim(fmt_c)) trim(c_tmp),
"volume"
651 WRITE (c_c, trim(fmt_r)) trim(c_tmp), &
652 move_types%mv_size(typ, temper)*au2a
657 WRITE (c_tit, trim(fmt_c)) trim(c_tmp),
"atom swap"
661 WRITE (c_c, trim(fmt_c)) trim(c_tmp),
"XXX"
666 WRITE (c_tit, trim(fmt_c)) trim(c_tmp),
"gauss adap"
670 WRITE (c_c, trim(fmt_r)) trim(c_tmp), &
671 move_types%mv_size(typ, temper)
674 CALL cp_warn(__location__, &
675 "unknown move type "//cp_to_string(typ)//
" with weight"// &
676 cp_to_string(move_types%mv_weight(typ)))
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)
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
711 CHARACTER(LEN=*),
PARAMETER :: routinen =
'prob_update'
713 INTEGER :: change_res, change_sb_type, change_type, &
714 conf_moved, handle, mv_type
716 cpassert(
ASSOCIATED(move_types))
717 cpassert(.NOT. (
PRESENT(pt_el) .AND.
PRESENT(subbox)))
720 CALL timeset(routinen, handle)
729 IF (
PRESENT(pt_el))
THEN
730 cpassert(
ASSOCIATED(pt_el))
731 conf_moved = pt_el%mv_conf
732 SELECT CASE (pt_el%stat)
736 IF (pt_el%swaped)
THEN
743 IF (pt_el%swaped)
THEN
748 CALL cp_abort(__location__, &
749 "global elem"//cp_to_string(pt_el%nr)// &
750 "has unknown status"//cp_to_string(pt_el%stat))
754 IF (
PRESENT(elem))
THEN
755 cpassert(
ASSOCIATED(elem))
757 conf_moved = elem%temp_created
758 mv_type = elem%move_type
760 cpassert(
PRESENT(acc))
761 IF (
PRESENT(subbox))
THEN
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
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
788 IF (change_res .GT. 0)
THEN
789 move_types%acc_count(0, conf_moved) = move_types%acc_count(0, conf_moved) + 1
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)
797 WHERE (move_types%mv_count .GT. 0) &
798 move_types%acc_prob(:, :) = move_types%acc_count(:, :)/real(move_types%mv_count(:, :), kind=
dp)
801 CALL timestop(handle)
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
818 INTEGER,
DIMENSION(:, :),
OPTIONAL :: mv_counter, acc_counter, subbox_counter, &
821 cpassert(
ASSOCIATED(move_types))
822 cpassert(
PRESENT(mv_counter) .OR.
PRESENT(subbox_counter))
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(:, :)
829 WHERE (move_types%mv_count .GT. 0) &
830 move_types%acc_prob(:, :) = move_types%acc_count(:, :)/real(move_types%mv_count(:, :), kind=
dp)
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(:, :)
848 TYPE(tmc_move_type),
POINTER :: move_types
850 cpassert(
ASSOCIATED(move_types))
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
869 TYPE(tmc_move_type),
POINTER :: move_types
873 CHARACTER(LEN=*),
PARAMETER :: routinen =
'select_random_move_type'
876 REAL(kind=
dp) :: rnd_mv, total_moves
878 cpassert(
ASSOCIATED(move_types))
879 cpassert(rnd .GE. 0.0_dp .AND. rnd .LT. 1.0_dp)
881 CALL timeset(routinen, handle)
883 total_moves = sum(move_types%mv_weight(2:))
884 rnd_mv = total_moves*rnd
886 search_loop:
DO i = 2,
SIZE(move_types%mv_weight(:))
887 IF (sum(move_types%mv_weight(2:i)) .GE. rnd_mv)
THEN
893 CALL timestop(handle)
various routines to log and control the output. The idea is that decisions about where to log should ...
Defines the basic variable types.
integer, parameter, public dp
integer, parameter, public default_string_length
Definition of mathematical constants and functions.
real(kind=dp), parameter, public pi
Definition of physical constants:
real(kind=dp), parameter, public angstrom
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.
integer, parameter, public task_type_gaussian_adaptation
integer, parameter, public task_type_mc
integer, parameter, public task_type_ideal_gas
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...