From: Axel Kohlmeyer (
Date: Thu Dec 15 2016 - 10:24:15 CST

On Thu, Dec 15, 2016 at 10:33 AM, Brian Radak
<> wrote:
> Thanks Ajasja,
> As expected, that makes perfect sense. I guess I was simply too excited
> that the simple single selection method worked in some cases where the atom
> indices happen to be in ascending order.
> However, I would think these kinds of selections are fairly common and the
> simplicity of a single selection is appealing (am I wrong to think I am not
> alone in this?). Would it be possible to add a flag to the "atomselect"
> command that would assure that the indices are returned in the order that
> they are parsed or does such a request merely highlight my ignorance about
> how selections are implemented?

the information about "selection order" (however that may be defined)
is lost in how selection information is stored (as an array of yes/no
besides, i don't consider this a good idea, since no selection method
outside of "index" and "serial" would define a unique ordering of
ajasja's suggestion to maintain an index map is the proper and most
effective way to go about this.

> For now (and I guess this is actually a fairly extensible solution) I have
> just wrapped your for loop into a proc under the assumption that the atom
> names are unique within some base selection (e.g. "protein and resid 1").

even that is a quite optimistic assumption.


> Maybe I should be content with that.
> Cheers,
> Brian
> On Thu, Dec 15, 2016 at 2:31 AM, Ajasja Ljubetič <>
> wrote:
>> Hi!
>> I think `name CG CD2 NE2 HE2` is just syntactical sugar for `(name CG) or
>> (name CD2) or (name NE2) or (name HE2)`. So there is no intrinsic ordering
>> possible and the atoms in the selection are by convention ordered in
>> increasing index.
>> When I last calculated dihedrals
>> <>, I just made an
>> atomselection for each atom and stored the indices in a list. An example is
>> here
>> <>.
>> It's a bit tedious but works well.
>> You could also use a loop:
>> set res {}
>> for {atomname in "CG CD2 NE2 HE2"} {
>> set atomsel [atomselect $mol "chain $chainname and resid $resid and
>> name $atomname"]
>> lappend res [$atomsel get index]
>> $atomsel delete
>> }
>> Best,
>> Ajasja
>> On 14 December 2016 at 22:49, Brian Radak <>
>> wrote:
>>> This is probably a well-known "gotcha", but I'm suitably new to VMD
>>> scripting that I don't know what the standard solution is.
>>> I have a simple script to measure several dihedral angles and print the
>>> output to a file. For example, I want to look at a specific torsion in a
>>> HIS ring, so I wrote the following:
>>> set heSel [atomselect top "protein and resid 1 and name CG CD2 NE2 HE2"]
>>> set hes [measure dihed [$heSel get index] frame all]
>>> and then wrote the contents of the "hes" list to file - but the results
>>> don't match what I get from the GUI because atomselect automatically sorts
>>> the indices and thus changes the dihedral that I thought I was selecting

Dr. Axel Kohlmeyer
College of Science & Technology, Temple University, Philadelphia PA, USA
International Centre for Theoretical Physics, Trieste. Italy.