Saturday, November 23, 2024
Google search engine
HomeLanguagesIntroduction to Chempy in Python

Introduction to Chempy in Python

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




# importing the module
from chempy.util import periodic
 
# number of elements to be fetched
n = 10
 
# displaying the information
print("Atomic No.\tName\t\tSymbol\t\tMass")
 
# fetching the information for
# the first 10 elements
for i in range(1, n + 1):
 
    # displaying the atomic number
    print(i, end = "\t\t")
 
    # displaying the name
    if len(periodic.names[i]) > 7:
        print(periodic.names[i], end = "\t")
    else:
        print(periodic.names[i], end = "\t\t")
 
    # displaying the symbol
    print(periodic.symbols[i], end = "\t\t")
 
    # displaying the mass
    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




# importing the module
from chempy import chemistry
 
# creating the reaction
reaction = chemistry.Reaction({'H2': 2, 'O2': 1},
                              {'H2O': 2})
 
# displaying the reaction
print(reaction)
 
# displaying the reaction order
print(reaction.order())


Output : 
 

2 H2 + O2 -> 2 H2O
3

 

RELATED ARTICLES

Most Popular

Recent Comments