From: Axel Kohlmeyer (akohlmey_at_gmail.com)
Date: Thu Feb 21 2013 - 04:43:08 CST

On Thu, Feb 21, 2013 at 10:26 AM, Marzieh Alishahi
<alishahi.mar_at_gmail.com> wrote:
> Dear VMD users
>
> I know it might be a simple question, but I will be so grateful if you help
> me.

> I want to put all the serial id of ion atoms in an array, I tried the
> following commands;
>
> set ion [atomselect top “ion”]
>
> $ion get serial
>
> The second line gives me the serial number of all atoms, which are not in
> array format. Can you help me how I can put this sequence of numbers in
> array format?

you get a list. what do you need an array for? by what do you want to index it?
please note that arrays in Tcl are "associative arrays" or "maps" and
not "vectors" or "sequential arrays" like in programming languages
like C, C++ or Fortran, that is that data is stored in pairs and
indexed via a hash table. that makes random access faster, but
sequential access slower than with lists. lists much more resemble
"sequential arrays"
thus lists are generally much more efficient and convenient to handle
when looping over its elements.
which is the typical case in vmd/tcl scripts. it is trivial Tcl coding
to convert a list into an array, e.g. via:

set i 0
foreach a $list {
   set array($i) $a
   incr i
}

please provide an example of how you want to use the data. it is
highly likely, that things can be done differently and more
efficiently.

axel.

axel.

>
> Thanks in advance
>
>
> Marzieh Alishahi

-- 
Dr. Axel Kohlmeyer  akohlmey_at_gmail.com  http://goo.gl/1wk0
International Centre for Theoretical Physics, Trieste. Italy.