From: Ajasja Ljubetič (ajasja.ljubetic_at_gmail.com)
Date: Thu Dec 15 2016 - 02:31:16 CST

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
<https://github.com/ajasja/calculate_dihedrals>, I just made an
atomselection for each atom and stored the indices in a list. An example is
here
<https://github.com/ajasja/calculate_dihedrals/blob/master/dihedral_angles_atom_names.tcl#L19>.

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 <brian.radak.accts_at_gmail.com>
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.
> In this case (15 20 18 19) becomes (15 18 19 20).
>
> I expect that there is a very good reason for this behavior (or at least
> one that ends with "it's a lot easier to implement this way") - is there a
> solution to this that is better than just selecting all four atoms
> separately? Writing single atom atomselections seems like a bit of a chore,
> but at least it will always work as expected.
>
> Thanks,
> Brian
>
> --
> Brian Radak
> Postdoctoral Appointee
> Leadership Computing Facility
> Argonne National Laboratory
>
> 9700 South Cass Avenue, Bldg. 240
> Argonne, IL 60439-4854
> (630) 252-8643
> brian.radak_at_anl.gov
>