From: Axel Kohlmeyer (
Date: Mon Nov 02 2015 - 10:51:24 CST

On Mon, Nov 2, 2015 at 4:06 AM, sunyeping <> wrote:
> 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"]

looks to me as if you need to read the namdenergy plugin documentation
more carefully. especially the following line:

Output file (-ofile FILE): Gives the name of the file for final energy
output to be printed to. If not specified, output will be printed to
the vmd console.

> namdenergy -ofile $file -vdw -elec -nonb -sel $sel3 $sel2 -tempname namd -switch 10 -cutoff 12

this line offers the name of the *file object* (so typically something
like file2 or file3) as argument.
if you want it to write to the file named output<frameno>.dat the line
would have to be:

 namdenergy -ofile "output$i.dat" -vdw -elec -nonb -sel $sel3 $sel2
-tempname namd -switch 10 -cutoff 12

and you *must* not open and close that file yourself, as that would
create an access conflict and leave it to chance whether you get to
see the output or an empty file.


> 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

Dr. Axel Kohlmeyer
College of Science & Technology, Temple University, Philadelphia PA, USA
International Centre for Theoretical Physics, Trieste. Italy.