Commit ad72f2ec authored by Thierry Martinez's avatar Thierry Martinez

Support for options (see numerical_simulation)

parent 551bfff0
...@@ -477,7 +477,7 @@ instantiate_grammar_body(Item) :- ...@@ -477,7 +477,7 @@ instantiate_grammar_body(Item) :-
generate_body_item_clause(Clause, Stream, Type) :- generate_body_item_clause(Clause, Stream, Type) :-
predicate_info(Clause, ArgumentTypes, BiochamCommand, Doc), predicate_info(Clause, ArgumentTypes, Options, BiochamCommand, Doc),
( (
( (
BiochamCommand = yes BiochamCommand = yes
...@@ -519,7 +519,24 @@ generate_body_item_clause(Clause, Stream, Type) :- ...@@ -519,7 +519,24 @@ generate_body_item_clause(Clause, Stream, Type) :-
write_doc_item(DocItem, Stream, Type) write_doc_item(DocItem, Stream, Type)
) )
), ),
write(Stream, '</div>') write(Stream, '\n</div>'),
(
Options = []
->
true
;
write(Stream, '\n<div>\n<h6>Options</h6>\n<dl>'),
\+ (
member(option(Option, _OptionType, OptionDoc), Options),
\+ (
format(Stream, '\n<dt>~a</dt>', [Option]),
write(Stream, '\n<dd>'),
write_doc(Stream, OptionDoc),
write(Stream, '</dd>')
)
),
write(Stream, '\n</dl>\n</div>')
)
; ;
true true
). ).
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
graph_editor, graph_editor,
[ [
% Grammars % Grammars
attribute/1,
edge/1, edge/1,
edgeref/1, edgeref/1,
% Commands % Commands
...@@ -18,7 +19,6 @@ ...@@ -18,7 +19,6 @@
list_isolated_vertices/0, list_isolated_vertices/0,
list_graph_objects/0, list_graph_objects/0,
graph_object/1, graph_object/1,
attribute/1,
set_attribute/2, set_attribute/2,
delete_attribute/2, delete_attribute/2,
list_attributes/1, list_attributes/1,
...@@ -49,6 +49,17 @@ ...@@ -49,6 +49,17 @@
:- devdoc('\\section{Grammars}'). :- devdoc('\\section{Grammars}').
:- grammar(attribute).
attribute(Key = Value) :-
name(Key),
term(Value).
attribute(Name) :-
name(Name).
:- grammar(edge). :- grammar(edge).
...@@ -198,22 +209,11 @@ graph_object(Name) :- ...@@ -198,22 +209,11 @@ graph_object(Name) :-
name(Name). name(Name).
:- grammar(attribute).
attribute(Key: Value) :-
name(Key),
term(Value).
attribute(Name) :-
name(Name).
set_attribute(Id, Attribute) :- set_attribute(Id, Attribute) :-
integer(Id), integer(Id),
!, !,
( (
Attribute = Key: _Value Attribute = (Key = _Value)
-> ->
true true
; ;
...@@ -319,7 +319,7 @@ get_attribute(Id, Attribute) :- ...@@ -319,7 +319,7 @@ get_attribute(Id, Attribute) :-
integer(Id), integer(Id),
!, !,
( (
Attribute = Key: _Value Attribute = (Key = _Value)
-> ->
true true
; ;
...@@ -381,7 +381,7 @@ kind(GraphId, Name, Kind) :- ...@@ -381,7 +381,7 @@ kind(GraphId, Name, Kind) :-
kind(GraphId, Name, Kind, VertexId) :- kind(GraphId, Name, Kind, VertexId) :-
add_vertex(GraphId, Name, VertexId), add_vertex(GraphId, Name, VertexId),
set_attribute(VertexId, kind: Kind). set_attribute(VertexId, kind = Kind).
add_vertex(GraphId, Name, VertexId) :- add_vertex(GraphId, Name, VertexId) :-
......
...@@ -87,11 +87,11 @@ test( ...@@ -87,11 +87,11 @@ test(
'list_graph_objects', 'list_graph_objects',
[true(Atom == '\c [true(Atom == '\c
[0] A->B [0] A->B
[1] stochiometry:2 [1] stochiometry=2
[2] B [2] B
[3] kind:transition [3] kind=transition
[4] C [4] C
[5] kind:place [5] kind=place
[6] D [6] D
')]) :- ')]) :-
clear_model, clear_model,
...@@ -101,7 +101,7 @@ test( ...@@ -101,7 +101,7 @@ test(
command(place('C')), command(place('C')),
command(add_vertex('D')), command(add_vertex('D')),
command(add_edge('A' -> 'B')), command(add_edge('A' -> 'B')),
command(set_attribute(('A' -> 'B'), stochiometry: 2)), command(set_attribute(('A' -> 'B'), stochiometry = 2)),
with_output_to(atom(Atom), list_graph_objects). with_output_to(atom(Atom), list_graph_objects).
test('set_attribute vertex', [true(Attributes == ['object', 'item'])]) :- test('set_attribute vertex', [true(Attributes == ['object', 'item'])]) :-
...@@ -115,17 +115,17 @@ test('set_attribute vertex', [true(Attributes == ['object', 'item'])]) :- ...@@ -115,17 +115,17 @@ test('set_attribute vertex', [true(Attributes == ['object', 'item'])]) :-
find_item([parent: GraphId, kind: vertex, key: 'A', id: VertexId]), find_item([parent: GraphId, kind: vertex, key: 'A', id: VertexId]),
all_items([parent: VertexId, kind: attribute], Attributes). all_items([parent: VertexId, kind: attribute], Attributes).
test('set_attribute edge', [true(Attributes == [stochiometry: 2])]) :- test('set_attribute edge', [true(Attributes == [stochiometry = 2])]) :-
clear_model, clear_model,
new_graph, new_graph,
command(add_vertex('A', 'B')), command(add_vertex('A', 'B')),
command(add_edge('A' -> 'B')), command(add_edge('A' -> 'B')),
command(set_attribute(('A' -> 'B'), stochiometry: 2)), command(set_attribute(('A' -> 'B'), stochiometry = 2)),
get_current_graph(GraphId), get_current_graph(GraphId),
find_item([parent: GraphId, kind: edge, key: ('A' -> 'B'), id: EdgeId]), find_item([parent: GraphId, kind: edge, key: ('A' -> 'B'), id: EdgeId]),
all_items([parent: EdgeId, kind: attribute], Attributes). all_items([parent: EdgeId, kind: attribute], Attributes).
test('place', [true(Attributes == [kind: place])]) :- test('place', [true(Attributes == [kind = place])]) :-
clear_model, clear_model,
new_graph, new_graph,
command(transition('A')), command(transition('A')),
...@@ -135,7 +135,7 @@ test('place', [true(Attributes == [kind: place])]) :- ...@@ -135,7 +135,7 @@ test('place', [true(Attributes == [kind: place])]) :-
find_item([parent: GraphId, kind: vertex, key: 'A', id: VertexId]), find_item([parent: GraphId, kind: vertex, key: 'A', id: VertexId]),
all_items([parent: VertexId, kind: attribute], Attributes). all_items([parent: VertexId, kind: attribute], Attributes).
test('transition', [true(Attributes == [kind: transition])]) :- test('transition', [true(Attributes == [kind = transition])]) :-
clear_model, clear_model,
new_graph, new_graph,
command(place('A')), command(place('A')),
...@@ -155,19 +155,19 @@ test('delete_attribute', [true(Attributes == [])]) :- ...@@ -155,19 +155,19 @@ test('delete_attribute', [true(Attributes == [])]) :-
find_item([parent: GraphId, kind: vertex, key: 'A', id: VertexId]), find_item([parent: GraphId, kind: vertex, key: 'A', id: VertexId]),
all_items([parent: VertexId, kind: attribute], Attributes). all_items([parent: VertexId, kind: attribute], Attributes).
test('list_attributes vertex', [true(Atom == '[0] kind:place\n')]) :- test('list_attributes vertex', [true(Atom == '[0] kind=place\n')]) :-
clear_model, clear_model,
new_graph, new_graph,
command(place('A')), command(place('A')),
with_output_to(atom(Atom), list_attributes('A')). with_output_to(atom(Atom), list_attributes('A')).
test('list_attributes edge', [true(Atom == '[0] stochiometry:2\n')]) :- test('list_attributes edge', [true(Atom == '[0] stochiometry=2\n')]) :-
clear_model, clear_model,
new_graph, new_graph,
command(add_vertex('A')), command(add_vertex('A')),
command(add_vertex('B')), command(add_vertex('B')),
command(add_edge('A' -> 'B')), command(add_edge('A' -> 'B')),
command(set_attribute(('A' -> 'B'), stochiometry: 2)), command(set_attribute(('A' -> 'B'), stochiometry = 2)),
with_output_to(atom(Atom), list_attributes('A' -> 'B')). with_output_to(atom(Atom), list_attributes('A' -> 'B')).
test('get_attribute', [true(Kind == transition)]) :- test('get_attribute', [true(Kind == transition)]) :-
...@@ -175,6 +175,6 @@ test('get_attribute', [true(Kind == transition)]) :- ...@@ -175,6 +175,6 @@ test('get_attribute', [true(Kind == transition)]) :-
new_graph, new_graph,
command(transition('A')), command(transition('A')),
get_current_graph(GraphId), get_current_graph(GraphId),
once(get_attribute(GraphId, 'A', kind: Kind)). once(get_attribute(GraphId, 'A', kind = Kind)).
:- end_tests(graph_editor). :- end_tests(graph_editor).
...@@ -53,7 +53,7 @@ write_headers(Options) :- ...@@ -53,7 +53,7 @@ write_headers(Options) :-
length(InitialParameterValues, ParameterCount), length(InitialParameterValues, ParameterCount),
write_header('VARIABLE_COUNT', '~d', VariableCount), write_header('VARIABLE_COUNT', '~d', VariableCount),
write_header('PARAMETER_COUNT', '~d', ParameterCount), write_header('PARAMETER_COUNT', '~d', ParameterCount),
write_option('METHOD', '~a', method, Options), write_option('METHOD', 'gsl_odeiv2_step_~a', method, Options),
write_option('ERROR_EPSILON_ABSOLUTE', '~f', error_epsilon_absolute, Options), write_option('ERROR_EPSILON_ABSOLUTE', '~f', error_epsilon_absolute, Options),
write_option('ERROR_EPSILON_RELATIVE', '~f', error_epsilon_relative, Options), write_option('ERROR_EPSILON_RELATIVE', '~f', error_epsilon_relative, Options),
write_option('INITIAL_STEP_SIZE', '~f', initial_step_size, Options), write_option('INITIAL_STEP_SIZE', '~f', initial_step_size, Options),
......
...@@ -7,7 +7,7 @@ test('van_der_pol') :- ...@@ -7,7 +7,7 @@ test('van_der_pol') :-
equations: [[1], -[0] + p(0) * [1] * (1 - [0] ^ 2)], equations: [[1], -[0] + p(0) * [1] * (1 - [0] ^ 2)],
initial_values: [1.0, 0.0], initial_values: [1.0, 0.0],
initial_parameter_values: [10], initial_parameter_values: [10],
method: gsl_odeiv2_step_rk8pd, method: rk8pd,
error_epsilon_absolute: 1e-6, error_epsilon_absolute: 1e-6,
error_epsilon_relative: 1e-6, error_epsilon_relative: 1e-6,
initial_step_size: 1e-6, initial_step_size: 1e-6,
......
...@@ -65,14 +65,14 @@ influence_graph_aux(GraphId) :- ...@@ -65,14 +65,14 @@ influence_graph_aux(GraphId) :-
count(influence, InfluenceCount), count(influence, InfluenceCount),
format(atom(InfluenceCounter), 'influence~d', [InfluenceCount]), format(atom(InfluenceCounter), 'influence~d', [InfluenceCount]),
transition(GraphId, InfluenceCounter, TransitionId), transition(GraphId, InfluenceCounter, TransitionId),
set_attribute(TransitionId, sign: Sign), set_attribute(TransitionId, sign = Sign),
set_attribute(TransitionId, force: Force), set_attribute(TransitionId, force = Force),
\+ ( \+ (
member(PositiveInput, PositiveInputs), member(PositiveInput, PositiveInputs),
\+ ( \+ (
place(GraphId, PositiveInput, PlaceId), place(GraphId, PositiveInput, PlaceId),
add_edge(GraphId, PlaceId, TransitionId, EdgeId), add_edge(GraphId, PlaceId, TransitionId, EdgeId),
set_attribute(EdgeId, sign: '+') set_attribute(EdgeId, sign = '+')
) )
), ),
\+ ( \+ (
...@@ -80,7 +80,7 @@ influence_graph_aux(GraphId) :- ...@@ -80,7 +80,7 @@ influence_graph_aux(GraphId) :-
\+ ( \+ (
place(GraphId, NegativeInput, PlaceId), place(GraphId, NegativeInput, PlaceId),
add_edge(GraphId, PlaceId, TransitionId, EdgeId), add_edge(GraphId, PlaceId, TransitionId, EdgeId),
set_attribute(EdgeId, sign: '-') set_attribute(EdgeId, sign = '-')
) )
), ),
place(GraphId, Output, PlaceId), place(GraphId, Output, PlaceId),
......
option(
method: rk8pd,
error_epsilon_absolute: 1e-6,
error_epsilon_relative: 1e-6,
initial_step_size: 1e-6,
precision: 5
).
function MA(k) = k * product(S * O in [reactants], O ^ S). function MA(k) = k * product(S * O in [reactants], O ^ S).
function MM(Vm, Km) = Vm * single_reactant / (Km + single_reactant). function MM(Vm, Km) = Vm * single_reactant / (Km + single_reactant).
......
:- module( :- module(
numerical_simulation, numerical_simulation,
[ [
numerical_simulation/0, % Grammars
method/1,
% Commands
numerical_simulation/1 numerical_simulation/1
] ]
). ).
numerical_simulation :- :- devdoc('\\section{Grammars}').
biocham_command,
doc('
performs a numerical simulation up to 20s. :- grammar(method).
\\begin{example}
'),
biocham_silent(clear_model), method(rk2).
biocham(a => b),
biocham(present(a)), method(rk4).
biocham(numerical_simulation),
biocham(plot), method(rkf45).
doc('
\\end{example} method(rkck).
'),
numerical_simulation(20). method(rk8pd).
method(rk1imp).
method(rk2imp).
method(rk4imp).
method(bsimp).
method(msadams).
method(msbdf).
:- devdoc('\\section{Commands}').
numerical_simulation(Time) :- numerical_simulation(Time) :-
biocham_command, biocham_command,
type(Time, time), type(Time, time),
option(method, method, Method, 'method for the numerical solver'),
option(
error_epsilon_absolute, number, ErrorEpsilonAbsolute,
'absolute error for the numerical solver'
),
option(
error_epsilon_relative, number, ErrorEpsilonRelative,
'relative error for the numerical solver'
),
option(
initial_step_size, number, InitialStepSize,
'initial step size for the numerical solver'
),
option(
precision, number, Precision,
'precision for the numerical solver'
),
doc('performs a numerical simulation up to a given time.'), doc('performs a numerical simulation up to a given time.'),
with_current_ode_system(( with_current_ode_system((
numerical_simulation:make_ode_system, numerical_simulation:make_ode_system,
numerical_simulation:solve(Time) numerical_simulation:solve(
Time, Method, ErrorEpsilonAbsolute, ErrorEpsilonRelative, InitialStepSize,
Precision
)
)). )).
...@@ -39,7 +76,13 @@ make_ode_system :- ...@@ -39,7 +76,13 @@ make_ode_system :-
convert_ode. convert_ode.
solve(Time) :- :- devdoc('\\section{Private predicate}').
solve(
Time, Method, ErrorEpsilonAbsolute, ErrorEpsilonRelative, InitialStepSize,
Precision
) :-
gather_headers(Headers), gather_headers(Headers),
gather_equations(Equations), gather_equations(Equations),
gather_initial_values(InitialValues), gather_initial_values(InitialValues),
...@@ -49,11 +92,11 @@ solve(Time) :- ...@@ -49,11 +92,11 @@ solve(Time) :-
equations: Equations, equations: Equations,
initial_values: InitialValues, initial_values: InitialValues,
initial_parameter_values: InitialParameterValues, initial_parameter_values: InitialParameterValues,
method: gsl_odeiv2_step_rk8pd, method: Method,
error_epsilon_absolute: 1e-6, error_epsilon_absolute: ErrorEpsilonAbsolute,
error_epsilon_relative: 1e-6, error_epsilon_relative: ErrorEpsilonRelative,
initial_step_size: 1e-6, initial_step_size: InitialStepSize,
precision: 6, precision: Precision,
time_initial: 0, time_initial: 0,
time_final: Time time_final: Time
], ],
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
test('mapk') :- test('mapk') :-
clear_model, clear_model,
command(load(library:examples/mapk/mapk)), command(load(library:examples/mapk/mapk)),
numerical_simulation. numerical_simulation(100).
:- end_tests(numerical_simulation). :- end_tests(numerical_simulation).
...@@ -65,7 +65,7 @@ reaction_graph(GraphId) :- ...@@ -65,7 +65,7 @@ reaction_graph(GraphId) :-
( (
Reversible = true Reversible = true
-> ->
set_attribute(GraphId, [ReactionCounter], reversible: Reversible) set_attribute(GraphId, [ReactionCounter], reversible = Reversible)
; ;
true true
), ),
...@@ -74,7 +74,7 @@ reaction_graph(GraphId) :- ...@@ -74,7 +74,7 @@ reaction_graph(GraphId) :-
-> ->
true true
; ;
set_attribute(GraphId, [ReactionCounter], kinetics: Kinetics) set_attribute(GraphId, [ReactionCounter], kinetics = Kinetics)
), ),
\+ ( \+ (
( (
...@@ -90,7 +90,7 @@ reaction_graph(GraphId) :- ...@@ -90,7 +90,7 @@ reaction_graph(GraphId) :-
place(GraphId, Object), place(GraphId, Object),
add_edge(GraphId, From -> To, EdgeId), add_edge(GraphId, From -> To, EdgeId),
( (
get_attribute(EdgeId, stoichiometry: OldStoichiometry) get_attribute(EdgeId, stoichiometry = OldStoichiometry)
-> ->
NewStoichiometry is OldStoichiometry + Stoichiometry NewStoichiometry is OldStoichiometry + Stoichiometry
; ;
...@@ -105,7 +105,7 @@ reaction_graph(GraphId) :- ...@@ -105,7 +105,7 @@ reaction_graph(GraphId) :-
true true
) )
; ;
set_attribute(EdgeId, stoichiometry: NewStoichiometry) set_attribute(EdgeId, stoichiometry = NewStoichiometry)
) )
) )
) )
...@@ -132,7 +132,7 @@ make_bipartite_graph :- ...@@ -132,7 +132,7 @@ make_bipartite_graph :-
retractall(vertex_unknown(_)), retractall(vertex_unknown(_)),
\+ ( \+ (
item([parent: GraphId, kind: vertex, id: VertexId, item: Vertex]), item([parent: GraphId, kind: vertex, id: VertexId, item: Vertex]),
get_attribute(VertexId, kind: Kind), get_attribute(VertexId, kind = Kind),
\+ ( \+ (
( (
Kind = place Kind = place
...@@ -267,7 +267,7 @@ make_reactions :- ...@@ -267,7 +267,7 @@ make_reactions :-
get_kinetics(GraphId, Vertex, Kinetics) :- get_kinetics(GraphId, Vertex, Kinetics) :-
( (
get_attribute(GraphId, Vertex, kinetics: Kinetics) get_attribute(GraphId, Vertex, kinetics = Kinetics)
-> ->
true true
; ;
...@@ -277,7 +277,7 @@ get_kinetics(GraphId, Vertex, Kinetics) :- ...@@ -277,7 +277,7 @@ get_kinetics(GraphId, Vertex, Kinetics) :-
get_reversible(GraphId, Vertex, Reversible) :- get_reversible(GraphId, Vertex, Reversible) :-
( (
get_attribute(GraphId, Vertex, reversible: Reversible) get_attribute(GraphId, Vertex, reversible = Reversible)
-> ->
( (
( (
...@@ -297,7 +297,7 @@ get_reversible(GraphId, Vertex, Reversible) :- ...@@ -297,7 +297,7 @@ get_reversible(GraphId, Vertex, Reversible) :-
get_stoichiometry(EdgeId, Stoichiometry) :- get_stoichiometry(EdgeId, Stoichiometry) :-
( (
get_attribute(EdgeId, stoichiometry: Stoichiometry) get_attribute(EdgeId, stoichiometry = Stoichiometry)
-> ->
true true
; ;
......
...@@ -6,11 +6,11 @@ ...@@ -6,11 +6,11 @@
test( test(
'reaction_graph', 'reaction_graph',
[true(( [
Edges == ['A' -> 'reaction0', 'reaction0' -> 'B'], result(Edges, Stoichiometry, Kinetics)
Stoichiometry == 2, ==
Kinetics == 'MA'(3) result(['A' -> 'reaction0', 'reaction0' -> 'B'], 2, 'MA'(3))
))] ]
) :- ) :-
clear_model, clear_model,
add_reaction('MA'(3) for 'A' => 2 * 'B'), add_reaction('MA'(3) for 'A' => 2 * 'B'),
...@@ -18,8 +18,8 @@ test( ...@@ -18,8 +18,8 @@ test(
get_current_graph(GraphId), get_current_graph(GraphId),
all_items([parent: GraphId, kind: edge], Edges), all_items([parent: GraphId, kind: edge], Edges),
once(( once((
get_attribute(GraphId, 'reaction0', kinetics: Kinetics), get_attribute(GraphId, 'reaction0', kinetics = Kinetics),
get_attribute(GraphId, ('reaction0' -> 'B'), stoichiometry: Stoichiometry) get_attribute(GraphId, ('reaction0' -> 'B'), stoichiometry = Stoichiometry)
)). )).
test( test(
...@@ -38,9 +38,9 @@ test( ...@@ -38,9 +38,9 @@ test(
'a' -> 'reaction1' 'a' -> 'reaction1'
) )
), ),
command(set_attribute('reaction1', kinetics: 'MA'(2))), command(set_attribute('reaction1', kinetics = 'MA'(2))),
command(set_attribute(('c' -> 'reaction1'), stoichiometry: 3)), command(set_attribute(('c' -> 'reaction1'), stoichiometry = 3)),
command(set_attribute(('reaction1' -> 'd'), stoichiometry: 2)), command(set_attribute(('reaction1' -> 'd'), stoichiometry = 2)),
import_reactions_from_graph,