From: Justin Gullingsrud (justin_at_ks.uiuc.edu)
Date: Sat Aug 25 2001 - 21:51:25 CDT

Hi,

Atom selections created within a foreach loop are not deleted until the
foreach loop ends, which is why you're seeing the large amount of memory
use. There are two solutions: either put the atom selection creation in
a separate proc and call it from within your foreach loop, or put the
command "unset upproc_var_$sel" where $sel is the name of your atom selection
at the end of your foreach loop.

I assume this means you already figured out your first question?

Justin

On Sun, Aug 26, 2001 at 09:54:48AM +0900, Dr. Paul Fons wrote:
> Hi in attempt to work on my construction of bonds, I quickly wrote the
> following code. The code seems to work but it uses an extravagent amount
> of memory for reasons I don't quite understand. I suspect that I am
> making numerous atomselect objects and not releasing memory. Does this
> mean I have to allocate a handle to each atomselect object so I can
> later manual delete it - e.g. embedding an atomselect object in a
> function reference (square brackets) does not result in a temporary
> stack allocated structure which automatically goes away. Anyway here is
> my attempt. Comments appreciated.
>
>
> proc makebonds {limit} { ;# generate bonds for an arbitrary structure
> puts "Zapping old bonds"
> zapbonds ;# zap all current bonds
> puts "Generating new bonds"
> set allatomlist [ [atomselect top "all"] list] ;# all atoms
> foreach atom1 $allatomlist { ;# loop over all atoms
> puts "Now working on neighbors of atom $atom1"
> foreach atom2 $allatomlist { ;# loop over all atoms
> if {$atom1 == $atom2} {continue}
> set atom1sel [atomselect top "index $atom1"]
> set atom2sel [atomselect top "index $atom2"]
> if {[measure rmsd $atom1sel $atom2sel] > $limit} {continue}
> set mybonds [$atom1sel getbonds]
> # puts stdout "Adding atom:$atom2 to atom $atom1 bond list"
> lappend mybonds $atom2 ;# append this neighbor to atoms list
> set mybonds [join $mybonds]
> # puts "the bond list is now: $mybonds"
> $atom1sel setbonds [list $mybonds]
> $atom1sel delete
> $atom2sel delete
> }
> }
> return 0
> }
>
> proc zapbonds {} {
> set allatomlist [[atomselect top "all"] list]
> foreach atom $allatomlist {
> set theatom [atomselect top "index $atom"]
> $theatom setbonds {{}}
> $theatom delete
> }
> return 0
> }

-- 
Justin Gullingsrud      3111 Beckman Institute
H: (217) 384-4220       I got a million ideas that I ain't even rocked yet...
W: (217) 244-8946       -- Mike D