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)) &
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!')
143 my_par => force_env%mixed_env%par
144 my_val => force_env%mixed_env%val
145 dx = force_env%mixed_env%dx
146 lerr = force_env%mixed_env%lerr
147 coupling_function = force_env%mixed_env%coupling_function
148 beta = 1/simpar%temp_ext
149 CALL parsef(1, trim(coupling_function), my_par)
150 nforce_eval =
SIZE(force_env%sub_force_env)
151 CALL dump_ac_info(my_val, my_par, dx, lerr, fe_section, nforce_eval, &
152 fe_env%covmx, istep, beta)
158 CALL timestop(handle)
168 SUBROUTINE print_fe_prolog(output_unit)
169 INTEGER,
INTENT(IN) :: output_unit
171 IF (output_unit > 0)
THEN
172 WRITE (output_unit,
'(T2,79("*"))')
173 WRITE (output_unit,
'(T30,"FREE ENERGY CALCULATION",/)')
175 END SUBROUTINE print_fe_prolog
183 SUBROUTINE print_fe_epilog(output_unit)
184 INTEGER,
INTENT(IN) :: output_unit
186 IF (output_unit > 0)
THEN
187 WRITE (output_unit,
'(T2,79("*"),/)')
189 END SUBROUTINE print_fe_epilog
200 SUBROUTINE ui_check_trend(fe_env, trend_free, nr_points, output_unit)
202 LOGICAL,
INTENT(OUT) :: trend_free
203 INTEGER,
INTENT(IN) :: nr_points, output_unit
205 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ui_check_trend'
207 INTEGER :: handle, i, ii, j, k, my_reject, ncolvar, &
208 ng_points, rejected_points
209 LOGICAL :: test_avg, test_std
210 REAL(kind=
dp) :: prob, tau, z
211 REAL(kind=
dp),
DIMENSION(:),
POINTER :: wrk
213 CALL timeset(routinen, handle)
217 ncolvar = fe_env%ncolvar
219 IF (output_unit > 0)
THEN
220 WRITE (output_unit, *) nr_points, fe_env%conv_par%cg_width
222 ng_points = nr_points/fe_env%conv_par%cg_width
225 CALL create_tmp_data(fe_env, wrk, ng_points, ncolvar)
227 CALL create_csg_data(fe_env, ng_points, output_unit)
231 DO i = ng_points, 1, -1
232 wrk(ii) = fe_env%cg_data(i)%avg(j)
235 DO i = my_reject + 1, ng_points
237 my_reject = max(0, my_reject - 1)
241 CALL k_test(wrk, my_reject + 1, ng_points, tau, z, prob)
242 print *, prob, fe_env%conv_par%k_conf_lm
243 IF (prob < fe_env%conv_par%k_conf_lm)
EXIT
244 my_reject = my_reject + 1
246 my_reject = min(ng_points, my_reject)
248 rejected_points = my_reject*fe_env%conv_par%cg_width
250 IF (output_unit > 0)
THEN
251 WRITE (output_unit, *)
"Kendall trend test (Average)", test_avg, &
252 "number of points rejected:", rejected_points + fe_env%nr_rejected
253 WRITE (output_unit, *)
"Reject Nr.", my_reject,
" coarse grained points testing average"
259 DO i = ng_points, 1, -1
260 wrk(ii) = fe_env%cg_data(i)%var(j, k)
263 DO i = my_reject + 1, ng_points
265 my_reject = max(0, my_reject - 1)
269 CALL k_test(wrk, my_reject + 1, ng_points, tau, z, prob)
270 print *, prob, fe_env%conv_par%k_conf_lm
271 IF (prob < fe_env%conv_par%k_conf_lm)
EXIT
272 my_reject = my_reject + 1
274 my_reject = min(ng_points, my_reject)
277 rejected_points = my_reject*fe_env%conv_par%cg_width
278 fe_env%nr_rejected = fe_env%nr_rejected + rejected_points
279 trend_free = test_avg .AND. test_std
281 IF (output_unit > 0)
THEN
282 WRITE (output_unit, *)
"Kendall trend test (Std. Dev.)", test_std, &
283 "number of points rejected:", fe_env%nr_rejected
284 WRITE (output_unit, *)
"Reject Nr.", my_reject,
" coarse grained points testing standard dev."
285 WRITE (output_unit, *)
"Kendall test passed:", trend_free
288 CALL destroy_tmp_data(fe_env, wrk, ng_points)
289 CALL timestop(handle)
290 END SUBROUTINE ui_check_trend
301 SUBROUTINE create_tmp_data(fe_env, wrk, ng_points, ncolvar)
303 REAL(kind=
dp),
DIMENSION(:),
OPTIONAL,
POINTER :: wrk
304 INTEGER,
INTENT(IN) :: ng_points, ncolvar
308 ALLOCATE (fe_env%cg_data(ng_points))
310 ALLOCATE (fe_env%cg_data(i)%avg(ncolvar))
311 ALLOCATE (fe_env%cg_data(i)%var(ncolvar, ncolvar))
313 IF (
PRESENT(wrk))
THEN
314 ALLOCATE (wrk(ng_points))
316 END SUBROUTINE create_tmp_data
326 SUBROUTINE destroy_tmp_data(fe_env, wrk, ng_points)
328 REAL(kind=
dp),
DIMENSION(:),
OPTIONAL,
POINTER :: wrk
329 INTEGER,
INTENT(IN) :: ng_points
334 DEALLOCATE (fe_env%cg_data(i)%avg)
335 DEALLOCATE (fe_env%cg_data(i)%var)
337 DEALLOCATE (fe_env%cg_data)
338 IF (
PRESENT(wrk))
THEN
341 END SUBROUTINE destroy_tmp_data
351 SUBROUTINE create_csg_data(fe_env, ng_points, output_unit)
353 INTEGER,
INTENT(IN) :: ng_points, output_unit
355 INTEGER :: i, iend, istart
358 istart = fe_env%nr_points - (i)*fe_env%conv_par%cg_width + 1
359 iend = fe_env%nr_points - (i - 1)*fe_env%conv_par%cg_width
360 IF (output_unit > 0)
THEN
361 WRITE (output_unit, *) istart, iend
363 CALL eval_cov_matrix(fe_env, cg_index=i, istart=istart, iend=iend, output_unit=output_unit)
366 END SUBROUTINE create_csg_data
378 SUBROUTINE ui_check_norm_sc(fe_env, test_passed, nr_points, output_unit)
380 LOGICAL,
INTENT(OUT) :: test_passed
381 INTEGER,
INTENT(IN) :: nr_points, output_unit
383 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ui_check_norm_sc'
385 INTEGER :: handle, ng_points
387 CALL timeset(routinen, handle)
388 test_passed = .false.
389 DO WHILE (fe_env%conv_par%cg_width < fe_env%conv_par%max_cg_width)
390 ng_points = nr_points/fe_env%conv_par%cg_width
393 CALL ui_check_norm_sc_low(fe_env, nr_points, output_unit)
394 test_passed = fe_env%conv_par%test_vn .AND. fe_env%conv_par%test_sw
395 IF (test_passed)
EXIT
396 fe_env%conv_par%cg_width = fe_env%conv_par%cg_width + 1
397 IF (output_unit > 0)
THEN
398 WRITE (output_unit, *)
"New coarse grained width:", fe_env%conv_par%cg_width
401 IF (fe_env%conv_par%cg_width == fe_env%conv_par%max_cg_width .AND. (.NOT. (test_passed)))
THEN
402 CALL ui_check_norm_sc_low(fe_env, nr_points, output_unit)
403 test_passed = fe_env%conv_par%test_vn .AND. fe_env%conv_par%test_sw
405 CALL timestop(handle)
406 END SUBROUTINE ui_check_norm_sc
417 SUBROUTINE ui_check_norm_sc_low(fe_env, nr_points, output_unit)
419 INTEGER,
INTENT(IN) :: nr_points, output_unit
421 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ui_check_norm_sc_low'
423 INTEGER :: handle, i, j, k, ncolvar, ng_points
424 LOGICAL :: avg_test_passed, sdv_test_passed
425 REAL(kind=
dp) :: prob, pw, r, u, w
426 REAL(kind=
dp),
DIMENSION(:),
POINTER :: wrk
428 CALL timeset(routinen, handle)
429 ncolvar = fe_env%ncolvar
431 fe_env%conv_par%test_sw = .false.
432 fe_env%conv_par%test_vn = .false.
434 avg_test_passed = .true.
435 sdv_test_passed = .true.
436 ng_points = nr_points/fe_env%conv_par%cg_width
437 CALL create_tmp_data(fe_env, wrk, ng_points, ncolvar)
438 CALL create_csg_data(fe_env, ng_points, output_unit)
442 wrk(i) = fe_env%cg_data(i)%avg(j)
446 CALL sw_test(wrk, ng_points, w, pw)
447 print *, 1.0_dp - pw, fe_env%conv_par%sw_conf_lm
448 avg_test_passed = (1.0_dp - pw) <= fe_env%conv_par%sw_conf_lm
449 fe_env%conv_par%test_sw = avg_test_passed
450 IF (output_unit > 0)
THEN
451 WRITE (output_unit, *)
"Shapiro-Wilks normality test (Avg)", avg_test_passed
455 CALL vn_test(wrk, ng_points, r, u, prob)
456 print *, prob, fe_env%conv_par%vn_conf_lm
457 avg_test_passed = prob <= fe_env%conv_par%vn_conf_lm
458 fe_env%conv_par%test_vn = avg_test_passed
459 IF (output_unit > 0)
THEN
460 WRITE (output_unit, *)
"von Neumann serial correlation test (Avg)", avg_test_passed
464 IF (fe_env%conv_par%test_vn .AND. fe_env%conv_par%test_sw)
THEN
469 wrk(i) = fe_env%cg_data(i)%var(j, k)
473 CALL sw_test(wrk, ng_points, w, pw)
474 print *, 1.0_dp - pw, fe_env%conv_par%sw_conf_lm
475 sdv_test_passed = (1.0_dp - pw) <= fe_env%conv_par%sw_conf_lm
476 fe_env%conv_par%test_sw = fe_env%conv_par%test_sw .AND. sdv_test_passed
477 IF (output_unit > 0)
THEN
478 WRITE (output_unit, *)
"Shapiro-Wilks normality test (Std. Dev.)", sdv_test_passed
482 CALL vn_test(wrk, ng_points, r, u, prob)
483 print *, prob, fe_env%conv_par%vn_conf_lm
484 sdv_test_passed = prob <= fe_env%conv_par%vn_conf_lm
485 fe_env%conv_par%test_vn = fe_env%conv_par%test_vn .AND. sdv_test_passed
486 IF (output_unit > 0)
THEN
487 WRITE (output_unit, *)
"von Neumann serial correlation test (Std. Dev.)", sdv_test_passed
491 CALL destroy_tmp_data(fe_env, wrk, ng_points)
493 CALL destroy_tmp_data(fe_env, wrk, ng_points)
495 CALL timestop(handle)
496 END SUBROUTINE ui_check_norm_sc_low
508 SUBROUTINE ui_check_convergence(fe_env, converged, nr_points, output_unit)
510 LOGICAL,
INTENT(OUT) :: converged
511 INTEGER,
INTENT(IN) :: nr_points, output_unit
513 CHARACTER(LEN=*),
PARAMETER :: routinen =
'ui_check_convergence'
515 INTEGER :: handle, i, ic, ncolvar, ng_points
516 LOGICAL :: test_passed
517 REAL(kind=
dp) :: max_error_avg, max_error_std
518 REAL(kind=
dp),
DIMENSION(:),
POINTER :: avg_std, avgmx
519 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: cov_std, covmx
521 CALL timeset(routinen, handle)
523 ncolvar = fe_env%ncolvar
524 NULLIFY (avgmx, avg_std, covmx, cov_std)
525 CALL ui_check_norm_sc(fe_env, test_passed, nr_points, output_unit)
526 IF (test_passed)
THEN
527 ng_points = nr_points/fe_env%conv_par%cg_width
530 CALL create_tmp_data(fe_env, ng_points=ng_points, ncolvar=ncolvar)
531 CALL create_csg_data(fe_env, ng_points, output_unit)
532 ALLOCATE (covmx(ncolvar, ncolvar))
533 ALLOCATE (avgmx(ncolvar))
534 ALLOCATE (cov_std(ncolvar*(ncolvar + 1)/2, ncolvar*(ncolvar + 1)/2))
535 ALLOCATE (avg_std(ncolvar))
539 covmx = covmx + fe_env%cg_data(i)%var
540 avgmx = avgmx + fe_env%cg_data(i)%avg
542 covmx = covmx/real(ng_points, kind=
dp)
543 avgmx = avgmx/real(ng_points, kind=
dp)
546 CALL compute_avg_std_errors(fe_env, ncolvar, avgmx, covmx, avg_std, cov_std)
547 IF (output_unit > 0)
THEN
548 WRITE (output_unit, *)
"pippo", avgmx, covmx
549 WRITE (output_unit, *)
"pippo", avg_std, cov_std
552 max_error_avg = sqrt(maxval(abs(avg_std))/real(ng_points, kind=
dp))/minval(avgmx)
553 max_error_std = sqrt(maxval(abs(cov_std))/real(ng_points, kind=
dp))/minval(covmx)
554 IF (max_error_avg <= fe_env%conv_par%eps_conv .AND. &
555 max_error_std <= fe_env%conv_par%eps_conv) converged = .true.
557 IF (output_unit > 0)
THEN
558 WRITE (output_unit,
'(/,T2,"CG SAMPLING LENGTH = ",I7,20X,"REQUESTED ACCURACY = ",E12.6)') ng_points, &
559 fe_env%conv_par%eps_conv
560 WRITE (output_unit,
'(T50,"PRESENT ACCURACY AVG= ",E12.6)') max_error_avg
561 WRITE (output_unit,
'(T50,"PRESENT ACCURACY STD= ",E12.6)') max_error_std
562 WRITE (output_unit,
'(T50,"CONVERGED FE-DER = ",L12)') converged
564 WRITE (output_unit,
'(/,T33, "COVARIANCE MATRIX")')
565 WRITE (output_unit,
'(T8,'//
cp_to_string(ncolvar)//
'(3X,I7,6X))') (ic, ic=1, ncolvar)
567 WRITE (output_unit,
'(T2,I6,'//
cp_to_string(ncolvar)//
'(3X,E12.6,1X))') ic, covmx(ic, :)
569 WRITE (output_unit,
'(T33, "ERROR OF COVARIANCE MATRIX")')
570 WRITE (output_unit,
'(T8,'//
cp_to_string(ncolvar)//
'(3X,I7,6X))') (ic, ic=1, ncolvar)
572 WRITE (output_unit,
'(T2,I6,'//
cp_to_string(ncolvar)//
'(3X,E12.6,1X))') ic, cov_std(ic, :)
575 WRITE (output_unit,
'(/,T2,"COLVAR Nr.",18X,13X,"AVERAGE",13X,"STANDARD DEVIATION")')
576 WRITE (output_unit,
'(T2,"CV",I8,21X,7X,E12.6,14X,E12.6)') &
577 (ic, avgmx(ic), sqrt(abs(avg_std(ic))), ic=1, ncolvar)
579 CALL destroy_tmp_data(fe_env, ng_points=ng_points)
585 CALL timestop(handle)
586 END SUBROUTINE ui_check_convergence
600 SUBROUTINE compute_avg_std_errors(fe_env, ncolvar, avgmx, covmx, avg_std, cov_std)
602 INTEGER,
INTENT(IN) :: ncolvar
603 REAL(kind=
dp),
DIMENSION(:),
POINTER :: avgmx
604 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: covmx
605 REAL(kind=
dp),
DIMENSION(:),
POINTER :: avg_std
606 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: cov_std
608 INTEGER :: i, ind, j, k, nvar
610 REAL(kind=
dp),
DIMENSION(:),
POINTER :: awrk, eig, tmp
611 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: wrk
616 ALLOCATE (wrk(nvar, nvar))
618 fac = real(
SIZE(fe_env%cg_data), kind=
dp)
621 DO k = 1,
SIZE(fe_env%cg_data)
624 wrk(i, j) = wrk(i, j) + fe_env%cg_data(k)%avg(i)*fe_env%cg_data(k)%avg(j)
630 wrk(i, j) = wrk(i, j) - avgmx(i)*avgmx(j)*
fac
631 wrk(j, i) = wrk(i, j)
634 wrk = wrk/(
fac - 1.0_dp)
643 nvar = ncolvar*(ncolvar + 1)/2
644 ALLOCATE (wrk(nvar, nvar))
646 ALLOCATE (awrk(nvar))
654 awrk(ind) = covmx(i, j)
657 DO k = 1,
SIZE(fe_env%cg_data)
662 tmp(ind) = fe_env%cg_data(k)%var(i, j)
667 wrk(i, j) = wrk(i, j) + tmp(i)*tmp(j) - awrk(i)*awrk(j)
673 wrk(i, j) = wrk(i, j) -
fac*awrk(i)*awrk(j)
674 wrk(j, i) = wrk(i, j)
677 wrk = wrk/(
fac - 1.0_dp)
684 cov_std(i, j) = eig(ind)
685 cov_std(j, i) = cov_std(i, j)
693 END SUBROUTINE compute_avg_std_errors
707 SUBROUTINE eval_cov_matrix(fe_env, cg_index, istart, iend, output_unit, covmx, avgs)
709 INTEGER,
INTENT(IN) :: cg_index, istart, iend, output_unit
710 REAL(kind=
dp),
DIMENSION(:, :),
OPTIONAL,
POINTER :: covmx
711 REAL(kind=
dp),
DIMENSION(:),
OPTIONAL,
POINTER :: avgs
713 CHARACTER(LEN=*),
PARAMETER :: routinen =
'eval_cov_matrix'
715 INTEGER :: handle, ic, jc, jstep, ncolvar, nlength
716 REAL(kind=
dp) :: tmp_ic, tmp_jc
719 CALL timeset(routinen, handle)
720 ncolvar = fe_env%ncolvar
721 nlength = iend - istart + 1
722 fe_env%cg_data(cg_index)%avg = 0.0_dp
723 fe_env%cg_data(cg_index)%var = 0.0_dp
724 IF (nlength > 1)
THEN
726 DO jstep = istart, iend
728 cv => fe_env%uivar(ic)
729 tmp_ic = cv%ss(jstep)
730 fe_env%cg_data(cg_index)%avg(ic) = fe_env%cg_data(cg_index)%avg(ic) + tmp_ic
733 cv => fe_env%uivar(ic)
734 tmp_ic = cv%ss(jstep)
736 cv => fe_env%uivar(jc)
737 tmp_jc = cv%ss(jstep)
738 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 = fe_env%cg_data(cg_index)%var/real(nlength - 1, kind=
dp)
745 fe_env%cg_data(cg_index)%avg = fe_env%cg_data(cg_index)%avg/real(nlength, kind=
dp)
748 tmp_ic = fe_env%cg_data(cg_index)%avg(ic)
750 tmp_jc = fe_env%cg_data(cg_index)%avg(jc)*real(nlength, kind=
dp)/real(nlength - 1, kind=
dp)
751 fe_env%cg_data(cg_index)%var(jc, ic) = fe_env%cg_data(cg_index)%var(jc, ic) - tmp_ic*tmp_jc
752 fe_env%cg_data(cg_index)%var(ic, jc) = fe_env%cg_data(cg_index)%var(jc, ic)
755 IF (output_unit > 0)
THEN
756 WRITE (output_unit, *)
"eval_cov_matrix", istart, iend, fe_env%cg_data(cg_index)%avg, fe_env%cg_data(cg_index)%var
758 IF (
PRESENT(covmx)) covmx = fe_env%cg_data(cg_index)%var
759 IF (
PRESENT(avgs)) avgs = fe_env%cg_data(cg_index)%avg
761 CALL timestop(handle)
762 END SUBROUTINE eval_cov_matrix
777 SUBROUTINE dump_ac_info(my_val, my_par, dx, lerr, fe_section, nforce_eval, cum_res, &
779 REAL(kind=
dp),
DIMENSION(:),
POINTER :: my_val
780 CHARACTER(LEN=default_string_length), &
781 DIMENSION(:),
POINTER :: my_par
782 REAL(kind=
dp),
INTENT(IN) :: dx, lerr
784 INTEGER,
INTENT(IN) :: nforce_eval
785 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: cum_res
786 INTEGER,
POINTER :: istep
787 REAL(kind=
dp),
INTENT(IN) :: beta
789 CHARACTER(LEN=default_path_length) :: coupling_function
790 CHARACTER(LEN=default_string_length) :: def_error, par, this_error
791 INTEGER :: i, iforce_eval, ipar, isize, iw, j, &
793 REAL(kind=
dp) :: avg_bp, avg_det, avg_due, d_ene_w, dedf, &
794 ene_w, err, err_det, err_due, std_det, &
795 std_due, tmp, tmp2, wfac
802 DO i = 1,
SIZE(my_par)
803 IF (my_par(i) == par)
EXIT
805 cpassert(i <=
SIZE(my_par))
807 dedf =
evalfd(1, ipar, my_val, dx, err)
808 IF (abs(err) > lerr)
THEN
809 WRITE (this_error,
"(A,G12.6,A)")
"(", err,
")"
810 WRITE (def_error,
"(A,G12.6,A)")
"(", lerr,
")"
813 CALL cp_warn(__location__, &
814 'ASSERTION (cond) failed at line '//
cp_to_string(__line__)// &
815 ' Error '//trim(this_error)//
' in computing numerical derivatives larger then'// &
816 trim(def_error)//
' .')
823 CALL compress(coupling_function, full=.true.)
824 CALL parsef(2, trim(coupling_function), my_par)
825 ene_w =
evalf(2, my_val)
826 d_ene_w =
evalfd(2, ipar, my_val, dx, err)
827 IF (abs(err) > lerr)
THEN
828 WRITE (this_error,
"(A,G12.6,A)")
"(", err,
")"
829 WRITE (def_error,
"(A,G12.6,A)")
"(", lerr,
")"
832 CALL cp_warn(__location__, &
833 'ASSERTION (cond) failed at line '//
cp_to_string(__line__)// &
834 ' Error '//trim(this_error)//
' in computing numerical derivatives larger then'// &
835 trim(def_error)//
' .')
839 IF (istep > nequilstep)
THEN
840 isize =
SIZE(cum_res, 2) + 1
842 cum_res(1, isize) = dedf
843 cum_res(2, isize) = dedf - d_ene_w
844 cum_res(3, isize) = ene_w
847 avg_det = sum(cum_res(1, 1:isize))/real(isize, kind=
dp)
848 std_det = sum(cum_res(1, 1:isize)**2)/real(isize, kind=
dp)
850 avg_bp = sum(cum_res(3, 1:isize))/real(isize, kind=
dp)
853 wfac = wfac + exp(beta*(cum_res(3, j) - avg_bp))
859 tmp2 = exp(beta*(cum_res(3, j) - avg_bp))/wfac
860 avg_due = avg_due + tmp*tmp2
861 std_due = std_due + tmp**2*tmp2
864 err_due = sqrt(std_due - avg_due**2)/sqrt(real(isize - 1, kind=
dp))
865 err_det = sqrt(std_det - avg_det**2)/sqrt(real(isize - 1, kind=
dp))
869 extension=
".free_energy")
871 WRITE (iw,
'(T2,79("-"),T37," oOo ")')
872 DO iforce_eval = 1, nforce_eval
873 WRITE (iw,
'(T2,"ALCHEMICAL CHANGE| FORCE_EVAL Nr.",I5,T48,"ENERGY (Hartree)= ",F15.9)') &
874 iforce_eval, my_val(iforce_eval)
876 WRITE (iw,
'(T2,"ALCHEMICAL CHANGE| DERIVATIVE OF TOTAL ENERGY [ PARAMETER (",A,") ]",T66,F15.9)') &
878 WRITE (iw,
'(T2,"ALCHEMICAL CHANGE| DERIVATIVE OF BIASED ENERGY [ PARAMETER (",A,") ]",T66,F15.9)') &
879 trim(par), dedf - d_ene_w
880 WRITE (iw,
'(T2,"ALCHEMICAL CHANGE| BIASING UMBRELLA POTENTIAL ",T66,F15.9)') &
884 WRITE (iw,
'(/,T2,"ALCHEMICAL CHANGE| DERIVATIVE TOTAL FREE ENERGY ",T50,F15.9,1X,"+/-",1X,F11.9)') &
886 WRITE (iw,
'(T2,"ALCHEMICAL CHANGE| DERIVATIVE UNBIASED FREE ENERGY ",T50,F15.9,1X,"+/-",1X,F11.9)') &
889 WRITE (iw,
'(/,T2,"ALCHEMICAL CHANGE| DERIVATIVE TOTAL FREE ENERGY ",T50,F15.9,1X,"+/-",1X,T76,A)') &
891 WRITE (iw,
'(T2,"ALCHEMICAL CHANGE| DERIVATIVE UNBIASED FREE ENERGY ",T50,F15.9,1X,"+/-",1X,T76,A)') &
894 WRITE (iw,
'(T2,79("-"))')
899 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.