Commit c9874702 authored by SOLIMAN Sylvain's avatar SOLIMAN Sylvain
Browse files

Rate independence in Biocham

parent c776c8e9
:- module(
rate_independence,
[
% Commands
test_rate_independence/0
]
).
:- use_module(doc).
%! test_rate_independence is det.
%
% Test the 3 graphical conditions (and not yet well-formedness) for rate independence.
test_rate_independence :-
biocham_command,
doc('Test the graphical sufficient conditions for rate independence of the current model.'),
reaction_graph,
get_current_graph(Id),
(
is_fork_free(Id),
is_synthesis_free,
is_loop_free(Id)
->
write('Current model is rate independent if its kinetics are well-formed.\n')
;
write('Cannot establish rate independence from graphical conditions.\n'),
nb_getval(rate_dependence_reason, Failed),
Failed =.. [Stage, Place],
format("Model is not ~w-free (on ~w).~n", [Stage, Place])
).
%! is_synthesis_free is det.
%
% check for the absence of a reaction with reactants included in products
is_synthesis_free :-
\+(
(
item([kind: reaction, item: Reaction]),
reaction(Reaction, [reactants: R, products: P]),
forall(
% FIXME stoichiometry?
member(_ * M, R),
memberchk(_ * M, P)
),
nb_setval(rate_dependence_reason, synthesis(Reaction))
)
).
%! is_fork_free(+GraphId) is det.
%
% check for the absence of a species participating in two different reactions
is_fork_free(GraphId) :-
\+(
(
item([parent: GraphId, kind: vertex, id: VertexId, item: Vertex]),
get_attribute(VertexId, kind=place),
item([parent: GraphId, kind: edge, id: Id1, item: (Vertex -> _)]),
item([parent: GraphId, kind: edge, id: Id2, item: (Vertex -> _)]),
Id1 \= Id2,
nb_setval(rate_dependence_reason, fork(Vertex))
)
).
:- dynamic(seen/1).
:- dynamic(visiting/1).
%! is_loop_free(+GraphId) is det.
%
% check for the absence of loop using a simple DFS.
is_loop_free(GraphId) :-
retractall(seen(_)),
retractall(visiting(_)),
forall(
item([parent: GraphId, kind: vertex, item: Vertex]),
(
% at top level, seen vertices are ok, we're just in the same connected component
seen(Vertex)
->
true
;
dfs_no_loop(GraphId, Vertex)
)
).
%! dfs_no_loop(+GraphId, +Vertex) is det.
%
% mark a Vertex as under visit, and loop on all its children that shouldn't be under visit.
dfs_no_loop(GraphId, Vertex) :-
assertz(visiting(Vertex)),
forall(
item([parent: GraphId, kind: edge, item: (Vertex -> Child)]),
(
(
% check this first since we do not retract visiting
seen(Child)
->
true
;
visiting(Child)
->
nb_setval(rate_dependence_reason, loop(Vertex)),
fail
;
dfs_no_loop(GraphId, Child)
)
)
),
assertz(seen(Vertex)).
:- use_module(library(plunit)).
:- begin_tests(rate_independence).
test('fork', [true(Reason == fork('B1')), setup(max_model), cleanup(clear_model)]) :-
command('B1 => C'),
reaction_graph,
get_current_graph(Id),
\+ rate_independence:is_fork_free(Id),
nb_getval(rate_dependence_reason, Reason).
test('synthesis', [true(Reason = synthesis(_)), setup(max_model), cleanup(clear_model)]) :-
command('C => C + D'),
reaction_graph,
\+ rate_independence:is_synthesis_free,
nb_getval(rate_dependence_reason, Reason).
test('loop', [true(Reason = loop(_)), setup(max_model), cleanup(clear_model)]) :-
command('delete_reaction(Sum + Min => _)'),
command('Sum + Min => B'),
reaction_graph,
get_current_graph(Id),
\+ rate_independence:is_loop_free(Id),
nb_getval(rate_dependence_reason, Reason).
test('Max', [setup(max_model), cleanup(clear_model)]) :-
with_output_to(atom(Result), test_rate_independence),
writeln(Result),
atom_concat('Current model is rate independent', _, Result).
:- end_tests(rate_independence).
max_model :-
clear_model,
command('A => A1 + A2'),
command('B => B1 + B2'),
command('A1 => Sum'),
command('B1 => Sum'),
command('A2 + B2 => Min'),
command('Sum + Min => _').
......@@ -83,6 +83,8 @@
** Multistability analysis
- multistability_command.pl
- oscilations.pl
** Rate independence
- rate_independence.pl
* Boolean Dynamics, Verification and Synthesis
** Boolean attractors
- influence_properties.pl
......
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