mobspy.modules package

Submodules

mobspy.modules.class_of_meta_specie_named_any module

The class_of_meta_specie_named_any.py model is responsible for defining the Context_specie_named_any class.

class mobspy.modules.class_of_meta_specie_named_any.Context_specie_named_any(name)

Bases: Species

Class which inherits from Species. It only has one object, Any, which is defined at the end of this script. It is used to simplify the syntax of reactions and count setting inside the body of a “with Any.example_characteristic1 :” statement. Is is compatible with event_condition and event_time methods of the Simulation class. It can be nested and used several time in the same with statement.

context_finish_for_meta_specie_named_any()

This removes the context which is ending from _list_of_nested_any_contexts and updates the current Any context. Then, it updates the Any context in all meta-species.

context_initiator_for_meta_specie_named_any()

This adds the current context in _list_of_nested_any_contexts and then updates the Any context in all meta-species.

mobspy.modules.event_functions module

mobspy.modules.event_functions.format_event_dictionary_for_sbml(species_for_sbml, event_list, characteristics_to_object, volume, dimension, meta_species_to_simulate, parameter_exist, parameters_in_events)

Creates events_for_sbml dictionary for sbml file construction on the sbml_simulator/SBMLWriter.py

Parameters:
  • species_for_sbml – (dict) {‘species_string’: count, ….}

  • event_list – [{‘species’:’meta_species_object’, ‘characteristics’:[‘list of characteristics’], ‘quantity’: number or pint object}

  • characteristics_to_object – {‘characteristic’:’meta_species_object’, …..}

  • volume – Simulation volume for unit conversion

  • dimension – Dimension of the system 2D, 3D, 4D, e

Returns:

event dictionary for the sbml file construction

Return type:

events = {‘e’: { ‘trigger’: ‘true’, ‘delay’: ‘10’, ‘assignments’: [(‘M’,’1’),]}}

mobspy.modules.function_rate_code module

mobspy.modules.process_result_data.py

Handles rate_assignment to the reactions:

The passing of arguments to be executed by the user supplied rate function The construction of mass action kinetics Handles the different types of rates supplied by the user

mobspy.modules.function_rate_code.basic_kinetics_string(reactants, reaction_rate, type_of_model, is_count=False)

This constructs the bases for mass-action kinetics. Both for stochastic and deterministic depending on the type of model

Params reactants:

(list of str) list of reactants in MobsPy str format

Params reaction_rate:

(float) reaction constant

Params type_of_model:

(str) stochastic or deterministic - rate expressions are different depending on each case

Returns:

kinetics_string (str) mass action kinetics expression for the reaction

mobspy.modules.function_rate_code.deterministic_string(reactant_name, number)

This function returns the deterministic string expression for mass action kinetics For instance the reaction 2A -> 3A would imply A*A It only does so for one reactant, so it must be called for all reactants in the reaction

Params reactant_name:

(str) species string involved in the reaction

Params number:

(int) stoichiometry (number of times it appears)

Returns:

to_return_string (str) the mass action kinetics string expression for only that species

mobspy.modules.function_rate_code.extract_reaction_rate(combination_of_reactant_species, reactant_string_list, reaction_rate_function, type_of_model, dimension, function_rate_arguments, parameter_exist, parameters_in_reaction, skip_check)

This function is responsible for returning the reaction rate string for the model construction. To do this it does a different action depending on the type of the reaction_rate_function (we consider constants as functions) It passes the rate as a string expression in MobsPy standard units

Parameters:
  • function_rate_arguments – list of strings of the function rate argument ex:[‘r1’, ‘r2’, ….]

  • combination_of_reactant_species – (list of Species) Meta-species currently being used in this reaction

  • reactant_string_list – (list of strings) list of species strings in order they apear in the reaction

  • reaction_rate_function – (float, callable, Quantity) rate stored in the reaction object

  • dimension – (int) system dimension (for the rate conversion)

Returns:

reaction_rate_string (str) the reaction kinetics as a string for SBML

mobspy.modules.function_rate_code.prepare_arguments_for_callable(combination_of_reactant_species, reactant_string_list, rate_function_arguments, dimension)

This function prepares the requested arguments to the rate function for a given reaction by creating objects of the Specific_Species_Operator class

Params combination_of_reactant_species:

meta-species involved in the reaction

Params reactant_string_list:

species strings involved in the reaction

Params rate_function_arguments:

arguments received by the rate function

mobspy.modules.function_rate_code.search_for_parameters_in_str(reaction_rate_string, parameters_exist, parameters_in_reaction)
mobspy.modules.function_rate_code.stochastic_string(reactant_name, number)

This function returns the stochastic string expression for mass action kinetics For instance the reaction 2A -> 3A would imply A*(A-1)/2 It only does so for one reactant, so it must be called for all reactants in the reaction

Params reactant_name:

(str) species string involved in the reaction

Params number:

(int) stoichiometry (number of times it appears)

Returns:

to_return_string (str) the mass action kinetics string expression for only that species

mobspy.modules.logic_operator_objects module

class mobspy.modules.logic_operator_objects.MetaSpeciesLogicResolver(operation, simulation_context=None)

Bases: object

This object stores the logical and comparison operations that become the event triggers for conditions or the conditional duration for simulations

Parameters:

operation – (list) the logical operation that will be transformed in a string for copasi. Format ex

[{object: …, characteristics:…}, ‘<=’, 10] :param simulation_context: (Simulation) simulation under context

add_double_symbol(symbol, number)
classmethod find_all_species_strings(species, characteristics, species_for_sbml)
generate_string(characteristics_to_object, to_sort=False)
class mobspy.modules.logic_operator_objects.ReactingSpeciesComparator

Bases: SpeciesComparator

This class implements the comparisons necessary for events and conditional durations for Reacting Species ex (A.a1 > 5)

Parameters:

_simulation_context – (Simulation) current simulation under context

add_operation_and_number(symbol, number)

Adds the symbol and number to create a MetaSpeciesLogicResolver object

Parameters:
  • symbol – Comparative symbols ‘<=’, ‘<’, ‘>=’, or ‘>’

  • number – (int) if compared to a value, (Species or ReactingSpecies) if compared to the objects

Returns:

MetaSpeciesLogicResolver object containing the comparison

check_context()

Checks if a reacting species is under context and add it to the attribute self._simulation_context

class mobspy.modules.logic_operator_objects.SpeciesComparator

Bases: object

This class implements the comparisons necessary for events and conditional durations for Species ex (A > 5)

Parameters:

_simulation_context – (Simulation) current simulation under context

add_operation_and_number(symbol, number)

Creates a MetaSpeciesLogicResolver from the comparison of a meta-species with a value or another meta-species

Parameters:
  • symbol – Comparison symbol ‘>=’, ‘<=’, ‘>’ or ‘<’

  • number – (int) if compared to a value, (Species or ReactingSpecies) if compared to the objects

classmethod check_parenthesis(code_line, line_number, pos, symbol, number_of_comp)

This function compiles part of a logic expression for meta-species. It checks to see if an operator ‘<’ or ‘>’ is properly written inside parenthesis. It only applies if more than one operator is present in the code line

Parameters:
  • code_line – (str) line of code to be compiled

  • line_number – (str) number of the code line currently being compiled

  • pos – (int) position of the ‘>’ or ‘<’ operator

  • symbol – ‘(’ or ‘)’, indicates in which direction the string analysis should proceded

  • number_of_comp – for distinction the default case where only one operator is present

Raises:

simlog.error – if the code line is not properly written isolating the clauses with parenthesis

Returns:

(bool) false if the line compiles, raises a error if it does not

classmethod compile_code_line()

Compiles the code line executing a logical operation

Raises:

simlog.error – if the code line is not properly written isolating the clauses with parenthesis

classmethod logical_add_reacting_species(react_spe)

Adds a reacting species object to an event trigger operation by summing over all the indicated characteristics. It also accepts sums of species multiplied by integers

Parameters:

react_spe – (ReactingSpecies) ReactingSpecies object

classmethod logical_add_species(species)

Adds a species object to an event trigger operation

Parameters:

species – (Species) species object

reformat_number_and_species(number)

Discovers if the number is a Species, ReactingSpecies or integer and prepares the output accordingly

Parameters:

number – (int) if compared to a value, (Species or ReactingSpecies) if compared to the objects

mobspy.modules.meta_class module

The meta_class.py model is responsible for defining the meta-species, meta-reactions and other “meta-classes” It is also responsible for compiling the models into data structures that will be converted into an SBML file later Bear in mind that they are not actually Python meta-classes. The first design utilized this feature but know there are just regular classes

mobspy.modules.meta_class.BaseSpecies(number_or_names=None)

Function that returns a number of base species according to the number_of_properties BaseSpecies are just Species with no inheritance attached to it

Parameters:

number_or_names – (int) number of base species wanted or (list) list of names of wanted Species

Returns:

Species objects according to the number of species requested

class mobspy.modules.meta_class.Compiler

Bases: object

The compiler is responsible for constructing the model from the meta-species and meta-reactions given and checking if it is a valid MobsPy model

classmethod add_phantom_reactions(reactions_for_sbml, species_to_add_phantom_reaction)

This method is here because basico cannot compile species that have been assigned to events but are not present in reactions. Interestingly enough this error does not happen in python 3.10. However, to be compatible with earlier versions we add an extremely slow phantom reaction for each one of those species with a coefficient of 1e-100. The idea is that the reaction is so slow that it should not make any sizable difference in any model. It adds them directly to the reactions for sbml dictionary

Parameters:
  • reactions_for_sbml – reactions dictionary in python sbml format

  • species_to_add_phantom_reaction – species that will be assigned a phantom reaction

classmethod add_to_parameters_to_sbml(parameters_used, parameters_for_sbml, parameters_to_add)
classmethod compile(meta_species_to_simulate, reactions_set, species_counts, orthogonal_vector_structure, volume=1, type_of_model='deterministic', verbose=True, event_dictionary=None, continuous_sim=False, ending_condition=None, skip_expression_check=False)

Here we construct the species for Copasi using their objects

It handles the construction of species_for_sbml, reactions_for_sbml, parameters_for_sbml, mappings_for_sbml, model_str which will be used to write the sbml_string for basiCO It also performs checks to see if the model is valid

Parameters:
  • meta_species_to_simulate – (List_Species or Species) Species to generate the model

  • reactions_set – (set) Set of meta-reactions collected when the simulation objected was constructed

  • species_counts – (dict) All counts assigned to species in the model before the simulation object was constructed

  • orthogonal_vector_structure – (dict) ref_characteristics_to_objects in other modules. Dictionary

with the characteristics as keys and the objects as values. Characteritics pointing to their coordinate in the vector space :param volume: (int, flot) Simulation volume :param type_of_model: (str) deterministic or stochastic :param verbose: (bool) print or not the model results by generating a model_str meta-reaction ( or Default we have the round-robin) and how MobsPy will handle meta-species in the products that are not referenced in the reactants - see order_operators.py :param event_dictionary: (dict) dictionary with all the events to be added to the model :param continuous_sim: (bool) simulation with conditional duration or not :param ending_condition: (MetaSpeciesLogicResolver) trigger for the ending contion

Returns:

species_for_sbml (dict) = dictionary where the species strings (in MobsPy format) are the keys and

the values are their counts inside the model. reactions_for_sbml (dict) = Reaction in dictionary format with keys ‘re’, ‘pr’ and ‘rate’. Values are strings parameters_for_sbml (dict) = value with parameter name and tuple with quantity and unit. For standard models it only holds the volume mappings_for_sbml (dict) = Dictionary that maps a meta-species to the set of species strings that belong to it. model_str (str) = str of the variables defined above in a user-readable format. events_for_sbml (dict) = dictionary containing the event trigger and count assignments. assigned_species (list) = list of meta-species which had counts assigned to them during this model execution (used when composing simulations)

entity_counter = 3
last_rate = None
classmethod override_get_item(object_to_return, item)

Due to priority in Python the item is stored before the reaction So it is stored in the Compiler level and passed to the reaction object in the end Important: the rate is used before the compilation level, it’s used when the reaction has been completely defined

Parameters:
  • object_to_return – (Species or Reacting) returns the object that the __getitem__ was performed on

  • item – (int, float, callable, Quantity) stored reaction rate

ref_characteristics_to_object = {}
mobspy.modules.meta_class.ListSpecies(number_of_elements, inherits_from=None)
class mobspy.modules.meta_class.List_Species(iterable)

Bases: object

This class just stores species after the | operation. It creates a list of species than can be loop through or given to the simulator

Parameters:

list_of_species – (Species) Meta-species list to store the meta-species

append(species)

Add species to the list_of_species

Parameters:

species – (Species) meta-species to be added to the List_Species

extend(other)
insert(index, item)
is_in(item)
remove(value)

Removes all instances of the meta-species in the object

Returns:

The number of instances removed

remove_repeated_elements()

This function creates a List_Species with no repetitions. The order of elements is lost

Returns:

List_Species with no repeated elements

mobspy.modules.meta_class.New(species, number_or_names=None)

Function that returns a number of meta-species that inherit from the species supplied

Parameters:

number_or_names – (int) number of meta-species wanted, (list) list of names wanted

Returns:

Species objects according to the number of species requested

class mobspy.modules.meta_class.Reacting_Species(object_reference, characteristics, stoichiometry=1, label=None)

Bases: ReactingSpeciesComparator

This is a intermediary object created when a species is used in a reaction. It is created when a species is part of a reaction, so it’s constructor is called by the Species class in several of it’s methods. It transforms a Species object into a list packable object to pass to create the reaction object. This list format allows for easy concatenation of reactants by summing

The >> operator calls the Reaction constructor to finally define a reaction object

Parameters:

list_of_reactants – (list of dict) used interchangeably for products and reactants.

A list of dictionaries containing the following {‘object’: meta-species object reference, ‘characteristics’: the characteristics queried, ‘stoichiometry’: stoichiometry value, ‘label’: label if used (None)}

c(item)

c query implementation, queries by the value inside a variable instead of the name it just calls __getattr__ with the value inside the variable

Parameters:

item – value to query over

context_finish_for_reacting_specie()

This removes the context which is ending from _list_of_nested_any_contexts and updates the current Cts context. Then, it updates the Cts context in all meta-species.

context_initiator_for_reacting_specie()

This adds the current context in _list_of_nested_any_contexts and then updates the Cts context in all meta-species.

classmethod is_spe_or_reac()
classmethod is_species()
label(label)

Label function implementation. This function assigns labels to meta-species to be matched by the compiler later

Parameters:

label – (int, float, str) value for the label for matching

old_context = {}
class mobspy.modules.meta_class.Reactions(reactants, products)

Bases: object

This is the Reaction class. It contains the reactants, products, rate and order Reactions are created with the >> operator. In each reaction is stored in all involved objects

Parameters:
  • reactants – (list of Species) list of meta-species used as reactants in the meta-reaction

  • products – (list of Species) list of meta-species used as products in the meta-reaction

  • order – (Order Operator) reaction order operator - default in a Round-Robin base

  • rate – (int, float, callable, Quantity) reaction rate

set_rate(rate)

Sets the stored reaction rate. See Compiler.override_get_item(self, item)

Parameters:

rate – (int, float, callable, Quantity) = reaction rate

class mobspy.modules.meta_class.Species(name)

Bases: SpeciesComparator

Fundamental class - The meta-species object Contains the characteristics, the species name, the reactions it is involved in and finally the other species it references Objects store all the basic information necessary to create an SBML file and construct a model So we construct the species through reactions and __getattr__ to form a model

Parameters:

_name – (str) name of the species - named firstly as N$Counter as a placeholder. During compilation it is

named by MobsPy to be equal to the variable name. It can also be named by the user using one the methods :param _characteristics: (str) set of characteristics DIRECTLY added to a species, does not contain inherited characteristics :param _references: (set) set of meta-species a meta-species has inherited from (used in it’s construction). Every species contains itself in this set :param first_characteristic: (str) first characteristic added to the species :param _reactions: (set) Every species stores all reactions is involved in. The compiler performs the union of the set with all species and species in the _references set to get the reactions back :param _species_counts: (list) counts listed for the species. Stores dictionaries with the characteristics as keys and the counts of values

add_characteristic(characteristic)
add_quantities(characteristics, quantity)

This function was implemented because Python can’t accept sets as dictionary keys Set the quantity of an specific string of species

Parameters:
  • characteristics – (str) characteristics of the species to be set

  • quantity – (int, float, Quantity) counts of that specific species

add_reaction(reaction)
add_reference(reference)
c(item)

c query implementation, queries by the value inside a variable instead of the name it just calls __getattr__ with the value inside the variable

Parameters:

item – value to query over

classmethod check_if_valid_characteristic(char)

Checks if the characteristics is valid. If there is any conflict between the methods of the class or attributes of the class the user will be asked to rename the characteristic

Param:

char - name of the characteristic to be added:

Raises:

simlog.error if the characteristic name is not allowed

Returns:

True if characteristic is allowed false if not

get_all_characteristics()

Different that get_characteristics. This function the characteristics directly added to it and the characteristics of the references. While get_characteristics only returns the characteristics directly added to that meta-species.

get_characteristics()
get_index_from_reference_dict(reference)
get_name()
get_ordered_references()
get_quantities()
Returns:

The list of species_counts

get_reactions()
get_references()
classmethod get_simulation_context()
classmethod is_spe_or_reac()
classmethod is_species()
label(label)

Label function implementation. This function matches equal meta-species if they have equal labels Here it returns a Reacting_Species as labels need to be used in reactions

Parameters:

label – (int, float, str) value for the label for matching

Returns:

Reacting_Species object created with the label in the constructor

meta_specie_named_any_context = {}
name(name)

Function to name a species. Allows the user to use a name different from the variable’s name

Parameters:

name – (str) name of the species

order_references()
print_characteristics()
remove_characteristic(characteristic)
remove_repeated_elements()

Defined to be consistent with the model behavior from List_Species :return: Itself

reset_counts()
reset_quantities()

Just reset the counts inside a species - potentially useful in jupyter environment

reset_reactions()
reset_references()
classmethod reset_simulation_context()
set_reactions(reactions)
set_references(reference_set)
classmethod set_simulation_context(sim)
show_characteristics()

Prints the directly characteristics inside the object

show_quantities()

Shows the species counts stored in this object

show_reactions()

Prints the reactions inside the object

show_references()

Prints the objects this object has inherited from (including self)

classmethod str_under_context(species_object, characteristics)

Returns the str representation of a species under context or not

Parameters:
  • species_object – Meta-species object to construct the string

  • characteristics – Characteristics to filter the strings

Returns:

String in format (A_dot_a1 + A_dot_a2 + ….) with the parenthesis

unit(unit)
classmethod update_meta_specie_named_any_context(meta_specie_named_any_characteristics)

This updates the class variable meta_specie_named_any_context with the characteristics of the current any context.

Parameters:

meta_specie_named_any_characteristics – (set) set of characteristics of the currently active any context.

mobspy.modules.meta_class.compile_species_number_line(code_line)

Compiles code line for BaseSpecies and New

Parameters:

code_line

  • Line of code where BaseSpecies or New has been called

Returns:

n (int) = number of variables after a coma, names (list) = list of strings with the names of the

variables

mobspy.modules.meta_class_utils module

This model stores function used by the meta_class.py module

mobspy.modules.meta_class_utils.check_orthogonality_between_references(references)

Check if meta-species objects inside a reference do not have characteristics in common The sets of characteristics directly added to species must be independent

Parameters:

references – (set) set of meta-species objects to check for independence

Raises:

simlog.error – raises error if there are repeated characteristics in different meta-species

mobspy.modules.meta_class_utils.combine_references(species1, species2)

Combine the sets of references of two species

Parameters:
  • species1 – (Meta-species object)

  • species2 – (Meta-species object)

mobspy.modules.meta_class_utils.complete_characteristics_with_first_values(spe_object, characteristics, characteristics_to_object)

This creates a string with the species object name and the set of all first characteristics added to it’s base species used to construct it It allows us to search for the proper string in the model using the result of this function It’s used to set the quantities using the call method in Species and Reacting_Species

Parameters:
  • spe_object – (meta-species object) meta-species to generate the species states with the first values

  • characteristics – (str) if there are characteristics to use instead of the default

  • characteristics_to_object – (dict) dictionary with characteristics as keys and the meta-species which

they have been added to directly as value (no inheritance or New)

Returns:

Set with the species name and characteristics

mobspy.modules.meta_class_utils.create_orthogonal_vector_structure(species)

This creates the independent state-structure for the model It is just a dictionary where the keys are characteristics and the values are meta-species objects that have been directly added to that object (no inheritance or New) It simplifies the code by allowing to easily keep track of the ‘axis’ of each characteristic. Allowing for easy transformation on the products and others

Parameters:

species – (meta-species objects) - meta-species objects used in a model

Return ref_characteristics_to_object:

(dict) a dictionary where the keys are characteristics and the

values are meta-species objects that have been directly added to that object

mobspy.modules.meta_class_utils.unite_characteristics(species)

This function unites the characteristics of all the given species

Parameters:

species – (list of species or List_Species object)

mobspy.modules.mobspy_expressions module

class mobspy.modules.mobspy_expressions.Bool_Override

Bases: object

Just a base class for implementing the . operation in the rate function arguments through boolean overriding. It is responsible for returning true when the reactant has the specified characteristic when using the dot notation

Parameters:
  • _stocked_characteristics – (str) stocks the characteristics of the queries performed by the user

  • species_string – (str) string value from an individual species in MobsPY format

class mobspy.modules.mobspy_expressions.ExpressionDefiner

Bases: object

combine_binary_attributes(other, attribute)
create_from_new_operation(other, symbol, count_op, conc_op, direct_sense=True, operation=None)
classmethod execute_op(first, second, operation)
execute_quantity_op(other, operation)
class mobspy.modules.mobspy_expressions.MobsPyExpression(species_string, species_object, operation=None, unit_count_op=1, unit_conc_op=<Quantity(1, '1 / liter')>, dimension=None, expression_variables=None, parameter_set=None, count_in_model=True, concentration_in_model=False, count_in_expression=True, concentration_in_expression=False, has_units=False)

Bases: Specific_Species_Operator, ExpressionDefiner

generate_string_operation(skip_check=False, reaction_order=None)
class mobspy.modules.mobspy_expressions.OverrideQuantity(value: MagnitudeT, units: UnitLike | None = None)
class mobspy.modules.mobspy_expressions.OverrideQuantity(value: str, units: UnitLike | None = None)
class mobspy.modules.mobspy_expressions.OverrideQuantity(value: Sequence[ScalarT], units: UnitLike | None = None)
class mobspy.modules.mobspy_expressions.OverrideQuantity(value: PlainQuantity[Any], units: UnitLike | None = None)

Bases: ExpressionDefiner, Quantity

convert(unit)
convert_into(unit)
non_expression_add(other)
non_expression_mul(other)
non_expression_pow(other)
non_expression_radd(other)
non_expression_rmul(other)
non_expression_rsub(other)
non_expression_rtruediv(other)
non_expression_sub(other)
non_expression_truediv(other)
set_ms_active(ms_active)
class mobspy.modules.mobspy_expressions.OverrideUnitRegistry

Bases: object

class mobspy.modules.mobspy_expressions.QuantityConverter

Bases: object

classmethod convert_received_unit(quantity)
class mobspy.modules.mobspy_expressions.Specific_Species_Operator(species_string, species_object)

Bases: Bool_Override

This class creates objects from the species strings from the meta-species to pass them to the rate functions as arguments. It uses the Bool_Override class to return true or false to the .dot operation inside the rate functions

Parameters:
  • _stocked_characteristics – (str) stocks the characteristics of the queries performed by the user

  • species_string – (str) string value from an individual species in MobsPY format

  • species_object – (Species) Meta-species object which originated the meta-species str

add(characteristic)

Adds characteristic to the set of characteristics when checking for all referred characteristics by the user

Parameters:

characteristic – (str) characteristic to add to the set

get_characteristics()

Returns: The characteristics of the species in this given state

get_name()

Returns: The name of the species the reactant is in string format

is_a(reference)

This function checks to see if the meta-species the species_string belong to has inherited from the parameter reference (reminder: every meta-species inherits from itself)

Parameters:

reference – (Species) Meta-species object

Returns:

(bool) True if the meta-species in Specific_Species_Operator has inherited from the reference

False otherwise

mobspy.modules.mobspy_parameters module

class mobspy.modules.mobspy_parameters.Mobspy_Parameter(name, value)

Bases: ExpressionDefiner, QuantityConverter

parameter_stack = {}
rename(new_name)
mobspy.modules.mobspy_parameters.ModelParameters(*args)

mobspy.modules.order_operators module

This module deals with order_operators Thus it deals with the Round-Robin order assignment and with species in the products that are not referenced in the reactants (Born Species) It has also the implementation of the Rev operator, since that is a also a reaction operator

mobspy.modules.reaction_construction_nb module

This module is responsible for the construction of all individual reactions from a meta-reaction

mobspy.modules.reaction_construction_nb.check_for_invalid_reactions(reactions, ref_characteristics_to_object)

If query references two independent characteristics from the in meta-species it would result in an empty set Like Ecoli.live.dead - (assuming live and dead belong to the same meta-species characteristics set) If that ever happens inside a meta-reaction we just pop an error

Parameters:
  • reactions – (set of meta-reactions) set of meta-reactions inside the model

  • ref_characteristics_to_object – (dict) dictionary with the characteristics as keys and their respective

object as values

mobspy.modules.reaction_construction_nb.construct_order_structure(species_order_list, current_species_string_list)

Order structure for reaction order operations. Returns the cyclic_dictionary to be used by the order operator. The meta-species objects are the keys of this dictionary and a lists of species strings currently being used in the reaction are the values - Allowing the product to find it’s corresponding species-string in a future step

Parameters:

species_order_list – (list of meta-species objects) list of meta-species objects as they appear in the

meta-reaction :param current_species_string_list: (list of strings) list of strings in MobsPy format of the species currently in this specific reaction

Returns:

cyclic_dict (dict) Dictionary where the keys are meta-species objects and the values are

lists of species

mobspy.modules.reaction_construction_nb.construct_product_structure(reaction)

This function unpacks the products in a meta-reaction

Param:

reaction meta-reaction currently being analysed

Returns:

product_list = A list of dictionaries for each product with the meta-species object, the label and the

characteristics

mobspy.modules.reaction_construction_nb.construct_rate_function_arguments(rate_function, reaction)
mobspy.modules.reaction_construction_nb.construct_reactant_structures(reactant_species, ref_characteristics_to_object)

This function finds the corresponding strings according to the reactant meta-species with or without a query pack then in a list and return

Parameters:
  • reactant_species – (meta-species object) species objects of the involved species

  • ref_characteristics_to_object – (dict) dictionary with characteristics as keys and species objects as

values

mobspy.modules.reaction_construction_nb.construct_single_reaction_for_sbml(reactant_species_string_list, product_species_string_list, reaction_rate)

This function constructs the reactions for SBML for the conversion by the model builder script It follows the following structure ‘re’:[(‘stoichmetry’, reactantant_string) …. The reaction rate must be a string containing the reaction kinetics This returns a single reaction to be appended by the reactions_for_sbml dictionary

Parameters:
  • reactant_species_string_list – (list of strings) list of reactants in MobsPy format

  • product_species_string_list – (list of strings) list of products in MobsPy format

  • reaction_rate – (str) reaction rate expression as a string

Returns:

to_return (dict) = dictionary that packs the reactants products and rate

mobspy.modules.reaction_construction_nb.copy_reaction(reaction)

Just copies a meta-reaction Deepcopy is not working because it calls __getattr__ on the species with a private method

Parameters:

reaction (meta-reaction) –

mobspy.modules.reaction_construction_nb.count_string_dictionary(list_of_strings)

Count the number of instances in a list and return them in a dictionary where the keys are the strings and the value the number of times it appeared in the list

mobspy.modules.reaction_construction_nb.create_all_reactions(reactions, meta_species_in_model, ref_characteristics_to_object, type_of_model, dimension, parameter_exist, parameters_in_reaction, skip_check)

This function creates all reactions Returns the reactions_for_sbml and parameters_for_sbml dictionary Those will be used by another module to create the SBML file

Parameters:
  • reactions – (meta-reaction objects) reactions objects constructed by the meta_class module

  • meta_species_in_model – (list) list of meta-species in model

  • ref_characteristics_to_object – (dict) Characteristics as keys objects as values

  • type_of_model – (str) stochastic or deterministic

  • dimension – (int) model dimension 1D, 2D, 3D, …..

Returns:

reactions_for_sbml (dict) = dictionary with all reactions that will be added to the sbml model file,

parameters_for_sbml (dict) = parameters for the sbml model file

mobspy.modules.reaction_construction_nb.expression_compilation_finish(expressions)

Sets _ms_active to false for all expressions found in the stack by expression_compilation_initiation()

mobspy.modules.reaction_construction_nb.expression_compilation_initiation()

First find all ExpressionDefiner objects in the stack. Then, sets _ms_active to True to change the behavior of quantities and units in expressions

mobspy.modules.reaction_construction_nb.get_involved_species(reaction, meta_species_in_model)

This extracts all the involved meta-species inside a reaction This function is responsible for implementing the inheritance mechanism, by finding within each meta-species references set, if they reference the meta-species in the reaction

Parameters:
  • reaction – (meta-reaction object)

  • meta_species_in_model – (list) list of meta-species used in the model

Returns:

base_species_order (list of meta-species objects) = order that the meta-species appear in the

meta-reaction, reactant_species_combination_list (list of lists of meta-species) = list of lists of all meta-species that have inherited from the meta-species in the meta-reaction

mobspy.modules.reaction_construction_nb.iterator_for_combinations(list_of_lists)

Iterate through all the combinations of a list of lists [[A,B,C], [D, F, E], [G]] means: ADG, AFG, AEG, BDG, BFG, BEG, CDG, CFG, CEG …..

Parameter:

list_of_lists (list of lists) = list of all lists to iterate through all combinations

mobspy.modules.reaction_construction_nb_parallel module

This module is responsible for the construction of all individual reactions from a meta-reaction

mobspy.modules.reaction_construction_nb_parallel.check_for_invalid_reactions(reactions, ref_characteristics_to_object)

If query references two independent characteristics from the in meta-species it would result in an empty set Like Ecoli.live.dead - (assuming live and dead belong to the same meta-species characteristics set) If that ever happens inside a meta-reaction we just pop an error

Parameters:
  • reactions – (set of meta-reactions) set of meta-reactions inside the model

  • ref_characteristics_to_object – (dict) dictionary with the characteristics as keys and their respective

object as values

mobspy.modules.reaction_construction_nb_parallel.construct_order_structure(species_order_list, current_species_string_list)

Order structure for reaction order operations. Returns the cyclic_dictionary to be used by the order operator. The meta-species objects are the keys of this dictionary and a lists of species strings currently being used in the reaction are the values - Allowing the product to find it’s corresponding species-string in a future step

Parameters:

species_order_list – (list of meta-species objects) list of meta-species objects as they appear in the

meta-reaction :param current_species_string_list: (list of strings) list of strings in MobsPy format of the species currently in this specific reaction

Returns:

cyclic_dict (dict) Dictionary where the keys are meta-species objects and the values are

lists of species

mobspy.modules.reaction_construction_nb_parallel.construct_product_structure(reaction)

This function unpacks the products in a meta-reaction

Param:

reaction meta-reaction currently being analysed

Returns:

product_list = A list of dictionaries for each product with the meta-species object, the label and the

characteristics

mobspy.modules.reaction_construction_nb_parallel.construct_rate_function_arguments(rate_function, reaction)
mobspy.modules.reaction_construction_nb_parallel.construct_reactant_structures(reactant_species, ref_characteristics_to_object)

This function finds the corresponding strings according to the reactant meta-species with or without a query pack then in a list and return

Parameters:
  • reactant_species – (meta-species object) species objects of the involved species

  • ref_characteristics_to_object – (dict) dictionary with characteristics as keys and species objects as

values

mobspy.modules.reaction_construction_nb_parallel.construct_single_reaction_for_sbml(reactant_species_string_list, product_species_string_list, reaction_rate)

This function constructs the reactions for SBML for the conversion by the model builder script It follows the following structure ‘re’:[(‘stoichmetry’, reactantant_string) …. The reaction rate must be a string containing the reaction kinetics This returns a single reaction to be appended by the reactions_for_sbml dictionary

Parameters:
  • reactant_species_string_list – (list of strings) list of reactants in MobsPy format

  • product_species_string_list – (list of strings) list of products in MobsPy format

  • reaction_rate – (str) reaction rate expression as a string

Returns:

to_return (dict) = dictionary that packs the reactants products and rate

mobspy.modules.reaction_construction_nb_parallel.copy_reaction(reaction)

Just copies a meta-reaction Deepcopy is not working because it calls __getattr__ on the species with a private method

Parameters:

reaction (meta-reaction) –

mobspy.modules.reaction_construction_nb_parallel.count_string_dictionary(list_of_strings)

Count the number of instances in a list and return them in a dictionary where the keys are the strings and the value the number of times it appeared in the list

mobspy.modules.reaction_construction_nb_parallel.create_all_reactions(reactions, meta_species_in_model, ref_characteristics_to_object, type_of_model, dimension, parameter_exist, parameters_in_reaction)

This function creates all reactions Returns the reactions_for_sbml and parameters_for_sbml dictionary Those will be used by another module to create the SBML file

Parameters:
  • reactions – (meta-reaction objects) reactions objects constructed by the meta_class module

  • meta_species_in_model – (list) list of meta-species in model

  • ref_characteristics_to_object – (dict) Characteristics as keys objects as values

  • type_of_model – (str) stochastic or deterministic

  • dimension – (int) model dimension 1D, 2D, 3D, …..

Returns:

reactions_for_sbml (dict) = dictionary with all reactions that will be added to the sbml model file,

parameters_for_sbml (dict) = parameters for the sbml model file

mobspy.modules.reaction_construction_nb_parallel.get_involved_species(reaction, meta_species_in_model)

This extracts all the involved meta-species inside a reaction This function is responsible for implementing the inheritance mechanism, by finding within each meta-species references set, if they reference the meta-species in the reaction

Parameters:
  • reaction – (meta-reaction object)

  • meta_species_in_model – (list) list of meta-species used in the model

Returns:

base_species_order (list of meta-species objects) = order that the meta-species appear in the

meta-reaction, reactant_species_combination_list (list of lists of meta-species) = list of lists of all meta-species that have inherited from the meta-species in the meta-reaction

mobspy.modules.reaction_construction_nb_parallel.iterator_for_combinations(list_of_lists)

Iterate through all the combinations of a list of lists [[A,B,C], [D, F, E], [G]] means: ADG, AFG, AEG, BDG, BFG, BEG, CDG, CFG, CEG …..

Parameter:

list_of_lists (list of lists) = list of all lists to iterate through all combinations

mobspy.modules.set_counts_module module

mobspy.modules.set_counts_module.set_counts(count_dic)

Adds counts to meta-species using a given dictionary. Keys from this dictionary can be either meta-species objects or strings. Items must be the assign counts to species

Parameters:

count_dic – Dictionary where keys can be either meta-species or strings

Raises:

simlog.error

  • If a count is assigned to a Reacting_Species with more than one meta-species.

If there are two species with the same name and a string assignment is performed. If the keys are not strings or meta-species. If the counts are not Quantities, Floats or Ints. If the species was not found in the stack. :return: List_Species object. All meta-species that had a count assigned in this dictionary will be returned as a List_Species which can be passed as a model to the simulation object

mobspy.modules.species_string_generator module

mobspy.modules.species_string_generator.characteristics_dictionary(characteristics, characteristics_to_object)

This function constructs a dictionary that leads from the species string characteristics to their respective object. This structure allows to easily find where the characteristics in a species string are locates

Parameters:
  • characteristics – (set) of characteristics

  • characteristics_to_object – (dict) with characteristics as keys and their respective base meta-species

object as value

mobspy.modules.species_string_generator.construct_all_combinations(spe_object, characteristics, characteristics_to_object, symbol=None)

This function constructs all possible list in the format [‘species_name’, ‘char1’, ‘char2’, …] using all combinations of characteristics from the vector coordinates not used in the characteristics specified in the function argument. If a symbol is given it generates a string from the list using the symbol to join it.

Parameters:
  • spe_object – meta-species object to be used

  • characteristics – (set) of characteristics given

  • characteristics_to_object – (dict) with characteristics as keys and their respective base meta-species

object as value :param symbol: (str) usually . or _dot_, connects the elements from the list using the specified symbol

mobspy.modules.species_string_generator.construct_species_char_list(spe_object, characteristics, characteristics_to_object, symbol=None)

This function constructs a list in the format [‘species_name’, ‘char1’, ‘char2’, …]. It generetes this list for a given meta-species and the specified characteristics. Values of characteristics not specified in a particular position are replaced by their default value. If a symbol is given it generates a string from the list using the symbol to join it.

Parameters:
  • spe_object – meta-species object to be used

  • characteristics – (set) of characteristics given

  • characteristics_to_object – (dict) with characteristics as keys and their respective base meta-species

object as value :param symbol: (str) usually . or _dot_, connects the elements from the list using the specified symbol

mobspy.modules.unit_handler module

This module is responsible for dealing with units in the modules directory level MobsPy standard units are Decimeter (Liter) - Second - Count

mobspy.modules.unit_handler.check_dimension(dimension, value)

Checks for dimension consistency. It “stores” the first dimension it was given by returning it

Parameters:
  • dimension – (int) model’s dimension (1D, 2D, 3D …)

  • value – (int) dimension value being analysed

Raises:

simlog.error – If dimensions are not consistent through the given units (units in 1D with 2D mixed)

Returns:

dimension (int) = model’s dimension (1D, 2D, 3D …)

mobspy.modules.unit_handler.convert_counts(quantity, volume, dimension)

This function converts the counts from the users given unit to MobsPy standard units. It also converts concentrations into counts

Parameters:
  • quantity – (int, float, Quantity) If it is a quantity object convert, otherwise it remains the same

  • volume – (int, float) volume in liters (converted beforehand)

  • dimension – (int) model’s dimension (1D, 2D, 3D, … )

Returns:

converted_quantity (int, float) = converted unit into MobsPy standard units

mobspy.modules.unit_handler.convert_rate(quantity, reaction_order, dimension)

This function converts the rate from the users given unit to MobsPy standard units

Parameters:
  • quantity – (int, float, Quantity) If it is a quantity object convert, otherwise it remains the same

  • reaction_order – (int) number of reactants in the reaction, to check if the rate is in the correct unit

  • dimension – (int) model’s dimension (1D, 2D, 3D, … )

  • quantity – (int, float) converted unit into MobsPy standard units

mobspy.modules.unit_handler.convert_time(time)

Converts time into seconds

Parameters:

time – (int, float, Quantity) any time used

mobspy.modules.unit_handler.convert_volume(volume, dimension)

Converts volume to decimetre**dimension

Parameters:

volume – (int, float, Quantity) volume used in simulation

Returns:

the converted volume in MobsPy units

mobspy.modules.unit_handler.extract_length_dimension(unit_string, dimension, reaction_order=None)

Extracts the volume dimension from a Quantity object from Pint

Parameters:
  • unit_string – (str) unit in str format

  • dimension – (int) model’s dimension (1D, 2D, 3D …)

mobspy.modules.user_functions module

mobspy.modules.user_functions.Apply(function, *args)

Module contents