Commit 4affd6ac authored by Mathieu Hemery's avatar Mathieu Hemery

Make infer_hidden_molecules an option of load_reactions

parent be06bbf6
......@@ -23,7 +23,7 @@
add_influences_from_ode_system/0,
(init)/1,
remove_fraction/0,
put_back_implicit_species/0,
infer_hidden_molecules/0,
% load_ode_system/1,
load_reactions_from_ode/1,
% add_ode_system/1,
......@@ -50,7 +50,7 @@
import_influences_from_ode_system/1,
with_current_ode_system/1,
edit_current_ode_system/1,
put_back_implicit_species/1,
infer_hidden_molecules/1,
all_odes/1,
ode/2,
ode/3,
......@@ -224,6 +224,8 @@ add_reactions_from_ode(InputFile) :-
'),
option(import_reactions_with_inhibitors, yesno, _,
'Add inhibitors when inferring reactions.'),
option(infer_hidden_molecules, yesno, _,
'Run infer_hidden_molecules (1-X => X_m) before loading reactions'),
retractall(flag_influences),
models:add_all('ode', InputFile).
......@@ -383,6 +385,8 @@ init(InitList) :-
)
).
:- initial(option(infer_hidden_molecules: no)).
add_reactions_from_ode_system :-
biocham_command,
doc('adds a set of reactions equivalent to the current ODE system.'),
......@@ -391,6 +395,14 @@ add_reactions_from_ode_system :-
get_current_ode_system(Id),
!,
retractall(flag_influences),
(
get_option(infer_hidden_molecules, IHM),
IHM = yes
->
infer_hidden_molecules(Id)
;
true
),
import_reactions_from_ode_system(Id).
add_reactions_from_ode_system :-
print_message(warning,'there is no current ode system').
......@@ -415,6 +427,8 @@ load_reactions_from_ode_system :-
\\command{add_reactions_from_ode_system/0}.'),
option(import_reactions_with_inhibitors, yesno, _,
'Add inhibitors when inferring reactions.'),
option(infer_hidden_molecules, yesno, _,
'Run infer_hidden_molecules (1-X => X_m) before loading reactions'),
delete_reactions,
add_reactions_from_ode_system.
......@@ -456,13 +470,13 @@ remove_fraction :-
select_ode_system(without_fraction_ode).
% For now a biocham command mainly to debug, remove also ode_system when switching to API
put_back_implicit_species :-
infer_hidden_molecules :-
biocham_command,
doc('Blabla'),
ode_system,
with_current_ode_system((
get_current_ode_system(Id),
put_back_implicit_species(Id)
infer_hidden_molecules(Id)
)).
......@@ -749,29 +763,29 @@ non_decomposable_term_in_additive_normal_form(-1, NCoeff * Term, Coefficient *
non_decomposable_term_in_additive_normal_form(1, Term, Term).
% put_back_implicit_species(+Id)
% infer_hidden_molecules(+Id)
%
% Recursively loop on the given ode system to remove implicit species
put_back_implicit_species(Id) :-
infer_hidden_molecules(Id) :-
repeat,
(
ode(Id, _X, Expr),
implicit_species(Expr, IS)
hidden_molecules(Expr, IS)
->
correct_implicit_species(Id, IS),
correct_hidden_molecules(Id, IS),
fail
;
!
).
% correct_implicit_species(+Id, +Implicit_Species)
% correct_hidden_molecules(+Id, +Implicit_Species)
%
% modify the current ODE system to add the implicit species and insert it in the
% derivatives
correct_implicit_species(Id, K-X-Y) :-
correct_hidden_molecules(Id, K-X-Y) :-
% Add the ODE
ode(Id, X, Expr_X),
ode(Id, Y, Expr_Y),
......@@ -795,18 +809,9 @@ correct_implicit_species(Id, K-X-Y) :-
)
).
correct_implicit_species(Id, K-X) :-
% Add the ODE
ode(Id, X, Expr),
correct_hidden_molecules(Id, K-X) :-
atom_concat(X, '_m', X_m),
distribute(-1*Expr, Der_Tempo),
simplify(Der_Tempo, Expr_m),
add_ode(Id, d(X_m)/dt = Expr_m),
% Add the initial value
get_initial_concentration(X, X0),
Init_m is K-X0,
set_ode_initial_value(X_m, Init_m),
% And replace the expression by the variable
% Replace the variable in the derivative expression
forall(
ode(Id, Var, Deriv),
(
......@@ -814,7 +819,16 @@ correct_implicit_species(Id, K-X) :-
substitute_all(K, X, X_m, Deriv, NewDeriv),
add_ode(Id, d(Var)/dt = NewDeriv)
)
).
),
% Add the ODE
ode(Id, X, Expr),
distribute(-1*Expr, Der_Tempo),
simplify(Der_Tempo, Expr_m),
add_ode(Id, d(X_m)/dt = Expr_m),
% Add the initial value
get_initial_concentration(X, X0),
Init_m is K-X0,
set_ode_initial_value(X_m, Init_m).
substitute_all(K, X, Y, XYm, In, Out) :-
substitute([K-X-Y], [XYm], In, E1),
......@@ -853,11 +867,11 @@ substitute_all(K, X, Xm, In, Out) :-
).
% implicit_species(+Expression, -Species)
% hidden_molecules(+Expression, -Species)
%
% Detect the implicit species in an expression
implicit_species(Expression, K-X-Y) :-
hidden_molecules(Expression, K-X-Y) :-
(
is_present(K-X-Y, Expression)
;
......@@ -867,7 +881,7 @@ implicit_species(Expression, K-X-Y) :-
),
is_numeric(K).
implicit_species(Expression, K-X) :-
hidden_molecules(Expression, K-X) :-
(
is_present(K-X, Expression)
;
......
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