From: John Stone (johns_at_ks.uiuc.edu)
Date: Mon Nov 02 2015 - 10:32:27 CST

Hi,
  I wonder about the use of a variable name that's the same as a
built-in Tcl command. Just for the sake of paranoia, I would replace
your "file" variable name with "outfile" or something else that is not
also the name of a built-in command. Beyond that, I would suggest that
you consider adding calls to "puts" at the points where you are emitting
output to your file so you can verify that your code is operating as
expected when run on a short interactive test run.

Cheers,
  John Stone
  vmd_at_ks.uiuc.edu

On Mon, Nov 02, 2015 at 07:54:58PM +0800, sunyeping wrote:
> Hi, Fotis
> Thank you for your reply. But strangely, add "flush $file" to the script
> doesn't work as expected. And Even all the namdenergy calculations are
> finished normally, the output files are still empty.
> Best regards.
>
> Yeping Sun
>
> Institute of Microbiology, Chinese Academy of Sciences
>
> ------------------------------------------------------------------
> From:Fotis Baltoumas <fbaltoumas_at_biol.uoa.gr>
> Time:2015 Nov 2 (Mon) 18:48
> To:aa*ae,*aa^1^3 <sunyeping_at_aliyun.com>
> Cc:vmd-l <vmd-l_at_ks.uiuc.edu>
> Subject:Re: vmd-l: Problems with vmd plugin namdenergy output
> Hello,
>
> 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."
>
> (http://wiki.tcl.tk/367 )
>
> So, if you absolutely need to see the output before the calculations are
> finished, you can try using "flush", as shown here:
>
> http://wiki.tcl.tk/1472
>
> 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."
>
> (https://www.tcl.tk/man/tcl8.5/tutorial/Tcl24.html )
>
> --
> *******************************************
> 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 : fbaltoumas_at_biol.uoa.gr
> http://biophysics.biol.uoa.gr
> http://bioinformatics.biol.uoa.gr
> *******************************************
>
> >
> > 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
> >

-- 
NIH Center for Macromolecular Modeling and Bioinformatics
Beckman Institute for Advanced Science and Technology
University of Illinois, 405 N. Mathews Ave, Urbana, IL 61801
http://www.ks.uiuc.edu/~johns/           Phone: 217-244-3349
http://www.ks.uiuc.edu/Research/vmd/