# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

import pandas as pd
from rdkit import Chem
from rdkit.Chem import PandasTools
from rdkit.Chem.Draw import MolsToGridImage
from rdkit.Chem.Draw import IPythonConsole
from rdkit.Chem import rdDepictor
rdDepictor.SetPreferCoordGen(True)
IPythonConsole.ipython_useSVG = True

# The next bit of code is a workaround to circumvent the broken Molrendering caused by changes in [Pandas v0.25.x](https://github.com/rdkit/rdkit/issues/2673).

# +
PandasTools.RenderImagesInAllDataFrames(images=True)

from IPython.core.display import HTML

def show(df):
    return HTML(df.to_html(notebook=True))


# -

mydf = pd.read_pickle('58_molobj.pkl')

show(mydf.head())

query = Chem.MolFromSmiles('c1ccncc1')

query

hits = mydf[mydf['mol'] >= query]

hits.shape

show(hits.head())

PandasTools.WriteSDF(hits, 'substruct_hits.sdf', molColName='mol', idName='molport_id')

StarcoderdataJupyterScriptsDedupFiltered