From: Axel Kohlmeyer (
Date: Tue May 02 2006 - 11:22:22 CDT

On Tue, 2 May 2006, John Stone wrote:

JS> Enzo,
JS> If you don't like writing the long expression below, you could

enzo, can you please explain, what you want to do.
there may be several solutions, but that depends
very much on what and how you need the coordinates.

JS> simply do something like:
JS> proc getatomcoords { index } {
JS> return [lindex [[atomselect top "index $index"] get {x y z}] 0]
JS> }

please take care, that this subroutine creates a memory leak,
as it allocates a selection, without deleting it.

if you want to access coordinates from an array/list you can
also do:

set sel [atomselect top "all"]
set coords [$sel get {x y z}]
$sel delete

and then access the coordinates via lindex from $coords.

best regards,
   axel (happy that there is a wireless here during a boring talk).

JS> You could then write the much more compact expression:
JS> getatomcoords 25
JS> If you want to be able to specify the atom in a 1-based indexing scheme, you
JS> could use "serial" rather than index, if you prefer:
JS> proc getatomcoords { serial } {
JS> return [lindex [[atomselect top "serial $serial"] get {x y z}] 0]
JS> }
JS> You could then write the same command with 1-based indices:
JS> getatomcoords 26
JS> John Stone
JS> On Tue, May 02, 2006 at 04:39:10PM +0200, Enzo Vitale wrote:
JS> > Dear VMD experts,
JS> >
JS> > I have another simple question, again related to scripting VMD by
JS> > means of TCL: is there a predefined array variable holding the
JS> > coordinates of all atoms of a given molecule ?
JS> >
JS> > So far, I get the coordinates via the following ugly expression:
JS> >
JS> > [lindex [[atomselect top "index 25"] get {x y z}] 0]
JS> >
JS> > when for instance I need the coordinates of the 26-th atom, but I
JS> > guess there must be a simpler and more readable form for getting the
JS> > same result.
JS> >
JS> > Thank you in advance,
JS> > Enzo

Axel Kohlmeyer
   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.