From: John Stone (johns_at_ks.uiuc.edu)
Date: Tue Feb 26 2013 - 13:12:52 CST

Hi,
  You need to make sure to delete your atom selections.
In your do_refresh_occupency proc, you are creating selections
within a doubly nested loop, but they are never getting deleted...
That's the first thing that you would need to fix there if you were
going to do it this way. Even that would be a bad idea however.
It is far more efficient to set _all_ of the occupency values with
a single atom selection operation, e.g.:

replace this operation in your reader loop:
         set occu($i) [lindex $line 8]

with something like this:
         lappend occlist [lindex $line 8]

Then, in do_refresh_occupancy, you could get rid of the innermost loop
and do something more like this:
         set s [atomselect $molid all]
         $s set occupancy $occlist

That would be massively faster than what you are doing presently.

There are yet other ways of doing this...

If you want to store occupancy per-frame, you probably want to store it
to one of the "user" fields rather than occupancy, and then VMD will
automatically update it as you animate the trajectory all by itself.
See the various VMD tutorials to learn how to use these features.

Cheers,
  John Stone
  vmd_at_ks.uiuc.edu

On Tue, Feb 26, 2013 at 01:42:59PM -0500, Fahimeh Baftizadeh wrote:
> Hello,
> I am trying to load a pdb trajectory and update the occupancy column at
> each fram. As far as I know, this is not automatic in VMD and I had to
> write a tcl script for that. Here is my script:
> mol new {new2.pdb} type pdb waitfor all
> set molid 0
> set i 0
> set pattern {ATOM}
> set fp [open "new2.pdb" r]
> while {[gets $fp line] !=-1} {
> if {[regexp $pattern $line]} {
> set occu($i) [lindex $line 8]
> incr i}
> }
> close $fp
> proc do_refresh_occupancy {args} {
> global occu molid
> set a [molinfo $molid get numatoms]
> set f [molinfo $molid get frame]
> for {set j 0} {$j <= $f} {incr j} {
> for {set i 0} {$i < $a} {incr i} {
> set s [atomselect $molid "index $i"]
> $s set occupancy $occu([expr $a*$j+$i])
> }
> }
> }
> trace variable vmd_frame($molid) w do_refresh_occupancy
> mol colupdate 0 $molid on
> mol scaleminmax 0 $molid 0.0 2.0
> animate goto start
> do_refresh_occupancy
> in which I read and load new2.pdb ... saving the occupancy column and then
> update it each fram. This is maybe complicated one but I am new to tcl and
> didn't know how to make it simpler.
> My problem now is that if new2.pdb is large ... then VMD crash and
> complain for memory ... (malloc)
> Could you please help me to solve this problem?
> Thanks
> Fahimeh

-- 
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/       Fax: 217-244-6078