Sciencemadness Discussion Board

Code of web application for balancing chemical equations made available

woelen - 22-1-2020 at 12:26

Some people may know my web application for balancing chemical equations:

https://woelen.homescience.net/chemeq

Click the help button for usage information and detailed background info.

---------------------------------------------------------------------------------------------------------

I cleaned up the code and made it available for others.

https://gitlab.com/chemeq/chemeq
https://gitlab.com/chemeq/chemeqweb

The first link is the interesting part. It contains the code for parsing chemical equations and solving the chemical equations. The algorithm, used for solving the equation, is based on first transforming the chemical equation to an homogeneous matrix equation of the form Ax = 0. The next step is finding the null-space of this equation. For most equations, the vector x is in a one-dimensional solution space. The coefficients then are fixed, up to a certain scaling factor (e.g. 2 H2 + O2 --> 2 H2O is equivalent to 4 H2 + 2 O2 --> 4 H2O). Sometimes, however, the solution space has a higher dimension (a nice example is Cu + HNO3 --> Cu(NO3)2 + NO + NO2 + H2O, which has a 2-dimensional solution space).
More info can be found in the code.

The second link is the code to a web project, which uses the library of the first link. The library is set up generally and can be used in any program (e.g. a mobile app, your own, still to be developed awesome program). The web application is a WAR file, which can be deployed in any recent Tomcat, using a Java 11 JVM or newer.

Building can be done as follows:
- Install maven on your machine and set up a local repositiy.

- Git clone the chemeq repository and go to the chemeq directory (where you see the file pom.xml)
- Give the command ' mvn clean'
- Give the command ' mvn package' --> this builds chemeq-1.0.jar
- Give the command ' mvn install' --> this places the library in your local repository
- Go up one directory

- Git clone the chemeqWeb repository and go to the chemeqWeb directory (where you see the file pom.xml).
- Give the command ' mvn clean'
- Give the command ' mvn package' --> this builds chemeqWeb-1.0.war
- Go up one directory

Deploy the file chemeqWeb/target/chemeqWeb-1.0.war in the webapps directory of a suitably installed and configured Tomcat, running on Java 11 or newer. You will find the application in the /chemeq context.



[Edited on 23-1-20 by woelen]