From: J T (jtibbitt_at_odu.edu)
Date: Tue Aug 21 2007 - 20:00:47 CDT

>> i suspect your problems arise from the
> fact, that you do _not_ distiguish between water
>> oxygen and hydrogen and thus may have multiple
>> matches with different distance.

I've also tried searching for only water oxygen contacts within a
given cutoff distance to the atom selection and the problem I'm
getting is that some of those oxygens are close to more than one atom
from the specified atom selection. I've been playing with this for a
couple of days now. The following is a messy little hack just
completed that seems to work. To note that only searching for water
oxygens results in a much faster code. That will help since I plan
on using this on each frame of large trajectories.

After obtaining the combined list of atom indices with matching
distances

1) First sort the list according to distance in decreasing order
2) Second sort the list according to residue (with -unique option)
3) Third sort the list according to distance again.

proc nwat {n sel} {
   set lists [measure contacts 5 [atomselect top "water and name
OH2"] $sel]
   set wlist [lindex $lists 0]
   set slist [lindex $lists 1]
   for {set i 0} {$i < [llength $wlist]} {incr i} {
     set satom [lindex $slist $i]
     set watom [lindex $wlist $i]
     set d [measure bond "$watom $satom"]
     lset wlist $i [list $watom $d]
   }
   set wlist2 [lsort -index 1 -decreasing $wlist]
   set wlist3 [lsort -unique -index 0 $wlist2]
   set wlist4 [lsort -index 1 $wlist3]
}

Thanks,
Jeff Tibbitt
jtibbitt_at_odu.edu

------------------------------------------------------------------------
----------------------------------------------------
On Aug 21, 2007, at 8:26 PM, Axel Kohlmeyer wrote:

> On 8/21/07, Axel Kohlmeyer <akohlmey_at_cmm.chem.upenn.edu> wrote:
>> On Tue, 21 Aug 2007, J T wrote:
>>
>> jeff,
>>
>> i suspect your problems arise from the
>> fact, that you do distiguish between water
>
> arrggggh, typo. this should read:
>
> fact, that you do _not_ distiguish between water
>
> sorry,
> axel.
>
>> oxygen and hydrogen and thus may have multiple
>> matches with different distance.
>>
>> the simple workaround would be to search
>> only for water oxygens. it is generally
>> more consistent in many ways, too.
>>
>> also, i would like to be careful with the
>> use of 'resid' this is not guaranteed to be
>> unique (it is whatever VMD reads from the
>> pdb/psf/whatever file).
>>
>> there are more elaborate ways to work around
>> your problems, in case you absolutely need
>> to include the hydrogens in your search.
>>
>> cheers,
>> axel.
>>
>> JT> > > Try instead
>> JT> > > set nwatlist [lsort -unique -index 1 $wlist]
>> JT>
>> JT> I've also tried that. Elements of the list may have the same
>> residue
>> JT> number, but the distance is still different, which renders the -
>> JT> unique option void. I've even setting the elements of the
>> list with:
>> JT>
>> JT> lset wlist $i [list $d $wresnum]
>> JT>
>> JT> instead of
>> JT>
>> JT> lset wlist $i "$d $wresnum"
>> JT>
>> JT>
>> JT> Jeff Tibbitt
>> JT>
>> JT>
>> JT>
>> JT>
>> JT>
>> JT>
>> JT>
>> JT>
>> JT>
>> JT>
>> ---------------------------------------------------------------------
>> ---
>> JT> ----------------------------------------------------
>> JT> On Aug 21, 2007, at 5:34 PM, Nuno Loureiro Ferreira wrote:
>> JT>
>> JT> > J T wrote:
>> JT> >>> > Instead of
>> JT> >>> > set nwatlist [lsort $wlist]
>> JT> >>> >
>> JT> >>> > try,
>> JT> >>> > set nwatlist [lsort -unique $wlist]
>> JT> >>
>> JT> >>
>> JT> >> Tried it. Since the list elements are double valued
>> (distance and
>> JT> >> residue number) the -unique does not work. Is a different
>> way to
>> JT> >> set the list up so the -unique option would filter out all
>> double
>> JT> >> residue numbers.
>> JT> >
>> JT> > Right ;-)
>> JT> > Try instead
>> JT> > set nwatlist [lsort -unique -index 1 $wlist]
>> JT> >
>> JT> > This way you will sort by uniqueness on the second element,
>> in your
>> JT> > case, the residue number.
>> JT> >
>> JT> >
>> JT> >> Right now the ith list element is created with the command:
>> JT> >>
>> JT> >> lset wlist $i "$d $wres"
>> JT> >>
>> JT> >> where $d is the distance and $wres is the water residue
>> number,
>> JT> >>
>> JT> >>
>> JT> >>
>> JT> >>
>> JT> >>
>> JT> >>
>> JT> >>
>> JT> >>
>> JT> >>
>> JT> >>
>> JT> >>
>> JT> >>
>> JT> >>
>> JT> >> On Aug 21, 2007, at 4:55 PM, Nuno Loureiro Ferreira wrote:
>> JT> >>
>> JT> >>> Hi JT
>> JT> >>>
>> JT> >>> Instead of
>> JT> >>> set nwatlist [lsort $wlist]
>> JT> >>>
>> JT> >>> try,
>> JT> >>> set nwatlist [lsort -unique $wlist]
>> JT> >>> N.
>> JT> >>>
>> JT> >>> J T wrote:
>> JT> >>>> Dear VMD Community,
>> JT> >>>>
>> JT> >>>> I've been working on a script that will select the N-closest
>> JT> >>>> waters to a specified atom selection by following the
>> algorithm
>> JT> >>>> suggested by John Stone in an earlier post. It
>> successfully
>> JT> >>>> returns a sorted list of increasing distances, but there are
>> JT> >>>> duplicate water residues. The script generates a list of
>> all
>> JT> >>>> water indices within a max cutoff distance. Then each water
>> JT> >>>> index in that list is replaced with a double valued element
>> JT> >>>> containing the distance and the water residue. Is there
>> a way I
>> JT> >>>> can use the -unique option somehow to fix this?
>> JT> >>>>
>> JT> >>>> Thank-you for reading,
>> JT> >>>> Jeff Tibbitt
>> JT> >>>> jtibbitt_at_odu.edu <mailto:jtibbitt_at_odu.edu>
>> JT> >>>>
>> JT> >>>>
>> JT> >>>> John Stone's algorithm:
>> JT> >>>> / 1) select all waters within the max cutoff distance M /
>> JT> >>>> / 2) calculate the distance D of each water molecule and
>> add the
>> JT> >>>> index and //distance to a list or lists /
>> JT> >>>> / 3) sort the list(s) by the distance (keeping the water
>> index
>> JT> >>>> and distance //assocation intact, if they are in separate
>> JT> >>>> lists..) /
>> JT> >>>> / 4) select the closest N waters from the sorted list// /
>> JT> >>>> /
>> JT> >>>> /
>> JT> >>>> /
>> JT> >>>> /
>> JT> >>>> /My Script:/
>> JT> >>>> proc nwat {n sel} {
>> JT> >>>> set lists [measure contacts 6 [atomselect top water] $sel]
>> JT> >>>> set wlist [lindex $lists 0]
>> JT> >>>> set slist [lindex $lists 1]
>> JT> >>>> set n [llength $wlist]
>> JT> >>>> for {set i 0} {$i < $n} {incr i} {
>> JT> >>>> set satom [lindex $slist $i]
>> JT> >>>> set watom [lindex $wlist $i]
>> JT> >>>> set wres [[atomselect top "index $watom"] get resid]
>> JT> >>>> set d [measure bond "$watom $satom"]
>> JT> >>>> lset wlist $i "$d $wres"
>> JT> >>>> } set nwatlist [lsort $wlist]
>> JT> >>>> }
>> JT> >>>>
>> -------------------------------------------------------------------
>> JT> >>>> -----
>> JT> >>>>
>> JT> >>>> No virus found in this incoming message.
>> JT> >>>> Checked by AVG Free Edition. Version: 7.5.484 / Virus
>> Database:
>> JT> >>>> 269.12.0/961 - Release Date: 19-08-2007 7:27
>> JT> >>>>
>> JT> >>>
>> JT> >>
>> JT> >>
>> JT> >>
>> JT> >
>> JT>
>>
>> --
>> =====================================================================
>> ==
>> Axel Kohlmeyer akohlmey_at_cmm.chem.upenn.edu http://
>> www.cmm.upenn.edu
>> Center for Molecular Modeling -- University of Pennsylvania
>> Department of Chemistry, 231 S.34th Street, Philadelphia, PA
>> 19104-6323
>> tel: 1-215-898-1582, fax: 1-215-573-6233, office-tel:
>> 1-215-898-5425
>> =====================================================================
>> ==
>> If you make something idiot-proof, the universe creates a better
>> idiot.
>>
>>
>
>
> --
> ======================================================================
> =
> Axel Kohlmeyer akohlmey_at_cmm.chem.upenn.edu http://
> www.cmm.upenn.edu
> Center for Molecular Modeling -- University of Pennsylvania
> Department of Chemistry, 231 S.34th Street, Philadelphia, PA
> 19104-6323
> tel: 1-215-898-1582, fax: 1-215-573-6233, office-tel: 1-215-898-5425
> ======================================================================
> =
> If you make something idiot-proof, the universe creates a better
> idiot.