From 6b3e16ad9cc43b9a2c1738317c4fb1b0238d009d Mon Sep 17 00:00:00 2001 From: Giacomo Fiorin Date: Wed, 3 May 2023 10:33:39 -0400 Subject: [PATCH] Use calcenergy & calcforces to avoid evolving the bias during exchanges --- colvartools/namd/colvars_replica_utils.tcl | 6 ++++-- doc/cvscript-fix-modify.tex | 2 +- doc/cvscript-tcl.tex | 2 +- src/colvarscript_commands_bias.h | 5 +++-- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/colvartools/namd/colvars_replica_utils.tcl b/colvartools/namd/colvars_replica_utils.tcl index 1dddcb5c9..a2ccc8bf8 100644 --- a/colvartools/namd/colvars_replica_utils.tcl +++ b/colvartools/namd/colvars_replica_utils.tcl @@ -174,7 +174,8 @@ proc select_bias { i_bias } { # Now turn on the selected one foreach bias_name $bias_names(${i_bias}) { cv bias ${bias_name} set active 1 - cv bias ${bias_name} update + cv bias ${bias_name} calcenergy + cv bias ${bias_name} calcforces } # The dependency system may have turned off some variables, reactivate them @@ -215,7 +216,8 @@ proc share_bias_state { bias_name this_replica i j } { } if { ${this_replica} == ${j} } { cv bias ${bias_name} loadfromstring [replicaRecv ${i}] - cv bias ${bias_name} update + cv bias ${bias_name} calcenergy + cv bias ${bias_name} calcforces } } diff --git a/doc/cvscript-fix-modify.tex b/doc/cvscript-fix-modify.tex index 1a0a4f813..27e35b9d4 100644 --- a/doc/cvscript-fix-modify.tex +++ b/doc/cvscript-fix-modify.tex @@ -644,7 +644,7 @@ \begin{mdexampleinput}{} \texttt{\textbf{fix\_modify Colvars bias name calcforces}} \\ -\-~~~~\texttt{Recalculate the forces of this bias at the current colvar values} +\-~~~~\texttt{Recalculate the forces of this bias after a call to calcenergy} \\ \-~~~~\texttt{\textbf{Returns}} \\ diff --git a/doc/cvscript-tcl.tex b/doc/cvscript-tcl.tex index e1e59467c..2eae9472a 100644 --- a/doc/cvscript-tcl.tex +++ b/doc/cvscript-tcl.tex @@ -644,7 +644,7 @@ \begin{mdexampleinput}{} \texttt{\textbf{cv bias name calcforces}} \\ -\-~~~~\texttt{Recalculate the forces of this bias at the current colvar values} +\-~~~~\texttt{Recalculate the forces of this bias after a call to calcenergy} \\ \-~~~~\texttt{\textbf{Returns}} \\ diff --git a/src/colvarscript_commands_bias.h b/src/colvarscript_commands_bias.h index 3c211c088..facfa802d 100644 --- a/src/colvarscript_commands_bias.h +++ b/src/colvarscript_commands_bias.h @@ -77,7 +77,8 @@ CVSCRIPT(bias_calcenergy, "E : float - Energy value", 0, 0, "", - if (this_bias->calc_energy(NULL) != COLVARS_OK) { + if ( ( this_bias->colvarbias::update() | + this_bias->calc_energy(NULL) ) != COLVARS_OK) { script->add_error_msg("Error: recalculating energy of bias " + this_bias->name); return COLVARSCRIPT_ERROR; @@ -87,7 +88,7 @@ CVSCRIPT(bias_calcenergy, ) CVSCRIPT(bias_calcforces, - "Recalculate the forces of this bias at the current colvar values\n" + "Recalculate the forces of this bias after a call to calcenergy\n" "forces : array of colvarvalue objects - Applied colvar forces", 0, 0, "",