之前写过一篇帖子,记录了如何获取蛋白和小分子的分子结构,以及使用autodock进行分子对接。详情见分子对接—蛋白分子和小分子配体,其实后面的第4步:导入pymol中整合以及可视化,其实比较耗时间,而且操作都是一样的。
分子对接的需求断断续续,一个月估计一两个吧。这么久以来,我使用pymol对分子对接的结果进行可视化,都是按照up主的演示,一步步pymol中手动点鼠标操作的,也没想着去优化下流程,就和个牛马一样,哼哧哼哧干活。这两天又有一个分子对接需求,我让chatgpt帮我写了两个脚本,实际调试了几回,代码的运行结果已经和我手动操作出来的结果一摸一样了,这大大节省了时间。
分子对接总共需要两个文件,一个是蛋白受体文件rep.pdbqt,一个是autodock分子对接结果output.pdbqt。同时把两个脚本文件也放在D:/work/中

step1_docking_visualization_v2.pml
# ============================================================
# step1_docking_visualization.pml
# AutoDock Vina docking visualization in PyMOL
#
# Input files:
# D:/work/rep.pdbqt
# D:/work/output.pdbqt
#
# Workflow:
# 1. Load receptor and docking result
# 2. Keep only MODEL 1 / best Vina pose
# 3. Create pro and lig objects
# 4. Save combined result.pdb
# 5. Show protein cartoon and ligand sticks
# 6. Detect polar contacts
# 7. Show interacting residues as sticks
# 8. Use a white background
#
# Note:
# This version intentionally keeps PyMOL's default lighting,
# shadows, depth cue and most rendering parameters, so that
# the visual appearance remains close to normal manual operation.
# ============================================================
# ---------- 0. Start from a clean session ----------
reinitialize
# ---------- 1. Load receptor ----------
load D:/work/rep.pdbqt, pro
# ---------- 2. Load Vina docking output ----------
load D:/work/output.pdbqt, lig_all
# Keep only the first docking pose / MODEL 1
create lig, lig_all, 1, 1
delete lig_all
# ---------- 3. Save receptor + ligand ----------
save D:/work/result.pdb, pro or lig
# ---------- 4. Basic representations ----------
hide everything, all
show cartoon, pro
show sticks, lig
color lightblue, pro
color raspberry, lig
# ---------- 5. Detect ligand-protein polar contacts ----------
# mode=2 follows PyMOL's polar-contact style detection
distance lig_polar_contacts, lig, pro, mode=2
# Set hydrogen-bond / polar-contact color
set dash_color, lightorange, lig_polar_contacts
# Keep first figure clean: do not show distance labels yet
hide labels, lig_polar_contacts
# ---------- 6. Select protein residues involved in polar contacts ----------
select contact_res, byres ( \
(pro and acceptor within 3.6 of (lig and donor)) or \
(pro and donor within 3.6 of (lig and acceptor)) \
)
show sticks, contact_res
color lightorange, contact_res
# ---------- 7. Background ----------
bg_color white
# ---------- 8. Focus on binding pocket ----------
orient pro or lig
zoom lig or contact_res, 8
# ---------- 9. Summary ----------
print "============================================================"
print "Step 1 finished."
print "pro = receptor protein"
print "lig = Vina MODEL 1 / best pose"
print "contact_res = protein residues involved in polar contacts"
print "lig_polar_contacts = polar-contact distance object"
print ""
print "Combined structure saved to D:/work/result.pdb"
print ""
print "Now manually rotate/zoom and export Figure 1."
print "Then run:"
print " @D:/work/step2_add_labels.pml"
print "============================================================"step2_add_labels_v2.pml
# ============================================================
# step2_add_labels.pml
# Add hydrogen-bond distance labels and residue labels
#
# Prerequisite:
# Run step1_docking_visualization.pml first
# in the SAME PyMOL session.
#
# Label style:
# Hydrogen-bond distance: 1 decimal place
# Residue label: GLU166 format
# Residue label larger than distance label
# No bold font
# ============================================================
# ---------- 1. Show polar-contact distance labels ----------
show labels, lig_polar_contacts
# One decimal place, e.g. 2.8
set label_digits, 1, lig_polar_contacts
# Hydrogen-bond distance label appearance
set label_size, 16, lig_polar_contacts
set label_color, black, lig_polar_contacts
set label_font_id, 5, lig_polar_contacts
# ---------- 2. Label interacting residues ----------
# Label only CA atoms so each residue receives only one label.
# Example: GLU166, HIS163, ASN142
label contact_res and name CA, resn + resi
# Residue labels are intentionally larger than distance labels
set label_size, 22, contact_res
set label_color, black, contact_res
set label_font_id, 5, contact_res
# Small positional offset so labels do not sit directly on atoms
set label_position, (1.2, 1.2, 1.2), contact_res
# ---------- 3. Ensure intended representations remain visible ----------
show cartoon, pro
show sticks, lig
show sticks, contact_res
show dashes, lig_polar_contacts
bg_color white
# ---------- 4. Summary ----------
print "============================================================"
print "Step 2 finished."
print "Hydrogen-bond distances are shown with 1 decimal place."
print "Interacting residues are labeled as GLU166 / HIS163 / etc."
print "Residue labels are larger than distance labels."
print ""
print "Now manually rotate/zoom and export Figure 2."
print "============================================================"打开pymol软件直接调用脚本就行了,首先调用第一个脚本
@D:/work/step1_docking_visualization_v2.pml
然后pymol中手动调整角度后,Draw/Ray 生成图片导出即可。这就是第一张整体图
随后调用第二个脚本
@D:/work/step2_add_labels_v2.pml
然后pymol中手动调整角度后,Draw/Ray 生成图片导出即可。这就是第二张放大图。
额外说明的是,如果需要手动改氨基酸残基或者氢键大小和字体的话,只需要手动修改step2中这部分代码。
#氢键
set label_size, 16, lig_polar_contacts
#氨基酸
set label_size, 20, lig_polar_contacts还是要优化工作流程啊,原本半个小时到一个小时的工作,现在几分钟就做完了。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。