{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "60f55f9d-109f-4f99-baf8-ace2f515a391",
   "metadata": {},
   "source": [
    "Copyright (c) 2025 Mitsuru Ohno  \n",
    "Use of this source code is governed by a BSD-3-style  \n",
    "license that can be found in the LICENSE file.  "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c79ad42b",
   "metadata": {},
   "source": [
    "## 当ノートブックのワークフロー  \n",
    "1. csvに書き込んだ反応式を読み込む。ただし速度定数はすべて既知とする  \n",
    "2. 化学種ごとの微分型の反応速度式を作成する  \n",
    "3. 作成した微分方程式を出力する  "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8b93b632-c08e-4830-8469-66ba36f363fb",
   "metadata": {},
   "source": [
    "## 記号的な操作による微分型の反応速度式を反応式から生成する場合  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "f1616341-c3ba-463f-8abb-6379c0f76cf9",
   "metadata": {},
   "outputs": [],
   "source": [
    "file_path = './sample_data/sample_rxn_ref1.csv'  # CSVファイルのパスを指定"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "b966b7fc-84e8-46b7-b9c7-a99552f36af4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'encoding': 'utf-8',\n",
      " 'file_path': './sample_data/sample_rxn_ref1.csv',\n",
      " 'function_names': ['AcOEt',\n",
      "                    'OHa1',\n",
      "                    'AcOa1',\n",
      "                    'EtOH',\n",
      "                    'AcOiPr',\n",
      "                    'iPrOH',\n",
      "                    'EGOAc2',\n",
      "                    'EG'],\n",
      " 'functions_dict': {'AcOEt': AcOEt,\n",
      "                    'AcOa1': AcOa1,\n",
      "                    'AcOiPr': AcOiPr,\n",
      "                    'EG': EG,\n",
      "                    'EGOAc2': EGOAc2,\n",
      "                    'EtOH': EtOH,\n",
      "                    'OHa1': OHa1,\n",
      "                    'iPrOH': iPrOH},\n",
      " 'rate_consts_dict': {'k1': 0.054, 'k2': 0.044, 'k3': 0.031},\n",
      " 'reactant_eq': [[['1', 0.054],\n",
      "                  [['', 'AcOEt'], ['', 'OHa1']],\n",
      "                  [['', 'AcOa1'], ['', 'EtOH']],\n",
      "                  [],\n",
      "                  ['k1*AcOEt(t)*OHa1(t)', ['', ''], ['', '']]],\n",
      "                 [['2', 0.044],\n",
      "                  [['', 'AcOiPr'], ['', 'OHa1']],\n",
      "                  [['', 'AcOa1'], ['', 'iPrOH']],\n",
      "                  [],\n",
      "                  ['k2*AcOiPr(t)*OHa1(t)', ['', ''], ['', '']]],\n",
      "                 [['3', 0.031],\n",
      "                  [['', 'EGOAc2'], ['2', 'OHa1']],\n",
      "                  [['2', 'AcOa1'], ['', 'EG']],\n",
      "                  [],\n",
      "                  ['k3*EGOAc2(t)*OHa1(t)**2', ['', '2'], ['2', '']]]],\n",
      " 'sympy_symbol_dict': {'AcOEt': AcOEt,\n",
      "                       'AcOa1': AcOa1,\n",
      "                       'AcOiPr': AcOiPr,\n",
      "                       'Derivative': <class 'sympy.core.function.Derivative'>,\n",
      "                       'EG': EG,\n",
      "                       'EGOAc2': EGOAc2,\n",
      "                       'EtOH': EtOH,\n",
      "                       'OHa1': OHa1,\n",
      "                       'iPrOH': iPrOH,\n",
      "                       'k1': 0.054,\n",
      "                       'k2': 0.044,\n",
      "                       'k3': 0.031,\n",
      "                       't': t},\n",
      " 'sys_odes_dict': {'AcOEt': '-k1*AcOEt(t)*OHa1(t)',\n",
      "                   'AcOa1': 'k1*AcOEt(t)*OHa1(t)+k2*AcOiPr(t)*OHa1(t)+2*k3*EGOAc2(t)*OHa1(t)**2',\n",
      "                   'AcOiPr': '-k2*AcOiPr(t)*OHa1(t)',\n",
      "                   'EG': 'k3*EGOAc2(t)*OHa1(t)**2',\n",
      "                   'EGOAc2': '-k3*EGOAc2(t)*OHa1(t)**2',\n",
      "                   'EtOH': 'k1*AcOEt(t)*OHa1(t)',\n",
      "                   'OHa1': '-k1*AcOEt(t)*OHa1(t)-k2*AcOiPr(t)*OHa1(t)-2*k3*EGOAc2(t)*OHa1(t)**2',\n",
      "                   'iPrOH': 'k2*AcOiPr(t)*OHa1(t)'},\n",
      " 't': t}\n"
     ]
    }
   ],
   "source": [
    "# 記号的な操作による基本的なODE生成\n",
    "from pprint import pprint\n",
    "from rxnfit.rxn_reader import RxnToODE\n",
    "\n",
    "# ファイルパスを指定するだけで自動的に処理される\n",
    "rxn_to_ode = RxnToODE(file_path)\n",
    "# または\n",
    "# rxn_to_ode = RxnToODE(\"sample_data.csv\", encoding=\"shift_jis\")\n",
    "pprint(vars(rxn_to_ode))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "00a8b02d-8df6-4dcd-a074-2f65639da3f0",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "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.13.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
