{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "735be567-ef26-49fd-b46f-67af1f3bee26",
   "metadata": {
    "tags": []
   },
   "source": [
    "<center><h1> Determination of the best chromatography type </h1></center>\n",
    "    \n",
    "## **Introduction**\n",
    "\n",
    "<p style=\"text-align: justify;\"> Chromatography is a crucial analytical method in chemistry used for separating, identifying, and quantifying components in a mixture. Selecting the appropriate type of chromatography (e.g., gas chromatography, liquid chromatography, ion chromatography, size exclusion chromatography) is essential for optimal results. This is why we decided to <b>create a programming tool that allows to determine easily the chromatpgraphy type as well as the best eluent and conditions needed to carry out the chromatography</b>. <br>\n",
    "This report details the development and execution of a programming project aimed at creating a tool to determine the most suitable chromatography technique for analyzing a given mixture of molecules. The project was conducted using python 3.10. The <b> different functions created to make this tool are listed </b> in this notebook. <br>\n",
    "To carry out this project, PubChem has been used as a data base in order to extract all the important information that were needed to establish the best chromatography type (boiling_point, pka, LogP, Molar Weight). Then, a function that takes into account all the different information contained in a dataframe has been created and finaly, a user interface has been created.\n",
    "\n",
    "## **Objectives**\n",
    "\n",
    "The primary objective of this project was to develop a program that:\n",
    "\n",
    "- Determine physicochemical properties from PubChem input data on the molecular composition of a mixture.\n",
    "- Store the properties\n",
    "- Recommends the most suitable chromatography technique based on predefined criteria and standards.\n",
    "\n",
    "## **References**\n",
    "\n",
    "- Pubchemprops: <b>Github repo of mawansui </b> (https://github.com/mawansui/pubchemprops) used to retrieve most of the properties of the molecules from Pubchem\n",
    "- pka_lookup.py: <b>Github repo of Khoivan88 </b> (https://github.com/khoivan88/pka_lookup) which request the needed dictionnary of pka on PubChem.\n",
    " "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ad65be8b-91a5-4967-b308-d1240b963934",
   "metadata": {
    "tags": []
   },
   "source": [
    "## **Methodology**"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b66a1e56-b03d-49c0-8b6c-617a9a99a2d4",
   "metadata": {},
   "source": [
    "### 1. Graphical User Interface ###\n",
    "\n",
    "<p style=\"text-align: justify;\">A simple user interface was developed using Tkinter, allowing users to input the name of several molecules and obtain chromatography recommendations. The user can give molecule names that will be added to a listbox to keep in mind the different molecules in the mixture. The user then decides to determine the best chromatography type that will be indicated on the interface using the \"Determine Chromatography\" button. If an error occurs, an error message will be displayed using a message box on the user interface."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ba83b8eb-0577-4442-8682-cd0c5ef6aa9d",
   "metadata": {},
   "source": [
    "<div style=\"display: flex; justify-content: center; align-items: center; padding: 20px;\">\n",
    "    <div style=\"margin: 10px;\">\n",
    "        <img src=\"../assets/edited-hydrocarbure.gif\" alt=\"hydrocarbures\" style=\"width: 400px; height: auto;\">\n",
    "    </div>\n",
    "    <div style=\"margin: 10px;\">\n",
    "        <img src=\"../assets/edited-naphtalene-.gif\" alt=\"HPLCexample\" style=\"width: 400px; height: auto;\">\n",
    "    </div>\n",
    "</div>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bde3e92d-ce16-4a6e-89ff-ad6d621f70b8",
   "metadata": {},
   "source": [
    "These two examples show how the results appear on the user ineterface when molecules are added. Above, two different mixtures are given, hence, two different results appear on the screen."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d8118e51-91b4-41d6-a303-a0eae89b3c70",
   "metadata": {
    "tags": []
   },
   "source": [
    "\n",
    "### 2. Data Collection and Preparation ###\n",
    "<p style=\"text-align: justify;\">\n",
    "A dataset containing various molecular properties (e.g., molecular weight, polarity, solubility) and corresponding successful chromatography types was compiled.\n",
    "Data preprocessing included handling missing values such as the pKa values. Relevant features such as molecular weight, polarity index, boiling point, pKa and solubility were selected and added to a data frame. \n",
    "\n",
    "First we import the function from the Chrfinder.py file."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "08bcc299-5b14-4a88-8455-90bd7ef10588",
   "metadata": {},
   "outputs": [],
   "source": [
    "from Chrfinder import find_pka, find_boiling_point, get_df_properties"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "df5e4f23-2ee9-4816-b9b5-5ac234b8a6ff",
   "metadata": {},
   "source": [
    "Then we can create a list of compounds, which will normally be done by tkinter."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "73032b6f-f8b4-4076-9271-e1359b43e573",
   "metadata": {},
   "outputs": [],
   "source": [
    "mixture = [\"caffeine\", \"Aspirin\", \"Maleic acid\"]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8c2ddb05-0eb8-40c3-a789-030304e24aea",
   "metadata": {},
   "source": [
    "Then we run and print the dataframe:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "bd39dd45-18df-42e6-89dd-5cd5599c9578",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "      CID MolecularFormula  MolecularWeight                     InChIKey  \\\n",
      "0    2519        C8H10N4O2           194.19  RYYVLZVUVIJVGH-UHFFFAOYSA-N   \n",
      "1    2244           C9H8O4           180.16  BSYNRYMUTXBXSQ-UHFFFAOYSA-N   \n",
      "2  444266           C4H4O4           116.07  VZCYOOQTPOCHFL-UPHRSURJSA-N   \n",
      "\n",
      "                         IUPACName  XLogP    pKa  Boiling Point  \n",
      "0  1,3,7-trimethylpurine-2,6-dione   -0.1  14.00         177.93  \n",
      "1          2-acetyloxybenzoic acid    1.2   3.47         140.00  \n",
      "2          (Z)-but-2-enedioic acid   -0.3   1.83         135.00  \n",
      "      CID MolecularFormula  MolecularWeight                     InChIKey  \\\n",
      "0    2519        C8H10N4O2           194.19  RYYVLZVUVIJVGH-UHFFFAOYSA-N   \n",
      "1    2244           C9H8O4           180.16  BSYNRYMUTXBXSQ-UHFFFAOYSA-N   \n",
      "2  444266           C4H4O4           116.07  VZCYOOQTPOCHFL-UPHRSURJSA-N   \n",
      "\n",
      "                         IUPACName  XLogP    pKa  Boiling Point  \n",
      "0  1,3,7-trimethylpurine-2,6-dione   -0.1  14.00         177.93  \n",
      "1          2-acetyloxybenzoic acid    1.2   3.47         140.00  \n",
      "2          (Z)-but-2-enedioic acid   -0.3   1.83         135.00  \n"
     ]
    }
   ],
   "source": [
    "print(get_df_properties(mixture))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b7b676ba-e6c2-48df-8a86-ddccaed0aba3",
   "metadata": {},
   "source": [
    "### 3. Determination of the chromatography type ###\n",
    "<p style=\"text-align: justify;\">\n",
    "A function has been created to determine the most suitable chromatography type based on the physical-chemical properties of the molecules saved on a data frame. To do this the following dependencies has tp be installed:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "7a7d1026-916e-4344-b274-cbe2307aa908",
   "metadata": {},
   "outputs": [],
   "source": [
    "import sys\n",
    "import os\n",
    "notebook_path = os.getcwd()  # Get the current working directory\n",
    "src_path = os.path.abspath(os.path.join(notebook_path, \"../src/Chrfinder\"))\n",
    "sys.path.insert(0, src_path)\n",
    "\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "10944839-7ac6-435a-9edf-62dbd6e8048c",
   "metadata": {},
   "source": [
    "Pandas will create a data frame from a dictionary as follows:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "7f094ec3-9b8b-41fd-a2f2-81dbb7902319",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  Mixture  Boiling Point  XLogP           pKa  MolecularWeight\n",
      "0     Caf          178.0  -0.07          [14]              194\n",
      "1     Ace          332.7  -1.33        [3.02]              204\n",
      "2     Asp          246.0   0.07  [1.08, 9.13]              133\n"
     ]
    }
   ],
   "source": [
    "data = {\n",
    "    'Mixture': ['Caf', 'Ace', 'Asp'],\n",
    "    'Boiling Point': [178, 332.7, 246],\n",
    "    'XLogP': [-0.07, -1.33, 0.07],\n",
    "    'pKa': [[14], [3.02], [1.08, 9.13]],\n",
    "    'MolecularWeight': [194, 204, 133],\n",
    "}\n",
    "\n",
    "df = pd.DataFrame(data)\n",
    "print(df)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d69fb945-57d1-4e1f-906e-d1cc113b0a99",
   "metadata": {},
   "source": [
    "As can be seen in the second column it is indicated the names of all the molecules from the mixture. Then the properties used by the function are the boiling point in [°C], the XlogP, the pKa and the molecular weight in [g/mol].\n",
    "\n",
    "Following an example of the functionality of the function:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "ee77c155-6de2-479a-8ea5-ca6cc02e6155",
   "metadata": {},
   "outputs": [],
   "source": [
    "from Chrfinder import det_chromato\n",
    "Mixture_chromato_type, eluent_nature, proposed_pH = det_chromato(df)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cd195f3c-74ab-4bf2-b55e-fdb5f3c0dbe9",
   "metadata": {},
   "source": [
    "The function will look up column per column in the data frame and search the maximum or the minimum of each fisical or chemical properties. Based on that it start to predict the best chromatogrphy to perform:\n",
    "\n",
    "The GC will be performed if the max **boiling temperature** of the mixture is under 250 °C, this will ensure the high volatility of the mixture.\n",
    "\n",
    "The **molar weight** will indicate if the steric exclusion chromatography is allowed or not. It is suitable for heavy molecules, thus for the compounds in the mixture with a mass larger than 2000 g/mol.\n",
    "\n",
    "The choice between high pressure liquid chromatography (HPLC) and ionic chromatography (IC) is determined by the **XlogP**, wich is an indicator of the hydrophilicity of the molecules. Negative values for the **XlogP** indicates that the molecule is likely to dissolve in water (thus hydrophile), positive values indicates that the molecule is more likely to dissolve in organic solvents (thus hydrofobe). Therefore the more hydrophile is the molecule the more likely it will ionize, hence the suitable chromatography will be IC. \n",
    "\n",
    "In the liquid chromatography such as HPLC or IC the pH of the eluent is an important parameter which can lead to a good separation. All the molecules have to be stable at this pH otherwise they can degrade and the separation will not be good. to ensure the stability of the molecules, the function propose a pH wich is 2 values above the minimum **pKa** of the mixture compunds."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "f64f399d-3b03-4c94-84cc-3e0ccf46862c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The advisable chromatography type is: HPLC on reverse stationary phase using C18 column\n",
      "Eluent nature: organic or hydro-organic\n",
      "Proposed pH for the eluent: 3.08\n"
     ]
    }
   ],
   "source": [
    "print(f\"The advisable chromatography type is: {Mixture_chromato_type}\")\n",
    "print(f\"Eluent nature: {eluent_nature}\")\n",
    "if proposed_pH is not None:\n",
    "    print(f\"Proposed pH for the eluent: {proposed_pH}\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e699e4ea-0fdf-41a6-8443-96c345fe6cf2",
   "metadata": {},
   "source": [
    "### 4. Explanation of each part of get_df_properties(mixture) (c.f. Methodology.2.) ###\n",
    "#### Getting 'CID', 'MolecularFormula', 'MolecularWeight', 'InChIKey', 'IUPACName', 'XLogP' using PubChem requests \n",
    "(only missing Boiling Point and pka)\n",
    "\n",
    "This part of the code uses pubchempy and the code of *Maxim Shevelev* (pubchemprops.py) to easily find most of the properties. It takes into arguments a list of compound's names. It will return a dictionnary for each compound with the following properties: 'CID', 'MolecularFormula', 'MolecularWeight', 'InChIKey', 'IUPACName', 'XLogP'.\n",
    "\n",
    "The tkinter interface returns a list of compounds as string. The first part of the code iterates through the whole list (compound_list), and encodes every compound name (string) as URL. Then it will search for the properties on pubchem using pubchempy and add them into a dictionnary."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "954d86e1-1d89-477d-9feb-aed0a541dc01",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'CID': 2519, 'MolecularFormula': 'C8H10N4O2', 'MolecularWeight': 194.19, 'InChIKey': 'RYYVLZVUVIJVGH-UHFFFAOYSA-N', 'IUPACName': '1,3,7-trimethylpurine-2,6-dione', 'XLogP': -0.1}\n",
      "{'CID': 134601, 'MolecularFormula': 'C14H18N2O5', 'MolecularWeight': 294.3, 'InChIKey': 'IAOZJIPTCAWIRG-QWRGUYRKSA-N', 'IUPACName': '(3S)-3-amino-4-[[(2S)-1-methoxy-1-oxo-3-phenylpropan-2-yl]amino]-4-oxobutanoic acid', 'XLogP': -2.7}\n",
      "{'CID': 11074431, 'MolecularFormula': 'C4H4KNO4S', 'MolecularWeight': 201.24, 'InChIKey': 'WBZFUFAFFUEMEI-UHFFFAOYSA-M', 'IUPACName': 'potassium;6-methyl-2,2-dioxo-1-oxa-2lambda6-thia-3-azanidacyclohex-5-en-4-one', 'XLogP': None}\n",
      "        CID MolecularFormula  MolecularWeight                     InChIKey  \\\n",
      "0      2519        C8H10N4O2           194.19  RYYVLZVUVIJVGH-UHFFFAOYSA-N   \n",
      "1    134601       C14H18N2O5           294.30  IAOZJIPTCAWIRG-QWRGUYRKSA-N   \n",
      "2  11074431        C4H4KNO4S           201.24  WBZFUFAFFUEMEI-UHFFFAOYSA-M   \n",
      "\n",
      "                                           IUPACName  XLogP    pKa  \\\n",
      "0                    1,3,7-trimethylpurine-2,6-dione   -0.1  14.00   \n",
      "1  (3S)-3-amino-4-[[(2S)-1-methoxy-1-oxo-3-phenyl...   -2.7   3.19   \n",
      "2  potassium;6-methyl-2,2-dioxo-1-oxa-2lambda6-th...    NaN    NaN   \n",
      "\n",
      "   Boiling Point  \n",
      "0         177.93  \n",
      "1            NaN  \n",
      "2            NaN  \n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>CID</th>\n",
       "      <th>MolecularFormula</th>\n",
       "      <th>MolecularWeight</th>\n",
       "      <th>InChIKey</th>\n",
       "      <th>IUPACName</th>\n",
       "      <th>XLogP</th>\n",
       "      <th>pKa</th>\n",
       "      <th>Boiling Point</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2519</td>\n",
       "      <td>C8H10N4O2</td>\n",
       "      <td>194.19</td>\n",
       "      <td>RYYVLZVUVIJVGH-UHFFFAOYSA-N</td>\n",
       "      <td>1,3,7-trimethylpurine-2,6-dione</td>\n",
       "      <td>-0.1</td>\n",
       "      <td>14.00</td>\n",
       "      <td>177.93</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>134601</td>\n",
       "      <td>C14H18N2O5</td>\n",
       "      <td>294.30</td>\n",
       "      <td>IAOZJIPTCAWIRG-QWRGUYRKSA-N</td>\n",
       "      <td>(3S)-3-amino-4-[[(2S)-1-methoxy-1-oxo-3-phenyl...</td>\n",
       "      <td>-2.7</td>\n",
       "      <td>3.19</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>11074431</td>\n",
       "      <td>C4H4KNO4S</td>\n",
       "      <td>201.24</td>\n",
       "      <td>WBZFUFAFFUEMEI-UHFFFAOYSA-M</td>\n",
       "      <td>potassium;6-methyl-2,2-dioxo-1-oxa-2lambda6-th...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        CID MolecularFormula  MolecularWeight                     InChIKey  \\\n",
       "0      2519        C8H10N4O2           194.19  RYYVLZVUVIJVGH-UHFFFAOYSA-N   \n",
       "1    134601       C14H18N2O5           294.30  IAOZJIPTCAWIRG-QWRGUYRKSA-N   \n",
       "2  11074431        C4H4KNO4S           201.24  WBZFUFAFFUEMEI-UHFFFAOYSA-M   \n",
       "\n",
       "                                           IUPACName  XLogP    pKa  \\\n",
       "0                    1,3,7-trimethylpurine-2,6-dione   -0.1  14.00   \n",
       "1  (3S)-3-amino-4-[[(2S)-1-methoxy-1-oxo-3-phenyl...   -2.7   3.19   \n",
       "2  potassium;6-methyl-2,2-dioxo-1-oxa-2lambda6-th...    NaN    NaN   \n",
       "\n",
       "   Boiling Point  \n",
       "0         177.93  \n",
       "1            NaN  \n",
       "2            NaN  "
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from Chrfinder.Chrfinder import get_df_properties\n",
    "\n",
    "compound_list = [\"caffeine\", \"Aspartame\", \"Acesulfame K\"]\n",
    "#Delete '#' for a list with a wrong name\n",
    "#compound_list = [\"Water\", \"Acetone\", \"Wrong name\"]\n",
    "\n",
    "get_df_properties(compound_list, verbose = True)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b6138509-2218-4a73-93b0-72d6ff46dd99",
   "metadata": {},
   "source": [
    "#### <ins> Finding pka using Pubchem from InchiKey String</ins>\n",
    "\n",
    "Using the InchiKey String found by the function right before, the following function **returns the first pka found on PubChem as string**. This value, similary to the Boiling temperature, is a lot harder to find. This script uses a file of *Khoi Van* named **pka_lookup.py** which request the needed dictionnary of strings on PubChem. This means it takes **quite a while to find the string**, but creating a database is in scope. \n",
    "\n",
    "From the string found, this code extracts the pka_value from the dictionnary and returns the value as a string which will be converted in float in the function of Chrfinder.py."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "56af93f0-23b1-4c1d-87ea-0e14d7ada4fd",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'source': 'Pubchem', 'Pubchem_CID': '2519', 'pKa': '14', 'reference': 'https://www.sigmaaldrich.com/content/dam/sigma-aldrich/docs/Sigma-Aldrich/Product_Information_Sheet/c0750pis.pdf', 'Substance_CASRN': '58-08-2', 'Canonical_SMILES': 'CN1C=NC2=C1C(=O)N(C(=O)N2C)C', 'Isomeric_SMILES': 'CN1C=NC2=C1C(=O)N(C(=O)N2C)C', 'InChI': 'InChI=1S/C8H10N4O2/c1-10-4-9-6-5(10)7(13)12(3)8(14)11(6)2/h4H,1-3H3', 'InChIKey': 'RYYVLZVUVIJVGH-UHFFFAOYSA-N', 'IUPAC_Name': '1,3,7-trimethylpurine-2,6-dione'}\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "'14'"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from Chrfinder.Chrfinder import find_pka\n",
    "\n",
    "#inchikey of caffeine\n",
    "inchikey_string = 'RYYVLZVUVIJVGH-UHFFFAOYSA-N'\n",
    "\n",
    "find_pka(inchikey_string, verbose=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e85c78ef-6b74-4c76-b52d-2c0ee46eb94b",
   "metadata": {},
   "source": [
    "#### <ins> Finding Boiling Temperature using Pubchem from name</ins>\n",
    "\n",
    "Using the names of compound_list, the following function **returns the mean of the celsius and Fahrenheit Boiling Temperatures found on PubChem as float**. This value, similary to the Boiling temperature, is a lot harder to find. This script uses a file of *Maxim Shevelev* named **pubchemprops.py** which request the needed dictionnary of strings on PubChem. This means it takes **quite a while to find the string**, but creating a database is in scope. \n",
    "\n",
    "From the string_value in text_dict (extracted from PubChem), this code extracts all the boiling points from the dictionnary and returns the mean after converting Fahrenheit in celsius. The output is a float with 2 decimals."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "e749f89d-f77b-4ed8-b250-1fbf4b7c3718",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'Boiling Point': [{'ReferenceNumber': 2, 'Reference': ['National Toxicology Program, Institute of Environmental Health Sciences, National Institutes of Health (NTP). 1992. National Toxicology Program Chemical Repository Database. Research Triangle Park, North Carolina.'], 'Value': {'StringWithMarkup': [{'String': '352 °F at 760 mmHg (sublimes) (NTP, 1992)'}]}}, {'ReferenceNumber': 24, 'Reference': ['http://www.inchem.org/documents/icsc/icsc/eics0405.htm'], 'Value': {'Number': [178]}}, {'ReferenceNumber': 51, 'Description': 'PEER REVIEWED', 'Reference': [\"O'Neil, M.J. (ed.). The Merck Index - An Encyclopedia of Chemicals, Drugs, and Biologicals. Cambridge, UK:  Royal Society of Chemistry, 2013., p. 289\"], 'Value': {'StringWithMarkup': [{'String': '178 °C (sublimes)'}]}}, {'ReferenceNumber': 71, 'Value': {'StringWithMarkup': [{'String': '178 °C (sublimes)'}]}}], 'Vapor Pressure': [{'ReferenceNumber': 49, 'Value': {'StringWithMarkup': [{'String': '0.00000001 [mmHg]'}]}}, {'ReferenceNumber': 51, 'Description': 'PEER REVIEWED', 'Reference': [\"Emel'yanenko VN, Verevkin SP; J Chem Thermodynamics 40: 1661-1665 (2008)\"], 'Value': {'StringWithMarkup': [{'String': '9.0X10-7 mm Hg at 25 °C /Extrapolated/'}]}}]}\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "177.93"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from Chrfinder.Chrfinder import find_boiling_point\n",
    "\n",
    "mixture = \"Caffeine\"\n",
    "find_boiling_point(mixture, verbose= True)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "37f96a51-0e85-49f9-a2dc-db3f5efcba13",
   "metadata": {},
   "source": [
    "## **Results** ##\n",
    "<p style=\"text-align: justify;\">\n",
    "The final model demonstrated high accuracy in recommending the appropriate chromatography technique based on the molecular properties of the mixture. Key results include:\n",
    "\n",
    "**Feature Importance:** \n",
    "<p style=\"text-align: justify;\">\n",
    "Polarity index, molecular weight, and solubility were identified as the most influential features in determining the suitable chromatography type.\n",
    "\n",
    "**User Feedback:**\n",
    "<p style=\"text-align: justify;\">\n",
    "The interactive nature of the user interface allowed for seamless user input and clear presentation of results, enhancing the user experience.\n",
    "    \n",
    "When error occurs, messages appear to inform the user of the encountered error. An example of this feature is shown bellow:\n",
    "\n",
    "<div style=\"text-align: center; padding: 20px;\">\n",
    "    <img src=\"../assets/edited-error-molecule-not-added.gif\" alt=\"errornomolecule\" style=\"width: 400px; height: auto;\">\n",
    "</div>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d5e4d262-3ffc-4f86-acfd-b2c31a154928",
   "metadata": {},
   "source": [
    "  \n",
    "\n",
    "## **Limits** ##\n",
    "\n",
    "The example bellow shows the limit of the program. Indeed, the suitable chromatography given by the interface is not correct, this is due to the fact that the boiling point is not given in pubchem which generates an error in the determination of the chromatography. Hence, a lack of data is limiting our project.\n",
    "\n",
    "<div style=\"text-align: center; padding: 20px;\">\n",
    "    <img src=\"../assets/edited-limit.gif\" alt=\"limit\" style=\"width: 400px; height: auto;\">\n",
    "</div>\n",
    "\n",
    "##### Take into account: \n",
    "- It takes into account **wrong names** and **compounds with no pages on PubChem**: it returns \"The_compound_name\" not found on PubChem'\n",
    "- The code works even with missing boiling point or pka in dataframe.\n",
    "\n",
    "##### To improve: \n",
    "- **Build a database**: mostly with thermostability for better choice of chromatography;\n",
    "- Taking into account **multiple pKa** values for polyacids for exemple;\n",
    "- Optimize the research: search only one time the **same name**, don't search for **one name**;\n",
    "- **Easier usage and options** of functionnalities to search physicalchemical properties in a dataframe;\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5945292b-5b88-4879-9eb5-5eeec0413f89",
   "metadata": {},
   "source": [
    "## **Encountered difficulties** ##\n",
    "\n",
    "A lot of challenges were faced to make request to pubchem:\n",
    "- Handling of **errors concerning pubchem**, no page found, wrong compound name, etc\n",
    "  \n",
    "- How to **extract string using regex**, used for pka, boiling temperature (°C) and (°F).\n",
    "  \n",
    "- Handling of **pka errors wrongly written in Pubchem** (either value in value, either input in the key of the dictionnary) <br>\n",
    "    {\"pka = 20.0\", } instead of {'pKa': '14'}\n",
    "  \n",
    "- Tests of dataframe object (pd.testing.assert_frame_equal(df, expected_df)) and Tk() listbox\n",
    "   \n",
    "## **Conclusion** ##\n",
    "<p style=\"text-align: justify;\">\n",
    "The project successfully developed a robust program for recommending chromatography techniques based on molecular composition. The use of a user interface facilitated an efficient and interactive development process, enabling easy experimentation and visualization. This tool has significant potential applications in chemical analysis, improving efficiency and accuracy in selecting the appropriate analytical methods. The main goal is to generate a database with commun eluants and their Boiling_point, pka, thermal stability. The last property needs to be researched in laboratory.\n",
    "\n",
    "## **Future Work** ##\n",
    "\n",
    "Future enhancements could include:\n",
    "\n",
    "- Expanding the dataset to cover more diverse molecular structures and additional chromatography techniques.\n",
    "- Improve the code to have a more efficient way to take the information on the molecules contained in the mixture to have the results more rapidly.\n",
    "- Integrating the program with real-time data acquisition systems for automated analysis.\n",
    "- Enhancing the user interface with more sophisticated visualization tools and user-friendly features.\n",
    "- By continuing to refine and expand this tool, it can establish itself as a valuable resource for chemists and researchers in analytical laboratories.\n",
    "\n",
    "This report provides an overview of the programming project conducted using Python, detailing the development process, results, and future directions for the chromatography recommendation program.\n"
   ]
  }
 ],
 "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
}
