计算化学公社
标题:
Tcl统计配体附近5埃内的氨基酸,在200帧内出现的次数
[打印本页]
作者Author:
lxhpdx
时间:
2024-6-12 11:50
标题:
Tcl统计配体附近5埃内的氨基酸,在200帧内出现的次数
set sel [atomselect top "same residue as {protein within 5 of resname MOL}"]
for {set i 0} {$i<200} {incr i} {
$sel frame $i
$sel update
set residue_ids [$sel get resid]
set unique_residue_ids [lsort -unique $residue_ids]
if {[llength $unique_residue_ids] > 0} {
puts "Frame: $i unique residue IDs: $unique_residue_ids"
} else {
puts "Frame: $i No residues selected"
}
}
复制代码
这个脚本可以正确统计每帧出现的残基ID如下图
(, 下载次数 Times of downloads: 12)
上传 Uploaded
点击下载Click to download
,于是乎我想统计一下每个残基在200帧中出现了几次,每帧只计数一次。
array set residue_counts {}
set sel [atomselect top "same residue as {protein within 5 of resname MOL}"]
for {set i 0} {$i<200} {incr i} {
$sel frame $i
$sel update
set residue_ids [$sel get resid]
set unique_residue_ids [lsort -unique $residue_ids]
foreach resid $unique_residue_ids {
if {[info exists residue_counts($resid)]} {
incr residue_counts($resid)
} else {
set residue_counts($resid) 1
}
}
}
foreach resid [array names residue_counts] {
puts "Residue ID: $resid, Total Count: $residue_counts($resid)"
}
复制代码
然后统计出来的残基次数就出现了大于200的情况。
(, 下载次数 Times of downloads: 13)
上传 Uploaded
点击下载Click to download
不知道是代码哪里写错了,请各位老师指点。
作者Author:
lxhpdx
时间:
2024-6-12 18:53
# 选择与名为"MOL"的残基距离在5埃之内的蛋白质原子
set sel [atomselect top "same residue as {protein within 5 of resname MOL}"]
# 循环处理200帧的数据
for {set i 0} {$i < 200} {incr i} {
# 设置当前帧
$sel frame $i
# 更新选择
$sel update
# 获取当前帧中选中的残基ID
set residue_ids [$sel get resid]
# 对残基ID进行去重,得到当前帧中的唯一残基ID
set unique_residue_ids [lsort -unique $residue_ids]
# 遍历唯一的残基ID
foreach resid $unique_residue_ids {
# 如果该残基ID已经存在于residue_frames数组中,则添加当前帧号
if {[info exists residue_frames($resid)]} {
lappend residue_frames($resid) $i
} else {
# 否则,初始化该残基ID的帧集合并添加当前帧号
set residue_frames($resid) [list $i]
}
}
}
# 输出每个残基ID以及其出现的帧数
foreach resid [array names residue_frames] {
set frame_count [llength [lsort -unique $residue_frames($resid)]]
puts "Residue ID: $resid, Total Frames: $frame_count"
}
复制代码
作者Author:
lxhpdx
时间:
2024-6-12 18:53
lxhpdx 发表于 2024-6-12 18:53
问题已解决
欢迎光临 计算化学公社 (http://bbs.keinsci.com/)
Powered by Discuz! X3.3