From: Kiana Jahani (kiana.jahani_at_REMOVE_yahoo.com)
Date: Mon Jan 24 2022 - 00:35:23 CST

Dear PeterThank you so much for your help and recommendation. I really appreciate it.Best,Kiana
   On Sunday, January 23, 2022, 08:42:00 PM GMT+3:30, Peter Freddolino <petefred_at_umich.edu> wrote:
 
 Dear Kiana,At least a couple of things that need to be fixed are (note that I use backticks to enclose code excerpts below):`veclenth` (sic) should be `veclength`the `k` in the expression `"lindex ($coor1 k)"` is missing the `$` that would indicate a variable referencethe lindex calls in that line should be `lindex $coor1 $k` , not `lindex ($coor1 k)`
In addition, even having fixed all of this, I suspect you're going to run into a complaint about the use of the subtraction in that line because you're trying to subtract two three-vectors; you should probably be using `vecsub` instead of the `-` operator.

More generally, when confronted by a situation like this, I would highly recommend beginning with a small piece of code that does your key calculation and making sure that it works properly in isolation (eg, doing a needed calculation on a single frame), and only then building up to the larger script infrastructure. That way you (and anyone helping troubleshoot) can focus better on where the problem is likely to be.Best,Peter

On Sun, Jan 23, 2022 at 7:20 AM Kiana Jahani <kiana.jahani_at_remove_yahoo.com> wrote:

Dear all,I have a dcd file and I want to calculate the distances between one atom and a series of atoms and select the minimum one in each frame. I wrote the following Tcl commands. But I got the following error in vmd:'can't use non-numeric string as operand of "-" '
(related to the expr command). I didnt realize what was the problem.
Can anyone help me with that? I would appreciate it.Best,
Kiana

proc distance { seltext1 seltext2 f }
set sel1 [atomselect top "seltext1"]  ####select 150 atoms
set sel2 [atomselect top "seltext2"]  ####select one atom

set nf [molinfo top get numframes]

set outfile [open $f w] ###Open file specified by the variable f
for {set i 0} {$i < $nf} {incr i} {

puts "frame $i of $nf"
$sel1 frame $i
$sel2 frame $i

set coor1 [$sel1 get {x y z}]set coor2 [$sel2 get {x y z}]
set l2 { }

for {set k 0} {$k < 150} {incr k} {
lappend l2 [ veclenth [expr {"lindex ($coor1 k)" - "lindex ($coor2 0)" } ] ]}
set min "$l2 0"
for {set j 0} {$j < 165 } {incr j} {set t "$l2 j"
if {$t < $min}
set mindata($i.r) $t}

puts $outfile "$i  $mindata($i.r)"

}close $outfile