From: John Stone (johns_at_ks.uiuc.edu)
Date: Thu Mar 05 2009 - 22:36:23 CST

Thomas,
  From what you've written below about the proc responding to _any_
file being loaded, I think you need to change the bigdcd
code so that the callback ignores new frames being loaded into any
molecule other than the one that you're processing. I've attached
a couple of old scripts I had sitting around that print messages
whenever callbacks are triggered, they should help you understand
what you'll need to do.

Cheers,
  John Stone
  vmd_at_ks.uiuc.edu

On Sat, Feb 28, 2009 at 12:19:03AM +0200, Thomas Evangelidis wrote:
> Hi everyone,
>
> I tried to integrate bigdcd into a namespace and seems that I made it
> but for some strange reason the procedure assigned to $bigdcd_proc is
> executed whenever I load a different pdb file. In this case
> $bigdcd_proc is a simple proc that write the current frame to a pdb
> file. Moreover none of the molecules is visible. The only variable
> I've set to be global is vmd_frame and is being increased whenever a
> new file is loaded. I quote the code below and would really appreciate
> any advice!
>
> PS: there are a lot of "puts" for debugging...
>
>
>
> package provide trunctraj 1.6
>
> namespace eval ::TruncTraj {
> namespace export trunctraj
> variable trajectory_psf
> "/home/thomas/Documents/Molecular_Dynamics/truncate_trajectory1.5/DCD_with_cell.psf"
> variable trajectory_dcd
> "/home/thomas/Documents/Molecular_Dynamics/truncate_trajectory1.5/sample_DCD_with_cell.dcd"
> variable bigdcd_frame
> variable bigdcd_proc
> variable bigdcd_firstframe
> variable bigdcd_is_done
> variable ch1 [open "bigdcd.log" RDWR]
> puts $::TruncTraj::ch1 "point 0"
> }
>
>
>
> proc ::TruncTraj::adaptedBigdcd { script args } {
> variable bigdcd_frame
> variable bigdcd_proc
> variable bigdcd_firstframe 0
> global vmd_frame
> variable bigdcd_is_done 0
> puts $::TruncTraj::ch1 "point 1"
>
> set bigdcd_firstframe [molinfo top get numframes]
> set bigdcd_proc $script
> puts $::TruncTraj::ch1 "point 2"
> uplevel #0 trace variable vmd_frame w ::TruncTraj::bigdcd_callback
> puts $::TruncTraj::ch1 "point 3"
> foreach dcd $args {
> animate read dcd $dcd waitfor 0
> }
> }
>
> proc ::TruncTraj::bigdcd_callback { name1 name2 op } {
> variable bigdcd_frame
> variable bigdcd_proc
> variable bigdcd_firstframe
> global vmd_frame
> puts $::TruncTraj::ch1 "point 4"
> # If we're out of frames, we're also done
> set thisframe $vmd_frame($name2)
> if { $thisframe < $bigdcd_firstframe } {
> ::TruncTraj::bigdcd_done
> return
> }
> puts $::TruncTraj::ch1 "point 5"
> incr bigdcd_frame
> if { [catch {uplevel #0 $bigdcd_proc $bigdcd_frame} msg] } {
> puts $::TruncTraj::ch1 "point 6"
> puts stderr "bigdcd aborting at frame $bigdcd_frame\n$msg"
> ::TruncTraj::bigdcd_done
> return
> }
> puts $::TruncTraj::ch1 "point 7"
> animate delete beg $thisframe end $thisframe
> return $msg
> }
>
> proc ::TruncTraj::bigdcd_done { } {
> variable bigdcd_is_done
> global vmd_frame
> set bigdcd_is_done 1
> puts "bigdcd_done"
> uplevel #0 trace vdelete vmd_frame w ::TruncTraj::bigdcd_callback
> puts $::TruncTraj::ch1 "point 8"
> }
>
> proc ::TruncTraj::adaptedBigdcd_wait_till_done {} {
> variable bigdcd_is_done
> global vmd_frame
> puts $::TruncTraj::ch1 "point 9"
> while {! $bigdcd_is_done} {
> display update
> puts $::TruncTraj::ch1 "point 10 bigdcd_is_done = $bigdcd_is_done
> bigdcd_frame = $::TruncTraj::bigdcd_frame"
> }
> }
>
>
> proc ::TruncTraj::SaveTruncTraj { frm } {
> puts "frame = $frm"
> animate write pdb
> "/home/thomas/Documents/Molecular_Dynamics/truncate_trajectory1.5/wholeframe_$frm.pdb" beg 0 end 0 waitfor all
> top
> }
>
> proc ::TruncTraj::RunTruncTraj {} {
> variable trajectory_psf
> variable trajectory_dcd
> mol delete all
> mol load psf "$trajectory_psf"
> ::TruncTraj::adaptedBigdcd ::TruncTraj::SaveTruncTraj "$trajectory_dcd"
> ::TruncTraj::adaptedBigdcd_wait_till_done
> }
>
> ::TruncTraj::RunTruncTraj
>

-- 
NIH Resource for Macromolecular Modeling and Bioinformatics
Beckman Institute for Advanced Science and Technology
University of Illinois, 405 N. Mathews Ave, Urbana, IL 61801
Email: johns_at_ks.uiuc.edu                 Phone: 217-244-3349
  WWW: http://www.ks.uiuc.edu/~johns/      Fax: 217-244-6078