Core
Atomic
- class eBCSgen.Core.Atomic.AtomicAgent(name: str, state: str)
Bases:
object- add_context(other, atomic_signature: dict, structure_signature: dict) set
Fills missing context for given agent.
If other is also an atomic agents, this methods gives them both the same states according to the given atomic_signature. Otherwise, context is filled independently and other part is None, unless it’s a StructureAgent. Finally, if both agents have defined states, they are returned untouched.
Note: it is assumed this method is used only for well formed rules, which means given atomics have the same name AND either both do or do not have specified state.
- Parameters:
other – possibly an atomic agent, -1 if context is empty on left, 1 for right
atomic_signature – given mapping of atomic name to possible states
structure_signature – given mapping of structure name to possible atomics
- Returns:
set of pairs
- compatible(other: AtomicAgent) bool
Check if two Atomic agents are compatible.
- Parameters:
other – given AtomicAgent
- Returns:
True if compatible
- extend_signature(atomic_signature: dict, structure_signature: dict)
Extend given signatures by possibly new context.
- Parameters:
atomic_signature – given atomic signature
structure_signature – given structure signature
- Returns:
updated signatures
- reduce_context()
Reduces context of AtomicAgent to minimum.
- Returns:
new AtomicAgent with reduced context
- replace(agent)
Replace agent based on a pattern.
- Parameters:
agent – given agent to be changed
- Returns:
changed agent
Complex
- class eBCSgen.Core.Complex.Complex(agents: list, compartment: str)
Bases:
object- align_match(complex)
Align self.agents based on given order. An alignment must exist (because respective complex is compatible)
- Parameters:
complex – given reference (from lhs) complex
- Returns:
aligned self.agents
- compatible(other: Complex)
Checks whether two Complexes are compatible.
- Parameters:
other – another Complex
- Returns:
True if they are compatible
- create_all_compatible(atomic_signature: dict, structure_signature: dict)
Creates all fully specified complexes compatible with the Complex
- Parameters:
atomic_signature – given atomic signature
structure_signature – given structure signature
- Returns:
set of all create Complexes
- extend_signature(atomic_signature: dict, structure_signature: dict)
Extend given signatures by possibly new context.
- Parameters:
atomic_signature – given atomic signature
structure_signature – given structure signature
- Returns:
updated signatures
- get_agent_names()
Maps names to all agents in complex :return: list of agent names in this complex
- get_atomic_names() set
Creates set of all atomic names used in the complex.
- Returns:
set of all atomic names
- identify_compatible(agents: tuple) list
Identifies compatible agents from given list.
- Parameters:
agents – given tuple of agents (ordering)
- Returns:
list of indices of compatible agents
- is_composed() bool
Determines if this complex agent is composed out of more atomic/structure agents or single agent.
- Returns:
True if holds
- reduce_context() Complex
Reduces context of Complex to minimum.
- Returns:
new Complex with reduced context
- to_PRISM_code(number: int) str
Creates state variable name for PRISM model.
- Parameters:
number – position in ordering
- Returns:
PRISM variable name
- to_SBML_speciesTypes_code() str
- Returns:
ID of SBML - speciesType of this complex agent
- to_SBML_species_code() str
Compute a unique SBML ID for complex. Uses modified hash which takes into account the ordering of agents (compared to self.__hash__() which treats them as a multiset).
- Returns:
ID of SBML species of this complex agent
- eBCSgen.Core.Complex.align_agents(ordered, to_align)
Recursively align two lists of agents based on compatibility.
- Parameters:
ordered – reference list of agents
to_align – target counter of agents
- Returns:
all possible alignments
Formula
- class eBCSgen.Core.Formula.APreplacetor(replacements, extra_quotes)
Bases:
Transformer- ap(proposition)
- class eBCSgen.Core.Formula.AtomicProposition(complex, sign, number)
Bases:
object
- class eBCSgen.Core.Formula.Formula(success, data)
Bases:
objectClass to represent Formula.
- create_complex_labels(ordering: tuple)
Creates label for each unique Complex from Formula. This covers two cases - ground and abstract Complexes. For the abstract ones, a PRISM formula needs to be constructed as a sum of all compatible complexes.
- Parameters:
ordering – given complex ordering of TS
- Returns:
unique label for each Complex and list of PRISM formulas for abstract Complexes
- get_APs() list
Extracts all AtomicPropositions from the Tree.
- Returns:
list of Atomic Propositions
- get_complexes() list
Extracts all used Complexes from the Tree.
- Returns:
list of extracted Complexes
- replace_APs(replacements: dict, extra_quotes=True) Formula
Replaces APs according to given dictionary. This is used for explicit file format for PRISM.
- Parameters:
replacements – dictionary of type AtomicProposition -> str
extra_quotes – wrap AP labels in quotes
- Returns:
new Formula with replaced APS
Model
- class eBCSgen.Core.Model.Model(rules: set, init: Counter, definitions: dict, params: set, regulation=None)
Bases:
object- check_rates() bool
Checks if all rates are defined. If not, attribute all_rates is set to False and default value is assigned to the rate
- Returns:
True if rates are defined
- compute_bound()
Estimates bound from the rules and initial state.
- Returns:
obtained bound
- create_ordering() SortedList
Extracts all possible unique agents from the model and gives them fixed order using SortedList.
- Returns:
SortedList of unique agents
- create_unique_complexes_and_params()
Extracts unique complexes and compartments from rules splits complexes by its isomorphisms
- Returns:
dict of unique complexes mapped to list of its isomorphisms and set of unique params
- eliminate_redundant()
Adds comments to rules which are potentially redundant.
In the case when there are no rule present, it automatically comments out the redundant rules.
- export_sbml() SBMLDocument
Convert model to a SBML model using SBML-multi package (libSBML).
- Returns:
SBML document
- extract_signatures()
Automatically creates signature from context of rules and initial state. Additionally it checks if all rules have a rate, sets all_rates to False otherwise.
- Returns:
created atomic and structure signatures
- generate_direct_transition_system(max_time: float = inf, max_size: float = inf, bound=None)
Generates transition system using direct rule firing.
- Parameters:
max_time – max time for TS generating before interrupting
max_size – max allowed size of TS before interrupting
bound – bound for individual elements
- Returns:
generated transitions system
- network_free_simulation(max_time: float)
Direct simulation method using Network-free Gillespie method.
- Parameters:
max_time – maximal simulation time
- Returns:
generated dataframe containing simulated time series
- reduce_context()
Reduces context of the Model to the minimum. Includes all rules and initial state.
- static_non_reachability(agent: Complex) bool
Checks whether there exists a rule with compatible agent in its rhs.
- Parameters:
agent – given Complex agent
- Returns:
True if exists compatible
- to_vector_model(bound: int | None = None) VectorModel
Creates vector representation of the model.
First reactions are generated, then unique complexes are collected and finally both reactions and initial state are transformed to vector representation.
- Parameters:
bound – given bound
- Returns:
VectorModel representation of the model
Rate
- class eBCSgen.Core.Rate.ContextReducer(visit_tokens: bool = True)
Bases:
Transformer- agent(matches)
- class eBCSgen.Core.Rate.DirectEvaluater(values, params)
Bases:
Transformer- agent(matches)
- param(matches)
- rate_agent(matches)
- class eBCSgen.Core.Rate.MathMLtransformer
Bases:
Transformer- fix_operator(node, matches)
- fun(matches)
- rate(matches)
- rate_agent(matches)
- class eBCSgen.Core.Rate.Rate(expression)
Bases:
object- evaluate(state) float
Evaluates all occurrences of States to a float using Evaluater. It is done as intersection of particular state with given state and sum of resulting elements.
If the result is nan, None is returned instead.
- Parameters:
state – given state
- Returns:
Sympy object for expression representation
- evaluate_direct(values, params) float
Evaluates all agents (Complex objects) and params (strings) used in the rate expression in the case of direct approach.
If the result is nan, None is returned instead.
- Parameters:
values – given mapping complex -> count
- Returns:
Sympy object for expression representation
- get_formula_in_list()
Create list representation of the formula.
- Returns:
list of formula components
- get_params_and_agents()
Extracts all agents (Complex objects) and params (strings) used in the rate expression.
- Returns:
set of agents and params
- reduce_context() Rate
Reduces context of all Complexes to minimum.
- Returns:
new Rate with reduced context
- to_mathML()
Create mathML representation of the formula.
- Returns:
mathML representation
- to_symbolic()
Translates rate from vector representation to symbolic one as a sum of particular components. e.g. [1, 0, 1] -> (x_0 + x_2)
- vectorize(ordering: SortedList, definitions: dict) list
Converts all occurrences of Complexes (resp. sub trees named agent) with its vector representation. These are directly replaced within the tree expression.
Moreover, in the process parameters are replaces with their values (if given).
- Parameters:
ordering – given SortedList of Complexes
definitions – dict of (param_name, value)
- Returns:
list of transformed States (just for testing)
Reaction
- class eBCSgen.Core.Reaction.Reaction(lhs: Side, rhs: Side, rate: Rate, label=None)
Bases:
object- compatible(other: Reaction) bool
Checks whether Reaction is compatible (position-wise) with the other Reaction.
- Parameters:
other – given Reaction
- Returns:
True if compatible
- create_all_compatible(atomic_signature: dict, structure_signature: dict)
Creates all fully specified complexes for all both Sides
- Parameters:
atomic_signature – given atomic signature
structure_signature – given structure signature
- Returns:
set of all created Complexes
- to_vector(ordering: SortedList, definitions: dict) VectorReaction
Creates vector representation of the Reaction.
- Parameters:
ordering – given fixed order of unique Complexes
definitions – dict of (param_name, value)
- Returns:
VectorReaction representation of Reaction
Rule
- class eBCSgen.Core.Rule.Rule(agents: tuple, mid: int, compartments: list, complexes: list, pairs: list, rate: Rate, label=None)
Bases:
object- compatible(other: Rule) bool
Checks whether Rule is compatible (position-wise) with the other Rule. Is done by formaly translating to Reactions (just a better object handling).
- Parameters:
other – given Rule
- Returns:
True if compatible
- create_all_compatible(atomic_signature: dict, structure_signature: dict)
Creates all fully specified complexes for all both Sides
- Parameters:
atomic_signature – given atomic signature
structure_signature – given structure signature
- Returns:
set of all created Complexes
- create_complexes()
Creates left- and right-hand sides of rule as multisets of Complexes.
- Returns:
two multisets of Complexes represented as object Side
- create_reactions(atomic_signature: dict, structure_signature: dict) set
Create all possible reactions. Decide if rule is of replication type and call corresponding lower level method.
- Parameters:
atomic_signature – given mapping of atomic name to possible states
structure_signature – given mapping of structure name to possible atomics
- Returns:
set of created reactions
- create_reversible(rate: Rate | None = None)
Create a reversible version of the rule with _bw label.
Also add implicit _fw label to current Rule.
TODO: allow two rates
- Returns:
reversed Rule
- evaluate_rate(state, params)
Evaluate rate based on current state and parameter values.
- Parameters:
state – given state
params – mapping of params to its value
- Returns:
a real number of the rate
- exists_compatible_agent(agent: Complex) bool
Checks whether there exists a compatible agent in the rhs of the rule.
- Parameters:
agent – given Complex agent
- Returns:
True if exists compatible
- get_unique_complexes_from_rule() dict
Creates complexes from rule and returns them in dict. Keys are Complex agents, values are sets of all found isomorphisms in SBML code.
- Returns:
dict of {Complexes:{SBML codes of all isomorphisms in set}}
- is_meaningful() bool
Checks whether the Rule does any change, i.e. is meaningful. Done by translating to Reaction and comparing its sides.
- Returns:
True if meaningful
- match(state, all=False)
Find all possible matches of the rule to given state.
- Parameters:
state – given state
all – bool to indicate if choose one matching randomly or return all of them
- Returns:
random match/all matches
- rate_to_vector(ordering, definitions: dict)
Converts all occurrences of Complexes in rate to vector representation.
- Parameters:
ordering – given ordering of unique of Complexes (as sortedcontainers.SortedList)
definitions – dict of (param_name, value)
- reconstruct_complexes_from_match(match)
Create complexes from agents matched to the LHS
- Parameters:
match – value of
- Returns:
multiset of constructed agents
- reduce_context()
Reduces context of Rule to minimum. Includes both agents and Rate.
- Returns:
new Rule with reduced context
- replace(aligned_match)
Apply rule to chosen match. Match contains agents which satisfy LHS of the rule an can be safely replaced based on RHS
- Parameters:
aligned_match – complexes fitting LHS of the rule
- Returns:
multiset replaced according to the match
- eBCSgen.Core.Rule.column(lst, index)
- eBCSgen.Core.Rule.find_all_matches(lhs_agents, state)
Finds all possible matches which actually can be used for given state.
- Parameters:
lhs_agents – given LHS of a rule
state – state to be applied to
- Returns:
candidates for match
Side
- class eBCSgen.Core.Side.Side(agents: list)
Bases:
object- compatible(other: Side) bool
Checks whether two Sides are compatible.
Is True only of on corresponding positions the Complexes are compatible and length of the Sides is equal.
- Parameters:
other – given Side
- Returns:
True if they are compatible
- create_all_compatible(atomic_signature: dict, structure_signature: dict)
Creates all fully specified complexes for all complexes in Side
- Parameters:
atomic_signature – given atomic signature
structure_signature – given structure signature
- Returns:
set of all created Complexes
- exists_compatible_agent(agent: Complex) bool
Checks whether there exists a compatible agent in the Side.
- Parameters:
agent – given Complex agent
- Returns:
True if exists compatible
- most_frequent()
- to_counter()
- to_list_of_strings()
Structure
- class eBCSgen.Core.Structure.StructureAgent(name: str, composition: set)
Bases:
object- add_context(other, atomic_signature: dict, structure_signature: dict) set
Fills missing context for given agent.
Note: it is assumed this method is used only for well formed rules, which means given structure agents have specified the same atomic agents and miss the same atomic agents.
Moreover, agents which are not specified are completely omitted. TBD: this could be somehow hacked.
- Parameters:
other – possibly a structure agent, -1 if context is empty on left, 1 for right
atomic_signature – given mapping of atomic name to possible states
structure_signature – given mapping of structure name to possible atomics
- Returns:
set of pairs
- compatible(other: StructureAgent)
This methods works correctly because it is guaranteed that each atomic agent name is at most once in the composition.
- Parameters:
other – another StructureAgent
- Returns:
True if they are compatible
- extend_signature(atomic_signature: dict, structure_signature: dict)
Extend given signatures by possibly new context.
- Parameters:
atomic_signature – given atomic signature
structure_signature – given structure signature
- Returns:
updated signatures
- reduce_context()
Reduces context of StructureAgent to minimum.
- Returns:
new StructureAgent with reduced context
- replace(agent)
Replace agent based on a pattern.
- Parameters:
agent – given agent to be changed
- Returns:
changed agent