CAS Common Chemistry API#
About this interactive 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)
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))
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']
3. Common Chemistry Search#
In addition to the /detail
API, the CAS Common Chemistry API has a /search
method that allows searching by CAS RN, SMILES, InChI/InChIKey, and name.
Import libraries#
import requests
from pprint import pprint
from time import sleep
Setup API Parameters#
search_base_url = "https://commonchemistry.cas.org/api/search?q="
Request data from CAS Common Chemistry Search API#
# keyword search query
quinine_search_data = requests.get(search_base_url + "quinine").json()
pprint(quinine_search_data)
{'count': 1,
'results': [{'image': '<svg width="280" viewBox="0 0 280 172" '
'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="172" '
'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="280" stroke="none" ry="7" rx="7" '
'height="172" fill="white" '
'class="cas-substance-group"/><svg y="0" x="0" '
'width="280" viewBox="0 0 280 172" style="fill:black;" '
'height="172" '
'class="cas-substance-single-component-image"><svg><g><clipPath '
'id="clipPath_bc3718cacd7145f589f52dd9bfea01721" '
'clipPathUnits="userSpaceOnUse"><path d="M36.2428 '
'-48.9389 L36.2012 -8.9389 L72.6092 -8.9011 L72.6507 '
'-48.9011 L58.0514 -48.9162 L58.0514 -48.9162 L46.7031 '
'-10.8966 L40.9538 -12.6127 L51.7918 -48.9227 L51.7918 '
'-48.9227 L36.2428 -48.9389 Z"/></clipPath><g '
'transform="translate(140,86)" '
'style="text-rendering:geometricPrecision; '
'color-rendering:optimizeQuality; '
'color-interpolation:linearRGB; stroke-linecap:butt; '
'image-rendering:optimizeQuality;"><path '
'style="stroke:none;" d="M-1.52 0.527 L-2.386 1.027 '
'L-16.2975 -18.0701 L-11.1012 -21.0699 Z"/><line '
'y2="26.757" y1="0.777" x2="-16.953" x1="-1.953" '
'style="fill:none;"/><line y2="0.777" y1="0.777" '
'x2="28.047" x1="-1.953" style="fill:none;"/><line '
'y2="-25.206" y1="-25.206" x2="-136.953" x1="-112.8905" '
'style="fill:none;"/><line y2="0.777" y1="-19.57" '
'x2="-91.953" x1="-103.6994" style="fill:none;"/><line '
'y2="-49.227" y1="-65.346" x2="136.953" x1="111.651" '
'style="fill:none;"/><line y2="-46.2751" y1="-61.3084" '
'x2="135.0725" x1="111.4747" style="fill:none;"/><path '
'style="stroke:none;" d="M85.2719 -51.0485 L84.8101 '
'-51.9355 L108.9981 -67.6289 L114.8412 -63.9065 '
'Z"/><line y2="26.757" y1="26.757" x2="-16.953" '
'x1="-46.953" style="fill:none;"/><line y2="52.737" '
'y1="26.757" x2="-61.953" x1="-46.953" '
'style="fill:none;"/><line y2="52.737" y1="30.257" '
'x2="-57.9115" x1="-44.9323" style="fill:none;"/><line '
'y2="0.777" y1="26.757" x2="-61.953" x1="-46.953" '
'style="fill:none;"/><line y2="52.737" y1="26.757" '
'x2="-1.953" x1="-16.953" style="fill:none;"/><line '
'y2="52.737" y1="30.257" x2="-5.9945" x1="-18.9737" '
'style="fill:none;"/><line y2="52.737" y1="52.737" '
'x2="-91.953" x1="-61.953" style="fill:none;"/><line '
'y2="72.5787" y1="52.737" x2="-50.497" x1="-61.953" '
'style="fill:none;"/><line y2="0.777" y1="0.777" '
'x2="-91.953" x1="-61.953" style="fill:none;"/><line '
'y2="4.277" y1="4.277" x2="-89.9323" x1="-63.9737" '
'style="fill:none;"/><line y2="78.717" y1="52.737" '
'x2="-16.953" x1="-1.953" style="fill:none;"/><line '
'y2="26.757" y1="52.737" x2="-106.953" x1="-91.953" '
'style="fill:none;"/><line y2="26.7569" y1="49.237" '
'x2="-102.9115" x1="-89.9323" style="fill:none;"/><line '
'y2="78.717" y1="78.717" x2="-16.953" x1="-41.6014" '
'style="fill:none;"/><line y2="75.217" y1="75.217" '
'x2="-18.9737" x1="-41.6014" style="fill:none;"/><line '
'y2="26.757" y1="0.777" x2="-106.953" x1="-91.953" '
'style="fill:none;"/><line y2="-22.9227" y1="0.777" '
'x2="37.5589" x1="28.047" style="fill:none;"/><path '
'style="stroke:none;" d="M28.3927 1.1383 L27.7013 '
'0.4157 L47.1148 -21.0165 L43.6455 -9.3935 Z"/><path '
'style="clip-path:url(#clipPath_bc3718cacd7145f589f52dd9bfea01721); '
'stroke:none;" d="M45.323 -28.4294 L45.3241 -29.4294 '
'L71.4315 -31.6118 L67.1417 -25.6163 Z"/><line '
'y2="-52.179" y1="-34.1312" x2="18.984" x1="35.2801" '
'style="fill:none;"/><line y2="-51.189" y1="-15.348" '
'x2="55.599" x1="44.901" style="fill:none;"/><line '
'y2="-51.492" y1="-28.905" x2="85.041" x1="68.88" '
'style="fill:none;"/><line y2="-75.186" y1="-52.179" '
'x2="33.555" x1="18.984" style="fill:none;"/><line '
'y2="-51.492" y1="-51.189" x2="85.041" x1="55.599" '
'style="fill:none;"/><line y2="-75.186" y1="-51.189" '
'x2="33.555" x1="55.599" style="fill:none;"/><path '
'style="stroke:none;" d="M28.8064 1.1461 L27.7536 '
'1.5689 L28.0263 2.5369 L29.2786 2.0339 L28.8064 1.1461 '
'ZM30.2231 3.8096 L28.5717 4.473 L28.5717 4.473 '
'L28.8444 5.441 L28.8444 5.441 L30.6953 4.6975 L30.2231 '
'3.8096 ZM31.6398 6.4732 L29.3899 7.377 L29.6626 8.345 '
'L29.6626 8.345 L32.112 7.3611 L32.112 7.3611 L31.6398 '
'6.4732 ZM33.0565 9.1368 L30.208 10.281 L30.208 10.281 '
'L30.4807 11.249 L30.4807 11.249 L33.5287 10.0247 '
'L33.0565 9.1368 ZM34.4732 11.8004 L31.0261 13.1851 '
'L31.0261 13.1851 L31.2988 14.1531 L31.2988 14.1531 '
'L34.9454 12.6883 L34.4732 11.8004 ZM35.8899 14.464 '
'L31.8442 16.0891 L32.1169 17.0571 L32.1169 17.0571 '
'L36.3621 15.3519 L35.8899 14.464 ZM37.3066 17.1276 '
'L32.6624 18.9931 L32.9351 19.9611 L32.9351 19.9611 '
'L37.7788 18.0154 L37.7788 18.0154 L37.3066 17.1276 '
'ZM38.7233 19.7912 L33.4805 21.8971 L33.7532 22.8652 '
'L39.1955 20.679 L39.1955 20.679 L38.7233 19.7912 '
'Z"/><path style="stroke:none;" d="M56.0578 -50.9903 '
'L55.1402 -51.3877 L62.1732 -73.9177 L67.6791 -71.5332 '
'Z"/></g><g transform="translate(140,86)" '
'style="font-size:8.4px; fill:gray; '
'text-rendering:geometricPrecision; '
'image-rendering:optimizeQuality; '
"color-rendering:optimizeQuality; font-family:'Open "
"Sans'; font-style:italic; stroke:gray; "
'color-interpolation:linearRGB;"><path '
'style="stroke:none;" d="M-1.3417 -6.7193 Q-1.3417 '
'-8.0474 -0.873 -9.1724 Q-0.4042 -10.2974 0.627 '
'-11.3755 L1.2364 -11.3755 Q0.2676 -10.313 -0.2167 '
'-9.1411 Q-0.7011 -7.9693 -0.7011 -6.7349 Q-0.7011 '
'-5.4068 -0.2636 -4.3911 L-0.7792 -4.3911 Q-1.3417 '
'-5.4224 -1.3417 -6.7193 ZM2.2183 -8.0318 L1.7183 '
'-5.6568 L1.0621 -5.6568 L2.2652 -11.3755 L3.5152 '
'-11.3755 Q5.2496 -11.3755 5.2496 -9.938 Q5.2496 '
'-8.5786 3.8121 -8.188 L4.7496 -5.6568 L4.0308 -5.6568 '
'L3.2027 -8.0318 L2.2183 -8.0318 ZM2.7964 -10.7818 '
'Q2.4058 -8.8599 2.3433 -8.6099 L2.9996 -8.6099 Q3.7496 '
'-8.6099 4.1558 -8.938 Q4.5621 -9.2661 4.5621 -9.8911 '
'Q4.5621 -10.3599 4.3042 -10.5708 Q4.0464 -10.7818 '
'3.4527 -10.7818 L2.7964 -10.7818 ZM7.4355 -9.0318 '
'Q7.4355 -7.7036 6.959 -6.5708 Q6.4824 -5.438 5.4668 '
'-4.3911 L4.8574 -4.3911 Q6.7949 -6.5474 6.7949 -9.0318 '
'Q6.7949 -10.3599 6.3574 -11.3755 L6.873 -11.3755 '
'Q7.4355 -10.313 7.4355 -9.0318 Z"/></g><g '
'transform="translate(140,86)" '
'style="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;"><path '
'style="stroke:none;" d="M-13.0155 -25.2763 Q-13.0155 '
'-23.2138 -14.0546 -22.0341 Q-15.0936 -20.8544 -16.9374 '
'-20.8544 Q-18.828 -20.8544 -19.8593 -22.0185 Q-20.8905 '
'-23.1826 -20.8905 -25.2919 Q-20.8905 -27.3857 -19.8593 '
'-28.5341 Q-18.828 -29.6826 -16.9374 -29.6826 Q-15.078 '
'-29.6826 -14.0468 -28.5107 Q-13.0155 -27.3388 -13.0155 '
'-25.2763 ZM-19.8436 -25.2763 Q-19.8436 -23.5419 '
'-19.1014 -22.6357 Q-18.3593 -21.7294 -16.9374 -21.7294 '
'Q-15.5155 -21.7294 -14.7889 -22.6279 Q-14.0624 '
'-23.5263 -14.0624 -25.2763 Q-14.0624 -27.0107 -14.7889 '
'-27.9013 Q-15.5155 -28.7919 -16.9374 -28.7919 '
'Q-18.3593 -28.7919 -19.1014 -27.8935 Q-19.8436 '
'-26.9951 -19.8436 -25.2763 Z"/><path '
'style="stroke:none;" d="M-21.8905 -20.9794 L-22.8905 '
'-20.9794 L-22.8905 -25.0107 L-27.4061 -25.0107 '
'L-27.4061 -20.9794 L-28.4061 -20.9794 L-28.4061 '
'-29.5419 L-27.4061 -29.5419 L-27.4061 -25.9013 '
'L-22.8905 -25.9013 L-22.8905 -29.5419 L-21.8905 '
'-29.5419 L-21.8905 -20.9794 Z"/><path '
'style="stroke:none;" d="M-103.0155 -25.2763 Q-103.0155 '
'-23.2138 -104.0546 -22.0341 Q-105.0936 -20.8544 '
'-106.9374 -20.8544 Q-108.828 -20.8544 -109.8592 '
'-22.0185 Q-110.8905 -23.1826 -110.8905 -25.2919 '
'Q-110.8905 -27.3857 -109.8592 -28.5341 Q-108.828 '
'-29.6826 -106.9374 -29.6826 Q-105.078 -29.6826 '
'-104.0467 -28.5107 Q-103.0155 -27.3388 -103.0155 '
'-25.2763 ZM-109.8436 -25.2763 Q-109.8436 -23.5419 '
'-109.1014 -22.6357 Q-108.3592 -21.7294 -106.9374 '
'-21.7294 Q-105.5155 -21.7294 -104.7889 -22.6279 '
'Q-104.0624 -23.5263 -104.0624 -25.2763 Q-104.0624 '
'-27.0107 -104.7889 -27.9013 Q-105.5155 -28.7919 '
'-106.9374 -28.7919 Q-108.3592 -28.7919 -109.1014 '
'-27.8935 Q-109.8436 -26.9951 -109.8436 -25.2763 '
'Z"/></g><g transform="translate(140,86)" '
'style="stroke-linecap:butt; '
'text-rendering:geometricPrecision; '
'color-rendering:optimizeQuality; '
"image-rendering:optimizeQuality; font-family:'Open "
"Sans'; color-interpolation:linearRGB; "
'stroke-miterlimit:5;"><path style="fill:none;" '
'd="M-47.203 27.19 L-46.953 26.757 L-46.453 '
'26.757"/><path style="fill:none;" d="M-16.703 27.19 '
'L-16.953 26.757 L-16.703 26.324"/><path '
'style="fill:none;" d="M-61.703 52.304 L-61.953 52.737 '
'L-62.453 52.737"/><path style="fill:none;" d="M-61.703 '
'1.21 L-61.953 0.777 L-62.453 0.777"/><path '
'style="fill:none;" d="M-2.203 52.304 L-1.953 52.737 '
'L-2.203 53.17"/><path style="fill:none;" d="M-91.453 '
'52.737 L-91.953 52.737 L-92.203 52.304"/><path '
'style="fill:rgb(0,5,255); stroke:none;" d="M-43.6014 '
'82.8732 L-44.7421 82.8732 L-49.4296 75.6857 L-49.4764 '
'75.6857 Q-49.3827 76.9514 -49.3827 77.9982 L-49.3827 '
'82.8732 L-50.3046 82.8732 L-50.3046 74.3107 L-49.1796 '
'74.3107 L-44.5077 81.467 L-44.4608 81.467 Q-44.4608 '
'81.3107 -44.5077 80.4514 Q-44.5546 79.592 -44.5389 '
'79.217 L-44.5389 74.3107 L-43.6014 74.3107 L-43.6014 '
'82.8732 Z"/><path style="fill:none;" d="M-91.453 0.777 '
'L-91.953 0.777 L-92.203 0.344"/><path '
'style="fill:none;" d="M-16.703 78.284 L-16.953 78.717 '
'L-17.453 78.717"/><path style="fill:none;" '
'd="M-106.703 27.19 L-106.953 26.757 L-106.703 '
'26.324"/><path style="fill:none;" d="M28.2333 1.241 '
'L28.047 0.777 L27.547 0.777"/></g><g '
'transform="translate(140,86)" '
'style="stroke-linecap:butt; font-size:8.4px; '
'fill:gray; text-rendering:geometricPrecision; '
'image-rendering:optimizeQuality; '
"color-rendering:optimizeQuality; font-family:'Open "
"Sans'; font-style:italic; stroke:gray; "
'color-interpolation:linearRGB; '
'stroke-miterlimit:5;"><path style="stroke:none;" '
'd="M33.7127 4.093 Q33.7127 2.7649 34.1815 1.6399 '
'Q34.6502 0.5149 35.6815 -0.5632 L36.2908 -0.5632 '
'Q35.3221 0.4993 34.8377 1.6711 Q34.3533 2.843 34.3533 '
'4.0774 Q34.3533 5.4055 34.7908 6.4211 L34.2752 6.4211 '
'Q33.7127 5.3899 33.7127 4.093 ZM39.3353 3.4993 '
'Q39.3353 4.3274 38.7884 4.7805 Q38.2415 5.2336 37.2415 '
'5.2336 Q36.8353 5.2336 36.5228 5.1789 Q36.2103 5.1243 '
'35.929 4.9836 L35.929 4.3274 Q36.554 4.6555 37.2571 '
'4.6555 Q37.8821 4.6555 38.2571 4.3586 Q38.6321 4.0618 '
'38.6321 3.5461 Q38.6321 3.2336 38.429 3.0071 Q38.2259 '
'2.7805 37.6634 2.4524 Q37.0696 2.1243 36.8431 1.7961 '
'Q36.6165 1.468 36.6165 1.0149 Q36.6165 0.2805 37.1321 '
'-0.1804 Q37.6478 -0.6414 38.4915 -0.6414 Q38.8665 '
'-0.6414 39.2025 -0.5632 Q39.5384 -0.4851 39.9134 '
'-0.3132 L39.6478 0.2805 Q39.3978 0.1243 39.0775 0.0383 '
'Q38.7571 -0.0476 38.4915 -0.0476 Q37.9603 -0.0476 '
'37.64 0.2258 Q37.3196 0.4993 37.3196 0.968 Q37.3196 '
'1.1711 37.39 1.3196 Q37.4603 1.468 37.6009 1.6008 '
'Q37.7415 1.7336 38.1634 1.9836 Q38.7259 2.3274 38.929 '
'2.5227 Q39.1321 2.718 39.2337 2.9524 Q39.3353 3.1868 '
'39.3353 3.4993 ZM41.9298 1.7805 Q41.9298 3.1086 '
'41.4532 4.2414 Q40.9766 5.3743 39.961 6.4211 L39.3516 '
'6.4211 Q41.2891 4.2649 41.2891 1.7805 Q41.2891 0.4524 '
'40.8516 -0.5632 L41.3673 -0.5632 Q41.9298 0.4993 '
'41.9298 1.7805 Z"/></g><g '
'transform="translate(140,86)" '
'style="stroke-linecap:butt; fill:rgb(0,5,255); '
'text-rendering:geometricPrecision; '
'color-rendering:optimizeQuality; '
"image-rendering:optimizeQuality; font-family:'Open "
"Sans'; stroke:rgb(0,5,255); "
'color-interpolation:linearRGB; '
'stroke-miterlimit:5;"><path style="stroke:none;" '
'd="M43.3236 -24.7787 L42.1829 -24.7787 L37.4954 '
'-31.9662 L37.4486 -31.9662 Q37.5423 -30.7006 37.5423 '
'-29.6537 L37.5423 -24.7787 L36.6204 -24.7787 L36.6204 '
'-33.3412 L37.7454 -33.3412 L42.4173 -26.185 L42.4642 '
'-26.185 Q42.4642 -26.3412 42.4173 -27.2006 Q42.3704 '
'-28.06 42.3861 -28.435 L42.3861 -33.3412 L43.3236 '
'-33.3412 L43.3236 -24.7787 Z"/></g><g '
'transform="translate(140,86)" '
'style="stroke-linecap:butt; font-size:8.4px; '
'fill:gray; text-rendering:geometricPrecision; '
'image-rendering:optimizeQuality; '
"color-rendering:optimizeQuality; font-family:'Open "
"Sans'; font-style:italic; stroke:gray; "
'color-interpolation:linearRGB; '
'stroke-miterlimit:5;"><path style="stroke:none;" '
'd="M40.0877 -37.2242 Q40.0877 -38.5523 40.5564 '
'-39.6773 Q41.0252 -40.8023 42.0564 -41.8804 L42.6658 '
'-41.8804 Q41.697 -40.8179 41.2127 -39.646 Q40.7283 '
'-38.4742 40.7283 -37.2398 Q40.7283 -35.9117 41.1658 '
'-34.896 L40.6502 -34.896 Q40.0877 -35.9273 40.0877 '
'-37.2242 ZM45.7102 -37.8179 Q45.7102 -36.9898 45.1633 '
'-36.5367 Q44.6165 -36.0835 43.6165 -36.0835 Q43.2102 '
'-36.0835 42.8977 -36.1382 Q42.5852 -36.1929 42.304 '
'-36.3335 L42.304 -36.9898 Q42.929 -36.6617 43.6321 '
'-36.6617 Q44.2571 -36.6617 44.6321 -36.9585 Q45.0071 '
'-37.2554 45.0071 -37.771 Q45.0071 -38.0835 44.804 '
'-38.3101 Q44.6008 -38.5367 44.0383 -38.8648 Q43.4446 '
'-39.1929 43.218 -39.521 Q42.9915 -39.8492 42.9915 '
'-40.3023 Q42.9915 -41.0367 43.5071 -41.4976 Q44.0227 '
'-41.9585 44.8665 -41.9585 Q45.2415 -41.9585 45.5774 '
'-41.8804 Q45.9133 -41.8023 46.2883 -41.6304 L46.0227 '
'-41.0367 Q45.7727 -41.1929 45.4524 -41.2789 Q45.1321 '
'-41.3648 44.8665 -41.3648 Q44.3352 -41.3648 44.0149 '
'-41.0914 Q43.6946 -40.8179 43.6946 -40.3492 Q43.6946 '
'-40.146 43.7649 -39.9976 Q43.8352 -39.8492 43.9758 '
'-39.7164 Q44.1165 -39.5835 44.5383 -39.3335 Q45.1008 '
'-38.9898 45.304 -38.7945 Q45.5071 -38.5992 45.6087 '
'-38.3648 Q45.7102 -38.1304 45.7102 -37.8179 ZM48.3047 '
'-39.5367 Q48.3047 -38.2085 47.8281 -37.0757 Q47.3516 '
'-35.9429 46.3359 -34.896 L45.7266 -34.896 Q47.6641 '
'-37.0523 47.6641 -39.5367 Q47.6641 -40.8648 47.2266 '
'-41.8804 L47.7422 -41.8804 Q48.3047 -40.8179 48.3047 '
'-39.5367 Z"/><path style="fill:none; stroke:black;" '
'd="M19.3191 -51.8079 L18.984 -52.179 L19.2515 '
'-52.6014"/><path style="stroke:none;" d="M41.7458 '
'-47.7405 Q41.7458 -49.0686 42.2146 -50.1936 Q42.6833 '
'-51.3186 43.7146 -52.3967 L44.324 -52.3967 Q43.3552 '
'-51.3342 42.8708 -50.1624 Q42.3865 -48.9905 42.3865 '
'-47.7561 Q42.3865 -46.428 42.824 -45.4124 L42.3083 '
'-45.4124 Q41.7458 -46.4436 41.7458 -47.7405 ZM47.3684 '
'-48.3342 Q47.3684 -47.5061 46.8215 -47.053 Q46.2746 '
'-46.5999 45.2746 -46.5999 Q44.8684 -46.5999 44.5559 '
'-46.6546 Q44.2434 -46.7092 43.9621 -46.8499 L43.9621 '
'-47.5061 Q44.5871 -47.178 45.2903 -47.178 Q45.9153 '
'-47.178 46.2903 -47.4749 Q46.6653 -47.7717 46.6653 '
'-48.2874 Q46.6653 -48.5999 46.4621 -48.8264 Q46.259 '
'-49.053 45.6965 -49.3811 Q45.1028 -49.7092 44.8762 '
'-50.0374 Q44.6496 -50.3655 44.6496 -50.8186 Q44.6496 '
'-51.553 45.1653 -52.0139 Q45.6809 -52.4749 46.5246 '
'-52.4749 Q46.8996 -52.4749 47.2356 -52.3967 Q47.5715 '
'-52.3186 47.9465 -52.1467 L47.6809 -51.553 Q47.4309 '
'-51.7092 47.1106 -51.7952 Q46.7903 -51.8811 46.5246 '
'-51.8811 Q45.9934 -51.8811 45.6731 -51.6077 Q45.3528 '
'-51.3342 45.3528 -50.8655 Q45.3528 -50.6624 45.4231 '
'-50.5139 Q45.4934 -50.3655 45.634 -50.2327 Q45.7746 '
'-50.0999 46.1965 -49.8499 Q46.759 -49.5061 46.9621 '
'-49.3108 Q47.1653 -49.1155 47.2668 -48.8811 Q47.3684 '
'-48.6467 47.3684 -48.3342 ZM49.9629 -50.053 Q49.9629 '
'-48.7249 49.4863 -47.5921 Q49.0097 -46.4592 47.9941 '
'-45.4124 L47.3847 -45.4124 Q49.3222 -47.5686 49.3222 '
'-50.053 Q49.3222 -51.3811 48.8847 -52.3967 L49.4004 '
'-52.3967 Q49.9629 -51.3342 49.9629 -50.053 Z"/><path '
'style="stroke:none;" d="M78.2253 -60.0289 Q78.2253 '
'-61.3571 78.6941 -62.4821 Q79.1628 -63.6071 80.1941 '
'-64.6852 L80.8034 -64.6852 Q79.8347 -63.6227 79.3503 '
'-62.4508 Q78.8659 -61.2789 78.8659 -60.0446 Q78.8659 '
'-58.7164 79.3034 -57.7008 L78.7878 -57.7008 Q78.2253 '
'-58.7321 78.2253 -60.0289 ZM81.7854 -61.3414 L81.2854 '
'-58.9664 L80.6291 -58.9664 L81.8322 -64.6852 L83.0822 '
'-64.6852 Q84.8166 -64.6852 84.8166 -63.2477 Q84.8166 '
'-61.8883 83.3791 -61.4977 L84.3166 -58.9664 L83.5979 '
'-58.9664 L82.7697 -61.3414 L81.7854 -61.3414 ZM82.3635 '
'-64.0914 Q81.9729 -62.1696 81.9104 -61.9196 L82.5666 '
'-61.9196 Q83.3166 -61.9196 83.7229 -62.2477 Q84.1291 '
'-62.5758 84.1291 -63.2008 Q84.1291 -63.6696 83.8713 '
'-63.8805 Q83.6135 -64.0914 83.0197 -64.0914 L82.3635 '
'-64.0914 ZM87.0026 -62.3414 Q87.0026 -61.0133 86.526 '
'-59.8805 Q86.0495 -58.7477 85.0338 -57.7008 L84.4245 '
'-57.7008 Q86.362 -59.8571 86.362 -62.3414 Q86.362 '
'-63.6696 85.9245 -64.6852 L86.4401 -64.6852 Q87.0026 '
'-63.6227 87.0026 -62.3414 Z"/><path style="fill:none; '
'stroke:black;" d="M33.2875 -74.7636 L33.555 -75.186 '
'L33.8933 -74.8178"/></g><g '
'transform="translate(140,86)" '
'style="stroke-linecap:butt; '
'text-rendering:geometricPrecision; '
'color-rendering:optimizeQuality; '
"image-rendering:optimizeQuality; font-family:'Open "
"Sans'; color-interpolation:linearRGB; "
'stroke-miterlimit:5;"><path style="stroke:none;" '
'd="M42.4798 32.7732 L41.4798 32.7732 L41.4798 28.742 '
'L36.9642 28.742 L36.9642 32.7732 L35.9642 32.7732 '
'L35.9642 24.2107 L36.9642 24.2107 L36.9642 27.8514 '
'L41.4798 27.8514 L41.4798 24.2107 L42.4798 24.2107 '
'L42.4798 32.7732 Z"/><path style="stroke:none;" '
'd="M70.7788 -74.5607 L69.7788 -74.5607 L69.7788 '
'-78.592 L65.2632 -78.592 L65.2632 -74.5607 L64.2632 '
'-74.5607 L64.2632 -83.1232 L65.2632 -83.1232 L65.2632 '
'-79.4826 L69.7788 -79.4826 L69.7788 -83.1232 L70.7788 '
'-83.1232 L70.7788 -74.5607 '
'Z"/></g></g></svg></svg></svg></svg>',
'name': 'Quinine',
'rn': '130-95-0'}]}
Note that with the CAS Common Chemistry Search API, only the image data, name, and CAS RN is returned. In order to retrieve the full record, we can combine our search with the related detail API:
# search query
quinine_search_data = requests.get(search_base_url + "quinine").json()
# extract our CAS RN
quinine_rn = quinine_search_data["results"][0]["rn"]
print(quinine_rn)
130-95-0
# get detailed record for quinine
detail_base_url = "https://commonchemistry.cas.org/api/detail?"
quinine_detail_data = requests.get(detail_base_url + "cas_rn=" + quinine_rn).json()
pprint(quinine_detail_data)
{'canonicalSmile': 'OC(C=1C=CN=C2C=CC(OC)=CC21)C3N4CCC(C3)C(C=C)C4',
'experimentalProperties': [{'name': 'Melting Point',
'property': '177 °C (decomp)',
'sourceNumber': 1}],
'hasMolfile': True,
'image': '<svg width="280" viewBox="0 0 280 172" 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="172" 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="280" stroke="none" ry="7" rx="7" height="172" fill="white" '
'class="cas-substance-group"/><svg y="0" x="0" width="280" '
'viewBox="0 0 280 172" style="fill:black;" height="172" '
'class="cas-substance-single-component-image"><svg><g><clipPath '
'id="clipPath_bc3718cacd7145f589f52dd9bfea01721" '
'clipPathUnits="userSpaceOnUse"><path d="M36.2428 -48.9389 L36.2012 '
'-8.9389 L72.6092 -8.9011 L72.6507 -48.9011 L58.0514 -48.9162 '
'L58.0514 -48.9162 L46.7031 -10.8966 L40.9538 -12.6127 L51.7918 '
'-48.9227 L51.7918 -48.9227 L36.2428 -48.9389 Z"/></clipPath><g '
'transform="translate(140,86)" '
'style="text-rendering:geometricPrecision; '
'color-rendering:optimizeQuality; color-interpolation:linearRGB; '
'stroke-linecap:butt; image-rendering:optimizeQuality;"><path '
'style="stroke:none;" d="M-1.52 0.527 L-2.386 1.027 L-16.2975 '
'-18.0701 L-11.1012 -21.0699 Z"/><line y2="26.757" y1="0.777" '
'x2="-16.953" x1="-1.953" style="fill:none;"/><line y2="0.777" '
'y1="0.777" x2="28.047" x1="-1.953" style="fill:none;"/><line '
'y2="-25.206" y1="-25.206" x2="-136.953" x1="-112.8905" '
'style="fill:none;"/><line y2="0.777" y1="-19.57" x2="-91.953" '
'x1="-103.6994" style="fill:none;"/><line y2="-49.227" y1="-65.346" '
'x2="136.953" x1="111.651" style="fill:none;"/><line y2="-46.2751" '
'y1="-61.3084" x2="135.0725" x1="111.4747" style="fill:none;"/><path '
'style="stroke:none;" d="M85.2719 -51.0485 L84.8101 -51.9355 '
'L108.9981 -67.6289 L114.8412 -63.9065 Z"/><line y2="26.757" '
'y1="26.757" x2="-16.953" x1="-46.953" style="fill:none;"/><line '
'y2="52.737" y1="26.757" x2="-61.953" x1="-46.953" '
'style="fill:none;"/><line y2="52.737" y1="30.257" x2="-57.9115" '
'x1="-44.9323" style="fill:none;"/><line y2="0.777" y1="26.757" '
'x2="-61.953" x1="-46.953" style="fill:none;"/><line y2="52.737" '
'y1="26.757" x2="-1.953" x1="-16.953" style="fill:none;"/><line '
'y2="52.737" y1="30.257" x2="-5.9945" x1="-18.9737" '
'style="fill:none;"/><line y2="52.737" y1="52.737" x2="-91.953" '
'x1="-61.953" style="fill:none;"/><line y2="72.5787" y1="52.737" '
'x2="-50.497" x1="-61.953" style="fill:none;"/><line y2="0.777" '
'y1="0.777" x2="-91.953" x1="-61.953" style="fill:none;"/><line '
'y2="4.277" y1="4.277" x2="-89.9323" x1="-63.9737" '
'style="fill:none;"/><line y2="78.717" y1="52.737" x2="-16.953" '
'x1="-1.953" style="fill:none;"/><line y2="26.757" y1="52.737" '
'x2="-106.953" x1="-91.953" style="fill:none;"/><line y2="26.7569" '
'y1="49.237" x2="-102.9115" x1="-89.9323" style="fill:none;"/><line '
'y2="78.717" y1="78.717" x2="-16.953" x1="-41.6014" '
'style="fill:none;"/><line y2="75.217" y1="75.217" x2="-18.9737" '
'x1="-41.6014" style="fill:none;"/><line y2="26.757" y1="0.777" '
'x2="-106.953" x1="-91.953" style="fill:none;"/><line y2="-22.9227" '
'y1="0.777" x2="37.5589" x1="28.047" style="fill:none;"/><path '
'style="stroke:none;" d="M28.3927 1.1383 L27.7013 0.4157 L47.1148 '
'-21.0165 L43.6455 -9.3935 Z"/><path '
'style="clip-path:url(#clipPath_bc3718cacd7145f589f52dd9bfea01721); '
'stroke:none;" d="M45.323 -28.4294 L45.3241 -29.4294 L71.4315 '
'-31.6118 L67.1417 -25.6163 Z"/><line y2="-52.179" y1="-34.1312" '
'x2="18.984" x1="35.2801" style="fill:none;"/><line y2="-51.189" '
'y1="-15.348" x2="55.599" x1="44.901" style="fill:none;"/><line '
'y2="-51.492" y1="-28.905" x2="85.041" x1="68.88" '
'style="fill:none;"/><line y2="-75.186" y1="-52.179" x2="33.555" '
'x1="18.984" style="fill:none;"/><line y2="-51.492" y1="-51.189" '
'x2="85.041" x1="55.599" style="fill:none;"/><line y2="-75.186" '
'y1="-51.189" x2="33.555" x1="55.599" style="fill:none;"/><path '
'style="stroke:none;" d="M28.8064 1.1461 L27.7536 1.5689 L28.0263 '
'2.5369 L29.2786 2.0339 L28.8064 1.1461 ZM30.2231 3.8096 L28.5717 '
'4.473 L28.5717 4.473 L28.8444 5.441 L28.8444 5.441 L30.6953 4.6975 '
'L30.2231 3.8096 ZM31.6398 6.4732 L29.3899 7.377 L29.6626 8.345 '
'L29.6626 8.345 L32.112 7.3611 L32.112 7.3611 L31.6398 6.4732 '
'ZM33.0565 9.1368 L30.208 10.281 L30.208 10.281 L30.4807 11.249 '
'L30.4807 11.249 L33.5287 10.0247 L33.0565 9.1368 ZM34.4732 11.8004 '
'L31.0261 13.1851 L31.0261 13.1851 L31.2988 14.1531 L31.2988 14.1531 '
'L34.9454 12.6883 L34.4732 11.8004 ZM35.8899 14.464 L31.8442 16.0891 '
'L32.1169 17.0571 L32.1169 17.0571 L36.3621 15.3519 L35.8899 14.464 '
'ZM37.3066 17.1276 L32.6624 18.9931 L32.9351 19.9611 L32.9351 '
'19.9611 L37.7788 18.0154 L37.7788 18.0154 L37.3066 17.1276 '
'ZM38.7233 19.7912 L33.4805 21.8971 L33.7532 22.8652 L39.1955 20.679 '
'L39.1955 20.679 L38.7233 19.7912 Z"/><path style="stroke:none;" '
'd="M56.0578 -50.9903 L55.1402 -51.3877 L62.1732 -73.9177 L67.6791 '
'-71.5332 Z"/></g><g transform="translate(140,86)" '
'style="font-size:8.4px; fill:gray; '
'text-rendering:geometricPrecision; image-rendering:optimizeQuality; '
"color-rendering:optimizeQuality; font-family:'Open Sans'; "
'font-style:italic; stroke:gray; '
'color-interpolation:linearRGB;"><path style="stroke:none;" '
'd="M-1.3417 -6.7193 Q-1.3417 -8.0474 -0.873 -9.1724 Q-0.4042 '
'-10.2974 0.627 -11.3755 L1.2364 -11.3755 Q0.2676 -10.313 -0.2167 '
'-9.1411 Q-0.7011 -7.9693 -0.7011 -6.7349 Q-0.7011 -5.4068 -0.2636 '
'-4.3911 L-0.7792 -4.3911 Q-1.3417 -5.4224 -1.3417 -6.7193 ZM2.2183 '
'-8.0318 L1.7183 -5.6568 L1.0621 -5.6568 L2.2652 -11.3755 L3.5152 '
'-11.3755 Q5.2496 -11.3755 5.2496 -9.938 Q5.2496 -8.5786 3.8121 '
'-8.188 L4.7496 -5.6568 L4.0308 -5.6568 L3.2027 -8.0318 L2.2183 '
'-8.0318 ZM2.7964 -10.7818 Q2.4058 -8.8599 2.3433 -8.6099 L2.9996 '
'-8.6099 Q3.7496 -8.6099 4.1558 -8.938 Q4.5621 -9.2661 4.5621 '
'-9.8911 Q4.5621 -10.3599 4.3042 -10.5708 Q4.0464 -10.7818 3.4527 '
'-10.7818 L2.7964 -10.7818 ZM7.4355 -9.0318 Q7.4355 -7.7036 6.959 '
'-6.5708 Q6.4824 -5.438 5.4668 -4.3911 L4.8574 -4.3911 Q6.7949 '
'-6.5474 6.7949 -9.0318 Q6.7949 -10.3599 6.3574 -11.3755 L6.873 '
'-11.3755 Q7.4355 -10.313 7.4355 -9.0318 Z"/></g><g '
'transform="translate(140,86)" style="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;"><path '
'style="stroke:none;" d="M-13.0155 -25.2763 Q-13.0155 -23.2138 '
'-14.0546 -22.0341 Q-15.0936 -20.8544 -16.9374 -20.8544 Q-18.828 '
'-20.8544 -19.8593 -22.0185 Q-20.8905 -23.1826 -20.8905 -25.2919 '
'Q-20.8905 -27.3857 -19.8593 -28.5341 Q-18.828 -29.6826 -16.9374 '
'-29.6826 Q-15.078 -29.6826 -14.0468 -28.5107 Q-13.0155 -27.3388 '
'-13.0155 -25.2763 ZM-19.8436 -25.2763 Q-19.8436 -23.5419 -19.1014 '
'-22.6357 Q-18.3593 -21.7294 -16.9374 -21.7294 Q-15.5155 -21.7294 '
'-14.7889 -22.6279 Q-14.0624 -23.5263 -14.0624 -25.2763 Q-14.0624 '
'-27.0107 -14.7889 -27.9013 Q-15.5155 -28.7919 -16.9374 -28.7919 '
'Q-18.3593 -28.7919 -19.1014 -27.8935 Q-19.8436 -26.9951 -19.8436 '
'-25.2763 Z"/><path style="stroke:none;" d="M-21.8905 -20.9794 '
'L-22.8905 -20.9794 L-22.8905 -25.0107 L-27.4061 -25.0107 L-27.4061 '
'-20.9794 L-28.4061 -20.9794 L-28.4061 -29.5419 L-27.4061 -29.5419 '
'L-27.4061 -25.9013 L-22.8905 -25.9013 L-22.8905 -29.5419 L-21.8905 '
'-29.5419 L-21.8905 -20.9794 Z"/><path style="stroke:none;" '
'd="M-103.0155 -25.2763 Q-103.0155 -23.2138 -104.0546 -22.0341 '
'Q-105.0936 -20.8544 -106.9374 -20.8544 Q-108.828 -20.8544 -109.8592 '
'-22.0185 Q-110.8905 -23.1826 -110.8905 -25.2919 Q-110.8905 -27.3857 '
'-109.8592 -28.5341 Q-108.828 -29.6826 -106.9374 -29.6826 Q-105.078 '
'-29.6826 -104.0467 -28.5107 Q-103.0155 -27.3388 -103.0155 -25.2763 '
'ZM-109.8436 -25.2763 Q-109.8436 -23.5419 -109.1014 -22.6357 '
'Q-108.3592 -21.7294 -106.9374 -21.7294 Q-105.5155 -21.7294 '
'-104.7889 -22.6279 Q-104.0624 -23.5263 -104.0624 -25.2763 '
'Q-104.0624 -27.0107 -104.7889 -27.9013 Q-105.5155 -28.7919 '
'-106.9374 -28.7919 Q-108.3592 -28.7919 -109.1014 -27.8935 '
'Q-109.8436 -26.9951 -109.8436 -25.2763 Z"/></g><g '
'transform="translate(140,86)" style="stroke-linecap:butt; '
'text-rendering:geometricPrecision; color-rendering:optimizeQuality; '
"image-rendering:optimizeQuality; font-family:'Open Sans'; "
'color-interpolation:linearRGB; stroke-miterlimit:5;"><path '
'style="fill:none;" d="M-47.203 27.19 L-46.953 26.757 L-46.453 '
'26.757"/><path style="fill:none;" d="M-16.703 27.19 L-16.953 26.757 '
'L-16.703 26.324"/><path style="fill:none;" d="M-61.703 52.304 '
'L-61.953 52.737 L-62.453 52.737"/><path style="fill:none;" '
'd="M-61.703 1.21 L-61.953 0.777 L-62.453 0.777"/><path '
'style="fill:none;" d="M-2.203 52.304 L-1.953 52.737 L-2.203 '
'53.17"/><path style="fill:none;" d="M-91.453 52.737 L-91.953 52.737 '
'L-92.203 52.304"/><path style="fill:rgb(0,5,255); stroke:none;" '
'd="M-43.6014 82.8732 L-44.7421 82.8732 L-49.4296 75.6857 L-49.4764 '
'75.6857 Q-49.3827 76.9514 -49.3827 77.9982 L-49.3827 82.8732 '
'L-50.3046 82.8732 L-50.3046 74.3107 L-49.1796 74.3107 L-44.5077 '
'81.467 L-44.4608 81.467 Q-44.4608 81.3107 -44.5077 80.4514 '
'Q-44.5546 79.592 -44.5389 79.217 L-44.5389 74.3107 L-43.6014 '
'74.3107 L-43.6014 82.8732 Z"/><path style="fill:none;" d="M-91.453 '
'0.777 L-91.953 0.777 L-92.203 0.344"/><path style="fill:none;" '
'd="M-16.703 78.284 L-16.953 78.717 L-17.453 78.717"/><path '
'style="fill:none;" d="M-106.703 27.19 L-106.953 26.757 L-106.703 '
'26.324"/><path style="fill:none;" d="M28.2333 1.241 L28.047 0.777 '
'L27.547 0.777"/></g><g transform="translate(140,86)" '
'style="stroke-linecap:butt; font-size:8.4px; fill:gray; '
'text-rendering:geometricPrecision; image-rendering:optimizeQuality; '
"color-rendering:optimizeQuality; font-family:'Open Sans'; "
'font-style:italic; stroke:gray; color-interpolation:linearRGB; '
'stroke-miterlimit:5;"><path style="stroke:none;" d="M33.7127 4.093 '
'Q33.7127 2.7649 34.1815 1.6399 Q34.6502 0.5149 35.6815 -0.5632 '
'L36.2908 -0.5632 Q35.3221 0.4993 34.8377 1.6711 Q34.3533 2.843 '
'34.3533 4.0774 Q34.3533 5.4055 34.7908 6.4211 L34.2752 6.4211 '
'Q33.7127 5.3899 33.7127 4.093 ZM39.3353 3.4993 Q39.3353 4.3274 '
'38.7884 4.7805 Q38.2415 5.2336 37.2415 5.2336 Q36.8353 5.2336 '
'36.5228 5.1789 Q36.2103 5.1243 35.929 4.9836 L35.929 4.3274 Q36.554 '
'4.6555 37.2571 4.6555 Q37.8821 4.6555 38.2571 4.3586 Q38.6321 '
'4.0618 38.6321 3.5461 Q38.6321 3.2336 38.429 3.0071 Q38.2259 2.7805 '
'37.6634 2.4524 Q37.0696 2.1243 36.8431 1.7961 Q36.6165 1.468 '
'36.6165 1.0149 Q36.6165 0.2805 37.1321 -0.1804 Q37.6478 -0.6414 '
'38.4915 -0.6414 Q38.8665 -0.6414 39.2025 -0.5632 Q39.5384 -0.4851 '
'39.9134 -0.3132 L39.6478 0.2805 Q39.3978 0.1243 39.0775 0.0383 '
'Q38.7571 -0.0476 38.4915 -0.0476 Q37.9603 -0.0476 37.64 0.2258 '
'Q37.3196 0.4993 37.3196 0.968 Q37.3196 1.1711 37.39 1.3196 Q37.4603 '
'1.468 37.6009 1.6008 Q37.7415 1.7336 38.1634 1.9836 Q38.7259 2.3274 '
'38.929 2.5227 Q39.1321 2.718 39.2337 2.9524 Q39.3353 3.1868 39.3353 '
'3.4993 ZM41.9298 1.7805 Q41.9298 3.1086 41.4532 4.2414 Q40.9766 '
'5.3743 39.961 6.4211 L39.3516 6.4211 Q41.2891 4.2649 41.2891 1.7805 '
'Q41.2891 0.4524 40.8516 -0.5632 L41.3673 -0.5632 Q41.9298 0.4993 '
'41.9298 1.7805 Z"/></g><g transform="translate(140,86)" '
'style="stroke-linecap:butt; fill:rgb(0,5,255); '
'text-rendering:geometricPrecision; color-rendering:optimizeQuality; '
"image-rendering:optimizeQuality; font-family:'Open Sans'; "
'stroke:rgb(0,5,255); color-interpolation:linearRGB; '
'stroke-miterlimit:5;"><path style="stroke:none;" d="M43.3236 '
'-24.7787 L42.1829 -24.7787 L37.4954 -31.9662 L37.4486 -31.9662 '
'Q37.5423 -30.7006 37.5423 -29.6537 L37.5423 -24.7787 L36.6204 '
'-24.7787 L36.6204 -33.3412 L37.7454 -33.3412 L42.4173 -26.185 '
'L42.4642 -26.185 Q42.4642 -26.3412 42.4173 -27.2006 Q42.3704 -28.06 '
'42.3861 -28.435 L42.3861 -33.3412 L43.3236 -33.3412 L43.3236 '
'-24.7787 Z"/></g><g transform="translate(140,86)" '
'style="stroke-linecap:butt; font-size:8.4px; fill:gray; '
'text-rendering:geometricPrecision; image-rendering:optimizeQuality; '
"color-rendering:optimizeQuality; font-family:'Open Sans'; "
'font-style:italic; stroke:gray; color-interpolation:linearRGB; '
'stroke-miterlimit:5;"><path style="stroke:none;" d="M40.0877 '
'-37.2242 Q40.0877 -38.5523 40.5564 -39.6773 Q41.0252 -40.8023 '
'42.0564 -41.8804 L42.6658 -41.8804 Q41.697 -40.8179 41.2127 -39.646 '
'Q40.7283 -38.4742 40.7283 -37.2398 Q40.7283 -35.9117 41.1658 '
'-34.896 L40.6502 -34.896 Q40.0877 -35.9273 40.0877 -37.2242 '
'ZM45.7102 -37.8179 Q45.7102 -36.9898 45.1633 -36.5367 Q44.6165 '
'-36.0835 43.6165 -36.0835 Q43.2102 -36.0835 42.8977 -36.1382 '
'Q42.5852 -36.1929 42.304 -36.3335 L42.304 -36.9898 Q42.929 -36.6617 '
'43.6321 -36.6617 Q44.2571 -36.6617 44.6321 -36.9585 Q45.0071 '
'-37.2554 45.0071 -37.771 Q45.0071 -38.0835 44.804 -38.3101 Q44.6008 '
'-38.5367 44.0383 -38.8648 Q43.4446 -39.1929 43.218 -39.521 Q42.9915 '
'-39.8492 42.9915 -40.3023 Q42.9915 -41.0367 43.5071 -41.4976 '
'Q44.0227 -41.9585 44.8665 -41.9585 Q45.2415 -41.9585 45.5774 '
'-41.8804 Q45.9133 -41.8023 46.2883 -41.6304 L46.0227 -41.0367 '
'Q45.7727 -41.1929 45.4524 -41.2789 Q45.1321 -41.3648 44.8665 '
'-41.3648 Q44.3352 -41.3648 44.0149 -41.0914 Q43.6946 -40.8179 '
'43.6946 -40.3492 Q43.6946 -40.146 43.7649 -39.9976 Q43.8352 '
'-39.8492 43.9758 -39.7164 Q44.1165 -39.5835 44.5383 -39.3335 '
'Q45.1008 -38.9898 45.304 -38.7945 Q45.5071 -38.5992 45.6087 '
'-38.3648 Q45.7102 -38.1304 45.7102 -37.8179 ZM48.3047 -39.5367 '
'Q48.3047 -38.2085 47.8281 -37.0757 Q47.3516 -35.9429 46.3359 '
'-34.896 L45.7266 -34.896 Q47.6641 -37.0523 47.6641 -39.5367 '
'Q47.6641 -40.8648 47.2266 -41.8804 L47.7422 -41.8804 Q48.3047 '
'-40.8179 48.3047 -39.5367 Z"/><path style="fill:none; '
'stroke:black;" d="M19.3191 -51.8079 L18.984 -52.179 L19.2515 '
'-52.6014"/><path style="stroke:none;" d="M41.7458 -47.7405 Q41.7458 '
'-49.0686 42.2146 -50.1936 Q42.6833 -51.3186 43.7146 -52.3967 '
'L44.324 -52.3967 Q43.3552 -51.3342 42.8708 -50.1624 Q42.3865 '
'-48.9905 42.3865 -47.7561 Q42.3865 -46.428 42.824 -45.4124 L42.3083 '
'-45.4124 Q41.7458 -46.4436 41.7458 -47.7405 ZM47.3684 -48.3342 '
'Q47.3684 -47.5061 46.8215 -47.053 Q46.2746 -46.5999 45.2746 '
'-46.5999 Q44.8684 -46.5999 44.5559 -46.6546 Q44.2434 -46.7092 '
'43.9621 -46.8499 L43.9621 -47.5061 Q44.5871 -47.178 45.2903 -47.178 '
'Q45.9153 -47.178 46.2903 -47.4749 Q46.6653 -47.7717 46.6653 '
'-48.2874 Q46.6653 -48.5999 46.4621 -48.8264 Q46.259 -49.053 45.6965 '
'-49.3811 Q45.1028 -49.7092 44.8762 -50.0374 Q44.6496 -50.3655 '
'44.6496 -50.8186 Q44.6496 -51.553 45.1653 -52.0139 Q45.6809 '
'-52.4749 46.5246 -52.4749 Q46.8996 -52.4749 47.2356 -52.3967 '
'Q47.5715 -52.3186 47.9465 -52.1467 L47.6809 -51.553 Q47.4309 '
'-51.7092 47.1106 -51.7952 Q46.7903 -51.8811 46.5246 -51.8811 '
'Q45.9934 -51.8811 45.6731 -51.6077 Q45.3528 -51.3342 45.3528 '
'-50.8655 Q45.3528 -50.6624 45.4231 -50.5139 Q45.4934 -50.3655 '
'45.634 -50.2327 Q45.7746 -50.0999 46.1965 -49.8499 Q46.759 -49.5061 '
'46.9621 -49.3108 Q47.1653 -49.1155 47.2668 -48.8811 Q47.3684 '
'-48.6467 47.3684 -48.3342 ZM49.9629 -50.053 Q49.9629 -48.7249 '
'49.4863 -47.5921 Q49.0097 -46.4592 47.9941 -45.4124 L47.3847 '
'-45.4124 Q49.3222 -47.5686 49.3222 -50.053 Q49.3222 -51.3811 '
'48.8847 -52.3967 L49.4004 -52.3967 Q49.9629 -51.3342 49.9629 '
'-50.053 Z"/><path style="stroke:none;" d="M78.2253 -60.0289 '
'Q78.2253 -61.3571 78.6941 -62.4821 Q79.1628 -63.6071 80.1941 '
'-64.6852 L80.8034 -64.6852 Q79.8347 -63.6227 79.3503 -62.4508 '
'Q78.8659 -61.2789 78.8659 -60.0446 Q78.8659 -58.7164 79.3034 '
'-57.7008 L78.7878 -57.7008 Q78.2253 -58.7321 78.2253 -60.0289 '
'ZM81.7854 -61.3414 L81.2854 -58.9664 L80.6291 -58.9664 L81.8322 '
'-64.6852 L83.0822 -64.6852 Q84.8166 -64.6852 84.8166 -63.2477 '
'Q84.8166 -61.8883 83.3791 -61.4977 L84.3166 -58.9664 L83.5979 '
'-58.9664 L82.7697 -61.3414 L81.7854 -61.3414 ZM82.3635 -64.0914 '
'Q81.9729 -62.1696 81.9104 -61.9196 L82.5666 -61.9196 Q83.3166 '
'-61.9196 83.7229 -62.2477 Q84.1291 -62.5758 84.1291 -63.2008 '
'Q84.1291 -63.6696 83.8713 -63.8805 Q83.6135 -64.0914 83.0197 '
'-64.0914 L82.3635 -64.0914 ZM87.0026 -62.3414 Q87.0026 -61.0133 '
'86.526 -59.8805 Q86.0495 -58.7477 85.0338 -57.7008 L84.4245 '
'-57.7008 Q86.362 -59.8571 86.362 -62.3414 Q86.362 -63.6696 85.9245 '
'-64.6852 L86.4401 -64.6852 Q87.0026 -63.6227 87.0026 -62.3414 '
'Z"/><path style="fill:none; stroke:black;" d="M33.2875 -74.7636 '
'L33.555 -75.186 L33.8933 -74.8178"/></g><g '
'transform="translate(140,86)" style="stroke-linecap:butt; '
'text-rendering:geometricPrecision; color-rendering:optimizeQuality; '
"image-rendering:optimizeQuality; font-family:'Open Sans'; "
'color-interpolation:linearRGB; stroke-miterlimit:5;"><path '
'style="stroke:none;" d="M42.4798 32.7732 L41.4798 32.7732 L41.4798 '
'28.742 L36.9642 28.742 L36.9642 32.7732 L35.9642 32.7732 L35.9642 '
'24.2107 L36.9642 24.2107 L36.9642 27.8514 L41.4798 27.8514 L41.4798 '
'24.2107 L42.4798 24.2107 L42.4798 32.7732 Z"/><path '
'style="stroke:none;" d="M70.7788 -74.5607 L69.7788 -74.5607 '
'L69.7788 -78.592 L65.2632 -78.592 L65.2632 -74.5607 L64.2632 '
'-74.5607 L64.2632 -83.1232 L65.2632 -83.1232 L65.2632 -79.4826 '
'L69.7788 -79.4826 L69.7788 -83.1232 L70.7788 -83.1232 L70.7788 '
'-74.5607 Z"/></g></g></svg></svg></svg></svg>',
'inchi': 'InChI=1S/C20H24N2O2/c1-3-13-12-22-9-7-14(13)10-19(22)20(23)16-6-8-21-18-5-4-15(24-2)11-17(16)18/h3-6,8,11,13-14,19-20,23H,1,7,9-10,12H2,2H3/t13-,14-,19-,20+/m0/s1',
'inchiKey': 'InChIKey=LOUPRKONTZGTKE-WZBLMQSHSA-N',
'molecularFormula': 'C<sub>20</sub>H<sub>24</sub>N<sub>2</sub>O<sub>2</sub>',
'molecularMass': '324.42',
'name': 'Quinine',
'propertyCitations': [{'docUri': '',
'source': 'Drugs - Synonyms and Properties data were '
'obtained from Ashgate Publishing Co. (US)',
'sourceNumber': 1}],
'replacedRns': ['6912-57-8',
'12239-42-8',
'21480-31-9',
'55980-20-6',
'72646-90-3',
'95650-40-1',
'128544-03-6',
'767303-40-2',
'840482-04-4',
'857212-53-4',
'864908-93-0',
'875538-34-4',
'888714-03-2',
'890027-24-4',
'894767-09-0',
'898813-59-7',
'898814-28-3',
'899813-83-3',
'900786-66-5',
'900789-95-9',
'906550-97-8',
'909263-47-4',
'909767-48-2',
'909882-78-6',
'910878-25-0',
'910880-97-6',
'911445-75-5',
'918778-04-8',
'1071756-51-8',
'1267651-57-9',
'1628705-47-4',
'2244812-93-7',
'2244812-97-1',
'2409557-51-1',
'2566761-34-8',
'2929261-86-7',
'3032276-91-5'],
'rn': '130-95-0',
'smile': '[C@@H](O)(C=1C2=C(C=CC(OC)=C2)N=CC1)[C@]3([N@@]4C[C@H](C=C)[C@](C3)(CC4)[H])[H]',
'synonyms': ['Cinchonan-9-ol, 6′-methoxy-, (8α,9<em>R</em>)-',
'Quinine',
'(8α,9<em>R</em>)-6′-Methoxycinchonan-9-ol',
'6′-Methoxycinchonidine',
'(-)-Quinine',
'(8<em>S</em>,9<em>R</em>)-Quinine',
'(<em>R</em>)-(-)-Quinine',
'NSC 192949',
'WR297608',
'Qualaquin',
'Mosgard',
'Quinlup',
'Quine 9',
'Cinkona',
'Quinex',
'Quinlex',
'Rezquin',
'QSM',
'SW 85833',
'(<em>R</em>)-(6-Methoxy-4-quinolyl)[(2<em>S</em>)-5-vinylquinuclidin-2-yl]methanol',
'MeSH ID: D011803'],
'uri': 'substance/pt/130950'}
Handle multiple results#
# setup search query parameters
search_base_url = "https://commonchemistry.cas.org/api/search?q="
# SMILES for butadiene
smi_bd = "C=CC=C"
# Request data from CAS Common Chemistry Search API
smi_search_data = requests.get(search_base_url + smi_bd).json()
# get results count
print(smi_search_data["count"])
7
# extract out CAS RNs
smi_casrn_list = []
for casrn_idx in range(len(smi_search_data["results"])):
smi_casrn_list.append(smi_search_data["results"][casrn_idx]["rn"])
print(smi_casrn_list)
['106-99-0', '16422-75-6', '26952-74-9', '29406-96-0', '29989-19-3', '31567-90-5', '9003-17-2']
# now use the detail API to retrieve the full records
detail_base_url = "https://commonchemistry.cas.org/api/detail?"
smi_detail_data = []
for casrn in smi_casrn_list:
smi_detail_data.append(requests.get(detail_base_url + "cas_rn=" + casrn).json())
sleep(1) # add a delay between API calls
# Get some specific data such as name from the detail records
names = []
for name_idx in range(len(smi_detail_data)):
names.append(smi_detail_data[name_idx]["name"])
print(names)
['1,3-Butadiene', 'Butadiene trimer', 'Butadiene dimer', '1,3-Butadiene, homopolymer, isotactic', '1,3-Butadiene-<em>1</em>,<em>1</em>,<em>2</em>,<em>3</em>,<em>4</em>,<em>4</em>-<em>d</em><sub>6</sub>, homopolymer', 'Syndiotactic polybutadiene', 'Polybutadiene']
Handle multiple page results#
The CAS Common Chemistry API returns 50 results per page, and only the first page is returned by default. If the search returns more than 50 results, the offset option can be added to page through and obtain all results:
# setup search query parameters
search_base_url = "https://commonchemistry.cas.org/api/search?q="
n = "selen*"
# get results count for CAS Common Chemistry Search
num_Results = requests.get(search_base_url + n).json()["count"]
print(num_Results)
194
# Request data and save to a list in a loop for each page
n_search_data = []
for page_idx in range(int(num_Results/50 +1)): # creates [0,1,2,3] for 4 pages
page_data = requests.get(search_base_url + n + "&offset=" + str(page_idx*50)).json()
sleep(1)
n_search_data.append(page_data)
# length of search data includes a top level list for each query
len(n_search_data)
4
# lists within lists contain the results
for idx in range(len(n_search_data)):
print(len(n_search_data[idx]["results"]))
50
50
50
44
# We can index and extract out the first casrn like this
pprint(n_search_data[0]["results"][0]["rn"])
'10025-68-0'
# extract out all CAS RNs from the list of lists
n_casrn_list = []
for n_idx in range(len(n_search_data)): # top level list
for casrn_idx in range(len(n_search_data[n_idx]["results"])): # lists within top level
n_casrn_list.append(n_search_data[n_idx]["results"][casrn_idx]["rn"])
len(n_casrn_list)
194
# show first 10
pprint(n_casrn_list[0:10])
['10025-68-0',
'10026-03-6',
'10026-23-0',
'10101-96-9',
'10102-18-8',
'10102-23-5',
'10112-94-4',
'10161-84-9',
'10214-40-1',
'10236-58-5']
# now we can loop through each casrn and use the detail API to obtain the entire record
# this will query CAS Common Chem 192 times and take ~ 5 min.
detail_base_url = "https://commonchemistry.cas.org/api/detail?"
n_detail_data = []
for casrn in n_casrn_list:
n_detail_data.append(requests.get(detail_base_url + "cas_rn=" + casrn).json())
sleep(1) # !! add a delay between API calls
---------------------------------------------------------------------------
KeyboardInterrupt Traceback (most recent call last)
Cell In[37], line 6
4 n_detail_data = []
5 for casrn in n_casrn_list:
----> 6 n_detail_data.append(requests.get(detail_base_url + "cas_rn=" + casrn).json())
7 sleep(1) # !! add a delay between API calls
File /opt/hostedtoolcache/Python/3.11.10/x64/lib/python3.11/site-packages/requests/api.py:73, in get(url, params, **kwargs)
62 def get(url, params=None, **kwargs):
63 r"""Sends a GET request.
64
65 :param url: URL for the new :class:`Request` object.
(...)
70 :rtype: requests.Response
71 """
---> 73 return request("get", url, params=params, **kwargs)
File /opt/hostedtoolcache/Python/3.11.10/x64/lib/python3.11/site-packages/requests/api.py:59, in request(method, url, **kwargs)
55 # By using the 'with' statement we are sure the session is closed, thus we
56 # avoid leaving sockets open which can trigger a ResourceWarning in some
57 # cases, and look like a memory leak in others.
58 with sessions.Session() as session:
---> 59 return session.request(method=method, url=url, **kwargs)
File /opt/hostedtoolcache/Python/3.11.10/x64/lib/python3.11/site-packages/requests/sessions.py:589, in Session.request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json)
584 send_kwargs = {
585 "timeout": timeout,
586 "allow_redirects": allow_redirects,
587 }
588 send_kwargs.update(settings)
--> 589 resp = self.send(prep, **send_kwargs)
591 return resp
File /opt/hostedtoolcache/Python/3.11.10/x64/lib/python3.11/site-packages/requests/sessions.py:703, in Session.send(self, request, **kwargs)
700 start = preferred_clock()
702 # Send the request
--> 703 r = adapter.send(request, **kwargs)
705 # Total elapsed time of the request (approximately)
706 elapsed = preferred_clock() - start
File /opt/hostedtoolcache/Python/3.11.10/x64/lib/python3.11/site-packages/requests/adapters.py:486, in HTTPAdapter.send(self, request, stream, timeout, verify, cert, proxies)
483 timeout = TimeoutSauce(connect=timeout, read=timeout)
485 try:
--> 486 resp = conn.urlopen(
487 method=request.method,
488 url=url,
489 body=request.body,
490 headers=request.headers,
491 redirect=False,
492 assert_same_host=False,
493 preload_content=False,
494 decode_content=False,
495 retries=self.max_retries,
496 timeout=timeout,
497 chunked=chunked,
498 )
500 except (ProtocolError, OSError) as err:
501 raise ConnectionError(err, request=request)
File /opt/hostedtoolcache/Python/3.11.10/x64/lib/python3.11/site-packages/urllib3/connectionpool.py:790, in HTTPConnectionPool.urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, preload_content, decode_content, **response_kw)
787 response_conn = conn if not release_conn else None
789 # Make the request on the HTTPConnection object
--> 790 response = self._make_request(
791 conn,
792 method,
793 url,
794 timeout=timeout_obj,
795 body=body,
796 headers=headers,
797 chunked=chunked,
798 retries=retries,
799 response_conn=response_conn,
800 preload_content=preload_content,
801 decode_content=decode_content,
802 **response_kw,
803 )
805 # Everything went great!
806 clean_exit = True
File /opt/hostedtoolcache/Python/3.11.10/x64/lib/python3.11/site-packages/urllib3/connectionpool.py:536, in HTTPConnectionPool._make_request(self, conn, method, url, body, headers, retries, timeout, chunked, response_conn, preload_content, decode_content, enforce_content_length)
534 # Receive the response from the server
535 try:
--> 536 response = conn.getresponse()
537 except (BaseSSLError, OSError) as e:
538 self._raise_timeout(err=e, url=url, timeout_value=read_timeout)
File /opt/hostedtoolcache/Python/3.11.10/x64/lib/python3.11/site-packages/urllib3/connection.py:461, in HTTPConnection.getresponse(self)
458 from .response import HTTPResponse
460 # Get the response from http.client.HTTPConnection
--> 461 httplib_response = super().getresponse()
463 try:
464 assert_header_parsing(httplib_response.msg)
File /opt/hostedtoolcache/Python/3.11.10/x64/lib/python3.11/http/client.py:1395, in HTTPConnection.getresponse(self)
1393 try:
1394 try:
-> 1395 response.begin()
1396 except ConnectionError:
1397 self.close()
File /opt/hostedtoolcache/Python/3.11.10/x64/lib/python3.11/http/client.py:325, in HTTPResponse.begin(self)
323 # read until we get a non-100 response
324 while True:
--> 325 version, status, reason = self._read_status()
326 if status != CONTINUE:
327 break
File /opt/hostedtoolcache/Python/3.11.10/x64/lib/python3.11/http/client.py:286, in HTTPResponse._read_status(self)
285 def _read_status(self):
--> 286 line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
287 if len(line) > _MAXLINE:
288 raise LineTooLong("status line")
File /opt/hostedtoolcache/Python/3.11.10/x64/lib/python3.11/socket.py:718, in SocketIO.readinto(self, b)
716 while True:
717 try:
--> 718 return self._sock.recv_into(b)
719 except timeout:
720 self._timeout_occurred = True
File /opt/hostedtoolcache/Python/3.11.10/x64/lib/python3.11/ssl.py:1314, in SSLSocket.recv_into(self, buffer, nbytes, flags)
1310 if flags != 0:
1311 raise ValueError(
1312 "non-zero flags not allowed in calls to recv_into() on %s" %
1313 self.__class__)
-> 1314 return self.read(nbytes, buffer)
1315 else:
1316 return super().recv_into(buffer, nbytes, flags)
File /opt/hostedtoolcache/Python/3.11.10/x64/lib/python3.11/ssl.py:1166, in SSLSocket.read(self, len, buffer)
1164 try:
1165 if buffer is not None:
-> 1166 return self._sslobj.read(len, buffer)
1167 else:
1168 return self._sslobj.read(len)
KeyboardInterrupt:
# Extract out some data such as molecularMass
mms = []
for mm_idx in range(len(n_detail_data)):
mms.append(n_detail_data[mm_idx]["molecularMass"])
len(mms)
192
# view first 20
# note that several do not have molecularMass values and have an empty string in the record
print(mms[0:20])
['228.83', '220.77', '', '', '', '', '', '300.24', '', '168.05', '', '', '', '', '', '241.11', '', '368.25', '265.00', '']
# finally, we can quickly create a simple visualization from the
# extracted molecularMass values (from the selen* search)
# remove empty strings
mms_values = list(filter(None, mms))
# convert to floats
mms_values_float = []
for mms_value in mms_values:
mms_values_float.append(float(mms_value))
# import numpy and matplotlib
import matplotlib.pyplot as plt
# plot data
plt.figure(figsize=(10,7))
plt.hist(mms_values_float, histtype='bar',bins = 20, facecolor="blue", alpha=0.5)
plt.title("Histogram of available molecularMass values for selen* search")
plt.xlabel("molecularMass")
plt.ylabel("Count")
plt.show()