CAS Common Chemistry API#

About this interactive icons recipe
  • Author: Vincent Scalfani

  • Reviewer: Stuart Chalk

  • Topics: How to interact with the CAS Common Chemistry API using Python.

  • Attribution: Adapted from the MIT licensed University of Alabama Scholarly API Cookbook Use of the CAS Common Chemistry API requires registration: https://www.cas.org/services/commonchemistry-api. Example data shown is credited to CAS Common Chemistry, which is licensed under the CC BY-NC 4.0 license.

  • Format: Interactive Jupyter Notebook (Python)

  • Scenarios: You are search for identifiers and general property of common chemical substances.

  • Skills: You should be familiar with

  • Learning outcomes: After completing this example you should understand:

    • What kind of data is available through the CAS Common Chemistry API

    • How to interact with the CAS Common Chemistry API using Python

  • Citation: ‘CAS Common Chemistry API’, Vincent Scalfani, The IUPAC FAIR Chemistry Cookbook, Contributed: 2024-02-14 https://w3id.org/ifcc/IFCC011.

  • Reuse: This notebook is made available under a CC-BY-4.0 license.

1. Common Chemistry Record Detail Retrieval#

Information about substances in CAS Common Chemistry can be retrieved using the /detail API and a CAS RN identifier:

Import libraries#

import requests
from pprint import pprint

Setup API parameters#

detail_base_url = "https://commonchemistry.cas.org/api/detail?"
casrn1 = "10094-36-7" # ethyl cyclohexanepropionate

Request data from CAS Common Chemistry Detail API#

casrn1_data = requests.get(detail_base_url + "cas_rn=" + casrn1).json()
pprint(casrn1_data)
{'canonicalSmile': 'O=C(OCC)CCC1CCCCC1',
 'experimentalProperties': [{'name': 'Boiling Point',
                             'property': '105-113 °C @ Press: 17 Torr',
                             'sourceNumber': 1}],
 'hasMolfile': True,
 'image': '<svg width="215" viewBox="0 0 215 101" style="fill-opacity:1; '
          'color-rendering:auto; color-interpolation:auto; '
          'text-rendering:auto; stroke:black; stroke-linecap:square; '
          'stroke-miterlimit:10; shape-rendering:auto; stroke-opacity:1; '
          'fill:black; stroke-dasharray:none; font-weight:normal; '
          "stroke-width:1; font-family:'Open Sans'; font-style:normal; "
          'stroke-linejoin:miter; font-size:12; stroke-dashoffset:0; '
          'image-rendering:auto;" height="101" class="cas-substance-image" '
          'xmlns:xlink="http://www.w3.org/1999/xlink" '
          'xmlns="http://www.w3.org/2000/svg"><svg '
          'class="cas-substance-single-component"><rect y="0" x="0" '
          'width="215" stroke="none" ry="7" rx="7" height="101" fill="white" '
          'class="cas-substance-group"/><svg y="0" x="0" width="215" '
          'viewBox="0 0 215 101" style="fill:black;" height="101" '
          'class="cas-substance-single-component-image"><svg><g><g '
          'transform="translate(107,49)" '
          'style="text-rendering:geometricPrecision; '
          'color-rendering:optimizeQuality; color-interpolation:linearRGB; '
          'stroke-linecap:butt; image-rendering:optimizeQuality;"><line y2="0" '
          'y1="15" x2="0" x1="-25.98" style="fill:none;"/><line y2="0" y1="15" '
          'x2="-51.963" x1="-25.98" style="fill:none;"/><line y2="15" y1="0" '
          'x2="25.98" x1="0" style="fill:none;"/><line y2="3.1886" y1="15" '
          'x2="46.4398" x1="25.98" style="fill:none;"/><line y2="38.5234" '
          'y1="13.9896" x2="24.23" x1="24.23" style="fill:none;"/><line '
          'y2="38.5234" y1="13.9897" x2="27.73" x1="27.73" '
          'style="fill:none;"/><line y2="15" y1="3.1786" x2="77.943" '
          'x1="57.4684" style="fill:none;"/><line y2="0" y1="15" x2="103.923" '
          'x1="77.943" style="fill:none;"/><line y2="15" y1="0" x2="-77.943" '
          'x1="-51.963" style="fill:none;"/><line y2="-30" y1="0" x2="-51.963" '
          'x1="-51.963" style="fill:none;"/><line y2="0" y1="15" x2="-103.923" '
          'x1="-77.943" style="fill:none;"/><line y2="-45" y1="-30" '
          'x2="-77.943" x1="-51.963" style="fill:none;"/><line y2="-30" y1="0" '
          'x2="-103.923" x1="-103.923" style="fill:none;"/><line y2="-30" '
          'y1="-45" x2="-103.923" x1="-77.943" style="fill:none;"/><path '
          'style="fill:none; stroke-miterlimit:5;" d="M-25.547 14.75 L-25.98 '
          '15 L-26.413 14.75"/><path style="fill:none; stroke-miterlimit:5;" '
          'd="M-0.433 0.25 L0 0 L0.433 0.25"/><path style="fill:none; '
          'stroke-miterlimit:5;" d="M25.547 14.75 L25.98 15 L26.413 '
          '14.75"/></g><g transform="translate(107,49)" '
          'style="stroke-linecap:butt; fill:rgb(230,0,0); '
          'text-rendering:geometricPrecision; color-rendering:optimizeQuality; '
          "image-rendering:optimizeQuality; font-family:'Open Sans'; "
          'stroke:rgb(230,0,0); color-interpolation:linearRGB; '
          'stroke-miterlimit:5;"><path style="stroke:none;" d="M55.9005 '
          '-0.0703 Q55.9005 1.9922 54.8614 3.1719 Q53.8224 4.3516 51.9786 '
          '4.3516 Q50.088 4.3516 49.0568 3.1875 Q48.0255 2.0234 48.0255 '
          '-0.0859 Q48.0255 -2.1797 49.0568 -3.3281 Q50.088 -4.4766 51.9786 '
          '-4.4766 Q53.838 -4.4766 54.8693 -3.3047 Q55.9005 -2.1328 55.9005 '
          '-0.0703 ZM49.0724 -0.0703 Q49.0724 1.6641 49.8146 2.5703 Q50.5568 '
          '3.4766 51.9786 3.4766 Q53.4005 3.4766 54.1271 2.5781 Q54.8536 '
          '1.6797 54.8536 -0.0703 Q54.8536 -1.8047 54.1271 -2.6953 Q53.4005 '
          '-3.5859 51.9786 -3.5859 Q50.5568 -3.5859 49.8146 -2.6875 Q49.0724 '
          '-1.7891 49.0724 -0.0703 Z"/><path style="stroke:none;" d="M29.9175 '
          '44.9297 Q29.9175 46.9922 28.8784 48.1719 Q27.8394 49.3516 25.9956 '
          '49.3516 Q24.105 49.3516 23.0737 48.1875 Q22.0425 47.0234 22.0425 '
          '44.9141 Q22.0425 42.8203 23.0737 41.6719 Q24.105 40.5234 25.9956 '
          '40.5234 Q27.855 40.5234 28.8862 41.6953 Q29.9175 42.8672 29.9175 '
          '44.9297 ZM23.0894 44.9297 Q23.0894 46.6641 23.8316 47.5703 Q24.5737 '
          '48.4766 25.9956 48.4766 Q27.4175 48.4766 28.1441 47.5781 Q28.8706 '
          '46.6797 28.8706 44.9297 Q28.8706 43.1953 28.1441 42.3047 Q27.4175 '
          '41.4141 25.9956 41.4141 Q24.5737 41.4141 23.8316 42.3125 Q23.0894 '
          '43.2109 23.0894 44.9297 Z"/><path style="fill:none; stroke:black;" '
          'd="M77.51 14.75 L77.943 15 L78.376 14.75"/><path style="fill:none; '
          'stroke:black;" d="M-77.51 14.75 L-77.943 15 L-78.376 14.75"/><path '
          'style="fill:none; stroke:black;" d="M-51.963 -29.5 L-51.963 -30 '
          'L-52.396 -30.25"/><path style="fill:none; stroke:black;" '
          'd="M-103.49 0.25 L-103.923 0 L-103.923 -0.5"/><path '
          'style="fill:none; stroke:black;" d="M-77.51 -44.75 L-77.943 -45 '
          'L-78.376 -44.75"/><path style="fill:none; stroke:black;" '
          'd="M-103.923 -29.5 L-103.923 -30 L-103.49 '
          '-30.25"/></g></g></svg></svg></svg></svg>',
 'inchi': 'InChI=1S/C11H20O2/c1-2-13-11(12)9-8-10-6-4-3-5-7-10/h10H,2-9H2,1H3',
 'inchiKey': 'InChIKey=NRVPMFHPHGBQLP-UHFFFAOYSA-N',
 'molecularFormula': 'C<sub>11</sub>H<sub>20</sub>O<sub>2</sub>',
 'molecularMass': '184.28',
 'name': 'Ethyl cyclohexanepropionate',
 'propertyCitations': [{'docUri': 'document/pt/document/22252593',
                        'source': 'De Benneville, Peter L.; Journal of the '
                                  'American Chemical Society, (1940), 62, '
                                  '283-7, CAplus',
                        'sourceNumber': 1}],
 'replacedRns': [],
 'rn': '10094-36-7',
 'smile': 'C(CC(OCC)=O)C1CCCCC1',
 'synonyms': ['Cyclohexanepropanoic acid, ethyl ester',
              'Cyclohexanepropionic acid, ethyl ester',
              'Ethyl cyclohexanepropionate',
              'Ethyl cyclohexylpropanoate',
              'Ethyl 3-cyclohexylpropionate',
              'Ethyl 3-cyclohexylpropanoate',
              '3-Cyclohexylpropionic acid ethyl ester',
              'NSC 71463',
              'Ethyl 3-cyclohexanepropionate'],
 'uri': 'substance/pt/10094367'}

Display the Molecule Drawing#

# get svg image text
svg_string1 = casrn1_data["image"]

# display the molecule
from IPython.display import SVG
SVG(svg_string1)
../_images/dc483030f9cbc340140eaffa8fd3d845e828bd0d9291a6e8920e236e4a31115b.svg

Select some specific data#

# Get Experimental Properties
casrn1_data["experimentalProperties"][0]
{'name': 'Boiling Point',
 'property': '105-113 °C @ Press: 17 Torr',
 'sourceNumber': 1}
# Get Boiling Point property
casrn1_data["experimentalProperties"][0]["property"]
'105-113 °C @ Press: 17 Torr'
# Get InChIKey
casrn1_data["inchiKey"]
'InChIKey=NRVPMFHPHGBQLP-UHFFFAOYSA-N'
# Get Canonical SMILES
casrn1_data["canonicalSmile"]
'O=C(OCC)CCC1CCCCC1'

2. Common Chemistry API record detail retrieval in a loop#

Import libraries#

import requests
from pprint import pprint
from time import sleep

Setup API parameters#

detail_base_url = "https://commonchemistry.cas.org/api/detail?"
casrn_list = ["10094-36-7", "10031-92-2", "10199-61-8", "10036-21-2", "1019020-13-3"]

Request data for each CAS RN and save to a list#

casrn_data = []
for casrn in casrn_list:
    casrn_data.append(requests.get(detail_base_url + "cas_rn=" + casrn).json())
    sleep(1) # add a delay between API calls
casrn_data[0:2] # view first 2
[{'uri': 'substance/pt/10094367',
  'rn': '10094-36-7',
  'name': 'Ethyl cyclohexanepropionate',
  'image': '<svg width="215" viewBox="0 0 215 101" style="fill-opacity:1; color-rendering:auto; color-interpolation:auto; text-rendering:auto; stroke:black; stroke-linecap:square; stroke-miterlimit:10; shape-rendering:auto; stroke-opacity:1; fill:black; stroke-dasharray:none; font-weight:normal; stroke-width:1; font-family:\'Open Sans\'; font-style:normal; stroke-linejoin:miter; font-size:12; stroke-dashoffset:0; image-rendering:auto;" height="101" class="cas-substance-image" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg"><svg class="cas-substance-single-component"><rect y="0" x="0" width="215" stroke="none" ry="7" rx="7" height="101" fill="white" class="cas-substance-group"/><svg y="0" x="0" width="215" viewBox="0 0 215 101" style="fill:black;" height="101" class="cas-substance-single-component-image"><svg><g><g transform="translate(107,49)" style="text-rendering:geometricPrecision; color-rendering:optimizeQuality; color-interpolation:linearRGB; stroke-linecap:butt; image-rendering:optimizeQuality;"><line y2="0" y1="15" x2="0" x1="-25.98" style="fill:none;"/><line y2="0" y1="15" x2="-51.963" x1="-25.98" style="fill:none;"/><line y2="15" y1="0" x2="25.98" x1="0" style="fill:none;"/><line y2="3.1886" y1="15" x2="46.4398" x1="25.98" style="fill:none;"/><line y2="38.5234" y1="13.9896" x2="24.23" x1="24.23" style="fill:none;"/><line y2="38.5234" y1="13.9897" x2="27.73" x1="27.73" style="fill:none;"/><line y2="15" y1="3.1786" x2="77.943" x1="57.4684" style="fill:none;"/><line y2="0" y1="15" x2="103.923" x1="77.943" style="fill:none;"/><line y2="15" y1="0" x2="-77.943" x1="-51.963" style="fill:none;"/><line y2="-30" y1="0" x2="-51.963" x1="-51.963" style="fill:none;"/><line y2="0" y1="15" x2="-103.923" x1="-77.943" style="fill:none;"/><line y2="-45" y1="-30" x2="-77.943" x1="-51.963" style="fill:none;"/><line y2="-30" y1="0" x2="-103.923" x1="-103.923" style="fill:none;"/><line y2="-30" y1="-45" x2="-103.923" x1="-77.943" style="fill:none;"/><path style="fill:none; stroke-miterlimit:5;" d="M-25.547 14.75 L-25.98 15 L-26.413 14.75"/><path style="fill:none; stroke-miterlimit:5;" d="M-0.433 0.25 L0 0 L0.433 0.25"/><path style="fill:none; stroke-miterlimit:5;" d="M25.547 14.75 L25.98 15 L26.413 14.75"/></g><g transform="translate(107,49)" style="stroke-linecap:butt; fill:rgb(230,0,0); text-rendering:geometricPrecision; color-rendering:optimizeQuality; image-rendering:optimizeQuality; font-family:\'Open Sans\'; stroke:rgb(230,0,0); color-interpolation:linearRGB; stroke-miterlimit:5;"><path style="stroke:none;" d="M55.9005 -0.0703 Q55.9005 1.9922 54.8614 3.1719 Q53.8224 4.3516 51.9786 4.3516 Q50.088 4.3516 49.0568 3.1875 Q48.0255 2.0234 48.0255 -0.0859 Q48.0255 -2.1797 49.0568 -3.3281 Q50.088 -4.4766 51.9786 -4.4766 Q53.838 -4.4766 54.8693 -3.3047 Q55.9005 -2.1328 55.9005 -0.0703 ZM49.0724 -0.0703 Q49.0724 1.6641 49.8146 2.5703 Q50.5568 3.4766 51.9786 3.4766 Q53.4005 3.4766 54.1271 2.5781 Q54.8536 1.6797 54.8536 -0.0703 Q54.8536 -1.8047 54.1271 -2.6953 Q53.4005 -3.5859 51.9786 -3.5859 Q50.5568 -3.5859 49.8146 -2.6875 Q49.0724 -1.7891 49.0724 -0.0703 Z"/><path style="stroke:none;" d="M29.9175 44.9297 Q29.9175 46.9922 28.8784 48.1719 Q27.8394 49.3516 25.9956 49.3516 Q24.105 49.3516 23.0737 48.1875 Q22.0425 47.0234 22.0425 44.9141 Q22.0425 42.8203 23.0737 41.6719 Q24.105 40.5234 25.9956 40.5234 Q27.855 40.5234 28.8862 41.6953 Q29.9175 42.8672 29.9175 44.9297 ZM23.0894 44.9297 Q23.0894 46.6641 23.8316 47.5703 Q24.5737 48.4766 25.9956 48.4766 Q27.4175 48.4766 28.1441 47.5781 Q28.8706 46.6797 28.8706 44.9297 Q28.8706 43.1953 28.1441 42.3047 Q27.4175 41.4141 25.9956 41.4141 Q24.5737 41.4141 23.8316 42.3125 Q23.0894 43.2109 23.0894 44.9297 Z"/><path style="fill:none; stroke:black;" d="M77.51 14.75 L77.943 15 L78.376 14.75"/><path style="fill:none; stroke:black;" d="M-77.51 14.75 L-77.943 15 L-78.376 14.75"/><path style="fill:none; stroke:black;" d="M-51.963 -29.5 L-51.963 -30 L-52.396 -30.25"/><path style="fill:none; stroke:black;" d="M-103.49 0.25 L-103.923 0 L-103.923 -0.5"/><path style="fill:none; stroke:black;" d="M-77.51 -44.75 L-77.943 -45 L-78.376 -44.75"/><path style="fill:none; stroke:black;" d="M-103.923 -29.5 L-103.923 -30 L-103.49 -30.25"/></g></g></svg></svg></svg></svg>',
  'inchi': 'InChI=1S/C11H20O2/c1-2-13-11(12)9-8-10-6-4-3-5-7-10/h10H,2-9H2,1H3',
  'inchiKey': 'InChIKey=NRVPMFHPHGBQLP-UHFFFAOYSA-N',
  'smile': 'C(CC(OCC)=O)C1CCCCC1',
  'canonicalSmile': 'O=C(OCC)CCC1CCCCC1',
  'molecularFormula': 'C<sub>11</sub>H<sub>20</sub>O<sub>2</sub>',
  'molecularMass': '184.28',
  'experimentalProperties': [{'name': 'Boiling Point',
    'property': '105-113 °C @ Press: 17 Torr',
    'sourceNumber': 1}],
  'propertyCitations': [{'docUri': 'document/pt/document/22252593',
    'sourceNumber': 1,
    'source': 'De Benneville, Peter L.; Journal of the American Chemical Society, (1940), 62, 283-7, CAplus'}],
  'synonyms': ['Cyclohexanepropanoic acid, ethyl ester',
   'Cyclohexanepropionic acid, ethyl ester',
   'Ethyl cyclohexanepropionate',
   'Ethyl cyclohexylpropanoate',
   'Ethyl 3-cyclohexylpropionate',
   'Ethyl 3-cyclohexylpropanoate',
   '3-Cyclohexylpropionic acid ethyl ester',
   'NSC 71463',
   'Ethyl 3-cyclohexanepropionate'],
  'replacedRns': [],
  'hasMolfile': True},
 {'uri': 'substance/pt/10031922',
  'rn': '10031-92-2',
  'name': 'Ethyl 2-nonynoate',
  'image': '<svg width="292" viewBox="0 0 292 86" style="fill-opacity:1; color-rendering:auto; color-interpolation:auto; text-rendering:auto; stroke:black; stroke-linecap:square; stroke-miterlimit:10; shape-rendering:auto; stroke-opacity:1; fill:black; stroke-dasharray:none; font-weight:normal; stroke-width:1; font-family:\'Open Sans\'; font-style:normal; stroke-linejoin:miter; font-size:12; stroke-dashoffset:0; image-rendering:auto;" height="86" class="cas-substance-image" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg"><svg class="cas-substance-single-component"><rect y="0" x="0" width="292" stroke="none" ry="7" rx="7" height="86" fill="white" class="cas-substance-group"/><svg y="0" x="0" width="292" viewBox="0 0 292 86" style="fill:black;" height="86" class="cas-substance-single-component-image"><svg><g><g transform="translate(146,41)" style="text-rendering:geometricPrecision; color-rendering:optimizeQuality; color-interpolation:linearRGB; stroke-linecap:butt; image-rendering:optimizeQuality;"><line y2="-7.5" y1="7.5" x2="-38.97" x1="-64.953" style="fill:none;"/><line y2="-4.3214" y1="7.5" x2="-85.4276" x1="-64.953" style="fill:none;"/><line y2="31.0234" y1="6.4896" x2="-66.703" x1="-66.703" style="fill:none;"/><line y2="31.0234" y1="6.4897" x2="-63.203" x1="-63.203" style="fill:none;"/><line y2="-22.5" y1="-7.5" x2="-12.99" x1="-38.97" style="fill:none;"/><line y2="-25.5311" y1="-10.5311" x2="-14.74" x1="-40.72" style="fill:none;"/><line y2="-19.4689" y1="-4.4689" x2="-11.24" x1="-37.22" style="fill:none;"/><line y2="7.5" y1="-4.3112" x2="-116.913" x1="-96.456" style="fill:none;"/><line y2="-37.5" y1="-22.5" x2="12.99" x1="-12.99" style="fill:none;"/><line y2="-7.5" y1="7.5" x2="-142.893" x1="-116.913" style="fill:none;"/><line y2="-22.5" y1="-37.5" x2="38.97" x1="12.99" style="fill:none;"/><line y2="-37.5" y1="-22.5" x2="64.953" x1="38.97" style="fill:none;"/><line y2="-22.5" y1="-37.5" x2="90.933" x1="64.953" style="fill:none;"/><line y2="-37.5" y1="-22.5" x2="116.913" x1="90.933" style="fill:none;"/><line y2="-22.5" y1="-37.5" x2="142.893" x1="116.913" style="fill:none;"/><path style="fill:none; stroke-miterlimit:5;" d="M-64.52 7.25 L-64.953 7.5 L-65.386 7.25"/><path style="fill:none; stroke-miterlimit:5;" d="M-39.403 -7.25 L-38.97 -7.5 L-38.537 -7.75"/></g><g transform="translate(146,41)" style="stroke-linecap:butt; fill:rgb(230,0,0); text-rendering:geometricPrecision; color-rendering:optimizeQuality; image-rendering:optimizeQuality; font-family:\'Open Sans\'; stroke:rgb(230,0,0); color-interpolation:linearRGB; stroke-miterlimit:5;"><path style="stroke:none;" d="M-86.9955 -7.5703 Q-86.9955 -5.5078 -88.0346 -4.3281 Q-89.0736 -3.1484 -90.9174 -3.1484 Q-92.808 -3.1484 -93.8392 -4.3125 Q-94.8705 -5.4766 -94.8705 -7.5859 Q-94.8705 -9.6797 -93.8392 -10.8281 Q-92.808 -11.9766 -90.9174 -11.9766 Q-89.058 -11.9766 -88.0267 -10.8047 Q-86.9955 -9.6328 -86.9955 -7.5703 ZM-93.8236 -7.5703 Q-93.8236 -5.8359 -93.0814 -4.9297 Q-92.3392 -4.0234 -90.9174 -4.0234 Q-89.4955 -4.0234 -88.7689 -4.9219 Q-88.0424 -5.8203 -88.0424 -7.5703 Q-88.0424 -9.3047 -88.7689 -10.1953 Q-89.4955 -11.0859 -90.9174 -11.0859 Q-92.3392 -11.0859 -93.0814 -10.1875 Q-93.8236 -9.2891 -93.8236 -7.5703 Z"/><path style="stroke:none;" d="M-61.0155 37.4297 Q-61.0155 39.4922 -62.0546 40.6719 Q-63.0936 41.8516 -64.9374 41.8516 Q-66.828 41.8516 -67.8593 40.6875 Q-68.8905 39.5234 -68.8905 37.4141 Q-68.8905 35.3203 -67.8593 34.1719 Q-66.828 33.0234 -64.9374 33.0234 Q-63.078 33.0234 -62.0468 34.1953 Q-61.0155 35.3672 -61.0155 37.4297 ZM-67.8436 37.4297 Q-67.8436 39.1641 -67.1014 40.0703 Q-66.3593 40.9766 -64.9374 40.9766 Q-63.5155 40.9766 -62.7889 40.0781 Q-62.0624 39.1797 -62.0624 37.4297 Q-62.0624 35.6953 -62.7889 34.8047 Q-63.5155 33.9141 -64.9374 33.9141 Q-66.3593 33.9141 -67.1014 34.8125 Q-67.8436 35.7109 -67.8436 37.4297 Z"/><path style="fill:none; stroke:black;" d="M-116.48 7.25 L-116.913 7.5 L-117.346 7.25"/><path style="fill:none; stroke:black;" d="M12.557 -37.25 L12.99 -37.5 L13.423 -37.25"/><path style="fill:none; stroke:black;" d="M38.537 -22.75 L38.97 -22.5 L39.403 -22.75"/><path style="fill:none; stroke:black;" d="M64.52 -37.25 L64.953 -37.5 L65.386 -37.25"/><path style="fill:none; stroke:black;" d="M90.5 -22.75 L90.933 -22.5 L91.366 -22.75"/><path style="fill:none; stroke:black;" d="M116.48 -37.25 L116.913 -37.5 L117.346 -37.25"/></g></g></svg></svg></svg></svg>',
  'inchi': 'InChI=1S/C11H18O2/c1-3-5-6-7-8-9-10-11(12)13-4-2/h3-8H2,1-2H3',
  'inchiKey': 'InChIKey=BFZNMUGAZYAMTG-UHFFFAOYSA-N',
  'smile': 'C(C#CCCCCCC)(OCC)=O',
  'canonicalSmile': 'O=C(C#CCCCCCC)OCC',
  'molecularFormula': 'C<sub>11</sub>H<sub>18</sub>O<sub>2</sub>',
  'molecularMass': '182.26',
  'experimentalProperties': [],
  'propertyCitations': [],
  'synonyms': ['2-Nonynoic acid, ethyl ester',
   'Ethyl 2-nonynoate',
   'NSC 190985'],
  'replacedRns': [],
  'hasMolfile': True}]

Display Molecule Drawings#

from IPython.display import SVG
# get svg image text
svg_strings = []
for svg_idx in range(len(casrn_data)):
    svg_strings.append(casrn_data[svg_idx]["image"])

# display the molecules
for svg_string in svg_strings:
    display(SVG(svg_string))
../_images/dc483030f9cbc340140eaffa8fd3d845e828bd0d9291a6e8920e236e4a31115b.svg../_images/1e7bde96360cba6744881b59b890ccc10eeb40a000a61c2203c8cfb2ea1e4d2d.svg../_images/02320cce6221845bc605d80bb0f50b3ed1d23066d38225e299daec64a38f4e15.svg../_images/017052da4dbf1b3f8be198c3157c9350b3908efe69c7f632ca4c95199d23bc63.svg../_images/121b05ae45ac5e5eb45e6fcbc92ea7a2171bc3c7945c60b424cb4f53cf7b0ea7.svg

Select some specific data#

# Get canonical SMILES
cansmiles = []
for cansmi in range(len(casrn_data)):
    cansmiles.append(casrn_data[cansmi]["canonicalSmile"])
print(cansmiles)
['O=C(OCC)CCC1CCCCC1', 'O=C(C#CCCCCCC)OCC', 'O=C(OCC)CN1N=CC=C1', 'O=C(OCC)C1=CC=CC(=C1)CCC(=O)OCC', 'N=C(OCC)C1=CCCCC1']
# Get synonyms
synonyms_list = []
for syn in range(len(casrn_data)):
    synonyms_list.append(casrn_data[syn]["synonyms"])
pprint(synonyms_list)
[['Cyclohexanepropanoic acid, ethyl ester',
  'Cyclohexanepropionic acid, ethyl ester',
  'Ethyl cyclohexanepropionate',
  'Ethyl cyclohexylpropanoate',
  'Ethyl 3-cyclohexylpropionate',
  'Ethyl 3-cyclohexylpropanoate',
  '3-Cyclohexylpropionic acid ethyl ester',
  'NSC 71463',
  'Ethyl 3-cyclohexanepropionate'],
 ['2-Nonynoic acid, ethyl ester', 'Ethyl 2-nonynoate', 'NSC 190985'],
 ['1<em>H</em>-Pyrazole-1-acetic acid, ethyl ester',
  'Pyrazole-1-acetic acid, ethyl ester',
  'Ethyl 1<em>H</em>-pyrazole-1-acetate',
  'Ethyl 1-pyrazoleacetate',
  'Ethyl 2-(1<em>H</em>-pyrazol-1-yl)acetate'],
 ['Benzenepropanoic acid, 3-(ethoxycarbonyl)-, ethyl ester',
  'Hydrocinnamic acid, <em>m</em>-carboxy-, diethyl ester',
  'Ethyl 3-(ethoxycarbonyl)benzenepropanoate'],
 ['1-Cyclohexene-1-carboximidic acid, ethyl ester',
  'Ethyl 1-cyclohexene-1-carboximidate']]
# Transform synonym "list of lists" to a flat list
synonyms_flat = []
for sublist in synonyms_list:
    for synonym in sublist:
        synonyms_flat.append(synonym)    
pprint(synonyms_flat)
['Cyclohexanepropanoic acid, ethyl ester',
 'Cyclohexanepropionic acid, ethyl ester',
 'Ethyl cyclohexanepropionate',
 'Ethyl cyclohexylpropanoate',
 'Ethyl 3-cyclohexylpropionate',
 'Ethyl 3-cyclohexylpropanoate',
 '3-Cyclohexylpropionic acid ethyl ester',
 'NSC 71463',
 'Ethyl 3-cyclohexanepropionate',
 '2-Nonynoic acid, ethyl ester',
 'Ethyl 2-nonynoate',
 'NSC 190985',
 '1<em>H</em>-Pyrazole-1-acetic acid, ethyl ester',
 'Pyrazole-1-acetic acid, ethyl ester',
 'Ethyl 1<em>H</em>-pyrazole-1-acetate',
 'Ethyl 1-pyrazoleacetate',
 'Ethyl 2-(1<em>H</em>-pyrazol-1-yl)acetate',
 'Benzenepropanoic acid, 3-(ethoxycarbonyl)-, ethyl ester',
 'Hydrocinnamic acid, <em>m</em>-carboxy-, diethyl ester',
 'Ethyl 3-(ethoxycarbonyl)benzenepropanoate',
 '1-Cyclohexene-1-carboximidic acid, ethyl ester',
 'Ethyl 1-cyclohexene-1-carboximidate']