From: Jan Saam (saam_at_charite.de)
Date: Wed Jun 13 2007 - 04:00:03 CDT

Dear Manali,

in there's a script in the plugin moltoptools that does what you want.
It takes two lists and sorts one list and rearranges the elements order
of the second list in the same way.

The script can be called with the command
::moltoptools::sort_alike $list1 $list2 <options for the lsort command>

For you convenience here's the script:

##########################################################
# Sorts elements in list1 in the same way as list2 would #
# be sorted using the options for the lsort command #
# given in args. #
# Example: #
# ::moltoptools::sort_alike {a b c d} {3 2 4 1} -integer #
# --> c b d a #
##########################################################

proc ::moltoptools::sort_alike { list1 list2 args } {
   set index {}
   if {[lsearch $args "-index"]>=0} {
      set index [lindex $args [expr {1+[lsearch $args "-index"]}]]
   }

   foreach s $list1 t $list2 {
      if {[llength $index]} {
         lappend combined [list $s [lindex $t $index]]
      } else {
         lappend combined [list $s $t]
      }
   }

   foreach pair [eval lsort $args -index 1 [list $combined]] {
      lappend sorted1 [lindex $pair 0]
      lappend sorted2 [lindex $pair 1]
   }
   return [list $sorted1 $sorted2]
}

Manali Mehendale schrieb:
> Hi,
>
> I am trying to write a Tcl script that calculates the minimum distance
> between
> a set of residues in each frame of a trajectory over time.
>
> In the process i generate a list that contains the min. distances between
> each residue (r1-r2, r1-r3, r2-r3 etc) which then i sort to find the least
> number.
>
> What i also would like is the names of the residues that have this minimum
> distance. I have created a parallel list that contains the names of
> residues interacting (r1-r2, r1-r3, r2-3).
>
> Is it possible to find which element no. in the previous list is the
> minimum and then access the same element no. from the second list ?
>
> Any help will be greatly appreciated !
>
> Thanks,
> -Manali
>
>
>
>

-- 
---------------------------
Jan Saam
Institute of Biochemistry
Charite Berlin
Monbijoustr. 2
10117 Berlin
Germany
+49 30 450-528-446
saam_at_charite.de