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 CHARACTER(LEN=default_path_length) :: coupling_function
75 CHARACTER(LEN=default_string_length), &
76 DIMENSION(:),
POINTER :: my_par
77 INTEGER :: handle, ic, icolvar, nforce_eval, &
78 output_unit, stat_sign_points
79 INTEGER,
POINTER :: istep
80 REAL(kind=
dp) :: beta, dx, lerr
81 REAL(kind=
dp),
DIMENSION(:),
POINTER :: my_val
89 NULLIFY (force_env, istep, subsys, cv, simpar)
91 CALL timeset(routinen, handle)
93 CALL get_md_env(md_env, force_env=force_env, fe_env=fe_env, simpar=simpar, &
97 IF (.NOT.
ASSOCIATED(force_env%meta_env) .AND.
ASSOCIATED(fe_env))
THEN
98 SELECT CASE (fe_env%type)
102 fe_env%nr_points = fe_env%nr_points + 1
104 DO ic = 1, fe_env%ncolvar
105 cv => fe_env%uivar(ic)
109 cv%ss(fe_env%nr_points) = subsys%colvar_p(icolvar)%colvar%ss
110 IF (output_unit > 0)
THEN
111 WRITE (output_unit, *)
"COLVAR::", cv%ss(fe_env%nr_points)
114 stat_sign_points = fe_env%nr_points - fe_env%nr_rejected
115 IF (output_unit > 0)
THEN
116 WRITE (output_unit, *) fe_env%nr_points, stat_sign_points
119 IF ((fe_env%conv_par%cg_width*fe_env%conv_par%cg_points <= stat_sign_points) .AND. &
120 (mod(stat_sign_points, fe_env%conv_par%cg_width) == 0))
THEN
122 extension=
".FreeEnergyLog", log_filename=.false.)
123 CALL print_fe_prolog(output_unit)
125 CALL ui_check_trend(fe_env, fe_env%conv_par%test_k, stat_sign_points, output_unit)
126 stat_sign_points = fe_env%nr_points - fe_env%nr_rejected
128 IF (fe_env%conv_par%cg_width*fe_env%conv_par%cg_points <= stat_sign_points .AND. &
129 fe_env%conv_par%test_k)
THEN
131 CALL ui_check_convergence(fe_env, converged, stat_sign_points, output_unit)
133 CALL print_fe_epilog(output_unit)
139 IF (.NOT.
ASSOCIATED(force_env%mixed_env))
THEN
140 CALL cp_abort(__location__, &
141 'ASSERTION (cond) failed at line '//
cp_to_string(__line__)// &
142 ' Free Energy calculations require the definition of a mixed env!')
144 my_par => force_env%mixed_env%par
145 my_val => force_env%mixed_env%val
146 dx = force_env%mixed_env%dx
147 lerr = force_env%mixed_env%lerr
148 coupling_function = force_env%mixed_env%coupling_function
149 beta = 1/simpar%temp_ext
150 CALL parsef(1, trim(coupling_function), my_par)
151 nforce_eval =
SIZE(force_env%sub_force_env)
152 CALL dump_ac_info(my_val, my_par, dx, lerr, fe_section, nforce_eval, &
153 fe_env%covmx, istep, beta)
159 CALL timestop(handle)
169 SUBROUTINE print_fe_prolog(output_unit)
170 INTEGER,
INTENT(IN) :: output_unit
172 IF (output_unit > 0)
THEN
173 WRITE (output_unit,
'(T2,79("*"))')
174 WRITE (output_unit,
'(T30,"FREE ENERGY CALCULATION",/)')
176 END SUBROUTINE print_fe_prolog
184 SUBROUTINE print_fe_epilog(output_unit)
185 INTEGER,
INTENT(IN) :: output_unit
187 IF (output_unit > 0)
THEN
188 WRITE (output_unit,
'(T2,79("*"),/)')
190 END SUBROUTINE print_fe_epilog
201 SUBROUTINE ui_check_trend(fe_env, trend_free, nr_points, output_unit)
203 LOGICAL,
INTENT(OUT) :: trend_free
204 INTEGER,
INTENT(IN) :: nr_points, output_unit
206 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ui_check_trend'
208 INTEGER :: handle, i, ii, j, k, my_reject, ncolvar, &
209 ng_points, rejected_points
210 LOGICAL :: test_avg, test_std
211 REAL(kind=
dp) :: prob, tau, z
212 REAL(kind=
dp),
DIMENSION(:),
POINTER :: wrk
214 CALL timeset(routinen, handle)
218 ncolvar = fe_env%ncolvar
220 IF (output_unit > 0)
THEN
221 WRITE (output_unit, *) nr_points, fe_env%conv_par%cg_width
223 ng_points = nr_points/fe_env%conv_par%cg_width
226 CALL create_tmp_data(fe_env, wrk, ng_points, ncolvar)
228 CALL create_csg_data(fe_env, ng_points, output_unit)
232 DO i = ng_points, 1, -1
233 wrk(ii) = fe_env%cg_data(i)%avg(j)
236 DO i = my_reject + 1, ng_points
238 my_reject = max(0, my_reject - 1)
242 CALL k_test(wrk, my_reject + 1, ng_points, tau, z, prob)
243 print *, prob, fe_env%conv_par%k_conf_lm
244 IF (prob < fe_env%conv_par%k_conf_lm)
EXIT
245 my_reject = my_reject + 1
247 my_reject = min(ng_points, my_reject)
249 rejected_points = my_reject*fe_env%conv_par%cg_width
251 IF (output_unit > 0)
THEN
252 WRITE (output_unit, *)
"Kendall trend test (Average)", test_avg, &
253 "number of points rejected:", rejected_points + fe_env%nr_rejected
254 WRITE (output_unit, *)
"Reject Nr.", my_reject,
" coarse grained points testing average"
260 DO i = ng_points, 1, -1
261 wrk(ii) = fe_env%cg_data(i)%var(j, k)
264 DO i = my_reject + 1, ng_points
266 my_reject = max(0, my_reject - 1)
270 CALL k_test(wrk, my_reject + 1, ng_points, tau, z, prob)
271 print *, prob, fe_env%conv_par%k_conf_lm
272 IF (prob < fe_env%conv_par%k_conf_lm)
EXIT
273 my_reject = my_reject + 1
275 my_reject = min(ng_points, my_reject)
278 rejected_points = my_reject*fe_env%conv_par%cg_width
279 fe_env%nr_rejected = fe_env%nr_rejected + rejected_points
280 trend_free = test_avg .AND. test_std
282 IF (output_unit > 0)
THEN
283 WRITE (output_unit, *)
"Kendall trend test (Std. Dev.)", test_std, &
284 "number of points rejected:", fe_env%nr_rejected
285 WRITE (output_unit, *)
"Reject Nr.", my_reject,
" coarse grained points testing standard dev."
286 WRITE (output_unit, *)
"Kendall test passed:", trend_free
289 CALL destroy_tmp_data(fe_env, wrk, ng_points)
290 CALL timestop(handle)
291 END SUBROUTINE ui_check_trend
302 SUBROUTINE create_tmp_data(fe_env, wrk, ng_points, ncolvar)
304 REAL(kind=
dp),
DIMENSION(:),
OPTIONAL,
POINTER :: wrk
305 INTEGER,
INTENT(IN) :: ng_points, ncolvar
309 ALLOCATE (fe_env%cg_data(ng_points))
311 ALLOCATE (fe_env%cg_data(i)%avg(ncolvar))
312 ALLOCATE (fe_env%cg_data(i)%var(ncolvar, ncolvar))
314 IF (
PRESENT(wrk))
THEN
315 ALLOCATE (wrk(ng_points))
317 END SUBROUTINE create_tmp_data
327 SUBROUTINE destroy_tmp_data(fe_env, wrk, ng_points)
329 REAL(kind=
dp),
DIMENSION(:),
OPTIONAL,
POINTER :: wrk
330 INTEGER,
INTENT(IN) :: ng_points
335 DEALLOCATE (fe_env%cg_data(i)%avg)
336 DEALLOCATE (fe_env%cg_data(i)%var)
338 DEALLOCATE (fe_env%cg_data)
339 IF (
PRESENT(wrk))
THEN
342 END SUBROUTINE destroy_tmp_data
352 SUBROUTINE create_csg_data(fe_env, ng_points, output_unit)
354 INTEGER,
INTENT(IN) :: ng_points, output_unit
356 INTEGER :: i, iend, istart
359 istart = fe_env%nr_points - (i)*fe_env%conv_par%cg_width + 1
360 iend = fe_env%nr_points - (i - 1)*fe_env%conv_par%cg_width
361 IF (output_unit > 0)
THEN
362 WRITE (output_unit, *) istart, iend
364 CALL eval_cov_matrix(fe_env, cg_index=i, istart=istart, iend=iend, output_unit=output_unit)
367 END SUBROUTINE create_csg_data
379 SUBROUTINE ui_check_norm_sc(fe_env, test_passed, nr_points, output_unit)
381 LOGICAL,
INTENT(OUT) :: test_passed
382 INTEGER,
INTENT(IN) :: nr_points, output_unit
384 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ui_check_norm_sc'
386 INTEGER :: handle, ng_points
388 CALL timeset(routinen, handle)
389 test_passed = .false.
390 DO WHILE (fe_env%conv_par%cg_width < fe_env%conv_par%max_cg_width)
391 ng_points = nr_points/fe_env%conv_par%cg_width
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
396 IF (test_passed)
EXIT
397 fe_env%conv_par%cg_width = fe_env%conv_par%cg_width + 1
398 IF (output_unit > 0)
THEN
399 WRITE (output_unit, *)
"New coarse grained width:", fe_env%conv_par%cg_width
402 IF (fe_env%conv_par%cg_width == fe_env%conv_par%max_cg_width .AND. (.NOT. (test_passed)))
THEN
403 CALL ui_check_norm_sc_low(fe_env, nr_points, output_unit)
404 test_passed = fe_env%conv_par%test_vn .AND. fe_env%conv_par%test_sw
406 CALL timestop(handle)
407 END SUBROUTINE ui_check_norm_sc
418 SUBROUTINE ui_check_norm_sc_low(fe_env, nr_points, output_unit)
420 INTEGER,
INTENT(IN) :: nr_points, output_unit
422 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ui_check_norm_sc_low'
424 INTEGER :: handle, i, j, k, ncolvar, ng_points
425 LOGICAL :: avg_test_passed, sdv_test_passed
426 REAL(kind=
dp) :: prob, pw, r, u, w
427 REAL(kind=
dp),
DIMENSION(:),
POINTER :: wrk
429 CALL timeset(routinen, handle)
430 ncolvar = fe_env%ncolvar
432 fe_env%conv_par%test_sw = .false.
433 fe_env%conv_par%test_vn = .false.
435 avg_test_passed = .true.
436 sdv_test_passed = .true.
437 ng_points = nr_points/fe_env%conv_par%cg_width
438 CALL create_tmp_data(fe_env, wrk, ng_points, ncolvar)
439 CALL create_csg_data(fe_env, ng_points, output_unit)
443 wrk(i) = fe_env%cg_data(i)%avg(j)
447 CALL sw_test(wrk, ng_points, w, pw)
448 print *, 1.0_dp - pw, fe_env%conv_par%sw_conf_lm
449 avg_test_passed = (1.0_dp - pw) <= fe_env%conv_par%sw_conf_lm
450 fe_env%conv_par%test_sw = avg_test_passed
451 IF (output_unit > 0)
THEN
452 WRITE (output_unit, *)
"Shapiro-Wilks normality test (Avg)", avg_test_passed
456 CALL vn_test(wrk, ng_points, r, u, prob)
457 print *, prob, fe_env%conv_par%vn_conf_lm
458 avg_test_passed = prob <= fe_env%conv_par%vn_conf_lm
459 fe_env%conv_par%test_vn = avg_test_passed
460 IF (output_unit > 0)
THEN
461 WRITE (output_unit, *)
"von Neumann serial correlation test (Avg)", avg_test_passed
465 IF (fe_env%conv_par%test_vn .AND. fe_env%conv_par%test_sw)
THEN
470 wrk(i) = fe_env%cg_data(i)%var(j, k)
474 CALL sw_test(wrk, ng_points, w, pw)
475 print *, 1.0_dp - pw, fe_env%conv_par%sw_conf_lm
476 sdv_test_passed = (1.0_dp - pw) <= fe_env%conv_par%sw_conf_lm
477 fe_env%conv_par%test_sw = fe_env%conv_par%test_sw .AND. sdv_test_passed
478 IF (output_unit > 0)
THEN
479 WRITE (output_unit, *)
"Shapiro-Wilks normality test (Std. Dev.)", sdv_test_passed
483 CALL vn_test(wrk, ng_points, r, u, prob)
484 print *, prob, fe_env%conv_par%vn_conf_lm
485 sdv_test_passed = prob <= fe_env%conv_par%vn_conf_lm
486 fe_env%conv_par%test_vn = fe_env%conv_par%test_vn .AND. sdv_test_passed
487 IF (output_unit > 0)
THEN
488 WRITE (output_unit, *)
"von Neumann serial correlation test (Std. Dev.)", sdv_test_passed
492 CALL destroy_tmp_data(fe_env, wrk, ng_points)
494 CALL destroy_tmp_data(fe_env, wrk, ng_points)
496 CALL timestop(handle)
497 END SUBROUTINE ui_check_norm_sc_low
509 SUBROUTINE ui_check_convergence(fe_env, converged, nr_points, output_unit)
511 LOGICAL,
INTENT(OUT) :: converged
512 INTEGER,
INTENT(IN) :: nr_points, output_unit
514 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ui_check_convergence'
516 INTEGER :: handle, i, ic, ncolvar, ng_points
517 LOGICAL :: test_passed
518 REAL(kind=
dp) :: max_error_avg, max_error_std
519 REAL(kind=
dp),
DIMENSION(:),
POINTER :: avg_std, avgmx
520 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: cov_std, covmx
522 CALL timeset(routinen, handle)
524 ncolvar = fe_env%ncolvar
525 NULLIFY (avgmx, avg_std, covmx, cov_std)
526 CALL ui_check_norm_sc(fe_env, test_passed, nr_points, output_unit)
527 IF (test_passed)
THEN
528 ng_points = nr_points/fe_env%conv_par%cg_width
531 CALL create_tmp_data(fe_env, ng_points=ng_points, ncolvar=ncolvar)
532 CALL create_csg_data(fe_env, ng_points, output_unit)
533 ALLOCATE (covmx(ncolvar, ncolvar))
534 ALLOCATE (avgmx(ncolvar))
535 ALLOCATE (cov_std(ncolvar*(ncolvar + 1)/2, ncolvar*(ncolvar + 1)/2))
536 ALLOCATE (avg_std(ncolvar))
540 covmx = covmx + fe_env%cg_data(i)%var
541 avgmx = avgmx + fe_env%cg_data(i)%avg
543 covmx = covmx/real(ng_points, kind=
dp)
544 avgmx = avgmx/real(ng_points, kind=
dp)
547 CALL compute_avg_std_errors(fe_env, ncolvar, avgmx, covmx, avg_std, cov_std)
548 IF (output_unit > 0)
THEN
549 WRITE (output_unit, *)
"pippo", avgmx, covmx
550 WRITE (output_unit, *)
"pippo", avg_std, cov_std
553 max_error_avg = sqrt(maxval(abs(avg_std))/real(ng_points, kind=
dp))/minval(avgmx)
554 max_error_std = sqrt(maxval(abs(cov_std))/real(ng_points, kind=
dp))/minval(covmx)
555 IF (max_error_avg <= fe_env%conv_par%eps_conv .AND. &
556 max_error_std <= fe_env%conv_par%eps_conv) converged = .true.
558 IF (output_unit > 0)
THEN
559 WRITE (output_unit,
'(/,T2,"CG SAMPLING LENGTH = ",I7,20X,"REQUESTED ACCURACY = ",E12.6)') ng_points, &
560 fe_env%conv_par%eps_conv
561 WRITE (output_unit,
'(T50,"PRESENT ACCURACY AVG= ",E12.6)') max_error_avg
562 WRITE (output_unit,
'(T50,"PRESENT ACCURACY STD= ",E12.6)') max_error_std
563 WRITE (output_unit,
'(T50,"CONVERGED FE-DER = ",L12)') converged
565 WRITE (output_unit,
'(/,T33, "COVARIANCE MATRIX")')
566 WRITE (output_unit,
'(T8,'//
cp_to_string(ncolvar)//
'(3X,I7,6X))') (ic, ic=1, ncolvar)
568 WRITE (output_unit,
'(T2,I6,'//
cp_to_string(ncolvar)//
'(3X,E12.6,1X))') ic, covmx(ic, :)
570 WRITE (output_unit,
'(T33, "ERROR OF COVARIANCE MATRIX")')
571 WRITE (output_unit,
'(T8,'//
cp_to_string(ncolvar)//
'(3X,I7,6X))') (ic, ic=1, ncolvar)
573 WRITE (output_unit,
'(T2,I6,'//
cp_to_string(ncolvar)//
'(3X,E12.6,1X))') ic, cov_std(ic, :)
576 WRITE (output_unit,
'(/,T2,"COLVAR Nr.",18X,13X,"AVERAGE",13X,"STANDARD DEVIATION")')
577 WRITE (output_unit,
'(T2,"CV",I8,21X,7X,E12.6,14X,E12.6)') &
578 (ic, avgmx(ic), sqrt(abs(avg_std(ic))), ic=1, ncolvar)
580 CALL destroy_tmp_data(fe_env, ng_points=ng_points)
586 CALL timestop(handle)
587 END SUBROUTINE ui_check_convergence
601 SUBROUTINE compute_avg_std_errors(fe_env, ncolvar, avgmx, covmx, avg_std, cov_std)
603 INTEGER,
INTENT(IN) :: ncolvar
604 REAL(kind=
dp),
DIMENSION(:),
POINTER :: avgmx
605 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: covmx
606 REAL(kind=
dp),
DIMENSION(:),
POINTER :: avg_std
607 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: cov_std
609 INTEGER :: i, ind, j, k, nvar
611 REAL(kind=
dp),
DIMENSION(:),
POINTER :: awrk, eig, tmp
612 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: wrk
617 ALLOCATE (wrk(nvar, nvar))
619 fac = real(
SIZE(fe_env%cg_data), kind=
dp)
622 DO k = 1,
SIZE(fe_env%cg_data)
625 wrk(i, j) = wrk(i, j) + fe_env%cg_data(k)%avg(i)*fe_env%cg_data(k)%avg(j)
631 wrk(i, j) = wrk(i, j) - avgmx(i)*avgmx(j)*
fac
632 wrk(j, i) = wrk(i, j)
635 wrk = wrk/(
fac - 1.0_dp)
644 nvar = ncolvar*(ncolvar + 1)/2
645 ALLOCATE (wrk(nvar, nvar))
647 ALLOCATE (awrk(nvar))
655 awrk(ind) = covmx(i, j)
658 DO k = 1,
SIZE(fe_env%cg_data)
663 tmp(ind) = fe_env%cg_data(k)%var(i, j)
668 wrk(i, j) = wrk(i, j) + tmp(i)*tmp(j) - awrk(i)*awrk(j)
674 wrk(i, j) = wrk(i, j) -
fac*awrk(i)*awrk(j)
675 wrk(j, i) = wrk(i, j)
678 wrk = wrk/(
fac - 1.0_dp)
685 cov_std(i, j) = eig(ind)
686 cov_std(j, i) = cov_std(i, j)
694 END SUBROUTINE compute_avg_std_errors
708 SUBROUTINE eval_cov_matrix(fe_env, cg_index, istart, iend, output_unit, covmx, avgs)
710 INTEGER,
INTENT(IN) :: cg_index, istart, iend, output_unit
711 REAL(kind=
dp),
DIMENSION(:, :),
OPTIONAL,
POINTER :: covmx
712 REAL(kind=
dp),
DIMENSION(:),
OPTIONAL,
POINTER :: avgs
714 CHARACTER(LEN=*),
PARAMETER :: routinen =
'eval_cov_matrix'
716 INTEGER :: handle, ic, jc, jstep, ncolvar, nlength
717 REAL(kind=
dp) :: tmp_ic, tmp_jc
720 CALL timeset(routinen, handle)
721 ncolvar = fe_env%ncolvar
722 nlength = iend - istart + 1
723 fe_env%cg_data(cg_index)%avg = 0.0_dp
724 fe_env%cg_data(cg_index)%var = 0.0_dp
725 IF (nlength > 1)
THEN
727 DO jstep = istart, iend
729 cv => fe_env%uivar(ic)
730 tmp_ic = cv%ss(jstep)
731 fe_env%cg_data(cg_index)%avg(ic) = fe_env%cg_data(cg_index)%avg(ic) + tmp_ic
734 cv => fe_env%uivar(ic)
735 tmp_ic = cv%ss(jstep)
737 cv => fe_env%uivar(jc)
738 tmp_jc = cv%ss(jstep)
739 fe_env%cg_data(cg_index)%var(jc, ic) = fe_env%cg_data(cg_index)%var(jc, ic) + tmp_ic*tmp_jc
745 fe_env%cg_data(cg_index)%var = fe_env%cg_data(cg_index)%var/real(nlength - 1, kind=
dp)
746 fe_env%cg_data(cg_index)%avg = fe_env%cg_data(cg_index)%avg/real(nlength, kind=
dp)
749 tmp_ic = fe_env%cg_data(cg_index)%avg(ic)
751 tmp_jc = fe_env%cg_data(cg_index)%avg(jc)*real(nlength, kind=
dp)/real(nlength - 1, kind=
dp)
752 fe_env%cg_data(cg_index)%var(jc, ic) = fe_env%cg_data(cg_index)%var(jc, ic) - tmp_ic*tmp_jc
753 fe_env%cg_data(cg_index)%var(ic, jc) = fe_env%cg_data(cg_index)%var(jc, ic)
756 IF (output_unit > 0)
THEN
757 WRITE (output_unit, *)
"eval_cov_matrix", istart, iend, fe_env%cg_data(cg_index)%avg, fe_env%cg_data(cg_index)%var
759 IF (
PRESENT(covmx)) covmx = fe_env%cg_data(cg_index)%var
760 IF (
PRESENT(avgs)) avgs = fe_env%cg_data(cg_index)%avg
762 CALL timestop(handle)
763 END SUBROUTINE eval_cov_matrix
778 SUBROUTINE dump_ac_info(my_val, my_par, dx, lerr, fe_section, nforce_eval, cum_res, &
780 REAL(kind=
dp),
DIMENSION(:),
POINTER :: my_val
781 CHARACTER(LEN=default_string_length), &
782 DIMENSION(:),
POINTER :: my_par
783 REAL(kind=
dp),
INTENT(IN) :: dx, lerr
785 INTEGER,
INTENT(IN) :: nforce_eval
786 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: cum_res
787 INTEGER,
POINTER :: istep
788 REAL(kind=
dp),
INTENT(IN) :: beta
790 CHARACTER(LEN=default_path_length) :: coupling_function
791 CHARACTER(LEN=default_string_length) :: def_error, par, this_error
792 INTEGER :: i, iforce_eval, ipar, isize, iw, j, &
794 REAL(kind=
dp) :: avg_bp, avg_det, avg_due, d_ene_w, dedf, &
795 ene_w, err, err_det, err_due, std_det, &
796 std_due, tmp, tmp2, wfac
803 DO i = 1,
SIZE(my_par)
804 IF (my_par(i) == par)
EXIT
806 cpassert(i <=
SIZE(my_par))
808 dedf =
evalfd(1, ipar, my_val, dx, err)
809 IF (abs(err) > lerr)
THEN
810 WRITE (this_error,
"(A,G12.6,A)")
"(", err,
")"
811 WRITE (def_error,
"(A,G12.6,A)")
"(", lerr,
")"
814 CALL cp_warn(__location__, &
815 'ASSERTION (cond) failed at line '//
cp_to_string(__line__)// &
816 ' Error '//trim(this_error)//
' in computing numerical derivatives larger then'// &
817 trim(def_error)//
' .')
824 CALL compress(coupling_function, full=.true.)
825 CALL parsef(2, trim(coupling_function), my_par)
826 ene_w =
evalf(2, my_val)
827 d_ene_w =
evalfd(2, ipar, my_val, dx, err)
828 IF (abs(err) > lerr)
THEN
829 WRITE (this_error,
"(A,G12.6,A)")
"(", err,
")"
830 WRITE (def_error,
"(A,G12.6,A)")
"(", lerr,
")"
833 CALL cp_warn(__location__, &
834 'ASSERTION (cond) failed at line '//
cp_to_string(__line__)// &
835 ' Error '//trim(this_error)//
' in computing numerical derivatives larger then'// &
836 trim(def_error)//
' .')
840 IF (istep > nequilstep)
THEN
841 isize =
SIZE(cum_res, 2) + 1
843 cum_res(1, isize) = dedf
844 cum_res(2, isize) = dedf - d_ene_w
845 cum_res(3, isize) = ene_w
848 avg_det = sum(cum_res(1, 1:isize))/real(isize, kind=
dp)
849 std_det = sum(cum_res(1, 1:isize)**2)/real(isize, kind=
dp)
851 avg_bp = sum(cum_res(3, 1:isize))/real(isize, kind=
dp)
854 wfac = wfac + exp(beta*(cum_res(3, j) - avg_bp))
860 tmp2 = exp(beta*(cum_res(3, j) - avg_bp))/wfac
861 avg_due = avg_due + tmp*tmp2
862 std_due = std_due + tmp**2*tmp2
865 err_due = sqrt(std_due - avg_due**2)/sqrt(real(isize - 1, kind=
dp))
866 err_det = sqrt(std_det - avg_det**2)/sqrt(real(isize - 1, kind=
dp))
870 extension=
".free_energy")
872 WRITE (iw,
'(T2,79("-"),T37," oOo ")')
873 DO iforce_eval = 1, nforce_eval
874 WRITE (iw,
'(T2,"ALCHEMICAL CHANGE| FORCE_EVAL Nr.",I5,T48,"ENERGY (Hartree)= ",F15.9)') &
875 iforce_eval, my_val(iforce_eval)
877 WRITE (iw,
'(T2,"ALCHEMICAL CHANGE| DERIVATIVE OF TOTAL ENERGY [ PARAMETER (",A,") ]",T66,F15.9)') &
879 WRITE (iw,
'(T2,"ALCHEMICAL CHANGE| DERIVATIVE OF BIASED ENERGY [ PARAMETER (",A,") ]",T66,F15.9)') &
880 trim(par), dedf - d_ene_w
881 WRITE (iw,
'(T2,"ALCHEMICAL CHANGE| BIASING UMBRELLA POTENTIAL ",T66,F15.9)') &
885 WRITE (iw,
'(/,T2,"ALCHEMICAL CHANGE| DERIVATIVE TOTAL FREE ENERGY ",T50,F15.9,1X,"+/-",1X,F11.9)') &
887 WRITE (iw,
'(T2,"ALCHEMICAL CHANGE| DERIVATIVE UNBIASED FREE ENERGY ",T50,F15.9,1X,"+/-",1X,F11.9)') &
890 WRITE (iw,
'(/,T2,"ALCHEMICAL CHANGE| DERIVATIVE TOTAL FREE ENERGY ",T50,F15.9,1X,"+/-",1X,T76,A)') &
892 WRITE (iw,
'(T2,"ALCHEMICAL CHANGE| DERIVATIVE UNBIASED FREE ENERGY ",T50,F15.9,1X,"+/-",1X,T76,A)') &
895 WRITE (iw,
'(T2,79("-"))')
900 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.