我在VMD(Visual Molecular Dynamics)中使用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
我运行第二个代码时收到的错误消息是&#34;无效的命令名称&#34; 26.774817104116487&#34;&#34;
如果有人能给我第二双眼睛让我知道发生了什么,我会非常感激!提前谢谢!
答案 0 :(得分: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