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_` 开头。

相关推荐
多打代码几秒前
2026.1.29 复原ip地址 & 子集 & 子集2
开发语言·python
人工智能AI技术1 分钟前
【Agent从入门到实践】47 与前端系统集成:通过API对接,实现前端交互
人工智能·python
qq_192779876 分钟前
如何用FastAPI构建高性能的现代API
jvm·数据库·python
癫狂的兔子7 分钟前
【bug】【Python】pandas中的DataFrame.to_excel()和ExcelWriter的区别
python·bug
生活很暖很治愈8 分钟前
Pytest-order插件
python·测试工具·测试用例·pytest
HeDongDong-9 分钟前
详解 Kotlin 的函数
开发语言·python·kotlin
啊阿狸不会拉杆9 分钟前
《数字信号处理》第5章-数字滤波器的基本结构
python·算法·机器学习·matlab·信号处理·数字信号处理·dsp
逄逄不是胖胖10 分钟前
《动手学深度学习》-56GRN实现
pytorch·python·深度学习
naruto_lnq13 分钟前
用户认证与授权:使用JWT保护你的API
jvm·数据库·python
m0_5811241916 分钟前
Python数据库操作:SQLAlchemy ORM指南
jvm·数据库·python