From: Ana Celia Vila Verde (acavilaverde_at_gmail.com)
Date: Fri Mar 09 2012 - 02:10:56 CST

Hi,

Here are a few suggestions to improve your script:

# "file" is a command in tcl; I'm not sure you can name a variable
"file", like you had...
set outfile [open "ca-dist.dat" w]

for { set i 2 } { $i <= 111 } { incr i } {
    # Since you only want the average distance between consecutive alpha
carbons, you don't need the second loop
    # Note that you should always use curly brackets when using expr;
your code will run much faster
    set j [expr {$i -1}]

   # Do the selections this way so you can delete them at the end of
the loop. This is good practice to save memory.
    set seli [atomselect top "protein and name CA and resid $i"]
    set selj [atomselect top "protein and name CA and resid $j"]

    # now getting the index
       set indi [$seli get index]
       set indj [$selj get index]

       set dist 0 ;# not sure if this line is correct ; # it
doesn't hurt

       # Just quotes should be sufficient. Alternatively you can write
set dist [ measure bond [list $indi $indj] ]
       # Note that this returns the distance for the top molecule in VMD
and for the current frame
       set dist [ measure bond "$indi $indj" ] ;
       puts $outfile "$j $i $dist"

       # delete selections to save memory
       $seli delete
       $selj delete
}; # for i
close $outfile

I hope this helps. Cheers,

Ana

On 3/8/12 10:33 PM, Murpholino Peligro wrote:
> Hi all!
> I want to know the average distance for alpha carbons in my protein
> with N residues (in this case 111)
> I was trying to get the distance for residue i and that of residue i-1
> Until now I have>
> set file [open "ca-dist.dat" w]
> for { set i 2 } { $i <= 111 } { incr i } {
> set j 0
> for { set j [ expr $i - 1 ] } { $j <= [ expr $i -1 ] } { incr j } {
> set seli [[atomselect top "protein and name CA and resid $i"]
> get index]
> set selj [[atomselect top "protein and name CA and resid $j"]
> get index]
> puts "$j $selj $i $seli" ;# everything is ok 'til here
> set dist 0 ;# not sure if this line is correct
> set dist [ measure bond {"$selj $seli"} ] ;# I think the
> problem are the double quotes, but I really don't have idea
> puts "$j $i $dist"
> }; # for j
> }; # for i
> close $file
> Any help with the code is appreciated
> loading the ca-dist.dat into R in this way I can get the average
> distance very easy and do some plots
>
> Ps ca-dist.tcl is somewhat different of what I want
>
> --
> Mr. Murpholino X
>
> "mi segundo nombre es Peligro!!"
>