Commit 79f3db54 authored by dcoudrin's avatar dcoudrin
Browse files

Merge branch 'develop' of...

Merge branch 'develop' of https://scm.gforge.inria.fr/authscm/dcoudrin/git/biocham/biocham into develop
parents f304e1b8 cf6e0676
......@@ -107,7 +107,8 @@ export_lemon_stream(Id, Stream) :-
Conserv,
(
invariants:base_mol(List),
atomic_list_concat(List, ',', Conserv)
maplist(no_coeff, List, LList),
atomic_list_concat(LList, ',', Conserv)
),
ConservList
),
......@@ -158,6 +159,15 @@ sign('+', 1).
sign('-', -1).
%! no_coeff(+Coeff, -NoCoeff) is det.
%
% from a species with or without stoichiometry Coeff, remove the optional
% coefficient to get the species without stoichiometry NoCoeff
no_coeff(_*V, V) :-
!.
no_coeff(X, X).
%! normalize_reaction(+Item, -NormalizedStoichiometry, -Negated) is det.
%
% compute a sorted stoichiometry list for the reaction Item as
......
......@@ -35,6 +35,10 @@
parameter_getValue/2,
rule_getVariable/2,
rule_getMath/2,
function_getName/2,
function_getBody/2,
function_getNumArguments/2,
function_getArgument/3,
is_assignment/1,
compartment_getId/2,
compartment_getVolume/2
......
......@@ -67,6 +67,11 @@ PL_get_rule(term_t rule_term, Rule_t **rule) {
return PL_get_pointer(rule_term, (void **) rule);
}
int
PL_get_function(term_t function_term, FunctionDefinition_t **function) {
return PL_get_pointer(function_term, (void **) function);
}
int
PL_unify_sbmlDocument_or_free(term_t document_term, SBMLDocument_t *document) {
int result = PL_unify_pointer(document_term, document);
......@@ -176,6 +181,16 @@ pl_model_getListOfRules(term_t model_term, term_t listOfRules_term) {
PL_succeed;
}
static foreign_t
pl_model_getListOfFunctions(term_t model_term, term_t listOfFunctions_term) {
Model_t *model;
ListOf_t *listOfFunctions;
PL_check(PL_get_model(model_term, &model));
PL_check(listOfFunctions = Model_getListOfFunctionDefinitions(model));
PL_check(PL_unify_pointer(listOfFunctions_term, listOfFunctions));
PL_succeed;
}
static foreign_t
pl_model_getSpeciesById(
term_t model_term, term_t id_term, term_t species_term
......@@ -482,6 +497,48 @@ pl_rule_getMath(term_t rule_term, term_t formula_term) {
PL_succeed;
}
static foreign_t
pl_function_getName(term_t function_term, term_t formula_term) {
FunctionDefinition_t *function;
const char *name;
PL_check(PL_get_function(function_term, &function));
PL_check(name = FunctionDefinition_getId(function));
PL_check(PL_unify_atom_chars(formula_term, name));
PL_succeed;
}
static foreign_t
pl_function_getBody(term_t function_term, term_t formula_term) {
FunctionDefinition_t *function;
const char *formula;
PL_check(PL_get_function(function_term, &function));
PL_check(formula = SBML_formulaToString(FunctionDefinition_getBody(function)));
PL_check(PL_unify_atom_chars(formula_term, formula));
PL_succeed;
}
static foreign_t
pl_function_getNumArguments(term_t function_term, term_t num_term) {
FunctionDefinition_t *function;
unsigned int n;
PL_check(PL_get_function(function_term, &function));
PL_check(n = FunctionDefinition_getNumArguments(function));
PL_check(PL_unify_integer(num_term, n));
PL_succeed;
}
static foreign_t
pl_function_getArgument(term_t function_term, term_t num_term, term_t arg_term) {
FunctionDefinition_t *function;
const char *argument;
int num;
PL_check(PL_get_function(function_term, &function));
PL_check(PL_get_integer(num_term, &num));
PL_check(argument = SBML_formulaToString(FunctionDefinition_getArgument(function, num)));
PL_check(PL_unify_atom_chars(arg_term, argument));
PL_succeed;
}
static foreign_t
pl_is_assignment(term_t rule_term) {
Rule_t *rule;
......@@ -521,6 +578,7 @@ PL_extension sbml_predicates[] = {
{ "model_getListOfCompartments", 2, (pl_function_t) pl_model_getListOfCompartments, 0 },
{ "model_getListOfParameters", 2, (pl_function_t) pl_model_getListOfParameters, 0 },
{ "model_getListOfRules", 2, (pl_function_t) pl_model_getListOfRules, 0 },
{ "model_getListOfFunctions", 2, (pl_function_t) pl_model_getListOfFunctions, 0 },
{ "model_getSpeciesById", 3, (pl_function_t) pl_model_getSpeciesById, 0 },
{ "listOf_get", 3, (pl_function_t) pl_listOf_get, 0 },
{ "listOf_size", 2, (pl_function_t) pl_listOf_size, 0 },
......@@ -550,6 +608,10 @@ PL_extension sbml_predicates[] = {
{ "parameter_getValue", 2, (pl_function_t) pl_parameter_getValue, 0 },
{ "rule_getVariable", 2, (pl_function_t) pl_rule_getVariable, 0 },
{ "rule_getMath", 2, (pl_function_t) pl_rule_getMath, 0 },
{ "function_getName", 2, (pl_function_t) pl_function_getName, 0 },
{ "function_getBody", 2, (pl_function_t) pl_function_getBody, 0 },
{ "function_getNumArguments", 2, (pl_function_t) pl_function_getNumArguments, 0 },
{ "function_getArgument", 3, (pl_function_t) pl_function_getArgument, 0 },
{ "compartment_getId", 2, (pl_function_t) pl_compartment_getId, 0 },
{ "compartment_getVolume", 2, (pl_function_t) pl_compartment_getVolume, 0 },
{ "is_assignment", 1, (pl_function_t) pl_is_assignment, 0 },
......
......@@ -5,6 +5,7 @@
model_reaction/2,
model_species/2,
model_assignment_rule/2,
model_function/2,
reaction_reactant/2,
reaction_modifier/2,
reaction_product/2,
......@@ -14,6 +15,7 @@
species_has_only_substance_units/1,
parameter_id_and_value/3,
rule_var_and_math/3,
function_name_args_body/4,
model_compartment/2,
model_parameter/2,
compartment_volume/3,
......@@ -55,6 +57,11 @@ model_assignment_rule(Model, Rule) :-
is_assignment(Rule).
model_function(Model, Function) :-
model_getListOfFunctions(Model, ListOfFunctions),
member_listof(Function, ListOfFunctions).
reaction_reactant(Reaction, Reactant) :-
reaction_getListOfReactants(Reaction, ListOfReactants),
member_listof(Reactant, ListOfReactants).
......@@ -126,6 +133,21 @@ rule_var_and_math(Rule, Variable, Math) :-
sbml_atom_to_term(MathAtom, Math).
function_name_args_body(Function, Name, Args, Body) :-
function_getName(Function, Name),
function_getBody(Function, BodyAtom),
sbml_atom_to_term(BodyAtom, Body),
function_getNumArguments(Function, NumArgs),
findall(
Arg,
(
between(0, NumArgs, Index),
function_getArgument(Function, Index, Arg)
),
Args
).
sbml_atom_to_term(Atom, Term) :-
read_term_from_atom(Atom, STerm, [variable_names(Names)]),
name_variables_and_anonymous(STerm, Names),
......
......@@ -53,7 +53,6 @@
:- op(1010, fx, init). % comma is 1000
:- op(1010, fx, par).
:- op(1010, fx, p).
:- op(1010, fx, num).
:- op(1010, fx, func).
......@@ -909,6 +908,11 @@ remove_single_secondary_notations(String, Codes) :-
->
split_string(String, "=", "\s\t", L),
atomics_to_string(L, " = ", NewString)
;
sub_string(String, 0, 2, After, "p "),
sub_string(String, 2, After, 0, Rest)
->
atomics_to_string(['par ', Rest], NewString)
;
NewString = String
),
......
......@@ -16,7 +16,9 @@ test('ode_system', [ODEs == [d(b)/dt = a, d(a)/dt = -a]]) :-
test(
'import_ode',
[true(ODEs == [init(a = 0), init(b = 0), d(a)/dt = -a, par(k = -2), d(b)/dt = k*a])]
[true(
ODEs == [init(a = 0), init(b = 0), d(a)/dt = -a, par(k = -2),
par(kk = 1.0), d(b)/dt = k*a])]
) :-
setup_call_cleanup(
open('test.ode', write, TestOde),
......@@ -27,6 +29,7 @@ B(0) = 0
wiener q
da/dt = -a
par k =-2
p kk = 1.0
B''= k*a
@ meth=cvode
done
......
......@@ -74,10 +74,11 @@ add_sbml_document(SBML) :-
add_sbml_model(Model) :-
add_compartments(Model),
add_species(Model),
add_reactions(Model),
add_global_parameters(Model),
add_assignment_rules(Model).
add_assignment_rules(Model),
add_function_definitions(Model),
add_species(Model),
add_reactions(Model).
:- dynamic(has_only_substance_units/1).
......@@ -167,6 +168,17 @@ add_assignment_rules(Model) :-
).
add_function_definitions(Model) :-
forall(
model_function(Model, Function),
(
function_name_args_body(Function, Name, Args, Body),
Func =.. [Name | Args],
function([Func = Body])
)
).
global_local_parameters([], _Rid, Kinetics, Kinetics).
global_local_parameters([Parameter | LocalParameters], Rid, LKinetics, GKinetics) :-
......
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