Skip to content

Instantly share code, notes, and snippets.

@iwatobipen
Created July 18, 2020 11:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iwatobipen/5346eab9025144780da669b4d840b545 to your computer and use it in GitHub Desktop.
Save iwatobipen/5346eab9025144780da669b4d840b545 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"load rdk schema\n"
]
}
],
"source": [
"import pickle\n",
"from rdkit import Chem\n",
"from rdkit.Chem import rdSubstructLibrary\n",
"from pychembldb import *\n",
"from rdkit.Chem import Draw\n",
"from rdkit.Chem.Draw import IPythonConsole\n",
"from razi.rdkit_postgresql.functions import mol_from_smarts, mol_from_smiles"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## To make ssslib please check follwoing nice post\n",
"### https://rdkit.blogspot.com/2018/02/introducing-substructlibrary.html"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"library = pickle.load(open('chembl27_ssslib.pkl', 'rb'))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# sub structure search with SMILES and rdkit-postgres cartridge."
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"CPU times: user 569 ms, sys: 16.8 ms, total: 586 ms\n",
"Wall time: 3.39 s\n"
]
}
],
"source": [
"q = chembldb.query(Mols.m)\n",
"res = q.filter(Mols.m.hassubstruct(mol_from_smiles('c1ccccc1'))).limit(10000)\n",
"%time a=res.all()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# subsearch molecule with SMILES and rdSubstructLibrary."
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"CPU times: user 847 ms, sys: 1.71 ms, total: 848 ms\n",
"Wall time: 348 ms\n"
]
}
],
"source": [
"%time a=library.GetMatches(Chem.MolFromSmiles('c1ccccc1'), maxResults=10000)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# substructure search with SMARTS and rdkit-postgres cartridge."
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"CPU times: user 615 ms, sys: 8.61 ms, total: 624 ms\n",
"Wall time: 3.41 s\n"
]
}
],
"source": [
"q = chembldb.query(Mols.m)\n",
"res = q.filter(Mols.m.hassubstruct(mol_from_smarts('a1aaaaa1'))).limit(10000)\n",
"%time a=res.all()"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"# subsearch molecule with SMARTS and rdSubstructLibrary."
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"CPU times: user 910 ms, sys: 0 ns, total: 910 ms\n",
"Wall time: 342 ms\n"
]
}
],
"source": [
"%time a=library.GetMatches(Chem.MolFromSmarts('a1aaaaa1'), maxResults=10000)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.7"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment