aboutsummaryrefslogtreecommitdiff
path: root/R/mkinpredict.R
diff options
context:
space:
mode:
authorJohannes Ranke <jranke@uni-bremen.de>2015-06-20 01:06:24 +0200
committerJohannes Ranke <jranke@uni-bremen.de>2015-06-20 03:59:56 +0200
commit062b9cc1d084e8bb5e552076fc48ade4b3050644 (patch)
treebfb8acaf64fbbefbd7423cf6d0cfdb5119120a26 /R/mkinpredict.R
parent6281424beafe531c9891670c3227ab12e9a21990 (diff)
Low-level generation of compiled models
As it is unclear if and when ccSolve will be published on CRAN, the generation, compilation and use of the C version of the system of differential equations was developed for mkin, inspired and guided by the code from the ccSolve package. Many thanks again to Karline Soetaert for all of her work on this and other R packages. Now all model types, including the Hockey-Stick model for the parent compund and the IORE model for parent and/or metabolites can be compiled.
Diffstat (limited to 'R/mkinpredict.R')
-rw-r--r--R/mkinpredict.R43
1 files changed, 27 insertions, 16 deletions
diff --git a/R/mkinpredict.R b/R/mkinpredict.R
index 3121f1d7..5f11c35a 100644
--- a/R/mkinpredict.R
+++ b/R/mkinpredict.R
@@ -54,8 +54,8 @@ mkinpredict <- function(mkinmod, odeparms, odeini,
IORE = IORE.solution(outtimes,
evalparse(parent.name),
ifelse(mkinmod$use_of_ff == "min",
- evalparse(paste("k.iore", parent.name, "sink", sep="_")),
- evalparse(paste("k.iore", parent.name, sep="_"))),
+ evalparse(paste("k__iore", parent.name, "sink", sep="_")),
+ evalparse(paste("k__iore", parent.name, sep="_"))),
evalparse("N_parent")),
DFOP = DFOP.solution(outtimes,
evalparse(parent.name),
@@ -88,10 +88,21 @@ mkinpredict <- function(mkinmod, odeparms, odeini,
names(out) <- c("time", mod_vars)
}
if (solution_type == "deSolve") {
- if (!is.null(mkinmod$compiled) & use_compiled[1] != FALSE) {
- mkindiff <- mkinmod$compiled
- } else {
- mkindiff <- function(t, state, parms) {
+ if (!is.null(mkinmod$cf) & use_compiled[1] != FALSE) {
+ out <- ode(
+ y = odeini,
+ times = outtimes,
+ func = "func",
+ initfunc = "initpar",
+ dllname = getDynLib(mkinmod$cf)[["name"]],
+ parms = odeparms[mkinmod$parms], # Order matters when using compiled models
+ method = method.ode,
+ atol = atol,
+ rtol = rtol,
+ ...
+ )
+ } else {
+ mkindiff <- function(t, state, parms) {
time <- t
diffs <- vector()
@@ -103,17 +114,17 @@ mkinpredict <- function(mkinmod, odeparms, odeini,
}
return(list(c(diffs)))
}
+ out <- ode(
+ y = odeini,
+ times = outtimes,
+ func = mkindiff,
+ parms = odeparms,
+ method = method.ode,
+ atol = atol,
+ rtol = rtol,
+ ...
+ )
}
- out <- ode(
- y = odeini,
- times = outtimes,
- func = mkindiff,
- parms = odeparms[mkinmod$parms], # Order matters when using compiled models
- method = method.ode,
- atol = atol,
- rtol = rtol,
- ...
- )
if (sum(is.na(out)) > 0) {
stop("Differential equations were not integrated for all output times because\n",
"NaN values occurred in output from ode()")

Contact - Imprint