Introduction to Chempy in Python
Last Updated :
19 Aug, 2021
ChemPy is a python package designed mainly to solve problems in analytical, physical and inorganic Chemistry. It is a free, open-source Python toolkit for chemistry, chemical engineering, and materials science applications.
ChemPy includes classes for representing substances, reactions, and systems of reactions. It also includes well-established formulae from physical chemistry, as well as analytic solutions to some differential equations commonly encountered in chemical kinetics.
Its intended audience is primarily researchers and engineers who need to perform modeling work. But since the intermediate representations of, e.g., ODE systems and systems of non-linear equations are available symbolically, ChemPy may also be used in an educational setting.
Installation: ChemPy can be installed by running the following script in the Command Prompt / Terminal:
pip install chempy
Here are some examples of the application of the ChemPy module :
Example 1 : Printing a list of elements with their mass.
Python3
from chempy.util import periodic
n = 10
print ( "Atomic No.\tName\t\tSymbol\t\tMass" )
for i in range ( 1 , n + 1 ):
print (i, end = "\t\t" )
if len (periodic.names[i]) > 7 :
print (periodic.names[i], end = "\t" )
else :
print (periodic.names[i], end = "\t\t" )
print (periodic.symbols[i], end = "\t\t" )
print (periodic.relative_atomic_masses[i])
|
Output :
Atomic No. Name Symbol Mass
1 Helium He 4.002602
2 Lithium Li 6.94
3 Beryllium Be 9.0121831
4 Boron B 10.81
5 Carbon C 12.011
6 Nitrogen N 14.007
7 Oxygen O 15.999
8 Fluorine F 18.998403163
9 Neon Ne 20.1797
10 Sodium Na 22.98976928
Example 2 : Let us see how to represent chemical reactions in ChemPy. Consider the formation of water. In the reaction, 2 H2 molecules combine with an O2 molecule to form 2 H2 molecules. In ChemPy the reaction will be created using the Reaction() function of the chempy.chemistry module.
Python3
from chempy import chemistry
reaction = chemistry.Reaction({ 'H2' : 2 , 'O2' : 1 },
{ 'H2O' : 2 })
print (reaction)
print (reaction.order())
|
Output :
2 H2 + O2 -> 2 H2O
3
Share your thoughts in the comments
Please Login to comment...