From: Axel Kohlmeyer (akohlmey_at_cmm.chem.upenn.edu)
Date: Sun Jan 11 2009 - 13:53:41 CST

On Sun, 11 Jan 2009, A D wrote:

dear <it-would-be-so-much-nicer-if-i-could-put-your-name-here>,

AD> I was wondering if it was possible to put a set of atom selections
AD> in a list. I tried the following:

yes. i've been doing it repeatedly. it works very nicely,
also you can use arrays, i.e. hashed lists, instead.

AD> -------------------------------------------------------------------
AD> set list1 [list]
AD> for { set resi 20 } { $resi <= 60 } { incr resi } {
AD>   set sel [atomselect 0 "protein and (resid $resi)"]

please note the difference between 'resid' and 'residue'.
resi are numbers that are read from the topology/coordinate
data and that may not be consecutive and may be redundant
(i.e. one resid referring to multiple residues in different
chains/segments), whereas residue is a numbering generated
by VMD upon load and that is complete, consecutive
and bijective.

AD>   lappend list1 $sel
AD> }
AD> --------------------------------------------------------------------
AD> But when I try to access the selection to calculate the center of mass:
AD> -------------------------------------------------------------------
AD> for { set i 0 } { $i <= 40 } { incr i } {
AD>   set sel [lindex $list1 $i]
AD>   set cm [measure center $sel weight mass]
AD>   puts "cm"
AD> }

BTW: a simpler and easier way (saves the multiple searches with lindex)
to build this loop is to do:

foreach sel $list1 {
    set cm [measure center $sel weight mass]
    puts "$cm"
}

AD> --------------------------------------------------------------------
AD> it complains that the selection is empty. I want to do this because

this doesn't mean that the selection does not work, but rather
that there are not atoms in the selection. see my comment about
resid vs. residue above. you can check this either when creating
the selection or when evaluating with a test, for example:

for { set resi 20 } { $resi <= 60 } { incr resi } {
   set sel [atomselect 0 "protein and (resid $resi)"]
   if {[$sel num] > 0} then {
     lappend list1 $sel
   } else {
     $sel delete
   }
}

AD> I don't want to select these residues again and again in all the
AD> frames of my huge trajectory. I just want to use $sel frame
AD> $frameno. I guess I can alternatively select them again and again in

your approach is the best way. creating and deleting selections
is time consuming. the savings in your case are especially large
since the internal list of indices does not need to be recreated,
since your selection does not change over time (in other words
you don't need to do a "$sel update" after "$sel frame $n",
the update is the most time consuming part of selection creation
and processing).

AD> a loop while keeping deleting them by $sel delete, but I am not sure
AD> if this would be as fast. I would appreciate your comments.

i guess the main problems is a misunderstanding of the error message.

cheers,
   axel.

AD>

-- 
=======================================================================
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.