2017-04-26 132 views
0

我一直使用一段时间来提取矢量的tcl脚本突然停止工作,我不确定为什么。另外,错误也没有意义。无效的命令名称“”错误

我运行的代码是:

for {set resd 501} {$resd < 502} {incr resd 1} { 
set basefile1 "CCvector$resd" 

set workdir [pwd] 
set nf [molinfo top get numframes] 

set fil [open $basefile1.dat w] 

for {set frame 0} {$frame < $nf} {incr frame 1} { 
    animate goto $frame 
    display update ui 
    set c1 [atomselect top "name C1 and resid $resd and resname G130"] 
    set c3 [atomselect top "name C3 and resid $resd and resname G130"] 
    set c1c [$c1 get {x y z} ] 
    set c3c [$c3 get {x y z} ] 
    set c1c3x [expr [$c3 get x]-[$c1 get x]] 
    set c1c3y [expr [$c3 get y]-[$c1 get y]] 
    set c1c3z [expr [$c3 get z]-[$c1 get z]] 
    set st [expr $frame] 
    puts $fil [list $st $c1c3x $c1c3y $c1c3z ] 
    $c3 delete 
    $c1 delete 
} 
close $fil 

我被接收原始误差是“缺少操作数在@”,然而我取代的代码的部分,以成为:

for {set frame 0} {$frame < $nf} {incr frame 1} { 
    animate goto $frame 
    display update ui 
    set c1 [atomselect top "name C1 and resid $resd and resname G130"] 
    set c3 [atomselect top "name C3 and resid $resd and resname G130"] 
    set c1x [$c1 get x] 
    set c3x [$c3 get x] 
    set c1c3x [expr [$c3x - $c1x]] 
    set c1y [$c1 get y] 
    set c3y [$c3 get y] 
    set c1c3y [expr [$c3y - $c1y]] 
    set c1z [$c1 get z] 
    set c3z [$c3 get z] 
    set c1c3z [expr [$c3z - $c1z]] 
    set st [expr $frame] 
    puts $fil [list $st $c1c3x $c1c3y $c1c3z ] 
    $c3 delete 
    $c1 delete 
} 
close $fil 

而现在我正在收到“Invalid Command Name”“”错误。我哪里错了?

附加信息:我运行这个使用VMD从在加载GROMACS轨迹提取坐标

回答

3

在:

set c1c3z [expr [$c3z - $c1z]] 

你会尝试与-运行$c3z命令$c1z的内容作为参数(并将其返回值作为参数传递给expr)。

要相当于以前版本的代码,这将是:

set c1c3z [expr $c3z - $c1z] 

然而,由于$c3z似乎是空的(所以不是一个数字),你可能有更多的问题。

这里,$c3z$c1z是最有可能为空,这意味着expr评估" - "表达,你会回看到:

$ tclsh <<< 'expr " - "' 
missing operand at [email protected]_ 
in expression " - [email protected]_" 

如果由多纳尔在意见提出,你写的,而不是:

set c1c3z [expr {$c3z - $c1z}] 

代替,然后字面$c3z - $c1z将被传递给exprexpr将能够给你更多有用的错误消息因为它试图对其进行评估:

$ tclsh <<< 'set a ""; expr {$a - $a}' 
can't use empty string as operand of "-" 

expr TCL man page会给你,为什么它是一般最好通过{} -enclosed表达它的更多信息。

+0

更好的办法是'set c1c3z [expr {$ c3z - $ c1z}]'这样可以避免各种麻烦,并且可以实现更高速的编译。 –

+0

@单调,好点。请参阅编辑。 –

相关问题