计算化学公社

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

[VMD] VMD的TCL脚本运行中报错求助

[复制链接 Copy URL]

1

帖子

0

威望

323

eV
积分
324

Level 3 能力者

本帖最后由 nobody 于 2023-9-8 10:19 编辑

各位老师好,我想用TCL语言写一个VMD程序脚本,计算Gromacs产生的xtc文件中每个TBP残基上的C1和C10原子组成的向量,求所获得的向量与z方向的夹角沿着z轴的数密度分布。由于实在不会写脚本,因此用AI生成了一个。在运行过程中报错cannot find attribute '1': in atomsel: get: ,请各位老师指点一下

# 创建一个列表来存储每个TBP残基上的几何中心连线向量
set centerline_vectors_list {}

# 创建一个列表来存储每一帧的夹角
set angle_list {}

# 遍历每一帧
for {set frame 0} {$frame < [molinfo top get numframes]} {incr frame} {
    # 设置当前帧
    animate goto $frame

    # 获取每个TBP残基上的C1和C10原子的坐标
    set sel [atomselect top "resname TBP and (name C1 or name C10)"]
    set num_atoms [$sel num]
    set frame_vectors {}

    for {set i 1} {$i < $num_atoms} {incr i} {
        set atom_coord [$sel get $i]
        lappend frame_vectors $atom_coord
    }

    # 计算每个TBP残基的几何中心连线向量
    if {[llength $frame_vectors] == 2} {
        set c1_coord [lindex $frame_vectors 0]
        set c2_coord [lindex $frame_vectors 1]
        set center_coord [vecscale 0.5 [vecadd $c1_coord $c2_coord]]
        set centerline_vector [vecsub $c2_coord $c1_coord]

        # 计算向量与z轴的夹角,并将角度保存到列表中
        set z_vector {0.0 0.0 1.0}
        set cos_angle [vecdot $centerline_vector $z_vector]
        set angle [expr acos($cos_angle) * 180.0 / 3.1415926]
        lappend angle_list $angle
    }

    # 关闭选择
    $sel delete
}

# 绘制夹角数密度分布
set num_bins 180
set bin_width [expr 180.0 / $num_bins]
set hist [array create hist]
foreach angle $angle_list {
    set bin [expr int($angle / $bin_width)]
    set hist($bin) [expr $hist($bin) + 1]
}

# 输出数据到文件
set output_file [open "angle_distribution.dat" w]
foreach bin [array names hist] {
    set angle_min [expr $bin * $bin_width]
    set angle_max [expr ($bin + 1) * $bin_width]
    set count $hist($bin)
    puts $output_file "$angle_min-$angle_max $count"
}
close $output_file

puts "夹角数密度分布已保存到 angle_distribution.dat 文件中"

本版积分规则 Credits rule

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

GMT+8, 2026-2-21 17:31 , Processed in 0.175572 second(s), 26 queries , Gzip On.

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