Commit d5e062f3 authored by FAGES Francois's avatar FAGES Francois
Browse files

doc

parents 4a9647e9 fa49c258
......@@ -120,7 +120,7 @@ jupyter_tests: install_kernel
# runs test unit %
test_%: biocham_debug
echo "flag(slow_test, _, false), run_tests_and_halt('$*')." | ./biocham_debug
echo "flag(slow_test, _, true), run_tests_and_halt('$*')." | ./biocham_debug
install_kernel: biocham $(KERNEL_DIR)/commands.js $(KERNEL_DIR)/commands.py $(WORKFLOWS_DIR)/workflows.js
- pip3 install --user $(JUPYTER_DIR)/kernel || pip install --user $(JUPYTER_DIR)/kernel
......
......@@ -162,6 +162,7 @@ commands = [
"option",
"pac_learning",
"parameter",
"parametrize",
"pattern_reduction",
"place",
"plot",
......
......@@ -1724,11 +1724,7 @@ abstract_names(0, []) :- !.
abstract_names(N, [Head|Tail]) :-
Nm is N-1,
divmod(Nm,26,R,C),
Code is C+65,
Rep is R+1,
char_code(Letter, Code),
stutter(Rep, Letter, Head),
new_molecule(Head),
abstract_names(Nm, Tail).
%! stutter(N,In,Out)
......
......@@ -19,6 +19,7 @@
set_model_name/1,
delete/1,
inherits/1,
parametrize/0,
% Public API
get_model_name/1,
get_model_name/2,
......@@ -54,7 +55,9 @@
at_delete/2,
get_parent/2,
get_model/2,
load_all/2
load_all/2,
parametrize_initial_concentration/0,
parametrize_reaction/0
]
).
......@@ -265,6 +268,15 @@ inherits(Ancestors) :-
)
).
%! parametrize
%
% Replace the all the numbers of a model by parameters initialized at current value
parametrize :-
biocham_command,
doc('Replace the all the numbers of a model by parameters.'),
parametrize_initial_concentration,
parametrize_reaction.
:- devdoc('\\section{Public API}').
......@@ -1090,3 +1102,81 @@ find_model_refs(RefSet, Models) :-
),
Models
).
%! parametrize_initial_concentration
%
% replace numeral initial concentration by parameter with the same value
parametrize_initial_concentration :-
forall(
(
item([item: present(Species, Value), kind:initial_state])
;
(item([item: present(Species), kind:initial_state]) ,Value=1)
)
,
(
number(Value)
->
new_parameter(K),
command(present(Species, K)),
command(parameter(K = Value))
;
true
)
).
%! parametrize_reaction
%
% Replace the numeral of a kinetic by similar parameter
parametrize_reaction :-
forall(
item([item: Reac, kind: reaction, id: Id])
,
(delete_item(Id),
introduce_param(Reac, Reac2),
command(Reac2))
).
%! introduce_param(+reaction, -parametrized_reaction)
%
% recursive routine for parametrize_reaction
introduce_param(Kin for Reac, Kin2 for Reac) :-
introduce_param(Kin, Kin2).
introduce_param(A*B, A2*B2) :-
introduce_param(A, A2),
introduce_param(B, B2).
introduce_param(A/B, A2/B2) :-
introduce_param(A, A2),
introduce_param(B, B2).
introduce_param(A+B, A2+B2) :-
introduce_param(A, A2),
introduce_param(B, B2).
introduce_param(A-B, A2-B2) :-
introduce_param(A, A2),
introduce_param(B, B2).
introduce_param(A^N, A2^N) :-
introduce_param(A, A2).
introduce_param(X, K) :-
number(X),
new_parameter(K),
command(parameter(K = X)).
introduce_param(Func, Func2) :-
Func =.. [Name | Param],
maplist(introduce_param, Param, Param2),
Func2 =.. [Name | Param2].
introduce_param(O,O).
......@@ -191,17 +191,26 @@ conserv_laws_for_multistability_graph :-
asserta(conservLawsParent(ConservList)).
%%% Conservation laws are adapted to the permutation
adapt_conserv_aux(_, [], []) :- !.
adapt_conserv_aux(Swaps, [H | T], [NewH | NewT]) :-
member([H, NewHName], Swaps),
adapt_conserv_aux([], [], _) :- !.
adapt_conserv_aux([H | T], [NewH | NewT], Swaps) :-
memberchk([H, NewHName], Swaps),
!,
correspond_vertex_name_id(NewHName, NewH),
adapt_conserv_aux(Swaps, T, NewT), !.
adapt_conserv_aux(T, NewT, Swaps).
% Isolated nodes create conservation laws with species not part of the graph
adapt_conserv_aux([H], [], Swaps) :-
\+ member([H, _], Swaps).
adapt_conserv_laws(_, [], []) :- !.
adapt_conserv_laws(Swaps, [HList | TList], [NewHList | NewTList]) :-
adapt_conserv_aux(Swaps, HList, NewHListUnsorted),
adapt_conserv_laws([], [], _) :- !.
adapt_conserv_laws([HList | TList], [NewHList | NewTList], Swaps) :-
adapt_conserv_aux(HList, NewHListUnsorted, Swaps),
sort(NewHListUnsorted, NewHList),
adapt_conserv_laws(Swaps, TList, NewTList), !.
adapt_conserv_laws(TList, NewTList, Swaps).
%%%
remove_vertex_from_conserv_laws(_, [], []) :- !.
remove_vertex_from_conserv_laws(VertexName, [H | T], L) :-
......@@ -230,6 +239,7 @@ reset_gauss_system :-
%%% Add a loop to the gauss system
add_loop_to_system(Loop) :-
debug(multistability, "Loop: ~w~n", [Loop]),
loop_gauss_system(System),
pass_loop_in_system(Loop, System, [Species, Sign], Pivots_Used),
(
......@@ -288,6 +298,7 @@ add_loop_to_system(Loop) :-
)
),
!,
debug(multistability, "Positive circuit: ~w~n", [Species_conflict]),
fail
)
;
......@@ -623,7 +634,7 @@ copy_multistability_graph(ParentId, Swaps) :-
conservLawsParent(ConservList),
retractall(conservLaws(_)),
% write(Swaps), write(' '), write(ConservList), write('\n'),
adapt_conserv_laws(Swaps, ConservList, NewConservList),
adapt_conserv_laws(ConservList, NewConservList, Swaps),
asserta(conservLaws(NewConservList)),
get_current_graph(MultiGraphId),
set_attribute(MultiGraphId, swaps_used=Swaps).
......@@ -866,6 +877,7 @@ get_vertex_to_remove(VertexId) :-
remove_best_vertex :-
get_vertex_to_remove(VertexId),
debug(multistability, "Removing vertex: ~w~n", [VertexId]),
remove_vertex(VertexId).
......@@ -944,7 +956,12 @@ check_multistability_graph :-
true
),
get_current_graph(GraphId),
get_attribute(GraphId, swaps_used=Swaps),
(
get_attribute(GraphId, swaps_used=Swaps)
->
% get_attribute creates a choice point
true
),
write('There is no multiple steady states with non-zero values, no positive circuit\n'),
(
identity_swap(Swaps)
......
......@@ -41,6 +41,8 @@
numeric_char/1,
identifier_name/1,
check_valid_identifier_name/1,
new_molecule/1,
new_parameter/1,
unify_records/2,
field_default/4,
watch_error/2,
......@@ -615,6 +617,69 @@ check_valid_identifier_name(Atom) :-
).
%! new_molecule(-Name)
%
% Generate the name of a new (and non-existent) molecule of the form A,B,C,..,AA,BB, etc.
new_molecule(Name) :-
(
nb_current(molecule_index, N)
->
true
;
N = 0
),
Np is N+1,
nb_setval(molecule_index, Np),
divmod(N,26,R,C),
Code is C+65,
Rep is R+1,
char_code(Letter, Code),
stutter(Rep, Letter, Try),
(
single_model(ModelId),
identifier_kind(ModelId, Try, object)
->
new_molecule(Name)
;
Name = Try
).
%! stutter(N,In,Out)
stutter(1, In, In) :- !.
stutter(N, In, Out) :-
Nm is N-1,
stutter(Nm, p, Tempo),
atom_concat(In, Tempo, Out).
%! new_parameter(-Name)
%
% Generate the name of a new (and non-existent) parameter of the form k_n
new_parameter(Name) :-
(
nb_current(parameter_index, N)
->
true
;
N = 1
),
Np is N+1,
nb_setval(parameter_index, Np),
atom_concat('k_',N,Try),
(
single_model(ModelId),
identifier_kind(ModelId, Try, parameter)
->
new_parameter(Name)
;
Name = Try
).
unify_records(Record0, Record1) :-
(
(var(Record0) ; var(Record1))
......
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