Visualizing Using Python Commands

The following tutorial assumes you are familiar with visualizing using the GUI.

Before starting:

  1. Load Blender with the BlenderNEURON add-on (NEURON tab should be visible in Blender left panel)
  2. Load your model in NEURON
  3. Load BlenderNEURON in NEURON by running from blenderneuron.quick import bn
  4. Test the connectivity between NEURON and Blender with bn.is_blender_ready() (Should say “True”)

See Installation for how to install the python library and the Blender addon.

Visualizing Morphology

Follow these steps to visualize the cell morphology of a NEURON model:

  1. Once your model is loaded, run bn.to_blender()
  2. A moment later, your model should appear in Blender
  3. Navigate around the Blender scene to inspect the model. If you’re not familiar with Blender, these tutorials will give an overview of basic scene navigation.

By default, BlenderNEURON will export the morphology of all cells (sections) in the model. It will use NEURON’s x/y/z3d() and diam3d() values to build the 3D meshes in Blender.

In within Blender, 1 cm is set to correspond to 1 micron in NEURON.

If you add or make changes to your model’s sections/cells, run bn.refresh() before running bn.to_blender() to ensure that the changes are included in the export.

For a more detailed control of the export process, see the client library API

A complete example of exporting a model to Blender:

from blenderneuron.quick import bn # import the BlenderNEURON library

assert bn.is_blender_ready()       # check if communication with Blender can be established

#bn.refresh()                      # uncomment this if there has been a model change since last run

bn.to_blender()                    # send section morphology data to Blender

Visualizing Activity

Follow these steps to visualize the morphology and simulated activity of a NEURON model:

  1. Once your model is loaded, run bn.prepare_for_collection(). This will add a handler to gather section voltage values during the simulation.
  2. Run your simulation (e.g. h.run())
  3. Once the simulation is finished, run bn.to_blender()
  4. A moment later, your model should appear in Blender
  5. Use the buttons under the bottom timeline in Blender to re-play the simulation. If your cells emit action potentials (Vm > -20mV), you should be able to see them as glowing compartments. By default, 1 frame in Blender corresponds to 0.5ms in NEURON.
  6. You can scrub the timeline to re-play any part of the simulation and use the left/right arrow keys to step through the frames.
_images/timeline.JPG

A complete example of exporting a model with activity to Blender:

from blenderneuron.quick import bn # import the BlenderNEURON library

assert bn.is_blender_ready()       # check if communication with Blender can be established

bn.prepare_for_collection()        # adds a NEURON handler to collect section activity data

#bn.refresh()                      # uncomment this if there has been a model change since last run

h.run()                            # run the simulation

bn.to_blender()                    # send section morphology and activity data to Blender