Learn R Programming

CHNOSZ (version 0.9-7)

findit: Multidimensionally Optimize Chemical Activities

Description

Use a gridded search to find a combination of one or more of chemical activities of basis species, temperature and/or pressure that maximize or minimize a target function of the metastable equilibrium chemical activities of the species of interest.

Usage

findit (lims = list(), target = "cv", n = NULL, iprotein = NULL, 
    do.plot = TRUE, T = 25, P = "Psat", res = NULL, labcex = 0.6, 
    loga.ref = NULL, as.residue = FALSE, loga.tot = 0)
  ## S3 method for class 'findit':
plot(x, which=NULL, mar=c(3.5,5,2,2), xlab="iteration", ...)

Arguments

lims
list, specification of search limits.
target
character, target statistic to optimize.
n
numeric, number of iterations.
res
numeric, grid resolution (number of points on one edge).
iprotein
numeric, indices of proteins.
do.plot
logical, make a plot?
T
numeric, temperature.
P
numeric, pressure; or character, "Psat".
labcex
numeric, character expansion for plot labels.
loga.ref
numeric, reference logarithms of activity of species.
as.residue
logical, use the activities of residues instead of proteins?
loga.tot
numeric, logarithm of total activity of residues (or other immobile component).
x
list, object of class findit.
which
numeric, which of the parameters to plot.
mar
numeric, plot margin specification.
xlab
character, x-axis label.
...
additional arguments passed to plot.

Value

  • findit returns a list having class findit with elements value (values of the parameters, and value of the target statistic, at each iteration), lolim (lower limits of the parameters) and hilim (upper limits of the parameters).

Details

findit implements a gridded optimization to find the minimum or maximum value of target as a function of one or more of the chemical activities, temperature and/or pressure whose ranges are listed in lims. Any target available in revisit can be optimized. Generally, the system (basis species and species of interest) must be set up before calling this function. If iprotein is supplied, indicating a set of proteins to use in the calculation, the definition of the species is not required.

lims is a list, each element of which contains two values indicating the range of the parameter indicated by the names of lims. The names should be formula(s) of one or more of the basis speices, T and/or P. If the latter two are missing, the calculations are performed at isothermal and/or isobaric conditions indicated by T and P.

It can be used for one, two, or more parameters. If $nd$ is the number of parameters (dimensions), default values of n and res come from the following table. These settings are selected mostly for quickness of testing the function in high-dimensional space. Detailed studies of a system might have to use more iterations and/or higher resolutions.

rrrrr{ nd n res res^nd rat 1 4 128 128 2/(1+sqrt(5)) 2 6 64 4096 2/(1+sqrt(5)) 3 6 16 4096 0.75 4 8 8 4096 0.8 5 12 6 7776 0.8 6 12 4 4096 0.85 7 12 4 16384 0.85 }

The function performs n iterations. At first, the limits of the parameters given in lims define the extent of a $nd$-dimensional box around the space of interest. The value of target is calculated at each of the $res^{nd}$ grid points and and optimum value located (see revisit and where.extreme). In the next iteration the new search box is centered on the location of the optimum value, and the edges are shrunk so their length is rat * the length in the previous step. If the limits of any of the parameters extend beyond those in lims, they are pushed in to fit (preserving the difference between them).

plot.findit plots the values of the parameters and the target statistic as a function of the number of iterations.

Examples

Run this code
data(thermo)
# an inorganic example: sulfur species
  basis("CHNOS+")
  basis("pH",5)
  species(c("H2S","S2-2","S3-2","S2O3-2","S2O4-2","S3O6-2",
    "S5O6-2","S2O6-2","HSO3-","SO2","HSO4-"))
  # to minimize the standard deviations of the loga of the species
  target <- "sd"
  # this one gives logfO2=-27.8
  f1 <- findit(list(O2=c(-50,-15)),target,T=325,P=350,n=3)
  title("SD of equilibrium log activities of sulfur species")
  # this one gives logfO2=-30.0 pH=9.38
  f2 <- findit(list(O2=c(-50,-15),pH=c(0,14)),target,T=325,P=350,res=16,n=4)
  title("SD of equilibrium log activities of sulfur species")

  # test the findit function in three dimensions
  # first calculate equilibrium activities of some proteins
  # using specified activities of basis species
  ip <- 1:20
  basis("CHNOS+")
  basis("CO2",-pi)        # -3.141593
  basis("H2O",-exp(1))    # -2.718282
  basis("NH3",-sqrt(2))   # -1.414214
  a <- affinity(iprotein=ip)
  # scale relative abundances such that total activity of residues 
  # is unity (since loga.tot=0 is default for findit)
  d <- diagram(a,do.plot=FALSE,logact=0)
  loga.ref <- as.numeric(d$logact)
  # return to default values for activities of basis species,
  basis("CHNOS+")
  a <- affinity(iprotein=ip)
  d <- diagram(a,do.plot=FALSE,logact=0)
  # we have diverged from the reference activities of proteins
  r0 <- revisit(d,"rmsd",loga.ref,main="")
  title(main=paste("log activities of 20 proteins for basis activities",
    "from numerical constants (ref) and CHNOSZ default (calc)",sep="\n"))
  # now find the activities of the basis species, within search 
  # intervals, that get us close to reference activities of proteins
  f <- findit(lims=list(CO2=c(-5,0),H2O=c(-5,0),NH3=c(-5,0)),
    "rmsd",10,iprotein=ip,loga.ref=loga.ref,res=16)
  title(main="RMSD of log activities from reference values")
  # -pi, -e and -sqrt(2) were approximately retrieved!
  -sapply(f$value,tail,1)[1:3]
  # we can plot the trajectories
  plot(f,mar=c(4,5,2,2))

Run the code above in your browser using DataLab