## ----setup, include = FALSE--------------------------------------------------- library(CHNOSZ) options(width = 80) ## Use pngquant to optimize PNG images library(knitr) knit_hooks$set(pngquant = hook_pngquant) pngquant <- "--speed=1 --quality=0-25" if (!nzchar(Sys.which("pngquant"))) pngquant <- NULL # Set dpi 20231129 knitr::opts_chunk$set( dpi = if(nzchar(Sys.getenv("CHNOSZ_BUILD_LARGE_VIGNETTES"))) 100 else 72 ) ## ----HTML, include = FALSE---------------------------------------------------- NOTE <- 'NOTE' # OBIGT columns model <- 'model' name <- 'name' abbrv <- 'abbrv' formula <- 'formula' state <- 'state' ref1 <- 'ref1' ref2 <- 'ref2' date <- 'date' E_units <- 'E_units' b <- 'b' c <- 'c' e <- 'e' f <- 'f' lambda <- 'lambda' c1 <- 'c1' c2 <- 'c2' omega <- 'omega' G_ <- 'G' H_ <- 'H' S_ <- 'S' Cp_ <- 'Cp' V_ <- 'V' T_ <- 'T' # CHNOSZ functions reset_ <- 'reset()' OBIGT_ <- 'OBIGT()' add.OBIGT_ <- 'add.OBIGT()' mod.OBIGT_ <- 'mod.OBIGT()' logB.to.OBIGT_ <- 'logB.to.OBIGT()' basis_ <- 'basis()' species_ <- 'species()' E.units_ <- 'E.units()' info_ <- 'info()' subcrt_ <- 'subcrt()' affinity_ <- 'affinity()' thermo.refs_ <- 'thermo.refs()' thermo_ <- 'thermo()' check.GHS_ <- 'check.GHS()' check.EOS_ <- 'check.EOS()' # Math stuff logK <- "log K" logB <- "log β" F_ <- "F-" Hplus <- "H+" HWO4_ <- "HWO4-" H2WO4 <- "H2WO4" H3WO4F2_ <- "H3WO4F2-" # Thermodynamic properties Cp_0 <- "Cp°" DG_0 <- "ΔG°" ## ----system.file-------------------------------------------------------------- system.file("extdata/OBIGT", package = "CHNOSZ") ## ----dir.system.file---------------------------------------------------------- dir(system.file("extdata/OBIGT", package = "CHNOSZ")) ## ----reset_------------------------------------------------------------------- reset() ## ----thermo.OBIGT------------------------------------------------------------- head(thermo()$OBIGT) ## ----colnames.OBIGT, echo = FALSE--------------------------------------------- paste(1:22, colnames(thermo()$OBIGT)) ## ----icr, message = FALSE----------------------------------------------------- icr <- info(c("orpiment,amorphous", "arsenic,alpha", "tin")) thermo()$OBIGT[icr, ] ## ----orpiment----------------------------------------------------------------- subcrt("orpiment,amorphous", T = c(25, 50, 75))$out[[1]] ## ----arsenic------------------------------------------------------------------ subcrt("arsenic,alpha", T = c(25, 50, 75))$out[[1]] ## ----tin---------------------------------------------------------------------- subcrt("tin", T = c(25, 50, 75))$out[[1]] ## ----info_.tin---------------------------------------------------------------- info(info("tin")) ## ----Berman------------------------------------------------------------------- info(info(c("quartz", "pyrite"))) ## ----add.OBIGT_quartz--------------------------------------------------------- add.OBIGT("SUPCRT92", "quartz") info(info("quartz")) ## ----add.OBIGT_SUPCRT92------------------------------------------------------- iSUPCRT92 <- add.OBIGT("SUPCRT92") unique(suppressMessages(info(iSUPCRT92))$name) ## ----BZA10-------------------------------------------------------------------- file <- system.file("extdata/adds/BZA10.csv", package = "CHNOSZ") read.csv(file, as.is = TRUE) ## ----BZA10_Cd----------------------------------------------------------------- iCd <- add.OBIGT(file) subcrt(c("CdCl+", "Cl-", "CdCl2"), c(-1, -1, 1), T = 25, P = c(1, 2000)) ## ----SSH97_subcrt------------------------------------------------------------- reset() thermo.refs(iCd)[, 1:3] subcrt(c("CdCl+", "Cl-", "CdCl2"), c(-1, -1, 1), T = 25, P = c(1, 2000)) ## ----mod.OBIGT__CoCl4_ghs----------------------------------------------------- mod.OBIGT("CoCl4-2", formula = "CoCl4-2", state = "aq", ref1 = "LBT+11", E_units = "cal", date = as.character(Sys.Date()), G = -134150, H = -171558, S = 19.55, Cp = 72.09, V = 27.74) ## ----mod.OBIGT__CoCl4_eos----------------------------------------------------- mod.OBIGT("CoCl4-2", a1 = 6.5467, a2 = 8.2069, a3 = 2.0130, a4 = -3.1183, c1 = 76.3357, c2 = 11.6389, omega = 2.9159, z = -2) ## ----CoCl4_reaction, message = FALSE, echo = 1:3------------------------------ T <- c(25, seq(50, 350, 50)) sres <- subcrt(c("Co+2", "Cl-", "CoCl4-2"), c(-1, -4, 1), T = T) round(sres$out$logK, 2) stopifnot(identical(round(sres$out$logK, 2), c(-3.2, -2.96, -2.02, -0.74, 0.77, 2.5, 4.57, 7.29))) ## ----info__CoCl4, results = "hide"-------------------------------------------- inew <- info("CoCl4-2") info(inew) ## ----mod.OBIGT__magnesiochromite_ghs------------------------------------------ H <- -1762000 S <- 119.6 V <- 43.56 mod.OBIGT("magnesiochromite", formula = "MgCr2O4", state = "cr", ref1 = "KOSG00", date = as.character(Sys.Date()), E_units = "J", H = H, S = S, V = V) ## ----mod.OBIGT__magnesiochromite_eos------------------------------------------ a <- 221.4 b <- -0.00102030 c <- -1757210 d <- -1247.9 mod.OBIGT("magnesiochromite", E_units = "J", a = a, b = b, c = c, d = d, e = 0, f = 0, lambda = 0, T = 1500) ## ----subcrt__magnesiochromite------------------------------------------------- T.units("K") Tref <- c(250, 300, 340) (sres <- subcrt("magnesiochromite", property = "Cp", T = Tref, P = 1)) ## ----magnesiochromite_check_Cp------------------------------------------------ Cpref <- c(114.3, 129.8, 138.4) stopifnot(max(abs(sres$out[[1]]$Cp - Cpref)) < 0.3) ## ----restore_units_magnesiochromite------------------------------------------- T.units("C") ## ----Psat--------------------------------------------------------------------- P <- "Psat" ## ----HWO4_-------------------------------------------------------------------- T <- c(250, 300, 350) logB <- c(5.58, 6.51, 7.99) species <- c("WO4-2", "H+", "HWO4-") coeff <- c(-1, -1, 1) logB.to.OBIGT(logB, species, coeff, T, P) ## ----H3WO4F2------------------------------------------------------------------ T <- seq(100, 250, 25) logB <- c(17.00, 17.11, 17.46, 17.75, 18.17, 18.71, 19.23) # Species and coefficients in the formation reaction species <- c("H+", "WO4-2", "F-", "H3WO4F2-") coeff <- c(-3, -1, -2, 1) logB.to.OBIGT(logB, species, coeff, T, P) ## ----H2WO4-------------------------------------------------------------------- logB <- c(7.12, 7.82, 7.07, 7.76, 7.59, 7.98, 8.28) species <- c("H+", "WO4-2", "H2WO4") coeff <- c(-2, -1, 1) logB.to.OBIGT(logB, species, coeff, T, P, tolerance = 0.3) ## ----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") species(iaq) a <- affinity(pH = c(2, 7), T = 300, IS = 0.9) e <- equilibrate(a) col <- c(1, 4, 5, 2) diagram(e, alpha = TRUE, col = col, lty = 1, lwd = 2, ylab = "Fraction total W") ## ----a_F---------------------------------------------------------------------- T <- 300 pH <- seq(2, 7, 0.1) logK_HF <- subcrt(c("H+", "F-", "HF"), c(-1, -1, 1), T = T, IS = 0.9)$out$logK F_tot <- 0.1 a_F <- F_tot / (1 + 10^(logK_HF - pH)) ## ----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) a <- affinity(pH = pH, "F-" = log10(a_F), T = T, IS = 0.9) e <- equilibrate(a) diagram(e, alpha = TRUE, col = col, lty = 1, lwd = 2, ylab = "Fraction total W")