diff --git a/notebooks/demo_compose.ipynb b/notebooks/demo_compose.ipynb new file mode 100644 index 000000000..e6509dfc7 --- /dev/null +++ b/notebooks/demo_compose.ipynb @@ -0,0 +1,752 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "808b6a4b-0894-4a8e-99d8-bf11b3164b6a", + "metadata": {}, + "source": [ + "## Examples with ```CopasiProcess``` using ``builder.Builder`` and ``biosimulator_processes.data_model``" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "b385dca6-942d-472c-9963-13b8cb33843c", + "metadata": { + "ExecuteTime": { + "end_time": "2024-03-01T20:26:45.156450Z", + "start_time": "2024-03-01T20:26:43.414577Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "CobraProcess registered successfully.\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/Users/alex/Library/Caches/pypoetry/virtualenvs/biosimulator-processes-KVuYbFzt-py3.10/lib/python3.10/site-packages/pydantic/_internal/_fields.py:151: UserWarning: Field \"model_id\" has conflict with protected namespace \"model_\".\n", + "\n", + "You may be able to resolve this warning by setting `model_config['protected_namespaces'] = ()`.\n", + " warnings.warn(\n", + "/Users/alex/Library/Caches/pypoetry/virtualenvs/biosimulator-processes-KVuYbFzt-py3.10/lib/python3.10/site-packages/pydantic/_internal/_fields.py:151: UserWarning: Field \"model_source\" has conflict with protected namespace \"model_\".\n", + "\n", + "You may be able to resolve this warning by setting `model_config['protected_namespaces'] = ()`.\n", + " warnings.warn(\n", + "/Users/alex/Library/Caches/pypoetry/virtualenvs/biosimulator-processes-KVuYbFzt-py3.10/lib/python3.10/site-packages/pydantic/_internal/_fields.py:151: UserWarning: Field \"model_language\" has conflict with protected namespace \"model_\".\n", + "\n", + "You may be able to resolve this warning by setting `model_config['protected_namespaces'] = ()`.\n", + " warnings.warn(\n", + "/Users/alex/Library/Caches/pypoetry/virtualenvs/biosimulator-processes-KVuYbFzt-py3.10/lib/python3.10/site-packages/pydantic/_internal/_fields.py:151: UserWarning: Field \"model_name\" has conflict with protected namespace \"model_\".\n", + "\n", + "You may be able to resolve this warning by setting `model_config['protected_namespaces'] = ()`.\n", + " warnings.warn(\n", + "/Users/alex/Library/Caches/pypoetry/virtualenvs/biosimulator-processes-KVuYbFzt-py3.10/lib/python3.10/site-packages/pydantic/_internal/_fields.py:151: UserWarning: Field \"model_changes\" has conflict with protected namespace \"model_\".\n", + "\n", + "You may be able to resolve this warning by setting `model_config['protected_namespaces'] = ()`.\n", + " warnings.warn(\n", + "/Users/alex/Library/Caches/pypoetry/virtualenvs/biosimulator-processes-KVuYbFzt-py3.10/lib/python3.10/site-packages/pydantic/_internal/_fields.py:151: UserWarning: Field \"model_units\" has conflict with protected namespace \"model_\".\n", + "\n", + "You may be able to resolve this warning by setting `model_config['protected_namespaces'] = ()`.\n", + " warnings.warn(\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "CopasiProcess registered successfully.\n", + "SmoldynProcess registered successfully.\n", + "TelluriumProcess registered successfully.\n" + ] + } + ], + "source": [ + "from builder import Builder, Process\n", + "from process_bigraph import pp, pf \n", + "from biosimulator_processes import CORE\n", + "from biosimulator_processes.data_model import *\n", + "from biosimulator_processes.biosimulator_builder import BiosimulatorBuilder" + ] + }, + { + "cell_type": "markdown", + "id": "a403d619-4dbe-49cc-8f24-29a83e31fe15", + "metadata": {}, + "source": [ + "#### Initialize a fresh instance of the `BiosimulatorBuilder`, which is inherently configured by `biosimulator_processes.CORE`." + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "b6260555-2bad-4834-adc5-e6d358063579", + "metadata": { + "ExecuteTime": { + "end_time": "2024-03-01T20:26:45.156955Z", + "start_time": "2024-03-01T20:26:45.154066Z" + } + }, + "outputs": [], + "source": [ + "b = BiosimulatorBuilder()" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "40cde984-cfdf-4571-af9c-3a3755e3763c", + "metadata": { + "ExecuteTime": { + "end_time": "2024-03-01T20:26:45.163368Z", + "start_time": "2024-03-01T20:26:45.157609Z" + } + }, + "outputs": [ + { + "data": { + "text/plain": "['TelluriumProcess',\n 'ram-emitter',\n 'CobraProcess',\n 'SmoldynProcess',\n 'console-emitter',\n 'CopasiProcess']" + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "###### list registered processes\n", + "\n", + "b.list_processes()" + ] + }, + { + "cell_type": "code", + "outputs": [], + "source": [ + "from basico import *\n", + "from basico import biomodels\n", + "\n", + "\n", + "model = load_biomodel('BIOMD0000000861')" + ], + "metadata": { + "collapsed": false, + "ExecuteTime": { + "end_time": "2024-03-01T20:26:47.219279Z", + "start_time": "2024-03-01T20:26:45.160804Z" + } + }, + "id": "9279a6fec5ad0c48", + "execution_count": 4 + }, + { + "cell_type": "code", + "outputs": [ + { + "data": { + "text/plain": " compartment type unit initial_concentration \\\nname \nEpoRJAK2 cyt reactions nmol/l 3.976220e+00 \nEpoRpJAK2 cyt reactions nmol/l 0.000000e+00 \np1EpoRpJAK2 cyt reactions nmol/l 0.000000e+00 \np2EpoRpJAK2 cyt reactions nmol/l 0.000000e+00 \np12EpoRpJAK2 cyt reactions nmol/l 0.000000e+00 \nEpoRJAK2_CIS cyt reactions nmol/l 0.000000e+00 \nSHP1 cyt reactions nmol/l 2.672510e+01 \nSHP1Act cyt reactions nmol/l 0.000000e+00 \nSTAT5 cyt reactions nmol/l 7.975350e+01 \npSTAT5 cyt reactions nmol/l 0.000000e+00 \nnpSTAT5 nuc reactions nmol/l 0.000000e+00 \nCISnRNA1 nuc reactions nmol/l 0.000000e+00 \nCISnRNA2 nuc reactions nmol/l 0.000000e+00 \nCISnRNA3 nuc reactions nmol/l 0.000000e+00 \nCISnRNA4 nuc reactions nmol/l 0.000000e+00 \nCISnRNA5 nuc reactions nmol/l 0.000000e+00 \nCISRNA cyt reactions nmol/l 0.000000e+00 \nCIS cyt reactions nmol/l 0.000000e+00 \nSOCS3nRNA1 nuc reactions nmol/l 0.000000e+00 \nSOCS3nRNA2 nuc reactions nmol/l 0.000000e+00 \nSOCS3nRNA3 nuc reactions nmol/l 0.000000e+00 \nSOCS3nRNA4 nuc reactions nmol/l 0.000000e+00 \nSOCS3nRNA5 nuc reactions nmol/l 0.000000e+00 \nSOCS3RNA cyt reactions nmol/l 0.000000e+00 \nSOCS3 cyt reactions nmol/l 0.000000e+00 \nEpo cyt reactions nmol/l 1.249970e-07 \n\n initial_particle_number initial_expression expression \\\nname \nEpoRJAK2 9.578143e+14 \nEpoRpJAK2 0.000000e+00 \np1EpoRpJAK2 0.000000e+00 \np2EpoRpJAK2 0.000000e+00 \np12EpoRpJAK2 0.000000e+00 \nEpoRJAK2_CIS 0.000000e+00 \nSHP1 6.437693e+15 \nSHP1Act 0.000000e+00 \nSTAT5 1.921147e+16 \npSTAT5 0.000000e+00 \nnpSTAT5 0.000000e+00 \nCISnRNA1 0.000000e+00 \nCISnRNA2 0.000000e+00 \nCISnRNA3 0.000000e+00 \nCISnRNA4 0.000000e+00 \nCISnRNA5 0.000000e+00 \nCISRNA 0.000000e+00 \nCIS 0.000000e+00 \nSOCS3nRNA1 0.000000e+00 \nSOCS3nRNA2 0.000000e+00 \nSOCS3nRNA3 0.000000e+00 \nSOCS3nRNA4 0.000000e+00 \nSOCS3nRNA5 0.000000e+00 \nSOCS3RNA 0.000000e+00 \nSOCS3 0.000000e+00 \nEpo 3.010998e+07 \n\n concentration particle_number rate particle_number_rate \\\nname \nEpoRJAK2 3.976220e+00 9.578143e+14 -0.314737 -7.581552e+13 \nEpoRpJAK2 0.000000e+00 0.000000e+00 0.314737 7.581552e+13 \np1EpoRpJAK2 0.000000e+00 0.000000e+00 0.000000 0.000000e+00 \np2EpoRpJAK2 0.000000e+00 0.000000e+00 0.000000 0.000000e+00 \np12EpoRpJAK2 0.000000e+00 0.000000e+00 0.000000 0.000000e+00 \nEpoRJAK2_CIS 0.000000e+00 0.000000e+00 0.000000 0.000000e+00 \nSHP1 2.672510e+01 6.437693e+15 0.000000 0.000000e+00 \nSHP1Act 0.000000e+00 0.000000e+00 0.000000 0.000000e+00 \nSTAT5 7.975350e+01 1.921147e+16 0.000000 0.000000e+00 \npSTAT5 0.000000e+00 0.000000e+00 0.000000 0.000000e+00 \nnpSTAT5 0.000000e+00 0.000000e+00 0.000000 0.000000e+00 \nCISnRNA1 0.000000e+00 0.000000e+00 0.000000 0.000000e+00 \nCISnRNA2 0.000000e+00 0.000000e+00 0.000000 0.000000e+00 \nCISnRNA3 0.000000e+00 0.000000e+00 0.000000 0.000000e+00 \nCISnRNA4 0.000000e+00 0.000000e+00 0.000000 0.000000e+00 \nCISnRNA5 0.000000e+00 0.000000e+00 0.000000 0.000000e+00 \nCISRNA 0.000000e+00 0.000000e+00 0.000000 0.000000e+00 \nCIS 0.000000e+00 0.000000e+00 0.000000 0.000000e+00 \nSOCS3nRNA1 0.000000e+00 0.000000e+00 0.000000 0.000000e+00 \nSOCS3nRNA2 0.000000e+00 0.000000e+00 0.000000 0.000000e+00 \nSOCS3nRNA3 0.000000e+00 0.000000e+00 0.000000 0.000000e+00 \nSOCS3nRNA4 0.000000e+00 0.000000e+00 0.000000 0.000000e+00 \nSOCS3nRNA5 0.000000e+00 0.000000e+00 0.000000 0.000000e+00 \nSOCS3RNA 0.000000e+00 0.000000e+00 0.000000 0.000000e+00 \nSOCS3 0.000000e+00 0.000000e+00 0.000000 0.000000e+00 \nEpo 1.249970e-07 3.010998e+07 0.000000 0.000000e+00 \n\n key sbml_id \nname \nEpoRJAK2 Metabolite_0 EpoRJAK2 \nEpoRpJAK2 Metabolite_1 EpoRpJAK2 \np1EpoRpJAK2 Metabolite_2 p1EpoRpJAK2 \np2EpoRpJAK2 Metabolite_3 p2EpoRpJAK2 \np12EpoRpJAK2 Metabolite_4 p12EpoRpJAK2 \nEpoRJAK2_CIS Metabolite_5 EpoRJAK2_CIS \nSHP1 Metabolite_6 SHP1 \nSHP1Act Metabolite_7 SHP1Act \nSTAT5 Metabolite_8 STAT5 \npSTAT5 Metabolite_9 pSTAT5 \nnpSTAT5 Metabolite_10 npSTAT5 \nCISnRNA1 Metabolite_11 CISnRNA1 \nCISnRNA2 Metabolite_12 CISnRNA2 \nCISnRNA3 Metabolite_13 CISnRNA3 \nCISnRNA4 Metabolite_14 CISnRNA4 \nCISnRNA5 Metabolite_15 CISnRNA5 \nCISRNA Metabolite_16 CISRNA \nCIS Metabolite_17 CIS \nSOCS3nRNA1 Metabolite_18 SOCS3nRNA1 \nSOCS3nRNA2 Metabolite_19 SOCS3nRNA2 \nSOCS3nRNA3 Metabolite_20 SOCS3nRNA3 \nSOCS3nRNA4 Metabolite_21 SOCS3nRNA4 \nSOCS3nRNA5 Metabolite_22 SOCS3nRNA5 \nSOCS3RNA Metabolite_23 SOCS3RNA \nSOCS3 Metabolite_24 SOCS3 \nEpo Metabolite_25 Epo ", + "text/html": "
\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
compartmenttypeunitinitial_concentrationinitial_particle_numberinitial_expressionexpressionconcentrationparticle_numberrateparticle_number_ratekeysbml_id
name
EpoRJAK2cytreactionsnmol/l3.976220e+009.578143e+143.976220e+009.578143e+14-0.314737-7.581552e+13Metabolite_0EpoRJAK2
EpoRpJAK2cytreactionsnmol/l0.000000e+000.000000e+000.000000e+000.000000e+000.3147377.581552e+13Metabolite_1EpoRpJAK2
p1EpoRpJAK2cytreactionsnmol/l0.000000e+000.000000e+000.000000e+000.000000e+000.0000000.000000e+00Metabolite_2p1EpoRpJAK2
p2EpoRpJAK2cytreactionsnmol/l0.000000e+000.000000e+000.000000e+000.000000e+000.0000000.000000e+00Metabolite_3p2EpoRpJAK2
p12EpoRpJAK2cytreactionsnmol/l0.000000e+000.000000e+000.000000e+000.000000e+000.0000000.000000e+00Metabolite_4p12EpoRpJAK2
EpoRJAK2_CIScytreactionsnmol/l0.000000e+000.000000e+000.000000e+000.000000e+000.0000000.000000e+00Metabolite_5EpoRJAK2_CIS
SHP1cytreactionsnmol/l2.672510e+016.437693e+152.672510e+016.437693e+150.0000000.000000e+00Metabolite_6SHP1
SHP1Actcytreactionsnmol/l0.000000e+000.000000e+000.000000e+000.000000e+000.0000000.000000e+00Metabolite_7SHP1Act
STAT5cytreactionsnmol/l7.975350e+011.921147e+167.975350e+011.921147e+160.0000000.000000e+00Metabolite_8STAT5
pSTAT5cytreactionsnmol/l0.000000e+000.000000e+000.000000e+000.000000e+000.0000000.000000e+00Metabolite_9pSTAT5
npSTAT5nucreactionsnmol/l0.000000e+000.000000e+000.000000e+000.000000e+000.0000000.000000e+00Metabolite_10npSTAT5
CISnRNA1nucreactionsnmol/l0.000000e+000.000000e+000.000000e+000.000000e+000.0000000.000000e+00Metabolite_11CISnRNA1
CISnRNA2nucreactionsnmol/l0.000000e+000.000000e+000.000000e+000.000000e+000.0000000.000000e+00Metabolite_12CISnRNA2
CISnRNA3nucreactionsnmol/l0.000000e+000.000000e+000.000000e+000.000000e+000.0000000.000000e+00Metabolite_13CISnRNA3
CISnRNA4nucreactionsnmol/l0.000000e+000.000000e+000.000000e+000.000000e+000.0000000.000000e+00Metabolite_14CISnRNA4
CISnRNA5nucreactionsnmol/l0.000000e+000.000000e+000.000000e+000.000000e+000.0000000.000000e+00Metabolite_15CISnRNA5
CISRNAcytreactionsnmol/l0.000000e+000.000000e+000.000000e+000.000000e+000.0000000.000000e+00Metabolite_16CISRNA
CIScytreactionsnmol/l0.000000e+000.000000e+000.000000e+000.000000e+000.0000000.000000e+00Metabolite_17CIS
SOCS3nRNA1nucreactionsnmol/l0.000000e+000.000000e+000.000000e+000.000000e+000.0000000.000000e+00Metabolite_18SOCS3nRNA1
SOCS3nRNA2nucreactionsnmol/l0.000000e+000.000000e+000.000000e+000.000000e+000.0000000.000000e+00Metabolite_19SOCS3nRNA2
SOCS3nRNA3nucreactionsnmol/l0.000000e+000.000000e+000.000000e+000.000000e+000.0000000.000000e+00Metabolite_20SOCS3nRNA3
SOCS3nRNA4nucreactionsnmol/l0.000000e+000.000000e+000.000000e+000.000000e+000.0000000.000000e+00Metabolite_21SOCS3nRNA4
SOCS3nRNA5nucreactionsnmol/l0.000000e+000.000000e+000.000000e+000.000000e+000.0000000.000000e+00Metabolite_22SOCS3nRNA5
SOCS3RNAcytreactionsnmol/l0.000000e+000.000000e+000.000000e+000.000000e+000.0000000.000000e+00Metabolite_23SOCS3RNA
SOCS3cytreactionsnmol/l0.000000e+000.000000e+000.000000e+000.000000e+000.0000000.000000e+00Metabolite_24SOCS3
Epocytreactionsnmol/l1.249970e-073.010998e+071.249970e-073.010998e+070.0000000.000000e+00Metabolite_25Epo
\n
" + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "get_species(model=model)" + ], + "metadata": { + "collapsed": false, + "ExecuteTime": { + "end_time": "2024-03-01T20:26:47.239689Z", + "start_time": "2024-03-01T20:26:47.218036Z" + } + }, + "id": "da6096ec3e0daa85", + "execution_count": 5 + }, + { + "cell_type": "markdown", + "id": "dfa2d764-8cdb-4a1e-84c5-fd81cc4e6afe", + "metadata": {}, + "source": [ + "#### Example 1: Add a simple `CopasiProcess`-based composite to the bigraph, specifying parameter values through the `data_model`. For now, let's try loading a biomodel and adding a change to initial concentration of a species" + ] + }, + { + "cell_type": "code", + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{ 'global_parameter_changes': [],\n", + " 'reaction_changes': [],\n", + " 'species_changes': { 'expression': '',\n", + " 'initial_concentration': 5.0,\n", + " 'initial_expression': '',\n", + " 'initial_particle_number': None,\n", + " 'name': 'SHP1',\n", + " 'unit': ''}}\n" + ] + } + ], + "source": [ + "# 1. specify model changes\n", + "\n", + "process_model_changes = ModelChanges(\n", + " species_changes=SpeciesChanges(\n", + " name='SHP1',\n", + " initial_concentration=5.00000\n", + " )\n", + ")\n", + "\n", + "\n", + "pp(process_model_changes.model_dump())" + ], + "metadata": { + "collapsed": false, + "ExecuteTime": { + "end_time": "2024-03-01T20:26:47.240290Z", + "start_time": "2024-03-01T20:26:47.228380Z" + } + }, + "id": "2b1c1bdd6864a771", + "execution_count": 6 + }, + { + "cell_type": "code", + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{ 'model_changes': { 'global_parameter_changes': [],\n", + " 'reaction_changes': [],\n", + " 'species_changes': { 'expression': '',\n", + " 'initial_concentration': 5.0,\n", + " 'initial_expression': '',\n", + " 'initial_particle_number': None,\n", + " 'name': 'SHP1',\n", + " 'unit': ''}},\n", + " 'model_id': 'simple_copasi_process',\n", + " 'model_language': 'sbml',\n", + " 'model_name': 'Simple Composite Process',\n", + " 'model_source': {'value': 'BIOMD0000000861'},\n", + " 'model_units': None}\n" + ] + } + ], + "source": [ + "# 2. define the model schema to be used by the composite process (one of the copasiprocess config parameters)\n", + "\n", + "process_model = Model(\n", + " model_id='simple_copasi_process',\n", + " model_source='BIOMD0000000861',\n", + " model_name='Simple Composite Process',\n", + " model_changes=process_model_changes\n", + ")\n", + "\n", + "\n", + "pp(process_model.model_dump())" + ], + "metadata": { + "collapsed": false, + "ExecuteTime": { + "end_time": "2024-03-01T20:26:47.240731Z", + "start_time": "2024-03-01T20:26:47.231720Z" + } + }, + "id": "8d0566183a2d1c1f", + "execution_count": 7 + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "b79dc6639a17e353", + "metadata": { + "collapsed": false, + "ExecuteTime": { + "end_time": "2024-03-01T20:26:47.241147Z", + "start_time": "2024-03-01T20:26:47.234287Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{ 'method': 'stochastic',\n", + " 'model': { 'model_changes': { 'global_parameter_changes': [],\n", + " 'reaction_changes': [],\n", + " 'species_changes': { 'expression': '',\n", + " 'initial_concentration': 5.0,\n", + " 'initial_expression': '',\n", + " 'initial_particle_number': None,\n", + " 'name': 'SHP1',\n", + " 'unit': ''}},\n", + " 'model_id': 'simple_copasi_process',\n", + " 'model_language': 'sbml',\n", + " 'model_name': 'Simple Composite Process',\n", + " 'model_source': {'value': 'BIOMD0000000861'},\n", + " 'model_units': None}}\n" + ] + } + ], + "source": [ + "# 3. Define config schema to be used as 'config' parameter of Process constructor\n", + "\n", + "\n", + "process_config = CopasiProcessConfigSchema(\n", + " method='stochastic',\n", + " model=process_model,\n", + " process_name='simple_copasi'\n", + ")\n", + "\n", + "\n", + "process_config_dict = process_config.model_dump()\n", + "process_config_dict.pop('process_name')\n", + "pp(process_config_dict)" + ] + }, + { + "cell_type": "code", + "outputs": [ + { + "data": { + "text/plain": "{'model_id': 'simple_copasi_process',\n 'model_source': {'value': 'BIOMD0000000861'},\n 'model_language': 'sbml',\n 'model_name': 'Simple Composite Process',\n 'model_changes': {'species_changes': {'name': 'SHP1',\n 'unit': '',\n 'initial_concentration': 5.0,\n 'initial_particle_number': None,\n 'initial_expression': '',\n 'expression': ''},\n 'global_parameter_changes': [],\n 'reaction_changes': []},\n 'model_units': None}" + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "process_config.model" + ], + "metadata": { + "collapsed": false, + "ExecuteTime": { + "end_time": "2024-03-01T20:26:47.263708Z", + "start_time": "2024-03-01T20:26:47.236777Z" + } + }, + "id": "1e4306cd3178c99e", + "execution_count": 9 + }, + { + "cell_type": "code", + "outputs": [ + { + "data": { + "text/plain": "{'model_id': 'simple_copasi_process',\n 'model_source': {'value': 'BIOMD0000000861'},\n 'model_language': 'sbml',\n 'model_name': 'Simple Composite Process',\n 'model_changes': {'species_changes': {'name': 'SHP1',\n 'unit': '',\n 'initial_concentration': 5.0,\n 'initial_particle_number': None,\n 'initial_expression': '',\n 'expression': ''},\n 'global_parameter_changes': [],\n 'reaction_changes': []},\n 'model_units': None}" + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "process_config.model" + ], + "metadata": { + "collapsed": false, + "ExecuteTime": { + "end_time": "2024-03-01T20:26:47.267191Z", + "start_time": "2024-03-01T20:26:47.239803Z" + } + }, + "id": "de1a53721f43fe1d", + "execution_count": 10 + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "503863ee-0a58-44b3-accc-20e0167b947b", + "metadata": { + "ExecuteTime": { + "end_time": "2024-03-01T20:26:49.368423Z", + "start_time": "2024-03-01T20:26:47.285527Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "THE CHANGES: {'name': 'SHP1', 'unit': '', 'initial_concentration': None, 'initial_particle_number': '', 'initial_expression': '', 'expression': ''}\n" + ] + } + ], + "source": [ + "# 4. Add the process instance by the name of 'simple_copasi' to the builder\n", + "\n", + "\n", + "b[process_config.process_name].add_process(\n", + " name='CopasiProcess',\n", + " model=process_config.model,\n", + " method=process_config.method\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "id": "b094f1e5-5202-48d0-8bdd-57bbdded7fd1", + "metadata": { + "ExecuteTime": { + "end_time": "2024-03-01T20:26:49.580968Z", + "start_time": "2024-03-01T20:26:49.382861Z" + } + }, + "outputs": [ + { + "data": { + "image/svg+xml": "\n\n\n\n\n\nbigraph\n\n\n\n('simple_copasi', 'interval')\n\ninterval\n\n\n\n('simple_copasi',)\n\nsimple_copasi\n\n\n\n('simple_copasi',)->('simple_copasi', 'interval')\n\n\n\n\n\n('simple_copasi', 't', 'i', 'm', 'e')->('simple_copasi',)\n\n\ntime\n\n\n\n('simple_copasi', 't', 'i', 'm', 'e')->('simple_copasi',)\n\n\ntime\n\n\n\n\n('simple_copasi', 'f', 'l', 'o', 'a', 't', 'i', 'n', 'g', '_', 's', 'p', 'e', 'c', 'i', 'e', 's')->('simple_copasi',)\n\n\nfloating_species\n\n\n\n('simple_copasi', 'f', 'l', 'o', 'a', 't', 'i', 'n', 'g', '_', 's', 'p', 'e', 'c', 'i', 'e', 's')->('simple_copasi',)\n\n\nfloating_species\n\n\n\n\n('simple_copasi', 'm', 'o', 'd', 'e', 'l', '_', 'p', 'a', 'r', 'a', 'm', 'e', 't', 'e', 'r', 's')->('simple_copasi',)\n\n\nmodel_parameters\n\n\n\n\n('simple_copasi', 'r', 'e', 'a', 'c', 't', 'i', 'o', 'n', 's')->('simple_copasi',)\n\n\nreactions\n\n\n\n", + "text/plain": "" + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# visualize shows the process with its disconnected ports\n", + "b.visualize()" + ] + }, + { + "cell_type": "code", + "outputs": [], + "source": [ + "b" + ], + "metadata": { + "collapsed": false + }, + "id": "94ca1656b04afb8", + "execution_count": null + }, + { + "cell_type": "markdown", + "id": "0238392e-5d1f-403d-98c9-785576a0d91b", + "metadata": {}, + "source": [ + "### print ports" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "5ea31425-a8bb-45c3-a31d-77714cc8c137", + "metadata": {}, + "outputs": [], + "source": [ + "b['event_process'].interface(True)" + ] + }, + { + "cell_type": "markdown", + "id": "8068e0af-ebdd-4f01-8c54-4fb3b07fc21e", + "metadata": {}, + "source": [ + "### connect ports using connect_all\n", + "`Builder.connect_all` connects ports to stores of the same name." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c9f462bb-5316-4724-aa8e-b3b71eb379b2", + "metadata": {}, + "outputs": [], + "source": [ + "b.connect_all(append_to_store_name='_store')\n", + "b" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "79809baf-1d87-475a-b85f-3729f4716cb4", + "metadata": {}, + "outputs": [], + "source": [ + "b.visualize()" + ] + }, + { + "cell_type": "markdown", + "id": "c7687da5-6992-447b-a51b-14373984597f", + "metadata": {}, + "source": [ + "### add interval process to the config" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f02c15797bdb73b8", + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "b['interval_process'].add_process(\n", + " name='GillespieInterval',\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "aeb344bcd6a120ae", + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "b.visualize()" + ] + }, + { + "cell_type": "markdown", + "id": "be3f6695-80ed-4819-a121-de29c5cce23e", + "metadata": {}, + "source": [ + "### connect port to specific target" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a5a1f48a-41aa-4768-b931-ad268495d836", + "metadata": {}, + "outputs": [], + "source": [ + "# to connect a port in a more targeted way, use connect and specify the port and its target path\n", + "b['interval_process'].connect(port='interval', target=['event_process', 'interval']) \n", + "\n", + "# the remaining ports can connect_all\n", + "b.connect_all() " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b21b54ae-49e8-47ad-bc88-1327a8e9d230", + "metadata": {}, + "outputs": [], + "source": [ + "b.visualize()" + ] + }, + { + "cell_type": "markdown", + "id": "ed3131ee-c607-42e5-88a3-930a84eedf0f", + "metadata": {}, + "source": [ + "### check current Builder config" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6e00749f-03b8-496e-9a10-106dbac3713f", + "metadata": {}, + "outputs": [], + "source": [ + "b" + ] + }, + { + "cell_type": "markdown", + "id": "9fd708e8-0688-4b97-a50c-e3d0a1c78d83", + "metadata": {}, + "source": [ + "## Update the initial state" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "212f4501-8050-4c39-88b8-986b3c38e716", + "metadata": {}, + "outputs": [], + "source": [ + "initial_state = {\n", + " 'DNA_store': {\n", + " 'A gene': 2.0,\n", + " 'B gene': 1.0},\n", + "}\n", + "b.update(initial_state)" + ] + }, + { + "cell_type": "markdown", + "id": "305582d1-f701-4a55-88a3-f8ec21643033", + "metadata": {}, + "source": [ + "## Generate composite from builder config and simulate" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e9a69f36-154c-416e-b00c-5df0726be49e", + "metadata": {}, + "outputs": [], + "source": [ + "composite = b.generate()\n", + "composite.run(10)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "578492a9-027d-4c5b-b90a-7d63e3f46bc0", + "metadata": {}, + "outputs": [], + "source": [ + "composite" + ] + }, + { + "cell_type": "markdown", + "id": "743960b7-a6d3-41af-8737-2776a66c60cd", + "metadata": {}, + "source": [ + "## Retrieve the composite document" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c975aab012b2706f", + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "doc = b.document()\n", + "doc" + ] + }, + { + "cell_type": "markdown", + "id": "b32a13ed-134d-4de1-a1ed-b72807b4af45", + "metadata": {}, + "source": [ + "### save the document to file" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "752e43636bf9fd17", + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "b.write(filename='toy_bigraph')" + ] + }, + { + "cell_type": "markdown", + "id": "ebdd7599-0b0e-4f79-a8ab-d507a81646d8", + "metadata": { + "ExecuteTime": { + "start_time": "2024-01-21T21:29:22.001943Z" + }, + "collapsed": false + }, + "source": [ + "### load a composite from document\n", + "This document represents the full state of the composite, and so can reproduce the previous composite when loaded into a fresh Builder" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "56b14beb-27de-469d-b4e6-10fc628e15e0", + "metadata": {}, + "outputs": [], + "source": [ + "b2 = Builder(core=core, file_path='out/toy_bigraph.json')\n", + "b2" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6197f4c3-41ca-468b-929f-cc0ebc1fabe9", + "metadata": {}, + "outputs": [], + "source": [ + "b2.visualize()" + ] + }, + { + "cell_type": "markdown", + "source": [], + "metadata": { + "collapsed": false + }, + "id": "b379609c7bc217c0" + }, + { + "cell_type": "code", + "outputs": [], + "source": [], + "metadata": { + "collapsed": false + }, + "id": "2f464e6189bc8287" + }, + { + "cell_type": "markdown", + "source": [ + "### Example 2: Parameter scan composite" + ], + "metadata": { + "collapsed": false + }, + "id": "69529e31211443e0" + }, + { + "cell_type": "code", + "outputs": [], + "source": [], + "metadata": { + "collapsed": false + }, + "id": "c3b55f3424ef4a16" + } + ], + "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.13" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}