bjodah / chempy

⚗ A package useful for chemistry written in Python
BSD 2-Clause "Simplified" License
536 stars 79 forks source link

Check if reaction is stoichiometry balanced #194

Closed rcolpo closed 2 years ago

rcolpo commented 3 years ago

Is there are why to check if a chemical equation is stoichiometry balanced?

For example, "C5H6N2O5 + H + HO4P = C4H6N1O4 + C1H2N1O5P1" is balanced and should return True. "C5H6N2O5 + HO4P = C4H6N1O4 + C1H2N1O5P1" is unbalanced and should return false.

bjodah commented 3 years ago

Sure, if you create a ReactionSystem (using .from_string is the easiest when your substances are represented by their chemical formulae), you can call .obeys_mass_balance(): https://github.com/bjodah/chempy/blob/dd8b934e9f2732d26ba6b5a71e5ee908079bd739/chempy/reactionsystem.py#L356