Package: chembl-downloader
chembl_downloaderDon't worry about downloading/extracting ChEMBL or versioning - just usechembl_downloaderto write code that knows
how to download it and use it automatically.InstallationInstall with:$pipinstallchembl-downloaderFull technical documentation can be found onReadTheDocs. Tutorials can be found
in Jupyter notebooks in thenotebooks/directory of the
repository.Database UsageDownload A Specific Versionimportchembl_downloaderpath=chembl_downloader.download_extract_sqlite(version='28')After it's been downloaded and extracted once, it's smart and does not need to download again. It gets stored
usingpystowautomatically in the~/.data/chembldirectory.We'd like to implement something such that it could load directly into SQLite from the archive, but it appears this is
apaid feature.Download the Latest VersionYou can modify the previous code slightly by omitting theversionkeyword
argument to automatically find the latest version of ChEMBL:importchembl_downloaderpath=chembl_downloader.download_extract_sqlite()Theversionkeyword argument is available for all functions in this package (e.g., includingconnect(),cursor(), andquery()), but will be omitted below for brevity.Automate ConnectionInside the archive is a single SQLite database file. Normally, people manually untar this folder then do something with
the resulting file. Don't do this, it's not reproducible!
Instead, the file can be downloaded and a connection can be opened automatically with:importchembl_downloaderwithchembl_downloader.connect()asconn:withconn.cursor()ascursor:cursor.execute(...)# run your query stringrows=cursor.fetchall()# get your resultsThecursor()function provides a convenient wrapper around this operation:importchembl_downloaderwithchembl_downloader.cursor()ascursor:cursor.execute(...)# run your query stringrows=cursor.fetchall()# get your resultsRun a query and get a pandas DataFrameThe most powerful function isquery()which builds on the previousconnect()function in combination
withpandas.read_sqlto make a query and load the results into a pandas DataFrame for any downstream use.importchembl_downloadersql="""SELECTMOLECULE_DICTIONARY.chembl_id,MOLECULE_DICTIONARY.pref_nameFROM MOLECULE_DICTIONARYJOIN COMPOUND_STRUCTURES ON MOLECULE_DICTIONARY.molregno == COMPOUND_STRUCTURES.molregnoWHERE molecule_dictionary.pref_name IS NOT NULLLIMIT 5"""df=chembl_downloader.query(sql)df.to_csv(...,sep='\t',index=False)Suggestion 1: usepystowto make a reproducible file path that's portable to other people's machines
(e.g., it doesn't have your username in the path).Suggestion 2: RDKit is now pip-installable withpip install rdkit-pypi, which means most users don't have to muck
around with complicated conda environments and configurations. One of the powerful but understated tools in RDKit is
therdkit.Chem.PandasToolsmodule.SDF UsageAccess an RDKit supplier over entries in the SDF dumpThis example is a bit more fit-for-purpose than the last two. Thesupplier()function makes sure that the latest SDF
dump is downloaded and loads it from the gzip file into ardkit.Chem.ForwardSDMolSupplierusing a context manager to make sure the file doesn't get closed until after parsing is done. Like the previous
examples, it can also explicitly take aversion.fromrdkitimportChemimportchembl_downloaderwithchembl_downloader.supplier()assuppl:data=[]fori,molinenumerate(suppl):ifmolisNoneormol.GetNumAtoms()>50:continuefp=Chem.PatternFingerprint(mol,fpSize=1024,tautomerFingerprints=True)smi=Chem.MolToSmiles(mol)data.append((smi,fp))This example was adapted from Greg Landrum's RDKit blog post
ongeneralized substructure search.Iterate over SMILESThis example uses thesupplier()method and RDKit to get SMILES strings from molecules
in ChEMBL's SDF file. If you want direct access to the RDKit molecule objects, usesupplier().importchembl_downloaderforsmilesinchembl_downloader.iterate_smiles():print(smiles)Get an RDKit substructure libraryBuilding on thesupplier()function, theget_substructure_library()makes the preparation of asubstructure libraryautomated and reproducible. Additionally, it caches the results of the build,
which takes on the order of tens of minutes, only has to be done once and future
loading from a pickle object takes on the order of seconds.The implementation was inspired by Greg Landrum's RDKit blog post,Some new features in the SubstructLibrary.
The following example shows how it can be used to accomplish some of the first
tasks presented in the post:fromrdkitimportChemimportchembl_downloaderlibrary=chembl_downloader.get_substructure_library()query=Chem.MolFromSmarts('[O,N]=C-c:1:c:c:n:c:c:1')matches=library.GetMatches(query)Morgan Fingerprints UsageGet the Morgan Fingerprint fileChEMBL makes a file containing pre-computed 2048 bit radius 2 morgan
fingerprints for each molecule available. It can be downloaded using:importchembl_downloaderpath=chembl_downloader.download_fps()Theversionand other keyword arguments are also valid for this function.Load fingerprints withchemfpThe following wraps thedownload_fpsfunction withchemfp's fingerprint
loader:importchembl_downloaderarena=chembl_downloader.chemfp_load_fps()Theversionand other keyword arguments are also valid for this function.
More information on working with thearenaobject can be foundhere.ExtrasStore in a Different PlaceIf you want to store the data elsewhere usingpystow(e.g., inpyoboI also keep a copy of this file), you can use theprefixargument.importchembl_downloader# It gets downloaded/extracted to# ~/.data/pyobo/raw/chembl/29/chembl_29/chembl_29_sqlite/chembl_29.dbpath=chembl_downloader.download_extract_sqlite(prefix=['pyobo','raw','chembl'])See thepystowdocumentationon configuring the storage
location further.Theprefixkeyword argument is available for all functions in this package (e.g., includingconnect(),cursor(), andquery()).Download via CLIAfter installing, run the following CLI command to ensure it and send the path to stdout$chembl_downloaderUse--testto show two example queries$chembl_downloader--testContributingPlease read the contribution guidelines inCONTRIBUTING.md.If you'd like to contribute, there's a submodule calledchembl_downloader.querieswhere you can add a useful SQL queries along with a description of what it does for easy
importing and reuse.UsersSeewho's usingchembl-downloader.Statistics and Compatibilitychembl-downloaderis compatible with all versions of ChEMBL. However, some files are
not available for all versions. For example, the SQLite version of the database was first
added in release 21 (2015-02-12).ChEMBL VersionRelease DateTotal Named Compoundsfrom SQLite312022-07-1241,585302022-02-2241,549292021-07-0141,383282021-01-1541,049272020-05-1840,834262020-02-1440,822252019-02-0139,88524_12018-05-0139,87724232017-05-1839,58422_12016-11-172239,422212015-02-1239,347202015-02-03-192014-07-2333-182014-04-02-172013-09-16-162013-055555-15-152013-01-30-142012 -07-18-132012-02-29-122011-11-30-112011-06-07-102011-06-07-092011-01-04-082010-11-05-072010-09-03-062010-09-03-052010-06-07-042010-05-26-032010-04-30-022009-12-07-012009-10-28-