BooN’s Documentation
The BooN project provides a complete set of functionalities for Boolean Network (BooN) analysis. It was originally designed to explore the modeling of genetic networks by Boolean networks. The project includes:
the definition of a Boolean network with the possibility to load and save it;
the computation of the model of dynamics with respect to a mode policy;
the definition of the interaction graph including a modular decomposition of the interaction;
the computation of equilibria based on dynamics model;
the efficient symbolic computation of stable states based on SAT solver;
the controllability analysis predicting which variables must be frozen to reach the expected goal at stable states based on possibility and necessity query;
also different basic functionalities are included as: update formula and importing/exporting to a text or SBML file the Boolean network.
BooN Modules Description
The BooN project comprises 3 modules:
boonmodule is related to the manipulation of Boolean network named BooN which is an object.boon.logicsub module includes the basic functions on propositional formula, as well as more advanced features like fast CNF conversion for large formulas, CNF conversion using Tseitin’s method, and prime implicant calculation. These functions are used in the BooN modules.boonifymodule is the graphical interface manipulating BooN:computation of dynamical model for synchronous and asynchronous mode, the computation ot the stable states, and the controllability analysis. For exploring BooN interactively runboonify.py
BooN installation
Go in the directory of BooN and type:
pip install .or,
python -m pip install .
Function Description
Boon Module
This module contains functions used for the manipulation of Boolean network (BooN). BooN is the class of this module.
- class boon.BooN(descriptor=None, style={'type': 'infix', False: 'false', True: 'true', sympy.logic.boolalg.And: '∧', sympy.logic.boolalg.Equivalent: '⇔', sympy.logic.boolalg.Implies: '⇒', sympy.logic.boolalg.Not: '¬', sympy.logic.boolalg.Or: '∨', sympy.logic.boolalg.Xor: '⊻'}, pos: dict = {})[source]
Bases:
objectBoolean Network Class.
- Parameters:
descriptor – The descriptor of a Boolean Network {variable: formula, …} (Default: None).
style – The output style of formulas (Default: LOGICAL).
pos – Positions of the variable in the interaction graph drawing. If empty, the positions are generated during the drawing (Default: {}).
- Variables:
desc (Dict) – Boolean network descriptor {variable: formula, …}.
style (dict) – Output form of the BooN: LOGICAL, SYMPY, MATHEMATICA, JAVA, BOOLNET, …
pos (dict) – Positions of the nodes in the interaction graph.
Initialize the BooN object.
- cnf(variable: Symbol | None = None, simplify: bool = True, force: bool = True) BooN[source]
Convert the formulas of the Boolean network to CNF.Convert the formulas of the Boolean network to CNF.
- Parameters:
variable (Symbol) – The variable where the formula is to be converted in CNF (Default None). If variable is None, then all the formulas are converted to CNF.
simplify (bool) – Boolean flag determining whether the formula should be simplified (Default True).
force (bool) – Boolean flag forcing the complete simplification of the resulting CNF (Default True).
- Returns:
self
- Return type:
- control(frozenfalse: set | list | frozenset, frozentrue: set | list | frozenset) None[source]
Set control on the BooN. The controlled variables are divided in two classes: the variables frozen to false and the variables frozen to true. A variable can belong to both classes.
- Parameters:
frozenfalse (Iterable object (list, set, tuple)) – List, set or sequence of variables that should be frozen to false by control.
frozentrue (iterable object (list, set, tuple)) – List, set or sequence of variables that should be frozen to true by control.
- Returns:
self
- Return type:
- delete(variable) BooN[source]
Delete a variable in a BooN. The formulas must all be in DNF to properly delete the variable.
- Parameters:
variable (Symbol) – The variable to delete.
- Returns:
self
- Return type:
- desc: dict = {}
- destify(query, max_solutions: int = 9223372036854775807, trace: bool = False, solver=pulp.PULP_CBC_CMD)[source]
Compute the core which is the minimal set of controls under the inclusion to satisfy the query at stable state.
Destify is a neologism that refers to the deliberate and purposeful act of shaping destiny by influencing or directing the course of events or outcomes towards an expected goal.
- Parameters:
query (Sympy formula) – The query defining the expected destiny or goal as propositional formula.
max_solutions (int) – Maximal number of solutions (Default the largest integer = sys.maxsize)
trace (Bool) – Boolean flag determining whether the trace is activated (Default: False).
solver (Pulp function) – The PulpSolver used for solving the problem (Default: PULP_CBC_CMD).
- Returns:
The core of control
- Return type:
frozenset[Sympy symbol]
- dnf(variable: Symbol | None = None, simplify: bool = True, force: bool = True) BooN[source]
Convert formula(s) of the Boolean network to DNF.
- Parameters:
variable (Symbol) – The variable where the formula is to be converted in DNF (Default: None). If variable is None, then all the formulas are converted to DNF.
simplify (bool) – Boolean flag determining whether the formula should be simplified (Default: True).
force (bool) – Boolean flag forcing the complete simplification (Default: True).
- Returns:
modified BooN
- Return type:
- draw_IG(IG: nx.DiGraph | None = None, modular: bool = False, **kwargs) nx.DiGraph[source]
Draw the interaction graph.
- Parameters:
IG (networkx DiGraph) – The interaction graph or None. If None, the interaction graph is generated from BooN (Default: None).
modular (bool) – Boolean indicating whether the modular structure of interactions is displayed if True (Default: False)
kwargs (dict) – additional keyword arguments to pass to the interaction graph drawing
- Returns:
interaction graph
- Return type:
Networkx DiGraph
- draw_model(model: nx.DiGraph | None = None, mode: Callable = <function asynchronous>, color: list[str] = ['tomato', 'gold', 'yellowgreen', 'plum', 'mediumaquamarine', 'darkorange', 'darkkhaki', 'forestgreen', 'salmon', 'lightcoral', 'cornflowerblue', 'orange', 'paleviolet', 'coral', 'dodgerblue', 'yellowgreen', 'orangered', 'pink', 'blueviolet', 'crimson'], **kwargs) None[source]
Draw the graph representing the model of dynamics.
- Parameters:
model (Networkx DiGraph) – Input graph model of the BooN or None (Default: None). If it is None, the asynchronous model computed from the BooN.
mode (function) – Function characterizing the mode of the model (Default: asynchronous)
color (list) – List of colors for highlighting the equlibria (Default: COLOR)
kwargs (dict) – Extra parameters of nx.draw_networkx.
- Returns:
None
- Return type:
None
- equilibria(model: nx.DiGraph | None = None, mode: Callable = <function asynchronous>, trace: bool = False) list[list][source]
Calculate equilibria for the network based on the model of dynamics. The method examines an exponential number of states, and thus it is restricted to networks with a small number of variables (max. ~10).
- Parameters:
model (Networkx DiGraph) – Data model from which the equilibria are calculated (Default: None)
mode (function) – Updating mode function, used if the model is None (Default: asynchronous).
trace (bool) – Define whether the trace of execution is enabled (Default: False (disabled)).
- Returns:
Equilibria structure as a list of lists where each sublist is an attractor.
- Return type:
List[list]
- filter_necessary(query, core: frozenset, trace: bool = False) frozenset[source]
Filter necessary controls in the network such that the query is satisfied for all stable states. This method must be applied to a non-controlled network to correctly functioning.
This function filters controls from the given core based on the condition that they satisfy the query for all stable states of the controlled network.
- Parameters:
query (Sympy expression) – The Boolean query to be satisfied across all stable states of the controlled network.
core – A set of prime implicants (controls) that will be filtered.
trace (bool) – Determines whether to display progress information during filtering (Defaults: False).
- Returns:
A subset of the given core containing only the necessary controls.
- Return type:
frozenset
- classmethod from_ig(IG: nx.DiGraph) Boon[source]
Define the descriptor of a BooN from an interaction graph. The method is a class method.
- Parameters:
IG – Interaction graph.
- Returns:
BooN
- Return type:
- classmethod from_sbmlfile(filename: str) BooN[source]
Import the Boolean network from a sbml file. The method is a class method.
- Parameters:
filename (Str) – The name of the file, if the extension is freestates, then .sbml is added.
- Returns:
BooN
- Return type:
- classmethod from_textfile(filename: str, sep: str = '\n', assign: str = ',', ops: dict = {'type': 'normal form', False: '0', True: '1', sympy.logic.boolalg.And: '&', sympy.logic.boolalg.Not: '!', sympy.logic.boolalg.Or: '|'}, skipline: str = '(targets\\s*,\\s*factors)|(#.*)') BooN[source]
Import the Boolean network from a text file, the syntax of which depends on the ops’ descriptor. The formulas must be in normal form containing OR, AND, NOT operators only. The nodes are circularly mapped. The default format is the Bool Net format (see ops and assign defaults). The method is a class method.
- Parameters:
filename (Str) – The file name to import the Boolean network. If the file extension is freestates, then .bnet is added.
sep (str) – The separator between definitions (default BOONSEP constant)
assign (str) – the operator defining the formula for a variable, e.g., a = f(…) → assign is ‘=’ (Default: ‘,’).
ops (dict) – A dictionary stipulating how the operators And, Or, Not are syntactically written (Default: BOOLNET).
skipline (str (regexp)) – Regular expression describing which lines must be skipped and not analyzed.
- Returns:
BooN
- Return type:
- property interaction_graph: networkx.DiGraph
Build the interaction graph.
- Returns:
The interaction graph.
- Return type:
Networkx DiGraph
- classmethod load(filename: str) BooN[source]
Load the Boolean Network from a file. If the extension is freestates, then .boon is added. The method is a class method
- Parameters:
filename (Str) – The name of the file to load the network.
- Returns:
self
- Return type:
- model(mode: ~collections.abc.Callable = <function asynchronous>, self_loop: bool = False, trace: bool = False) networkx.DiGraph[source]
Compute the dynamical model of the BooN with respect to a mode.
- Parameters:
mode (function) – Determines the mode policy applied to the model (Default: asynchronous).
self_loop (Bool) – Determines whether the boon loops are included in the model (Default: False).
trace (bool) – Define whether the trace of the execution is enabled (Default: False (disabled)).
- Returns:
A Digraph representing the complete state-based dynamics.
- Return type:
Networkx Digraph
- necessary(query, trace: bool = False)[source]
Compute the necessary constraints. The computation may take time because the query is converted to CNF that may contain a lot of terms.
- Parameters:
query (Sympy formula) – A formula characterizing the query, objective or goal.
trace (bool) – Boolean flag determining whether the trace is activated (Default value = False).
- Returns:
CNF specifying the necessity.
- Return type:
Sympy formula
- pos: dict = {}
- possibly(query)[source]
Compute the possibility constraint.
- Parameters:
query (Sympy formula) – A formula characterizing the query, objective or goal.
- Returns:
A formula specifying the possibility.
- Return type:
Sympy formula
- classmethod random(n: int, p_link: float, p_pos: float = 0.5, topology: str = 'Erdos-Reny', min_clauses: int = 1, max_clauses: int = 5, prefix: str = 'x') BooN[source]
Generate a random BooN where the formulas are in DNF. The method is a class method.
- Parameters:
n (Int) – The number of variables.
p_link – Probability related to interaction between variables, the use depends on the topology class.
p_pos (Float) – The probability of defining a variable as a positive term (default 0.5).
topology (str) – The topology class of the interaction graph: ‘Erdos-Reny’, ‘Scale-Free’, ‘Small-World’ (default ‘Erdos-Reny’)
min_clauses (Int) – The minimum number of clauses required to define a formula (default 1).
max_clauses (Int) – The minimum number of clauses required to define a formula (default 5).
prefix (Str) – The prefix of the variable name, the variables are of the form <prefix> <int> (default ‘x’).
- Returns:
A random BooN
- Return type:
- rename(source: sympy.core.symbol.Symbol, target: sympy.core.symbol.Symbol) BooN[source]
Rename a variable.
- Parameters:
source (Symbol) – The variable to rename.
target (Symbol) – The variable renaming the source.
- save(filename: str = 'BooN11-juin-26-15.boon') None[source]
Save the Boolean Network to file. If the extension is freestates, then .boon is added.
- Parameters:
filename (str) – The name of the file to save the network (Default: BooN+date+hour.boon)
- Returns:
None
- Return type:
None
- property stable_states: list[dict]
Compute all the stable states of a BooN. The algorithm is based on SAT solver.
- Returns:
List of stable states.
- Return type:
List[dict]
- str(sep: str = '\n', assign: str = '=') str[source]
Return a string representing the BooN. The output format can be parameterized (see style argument of BooN)
- Parameters:
sep (str) – The separator between formulas (Default: BOONSEP constant).
assign (str) – The operator defining the assignment of a formula to a variable (e.g., a = f(…) → assign is ‘=’) (Default: ‘=’).
- style: dict = {}
- to_textfile(filename: str, sep: str = '\n', assign: str = ',', ops: dict = {'type': 'normal form', False: '0', True: '1', sympy.logic.boolalg.And: '&', sympy.logic.boolalg.Not: '!', sympy.logic.boolalg.Or: '|'}, header: str = '# BooN saved on 11-06-2026\ntargets, factors') BooN[source]
Export the Boolean network in a text file. If the file extension is freestates, then .txt is added. The default format is BOOLNET.
- Parameters:
filename (Str) – The file name to export the Boolean network.
sep (str) – The separator between formulas (Default: BOONSEP constant).
assign (str) – The operator defining the formula for a variable, e.g., a = f(…) → assign is ‘=’ (Default: ‘,’ Boolnet Format).
ops (dict) – A dictionary stipulating how the operators And, Or, Not are syntactically written (Default: BOOLNET).
header (str) – Header text inserted at the beginning of the saved file.
- Returns:
self
- Return type:
- property variables: set
Return the set of variables. (property)
- Returns:
Variables
- Return type:
set[Symbol]
- boon.asynchronous(variables: list | set) frozenset[source]
Asynchronous or sequential mode. One variable is updated per transition.
- Parameters:
variables (List or set) – List of variables.
- Returns:
Sets: {{x1},…,{xi},…,{xn}} representing the asynchronous mode.
- Return type:
frozenset[frozenset[Symbol]]
- boon.controls2actions(controls: frozenset) list[tuple][source]
Convert a set of controls into a list of actions where an action is a pair (symbol, boolean value).
- Parameters:
controls (frozenset[Sympy symbols]) – The set of control parameters.
- Returns:
A list of actions.
- Return type:
list[tuple[Sympy symbol, bool]]
- boon.core2actions(core: frozenset) list[source]
Convert the core to a list of actions where an action is a list of (variable, Boolean). The actions are sorted by length, meaning that the more parsimonious actions are at first.
- Parameters:
core (Frozenset[Frozenset[Sympy symbol]].) – The core.
- Returns:
A list of combined actions where an action is defined as:[(variable, bool) …]
- Return type:
List[list[tuple]]
- boon.hypercube_layout(arg: int | nx.Digraph) dict[source]
Compute the hypercube layout of a graph.
- Parameters:
arg (Int or networkx Digraph) – The dimension of the hypercube or the network to which the layout is applied.
- Returns:
A dictionary {int:position} where int is the integer code of the hypercube labels.
- Return type:
Dict
- boon.int2state(int_state: int, variables: list | set) dict[source]
Convert an integer state to a dictionary state.
- Parameters:
int_state (Int) – The state coded into integer.
variables (list or set) – List of variables.
- Returns:
A dictionary representing the state {variable: boolean state…}.
- Return type:
Dict
- boon.is_controlled(formula) bool[source]
Check whether a formula is controlled.
- Parameters:
formula (Sympy formula.) – The input formula.
- Returns:
True if the formula is controlled otherwise False.
- Return type:
bool
- boon.isctrl(lit) bool[source]
Determines if a literal contains a controller.
- Parameters:
lit (Literal) – The literal to be validated.
- Returns:
True if the literal is a negative control, False otherwise.
- Return type:
Bool
- boon.isnegctrl(lit) bool[source]
Determines if a given literal is a negative control.
- Parameters:
lit (Literal) – The literal to be validated.
- Returns:
True if the literal is a negative control, False otherwise.
- Return type:
Bool
- boon.state2int(state: dict | tuple, variables: set | list | None = None) int[source]
Convert a set of states to an integer the binary profile of which corresponds to the state of the variables.
- Parameters:
state (Dict or tuple) – State of the variables.
variables (list or set) – List of variables.
- Returns:
An integer such that its binary profile represents the state.
- Return type:
Int
- boon.synchronous(variables: list | set) frozenset[source]
Synchronous or parallel mode. All the variables are updated jointly per transition.
- Parameters:
variables (list or set) – list of variables.
- Returns:
Sets: {{x1,…,xi,…,xn}} representing the synchronous mode.
- Return type:
frozenset[frozenset[Symbol]]
Logic Module
This module includes functions on propositional formula.
- boon.logic.clause2literals(clause) set[source]
Convert a clause or a cube into of a sequence of literals.
- Parameters:
clause (Sympy formula) – The clause or cube.
- Returns:
Set of literals.
- Return type:
Set
- boon.logic.cnf2clauses(cnf)[source]
Decomposition of a CNF into a sequence of clauses.
- Parameters:
cnf (sympy formula) – CNF formula
- Returns:
Sequence of clauses.
- Return type:
Tuple[formula]
- boon.logic.errmsg(msg: str, arg='', kind: str = 'ERROR') None[source]
Display an error message and exit in case of error (kind = “ERROR”).
- Parameters:
msg (str) – The error message.
arg (str) – The argument of the error message (Default: “” no args).
kind (str) – Type of error (Default: ERROR). Only the “ERROR” option will exit the application.
- Returns:
None
- Return type:
None
- boon.logic.firstsymbol(formula)[source]
Extract the first symbol from the symbols of a dnf.
- Parameters:
formula (Sympy formula) – The input dnf.
- Returns:
The first symbol.
- boon.logic.newvar(initialize: int | None = None)[source]
Create a new sympy symbol of the form <prefix><number>. The prefix is given by TSEITIN constant.
- Parameters:
initialize (int|None) – Initialize the counter if the value is an integer or let the counter increment by 1 if it is set to None (Default value = None)
- Returns:
A Simpy symbol.
- Return type:
Symbol
- boon.logic.prettyform(formula, style: dict = {'type': 'infix', False: 'false', True: 'true', sympy.logic.boolalg.And: '∧', sympy.logic.boolalg.Equivalent: '⇔', sympy.logic.boolalg.Implies: '⇒', sympy.logic.boolalg.Not: '¬', sympy.logic.boolalg.Or: '∨', sympy.logic.boolalg.Xor: '⊻'}, depth=0)[source]
Return a string of a formula in nice form.
- Parameters:
formula (sympy formula) – The input formula.
style (dict) – The style of the logical operators (Default: LOGICAL).
depth (int) – The current depth of the formula for setting parentheses (Default: 0).
- boon.logic.prime_implicants(formula, kept: ~collections.abc.Callable = <function <lambda>>, max_solutions: int = 9223372036854775807, trace: bool = False, solver: type = pulp.PULP_CBC_CMD) frozenset[source]
Compute all the prime implicants of a propositional formula where the literals are filtered by kept function.
- Parameters:
formula (Sympy formula) – The input formula. The formula does not need to be in CNF.
kept (function) – Predicate selecting the literals that are kept in the solutions (Default: function discarding the Tseitin working variables).
max_solutions (int) – Maximal number of solutions (Default sys.maxsize).
trace (bool) – A Boolean flag determining whether the trace showing the resolution is activated (Default: False).
solver (solver function) – The solver to use (Default: Pulp solver).
- Returns:
All the prime implicants in the form of a set of sets where each subset represents one prime implicant filtered by kept.
- Return type:
frozenset
- boon.logic.supercnf(formula, trace: bool = False)[source]
Convert the formula to CNF. The method is well adapted to large formula.
- Parameters:
formula (sympy formula) – The formula to convert.
trace (bool) – Boolean flag if True trace the computational steps (Default value = False)
- Returns:
CNF formula
- Return type:
sympy formula
- boon.logic.sympy2z3(formula)[source]
Convert a sympy formula to z3 formula.
- Parameters:
formula (Sympy formula) – The formula to convert.
- Returns:
The equivalent z3 formula.
- Return type:
Z3 formula
Boonify Module
Graphical interface module.
- class boonify.Boonify[source]
Bases:
QMainWindowRepresents the main application window for managing and designing BooNs (Boolean Networks). Provides a GUI with a comprehensive set of functionalities. This class is primarily responsible for initializing and connecting GUI widgets, setting up callbacks, and constructing an editable graph for network interaction design.
- Variables:
boon – The current Boolean Network object being managed or displayed.
filename – The name of the file associated with the current BooN (empty if no file is loaded or saved).
history – Maintains a history list of BooN objects for undo/redo functionalities.
hindex – The index of the last BooN added to the history.
hupdate – Flag indicating whether the history should be updated.
saved – Flag indicating if the current BooN has been saved.
QView – Widget for displaying BooN visualization.
QStableStates – Widget for displaying stable states of BooNs.
QModel – Widget for displaying the dynamic model of the BooN.
QControllability – Widget for displaying BooN controllability analysis.
editgraph – Editable graphical representation of the BooN’s interaction graph.
disablecallback – Flag indicating whether design callbacks are disabled.
designsize – Scaling factor related to graphics elements in the EditableGraph.
worker – Background thread for processing long-running BooN operations.
canvas – Matplotlib canvas for rendering the network design figure in the GUI.
- add_color_history(boon_snapshot=None)[source]
Records a color-only change into both parallel history stacks. Called by set_edge_color_from_palette, set_family_color, and node-resize operations after updating edge_family_colors / node_sizes / node_label_top, when the BooN descriptor itself has not changed. A new slot is created only if something actually differs from the last recorded snapshot, so making the same change twice produces only one history entry.
- Returns:
None
- add_history()[source]
Records the current BooN and edge_family_colors into the parallel history stacks if the BooN descriptor has changed since the last recorded entry.
Both self.history (BooN snapshots) and self.color_history (edge_family_colors snapshots) are always advanced together so their indices stay in sync. .. warning:
BooN equality is based on descriptors only (see ``BooN.__eq__``). Color-only changes do NOT create a new entry here: use add_color_history() for those.
- Returns:
None
- closeEvent(event)[source]
Handles the close event for the application window. This method ensures that when the application’s close event is triggered, it invokes the quit method to handle quitting properly. The event.ignore() ensures that the close event is ignored unless the application is closed successfully prior to that, in which case event.ignore() will not execute.
- Parameters:
event (QCloseEvent) – The Qt close event triggered when the user closes the window.
- Returns:
None
- controllability()[source]
Opens the Controllability window, which computes control actions to drive the BooN toward a target marking profile. The instance is stored in self.QControllability so that refresh() can update it while it is open.
- Returns:
None
- display_saved_flag(val: bool = True)[source]
Displays a flag in the status bar indicating whether the data has been saved. A large empty circle (○) means the BooN is saved; a large filled circle (⬤) means it has unsaved changes. Also updates self.saved so that quit() can check the state consistently.
- Parameters:
val (bool) – True if the BooN is saved, False if it has unsaved changes. Defaults to True.
- Returns:
None
- exportation()[source]
Exports the current BooN to an external file format via a Save dialog. Supported formats are BoolNet (.bnet) and Python/SymPy (.txt). The export format is determined automatically from the chosen file extension.
- Raises:
ValueError – If the filename extension is unsupported or invalid.
- Returns:
None
- help()[source]
Provides functionality to call and display help using an external Help object.
- Returns:
None
- history_raz()[source]
Resets both BooN history and color history, then records the current state as the first entry. Called after loading or importing a file to start a fresh undo/redo stack from the new state. Resets
history,color_history,hindex, andhupdateto their initial values.- Returns:
None
- importation()[source]
Imports a BooN from an external file format and updates the application state. Supported formats are BoolNet (.bnet), Python/SymPy (.txt), and SBML (.sbml, .xml). After a successful import, self.filename is set to None because the BooN is not stored in the native .boon format. All open views are refreshed and the history is reset. An error dialog is shown if the file extension isn’t recognised.
- Returns:
None
- model()[source]
Opens the Dynamical Model window, which draws the state-transition graph of the current BooN. Refused if the number of variables exceeds MODELBOUND, since the state space grows as 2^n and the graph would be too large to render.
- Returns:
None
- on_graph_changed()[source]
Update the BooN model after a graph editor modification.
Converts the current graph representation into a BooN object, records the change in the history, and refreshes all open views.
- Returns:
None
- open()[source]
Opens a file using a file dialog, loads its contents, and updates the application state. Presents a file dialog filtered to .boon files. After a successful selection, loads the BooN, refreshes all open views, reinitializes the graph editor, and resets the undo/redo history.
- Returns:
None
- quit()[source]
Terminates the application, prompting the user to save if there are unsaved changes. If the BooN is already saved, the application exits immediately. Otherwise a dialog offers three choices: Save then quit, Quit without saving, or Cancel.
- Returns:
None
- redo()[source]
Restores the next BooN and edge family colors from the parallel history stacks. Moves the history cursor one step forward. Edge colors are restored before setup_design so the graph redraw immediately uses the correct color state. Stops at the most recent state and never wraps around.
- Returns:
None
- refresh()[source]
Refreshes all visible components, such as BooN View, Stable States View, Model View, and Controllability View. Each visible component is reinitialized or updated via its relevant function. This ensures that all active components reflect the most current state.
- Returns:
None
- save()[source]
Saves the current BooN to the existing file, or delegates to saveas() if no file is set. If self.filename is already defined, the BooN is saved in place and the saved-state indicator is updated. If no filename exists yet (e.g. new unsaved network), the Save As dialog is opened.
- Returns:
None
- saveas()[source]
Opens a Save As dialog and saves the current BooN to the chosen file. Updates self.filename with the selected path and refreshes the saved-state indicator. Does nothing if the dialog is cancelled.
- Returns:
None
- setup_callbacks()[source]
Connect internal application signals to their corresponding handlers. If the graph editor has already been created, connect its graph_changed signal to the synchronization callback.
- Returns:
None
- show_history()[source]
Displays the entire history of changes, showing each entry formatted according to its identifier and rendering logic using a tabulated structure. The current history index is highlighted, and associated data details are presented using a plain tabular format. If a history entry lacks data, it displays a placeholder.
- Returns:
None
- stablestates()[source]
Opens the Stable States window, which computes and displays the stable states of the current BooN. The instance is stored in self.QStableStates so that refresh() can update it while it is open.
- Returns:
None
- undo()[source]
Restores the previous BooN and edge family colors from the parallel history stacks. Moves the history cursor one step back. Edge colors are restored before setup_design so the graph redraw immediately uses the correct color state. Stops at the oldest recorded state (up to HSIZE-1 steps back) and never wraps around.
- Returns:
None
- class boonify.Controllability(parent=None)[source]
Bases:
QMainWindowControllability class for managing user interactions with the controllability widget of the GUI application. This class is responsible for initializing the controllability user interface, handling the interactions between destiny and observers tables, computing control actions based on user selections, and managing the graphical representation of these actions.
- Variables:
parent – Parent window instance for the controllability widget.
actions – Stores the calculated control actions, if any.
row – Index of the currently selected solution in control actions, if applicable.
- controllability()[source]
The method calculates control actions required to achieve or avoid a defined goal (or state) in a system represented by the BooN model. The method determines the applicable control actions by analyzing a user-specified query defining the desired or undesired state, along with the possible variables that can be controlled. This process involves interpreting various parameters such as observer states, query types, and logical modalities.
- Returns:
None
- destiny_to_observers(label: str)[source]
Updates the check state of an item in the Observers table based on the provided label and the currently selected row in the Destiny table.
- Parameters:
label (str) – If “None”, the item is unchecked; otherwise it is checked.
- Returns:
None
- display_controllability()[source]
Build the Qt tree model from self.actions and update ControlActions. Connected to Threader.finished so it always runs on the main thread.
- Returns:
None
- initialize_controllability()[source]
Initialize the controllability setup for the application.
- Returns:
None
- observers_to_destiny(chkitem)[source]
Synchronizes the Destiny table when an observer checkbox is unchecked. When a variable is unchecked in the Observers table, its corresponding entry in the Destiny table is reset to “None”.
- Parameters:
chkitem (QTableWidgetItem) – The table item whose check state changed.
- Returns:
None
- class boonify.Graph(*args: Any, **kwargs: Any)[source]
Bases:
QObjectInteractive graph editor managing the visual and logical representation of a BooN interaction graph on a Matplotlib canvas embedded in the PyQt5 GUI. Handles node/edge creation, deletion, renaming, selection, dragging, zooming, edge sign toggling, family color assignment, and self-loop rendering.
- Variables:
canvas – The Matplotlib canvas used for rendering the graph.
axes – The Matplotlib axes used for drawing.
graph – The directed graph storing nodes and edges.
node_positions – Dictionary mapping node IDs to (x, y) coordinates.
node_labels – Dictionary mapping node IDs to their display labels.
next_node_id – Counter for assigning unique integer IDs to new nodes.
edge_colors – Mapping from edge (u, v) to RGB display color.
edge_labels – Mapping from edge (u, v) to its display label.
edge_modules – Mapping from edge (u, v) to its BooN module set.
default_edge_sign – Default sign for newly created edges (+1 or -1).
selected_nodes – Set of currently selected node IDs.
selected_edge – Currently selected edge as (src, tgt), or None.
zoom_factor – Current zoom level multiplier.
edge_family_colors – Mapping from edge (u, v) to its family RGB color.
show_family_colors – Whether to render family color markers on edges.
graph_changed – Qt signal emitted whenever the graph topology changes.
NODE_SIZE_DEFAULT – Default (and minimum) node size in Matplotlib units.
NODE_SIZE_MAX – Maximum allowed node size.
NODE_SIZE_STEP – Size increment/decrement step.
node_sizes – Per-node size overrides; absent key falls back to NODE_SIZE_DEFAULT.
Initializes the Graph editor and attaches it to a Matplotlib canvas.
- Parameters:
canvas (FigureCanvas) – The Matplotlib FigureCanvas used for rendering.
- build_resize_palette()[source]
- Build the node-size adjustment UI inside the resize menu popup.
The panel contains:
A horizontal slider to set the size of the target node(s) continuously.
- A toggle switch (Selected / All) to apply the size to the selected node(s) or
uniformly to all nodes in the graph.
- A label-position icon button that switches the node name between Center and Top.
Switching to Top immediately resets all node sizes back to NODE_SIZE_DEFAULT so that the label offset is consistent across the graph.
- return:
None
- change_edge_sign(sign)[source]
Changes the sign and display color of the currently selected edge. Updates both the logical sign stored in the graph and the visual color mapping, then emits a graph update (graph_changed) signal after modification to notify the BooN model.
- Parameters:
sign (int) – New sign value for the edge(+1 for activation, -1 for inhibition).
- Raises:
QMessageBox.warning – If no edge is currently selected.
- Returns:
None
- delete_selection()[source]
Deletes the currently selected nodes or edge from the graph. Priority:
If nodes are selected, removes them and all their connected edges.
If only an edge is selected, removes that edge.
If nothing is selected, displays a warning dialog.
- Returns:
None
- next_default_label()[source]
Generates the next available default node label. Only labels matching the pattern “x<number>” are considered. Custom renamed nodes are ignored when computing the next index.
- Returns:
Next generated label (e.g., “x3”).
- Return type:
str
Example:
x1, x2 -> x3 tom, x2, x3 -> x4
- on_canvas_motion(event)[source]
Handles mouse motion events on the canvas. Priority order:
Edge preview: if an edge source is set, draws a dashed preview line.
Selection rectangle: if dragging on empty space, draws a dashed rectangle.
Node dragging: if nodes are selected and being dragged, updates their positions.
- Parameters:
event (matplotlib.backend_bases.MouseEvent) – The Matplotlib mouse event carrying position data.
- Returns:
None
- on_canvas_press(event)[source]
- Handles mouse button press events on the canvas. Dispatches to the appropriate action based on button and position.
Right-click on empty space while creating an edge: cancels edge creation.
Right-click on node: starts or completes edge creation (first click sets source, second click creates the edge).
Right-click on edge: toggles the edge sign and selects the edge.
Left-click on edge (no node nearby): selects the edge.
Left-click on node: selects the node for dragging (Shift adds to selection).
Left-double-click on node: selects the node and opens the rename dialog.
Left-click on empty space: begins a rubber-band selection rectangle or prepares a node creation on release.
- Parameters:
event (matplotlib.backend_bases.MouseEvent) – The Matplotlib mouse event carrying button, position, and modifier data.
- Returns:
None
- on_canvas_release(event)[source]
Handles mouse button release events on the canvas. On left-button release:
If nodes were being dragged, commits their new positions.
If a selection rectangle was drawn, selects all nodes within it.
If the release is a short click on empty space, creates a new node there.
Resets all drag and selection rectangle state after processing.
- Parameters:
event (matplotlib.backend_bases.MouseEvent) – The Matplotlib mouse event carrying button and position data.
- Returns:
None
- on_key_press(event)[source]
Handles keyboard press events on the canvas. Supported keys:
Delete: Deletes the currently selected node(s) or edge.
Escape: Cancels active edge creation and clears the edge preview.
- Parameters:
event (matplotlib.backend_bases.KeyEvent) – The Matplotlib key event.
- Returns:
None
- open_color_palette()[source]
Opens the edge family color palette menu at the current mouse cursor position. Rebuilds the palette UI before displaying so that the icon states (show/hide family colors) always reflect the current application state.
- Returns:
None
Opens the node-size adjustment panel at the current mouse cursor position. The panel can be opened even without a selection because the ‘All’ mode operates on every node. A warning is shown only when the panel is actually used in ‘Selected’ mode with no node chosen.
- Returns:
None
- pick_edge_color()[source]
Open a color picker to set the color of the selected edge. If no edge is selected, a warning is shown. Otherwise, the user selects a color which is applied to the edge.
- redraw_graph()[source]
Clears and fully reconstructs the graph canvas. Draws nodes, labels, edges, self-loops, family color markers, and applies the current zoom. If an edge preview is active when this is called (e.g. mid-drag), its endpoints are saved and the preview line is recreated after the redraw so it is not lost.
- Returns:
None
- refresh_next_node_id()[source]
Recomputes the next available integer node ID. Must be called after undo/redo or any external graph modification that may have changed which integer IDs are in use.
- Returns:
None
- reset_zoom()[source]
Reset the zoom level to the default value. Sets zoom factor back to 1.0 and redraws the graph.
- set_default_edge_sign(sign)[source]
Sets the default sign used for newly created edges.
- Parameters:
sign (int) – Edge sign (+1 for activation, -1 for inhibition).
- Returns:
None
- set_edge_color_from_palette(color_name)[source]
Set the color of the selected edge using a predefined palette color. Stores the RGB color in edge_family_colors, redraws, then records a color-only history snapshot via add_color_history so that each individual color assignment is independently undoable/redoable.
- set_family_color(color_value)[source]
Set a family color for the selected edge. Stores the RGB color in edge_family_colors, redraws, then records a color-only history snapshot via add_color_history so that each individual color assignment is independently undoable/redoable. Requires an edge to be selected.
- Initialize the edge color palette menu.
Defines available colors, sets initial visibility count, creates the QMenu container, and builds the initial palette UI.
- setup_design(boon)[source]
Builds the internal graph structure from a BooN model and prepares the canvas for rendering. Node IDs are assigned as integers in sorted symbol order. Node positions are taken from boon.pos if available, otherwise computed with a spring layout. Edge signs and colors are read from the interaction graph and stored for later rendering.
- Parameters:
boon (BooN) – The Boolean Network model to visualise.
SIGNCOLORis also stored as an instance attribute for use by the rendering methods.- Returns:
None
Initialize the node-size adjustment menu. Creates a QMenu container and builds the initial resize UI.
- show_less_colors()[source]
Decrease the number of visible colors in the palette. Reduces visible color count (minimum 5) and rebuilds the palette UI.
- show_more_colors()[source]
Increase the number of visible colors in the palette. Expands visible color count and rebuilds the palette UI.
- toggle_edge_sign(edge)[source]
Toggles the sign of an edge between activation (+1) and inhibition (-1). Updates both the logical sign stored in the graph and the display color, then emits graph_changed to notify the BooN model.
- Parameters:
edge (tuple) – Edge to toggle as a (src, tgt) tuple.
- Returns:
None
- toggle_family_colors()[source]
Toggles visibility of edge family color circles and redraws the graph. Enables or disables rendering of additional edge grouping markers and refreshes the graph display.
- Returns:
None
- class boonify.Help(parent=None)[source]
Bases:
QMainWindowDefines the Help class, a window in the application providing a user interface for displaying help documentation. This class inherits from QMainWindow and is used to load and display an HTML-based help file using QWebEngineView. It provides a ‘Close’ button to dismiss the window. The layout and UI components are loaded from a .ui file.
- Variables:
CloseButton – The button widget used to close the help window.
web – A web engine view widget used to render and display the help HTML content.
WebContainer – The container widget to hold the QWebEngineView displaying the help content.
- class boonify.Model(parent=None)[source]
Bases:
QMainWindowA Model class for managing and visualizing network dynamics using a GUI interface.
- Variables:
parent – Reference to the parent window or application.
mode – Represents the selected mode of dynamics (asynchronous or synchronous).
layout – Defines the network layout function to be used for visualization.
canvas – Matplotlib widget for rendering the network visualization.
Initializes the Model window, loads the UI layout, connects radio buttons and the layout combo box, and renders the initial dynamics model.
- Parameters:
parent (Boonify or None) – The parent Boonify instance providing BooN data.
- cb_network_layout()[source]
Adjusts the network layout based on the selected option and applies the corresponding layout algorithm to the network. The method retrieves the currently selected network layout from a user interface component, maps it to an appropriate algorithm, and configures the network’s visualization layout accordingly. It also invokes an update via the modeling method to apply and reflect the changes.
- Returns:
None
- rb_mode()[source]
Determine and set the mode of operation based on user selection from the interface. This function checks the state of radio buttons to assign either an asynchronous or synchronous mode. The established mode is then used for further modeling via a further call to the modeling method.
- Returns:
None
- class boonify.Network[source]
Bases:
objectConversion layer between Graph and BooN. Handles transformation between GUI graph representation and BooN model.
Initializes the Network conversion layer with an empty BooN model.
- boon_to_graph(boon, graph_editor)[source]
Converts a BooN logical model back into a GUI graph representation. This method rebuilds nodes, edges, positions, labels, and visual properties from the BooN interaction graph and updates the graph editor accordingly.
- Parameters:
boon – BooN model to convert.
graph_editor – Target GUI graph editor to populate.
- Returns:
None
- graph_to_boon(graph_editor, current_boon=None)[source]
Converts GUI graph into BooN using BooN.from_ig() (correct logical semantics).
Family color semantics (clause grouping): Edges that share the same family color AND point to the same target node belong to the SAME AND-clause (same module index). Edges with different family colors each form their own separate clause, joined by OR in the final DNF formula (alternative regulation).
White / BASIC_FAMILY_COLOR edges pointing to the same target all share the SAME clause index (cooperative regulation: all white edges are AND’d together into one clause). Only when non-white family colors are present does OR-separation (alternative regulation) apply.
- Module sign follows edge sign exactly (from_ig convention):
positive sign -> positive module index (+k) -> literal = src negative sign -> negative module index (-k) -> literal = Not(src)
Example:
x1->x2 pink sign+1 -> module +1 x3->x2 pink sign-1 -> module -1 (same clause 1, negated literal) x4->x2 yellow sign+1 -> module +2 (separate clause 2) => x2 = (x1 & ~x3) | x4
- class boonify.QAbstractItemView
Bases:
object
- class boonify.QDialogButtonBox
Bases:
object
- class boonify.QFrame
Bases:
object
- class boonify.QGroupBox
Bases:
object
- class boonify.QHeaderView
Bases:
object
- class boonify.QTableWidget
Bases:
object
- class boonify.StableStates(parent=None)[source]
Bases:
QDialogA dialog for displaying and managing stable states in a computational model. This class represents a graphical interface for visualizing stable states of a Boolean network model. It allows users to switch between different display styles, such as icons or textual representation, for better interpretation of the stable states.
- Variables:
parent – Reference to the parent widget or application component.
style – The display style for representing stable states (e.g., ‘Icon Boolean’).
datamodel – The data model used for organizing and displaying stable states.
- cb_styling()[source]
Updates the formula display style and refreshes the view. This method changes how formulas are rendered (logical, Python, etc.) based on user selection.
- Returns:
None
- stablestates()[source]
Generates and sets up a data model to visualize stable states of a system. This method processes the stable states of a parent object’s model and organizes them into a table-like structure using a Qt QStandardItemModel. Each row represents a variable, and each column corresponds to a stable state. The presentation style of the data (e.g., icons, boolean values, or integers) is determined by the specified style attribute of the object.
- Returns:
None
- class boonify.Threader(*args: Any, **kwargs: Any)[source]
Bases:
QObjectThreader class for managing application execution within a separate thread.
This class is designed to separate the execution of a provided application function into its own thread using PyQt’s threading mechanism. The class provides functionality to start, switch, and terminate the application running within the thread effectively.
- Variables:
finished – Signal emitted when the thread’s application completes execution.
app – The callable application to be executed within the thread.
thread – The QThread instance used to run the application in a separate thread.
Represents a custom asynchronous functionality encapsulated in a QThread. This class initializes with a callable app function, assigns it to an internal property, and starts a new thread for its execution.
- app
A callable function assigned to the class instance.
- Type:
Callable[[], Any]
- thread
The thread in which the object operates.
- Type:
QThread
- Parameters:
app (Callable[[], Any]) – A callable function that serves as the application’s main function. Defaults to a no-op lambda function.
- apply(app)[source]
Handles the application of a given app instance to a particular object by assigning the provided app to the instance attribute.
- Parameters:
app – The application instance to be applied.
- Returns:
None
- class boonify.View(parent=None)[source]
Bases:
QDialogDialog showing Boolean formulas in a table, allowing editing, validation and conversions.
Integrates with a parent Boonify instance to obtain formulas and variables for display.
- Variables:
style – Style of the formulas displayed in the view.
parent – Reference to the parent Boonify instance.
formulas – List of formula input fields linked to variables.
Initializes the View dialog, loads the UI layout, sets up signal connections, and populates the formula table for the current BooN.
- Parameters:
parent (Boonify or None) – The parent Boonify instance providing BooN data.
- cb_styling()[source]
Updates the current styling for the component based on the selected style and refreshes the view.
- Returns:
None
- change_formula()[source]
Update the BooN formula based on user input and refresh-related components. This method processes the formula input provided through the GUI, verifies its syntax and the validity of the variables involved, and updates the associated BooN data structure if the formula passes all checks. It also refreshes related components to reflect the changes. In case of errors, appropriate error messages are displayed to the user.
- Returns:
None
- convertdnf()[source]
Converts the current BooNn into Disjunctive Normal Form (DNF) and refreshes the view accordingly.
- Returns:
None
- initialize_view()[source]
Initializes and populates the view with formula fields and their respective descriptions and attributes. This method configures a table to display rows of formulas, sets the required text and style for each formula, and identifies and specifies the type of logical formulation.