mcdougallab / matlabneuroninterface

Interface for connecting NEURON and MATLAB
BSD 3-Clause "New" or "Revised" License
4 stars 1 forks source link

NEURON Toolbox for MATLAB

View NEURON toolbox for MATLAB on File Exchange

:warning: This toolbox has specific requirements depending on operating system

  • Windows: Matlab R2022a or higher, MinGW compiler, and Administrator rights
  • Linux: Matlab R2023a or higher and GCC compiler
  • Mac: [Under Development] Matlab R2023a or higher, Intel Macs only and Clang compiler

For the compiler used, the version should preferably match the exact version used to compile NEURON, as using a newer or older version could have different symbol name-mangling.

The NEURON Toolbox provides a MATLAB API to NEURON, using the MATLAB provided clibgen and clib packages to connect MATLAB and NEURON.

The NEURON simulation environment is used in laboratories and classrooms around the world for building and using computational models of neurons and networks of neurons.

About this toolbox:

MATLAB is a registered trademark of The MathWorks, Inc.

For more detailed technical information about e.g. code structure, see doc/DEV_README.md.

Usage

Setup

Before using the toolbox for the first time, go through the first time only steps. On Windows, these steps need to be run from a Matlab session with Administrator rights.

Linux and Mac: To be able to use the toolbox, Matlab always needs to be started from an environment with specific environment variables, see first time only for details. Also, output printed from within NEURON itself will show in the shell from which Matlab is started, instead of the Matlab command window.

In each Matlab session where you want to use the toolbox, run the script setup.m. Alternatively, add a call to this setup.m in your startup.m file.

Example scripts

A comprehensive example live script, encompassing the smaller examples and providing additional explanation, can be found at examples/example_livescript.mlx.

Smaller example scripts are available at:

example_acpot should result in:

Action potential

Basic API usage

The main Neuron class can be found at neuron.Session. A (singleton) neuron.Session is returned upon calling the neuron.launch() function.

n = neuron.launch();

Now all top-level variables, functions and classes can be accessed using this object. The available variables, functions and classes, as well as their Neuron types can be displayed with:

n.list_functions();

Top-level variables, functions and objects can be called directly. E.g.:

disp(n.t);                  % Display the time
n.fadvance();               % Advance by one timestep
v = n.Vector();             % Create a Vector object

If you create an object like a Vector, you can see a list of its properties and methods with:

v.list_methods();

Testing

Run the tests with:

runtests +tests

Differences with Python NEURON interface

A non-exhaustive list:

First time only

Here the steps are given that need to be done only once to be able to use the toolbox.

  1. Make sure NEURON is installed (see http://neuron.yale.edu/).
  2. Linux and Mac: start Matlab from a bash shell with the correct PATH, HOC_LIBRARY_PATH and on Linux LD_LIBRARY_PATH, on Mac DYLD_LIBRARY_PATH. Matlab always needs to be started from such a shell, not just the first time only.
    • Get the directory where libnrniv is installed, within the NEURON installation folder
    • Get the directory where this toolbox is installed
    • Determine the value of matlabroot (https://nl.mathworks.com/help/matlab/ref/matlabroot.html)
    • Use these values to set the HOC_LIBRARY_PATH and LD_LIBRARY_PATH / DYLD_LIBRARY_PATH. Example shell scripts are available for Linux and Mac. Within these scripts, replace <..matlabroot..>, <..neuron-directory..> and <..matlabneuroninterface..> with the correct directory paths.
    • Depending on how Neuron was installed, it may be that also the PATH variable needs to be updated. See item 6 'Check it works'.
  3. Make sure to setup your MEX C++ compiler; for more information about this, run mex -setup cpp in MATLAB.
    • Windows: MinGW-w64
    • Linux: gcc
    • Mac: clang
  4. Update neuron_lib_directory in +utils/Paths.m if needed.
  5. Run the MATLAB scripts in the following order:
    • setup
      • This script needs to be run every time a new MATLAB session is started
      • It adds the appropriate directories to your path
    • utils.build_interface
      • This script needs to be run once to generate the library interface, and only needs to be re-run if the interface changes (for example when using a newer Neuron version)
      • It builds the library interface (neuron/neuronInterface.*)
      • Please note: on Windows you need administrator rights to run build_interface
  6. Check it works:
    • With the previous steps completed, run the matlab scripts example_run and example_acpot to check that the matlabneuroninterface works.
    • Linux and Mac, additionally:
      • Run example_loadfile to check that the HOC_LIBRARY_PATH has been set correctly.
      • Run example_mod to check that the PATH is correct. If this example fails, update the PATH per the instructions in the example startup script.