# CAS Common Chemistry

**URL:** <https://discourse.julialang.org/t/cas-common-chemistry/76429>\
**Category:** Chemistry\
**Created:** [February 14, 2022, 12:15pm UTC](https://discourse.julialang.org/t/cas-common-chemistry/76429 "2022-02-14T12:15:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tp2750](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tp2750/32/207806_2.png) [@tp2750](https://discourse.julialang.org/u/tp2750)\
**Post date:** [February 14, 2022, 12:15pm UTC](https://discourse.julialang.org/t/cas-common-chemistry/76429/1 "2022-02-14T12:15:17Z")

</div>

Is there a Julia package for accessing the CAS Common Chemistry database?

> **[CAS Common Chemistry](https://commonchemistry.cas.org/)**
>
> Quickly confirm chemical names, CAS Registry Numbers®, structures or basic physical properties by searching compounds of general interest or leveraging an API connection.

---

<div class="post-metadata">

**Author:** ![jd-foster](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jd-foster/32/35824_2.png) [@jd-foster](https://discourse.julialang.org/u/jd-foster)\
**Post date:** [April 8, 2022, 1:26am UTC](https://discourse.julialang.org/t/cas-common-chemistry/76429/2 "2022-04-08T01:26:19Z")

</div>

You might not need a package depending on how much processing you require?  
For example, I found this tutorial […in Python — Scholarly API Cookbook](https://ualibweb.github.io/UALIB_ScholarlyAPI_Cookbook/content/scripts/python/python_casc.html)  
It is reasonably direct to adapt it to Julia:

```julia
using HTTP
using JSON

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

data = HTTP.request("GET", detail_base_url*"cas_rn="*casrn1)
body = String(data.body)

casrn1_data = JSON.parse(body)

# We can then use the data: for example, get an SVG of the format
write(casrn1*".svg", casrn1_data["image"])
# or continue with the tutorial example:
casrn1_data["experimentalProperties"][1]

```

If you’re interested in writing this into a package, happy to help.

---

<div class="post-metadata">

**Author:** ![tp2750](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tp2750/32/207806_2.png) [@tp2750](https://discourse.julialang.org/u/tp2750)\
**Post date:** [April 10, 2022, 2:08pm UTC](https://discourse.julialang.org/t/cas-common-chemistry/76429/3 "2022-04-10T14:08:46Z")

</div>

Thanks for the link and suggestions @jd-foster .

Could be fun to write a package like that together.

---

<div class="post-metadata">

**Author:** ![tp2750](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tp2750/32/207806_2.png) [@tp2750](https://discourse.julialang.org/u/tp2750)\
**Post date:** [October 1, 2022, 9:14pm UTC](https://discourse.julialang.org/t/cas-common-chemistry/76429/4 "2022-10-01T21:14:33Z")

</div>

Now there is a package for accessing the CAS Common Chemistry API: [GitHub - tp2750/CasCommonChemistry.jl](https://github.com/tp2750/CasCommonChemistry.jl)

It only exports two functions: `cas`, `cas_search`.  
For interactive use, the `cas` function should all that is needed.

It takes a query string as input, and returns a DataFrame of matching records:

```julia
julia> using CasCommonChemistry

julia> cas("water")
# [ Info: Found 1 results from query 'water'. Fetching 1..1
# 1×15 DataFrame
# Row │ hasMolfile rn name inchi replacedRns smile experimentalProperties ⋯
# │ Bool String String String Vector{Any} String Vector{Any} ⋯
# ─────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
# 1 │ true 7732-18-5 Water InChI=1S/H2O/h1H2 Any["558440-22-5", "558440-53-2"… O Any[Dict{String, Any}("name"=>"B… ⋯

```

It is not registered yet.

Comments are welcome.
