Commit 555912a7 authored by Thierry Martinez's avatar Thierry Martinez

Rules are now reactions

parent 29ceb236
...@@ -30,7 +30,7 @@ add_equivalence_class_list(EquivalenceClassList) :- ...@@ -30,7 +30,7 @@ add_equivalence_class_list(EquivalenceClassList) :-
; ;
list_to_equals(EquivalenceClassList, EquivalenceClass), list_to_equals(EquivalenceClassList, EquivalenceClass),
add_item(alias, EquivalenceClassList, alias(EquivalenceClass)), add_item(alias, EquivalenceClassList, alias(EquivalenceClass)),
simplify_all_rules simplify_all_reactions
). ).
......
...@@ -2,10 +2,10 @@ ...@@ -2,10 +2,10 @@
:- begin_tests(aliases). :- begin_tests(aliases).
test('alias', [true(Rules == [2 * a => c])]) :- test('alias', [true(Reactions == [2 * a => c])]) :-
clear_model, clear_model,
add_rule(a + b => c), add_reaction(a + b => c),
command(alias(a = b)), command(alias(a = b)),
all_items([model: current_model, kind: rule], Rules). all_items([model: current_model, kind: reaction], Reactions).
:- end_tests(aliases). :- end_tests(aliases).
...@@ -30,7 +30,7 @@ add_conservation(Conservation) :- ...@@ -30,7 +30,7 @@ add_conservation(Conservation) :-
these checks are not complete, even a failure will be accepted with a these checks are not complete, even a failure will be accepted with a
warning.' warning.'
), ),
rule_editor:solution_to_list(Conservation, C), solution_to_list(Conservation, C),
add_item(conservation, C). add_item(conservation, C).
...@@ -38,7 +38,7 @@ delete_conservation(Conservation) :- ...@@ -38,7 +38,7 @@ delete_conservation(Conservation) :-
biocham_command, biocham_command,
type(Conservation, solution), type(Conservation, solution),
doc('removes the given mass conservation law.'), doc('removes the given mass conservation law.'),
rule_editor:solution_to_list(Conservation, C), solution_to_list(Conservation, C),
find_item([model: current_model, id: Id, type: conservation, item: C]), find_item([model: current_model, id: Id, type: conservation, item: C]),
delete_item(Id). delete_item(Id).
......
...@@ -33,7 +33,7 @@ test( ...@@ -33,7 +33,7 @@ test(
[true(InitialState == [present(a), absent(b)])] [true(InitialState == [present(a), absent(b)])]
) :- ) :-
clear_model, clear_model,
add_rule(a => b), add_reaction(a => b),
command(present(a)), command(present(a)),
make_absent_not_present, make_absent_not_present,
all_items([model: current_model, kind: initial_state], InitialState). all_items([model: current_model, kind: initial_state], InitialState).
...@@ -43,7 +43,7 @@ test( ...@@ -43,7 +43,7 @@ test(
[true(InitialState == [absent(a), present(b)])] [true(InitialState == [absent(a), present(b)])]
) :- ) :-
clear_model, clear_model,
add_rule(a => b), add_reaction(a => b),
command(absent(a)), command(absent(a)),
make_present_not_absent, make_present_not_absent,
all_items([model: current_model, kind: initial_state], InitialState). all_items([model: current_model, kind: initial_state], InitialState).
......
...@@ -3,13 +3,13 @@ ...@@ -3,13 +3,13 @@
:- begin_tests(models). :- begin_tests(models).
test('new_model', [true(Rules == [])]) :- test('new_model', [true(Reactions == [])]) :-
new_model, new_model,
single_model(Id0), single_model(Id0),
add_rule(a => b), add_reaction(a => b),
new_model, new_model,
single_model(Id1), single_model(Id1),
all_items([model: current_model, kind: rule], Rules), all_items([model: current_model, kind: reaction], Reactions),
delete_item(Id0), delete_item(Id0),
delete_item(Id1). delete_item(Id1).
......
...@@ -4,8 +4,8 @@ ...@@ -4,8 +4,8 @@
test('nusmv') :- test('nusmv') :-
clear_model, clear_model,
add_rule(a => b), add_reaction(a => b),
add_rule(a + b => c), add_reaction(a + b => c),
command(present(a)), command(present(a)),
command(absent(c)), command(absent(c)),
export_nusmv('unittest'). export_nusmv('unittest').
......
:- module( :- module(
rule_editor, reaction_editor,
[ [
add_rule/1, add_reaction/1,
list_rules/0, list_reactions/0,
rule/4, reaction/4,
simplify_all_rules/0, simplify_all_reactions/0,
enumerate_molecules/1 enumerate_molecules/1,
solution_to_list/2
] ]
). ).
add_rule(Reaction) :- add_reaction(Reaction) :-
biocham_command, biocham_command,
type(Reaction, reaction), type(Reaction, reaction),
doc('adds reaction rules to the current set of rules.'), doc('adds reaction rules to the current set of reactions.'),
simplify_rule(Reaction, SimplifiedReaction), simplify_reaction(Reaction, SimplifiedReaction),
add_item(rule, SimplifiedReaction). add_item(reaction, SimplifiedReaction).
list_rules :- list_reactions :-
biocham_command, biocham_command,
doc('lists the current set of rules.'), doc('lists the current set of reactions.'),
list_items([model: current_model, kind: rule]). list_items([model: current_model, kind: reaction]).
simplify_all_rules :- simplify_all_reactions :-
\+ ( \+ (
item([model: current_model, kind: rule, id: Id, item: Rule]), item([model: current_model, kind: reaction, id: Id, item: Reaction]),
\+ ( \+ (
delete_item(Id), delete_item(Id),
simplify_rule(Rule, SimplifiedRule), simplify_reaction(Reaction, SimplifiedReaction),
add_item(rule, SimplifiedRule) add_item(reaction, SimplifiedReaction)
) )
). ).
rule(Item, Kinetics, Reactants, Products, Reversible) :- reaction(Item, Kinetics, Reactants, Products, Reversible) :-
( (
Item = (Kinetics for Body) Item = (Kinetics for Body)
-> ->
...@@ -68,8 +69,8 @@ rule(Item, Kinetics, Reactants, Products, Reversible) :- ...@@ -68,8 +69,8 @@ rule(Item, Kinetics, Reactants, Products, Reversible) :-
append(CatalystMolecules, LeftMolecules, Reactants), append(CatalystMolecules, LeftMolecules, Reactants),
append(CatalystMolecules, RightMolecules, Products). append(CatalystMolecules, RightMolecules, Products).
rule(Item, Kinetics, Reactants, Products) :- reaction(Item, Kinetics, Reactants, Products) :-
rule(Item, PairKinetics, LeftMolecules, RightMolecules, Reversible), reaction(Item, PairKinetics, LeftMolecules, RightMolecules, Reversible),
( (
Reversible = yes Reversible = yes
-> ->
...@@ -139,16 +140,16 @@ coefficient_object(1 * Object, Object) :- ...@@ -139,16 +140,16 @@ coefficient_object(1 * Object, Object) :-
coefficient_object(CoefficientObject, CoefficientObject). coefficient_object(CoefficientObject, CoefficientObject).
simplify_rule(Rule, SimplifiedRule) :- simplify_reaction(Reaction, SimplifiedReaction) :-
rule(Rule, Kinetics, LeftMolecules, RightMolecules, Reversible), reaction(Reaction, Kinetics, LeftMolecules, RightMolecules, Reversible),
simplify_kinetics(Kinetics, KineticsSimplified), simplify_kinetics(Kinetics, KineticsSimplified),
simplify_solution(LeftMolecules, LeftMoleculesSimplified), simplify_solution(LeftMolecules, LeftMoleculesSimplified),
simplify_solution(RightMolecules, RightMoleculesSimplified), simplify_solution(RightMolecules, RightMoleculesSimplified),
simplify_catalyst( simplify_catalyst(
LeftMoleculesSimplified, RightMoleculesSimplified, Left, Catalyst, Right LeftMoleculesSimplified, RightMoleculesSimplified, Left, Catalyst, Right
), ),
build_rule( build_reaction(
KineticsSimplified, Left, Catalyst, Right, Reversible, SimplifiedRule KineticsSimplified, Left, Catalyst, Right, Reversible, SimplifiedReaction
). ).
...@@ -225,13 +226,13 @@ simplify_catalyst([Head | Tail], Right, NewLeft, Catalyst, NewRight) :- ...@@ -225,13 +226,13 @@ simplify_catalyst([Head | Tail], Right, NewLeft, Catalyst, NewRight) :-
). ).
build_rule(Kinetics, Left, Catalyst, Right, Reversible, Rule) :- build_reaction(Kinetics, Left, Catalyst, Right, Reversible, Reaction) :-
( (
Kinetics = 'MA'(1) Kinetics = 'MA'(1)
-> ->
Rule = Body Reaction = Body
; ;
Rule = (Kinetics for Body) Reaction = (Kinetics for Body)
), ),
list_to_solution(Left, LeftSolution), list_to_solution(Left, LeftSolution),
list_to_solution(Catalyst, CatalystSolution), list_to_solution(Catalyst, CatalystSolution),
...@@ -266,8 +267,8 @@ enumerate_molecules(Molecules) :- ...@@ -266,8 +267,8 @@ enumerate_molecules(Molecules) :-
enumerate_molecule(Molecule) :- enumerate_molecule(Molecule) :-
item([model: current_model, kind: rule, item: Item]), item([model: current_model, kind: reaction, item: Item]),
rule(Item, _Kinetics, Reactants, Products, _Reversible), reaction(Item, _Kinetics, Reactants, Products, _Reversible),
( (
member(_ * Molecule, Reactants) member(_ * Molecule, Reactants)
; ;
......
:- use_module(library(plunit)).
:- begin_tests(reaction_editor).
test('compound', [true(Reactions == [2 * a + 2 * b => 2 * 'a-b'])]) :-
clear_model,
command(add_reaction(2 * a + 2 * b => 2 * a-b)),
all_items([model: current_model, kind: reaction], Reactions).
test('catalyst', [true(Reactions == [2 * b <=[ a + c ]=> b])]) :-
clear_model,
add_reaction(a + b + c <=[ b ]=> a + c),
all_items([model: current_model, kind: reaction], Reactions).
:- end_tests(reaction_editor).
:- use_module(library(plunit)).
:- begin_tests(rule_editor).
test('compound', [true(Rules == [2 * a + 2 * b => 2 * 'a-b'])]) :-
clear_model,
command(add_rule(2 * a + 2 * b => 2 * a-b)),
all_items([model: current_model, kind: rule], Rules).
test('catalyst', [true(Rules == [2 * b <=[ a + c ]=> b])]) :-
clear_model,
add_rule(a + b + c <=[ b ]=> a + c),
all_items([model: current_model, kind: rule], Rules).
:- end_tests(rule_editor).
...@@ -32,9 +32,9 @@ ...@@ -32,9 +32,9 @@
*** Graphics files *** Graphics files
*** Other files *** Other files
- nusmv.pl - nusmv.pl
** Listing and editing rules and events ** Listing and editing reactions and events
*** Rules *** Reactions
- rule_editor.pl - reaction_editor.pl
- ode.pl - ode.pl
*** Events *** Events
- events.pl - events.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