From: Axel Kohlmeyer (akohlmey_at_gmail.com)
Date: Wed Jun 12 2013 - 21:22:53 CDT

No. It is not a memory problem, but a problem of opening files without properly closing them. Check your script.

As for question 2. You have to keep track of things inside the script and set the user field accordingly. There is no trigger-and-keep setting in VMD.

Axel

--
Dr. Axel Kohlmeyer  akohlmey_at_gmail.com  http://goo.gl/1wk0
International Centre for Theoretical Physics, Trieste. Italy.
-----Original Message-----
From: Ludovic <ludomer_at_gmail.com>
Sender: owner-vmd-l_at_ks.uiuc.edu
Date: Thu, 13 Jun 2013 02:14:35 
To: <vmd-l_at_ks.uiuc.edu>
Subject: vmd-l: error: too many open files
Hi everyone!
I'm trying to visualize the movement of atoms using a system with 8000 
frames.
I'm using a Tcl script to load each frame (each in a single PDB file) 
and make a screenshot with VMD.
The problem is that it stops at the 1000-ish frame giving me the error:
"couldn't read file XXX: too many open files"
(it works well if I use less than a 1000 frames)
(I'm using Ubuntu 10.4 64-bit and VMD 1.9.1)
You can find the script I was using at the end of this post (version 1).
I guess it's a memory problem so I tried modifying the script (version 
2) so it is creating a molecule, adding to it the first 1000 frames, 
make the screenshots then delete the molecule, creating a second 
molecule, adding to it the next 1000 frames...
But it gives me the same error.
I also tried using the command "animate delete" at the end end of each 
loop, but still the same error.
I really have no idea what to do. Maybe the problem is in the "readBF" part?
I'd be really glad if someone could help me on this...
I also have another question while I'm at it.
For the time being I'm using the user-field to save data for each atom, 
so that, each frame, VMD checks if this value is higher than a value 
"$thresh" for each atom and modify the color using a color scale.
What I would like (and couldn't manage) to do is, when an atom get a 
higher value of $thresh, modify its color but keep this color for all 
subsequent frames (and still modify its position).
I tried using "mol colupdate 1 top off" but it doesn't work, and the 
colors go weird.
I can't use "mol drawframes" either since the position of the atoms will 
not be updated.
If you have an idea of some kind...
Thank you very much!
Regards,
Ludovic Mercier
##########################################################
##########################################################
###
### VERSION 1
###
## Name:
## makeanimallpdbwBF.tcl
##
proc readBF { fname } {
   set all [atomselect top all]
   set in [open $fname r]
   set beta {}
   set numat 0
   while { [gets $in line] != -1 } {
     switch -- [string range $line 0 3] {
      ATOM -
       HETA {
         incr numat
         lappend beta [expr [string range $line 61 66]]
       }
      }
   }
   return $beta
}
#start is 1
#end is the total number of frames
proc makeanimallpdbwBF {start end fileformat thresh threshmax} {
   for {set i [expr $start]} {$i <= $end} {incr i 1} {
     set filename [format $fileformat [expr $i]]
     mol addfile $filename type pdb waitfor all
   }
   for {set i $start} {$i <= $end} {incr i 1} {
     set filename [format $fileformat [expr $i]]
     set all [atomselect top all frame [expr $i-1]]
     set beta [readBF $filename]
     $all set user $beta
     $all delete
   }
   mol modselect 0 top user < $thresh and not protein
   mol modcolor 0 top ColorID 2
   mol modstyle 0 top CPK 1.800000 0.300000 10.000000 2.000000
   mol modmaterial 0 top AOEdgy
   #mol showperiodic top 0 xyXY
   #mol numperiodic top 0 1
   mol addrep top
   mol modselect 1 top user >= $thresh
   mol modcolor 1 top user
   mol modstyle 1 top CPK 2.600000 0.300000 10.000000 2.000000
   mol modmaterial 1 top Opaque
   #mol showperiodic top 1 xyXY
   #mol numperiodic top 1 1
   mol addrep top
   mol modselect 2 top protein
   mol modcolor 2 top Name
   mol modstyle 2 top CPK 1.500000 1.2000000 10.000000 2.000000
   mol modmaterial 2 top BrushedMetal
   #mol showperiodic top 2 xyXY
   #mol numperiodic top 2 1
   mol addrep top
   mol selupdate 0 top on
   mol selupdate 1 top on
   mol selupdate 2 top on
   mol colupdate 0 top on
   mol colupdate 1 top on
   mol colupdate 2 top on
   #pbc set {41.259 41.259 41.259 90.0 90.0 90.0} -molid top -all
   #pbc box -centersel protein -center com -color magenta
   color scale method BGR
   color scale midpoint 0.2
   mol scaleminmax top 1 $thresh $threshmax
   scale by 1.6
   for {set i [expr $start]} {$i <= $end} {incr i 1} {
     animate goto [expr $i-1]
     set filename [format $fileformat [expr $i]]
     set filename $filename.rgb
     render snapshot $filename
   }
   #atomselect list
}
############################################
############################################
###
### VERSION 2
###
## Name:
## makeanimallpdbwBF.tcl
##
proc readBF { fname } {
   set all [atomselect top all]
   set in [open $fname r]
   set beta {}
   set numat 0
   while { [gets $in line] != -1 } {
     switch -- [string range $line 0 3] {
      ATOM -
       HETA {
         incr numat
         lappend beta [expr [string range $line 61 66]]
       }
      }
   }
   return $beta
}
proc makeanimallpdbwBF {start end fileformat thresh threshmax} {
   set filename [format $fileformat [expr $start]]
   mol new $filename type pdb waitfor all
   mol modselect 0 top user < $thresh and not protein
   mol modcolor 0 top ColorID 2
   mol modstyle 0 top CPK 1.800000 0.300000 10.000000 2.000000
   mol modmaterial 0 top AOEdgy
   mol addrep top
   mol modselect 1 top user >= $thresh
   mol modcolor 1 top user
   mol modstyle 1 top CPK 2.600000 0.300000 10.000000 2.000000
   mol modmaterial 1 top Opaque
   mol addrep top
   mol modselect 2 top protein
   mol modcolor 2 top Name
   mol modstyle 2 top CPK 1.500000 1.2000000 10.000000 2.000000
   mol modmaterial 2 top BrushedMetal
   color scale method BGR
   color scale midpoint 0.2
   mol scaleminmax top 1 $thresh $threshmax
   scale by 1.7
   for {set i $start} {$i <= 1000} {incr i 1} {
     set filename [format $fileformat [expr $i]]
     animate read pdb $filename
     set all [atomselect top all]
     set beta [readBF $filename]
     $all set user $beta
     set filename $filename.rgb
     render snapshot $filename
     $all delete
   }
   animate delete all top
   mol delete top
   set filename [format $fileformat 1001]
   mol new $filename type pdb waitfor all
   mol modselect 0 top user < $thresh and not protein
   mol modcolor 0 top ColorID 2
   mol modstyle 0 top CPK 1.800000 0.300000 10.000000 2.000000
   mol modmaterial 0 top AOEdgy
   mol addrep top
   mol modselect 1 top user >= $thresh
   mol modcolor 1 top user
   mol modstyle 1 top CPK 2.600000 0.300000 10.000000 2.000000
   mol modmaterial 1 top Opaque
   mol addrep top
   mol modselect 2 top protein
   mol modcolor 2 top Name
   mol modstyle 2 top CPK 1.500000 1.2000000 10.000000 2.000000
   mol modmaterial 2 top BrushedMetal
   color scale method BGR
   color scale midpoint 0.2
   mol scaleminmax top 1 $thresh $threshmax
   scale by 1.7
   for {set i 1001} {$i <= 2000} {incr i 1} {
     set filename [format $fileformat [expr $i]]
     animate read pdb $filename
     set all [atomselect top all]
     set beta [readBF $filename]
     $all set user $beta
     set filename $filename.rgb
     render snapshot $filename
     $all delete
   }
   animate delete all top
#atomselect list
#mol list
}