Open jdbocarsly opened 3 months ago
Yes, this is part of the same issue. I've been meaning to fix this for a while, so will go on and try to come up with something that works nicely across a wider range of cases. For the mean time, the formula is actually just stored as a string in the database, so even though the display is incorrect, your data should be intact (you can see the actual data stored by clicking in the field in the UI)
I think we should also have a fail-safe, if the entire formula cannot be captured by whatever regexp we conjure up for the formatting, it should just show the formula unformatted.
I think we should also have a fail-safe, if the entire formula cannot be captured by whatever regexp we conjure up for the formatting, it should just show the formula unformatted.
good idea
I am also am thinking of all the ways we often express formulas, like Li1-xCoO2 if we aren't sure about x. It probably will be hard to properly handle everything people want to do, but we can certainly do a bit better.
This package might help: https://pypi.org/project/chemformula/#:~:text=Description-,ChemFormula%20is%20a%20Python%20class%20for%20working%20with%20chemical%20formulas,4%E2%8B%85H2O.
Doesn't do variable occupancy - I guess it depends what is required.
Trouble is this part of the code is JavaScript (though I'm sure a similar package exists) -- we could do the parsing on the server side but it would need another round-trip so probably want to avoid it
This might be the same issue, but if you put in the chemical formula section (NH4)2(SO4) it renders as NH$_4$SO$_4$ - this is pretty important for molecular stuff. Might be nice to have it also expand it to the empirical formula & molecular mass?