Commit 9d917df7 authored by guillaume le guludec's avatar guillaume le guludec

minor changes

parent 8c90f151
......@@ -18,13 +18,15 @@
disable_plus_minus_mode/0,
which_plus_minus_mode/0,
set_plus_minus_rate/1
set_plus_minus_rate/1,
set_kinetics_rate/1
]).
:- dynamic
fresh_index/1,
plus_minus_mode/0,
plus_minus_rate/1.
plus_minus_rate/1,
kinetics_rate/1.
:- devdoc('\\section{Grammars}').
......@@ -84,14 +86,17 @@ transfer_strictly_proper(F) :-
enable_plus_minus_mode :-
biocham_command,
doc('Each variable corresponds to two species: one for the negative part and one for the positive part.'),
( \+(plus_minus_mode) -> assert(plus_minus_mode) ; true ).
disable_plus_minus_mode :-
biocham_command,
doc('Each variable corresponds to one species.').
( plus_minus_mode -> retract(plus_minus_mode) ; true ).
which_plus_minus_mode :-
biocham_command,
doc('Displays which mode is being used.'),
( plus_minus_mode -> write('enabled') ; write('disabled') ), nl.
plus_minus_rate(1000).
......@@ -99,10 +104,19 @@ plus_minus_rate(1000).
set_plus_minus_rate(Rate) :-
biocham_command,
type(Rate, number),
doc('Set the annihilation rate between two complementary species.'),
retract(plus_minus_rate(_)),
assert(plus_minus_rate(Rate)).
kinetics_rate(1000).
set_kinetics_rate(Rate) :-
biocham_command,
type(Rate, number),
doc('Set the final summator rate'),
retract(kinetics_rate(_)),
assert(kinetics_rate(Rate)).
% some handy shortcuts
small(N) :-
......@@ -120,6 +134,17 @@ get_index(N) :-
M is N + 1,
assert(fresh_index(M)).
output_counter(0).
get_output_counter(N) :-
retract(output_counter(N)),
M is N + 1,
assert(output_counter(M)).
reset_output_counter :-
retract(output_counter(_)),
assert(output_counter(0)).
add_normal(A * s ^ N, 0, A * s ^ N) :-
number(A), nat(N), !.
......@@ -414,10 +439,12 @@ transfer_block_1_0(K0, K1, U, Y) :-
;
true
),
plus_minus_rate(K),
% annihilation rules
add_reaction(1000 * [U_plus] * [U_minus] for U_plus + U_minus => _),
add_reaction(1000 * [Y_plus] * [Y_minus] for Y_plus + Y_minus => _)
add_reaction(K * [U_plus] * [U_minus] for U_plus + U_minus => _),
add_reaction(K * [Y_plus] * [Y_minus] for Y_plus + Y_minus => _)
;
add_reaction(K1 * [U] for _ =[U]=> Y),
add_reaction(K0 * [Y] for Y => _)
......@@ -476,10 +503,12 @@ transfer_block_2_0(K0, K1, K2, K3, U, Y, X1) :-
true
),
plus_minus_rate(K),
% annihilation rules
add_reaction(1000 * [U_plus] * [U_minus] for U_plus + U_minus => _),
add_reaction(1000 * [Y_plus] * [Y_minus] for Y_plus + Y_minus => _),
add_reaction(1000 * [X1_plus] * [X1_minus] for X1_plus + X1_minus => _)
add_reaction(K * [U_plus] * [U_minus] for U_plus + U_minus => _),
add_reaction(K * [Y_plus] * [Y_minus] for Y_plus + Y_minus => _),
add_reaction(K * [X1_plus] * [X1_minus] for X1_plus + X1_minus => _)
;
add_reaction(K1 * [U] for _=[U]=> X1),
......@@ -489,19 +518,6 @@ transfer_block_2_0(K0, K1, K2, K3, U, Y, X1) :-
).
transfer_block_2_1(K0, K1, K2, K3, U, Y, X2) :-
%%write('(2, 1)-degree reaction block with param ('),
%%write(K0), write(', '), write(K1), write(', '),
%%write(K2),write(', '), write(K3), write(')'),
%%write('added.'), nl,
%%( plus_minus_mode()
%% ->
%% true
%%;
%%add_reaction(K1 * [U] for _=[U]=> Y),
%%add_reaction(-K2 * [X2] for _=[X2]=> Y),
%%add_reaction(K3 * [Y] for _=[Y]=> X2),
%%add_reaction(K0 * [Y] for Y => _)
%%).
transfer_block_2_0(K0, K1, K2, K3, U, X2, Y).
......@@ -542,9 +558,24 @@ translate_to_blocks(AL, Q, M, U, Y) :-
list_to_1([], _, 0, _, _).
list_to_1([AH|AT], Alpha, M, U, Y) :-
kinetics_rate(K),
( AH = [A]
->
( \+(small(A)) -> transfer_series_1_0(M, A, Alpha, U, Y) ; true )
( \+(small(A))
->
get_index(N),
atom_concat(Y, '_', Y_underscore), atom_concat(Y_underscore, N, Y_N),
transfer_series_1_0(M, A, Alpha, U, Y_N),
( plus_minus_mode()
->
atom_concat(Y_N, '_plus', Y_N_plus), atom_concat(Y_N, '_minus', Y_N_minus),
atom_concat(Y, '_plus', Y_plus), atom_concat(Y, '_minus', Y_minus),
add_reaction(K * [Y_N_plus] for _=[Y_N_plus]=> Y_plus),
add_reaction(K * [Y_N_minus] for _=[Y_N_minus]=> Y_minus)
;
add_reaction(K * [Y_N] for _=[Y_N]=> Y) )
;
true )
;
AH = []
->
......@@ -560,25 +591,53 @@ list_to_1([AH|AT], Alpha, M, U, Y) :-
list_to_2([], _, _, 0, _, _).
list_to_2([BH|BT], Beta, Gamma, M, U, Y) :-
kinetics_rate(K),
( BH = [B0, B1]
->
( \+(small(B0)) ->
%atomic_list_concat(['x1', M, Beta, Gamma, U, Y], '_', X1),
X1 = 'x1_',
transfer_series_2_0(M, B0, Beta, Gamma, U, Y, X1)
get_index(N1),
atom_concat(Y, '_', Y_underscore1), atom_concat(Y_underscore1, N1, Y_N1),
transfer_series_2_0(M, B0, Beta, Gamma, U, Y_N1, X1),
( plus_minus_mode()
->
atom_concat(Y_N1, '_plus', Y_N1_plus), atom_concat(Y_N1, '_minus', Y_N1_minus),
atom_concat(Y, '_plus', Y_plus), atom_concat(Y, '_minus', Y_minus),
add_reaction(K * [Y_N1_plus] for _=[Y_N1_plus]=> Y_plus),
add_reaction(K * [Y_N1_minus] for _=[Y_N1_minus]=> Y_minus)
;
add_reaction(K * [Y_N1] for _=[Y_N1]=> Y) )
; true ),
( \+ (small(B1)) ->
X2 = 'x2_',
%atomic_list_concat(['x2', M, Beta, Gamma, U, Y], '_', X2),
transfer_series_2_1(M, B1, Beta, Gamma, U, Y, X2)
get_index(N2),
atom_concat(Y, '_', Y_underscore2), atom_concat(Y_underscore2, N2, Y_N2),
transfer_series_2_1(M, B1, Beta, Gamma, U, Y_N2, X2),
( plus_minus_mode()
->
atom_concat(Y_N2, '_plus', Y_N2_plus), atom_concat(Y_N2, '_minus', Y_N2_minus),
atom_concat(Y, '_plus', Y_plus), atom_concat(Y, '_minus', Y_minus),
add_reaction(K * [Y_N2_plus] for _=[Y_N2_plus]=> Y_plus),
add_reaction(K * [Y_N2_minus] for _=[Y_N2_minus]=> Y_minus)
;
add_reaction(K * [Y_N2] for _=[Y_N2]=> Y) )
; true )
;
BH = [B0]
->
( \+(small(B0)) ->
X1 = 'x1_',
%atomic_list_concat(['x1', M, Beta, Gamma, U, Y], '_', X1),
transfer_series_2_0(M, B0, Beta, Gamma, U, Y, X1)
get_index(N1),
atom_concat(Y, '_', Y_underscore1), atom_concat(Y_underscore1, N1, Y_N1),
transfer_series_2_0(M, B0, Beta, Gamma, U, Y_N1, X1),
( plus_minus_mode()
->
atom_concat(Y_N1, '_plus', Y_N1_plus), atom_concat(Y_N1, '_minus', Y_N1_minus),
atom_concat(Y, '_plus', Y_plus), atom_concat(Y, '_minus', Y_minus),
add_reaction(K * [Y_N1_plus] for _=[Y_N1_plus]=> Y_plus),
add_reaction(K * [Y_N1_minus] for _=[Y_N1_minus]=> Y_minus)
;
add_reaction(K * [Y_N1] for _=[Y_N1]=> Y) )
; true )
;
BH = []
......@@ -598,10 +657,17 @@ compile_transfer_function(F, U, Y) :-
type(Y, object),
doc('compile a transfer function in variable s into a chemical filter.'),
kinetics_rate(K),
( transfer_strictly_proper(F)
->
get_partial_fraction(F, AL, QL, ML),
translate_list_to_blocks(AL, QL, ML, U, Y)
translate_list_to_blocks(AL, QL, ML, U, Y),
( plus_minus_mode() ->
atom_concat(Y, '_plus', Y_plus), atom_concat(Y, '_minus', Y_minus),
add_reaction(K * [Y_plus] for Y_plus=>_),
add_reaction(K * [Y_minus] for Y_minus=>_)
;
add_reaction(K * [Y] for Y=>_) )
;
write('Error: unproper transfer function, compilation aborted.'), nl
).
......@@ -613,10 +679,17 @@ compile_transfer_function(NL, DL, U, Y) :-
type(Y, object),
doc('compile a transfer function into a chemical filter.'),
kinetics_rate(K),
( transfer_list_strictly_proper(NL, DL)
->
partial_fraction(NL, DL, AL, QL, ML),
translate_list_to_blocks(AL, QL, ML, U, Y)
translate_list_to_blocks(AL, QL, ML, U, Y),
( plus_minus_mode() ->
atom_concat(Y, '_plus', Y_plus), atom_concat(Y, '_minus', Y_minus),
add_reaction(K * [Y_plus] for Y_plus=>_),
add_reaction(K * [Y_minus] for Y_minus=>_)
;
add_reaction(K * [Y] for Y=>_) )
;
write('Error: unproper transfer function, compilation aborted.'), nl
).
......@@ -624,6 +697,7 @@ compile_transfer_function(NL, DL, U, Y) :-
:- doc('\\begin{example}
').
:- biocham_silent(clear_model).
:- biocham(set_kinetics_rate(1000)).
:- biocham(compile_transfer_function([22, 51, 47, 19, 3], [30, 66, 67, 36, 10, 1], a, b)).
:- biocham(present(a)).
:- biocham(numerical_simulation(20, method:msbdf)).
......
......@@ -4,7 +4,8 @@
test('compile_transfer_function') :-
clear_model,
disable_plus_minus_mode.
disable_plus_minus_mode,
set_kinetics_rate(1000),
compile_transfer_function([22, 51, 47, 19, 3], [30, 66, 67, 36, 10, 1], a, b).
:- end_tests(transfer_function).
\ No newline at end of file
......@@ -109,7 +109,7 @@ get_fresh(N) :-
compile_wgpac(Y, _) :-
biocham_command,
write('Start compilation of object :'), write(Y), nl,
%% write('Start compilation of object :'), write(Y), nl,
object(Y), !.
......@@ -118,7 +118,7 @@ compile_wgpac(Wgpac, Rate) :-
type(Wgpac, wgpac),
type(Rate, number),
write('Start anonymous of: '), write_wgpac(Wgpac), nl,
%% write('Start anonymous of: '), write_wgpac(Wgpac), nl,
wgpac_anonymous(Wgpac),
get_fresh(N),
......@@ -133,7 +133,7 @@ compile_wgpac(Wgpac, Rate) :-
type(Rate, number),
doc('compiles a weak-gpac into a biochemical system.'),
write('Start named compilation of :'), write_wgpac(Wgpac), nl,
%% write('Start named compilation of :'), write_wgpac(Wgpac), nl,
wgpac_named(Wgpac),
wgpac_well_formed(Wgpac),
......@@ -146,29 +146,29 @@ compile_wgpac(Wgpac, Rate) :-
;
B = W1 + W2
->
write('Sum box'), nl,
%% write('Sum box'), nl,
( wgpac_named(W1)
->
write('Named(1): '), write_wgpac(W1), nl,
%% 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,
%% 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,
%% 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,
%% write('Anonymous(2): '), write_wgpac(W2), nl,
get_fresh(N2),
atom_concat('x_auto_', N2, X2),
compile_wgpac(X2 :: W2, Rate)
......@@ -180,29 +180,29 @@ compile_wgpac(Wgpac, Rate) :-
;
B = W1 * W2
->
write('Product box'), nl,
%% write('Product box'), nl,
( wgpac_named(W1)
->
write('Named(1): '), write_wgpac(W1), nl,
%% 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,
%% 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,
%% 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,
%% write('Anonymous(2): '), write_wgpac(W2), nl,
get_fresh(N2),
atom_concat('x_auto_', N2, X2),
compile_wgpac(X2 :: W2, Rate)
......@@ -239,6 +239,17 @@ compile_wgpac(Wgpac, Rate) :-
\\end{example}
').
compile_wgpac(WgpacSet, Rate) :-
biocham_command,
type(WgpacSet, {wgpac}),
doc('compiles a set of w-gpac.'),
\+ (
member(Wgpac, WgpacSet),
\+ (
compile_wgpac(Wgpac, Rate)
)
).
debug_iswgpac(W) :-
biocham_command,
(wgpac(W) -> write('WGPAC') ; write('not 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