{
"cells": [
{
"cell_type": "markdown",
"id": "36af7001",
"metadata": {},
"source": [
"# PyCoMo Maximum Growth-Rate #\n",
"This tutorial show-cases how to find the maximum growth-rate of a community - across all possible abundance profiles.\n",
"\n",
"The expected runtime for this notebook is less than 10 minutes."
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "2cadb7fd-5d68-4c2b-b803-d6c39ebbf828",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"from pathlib import Path\n",
"import sys\n",
"import os\n",
"import cobra\n",
"import math \n",
"import time\n",
"import warnings"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "30fa3103-2733-43c7-800a-14db6486fe3e",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"2025-02-11 16:57:51,049 - pycomo - INFO - Logger initialized.\n",
"2025-02-11 16:57:51,051 - pycomo - INFO - Process Pool Logger initialized.\n",
"2025-02-11 16:57:51,051 - pycomo - INFO - Utils Logger initialized.\n",
"2025-02-11 16:57:51,053 - pycomo - INFO - Multiprocess Logger initialized.\n",
"2025-02-11 16:57:51,054 - pycomo - INFO - Log level set to info\n"
]
}
],
"source": [
"path_root = \"../src\" # Change path according to your PyCoMo location\n",
"sys.path.append(str(path_root))\n",
"import pycomo\n",
"pycomo.configure_logger(level=\"info\")"
]
},
{
"cell_type": "markdown",
"id": "686051ed",
"metadata": {},
"source": [
"## Load the Toy Models ##\n",
"These are simple toy models of 2 organisms. In a community, they are expexted to grow at a maximum of 10/h, however one organism alone can grow as fast as 15/h. Both cases can be calculated."
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "3d8fef41-c444-4888-a560-b0f8c444d4e3",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"# create two cobra models from sbml (change the path according to where the models are located)\n",
"toy1 = cobra.io.read_sbml_model(\"../data/use_case/toy_models/toy_1.xml\")\n",
"toy2 = cobra.io.read_sbml_model(\"../data/use_case/toy_models/toy_2_2.xml\")\n",
"\n",
"# create Single Organism Models from cobra models\n",
"Toy1 = pycomo.SingleOrganismModel(toy1, \"toy1\")\n",
"Toy2 = pycomo.SingleOrganismModel(toy2, \"toy2\")\n",
"\n",
"# create Community Model from Single Organism Models\n",
"C = pycomo.CommunityModel([Toy1, Toy2], name = \"Toy_community\")\n",
"# instantiate the model and set cplex as a solver (if available)\n",
"#C.model.solver = \"cplex\""
]
},
{
"cell_type": "markdown",
"id": "8a5e3d76-7f16-4e9d-8c30-a08bce46d809",
"metadata": {},
"source": [
"## Compute maximum community growth rate\n",
"\n",
"The method ```max_growth_rate``` calculates the overall maximum growth rate of the community, regardless of its composition."
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "4ffa3cd7-ab7f-46ec-af13-1b833c74bbbd",
"metadata": {
"scrolled": true,
"tags": []
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"2025-02-11 16:57:51,118 - pycomo - INFO - No community model generated yet. Generating now:\n",
"2025-02-11 16:57:51,126 - pycomo - INFO - Identified biomass reaction from objective: R4\n",
"2025-02-11 16:57:51,146 - pycomo - INFO - Identified biomass reaction from objective: R4\n",
"2025-02-11 16:57:51,207 - pycomo - WARNING - Not all reactions in the model are mass and charge balanced. To check which reactions are imbalanced, please run the get_unbalanced_reactions method of this CommunityModel object\n",
"2025-02-11 16:57:51,209 - pycomo - INFO - Generated community model.\n",
"2025-02-11 16:57:51,212 - pycomo - INFO - New round: lb: 0.0, ub: 1000.0, x: 2e-06\n",
"2025-02-11 16:57:52,205 - pycomo - INFO - Logger initialized.\n",
"2025-02-11 16:57:52,206 - pycomo - INFO - Process Pool Logger initialized.\n",
"2025-02-11 16:57:52,206 - pycomo - INFO - Utils Logger initialized.\n",
"2025-02-11 16:57:52,208 - pycomo - INFO - Multiprocess Logger initialized.\n",
"2025-02-11 16:57:52,217 - pycomo - INFO - Logger initialized.\n",
"2025-02-11 16:57:52,217 - pycomo - INFO - Process Pool Logger initialized.\n",
"2025-02-11 16:57:52,218 - pycomo - INFO - Utils Logger initialized.\n",
"2025-02-11 16:57:52,219 - pycomo - INFO - Multiprocess Logger initialized.\n",
"2025-02-11 16:57:52,237 - pycomo - INFO - Log level set to 20\n",
"2025-02-11 16:57:52,242 - pycomo - INFO - Processed 100.0% of fva steps\n",
"2025-02-11 16:57:52,261 - pycomo - INFO - New round: lb: 10.0, ub: 1000.0, x: 10.000002\n",
"2025-02-11 16:57:53,214 - pycomo - INFO - Logger initialized.\n",
"2025-02-11 16:57:53,214 - pycomo - INFO - Process Pool Logger initialized.\n",
"2025-02-11 16:57:53,214 - pycomo - INFO - Utils Logger initialized.\n",
"2025-02-11 16:57:53,214 - pycomo - INFO - Logger initialized.\n",
"2025-02-11 16:57:53,215 - pycomo - INFO - Process Pool Logger initialized.\n",
"2025-02-11 16:57:53,215 - pycomo - INFO - Utils Logger initialized.\n",
"2025-02-11 16:57:53,216 - pycomo - INFO - Multiprocess Logger initialized.\n",
"2025-02-11 16:57:53,217 - pycomo - INFO - Multiprocess Logger initialized.\n",
"2025-02-11 16:57:53,246 - pycomo - INFO - Log level set to 20\n",
"2025-02-11 16:57:53,247 - pycomo - INFO - Log level set to 20\n",
"2025-02-11 16:57:53,248 - pycomo - INFO - Processed 100.0% of fva steps\n",
"2025-02-11 16:57:53,267 - pycomo - INFO - New round: lb: 15.000000000000002, ub: 1000.0, x: 15.000002000000002\n",
"2025-02-11 16:57:54,245 - pycomo - INFO - Logger initialized.\n",
"2025-02-11 16:57:54,246 - pycomo - INFO - Process Pool Logger initialized.\n",
"2025-02-11 16:57:54,246 - pycomo - INFO - Utils Logger initialized.\n",
"2025-02-11 16:57:54,248 - pycomo - INFO - Multiprocess Logger initialized.\n",
"2025-02-11 16:57:54,253 - pycomo - INFO - Logger initialized.\n",
"2025-02-11 16:57:54,254 - pycomo - INFO - Process Pool Logger initialized.\n",
"2025-02-11 16:57:54,255 - pycomo - INFO - Utils Logger initialized.\n",
"2025-02-11 16:57:54,256 - pycomo - INFO - Multiprocess Logger initialized.\n",
"2025-02-11 16:57:54,277 - pycomo - INFO - Log level set to 20\n",
"2025-02-11 16:57:54,281 - pycomo - INFO - Processed 100.0% of fva steps\n",
"2025-02-11 16:57:54,301 - pycomo - WARNING - Upper and lower bounds do not allow abundances to sum up to 1: toy1_fraction_reaction 0.0\n",
"toy2_fraction_reaction 0.0\n",
"Name: max_flux, dtype: float64, toy1_fraction_reaction 0\n",
"toy2_fraction_reaction 0\n",
"Name: min_flux, dtype: int64\n",
"2025-02-11 16:57:54,302 - pycomo - INFO - New round: lb: 15.000000000000002, ub: 15.000002000000002, x: 15.000001000000001\n",
"2025-02-11 16:57:55,252 - pycomo - INFO - Logger initialized.\n",
"2025-02-11 16:57:55,253 - pycomo - INFO - Process Pool Logger initialized.\n",
"2025-02-11 16:57:55,253 - pycomo - INFO - Utils Logger initialized.\n",
"2025-02-11 16:57:55,256 - pycomo - INFO - Multiprocess Logger initialized.\n",
"2025-02-11 16:57:55,284 - pycomo - INFO - Log level set to 20\n",
"2025-02-11 16:57:55,289 - pycomo - INFO - Processed 100.0% of fva steps\n",
"2025-02-11 16:57:55,305 - pycomo - WARNING - Upper and lower bounds do not allow abundances to sum up to 1: toy1_fraction_reaction 0.0\n",
"toy2_fraction_reaction 0.0\n",
"Name: max_flux, dtype: float64, toy1_fraction_reaction 0\n",
"toy2_fraction_reaction 0\n",
"Name: min_flux, dtype: int64\n",
"2025-02-11 16:57:55,308 - pycomo - INFO - Maximum growth-rate is 15.0\n"
]
},
{
"data": {
"text/plain": [
"np.float64(15.0)"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"C.max_growth_rate()"
]
},
{
"cell_type": "markdown",
"id": "77e1e1bf-9532-4222-8120-d876fb1a4083",
"metadata": {},
"source": [
"```max_growth_rate``` has the following parameters:\n",
"* ```minimal_abundance``` (default = 0)\n",
"* ```return_abundances``` (default = False)\n",
"* ```sensitivity``` (default = 6)\n",
"* ```gurobi``` (default = False)"
]
},
{
"cell_type": "markdown",
"id": "19981da5-150c-40dc-86d0-9a391082c303",
"metadata": {
"tags": []
},
"source": [
"### Return Abundances\n",
"By setting the parameter ```return_abundances``` to ```True```, additional information about the feasible community compositions at the maximum growth rate is returned in the form of a pandas dataframe.\n",
"\n",
"The minimal flux of x_fraction_reaction corresponds to the minimal abundance of member x in the community. Likewise, the maximal flux corresponds to the maximal abundance of member x."
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "ae13806a-8cf2-4ddc-b509-86ba9a2cce7f",
"metadata": {
"scrolled": true,
"tags": []
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"2025-02-11 16:57:55,317 - pycomo - INFO - New round: lb: 0.0, ub: 1000.0, x: 2e-06\n",
"2025-02-11 16:57:56,280 - pycomo - INFO - Logger initialized.\n",
"2025-02-11 16:57:56,280 - pycomo - INFO - Process Pool Logger initialized.\n",
"2025-02-11 16:57:56,280 - pycomo - INFO - Utils Logger initialized.\n",
"2025-02-11 16:57:56,282 - pycomo - INFO - Multiprocess Logger initialized.\n",
"2025-02-11 16:57:56,297 - pycomo - INFO - Logger initialized.\n",
"2025-02-11 16:57:56,298 - pycomo - INFO - Process Pool Logger initialized.\n",
"2025-02-11 16:57:56,298 - pycomo - INFO - Utils Logger initialized.\n",
"2025-02-11 16:57:56,299 - pycomo - INFO - Multiprocess Logger initialized.\n",
"2025-02-11 16:57:56,312 - pycomo - INFO - Log level set to 20\n",
"2025-02-11 16:57:56,315 - pycomo - INFO - Processed 100.0% of fva steps\n",
"2025-02-11 16:57:56,333 - pycomo - INFO - New round: lb: 10.0, ub: 1000.0, x: 10.000002\n",
"2025-02-11 16:57:57,234 - pycomo - INFO - Logger initialized.\n",
"2025-02-11 16:57:57,234 - pycomo - INFO - Process Pool Logger initialized.\n",
"2025-02-11 16:57:57,234 - pycomo - INFO - Utils Logger initialized.\n",
"2025-02-11 16:57:57,236 - pycomo - INFO - Multiprocess Logger initialized.\n",
"2025-02-11 16:57:57,267 - pycomo - INFO - Log level set to 20\n",
"2025-02-11 16:57:57,273 - pycomo - INFO - Processed 100.0% of fva steps\n",
"2025-02-11 16:57:57,291 - pycomo - INFO - New round: lb: 15.000000000000002, ub: 1000.0, x: 15.000002000000002\n",
"2025-02-11 16:57:58,167 - pycomo - INFO - Logger initialized.\n",
"2025-02-11 16:57:58,167 - pycomo - INFO - Process Pool Logger initialized.\n",
"2025-02-11 16:57:58,168 - pycomo - INFO - Utils Logger initialized.\n",
"2025-02-11 16:57:58,169 - pycomo - INFO - Multiprocess Logger initialized.\n",
"2025-02-11 16:57:58,198 - pycomo - INFO - Log level set to 20\n",
"2025-02-11 16:57:58,203 - pycomo - INFO - Processed 100.0% of fva steps\n",
"2025-02-11 16:57:58,219 - pycomo - WARNING - Upper and lower bounds do not allow abundances to sum up to 1: toy1_fraction_reaction 0.0\n",
"toy2_fraction_reaction 0.0\n",
"Name: max_flux, dtype: float64, toy1_fraction_reaction 0\n",
"toy2_fraction_reaction 0\n",
"Name: min_flux, dtype: int64\n",
"2025-02-11 16:57:58,220 - pycomo - INFO - New round: lb: 15.000000000000002, ub: 15.000002000000002, x: 15.000001000000001\n",
"2025-02-11 16:57:59,219 - pycomo - INFO - Logger initialized.\n",
"2025-02-11 16:57:59,219 - pycomo - INFO - Process Pool Logger initialized.\n",
"2025-02-11 16:57:59,220 - pycomo - INFO - Utils Logger initialized.\n",
"2025-02-11 16:57:59,222 - pycomo - INFO - Multiprocess Logger initialized.\n",
"2025-02-11 16:57:59,225 - pycomo - INFO - Logger initialized.\n",
"2025-02-11 16:57:59,226 - pycomo - INFO - Process Pool Logger initialized.\n",
"2025-02-11 16:57:59,226 - pycomo - INFO - Utils Logger initialized.\n",
"2025-02-11 16:57:59,228 - pycomo - INFO - Multiprocess Logger initialized.\n",
"2025-02-11 16:57:59,250 - pycomo - INFO - Log level set to 20\n",
"2025-02-11 16:57:59,255 - pycomo - INFO - Processed 100.0% of fva steps\n",
"2025-02-11 16:57:59,271 - pycomo - WARNING - Upper and lower bounds do not allow abundances to sum up to 1: toy1_fraction_reaction 0.0\n",
"toy2_fraction_reaction 0.0\n",
"Name: max_flux, dtype: float64, toy1_fraction_reaction 0\n",
"toy2_fraction_reaction 0\n",
"Name: min_flux, dtype: int64\n",
"2025-02-11 16:58:00,294 - pycomo - INFO - Logger initialized.\n",
"2025-02-11 16:58:00,295 - pycomo - INFO - Process Pool Logger initialized.\n",
"2025-02-11 16:58:00,295 - pycomo - INFO - Utils Logger initialized.\n",
"2025-02-11 16:58:00,296 - pycomo - INFO - Multiprocess Logger initialized.\n",
"2025-02-11 16:58:00,325 - pycomo - INFO - Logger initialized.\n",
"2025-02-11 16:58:00,325 - pycomo - INFO - Process Pool Logger initialized.\n",
"2025-02-11 16:58:00,325 - pycomo - INFO - Utils Logger initialized.\n",
"2025-02-11 16:58:00,327 - pycomo - INFO - Multiprocess Logger initialized.\n",
"2025-02-11 16:58:00,328 - pycomo - INFO - Log level set to 20\n",
"2025-02-11 16:58:00,332 - pycomo - INFO - Processed 100.0% of fva steps\n",
"2025-02-11 16:58:00,346 - pycomo - INFO - Maximum growth-rate is reaction_id min_flux max_flux\n",
"0 toy1_fraction_reaction 0.0 0.0\n",
"1 toy2_fraction_reaction 1.0 1.0\n",
"2 community_biomass 15.0 15.0\n"
]
},
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" reaction_id | \n",
" min_flux | \n",
" max_flux | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" toy1_fraction_reaction | \n",
" 0.0 | \n",
" 0.0 | \n",
"
\n",
" \n",
" 1 | \n",
" toy2_fraction_reaction | \n",
" 1.0 | \n",
" 1.0 | \n",
"
\n",
" \n",
" 2 | \n",
" community_biomass | \n",
" 15.0 | \n",
" 15.0 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" reaction_id min_flux max_flux\n",
"0 toy1_fraction_reaction 0.0 0.0\n",
"1 toy2_fraction_reaction 1.0 1.0\n",
"2 community_biomass 15.0 15.0"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"C.max_growth_rate(return_abundances=True)"
]
},
{
"cell_type": "markdown",
"id": "ca292ce1-73ba-4c76-9408-e7855d8fc925",
"metadata": {
"tags": []
},
"source": [
"### Minimal abundance\n",
"Edge cases exist in which the highest growth rate of a community is not achieved by a combination of all the members. Instead, one member with an abundance of 100% may achieve the maximum growth rate. \n",
"\n",
"In order to exclude these cases, the parameter ```minimal_abundance``` must be set to a float greater than 0. This sets the minimal abundance of all members to the set float. Take care that the sum of the minimal abundances is not greater than 1, as this will result in an error."
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "5f78e750-989a-4020-993b-436f1cad954e",
"metadata": {
"scrolled": true,
"tags": []
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"2025-02-11 16:58:00,355 - pycomo - INFO - New round: lb: 0.0, ub: 1000.0, x: 2e-06\n",
"2025-02-11 16:58:01,304 - pycomo - INFO - Logger initialized.\n",
"2025-02-11 16:58:01,305 - pycomo - INFO - Process Pool Logger initialized.\n",
"2025-02-11 16:58:01,305 - pycomo - INFO - Utils Logger initialized.\n",
"2025-02-11 16:58:01,307 - pycomo - INFO - Multiprocess Logger initialized.\n",
"2025-02-11 16:58:01,312 - pycomo - INFO - Logger initialized.\n",
"2025-02-11 16:58:01,312 - pycomo - INFO - Process Pool Logger initialized.\n",
"2025-02-11 16:58:01,313 - pycomo - INFO - Utils Logger initialized.\n",
"2025-02-11 16:58:01,314 - pycomo - INFO - Multiprocess Logger initialized.\n",
"2025-02-11 16:58:01,335 - pycomo - INFO - Log level set to 20\n",
"2025-02-11 16:58:01,340 - pycomo - INFO - Processed 100.0% of fva steps\n",
"2025-02-11 16:58:01,357 - pycomo - INFO - New round: lb: 10.0, ub: 1000.0, x: 10.000002\n",
"2025-02-11 16:58:02,281 - pycomo - INFO - Logger initialized.\n",
"2025-02-11 16:58:02,281 - pycomo - INFO - Process Pool Logger initialized.\n",
"2025-02-11 16:58:02,281 - pycomo - INFO - Utils Logger initialized.\n",
"2025-02-11 16:58:02,283 - pycomo - INFO - Multiprocess Logger initialized.\n",
"2025-02-11 16:58:02,313 - pycomo - INFO - Log level set to 20\n",
"2025-02-11 16:58:02,317 - pycomo - INFO - Processed 100.0% of fva steps\n",
"2025-02-11 16:58:02,335 - pycomo - WARNING - Not all upper bounds are bigger than the set minimal abundance:\n",
"toy1_fraction_reaction 0.0\n",
"toy2_fraction_reaction 1.0\n",
"Name: max_flux, dtype: float64\n",
"2025-02-11 16:58:02,335 - pycomo - INFO - New round: lb: 10.0, ub: 10.000002, x: 10.000001000000001\n",
"2025-02-11 16:58:03,265 - pycomo - INFO - Logger initialized.\n",
"2025-02-11 16:58:03,265 - pycomo - INFO - Process Pool Logger initialized.\n",
"2025-02-11 16:58:03,265 - pycomo - INFO - Utils Logger initialized.\n",
"2025-02-11 16:58:03,267 - pycomo - INFO - Multiprocess Logger initialized.\n",
"2025-02-11 16:58:03,276 - pycomo - INFO - Logger initialized.\n",
"2025-02-11 16:58:03,277 - pycomo - INFO - Process Pool Logger initialized.\n",
"2025-02-11 16:58:03,277 - pycomo - INFO - Utils Logger initialized.\n",
"2025-02-11 16:58:03,279 - pycomo - INFO - Multiprocess Logger initialized.\n",
"2025-02-11 16:58:03,295 - pycomo - INFO - Log level set to 20\n",
"2025-02-11 16:58:03,298 - pycomo - INFO - Processed 100.0% of fva steps\n",
"2025-02-11 16:58:03,313 - pycomo - WARNING - Not all upper bounds are bigger than the set minimal abundance:\n",
"toy1_fraction_reaction 0.0\n",
"toy2_fraction_reaction 1.0\n",
"Name: max_flux, dtype: float64\n",
"2025-02-11 16:58:03,314 - pycomo - INFO - New round: lb: 10.0, ub: 10.000001000000001, x: 10.0000005\n",
"2025-02-11 16:58:04,201 - pycomo - INFO - Logger initialized.\n",
"2025-02-11 16:58:04,201 - pycomo - INFO - Process Pool Logger initialized.\n",
"2025-02-11 16:58:04,201 - pycomo - INFO - Utils Logger initialized.\n",
"2025-02-11 16:58:04,203 - pycomo - INFO - Multiprocess Logger initialized.\n",
"2025-02-11 16:58:04,206 - pycomo - INFO - Logger initialized.\n",
"2025-02-11 16:58:04,206 - pycomo - INFO - Process Pool Logger initialized.\n",
"2025-02-11 16:58:04,206 - pycomo - INFO - Utils Logger initialized.\n",
"2025-02-11 16:58:04,208 - pycomo - INFO - Multiprocess Logger initialized.\n",
"2025-02-11 16:58:04,228 - pycomo - INFO - Log level set to 20\n",
"2025-02-11 16:58:04,232 - pycomo - INFO - Processed 100.0% of fva steps\n",
"2025-02-11 16:58:04,251 - pycomo - INFO - Maximum growth-rate is 10.0\n"
]
},
{
"data": {
"text/plain": [
"np.float64(10.0)"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"C.max_growth_rate(minimal_abundance=0.1)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "af800adc-ed1a-4db0-aa44-2295b3d5add6",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Error thrown!\n"
]
}
],
"source": [
"# too large minimal_abundance value leads to an error\n",
"try:\n",
" C.max_growth_rate(minimal_abundance=0.6)\n",
"except ValueError:\n",
" print(\"Error thrown!\")\n",
" \n",
"# The community has two members: \n",
"# 2 * 0.6 = 1.2\n",
"# 1.2 > 1"
]
},
{
"cell_type": "markdown",
"id": "221ee104-59a2-4510-a6d8-9f3d8b15b8d3",
"metadata": {},
"source": [
"## Example: Biogas producing community ##\n",
"The example for this part will be a three member community published by Koch et al. 2019 (https://doi.org/10.1371/journal.pcbi.1006759). The three member organisms are representatives of functional guilds in a biogas community."
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "97960ca4-12d8-4ea5-945e-1d080248c86a",
"metadata": {
"scrolled": true,
"tags": []
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"'3PG' is not a valid SBML 'SId'.\n",
"'2PG' is not a valid SBML 'SId'.\n",
"'2PG__PEP' is not a valid SBML 'SId'.\n",
"'3PG__2PG' is not a valid SBML 'SId'.\n",
"'0Pyr__AcCoA' is not a valid SBML 'SId'.\n",
"'5CHOMPT' is not a valid SBML 'SId'.\n",
"'3PG' is not a valid SBML 'SId'.\n",
"'2PG' is not a valid SBML 'SId'.\n",
"'2PG__3PG' is not a valid SBML 'SId'.\n",
"'3PG__DPG' is not a valid SBML 'SId'.\n",
"'5CHOMPT__CHH4MPT' is not a valid SBML 'SId'.\n",
"'3PG' is not a valid SBML 'SId'.\n",
"'2PG' is not a valid SBML 'SId'.\n",
"'5CHOMPT' is not a valid SBML 'SId'.\n",
"'3PG__2PG__3PG' is not a valid SBML 'SId'.\n",
"'5CHOMPT__CHH4MPT' is not a valid SBML 'SId'.\n",
"2025-02-11 16:58:04,460 - pycomo - INFO - No community model generated yet. Generating now:\n",
"2025-02-11 16:58:04,473 - pycomo - INFO - Identified biomass reaction from objective: r_BMDV2BMc\n",
"2025-02-11 16:58:04,607 - pycomo - INFO - Identified biomass reaction from objective: BM_Synth\n",
"2025-02-11 16:58:04,798 - pycomo - INFO - Identified biomass reaction from objective: BM_Synth\n",
"2025-02-11 16:58:05,046 - pycomo - WARNING - No annotation overlap found for matching several metabolites (8). Please make sure that the matched metabolites are indeed representing the same substance in all models! The list of metaboliteswithout annotation overlap can be accessed via 'model.no_annotation_overlap'\n",
"2025-02-11 16:58:05,117 - pycomo - INFO - Generated community model.\n"
]
}
],
"source": [
"# create cobra models from sbml\n",
"dv = cobra.io.read_sbml_model(\"../data/use_case/koch/dv.xml\")\n",
"mh = cobra.io.read_sbml_model(\"../data/use_case/koch/mh.xml\")\n",
"mb = cobra.io.read_sbml_model(\"../data/use_case/koch/mb.xml\")\n",
"\n",
"# change infinite upper bounds to 1000\n",
"for model in [dv,mh,mb]:\n",
" for reaction in model.reactions:\n",
" if reaction.upper_bound == math.inf:\n",
" reaction.upper_bound = 1000.\n",
" if reaction.lower_bound == -math.inf:\n",
" reaction.lower_bound = -1000.\n",
"\n",
"# create Single Organism Models from cobra models\n",
"DV = pycomo.SingleOrganismModel(dv, \"dv\")\n",
"MH = pycomo.SingleOrganismModel(mh, \"mh\")\n",
"MB = pycomo.SingleOrganismModel(mb, \"mb\")\n",
"\n",
"# create Community Model from Single Organism Models\n",
"C2 = pycomo.CommunityModel([DV, MH, MB], name = \"dv_mh_mb_community\")\n",
"\n",
"# set solver to cplex (if available)\n",
"#C2.model.solver = \"cplex\"\n",
"\n",
"# apply the same medium as in the paper by Koch et al.\n",
"medium = {\n",
" 'EX_CO2_EX_medium': 1000.0,\n",
" 'EX_Eth_EX_medium': 1000.0,\n",
" 'EX_BM_tot_medium': 1000.0\n",
"}\n",
"C2.medium = medium\n",
"C2.apply_medium()\n",
"\n",
"# Formate and Hydrogen are not allowed to accumulate in the medium.\n",
"C2.model.reactions.get_by_id(\"EX_Form_EX_medium\").upper_bound = 0.\n",
"C2.model.reactions.get_by_id(\"EX_H2_EX_medium\").upper_bound = 0.\n"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "46812556-3d00-40bb-8fc2-30940ad18269",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"2025-02-11 16:58:05,131 - pycomo - INFO - New round: lb: 0.0, ub: 1000.0, x: 2e-06\n",
"2025-02-11 16:58:06,131 - pycomo - INFO - Logger initialized.\n",
"2025-02-11 16:58:06,131 - pycomo - INFO - Process Pool Logger initialized.\n",
"2025-02-11 16:58:06,131 - pycomo - INFO - Utils Logger initialized.\n",
"2025-02-11 16:58:06,133 - pycomo - INFO - Multiprocess Logger initialized.\n",
"2025-02-11 16:58:06,234 - pycomo - INFO - Log level set to 20\n",
"2025-02-11 16:58:06,999 - pycomo - INFO - Logger initialized.\n",
"2025-02-11 16:58:07,000 - pycomo - INFO - Process Pool Logger initialized.\n",
"2025-02-11 16:58:07,000 - pycomo - INFO - Utils Logger initialized.\n",
"2025-02-11 16:58:07,001 - pycomo - INFO - Multiprocess Logger initialized.\n",
"2025-02-11 16:58:07,100 - pycomo - INFO - Log level set to 20\n",
"2025-02-11 16:58:08,108 - pycomo - INFO - Logger initialized.\n",
"2025-02-11 16:58:08,109 - pycomo - INFO - Process Pool Logger initialized.\n",
"2025-02-11 16:58:08,109 - pycomo - INFO - Utils Logger initialized.\n",
"2025-02-11 16:58:08,111 - pycomo - INFO - Multiprocess Logger initialized.\n",
"2025-02-11 16:58:08,153 - pycomo - INFO - Processed 100.0% of fva steps\n",
"2025-02-11 16:58:08,214 - pycomo - INFO - New round: lb: 0.05212885425733065, ub: 1000.0, x: 0.052130854257330654\n",
"2025-02-11 16:58:08,290 - pycomo - INFO - New round: lb: 0.05212885425733065, ub: 0.052130854257330654, x: 0.05212985425733065\n",
"2025-02-11 16:58:08,346 - pycomo - INFO - New round: lb: 0.05212885425733065, ub: 0.05212985425733065, x: 0.05212935425733065\n",
"2025-02-11 16:58:09,356 - pycomo - INFO - Logger initialized.\n",
"2025-02-11 16:58:09,357 - pycomo - INFO - Process Pool Logger initialized.\n",
"2025-02-11 16:58:09,357 - pycomo - INFO - Utils Logger initialized.\n",
"2025-02-11 16:58:09,359 - pycomo - INFO - Multiprocess Logger initialized.\n",
"2025-02-11 16:58:09,481 - pycomo - INFO - Log level set to 20\n",
"2025-02-11 16:58:10,201 - pycomo - INFO - Logger initialized.\n",
"2025-02-11 16:58:10,201 - pycomo - INFO - Process Pool Logger initialized.\n",
"2025-02-11 16:58:10,201 - pycomo - INFO - Utils Logger initialized.\n",
"2025-02-11 16:58:10,203 - pycomo - INFO - Multiprocess Logger initialized.\n",
"2025-02-11 16:58:10,319 - pycomo - INFO - Log level set to 20\n",
"2025-02-11 16:58:10,974 - pycomo - INFO - Logger initialized.\n",
"2025-02-11 16:58:10,975 - pycomo - INFO - Process Pool Logger initialized.\n",
"2025-02-11 16:58:10,975 - pycomo - INFO - Utils Logger initialized.\n",
"2025-02-11 16:58:10,976 - pycomo - INFO - Multiprocess Logger initialized.\n",
"2025-02-11 16:58:11,034 - pycomo - INFO - Processed 100.0% of fva steps\n",
"2025-02-11 16:58:11,048 - pycomo - WARNING - Upper and lower bounds do not allow abundances to sum up to 1: dv_fraction_reaction 0.0\n",
"mh_fraction_reaction 0.0\n",
"mb_fraction_reaction 0.0\n",
"Name: max_flux, dtype: float64, dv_fraction_reaction 0\n",
"mh_fraction_reaction 0\n",
"mb_fraction_reaction 0\n",
"Name: min_flux, dtype: int64\n",
"2025-02-11 16:58:11,077 - pycomo - INFO - Maximum growth-rate is 0.052128\n"
]
},
{
"data": {
"text/plain": [
"np.float64(0.052128)"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# calculate max growth rate of community\n",
"C2.max_growth_rate()"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "1cd3c036-ebf1-4cf8-b89b-d6803e94aa16",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"2025-02-11 16:58:11,085 - pycomo - INFO - New round: lb: 0.0, ub: 1000.0, x: 2e-06\n",
"2025-02-11 16:58:12,016 - pycomo - INFO - Logger initialized.\n",
"2025-02-11 16:58:12,016 - pycomo - INFO - Process Pool Logger initialized.\n",
"2025-02-11 16:58:12,016 - pycomo - INFO - Utils Logger initialized.\n",
"2025-02-11 16:58:12,018 - pycomo - INFO - Multiprocess Logger initialized.\n",
"2025-02-11 16:58:12,156 - pycomo - INFO - Log level set to 20\n",
"2025-02-11 16:58:12,937 - pycomo - INFO - Logger initialized.\n",
"2025-02-11 16:58:12,938 - pycomo - INFO - Process Pool Logger initialized.\n",
"2025-02-11 16:58:12,938 - pycomo - INFO - Utils Logger initialized.\n",
"2025-02-11 16:58:12,940 - pycomo - INFO - Multiprocess Logger initialized.\n",
"2025-02-11 16:58:13,042 - pycomo - INFO - Log level set to 20\n",
"2025-02-11 16:58:13,815 - pycomo - INFO - Logger initialized.\n",
"2025-02-11 16:58:13,816 - pycomo - INFO - Process Pool Logger initialized.\n",
"2025-02-11 16:58:13,816 - pycomo - INFO - Utils Logger initialized.\n",
"2025-02-11 16:58:13,818 - pycomo - INFO - Multiprocess Logger initialized.\n",
"2025-02-11 16:58:13,859 - pycomo - INFO - Processed 100.0% of fva steps\n",
"2025-02-11 16:58:13,910 - pycomo - INFO - New round: lb: 0.05212885425733052, ub: 1000.0, x: 0.05213085425733052\n",
"2025-02-11 16:58:13,982 - pycomo - INFO - New round: lb: 0.05212885425733052, ub: 0.05213085425733052, x: 0.05212985425733052\n",
"2025-02-11 16:58:14,020 - pycomo - INFO - New round: lb: 0.05212885425733052, ub: 0.05212985425733052, x: 0.05212935425733052\n",
"2025-02-11 16:58:14,905 - pycomo - INFO - Logger initialized.\n",
"2025-02-11 16:58:14,905 - pycomo - INFO - Process Pool Logger initialized.\n",
"2025-02-11 16:58:14,905 - pycomo - INFO - Utils Logger initialized.\n",
"2025-02-11 16:58:14,907 - pycomo - INFO - Multiprocess Logger initialized.\n",
"2025-02-11 16:58:15,012 - pycomo - INFO - Log level set to 20\n",
"2025-02-11 16:58:15,730 - pycomo - INFO - Logger initialized.\n",
"2025-02-11 16:58:15,731 - pycomo - INFO - Process Pool Logger initialized.\n",
"2025-02-11 16:58:15,731 - pycomo - INFO - Utils Logger initialized.\n",
"2025-02-11 16:58:15,733 - pycomo - INFO - Multiprocess Logger initialized.\n",
"2025-02-11 16:58:15,847 - pycomo - INFO - Log level set to 20\n",
"2025-02-11 16:58:16,571 - pycomo - INFO - Logger initialized.\n",
"2025-02-11 16:58:16,572 - pycomo - INFO - Process Pool Logger initialized.\n",
"2025-02-11 16:58:16,572 - pycomo - INFO - Utils Logger initialized.\n",
"2025-02-11 16:58:16,574 - pycomo - INFO - Multiprocess Logger initialized.\n",
"2025-02-11 16:58:16,651 - pycomo - INFO - Processed 100.0% of fva steps\n",
"2025-02-11 16:58:16,669 - pycomo - WARNING - Upper and lower bounds do not allow abundances to sum up to 1: dv_fraction_reaction 0.0\n",
"mh_fraction_reaction 0.0\n",
"mb_fraction_reaction 0.0\n",
"Name: max_flux, dtype: float64, dv_fraction_reaction 0\n",
"mh_fraction_reaction 0\n",
"mb_fraction_reaction 0\n",
"Name: min_flux, dtype: int64\n",
"2025-02-11 16:58:17,561 - pycomo - INFO - Logger initialized.\n",
"2025-02-11 16:58:17,562 - pycomo - INFO - Process Pool Logger initialized.\n",
"2025-02-11 16:58:17,563 - pycomo - INFO - Utils Logger initialized.\n",
"2025-02-11 16:58:17,565 - pycomo - INFO - Multiprocess Logger initialized.\n",
"2025-02-11 16:58:17,677 - pycomo - INFO - Log level set to 20\n",
"2025-02-11 16:58:18,445 - pycomo - INFO - Logger initialized.\n",
"2025-02-11 16:58:18,446 - pycomo - INFO - Process Pool Logger initialized.\n",
"2025-02-11 16:58:18,446 - pycomo - INFO - Utils Logger initialized.\n",
"2025-02-11 16:58:18,448 - pycomo - INFO - Multiprocess Logger initialized.\n",
"2025-02-11 16:58:18,548 - pycomo - INFO - Log level set to 20\n",
"2025-02-11 16:58:19,277 - pycomo - INFO - Logger initialized.\n",
"2025-02-11 16:58:19,278 - pycomo - INFO - Process Pool Logger initialized.\n",
"2025-02-11 16:58:19,278 - pycomo - INFO - Utils Logger initialized.\n",
"2025-02-11 16:58:19,280 - pycomo - INFO - Multiprocess Logger initialized.\n",
"2025-02-11 16:58:19,316 - pycomo - INFO - Processed 100.0% of fva steps\n",
"2025-02-11 16:58:19,332 - pycomo - INFO - Maximum growth-rate is reaction_id min_flux max_flux\n",
"0 dv_fraction_reaction 0.074553 0.393590\n",
"1 mh_fraction_reaction 0.000000 0.681848\n",
"2 mb_fraction_reaction 0.000000 0.925447\n",
"3 community_biomass 0.052128 0.052128\n"
]
},
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" reaction_id | \n",
" min_flux | \n",
" max_flux | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" dv_fraction_reaction | \n",
" 0.074553 | \n",
" 0.393590 | \n",
"
\n",
" \n",
" 1 | \n",
" mh_fraction_reaction | \n",
" 0.000000 | \n",
" 0.681848 | \n",
"
\n",
" \n",
" 2 | \n",
" mb_fraction_reaction | \n",
" 0.000000 | \n",
" 0.925447 | \n",
"
\n",
" \n",
" 3 | \n",
" community_biomass | \n",
" 0.052128 | \n",
" 0.052128 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" reaction_id min_flux max_flux\n",
"0 dv_fraction_reaction 0.074553 0.393590\n",
"1 mh_fraction_reaction 0.000000 0.681848\n",
"2 mb_fraction_reaction 0.000000 0.925447\n",
"3 community_biomass 0.052128 0.052128"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# calculate abundance profile as well\n",
"C2.max_growth_rate(return_abundances=True)"
]
},
{
"cell_type": "markdown",
"id": "529b5bcb-c4e9-46fc-9de5-4fa1c18ed8c8",
"metadata": {},
"source": [
"### Sensitivity\n",
"\n",
"The ```sensitivity``` parameter describes the amount of decimal places that should be calculated. The default is set to 6, as the cplex solver may return inaccurate results at a higher value."
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "46bbb5fe-c38e-4ccf-93f6-21f555fe5f14",
"metadata": {
"scrolled": true
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"2025-02-11 16:58:19,340 - pycomo - INFO - New round: lb: 0.0, ub: 1000.0, x: 0.0002\n",
"2025-02-11 16:58:20,217 - pycomo - INFO - Logger initialized.\n",
"2025-02-11 16:58:20,218 - pycomo - INFO - Process Pool Logger initialized.\n",
"2025-02-11 16:58:20,218 - pycomo - INFO - Utils Logger initialized.\n",
"2025-02-11 16:58:20,219 - pycomo - INFO - Multiprocess Logger initialized.\n",
"2025-02-11 16:58:20,319 - pycomo - INFO - Log level set to 20\n",
"2025-02-11 16:58:21,085 - pycomo - INFO - Logger initialized.\n",
"2025-02-11 16:58:21,086 - pycomo - INFO - Process Pool Logger initialized.\n",
"2025-02-11 16:58:21,086 - pycomo - INFO - Utils Logger initialized.\n",
"2025-02-11 16:58:21,088 - pycomo - INFO - Multiprocess Logger initialized.\n",
"2025-02-11 16:58:21,193 - pycomo - INFO - Log level set to 20\n",
"2025-02-11 16:58:21,990 - pycomo - INFO - Logger initialized.\n",
"2025-02-11 16:58:21,991 - pycomo - INFO - Process Pool Logger initialized.\n",
"2025-02-11 16:58:21,991 - pycomo - INFO - Utils Logger initialized.\n",
"2025-02-11 16:58:21,993 - pycomo - INFO - Multiprocess Logger initialized.\n",
"2025-02-11 16:58:22,031 - pycomo - INFO - Processed 100.0% of fva steps\n",
"2025-02-11 16:58:22,084 - pycomo - INFO - New round: lb: 0.0521288542573306, ub: 1000.0, x: 0.052328854257330595\n",
"2025-02-11 16:58:22,151 - pycomo - INFO - New round: lb: 0.0521288542573306, ub: 0.052328854257330595, x: 0.05222885425733059\n",
"2025-02-11 16:58:22,221 - pycomo - INFO - Maximum growth-rate is 0.0521\n"
]
},
{
"data": {
"text/plain": [
"np.float64(0.0521)"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# sensitivity = 4\n",
"C2.max_growth_rate(sensitivity=4)"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "7205745a-76dc-4566-b005-bc8f6b70defb",
"metadata": {
"scrolled": true
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"2025-02-11 16:58:22,229 - pycomo - INFO - New round: lb: 0.0, ub: 1000.0, x: 0.02\n",
"2025-02-11 16:58:23,158 - pycomo - INFO - Logger initialized.\n",
"2025-02-11 16:58:23,159 - pycomo - INFO - Process Pool Logger initialized.\n",
"2025-02-11 16:58:23,159 - pycomo - INFO - Utils Logger initialized.\n",
"2025-02-11 16:58:23,161 - pycomo - INFO - Multiprocess Logger initialized.\n",
"2025-02-11 16:58:23,260 - pycomo - INFO - Log level set to 20\n",
"2025-02-11 16:58:24,086 - pycomo - INFO - Logger initialized.\n",
"2025-02-11 16:58:24,087 - pycomo - INFO - Process Pool Logger initialized.\n",
"2025-02-11 16:58:24,087 - pycomo - INFO - Utils Logger initialized.\n",
"2025-02-11 16:58:24,089 - pycomo - INFO - Multiprocess Logger initialized.\n",
"2025-02-11 16:58:24,199 - pycomo - INFO - Log level set to 20\n",
"2025-02-11 16:58:24,972 - pycomo - INFO - Logger initialized.\n",
"2025-02-11 16:58:24,973 - pycomo - INFO - Process Pool Logger initialized.\n",
"2025-02-11 16:58:24,973 - pycomo - INFO - Utils Logger initialized.\n",
"2025-02-11 16:58:24,975 - pycomo - INFO - Multiprocess Logger initialized.\n",
"2025-02-11 16:58:25,014 - pycomo - INFO - Processed 100.0% of fva steps\n",
"2025-02-11 16:58:25,068 - pycomo - INFO - New round: lb: 0.052128854257330645, ub: 1000.0, x: 0.07212885425733065\n",
"2025-02-11 16:58:25,138 - pycomo - INFO - New round: lb: 0.052128854257330645, ub: 0.07212885425733065, x: 0.06212885425733065\n",
"2025-02-11 16:58:25,175 - pycomo - INFO - New round: lb: 0.052128854257330645, ub: 0.06212885425733065, x: 0.05712885425733065\n",
"2025-02-11 16:58:25,243 - pycomo - INFO - Maximum growth-rate is 0.05\n"
]
},
{
"data": {
"text/plain": [
"np.float64(0.05)"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# sensitivity = 2\n",
"C2.max_growth_rate(sensitivity=2)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3e41355c",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.8"
}
},
"nbformat": 4,
"nbformat_minor": 5
}