Skip to content

Commit

Permalink
Use calcenergy & calcforces to avoid evolving the bias during exchanges
Browse files Browse the repository at this point in the history
  • Loading branch information
giacomofiorin committed Oct 7, 2024
1 parent af1284b commit 6b3e16a
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
6 changes: 4 additions & 2 deletions colvartools/namd/colvars_replica_utils.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}

Expand Down
2 changes: 1 addition & 1 deletion doc/cvscript-fix-modify.tex
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
\\
Expand Down
2 changes: 1 addition & 1 deletion doc/cvscript-tcl.tex
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
\\
Expand Down
5 changes: 3 additions & 2 deletions src/colvarscript_commands_bias.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
"",
Expand Down

0 comments on commit 6b3e16a

Please sign in to comment.