From: jeela keel (jeela22_at_gmail.com)
Date: Wed Jan 25 2012 - 13:48:18 CST

Dear Alex and VMD users,

Thank you for your help and I am sorry if I was not clear earlier. I am
looking for a way of counting a molecule for example with an index 452, how
many times does this molecule appear in the selection or how many times it
is in the list of the molcules that are selected.

Based on your suggestion , started writing the following :

So I make the selection of the atom atom_select
then get the index of the atom selected set atom1_list [$atom1_select get
index]
get the number of the atoms in the list atoms1_number [llength
[$atom1_select list]]
                   for {set k 0} {$k < $atoms1_number } {incr k} {
                   set atom1 [lindex $atom1_list $k]
                set atom2_select [atomselect top "resname SOL and pbwithin
5.00 of index $atom1"]
                 set atom2_index [$atom2_select get index]
                    set atom2_list [ $atom2_index list ]
                    set num_atom2 [ llength $atom2_list]

                              puts " atoms: $atom2_list and
num_atoms : $num_atom2
"

*so I get something like this for one single frame. in the list there are
three atoms with index 452 and two atoms of index 1942 and nine atoms of
index 1855.*

atom : 1855 num_atoms 1
atom : 1855 num_atoms 1
atom : 452 num_atoms 1
atom : 452 num_atoms 1
atom : 1855 num_atoms 1
atom : 1855 num_atoms 1
atom : 1942 num_atoms 1
atom : 1855 num_atoms 1
atom : 1855 num_atoms 1
atom : 1855 num_atoms 1
atom : 1942 num_atoms 1
atom : 1855 num_atoms 1
atom : 452 num_atoms 1
atom : 1855 num_atoms 1

the question I am trying to solve, is* how do I count how many atoms are
that have same index* ( meaning how many times the same atom is selected).
and create a new list that has something like this

index 452 3
index 1855 9
index 1942 2

Thank you for any suggestions or sharing scripts that are solving similar
question.

Jeela

On Wed, Jan 25, 2012 at 10:12 AM, Axel Kohlmeyer <akohlmey_at_gmail.com> wrote:

> On Wed, Jan 25, 2012 at 9:39 AM, jeela keel <jeela22_at_gmail.com> wrote:
> > Hello VMD users,
> >
> > Is possible to count how many of same atomselect is in a list or how
> many
> > times atomselect is selected? Using VMD , selected molecules that are
> close
> > to different parts of protein and selected some molecules more than once
> and
> > want to know how many times the same atomselect is been selected or how
> many
> > of them are in the list per each frame.
> >
> > for example in frame 1 there are 4 of atomselect2345 (same molecule) and
> 5
> > of atomselect8509 and so on.
>
> your wording is a bit confusing. lets first see whether we are on the same
> page.
>
> an "atom selection", i.e. the procedure that is created by the
> atomselect command,
> is in essence a list of atoms that is generated based on a rule (the
> selection text).
>
> from what i gather, you are now looking for the *intersection*
> of two atom selections, right?
>
> there are multiple ways to do that. for example, create a new
> selection that contains
> the first selection text combined with the section selection text via
> an "and" condition.
>
> if you want to do that in an automated fashion, there should be
> something like this:
>
> set selintersect [atomselect top "([$sel1 text]) and ([$sel2 text])"]
>
> you could also write a small proc that computes the intersection of
> [$sel1 get index] and [$sel2 get index]. there is an 'intersect' command
> in TclX that does this automatically, but VMD does not contain TclX.
>
> it should also be straightforward to write a small proc to do this.
> you can write the proc fairly efficiently, since you can rely on the
> fact that index lists are always pre-sorted with increasing index.
>
> a good place to look for Tcl script hacks and existing solutions
> is the Tcl/Tk wiki at: http://wiki.tcl.tk
>
> axel.
>
>
> > I have used the command llength and num before that counts how many atoms
> > are in a list, but this time I need to count how many times each specific
> > atomselect is selected in the same frame. then move to next frame where
> > there are different atomselect that again change with next frame.
> >
> > I am trying to write a script to do the above but I am wondering if
> there is
> > a command that can be useful to use in the script . Did anybody wrote
> > something similar to what am trying to do or have any suggestion. Thank
> you
> > for your help and suggestions.
> >
> > jeela
>
>
>
> --
> Dr. Axel Kohlmeyer
> akohlmey_at_gmail.com http://goo.gl/1wk0
>
> College of Science and Technology
> Temple University, Philadelphia PA, USA.
>
>