From 350f2f41c0202cd1ea533dc44986f66c83256d2e Mon Sep 17 00:00:00 2001 From: Jeffrey Dick Date: Wed, 29 Nov 2023 12:01:48 +0000 Subject: [PATCH] Use environment variable to control vignette size git-svn-id: svn://scm.r-forge.r-project.org/svnroot/chnosz/pkg/CHNOSZ@818 edb9625f-4e0d-4859-8d74-9fd3b1da38cb --- DESCRIPTION | 2 +- inst/CHECKLIST | 8 +++---- inst/NEWS.Rd | 7 +++++- vignettes/FAQ.Rmd | 13 +++++++---- vignettes/anintro.Rmd | 42 ++++++++++++++++++---------------- vignettes/custom_data.Rmd | 10 ++++---- vignettes/eos-regress.Rmd | 22 ++++++++++-------- vignettes/equilibrium.Rmd | 12 ++++++---- vignettes/multi-metal.Rmd | 48 +++++++++++++++++++++------------------ 9 files changed, 91 insertions(+), 73 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index ebc0fd6..45a8ab7 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Date: 2023-11-29 Package: CHNOSZ -Version: 2.0.0-37 +Version: 2.0.0-38 Title: Thermodynamic Calculations and Diagrams for Geochemistry Authors@R: c( person("Jeffrey", "Dick", , "j3ffdick@gmail.com", role = c("aut", "cre"), diff --git a/inst/CHECKLIST b/inst/CHECKLIST index e3cd842..8b848f1 100644 --- a/inst/CHECKLIST +++ b/inst/CHECKLIST @@ -1,6 +1,6 @@ **************************** Release checklist for CHNOSZ - (updated 2023-03-10) + (updated 2023-11-29) **************************** - Run examples() and demos() and inspect their output (especially plots) @@ -73,11 +73,9 @@ exit_file("Skipping tests so development builds on R-Forge work") Making vignettes for website (https://chnosz.net) ************************************************* -- Use dpi <- 72 in anintro.Rmd +- Build package after setting CHNOSZ_BUILD_LARGE_VIGNETTES environment variable. -- Use hires <- TRUE in multi-metal.Rmd - -- After making vignettes, run doc/mklinks.sh in installed directory +- Install the package and run doc/mklinks.sh within the installation directory. (this adds links to the HTML renditions of Rd files) *************** diff --git a/inst/NEWS.Rd b/inst/NEWS.Rd index 4c31bbb..1a33cf6 100644 --- a/inst/NEWS.Rd +++ b/inst/NEWS.Rd @@ -15,7 +15,7 @@ \newcommand{\Cp}{\ifelse{latex}{\eqn{C_P}}{\ifelse{html}{\out{CP}}{Cp}}} \newcommand{\DG0}{\ifelse{latex}{\eqn{{\Delta}G^{\circ}}}{\ifelse{html}{\out{ΔG°}}{ΔG°}}} -\section{Changes in CHNOSZ version 2.0.0-36 (2023-11-29)}{ +\section{Changes in CHNOSZ version 2.0.0-38 (2023-11-29)}{ \itemize{ @@ -74,6 +74,11 @@ vaporization, or decomposition). The temperature limit for \Cp equations is stored as the opposite (negative) value in OBIGT. See \viglink{FAQ} for details. + + \item The environment variable CHNOSZ_BUILD_LARGE_VIGNETTES is used to + control `dpi` in knitr chunk options. Setting this variable results in + larger vignettes (used for the CHNOSZ website); if this variable is unset + (as on CRAN), a smaller package is built. } diff --git a/vignettes/FAQ.Rmd b/vignettes/FAQ.Rmd index 713b8f0..3118636 100644 --- a/vignettes/FAQ.Rmd +++ b/vignettes/FAQ.Rmd @@ -135,8 +135,11 @@ knitr::knit_hooks$set( '', sep = '\n') } ) + # Set dpi 20231129 -dpi <- 72 +knitr::opts_chunk$set( + dpi = if(nzchar(Sys.getenv("CHNOSZ_BUILD_LARGE_VIGNETTES"))) 100 else 72 +) ``` ```{r echo = F, cache = F} @@ -333,7 +336,7 @@ reset() ``` -```{r DEW_Ctot, echo = FALSE, message = FALSE, results = "hide", fig.width = 8, fig.height = 4, out.width = "100%", fig.align = "center", pngquant = pngquant, cache = TRUE, dpi = dpi} +```{r DEW_Ctot, echo = FALSE, message = FALSE, results = "hide", fig.width = 8, fig.height = 4, out.width = "100%", fig.align = "center", pngquant = pngquant, cache = TRUE} ``` *Added on 2023-05-17.* @@ -495,7 +498,7 @@ for(property in c("G", "H", "S", "Cp")) { reset() ``` -```{r pyrrhotite_T, echo = FALSE, message = FALSE, results = "hide", fig.width = 8, fig.height = 2.5, out.width = "100%", fig.align = "center", pngquant = pngquant, dpi = dpi} +```{r pyrrhotite_T, echo = FALSE, message = FALSE, results = "hide", fig.width = 8, fig.height = 2.5, out.width = "100%", fig.align = "center", pngquant = pngquant} ``` For additional polymorphs, we could repeat the above procedure using polymorph 2 as the starting point to calculate `G`, `H`, and `S` of polymorph 3, and so on. @@ -673,7 +676,7 @@ OBIGT() Here are the three plots that we made: -```{r trisulfur, echo = FALSE, message = FALSE, results = "hide", fig.width = 10, fig.height = 3.33, out.width = "100%", out.extra='class="full-width"', pngquant = pngquant, cache = TRUE, dpi = dpi} +```{r trisulfur, echo = FALSE, message = FALSE, results = "hide", fig.width = 10, fig.height = 3.33, out.width = "100%", out.extra='class="full-width"', pngquant = pngquant, cache = TRUE} ``` *Added on 2023-09-08.* @@ -802,7 +805,7 @@ title("Mineral data from Helgeson et al. (1978)\n(as used in SUPCRT92)", font.main = 1, cex.main = 0.9) OBIGT() ``` -```{r KMQ_diagram, message = FALSE, fig.width = 8, fig.height = 4, out.width = "100%", results = "hide", echo = FALSE, dpi = dpi} +```{r KMQ_diagram, message = FALSE, fig.width = 8, fig.height = 4, out.width = "100%", results = "hide", echo = FALSE} ``` The gray area, which is automatically drawn by `diagram()`, is below the reducing stability limit of water; that is, this area is where the equilibrium fugacity of `r H2` exceeds unity. diff --git a/vignettes/anintro.Rmd b/vignettes/anintro.Rmd index 9ca22b3..d3a7e6e 100644 --- a/vignettes/anintro.Rmd +++ b/vignettes/anintro.Rmd @@ -81,9 +81,11 @@ pngquant <- "--speed=1 --quality=0-25" # pngquant isn't available on R-Forge ... if (!nzchar(Sys.which("pngquant"))) pngquant <- NULL -## Use a low resolution to save space in the package -# Change this to 72 to make higher-resolution images for the CHNOSZ web page -dpi <- 50 +# Set dpi 20231129 +knitr::opts_chunk$set( + dpi = if(nzchar(Sys.getenv("CHNOSZ_BUILD_LARGE_VIGNETTES"))) 72 else 50 +) +hidpi = if(nzchar(Sys.getenv("CHNOSZ_BUILD_LARGE_VIGNETTES"))) 100 else 50 ## http://stackoverflow.com/questions/23852753/knitr-with-gridsvg ## Set up a chunk hook for manually saved plots. @@ -312,7 +314,7 @@ Here, we calculate the properties of `r h2o` on a *T*, *P* grid in the supercrit subcrt("water", T = c(400, 500, 600), P = c(200, 400, 600), grid = "P")$out$water ``` -```{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-3) and pressure (bar) of water.", cache=TRUE, pngquant=pngquant, timeit=timeit} +```{r subcrt_water_plot, fig.margin=TRUE, fig.width=4, fig.height=4, small.mar=TRUE, out.width="100%", echo=FALSE, message=FALSE, fig.cap="Isothermal contours of density (g cm-3) and pressure (bar) of water.", cache=TRUE, pngquant=pngquant, timeit=timeit} 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") @@ -370,7 +372,7 @@ CO <- subcrt(c("CO", "CO"), c("gas", "aq"), c(-1, 1), T = T)$out$logK CH4 <- subcrt(c("CH4", "CH4"), c("gas", "aq"), c(-1, 1), T = T)$out$logK logK <- data.frame(T, CO2, CO, CH4) ``` -```{r CO2_plot, fig.margin=TRUE, fig.width=4, fig.height=4, small.mar=TRUE, dpi=dpi, out.width="100%", echo=FALSE, message=FALSE, fig.cap="Calculated equilibrium constants for dissolution of CO2, CO, and CH4.", cache=TRUE, pngquant=pngquant, timeit=timeit} +```{r CO2_plot, fig.margin=TRUE, fig.width=4, fig.height=4, small.mar=TRUE, out.width="100%", echo=FALSE, message=FALSE, fig.cap="Calculated equilibrium constants for dissolution of CO2, CO, and CH4.", cache=TRUE, pngquant=pngquant, timeit=timeit} matplot(logK[, 1], logK[, -1], type = "l", col = 1, lty = 1, xlab = axis.label("T"), ylab = axis.label("logK")) text(80, -1.7, expr.species("CO2")) @@ -439,7 +441,7 @@ acetoclastic <- subcrt(c("acetate", "CH4"), c(-1, 1)) Use `describe.reaction()` to write the reactions on a plot: -```{r describe_reaction_plot, fig.margin=TRUE, fig.width=3.5, fig.height=1.8, tiny.mar=TRUE, dpi=dpi, out.width="100%", pngquant=pngquant, timeit=timeit} +```{r describe_reaction_plot, fig.margin=TRUE, fig.width=3.5, fig.height=1.8, tiny.mar=TRUE, out.width="100%", pngquant=pngquant, timeit=timeit} plot(0, 0, type = "n", axes = FALSE, ann=FALSE, xlim=c(0, 5), ylim=c(5.2, -0.2)) text(0, 0, "acetoclastic methanogenesis", adj = 0) text(5, 1, describe.reaction(acetoclastic$reaction), adj = 1) @@ -502,7 +504,7 @@ We insert an empty reaction to get a line at zero affinity. R's `do.call()` and `rbind()` are used to turn the list into a data frame that can be plotted with R's `matplot()`. There, we plot the negative affinities, equal to Gibbs energy, as shown in the plot of Mayumi et al. (2013). -```{r methanogenesis_plot, fig.margin=TRUE, fig.width=4.1, fig.height=4.1, small.mar=TRUE, dpi=dpi, out.width="100%", echo=FALSE, message=FALSE, fig.cap="Gibbs energies of acetate oxidation and methanogenesis (after Mayumi et al., 2013).", cache=TRUE, pngquant=pngquant, timeit=timeit} +```{r methanogenesis_plot, fig.margin=TRUE, fig.width=4.1, fig.height=4.1, small.mar=TRUE, out.width="100%", echo=FALSE, message=FALSE, fig.cap="Gibbs energies of acetate oxidation and methanogenesis (after Mayumi et al., 2013).", cache=TRUE, pngquant=pngquant, timeit=timeit} Adat <- lapply(c(-3, 3), function(logfCO2) { basis("CO2", logfCO2) data.frame(logfCO2, @@ -568,7 +570,7 @@ The result is equivalent to a "predominance diagram" [@Dic19], where the fields If both aqueous species and minerals are present, it is common practice to assign a constant activity to all aqueous species and unit activity (i.e. log activity = 0) for minerals. More sophisticated diagrams can be made by showing the solubility contours of a metal on the diagram; see [`demo(contour)`](../demo) for an example. -```{r EhpH_plot, fig.margin=TRUE, fig.width=4, fig.height=4, dpi=dpi, out.width="100%", echo = FALSE, message=FALSE, cache=TRUE, fig.cap="Aqueous sulfur species at 25 °C.", pngquant=pngquant, timeit=timeit} +```{r EhpH_plot, fig.margin=TRUE, fig.width=4, fig.height=4, out.width="100%", echo = FALSE, message=FALSE, cache=TRUE, fig.cap="Aqueous sulfur species at 25 °C.", pngquant=pngquant, timeit=timeit} a <- affinity(pH = c(0, 12), Eh = c(-0.5, 1)) diagram(a, limit.water = TRUE) ``` @@ -580,7 +582,7 @@ The names of species that can be parsed as chemical formulas are formatted with ```{r EhpH_plot, echo=TRUE, eval=FALSE} ``` -```{r EhpH_plot_color, fig.margin=TRUE, fig.width=4, fig.height=4, smallish.mar=TRUE, dpi=dpi, out.width="100%", echo=FALSE, message=FALSE, cache=TRUE, fig.cap="The same plot, with different colors and labels.", pngquant=pngquant, timeit=timeit} +```{r EhpH_plot_color, fig.margin=TRUE, fig.width=4, fig.height=4, smallish.mar=TRUE, out.width="100%", echo=FALSE, message=FALSE, cache=TRUE, fig.cap="The same plot, with different colors and labels.", pngquant=pngquant, timeit=timeit} diagram(a, fill = "terrain", lwd = 2, lty = 3, names = c("hydrogen sulfide", "bisulfide", "bisulfate", "sulfate"), las = 0) @@ -617,7 +619,7 @@ retrieve("Mn", c("O", "H"), "cr") Below, these commands are used to identify the species in an Eh-pH diagram for the Mn-O-H system at 100 °C. This diagram includes Mn oxides (pyrolusite, bixbyite, hausmannite), Mn(OH)2, and aqueous Mn species. -```{r retrieve_diagram, fig.margin=TRUE, fig.width=5, fig.height=5, dpi=dpi, out.width="100%", message=FALSE, results = "hide", cache=TRUE, fig.cap="Eh-pH diagram for the Mn-O-H system.", pngquant=pngquant, timeit=timeit} +```{r retrieve_diagram, fig.margin=TRUE, fig.width=5, fig.height=5, out.width="100%", message=FALSE, results = "hide", cache=TRUE, fig.cap="Eh-pH diagram for the Mn-O-H system.", pngquant=pngquant, timeit=timeit} # Set decimal logarithm of activity of aqueous species, # temperature and plot resolution logact <- -4 @@ -688,7 +690,7 @@ The other arguments, like those of `affinity()` The first call to `diagram()` plots the species of interest; the second adds the predominance fields of the basis species. We also use `water.lines()` to draw dashed blue lines at the water stability limits: -```{r copper_mosaic, fig.margin=TRUE, fig.width=4, fig.height=4, dpi=dpi, out.width="100%", message=FALSE, cache=TRUE, fig.cap="Copper minerals and aqueous complexes with chloride, 200 °C.", pngquant=pngquant, timeit=timeit} +```{r copper_mosaic, fig.margin=TRUE, fig.width=4, fig.height=4, out.width="100%", message=FALSE, cache=TRUE, fig.cap="Copper minerals and aqueous complexes with chloride, 200 °C.", pngquant=pngquant, timeit=timeit} T <- 200 res <- 200 bases <- c("H2S", "HS-", "HSO4-", "SO4-2") @@ -758,7 +760,7 @@ a$values <- lapply(a$values, convert, "cal") a$values <- lapply(a$values, `*`, -0.001) ``` -```{r rainbow_diagram, fig.margin=TRUE, fig.width=4, fig.height=4, dpi=dpi, out.width="100%", echo=FALSE, message=FALSE, cache=TRUE, fig.cap="Affinities of organic synthesis in a hydrothermal system, after Shock and Canovas (2010).", pngquant=pngquant, timeit=timeit} +```{r rainbow_diagram, fig.margin=TRUE, fig.width=4, fig.height=4, out.width="100%", echo=FALSE, message=FALSE, cache=TRUE, fig.cap="Affinities of organic synthesis in a hydrothermal system, after Shock and Canovas (2010).", pngquant=pngquant, timeit=timeit} diagram(a, balance = 1, ylim = c(-100, 100), ylab = quote(italic(A)*", kcal/mol"), col = rainbow(8), lwd = 2, bg = "slategray3") abline(h = 0, lty = 2, lwd = 2) @@ -821,7 +823,7 @@ unlist(affinity(T = 300, P = 100, return.buffer = TRUE)[1:3]) ``` -```{r demo_buffer_noecho, fig.margin=TRUE, fig.width=4, fig.height=4, dpi=dpi, out.width="100%", message=FALSE, echo=FALSE, cache=TRUE, fig.cap="Values of logfH2 corresponding to mineral buffers or to given activities of aqueous species.", pngquant=pngquant, timeit=timeit} +```{r demo_buffer_noecho, fig.margin=TRUE, fig.width=4, fig.height=4, out.width="100%", message=FALSE, echo=FALSE, cache=TRUE, fig.cap="Values of logfH2 corresponding to mineral buffers or to given activities of aqueous species.", pngquant=pngquant, timeit=timeit} demo(buffer, echo = FALSE) ``` Et voilà! We have found log*a*H2S and `r logfO2` that are compatible with the coexistence of the three minerals. @@ -864,7 +866,7 @@ The `equilibrate()` function in CHNOSZ automati The method based on the Boltzmann equation is fast, but is applicable only to systems where the coefficient on the balanced basis species in each of the formation reactions is one. The reaction-matrix method is slower, but can be applied to systems were the balanced basis species has reaction coefficients other than one. -```{r bjerrum_diagram, fig.margin=TRUE, fig.width=3, fig.height=6, dpi=dpi, out.width="100%", echo=FALSE, results="hide", message=FALSE, cache=TRUE, fig.cap="Three views of carbonate speciation: affinity, activity, degree of formation.", pngquant=pngquant, timeit=timeit} +```{r bjerrum_diagram, fig.margin=TRUE, fig.width=3, fig.height=6, out.width="100%", echo=FALSE, results="hide", message=FALSE, cache=TRUE, fig.cap="Three views of carbonate speciation: affinity, activity, degree of formation.", pngquant=pngquant, timeit=timeit} par(mfrow = c(3, 1)) basis("CHNOS+") species(c("CO2", "HCO3-", "CO3-2")) @@ -922,7 +924,7 @@ An additional argument, `in.terms.of`, is used to compute the total molality of `diagram()` is used twice, first to plot the total molality of Al, then the concentrations of the individual species, using `adj` and `dy` to adjust the positions of labels in the *x*- and *y*-directions. At the end of the calculation, we use `reset()` to restore the default thermodynamic database. -```{r corundum, fig.margin=TRUE, fig.width=4, fig.height=4, dpi=dpi, out.width="100%", results="hide", message=FALSE, cache=TRUE, fig.cap="Solubility of corundum (green line) and equilibrium concentrations of aqueous species (black lines).", pngquant=pngquant, timeit=timeit} +```{r corundum, fig.margin=TRUE, fig.width=4, fig.height=4, out.width="100%", results="hide", message=FALSE, cache=TRUE, fig.cap="Solubility of corundum (green line) and equilibrium concentrations of aqueous species (black lines).", pngquant=pngquant, timeit=timeit} add.OBIGT("SLOP98") basis(c("Al+3", "H2O", "H+", "O2")) species("corundum") @@ -1098,7 +1100,7 @@ This is similar to Figure 1.5 of Alberty (2003): ```

-```{r ATP, fig.fullwidth=TRUE, fig.width=10, fig.height=2.5, dpi=ifelse(dpi==50, 50, 100), out.width="100%", echo=FALSE, message=FALSE, results="hide", fig.cap="Binding of H+ and Mg+2 to ATP at 100 °C and *I* = 0 M (first plot) or *I* = 0.25 M (third and fourth plots).", cache=TRUE, pngquant=pngquant, timeit=timeit} +```{r ATP, fig.fullwidth=TRUE, fig.width=10, fig.height=2.5, dpi=hidpi, out.width="100%", echo=FALSE, message=FALSE, results="hide", fig.cap="Binding of H+ and Mg+2 to ATP at 100 °C and *I* = 0 M (first plot) or *I* = 0.25 M (third and fourth plots).", cache=TRUE, pngquant=pngquant, timeit=timeit} ```

@@ -1156,7 +1158,7 @@ subcrt("LYSC_CHICK")$out[[1]][1:6, ] Let's compare experimental values of heat capacity of four proteins, from @PM90, with those calculated using group additivity. We divide Privalov and Makhatadze's experimental values by the lengths of the proteins to get per-residue values, then plot them. -```{r protein_Cp, fig.margin=TRUE, fig.width=4, fig.height=4, small.mar=TRUE, dpi=dpi, out.width="100%", echo=FALSE, message=FALSE, fig.cap='The heat capacity calculated by group additivity closely approximates experimental values for aqueous proteins. For a related figure showing the effects of ionization in the calculations, see `?ionize.aa`.', cache=TRUE, pngquant=pngquant, timeit=timeit} +```{r protein_Cp, fig.margin=TRUE, fig.width=4, fig.height=4, small.mar=TRUE, out.width="100%", echo=FALSE, message=FALSE, fig.cap='The heat capacity calculated by group additivity closely approximates experimental values for aqueous proteins. For a related figure showing the effects of ionization in the calculations, see `?ionize.aa`.', cache=TRUE, pngquant=pngquant, timeit=timeit} PM90 <- read.csv(system.file("extdata/cpetc/PM90.csv", package = "CHNOSZ")) plength <- protein.length(colnames(PM90)[2:5]) Cp_expt <- t(t(PM90[, 2:5]) / plength) @@ -1189,7 +1191,7 @@ The following plot shows the calculated affinity of reaction between nonionized Charged and uncharged sets of basis species are used to to activate and suppress the ionization calculations. The calculation of affinity for the ionized proteins returns multiple values (as a function of pH), but there is only one value of affinity returned for the nonionized proteins, so we need to use R's `as.numeric()` to avoid subtracting nonconformable arrays: -```{r protein_ionization, fig.margin=TRUE, fig.width=4, fig.height=4, small.mar=TRUE, dpi=dpi, out.width="100%", echo=FALSE, results="hide", message=FALSE, fig.cap='Affinity of ionization of proteins. See [demo(ionize)](../demo) for ionization properties calculated as a function of temperature and pH.', cache=TRUE, pngquant=pngquant, timeit=timeit} +```{r protein_ionization, fig.margin=TRUE, fig.width=4, fig.height=4, small.mar=TRUE, out.width="100%", echo=FALSE, results="hide", message=FALSE, fig.cap='Affinity of ionization of proteins. See [demo(ionize)](../demo) for ionization properties calculated as a function of temperature and pH.', cache=TRUE, pngquant=pngquant, timeit=timeit} ip <- pinfo(c("CYC_BOVIN", "LYSC_CHICK", "MYG_PHYCA", "RNAS1_BOVIN")) basis("CHNOS+") a_ion <- affinity(pH = c(0, 14), iprotein = ip) @@ -1312,7 +1314,7 @@ The calculation of *Z*C, which sums elemental ratios, is not affected The `QEC` keyword to `basis()` loads basis species including three amino acids (glutamine, glutamic acid, cysteine, `r h2o`, `r o2`). This basis strengthens the relationship between `r zc` and *n*̅`r o2`, but weakens that between `r zc` and *n*̅`r h2o` (shown in the plots on the right). -```{r rubisco_O2, fig.margin=TRUE, fig.width=4, fig.height=4, small.mar=TRUE, dpi=dpi, out.width="100%", echo=FALSE, results="hide", message=FALSE, fig.cap="Elemental compositions of proteins projected into different sets of basis species.", cache=TRUE, pngquant=pngquant, timeit=timeit} +```{r rubisco_O2, fig.margin=TRUE, fig.width=4, fig.height=4, small.mar=TRUE, out.width="100%", echo=FALSE, results="hide", message=FALSE, fig.cap="Elemental compositions of proteins projected into different sets of basis species.", cache=TRUE, pngquant=pngquant, timeit=timeit} layout(matrix(1:4, nrow = 2)) par(mgp = c(1.8, 0.5, 0)) pl <- protein.length(aa) @@ -1410,7 +1412,7 @@ The normalization step is followed by conversion of activities of residues to ac The experimental relative abundances are plotted as thin horizontal lines with the same style and color as the thicker curved lines calculated for metastable equilibrium. With the exception of YNL049C, the correspondence between the calculations and experiments looks to be greatest near the middle-left part of the figure. -```{r yeastplot, fig.width=6, fig.height=2.5, dpi=ifelse(dpi==50, 50, 100), out.width="100%", echo=FALSE, message=FALSE, results="hide", cache=TRUE, fig.cap="ER-to-Golgi proteins: calculations without and with length normalization.", pngquant=pngquant, timeit=timeit} +```{r yeastplot, fig.width=6, fig.height=2.5, dpi=hidpi, out.width="100%", echo=FALSE, message=FALSE, results="hide", cache=TRUE, fig.cap="ER-to-Golgi proteins: calculations without and with length normalization.", pngquant=pngquant, timeit=timeit} ``` ## Getting amino acid compositions diff --git a/vignettes/custom_data.Rmd b/vignettes/custom_data.Rmd index a4331c6..69c7493 100644 --- a/vignettes/custom_data.Rmd +++ b/vignettes/custom_data.Rmd @@ -23,8 +23,10 @@ knit_hooks$set(pngquant = hook_pngquant) pngquant <- "--speed=1 --quality=0-25" if (!nzchar(Sys.which("pngquant"))) pngquant <- NULL -## Set dpi 20231129 -dpi <- 72 +# Set dpi 20231129 +knitr::opts_chunk$set( + dpi = if(nzchar(Sys.getenv("CHNOSZ_BUILD_LARGE_VIGNETTES"))) 100 else 72 +) ``` ```{r HTML, include = FALSE} @@ -513,7 +515,7 @@ A constant molality of `r F_` is based on the assumption of complete dissociatio An ionic strength of 0.9 mol/kg is estimated for a solution with 1.8 m NaCl (use `NaCl(1.8, T = 300)`). `r NOTE`: because the ionic strength is non-zero, the calculations here refer to molality instead of activity of species (see [An Introduction to CHNOSZ](anintro.html#from-activity-to-molality)). -```{r diagram1, message = FALSE, results = "hide", fig.width = 6, fig.height = 5, out.width = "75%", fig.align = "center", pngquant = pngquant, dpi = dpi} +```{r diagram1, message = FALSE, results = "hide", fig.width = 6, fig.height = 5, out.width = "75%", fig.align = "center", pngquant = pngquant} basis(c("H+", "WO4-2", "F-", "H2O", "O2")) basis("F-", log10(0.1)) iaq <- retrieve("W", c("O", "H", "F"), "aq") @@ -542,7 +544,7 @@ a_F <- F_tot / (1 + 10^(logK_HF - pH)) ``` Now that we have the molality of `r F_` as a function of pH, we can provide it in the call to `r affinity_`. -```{r diagram2, message = FALSE, results = "hide", results = "hide", fig.width = 6, fig.height = 5, out.width = "75%", fig.align = "center", pngquant = pngquant, dpi = dpi} +```{r diagram2, message = FALSE, results = "hide", results = "hide", fig.width = 6, fig.height = 5, out.width = "75%", fig.align = "center", pngquant = pngquant} basis(c("H+", "WO4-2", "F-", "H2O", "O2")) iaq <- retrieve("W", c("O", "H", "F"), "aq") species(iaq) diff --git a/vignettes/eos-regress.Rmd b/vignettes/eos-regress.Rmd index 3349d69..5ba4d80 100644 --- a/vignettes/eos-regress.Rmd +++ b/vignettes/eos-regress.Rmd @@ -79,11 +79,8 @@ knit_hooks$set(pngquant = hook_pngquant) # pngquant isn't available on R-Forge ... if (!nzchar(Sys.which("pngquant"))) { pngquant <- NULL - # Save space by using a lower resolution - dpi <- 50 } else { pngquant <- "--speed=1 --quality=0-50" - dpi <- 72 } ## Colorize messages 20171031 @@ -92,6 +89,11 @@ color_block = function(color) { function(x, options) sprintf('
%s
', color, x) } knit_hooks$set(warning = color_block('magenta'), error = color_block('red'), message = color_block('blue')) + +# Set dpi 20231129 +knitr::opts_chunk$set( + dpi = if(nzchar(Sys.getenv("CHNOSZ_BUILD_LARGE_VIGNETTES"))) 72 else 50 +) ``` @@ -159,7 +161,7 @@ Cplm_low <- EOSregress(Cpdat, var, T.max = 600) Cplm_low$coefficients ``` -```{r EOSplot, fig.margin = TRUE, fig.cap = "Heat capacity of aqueous methane.", fig.width=3.5, fig.height=3.5, cache=TRUE, results="hide", message=FALSE, echo=FALSE, dpi=dpi, out.width=672, out.height=336, pngquant=pngquant} +```{r EOSplot, fig.margin = TRUE, fig.cap = "Heat capacity of aqueous methane.", fig.width=3.5, fig.height=3.5, cache=TRUE, results="hide", message=FALSE, echo=FALSE, out.width=672, out.height=336, pngquant=pngquant} EOSplot(Cpdat, coefficients = round(Cplm_low$coefficients, 1)) EOSplot(Cpdat, coeficients = Cplm_high, add = TRUE, lty = 3) PS01_data <- convert(EOScoeffs("CH4", "Cp"), "J") @@ -239,7 +241,7 @@ Vcoeffs <- round(c(Vnonlm$coefficients, QBorn = Vomega), 1) Vcoeffs_database <- convert(EOScoeffs("CH4", "V"), "J") ``` -```{r Vplot, fig.margin=TRUE, results="hide", message=FALSE, echo=FALSE, fig.width=3.5, fig.height=7, fig.cap="Volume of aqueous methane.", dpi=dpi, out.width=672, out.height=672, pngquant=pngquant} +```{r Vplot, fig.margin=TRUE, results="hide", message=FALSE, echo=FALSE, fig.width=3.5, fig.height=7, fig.cap="Volume of aqueous methane.", out.width=672, out.height=672, pngquant=pngquant} par(mfrow = c(2, 1)) # plot 1 EOSplot(Vdat, coefficients = Vcoeffs) @@ -278,7 +280,7 @@ Nadat <- prop.PT[, c("T", "P", "Cp")] As noted above, ω for electrolytes is not a constant. What happens if we apply the constant-ω model anyway, knowing it's not applicable (especially at high temperature)? -```{r Nalm, fig.margin=TRUE, fig.width=3.5, fig.height=3.5, fig.cap="Heat capacity of Na+ (inapplicable: constant ω).", dpi=dpi, out.width=672, out.height=336, pngquant=pngquant} +```{r Nalm, fig.margin=TRUE, fig.width=3.5, fig.height=3.5, fig.cap="Heat capacity of Na+ (inapplicable: constant ω).", out.width=672, out.height=336, pngquant=pngquant} var <- c("invTTheta2", "TXBorn") Nalm <- EOSregress(Nadat, var, T.max = 600) EOSplot(Nadat, coefficients = Nalm$coefficients, fun.legend = NULL) @@ -302,7 +304,7 @@ omega.guess <- coef(Nalm)[3] Then, we can use an iterative procedure that refines successive guesses of `r wPrTr`. The convergence criterion is measured by the difference in sequential regressed values of ω. -```{r Nawhile, fig.margin=TRUE, fig.width=3.5, fig.height=3.5, fig.cap="Heat capacity of Na+ (variable ω).", dpi=dpi, out.width=672, out.height=336, pngquant=pngquant} +```{r Nawhile, fig.margin=TRUE, fig.width=3.5, fig.height=3.5, fig.cap="Heat capacity of Na+ (variable ω).", out.width=672, out.height=336, pngquant=pngquant} diff.omega <- 999 while(abs(diff.omega) > 1) { Nalm1 <- EOSregress(Nadat, var1, omega.PrTr = tail(omega.guess, 1), Z = 1) @@ -324,7 +326,7 @@ Note that the regressed value of ω has volumetric units (cm3 ba Compared to `r Cp0`, the regression of `r V0` is very finicky. Given a starting guess of `r wPrTr` of 1400000 cm3 bar/mol, the iteration converges on 1394890 instead of the "true" database value of 1383230 (represented by dashed line in the plot). -```{r NaVolume, fig.margin=TRUE, fig.width=3.5, fig.height=3.5, fig.cap="Volume of Na+ (variable ω).", results="hide", message=FALSE, echo=FALSE, dpi=dpi, out.width=672, out.height=336, pngquant=pngquant} +```{r NaVolume, fig.margin=TRUE, fig.width=3.5, fig.height=3.5, fig.cap="Volume of Na+ (variable ω).", results="hide", message=FALSE, echo=FALSE, out.width=672, out.height=336, pngquant=pngquant} T <- convert(seq(0, 600, 25), "K") P <- 1000 prop.PT <- subcrt("Na+", T = T, P = P, grid = "T", convert = FALSE)$out[[1]] @@ -429,7 +431,7 @@ info(info(c("calc-H4SiO4", "H4SiO4"))) ```{r width80, include=FALSE} ``` -```{r subcrt_H4SiO4, fig.margin=TRUE, fig.width=4, fig.height=4, small.mar=TRUE, echo=FALSE, results="hide", message=FALSE, dpi=dpi, out.width="100%", cache=TRUE, fig.cap="Comparison of H4SiO4 pseudospecies.", pngquant=pngquant} +```{r subcrt_H4SiO4, fig.margin=TRUE, fig.width=4, fig.height=4, small.mar=TRUE, echo=FALSE, results="hide", message=FALSE, out.width="100%", cache=TRUE, fig.cap="Comparison of H4SiO4 pseudospecies.", pngquant=pngquant} s1 <- subcrt(c("calc-H4SiO4", "SiO2", "H2O"), c(-1, 1, 2)) plot(s1$out$T, s1$out$G, type = "l", ylim = c(-500, 2000), xlab = axis.label("T"), ylab = axis.label("DG0")) @@ -453,7 +455,7 @@ For example, the almost 800 J/mol offset in ΔG° at 350 °C c The following example uses the `H4SiO4` from Stefánsson (2001) to make an activity diagram for the K2O-Al2O3-SiO2-H2O system. This is similar to the diagram on p. 361 of [Garrels and Christ, 1965](https://www.worldcat.org/oclc/517586), but is quantitatively a closer match to the diagram in the [User's Guide to PHREEQC](https://wwwbrr.cr.usgs.gov/projects/GWC_coupled/phreeqc/html/final-75.html). -```{r activity_diagram, fig.margin=TRUE, fig.width=4, fig.height=4, small.mar=TRUE, echo=TRUE, results="hide", message=FALSE, dpi=dpi, out.width="100%", cache=TRUE, fig.cap="Activity diagram for K2O-Al2O3-SiO2-H2O.", pngquant=pngquant} +```{r activity_diagram, fig.margin=TRUE, fig.width=4, fig.height=4, small.mar=TRUE, echo=TRUE, results="hide", message=FALSE, out.width="100%", cache=TRUE, fig.cap="Activity diagram for K2O-Al2O3-SiO2-H2O.", pngquant=pngquant} basis(c("Al+3", "H4SiO4", "K+", "H2O", "H+", "O2")) species(c("gibbsite", "muscovite", "kaolinite", "pyrophyllite", "K-feldspar")) a <- affinity(H4SiO4 = c(-8, 0, 300), `K+` = c(-1, 8, 300)) diff --git a/vignettes/equilibrium.Rmd b/vignettes/equilibrium.Rmd index ed3b67b..672721e 100644 --- a/vignettes/equilibrium.Rmd +++ b/vignettes/equilibrium.Rmd @@ -64,8 +64,10 @@ knit_hooks$set(pngquant = hook_pngquant) pngquant <- "--speed=1 --quality=0-25" if (!nzchar(Sys.which("pngquant"))) pngquant <- NULL -## Set dpi 20231129 -dpi <- 72 +# Set dpi 20231129 +knitr::opts_chunk$set( + dpi = if(nzchar(Sys.getenv("CHNOSZ_BUILD_LARGE_VIGNETTES"))) 100 else 72 +) ``` ```{r CHNOSZ_reset, include=FALSE} @@ -270,7 +272,7 @@ label.figure("F", yfrac=0.92, xfrac=0.1, font = 2) ``` -```{r AAplot, echo = FALSE, results = "hide", message = FALSE, fig.width = 13/2, fig.height = 8.7/2, out.width = "100%", pngquant = pngquant, dpi = dpi} +```{r AAplot, echo = FALSE, results = "hide", message = FALSE, fig.width = 13/2, fig.height = 8.7/2, out.width = "100%", pngquant = pngquant} ``` Diagrams **A** and **B** use the *maximum affinity method*, where the reference @@ -370,7 +372,7 @@ prF <- function() { ``` -```{r PRplot, echo = FALSE, results = "hide", message = FALSE, fig.width = 13/2, fig.height = 8.7/2, out.width = "100%", pngquant = pngquant, dpi = dpi} +```{r PRplot, echo = FALSE, results = "hide", message = FALSE, fig.width = 13/2, fig.height = 8.7/2, out.width = "100%", pngquant = pngquant} layout(t(matrix(1:12, nrow=4)), widths=c(1, 4, 4, 4), heights=c(0.7, 4, 4)) ## Row 0 (column titles) @@ -449,7 +451,7 @@ Here is another figure showing the effects of normalization. This is like Figure 5 of @Dic08, extended to more extreme conditions. If you wish to reproduce the diagram from the 2008 paper more closely, uncomment the `add.OBIGT()` command. -```{r ProteinSpeciation, results = "hide", message = FALSE, fig.width = 8, fig.height = 5.5, out.width = "100%", pngquant = pngquant, dpi = dpi} +```{r ProteinSpeciation, results = "hide", message = FALSE, fig.width = 8, fig.height = 5.5, out.width = "100%", pngquant = pngquant} organisms <- c("METSC", "METJA", "METFE", "METVO", "METBU", "HALJP", "ACEKI", "GEOSE", "BACLI", "AERSA") proteins <- c(rep("CSG", 6), rep("SLAP", 4)) diff --git a/vignettes/multi-metal.Rmd b/vignettes/multi-metal.Rmd index 7d7e537..2b98cea 100644 --- a/vignettes/multi-metal.Rmd +++ b/vignettes/multi-metal.Rmd @@ -68,19 +68,21 @@ if (!nzchar(Sys.which("pngquant"))) pngquant <- NULL ## Resolution settings # Change this to TRUE to make high-resolution plots # (default is FALSE to save time in CRAN checks) -hires <- FALSE +hires <- nzchar(Sys.getenv("CHNOSZ_BUILD_LARGE_VIGNETTES")) res1.lo <- 150 res1.hi <- 256 -res1 <- ifelse(hires, res1.hi, res1.lo) +res1 <- if(hires) res1.hi else res1.lo res2.lo <- 200 res2.hi <- 400 -res2 <- ifelse(hires, res2.hi, res2.lo) - -## Set dpi 20231129 -dpi <- 72 +res2 <- if(hires) res2.hi else res2.lo ## logK with a thin space 20200627 logK <- "log K" + +## Set dpi 20231129 +knitr::opts_chunk$set( + dpi = if(nzchar(Sys.getenv("CHNOSZ_BUILD_LARGE_VIGNETTES"))) 100 else 72 +) ``` ```{r CHNOSZ_reset, include=FALSE} @@ -93,18 +95,20 @@ This vignette was compiled on `r Sys.Date()` with CHNOSZ version `r sessionInfo( This vignette is associated with a paper that has been published in *Applied Computing and Geosciences* ([Dick, 2021](https://doi.org/10.1016/j.acags.2021.100059 "Diagrams with multiple metals in CHNOSZ")). Please consider citing that paper if you use the functions or diagrams described here. -The plots in this vignette were made using the following resolution settings, which can be changed if desired (low resolutions are used to save time in CRAN checks): +The plots in this vignette were made using the following resolution settings. +Low resolutions are used for submitting the package to CRAN. +High resolutions are used if the `CHNOSZ_BUILD_LARGE_VIGNETTES` environment variable is set. ```{r res, results = "asis", echo = FALSE} cat("```") cat("\n") -cat(paste0(ifelse(hires, "# ", ""), "res1 <- ", res1.lo)) +cat(paste0(if(hires) "# " else "", "res1 <- ", res1.lo)) cat("\n") -cat(paste0(ifelse(hires, "", "# "), "res1 <- ", res1.hi)) +cat(paste0(if(hires) "" else "# ", "res1 <- ", res1.hi)) cat("\n") -cat(paste0(ifelse(hires, "# ", ""), "res2 <- ", res2.lo)) +cat(paste0(if(hires) "# " else "", "res2 <- ", res2.lo)) cat("\n") -cat(paste0(ifelse(hires, "", "# "), "res2 <- ", res2.hi)) +cat(paste0(if(hires) "" else "# ", "res2 <- ", res2.hi)) cat("\n") cat("```") ``` @@ -142,7 +146,7 @@ legend("topright", legend = lTP(25, 1), bty = "n") The second diagram is just like the first, except the function `mash()` is used to label the fields with names of species from both systems, and a legend is added to indicate the temperature and pressure. -```{r mash, echo = 9:14, results = "hide", message = FALSE, fig.width = 10, fig.height = 5, out.width = "100%", dpi = dpi} +```{r mash, echo = 9:14, results = "hide", message = FALSE, fig.width = 10, fig.height = 5, out.width = "100%"} ``` Note that these are predominance diagrams, so they show only the species with highest activity; there is in fact a distribution of activities of aqueous species that is not visible here. @@ -317,7 +321,7 @@ The `mix()` function is used to calculate the affinities of formation from basis Finally, the `diagram()`s are plotted; the `min.area` argument is used to remove labels for very small fields. Regarding the legend, it should be noted that although the DFT calculations for solids are made for zero temperature and zero pressure [@SZS_17], the standard Gibbs energies of aqueous species [e.g. @WEP_82] are modified by a correction term so that they can be combined with DFT energies to reproduce the experimental energy for dissolution of a representative material for each metal at 25 °C and 1 bar [@PWLC12]. -```{r mixing1, echo = 16:47, message = FALSE, results = "hide", fig.width = 9, fig.height = 3, out.width = "100%", out.extra='class="full-width"', pngquant = pngquant, dpi = dpi} +```{r mixing1, echo = 16:47, message = FALSE, results = "hide", fig.width = 9, fig.height = 3, out.width = "100%", out.extra='class="full-width"', pngquant = pngquant} ``` In these diagrams, changing the Fe:V ratio affects the fully reduced metallic species. @@ -405,7 +409,7 @@ Given the diagram for the stable Fe-, V- and bimetallic materials *mixed with th This is plotted as a color map in the second diagram. (See the source of this vignette for the code used to make the scale bar.) -```{r FeVO4, echo = 31:44, message = FALSE, results = "hide", fig.width = 11, fig.height = 5, out.width = "100%", pngquant = pngquant, dpi = dpi} +```{r FeVO4, echo = 31:44, message = FALSE, results = "hide", fig.width = 11, fig.height = 5, out.width = "100%", pngquant = pngquant} ``` Now we locate the pH and Eh that maximize the affinity (that is, minimize Δ*G*~pbx~) of FeVO~4~ compared to the stable species. @@ -516,7 +520,7 @@ The result is used to plot the last layer of the diagram: After that we add the legend and title. -```{r stack1_2, echo=5:17, results = "hide", message = FALSE, fig.width = 6, fig.height = 5, out.width = "75%", fig.align = "center", pngquant = pngquant, dpi = dpi} +```{r stack1_2, echo=5:17, results = "hide", message = FALSE, fig.width = 6, fig.height = 5, out.width = "75%", fig.align = "center", pngquant = pngquant} ``` This diagram has a distinctive chalcopyrite "hook" surrounded by a thin bornite field. @@ -642,7 +646,7 @@ OBIGT() ``` -```{r stack2, echo = FALSE, results = "hide", message = FALSE, fig.width = 6, fig.height = 5, out.width = "75%", fig.align = "center", pngquant = pngquant, dpi = dpi} +```{r stack2, echo = FALSE, results = "hide", message = FALSE, fig.width = 6, fig.height = 5, out.width = "75%", fig.align = "center", pngquant = pngquant} ``` After running the code to make this diagram, we can list the reference keys for the minerals and aqueous species. @@ -734,7 +738,7 @@ title("Fe:Cu = 1:2") ``` -```{r mixing2, echo = FALSE, results = "hide", message = FALSE, fig.width = 8, fig.height = 6.5, out.width = "100%", pngquant = pngquant, dpi = dpi} +```{r mixing2, echo = FALSE, results = "hide", message = FALSE, fig.width = 8, fig.height = 6.5, out.width = "100%", pngquant = pngquant} ``` These diagrams show that changing the amounts of the metals affects the stability of minerals involved in reactions with chalcopyrite. @@ -798,7 +802,7 @@ title("Cu-Fe-S-O-H") ``` -```{r stack3, echo = FALSE, results = "hide", message = FALSE, fig.width = 6, fig.height = 4, out.width = "100%", pngquant = pngquant, dpi = dpi} +```{r stack3, echo = FALSE, results = "hide", message = FALSE, fig.width = 6, fig.height = 4, out.width = "100%", pngquant = pngquant} ``` The resulting diagram is similar to Figure 2 of @Sve87; that diagram also shows calculations of the solubility of Cu and concentration of SO~4~^-2^ in model Cu ore-forming fluids. @@ -881,7 +885,7 @@ title(bquote(bold(.(expr.species("SO4-2"))~"(ppm)"))) ``` -```{r solubility, echo = FALSE, results = "hide", message = FALSE, fig.width = 7, fig.height = 3, out.width = "100%", fig.align = "center", pngquant = pngquant, dpi = dpi} +```{r solubility, echo = FALSE, results = "hide", message = FALSE, fig.width = 7, fig.height = 3, out.width = "100%", fig.align = "center", pngquant = pngquant} ``` After running the code above, we can inspect the value of `calc` to show the estimated ionic strength and activity of Cl^-^; the latter is very close to unity. @@ -1012,7 +1016,7 @@ The fields in this diagram are labeled with mineral abbreviations from the OBIGT ```{r rebalance, eval = FALSE, echo = 36:49} ``` -```{r rebalance, echo = FALSE, results = "hide", message = FALSE, fig.width = 6.5, fig.height = 5, out.width = "100%", fig.align = "center", pngquant = pngquant, dpi = dpi} +```{r rebalance, echo = FALSE, results = "hide", message = FALSE, fig.width = 6.5, fig.height = 5, out.width = "100%", fig.align = "center", pngquant = pngquant} ``` The final diagram is like one shown in Figure 5 of @Bri80 and Figure 5 of @MH85. @@ -1032,7 +1036,7 @@ Here is an example for the Cu-Fe-S-O-H system. The reactions are balanced on O~2~, which means that no O~2~ appears in the reaction between any two minerals, but Fe^+2^ and/or Cu^+^ can be present, depending on the chemical composition. Saturation limits are shown for species that have no O~2~ in their formation reactions. -```{r non-metal, results = "hide", message = FALSE, fig.width = 6, fig.height = 5, out.width = "80%", fig.align = "center", pngquant = pngquant, dpi = dpi} +```{r non-metal, results = "hide", message = FALSE, fig.width = 6, fig.height = 5, out.width = "80%", fig.align = "center", pngquant = pngquant} basis(c("Fe+2", "Cu+", "hydrogen sulfide", "oxygen", "H2O", "H+")) basis("H2S", 2) species(c("pyrite", "magnetite", "hematite", "covellite", "tenorite", @@ -1147,7 +1151,7 @@ stopifnot(all.equal(as.numeric(e$loga.equil[[3]]), logAcAm, tol = 1e-3, scale = ``` -```{r mosaic-combo, echo = FALSE, results = "hide", message = FALSE, fig.width = 6, fig.height = 5, out.width = "80%", fig.align = "center", pngquant = pngquant, dpi = dpi} +```{r mosaic-combo, echo = FALSE, results = "hide", message = FALSE, fig.width = 6, fig.height = 5, out.width = "80%", fig.align = "center", pngquant = pngquant} ``` The diagram shows the ionization of acetic acid and NH~3~ at different pHs.