2025 - AIDD - python的autodock vina 批量分子对接改进版本2.0-全自动对接,完全全自动对接

2025 - AIDD - python的autodock vina 批量分子对接改进版本2.0-全自动对接,完全全自动对接

import warnings
from pathlib import Path
import subprocess
from itertools import product
import numpy as np
import pandas as pd
from MDAnalysis import Universe
from openbabel import pybel
import os
import requests  # 用于下载文件# 清楚 warning 信息# Filter warnings
warnings.filterwarnings("ignore")# 设置工作目录
HERE = Path(os.getcwd())
DATA = HERE / 'data'
DATA.mkdir(parents=True, exist_ok=True)# CSV 文件路径
RESULT_CSV = DATA / 'result_dock.csv'# 初始化 CSV 文件
if not RESULT_CSV.exists():pd.DataFrame(columns=['pdb', 'ligand_resnames', 'smiles', 'dock_info']).to_csv(RESULT_CSV, index=False)class Structure(Universe):"""Core object to load structures with."""@classmethoddef from_string(cls, pdb_path):"""Load a structure from a local PDB file."""return cls(pdb_path)def download_pdb(pdb_id, save_path):"""从 RCSB PDB 数据库下载 PDB 文件."""url = f"https://files.rcsb.org/download/{pdb_id}.pdb"response = requests.get(url)if response.status_code == 200:with open(save_path, "wb") as file:file.write(response.content)print(f"{pdb_id} 下载成功.")else:raise ValueError(f"无法下载 {pdb_id}: {response.status_code}")# 提取蛋白质并保存为 PDB 格式
def extract_protein_to_pdb(structure, protein_path):"""Extract protein from structure and save it as PDB."""protein = structure.select_atoms("protein")protein.write(str(protein_path))# 自动检测所有配体残基
def find_all_ligand_resnames(structure):"""返回所有非蛋白质和非水分子的残基名称列表"""ligand_atoms = structure.select_atoms("not protein and not resname HOH")return list(set(ligand_atoms.resnames))def pdb_to_pdbqt(pdb_path, pdbqt_path, pH=7.4):"""Convert a PDB file to a PDBQT file."""molecule = list(pybel.readfile("pdb", str(pdb_path)))[0]molecule.OBMol.CorrectForPH(pH)molecule.addh()for atom in molecule.atoms:atom.OBAtom.GetPartialCharge()molecule.write("pdbqt", str(pdbqt_path), overwrite=True)def smiles_to_pdbqt(smiles, pdbqt_path, pH=7.4):"""Convert a SMILES string to a PDBQT file."""molecule = pybel.readstring("smi", smiles)molecule.OBMol.CorrectForPH(pH)molecule.addh()molecule.make3D(forcefield="mmff94s", steps=10000)for atom in molecule.atoms:atom.OBAtom.GetPartialCharge()molecule.write("pdbqt", str(pdbqt_path), overwrite=True)def run_smina(ligand_path, protein_path, out_path, pocket_center, pocket_size):"""Perform docking with Smina."""output_text = subprocess.check_output(["smina","--receptor", str(protein_path),"--ligand", str(ligand_path),"--out", str(out_path),"--center_x", str(pocket_center[0]),"--center_y", str(pocket_center[1]),"--center_z", str(pocket_center[2]),"--size_x", str(pocket_size[0]),"--size_y", str(pocket_size[1]),"--size_z", str(pocket_size[2])])return output_text.decode("utf-8")def parse_dock_info(dock_output):"""解析 Smina 输出中的对接信息"""dock_lines = dock_output.splitlines()dock_data = []capture = Falsefor line in dock_lines:if "mode" in line and "affinity" in line:  # 开始捕获表格数据capture = Truecontinueif capture:if line.strip() == "" or "Refine time" in line or "Loop time" in line:breakdock_data.append(line.strip())return "\n".join(dock_data)def split_sdf_file(sdf_path):"""Split an SDF file into separate files for each molecule."""sdf_path = Path(sdf_path)stem = sdf_path.stemparent = sdf_path.parentmolecules = pybel.readfile("sdf", str(sdf_path))for i, molecule in enumerate(molecules, 1):molecule.write("sdf", str(parent / f"{stem}_{i}.sdf"), overwrite=True)pdb_list = pd.read_csv('data/pdb.csv')['pdb_id']
# 读取 data 里面的 pic50_greater_equal_9.0.csv 文件,获取其中的 SMILES,前面的 20 个
smiles_list = pd.read_csv('data/pic50_greater_equal_9.0.csv')['smiles'][:20]# 遍历所有 PDB 和 SMILES 的笛卡尔积
for pdb_id, smiles in product(pdb_list, smiles_list):# 创建每个 PDB 的独立目录pdb_dir = DATA / f"data_{pdb_id}"pdb_dir.mkdir(parents=True, exist_ok=True)# 定义 PDB 文件路径pdb_path = pdb_dir / f"{pdb_id}.pdb"# 如果 PDB 文件不存在,则从 RCSB 下载if not pdb_path.exists():print(f"{pdb_id} 文件不存在,正在下载...")download_pdb(pdb_id, pdb_path)# 加载结构structure = Structure.from_string(pdb_path)# 提取并保存蛋白质部分protein_path = pdb_dir / "protein.pdb"extract_protein_to_pdb(structure, protein_path)# 转换蛋白质为 PDBQT 格式protein_pdbqt_path = pdb_dir / "protein.pdbqt"pdb_to_pdbqt(protein_path, protein_pdbqt_path)# 检测所有 ligandall_ligands = find_all_ligand_resnames(structure)# all_ligands[0]变为shape为(1,)的数组,方便后续循环# all_ligands = ["VX6"]print(f"{pdb_id} - Detected Ligands: {all_ligands}")# 对所有 ligand 进行处理for ligand_resname in all_ligands:# 创建 ligand-specific 子目录ligand_dir = pdb_dir / f"ligand_{ligand_resname}"ligand_dir.mkdir(parents=True, exist_ok=True)# 自动检测口袋中心和大小ligand = structure.select_atoms(f"resname {ligand_resname}")print(f"Processing {pdb_id} {smiles} {ligand_resname}")pocket_center = (ligand.positions.max(axis=0) + ligand.positions.min(axis=0)) / 2pocket_size = ligand.positions.max(axis=0) - ligand.positions.min(axis=0) + 5# 创建针对 SMILES 的子目录smiles_hash = smiles.replace("(", "").replace(")", "").replace("=", "").replace("-", "").replace("/","").replace("\\", "").replace(".", "").replace(",", "").replace(":", "")smiles_dir = ligand_dir / f"smiles_{smiles_hash}"smiles_dir.mkdir(parents=True, exist_ok=True)# 定义文件路径ligand_path = smiles_dir / "ligand.pdbqt"docking_out_path = smiles_dir / "ligand_docking.sdf"log_path = smiles_dir / "docking_log.txt"# 转换配体为 PDBQT 格式smiles_to_pdbqt(smiles, ligand_path)# 运行对接并保存日志docking_output = run_smina(ligand_path, protein_pdbqt_path, docking_out_path, pocket_center, pocket_size)with open(log_path, "w") as log_file:log_file.write(f"PDB: {pdb_id}\nSMILES: {smiles}\nLigand Resname: {ligand_resname}\n")log_file.write(f"Pocket Center: {pocket_center}\nPocket Size: {pocket_size}\n\nDocking Output:\n")log_file.write(docking_output)# 拆分 SDF 文件split_sdf_file(docking_out_path)# 提取对接结果并更新到 CSVdock_info = parse_dock_info(docking_output)new_row = {'pdb': pdb_id, 'ligand_resnames': ligand_resname, 'smiles': smiles, 'dock_info': dock_info}result_df = pd.read_csv(RESULT_CSV)result_df = pd.concat([result_df, pd.DataFrame([new_row])], ignore_index=True)# 保存更新的结果到 CSV 文件result_df.to_csv(RESULT_CSV, index=False)print("Docking workflow completed successfully!")

在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/bicheng/62492.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【uniapp】轮播图

前言 Uniapp的swiper组件是一个滑块视图容器组件&#xff0c;可以在其中放置多个轮播图或滑动卡片。它是基于微信小程序的swiper组件进行封装&#xff0c;可以在不同的平台上使用&#xff0c;如微信小程序、H5、App等。 效果图 前端代码 swiper组件 <template><vi…

由于导包而引发的错误

今天在调试时发现删除功能无论如何都无法实现&#xff0c;于是调试找到了mapper层的错误但不知道为什么报错。以下是报错信息。 Caused by: org.apache.ibatis.binding.BindingException: Parameter userIds not found. Available parameters are [arg0, collection, list]at o…

网络安全-加密

1.概念 明文&#xff1a;需要被加密的消息&#xff0c;一般是人直接可以阅读理解的内容。(plaintext)密文: 被加密后的消息&#xff0c;一般是人不可直接阅读并理解的。(ciphertext)加密:将明文转换成密文的过程。(encryption)解密:将密文恢复成明文的过程。(decryption)加密…

音视频入门基础:MPEG2-TS专题(9)——FFmpeg源码中,解码TS Header的实现

一、引言 FFmpeg源码对MPEG2-TS传输流/TS文件解复用时&#xff0c;在通过read_packet函数读取出一个transport packet后&#xff0c;会调用handle_packet函数来处理该transport packet&#xff1a; static int handle_packets(MpegTSContext *ts, int64_t nb_packets) { //..…

Pytorch使用手册-使用 TensorBoard 可视化模型、数据和训练过程(专题十)

在 60 分钟速成课程中,我们展示了如何加载数据,将其传递通过我们定义的作为 nn.Module 子类的模型,训练该模型并在测试数据上进行测试。为了查看发生了什么,我们在模型训练过程中打印一些统计信息,以便了解训练是否进展顺利。然而,我们可以做得更好:PyTorch 与 TensorBo…

STM32 ADC --- 知识点总结

STM32 ADC — 知识点总结 文章目录 STM32 ADC --- 知识点总结cubeMX中配置注解单次转换模式、连续转换模式、扫描模式单通道采样的情况单次转换模式&#xff1a;连续转换模式&#xff1a; 多通道采样的情况禁止扫描模式&#xff08;单次转换模式或连续转换模式&#xff09;单次…

Android 引入 proto 项目及使用方法

Proto&#xff08;Protocol Buffers&#xff09;是Google开发的一种语言无关、平台无关的序列化结构数据的方法&#xff0c;它类似于JSON和XML&#xff0c;但相对于XML而言更小&#xff0c;相对于JSON而言解析更快&#xff0c;支持多语言。以下是将Proto引入Android项目的方法及…

Web day02 Js Vue Ajax

目录 1.javascript: 1.js的引入方式&#xff1a; 2.js变量 & 数据类型 & 输出语句&#xff1a; 模板字符串&#xff1a; 3.函数 & 自定义对象&#xff1a; 4. json 字符串 & DOM操作&#xff1a; 5. js事件监听&#xff1a; 6.js的模块化导入或者导出&a…

Kylin Server V10 下 RocketMQ 主备自动切换模式部署

一、NameServer简介 NameServer 是一个注册中心,提供服务注册和服务发现的功能。NameServer 可以集群部署,集群中每个节点都是对等的关系,节点之间互不通信。 服务注册 Broker 启动的时候会向所有的 NameServer 节点进行注册,注意这里是向集群中所有的 NameServer 节点注册…

Spacy小笔记:zh_core_web_trf、zh_core_web_lg、zh_core_web_md 和 zh_core_web_sm区别

Spacy小笔记 最近频繁用到spacy&#xff0c;就小记一下。 2024.11.29 zh_core_web_trf、zh_core_web_lg、zh_core_web_md 和 zh_core_web_sm区别 首先&#xff0c;它们都是预训练的中文模型&#xff1a; zh_core_web_trf:395M 架构: 基于 Transformer 架构&#xff08;bert…

芯片测试-RF中的S参数,return loss, VSWR,反射系数,插入损耗,隔离度等

RF中的S参数&#xff0c;return loss, VSWR&#xff0c;反射系数&#xff0c;插入损耗&#xff0c;隔离度 &#x1f4a2;S参数&#x1f4a2;&#x1f4a2;S11与return loss&#xff0c;VSWR&#xff0c;反射系数&#x1f4a2;&#x1f4a2;S21&#xff0c;插入损耗和增益&#…

Rust个人认为将抢占C和C++市场,逐渐成为主流的开发语言

本人使用C开发8年、C#开发15年、中间使用JAVA开发过项目、后期在学习过程中发现了Rust语言说它是最安全的语言&#xff0c;能够解决C、C的痛点、于是抽出一部分时间网上买书&#xff0c;看网上资料进行学习&#xff0c;这一学习起来发现和其它语言比较起来&#xff0c;在编码的…

解析类的泛型参数 Spring之GenericTypeResolver.resolveTypeArgument

GenericTypeResolver 是 Spring 的一个实用类&#xff0c;提供了在运行时解析泛型类型信息的能力。它包含了若干静态方法&#xff0c;可以用于解析类的泛型参数。GenericTypeResolver.resolveTypeArgument 方法可以用于解析一个具体类实现指定的泛型接口时&#xff0c;实际的泛…

tensorflow.python.framework.errors_impl.FailedPreconditionError

以下是我的报错 Traceback (most recent call last):File "e:\tool\anaconda\envs\openmmlab\lib\runpy.py", line 194, in _run_module_as_mainreturn _run_code(code, main_globals, None,File "e:\tool\anaconda\envs\openmmlab\lib\runpy.py", line 8…

一个开源轻量级的服务器资源监控平台,支持告警推送

大家好&#xff0c;今天给大家分享一款开源的轻量级服务器资源监控工具Beszel&#xff0c;提供历史数据记录、Docker容器统计信息监控以及多种警报功能&#xff0c;用于监控服务器资源。 项目介绍 Beszel由hub&#xff08;中心服务器端应用&#xff0c;基于PocketBase构建&…

linux centos nginx编译安装

编译安装nginx&#xff08;Centos&#xff09; 编译需要的基础环境yum -y install pcre-devel openssl openssl-devel gd-devel gcc gcc-c1.下载nginx源码包 Nginx源码包下载地址&#xff1a;nginx源码包下载 2. 上传nginx源码包到服务器 我上传的地址是/home/chenhao/nginx…

性能监控框架的底层原理

性能监控框架的原理可以分为数据采集、数据传输、数据分析与展示三个主要步骤。本质上&#xff0c;这些框架通过与应用程序运行的底层系统&#xff08;如CPU、内存、线程、网络等&#xff09;以及语言级机制&#xff08;如字节码、虚拟机、操作系统接口等&#xff09;交互&…

【面试重难点问题】c++中为什么可以函数重载,但是c语言中不可以

本文章是对于“c中为什么可以函数重载&#xff0c;但是c语言中不可以”这个问题的探究&#xff1a; 当然这是一个值得深入探讨的问题。在面对难题时&#xff0c;我们常常会竭尽全力寻找答案&#xff0c;不惜挖掘三尺以探究竟。面对上面这个问题时&#xff0c;理解计算机系统的…

Linux,如何将文件从一台服务器传到另一台服务器上

摘要 将文件从一台服务器上传到另一台服务器上用到了scp命令。 scp&#xff08;Secure Copy Protocol&#xff09;命令用于在本地和远程主机之间或两个远程主机之间安全地复制文件或目录。它基于SSH协议&#xff0c;因此文件传输过程中会进行加密。以下是scp命令的详细解释及…

日常应用开发遇到的小问题二三则

文章目录 前言Redis问题启用碎片自动回收失败启动Redis未脱离终端 Vercel问题未在Vecel团队的人提交无法触发自动部署更新package.json后部署Vercel时报错 Android问题主动请求通知权限网络状态变化的监听不能使用静态注册各种Service介绍和对比 总结 前言 这两天的工作又相对…