8000 [Feature] Molecule Meida Object3D Support. by xj63 · Pull Request #920 · SwanHubX/SwanLab · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[Feature] Molecule Meida Object3D Support. #920

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

Merged
merged 15 commits into from
Apr 5, 2025

Conversation

xj63
Copy link
Contributor
@xj63 xj63 commented Mar 30, 2025

Description

This PR introduces support for visualizing 3D molecules within SwanLab. It adds a Molecule class to the object3d module, enabling users to display molecules from various sources. This includes reading from common molecule file formats (PDB, SDF, MOL) as well as directly from RDKit Mol objects. A test case is also included to demonstrate the functionality.

Closes: #476

Supported Input Types

The Object3D class now supports the following input types for visualizing molecules:

  • Files: .pdb, .sdf, .sd, .mol
  • RDKit Mol Objects: rdkit.Chem.Mol

Dependencies

This functionality relies on the RDKit library. If RDKit is not already installed, please install it using:

pip install rdkit

Example

from rdkit import Chem

import swanlab

swanlab.init(project="molecule", public=True)

# from rdkit.Chem.Mol
chem = Chem.MolFromSmiles("CCO")

molecule = swanlab.Object3D(chem, caption="cco")
swanlab.log({"example": molecule})

# from file path
mol2 = swanlab.Object3D("./molecule.example.pdb")
swanlab.log({"file": mol2})

xj63 added 8 commits March 29, 2025 20:04
This commit introduces the Molecule class, which is used to visualize
3D molecules. The class can be initialized with PDB data or from an
RDKit Mol object. It includes methods for parsing the molecule data
into a buffer and for returning metadata for visualization.
This commit introduces a test case for visualizing molecules
using swanlab.data.modules.object3d.Molecule.
This commit introduces the Molecule class for handling molecule
data from various formats using the RDKit library, and add it to
`__all__` in `__init__.py`.
Adds from_pdb_file, from_sdf_file, from_smiles and from_mol_file
methods to the Molecule class. These methods allow creating
Molecule instances from various file formats (PDB, SDF, Mol) and
SMILES strings, providing more flexibility in how molecule data is
loaded and displayed.
Enable creation of Object3D from rdkit.Chem.Mol objects and
add file handlers for common molecule file formats.
@SAKURA-CAT SAKURA-CAT self-assigned this Mar 30, 2025
@SAKURA-CAT SAKURA-CAT added the 💪 enhancement New feature or request label Mar 30, 2025
Copy link
@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for visualizing 3D molecules in SwanLab by introducing a new Molecule class in the object3d module. It enables handling RDKit Mol objects and common molecule file formats while updating the Object3D dispatcher and exporting the Molecule class.

  • Added test cases that demonstrate molecule visualization using both file paths and RDKit Mol objects.
  • Updated Object3D to handle molecule input and added file handlers for various molecule file extensions.
  • Introduced a new Molecule class that provides methods for creating molecule instances from Mol objects and molecule files.

Reviewed Changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated no comments.

File Description
test/metrics/molecule.py Added tests demonstrating functionality with RDKit Mol objects and PDB files.
swanlab/data/modules/object3d/object3d.py Integrated molecule support into Object3D with proper file handlers and type checking.
swanlab/data/modules/object3d/molecule.py New Molecule class supporting multiple construction methods from molecule data.
swanlab/data/modules/object3d/init.py Updated exports to include the new Molecule class.
Files not reviewed (1)
  • test/metrics/molecule.example.pdb: Language not supported
Comments suppressed due to low confidence (1)

swanlab/data/modules/object3d/molecule.py:171

  • The code references 'self.step' in the parse method, but there is no clear definition or initialization of 'step' in the Molecule class. Ensure that 'step' is properly defined, inherited, or provided to avoid runtime errors.
save_name = f"molecule-step{self.step}-{hash_name}.pdb"

xj63 and others added 7 commits March 31, 2025 18:34
This commit introduces a comprehensive test suite for the
`Molecule` class within the `swanlab.data.modules.object3d` module.
The tests cover various functionalities including:

- Creating `Molecule` objects from different file formats (PDB, SDF,
  Mol) and SMILES strings.
- Parsing `Molecule` objects.
- Verifying metadata such as caption and chart type.
- Ensures that `Object3D` correctly dispatches `Molecule` objects.
@SAKURA-CAT SAKURA-CAT merged commit 11a303e into SwanHubX:main Apr 5, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💪 enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

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