[CHNOSZ-commits] r755 - in pkg/CHNOSZ: . R demo inst inst/tinytest man man/macros vignettes

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Nov 25 11:01:43 CET 2022


Author: jedick
Date: 2022-11-25 11:01:43 +0100 (Fri, 25 Nov 2022)
New Revision: 755

Added:
   pkg/CHNOSZ/R/logB.to.OBIGT.R
   pkg/CHNOSZ/R/rank.affinity.R
   pkg/CHNOSZ/demo/rank.affinity.R
   pkg/CHNOSZ/man/logB.to.OBIGT.Rd
   pkg/CHNOSZ/man/rank.affinity.Rd
Removed:
   pkg/CHNOSZ/R/logB_to_OBIGT.R
   pkg/CHNOSZ/R/rank_affinity.R
   pkg/CHNOSZ/demo/rank_affinity.R
   pkg/CHNOSZ/man/logB_to_OBIGT.Rd
   pkg/CHNOSZ/man/rank_affinity.Rd
Modified:
   pkg/CHNOSZ/DESCRIPTION
   pkg/CHNOSZ/NAMESPACE
   pkg/CHNOSZ/R/diagram.R
   pkg/CHNOSZ/R/stack_mosaic.R
   pkg/CHNOSZ/R/util.plot.R
   pkg/CHNOSZ/demo/00Index
   pkg/CHNOSZ/inst/NEWS.Rd
   pkg/CHNOSZ/inst/tinytest/test-mod.OBIGT.R
   pkg/CHNOSZ/man/add.OBIGT.Rd
   pkg/CHNOSZ/man/diagram.Rd
   pkg/CHNOSZ/man/extdata.Rd
   pkg/CHNOSZ/man/macros/macros.Rd
   pkg/CHNOSZ/man/stack_mosaic.Rd
   pkg/CHNOSZ/man/util.plot.Rd
   pkg/CHNOSZ/vignettes/customizing.Rmd
Log:
Change underscore to period in add.alpha(), logB.to.OBIGT(), and rank.affinity()


Modified: pkg/CHNOSZ/DESCRIPTION
===================================================================
--- pkg/CHNOSZ/DESCRIPTION	2022-11-25 09:44:09 UTC (rev 754)
+++ pkg/CHNOSZ/DESCRIPTION	2022-11-25 10:01:43 UTC (rev 755)
@@ -1,6 +1,6 @@
-Date: 2022-11-22
+Date: 2022-11-25
 Package: CHNOSZ
-Version: 1.9.9-46
+Version: 1.9.9-47
 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/NAMESPACE
===================================================================
--- pkg/CHNOSZ/NAMESPACE	2022-11-25 09:44:09 UTC (rev 754)
+++ pkg/CHNOSZ/NAMESPACE	2022-11-25 10:01:43 UTC (rev 755)
@@ -56,11 +56,11 @@
 # added 20200716 or later
   "mash", "mix", "rebalance",
 # added 20220324
-  "logB_to_OBIGT",
+  "logB.to.OBIGT",
 # added 20220416
-  "rank_affinity",
+  "rank.affinity",
 # added 20220620
-  "stack_mosaic", "add_alpha"
+  "stack_mosaic", "add.alpha"
 )
 
 # Load shared objects

Modified: pkg/CHNOSZ/R/diagram.R
===================================================================
--- pkg/CHNOSZ/R/diagram.R	2022-11-25 09:44:09 UTC (rev 754)
+++ pkg/CHNOSZ/R/diagram.R	2022-11-25 10:01:43 UTC (rev 755)
@@ -44,15 +44,15 @@
   ## Check that eout is a valid object
   efun <- eout$fun
   if(length(efun)==0) efun <- ""
-  if(!(efun %in% c("affinity", "rank_affinity", "equilibrate") | grepl("solubilit", efun)))
-    stop("'eout' is not the output from one of these functions: affinity, rank_affinity, equilibrate, or solubility")
+  if(!(efun %in% c("affinity", "rank.affinity", "equilibrate") | grepl("solubilit", efun)))
+    stop("'eout' is not the output from one of these functions: affinity, rank.affinity, equilibrate, or solubility")
   # For solubilities(), default type is loga.balance 20210303
   if(grepl("solubilities", efun) & missing(type)) type <- "loga.balance"
-  # Check balance argument for rank_affinity() 20220416
-  if(efun == "rank_affinity") {
+  # Check balance argument for rank.affinity() 20220416
+  if(efun == "rank.affinity") {
     if(!identical(balance, 1)) {
-      if(!is.null(balance)) stop("balance = 1 or NULL is required for plotting output of rank_affinity()")
-      if(is.null(balance)) message("diagram: setting balance = 1 for plotting output of rank_affinity()")
+      if(!is.null(balance)) stop("balance = 1 or NULL is required for plotting output of rank.affinity()")
+      if(is.null(balance)) message("diagram: setting balance = 1 for plotting output of rank.affinity()")
       balance <- 1
     }
   }
@@ -124,8 +124,8 @@
     })
     names(plotvals) <- names(eout$values)
     plotvar <- eout$property
-    if(efun == "rank_affinity") {
-      plotvar <- "rank_affinity"
+    if(efun == "rank.affinity") {
+      plotvar <- "rank.affinity"
       message(paste("diagram: plotting average affinity ranking for", length(plotvals), "groups"))
     } else if(plotvar=="A") {
       # We change 'A' to 'A/(2.303RT)' so the axis label is made correctly
@@ -203,7 +203,7 @@
   ## Identify predominant species
   predominant <- NA
   H2O.predominant <- NULL
-  if(plotvar %in% c("loga.equil", "alpha", "A/(2.303RT)", "rank_affinity") & type!="saturation") {
+  if(plotvar %in% c("loga.equil", "alpha", "A/(2.303RT)", "rank.affinity") & type!="saturation") {
     pv <- plotvals
     # Some additional steps for affinity values, but not for equilibrated activities
     if(eout.is.aout) {
@@ -352,7 +352,7 @@
         if(missing(xlab)) xlab <- axis.label(eout$vars[1], basis=eout$basis, molality=molality)
         if(missing(ylab)) {
           ylab <- axis.label(plotvar, units="", molality=molality)
-          if(plotvar == "rank_affinity") ylab <- "Average affinity ranking"
+          if(plotvar == "rank.affinity") ylab <- "Average affinity ranking"
           # Use ppb, ppm, ppt (or log ppb etc.) for converted values of solubility 20190526
           if(grepl("solubility.", eout$fun, fixed=TRUE)) {
             ylab <- strsplit(eout$fun, ".", fixed=TRUE)[[1]][2]

Copied: pkg/CHNOSZ/R/logB.to.OBIGT.R (from rev 754, pkg/CHNOSZ/R/logB_to_OBIGT.R)
===================================================================
--- pkg/CHNOSZ/R/logB.to.OBIGT.R	                        (rev 0)
+++ pkg/CHNOSZ/R/logB.to.OBIGT.R	2022-11-25 10:01:43 UTC (rev 755)
@@ -0,0 +1,61 @@
+# CHNOSZ/logB.to.OBIGT.R
+# Fit G, S, and Cp to formation constants (logB) as a function of temperature
+# 20220324 jmd
+
+logB.to.OBIGT <- function(logB, species, coeff, T, P, tolerance = 0.05) {
+
+  # We need at least three temperature values
+  if(length(unique(T)) < 3) stop("at least 3 unique temperature values are needed")
+
+  ## Get the formula of the formed species (used as the species name in OBIGT)
+  ### NOTE: the formed species has to be *last* in this list
+  name <- tail(species, 1)
+  # Add the formed species to the thermodynamic database with ΔG°f = 0 at all temperatures
+  # Be sure to zap properties of a formed species that is already in the database
+  suppressMessages(mod.OBIGT(name, formula = name, E_units = E.units(), G = 0, S = 0, Cp = 0, zap = TRUE))
+  # Calculate logK of the formation reaction with ΔG°f = 0 for the formed species
+  logK0 <- suppressMessages(subcrt(species, coeff, T = T, P = P)$out$logK)
+
+  ## Get Gibbs energy of species from logB of reaction
+  # Calculate T in Kelvin
+  TK <- convert(T, "K")
+  # logB gives values for ΔG°r of the reaction
+  Gr <- convert(logB, "G", TK)
+  # logK0 gives values for ΔG°r of the reaction with ΔG°f = 0 for the formed species
+  Gr0 <- convert(logK0, "G", TK)
+  # Calculate ΔG°f of the formed species
+  Gf <- Gr - Gr0
+
+  ## Solve for G, S, and Cp
+  # Make an 'lm' model object for given Cp
+  Gfun <- function(Cp = 0) {
+    Tr <- 298.15
+    TTr <- TK - Tr
+    # Subtract Cp term from Gf
+    GCp <- Cp * (TK - Tr - TK * log(TK / Tr))
+    GCp[is.na(GCp)] <- 0
+    GfCp <- Gf - GCp
+    # Write linear model in Ttr -- slope is -S
+    lm(GfCp ~ TTr)
+  }
+  # Calculate the sum of squares of residuals for given Cp
+  Sqfun <- function(Cp) sum(Gfun(Cp)$residuals ^ 2)
+  # Find the Cp with minimum sum of squares of residuals
+  Cp <- optimize(Sqfun, c(-100, 100))$minimum
+  # Calculate the fitted G and S for this Cp
+  G <- Gfun(Cp)$coefficients[[1]]
+  S <- - Gfun(Cp)$coefficients[[2]]
+
+  ## Update the thermodynamic parameters of the formed species
+  ispecies <- do.call(mod.OBIGT, list(name = name, G = G, S = S, Cp = Cp))
+  # Calculate logK of the formation reaction with "real" ΔG°f for the formed species
+  logK <- suppressMessages(subcrt(species, coeff, T = T, P = P)$out$logK)
+  # Calculate the mean absolute difference
+  mad <- mean(abs(logK - logB))
+  message(paste("logB.to.OBIGT: mean absolute difference between logB (experimental) and logK (calculated) is", round(mad, 4)))
+  # Check that calculated values are close to input values
+  stopifnot(all.equal(logK, logB, tolerance = tolerance, scale = 1))
+  # Return the species index in OBIGT
+  ispecies
+
+}

Deleted: pkg/CHNOSZ/R/logB_to_OBIGT.R
===================================================================
--- pkg/CHNOSZ/R/logB_to_OBIGT.R	2022-11-25 09:44:09 UTC (rev 754)
+++ pkg/CHNOSZ/R/logB_to_OBIGT.R	2022-11-25 10:01:43 UTC (rev 755)
@@ -1,61 +0,0 @@
-# CHNOSZ/logB_to_OBIGT.R
-# Fit G, S, and Cp to formation constants (logB) as a function of temperature
-# 20220324 jmd
-
-logB_to_OBIGT <- function(logB, species, coeff, T, P, tolerance = 0.05) {
-
-  # We need at least three temperature values
-  if(length(unique(T)) < 3) stop("at least 3 unique temperature values are needed")
-
-  ## Get the formula of the formed species (used as the species name in OBIGT)
-  ### NOTE: the formed species has to be *last* in this list
-  name <- tail(species, 1)
-  # Add the formed species to the thermodynamic database with ΔG°f = 0 at all temperatures
-  # Be sure to zap properties of a formed species that is already in the database
-  suppressMessages(mod.OBIGT(name, formula = name, E_units = E.units(), G = 0, S = 0, Cp = 0, zap = TRUE))
-  # Calculate logK of the formation reaction with ΔG°f = 0 for the formed species
-  logK0 <- suppressMessages(subcrt(species, coeff, T = T, P = P)$out$logK)
-
-  ## Get Gibbs energy of species from logB of reaction
-  # Calculate T in Kelvin
-  TK <- convert(T, "K")
-  # logB gives values for ΔG°r of the reaction
-  Gr <- convert(logB, "G", TK)
-  # logK0 gives values for ΔG°r of the reaction with ΔG°f = 0 for the formed species
-  Gr0 <- convert(logK0, "G", TK)
-  # Calculate ΔG°f of the formed species
-  Gf <- Gr - Gr0
-
-  ## Solve for G, S, and Cp
-  # Make an 'lm' model object for given Cp
-  Gfun <- function(Cp = 0) {
-    Tr <- 298.15
-    TTr <- TK - Tr
-    # Subtract Cp term from Gf
-    GCp <- Cp * (TK - Tr - TK * log(TK / Tr))
-    GCp[is.na(GCp)] <- 0
-    GfCp <- Gf - GCp
-    # Write linear model in Ttr -- slope is -S
-    lm(GfCp ~ TTr)
-  }
-  # Calculate the sum of squares of residuals for given Cp
-  Sqfun <- function(Cp) sum(Gfun(Cp)$residuals ^ 2)
-  # Find the Cp with minimum sum of squares of residuals
-  Cp <- optimize(Sqfun, c(-100, 100))$minimum
-  # Calculate the fitted G and S for this Cp
-  G <- Gfun(Cp)$coefficients[[1]]
-  S <- - Gfun(Cp)$coefficients[[2]]
-
-  ## Update the thermodynamic parameters of the formed species
-  ispecies <- do.call(mod.OBIGT, list(name = name, G = G, S = S, Cp = Cp))
-  # Calculate logK of the formation reaction with "real" ΔG°f for the formed species
-  logK <- suppressMessages(subcrt(species, coeff, T = T, P = P)$out$logK)
-  # Calculate the mean absolute difference
-  mad <- mean(abs(logK - logB))
-  message(paste("logB_to_OBIGT: mean absolute difference between logB (experimental) and logK (calculated) is", round(mad, 4)))
-  # Check that calculated values are close to input values
-  stopifnot(all.equal(logK, logB, tolerance = tolerance, scale = 1))
-  # Return the species index in OBIGT
-  ispecies
-
-}

Copied: pkg/CHNOSZ/R/rank.affinity.R (from rev 754, pkg/CHNOSZ/R/rank_affinity.R)
===================================================================
--- pkg/CHNOSZ/R/rank.affinity.R	                        (rev 0)
+++ pkg/CHNOSZ/R/rank.affinity.R	2022-11-25 10:01:43 UTC (rev 755)
@@ -0,0 +1,27 @@
+# Calculate normalized sum of ranking of affinities for species in designated groups
+# 20220416 jmd first version
+
+rank.affinity <- function(aout, groups) {
+  # Put the affinities into matrix form
+  amat <- sapply(aout$values, as.numeric)
+  # Calculate ranks
+  # https://stackoverflow.com/questions/1412775/pmax-parallel-maximum-equivalent-for-rank-in-r
+  arank <- apply(amat, 1, rank)
+  # Get the normalized ranks for each group
+  grank <- sapply(groups, function(group) {
+    # Sum the ranks for this group and divide by number of species in the group
+    if(inherits(group, "logical")) n <- sum(group)
+    if(inherits(group, "integer")) n <- length(group)
+    colSums(arank[group, ]) / n
+  })
+  # Restore dims
+  dims <- dim(aout$values[[1]])
+  glist <- apply(grank, 2, "dim<-", dims, simplify = FALSE)
+  aout$values <- glist
+  # Rename species to group names (for use by diagram())
+  aout$species <- aout$species[1:length(groups), ]
+  aout$species$name <- names(groups)
+  # "Sign" the object with our function name
+  aout$fun <- "rank.affinity"
+  aout
+}

Deleted: pkg/CHNOSZ/R/rank_affinity.R
===================================================================
--- pkg/CHNOSZ/R/rank_affinity.R	2022-11-25 09:44:09 UTC (rev 754)
+++ pkg/CHNOSZ/R/rank_affinity.R	2022-11-25 10:01:43 UTC (rev 755)
@@ -1,27 +0,0 @@
-# Calculate normalized sum of ranking of affinities for species in designated groups
-# 20220416 jmd first version
-
-rank_affinity <- function(aout, groups) {
-  # Put the affinities into matrix form
-  amat <- sapply(aout$values, as.numeric)
-  # Calculate ranks
-  # https://stackoverflow.com/questions/1412775/pmax-parallel-maximum-equivalent-for-rank-in-r
-  arank <- apply(amat, 1, rank)
-  # Get the normalized ranks for each group
-  grank <- sapply(groups, function(group) {
-    # Sum the ranks for this group and divide by number of species in the group
-    if(inherits(group, "logical")) n <- sum(group)
-    if(inherits(group, "integer")) n <- length(group)
-    colSums(arank[group, ]) / n
-  })
-  # Restore dims
-  dims <- dim(aout$values[[1]])
-  glist <- apply(grank, 2, "dim<-", dims, simplify = FALSE)
-  aout$values <- glist
-  # Rename species to group names (for use by diagram())
-  aout$species <- aout$species[1:length(groups), ]
-  aout$species$name <- names(groups)
-  # "Sign" the object with our function name
-  aout$fun <- "rank_affinity"
-  aout
-}

Modified: pkg/CHNOSZ/R/stack_mosaic.R
===================================================================
--- pkg/CHNOSZ/R/stack_mosaic.R	2022-11-25 09:44:09 UTC (rev 754)
+++ pkg/CHNOSZ/R/stack_mosaic.R	2022-11-25 10:01:43 UTC (rev 755)
@@ -10,7 +10,7 @@
   loga_aq = NULL, plot.it = TRUE, ...) {
 
   # Default is to use semi-transparent fill for bimetallic species
-  if(is.null(fill)) fill <- list(NA, NA, add_alpha(col.names[3], "50"))
+  if(is.null(fill)) fill <- list(NA, NA, add.alpha(col.names[3], "50"))
 
   # Load species1 (first metal-bearing species)
   isp1 <- species(species1)
@@ -58,12 +58,3 @@
   invisible(out)
 
 }
-
-# Function to add transparency to given color 20220223
-add_alpha <- function(col, alpha) {
-  x <- col2rgb(col)
-  newcol <- rgb(x[1], x[2], x[3], maxColorValue = 255)
-  newcol <- paste0(newcol, alpha)
-  newcol
-}
-

Modified: pkg/CHNOSZ/R/util.plot.R
===================================================================
--- pkg/CHNOSZ/R/util.plot.R	2022-11-25 09:44:09 UTC (rev 754)
+++ pkg/CHNOSZ/R/util.plot.R	2022-11-25 10:01:43 UTC (rev 755)
@@ -295,3 +295,11 @@
     if(!is.null(lab)) mtext(lab,side=thisside,line=line,cex=cex,las=las)
   }
 }
+
+# Function to add transparency to given color 20220223
+add.alpha <- function(col, alpha) {
+  x <- col2rgb(col)
+  newcol <- rgb(x[1], x[2], x[3], maxColorValue = 255)
+  newcol <- paste0(newcol, alpha)
+  newcol
+}

Modified: pkg/CHNOSZ/demo/00Index
===================================================================
--- pkg/CHNOSZ/demo/00Index	2022-11-25 09:44:09 UTC (rev 754)
+++ pkg/CHNOSZ/demo/00Index	2022-11-25 10:01:43 UTC (rev 755)
@@ -30,4 +30,4 @@
 comproportionation  Gibbs energy of sulfur comproportionation
 Pourbaix        Eh-pH diagram for Fe-O-H with equisolubility lines
 E_coli          Gibbs energy of biomass synthesis in E. coli
-rank_affinity   Affinity ranking for proteins in yeast nutrient limitation
+rank.affinity   Affinity ranking for proteins in yeast nutrient limitation

Copied: pkg/CHNOSZ/demo/rank.affinity.R (from rev 754, pkg/CHNOSZ/demo/rank_affinity.R)
===================================================================
--- pkg/CHNOSZ/demo/rank.affinity.R	                        (rev 0)
+++ pkg/CHNOSZ/demo/rank.affinity.R	2022-11-25 10:01:43 UTC (rev 755)
@@ -0,0 +1,31 @@
+## Affinity ranking for proteins coded by differentially expressed
+## genes in response to carbon limitation in yeast
+# Demo written on 20220620
+# Adapted from an example previously in read.expr.Rd (CHNOSZ 1.1.0) and yeast.Rd (CHNOSZ 1.2.0-1.3.0)
+library(CHNOSZ)
+
+# Experimental data are from Tai et al. (2005)
+# https://doi.org/10.1074/jbc.M410573200
+file <- system.file("extdata/protein/TBD+05.csv", package = "CHNOSZ")
+dat <- read.csv(file, row.names = 1, check.names = FALSE)
+
+# The activities of ammonium and sulfate are similar to the
+# non-growth-limiting concentrations used by Boer et al. (2003)
+# https://doi.org/10.1074/jbc.M209759200 
+basis(c("glucose", "H2O", "NH4+", "oxygen", "SO4-2", "H+"),
+  c(-1, 0, -1.3, 999, -1.4, -7))
+
+aafile <- system.file("extdata/protein/TBD+05_aa.csv", package = "CHNOSZ")
+aa <- read.csv(aafile)
+iprotein <- add.protein(aa, as.residue = TRUE)
+
+res <- 200
+aout <- affinity(C6H12O6 = c(-60, -20, res), O2 = c(-72, -60, res), iprotein = iprotein)
+groups <- apply(dat, 2, which)
+names(groups) <- paste0(names(groups), "\n(", colSums(dat), ")")
+arank <- rank.affinity(aout, groups)
+fill <- c("#d2b48c", "#b0e0e6", "#d3d3d3", "#d8bfd8")
+diagram(arank, format.names = FALSE, fill = fill)
+
+title(main = paste("Affinity ranking for proteins coded by differentially expressed\n",
+  "genes under carbon limitation in yeast (data from Tai et al., 2005)"), font.main = 1)

Deleted: pkg/CHNOSZ/demo/rank_affinity.R
===================================================================
--- pkg/CHNOSZ/demo/rank_affinity.R	2022-11-25 09:44:09 UTC (rev 754)
+++ pkg/CHNOSZ/demo/rank_affinity.R	2022-11-25 10:01:43 UTC (rev 755)
@@ -1,31 +0,0 @@
-## Affinity ranking for proteins coded by differentially expressed
-## genes in response to carbon limitation in yeast
-# Demo written on 20220620
-# Adapted from an example previously in read.expr.Rd (CHNOSZ 1.1.0) and yeast.Rd (CHNOSZ 1.2.0-1.3.0)
-library(CHNOSZ)
-
-# Experimental data are from Tai et al. (2005)
-# https://doi.org/10.1074/jbc.M410573200
-file <- system.file("extdata/protein/TBD+05.csv", package = "CHNOSZ")
-dat <- read.csv(file, row.names = 1, check.names = FALSE)
-
-# The activities of ammonium and sulfate are similar to the
-# non-growth-limiting concentrations used by Boer et al. (2003)
-# https://doi.org/10.1074/jbc.M209759200 
-basis(c("glucose", "H2O", "NH4+", "oxygen", "SO4-2", "H+"),
-  c(-1, 0, -1.3, 999, -1.4, -7))
-
-aafile <- system.file("extdata/protein/TBD+05_aa.csv", package = "CHNOSZ")
-aa <- read.csv(aafile)
-iprotein <- add.protein(aa, as.residue = TRUE)
-
-res <- 200
-aout <- affinity(C6H12O6 = c(-60, -20, res), O2 = c(-72, -60, res), iprotein = iprotein)
-groups <- apply(dat, 2, which)
-names(groups) <- paste0(names(groups), "\n(", colSums(dat), ")")
-arank <- rank_affinity(aout, groups)
-fill <- c("#d2b48c", "#b0e0e6", "#d3d3d3", "#d8bfd8")
-diagram(arank, format.names = FALSE, fill = fill)
-
-title(main = paste("Affinity ranking for proteins coded by differentially expressed\n",
-  "genes under carbon limitation in yeast (data from Tai et al., 2005)"), font.main = 1)

Modified: pkg/CHNOSZ/inst/NEWS.Rd
===================================================================
--- pkg/CHNOSZ/inst/NEWS.Rd	2022-11-25 09:44:09 UTC (rev 754)
+++ pkg/CHNOSZ/inst/NEWS.Rd	2022-11-25 10:01:43 UTC (rev 755)
@@ -12,7 +12,7 @@
 % links to vignettes 20220723
 \newcommand{\viglink}{\ifelse{html}{\out{<a href="../CHNOSZ/doc/#1.html"><strong>#1.Rmd</strong></a>}}{\bold{#1.Rmd}}}
 
-\section{Changes in CHNOSZ version 1.9.9-46 (2022-11-22)}{
+\section{Changes in CHNOSZ version 1.9.9-47 (2022-11-25)}{
 
   \subsection{MAJOR USER-VISIBLE CHANGES}{
     \itemize{
@@ -73,7 +73,7 @@
   \subsection{NEW FEATURES: THERMODYNAMIC DATA}{
     \itemize{
 
-      \item Add \code{logB_to_OBIGT()} to fit three thermodynamic parameters
+      \item Add \code{logB.to.OBIGT()} to fit three thermodynamic parameters
       (\samp{G}, \samp{S}, and \samp{Cp} at 25 \degC) to formation constants of
       aqueous species as a function of temperature.
 
@@ -80,7 +80,7 @@
       \item Add vignette \viglink{customizing} with description of database
       format, data-entry conventions, and examples of customizing the
       thermodynamic database using \code{add.OBIGT()}, \code{mod.OBIGT()}, and
-      \code{logB_to_OBIGT()}.
+      \code{logB.to.OBIGT()}.
 
     }
   }
@@ -99,7 +99,7 @@
       aqueous basis species. This obviates a workaround that was previously
       used in the Mosaic Stacking 2 section of \strong{multi-metal.Rmd}.
 
-      \item Add \code{add_alpha()} to add alpha value to a color specified in
+      \item Add \code{add.alpha()} to add alpha value to a color specified in
       any notation accepted by \code{col2rgb()}.
 
     }
@@ -108,7 +108,7 @@
   \subsection{NEW FEATURES: PROTEINS}{
     \itemize{
 
-      \item Add function \code{rank_affinity()} to calculate means of affinity
+      \item Add function \code{rank.affinity()} to calculate means of affinity
       rankings for specified groups of proteins, intended for evolutionary
       comparisons. The output of the new function can be used by
       \code{diagram()}.
@@ -187,7 +187,7 @@
       activated.
 
       \item Add a \strong{zap} argument to \code{mod.OBIGT()} to clear
-      parameters of preexisting species (used by \code{logB_to_OBIGT()}).
+      parameters of preexisting species (used by \code{logB.to.OBIGT()}).
 
       \item In \code{affinity()}, make \code{loga.protein = 0} the default
       (changed from -3).

Modified: pkg/CHNOSZ/inst/tinytest/test-mod.OBIGT.R
===================================================================
--- pkg/CHNOSZ/inst/tinytest/test-mod.OBIGT.R	2022-11-25 09:44:09 UTC (rev 754)
+++ pkg/CHNOSZ/inst/tinytest/test-mod.OBIGT.R	2022-11-25 10:01:43 UTC (rev 755)
@@ -34,7 +34,7 @@
 coeff <- c(-1, -1, 1)
 T <- c(120, 150, 200, 250, 300)
 P <- "Psat"
-expect_error(logB_to_OBIGT(logB[1:2], species, coeff, T[1:2], P))
+expect_error(logB.to.OBIGT(logB[1:2], species, coeff, T[1:2], P))
 
 # Test added 20220920
 info <- "Can add > 1 species; different states get different default models; info() works after mod.OBIGT"

Modified: pkg/CHNOSZ/man/add.OBIGT.Rd
===================================================================
--- pkg/CHNOSZ/man/add.OBIGT.Rd	2022-11-25 09:44:09 UTC (rev 754)
+++ pkg/CHNOSZ/man/add.OBIGT.Rd	2022-11-25 10:01:43 UTC (rev 755)
@@ -63,7 +63,7 @@
 The values returned (\code{\link{invisible}}-y) are the indices of the added and/or modified species.
 }
 
-\seealso{ \code{\link{thermo}} (description of OBIGT), \code{\link{mod.buffer}} (modify buffer definitions), \code{\link{logB_to_OBIGT}} (fit thermodynamic parameters to formation constants) }
+\seealso{ \code{\link{thermo}} (description of OBIGT), \code{\link{mod.buffer}} (modify buffer definitions), \code{\link{logB.to.OBIGT}} (fit thermodynamic parameters to formation constants) }
 
 \examples{\dontshow{reset()}
 ## Modify an existing species (not real properties)

Modified: pkg/CHNOSZ/man/diagram.Rd
===================================================================
--- pkg/CHNOSZ/man/diagram.Rd	2022-11-25 09:44:09 UTC (rev 754)
+++ pkg/CHNOSZ/man/diagram.Rd	2022-11-25 10:01:43 UTC (rev 755)
@@ -93,7 +93,7 @@
 \details{
 
 This function displays diagrams representing either chemical affinities or equilibrium chemical activities of species.
-The first argument is the output from \code{\link{affinity}}, \code{\link{rank_affinity}}, \code{\link{equilibrate}}, or \code{\link{solubility}}.
+The first argument is the output from \code{\link{affinity}}, \code{\link{rank.affinity}}, \code{\link{equilibrate}}, or \code{\link{solubility}}.
 0-D diagrams, at a single point, are shown as \code{\link{barplot}}s.
 1-D diagrams, for a single variable on the x-axis, are plotted as lines.
 2-D diagrams, for two variables, are plotted as predominance fields.

Modified: pkg/CHNOSZ/man/extdata.Rd
===================================================================
--- pkg/CHNOSZ/man/extdata.Rd	2022-11-25 09:44:09 UTC (rev 754)
+++ pkg/CHNOSZ/man/extdata.Rd	2022-11-25 10:01:43 UTC (rev 755)
@@ -30,7 +30,7 @@
     \item \code{HWM96_V.csv}, \code{HW97_Cp.csv} Apparent molar volumes and heat capacities of \CH4, \CO2, \H2S, and \NH3 in dilute aqueous solutions reported by Hnědkovský et al., 1996 and Hnědkovský and Wood, 1997. Units are Kelvin, MPa, J/K/mol, and cm3/mol. See \code{demo("AD")} for examples that use these files.
     \item \code{SC10_Rainbow.csv} Values of temperature (\degC), pH and logarithms of activity of \CO2, \H2, \NH4plus, \H2S and \CH4 for mixing of seawater and hydrothermal fluid at Rainbow field (Mid-Atlantic Ridge), taken from Shock and Canovas, 2010. See the vignette \viglink{anintro} for an example that uses this file.
     \item \code{SS98_Fig5a.csv}, \code{SS98_Fig5b.csv} Values of logarithm of fugacity of \O2 and pH as a function of temperature for mixing of seawater and hydrothermal fluid, digitized from Figs. 5a and b of Shock and Schulte, 1998. See the vignette \viglink{anintro} for an example that uses this file.
-    \item \code{rubisco.csv} UniProt IDs for Rubisco, ranges of optimal growth temperature of organisms, domain and name of organisms, and URL of reference for growth temperature, from Dick, 2014. See \code{\link{rank_affinity}} and the vignette \viglink{anintro} for examples that use this file.
+    \item \code{rubisco.csv} UniProt IDs for Rubisco, ranges of optimal growth temperature of organisms, domain and name of organisms, and URL of reference for growth temperature, from Dick, 2014. See \code{\link{rank.affinity}} and the vignette \viglink{anintro} for examples that use this file.
     \item \code{bluered.txt} Blue - light grey - red color palette, computed using \CRANpkg{colorspace}\code{::diverge_hcl(1000,} \code{c = 100, l = c(50, 90), power = 1)}. This is used by \code{\link{ZC.col}}.
     \item \code{AD03_Fig1?.csv} Experimental data points digitized from Figure 1 of Akinfiev and Diamond, 2003, used in \code{demo("AD")}.
     \item \code{TKSS14_Fig2.csv} Experimental data points digitized from Figure 2 of Tutolo et al., 2014, used in \code{demo("aluminum")}.
@@ -46,7 +46,7 @@
       These are various subunits of the Poliovirus type 1 polyprotein (POLG_POL1M in UniProt).
     \item \code{TBD+05.csv} lists genes with transcriptomic expression changes in carbon limitation stress response experiments in yeast (Tai et al., 2005).
     \item \code{TBD+05_aa.csv} has the amino acid compositions of proteins coded by those genes.
-      The last two files are used in \code{demo{"rank_affinity"}}.
+      The last two files are used in \code{demo{"rank.affinity"}}.
   }
 
   Files in \code{taxonomy} contain taxonomic data files:

Copied: pkg/CHNOSZ/man/logB.to.OBIGT.Rd (from rev 754, pkg/CHNOSZ/man/logB_to_OBIGT.Rd)
===================================================================
--- pkg/CHNOSZ/man/logB.to.OBIGT.Rd	                        (rev 0)
+++ pkg/CHNOSZ/man/logB.to.OBIGT.Rd	2022-11-25 10:01:43 UTC (rev 755)
@@ -0,0 +1,91 @@
+\encoding{UTF-8}
+\name{logB.to.OBIGT}
+\alias{logB.to.OBIGT}
+\title{Fit Thermodynamic Parameters to Formation Constants (\logB)}
+\description{
+Fit thermodynamic parameters to experimental formation constants for an aqueous species and add the parameters to OBIGT.
+}
+
+\usage{
+  logB.to.OBIGT(logB, species, coeff, T, P, tolerance = 0.05)
+}
+
+\arguments{
+  \item{logB}{Values of \logB}
+  \item{species}{Species in the formation reaction (the formed species must be last)}
+  \item{coeff}{Coefficients of the formation reaction}
+  \item{T}{Temperature (units of \code{\link{T.units}})}
+  \item{P}{Temperature (\samp{Psat} or numerical values with units of \code{\link{P.units}})}
+  \item{tolerance}{Tolerance for checking equivalence of input and calculated \logB values}
+}
+
+\details{
+
+\code{logB.to.OBIGT} starts with the decimal logarithms of equilibrium constants (\logB) for a formation reaction.
+The formation reaction is defined by \code{species} and \code{coeff}.
+All species in the formation reaction must be available in OBIGT except for the \emph{last} species, which must be the newly formed species.
+The properties of the known species are combined with \logB to calculate the standard Gibbs energy (G[T]) of the formed species as a function of \T and \P.
+
+The values of G[T] are fit using the thermodynamic parameters \code{G}, \code{S}, and \code{Cp} (i.e., standard-state values at 25 °C and 1 bar).
+The equation is this: G[T] = G[Tr] + -S[Tr] * (T - Tr) + Cp[Tr] (T - Tr - T * ln(T / Tr)), where G, S, and Cp are standard-state Gibbs energy, entropy, and isobaric heat capacity, T is the temperature in Kelvin, Tr is the reference temperature (298.15 K), and ln stands for the natural logarithm.
+Note that the equation assumes a constant heat capacity and no volume change, and it may be unsuitable for extrapolation beyond the original \T and \P range.
+
+The fitted \code{G}, \code{S}, and \code{Cp} for the formed species are added to OBIGT.
+\code{\link{all.equal}} is used to test the near equivalence of the input and calculated equilibrium constants; if the mean absolute difference exceeds \code{tolerance}, an error occurs.
+
+}
+
+\seealso{
+\code{logB.to.OBIGT} calls \code{\link{mod.OBIGT}} with \code{zap = TRUE} to clear the parameters of a formed species if it already exists in the OBIGT database.
+If preexisting parameters (e.g. HKF coefficients) weren't cleared, they would interfere with the fitting done here, which uses only three parameters (\code{G}, \code{S}, and \code{Cp}).
+}
+
+\examples{
+## CoHS+ from Migdisov et al. (2011)
+logB <- c(6.24, 6.02, 5.84, 5.97, 6.52)
+species <- c("Co+2", "HS-", "CoHS+")
+coeff <- c(-1, -1, 1)
+T <- c(120, 150, 200, 250, 300)
+P <- "Psat"
+inew <- logB.to.OBIGT(logB, species, coeff, T, P)
+# Print the new database entry
+# (Note: H is calculated from G and S)
+info(inew)
+# Make a plot of experimental logB
+xlim <- c()
+plot(T, logB, "n", c(100, 320), c(5.8, 6.8), xlab = axis.label("T"), ylab = quote(log~beta))
+points(T, logB, pch = 19, cex = 2)
+# Plot fitted values
+Tfit <- seq(100, 320, 10)
+sres <- subcrt(species, coeff, T = Tfit)
+lines(sres$out$T, sres$out$logK, col = 4)
+title(describe.reaction(sres$reaction))
+legend <- c("Migdisov et al. (2011)", "logB.to.OBIGT()")
+legend("topleft", legend, pch = c(19, NA), lty = c(0, 1), col = c(1, 4), pt.cex = 2)
+
+## ZnCl+ from Mei et al. (2015)
+# These are values for 5000 bar calculated from the modified Ryzhenko-Bryzgalin model
+logB <- c(-1.93, -1.16, -0.38, 0.45, 1.15, 1.76, 2.30, 2.80, 3.26, 3.70, 4.12, 4.53, 4.92)
+species <- c("Zn+2", "Cl-", "ZnCl+")
+coeff <- c(-1, -1, 1)
+T <- c(25, 60, 100, 150, 200, 250, 300, 350, 400, 450, 500, 550, 600)
+P <- 5000
+# Note: ZnCl+ is in the default OBIGT database;
+# logB.to.OBIGT() "zaps" the previous parameters before adding the fitted ones
+inew <- logB.to.OBIGT(logB, species, coeff, T, P)
+# Plot MRB and logB.to.OBIGT fitted values
+plot(T, logB, xlab = axis.label("T"), ylab = axis.label("logB"), pch = 19, cex = 2)
+Tfit <- seq(25, 600, 25)
+sres <- subcrt(species, coeff, T = Tfit, P = P)
+lines(sres$out$T, sres$out$logK, col = 4)
+title(describe.reaction(sres$reaction), line = 3)
+title("5000 bar", font.main = 1, line = 1)
+legend <- c("Mei et al. (2015)", "logB.to.OBIGT()")
+legend("topleft", legend, pch = c(19, NA), lty = c(0, 1), col = c(1, 4), pt.cex = 2)
+}
+
+\references{
+Migdisov, Art. A., Zezin, D. and Williams-Jones, A. E. (2011) An experimental study of Cobalt (II) complexation in Cl\S{-} and H\s{2}S-bearing hydrothermal solutions. \emph{Geochim. Cosmochim. Acta} \bold{75}, 4065--4079. \doi{10.1016/j.gca.2011.05.003}
+
+Mei, Y., Sherman, D. M., Liu, W., Etschmann, B., Testemale, D. and Brugger, J. (2015) Zinc complexation in chloride-rich hydrothermal fluids (25--600 \degC): A thermodynamic model derived from \emph{ab initio} molecular dynamics. \emph{Geochim. Cosmochim. Acta} \bold{150}, 264--284. \doi{10.1016/j.gca.2014.09.023}
+}

Deleted: pkg/CHNOSZ/man/logB_to_OBIGT.Rd
===================================================================
--- pkg/CHNOSZ/man/logB_to_OBIGT.Rd	2022-11-25 09:44:09 UTC (rev 754)
+++ pkg/CHNOSZ/man/logB_to_OBIGT.Rd	2022-11-25 10:01:43 UTC (rev 755)
@@ -1,91 +0,0 @@
-\encoding{UTF-8}
-\name{logB_to_OBIGT}
-\alias{logB_to_OBIGT}
-\title{Fit Thermodynamic Parameters to Formation Constants (\logB)}
-\description{
-Fit thermodynamic parameters to experimental formation constants for an aqueous species and add the parameters to OBIGT.
-}
-
-\usage{
-  logB_to_OBIGT(logB, species, coeff, T, P, tolerance = 0.05)
-}
-
-\arguments{
-  \item{logB}{Values of \logB}
-  \item{species}{Species in the formation reaction (the formed species must be last)}
-  \item{coeff}{Coefficients of the formation reaction}
-  \item{T}{Temperature (units of \code{\link{T.units}})}
-  \item{P}{Temperature (\samp{Psat} or numerical values with units of \code{\link{P.units}})}
-  \item{tolerance}{Tolerance for checking equivalence of input and calculated \logB values}
-}
-
-\details{
-
-\code{logB_to_OBIGT} starts with the decimal logarithms of equilibrium constants (\logB) for a formation reaction.
-The formation reaction is defined by \code{species} and \code{coeff}.
-All species in the formation reaction must be available in OBIGT except for the \emph{last} species, which must be the newly formed species.
-The properties of the known species are combined with \logB to calculate the standard Gibbs energy (G[T]) of the formed species as a function of \T and \P.
-
-The values of G[T] are fit using the thermodynamic parameters \code{G}, \code{S}, and \code{Cp} (i.e., standard-state values at 25 °C and 1 bar).
-The equation is this: G[T] = G[Tr] + -S[Tr] * (T - Tr) + Cp[Tr] (T - Tr - T * ln(T / Tr)), where G, S, and Cp are standard-state Gibbs energy, entropy, and isobaric heat capacity, T is the temperature in Kelvin, Tr is the reference temperature (298.15 K), and ln stands for the natural logarithm.
-Note that the equation assumes a constant heat capacity and no volume change, and it may be unsuitable for extrapolation beyond the original \T and \P range.
-
-The fitted \code{G}, \code{S}, and \code{Cp} for the formed species are added to OBIGT.
[TRUNCATED]

To get the complete diff run:
    svnlook diff /svnroot/chnosz -r 755


More information about the CHNOSZ-commits mailing list