Skip to content

Commit a0f4f67

Browse files
committed
add IO functionalities
1 parent a8605b8 commit a0f4f67

File tree

13 files changed

+924
-237
lines changed

13 files changed

+924
-237
lines changed

mols2grid/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
from mols2grid._version import __version__
44
from mols2grid.callbacks import make_popup_callback
55
from mols2grid.dispatch import display, save
6+
from mols2grid.io import read_mols_to_df
67
from mols2grid.molgrid import MolGrid
78
from mols2grid.select import get_selection, link_marimo_state, list_grids
8-
from mols2grid.utils import is_running_within_streamlit, sdf_to_dataframe
9+
from mols2grid.utils import is_running_within_streamlit
910

1011
if is_running_within_streamlit():
1112
import os

mols2grid/chem.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from typing import Any
2+
3+
from rdkit import Chem
4+
5+
6+
def mol_to_smiles(mol: Chem.Mol | None) -> str | None:
7+
"""Returns a SMILES from an RDKit molecule, or None if not an RDKit mol"""
8+
return Chem.MolToSmiles(mol) if mol else None
9+
10+
11+
def mol_to_record(mol: Chem.Mol | None, mol_col: str = "mol") -> dict[str, Any]:
12+
"""Function to create a dict of data from an RDKit molecule"""
13+
return {**mol.GetPropsAsDict(includePrivate=True), mol_col: mol} if mol else {}
14+
15+
16+
def remove_coordinates(mol: Chem.Mol) -> Chem.Mol:
17+
"""Removes the existing coordinates from the molecule. The molecule is
18+
modified inplace"""
19+
mol.RemoveAllConformers()
20+
return mol

0 commit comments

Comments
 (0)