Commit 0f569016 authored by Sylvain Soliman's avatar Sylvain Soliman
Browse files

Read units from SBML v2 or v3 files

parent 73c8176f
......@@ -573,8 +573,14 @@ pl_model_getTimeUnits(
) {
const char *units;
Model_t *model;
UnitDefinition_t *unitdef;
PL_check(PL_get_model(model_term, &model));
PL_check(units = Model_getTimeUnits(model));
if (Model_isSetTimeUnits(model)) {
PL_check(units = Model_getTimeUnits(model));
} else {
PL_check(unitdef = Model_getUnitDefinitionById(model, "time"));
PL_check(units = UnitDefinition_getName(unitdef))
}
PL_check(PL_unify_atom_chars(units_term, units));
PL_succeed;
}
......@@ -586,8 +592,14 @@ pl_model_getSubstanceUnits(
) {
const char *units;
Model_t *model;
UnitDefinition_t *unitdef;
PL_check(PL_get_model(model_term, &model));
PL_check(units = Model_getSubstanceUnits(model));
if (Model_isSetSubstanceUnits(model)) {
PL_check(units = Model_getSubstanceUnits(model));
} else {
PL_check(unitdef = Model_getUnitDefinitionById(model, "substance"));
PL_check(units = UnitDefinition_getName(unitdef))
}
PL_check(PL_unify_atom_chars(units_term, units));
PL_succeed;
}
......@@ -599,8 +611,14 @@ pl_model_getVolumeUnits(
) {
const char *units;
Model_t *model;
UnitDefinition_t *unitdef;
PL_check(PL_get_model(model_term, &model));
PL_check(units = Model_getVolumeUnits(model));
if (Model_isSetVolumeUnits(model)) {
PL_check(units = Model_getVolumeUnits(model));
} else {
PL_check(unitdef = Model_getUnitDefinitionById(model, "volume"));
PL_check(units = UnitDefinition_getName(unitdef))
}
PL_check(PL_unify_atom_chars(units_term, units));
PL_succeed;
}
......
......@@ -73,6 +73,7 @@ add_sbml_document(SBML) :-
add_sbml_model(Model) :-
add_units(Model),
add_compartments(Model),
add_global_parameters(Model),
add_assignment_rules(Model),
......@@ -215,6 +216,35 @@ add_reactions(Model) :-
)
).
add_units(Model) :-
debug(sbml, "getting units…", []),
(
model_getTimeUnits(Model, Time)
->
debug(sbml, "getTimeUnits(~w)", [Time]),
set_units(time, Time)
;
debug(sbml, "no timeUnits defined", [])
),
(
model_getSubstanceUnits(Model, Substance)
->
debug(sbml, "getSubstanceUnits(~w)", [Substance]),
set_units(substance, Substance)
;
debug(sbml, "no substanceUnits defined", [])
),
(
model_getVolumeUnits(Model, Volume)
->
debug(sbml, "getVolumeUnits(~w)", [Volume]),
set_units(volume, Volume)
;
debug(sbml, "no volumeUnits defined", [])
).
% Store SBML-definde compartments/locations
:- dynamic(compartment/1).
:- dynamic(single_compartment/1).
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment