[CHNOSZ-commits] r774 - in pkg/CHNOSZ: . R inst/tinytest man vignettes

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat Mar 4 03:41:46 CET 2023


Author: jedick
Date: 2023-03-04 03:41:46 +0100 (Sat, 04 Mar 2023)
New Revision: 774

Modified:
   pkg/CHNOSZ/DESCRIPTION
   pkg/CHNOSZ/R/protein.info.R
   pkg/CHNOSZ/R/util.formula.R
   pkg/CHNOSZ/inst/tinytest/test-util.R
   pkg/CHNOSZ/man/NaCl.Rd
   pkg/CHNOSZ/man/extdata.Rd
   pkg/CHNOSZ/man/nonideal.Rd
   pkg/CHNOSZ/man/subcrt.Rd
   pkg/CHNOSZ/man/util.expression.Rd
   pkg/CHNOSZ/man/util.formula.Rd
   pkg/CHNOSZ/man/util.misc.Rd
   pkg/CHNOSZ/vignettes/anintro.Rmd
Log:
Use default E_units = "J" in GHS()


Modified: pkg/CHNOSZ/DESCRIPTION
===================================================================
--- pkg/CHNOSZ/DESCRIPTION	2023-03-04 02:02:13 UTC (rev 773)
+++ pkg/CHNOSZ/DESCRIPTION	2023-03-04 02:41:46 UTC (rev 774)
@@ -1,6 +1,6 @@
 Date: 2023-03-04
 Package: CHNOSZ
-Version: 1.9.9-65
+Version: 1.9.9-66
 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/protein.info.R
===================================================================
--- pkg/CHNOSZ/R/protein.info.R	2023-03-04 02:02:13 UTC (rev 773)
+++ pkg/CHNOSZ/R/protein.info.R	2023-03-04 02:41:46 UTC (rev 774)
@@ -82,7 +82,7 @@
   OBIGT <- get("thermo", CHNOSZ)$OBIGT
   OBIGT_state <- paste(OBIGT$name, OBIGT$state)
   igroup <- match(groups_state, OBIGT_state)
-  # The properties are in columns 9-21 of thermo()$OBIGT
+  # The properties are in columns 10-22 of thermo()$OBIGT
   groupprops <- OBIGT[igroup, 10:22]
   # The elements in each of the groups
   groupelements <- i2A(igroup)

Modified: pkg/CHNOSZ/R/util.formula.R
===================================================================
--- pkg/CHNOSZ/R/util.formula.R	2023-03-04 02:02:13 UTC (rev 773)
+++ pkg/CHNOSZ/R/util.formula.R	2023-03-04 02:41:46 UTC (rev 774)
@@ -93,10 +93,10 @@
   convert(entropy, "J")
 }
 
-GHS <- function(formula, G=NA, H=NA, S=NA, T=298.15, E_units = "cal") {
-  # for all NA in G, H and S, do nothing
-  # for no  NA in G, H and S, do nothing
-  # for one NA in G, H and S, calculate its value from the other two:
+GHS <- function(formula, G = NA, H = NA, S = NA, T = 298.15, E_units = "J") {
+  # For all NA in G, H and S, do nothing
+  # For no  NA in G, H and S, do nothing
+  # For one NA in G, H and S, calculate its value from the other two:
   # G - standard molal Gibbs energy of formation from the elements
   # H - standard molal enthalpy of formation from the elements
   # S - standard molal entropy
@@ -115,13 +115,13 @@
     if(is.na(G)) G <- H - T * (S - Se)
     else if(is.na(H)) H <- G + T * (S - Se)
     else if(is.na(S)) S <- (H - G) / T + Se
-    return(list(G, H, S))
+    list(G, H, S)
   })
   # Turn the list into a matrix and add labels
   GHS <- t(sapply(GHS, c))
   colnames(GHS) <- c("G", "H", "S")
   rownames(GHS) <- formula
-  return(GHS)
+  GHS
 }
 
 ZC <- function(formula) {

Modified: pkg/CHNOSZ/inst/tinytest/test-util.R
===================================================================
--- pkg/CHNOSZ/inst/tinytest/test-util.R	2023-03-04 02:02:13 UTC (rev 773)
+++ pkg/CHNOSZ/inst/tinytest/test-util.R	2023-03-04 02:41:46 UTC (rev 774)
@@ -25,14 +25,14 @@
 expect_equal(coe$S, GHS[[3]], info = info)
 ## Mass and entropy of elements in chemical formulas
 # The "-1" is a single negative charge, the electron
-testform <- c("CH4", "H2O", "-1")
-testmass <- mass(testform)
-testent <- convert(entropy(testform), "cal")
-expect_equal(testmass, c(16.04276, 18.01528, 0), info = info)
-expect_equal(testent, c(63.83843212237, 55.74952198853, 15.61663479924), info = info)
+formula <- c("CH4", "H2O", "-1")
+calcmass <- mass(formula)
+calcS <- convert(entropy(formula), "cal")
+expect_equal(calcmass, c(16.04276, 18.01528, 0), info = info)
+expect_equal(calcS, c(63.83843212237, 55.74952198853, 15.61663479924), info = info)
 # Another way to calculate the entropy of the elements in H2O
-testGHS <- GHS("H2O", G = 0, H = 0)
-expect_equal(as.numeric(testGHS[1, 3]), testent[2], info = info)
+calcGHS <- GHS("H2O", G = 0, H = 0, E_units = "cal")
+expect_equal(as.numeric(calcGHS[1, 3]), calcS[2], info = info)
   
 info <- "[P|T|E].units() do not accept invalid units"
 expect_error(P.units("X"), "units of pressure must be either bar or MPa", info = info)

Modified: pkg/CHNOSZ/man/NaCl.Rd
===================================================================
--- pkg/CHNOSZ/man/NaCl.Rd	2023-03-04 02:02:13 UTC (rev 773)
+++ pkg/CHNOSZ/man/NaCl.Rd	2023-03-04 02:41:46 UTC (rev 774)
@@ -85,7 +85,7 @@
 }
 
 \references{
-Shvarov, Y. and Bastrakov, E. (1999) HCh: A software package for geochemical equilibrium modelling. User's Guide. \emph{Australian Geological Survey Organisation} \bold{1999/25}. \url{http://pid.geoscience.gov.au/dataset/ga/25473}
+Shvarov, Y. and Bastrakov, E. (1999) HCh: A software package for geochemical equilibrium modelling. User's Guide. \emph{Australian Geological Survey Organisation} \bold{1999/25}. \url{https://pid.geoscience.gov.au/dataset/ga/25473}
 }
 
 \concept{Extended workflow}

Modified: pkg/CHNOSZ/man/extdata.Rd
===================================================================
--- pkg/CHNOSZ/man/extdata.Rd	2023-03-04 02:02:13 UTC (rev 773)
+++ pkg/CHNOSZ/man/extdata.Rd	2023-03-04 02:41:46 UTC (rev 774)
@@ -109,7 +109,7 @@
 
 Shock, E. L. and Schulte, M. D. (1998) Organic synthesis during fluid mixing in hydrothermal systems. \emph{J. Geophys. Res.} \bold{103}, 28513--28527. \doi{10.1029/98JE02142}
 
-Tai, S. L., Boer, V. M., Daran-Lapujade, P., Walsh, M. C., de Winde, J. H., Daran, J.-M. and Pronk, J. T. (2005) Two-dimensional transcriptome analysis in chemostat cultures: Combinatorial effects of oxygen availability and macronutrient limitation in \emph{Saccharomyces cerevisiae}. \emph{J. Biol. Chem.} \bold{280}, 437--447. \url{https://doi.org/10.1074/jbc.M410573200}
+Tai, S. L., Boer, V. M., Daran-Lapujade, P., Walsh, M. C., de Winde, J. H., Daran, J.-M. and Pronk, J. T. (2005) Two-dimensional transcriptome analysis in chemostat cultures: Combinatorial effects of oxygen availability and macronutrient limitation in \emph{Saccharomyces cerevisiae}. \emph{J. Biol. Chem.} \bold{280}, 437--447. \doi{10.1074/jbc.M410573200}
 
 Tutolo, B. M., Kong, X.-Z., Seyfried, W. E., Jr. and Saar, M. O. (2014) Internal consistency in aqueous geochemical data revisited: Applications to the aluminum system. \emph{Geochim. Cosmochim. Acta} \bold{133}, 216--234. \doi{10.1016/j.gca.2014.02.036}
 

Modified: pkg/CHNOSZ/man/nonideal.Rd
===================================================================
--- pkg/CHNOSZ/man/nonideal.Rd	2023-03-04 02:02:13 UTC (rev 773)
+++ pkg/CHNOSZ/man/nonideal.Rd	2023-03-04 02:41:46 UTC (rev 774)
@@ -241,7 +241,7 @@
 
 Manning, C. E., Shock, E. L. and Sverjensky, D. A. (2013) The chemistry of carbon in aqueous fluids at crustal and upper-mantle conditions: Experimental and theoretical constraints. \emph{Rev. Mineral. Geochem.} \bold{75}, 109--148. \doi{10.2138/rmg.2013.75.5}
 
-Shvarov, Y. and Bastrakov, E. (1999) HCh: A software package for geochemical equilibrium modelling. User's Guide. \emph{Australian Geological Survey Organisation} \bold{1999/25}. \url{http://pid.geoscience.gov.au/dataset/ga/25473}
+Shvarov, Y. and Bastrakov, E. (1999) HCh: A software package for geochemical equilibrium modelling. User's Guide. \emph{Australian Geological Survey Organisation} \bold{1999/25}. \url{https://pid.geoscience.gov.au/dataset/ga/25473}
 }
 
 \concept{Thermodynamic calculations}

Modified: pkg/CHNOSZ/man/subcrt.Rd
===================================================================
--- pkg/CHNOSZ/man/subcrt.Rd	2023-03-04 02:02:13 UTC (rev 773)
+++ pkg/CHNOSZ/man/subcrt.Rd	2023-03-04 02:41:46 UTC (rev 774)
@@ -105,7 +105,7 @@
 \code{subcrt} in this case simultaneously calculates the requested properties of all the phases of each such mineral (phase species) and, using the values of the transition temperatures calculated from those at P = 1 bar given in the thermodynamic database together with functions of the entropies and volumes of transitions (see \code{\link{dPdTtr}}), determines the stable phase of the mineral at any grid point and substitutes the properties of this phase at that point for further calculations.
 If individual phase species of minerals are specified (by \samp{cr}, \samp{cr2} etc. in \code{state}), and \code{exceed.Ttr} is \code{FALSE} (the default), the Gibbs energies of these minerals are assigned values of NA at conditions beyond their transition temperature, where another of the phases is stable.
 If you set \code{exceed.Ttr} to \code{TRUE} to calculate the properties of mineral polymorphs (i.e., using \samp{cr}) the function will identify the stable polymorph using the calculated Gibbs energies of the phase species instead of the tabulated transition temperatures.
-This is not generally advised, since the computed standard molal properties of a phase species lose their physical meaning beyond the transition temperatures of the phase.
+This is not generally advised, as the computed standard molal properties of a phase species lose their physical meaning beyond the transition temperatures of the phase.
 
 }
 

Modified: pkg/CHNOSZ/man/util.expression.Rd
===================================================================
--- pkg/CHNOSZ/man/util.expression.Rd	2023-03-04 02:02:13 UTC (rev 773)
+++ pkg/CHNOSZ/man/util.expression.Rd	2023-03-04 02:41:46 UTC (rev 774)
@@ -172,7 +172,7 @@
 dprop <- describe.property(property[1:2], value[1:2])
 legend(2.4, 3.9, legend=c(dbasis, dprop), bty = "n")
 # describe.reaction
-# Reaction is automatically balanced since basis species are defined
+# Reaction is automatically balanced because basis species are defined
 reaction <- subcrt("glucose", -1)$reaction
 text(3, 4.25, describe.reaction(reaction))
 text(3, 4.5, describe.reaction(reaction, states = "all"))

Modified: pkg/CHNOSZ/man/util.formula.Rd
===================================================================
--- pkg/CHNOSZ/man/util.formula.Rd	2023-03-04 02:02:13 UTC (rev 773)
+++ pkg/CHNOSZ/man/util.formula.Rd	2023-03-04 02:41:46 UTC (rev 774)
@@ -17,7 +17,7 @@
   as.chemical.formula(makeup, drop.zero = TRUE)
   mass(formula)
   entropy(formula)
-  GHS(formula, G = NA, H = NA, S = NA, T = 298.15, E_units = "cal")
+  GHS(formula, G = NA, H = NA, S = NA, T = 298.15, E_units = "J")
   ZC(formula)
   i2A(formula)
 }
@@ -30,7 +30,7 @@
   \item{H}{numeric, standard molal enthalpy of formation from the elements}
   \item{S}{numeric, standard molal molal entropy}
   \item{T}{numeric, temperature in Kelvin}
-  \item{E_units}{character, energy units (cal or J)}
+  \item{E_units}{character, energy units (J or cal)}
 }
 
 \details{
@@ -53,7 +53,7 @@
 \code{GHS} computes one of the standard molal Gibbs energy or enthalpy of formation from the elements, or standard molal entropy, from values of the other two.
 The \code{formula}, \code{G}, \code{H} and \code{S} arguments must all have the same length.
 The entropies of the elements (\code{Se}) in each \code{formula} are calculated using \code{\link{entropy}}, which gives values in Joules.
-If \code{E_units} is \samp{J}, the values are converted to Joules.
+If \code{E_units} is \samp{cal}, the values are converted to calories.
 The equation in effect can be written as \eqn{{\Delta}G^{\circ}={\Delta}H^{\circ}-T{\Delta}S^{\circ}}{delta_G = delta_H - T * delta_S}, where \eqn{{\Delta}S^{\circ}=S-S_e}{delta_S = S - Se} and \eqn{T}{T} is the temperature given in \code{T} (defaults to 298.15 K) (note that \code{G} and \code{H} in the arguments correspond respectively to \eqn{{\Delta}G^{\circ}}{delta_G} and \eqn{{\Delta}H^{\circ}}{delta_H} in the equation).
 For each formula, if one of \code{G}, \code{H}, or \code{S} is NA, its value is calculated from the other two.
 Otherwise, the values are returned unchanged.
@@ -88,9 +88,9 @@
 
 ## Converting among Gibbs energy, enthalpy, entropy
 # Calculate the value of G from H and S
-GHS("H2O", H = water("H"), S = water("S"))[1, ]
-# That's not quite equal to the value from water("G");
-# probably using different entropies of the elements
+GHS("H2O", H = water("H")$H, S = water("S")$S)
+# The result is not exactly equal to the value from water("G"),
+# probably because of different entropies of the elements
 
 ## Average oxidation states of carbon
 ZC(c("CO2", "CH4", "CHNOSZ"))  # 4, -4, 7

Modified: pkg/CHNOSZ/man/util.misc.Rd
===================================================================
--- pkg/CHNOSZ/man/util.misc.Rd	2023-03-04 02:02:13 UTC (rev 773)
+++ pkg/CHNOSZ/man/util.misc.Rd	2023-03-04 02:41:46 UTC (rev 774)
@@ -71,8 +71,8 @@
   # A very small T increment around the transition temperature
   T <- convert(c(T-0.01, T), "C")
   # Use suppressMessages to make the output less crowded
-  substuff <- suppressMessages(subcrt("iron", T = T, P = 1))
-  diff(substuff$out$iron$H)
+  sres <- suppressMessages(subcrt("iron", T = T, P = 1))
+  diff(sres$out$iron$H)
 })
 
 ## Scale logarithms of activity

Modified: pkg/CHNOSZ/vignettes/anintro.Rmd
===================================================================
--- pkg/CHNOSZ/vignettes/anintro.Rmd	2023-03-04 02:02:13 UTC (rev 773)
+++ pkg/CHNOSZ/vignettes/anintro.Rmd	2023-03-04 02:41:46 UTC (rev 774)
@@ -313,8 +313,8 @@
 ```
 
 ```{r subcrt_water_plot, fig.margin=TRUE, fig.width=4, fig.height=4, small.mar=TRUE, dpi=dpi, out.width="100%", echo=FALSE, message=FALSE, fig.cap="Isothermal contours of density (g cm<sup>-3</sup>) and pressure (bar) of water.", cache=TRUE, pngquant=pngquant, timeit=timeit}
-substuff <- subcrt("water", T=seq(0,1000,100), P=c(NA, seq(1,500,1)), grid="T")
-water <- substuff$out$water
+sres <- subcrt("water", T=seq(0,1000,100), P=c(NA, seq(1,500,1)), grid="T")
+water <- sres$out$water
 plot(water$P, water$rho, type = "l")
 ```
 The additional operations (`$out$water`) are used to extract a specific part of the results; this can be used with e.g. R's `write.table()` or `plot()` for further processing:
@@ -1502,8 +1502,8 @@
 With the default settings, thermodynamic properties for H<sub>2</sub>O are derived from SUPCRT92 (Johnson et al., 1992).
 ```
 ```{r thermo_refs_subcrt, message=FALSE}
-substuff <- subcrt(c("C2H5OH", "O2", "CO2", "H2O"), c(-1, -3, 2, 3))
-thermo.refs(substuff)
+sres <- subcrt(c("C2H5OH", "O2", "CO2", "H2O"), c(-1, -3, 2, 3))
+thermo.refs(sres)
 ```
 ```{r width80, include=FALSE}
 ```



More information about the CHNOSZ-commits mailing list