{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "collapsed": false,
    "id": "fCQhSMBX3WOP"
   },
   "source": [
    "# Tutorial 01 - Loading Data Sets\n",
    "\n",
    "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/openforcefield/openff-evaluator/blob/master/docs/tutorials/tutorial01.ipynb)\n",
    "\n",
    "In this tutorial we will be exploring the frameworks utilities for loading and manipulating data sets of physical\n",
    "property measurements. The tutorial will cover\n",
    "\n",
    "- Loading a data set of density measurements from NISTs ThermoML Archive\n",
    "- Filtering the data set down using a range of criteria, including temperature pressure, and composition.\n",
    "- Supplementing the data set with enthalpy of vaporization ($\\Delta H_{v}$) data sourced directly from the literature\n",
    "\n",
    "If you haven't yet installed the OpenFF Evaluator framework on your machine, check out the [installation instructions \n",
    "here!](../install.rst)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "collapsed": false,
    "id": "gMcVrp5e3WOS",
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "*Note: If you are running this tutorial in google colab you will need to run a setup script instead of following the \n",
    "installation instructions:*"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "SrYqUKE93WOU",
    "pycharm": {
     "is_executing": false,
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "!wget https://raw.githubusercontent.com/openforcefield/openff-evaluator/master/docs/tutorials/colab_setup.ipynb\n",
    "%run colab_setup.ipynb"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "collapsed": false,
    "id": "JowZqBF23WOa",
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "For the sake of clarity all warnings will be disabled in this tutorial:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "Fa44xTAy3WOc",
    "pycharm": {
     "is_executing": false,
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "import warnings\n",
    "warnings.filterwarnings('ignore')\n",
    "import logging\n",
    "logging.getLogger(\"openforcefield\").setLevel(logging.ERROR)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "collapsed": false,
    "id": "QfZ0AwW-3WOj",
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "## Extracting Data from ThermoML\n",
    "\n",
    "For anyone who is not familiar with the ThermoML archive - it is a fantastic database of physical property measurements\n",
    "which have been extracted from data published in the \n",
    "\n",
    "- Journal of Chemical and Engineering Data\n",
    "- Journal of Chemical Thermodynamics\n",
    "- Fluid Phase Equilibria\n",
    "- Thermochimica Acta \n",
    "- International Journal of Thermophysics\n",
    "\n",
    "journals. It includes data for a wealth of different physical properties, from simple densities and melting points, to \n",
    "activity coefficients and osmotic coefficients, all of which is freely available. As such, it serves as a fantastic \n",
    "resource for benchmarking and optimising molecular force fields against.\n",
    "\n",
    "The Evaluator framework has built-in support for extracting this wealth of data, storing the data in easy to manipulate \n",
    "python objects, and for automatically re-computing those properties using an array of calculation techniques, such as \n",
    "molecular simulations and, in future, from trained surrogate models.\n",
    "\n",
    "This support is provided by the `ThermoMLDataSet` object:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "GrU7WuUE3WOm",
    "pycharm": {
     "is_executing": false,
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "from openff.evaluator.datasets.thermoml import ThermoMLDataSet"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "collapsed": false,
    "id": "XWBXcXF03WOw",
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "The `ThermoMLDataSet` object offers two main routes for extracting data the the archive:\n",
    "\n",
    "- extracting data directly from the NIST ThermoML web server\n",
    "- extracting data from a local ThermoML XML archive file\n",
    "\n",
    "Here we will be extracting data directly from the web server. To pull data from the web server we need to specifiy the \n",
    "digital object identifiers (DOIs) of the data we wish to extract - these correspond to the DOI of the publication that\n",
    "the data was initially sourced from.\n",
    "\n",
    "For this tutorial we will be extracting data using the following DOIs:   "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "530MHJsR3WOy",
    "pycharm": {
     "is_executing": false,
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "data_set = ThermoMLDataSet.from_doi(\n",
    "    \"10.1016/j.fluid.2013.10.034\",\n",
    "    \"10.1021/je1013476\",\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "collapsed": false,
    "id": "DKTRAAy_3WO8",
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "We can inspect the data set to see how many properties were loaded:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 35
    },
    "colab_type": "code",
    "executionInfo": {
     "elapsed": 351767,
     "status": "ok",
     "timestamp": 1583268516022,
     "user": {
      "displayName": "Simon Boothroyd",
      "photoUrl": "",
      "userId": "14278355403410282083"
     },
     "user_tz": 420
    },
    "id": "Q6OUsdH43WO_",
    "outputId": "de8c21b9-f525-4849-cf76-45f71950fd1e",
    "pycharm": {
     "is_executing": false,
     "name": "#%% \n"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "275"
      ]
     },
     "execution_count": 5,
     "metadata": {
      "tags": []
     },
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(data_set)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "collapsed": false,
    "id": "szMNT-tV3WPG",
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "and for how many different substances those properties were measured for:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 35
    },
    "colab_type": "code",
    "executionInfo": {
     "elapsed": 351764,
     "status": "ok",
     "timestamp": 1583268516023,
     "user": {
      "displayName": "Simon Boothroyd",
      "photoUrl": "",
      "userId": "14278355403410282083"
     },
     "user_tz": 420
    },
    "id": "uSGF7E9-3WPH",
    "outputId": "d968d0fe-ef68-43e4-85f7-9a59f05c66c6",
    "pycharm": {
     "is_executing": false,
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "254"
      ]
     },
     "execution_count": 6,
     "metadata": {
      "tags": []
     },
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(data_set.substances)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "collapsed": false,
    "id": "LZT4CQ0q3WPM",
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "We can also easily check which types of properties were loaded in:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 35
    },
    "colab_type": "code",
    "executionInfo": {
     "elapsed": 351762,
     "status": "ok",
     "timestamp": 1583268516024,
     "user": {
      "displayName": "Simon Boothroyd",
      "photoUrl": "",
      "userId": "14278355403410282083"
     },
     "user_tz": 420
    },
    "id": "LTHDuTUh3WPO",
    "outputId": "ede1dffc-3619-45cd-85ce-6bcbabd182d7",
    "pycharm": {
     "is_executing": false,
     "name": "#%% \n"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'EnthalpyOfMixing', 'Density'}\n"
     ]
    }
   ],
   "source": [
    "print(data_set.property_types)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "collapsed": false,
    "id": "4YpYiQYr3WPT",
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "## Filtering the Data Set\n",
    "\n",
    "The data set object we just created contains many different functions which will allow us to filter the data down, \n",
    "retaining only those measurements which are of interest to us.\n",
    "\n",
    "The first thing we will do is filter out all of the measurements which aren't density measurements:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 35
    },
    "colab_type": "code",
    "executionInfo": {
     "elapsed": 351760,
     "status": "ok",
     "timestamp": 1583268516025,
     "user": {
      "displayName": "Simon Boothroyd",
      "photoUrl": "",
      "userId": "14278355403410282083"
     },
     "user_tz": 420
    },
    "id": "QXphqqP53WPV",
    "outputId": "b19709c6-1524-4ef4-ff50-84e9112b05cd",
    "pycharm": {
     "is_executing": false,
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'Density'}\n"
     ]
    }
   ],
   "source": [
    "data_set.filter_by_property_types(\"Density\")\n",
    "print(data_set.property_types)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "collapsed": false,
    "id": "R7P4Q5pd3WPZ",
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "Next we will filter out all measurements which were made away from atmospheric conditions: "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 53
    },
    "colab_type": "code",
    "executionInfo": {
     "elapsed": 351857,
     "status": "ok",
     "timestamp": 1583268516125,
     "user": {
      "displayName": "Simon Boothroyd",
      "photoUrl": "",
      "userId": "14278355403410282083"
     },
     "user_tz": 420
    },
    "id": "D9iOJ28l3WPb",
    "outputId": "754dddaf-ac27-43c2-a77d-001b0dd2b336",
    "pycharm": {
     "is_executing": false,
     "name": "#%% \n"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "There were 213 properties before filtering\n",
      "There are now 9 properties after filtering\n"
     ]
    }
   ],
   "source": [
    "from openff.evaluator import unit\n",
    "\n",
    "print(f\"There were {len(data_set)} properties before filtering\")\n",
    "\n",
    "data_set.filter_by_temperature(\n",
    "    min_temperature=298.0 * unit.kelvin, max_temperature=298.2*unit.kelvin\n",
    ")\n",
    "\n",
    "data_set.filter_by_pressure(\n",
    "    min_pressure=0.999 * unit.atmosphere, max_pressure=1.001 * unit.atmosphere\n",
    ")\n",
    "\n",
    "print(f\"There are now {len(data_set)} properties after filtering\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "collapsed": false,
    "id": "wcW0jWKb3WPf",
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "*Note: Here we have made use of the `openff.evaluator.unit` module to attach units to the temperatures and pressures\n",
    "we are filtering by. This module simply exposes a `UnitRegistry` from the fantastic [pint](https://pint.readthedocs.io/en/stable/) \n",
    "library. Pint provides full support for attaching to units to values and is used extensively throughout this \n",
    "framework.*\n",
    "\n",
    "Finally, we will filter out all measurements which were not measured for either ethanol (CCO) or isopropanol (CC(C)O):"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 35
    },
    "colab_type": "code",
    "executionInfo": {
     "elapsed": 351855,
     "status": "ok",
     "timestamp": 1583268516126,
     "user": {
      "displayName": "Simon Boothroyd",
      "photoUrl": "",
      "userId": "14278355403410282083"
     },
     "user_tz": 420
    },
    "id": "GngQ8DJ93WPh",
    "outputId": "66d05bf0-6cb8-4d07-da53-381a70ae7c90",
    "pycharm": {
     "is_executing": false,
     "name": "#%% \n"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "There are now 2 properties after filtering\n"
     ]
    }
   ],
   "source": [
    "data_set.filter_by_smiles(\"CCO\", \"CC(C)O\")\n",
    "print(f\"There are now {len(data_set)} properties after filtering\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "collapsed": false,
    "id": "9Jw4dJZz3WPn",
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "We will convert the filtered data to a pandas `DataFrame` to more easily visualize the final data set:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 111
    },
    "colab_type": "code",
    "executionInfo": {
     "elapsed": 351853,
     "status": "ok",
     "timestamp": 1583268516127,
     "user": {
      "displayName": "Simon Boothroyd",
      "photoUrl": "",
      "userId": "14278355403410282083"
     },
     "user_tz": 420
    },
    "id": "6zcKs8vw3WPo",
    "outputId": "d5d5e565-adc6-49fd-8b98-b505e20b378d",
    "pycharm": {
     "is_executing": false,
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "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>Temperature (K)</th>\n",
       "      <th>Pressure (kPa)</th>\n",
       "      <th>Component 1</th>\n",
       "      <th>Density Value (g / ml)</th>\n",
       "      <th>Source</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>298.15</td>\n",
       "      <td>101.325</td>\n",
       "      <td>CC(C)O</td>\n",
       "      <td>0.78270</td>\n",
       "      <td>10.1016/j.fluid.2013.10.034</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>298.15</td>\n",
       "      <td>101.325</td>\n",
       "      <td>CCO</td>\n",
       "      <td>0.78507</td>\n",
       "      <td>10.1021/je1013476</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Temperature (K)  ...                       Source\n",
       "0           298.15  ...  10.1016/j.fluid.2013.10.034\n",
       "1           298.15  ...            10.1021/je1013476\n",
       "\n",
       "[2 rows x 5 columns]"
      ]
     },
     "execution_count": 11,
     "metadata": {
      "tags": []
     },
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pandas_data_set = data_set.to_pandas()\n",
    "pandas_data_set[\n",
    "    [\"Temperature (K)\", \"Pressure (kPa)\", \"Component 1\", \"Density Value (g / ml)\", \"Source\"]\n",
    "].head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "collapsed": false,
    "id": "qLt21Daw3WPv",
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "Through filtering, we have now cut down from over 250 property measurements down to just 2. There are many more \n",
    "possible filters which can be applied. All of these and more information about the data set object can be found in the\n",
    "`PhysicalPropertyDataSet` (from which the `ThermoMLDataSet` class inherits) API documentation.\n",
    "\n",
    "## Adding Extra Data\n",
    "\n",
    "For the final part of this tutorial, we will be supplementing our newly filtered data set with some enthalpy of \n",
    "vaporization ($\\Delta H_{v}$) measurements sourced directly from the literature (as opposed to from the ThermoML \n",
    "archive).\n",
    "\n",
    "We will be sourcing values of the $\\Delta H_{v}$ of ethanol and isopropanol, summarised in the table below, from the \n",
    "[Enthalpies of vaporization of some aliphatic alcohols](https://www.sciencedirect.com/science/article/pii/S0021961471801088) \n",
    "publication:\n",
    "\n",
    "| Compound    | Temperature / $K$ | $\\Delta H_{v}$ / $kJ mol^{-1}$ | $\\delta \\Delta H_{v}$ / $kJ mol^{-1}$ |\n",
    "|-------------|-------------------|--------------------------------|---------------------------------------|\n",
    "| Ethanol     | 298.15            | 42.26                          | 0.02                                  |\n",
    "| Isopropanol | 298.15            | 45.34                          | 0.02                                  |\n",
    "\n",
    "In order to create a new $\\Delta H_{v}$ measurements, we will first define the state (namely temperature and pressure)\n",
    "that the measurements were recorded at:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "s-ZPLIP73WPw",
    "pycharm": {
     "is_executing": false,
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "from openff.evaluator.thermodynamics import ThermodynamicState\n",
    "\n",
    "thermodynamic_state = ThermodynamicState(\n",
    "    temperature=298.15 * unit.kelvin, pressure=1.0 * unit.atmosphere\n",
    ") "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "collapsed": false,
    "id": "QIQ5Kyit3WP2",
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "the substances that the measurements were recorded for:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "SUDl9mlN3WP3",
    "pycharm": {
     "is_executing": false,
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "from openff.evaluator.substances import Substance\n",
    "\n",
    "ethanol = Substance.from_components(\"CCO\")\n",
    "isopropanol = Substance.from_components(\"CC(C)O\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "collapsed": false,
    "id": "CVAiPSET3WP8",
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "and the source of this measurement (defined as the DOI of the publication):"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "L9k9s2d03WP9",
    "pycharm": {
     "is_executing": false,
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "from openff.evaluator.datasets import MeasurementSource\n",
    "\n",
    "source = MeasurementSource(doi=\"10.1016/S0021-9614(71)80108-8\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "collapsed": false,
    "id": "SRFL2U9m3WQB",
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "We will combine this information with the values of the measurements to create an object which encodes each of the \n",
    "$\\Delta H_{v}$ measurements  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "S84948QW3WQD",
    "pycharm": {
     "is_executing": false,
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "from openff.evaluator.datasets import PropertyPhase\n",
    "from openff.evaluator.properties import EnthalpyOfVaporization\n",
    "\n",
    "ethanol_hvap = EnthalpyOfVaporization(\n",
    "    thermodynamic_state=thermodynamic_state,\n",
    "    phase=PropertyPhase.Liquid | PropertyPhase.Gas,\n",
    "    substance=ethanol,\n",
    "    value=42.26*unit.kilojoule / unit.mole,\n",
    "    uncertainty=0.02*unit.kilojoule / unit.mole,\n",
    "    source=source\n",
    ")\n",
    "isopropanol_hvap = EnthalpyOfVaporization(\n",
    "    thermodynamic_state=thermodynamic_state,\n",
    "    phase=PropertyPhase.Liquid | PropertyPhase.Gas,\n",
    "    substance=isopropanol,\n",
    "    value=45.34*unit.kilojoule / unit.mole,\n",
    "    uncertainty=0.02*unit.kilojoule / unit.mole,\n",
    "    source=source\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "collapsed": false,
    "id": "qkXOskeG3WQI",
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "These properties can then be added to our data set:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "MVLy9Pus3WQJ",
    "pycharm": {
     "is_executing": false,
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "data_set.add_properties(ethanol_hvap, isopropanol_hvap)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "collapsed": false,
    "id": "IXvNfKbG3WQO"
   },
   "source": [
    "If we print the data set again using pandas we should see that our new measurements have been added:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 173
    },
    "colab_type": "code",
    "executionInfo": {
     "elapsed": 351959,
     "status": "ok",
     "timestamp": 1583268516251,
     "user": {
      "displayName": "Simon Boothroyd",
      "photoUrl": "",
      "userId": "14278355403410282083"
     },
     "user_tz": 420
    },
    "id": "WztbDFxA3WQQ",
    "outputId": "a622a763-75df-4101-9555-2714ec56fe15",
    "pycharm": {
     "is_executing": false,
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "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>Temperature (K)</th>\n",
       "      <th>Pressure (kPa)</th>\n",
       "      <th>Component 1</th>\n",
       "      <th>Density Value (g / ml)</th>\n",
       "      <th>EnthalpyOfVaporization Value (kJ / mol)</th>\n",
       "      <th>Source</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>298.15</td>\n",
       "      <td>101.325</td>\n",
       "      <td>CC(C)O</td>\n",
       "      <td>0.78270</td>\n",
       "      <td>NaN</td>\n",
       "      <td>10.1016/j.fluid.2013.10.034</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>298.15</td>\n",
       "      <td>101.325</td>\n",
       "      <td>CCO</td>\n",
       "      <td>0.78507</td>\n",
       "      <td>NaN</td>\n",
       "      <td>10.1021/je1013476</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>298.15</td>\n",
       "      <td>101.325</td>\n",
       "      <td>CCO</td>\n",
       "      <td>NaN</td>\n",
       "      <td>42.26</td>\n",
       "      <td>10.1016/S0021-9614(71)80108-8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>298.15</td>\n",
       "      <td>101.325</td>\n",
       "      <td>CC(C)O</td>\n",
       "      <td>NaN</td>\n",
       "      <td>45.34</td>\n",
       "      <td>10.1016/S0021-9614(71)80108-8</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Temperature (K)  ...                         Source\n",
       "0           298.15  ...    10.1016/j.fluid.2013.10.034\n",
       "1           298.15  ...              10.1021/je1013476\n",
       "2           298.15  ...  10.1016/S0021-9614(71)80108-8\n",
       "3           298.15  ...  10.1016/S0021-9614(71)80108-8\n",
       "\n",
       "[4 rows x 6 columns]"
      ]
     },
     "execution_count": 17,
     "metadata": {
      "tags": []
     },
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pandas_data_set = data_set.to_pandas()\n",
    "pandas_data_set[\n",
    "    [\"Temperature (K)\", \n",
    "     \"Pressure (kPa)\", \n",
    "     \"Component 1\", \n",
    "     \"Density Value (g / ml)\", \n",
    "     \"EnthalpyOfVaporization Value (kJ / mol)\", \n",
    "     \"Source\"\n",
    "     ]\n",
    "].head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "collapsed": false,
    "id": "XZDGlVrE3WQU",
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "## Conclusion\n",
    "\n",
    "We will finish off this tutorial by saving the data set we have created as a JSON file for future use:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "HrhoALaI3WQV",
    "pycharm": {
     "is_executing": false,
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "data_set.json(\"filtered_data_set.json\", format=True);"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "collapsed": false,
    "id": "8FmNVb3r3WQb"
   },
   "source": [
    "And that concludes the first tutorial. For more information about data sets in the Evaluator framework check out the \n",
    "[data set](../datasets/physicalproperties.rst) and [ThermoML](../datasets/thermomldatasets.rst) documentation.\n",
    "\n",
    "In the next tutorial we will be estimating the data set we have created here using molecular simulation.\n",
    "\n",
    "If you have any questions and / or feedback, please open an issue on the\n",
    "[GitHub issue tracker](https://github.com/openforcefield/openff-evaluator/issues)."
   ]
  }
 ],
 "metadata": {
  "colab": {
   "collapsed_sections": [],
   "name": "tutorial01.ipynb",
   "provenance": [
    {
     "file_id": "https://github.com/openforcefield/openff-evaluator/blob/master/docs/tutorials/tutorial01.ipynb",
     "timestamp": 1583264541058
    }
   ]
  },
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
