2017-04-26 133 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

@單調,好點。請參閱編輯。 –

相關問題