计算化学公社

 找回密码 Forget password
 注册 Register
Views: 2998|回复 Reply: 0
打印 Print 上一主题 Last thread 下一主题 Next thread

[VMD] 求助 统计体系中分子周围其余分子数目少于4个的分子个数随时间的变化(已解决)

[复制链接 Copy URL]

7

帖子

0

威望

187

eV
积分
194

Level 3 能力者

跳转到指定楼层 Go to specific reply
楼主
本帖最后由 小桃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


评分 Rate

参与人数
Participants 2
eV +8 收起 理由
Reason
五月雨 + 5 GJ!
panernie + 3 赞!

查看全部评分 View all ratings

本版积分规则 Credits rule

手机版 Mobile version|北京科音自然科学研究中心 Beijing Kein Research Center for Natural Sciences|京公网安备 11010502035419号|计算化学公社 — 北京科音旗下高水平计算化学交流论坛 ( 京ICP备14038949号-1 )|网站地图

GMT+8, 2026-2-23 13:59 , Processed in 0.156227 second(s), 21 queries , Gzip On.

快速回复 返回顶部 返回列表 Return to list