Skip to content

Commit 04b2aaa

Browse files
author
Oliver Scott
committed
Dataframe supplier can use columns containing Mol objects instead of SMILES strings
1 parent 75acd7d commit 04b2aaa

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

scaffoldgraph/core/graph.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -952,7 +952,8 @@ def from_dataframe(cls, df, smiles_column='Smiles', name_column='Name', data_col
952952
df : pd.DataFrame
953953
A pandas DataFrame containing SMILES strings and a molecule identifier.
954954
smiles_column : value, optional
955-
Label of column containing SMILES strings. The default is 'Smiles'.
955+
Label of column containing SMILES strings. The default is 'Smiles'. The
956+
column may instead contain precomputed rdkit Mol objects.
956957
name_column : str
957958
Label of column containing SMILES strings. The default is 'Name'.
958959
data_columns : list

scaffoldgraph/io/dataframe.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Contains functions for reading molecules from pandas dataframes.
55
"""
66

7-
from rdkit.Chem import MolFromSmiles
7+
from rdkit.Chem import MolFromSmiles, Mol
88
from loguru import logger
99

1010

@@ -48,7 +48,10 @@ def __iter__(self):
4848
def __next__(self):
4949
values = next(self.supplier)
5050
try:
51-
mol = MolFromSmiles(values[0])
51+
if isinstance(values[0], Mol):
52+
mol = values[0]
53+
else:
54+
mol = MolFromSmiles(values[0])
5255
mol.SetProp('_Name', str(values[1]))
5356
if self.data_cols is not None:
5457
for key, value in zip(self.data_cols, values[2]):
@@ -75,7 +78,7 @@ def read_dataframe(df, smiles_column, name_column, data_columns=None):
7578
df : pandas.DataFrame
7679
Dataframe to read molecules from.
7780
smiles_column : str
78-
Key of column containing SMILES strings.
81+
Key of column containing SMILES strings or rdkit Mol objects.
7982
name_column : str
8083
Key of column containing molecule name strings.
8184
data_columns : list, optional

0 commit comments

Comments
 (0)