It is mostly based on the syntax of Balance Chemical Equation - Online Balancer, but it is more flexible. It uses ce"H2 + O2 = H2O" syntax for equations and cc"H2O" for compounds.
I want to hear the opinions on package’s API and syntax. Are they intuitive? Do they follow the best conventions?
After another round of review, I’ll write a post on my blog about the package. Maybe there’ll be another blog post, sharing my experience with the automated tests and documentation. The package is 100% documented and 100% tested (100% coverage) after all.
Nice package!, the API seems concise enough. a few feature requests on my part :
an option to display a fractional balance? balance(chemeq,int=false) that fixes the the least relative abundant element to 1 mol and gives a float result?
molecular_weight(chemelem) ?
is there a way to query if the compound has a ring? (in the webhc example, they do something with this, using this example: (C6H5C2H5 + O2 = C6H5OH + CO2 + H2O )
nice package, would be good for pedagogical use, or make a cool web app for students.
Would be nice if it could dump to LaTeX maybe. Just a passing thought, but yea great concept, execution looks usable to me!
If you want bells and whistles, you can add support for building a ReactionNetwork from a collection of ChemEquations haahah (I’m gonna check on how can it be done and do a PR)
Do you want it just to be displayed that way, or also for data to be stored as Rational? Currently Compound and ChemEquation structs work with Ints only, but it can be reworked. That would even support compounds with fractional or even real indexes and charges (doesn’t make sense chemically, but it does mathematically).
Do you have an idea how they check it? We can try to write some basic function that checks for “C6H12”, “C6H6”, “C6H5…” and unicode characters that are rings. Although more advanced verification would require adding oxidation numbers. It’s a nice feature to have nevertheless.
I had the same ideas in mind, I’m glad that you recognized that.
LaTeX output can be done nicely by just replacing = with \to arrow, {digits} with _{digits} and {+-charge}^{+-charge}. Is there some more generic way to convert the output to LaTex, though?
Respecting to the detection of aromatic rings, I don’t thibk is good to detect automatically, but using the ring unicode seems good! (one more point for Julia and its unicode support)
Although it is fairly easy if your formula is written with a unicode character representing a ring (as suggested above).
That’s great. If there is something to do to help you with the integration, please suggest it. I’m currently abstracting compounds and chemequations to work on any number, not just integer. (If constructed manually of course, parsing that isn’t easy…)
Yes if you are using a ring as a unicode it does tell you something about aromaticity. Is this using emipirical formulas(IE:C2H6) or just anything someone types in(IE: CH3CH3)? I may be misunderstanding the scope. It’s actually difficult to create a symbolic language to display chemicals uniquely. One that I use on computers is SMILES.
All I’d need from it would be the output :). So a collection of maps like the following: compound_name => stoich. Maybe one for each rxn in a network. But maybe we could work on it together, it’d be a pretty short and sweet application.
Instead of loading “heavy” packages AbstractAlgebra for one method and LinearAlgebra for I (identity matrix), ChemEquations now uses LinearAlgebraX. It calculates nullspace and other matrix operations exactly if that possible, generically.
ce and cc are removed from Base.show() methods, so that copy-paste from REPL is easier.
Although not 100% percent in the way you wanted, since
julia> balance(ce"C2H4 + O2 = CO2 + H2O", fractions=true)
1//2 C2H4 + 3//2 O2 = CO2 + H2O
But on the other side, this is the “neatest” solution, as the number of coefficients equal to 1 is maximal. If you still want scaling to 1, which way would you prefer it to called?
There is nothing inherently special about redox reactions.
Even some chemists overlook it, but if the system of equations is specified correctly (matrix of coefficients is correct and system of linear equations can be solved) then the chemical reaction can be balanced regardless of it’s “chemical” nature.
After all it’s just about balancing numbers of atoms on the both sides, you don’t even have to really know chemistry if (correct) equation(s) to balance are written.