From: Axel Kohlmeyer (akohlmey_at_gmail.com)
Date: Wed Jul 06 2011 - 19:01:31 CDT

On Wed, Jul 6, 2011 at 6:04 PM, KIRTANA S <skirtana4_at_gmail.com> wrote:
> All,
>
> I am using the following script , the loop does not move to the next vakue
> of i (which is my residue number ). It takes i value at 1 throughout the
> run.Please suggest where I am going wrong

this looks familiar, like i've debugged it (and complained
about the bad VMD scripting style) before.

first off, you should indent scripts, so that it is easier
to follow the logic.

>
> set nf [molinfo top get numframes]
> for {set x 0} {$x < $nf} {incr x} {
> set j 2

here is the problem! you set j outside the i loop.

> for {set i 1} {$i < 4} {incr i} {
> set sel1 [atomselect top "resid $i"]
> while {$j <= 3 } {

so only on the first i iteration, $j will be smaller or equal 3.

> $sel1 frame $x
> $sel1 update

the update is not needed

> set sel2 [atomselect top "resid $j"]
> $sel2 frame $x

this can be combined into one line.

> $sel2 update

the update is not needed, you just created the
selection it is already up-to-date.

> set com1 [measure center $sel1 weight mass]
> set com2 [measure center $sel2 weight mass]
> set comdist [vecdist $com1 $com2]
> puts "COM distance for frame $x between $i $j $comdist"
> incr j $i

you created a selection but didn't delete it. => memory leak
since you did it in an inner loop => _big_ memory leak.

> }

and another loop without deleting the selection.

> }
> }

cleaned up, i would get this.

set nf [molinfo top get numframes]
for {set x 0} {$x < $nf} {incr x} {
    for {set i 1} {$i < 4} {incr i} {
        set j 2
        set sel1 [atomselect top "resid $i"]
        while {$j <= 3 } {
            $sel1 frame $x
            set sel2 [atomselect top "resid $j" frame $x]
            set com1 [measure center $sel1 weight mass]
            set com2 [measure center $sel2 weight mass]
            set comdist [vecdist $com1 $com2]
            set comdist 0.0
            puts "COM distance for frame $x between $i $j $comdist"
            incr j $i
            $sel2 delete
        }
        $sel1 delete
    }
}

axel.

-- 
Dr. Axel Kohlmeyer
akohlmey_at_gmail.com  http://goo.gl/1wk0
Institute for Computational Molecular Science
Temple University, Philadelphia PA, USA.