{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "id": "mkchf6PsO2vs",
    "outputId": "3c5b7a7b-8625-4ebd-8d53-22acb2e6fd68"
   },
   "outputs": [],
   "source": [
    "#pip install cobra"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "id": "ub_5YicIO5US",
    "outputId": "4bec5d9b-f484-410c-f7f1-1d44b09b5682"
   },
   "outputs": [],
   "source": [
    "#pip install escher"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "id": "dHqKQRq3PBq4"
   },
   "outputs": [],
   "source": [
    "import cobra\n",
    "import escher"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 238
    },
    "id": "xSnvqrAxPHfw",
    "outputId": "7d2547a6-f7b4-44c5-98b9-86c42af99bd9"
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Adding exchange reaction EX_S with default bounds for boundary metabolite: S.\n",
      "Adding exchange reaction EX_biomass with default bounds for boundary metabolite: biomass.\n",
      "Adding exchange reaction EX_fuel1 with default bounds for boundary metabolite: fuel1.\n",
      "Adding exchange reaction EX_fuel2 with default bounds for boundary metabolite: fuel2.\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "\n",
       "        <table>\n",
       "            <tr>\n",
       "                <td><strong>Name</strong></td>\n",
       "                <td>toy_model_xml</td>\n",
       "            </tr><tr>\n",
       "                <td><strong>Memory address</strong></td>\n",
       "                <td>0x07fea90b94fd0</td>\n",
       "            </tr><tr>\n",
       "                <td><strong>Number of metabolites</strong></td>\n",
       "                <td>17</td>\n",
       "            </tr><tr>\n",
       "                <td><strong>Number of reactions</strong></td>\n",
       "                <td>22</td>\n",
       "            </tr><tr>\n",
       "                <td><strong>Number of groups</strong></td>\n",
       "                <td>0</td>\n",
       "            </tr><tr>\n",
       "                <td><strong>Objective expression</strong></td>\n",
       "                <td>1.0*R01 - 1.0*R01_reverse_59259</td>\n",
       "            </tr><tr>\n",
       "                <td><strong>Compartments</strong></td>\n",
       "                <td>ext, int</td>\n",
       "            </tr>\n",
       "          </table>"
      ],
      "text/plain": [
       "<Model toy_model_xml at 0x7fea90b94fd0>"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Loading a model\n",
    "model_path = 'toy_model.xml'\n",
    "model = cobra.io.read_sbml_model(model_path)\n",
    "\n",
    "model"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "id": "yjTOtp9FQIwc",
    "outputId": "c17a90f0-752e-469e-97ae-360ce5b5a6d3"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'EX_S': (-100, 0),\n",
       " 'EX_biomass': (0, 1000),\n",
       " 'EX_fuel1': (0, 1000),\n",
       " 'EX_fuel2': (0, 1000)}"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "environmental_conditions = {\n",
    "    'EX_S': (-100, 0),\n",
    "    'EX_biomass': (0, 1000),\n",
    "    'EX_fuel1': (0, 1000),\n",
    "    'EX_fuel2': (0, 1000),\n",
    "\n",
    "}\n",
    "environmental_conditions"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "id": "ZEr9bhxmz9Wd"
   },
   "outputs": [],
   "source": [
    "for reaction_id, bound in environmental_conditions.items():\n",
    "    model.reactions.get_by_id(reaction_id).bounds = bound"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "id": "y12-JuGIS8Op"
   },
   "outputs": [],
   "source": [
    "model.objective='EX_biomass'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 38
    },
    "id": "YMJIZUh3QMf7",
    "outputId": "18af01cc-f666-41f0-c437-6381c67634d5"
   },
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle 1.0 \\cdot EX_{biomass} - 1.0 \\cdot EX_{biomass reverse 91cf2}$"
      ],
      "text/plain": [
       "1.0*EX_biomass - 1.0*EX_biomass_reverse_91cf2"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model.objective.expression"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "id": "65HRA5P8TAKw",
    "outputId": "875ea815-e335-4a82-a9f7-1c08af86faa9"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "EX_S  :  S <-- \n",
      "EX_biomass  :  biomass --> \n",
      "EX_fuel1  :  fuel1 --> \n",
      "EX_fuel2  :  fuel2 --> \n",
      "R01  :  S --> M1\n",
      "R02  :  M1 <=> M2\n",
      "R03  :  M2 --> M3\n",
      "R04  :  M3 <=> M4\n",
      "R05  :  M4 <=> M5\n",
      "R06  :  M3 --> M6\n",
      "R07  :  M6 --> M7\n",
      "R08  :  M7 --> 0.5 M5 + 0.5 M8\n",
      "R09  :  M8 --> fuel1\n",
      "R10  :  M1 <=> M9\n",
      "R11  :  M9 --> M2\n",
      "R12  :  M9 --> M10\n",
      "R13  :  M9 --> M11\n",
      "R14  :  M11 --> 0.7 M12 + 0.3 M13\n",
      "R15  :  M13 --> fuel2\n",
      "R16  :  M12 --> M5\n",
      "R17  :  M5 --> biomass\n",
      "R18  :  M3 --> 2.0 M8\n"
     ]
    }
   ],
   "source": [
    "for i in range(0,len(model.reactions)):\n",
    "    print(model.reactions[i].id,' : ', model.reactions[i].reaction)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "id": "X1-LHOLLQbw8",
    "outputId": "4a8cc89e-9e20-467b-9274-9a7ea9496939"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "EX_S         -100.0\n",
       "EX_biomass    100.0\n",
       "EX_fuel1       -0.0\n",
       "EX_fuel2       -0.0\n",
       "R01           100.0\n",
       "R02           100.0\n",
       "R03           100.0\n",
       "R04           100.0\n",
       "R05           100.0\n",
       "R06             0.0\n",
       "R07             0.0\n",
       "R08             0.0\n",
       "R09             0.0\n",
       "R10             0.0\n",
       "R11             0.0\n",
       "R12             0.0\n",
       "R13             0.0\n",
       "R14             0.0\n",
       "R15             0.0\n",
       "R16             0.0\n",
       "R17           100.0\n",
       "R18             0.0\n",
       "Name: fluxes, dtype: float64"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "solution = model.optimize()\n",
    "solution.fluxes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "lLw4gkj0TL3G"
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 1000
    },
    "id": "3wB6lIQMawti",
    "outputId": "24bdc788-8e29-4207-dc52-5ab851d90d86"
   },
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "194ba233851c4ab9b9b8b6fa2a5267f3",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Builder(reaction_data={'EX_S': -100.0, 'EX_biomass': 100.0, 'EX_fuel1': -0.0, 'EX_fuel2': -0.0, 'R01': 100.0, …"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "builder = escher.Builder(map_json='toy_escher_map.json', model=model, reaction_data=solution.fluxes)\n",
    "#builder.save_html('map2')\n",
    "#from IPython.core.display import display, HTML\n",
    "#display(HTML('map2'))\n",
    "builder"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "id": "ILggVurIax9p",
    "outputId": "08d3c6a5-95b9-4bb1-e203-8bc3c5e867c7"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "EX_S         -100.0\n",
       "EX_biomass     -0.0\n",
       "EX_fuel1      200.0\n",
       "EX_fuel2       -0.0\n",
       "R01           100.0\n",
       "R02           100.0\n",
       "R03           100.0\n",
       "R04             0.0\n",
       "R05             0.0\n",
       "R06             0.0\n",
       "R07             0.0\n",
       "R08             0.0\n",
       "R09           200.0\n",
       "R10             0.0\n",
       "R11             0.0\n",
       "R12             0.0\n",
       "R13             0.0\n",
       "R14             0.0\n",
       "R15             0.0\n",
       "R16             0.0\n",
       "R17             0.0\n",
       "R18           100.0\n",
       "Name: fluxes, dtype: float64"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model.objective='EX_fuel1'\n",
    "solution = model.optimize()\n",
    "solution.fluxes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 1000
    },
    "id": "8GAHi0l0ayYi",
    "outputId": "481141cc-0926-4dd2-909c-3f8c838fdf0c"
   },
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "768d9dc7c302448c93ce3c60b02327fe",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Builder(reaction_data={'EX_S': -100.0, 'EX_biomass': -0.0, 'EX_fuel1': 200.0, 'EX_fuel2': -0.0, 'R01': 100.0, …"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "builder = escher.Builder(map_json='toy_escher_map.json', model=model, reaction_data=solution.fluxes)\n",
    "#builder.save_html('map2')\n",
    "#from IPython.core.display import display, HTML\n",
    "#display(HTML('map2'))\n",
    "builder"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "id": "-5QTzw0_reIt",
    "outputId": "67c488ba-7397-4192-d457-d3eda1569005"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "EX_S         -100.0\n",
       "EX_biomass    100.0\n",
       "EX_fuel1       -0.0\n",
       "EX_fuel2       -0.0\n",
       "R01           100.0\n",
       "R02           100.0\n",
       "R03           100.0\n",
       "R04           100.0\n",
       "R05           100.0\n",
       "R06             0.0\n",
       "R07             0.0\n",
       "R08             0.0\n",
       "R09             0.0\n",
       "R10             0.0\n",
       "R11             0.0\n",
       "R12             0.0\n",
       "R13             0.0\n",
       "R14             0.0\n",
       "R15             0.0\n",
       "R16             0.0\n",
       "R17           100.0\n",
       "R18             0.0\n",
       "Name: fluxes, dtype: float64"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model.objective='EX_biomass'\n",
    "solution = model.optimize()\n",
    "solution.fluxes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 739
    },
    "id": "E917rnQ3ays6",
    "outputId": "15b0c3c5-e1b6-4448-fae4-c4e3a6e83d65"
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>minimum</th>\n",
       "      <th>maximum</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>EX_S</th>\n",
       "      <td>-100.0</td>\n",
       "      <td>-100.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>EX_biomass</th>\n",
       "      <td>100.0</td>\n",
       "      <td>100.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>EX_fuel1</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>EX_fuel2</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>R01</th>\n",
       "      <td>100.0</td>\n",
       "      <td>100.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>R02</th>\n",
       "      <td>-900.0</td>\n",
       "      <td>100.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>R03</th>\n",
       "      <td>100.0</td>\n",
       "      <td>100.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>R04</th>\n",
       "      <td>100.0</td>\n",
       "      <td>100.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>R05</th>\n",
       "      <td>100.0</td>\n",
       "      <td>100.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>R06</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>R07</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>R08</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>R09</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>R10</th>\n",
       "      <td>0.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>R11</th>\n",
       "      <td>0.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>R12</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>R13</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>R14</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>R15</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>R16</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>R17</th>\n",
       "      <td>100.0</td>\n",
       "      <td>100.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>R18</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            minimum  maximum\n",
       "EX_S         -100.0   -100.0\n",
       "EX_biomass    100.0    100.0\n",
       "EX_fuel1        0.0      0.0\n",
       "EX_fuel2        0.0      0.0\n",
       "R01           100.0    100.0\n",
       "R02          -900.0    100.0\n",
       "R03           100.0    100.0\n",
       "R04           100.0    100.0\n",
       "R05           100.0    100.0\n",
       "R06             0.0      0.0\n",
       "R07             0.0      0.0\n",
       "R08             0.0      0.0\n",
       "R09             0.0      0.0\n",
       "R10             0.0   1000.0\n",
       "R11             0.0   1000.0\n",
       "R12             0.0      0.0\n",
       "R13             0.0      0.0\n",
       "R14             0.0      0.0\n",
       "R15             0.0      0.0\n",
       "R16             0.0      0.0\n",
       "R17           100.0    100.0\n",
       "R18             0.0      0.0"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from cobra.flux_analysis import flux_variability_analysis\n",
    "flux_variability_analysis(model)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "id": "ekcssglglXLP"
   },
   "outputs": [],
   "source": [
    "environmental_conditions = {\n",
    "    'R11': (1000, 1000)\n",
    "}\n",
    "for reaction_id, bound in environmental_conditions.items():\n",
    "    model.reactions.get_by_id(reaction_id).bounds = bound"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "id": "3psb5oiNlXgj",
    "outputId": "1a82d2df-7447-47f2-be74-0e2e25b144e7"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "EX_S          -100.0\n",
       "EX_biomass     100.0\n",
       "EX_fuel1        -0.0\n",
       "EX_fuel2        -0.0\n",
       "R01            100.0\n",
       "R02           -900.0\n",
       "R03            100.0\n",
       "R04            100.0\n",
       "R05            100.0\n",
       "R06              0.0\n",
       "R07              0.0\n",
       "R08              0.0\n",
       "R09              0.0\n",
       "R10           1000.0\n",
       "R11           1000.0\n",
       "R12              0.0\n",
       "R13              0.0\n",
       "R14              0.0\n",
       "R15              0.0\n",
       "R16              0.0\n",
       "R17            100.0\n",
       "R18              0.0\n",
       "Name: fluxes, dtype: float64"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "solution = model.optimize()\n",
    "solution.fluxes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 1000
    },
    "id": "xraorRZ5TSKv",
    "outputId": "ab6a17f1-4119-4d53-f0f1-9b64eb8a641c"
   },
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "0c625b3b668841a2bda3355709dacede",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Builder(reaction_data={'EX_S': -100.0, 'EX_biomass': 100.0, 'EX_fuel1': -0.0, 'EX_fuel2': -0.0, 'R01': 100.0, …"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "builder = escher.Builder(map_json='toy_escher_map.json', model=model, reaction_data=solution.fluxes)\n",
    "#builder.save_html('map2')\n",
    "#from IPython.core.display import display, HTML\n",
    "#display(HTML('map2'))\n",
    "builder"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<h3>Objective</h3><p>1.0 EX_fuel1 = 200.0</p><h4>Uptake</h4><table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th>Metabolite</th>\n",
       "      <th>Reaction</th>\n",
       "      <th>Flux</th>\n",
       "      <th>C-Number</th>\n",
       "      <th>C-Flux</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>S</td>\n",
       "      <td>EX_S</td>\n",
       "      <td>100</td>\n",
       "      <td>0</td>\n",
       "      <td>0.00%</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table><h4>Secretion</h4><table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th>Metabolite</th>\n",
       "      <th>Reaction</th>\n",
       "      <th>Flux</th>\n",
       "      <th>C-Number</th>\n",
       "      <th>C-Flux</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>fuel1</td>\n",
       "      <td>EX_fuel1</td>\n",
       "      <td>-200</td>\n",
       "      <td>0</td>\n",
       "      <td>0.00%</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>"
      ],
      "text/plain": [
       "<cobra.summary.model_summary.ModelSummary at 0x7feae92d2880>"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model.objective={model.reactions.EX_fuel1:1}\n",
    "solution = model.optimize()\n",
    "model.summary()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "EX_S         -100.0\n",
       "EX_biomass     -0.0\n",
       "EX_fuel1      200.0\n",
       "EX_fuel2       -0.0\n",
       "R01           100.0\n",
       "R02           100.0\n",
       "R03           100.0\n",
       "R04             0.0\n",
       "R05             0.0\n",
       "R06             0.0\n",
       "R07             0.0\n",
       "R08             0.0\n",
       "R09           200.0\n",
       "R10             0.0\n",
       "R11             0.0\n",
       "R12             0.0\n",
       "R13             0.0\n",
       "R14             0.0\n",
       "R15             0.0\n",
       "R16             0.0\n",
       "R17             0.0\n",
       "R18           100.0\n",
       "Name: fluxes, dtype: float64"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "solution.fluxes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [],
   "source": [
    "model.objective={model.reactions.EX_biomass:1}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "id": "N2NQjVDeUzHn"
   },
   "outputs": [],
   "source": [
    "environmental_conditions = {\n",
    "    'R11': (0, 1000),\n",
    "    'R04': (0,0),\n",
    "    'R10': (0,0),\n",
    "}\n",
    "for reaction_id, bound in environmental_conditions.items():\n",
    "    model.reactions.get_by_id(reaction_id).bounds = bound"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "id": "dKjcIhGadO63",
    "outputId": "fcdc6fe4-025d-4cca-a2f2-ec03d9188dd7"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "EX_S         -100.0\n",
       "EX_biomass     50.0\n",
       "EX_fuel1       50.0\n",
       "EX_fuel2       -0.0\n",
       "R01           100.0\n",
       "R02           100.0\n",
       "R03           100.0\n",
       "R04             0.0\n",
       "R05             0.0\n",
       "R06           100.0\n",
       "R07           100.0\n",
       "R08           100.0\n",
       "R09            50.0\n",
       "R10             0.0\n",
       "R11             0.0\n",
       "R12             0.0\n",
       "R13             0.0\n",
       "R14             0.0\n",
       "R15             0.0\n",
       "R16             0.0\n",
       "R17            50.0\n",
       "R18             0.0\n",
       "Name: fluxes, dtype: float64"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "solution = model.optimize()\n",
    "solution.fluxes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 1000
    },
    "id": "1Yhz2EbYdPPP",
    "outputId": "a6139ec6-9568-49fb-f5d2-0470a346f84a"
   },
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "2ae4d64f18134148b0667016c110dee9",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Builder(reaction_data={'EX_S': -100.0, 'EX_biomass': 50.0, 'EX_fuel1': 50.0, 'EX_fuel2': -0.0, 'R01': 100.0, '…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "builder = escher.Builder(map_json='toy_escher_map.json', model=model, reaction_data=solution.fluxes)\n",
    "#builder.save_html('map2')\n",
    "#from IPython.core.display import display, HTML\n",
    "#display(HTML('map2'))\n",
    "builder"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "T_ZO713GdPr3"
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "QD9_9xYxUzeC"
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "n9qmsvDKWaFK"
   },
   "outputs": [],
   "source": [
    "# Dessiner une map escher\n",
    "''' \n",
    "cobra.io.save_json_model(model,'toy_model.json')\n",
    "from escher import Builder\n",
    "b=Builder()\n",
    "b.model_json='toy_model.json'\n",
    "b.height=1600\n",
    "b.width=1600\n",
    "b.save_html('map')\n",
    "from IPython.core.display import display, HTML\n",
    "display(HTML('map'))\n",
    "'''"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "KdGUXmxyg0OC"
   },
   "outputs": [],
   "source": [
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "5wpxRl0Ek8KB"
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "colab": {
   "collapsed_sections": [],
   "provenance": []
  },
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "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.8.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
