Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/molecule-class #477

Closed
wants to merge 5 commits into from
Closed

Feat/molecule-class #477

wants to merge 5 commits into from

Conversation

Zeyi-Lin
Copy link
Member

@Zeyi-Lin Zeyi-Lin commented Apr 18, 2024

swanlab.Molecule 类

swanlab.Molecule 类的目标是提供一系列数据处理方法,用于预处理和转换三种类型的输入数据:

支持的输入类型

  1. 文件路径:支持传入string与IO流,支持多种格式,包括 "pdb", "pqr", "mmcif", "mcif", "cif", "sdf", "sd", "gro", "mol2", "mmtf" 等。
  2. rdkit 对象:使用 rdkit 化学工具包的 rdkit.Chem.rdchem.Mol 对象。
  3. SMILES 文本:使用 SMILES (Simplified Molecular Input Line Entry System) 格式的文本。

处理规则

输入类型 数据类型 处理方式 接口方法
文件路径 str, io 判断后缀格式,移动到对应 swanlog 目录下 Molecule(data)
rdkit 对象 "rdkit.Chem.rdchem.Mol" 转换为 pdb 格式文件,移动到对应 swanlog 目录下 Molecule.from_rakit(data)
SMILES 文本 str 传入 Molecule.from_rakit 处理 Molecule.from_smiles(data)

思维导图

image

功能实现

Molecule 实例被 swanlab.log() 调用时,它会执行上述的处理流程(pipeline),并将结果保存到 swanlog 文件夹下,以便前端显示。

测试代码

如需测试rdkit,需要安装该pypi库:

pip install rdkit

下载PDB文件:

5p21.pdb.zip

测试代码如下:

import swanlab
from rdkit import Chem

swanlab.init(project="molecule_visualization", cloud=False)

# 使用 SMILES 字符串创建一个 RDKit 分子对象
smiles = "CCO"  # 这是乙醇的 SMILES 表达式
molecule = Chem.MolFromSmiles(smiles)

# 将分子图像记录到 W&B
# 1. from_rdkit
swanlab.log({"Benzene": swanlab.Molecule.from_rdkit(molecule)})

# 2. 直接smiles
swanlab.log({"Benzene": swanlab.Molecule.from_smiles(smiles)})

# 3. 使用文件路径
swanlab.log({"Benzene": swanlab.Molecule("test/temp/molecules_pdb/5p21.pdb", caption="5p21")})

swanlog下的保存结果:

image

Closes: #476

@Zeyi-Lin Zeyi-Lin self-assigned this Apr 18, 2024
@Zeyi-Lin Zeyi-Lin added the 🌍 prepare for the future Feature prepare for the future label Apr 18, 2024
@Zeyi-Lin Zeyi-Lin added this to the DataType milestone Apr 18, 2024
@SAKURA-CAT SAKURA-CAT closed this May 16, 2024
@SAKURA-CAT SAKURA-CAT added the 🙋 help wanted Extra attention is needed label May 16, 2024
@SAKURA-CAT SAKURA-CAT deleted the feat/Molecule branch June 4, 2024 16:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🙋 help wanted Extra attention is needed 🌍 prepare for the future Feature prepare for the future
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[REQUEST] swanlab.Melocule 生物化学分子处理类
2 participants