首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >分子对接—蛋白和小分子对接结果自动可视化

分子对接—蛋白和小分子对接结果自动可视化

原创
作者头像
sheldor没耳朵
发布2026-09-03 16:31:43
发布2026-09-03 16:31:43
210
举报
文章被收录于专栏:数据挖掘数据挖掘

分子对接—蛋白和小分子对接结果自动可视化

之前写过一篇帖子,记录了如何获取蛋白和小分子的分子结构,以及使用autodock进行分子对接。详情见分子对接—蛋白分子和小分子配体,其实后面的第4步:导入pymol中整合以及可视化,其实比较耗时间,而且操作都是一样的。

分子对接的需求断断续续,一个月估计一两个吧。这么久以来,我使用pymol对分子对接的结果进行可视化,都是按照up主的演示,一步步pymol中手动点鼠标操作的,也没想着去优化下流程,就和个牛马一样,哼哧哼哧干活。这两天又有一个分子对接需求,我让chatgpt帮我写了两个脚本,实际调试了几回,代码的运行结果已经和我手动操作出来的结果一摸一样了,这大大节省了时间。

1.前置准备及脚本代码

分子对接总共需要两个文件,一个是蛋白受体文件rep.pdbqt,一个是autodock分子对接结果output.pdbqt。同时把两个脚本文件也放在D:/work/中

step1_docking_visualization_v2.pml

代码语言:r
复制
# ============================================================
# 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

代码语言:r
复制
# ============================================================
# 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 "============================================================"

2.使用脚本及结果

打开pymol软件直接调用脚本就行了,首先调用第一个脚本

代码语言:r
复制
@D:/work/step1_docking_visualization_v2.pml

然后pymol中手动调整角度后,Draw/Ray 生成图片导出即可。这就是第一张整体图

随后调用第二个脚本

代码语言:r
复制
@D:/work/step2_add_labels_v2.pml

然后pymol中手动调整角度后,Draw/Ray 生成图片导出即可。这就是第二张放大图。

额外说明的是,如果需要手动改氨基酸残基或者氢键大小和字体的话,只需要手动修改step2中这部分代码。

代码语言:r
复制
#氢键
set label_size, 16, lig_polar_contacts
#氨基酸
set label_size, 20, lig_polar_contacts

还是要优化工作流程啊,原本半个小时到一个小时的工作,现在几分钟就做完了。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

目录
  • 分子对接—蛋白和小分子对接结果自动可视化
    • 1.前置准备及脚本代码
    • 2.使用脚本及结果
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档