Skip to main content

Get Chemical SMILES Strings Based on CAS Numbers or Names

ยท 3 min read
Kuan Huang

Here we have a few sets of codes that you can use to find chemical SMILES strings (structures) if you already know the CAS numbers or the names of your chemicals. Although there are many sources available for us to get SMILES strings, mostly they will not cover all your chemicals if you have a lot. In such cases, checking multiple sources/databases becomes necessary.

This tutorial has also been uploaded in our GitHub page at:, where you can also download additional files for your needs.

In this tutorial, we present four ways to obtain SMILES strings, the first one being using an available Python library called CIRpy, while the second to the fourth ones being three very popular websites that are built on very large databases, including,, and

Please find all the codes in one single JupyterNotebook called get-chemical-smiles-by-cas-or-name.ipynb in the src folder in our GitHub page for details.

Python library CIRpy

CIRpy is a Python interface for the Chemical Identifier Resolver (CIR) by the CADD Group at the NCI/NIH. It is a very powerful tool that can resolve any chemical identifier to another chemical representation. For example, from CAS number to name, SMILES, or from name to SMILES:

>>> import cirpy
>>> cirpy.resolve('Aspirin', 'smiles')
>>> cirpy.resolve('108-95-2', 'smiles')
>>> cirpy.resolve('Oc1ccccc1', 'cas')

The installation is simple:

pip install cirpy

For more info about CIRpy, please refer to


The website is another powerful and easy-to-use source for looking for SMILES strings if CAS numbers are given. To use it, simply add the CAS number in the url as shown below. Then open the url with urllib.request.urlopen, and the decoded content would then be the SMILES string.

>>> from urllib.request import urlopen
>>> cas = '108-95-2'
>>> url = '' + cas + '/smiles'
>>> smiles = urlopen(url).read().decode('utf8')
>>> smiles


The website is another useful source we have been using. To use it, we first go to the address using the library selenium. Then use the find_element_by_xpath command to find the search box, and input the CAS number into the search box. Upon submit, we follow a few more steps to extract the SMILES string (if available) mainly using selenium and re (regular expression) to identify the target content.

These steps control the automatic opening and closing of the web browser, which usually takes some time to get the job done. For more information, please refer to the JupyterNotebook get-chemical-smiles-by-cas-or-name.ipynb in the src folder.


Similarly, we can also scrape the website following the same steps to get the SMILES strings based on CAS numbers. Details can be found in the JupyterNotebook get-chemical-smiles-by-cas-or-name.ipynb in the src folder in our GitHub page. For example:

from urllib.request import urlopen
from selenium import webdriver

url = ""
CAS = '108-95-2'
driver = webdriver.Chrome(ChromeDriverManager().install())
search_box = driver.find_element_by_id("quick_search_input")
links = driver.find_elements_by_xpath('//*[@id="resultArea"]/div[2]/div/table/tbody/tr/td[1]/a')
href = links[0].get_attribute("href")
website = urlopen(href).read().decode('utf8')
details ='<th>Smiles</th><td>.*', website)
details =
smiles = details[details.find('</th><td>') + 9: -5]

print('No results found')

The output would then be