Tikhonova Polina, Homework 3

In [1]:
from pubchempy import *
from rdkit import Chem
from rdkit.Chem import AllChem
from rdkit import RDConfig
from rdkit.Chem.Draw import IPythonConsole 
from rdkit.Chem import Draw
import rdkit.Chem.Lipinski as Lipinksy

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

Chem.Draw.DrawingOptions.bondLineWidth=2
Chem.Draw.DrawingOptions.atomLabelFontSize=14
In [2]:
ibus = [Chem.MolFromSmiles(i) for i in ['CC(C)CC1=CC=C(C=C1)C(C)C(=O)O',"C#CCC1=CC=C(C=C1)C(C)C(=O)O"]]
ibus[0].SetProp('_Name', 'Ibuprofen')
ibus[1].SetProp('_Name', 'Modificated Ibuprofen')

img = Chem.Draw.MolsToGridImage(ibus, molsPerRow=2, 
                                subImgSize=(500,200), 
                                legends=[ibus[0].GetProp('_Name'), ibus[1].GetProp('_Name')])
display(img)
In [3]:
def Lipinksy_rules(substance):
     return ((Lipinksy.NumHDonors(substance) <= 5) & 
             (Lipinksy.NumHAcceptors(substance) <= 10)&
             (Lipinksy.rdMolDescriptors.CalcExactMolWt(substance)<500)& 
             ( Lipinksy.rdMolDescriptors.CalcCrippenDescriptors(substance)[0]<=5))
In [4]:
# check if Ibuprofen and modified ibuprofen satisfy Lipinksy conditions
print('Ibuprofen: %s\nModified Ibuprofen: %s'%tuple([Lipinksy_rules(ibu) for ibu in ibus]))
Ibuprofen: True
Modified Ibuprofen: True
In [5]:
# The molecule we'll insert
display(Chem.MolFromSmiles("N2C=C(N=N2)CC1=CC=C(C=C1)C(C)C(=O)O"))
In [6]:
df = get_properties( 
    properties="CanonicalSMILES", identifier="N=N=N", namespace="smiles", 
    searchtype="substructure", RingsNotEmbedded=True, as_dataframe=True )
radicals_array = np.array(df).flatten()
df.head()
Out[6]:
CanonicalSMILES
CID
129900310 CC1C(OC(=O)C(C1O)C)CC(C=CC(C)C(C(C)C=C(C)CC(C)...
129897709 C1=C2C=C(C(=O)OC2=CC(=C1Br)OCC(=O)O)N=[N+]=[N-]
129897708 C1=C2C=C(C(=O)OC2=C(C(=C1Cl)O)Cl)N=[N+]=[N-]
129897707 CCC1=CC2=C(C=C1)OC(=O)C(=C2)N=[N+]=[N-]
129897706 C1=CC=C2C(=C1)C=CC3=C2C=C(C(=O)O3)N=[N+]=[N-]
In [7]:
smiles = []
for radical in radicals_array:
    if len(radical) < 30 and not '.' in radical:
        smiles.append(radical)
print('Amount of objects: %d'%len(smiles))
Amount of objects: 10750
In [8]:
new_molecules = []
for smile in smiles:
    if 'N=[N+]=[N-]' in smile:
        new_smile = smile.replace('N=[N+]=[N-]',"N2C=C(N=N2)CC1=CC=C(C=C1)C(C)C(=O)O")
        try:
            new_molecule = Chem.MolFromSmiles(new_smile)
            new_molecules.append(new_molecule) if Lipinksy_rules(new_molecule) else None
        except:
            pass
    else:
        continue
print('Amount of moleculas: %d'%len(new_molecules))
Amount of moleculas: 10070
In [28]:
# randomly choose and display 9 molecules
indexes = random.sample(range(10070), 9)
to_show = [new_molecules[i] for i in indexes]
img = Chem.Draw.MolsToGridImage(to_show, molsPerRow=3, 
                                subImgSize=(400,200))
display(img)

Unfortunately, nglview doesn't work on my computer. It shows nothing(((