Commit c6fd613d authored by Thierry Martinez's avatar Thierry Martinez

Influence rules

parent 2e21d0e9
:- module(
influence_editor,
[
% Commands
add_influence/1,
list_influences/0,
% Public API
is_influence_model/0,
check_influence_model/0,
influence/5
]
).
:- devdoc('\\section{Commands}').
add_influence(Influence) :-
biocham_command,
type(Influence, influence),
doc('
adds influence rules to the current set of influences.
This command is implicit: influence rules can be added directly in
influence models.
'),
check_influence_model,
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.'),
check_influence_model,
list_items([kind: influence]).
:- devdoc('\\section{Public API}').
is_influence_model :-
devdoc('
succeeds if the current model is an influence model
(i.e., does not contain any reaction rules).
'),
\+ item([kind: reaction]).
check_influence_model :-
(
is_influence_model
->
true
;
throw(error(not_an_influence_model, check_influence_model))
).
prolog:error_message(not_an_influence_model) -->
['Not an influence model'].
influence(InfluenceRule, PositiveInputs, NegativeInputs, Sign, Output) :-
devdoc('builds or decompose an influence rule.'
),
once((
InfluenceRule = (Inputs -> Output),
Sign = +
;
InfluenceRule = (Inputs -< Output),
Sign = -
)),
inputs(Inputs, PositiveInputs, NegativeInputs).
:- devdoc('\\section{Private predicates}').
inputs(PositiveInputEnum, PositiveInputList, []) :-
(
var(PositiveInputEnum)
->
true
;
PositiveInputEnum \= (_ \ _),
PositiveInputEnum \= (\ _)
),
list_enumeration(PositiveInputList, PositiveInputEnum),
!.
inputs(\ NegativeInputEnum, [], NegativeInputList) :-
list_enumeration(NegativeInputList, NegativeInputEnum),
!.
inputs(
PositiveInputEnum \ NegativeInputEnum,
PositiveInputList,
NegativeInputList
) :-
list_enumeration(PositiveInputList, PositiveInputEnum),
list_enumeration(NegativeInputList, NegativeInputEnum),
!.
list_enumeration([], '_') :-
!.
list_enumeration([H], H) :-
H \= (_, _),
!.
list_enumeration([H | List], (H, Enum)) :-
list_enumeration(List, Enum).
:- use_module(library(plunit)).
:- begin_tests(influence_editor).
test(
'add_influence',
[Influences == [(a, b \ c -> d), (b -< c), (\ a -< a)]]
) :-
clear_model,
command((a, b \ c -> d)),
command((b -< c)),
command((\ a -< a)),
all_items([kind: influence], Influences).
test(
'add_influence fails on reaction models',
[error(not_an_influence_model)]
) :-
clear_model,
command((a => b)),
command((a -> b)).
test(
'influence builds',
[Influence == (a, b \ c -> d)]
) :-
influence(Influence, [a, b], [c], +, d).
test(
'influence builds with positive inputs',
[Influence == (b -< c)]
) :-
influence(Influence, [b], [], -, c).
test(
'influence builds with negative inputs',
[Influence == (\ a -< a)]
) :-
influence(Influence, [], [a], -, a).
test(
'influence builds with no inputs',
[Influence == ('_' -> a)]
) :-
influence(Influence, [], [], +, a).
test(
'influence destructs',
[
result(PositiveInputs, NegativeInputs, Sign, Output)
==
result([a, b], [c], +, d)
]
) :-
influence((a, b \ c -> d), PositiveInputs, NegativeInputs, Sign, Output).
test(
'influence destructs with positive inputs',
[
result(PositiveInputs, NegativeInputs, Sign, Output)
==
result([b], [], -, c)
]
) :-
influence((b -< c), PositiveInputs, NegativeInputs, Sign, Output).
test(
'influence destructs with negative inputs',
[
result(PositiveInputs, NegativeInputs, Sign, Output)
==
result([], [a], -, a)
]
) :-
influence((\ a -< a), PositiveInputs, NegativeInputs, Sign, Output).
:- end_tests(influence_editor).
:- module(
influence_rules,
[
influence_predicate/1,
influence/1,
inputs/1,
enumeration/1,
op(1050, xfx, (->)),
op(1050, xfx, (-<)),
op(1025, xfx, (\)),
op(1025, fx, (\))
]
).
influence_predicate(_ -> _).
influence_predicate(_ -< _).
:- grammar(influence).
influence(Inputs -> Output) :-
inputs(Inputs),
object(Output).
influence(Inputs -< Output) :-
inputs(Inputs),
object(Output).
:- grammar(inputs).
inputs(PositiveInputs \ NegativeInputs) :-
enumeration(PositiveInputs),
enumeration(NegativeInputs).
inputs(\ NegativeInputs) :-
enumeration(NegativeInputs).
inputs(PositiveInputs) :-
enumeration(PositiveInputs).
:- grammar(enumeration).
enumeration('_').
enumeration((A, B)) :-
object(A),
enumeration(B).
enumeration(A) :-
object(A).
#!/bin/sh
set -e
sudo apt-get install libgsl0-dev gnuplot graphviz-dev libppl-dev # swi-prolog libsbml5-dev
sudo apt-get install libgsl0-dev gnuplot libppl-dev # swi-prolog libsbml5-dev graphviz-dev
if ! swipl -g '
call_cleanup(
......
:- module(
reaction_editor,
[
% Commands
add_reaction/1,
list_reactions/0,
simplify_all_reactions/0,
add_reaction/4,
% Public API
is_reaction_model/0,
check_reaction_model/0,
reaction/5,
reaction/4,
enumerate_molecules/1,
......@@ -22,7 +26,8 @@ add_reaction(Reaction) :-
type(Reaction, reaction),
doc('
adds reaction rules to the current set of reactions.
This command is implicit: reaction rules can be added directly in models.
This command is implicit: reaction rules can be added directly in
reaction models.
'),
\+ (
reaction(Reaction, Kinetics, Reactants, Products),
......@@ -50,16 +55,39 @@ add_reaction(Reaction) :-
list_reactions :-
biocham_command,
doc('lists the current set of reactions.'),
doc('lists the current set of reaction rules.'),
check_reaction_model,
list_items([kind: reaction]).
:- devdoc('\\section{Public API}').
is_reaction_model :-
devdoc('
succeeds if the current model is a reaction model
(i.e., does not contain any influence rules).
'),
\+ item([kind: influence]).
check_reaction_model :-
(
is_reaction_model
->
true
;
throw(error(not_a_reaction_model, check_reaction_model))
).
prolog:error_message(not_a_reaction_model) -->
['Not a reaction model'].
add_reaction(Kinetics, Left, Right, Reversible) :-
make_reaction(Kinetics, Left, Right, Reversible, Reaction),
check_reaction_model,
add_item([kind: reaction, item: Reaction]).
......
......@@ -4,16 +4,30 @@
:- begin_tests(reaction_editor).
test('compound', [true(Reactions == [2 * a + 2 * b => 2 * 'a-b'])]) :-
test(
'compound',
[Reactions == [2 * a + 2 * b => 2 * 'a-b']]
) :-
clear_model,
command(add_reaction(2 * a + 2 * b => 2 * a-b)),
all_items([kind: reaction], Reactions).
test('catalyst', [true(Reactions == [2 * b =[ a + c ]=> b, b =[ a + c ]=> 2 * b])]) :-
test(
'catalyst',
[Reactions == [2 * b =[ a + c ]=> b, b =[ a + c ]=> 2 * b]]
) :-
clear_model,
add_reaction(a + b + c <=[ b ]=> a + c),
simplify_all_reactions,
all_items([kind: reaction], Reactions).
test(
'add_reaction fails on influence models',
[error(not_a_reaction_model)]
) :-
clear_model,
command((a -> b)),
command((a => b)).
:- end_tests(reaction_editor).
:- module(
reaction_rules,
[
reaction_predicate/1,
reaction/1,
basic_reaction/1,
solution/1,
......@@ -17,6 +18,13 @@
).
reaction_predicate(_ for _).
reaction_predicate(_ => _).
reaction_predicate(_ <=> _).
:- grammar(reaction).
......
......@@ -17,6 +17,8 @@
- reaction_rules.pl
- kinetics.pl
- types.pl
* Syntax of Biocham Influence Systems
- influence_rules.pl
* Syntax of Biocham Temporal Specifications
** Boolean temporal properties
** Numerical temporal properties
......@@ -33,9 +35,11 @@
*** Graphics files
*** Other files
- nusmv.pl
** Listing and editing reactions and events
** Listing and editing reactions, influences and events
*** Reactions
- reaction_editor.pl
*** Influences...
- influence_editor.pl
*** Events
- events.pl
** Listing and defining initial states, molecules and locations
......
......@@ -125,15 +125,13 @@ command(Command) :-
check_types(Command0, ArgumentTypes, NewCommand),
NewCommand
;
(
Command = (_ => _)
;
Command = (_ <=> _)
;
Command = (_ for _)
)
reaction_predicate(Command)
->
command(add_reaction(Command))
;
influence_predicate(Command)
->
command(add_influence(Command))
;
throw(error(unknown_command(Functor/Arity)))
).
......
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