[CHNOSZ-commits] r95 - in pkg/CHNOSZ: . R demo inst man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Nov 5 06:18:37 CET 2015


Author: jedick
Date: 2015-11-05 06:18:37 +0100 (Thu, 05 Nov 2015)
New Revision: 95

Added:
   pkg/CHNOSZ/demo/copper.R
Modified:
   pkg/CHNOSZ/DESCRIPTION
   pkg/CHNOSZ/NAMESPACE
   pkg/CHNOSZ/R/diagram.R
   pkg/CHNOSZ/R/equilibrate.R
   pkg/CHNOSZ/R/examples.R
   pkg/CHNOSZ/R/mosaic.R
   pkg/CHNOSZ/R/swap.basis.R
   pkg/CHNOSZ/R/util.plot.R
   pkg/CHNOSZ/demo/00Index
   pkg/CHNOSZ/inst/NEWS
   pkg/CHNOSZ/man/diagram.Rd
   pkg/CHNOSZ/man/equilibrate.Rd
   pkg/CHNOSZ/man/examples.Rd
   pkg/CHNOSZ/man/swap.basis.Rd
   pkg/CHNOSZ/man/util.plot.Rd
Log:
add demo copper.R


Modified: pkg/CHNOSZ/DESCRIPTION
===================================================================
--- pkg/CHNOSZ/DESCRIPTION	2015-10-19 18:37:20 UTC (rev 94)
+++ pkg/CHNOSZ/DESCRIPTION	2015-11-05 05:18:37 UTC (rev 95)
@@ -1,6 +1,6 @@
-Date: 2015-10-19
+Date: 2015-11-05
 Package: CHNOSZ
-Version: 1.0.6
+Version: 1.0.6-1
 Title: Chemical Thermodynamics and Activity Diagrams
 Author: Jeffrey Dick
 Maintainer: Jeffrey Dick <j3ffdick at gmail.com>

Modified: pkg/CHNOSZ/NAMESPACE
===================================================================
--- pkg/CHNOSZ/NAMESPACE	2015-10-19 18:37:20 UTC (rev 94)
+++ pkg/CHNOSZ/NAMESPACE	2015-11-05 05:18:37 UTC (rev 95)
@@ -11,7 +11,8 @@
   "contour", "image", "legend", "lines", "mtext", "par", "plot",
   "plot.new", "plot.window", "points", "rect", "text", "title")
 importFrom("stats", "D", "as.formula", "cor", "lm", "loess.smooth",
-  "na.omit", "qqline", "qqnorm", "sd", "splinefun", "uniroot")
+  "na.omit", "predict.lm", "qqline", "qqnorm", "sd", "splinefun",
+  "uniroot")
 importFrom("utils", "browseURL", "capture.output", "combn", "demo",
   "example", "head", "installed.packages", "read.csv", "tail",
   "write.csv", "write.table")

Modified: pkg/CHNOSZ/R/diagram.R
===================================================================
--- pkg/CHNOSZ/R/diagram.R	2015-10-19 18:37:20 UTC (rev 94)
+++ pkg/CHNOSZ/R/diagram.R	2015-11-05 05:18:37 UTC (rev 95)
@@ -24,7 +24,7 @@
   # labels
   names=NULL, main=NULL, legend.x="topright",
   # plotting controls
-  add=FALSE, plot.it=TRUE, tplot=TRUE
+  add=FALSE, plot.it=TRUE, tplot=TRUE, ...
 ) {
 
   ### argument handling ###
@@ -203,7 +203,7 @@
       ### 0-D diagram - bar graph of properties of species or reactions
       # plot setup
       if(missing(ylab)) ylab <- axis.label(plotvar, units="")
-      barplot(unlist(plotvals), names.arg=names, ylab=ylab, cex.names=cex.names, col=col)
+      barplot(unlist(plotvals), names.arg=names, ylab=ylab, cex.names=cex.names, col=col, ...)
       if(!is.null(main)) title(main=main)
 
     } else if(nd==1) {
@@ -223,7 +223,7 @@
           ylim <- extendrange(myval)
         }
         if(tplot) thermo.plot.new(xlim=xlim, ylim=ylim, xlab=xlab, ylab=ylab, cex=cex, mar=mar, yline=yline, side=side)
-        else plot(0, 0, type="n", xlim=xlim, ylim=ylim, xlab=xlab, ylab=ylab)
+        else plot(0, 0, type="n", xlim=xlim, ylim=ylim, xlab=xlab, ylab=ylab, ...)
       }
       # draw the lines
       for(i in 1:length(plotvals)) lines(xvalues, plotvals[[i]], col=col[i], lty=lty[i], lwd=lwd[i])
@@ -406,7 +406,7 @@
         if(is.null(ylab)) ylab <- axis.label(eout$vars[2], basis=eout$basis)
         if(tplot) thermo.plot.new(xlim=xlim, ylim=ylim, xlab=xlab, ylab=ylab,
           cex=cex, cex.axis=cex.axis, mar=mar, yline=yline, side=side)
-        else plot(0, 0, type="n", xlim=xlim, ylim=ylim, xlab=xlab, ylab=ylab)
+        else plot(0, 0, type="n", xlim=xlim, ylim=ylim, xlab=xlab, ylab=ylab, ...)
         # add a title
         if(!is.null(main)) title(main=main)
       }

Modified: pkg/CHNOSZ/R/equilibrate.R
===================================================================
--- pkg/CHNOSZ/R/equilibrate.R	2015-10-19 18:37:20 UTC (rev 94)
+++ pkg/CHNOSZ/R/equilibrate.R	2015-11-05 05:18:37 UTC (rev 95)
@@ -64,7 +64,8 @@
     })
   }
   ## put together the output
-  out <- c(aout, list(balance=balance, m.balance=m.balance, n.balance=n.balance, Astar=Astar, loga.equil=loga.equil))
+  out <- c(aout, list(balance=balance, m.balance=m.balance, n.balance=n.balance,
+    loga.balance=loga.balance, Astar=Astar, loga.equil=loga.equil))
   # done!
   return(out)
 }

Modified: pkg/CHNOSZ/R/examples.R
===================================================================
--- pkg/CHNOSZ/R/examples.R	2015-10-19 18:37:20 UTC (rev 94)
+++ pkg/CHNOSZ/R/examples.R	2015-11-05 05:18:37 UTC (rev 95)
@@ -32,7 +32,7 @@
 demos <- function(which=c("sources", "NaCl", "density", 
   "phosphate", "nucleobase", "ORP", "diagram", "revisit", "findit",
   "CO2Ac", "nonideal", "ionize", "buffer", "yeastgfp", "mosaic",
-  "solubility", "wjd"), do.png=FALSE) {
+  "copper", "solubility", "wjd"), do.png=FALSE) {
   # run one or more demos from CHNOSZ with ask=FALSE, and return the value of the last one
   for(i in 1:length(which)) {
     # say something so the user sees where we are

Modified: pkg/CHNOSZ/R/mosaic.R
===================================================================
--- pkg/CHNOSZ/R/mosaic.R	2015-10-19 18:37:20 UTC (rev 94)
+++ pkg/CHNOSZ/R/mosaic.R	2015-11-05 05:18:37 UTC (rev 95)
@@ -17,7 +17,7 @@
   # (the first one should be present in the starting basis set)
   iswap <- match(bases[1], names(myargs))
   # the log activity of the starting basis species
-  logact.swap <- basis()$logact[match(bases[1], row.names(basis()))]
+  logact.swap <- basis()$logact[ibasis(bases[1])]
   # a list where we'll keep the affinity calculations
   affs <- list()
   for(i in seq_along(bases)) {
@@ -35,11 +35,14 @@
     # change the basis species; restore the original at the end of the loop
     if(i < length(bases)) {
       swap.basis(bases[i], bases[i+1]) 
-      basis(bases[i+1], logact.swap)
+      # TODO: basis() requires the formula to identify the basis species,
+      # would be nicer to just use the ibasis here
+      bformula <- rownames(basis())[ibasis(bases[i+1])]
+      basis(bformula, logact.swap)
     } else {
       swap.basis(bases[i], bases[1])
-      basis(bases[1], logact.swap)
-      names <- row.names(basis())
+      bformula <- rownames(basis())[ibasis(bases[1])]
+      basis(bformula, logact.swap)
     }
   }
   # calculate affinities of formation of basis species

Modified: pkg/CHNOSZ/R/swap.basis.R
===================================================================
--- pkg/CHNOSZ/R/swap.basis.R	2015-10-19 18:37:20 UTC (rev 94)
+++ pkg/CHNOSZ/R/swap.basis.R	2015-11-05 05:18:37 UTC (rev 95)
@@ -47,6 +47,19 @@
   return(basis.logact)
 }
 
+ibasis <- function(species) {
+  # get the index of a basis species from a species index, name or formula
+  basis <- basis()
+  if(is.numeric(species)) ib <- match(species, basis$ispecies)
+  else {
+    # character: first look for formula of basis species
+    ib <- match(species, rownames(basis))
+    # if that doesn't work, look for name of basis species
+    if(is.na(ib)) ib <- match(species, get("thermo")$obigt$name[basis$ispecies])
+  }
+  return(ib)
+}
+
 # swap in one basis species for another
 swap.basis <- function(species, species2, T = 25) {
   # before we do anything, remember the old basis definition
@@ -63,8 +76,7 @@
   if(length(species) > 1 | length(species2) > 2)
     stop("can only swap one species for one species")
   # arguments are good, now find the basis species to swap out
-  if(is.numeric(species)) ib <- match(species, oldbasis$ispecies)
-  else ib <- match(species, rownames(oldbasis))
+  ib <- ibasis(species)
   if(is.na(ib)) stop(paste("basis species '",species,"' is not defined",sep=""))
   # find species2 in the thermodynamic database
   if(is.numeric(species2)) ispecies2 <- species2

Modified: pkg/CHNOSZ/R/util.plot.R
===================================================================
--- pkg/CHNOSZ/R/util.plot.R	2015-10-19 18:37:20 UTC (rev 94)
+++ pkg/CHNOSZ/R/util.plot.R	2015-11-05 05:18:37 UTC (rev 95)
@@ -103,16 +103,41 @@
   if(!is.null(T)) par(opar)
 }
 
-label.plot <- function(x,xfrac=0.95,yfrac=0.9,cex=1,paren=TRUE,adj=1) {
+label.plot <- function(x, xfrac=0.05, yfrac=0.95, paren=FALSE, italic=FALSE, ...) {
   # make a text label e.g., "(a)" in the corner of a plot
   # xfrac, yfrac: fraction of axis where to put label (default top right)
   # paren: put a parenthesis around the text, and italicize it?
-  if(paren) x <- as.expression(substitute(group('(',italic(a),')'),list(a=x)))
+  if(italic) x <- substitute(italic(a), list(a=x))
+  if(paren) x <- substitute(group('(',a,')'), list(a=x))
+  if(italic | paren) x <- as.expression(x)
   pu <- par('usr')
-  text( pu[1]+xfrac*(pu[2]-pu[1]), pu[3]+yfrac*(pu[4]-pu[3]), labels=x, cex=cex , adj=adj)
+  text(pu[1]+xfrac*(pu[2]-pu[1]), pu[3]+yfrac*(pu[4]-pu[3]), labels=x, ...)
 }
 
+usrfig <- function() {
+  # function to get the figure limits in user coordinates
+  # get plot limits in user coordinates (usr) and as fraction [0,1] of figure region (plt)
+  xusr <- par('usr')[1:2]; yusr <- par('usr')[3:4]
+  xplt <- par('plt')[1:2]; yplt <- par('plt')[3:4]
+  # linear model to calculate figure limits in user coordinates
+  xlm <- lm(xusr ~ xplt); ylm <- lm(yusr ~ yplt)
+  xfig <- predict.lm(xlm, data.frame(xplt=c(0, 1)))
+  yfig <- predict.lm(ylm, data.frame(yplt=c(0, 1)))
+  return(list(x=xfig, y=yfig))
+}
 
+label.figure <- function(x, xfrac=0.05, yfrac=0.95, paren=FALSE, italic=FALSE, ...) {
+  # function to add labels outside of the plot region  20151020
+  f <- usrfig()
+  # similar to label.plot(), except we have to set xpd=TRUE here
+  opar <- par(xpd=NA)
+  if(italic) x <- substitute(italic(a), list(a=x))
+  if(paren) x <- substitute(group('(',a,')'), list(a=x))
+  if(italic | paren) x <- as.expression(x)
+  text(f$x[1]+xfrac*(f$x[2]-f$x[1]), f$y[1]+yfrac*(f$y[2]-f$y[1]), labels=x, ...)
+  par(opar)
+}
+
 water.lines <- function(xaxis='pH', yaxis='Eh', T=298.15, P='Psat', which=c('oxidation','reduction'),
   logaH2O=0, lty=2, lwd=1, col=par('fg'), xpoints=NULL, O2state="gas") {
   # draw water stability limits

Modified: pkg/CHNOSZ/demo/00Index
===================================================================
--- pkg/CHNOSZ/demo/00Index	2015-10-19 18:37:20 UTC (rev 94)
+++ pkg/CHNOSZ/demo/00Index	2015-11-05 05:18:37 UTC (rev 95)
@@ -13,5 +13,6 @@
 buffer          ionized proteins as a chemical activity buffer (1. thiol peroxidases 2. sigma factors)
 yeastgfp        logfO2-logaH2O diagrams for model proteins based on YeastGFP localizations
 mosaic          Eh-pH diagram for iron oxides, sulfides and carbonate with two sets of changing basis species
+copper          another example of mosaic(): complexation of copper with glycine species
 solubility      solubility of calicite or CO2(gas) as a function of pH
 wjd             run.wjd() with proteins: cell periphery of yeast

Added: pkg/CHNOSZ/demo/copper.R
===================================================================
--- pkg/CHNOSZ/demo/copper.R	                        (rev 0)
+++ pkg/CHNOSZ/demo/copper.R	2015-11-05 05:18:37 UTC (rev 95)
@@ -0,0 +1,68 @@
+## Eh-pH diagrams for copper-water-glycine
+## After Fig. 2 of Aksu and Doyle, 2001
+## (Aksu, S. and Doyle, F. M., 2001. Electrochemistry of copper in aqueous glycine 
+## solutions. J. Electrochem. Soc., 148, B51-B57. doi:10.1149/1.1344532)
+
+# add some new species to thermo$obigt
+m1 <- makeup(info(c("Cu+", "glycinate", "glycinate")), sum=TRUE)
+mod.obigt(name="Cu(Gly)2-", formula=as.chemical.formula(m1))
+m2 <- makeup(info(c("Cu+2", "glycinate", "H+")), sum=TRUE)
+mod.obigt(name="HCu(Gly)+2", formula=as.chemical.formula(m2))
+# Gibbs energies from A&D's Table 1 and Table II
+Cu_s <- c("copper", "cuprite", "tenorite")
+Gly <- c("glycinium", "glycine", "glycinate")
+Cu_aq <- c("Cu+", "Cu+2", "CuO2-2", "HCuO2-")
+CuGly <- c("Cu(Gly)+", "Cu(Gly)2", "Cu(Gly)2-", "HCu(Gly)+2")
+names <- c(Cu_s, Gly, Cu_aq, CuGly)
+G <- c(
+  convert(c(0, -146, -129.7,
+  -384.061, -370.647, -314.833,
+  49.98, 65.49, -183.6, -258.5, -298.2)*1000, "cal"),
+  convert(c(15.64, 10.1, 2.92), "G"))
+# run updates in order so later species take account of prev. species' values
+getG <- function(x) info(info(x))$G
+for(i in 1:length(G)) {
+  myG <- G[i]
+  if(i==12) myG <- myG + getG("Cu+2") + 2*getG("glycinate")
+  if(i==13) myG <- myG + getG("Cu+") + 2*getG("glycinate")
+  if(i==14) myG <- myG + getG("Cu(Gly)+")
+  mod.obigt(names[i], G=myG)
+}  
+
+# in Fig. 2b, total log activities of Cu (Cu_T) and glycine (L_T) are -4 and -1
+basis(c("Cu+2", "H2O", "H+", "e-", "glycinium", "CO2"), c(999, 0, 999, 999, -1, 999))
+# add solids and aqueous species
+species(Cu_s)
+species(c(Cu_aq, CuGly), -4)
+names <- c(Cu_s, Cu_aq, CuGly)
+# mosaic diagram with to speciate glycine as a function of pH
+m <- mosaic(bases=Gly, pH=c(0, 16, 300), Eh=c(-0.6, 1.0, 300))
+fill <- c(rep("lightgrey", 3), rep("white", 4), rep("lightblue", 4))
+d <- diagram(m$A.species, fill=fill, names=NULL, tplot=FALSE, xaxs="i", yaxs="i")
+# to make the labels look nicer
+names <- names[sort(unique(as.numeric(d$predominant)))]
+for(i in 1:length(names)) {
+  if(i %in% 1:3) lab <- names[i] else lab <- expr.species(names[i])
+  # some manual adjustment so labels don't collide
+  srt <- dy <- dx <- 0
+  if(names[i]=="tenorite") dy <- -0.1
+  if(names[i]=="CuO2-2") dy <- -0.1
+  if(names[i]=="HCu(Gly)+2") srt <- 90
+  if(names[i]=="HCu(Gly)+2") dx <- -0.2
+  if(names[i]=="Cu(Gly)+") srt <- 90
+  text(d$lx[i]+dx, d$ly[i]+dy, lab, srt=srt)
+}
+
+# add glycine ionization lines
+d <- diagram(m$A.bases, add=TRUE, col="darkblue", dotted=c(2, 3), names=NULL)
+text(d$lx, -0.5, Gly, col="darkblue")
+
+# add water lines and title and re-draw a box around the plot
+# because the filling of fields masks it
+water.lines()
+box()
+title(main=paste("Aqueous Copper + Glycine, 25 deg C, 1 bar",
+  "After Aksu and Doyle, 2001 Fig. 2b",sep="\n"))
+
+# done!
+data(thermo)

Modified: pkg/CHNOSZ/inst/NEWS
===================================================================
--- pkg/CHNOSZ/inst/NEWS	2015-10-19 18:37:20 UTC (rev 94)
+++ pkg/CHNOSZ/inst/NEWS	2015-11-05 05:18:37 UTC (rev 95)
@@ -1,6 +1,25 @@
-CHANGES IN CHNOSZ 1.0.6 (2015-10-19)
+CHANGES IN CHNOSZ 1.0.6-1 (2015-11-05)
 --------------------------------------
 
+- Add functions usrfig() (get figure limits in user coordinates) and
+  label.figure() (add label to figure outside of plot region).
+
+- Add copper.R demo (complexation of copper with glycine, uses
+  mosaic()).
+
+- Using new supporting function ibasis(), swap.basis() and mosaic()
+  now allow basis species to be specified by name, not just formula.
+
+- diagram() now has '...' argument to pass additional options to
+  plot() (useful with diagram(tplot=FALSE, ...)).
+
+- TODO: Update vignette 'equilibrium.Rnw' with better definitions of
+  concepts, organization of functions, and amino acid and protein
+  examples.
+
+CHANGES IN CHNOSZ 1.0.6 (2015-10-19)
+------------------------------------
+
 - Rewrite rho.IAPWS95() to be able to invert density from IAPWS-95
   equations for a more extensive range of T,P values.
 

Modified: pkg/CHNOSZ/man/diagram.Rd
===================================================================
--- pkg/CHNOSZ/man/diagram.Rd	2015-10-19 18:37:20 UTC (rev 94)
+++ pkg/CHNOSZ/man/diagram.Rd	2015-11-05 05:18:37 UTC (rev 95)
@@ -16,7 +16,7 @@
     lty=NULL, lwd=par("lwd"), dotted=0,
     bg=par("bg"), col=par("col"), col.names=par("col"), fill=NULL,
     names=NULL, main=NULL, legend.x="topright", add=FALSE, plot.it=TRUE,
-    tplot=TRUE)
+    tplot=TRUE, ...)
   strip(affinity, ispecies = NULL, col = NULL, ns = NULL, 
     xticks = NULL, ymin = -0.2, xpad = 1, cex.names = 0.7)
   find.tp(x)
@@ -62,12 +62,13 @@
   \item{ymin}{numeric, lower limit of y-axis}
   \item{xpad}{numeric, amount to extend x-axis on each side}
   \item{x}{matrix, value of the \code{predominant} list element from \code{diagram}}
+  \item{...}{additional arguments passed to \code{\link{plot}} or \code{\link{barplot}}}
 }
 
 \details{
 
 \code{diagram} takes as its primary input the results from \code{\link{equilibrate}} and displays diagrams representing the equilibrium chemical activities of the species.
-0-D diagrams, at a single point, are shown as barcharts.
+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.
 The allowed variables are any that \code{\link{affinity}} accepts: temperature, pressure, or the chemical activities of the basis species

Modified: pkg/CHNOSZ/man/equilibrate.Rd
===================================================================
--- pkg/CHNOSZ/man/equilibrate.Rd	2015-10-19 18:37:20 UTC (rev 94)
+++ pkg/CHNOSZ/man/equilibrate.Rd	2015-11-05 05:18:37 UTC (rev 95)
@@ -86,7 +86,7 @@
 
 \value{
 \code{equil.reaction} and \code{equil.boltzmann} each return a list with dimensions and length equal to those of \code{Astar}, giving the \code{\link{log10}} of the equilibrium activities of the species of interest.
-\code{equilibrate} returns a list, containing first the values in \code{aout}, to which are appended \code{m.balance} (the balancing coefficients if \code{normalize} is TRUE, a vector of \samp{1}s otherwise), \code{n.balance} (the balancing coefficients if \code{normalize} is FALSE, a vector of \samp{1}s otherwise) and \code{loga.equil} (the calculated equilibrium activities of the species).
+\code{equilibrate} returns a list, containing first the values in \code{aout}, to which are appended \code{m.balance} (the balancing coefficients if \code{normalize} is TRUE, a vector of \samp{1}s otherwise), \code{n.balance} (the balancing coefficients if \code{normalize} is FALSE, a vector of \samp{1}s otherwise), \code{loga.balance}, \code{Astar}, and \code{loga.equil} (the calculated equilibrium activities of the species).
 \code{balance} returns a list containing the balancing coefficients (\code{n}) and a textual description (\code{description}).
 }
 

Modified: pkg/CHNOSZ/man/examples.Rd
===================================================================
--- pkg/CHNOSZ/man/examples.Rd	2015-10-19 18:37:20 UTC (rev 94)
+++ pkg/CHNOSZ/man/examples.Rd	2015-11-05 05:18:37 UTC (rev 95)
@@ -16,7 +16,7 @@
   demos(which = c("sources", "NaCl", "density",
     "phosphate", "nucleobase", "ORP", "diagram", "revisit", "findit", 
     "CO2Ac", "nonideal", "ionize", "buffer", "yeastgfp", "mosaic",
-    "solubility", "wjd"), do.png=FALSE)
+    "copper", "solubility", "wjd"), do.png=FALSE)
 }
 
 \details{
@@ -46,6 +46,7 @@
     \code{buffer} \tab ionized proteins as a chemical activity buffer (1. thiol peroxidases 2. sigma factors) \cr
     \code{yeastgfp} \tab logfO2-logaH2O diagrams for model proteins based on YeastGFP localizations (Dick, 2009) \cr
     \code{mosaic} \tab Eh-pH diagram with two sets of changing basis species (Garrels and Christ, 1965) \cr
+    \code{copper} \tab another example of \code{\link{mosaic}}: complexation of Cu with glycine (Aksu and Doyle, 2001) \cr
     \code{solubility} \tab solubility of calcite (cf. Manning et al., 2013) or CO2(gas) (cf. Stumm and Morgan, 1996) \cr
     \code{wjd} \tab run.wjd() with proteins: cell periphery of yeast \cr
   }
@@ -53,6 +54,8 @@
 }
 
 \references{
+  Aksu, S. and Doyle, F. M. (2001) Electrochemistry of copper in aqueous glycine solutions. \emph{J. Electrochem. Soc.} \bold{148}, B51--B57. \url{http://dx.doi.org/10.1149/1.1344532}
+
   Alberty, R. A. (2003) \emph{Thermodynamics of Biochemical Reactions}, John Wiley & Sons, Hoboken, New Jersey, 397 p. \url{http://www.worldcat.org/oclc/51242181}
 
   Dick, J. M. (2009) Calculation of the relative metastabilities of proteins in subcellular compartments of \emph{Saccharomyces cerevisiae}. \emph{BMC Syst. Biol.} \bold{3}:75. \url{http://dx.doi.org/10.1186/1752-0509-3-75}

Modified: pkg/CHNOSZ/man/swap.basis.Rd
===================================================================
--- pkg/CHNOSZ/man/swap.basis.Rd	2015-10-19 18:37:20 UTC (rev 94)
+++ pkg/CHNOSZ/man/swap.basis.Rd	2015-11-05 05:18:37 UTC (rev 95)
@@ -4,16 +4,18 @@
 \alias{element.mu}
 \alias{basis.logact}
 \alias{swap.basis}
+\alias{ibasis}
 \title{Swap Basis Species}
 \description{
   Swap the basis species defining a chemical system. One basis species is replaced by a new one with a different chemical formula.
 }
 
 \usage{
+  swap.basis(species, species2, T = 25)
   basis.matrix(basis = get("thermo")$basis)
   element.mu(basis = get("thermo")$basis, T = 25)
   basis.logact(emu, basis = get("thermo")$basis, T = 25)
-  swap.basis(species, species2, T = 25)
+  ibasis(species)
 }
 
 \arguments{
@@ -25,12 +27,17 @@
 }
 
 \details{
-  To change the basis definition, specify the names or formulas of the new basis species in the first argument. When the basis definition is changed, any species of interest that were present are deleted, unless the new basis definition has exactly the same elements as before. In that case, the species are kept and the activities of the new basis species are set so that the chemical potentials of the elements at 25 \eqn{^{\circ}}{°}C and 1 bar are unchanged.
+\code{swap.basis} allows to change the basis definition by swapping out a basis species for a new one.
+Specify the names or formulas of the old and replacement basis species in the first argument.
+When the basis definition is changed, any species of interest that were present are deleted, unless the new basis definition has exactly the same elements as before.
+In that case, the species are kept; also, the activities of the new basis species are set in order to maintain the chemical potentials of the elements at \code{T} \eqn{^{\circ}}{°}C and 1 bar.
 
+The other functions are supporting functions: \code{basis.matrix} returns the stoichiometric matrix for the current basis definition, \code{element.mu} calculates the chemical potentials of elements corresponding to the activities of the basis species, \code{basis.logact} does the inverse operation, and \code{ibasis} returns the index in the basis set for a given species index (in \code{\link{thermo}$obigt}), name or formula.
+
 }
 
 \seealso{
-  \code{\link{basis}} for defining the basis species, a prerequisite for swapping. Tests (using \code{\link[testthat]{test_that}}) showing common error conditions are in \samp{inst/tests}.
+  \code{\link{basis}} for defining the basis species, a prerequisite for swapping, and \code{\link{mosaic}}, which swaps basis species in order to calculate affinities and make diagrams with changing basis species.
 }
 
 \examples{

Modified: pkg/CHNOSZ/man/util.plot.Rd
===================================================================
--- pkg/CHNOSZ/man/util.plot.Rd	2015-10-19 18:37:20 UTC (rev 94)
+++ pkg/CHNOSZ/man/util.plot.Rd	2015-11-05 05:18:37 UTC (rev 95)
@@ -3,6 +3,8 @@
 \alias{thermo.plot.new}
 \alias{thermo.axis}
 \alias{label.plot}
+\alias{usrfig}
+\alias{label.figure}
 \alias{water.lines}
 \alias{mtitle}
 \alias{residualsplot}
@@ -21,8 +23,11 @@
     xline = NULL)
   thermo.axis(lab = "x-axis", side = 1, line = 1.5, cex = par("cex"),
     lwd = par("lwd"), T = NULL, col = par("col"))
-  label.plot(x, xfrac = 0.95, yfrac = 0.9, cex = 1, paren = TRUE, 
-    adj = 1)
+  label.plot(x, xfrac = 0.05, yfrac = 0.95, paren = FALSE,
+    italic = FALSE, ...)
+  usrfig()
+  label.figure(x, xfrac = 0.05, yfrac = 0.95, paren = FALSE,
+    italic = FALSE, ...)
   water.lines(xaxis = "pH", yaxis = "Eh", T = 298.15, P = "Psat", 
     which = c("oxidation","reduction"), logaH2O = 0, lty = 2, lwd=1,
     col = par("fg"), xpoints = NULL, O2state="gas")
@@ -55,7 +60,7 @@
   \item{xfrac}{numeric, fractional location on \eqn{x}{x}-axis for placement of label}
   \item{yfrac}{numeric, fractional location on \eqn{y}{y}-axis for placement of label}
   \item{paren}{logical, add parentheses around label text?}
-  \item{adj}{numeric, parameter for text alignment}
+  \item{italic}{logical, italicize label text?}
   \item{xaxis}{character, description of \eqn{x}{x}-axis}
   \item{yaxis}{character, description of \eqn{y}{y}-axis}
   \item{P}{numeric, pressure (bar)}
@@ -82,8 +87,13 @@
 Change this to \samp{aq} to plot the logarithm of oxygen activity (do not change it if plotting \samp{Eh}).
 \code{xpoints} is an optional list of points on the x axis to which to restrict the plotting (default of \code{NULL} refers to the axis limits).
 
-  \code{label.plot} adds identifying text to the plot; the value given for \code{x} is made into a label like \eqn{(a)}{(a)}. The location of the label is controlled by \code{xfrac} and \code{yfrac} (the fractional locations along the respective axes) as well as \code{adj} (the text alignment parameter, see \code{\link{text}}).
+\code{label.plot} and \code{label.figure} add identifying text within the plot region and figure region.
+The value given for \code{x} is made into a label, optionally italicized and with parentheses (like \ifelse{latex}{\eqn{(a)}}{\ifelse{html}{\out{(<i>a</i>)}}{(a)}}).
+The location of the label is controlled by \code{xfrac} and \code{yfrac} (the fractional coordinates of either the plot or figure region), and \code{...} can include other parameters such as \code{cex} and \code{adj} that are passed to \code{\link{text}}.
 
+\code{usrfig} returns the limits of the figure region in \dQuote{user} coordinates (i.e. the limits of the plot region, from \code{\link{par}("usr")}).
+It is a supporting function for \code{label.figure} but is also useful for other circumstances where information must be added at a particular location in a figure.
+
   \code{thermo.axis} is used to add axes and axis labels to plots, with some default style settings (rotation of numeric labels) and conversions between oxidation-reduction scales (called by \code{thermo.plot.new}). It also adds minor tick marks.
 
   \code{mtitle} can be used to add a multi-line title to a plot. It loops over each element of \code{main} and places it on a separate margin line using \code{\link{mtext}}. This function exists to facilitate using \code{\link{expression}}s in multiline titles (see \code{\link{revisit}} for an example.) 



More information about the CHNOSZ-commits mailing list