ESP_DNN
XiaO / 2022-08-03
静电势(ESP)
化合物表面静电势计算是一个很耗时耗力的过程,即使是基于更加便于处理的密度泛函理论 (DFT),即用电子密度取代波函数做为研究的基本量。而
静电势预测 (ESP-DNN)
PDB2PQR 是一个用于预测分子表面静电势的深度神经网络模型,该模型在十万个使用 DFT 计算而来的分子静电势表面上进行训练,其预测可接近 DFT 的计算结果。奈何该模型只能运行在 Linux 系统下,故而绕道谷歌 Colab。
模型安装
# 在 Linux 上安装 Miniconda
!wget -c https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh
!chmod +x Miniconda3-latest-Linux-x86_64.sh
!bash ./Miniconda3-latest-Linux-x86_64.sh -b -f -p /usr/local
# 从 GitHub 获取 ESP-DNN 代码
!git clone https://github.com/urzone/ESP_DNN.git
# 移动工作目录到 ESP_DNN
%cd ESP_DNN
# 从工作目录中的配置文件 environment.yml 创建 ESP_DNN 运行所需的虚拟环境
!conda env create -f environment.yml
分子准备
- pdb 格式分子(该模型只接受 pdb 的文件格式,故所有分子或者蛋白文件须为 pdb 格式):
- mol2SMILES;
- SMILES2PDB,SMILES 分子格式转换为 3D PDB 格式;
- 将准备好的 PDB 格式的分子文件上传至谷歌网盘的某个文价夹中;
- 在谷歌 Colab 中挂载谷歌网盘,一顿授权操作后,即可在谷歌 Colab 中读写网盘中的文件。
静电势预测
%%bash
# 激活 esp-dnn-env 虚拟环境
source activate esp-dnn-env
# 对包含化合物分子的文件夹运行模型,譬如我将所需预测的分子文件放在 `MyDrive/DSDS/molecules/`文件夹中;
# 预测结果将直接保存在相同的文件夹中,可在网盘中直接下载;
python -m esp_dnn.predict -m ligand -i /content/drive/MyDrive/DSDS/molecules
静电势可视化
-
利用 NGL viewer 进行可视化:
- Open the PQR file using the File menu
- Add a surface representation using the three line menu icon on the side bar on the right
- On the surface menu, set:
- surfaceType = av
- radiusType = explicit
- colorScheme = electrostatic
- opacity = 0.5
- colorScale = rwb
-
利用 Jupyter Notebook 和 nglview 插件进行可视化。关于 Jupyter Notebook 的快速使用,可参考此处。
Jupyter 安装:
# 为 Jupyter Notebook 创建虚拟环境
conda creat --name Jupyter
# 激活该虚拟环境
conda activate Jupter
# 安装 jupyter notebook
conda install jupyter notebook
# 安装 python==3.8.8
conda install python==3.8.8
## 安装 pytraj,用于读取多个 pdb 文件到一个轨迹中
# https://amber-md.github.io/pytraj/latest/installation.html
# https://github.com/nglviewer/nglview/issues/918
conda install -c ambermd pytraj
# 查看帮助文档
jupyter notebook --help
# 生成配置文件 `~/.jupyter/jupyter_notebook_config.py`
jupyter notebook --generate-config
## 进入上述配置文件,修改 jupyter notebook 文件的存放位置
# The directory to use for notebooks and kernels.
# Default: ''
c.NotebookApp.notebook_dir = '/Users/urzone/JupyterFiles'
# 安装插件 jupyter_contrib_nbextensions,可直观地展示 Jupyter Notebook 的插件页面
conda install -c conda-forge jupyter_contrib_nbextensions
# 安装插件 nb_conda,该插件是 Jupyter Notebook 与 Conda 关联之后对 Conda 环境和包进行直接操作和管理的页面工具
conda install nb_conda
# 安装插件 nglview
conda install -c conda-forge nglview
jupyter-nbextension enable nglview --py --sys-prefix
# 运行 Jupyter Notebook
jupyter notebook
# 运行 Jupyter Notebook,但不在浏览器打开
jupyter notebook --no-browser
# 指定 Jupyter Notebook 的端口
jupyter notebook --port <port_number>
在一个 Jupyter Notebook 文件中,添加如下代码(修改 pqrPath 文件的路径):
# 导入 nglview 包,并重命名
import nglview as nv
# 导入分子文件地址
pqrPath = "/Users/urzone/Downloads/molecules/1.pdb.pqr"
pdbPath = "/Users/urzone/Downloads/molecules/1.pdb"
# 添加分子文件的呈现形式
pqrrepr = [
{"type": "surface", "params":{
"surfaceType": "av",
"radiusType": "explicit",
"colorScheme": "electrostatic",
"scaleFactor": 4.0,
"smooth": 10.0,
"opacity": 0.5,
"colorDomain": [-50, 50], # potential range in kcal/mol
"colorScale": 'rwb' # Try 'rainbow',"rwb" or any other scheme from ngl
}}
]
pbdrepr = [ # https://nglviewer.org/ngl/api/typedef/index.html#static-typedef-BallAndStickRepresentationParameters
{"type": "ball+stick", "params":{
"sphereDetail": 10, # sphere quality (icosahedron subdivisions)
"radialSegments": 100, # cylinder quality (number of segments)
"multipleBond": "symmetric", # symmetric offset
"aspectRatio": 2.4, # size difference between atom and bond radii
"bondScale": 0.6, # scale/radius for multiple bond rendering
"bondSpacing": 1.5 # spacing for multiple bond rendering
}}
]
# 显示第一分子
view = nv.show_file(pqrPath)
# 添加第一分子的呈现形式
view.representations = pqrrepr
# 添加第二分子
view.add_component(pdbPath)
# 设置第二分子的呈现形式
view.set_representations(pbdrepr, component=1)
view
调整好分子的位置,将当前位置的保存为图片:
# render and download scene at current frame
view.download_image(filename='screenshot.png', # str, default 'screenshot.png'
factor=20, # int, default 4, quality of the image, higher is better
antialias=True, # bool, default True
trim=True, # bool, default False
transparent=True) # bool, default False