From: Axel Kohlmeyer (akohlmey_at_gmail.com)
Date: Thu Jan 07 2010 - 05:55:29 CST

> Axel,
>
> I agree with your comments, but these sorts of land-mines are not obvious
> with the TCL script.  For example, in the python environment, when the
> equivalent object is out of scope it is automatically freed.

even though the two examples you are quoting are doing the equivalent
thing, they are semantically different. main thing that people have to keep
in mind is that atomselect in tcl creates a new command and adds it to
the interpreter, in the python case you create an instance of a class.

> for i in range(Nframes)
>   atom = atomsel.atomsel('resid 25 and NE2', 0, i)
>   xa, ya, za = atom.get('x'), atom.get('y'), atom.get('z')
>
>
> everything is freed in a timely fashion with atomsel().  On the other hand,
> TCL requires the following
> for {set i 0} { $i < $Nframes} { incr i} {
>   set atom(0) [ atomselect $mol_ID "resid 25 and NE2"  frame $i ]
>   set xa(0) [ $atom(0) get x ]; set ya(0) [ $atom(0) get y ]; set za(0) [
> $atom(0) get z ]
>   $atom(0) delete
> }
>
> xa(0) etc are freed when they go out of scope, but, without "$atom(0)
> delete", atomselect is not.

for the sake of completeness, if you would rewrite this piece of code as:

proc getxyz {molid nframes} {

for {set i 0} { $i < $nframes} { incr i} {
  set atom(0) [ atomselect $molid "resid 25 and NE2" frame $i ]
  set xa(0) [ $atom(0) get x ]
  set ya(0) [ $atom(0) get y ]
  set za(0) [ $atom(0) get z ]
}
}

all the generated selection commands will be deleted as soon
as getxyz goes out of scope.

> So it is quite easy to unwittingly make the mistake of creating a memory
> leak with the TCL script as a result.

the key point is to understand what the atomselect command does.
then it is obvious. this is not really a TCL issue, but a VMD idiosyncrasy.

axel.

> Wayne -----------------------------------------------------------
> Bioinformation Engineering Laboratory
> Building 6
> Department of Biotechnology
> Division of Agriculture
> Graduate School of Agricultural and Life Sciences
> The University of Tokyo Yayoi 1-1-1, Bunkyo-ku, Tokyo 113-8657
>
> TEL          (+81)-3-5841-5449
> cellphone    (+81)-090-5312-9325
>
>

-- 
Dr. Axel Kohlmeyer    akohlmey_at_gmail.com
Institute for Computational Molecular Science
College of Science and Technology
Temple University, Philadelphia PA, USA.