From: Kiana Jahani (kiana.jahani_at_REMOVE_yahoo.com)
Date: Sun Jan 23 2022 - 05:13:46 CST

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