{ "cells": [ { "cell_type": "markdown", "id": "5cbc8640", "metadata": {}, "source": [ "### Random Networks\n", "\n", "Early implementation" ] }, { "cell_type": "markdown", "id": "5a3fe1d4-ffc9-4db9-ac0f-d51d2231d32b", "metadata": {}, "source": [ "### TAGS : \"uniform compartment\"" ] }, { "cell_type": "code", "execution_count": 1, "id": "97a57e9a-039b-479a-81dc-81399e22743a", "metadata": {}, "outputs": [], "source": [ "LAST_REVISED = \"Feb. 16, 2026\"\n", "LIFE123_VERSION = \"1.0.0rc7\" # Library version this experiment is based on" ] }, { "cell_type": "code", "execution_count": 2, "id": "b5b8a8b0-d417-4432-b6a8-c196af57b105", "metadata": {}, "outputs": [], "source": [ "#import set_path # Using MyBinder? Uncomment this before running the next cell!\n", " # Importing this module will add the project's home directory to sys.path" ] }, { "cell_type": "code", "execution_count": 3, "id": "a29db1c7", "metadata": { "tags": [] }, "outputs": [], "source": [ "#import sys, os\n", "#os.getcwd()\n", "#sys.path.append(\"C:/some_path/my_env_or_install\") # CHANGE to the folder containing your venv or libraries installation!\n", "# NOTE: If any of the imports below can't find a module, uncomment the lines above, or try: import set_path\n", "\n", "import ipynbname\n", "\n", "from life123 import check_version, RandomReactionNetwork, UniformCompartment" ] }, { "cell_type": "code", "execution_count": 4, "id": "ccd6701b-ae96-4d20-b537-40c2c40df9aa", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "OK\n" ] } ], "source": [ "check_version(LIFE123_VERSION) # To check compatibility" ] }, { "cell_type": "code", "execution_count": 5, "id": "25281125-fcea-4cae-b5fd-790810e87200", "metadata": { "tags": [] }, "outputs": [], "source": [ "# Initialize the HTML logging (for the graphics)\n", "log_file = ipynbname.name() + \".log.htm\" # Use the notebook base filename for the log file\n", " # IN CASE OF PROBLEMS, set manually to any desired name" ] }, { "cell_type": "code", "execution_count": null, "id": "e4047c5b-3d34-43ca-95db-334435f7e8fe", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "id": "e104bbb5-f0a9-41d2-a2a2-9e2d8e0ef522", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "id": "e0529a0c", "metadata": {}, "source": [ "## Set up Random Network (no thermodynamic nor kinetic data)" ] }, { "cell_type": "code", "execution_count": 6, "id": "c95bf9b8-e8bb-4c4d-ad92-8777768d03d1", "metadata": { "tags": [] }, "outputs": [], "source": [ "net = RandomReactionNetwork(n_chems=4, n_rxns=6)" ] }, { "cell_type": "code", "execution_count": 7, "id": "ac9eea69-174c-43e5-9eed-443cbc5e2ba7", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['A', 'B', 'C', 'D']" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "net.chem_data.get_all_labels()" ] }, { "cell_type": "markdown", "id": "33af1a01-644b-4acf-808e-ff8c4bd3d0aa", "metadata": {}, "source": [ "### The above chemical labels were auto-generated" ] }, { "cell_type": "code", "execution_count": 8, "id": "7f59733f", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "6" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "net.registry.number_of_reactions()" ] }, { "cell_type": "code", "execution_count": 9, "id": "cf6e1c21-1627-4b97-8bcc-343911099cdd", "metadata": { "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "(0) D + B <-> A Elementary Synthesis reaction\n", "(1) A + D <-> B Elementary Synthesis reaction\n", "(2) C + A <-> B Elementary Synthesis reaction\n", "(3) 2 A <-> B Elementary Synthesis reaction\n", "(4) A + B <-> C Elementary Synthesis reaction\n", "(5) C <-> A + D Elementary Decomposition reaction\n" ] } ], "source": [ "for i in range(net.registry.number_of_reactions()):\n", " rxn = net.registry.get_reaction(i)\n", " print(f\"({i}) {rxn.describe(concise=False)}\")" ] }, { "cell_type": "code", "execution_count": null, "id": "eed8d982-d551-4790-ab4d-c20012f55466", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 10, "id": "2520814f-9cd4-401a-a81b-ef765d1f62f4", "metadata": { "tags": [] }, "outputs": [], "source": [ "# Instantiate the simulator with our chemicals and reactions\n", "uc = UniformCompartment(reactions=net.registry)" ] }, { "cell_type": "code", "execution_count": null, "id": "52084745-7a4a-4c00-b51b-81d9c2f157e7", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 11, "id": "aab2d30b-ccdc-4fbf-a338-f47769406e4b", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[GRAPHIC ELEMENT SENT TO FILE `random_networks_1.log.htm`]\n" ] } ], "source": [ "# Send a plot of the network of reactions to the HTML log file\n", "uc.plot_reaction_network(log_file=log_file)" ] } ], "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.11.9" } }, "nbformat": 4, "nbformat_minor": 5 }