# \[ANN\] Mendeleev.jl - accessing chemical elements data

**URL:** <https://discourse.julialang.org/t/ann-mendeleev-jl-accessing-chemical-elements-data/89804>\
**Category:** Package Announcements\
**Tags:** physics, chemistry\
**Created:** [November 5, 2022, 10:01am UTC](https://discourse.julialang.org/t/ann-mendeleev-jl-accessing-chemical-elements-data/89804 "2022-11-05T10:01:17Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eben60](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/eben60/32/13475_2.png) [@Eben60](https://discourse.julialang.org/u/Eben60)\
**Post date:** [November 5, 2022, 10:01am UTC](https://discourse.julialang.org/t/ann-mendeleev-jl-accessing-chemical-elements-data/89804/1 "2022-11-05T10:01:17Z")

</div>

I am excited to announce [Mendeleev](https://github.com/Eben60/Mendeleev.jl) - a database of chemical elements. The package is API compatible with the venerable [PeriodicTable](https://github.com/JuliaPhysics/PeriodicTable.jl), but contains data on much more properties (about 100), including e.g. atomic and ionic radii, ionization energies, isotopic composition etc. The data are mostly taken over from the Python [mendeleev](https://github.com/lmmentel/mendeleev) package, and the data sources are [documented](https://mendeleev.readthedocs.io/en/stable/data.html) therein.

For more information see [the package documentation](https://docs.juliahub.com/Mendeleev). The package has already been registered a while ago, but by now I’ve implemented all initially planned features. The API stems from [PeriodicTable](https://github.com/JuliaPhysics/PeriodicTable.jl), which has been stable for long time now, and is not going to change in a breaking way. The current package version is 0.3.0, but the plan is to wait a couple of months and then set it to 1.0.0.

---

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [November 5, 2022, 11:38am UTC](https://discourse.julialang.org/t/ann-mendeleev-jl-accessing-chemical-elements-data/89804/2 "2022-11-05T11:38:45Z")

</div>

Can’t this effort be merged with PeriodicTable.jl to help the lives of existing users?

---

<div class="post-metadata">

**Author:** ![Eben60](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/eben60/32/13475_2.png) [@Eben60](https://discourse.julialang.org/u/Eben60)\
**Post date:** [November 5, 2022, 12:31pm UTC](https://discourse.julialang.org/t/ann-mendeleev-jl-accessing-chemical-elements-data/89804/3 "2022-11-05T12:31:03Z")

</div>

In principle it can - meaning the PeriodicTable.jl source must be completely replaced by the Mendeleev.jl source. At the start of the project I [asked](https://github.com/Eben60/Mendeleev.jl/issues/1) the PeriodicTable contributors, just got no answer. I’m still open to it, however now Mendeleev is so much more extensive as compared to PeriodicTable, I’d prefer it keeps it’s identity and PeriodicTable docs point to Mendeleev as a successor.

As for lives of existing users: just write  
`using Mendeleev: elements, Element` instead of  
`using PeriodicTable`, and you are fine

---

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [November 5, 2022, 12:45pm UTC](https://discourse.julialang.org/t/ann-mendeleev-jl-accessing-chemical-elements-data/89804/4 "2022-11-05T12:45:12Z")

</div>

@Eben60 I found the exact issue in PeriodicTable.jl where you mentioned the new Mendeleev.jl package:

> <https://github.com/JuliaPhysics/PeriodicTable.jl/issues/41>
>
> There are a couple of open issues regarding adding of additional information, wh…ich have no progress in part due to laziness of the authors of these issues (myself included).
> 
> On the other hand, it seems to me that the internal organization of the information in the package might play a part in it (of course it is totally subjective). Let's say you want to add additional information to existing element type. Then, you have to create a new type with additional fields. Then, you have to go over all the lines where elements are defined and add the data in new fields. Sounds a bit complicated. When you start thinking about adding isotopic information, it gets even more complicated.
> 
> The counterpart of \`PeriodicTable.jl\` in python community is \`mendeleev\`. It is interesting that they store all the data as an sqlite database with several interconnected tables. May be we can take inspiration from that?
> 
> In Julia case, I think we might not need the whole database, but we can store the data in a dataframe (or several linked dataframes instead). Overall, it should make working with the information rather convenient. For example, one can add additional fields to the elements by appending a column with the relevant data. One can also leverage dataframe utilities and do all kinds of querying on the information.
> 
> This approach also lends itself nice for the purpose of introduction of isotopic information: we can create an additional dataframe which will store isotope-dependent information, and the proton number can be used to establish foreign key relationship with the main dataframe storing the elements.
> 
> We can also simply copy the database from \`mendeleev\`, provided that its maintainers are ok with that.

From your comment it wasn’t clear that you intended to merge the package or join efforts, maybe you should state it more clearly or open a new issue with maintainers to do so?

It would be super helpful for the community of users, the more maintainers and collaborators in a big initiative like this the better. It is annoying to maintain so much data alone.

---

<div class="post-metadata">

**Author:** ![Eben60](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/eben60/32/13475_2.png) [@Eben60](https://discourse.julialang.org/u/Eben60)\
**Post date:** [November 5, 2022, 1:23pm UTC](https://discourse.julialang.org/t/ann-mendeleev-jl-accessing-chemical-elements-data/89804/5 "2022-11-05T13:23:13Z")

</div>

> [@juliohm](#):
>
> it wasn’t clear that you intended to merge the package or join efforts

It takes at least two to tango.

---

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [November 5, 2022, 3:57pm UTC](https://discourse.julialang.org/t/ann-mendeleev-jl-accessing-chemical-elements-data/89804/6 "2022-11-05T15:57:30Z")

</div>

> [@Eben60](#):
>
> It takes at least two to tango.

You mean that you are not interested in putting your work in PeriodicTable.jl? Because from your comment in that issue there was no explicit sentence saying that you were willing to submit a PR to the package.

---

<div class="post-metadata">

**Author:** ![Eben60](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/eben60/32/13475_2.png) [@Eben60](https://discourse.julialang.org/u/Eben60)\
**Post date:** [November 5, 2022, 4:56pm UTC](https://discourse.julialang.org/t/ann-mendeleev-jl-accessing-chemical-elements-data/89804/7 "2022-11-05T16:56:28Z")

</div>

> [@juliohm](#):
>
> You mean that you are not interested in putting your work in PeriodicTable.jl?

Firstly I mean it makes little sense to discuss my intentions without the other side taking part in the discussion at all - I have reached out several times for them. Also, I am not sure the current state of the PeriodicTable.jl can be really described as “maintained”.

---

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [November 5, 2022, 5:09pm UTC](https://discourse.julialang.org/t/ann-mendeleev-jl-accessing-chemical-elements-data/89804/8 "2022-11-05T17:09:50Z")

</div>

I am just trying to avoid yet another split in the tiny community we are already. I am not involved with PeriodicTable.jl but was planning to use it in a project. Now that I know it is not maintained, I will take a look into the alternative.

---

<div class="post-metadata">

**Author:** ![Eben60](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/eben60/32/13475_2.png) [@Eben60](https://discourse.julialang.org/u/Eben60)\
**Post date:** [November 5, 2022, 5:25pm UTC](https://discourse.julialang.org/t/ann-mendeleev-jl-accessing-chemical-elements-data/89804/9 "2022-11-05T17:25:08Z")

</div>

I do not maintain it is “not maintained”. A couple of PRs I’ve made in the process of re-checking the data were merged. A couple of open issues just stay open. On the other side, the software itself is not going to break on Julia updates, and the data just reflect the physical world - so presumably PeriodicTable will stay just as usable for the years to come as it is now.

Now - may I ask you in which way do you plan to use PeriodicTable? There are some packages using it, but they just use the interface and maybe the atomic weights, and I have difficulties imagining any other serious use. To be honest I don’t see why the physical properties of elemental substances are in any way special.

---

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [November 5, 2022, 5:36pm UTC](https://discourse.julialang.org/t/ann-mendeleev-jl-accessing-chemical-elements-data/89804/10 "2022-11-05T17:36:02Z")

</div>

I will probably need PeriodicTable.jl for basic stoichiometry, nothing sophisticated.

---

<div class="post-metadata">

**Author:** ![Eben60](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/eben60/32/13475_2.png) [@Eben60](https://discourse.julialang.org/u/Eben60)\
**Post date:** [November 5, 2022, 5:43pm UTC](https://discourse.julialang.org/t/ann-mendeleev-jl-accessing-chemical-elements-data/89804/11 "2022-11-05T17:43:31Z")

</div>

Atomic weights (maybe with an exception or two) are stable over the years. You will be equally well served by any of the both packages.

---

<div class="post-metadata">

**Author:** ![Eben60](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/eben60/32/13475_2.png) [@Eben60](https://discourse.julialang.org/u/Eben60)\
**Post date:** [November 13, 2022, 6:46pm UTC](https://discourse.julialang.org/t/ann-mendeleev-jl-accessing-chemical-elements-data/89804/12 "2022-11-13T18:46:37Z")

</div>

> [@juliohm](#):
>
> I will probably need PeriodicTable.jl for basic stoichiometry, nothing sophisticated.

Actually that’s apparently the only (visible, i.e in a registered package) use of the PeriodicTable: Stoichiometry and the fancy indexing. As these functionalities are the most used, I’ve decided to split out a separate minimalistic package from Mendeleev, with these functionalities only, no dependencies, no extra data etc… Then however I couldn’t resist a temptation to add some sugar onto these bare-bones. The package is already fully functional and to be registered after adding tests, documentation etc.

```julia
using ChemElementsBB

K = chem_els["potassium"]
Ca = chem_els[:Ca]
P = chem_els[15] # three ways of indexing similar to PeriodicTable
O = chem_els.O # one more (Mendeleev)

julia> O
Oxygen (O) - element 8, m=15.999

julia> K / (K + Ca + P + 4*O)
0.22451440791379498

```

Macro to create element-named-variables (doing in effect the same as the code above).

```julia
using ChemElementsBB
@import_els K Ca P O

julia> K
Potassium (K) - element 19, m=39.0983

@import_els O:Ca

julia> F
Fluorine (F) - element 9, m=18.998403163

```

On this basis another separate package for chemical formulas is feasible, along the lines of [ChemEquations.jl](https://discourse.julialang.org/t/ann-chemequations-jl-write-and-balance-chemical-equations-elegantly-and-efficiently/44153). The usage then could be like

```julia
julia> K/cf"KCaPO4"
0.22451440791379498

```

---

<div class="post-metadata">

**Author:** ![Eben60](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/eben60/32/13475_2.png) [@Eben60](https://discourse.julialang.org/u/Eben60)\
**Post date:** [November 13, 2022, 6:56pm UTC](https://discourse.julialang.org/t/ann-mendeleev-jl-accessing-chemical-elements-data/89804/13 "2022-11-13T18:56:40Z")

</div>

> [@Eben60](#):
>
> Atomic weights (maybe with an exception or two) are stable over the years.

Now an off-topic quiz question. With an “an exception or two” I have really meant it, and not on the geological scale. The atomic weight of an element from an old container in lab may deviate substantially from one of a freshly bought sample. Which, why?

---

<div class="post-metadata">

**Author:** ![berquist](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/berquist/32/14270_2.png) [@berquist](https://discourse.julialang.org/u/berquist)\
**Post date:** [November 13, 2022, 7:22pm UTC](https://discourse.julialang.org/t/ann-mendeleev-jl-accessing-chemical-elements-data/89804/14 "2022-11-13T19:22:56Z")

</div>

Radioactive decay? My first thought was other sorts of decomposition, or if something is hygroscopic, but that’s not exactly the same thing as the atomic weight changing.

---

<div class="post-metadata">

**Author:** ![Eben60](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/eben60/32/13475_2.png) [@Eben60](https://discourse.julialang.org/u/Eben60)\
**Post date:** [November 13, 2022, 7:29pm UTC](https://discourse.julialang.org/t/ann-mendeleev-jl-accessing-chemical-elements-data/89804/15 "2022-11-13T19:29:30Z")

</div>

no, nothing that dangerous 🙂

---

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [November 14, 2022, 10:38am UTC](https://discourse.julialang.org/t/ann-mendeleev-jl-accessing-chemical-elements-data/89804/16 "2022-11-14T10:38:07Z")

</div>

Can any of these packages be used to parse a string like `"NaPb2(CO3)2(OH)"` into a vector of chemical elements `[:Na, :Pb, :C, :O, :H]` and a vector of counts `[1, 2, 2, 7, 1]`?

Appreciate if someone can share some code snippet to achieve this result. Let me know if there is a package to parse formulas like the above.

---

<div class="post-metadata">

**Author:** ![Eben60](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/eben60/32/13475_2.png) [@Eben60](https://discourse.julialang.org/u/Eben60)\
**Post date:** [November 14, 2022, 11:57am UTC](https://discourse.julialang.org/t/ann-mendeleev-jl-accessing-chemical-elements-data/89804/17 "2022-11-14T11:57:32Z")

</div>

> [@juliohm](#):
>
> Can any of these packages be used to parse a string like `"NaPb2(CO3)2(OH)"` i

Not yet, but that is exactly what I was thinking of:

> [@Eben60](#):
>
> On this basis another separate package for chemical formulas is feasible, along the lines of [ChemEquations.jl](https://discourse.julialang.org/t/ann-chemequations-jl-write-and-balance-chemical-equations-elegantly-and-efficiently/44153). The usage then could be like

In the meanwhile I’ve just discovered another related package - [UnitfulMoles.jl](https://github.com/rafaqz/UnitfulMoles.jl) by @Raf

---

<div class="post-metadata">

**Author:** ![Eben60](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/eben60/32/13475_2.png) [@Eben60](https://discourse.julialang.org/u/Eben60)\
**Post date:** [November 14, 2022, 12:42pm UTC](https://discourse.julialang.org/t/ann-mendeleev-jl-accessing-chemical-elements-data/89804/18 "2022-11-14T12:42:07Z")

</div>

UnitfulMoles parses `@compound H2O` , but unfortunately fails on `@compound NaPb2(CO3)2(OH)`

---

<div class="post-metadata">

**Author:** ![Eben60](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/eben60/32/13475_2.png) [@Eben60](https://discourse.julialang.org/u/Eben60)\
**Post date:** [November 14, 2022, 12:52pm UTC](https://discourse.julialang.org/t/ann-mendeleev-jl-accessing-chemical-elements-data/89804/19 "2022-11-14T12:52:56Z")

</div>

```julia
julia> using ChemEquations

julia> c = cc"NaPb2(CO3)2(OH)"
NaPb2C2O7H

julia> c.tuples
5-element Vector{Tuple{String, Int64}}:
 ("Na", 1)
 ("Pb", 2)
 ("C", 2)
 ("O", 7)
 ("H", 1)

```

---

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [November 14, 2022, 1:42pm UTC](https://discourse.julialang.org/t/ann-mendeleev-jl-accessing-chemical-elements-data/89804/20 "2022-11-14T13:42:04Z")

</div>

That is great. Do you know if it also works with subscript? \_2 I’m far from my computer at the moment, will check when I get acess to it.

[Next page](https://discourse.julialang.org/t/ann-mendeleev-jl-accessing-chemical-elements-data/89804.md?page=2)
