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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Nov 4 01:58:50 CET 2020


Author: jedick
Date: 2020-11-04 01:58:50 +0100 (Wed, 04 Nov 2020)
New Revision: 612

Modified:
   pkg/CHNOSZ/DESCRIPTION
   pkg/CHNOSZ/R/affinity.R
   pkg/CHNOSZ/R/basis.R
   pkg/CHNOSZ/R/buffer.R
   pkg/CHNOSZ/R/info.R
   pkg/CHNOSZ/R/thermo.R
   pkg/CHNOSZ/inst/NEWS.Rd
   pkg/CHNOSZ/man/buffer.Rd
Log:
Change defaults for 'state' and 'logact' in mod.buffer()


Modified: pkg/CHNOSZ/DESCRIPTION
===================================================================
--- pkg/CHNOSZ/DESCRIPTION	2020-11-03 02:02:47 UTC (rev 611)
+++ pkg/CHNOSZ/DESCRIPTION	2020-11-04 00:58:50 UTC (rev 612)
@@ -1,6 +1,6 @@
-Date: 2020-11-03
+Date: 2020-11-04
 Package: CHNOSZ
-Version: 1.3.6-85
+Version: 1.3.6-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/affinity.R
===================================================================
--- pkg/CHNOSZ/R/affinity.R	2020-11-03 02:02:47 UTC (rev 611)
+++ pkg/CHNOSZ/R/affinity.R	2020-11-04 00:58:50 UTC (rev 612)
@@ -102,8 +102,8 @@
       for(i in 1:length(is.buffer)) is.buff <- c(is.buff,as.numeric(is.buffer[[i]]))
       is.only.buffer <- is.buff[!is.buff %in% is.species]
       buffers <- names(is.buffer)
-      # reorder the buffers according to thermo$buffers
-      buffers <- buffers[order(match(buffers,thermo$buffers$name))]
+      # reorder the buffers according to thermo$buffer
+      buffers <- buffers[order(match(buffers,thermo$buffer$name))]
     }
 
     # here we call 'energy'

Modified: pkg/CHNOSZ/R/basis.R
===================================================================
--- pkg/CHNOSZ/R/basis.R	2020-11-03 02:02:47 UTC (rev 611)
+++ pkg/CHNOSZ/R/basis.R	2020-11-04 00:58:50 UTC (rev 612)
@@ -151,17 +151,17 @@
     if(!is.null(state)) {
       if(state[i] %in% thermo$buffer$name) {
         # this is the name of a buffer
-        ibuff <- which(as.character(thermo$buffers$name)==state[i])
+        ibuff <- which(as.character(thermo$buffer$name)==state[i])
         # check that each species in the buffer is compositionally
         # compatible with the basis definition
         for(k in 1:length(ibuff)) {
-          ispecies <- suppressMessages(info(as.character(thermo$buffers$species)[ibuff[k]],
-            as.character(thermo$buffers$state)[ibuff[k]], check.it=FALSE))
+          ispecies <- suppressMessages(info(as.character(thermo$buffer$species)[ibuff[k]],
+            as.character(thermo$buffer$state)[ibuff[k]], check.it=FALSE))
           bufmakeup <- makeup(ispecies)
           inbasis <- names(bufmakeup) %in% colnames(basis()) 
           if(FALSE %in% inbasis) {
             stop(paste("the elements '",c2s(names(bufmakeup)[!inbasis]),
-              "' of species '",thermo$buffers$species[ibuff[k]],"' in buffer '",state[i],
+              "' of species '",thermo$buffer$species[ibuff[k]],"' in buffer '",state[i],
               "' are not in the basis\n",sep=""))
           }
         }

Modified: pkg/CHNOSZ/R/buffer.R
===================================================================
--- pkg/CHNOSZ/R/buffer.R	2020-11-03 02:02:47 UTC (rev 611)
+++ pkg/CHNOSZ/R/buffer.R	2020-11-04 00:58:50 UTC (rev 612)
@@ -2,12 +2,12 @@
 # Calculate chemical activities of buffered species
 # 20061102 jmd
 
-mod.buffer <- function(name,species=NULL,state=thermo()$opt$state,logact=-3) {
+mod.buffer <- function(name, species = NULL, state = "cr", logact = 0) {
   # 20071102 add or change a buffer system
   thermo <- get("thermo", CHNOSZ)
   if(is.null(species)) {
-    iname <- which(name==thermo$buffers$name)
-    if(length(iname)>0) species <- thermo$buffers$species[iname]
+    iname <- which(name==thermo$buffer$name)
+    if(length(iname)>0) species <- thermo$buffer$species[iname]
     else species <- character()
   }
   ls <- length(species)
@@ -15,24 +15,24 @@
     stop('species must be at least as long as the other arguments')
   if(length(name)!=ls) name <- rep(name,length.out=ls)
   add <- TRUE
-  if(TRUE %in% (name %in% thermo$buffers$name)) {
+  if(TRUE %in% (name %in% thermo$buffer$name)) {
     add <- FALSE
-    imod <- which(thermo$buffers$name %in% name & thermo$buffers$species %in% species)
+    imod <- which(thermo$buffer$name %in% name & thermo$buffer$species %in% species)
     if(length(imod)>0) {
       if(state[1]=='') {
-        thermo$buffers <- thermo$buffers[-imod,]
+        thermo$buffer <- thermo$buffer[-imod,]
         assign("thermo", thermo, CHNOSZ)
         message(paste('mod.buffer: removed ',c2s(species),' in ',
           c2s(unique(name)),' buffer',sep=''))
       } else {
-        if(missing(state)) state <- thermo$buffers$state[imod]
-        if(missing(logact)) logact <- thermo$buffers$logact[imod]
+        if(missing(state)) state <- thermo$buffer$state[imod]
+        if(missing(logact)) logact <- thermo$buffer$logact[imod]
         if(length(state)!=ls) state <- rep(state,length.out=ls)
         if(length(logact)!=ls) logact <- rep(logact,length.out=ls)
-        state.old <- thermo$buffers$state[imod]
-        logact.old <- thermo$buffers$logact[imod]
-        thermo$buffers$state[imod] <- state
-        thermo$buffers$logact[imod] <- logact
+        state.old <- thermo$buffer$state[imod]
+        logact.old <- thermo$buffer$logact[imod]
+        thermo$buffer$state[imod] <- state
+        thermo$buffer$logact[imod] <- logact
         assign("thermo", thermo, CHNOSZ)
         if(identical(state.old,state) & identical(logact.old,logact)) {
           message(paste('mod.buffer: nothing changed for ',
@@ -49,11 +49,11 @@
   if(add) {
     if(state[1]=='') state <- rep(thermo$opt$state,length.out=ls)
     t <- data.frame(name=name,species=species,state=state,logact=logact)
-    thermo$buffers <- rbind(thermo$buffers,t)
+    thermo$buffer <- rbind(thermo$buffer,t)
     assign("thermo", thermo, CHNOSZ)
     message(paste('mod.buffer: added',c2s(unique(name))))
   }
-  return(invisible(thermo$buffers[thermo$buffers$name %in% name,]))
+  return(invisible(thermo$buffer[thermo$buffer$name %in% name,]))
 }
 
 ### unexported functions ###
@@ -70,15 +70,15 @@
       ibasis <- which(thermo$basis$logact==buffers[k])
       ispecies <- numeric()
       for(i in 1:length(ibasis)) {
-        ib <- as.character(thermo$buffers$name)==as.character(thermo$basis$logact[ibasis[i]])
-        species <- as.character(thermo$buffers$species)[ib]
-        state <- as.character(thermo$buffers$state)[ib]
+        ib <- as.character(thermo$buffer$name)==as.character(thermo$basis$logact[ibasis[i]])
+        species <- as.character(thermo$buffer$species)[ib]
+        state <- as.character(thermo$buffer$state)[ib]
         #ibuff <- info(species,state,quiet=TRUE)
         ispecies <- c(ispecies, species(species, state, index.return=TRUE, add = TRUE))
       }
       ispecies.new <- c(ispecies.new,list(ispecies))
       # make sure to set the activities
-      species(ispecies,thermo$buffers$logact[ib])
+      species(ispecies,thermo$buffer$logact[ib])
     }
     names(ispecies.new) <- buffers
     return(ispecies.new)

Modified: pkg/CHNOSZ/R/info.R
===================================================================
--- pkg/CHNOSZ/R/info.R	2020-11-03 02:02:47 UTC (rev 611)
+++ pkg/CHNOSZ/R/info.R	2020-11-04 00:58:50 UTC (rev 612)
@@ -20,7 +20,7 @@
     message(paste("thermo()$OBIGT has", nrow(thermo$OBIGT[thermo$OBIGT$state=="aq", ]), "aqueous,",
       nrow(thermo$OBIGT), "total species"))
     message(paste("number of literature sources: ", nrow(thermo$refs), ", elements: ",
-      nrow(thermo$element), ", buffers: ", length(unique(thermo$buffers$name)), sep=""))
+      nrow(thermo$element), ", buffers: ", length(unique(thermo$buffer$name)), sep=""))
     message(paste("number of proteins in thermo()$protein is", nrow(thermo$protein), "from",
       length(unique(thermo$protein$organism)), "organisms"))
     return()

Modified: pkg/CHNOSZ/R/thermo.R
===================================================================
--- pkg/CHNOSZ/R/thermo.R	2020-11-03 02:02:47 UTC (rev 611)
+++ pkg/CHNOSZ/R/thermo.R	2020-11-04 00:58:50 UTC (rev 612)
@@ -14,7 +14,7 @@
     element = read.csv(file.path(thermodir, "element.csv"), as.is=1:3),
     OBIGT = NULL,
     refs = NULL,
-    buffers = read.csv(file.path(thermodir, "buffer.csv"), as.is=1:3),
+    buffer = read.csv(file.path(thermodir, "buffer.csv"), as.is=1:3),
     protein = read.csv(file.path(thermodir, "protein.csv"), as.is=1:4),
     groups = read.csv(file.path(thermodir, "groups.csv"), row.names=1, check.names=FALSE),
     stoich = read.csv(file.path(thermodir, "stoich.csv.xz"), as.is=TRUE),

Modified: pkg/CHNOSZ/inst/NEWS.Rd
===================================================================
--- pkg/CHNOSZ/inst/NEWS.Rd	2020-11-03 02:02:47 UTC (rev 611)
+++ pkg/CHNOSZ/inst/NEWS.Rd	2020-11-04 00:58:50 UTC (rev 612)
@@ -9,7 +9,7 @@
 \newcommand{\s}{\ifelse{latex}{\eqn{_{#1}}}{\ifelse{html}{\out{<sub>#1</sub>}}{#1}}}
 \newcommand{\S}{\ifelse{latex}{\eqn{^{#1}}}{\ifelse{html}{\out{<sup>#1</sup>}}{^#1}}}
 
-\section{Changes in CHNOSZ version 1.3.6-83 (2020-10-06)}{
+\section{Changes in CHNOSZ version 1.3.6-86 (2020-11-04)}{
 
   \subsection{MAJOR CHANGES}{
     \itemize{
@@ -253,6 +253,9 @@
       require that species have non-NA values of standard Gibbs energy at this
       temperature and pressure.
 
+      \item Change defaults in \code{mod.buffer()} to be more suitable for
+      mineral buffers (\code{state = "cr"} and \code{logact = 0}).
+
       \item Convert this NEWS file to Rd format.
 
     }

Modified: pkg/CHNOSZ/man/buffer.Rd
===================================================================
--- pkg/CHNOSZ/man/buffer.Rd	2020-11-03 02:02:47 UTC (rev 611)
+++ pkg/CHNOSZ/man/buffer.Rd	2020-11-04 00:58:50 UTC (rev 612)
@@ -8,12 +8,11 @@
 }
 
 \usage{
-  mod.buffer(name, species = NULL, state = thermo()$opt$state, 
-    logact = -3)
+  mod.buffer(name, species = NULL, state = "cr", logact = 0)
 }
 
 \arguments{
-  \item{name}{character, name of buffer to add to or find in \code{thermo()$buffers}.}
+  \item{name}{character, name of buffer to add to or find in \code{thermo()$buffer}.}
   \item{species}{character, names or formulas of species in a buffer.}
   \item{state}{character, physical states of species in buffer.}
   \item{logact}{numeric, logarithms of activities of species in buffer.}
@@ -33,9 +32,9 @@
 This can be overriden with \code{balance}.
 The default value of \code{balance} is \samp{PBB}, which instructs the function to use the protein backbone group as the conserved quantity in buffers consisting of proteins, but has no overriding effect on the computations for buffers without proteins.
 
-To view the available buffers, print the \code{\link{thermo}$buffer} object.
+To view the available buffers, print the \code{\link{thermo}()$buffer} object.
 Buffer definitions can be added to this dataframe with \code{mod.buffer}.
-It is possible to set the logarithms of activities of the species in the buffer through the \code{logact} argument; if this is missing unit activity is assigned to crystalline species in buffer, otherwise (for aqueous species) the default value of activity is 10\eqn{^{-3}}{^-3}.
+The defaults for \code{state} and \code{logact} are intended for mineral buffers.
 If \code{name} identifies an already defined buffer, this function modifies the logarithms of activities or states of species in that buffer, optionally restricted to only those species given in \code{species}.
 
 It is possible to assign different buffers to different basis species, in which case the order of their calculation depends on their order in \code{thermo()$buffers}.
@@ -49,7 +48,7 @@
 \examples{
 \dontshow{reset()}
 ## list the buffers
-thermo()$buffers
+thermo()$buffer
 # another way to do it, for a specific buffer
 print(mod.buffer("PPM"))
 
@@ -57,18 +56,18 @@
 # calculate the activity of CO2 in equilibrium with
 # (a buffer made of) acetic acid at a given activity
 basis("CHNOS")
-basis("CO2","AC")
+basis("CO2", "AC")
 # what activity of acetic acid are we using?
 print(mod.buffer("AC"))
 # return the activity of CO2
-affinity(return.buffer=TRUE)$CO2  # -7.057521
+affinity(return.buffer = TRUE)$CO2  # -7.057521
 # as a function of oxygen fugacity
-affinity(O2=c(-85,-70,4),return.buffer=TRUE)
+affinity(O2 = c(-85, -70, 4), return.buffer = TRUE)
 # as a function of logfO2 and temperature
-affinity(O2=c(-85,-70,4),T=c(25,100,4),return.buffer=TRUE)
+affinity(O2 = c(-85, -70, 4), T = c(25, 100, 4), return.buffer = TRUE)
 # change the activity of species in the buffer
-mod.buffer("AC",logact=-10)
-affinity(O2=c(-85,-70,4),T=c(25,100,4),return.buffer=TRUE)
+mod.buffer("AC", logact = -10)
+affinity(O2 = c(-85,-70,4), T = c(25, 100, 4), return.buffer = TRUE)
 
 ## buffer made of three species
 ## Pyrite-Pyrrhotite-Magnetite (PPM)
@@ -93,27 +92,27 @@
 ## Eh-pH diagram; after Garrels, 1960, Figure 6
 basis("CHNOSe")
 # here we will buffer the activity of the electron by O2
-mod.buffer("O2","O2","gas",999)
-basis("e-","O2")
+mod.buffer("O2", "O2", "gas", 999)
+basis("e-", "O2")
 # start our plot, then loop over values of logfO2
-thermo.plot.new(xlim=c(0,14),ylim=c(-0.8,1.2),
-  xlab="pH",ylab=axis.label("Eh"))
+thermo.plot.new(xlim = c(0, 14), ylim = c(-0.8, 1.2),
+  xlab = "pH",ylab = axis.label("Eh"))
 # the upper and lower lines correspond to the upper
 # and lower stability limits of water
-logfO2 <- c(0,-20,-40,-60,-83.1)
+logfO2 <- c(0, -20, -40, -60, -83.1)
 for(i in 1:5) {
   # update the logarithm of fugacity (logact) of O2 in the buffer
-  mod.buffer("O2","O2","gas",logfO2[i])
+  mod.buffer("O2", "O2", "gas", logfO2[i])
   # get the values of the logarithm of activity of the electron
-  a <- affinity(pH=c(0,14,15),return.buffer=TRUE)
+  a <- affinity(pH = c(0, 14, 15), return.buffer = TRUE)
   # convert values of pe (-logact of the electron) to Eh
-  Eh <- convert(-as.numeric(a$`e-`),"Eh")
-  lines(seq(0,14,length.out=15),Eh)
+  Eh <- convert(-as.numeric(a$`e-`), "Eh")
+  lines(seq(0, 14, length.out = 15), Eh)
   # add some labels
-  text(seq(0,14,length.out=15)[i*2+2],Eh[i*2+2],
-    paste("logfO2=",logfO2[i],sep=""))
+  text(seq(0, 14, length.out = 15)[i*2+2], Eh[i*2+2],
+    paste("logfO2 =", logfO2[i]))
 }
-title(main=paste("Relation between logfO2(g), Eh and pH at\n",
+title(main = paste("Relation between logfO2(g), Eh and pH at\n",
   "25 degC and 1 bar. After Garrels, 1960"))
 
 ## buffer made of two species
@@ -121,13 +120,13 @@
 # CO2 and acetic acid. note their starting activities:
 print(mod.buffer("CO2-AC")) 
 basis("CHNOS")
-basis("O2","CO2-AC")
-affinity(return.buffer=TRUE)  # logfO2 = -75.94248
-basis("CO2",123)  # what the buffer reactions are balanced on
-affinity(return.buffer=TRUE)  # unchanged
+basis("O2", "CO2-AC")
+affinity(return.buffer = TRUE)  # logfO2 = -75.94248
+basis("CO2", 123)  # what the buffer reactions are balanced on
+affinity(return.buffer = TRUE)  # unchanged
 # consider more oxidizing conditions
-mod.buffer("CO2-AC",logact=c(0,-10))
-affinity(return.buffer=TRUE)
+mod.buffer("CO2-AC", logact = c(0, -10))
+affinity(return.buffer = TRUE)
 }
 
 \references{



More information about the CHNOSZ-commits mailing list