biocrnpyler.ChemicalReactionNetwork

class biocrnpyler.ChemicalReactionNetwork(species: List[Species], reactions: List[Reaction], initial_concentration_dict: Dict[Species, Real | Parameter] = None, show_warnings=False)[source]

Network of reactions between a set of species.

A chemical reaction network is a container of species and reactions chemical reaction networks can be compiled into SBML.

reaction types: mass action: standard mass action semantics where the propensity of a reaction is given by deterministic propensity = .. math:: k Prod_{inputs i} [S_i]^a_i stochastic propensity = .. math:: k Prod_{inputs i} (S_i)!/(S_i - a_i)! where a_i is the spectrometric coefficient of species i

__init__(species: List[Species], reactions: List[Reaction], initial_concentration_dict: Dict[Species, Real | Parameter] = None, show_warnings=False)[source]

Methods

__init__(species, reactions[, ...])

add_reactions(reactions[, copy_reactions, ...])

Adds a reaction or a list of reactions to the CRN object

add_species(species[, copy_species, compartment])

Adds a Species or a list of Species to the CRN object

check_crn_validity(reactions, species[, ...])

Checks that the given list of reactions and list of species can form a valid CRN.

generate_sbml_model([stochastic_model, ...])

Creates an new SBML model and populates with the species and reactions in the ChemicalReactionNetwork object

get_all_species_containing(species[, ...])

Returns all species (complexes and otherwise) containing a given species (or string).

initial_condition_vector(init_cond_dict)

pretty_print([show_rates, show_material, ...])

A more powerful printing function.

replace_species(species, new_species)

Replaces species with new_species in the entire CRN.

simulate_with_bioscrape(timepoints[, ...])

Simulate CRN model with bioscrape (https://github.com/biocircuits/bioscrape).

simulate_with_bioscrape_via_sbml(timepoints)

Simulate CRN model with bioscrape via writing a SBML file temporarily.

simulate_with_roadrunner(timepoints[, ...])

To simulate using roadrunner.

write_sbml_file([file_name, ...])

"Writes CRN object to a SBML file

Attributes

initial_concentration_dict

reactions

species

add_reactions(reactions: Reaction | List[Reaction], copy_reactions=True, add_species=True, compartment=None) None[source]

Adds a reaction or a list of reactions to the CRN object

Parameters:
  • reactions – Reaction instance or list of Reaction instances

  • copy_reactions – whether to deep copy reactions before adding them to the CRN. Protects CRN validity at the expense of speed.

  • add_species – whether to add species in reactions to the CRN. Prevents errors at the expense of speed.

Returns:

None

add_species(species, copy_species=True, compartment=None)[source]

Adds a Species or a list of Species to the CRN object

Parameters:
  • species – Species instance or list of Species instances

  • copy_species – whether to deep copy Species added to the CRN. Protects CRN validity at teh expense of speed.

static check_crn_validity(reactions: List[Reaction], species: List[Species], show_warnings=True) Tuple[List[Reaction], List[Species]][source]

Checks that the given list of reactions and list of species can form a valid CRN.

Parameters:
  • reactions – list of reaction

  • species – list of species

  • show_warnings – whether to show warning when duplicated reactions/species was found

Returns:

tuple(reaction,species)

generate_sbml_model(stochastic_model=False, show_warnings=False, check_validity=True, **keywords)[source]

Creates an new SBML model and populates with the species and reactions in the ChemicalReactionNetwork object

Parameters:
  • stochastic_model – whether the model is stochastic

  • show_warnings – of from check crn validity

  • keywords – extra keywords pass onto create_sbml_model() and add_all_reactions()

Returns:

tuple: (document,model) SBML objects

get_all_species_containing(species: Species, return_as_strings=False)[source]

Returns all species (complexes and otherwise) containing a given species (or string).

pretty_print(show_rates=True, show_material=True, show_attributes=True, show_initial_concentration=True, show_keys=True, show_compartment=False, **kwargs)[source]

A more powerful printing function.

Useful for understanding CRNs but does not return string identifiers. show_material toggles whether species.material is printed. show_attributes toggles whether species.attributes is printed show_rates toggles whether reaction rate functions are printed show_compartment toggles whether species.compartment is printed

replace_species(species: Species, new_species: Species)[source]

Replaces species with new_species in the entire CRN.

Does not act in place: returns a new CRN.

simulate_with_bioscrape(timepoints, initial_condition_dict=None, stochastic=False, return_dataframe=True, safe=False)[source]

Simulate CRN model with bioscrape (https://github.com/biocircuits/bioscrape). Returns the data for all species as Pandas dataframe.

simulate_with_bioscrape_via_sbml(timepoints, filename=None, initial_condition_dict=None, return_dataframe=True, stochastic=False, safe=False, return_model=False, check_validity=True, **kwargs)[source]

Simulate CRN model with bioscrape via writing a SBML file temporarily. [Bioscrape on GitHub](https://github.com/biocircuits/bioscrape).

Returns the data for all species as Pandas dataframe.

simulate_with_roadrunner(timepoints: List[float], initial_condition_dict: Dict[str, float] = None, return_roadrunner=False, check_validity=True)[source]

To simulate using roadrunner. Arguments: timepoints: The array of time points to run the simulation for. initial_condition_dict:

Returns the results array as returned by RoadRunner OR a Roadrunner model object.

Refer to the libRoadRunner simulator library documentation for details on simulation results: (http://libroadrunner.org/)[http://libroadrunner.org/] NOTE : Needs roadrunner package installed to simulate.

write_sbml_file(file_name=None, stochastic_model=False, check_validity=True, **keywords) bool[source]

“Writes CRN object to a SBML file

Parameters:
  • file_name – name of the file where the SBML model gets written

  • stochastic_model – export an SBML file which ready for stochastic simulations

  • keywords – keywords that passed into generate_sbml_model()

Returns:

bool, show whether the writing process was successful