ReactionRegistry – Reference Guide

This guide is for versions 1.0.0rc.7+ (Release Candidate)

Source code

Class ReactionRegistry

    Manage a list of reactions, and the reaction-specific objects (defined in reactions.py file),
    such as ReactionUnimolecular, ReactionSynthesis, ReactionDecomposition, ReactionGeneric, ReactionEnzyme, etc.

    Instances of this class are typically used by UniformCompartment objects.
    A ReactionRegistry object may be shared by multiple UniformCompartment objects IF the latter
    all make use of ALL the registered reactions  (i.e. no "pick and choose" some of the reactions.)
    
nameargumentsreturns
__init__chem_data=None
        :param chem_data:   [OPTIONAL] Object of type "ChemData"; if not passed, it will get instantiated automatically -
                                and then it can be obtained by means of the method get_chem_data()
        
nameargumentsreturns
number_of_reactionsinclude_inactive=Falseint
        Return the number of registered chemical reactions

        :param include_inactive:    If True, disabled reactions are also included
        :return:                    The number of registered chemical reactions
        
nameargumentsreturns
get_all_reactions

        :return:    A list of various types of reaction objects,
                        such as ReactionUnimolecular, ReactionSynthesis, etc.
        
nameargumentsreturns
active_reaction_indices[int]
        Return a list of the reaction index numbers of all the active reactions

        :return:    A list of integers, to identify the active reactions by their indices
        
nameargumentsreturns
assert_valid_rxn_indexindex :intNone
        Raise an Exception if the specified reaction index isn't valid

        :param index:   An integer that indexes the reaction of interest (numbering starts at 0)
        :return:        None
        
nameargumentsreturns
get_chem_data
        :return:    Object of type "ChemData"
        
nameargumentsreturns
get_reactioni :int
        Return the data structure of the i-th reaction,
        in the order in which reactions were added (numbering starts at 0)

        :param i:   An integer that indexes the reaction of interest (numbering starts at 0)
        :return:    An object of one of the various individual reaction classes,
                    such as "ReactionGeneric" and "ReactionEnz"
        
nameargumentsreturns
get_reactantsi :int[(int, str)]
        Return a list of pairs with details of the reactants of the i-th reaction.
        Each pair represents a "complex" of the reaction reactants

        :param i:   The index (0-based) to identify the reaction of interest
        :return:    A list of pairs of the form (stoichiometry, chem labels)
        
nameargumentsreturns
get_reactant_speciesi :int[str]
        Return a list of the reactant species of the i-th reaction.

        :param i:   The index (0-based) to identify the reaction of interest
        :return:    A list of chem labels
        
nameargumentsreturns
get_reactants_formulai :intstr
        Return a string with a user-friendly form of the left (reactants) side of the reaction formula

        :param i:   The index (0-based) to identify the reaction of interest
        :return:    A string with a user-friendly form of the left (reactants) side of the chemical reaction
        
nameargumentsreturns
get_productsi :int[(int, str)]
        Return a list of pairs with details of the products of the i-th reaction.
        Each pair represents a "complex" of the reaction products

        :param i:   The index (0-based) to identify the reaction of interest
        :return:    A list of pairs of the form (stoichiometry, species label)
        
nameargumentsreturns
get_product_speciesi :int[str]
        Return a list of the product species of the i-th reaction.

        :param i:   The index (0-based) to identify the reaction of interest
        :return:    A list of chem labels
        
nameargumentsreturns
get_products_formulai :intstr
        Return a string with a user-friendly form of the right (products) side of the reaction formula

        :param i:   The index (0-based) to identify the reaction of interest
        :return:    A string with a user-friendly form of the right (products) side of the chemical reaction
        
nameargumentsreturns
get_forward_ratei :intfloat
        Return the value of the forward rate constant of the i-th reaction

        :param i:   The integer index (0-based) to identify the reaction of interest
        :return:    The value of the forward rate constant for the above reaction
        
nameargumentsreturns
get_reverse_ratei :intfloat
        Return the value of the reverse (back) rate constant of the i-th reaction

        :param i:   The integer index (0-based) to identify the reaction of interest
        :return:    The value of the reverse (back) rate constant for the above reaction
        
nameargumentsreturns
get_chemicals_in_reactionrxn_index :int{int}
        Return a SET of indices (being a set, they're NOT in any particular order)
        of all the chemicals participating in the i-th reaction

        :param rxn_index:   An integer with the (zero-based) index to identify the reaction of interest
        :return:            A SET of indices of the chemicals involved in the above reaction
                                Note: being a set, it's NOT in any particular order
        
nameargumentsreturns
get_chemicals_indexes_in_reactionrxn_index :int[int]
        Return a sorted list of the indexes
        of all the chemicals participating in the i-th reaction

        :param rxn_index:   An integer with the (zero-based) index to identify the reaction of interest
        :return:            A sorted list of indices of the chemicals involved in the above reaction
        
nameargumentsreturns
get_reactions_participating_inchem_label :str, side :strlist
        Return a list of all the reactions that the given chemical species
        is involved in

        :param chem_label:
        :param side:        Either "left" or "right"
        :return:            List of varius types of "Reaction" objects
        
nameargumentsreturns
add_elementary_reactionreactants :str|list, products :str|list, reaction_type=None, temp=None, **kwargsint
        Create and register a new SINGLE elementary chemical reaction,
        optionally including its kinetic and/or thermodynamic data.
        All the involved chemicals can be either previously registered, or not.

        :param reactants:       A string or pair of strings; for reactions such as 2 A -> P, pass ["A", "A"]
        :param products:        A string or pair of strings; for reactions such as A -> 2 P, pass ["P", "P"]
        :param reaction_type:   A string with one of the following values:
                                    "ReactionUnimolecular", "ReactionSynthesis", "ReactionDecomposition"

        :param temp:            [OPTIONAL] Temperature in Kelvins
        :param kwargs:          [OPTIONAL] Other named arguments to pass to instantiate the various reaction
                                objects, such as `ReactionSynthesis`.
                                For list, see documentation of the classes in reactions.py

        :return:                Integer index of the newly-added reaction
                                    (in the list self.reaction_list, stored as object variable)
        
nameargumentsreturns
add_reactionreactants :str|list, products :str|list, kF=None, kR=None, enzyme=None, k1_F=None, k1_R=None, k2_F=None, temp=None, **kwargsint
        Create and register a new SINGLE chemical reaction,
        optionally including its kinetic and/or thermodynamic data.
        All the involved chemicals can be either previously registered, or not.

        NOTE: in the reactants and products, if the stoichiometry coefficients aren't specified,
              they're assumed to be 1.

              The full structure of each term in the list of reactants and of products
              is the pair:  (stoichiometry coefficient, chemical label)

              EXAMPLES of formats to use for each term in the lists of the reactants and of the products:
                "F"         is taken to mean (1, "F") - default stoichiometry
                (2, "F")    is taken to mean (2, "F") - stoichiometry coefficient specified

              It's equally acceptable to use LISTS in lieu of tuples for the pairs

        :param reactants:       A string or list of pairs (stoichiometry, species name),
                                    or simplified terms in various formats; for details, see above
        :param products:        A string or list of pairs (stoichiometry, species name),
                                    or simplified terms in various formats; for details, see above

        :param temp:            [OPTIONAL] Temperature in Kelvins
        :param kwargs:          [OPTIONAL] Other named arguments to pass to instantiate the various reaction
                                objects, such as `ReactionSynthesis`.
                                For list, see documentation of the classes in reactions.py

        :return:                Integer index of the newly-added reaction
                                    (in the list self.reaction_list, stored as object variable)
        
nameargumentsreturns
register_reactionrxn, temp=Noneint
        Register a SINGLE chemical reaction from its reaction-specific object,
        and set all its kinetic and/or thermodynamic data from the available information,
        including the value of the temperature (stored in object variable.)

        All the involved chemicals can be either previously registered, or not;
        if not, they will get automatically registered.

        :param rxn: Object of one of the specific Reaction classes, such as
                        ReactionUnimolecular, ReactionSynthesis, ReactionDecomposition,
                        ReactionEnz, ReactionGeneric
        :param temp:Temperature in degree Kelvin

        :return:    Integer index of the newly-added reaction
                        (in the list self.reaction_list, stored as object variable)
        
nameargumentsreturns
clear_reactions_dataNone
        Get rid of all the reactions; start again with "an empty slate" (but still with reference
        to the same data object about the chemicals and their properties)

        :return:    None
        

DESCRIBE RXNS

nameargumentsreturns
describe_reactionsconcise=FalseNone
        Print out a user-friendly plain-text form of ALL the reactions.
        If wanting to describe just 1 reaction, use single_reaction_describe()

        EXAMPLE (not concise):
            Number of reactions: 2
            (0) CH4 + 2 O2 <-> CO2 + 2 H2O  (kF = 3.0 / kR = 2.0 / Delta_G = -1,005.13 / K = 1.5) | 1st order in all reactants & products
            (1) A + B <-> C  (kF = 5.0 / kR = 1.0 / Delta_G =  / K = 5.0) | 1st order in all reactants & products
            Chemicals involved in the above reactions: {'CH4', 'O2', 'H2O', 'A', 'B', 'C'}

        :param concise:     If True, less detail is shown
        :return:            None
        
nameargumentsreturns
multiple_reactions_describerxn_list=None, concise=False[str]
        The counterpart of single_reaction_describe() for many reactions.
        Return a list of strings, each string being a (concise or not) user-friendly plain-text form of
        each of the reactions

        :param rxn_list:    Either a list of integers, to identify the reactions of interest,
                                or None, meaning ALL reactions
        :param concise:     If True, less detail is shown
        :return:            A list of strings; each string is the description of one of the reactions
        
nameargumentsreturns
single_reaction_describerxn_index: int, concise=Falsestr
        Return as a string, a user-friendly plain-text form of the given reaction
        EXAMPLE (concise):      "CH4 + 2 O2 <-> CO2 + 2 H2O"
        EXAMPLE (not concise):  "CH4 + 2 O2 <-> CO2 + 2 H2O  (kF = 3.0 / kR = 2.0 / Delta_G = -1,005.13 / K = 1.5) | 1st order in all reactants & products"

        :param rxn_index:   Integer to identify the reaction of interest
        :param concise:     If True, less detail is shown
        :return:            A string with a description of the specified reaction
        
nameargumentsreturns
labels_of_active_chemicalssort_by_index=False[str]
        Return a list of the labels of all the chemicals
        involved in ANY of the registered reactions,
        but NOT counting chemicals that always appear
        in a catalytic role in all the reactions they participate in
        (if a chemical participates in a non-catalytic role in ANY reaction, it'll appear here)

        The list is not in any particular order, unless sort_by_index is True

        :param sort_by_index:   If True, the list is sorted by the index (order of registration)
                                    of the chemicals in it
        :return:                A set of chemical labels
        
nameargumentsreturns
number_of_active_chemicalsint
        Return the number of all the chemicals
        involved in ANY of the registered reactions,
        but NOT counting chemicals that always appear
        in a catalytic role in all the reactions they participate in
        (if a chemical participates in a non-catalytic role in ANY reaction, it'll appear here)
        
nameargumentsreturns
indexes_of_active_chemicals[int]
        Return the ordered list (numerically sorted) of the INDEX numbers of all the chemicals
        involved in ANY of the registered reactions,
        but NOT counting chemicals that always appear in a catalytic role in all the reactions they
        participate in
        (if a chemical participates in a non-catalytic role in ANY reaction, it'll appear here.)

        EXAMPLE: [2, 7, 8]  if only those 3 chemicals (with indexes of, respectively, 2, 7 and 8)
                            are actively involved in ANY of the registered reactions

        CAUTION: the concept of "active chemical" might change in future versions, where only SOME of
                 the reactions are simulated
        

NETWORK DIAGRAMS

nameargumentsreturns
prepare_graph_networkdict
        Prepare and return a data structure with chemical-reaction data in a network format,
        ready to be passed to the front end, for network-diagram visualization with the Cytoscape.js library
        (in the graph module "vue_cytoscape")

        4 parts are generated, and assembled together as a dictionary with 4 keys: 'nodes', 'edges', 'color_mapping', 'caption_mapping'

        EXAMPLE of the 'nodes' structure part of the returned object for an  A <-> B reaction:
           [{'id': 'C-0', 'labels': ['Chemical'], 'name': 'A', 'diff_rate': None},
            {'id': 'C-1', 'labels': ['Chemical'], 'name': 'B', 'diff_rate': None},

            {'id': 'R-0', 'labels': ['Reaction'], 'name': 'RXN', 'kF': 3.0, 'kR': 2.0, 'K': 1.5, 'Delta_G': -1005.13}
           ]

        EXAMPLE of the 'edges' structure part of the returned object for that same  A <-> B reaction:
           [
            {'id': 'edge-1', 'name': 'produces', 'source': 'R-0', 'target': 'C-1', 'stoich': 1, 'rxn_order': 1},
            {'id': 'edge-2', 'name': 'reacts',   'source': 'C-0', 'target': 'R-0', 'stoich': 1, 'rxn_order': 1}
           ]

        EXAMPLE of `color_mapping`:     {'Chemical': '#8DCC92', 'Reaction': '#D9C8AD'},
        EXAMPLE of `caption_mapping`:   {'Chemical': 'name', 'Reaction': 'name'}}

        :return:    A dictionary with 4 keys: 'nodes', 'edges', 'color_mapping', 'caption_mapping'
        
nameargumentsreturns
plot_reaction_networklog_file :str, graphic_component="vue_cytoscape_5"None
        Send a plot of the network of reactions to the HTML log file,
        also including a brief summary of all the reactions.

        :param log_file:            The name of the file into which to place the HTML code
                                        to create the interactive network plot.
                                        The suffix ".htm" will be added if it doesn't end with ".htm" or ".html"
                                        If the file already exists, it will get overwritten.
                                        (Note: this file will automatically include an internal reference to the JavaScript
                                        file specified in `graphic_component`)
        :param graphic_component:   The name of a Vue component that accepts a "graph_data" argument,
                                        an object with the following keys
                                        'nodes', 'edges', 'color_mapping' and 'caption_mapping
                                        For more details, see prepare_graph_network()

        :return:                    None