EPFL.hoc import

203 views
Skip to first unread message

Michael

unread,
Sep 16, 2021, 12:18:47 PM9/16/21
to NetPyNE Q&A forum
I'm trying to import in my Netpyne model neuron from EPFL .hoc/.nml
https://bbp.epfl.ch/nmc-portal/downloads.html
Are there already available means to do that together with morphology, ions, mechanisms etc?
 
If not, I am trying to write my own simple converter from .hoc to .json and then use
netParams.loadCellParamsRule(label='Erule', fileName='test.json')
netParams.cellParams['Erule']['conds'] = {'cellType': ['E']}
 
Would it support all .hoc parameters needed for simulation? I see there are some equations in mechanisms and not sure .json would support such parameters

Joe Graham

unread,
Sep 16, 2021, 2:46:11 PM9/16/21
to NetPyNE Q&A forum
Hello,

You should be easily able to import cell models from .hoc, .json, and .py files.  Please see here for details and examples: http://netpyne.org/advanced.html#importing-externally-defined-cell-models

If your model has mechanisms defined in a .mod file, you will need to compile them in the directory where you are running your NetPyNE simulations.

Please give it a try and let us know if you have any problems.

Best wishes,
Joe

Michael

unread,
Sep 17, 2021, 1:06:22 PM9/17/21
to NetPyNE Q&A forum
Good Day! Thank you for your answer. I am trying to launch it with this code

from netpyne import specs, sim, conversion
netParams = specs.NetParams()  # object of class NetParams to store the network parameters
cellRule = netParams.importCellParams(
        label='PYR_HH3D_hoc',
        conds={'cellType': 'PYR', 'cellModel': 'HH3D'},
        fileName='template.hoc',
        cellName='bAC217_L4_BP_d04c4872bd',
        importSynMechs=True)


I still get errors

/nrml_3d/L4_BP_bAC217_1$ python pynml.py 
NEURON: NaTs2_t is not a MECHANISM
 in biophysics.hoc near line 50
  insert NaTs2_t
                ^
        xopen("biophysics.hoc")
      execute1("{xopen("bi...")
    load_file("biophysics.hoc")
  xopen("template.hoc")
and others
NEURON: ProbGABAAB_EMS is not a template
 in synapses.hoc near line 274
             section.sec synapse = new ProbGABAAB_EMS(seg_x)
                                                           ^
        xopen("synapses.hoc")
      execute1("{xopen("sy...")
    load_file("synapses/s...")
  xopen("template.hoc")
and others
NEURON: init not enough arguments
 near line 0
 ^
        bAC217_L4_BP_d04c4872bd[0].init()
Traceback (most recent call last):
  File "pynml.py", line 40, in <module>
    importSynMechs=True)
  File "/home/ubuntu/.local/lib/python2.7/site-packages/netpyne/specs/netParams.py", line 401, in importCellParams
    secs, secLists, synMechs, globs = conversion.importCell(fileName, cellName, cellArgs, cellInstance)
  File "/home/ubuntu/.local/lib/python2.7/site-packages/netpyne/conversion/neuronPyHoc.py", line 280, in importCell
    cell = getattr(h, cellName)(**cellArgs)  # create cell using template, passing dict with args
RuntimeError: hoc error







Even after commenting all problem strings. Which I believe damaged synapses data



/nrml_3d/L4_BP_bAC217_1$ python pynml.py 
NEURON: NaTs2_t is not a MECHANISM
 in biophysics.hoc near line 50
  insert NaTs2_t
                ^
        xopen("biophysics.hoc")
      execute1("{xopen("bi...")
    load_file("biophysics.hoc")
  xopen("template.hoc")
and others
NEURON: init not enough arguments
 near line 0
 ^
        bAC217_L4_BP_d04c4872bd[0].init()
Traceback (most recent call last):
  File "pynml.py", line 40, in <module>
    importSynMechs=True)
  File "/home/ubuntu/.local/lib/python2.7/site-packages/netpyne/specs/netParams.py", line 401, in importCellParams
    secs, secLists, synMechs, globs = conversion.importCell(fileName, cellName, cellArgs, cellInstance)
  File "/home/ubuntu/.local/lib/python2.7/site-packages/netpyne/conversion/neuronPyHoc.py", line 280, in importCell
    cell = getattr(h, cellName)(**cellArgs)  # create cell using template, passing dict with args
RuntimeError: hoc error

Message has been deleted

Michael

unread,
Sep 18, 2021, 7:25:01 AM9/18/21
to NetPyNE Q&A forum
still error


/nrml_3d/L4_BP_bAC217_1$ nrnivmodl ./mechanisms
..
Successfully created x86_64/special

/nrml_3d/L4_BP_bAC217_1$ python pynml.py 
NEURON: init not enough arguments
 near line 0
 ^
        bAC217_L4_BP_d04c4872bd[0].init()
Traceback (most recent call last):
  File "pynml.py", line 40, in <module>
    importSynMechs=True)
  File "/home/ubuntu/.local/lib/python2.7/site-packages/netpyne/specs/netParams.py", line 401, in importCellParams
    secs, secLists, synMechs, globs = conversion.importCell(fileName, cellName, cellArgs, cellInstance)
  File "/home/ubuntu/.local/lib/python2.7/site-packages/netpyne/conversion/neuronPyHoc.py", line 280, in importCell
    cell = getattr(h, cellName)(**cellArgs)  # create cell using template, passing dict with args
RuntimeError: hoc error


/nrml_3d/L4_BP_bAC217_1$ ./run_hoc.sh
..successfully loads gui
/nrml_3d/L4_BP_bAC217_1$ python pynml.py 


absolutely same error

Joe Graham

unread,
Sep 21, 2021, 11:27:56 AM9/21/21
to NetPyNE Q&A forum
Whenever you get an error message that includes "NEURON: <mechName> is not a MECHANISM", that is typically going to mean that you either forgot to compile your mod files or a mod file didn't compile correctly...

One big problem I see in your error messages is that you're using Python 2.  This has been deprecated since January 2020, and we no longer actively support Python 2.  Please upgrade to Python 3 and see if you still get these errors (after compiling the mod files).

If you still get these errors with Python 3, it would be easiest if you could provide a link directly to the files you are using and your NetPyNE code (a GitHub repo is ideal).

Best wishes,
Joe

Michael

unread,
Sep 26, 2021, 2:42:02 PM9/26/21
to NetPyNE Q&A forum
error was here template.hoc. strangely it worked with nrngui
proc init() { local synapses_enabled
    ///synapses_enabled = $1

MOD files were recompiled with nrnivmodl

now it loads and netParams.save('wow.json') writes the data OK. However 3D plot doesn't show this neuron. and netParams.popParams['PYR'] = {'cellType': 'PYR', 'numCells': 5, } also gives some error



my GitHub


log so far is. probably some synapses refer to invalid mechanisms. however their nrngui example worked ok. investigating. probably commenting out invalid synapses will solve the problem and make model more robust

Added inhibitory synapse 39 originating from cell 149929 of m-type L6_LBC on basal section 5(0.446000) and dep 370.000000
Added inhibitory synapse 40 originating from cell 149929 of m-type L6_LBC on basal section 5(0.457000) and dep 1076.000000
 Could not create 
Saving netParams to wow.json ... 

Start time:  2021-09-26 21:13:44.886235

Creating network of 2 cell populations on 1 hosts...
ERROR: Some mechanisms and/or ions were not inserted (for details run with cfg.verbose=True). Make sure the required mod files are compiled.
  Number of cells on node 0: 6 
  Done; cell creation time = 0.13 s.
Making connections...
  Number of connections on node 0: 0 
  Done; cell connection time = 0.00 s.
Adding stims...
  Number of stims on node 0: 1 
  Done; cell stims creation time = 0.00 s.
Recording 1 traces of 1 types on node 0
NEURON: Arg out of range in user function
 near line 0
 ko0_k_ion = 2.5
                ^
        PtrVector(0)
Traceback (most recent call last):
  File "pynml2.py", line 97, in <module>
    sim.createSimulateAnalyze(netParams = netParams, simConfig = simConfig)    
  File "/home/ubuntu/.local/lib/python3.6/site-packages/netpyne/sim/wrappers.py", line 202, in createSimulateAnalyze
    (pops, cells, conns, stims, rxd, simData) = sim.create(netParams, simConfig, output=True)
  File "/home/ubuntu/.local/lib/python3.6/site-packages/netpyne/sim/wrappers.py", line 54, in create
    simData = sim.setupRecording()             # setup variables to record for each cell (spikes, V traces, etc)
  File "/home/ubuntu/.local/lib/python3.6/site-packages/netpyne/sim/setup.py", line 434, in setupRecording
    setupRecordLFP()
  File "/home/ubuntu/.local/lib/python3.6/site-packages/netpyne/sim/setup.py", line 327, in setupRecordLFP
    cell.imembPtr = h.PtrVector(nseg)  # pointer vector
RuntimeError: hoc error

Michael

unread,
Oct 6, 2021, 3:52:03 PM10/6/21
to NetPyNE Q&A forum
Thanks! Now it works



Also while plotting there was a little bug in

analysis/lfp.py 

                     for j in range(i,i+nseg):  del trSegs[j]

replaced:

                     for j in range(i,i+nseg): 
                            if (i+nseg < len(trSegs)-1) : del trSegs[j]




just in case someone needs working .py code for EPFL example:

from netpyne import specs, sim, conversion

# Network parameters
netParams = specs.NetParams()  # object of class NetParams to store the network parameters
cellRule = netParams.importCellParams(
        label='PYR_HH3D_hoc',
        conds={'cellType': 'PYR', 'cellModel': 'HH3D'},
        fileName='createsimulation.hoc',
        cellName='bAC217_L4_BP_d04c4872bd',
        importSynMechs=True)

## Population parameters

netParams.popParams['PYR'] = {'cellType': 'PYR', 'numCells': 5, 'yRange': [700,800]}
netParams.cellParams['PYR_HH3D_hoc']['conds'] = {'cellType': ['PYR']}

## Synaptic mechanism parameters
netParams.synMechParams['exc'] = {'mod': 'Exp2Syn', 'tau1': 0.8, 'tau2': 5.3, 'e': 0}  # NMDA synaptic mechanism

# Stimulation parameters
netParams.stimSourceParams['bkg'] = {'type': 'NetStim', 'rate': 50, 'noise': 0.0}
netParams.stimTargetParams['bkg->all'] = {'source': 'bkg', 'conds': {'cellType': ['PYR']}, 'weight': 10.0, 'sec': 'soma', 'delay': 15, 'synMech': 'exc'}

# Simulation options
simConfig = specs.SimConfig()        # object of class SimConfig to store simulation configuration
simConfig.duration = 0.05*1e3           # Duration of the simulation, in ms
simConfig.dt = 0.1                # Internal integration timestep to use
simConfig.verbose = False            # Show detailed messages
simConfig.recordTraces = {'V_soma':{'sec':'soma','loc':0.5,'var':'v'}}
simConfig.recordStep = 1             # Step size in ms to save data (eg. V traces, LFP, etc)
simConfig.filename = 'cell_lfp'  # Set file output name



simConfig.recordLFP = [[x, y, 35] for y in range(280, 1000, 150) for x in [30, 90]]

simConfig.analysis['plotTraces'] = {'include': [('E',0)], 'oneFigPer':'cell', 'overlay': True, 'figSize': (5,3),'saveFig': True}      # Plot recorded traces for this list of cells
simConfig.analysis['plotLFP'] = {'includeAxon': False, 'plots': ['timeSeries',  'locations'], 'figSize': (5,9), 'saveFig': True}
simConfig.analysis['getCSD'] = {'spacing_um': 150, 'vaknin': True}
#simConfig.analysis['plotCSD'] = {'timeRange': [10,45],'saveFig': True}
#sim.analysis.getCSD(spacing_um= 150, vaknin= True)
#simConfig.analysis['plotCSD'] = {'saveFig': True}


# Create network and run simulation
sim.createSimulateAnalyze(netParams = netParams, simConfig = simConfig)    
sim.analysis.plotCSD()

# check model output
sim.checkOutput('cell_lfp')
Reply all
Reply to author
Forward
0 new messages