本帖最后由 小桃UpUp 于 2021-11-6 17:02 编辑
各位老师好,本人刚接触vmd脚本,想统计2340个水分子体系中水分子周围4埃内其余水分子数目少于4个的水分子个数,并输出此分子个数随时间(共5001帧)的变化。目前,自己尝试编写了脚本,仅能做到统计某一帧的结果,具体代码如下(如统计第1帧),请各位老师帮忙看下是否有问题:
set k 0 set numresid 2340 set myfile [open contact.txt w] for {set i 1} {$i <=$numresid} {incr i} { set sel [atomselect top"same residue as {resname SOL and within 4 of resid $i}"] $sel frame 1 $sel update if {[expr [$sel num]/3]<=4} {incr k 1} } puts $myfile "$k" close $myfile 在此基础上尝试添加如下的更新帧的语句:
set k 0 set numresid 2340 set myfile [open contact.txt w] for {set i 1} {$i <= $numresid} {incr i} { set sel [atomselect top "same residue as {resname SOL and within 4 of resid $i}"] for {set j 0} {$j < 5001} {incr j} { $sel frame $j $sel update if {[expr [$sel num]/3] <=4} {incr k 1} } } puts $myfile "$k" close $myfile 但仅能输出所有帧中水分子周围4埃内其余水分子数目少于4个的水分子个数的加和,我的目的是获得每帧的结果随时间的变化,而非总和值。 请各位老师帮帮忙,谢谢大家~
已解决,原来是重复写入文件覆盖了原先的文件,代码如下就不会存在问题了: set myfile [open contact.txt w] for {set j 0} {$j < 5001} {incr j} { set k 0 set numresid 2340 for {set i 1} {$i <= $numresid} {incr i} { set sel [atomselect top "same residue as {resname SOL and within 4 of resid $i}"] $sel frame $j $sel update if {[expr [$sel num]/3] <=4} {incr k 1} } puts $myfile "$k" } close $myfile
|