From: Axel Kohlmeyer (akohlmey_at_gmail.com)
Date: Tue Nov 27 2012 - 16:06:29 CST

On Tue, Nov 27, 2012 at 10:00 PM, Mustafa Tekpinar <tekpinar_at_buffalo.edu> wrote:
> Hi,
> I am trying to produce an Elastic Network Model representation by using a
> simple VMD script. However, each time I get the following error:
> "vecsub: two vectors don't have the same size"

you seem to be making assumptions about the residue id,
that may not be given. also the way you use atomselect
inside the nested loops is creating a memory leak and
very inefficient. check out the modifications below.

>
> Here is the script I wrote:
> //==========================================
> #Select a CPK representation of CA atoms.
> menu graphics off
> menu graphics on
> mol modselect 0 0 name CA
> mol modstyle 0 0 CPK 1.000000 0.300000 10.000000 10.000000
> menu graphics off
>
> #R_c = Cutoff radius
> set R_c 10.0
> set ca_atoms [atomselect top "name CA"]
> set total_ca [$ca_atoms num]
> puts "Total number of CA atoms are $total_ca"

set allca [$ca_atoms get {x y z}]

for { set i 0 } { $i < $total_ca } { incr i } {
    set coord1 [lindex $allca $i]
    for { set j 0 } { $j < $i} { incr j } {
         set coord2 [lindex $allca $j]
         set dist [veclength [vecsub $coord1 $coord2]]
> if {$dist <= $R_c} {
> if {[expr ($i-$j)]==1 } {
> draw color red
> draw cylinder $coord1 $coord2 radius 0.2
> } else {
> draw color yellow
> draw cylinder $coord1 $coord2 radius 0.1
> }
> }
> }
> }
>
> //==========================================
> I will really be glad if anybody can point me my mistake.
> Mustafa Tekpinar

--
Dr. Axel Kohlmeyer  akohlmey_at_gmail.com  http://goo.gl/1wk0
International Centre for Theoretical Physics, Trieste. Italy.