Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Chemical formula formatting of formulas such as Na2/3CoO2 and Ni(NO3)2.6H2O #634

Open
jdbocarsly opened this issue Mar 8, 2024 · 6 comments
Assignees

Comments

@jdbocarsly
Copy link
Member

No description provided.

@MJCliffe
Copy link

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?

@jdbocarsly
Copy link
Member Author

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)

@ml-evs
Copy link
Member

ml-evs commented May 17, 2024

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.

@jdbocarsly
Copy link
Member Author

jdbocarsly commented May 17, 2024

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.

@MJCliffe
Copy link

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.

@ml-evs
Copy link
Member

ml-evs commented May 18, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants