
Translate structural models between rxode2 and MLXTRAN syntax
Source:R/sg-translator.R
sg_translator.RdConverts structural pharmacometric model files between rxode2 (R package) and MLXTRAN (Monolix) syntax. Supports ODE-based models and Monolix pkmodel macros.
Usage
sg_translator(
input_path,
to,
output_path,
dm_list = NULL,
regressors = NULL,
output_vars = NULL,
macros = TRUE,
stiff = TRUE
)Arguments
- input_path
Character string. Path to the input structural model file (.txt).
- to
Character string. Target format:
"mlxtran"or"rxode".- output_path
Character string. Path to write the translated model file (.txt).
- dm_list
List of dosing macros with
cmtandadmvectors. For example,list(cmt = 2, adm = 1)orlist(cmt = c(2, 1), adm = c(1, 2)). Used to generateiv()dosing macros in MLXTRAN output.- regressors
Character vector of regressor variable names. For example,
c("WTBL", "ADAN")generatesWTBL = {use = regressor}in MLXTRAN.- output_vars
Character vector of output variable names for the MLXTRAN
OUTPUT:section. For example,c("Cc_mgL", "CSF1_ngmL")generatesoutput = {Cc_mgL, CSF1_ngmL}. Required whento = "mlxtran"; ignored whento = "rxode".- macros
Logical. If
TRUE, attempt to convert rxode2 model to pkmodel macro format in MLXTRAN (only for simple 1- or 2-compartment oral PK models). DefaultTRUE.- stiff
Logical. If
TRUE, addodeType = stiffto the MLXTRAN EQUATION section. DefaultTRUE.
Value
Invisibly returns the translated model as a character string.
The translated model is also written to output_path.
Details
The function detects the source format automatically from file content.
rxode2 format uses # [INPUT], # [MODEL], # [OUTPUT] section markers,
d/dt(X) ODE notation, f(X) for bioavailability, and alag(X) for lag time.
MLXTRAN format uses [LONGITUDINAL], PK:/EQUATION:/OUTPUT: sections,
ddt_X ODE notation, compartment()/iv() dosing macros, and optionally
pkmodel() macros.
When converting rxode2 to MLXTRAN with macros = TRUE, the function checks if the model
structure matches a simple pkmodel() pattern (1- or 2-compartment with first-order oral
absorption). If not, it falls back to full ODE format with compartment()/iv() macros.
MLXTRAN models using absorption()/elimination()/peripheral() macros (type 2)
are expanded to explicit ODEs when converted to rxode2.
Examples
# \donttest{
# Convert rxode2 model to MLXTRAN ODE format
rxode_model_hv_iv <- system.file("extdata", "models", "rxode",
"model_PK_hv_iv.txt", package = "SimuRg")
#> Warning: cannot open compressed file '/tmp/RtmpLedq7K/temp_libpath8b6abff614d/SimuRg/DESCRIPTION', probable reason 'No such file or directory'
rxode_model_1c <- system.file("extdata", "models", "rxode",
"model_PK_1c.txt", package = "SimuRg")
#> Warning: cannot open compressed file '/tmp/RtmpLedq7K/temp_libpath8b6abff614d/SimuRg/DESCRIPTION', probable reason 'No such file or directory'
monolix_model_hv_iv <- system.file("extdata", "models", "monolix",
"model_PK_hv_iv.txt", package = "SimuRg")
#> Warning: cannot open compressed file '/tmp/RtmpLedq7K/temp_libpath8b6abff614d/SimuRg/DESCRIPTION', probable reason 'No such file or directory'
monolix_model_1c <- system.file("extdata", "models", "monolix",
"model_PK_1c.txt", package = "SimuRg")
#> Warning: cannot open compressed file '/tmp/RtmpLedq7K/temp_libpath8b6abff614d/SimuRg/DESCRIPTION', probable reason 'No such file or directory'
path_to_save <- tempdir()
sg_translator(rxode_model_hv_iv, to = "mlxtran",
output_path = normalizePath(file.path(path_to_save,
"model_PK_hv_iv_mlx.txt"),
mustWork = FALSE),
output_vars = "Cc_mgL",
dm_list = list(cmt = 1, adm = 1), stiff = TRUE)
#> Error: cannot open file '/tmp/RtmpLedq7K/temp_libpath8b6abff614d/SimuRg/R/SimuRg.rdb': No such file or directory
# Convert rxode2 model to MLXTRAN with pkmodel macros
sg_translator(rxode_model_1c, to = "mlxtran",
output_path = normalizePath(file.path(path_to_save,
"model_PK_1c_mlx.txt"),
mustWork = FALSE),
output_vars = "Cc_nM", macros = TRUE)
#> Warning: restarting interrupted promise evaluation
#> Error: cannot open file '/tmp/RtmpLedq7K/temp_libpath8b6abff614d/SimuRg/R/SimuRg.rdb': No such file or directory
# Convert MLXTRAN model to rxode2
sg_translator(monolix_model_hv_iv, to = "rxode",
output_path = normalizePath(file.path(path_to_save,
"model_PK_hv_iv_rx.txt"),
mustWork = FALSE))
#> Warning: restarting interrupted promise evaluation
#> Error: cannot open file '/tmp/RtmpLedq7K/temp_libpath8b6abff614d/SimuRg/R/SimuRg.rdb': No such file or directory
# }