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
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)
def Lipinksy_rules(substance):
return ((Lipinksy.NumHDonors(substance) <= 5) &
(Lipinksy.NumHAcceptors(substance) <= 10)&
(Lipinksy.rdMolDescriptors.CalcExactMolWt(substance)<500)&
( Lipinksy.rdMolDescriptors.CalcCrippenDescriptors(substance)[0]<=5))
# check if Ibuprofen and modified ibuprofen satisfy Lipinksy conditions
print('Ibuprofen: %s\nModified Ibuprofen: %s'%tuple([Lipinksy_rules(ibu) for ibu in ibus]))
# The molecule we'll insert
display(Chem.MolFromSmiles("N2C=C(N=N2)CC1=CC=C(C=C1)C(C)C(=O)O"))
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()
smiles = []
for radical in radicals_array:
if len(radical) < 30 and not '.' in radical:
smiles.append(radical)
print('Amount of objects: %d'%len(smiles))
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))
# 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(((