swap.basis

## Don't show: data(thermo)
thermo$obigt: 1911 aqueous, 3588 total species
## End(Don't show) ## swapping basis species # start with a preset basis definition b1 <- basis("CHNOS+") # swap H2(aq) for O2(gas) (b2 <- swap.basis("O2", "H2"))
subcrt: 6 species at 298.15 K and 1 bar (wet) subcrt: 6 species at 298.15 K and 1 bar (wet) C H N O S Z ispecies logact state CO2 1 0 0 2 0 0 1576 -3.000000 aq H2O 0 2 0 1 0 0 1 0.000000 liq NH3 0 3 1 0 0 0 66 -4.000000 aq H2S 0 2 0 0 1 0 67 -7.000000 aq H2 0 2 0 0 0 0 64 -4.657486 aq H+ 0 1 0 0 0 1 3 -7.000000 aq
# the logarithm of activity calculated for H2 # is equal to the one calculated from the equilibrium constant # for H2O = H2 + 0.5O2 logK <- subcrt(c("oxygen","H2","H2O"), c(-0.5,-1,1), T=25)$out$logK
info.character: found H2(aq), also available in gas info.character: found H2O(liq), also available in cr subcrt: 3 species at 298.15 K and 1 bar (wet)
# the equilibrium value of logaH2 # (for logaH2O = 0 and logfO2 = -80) (logaH2 <- -logK + 40)
[1] -4.657486
stopifnot(all.equal(logaH2, b2$logact[5])) # put O2 back in b3 <- swap.basis("H2", "oxygen")
subcrt: 6 species at 298.15 K and 1 bar (wet) subcrt: 6 species at 298.15 K and 1 bar (wet)
# we have returned to starting point stopifnot(all.equal(b1$logact, b3$logact)) ## demonstrating the interconvertibility between ## chemical potentials of elements and logarithms ## of activities of basis species at high temperature #basis("CHNOS+") #bl1 <- basis()$logact #emu <- element.mu(T=100) #bl2 <- basis.logact(emu, T=100) ## note that basis.logact produces a named array #stopifnot(all.equal(bl1, as.numeric(bl2))) ## swapping basis species while species are defined ## and using numeric species indices basis("MgCHNOPS+")
C H Mg N O P S Z ispecies logact state Mg+2 0 0 1 0 0 0 0 2 9 -3 aq CO2 1 0 0 0 2 0 0 0 1576 -3 aq H2O 0 2 0 0 1 0 0 0 1 0 liq NH3 0 3 0 1 0 0 0 0 66 -4 aq H3PO4 0 3 0 0 4 1 0 0 70 -3 aq H2S 0 2 0 0 0 0 1 0 67 -7 aq e- 0 0 0 0 0 0 0 -1 2 -7 aq H+ 0 1 0 0 0 0 0 1 3 -7 aq
# load some Mg-ATP species species(c("MgATP-2", "MgHATP-", "MgH2ATP", "Mg2ATP"))
Mg+2 CO2 H2O NH3 H3PO4 H2S e- H+ ispecies logact state name 1 1 10 -19 5 3 0 30 26 1820 -3 aq MgATP-2 2 1 10 -19 5 3 0 30 27 1821 -3 aq MgHATP- 3 1 10 -19 5 3 0 30 28 1822 -3 aq MgH2ATP 4 2 10 -19 5 3 0 30 26 1823 -3 aq Mg2ATP
# swap in CO2(g) for CO2(aq) iCO2g <- info("CO2", "gas") swap.basis("CO2", iCO2g)
subcrt: 8 species at 298.15 K and 1 bar (wet) subcrt: 8 species at 298.15 K and 1 bar (wet) C H Mg N O P S Z ispecies logact state Mg+2 0 0 1 0 0 0 0 2 9 -3.000000e+00 aq CO2 1 0 0 0 2 0 0 0 3308 -1.531055e+00 gas H2O 0 2 0 0 1 0 0 0 1 1.066665e-14 liq NH3 0 3 0 1 0 0 0 0 66 -4.000000e+00 aq H3PO4 0 3 0 0 4 1 0 0 70 -3.000000e+00 aq H2S 0 2 0 0 0 0 1 0 67 -7.000000e+00 aq e- 0 0 0 0 0 0 0 -1 2 -7.000000e+00 aq H+ 0 1 0 0 0 0 0 1 3 -7.000000e+00 aq
a1 <- affinity()
energy.args: temperature is 25 C energy.args: pressure is Psat subcrt: 12 species at 298.15 K and 1 bar (wet)
# swap in CH4(g) for CO2(g) iCH4g <- info("CH4", "gas") swap.basis(iCO2g, iCH4g)
subcrt: 8 species at 298.15 K and 1 bar (wet) subcrt: 8 species at 298.15 K and 1 bar (wet) C H Mg N O P S Z ispecies logact state Mg+2 0 0 1 0 0 0 0 2 9 -3.000000e+00 aq CH4 1 4 0 0 0 0 0 0 3307 -9.062912e+01 gas H2O 0 2 0 0 1 0 0 0 1 2.133330e-14 liq NH3 0 3 0 1 0 0 0 0 66 -4.000000e+00 aq H3PO4 0 3 0 0 4 1 0 0 70 -3.000000e+00 aq H2S 0 2 0 0 0 0 1 0 67 -7.000000e+00 aq e- 0 0 0 0 0 0 0 -1 2 -7.000000e+00 aq H+ 0 1 0 0 0 0 0 1 3 -7.000000e+00 aq
a2 <- affinity()
energy.args: temperature is 25 C energy.args: pressure is Psat subcrt: 12 species at 298.15 K and 1 bar (wet)
# the equilibrium fugacity of CH4 is *very* low # swap in CO2(aq) for CH4(g) iCO2a <- info("CO2", "aq") swap.basis(iCH4g, iCO2a)
subcrt: 8 species at 298.15 K and 1 bar (wet) subcrt: 8 species at 298.15 K and 1 bar (wet) C H Mg N O P S Z ispecies logact state Mg+2 0 0 1 0 0 0 0 2 9 -3.000000e+00 aq CO2 1 0 0 0 2 0 0 0 1576 -3.000000e+00 aq H2O 0 2 0 0 1 0 0 0 1 3.199995e-14 liq NH3 0 3 0 1 0 0 0 0 66 -4.000000e+00 aq H3PO4 0 3 0 0 4 1 0 0 70 -3.000000e+00 aq H2S 0 2 0 0 0 0 1 0 67 -7.000000e+00 aq e- 0 0 0 0 0 0 0 -1 2 -7.000000e+00 aq H+ 0 1 0 0 0 0 0 1 3 -7.000000e+00 aq
a3 <- affinity()
energy.args: temperature is 25 C energy.args: pressure is Psat subcrt: 12 species at 298.15 K and 1 bar (wet)
# swapping the basis species didn't affect the affinities # of the formation reactions of the species, since # the chemical potentials of the elements were unchanged stopifnot(all.equal(a1$values, a2$values)) stopifnot(all.equal(a1$values, a3$values))