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

Add unicode form formula #225

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

montmorill
Copy link
Contributor

@montmorill montmorill commented Sep 18, 2023

eg.:

from chempy import balance_stoichiometry, Reaction
from chempy.printing import unicode_

reac = {"H+", "SO4-2"}
prod = {"H2SO4"}
reac, prod = balance_stoichiometry(reac, prod)
print(unicode_(Reaction(reac, prod)))

before: 2 H+ + SO4-2 → H2SO4
after: 2 H⁺ + SO₄²⁻ → H₂SO₄

@bjodah
Copy link
Owner

bjodah commented Sep 18, 2023

For simple substances this is a nice change of default. However, I do worry that for other substances which are typically entered by their field specific code name (which may contain digits), e.g G6P for glucose-6-phosphate, then this default might be unwanted. We have a .unicode_name field on the Substance class. But it is only set by the parser I think.

Perhaps something along these lines would be preferable (I'm thinking out loud here, I'm not asking you the implement the following):

>>> r1 = Reaction.parse("H+ + SO4-2 -> H2SO4", elements_in_formula=True)
>>> r2 = r1.balanced()
>>> r2
2 H⁺ + SO₄²⁻ → H₂SO₄

That way, someone who is entering e.g. "G6P" may pass a different flag to the .parse method. What do you think?

I find that printing options in general are a bit tricky, since the preferred defaults may differ quite a bit between different fields...

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

Successfully merging this pull request may close these issues.

2 participants