Possible to directly feed SMILE structures stored in a pandas dataframe into RDKit to calculate molecular fingerprint and similarity?

Viewed 654
ref_Molecule = Chem.MolFromSmiles('CC1=C(C(O)=O)C2=CC(=CC=C2N=C1C3=CC=C(C=C3)C4=CC=CC=C4F)F')

merged_data['Molecule_Tan'] = DataStructs.TanimotoSimilarity(Chem.RDKFingerprint(ref_Brequinar), Chem.RDKFingerprint(Chem.MolFromSmiles(merged_data.SMILES)))

I have roughly 1500 SMILES structures stored in my df, merged_data['SMILES'].

I am trying to create a new column of merged_data named 'Molecule_Tan' which I want to populate with the Tanimoto Similarity Index of the data frame smiles verses the reference sequence stored in, ref_Molecule.

I tried being efficient by passing the SMILE values directly from the data frame into the nested RDKit functions all on one line using merged_data.SMILES or merged_data['SMILES'], but when I try to run this I get this error..

Traceback (most recent call last):
  File "filepath", line 69, in <module>
    strasd = Chem.MolFromSmiles(merged_data['SMILES'].astype('object'))

TypeError: No registered converter was able to produce a C++ rvalue of type class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> > from this Python object of type Series

This error also occurs if I try to give only Chem.MolFromSmiles() the data frame.

Though I'm not 100% clear on it, I think the error is related to the pandas data frame trying to give the MolFromSmiles() function a series instead of individual objects.

What I am trying to figure out is if there is a way that I could manage what I am trying to do within pandas, without writing a loop to iterate over the entire data frame.

Thank you to anyone who can give me some input on whether what I am trying to do is possible!!!

==============

If it helps, this is roughly what the important parts of my data frame looks like...

      Title  ...                                             SMILES
0    236254  ...           Cc1c(-c2ccccc2)n(O)[n+]([O-])c1-c1ccccc1
1     79582  ...                        [O-][n+]1nc2ccccc2c2ccccc21
2     26744  ...                     O=c1cc(-c2ccccc2)oc2ccc(O)cc12
3     38007  ...                     Oc1cc(-c2ccc(Cl)cc2)nc2ccccc12
4    109747  ...                  Cc1cc(O)c2cc(C(=O)c3ccccc3)ccc2n1
..      ...  ...                                                ...
1 Answers

You are right, that pandas gives the whole series instead of individual objects, so you have to iterate.

But then the fingerprints can be compared at once with BulkTanimotoSimilarity().

You could try this code:

from rdkit import Chem
from rdkit import DataStructs
import pandas as pd

target = Chem.RDKFingerprint(Chem.MolFromSmiles('CC1=C(C(O)=O)C2=CC(=CC=C2N=C1C3=CC=C(C=C3)C4=CC=CC=C4F)F'))

d = {'SMILES': ['Cc1c(-c2ccccc2)n(O)[n+]([O-])c1-c1ccccc1',
                '[O-][n+]1nc2ccccc2c2ccccc21',
                'O=c1cc(-c2ccccc2)oc2ccc(O)cc12',
                'Oc1cc(-c2ccc(Cl)cc2)nc2ccccc12',
                'Cc1cc(O)c2cc(C(=O)c3ccccc3)ccc2n1']}

df = pd.DataFrame(data=d)

df['Tanimoto'] = DataStructs.BulkTanimotoSimilarity(target, [Chem.RDKFingerprint(Chem.MolFromSmiles(s)) for s in df['SMILES']])

print(df)

Output:

                                     SMILES  Tanimoto
0  Cc1c(-c2ccccc2)n(O)[n+]([O-])c1-c1ccccc1  0.287625
1               [O-][n+]1nc2ccccc2c2ccccc21  0.178967
2            O=c1cc(-c2ccccc2)oc2ccc(O)cc12  0.273179
3            Oc1cc(-c2ccc(Cl)cc2)nc2ccccc12  0.387127
4         Cc1cc(O)c2cc(C(=O)c3ccccc3)ccc2n1  0.319298
Related