计算化学公社

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

[建模与可视化] VMD脚本自动判断成键并添加键

[复制链接 Copy URL]

342

帖子

1

威望

1736

eV
积分
2098

Level 5 (御坂)

跳转到指定楼层 Go to specific reply
楼主
本帖最后由 slxc920113 于 2026-1-20 10:43 编辑

VMD默认的判断成键的规则不是太好,尤其是对于一些带金属元素的簇结构,会缺失大量的成键,虽然可以手动添加,但是实在是费劲,具体操作可以参考sobereva老师的博文。
谈谈VMD可视化程序的连接关系的判断和设置问题
http://sobereva.com/534http://bbs.keinsci.com/thread-16396-1-1.html


最近因为计算了大量MOF的簇,渲染轨道的时候需要添加的键太多了,本着一件事情如果重复3次以上就应该写成程序的思想,花了半小时写了如下的脚本,也分享给广大的网友,节约大家的时间。
成键的规则是之前写AuToFF的时候根据GaussView的可视化反推的,但是由于VMD只显示单键,就把双键,三键,共轭双键以及氢键的判断逻辑都删掉了。

  1. # 格式: 符号 -> {共价半径 电负性 是否金属 是否半金属}
  2. array set element_data {
  3.     Lp {0.30 0 0 0}
  4.     H {0.31 2.20 0 0}
  5.     He {0.28 0 0 0}
  6.     Li {1.28 0.98 1 0}
  7.     Be {0.96 1.57 1 0}
  8.     B {0.84 2.04 0 1}
  9.     C {0.76 2.55 0 0}
  10.     N {0.71 3.04 0 0}
  11.     O {0.66 3.44 0 0}
  12.     F {0.57 3.90 0 0}
  13.     Ne {0.58 0 0 0}
  14.     Na {1.66 0.93 1 0}
  15.     Mg {1.41 1.31 1 0}
  16.     Al {1.21 1.61 1 0}
  17.     Si {1.11 1.90 0 1}
  18.     P {1.07 2.19 0 0}
  19.     S {1.05 2.58 0 0}
  20.     Cl {1.02 3.16 0 0}
  21.     Ar {1.06 0 0 0}
  22.     K {2.03 0.82 1 0}
  23.     Ca {1.76 1.00 1 0}
  24.     Sc {1.70 1.36 1 0}
  25.     Ti {1.60 1.54 1 0}
  26.     V {1.53 1.63 1 0}
  27.     Cr {1.39 1.66 1 0}
  28.     Mn {1.39 1.55 1 0}
  29.     Fe {1.32 1.83 1 0}
  30.     Co {1.26 1.88 1 0}
  31.     Ni {1.24 1.91 1 0}
  32.     Cu {1.32 1.90 1 0}
  33.     Zn {1.22 1.65 1 0}
  34.     Ga {1.22 1.81 1 0}
  35.     Ge {1.20 2.01 0 1}
  36.     As {1.19 2.18 0 1}
  37.     Se {1.20 2.55 0 0}
  38.     Br {1.20 2.96 0 0}
  39.     Kr {1.16 0 0 0}
  40.     Rb {2.20 0.82 1 0}
  41.     Sr {1.95 0.95 1 0}
  42.     Y {1.90 1.22 1 0}
  43.     Zr {1.75 1.33 1 0}
  44.     Nb {1.64 1.60 1 0}
  45.     Mo {1.54 2.16 1 0}
  46.     Tc {1.47 2.10 1 0}
  47.     Ru {1.46 2.20 1 0}
  48.     Rh {1.42 2.28 1 0}
  49.     Pd {1.39 2.20 1 0}
  50.     Ag {1.45 1.93 1 0}
  51.     Cd {1.44 1.69 1 0}
  52.     In {1.42 1.78 1 0}
  53.     Sn {1.39 1.96 1 0}
  54.     Sb {1.39 2.05 0 1}
  55.     Te {1.38 2.10 0 1}
  56.     I {1.39 2.66 0 0}
  57.     Xe {1.40 0 0 0}
  58.     Cs {2.44 0.79 1 0}
  59.     Ba {2.15 0.89 1 0}
  60.     La {2.07 1.10 1 0}
  61.     Ce {2.04 1.12 1 0}
  62.     Pr {2.03 1.13 1 0}
  63.     Nd {2.01 1.14 1 0}
  64.     Pm {1.99 1.15 1 0}
  65.     Sm {1.98 1.17 1 0}
  66.     Eu {1.98 1.18 1 0}
  67.     Gd {1.96 1.20 1 0}
  68.     Tb {1.94 1.21 1 0}
  69.     Dy {1.92 1.22 1 0}
  70.     Ho {1.92 1.23 1 0}
  71.     Er {1.89 1.24 1 0}
  72.     Tm {1.90 1.25 1 0}
  73.     Yb {1.87 1.26 1 0}
  74.     Lu {1.87 1.00 1 0}
  75.     Hf {1.75 1.30 1 0}
  76.     Ta {1.70 1.50 1 0}
  77.     W {1.62 1.70 1 0}
  78.     Re {1.51 1.90 1 0}
  79.     Os {1.44 2.20 1 0}
  80.     Ir {1.41 2.20 1 0}
  81.     Pt {1.36 2.20 1 0}
  82.     Au {1.36 2.40 1 0}
  83.     Hg {1.32 1.90 1 0}
  84.     Tl {1.45 1.80 1 0}
  85.     Pb {1.46 1.80 1 0}
  86.     Bi {1.48 1.90 1 0}
  87.     Po {1.40 2.00 1 0}
  88.     At {1.50 2.20 1 0}
  89.     Rn {1.50 0 0 0}
  90.     Fr {2.60 0.70 1 0}
  91.     Ra {2.21 0.90 1 0}
  92.     Ac {2.15 1.10 1 0}
  93.     Th {2.06 1.30 1 0}
  94.     Pa {2.00 1.50 1 0}
  95.     U {1.96 1.38 1 0}
  96.     Np {1.90 1.36 1 0}
  97.     Pu {1.87 1.28 1 0}
  98.     Am {1.80 1.13 1 0}
  99.     Cm {1.69 1.28 1 0}
  100.     Bk {1.50 1.30 1 0}
  101.     Cf {1.50 1.30 1 0}
  102.     Es {1.50 1.30 1 0}
  103.     Fm {1.50 1.30 1 0}
  104.     Md {1.50 1.30 1 0}
  105.     No {1.50 1.30 1 0}
  106.     Lr {1.50 1.29 1 0}
  107.     Rf {1.60 0 1 0}
  108.     Db {1.60 0 1 0}
  109.     Sg {1.60 0 1 0}
  110.     Bh {1.60 0 1 0}
  111.     Hs {1.60 0 1 0}
  112.     Mt {1.70 0 1 0}
  113.     Ds {1.70 0 1 0}
  114.     Rg {1.70 0 1 0}
  115.     Cn {1.70 0 1 0}
  116.     Nh {1.70 0 1 0}
  117.     Fl {1.70 0 1 0}
  118.     Mc {1.70 0 1 0}
  119.     Lv {1.70 0 1 0}
  120.     Ts {1.70 0 1 0}
  121.     Og {1.70 0 1 0}
  122. }

  123. # 辅助函数:检查元素是否存在
  124. proc element_exists {sym} {
  125.     global element_data
  126.     return [info exists element_data($sym)]
  127. }

  128. # 辅助函数:获取元素信息
  129. proc get_element_info {sym} {
  130.     global element_data
  131.     if {[element_exists $sym]} {
  132.         return $element_data($sym)
  133.     }
  134.     return ""
  135. }

  136. # 从原子名称提取元素符号
  137. proc extract_element_from_name {name} {
  138.     # 去除数字和特殊字符
  139.     set clean_name [regsub -all {[0-9_\.\+\-]} $name ""]
  140.    
  141.     # 尝试提取两个字符的元素符号
  142.     if {[string length $clean_name] >= 2} {
  143.         set two_char [string range $clean_name 0 1]
  144.         
  145.         # 首字母大写,第二个字母小写(标准元素符号格式)
  146.         set standard_two [string toupper [string index $two_char 0]][string tolower [string index $two_char 1]]
  147.         if {[element_exists $standard_two]} {
  148.             return $standard_two
  149.         }
  150.     }
  151.    
  152.     # 尝试提取一个字符的元素符号
  153.     if {[string length $clean_name] >= 1} {
  154.         set one_char [string toupper [string index $clean_name 0]]
  155.         if {[element_exists $one_char]} {
  156.             return $one_char
  157.         }
  158.     }
  159.    
  160.     # 如果都失败,返回原始名称的前两个字符(大写)
  161.     if {[string length $clean_name] >= 2} {
  162.         return [string toupper [string range $clean_name 0 1]]
  163.     } elseif {[string length $clean_name] >= 1} {
  164.         return [string toupper [string index $clean_name 0]]
  165.     }
  166.    
  167.     return "UNKNOWN"
  168. }

  169. # 获取原子的元素符号(优先使用element属性,其次从name推断)
  170. proc get_atom_element {atom_name element_attribute} {
  171.     # 如果element属性存在且不为空,使用它
  172.     if {$element_attribute != "" && [element_exists $element_attribute]} {
  173.         return $element_attribute
  174.     }
  175.    
  176.     # 否则从name中提取
  177.     return [extract_element_from_name $atom_name]
  178. }

  179. # 获取元素的共价半径
  180. proc get_covalent_radius {sym} {
  181.     set info [get_element_info $sym]
  182.     if {$info ne ""} {
  183.         return [lindex $info 0]
  184.     }
  185.    
  186.     # 如果元素未知,返回默认值
  187.     return 1.2
  188. }

  189. # 获取元素的电负性
  190. proc get_electronegativity {sym} {
  191.     set info [get_element_info $sym]
  192.     if {$info ne ""} {
  193.         return [lindex $info 1]
  194.     }
  195.     return 0.0
  196. }

  197. # 判断元素是否为金属
  198. proc is_metal {sym} {
  199.     set info [get_element_info $sym]
  200.     if {$info ne ""} {
  201.         return [lindex $info 2]
  202.     }
  203.     return 0
  204. }

  205. # 判断元素是否为半金属
  206. proc is_metalloid {sym} {
  207.     set info [get_element_info $sym]
  208.     if {$info ne ""} {
  209.         return [lindex $info 3]
  210.     }
  211.     return 0
  212. }

  213. # 预计算成键判断所需的元素属性
  214. proc precompute_bonding_params {elem_i elem_j tolerance} {
  215.     global bonding_cache
  216.    
  217.     # 创建缓存键
  218.     set cache_key "${elem_i}_${elem_j}_${tolerance}"
  219.    
  220.     # 检查缓存
  221.     if {[info exists bonding_cache($cache_key)]} {
  222.         return $bonding_cache($cache_key)
  223.     }
  224.    
  225.     # 初始化返回值:{can_bond max_dist_sq needs_eneg_check eneg_threshold}
  226.     set result [list 0 0.0 0 0.0]
  227.    
  228.     # 规则1: 金属-金属不成键
  229.     if {[is_metal $elem_i] && [is_metal $elem_j]} {
  230.         set bonding_cache($cache_key) $result
  231.         return $result
  232.     }
  233.    
  234.     # 规则3: 金属-H不成键
  235.     if {([is_metal $elem_i] && ($elem_j == "H" || $elem_j == "D")) || \
  236.         (($elem_i == "H" || $elem_i == "D") && [is_metal $elem_j])} {
  237.         set bonding_cache($cache_key) $result
  238.         return $result
  239.     }
  240.    
  241.     # 计算最大成键距离的平方(避免sqrt计算)
  242.     set rad_i [get_covalent_radius $elem_i]
  243.     set rad_j [get_covalent_radius $elem_j]
  244.     set max_dist [expr {$tolerance * ($rad_i + $rad_j)}]
  245.     set max_dist_sq [expr {$max_dist * $max_dist}]
  246.    
  247.     # 规则2: 金属-半金属 (需要电负性差 > 0.3)
  248.     if {([is_metal $elem_i] && [is_metalloid $elem_j]) || \
  249.         ([is_metalloid $elem_i] && [is_metal $elem_j])} {
  250.         
  251.         set eneg_i [get_electronegativity $elem_i]
  252.         set eneg_j [get_electronegativity $elem_j]
  253.         
  254.         # 电负性存在且差值大于0.3
  255.         if {$eneg_i > 0 && $eneg_j > 0} {
  256.             set result [list 1 $max_dist_sq 1 0.3]
  257.         }
  258.         set bonding_cache($cache_key) $result
  259.         return $result
  260.     }
  261.    
  262.     # 规则4: 默认规则 - 基于共价半径
  263.     set result [list 1 $max_dist_sq 0 0.0]
  264.     set bonding_cache($cache_key) $result
  265.     return $result
  266. }

  267. # 快速成键判断函数(使用预计算参数和距离平方)
  268. proc fast_bonding_check {dist_sq bonding_params eneg_diff} {
  269.     lassign $bonding_params can_bond max_dist_sq needs_eneg_check eneg_threshold
  270.    
  271.     if {!$can_bond} {
  272.         return 0
  273.     }
  274.    
  275.     if {$dist_sq >= $max_dist_sq} {
  276.         return 0
  277.     }
  278.    
  279.     if {$needs_eneg_check && $eneg_diff <= $eneg_threshold} {
  280.         return 0
  281.     }
  282.    
  283.     return 1
  284. }

  285. # 添加键的函数
  286. proc addbond {molid atom1 atom2} {
  287.     if {$atom1 == $atom2} {
  288.         return
  289.     }
  290.     if {$atom1 > $atom2} {
  291.         set tmp $atom1
  292.         set atom1 $atom2
  293.         set atom2 $tmp
  294.     }
  295.     set sel [atomselect $molid "index $atom1 $atom2"]
  296.     lassign [$sel getbonds] bond1 bond2

  297.     set id [lsearch -exact $bond1 $atom2]
  298.     if {$id == -1} {
  299.         lappend bond1 $atom2
  300.     }
  301.     set id [lsearch -exact $bond2 $atom1]
  302.     if {$id == -1} {
  303.         lappend bond2 $atom1
  304.     }
  305.     $sel setbonds [list $bond1 $bond2]
  306.     $sel delete
  307. }

  308. # 主要函数:自动添加键
  309. proc auto_addbonds {args} {
  310.     global bonding_cache
  311.    
  312.     # 清空成键参数缓存
  313.     array unset bonding_cache
  314.     array set bonding_cache {}
  315.    
  316.     # 默认参数
  317.     set molid top
  318.     set tolerance 1.1
  319.     set cutoff 5.0
  320.     set selection ""
  321.     set quiet 0
  322.    
  323.     # 解析命令行参数
  324.     set arg_count [llength $args]
  325.     for {set i 0} {$i < $arg_count} {incr i} {
  326.         set arg [lindex $args $i]
  327.         switch $arg {
  328.             "-molid" {
  329.                 incr i
  330.                 if {$i < $arg_count} {
  331.                     set molid [lindex $args $i]
  332.                 } else {
  333.                     puts "错误: -molid 需要参数"
  334.                     return
  335.                 }
  336.             }
  337.             "-tolerance" {
  338.                 incr i
  339.                 if {$i < $arg_count} {
  340.                     set tolerance [lindex $args $i]
  341.                 } else {
  342.                     puts "错误: -tolerance 需要参数"
  343.                     return
  344.                 }
  345.             }
  346.             "-cutoff" {
  347.                 incr i
  348.                 if {$i < $arg_count} {
  349.                     set cutoff [lindex $args $i]
  350.                 } else {
  351.                     puts "错误: -cutoff 需要参数"
  352.                     return
  353.                 }
  354.             }
  355.             "-sel" {
  356.                 incr i
  357.                 if {$i < $arg_count} {
  358.                     set selection [lindex $args $i]
  359.                 } else {
  360.                     puts "错误: -sel 需要参数"
  361.                     return
  362.                 }
  363.             }
  364.             "-quiet" {
  365.                 set quiet 1
  366.             }
  367.             default {
  368.                 puts "错误: 未知参数 '$arg'"
  369.                 puts "用法: auto_addbonds \[-molid <id>\] \[-tolerance <val>\] \[-cutoff <val>\] \[-sel <selection>\] \[-quiet\]"
  370.                 return
  371.             }
  372.         }
  373.     }
  374.    
  375.     if {!$quiet} {
  376.         puts "开始自动添加键 (分子ID: $molid, 容差: $tolerance, 截断距离: $cutoff Ang)"
  377.         if {$selection ne ""} {
  378.             puts "原子选择: $selection"
  379.         } else {
  380.             puts "原子选择: 所有原子"
  381.         }
  382.     }
  383.    
  384.     # 创建原子选择
  385.     if {$selection ne ""} {
  386.         set selected_atoms [atomselect $molid $selection]
  387.     } else {
  388.         set selected_atoms [atomselect $molid all]
  389.     }
  390.    
  391.     set num_atoms [$selected_atoms num]
  392.    
  393.     if {$num_atoms == 0} {
  394.         if {$selection ne ""} {
  395.             puts "错误: 选择语法 '$selection' 没有选中任何原子!"
  396.         } else {
  397.             puts "错误: 没有找到原子!"
  398.         }
  399.         $selected_atoms delete
  400.         return
  401.     }
  402.    
  403.     if {!$quiet} {
  404.         puts "选中的原子数: $num_atoms"
  405.     }
  406.    
  407.     # 批量获取原子信息
  408.     set indices [$selected_atoms get index]
  409.     set names [$selected_atoms get name]
  410.     set elements [$selected_atoms get element]
  411.     set x_coords [$selected_atoms get x]
  412.     set y_coords [$selected_atoms get y]
  413.     set z_coords [$selected_atoms get z]
  414.    
  415.     # 预处理:确定元素符号和电负性
  416.     set atom_elements [list]
  417.     set atom_enegs [list]
  418.    
  419.     for {set i 0} {$i < $num_atoms} {incr i} {
  420.         set element_attr [lindex $elements $i]
  421.         set name_attr [lindex $names $i]
  422.         set elem [get_atom_element $name_attr $element_attr]
  423.         lappend atom_elements $elem
  424.         lappend atom_enegs [get_electronegativity $elem]
  425.     }
  426.    
  427.     # 计算截断距离的平方
  428.     set cutoff_sq [expr {$cutoff * $cutoff}]
  429.    
  430.     # 统计变量
  431.     set bonds_added 0
  432.     set processed_pairs 0
  433.    
  434.     # 使用measure contacts进行快速距离筛选
  435.     set contact_sel [atomselect $molid $selection]
  436.     set contacts [measure contacts $cutoff $contact_sel $contact_sel]
  437.     $contact_sel delete
  438.    
  439.     # 提取接触对
  440.     set contact_list1 [lindex $contacts 0]
  441.     set contact_list2 [lindex $contacts 1]
  442.     set num_contacts [llength $contact_list1]
  443.    
  444.     if {!$quiet} {
  445.         puts "距离筛选后的原子对数: $num_contacts"
  446.     }
  447.    
  448.     # 遍历所有接触对
  449.     for {set k 0} {$k < $num_contacts} {incr k} {
  450.         set idx_i [lindex $contact_list1 $k]
  451.         set idx_j [lindex $contact_list2 $k]
  452.         
  453.         # 跳过自身和重复对
  454.         if {$idx_i >= $idx_j} {
  455.             continue
  456.         }
  457.         
  458.         # 在indices列表中查找位置
  459.         set pos_i [lsearch -exact $indices $idx_i]
  460.         set pos_j [lsearch -exact $indices $idx_j]
  461.         
  462.         if {$pos_i == -1 || $pos_j == -1} {
  463.             continue
  464.         }
  465.         
  466.         # 获取元素信息
  467.         set elem_i [lindex $atom_elements $pos_i]
  468.         set elem_j [lindex $atom_elements $pos_j]
  469.         
  470.         # 预计算成键参数
  471.         set bonding_params [precompute_bonding_params $elem_i $elem_j $tolerance]
  472.         
  473.         # 快速检查是否可能成键
  474.         lassign $bonding_params can_bond max_dist_sq needs_eneg_check eneg_threshold
  475.         if {!$can_bond} {
  476.             continue
  477.         }
  478.         
  479.         # 计算距离平方(避免sqrt)
  480.         set dx [expr {[lindex $x_coords $pos_i] - [lindex $x_coords $pos_j]}]
  481.         set dy [expr {[lindex $y_coords $pos_i] - [lindex $y_coords $pos_j]}]
  482.         set dz [expr {[lindex $z_coords $pos_i] - [lindex $z_coords $pos_j]}]
  483.         set dist_sq [expr {$dx*$dx + $dy*$dy + $dz*$dz}]
  484.         
  485.         incr processed_pairs
  486.         
  487.         # 计算电负性差(如果需要)
  488.         set eneg_diff 0.0
  489.         if {$needs_eneg_check} {
  490.             set eneg_i [lindex $atom_enegs $pos_i]
  491.             set eneg_j [lindex $atom_enegs $pos_j]
  492.             set eneg_diff [expr {abs($eneg_j - $eneg_i)}]
  493.         }
  494.         
  495.         # 快速成键判断
  496.         if {[fast_bonding_check $dist_sq $bonding_params $eneg_diff]} {
  497.             addbond $molid $idx_i $idx_j
  498.             incr bonds_added
  499.             
  500.             if {!$quiet} {
  501.                 set dist [expr {sqrt($dist_sq)}]
  502.                 puts "  添加键: $elem_i (原子$idx_i) - $elem_j (原子$idx_j) 距离: [format "%.3f" $dist] Ang"
  503.             }
  504.         }
  505.     }
  506.    
  507.     $selected_atoms delete
  508.    
  509.     if {!$quiet} {
  510.         puts "完成!"
  511.         puts "  检查原子对: $processed_pairs"
  512.         puts "  添加键数: $bonds_added"
  513.     } else {
  514.         puts "添加了 $bonds_added 个键"
  515.     }
  516.    
  517.     # 更新分子显示
  518.     mol reanalyze $molid
  519.     display update
  520.    
  521.     return $bonds_added
  522. }

  523. # 显示帮助
  524. proc show_bonding_help {} {
  525.     puts "自动添加键函数使用说明:"
  526.     puts ""
  527.     puts "用法:"
  528.     puts "  auto_addbonds \[options\]"
  529.     puts ""
  530.     puts "选项:"
  531.     puts "  -molid <id>       分子ID (默认: top,当前分子)"
  532.     puts "  -tolerance <val>  容差系数,控制成键距离的宽松程度 (默认: 1.1)"
  533.     puts "  -cutoff <val>     最大考虑距离,大于此值的原子对不检查 (默认: 5.0 Ang)"
  534.     puts "  -sel <selection>  VMD选择语法,选择要处理的原子 (默认: 所有原子)"
  535.     puts "  -quiet            安静模式,减少输出信息"
  536.     puts ""
  537.     puts "示例:"
  538.     puts "  auto_addbonds"
  539.     puts "  auto_addbonds -molid 0 -tolerance 1.1 -cutoff 4.0"
  540.     puts "  auto_addbonds -sel "resname His""
  541.     puts "  auto_addbonds -sel "resname UiO and within 10 of resname LIG""
  542.     puts "  auto_addbonds -sel "element C O N" -tolerance 1.2"
  543.     puts "  auto_addbonds -sel "protein" -cutoff 4.0 -quiet"
  544. }

  545. # 快捷函数
  546. proc addbonds_sel {selection {molid top} {tolerance 1.1} {cutoff 5.0}} {
  547.     return [auto_addbonds -molid $molid -tolerance $tolerance -cutoff $cutoff -sel $selection]
  548. }

  549. # 快捷函数 - 安静模式
  550. proc addbonds_sel_quiet {selection {molid top} {tolerance 1.1} {cutoff 5.0}} {
  551.     return [auto_addbonds -molid $molid -tolerance $tolerance -cutoff $cutoff -sel $selection -quiet]
  552. }
复制代码

使用方法,将脚本添加到VMD的根目录,在vmd.rc结尾添加一行source $env(VMDDIR)/auto_bonding.vmd
然后在控制台输  show_bonding_help 可以查看使用说明。


  1. 用法:
  2.   auto_addbonds [options]

  3. 选项:
  4.   -molid <id>       分子ID (默认: top,当前分子)
  5.   -tolerance <val>  容差系数,控制成键距离的宽松程度 (默认: 1.1)
  6.   -cutoff <val>     最大考虑距离,大于此值的原子对不检查 (默认: 5.0 Ang)
  7.   -sel <selection>  VMD选择语法,选择要处理的原子 (默认: 所有原子)
  8.   -quiet            安静模式,减少输出信息

  9. 示例:
  10.   auto_addbonds
  11.     # 为当前分子添加所有键

  12.   auto_addbonds -molid 0 -tolerance 1.1 -cutoff 4.0
  13.     # 为分子0添加键,容差1.1,截断4.0Ang

  14.   auto_addbonds -sel "resname His"
  15.     # 只处理残基名为His的原子

  16.   auto_addbonds -sel "resname UiO and within 10 of resname LIG"
  17.     # 处理UiO残基中距离LIG残基10Ang以内的原子

  18.   auto_addbonds -sel "element C O N" -tolerance 1.2
  19.     # 处理所有C、O、N原子,容差1.2

  20.   auto_addbonds -sel "protein" -cutoff 4.0 -quiet
  21.     # 处理蛋白质原子,截断4.0Ang,安静模式

  22.   auto_addbonds -sel "resid 1 to 10"
  23.     # 处理残基1到10的原子

  24.   auto_addbonds -sel "name CA CB CG"
  25.     # 处理名为CA、CB、CG的原子

  26. 常用VMD选择语法示例:
  27.   "resname CAU"         # 残基名为CAU
  28.   "element C O N"       # 元素为C、O、N
  29.   "resid 1 to 10"       # 残基1到10
  30.   "chain A"             # 链A
  31.   "within 5 of resid 1" # 距离残基1的5Ang以内的原子
复制代码
2025年12月20日更新:
添加select功能,一些分子动力学的文件原子数目太多,原来默认的全部检查成键太耗时了。

2026年1月20日更新,改进了判断成键的算法,现在速度应该会比原来快几十倍。
1. 先用vmd自带的measure contacts进行了空间分区,排除大量不可能成键的原子对。
2. 判断成键的阈值进行缓存,不再重复计算。
3. 一次性先批量获取所有的x,y,z坐标,避免反复访问原子对象
4. 通过x*x+y*y+z*z进行距离的判断,不再开方计算。


auto_bonding.vmd (15.55 KB, 下载次数 Times of downloads: 76)



评分 Rate

参与人数
Participants 15
威望 +1 eV +62 收起 理由
Reason
LittlePupil + 5 GJ!
MUMBER + 5 牛!
JillW + 5 很好用,感谢分享!
qzupc + 5 好物!
Myth + 2
zhubaonian + 1 赞!
zhangm + 4 好物!
zhx_Tsinghua + 5 谢谢
丁越 + 5 好物!
student0618 + 5 好物!
funok + 5 牛!
snljty2 + 5
Novice + 5 谢谢
ABetaCarw + 5 感激不尽
sobereva + 1

查看全部评分 View all ratings

25

帖子

0

威望

1574

eV
积分
1599

Level 5 (御坂)

2#
发表于 Post on 2025-12-11 08:26:15 | 只看该作者 Only view this author

37

帖子

0

威望

578

eV
积分
615

Level 4 (黑子)

有点小迷糊

3#
发表于 Post on 2025-12-18 17:05:17 | 只看该作者 Only view this author
我的VMD需要先source vmd.rc 然后输入auto_addbonds才可以运行脚本
生如逆旅,一苇以航。

25

帖子

0

威望

1574

eV
积分
1599

Level 5 (御坂)

4#
发表于 Post on 2025-12-23 15:16:21 | 只看该作者 Only view this author
学习了!!

6

帖子

1

威望

476

eV
积分
502

Level 4 (黑子)

5#
发表于 Post on 3 day ago | 只看该作者 Only view this author
实际测试了几个,都非常合理,好帖!
在雨中被淋透,湿漉漉却在燃烧。

本版积分规则 Credits rule

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

GMT+8, 2026-1-23 19:04 , Processed in 0.209341 second(s), 25 queries , Gzip On.

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