{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "edb387b3-ffab-46f9-b608-3a4977cfc2ce",
   "metadata": {},
   "source": [
    "# Characteristic Restraints\n",
    "\n",
    "MobsPy has some restraints for modeling regarding the characteristics combinations.\n",
    "In this model, we will discuss them."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "cc42c2c5-1eb5-45c9-b2e2-94f2b855fd55",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\u001b[91mERROR: The same characteristic can only be shared through inheritance. There are two characteristics directly added to two meta-species \n",
      "Repetition in: C, A \n",
      "Characteristics: {'aaa', 'ccc'}, {'aaa', 'bbb'} \n",
      "\u001b[0m\n"
     ]
    }
   ],
   "source": [
    "from mobspy import *\n",
    "\n",
    "try:\n",
    "    # Here we define two base Species\n",
    "    A, C = BaseSpecies()\n",
    "\n",
    "    # We them add two characteristics to characteristics to each of them\n",
    "    A.aaa, A.bbb\n",
    "    C.aaa, C.ccc\n",
    "\n",
    "    # And add them to the simulation object\n",
    "    MySim = Simulation(A | C)\n",
    "    MySim.compile()\n",
    "except SystemExit:\n",
    "    pass"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b139ce63-e188-42ad-9576-9c084c1f12b7",
   "metadata": {},
   "source": [
    "If one queries for the characteristic \\texttt{aaa}, it is undecidable if the characteristic is the one in the space of meta-species \\texttt{A} or in the space of \\texttt{C}. \n",
    "Therefore, MobsPy gives out an error. \n",
    "If one wants both \\texttt{A} and \\texttt{C} to have access to the characteristic \\texttt{aaa}, the solution is to have them inherit from a common meta-species:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "e4da6c18-1d6b-4eaf-9464-3b91af799539",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Compiling model\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Species\n",
      "A.aaa,0\n",
      "A.bbb,0\n",
      "A.ccc,0\n",
      "C.aaa,0\n",
      "C.bbb,0\n",
      "C.ccc,0\n",
      "\n",
      "Mappings\n",
      "A :\n",
      "A.aaa\n",
      "A.bbb\n",
      "A.ccc\n",
      "C :\n",
      "C.aaa\n",
      "C.bbb\n",
      "C.ccc\n",
      "\n",
      "Parameters\n",
      "volume,1\n",
      "\n",
      "Reactions\n",
      "\n"
     ]
    }
   ],
   "source": [
    "from mobspy import *\n",
    "\n",
    "# Here we define two base Species\n",
    "Base = BaseSpecies()\n",
    "A, C = New(Base)\n",
    "\n",
    "# We add common characteristics to all of them. \n",
    "Base.aaa, Base.bbb, Base.ccc\n",
    "\n",
    "# And add them to the simulation object\n",
    "MySim = Simulation(A | C)\n",
    "print(MySim.compile())"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9d5719ee-29b9-4542-87d8-69a332e90ad9",
   "metadata": {},
   "source": [
    "Note that in this example, all the characteristics \\text{aaa}, \\text{bbb}, and \\text{ccc} share the same space, while in the previous \\text{bbb} and \\text{ccc} where in a different space. "
   ]
  }
 ],
 "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.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
