Commit 2bf234c7 authored by guillaume le guludec's avatar guillaume le guludec

Merge branch 'master' of git+ssh://scm.gforge.inria.fr/gitroot/biocham/biocham

Conflicts:
	wgpac.pl
parents 9d917df7 ed4ed600
......@@ -2,7 +2,7 @@
partial_fraction/5
]).
:- use_foreign_library(foreign(roots)).
% :- use_foreign_library(foreign(roots)).
% A polynomial is represented by the list of its coefficients
% the fist one is the constant and the last one is the leading coefficient
......
......@@ -189,7 +189,7 @@ export_valid_reactions(Stream, Reactions) :-
atomic_list_concat(Conditions, ' | ', AReactionIsEnabled),
format(Stream, ' !(~a): TRUE;\n', [AReactionIsEnabled]),
forall(
nth1(ReactionIndex, Reactions, (Reactants, _Products)),
nth1(ReactionIndex, Reactions, (Reactants, __Products)),
(
reactants_to_condition(Reactants, Condition),
format(Stream, ' R = ~d & !(~a): FALSE;\n', [ReactionIndex, Condition])
......@@ -430,6 +430,15 @@ check_ctl(Query) :-
check_ctl(Query, Result),
format('~w is ~w\n', [Query, Result]).
:- doc('\\begin{example}\n').
:- biocham_silent(clear_model).
:- biocham(present(a)).
:- biocham(absent(b)).
:- biocham(a => b).
:- biocham(a + b => a).
:- biocham(check_ctl('EX'(not(a) \/ 'EG'(not(b))))).
:- biocham(check_ctl('EX'(not(a) \/ 'EG'(not(b) /\ '_valid')))).
:- doc('\\end{example}').
check_ctl(Query, Result) :-
translate_ctl_for_nusmv(Query, Nusmv),
......
:- module(
wgpac,
[
% Grammars
wgpac/1,
wgpac_box/1,
wgpac_free/2,
wgpac_box_free/2,
wgpac_name/2,
op(600, xfy, ::),
op(500, yfx, +),
op(400, yfx, *),
op(550, fy, integral),
% Commands
compile_wgpac/2
]).
:- devdoc('\\section{Grammars}').
wgpac,
[
% Grammars
wgpac/1,
wgpac_box/1,
wgpac_named/1,
wgpac_name/2,
op(600, xfy, ::),
op(550, fy, integral),
% Commands
compile_wgpac/2
]).
:- grammar(wgpac).
wgpac(Y :: B) :-
object(Y),
wgpac_box(B).
wgpac(B) :-
wgpac_box(B).
wgpac_box(B).
wgpac(Y) :-
object(Y).
wgpac_named(Y).
:- grammar(wgpac_box).
wgpac_box(K) :-
concentration(K).
concentration(K).
wgpac_box(W1 + W2) :-
wgpac(W1),
wgpac(W2).
wgpac(W1),
wgpac(W2).
wgpac_box(W1 * W2) :-
wgpac(W1),
wgpac(W2).
wgpac(W1),
wgpac(W2).
wgpac_box(integral W) :-
wgpac(W).
wgpac(W).
:- grammar(wgpac_named).
wgpac_named(Y :: B) :-
object(Y),
wgpac_box(B).
wgpac_named(Y) :-
object(Y).
wgpac_name(Y :: _, Y) :-
object(Y).
object(Y).
wgpac_name(Y, Y) :-
object(Y).
object(Y).
wgpac_free(Y, _) :-
object(Y).
wgpac_free(B, Z) :-
wgpac_box_free(B, Z).
object(Y),
!.
wgpac_free(Y :: B, Z) :-
Y \== Z,
wgpac_box_free(B, Z).
!,
Y \== Z,
wgpac_box_free(B, Z).
wgpac_free(B, Z) :-
wgpac_box_free(B, Z).
wgpac_box_free(K, _) :-
concentration(K).
concentration(K),
!.
wgpac_box_free(W1 + W2, Z) :-
wgpac_free(W1, Z),
wgpac_free(W2, Z).
wgpac_free(W1, Z),
wgpac_free(W2, Z).
wgpac_box_free(W1 * W2, Z) :-
wgpac_free(W1, Z),
wgpac_free(W2, Z).
wgpac_free(W1, Z),
wgpac_free(W2, Z).
wgpac_box_free(integral W, Z) :-
wgpac_free(W, Z).
wgpac_free(W, Z).
wgpac_well_formed(Y) :-
object(Y).
object(Y).
wgpac_well_formed(Y :: B) :-
object(Y),
wgpac_box(B),
wgpac_box_free(B, Y).
object(Y),
wgpac_box_free(B, Y).
wgpac_named(Y :: B) :-
object(Y),
wgpac_box(B).
wgpac_named(Y) :-
object(Y).
wgpac_anonymous(B) :-
wgpac_box(B).
% global counter, useful for anonymous species
:- assert(fresh_index(0)).
:- dynamic(fresh_index/1).
get_fresh(N) :-
retract(fresh_index(N)),
M is N + 1,
assert(fresh_index(M)).
retract(fresh_index(N)),
M is N + 1,
assert(fresh_index(M)).
:- devdoc('\\section{Commands}').
compile_wgpac(Y, _) :-
biocham_command,
%% write('Start compilation of object :'), write(Y), nl,
object(Y), !.
compile_wgpac(Wgpac, Rate) :-
biocham_command,
type(Wgpac, wgpac),
type(Rate, number),
%% write('Start anonymous of: '), write_wgpac(Wgpac), nl,
wgpac_anonymous(Wgpac),
get_fresh(N),
atom_concat('x_auto_', N, Y),
wgpac_well_formed(Y :: Wgpac),
compile_wgpac(Y :: Wgpac, Rate), !.
compile_wgpac(Wgpac, Rate) :-
biocham_command,
type(Wgpac, wgpac),
type(Rate, number),
doc('compiles a weak-gpac into a biochemical system.'),
%% write('Start named compilation of :'), write_wgpac(Wgpac), nl,
wgpac_named(Wgpac),
wgpac_well_formed(Wgpac),
Wgpac = Y :: B,
biocham_command,
doc('compiles a weak-gpac into a biochemical system.'),
type(Wgpac, wgpac),
retractall(fresh_index(_)),
assert(fresh_index(0)),
type(Rate, number),
compile_wgpac_impl(Wgpac, Rate).
compile_wgpac_impl(Y, _) :-
object(Y),
!,
print_message(informational, start(object, Y)).
compile_wgpac_impl(Wgpac, Rate) :-
Wgpac = Y :: B,
wgpac_well_formed(Wgpac),
!,
print_message(informational, start(named, Wgpac)),
(
B = K,
concentration(K)
->
present([Y], K)
;
B = W1 + W2
->
print_message(informational, found('Sum box')),
(
wgpac_named(W1)
->
print_message(informational, found(1, named, W1)),
wgpac_name(W1, X1),
compile_wgpac_impl(W1, Rate)
;
print_message(informational, found(1, anonymous, W1)),
get_fresh(N1),
atom_concat('x_auto_', N1, X1),
compile_wgpac_impl(X1 :: W1, Rate)
),
(
wgpac_named(W2)
->
print_message(informational, found(2, named, W2)),
wgpac_name(W2, X2),
compile_wgpac_impl(W2, Rate)
;
print_message(informational, found(2, anonymous, W2)),
get_fresh(N2),
atom_concat('x_auto_', N2, X2),
compile_wgpac_impl(X2 :: W2, Rate)
),
add_reaction(Rate * [X1] for _ =[X1]=> Y),
add_reaction(Rate * [X2] for _ =[X2]=> Y),
add_reaction(Rate * [Y] for Y => _)
;
B = W1 * W2
->
print_message(informational, found('Product box')),
(
B = K,
concentration(K)
->
present([Y], K)
;
B = W1 + W2
->
%% write('Sum box'), nl,
( wgpac_named(W1)
->
%% write('Named(1): '), write_wgpac(W1), nl,
wgpac_name(W1, X1),
compile_wgpac(W1, Rate)
;
wgpac_anonymous(W1)
->
%% write('Anonymous(1): '), write_wgpac(W1), nl,
get_fresh(N1),
atom_concat('x_auto_', N1, X1),
compile_wgpac(X1 :: W1, Rate)
),
( wgpac_named(W2)
->
%% write('Named(2): '), write_wgpac(W2), nl,
wgpac_name(W2, X2),
compile_wgpac(W2, Rate)
;
wgpac_anonymous(W2)
->
%% write('Anonymous(2): '), write_wgpac(W2), nl,
get_fresh(N2),
atom_concat('x_auto_', N2, X2),
compile_wgpac(X2 :: W2, Rate)
),
add_reaction(Rate * [X1] for _ =[X1]=> Y),
add_reaction(Rate * [X2] for _ =[X2]=> Y),
add_reaction(Rate * [Y] for Y => _)
;
B = W1 * W2
->
%% write('Product box'), nl,
( wgpac_named(W1)
->
%% write('Named(1): '), write_wgpac(W1), nl,
wgpac_name(W1, X1),
compile_wgpac(W1, Rate)
;
wgpac_anonymous(W1)
->
%% write('Anonymous(1): '), write_wgpac(W1), nl,
get_fresh(N1),
atom_concat('x_auto_', N1, X1),
compile_wgpac(X1 :: W1, Rate)
),
( wgpac_named(W2)
->
%% write('Named(2): '), write_wgpac(W2), nl,
wgpac_name(W2, X2),
compile_wgpac(W2, Rate)
;
wgpac_anonymous(W2)
->
%% write('Anonymous(2): '), write_wgpac(W2), nl,
get_fresh(N2),
atom_concat('x_auto_', N2, X2),
compile_wgpac(X2 :: W2, Rate)
),
add_reaction(Rate * [X1] * [X2] for _ =[X1 + X2]=> Y),
add_reaction(Rate * [Y] for Y => _)
;
B = integral W1
->
( wgpac_named(W1)
->
wgpac_name(W1, X1),
compile_wgpac(W1, Rate)
;
wgpac_anonymous(W1)
->
get_fresh(N),
atom_concat('x_auto_', N, X1),
compile_wgpac(X1 :: W1, Rate)
),
add_reaction(_ =[X1]=> Y)
).
wgpac_named(W1)
->
print_message(informational, found(1, named, W1)),
wgpac_name(W1, X1),
compile_wgpac_impl(W1, Rate)
;
print_message(informational, found(1, anonymous, W1)),
get_fresh(N1),
atom_concat('x_auto_', N1, X1),
compile_wgpac_impl(X1 :: W1, Rate)
),
(
wgpac_named(W2)
->
print_message(informational, found(2, named, W2)),
wgpac_name(W2, X2),
compile_wgpac_impl(W2, Rate)
;
print_message(informational, found(2, anonymous, W2)),
get_fresh(N2),
atom_concat('x_auto_', N2, X2),
compile_wgpac_impl(X2 :: W2, Rate)
),
add_reaction(Rate * [X1] * [X2] for _ =[X1 + X2]=> Y),
add_reaction(Rate * [Y] for Y => _)
;
B = integral W1
->
(
wgpac_named(W1)
->
wgpac_name(W1, X1),
compile_wgpac_impl(W1, Rate)
;
get_fresh(N),
atom_concat('x_auto_', N, X1),
compile_wgpac_impl(X1 :: W1, Rate)
),
add_reaction(_ =[X1]=> Y)
).
compile_wgpac_impl(Wgpac, Rate) :-
print_message(informational, start(anonymous, Wgpac)),
get_fresh(N),
atom_concat('x_auto_', N, Y),
wgpac_well_formed(Y :: Wgpac),
compile_wgpac_impl(Y :: Wgpac, Rate).
:- doc('\\begin{example}\n
Cosine is generable:\n
').
Cosine is generable:\n
').
:- biocham_silent(clear_model).
:- biocham(compile_wgpac(a :: integral integral (-1 * a), 100)).
:- biocham(present(a)).
:- biocham(numerical_simulation(10, method:msbdf)).
:- biocham(plot).
:- doc('
\\end{example}
').
\\end{example}
').
compile_wgpac(WgpacSet, Rate) :-
biocham_command,
......@@ -251,47 +232,21 @@ compile_wgpac(WgpacSet, Rate) :-
).
debug_iswgpac(W) :-
biocham_command,
(wgpac(W) -> write('WGPAC') ; write('not WGPAC')),
nl.
biocham_command,
(wgpac(W) -> write('WGPAC') ; write('not WGPAC')),
nl.
debug_iswgpacbox(B) :-
biocham_command,
(wgpacbox(B) -> write('WGPAC BOX') ; write('not WGPAC BOX')),
nl.
write_wgpac(Y :: B) :-
object(Y),
write(Y),
write(' :: '),
write_wgpac_box(B).
write_wgpac(B) :-
write_wgpac_box(B).
write_wgpac(Y) :-
object(Y),
write(Y).
write_wgpac_box(K) :-
concentration(K),
write(K).
write_wgpac_box(W1 + W2) :-
write('('),
write_wgpac(W1),
write(' + '),
write_wgpac(W2),
write(')').
write_wgpac_box(W1 * W2) :-
write('('),
write_wgpac(W1),
write(' * '),
write_wgpac(W2),
write(')').
write_wgpac_box(integral W) :-
write('( integral '),
write_wgpac(W),
write(')').
biocham_command,
(wgpacbox(B) -> write('WGPAC BOX') ; write('not WGPAC BOX')),
nl.
prolog:message(start(Type, Object)) -->
['Start ~w compilation of: ~w'-[Type, Object]].
prolog:message(found(Position, Type, Object)) -->
['Found ~w at position ~w: ~w'-[Type, Position, Object]].
prolog:message(found(Object)) -->
['Found ~w'-[Object]].
......@@ -3,6 +3,6 @@
:- begin_tests(wgpac).
test('compile_wgpac') :-
compile_wgpac(a :: integral integral (-1 * a), 100).
compile_wgpac(a :: integral integral (-1 * a), 100).
:- end_tests(wgpac).
\ No newline at end of file
:- end_tests(wgpac).
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