{
"cells": [
{
"cell_type": "markdown",
"id": "86d5d8a5",
"metadata": {},
"source": [
"## Editing reaction kinetics\n",
"Previous examples showed how to create models using basico, and using kinetic functions from the reaction database. Here, I want to expand on that showing how to map kinetic functions to reactions involving modifiers as well. Lets start as usual by importing basico: "
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "ec398d0f",
"metadata": {},
"outputs": [],
"source": [
"from basico import *"
]
},
{
"cell_type": "markdown",
"id": "719e97a5",
"metadata": {},
"source": [
"now lets create a new model: "
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "bff10872",
"metadata": {},
"outputs": [],
"source": [
"new_model(name='Reactions');"
]
},
{
"cell_type": "markdown",
"id": "bd513ab6",
"metadata": {},
"source": [
"we know we can create a reaction, by using the `add_reaction` command. It requires at the very least two arguments: \n",
"\n",
"* `name`: the name of the reaction\n",
"* `scheme`: the reaction scheme\n",
"\n",
"If nothing else is specified, this will create the reaction with the given `name` and reaction `scheme`, assigning it mass action kinetics with local parameters defaulting to a value of `0.1`. All species will be created if they do not exist yet in the model. For example: "
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "0d2daeaa",
"metadata": {},
"outputs": [],
"source": [
"add_reaction('R1', 'A -> B');"
]
},
{
"cell_type": "markdown",
"id": "eaea42a1",
"metadata": {},
"source": [
"creates the reaction `R1`, species `A` and `B` and a local parameter `(R1).k1`. With `get_reactions` we can have a look at what was created: "
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "9a201872",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" scheme | \n",
" function | \n",
" mapping | \n",
"
\n",
" \n",
" | name | \n",
" | \n",
" | \n",
" | \n",
"
\n",
" \n",
" \n",
" \n",
" | R1 | \n",
" A -> B | \n",
" Mass action (irreversible) | \n",
" {'k1': 0.1, 'substrate': 'A'} | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" scheme function mapping\n",
"name \n",
"R1 A -> B Mass action (irreversible) {'k1': 0.1, 'substrate': 'A'}"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"get_reactions()[['scheme', 'function', 'mapping']]"
]
},
{
"cell_type": "markdown",
"id": "f64abc5a",
"metadata": {},
"source": [
"here I want to point out, the `mapping` column. It shows that the parameter `k1` is a local one, as it is mapped to a value. And that the substrate of the function is mapped to `A`. We can specify the mapping directly in the `add_reaction` call, or we can specify it using `set_reaction`. So for example, if we wanted to modify the reaction, to map the reactions `k1` parameter to a global quantity `global_k`, we could to that as follows: "
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "b9e54bdd",
"metadata": {},
"outputs": [],
"source": [
"add_parameter(name='global_k', initial_value=0.2)\n",
"set_reaction('R1', mapping={'k1': 'global_k'})"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "d2265200",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" scheme | \n",
" function | \n",
" mapping | \n",
"
\n",
" \n",
" | name | \n",
" | \n",
" | \n",
" | \n",
"
\n",
" \n",
" \n",
" \n",
" | R1 | \n",
" A -> B | \n",
" Mass action (irreversible) | \n",
" {'k1': 'global_k', 'substrate': 'A'} | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" scheme function mapping\n",
"name \n",
"R1 A -> B Mass action (irreversible) {'k1': 'global_k', 'substrate': 'A'}"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"get_reactions()[['scheme', 'function', 'mapping']]"
]
},
{
"cell_type": "markdown",
"id": "5321d797",
"metadata": {},
"source": [
"next let us assume, i wanted to use a kinetic from the function database, that includes inhibition for the reaction. Using `get_functions` we can filter the functiondatabase, for suitable functions for our reaction, and then filter for ones that contain inhibition: "
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "b0ef53ab",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" formula | \n",
" mapping | \n",
"
\n",
" \n",
" | name | \n",
" | \n",
" | \n",
"
\n",
" \n",
" \n",
" \n",
" | Allosteric inhibition (MWC) | \n",
" V*(substrate/Ks)*(1+(substrate/Ks))^(n-1)/(L*(... | \n",
" {'substrate': 'substrate', 'Inhibitor': 'modif... | \n",
"
\n",
" \n",
" | Competitive inhibition (irr) | \n",
" V*substrate/(Km+substrate+Km*Inhibitor/Ki) | \n",
" {'substrate': 'substrate', 'Inhibitor': 'modif... | \n",
"
\n",
" \n",
" | Mixed inhibition (irr) | \n",
" V*substrate/(Km*(1+Inhibitor/Kis)+substrate*(1... | \n",
" {'substrate': 'substrate', 'Inhibitor': 'modif... | \n",
"
\n",
" \n",
" | Noncompetitive inhibition (irr) | \n",
" V*substrate/((Km+substrate)*(1+Inhibitor/Ki)) | \n",
" {'substrate': 'substrate', 'Inhibitor': 'modif... | \n",
"
\n",
" \n",
" | Substrate inhibition (irr) | \n",
" V*substrate/(Km+substrate+Km*(substrate/Ki)^2) | \n",
" {'substrate': 'substrate', 'Km': 'parameter', ... | \n",
"
\n",
" \n",
" | Uncompetitive inhibition (irr) | \n",
" V*substrate/(Km+substrate*(1+Inhibitor/Ki)) | \n",
" {'substrate': 'substrate', 'Inhibitor': 'modif... | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" formula \\\n",
"name \n",
"Allosteric inhibition (MWC) V*(substrate/Ks)*(1+(substrate/Ks))^(n-1)/(L*(... \n",
"Competitive inhibition (irr) V*substrate/(Km+substrate+Km*Inhibitor/Ki) \n",
"Mixed inhibition (irr) V*substrate/(Km*(1+Inhibitor/Kis)+substrate*(1... \n",
"Noncompetitive inhibition (irr) V*substrate/((Km+substrate)*(1+Inhibitor/Ki)) \n",
"Substrate inhibition (irr) V*substrate/(Km+substrate+Km*(substrate/Ki)^2) \n",
"Uncompetitive inhibition (irr) V*substrate/(Km+substrate*(1+Inhibitor/Ki)) \n",
"\n",
" mapping \n",
"name \n",
"Allosteric inhibition (MWC) {'substrate': 'substrate', 'Inhibitor': 'modif... \n",
"Competitive inhibition (irr) {'substrate': 'substrate', 'Inhibitor': 'modif... \n",
"Mixed inhibition (irr) {'substrate': 'substrate', 'Inhibitor': 'modif... \n",
"Noncompetitive inhibition (irr) {'substrate': 'substrate', 'Inhibitor': 'modif... \n",
"Substrate inhibition (irr) {'substrate': 'substrate', 'Km': 'parameter', ... \n",
"Uncompetitive inhibition (irr) {'substrate': 'substrate', 'Inhibitor': 'modif... "
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"suitable_functions = get_functions(suitable_for='R1')[['formula', 'mapping']]\n",
"suitable_inhibitions = suitable_functions[suitable_functions.index.str.contains('inhibition')]\n",
"suitable_inhibitions"
]
},
{
"cell_type": "markdown",
"id": "b550042e",
"metadata": {},
"source": [
"let us use `Allosteric inhibition (MWC)` here, lets have a look at the formula and the mapping table: "
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "2faf9910",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'name': 'Allosteric inhibition (MWC)',\n",
" 'formula': 'V*(substrate/Ks)*(1+(substrate/Ks))^(n-1)/(L*(1+Inhibitor/Ki)^n+(1+(substrate/Ks))^n)',\n",
" 'mapping': {'substrate': 'substrate',\n",
" 'Inhibitor': 'modifier',\n",
" 'V': 'parameter',\n",
" 'Ks': 'parameter',\n",
" 'n': 'parameter',\n",
" 'L': 'parameter',\n",
" 'Ki': 'parameter'}}"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"as_dict(suitable_inhibitions)[0]"
]
},
{
"cell_type": "markdown",
"id": "b2aadc12",
"metadata": {},
"source": [
"since this function requires a modifier, we also change the reaction scheme to include a modifier. This is done by adding a semicolon at the end of the reaction scheme, and listing the modifiers space separated there. Then we an assign that function directly. "
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "a44ab0c2",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" scheme | \n",
" function | \n",
" mapping | \n",
"
\n",
" \n",
" | name | \n",
" | \n",
" | \n",
" | \n",
"
\n",
" \n",
" \n",
" \n",
" | R1 | \n",
" A -> B; C | \n",
" Allosteric inhibition (MWC) | \n",
" {'substrate': 'A', 'Inhibitor': 'C', 'V': 0.1,... | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" scheme function \\\n",
"name \n",
"R1 A -> B; C Allosteric inhibition (MWC) \n",
"\n",
" mapping \n",
"name \n",
"R1 {'substrate': 'A', 'Inhibitor': 'C', 'V': 0.1,... "
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"set_reaction('R1', scheme='A -> B; C', function='Allosteric inhibition (MWC)')\n",
"get_reactions()[['scheme', 'function', 'mapping']]"
]
},
{
"cell_type": "markdown",
"id": "6666b360",
"metadata": {},
"source": [
"*Note:* that here, the mapping is not necessary, as the function has only one modifier, had we multiple modifiers defined, then we'd want to specify the mapping dictionary and map the `Inhibitor` to the respective modifier in our reaction scheme: "
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "e588d15a",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" scheme | \n",
" function | \n",
" mapping | \n",
"
\n",
" \n",
" | name | \n",
" | \n",
" | \n",
" | \n",
"
\n",
" \n",
" \n",
" \n",
" | R1 | \n",
" A -> B; D | \n",
" Allosteric inhibition (MWC) | \n",
" {'substrate': 'A', 'Inhibitor': 'D', 'V': 0.1,... | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" scheme function \\\n",
"name \n",
"R1 A -> B; D Allosteric inhibition (MWC) \n",
"\n",
" mapping \n",
"name \n",
"R1 {'substrate': 'A', 'Inhibitor': 'D', 'V': 0.1,... "
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"set_reaction('R1', scheme='A -> B; C D', function='Allosteric inhibition (MWC)', mapping={'Inhibitor': 'D'})\n",
"get_reactions()[['scheme', 'function', 'mapping']]"
]
},
{
"cell_type": "markdown",
"id": "111ed9d0",
"metadata": {},
"source": [
"*Note:* Assigning a function that uses modifiers, *requires* that modifiers are present in the reaction scheme, or that *all modifiers* are specified in the mapping parameter. So assigning the function above would fail with error, if no modifier is declared: "
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "e4fd7589",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"ERROR:root:the mapping for reaction \"error\" with function \"Allosteric inhibition (MWC)\" is not valid and cannot be applied.\n"
]
},
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" scheme | \n",
" function | \n",
" mapping | \n",
"
\n",
" \n",
" | name | \n",
" | \n",
" | \n",
" | \n",
"
\n",
" \n",
" \n",
" \n",
" | R1 | \n",
" A -> B; D | \n",
" Allosteric inhibition (MWC) | \n",
" {'substrate': 'A', 'Inhibitor': 'D', 'V': 0.1,... | \n",
"
\n",
" \n",
" | error | \n",
" A -> B | \n",
" Mass action (irreversible) | \n",
" {'k1': 0.1, 'substrate': 'A'} | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" scheme function \\\n",
"name \n",
"R1 A -> B; D Allosteric inhibition (MWC) \n",
"error A -> B Mass action (irreversible) \n",
"\n",
" mapping \n",
"name \n",
"R1 {'substrate': 'A', 'Inhibitor': 'D', 'V': 0.1,... \n",
"error {'k1': 0.1, 'substrate': 'A'} "
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"add_reaction('error', scheme='A -> B', function='Allosteric inhibition (MWC)');\n",
"get_reactions()[['scheme', 'function', 'mapping']]"
]
},
{
"cell_type": "markdown",
"id": "fca16b2a",
"metadata": {},
"source": [
"However, it will succeeed, if the modifier is specified. in the mapping parameter: "
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "359b2f58",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" scheme | \n",
" function | \n",
" mapping | \n",
"
\n",
" \n",
" | name | \n",
" | \n",
" | \n",
" | \n",
"
\n",
" \n",
" \n",
" \n",
" | R1 | \n",
" A -> B; D | \n",
" Allosteric inhibition (MWC) | \n",
" {'substrate': 'A', 'Inhibitor': 'D', 'V': 0.1,... | \n",
"
\n",
" \n",
" | now_it_works | \n",
" A -> B; D | \n",
" Allosteric inhibition (MWC) | \n",
" {'substrate': 'A', 'Inhibitor': 'D', 'V': 0.1,... | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" scheme function \\\n",
"name \n",
"R1 A -> B; D Allosteric inhibition (MWC) \n",
"now_it_works A -> B; D Allosteric inhibition (MWC) \n",
"\n",
" mapping \n",
"name \n",
"R1 {'substrate': 'A', 'Inhibitor': 'D', 'V': 0.1,... \n",
"now_it_works {'substrate': 'A', 'Inhibitor': 'D', 'V': 0.1,... "
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"set_reaction('error', new_name='now_it_works', function='Allosteric inhibition (MWC)', mapping={'Inhibitor': 'D'})\n",
"get_reactions()[['scheme', 'function', 'mapping']]"
]
}
],
"metadata": {
"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.10.4"
}
},
"nbformat": 4,
"nbformat_minor": 5
}