From: Sangkha Borah (sborah53_at_gmail.com)
Date: Thu Aug 04 2016 - 00:56:43 CDT

Dear all,

I need some help to improve my script. Though the script works but is very
slow. In fact it runs with desired speed initially but becomes terribly
slow afterwards. I guess the script is not able to deallocate the memory
during the process. The script simply finds some selections and prints in
some order.

###################################################
mol new TRAJECTORY.xyz type xyz first 0 last -1 step 1 waitfor all
package require pbctools
pbc set {12.42 12.42 12.42} -all
animate goto 0
set mol [molinfo top]
set nf [molinfo $mol get numframes]
set ox [atomselect $mol {name O and not index 1 2 3}]
set all [atomselect $mol {name H O}]
set out [open "TRAJ-SORTED.xyz" w]

foreach i [$ox get index] {
   set sel($i) [atomselect $mol "pbwithin 1.30 of index $i"]
}

for {set n 0} {$n < $nf} {incr n} {
   foreach i [$ox get index] {
   $all frame $n
   $ox frame $n
   $sel($i) frame $n
   $sel($i) update
   set num [$sel($i) num]
   if {$num ==2} {
   puts $out "183"
   puts $out "$n"
   set H3O [atomselect $mol "index [$sel($i) get index]"]
   set SeO3 [atomselect $mol "index 0 1 2 3"]
   set REST [atomselect $mol "not index [$H3O get index] [$SeO3 get index]"]

   foreach iH3O [$H3O get index] {
   set h3o [atomselect $mol "index $iH3O"]
   $h3o frame $n
   puts $out "[$h3o get name] [$h3o get x] [$h3o get y] [$h3o get z]"
 }

  foreach iSeO3 [$SeO3 get index] {
   set seo3 [atomselect $mol "index $iSeO3"]
   $seo3 frame $n
   puts $out "[$seo3 get name] [$seo3 get x] [$seo3 get y] [$seo3 get z]"
 }

  foreach iREST [$REST get index] {
   set rest [atomselect $mol "index $iREST"]
   $rest frame $n
   puts $out "[$rest get name] [$rest get x] [$rest get y] [$rest get z]"
 }

}
}
}
# clean up selections
foreach i [$ox get index] {
    $sel($i) delete
}
$ox delete
$all delete
unset ox all sel i n
exit

############################################################

Best,

-- 
Sangkha Borah
Email-sborah53_at_gmail.com
IIT Guwahati, India