Lead solubility prediction using R and Shiny

An R package and Shiny app for PHREEQC-based equilibrium lead and copper solubility prediction.

Ben Trueman true
06-18-2021

Recently, I’ve been experimenting with the excellent R package tidyphreeqc (Dunnington 2019), which provides a convenient interface for generating PHREEQC input files (Charlton and Parkhurst 2011; Parkhurst and Appelo 2013). tidyphreeqc incorporates easily into my workflow, and it’s found its way into several recent publications (Li et al. 2021, 2020).

I’ve also used it to build a separate package, pbcusol, that handles lead and copper solubility prediction specifically, with curated thermodynamic data and some domain specific features implemented in what is hopefully a straightforward collection of functions. pbcusol is implemented as a Shiny app, available here.

pbcusol can be used to generate lead and copper solubility predictions that are comparable with those found in literature (Schock, Wagner, and Oliphant 1996), as detailed in the package README on GitHub. (They’re reproduced here using the wesanderson package for the colour palette (Ram and Wickham 2018).)

pbcusol can also be used to generate predicted lead and copper solubility in the presence of humic substances. This is also outlined in the package README, but here is an example of the type of visualization that can be generated, along with the code necessary to reproduce the model output. Of course, these predictions should be properly validated—more on that later.

grid_dim <- 25 # dimension of solubility grid square

future::plan("multisession")

nom_grid <- crossing(
  pH_in = seq(6.5, 10.5, length.out = grid_dim),
  nom_in = seq(0, 3e-3, length.out = grid_dim)
) %>% 
  rowid_to_column() %>% 
  group_by(rowid) %>% 
  nest() %>% 
  ungroup() %>%  
  mutate(
    model = furrr::future_map(data, 
      ~ with(.x, 
        pb_sol_wham(
          ph = pH_in, dic = 5, phase = "Hydcerussite", 
          Na = 10 / chemr::mass("Na"), mass_ha = nom_in
        )
      )
    )
  )

Charlton, S. R., and D. L. Parkhurst. 2011. “Modules Based on the Geochemical Model Phreeqc for Use in Scripting and Programming Languages.” Computers & Geosciences 37: 1653–63. http://dx.doi.org/10.1016/j.cageo.2011.02.005.

Dunnington, Dewey. 2019. tidyphreeqc: Tidy Geochemical Modeling Using Phreeqc. https://github.com/paleolimbot/tidyphreeqc.

Li, Bofu, Benjamin F. Trueman, Javier M. Locsin, Yaohuan Gao, Mohammad Shahedur Rahman, Yuri Park, and Graham A. Gagnon. 2021. “Impact of Sodium Silicate on Lead Release from Lead(II) Carbonate.” Environmental Science: Water Research & Technology 7 (3): 599–609. https://doi.org/10.1039/D0EW00886A.

Li, Bofu, Benjamin F. Trueman, Mohammad Shahedur Rahman, and Graham A. Gagnon. 2020. “Controlling Lead Release Due to Uniform and Galvanic Corrosion—an Evaluation of Silicate-Based Inhibitors.” Journal of Hazardous Materials, December, 124707. https://doi.org/10.1016/j.jhazmat.2020.124707.

Parkhurst, D. L., and C. A. J. Appelo. 2013. Description of Input and Examples for Phreeqc Version 3–a Computer Program for Speciation, Batch-Reaction, One-Dimensional Transport, and Inverse Geochemical Calculations. Vol. book 6. Techniques and Methods. U.S. Geological Survey. https://pubs.usgs.gov/tm/06/a43.

Ram, Karthik, and Hadley Wickham. 2018. wesanderson: A Wes Anderson Palette Generator. https://CRAN.R-project.org/package=wesanderson.

Schock, M. R., I. Wagner, and R. J. Oliphant. 1996. “Corrosion and solubility of lead in drinking water.” In Internal corrosion of water distribution systems, 2nd ed., 131–230. Denver, CO: American Water Works Association Research Foundation.

References

Corrections

If you see mistakes or want to suggest changes, please create an issue on the source repository.

Citation

For attribution, please cite this work as

Trueman (2021, June 18). Benjamin Trueman: Lead solubility prediction using R and Shiny. Retrieved from https://bentrueman.github.io/posts/2021-06-18-lead-solubility-prediction-using-shiny/

BibTeX citation

@misc{trueman2021lead,
  author = {Trueman, Ben},
  title = {Benjamin Trueman: Lead solubility prediction using R and Shiny},
  url = {https://bentrueman.github.io/posts/2021-06-18-lead-solubility-prediction-using-shiny/},
  year = {2021}
}