[CHNOSZ-commits] r610 - in pkg/CHNOSZ: . R demo inst man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Oct 14 03:02:12 CEST 2020


Author: jedick
Date: 2020-10-14 03:02:11 +0200 (Wed, 14 Oct 2020)
New Revision: 610

Added:
   pkg/CHNOSZ/demo/zinc.R
Modified:
   pkg/CHNOSZ/DESCRIPTION
   pkg/CHNOSZ/R/examples.R
   pkg/CHNOSZ/R/mosaic.R
   pkg/CHNOSZ/demo/00Index
   pkg/CHNOSZ/inst/NEWS.Rd
   pkg/CHNOSZ/man/examples.Rd
Log:
Add demo/zinc.R (solubilities of multiple minerals)


Modified: pkg/CHNOSZ/DESCRIPTION
===================================================================
--- pkg/CHNOSZ/DESCRIPTION	2020-10-06 10:17:46 UTC (rev 609)
+++ pkg/CHNOSZ/DESCRIPTION	2020-10-14 01:02:11 UTC (rev 610)
@@ -1,6 +1,6 @@
-Date: 2020-10-06
+Date: 2020-10-14
 Package: CHNOSZ
-Version: 1.3.6-83
+Version: 1.3.6-84
 Title: Thermodynamic Calculations and Diagrams for Geochemistry
 Authors at R: c(
     person("Jeffrey", "Dick", , "j3ffdick at gmail.com", role = c("aut", "cre"),

Modified: pkg/CHNOSZ/R/examples.R
===================================================================
--- pkg/CHNOSZ/R/examples.R	2020-10-06 10:17:46 UTC (rev 609)
+++ pkg/CHNOSZ/R/examples.R	2020-10-14 01:02:11 UTC (rev 610)
@@ -32,7 +32,7 @@
 
 demos <- function(which=c("sources", "protein.equil", "affinity", "NaCl", "density", 
   "ORP", "findit", "ionize", "buffer", "protbuff", "glycinate",
-  "mosaic", "copper", "arsenic", "solubility", "gold", "contour", "sphalerite",
+  "mosaic", "copper", "arsenic", "solubility", "gold", "contour", "sphalerite", "zinc",
   "Shh", "saturation", "adenine", "DEW", "lambda", "berman", "TCA", "aluminum",
   "AkDi", "comproportionation"), save.png=FALSE) {
   # run one or more demos from CHNOSZ with ask=FALSE, and return the value of the last one

Modified: pkg/CHNOSZ/R/mosaic.R
===================================================================
--- pkg/CHNOSZ/R/mosaic.R	2020-10-06 10:17:46 UTC (rev 609)
+++ pkg/CHNOSZ/R/mosaic.R	2020-10-14 01:02:11 UTC (rev 610)
@@ -81,7 +81,8 @@
     mysp <- species(bases[[i]])
     # 20191111 include only aq species in total activity
     iaq <- mysp$state == "aq"
-    if(any(iaq)) species(which(iaq), basis0$logact[ibasis0[i]])
+    # use as.numeric in case a buffer is active 20201014
+    if(any(iaq)) species(which(iaq), as.numeric(basis0$logact[ibasis0[i]]))
     A.bases[[i]] <- suppressMessages(affinity(..., sout = sout))
   }
 
@@ -116,7 +117,7 @@
       if(any(!sapply(A.bases[[1]]$values, is.na))) {
         # 20190504: when equilibrating the changing basis species, use a total activity equal to the activity from the basis definition
         # 20191111 use equilibrate(loga.balance = ) instead of setting activities in species definition
-        e <- equilibrate(A.bases[[i]], loga.balance = basis0$logact[ibasis0[i]])
+        e <- equilibrate(A.bases[[i]], loga.balance = as.numeric(basis0$logact[ibasis0[i]]))
         # exponentiate to get activities then divide by total activity
         a.equil <- lapply(e$loga.equil, function(x) 10^x)
         a.tot <- Reduce("+", a.equil)

Modified: pkg/CHNOSZ/demo/00Index
===================================================================
--- pkg/CHNOSZ/demo/00Index	2020-10-06 10:17:46 UTC (rev 609)
+++ pkg/CHNOSZ/demo/00Index	2020-10-14 01:02:11 UTC (rev 610)
@@ -16,6 +16,7 @@
 gold            Solubility of gold
 contour         Gold solubility contours on a log fO2 - pH diagram
 sphalerite      Solubility of sphalerite
+zinc            Solubilities of multiple minerals (zincite and sphalerite)
 dehydration     log K of dehydration reactions; SVG file contains tooltips and links
 Shh             Affinities of transcription factors relative to Sonic hedgehog
 saturation      Equilibrium activity diagram showing activity ratios and mineral saturation limits

Added: pkg/CHNOSZ/demo/zinc.R
===================================================================
--- pkg/CHNOSZ/demo/zinc.R	                        (rev 0)
+++ pkg/CHNOSZ/demo/zinc.R	2020-10-14 01:02:11 UTC (rev 610)
@@ -0,0 +1,100 @@
+# CHNOSZ/demo/zinc.R
+# make Zn solubility diagram with multiple minerals
+# 20190530 jmd first version (plot_Zn.R)
+# 20201008 combine solubility contours for different minerals
+# 20201014 added to CHNOSZ
+
+par(mfrow = c(2, 2))
+
+# system variables
+res <- 300
+T <- 100
+P <- "Psat"
+Stot <- 1e-3
+pH <- c(0, 14, res)
+O2 <- c(-62, -40, res)
+# mass percent NaCl in saturated solution at 100 degC, from CRC handbook
+w2 <- 0.2805  
+
+# set up basis species
+basis(c("ZnO", "H2S", "Cl-", "oxygen", "H2O", "H+"))
+basis("H2S", log10(Stot))
+# molality of NaCl in saturated solution
+m2 <- 1000 * w2 / (mass("NaCl") * (1 - w2))
+# estimate ionic strength and molality of Cl-
+sat <- NaCl(T = 100, m_tot = m2)
+basis("Cl-", log10(sat$m_Cl))
+
+# Add minerals and aqueous species
+icr <- (c("sphalerite", "zincite"))
+iaq <- (c("ZnCl4-2", "ZnO2-2"))
+logm_Zn <- -3
+species(c(icr, iaq), c(0, 0, logm_Zn, logm_Zn))
+
+# Calculate affinities and make diagram
+bases <- c("H2S", "HS-", "HSO4-", "SO4-2")
+m <- mosaic(bases, pH = pH, O2 = O2, T = T, P = P, IS = sat$IS)
+fill <- c("lightgoldenrod1", "goldenrod1", "skyblue", "skyblue")
+col.names <- c("red", "red", "blue", "blue")
+d <- diagram(m$A.species, fill = fill, col.names = col.names, bold = TRUE)
+diagram(m$A.bases, add = TRUE, col = "slategray", lwd = 2, lty = 3, names = NA)
+title(bquote(log * italic(m)["Zn(aq) species"] == .(logm_Zn)))
+label.figure("A")
+
+# Add legend
+plot.new()
+l <- c(
+  lTP(T, P),
+  lNaCl(m2),
+  lS(Stot)
+)
+legend("topleft", legend = lex(l), bty = "n", cex = 1.5)
+# Describe steps
+par(xpd = NA)
+legend("bottomleft", c("Predominance diagram: molality of aqueous", "species defines one solubility contour.",
+  "Take away aqueous species to see", "all possible minerals.",
+  "Calculate solubility for each mineral separately", "then take the minimum to plot solubilities", "of stable minerals across the diagram."),
+       pch = c("A", "", "B", "", "C", "", ""), inset = c(-0.1, 0), cex = 0.95)
+par(xpd = FALSE)
+
+# Make diagram for Co minerals only 20201007
+if(packageVersion("CHNOSZ") <= "1.3.6") species(delete = TRUE)
+species(icr)
+mcr <- mosaic(bases, pH = pH, O2 = O2, T = T, P = P, IS = sat$IS)
+diagram(mcr$A.species, col = 2)
+label.figure("B")
+
+## Solubility plot 20201008
+
+# Make a list to store the calculated solubilities for each mineral
+slist <- list()
+# Loop over minerals
+minerals <- c("zincite", "sphalerite")
+for(i in seq_along(minerals)) {
+  # Define basis species with mineral to dissolve
+  basis(c(minerals[i], "H2S", "Cl-", "oxygen", "H2O", "H+"))
+  basis("H2S", log10(Stot))
+  basis("Cl-", log10(sat$m_Cl))
+  # Add aqueous species (no need to define activities here - they will be calculated)
+  species(iaq)
+  # Calculate affinities of formation reactions, using mosaic() to speciate the S-bearing basis species
+  m <- mosaic(bases, pH = pH, O2 = O2, T = T, IS = sat$IS)
+  # Calculate solubility of this mineral
+  s <- solubility(m$A.species, in.terms.of = "Zn", dissociation = FALSE)
+  # Store the solubilities in the list
+  slist[[i]] <- s$loga.balance
+}
+
+# The overall solubility is the *minimum* among all the minerals
+smin <- do.call(pmin, slist)
+# Put this into the last-computed 'solubility' object
+s$loga.balance <- smin
+# Specify contour levels
+levels <- seq(-12, 9, 3)
+diagram(s, type = "loga.balance", levels = levels, contour.method = "flattest")
+# Show the mineral stability boundaries
+diagram(mcr$A.species, names = NA, add = TRUE, lty = 2, col = 2)
+title("Solubilities of 2 minerals", font.main = 1, line = 1.5)
+title(bquote(log[10]~"moles of Zn in solution"), line = 0.7)
+label.figure("C")
+

Modified: pkg/CHNOSZ/inst/NEWS.Rd
===================================================================
--- pkg/CHNOSZ/inst/NEWS.Rd	2020-10-06 10:17:46 UTC (rev 609)
+++ pkg/CHNOSZ/inst/NEWS.Rd	2020-10-14 01:02:11 UTC (rev 610)
@@ -156,6 +156,9 @@
       comproportionation, after
       \href{https://doi.org/10.1111/1462-2920.14982}{Amend et al., 2020}.
 
+      \item Add \samp{demo/zinc.R}: Solubilities of multiple minerals (zincite
+      and sphalerite).
+
       \item Revise and simplify \samp{anintro.Rmd} and \samp{equilibrium.Rmd}
       (converted from \samp{equilibrium.Rnw}).
 

Modified: pkg/CHNOSZ/man/examples.Rd
===================================================================
--- pkg/CHNOSZ/man/examples.Rd	2020-10-06 10:17:46 UTC (rev 609)
+++ pkg/CHNOSZ/man/examples.Rd	2020-10-14 01:02:11 UTC (rev 610)
@@ -16,7 +16,7 @@
   demos(which = c("sources", "protein.equil", "affinity", "NaCl",
     "density", "ORP", "findit", "ionize", "buffer", "protbuff",
     "glycinate", "mosaic", "copper", "arsenic", "solubility", "gold",
-    "contour", "sphalerite", "Shh", "saturation",
+    "contour", "sphalerite", "zinc", "Shh", "saturation",
     "adenine", "DEW", "lambda", "berman", "TCA", "aluminum", "AkDi",
     "comproportionation"),
     save.png=FALSE)
@@ -49,6 +49,7 @@
     \code{gold} \tab Solubility of gold (Akinfiev and Zotov; 2001; Stef{\aacute}nsson and Seward, 2004; Williams-Jones et al., 2009) \cr
     \code{contour} \tab Gold solubility contours on a log fO2 - pH diagram (Williams-Jones et al., 2009) \cr
     \code{sphalerite} \tab Solubility of sphalerite (Akinfiev and Tagirov, 2014) \cr
+    \code{zinc} \tab Solubilities of multiple minerals (zincite and sphalerite) \cr
     \code{dehydration} \tab \logK of dehydration reactions; SVG file contains tooltips and links \cr
     \code{Shh} \tab Affinities of transcription factors relative to Sonic hedgehog (Dick, 2015) \cr
     \code{saturation} \tab Equilibrium activity diagram showing activity ratios and mineral saturation limits (Bowers et al., 1984) \cr



More information about the CHNOSZ-commits mailing list