48#include "../base/base_uses.f90"
53 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'free_energy_methods'
69 LOGICAL,
INTENT(OUT) :: converged
72 CHARACTER(LEN=*),
PARAMETER :: routinen =
'free_energy_evaluate'
74 INTEGER :: handle, ic, icolvar, nforce_eval, &
75 output_unit, stat_sign_points
76 INTEGER,
POINTER :: istep
85 NULLIFY (force_env, istep, subsys, cv, simpar)
87 CALL timeset(routinen, handle)
89 CALL get_md_env(md_env, force_env=force_env, fe_env=fe_env, simpar=simpar, &
93 IF (.NOT.
ASSOCIATED(force_env%meta_env) .AND.
ASSOCIATED(fe_env))
THEN
94 SELECT CASE (fe_env%type)
98 fe_env%nr_points = fe_env%nr_points + 1
100 DO ic = 1, fe_env%ncolvar
101 cv => fe_env%uivar(ic)
105 cv%ss(fe_env%nr_points) = subsys%colvar_p(icolvar)%colvar%ss
106 IF (output_unit > 0)
THEN
107 WRITE (output_unit, *)
"COLVAR::", cv%ss(fe_env%nr_points)
110 stat_sign_points = fe_env%nr_points - fe_env%nr_rejected
111 IF (output_unit > 0)
THEN
112 WRITE (output_unit, *) fe_env%nr_points, stat_sign_points
115 IF ((fe_env%conv_par%cg_width*fe_env%conv_par%cg_points <= stat_sign_points) .AND. &
116 (mod(stat_sign_points, fe_env%conv_par%cg_width) == 0))
THEN
118 extension=
".FreeEnergyLog", log_filename=.false.)
119 CALL print_fe_prolog(output_unit)
121 CALL ui_check_trend(fe_env, fe_env%conv_par%test_k, stat_sign_points, output_unit)
122 stat_sign_points = fe_env%nr_points - fe_env%nr_rejected
124 IF (fe_env%conv_par%cg_width*fe_env%conv_par%cg_points <= stat_sign_points .AND. &
125 fe_env%conv_par%test_k)
THEN
127 CALL ui_check_convergence(fe_env, converged, stat_sign_points, output_unit)
129 CALL print_fe_epilog(output_unit)
134 IF (.NOT.
ASSOCIATED(force_env%mixed_env))
THEN
135 CALL cp_abort(__location__, &
136 "Free Energy calculations with the alchemical method require the "// &
137 "definition of a mixed force env with the FORCE_EVAL/MIXED/GENERIC "// &
138 "section, but none is found!")
140 beta = 1.0_dp/simpar%temp_ext
141 nforce_eval =
SIZE(force_env%sub_force_env)
142 CALL dump_ac_info(force_env%mixed_env%val, force_env%mixed_env%par, &
143 force_env%mixed_env%coupling_function, &
144 force_env%mixed_env%dx, force_env%mixed_env%lerr, &
145 fe_section, nforce_eval, fe_env%covmx, istep, beta)
150 CALL timestop(handle)
160 SUBROUTINE print_fe_prolog(output_unit)
161 INTEGER,
INTENT(IN) :: output_unit
163 IF (output_unit > 0)
THEN
164 WRITE (output_unit,
'(T2,79("*"))')
165 WRITE (output_unit,
'(T30,"FREE ENERGY CALCULATION",/)')
167 END SUBROUTINE print_fe_prolog
175 SUBROUTINE print_fe_epilog(output_unit)
176 INTEGER,
INTENT(IN) :: output_unit
178 IF (output_unit > 0)
THEN
179 WRITE (output_unit,
'(T2,79("*"),/)')
181 END SUBROUTINE print_fe_epilog
192 SUBROUTINE ui_check_trend(fe_env, trend_free, nr_points, output_unit)
194 LOGICAL,
INTENT(OUT) :: trend_free
195 INTEGER,
INTENT(IN) :: nr_points, output_unit
197 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ui_check_trend'
199 INTEGER :: handle, i, ii, j, k, my_reject, ncolvar, &
200 ng_points, rejected_points
201 LOGICAL :: test_avg, test_std
202 REAL(kind=
dp) :: prob, tau, z
203 REAL(kind=
dp),
DIMENSION(:),
POINTER :: wrk
205 CALL timeset(routinen, handle)
209 ncolvar = fe_env%ncolvar
211 IF (output_unit > 0)
THEN
212 WRITE (output_unit, *) nr_points, fe_env%conv_par%cg_width
214 ng_points = nr_points/fe_env%conv_par%cg_width
217 CALL create_tmp_data(fe_env, wrk, ng_points, ncolvar)
219 CALL create_csg_data(fe_env, ng_points, output_unit)
223 DO i = ng_points, 1, -1
224 wrk(ii) = fe_env%cg_data(i)%avg(j)
227 DO i = my_reject + 1, ng_points
229 my_reject = max(0, my_reject - 1)
233 CALL k_test(wrk, my_reject + 1, ng_points, tau, z, prob)
234 print *, prob, fe_env%conv_par%k_conf_lm
235 IF (prob < fe_env%conv_par%k_conf_lm)
EXIT
236 my_reject = my_reject + 1
238 my_reject = min(ng_points, my_reject)
240 rejected_points = my_reject*fe_env%conv_par%cg_width
242 IF (output_unit > 0)
THEN
243 WRITE (output_unit, *)
"Kendall trend test (Average)", test_avg, &
244 "number of points rejected:", rejected_points + fe_env%nr_rejected
245 WRITE (output_unit, *)
"Reject Nr.", my_reject,
" coarse grained points testing average"
251 DO i = ng_points, 1, -1
252 wrk(ii) = fe_env%cg_data(i)%var(j, k)
255 DO i = my_reject + 1, ng_points
257 my_reject = max(0, my_reject - 1)
261 CALL k_test(wrk, my_reject + 1, ng_points, tau, z, prob)
262 print *, prob, fe_env%conv_par%k_conf_lm
263 IF (prob < fe_env%conv_par%k_conf_lm)
EXIT
264 my_reject = my_reject + 1
266 my_reject = min(ng_points, my_reject)
269 rejected_points = my_reject*fe_env%conv_par%cg_width
270 fe_env%nr_rejected = fe_env%nr_rejected + rejected_points
271 trend_free = test_avg .AND. test_std
273 IF (output_unit > 0)
THEN
274 WRITE (output_unit, *)
"Kendall trend test (Std. Dev.)", test_std, &
275 "number of points rejected:", fe_env%nr_rejected
276 WRITE (output_unit, *)
"Reject Nr.", my_reject,
" coarse grained points testing standard dev."
277 WRITE (output_unit, *)
"Kendall test passed:", trend_free
280 CALL destroy_tmp_data(fe_env, wrk, ng_points)
281 CALL timestop(handle)
282 END SUBROUTINE ui_check_trend
293 SUBROUTINE create_tmp_data(fe_env, wrk, ng_points, ncolvar)
295 REAL(kind=
dp),
DIMENSION(:),
OPTIONAL,
POINTER :: wrk
296 INTEGER,
INTENT(IN) :: ng_points, ncolvar
300 ALLOCATE (fe_env%cg_data(ng_points))
302 ALLOCATE (fe_env%cg_data(i)%avg(ncolvar))
303 ALLOCATE (fe_env%cg_data(i)%var(ncolvar, ncolvar))
305 IF (
PRESENT(wrk))
THEN
306 ALLOCATE (wrk(ng_points))
308 END SUBROUTINE create_tmp_data
318 SUBROUTINE destroy_tmp_data(fe_env, wrk, ng_points)
320 REAL(kind=
dp),
DIMENSION(:),
OPTIONAL,
POINTER :: wrk
321 INTEGER,
INTENT(IN) :: ng_points
326 DEALLOCATE (fe_env%cg_data(i)%avg)
327 DEALLOCATE (fe_env%cg_data(i)%var)
329 DEALLOCATE (fe_env%cg_data)
330 IF (
PRESENT(wrk))
THEN
333 END SUBROUTINE destroy_tmp_data
343 SUBROUTINE create_csg_data(fe_env, ng_points, output_unit)
345 INTEGER,
INTENT(IN) :: ng_points, output_unit
347 INTEGER :: i, iend, istart
350 istart = fe_env%nr_points - (i)*fe_env%conv_par%cg_width + 1
351 iend = fe_env%nr_points - (i - 1)*fe_env%conv_par%cg_width
352 IF (output_unit > 0)
THEN
353 WRITE (output_unit, *) istart, iend
355 CALL eval_cov_matrix(fe_env, cg_index=i, istart=istart, iend=iend, output_unit=output_unit)
358 END SUBROUTINE create_csg_data
370 SUBROUTINE ui_check_norm_sc(fe_env, test_passed, nr_points, output_unit)
372 LOGICAL,
INTENT(OUT) :: test_passed
373 INTEGER,
INTENT(IN) :: nr_points, output_unit
375 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ui_check_norm_sc'
377 INTEGER :: handle, ng_points
379 CALL timeset(routinen, handle)
380 test_passed = .false.
381 DO WHILE (fe_env%conv_par%cg_width < fe_env%conv_par%max_cg_width)
382 ng_points = nr_points/fe_env%conv_par%cg_width
385 CALL ui_check_norm_sc_low(fe_env, nr_points, output_unit)
386 test_passed = fe_env%conv_par%test_vn .AND. fe_env%conv_par%test_sw
387 IF (test_passed)
EXIT
388 fe_env%conv_par%cg_width = fe_env%conv_par%cg_width + 1
389 IF (output_unit > 0)
THEN
390 WRITE (output_unit, *)
"New coarse grained width:", fe_env%conv_par%cg_width
393 IF (fe_env%conv_par%cg_width == fe_env%conv_par%max_cg_width .AND. (.NOT. (test_passed)))
THEN
394 CALL ui_check_norm_sc_low(fe_env, nr_points, output_unit)
395 test_passed = fe_env%conv_par%test_vn .AND. fe_env%conv_par%test_sw
397 CALL timestop(handle)
398 END SUBROUTINE ui_check_norm_sc
409 SUBROUTINE ui_check_norm_sc_low(fe_env, nr_points, output_unit)
411 INTEGER,
INTENT(IN) :: nr_points, output_unit
413 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ui_check_norm_sc_low'
415 INTEGER :: handle, i, j, k, ncolvar, ng_points
416 LOGICAL :: avg_test_passed, sdv_test_passed
417 REAL(kind=
dp) :: prob, pw, r, u, w
418 REAL(kind=
dp),
DIMENSION(:),
POINTER :: wrk
420 CALL timeset(routinen, handle)
421 ncolvar = fe_env%ncolvar
423 fe_env%conv_par%test_sw = .false.
424 fe_env%conv_par%test_vn = .false.
426 avg_test_passed = .true.
427 sdv_test_passed = .true.
428 ng_points = nr_points/fe_env%conv_par%cg_width
429 CALL create_tmp_data(fe_env, wrk, ng_points, ncolvar)
430 CALL create_csg_data(fe_env, ng_points, output_unit)
434 wrk(i) = fe_env%cg_data(i)%avg(j)
438 CALL sw_test(wrk, ng_points, w, pw)
439 print *, 1.0_dp - pw, fe_env%conv_par%sw_conf_lm
440 avg_test_passed = (1.0_dp - pw) <= fe_env%conv_par%sw_conf_lm
441 fe_env%conv_par%test_sw = avg_test_passed
442 IF (output_unit > 0)
THEN
443 WRITE (output_unit, *)
"Shapiro-Wilks normality test (Avg)", avg_test_passed
447 CALL vn_test(wrk, ng_points, r, u, prob)
448 print *, prob, fe_env%conv_par%vn_conf_lm
449 avg_test_passed = prob <= fe_env%conv_par%vn_conf_lm
450 fe_env%conv_par%test_vn = avg_test_passed
451 IF (output_unit > 0)
THEN
452 WRITE (output_unit, *)
"von Neumann serial correlation test (Avg)", avg_test_passed
456 IF (fe_env%conv_par%test_vn .AND. fe_env%conv_par%test_sw)
THEN
461 wrk(i) = fe_env%cg_data(i)%var(j, k)
465 CALL sw_test(wrk, ng_points, w, pw)
466 print *, 1.0_dp - pw, fe_env%conv_par%sw_conf_lm
467 sdv_test_passed = (1.0_dp - pw) <= fe_env%conv_par%sw_conf_lm
468 fe_env%conv_par%test_sw = fe_env%conv_par%test_sw .AND. sdv_test_passed
469 IF (output_unit > 0)
THEN
470 WRITE (output_unit, *)
"Shapiro-Wilks normality test (Std. Dev.)", sdv_test_passed
474 CALL vn_test(wrk, ng_points, r, u, prob)
475 print *, prob, fe_env%conv_par%vn_conf_lm
476 sdv_test_passed = prob <= fe_env%conv_par%vn_conf_lm
477 fe_env%conv_par%test_vn = fe_env%conv_par%test_vn .AND. sdv_test_passed
478 IF (output_unit > 0)
THEN
479 WRITE (output_unit, *)
"von Neumann serial correlation test (Std. Dev.)", sdv_test_passed
483 CALL destroy_tmp_data(fe_env, wrk, ng_points)
485 CALL destroy_tmp_data(fe_env, wrk, ng_points)
487 CALL timestop(handle)
488 END SUBROUTINE ui_check_norm_sc_low
500 SUBROUTINE ui_check_convergence(fe_env, converged, nr_points, output_unit)
502 LOGICAL,
INTENT(OUT) :: converged
503 INTEGER,
INTENT(IN) :: nr_points, output_unit
505 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ui_check_convergence'
507 INTEGER :: handle, i, ic, ncolvar, ng_points
508 LOGICAL :: test_passed
509 REAL(kind=
dp) :: max_error_avg, max_error_std
510 REAL(kind=
dp),
DIMENSION(:),
POINTER :: avg_std, avgmx
511 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: cov_std, covmx
513 CALL timeset(routinen, handle)
515 ncolvar = fe_env%ncolvar
516 NULLIFY (avgmx, avg_std, covmx, cov_std)
517 CALL ui_check_norm_sc(fe_env, test_passed, nr_points, output_unit)
518 IF (test_passed)
THEN
519 ng_points = nr_points/fe_env%conv_par%cg_width
522 CALL create_tmp_data(fe_env, ng_points=ng_points, ncolvar=ncolvar)
523 CALL create_csg_data(fe_env, ng_points, output_unit)
524 ALLOCATE (covmx(ncolvar, ncolvar))
525 ALLOCATE (avgmx(ncolvar))
526 ALLOCATE (cov_std(ncolvar*(ncolvar + 1)/2, ncolvar*(ncolvar + 1)/2))
527 ALLOCATE (avg_std(ncolvar))
531 covmx = covmx + fe_env%cg_data(i)%var
532 avgmx = avgmx + fe_env%cg_data(i)%avg
534 covmx = covmx/real(ng_points, kind=
dp)
535 avgmx = avgmx/real(ng_points, kind=
dp)
538 CALL compute_avg_std_errors(fe_env, ncolvar, avgmx, covmx, avg_std, cov_std)
539 IF (output_unit > 0)
THEN
540 WRITE (output_unit, *)
"pippo", avgmx, covmx
541 WRITE (output_unit, *)
"pippo", avg_std, cov_std
544 max_error_avg = sqrt(maxval(abs(avg_std))/real(ng_points, kind=
dp))/minval(avgmx)
545 max_error_std = sqrt(maxval(abs(cov_std))/real(ng_points, kind=
dp))/minval(covmx)
546 IF (max_error_avg <= fe_env%conv_par%eps_conv .AND. &
547 max_error_std <= fe_env%conv_par%eps_conv) converged = .true.
549 IF (output_unit > 0)
THEN
550 WRITE (output_unit,
'(/,T2,"CG SAMPLING LENGTH = ",I7,20X,"REQUESTED ACCURACY = ",E12.6)') ng_points, &
551 fe_env%conv_par%eps_conv
552 WRITE (output_unit,
'(T50,"PRESENT ACCURACY AVG= ",E12.6)') max_error_avg
553 WRITE (output_unit,
'(T50,"PRESENT ACCURACY STD= ",E12.6)') max_error_std
554 WRITE (output_unit,
'(T50,"CONVERGED FE-DER = ",L12)') converged
556 WRITE (output_unit,
'(/,T33, "COVARIANCE MATRIX")')
557 WRITE (output_unit,
'(T8,'//
cp_to_string(ncolvar)//
'(3X,I7,6X))') (ic, ic=1, ncolvar)
559 WRITE (output_unit,
'(T2,I6,'//
cp_to_string(ncolvar)//
'(3X,E12.6,1X))') ic, covmx(ic, :)
561 WRITE (output_unit,
'(T33, "ERROR OF COVARIANCE MATRIX")')
562 WRITE (output_unit,
'(T8,'//
cp_to_string(ncolvar)//
'(3X,I7,6X))') (ic, ic=1, ncolvar)
564 WRITE (output_unit,
'(T2,I6,'//
cp_to_string(ncolvar)//
'(3X,E12.6,1X))') ic, cov_std(ic, :)
567 WRITE (output_unit,
'(/,T2,"COLVAR Nr.",18X,13X,"AVERAGE",13X,"STANDARD DEVIATION")')
568 WRITE (output_unit,
'(T2,"CV",I8,21X,7X,E12.6,14X,E12.6)') &
569 (ic, avgmx(ic), sqrt(abs(avg_std(ic))), ic=1, ncolvar)
571 CALL destroy_tmp_data(fe_env, ng_points=ng_points)
577 CALL timestop(handle)
578 END SUBROUTINE ui_check_convergence
592 SUBROUTINE compute_avg_std_errors(fe_env, ncolvar, avgmx, covmx, avg_std, cov_std)
594 INTEGER,
INTENT(IN) :: ncolvar
595 REAL(kind=
dp),
DIMENSION(:),
POINTER :: avgmx
596 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: covmx
597 REAL(kind=
dp),
DIMENSION(:),
POINTER :: avg_std
598 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: cov_std
600 INTEGER :: i, ind, j, k, nvar
602 REAL(kind=
dp),
DIMENSION(:),
POINTER :: awrk, eig, tmp
603 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: wrk
608 ALLOCATE (wrk(nvar, nvar))
610 fac = real(
SIZE(fe_env%cg_data), kind=
dp)
613 DO k = 1,
SIZE(fe_env%cg_data)
616 wrk(i, j) = wrk(i, j) + fe_env%cg_data(k)%avg(i)*fe_env%cg_data(k)%avg(j)
622 wrk(i, j) = wrk(i, j) - avgmx(i)*avgmx(j)*
fac
623 wrk(j, i) = wrk(i, j)
626 wrk = wrk/(
fac - 1.0_dp)
635 nvar = ncolvar*(ncolvar + 1)/2
636 ALLOCATE (wrk(nvar, nvar))
638 ALLOCATE (awrk(nvar))
646 awrk(ind) = covmx(i, j)
649 DO k = 1,
SIZE(fe_env%cg_data)
654 tmp(ind) = fe_env%cg_data(k)%var(i, j)
659 wrk(i, j) = wrk(i, j) + tmp(i)*tmp(j) - awrk(i)*awrk(j)
665 wrk(i, j) = wrk(i, j) -
fac*awrk(i)*awrk(j)
666 wrk(j, i) = wrk(i, j)
669 wrk = wrk/(
fac - 1.0_dp)
676 cov_std(i, j) = eig(ind)
677 cov_std(j, i) = cov_std(i, j)
685 END SUBROUTINE compute_avg_std_errors
699 SUBROUTINE eval_cov_matrix(fe_env, cg_index, istart, iend, output_unit, covmx, avgs)
701 INTEGER,
INTENT(IN) :: cg_index, istart, iend, output_unit
702 REAL(kind=
dp),
DIMENSION(:, :),
OPTIONAL,
POINTER :: covmx
703 REAL(kind=
dp),
DIMENSION(:),
OPTIONAL,
POINTER :: avgs
705 CHARACTER(LEN=*),
PARAMETER :: routinen =
'eval_cov_matrix'
707 INTEGER :: handle, ic, jc, jstep, ncolvar, nlength
708 REAL(kind=
dp) :: tmp_ic, tmp_jc
711 CALL timeset(routinen, handle)
712 ncolvar = fe_env%ncolvar
713 nlength = iend - istart + 1
714 fe_env%cg_data(cg_index)%avg = 0.0_dp
715 fe_env%cg_data(cg_index)%var = 0.0_dp
716 IF (nlength > 1)
THEN
718 DO jstep = istart, iend
720 cv => fe_env%uivar(ic)
721 tmp_ic = cv%ss(jstep)
722 fe_env%cg_data(cg_index)%avg(ic) = fe_env%cg_data(cg_index)%avg(ic) + tmp_ic
725 cv => fe_env%uivar(ic)
726 tmp_ic = cv%ss(jstep)
728 cv => fe_env%uivar(jc)
729 tmp_jc = cv%ss(jstep)
730 fe_env%cg_data(cg_index)%var(jc, ic) = fe_env%cg_data(cg_index)%var(jc, ic) + tmp_ic*tmp_jc
736 fe_env%cg_data(cg_index)%var = fe_env%cg_data(cg_index)%var/real(nlength - 1, kind=
dp)
737 fe_env%cg_data(cg_index)%avg = fe_env%cg_data(cg_index)%avg/real(nlength, kind=
dp)
740 tmp_ic = fe_env%cg_data(cg_index)%avg(ic)
742 tmp_jc = fe_env%cg_data(cg_index)%avg(jc)*real(nlength, kind=
dp)/real(nlength - 1, kind=
dp)
743 fe_env%cg_data(cg_index)%var(jc, ic) = fe_env%cg_data(cg_index)%var(jc, ic) - tmp_ic*tmp_jc
744 fe_env%cg_data(cg_index)%var(ic, jc) = fe_env%cg_data(cg_index)%var(jc, ic)
747 IF (output_unit > 0)
THEN
748 WRITE (output_unit, *)
"eval_cov_matrix", istart, iend, fe_env%cg_data(cg_index)%avg, fe_env%cg_data(cg_index)%var
750 IF (
PRESENT(covmx)) covmx = fe_env%cg_data(cg_index)%var
751 IF (
PRESENT(avgs)) avgs = fe_env%cg_data(cg_index)%avg
753 CALL timestop(handle)
754 END SUBROUTINE eval_cov_matrix
770 SUBROUTINE dump_ac_info(my_val, my_par, coupling_function, dx, lerr, fe_section, &
771 nforce_eval, cum_res, istep, beta)
772 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:), &
773 INTENT(INOUT) :: my_val
774 CHARACTER(LEN=default_string_length), &
775 ALLOCATABLE,
DIMENSION(:),
INTENT(IN) :: my_par
776 CHARACTER(LEN=default_path_length),
INTENT(IN) :: coupling_function
777 REAL(kind=
dp),
INTENT(IN) :: dx, lerr
779 INTEGER,
INTENT(IN) :: nforce_eval
780 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: cum_res
781 INTEGER,
POINTER :: istep
782 REAL(kind=
dp),
INTENT(IN) :: beta
784 CHARACTER(LEN=default_path_length) :: weighting_function
785 CHARACTER(LEN=default_string_length) :: def_error, par, this_error
786 INTEGER :: i, iforce_eval, ipar, isize, iw, j, &
788 REAL(kind=
dp) :: avg_bp, avg_det, avg_due, d_ene_w, dedf, &
789 ene_w, err, err_det, err_due, std_det, &
790 std_due, tmp, tmp2, wfac
797 DO i = 1,
SIZE(my_par)
798 IF (my_par(i) == par)
EXIT
800 cpassert(i <=
SIZE(my_par))
811 CALL parsef(1, trim(coupling_function), my_par)
812 dedf =
evalfd(1, ipar, my_val, dx, err)
813 IF (abs(err) > lerr)
THEN
814 WRITE (this_error,
"(A,G12.6,A)")
"(", err,
")"
815 WRITE (def_error,
"(A,G12.6,A)")
"(", lerr,
")"
818 CALL cp_warn(__location__, &
819 'ASSERTION (cond) failed at line '//
cp_to_string(__line__)// &
820 ' Error '//trim(this_error)//
' in computing numerical derivatives larger than'// &
821 trim(def_error)//
' .')
828 CALL compress(weighting_function, full=.true.)
829 CALL parsef(2, trim(weighting_function), my_par)
830 ene_w =
evalf(2, my_val)
831 d_ene_w =
evalfd(2, ipar, my_val, dx, err)
832 IF (abs(err) > lerr)
THEN
833 WRITE (this_error,
"(A,G12.6,A)")
"(", err,
")"
834 WRITE (def_error,
"(A,G12.6,A)")
"(", lerr,
")"
837 CALL cp_warn(__location__, &
838 'ASSERTION (cond) failed at line '//
cp_to_string(__line__)// &
839 ' Error '//trim(this_error)//
' in computing numerical derivatives larger than'// &
840 trim(def_error)//
' .')
846 IF (istep > nequilstep)
THEN
847 isize =
SIZE(cum_res, 2) + 1
849 cum_res(1, isize) = dedf
850 cum_res(2, isize) = dedf - d_ene_w
851 cum_res(3, isize) = ene_w
854 avg_det = sum(cum_res(1, 1:isize))/real(isize, kind=
dp)
855 std_det = sum(cum_res(1, 1:isize)**2)/real(isize, kind=
dp)
857 avg_bp = sum(cum_res(3, 1:isize))/real(isize, kind=
dp)
860 wfac = wfac + exp(beta*(cum_res(3, j) - avg_bp))
866 tmp2 = exp(beta*(cum_res(3, j) - avg_bp))/wfac
867 avg_due = avg_due + tmp*tmp2
868 std_due = std_due + tmp**2*tmp2
871 err_due = sqrt(std_due - avg_due**2)/sqrt(real(isize - 1, kind=
dp))
872 err_det = sqrt(std_det - avg_det**2)/sqrt(real(isize - 1, kind=
dp))
876 extension=
".free_energy")
878 WRITE (iw,
'(T2,79("-"),T37," oOo ")')
879 DO iforce_eval = 1, nforce_eval
880 WRITE (iw,
'(T2,"ALCHEMICAL CHANGE| FORCE_EVAL Nr.",I5,T48,"ENERGY (Hartree)= ",F15.9)') &
881 iforce_eval, my_val(iforce_eval)
883 WRITE (iw,
'(T2,"ALCHEMICAL CHANGE| DERIVATIVE OF TOTAL ENERGY [ PARAMETER (",A,") ]",T66,F15.9)') &
885 WRITE (iw,
'(T2,"ALCHEMICAL CHANGE| DERIVATIVE OF BIASED ENERGY [ PARAMETER (",A,") ]",T66,F15.9)') &
886 trim(par), dedf - d_ene_w
887 WRITE (iw,
'(T2,"ALCHEMICAL CHANGE| BIASING UMBRELLA POTENTIAL ",T66,F15.9)') &
891 WRITE (iw,
'(/,T2,"ALCHEMICAL CHANGE| DERIVATIVE TOTAL FREE ENERGY ",T50,F15.9,1X,"+/-",1X,F11.9)') &
893 WRITE (iw,
'(T2,"ALCHEMICAL CHANGE| DERIVATIVE UNBIASED FREE ENERGY ",T50,F15.9,1X,"+/-",1X,F11.9)') &
896 WRITE (iw,
'(/,T2,"ALCHEMICAL CHANGE| DERIVATIVE TOTAL FREE ENERGY ",T50,F15.9,1X,"+/-",1X,T76,A)') &
898 WRITE (iw,
'(T2,"ALCHEMICAL CHANGE| DERIVATIVE UNBIASED FREE ENERGY ",T50,F15.9,1X,"+/-",1X,T76,A)') &
901 WRITE (iw,
'(T2,79("-"))')
906 END SUBROUTINE dump_ac_info
static GRID_HOST_DEVICE double fac(const int i)
Factorial function, e.g. fac(5) = 5! = 120.
defines collective variables s({R}) and the derivative of this variable wrt R these can then be used ...
subroutine, public colvar_eval_glob_f(icolvar, force_env)
evaluates the derivatives (dsdr) given and due to the given colvar
various routines to log and control the output. The idea is that decisions about where to log should ...
integer function, public cp_logger_get_default_io_unit(logger)
returns the unit nr for the ionode (-1 on all other processors) skips as well checks if the procs cal...
type(cp_logger_type) function, pointer, public cp_get_default_logger()
returns the default logger
routines to handle the output, The idea is to remove the decision of wheter to output and what to out...
integer function, public cp_print_key_unit_nr(logger, basis_section, print_key_path, extension, middle_name, local, log_filename, ignore_should_output, file_form, file_position, file_action, file_status, do_backup, on_file, is_new_file, mpi_io, fout)
...
subroutine, public cp_print_key_finished_output(unit_nr, logger, basis_section, print_key_path, local, ignore_should_output, on_file, mpi_io)
should be called after you finish working with a unit obtained with cp_print_key_unit_nr,...
types that represent a subsys, i.e. a part of the system
Interface for the force calculations.
recursive subroutine, public force_env_get(force_env, in_use, fist_env, qs_env, meta_env, fp_env, subsys, para_env, potential_energy, additional_potential, kinetic_energy, harmonic_shell, kinetic_shell, cell, sub_force_env, qmmm_env, qmmmx_env, eip_env, pwdft_env, globenv, input, force_env_section, method_name_id, root_section, mixed_env, nnp_env, embed_env, ipi_env)
returns various attributes about the force environment
This public domain function parser module is intended for applications where a set of mathematical ex...
subroutine, public parsef(i, funcstr, var)
Parse ith function string FuncStr and compile it into bytecode.
real(rn) function, public evalf(i, val)
...
real(kind=rn) function, public evalfd(id_fun, ipar, vals, h, err)
Evaluates derivatives.
subroutine, public finalizef()
...
subroutine, public initf(n)
...
Methods to perform free energy and free energy derivatives calculations.
subroutine, public free_energy_evaluate(md_env, converged, fe_section)
Main driver for free energy calculations In this routine we handle specifically biased MD.
defines types for metadynamics calculation
Defines the basic variable types.
integer, parameter, public dp
integer, parameter, public default_string_length
integer, parameter, public default_path_length
Collection of simple mathematical functions and subroutines.
subroutine, public diamat_all(a, eigval, dac)
Diagonalize the symmetric n by n matrix a using the LAPACK library. Only the upper triangle of matrix...
subroutine, public get_md_env(md_env, itimes, constant, used_time, cell, simpar, npt, force_env, para_env, reftraj, t, init, first_time, fe_env, thermostats, barostat, thermostat_coeff, thermostat_part, thermostat_shell, thermostat_baro, thermostat_fast, thermostat_slow, md_ener, averages, thermal_regions, ehrenfest_md)
get components of MD environment type
Utility routines for the memory handling.
Type for storing MD parameters.
Methods to perform on the fly statistical analysis of data -) Schiferl and Wallace,...
subroutine, public vn_test(xdata, n, r, u, prob)
Von Neumann test for serial correlation.
integer, parameter, public min_sample_size
subroutine, public k_test(xdata, istart, n, tau, z, prob)
Kandall's test for correlation.
subroutine, public sw_test(ix, n, w, pw)
Shapiro - Wilk's test or W-statistic to test normality of a distribution R94 APPL....
Utilities for string manipulations.
subroutine, public compress(string, full)
Eliminate multiple space characters in a string. If full is .TRUE., then all spaces are eliminated.
type of a logger, at the moment it contains just a print level starting at which level it should be l...
represents a system: atoms, molecules, their pos,vel,...
wrapper to abstract the force evaluation of the various methods
Simulation parameter type for molecular dynamics.