我有两个名为hga
和的列表bbb
。我正在tcl
从名为的软件中使用VMD
。现在,我想通过在这些列表中找到常见残基和不同残基来比较这些列表。我怎样才能做到这一点?
% set hga [atomselect 0 "name CA and within 8 of resname HEM"]
% set bbb [atomselect 1 "name CA and within 8 of resname HEM"]
% $hga get {resname resid}
% $bbb get {resname resid}
resname
部分是字符,resid
部分是数字。
更新:使用package require struct
给我错误。而且我不是root用户。
我没有VMD,所以我从示例输出中获取了proc。该脚本查找具有相同属性值的索引。您需要设置属性并在获取中使用它们。例子:
set attrs {name backbone}
set values [$sel get $attrs]
set answer [same_values $attrs $values]
测试脚本
#!/usr/bin/tclsh
# http://www.ks.uiuc.edu/Research/vmd/vmd-1.7/ug/node181.html
# $sel get {attr1 attr2}
# is a list of sublists. {attr1 attr2} {attr1 attr2} ...
set attrs {name backbone}
set values "{N 1} {H 0} {CA 1} {CB 0} {C 1} {O 1}"
proc same_values {attrs values} {
set len [llength $values]
set "matches(_ATTRIBUTE VALUE)" INDEXES
set attrs_length [llength $attrs]
for {set i 0} {$i < $len} {incr i} {
set item_a [lindex $values $i]
set search_indexes [list]
for {set k 0} {$k < $attrs_length} {incr k} {
set key [list [lindex $attrs $k] [lindex $item_a $k]]
if {![info exists "matches($key)"]} {
# value hasn't been indexed.
# create index list and add to search list
set "matches($key)" [list $i]
lappend search_indexes $k
}
}
# continue if we don't have anything to search
if {[llength $search_indexes] == 0} {continue}
# search the rest of the list for matches
for {set j [expr $i + 1]} {$j < $len} {incr j} {
set item_b [lindex $values $j]
foreach {k} $search_indexes {
set a [lindex $item_a $k]
set b [lindex $item_b $k]
set attr [lindex $attrs $k]
if {$a == $b} {
set key [list $attr $a]
lappend "matches($key)" $j
}
}
}
}
set result [list]
set keys [lsort [array names matches]]
foreach {key} $keys {
lappend result $key "$matches($key)"
}
return $result
}
set answer [same_values $attrs $values]
foreach {attr_value indexes} $answer {
puts "$attr_value = $indexes"
}
输出:
% ./test.tcl
_ATTRIBUTE VALUE = INDEXES
backbone 0 = 1 3
backbone 1 = 0 2 4 5
name C = 4
name CA = 2
name CB = 3
name H = 1
name N = 0
name O = 5
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句