From: Mark Cunningham (cunningham_at_utpa.edu)
Date: Wed Jul 06 2011 - 12:34:36 CDT

 Sara:

If the values are not changing, it is undoubtably due to the fact that you are not
incrementing the frame. If i is your frame index, you need a
$sel1 frame $i

As a cautionary note, atomselect is computationally expensive. It would be best
to not recompute them. You can use the tcl array construct:

 for {set j 0} {$j < 6} {incr j} {
    set sel1($j) [atomselect $mol "residue $j and resname LEU and name BBc"]
    set sel2($j) [atomselect $mol "residue $j and resname GLU and name BBc"]
}

Inside your loop over the frames, you can access the stored selections:
set vec2 {0 1 0} # This isn't changing so don't put it inside the loop
set conv [expr 180/acos(-1.0)] # Using just the digits of pi that you remember is poor practice
for {set i 0} {$i < $Nframes} {incr i} {
   puts -nonewline $outfile [format "%5i" $i]
   for {set j 0} {$j < 6}{incr j} {
       $sel1($j) frame $i
       $sel2($j) frame $i
       set coord1 [lindex [$sel1($j) get { x y z }] 0]
       set coord2 [lindex [$sel2($j) get { x y z }] 0]
       set vec1 [vecnorm[vecsub $coord1 $coord2 ]] #vecnorm will not fail if the vector length is 0 so
                                                                          #there's no particular reason to do the checking you do
       set angle [expr $conv*acos([vecdot $vec1 $vec2])]
       puts -nonewline [format "%7.2f " $angle] # this will write all 6 angles on one line
   }
   puts $outfile " " # this will force a newline
}

Good luck

Mark
________________________________
From: owner-vmd-l_at_ks.uiuc.edu [owner-vmd-l_at_ks.uiuc.edu] on behalf of Sara baretller [sarabiocomputation_at_gmail.com]
Sent: Wednesday, July 06, 2011 10:04 AM
To: vmd-l_at_ks.uiuc.edu
Subject: vmd-l: Re: Problem with for loop.

Hi all

please if you have an idea or suggestion , i would really appreciated it

I solved the first problem , and the script worked and gave me the angle between the six peptides and the vector { 0 1 0} so i added another loop for the frames. for {set i 0} {$i < 8} {incr i} { , 8 as an example.

 it gave me the same results over and over again for the frames.

here the loop is only till frame 8 as an example:

the repeat for all the angle but i highlighted two anglesas an example that keep repeating between from the first frame to the other frame. angle 117.72161220856759 between (peptides 0)'s vector and the vector { 0 1 0} in frame 0. is the same as angle 117.72161220856759 between peptides 1 vector and the vector { 0 1 0} in frame 1 and so on.

 i alos hilighted : 55.63259488419982 for the height frame

Tcl Counsel results:

residue 0 of 6 peptides
 vec1l vec2l : 19.99249894859944 1.0
Final angle : 117.72161220856759
117.72161220856759
0
residue 1 of 6 peptides
 vec1l vec2l : 18.69491870304378 1.0
Final angle : 135.78875014576658
135.78875014576658
0
residue 2 of 6 peptides
 vec1l vec2l : 27.989461118438296 1.0
Final angle : 55.63259488419982
55.63259488419982
0
residue 3 of 6 peptides
 vec1l vec2l : 27.10166056426399 1.0
Final angle : 93.17285877063786
93.17285877063786
0
residue 4 of 6 peptides
 vec1l vec2l : 29.5839470751503 1.0
Final angle : 145.5654673648764
145.5654673648764
0
residue 5 of 6 peptides
 vec1l vec2l : 25.998842961169046 1.0
Final angle : 87.57519131337723
87.57519131337723
0
residue 0 of 6 peptides
 vec1l vec2l : 19.99249894859944 1.0
Final angle : 117.72161220856759
117.72161220856759
1
residue 1 of 6 peptides
 vec1l vec2l : 18.69491870304378 1.0
Final angle : 135.78875014576658
135.78875014576658
1
residue 2 of 6 peptides
 vec1l vec2l : 27.989461118438296 1.0
Final angle : 55.63259488419982
55.63259488419982
1
residue 3 of 6 peptides
 vec1l vec2l : 27.10166056426399 1.0
Final angle : 93.17285877063786
93.17285877063786
1
residue 4 of 6 peptides
 vec1l vec2l : 29.5839470751503 1.0
Final angle : 145.5654673648764
145.5654673648764
1
residue 5 of 6 peptides
 vec1l vec2l : 25.998842961169046 1.0
Final angle : 87.57519131337723
87.57519131337723
1
residue 0 of 6 peptides
 vec1l vec2l : 19.99249894859944 1.0
Final angle : 117.72161220856759
117.72161220856759
2
residue 1 of 6 peptides
 vec1l vec2l : 18.69491870304378 1.0
Final angle : 135.78875014576658
135.78875014576658
2
residue 2 of 6 peptides
 vec1l vec2l : 27.989461118438296 1.0
Final angle : 55.63259488419982
55.63259488419982
2
residue 3 of 6 peptides
 vec1l vec2l : 27.10166056426399 1.0
Final angle : 93.17285877063786
93.17285877063786
2
residue 4 of 6 peptides
 vec1l vec2l : 29.5839470751503 1.0
Final angle : 145.5654673648764
145.5654673648764
2
residue 5 of 6 peptides
 vec1l vec2l : 25.998842961169046 1.0
Final angle : 87.57519131337723
87.57519131337723
2
residue 0 of 6 peptides
 vec1l vec2l : 19.99249894859944 1.0
Final angle : 117.72161220856759
117.72161220856759
3
residue 1 of 6 peptides
 vec1l vec2l : 18.69491870304378 1.0
Final angle : 135.78875014576658
135.78875014576658
3
residue 2 of 6 peptides
 vec1l vec2l : 27.989461118438296 1.0
Final angle : 55.63259488419982
55.63259488419982
3
residue 3 of 6 peptides
 vec1l vec2l : 27.10166056426399 1.0
Final angle : 93.17285877063786
93.17285877063786
3
residue 4 of 6 peptides
 vec1l vec2l : 29.5839470751503 1.0
Final angle : 145.5654673648764
145.5654673648764
3
residue 5 of 6 peptides
 vec1l vec2l : 25.998842961169046 1.0
Final angle : 87.57519131337723
87.57519131337723
3
residue 0 of 6 peptides
 vec1l vec2l : 19.99249894859944 1.0
Final angle : 117.72161220856759
117.72161220856759
4
residue 1 of 6 peptides
 vec1l vec2l : 18.69491870304378 1.0
Final angle : 135.78875014576658
135.78875014576658
4
residue 2 of 6 peptides
 vec1l vec2l : 27.989461118438296 1.0
Final angle : 55.63259488419982
55.63259488419982
4
residue 3 of 6 peptides
 vec1l vec2l : 27.10166056426399 1.0
Final angle : 93.17285877063786
93.17285877063786
4
residue 4 of 6 peptides
 vec1l vec2l : 29.5839470751503 1.0
Final angle : 145.5654673648764
145.5654673648764
4
residue 5 of 6 peptides
 vec1l vec2l : 25.998842961169046 1.0
Final angle : 87.57519131337723
87.57519131337723
4

On Wed, Jul 6, 2011 at 10:38 AM, Sara baretller <sarabiocomputation_at_gmail.com<mailto:sarabiocomputation_at_gmail.com>> wrote:

I have been having a problem with this script , I will really appreciate your help. so the script does get me the angle between two vectors but then it will not go to the next loop. it stops in the first. by giving the angle between the first vector and the vector {0 1 0 }.

Script:

 for {set j 0} {$j < 6} {incr j} {

                set outfile [open "out.dat" "w"]

                set mol [molinfo top]

                set sel1 [atomselect $mol "residue $j and resname LEU and name BBc"]

                set sel2 [atomselect $mol "residue $j and resname GLU and name BBc"]

                $sel1 frame $j
                $sel2 frame $j

                $sel1 update
                $sel2 update

                puts "residue $j of 6 peptides"
                puts "$sel1 $sel2"

                set nLEU [llength [$sel1 list]]
                set nGLU [llength [$sel2 list]]

                set coord1 [$sel1 get { x y z }]
                set coord2 [$sel2 get { x y z }]

                set vec1 [vecsub [lindex $coord1 0] [lindex $coord2 0]]

                set vec2 {0 1 0}

                set vec1l [veclength $vec1]
                set vec2l [veclength $vec2]

                if {$vec1l != 0} {
                set vec1 [vecnorm $vec1]
                }
                if {$vec2l != 0} {
                set vec2 [vecnorm $vec2]
                }

                set dotprod [vecdot $vec1 $vec2]

                set angle [expr acos($dotprod)]

                set angle [expr ($angle * 180/3.14159)]
                puts "Final angle : $angle"
                puts $angle
                }

close $outfile

tcl councel:

angle 1.5284741404344042
Final angle : 87.57519131337723
87.57519131337723

Thank you

Sara