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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Dec 11 07:16:03 CET 2014


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 <j3ffdick at gmail.com>

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.
 



More information about the CHNOSZ-commits mailing list