From: Brian Radak (
Date: Thu Dec 15 2016 - 09:33:06 CST

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?

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").
Maybe I should be content with that.


On Thu, Dec 15, 2016 at 2:31 AM, Ajasja Ljubetič <>

> 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--94eb2c0941ba8043aa0543b42b0a--