RDKit 给3D信息缺失的sdf生成三维结构

要生成包含三维结构的 SDF 文件,可以使用 RDKit 等化学信息学工具。以下是一个 Python 脚本示例,使用 RDKit 读取 SDF 文件、生成三维结构并保存。

安装 RDKit

如果尚未安装 RDKit,可以通过以下命令安装:

```bash

conda install -c conda-forge rdkit

```

Python 脚本

```python

import os

from rdkit import Chem

from rdkit.Chem import AllChem

def generate_3d_structure(input_sdf, output_sdf):

读取 SDF 文件

suppl = Chem.SDMolSupplier(input_sdf)

writer = Chem.SDWriter(output_sdf)

for mol in suppl:

if mol is not None:

生成三维结构

AllChem.EmbedMolecule(mol)

AllChem.UFFOptimizeMolecule(mol)

写入新的 SDF 文件

writer.write(mol)

writer.close()

def process_directory(directory):

for filename in os.listdir(directory):

if filename.endswith(".sdf"):

input_sdf = os.path.join(directory, filename)

output_sdf = os.path.join(directory, f"3d_{filename}")

generate_3d_structure(input_sdf, output_sdf)

print(f"Processed {filename} and saved to {output_sdf}")

if name == "main":

指定目录

directory = "path/to/your/directory"

process_directory(directory)

```

脚本说明

  1. **generate_3d_structure**: 读取 SDF 文件,生成三维结构并保存。

  2. **process_directory**: 遍历指定目录,处理所有 `.sdf` 文件。

  3. **EmbedMolecule**: 生成三维坐标。

  4. **UFFOptimizeMolecule**: 使用 UFF 力场优化结构。

使用步骤

  1. 将脚本保存为 `generate_3d_structures.py`。

  2. 修改 `directory` 变量为目标目录路径。

  3. 运行脚本:

```bash

python generate_3d_structures.py

```

脚本会为每个 `.sdf` 文件生成一个包含三维结构的新文件,文件名以 `3d_` 开头。

相关推荐
YuanDaima204813 小时前
基于 LangChain 1.0 的检索增强生成(RAG)实战
人工智能·笔记·python·langchain·个人开发·langgraph
RopenYuan13 小时前
FastAPI -API Router的应用
前端·网络·python
听风吹等浪起13 小时前
用Python和Pygame从零实现坦克大战
开发语言·python·pygame
书到用时方恨少!13 小时前
Python Pandas 使用指南:数据分析的瑞士军刀
python·数据分析·pandas
智算菩萨14 小时前
【Pygame】第8章 文字渲染与字体系统(支持中文字体)
开发语言·python·pygame
:mnong14 小时前
全图纸语义理解升级分析
python·openvino·paddleocr·qt6.3·paddleocr-vl
qh0526wy14 小时前
pathlib 核心功能一览
python
Hello eveybody15 小时前
PyCharm性能调优避坑录
python·pycharm
¥-oriented15 小时前
【Python桌面应用开发环境搭建指南】
开发语言·python
Etherious_Young15 小时前
用u2写一个实况足球图像识别自动化脚本(3)
python·自动化·游戏自动化