From: Axel Kohlmeyer (akohlmey_at_gmail.com)
Date: Mon Sep 21 2009 - 14:22:08 CDT

On Mon, Sep 21, 2009 at 2:45 PM, Myunggi Yi <myunggi_at_gmail.com> wrote:
> Dear VMD users,
>
> I have an atom selection problem.
> I want to use a variable in the atom selection.
>
> =====================
>>Main< (16T) 21 % set i 1
>>Main< (16T) 22 % set sel [atomselect top {name "B.*" and segid $i}]
> atomselect39
>>Main< (16T) 23 % $sel num
> 0
>>Main< (16T) 24 % set sel [atomselect top {name "B.*" and segid 1}]
> atomselect40
>>Main< (16T) 25 % $sel num
> 26
> =====================
>
> As you see the above, if I use a variable I cannot select the atoms.
>
> Can anyone help?

please read up on tcl string syntax and quoting rules. any string in
curly braces is a literal string, any string in double quotes is expanded.

so you can try either (untested):

set sel [atomselect top "name \"B.*\" and segid $i"]

or

set sel [atomselect top [join [list {name "B.*"} "segid $i"] { and } ]]

cheers,
    axel.
>
>
> --
> Best wishes,
>
> Myunggi Yi
> ==================================
> 91 Chieftan Way
> Institute of Molecular Biophysics
> Florida State University
> Tallahassee, FL 32306
>
> Office: +1-850-645-1334
>
> http://sites.google.com/site/myunggi/
> http://people.sc.fsu.edu/~myunggi/
>
>

-- 
Dr. Axel Kohlmeyer    akohlmey_at_gmail.com
Institute for Computational Molecular Science
College of Science and Technology
Temple University, Philadelphia PA, USA.