PyGENESIS

Navigation

Tutorial

Tutorial 1
 
In this tutorial, I show you building a Hodgkin-Huxley point neuron in PyGENESIS.
 
Let's start by creating a leaky soma with no channel currents.

soma = Segment(Rm = 3.33333, Cm = 1, ELEAK = 10.6)

Then you can introduce some custom channel currents into it.

soma.addChannel('k')

Specification of the channel currents are done as below.

na = Channel(G_MAX = 120, Erev = 120)
na.addGate('m', 3)
na.addGate('h', 1)
 
k = Channel(G_MAX = 36, Erev = -12)
k.addGate('n', 4)
 
Gates are usually described in terms of alpha and beta functions. In PyGENESIS, you specify alpha and beta functions by filling the five slots(A,B,C,D,F) of the following equation,

    (alpha, beta) = (A + B * Vm)/(C + exp((Vm + D) / F))
 
This is the convention adopted from setupalpha function of GENESIS 2.

from pygenesis import *
 
n = Gate(alpha = (0.1, -0.01, -1, -10, -10), beta = (0.125, 0, 0, 0, 0, 80))
m = Gate(alpha = (2.5, -0.1, -1, -25, -10),  beta = (4, 0, 0, 0, 18))
h = Gate(alpha = (0.07, 0, 0, 0, 20),        beta = (1, 0, 1, -30, -10))

 
Tutorial 2
 
I explain here a way to study the internals of PyGENESIS objects.
 
An equation system a class represents is stored in 'template_str' attribute. Equation and variable substitutions take place following this template string. The evolution of the equation system following substitutions can be traced through with 'equation_str' attribute.

print n.equation_str

A function's behavior can be better understood with a plain plot over a given input values. Below is such a visualization of the alpha, beta and differential function of gate n.

alpha_f = h.function('alpha',    Vm = x)
beta_f  = h.function('beta',     Vm = x)
gate_d  = h.function('dGate/dt', Vm = x, Gate = 0)
 
import pylab
 
x = pylab.arange(-40, 120, 0.01)
pylab.figure(1)
pylab.subplot(511); pylab.plot(x, alpha_f)
pylab.subplot(512); pylab.plot(x, beta_f)
pylab.subplot(513); pylab.plot(x, gate_d)
 
With simple math, you can turn alpha and beta functions into noo and tau functions of the gate.

pylab.subplot(515); pylab.plot(x, 1/(alpha_f + beta_f))

Tutorial 3
 
You will learn here a way to plot the behavior of a neuron over a given time range.
 
record_obj = System(soma)
record = record_obj.run(soma = 0, n = 0.31838, m = 0.05322, h = 0.59450)
pylab.plot(record['Vm'])
 
The codes above will give you a resting neuron with a brief fluctuation in membrane potential at the start because of imperfect precision in initializing values.
 
I_injection = pylab.zeros(10000)
I_injection[2000:2050] = 500
record_obj.setProtocol(I_inject = I_injection)
record = record_obj.run(soma = 0, n = 0.3, m = 0.02, h = 0.55)
pylab.plot(record)
 
The setProtocol method configures the equations of the system. I am simulating a current clamp experiment with the above script.


 
Tutorial 4
 
A direct and intuitive interface to GENESIS is a main goal of this project.
 
genesis = Genesis('standalone')
genesis.addModel('soma')
genesis.run()
 
The method addModel() creates a dict containing arguments necessary to generate GENESIS 3 scripts in NDF file format. The dict structure actually is meant for a more direct YAML interface to GENESIS 3 which will be available soon.
 
The method run() converts the above dict into an NDF string and saves it into the file specified at the object initialization - 'standalone.ndf'. This method is supposed to more directly 'run' this model on GENESIS 3 on fly, but this feature is not yet available by present.