Commit 7c7bcb73 authored by HEMERY Mathieu's avatar HEMERY Mathieu
Browse files

Try to sanitize the hybrid conversion against {} in species, WIP!

parent c039942d
......@@ -131,9 +131,9 @@ hybrid_static_simulation(ODEFilename, StochFilename, OutFilename, Volume, Time)
member(Present_pre, SortedODESpecies)
->
(
atom_concat(Present_pre, '_stoch', Present),
species_to_stoch(Present_pre, Present),
Init_value = 0,
atom_concat(Present_pre, '_total', Hybrid_species),
species_to_total(Present_pre, Hybrid_species),
write(Stream, 'function('),
write(Stream, Hybrid_species),
write(Stream,' = floor('),
......@@ -149,9 +149,9 @@ hybrid_static_simulation(ODEFilename, StochFilename, OutFilename, Volume, Time)
)
;
(
atom_concat(Present_pre, '_stoch', Present),
species_to_stoch(Present_pre, Present),
Init_value = Init_value_pre,
atom_concat(Present_pre, '_total', Hybrid_species),
species_to_total(Present_pre, Hybrid_species),
write(Stream, 'function('),
write(Stream, Hybrid_species),
write(Stream,' = '),
......@@ -183,7 +183,7 @@ hybrid_static_simulation(ODEFilename, StochFilename, OutFilename, Volume, Time)
reaction(Reaction, [kinetics: _,reactants: Reactants,inhibitors: _, products: _]),
member(Reactant,Reactants),
Reactant = _*R2_pre,
atom_concat(R2_pre, '_stoch', R2)
species_to_stoch(R2_pre, R2)
),
Reactants2),
......@@ -219,7 +219,7 @@ hybrid_static_simulation(ODEFilename, StochFilename, OutFilename, Volume, Time)
reaction(Reaction, [kinetics: _,reactants: _,inhibitors: _, products: Products]),
member(Product,Products),
Product = _*P2_pre,
atom_concat(P2_pre, '_stoch', P2)
species_to_stoch(P2_pre, P2)
),
Products2),
append(Reactants2, Products2, StochSpecies),
......@@ -246,14 +246,14 @@ hybrid_static_simulation(ODEFilename, StochFilename, OutFilename, Volume, Time)
(
member(R, Reactants),
R = Minus_number * Rname,
atom_concat(Rname, '_stoch', Species1)
species_to_stoch(Rname, Species1)
),
RSpecies),
findall([Species2, Add_number],
(
member(P, Products),
P = Add_number * Pname,
atom_concat(Pname, '_stoch', Species2)
species_to_stoch(Pname, Species2)
),
PSpecies),
%== Build list (Species_change) to record species change ==%
......@@ -306,6 +306,21 @@ hybrid_static_simulation(ODEFilename, StochFilename, OutFilename, Volume, Time)
%================== END of Preprocessor ====================%
%===========================================================%
%! species_to_stoch(+Species, -Species_stoch)
%
% write the stochastic name of a species, include quote to sanitize some model names.
species_to_stoch(Species, Species_stoch) :-
atomic_list_concat(['\'', Species, '_stoch\''], Species_stoch).
%! species_to_total(+Species, -Species_total)
%
% write the total name of a species, include quote to sanitize some model names.
species_to_total(Species, Species_total) :-
atomic_list_concat(['\'', Species, '_total\''], Species_total).
% The 'Current_counter' here is used for indexing reactions.
build_constraints_by_rules(Reactants_by_rules, ODEReactants, Current_counter, Orig_list, Results_list) :-
length(Reactants_by_rules, Number_of_rules),
......@@ -325,7 +340,8 @@ build_constraints_by_rules(Reactants_by_rules, ODEReactants, Current_counter, Or
)
->
(
atom_concat(Reactant_name, '_total >= ', Temp),
species_to_total(Reactant_name, Reactant_total),
atom_concat(Reactant_total, ' >= ', Temp),
Reactants_pair = Least_number * Reactant_name,
atom_number(Least_number_atom,Least_number),
atom_concat(Temp, Least_number_atom, Constraints)
......@@ -381,9 +397,9 @@ build_reactants(StochSpecies, ODESpecies, Species_number, Counter, Init, StochRe
(
member(This_species, ODESpecies)
->
atom_concat(This_species, '_total', This_reactant)
species_to_total(This_species, This_reactant)
;
atom_concat(This_species, '_stoch', This_reactant)
species_to_stoch(This_species, This_reactant)
),
append(Init, [This_reactant], Next),
(
......@@ -475,8 +491,9 @@ convert_into_hybrid(Molecule,Hybrid_originals,HybridMolecule) :-
get_option(stochastic_conversion, Rate),
nb_getval(volume,Volume),
member(Molecule,Hybrid_originals),
atom_concat('(',Molecule,Molecule1),
atom_concat(Molecule1,'_total/(',Molecule2),
species_to_total(Molecule, Molecule_total),
atom_concat('(',Molecule_total,Molecule1),
atom_concat(Molecule1,'/(',Molecule2),
atom_concat(Molecule2,Rate,Molecule3),
atom_concat(Molecule3,'*',Molecule4),
atom_concat(Molecule4,Volume,Molecule5),
......@@ -527,15 +544,16 @@ convert_into_hybrid2(Number,_,Number) :-
convert_into_hybrid2(Molecule,ODESpecies,StochMolecule) :-
\+(member(Molecule,ODESpecies)),
atom_concat(Molecule,'_stoch',StochMolecule),
species_to_stoch(Molecule,StochMolecule),
!.
convert_into_hybrid2(Molecule,Hybrid_originals,HybridMolecule) :-
get_option(stochastic_conversion, Rate),
nb_getval(volume,Volume),
member(Molecule,Hybrid_originals),
atom_concat('(',Molecule,Molecule1),
atom_concat(Molecule1,'_total/(',Molecule2),
species_to_total(Molecule, Molecule_total),
atom_concat('(',Molecule_total,Molecule1),
atom_concat(Molecule1,'/(',Molecule2),
atom_concat(Molecule2,Rate,Molecule3),
atom_concat(Molecule3,'*',Molecule4),
atom_concat(Molecule4,Volume,Molecule5),
......@@ -1116,7 +1134,7 @@ concat_species(Species, Count, Init, Results) :-
Count =< L
->
nth1(Count, Species, Species1),
atom_concat(Species1,'_total',Species1_processed),
species_to_total(Species1,Species1_processed),
atom_concat(', ', Species1_processed, Species2_processed),
atom_concat(Init, Species2_processed, NewSubstring),
Next_count is Count + 1,
......@@ -1128,7 +1146,7 @@ concat_species(Species, Count, Init, Results) :-
concat_species2(Species, Init, Results) :-
nth1(1, Species, First),
atom_concat(First,'_total',First1),
species_to_total(First,First1),
atom_concat(Init, First1, Newsubstring),
concat_species(Species, 2, Newsubstring, Results).
......@@ -1153,6 +1171,7 @@ print_show_option(Hybrid_originals,Stream) :-
%! hybrid_dynamic_simulation(+InputFile, +PropTresh, +PartTresh)
%
% Fast front-end for the hybrid_dynamic_simulation/5 predicate
% Typical value are PropTresh = 20, PartTresh = 20
hybrid_dynamic_simulation(InputFile,PropTresh,PartTresh) :-
biocham_command,
......@@ -1223,9 +1242,9 @@ hybrid_dynamic_simulation(InputFile,OutFilename,Volume,Time,PropTresh,PartTresh)
member(Present_pre, SortedSpecies)
->
(
atom_concat(Present_pre, '_stoch', Present),
species_to_stoch(Present_pre, Present),
Init_value = 0,
atom_concat(Present_pre, '_total', Hybrid_species),
species_to_total(Present_pre, Hybrid_species),
write(Stream, 'function('),
write(Stream, Hybrid_species),
write(Stream,' = floor('),
......@@ -1241,7 +1260,7 @@ hybrid_dynamic_simulation(InputFile,OutFilename,Volume,Time,PropTresh,PartTresh)
)
;
(
atom_concat(Present_pre, '_stoch', Present),
species_to_stoch(Present_pre, Present),
Init_value = Init_value_pre
)
),
......@@ -1269,7 +1288,7 @@ hybrid_dynamic_simulation(InputFile,OutFilename,Volume,Time,PropTresh,PartTresh)
findall(StochSpecie,
(
member(Species,SortedSpecies),
atom_concat(Species,'_stoch',StochSpecie)
species_to_stoch(Species,StochSpecie)
),
SortedStochSpecies),
%format("SortedStochSpecies is ~w ~n",[SortedStochSpecies]),
......@@ -1324,7 +1343,7 @@ hybrid_dynamic_simulation(InputFile,OutFilename,Volume,Time,PropTresh,PartTresh)
(
member(R, Reactants),
R = _ * Rname,
atom_concat(Rname,'_total',Rname1)
species_to_total(Rname, Rname1)
),
RSpecies)
),
......
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