Commit 1f4edde9 authored by Thierry Martinez's avatar Thierry Martinez

Influence inferrence: influence_model & list_influences for reaction models

parent 9b0d5a25
......@@ -11,7 +11,7 @@
version('4.0').
copyright(
'Copyright (C) 2003-2015 Inria, EPI Lifeware, Paris-Rocquencourt, France'
'Copyright (C) 2003-2016 Inria, EPI Lifeware, Saclay-Île de France, France'
).
license('GNU GPL 2').
......
......@@ -4,6 +4,7 @@
% Commands
add_influence/1,
list_influences/0,
influence_model/0,
% Public API
is_influence_model/0,
check_influence_model/0,
......@@ -28,27 +29,44 @@ add_influence(Influence) :-
add_item([kind: influence, item: Influence]).
%simplify_all_reactions :-
% biocham_command,
% doc('
% replaces each reaction by a simplified form, by grouping common molecules,
% identifying catalysts, and by using the canonical molecule for aliases.
% '),
% \+ (
% item([kind: reaction, id: Id, item: Reaction]),
% \+ (
% delete_item(Id),
% simplify_reaction(Reaction, SimplifiedReaction),
% add_item([kind: reaction, item: SimplifiedReaction])
% )
% ).
list_influences :-
biocham_command,
doc('
lists the current set of influence rules.
If the current model is a reaction model,
the influence rules are inferred from the reaction model
(see \\command{influence_model/0}).'),
(
is_influence_model
->
list_items([kind: influence])
;
is_reaction_model
->
single_model(ReactionModel),
setup_call_cleanup(
new_model(InfluenceModel),
(
influence_model(ReactionModel, InfluenceModel),
list_items([parent: InfluenceModel, kind: influence, no_numbering])
),
delete_item(InfluenceModel)
)
).
list_influences :-
influence_model :-
biocham_command,
doc('lists the current set of influence rules.'),
check_influence_model,
list_items([kind: influence]).
doc('
creates a new influence model by inferring
the influences between all molecular objects of the current reaction model
'),
check_reaction_model,
single_model(ReactionModel),
new_model,
set_model_name(influence_model),
single_model(InfluenceModel),
influence_model(ReactionModel, InfluenceModel).
:- devdoc('\\section{Public API}').
......@@ -119,6 +137,57 @@ influence(InfluenceRule, Force, PositiveInputs, NegativeInputs, Sign, Output) :-
:- devdoc('\\section{Private predicates}').
influence_model(ReactionModel, InfluenceModel) :-
\+ (
item([parent: ReactionModel, kind: reaction, item: Reaction]),
reaction(Reaction, _Kinetics, Reactants, Products),
\+ (
substract_list(Reactants, Products, Difference),
create_influences(Reactants, Difference, InfluenceModel)
)
).
substract_list([], Difference, Difference).
substract_list([Coefficient0 * Object | Tail], Products, Difference) :-
(
select(Coefficient1 * Object, Products, Others)
->
Coefficient is Coefficient1 - Coefficient0,
(
Coefficient = 0
->
substract_list(Tail, Others, Difference)
;
substract_list(Tail, [Coefficient * Object | Others], Difference)
)
;
Coefficient is - Coefficient0,
substract_list(Tail, [Coefficient * Object | Products], Difference)
).
create_influences(Reactants, Difference, InfluenceModel) :-
\+ (
member(_ * Input, Reactants),
member(Coefficient * Output, Difference),
\+ (
(
Coefficient > 0
->
add_item(
[parent: InfluenceModel, kind: influence, item: (Input -> Output)]
)
;
add_item(
[parent: InfluenceModel, kind: influence, item: (Input -< Output)]
)
)
)
).
inputs(PositiveInputEnum, PositiveInputList, []) :-
(
var(PositiveInputEnum)
......
......@@ -10,8 +10,8 @@ test(
) :-
clear_model,
command((a, b \ c -> d)),
command((b -< c)),
command((\ a -< a)),
command(b -< c),
command(\ a -< a),
all_items([kind: influence], Influences).
test(
......@@ -19,8 +19,24 @@ test(
[error(not_an_influence_model)]
) :-
clear_model,
command((a => b)),
command((a -> b)).
command(a => b),
command(a -> b).
test(
'influence_model',
[
Influences
==
[
(a -< b), (a -< a), (a -> c), (a -> d),
(b -< b), (b -< a), (b -> c), (b -> d)
]
]
) :-
clear_model,
command(a + b => c + d),
influence_model,
all_items([kind: influence], Influences).
test(
'influence builds',
......@@ -76,5 +92,4 @@ test(
) :-
influence((\ a -< a), Force, PositiveInputs, NegativeInputs, Sign, Output).
:- end_tests(influence_editor).
This diff is collapsed.
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