# PourPy - A python package to generate potential-pH diagrams

Anja Korber¹, Fabio E. Furcas ID ¹, Mohit Pundir ID ¹¶, David S. Kammer ID ¹, and Ueli M. Angst ID ¹

1 Institute for Building Materials, ETH Zürich, Laura-Hezner-Weg 7, Zürich, 8093, Switzerland ¶
Corresponding author

DOI: 10.21105/joss.06536

## Software

- Review 🐰

- Repository 🐰

- Archive 🐰

Editor: Rachel Kurchin 🐰 ID

## Reviewers:

- @yaomz16

- @sudarshanv01

Submitted: 05 March 2024

Published: 29 May 2024

## License

Authors of papers retain copyright and release the work under a Creative Commons Attribution 4.0 International License (CC BY 4.0).

## Summary

PourPy is an open-source Python package for generating thermodynamic stability diagrams of solid phases and complexes in aqueous electrolytes. These so-called Pourbaix diagrams provide valuable information about the reactivity of chemical elements and compounds as a function of the electrochemical potential and the pH. In the context of corrosion science, environmental and process engineering, Pourbaix diagrams are useful to predict the reactivity of aqueous complexes, the passivation behaviour of metals, and the electrochemical stability of the aqueous electrolyte. PourPy is a tool enabling users to inspect the reactivity of aqueous systems under full control of all chemical species considered. Users can define custom reactive systems containing multiple solid, aqueous and gaseous species thereof and build all (electro)chemical reactions to be considered. The package provides additional functionality to perform basic manipulations on the thermodynamic parameters associated with each chemical component, change the system's reference electrode as well as calculate the number of phases stable across a given potential-pH space or at discrete values. Future releases are planned to retrieve thermodynamic parameters from established databases including SUPCRT92 (Johnson et al., 1992) and PHREEQC (Parkhurst et al., 1999, 2013).

## Statement of need

In 1963, Marcel Pourbaix submitted his PhD thesis titled *Atlas d'Équilibres Électrochimiques*, comprising a collection of thermodynamic equilibrium relationships that describe the electro-chemical stability of chemical elements (Pedeferri & Ormellese, 2018; Pourbaix & Zoubov, 1963). Over the course of the last century, graphical representations of these equilibrium relationships, the so-called Pourbaix diagrams, also known as potential-pH diagrams, have emerged as an invaluable tool to predict the corrosion behaviour of materials. Pourbaix diagrams are widely used in corrosion science to assess the stability of a metal and its possible different metal (hydr)oxides (McCafferty, 2010). In this context, Pourbaix diagrams provide maps of three different regions of interest, namely *corrosion*, *passivity*, and *immunity*. The corrosion region is the potential-pH domain in which dissolution of the metal is possible and where it is thermodynamically stable in the form of dissolved aqueous species. The immunity domain designates the conditions in which the metal is stable in its unreacted Me⁰ form. Finally, a domain of tremendous technological relevance for many metals, especially iron-based alloys, is the passivity domain, in which oxides are stable and can – under some conditions – offer protective properties to the underlying metal. In addition, in many cases, scales incorporating both metal (hydr)oxide phases and substances stemming from the exposure environment (carbonate ions, sulphur species, phosphate species, etc.) can form on the surface as well and affect the corrosion process. Such cases can also be investigated by means of Pourbaix diagrams, provided that the relevant species are incorporated in the thermodynamic calculations
carried out to construct the Pourbaix diagram. While Pourbaix diagrams for simple cases such as metal-water systems can often be found in the literature, diagrams for more complex situations or cases deviating from standard conditions (e.g. in terms of temperature, electrolyte composition, and/or ionic activity), scholars may face challenges in obtaining the required Pourbaix diagrams. It should be mentioned here that Pourbaix diagrams also have limitations. For instance, the thermodynamically stable phase may not always be the relevant in practical situations, as intermediates may dominate the behavior over considerable time scales. Though not energetically favorable, these intermediate species may also be plotted in the Pourbaix diagram by excluding other, thermodynamically more stable species and compounds. Moreover, the lines depicted in Pourbaix diagrams represent the predominance boundaries, which means that different species / phases may be stable and present on both sides of these lines. Such information, although not visible from classical Pourbaix diagrams, may impact the behavior of the system. Another (well-known) limitation of Pourbaix diagrams is that they do not provide information on the kinetics of reactions.

Pourbaix diagrams are two-dimensional and Cartesian, plotting the electrochemical redox potential of e.g. a metal or an alloy versus the solution pH in contact with the material. Any electrochemical and/or pH-dependent reaction can be drawn on such a diagram in the form of a straight line, provided the standard molar Gibbs free energy of formation $\Delta G^\circ_f$ of all reactants are known. Despite their simplicity and widespread use in engineering and science, there are few software packages that generate correct Pourbaix diagrams, without hiding some of their essential features behind a staggering paywall. Other packages including *pymatgen* (Persson et al., 2012; Singh et al., 2017) part of the *The Materials Project API* (Jain et al., 2013) and the *Atomic Simulation Environment (ASE)* (Larsen et al., 2017) are available free of charge, but the diagrams generated are not customisable and involve DFT modelling methods and energy minimisation routines far more complicated than the set of thermodynamic equilibrium relationships originally published. As the underlying minimisation routines are further performed at each discrete pH-potential coordinate considered, the generation of Pourbaix diagrams via the *pymatgen* or *ASE* package is also computationally expensive. *PourPy* is developed to address this accessibility gap. The package provides a set of seven classes that handle user-defined chemical reactants and reactions to be included in a completely customisable Pourbaix diagram. Classes include functionality to change the reference electrode scale of the system, control the activity of all aqueous species of a particular chemical element and interact with the diagram to extract the stable phase(s) predominant at a given potential and pH coordinate. Lastly, the provision of a web application eliminates the need to set up a local installation environment, making the package more accessible to scholars and engineering professionals.

## Brief software description

The *PourPy* package distinguishes between 3 main line types drawn on the Pourbaix diagram. The first type represents reactions that are vertical, pH-dependent and involve the exchange of protons ($H^+$). The assigned pH can be calculated based on the equilibrium constant of the chemical reaction. The second type represent potential-dependent reactions, involving the generation or consumption of electrons ($e^-$). They appear as horizontal lines on the diagram. The third prototype of Pourbaix lines is a combination of the first two, i.e. involving the exchange of protons and electrons, resulting in a sloped line on the potential-pH diagram. Consider the formation and consumption of reactants, products $A_i$, and protons $H^+$ according to the general chemical reaction

$$ \sum_i \nu_{a,i} A_i + \nu_{H^+} H^+ = 0, \qquad (1) $$

where $\nu_{a,i}$ and $\nu_{H^+}$ are the stoichiometric coefficients of reactants, products and protons involved. The reaction equilibrium constant $\beta$ can be computed from the Gibbs free energy
change of the reaction $\Delta G_r^\circ$ according to

$$ \beta = \exp(-\Delta G_r^\circ/(R \cdot T)), \qquad (2) $$

where $R = 8.31446262 \text{ J mol}^{-1} \text{ K}^{-1}$ is the ideal gas constant and $T$ is the temperature in degree K. It also relates to the activity of all reactants

$$ K = \prod_{i} \{A_{i}\}^{\nu_{a,i}} \times \{H^{+}\}^{\nu_{H^{+}}}. \qquad (3) $$

Provided the Gibbs free energy of the reaction is known, the pH above which the formation of products is favoured can be computed as

$$ \text{pH} = -\log_{10}\{\text{H}^{+}\} = \frac{1}{\nu_{\text{H}^{+}}} \left[ \log_{10} \prod_{i} \{A_{i}\}^{\nu_{a,i}} - \log_{10} K \right]. \qquad (4) $$

Reactions that additionally consume or generate electrons (horizontal or inclined lines), i.e.

$$ \sum_{i} \nu_{a,i} A_{i} + \nu_{\text{H}^{+}} \text{H}^{+} + ne^{-} = 0, \qquad (5) $$

are plotted by computing the potential at which the formation of products becomes favourable via the Nernst Equation

$$ E_{\text{rev}} = E_{\text{rev}}^{\circ} + 2.303 \times \frac{RT}{nF} \times \log_{10} \prod_{i} \{A_{i}\}^{\nu_{a,i}} + 2.303 \times \nu_{\text{H}^{+}} \times \frac{RT}{nF} \times \text{pH}, \qquad (6) $$

where $n$ is the number of electrons transferred and $F = 96485.3321 \text{ A mol}^{-1} \text{ s}^{-1}$ refers to the Faraday constant. For a reaction including the exchange of protons $\nu_{\text{H}^{+}}$, Equation 6 corresponds to the third (inclined) line type and for $\nu_{\text{H}^{+}} = 0$, the second (horizontal) line type is generated. The intersections of multiple of these line types define regions in the potential-pH space in which various chemical species $A_i$ are stable. For all $A_i$, these thermodynamic stability regions are determined based on the sign of the stoichiometric coefficient $\nu_{a,i}$, relative to the stoichiometric coefficients of the protons and electrons involved in their formation.

## Availability, usage and documentation

PourPy is written in Python and hosted on GitLab and can be accessed via a Mercury-powered web application. It has been uploaded to the Python Packaging Index under the name 'PourPy' and can be installed using the pip package manager. Users are guided through the functionality of the package via a set of tutorials available here. We encourage collaborative efforts to improve the functionality of PourPy via the Git repository and appreciate any suggestions for future features and showcase tutorials.

## Acknowledgements

The authors thank the European Research Council (ERC) for the financial support provided for Fabio Enrico Furcas under the European Union Horizon 2020 research and innovation program (grant agreement no. 848794).

## Contributions

F.E.F, D.K. and U.M.A conceived the study, all authors contributed to the study design. A.K., M.P. and F.E.F. conducted the programming. F.E.F. wrote the main draft of the manuscript, all authors co-wrote and approved the final manuscript.
## References

Jain, A., Ong, S. P., Hautier, G., Chen, W., Richards, W. D., Dacek, S., Cholia, S., Gunter, D., Skinner, D., Ceder, G., & others. (2013). Commentary: The Materials Project: A materials genome approach to accelerating materials innovation. *APL Materials, 1*(1). https://doi.org/10.1063/1.4812323

Johnson, J. W., Oelkers, E. H., & Helgeson, H. C. (1992). SUPCRT92: A software package for calculating the standard molal thermodynamic properties of minerals, gases, aqueous species, and reactions from 1 to 5000 bar and 0 to 1000 C. *Computers & Geosciences*, **18**(7), 899-947. https://doi.org/10.1016/0098-3004(92)90029-Q

Larsen, A. H., Mortensen, J. J., Blomqvist, J., Castelli, I. E., Christensen, R., Dułak, M., Friis, J., Groves, M. N., Hammer, B., Hargus, C., Hermes, E. D., Jennings, P. C., Jensen, P. B., Kermode, J., Kitchin, J. R., Kolsbjerg, E. L., Kubal, J., Kaasbjerg, K., Lysgaard, S., ... Jacobsen, K. W. (2017). The atomic simulation environment — a Python library for working with atoms. *Journal of Physics: Condensed Matter*, **29**(27), 273002. https://doi.org/10.1021/acs.chemmater.7b03980.s001

McCafferty, E. (2010). *Introduction to Corrosion Science* [Book]. Springer Science & Business Media. https://doi.org/10.1007/978-1-4419-0455-3

Parkhurst, D. L., Appelo, C., & others. (1999). User's guide to PHREEQC (Version 2): A computer program for speciation, batch-reaction, one-dimensional transport, and inverse geochemical calculations. *Water-Resources Investigations Report, 99*(4259), 312. https://doi.org/10.3133/wri994259

Parkhurst, D. L., Appelo, C., & others. (2013). Description of input and examples for PHREEQC version 3 — a computer program for speciation, batch-reaction, one-dimensional transport, and inverse geochemical calculations. *US Geological Survey Techniques and Methods, 6*(A43), 497. https://doi.org/10.3133/tm6a43

Pedeferri, P., & Ormellese, M. (2018). *Corrosion Science and Engineering* (Vol. 720) [Book]. Springer. https://doi.org/10.1007/978-3-319-97625-9

Persson, K. A., Waldwick, B., Lazic, P., & Ceder, G. (2012). Prediction of solid-aqueous equilibria: Scheme to combine first-principles calculations of solids with experimental aqueous states. *Phys. Rev. B*, **85**, 235438. https://doi.org/10.1103/physrevb.85.235438

Pourbaix, M., & Zoubov, N. de. (1963). Atlas d'Équilibres Électrochimiques: Eau oxygénée. In *Centre belge d'étude de la corrosion*. Paris: Gauthier-Villars.

Singh, A. K., Zhou, L., Shinde, A., Suram, S. K., Montoya, J. H., Winston, D., Gregoire, J. M., & Persson, K. A. (2017). Electrochemical stability of metastable materials. *Chemistry of Materials*, **29**(23), 10159-10167. https://doi.org/10.1021/acs.chemmater.7b03980