[CHNOSZ-commits] r574 - in pkg/CHNOSZ: . R inst man tests/testthat vignettes

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Jul 24 02:40:29 CEST 2020


Author: jedick
Date: 2020-07-24 02:40:29 +0200 (Fri, 24 Jul 2020)
New Revision: 574

Modified:
   pkg/CHNOSZ/DESCRIPTION
   pkg/CHNOSZ/R/equilibrate.R
   pkg/CHNOSZ/R/examples.R
   pkg/CHNOSZ/R/util.affinity.R
   pkg/CHNOSZ/inst/NEWS.Rd
   pkg/CHNOSZ/man/retrieve.Rd
   pkg/CHNOSZ/tests/testthat/test-diagram.R
   pkg/CHNOSZ/tests/testthat/test-equilibrate.R
   pkg/CHNOSZ/vignettes/multi-metal.Rmd
Log:
Clean up messages


Modified: pkg/CHNOSZ/DESCRIPTION
===================================================================
--- pkg/CHNOSZ/DESCRIPTION	2020-07-23 06:25:03 UTC (rev 573)
+++ pkg/CHNOSZ/DESCRIPTION	2020-07-24 00:40:29 UTC (rev 574)
@@ -1,6 +1,6 @@
-Date: 2020-07-23
+Date: 2020-07-24
 Package: CHNOSZ
-Version: 1.3.6-47
+Version: 1.3.6-48
 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/equilibrate.R
===================================================================
--- pkg/CHNOSZ/R/equilibrate.R	2020-07-23 06:25:03 UTC (rev 573)
+++ pkg/CHNOSZ/R/equilibrate.R	2020-07-24 00:40:29 UTC (rev 574)
@@ -357,7 +357,7 @@
   #   name of basis species   - balanced on this basis species
   #   "length"                   - balanced on sequence length of proteins 
   #                             (default if balance is missing and all species are proteins)
-  #   1                       - balanced on one mole of species
+  #   1                       - balanced on one mole of species (formula units)
   #   numeric vector          - user-defined n.balance
   #   "volume"                - standard-state volume listed in thermo()$OBIGT
   # the index of the basis species that might be balanced
@@ -376,16 +376,18 @@
   if(is.numeric(balance[1])) {
     # a numeric vector
     n.balance <- rep(balance, length.out=length(aout$values))
-    message(paste0("balance: from supplied numeric argument (", paste(balance, collapse = ","), ")"))
+    msgtxt <- paste0("balance: on supplied numeric argument (", paste(balance, collapse = ","), ")")
+    if(identical(balance, 1)) msgtxt <- paste(msgtxt, "[1 means balance on formula units]")
+    message(msgtxt)
   } else {
     # "length" for balancing on protein length
     if(identical(balance, "length")) {
-      if(!all(isprotein)) stop("length was the requested balance, but some species are not proteins")
+      if(!all(isprotein)) stop("'length' was the requested balance, but some species are not proteins")
       n.balance <- protein.length(aout$species$name)
-      message("balance: from protein length")
+      message("balance: on protein length")
     } else if(identical(balance, "volume")) {
       n.balance <- info(aout$species$ispecies, check.it=FALSE)$V
-      message("balance: from volume")
+      message("balance: on volume")
     } else {
       # is the balance the name of a basis species?
       if(length(ibalance)==0) {
@@ -394,8 +396,8 @@
       }
       # the name of the basis species (need this if we got ibalance which which.balance, above)
       balance <- colnames(aout$species)[ibalance[1]]
-      message(paste("balance: moles of", balance, "in formation reactions"))
-      # the balance vector
+      message(paste("balance: on moles of", balance, "in formation reactions"))
+      # the balancing coefficients
       n.balance <- aout$species[, ibalance[1]]
       # we check if that all formation reactions contain this basis species
       if(any(n.balance==0)) stop("some species have no ", balance, " in the formation reaction")

Modified: pkg/CHNOSZ/R/examples.R
===================================================================
--- pkg/CHNOSZ/R/examples.R	2020-07-23 06:25:03 UTC (rev 573)
+++ pkg/CHNOSZ/R/examples.R	2020-07-24 00:40:29 UTC (rev 574)
@@ -12,7 +12,7 @@
     "hkf", "water", "IAPWS95", "subcrt", "berman",
     "makeup", "basis", "swap.basis", "species", "affinity",
     "solubility", "equilibrate", 
-    "diagram", "mosaic", "combine",
+    "diagram", "mosaic", "mix",
     "buffer", "nonideal", "NaCl",
     "add.protein", "protein", "ionize.aa",
     "objective", "revisit", "EOSregress", "wjd")

Modified: pkg/CHNOSZ/R/util.affinity.R
===================================================================
--- pkg/CHNOSZ/R/util.affinity.R	2020-07-23 06:25:03 UTC (rev 573)
+++ pkg/CHNOSZ/R/util.affinity.R	2020-07-24 00:40:29 UTC (rev 574)
@@ -293,8 +293,11 @@
     if(length(IS) > 1) IS.is.var <- TRUE
   }
   # report non-variables to user
-  if(!T.is.var)
-    message('affinity: temperature is ',outvert(T,'K'),' ',T.units())
+  if(!T.is.var) {
+    Tunits <- T.units()
+    if(Tunits=="C") Tunits <- "\u00BAC"
+    message('affinity: temperature is ', outvert(T, 'K'), ' ', Tunits)
+  }
   if(!P.is.var) {
     if(identical(P,"Psat")) message("affinity: pressure is Psat")
     else message('affinity: pressure is ',outvert(P,'bar'),' ',P.units())

Modified: pkg/CHNOSZ/inst/NEWS.Rd
===================================================================
--- pkg/CHNOSZ/inst/NEWS.Rd	2020-07-23 06:25:03 UTC (rev 573)
+++ pkg/CHNOSZ/inst/NEWS.Rd	2020-07-24 00:40:29 UTC (rev 574)
@@ -204,12 +204,8 @@
 
       \item TODO: OBIGT.Rmd: change "CHNOSZ" references to "OBIGT".
 
-      \item TODO: fix logic for negating balancing coefficients in diagram().
-
       \item TODO: add elements from RH95.
 
-      \item TODO: check that Rd <-> vignette links work in Rstudio help viewer.
-
       \item TODO: add check to mosaic() that 'predominant' values have the right dimensions.
 
       \item TODO: remove stopifnot() from examples.
@@ -220,10 +216,8 @@
       different units (cal, J) in OBIGT can be used in subcrt, diagrams, etc.
       in CHNOSZ.
 
-      \item TODO: for balance = 1, add or change message text to "formula units".
+      \item TODO: add library(CHNOSZ) to all scripts in demo/.
 
-      \item TODO: remove species combinations with no stability field in flatten().
-
     }
   }
 

Modified: pkg/CHNOSZ/man/retrieve.Rd
===================================================================
--- pkg/CHNOSZ/man/retrieve.Rd	2020-07-23 06:25:03 UTC (rev 573)
+++ pkg/CHNOSZ/man/retrieve.Rd	2020-07-24 00:40:29 UTC (rev 574)
@@ -68,7 +68,7 @@
 iMn <- retrieve("Mn", c("O", "H"), "aq")
 species(iMn)
 a <- affinity(pH = c(6, 14), Eh = c(-1, 1))
-diagram(a, fill = "terrain")
+diagram(a, fill = "terrain", limit.water = TRUE)
 \dontshow{par(thermo()$opar)}
 }
 

Modified: pkg/CHNOSZ/tests/testthat/test-diagram.R
===================================================================
--- pkg/CHNOSZ/tests/testthat/test-diagram.R	2020-07-23 06:25:03 UTC (rev 573)
+++ pkg/CHNOSZ/tests/testthat/test-diagram.R	2020-07-24 00:40:29 UTC (rev 574)
@@ -5,7 +5,7 @@
   basis("CHNOS")
   species(c("glycine", "alanine"))
   a <- affinity()
-  expect_message(diagram(a, plot.it=FALSE), "balance: moles of CO2 in formation reactions")
+  expect_message(diagram(a, plot.it=FALSE), "balance: on moles of CO2 in formation reactions")
   e <- equilibrate(a)
   expect_error(diagram(e, "Z"), "Z is not a valid diagram type")
 })
@@ -22,7 +22,7 @@
   # we can't calculate the equilibrium activity of a basis species if it's externally buffered
   expect_error(diagram(a, "O2"), "is not numeric - was a buffer selected\\?")
   # this one works - a barplot of A/2.303RT
-  expect_message(diagram(a, plot.it=FALSE), "balance: moles of CO2 in formation reactions")
+  expect_message(diagram(a, plot.it=FALSE), "balance: on moles of CO2 in formation reactions")
   # if we're plotting A/2.303RT the values can be divided by balancing coefficient or not
   d.1 <- diagram(a, balance=1, plot.it=FALSE)
   d.CO2 <- diagram(a, plot.it=FALSE)

Modified: pkg/CHNOSZ/tests/testthat/test-equilibrate.R
===================================================================
--- pkg/CHNOSZ/tests/testthat/test-equilibrate.R	2020-07-23 06:25:03 UTC (rev 573)
+++ pkg/CHNOSZ/tests/testthat/test-equilibrate.R	2020-07-24 00:40:29 UTC (rev 574)
@@ -18,17 +18,17 @@
 test_that("equilibrate() gives expected messages and errors for balance calculation", {
   # the following error is triggered by equil.react, not equil.boltzmann
   expect_error(equilibrate(aone), "at least two species needed")
-  expect_message(equilibrate(aacid), "balance: moles of CO2")
+  expect_message(equilibrate(aacid), "balance: on moles of CO2")
   expect_message(equilibrate(aacid), "n.balance is 2 1 1 2")
   expect_message(equilibrate(aacid), "loga.balance is -2.221848")
   expect_message(equilibrate(aacid, loga.balance=-3), "loga.balance is -3")
   expect_error(equilibrate(aacid, balance="length"), "some species are not proteins")
   expect_error(equilibrate(aacidS), "no basis species is present in all formation reactions")
-  expect_message(equilibrate(aacidS, balance=1), "balance: from supplied numeric argument")
+  expect_message(equilibrate(aacidS, balance=1), "balance: on supplied numeric argument")
   expect_message(equilibrate(aacidS, balance=1), "n.balance is 1 1 1 1 1")
   expect_message(equilibrate(aacidS, balance=1), "loga.balance is -2.301029")
   expect_error(equilibrate(aacidS, balance="CO2"), "some species have no CO2 in the formation reaction")
-  expect_message(equilibrate(aprot), "balance: from protein length")
+  expect_message(equilibrate(aprot), "balance: on protein length")
   expect_message(equilibrate(aprot), "n.balance is 129 153 124 104")
   expect_message(equilibrate(aprot), "loga.balance is -0.292429")
   expect_message(equilibrate(aprot, normalize=TRUE), "using 'normalize' for molar formulas")

Modified: pkg/CHNOSZ/vignettes/multi-metal.Rmd
===================================================================
--- pkg/CHNOSZ/vignettes/multi-metal.Rmd	2020-07-23 06:25:03 UTC (rev 573)
+++ pkg/CHNOSZ/vignettes/multi-metal.Rmd	2020-07-24 00:40:29 UTC (rev 574)
@@ -353,7 +353,9 @@
 Then, the two diagrams are flattened to show all minerals in a single diagram.
 Greener colors are used to indicate minerals with lower S~2~ and higher O~2~ in their formation reactions.
 
-```{r stack2, results = "hide", message = FALSE, fig.width = 6, fig.height = 4, out.width = "100%", pngquant = pngquant}
+<button id="B-stack2" onclick="ToggleDiv('stack2')">Show code</button>
+<div id="D-stack2" style="display: none">
+```{r stack2, eval = FALSE}
 T <- 125
 layout(matrix(c(1, 2, 3, 3), nrow = 2), widths = c(1, 1.5))
 
@@ -395,7 +397,11 @@
 legend("topleft", legend = lTP(T, "Psat"))
 title("Cu-Fe-S-O-H")
 ```
+</div>
 
+```{r stack2, echo = FALSE, results = "hide", message = FALSE, fig.width = 6, fig.height = 4, out.width = "100%", pngquant = pngquant}
+```
+
 The resulting diagram is similar to Figure 2 of @Sve87; that diagram also shows calculations of the solubility of Cu and concentration of SO~4~^-2^ in model Cu ore-forming fluids.
 The `solubility()` function can be used to make these calculations.
 By combining it with the output of `mosaic()`, we use the solubilities of the stable minerals across the diagram to calculate the total concentration of Cu in solution, including its complexes.
@@ -402,8 +408,6 @@
 The pH for these calculations is set to 6, and the molality of free Cl^-^, which affects the formation of the Cu chloride complexes, is estimated based on the composition of fluids from Table 2 of @Sve87 (ca. 80000 mg Cl / kg H~2~O) and the `NaCl()` function in CHNOSZ.
 This also gives an estimated ionic strength, which is used in the following `mosaic()` and `affinity()` calls to calculate activity coefficients.
 
-See the detailed comments in the code below.
-
 <button id="B-solubility" onclick="ToggleDiv('solubility')">Show code</button>
 <div id="D-solubility" style="display: none">
 ```{r solubility, eval = FALSE}
@@ -420,14 +424,18 @@
 basis("Cl-", log10(calc$m_Cl))
 
 # Calculate affinities for aqueous Cu species while changing both Fe and Cu minerals
-mFeCu <- mosaic(list(bFe, bCu), S2 = c(-34, -10), O2 = c(-55, -40),
-  T = T, IS = calc$IS, predominant = list(dFe$predominant, dCu$predominant))
-# Calculate concentration of Cu
-s <- solubility(mFeCu$A.species)
-s <- convert(s, "ppm")
-diagram(aFeCu, names = NA, col = "gray", fill = fill)
-diagram(s, type = "loga.balance", levels = 10^(-3:3), add = TRUE)
-diagram(s, type = "loga.balance", levels = 35, add = TRUE, lwd = 3, col = 6, contour.method = NA)
+mfun <- function() {
+  mFeCu <- mosaic(list(bFe, bCu), S2 = c(-34, -10), O2 = c(-55, -40),
+    T = T, IS = calc$IS, predominant = list(dFe$predominant, dCu$predominant))
+  # Calculate concentration of Cu
+  s <- solubility(mFeCu$A.species)
+  s <- convert(s, "ppm")
+  diagram(aFeCu, names = NA, col = "gray", fill = fill)
+  diagram(s, type = "loga.balance", levels = 10^(-3:3), add = TRUE)
+  diagram(s, type = "loga.balance", levels = 35, add = TRUE, lwd = 3, col = 6, contour.method = NA)
+}
+# DIAGRAM 1
+mfun()
 title("Cu (ppm)")
 
 # Calculate logK for CuCl2- dissociation at 125 °C
@@ -447,15 +455,8 @@
 newG <- info(info("CuCl3-2"))$G + dG
 mod.OBIGT("CuCl3-2", G = newG)
 
-# Calculate affinities for aqueous Cu species while changing both Fe and Cu minerals
-mFeCu <- mosaic(list(bFe, bCu), S2 = c(-34, -10), O2 = c(-55, -40),
-  T = T, IS = calc$IS, predominant = list(dFe$predominant, dCu$predominant))
-# Calculate concentration of Cu
-s <- solubility(mFeCu$A.species)
-s <- convert(s, "ppm")
-diagram(aFeCu, names = NA, col = "gray", fill = fill)
-diagram(s, type = "loga.balance", levels = 10^(-3:3), add = TRUE)
-diagram(s, type = "loga.balance", levels = 35, add = TRUE, lwd = 3, col = 6, contour.method = NA)
+# DIAGRAM 2
+mfun()
 title("Cu (ppm)", line = 1.7)
 CuCl2 <- expr.species("CuCl2-")
 CuCl3 <- expr.species("CuCl3-2")
@@ -467,6 +468,7 @@
 # Calculate concentration of SO4-2
 s <- solubility(aSO4, in.terms.of = "SO4-2")
 s <- convert(s, "ppm")
+# DIAGRAM 3
 diagram(aFeCu, names = NA, col = "gray", fill = fill)
 diagram(s, type = "loga.balance", levels = 10^(-3:3), add = TRUE)
 diagram(s, type = "loga.balance", levels = 35, add = TRUE, lwd = 3, col = 6, contour.method = NA)
@@ -477,7 +479,7 @@
 ```{r solubility, echo = FALSE, results = "hide", message = FALSE, fig.width = 7, fig.height = 3, out.width = "100%", fig.align = "center", pngquant = pngquant}
 ```
 
-After running the above code, we can inspect the value of `calc` to show the estimated ionic strength and activity of Cl^-^; the latter is very close to unity.
+After running the code above, we can inspect the value of `calc` to show the estimated ionic strength and activity of Cl^-^; the latter is very close to unity.
 ```{r NaCl}
 # Ionic strength
 calc$IS
@@ -672,7 +674,7 @@
 The diagram shows the expected ionization of acetic acid and NH~3~ at different pHs.
 The appearance of acetamide (CH~3~CONH~2~) is a consequence of the interaction between the N-bearing and C-bearing species, and is analogous to the formation of a multi-metal complex.
 
-*Thanks to Kirt Robinson for the feature request and test case that led to this example.*
+*Thanks to Kirt Robinson for the feature request and test case used in this example.*
 
 ## Document History
 



More information about the CHNOSZ-commits mailing list