Commit 4103e241 authored by Mathieu Hemery's avatar Mathieu Hemery
Browse files

First success for implicit species inference in BIOMD.008

parent 83fa1501
......@@ -23,6 +23,7 @@
add_influences_from_ode_system/0,
(init)/1,
remove_fraction/0,
put_back_implicit_species/0,
% load_ode_system/1,
load_reactions_from_ode/1,
% add_ode_system/1,
......@@ -49,6 +50,7 @@
import_influences_from_ode_system/1,
with_current_ode_system/1,
edit_current_ode_system/1,
put_back_implicit_species/1,
all_odes/1,
ode/2,
ode/3,
......@@ -453,7 +455,15 @@ 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 :-
biocham_command,
doc('Blabla'),
ode_system,
with_current_ode_system((
get_current_ode_system(Id),
put_back_implicit_species(Id)
)).
:- devdoc('\\section{Public API}').
......@@ -667,18 +677,16 @@ parse_ode(ODE, X, Item) :-
enumerate_terms_in_odes(Id) :-
\+ (
forall(
ode(Id, X, E),
\+ (
enumerate_terms_in_ode(X, E)
)
enumerate_terms_in_ode(X, E)
).
enumerate_terms_in_ode(X, E) :-
\+ (
forall(
non_decomposable_term_in_expression(Coefficient, Term, E),
\+ (
(
(
retract(assoc(Term, Occurrences))
->
......@@ -741,6 +749,82 @@ 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)
%
% Recursively loop on the given ode system to remove implicit species
put_back_implicit_species(Id) :-
repeat,
(
ode(Id, _X, Expr),
implicit_species(Expr, IS)
->
correct_implicit_species(Id, IS),
fail
;
!
).
% Deal with the one species case
correct_implicit_species(Id, K-X) :-
% Add the ODE of the implicit species
ode(Id, X, Expr),
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
forall(
ode(Id, Var, Deriv),
(
delete_single_ode(Var),
substitute_all(K, X, X_m, Deriv, NewDeriv),
add_ode(Id, d(Var)/dt = NewDeriv)
)
).
substitute_all(K, X, Xm, In, Out) :-
substitute([K-X], [Xm], In, E1),
substitute([-X+K], [Xm], E1, E2),
substitute([V1+K-X], [V1+Xm], E2, E3),
substitute([K+V2-X], [V2+Xm], E3, E4),
substitute([V3-X+K], [V3+Xm], E4, Test),
(
In = Test
->
Test = Out
;
substitute_all(K, X, Xm, Test, Out)
).
% implicit_species(+Expression, -Species)
%
% Detect the implicit species in an expression
implicit_species(Expression, K-X-Y) :-
(
is_present(K-X-Y, Expression)
;
is_present(-X+K-Y, Expression)
;
is_present(-X-Y+K, Expression)
),
is_numeric(K).
implicit_species(Expression, K-X) :-
(
is_present(K-X, Expression)
;
is_present(-X+K, Expression)
),
is_numeric(K).
:- dynamic(reactant/2).
......
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