From: Nuno Loureiro Ferreira (nunolf_at_ci.uc.pt)
Date: Sat Jul 14 2007 - 11:49:29 CDT

Has Axel said, you should import those sel1 sel2 vars.
But you say that you get the result on the console, so I deduce that you
are feeding those vars some way to the proc.

About the no output ... because your script reports an error before
reaching the "puts $f".
Specifically:

set list1 [lsort -increasing $lists 0]

What's the "0" doing there? ;-)
And by the way, why are you sorting a list of 2 elements? Be sure you
know what you are doing, since the results
from the measure contacts command, are indices, you cannot sort these
lists, since you the correct correspondence between the elements of both
element lists.

Probably you want to sort the pairs of contacts, using -increasing and
-index 0?
Check the following:

vmd > set c [measure contacts 3 $sel1 $sel2]
{25 25 21 22 21 22 34 22 22 34 34 35 35 23} {36 39 36 36 39 39 39 38 56
38 37 36 37 39}
vmd > set a [lindex $c 0]
25 25 21 22 21 22 34 22 22 34 34 35 35 23
vmd > set b [lindex $c 1]
36 39 36 36 39 39 39 38 56 38 37 36 37 39
vmd > foreach i $a j $b {lappend nlist "$i $j"}
vmd > puts $nlist
{25 36} {25 39} {21 36} {22 36} {21 39} {22 39} {34 39} {22 38} {22 56}
{34 38} {34 37} {35 36} {35 37} {23 39}
vmd > lsort -increasing -index 0 $nlist
{21 36} {21 39} {22 36} {22 39} {22 38} {22 56} {23 39} {25 36} {25 39}
{34 39} {34 38} {34 37} {35 36} {35 37}

Is this what you want?

Cheers,
Nuno

sally cii wrote:
> Dear all,
> I want to write a tcl script that can return the list of atom index in
> $sel1 that within a certain distance contact with atoms in $sel2
> during a trajectory. Here is the trial script, after I load this
> script, I got the atom index printed out in tcl console together with
> complain about 'bad option', but not saved in the file I wanted.
> Can anyone tell me how to return a list in a file? thank you in advance!
>
> #####################################################
> proc num_contact {mol dist fname} {
>
> set nf [molinfo top get numframes]
>
> set f [open $fname "w"]
>
> for {set i 0} {$i < $nf} {incr i} {
>
> $sel1 frame $i
>
> $sel1 update
>
> $sel2 frame $i
>
> $sel2 update
>
> set lists [measure contacts $dist $sel1 $sel2]
>
> set list1 [lsort -increasing $lists 0]
>
> puts $f "$list1"}
>
> close $f
>
> $sel1 delete
>
> $sel2 delete
>
> }
> ####################################################
>
> Sincerely,
> Sally Cii
> ------------------------------------------------------------------------
>
> No virus found in this incoming message.
> Checked by AVG Free Edition.
> Version: 7.5.476 / Virus Database: 269.10.4/898 - Release Date: 12-07-2007 16:08
>