Commit e21a7757 authored by Hemery Mathieu's avatar Hemery Mathieu
Browse files

Add the check_model biocham command

parent 6f38fe0d
......@@ -73,16 +73,16 @@ Coder: T. Martinez
get_model/2,
load_all/2,
parametrize_initial_concentration/0,
parametrize_reaction/0,
is_wellformed/1,
is_strict/1
parametrize_reaction/0
]
).
% Only for separate compilation/linting
:- use_module(arithmetic_rules).
:- use_module(doc).
:- use_module(formal_derivation).
:- use_module(arithmetic_rules).
:- use_module(reaction_rules).
:- use_module(util).
:- devdoc('This secton needs documentation for the developper, in particular about the invariants concerning item, parent, id, key, kind.
......@@ -304,16 +304,29 @@ parametrize :-
check_model :-
biocham_command,
doc('Check is the current model is well formed and strict, (see TCS15_FGS)'),
single_model(Id),
doc('Check if the current model is well formed and strict, (see TCS15_FGS).'),
doc('If it is not the case, proposes a witness.'),
single_model(ModelId),
findall(
Molecule,
identifier_kind(ModelId, Molecule, object),
List_Molecule
),
(
is_wellformed(Id)
maplist(test_all_reactions(reactions_with_reactant, test_wf_reactant), List_Molecule),
maplist(test_all_reactions(reactions_with_inhibitor, test_wf_inhibitor), List_Molecule)
->
format("The model is wellformed.~n", [])
;
format("The model is NOT wellformed.~n", [])
),
format("The test for strictness is not implemented yet.~n").
(
maplist(test_all_reactions(reactions_with_catalyst, test_strictness), List_Molecule)
->
format("The model is strict.~n", [])
;
format("The model is NOT strict.~n", [])
).
:- devdoc('\\section{Public API}').
......@@ -1279,37 +1292,40 @@ introduce_param(Func, Func2) :-
introduce_param(O,O).
%! is_wellformed(+model)
%
% Check if the model is wellformed (see TCS15_FGS)
is_wellformed(ModelId) :-
findall(
Molecule,
identifier_kind(ModelId, Molecule, object),
List_Molecule
),
maplist(check_reactant, List_Molecule),
maplist(check_inhibitor, List_Molecule).
test_all_reactions(Apply, Test, Molecule) :-
Constructor =.. [Apply, [Molecule], List_Reactions],
call(Constructor),
forall(
member(Expression for _Reaction, List_Reactions),
(The_test =.. [Test, Molecule, Expression],
call(The_test))
).
check_reactant(Molecule) :-
reactions_with_reactant([Molecule], List_Reaction),
forall(member(Expr for _Reaction, List_Reaction),
(
formal_derivation:derivate(Expr, Molecule, Derivative),
\+(arithmetic_rules:always_negative(Derivative))
)
test_wf_reactant(Molecule, Expression) :-
formal_derivation:derivate(Expression, Molecule, Derivative),
(
\+(arithmetic_rules:always_negative(Derivative))
;
format("Due to: ~w while checking ~w;~n", [Derivative, Molecule]),
fail
).
check_inhibitor(Molecule) :-
reactions_with_inhibitor([Molecule], List_Reaction),
forall(member(Expr for _Reaction, List_Reaction),
(
formal_derivation:derivate(Expr, Molecule, Derivative),
\+(arithmetic_rules:always_positive(Derivative))
)
test_wf_inhibitor(Molecule, Expression) :-
formal_derivation:derivate(Expression, Molecule, Derivative),
(
\+(arithmetic_rules:always_positive(Derivative))
;
format("Due to: ~w while checking ~w;~n", [Derivative, Molecule]),
fail
).
%! is_strict(+model)
%
% Check if the model is strict (see TCS15_FGS)
test_strictness(Molecule, Expression) :-
substitute([Molecule], [0], Expression, Output),
(
simplify(Output+0, 0)
;
format("Due to: ~w while checking ~w;~n", [Expression, Molecule]),
fail
).
Supports Markdown
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