From: Josh Vermaas (vermaas2_at_illinois.edu)
Date: Fri Nov 06 2015 - 10:07:48 CST

Yeah, you never defined l1. Is it supposed to be l2 or l3?
-Josh

On 11/06/2015 03:56 AM, dipak sanap wrote:
> Hey all,
> I have written a script to find nearest neighbours.It works fine but
> after writing some out put, it gives following error. Please help me
> out with this error.
>
> Error:
> can't read "l1": no such variable.
>
> Script:
>
> #!/bin/env wish
>
> ##Script for n neighbours waters for every SOL oxygen.
>
> proc nb {n sel} {
> set l3 {};
> set wat_oxy [atomselect top "name OW"];
> set nbrs [measure contacts 4.5 $wat_oxy $sel];
>
> set wlist [lindex $nbrs 0];
> set qlist [lindex $nbrs 1];
>
> foreach qatom $qlist watom $wlist {
> set z [atomselect top "index $watom"];
> set wresnum [$z get resid];
> set d [measure bond "$watom $qatom"];
> lappend l1 [list $wresnum $d];
> }
>
> set l2 [lrange [lsort -index 1 [lsort -unique -index 0 [lsort -index 1
> -decreasing $l1]]] 0 [expr $n-1]];
>
> foreach water $l2 {
> lappend l3 [lindex $water 0];
> }
>
> return $l3
>
> $wat_oxy delete;
> array unset $wat_oxy;
> array unset $nbrs;
> array unset $n;
> $sel delete;
> array unset $sel;
> array unset wlist;
> array unset qlist;
> array unset qatom;
> array unset watom;
> $z delete;
> array unset $z;
> array unset wresnum;
> array unset d;
> $l1 delete;
> array unset l1;
> array unset l2;
> }
>
> set o_file [open "closest-4.txt" w];
> set wat_oxy [atomselect top "name OW"];
> set total_wat [$wat_oxy num];
> puts $o_file "Total number of water oxygens are $total_wat"
> set reid [$wat_oxy get resid];
>
> foreach a $reid {
> set oxy [atomselect top "resid $a and name OW"];
> set id [$oxy get resid];
> set neig [nb 4 $oxy];
> puts $o_file "The residue id $id has neighbours $neig";
>
> array unset oxy;
> array unset id;
> array unset neig;
> }
>
>
> close $o_file
>
>