From: Fotis Baltoumas (
Date: Mon Nov 02 2015 - 04:48:11 CST


As far as the I/O is concerned, there's nothing wrong with your script.
It's just how Tcl works.

As we can read in the Tcl wiki, when it comes to file outputs the
following applies:

"note: When you are writing into a file , the contents of the file will
not be visible till the end of the execution of the TCL script. so if you
are going to use "tail -f " midway to check out , I am sorry to say you
will find that the size of the file will be 0. Its contents are visible
only after the file has finished executing. LV Of course, if there is a
need to see the file while it is open, just be certain your code invokes
flush, which will force the output to the file instead of waiting until
there is a large enough chunk of data to force out."

( )

So, if you absolutely need to see the output before the calculations are
finished, you can try using "flush", as shown here:

However, note the following:

(from the Tcl manual)

"The file I/O is buffered. The output may not be sent out when you expect
it to be sent. Files will all be closed and flushed when your program
exits normally, but may only be closed (not flushed) if the program is
terminated in an unexpected manner."

( )

Fotis A. Baltoumas
Phd Candidate, Bioinformatics Postgraduate Programme
Department of Cell Biology and Biophysics
Faculty of Biology, University of Athens
Panepistimiopolis, Athens 157 01, GREECE
email :
> Dear all,
> I am trying to use VMD plugin namdenergy to calculate the interaction
> potential between each reside of one segname of a protein with anoher
> segment of the protein, and write the results into a series of files. The
> following is the script:
> set sel1 [atomselect top "segname P3"]
> set sel2 [atomselect top "segname P1"]
> set n [llength [lsort -unique [$sel1 get resid]]] ;#return the number of the
> residues in segment P3
> set n0 [lindex [lsort -unique [$sel1 get resid]] 0] ;#return the index of the first residue
> of segment P3
> for {set i $n0} {$i<=$n} {incr i} {
>  set file [open output$i.dat w]   #generate an empty file for writing the
> calculation results of interaction energy between segment P1 and residue
> $i of segment P3 
>  set sel3 [atomselect top "segname P3 and resid $i"]
>  namdenergy -ofile $file
> -vdw -elec -nonb -sel $sel3 $sel2 -tempname namd -switch 10 -cutoff 12
>  close $file
> }
> However, when I source the script in VMD console, the files are indeed
> generated, and the namdenergy calculation are perfomed, but all the output
> files are empty until the calculation is finished. So what's wrong with
> the scripts?
> Thank you in advance.Yeping Sun
> Institute of Microbiology, Chinese Academy of Sciences