Commit 02ff9fe3 authored by Mathieu Hemery's avatar Mathieu Hemery
Browse files

Try to take care of modifiers but harder than expectec

parent daf435ab
......@@ -28,6 +28,7 @@ correct_model :-
identifier_kind(ModelId, Molecule, object),
List_Molecule
),
% First loop that add/delete/split reactions
reactions_with_species(List_Molecule, List_Reaction),
forall(
member(Reaction, List_Reaction),
......@@ -35,9 +36,17 @@ correct_model :-
remove_null_kinetic(Reaction),!
;
split_bidirectional_reaction(Reaction),!
;
reverse_reaction(Reaction),!
;
true
)
),
% Second loop to add catalyst/inhibitor
reactions_with_species(List_Molecule, Sec_List_Reaction),
forall(
member(Reaction, Sec_List_Reaction),
correct_modifiers(List_Molecule, Reaction)
).
%! remove_null_kinetic(+Reaction)
......@@ -46,7 +55,8 @@ correct_model :-
remove_null_kinetic(Expression for Reaction) :-
(
is_null(Expression)
ode:substitute_functions(Expression, Expr),
is_null(Expr)
->
delete_reaction(Expression for Reaction)
).
......@@ -57,12 +67,93 @@ remove_null_kinetic(Expression for Reaction) :-
split_bidirectional_reaction(Expression for Reactant => Product) :-
(
distribute(Expression, DistExpr),
ode:substitute_functions(Expression, Expr),
distribute(Expr, DistExpr),
DistExpr = Up - Down
->
delete_reaction(Expression for Reactant => Product),
add_reaction(Up for Reactant => Product),
add_reaction(Down for Product => Reactant)
;
).
%! reverse_reaction(+Reaction)
%
% Reverse a reaction if its kinetic is negative
reverse_reaction(Expression for Reactant => Product) :-
(
ode:substitute_functions(Expression, - RevExpr)
->
delete_reaction(Expression for Reactant => Product),
add_reaction(RevExpr for Product => Reactant)
).
%! correct_modifiers(+List_Molecule, +Reaction)
%
% Ensure that the modifiers are correctly formulated
correct_modifiers(List_Molecule, Expression_raw for Reaction) :-
ode:substitute_functions(Expression_raw, Expression),
detect_modifiers(List_Molecule, Expression, Catalysts, Inhibitors),
(
append(Catalysts, Inhibitors, [])
->
true
;
add_catalysts(Catalysts, Reaction, ReactionTempo),
add_inhibitors(Inhibitors, ReactionTempo, NewReaction),
delete_reaction(Expression_raw for Reaction),
add_reaction(Expression_raw for NewReaction)
).
detect_modifiers([], _Expression, [], []).
detect_modifiers([Mol|TailM], Expression, NewC, NewI) :-
derivate(Expression, Mol, Deriv),
(
is_null(Deriv)
->
NewC = TailC,
NewI = TailI
;
always_negative(Deriv)
->
NewC = TailC,
NewI = [Mol|TailI]
;
NewC = [Mol|TailC],
NewI = TailI
),
detect_modifiers(TailM, Expression, TailC, TailI).
add_catalysts([], Reaction, Reaction).
add_catalysts([Head|Tail], Reaction, NewReaction) :-
models:formal_reactant(Head, Reaction),
!,
add_catalysts(Tail, Reaction, NewReaction).
add_catalysts([Head|Tail], Reactants => Products, NewReactants => NProducts+Head) :-
add_catalysts(Tail, Reactants => Products, NReactants => NProducts),
(
NReactants = Reac / Inhib
->
NewReactants = Reac+Head / Inhib
;
NewReactants = Reactants+Head
).
add_inhibitors([], Reaction, Reaction).
add_inhibitors([Head|Tail], Reaction, NewReaction) :-
models:formal_inhibitor(Head, Reaction),
!,
add_inhibitors(Tail, Reaction, NewReaction).
add_inhibitors([Head|Tail], Reactants => Products, NewReactants => Products) :-
add_inhibitors(Tail, Reactants => Products, NReactants => Products),
(
NReactants = Reac / Inhib
->
NewReactants = Reac / (Head,Inhib)
;
NewReactants = Reactants / Head
).
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