计算化学公社

标题: VMD 用于测算结冰速率的tcl脚本出错 [打印本页]

作者
Author:
ysrhhhh    时间: 2024-4-22 20:54
标题: VMD 用于测算结冰速率的tcl脚本出错
本帖最后由 ysrhhhh 于 2024-4-22 20:54 编辑

本人目前想通过tcl脚本来计算结冰的速率,在群中咨询了之后,编写了一个通过O-O键来判断当前水分子是属于冰晶分子还是自由水分子的脚本,但是在加载到VMD之后出现了报错,以下是tcl脚本的具体内容,由于之前没有编写过tcl脚本还请大家指出错误,我自己的想法是:通过判断O-O之间的距离是否在2.5A内,在这个范围内则为水分子,不在则是冰晶分子,因为查到的1h冰晶的O-O键长为2.7A,最终获得自由水分子个数,模型中用的tip4p水分子。
set outfile [open growthrate.dat w]
set oxygen_sel [atomselect top "name OW"]
#在某一帧上进行循环
set nf [molinfo top get numframes]
proc analyze_frame {} {
    global oxygen_sel outfile
    set num_oxygen_atoms [$oxygen_sel num]
    set frame_sum 0
    for {set i 0} {$i < $num_oxygen_atoms} {incr i 1} {
        set atom1 [$oxygen_sel get $i]
        set neighbors [$oxygen_sel within 2.5 of $atom1]
        set num_neighbors [llength $neighbors]
        if {$num_neighbors > 1} {
            incr frame_sum
        }
    }
    puts $outfile $frame_sum
}
#在每一帧上进行循环
animate goto 0
for {set i 0} {$i < $nf } {incr i} {
    animate goto $i
    analyze_frame
}
#关闭文件
close $outfile
puts "All Done!"

错误信息:

(, 下载次数 Times of downloads: 6)
还请大家帮忙看一下哪里出错了

作者
Author:
sobereva    时间: 2024-4-23 08:44
atomselect对象根本没有get后面跟上一个序号的用法

参考北京科音分子动力学与GROMACS培训班(http://www.keinsci.com/workshop/KGMX_content.html)的ppt了解get该怎么用:
(, 下载次数 Times of downloads: 9)
作者
Author:
ysrhhhh    时间: 2024-4-23 21:23
sobereva 发表于 2024-4-23 08:44
atomselect对象根本没有get后面跟上一个序号的用法

参考北京科音分子动力学与GROMACS培训班(http://www ...

谢谢社长,我重新修改了一下,但还是出现了问题,以下是我修改后的文件,这次是within这里出现了报错(invalid command name),但是反复尝试了其他表示,还是没有解决,还请指点,还有修改了上次的错误部分没出现报错,但是还是没有完整运行下来,也烦请再看下是否合理
set outfile [open growthrate.dat w]
set oxygen_sel [atomselect top "name OW"]
#在某一帧上进行循环
set nf [molinfo top get numframes]
proc analyze_frame {} {
    global oxygen_sel outfile
    set num_oxygen_atoms [$oxygen_sel num]
    set frame_sum 0
    for {set i 0} {$i < $num_oxygen_atoms} {incr i 1} {
        foreach j [$oxygen_sel list] {
            set coordinate($j) [atomselect top "index $j"]
        set neighbors [ $oxygen_sel within 2.5 of $coordinate($j)]
        set num_neighbors [llength $neighbors]
        if {$num_neighbors > 1} {
            incr frame_sum
        }
      }
    }
    puts $outfile $frame_sum
}
#在每一帧上进行循环
animate goto 0
for {set i 0} {$i < $nf } {incr i} {
    animate goto $i
    analyze_frame
}
#关闭文件
close $outfile
puts "All Done!"
作者
Author:
牧生    时间: 2024-4-23 21:45
https://www.bilibili.com/video/B ... arch-card.all.click      

你看这个教程更合适。
作者
Author:
sobereva    时间: 2024-4-24 06:31
ysrhhhh 发表于 2024-4-23 21:23
谢谢社长,我重新修改了一下,但还是出现了问题,以下是我修改后的文件,这次是within这里出现了报错(inv ...

明显用法不对
within只能出现在选择语句里,而$oxygen_sel是个atomselect对象,后面显然不能直接接一个选择语句,根本没有这种用法




欢迎光临 计算化学公社 (http://bbs.keinsci.com/) Powered by Discuz! X3.3