From: Axel Kohlmeyer (akohlmey_at_cmm.chem.upenn.edu)
Date: Fri Feb 23 2007 - 11:10:04 CST

On Fri, 23 Feb 2007, Ivan Degtyarenko wrote:

dear ivan,

ID> Here is an example
ID>
ID> vmd > set n [atomselect top {index 0} frame 0]
ID> atomselect0
ID> vmd > set h1 [atomselect top {index 3} frame 0]
ID> atomselect1
ID> vmd > set nh1 [vecdist [$n get {x y z}] [$h1 get {x y z}]]
ID> vecsub: non-numeric in first argument

ID> the error it is due to [$n get {x y z}] returns a single value but not a
ID> list

this is a _very_ common misunderstanding. a 'get' on a selection
_always_ returns a list of lists, i.e. one item per atom in your
selection. in the special case of having only one atom in the
selection, the code does not change that behavior.

try using [lindex [$n get {x y z}] 0] which will return the
first item on the per-atom list, i.e. the x/y/z vector you desire.

generally, for all code that you write using selections, please
always write it in a way that it can handle the case of no and
multiple atoms in the selection properly and you'll get fewer
surprises like this one.

cheers,
   axel.

ID>
ID> vmd > foreach i [$n get {x y z}] {puts $i}
ID> 15.8505477905 12.2714548111 14.0315284729
ID>
ID> and splitting gives:
ID>
ID> vmd > foreach i [split [$n get {x y z}]] {puts $i}
ID> {15.8505477905
ID> 12.2714548111
ID> 14.0315284729}
ID>
ID> while construction like this works fine:
ID>
ID> vmd> set nh1 [vecdist "[$n get x] [$n get y] [$n get z]" \
ID> "[$h1 get x] [$h1 get y] [$h1 get z]"];
ID>
ID>
ID> So, the questions how to make "vecdist [$n get {x y z}] [$h1 get {x y z}]"
ID> work in one string?
ID>
ID>
ID> Ivan Degtyarenko
ID>
ID>

-- 
=======================================================================
Axel Kohlmeyer   akohlmey_at_cmm.chem.upenn.edu   http://www.cmm.upenn.edu
   Center for Molecular Modeling   --   University of Pennsylvania
Department of Chemistry, 231 S.34th Street, Philadelphia, PA 19104-6323
tel: 1-215-898-1582,  fax: 1-215-573-6233,  office-tel: 1-215-898-5425
=======================================================================
If you make something idiot-proof, the universe creates a better idiot.