From: John Stone (johns_at_ks.uiuc.edu)
Date: Fri Jan 23 2015 - 11:39:51 CST

Hi,
  Okay, the next problem you have is that in several places in your
scripts you're creating atom selections which are immediately "leaked"
because you don't assign them to a variable and delete them:
    set lists [measure contacts 10 [atomselect top "name OW"] $sel];

So, for the line above, you need to rewrite it more like this:
    set owsel [atomselect top "name OS"]
    set lists [measure contacts 10 $owsel $sel];
    $owsel delete
 
I saw several places in your code that have this sort of problem.
 
Cheers,
  John Stone
  vmd_at_ks.uiuc.edu

On Fri, Jan 23, 2015 at 11:46:57AM +0000, MannyEful E wrote:
> Thank you John,
>
> I have made the changes you've suggested (the areas labelled with
> arrows).A And have also tried the same for the nwat process for good
> measure.
>
> Although the script runs faster, vmd still crashes.
>
> Script:
> ##################################################################################
> #: TitleA A A A A A : q4_calc.tclA A A A A A A A A A A A A A A
> A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
> A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
> A A A A A A A A A A A A A A A #
> #: Description : Get the tetrahedral orientation parameter for
> watersA A A A A A A A A A A A A A A A A A A A A A A A A A A A
> A A A A A A A A A A A A A #
> #: Usage:A A A A A A A A A A A vmd -dispdev text -gro test.gro -e
> q4_calc_bulk.tcl A A A A A A A A A A A A A A A A A A A A A A A A
> A A A A A A A A A A A A A A A A #
> ##################################################################################
>
> proc angle {Di Hi Ai} {
>
> # Calculates angles between three points
> # select atoms
> set selD [atomselect top "resid $Di and name OW"];A A A A A # select
> atom1
> set selH [atomselect top "index $Hi and name OW"];A A A A # select atom2
> set selA [atomselect top "resid $Ai and name OW"];A A A A A # select
> atom3
> A
> # obtain corresponding coordinates
> set D [lindex [$selD get {x y z}] 0];
> set H [lindex [$selH get {x y z}] 0];
> set A [lindex [$selA get {x y z}] 0];
>
> # obtain cosine of the angle between the 3 selected atoms
> A global M_PI;A A A A A A A A A A A A A A A A A A A A # get pi value
> A set hd [vecsub $D $H];A A A A # calculate hd vector
> A set ha [vecsub $A $H];A A A A # calculate ha vector
> A set cosine [expr [vecdot $hd $ha] / ( [veclength $hd] * [veclength
> $ha])];A A # calculate cosine
>
> # delete variables we do not need any moreA <----
> A $selD delete; array unset selD;
> A $selH delete;array unset selH;
> A $selA delete;array unset selA;
> A array unset D;
> A array unset H;
> A array unset A;
> A array unset hd;
> A array unset ha;
> A unset Di;
> A unset Hi;
> A unset Ai;
>
> # return [expr acos($cosine)*(180.0/$M_PI)]; A A # convert cosine to
> angle in degreesA A
> A return $cosine
> A
> }
>
> proc nwat {n sel} {
> A # Calculates the n nearest neighbours
> A # reset the l3 variables to become an empty array
> A set l3 {};
>
> A # find the oxygens within 10 angstroms of the selection
> A set lists [measure contacts 10 [atomselect top "name OW"] $sel];
>
> A # obtains the list of oxygens indices
> A set wlist [lindex $lists 0];
>
> A # obtain the list of the selection atoms indices
> A set slist [lindex $lists 1];
>
> A # for every listed selection and its corresponding oxygen
> A # get the residue number for the oxygen
> A # get the distance between the twoA
> A # appends this distance and corresponding resids to a list called l1
> A foreach satom $slist watom $wlist {
> A A A set wresnum [[atomselect top "index $watom"] get resid];
> A A A set d [measure bond "$watom $satom"];
> A A A lappend l1 [list $wresnum $d];
> A }
>
> A # make a variable called l1 which sorts out the 4 closest distancesA
> A # appends the 4 atom resids to a list called l3
> A set l2 [lrange [lsort -index 1 [lsort -unique -index 0 [lsort -index 1
> -decreasing $l1]]] 0 [expr $n - 1]];
> A #puts " F ";A
> A foreach water $l2 {
> A A A lappend l3 "[lindex $water 0]";
> A }
>
> # delete variables we do not need any moreA A <----
> A array unset n;
> A array unset $sel;
> A array unset lists;
> A array unset wlist;
> A array unset slist;
> A array unset satom;
> A array unset watom;
> A array unset wresnum;
> A array unset d;
> A array unset l1;
> A array unset l2;
>
> A # returns a list of resids for the 4 nearest
> A return $l3;
>
> }
>
> # assign a filename
> ##A set q_file [open "q_19Jan2015_sla_260K_0-3_8.txt" w];
>
> # define the number of frames
> set end 3;
> A
> # make a selection for which q will be calculated
> set total_wat [atomselect top "name OW and (resname SLA) "];A
> A A
> # loop through all the framesA
> for { set i 0 } { $i < $end } { incr i} {A
> A
> A A A A A A # go to the specified frame
> A A A A A A animate goto $i;
> A A A A A
> A A A A A A # selection refreshed for the new frame
> A A A A A A $total_wat frame $i;
>
> A A A A A A # counts the number of atoms selected
> A A A A A A set num_Totalwat [$total_wat num];
> A A A A A
> A A A A A A # get the residue indices and atom indices for selection
> A A A A A A set wat_resid [$total_wat get resid];
> A A A A A A set wat_index [$total_wat get index];
>
> A A A A A A # sets a counter to zero
> A A A A A A set checkingNums 0;
>
> A A A A A A # for each water we do the following
> A A A A A A foreach waterID $wat_index waterRID $wat_resid {
>
> A A A A A A # add 1 to the counter and print out so we know how far into
> the loop we have gone
> A A A A A A incr checkingNums;
> A A A A A A puts " WATER $checkingNums OF $num_Totalwat ";A
> A A A A A A A A
> A A A A A A # make a temporary selection using the atom indices and
> residue indicesA A
> A A A A A A set wat_coord [atomselect top "name OW and index $waterID and
> resid $waterRID"];A
> A
> A A A A A A # find the 4 closest waters to this atom
> A A A A A A set close_wat [nwat 4 $wat_coord];
>
> A A A A A # Find all the possible 3 angle combinations which can be made
> with the 4 neighbour whilst wat_coord is at the centre
> A A A # set the sum to zero A A A A A A A A A A A A A A A A A A A A A
> A A A A A A set sum 0.0;
>
> A A A A A A # set counter to zero
> A A A A A A set countAngles 0;
> A A A A A A for { set k 0 } { $k < 4 } { incr k } {A
> A A A A A A A A A A for { set l [expr $k+1] } { $l < 4 } { incr l } {A
>
> A A A A A A A A A A A A A A # add 1 to angles which have been calculated.
> The final value should always be 6 for 4 neighbours.
> A A A A A A A A A A A A A A incr countAngles;
>
> A A A A A A A A A A A A A A # select the first atom index
> A A A A A A A A A A A A A A set hi1 "[lindex $close_wat $k]";
>
> A A A A A A A A A A A A A A # select the reference atom index
> A A A A A A A A A A A A A A set atom2 [[atomselect top "name OW and
> (index $waterID and resid $waterRID)"] get {index}];
>
> A A A A A A A A A A A A A A # select the third atom indexA
> A A A A A A A A A A A A A A set hi3 "[lindex $close_wat $l]";A
>
> A A A A A A A A A A A A A A # calculate the angle usin proc calcangle
> defined earlier
> A A A A A A A A A A A A A A set calcangle [angle $hi1 $atom2 $hi3];
> A
> A A A A A A A A A A A A A A # add up cosine results to those from
> previous angles
> A A A A A A A A A A A A A A set sum [expr
> {(($calcangle+1.0/3.0)*($calcangle+1.0/3.0))+$sum}];
> A
> A A A A A A A A A A }A
> A A A A A A }
> A
> A A A A A # define the q value
> A A A A A A set q [expr {1.0-((3.0/8.0)*$sum)}];
>
> A A A A A A # print theA A A A FrameA A A A A A A Loop
> numberA A A A A A A Atom index A A A A A A A Q valueA A A A details to
> file
> A A A A A A puts [format "Frame: $i\t ID: $checkingNums \t AtomIDX:
> $waterID \t Q: %.2f"A A $q];
> A
> ##A puts $q_file "ID: $checkingNumsA A A AtomIDX: $waterIDA A Q: $q";A
> # print details to file
> A
> A A A A }
>
> A A A A A # delete variables we do not need any moreA A A A A A
> A A A A A $wat_coord delete; array unset wat_coord;
> A A A A A $close_wat delete; array unset close_wat;
> A A A A A $k delete; array unset k;
> A A A A A $l delete; array unset l;
> A A A A A $hi1 delete; array unset hi1;
> A A A A A $atom2 delete; array unset atom2;
> A A A A A $hi3 delete; array unset hi3;
> A A A A A $calcangle delete; array unset calcangle;
> A A A A A $sum delete; array unset sum;
> A A A A A $q delete; array unset q;
> A A A A A A
>
> ##A A puts $q_file "END"; # add END line after every frame
>
> # delete variables we do not need any moreA A
> A $total_wat delete; array unset total_wat;
> A $num_Totalwat delete; array unset num_Totalwat;
> A $wat_resid $delete; array unset wat_resid;
> A $wat_index delete; array unset wat_index;
> A $waterID delete; array unset waterID;
> A $waterRID delete; array unset waterRID;
> A $checkingNums delete; array unset checkingNums;
> A $countAngles delete; array unset countAngles;
> A
> A A }A
>
> ##A A puts $q_file " "; # add empty newline to file
>
> ##A A close $q_file;A A A # close file
>
> # delete variables we do not need any moreA A
> $total_wat delete;
> A
> A
>
> END
> On Fri, Jan 23, 2015 at 6:20 AM, John Stone <[1]johns_at_ks.uiuc.edu> wrote:
>
> Hi,
> A Your return statement in the angle proc occurs before you
> call the $sel delete commands, so they are not being executed at all.
> Move the return statement so it is the last line of the proc and that
> should cure your problem assuming there aren't other issues that I
> didn't see.
>
> Cheers,
> A John Stone
> A [2]vmd_at_ks.uiuc.edu
> On Fri, Jan 23, 2015 at 05:18:10AM +0000, MannyEful E wrote:
> >A A Hello Everyone,
> >
> >A A I wrote a script to calculate the tetrahedral orientation order
> parameter
> >A A of liquid water over time. Could anyone advise me on what causes
> VMD to be
> >A A killed despite the use of "$sel delete" / "unset sel" / "array
> unset sel"?
> >A A I imagine that this is a memory leak problem, however I can't
> spot it.
> >
> >A A Thanks in advanced for your time and help!
> >
> >A A Script:
> >A A
> ##################################################################################
> >A A #: TitleA A A A A AA : q4_calc.tclA A AA A A AA A A AA A A
> AA A A A
> >A A A A AA A A AA A AA A A AA A A AA A A AA A A AA A A AA A A
> AA A AA A A A
> >A A A A AA A A AA A A AA A A AA A A AA A AA A A AA A A AA A A
> AA A A AA A A A
> >A A A A AA A AA A A AA A A AA A A AA AA #
> >A A #: Description : Get the tetrahedral orientation parameter for
> >A A watersA A AA A A AA AA AA A A AA A A AA A A AA A A AA A A
> AA A A A AA A
> >A A A A AA A A AA A A AA A A A AA #
> >A A #: Usage:A A A A A A A A A A AA vmd -dispdev text -gro test.gro
> -e
> >A A q4_calc_bulk.tcl A A AA A A AA A A AA A A AA A A AA A A AA
> A A AA A A A
> >A A A A AA AA AA A A AA A A AA A A AA A AA #
> >A A
> ##################################################################################
> >
> >A A proc angle {Di Hi Ai} {
> >
> >A A # Calculates angles between three points
> >A A # select atoms
> >A A set selD [atomselect top "resid $Di and name OW"];A A A A AA #
> select
> >A A atom1
> >A A set selH [atomselect top "index $Hi and name OW"];A A A AA #
> select atom2
> >A A set selA [atomselect top "resid $Ai and name OW"];A A A A AA #
> select
> >A A atom3
> >A A A
> >A A # obtain corresponding coordinates
> >A A set D [lindex [$selD get {x y z}] 0];
> >A A set H [lindex [$selH get {x y z}] 0];
> >A A set A [lindex [$selA get {x y z}] 0];
> >
> >A A # obtain cosine of the angle between the 3 selected atoms
> >A A A global M_PI;A A A A A A A A A A A A A A A A A A A AA # get pi
> value
> >A A A set hd [vecsub $D $H];A A A AA # calculate hd vector
> >A A A set ha [vecsub $A $H];A A A AA # calculate ha vector
> >A A A set cosine [expr [vecdot $hd $ha] / ( [veclength $hd] *
> [veclength
> >A A $ha])];AA AA # calculate cosine
> >
> >A A # return [expr acos($cosine)*(180.0/$M_PI)]; A AA # convert
> cosine to
> >A A angle in degreesAA A
> >A A AA return $cosine
> >A A A
> >A A # delete variables we do not need any moreA
> >A A $Di delete;
> >A A $Hi delete;
> >A A $Ai delete;
> >A A $selD delete;
> >A A $selH delete;
> >A A $selA delete;
> >A A $D delete;
> >A A $H delete;
> >A A $A delete;
> >A A $hd delete;
> >A A $ha delete;
> >A A A
> >A A }
> >
> >A A proc nwat {n sel} {
> >A A AA # Calculates the n nearest neighbours
> >A A AA # reset the l3 variables to become an empty array
> >A A AA set l3 {};
> >
> >A A AA # find the oxygens within 10 angstroms of the selection
> >A A AA set lists [measure contacts 10 [atomselect top "name OW"]
> $sel];
> >
> >A A AA # obtains the list of oxygens indices
> >A A AA set wlist [lindex $lists 0];
> >
> >A A AA # obtain the list of the selection atoms indices
> >A A AA set slist [lindex $lists 1];
> >
> >A A AA # for every listed selection and its corresponding oxygen
> >A A AA # get the residue number for the oxygen
> >A A AA # get the distance between the twoA
> >A A AA # appends this distance and corresponding resids to a list
> called l1
> >A A AA foreach satom $slist watom $wlist {
> >A A A A AA set wresnum [[atomselect top "index $watom"] get resid];
> >A A A A AA set d [measure bond "$watom $satom"];
> >A A A A AA lappend l1 [list $wresnum $d];
> >A A AA }
> >
> >A A AA # make a variable called l1 which sorts out the 4 closest
> distancesA
> >A A AA # appends the 4 atom resids to a list called l3
> >A A AA set l2 [lrange [lsort -index 1 [lsort -unique -index 0 [lsort
> -index 1
> >A A -decreasing $l1]]] 0 [expr $n - 1]];
> >A A AA #puts " F ";A
> >A A AA foreach water $l2 {
> >A A A A AA lappend l3 "[lindex $water 0]";
> >A A AA }
> >
> >A A AA # returns a list of resids for the 4 nearest
> >A A AA return $l3;
> >
> >A A # delete variables we do not need any moreAA A
> >A A array unset $selD;
> >A A array unset $selA;
> >A A array unset $selH;
> >A A array unset $D;
> >A A array unset $A;
> >A A array unset $H;
> >A A $Di delete; unset Di;
> >A A $Hi delete; unset Hi;
> >A A $Ai delete; unset Ai;
> >A A $selD delete; array unset selD;
> >A A $selH delete;array unset selH;
> >A A $selA delete;array unset selA;
> >A A $D delete;array unset D;
> >A A $H delete;array unset A;
> >A A $A delete; array unset A;
> >A A $hd delete;array unset hd;
> >A A $ha delete;array unset ha;
> >A A A
> >A A }
> >
> >A A # assign a filename
> >A A ##AA set q_file [open "q_19Jan2015_sla_260K_0-3_8.txt" w];
> >
> >A A # define the number of frames
> >A A set end 3;
> >A A A
> >A A # make a selection for which q will be calculated
> >A A set total_wat [atomselect top "name OW and (resname SLA) "];A
> >A A A A
> >A A # loop through all the framesA
> >A A for { set i 0 } { $i < $end } { incr i} {A
> >A A A
> >A A A A A A A AA # go to the specified frame
> >A A A A A A A AA animate goto $i;
> >A A A A A A A
> >A A A A A A A AA # selection refreshed for the new frame
> >A A A A A A A AA $total_wat frame $i;
> >
> >A A A A A A A AA # counts the number of atoms selected
> >A A A A A A A AA set num_Totalwat [$total_wat num];
> >A A A A AA A A
> >A A A A A A A AA # get the residue indices and atom indices for
> selection
> >A A A A A A A AA set wat_resid [$total_wat get resid];
> >A A A A A A A AA set wat_index [$total_wat get index];
> >
> >A A A A A A A AA # sets a counter to zero
> >A A A A A A A AA set checkingNums 0;
> >
> >A A A A A A A AA # for each water we do the following
> >A A A A A A A AA foreach waterID $wat_index waterRID $wat_resid {
> >
> >A A A A A A A AA # add 1 to the counter and print out so we know how
> far into
> >A A the loop we have gone
> >A A A A A A A AA incr checkingNums;
> >A A A A A A A AA puts " WATER $checkingNums OF $num_Totalwat ";A
> >A A A A A A A A A A
> >A A A A A A A AA # make a temporary selection using the atom indices
> and
> >A A residue indicesAA A
> >A A A A A A A AA set wat_coord [atomselect top "name OW and index
> $waterID and
> >A A resid $waterRID"];A
> >A A A
> >A A A A A A A AA # find the 4 closest waters to this atom
> >A A A A A A A AA set close_wat [nwat 4 $wat_coord];
> >
> >A A A A A A AA # Find all the possible 3 angle combinations which
> can be made
> >A A with the 4 neighbour whilst wat_coord is at the centre
> >A A AA AA AA # set the sum to zero A A A A A A A A A A A A A A A A
> A A A A A
> >A A A A A A A AA set sum 0.0;
> >
> >A A A A A A A AA # set counter to zero
> >A A A A A A A AA set countAngles 0;
> >A A A A A A A AA for { set k 0 } { $k < 4 } { incr k } {A
> >A A A A A A A A A A A AA for { set l [expr $k+1] } { $l < 4 } { incr
> l } {A
> >
> >A A A A A A A A A A A A A A A AA # add 1 to angles which have been
> calculated.
> >A A The final value should always be 6 for 4 neighbours.
> >A A A A A A A A A A A A A A A AA incr countAngles;
> >
> >A A A A A A A A A A A A A A A AA # select the first atom index
> >A A A A A A A A A A A A A A A AA set hi1 "[lindex $close_wat $k]";
> >
> >A A A A A A A A A A A A A A A AA # select the reference atom index
> >A A A A A A A A A A A A A A A AA set atom2 [[atomselect top "name OW
> and
> >A A (index $waterID and resid $waterRID)"] get {index}];
> >
> >A A A A A A A A A A A A A A A AA # select the third atom indexA
> >A A A A A A A A A A A A A A A AA set hi3 "[lindex $close_wat $l]";A
> >
> >A A A A A A A A A A A A A A A AA # calculate the angle usin proc
> calcangle
> >A A defined earlier
> >A A A A A A A A A A A A A A A AA set calcangle [angle $hi1 $atom2
> $hi3];
> >A A A
> >A A A A A A A A A A A A A A A AA # add up cosine results to those
> from
> >A A previous angles
> >A A A A A A A A A A A A A A A AA set sum [expr
> >A A {(($calcangle+1.0/3.0)*($calcangle+1.0/3.0))+$sum}];
> >A A A
> >A A A A A A A A A A A AA }A
> >A A A A A A A AA }
> >A A A
> >A A A A A A AA # define the q value
> >A A A A A A A AA set q [expr {1.0-((3.0/8.0)*$sum)}];
> >
> >A A A A A A A AA # print theA A A AA FrameA A A A A A AA Loop
> >A A numberA A A A A A AA Atom index A A A A A A AA Q valueA A A AA
> details to
> >A A file
> >A A A A A A A AA puts [format "Frame: $i\t ID: $checkingNums \t
> AtomIDX:
> >A A $waterID \t Q: %.2f"A AA $q];
> >A A A
> >A A ##AA puts $q_file "ID: $checkingNumsA A AA AtomIDX: $waterIDA
> AA Q: $q";A
> >A A # print details to file
> >A A A
> >A A A A A AA }
> >
> >A A A A A A AA # delete variables we do not need any moreAA AA A A
> A A
> >A A A A A A AA $wat_coord delete; array unset wat_coord;
> >A A A A A A AA $close_wat delete; array unset close_wat;
> >A A A A A A AA $k delete; array unset k;
> >A A A A A A AA $l delete; array unset l;
> >A A A A A A AA $hi1 delete; array unset hi1;
> >A A A A A A AA $atom2 delete; array unset atom2;
> >A A A A A A AA $hi3 delete; array unset hi3;
> >A A A A A A AA $calcangle delete; array unset calcangle;
> >A A A A A A AA $sum delete; array unset sum;
> >A A A A A A AA $q delete; array unset q;
> >A A A A A A A A
> >
> >A A ##A AA puts $q_file "END"; # add END line after every frame
> >
> >A A # delete variables we do not need any moreAA A
> >A A A $total_wat delete; array unset total_wat;
> >A A A $num_Totalwat delete; array unset num_Totalwat;
> >A A A $wat_resid $delete; array unset wat_resid;
> >A A A $wat_index delete; array unset wat_index;
> >A A A $waterID delete; array unset waterID;
> >A A A $waterRID delete; array unset waterRID;
> >A A A $checkingNums delete; array unset checkingNums;
> >A A A $countAngles delete; array unset countAngles;
> >A A A
> >A A A AA }A
> >
> >A A ##A AA puts $q_file " "; # add empty newline to file
> >
> >A A ##A AA close $q_file;A A AA # close file
> >
> >A A # delete variables we do not need any moreAA A
> >A A $total_wat delete;
> >A A A
> >A A A
> >
> >A A END
> --
> NIH Center for Macromolecular Modeling and Bioinformatics
> Beckman Institute for Advanced Science and Technology
> University of Illinois, 405 N. Mathews Ave, Urbana, IL 61801
> [3]http://www.ks.uiuc.edu/~johns/A A A A A A Phone: [4]217-244-3349
> [5]http://www.ks.uiuc.edu/Research/vmd/
>
> References
>
> Visible links
> 1. mailto:johns_at_ks.uiuc.edu
> 2. mailto:vmd_at_ks.uiuc.edu
> 3. http://www.ks.uiuc.edu/~johns/
> 4. tel:217-244-3349
> 5. http://www.ks.uiuc.edu/Research/vmd/

-- 
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/