Re: Is there a way to stop a MD run before the END_OF_RUN timestep?

From: Cardenas, Alfredo E (
Date: Tue May 26 2020 - 14:44:22 CDT

Hi Josh,
Thanks for the link to the scripting guide. I have tried some variants of what you suggested but I can't make it work. Here is part of the conf file that contain the evaluation of the colvars. Actually the script needs to evaluate ten's to hundred's of different colvars (distances) and it stops when a given colvar (that initially has the lowest value of the list of colvars, associated with anchor 1 in the example below) is not the lowest anymore. At that moment, the run stop with an exit. To capture coor and vel for the exit event, restartfreq would have to be small, that makes the run very slow.

colvars on
colvarsConfig colvar_free.conf
set anchor1 1
proc calc_colvar_forces { ts } {
global anchor1 anchor2
set list [cv list]
set i 1
set minV [lindex $list 0]
set minC $i
foreach colv $list {
set col [ expr abs([cv colvar $colv value])]
if {$col < $minV} {
set minV $col
set minC $i
incr i
if {$minC != $anchor1} {
print $ts $minC $minV
cv printframe
cv save stop
print "hit new colvar"
#run 1
#print " after run 1"
#### pick exit command depands on the cluster ###
run 50000

It would be fine with me if the coor and vel are written one step after the "hit new colvar" so that is why I tried to place run 1 before the exit command. If I uncomment the "run 1" line I get an error:
TCL: 202 3 1.11704898925451
colvars: The restart output state file will be "pet_dopc.restart.colvars.state".
colvars: The final output state file will be "stop.colvars.state".
colvars: Saving collective variables state to "stop.colvars.state".
TCL: hit new colvar
colvars: Error while executing calc_colvar_forces:
colvars: number of steps must be a multiple of stepsPerCycle
FATAL ERROR: Error in the collective variables module (see above for details): No such file or directory
[Partition 0][Node 0] End of program

The stepsPerCycle=20 in my simulation, and according to the script guide I don't think I can change that value with scripting. Actually I also tried "run 20". In that case the run seems stalled without exiting
TCL: hit new colvar
TCL: Original numsteps 50000 will be ignored.
TCL: Running for 20 steps

Maybe calc_colvar_forces procedure is incompatible with setting different run values? But also run 1 seems to have additional problems because I don't know how to change stepsperCycle or as you mentioned pairlistfreq. Using small values for those parameters from the beginning would not be good. By the way, I am using NAMD 2.14b1

From: Josh Vermaas <>
Sent: Monday, May 25, 2020 5:35 PM
To: NAMD list <>; Cardenas, Alfredo E <>
Subject: Re: namd-l: Is there a way to stop a MD run before the END_OF_RUN timestep?

Hi Alfredo,

Based on my reading of the scripting guide (, you could do something like this, having an outer loop that runs at a less frequent restart rate until you get close. Then you'd use the "output" feature to force the writing of the .coor, .vel, and .xsc files:

set isfar 1
while { $isfar } {
run 1000
#Insert some code to check the cv value and whatever threshold you are interested in.
#I assume you have this already, and that you are waiting for the value to be greater than the threshold.
if { $cvvalueyoucomputed > $somethreshold } {
set isfar 0
while { $isfar == 0 } {
#Now that you are close, run 1 step at a time, and force outputs if needed.
run 1
#Insert some code to check the cv value and whatever threshold you are interested in.
if { $cvvalueyoucomputed <= $somethreshold } {
#This lets you go back to efficient running if the simulation slides back.
set isfar 1
if { $cvvalueyoucomputed > $targetthreshold } {
#If you reach your target, write a set of output files immediately, and kill the simulation.
output targetreached

The trick is going to be that as soon as you make it into the inner loop, your performance is going to be garbage, and the other things that are required so that you can run 1 step at a time (I think your pairlistfreq needs to be 1) also make your performance not great. When I wanted to kill simulations after they had made sufficient progress, I'd just only check every 1000 steps or so, since the amount of extra compute time that I saved having pairlistfreq be something reasonable more than made up for overrunning my target.


On Sun, May 24, 2020 at 11:37 PM Cardenas, Alfredo E <<>> wrote:
I use certain TCL script in a NAMD conf file to evaluate certain colvars during the run. When certain values of the colvars are reached the simulation is kill. We need to save the coor, vel and xsc files at the timestep when the colvar condition is satisfied. To do that we use a very small restartfreq value and that evidently slows the simulation. I wonder if there is a way to trick NAMD, to change on the flight the END_OF_RUN or FILE_OUTPUT values so it could write those files when the colvars conditions are satisfied without the need to write restart files too often. If not, any other suggestion to do this will be appreciated. For example, there are ways to print out complete coor, vel and xsc in TCL scripts?

This archive was generated by hypermail 2.1.6 : Thu Dec 31 2020 - 23:17:13 CST