Commit 4292f8d4 authored by Thierry Martinez's avatar Thierry Martinez
Browse files

Graph editors...

parents 58458c6d 20c18df4
...@@ -10,8 +10,8 @@ biocham: $(MODULES) toc.org Makefile ...@@ -10,8 +10,8 @@ biocham: $(MODULES) toc.org Makefile
@echo $(MODULES) @echo $(MODULES)
swipl -o biocham --goal=start --toplevel=toplevel -c $(MODULES) swipl -o biocham --goal=start --toplevel=toplevel -c $(MODULES)
biocham_debug: $(MODULES) toc.org Makefile biocham_debug: $(MODULES) $(TEST_MODULES) toc.org Makefile
swipl -o biocham_debug --goal=initialize -c $(MODULES) swipl -o biocham_debug --goal=initialize -c $(MODULES) $(TEST_MODULES)
tests: biocham_tests tests: biocham_tests
./biocham_tests ./biocham_tests
......
...@@ -29,7 +29,9 @@ add_equivalence_class_list(EquivalenceClassList) :- ...@@ -29,7 +29,9 @@ add_equivalence_class_list(EquivalenceClassList) :-
true true
; ;
list_to_equals(EquivalenceClassList, EquivalenceClass), list_to_equals(EquivalenceClassList, EquivalenceClass),
add_item(alias, EquivalenceClassList, alias(EquivalenceClass)), add_item([
kind: alias, key: EquivalenceClassList, item: alias(EquivalenceClass)
]),
simplify_all_reactions simplify_all_reactions
). ).
...@@ -81,7 +83,7 @@ canonical(Object, Canonical) :- ...@@ -81,7 +83,7 @@ canonical(Object, Canonical) :-
list_aliases :- list_aliases :-
biocham_command, biocham_command,
doc('shows the values of all known aliases.'), doc('shows the values of all known aliases.'),
list_items([model: current_model, kind: alias]). list_items([kind: alias]).
delete_alias(Object) :- delete_alias(Object) :-
......
...@@ -6,6 +6,6 @@ test('alias', [true(Reactions == [2 * a => c])]) :- ...@@ -6,6 +6,6 @@ test('alias', [true(Reactions == [2 * a => c])]) :-
clear_model, clear_model,
add_reaction(a + b => c), add_reaction(a + b => c),
command(alias(a = b)), command(alias(a = b)),
all_items([model: current_model, kind: reaction], Reactions). all_items([kind: reaction], Reactions).
:- end_tests(aliases). :- end_tests(aliases).
...@@ -31,7 +31,7 @@ add_conservation(Conservation) :- ...@@ -31,7 +31,7 @@ add_conservation(Conservation) :-
a warning.' a warning.'
), ),
solution_to_conservation(Conservation, C), solution_to_conservation(Conservation, C),
add_item(conservation, [], Conservation, Id), add_item([kind: conservation, item: Conservation, id: Id]),
set_annotation(Id, conservation_list, C). set_annotation(Id, conservation_list, C).
......
...@@ -7,14 +7,14 @@ ...@@ -7,14 +7,14 @@
test( test(
'add_conservation adds a conservation', 'add_conservation adds a conservation',
[ [
setup(models:clear_model), setup(clear_model),
cleanup(models:clear_model), cleanup(clear_model),
forall(member(Input, ['a-a' + 2*'a', 'b', 'a' + 'b'])), forall(member(Input, ['a-a' + 2*'a', 'b', 'a' + 'b'])),
true(Conservations == [Input]) true(Conservations == [Input])
] ]
) :- ) :-
command(add_conservation(Input)), command(add_conservation(Input)),
all_items([model: current_model, kind: conservation], Conservations). all_items([kind: conservation], Conservations).
%%% FIXME should test that conservations are properly used for numerical %%% FIXME should test that conservations are properly used for numerical
%%% integration %%% integration
...@@ -23,31 +23,31 @@ test( ...@@ -23,31 +23,31 @@ test(
'delete_conservation deletes the correct conservation', 'delete_conservation deletes the correct conservation',
[ [
setup(set_some_conservations), setup(set_some_conservations),
cleanup(models:clear_model), cleanup(clear_model),
true(Conservations == ['a-a'+2*a,'c-c'+2*c]) true(Conservations == ['a-a'+2*a,'c-c'+2*c])
] ]
) :- ) :-
command(delete_conservation(b-b + 2*b)), command(delete_conservation(b-b + 2*b)),
all_items([model: current_model, kind: conservation], Conservations). all_items([kind: conservation], Conservations).
test( test(
'delete_conservations deletes all conservations', 'delete_conservations deletes all conservations',
[ [
setup(set_some_conservations), setup(set_some_conservations),
cleanup(models:clear_model), cleanup(clear_model),
true(Conservations == []) true(Conservations == [])
] ]
) :- ) :-
command(delete_conservations), command(delete_conservations),
all_items([model: current_model, kind: conservation], Conservations). all_items([kind: conservation], Conservations).
test( test(
'list_conservations lists all conservations', 'list_conservations lists all conservations',
[ [
setup(set_some_conservations), setup(set_some_conservations),
cleanup(models:clear_model), cleanup(clear_model),
true(Conservations == true(Conservations ==
'[0] a-a+2*a\n[1] b-b+2*b\n[2] c-c+2*c\n') '[0] a-a+2*a\n[1] b-b+2*b\n[2] c-c+2*c\n')
] ]
...@@ -58,8 +58,8 @@ test( ...@@ -58,8 +58,8 @@ test(
test( test(
'check_conservations is ok with trivial P-invariants', 'check_conservations is ok with trivial P-invariants',
[ [
setup((models:clear_model, set_prolog_flag(verbose, silent))), setup((clear_model, set_prolog_flag(verbose, silent))),
cleanup((models:clear_model, set_prolog_flag(verbose, normal))) cleanup((clear_model, set_prolog_flag(verbose, normal)))
] ]
) :- ) :-
command(add_reaction(a => b)), command(add_reaction(a => b)),
...@@ -71,8 +71,8 @@ test( ...@@ -71,8 +71,8 @@ test(
test( test(
'check_conservations is ok with kinetically conserved moieties', 'check_conservations is ok with kinetically conserved moieties',
[ [
setup((models:clear_model, set_prolog_flag(verbose, silent))), setup((clear_model, set_prolog_flag(verbose, silent))),
cleanup((models:clear_model, set_prolog_flag(verbose, normal))) cleanup((clear_model, set_prolog_flag(verbose, normal)))
] ]
) :- ) :-
command(add_reaction(k*[a] for a => b)), command(add_reaction(k*[a] for a => b)),
...@@ -84,8 +84,8 @@ test( ...@@ -84,8 +84,8 @@ test(
test( test(
'check_conservations is unhappy with non-conserved moieties', 'check_conservations is unhappy with non-conserved moieties',
[ [
setup((models:clear_model, set_prolog_flag(verbose, silent))), setup((clear_model, set_prolog_flag(verbose, silent))),
cleanup((models:clear_model, set_prolog_flag(verbose, normal))), cleanup((clear_model, set_prolog_flag(verbose, normal))),
true(Warnings == 1) true(Warnings == 1)
] ]
) :- ) :-
...@@ -101,7 +101,7 @@ test( ...@@ -101,7 +101,7 @@ test(
set_some_conservations :- set_some_conservations :-
models:clear_model, clear_model,
command(add_conservation(a-a + 2*a)), command(add_conservation(a-a + 2*a)),
command(add_conservation(b-b + 2*b)), command(add_conservation(b-b + 2*b)),
command(add_conservation(c-c + 2*c)). command(add_conservation(c-c + 2*c)).
......
...@@ -36,7 +36,7 @@ biocham_silent(_). ...@@ -36,7 +36,7 @@ biocham_silent(_).
generate_doc :- generate_doc :-
set_plot_driver(plot_png), set_plot_driver(gnu_plot_png),
set_counter(plot_png, 0), set_counter(plot_png, 0),
generate_doc(doc), generate_doc(doc),
generate_doc(devdoc). generate_doc(devdoc).
...@@ -839,6 +839,10 @@ write_command(begin, enumerate, Stream) :- ...@@ -839,6 +839,10 @@ write_command(begin, enumerate, Stream) :-
nb_setval(opened_li, false), nb_setval(opened_li, false),
write(Stream, '</div>\n<ol>\n'). write(Stream, '</div>\n<ol>\n').
write_command(begin, example, Stream) :-
!,
write(Stream, '</div><div class="example"><div><strong>Example.</strong> ').
write_command(item, Argument, Stream) :- write_command(item, Argument, Stream) :-
!, !,
close_opened_li(Stream), close_opened_li(Stream),
...@@ -856,18 +860,17 @@ write_command(end, enumerate, Stream) :- ...@@ -856,18 +860,17 @@ write_command(end, enumerate, Stream) :-
close_opened_li(Stream), close_opened_li(Stream),
write(Stream, '</ol>\n<div>'). write(Stream, '</ol>\n<div>').
write_command(example, Argument, Stream) :- write_command(end, example, Doc) :-
!, !,
write(Stream, '</div>\n<div><strong>Example.</strong> '), write(Doc, '</div></div><div>').
write_doc(Stream, Argument).
write_command(section, Argument, Stream) :- write_command(section, Argument, Stream) :-
!, !,
nb_getval(current_counters, Counters), nb_getval(current_counters, Counters),
length(Counnters, CounterCount), length(Counters, CounterCount),
SectionLevel is CounterCount + 2, SectionLevel is CounterCount + 2,
format(Stream, '</div>\n<h~d>', [SectionLevel]), format(Stream, '</div>\n<h~d>', [SectionLevel]),
write_doc(Stream, Argument) write_doc(Stream, Argument),
format(Stream, '</h~d>\n<div>', [SectionLevel]). format(Stream, '</h~d>\n<div>', [SectionLevel]).
write_command(Command, _Argument, _Stream) :- write_command(Command, _Argument, _Stream) :-
......
:- module(
graph_editor,
[
new_graph/0,
delete_graph/1,
set_graph_name/1,
list_graphs/0,
select_graph/1,
draw_graph/0,
export_graph/1,
add_vertex/1,
delete_vertex/1,
add_attribute/2,
delete_attribute/2,
list_attributes/1,
edge/1,
add_edge/1,
delete_edge/1,
list_edges/0,
get_current_graph/1
]
).
:- devdoc('\\section{Commands}').
new_graph :-
biocham_command,
doc('Creates a new graph.'),
add_item([kind: graph, key: new_graph, id: Id]),
set_current_graph(Id).
delete_graph(Name) :-
biocham_command,
type(Name, name),
doc('Deletes a graph.'),
delete_items([kind: graph, key: Name]).
set_graph_name(Name) :-
biocham_command,
type(Name, name),
doc('Sets the name of the current graph.'),
get_current_graph(Id),
replace_item(Id, graph, Name, Name).
list_graphs :-
biocham_command,
doc('Lists the graph of the current model.'),
list_items([kind: graph]).
select_graph(Name) :-
biocham_command,
type(Name, name),
doc('Selects a graph'),
find_item([kind: graph, key: Name, id: Id]),
set_current_graph(Id).
draw_graph :-
biocham_command,
doc('').
export_graph(Argument) :-
biocham_command,
type(Argument, type),
doc('').
add_vertex(Name) :-
biocham_command,
type(Name, name),
doc('Adds a vertex to the current graph.'),
get_current_graph(GraphId),
add_item([parent: GraphId, kind: vertex, key: Name]).
delete_vertex(Name) :-
biocham_command,
type(Name, name),
doc('Removes a vertex from the current graph.'),
get_current_graph(GraphId),
delete_item([parent: GraphId, kind: vertex, key: Name]).
add_attribute(Name, Attribute) :-
biocham_command,
type(Name, name),
type(Attribute, name),
doc('Adds an attribute to a vertex.'),
find_vertex(Name, Id),
(
find_item([parent: Id, kind: attribute, key: Attribute])
->
true
;
add_item([parent: Id, kind: attribute, key: Attribute])
).
delete_attribute(Name, Attribute) :-
biocham_command,
type(Name, name),
type(Abbribute, name),
doc('Removes an attribute from a vertex.'),
find_vertex(Name, Id),
delete_item([parent: Id, kind: attribute, key: Attribute]).
list_attributes(Name) :-
biocham_command,
type(Name, name),
doc('List the attributes of a vertex.'),
find_vertex(Name, Id),
list_items([parent: Id, kind: attribute]).
:- grammar(edge).
edge(From -> To) :-
name(From),
name(To).
add_edge(Edge) :-
biocham_command,
type(Edge, edge),
doc('Adds an edge'),
Edge = (From -> To),
find_vertex(From, FromId),
find_vertex(To, ToId),
get_current_graph(GraphId),
add_item([parent: GraphId, kind: edge, key: Edge, id: Id]),
add_dependency(Id, FromId),
add_dependency(Id, ToId).
delete_edge(Edge) :-
biocham_command,
type(Edge, edge),
doc('Deletes an edge'),
get_current_graph(GraphId),
delete_item([parent: GraphId, kind: edge, key: Edge]).
list_edges :-
biocham_command,
doc('Lists the edges of the current graph'),
get_current_graph(GraphId),
list_items([parent: GraphId, kind: edge]).
:- devdoc('\\section{End of commands}').
find_vertex(Name, Id) :-
get_current_graph(GraphId),
find_item([parent: GraphId, kind: vertex, key: Name, id: Id]).
deselect_graph :-
\+ (
item([kind: Graph, id: Id]),
\+ (
(
delete_annotation(Id, selected)
->
true
;
true
)
)
).
set_current_graph(Id) :-
deselect_graph,
set_annotation(Id, selected, selected).
get_current_graph(Id) :-
(
item([kind: Graph, id: Id]),
get_annotation(Id, selected, selected)
->
true
;
throw(error(no_graph_selected))
).
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
get_initial_state(Object, State) :- get_initial_state(Object, State) :-
( (
item([model: current_model, kind: initial_state, key: Object, item: Item]) item([kind: initial_state, key: Object, item: Item])
-> ->
( (
Item = present(Object) Item = present(Object)
...@@ -59,7 +59,7 @@ list_initial_state :- ...@@ -59,7 +59,7 @@ list_initial_state :-
doc(' doc('
lists the objects which are present (including their initial concentration) lists the objects which are present (including their initial concentration)
and absent from the initial state.'), and absent from the initial state.'),
list_items([model: current_model, kind: initial_state]). list_items([kind: initial_state]).
clear_initial_state :- clear_initial_state :-
...@@ -67,12 +67,7 @@ clear_initial_state :- ...@@ -67,12 +67,7 @@ clear_initial_state :-
doc(' doc('
makes undefined all objects possibly present or absent in the initial makes undefined all objects possibly present or absent in the initial
state.'), state.'),
\+ ( delete_items([kind: initial_state]).
item([model: current_model, kind: initial_state, id: Id]),
\+ (
delete_item(Id)
)
).
present(ObjectSet) :- present(ObjectSet) :-
...@@ -109,7 +104,7 @@ set_state(ObjectSet, Object, State) :- ...@@ -109,7 +104,7 @@ set_state(ObjectSet, Object, State) :-
member(Object, ObjectSet), member(Object, ObjectSet),
\+ ( \+ (
undefined_object(Object), undefined_object(Object),
add_item(initial_state, Object, State) add_item([kind: initial_state, key: Object, item: State])
) )
). ).
...@@ -130,7 +125,7 @@ undefined(ObjectSet) :- ...@@ -130,7 +125,7 @@ undefined(ObjectSet) :-
undefined_object(Object) :- undefined_object(Object) :-
( (
item([model: current_model, kind: initial_state, key: Object, id: Id]) item([kind: initial_state, key: Object, id: Id])
-> ->
delete_item(Id) delete_item(Id)
; ;
...@@ -169,4 +164,4 @@ make_absent_not_present :- ...@@ -169,4 +164,4 @@ make_absent_not_present :-
defined(Object) :- defined(Object) :-
once(item([model: current_model, kind: initial_state, key: Object])). once(item([kind: initial_state, key: Object])).
...@@ -8,7 +8,7 @@ test( ...@@ -8,7 +8,7 @@ test(
) :- ) :-
clear_model, clear_model,
command(present({ a, b })), command(present({ a, b })),
all_items([model: current_model, kind: initial_state], InitialState). all_items([kind: initial_state], InitialState).
test( test(
'absent', 'absent',
...@@ -16,7 +16,7 @@ test( ...@@ -16,7 +16,7 @@ test(
) :- ) :-
clear_model, clear_model,
command(absent({ a, b })), command(absent({ a, b })),
all_items([model: current_model, kind: initial_state], InitialState). all_items([kind: initial_state], InitialState).
test( test(
'undefined', 'undefined',
...@@ -26,7 +26,7 @@ test( ...@@ -26,7 +26,7 @@ test(
command(present({ a, b, c })), command(present({ a, b, c })),
command(absent({ b, c, e })), command(absent({ b, c, e })),
command(undefined({ c, d, e })), command(undefined({ c, d, e })),
all_items([model: current_model, kind: initial_state], InitialState). all_items([kind: initial_state], InitialState).
test( test(
'make_absent_not_present', 'make_absent_not_present',
...@@ -36,7 +36,7 @@ test( ...@@ -36,7 +36,7 @@ test(
add_reaction(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([kind: initial_state], InitialState).
test( test(
'make_present_not_absent', 'make_present_not_absent',
...@@ -46,6 +46,6 @@ test( ...@@ -46,6 +46,6 @@ test(
add_reaction(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([kind: initial_state], InitialState).
:- end_tests(initial_state). :- end_tests(initial_state).
#!/bin/sh #!/bin/sh
brew install swi-prolog gsl libsbml brew install swi-prolog gsl libsbml gnuplot
...@@ -21,7 +21,7 @@ set_macro(MacroList) :- ...@@ -21,7 +21,7 @@ set_macro(MacroList) :-
replace_item(Id, macro, Macro, macro(Macro = Value)) replace_item(Id, macro, Macro, macro(Macro = Value))
), ),
error(unknown_item), error(unknown_item),
add_item(macro, Macro, macro(Macro = Value)) add_item([kind: macro, key: Macro, item: macro(Macro = Value)])
) )
) )
). ).
...@@ -31,9 +31,7 @@ show_macro(Macro) :- ...@@ -31,9 +31,7 @@ show_macro(Macro) :-
biocham_command, biocham_command,
type(Macro, macro),