PourPy - A python package to generate potential-pH diagrams

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 electrochemical 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 bevaviour 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 0 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 canunder some conditionsoffer 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 Δ ∘  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 accessability 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 ( − ).They appear as horizontal lines on the diagram.The third archetype 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   , and protons H + according to the general chemical reaction where  , and  H + are the stoichiometric coefficients of reactants, products and protons involved.The reaction equilibrium constant  can be computed from the Gibbs free energy change of the reaction Δ ∘  according to where  = 8.31446262 J mol −1 K −1 is the ideal gas constant and  is the temperature in degree K.It also relates to the activity of all reactants Provided the Gibbs free energy of the reaction is known, the pH above which the formation of products is favoured can be computed as Reactions that additionally consume or generate electrons (horizontal or inclined lines), i.e.
are plotted by computing the potential at which the formation of products becomes favourable via the Nernst Equation where  is the number of electrons transferred and  = 96485.3321A mol −1 s −1 refers to the Faraday constant.For a reaction including the exchange of protons  H + , Equation 6corresponds to the third (inclined) line type and for  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   are stable.For all   , these thermodynamic stability regions are determined based on the sign of the stoichiometric coefficient  , , 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.