From noreply at r-forge.r-project.org Mon Dec 8 14:07:31 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 8 Dec 2014 14:07:31 +0100 (CET) Subject: [CHNOSZ-commits] r67 - in pkg/CHNOSZ: . R inst Message-ID: <20141208130731.19A43180599@r-forge.r-project.org> Author: jedick Date: 2014-12-08 14:07:30 +0100 (Mon, 08 Dec 2014) New Revision: 67 Modified: pkg/CHNOSZ/DESCRIPTION pkg/CHNOSZ/R/diagram.R pkg/CHNOSZ/inst/NEWS Log: diagram() returns 'lx', 'ly' and 'is' Modified: pkg/CHNOSZ/DESCRIPTION =================================================================== --- pkg/CHNOSZ/DESCRIPTION 2014-03-23 02:53:46 UTC (rev 66) +++ pkg/CHNOSZ/DESCRIPTION 2014-12-08 13:07:30 UTC (rev 67) @@ -1,6 +1,6 @@ -Date: 2014-03-23 +Date: 2014-11-20 Package: CHNOSZ -Version: 1.0.3-4 +Version: 1.0.3-5 Title: Chemical Thermodynamics and Activity Diagrams Author: Jeffrey Dick Maintainer: Jeffrey Dick Modified: pkg/CHNOSZ/R/diagram.R =================================================================== --- pkg/CHNOSZ/R/diagram.R 2014-03-23 02:53:46 UTC (rev 66) +++ pkg/CHNOSZ/R/diagram.R 2014-12-08 13:07:30 UTC (rev 67) @@ -189,6 +189,8 @@ } } + out2D <- list() + if(nd==0) { ### 0-D diagram - bar graph of properties of species or reactions @@ -345,7 +347,7 @@ } ## label plot function # calculate coordinates for field labels - plot.names <- function(out,xs,ys,names) { + plot.names <- function(out, xs, ys, names) { ll <- ngroups lx <- numeric(ll); ly <- numeric(ll); n <- numeric(ll) for(j in nrow(out):1) { @@ -367,7 +369,8 @@ # plot field labels # the cex argument in this function specifies the character # expansion of the labels relative to the current - text(lx,ly,labels=names[is],cex=cex.names,col=col.names[is]) + if(!is.null(names)) text(lx, ly, labels=names[is], cex=cex.names, col=col.names[is]) + return(list(lx=lx, ly=ly, is=which(is))) } ### done with predominance diagram functions @@ -407,13 +410,14 @@ # put predominance matrix in the right order for image() etc zs <- t(predominant[, ncol(predominant):1]) if(!is.null(fill)) fill.color(xs, ys, zs, fill, ngroups) - if(!is.null(names)) plot.names(zs, xs, ys, names) + pn <- plot.names(zs, xs, ys, names) if(!is.null(dotted)) plot.line(zs, xlim, ylim, dotted, col, lwd, xrange=xrange) } # done with the 2D plot! + out2D <- list(lx=pn$lx, ly=pn$ly, is=pn$is) } # end if(nd==2) } # end if(plot.it) - out <- c(eout, list(plotvar=plotvar, plotvals=plotvals, names=names, predominant=predominant)) + out <- c(eout, list(plotvar=plotvar, plotvals=plotvals, names=names, predominant=predominant), out2D) return(invisible(out)) } Modified: pkg/CHNOSZ/inst/NEWS =================================================================== --- pkg/CHNOSZ/inst/NEWS 2014-03-23 02:53:46 UTC (rev 66) +++ pkg/CHNOSZ/inst/NEWS 2014-12-08 13:07:30 UTC (rev 67) @@ -1,4 +1,4 @@ -CHANGES IN CHNOSZ 1.0.3-4 (2014-03-23) +CHANGES IN CHNOSZ 1.0.3-5 (2014-11-20) -------------------------------------- - Add files with average amino acid compositions of proteins from Bison @@ -11,6 +11,10 @@ - In energy(), add missing 'IS' argument in call to subcrt(). Thanks to Grayson Boyer for the bug report. +- diagram() returns 'lx', 'ly' and 'is' for calculated positions of + labels and indices of those species in predominance diagrams, + including when the labels aren't plotted (by setting names=FALSE). + CHANGES IN CHNOSZ 1.0.3 (2014-01-12) ------------------------------------ From noreply at r-forge.r-project.org Mon Dec 8 15:23:52 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 8 Dec 2014 15:23:52 +0100 (CET) Subject: [CHNOSZ-commits] r68 - in pkg/CHNOSZ: . R inst Message-ID: <20141208142352.88BDF187393@r-forge.r-project.org> Author: jedick Date: 2014-12-08 15:23:52 +0100 (Mon, 08 Dec 2014) New Revision: 68 Modified: pkg/CHNOSZ/DESCRIPTION pkg/CHNOSZ/R/diagram.R pkg/CHNOSZ/R/util.program.R pkg/CHNOSZ/R/wjd.R pkg/CHNOSZ/inst/NEWS Log: fixes for R CMD check Modified: pkg/CHNOSZ/DESCRIPTION =================================================================== --- pkg/CHNOSZ/DESCRIPTION 2014-12-08 13:07:30 UTC (rev 67) +++ pkg/CHNOSZ/DESCRIPTION 2014-12-08 14:23:52 UTC (rev 68) @@ -1,6 +1,6 @@ -Date: 2014-11-20 +Date: 2014-12-08 Package: CHNOSZ -Version: 1.0.3-5 +Version: 1.0.3-6 Title: Chemical Thermodynamics and Activity Diagrams Author: Jeffrey Dick Maintainer: Jeffrey Dick Modified: pkg/CHNOSZ/R/diagram.R =================================================================== --- pkg/CHNOSZ/R/diagram.R 2014-12-08 13:07:30 UTC (rev 67) +++ pkg/CHNOSZ/R/diagram.R 2014-12-08 14:23:52 UTC (rev 68) @@ -144,6 +144,9 @@ dim(predominant) <- dim(pv[[1]]) } + ## where we'll put extra output for predominance diagrams (lx, ly, is) + out2D <- list() + ### now on to the plotting ### if(plot.it) { @@ -189,8 +192,6 @@ } } - out2D <- list() - if(nd==0) { ### 0-D diagram - bar graph of properties of species or reactions @@ -406,6 +407,7 @@ zs <- plotvals[[1]] if(length(plotvals) > 1) warning("showing only first species in 2-D property diagram") contour(xs, ys, zs, add=TRUE, col=col, lty=lty, lwd=lwd, labcex=cex) + pn <- list(lx=NULL, ly=NULL, is=NULL) } else { # put predominance matrix in the right order for image() etc zs <- t(predominant[, ncol(predominant):1]) Modified: pkg/CHNOSZ/R/util.program.R =================================================================== --- pkg/CHNOSZ/R/util.program.R 2014-12-08 13:07:30 UTC (rev 67) +++ pkg/CHNOSZ/R/util.program.R 2014-12-08 14:23:52 UTC (rev 68) @@ -25,11 +25,11 @@ ## Use option mc.cores to choose an appropriate cluster size. # or detectCores if that is NULL, and set max at 2 for now # (to be nice to CRAN etc.) - nCores <- max(getOption("mc.cores", detectCores()), 2) + nCores <- max(getOption("mc.cores", parallel::detectCores()), 2) # don't load methods package, to save startup time - ?makeCluster - cl <- makeCluster(nCores, methods=FALSE) - out <- parLapply(cl, X, FUN, ...) - stopCluster(cl) + cl <- parallel::makeCluster(nCores, methods=FALSE) + out <- parallel::parLapply(cl, X, FUN, ...) + parallel::stopCluster(cl) } else out <- lapply(X, FUN, ...) return(out) } Modified: pkg/CHNOSZ/R/wjd.R =================================================================== --- pkg/CHNOSZ/R/wjd.R 2014-12-08 13:07:30 UTC (rev 67) +++ pkg/CHNOSZ/R/wjd.R 2014-12-08 14:23:52 UTC (rev 68) @@ -270,7 +270,7 @@ # minX is the minimum mole number we will accept H <- rep(minX, nrow(A)) # get a solution - X <- xranges(E=t(A), F=B, G=G, H=H, central=TRUE, full=TRUE)[, "central"] + X <- limSolve::xranges(E=t(A), F=B, G=G, H=H, central=TRUE, full=TRUE)[, "central"] return(X) } } Modified: pkg/CHNOSZ/inst/NEWS =================================================================== --- pkg/CHNOSZ/inst/NEWS 2014-12-08 13:07:30 UTC (rev 67) +++ pkg/CHNOSZ/inst/NEWS 2014-12-08 14:23:52 UTC (rev 68) @@ -1,4 +1,4 @@ -CHANGES IN CHNOSZ 1.0.3-5 (2014-11-20) +CHANGES IN CHNOSZ 1.0.3-6 (2014-12-08) -------------------------------------- - Add files with average amino acid compositions of proteins from Bison From noreply at r-forge.r-project.org Tue Dec 9 06:05:54 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 9 Dec 2014 06:05:54 +0100 (CET) Subject: [CHNOSZ-commits] r69 - in pkg/CHNOSZ: . R data inst inst/extdata/thermo man Message-ID: <20141209050554.D8020187879@r-forge.r-project.org> Author: jedick Date: 2014-12-09 06:05:51 +0100 (Tue, 09 Dec 2014) New Revision: 69 Modified: pkg/CHNOSZ/DESCRIPTION pkg/CHNOSZ/R/transfer.R pkg/CHNOSZ/data/OBIGT.csv pkg/CHNOSZ/inst/NEWS pkg/CHNOSZ/inst/extdata/thermo/OBIGT-2.csv pkg/CHNOSZ/man/CHNOSZ-package.Rd pkg/CHNOSZ/man/data.Rd pkg/CHNOSZ/man/transfer.Rd Log: move H4SiO4 to OBIGT-2.csv Modified: pkg/CHNOSZ/DESCRIPTION =================================================================== --- pkg/CHNOSZ/DESCRIPTION 2014-12-08 14:23:52 UTC (rev 68) +++ pkg/CHNOSZ/DESCRIPTION 2014-12-09 05:05:51 UTC (rev 69) @@ -1,6 +1,6 @@ -Date: 2014-12-08 +Date: 2014-12-09 Package: CHNOSZ -Version: 1.0.3-6 +Version: 1.0.3-7 Title: Chemical Thermodynamics and Activity Diagrams Author: Jeffrey Dick Maintainer: Jeffrey Dick Modified: pkg/CHNOSZ/R/transfer.R =================================================================== --- pkg/CHNOSZ/R/transfer.R 2014-12-08 14:23:52 UTC (rev 68) +++ pkg/CHNOSZ/R/transfer.R 2014-12-09 05:05:51 UTC (rev 69) @@ -807,7 +807,8 @@ # setup conditions for feldspar reaction #basis(c('Al+3','SiO2','K+','H2O','H+','O2')) basis(delete=TRUE) - # SLS89 use H4SiO4 instead of SiO2 + # SLS89 use H4SiO4 instead of SiO2 - use the secondary database + add.obigt() basis(c('Al+3','H4SiO4','K+','H2O','H+','O2')) # some of SLS89's initial conditions basis(c('K+','H4SiO4'),c(-6,-6)) Modified: pkg/CHNOSZ/data/OBIGT.csv =================================================================== --- pkg/CHNOSZ/data/OBIGT.csv 2014-12-08 14:23:52 UTC (rev 68) +++ pkg/CHNOSZ/data/OBIGT.csv 2014-12-09 05:05:51 UTC (rev 69) @@ -1768,8 +1768,6 @@ "dibutyl sulfide",NA,C8H18S,aq,Sch10,NA,03.Jul.10,13260,-51810,81.4,195,162.7,23.7393,57.9427,-33.671,-5.1744,177.4725,5.2072,-0.7624,0 "dipentyl sulfide",NA,C10H22S,aq,Sch10,NA,03.Jul.10,17360,-63150,94.8,238,194.3,28.0757,67.7711,-35.9048,-5.5807,213.8806,8.5956,-0.7302,0 "dihexyl sulfide",NA,C12H26S,aq,Sch10,NA,03.Jul.10,21460,-74490,108.2,280,225.9,32.412,77.5996,-38.1385,-5.987,249.442,11.9085,-0.698,0 -Ti(OH)4,NA,Ti(OH)4,aq,Ste01,NA,31.Aug.06,-313690.248565966,-361331.022944551,5.23900573613767,48.4942638623327,40.6,7.36687380497132,10.210086042065,1.15296367112811,-3.20100382409178,51.2762906309751,-1.27652963671128,0.01498565965583,0 -H4SiO4,NA,H4SiO4,aq,Ste01,NA,31.Aug.06,-312919.933078394,-348676.147227533,45.1003824091778,15.0095602294455,52.3,18.7299235181644,-21.2600382409178,18.6199808795411,-1.20004780114723,58.0305927342256,-20.789913957935,0.08690248565966,0 Br2,bromine,Br2,aq,WEP+82,NA,27.Apr.11,939.3,-619,31.19,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA I2,iodine,I2,aq,WEP+82,NA,27.Apr.11,3919.7,5401.5,32.79,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA 2-methylpropane,NA,C4H10,aq,CGM+81,NA,7.Aug.11,NA,NA,NA,-11.38,NA,NA,NA,NA,NA,NA,NA,NA,NA Modified: pkg/CHNOSZ/inst/NEWS =================================================================== --- pkg/CHNOSZ/inst/NEWS 2014-12-08 14:23:52 UTC (rev 68) +++ pkg/CHNOSZ/inst/NEWS 2014-12-09 05:05:51 UTC (rev 69) @@ -1,4 +1,4 @@ -CHANGES IN CHNOSZ 1.0.3-6 (2014-12-08) +CHANGES IN CHNOSZ 1.0.3-7 (2014-12-09) -------------------------------------- - Add files with average amino acid compositions of proteins from Bison @@ -15,6 +15,10 @@ labels and indices of those species in predominance diagrams, including when the labels aren't plotted (by setting names=FALSE). +- Move aqueous Ti(OH)4 and H4SiO4 to OBIGT-2.csv. + +- Add warning about data and examples to CHNOSZ-package.Rd. + CHANGES IN CHNOSZ 1.0.3 (2014-01-12) ------------------------------------ Modified: pkg/CHNOSZ/inst/extdata/thermo/OBIGT-2.csv =================================================================== --- pkg/CHNOSZ/inst/extdata/thermo/OBIGT-2.csv 2014-12-08 14:23:52 UTC (rev 68) +++ pkg/CHNOSZ/inst/extdata/thermo/OBIGT-2.csv 2014-12-09 05:05:51 UTC (rev 69) @@ -248,6 +248,8 @@ TmCl2+,NA,TmCl2+,aq,MWW09,NA,03.Jul.10,-223290,NA,-20.2,4.66,1.26,2.2586,-2.2666,6.6409,-2.6853,16.6521,-2.0854,0.85,1 YbCl2+,NA,YbCl2+,aq,MWW09,NA,03.Jul.10,-216360,NA,-19.22,-4.55,-0.6,1.9985,-2.9017,6.8906,-2.659,11.1191,-3.9614,0.8351,1 LuCl2+,NA,LuCl2+,aq,MWW09,NA,03.Jul.10,-222750,NA,-30.31,11.26,-1.23,1.9757,-2.9572,6.9124,-2.6567,21.9175,-0.7409,1.0031,1 +Ti(OH)4,NA,Ti(OH)4,aq,Ste01,NA,31.Aug.06,-313690.248565966,-361331.022944551,5.23900573613767,48.4942638623327,40.6,7.36687380497132,10.210086042065,1.15296367112811,-3.20100382409178,51.2762906309751,-1.27652963671128,0.0149856596558317,0 +H4SiO4,NA,H4SiO4,aq,Ste01,NA,31.Aug.06,-312919.933078394,-348676.147227533,45.1003824091778,15.0095602294455,52.3,18.7299235181644,-21.2600382409178,18.6199808795411,-1.20004780114723,58.0305927342256,-20.789913957935,0.0869024856596558,0 arsenolite,NA,As2O3,cr,PGS+96,NA,25.Aug.06,-137640,-156930,25.67,23.15,51.12,20.9,17.73,-2.7,0,0,0,0,548 claudetite,NA,As2O3,cr,PGS+96,NA,25.Aug.06,-137730,-156600,27.09,23.19,47.26,23.86,10.74,-3.44,0,0,0,0,588 orpiment,NA,As2S3,cr,PGS+96,NA,25.Aug.06,-20550,-20700,39.1,27.53,70.5,22.73,13.82,0.605,0,0,0,0,580 Modified: pkg/CHNOSZ/man/CHNOSZ-package.Rd =================================================================== --- pkg/CHNOSZ/man/CHNOSZ-package.Rd 2014-12-08 14:23:52 UTC (rev 68) +++ pkg/CHNOSZ/man/CHNOSZ-package.Rd 2014-12-09 05:05:51 UTC (rev 69) @@ -6,8 +6,21 @@ CHNOSZ is a package for thermodynamic calculations, primarily with applications in geochemistry and biochemistry. It can be used to calculate the standard molal thermodynamic properties and chemical affinities of reactions relevant to geobiochemical processes, and to visualize the equilibrium activities of species on chemical speciation and predominance diagrams. The package can be used interactively and in batch mode, through the use of R source files containing a sequence of commands. The major features of the package are outlined below, with links to specific help topics in this document, which constitutes the primary technical description of the package. If you are a new user, the \sQuote{anintro} vignette (An introduction to CHNOSZ) may offer a more comfortable way to get started with using the package. } -\details{ +\section{Warning}{ +All thermodynamic data and examples are provided on an as-is basis. +It is up to you to check not only the accuracy of the data, but also the \emph{suitability of the data for your problem}. +By combining data taken from different sources, it is possible to build an inconsistent and/or nonsensical calculation. +An attempt has been made to provide a primary database (OBIGT.csv) that is internally consistent, but no guarantee can be made. +Where possible, data with known or suspected inconsistencies have been placed into a secondary database (OBIGT-2.csv) that should be regarded as experimental. +If there is any doubt about the accuracy or suitability of data for a particular problem, PLEASE consult the primary sources (see \code{\link{browse.refs}}). +Do not assume that by adding any species to your calculation (or to any of the examples), you will necessarily obtain a reasonable answer. +Do not assume that the examples are correct, either by themselves, or for your problem. +As with the data, PLEASE compare the construction and output of the examples to the primary sources, cited in the help page reference list. +Examples without a reference (and some with references) demonstrate experimental features of CHNOSZ. +} +\section{Overview}{ + Major features in CHNOSZ: \itemize{ Modified: pkg/CHNOSZ/man/data.Rd =================================================================== --- pkg/CHNOSZ/man/data.Rd 2014-12-08 14:23:52 UTC (rev 68) +++ pkg/CHNOSZ/man/data.Rd 2014-12-09 05:05:51 UTC (rev 69) @@ -10,6 +10,8 @@ \alias{buffers} \title{Thermodynamic Database and System Definition} \description{ + + Please read the important Warning at \code{\link{CHNOSZ-package}}. The core data files provided with CHNOSZ are in the \code{data} directory of the package. These \code{*.csv} files are used to build the \code{thermo} data object on loading the package. Additional (extra) data files, supporting the examples and vignettes, are documented separately at \code{\link{extdata}}. Modified: pkg/CHNOSZ/man/transfer.Rd =================================================================== --- pkg/CHNOSZ/man/transfer.Rd 2014-12-08 14:23:52 UTC (rev 68) +++ pkg/CHNOSZ/man/transfer.Rd 2014-12-09 05:05:51 UTC (rev 69) @@ -59,6 +59,10 @@ } +\section{Warning}{ + \code{feldspar} loads the secondary database (using \code{\link{add.obigt}}); after using this function use \code{data(thermo)} to restore the primary database. +} + \value{ \code{transfer} returns a list containing information about the conditions at each step: \code{basis}, data frame of the logarithms of activities of basis species, \code{species}, data frame of the logarithms of activities (moles for solids) of species, \code{alphas}, numeric vector of the values of the destruction exponent, \code{dmodes}, character vector of the destruction mode, \code{istables}, numeric vector of the index of the most stable product, \code{myaffs}, list of the affinities of the formation reactions of species, \code{didwork}, logical vector indicating whether the steps succeeded or failed. } @@ -67,6 +71,8 @@ \examples{\dontshow{data(thermo)} \donttest{## react potassium feldspar in a closed system ## after Steinmann et al., 1994 and Helgeson et al., 1969 +# load the secondary database to use H4SiO4 +add.obigt() basis(c("Al+3", "H4SiO4", "K+", "H2O", "H+", "O2"), c(0, -6, -6, 0, 0, 0)) species(c("k-feldspar", "muscovite", "pyrophyllite", "kaolinite", "gibbsite")) a <- affinity(H4SiO4=c(-6, -2), "K+"=c(-3, 8)) @@ -78,6 +84,8 @@ draw.transfer(tr) # reset the plot layout layout(matrix(1)) +# restore the primary database +data(thermo) ## can also run the calculation above with #feldspar("closed") From noreply at r-forge.r-project.org Thu Dec 11 07:16:03 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Thu, 11 Dec 2014 07:16:03 +0100 (CET) Subject: [CHNOSZ-commits] r70 - in pkg/CHNOSZ: . R inst inst/tests man Message-ID: <20141211061603.CCC411875C8@r-forge.r-project.org> Author: jedick Date: 2014-12-11 07:16:03 +0100 (Thu, 11 Dec 2014) New Revision: 70 Modified: pkg/CHNOSZ/DESCRIPTION pkg/CHNOSZ/R/util.affinity.R pkg/CHNOSZ/R/util.misc.R pkg/CHNOSZ/inst/NEWS pkg/CHNOSZ/inst/tests/test-affinity.R pkg/CHNOSZ/man/CHNOSZ-package.Rd pkg/CHNOSZ/man/util.misc.Rd Log: skip H+ and e- in nonideal(), and add a test for constant and variable IS to test-util.affinity.R Modified: pkg/CHNOSZ/DESCRIPTION =================================================================== --- pkg/CHNOSZ/DESCRIPTION 2014-12-09 05:05:51 UTC (rev 69) +++ pkg/CHNOSZ/DESCRIPTION 2014-12-11 06:16:03 UTC (rev 70) @@ -1,6 +1,6 @@ -Date: 2014-12-09 +Date: 2014-12-11 Package: CHNOSZ -Version: 1.0.3-7 +Version: 1.0.3-8 Title: Chemical Thermodynamics and Activity Diagrams Author: Jeffrey Dick Maintainer: Jeffrey Dick Modified: pkg/CHNOSZ/R/util.affinity.R =================================================================== --- pkg/CHNOSZ/R/util.affinity.R 2014-12-09 05:05:51 UTC (rev 69) +++ pkg/CHNOSZ/R/util.affinity.R 2014-12-11 06:16:03 UTC (rev 70) @@ -119,19 +119,9 @@ 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")]] s.args <- list(species=species,property=property,T=T,P=P,IS=IS,grid=grid,convert=FALSE,exceed.Ttr=exceed.Ttr) - if("IS" %in% vars) { - IS <- vals[[which(vars=="IS")]] - # do the calculation in parts: basis species (IS=0) - s.args$species <- mybasis$ispecies - s.out.basis <- do.call("subcrt",s.args)$out - # and species of interest (IS=IS) - s.args$species <- myspecies$ispecies - s.args <- c(s.args,list(IS=IS)) - s.out.species <- do.call("subcrt",s.args)$out - # put them together - return(c(s.out.basis,s.out.species)) - } else return(do.call("subcrt",s.args)$out) + return(do.call("subcrt",s.args)$out) } } Modified: pkg/CHNOSZ/R/util.misc.R =================================================================== --- pkg/CHNOSZ/R/util.misc.R 2014-12-09 05:05:51 UTC (rev 69) +++ pkg/CHNOSZ/R/util.misc.R 2014-12-11 06:16:03 UTC (rev 70) @@ -68,8 +68,8 @@ Z <- mkp[grep("Z", names(mkp))] # don't do anything for neutral species if(Z==0) next - # this would keep unit activity coefficient of the proton and electron - #if(species[i] %in% c(info('H+',quiet=TRUE),info('e-',quiet=TRUE))) next + # this keeps unit activity coefficient of the proton and electron + if(species[i] %in% c(info("H+"), info("e-"))) next didit <- FALSE for(j in 1:ncol(myprops)) { #if(colnames(myprops)[j]=='G') myprops[,j] <- myprops[,j] + thermo$opt$R * T * mlg(Z,IS,convert(T,'C')) Modified: pkg/CHNOSZ/inst/NEWS =================================================================== --- pkg/CHNOSZ/inst/NEWS 2014-12-09 05:05:51 UTC (rev 69) +++ pkg/CHNOSZ/inst/NEWS 2014-12-11 06:16:03 UTC (rev 70) @@ -1,4 +1,4 @@ -CHANGES IN CHNOSZ 1.0.3-7 (2014-12-09) +CHANGES IN CHNOSZ 1.0.3-8 (2014-12-11) -------------------------------------- - Add files with average amino acid compositions of proteins from Bison @@ -11,6 +11,9 @@ - In energy(), add missing 'IS' argument in call to subcrt(). Thanks to Grayson Boyer for the bug report. +- In nonideal(), skip proton and electron. Add test for calculations + at constant and variable IS to test-util.affinity.R. + - diagram() returns 'lx', 'ly' and 'is' for calculated positions of labels and indices of those species in predominance diagrams, including when the labels aren't plotted (by setting names=FALSE). @@ -19,6 +22,7 @@ - Add warning about data and examples to CHNOSZ-package.Rd. + CHANGES IN CHNOSZ 1.0.3 (2014-01-12) ------------------------------------ Modified: pkg/CHNOSZ/inst/tests/test-affinity.R =================================================================== --- pkg/CHNOSZ/inst/tests/test-affinity.R 2014-12-09 05:05:51 UTC (rev 69) +++ pkg/CHNOSZ/inst/tests/test-affinity.R 2014-12-11 06:16:03 UTC (rev 70) @@ -144,3 +144,18 @@ a2 <- affinity(pH=c(6, 8, 3), T=c(0, 75, 4)) expect_equal(as.numeric(a1$values[[1]]), a2$values[[1]][, 2]) }) + +test_that("IS can be constant or variable", { + # inspired by an error from demo("phosphate") + # > a25 <- affinity(IS=c(0, 0.14), T=T[1]) + # ... + # Error in subcrt(species = c(1017L, 20L, 19L), property = "logK", T = 298.15, : + # formal argument "IS" matched by multiple actual arguments + basis("CHNOPS+") + species(c("PO4-3", "HPO4-2", "H2PO4-")) + a0 <- affinity() + a1 <- affinity(IS=0.14) + a2 <- affinity(IS=c(0, 0.14)) + expect_equal(unlist(lapply(a2$values, head, 1)), unlist(a0$values)) + expect_equal(unlist(lapply(a2$values, tail, 1)), unlist(a1$values)) +}) Modified: pkg/CHNOSZ/man/CHNOSZ-package.Rd =================================================================== --- pkg/CHNOSZ/man/CHNOSZ-package.Rd 2014-12-09 05:05:51 UTC (rev 69) +++ pkg/CHNOSZ/man/CHNOSZ-package.Rd 2014-12-11 06:16:03 UTC (rev 70) @@ -8,14 +8,14 @@ \section{Warning}{ All thermodynamic data and examples are provided on an as-is basis. -It is up to you to check not only the accuracy of the data, but also the \emph{suitability of the data for your problem}. +It is up to you to check not only the accuracy of the data, but also the \emph{suitability of the data AND computational techniques} for your problem. By combining data taken from different sources, it is possible to build an inconsistent and/or nonsensical calculation. An attempt has been made to provide a primary database (OBIGT.csv) that is internally consistent, but no guarantee can be made. Where possible, data with known or suspected inconsistencies have been placed into a secondary database (OBIGT-2.csv) that should be regarded as experimental. If there is any doubt about the accuracy or suitability of data for a particular problem, PLEASE consult the primary sources (see \code{\link{browse.refs}}). Do not assume that by adding any species to your calculation (or to any of the examples), you will necessarily obtain a reasonable answer. -Do not assume that the examples are correct, either by themselves, or for your problem. -As with the data, PLEASE compare the construction and output of the examples to the primary sources, cited in the help page reference list. +Do not assume that the examples are correct, or that they can be applied to your problem. +As with the data, PLEASE compare the construction and output of the examples to the primary sources, cited in the reference list in each help page. Examples without a reference (and some with references) demonstrate experimental features of CHNOSZ. } Modified: pkg/CHNOSZ/man/util.misc.Rd =================================================================== --- pkg/CHNOSZ/man/util.misc.Rd 2014-12-09 05:05:51 UTC (rev 69) +++ pkg/CHNOSZ/man/util.misc.Rd 2014-12-11 06:16:03 UTC (rev 70) @@ -37,7 +37,12 @@ \code{dPdTtr} returns values of \eqn{(dP/dT)_{Ttr}}{(dP/dT)Ttr}, where \eqn{Ttr}{Ttr} represents the transition temperature, of the phase transition at the high-\eqn{T}{T} stability limit of the \code{x}th species in \code{thermo$obigt} (no checking is done to verify that the species represents in fact one phase of a mineral with phase transitions). \code{dPdTtr} takes account of the Clapeyron equation, \eqn{(dP/dT)_{Ttr}}{(dP/dT)Ttr}=\eqn{{\Delta}S/{\Delta}V}{DS/DV}, where \eqn{{\Delta}S}{DS} and \eqn{{\Delta}V}{DV} represent the changes in entropy and volume of phase transition, and are calculated using \code{subcrt} at Ttr from the standard molal entropies and volumes of the two phases involved. Using values of \code{dPdT} calculated using \code{dPdTtr} or supplied in the arguments, \code{Ttr} returns as a function of \code{P} values of the upper transition temperature of the mineral phase represented by the \code{x}th species. - \code{nonideal} takes a list of dataframes (in \code{proptable}) containing the standard molal properties of the identified \code{species}. For those species whose charge (determined by the number of Z in their \code{\link{makeup}}) is not equal to zero, the values of \code{IS} are combined with Alberty's (2003) equation 3.6-1 (Debye-Huckel equation) and its derivatives, to calculate apparent molal properties at the specified ionic strength(s) and temperature(s). The lengths of \code{IS} and \code{T} supplied in the arguments should be equal to the number of rows of each dataframe in \code{proptable}, or one to use single values throughout. The apparent molal properties that can be calculated include \code{G}, \code{H}, \code{S} and \code{Cp}; any columns in the dataframes of \code{proptable} with other names are left untouched. A column named \code{loggam} (logarithm of gamma, the activity coefficient) is appended to the output dataframe of species properties. +\code{nonideal} takes a list of dataframes (in \code{proptable}) containing the standard molal properties of the identified \code{species}. +The function bypasses (leaves unchanged) properties of the proton (H+), electron (e-), and all species whose charge (determined by the number of Z in their \code{\link{makeup}}) is equal to zero. +The values of \code{IS} are combined with Alberty's (2003) equation 3.6-1 (Debye-Huckel equation) and its derivatives, to calculate apparent molal properties at the specified ionic strength(s) and temperature(s). +The lengths of \code{IS} and \code{T} supplied in the arguments should be equal to the number of rows of each dataframe in \code{proptable}, or one to use single values throughout. +The apparent molal properties that can be calculated include \code{G}, \code{H}, \code{S} and \code{Cp}; any columns in the dataframes of \code{proptable} with other names are left untouched. +A column named \code{loggam} (logarithm of gamma, the activity coefficient) is appended to the output dataframe of species properties. \code{which.balance} returns, in order, which column(s) of \code{species} all have non-zero values. It is used by \code{\link{diagram}} and \code{\link{transfer}} to determine a conservant (i.e. basis species that are conserved in transformation reactions) if none is supplied by the user. From noreply at r-forge.r-project.org Mon Dec 15 09:45:44 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 15 Dec 2014 09:45:44 +0100 (CET) Subject: [CHNOSZ-commits] r71 - in pkg/CHNOSZ: . R inst man Message-ID: <20141215084544.BE8591844A4@r-forge.r-project.org> Author: jedick Date: 2014-12-15 09:45:44 +0100 (Mon, 15 Dec 2014) New Revision: 71 Modified: pkg/CHNOSZ/DESCRIPTION pkg/CHNOSZ/R/util.plot.R pkg/CHNOSZ/inst/NEWS pkg/CHNOSZ/man/util.plot.Rd Log: water.lines() gets 'O2state' argument for state of O2 Modified: pkg/CHNOSZ/DESCRIPTION =================================================================== --- pkg/CHNOSZ/DESCRIPTION 2014-12-11 06:16:03 UTC (rev 70) +++ pkg/CHNOSZ/DESCRIPTION 2014-12-15 08:45:44 UTC (rev 71) @@ -1,6 +1,6 @@ -Date: 2014-12-11 +Date: 2014-12-15 Package: CHNOSZ -Version: 1.0.3-8 +Version: 1.0.3-9 Title: Chemical Thermodynamics and Activity Diagrams Author: Jeffrey Dick Maintainer: Jeffrey Dick Modified: pkg/CHNOSZ/R/util.plot.R =================================================================== --- pkg/CHNOSZ/R/util.plot.R 2014-12-11 06:16:03 UTC (rev 70) +++ pkg/CHNOSZ/R/util.plot.R 2014-12-15 08:45:44 UTC (rev 71) @@ -113,7 +113,8 @@ } -water.lines <- function(xaxis='pH',yaxis='Eh',T=298.15,P='Psat',which=c('oxidation','reduction'),logaH2O=0,lty=2,col=par('fg'),xpoints=NULL) { +water.lines <- function(xaxis='pH', yaxis='Eh', T=298.15, P='Psat', which=c('oxidation','reduction'), + logaH2O=0, lty=2, lwd=1, col=par('fg'), xpoints=NULL, O2state="gas") { # draw water stability limits # if we're on an Eh-pH diagram, or logfO2-pH diagram, # or logfO2-T or Eh-T @@ -129,17 +130,21 @@ if(xaxis=='pH' & (yaxis=='Eh' | yaxis=='O2' | yaxis=="pe")) { if('reduction' %in% which) { logfH2 <- 0 - logK <- subcrt(c('H2O','oxygen','hydrogen'),c(-1,0.5,1),T=T,P=P,convert=FALSE)$out$logK + logK <- subcrt(c("H2O", "O2", "H2"), c(-1, 0.5, 1), c("liq", O2state, "gas"), T=T, P=P, convert=FALSE)$out$logK + # this is logfO2 if O2state=="gas", or logaO2 if O2state=="aq" logfO2 <- 2 * logK - logfH2 + 2 * logaH2O - if(yaxis=='O2') abline(h=logfO2,lty=lty,col=col) - else if(yaxis=="Eh") lines(xlim,convert(logfO2,'E0',T=T,P=P,pH=xlim),lty=lty,col=col) - else if(yaxis=="pe") lines(xlim,convert(convert(logfO2,'E0',T=T,P=P,pH=xlim),"pe",T=T),lty=lty,col=col) + if(yaxis=='O2') abline(h=logfO2,lty=lty,lwd=lwd,col=col) + else if(yaxis=="Eh") lines(xlim,convert(logfO2,'E0',T=T,P=P,pH=xlim),lty=lty,lwd=lwd,col=col) + else if(yaxis=="pe") lines(xlim,convert(convert(logfO2,'E0',T=T,P=P,pH=xlim),"pe",T=T),lty=lty,lwd=lwd,col=col) } if('oxidation' %in% which) { logfO2 <- 0 - if(yaxis=='O2') abline(h=logfO2,lty=lty,col=col) - else if(yaxis=="Eh") lines(xlim,convert(logfO2,'E0',T=T,P=P,pH=xlim),lty=lty,col=col) - else if(yaxis=="pe") lines(xlim,convert(convert(logfO2,'E0',T=T,P=P,pH=xlim),"pe",T=T),lty=lty,col=col) + logK <- subcrt(c("O2", "O2"), c(-1, 1), c("gas", O2state), T=T, P=P, convert=FALSE)$out$logK + # this is logfO2 if O2state=="gas", or logaO2 if O2state=="aq" + logfO2 <- logfO2 + logK + if(yaxis=='O2') abline(h=logfO2,lty=lty,lwd=lwd,col=col) + else if(yaxis=="Eh") lines(xlim,convert(logfO2,'E0',T=T,P=P,pH=xlim),lty=lty,lwd=lwd,col=col) + else if(yaxis=="pe") lines(xlim,convert(convert(logfO2,'E0',T=T,P=P,pH=xlim),"pe",T=T),lty=lty,lwd=lwd,col=col) } } else if(xaxis %in% c('T','P') & yaxis %in% c('Eh','O2') ) { #if(xaxis=='T') if(is.null(xpoints)) xpoints <- T @@ -154,15 +159,15 @@ if(xaxis=='P') if(is.null(xpoints)) xpoints <- P if('oxidation' %in% which) { logfO2 <- rep(0,length(xpoints)) - if(yaxis=='Eh') lines(xpoints,convert(logfO2,'E0',T=T,P=P,pH=xlim),lty=lty,col=col) - else lines(xpoints,logfO2,lty=lty,col=col) + if(yaxis=='Eh') lines(xpoints,convert(logfO2,'E0',T=T,P=P,pH=xlim),lty=lty,lwd=lwd,col=col) + else lines(xpoints,logfO2,lty=lty,lwd=lwd,col=col) } if('reduction' %in% which) { logfH2 <- 0 logK <- subcrt(c('H2O','oxygen','hydrogen'),c(-1,0.5,1),T=T,P=P,convert=FALSE)$out$logK logfO2 <- 2 * logK - logfH2 + 2 * logaH2O - if(yaxis=='Eh') lines(xpoints,convert(logfO2,'E0',T=T,P=P,pH=xlim),lty=lty,col=col) - else lines(xpoints,logfO2,lty=lty,col=col) + if(yaxis=='Eh') lines(xpoints,convert(logfO2,'E0',T=T,P=P,pH=xlim),lty=lty,lwd=lwd,col=col) + else lines(xpoints,logfO2,lty=lty,lwd=lwd,col=col) } } else { # inexact lines Modified: pkg/CHNOSZ/inst/NEWS =================================================================== --- pkg/CHNOSZ/inst/NEWS 2014-12-11 06:16:03 UTC (rev 70) +++ pkg/CHNOSZ/inst/NEWS 2014-12-15 08:45:44 UTC (rev 71) @@ -1,4 +1,4 @@ -CHANGES IN CHNOSZ 1.0.3-8 (2014-12-11) +CHANGES IN CHNOSZ 1.0.3-9 (2014-12-15) -------------------------------------- - Add files with average amino acid compositions of proteins from Bison @@ -22,6 +22,7 @@ - Add warning about data and examples to CHNOSZ-package.Rd. +- water.lines() gets 'O2state' argument for state of O2. CHANGES IN CHNOSZ 1.0.3 (2014-01-12) ------------------------------------ Modified: pkg/CHNOSZ/man/util.plot.Rd =================================================================== --- pkg/CHNOSZ/man/util.plot.Rd 2014-12-11 06:16:03 UTC (rev 70) +++ pkg/CHNOSZ/man/util.plot.Rd 2014-12-15 08:45:44 UTC (rev 71) @@ -24,8 +24,8 @@ label.plot(x, xfrac = 0.95, yfrac = 0.9, cex = 1, paren = TRUE, adj = 1) water.lines(xaxis = "pH", yaxis = "Eh", T = 298.15, P = "Psat", - which = c("oxidation","reduction"), logaH2O = 0, lty = 2, - col = par("fg"), xpoints = NULL) + which = c("oxidation","reduction"), logaH2O = 0, lty = 2, lwd=1, + col = par("fg"), xpoints = NULL, O2state="gas") mtitle(main, ...) residualsplot(residuals, property = "Cp", model = "big") } @@ -63,6 +63,7 @@ \item{logaH2O}{numeric, logarithm of the activity of \eqn{\mathrm{H_2O}}{H2O}} \item{lty}{numeric, line type} \item{xpoints}{numeric, points to plot on \eqn{x}{x} axis} + \item{O2state}{character, state of O2} \item{main}{character, text for plot title} \item{...}{further arguments passed to \code{mtext}} \item{residuals}{numeric, named vector of residuals to plot} @@ -74,7 +75,12 @@ \code{thermo.plot.new} sets parameters for a new plot, creates a new plot using \code{\link{plot.new}}, and adds axes and major and minor ticks to the plot. Plot parameters (see \code{\link{par}}) including \code{cex}, \code{mar}, \code{lwd}, \code{mgp} and \code{axs} can be given, as well as a numeric vector in \code{ticks} identifying which sides of the plot receive tick marks. \code{yline}, if present, denotes the margin line (default \code{\link{par}('mgp')[1]}) where the y-axis name is plotted. The very first time \code{thermo.plot.new} is called, it stores the existing value of \code{par(no.readonly=TRUE)} in \code{thermo$opar} so that the plot device can be reset to the previous state later on. - \code{water.lines} plots lines representing the oxidation and reduction stability limits of water on \code{yaxis}-\code{xaxis} diagrams, where \code{yaxis} can be \samp{Eh} or \samp{O2}, and \code{xaxis} can be \samp{pH} or \samp{T}. \code{which} controls which lines (\samp{oxidation}, \samp{reduction}, or both (the default)) are drawn, \code{logaH2O} (default 0) denotes the logarithm of the activity of water, \code{lty} (default 2) the line type, \code{col} (default \code{\link{par}('fg')}, the foreground color), and \code{xpoints} an optional list of points on the x axis to which to restrict the plotting (default of \code{NULL} refers to the axis limits). +\code{water.lines} plots lines representing the oxidation and reduction stability limits of water on \code{yaxis}-\code{xaxis} diagrams, where \code{yaxis} can be \samp{Eh} or \samp{O2}, and \code{xaxis} can be \samp{pH} or \samp{T}. +\code{which} controls which lines are drawn (\samp{oxidation}, \samp{reduction}, or both (the default)). +\code{logaH2O} denotes the logarithm of the activity of water. +With \code{O2state} set to \samp{gas} (the default), the logarithm of oxygen fugacity is plotted. +Change this to \samp{aq} to plot the logarithm of oxygen activity (do not change it if plotting \samp{Eh}). +\code{xpoints} is an optional list of points on the x axis to which to restrict the plotting (default of \code{NULL} refers to the axis limits). \code{label.plot} adds identifying text to the plot; the value given for \code{x} is made into a label like \eqn{(a)}{(a)}. The location of the label is controlled by \code{xfrac} and \code{yfrac} (the fractional locations along the respective axes) as well as \code{adj} (the text alignment parameter, see \code{\link{text}}). From noreply at r-forge.r-project.org Sat Dec 20 08:36:08 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sat, 20 Dec 2014 08:36:08 +0100 (CET) Subject: [CHNOSZ-commits] r72 - in pkg/CHNOSZ: . R inst man Message-ID: <20141220073609.0AA9D18681D@r-forge.r-project.org> Author: jedick Date: 2014-12-20 08:36:08 +0100 (Sat, 20 Dec 2014) New Revision: 72 Added: pkg/CHNOSZ/R/mosaic.R pkg/CHNOSZ/man/mosaic.Rd Modified: pkg/CHNOSZ/DESCRIPTION pkg/CHNOSZ/R/affinity.R pkg/CHNOSZ/inst/NEWS pkg/CHNOSZ/man/affinity.Rd Log: add mosaic() for affinity calculations with changing basis species Modified: pkg/CHNOSZ/DESCRIPTION =================================================================== --- pkg/CHNOSZ/DESCRIPTION 2014-12-15 08:45:44 UTC (rev 71) +++ pkg/CHNOSZ/DESCRIPTION 2014-12-20 07:36:08 UTC (rev 72) @@ -1,6 +1,6 @@ -Date: 2014-12-15 +Date: 2014-12-20 Package: CHNOSZ -Version: 1.0.3-9 +Version: 1.0.3-10 Title: Chemical Thermodynamics and Activity Diagrams Author: Jeffrey Dick Maintainer: Jeffrey Dick Modified: pkg/CHNOSZ/R/affinity.R =================================================================== --- pkg/CHNOSZ/R/affinity.R 2014-12-15 08:45:44 UTC (rev 71) +++ pkg/CHNOSZ/R/affinity.R 2014-12-20 07:36:08 UTC (rev 72) @@ -26,6 +26,11 @@ mybasis <- thermo$basis myspecies <- thermo$species + # stop if Eh or pe is requested but e- isn't in the basis + if(any(c("Eh", "pe") %in% names(args$lims))) { + if(!"e-" %in% rownames(mybasis)) stop("variable Eh or pe requested but e- isn't in the basis") + } + if(!is.null(property)) { # the user just wants an energy property buffer <- FALSE Added: pkg/CHNOSZ/R/mosaic.R =================================================================== --- pkg/CHNOSZ/R/mosaic.R (rev 0) +++ pkg/CHNOSZ/R/mosaic.R 2014-12-20 07:36:08 UTC (rev 72) @@ -0,0 +1,66 @@ +# CHNOSZ/mosaic.R +# calculate affinities with changing basis species +# 20141220 jmd + +# function to calculate affinities with mosaic of basis species +mosaic <- function(bases, blend=FALSE, ...) { + # the arguments for affinity() + myargs <- list(...) + # 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[match(bases[1], row.names(basis()))] + # a list where we'll keep the affinity calculations + affs <- list() + for(i in seq_along(bases)) { + # set up argument list: name of swapped-in basis species + if(!is.na(iswap)) names(myargs)[iswap] <- bases[i] + # calculate affinities + affs[[i]] <- do.call(affinity, myargs) + # change the basis species; restore the original at the end of the loop + if(i < length(bases)) { + swap.basis(bases[i], bases[i+1]) + basis(bases[i+1], logact.swap) + } else { + swap.basis(bases[i], bases[1]) + basis(bases[1], logact.swap) + names <- row.names(basis()) + } + } + # calculate affinities of formation of basis species + ispecies <- species()$ispecies + species.logact <- species()$logact + species(delete=TRUE) + species(bases) + A.basis <- do.call(affinity, myargs) + # restore original species with original activities + species(delete=TRUE) + species(ispecies, species.logact) + # affinities calculated using the first basis species + A.species <- affs[[1]] + if(blend) { + # calculate affinities using relative abundances of basis species + e <- equilibrate(A.basis) + 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 + A.species$values[[i]] <- A.species$values[[i]] + affs[[j]]$values[[i]] * 10^e$loga.equil[[j]] + } + } + } else { + # use affinities from the single predominant basis species + d <- diagram(A.basis, plot.it=FALSE) + # merge affinities using the second, third, ... basis species + for(j in tail(seq_along(affs), -1)) { + is.predominant <- d$predominant==j + for(i in seq_along(A.species$values)) { + A.species$values[[i]][is.predominant] <- affs[[j]]$values[[i]][is.predominant] + } + } + } + # return the affinities for the species and basis species + return(list(A.species=A.species, A.basis=A.basis)) +} Modified: pkg/CHNOSZ/inst/NEWS =================================================================== --- pkg/CHNOSZ/inst/NEWS 2014-12-15 08:45:44 UTC (rev 71) +++ pkg/CHNOSZ/inst/NEWS 2014-12-20 07:36:08 UTC (rev 72) @@ -1,5 +1,5 @@ -CHANGES IN CHNOSZ 1.0.3-9 (2014-12-15) --------------------------------------- +CHANGES IN CHNOSZ 1.0.3-10 (2014-12-20) +--------------------------------------- - Add files with average amino acid compositions of proteins from Bison Pool grouped according to annotation keyword (DS11.csv) (moved here @@ -24,6 +24,9 @@ - water.lines() gets 'O2state' argument for state of O2. +- Add mosaic() function for affinity calculations with changing basis + species. + CHANGES IN CHNOSZ 1.0.3 (2014-01-12) ------------------------------------ Modified: pkg/CHNOSZ/man/affinity.Rd =================================================================== --- pkg/CHNOSZ/man/affinity.Rd 2014-12-15 08:45:44 UTC (rev 71) +++ pkg/CHNOSZ/man/affinity.Rd 2014-12-20 07:36:08 UTC (rev 72) @@ -27,20 +27,31 @@ The calculation of chemical affinities relies on the current definitions of the \code{\link{basis}} species and \code{\link{species}} of interest. It is possible to use the results of \code{affinity} to generate equilibrium activity diagrams using \code{\link{diagram}}. - The equation used to calculate chemical affinity \emph{\bold{A}} is \emph{\bold{A}}=\eqn{RT\ln (K/Q)}{RT*ln(K/Q)} (Kondepudi and Prigogine, 1998), where \eqn{K} denotes the equilibrium constant of the reaction and \eqn{Q} stands for the activity product of the species in the reaction. (The equilibrium constant is related to standard Gibbs energy of reaction, \eqn{\Delta G^{\circ}_r}{DeltaG0r}, by \eqn{\Delta G^{\circ}_r = -2.303RT\log K}{DeltaG0r = -2.303*RT*logK}, where \eqn{R} and \eqn{T} stand for, respectively, the gas constant and temperature). With the approach of a given reaction to a state of equilibrium, the chemical affinity tends toward zero, or \eqn{K = Q}. +The equation used to calculate chemical affinity \emph{\bold{A}} is \emph{\bold{A}}=\eqn{RT\ln (K/Q)}{RT*ln(K/Q)} (Kondepudi and Prigogine, 1998), where \eqn{K} denotes the equilibrium constant of the reaction and \eqn{Q} stands for the activity product of the species in the reaction. +(The equilibrium constant is related to standard Gibbs energy of reaction, \eqn{\Delta G^{\circ}_r}{DeltaG0r}, by \eqn{\Delta G^{\circ}_r = -2.303RT\log K}{DeltaG0r = -2.303*RT*logK}, where \eqn{R} and \eqn{T} stand for, respectively, the gas constant and temperature). +With the approach of a given reaction to a state of equilibrium, the chemical affinity tends toward zero, or \eqn{K = Q}. - Valid properties are \samp{A} or NULL for chemical affinity, \samp{logK} or \samp{logQ} for logarithm of equilibrium constant and reaction activity product, or any of the properties available in \code{\link{subcrt}} except for \samp{rho}. The properties returned are those of the formation reactions of the species of interest from the basis species. It is also possible to calculate the properties of the species of interest themselves (not their formation reactions) by setting the \code{property} to \samp{G.species}, \samp{Cp.species}, etc. Except for \samp{A}, the properties of proteins or their reactions calculated in this manner are restricted to nonionized proteins. +Valid properties are \samp{A} or NULL for chemical affinity, \samp{logK} or \samp{logQ} for logarithm of equilibrium constant and reaction activity product, or any of the properties available in \code{\link{subcrt}} except for \samp{rho}. +The properties returned are those of the formation reactions of the species of interest from the basis species. +It is also possible to calculate the properties of the species of interest themselves (not their formation reactions) by setting the \code{property} to \samp{G.species}, \samp{Cp.species}, etc. +Except for \samp{A}, the properties of proteins or their reactions calculated in this manner are restricted to nonionized proteins. - Zero, one, or more leading arguments to the function identify which of the chemical activities of basis species, temperature, pressure and/or ionic strength to vary. The names of each of these arguments may be the formula of any of the basis species of the system, or \samp{T}, \samp{P}, \samp{pe}, \samp{pH}, \samp{Eh}, or \samp{IS} (but names may not be repeated). To use the names of charged basis species such as \samp{K+} and \samp{SO4-2} as the arguments, they should be enclosed in quotes (see the example for aluminum speciation in \code{\link{diagram}}). The value of each argument is of the form \code{c(min,max)} or \code{c(min,max,res)} where \code{min} and \code{max} refer to the minimimum and maximum values of variable identified by the name of the argument, and \code{res} denotes the resolution, or number of points along which to do the calculations (this is assigned a default value of 128 if it is missing). For any arguments that refer to basis species, the numerical values are the logarithms of the activities of that basis species, or logarithms of fugacities if it is a gas. Unlike the \code{energy} function, the units of \samp{T} and \samp{P} in \code{affinity} are those the user has set using \code{\link{T.units}} and \code{\link{P.units} }(on program start-up these are \eqn{^{\circ}}{?}C and bar, respectively). +Zero, one, or more leading arguments to the function identify which of the chemical activities of basis species, temperature, pressure and/or ionic strength to vary. +The names of each of these arguments may be the formula of any of the basis species of the system, or \samp{T}, \samp{P}, \samp{pe}, \samp{pH}, \samp{Eh}, or \samp{IS} (but names may not be repeated). +To use the names of charged basis species such as \samp{K+} and \samp{SO4-2} as the arguments, they should be enclosed in quotes (see the example for aluminum speciation in \code{\link{diagram}}). +The value of each argument is of the form \code{c(min,max)} or \code{c(min,max,res)} where \code{min} and \code{max} refer to the minimimum and maximum values of variable identified by the name of the argument, and \code{res} denotes the resolution, or number of points along which to do the calculations (this is assigned a default value of 128 if it is missing). +For any arguments that refer to basis species, the numerical values are the logarithms of the activities of that basis species, or logarithms of fugacities if it is a gas. +Unlike the \code{energy} function, the units of \samp{T} and \samp{P} in \code{affinity} are those the user has set using \code{\link{T.units}} and \code{\link{P.units} }(on program start-up these are \eqn{^{\circ}}{?}C and bar, respectively). - If one or more buffers are assigned to the definition of \code{\link{basis}} species, \code{affinity} calls \code{\link{buffer}} to calculate the logarithms of activities of these basis species from the buffer. +If one or more buffers are assigned to the definition of \code{\link{basis}} species, \code{affinity} calls \code{\link{buffer}} to calculate the logarithms of activities of these basis species from the buffer. The \code{iprotein} and \code{loga.protein} arguments can be used to compute the chemical affinities of formation reactions of proteins that are not in the current \code{\link{species}} definition. This approach can be utilized in order to calculate the properties of many proteins in a fraction of the time it would take to calculate them individually. The appropriate \code{\link{basis}} species still must be defined prior to calling \code{affinity}. \code{iprotein} contains indices of desired proteins in \code{\link{thermo}$protein}; \code{affinity} adds to the species list the amino acid residues and and terminal H2O group (indicated by \dQuote{RESIDUE} in \code{thermo$protein}) then calculates the properties of the reactions for the residues and terminal group, including ionization effects, and adds them together to get those of the indicated proteins. - In CHNOSZ version 0.9, \code{energy} gained a new argument \samp{transect} which is set to TRUE by \code{energy.args} when the length(s) of the variables is(are) greater than three. In this mode of operation, instead of performing the calculations on an \eqn{n}{n}-dimensional grid, the affinities are calculated on an \eqn{n}{n}-dimensional transect through chemical potential (possibly including T and/or P) space. +In CHNOSZ version 0.9, \code{energy} gained a new argument \samp{transect} which is set to TRUE by \code{energy.args} when the length(s) of the variables is(are) greater than three. +In this mode of operation, instead of performing the calculations on an \eqn{n}{n}-dimensional grid, the affinities are calculated on an \eqn{n}{n}-dimensional transect through chemical potential (possibly including T and/or P) space. } Added: pkg/CHNOSZ/man/mosaic.Rd =================================================================== --- pkg/CHNOSZ/man/mosaic.Rd (rev 0) +++ pkg/CHNOSZ/man/mosaic.Rd 2014-12-20 07:36:08 UTC (rev 72) @@ -0,0 +1,71 @@ +\encoding{UTF-8} +\name{mosaic} +\alias{mosaic} +\title{Chemical Affinities with Changing Basis Species} +\description{ +Calculate chemical affinities of formation reactions of species using basis species that change with the conditions. +} + +\usage{ + mosaic(bases, blend=FALSE, ...) +} + +\arguments{ + \item{bases}{character, basis species to include in the calculation} + \item{blend}{logical, use relative abundances of basis species?} + \item{...}{additional arguments to be passed to \code{\link{affinity}}} +} + +\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. +This is a way to \dQuote{speciate the basis species}. +An example is consideration of the speciation of sulfur (\samp{SO4-2}, \samp{HSO4-}, \samp{HS-} and \samp{H2S}) as a function of oxygen fugacity (or Eh) and pH in calculating the relative stabilities of minerals and aqueous species in the system Fe-S-O-H. +The first species listed in \code{bases} should correspond to one of the basis species currently defined, and the function only supports calculations using basis species that all derive from that species (i.e. all share the same element). +The arguments in \code{...} are passed to \code{affinity} to specify the conditions. + +The function calculates the affinities using each basis species in turn, changing them via \code{\link{swap.basis}}. +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. +Chemical activity or predominance diagrams constructed using this method have been described as \dQuote{mosaic diagrams} in the literature. +If \code{blend} is TRUE, the function combines the affinities of the formation reactions weighted by the relative abundances of the basis species at each condition. +This tends to produce curved boundaries. + +} + +\value{ +A list containing \code{A.species} (affinities of formation of the species with changing basis speceis) and \code{A.basis} (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}}. +} + +\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) +T <- 25 +basis(c("FeO", "SO4-2", "H2O", "H+", "e-")) +basis("SO4-2", -6) +species(c("Fe+2", "Fe+3"), -6) +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) +# make a diagram and add water stability lines +diagram(m1$A.species) +water.lines("pH", "Eh", T=convert(T, "K"), 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, dotted=3) +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 +#diagram(m1$A.basis, add=TRUE, col="blue", col.names="blue", dotted=3) +} + +\references{ + Garrels, R. M. and Christ, C. L. (1965) \emph{Solutions, Minerals, and Equilibria}, Harper & Row, New York, 450 p. \url{http://www.worldcat.org/oclc/517586} +} + +\keyword{secondary} From noreply at r-forge.r-project.org Sun Dec 21 08:31:43 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sun, 21 Dec 2014 08:31:43 +0100 (CET) Subject: [CHNOSZ-commits] r73 - in pkg/CHNOSZ: . R demo inst man Message-ID: <20141221073143.AD3FB18675F@r-forge.r-project.org> Author: jedick Date: 2014-12-21 08:31:42 +0100 (Sun, 21 Dec 2014) New Revision: 73 Added: pkg/CHNOSZ/demo/mosaic.R Modified: pkg/CHNOSZ/DESCRIPTION pkg/CHNOSZ/R/examples.R pkg/CHNOSZ/R/mosaic.R pkg/CHNOSZ/R/transfer.R pkg/CHNOSZ/demo/00Index pkg/CHNOSZ/inst/NEWS pkg/CHNOSZ/man/examples.Rd pkg/CHNOSZ/man/mosaic.Rd Log: add 'bases2' argument to mosaic() Modified: pkg/CHNOSZ/DESCRIPTION =================================================================== --- pkg/CHNOSZ/DESCRIPTION 2014-12-20 07:36:08 UTC (rev 72) +++ pkg/CHNOSZ/DESCRIPTION 2014-12-21 07:31:42 UTC (rev 73) @@ -1,6 +1,6 @@ -Date: 2014-12-20 +Date: 2014-12-21 Package: CHNOSZ -Version: 1.0.3-10 +Version: 1.0.3-11 Title: Chemical Thermodynamics and Activity Diagrams Author: Jeffrey Dick Maintainer: Jeffrey Dick Modified: pkg/CHNOSZ/R/examples.R =================================================================== --- pkg/CHNOSZ/R/examples.R 2014-12-20 07:36:08 UTC (rev 72) +++ pkg/CHNOSZ/R/examples.R 2014-12-21 07:31:42 UTC (rev 73) @@ -31,7 +31,7 @@ demos <- function(which=c("sources", "NaCl", "cordierite", "phosphate", "nucleobase", "orp", - "findit", "CO2Ac", "nonideal")) { + "findit", "CO2Ac", "nonideal", "TPX", "mosaic")) { # run one or more demos from CHNOSZ with ask=FALSE, and return the value of the last one for(i in 1:length(which)) { # say something so the user sees where we are Modified: pkg/CHNOSZ/R/mosaic.R =================================================================== --- pkg/CHNOSZ/R/mosaic.R 2014-12-20 07:36:08 UTC (rev 72) +++ pkg/CHNOSZ/R/mosaic.R 2014-12-21 07:31:42 UTC (rev 73) @@ -3,9 +3,16 @@ # 20141220 jmd # function to calculate affinities with mosaic of basis species -mosaic <- function(bases, blend=FALSE, ...) { - # the arguments for affinity() - myargs <- list(...) +mosaic <- function(bases, bases2=NULL, blend=FALSE, ...) { + 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, ...) + } # 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)) @@ -14,10 +21,17 @@ # a list where we'll keep the affinity calculations affs <- list() for(i in seq_along(bases)) { + msgout(paste("mosaic: current basis species is", bases[i], "\n", sep=" ")) # set up argument list: name of swapped-in basis species if(!is.na(iswap)) names(myargs)[iswap] <- bases[i] # calculate affinities - affs[[i]] <- do.call(affinity, myargs) + 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(i < length(bases)) { swap.basis(bases[i], bases[i+1]) @@ -29,11 +43,13 @@ } } # calculate affinities of formation of basis species + msgout(paste("mosaic: combining diagrams for", paste(bases, collapse=" "), "\n", sep=" ")) ispecies <- species()$ispecies species.logact <- species()$logact species(delete=TRUE) species(bases) - A.basis <- do.call(affinity, myargs) + 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) @@ -41,7 +57,7 @@ A.species <- affs[[1]] if(blend) { # calculate affinities using relative abundances of basis species - e <- equilibrate(A.basis) + e <- equilibrate(A.bases) for(j in seq_along(affs)) { for(i in seq_along(A.species$values)) { # start with zero affinity @@ -52,7 +68,7 @@ } } else { # use affinities from the single predominant basis species - d <- diagram(A.basis, plot.it=FALSE) + 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 @@ -62,5 +78,6 @@ } } # return the affinities for the species and basis species - return(list(A.species=A.species, A.basis=A.basis)) + if(is.null(bases2)) return(list(A.species=A.species, A.bases=A.bases)) + else return(list(A.species=A.species, A.bases=A.bases, A.bases2=A.bases2)) } Modified: pkg/CHNOSZ/R/transfer.R =================================================================== --- pkg/CHNOSZ/R/transfer.R 2014-12-20 07:36:08 UTC (rev 72) +++ pkg/CHNOSZ/R/transfer.R 2014-12-21 07:31:42 UTC (rev 73) @@ -25,7 +25,7 @@ istables <- character() myaffs <- list() sout <- NULL - # logarithm of zero (approx.) + # logarithm of a very small number (approaching zero) log0 <- -999 # logarithm of molality above which something # is considered possible for reaction (is present) Modified: pkg/CHNOSZ/demo/00Index =================================================================== --- pkg/CHNOSZ/demo/00Index 2014-12-20 07:36:08 UTC (rev 72) +++ pkg/CHNOSZ/demo/00Index 2014-12-21 07:31:42 UTC (rev 73) @@ -7,4 +7,5 @@ findit example of findit() using log-normal distribution as an objective CO2Ac activity of CO2 buffered by acetic acid; comparing affinity(return.buffer=TRUE) with diagram(what="CO2") nonideal activity coefficient of charged species, using the IS argument of subcrt -TPX Metastablilities of selected ionized bacterial thiol peroxidases as a chemical activity buffer +TPX metastablilities of selected ionized bacterial thiol peroxidases as a chemical activity buffer +mosaic Eh-pH diagram for iron oxides, sulfides and carbonate with two sets of changing basis species Added: pkg/CHNOSZ/demo/mosaic.R =================================================================== --- pkg/CHNOSZ/demo/mosaic.R (rev 0) +++ pkg/CHNOSZ/demo/mosaic.R 2014-12-21 07:31:42 UTC (rev 73) @@ -0,0 +1,38 @@ +# 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)) +# conditions and system definition +pH <- c(0, 14, 400) +Eh <- c(-1, 1, 400) +T <- 25 +basis(c("FeO", "SO4-2", "H2O", "H+", "e-", "CO3-2")) +basis("SO4-2", -6) +basis("CO3-2", 0) +species(c("Fe+2", "Fe+3"), -6) +species(c("pyrrhotite", "pyrite", "hematite", "magnetite", "siderite")) +# two sets of changing basis species: +# speciate SO4-2, HSO4-, HS-, H2S as a function of Eh and pH +# 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, TRUE, pH=pH, Eh=Eh, T=T) +# make a diagram and add water stability lines +diagram(m1$A.species) +water.lines("pH", "Eh", T=convert(T, "K"), col="seagreen", lwd=1.5) +# show lines for Fe(aq) = 10^-4 M +species(c("Fe+2", "Fe+3"), -4) +m2 <- mosaic(bases, bases2, TRUE, pH=pH, Eh=Eh, T=T) +diagram(m2$A.species, add=TRUE, names=NULL, dotted=3) +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")) +# overlay the carbonate basis species predominance fields +diagram(m1$A.bases2, add=TRUE, col="blue", col.names="blue", dotted=3) +# reset the database, as it was changed in this example +data(thermo) Modified: pkg/CHNOSZ/inst/NEWS =================================================================== --- pkg/CHNOSZ/inst/NEWS 2014-12-20 07:36:08 UTC (rev 72) +++ pkg/CHNOSZ/inst/NEWS 2014-12-21 07:31:42 UTC (rev 73) @@ -1,4 +1,4 @@ -CHANGES IN CHNOSZ 1.0.3-10 (2014-12-20) +CHANGES IN CHNOSZ 1.0.3-11 (2014-12-21) --------------------------------------- - Add files with average amino acid compositions of proteins from Bison Modified: pkg/CHNOSZ/man/examples.Rd =================================================================== --- pkg/CHNOSZ/man/examples.Rd 2014-12-20 07:36:08 UTC (rev 72) +++ pkg/CHNOSZ/man/examples.Rd 2014-12-21 07:31:42 UTC (rev 73) @@ -8,14 +8,14 @@ \arguments{ \item{do.png}{logical, generate PNG files for the plots?} - \item{which}{character, which example to run.} + \item{which}{character, which example to run} } \usage{ examples(do.png = FALSE) demos(which = c("sources", "NaCl", "cordierite", "phosphate", "nucleobase", "orp", "findit", - "CO2Ac", "nonideal")) + "CO2Ac", "nonideal", "TPX", "mosaic")) } \details{ @@ -39,12 +39,16 @@ \code{findit} \tab detailed example of usage of \code{\link{findit}} using log-normal distribution as an objective \cr \code{CO2Ac} \tab activity of CO2 buffered by acetic acid; comparing \code{\link{affinity}(return.buffer=TRUE)} with \code{\link{diagram}(what="CO2")} \cr \code{nonideal} \tab activity coefficient of charged species (Alberty, 2003), using the \code{IS} argument of \code{subcrt} \cr + \code{TPX} \tab metastablilities of selected ionized bacterial thiol peroxidases as a chemical activity buffer \cr + \code{mosaic} \tab Eh-pH diagram for iron oxides, sulfides and carbonate with two sets of changing basis species (Garrels and Christ, 1965) \cr } } \references{ Alberty, R. A. (2003) \emph{Thermodynamics of Biochemical Reactions}, John Wiley & Sons, Hoboken, New Jersey, 397 p. \url{http://www.worldcat.org/oclc/51242181} + + Garrels, R. M. and Christ, C. L. (1965) \emph{Solutions, Minerals, and Equilibria}, Harper & Row, New York, 450 p. \url{http://www.worldcat.org/oclc/517586} Shock, E. L., Oelkers, E. H., Johnson, J. W., Sverjensky, D. A. and Helgeson, H. C. (1992) Calculation of the thermodynamic properties of aqueous species at high pressures and temperatures: Effective electrostatic radii, dissociation constants and standard partial molal properties to 1000 \eqn{^{\circ}}{?}C and 5 kbar. \emph{J. Chem. Soc. Faraday Trans.} \bold{88}, 803--826. \url{http://dx.doi.org/10.1039/FT9928800803} } Modified: pkg/CHNOSZ/man/mosaic.Rd =================================================================== --- pkg/CHNOSZ/man/mosaic.Rd 2014-12-20 07:36:08 UTC (rev 72) +++ pkg/CHNOSZ/man/mosaic.Rd 2014-12-21 07:31:42 UTC (rev 73) @@ -7,11 +7,12 @@ } \usage{ - mosaic(bases, blend=FALSE, ...) + mosaic(bases, bases2=NULL, blend=FALSE, ...) } \arguments{ - \item{bases}{character, basis species to include in the calculation} + \item{bases}{character, basis species to be changed in the calculation} + \item{bases2}{character, second set of changing basis species} \item{blend}{logical, use relative abundances of basis species?} \item{...}{additional arguments to be passed to \code{\link{affinity}}} } @@ -19,23 +20,33 @@ \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. This is a way to \dQuote{speciate the basis species}. -An example is consideration of the speciation of sulfur (\samp{SO4-2}, \samp{HSO4-}, \samp{HS-} and \samp{H2S}) as a function of oxygen fugacity (or Eh) and pH in calculating the relative stabilities of minerals and aqueous species in the system Fe-S-O-H. -The first species listed in \code{bases} should correspond to one of the basis species currently defined, and the function only supports calculations using basis species that all derive from that species (i.e. all share the same element). +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. + +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 arguments in \code{...} are passed to \code{affinity} to specify the conditions. - -The function calculates the affinities using each basis species in turn, changing them via \code{\link{swap.basis}}. 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. -Chemical activity or predominance diagrams constructed using this method have been described as \dQuote{mosaic diagrams} in the literature. If \code{blend} is TRUE, the function combines the affinities of the formation reactions weighted by the relative abundances of the basis species at each condition. This tends to produce curved boundaries. +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. + } \value{ -A list containing \code{A.species} (affinities of formation of the species with changing basis speceis) and \code{A.basis} (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}}. +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). } +\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. +} + \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 @@ -61,7 +72,7 @@ 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 -#diagram(m1$A.basis, add=TRUE, col="blue", col.names="blue", dotted=3) +#diagram(m1$A.bases, add=TRUE, col="blue", col.names="blue", dotted=3) } \references{