{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "dbac9fd1-6de0-4b42-bc80-9e0c98d7515a",
   "metadata": {},
   "source": [
    "# Characteristics\n",
    "\n",
    "Characteristics are the units combined to generate meta-species states. \n",
    "They allow for the construction of reactions through queries in both the products and the reactants. \n",
    "\n",
    "Characteristics can be added using the dot operator to a meta-species.\n",
    "They can be added implicitly inside a reaction and explicitly outside of one. When added implicitly, the characteristics will automatically partake in the reaction. An example follows: "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "8a97e372-3f01-40f2-b3fc-c2309ba74efa",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<mobspy.modules.meta_class.Reactions at 0x7ff51e2a9670>"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from mobspy import *\n",
    "\n",
    "Age, Color = BaseSpecies()\n",
    "\n",
    "Color.blue, Color.red, Color.yellow\n",
    "Age.young >> Age.old [1]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bbf5bfc3-cd90-492c-a5a2-a0f47d22f689",
   "metadata": {},
   "source": [
    "We now multiply Age and Color to create a Dummy meta-species that inherits from both of them. \n",
    "In MobsPy, inheritance is not only for reactions but also for characteristics. \n",
    "Thus, the Dummy meta-species will inherit all of the characteristics from the meta-species used to create it. \n",
    "Further, the states of the meta-species are constructed using all possible orthogonal combinations of characteristics coming from different inheritors."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "cf2fc33f-e028-4090-9f35-c3a8f6a6fc33",
   "metadata": {},
   "outputs": [],
   "source": [
    "Dummy = Age*Color"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "71980e63-98e4-4190-a615-a243ec772079",
   "metadata": {},
   "source": [
    "The Dummy meta-species can be in the following states:\n",
    "\n",
    "Dummy.blue.young, \\\n",
    "Dummy.blue.old, \\\n",
    "Dummy.red.young, \\\n",
    "Dummy.red.old, \\\n",
    "Dummy.yellow.young, \\\n",
    "Dummy.yellow.old\n",
    "\n",
    "One can query the meta-species that Dummy represents using characteristics.\n",
    "If the query is present on a reactant, it filters through the states that do not possess the requested characteristic.\n",
    "As an example, the meta-reaction:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "21118e41-f9f2-478b-bd73-9cf6ce5d4646",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<mobspy.modules.meta_class.Reactions at 0x7ff51e280e50>"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Dummy.old >> Zero [1]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3e019470-03f4-47c6-82e8-67f27501ab22",
   "metadata": {},
   "source": [
    "Defines the following reactions:\n",
    "\n",
    "Dummy.red.old -> \\\n",
    "Dummy.yellow.old -> \\\n",
    "Dummy.blue.old ->"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "366c3b80-97d9-44d3-8c07-0e7e1f4fb7a5",
   "metadata": {},
   "source": [
    "One can also perform a query in the products. When performed in the products, the query specifies in which characteristics space one wishes the transformation to occur. \n",
    "Characteristic spaces are spaces shared by characteristics coming from the same inheritor, with the spaces being defined by the characteristics that were initially added to that species. \n",
    "The Dummy meta species also has an empty characteristic space, as it obtained all its characteristics from inheritance.\n",
    "\n",
    "As an example, the meta-reaction: "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "96ceda1e-c397-4e01-a815-bc7a262d2619",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<mobspy.modules.meta_class.Reactions at 0x7ff523a39ca0>"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Dummy >> Dummy.blue [1]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f294a057-6ab7-4b44-8b0f-7901c3f4deae",
   "metadata": {},
   "source": [
    "Uses the characteristic space of meta-species Color to define the following reactions:\n",
    "\n",
    "Dummy.red.young -> Dummy.blue.young \\\n",
    "Dummy.red.old -> Dummy.blue.old \\\n",
    "Dummy.blue.young -> Dummy.blue.young \\\n",
    "Dummy.blue.old -> Dummy.blue.old \\\n",
    "Dummy.yellow.young -> Dummy.blue.young \\\n",
    "Dummy.yellow.old -> Dummy.blue.old\n",
    "\n",
    "Thus, by querying the blue characteristic in the products, one has specified that he wishes that the color characteristic transforms into blue.\n",
    "\n",
    "It is also possible to query over multiple characteristics at the same time, and the order is irrelevant.\n",
    "\n",
    "We finish by compiling the model to visualize all the reactions in detail:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "4e3d95b8-ec1a-4969-87a0-93b39a421160",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Compiling model\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Species\n",
      "Dummy.blue.old,0\n",
      "Dummy.blue.young,0\n",
      "Dummy.red.old,0\n",
      "Dummy.red.young,0\n",
      "Dummy.yellow.old,0\n",
      "Dummy.yellow.young,0\n",
      "\n",
      "Mappings\n",
      "Dummy :\n",
      "Dummy.blue.old\n",
      "Dummy.blue.young\n",
      "Dummy.red.old\n",
      "Dummy.red.young\n",
      "Dummy.yellow.old\n",
      "Dummy.yellow.young\n",
      "\n",
      "Parameters\n",
      "volume,1\n",
      "\n",
      "Reactions\n",
      "reaction_0,{'re': [(1, 'Dummy.blue.old')], 'pr': [(1, 'Dummy.blue.old')], 'kin': 'Dummy.blue.old * 1'}\n",
      "reaction_1,{'re': [(1, 'Dummy.blue.old')], 'pr': [], 'kin': 'Dummy.blue.old * 1'}\n",
      "reaction_2,{'re': [(1, 'Dummy.blue.young')], 'pr': [(1, 'Dummy.blue.old')], 'kin': 'Dummy.blue.young * 1'}\n",
      "reaction_3,{'re': [(1, 'Dummy.blue.young')], 'pr': [(1, 'Dummy.blue.young')], 'kin': 'Dummy.blue.young * 1'}\n",
      "reaction_4,{'re': [(1, 'Dummy.red.old')], 'pr': [(1, 'Dummy.blue.old')], 'kin': 'Dummy.red.old * 1'}\n",
      "reaction_5,{'re': [(1, 'Dummy.red.old')], 'pr': [], 'kin': 'Dummy.red.old * 1'}\n",
      "reaction_6,{'re': [(1, 'Dummy.red.young')], 'pr': [(1, 'Dummy.blue.young')], 'kin': 'Dummy.red.young * 1'}\n",
      "reaction_7,{'re': [(1, 'Dummy.red.young')], 'pr': [(1, 'Dummy.red.old')], 'kin': 'Dummy.red.young * 1'}\n",
      "reaction_8,{'re': [(1, 'Dummy.yellow.old')], 'pr': [(1, 'Dummy.blue.old')], 'kin': 'Dummy.yellow.old * 1'}\n",
      "reaction_9,{'re': [(1, 'Dummy.yellow.old')], 'pr': [], 'kin': 'Dummy.yellow.old * 1'}\n",
      "reaction_10,{'re': [(1, 'Dummy.yellow.young')], 'pr': [(1, 'Dummy.blue.young')], 'kin': 'Dummy.yellow.young * 1'}\n",
      "reaction_11,{'re': [(1, 'Dummy.yellow.young')], 'pr': [(1, 'Dummy.yellow.old')], 'kin': 'Dummy.yellow.young * 1'}\n",
      "\n"
     ]
    }
   ],
   "source": [
    "S = Simulation(Dummy)\n",
    "print(S.compile())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3f67b1bd-e81c-4f51-af2e-2319ea43bef6",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "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
}
