chembl_webresource_client - Usage Examples

This section provides a tutorial example to install chembl_webresource_client, the Official Python client for accessing ChEMBL API.

With chembl_webresource_client installed, you can try some examples.

1. Get details of a given molecule:

herong$ python3

from chembl_webresource_client.new_client import new_client
molecule = new_client.molecule.get('BSYNRYMUTXBXSQ-UHFFFAOYSA-N')
print(molecule)
{'atc_classifications': ['N02BA01', 'N02BA51', 'N02BA71', 'A01AD05',
'B01AC06'], 'availability_type': '2', 'biotherapeutic': None,
'black_box_warning': '0', 'chebi_par_id': 15365, 'chirality': '2',
'cross_references': [{'xref_id': 'aspirin', 'xref_name': 'aspirin',
...

2. Get the PNG image of the 2D representation of a given molecule and save it to a file. You can open the test.png file in an image viewer to see it.

herong$ python3

from chembl_webresource_client.new_client import new_client
image = new_client.image.get('CHEMBL25')
file = open("test.png", 'wb')
file.write(image)
file.close()

3. Search for all approved drugs and get them in JSON format:

herong$ python3

from chembl_webresource_client.new_client import new_client
molecule = new_client.molecule
approved_drugs = molecule.filter(max_phase=4)
print(approved_drugs)
[{'atc_classifications': ['C02CA01'], 'availability_type': '1',
'biotherapeutic': None, 'black_box_warning': '0', 'chebi_par_id': 8364,
'chirality': '2', 'cross_references': [{'xref_id': '50104272',
'xref_name': 'SID: 50104272', 'xref_src': 'PubChem'},
{'xref_id': '50100502', 'xref_name': 'SID: 50100502',
...

3. Search for all approved drugs and save them in SDF format:

herong$ python3

from chembl_webresource_client.new_client import new_client
molecule = new_client.molecule
molecule.set_format('sdf')
mols = molecule.filter(max_phase=4)

with open('test.sdf', 'wb') as output:
  for mol in mols:
    output.write(mol)
    output.write(b'$$$$\n')

4. Converting to 3D SDF (also called CTAB, Connection Table) from a given 2D SDF file:

from chembl_webresource_client.utils import utils
with open('test-3d.sdf', 'w') as output:
  with open('test.sdf', 'r') as input:
    mols = input.read().split('$$$$\n')
    for mol in mols:
      mol_3D = utils.ctab23D(mol)
      output.write(mol_3D)

5. Converting SMILES to SDF, then to SVG.

from chembl_webresource_client.utils import utils
sdf = utils.smiles2ctab("c1(C=O)cc(OC)c(O)cc1")
svg = utils.ctab2svg(sdf)
print svg
"<?xml version='1.0' encoding='iso-8859-1'?>\n<svg:svg version='1.1'
  baseProfile='full'\n  xmlns:svg='http://www.w3.org/2000/svg'\n
  xmlns:rdkit='http://www.rdkit.org/xml'\n
  xmlns:xlink='http://www.w3.org/1999/xlink'\n
  xml:space='preserve'\nwidth='200px' height='200px' >\n
<svg:rect style='opacity:1.0;fill:#FFFFFF;stroke:none'
  width='200' height='200' x='0' y='0'> </svg:rect>\n
  <svg:path d='M 134.556,74.8299 176.377,82.1956'
    style='fill:none;fill-rule:evenodd;stroke:#000000;...

Table of Contents

 About This Book

 Introduction of Molecules

 Molecule Names and Identifications

 Molecule Mass and Weight

 Protein and Amino Acid

 Nucleobase, Nucleoside, Nucleotide, DNA and RNA

 Gene and Chromosome

 Protein Kinase (PK)

 DNA Sequencing

 Gene Mutation

 SDF (Structure Data File)

 PyMol Installation

 PyMol GUI and CLI

 PyMol Selections

 PyMol Editing Functions

 PyMol Measurement Functions

 PyMol Movie Functions

 PyMol Python Integration

 PyMol Object Functions

ChEMBL Database - European Molecular Biology Laboratory

 What Is ChEMBL

 ChEMBL Speical Web Portals

 Download ChEMBL Database

 ChEMBL FTP Repository

 ChEMBL Web Services API

 Call ChEMBL Data Web Service Directly

 ChEMBL Data Resource - molecule

 ChEMBL Data Resource - activity

 ChEMBL Data Resource - assay

 ChEMBL Data Resource - document

 ChEMBL Data Resource - target

 ChEMBL Data Resource - chembl_id_lookup

 ChEMBL Related Tools

 chembl_webresource_client - Python Client

chembl_webresource_client - Usage Examples

 chembl_webresource_client - RetryError Exception

 ChEMBL Terminologies

 PubChem Database - National Library of Medicine

 PDB (Protein Data Bank)

 INSDC (International Nucleotide Sequence Database Collaboration)

 HGNC (HUGO Gene Nomenclature Committee)

 Relocated Tutorials

 Resources and Tools

 Molecule Related Terminologies

 References

 Full Version in PDF/EPUB