{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Pre-requisites\n",
    "\n",
    "This Notebook requires the following to be installed on one's machine:\n",
    "\n",
    "* **openmc**\n",
    "* **beavrs**\n",
    "\n",
    "**NOTE**: You can install the `beavrs` Python module by running the following in the terminal:\n",
    "\n",
    "```\n",
    "$ python setup.py install --user\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import openmc\n",
    "import beavrs.builder\n",
    "from beavrs.constants import Constants\n",
    "from IPython.display import Image\n",
    "\n",
    "c = Constants(150,0)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Create BEAVRS Model"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Cannot have a negative S position. S set to 0\n",
      "Cannot have a negative SS position. SS set to 0\n",
      "  RCCA Positions\n",
      "    A: 228  B: 228  C: 228  D: 228\n",
      "   SA: 228 SB: 228 SC: 228 SD: 228 SE: 228\n"
     ]
    }
   ],
   "source": [
    "# Instantiate a BEAVRS object from the mit-crpg/PWR_benchmarks repository\n",
    "b = beavrs.builder.BEAVRS(0)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The BEAVRS model represented by variable `b` encapsulates the fully-detailed 3D BEAVRS core geometry and materials built using the OpenMC Python API."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Create \"geometry.xml\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We wish to extract a fuel assembly from the BEAVRS `Geometry` object for our simulation. We will first extract a Python `list` of all `Lattice` objects in the `Geometry` using the `Geometry.get_all_lattices()` routine:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# Get all OpenMC Lattices in a Python list\n",
    "all_latts = b.openmc_geometry.get_all_lattices()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "There are a number of different fuel assembly `Lattices` in the BEAVRS model, each of which has been assigned a unique string name. let's loop over all `Lattices` and report the string name for each `Lattice`:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "762 Core Lattice\n",
      "336 Fuel 3.1% enr no instr no BAs\n",
      "354 Fuel 3.1% enr no instr 6S\n",
      "339 Fuel 3.1% enr instr no BAs\n",
      "357 Fuel 3.1% enr instr 6S\n",
      "444 Fuel 3.1% enr no instr RCCA SA\n",
      "408 Fuel 3.1% enr no instr 16\n",
      "153 Fuel 1.6% enr instr RCCA B\n",
      "414 Fuel 3.1% enr no instr 20\n",
      "159 Fuel 1.6% enr instr RCCA C\n",
      "150 Fuel 1.6% enr no instr RCCA B\n",
      "402 Fuel 3.1% enr no instr 15SE\n",
      "270 Fuel 2.4% enr no instr 16\n",
      "186 Fuel 1.6% enr no instr RCCA SD\n",
      "174 Fuel 1.6% enr no instr RCCA SB\n",
      "273 Fuel 2.4% enr instr 16\n",
      "180 Fuel 1.6% enr no instr RCCA SC\n",
      "396 Fuel 3.1% enr no instr 15SW\n",
      "447 Fuel 3.1% enr instr RCCA SA\n",
      "300 Fuel 2.4% enr no instr RCCA D\n",
      "60 Fuel 1.6% enr no instr no BAs\n",
      "240 Fuel 2.4% enr no instr 12\n",
      "195 Fuel 1.6% enr instr RCCA SE\n",
      "63 Fuel 1.6% enr instr no BAs\n",
      "189 Fuel 1.6% enr instr RCCA SD\n",
      "363 Fuel 3.1% enr instr 6E\n",
      "147 Fuel 1.6% enr instr RCCA A\n",
      "156 Fuel 1.6% enr no instr RCCA C\n",
      "366 Fuel 3.1% enr no instr 6W\n",
      "243 Fuel 2.4% enr instr 12\n",
      "177 Fuel 1.6% enr instr RCCA SB\n",
      "192 Fuel 1.6% enr no instr RCCA SE\n",
      "144 Fuel 1.6% enr no instr RCCA A\n",
      "162 Fuel 1.6% enr no instr RCCA D\n",
      "417 Fuel 3.1% enr instr 20\n",
      "360 Fuel 3.1% enr no instr 6E\n",
      "303 Fuel 2.4% enr instr RCCA D\n",
      "393 Fuel 3.1% enr instr 15NE\n",
      "183 Fuel 1.6% enr instr RCCA SC\n",
      "384 Fuel 3.1% enr no instr 15NW\n",
      "348 Fuel 3.1% enr no instr 6N\n",
      "351 Fuel 3.1% enr instr 6N\n"
     ]
    }
   ],
   "source": [
    "# Print the name of each Lattice\n",
    "for id, latt in all_latts.items():\n",
    "    print(id, latt.name)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Now that we know the names of all of the `Lattices` in the BEAVRS `Geometry`, let's select out the one we wish to model."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# Find the 1.6% enriched fuel lattice w/o BAs\n",
    "assembly_name = 'Fuel 1.6% enr instr no BAs'\n",
    "for id, latt in all_latts.items():\n",
    "    if latt.name == assembly_name:\n",
    "        assembly = latt"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can inspect our chosen fuel assembly using OpenMC's built-in string representation for the object:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "RectLattice\n",
       "\tID             =\t63\n",
       "\tName           =\tFuel 1.6% enr instr no BAs\n",
       "\tShape          =\t(17, 17)\n",
       "\tLower Left     =\t[-10.70864, -10.70864]\n",
       "\tPitch          =\t[1.25984, 1.25984]\n",
       "\tOuter          =\tNone\n",
       "\tUniverses      \n",
       "15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 \n",
       "15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 \n",
       "15 15 15 15 15 27 15 15 27 15 15 27 15 15 15 15 15 \n",
       "15 15 15 27 15 15 15 15 15 15 15 15 15 27 15 15 15 \n",
       "15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 \n",
       "15 15 27 15 15 27 15 15 27 15 15 27 15 15 27 15 15 \n",
       "15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 \n",
       "15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 \n",
       "15 15 27 15 15 27 15 15 33 15 15 27 15 15 27 15 15 \n",
       "15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 \n",
       "15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 \n",
       "15 15 27 15 15 27 15 15 27 15 15 27 15 15 27 15 15 \n",
       "15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 \n",
       "15 15 15 27 15 15 15 15 15 15 15 15 15 27 15 15 15 \n",
       "15 15 15 15 15 27 15 15 27 15 15 27 15 15 15 15 15 \n",
       "15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 \n",
       "15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 "
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "assembly"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We need to construct a sub-geometry encapsulating only this fuel assembly rather than the entire BEAVRS core. We will do this by first creating a \"root\" cell and fill it with our fuel assembly:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# Create surface objects for our \"root\" cell\"\n",
    "lattice_sides = openmc.model.RectangularPrism(17*c.pinPitch, 17*c.pinPitch,\n",
    "                                                   boundary_type='reflective')\n",
    "min_z = openmc.ZPlane(z0=c.struct_LowestExtent, boundary_type='vacuum')\n",
    "max_z = openmc.ZPlane(z0=c.struct_HighestExtent, boundary_type='vacuum')\n",
    "\n",
    "# Create a \"root\" cell filled by the fuel assembly\n",
    "root_cell = openmc.Cell(name='root cell',\n",
    "                        fill=assembly,\n",
    "                        region=-lattice_sides & +min_z & -max_z\n",
    "                       )"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We then create a \"root\" universe and add our \"root\" cell to it:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# Create a \"root\" universe with ID=0 and add the \"root\" cell to it\n",
    "root_univ = openmc.Universe(name='root universe', cells=[root_cell])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Lastly, the \"root\" universe must be attached to a new OpenMC `Geometry` object representing this new sub-geometry:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# Create an OpenMC Geometry around root Universe\n",
    "sub_geometry = openmc.Geometry(root_univ)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Finally, we are ready to create a \"geometry.xml\" input file for OpenMC! We simply export it to XML as follows:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# Export the OpenMC Geometry to a \"geometry.xml\" file\n",
    "sub_geometry.export_to_xml()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Create \"materials.xml\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Now we need to create materials for our geometry. This is very easy to do with the `b.write_openmc_materials()` routine. The one disadvantage of this is that it will write *all* materials for the entire BEAVRS geometry to a \"materials.xml\" file, most of which are not used in our sub-geometry for a single fuel assembly. Instead, we can write out only those materials that are in our geometry as follows:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# Get a list of all OpenMC Materials\n",
    "all_materials = sub_geometry.get_all_materials()\n",
    "\n",
    "# Create a MaterialsFile object\n",
    "materials = openmc.Materials(all_materials.values())\n",
    "\n",
    "# Export the OpenMC Materials to a \"materials.xml\" file\n",
    "materials.export_to_xml()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Create \"settings.xml\" "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Now for the easy part :-) Let's create a \"settings.xml\" file:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# Create a MaterialsFile object\n",
    "settings = openmc.Settings()\n",
    "\n",
    "# Set any settings of interest\n",
    "settings.batches = 150\n",
    "settings.inactive = 10\n",
    "settings.particles = 1000\n",
    "\n",
    "# Use a bounding box to define the starting source distribution\n",
    "lower_left = [-17*c.pinPitch/2, -17*c.pinPitch/2, c.fuel_ActiveFuel_bot]\n",
    "upper_right = [+17*c.pinPitch/2, +17*c.pinPitch/2, c.fuel_ActiveFuel_top]\n",
    "settings.source = openmc.source.IndependentSource(\n",
    "    openmc.stats.Box(lower_left, upper_right, only_fissionable=True))\n",
    "\n",
    "# Export the settings to a \"settings.xml\" file\n",
    "settings.export_to_xml()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Create \"plots.xml\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# Create a single plot using default paramters (basis='xy', origin=(0,0,0))\n",
    "plot = openmc.Plot(plot_id=1)\n",
    "plot.width = [17*c.pinPitch, 17*c.pinPitch]\n",
    "\n",
    "# Create a PlotsFile object and add our plot to it\n",
    "plot_file = openmc.Plots([plot])\n",
    "\n",
    "# Export the plots to a \"plots.xml\" file\n",
    "plot_file.export_to_xml()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "With the \"plots.xml\" file, we can now generate and view the plot. We must first instantiate an `openmc.Executor` object and then ask it to plot the geometry(equivalent to running `openmc -p` from within the terminal)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# Run openmc in plotting mode\n",
    "openmc.plot_geometry(output=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "OpenMC outputs plots in .ppm format, which can be converted into a compressed format like .png with the convert utility. We can view the .png image inline using the `IPython.display.Image` class as follows:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAZAAAAGQCAIAAAAP3aGbAAAFMklEQVR4nO3UQQ0AIBDAMMC/58MCP7KkVbDX9swsgILzOwDglWEBGYYFZBgWkGFYQIZhARmGBWQYFpBhWECGYQEZhgVkGBaQYVhAhmEBGYYFZBgWkGFYQIZhARmGBWQYFpBhWECGYQEZhgVkGBaQYVhAhmEBGYYFZBgWkGFYQIZhARmGBWQYFpBhWECGYQEZhgVkGBaQYVhAhmEBGYYFZBgWkGFYQIZhARmGBWQYFpBhWECGYQEZhgVkGBaQYVhAhmEBGYYFZBgWkGFYQIZhARmGBWQYFpBhWECGYQEZhgVkGBaQYVhAhmEBGYYFZBgWkGFYQIZhARmGBWQYFpBhWECGYQEZhgVkGBaQYVhAhmEBGYYFZBgWkGFYQIZhARmGBWQYFpBhWECGYQEZhgVkGBaQYVhAhmEBGYYFZBgWkGFYQIZhARmGBWQYFpBhWECGYQEZhgVkGBaQYVhAhmEBGYYFZBgWkGFYQIZhARmGBWQYFpBhWECGYQEZhgVkGBaQYVhAhmEBGYYFZBgWkGFYQIZhARmGBWQYFpBhWECGYQEZhgVkGBaQYVhAhmEBGYYFZBgWkGFYQIZhARmGBWQYFpBhWECGYQEZhgVkGBaQYVhAhmEBGYYFZBgWkGFYQIZhARmGBWQYFpBhWECGYQEZhgVkGBaQYVhAhmEBGYYFZBgWkGFYQIZhARmGBWQYFpBhWECGYQEZhgVkGBaQYVhAhmEBGYYFZBgWkGFYQIZhARmGBWQYFpBhWECGYQEZhgVkGBaQYVhAhmEBGYYFZBgWkGFYQIZhARmGBWQYFpBhWECGYQEZhgVkGBaQYVhAhmEBGYYFZBgWkGFYQIZhARmGBWQYFpBhWECGYQEZhgVkGBaQYVhAhmEBGYYFZBgWkGFYQIZhARmGBWQYFpBhWECGYQEZhgVkGBaQYVhAhmEBGYYFZBgWkGFYQIZhARmGBWQYFpBhWECGYQEZhgVkGBaQYVhAhmEBGYYFZBgWkGFYQIZhARmGBWQYFpBhWECGYQEZhgVkGBaQYVhAhmEBGYYFZBgWkGFYQIZhARmGBWQYFpBhWECGYQEZhgVkGBaQYVhAhmEBGYYFZBgWkGFYQIZhARmGBWQYFpBhWECGYQEZhgVkGBaQYVhAhmEBGYYFZBgWkGFYQIZhARmGBWQYFpBhWECGYQEZhgVkGBaQYVhAhmEBGYYFZBgWkGFYQIZhARmGBWQYFpBhWECGYQEZhgVkGBaQYVhAhmEBGYYFZBgWkGFYQIZhARmGBWQYFpBhWECGYQEZhgVkGBaQYVhAhmEBGYYFZBgWkGFYQIZhARmGBWQYFpBhWECGYQEZhgVkGBaQYVhAhmEBGYYFZBgWkGFYQIZhARmGBWQYFpBhWECGYQEZhgVkGBaQYVhAhmEBGYYFZBgWkGFYQIZhARmGBWQYFpBhWECGYQEZhgVkGBaQYVhAhmEBGYYFZBgWkGFYQIZhARmGBWQYFpBhWECGYQEZhgVkGBaQYVhAhmEBGYYFZBgWkGFYQIZhARmGBWQYFpBhWECGYQEZhgVkGBaQYVhAhmEBGYYFZBgWkGFYQIZhARmGBWQYFpBhWECGYQEZhgVkGBaQYVhAhmEBGYYFZBgWkGFYQIZhARmGBWQYFpBhWECGYQEZhgVkGBaQYVhAhmEBGYYFZBgWkGFYQIZhARmGBWQYFpBhWECGYQEZhgVkGBaQYVhAhmEBGYYFZBgWkGFYQIZhARmGBWQYFpBhWECGYQEZhgVkGBaQYVhAhmEBGYYFZFwW0QYdRnYtDgAAAABJRU5ErkJggg==",
      "text/plain": [
       "<IPython.core.display.Image object>"
      ]
     },
     "execution_count": 15,
     "metadata": {
      "image/png": {
       "height": 250,
       "width": 250
      }
     },
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Display the plot inline\n",
    "Image(filename='plot_1.png', width=250, height=250)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Create \"tallies.xml\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "I'm not exactly sure what you need in the way of tallies, but perhaps I can get you started with a fission tally in the instrument tube. First, let's inspect the names for all of the `Cells` in the geometry using the `all_material_cells` list:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Fuel rod - 1.6% enr axial 0: Borated Water\n",
      "Fuel rod - 1.6% enr axial 1: SS SPN\n",
      "Fuel rod - 1.6% enr axial 2: Zircaloy 4\n",
      "Fuel rod - 1.6% enr axial 5: Zircaloy 4\n",
      "Fuel rod - 1.6% enr axial 6: Borated Water\n",
      "Fuel rod - 1.6% enr axial 7: SS SPN\n",
      "Fuel rod - 1.6% enr axial top: Borated Water\n",
      "Fuel rod active region - 1.6% enr radial 0: Fuel 1.6%\n",
      "Fuel rod active region - 1.6% enr radial 1: Helium\n",
      "Fuel rod active region - 1.6% enr radial outer: Zircaloy 4\n",
      "Fuel rod plenum radial 0: Inconel 718\n",
      "Fuel rod plenum radial 1: Helium\n",
      "Fuel rod plenum radial outer: Zircaloy 4\n",
      "Grids axial universe axial 0: Borated Water\n",
      "Grids axial universe axial 1: Water SPN\n",
      "Grids axial universe axial 2: Borated Water\n",
      "Grids axial universe axial 4: Borated Water\n",
      "Grids axial universe axial 6: Borated Water\n",
      "Grids axial universe axial 8: Borated Water\n",
      "Grids axial universe axial 10: Borated Water\n",
      "Grids axial universe axial 12: Borated Water\n",
      "Grids axial universe axial 14: Borated Water\n",
      "Grids axial universe axial 16: Borated Water\n",
      "Grids axial universe axial 18: Borated Water\n",
      "Grids axial universe axial 19: Water SPN\n",
      "Grids axial universe axial top: Borated Water\n",
      "Top/Bottom grid pincell radial 0: Borated Water\n",
      "Top/Bottom grid pincell radial outer: Inconel 718\n",
      "Intermediate grid pincell radial 0: Borated Water\n",
      "Intermediate grid pincell radial outer: Zircaloy 4\n",
      "Empty Guide Tube axial 0: Borated Water\n",
      "Empty Guide Tube axial 1: Water SPN\n",
      "Empty Guide Tube axial 4: Water SPN\n",
      "Empty Guide Tube axial top: Borated Water\n",
      "Empty GT below the dashpot radial 0: Borated Water\n",
      "Empty GT below the dashpot radial 1: Zircaloy 4\n",
      "Empty GT below the dashpot radial outer: Borated Water\n",
      "Empty GT above the dashpot radial 0: Borated Water\n",
      "Empty GT above the dashpot radial outer: Zircaloy 4\n",
      "Instrument tube axial stack axial 3: Water SPN\n",
      "Instrument tube axial stack axial top: Borated Water\n",
      "Instrument tube thimble radial 0: Air\n",
      "Instrument tube thimble radial outer: Zircaloy 4\n",
      "Instrument tube thimble support plane radial 0: Air\n",
      "Instrument tube thimble support plane radial outer: Zircaloy 4\n",
      "Empty Guide Tube in Center Position axial 0: Borated Water\n",
      "Empty Guide Tube in Center Position axial 1: Water SPN\n",
      "Empty Guide Tube in Center Position axial 3: Water SPN\n",
      "Empty Guide Tube in Center Position axial top: Borated Water\n"
     ]
    }
   ],
   "source": [
    "all_material_cells = sub_geometry.get_all_material_cells()\n",
    "for id, cell in all_material_cells.items():\n",
    "    print(cell.name)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Perhaps you'd like a tally in one of these cells. First, we need to extract the cell(s) of interest:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "cell_name = 'Instrument tube thimble radial 0: Air'\n",
    "for id, cell in all_material_cells.items():\n",
    "    if cell.name == cell_name:\n",
    "        my_cell = cell"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Let's tally the fast/thermal scatter and absorption rates for all nuclides in our cell. We create a `Tally` to do so as follows:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# Instantiate a really cool tally\n",
    "tally = openmc.Tally(name='a really cool tally')\n",
    "\n",
    "# Instantiate a cell filter\n",
    "cell_filter = openmc.CellFilter(bins=[my_cell.id])\n",
    "\n",
    "# Instantiate energy filter\n",
    "energy_filter = openmc.EnergyFilter([0., 0.625e-6, 20.])\n",
    "\n",
    "tally.filters = [cell_filter, energy_filter]\n",
    "\n",
    "# Add the scores of interest to the tally\n",
    "tally.scores = ['scatter', 'absorption']\n",
    "\n",
    "# Add all nuclides to the tally for kicks\n",
    "tally.nuclides = my_cell.fill.get_nuclides()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Next, we simply need to add our `Tally` object(s) to a `TalliesFile` object and export them to a \"tallies.xml\" file:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# Instantiate an empty TalliesFile\n",
    "tallies_file = openmc.Tallies()\n",
    "\n",
    "# Add our tally(ies) to the file\n",
    "tallies_file.append(tally)\n",
    "\n",
    "# Export the tallies to a \"tallies.xml\" file\n",
    "tallies_file.export_to_xml()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Run OpenMC!"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can run OpenMC from within the notebook if we wish. Wow, isn't this so much more powerful than ASCII!"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "                                %%%%%%%%%%%%%%%\n",
      "                           %%%%%%%%%%%%%%%%%%%%%%%%\n",
      "                        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n",
      "                      %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n",
      "                    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n",
      "                   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n",
      "                                    %%%%%%%%%%%%%%%%%%%%%%%%\n",
      "                                     %%%%%%%%%%%%%%%%%%%%%%%%\n",
      "                 ###############      %%%%%%%%%%%%%%%%%%%%%%%%\n",
      "                ##################     %%%%%%%%%%%%%%%%%%%%%%%\n",
      "                ###################     %%%%%%%%%%%%%%%%%%%%%%%\n",
      "                ####################     %%%%%%%%%%%%%%%%%%%%%%\n",
      "                #####################     %%%%%%%%%%%%%%%%%%%%%\n",
      "                ######################     %%%%%%%%%%%%%%%%%%%%\n",
      "                #######################     %%%%%%%%%%%%%%%%%%\n",
      "                 #######################     %%%%%%%%%%%%%%%%%\n",
      "                 ######################     %%%%%%%%%%%%%%%%%\n",
      "                  ####################     %%%%%%%%%%%%%%%%%\n",
      "                    #################     %%%%%%%%%%%%%%%%%\n",
      "                     ###############     %%%%%%%%%%%%%%%%\n",
      "                       ############     %%%%%%%%%%%%%%%\n",
      "                          ########     %%%%%%%%%%%%%%\n",
      "                                      %%%%%%%%%%%\n",
      "\n",
      "                 | The OpenMC Monte Carlo Code\n",
      "       Copyright | 2011-2023 MIT, UChicago Argonne LLC, and contributors\n",
      "         License | https://docs.openmc.org/en/latest/license.html\n",
      "         Version | 0.14.0\n",
      "        Git SHA1 | e1a8ee7794b441c992426f17fafe216391cbba83\n",
      "       Date/Time | 2024-02-02 00:45:16\n",
      "   MPI Processes | 1\n",
      "  OpenMP Threads | 4\n",
      "\n",
      " Reading settings XML file...\n",
      " Reading cross sections XML file...\n",
      " Reading materials XML file...\n",
      " Reading geometry XML file...\n",
      " Reading O16 from /opt/xdata/endfb-vii.1-hdf5/neutron/O16.h5\n",
      " Reading O17 from /opt/xdata/endfb-vii.1-hdf5/neutron/O17.h5\n",
      " Reading N14 from /opt/xdata/endfb-vii.1-hdf5/neutron/N14.h5\n",
      " Reading N15 from /opt/xdata/endfb-vii.1-hdf5/neutron/N15.h5\n",
      " Reading Ar36 from /opt/xdata/endfb-vii.1-hdf5/neutron/Ar36.h5\n",
      " WARNING: Negative value(s) found on probability table for nuclide Ar36 at 294K\n",
      " Reading Ar38 from /opt/xdata/endfb-vii.1-hdf5/neutron/Ar38.h5\n",
      " Reading Ar40 from /opt/xdata/endfb-vii.1-hdf5/neutron/Ar40.h5\n",
      " Reading C0 from /opt/xdata/endfb-vii.1-hdf5/neutron/C0.h5\n",
      " Reading He3 from /opt/xdata/endfb-vii.1-hdf5/neutron/He3.h5\n",
      " Reading He4 from /opt/xdata/endfb-vii.1-hdf5/neutron/He4.h5\n",
      " Reading Si28 from /opt/xdata/endfb-vii.1-hdf5/neutron/Si28.h5\n",
      " Reading Si29 from /opt/xdata/endfb-vii.1-hdf5/neutron/Si29.h5\n",
      " Reading Si30 from /opt/xdata/endfb-vii.1-hdf5/neutron/Si30.h5\n",
      " Reading Cr50 from /opt/xdata/endfb-vii.1-hdf5/neutron/Cr50.h5\n",
      " Reading Cr52 from /opt/xdata/endfb-vii.1-hdf5/neutron/Cr52.h5\n",
      " Reading Cr53 from /opt/xdata/endfb-vii.1-hdf5/neutron/Cr53.h5\n",
      " Reading Cr54 from /opt/xdata/endfb-vii.1-hdf5/neutron/Cr54.h5\n",
      " Reading Mn55 from /opt/xdata/endfb-vii.1-hdf5/neutron/Mn55.h5\n",
      " Reading Fe54 from /opt/xdata/endfb-vii.1-hdf5/neutron/Fe54.h5\n",
      " Reading Fe56 from /opt/xdata/endfb-vii.1-hdf5/neutron/Fe56.h5\n",
      " Reading Fe57 from /opt/xdata/endfb-vii.1-hdf5/neutron/Fe57.h5\n",
      " Reading Fe58 from /opt/xdata/endfb-vii.1-hdf5/neutron/Fe58.h5\n",
      " Reading Ni58 from /opt/xdata/endfb-vii.1-hdf5/neutron/Ni58.h5\n",
      " Reading Ni60 from /opt/xdata/endfb-vii.1-hdf5/neutron/Ni60.h5\n",
      " Reading Ni61 from /opt/xdata/endfb-vii.1-hdf5/neutron/Ni61.h5\n",
      " Reading Ni62 from /opt/xdata/endfb-vii.1-hdf5/neutron/Ni62.h5\n",
      " Reading Ni64 from /opt/xdata/endfb-vii.1-hdf5/neutron/Ni64.h5\n",
      " Reading Zr90 from /opt/xdata/endfb-vii.1-hdf5/neutron/Zr90.h5\n",
      " Reading Zr91 from /opt/xdata/endfb-vii.1-hdf5/neutron/Zr91.h5\n",
      " Reading Zr92 from /opt/xdata/endfb-vii.1-hdf5/neutron/Zr92.h5\n",
      " Reading Zr94 from /opt/xdata/endfb-vii.1-hdf5/neutron/Zr94.h5\n",
      " Reading Zr96 from /opt/xdata/endfb-vii.1-hdf5/neutron/Zr96.h5\n",
      " Reading Sn112 from /opt/xdata/endfb-vii.1-hdf5/neutron/Sn112.h5\n",
      " Reading Sn114 from /opt/xdata/endfb-vii.1-hdf5/neutron/Sn114.h5\n",
      " Reading Sn115 from /opt/xdata/endfb-vii.1-hdf5/neutron/Sn115.h5\n",
      " Reading Sn116 from /opt/xdata/endfb-vii.1-hdf5/neutron/Sn116.h5\n",
      " Reading Sn117 from /opt/xdata/endfb-vii.1-hdf5/neutron/Sn117.h5\n",
      " Reading Sn118 from /opt/xdata/endfb-vii.1-hdf5/neutron/Sn118.h5\n",
      " Reading Sn119 from /opt/xdata/endfb-vii.1-hdf5/neutron/Sn119.h5\n",
      " Reading Sn120 from /opt/xdata/endfb-vii.1-hdf5/neutron/Sn120.h5\n",
      " Reading Sn122 from /opt/xdata/endfb-vii.1-hdf5/neutron/Sn122.h5\n",
      " Reading Sn124 from /opt/xdata/endfb-vii.1-hdf5/neutron/Sn124.h5\n",
      " Reading U234 from /opt/xdata/endfb-vii.1-hdf5/neutron/U234.h5\n",
      " Reading U235 from /opt/xdata/endfb-vii.1-hdf5/neutron/U235.h5\n",
      " Reading U238 from /opt/xdata/endfb-vii.1-hdf5/neutron/U238.h5\n",
      " Reading U236 from /opt/xdata/endfb-vii.1-hdf5/neutron/U236.h5\n",
      " Reading B10 from /opt/xdata/endfb-vii.1-hdf5/neutron/B10.h5\n",
      " Reading B11 from /opt/xdata/endfb-vii.1-hdf5/neutron/B11.h5\n",
      " Reading H1 from /opt/xdata/endfb-vii.1-hdf5/neutron/H1.h5\n",
      " Reading H2 from /opt/xdata/endfb-vii.1-hdf5/neutron/H2.h5\n",
      " Reading c_H_in_H2O from /opt/xdata/endfb-vii.1-hdf5/neutron/c_H_in_H2O.h5\n",
      " Minimum neutron data temperature: 294 K\n",
      " Maximum neutron data temperature: 294 K\n",
      " Reading tallies XML file...\n",
      " Preparing distributed cell instances...\n",
      " Reading plot XML file...\n",
      " Writing summary.h5 file...\n",
      " Maximum neutron transport energy: 20000000 eV for O17\n",
      " Initializing source particles...\n",
      "\n",
      " ====================>     K EIGENVALUE SIMULATION     <====================\n",
      "\n",
      "  Bat./Gen.      k            Average k\n",
      "  =========   ========   ====================\n",
      "        1/1    0.96733\n",
      "        2/1    1.01426\n",
      "        3/1    1.00891\n",
      "        4/1    0.98251\n",
      "        5/1    0.97608\n",
      "        6/1    0.98854\n",
      "        7/1    0.98650\n",
      "        8/1    0.89145\n",
      "        9/1    0.99093\n",
      "       10/1    1.01713\n",
      "       11/1    0.97521\n",
      "       12/1    1.00458    0.98990 +/- 0.01468\n",
      "       13/1    1.05596    1.01192 +/- 0.02360\n",
      "       14/1    1.03992    1.01892 +/- 0.01810\n",
      "       15/1    0.99228    1.01359 +/- 0.01500\n",
      "       16/1    1.04166    1.01827 +/- 0.01311\n",
      "       17/1    1.02397    1.01908 +/- 0.01111\n",
      "       18/1    0.93476    1.00854 +/- 0.01427\n",
      "       19/1    0.96790    1.00403 +/- 0.01337\n",
      "       20/1    1.01333    1.00496 +/- 0.01199\n",
      "       21/1    0.99930    1.00444 +/- 0.01086\n",
      "       22/1    0.96360    1.00104 +/- 0.01048\n",
      "       23/1    1.04452    1.00438 +/- 0.01021\n",
      "       24/1    1.00540    1.00446 +/- 0.00945\n",
      "       25/1    1.03337    1.00638 +/- 0.00901\n",
      "       26/1    0.98441    1.00501 +/- 0.00854\n",
      "       27/1    0.97719    1.00337 +/- 0.00818\n",
      "       28/1    0.99739    1.00304 +/- 0.00772\n",
      "       29/1    0.97195    1.00141 +/- 0.00749\n",
      "       30/1    0.97567    1.00012 +/- 0.00722\n",
      "       31/1    0.98488    0.99939 +/- 0.00690\n",
      "       32/1    0.99132    0.99903 +/- 0.00659\n",
      "       33/1    0.97166    0.99784 +/- 0.00641\n",
      "       34/1    1.02146    0.99882 +/- 0.00622\n",
      "       35/1    1.00964    0.99925 +/- 0.00598\n",
      "       36/1    1.00894    0.99963 +/- 0.00576\n",
      "       37/1    1.04730    1.00139 +/- 0.00581\n",
      "       38/1    1.00749    1.00161 +/- 0.00561\n",
      "       39/1    0.97450    1.00067 +/- 0.00549\n",
      "       40/1    0.99078    1.00034 +/- 0.00531\n",
      "       41/1    0.98638    0.99989 +/- 0.00516\n",
      "       42/1    1.05222    1.00153 +/- 0.00526\n",
      "       43/1    1.00114    1.00152 +/- 0.00509\n",
      "       44/1    1.00369    1.00158 +/- 0.00494\n",
      "       45/1    0.98097    1.00099 +/- 0.00483\n",
      "       46/1    1.01918    1.00150 +/- 0.00473\n",
      "       47/1    1.02984    1.00226 +/- 0.00466\n",
      "       48/1    1.00466    1.00233 +/- 0.00454\n",
      "       49/1    0.97042    1.00151 +/- 0.00449\n",
      "       50/1    0.98406    1.00107 +/- 0.00440\n",
      "       51/1    1.02719    1.00171 +/- 0.00434\n",
      "       52/1    0.96843    1.00092 +/- 0.00431\n",
      "       53/1    0.96103    0.99999 +/- 0.00431\n",
      "       54/1    1.08631    1.00195 +/- 0.00464\n",
      "       55/1    1.04892    1.00300 +/- 0.00466\n",
      "       56/1    1.04540    1.00392 +/- 0.00465\n",
      "       57/1    1.02331    1.00433 +/- 0.00457\n",
      "       58/1    0.98167    1.00386 +/- 0.00450\n",
      "       59/1    0.95736    1.00291 +/- 0.00450\n",
      "       60/1    1.08186    1.00449 +/- 0.00469\n",
      "       61/1    0.99151    1.00423 +/- 0.00460\n",
      "       62/1    1.09483    1.00598 +/- 0.00484\n",
      "       63/1    0.96655    1.00523 +/- 0.00480\n",
      "       64/1    1.02323    1.00556 +/- 0.00472\n",
      "       65/1    0.99552    1.00538 +/- 0.00464\n",
      "       66/1    1.03743    1.00595 +/- 0.00459\n",
      "       67/1    1.01470    1.00611 +/- 0.00451\n",
      "       68/1    1.00330    1.00606 +/- 0.00444\n",
      "       69/1    0.99583    1.00589 +/- 0.00436\n",
      "       70/1    0.97011    1.00529 +/- 0.00433\n",
      "       71/1    1.05257    1.00606 +/- 0.00433\n",
      "       72/1    0.95486    1.00524 +/- 0.00434\n",
      "       73/1    0.95579    1.00445 +/- 0.00434\n",
      "       74/1    1.06181    1.00535 +/- 0.00437\n",
      "       75/1    1.01547    1.00551 +/- 0.00430\n",
      "       76/1    0.95828    1.00479 +/- 0.00430\n",
      "       77/1    1.06930    1.00575 +/- 0.00434\n",
      "       78/1    0.98848    1.00550 +/- 0.00428\n",
      "       79/1    0.98801    1.00525 +/- 0.00423\n",
      "       80/1    1.01087    1.00533 +/- 0.00417\n",
      "       81/1    0.94958    1.00454 +/- 0.00418\n",
      "       82/1    1.04203    1.00506 +/- 0.00416\n",
      "       83/1    0.98562    1.00480 +/- 0.00411\n",
      "       84/1    1.01031    1.00487 +/- 0.00405\n",
      "       85/1    0.94282    1.00404 +/- 0.00408\n",
      "       86/1    1.01565    1.00419 +/- 0.00403\n",
      "       87/1    1.06248    1.00495 +/- 0.00405\n",
      "       88/1    0.96519    1.00444 +/- 0.00403\n",
      "       89/1    0.94915    1.00374 +/- 0.00404\n",
      "       90/1    1.00009    1.00370 +/- 0.00399\n",
      "       91/1    0.98034    1.00341 +/- 0.00395\n",
      "       92/1    1.02393    1.00366 +/- 0.00391\n",
      "       93/1    1.01846    1.00384 +/- 0.00387\n",
      "       94/1    1.04298    1.00430 +/- 0.00385\n",
      "       95/1    0.96884    1.00389 +/- 0.00383\n",
      "       96/1    0.98588    1.00368 +/- 0.00379\n",
      "       97/1    1.01417    1.00380 +/- 0.00375\n",
      "       98/1    1.03141    1.00411 +/- 0.00372\n",
      "       99/1    0.99799    1.00404 +/- 0.00367\n",
      "      100/1    0.97342    1.00370 +/- 0.00365\n",
      "      101/1    1.03521    1.00405 +/- 0.00363\n",
      "      102/1    0.99810    1.00398 +/- 0.00359\n",
      "      103/1    1.07640    1.00476 +/- 0.00363\n",
      "      104/1    0.92379    1.00390 +/- 0.00370\n",
      "      105/1    0.98163    1.00367 +/- 0.00366\n",
      "      106/1    1.05657    1.00422 +/- 0.00367\n",
      "      107/1    1.01114    1.00429 +/- 0.00363\n",
      "      108/1    0.98687    1.00411 +/- 0.00360\n",
      "      109/1    1.00438    1.00411 +/- 0.00356\n",
      "      110/1    1.04605    1.00453 +/- 0.00355\n",
      "      111/1    0.95116    1.00400 +/- 0.00355\n",
      "      112/1    1.04926    1.00445 +/- 0.00355\n",
      "      113/1    1.05672    1.00496 +/- 0.00355\n",
      "      114/1    0.98303    1.00474 +/- 0.00352\n",
      "      115/1    1.00398    1.00474 +/- 0.00349\n",
      "      116/1    1.00943    1.00478 +/- 0.00345\n",
      "      117/1    1.01657    1.00489 +/- 0.00342\n",
      "      118/1    0.95180    1.00440 +/- 0.00343\n",
      "      119/1    0.99597    1.00432 +/- 0.00340\n",
      "      120/1    0.95905    1.00391 +/- 0.00339\n",
      "      121/1    1.03602    1.00420 +/- 0.00337\n",
      "      122/1    0.91355    1.00339 +/- 0.00344\n",
      "      123/1    0.98042    1.00319 +/- 0.00341\n",
      "      124/1    0.99438    1.00311 +/- 0.00338\n",
      "      125/1    1.01523    1.00322 +/- 0.00336\n",
      "      126/1    1.02405    1.00340 +/- 0.00333\n",
      "      127/1    0.97345    1.00314 +/- 0.00331\n",
      "      128/1    0.99830    1.00310 +/- 0.00329\n",
      "      129/1    0.98598    1.00296 +/- 0.00326\n",
      "      130/1    0.97527    1.00272 +/- 0.00324\n",
      "      131/1    0.99513    1.00266 +/- 0.00322\n",
      "      132/1    0.95591    1.00228 +/- 0.00321\n",
      "      133/1    1.03151    1.00252 +/- 0.00319\n",
      "      134/1    1.01308    1.00260 +/- 0.00317\n",
      "      135/1    0.99918    1.00257 +/- 0.00314\n",
      "      136/1    1.01363    1.00266 +/- 0.00312\n",
      "      137/1    0.95709    1.00230 +/- 0.00312\n",
      "      138/1    1.01557    1.00241 +/- 0.00309\n",
      "      139/1    1.02028    1.00255 +/- 0.00307\n",
      "      140/1    1.03371    1.00278 +/- 0.00306\n",
      "      141/1    1.00297    1.00279 +/- 0.00304\n",
      "      142/1    0.97399    1.00257 +/- 0.00302\n",
      "      143/1    0.99265    1.00249 +/- 0.00300\n",
      "      144/1    0.96677    1.00223 +/- 0.00299\n",
      "      145/1    1.00505    1.00225 +/- 0.00297\n",
      "      146/1    1.02356    1.00240 +/- 0.00295\n",
      "      147/1    0.96630    1.00214 +/- 0.00294\n",
      "      148/1    1.01760    1.00225 +/- 0.00292\n",
      "      149/1    0.95798    1.00193 +/- 0.00292\n",
      "      150/1    1.06026    1.00235 +/- 0.00292\n",
      " Creating state point statepoint.150.h5...\n",
      "\n",
      " =======================>     TIMING STATISTICS     <=======================\n",
      "\n",
      " Total time for initialization     = 3.6541e+00 seconds\n",
      "   Reading cross sections          = 3.5885e+00 seconds\n",
      " Total time in simulation          = 1.2538e+01 seconds\n",
      "   Time in transport only          = 1.2481e+01 seconds\n",
      "   Time in inactive batches        = 8.1915e-01 seconds\n",
      "   Time in active batches          = 1.1719e+01 seconds\n",
      "   Time synchronizing fission bank = 1.2144e-02 seconds\n",
      "     Sampling source sites         = 1.0466e-02 seconds\n",
      "     SEND/RECV source sites        = 1.3148e-03 seconds\n",
      "   Time accumulating tallies       = 1.0449e-02 seconds\n",
      "   Time writing statepoints        = 9.1849e-03 seconds\n",
      " Total time for finalization       = 1.7939e-04 seconds\n",
      " Total time elapsed                = 1.6208e+01 seconds\n",
      " Calculation Rate (inactive)       = 12207.8 particles/second\n",
      " Calculation Rate (active)         = 11946.2 particles/second\n",
      "\n",
      " ============================>     RESULTS     <============================\n",
      "\n",
      " k-effective (Collision)     = 1.00135 +/- 0.00266\n",
      " k-effective (Track-length)  = 1.00235 +/- 0.00292\n",
      " k-effective (Absorption)    = 1.00742 +/- 0.00269\n",
      " Combined k-effective        = 1.00441 +/- 0.00218\n",
      " Leakage Fraction            = 0.00004 +/- 0.00002\n",
      "\n"
     ]
    }
   ],
   "source": [
    "# Run OpenMC with 2 MPI processes\n",
    "openmc.run()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Analyze Tally Data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# Instantiate a StatePoint object\n",
    "from openmc.statepoint import StatePoint\n",
    "filename = 'statepoint.{}.h5'.format(settings.batches)\n",
    "sp = StatePoint(filename)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{1: Tally\n",
       " \tID             =\t1\n",
       " \tName           =\ta really cool tally\n",
       " \tFilters        =\tCellFilter, EnergyFilter\n",
       " \tNuclides       =\tO16 O17 N14 N15 Ar36 Ar38 Ar40 C0\n",
       " \tScores         =\t['scatter', 'absorption']\n",
       " \tEstimator      =\ttracklength\n",
       " \tMultiply dens. =\tTrue}"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Inspect the StatePoint's tallies\n",
    "sp.tallies"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>cell</th>\n",
       "      <th>energy low [eV]</th>\n",
       "      <th>energy high [eV]</th>\n",
       "      <th>nuclide</th>\n",
       "      <th>score</th>\n",
       "      <th>mean</th>\n",
       "      <th>std. dev.</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>145</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>6.250000e-07</td>\n",
       "      <td>O16</td>\n",
       "      <td>scatter</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>145</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>6.250000e-07</td>\n",
       "      <td>O16</td>\n",
       "      <td>absorption</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>145</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>6.250000e-07</td>\n",
       "      <td>O17</td>\n",
       "      <td>scatter</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>145</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>6.250000e-07</td>\n",
       "      <td>O17</td>\n",
       "      <td>absorption</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>145</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>6.250000e-07</td>\n",
       "      <td>N14</td>\n",
       "      <td>scatter</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>145</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>6.250000e-07</td>\n",
       "      <td>N14</td>\n",
       "      <td>absorption</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>145</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>6.250000e-07</td>\n",
       "      <td>N15</td>\n",
       "      <td>scatter</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>145</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>6.250000e-07</td>\n",
       "      <td>N15</td>\n",
       "      <td>absorption</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>145</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>6.250000e-07</td>\n",
       "      <td>Ar36</td>\n",
       "      <td>scatter</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>145</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>6.250000e-07</td>\n",
       "      <td>Ar36</td>\n",
       "      <td>absorption</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>145</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>6.250000e-07</td>\n",
       "      <td>Ar38</td>\n",
       "      <td>scatter</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>145</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>6.250000e-07</td>\n",
       "      <td>Ar38</td>\n",
       "      <td>absorption</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>145</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>6.250000e-07</td>\n",
       "      <td>Ar40</td>\n",
       "      <td>scatter</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>145</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>6.250000e-07</td>\n",
       "      <td>Ar40</td>\n",
       "      <td>absorption</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>145</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>6.250000e-07</td>\n",
       "      <td>C0</td>\n",
       "      <td>scatter</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>145</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>6.250000e-07</td>\n",
       "      <td>C0</td>\n",
       "      <td>absorption</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>145</td>\n",
       "      <td>6.250000e-07</td>\n",
       "      <td>2.000000e+01</td>\n",
       "      <td>O16</td>\n",
       "      <td>scatter</td>\n",
       "      <td>3.883551e-07</td>\n",
       "      <td>9.504800e-09</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>145</td>\n",
       "      <td>6.250000e-07</td>\n",
       "      <td>2.000000e+01</td>\n",
       "      <td>O16</td>\n",
       "      <td>absorption</td>\n",
       "      <td>1.036318e-11</td>\n",
       "      <td>3.458754e-13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>145</td>\n",
       "      <td>6.250000e-07</td>\n",
       "      <td>2.000000e+01</td>\n",
       "      <td>O17</td>\n",
       "      <td>scatter</td>\n",
       "      <td>1.428327e-10</td>\n",
       "      <td>3.495404e-12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>145</td>\n",
       "      <td>6.250000e-07</td>\n",
       "      <td>2.000000e+01</td>\n",
       "      <td>O17</td>\n",
       "      <td>absorption</td>\n",
       "      <td>4.932669e-12</td>\n",
       "      <td>1.647897e-13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>145</td>\n",
       "      <td>6.250000e-07</td>\n",
       "      <td>2.000000e+01</td>\n",
       "      <td>N14</td>\n",
       "      <td>scatter</td>\n",
       "      <td>3.720407e-06</td>\n",
       "      <td>9.108040e-08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>145</td>\n",
       "      <td>6.250000e-07</td>\n",
       "      <td>2.000000e+01</td>\n",
       "      <td>N14</td>\n",
       "      <td>absorption</td>\n",
       "      <td>3.849441e-07</td>\n",
       "      <td>1.286033e-08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>145</td>\n",
       "      <td>6.250000e-07</td>\n",
       "      <td>2.000000e+01</td>\n",
       "      <td>N15</td>\n",
       "      <td>scatter</td>\n",
       "      <td>6.040028e-09</td>\n",
       "      <td>1.481040e-10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>145</td>\n",
       "      <td>6.250000e-07</td>\n",
       "      <td>2.000000e+01</td>\n",
       "      <td>N15</td>\n",
       "      <td>absorption</td>\n",
       "      <td>1.790637e-14</td>\n",
       "      <td>5.975234e-16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>145</td>\n",
       "      <td>6.250000e-07</td>\n",
       "      <td>2.000000e+01</td>\n",
       "      <td>Ar36</td>\n",
       "      <td>scatter</td>\n",
       "      <td>1.092466e-09</td>\n",
       "      <td>2.672008e-11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>145</td>\n",
       "      <td>6.250000e-07</td>\n",
       "      <td>2.000000e+01</td>\n",
       "      <td>Ar36</td>\n",
       "      <td>absorption</td>\n",
       "      <td>4.127303e-11</td>\n",
       "      <td>1.385564e-12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>145</td>\n",
       "      <td>6.250000e-07</td>\n",
       "      <td>2.000000e+01</td>\n",
       "      <td>Ar38</td>\n",
       "      <td>scatter</td>\n",
       "      <td>2.469434e-11</td>\n",
       "      <td>6.040052e-13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>145</td>\n",
       "      <td>6.250000e-07</td>\n",
       "      <td>2.000000e+01</td>\n",
       "      <td>Ar38</td>\n",
       "      <td>absorption</td>\n",
       "      <td>1.254291e-12</td>\n",
       "      <td>4.262034e-14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>145</td>\n",
       "      <td>6.250000e-07</td>\n",
       "      <td>2.000000e+01</td>\n",
       "      <td>Ar40</td>\n",
       "      <td>scatter</td>\n",
       "      <td>2.866552e-09</td>\n",
       "      <td>7.011203e-11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>145</td>\n",
       "      <td>6.250000e-07</td>\n",
       "      <td>2.000000e+01</td>\n",
       "      <td>Ar40</td>\n",
       "      <td>absorption</td>\n",
       "      <td>1.594757e-09</td>\n",
       "      <td>5.329713e-11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>145</td>\n",
       "      <td>6.250000e-07</td>\n",
       "      <td>2.000000e+01</td>\n",
       "      <td>C0</td>\n",
       "      <td>scatter</td>\n",
       "      <td>6.191605e-10</td>\n",
       "      <td>1.516336e-11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31</th>\n",
       "      <td>145</td>\n",
       "      <td>6.250000e-07</td>\n",
       "      <td>2.000000e+01</td>\n",
       "      <td>C0</td>\n",
       "      <td>absorption</td>\n",
       "      <td>2.711282e-13</td>\n",
       "      <td>9.057393e-15</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    cell  energy low [eV]  energy high [eV] nuclide       score     mean  \\\n",
       "0    145         0.00e+00          6.25e-07     O16     scatter 0.00e+00   \n",
       "1    145         0.00e+00          6.25e-07     O16  absorption 0.00e+00   \n",
       "2    145         0.00e+00          6.25e-07     O17     scatter 0.00e+00   \n",
       "3    145         0.00e+00          6.25e-07     O17  absorption 0.00e+00   \n",
       "4    145         0.00e+00          6.25e-07     N14     scatter 0.00e+00   \n",
       "5    145         0.00e+00          6.25e-07     N14  absorption 0.00e+00   \n",
       "6    145         0.00e+00          6.25e-07     N15     scatter 0.00e+00   \n",
       "7    145         0.00e+00          6.25e-07     N15  absorption 0.00e+00   \n",
       "8    145         0.00e+00          6.25e-07    Ar36     scatter 0.00e+00   \n",
       "9    145         0.00e+00          6.25e-07    Ar36  absorption 0.00e+00   \n",
       "10   145         0.00e+00          6.25e-07    Ar38     scatter 0.00e+00   \n",
       "11   145         0.00e+00          6.25e-07    Ar38  absorption 0.00e+00   \n",
       "12   145         0.00e+00          6.25e-07    Ar40     scatter 0.00e+00   \n",
       "13   145         0.00e+00          6.25e-07    Ar40  absorption 0.00e+00   \n",
       "14   145         0.00e+00          6.25e-07      C0     scatter 0.00e+00   \n",
       "15   145         0.00e+00          6.25e-07      C0  absorption 0.00e+00   \n",
       "16   145         6.25e-07          2.00e+01     O16     scatter 3.88e-07   \n",
       "17   145         6.25e-07          2.00e+01     O16  absorption 1.04e-11   \n",
       "18   145         6.25e-07          2.00e+01     O17     scatter 1.43e-10   \n",
       "19   145         6.25e-07          2.00e+01     O17  absorption 4.93e-12   \n",
       "20   145         6.25e-07          2.00e+01     N14     scatter 3.72e-06   \n",
       "21   145         6.25e-07          2.00e+01     N14  absorption 3.85e-07   \n",
       "22   145         6.25e-07          2.00e+01     N15     scatter 6.04e-09   \n",
       "23   145         6.25e-07          2.00e+01     N15  absorption 1.79e-14   \n",
       "24   145         6.25e-07          2.00e+01    Ar36     scatter 1.09e-09   \n",
       "25   145         6.25e-07          2.00e+01    Ar36  absorption 4.13e-11   \n",
       "26   145         6.25e-07          2.00e+01    Ar38     scatter 2.47e-11   \n",
       "27   145         6.25e-07          2.00e+01    Ar38  absorption 1.25e-12   \n",
       "28   145         6.25e-07          2.00e+01    Ar40     scatter 2.87e-09   \n",
       "29   145         6.25e-07          2.00e+01    Ar40  absorption 1.59e-09   \n",
       "30   145         6.25e-07          2.00e+01      C0     scatter 6.19e-10   \n",
       "31   145         6.25e-07          2.00e+01      C0  absorption 2.71e-13   \n",
       "\n",
       "    std. dev.  \n",
       "0    0.00e+00  \n",
       "1    0.00e+00  \n",
       "2    0.00e+00  \n",
       "3    0.00e+00  \n",
       "4    0.00e+00  \n",
       "5    0.00e+00  \n",
       "6    0.00e+00  \n",
       "7    0.00e+00  \n",
       "8    0.00e+00  \n",
       "9    0.00e+00  \n",
       "10   0.00e+00  \n",
       "11   0.00e+00  \n",
       "12   0.00e+00  \n",
       "13   0.00e+00  \n",
       "14   0.00e+00  \n",
       "15   0.00e+00  \n",
       "16   9.50e-09  \n",
       "17   3.46e-13  \n",
       "18   3.50e-12  \n",
       "19   1.65e-13  \n",
       "20   9.11e-08  \n",
       "21   1.29e-08  \n",
       "22   1.48e-10  \n",
       "23   5.98e-16  \n",
       "24   2.67e-11  \n",
       "25   1.39e-12  \n",
       "26   6.04e-13  \n",
       "27   4.26e-14  \n",
       "28   7.01e-11  \n",
       "29   5.33e-11  \n",
       "30   1.52e-11  \n",
       "31   9.06e-15  "
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Get a Pandas DataFrame of the tally data\n",
    "tally = sp.get_tally(name='a really cool tally')\n",
    "tally.get_pandas_dataframe()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "And I'll leave it up to you at this point :-)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
