This Jupyter notebook demonstrate the use of the symbolic algebra package `Sympy`

for the generation/consumption analysis for the production of ammonia using basic principles of reaction stoichiometry.

BASF, headquartered in Ludwigshafen, Germany, is the largest chemical company in the world. In 1913, under its original name Badische Anilin- und Soda-Fabrik, BASF commercialized the Haber-Bosch process for the production of ammonia from natural gas, water, and air.

Prior to this invention, American and European agriculture was dependent on guano mined from the 'Guano Islands' in the Caribbean Sea and Pacific Ocean, and saltpeter mined from the deserts of Peru, Chile, and Bolivia. The competition for these limited resouces led to the notorious U.S. Guano Islands Act of 1856, and multiple wars (the Guano War, the War of the Pacific, later resulting in acute fertilizer shortages that was called 'the Wheat Problem' in England by Sir William Crookes in 1898.

The following video produced by BASF provides a technical overview of the Haber-Bosch process.

In [1]:

```
from IPython.display import YouTubeVideo
YouTubeVideo("uMkzxV_y7tY",560,315,rel=0)
```

Out[1]:

Consider three reactions for the production of ammonia

- Steam-reforming of methaneCH
_{4}+ H_{2}O → CO + 3 H_{2 } - Water-gas shift CO + H
_{2}O → CO_{2}+ H_{2 } - Haber-Bosch reactionN
_{2}+ 3 H_{2}→ 2 NH_{3}

Determine if it is possible to construct a process for the production of ammonia with no wasted hydrogen and no release of carbon monoxide.

We begin by setting up the stoichiometric matrix for generation/consumption analysis

Species | R_{1} |
R_{2} |
R_{3} |
Net |
---|---|---|---|---|

χ_{1} |
χ_{2} |
χ_{3} |
$\sum_k\nu_k\chi_k$ | |

CH_{4} |
-1 | 0 | 0 | ≤ 0 |

H_{2}O |
-1 | -1 | 0 | ≤ 0 |

CO | 1 | -1 | 0 | 0 |

H_{2} |
3 | 1 | -3 | 0 |

CO_{2} |
0 | 1 | 0 | ≥ 0 |

N_{2} |
0 | 0 | 1 | ≤ 0 |

NH_{3} |
0 | 0 | 2 | 1 |

which includes three equality constraints which need to be solved for
χ_{1}, χ_{2}, and χ_{3}.

The first step is to import `sympy`

.

In [2]:

```
import sympy
```

When imported in this way, the functions from `sympy`

must be accessed with the prefix `sympy.`

. This avoids overwriting functions with the same name as those in `sympy`

, such as `plot`

.

Next we use the `sympy.var`

function to create three symbolic variables corresponding to χ_{1}, χ_{2}, and χ_{3}.

In [3]:

```
sympy.var('x1 x2 x3')
```

Out[3]:

The net stoichiometric coefficients can be written in terms of the symbolic variables.

In [4]:

```
v = dict()
v['CH4'] = -x1
v['H2O'] = -x1 - x2
v['CO'] = x1 - x2
v['H2'] = 3*x1 + x2 - 3*x3
v['CO2'] = x2
v['N2'] = -x3
v['NH3'] = 2*x3
```

The three process constraints are encoded as equations using the sympy function `Eq()`

In [5]:

```
eqns = [
sympy.Eq(v['NH3'],1),
sympy.Eq(v['CO'],0),
sympy.Eq(v['H2'],0)
]
```

These equations are solved for χ_{1}, χ_{2}, and χ_{3}.

In [6]:

```
soln = sympy.solve(eqns)
print(soln)
```

To finish the problem, the solutions are substituted back into the expressions for the stoichiometric coefficients, and the non-zero coefficients are displayed.

In [7]:

```
for k in v.keys():
a = v[k].subs(soln)
if a != 0:
print("{0:<3s} {1:>6s}".format(k,str(a)))
```

In [ ]:

```
```