VMD script to annotate each frame of a trajectory
Jump to navigation
Jump to search
annotateTraj.tcl contains procedures to annotate each frame of a pdb trajectory file with data from the pdb file (e.g. energy from the header line of each frame) or computed using measure (e.g. RMSD). See comments in the code for instructions for modifying the script. A sample pdb trajectory file for testing is listed below.
Usage:
In VMD TKconsole % mol load pdb extracted.pdb % source annotateTraj.tcl % getTrajData % traceon Play movie to see the annotations.
Error creating thumbnail: Unable to save thumbnail to destination
annotateTraj.tcl
################################################################################ # annotateTraj.tcl contains procedures to annotate each frame of a trajectory with # data from the pdb file or computed using measure. # # Usage: # In VMD TKconsole # % mol load pdb extracted.pdb # % source annotateTraj.tcl # % getTrajData # % traceon # # Author: # ss2029@cam.ac.uk # (adapted from James' batch_rmsd.tcl) # # Last Updated: # 14 Mar 2012 - created # ################################################################################ proc traceon {} { # Executes 'drawmol' whenever the frame changes global vmd_frame trace variable vmd_frame([molinfo top]) w drawmol } # --------------------------------- proc drawmol { name element op } { global vmd_frame # trajData is calculated in proc batch_rmsd global trajData # get current frame number set i $vmd_frame([molinfo top]) # draw commands draw delete all draw material Opaque draw color white draw text {0 0 0} "$trajData($i)" } # --------------------------------- proc getTrajData {} { global vmd_frame global trajData # Get number of frames set Nframes $vmd_frame([molinfo top]) puts "Number of frames = [expr {$Nframes+1}]" # Read all frames into array allFrames() for {set f 0} {$f<=$Nframes} {incr f} { set allFrames($f) [atomselect top "all" frame $f] } #{{{ # Populate trajData using measure # e.g. RMSD wrt frame 0 as done here # set i 0 # # Open output file # set outfile [open "batch_rmsd.out" w] # for {set j 0} {$j<=$Nframes} {incr j} { # # measure RMSD and store in an array # set tRMSD($j) [measure rmsd $allFrames($i) $allFrames($j)] # puts "$i\t$j\t$tRMSD($j)" # puts $outfile "$i\t$j\t$tRMSD($j)" # } # close $outfile #}}} #{{{ # Populate trajData with data header lines of frames in the pdb file # TITLE alkane t= 2.80000 # here trajData is populated with the 4th word of lines starting with TITLE is # open pdb file (or any data file) set infile [open "extracted.pdb" r] set iTitle 0 # read one line at a time while {[gets $infile line]>=0} { # look for line starting with 'TITLE' if [regexp {^TITLE} $line] { # print the full line puts "$line" # print 4th word of line puts [lindex $line 3] set iTitle [expr {$iTitle+1}] set trajData($iTitle) [lindex $line 3] puts $trajData($iTitle) } } # file read # close file close $infile #}}} #{{{ # Populate trajData from a data file, here ener.dat # # # open pdb file (or any data file) # puts "reading first column of ener.dat" # set infile [open "ener.dat" r] # set iTitle 0 # # read one line at a time # while {[gets $infile line]>=0} { # set iTitle [expr {$iTitle+1}] # set trajData($iTitle) [lindex $line 0] # puts $trajData($iTitle) # } # file read # close file # close $infile # puts "$iTitle lines read from ener.dat" #}}} } # END proc getTrajData
Test pdb file (save as extracted.pdb)
REMARK GENERATED BY TRJCONV TITLE alkane t= 0.00000 MODEL 1 ATOM 1 C1 DRG 1 -2.810 -0.760 -1.720 1.00 0.00 ATOM 2 C2 DRG 1 -2.370 -1.570 -0.490 1.00 0.00 ATOM 3 C3 DRG 1 -0.870 -1.370 -0.230 1.00 0.00 ATOM 4 C4 DRG 1 -0.240 -0.520 -1.330 1.00 0.00 ATOM 5 C5 DRG 1 0.190 0.840 -0.770 1.00 0.00 ATOM 6 C6 DRG 1 -0.280 0.970 0.690 1.00 0.00 ATOM 7 C7 DRG 1 0.920 1.110 1.640 1.00 0.00 ATOM 8 C8 DRG 1 2.230 1.170 0.850 1.00 0.00 ATOM 9 C9 DRG 1 3.230 0.130 1.360 1.00 0.00 TER ENDMDL REMARK GENERATED BY TRJCONV TITLE alkane t= 0.10000 MODEL 2 ATOM 1 C1 DRG 1 -2.805 -0.727 -1.702 1.00 0.00 ATOM 2 C2 DRG 1 -2.369 -1.579 -0.509 1.00 0.00 ATOM 3 C3 DRG 1 -0.875 -1.372 -0.210 1.00 0.00 ATOM 4 C4 DRG 1 -0.218 -0.533 -1.323 1.00 0.00 ATOM 5 C5 DRG 1 0.158 0.860 -0.802 1.00 0.00 ATOM 6 C6 DRG 1 -0.312 1.052 0.642 1.00 0.00 ATOM 7 C7 DRG 1 0.878 0.929 1.596 1.00 0.00 ATOM 8 C8 DRG 1 2.193 1.114 0.821 1.00 0.00 ATOM 9 C9 DRG 1 3.304 0.224 1.396 1.00 0.00 TER ENDMDL REMARK GENERATED BY TRJCONV TITLE alkane t= 0.20000 MODEL 3 ATOM 1 C1 DRG 1 -2.788 -0.577 -1.621 1.00 0.00 ATOM 2 C2 DRG 1 -2.360 -1.591 -0.541 1.00 0.00 ATOM 3 C3 DRG 1 -0.904 -1.363 -0.133 1.00 0.00 ATOM 4 C4 DRG 1 -0.122 -0.572 -1.196 1.00 0.00 ATOM 5 C5 DRG 1 -0.218 0.934 -0.926 1.00 0.00 ATOM 6 C6 DRG 1 -0.258 1.202 0.590 1.00 0.00 ATOM 7 C7 DRG 1 0.904 0.504 1.304 1.00 0.00 ATOM 8 C8 DRG 1 2.253 0.995 0.766 1.00 0.00 ATOM 9 C9 DRG 1 3.409 0.476 1.646 1.00 0.00 TER ENDMDL REMARK GENERATED BY TRJCONV TITLE alkane t= 0.30000 MODEL 4 ATOM 1 C1 DRG 1 -2.618 -0.257 -1.545 1.00 0.00 ATOM 2 C2 DRG 1 -2.457 -1.539 -0.722 1.00 0.00 ATOM 3 C3 DRG 1 -0.986 -1.751 -0.318 1.00 0.00 ATOM 4 C4 DRG 1 -0.090 -0.680 -0.976 1.00 0.00 ATOM 5 C5 DRG 1 -0.674 0.712 -0.737 1.00 0.00 ATOM 6 C6 DRG 1 -0.071 1.342 0.521 1.00 0.00 ATOM 7 C7 DRG 1 1.018 0.441 1.123 1.00 0.00 ATOM 8 C8 DRG 1 2.406 0.947 0.708 1.00 0.00 ATOM 9 C9 DRG 1 3.422 0.745 1.832 1.00 0.00 TER ENDMDL REMARK GENERATED BY TRJCONV TITLE alkane t= 0.40000 MODEL 5 ATOM 1 C1 DRG 1 -2.418 0.044 -1.326 1.00 0.00 ATOM 2 C2 DRG 1 -2.551 -1.412 -0.842 1.00 0.00 ATOM 3 C3 DRG 1 -1.154 -2.015 -0.592 1.00 0.00 ATOM 4 C4 DRG 1 -0.107 -0.916 -0.722 1.00 0.00 ATOM 5 C5 DRG 1 -0.788 0.451 -0.586 1.00 0.00 ATOM 6 C6 DRG 1 -0.026 1.343 0.406 1.00 0.00 ATOM 7 C7 DRG 1 1.068 0.547 1.121 1.00 0.00 ATOM 8 C8 DRG 1 2.445 1.047 0.690 1.00 0.00 ATOM 9 C9 DRG 1 3.456 0.942 1.840 1.00 0.00 TER ENDMDL REMARK GENERATED BY TRJCONV TITLE alkane t= 0.50000 MODEL 6 ATOM 1 C1 DRG 1 -2.389 0.125 -0.972 1.00 0.00 ATOM 2 C2 DRG 1 -2.586 -1.396 -1.096 1.00 0.00 ATOM 3 C3 DRG 1 -1.229 -2.084 -0.998 1.00 0.00 ATOM 4 C4 DRG 1 -0.281 -1.134 -0.263 1.00 0.00 ATOM 5 C5 DRG 1 -0.742 0.301 -0.587 1.00 0.00 ATOM 6 C6 DRG 1 0.050 1.351 0.175 1.00 0.00 ATOM 7 C7 DRG 1 1.104 0.697 1.078 1.00 0.00 ATOM 8 C8 DRG 1 2.500 1.251 0.752 1.00 0.00 ATOM 9 C9 DRG 1 3.482 0.964 1.885 1.00 0.00 TER ENDMDL