{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "prerequistes:\n",
    "1. simple plotting\n",
    "2. basics\n",
    "3. reading documentation\n",
    "\n",
    "# Reading and writing data\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "While studying chemistry, we will inevitably gather data. If we want to interrogate that data using Python, we need a means to parse that data. Perhaps you have collected some data from a pratcical lab, and have copied said data into Excel, and would now like to analyse it in a Jupyter notebook. Or perhaps you are using a computer program to run simulations, and need to load the data into a notebook to check your results. In this section, we'll going into the basics of dealing with data files."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Parsing text files\n",
    "\n",
    "For our first example: imagine we have run a program to compute the relative energies of three conformers of the same molecule. This is stored in the file  \"computational_output.txt\". We want to read in the results as python variables to determine our ground state, and do any subsequent analysis we might require. We open files using the open function, starting with an example of **what not to do**."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Starting program...\n",
      "\n",
      "Loading atomic coordinates...\n",
      "\n",
      "Starting the calculation...\n",
      "\n",
      "Conformer 1 energy = 2331.2 kcal mol-1\n",
      "\n",
      "Conformer 2 energy = 2329.1 kcal mol-1\n",
      "\n",
      "Conformer 3 energy = 2330.4 kcal mol-1\n",
      "\n",
      "Calculation complete\n"
     ]
    }
   ],
   "source": [
    "# First, we read in the file as some variable name,\n",
    "computational_results = open('computational_output.txt')\n",
    "\n",
    "# computational results is now an interable object, like a\n",
    "# list, comprised of strings.\n",
    "for line in computational_results:\n",
    "        print(line)\n",
    "\n",
    "# We must close the file as below when we've finished,\n",
    "computational_results.close()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The above clearly works for printing the file, so why is it bad practice? It's easy to forget to `close` the file at the end. Much like having too many applications running at once on your computer, too many opened files in python is going to drain your computers resources. Not so bad for a 7 line text file, but the outputs of popular computational analysis packages can easily be as large as a few gigabytes. We ensure the file is always closed by wrapping our file processing in a `with` statement. The `with` statement will automatically close the file when the code within it has finished running. To achieve the exact same as above, but employing best practice, we can instead write"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Starting program...\n",
      "\n",
      "Loading atomic coordinates...\n",
      "\n",
      "Starting the calculation...\n",
      "\n",
      "Conformer 1 energy = 2331.2 kcal mol-1\n",
      "\n",
      "Conformer 2 energy = 2329.1 kcal mol-1\n",
      "\n",
      "Conformer 3 energy = 2330.4 kcal mol-1\n",
      "\n",
      "Calculation complete\n"
     ]
    }
   ],
   "source": [
    "with open('computational_output.txt') as results_file:\n",
    "    for line in results_file:\n",
    "        print(line)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "All well and good, but how do we processing the data? We can use any tools we would normally use for processing strings. For example"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['Conformer', '1', 'energy', '=', '2331.2', 'kcal', 'mol-1']\n"
     ]
    }
   ],
   "source": [
    "energy_strings = []\n",
    "\n",
    "with open('computational_output.txt') as results_file:\n",
    "    for line in results_file:\n",
    "        # we can use a conditional to find any line that contains\n",
    "        # '=', as we know these contain our energies\n",
    "        if '=' in line:\n",
    "            energy_strings.append(line)\n",
    "\n",
    "# we can then 'split' the strings into individual\n",
    "# strings, breaking on whitespace, and returning a list\n",
    "\n",
    "print(energy_strings[0].split())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We know that our output file has a consistent format, so for any lines that contains an '=' sign, the fifth value in a split of that line (i.e. index 4), will have the energy of our conformer. In code,"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[2331.2, 2329.1, 2330.4]\n"
     ]
    }
   ],
   "source": [
    "energies = []\n",
    "\n",
    "# iterative over the lines we know contain our conformer energies\n",
    "# we'll add these to a list, ensuring that we convert from strings\n",
    "# to floats\n",
    "\n",
    "for line in energy_strings:\n",
    "    energy_string = line.split()[4]\n",
    "    energies.append(float(energy_string))\n",
    "    \n",
    "print(energies)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The energies are now stored as floats in the list `energies` for us to do whatever analysis we need. \n",
    "\n",
    "## Excercise\n",
    "\n",
    "Copy the code above to retrieve the energies from the data file, but rather than storing the energies as a list, store them in a dictonary with the format `{'conformer_1_energy': ..., 'conformer_2_energy': ..., 'conformer_3_energy': ...}`. Do this in a way that ensures if we change the number of conformers, the code will still store all the energies in a dictionary.\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [],
   "source": [
    "### Write your code here"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Parsing standard data files\n",
    "\n",
    "One very common format for numerical data to be stored in is a 'comma separeted values' or .csv file. These files contain rows and columns of data, sepearted by ',' symbols, and are easily converted into numpy arrays. If you want to work on some data you were provided in a spreadsheet using python, you could save that spreadsheet as a `.csv` file, and then read it in as follows, using the numpy function `loadtxt`,"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[  320.    10887.   ]\n",
      " [  320.5   10880.   ]\n",
      " [  321.    10873.   ]\n",
      " [  321.5   10866.   ]\n",
      " [  322.    10859.   ]\n",
      " [  322.5   10852.   ]\n",
      " [  323.    10845.   ]\n",
      " [  323.5   10838.   ]\n",
      " [  324.    10831.   ]\n",
      " [  324.5   10824.   ]\n",
      " [  325.    10817.   ]\n",
      " [  325.5   10810.   ]\n",
      " [  326.    10803.   ]\n",
      " [  326.5   10796.   ]\n",
      " [  327.    10789.   ]\n",
      " [  327.5   10782.   ]\n",
      " [  328.    10775.   ]\n",
      " [  328.5   10768.   ]\n",
      " [  329.    10761.   ]\n",
      " [  329.5   10754.   ]\n",
      " [  330.    10747.   ]\n",
      " [  330.5   10740.   ]\n",
      " [  331.    10733.   ]\n",
      " [  331.5   10726.   ]\n",
      " [  332.    10719.   ]\n",
      " [  332.5   10712.   ]\n",
      " [  333.    10705.   ]\n",
      " [  333.5   10697.   ]\n",
      " [  334.    10690.   ]\n",
      " [  334.5   10683.   ]\n",
      " [  335.    10676.   ]\n",
      " [  335.5   10669.   ]\n",
      " [  336.    10662.   ]\n",
      " [  336.5   10655.   ]\n",
      " [  337.    10648.   ]\n",
      " [  337.5   10641.   ]\n",
      " [  338.    10634.   ]\n",
      " [  338.5   10627.   ]\n",
      " [  339.    10619.   ]\n",
      " [  339.5   10612.   ]\n",
      " [  340.    10605.   ]\n",
      " [  340.5   10598.   ]\n",
      " [  341.    10591.   ]\n",
      " [  341.5   10584.   ]\n",
      " [  342.    10577.   ]\n",
      " [  342.5   10570.   ]\n",
      " [  343.    10562.   ]\n",
      " [  343.5   10555.   ]\n",
      " [  344.    10548.   ]\n",
      " [  344.5   10541.   ]\n",
      " [  345.    10534.   ]\n",
      " [  345.5   10527.   ]\n",
      " [  346.    10519.   ]\n",
      " [  346.5   10512.   ]\n",
      " [  347.    10505.   ]\n",
      " [  347.5   10498.   ]\n",
      " [  348.    10491.   ]\n",
      " [  348.5   10483.   ]\n",
      " [  349.    10476.   ]\n",
      " [  349.5   10469.   ]\n",
      " [  350.    10462.   ]\n",
      " [  350.5   10455.   ]\n",
      " [  351.    10447.   ]\n",
      " [  351.5   10440.   ]\n",
      " [  352.    10433.   ]\n",
      " [  352.5   10426.   ]\n",
      " [  353.    10418.   ]\n",
      " [  353.13  10417.   ]\n",
      " [  353.13     35.561]\n",
      " [  353.5      35.519]\n",
      " [  354.       35.463]\n",
      " [  354.5      35.407]\n",
      " [  355.       35.351]\n",
      " [  355.5      35.296]\n",
      " [  356.       35.24 ]\n",
      " [  356.5      35.185]\n",
      " [  357.       35.13 ]\n",
      " [  357.5      35.075]\n",
      " [  358.       35.021]\n",
      " [  358.5      34.966]\n",
      " [  359.       34.912]\n",
      " [  359.5      34.858]\n",
      " [  360.       34.804]\n",
      " [  360.5      34.751]\n",
      " [  361.       34.697]\n",
      " [  361.5      34.644]\n",
      " [  362.       34.591]\n",
      " [  362.5      34.538]\n",
      " [  363.       34.485]\n",
      " [  363.5      34.433]\n",
      " [  364.       34.381]\n",
      " [  364.5      34.328]\n",
      " [  365.       34.276]\n",
      " [  365.5      34.225]\n",
      " [  366.       34.173]\n",
      " [  366.5      34.122]\n",
      " [  367.       34.07 ]\n",
      " [  367.5      34.019]\n",
      " [  368.       33.968]\n",
      " [  368.5      33.917]\n",
      " [  369.       33.867]\n",
      " [  369.5      33.816]\n",
      " [  370.       33.766]]\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "\n",
    "# first argument is the filename, the second is the 'delimiter'\n",
    "# i.e. what seperates the values, in our case, ',', we need to \n",
    "# also add skiprows = 1 as the first line of the file is strings\n",
    "# that cannot be converted to floats\n",
    "\n",
    "benzene_data = np.loadtxt('benzene_data.csv', delimiter = ',', skiprows = 1)\n",
    "\n",
    "print(benzene_data)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`benzene_data` now contains the content of the file `benzene_data.csv`, that is to say the density of a benzene sample in $\\mathrm{mol~m}^{-3}$ as a function of temperature in $\\mathrm{K}$. It is an array of arrays. Each sub array contains two values, a temperature and a density. The csv file has been read 'row-wise'. If we wanted to read it 'column-wise' (which we often do), and return an array of two sub-arrays: all temperatures, and all densities, we add one argument to out `loadtxt()` call, "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[  320.      320.5     321.      321.5     322.      322.5     323.\n",
      "    323.5     324.      324.5     325.      325.5     326.      326.5\n",
      "    327.      327.5     328.      328.5     329.      329.5     330.\n",
      "    330.5     331.      331.5     332.      332.5     333.      333.5\n",
      "    334.      334.5     335.      335.5     336.      336.5     337.\n",
      "    337.5     338.      338.5     339.      339.5     340.      340.5\n",
      "    341.      341.5     342.      342.5     343.      343.5     344.\n",
      "    344.5     345.      345.5     346.      346.5     347.      347.5\n",
      "    348.      348.5     349.      349.5     350.      350.5     351.\n",
      "    351.5     352.      352.5     353.      353.13    353.13    353.5\n",
      "    354.      354.5     355.      355.5     356.      356.5     357.\n",
      "    357.5     358.      358.5     359.      359.5     360.      360.5\n",
      "    361.      361.5     362.      362.5     363.      363.5     364.\n",
      "    364.5     365.      365.5     366.      366.5     367.      367.5\n",
      "    368.      368.5     369.      369.5     370.   ]\n",
      " [10887.    10880.    10873.    10866.    10859.    10852.    10845.\n",
      "  10838.    10831.    10824.    10817.    10810.    10803.    10796.\n",
      "  10789.    10782.    10775.    10768.    10761.    10754.    10747.\n",
      "  10740.    10733.    10726.    10719.    10712.    10705.    10697.\n",
      "  10690.    10683.    10676.    10669.    10662.    10655.    10648.\n",
      "  10641.    10634.    10627.    10619.    10612.    10605.    10598.\n",
      "  10591.    10584.    10577.    10570.    10562.    10555.    10548.\n",
      "  10541.    10534.    10527.    10519.    10512.    10505.    10498.\n",
      "  10491.    10483.    10476.    10469.    10462.    10455.    10447.\n",
      "  10440.    10433.    10426.    10418.    10417.       35.561    35.519\n",
      "     35.463    35.407    35.351    35.296    35.24     35.185    35.13\n",
      "     35.075    35.021    34.966    34.912    34.858    34.804    34.751\n",
      "     34.697    34.644    34.591    34.538    34.485    34.433    34.381\n",
      "     34.328    34.276    34.225    34.173    34.122    34.07     34.019\n",
      "     33.968    33.917    33.867    33.816    33.766]]\n"
     ]
    }
   ],
   "source": [
    "# unpack = True will ensure that the data is read in column-wise, and we are left with an array of two arrays.\n",
    "\n",
    "benzene_data = np.loadtxt('benzene_data.csv', delimiter = ',', skiprows = 1,unpack=True)\n",
    "\n",
    "print(benzene_data)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can then do whatever we like with these arrays, such as plot against each other."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAZEAAAEGCAYAAACkQqisAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+j8jraAAAcuklEQVR4nO3df5xd873v8ddbEkQRkcxREjlhklbL1YYhabSl3KK0jd66LQ7CQ0WVE21Pb0sefVyq6uhtD+W4QtSPoCqqSvyqG9SPnjRhIqgfwUz8SlCJpKF+h8/9Y31nbDF7z56V/SN79vv5eMxjvvu7vmvt79eMvGd919rfpYjAzMwsj/Xq3QEzM2tcDhEzM8vNIWJmZrk5RMzMLDeHiJmZ5Taw3h2oteHDh8fo0aPr3Q0zs4axYMGC5RHR0tO2pguR0aNH097eXu9umJk1DEnPFNvm6SwzM8vNIWJmZrk5RMzMLDeHiJmZ5eYQMTOz3BwivTj/rk7mdi7/QHlu53KOuOTe7vL5d3UCfKBsZtYMmu4W377aceQQjr9yIeceMo4dRw7hmMsXADB1rzHd5S/vuCUX3tPJ9DsXs8/2W3SHzoy7FzPl89vmKj+0ZBXf3r2VuZ3Lu8tmZusah0gvJrYO59xDxnH8lQs5dPyo7vpX31jdXX7znXc5/aZFTNt/O7bfqueg6Wu5WsEEMGA9ePc9uoPJQWVmeTlEyjCxdTiHjh/FOXd0MHXPMQAfKn9t3FZMv3Nx0aDpa7kawXTBYTvzyPOruo97/l2dDFiPigaVz6bMmotDpAxzO5dzxfxnmbrnGC6Z+zTAh8pXzH+W3T/WUjJo+lqudDDN63yZK+Y/y7T9t2P6nYvZ/WPDuW7h8xUNqmqfTTmkzNYtDpFezO1c3n1NBOgOjk0Gv/+fbkLrM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MlfSwinijSxgxwiFhzE1k4fKbI9rfS9/cKyl2vu/7fWXPdoCjjuK8VlP8TODMiZkvaAzilyD6rSTMHktYjC5yejifgXyPi1iLHIU25bRYRzxdpcjfZg7hukfTZRlqI0GrP01nWzN4CWiR9BrIHj0navo/HGNW1P3AI2V/xj/fhuEN4fwnuyQX1rwKbFLx+Gtg5lb9K9uS6ntwKHJum1JD0MUkfWaPNF8iWCi8qIn4P/BL4Y9fqsGY9cYhYM3uPbJnsn0t6kGwl277eVvs4cJykx4ChwPSIeLsPxz0F+J2kBcDygvobgK91XVgne4DS7ul4n+GDZx+Ffg08Ctwv6WHgAj4841Dqeki3iJhO9syN2ZI27K29NSev4muWU7qL6saI2KGXpusUSfcD4yPinXr3xRqfr4mYNZmI2KnefbD+w2ciZmaWm6+JmJlZbg4RMzPLzSFiZma5OUTMzCw3h4iZmeX2/wHzT9IRQud5aQAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "\n",
    "plt.plot(benzene_data[0],benzene_data[1],'x')\n",
    "plt.xlabel('Temperature / K')\n",
    "plt.ylabel('Density / molm-3')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "From the above plot, it's clear to see the boiling point of benzene as the density drops dramatically. These data were taken from the NIST website \\[1\\], where you can get access to all manner of chemical and physical properties of different chemical systems, download them as `.csv` files, and now you have the tools to do whatever you like with them!\n",
    "\n",
    "## Excercise\n",
    "\n",
    "Read in the benzene_data.csv file, and convert the temperature array from Kelvin to Celcius, then, using the [`np.savetext`](https://numpy.org/doc/stable/reference/generated/numpy.savetxt.html) fucntion, write that information back to a `.csv` file. If you can't understand how to do this from the numpy documentation, re-read the chapter on reading and understanding python documentation to get help.\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [],
   "source": [
    "### Write your code here"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## References\n",
    "\n",
    "1. Eric W. Lemmon, Mark O. McLinden and Daniel G. Friend, \"Thermophysical Properties of Fluid Systems\" in NIST Chemistry WebBook, NIST Standard Reference Database Number 69, Eds. P.J. Linstrom and W.G. Mallard, National Institute of Standards and Technology, Gaithersburg MD, 20899, https://doi.org/10.18434/T4D303, (retrieved June 16, 2020).\n"
   ]
  }
 ],
 "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.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
