From: Axel Kohlmeyer (axel.kohlmeyer_at_theochem.ruhr-uni-bochum.de)
Date: Wed Jul 27 2005 - 15:09:23 CDT

On Wed, 27 Jul 2005, John Stone wrote:

hi,
 
JS> You might find it easier to generate the atom selection text with a
JS> call to the Tcl "format" proc first, something like:
JS> set seltext [format "resid 5 and chain %s and not name [0-9]?H.*" $names($i)]

cannot work, since tcl will try to expand the [0-9] when in double quotes,
and also, IIRC, you need the double quotes around the regular expression
to make the selection parser in VMD happy, right?

however,

set seltext [format {resid 5 and chain %s and not name "[0-9]?H.*"} $names($i)]

should work (better).

axel.

p.s.: the general problem of combining the two selections texts below
is that you need the double quotes to expand $names($i), but you
need the curly braces to not expand the regular expression before
creating the selection. john's suggestion of using format is a nice
way to avoid becoming a victim of the falling toothpick syndrome
(as you can expand the variables outside of the literal string).

JS>
JS> I didn't check, but you should make sure that you're properly escaping
JS> your regular expression there. This is discussed in the User's Guide here:
JS> http://www.ks.uiuc.edu/Research/vmd/vmd-1.8.3/ug/node81.html#4997
JS>
JS> John Stone
JS> vmd_at_ks.uiuc.edu
JS>
JS> On Wed, Jul 27, 2005 at 06:18:53PM +0200, Ramon Crehuet wrote:
JS> > Hi all,
JS> > I have a problem writing a tcl script. The following line
JS> >
JS> > set sel [atomselect top "resid 5 and chain $names($i) and not name
JS> > "[0-9]?H.*" "]
JS> >
JS> > gives the error:
JS> > extra characters after close-quote
JS> > Looking at previous e-mail from the list, I tried:
JS> >
JS> > set sel [atomselect top {resid 5 and chain $names($i) and not name
JS> > "[0-9]?H.*" }]
JS> >
JS> > but then I get:
JS> > ERROR) Selection terminated too early
JS> > syntax error
JS> > atomselect: cannot parse selection text: chain $names($i) and resid 5 to
JS> > 114 and not name "[0-9]?H.*"
JS> >
JS> > It's a pity because these two work:
JS> > set sel [atomselect top "chain $names($i) "]
JS> > set sel [atomselect top {resid 5 and not name "[0-9]?H.*"}]
JS> >
JS> > but I don't know how to combine them...
JS> > Cheers,
JS> >
JS> > Ramon
JS> >
JS> >
JS> > PS. names is an array defined as:
JS> > array set names {0 A 1 B 2 C 3 D 4 E 5 F}
JS>
JS>

-- 
=======================================================================
Dr. Axel Kohlmeyer   e-mail: axel.kohlmeyer_at_theochem.ruhr-uni-bochum.de
Lehrstuhl fuer Theoretische Chemie          Phone: ++49 (0)234/32-26673
Ruhr-Universitaet Bochum - NC 03/53         Fax:   ++49 (0)234/32-14045
D-44780 Bochum  http://www.theochem.ruhr-uni-bochum.de/~axel.kohlmeyer/
=======================================================================
If you make something idiot-proof, the universe creates a better idiot.