andrejewski / periodic-table

Periodic elements data

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Parsing Complex Formulae

sabidhasan opened this issue · comments

Hello,

Would you be open to a modification of the atomicMass function that allows it to parse complex formulae?

I mean two things by this:

  1. Natural formulas with no spaces between the elements (C6H12O6 rather than C6 H12 O6)
  2. Brackets (eg C2[Cr(H2O)4]2N2 for the sake of illustration)

I wrote a Python module at one point with this functionality so it should be pretty easy to port to JS.

If interested, I can fork and make a PR

@sabidhasan perhaps you are interested for a similar solution in C++? Then take a look at my repository GTK-Periodic-Table-Molecular-Formula ...

Might I recommend adding a separate helper function that would format a given complex string into one more readable by functions like atomicMass? I could write one up and make a PR fairly easily if need be; I've worked on a similar project in JS before.