Changeset 726

Show
Ignore:
Timestamp:
03/11/10 15:24:33 (2 years ago)
Author:
apdavison
Message:

Resumed implementation of the moose module. HH_cond_exp2.py example runs and gives the same results with moose as with neuron (nest is different - need to figure out why).

Location:
trunk
Files:
4 added
4 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/moose/__init__.py

    r601 r726  
    1 """Interfacing MOOSE to PyNN""" 
     1# encoding: utf-8 
     2""" 
     3MOOSE implementation of the PyNN API 
     4 
     5Authors: Subhasis Ray and Andrew Davison 
     6 
     7$Id:$ 
     8""" 
     9 
    210import moose 
    3 import Neuron 
    4 from cells import * 
    5 from pyNN import common 
     11from pyNN.moose import simulator 
     12from pyNN import common, recording 
     13common.simulator = simulator 
     14recording.simulator = simulator 
    615 
    7 def setup(timestep=0.1, min_delay=0.1, max_delay=10.0, debug=False, **extra_params): 
     16from pyNN.moose.cells import * 
     17from pyNN.moose.recording import * 
     18 
     19import logging 
     20logger = logging.getLogger("PyNN") 
     21 
     22# ============================================================================== 
     23#   Functions for simulation set-up and control 
     24# ============================================================================== 
     25 
     26def setup(timestep=0.1, min_delay=0.1, max_delay=10.0, **extra_params): 
    827    """ 
    928    Should be called at the very beginning of a script. 
     
    1130    simulator but not by others. 
    1231    """ 
    13     common.setup(timestep, min_delay, max_delay, debug, **extra_params) 
    14     ctx = moose.PyMooseBase.getContext() 
    15     ctx.setClock(0, timestep, 0) 
     32    common.setup(timestep, min_delay, max_delay, **extra_params) 
     33    simulator.state.dt = timestep 
    1634    return 0 
    1735 
    1836def end(compatible_output=True): 
    1937    """Do any necessary cleaning up before exiting.""" 
     38    for recorder in simulator.recorder_list: 
     39        recorder.write(gather=True, compatible_output=compatible_output) 
    2040    moose.PyMooseBase.endSimulation() 
    21   
    22 def create(cellclass, cellparams=None, n=1): 
    23     """ 
    24     Create n cells all of the same type. 
    25     If n > 1, return a list of cell ids/references. 
    26     If n==1, return just the single id. 
    27     """ 
    28     assert n > 0, 'n must be a positive integer' 
    29     cell_gids = [] 
    30     if isinstance(cellclass, type): 
    31         for i in range(n): 
    32                 print cellclass, cellparams 
    33                 cell_type = cellclass(cellparams) 
    34                 cell = eval("Neuron."+cell_type.moose_name)(**cell_type.parameters) 
    35                 cell_gids.append(cell.id) 
    36         cell_gids = [ID(gid) for gid in cell_gids] 
    37     elif isinstance(cellclass, str):  # celltype is not a standard cell 
    38         cellclass = eval(cellclass) 
    39         for i in range(n): 
    40                 cell = cellclass(**cellparams) 
    41                 cell_gids.append(cell.id) 
    42         cell_gids = [ID(gid) for gid in cell_gids] 
    43     else: 
    44         raise Exception("Invalid cell type") 
    45     for id in cell_gids: 
    46         id.cellclass = cellclass 
    47     if n == 1: 
    48         return cell_gids[0] 
    49     else: 
    50         return cell_gids 
    5141 
    52 def record(source, filename): 
    53         dataDir = Neutral("/data") 
    54         probe = Table(source.name, dataDir) 
    55         probe.step_mode = 3 
    56         probe.connect("inputRequest", source, "Vm") 
    57          
    5842def run(simtime): 
    5943        """Run the simulation for simtime""" 
    60         moose.step(simtime) 
     44        simulator.run(simtime) 
     45 
     46 
     47# ============================================================================== 
     48#   Functions returning information about the simulation state 
     49# ============================================================================== 
     50 
     51get_current_time = common.get_current_time 
     52get_time_step = common.get_time_step 
     53get_min_delay = common.get_min_delay 
     54get_max_delay = common.get_max_delay 
     55num_processes = common.num_processes 
     56rank = common.rank    
     57 
     58# ============================================================================== 
     59#   Low-level API for creating, connecting and recording from individual neurons 
     60# ============================================================================== 
     61 
     62create = common.create 
     63 
     64#connect = common.connect 
     65 
     66#set = common.set 
     67 
     68record = common.build_record('spikes', simulator) 
     69 
     70record_v = common.build_record('v', simulator) 
     71 
     72record_gsyn = common.build_record('gsyn', simulator) 
     73         
     74 
  • trunk/src/moose/cells.py

    r601 r726  
    1 from pyNN import common, cells 
     1import moose 
     2from pyNN import standardmodels, cells 
     3 
     4mV = 1e-3 
     5ms = 1e-3 
     6nA = 1e-9 
     7 
     8class SingleCompHH(moose.Neutral): 
     9     
     10    def __init__(self, path, GbarNa=0.0, GbarK=0.0, GLeak=0.0, Cm=1.0, 
     11                 ENa=40*mV, EK=-90*mV, VLeak=-65*mV, Voff=-63*mV, ESynE=0*mV, 
     12                 ESynI=-70*mV, tauE=2*ms, tauI=5*ms, inject=0*nA, initVm=-65*mV): 
     13        moose.Neutral.__init__(self, path) 
     14        self.comp = moose.Compartment("compartment", self) 
     15        print "compartment is at %s" % self.comp.path 
     16        print locals() 
     17        self.comp.initVm = initVm 
     18        self.comp.Rm = 1/GLeak 
     19        self.comp.Cm = Cm 
     20        self.comp.Em = VLeak 
     21        self.comp.inject = inject 
     22        self.na = moose.HHChannel("na", self.comp) 
     23        self.na.Ek = ENa 
     24        self.na.Gbar = GbarNa 
     25        self.na.Xpower = 3 
     26        self.na.Ypower = 1 
     27        self.na.setupAlpha("X", 3.2e5 * (13*mV+Voff), -3.2e5, -1, -(13*mV+Voff), -4*mV, # alpha 
     28                               -2.8e5 * (40*mV+Voff),  2.8e5, -1, -(40*mV+Voff), 5*mV)  # beta 
     29        self.na.setupAlpha("Y", 128,                   0,      0, -(17*mV+Voff), 18*mV, # alpha 
     30                                4.0e3,                 0,      1, -(40*mV+Voff), -5*mV) # beta 
     31 
     32        self.k = moose.HHChannel("k", self.comp) 
     33        self.k.Ek = EK 
     34        self.k.Gbar = GbarK 
     35        self.k.Xpower = 4 
     36        self.k.setupAlpha("X", 3.2e4 * (15*mV+Voff), -3.2e4, -1, -(15*mV+Voff), -5*mV, 
     37                               500,                  0,       0, -(10*mV+Voff),  40*mV) 
     38 
     39        #self.synE = moose.SynChan("excitatory", self.comp) 
     40        #self.synE.Ek = ESynE 
     41        #self.synE.tau1 = 1e-6 
     42        #self.synE.tau2 = tauE 
     43        #self.synE.Gbar = 1e-9 
     44        #self.synI = moose.SynChan("inhibitory", self.comp) 
     45        #self.synI.Ek = ESynI 
     46        #self.synI.tau1 = 1e-6 
     47        #self.synI.tau2 = tauI 
     48        #self.synI.Gbar = 1e-9 
     49     
     50        #self.comp.connect("channel", self.synE, "channel") 
     51        #self.comp.connect("channel", self.synI, "channel") 
     52        self.comp.connect("channel", self.na, "channel") 
     53        self.comp.connect("channel", self.k , "channel") 
     54         
     55        self.comp.useClock(0) 
     56        self.comp.useClock(1, "init") 
     57 
     58    def record_v(self): 
     59        self.vmTable = moose.Table("Vm", self) 
     60        self.vmTable.stepMode = 3 
     61        self.vmTable.connect("inputRequest", self.comp, "Vm") 
     62        self.vmTable.useClock(2) 
     63        print "vmTable is at %s" % self.vmTable.path 
     64        #moose.PyMooseBase.getContext().useClock(0, self.comp.path+"/##") 
     65 
     66#a = SingleCompHH("/comp", 1e-9, 1e-9, 1e-9, 1e-12, -0.06, 0.08, -0.06, 0.001, 0.05, -0.05, 1e-2, 2e-2, 1e-9, -0.06) 
     67#print "Successfully setup SingleCompHH" 
     68 
     69 
    270 
    371class HH_cond_exp(cells.HH_cond_exp): 
    472    """Single compartment cell with an Na channel and a K channel""" 
    5     translations = common.build_translations( 
     73    translations = standardmodels.build_translations( 
    674        ('gbar_Na',    'GbarNa', 1e-9),    
    775        ('gbar_K',     'GbarK', 1e-9),     
     
    1179        ('e_rev_Na',   'ENa', 1e-3), 
    1280        ('e_rev_K',    'EK', 1e-3),  
    13         ('e_rev_leak', 'Vleak', 1e-3), 
     81        ('e_rev_leak', 'VLeak', 1e-3), 
    1482        ('e_rev_E',    'ESynE', 1e-3), 
    1583        ('e_rev_I',    'ESynI', 1e-3), 
     
    1987        ('v_init',     'initVm', 1e-3), 
    2088    ) 
    21     moose_name = "SingleCompHH" 
     89    model = SingleCompHH 
    2290 
    2391 
  • trunk/src/neuron/__init__.py

    r719 r726  
    5959        simulator.state.cvode.active(int(extra_params['use_cvode'])) 
    6060        if extra_params.has_key('rtol'): 
    61             simulator.state.cvode.rtol(float(extra_params['rtol'])) 
     61            simulator.state.cvode.rtol(float(extra_params['rtol'])) 
    6262        if extra_params.has_key('atol'): 
    6363            simulator.state.cvode.atol(float(extra_params['atol'])) 
  • trunk/src/neuron/simulator.py

    r713 r726  
    22""" 
    33Implementation of the "low-level" functionality used by the common 
    4 implementation of the API. 
     4implementation of the API, for the NEURON simulator. 
    55 
    66Functions and classes useable by the common implementation: