[CHNOSZ-commits] r953 - in pkg/CHNOSZ: . R inst inst/tinytest man vignettes
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Wed Jan 7 09:12:09 CET 2026
Author: jedick
Date: 2026-01-07 09:12:08 +0100 (Wed, 07 Jan 2026)
New Revision: 953
Modified:
pkg/CHNOSZ/DESCRIPTION
pkg/CHNOSZ/R/phosphorylate.R
pkg/CHNOSZ/inst/NEWS.Rd
pkg/CHNOSZ/inst/tinytest/test-phosphorylate.R
pkg/CHNOSZ/man/phosphorylate.Rd
pkg/CHNOSZ/vignettes/anintro.Rmd
Log:
Add tests for phosphorylate() and phospho_plot()
Modified: pkg/CHNOSZ/DESCRIPTION
===================================================================
--- pkg/CHNOSZ/DESCRIPTION 2026-01-06 11:14:02 UTC (rev 952)
+++ pkg/CHNOSZ/DESCRIPTION 2026-01-07 08:12:08 UTC (rev 953)
@@ -1,6 +1,6 @@
-Date: 2026-01-06
+Date: 2026-01-07
Package: CHNOSZ
-Version: 2.2.0-19
+Version: 2.2.0-20
Title: Thermodynamic Calculations and Diagrams for Geochemistry
Authors at R: c(
person("Jeffrey", "Dick", , "j3ffdick at gmail.com", role = c("aut", "cre"),
Modified: pkg/CHNOSZ/R/phosphorylate.R
===================================================================
--- pkg/CHNOSZ/R/phosphorylate.R 2026-01-06 11:14:02 UTC (rev 952)
+++ pkg/CHNOSZ/R/phosphorylate.R 2026-01-07 08:12:08 UTC (rev 953)
@@ -193,6 +193,8 @@
c("H3ADP", "H2ADP-", "HADP-2", "ADP-3", "Mg2ADP+", "MgHADP", "MgADP-"),
c("H3PO4", "H2PO4-", "HPO4-2", "PO4-3")
)
+ } else {
+ stop(paste("unrecognized P_source:", P_source))
}
basis("pH", const_pH)
basis("Mg+2", loga_Mg)
@@ -218,7 +220,7 @@
} # end of phosphorylate()
# Define a function to make the plots for a given reaction
-phospho_plot <- function(reactant, P_source, loga_Mg = -999) {
+phospho_plot <- function(reactant, P_source, loga_Mg = -999, res = 50) {
# Reaction-independent settings (activities of species)
# The product (phosphorylated species)
@@ -237,7 +239,6 @@
pH <- c(0, 12)
T <- c(0, 200)
P <- c(1, 5000)
- res <- 50
# Define which contour levels to show
levels <- c(-1e6, seq(-100, 100, 10), 1e6)
Modified: pkg/CHNOSZ/inst/NEWS.Rd
===================================================================
--- pkg/CHNOSZ/inst/NEWS.Rd 2026-01-06 11:14:02 UTC (rev 952)
+++ pkg/CHNOSZ/inst/NEWS.Rd 2026-01-07 08:12:08 UTC (rev 953)
@@ -15,7 +15,7 @@
\newcommand{\Cp}{\ifelse{latex}{\eqn{C_P}}{\ifelse{html}{\out{<I>C<sub>P</sub></I>}}{Cp}}}
\newcommand{\DG0}{\ifelse{latex}{\eqn{{\Delta}G^{\circ}}}{\ifelse{html}{\out{Δ<I>G</I>°}}{ΔG°}}}
-\section{Changes in CHNOSZ version 2.2.0-17 (2026-01-06)}{
+\section{Changes in CHNOSZ version 2.2.0-20 (2026-01-07)}{
\itemize{
@@ -52,6 +52,10 @@
\item Remove \code{lex()}, which only wrapped its argument in
\code{as.expression(c())}.
+ \item Remove unused subroutines in \file{src/H2O92D.f}: \code{valTD},
+ \code{Psublm}, \code{TsHGK}, \code{TdPsdT}, \code{tcorr}, and
+ \code{cpswap}.
+
}
}
Modified: pkg/CHNOSZ/inst/tinytest/test-phosphorylate.R
===================================================================
--- pkg/CHNOSZ/inst/tinytest/test-phosphorylate.R 2026-01-06 11:14:02 UTC (rev 952)
+++ pkg/CHNOSZ/inst/tinytest/test-phosphorylate.R 2026-01-07 08:12:08 UTC (rev 953)
@@ -1,4 +1,4 @@
-# 20251207
+# Test added on 20251207
# First add thermodynamic data for sugar phosphates (from Table 3.2 of Alberty, 2003)
mod.OBIGT("glucose-6-phosphate-2", formula = "C6H11O9P-2", G = -1763940)
@@ -10,7 +10,8 @@
# Calculate affinity at pH 5-9 with unit activities (loga = 0)
pH <- 5:9
-result <- phosphorylate("glucose", "ATP", pH = pH)
+info <- "phosphorylate() runs without error"
+expect_silent(result <- phosphorylate("glucose", "ATP", pH = pH), info = info)
# Extract the overall affinity
A <- result$a12
@@ -33,3 +34,85 @@
deltaG_J <- convert(A, "G", T = TK)
deltaG_kJ <- deltaG_J / 1000
expect_equal(round(as.numeric(deltaG_kJ), 2), -32.15, info = info)
+
+# Tests added on 20260107
+
+info <- "phospho_plot() doesn't error"
+# Save plot to a temporary PNG file
+pngfile <- tempfile(fileext = ".png")
+png(pngfile)
+expect_silent(phospho_plot("adenosine_to_AMP", "PP", loga_Mg = -5, res = 50), info = info)
+# Close the graphics device and remove the temporary PNG file
+dev.off()
+file.remove(pngfile)
+
+info <- "Tests for more species"
+
+# Acetate phosphorylation: circular reference
+# Delta G0 from Table 3.2 of Alberty (2003)
+mod.OBIGT("acetylphosphate0", formula = "C2H5O5P", G = -1298260)
+mod.OBIGT("acetylphosphate-1", formula = "C2H4O5P-", G = -1268080)
+mod.OBIGT("acetylphosphate-2", formula = "C2H3O5P-2", G = -1219390)
+# Alberty doesn't have acetylphosphate-3, so we just use an arbitrarily high number
+mod.OBIGT("acetylphosphate-3", formula = "C2H2O5P-3", G = 0)
+# This is the dimensionless affinity (A/2.303RT) of the reaction
+affinity_nodim <- as.numeric(phosphorylate("acetic acid", "P")$a12)
+expect_equal(affinity_nodim, -6.20, tolerance = 0.01, scale = 1)
+
+# Glycerol phosphorylation: reference value from p. 295 of Alberty (2003)
+mod.OBIGT("3-phosphoglycerol", formula = "C3H9O6P", G = 0)
+mod.OBIGT("3-phosphoglycerol-1", formula = "C3H8O6P-", G = -1397040)
+mod.OBIGT("3-phosphoglycerol-2", formula = "C3H7O6P-2", G = -1358960)
+affinity_nodim <- as.numeric(phosphorylate("glycerol", "P")$a12)
+expect_equal(convert(affinity_nodim, "G"), -1780.75, tolerance = 1200, scale = 1)
+
+# Adenosine phosphorylation (to AMP): reference value from p. 295 of Alberty (2003)
+affinity_nodim <- as.numeric(phosphorylate("adenosine_to_AMP", "P")$a12)
+expect_equal(convert(affinity_nodim, "G"), 12969.6, tolerance = 500, scale = 1)
+
+# Adenosine phosphorylation (model 2)
+# adenosine_for_RNA excludes PO4-3 and AMP-2 (polymerization model from LaRowe and Dick, 2025)
+affinity_nodim <- as.numeric(phosphorylate("adenosine_for_RNA", "P")$a12)
+# For this let's use the same reference value as above, but with a greater expected difference
+expect_equal(convert(affinity_nodim, "G"), 12969.6, tolerance = 7000, scale = 1)
+
+# Adenosine phosphorylation (to cAMP): circular reference
+# Delta G0 are placeholder values
+mod.OBIGT("cyclic-HAMP", formula = "C10H12N5O6P", G = 0)
+mod.OBIGT("cyclic-AMP-1", formula = "C10H11N5O6P-", G = 0)
+affinity_nodim <- as.numeric(phosphorylate("adenosine_to_cAMP", "P")$a12)
+expect_equal(affinity_nodim, -149.20, tolerance = 0.01, scale = 1)
+
+# Ribose phosphorylation: circular reference
+affinity_nodim <- as.numeric(phosphorylate("ribose", "P")$a12)
+expect_equal(affinity_nodim, -3.75, tolerance = 0.01, scale = 1)
+
+# Uridine phosphorylation: circular reference
+affinity_nodim <- as.numeric(phosphorylate("uridine", "P")$a12)
+expect_equal(affinity_nodim, -2.24, tolerance = 0.01, scale = 1)
+
+# AMP phosphorylation: circular reference
+affinity_nodim <- as.numeric(phosphorylate("AMP", "P")$a12)
+expect_equal(affinity_nodim, -5.83, tolerance = 0.01, scale = 1)
+
+# ADP phosphorylation: circular reference
+affinity_nodim <- as.numeric(phosphorylate("ADP", "P")$a12)
+expect_equal(affinity_nodim, -6.52, tolerance = 0.01, scale = 1)
+
+# Pyruvate phosphorylation with ATP: reference value from p. 224 of Alberty (2003)
+mod.OBIGT("phosphoenolpyruvate", formula = "C3H5O6P", G = 0)
+mod.OBIGT("phosphoenolpyruvate-1", formula = "C3H4O6P-", G = 0)
+mod.OBIGT("phosphoenolpyruvate-2", formula = "C3H3O6P-2", G = -1303610)
+mod.OBIGT("phosphoenolpyruvate-3", formula = "C3H2O6P-3", G = -1263650)
+affinity_nodim <- as.numeric(phosphorylate("pyruvic acid", "ATP")$a12)
+expect_equal(convert(affinity_nodim, "G"), 30622.4, tolerance = 4000, scale = 1)
+
+# Pyruvate phosphorylation with acetylphosphate: circular reference
+affinity_nodim <- as.numeric(phosphorylate("pyruvic acid", "acetylphosphate")$a12)
+expect_equal(affinity_nodim, -5.06, tolerance = 0.01, scale = 1)
+
+info <- "Error produced with unknown reactant or P_source"
+# reactant should be pyruvic acid, not pyruvate
+expect_error(phosphorylate("pyruvate", "acetylphosphate"), "unrecognized reactant")
+# acetyphosphate is missing an "l"
+expect_error(phosphorylate("pyruvic acid", "acetyphosphate"), "unrecognized P_source")
Modified: pkg/CHNOSZ/man/phosphorylate.Rd
===================================================================
--- pkg/CHNOSZ/man/phosphorylate.Rd 2026-01-06 11:14:02 UTC (rev 952)
+++ pkg/CHNOSZ/man/phosphorylate.Rd 2026-01-07 08:12:08 UTC (rev 953)
@@ -9,7 +9,7 @@
\usage{
phosphorylate(reactant, P_source, loga_reactant = 0, loga_product = 0,
loga_P_source = 0, loga_P_remainder = 0, const_pH = 7, loga_Mg = -999, ...)
-phospho_plot(reactant, P_source, loga_Mg = -999)
+phospho_plot(reactant, P_source, loga_Mg = -999, res = 50)
}
\arguments{
\item{reactant}{
@@ -29,6 +29,7 @@
\item{\dots}{
additional arguments passed to \code{\link{mosaic}},
such as \code{pH}, \code{T} (temperature), or \code{P} (pressure) ranges for multi-dimensional calculations.}
+ \item{res}{numeric, plot resolution}
}
\details{
Modified: pkg/CHNOSZ/vignettes/anintro.Rmd
===================================================================
--- pkg/CHNOSZ/vignettes/anintro.Rmd 2026-01-06 11:14:02 UTC (rev 952)
+++ pkg/CHNOSZ/vignettes/anintro.Rmd 2026-01-07 08:12:08 UTC (rev 953)
@@ -2048,9 +2048,9 @@
<p>
```{r the_end}
- ###### ## ## ## ## ###### ##### #####
- ## ##===## ## \\## ## ## \\ //
- ###### ## ## ## ## ###### ##### #####
+ ###### ## ## ## ## ###### ##### #####
+ ## ##===## ## \\## ## ## \\ //
+ ###### ## ## ## ## ###### ##### #####
```
</p>
More information about the CHNOSZ-commits
mailing list