[CHNOSZ-commits] r136 - in pkg/CHNOSZ: . R inst man vignettes
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Mon Feb 6 17:08:42 CET 2017
Author: jedick
Date: 2017-02-06 17:08:42 +0100 (Mon, 06 Feb 2017)
New Revision: 136
Modified:
pkg/CHNOSZ/DESCRIPTION
pkg/CHNOSZ/NAMESPACE
pkg/CHNOSZ/R/util.plot.R
pkg/CHNOSZ/inst/NEWS
pkg/CHNOSZ/man/util.plot.Rd
pkg/CHNOSZ/vignettes/anintro.Rmd
pkg/CHNOSZ/vignettes/vig.bib
Log:
anintro.Rmd: add choosing a different balance
Modified: pkg/CHNOSZ/DESCRIPTION
===================================================================
--- pkg/CHNOSZ/DESCRIPTION 2017-02-06 13:30:10 UTC (rev 135)
+++ pkg/CHNOSZ/DESCRIPTION 2017-02-06 16:08:42 UTC (rev 136)
@@ -1,12 +1,12 @@
Date: 2017-02-06
Package: CHNOSZ
-Version: 1.0.8-25
+Version: 1.0.8-26
Title: Chemical Thermodynamics and Activity Diagrams
Author: Jeffrey Dick
Maintainer: Jeffrey Dick <j3ffdick at gmail.com>
Depends: R (>= 3.1.0)
Suggests: limSolve, testthat, knitr, rmarkdown, tufte
-Imports: grDevices, graphics, stats, utils
+Imports: grDevices, graphics, stats, utils, colorspace
Description: Functions and data sets to support chemical thermodynamic modeling in biochemistry
and low-temperature geochemistry. The features include calculation of the standard molal
thermodynamic properties and chemical affinities of reactions involving minerals and/or
Modified: pkg/CHNOSZ/NAMESPACE
===================================================================
--- pkg/CHNOSZ/NAMESPACE 2017-02-06 13:30:10 UTC (rev 135)
+++ pkg/CHNOSZ/NAMESPACE 2017-02-06 16:08:42 UTC (rev 136)
@@ -16,3 +16,7 @@
importFrom("utils", "browseURL", "capture.output", "combn", "demo",
"example", "head", "installed.packages", "read.csv", "tail",
"write.csv", "write.table")
+
+# Imports from colorspace
+importFrom("colorspace", "diverge_hcl")
+
Modified: pkg/CHNOSZ/R/util.plot.R
===================================================================
--- pkg/CHNOSZ/R/util.plot.R 2017-02-06 13:30:10 UTC (rev 135)
+++ pkg/CHNOSZ/R/util.plot.R 2017-02-06 16:08:42 UTC (rev 136)
@@ -230,3 +230,14 @@
# add axis label
mtext(axis.label(property),1,3)
}
+
+# get colors for range of ZC values 20170206
+ZC.col <- function(z) {
+ # scale values to [1, 1000]
+ z <- z * 999/diff(range(z))
+ z <- round(z - min(z)) + 1
+ # diverging (blue - light grey - red) palette
+ dcol <- colorspace::diverge_hcl(1000, c = 100, l = c(50, 90), power = 1)
+ # reverse the palette so red is at lower ZC (more reduced)
+ rev(dcol)[z]
+}
Modified: pkg/CHNOSZ/inst/NEWS
===================================================================
--- pkg/CHNOSZ/inst/NEWS 2017-02-06 13:30:10 UTC (rev 135)
+++ pkg/CHNOSZ/inst/NEWS 2017-02-06 16:08:42 UTC (rev 136)
@@ -1,4 +1,4 @@
-CHANGES IN CHNOSZ 1.0.8-25 (2017-02-06)
+CHANGES IN CHNOSZ 1.0.8-26 (2017-02-06)
---------------------------------------
- Add "AA" as a keyword for preset species in basis() (cysteine,
@@ -49,6 +49,9 @@
- Remove HTCC1062.faa.xz.
+- Add ZC.col() for generating a red-grey-blue color scale from
+ numeric values.
+
CHANGES IN CHNOSZ 1.0.8 (2016-05-28)
------------------------------------
Modified: pkg/CHNOSZ/man/util.plot.Rd
===================================================================
--- pkg/CHNOSZ/man/util.plot.Rd 2017-02-06 13:30:10 UTC (rev 135)
+++ pkg/CHNOSZ/man/util.plot.Rd 2017-02-06 16:08:42 UTC (rev 136)
@@ -8,10 +8,11 @@
\alias{water.lines}
\alias{mtitle}
\alias{residualsplot}
+\alias{ZC.col}
\title{Functions to Create and Modify Plots}
\description{
- Initialize a new plot window using preset parameters, open a postcript file for plotting, add an axis or title to a plot, generate labels for plot axes and for identification of subplots and physical and chemical conditions, add stability lines for water to a diagram.
+ Initialize a new plot window using preset parameters, open a postcript file for plotting, add an axis or title to a plot, generate labels for plot axes and for identification of subplots and physical and chemical conditions, add stability lines for water to a diagram, get colors for set of values.
}
@@ -33,6 +34,7 @@
col = par("fg"), xpoints = NULL, O2state="gas")
mtitle(main, line=0, ...)
residualsplot(residuals, property = "Cp", model = "big")
+ ZC.col(z)
}
\arguments{
@@ -74,6 +76,7 @@
\item{residuals}{numeric, named vector of residuals to plot}
\item{property}{character, name of property}
\item{model}{character, name of model to use in plot title}
+ \item{z}{numeric, set of values}
}
\details{
@@ -103,6 +106,10 @@
\code{residualsplot} produces a \code{\link{barchart}} with options useful for plotting residuals of group contribution models for thermodynamic properties. It plots horizontal bars stacked with largest on top. The names of the \code{residuals} argument (i.e., the names of model species) are plotted across from each respective bar. The axis title is taken from the \code{property} (probably \samp{Cp} or \samp{V}), and the plot title includes the \code{model} name. See the \sQuote{xadditivity} vignette for examples of these plots.
+\code{ZC.col} returns colors from a diverging palette (red - light grey - blue) corresponding to the values in \code{z}.
+Red is associated with lower values of \code{z}.
+This function is intended to generate colors for distinguishing average oxidation state of carbon \code{\link{ZC}}, but any numeric values can be supplied.
+
}
\section{Side Effects}{
Modified: pkg/CHNOSZ/vignettes/anintro.Rmd
===================================================================
--- pkg/CHNOSZ/vignettes/anintro.Rmd 2017-02-06 13:30:10 UTC (rev 135)
+++ pkg/CHNOSZ/vignettes/anintro.Rmd 2017-02-06 16:08:42 UTC (rev 136)
@@ -42,12 +42,12 @@
})
```
-# About
+# First steps
This document introduces the basic functionality of CHNOSZ, a package for the [R software environment](http://r-project.org).
For more information on R, see "An Introduction to R" and other documents in [The R Manuals](http://cran.r-project.org/manuals.html).
-CHNOSZ has been developed since 2006 to support research projects in geochemistry and biochemistry.
+CHNOSZ has been developed since 2006 to support research projects in geochemistry and compositional biology.
The package provides functions and an extensive thermodynamic database that can be used to calculate the stoichiometric and energetic properties of reactions among minerals and organic or inorganic aqueous species.
These same functions enable calculations of chemical affinities and metastable equilibrium for systems of proteins.
@@ -55,7 +55,8 @@
If you have just installed R for the first time, installing CHNOSZ should be as simple as selecting the "Install packages from CRAN" or similar menu item in the R GUI or using the following command to start the package installation process:
```{marginfigure}
-Or, install the package from a local package file, which you can download from [CRAN](https://cran.r-project.org/package=CHNOSZ) or from the [CHNOSZ website](http://chnosz.net/download).
+Or, install the package from a package file, which you can download from [CRAN](https://cran.r-project.org/package=CHNOSZ) or from the [CHNOSZ website](http://chnosz.net/download).
+This vignette depends on some features that are only available in the development version of CHNOSZ, which can be found at [R-Forge](https://r-forge.r-project.org/projects/chnosz/).
```
```{r install_CHNOSZ, eval=FALSE}
install.packages("CHNOSZ")
@@ -448,6 +449,11 @@
By *formation reaction* is meant the stoichiometric requirements for formation of one mole of any species from the basis species.
The <span style="color:red">`species()`</span> function is used to set these *species of interest*.
Let's consider the stoichiometry of some aqueous sulfur-bearing species.
+Here we use <span style="color:red">`basis()`</span> with a keyword to identify a preset basis definition.
+```{marginfigure}
+Possible keywords are `CHNOS` (including CO<sub>2</sub>, H<sub>2</sub>O, NH<sub>3</sub>, H<sub>2</sub>S, and O<sub>2</sub>), `CHNOS+` (also including H<sup>+</sup>), `CHNOSe` (including H<sup>+</sup>, and *e*<sup>-</sup> instead of O<sub>2</sub>).
+See <span style="color:blue">?basis</span> for more options.
+```
```{r basis_CHNOSZ, results="hide"}
basis("CHNOS+")
```
@@ -455,7 +461,6 @@
species(c("H2S", "HS-", "HSO4-", "SO4-2"))
```
-There we used <span style="color:red">`basis()`</span> with a keyword to identify a preset basis definition.
Now, we can use `affinity()` to calculate the affinities of the formation reactions of each of the species:
```{marginfigure}
The values returned by `affinity()` are dimensionless, i.e. log<sub>10</sub>(**_A_**/*RT*).
@@ -710,7 +715,7 @@
```
Instead, it assumes that the total activity of species in the system is set by the activity of *one* basis species.
```{marginfigure}
-Because activity coefficients are assumed to be zero, activities are additive and we can refer to "total activity".
+Because activity coefficients are assumed to be zero, activities are equal to concentration and we can refer to "total activity".
```
This balanced basis species must be present (with a positive or negative coefficient) in the formation reactions of all species considered.
@@ -787,10 +792,45 @@
[SMS98]
-## Choosing different balancing constraints
+## Choosing a different balance
-amino acids: [Sho90b]
+How about the choice between balancing constraints?
+Let's look at some amino acids in a hypothetical metastable equilibrium.
+This calculation is similar to one presented by @Sho90b for five amino acids, but here we include 20 proteinogenic amino acids, whose names are returned by `aminoacids("")`.
+We use `ZC.col()` to generate colors based on the average oxidation state of carbon of the amino acids (red and blue for relatively reduced and oxidized).
+```{r aminoacids_setup, results="hide", message=FALSE}
+basis("CHNOS")
+basis("CO2", "gas")
+swap.basis("NH3", "N2")
+species(aminoacids(""))
+a <- affinity(O2=c(-50, -25), CO2=c(-10, 15), T=250, P=265)
+aa.ZC <- ZC(info(aminoacids("")))
+col <- ZC.col(aa.ZC)
+```
+To make plots using different balance constraints, let's write a simple function that sets the `balance` argument of `diagram()` and adds a title to the plot.
+The first plot is the most similar to Figure 4 of Shock (1990), except for the absence of alanine (probably due to different thermodynamic data) and the presence of some other amino acids.
+There, we set `balance=1`, which indicates that moles of species are conserved; this is equivalent to balancing on the amino acid backbone.
+The remaining plots balance on each of the basis species (except for O<sub>2</sub>), then on volume (in the last plot).
+```{r aafun, fig.fullwidth=TRUE, fig.width=12.5, fig.height=2.5, small.mar=TRUE, dpi=50, out.width="100%", message=FALSE, results="hide", cache=TRUE}
+aafun <- function(balance) {
+ diagram(a, balance=balance, fill=col)
+ title(main=paste("balanced on", balance))
+}
+par(mfrow=c(1, 5))
+lapply(c("1", "CO2", "H2O", "N2", "volume"), aafun)
+```
+
+There are some broad similarities---increasing log*f*<sub>O<sub>2</sub></sub> favors more oxidized amino acids---but also substantial differences.
+It is interesting that there is more "going on" in the middle part of the digram showing volume conservation.
+
+Caveat: these plots demonstrate some possibilities in CHNOSZ and are not necessarily realistic portrayals of this system.
+It does seem odd to balance on a fugacious component like O<sub>2</sub> or H<sub>2</sub>O.
+Unlike different choices of basis species, which are thermodynamically equivalent (see the example above for a mineral system), the choice of balance reflects extra-thermodynamic factors.
+For instance, the widespread rule of thumb for balancing mineral reactions on a component is unrealistic for processes where volume is conserved [@MC11].
+Any choice of balancing constraints may oversimplify the physical or biological context for reactions of organic species or biomolecules.
+While choosing an inappropriate balance leads to infeasible models, a well-considered overview of the possibilities might offer insight into the conditions affecting the dynamics of some systems.
+
# Proteins
## Sources of amino acid data
@@ -799,15 +839,11 @@
## Normalizing for different lengths
-[Dic08]
-
## Compositional analysis (ZC)
-[Dic14]
-
# Modifying the database
-mod.obigt, mod.buffer
+mod.obigt, mod.buffer, OBIGT-2
# Functions outside of the main workflow
Modified: pkg/CHNOSZ/vignettes/vig.bib
===================================================================
--- pkg/CHNOSZ/vignettes/vig.bib 2017-02-06 13:30:10 UTC (rev 135)
+++ pkg/CHNOSZ/vignettes/vig.bib 2017-02-06 16:08:42 UTC (rev 136)
@@ -20,21 +20,6 @@
url = {http://www.worldcat.org/oclc/12106344},
}
- at Article{DLE64,
- author = {Dayhoff, M. O. and Lippincott, E. R. and Eck, R. V.},
- journal = {Science},
- title = {Thermodynamic equilibria in prebiological atmospheres},
- year = {1964},
- volume = {146},
- number = {3650},
- pages = {1461--1464},
- doi = {10.1126/science.146.3650.1461},
- sn = {0036-8075},
- z8 = {0},
- z9 = {60},
- zb = {13},
-}
-
@TechReport{DLEN67,
author = {Dayhoff, M. O. and Lippincott, E. R. and Eck, R. V. and Nagarajan, G.},
title = {Thermodynamic equilibrium in prebiological atmospheres of {C}, {H}, {O}, {N}, {P}, {S}, and {C}l},
@@ -165,6 +150,19 @@
doi = {10.2138/rmg.2013.75.5},
}
+ at Article{MC11,
+ author = {Merino, Enrique and Canals, Àngels},
+ journal = {American Journal of Science},
+ title = {Self-accelerating dolomite-for-calcite replacement: Self-organized dynamics of burial dolomitization and associated mineralization},
+ year = {2011},
+ volume = {311},
+ number = {7},
+ pages = {573--607},
+ doi = {10.2475/07.2011.01},
+ sn = {0002-9599},
+ z9 = {0},
+}
+
@InProceedings{NPW_79,
author = {Nordstrom, D. K. and Plummer, L. N. and Wigley, T. M. L. and Wolery, T. J. and Ball, J. W. and Jenne, E. A. and Bassett, R. L. and Crerar, D. A. and Florence, T. M. and Fritz, B. and Hoffman, M. and Holdren, G. R., Jr. and Lafon, G. M. and Mattigod, S. V. and McDuff, R. E. and Morel, F. and Reddy, M. M. and Sposito, G. and Thrailkill, J.},
title = {A comparison of computerized chemical models for equilibrium calculations in aqueous systems},
@@ -257,6 +255,18 @@
sn = {1468-8115},
}
+ at Article{Sho90b,
+ author = {Shock, Everett L.},
+ journal = {Geochimica et Cosmochimica Acta},
+ title = {{D}o amino acids equilibrate in hydrothermal fluids?},
+ year = {1990},
+ volume = {54},
+ number = {4},
+ pages = {1185--1189},
+ doi = {10.1016/0016-7037(90)90450-Y},
+ issn = {0016-7037},
+}
+
@Article{SH90,
author = {Shock, Everett L. and Helgeson, Harold C.},
journal = {Geochimica et Cosmochimica Acta},
More information about the CHNOSZ-commits
mailing list