1

我在 VMD(视觉分子动力学)中使用 tk 控制台运行代码。我遇到的第一个问题是代码占用了我的计算机过多的处理能力并导致 VMD 关闭。我认为这是因为我让它将每个结果都打印到文件中。我真的只需要查看距离小于 20 的结果。下面是导致 VMD 关闭的原始代码:

set seg1 [atomselect top "segname LA0 and name CA"]
set seg2 [atomselect top "segname RA0 and name CA"]

set file [open "Contact_map27.dat" w]

set list1 [$seg1 get index]
set list2 [$seg2 get index]

foreach atom1 $list1 {
    foreach atom2 $list2 {
            set index1 [atomselect top "index $atom1"]
            set index2 [atomselect top "index $atom2"]
            set resid1 [[atomselect top "index $atom1"] get resid]
            set resid2 [[atomselect top "index $atom2"] get resid]
            set resnm1 [[atomselect top "index $atom1"] get resname]
            set resnm2 [[atomselect top "index $atom2"] get resname]
 puts $file "$resnm1 $resid1 $resnm2 $resid2 [veclength [vecsub [measure center $index1] [measure center $index2]]]"
            $index1 delete
            $index2 delete
    }
}

close $file

以下是我所做的修改,仅在距离小于 20 时才打印值:

set seg1 [atomselect top "segname LA0 and name CA"]
set seg2 [atomselect top "segname RA0 and name CA"]

set file [open "Contact_map27.dat" w]

set list1 [$seg1 get index]
set list2 [$seg2 get index]

foreach atom1 $list1 {
    foreach atom2 $list2 {
            set index1 [atomselect top "index $atom1"]
            set index2 [atomselect top "index $atom2"]
            set resid1 [[atomselect top "index $atom1"] get resid]
            set resid2 [[atomselect top "index $atom2"] get resid]
            set resnm1 [[atomselect top "index $atom1"] get resname]
            set resnm2 [[atomselect top "index $atom2"] get resname]
    set dist [[veclength [vecsub [measure center $index1] [measure center $index2]]]]
 if {$dist < 20} {
puts $file "$resnm1 $resid1 $resnm2 $resid2 $dist"}
else {puts $file " "}
            $index1 delete
            $index2 delete
    }
}

close $file

运行第二个代码时收到的错误消息是“无效的命令名称”26.774817104116487“”

如果有人能给我第二双眼睛,让我知道发生了什么,我将不胜感激!提前致谢!

4

1 回答 1

1

在对 veclength 的调用周围有一组额外的括号。

您可以通过将一些代码移出内循环并移入外循环来减少 CPU 使用量。只依赖于 atom1 的调用不需要在内部循环中。

您还可以通过使用您设置的索引变量来减少 CPU 数量。不使用变量并且重复“atomselect”调用。我假设它每次都返回相同的索引。

set seg1 [atomselect top "segname LA0 and name CA"]
set seg2 [atomselect top "segname RA0 and name CA"]

set file [open "Contact_map27.dat" w]

set list1 [$seg1 get index]
set list2 [$seg2 get index]

foreach atom1 $list1 {
    set index1 [atomselect top "index $atom1"]
    set resid1 [$index1 get resid]
    set resnm1 [$index1 get resname]
    foreach atom2 $list2 {
            set index2 [atomselect top "index $atom2"]
            set resid2 [$index2 get resid]
            set resnm2 [$index2 get resname]
    set dist [veclength [vecsub [measure center $index1] [measure center $index2]]]
 if {$dist < 20} {
puts $file "$resnm1 $resid1 $resnm2 $resid2 $dist"}
else {puts $file " "}
            $index2 delete
    }
    $index1 delete
}

close $file
于 2015-02-17T15:53:09.077 回答