{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# MolStandardize"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This is a demonstration on how to use the __rdMolStandardize__ module within RDKit. The structure and capabilities remain largely the same as MolVS (https://molvs.readthedocs.io/en/latest/) but will extended capabilities of user-supplied lists in some of the standardization tools. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "import rdkit\n",
    "from rdkit import Chem\n",
    "from rdkit.Chem.Draw import IPythonConsole\n",
    "from rdkit.Chem.MolStandardize import rdMolStandardize"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The __rdMolStandardize__ module contains the following convenience functions for quickly performing that standardization task:\n",
    "-  rdMolStandardize.StandardizeSmiles()\n",
    "-  rdMolStandardize.ValidateSmiles()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Other functions within the module:\n",
    "-  rdMolStandardize.Cleanup() \n",
    "-  rdMolStandardize.ChargeParent()\n",
    "-  rdMolStandardize.FragmentParent()\n",
    "\n",
    "__rdMolStandardize.Cleanup()__ is equivalent to the __molvs.standardize.Standardizer().standardize()__ function in molvs"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The __rdMolStandardize__ module contains the following classes, that allow you to develop your custom standardization process.\n",
    "-  rdMolStandardize.CleanupParameters\n",
    "-  rdMolStandardize.Normalize\n",
    "-  rdMolStandardize.MetalDisconnector\n",
    "-  rdMolStandardize.FragmentParent\n",
    "-  rdMolStandardize.FragmentRemover\n",
    "-  rdMolStandardize.Reionizer\n",
    "-  rdMolStandardize.Uncharger\n",
    "-  rdMolStandardize.RDKitValidation\n",
    "-  rdMolStandardize.MolVSValidation\n",
    "-  rdMolStandardize.AllowedAtomsValidation\n",
    "-  rdMolStandardize.DisallowedAtomsValidation\n",
    "\n",
    "TODO\n",
    "-  rdMolStandardize.tautomer "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## rdMolStandardize.StandardizeSmiles()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The __rdMolStandardize.StandardizeSmiles()__ convenience function contains all sensible default functionality to help get started"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'O=C([O-])c1ccc(C[S](=O)=O)cc1.[Na+]'"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sm = \"[Na]OC(=O)c1ccc(C[S+2]([O-])([O-]))cc1\"\n",
    "rdMolStandardize.StandardizeSmiles(sm)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The __rdMolStandardize.StandardizeSmiles()__ function performs the following steps."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'O=C([O-])c1ccc(C[S](=O)=O)cc1.[Na+]'"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mol = Chem.MolFromSmiles(sm)\n",
    "Chem.SanitizeMol(mol)\n",
    "mol = Chem.RemoveHs(mol)\n",
    "mol = rdMolStandardize.MetalDisconnector().Disconnect(mol)\n",
    "mol = rdMolStandardize.Normalize(mol)\n",
    "mol = rdMolStandardize.Reionize(mol)\n",
    "Chem.AssignStereochemistry(mol, force=True, cleanIt=True)\n",
    "Chem.MolToSmiles(mol)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## rdMolStandardize.ValidateSmiles()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The __rdMolStandardize.ValidateSmiles()__ function is a convenience funtion that quickly validates a single SMILES string. It uses the __rdMolStandardize.MolVSValidation()__ class with the default to do all validations."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "RDKit INFO: [15:43:30] INFO: [FragmentValidation] 1,2-dichloroethane is present\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "['INFO: [FragmentValidation] 1,2-dichloroethane is present']"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rdMolStandardize.ValidateSmiles(\"ClCCCl.c1ccccc1O\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## rdMolStandardize validation methods"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "There are four different ways of validating molecules, each can by run with their different classes:\n",
    "-  rdMolStandardize.RDKitValidation\n",
    "-  rdMolStandardize.MolVSValidation\n",
    "-  rdMolStandardize.AllowedAtomsValidation\n",
    "-  rdMolStandardize.DisallowedAtomsValidation\n",
    "\n",
    "All the classes have a __validate()__ method to perform the validation."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The __rdMolStandardize.RDKitValidation__ class validates the valency of every atom in the input molecule (much like RDKit automatically does)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "RDKit ERROR: [15:41:32] Explicit valence for atom # 1 O, 3, is greater than permitted\n",
      "RDKit INFO: [15:41:32] INFO: [ValenceValidation] Explicit valence for atom # 1 O, 3, is greater than permitted\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "['INFO: [ValenceValidation] Explicit valence for atom # 1 O, 3, is greater than permitted']"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "vm = rdMolStandardize.RDKitValidation()\n",
    "mol = Chem.MolFromSmiles(\"CO(C)C\", sanitize=False)\n",
    "vm.validate(mol)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The __rdMolStandardize.MolVSValidation__ class goes through similar validations as the standalone MolVS.\n",
    "https://molvs.readthedocs.io/en/latest/api.html#molvs-validate\n",
    "The default is to do all validations:\n",
    "-  NoAtomValidation\n",
    "-  FragmentValidation\n",
    "-  NeutralValidation\n",
    "-  IsotopeValidation\n",
    "\n",
    "Using the __rdMolStandardize.MolVSValidation__ class rather than the convenience function __rdMolStandardize.ValidateSmiles()__ provides more flexibility when working with multiple molecules or when a custom validation list is required"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "RDKit INFO: [15:41:32] INFO: [FragmentValidation] water/hydroxide is present\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "['INFO: [FragmentValidation] water/hydroxide is present']"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "vm = rdMolStandardize.MolVSValidation()\n",
    "mol = Chem.MolFromSmiles(\"COc1cccc(C=N[N-]C(N)=O)c1[O-].O.O.O.O=[U+2]=O\")\n",
    "vm.validate(mol)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Or you can specify which subset of MolVSValidations you want when initializing"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[]"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "validations = [rdMolStandardize.NoAtomValidation()]\n",
    "vm = rdMolStandardize.MolVSValidation(validations)\n",
    "mol = Chem.MolFromSmiles(\"COc1cccc(C=N[N-]C(N)=O)c1[O-].O.O.O.O=[U+2]=O\")\n",
    "vm.validate(mol)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The __rdMolStandardize.AllowedAtomsValidation__ class lets the user input a list of atoms, anything not on the list throws an error.\n",
    "\n",
    "The __rdMolStandardize.DisallowedAtomsValidation__ class also takes an input of a list of atoms and as long as there are no atoms from the list it is deemed acceptable. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "RDKit INFO: [15:41:32] INFO: [AllowedAtomsValidation] Atom F is not in allowedAtoms list\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "['INFO: [AllowedAtomsValidation] Atom F is not in allowedAtoms list']"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from rdkit.Chem.rdchem import Atom\n",
    "atomic_no = [6,7,8]\n",
    "allowed_atoms = [Atom(i) for i in atomic_no]\n",
    "vm = rdMolStandardize.AllowedAtomsValidation(allowed_atoms) \n",
    "mol = Chem.MolFromSmiles(\"CC(=O)CF\")\n",
    "vm.validate(mol)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "RDKit INFO: [15:41:32] INFO: [DisallowedAtomsValidation] Atom F is in disallowedAtoms list\n"
     ]
    }
   ],
   "source": [
    "atomic_no = [9, 17, 35]                                                     \n",
    "disallowed_atoms = [Atom(i) for i in atomic_no]                             \n",
    "vm = rdMolStandardize.DisallowedAtomsValidation(disallowed_atoms)          \n",
    "mol = Chem.MolFromSmiles(\"CC(=O)CF\")                                       \n",
    "msg = vm.validate(mol)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## rdMolStandardize.Cleanup\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Whilst __rdMolStandardize.StandardizeSmiles()__ provides a quick and easy way to get standardized version of a SMILES string, it's inefficient when dealing with multiple molecules and doesn't allow customization of the standardize process.\n",
    "\n",
    "The __Cleanup__ function provides flexibility to specify custom cleanup files and parameters."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 11020 characters]\n",
      "text/plain": [
       "<rdkit.Chem.rdchem.Mol at 0x7f318c0946c0>"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mol = Chem.MolFromSmiles(\"[Na]OC(=O)c1ccc(C[S+2]([O-])([O-]))cc1\")\n",
    "mol"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 11328 characters]\n",
      "text/plain": [
       "<rdkit.Chem.rdchem.Mol at 0x7f3184051990>"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "smol = rdMolStandardize.Cleanup(mol)\n",
    "smol"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "__rdMolStandardize.Cleanup()__ function can take in an optional __rdMolStandardize.CleanupParameters__ object which you can specify your own standardization reference files to use.\n",
    "The member variables that you can change are:\n",
    "-  CleanupParameters.acidbaseFile\n",
    "-  CleanupParameters.normalizationsFile\n",
    "-  CleanupParameters.fragmentFile\n",
    "-  CleanupParameters.maxRestarts\n",
    "-  CleanupParameters.preferOrganic"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Default acidbaseFile: /data/dipper/leung/gsoc/rdkit/Data/MolStandardize/acid_base_pairs.txt\n",
      "Default normalizationsFile: /data/dipper/leung/gsoc/rdkit/Data/MolStandardize/normalizations.txt\n",
      "Default fragmentFile: /data/dipper/leung/gsoc/rdkit/Data/MolStandardize/fragmentPatterns.txt\n",
      "Default maxRestarts: 200\n",
      "Default preferOrganic: False\n"
     ]
    }
   ],
   "source": [
    "params = rdMolStandardize.CleanupParameters()\n",
    "\n",
    "print(\"Default acidbaseFile: %s\" % params.acidbaseFile)\n",
    "print(\"Default normalizationsFile: %s\" % params.normalizationsFile)\n",
    "print(\"Default fragmentFile: %s\" % params.fragmentFile)\n",
    "print(\"Default maxRestarts: %s\" % params.maxRestarts)\n",
    "print(\"Default preferOrganic: %s\" % params.preferOrganic)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## rdMolStandardize.Normalize"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The __rdMolStandardize.Normalizer__ class is used to apply a series of Normalization transforms to correct functional groups and recombine charges."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 4708 characters]\n",
      "text/plain": [
       "<rdkit.Chem.rdchem.Mol at 0x7f318c0945d0>"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "n = rdMolStandardize.Normalizer()\n",
    "n.normalize(Chem.MolFromSmiles(\"C[S+2]([O-])([O-])O\"))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## rdMolStandardize.MetalDisconnector"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The __rdMolStandardize.MetalDisconnector__ class disconnects metal atoms that are defined as covalently bonded to non-metals."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 4608 characters]\n",
      "text/plain": [
       "<rdkit.Chem.rdchem.Mol at 0x7f3184051e90>"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "md = rdMolStandardize.MetalDisconnector()\n",
    "md.Disconnect(Chem.MolFromSmiles(\"CCC(=O)O[Na]\"))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## rdMolStandardize.LargestFragmentChooser and rdMolStandardize.Remover"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "-  __rdMolStandardize.LargestFragmentChooser__ class gets the largest fragment"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 5320 characters]\n",
      "text/plain": [
       "<rdkit.Chem.rdchem.Mol at 0x7f31840517b0>"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "lfc = rdMolStandardize.LargestFragmentChooser()\n",
    "lfc.choose(Chem.MolFromSmiles(\"O=C(O)CCC.O=C(O)CCCC.O=C(O)CCCCC.O=C(O)CCCC\"))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "__rdMolStandardize.FragmentParent()__ function is similar to __rdMolStandardize.LargestFragmentChooser__  but first performs __rdMolStandardize.Cleanup()__"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "-  __rdMolStandardize.FragmentRemover__ class filters out fragments"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAcIAAACWCAYAAABNcIgQAAAGkklEQVR4nO3dTYiVhR7H8Z8vA4UYFlYElb3qDA7lYmgIgnaDQygFbiqbRRBywe4oZVikSU1hEIIUTdYiGHpDVyluFMQ2USHNQrAzBS6awgKlqKjEPOcuzoULF2732p3xmfp/Ppt54cx5fgwcvjznOTNnXqfT6QQAiprf9AAAaJIQAlCaEAJQmhACUJoQAlCaEAJQmhACUJoQAlCaEAJQmhACUJoQAlCaEAJQmhACUJoQAlCaEAJQmhACUJoQAlCaEAJQmhACUJoQAlCaEAJQmhACUJoQAlCaEAJQmhACUJoQAlCaEAJQmhACUJoQAlCaEAJQmhACUJoQAlCaEAJQmhACUJoQAlCaEAJQmhACUJoQAlCaEAJQmhACUJoQAlCaEAJQmhACUJoQAlCaEAJQmhBCg8bHxzM+Pt70DChtYdMDoLLJycmmJ0B5zggBKE0IAShNCAEoTQgBKE0IAShNCAEoTQgBKE0IAShNCAEoTQgBKE0IAShNCAEoTQgBKE0IASjN2zBBg5Yu/XvTE6A8IYQGnT7d3/QEKM9TowCUJoQAlCaEAJQmhACUJoQAlCaEAJQmhACUJoQAlCaEAJQmhACUJoQAlCaEAJQmhACUJoQAlDav0+l0mh4BVbVa3Y+9vc3ugMqEEIDSPDUKDenvTy67LDlz5l/fe++9ZGCguU1QkRBCg3p6khdfbHoF1CaE0KDNm5PXXku++abpJVCXEEKDenuT++5LXnih6SVQlxBCw555JnnzzWR6uuklUJMQQsNuuil54IHk2WebXgI1LWx6AJA8/XTS15fccEPTS6AeZ4Qwy9rt7lOfW7b859tcd13y8MPJrl3dr7ds6f5Mu31xNkJlQgiz6MMPk8HB5LHHkmXLfv+2Tz2V/Ppr9/Nly7o/MzjYvQ9g9vjPMjALvv46efLJ5J13utf/XnopueqqC7uP775LduxIXn01Wb06efllT53CbHBGCDPol1+6fyDf15d89VXy6afJxMSFRzBJLr882b07OX48OX8+Wbky2bo1+emnmd8NlTkjhBly4EAyOpr89lsyNpaMjMz8/W/enJw9mzz/fPLQQ8m8eTN7DKjIGSH8nyYnk7vvTu6/vxu/zz+f+QgmyZo1yWefJY8/njz6aHLnncnHH8/8caAaIYQ/6MyZ7hngHXckV1+dnDjRvaZ3ySWzd8yenu4xW63k9tuTu+7qRvfbb2fvmPBXJ4Rwgc6d6167u/nm7is6P/gg2bs3uf76i7fhmmuSPXuSjz5KTp5MbrmlG+GzZy/eBvircI0QLsDBgwfzxhtf5tixv2XnzuTBB5u/TtfpJG+/3X0hzcDAaB55ZCj33HNPs6PgT8QZIfwPWq1WhoeHs27duvT3f52pqXbWr28+gkl3w/r1ydRUO/39i7Nu3boMDw+n1Wo1PQ3+FIQQfsf333+frVu3ZtWqVVm4cGFOnDiRsbGxLFo09x46ixbNz9jYWL744otceeWVue2227Jhw4acPn266Wkwp829RzPMAe12OxMTE1mxYkX279+f999/PwcOHMiNN97Y9LT/6tprr83ExEQOHz6cTz75JCtWrMju3btz/vz5pqfBnOQaIfybo0ePZtOmTZmens727duzcePGLFiwoOlZf0i73c5bb72VJ554IldccUV27dqV1atXNz0L5hRnhPBP09PTGRkZydDQUAYHBzM1NZXR0dE/bQSTZP78+RkZGUmr1cratWtz7733Zs2aNTl58mTT02DOEELK+/nnn7Njx44sX748p06dyuTkZPbs2ZOlS5c2PW3GLFmyJDt37szx48dz6aWXpq+vL6Ojo/nhhx+angaNE0LK6nQ62bdvX/r6+vLuu+9m3759OXz4cFauXNn0tFlz6623Zu/evTl48GCOHDmS3t7evP7662l7vycKc42Qso4dO5ahoaFs27YtGzduTE9PT9OTLqpz587llVdeyXPPPZdDhw5lYGCg6UnQCCGktB9//DGLFy9uekaj/A6oTggBKM01QgBKE0IAShNCAEoTQgBKE0IAShNCAEoTQgBKE0IAShNCAEoTQgBKE0IAShNCAEoTQgBKE0IAShNCAEoTQgBKE0IAShNCAEoTQgBKE0IAShNCAEoTQgBKE0IAShNCAEoTQgBKE0IAShNCAEoTQgBKE0IAShNCAEoTQgBKE0IAShNCAEoTQgBKE0IAShNCAEoTQgBKE0IAShNCAEoTQgBKE0IAShNCAEoTQgBKE0IASvsHwHdaImkAjPUAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<rdkit.Chem.rdchem.Mol at 0x7f3184051d00>"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fr = rdMolStandardize.FragmentRemover()\n",
    "fr.remove(Chem.MolFromSmiles(\"CN(C)C.Cl.Cl.Br\"))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## rdMolStandardize.Reionizer and rdMolStandardizer.Uncharger"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "-  __rdMolStandardize.Reionizer__ ensure the strongest acid groups ionize first in partially ionized molecules.\n",
    "-  __rdMolStandardize.Uncharger__ attempts to neutralize charges by adding and/or removing hydrogens where possible.\n",
    "\n",
    "\n",
    "__rdMolStandardize.ChargeParent()__ method is the uncharged version of the fragment parent. It involves taking the fragment parent then applying __Neutralize__ and __Reionize__."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 6824 characters]\n",
      "text/plain": [
       "<rdkit.Chem.rdchem.Mol at 0x7f318405f3f0>"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mol = Chem.MolFromSmiles(\"[Na+].O=C([O-])c1ccccc1\")\n",
    "\n",
    "lfc = rdMolStandardize.LargestFragmentChooser()\n",
    "mol = lfc.choose(mol)\n",
    "mol"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 6892 characters]\n",
      "text/plain": [
       "<rdkit.Chem.rdchem.Mol at 0x7f318405f530>"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "u = rdMolStandardize.Uncharger()\n",
    "mol = u.uncharge(mol)\n",
    "mol"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 6892 characters]\n",
      "text/plain": [
       "<rdkit.Chem.rdchem.Mol at 0x7f318405f170>"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r = rdMolStandardize.Reionizer()\n",
    "mol = r.reionize(mol)\n",
    "mol"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 6892 characters]\n",
      "text/plain": [
       "<rdkit.Chem.rdchem.Mol at 0x7f318405f670>"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mol = Chem.MolFromSmiles(\"[Na+].O=C([O-])c1ccccc1\")\n",
    "rdMolStandardize.ChargeParent(mol)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# TODO"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##  MolStandardize.tautomer"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "TODO\n",
    "\n",
    "-  __Tautomer_enumeration__ generates all possible tautomers using a series of transform rules. It also removes stereochemistry from double bonds that are single in at least 1 tautomer.\n",
    "-  __Tautomer_canonicalization__ enumerates all possible tautomers using transform rules and uses a scoring system to determine canonical tautomer."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [],
   "source": [
    "from rdkit.Chem.MolStandardize.standardize import enumerate_tautomers_smiles, canonicalize_tautomer_smiles"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'C=C(O)C(C)C', 'CC(=O)C(C)C', 'CC(C)=C(C)O'}"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "enumerate_tautomers_smiles(\"OC(C)=C(C)C\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'CC(=O)C(C)C'"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "canonicalize_tautomer_smiles(\"OC(C)=C(C)C\")"
   ]
  }
 ],
 "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.6.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
