influence_editor.pl 2.89 KB
Newer Older
Thierry Martinez's avatar
Thierry Martinez committed
1 2 3 4 5 6 7 8 9
:- module(
  influence_editor,
  [
    % Commands
    add_influence/1,
    list_influences/0,
    % Public API
    is_influence_model/0,
    check_influence_model/0,
10
    list_model_influences/0,
Thierry Martinez's avatar
Thierry Martinez committed
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
    influence/5
  ]
).


:- devdoc('\\section{Commands}').


add_influence(Influence) :-
  biocham_command,
  type(Influence, influence),
  doc('
    adds influence rules to the current set of influences.
    This command is implicit: influence rules can be added directly in
    influence models.
  '),
  check_influence_model,
  add_item([kind: influence, item: Influence]).


%simplify_all_reactions :-
%  biocham_command,
%  doc('
%    replaces each reaction by a simplified form, by grouping common molecules,
%    identifying catalysts, and by using the canonical molecule for aliases.
%  '),
%  \+ (
%    item([kind: reaction, id: Id, item: Reaction]),
%    \+ (
%      delete_item(Id),
%      simplify_reaction(Reaction, SimplifiedReaction),
%      add_item([kind: reaction, item: SimplifiedReaction])
%    )
%  ).


list_influences :-
  biocham_command,
  doc('lists the current set of influence rules.'),
  check_influence_model,
  list_items([kind: influence]).


:- devdoc('\\section{Public API}').


is_influence_model :-
   devdoc('
     succeeds if the current model is an influence model
     (i.e., does not contain any reaction rules).
   '),
   \+ item([kind: reaction]).


check_influence_model :-
  (
    is_influence_model
  ->
    true
  ;
    throw(error(not_an_influence_model, check_influence_model))
  ).


75 76 77 78 79 80 81 82 83 84 85 86 87
list_model_influences :-
  devdoc('
    lists all the influence rules in a loadable syntax
    (auxiliary predicate of list_model).
  '),
  \+ (
    item([no_inheritance, kind: influence, item: Influence]),
    \+ (
      format('~w.\n', [Influence])
    )
  ).


Thierry Martinez's avatar
Thierry Martinez committed
88 89 90 91 92
prolog:error_message(not_an_influence_model) -->
  ['Not an influence model'].


influence(InfluenceRule, PositiveInputs, NegativeInputs, Sign, Output) :-
Thierry Martinez's avatar
Typo  
Thierry Martinez committed
93
  devdoc('builds or decomposes an influence rule.'
Thierry Martinez's avatar
Thierry Martinez committed
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
),
  once((
    InfluenceRule = (Inputs -> Output),
    Sign = +
  ;
    InfluenceRule = (Inputs -< Output),
    Sign = -
  )),
  inputs(Inputs, PositiveInputs, NegativeInputs).


:- devdoc('\\section{Private predicates}').


inputs(PositiveInputEnum, PositiveInputList, []) :-
  (
    var(PositiveInputEnum)
  ->
    true
  ;
    PositiveInputEnum \= (_ \ _),
    PositiveInputEnum \= (\ _)
  ),
  list_enumeration(PositiveInputList, PositiveInputEnum),
  !.

inputs(\ NegativeInputEnum, [], NegativeInputList) :-
  list_enumeration(NegativeInputList, NegativeInputEnum),
  !.

inputs(
  PositiveInputEnum \ NegativeInputEnum,
  PositiveInputList,
  NegativeInputList
) :-
  list_enumeration(PositiveInputList, PositiveInputEnum),
  list_enumeration(NegativeInputList, NegativeInputEnum),
  !.


list_enumeration([], '_') :-
  !.

list_enumeration([H], H) :-
  H \= (_, _),
  !.

list_enumeration([H | List], (H, Enum)) :-
  list_enumeration(List, Enum).