Crates.io | chemistry_parser |
lib.rs | chemistry_parser |
version | 0.1.3 |
source | src |
created_at | 2024-11-13 02:08:59.850009 |
updated_at | 2024-11-15 15:38:54.214243 |
description | A parser for the analysis of chemical elements, formulas and equations. |
homepage | |
repository | https://github.com/lillydaystar/chemistry_parser |
max_upload_size | |
id | 1445832 |
size | 391,045 |
Link: https://crates.io/crates/chemistry_parser Docs: https://docs.rs/chemistry_parser/latest/chemistry_parser/
A parser for the analysis of chemical elements, formulas and equations. This parser is designed to automate the processing of chemical formulas and equations, providing structured information about each element in the formula, as well as the ability to recognize and check the correctness of chemical equations.
H
, O
, Na
.H2O
, H2SO4
, CH3(CH2)4CH3
2H2 + O2 -> 2H2O
The parser processes chemical elements, formulas and equations in the following steps:
element
): An element is identified by its symbol(s) in the periodic table.formula
): Each element in the formula is identified by its symbol and number of atoms (index
). For example, in the formula C6H12O6
, the parser will determine the symbols C
, H
, and O
with the corresponding indices. The molecular mass is calculated based on the elements and their indices in the chemical formula.group
): The parser processes groups enclosed in brackets, for example Al2(SO4)3
. The parser multiplies the count of elements inside the group by the number outside the brackets.equation
): The parser separates reactants and products, which makes it possible to determine the structure of the reaction. It ensures the correct format, parsing both the reactants and the products. This makes it possible to determine if the equation is balanced.Element
: parsed element with its information from the periodic table;Formula
: parsed formula with its elements and molecular mass;Equation
: parsed equation with its reactants and products.The parsing process is described in the diagram below:
The CLI interface allows interaction with the parser using different commands.
cargo run help
Output:
Use following commands:
help Show all commands
credits Show credits
symbol <element-symbol> Parse the element and print information about it
formula <chemical-formula> Parse the formula and print information about it
equation <chemical-equation> Parse the chemical equation and print its formulas
check <chemical-equation> Check if the chemical equation is balanced
file <file-path> Parse the file with chemical equations and solve them
The parser uses the Hydrogen to Oganesson: Periodic Insights dataset to define and validate the symbols of chemical elements