From: Thomas Hedegaard Pedersen (c971742_at_student.dtu.dk)
Date: Wed Apr 30 2003 - 09:28:01 CDT

I need help!!!

My question probably relates very much to the earlier email posted to
VMD-L by Joe Huang:

# Memory problems with TCL scripts in VMD. Joe Huang (Thu Mar 20 2003 -
13:02:48 CST)

I'm trying to do an RMSD calculation for each residue in a protein as
function of time. I have produced a Tcl script for this purpose (see
below) but when I run the script it gradually uses up all of my memory
causing the computer to freeze. By successively commenting out lines in
the script I could pin point the cause of the problem down to the line:

"$compare2 move $trans_mat1"

located inside the loop in the proc - if this line is commented out
VMD's memory usage becomes relatively small and constant through out the
run! Am I doing something completely wrong when using the "move" command
or is it something else??????

Thanks for your help

Thomas H. Pedersen
Tecnical University of Denmark (DTU)
Kemitorvet build. 206 room 243
DK-2800 Kgs. Lyngby, Denmark

Tcl-script:
----------------------------------------------------------------------------
# Calculates the RMSD of every residue as function of time.
        #Written by Thomas Hedegaard Pedersen
        #Technical University of Denmark
        #Kgs. Lyngby

#REMEMBER TO SET BIGDCD-PATH, PSF and PDB FILENAMES, DCD FILENAMES,
SELECTION#
##############################################################################
source /home/Thomas/scripts/vmd/PCA/bigdcd.tcl

#set sys
set sys 1az8

#set rmsd id
set id RESID_CA

#set sim id
set sim SIM4_SIM4B

#set paths
set psf "/home/Thomas/${sys}/${sys}_psfgen.psf"

set dcdpath1 "/home/Thomas/${sys}/SIM/dcd/${sys}_300K_SIM4.dcd"
set dcdpath2 "/home/Thomas/${sys}/SIM/dcd/${sys}_300K_SIM4_B.dcd"

set out_dir "/home/Thomas/${sys}/SIM/rmsd/Residues/"

#set reference pdb
set pdb "/home/Thomas/${sys}/${sys}_EQ_frame_1999.pdb"
set ref EQ1999

#set time between frames (picoseconds)
set time_betw_frame 0.5

#REMEMBER to do the following selections as less time demanding as
possible as
#this will have a profound impact on the performance

#set fit selection
set selection "protein and name CA"

#set rmsd selection
set rmsd_selec "protein and name CA"
##############################################################################

#set ref_frame - only 0 (corresponding to pdb-file)
set ref_frame 0

set name1 "${out_dir}rmsd_${sys}_${sim}_${id}_ref${ref}.dat"
if {[file exists $name1] == 1} {
   return "file $name1 already exists - remove it and run the program
again"
} else {
   set fid20 [open $name1 a]
}
 
        
proc rmsd_resid { frame } {

        global time_betw_frame selection rmsd_selec fid20 reference1 num_resid

        # the selection and frame used for fitting
               set compare1 [atomselect top $selection frame $frame]

        # compute the transformation
               set trans_mat1 [measure fit $compare1 $reference1]

        $compare1 delete
        unset compare1

               puts "Frame : $frame"

        puts -nonewline $fid20 "[expr {$frame * $time_betw_frame}] "

        # Calculate rmsd on the desired selection residue wise

        for {set n 0} {$n <= [expr {$num_resid-1}]} {incr n} {

                upvar #0 ref2_$n ref

                #the selection and frame used for rmsd
                set compare2 [atomselect top "($rmsd_selec) and (residue $n)"
frame $frame]

#####################################################################
#THE FOLLOWING LINE SEEMS TO CAUSE THE PROBLEM REGARDING MEMORY USAGE
#####################################################################
                # do the alignment
                       $compare2 move $trans_mat1
#####################################################################

                # compute the RMSD
                       set rmsd1 [measure rmsd $compare2 $ref]

                puts -nonewline $fid20 "$rmsd1 "

                $compare2 delete
                unset compare2
                unset rmsd1
        }

        unset trans_mat1
        
        puts $fid20 ""

        flush $fid20
}

# read in psf-file
mol load psf $psf

#set reference for fit
set reference1 [atomselect top $selection frame $ref_frame]
puts "reference for fit set to selection: $selection"
puts " at frame: $ref_frame\n"

#set reference for rmsd
set residues [atomselect top "(same residue as ($rmsd_selec)) and (name
CA)"]
set num_resid [$residues num]

for {set n 0} {$n <= [expr {$num_resid-1}]} {incr n} {
        set ref2_$n [atomselect top "($rmsd_selec) and (residue $n)" frame
$ref_frame]
}
puts "reference for residues set to selection: $rmsd_selec"
puts " at frame: $ref_frame\n"

#read in reference pdb-file
animate read pdb $pdb

# read in dcd files
bigdcd rmsd_resid $dcdpath1 $dcdpath2