3. Ibuprofen alternatives.

3.1 Importing all basics modules.

In [1]:
# Lipinski -- checking Lipinski rules
# IPythonConsole -- displaying chemical molecules

from rdkit import Chem
from rdkit.Chem import AllChem, Draw, Lipinski
from rdkit.Chem.Draw import SimilarityMaps, IPythonConsole

import numpy as np
from IPython.display import SVG,Image

3.2 Displaying ibuprofen molecule and checking Lipinski rules.

In [2]:
ibu = Chem.MolFromSmiles('CC(C)CC1=CC=C(C=C1)C(C)C(=O)O')

AllChem.Compute2DCoords(ibu)
display(ibu)
In [3]:
def check_Lipinski(mol): 
    is_Lipinsky = bool((Lipinski.NumHDonors(mol) <= 5) \
    and (Lipinski.NumHAcceptors(mol) <= 10) \
    and (Lipinski.rdMolDescriptors.CalcExactMolWt(mol) < 500) \
    and(Lipinski.rdMolDescriptors.CalcCrippenDescriptors(mol)[0]) <= 5)
    return is_Lipinsky
In [4]:
# Ibuprofen fits Lipinski rules

print (check_Lipinski(ibu))
True

3.3 Modifying ibuprofen molecule.

In [5]:
modified_ibu = 'N1N=NC(=C1)C(C)CC1=CC=C(C=C1)C(C)C(=O)O'

diene_ibu = Chem.MolFromSmiles('{}'.format(modified_ibu))

AllChem.Compute2DCoords(diene_ibu)
display(diene_ibu)

3.4 How to search for azide containing compounds?

Substructure/superstructure --> CID,SMILES/SMARTS,InChi --> compound id

(#22) AND (lipinski_rule_of_5[filt]) AND (pccompound_pcassay[filt]) -- 69448 hits (BioAssays, tested)

Actions on your result --> download structures --> smiles

3.5 Filtering compounds.

In [6]:
strings_cut = np.genfromtxt('smiles_cut.txt',dtype = np.str)
smiles_cut = []

for line in strings_cut:
    if (len(line[1]) < 30) and (len(line[1]) > 11) and not ( '.' in line[1]):
        smiles_cut.append(line[1])
In [7]:
print('Size of cut list is ' + str(len(smiles_cut)))
Size of cut list is 2281
In [8]:
products = []

for smi in smiles_cut[:len(smiles_cut)]:
    if "N=[N+]=[N-]" in smi:
        newsmi = smi.replace("N=[N+]=[N-]", modified_ibu)
    else:
        continue
    try:
        newmol = Chem.MolFromSmiles(newsmi)
        if check_Lipinski(newmol):
            products.append(newmol)
    except Exception:
        pass
In [9]:
print('Size of cut filtered list is ' + str(len(products)))
Size of cut filtered list is 94

3.6 Making a random list (size = 16) of compounds.

In [10]:
import random

molecules = []

for pics in random.sample(products, 16):
    AllChem.Compute2DCoords(pics)
    molecules.append(pics)

Chem.Draw.MolsToGridImage(molecules, molsPerRow = 4, subImgSize = (500, 500))
Out[10]:

3.7 Click-chemistry reaction with the 1 molecule in random list of compounds.

In [12]:
fig, maxweight = SimilarityMaps.GetSimilarityMapForFingerprint(ibu, \
    molecules[0], SimilarityMaps.GetMorganFingerprint)
In [13]:
maxweight
Out[13]:
0.20234192037470727

3.8 Molecule in 3D.

In [14]:
m3d = Chem.AddHs(molecules[0])
AllChem.EmbedMolecule(m3d)
AllChem.MMFFOptimizeMolecule(m3d, maxIters = 500, nonBondedThresh = 200)

m3d
Out[14]:
In [10]:
# Do not work :(

import nglview as nv

nv.show_rdkit(m3d)
Widget Javascript not detected.  It may not be installed properly. Did you enable the widgetsnbextension? If not, then run "jupyter nbextension enable --py --sys-prefix widgetsnbextension"

3.9 Converting smiles format to mol format using openbabel.

In [15]:
smiles_to_pymol = Chem.MolToSmiles(m3d)

with open('my_mol.smi', 'w') as file:
    file.write(smiles_to_pymol)
In [24]:
import subprocess
import os

where_am_i = os.getcwd()
subprocess.run(['obgen', '"$where_am_i"/my_mol.smi', '>', '"$where_am_i"/my_mol.mol'], shell = True)
Out[24]:
CompletedProcess(args=['obgen', '"$where_am_i"/my_mol.smi', '>', '"$where_am_i"/my_mol.mol'], returncode=255)

3.10 Importing pymol module to display ibuprofen alternative.

In [25]:
import __main__
__main__.pymol_argv = [ 'pymol', '-x' ]

import pymol
pymol.finish_launching()

from pymol import cmd
In [26]:
cmd.reinitialize()
cmd.bg_color('white')

cmd.load('my_mol.mol', 'structure')
cmd.util.cbas('structure')

cmd.turn('y', -20)
cmd.turn('x', 20)

3.11 Enjoying the result.

In [27]:
cmd.set('ray_trace_mode', 1)
cmd.png('my_mol.png', '1920', '1080', ray=1)
In [28]:
Image('my_mol.png', retina=True)
Out[28]: