[CHNOSZ-commits] r585 - in pkg/CHNOSZ: . R inst man vignettes
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sun Jul 26 09:42:16 CEST 2020
Author: jedick
Date: 2020-07-26 09:42:16 +0200 (Sun, 26 Jul 2020)
New Revision: 585
Modified:
pkg/CHNOSZ/DESCRIPTION
pkg/CHNOSZ/R/diagram.R
pkg/CHNOSZ/R/mosaic.R
pkg/CHNOSZ/inst/NEWS.Rd
pkg/CHNOSZ/man/mosaic.Rd
pkg/CHNOSZ/vignettes/multi-metal.Rmd
Log:
Rename 'predominant' argument to 'stable' in mosaic()
Modified: pkg/CHNOSZ/DESCRIPTION
===================================================================
--- pkg/CHNOSZ/DESCRIPTION 2020-07-25 10:36:00 UTC (rev 584)
+++ pkg/CHNOSZ/DESCRIPTION 2020-07-26 07:42:16 UTC (rev 585)
@@ -1,6 +1,6 @@
-Date: 2020-07-25
+Date: 2020-07-26
Package: CHNOSZ
-Version: 1.3.6-58
+Version: 1.3.6-59
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/diagram.R
===================================================================
--- pkg/CHNOSZ/R/diagram.R 2020-07-25 10:36:00 UTC (rev 584)
+++ pkg/CHNOSZ/R/diagram.R 2020-07-26 07:42:16 UTC (rev 585)
@@ -296,7 +296,7 @@
## handle line type/width/color arguments
if(is.null(lty)) {
- if(type=="loga.balance") lty <- 1
+ if(type=="loga.balance" | nd==2) lty <- 1
else lty <- 1:ngroups
}
lty <- rep(lty, length.out=ngroups)
@@ -537,8 +537,7 @@
# loop in case contourLines returns multiple lines
for(k in 1:length(cLines)) {
# draw the lines
- mylty <- lty
- lines(cLines[[k]][2:3], lty=mylty, col=col, lwd=lwd)
+ lines(cLines[[k]][2:3], lty=lty[i], col=col[i], lwd=lwd[i])
}
}
# mask species to prevent double-plotting contour lines
Modified: pkg/CHNOSZ/R/mosaic.R
===================================================================
--- pkg/CHNOSZ/R/mosaic.R 2020-07-25 10:36:00 UTC (rev 584)
+++ pkg/CHNOSZ/R/mosaic.R 2020-07-26 07:42:16 UTC (rev 585)
@@ -11,7 +11,7 @@
#source("util.args.R")
# function to calculate affinities with mosaic of basis species
-mosaic <- function(bases, bases2 = NULL, blend = TRUE, predominant = list(), ...) {
+mosaic <- function(bases, bases2 = NULL, blend = TRUE, stable = list(), ...) {
# argument recall 20190120
# if the first argument is the result from a previous mosaic() calculation,
@@ -42,7 +42,7 @@
hasbases2 <- TRUE
}
otherargs <- list(...)
- allargs <- c(list(bases = bases, blend = blend, predominant = predominant), otherargs)
+ allargs <- c(list(bases = bases, blend = blend, stable = stable), otherargs)
out <- do.call(mosaic, allargs)
# replace A.bases (affinity calculations for all groups of basis species) with backwards-compatbile A.bases and A.bases2
if(hasbases2) A.bases2 <- out$A.bases[[2]]
@@ -111,7 +111,7 @@
blend <- rep(blend, length(A.bases))
E.bases <- list()
for(i in 1:length(A.bases)) {
- if(blend[i] & is.null(predominant[i][[1]])) {
+ if(blend[i] & is.null(stable[i][[1]])) {
# this isn't needed (and doesn't work) if all the affinities are NA 20180925
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
@@ -129,12 +129,12 @@
} else {
# for blend = FALSE, we just look at whether
# a basis species predominates within its group
- if(is.null(predominant[i][[1]])) {
+ if(is.null(stable[i][[1]])) {
d <- diagram(A.bases[[i]], plot.it = FALSE, limit.water = FALSE)
predom <- d$predominant
} else {
- # get the predominances from the argument 20200715
- predom <- predominant[i][[1]]
+ # get the stable species from the argument 20200715
+ predom <- stable[i][[1]]
}
group.fraction[[i]] <- list()
for(j in 1:length(bases[[i]])) {
Modified: pkg/CHNOSZ/inst/NEWS.Rd
===================================================================
--- pkg/CHNOSZ/inst/NEWS.Rd 2020-07-25 10:36:00 UTC (rev 584)
+++ pkg/CHNOSZ/inst/NEWS.Rd 2020-07-26 07:42:16 UTC (rev 585)
@@ -9,7 +9,7 @@
\newcommand{\s}{\ifelse{latex}{\eqn{_{#1}}}{\ifelse{html}{\out{<sub>#1</sub>}}{#1}}}
\newcommand{\S}{\ifelse{latex}{\eqn{^{#1}}}{\ifelse{html}{\out{<sup>#1</sup>}}{^#1}}}
-\section{Changes in CHNOSZ version 1.3.6-55 (2020-07-25)}{
+\section{Changes in CHNOSZ version 1.3.6-59 (2020-07-26)}{
\subsection{MAJOR CHANGES}{
\itemize{
@@ -62,11 +62,10 @@
\item Add function \strong{rebalance()} for making a new diagram by
secondary balancing between two systems.
- \item Add a \strong{predominant} argument to \code{mosaic()} to use
- previously calculated predominances of species (e.g. minerals) for the
- changing basis species. This allows \code{mosaic()} calculations to be
- linked in series, for instance to sequentially add metals (Fe, then Cu)
- to a diagram.
+ \item Add a \strong{stable} argument to \code{mosaic()} to use previously
+ calculated stabilities of species (e.g. minerals) for the changing basis
+ species. This allows \code{mosaic()} calculations to be linked in series,
+ for instance to sequentially add metals (Fe, then Cu) to a diagram.
\item Add vignette \strong{multi-metal.Rmd} for examples that use these
new features to make diagrams for minerals with multiple metals
@@ -225,7 +224,7 @@
\item TODO: add elements from RH95.
- \item TODO: add check to mosaic() that 'predominant' values have the right dimensions.
+ \item TODO: add check to mosaic() that 'stable' values have the right dimensions.
\item TODO: remove stopifnot() from examples.
Modified: pkg/CHNOSZ/man/mosaic.Rd
===================================================================
--- pkg/CHNOSZ/man/mosaic.Rd 2020-07-25 10:36:00 UTC (rev 584)
+++ pkg/CHNOSZ/man/mosaic.Rd 2020-07-26 07:42:16 UTC (rev 585)
@@ -7,7 +7,7 @@
}
\usage{
- mosaic(bases, bases2 = NULL, blend = TRUE, predominant = list(), ...)
+ mosaic(bases, bases2 = NULL, blend = TRUE, stable = list(), ...)
}
\arguments{
@@ -14,7 +14,7 @@
\item{bases}{character, basis species to be changed in the calculation, or list, containing vectors for each group of changing basis species}
\item{bases2}{character, second set of changing basis species}
\item{blend}{logical, use relative abundances of basis species?}
- \item{predominant}{list, predominant species to use with blend = FALSE}
+ \item{stable}{list, stable species to use with blend = FALSE}
\item{...}{additional arguments to be passed to \code{\link{affinity}}}
}
@@ -23,7 +23,7 @@
\code{mosaic} can be used to calculate the affinities of formation of species when the relative abundances of the basis species listed in \code{bases} change over the range of conditions, due to e.g. ionization, complexation or redox reactions.
This is a way to \dQuote{speciate the basis species}.
For example, the speciation of sulfur (\samp{SO4-2}, \samp{HSO4-}, \samp{HS-} and \samp{H2S}) as a function of Eh and pH affects the formation affinities, and therefore relative stabilities of iron oxide and sulfide minerals.
-Chemical activity diagrams constructed by assembling sub-diagrams corresponding to the predominant basis species can described as \dQuote{mosaic diagrams}.
+Chemical activity diagrams constructed by assembling sub-diagrams corresponding to the predominant (i.e. most stable) basis species can described as \dQuote{mosaic diagrams}.
The function calculates the affinities using all combination of basis species given as vector arguments to \code{bases} and \code{bases2}.
The first species listed in each group should be in the current basis definition, and all the basis species in each group should be related to the first basis species there (i.e. all share the same element).
@@ -37,12 +37,12 @@
If \code{blend} is FALSE, the function returns the affinities calculated using the single predominant basis species in \code{bases} at each condition.
This is appropriate when minerals, rather than aqueous species, are used as the changing basis species.
-Note, however, that \code{mosaic} is not internally recursive: the predominances of one group of basis species (e.g. minerals) are not affected by changes in another group (e.g. aqueous species).
+Note, however, that \code{mosaic} is not internally recursive: the stabilities of one group of basis species (e.g. minerals) are not affected by changes in another group (e.g. aqueous species).
-This limitation can be overcome by supplying the calculated predominances (from the \code{predominant} element of the output of \code{\link{diagram}}) as an element of the list in the \code{predominant} argument whose position corresponds to the appropriate group of basis species.
-By using the predominances of minerals in one calculation to identify the basis species in a subsequent calculation, a series of linked \code{mosaic} diagrams with increasing complexity can be made.
+This limitation can be overcome by supplying the calculated stabilities (from the \code{predominant} element of the output of \code{\link{diagram}}) as an element of the list in the \code{stable} argument whose position corresponds to the appropriate group of basis species.
+By using the stabilities of minerals in one calculation to identify the basis species in a subsequent calculation, a series of linked \code{mosaic} diagrams with increasing complexity can be made.
This is useful for diagrams for minerals with multiple metallic elements.
-Note that a value in any position of the \code{predominant} list forces \code{blend = FALSE} for the corresponding group of basis species, so there is no need to explicity change the \code{blend} argument.
+Note that a value in any position of the \code{stable} list forces \code{blend = FALSE} for the corresponding group of basis species, so there is no need to explicity change the \code{blend} argument.
A more flexible method of specifying multiple sets of basis species is now available.
Instead of using \code{bases} and \code{bases2}, supply a list for just the \code{bases} argument.
Modified: pkg/CHNOSZ/vignettes/multi-metal.Rmd
===================================================================
--- pkg/CHNOSZ/vignettes/multi-metal.Rmd 2020-07-25 10:36:00 UTC (rev 584)
+++ pkg/CHNOSZ/vignettes/multi-metal.Rmd 2020-07-26 07:42:16 UTC (rev 585)
@@ -316,7 +316,7 @@
```
We then compute the affinity for formation of a metastable material, in this case triclinic FeVO~4~, from the same basis species used to make the previous diagrams.
-Given the previous diagrams for the stable Fe-, V- and bimetallic materials *mixed with the same stoichiometry* as FeVO~4~ (1:1 Fe:V), the difference between their affinities of formation and that of FeVO~4~ corresponds to the Pourbaix energy (Δ*G*~pbx~).
+Given the previous diagrams for the stable Fe-, V- and bimetallic materials *mixed with the same stoichiometry* as FeVO~4~ (1:1 Fe:V), the difference between their affinities of formation and that of FeVO~4~ corresponds to the Pourbaix energy (-Δ*G*~pbx~).
This is plotted as a color map in the second diagram.
```{r FeVO4, echo = 22:34, message = FALSE, results = "hide", fig.width = 10, fig.height = 5, out.width = "100%", pngquant = pngquant}
@@ -350,7 +350,7 @@
stopifnot(round(eV_atom, 3) == 0.411)
```
-This is nearly equal to the value of 0.412 eV/atom for the energy above the hull for [triclinic FeVO~4~ on the MP website](https://materialsproject.org/materials/mp-504509/), showing that we successfully made a round-trip starting with the input formation energies (eV/atom) from the MP website, to Gibbs energy (J/mol) in the OBIGT database, and back out to energy above the hull (eV/atom).
+This is nearly equal to the value of 0.412 eV/atom for the energy above the hull for [triclinic FeVO~4~ on the MP website](https://materialsproject.org/materials/mp-504509/), showing that we successfully made a round trip starting with the input formation energies (eV/atom) from the MP website, to Gibbs energy (J/mol) in the OBIGT database, and back out to energy above the hull (eV/atom).
The concept of using the stable minerals and aqueous species to calculate reaction energetics is formalized in the `mosaic()` function, which is described next.
Because this example modified the thermodynamic data for some minerals that are used below, we should restore the default OBIGT database before proceeding to the next section.
@@ -370,36 +370,39 @@
First we define the conditions and basis species.
It is important to put Cu^+^ first so that it will be used as the balance for the reactions with Cu-bearing minerals (which also have Fe).
-Pyrite is chosen as the starting Fe-bearing basis species, which will be changed as indicated in `bases2`.
+Pyrite is chosen as the starting Fe-bearing basis species, which will be changed as indicated in `Fe.cr`.
```{r stack1_1, results = "hide", message = FALSE}
logaH2S <- -2
T <- 200
-pH <- c(0, 12, 500)
-O2 <- c(-50, -30, 500)
+pH <- c(0, 14, 500)
+O2 <- c(-45, -30, 500)
basis(c("Cu+", "pyrite", "H2S", "oxygen", "H2O", "H+"))
basis("H2S", logaH2S)
-bases1 <- c("H2S", "HS-", "HSO4-", "SO4-2")
-bases2 <- c("pyrite", "pyrrhotite", "magnetite", "hematite")
+S.aq <- c("H2S", "HS-", "HSO4-", "SO4-2")
+Fe.cr <- c("pyrite", "pyrrhotite", "magnetite", "hematite")
```
-Now we calculate affinities for minerals in the Fe-S-O-H system that take account of the changing aqueous sulfur species in `bases1`.
+Now we calculate affinities for minerals in the Fe-S-O-H system that take account of the changing aqueous sulfur species in `S.aq`.
The result is used to make different layers of the diagram (1 and 2 are both made by the first call to `diagram()`):
1. Water stability region (bounded by the grey area)
-2. Predominance fields for the aqueous S species (italic blue text and dashed lines)
-3. Stability areas for the Fe-bearing minerals (black text and solid lines)
+2. Predominance fields for the aqueous S species (blue text and dashed lines)
+3. Stability areas for the Fe-bearing minerals (black text and lines)
```{r stack1_2, eval = FALSE, echo = 1:4}
-species(bases2)
-mFe <- mosaic(bases1, pH = pH, O2 = O2, T = T)
+species(Fe.cr)
+mFe <- mosaic(S.aq, pH = pH, O2 = O2, T = T)
diagram(mFe$A.bases, lty = 2, col = 4, col.names = 4, italic = TRUE)
-dFe <- diagram(mFe$A.species, add = TRUE)
-species(c("chalcopyrite", "bornite"))
-mCu <- mosaic(list(bases1, bases2), pH = pH, O2 = O2,
- T = T, predominant = list(NULL, dFe$predominant))
-diagram(mCu$A.species, add = TRUE, col = "#FF4500", col.names = "#FF4500",
- lwd = 2, bold = TRUE)
+dFe <- diagram(mFe$A.species, add = TRUE, lwd = 2)
+FeCu.cr <- c("chalcopyrite", "bornite")
+Cu.cr <- c("copper", "cuprite", "tenorite", "chalcocite", "covellite")
+species(c(FeCu.cr, Cu.cr))
+mFeCu <- mosaic(list(S.aq, Fe.cr), pH = pH, O2 = O2,
+ T = T, stable = list(NULL, dFe$predominant))
+diagram(mFeCu$A.species, add = TRUE, col = 2, col.names = 2, bold = TRUE)
+col <- c("#FF8C00", rep(NA, 6))
+diagram(mFeCu$A.species, add = TRUE, col = col, lwd = 2, col.names = col, bold = TRUE)
TP <- describe.property(c("T", "P"), c(T, "Psat"))
legend("topright", TP, bty = "n")
title(paste("Cu-Fe-S-O-H; Total S =", 10^logaH2S, "m"))
@@ -406,27 +409,27 @@
```
Next we load the Cu-bearing minerals and calculate their affinities while changing *both* the aqueous sulfur species and the Fe-bearing minerals whose stability fields were just calculated.
-The latter step is the key to the mosaic stack and is activated by supplying the calculated stabilities of the Fe-bearing minerals in the `predominant` argument.
+The latter step is the key to the mosaic stack and is activated by supplying the calculated stabilities of the Fe-bearing minerals in the `stable` argument.
This is a list whose elements correspond to each group of changing basis species given in the first argument.
The NULL means that the abundances of S-bearing aqueous species are calculated according to the default in `mosaic()`, which uses `equilibrate()` to compute the continuous transition between them ("blending").
-Because the Fe-bearing minerals are the second group of changing basis species (`bases2`), their stabilities are given in the second position of the `predominant` list.
+Because the Fe-bearing minerals are the second group of changing basis species (`Fe.cr`), their stabilities are given in the second position of the `stable` list.
The result is used to plot the last layer of the diagram:
-4. Stability areas for Cu-bearing minerals (bold red text and solid lines)
+4. Stability areas for Cu-bearing minerals (red text and lines; orange for chalcopyrite)
After that we add the legend and title.
-```{r stack1_2, echo=5:12, results = "hide", message = FALSE, fig.width = 6, fig.height = 5, out.width = "75%", fig.align = "center", pngquant = pngquant}
+```{r stack1_2, echo=5:15, results = "hide", message = FALSE, fig.width = 6, fig.height = 5, out.width = "75%", fig.align = "center", pngquant = pngquant}
```
-This diagram has a distinctive chalcopyrite "hook" that is controlled on the low-pH side by the reaction with pyrite.
-Only that reaction is shown in many published diagrams [e.g. @And75;@Gio02], but diagrams with a similar chalcopyrite wedge or hook can be seen in @BBR77 and @Bri80.
+This diagram has a distinctive chalcopyrite "hook" surrounded by a thin bornite field.
+Only the chalcopyrite-bornite reaction in the pyrite field is shown in many published diagrams [e.g. @And75;@Gio02], but diagrams with a similar chalcopyrite wedge or hook geometry can be seen in @BBR77 and @Bri80.
## Mixing 2
The previous diagram shows a stability boundary between chalcopyrite and bornite but does not identify the stable *assemblages* that contain these minerals.
This is where `mix()` can help.
-Following the pattern described in **Mixing 1**, we first calculate individual diagrams for Fe-S-O-H and Cu-S-O-H, which are overlaid on the first plot and saved in `dFe` and `dCu`.
+Following the workflow described in **Mixing 1**, we first calculate individual diagrams for Fe-S-O-H and Cu-S-O-H, which are overlaid on the first plot and saved in `dFe` and `dCu`.
We then calculate the affinities for the bimetallic Cu and Fe minerals and run them through `diagram()` without actually making a plot, but save the result in `dFeCu`.
Then, we combine the results using `mix()` to define different proportions of Fe and Cu.
@@ -468,11 +471,11 @@
names <- info(info(FeCu.cr))$abbrv
dFeCu <- diagram(mFeCu$A.species, plot.it = FALSE, names = names)
-fill <- function(x) {
- ifelse(grepl("Ccp", x$species$name), "#FF8C0088",
- ifelse(grepl("Bn", x$species$name), "#DC143C88", NA)
+fill <- function(a) {
+ ifelse(grepl("Ccp", a$species$name), "#FF8C0088",
+ ifelse(grepl("Bn", a$species$name), "#DC143C88", NA)
)}
-srt <- function(x) ifelse(x$species$name %in% c("Mt+Bn", "Mt+Cct", "Mt+Ccp"), 80, 0)
+srt <- function(a) ifelse(a$species$name %in% c("Mt+Bn", "Mt+Cct", "Mt+Ccp"), 80, 0)
a11 <- mix(dFe, dCu, dFeCu)
diagram(a11, fill = fill(a11), srt = srt(a11), min.area = 0.01)
@@ -491,11 +494,10 @@
```{r mixing2, echo = FALSE, results = "hide", message = FALSE, fig.width = 8, fig.height = 6.5, out.width = "100%", pngquant = pngquant}
```
-Now we can see that the "hook" has a chalcopyrite core and bornite rim.
-Notably, bornite is not stable outside of this region; this feature is not visible on the previous diagram.
-At an exact 1:1 ratio of Fe:Cu, chalcopyrite is the only stable mineral in the core.
-At a 2:1 ratio, pyrite, pyrrhotite, or magnetite can coexist with chalcopyrite.
-At a 1:2 ratio, an assemblage of the two bimetallic minerals (chalcopyrite and bornite) is stable.
+These diagrams show that changing the amounts of the metals affects the stability of minerals involved in reactions with chalcopyrite.
+At a 1:1 ratio of Fe:Cu, chalcopyrite is a stable single-mineral assemblage.
+At a 2:1 ratio, pyrite, pyrrhotite, or magnetite can coexist in a two-phase assemblage with chalcopyrite.
+At a 1:2 ratio, an assemblage consisting of the two bimetallic minerals (chalcopyrite and bornite) is stable.
## Mosaic Stacking 2
@@ -526,7 +528,7 @@
# stable Fe-bearing minerals (mosaic stack)
bCu <- species(c("copper", "chalcocite", "covellite", "chalcopyrite", "bornite"))$name
mCu <- mosaic(bFe, S2 = c(-34, -10), O2 = c(-55, -40),
- T = T, predominant = list(dFe$predominant))
+ T = T, stable = list(dFe$predominant))
oCu <- order(mCu$A.species$species$S2 - mCu$A.species$species$O2)
fill <- terrain.colors(length(oCu), alpha = 0.3)[oCu]
abbrv <- info(mCu$A.species$species$ispecies)$abbrv
@@ -578,7 +580,7 @@
# Calculate affinities for aqueous Cu species while changing both Fe and Cu minerals
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))
+ T = T, IS = calc$IS, stable = list(dFe$predominant, dCu$predominant))
# Calculate concentration of Cu
s <- solubility(mFeCu$A.species)
s <- convert(s, "ppm")
@@ -824,7 +826,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.
+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 bimetallic complex.
*Thanks to Kirt Robinson for the feature request and test case used in this example.*
More information about the CHNOSZ-commits
mailing list