Commit 82061557 authored by Thierry Martinez's avatar Thierry Martinez

Aliases

parent 5e30bec0
:- module(
aliases,
[
alias/1,
list_parameters/0,
delete_parameter/1
]
).
alias(Objects) :-
biocham_command,
type(Objects, =([object])),
doc('
makes \\argument{Objects} be alternative names for the
same object.'),
equals_to_list(Objects, ObjectList),
setof(
add_item(parameter, parameter(Parameter, Value)).
parameter(Parameter) :-
biocham_command,
type(Parameter, parameter),
doc('shows the value of \\argument{Parameter}.'),
find_parameter(Parameter, _Id, Value),
write(Value),
nl.
find_parameter(Parameter, Id, Value) :-
(
item(
[model: current_model, kind: macro, id: Id],
parameter(Parameter, Value)
)
->
true
;
throw(error(undefined_parameter(Parameter)))
).
list_parameters :-
biocham_command,
doc('shows the values of all known parameters.'),
list_items([model: current_model, kind: parameter]).
delete_parameter(Parameter) :-
biocham_command,
type(Parameter, parameter),
doc('deletes a parameter'),
find_parameter(Parameter, Id, _Value),
delete_item(Id).
......@@ -14,17 +14,15 @@
get_initial_state(Object, Concentration) :-
(
item(
[model: current_model, kind: initial_state],
present(Object)
)
item([model: current_model, kind: initial_state, item: present(Object)])
->
Concentration = 1
;
item(
[model: current_model, kind: initial_state],
present(Object, Concentration)
)
item([
model: current_model,
kind: initial_state,
item: present(Object, Concentration)
])
->
true
;
......@@ -46,7 +44,7 @@ clear_initial_state :-
makes undefined all objects possibly present or absent in the initial
state.'),
\+ (
item([model: current_model, kind: initial_state, id: Id], _),
item([model: current_model, kind: initial_state, id: Id]),
\+ (
delete_item(Id)
)
......@@ -58,7 +56,7 @@ present(Object) :-
type(Object, object),
doc('\\argument{Object} is made present in the initial state.'),
undefined_no_error(Object),
add_item(initial_state, present(Object)).
add_item(initial_state, Object, present(Object)).
present(Object, Concentration) :-
......@@ -69,7 +67,7 @@ present(Object, Concentration) :-
\\argument{Object} is initialized with the given initial concentration.
An initial value equal to 0 means absent.'),
undefined_no_error(Object),
add_item(initial_state, present(Object, Concentration)).
add_item(initial_state, Object, present(Object, Concentration)).
absent(Object) :-
......@@ -81,7 +79,7 @@ absent(Object) :-
error(unknown_initial_state(_)),
true
),
add_item(initial_state, absent(Object)).
add_item(initial_state, Object, absent(Object)).
undefined_no_error(Object) :-
......@@ -99,22 +97,7 @@ undefined(Object) :-
\\argument{Object} is made possibly present or absent in the initial
state.'),
(
(
item(
[model: current_model, kind: initial_state, id: Id],
present(Object)
)
;
item(
[model: current_model, kind: initial_state, id: Id],
present(Object, _Concentration)
)
;
item(
[model: current_model, kind: initial_state, id: Id],
absent(Object)
)
)
item([model: current_model, kind: initial_state, key: Object, id: Id])
->
delete_item(Id)
;
......
......@@ -17,7 +17,7 @@ macro(Macro, Value) :-
error(undefined_macro(_)),
true
),
add_item(macro, macro(Macro, Value)).
add_item(macro, Macro, macro(Macro, Value)).
macro(Macro) :-
......
......@@ -4,10 +4,11 @@
load/1,
load_biocham/1,
new_model/0,
add_item/2,
add_item/3,
item/1,
all_items/2,
list_items/1,
delete_item/1,
item/2
delete_item/1
]
).
......@@ -143,7 +144,7 @@ clear_model :-
biocham_command,
doc('clears the current model.'),
single_model(Model),
retractall(item(_, Model, _, _)).
retractall(item(_, Model, _, _, _)).
set_model_name(ModelName) :-
......@@ -159,11 +160,14 @@ not_fresh :-
retractall(fresh).
add_item(Kind, Item) :-
:- dynamic(item/5).
add_item(Kind, Key, Item) :-
single_model(Model),
not_fresh,
create_item_id(Id),
assertz(item(Id, Model, Kind, Item)).
assertz(item(Id, Model, Kind, Key, Item)).
single_model(Model) :-
......@@ -185,11 +189,13 @@ single_model(Model, ModelId) :-
).
item(Options, Item) :-
item(Options) :-
optional(models: Models, Options),
optional(model: Model, Options),
optional(kind: Kind, Options),
optional(id: Id, Options),
optional(key: Key, Options),
optional(item: Item, Options),
(
var(Model)
->
......@@ -216,9 +222,16 @@ item(Options, Item) :-
;
single_model(Model, ModelId)
),
item(Id, ModelId, Kind, Item).
item(Id, ModelId, Kind, Key, Item).
all_items(Options, Items) :-
findall(
Item,
item([item: Item | Options]),
Items
).
optional(Item, List) :-
(
memberchk(Item, List)
......@@ -232,7 +245,7 @@ optional(Item, List) :-
list_items(Options) :-
set_counter(list_item_counter, 0),
\+ (
item(Options, Item),
item([item: Item | Options]),
count(list_item_counter, Counter),
\+ (
format('[~d] ~w\n', [Counter, Item])
......@@ -241,7 +254,7 @@ list_items(Options) :-
delete_item(Id) :-
retract(item(Id, _Model, _Kind, _Item)).
retract(item(Id, _Model, _Kind, _Key, _Item)).
create_item_id(Id) :-
......
......@@ -20,7 +20,7 @@ list_ODE :-
compute_ode :-
retractall(ode(_, _)),
\+ (
item([model: current_model, kind: rule], Item),
item([model: current_model, kind: rule, item: Item]),
rule(Item, Kinetics, Reactants, Products),
\+ (
kinetics(Kinetics, Reactants, KineticsExpression),
......
......@@ -12,7 +12,7 @@ add_rule(Rule) :-
type(Rule, reaction),
doc('adds reaction rules to the current set of rules.'),
simplify_rule(Rule, SimplifiedRule),
add_item(rule, SimplifiedRule).
add_item(rule, SimplifiedRule, SimplifiedRule).
list_rules :-
biocham_command,
......@@ -29,6 +29,14 @@ rule(Item, Kinetics, Reactants, Products, Reversible) :-
Body = Item
),
(
Body = (Left =[ Catalyst ]=> Right)
->
Reversible = no
;
Body = (Left <=[ Catalyst ]=> Right)
->
Reversible = yes
;
Body = (Left => Right)
->
Reversible = no,
......@@ -38,14 +46,6 @@ rule(Item, Kinetics, Reactants, Products, Reversible) :-
->
Reversible = yes,
Catalyst = '_'
;
Body = (Left =[ Catalyst ]=> Right)
->
Reversible = no
;
Body = (Left <=[ Catalyst ]=> Right)
->
Reversible = yes
),
solution_to_list(Left, LeftMolecules),
solution_to_list(Right, RightMolecules),
......@@ -103,16 +103,16 @@ solution_to_list(Object, [1 * Object]).
list_to_solution([], '_').
list_to_solution([Head | Tail], Solution) :-
list_to_solution(List, Solution) :-
reverse(List, [Head | Tail]),
list_to_solution(Tail, Head, Solution).
list_to_solution([], CoefficientObject, Object) :-
coefficient_object(CoefficientObject, Object).
list_to_solution([Head | Tail], CoefficientObject, Solution) :-
coefficient_object(CoefficientObject, Object),
Solution = Object + SolutionTail,
Solution = SolutionTail + Object,
list_to_solution(Tail, Head, SolutionTail).
......@@ -164,7 +164,7 @@ simplify_solution([Coefficient * Object | Tail], SimplifiedSolution) :-
simplify_solution(Others, SimplifiedCoefficient)
;
SimplifiedSolution = [SimplifiedCoefficient * Object | SimplifiedTail],
simplify_solution(Tail, SimplifiedTail)
simplify_solution(Others, SimplifiedTail)
).
......@@ -180,14 +180,18 @@ collect_object([CoefficientObject | Tail], Object, Sum, Others) :-
collect_object(Tail, Object, Sum, OthersTail).
simplify_catalyst([], Right, [], [], Right) :-
simplify_catalyst([], Right, [], [], Right).
simplify_catalyst([Head | Tail], Right, NewLeft, Catalyst, NewRight) :-
(
select(Head, Right, OthersRight)
->
Catalyst = [Head | CatalystTail],
simplify_catalyst(Tail, Right, NewLeft, CatalystTail, NewRight)
simplify_catalyst(Tail, OthersRight, NewLeft, CatalystTail, NewRight)
;
NewLeft = [Head | LeftTail],
simplify_catalyst(Tail, Right, LeftTail, Catalyst, NewRight)
).
build_rule(Kinetics, Left, Catalyst, Right, Reversible, Rule) :-
......
......@@ -77,6 +77,10 @@ simplify(sin(A), Result) :-
simplify(A, Asimplified),
simplify_sin(Asimplified, Result).
simplify('MA'(E), 'MA'(Simplified)) :-
!,
simplify(E, Simplified).
simplify(E, _Result) :-
type_error(arithmetic_expression, E).
......
- biocham.pl
- biocham.plt
- about.pl
- commandline.pl
- util.pl
......@@ -22,6 +23,7 @@
** Listing and editing rules and events
*** Rules
- rules.pl
- rules.plt
- kinetics.pl
- ode.pl
** Listing and defining initial states, molecules and locations
......
......@@ -2,7 +2,8 @@
util,
[
name_variables_and_anonymous/2,
camel_case/2
camel_case/2,
equals_to_list/2
]).
%! name_variables(?List:list) is det.
......@@ -52,3 +53,19 @@ camel_case_chars_tail(['_' | Chars], CamelChars) :-
camel_case_chars_tail([Head | Chars], [Head | CamelChars]) :-
camel_case_chars_tail(Chars, CamelChars).
equals_to_list(A = B, List) :-
!,
equals_to_list(A, LA),
equals_to_list(B, LB),
append(LA, LB, List).
equals_to_list([A], A).
list_to_equals([A], A) :-
!.
list_to_equals([Head | Tail], Head = EqTail) :-
list_to_equals(Tail, EqTail).
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