[CHNOSZ-commits] r364 - in pkg/CHNOSZ: . R inst tests/testthat
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Wed Jan 23 10:10:18 CET 2019
Author: jedick
Date: 2019-01-23 10:10:17 +0100 (Wed, 23 Jan 2019)
New Revision: 364
Modified:
pkg/CHNOSZ/DESCRIPTION
pkg/CHNOSZ/R/equilibrate.R
pkg/CHNOSZ/R/solubility.R
pkg/CHNOSZ/inst/NEWS
pkg/CHNOSZ/tests/testthat/test-equilibrate.R
pkg/CHNOSZ/tests/testthat/test-solubility.R
pkg/CHNOSZ/tests/testthat/test-water.lines.R
Log:
balance(): produce error if no basis species is present in all formation reactions
Modified: pkg/CHNOSZ/DESCRIPTION
===================================================================
--- pkg/CHNOSZ/DESCRIPTION 2019-01-23 04:37:46 UTC (rev 363)
+++ pkg/CHNOSZ/DESCRIPTION 2019-01-23 09:10:17 UTC (rev 364)
@@ -1,6 +1,6 @@
Date: 2019-01-23
Package: CHNOSZ
-Version: 1.1.3-71
+Version: 1.1.3-72
Title: Thermodynamic Calculations and Diagrams for Geo(bio)chemistry
Authors at R: c(
person("Jeffrey", "Dick", , "j3ffdick at gmail.com", role = c("aut", "cre"),
Modified: pkg/CHNOSZ/R/equilibrate.R
===================================================================
--- pkg/CHNOSZ/R/equilibrate.R 2019-01-23 04:37:46 UTC (rev 363)
+++ pkg/CHNOSZ/R/equilibrate.R 2019-01-23 09:10:17 UTC (rev 364)
@@ -271,8 +271,8 @@
# try to automatically find a balance
if(is.null(balance)) {
ibalance <- which.balance(aout$species)
- # no shared basis species - balance on one mole of species
- if(length(ibalance) == 0) balance <- 1
+ # no shared basis species and balance not specified by user - an error
+ if(length(ibalance) == 0) stop("no basis species is present in all formation reactions")
}
# change "1" to 1 (numeric) 20170206
if(identical(balance, "1")) balance <- 1
Modified: pkg/CHNOSZ/R/solubility.R
===================================================================
--- pkg/CHNOSZ/R/solubility.R 2019-01-23 04:37:46 UTC (rev 363)
+++ pkg/CHNOSZ/R/solubility.R 2019-01-23 09:10:17 UTC (rev 364)
@@ -20,15 +20,11 @@
if(is.null(dissociation)) {
# assume FALSE unless determined otherwise
dissociation <- FALSE
- # react the first basis species to form the first species
- sres <- suppressMessages(subcrt(c(rownames(aout$basis)[1], aout$species$name[1]), c(-1, 1)))
- # note that the reaction is auto-balanced using all the basis species
- # if the reaction involves the second basis species, we consider it to be a dissociation reaction
- if(rownames(aout$basis)[2] %in% sres$reaction$formula) {
+ # if the reaction to form the first species involves the second basis species, we consider it to be a dissociation reaction
+ if(aout$species[1, 2] != 0) {
# however, if the second basis species is H2O, H+, e-, O2 (or others?), we don't have enough information, so stop
- if(rownames(aout$basis)[2] %in% c("H2O", "H+", "e-", "O2")) {
- print(sres$reaction)
- stop("unsure whether this is a dissociation reaction. if it is, redefine the basis to put a product ion second")
+ if(colnames(aout$species)[2] %in% c("H2O", "H+", "e-", "O2")) {
+ stop("Unsure whether the first formation reaction is a dissociation reaction.\nSet the 'dissociation' argument to TRUE or FALSE, or redefine the basis to put a product ion second.")
}
dissociation <- TRUE
}
Modified: pkg/CHNOSZ/inst/NEWS
===================================================================
--- pkg/CHNOSZ/inst/NEWS 2019-01-23 04:37:46 UTC (rev 363)
+++ pkg/CHNOSZ/inst/NEWS 2019-01-23 09:10:17 UTC (rev 364)
@@ -1,17 +1,16 @@
-CHANGES IN CHNOSZ 1.1.3-71 (2019-01-23)
+CHANGES IN CHNOSZ 1.1.3-72 (2019-01-23)
---------------------------------------
BUG FIXES
+- Fix bug in nonideal() where "Zn" in formula was identified as charge.
+ Thanks to Feng Lai for the bug report.
+
- Fix a bug where subcrt()$reaction$coeffs was incorrect for reactions
involving minerals with phase transitions. Also ensure that the output
reaction stoichiometry is correct for duplicated species in reactions.
Thanks to Grayson Boyer for the bug report.
-- Fix bug in nonideal() where "Zn" in formula was identified as charge.
- Thanks to Feng Lai for reporting the incorrect behavior caused by
- this bug.
-
- For species in the revised HKF model, subcrt() now sets properties to
NA where the density of H2O is less than 0.35 g/cm3, avoiding the
output of bogus values in this region. Thanks to Evgeniy Bastrakov.
@@ -20,6 +19,14 @@
Gibbs energy of mixing. An example using mosaic() to calculate the
pH-dependent solubility of calcite has been added to solubility.Rd.
+- For systems where no basis species is present in all formation
+ reactions, and the user hasn't provided balance coefficients, stop
+ with an error instead of setting the balance cofficients to 1.
+ Thanks to Shuang Kong for an example calculation and Tucker Ely for
+ a previous request to produce an error here. The affected code is in
+ balance(), an unexported function used in equilibrate() and
+ diagram() (and now also solubility()).
+
NEW FEATURE: SOLUBILITY CALCULATIONS
- Add solubility(). Run this after affinity() to calculate the
Modified: pkg/CHNOSZ/tests/testthat/test-equilibrate.R
===================================================================
--- pkg/CHNOSZ/tests/testthat/test-equilibrate.R 2019-01-23 04:37:46 UTC (rev 363)
+++ pkg/CHNOSZ/tests/testthat/test-equilibrate.R 2019-01-23 09:10:17 UTC (rev 364)
@@ -24,9 +24,10 @@
expect_message(equilibrate(aacid), "loga.balance is -2.221848")
expect_message(equilibrate(aacid, loga.balance=-3), "loga.balance is -3")
expect_error(equilibrate(aacid, balance="length"), "some species are not proteins")
- expect_message(equilibrate(aacidS), "balance: from numeric argument value")
- expect_message(equilibrate(aacidS), "n.balance is 1 1 1 1 1")
- expect_message(equilibrate(aacidS), "loga.balance is -2.301029")
+ expect_error(equilibrate(aacidS), "no basis species is present in all formation reactions")
+ expect_message(equilibrate(aacidS, balance=1), "balance: from numeric argument value")
+ expect_message(equilibrate(aacidS, balance=1), "n.balance is 1 1 1 1 1")
+ expect_message(equilibrate(aacidS, balance=1), "loga.balance is -2.301029")
expect_error(equilibrate(aacidS, balance="CO2"), "some species have no CO2 in the formation reaction")
expect_message(equilibrate(aprot), "balance: from protein length")
expect_message(equilibrate(aprot), "n.balance is 129 153 124 104")
Modified: pkg/CHNOSZ/tests/testthat/test-solubility.R
===================================================================
--- pkg/CHNOSZ/tests/testthat/test-solubility.R 2019-01-23 04:37:46 UTC (rev 363)
+++ pkg/CHNOSZ/tests/testthat/test-solubility.R 2019-01-23 09:10:17 UTC (rev 364)
@@ -48,5 +48,5 @@
basis(c("calcite", "H2O", "Ca+2", "O2", "H+"))
species(c("CO2", "HCO3-", "CO3-2"))
a <- affinity()
- expect_error(solubility(a), "unsure whether this is a dissociation reaction")
+ expect_error(solubility(a), "Unsure whether the first formation reaction is a dissociation reaction.")
})
Modified: pkg/CHNOSZ/tests/testthat/test-water.lines.R
===================================================================
--- pkg/CHNOSZ/tests/testthat/test-water.lines.R 2019-01-23 04:37:46 UTC (rev 363)
+++ pkg/CHNOSZ/tests/testthat/test-water.lines.R 2019-01-23 09:10:17 UTC (rev 364)
@@ -7,7 +7,7 @@
limit.water <- TRUE
# function to count the number of species on a diagram (not including NA fields)
-nspecies <- function(a) length(na.omit(unique(as.numeric(diagram(a, limit.water=limit.water, plot.it=plot.it)$predominant))))
+nspecies <- function(a) length(na.omit(unique(as.numeric(diagram(a, limit.water=limit.water, plot.it=plot.it, balance=1)$predominant))))
res <- 25
More information about the CHNOSZ-commits
mailing list