{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Citrine data retrieval example"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This notebook demonstrates use of the code 'retrieve_Citrine.py' in retrieving data from various datasets collected by Citrine Informatics at http://citrination.com/, and output it in the form of a Pandas dataframe. In this example, we query the Citrine API to retrieve all the data on the semiconductor material GaN contributed by 'OQMD' (http://oqmd.org/) to Citrine. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from matminer.data_retrieval.retrieve_Citrine import CitrineDataRetrieval"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "api_key = None     # Set your Citrine API key here. If set as an environment variable 'CITRINE_KEY', set it to 'None'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Create an adapter to the Citrine Database."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": []
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>data_set_id</th>\n",
       "      <th>material.chemicalFormula</th>\n",
       "      <th>material.condition</th>\n",
       "      <th>Band gap</th>\n",
       "      <th>Formation energy</th>\n",
       "      <th>Stability (energy relative to convex hull)</th>\n",
       "      <th>measurement.condition</th>\n",
       "      <th>measurement.dataType</th>\n",
       "      <th>measurement.method</th>\n",
       "      <th>measurement.reference</th>\n",
       "      <th>property.units</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>sample</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1183</td>\n",
       "      <td>GaN</td>\n",
       "      <td>[{u'scalar': [{u'value': u'334755'}], u'name':...</td>\n",
       "      <td>1.99</td>\n",
       "      <td>-0.594</td>\n",
       "      <td>-0.584</td>\n",
       "      <td>[{u'units': u'KPPRA', u'scalar': [{u'value': u...</td>\n",
       "      <td>Computational</td>\n",
       "      <td>VASP with PAW/PBE</td>\n",
       "      <td>[{u'url': u'http://oqmd.org/materials/entry/33...</td>\n",
       "      <td>{u'Formation energy': u'eV/atom', u'Band gap':...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1178</td>\n",
       "      <td>GaN</td>\n",
       "      <td>[{u'scalar': [{u'value': u'317241'}], u'name':...</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.355</td>\n",
       "      <td>0.950</td>\n",
       "      <td>[{u'units': u'KPPRA', u'scalar': [{u'value': u...</td>\n",
       "      <td>Computational</td>\n",
       "      <td>VASP with PAW/PBE</td>\n",
       "      <td>[{u'url': u'http://oqmd.org/materials/entry/31...</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1182</td>\n",
       "      <td>GaN</td>\n",
       "      <td>[{u'scalar': [{u'value': u'331269'}], u'name':...</td>\n",
       "      <td>0.72</td>\n",
       "      <td>-0.116</td>\n",
       "      <td>0.479</td>\n",
       "      <td>[{u'units': u'KPPRA', u'scalar': [{u'value': u...</td>\n",
       "      <td>Computational</td>\n",
       "      <td>VASP with PAW/PBE</td>\n",
       "      <td>[{u'url': u'http://oqmd.org/materials/entry/33...</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1175</td>\n",
       "      <td>GaN</td>\n",
       "      <td>[{u'scalar': [{u'value': u'306699'}], u'name':...</td>\n",
       "      <td>0.00</td>\n",
       "      <td>1.026</td>\n",
       "      <td>1.620</td>\n",
       "      <td>[{u'units': u'KPPRA', u'scalar': [{u'value': u...</td>\n",
       "      <td>Computational</td>\n",
       "      <td>VASP with PAW/PBE</td>\n",
       "      <td>[{u'url': u'http://oqmd.org/materials/entry/30...</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>1165</td>\n",
       "      <td>GaN</td>\n",
       "      <td>[{u'scalar': [{u'value': u'97043'}], u'name': ...</td>\n",
       "      <td>2.09</td>\n",
       "      <td>-0.593</td>\n",
       "      <td>0.001</td>\n",
       "      <td>[{u'units': u'KPPRA', u'scalar': [{u'value': u...</td>\n",
       "      <td>Computational</td>\n",
       "      <td>VASP with PAW/PBE</td>\n",
       "      <td>[{u'url': u'http://oqmd.org/materials/entry/97...</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>1165</td>\n",
       "      <td>Mn3GaN</td>\n",
       "      <td>[{u'scalar': [{u'value': u'15510'}], u'name': ...</td>\n",
       "      <td>0.00</td>\n",
       "      <td>-0.346</td>\n",
       "      <td>-0.088</td>\n",
       "      <td>[{u'units': u'KPPRA', u'scalar': [{u'value': u...</td>\n",
       "      <td>Computational</td>\n",
       "      <td>VASP with PAW/PBE</td>\n",
       "      <td>[{u'url': u'http://oqmd.org/materials/entry/15...</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>1152</td>\n",
       "      <td>CaGaN</td>\n",
       "      <td>[{u'scalar': [{u'value': u'2044'}], u'name': u...</td>\n",
       "      <td>0.00</td>\n",
       "      <td>-0.813</td>\n",
       "      <td>-0.040</td>\n",
       "      <td>[{u'units': u'KPPRA', u'scalar': [{u'value': u...</td>\n",
       "      <td>Computational</td>\n",
       "      <td>VASP with PAW/PBE</td>\n",
       "      <td>[{u'url': u'http://oqmd.org/materials/entry/20...</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>1166</td>\n",
       "      <td>Nd3GaN</td>\n",
       "      <td>[{u'scalar': [{u'value': u'17258'}], u'name': ...</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.902</td>\n",
       "      <td>1.730</td>\n",
       "      <td>[{u'units': u'KPPRA', u'scalar': [{u'value': u...</td>\n",
       "      <td>Computational</td>\n",
       "      <td>VASP with PAW/PBE</td>\n",
       "      <td>[{u'url': u'http://oqmd.org/materials/entry/17...</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>113929</td>\n",
       "      <td>CaGaN</td>\n",
       "      <td>[{u'scalar': [{u'value': u'2044'}], u'name': u...</td>\n",
       "      <td>0.00</td>\n",
       "      <td>-0.813</td>\n",
       "      <td>-0.040</td>\n",
       "      <td>[{u'units': u'KPPRA', u'scalar': [{u'value': u...</td>\n",
       "      <td>Computational</td>\n",
       "      <td>VASP with PAW/PBE</td>\n",
       "      <td>[{u'url': u'http://oqmd.org/materials/entry/20...</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>113921</td>\n",
       "      <td>CaGaN</td>\n",
       "      <td>[{u'scalar': [{u'value': u'2044'}], u'name': u...</td>\n",
       "      <td>0.00</td>\n",
       "      <td>-0.813</td>\n",
       "      <td>-0.040</td>\n",
       "      <td>[{u'units': u'KPPRA', u'scalar': [{u'value': u...</td>\n",
       "      <td>Computational</td>\n",
       "      <td>VASP with PAW/PBE</td>\n",
       "      <td>[{u'url': u'http://oqmd.org/materials/entry/20...</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>1163</td>\n",
       "      <td>Cr2GaN</td>\n",
       "      <td>[{u'scalar': [{u'value': u'51566'}], u'name': ...</td>\n",
       "      <td>0.00</td>\n",
       "      <td>-0.347</td>\n",
       "      <td>0.037</td>\n",
       "      <td>[{u'units': u'KPPRA', u'scalar': [{u'value': u...</td>\n",
       "      <td>Computational</td>\n",
       "      <td>VASP with PAW/PBE</td>\n",
       "      <td>[{u'url': u'http://oqmd.org/materials/entry/51...</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>1167</td>\n",
       "      <td>Cr3GaN</td>\n",
       "      <td>[{u'scalar': [{u'value': u'647109'}], u'name':...</td>\n",
       "      <td>0.00</td>\n",
       "      <td>-0.297</td>\n",
       "      <td>0.028</td>\n",
       "      <td>[{u'units': u'KPPRA', u'scalar': [{u'value': u...</td>\n",
       "      <td>Computational</td>\n",
       "      <td>VASP with PAW/PBE</td>\n",
       "      <td>[{u'url': u'http://oqmd.org/materials/entry/64...</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>1158</td>\n",
       "      <td>ZnGaNO</td>\n",
       "      <td>[{u'scalar': [{u'value': u'20342'}], u'name': ...</td>\n",
       "      <td>0.53</td>\n",
       "      <td>-1.081</td>\n",
       "      <td>0.060</td>\n",
       "      <td>[{u'units': u'KPPRA', u'scalar': [{u'value': u...</td>\n",
       "      <td>Computational</td>\n",
       "      <td>VASP with PAW/PBE</td>\n",
       "      <td>[{u'url': u'http://oqmd.org/materials/entry/20...</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>1167</td>\n",
       "      <td>ZnGaNO</td>\n",
       "      <td>[{u'scalar': [{u'value': u'20341'}], u'name': ...</td>\n",
       "      <td>0.00</td>\n",
       "      <td>-1.059</td>\n",
       "      <td>0.022</td>\n",
       "      <td>[{u'units': u'KPPRA', u'scalar': [{u'value': u...</td>\n",
       "      <td>Computational</td>\n",
       "      <td>VASP with PAW/PBE</td>\n",
       "      <td>[{u'url': u'http://oqmd.org/materials/entry/20...</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>1167</td>\n",
       "      <td>ZnGaNO</td>\n",
       "      <td>[{u'scalar': [{u'value': u'20343'}], u'name': ...</td>\n",
       "      <td>0.00</td>\n",
       "      <td>-1.062</td>\n",
       "      <td>0.019</td>\n",
       "      <td>[{u'units': u'KPPRA', u'scalar': [{u'value': u...</td>\n",
       "      <td>Computational</td>\n",
       "      <td>VASP with PAW/PBE</td>\n",
       "      <td>[{u'url': u'http://oqmd.org/materials/entry/20...</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>1177</td>\n",
       "      <td>GaN3</td>\n",
       "      <td>[{u'scalar': [{u'value': u'313393'}], u'name':...</td>\n",
       "      <td>0.00</td>\n",
       "      <td>2.396</td>\n",
       "      <td>0.701</td>\n",
       "      <td>[{u'units': u'KPPRA', u'scalar': [{u'value': u...</td>\n",
       "      <td>Computational</td>\n",
       "      <td>VASP with PAW/PBE</td>\n",
       "      <td>[{u'url': u'http://oqmd.org/materials/entry/31...</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>1179</td>\n",
       "      <td>GaN3</td>\n",
       "      <td>[{u'scalar': [{u'value': u'323106'}], u'name':...</td>\n",
       "      <td>0.00</td>\n",
       "      <td>1.695</td>\n",
       "      <td>1.992</td>\n",
       "      <td>[{u'units': u'KPPRA', u'scalar': [{u'value': u...</td>\n",
       "      <td>Computational</td>\n",
       "      <td>VASP with PAW/PBE</td>\n",
       "      <td>[{u'url': u'http://oqmd.org/materials/entry/32...</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>1174</td>\n",
       "      <td>GaN3</td>\n",
       "      <td>[{u'scalar': [{u'value': u'302851'}], u'name':...</td>\n",
       "      <td>0.00</td>\n",
       "      <td>2.461</td>\n",
       "      <td>0.766</td>\n",
       "      <td>[{u'units': u'KPPRA', u'scalar': [{u'value': u...</td>\n",
       "      <td>Computational</td>\n",
       "      <td>VASP with PAW/PBE</td>\n",
       "      <td>[{u'url': u'http://oqmd.org/materials/entry/30...</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>1186</td>\n",
       "      <td>GaN3</td>\n",
       "      <td>[{u'scalar': [{u'value': u'347592'}], u'name':...</td>\n",
       "      <td>0.00</td>\n",
       "      <td>2.425</td>\n",
       "      <td>0.730</td>\n",
       "      <td>[{u'units': u'KPPRA', u'scalar': [{u'value': u...</td>\n",
       "      <td>Computational</td>\n",
       "      <td>VASP with PAW/PBE</td>\n",
       "      <td>[{u'url': u'http://oqmd.org/materials/entry/34...</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>1156</td>\n",
       "      <td>GaH3NF3</td>\n",
       "      <td>[{u'scalar': [{u'value': u'15761'}], u'name': ...</td>\n",
       "      <td>5.79</td>\n",
       "      <td>-1.778</td>\n",
       "      <td>-0.036</td>\n",
       "      <td>[{u'units': u'KPPRA', u'scalar': [{u'value': u...</td>\n",
       "      <td>Computational</td>\n",
       "      <td>VASP with PAW/PBE</td>\n",
       "      <td>[{u'url': u'http://oqmd.org/materials/entry/15...</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>1165</td>\n",
       "      <td>Ba2GaGeN</td>\n",
       "      <td>[{u'scalar': [{u'value': u'15061'}], u'name': ...</td>\n",
       "      <td>0.00</td>\n",
       "      <td>-0.633</td>\n",
       "      <td>-0.036</td>\n",
       "      <td>[{u'units': u'KPPRA', u'scalar': [{u'value': u...</td>\n",
       "      <td>Computational</td>\n",
       "      <td>VASP with PAW/PBE</td>\n",
       "      <td>[{u'url': u'http://oqmd.org/materials/entry/15...</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>1169</td>\n",
       "      <td>GaH4NF4</td>\n",
       "      <td>[{u'scalar': [{u'value': u'25250'}], u'name': ...</td>\n",
       "      <td>5.78</td>\n",
       "      <td>-1.810</td>\n",
       "      <td>0.009</td>\n",
       "      <td>[{u'units': u'KPPRA', u'scalar': [{u'value': u...</td>\n",
       "      <td>Computational</td>\n",
       "      <td>VASP with PAW/PBE</td>\n",
       "      <td>[{u'url': u'http://oqmd.org/materials/entry/25...</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>1169</td>\n",
       "      <td>Sr2GaGeN</td>\n",
       "      <td>[{u'scalar': [{u'value': u'26877'}], u'name': ...</td>\n",
       "      <td>0.00</td>\n",
       "      <td>-0.712</td>\n",
       "      <td>-0.045</td>\n",
       "      <td>[{u'units': u'KPPRA', u'scalar': [{u'value': u...</td>\n",
       "      <td>Computational</td>\n",
       "      <td>VASP with PAW/PBE</td>\n",
       "      <td>[{u'url': u'http://oqmd.org/materials/entry/26...</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>1158</td>\n",
       "      <td>ZnGa3N3O</td>\n",
       "      <td>[{u'scalar': [{u'value': u'20344'}], u'name': ...</td>\n",
       "      <td>0.33</td>\n",
       "      <td>-0.816</td>\n",
       "      <td>0.052</td>\n",
       "      <td>[{u'units': u'KPPRA', u'scalar': [{u'value': u...</td>\n",
       "      <td>Computational</td>\n",
       "      <td>VASP with PAW/PBE</td>\n",
       "      <td>[{u'url': u'http://oqmd.org/materials/entry/20...</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>1159</td>\n",
       "      <td>Sr3GaN3</td>\n",
       "      <td>[{u'scalar': [{u'value': u'24307'}], u'name': ...</td>\n",
       "      <td>0.73</td>\n",
       "      <td>-0.738</td>\n",
       "      <td>-0.049</td>\n",
       "      <td>[{u'units': u'KPPRA', u'scalar': [{u'value': u...</td>\n",
       "      <td>Computational</td>\n",
       "      <td>VASP with PAW/PBE</td>\n",
       "      <td>[{u'url': u'http://oqmd.org/materials/entry/24...</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>1159</td>\n",
       "      <td>Sr6GaN5</td>\n",
       "      <td>[{u'scalar': [{u'value': u'24308'}], u'name': ...</td>\n",
       "      <td>0.43</td>\n",
       "      <td>-0.690</td>\n",
       "      <td>0.005</td>\n",
       "      <td>[{u'units': u'KPPRA', u'scalar': [{u'value': u...</td>\n",
       "      <td>Computational</td>\n",
       "      <td>VASP with PAW/PBE</td>\n",
       "      <td>[{u'url': u'http://oqmd.org/materials/entry/24...</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>1159</td>\n",
       "      <td>GaN5O14</td>\n",
       "      <td>[{u'scalar': [{u'value': u'24155'}], u'name': ...</td>\n",
       "      <td>2.03</td>\n",
       "      <td>-0.693</td>\n",
       "      <td>0.007</td>\n",
       "      <td>[{u'units': u'KPPRA', u'scalar': [{u'value': u...</td>\n",
       "      <td>Computational</td>\n",
       "      <td>VASP with PAW/PBE</td>\n",
       "      <td>[{u'url': u'http://oqmd.org/materials/entry/24...</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>1168</td>\n",
       "      <td>GaN5O14</td>\n",
       "      <td>[{u'scalar': [{u'value': u'24154'}], u'name': ...</td>\n",
       "      <td>1.90</td>\n",
       "      <td>-0.690</td>\n",
       "      <td>0.003</td>\n",
       "      <td>[{u'units': u'KPPRA', u'scalar': [{u'value': u...</td>\n",
       "      <td>Computational</td>\n",
       "      <td>VASP with PAW/PBE</td>\n",
       "      <td>[{u'url': u'http://oqmd.org/materials/entry/24...</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>1171</td>\n",
       "      <td>Ca6GaN5</td>\n",
       "      <td>[{u'scalar': [{u'value': u'6342'}], u'name': u...</td>\n",
       "      <td>0.79</td>\n",
       "      <td>-0.909</td>\n",
       "      <td>-0.026</td>\n",
       "      <td>[{u'units': u'KPPRA', u'scalar': [{u'value': u...</td>\n",
       "      <td>Computational</td>\n",
       "      <td>VASP with PAW/PBE</td>\n",
       "      <td>[{u'url': u'http://oqmd.org/materials/entry/63...</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>1171</td>\n",
       "      <td>Li3GaN2</td>\n",
       "      <td>[{u'scalar': [{u'value': u'30294'}], u'name': ...</td>\n",
       "      <td>2.73</td>\n",
       "      <td>-0.617</td>\n",
       "      <td>-0.130</td>\n",
       "      <td>[{u'units': u'KPPRA', u'scalar': [{u'value': u...</td>\n",
       "      <td>Computational</td>\n",
       "      <td>VASP with PAW/PBE</td>\n",
       "      <td>[{u'url': u'http://oqmd.org/materials/entry/30...</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31</th>\n",
       "      <td>1157</td>\n",
       "      <td>La2GaN3</td>\n",
       "      <td>[{u'scalar': [{u'value': u'20275'}], u'name': ...</td>\n",
       "      <td>1.95</td>\n",
       "      <td>-1.171</td>\n",
       "      <td>-0.012</td>\n",
       "      <td>[{u'units': u'KPPRA', u'scalar': [{u'value': u...</td>\n",
       "      <td>Computational</td>\n",
       "      <td>VASP with PAW/PBE</td>\n",
       "      <td>[{u'url': u'http://oqmd.org/materials/entry/20...</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        data_set_id material.chemicalFormula  \\\n",
       "sample                                         \n",
       "1              1183                      GaN   \n",
       "2              1178                      GaN   \n",
       "3              1182                      GaN   \n",
       "4              1175                      GaN   \n",
       "5              1165                      GaN   \n",
       "6              1165                   Mn3GaN   \n",
       "7              1152                    CaGaN   \n",
       "8              1166                   Nd3GaN   \n",
       "9            113929                    CaGaN   \n",
       "10           113921                    CaGaN   \n",
       "11             1163                   Cr2GaN   \n",
       "12             1167                   Cr3GaN   \n",
       "13             1158                   ZnGaNO   \n",
       "14             1167                   ZnGaNO   \n",
       "15             1167                   ZnGaNO   \n",
       "16             1177                     GaN3   \n",
       "17             1179                     GaN3   \n",
       "18             1174                     GaN3   \n",
       "19             1186                     GaN3   \n",
       "20             1156                  GaH3NF3   \n",
       "21             1165                 Ba2GaGeN   \n",
       "22             1169                  GaH4NF4   \n",
       "23             1169                 Sr2GaGeN   \n",
       "24             1158                 ZnGa3N3O   \n",
       "25             1159                  Sr3GaN3   \n",
       "26             1159                  Sr6GaN5   \n",
       "27             1159                  GaN5O14   \n",
       "28             1168                  GaN5O14   \n",
       "29             1171                  Ca6GaN5   \n",
       "30             1171                  Li3GaN2   \n",
       "31             1157                  La2GaN3   \n",
       "\n",
       "                                       material.condition Band gap  \\\n",
       "sample                                                               \n",
       "1       [{u'scalar': [{u'value': u'334755'}], u'name':...     1.99   \n",
       "2       [{u'scalar': [{u'value': u'317241'}], u'name':...     0.00   \n",
       "3       [{u'scalar': [{u'value': u'331269'}], u'name':...     0.72   \n",
       "4       [{u'scalar': [{u'value': u'306699'}], u'name':...     0.00   \n",
       "5       [{u'scalar': [{u'value': u'97043'}], u'name': ...     2.09   \n",
       "6       [{u'scalar': [{u'value': u'15510'}], u'name': ...     0.00   \n",
       "7       [{u'scalar': [{u'value': u'2044'}], u'name': u...     0.00   \n",
       "8       [{u'scalar': [{u'value': u'17258'}], u'name': ...     0.00   \n",
       "9       [{u'scalar': [{u'value': u'2044'}], u'name': u...     0.00   \n",
       "10      [{u'scalar': [{u'value': u'2044'}], u'name': u...     0.00   \n",
       "11      [{u'scalar': [{u'value': u'51566'}], u'name': ...     0.00   \n",
       "12      [{u'scalar': [{u'value': u'647109'}], u'name':...     0.00   \n",
       "13      [{u'scalar': [{u'value': u'20342'}], u'name': ...     0.53   \n",
       "14      [{u'scalar': [{u'value': u'20341'}], u'name': ...     0.00   \n",
       "15      [{u'scalar': [{u'value': u'20343'}], u'name': ...     0.00   \n",
       "16      [{u'scalar': [{u'value': u'313393'}], u'name':...     0.00   \n",
       "17      [{u'scalar': [{u'value': u'323106'}], u'name':...     0.00   \n",
       "18      [{u'scalar': [{u'value': u'302851'}], u'name':...     0.00   \n",
       "19      [{u'scalar': [{u'value': u'347592'}], u'name':...     0.00   \n",
       "20      [{u'scalar': [{u'value': u'15761'}], u'name': ...     5.79   \n",
       "21      [{u'scalar': [{u'value': u'15061'}], u'name': ...     0.00   \n",
       "22      [{u'scalar': [{u'value': u'25250'}], u'name': ...     5.78   \n",
       "23      [{u'scalar': [{u'value': u'26877'}], u'name': ...     0.00   \n",
       "24      [{u'scalar': [{u'value': u'20344'}], u'name': ...     0.33   \n",
       "25      [{u'scalar': [{u'value': u'24307'}], u'name': ...     0.73   \n",
       "26      [{u'scalar': [{u'value': u'24308'}], u'name': ...     0.43   \n",
       "27      [{u'scalar': [{u'value': u'24155'}], u'name': ...     2.03   \n",
       "28      [{u'scalar': [{u'value': u'24154'}], u'name': ...     1.90   \n",
       "29      [{u'scalar': [{u'value': u'6342'}], u'name': u...     0.79   \n",
       "30      [{u'scalar': [{u'value': u'30294'}], u'name': ...     2.73   \n",
       "31      [{u'scalar': [{u'value': u'20275'}], u'name': ...     1.95   \n",
       "\n",
       "       Formation energy Stability (energy relative to convex hull)  \\\n",
       "sample                                                               \n",
       "1                -0.594                                     -0.584   \n",
       "2                 0.355                                      0.950   \n",
       "3                -0.116                                      0.479   \n",
       "4                 1.026                                      1.620   \n",
       "5                -0.593                                      0.001   \n",
       "6                -0.346                                     -0.088   \n",
       "7                -0.813                                     -0.040   \n",
       "8                 0.902                                      1.730   \n",
       "9                -0.813                                     -0.040   \n",
       "10               -0.813                                     -0.040   \n",
       "11               -0.347                                      0.037   \n",
       "12               -0.297                                      0.028   \n",
       "13               -1.081                                      0.060   \n",
       "14               -1.059                                      0.022   \n",
       "15               -1.062                                      0.019   \n",
       "16                2.396                                      0.701   \n",
       "17                1.695                                      1.992   \n",
       "18                2.461                                      0.766   \n",
       "19                2.425                                      0.730   \n",
       "20               -1.778                                     -0.036   \n",
       "21               -0.633                                     -0.036   \n",
       "22               -1.810                                      0.009   \n",
       "23               -0.712                                     -0.045   \n",
       "24               -0.816                                      0.052   \n",
       "25               -0.738                                     -0.049   \n",
       "26               -0.690                                      0.005   \n",
       "27               -0.693                                      0.007   \n",
       "28               -0.690                                      0.003   \n",
       "29               -0.909                                     -0.026   \n",
       "30               -0.617                                     -0.130   \n",
       "31               -1.171                                     -0.012   \n",
       "\n",
       "                                    measurement.condition  \\\n",
       "sample                                                      \n",
       "1       [{u'units': u'KPPRA', u'scalar': [{u'value': u...   \n",
       "2       [{u'units': u'KPPRA', u'scalar': [{u'value': u...   \n",
       "3       [{u'units': u'KPPRA', u'scalar': [{u'value': u...   \n",
       "4       [{u'units': u'KPPRA', u'scalar': [{u'value': u...   \n",
       "5       [{u'units': u'KPPRA', u'scalar': [{u'value': u...   \n",
       "6       [{u'units': u'KPPRA', u'scalar': [{u'value': u...   \n",
       "7       [{u'units': u'KPPRA', u'scalar': [{u'value': u...   \n",
       "8       [{u'units': u'KPPRA', u'scalar': [{u'value': u...   \n",
       "9       [{u'units': u'KPPRA', u'scalar': [{u'value': u...   \n",
       "10      [{u'units': u'KPPRA', u'scalar': [{u'value': u...   \n",
       "11      [{u'units': u'KPPRA', u'scalar': [{u'value': u...   \n",
       "12      [{u'units': u'KPPRA', u'scalar': [{u'value': u...   \n",
       "13      [{u'units': u'KPPRA', u'scalar': [{u'value': u...   \n",
       "14      [{u'units': u'KPPRA', u'scalar': [{u'value': u...   \n",
       "15      [{u'units': u'KPPRA', u'scalar': [{u'value': u...   \n",
       "16      [{u'units': u'KPPRA', u'scalar': [{u'value': u...   \n",
       "17      [{u'units': u'KPPRA', u'scalar': [{u'value': u...   \n",
       "18      [{u'units': u'KPPRA', u'scalar': [{u'value': u...   \n",
       "19      [{u'units': u'KPPRA', u'scalar': [{u'value': u...   \n",
       "20      [{u'units': u'KPPRA', u'scalar': [{u'value': u...   \n",
       "21      [{u'units': u'KPPRA', u'scalar': [{u'value': u...   \n",
       "22      [{u'units': u'KPPRA', u'scalar': [{u'value': u...   \n",
       "23      [{u'units': u'KPPRA', u'scalar': [{u'value': u...   \n",
       "24      [{u'units': u'KPPRA', u'scalar': [{u'value': u...   \n",
       "25      [{u'units': u'KPPRA', u'scalar': [{u'value': u...   \n",
       "26      [{u'units': u'KPPRA', u'scalar': [{u'value': u...   \n",
       "27      [{u'units': u'KPPRA', u'scalar': [{u'value': u...   \n",
       "28      [{u'units': u'KPPRA', u'scalar': [{u'value': u...   \n",
       "29      [{u'units': u'KPPRA', u'scalar': [{u'value': u...   \n",
       "30      [{u'units': u'KPPRA', u'scalar': [{u'value': u...   \n",
       "31      [{u'units': u'KPPRA', u'scalar': [{u'value': u...   \n",
       "\n",
       "       measurement.dataType measurement.method  \\\n",
       "sample                                           \n",
       "1             Computational  VASP with PAW/PBE   \n",
       "2             Computational  VASP with PAW/PBE   \n",
       "3             Computational  VASP with PAW/PBE   \n",
       "4             Computational  VASP with PAW/PBE   \n",
       "5             Computational  VASP with PAW/PBE   \n",
       "6             Computational  VASP with PAW/PBE   \n",
       "7             Computational  VASP with PAW/PBE   \n",
       "8             Computational  VASP with PAW/PBE   \n",
       "9             Computational  VASP with PAW/PBE   \n",
       "10            Computational  VASP with PAW/PBE   \n",
       "11            Computational  VASP with PAW/PBE   \n",
       "12            Computational  VASP with PAW/PBE   \n",
       "13            Computational  VASP with PAW/PBE   \n",
       "14            Computational  VASP with PAW/PBE   \n",
       "15            Computational  VASP with PAW/PBE   \n",
       "16            Computational  VASP with PAW/PBE   \n",
       "17            Computational  VASP with PAW/PBE   \n",
       "18            Computational  VASP with PAW/PBE   \n",
       "19            Computational  VASP with PAW/PBE   \n",
       "20            Computational  VASP with PAW/PBE   \n",
       "21            Computational  VASP with PAW/PBE   \n",
       "22            Computational  VASP with PAW/PBE   \n",
       "23            Computational  VASP with PAW/PBE   \n",
       "24            Computational  VASP with PAW/PBE   \n",
       "25            Computational  VASP with PAW/PBE   \n",
       "26            Computational  VASP with PAW/PBE   \n",
       "27            Computational  VASP with PAW/PBE   \n",
       "28            Computational  VASP with PAW/PBE   \n",
       "29            Computational  VASP with PAW/PBE   \n",
       "30            Computational  VASP with PAW/PBE   \n",
       "31            Computational  VASP with PAW/PBE   \n",
       "\n",
       "                                    measurement.reference  \\\n",
       "sample                                                      \n",
       "1       [{u'url': u'http://oqmd.org/materials/entry/33...   \n",
       "2       [{u'url': u'http://oqmd.org/materials/entry/31...   \n",
       "3       [{u'url': u'http://oqmd.org/materials/entry/33...   \n",
       "4       [{u'url': u'http://oqmd.org/materials/entry/30...   \n",
       "5       [{u'url': u'http://oqmd.org/materials/entry/97...   \n",
       "6       [{u'url': u'http://oqmd.org/materials/entry/15...   \n",
       "7       [{u'url': u'http://oqmd.org/materials/entry/20...   \n",
       "8       [{u'url': u'http://oqmd.org/materials/entry/17...   \n",
       "9       [{u'url': u'http://oqmd.org/materials/entry/20...   \n",
       "10      [{u'url': u'http://oqmd.org/materials/entry/20...   \n",
       "11      [{u'url': u'http://oqmd.org/materials/entry/51...   \n",
       "12      [{u'url': u'http://oqmd.org/materials/entry/64...   \n",
       "13      [{u'url': u'http://oqmd.org/materials/entry/20...   \n",
       "14      [{u'url': u'http://oqmd.org/materials/entry/20...   \n",
       "15      [{u'url': u'http://oqmd.org/materials/entry/20...   \n",
       "16      [{u'url': u'http://oqmd.org/materials/entry/31...   \n",
       "17      [{u'url': u'http://oqmd.org/materials/entry/32...   \n",
       "18      [{u'url': u'http://oqmd.org/materials/entry/30...   \n",
       "19      [{u'url': u'http://oqmd.org/materials/entry/34...   \n",
       "20      [{u'url': u'http://oqmd.org/materials/entry/15...   \n",
       "21      [{u'url': u'http://oqmd.org/materials/entry/15...   \n",
       "22      [{u'url': u'http://oqmd.org/materials/entry/25...   \n",
       "23      [{u'url': u'http://oqmd.org/materials/entry/26...   \n",
       "24      [{u'url': u'http://oqmd.org/materials/entry/20...   \n",
       "25      [{u'url': u'http://oqmd.org/materials/entry/24...   \n",
       "26      [{u'url': u'http://oqmd.org/materials/entry/24...   \n",
       "27      [{u'url': u'http://oqmd.org/materials/entry/24...   \n",
       "28      [{u'url': u'http://oqmd.org/materials/entry/24...   \n",
       "29      [{u'url': u'http://oqmd.org/materials/entry/63...   \n",
       "30      [{u'url': u'http://oqmd.org/materials/entry/30...   \n",
       "31      [{u'url': u'http://oqmd.org/materials/entry/20...   \n",
       "\n",
       "                                           property.units  \n",
       "sample                                                     \n",
       "1       {u'Formation energy': u'eV/atom', u'Band gap':...  \n",
       "2                                                     NaN  \n",
       "3                                                     NaN  \n",
       "4                                                     NaN  \n",
       "5                                                     NaN  \n",
       "6                                                     NaN  \n",
       "7                                                     NaN  \n",
       "8                                                     NaN  \n",
       "9                                                     NaN  \n",
       "10                                                    NaN  \n",
       "11                                                    NaN  \n",
       "12                                                    NaN  \n",
       "13                                                    NaN  \n",
       "14                                                    NaN  \n",
       "15                                                    NaN  \n",
       "16                                                    NaN  \n",
       "17                                                    NaN  \n",
       "18                                                    NaN  \n",
       "19                                                    NaN  \n",
       "20                                                    NaN  \n",
       "21                                                    NaN  \n",
       "22                                                    NaN  \n",
       "23                                                    NaN  \n",
       "24                                                    NaN  \n",
       "25                                                    NaN  \n",
       "26                                                    NaN  \n",
       "27                                                    NaN  \n",
       "28                                                    NaN  \n",
       "29                                                    NaN  \n",
       "30                                                    NaN  \n",
       "31                                                    NaN  "
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "c = CitrineDataRetrieval(api_key)\n",
    "df = c.get_dataframe(contributor='OQMD', formula='GaN')\n",
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In the dataframe above, the search query results in 31 samples/hits from the Citrine API, each with 3 properties - band gap, formation energy, and energy relative to convex hull."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Note: the above query also pulls samples that also contain the chemical formula of 'GaN', such as La2GaN3, and not just the compound 'GaN'. To filter results only for the compound 'GaN', we run the following query on the dataframe,"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>data_set_id</th>\n",
       "      <th>material.chemicalFormula</th>\n",
       "      <th>material.condition</th>\n",
       "      <th>Band gap</th>\n",
       "      <th>Formation energy</th>\n",
       "      <th>Stability (energy relative to convex hull)</th>\n",
       "      <th>measurement.condition</th>\n",
       "      <th>measurement.dataType</th>\n",
       "      <th>measurement.method</th>\n",
       "      <th>measurement.reference</th>\n",
       "      <th>property.units</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>sample</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1183</td>\n",
       "      <td>GaN</td>\n",
       "      <td>[{u'scalar': [{u'value': u'334755'}], u'name':...</td>\n",
       "      <td>1.99</td>\n",
       "      <td>-0.594</td>\n",
       "      <td>-0.584</td>\n",
       "      <td>[{u'units': u'KPPRA', u'scalar': [{u'value': u...</td>\n",
       "      <td>Computational</td>\n",
       "      <td>VASP with PAW/PBE</td>\n",
       "      <td>[{u'url': u'http://oqmd.org/materials/entry/33...</td>\n",
       "      <td>{u'Formation energy': u'eV/atom', u'Band gap':...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1178</td>\n",
       "      <td>GaN</td>\n",
       "      <td>[{u'scalar': [{u'value': u'317241'}], u'name':...</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.355</td>\n",
       "      <td>0.950</td>\n",
       "      <td>[{u'units': u'KPPRA', u'scalar': [{u'value': u...</td>\n",
       "      <td>Computational</td>\n",
       "      <td>VASP with PAW/PBE</td>\n",
       "      <td>[{u'url': u'http://oqmd.org/materials/entry/31...</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1182</td>\n",
       "      <td>GaN</td>\n",
       "      <td>[{u'scalar': [{u'value': u'331269'}], u'name':...</td>\n",
       "      <td>0.72</td>\n",
       "      <td>-0.116</td>\n",
       "      <td>0.479</td>\n",
       "      <td>[{u'units': u'KPPRA', u'scalar': [{u'value': u...</td>\n",
       "      <td>Computational</td>\n",
       "      <td>VASP with PAW/PBE</td>\n",
       "      <td>[{u'url': u'http://oqmd.org/materials/entry/33...</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1175</td>\n",
       "      <td>GaN</td>\n",
       "      <td>[{u'scalar': [{u'value': u'306699'}], u'name':...</td>\n",
       "      <td>0.00</td>\n",
       "      <td>1.026</td>\n",
       "      <td>1.620</td>\n",
       "      <td>[{u'units': u'KPPRA', u'scalar': [{u'value': u...</td>\n",
       "      <td>Computational</td>\n",
       "      <td>VASP with PAW/PBE</td>\n",
       "      <td>[{u'url': u'http://oqmd.org/materials/entry/30...</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>1165</td>\n",
       "      <td>GaN</td>\n",
       "      <td>[{u'scalar': [{u'value': u'97043'}], u'name': ...</td>\n",
       "      <td>2.09</td>\n",
       "      <td>-0.593</td>\n",
       "      <td>0.001</td>\n",
       "      <td>[{u'units': u'KPPRA', u'scalar': [{u'value': u...</td>\n",
       "      <td>Computational</td>\n",
       "      <td>VASP with PAW/PBE</td>\n",
       "      <td>[{u'url': u'http://oqmd.org/materials/entry/97...</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        data_set_id material.chemicalFormula  \\\n",
       "sample                                         \n",
       "1              1183                      GaN   \n",
       "2              1178                      GaN   \n",
       "3              1182                      GaN   \n",
       "4              1175                      GaN   \n",
       "5              1165                      GaN   \n",
       "\n",
       "                                       material.condition Band gap  \\\n",
       "sample                                                               \n",
       "1       [{u'scalar': [{u'value': u'334755'}], u'name':...     1.99   \n",
       "2       [{u'scalar': [{u'value': u'317241'}], u'name':...     0.00   \n",
       "3       [{u'scalar': [{u'value': u'331269'}], u'name':...     0.72   \n",
       "4       [{u'scalar': [{u'value': u'306699'}], u'name':...     0.00   \n",
       "5       [{u'scalar': [{u'value': u'97043'}], u'name': ...     2.09   \n",
       "\n",
       "       Formation energy Stability (energy relative to convex hull)  \\\n",
       "sample                                                               \n",
       "1                -0.594                                     -0.584   \n",
       "2                 0.355                                      0.950   \n",
       "3                -0.116                                      0.479   \n",
       "4                 1.026                                      1.620   \n",
       "5                -0.593                                      0.001   \n",
       "\n",
       "                                    measurement.condition  \\\n",
       "sample                                                      \n",
       "1       [{u'units': u'KPPRA', u'scalar': [{u'value': u...   \n",
       "2       [{u'units': u'KPPRA', u'scalar': [{u'value': u...   \n",
       "3       [{u'units': u'KPPRA', u'scalar': [{u'value': u...   \n",
       "4       [{u'units': u'KPPRA', u'scalar': [{u'value': u...   \n",
       "5       [{u'units': u'KPPRA', u'scalar': [{u'value': u...   \n",
       "\n",
       "       measurement.dataType measurement.method  \\\n",
       "sample                                           \n",
       "1             Computational  VASP with PAW/PBE   \n",
       "2             Computational  VASP with PAW/PBE   \n",
       "3             Computational  VASP with PAW/PBE   \n",
       "4             Computational  VASP with PAW/PBE   \n",
       "5             Computational  VASP with PAW/PBE   \n",
       "\n",
       "                                    measurement.reference  \\\n",
       "sample                                                      \n",
       "1       [{u'url': u'http://oqmd.org/materials/entry/33...   \n",
       "2       [{u'url': u'http://oqmd.org/materials/entry/31...   \n",
       "3       [{u'url': u'http://oqmd.org/materials/entry/33...   \n",
       "4       [{u'url': u'http://oqmd.org/materials/entry/30...   \n",
       "5       [{u'url': u'http://oqmd.org/materials/entry/97...   \n",
       "\n",
       "                                           property.units  \n",
       "sample                                                     \n",
       "1       {u'Formation energy': u'eV/atom', u'Band gap':...  \n",
       "2                                                     NaN  \n",
       "3                                                     NaN  \n",
       "4                                                     NaN  \n",
       "5                                                     NaN  "
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc[df['material.chemicalFormula'] == 'GaN']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "celltoolbar": "Raw Cell Format",
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "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.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
