{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "-"
    }
   },
   "source": [
    "# Thermodynamic modeling of lipid adaptation in thermophilic microbes\n",
    "\n",
    "### Grayson Boyer, Arizona State University"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "-"
    }
   },
   "source": [
    "## Introduction\n",
    "\n",
    "My research involves visiting and sampling hot springs of Yellowstone National Park (YNP), USA and elsewhere around the world."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<div style=\"float: left; width: 40%; margin-right: 1%; margin-bottom: 0.5em;\" class=\"container\">\n",
    "    <center>Bison Pool, YNP</center>\n",
    "    <img src=\"images/BisonSmall2.png\">\n",
    "</div>\n",
    "<div style=\"float: left; width: 40%; margin-left: 1%; margin-bottom: 0.5em;\" class=\"container\">\n",
    "    <center>Octopus Spring, YNP</center>\n",
    "    <img src=\"images/OctopusUpstreamSmall.png\">\n",
    "</div>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Specifically, I sample and study heat-loving, or **\"thermophilic\"**, microbes that form **communities** submerged in hot spring water. Communities can grow large enough to view with the naked eye, such as these \"pink streamer\" communities photographed in the water of Octopus Spring. (In person, these look like billowing clumps of cotton candy stuck to rocks under the water!)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<center>Pink streamers at Octopus Spring</center>\n",
    "<img src=\"images/PSC_small.png\" height=\"700\" width=\"700\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Downstream, thermophile communities can look completely different, like this huge photosynthetic microbial mat at Octopus Spring. It is as squishy and slimy as it looks!"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<center>Microbial mat downstream of Octopus Spring</center>\n",
    "<img src=\"images/OctopusDownstreamSmall.png\" height=\"700\" width=\"700\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Thermophile Lipids\n",
    "\n",
    "One way that thermophiles have adapted to life in boiling water is by making their outer layer, or **cell membrane**, resistant to heat. Cell membranes are composed of many individual **lipid molecules** with different abundances and chemical structures that provide heat-resistance. There are many, many, many different kinds of lipids. Chemical cartoons of two examples are shown below. For fun, try to find a few similarities and differences between them."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "-"
    }
   },
   "source": [
    "<center><img src=\"images/IPL_examples.png\" height=\"700\" width=\"700\"></center>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The top one is found in some thermophiles that live around 70 to 90 $^\\circ$C while the bottom one found in photosynthetic microbes that live below 70$^\\circ$C and is also common in plants. These lipids have complicated chemical names that I won't refer to here, but in case you're curious, the top and bottom lipids shown above are called \"phosphoaminopentanetetrol acyl ether glycerol\" and \"sulfoquinovosyl diacylglycerol\", respectively.\n",
    "\n",
    "Note that these lipids have commonly have a **polar headgroup** and a **nonpolar tailgroup**. The tailgroup commonly has two lipid **chains**, which are represented by the long zig-zag lines in the cartoon."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "A few ways that the chemical structure of lipids can be modified are shown in blue in the cartoon below. Some of these modifications provide heat resistance, such as longer chain lengths, more ether bonds, and fewer double bonds."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "-"
    }
   },
   "source": [
    "<center><img src=\"images/lipid_example.png\" height=\"700\" width=\"700\"></center>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "When I extract and quantify thermophile lipids in hot spring sediment or biomass samples I look for:\n",
    "\n",
    "1. Patterns in chemical structures that provide heat resistance.\n",
    "2. How these patterns change with temperature and other geochemical variables, such as dissolved oxygen concentration in the water.\n",
    "3. Ways that microbes are **saving energy** with their lipids.\n",
    "\n",
    "\n",
    "Point 3 requires performing calculations to estimate how much energy it takes for a thermophile to synthesize a particular lipid relative to another. This cost changes depending on the temperature and water chemistry of the habitat."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Hypothesis\n",
    "\n",
    "I hypothesize that microbes adapt their lipid composition to **1) minimize energy cost** and **2) maximize lipid function**.\n",
    "\n",
    "In other words, microbes have performed cost-benefit analysis through natural selection: a microbe that evolves a way to save more energy can reproduce faster than its neighbors, therefore making it more competitive. But remember, a given lipid will cost different amounts to make depending on habitat conditions, which could explain why we see different distributions and chemical structures of lipids in different places.\n",
    "\n",
    "To test this hypothesis, I first sampled thermophile communities living in different temperatures and chemical conditions. Then for each sample, I calculated whether the energy needed to synthesize observed lipids was minimized in the chemical conditions of that sample location relative to other locations.\n",
    "\n",
    "The remained of this notebook focuses on the results of one hot spring in YNP, **Bison Pool**, which was sampled during the summer of 2012. The **source** pool is pictured below on the left, where hot water comes to the surface at ~89$^{\\circ}$C and then flows away via a narrow **outflow channel**. The photomosaic map of Bison Pool's outflow channel shown below indicates the six sites where I sampled lipids from thermophile biomass."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "-"
    }
   },
   "source": [
    "<img src=\"images/bisonpicsmall.jpg\" style=\"float: left; width: 50%; margin-right: 1%; margin-bottom: 0.5em;\">\n",
    "<img src=\"images/bison_map.png\" style=\"float: left; width: 40%; margin-right: 1%; margin-bottom: 0.5em;\">\n",
    "<p style=\"clear: both;\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Lipid data\n",
    "\n",
    "Lipid identities and abundances are obtained by analyzing biomass extracts via liquid chromatography tandem mass spectrometry. This is a time-intensive process, as hot spring samples like these can produce very complex lipid profiles, commonly with never-before-seen lipids.\n",
    "\n",
    "Shown in the Table 1 (below) are weighted lipid chain properties observed in biomass extracts from six sample locations marked on the map above. For reference, these properties are shown in the cartoon below Table 1. The column \"% ester bond\" is the percent of observed lipid chains in a sample with an **ester bond** (the remainder are overwhelmingly **ether bonds**). The column \"ave. length\" shows the **average number of carbons** (or \"kinks\" in the zig-zag cartoon chain). The column \"ave. double bonds\" is the **average number of double bonds** per chain, and \"% hydroxyl\" is the percent of observed chains in a sample with a **hydroxylation**."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "-"
    }
   },
   "source": [
    "<center><b>Table 1:</b> Weighted lipid chain properties</center>\n",
    "\n",
    "Site          | % ester bond  | ave. length   | ave. double bonds | % hydroxyl.\n",
    "------------- | ------------: | ------------: | ----------------: |----------------:\n",
    "Bison Pool 1  | 27            |  19.8         | 0.16              | 0.9\n",
    "Bison Pool 2  | 42            |  19.4         | 0.18              | 1.4\n",
    "Bison Pool 3  | 74            |  17.9         | 0.17              | 2.1\n",
    "Bison Pool 4  | 55            |  17.3         | 0.17              | 1.5\n",
    "Bison Pool 5  | 85            |  16.8         | 0.27              | 2.6\n",
    "Bison Pool 6  | 97            |  16.7         | 0.41              | 0.3"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "-"
    }
   },
   "source": [
    "<center><img src=\"images/lipid_example.png\" height=\"700\" width=\"700\"></center>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In this work, I focus only on lipid tailgroup properties in my samples, and not headgroup properties, because there is a lack of experimental thermodynamic data for many headgroups and headgroup-like structures in scientific literature. I *do* have thermodynamic data that allow calculations involving lipid tailgroup chains, but this first requires knowing what type of chains for which to calculate properties.\n",
    "\n",
    "\n",
    "### An average lipid representing the entire lipid composition of a sample\n",
    "\n",
    "\n",
    "In reality, hundreds of lipid structures are typically observed in a single hot spring sample. Performing thermodynamic calculations on this many lipids across the six sample sites of Bison Pool can get nasty and complicated, so I chose to approach this problem in a different way.\n",
    "\n",
    "Imagine instead that only a *single lipid* was found at each sample site, and the properties of these lipids shown in Table 1. For Bison Pool site 1, this **average lipid** would have 27% of an ester bond, a length of 19.8 carbons, 0.4 of a double bond, and 0.01 of a hydroxylation. A cartoon of this average lipid is shown below."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "-"
    }
   },
   "source": [
    "<center><img src=\"images/Bison1RepLipid.png\" height=\"700\" width=\"700\"></center>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Repeat this process for each of the six samples along Bison Pool, and one ends up with six average lipid representatives. Table 2 (below) shows the calculated chemical formulae of these six average lipids.\n",
    "\n",
    "Six lipids, rather than hundreds, is much more manageable when it comes to computing thermodynamic properties in the next step."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "-"
    }
   },
   "source": [
    "<center><b>Table 2:</b> Chemical formulae of average representative lipid chains</center>\n",
    "\n",
    "Site    | hypoth. lipid formula\n",
    "------------- |--------------:\n",
    "Bison Pool 1  | C<sub>19.8</sub>H<sub>39.8</sub>O<sub>1.3</sub>N<sub>0.01</sub>\n",
    "Bison Pool 2  | C<sub>19.4</sub>H<sub>38.9</sub>O<sub>1.4</sub>N<sub>0.02</sub>\n",
    "Bison Pool 3  | C<sub>17.9</sub>H<sub>35.8</sub>O<sub>1.7</sub>N<sub>0.02</sub>\n",
    "Bison Pool 4  | C<sub>17.3</sub>H<sub>35.1</sub>O<sub>1.6</sub>N<sub>0.01</sub>\n",
    "Bison Pool 5  | C<sub>16.9</sub>H<sub>33.4</sub>O<sub>1.8</sub>N<sub>0.003</sub>\n",
    "Bison Pool 6  | C<sub>16.7</sub>H<sub>32.6</sub>O<sub>2.0</sub>N<sub>0.003</sub>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Thermodynamic properties of average representative lipids\n",
    "\n",
    "Recall that the goal of this work is to test the hypothesis that thermophiles have naturally selected lipids that minimize energetic cost while maximizing function.\n",
    "\n",
    "\n",
    "Thermodynamic calculations allow the estimation of the energetic costs of these six average lipid chains relative to each other. If the final results of the calculation show that the average lipids of sites 1, 2, 3, 4, 5, and 6 are most stable in their respective thermal and geochemical conditions, then this lends support to the hypothesis. If, on the other hand, the average lipid of site 6 is most stable in the thermal and geochemical conditions measured at site 1 (for example) then there is a problem with our original hypothesis.\n",
    "\n",
    "\n",
    "Describing in detail the process behind estimating the thermodynamic properties of the six average representative lipids could fill one or more Jupyter notebooks in itself, so instead I'll keep it simple and brief. I wrote [scripts](https://github.com/gmboyer/IPL-R-WIP) in the R programming language to do the following:\n",
    "\n",
    "\n",
    "1. Take my lipid data and compute the average representative lipids.\n",
    "2. Cross-reference separate experimental thermodynamic data in the literature.\n",
    "3. Using a process called 'group additivity', I build the thermodynamic properties of the average lipids using available thermodynamic literature for chemical groups.\n",
    "\n",
    "Think of Step 3 like building a Lego set (e.g. the thermodynamic property of an average lipid) out of individual Lego blocks (e.g. the partial thermodynamic contribution of an ester bond). Most of these thermodynamic data come from [ORCHYD](http://orchyd.asu.edu/), an online thermodynamic database of aqueous chemical species.\n",
    "\n",
    "Parts of the average lipids, thermodynamic estimation strategy, and thermodynamic data used are summarized in Table 3, below. For simplicity's sake, many of the lipid parts mentioned in Table 3, such as \"pentane rings\" and \"half monolayers\" haven't been shown in any cartoon in this notebook demo, but exist in nature and have been accounted for in these calculations."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "-"
    }
   },
   "source": [
    "<center><b>Table 3:</b> Thermodynamic data and strategies used in the estimation of average representative lipid thermodynamic properties</center>\n",
    "\n",
    "| lipid part     \t| strategy                            \t| data used                                                                      \t|\n",
    "|:----------------\t|:-------------------------------------\t|:--------------------------------------------------------------------------------\t|\n",
    "| *straight-chain* \t| *linear regression of…*               \t|                                                                                \t|\n",
    "| C-C            \t| n-alkanes                           \t| C3 to C14                                                                      \t|\n",
    "| ether          \t| 1-alcohols                          \t| C3 to C12                                                                      \t|\n",
    "| ester          \t| carboxylic acids                    \t| C3 to C12                                                                      \t|\n",
    "|                \t|              \t|                                     \t|                                                                                \t|\n",
    "| *modification*   \t| *add properties of…*                  \t|                                                                                \t|\n",
    "| unsaturation   \t| 2-alkenes - alkanes                 \t| 2-(pent, hex)ene                                                               \t|\n",
    "| hydroxyl       \t| 2-alcohols - alkanes                \t| 2-hept, 3-(pent, hex, hept), 4-heptanol                                        \t|\n",
    "| branch         \t| banched - nonbranched alkanes       \t| 2-methyl(prop, but, pent, hex, oct), 3-methyl(pent, hex, hept), 4-methyloctane \t|\n",
    "| pentane ring   \t| cyclopentanes - n-alkanes           \t| (methyl, propyl, pentyl)cyclopentane                                           \t|\n",
    "| hexane ring    \t| 1,1,3-trimethylcyclohexane - decane \t| 1,1,3-trimethylcyclohexane                                                     \t|\n",
    "| half monolayer \t| [CH2] - [CH3]                       \t| CH2 and CH3 contribution of n-alkanes, C3 to C14                               \t|\n",
    "| amide          \t| [CONH2] - [COOH]                    \t| amino acid backbone contributions                                                                        \t|\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Shown below are the thermodynamic properties estimated for the average representative lipid of Bison Pool sample site 1 that are relevant to testing the original hypothesis.\n",
    "\n",
    "These properties are then used to calculate a few extra parameters, called \"Helgeson-Kirkham-Flowers (HKF) equation-of-state coefficients\", that are needed to perform thermodynamic calculations at temperatures other than 25$^{\\circ}$C. This is an important step, considering we are doing calculations for Bison Pool, which is 89$^{\\circ}$C at site 1!"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true,
    "slideshow": {
     "slide_type": "-"
    }
   },
   "source": [
    "<center>Thermodynamic properties estimated for the average lipid of Bison Pool Site 1:</center>\n",
    "\\begin{align}\n",
    "& \\Delta _hG^{\\circ}_{(aq)} && = -2499\\ cal \\cdot mol^{-1} \\\\\n",
    "& \\Delta _fG^{\\circ}_{(aq)} && = -10781\\ cal \\cdot mol^{-1} \\\\\n",
    "& \\Delta _fH^{\\circ}_{(aq)} && = -170234\\ cal \\cdot mol^{-1} \\\\\n",
    "& S^{\\circ}_{(aq)} && = \\ \\ 145.5\\ cal \\cdot mol^{-1} K^{-1} \\\\\n",
    "& Cp^{\\circ}_{2} && = \\ \\ 396.7\\ cal \\cdot mol^{-1} K^{-1} \\\\\n",
    "& V^{\\circ}_{2} && = \\ \\ 320.9\\ cm^{3} \\cdot mol^{-1} \\\\\n",
    "\\end{align}\n",
    "\n",
    "<center>Estimated HKF equation-of-state coefficients using methods from <a href=\"https://doi.org/10.1016/S0016-7037%2801%2900678-0\">Plyasunov and Shock 2001</a></center>\n",
    "\\begin{align}\n",
    "& a_1 \\cdot 10 && =  \\ \\ 64.4\\ cal \\cdot mol^{-1} bar^{-1} \\\\\n",
    "& a_2 \\cdot 10^{-2} && =  \\ \\ 45.8\\ cal \\cdot mol^{-1} \\\\\n",
    "& a_3 && =  \\ \\ 88\\ cal \\cdot K \\cdot mol^{-1} bar^{-1} \\\\\n",
    "& a_4 \\cdot 10^{-4} && = -32.8\\ cal \\cdot K \\cdot mol^{-1} \\\\\n",
    "& c_1 && =  \\ \\ 389.3\\ cal \\cdot K^{-1} mol^{-1} \\\\\n",
    "& c_2 \\cdot 10^{-4} && =  \\ \\ 3.0\\ cal \\cdot K \\cdot mol^{-1} \\\\\n",
    "& \\omega \\cdot 10^{-5} && = -0.142\\ cal \\cdot mol^{-1}\n",
    "\\end{align}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "-"
    }
   },
   "source": [
    "These calculations are repeated to obtain thermodynamic properties and HKF coefficients for all six average lipids. Next, we need to compare relative energetic costs of lipids to finally test the hypothesis that thermophiles minimize energetic cost while maximizing lipid function."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Testing the hypothesis: relative energetic costs of average lipids\n",
    "\n",
    "Now that the thermodynamic properties of the six average representative thermophile lipids have been calculated, the next step is to compare their energetic costs.\n",
    "\n",
    "A number of factors influence energetic cost that a thermophile must pay when making a lipid. One factor is **temperature**; a particular lipid might cost more to make at a higher temperature than a lower one, and vice-versa. Another is the **availability of nutrients**. By \"nutrients\", I refer to the molecules thermophiles \"eat\" from their environment to make themselves, such as dissolved bicarbonate (HCO$_{3}^-$) as a source of carbon and ammonia (NH$_{3}$) as a source of nitrogen. The concentration of protons (H$^{+}$) in the environment determines **pH** and can have a huge impact on energetic costs.\n",
    "\n",
    "Likewise, the **oxidation-reduction potential** (Eh) of a thermophile habitat influences the energetic cost of creating a more oxidized or reduced lipid. One can visualize this in terms of dissolved oxygen (O$_{2}$) concentrations along Bison Pool. When hot water bubbles up from underground at the spring source, there is very little dissolved oxygen in the water, which makes chemical reactions that require O$_{2}$ less favorable in those conditions because of its scarcity. We call these conditions more **reducing**. As water trickles downstream away from the hot spring source, O$_{2}$ from the atmosphere begins mixing with the water, increasing its concentration. At the same time, some thermophiles generate O$_{2}$ metabolically, increasing the concentration of O$_{2}$ even more downstream. In sites where the oxygen concentration is higher, reactions that require O$_{2}$ are more favorable. We call these conditions more **oxidizing**. Rather than using O$_{2}$ concentrations in these calculations, I've chosen instead to represent Eh in terms of electron (e$^{-}$) concentrations, though doing it either way yields equivalent results.\n",
    "\n",
    "Eh receives special attention in this work because there is a huge gradient in Eh between Bison Pool site 1 and site 6, with the most reduced sites upstream (e.g. site 1) and the most oxidized sites downstream (e.g. sites 5 and 6).\n",
    "\n",
    "An unbalanced example reaction involving these important chemicals has been written below for the synthesis of the average representative lipid from Bison Pool site 1. Note that nutrients (HCO$_{3}^{-}$ and NH$_{3}$), pH in the form of H$^{+}$, and Eh in the form of $e^{-}$ are all considered. Water (H$_{2}$O) is on the right side of the reaction because it is a common byproduct of metabolic reactions and will serve to balance our equation later. Because the average lipid from site 1 is being formed in this reaction, we call this a **formation reaction**."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "-"
    }
   },
   "source": [
    "$$HCO_{3(aq)}^{-} + NH_{3} + H_{(aq)}^+ + e_{(aq)}^- = average\\ lipid\\ of\\ site\\ 1_{(aq)} + H_2O_{(liq)}$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Now that the thermodynamic properties of each of the six average lipids and their chemical formulae (Table 2) have been calculated or estimated, it is possible to balance their formation reactions and calculate their energetic costs.\n",
    "\n",
    "I use a thermodynamic R package called \"CHNOSZ\" to automate this. Shown below is a full calculation comparing the energetic costs of the six average representative lipids at Bison Pool."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "First, I load the necessary packages for calculation and plotting."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "My six average representative lipids are then imported into the CHNOSZ thermodynamic database. Their names are Bison1, Bison2, and so on to Bison6 furthest downstream from the hot spring source."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "slideshow": {
     "slide_type": "-"
    }
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "CHNOSZ version 1.3.2-10 (2019-05-06)\n",
      "reset: creating \"thermo\" object\n",
      "obigt: loading default database with 1841 aqueous, 3357 total species\n"
     ]
    }
   ],
   "source": [
    "### install necessary R packages\n",
    "# install.packages('CHNOSZ', repos='http://cran.us.r-project.org')\n",
    "# install.packages('ggplot2', repos='http://cran.us.r-project.org')\n",
    "# install.packages('repr', repos='http://cran.us.r-project.org')\n",
    "\n",
    "### Load packages\n",
    "library(CHNOSZ)\n",
    "library(ggplot2)\n",
    "library(repr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "slideshow": {
     "slide_type": "-"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<caption>A data.frame: 6 × 20</caption>\n",
       "<thead>\n",
       "\t<tr><th></th><th scope=col>name</th><th scope=col>abbrv</th><th scope=col>formula</th><th scope=col>state</th><th scope=col>ref1</th><th scope=col>ref2</th><th scope=col>date</th><th scope=col>G</th><th scope=col>H</th><th scope=col>S</th><th scope=col>Cp</th><th scope=col>V</th><th scope=col>a1</th><th scope=col>a2</th><th scope=col>a3</th><th scope=col>a4</th><th scope=col>c1</th><th scope=col>c2</th><th scope=col>omega</th><th scope=col>Z</th></tr>\n",
       "\t<tr><th></th><th scope=col>&lt;chr&gt;</th><th scope=col>&lt;chr&gt;</th><th scope=col>&lt;chr&gt;</th><th scope=col>&lt;chr&gt;</th><th scope=col>&lt;chr&gt;</th><th scope=col>&lt;chr&gt;</th><th scope=col>&lt;chr&gt;</th><th scope=col>&lt;dbl&gt;</th><th scope=col>&lt;dbl&gt;</th><th scope=col>&lt;dbl&gt;</th><th scope=col>&lt;dbl&gt;</th><th scope=col>&lt;dbl&gt;</th><th scope=col>&lt;dbl&gt;</th><th scope=col>&lt;dbl&gt;</th><th scope=col>&lt;dbl&gt;</th><th scope=col>&lt;dbl&gt;</th><th scope=col>&lt;dbl&gt;</th><th scope=col>&lt;dbl&gt;</th><th scope=col>&lt;dbl&gt;</th><th scope=col>&lt;dbl&gt;</th></tr>\n",
       "</thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row>3358</th><td>Bison1</td><td>NA</td><td>C19.8H39.5N0.0111O1.28</td><td>aq</td><td>thermofunc</td><td>NA</td><td>11/1/2017</td><td> -7779.977</td><td>-165548.2</td><td>146.4985</td><td>395.8124</td><td>319.0402</td><td>6.380555</td><td>4610.164</td><td>88.93901</td><td>-329282.4</td><td>387.7237</td><td>32835.18</td><td>-15373.26</td><td>0</td></tr>\n",
       "\t<tr><th scope=row>3359</th><td>Bison2</td><td>NA</td><td>C19.4H38.6N0.0164O1.42</td><td>aq</td><td>thermofunc</td><td>NA</td><td>11/1/2017</td><td>-15764.062</td><td>-169001.9</td><td>150.6434</td><td>388.9181</td><td>312.4211</td><td>6.254139</td><td>4499.090</td><td>86.61967</td><td>-321221.1</td><td>381.0372</td><td>31963.55</td><td>-15039.45</td><td>0</td></tr>\n",
       "\t<tr><th scope=row>3360</th><td>Bison3</td><td>NA</td><td>C18H35.5N0.0236O1.73  </td><td>aq</td><td>thermofunc</td><td>NA</td><td>11/1/2017</td><td>-36975.259</td><td>-177535.1</td><td>150.5980</td><td>361.4238</td><td>291.4375</td><td>5.849094</td><td>4158.048</td><td>79.53854</td><td>-296386.5</td><td>354.1030</td><td>29609.83</td><td>-14152.19</td><td>0</td></tr>\n",
       "\t<tr><th scope=row>3361</th><td>Bison4</td><td>NA</td><td>C17.3H34.7N0.015O1.55 </td><td>aq</td><td>thermofunc</td><td>NA</td><td>11/1/2017</td><td>-28442.862</td><td>-165284.8</td><td>145.0045</td><td>350.8409</td><td>280.6913</td><td>5.642638</td><td>3980.866</td><td>75.87279</td><td>-283555.8</td><td>343.8761</td><td>28109.31</td><td>-13597.09</td><td>0</td></tr>\n",
       "\t<tr><th scope=row>3362</th><td>Bison5</td><td>NA</td><td>C16.9H33N0.00259O1.81 </td><td>aq</td><td>thermofunc</td><td>NA</td><td>11/1/2017</td><td>-42450.206</td><td>-172146.0</td><td>147.9660</td><td>338.3405</td><td>272.5637</td><td>5.481634</td><td>3859.431</td><td>73.37821</td><td>-274599.8</td><td>331.4704</td><td>27710.01</td><td>-13450.73</td><td>0</td></tr>\n",
       "\t<tr><th scope=row>3363</th><td>Bison6</td><td>NA</td><td>C16.7H31.8N0.0033O1.96</td><td>aq</td><td>thermofunc</td><td>NA</td><td>11/1/2017</td><td>-44937.702</td><td>-169183.8</td><td>150.9237</td><td>329.8841</td><td>265.7185</td><td>5.374079</td><td>3684.549</td><td>69.73712</td><td>-262889.3</td><td>324.2365</td><td>22531.73</td><td>-11602.47</td><td>0</td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "A data.frame: 6 × 20\n",
       "\\begin{tabular}{r|llllllllllllllllllll}\n",
       "  & name & abbrv & formula & state & ref1 & ref2 & date & G & H & S & Cp & V & a1 & a2 & a3 & a4 & c1 & c2 & omega & Z\\\\\n",
       "  & <chr> & <chr> & <chr> & <chr> & <chr> & <chr> & <chr> & <dbl> & <dbl> & <dbl> & <dbl> & <dbl> & <dbl> & <dbl> & <dbl> & <dbl> & <dbl> & <dbl> & <dbl> & <dbl>\\\\\n",
       "\\hline\n",
       "\t3358 & Bison1 & NA & C19.8H39.5N0.0111O1.28 & aq & thermofunc & NA & 11/1/2017 &  -7779.977 & -165548.2 & 146.4985 & 395.8124 & 319.0402 & 6.380555 & 4610.164 & 88.93901 & -329282.4 & 387.7237 & 32835.18 & -15373.26 & 0\\\\\n",
       "\t3359 & Bison2 & NA & C19.4H38.6N0.0164O1.42 & aq & thermofunc & NA & 11/1/2017 & -15764.062 & -169001.9 & 150.6434 & 388.9181 & 312.4211 & 6.254139 & 4499.090 & 86.61967 & -321221.1 & 381.0372 & 31963.55 & -15039.45 & 0\\\\\n",
       "\t3360 & Bison3 & NA & C18H35.5N0.0236O1.73   & aq & thermofunc & NA & 11/1/2017 & -36975.259 & -177535.1 & 150.5980 & 361.4238 & 291.4375 & 5.849094 & 4158.048 & 79.53854 & -296386.5 & 354.1030 & 29609.83 & -14152.19 & 0\\\\\n",
       "\t3361 & Bison4 & NA & C17.3H34.7N0.015O1.55  & aq & thermofunc & NA & 11/1/2017 & -28442.862 & -165284.8 & 145.0045 & 350.8409 & 280.6913 & 5.642638 & 3980.866 & 75.87279 & -283555.8 & 343.8761 & 28109.31 & -13597.09 & 0\\\\\n",
       "\t3362 & Bison5 & NA & C16.9H33N0.00259O1.81  & aq & thermofunc & NA & 11/1/2017 & -42450.206 & -172146.0 & 147.9660 & 338.3405 & 272.5637 & 5.481634 & 3859.431 & 73.37821 & -274599.8 & 331.4704 & 27710.01 & -13450.73 & 0\\\\\n",
       "\t3363 & Bison6 & NA & C16.7H31.8N0.0033O1.96 & aq & thermofunc & NA & 11/1/2017 & -44937.702 & -169183.8 & 150.9237 & 329.8841 & 265.7185 & 5.374079 & 3684.549 & 69.73712 & -262889.3 & 324.2365 & 22531.73 & -11602.47 & 0\\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "A data.frame: 6 × 20\n",
       "\n",
       "| <!--/--> | name &lt;chr&gt; | abbrv &lt;chr&gt; | formula &lt;chr&gt; | state &lt;chr&gt; | ref1 &lt;chr&gt; | ref2 &lt;chr&gt; | date &lt;chr&gt; | G &lt;dbl&gt; | H &lt;dbl&gt; | S &lt;dbl&gt; | Cp &lt;dbl&gt; | V &lt;dbl&gt; | a1 &lt;dbl&gt; | a2 &lt;dbl&gt; | a3 &lt;dbl&gt; | a4 &lt;dbl&gt; | c1 &lt;dbl&gt; | c2 &lt;dbl&gt; | omega &lt;dbl&gt; | Z &lt;dbl&gt; |\n",
       "|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|\n",
       "| 3358 | Bison1 | NA | C19.8H39.5N0.0111O1.28 | aq | thermofunc | NA | 11/1/2017 |  -7779.977 | -165548.2 | 146.4985 | 395.8124 | 319.0402 | 6.380555 | 4610.164 | 88.93901 | -329282.4 | 387.7237 | 32835.18 | -15373.26 | 0 |\n",
       "| 3359 | Bison2 | NA | C19.4H38.6N0.0164O1.42 | aq | thermofunc | NA | 11/1/2017 | -15764.062 | -169001.9 | 150.6434 | 388.9181 | 312.4211 | 6.254139 | 4499.090 | 86.61967 | -321221.1 | 381.0372 | 31963.55 | -15039.45 | 0 |\n",
       "| 3360 | Bison3 | NA | C18H35.5N0.0236O1.73   | aq | thermofunc | NA | 11/1/2017 | -36975.259 | -177535.1 | 150.5980 | 361.4238 | 291.4375 | 5.849094 | 4158.048 | 79.53854 | -296386.5 | 354.1030 | 29609.83 | -14152.19 | 0 |\n",
       "| 3361 | Bison4 | NA | C17.3H34.7N0.015O1.55  | aq | thermofunc | NA | 11/1/2017 | -28442.862 | -165284.8 | 145.0045 | 350.8409 | 280.6913 | 5.642638 | 3980.866 | 75.87279 | -283555.8 | 343.8761 | 28109.31 | -13597.09 | 0 |\n",
       "| 3362 | Bison5 | NA | C16.9H33N0.00259O1.81  | aq | thermofunc | NA | 11/1/2017 | -42450.206 | -172146.0 | 147.9660 | 338.3405 | 272.5637 | 5.481634 | 3859.431 | 73.37821 | -274599.8 | 331.4704 | 27710.01 | -13450.73 | 0 |\n",
       "| 3363 | Bison6 | NA | C16.7H31.8N0.0033O1.96 | aq | thermofunc | NA | 11/1/2017 | -44937.702 | -169183.8 | 150.9237 | 329.8841 | 265.7185 | 5.374079 | 3684.549 | 69.73712 | -262889.3 | 324.2365 | 22531.73 | -11602.47 | 0 |\n",
       "\n"
      ],
      "text/plain": [
       "     name   abbrv formula                state ref1       ref2 date     \n",
       "3358 Bison1 NA    C19.8H39.5N0.0111O1.28 aq    thermofunc NA   11/1/2017\n",
       "3359 Bison2 NA    C19.4H38.6N0.0164O1.42 aq    thermofunc NA   11/1/2017\n",
       "3360 Bison3 NA    C18H35.5N0.0236O1.73   aq    thermofunc NA   11/1/2017\n",
       "3361 Bison4 NA    C17.3H34.7N0.015O1.55  aq    thermofunc NA   11/1/2017\n",
       "3362 Bison5 NA    C16.9H33N0.00259O1.81  aq    thermofunc NA   11/1/2017\n",
       "3363 Bison6 NA    C16.7H31.8N0.0033O1.96 aq    thermofunc NA   11/1/2017\n",
       "     G          H         S        Cp       V        a1       a2       a3      \n",
       "3358  -7779.977 -165548.2 146.4985 395.8124 319.0402 6.380555 4610.164 88.93901\n",
       "3359 -15764.062 -169001.9 150.6434 388.9181 312.4211 6.254139 4499.090 86.61967\n",
       "3360 -36975.259 -177535.1 150.5980 361.4238 291.4375 5.849094 4158.048 79.53854\n",
       "3361 -28442.862 -165284.8 145.0045 350.8409 280.6913 5.642638 3980.866 75.87279\n",
       "3362 -42450.206 -172146.0 147.9660 338.3405 272.5637 5.481634 3859.431 73.37821\n",
       "3363 -44937.702 -169183.8 150.9237 329.8841 265.7185 5.374079 3684.549 69.73712\n",
       "     a4        c1       c2       omega     Z\n",
       "3358 -329282.4 387.7237 32835.18 -15373.26 0\n",
       "3359 -321221.1 381.0372 31963.55 -15039.45 0\n",
       "3360 -296386.5 354.1030 29609.83 -14152.19 0\n",
       "3361 -283555.8 343.8761 28109.31 -13597.09 0\n",
       "3362 -274599.8 331.4704 27710.01 -13450.73 0\n",
       "3363 -262889.3 324.2365 22531.73 -11602.47 0"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "### add average lipid properties to CHNOSZ database\n",
    "suppressMessages(add.obigt(\"data/OBIGT_bison.csv\"))\n",
    "\n",
    "# check to see lipids have loaded properly into the database\n",
    "info(info(c(\"Bison1\", \"Bison2\", \"Bison3\",\n",
    "            \"Bison4\", \"Bison5\", \"Bison6\")))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Next, I input the concentrations of nutrients (HCO$_{3}^{-}$ and NH$_{3}$) and protons (H$^{+}$) that our research group actually measured in the water of Bison Pool. I have chosen to perform the calculation for the geochemical conditions we measured for Bison Pool site 1 as a starting point.\n",
    "\n",
    "\n",
    "Note that I do not include a measured value for Eh. The technical reason for this is that there is no single Eh value for water not in redox equilibrium. So instead of defining a single Eh value, Eh is allowed to become an independent variable to show how relative energetic costs of making these average representative lipids changes along an Eh gradient."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "slideshow": {
     "slide_type": "-"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<caption>A data.frame: 5 × 8</caption>\n",
       "<thead>\n",
       "\t<tr><th></th><th scope=col>C</th><th scope=col>H</th><th scope=col>N</th><th scope=col>O</th><th scope=col>Z</th><th scope=col>ispecies</th><th scope=col>logact</th><th scope=col>state</th></tr>\n",
       "\t<tr><th></th><th scope=col>&lt;dbl&gt;</th><th scope=col>&lt;dbl&gt;</th><th scope=col>&lt;dbl&gt;</th><th scope=col>&lt;dbl&gt;</th><th scope=col>&lt;dbl&gt;</th><th scope=col>&lt;int&gt;</th><th scope=col>&lt;dbl&gt;</th><th scope=col>&lt;chr&gt;</th></tr>\n",
       "</thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row>HCO3-</th><td>1</td><td>1</td><td>0</td><td>3</td><td>-1</td><td>13</td><td>-2.3655</td><td>aq </td></tr>\n",
       "\t<tr><th scope=row>H2O</th><td>0</td><td>2</td><td>0</td><td>1</td><td> 0</td><td> 1</td><td> 0.0000</td><td>liq</td></tr>\n",
       "\t<tr><th scope=row>H+</th><td>0</td><td>1</td><td>0</td><td>0</td><td> 1</td><td> 3</td><td>-7.2350</td><td>aq </td></tr>\n",
       "\t<tr><th scope=row>e-</th><td>0</td><td>0</td><td>0</td><td>0</td><td>-1</td><td> 2</td><td>     NA</td><td>aq </td></tr>\n",
       "\t<tr><th scope=row>NH3</th><td>0</td><td>3</td><td>1</td><td>0</td><td> 0</td><td>64</td><td>-5.6034</td><td>aq </td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "A data.frame: 5 × 8\n",
       "\\begin{tabular}{r|llllllll}\n",
       "  & C & H & N & O & Z & ispecies & logact & state\\\\\n",
       "  & <dbl> & <dbl> & <dbl> & <dbl> & <dbl> & <int> & <dbl> & <chr>\\\\\n",
       "\\hline\n",
       "\tHCO3- & 1 & 1 & 0 & 3 & -1 & 13 & -2.3655 & aq \\\\\n",
       "\tH2O & 0 & 2 & 0 & 1 &  0 &  1 &  0.0000 & liq\\\\\n",
       "\tH+ & 0 & 1 & 0 & 0 &  1 &  3 & -7.2350 & aq \\\\\n",
       "\te- & 0 & 0 & 0 & 0 & -1 &  2 &      NA & aq \\\\\n",
       "\tNH3 & 0 & 3 & 1 & 0 &  0 & 64 & -5.6034 & aq \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "A data.frame: 5 × 8\n",
       "\n",
       "| <!--/--> | C &lt;dbl&gt; | H &lt;dbl&gt; | N &lt;dbl&gt; | O &lt;dbl&gt; | Z &lt;dbl&gt; | ispecies &lt;int&gt; | logact &lt;dbl&gt; | state &lt;chr&gt; |\n",
       "|---|---|---|---|---|---|---|---|---|\n",
       "| HCO3- | 1 | 1 | 0 | 3 | -1 | 13 | -2.3655 | aq  |\n",
       "| H2O | 0 | 2 | 0 | 1 |  0 |  1 |  0.0000 | liq |\n",
       "| H+ | 0 | 1 | 0 | 0 |  1 |  3 | -7.2350 | aq  |\n",
       "| e- | 0 | 0 | 0 | 0 | -1 |  2 |      NA | aq  |\n",
       "| NH3 | 0 | 3 | 1 | 0 |  0 | 64 | -5.6034 | aq  |\n",
       "\n"
      ],
      "text/plain": [
       "      C H N O Z  ispecies logact  state\n",
       "HCO3- 1 1 0 3 -1 13       -2.3655 aq   \n",
       "H2O   0 2 0 1  0  1        0.0000 liq  \n",
       "H+    0 1 0 0  1  3       -7.2350 aq   \n",
       "e-    0 0 0 0 -1  2            NA aq   \n",
       "NH3   0 3 1 0  0 64       -5.6034 aq   "
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# input measured log concentrations of nutrients and pH\n",
    "basis(c(\"HCO3-\", \"H2O\", \"H+\", \"e-\", \"NH3\"),\n",
    "      c(-2.3655, 0, -7.235, NA, -5.6034))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "After that, I call up the six average representative lipids. This table shows how many of each nutrient/proton/electron are required to balance the formation reactions for each average representative lipid.\n",
    "\n",
    "Note that the rightmost column of each row gives the name of each average lipid, and to their left are the numbers of HCO$_{3}^{-}$, NH$_{3}$, H$^{+}$, and e$^{-}$ necessary to balance the formation reaction. For instance, the average lipid Bison1 requires 19.8 HCO$_{3}^{-}$ in the formation reaction to supply the necessary 19.8 carbons in the lipid structure. Also note the negative sign for H$_{2}$O, which represents that water is being formed as a byproduct of the lipid formation reaction.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "scrolled": true,
    "slideshow": {
     "slide_type": "-"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<caption>A data.frame: 6 × 9</caption>\n",
       "<thead>\n",
       "\t<tr><th scope=col>HCO3-</th><th scope=col>H2O</th><th scope=col>H+</th><th scope=col>e-</th><th scope=col>NH3</th><th scope=col>ispecies</th><th scope=col>logact</th><th scope=col>state</th><th scope=col>name</th></tr>\n",
       "\t<tr><th scope=col>&lt;dbl&gt;</th><th scope=col>&lt;dbl&gt;</th><th scope=col>&lt;dbl&gt;</th><th scope=col>&lt;dbl&gt;</th><th scope=col>&lt;dbl&gt;</th><th scope=col>&lt;int&gt;</th><th scope=col>&lt;dbl&gt;</th><th scope=col>&lt;chr&gt;</th><th scope=col>&lt;chr&gt;</th></tr>\n",
       "</thead>\n",
       "<tbody>\n",
       "\t<tr><td>19.8</td><td>-58.12</td><td>135.9067</td><td>116.10670</td><td>0.01110</td><td>3358</td><td>-3</td><td>aq</td><td>Bison1</td></tr>\n",
       "\t<tr><td>19.4</td><td>-56.78</td><td>132.7108</td><td>113.31080</td><td>0.01640</td><td>3359</td><td>-3</td><td>aq</td><td>Bison2</td></tr>\n",
       "\t<tr><td>18.0</td><td>-52.27</td><td>121.9692</td><td>103.96920</td><td>0.02360</td><td>3360</td><td>-3</td><td>aq</td><td>Bison3</td></tr>\n",
       "\t<tr><td>17.3</td><td>-50.35</td><td>118.0550</td><td>100.75500</td><td>0.01500</td><td>3361</td><td>-3</td><td>aq</td><td>Bison4</td></tr>\n",
       "\t<tr><td>16.9</td><td>-48.89</td><td>113.8722</td><td> 96.97223</td><td>0.00259</td><td>3362</td><td>-3</td><td>aq</td><td>Bison5</td></tr>\n",
       "\t<tr><td>16.7</td><td>-48.14</td><td>111.3701</td><td> 94.67010</td><td>0.00330</td><td>3363</td><td>-3</td><td>aq</td><td>Bison6</td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "A data.frame: 6 × 9\n",
       "\\begin{tabular}{r|lllllllll}\n",
       " HCO3- & H2O & H+ & e- & NH3 & ispecies & logact & state & name\\\\\n",
       " <dbl> & <dbl> & <dbl> & <dbl> & <dbl> & <int> & <dbl> & <chr> & <chr>\\\\\n",
       "\\hline\n",
       "\t 19.8 & -58.12 & 135.9067 & 116.10670 & 0.01110 & 3358 & -3 & aq & Bison1\\\\\n",
       "\t 19.4 & -56.78 & 132.7108 & 113.31080 & 0.01640 & 3359 & -3 & aq & Bison2\\\\\n",
       "\t 18.0 & -52.27 & 121.9692 & 103.96920 & 0.02360 & 3360 & -3 & aq & Bison3\\\\\n",
       "\t 17.3 & -50.35 & 118.0550 & 100.75500 & 0.01500 & 3361 & -3 & aq & Bison4\\\\\n",
       "\t 16.9 & -48.89 & 113.8722 &  96.97223 & 0.00259 & 3362 & -3 & aq & Bison5\\\\\n",
       "\t 16.7 & -48.14 & 111.3701 &  94.67010 & 0.00330 & 3363 & -3 & aq & Bison6\\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "A data.frame: 6 × 9\n",
       "\n",
       "| HCO3- &lt;dbl&gt; | H2O &lt;dbl&gt; | H+ &lt;dbl&gt; | e- &lt;dbl&gt; | NH3 &lt;dbl&gt; | ispecies &lt;int&gt; | logact &lt;dbl&gt; | state &lt;chr&gt; | name &lt;chr&gt; |\n",
       "|---|---|---|---|---|---|---|---|---|\n",
       "| 19.8 | -58.12 | 135.9067 | 116.10670 | 0.01110 | 3358 | -3 | aq | Bison1 |\n",
       "| 19.4 | -56.78 | 132.7108 | 113.31080 | 0.01640 | 3359 | -3 | aq | Bison2 |\n",
       "| 18.0 | -52.27 | 121.9692 | 103.96920 | 0.02360 | 3360 | -3 | aq | Bison3 |\n",
       "| 17.3 | -50.35 | 118.0550 | 100.75500 | 0.01500 | 3361 | -3 | aq | Bison4 |\n",
       "| 16.9 | -48.89 | 113.8722 |  96.97223 | 0.00259 | 3362 | -3 | aq | Bison5 |\n",
       "| 16.7 | -48.14 | 111.3701 |  94.67010 | 0.00330 | 3363 | -3 | aq | Bison6 |\n",
       "\n"
      ],
      "text/plain": [
       "  HCO3- H2O    H+       e-        NH3     ispecies logact state name  \n",
       "1 19.8  -58.12 135.9067 116.10670 0.01110 3358     -3     aq    Bison1\n",
       "2 19.4  -56.78 132.7108 113.31080 0.01640 3359     -3     aq    Bison2\n",
       "3 18.0  -52.27 121.9692 103.96920 0.02360 3360     -3     aq    Bison3\n",
       "4 17.3  -50.35 118.0550 100.75500 0.01500 3361     -3     aq    Bison4\n",
       "5 16.9  -48.89 113.8722  96.97223 0.00259 3362     -3     aq    Bison5\n",
       "6 16.7  -48.14 111.3701  94.67010 0.00330 3363     -3     aq    Bison6"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# set 'average lipids' as species of interest\n",
    "species(c(\"Bison1\", \"Bison2\", \"Bison3\", \"Bison4\", \"Bison5\", \"Bison6\"))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Finally, I perform the thermodynamic calculation that compares the relative energetic costs of making each of the six average lipids in the geochemical conditions and temperature we measured at Bison Pool (site 1)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "scrolled": true,
    "slideshow": {
     "slide_type": "-"
    }
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "affinity: temperature is 89 C\n",
      "affinity: pressure is Psat\n",
      "affinity: variable 1 is Eh at 300 values from -0.55 to -0.3 V\n",
      "subcrt: 11 species at 362.15 K and 1 bar (wet)\n",
      "balance: from numeric argument value\n",
      "equilibrate: n.balance is 1 1 1 1 1 1\n",
      "equilibrate: loga.balance is -2.22184874961636\n",
      "equilibrate: using boltzmann method\n"
     ]
    }
   ],
   "source": [
    "# set resolution to 300 calculations\n",
    "res <- 300\n",
    "\n",
    "# calculate hyp. lipid affinities of formation at 89 degreesC\n",
    "a <-affinity(Eh=c(-0.55, -0.30, res), T=89.0)\n",
    "\n",
    "# calculate equilibrium chemical activities of lipids from affinities\n",
    "e <-equilibrate(a, balance=1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "With the thermodynamic calculation complete, all that remains is to plot the output using the ggplot2 package."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "slideshow": {
     "slide_type": "-"
    }
   },
   "outputs": [],
   "source": [
    "# prepare 'average lipid' speciation output for plotting:\n",
    "x  <- round(seq(from=-0.55, to=-0.30, length.out=res), 5)  # Eh\n",
    "y1 <- round(10^e$loga.equil[[1]]/10^e$loga.balance, 5)*100 # Bison1\n",
    "y2 <- round(10^e$loga.equil[[2]]/10^e$loga.balance, 5)*100 # Bison2\n",
    "y3 <- round(10^e$loga.equil[[3]]/10^e$loga.balance, 5)*100 # Bison3\n",
    "y4 <- round(10^e$loga.equil[[4]]/10^e$loga.balance, 5)*100 # Bison4\n",
    "y5 <- round(10^e$loga.equil[[5]]/10^e$loga.balance, 5)*100 # Bison5\n",
    "y6 <- round(10^e$loga.equil[[6]]/10^e$loga.balance, 5)*100 # Bison6\n",
    "\n",
    "df <- data.frame(cbind(x, y1, y2, y3, y4, y5, y6)) # bind output into a data frame"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAA0gAAAFoCAMAAABaCiv2AAAASFBMVEUAAAAfd7QsoCwzMzNN\nTU1oaGh8fHyMVkuMjIyUZ72ampqnp6eysrK9vb3Hx8fQ0NDWJyjZ2dnh4eHp6enw8PDy8vL/\nfw7///+brfoyAAAACXBIWXMAABJ0AAASdAHeZh94AAAd3ElEQVR4nO2diZajrBZGqfqNnc5Q\nuZWk4/u/6RVxQARFRabz7bWqMihyjOwcJIawCgCwGxY6AAByACIB4ACIBIADIBIADoBIADgA\nIgHgAIgEgAMgEgAOgEgAOAAiAeCA/SKxni2l3xexjdXFGDttqS8gYlenzyzvPF9jstboCYsX\ncPSStUfsdLMtPa5ZUN6X1lOfeZ4Zu7zE/ftpuD/hp16RnR+rwgpLaJFEqdVl+etcbqkvINOd\ntN15JyKNXrL+mJWWpcc1j0rPrKc88RSlGnuu4v7vsPT3xE7i4bOw2n5UuBApQGnGnntqDYJJ\npC0lN2xp9JK16z9LdrULQVfZb8Fmc9IkqDNf/87O9d0HK2ppXmXRL/wtn3U83KTat/Nv80y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WW/bLMOyQAhDpYMYi\ntT03iZP4qg3v3b1EahpEKtjlESJmsB6IdDDTwYaxSHf2W2edm7ywF+lR9/ZOL4/Bgs1ApINZ\nEunNLnWv7q0VqaqeJ1b8eosVbAciHcySSNWFvdi50nbtOHcMhCcBjtLBLIr0W58/8aSjGWwo\n6gVPDDYkAUQ6mOmVDe24Q7/GSXyWNBr+rv+Kbvj7FiZwsAqIdDDLIt3ZT3MrfyBbP8kT0bVg\nBTxKAogUhhc6bHkBkcJwwlhcXkAkABwAkQBwAEQCwAEQCQAHQCQAHACRAHAARALAARAJAAdA\nJAAcAJEAcMD/AZokTZtCnLTfAAAAAElFTkSuQmCC",
      "text/plain": [
       "plot without title"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# plotly color palette\n",
    "pal <- c(\"#1f77b4\", \"#ff7f0e\", \"#2ca02c\", \"#d62728\", \"#9467bd\", \"#8c564b\")\n",
    "\n",
    "# create ggplot\n",
    "p <- ggplot(data=df) +\n",
    "     ggtitle(expression(\"Formation of average representative lipids of Bison Pool, 89\"*~degree*C)) +\n",
    "     theme(panel.background=element_blank()) +\n",
    "     labs(x=\"Eh, volts\", y=\"percent formation\") +\n",
    "     geom_line(aes(x=x, y=y1, colour=\"Bison1\"), size=1) +\n",
    "     geom_line(aes(x=x, y=y2, colour=\"Bison2\"), size=1) +\n",
    "     geom_line(aes(x=x, y=y3, colour=\"Bison3\"), size=1) +\n",
    "     geom_line(aes(x=x, y=y4, colour=\"Bison4\"), size=1) +\n",
    "     geom_line(aes(x=x, y=y5, colour=\"Bison5\"), size=1) +\n",
    "     geom_line(aes(x=x, y=y6, colour=\"Bison6\"), size=1) +\n",
    "     scale_colour_manual(name=\"Lipid\", values=pal)\n",
    "\n",
    "# Change plot size to 7 x 3\n",
    "options(repr.plot.width=7, repr.plot.height=3)\n",
    "\n",
    "# Display plot\n",
    "print(p)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Interpreting results\n",
    "\n",
    "Try out an [interactive plotly version of this plot.](https://gmboyer.github.io/HotSpringSpeciation.html)\n",
    "\n",
    "As mentioned previously, Eh is allowed to be our independent variable (x-axis) because we are interested in how the relative energetic costs of the six average lipids change along an Eh gradient, such as the one downstream at Bison Pool. Eh values further to the left side of the x-axis are **more reduced** (e.g. conditions close to the hot spring source), while values further to the right are **more oxidized** (e.g. conditions further downstream).\n",
    "\n",
    "Changes in Eh result in the rise and fall of six colored lines, which correspond to our six average representative lipids. The y-axis is \"percent formation\" and is a measure of relative **thermodynamic stability**, with higher values meaning a lipid is relatively more thermodynamically stable compared to others, therefore requiring **less energy to produce** by their formation reaction. For any given Eh, the percent formation of all six average lipids adds up to 100; so for instance at the Eh where the purple and brown lines cross, the most energetically favorable lipid composition is 50%-50% Bison5 and Bison6.\n",
    "\n",
    "#### Do these results support the original hypothesis that thermophiles tend to minimize energetic cost and maximize lipid function through evolution and adaptation?\n",
    "\n",
    "According to the diagram above, the most favorable configuration of lipids in the most reduced Eh is represented by average lipid Bison1, which was sampled at the hottest, most reduced site upstream, which agrees with the original hypothesis. A result that would challenge our hypothesis would show a average lipid representative of a downstream site, e.g. Bison5 or Bison6, as the most stable lipid in the most reducing Eh. Likewise, if Bison1 or Bison2 was most stable in oxidizing Eh relative to other lipids, this would challenge our hypothesis. But because the percent formation of average lipids transitions from Bison1 to Bison6 from most reduced to most oxidized Eh, or left to right on the x-axis, **these results support the original hypothesis**."
   ]
  }
 ],
 "metadata": {
  "celltoolbar": "Slideshow",
  "hide_input": false,
  "kernelspec": {
   "display_name": "R",
   "language": "R",
   "name": "ir"
  },
  "language_info": {
   "codemirror_mode": "r",
   "file_extension": ".r",
   "mimetype": "text/x-r-source",
   "name": "R",
   "pygments_lexer": "r",
   "version": "3.5.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}