From noreply at r-forge.r-project.org Fri Feb 1 02:45:02 2019
From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org)
Date: Fri, 1 Feb 2019 02:45:02 +0100 (CET)
Subject: [CHNOSZ-commits] r377 - in pkg/CHNOSZ: . R inst man tests/testthat
vignettes
Message-ID: <20190201014502.3683618AB49@r-forge.r-project.org>
Author: jedick
Date: 2019-02-01 02:45:00 +0100 (Fri, 01 Feb 2019)
New Revision: 377
Modified:
pkg/CHNOSZ/DESCRIPTION
pkg/CHNOSZ/R/affinity.R
pkg/CHNOSZ/R/util.affinity.R
pkg/CHNOSZ/inst/NEWS
pkg/CHNOSZ/man/affinity.Rd
pkg/CHNOSZ/tests/testthat/test-affinity.R
pkg/CHNOSZ/vignettes/obigt.Rmd
pkg/CHNOSZ/vignettes/obigt.bib
Log:
affinity(): add 'return.sout' argument
Modified: pkg/CHNOSZ/DESCRIPTION
===================================================================
--- pkg/CHNOSZ/DESCRIPTION 2019-01-28 08:53:03 UTC (rev 376)
+++ pkg/CHNOSZ/DESCRIPTION 2019-02-01 01:45:00 UTC (rev 377)
@@ -1,6 +1,6 @@
-Date: 2019-01-28
+Date: 2019-02-01
Package: CHNOSZ
-Version: 1.1.3-84
+Version: 1.1.3-85
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/affinity.R
===================================================================
--- pkg/CHNOSZ/R/affinity.R 2019-01-28 08:53:03 UTC (rev 376)
+++ pkg/CHNOSZ/R/affinity.R 2019-02-01 01:45:00 UTC (rev 377)
@@ -13,7 +13,7 @@
#source("species.R")
affinity <- function(..., property=NULL, sout=NULL, exceed.Ttr=FALSE, exceed.rhomin=FALSE,
- return.buffer=FALSE, balance="PBB", iprotein=NULL, loga.protein=-3) {
+ return.buffer=FALSE, return.sout=FALSE, balance="PBB", iprotein=NULL, loga.protein=-3) {
# ...: variables over which to calculate
# property: what type of energy
# (G.basis,G.species,logact.basis,logK,logQ,A)
@@ -111,6 +111,8 @@
a <- aa$a
sout <- aa$sout
+ if(return.sout) return(sout)
+
# more buffer stuff
if(buffer) {
args$what <- "logact.basis"
Modified: pkg/CHNOSZ/R/util.affinity.R
===================================================================
--- pkg/CHNOSZ/R/util.affinity.R 2019-01-28 08:53:03 UTC (rev 376)
+++ pkg/CHNOSZ/R/util.affinity.R 2019-02-01 01:45:00 UTC (rev 377)
@@ -133,9 +133,16 @@
### function for calling subcrt
sout.fun <- function(property="logK") {
- if(!is.null(sout)) return(sout) else {
+ species <- c(mybasis$ispecies,myspecies$ispecies)
+ if(!is.null(sout)) {
+ # extract the needed species from a provided sout 20190131
+ isout <- match(species, sout$species$ispecies)
+ this.sout <- sout
+ this.sout$species <- this.sout$species[isout, ]
+ this.sout$out <- this.sout$out[isout]
+ return(this.sout)
+ } else {
## subcrt arguments
- species <- c(mybasis$ispecies,myspecies$ispecies)
if("T" %in% vars) T <- vals[[which(vars=="T")]]
if("P" %in% vars) P <- vals[[which(vars=="P")]]
if("IS" %in% vars) IS <- vals[[which(vars=="IS")]]
Modified: pkg/CHNOSZ/inst/NEWS
===================================================================
--- pkg/CHNOSZ/inst/NEWS 2019-01-28 08:53:03 UTC (rev 376)
+++ pkg/CHNOSZ/inst/NEWS 2019-02-01 01:45:00 UTC (rev 377)
@@ -1,4 +1,4 @@
-CHANGES IN CHNOSZ 1.1.3-84 (2019-01-28)
+CHANGES IN CHNOSZ 1.1.3-85 (2019-02-01)
---------------------------------------
BUG FIXES
@@ -240,6 +240,9 @@
- In affinity(), make invalid variable names an error.
+- Add 'return.sout' argument to affinity(), to return just the values
+ calculated with subcrt().
+
CHANGES IN CHNOSZ 1.1.3 (2017-11-13)
------------------------------------
Modified: pkg/CHNOSZ/man/affinity.Rd
===================================================================
--- pkg/CHNOSZ/man/affinity.Rd 2019-01-28 08:53:03 UTC (rev 376)
+++ pkg/CHNOSZ/man/affinity.Rd 2019-02-01 01:45:00 UTC (rev 377)
@@ -8,7 +8,7 @@
\usage{
affinity(..., property=NULL, sout=NULL, exceed.Ttr=FALSE, exceed.rhomin = FALSE,
- return.buffer=FALSE, balance="PBB", iprotein=NULL, loga.protein=-3)
+ return.buffer=FALSE, return.sout=FALSE, balance="PBB", iprotein=NULL, loga.protein=-3)
}
\arguments{
@@ -18,6 +18,7 @@
\item{exceed.Ttr}{logical, allow \code{\link{subcrt}} to compute properties for phases beyond their transition temperature?}
\item{exceed.rhomin}{logical, allow \code{\link{subcrt}} to compute properties of species in the HKF model below 0.35 g cm\S{-3}?}
\item{return.buffer}{logical. If \code{TRUE}, and a \code{\link{buffer}} has been associated with one or more basis species in the system, return the values of the activities of the basis species calculated using the buffer. Default is \code{FALSE}.}
+ \item{return.sout}{logical, return only the values calculated with \code{\link{subcrt}}?}
\item{balance}{character. This argument is used to identify a conserved basis species (or \samp{PBB}) in a chemical activity buffer. Default is \samp{PBB}.}
\item{iprotein}{numeric, indices of proteins in \code{\link{thermo}$protein} for which to calculate properties}
\item{loga.protein}{numeric, logarithms of activities of proteins identified in \code{iprotein}}
Modified: pkg/CHNOSZ/tests/testthat/test-affinity.R
===================================================================
--- pkg/CHNOSZ/tests/testthat/test-affinity.R 2019-01-28 08:53:03 UTC (rev 376)
+++ pkg/CHNOSZ/tests/testthat/test-affinity.R 2019-02-01 01:45:00 UTC (rev 377)
@@ -174,6 +174,7 @@
})
test_that("argument recall is usable", {
+ # 20190127
basis("CHNOS")
species(c("CO2", "CH4"))
a0 <- affinity(O2=c(-80, -60))
@@ -184,3 +185,18 @@
# we don't test entire output here becuase a0 doesn't have a "T" argument
expect_identical(a0$values, a3$values)
})
+
+test_that("sout is processed correctly", {
+ # 20190201
+ basis("CHNOS+")
+ # previously, this test would fail when sout has
+ # more species than are used in the calculation
+ species(c("H2S", "CO2", "CH4"))
+ a0 <- affinity(T = c(0, 100))
+ sout <- a0$sout
+ # test the calculation with just CH4
+ species(1:2, delete = TRUE)
+ a1 <- affinity(T = c(0, 100))
+ a2 <- affinity(T = c(0, 100), sout = a0$sout)
+ expect_equal(a1$values, a2$values)
+})
Modified: pkg/CHNOSZ/vignettes/obigt.Rmd
===================================================================
--- pkg/CHNOSZ/vignettes/obigt.Rmd 2019-01-28 08:53:03 UTC (rev 376)
+++ pkg/CHNOSZ/vignettes/obigt.Rmd 2019-02-01 01:45:00 UTC (rev 377)
@@ -119,7 +119,7 @@
* Data from SUPCRT92 which have been superseded by the Berman data are listed under **Optional Data** / **SUPCRT92**.
-* Superseded data from SLOP98 (aqueous Au species) are listed under **Optional Data** / **SLOP98**.
+* Superseded data from SLOP98 (aqueous SiO2 and Al, As, and Au species) are listed under **Optional Data** / **SLOP98**.
# Sources of data {.tabset .tabset-fade}
@@ -227,7 +227,7 @@
### `r setfile("SLOP98.csv")`
```{r SLOP98, results="asis", echo=FALSE}
-cat('These species, taken from the slop98 data file, were present in earlier versions of CHNOSZ but have been replaced by or are inconsistent with later updates. The data are kept here for comparative purposes. Use e.g. `add.obigt("SLOP98")` to load the data.\n\n')
+cat('These species, taken from the slop98 data file, were present in earlier versions of CHNOSZ but have been replaced by or are inconsistent with later updates. The data are kept here for comparative purposes. Use `add.obigt("SLOP98")` to load the data.\n\n')
```
```{r optreflist, results="asis", echo=FALSE}
@@ -235,7 +235,7 @@
### `r setfile("SUPCRT92.csv")`
```{r SUPCRT92, results="asis", echo=FALSE}
-cat("These minerals, taken from the SUPCRT92 database, were used by default in earlier versions of CHNOSZ but have since been superseded by the Berman dataset. They are kept as optional data for testing and comparison purposes. The minerals here include all of the silicates and Al-bearing minerals from [Helgeson et al., 1978](http://www.worldcat.org/oclc/13594862), as well as calcite, dolomite, hematite, and magnetite. Note that other minerals from SUPCRT92 (including native elements, sulfides, halides, sulfates, and selected carbonates and oxides that do not duplicate those in the Berman dataset) are still present in the default database (**inorganic_cr.csv**).\n\n")
+cat('These minerals, taken from the SUPCRT92 database, were present in earlier versions of CHNOSZ but have since been superseded by the Berman dataset. They are kept as optional data for testing and comparison purposes. The minerals here include all of the silicates and Al-bearing minerals from [Helgeson et al., 1978](http://www.worldcat.org/oclc/13594862), as well as calcite, dolomite, hematite, and magnetite. Use `add.obigt("SUPCRT92")` to load the data. Note that other minerals from SUPCRT92, including native elements, sulfides, halides, sulfates, and selected carbonates and oxides that do not duplicate those in the Berman dataset, are still present in the default database (**inorganic_cr.csv**).\n\n')
```
```{r optreflist, results="asis", echo=FALSE}
Modified: pkg/CHNOSZ/vignettes/obigt.bib
===================================================================
--- pkg/CHNOSZ/vignettes/obigt.bib 2019-01-28 08:53:03 UTC (rev 376)
+++ pkg/CHNOSZ/vignettes/obigt.bib 2019-02-01 01:45:00 UTC (rev 377)
@@ -1177,16 +1177,16 @@
}
@Article{HP11,
- author = {Holland, T. J. B. and Powell, R.},
- journal = {Journal of Metamorphic Geology},
- title = {{A}n improved and extended internally consistent thermodynamic dataset for phases of petrological interest, involving a new equation of state for solids},
- year = {2011},
- volume = {29},
- number = {3},
- pages = {333--383},
- doi = {10.1111/j.1525-1314.2010.00923.x},
- sn = {0263-4929},
- z9 = {2},
+ author = {Holland, T. J. B. and Powell, R.},
+ journal = {Journal of Metamorphic Geology},
+ title = {{A}n improved and extended internally consistent thermodynamic dataset for phases of petrological interest, involving a new equation of state for solids},
+ year = {2011},
+ volume = {29},
+ number = {3},
+ pages = {333--383},
+ doi = {10.1111/j.1525-1314.2010.00923.x},
+ sn = {0263-4929},
+ z9 = {2},
}
@Article{HRA91,
@@ -1260,13 +1260,12 @@
pages = {9--70},
doi = {10.1144/SP402.4},
issn = {0305-8719},
- publisher = {Geological Society of London},
}
@Article{WS00,
author = {Wood, Scott A. and Samson, Iain M.},
journal = {Economic Geology},
- title = {{T}he hydrothermal geochemistry of tungsten in granitoid environments: {I}. {R}elative solubilities of ferberite and scheelite as a function of {T}, {P}, p{H}, and m{N}a{C}l},
+ title = {{T}he hydrothermal geochemistry of tungsten in granitoid environments: {I}. {R}elative solubilities of ferberite and scheelite as a function of {T}, {P}, p{H}, and $m_\text{NaCl}$},
year = {2000},
volume = {95},
number = {1},
From noreply at r-forge.r-project.org Fri Feb 1 06:42:25 2019
From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org)
Date: Fri, 1 Feb 2019 06:42:25 +0100 (CET)
Subject: [CHNOSZ-commits] r378 - in pkg/CHNOSZ: . R demo inst man
tests/testthat
Message-ID: <20190201054225.2107F18B828@r-forge.r-project.org>
Author: jedick
Date: 2019-02-01 06:42:24 +0100 (Fri, 01 Feb 2019)
New Revision: 378
Modified:
pkg/CHNOSZ/DESCRIPTION
pkg/CHNOSZ/R/mosaic.R
pkg/CHNOSZ/demo/mosaic.R
pkg/CHNOSZ/inst/NEWS
pkg/CHNOSZ/man/mosaic.Rd
pkg/CHNOSZ/man/solubility.Rd
pkg/CHNOSZ/tests/testthat/test-mosaic.R
Log:
mosaic(): rewrite for performance and to handle more than two sets of changing basis species
Modified: pkg/CHNOSZ/DESCRIPTION
===================================================================
--- pkg/CHNOSZ/DESCRIPTION 2019-02-01 01:45:00 UTC (rev 377)
+++ pkg/CHNOSZ/DESCRIPTION 2019-02-01 05:42:24 UTC (rev 378)
@@ -1,6 +1,6 @@
Date: 2019-02-01
Package: CHNOSZ
-Version: 1.1.3-85
+Version: 1.1.3-86
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/mosaic.R
===================================================================
--- pkg/CHNOSZ/R/mosaic.R 2019-02-01 01:45:00 UTC (rev 377)
+++ pkg/CHNOSZ/R/mosaic.R 2019-02-01 05:42:24 UTC (rev 378)
@@ -1,15 +1,22 @@
# CHNOSZ/mosaic.R
# calculate affinities with changing basis species
-# 20141220 jmd
+# 20141220 jmd initial version
+# 20190129 complete rewrite to use any number of groups of changing basis species
+# and improve speed by pre-calculating subcrt values (sout)
+## if this file is interactively sourced, the following are also needed to provide unexported functions:
+#source("basis.R")
+#source("util.character.R")
+#source("util.args.R")
+
# function to calculate affinities with mosaic of basis species
-mosaic <- function(bases, bases2=NULL, blend=FALSE, ...) {
+mosaic <- function(bases, bases2 = NULL, blend = FALSE, mixing = FALSE, ...) {
# argument recall 20190120
# if the first argument is the result from a previous mosaic() calculation,
# just update the remaining arguments
if(is.list(bases)) {
- if(identical(bases[1], list(fun="mosaic"))) {
+ if(identical(bases[1], list(fun = "mosaic"))) {
aargs <- bases$args
# we can only update arguments given in ...
ddd <- list(...)
@@ -23,100 +30,131 @@
}
}
- if(is.null(bases2)) {
- # the arguments for affinity()
- myargs <- list(...)
- } else {
- # the arguments for affinity (first set of basis species; outer loop)
- myargs1 <- list(...)
- # the arguments for mosaic() (second set of basis species; inner loop)
- myargs <- list(bases=bases2, blend=blend, ...)
+ # backward compatibility 20190131:
+ # bases can be a vector instead of a list
+ # bases2 can be present
+ if(!is.list(bases)) {
+ bases <- list(bases)
+ hasbases2 <- FALSE
+ if(!is.null(bases2)) {
+ bases <- c(bases, list(bases2))
+ hasbases2 <- TRUE
+ }
+ otherargs <- list(...)
+ allargs <- c(list(bases = bases, blend = blend, mixing = mixing), 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]]
+ A.bases <- out$A.bases[[1]]
+ out$A.bases <- A.bases
+ if(hasbases2) out <- c(out, list(A.bases2 = A.bases2))
+ return(out)
}
- # are the swapped basis species on the plot?
- # (the first one should be present in the starting basis set)
- iswap <- match(bases[1], names(myargs))
- # the log activity of the starting basis species
- logact.swap <- basis()$logact[ibasis(bases[1])]
+ # save starting basis and species definition
+ basis0 <- get("thermo")$basis
+ species0 <- get("thermo")$species
+ # get species indices of requested basis species
+ ispecies <- lapply(bases, info)
+ if(any(is.na(unlist(ispecies)))) stop("one or more of the requested basis species is unavailable")
+ # identify starting basis species
+ ispecies0 <- sapply(ispecies, "[", 1)
+ ibasis0 <- match(ispecies0, basis0$ispecies)
+ # quit if starting basis species are not present
+ ina <- is.na(ibasis0)
+ if(any(ina)) stop("the starting basis does not have ", paste(bases[ina], collapse = ", "))
- # a list where we'll keep the affinity calculations
- affs <- list()
- for(i in seq_along(bases)) {
- message(paste("mosaic: current basis species is", bases[i], sep=" "))
- # set up argument list: name of swapped-in basis species
- if(!is.na(iswap)) names(myargs)[iswap] <- bases[i]
- # calculate affinities
- if(is.null(bases2)) {
- affs[[i]] <- do.call(affinity, myargs)
- } else {
- mcall <- do.call(mosaic, myargs)
- affs[[i]] <- mcall$A.species
- A.bases2 <- mcall$A.bases
- }
- # change the basis species; restore the original at the end of the loop
- if(can.be.numeric(logact.swap)) logact.swap <- as.numeric(logact.swap)
- if(i < length(bases)) {
- swap.basis(bases[i], bases[i+1])
- # TODO: basis() requires the formula to identify the basis species,
- # would be nicer to just use the ibasis here
- bformula <- rownames(basis())[ibasis(bases[i+1])]
- basis(bformula, logact.swap)
- } else {
- swap.basis(bases[i], bases[1])
- bformula <- rownames(basis())[ibasis(bases[1])]
- basis(bformula, logact.swap)
- }
+ # run subcrt() calculations for all basis species and formed species 20190131
+ # this avoids repeating the calculations in different calls to affinity()
+ # add all the basis species here - the formed species are already present
+ lapply(bases, species)
+ sout <- affinity(..., return.sout = TRUE)
+
+ # calculate affinities of the basis species themselves
+ A.bases <- list()
+ for(i in 1:length(bases)) {
+ message("mosaic: calculating affinities of basis species group ", i, ": ", paste(bases[[i]], collapse=" "))
+ species(delete = TRUE)
+ species(bases[[i]])
+ A.bases[[i]] <- suppressMessages(affinity(..., sout = sout))
}
- # calculate affinities of formation of basis species
- message(paste("mosaic: combining diagrams for", paste(bases, collapse=" "), sep=" "))
- ispecies <- species()$ispecies
- species.logact <- species()$logact
- species(delete=TRUE)
- species(bases)
- if(is.null(bases2)) A.bases <- do.call(affinity, myargs)
- else A.bases <- do.call(affinity, myargs1)
- # restore original species with original activities
- species(delete=TRUE)
- species(ispecies, species.logact)
+ # get all combinations of basis species
+ newbases <- as.matrix(expand.grid(ispecies))
+ allbases <- matrix(basis0$ispecies, nrow = 1)[rep(1, nrow(newbases)), , drop = FALSE]
+ allbases[, ibasis0] <- newbases
- # affinities calculated using the first basis species
- A.species <- affs[[1]]
+ # calculate affinities of species for all combinations of basis species
+ aff.species <- list()
+ message("mosaic: calculating affinities of species for all ", nrow(allbases), " combinations of the basis species")
+ # run backwards so that we put the starting basis species back at the end
+ for(i in nrow(allbases):1) {
+ put.basis(allbases[i, ], basis0$logact)
+ # we have to define the species using the current basis
+ species(species0$ispecies, species0$logact)
+ aff.species[[i]] <- suppressMessages(affinity(..., sout = sout))
+ }
+
+ # calculate equilibrium mole fractions for each group of basis species
+ group.fraction <- list()
if(blend) {
- # calculate affinities using relative abundances of basis species
- # this isn't needed (and doesn't work) if all the affinities are NA 20180925
- if(any(!sapply(A.species$values, is.na))) {
- e <- equilibrate(A.bases)
- # what is the total activity of the basis species?
- a.tot <- Reduce("+", lapply(e$loga.equil, function(x) 10^x))
- for(j in seq_along(affs)) {
- for(i in seq_along(A.species$values)) {
- # start with zero affinity
- if(j==1) A.species$values[[i]][] <- 0
- # add affinity scaled by relative abundance of this basis species
- # and include mixing term (-x*log10(x)) 20190121
- x <- 10^e$loga.equil[[j]]/a.tot
- A.species$values[[i]] <- A.species$values[[i]] + affs[[j]]$values[[i]] * x - x * log10(x)
- }
+ for(i in 1:length(A.bases)) {
+ # this isn't needed (and doesn't work) if all the affinities are NA 20180925
+ if(any(!sapply(A.bases[[1]]$values, is.na))) {
+ e <- equilibrate(A.bases[[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)
+ group.fraction[[i]] <- lapply(a.equil, function(x) x / a.tot)
+ } else {
+ group.fraction[[i]] <- A.bases[[i]]$values
}
}
} else {
- # use affinities from the single predominant basis species
- d <- diagram(A.bases, plot.it=FALSE)
- # merge affinities using the second, third, ... basis species
- for(j in tail(seq_along(affs), -1)) {
- is.predominant <- d$predominant==j
- # diagram() produces NA beyond water limits on Eh-pH diagrams (but we can't use NA for indexing, below)
- is.predominant[is.na(is.predominant)] <- FALSE
- for(i in seq_along(A.species$values)) {
- A.species$values[[i]][is.predominant] <- affs[[j]]$values[[i]][is.predominant]
+ # for blend = FALSE, we just look at whether
+ # a basis species predominates within its group
+ for(i in 1:length(A.bases)) {
+ d <- diagram(A.bases[[i]], plot.it = FALSE, limit.water = FALSE)
+ group.fraction[[i]] <- list()
+ for(j in 1:length(bases[[i]])) {
+ # if a basis species predominates, it has a mole fraction of 1, or 0 otherwise
+ yesno <- d$predominant
+ yesno[yesno != j] <- 0
+ yesno[yesno == j] <- 1
+ group.fraction[[i]][[j]] <- yesno
}
}
}
+ # make an indexing matrix for all combinations of basis species
+ ind.mat <- list()
+ for(i in 1:length(ispecies)) ind.mat[[i]] <- 1:length(ispecies[[i]])
+ ind.mat <- as.matrix(expand.grid(ind.mat))
+
+ # calculate mole fractions for each combination of basis species
+ for(i in 1:nrow(ind.mat)) {
+ # multiply fractions from each group
+ for(j in 1:ncol(ind.mat)) {
+ if(j==1) x <- group.fraction[[j]][[ind.mat[i, j]]]
+ else x <- x * group.fraction[[j]][[ind.mat[i, j]]]
+ }
+ # multiply affinities by the mole fractions of basis species
+ # include mixing term (-x*log10(x)) 20190121
+ if(blend & mixing) aff.species[[i]]$values <- lapply(aff.species[[i]]$values, function(values) values * x - x * log10(x))
+ else aff.species[[i]]$values <- lapply(aff.species[[i]]$values, function(values) values * x)
+ }
+
+ # get total affinities for the species
+ A.species <- aff.species[[1]]
+ for(i in 1:length(A.species$values)) {
+ # extract the affinity contributions from each basis species
+ A.values <- lapply(lapply(aff.species, "[[", "values"), "[[", i)
+ # sum them to get total affinities for this species
+ A.species$values[[i]] <- Reduce("+", A.values)
+ }
+
# for argument recall, include all arguments in output 20190120
- allargs <- c(list(bases=bases, bases2=bases2, blend=blend), list(...))
+ allargs <- c(list(bases = bases, blend = blend, mixing = mixing), list(...))
# return the affinities for the species and basis species
- if(is.null(bases2)) return(list(fun="mosaic", args=allargs, A.species=A.species, A.bases=A.bases))
- else return(list(fun="mosaic", args=allargs, A.species=A.species, A.bases=A.bases, A.bases2=A.bases2))
+ return(list(fun = "mosaic", args = allargs, A.species = A.species, A.bases = A.bases))
}
Modified: pkg/CHNOSZ/demo/mosaic.R
===================================================================
--- pkg/CHNOSZ/demo/mosaic.R 2019-02-01 01:45:00 UTC (rev 377)
+++ pkg/CHNOSZ/demo/mosaic.R 2019-02-01 05:42:24 UTC (rev 378)
@@ -1,10 +1,13 @@
+# CHNOSZ/demo/mosaic.R
+# 20141221 first version
+
# Fe-minerals and aqueous species in Fe-S-O-H-C system
# after Garrels and Christ, 1965 Figure 7.21
# to reproduce their diagram as closely as posssible, use their thermodynamic data (from Appendix 2)
-mod.obigt(c("Fe+2", "Fe+3"), G=c(-20300, -2520))
-mod.obigt(c("hematite", "magnetite", "pyrrhotite", "pyrite", "siderite"), G=c(-177100, -242400, -23320, -36000, -161060))
-mod.obigt(c("SO4-2", "HS-", "H2S", "HSO4-"), G=c(-177340, 3010, -6540, -179940))
-mod.obigt(c("CO2", "HCO3-", "CO3-2"), G=c(-92310, -140310, -126220))
+mod.obigt(c("Fe+2", "Fe+3"), G = c(-20300, -2520))
+mod.obigt(c("hematite", "magnetite", "pyrrhotite", "pyrite", "siderite"), G = c(-177100, -242400, -23320, -36000, -161060))
+mod.obigt(c("SO4-2", "HS-", "H2S", "HSO4-"), G = c(-177340, 3010, -6540, -179940))
+mod.obigt(c("CO2", "HCO3-", "CO3-2"), G = c(-92310, -140310, -126220))
# conditions and system definition
pH <- c(0, 14, 400)
Eh <- c(-1, 1, 400)
@@ -22,18 +25,18 @@
# calculate affinities using the predominant basis species
# using blend=TRUE we get curvy lines, particularly at the boundaries with siderite
# compare with the plot in Garrels and Christ, 1965
-m1 <- mosaic(bases, bases2, blend=TRUE, pH=pH, Eh=Eh, T=T)
+m1 <- mosaic(bases, bases2, blend = TRUE, pH = pH, Eh = Eh, T = T)
# make a diagram and add water stability lines
-diagram(m1$A.species, lwd=2)
-water.lines(m1$A.species, col="seagreen", lwd=1.5)
+diagram(m1$A.species, lwd = 2)
+water.lines(m1$A.species, col = "seagreen", lwd = 1.5)
# show lines for Fe(aq) = 10^-4 M
species(c("Fe+2", "Fe+3"), -4)
-m2 <- mosaic(bases, bases2, blend=TRUE, pH=pH, Eh=Eh, T=T)
-diagram(m2$A.species, add=TRUE, names=NULL)
+m2 <- mosaic(bases, bases2, blend = TRUE, pH = pH, Eh = Eh, T = T)
+diagram(m2$A.species, add = TRUE, names = NULL)
title(main=paste("Iron oxides, sulfides and carbonate in water, log(total S) = -6,",
- "log(total C)=0, after Garrels and Christ, 1965", sep="\n"))
+ "log(total C)=0, after Garrels and Christ, 1965", sep = "\n"))
# overlay the carbonate basis species predominance fields
-d <- diagram(m1$A.bases2, add=TRUE, col="blue", names=NULL, lty=3, limit.water=FALSE)
-text(d$namesx, -0.8, as.expression(sapply(m1$A.bases2$species$name, expr.species)), col="blue")
+d <- diagram(m1$A.bases2, add = TRUE, col = "blue", names = NULL, lty = 3, limit.water = FALSE)
+text(d$namesx, -0.8, as.expression(sapply(m1$A.bases2$species$name, expr.species)), col = "blue")
# reset the database, as it was changed in this example
data(thermo)
Modified: pkg/CHNOSZ/inst/NEWS
===================================================================
--- pkg/CHNOSZ/inst/NEWS 2019-02-01 01:45:00 UTC (rev 377)
+++ pkg/CHNOSZ/inst/NEWS 2019-02-01 05:42:24 UTC (rev 378)
@@ -1,4 +1,4 @@
-CHANGES IN CHNOSZ 1.1.3-85 (2019-02-01)
+CHANGES IN CHNOSZ 1.1.3-86 (2019-02-01)
---------------------------------------
BUG FIXES
@@ -69,6 +69,15 @@
of NaCl in water, taking account of activity coefficients and the
reaction Na+ + Cl- = NaCl(aq).
+OTHER NEW FEATURES
+
+- Add dumpdata() for returning/writing all packaged thermodynamic data
+ (including default database and optional data files). The file is
+ also available on the website (chnosz.net/download/alldata.csv).
+
+- mosaic() has been rewritten to handle more than two changing groups
+ of basis species.
+
DOCUMENTATION
- Add demo/gold.R for calculations of Au solubility in hydrothermal
@@ -92,10 +101,6 @@
THERMODYNAMIC DATA
-- Add dumpdata() for returning/writing all packaged thermodynamic data
- (including default database and optional data files). The file is
- also available on the website (chnosz.net/download/alldata.csv).
-
- The Berman data (Berman, 1988 and later additions) have replaced the
SUPCRT92 data (based on Helgeson et al., 1978) for most minerals in
the default database (i.e. the one loaded by data(thermo)). Only
Modified: pkg/CHNOSZ/man/mosaic.Rd
===================================================================
--- pkg/CHNOSZ/man/mosaic.Rd 2019-02-01 01:45:00 UTC (rev 377)
+++ pkg/CHNOSZ/man/mosaic.Rd 2019-02-01 05:42:24 UTC (rev 378)
@@ -7,13 +7,14 @@
}
\usage{
- mosaic(bases, bases2=NULL, blend=FALSE, ...)
+ mosaic(bases, bases2 = NULL, blend = FALSE, mixing = FALSE, ...)
}
\arguments{
- \item{bases}{character, basis species to be changed in the calculation}
+ \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{mixing}{logical, include a term for the Gibbs energy of mixing?}
\item{...}{additional arguments to be passed to \code{\link{affinity}}}
}
@@ -28,14 +29,21 @@
The first species listed in \code{bases} should be in the current basis definition.
The arguments in \code{...} are passed to \code{affinity} to specify the conditions.
If \code{blend} is FALSE (the default), the function returns the affinities calculated using the single predominant basis species in \code{bases} at each condition.
-If \code{blend} is TRUE, the function combines the affinities of the formation reactions in proportion to the relative abundances of the basis species at each condition, including a term to account for the Gibbs energy of mixing.
-See the second example in \code{\link{solubility}} for a numerical test of the calculations using \code{blend}.
+If \code{blend} is TRUE, the function combines the affinities of the formation reactions in proportion to the relative abundances of the basis species at each condition.
+Additionally, if \code{mixing} is TRUE, a term is included to account for the Gibbs energy of mixing.
+See the second example in \code{\link{solubility}} for a numerical test of the calculations using \code{blend} and \code{mixing}.
The basis species listed in \code{bases} should all be related to the first basis species there (i.e. all share the same element).
A second, independent set of basis species can be provided in \code{bases2} (for example \samp{CO3-2}, \samp{HCO3-}, \samp{CO2}, if the first set of basis species are the sulfur-bearing ones listed above).
The function then works recursively, by calling itself instead of \code{affinity}, so that the inner loop changes the basis species in \code{bases2}.
In this way, all possible combinations of the two sets of basis species are used in the calculation.
+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.
+The list should contain any number of vectors specifying the groups of basis species.
+All combinations of basis species in these groups are used for the calculations.
+This overcomes the prior limitation of only having two changing groups of basis species.
+
}
\value{
Modified: pkg/CHNOSZ/man/solubility.Rd
===================================================================
--- pkg/CHNOSZ/man/solubility.Rd 2019-02-01 01:45:00 UTC (rev 377)
+++ pkg/CHNOSZ/man/solubility.Rd 2019-02-01 05:42:24 UTC (rev 378)
@@ -121,7 +121,7 @@
## method 2: CO2 and carbonate species as basis species
basis(c("calcite", "CO2", "H2O", "O2", "H+"))
species(c("Ca+2"))
-m <- mosaic(c("CO2", "HCO3-", "CO3-2"), pH = c(3, 14), blend = TRUE)
+m <- mosaic(c("CO2", "HCO3-", "CO3-2"), pH = c(3, 14), blend = TRUE, mixing = TRUE)
sm0 <- solubility(m)
smI <- solubility(m, find.IS = TRUE)
## plot the results
Modified: pkg/CHNOSZ/tests/testthat/test-mosaic.R
===================================================================
--- pkg/CHNOSZ/tests/testthat/test-mosaic.R 2019-02-01 01:45:00 UTC (rev 377)
+++ pkg/CHNOSZ/tests/testthat/test-mosaic.R 2019-02-01 05:42:24 UTC (rev 378)
@@ -34,8 +34,9 @@
bases <- c("SO4-2", "HSO4-", "HS-", "H2S")
# calculate affinities using the predominant basis species
pH <- c(0, 14, 29)
- m1 <- mosaic(bases, pH=pH)
- m2 <- mosaic(bases, pH=pH, blend=TRUE)
+ m1 <- mosaic(bases, pH = pH)
+ # calculate affinities with smooth transitions between basis species, including a mixing energy
+ m2 <- mosaic(bases, pH = pH, blend = TRUE, mixing = TRUE)
# these species have no S so the results should be similar,
# 20190121 except for a negative free energy of mixing (positive affinity)
expect_true(all(m2$A.species$values[[1]] - m1$A.species$values[[1]] > 0))
From noreply at r-forge.r-project.org Sat Feb 2 12:54:47 2019
From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org)
Date: Sat, 2 Feb 2019 12:54:47 +0100 (CET)
Subject: [CHNOSZ-commits] r379 - in pkg/CHNOSZ: . R demo inst man
tests/testthat vignettes
Message-ID: <20190202115447.12BEE18C2F2@r-forge.r-project.org>
Author: jedick
Date: 2019-02-02 12:54:46 +0100 (Sat, 02 Feb 2019)
New Revision: 379
Modified:
pkg/CHNOSZ/DESCRIPTION
pkg/CHNOSZ/R/mosaic.R
pkg/CHNOSZ/demo/go-IU.R
pkg/CHNOSZ/demo/mosaic.R
pkg/CHNOSZ/inst/NEWS
pkg/CHNOSZ/man/mosaic.Rd
pkg/CHNOSZ/man/solubility.Rd
pkg/CHNOSZ/tests/testthat/test-mosaic.R
pkg/CHNOSZ/vignettes/mklinks.sh
Log:
mosaic(): change defaults to blend = TRUE and mixing = TRUE
Modified: pkg/CHNOSZ/DESCRIPTION
===================================================================
--- pkg/CHNOSZ/DESCRIPTION 2019-02-01 05:42:24 UTC (rev 378)
+++ pkg/CHNOSZ/DESCRIPTION 2019-02-02 11:54:46 UTC (rev 379)
@@ -1,6 +1,6 @@
-Date: 2019-02-01
+Date: 2019-02-02
Package: CHNOSZ
-Version: 1.1.3-86
+Version: 1.1.3-87
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/mosaic.R
===================================================================
--- pkg/CHNOSZ/R/mosaic.R 2019-02-01 05:42:24 UTC (rev 378)
+++ pkg/CHNOSZ/R/mosaic.R 2019-02-02 11:54:46 UTC (rev 379)
@@ -10,7 +10,7 @@
#source("util.args.R")
# function to calculate affinities with mosaic of basis species
-mosaic <- function(bases, bases2 = NULL, blend = FALSE, mixing = FALSE, ...) {
+mosaic <- function(bases, bases2 = NULL, blend = TRUE, mixing = TRUE, ...) {
# argument recall 20190120
# if the first argument is the result from a previous mosaic() calculation,
Modified: pkg/CHNOSZ/demo/go-IU.R
===================================================================
--- pkg/CHNOSZ/demo/go-IU.R 2019-02-01 05:42:24 UTC (rev 378)
+++ pkg/CHNOSZ/demo/go-IU.R 2019-02-02 11:54:46 UTC (rev 379)
@@ -98,9 +98,9 @@
bases <- c("H2S", "HS-", "HSO4-", "SO4-2")
# calculate affinties of formation reactions using the speciated S basis species
res <- 300
-# we "blend" the transitions with pH, unlike LZ11's diagram where
+# the default has blend = TRUE, unlike LZ11's diagram where
# it appears the S-basis species are switched in an on/off fashion
-m <- mosaic(bases, pH=c(0, 14, res), Eh=c(-0.8, 0.8, res), blend=TRUE)
+m <- mosaic(bases, pH=c(0, 14, res), Eh=c(-0.8, 0.8, res))
# adjust colors and names
fill <- rev(heat.colors(nrow(species())))
fill[11:15] <- "darkgrey"
Modified: pkg/CHNOSZ/demo/mosaic.R
===================================================================
--- pkg/CHNOSZ/demo/mosaic.R 2019-02-01 05:42:24 UTC (rev 378)
+++ pkg/CHNOSZ/demo/mosaic.R 2019-02-02 11:54:46 UTC (rev 379)
@@ -9,8 +9,8 @@
mod.obigt(c("SO4-2", "HS-", "H2S", "HSO4-"), G = c(-177340, 3010, -6540, -179940))
mod.obigt(c("CO2", "HCO3-", "CO3-2"), G = c(-92310, -140310, -126220))
# conditions and system definition
-pH <- c(0, 14, 400)
-Eh <- c(-1, 1, 400)
+pH <- c(0, 14, 500)
+Eh <- c(-1, 1, 500)
T <- 25
basis(c("FeO", "SO4-2", "H2O", "H+", "e-", "CO3-2"))
basis("SO4-2", -6)
@@ -22,16 +22,16 @@
# speciate CO3-2, HCO3-, CO2 as a function of pH
bases <- c("SO4-2", "HSO4-", "HS-", "H2S")
bases2 <- c("CO3-2", "HCO3-", "CO2")
-# calculate affinities using the predominant basis species
-# using blend=TRUE we get curvy lines, particularly at the boundaries with siderite
-# compare with the plot in Garrels and Christ, 1965
-m1 <- mosaic(bases, bases2, blend = TRUE, pH = pH, Eh = Eh, T = T)
+# calculate affinities using the relative abundances of different basis species
+# (using default blend = TRUE)
+# note curved lines, particularly at the boundaries with siderite
+m1 <- mosaic(bases, bases2, pH = pH, Eh = Eh, T = T)
# make a diagram and add water stability lines
diagram(m1$A.species, lwd = 2)
water.lines(m1$A.species, col = "seagreen", lwd = 1.5)
# show lines for Fe(aq) = 10^-4 M
species(c("Fe+2", "Fe+3"), -4)
-m2 <- mosaic(bases, bases2, blend = TRUE, pH = pH, Eh = Eh, T = T)
+m2 <- mosaic(bases, bases2, pH = pH, Eh = Eh, T = T)
diagram(m2$A.species, add = TRUE, names = NULL)
title(main=paste("Iron oxides, sulfides and carbonate in water, log(total S) = -6,",
"log(total C)=0, after Garrels and Christ, 1965", sep = "\n"))
Modified: pkg/CHNOSZ/inst/NEWS
===================================================================
--- pkg/CHNOSZ/inst/NEWS 2019-02-01 05:42:24 UTC (rev 378)
+++ pkg/CHNOSZ/inst/NEWS 2019-02-02 11:54:46 UTC (rev 379)
@@ -1,4 +1,4 @@
-CHANGES IN CHNOSZ 1.1.3-86 (2019-02-01)
+CHANGES IN CHNOSZ 1.1.3-87 (2019-02-02)
---------------------------------------
BUG FIXES
@@ -15,10 +15,6 @@
NA where the density of H2O is less than 0.35 g/cm3, avoiding the
output of bogus values in this region. Thanks to Evgeniy Bastrakov.
-- In mosaic() with blend = TRUE, add a previously missing term for
- Gibbs energy of mixing. An example using mosaic() to calculate the
- pH-dependent solubility of calcite has been added to solubility.Rd.
-
- For systems where no basis species is present in all formation
reactions, and the user hasn't provided balance coefficients, stop
with an error instead of setting the balance cofficients to 1.
@@ -78,6 +74,12 @@
- mosaic() has been rewritten to handle more than two changing groups
of basis species.
+- mosaic() gets a new argument 'mixing' (default TRUE), indicating
+ whether the Gibbs energy of ideal mixing should be included in the
+ calculations with blend = TRUE. As a test of this change, an example
+ using mosaic() to calculate the pH-dependent solubility of calcite
+ has been added to solubility.Rd.
+
DOCUMENTATION
- Add demo/gold.R for calculations of Au solubility in hydrothermal
Modified: pkg/CHNOSZ/man/mosaic.Rd
===================================================================
--- pkg/CHNOSZ/man/mosaic.Rd 2019-02-01 05:42:24 UTC (rev 378)
+++ pkg/CHNOSZ/man/mosaic.Rd 2019-02-02 11:54:46 UTC (rev 379)
@@ -7,7 +7,7 @@
}
\usage{
- mosaic(bases, bases2 = NULL, blend = FALSE, mixing = FALSE, ...)
+ mosaic(bases, bases2 = NULL, blend = TRUE, mixing = TRUE, ...)
}
\arguments{
@@ -20,24 +20,21 @@
\details{
-\code{mosaic} can be used to calculate the reaction affinities when the basis species listed in \code{bases} change in relative abundance over the range of conditions, due to e.g. ionization, complexation or redox reactions.
-Chemical activity or predominance diagrams constructed by assembling sub-diagrams corresponding to the predominant basis species have sometimes been described as \dQuote{mosaic diagrams} in the literature.
+\code{mosaic} can be used to calculate the affinities of formation of species when the relative abundances of basis species listed in \code{bases} changes 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}.
-The function calculates the affinities using each basis species listed in \code{bases} in turn, changing them via \code{\link{swap.basis}}.
-The first species listed in \code{bases} should be in the current basis definition.
+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).
+A second, independent set of basis species can be provided in \code{bases2} (for example \samp{CO3-2}, \samp{HCO3-}, \samp{CO2}, if the first set of basis species are the sulfur-bearing ones listed above).
The arguments in \code{...} are passed to \code{affinity} to specify the conditions.
-If \code{blend} is FALSE (the default), the function returns the affinities calculated using the single predominant basis species in \code{bases} at each condition.
-If \code{blend} is TRUE, the function combines the affinities of the formation reactions in proportion to the relative abundances of the basis species at each condition.
-Additionally, if \code{mixing} is TRUE, a term is included to account for the Gibbs energy of mixing.
+
+If \code{blend} is TRUE (the default), the function combines the affinities of the formation reactions in proportion to the relative abundances of the basis species at each condition.
+Additionally, if \code{mixing} is TRUE (the default), a term is included to account for the Gibbs energy of ideal mixing.
See the second example in \code{\link{solubility}} for a numerical test of the calculations using \code{blend} and \code{mixing}.
+If \code{blend} is FALSE, the function returns the affinities calculated using the single predominant basis species in \code{bases} at each condition (in this case, the \code{mixing} argument has no effect).
-The basis species listed in \code{bases} should all be related to the first basis species there (i.e. all share the same element).
-A second, independent set of basis species can be provided in \code{bases2} (for example \samp{CO3-2}, \samp{HCO3-}, \samp{CO2}, if the first set of basis species are the sulfur-bearing ones listed above).
-The function then works recursively, by calling itself instead of \code{affinity}, so that the inner loop changes the basis species in \code{bases2}.
-In this way, all possible combinations of the two sets of basis species are used in the calculation.
-
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.
The list should contain any number of vectors specifying the groups of basis species.
@@ -48,19 +45,19 @@
\value{
A list containing \code{A.species} (affinities of formation of the species with changing basis species) and \code{A.bases} (affinities of formation of the basis species in terms of the first basis species), each having same structure as the list returned by \code{\link{affinity}}.
-If \code{bases2} is provided, the list also contains \code{A.bases2} (affinities of formation of the second set of basis species, in terms of the first one in that set).
+If \code{bases2} is provided, the list also contains \code{A.bases2} (affinities of formation of the second set of basis species).
}
\seealso{
-\code{demo("mosaic")}, extending the example below by addition of carbonate species in \code{bases2}, with \code{blend} set to TRUE, and using thermodynamic data from Garrels and Christ, 1965.
+\code{demo("mosaic")}, extending the example below by addition of carbonate species in \code{bases2}, and using thermodynamic data from Garrels and Christ, 1965.
}
\examples{
\dontshow{data(thermo)}# Fe-minerals and aqueous species in Fe-S-O-H system
# speciate SO4-2, HSO4-, HS-, H2S as a function of Eh and pH
# after Garrels and Christ, 1965 Figure 7.20
-pH <- c(0, 14, 200)
-Eh <- c(-1, 1, 200)
+pH <- c(0, 14, 500)
+Eh <- c(-1, 1, 500)
T <- 25
basis(c("FeO", "SO4-2", "H2O", "H+", "e-"))
basis("SO4-2", -6)
@@ -68,15 +65,17 @@
species(c("pyrrhotite", "pyrite", "hematite", "magnetite"))
# the basis species we'll swap through
bases <- c("SO4-2", "HSO4-", "HS-", "H2S")
-# calculate affinities using the predominant basis species
-m1 <- mosaic(bases, pH=pH, Eh=Eh, T=T)
+# calculate affinities using the relative abundances of the basis species
+# NOTE: set blend = FALSE for sharp transitions between the basis species
+# (looks more like the diagram in GC65)
+m1 <- mosaic(bases, pH = pH, Eh = Eh, T = T)
# make a diagram and add water stability lines
-d <- diagram(m1$A.species, lwd=2)
-water.lines(d, col="seagreen", lwd=1.5)
+d <- diagram(m1$A.species, lwd = 2)
+water.lines(d, col = "seagreen", lwd = 1.5)
# show lines for Fe(aq) = 10^-4 M
species(c("Fe+2", "Fe+3"), -4)
-m2 <- mosaic(bases, pH=pH, Eh=Eh, T=T)
-diagram(m2$A.species, add=TRUE, names=NULL)
+m2 <- mosaic(bases, pH = pH, Eh = Eh, T = T)
+diagram(m2$A.species, add = TRUE, names = NULL)
title(main=paste("Iron oxides and sulfides in water, log(total S) = -6",
"After Garrels and Christ, 1965", sep="\n"))
# we could overlay the basis species predominance fields
Modified: pkg/CHNOSZ/man/solubility.Rd
===================================================================
--- pkg/CHNOSZ/man/solubility.Rd 2019-02-01 05:42:24 UTC (rev 378)
+++ pkg/CHNOSZ/man/solubility.Rd 2019-02-02 11:54:46 UTC (rev 379)
@@ -121,7 +121,7 @@
## method 2: CO2 and carbonate species as basis species
basis(c("calcite", "CO2", "H2O", "O2", "H+"))
species(c("Ca+2"))
-m <- mosaic(c("CO2", "HCO3-", "CO3-2"), pH = c(3, 14), blend = TRUE, mixing = TRUE)
+m <- mosaic(c("CO2", "HCO3-", "CO3-2"), pH = c(3, 14))
sm0 <- solubility(m)
smI <- solubility(m, find.IS = TRUE)
## plot the results
Modified: pkg/CHNOSZ/tests/testthat/test-mosaic.R
===================================================================
--- pkg/CHNOSZ/tests/testthat/test-mosaic.R 2019-02-01 05:42:24 UTC (rev 378)
+++ pkg/CHNOSZ/tests/testthat/test-mosaic.R 2019-02-02 11:54:46 UTC (rev 379)
@@ -6,18 +6,18 @@
a25 <- affinity()
# this is a degenerate case because we only allow NH3 to swap for NH3, and CO2 for CO2;
# however it still exercises the affinity scaling and summing code
- m1_25 <- mosaic("NH3", "CO2", blend=TRUE)
+ m1_25 <- mosaic("NH3", "CO2")
# this failed before we divided by loga.tot to get _relative_ abundances of basis species in mosaic.R
expect_equal(a25$values, m1_25$A.species$values)
# the next call failed when which.pmax(), called by diagram(), choked on a list of length one
- m2_25 <- mosaic("NH3", "CO2")
+ m2_25 <- mosaic("NH3", "CO2", blend = FALSE)
expect_equal(a25$values, m2_25$A.species$values)
# make sure the function works when all affinities are NA
a500 <- affinity(T=500)
# using blend=TRUE was failing prior to version 1.1.3-37
- m1_500 <- mosaic("NH3", "CO2", blend=TRUE, T=500)
+ m1_500 <- mosaic("NH3", "CO2", T=500)
expect_equal(a500$values, m1_500$A.species$values)
- m2_500 <- mosaic("NH3", "CO2", T=500)
+ m2_500 <- mosaic("NH3", "CO2", blend = FALSE, T=500)
expect_equal(a500$values, m2_500$A.species$values)
})
@@ -34,9 +34,9 @@
bases <- c("SO4-2", "HSO4-", "HS-", "H2S")
# calculate affinities using the predominant basis species
pH <- c(0, 14, 29)
- m1 <- mosaic(bases, pH = pH)
+ m1 <- mosaic(bases, pH = pH, blend = FALSE)
# calculate affinities with smooth transitions between basis species, including a mixing energy
- m2 <- mosaic(bases, pH = pH, blend = TRUE, mixing = TRUE)
+ m2 <- mosaic(bases, pH = pH)
# these species have no S so the results should be similar,
# 20190121 except for a negative free energy of mixing (positive affinity)
expect_true(all(m2$A.species$values[[1]] - m1$A.species$values[[1]] > 0))
@@ -44,8 +44,8 @@
expect_equal(unique(sign(diff(as.numeric(m2$A.species$values[[1]] - m1$A.species$values[[1]])))), c(1, -1))
# now with S-bearing species ...
species(c("pyrrhotite", "pyrite"))
- m3 <- mosaic(bases, pH=pH)
- m4 <- mosaic(bases, pH=pH, blend=TRUE)
+ m3 <- mosaic(bases, pH = pH, blend = FALSE)
+ m4 <- mosaic(bases, pH = pH)
# the results are different ...
expect_equal(sapply(m3$A.species$values, "[", 13), sapply(m4$A.species$values, "[", 13), tol=1e-1)
# but more similar at extreme pH values
Modified: pkg/CHNOSZ/vignettes/mklinks.sh
===================================================================
--- pkg/CHNOSZ/vignettes/mklinks.sh 2019-02-01 05:42:24 UTC (rev 378)
+++ pkg/CHNOSZ/vignettes/mklinks.sh 2019-02-02 11:54:46 UTC (rev 379)
@@ -6,7 +6,7 @@
# set background-image:none to remove underlines (from bootstrap theme)
sed -i 's/?`CHNOSZ-package`<\/code>/?`CHNOSZ-package`<\/a><\/code>/g' anintro.html
sed -i 's/?basis<\/code>/?basis<\/a><\/code>/g' anintro.html
-sed -i 's/?mosaic<\/code>/?mosaic<\/a><\/code>/g' anintro.html
+sed -i 's/?mosaic<\/code>/?mosaic<\/a><\/code>/g' anintro.html
sed -i 's/?buffer<\/code>/?buffer<\/a><\/code>/g' anintro.html
sed -i 's/?solubility<\/code>/?solubility<\/a><\/code>/g' anintro.html
sed -i 's/?ionize.aa<\/code>/?ionize.aa<\/a><\/code>/g' anintro.html
From noreply at r-forge.r-project.org Sun Feb 3 04:23:57 2019
From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org)
Date: Sun, 3 Feb 2019 04:23:57 +0100 (CET)
Subject: [CHNOSZ-commits] r380 - in pkg/CHNOSZ: . R vignettes
Message-ID: <20190203032357.EDAE118C1C0@r-forge.r-project.org>
Author: jedick
Date: 2019-02-03 04:23:56 +0100 (Sun, 03 Feb 2019)
New Revision: 380
Modified:
pkg/CHNOSZ/DESCRIPTION
pkg/CHNOSZ/R/util.affinity.R
pkg/CHNOSZ/vignettes/anintro.Rmd
Log:
anintro.Rmd: fix to energy() for mosaic diagram with chalcocite (phase transitions)
Modified: pkg/CHNOSZ/DESCRIPTION
===================================================================
--- pkg/CHNOSZ/DESCRIPTION 2019-02-02 11:54:46 UTC (rev 379)
+++ pkg/CHNOSZ/DESCRIPTION 2019-02-03 03:23:56 UTC (rev 380)
@@ -1,6 +1,6 @@
-Date: 2019-02-02
+Date: 2019-02-03
Package: CHNOSZ
-Version: 1.1.3-87
+Version: 1.1.3-88
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/util.affinity.R
===================================================================
--- pkg/CHNOSZ/R/util.affinity.R 2019-02-02 11:54:46 UTC (rev 379)
+++ pkg/CHNOSZ/R/util.affinity.R 2019-02-03 03:23:56 UTC (rev 380)
@@ -147,7 +147,13 @@
if("P" %in% vars) P <- vals[[which(vars=="P")]]
if("IS" %in% vars) IS <- vals[[which(vars=="IS")]]
s.args <- list(species=species,property=property,T=T,P=P,IS=IS,grid=grid,convert=FALSE,exceed.Ttr=exceed.Ttr,exceed.rhomin=exceed.rhomin)
- return(do.call("subcrt",s.args))
+ sout <- do.call("subcrt",s.args)
+ # species indices are updated by subcrt() for minerals with phase transitions
+ # e.g. i <- info("chalcocite"); subcrt(i, T=200)$species$ispecies == i + 1
+ # so we should keep the original species index to be able to find the species in a provided 'sout'
+ # (noted for Mosaic diagram section of anintro.Rmd 20190203)
+ sout$species$ispecies <- species
+ return(sout)
}
}
Modified: pkg/CHNOSZ/vignettes/anintro.Rmd
===================================================================
--- pkg/CHNOSZ/vignettes/anintro.Rmd 2019-02-02 11:54:46 UTC (rev 379)
+++ pkg/CHNOSZ/vignettes/anintro.Rmd 2019-02-03 03:23:56 UTC (rev 380)
@@ -687,22 +687,22 @@
The key argument is `bases`, which identifies the candidate basis species, starting with the one in the current basis.
The other arguments, like those of `affinity()`, specify the ranges of the variables; `res` indicates the grid resolution to use for each variable (the default is 128).
The first call to `diagram()` plots the species of interest; the second adds the predominance fields of the basis species.
-We turn off the gray coloring beyond the water stability limits (`limit.water`) but plot the red dotted lines using `water.lines()`:
+We turn off the gray coloring beyond the water stability limits (`limit.water`) but plot dashed blue lines using `water.lines()`:
```{r copper_mosaic, fig.margin=TRUE, fig.width=4, fig.height=4, dpi=dpi, out.width="100%", message=FALSE, cache=TRUE, fig.cap="Copper minerals and aqueous complexes with chloride, 200 ?C.", pngquant=pngquant, timeit=timeit}
T <- 200
res <- 300
bases <- c("H2S", "HS-", "HSO4-", "SO4-2")
-m1 <- mosaic(bases, blend = TRUE, pH = c(0, 12, res), Eh=c(-1.2, 0.75, res), T=T)
+m1 <- mosaic(bases, pH = c(0, 12, res), Eh=c(-1.2, 0.75, res), T=T)
diagram(m1$A.species, lwd = 2, fill = NA, limit.water = FALSE)
diagram(m1$A.bases, add = TRUE, col = "red1", col.names = "red1", lty = 3,
limit.water = FALSE, italic = TRUE)
water.lines(m1$A.species, col = "blue1")
```
-The argument `blend = TRUE` is used to combine the diagrams according to the relative abundances of the basis species along with a mixing term (see `?mosaic`).
+The diagrams are combined according to the relative abundances of the different possible basis species listed in `bases` along with a term for the Gibbs energy of mixing (see `?mosaic`).
The smooth transitions between basis species can result in curved field boundaries, in this case around the chalcocite field.
-Without that argument, the diagrams would be combined using the dominant basis species, and all of the line segments would be straight.
+If we added the argument `blend = FALSE`, the diagrams would instead be assembled using the single predominant basis species at any point on the Eh-pH grid, and all of the line segments would be straight.
The reactions used to make this diagram are balanced on Cu, so that no Cu appears in reactions between any two other species (minerals or aqueous species).
If `diagram()` is run with `balance = 1`, then the reactions are written for one mole of the mineral formulas on each side of the reaction, with the possibility of Cu appearing as an additional species to conserve the elements.
@@ -720,7 +720,7 @@
mosaicfun <- function(newvar, T = 200) {
swap.basis("e-", names(newvar))
if (names(newvar) == "O2") basis("O2", "gas")
- mosaicargs <- c(list(bases), blend=TRUE, pH=list(c(-2, 12, res)), newvar, T=T)
+ mosaicargs <- c(list(bases), pH = list(c(-2, 12, res)), newvar, T = T)
m1 <- do.call(mosaic, mosaicargs)
diagram(m1$A.species, lwd = 2, fill = "terrain",
limit.water = FALSE)
From noreply at r-forge.r-project.org Wed Feb 6 07:35:10 2019
From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org)
Date: Wed, 6 Feb 2019 07:35:10 +0100 (CET)
Subject: [CHNOSZ-commits] r381 - in pkg/CHNOSZ: . data inst
inst/extdata/OBIGT inst/extdata/thermo man man/macros tests/testthat
Message-ID: <20190206063510.70D8418BD6B@r-forge.r-project.org>
Author: jedick
Date: 2019-02-06 07:35:06 +0100 (Wed, 06 Feb 2019)
New Revision: 381
Added:
pkg/CHNOSZ/inst/extdata/thermo/SK95.csv
pkg/CHNOSZ/tests/testthat/test-recalculate.R
Modified:
pkg/CHNOSZ/DESCRIPTION
pkg/CHNOSZ/data/refs.csv
pkg/CHNOSZ/inst/NEWS
pkg/CHNOSZ/inst/extdata/OBIGT/organic_aq.csv.xz
pkg/CHNOSZ/man/extdata.Rd
pkg/CHNOSZ/man/macros/macros.Rd
Log:
add test of recalculated GHS of alanate and glycinate complexes
Modified: pkg/CHNOSZ/DESCRIPTION
===================================================================
--- pkg/CHNOSZ/DESCRIPTION 2019-02-03 03:23:56 UTC (rev 380)
+++ pkg/CHNOSZ/DESCRIPTION 2019-02-06 06:35:06 UTC (rev 381)
@@ -1,6 +1,6 @@
-Date: 2019-02-03
+Date: 2019-02-06
Package: CHNOSZ
-Version: 1.1.3-88
+Version: 1.1.3-89
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/data/refs.csv
===================================================================
--- pkg/CHNOSZ/data/refs.csv 2019-02-03 03:23:56 UTC (rev 380)
+++ pkg/CHNOSZ/data/refs.csv 2019-02-06 06:35:06 UTC (rev 381)
@@ -56,10 +56,11 @@
PK95,"V. B. Parker and I. L. Khodakovskii",1995,"J. Phys. Chem. Ref. Data 24, 1699-1745",melanterite,https://doi.org/10.1063/1.555964
RH95,"R. A. Robie and B. S. Hemingway",1995,"U. S. Geological Survey Bull. 2131","gypsum GHS",http://pubs.er.usgs.gov/publication/b2131
SK95,"E. L. Shock and C. M. Koretsky",1995,"Geochim. Cosmochim. Acta 59, 1497-1532","metal-organic acid complexes",https://doi.org/10.1016/0016-7037(95)00058-8
-SK95.1,"E. L. Shock and C. M. Koretsky",1995,"Geochim. Cosmochim. Acta 59, 1497-1532","alanate, glycinate and their complexes not included in later slop files.",https://doi.org/10.1016/0016-7037(95)00058-8
+SK95.1,"E. L. Shock and C. M. Koretsky",1995,"Geochim. Cosmochim. Acta 59, 1497-1532","alanate, glycinate and their complexes with metals. Values are taken from slop98.dat, which notes corrected values for some species.",https://doi.org/10.1016/0016-7037(95)00058-8
Sho95,"E. L. Shock",1995,"Am. J. Sci. 295, 496-580","carboxylic acids",https://doi.org/10.2475/ajs.295.5.496
DPS+96,"I. Diakonov, G. Pokrovski et al.",1996,"Geochim. Cosmochim. Acta 60, 197-211",NaAl(OH)4,http://dx.doi.org/10.1016/0016-7037(95)00403-3
AH97b,"J. P. Amend and H. C. Helgeson",1997,"J. Chem. Soc., Faraday Trans. 93, 1927-1941","amino acids GHS",https://doi.org/10.1039/A608126F
+AH97b.1,"J. P. Amend and H. C. Helgeson",1997,"J. Chem. Soc., Faraday Trans. 93, 1927-1941","alanate and glycinate GHS",https://doi.org/10.1039/A608126F
DSM+97,"J. D. Dale, E. L. Shock et al.",1997,"Geochim. Cosmochim. Acta 61, 4017-4024",alkylphenols,https://doi.org/10.1016/S0016-7037(97)00212-3
DSM+97.1,"J. D. Dale, E. L. Shock et al.",1997,"Geochim. Cosmochim. Acta 61, 4017-4024","phenol, and cresol isomers",https://doi.org/10.1016/S0016-7037(97)00212-3
DSM+97.2,"J. D. Dale, E. L. Shock et al.",1997,"Geochim. Cosmochim. Acta 61, 4017-4024","dimethylphenol isomers",https://doi.org/10.1016/S0016-7037(97)00212-3
@@ -162,8 +163,7 @@
ZZL+16.2,"K. Zimmer et al.",2016,"Comp. Geosci. 90, 97-111","Cp parameters listed in spronsbl.dat",https://doi.org/10.1016/j.cageo.2016.02.013
ZZL+16.3,"K. Zimmer et al.",2016,"Comp. Geosci. 90, 97-111","dawsonite GHS",https://doi.org/10.1016/j.cageo.2016.02.013
CHNOSZ.1,"J. M. Dick",2017,"CHNOSZ package documentation","GHS (Tr) of the phase that is stable at 298.15 K was combined with Htr and the Cp coefficients to calculate the metastable GHS (Tr) of the phases that are stable at higher temperatures.",http://chnosz.net
-CHNOSZ.2,"J. M. Dick",2017,"CHNOSZ package documentation","alanate and glycinate: GHS as used by @DLH06",http://chnosz.net
-CHNOSZ.3,"J. M. Dick",2017,"CHNOSZ package documentation","metal-amino acid complexes: GHS were recalculated by adding the differences between values from @AH97b and @DLH06 for alanate or glycinate to the properties of the complexes reported by @SK95.",http://chnosz.net
+CHNOSZ.3,"J. M. Dick",2017,"CHNOSZ package documentation","metal-amino acid complexes: GHS were recalculated by adding the differences between values from @SK95 and @AH97b for alanate or glycinate to the properties of the complexes reported by @SK95.",http://chnosz.net
CHNOSZ.5,"J. M. Dick",2017,"CHNOSZ package documentation","AuCl4- renamed to AuCl4-3",http://chnosz.net
CHNOSZ.6,"J. M. Dick",2017,"CHNOSZ package documentation","dipeptides not included in slop files after slop98.dat",http://chnosz.net
CHNOSZ.7,"J. M. Dick",2017,"CHNOSZ package documentation","charge of NpO2(Oxal), La(Succ)+, NH4(Succ)-, and NpO2(Succ) as listed by @PSK99",http://chnosz.net
Modified: pkg/CHNOSZ/inst/NEWS
===================================================================
--- pkg/CHNOSZ/inst/NEWS 2019-02-03 03:23:56 UTC (rev 380)
+++ pkg/CHNOSZ/inst/NEWS 2019-02-06 06:35:06 UTC (rev 381)
@@ -1,4 +1,4 @@
-CHANGES IN CHNOSZ 1.1.3-87 (2019-02-02)
+CHANGES IN CHNOSZ 1.1.3-89 (2019-02-06)
---------------------------------------
BUG FIXES
@@ -163,6 +163,9 @@
- Move SUPCRTBL updates into default database.
+- Add test-recalculate.R to check that some recalculated values are
+ correctly entered in OBIGT.
+
DIAGRAMS
- Lines in 1-D diagram()s can optionally be drawn as splines using the
Modified: pkg/CHNOSZ/inst/extdata/OBIGT/organic_aq.csv.xz
===================================================================
--- pkg/CHNOSZ/inst/extdata/OBIGT/organic_aq.csv.xz 2019-02-03 03:23:56 UTC (rev 380)
+++ pkg/CHNOSZ/inst/extdata/OBIGT/organic_aq.csv.xz 2019-02-06 06:35:06 UTC (rev 381)
@@ -1,4 +1,4 @@
-?7zXZ ???F ! t/????Pq?] 7I??b???9??????TB;q?"?q???cL;?"???b??g?;??K?????f??1?w?oz??C??a?]I????5i????????!A ??e?C;??M?'???~1??hJO?q=??{
+?7zXZ ???F ! t/????Nr] 7I??b???9??????TB;q?"?q???cL;?"???b??g?;??K?????f??1?w?oz??C??a?]I????5i????????!A ??e?C;??M?'???~1??hJO?q=??{
!S??l?J0?wo????V?)*+?F??~? p60p??
%????d??H4Z?????s?9???l??uA at +?m?G?]#?|An??cB??.*????i?6Y6??l???>? x!#???0N?????????V?q??P?@o?*?~??!?~?&??????x?{;? ?Q(T?{????~W??U?@??
r?&?3??f1(\F?^??=W?O?N ?????D?|???}?%?bi?????6?????N_[6????D *???????d?1*?|???QU?1?????u?P??/a?vT???????"J?.!f?????t
@@ -83,160 +83,150 @@
@xmd?(r??E?2??????Y???A?X?j2;\??H??R^Z??kg?yyv???????
Z<@??3e|?'.?????6?]c?2 Q??K??5???n???Y-x,???Mk?#k?