In [1]:
 conda install -c rdkit rdkit
Collecting package metadata (current_repodata.json): done
Solving environment: | 
Warning: >10 possible package resolutions (only showing differing packages):
  - anaconda/osx-64::ca-certificates-2019.8.28-0, anaconda/osx-64::certifi-2019.9.11-py37_0, anaconda/osx-64::conda-4.8.2-py37_0, anaconda/osx-64::openssl-1.1.1d-h1de35cc_2
  - anaconda/osx-64::ca-certificates-2019.8.28-0, anaconda/osx-64::certifi-2019.9.11-py37_0, anaconda/osx-64::openssl-1.1.1d-h1de35cc_2, defaults/osx-64::conda-4.8.2-py37_0
  - anaconda/osx-64::ca-certificates-2019.8.28-0, anaconda/osx-64::conda-4.8.2-py37_0, anaconda/osx-64::openssl-1.1.1d-h1de35cc_2, defaults/osx-64::certifi-2019.9.11-py37_0
  - anaconda/osx-64::ca-certificates-2019.8.28-0, anaconda/osx-64::openssl-1.1.1d-h1de35cc_2, defaults/osx-64::certifi-2019.9.11-py37_0, defaults/osx-64::conda-4.8.2-py37_0
  - anaconda/osx-64::ca-certificates-2019.8.28-0, anaconda/osx-64::conda-4.8.2-py37_0, defaults/osx-64::certifi-2019.9.11-py37_0, defaults/osx-64::openssl-1.1.1d-h1de35cc_2
  - anaconda/osx-64::ca-certificates-2019.8.28-0, defaults/osx-64::certifi-2019.9.11-py37_0, defaults/osx-64::conda-4.8.2-py37_0, defaults/osx-64::openssl-1.1.1d-h1de35cc_2
  - anaconda/osx-64::ca-certificates-2019.8.28-0, anaconda/osx-64::certifi-2019.9.11-py37_0, anaconda/osx-64::conda-4.8.2-py37_0, defaults/osx-64::openssl-1.1.1d-h1de35cc_2
  - anaconda/osx-64::ca-certificates-2019.8.28-0, anaconda/osx-64::certifi-2019.9.11-py37_0, defaults/osx-64::conda-4.8.2-py37_0, defaults/osx-64::openssl-1.1.1d-h1de35cc_2
  - anaconda/osx-64::certifi-2019.9.11-py37_0, anaconda/osx-64::conda-4.8.2-py37_0, defaults/osx-64::ca-certificates-2019.8.28-0, defaults/osx-64::openssl-1.1.1d-h1de35cc_2
  - anaconda/osx-64::certifi-2019.9.11-py37_0, anaconda/osx-64::conda-4.8.2-py37_0, anaconda/osx-64::openssl-1.1.1d-h1de35cc_2, defaults/osx-64::ca-certificates-2019.8.28-0
  ... and othedone

## Package Plan ##

  environment location: /opt/anaconda3

  added / updated specs:
    - rdkit


The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    cairo-1.14.12              |       hc4e6be7_4         860 KB
    fontconfig-2.13.0          |       h5d5b041_1         202 KB
    libboost-1.67.0            |       hebc422b_4        12.7 MB
    pixman-0.38.0              |       h1de35cc_0         341 KB
    py-boost-1.67.0            |   py37h6440ff4_4         286 KB
    rdkit-2019.09.3.0          |   py37h65625ec_1        22.2 MB  rdkit
    ------------------------------------------------------------
                                           Total:        36.6 MB

The following NEW packages will be INSTALLED:

  cairo              pkgs/main/osx-64::cairo-1.14.12-hc4e6be7_4
  fontconfig         pkgs/main/osx-64::fontconfig-2.13.0-h5d5b041_1
  libboost           pkgs/main/osx-64::libboost-1.67.0-hebc422b_4
  pixman             pkgs/main/osx-64::pixman-0.38.0-h1de35cc_0
  py-boost           pkgs/main/osx-64::py-boost-1.67.0-py37h6440ff4_4
  rdkit              rdkit/osx-64::rdkit-2019.09.3.0-py37h65625ec_1



Downloading and Extracting Packages
rdkit-2019.09.3.0    | 22.2 MB   | ##################################### | 100% 
cairo-1.14.12        | 860 KB    | ##################################### | 100% 
fontconfig-2.13.0    | 202 KB    | ##################################### | 100% 
pixman-0.38.0        | 341 KB    | ##################################### | 100% 
libboost-1.67.0      | 12.7 MB   | ##################################### | 100% 
py-boost-1.67.0      | 286 KB    | ##################################### | 100% 
Preparing transaction: done
Verifying transaction: done
Executing transaction: done

Note: you may need to restart the kernel to use updated packages.
In [2]:
 conda install -c jirinovo pubchempy 
Collecting package metadata (current_repodata.json): done
Solving environment: - 
Warning: >10 possible package resolutions (only showing differing packages):
  - anaconda/osx-64::ca-certificates-2019.8.28-0, anaconda/osx-64::certifi-2019.9.11-py37_0, anaconda/osx-64::conda-4.8.2-py37_0, anaconda/osx-64::openssl-1.1.1d-h1de35cc_2
  - anaconda/osx-64::ca-certificates-2019.8.28-0, anaconda/osx-64::certifi-2019.9.11-py37_0, anaconda/osx-64::openssl-1.1.1d-h1de35cc_2, defaults/osx-64::conda-4.8.2-py37_0
  - anaconda/osx-64::ca-certificates-2019.8.28-0, anaconda/osx-64::conda-4.8.2-py37_0, anaconda/osx-64::openssl-1.1.1d-h1de35cc_2, defaults/osx-64::certifi-2019.9.11-py37_0
  - anaconda/osx-64::ca-certificates-2019.8.28-0, anaconda/osx-64::openssl-1.1.1d-h1de35cc_2, defaults/osx-64::certifi-2019.9.11-py37_0, defaults/osx-64::conda-4.8.2-py37_0
  - anaconda/osx-64::conda-4.8.2-py37_0, anaconda/osx-64::openssl-1.1.1d-h1de35cc_2, defaults/osx-64::ca-certificates-2019.8.28-0, defaults/osx-64::certifi-2019.9.11-py37_0
  - anaconda/osx-64::openssl-1.1.1d-h1de35cc_2, defaults/osx-64::ca-certificates-2019.8.28-0, defaults/osx-64::certifi-2019.9.11-py37_0, defaults/osx-64::conda-4.8.2-py37_0
  - anaconda/osx-64::certifi-2019.9.11-py37_0, anaconda/osx-64::conda-4.8.2-py37_0, anaconda/osx-64::openssl-1.1.1d-h1de35cc_2, defaults/osx-64::ca-certificates-2019.8.28-0
  - anaconda/osx-64::certifi-2019.9.11-py37_0, anaconda/osx-64::openssl-1.1.1d-h1de35cc_2, defaults/osx-64::ca-certificates-2019.8.28-0, defaults/osx-64::conda-4.8.2-py37_0
  - anaconda/osx-64::certifi-2019.9.11-py37_0, anaconda/osx-64::conda-4.8.2-py37_0, defaults/osx-64::ca-certificates-2019.8.28-0, defaults/osx-64::openssl-1.1.1d-h1de35cc_2
  - anaconda/osx-64::ca-certificates-2019.8.28-0, anaconda/osx-64::certifi-2019.9.11-py37_0, anaconda/osx-64::conda-4.8.2-py37_0, defaults/osx-64::openssl-1.1.1d-h1de35cc_2
  ... and othedone

## Package Plan ##

  environment location: /opt/anaconda3

  added / updated specs:
    - pubchempy


The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    pubchempy-1.0.3            |             py_0          34 KB  jirinovo
    ------------------------------------------------------------
                                           Total:          34 KB

The following NEW packages will be INSTALLED:

  pubchempy          jirinovo/noarch::pubchempy-1.0.3-py_0



Downloading and Extracting Packages
pubchempy-1.0.3      | 34 KB     | ##################################### | 100% 
Preparing transaction: done
Verifying transaction: done
Executing transaction: done

Note: you may need to restart the kernel to use updated packages.
In [2]:
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 numpy as np
from IPython.display import display,Image
RDKit WARNING: [15:02:02] Enabling RDKit 2019.09.3 jupyter extensions
In [3]:
ibu=Chem.MolFromSmiles('CC(C)CC1=CC=C(C=C1)C(C)C(=O)O')
AllChem.Compute2DCoords(ibu)
display(ibu)
In [4]:
ibu=Chem.MolFromSmiles('CC(C)CC1=CC=C(C=C1)C(C)C(=O)[O-]')
import rdkit.Chem.Lipinski as Lipinksy
print(Lipinksy.NumHDonors(ibu))
print(Lipinksy.NumHAcceptors(ibu))
print(Lipinksy.rdMolDescriptors.CalcExactMolWt(ibu))
print(Lipinksy.rdMolDescriptors.CalcCrippenDescriptors(ibu)[0])
0
2
205.12340336391
1.7384999999999997
In [5]:
import pubchempy 
In [5]:
compounds = []
per_page = 10**5
for smiles in ["N=N=N", "NN#N",]:
    for i in range(200):
        try:
            a = pcp.get_properties(
              properties="CanonicalSMILES", 
              identifier=smiles, namespace="smiles", 
              searchtype="substructure",
              RingsNotEmbedded=True,
              listkey_count=per_page, listkey_start=i*per_page
            )
        except:
            print("Page {} returns 500, which is "
                   "our signal to stop.".format(i+1))
            break
        print("Retrieved page {} of {} search".format(i+1, smiles))
        compounds.extend(a)
Page 1 returns 500, which is our signal to stop.
Page 1 returns 500, which is our signal to stop.
In [6]:
strings=np.genfromtxt('1931431637611612961.txt',dtype=np.str)
smiles=[]
for line in strings:
    if len(line[1]) < 30 and not '.' in line[1]:
        smiles.append(line[1])
In [7]:
ibu_azid = 'N(N=N1)C=C1-C1=CC=C(C=C1)C(C)C(=O)O'
ibu_azid_show=Chem.MolFromSmiles("N(N=N1)C=C1-C1=CC=C(C=C1)C(C)C(=O)O")
AllChem.Compute2DCoords(ibu_azid_show)
display(ibu_azid_show)
In [12]:
azid = 'N=[N+]=[N-]'
good_mol=[]
for smi in smiles[:1500]:
    
    if azid in smi:
        newsmi=smi.replace(azid ,ibu_azid)
        print(newsmi)
    else:
        continue
    try:
        newmol=Chem.MolFromSmiles(newsmi)
        display(newmol)
        if (Lipinksy.NumHDonors(newmol)<=5) and (Lipinksy.NumHAcceptors(newmol)<=10) and (Lipinksy.rdMolDescriptors.CalcExactMolWt(newmol)<500) and (Lipinksy.rdMolDescriptors.CalcCrippenDescriptors(newmol)[0]<=5):
            AllChem.Compute2DCoords(newmol)
            good_mol.append(newmol)
    
        
            
            
    except:
        pass
In [10]:
Chem.Draw.MolsToGridImage(good_mol, maxMols = 20, molsPerRow = 4, subImgSize = (500, 300))
---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
<ipython-input-10-802dd376e721> in <module>
----> 1 Chem.Draw.MolsToGridImage(good_mol, maxMols = 20, molsPerRow = 4, subImgSize = (500, 300))

/opt/anaconda3/lib/python3.7/site-packages/rdkit/Chem/Draw/IPythonConsole.py in ShowMols(mols, maxMols, **kwargs)
    191       if prop in kwargs:
    192         kwargs[prop] = kwargs[prop][:maxMols]
--> 193   res = fn(mols, drawOptions=drawOptions, **kwargs)
    194   if kwargs['useSVG']:
    195     return SVG(res)

/opt/anaconda3/lib/python3.7/site-packages/rdkit/Chem/Draw/__init__.py in MolsToGridImage(mols, molsPerRow, subImgSize, legends, highlightAtomLists, highlightBondLists, useSVG, **kwargs)
    495     return _MolsToGridImage(mols, molsPerRow=molsPerRow, subImgSize=subImgSize, legends=legends,
    496                             highlightAtomLists=highlightAtomLists,
--> 497                             highlightBondLists=highlightBondLists, **kwargs)
    498 
    499 

/opt/anaconda3/lib/python3.7/site-packages/rdkit/Chem/Draw/__init__.py in _MolsToGridImage(mols, molsPerRow, subImgSize, legends, highlightAtomLists, highlightBondLists, drawOptions, **kwargs)
    443                       highlightBonds=highlightBondLists, **kwargs)
    444     d2d.FinishDrawing()
--> 445     res = _drawerToImage(d2d)
    446 
    447   return res

/opt/anaconda3/lib/python3.7/site-packages/rdkit/Chem/Draw/__init__.py in _drawerToImage(d2d)
    338     from PIL import Image
    339   sio = BytesIO(d2d.GetDrawingText())
--> 340   return Image.open(sio)
    341 
    342 

/opt/anaconda3/lib/python3.7/site-packages/PIL/Image.py in open(fp, mode)
   2816     for message in accept_warnings:
   2817         warnings.warn(message)
-> 2818     raise IOError("cannot identify image file %r" % (filename if filename else fp))
   2819 
   2820 

OSError: cannot identify image file <_io.BytesIO object at 0x118698d70>
In [ ]:
m3d=Chem.AddHs(good_mol[4])
Chem.AllChem.EmbedMolecule(m3d)
AllChem.MMFFOptimizeMolecule(m3d,maxIters=500,nonBondedThresh=200 )
m3d