Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macOS-latest]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v3
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,8 @@ examples/bioRxiv281717/figure_7_8/parameters
x86_64
arm64
aarch64
# ignoring downloaded model folders from GitHub for
# examples/LFPy-example-03.ipynb and others
examples/2488/
# examples/LFPy-example-04.ipynb and others
examples/139653/
15 changes: 13 additions & 2 deletions LFPy/templatecell.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class TemplateCell(Cell):
File with cell template definition(s)
templatename : str
Cell template-name used for this cell object
templateargs : str
templateargs : None, str, int or list of arguments
Parameters provided to template-definition
v_init : float
Initial membrane potential. Default to -65.
Expand Down Expand Up @@ -150,7 +150,18 @@ def __init__(self,
def _load_geometry(self):
"""Load the morphology-file in NEURON"""
# the python cell object we are loading the morphology into:
self.template = getattr(neuron.h, self.templatename)(self.templateargs)
# Check templateargs arguments
if self.templateargs is None:
self.template = getattr(neuron.h, self.templatename)()
elif isinstance(self.templateargs, (str, int)):
self.template = getattr(neuron.h,
self.templatename)(self.templateargs)
elif isinstance(self.templateargs, (list, tuple)):
self.template = getattr(neuron.h,
self.templatename)(*self.templateargs)
else:
msg = "templateargs must be None, int, str, list or tuple"
raise ValueError(msg)

# perform a test if the morphology is already loaded:
seccount = 0
Expand Down
2 changes: 1 addition & 1 deletion LFPy/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version = "2.3.3"
version = "2.3.4"
25 changes: 5 additions & 20 deletions examples/LFPy-example-01.ipynb

Large diffs are not rendered by default.

25 changes: 5 additions & 20 deletions examples/LFPy-example-02.ipynb

Large diffs are not rendered by default.

65 changes: 21 additions & 44 deletions examples/LFPy-example-03.ipynb

Large diffs are not rendered by default.

73 changes: 25 additions & 48 deletions examples/LFPy-example-04.ipynb

Large diffs are not rendered by default.

13 changes: 4 additions & 9 deletions examples/LFPy-example-05.ipynb

Large diffs are not rendered by default.

85 changes: 15 additions & 70 deletions examples/LFPy-example-06.ipynb

Large diffs are not rendered by default.

66 changes: 12 additions & 54 deletions examples/LFPy-example-07.ipynb

Large diffs are not rendered by default.

44 changes: 24 additions & 20 deletions examples/LFPy-example-08.ipynb

Large diffs are not rendered by default.

17 changes: 6 additions & 11 deletions examples/LFPy-example-09.ipynb

Large diffs are not rendered by default.

29 changes: 12 additions & 17 deletions examples/LFPy-example-10.ipynb

Large diffs are not rendered by default.

19 changes: 7 additions & 12 deletions examples/LFPy-example-11.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion examples/example_EPFL_neurons.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""
Test implementation using cell models of the Blue Brain Project with LFPy.
The example assumes that the complete set of cell models available from
https://bbpnmc.epfl.ch/nmc-portal/downloads is unzipped in this folder.
https://bbp.epfl.ch/nmc-portal/downloads.html is unzipped in this folder.

Execution:

Expand Down
18 changes: 3 additions & 15 deletions examples/example_MEA.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ class LFPy.RecMEAElectrode which incorporates discontinous extracellular
"""
import os
from os.path import join
from urllib.request import urlopen
import zipfile
import ssl
import LFPy
import numpy as np
import matplotlib.pyplot as plt
Expand Down Expand Up @@ -188,18 +185,9 @@ def mark_subplots(axes, letters='ABCDEFGHIJKLMNOPQRSTUVWXYZ',


# Fetch Mainen&Sejnowski 1996 model files
if not os.path.isfile(join('cells', 'cells', 'j4a.hoc')):
if not os.path.isfile(join('2488', 'cells', 'j4a.hoc')):
# get the model files:
url = '{}{}'.format('http://senselab.med.yale.edu/ModelDB/eavBinDown.asp',
'?o=2488&a=23&mime=application/zip')
u = urlopen(url, context=ssl._create_unverified_context())
localFile = open('patdemo.zip', 'wb')
localFile.write(u.read())
localFile.close()
# unzip:
myzip = zipfile.ZipFile('patdemo.zip', 'r')
myzip.extractall('.')
myzip.close()
os.system('git clone https://github.com/ModelDBRepository/2488.git')

##########################################################################
# Main script, set parameters and create cell, synapse and electrode objects
Expand All @@ -208,7 +196,7 @@ def mark_subplots(axes, letters='ABCDEFGHIJKLMNOPQRSTUVWXYZ',
# Define cell parameters
cell_parameters = {
# from Mainen & Sejnowski, J Comput Neurosci, 1996
'morphology': join('cells', 'cells', 'j4a.hoc'),
'morphology': join('2488', 'cells', 'j4a.hoc'),
'cm': 1.0, # membrane capacitance
'Ra': 150., # axial resistance
'v_init': -65., # initial crossmembrane potential
Expand Down
37 changes: 11 additions & 26 deletions examples/example_loadL5bPCmodelsEH.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
this folder from ModelDB:
http://senselab.med.yale.edu/modeldb/ShowModel.asp?model=139653

The mod-files inside /L5bPCmodelsEH/mod/ must be compiled using nrnivmodl.
The mod-files inside /139653/mod/ must be compiled using nrnivmodl.

Note that LFPy can only deal with one cell at the time, creating several
cell objects will slow everything down, but each cell *should* get the correct
Expand Down Expand Up @@ -37,44 +37,29 @@
import matplotlib.pyplot as plt
import os
import sys
if sys.version < '3':
from urllib2 import urlopen
else:
from urllib.request import urlopen
import zipfile
import ssl
from warnings import warn


# Fetch Hay et al. 2011 model files
if not os.path.isfile('L5bPCmodelsEH/morphologies/cell1.asc'):
if not os.path.isfile('139653/morphologies/cell1.asc'):
# get the model files:
url = '{}{}'.format('http://senselab.med.yale.edu/ModelDB/eavBinDown.asp',
'?o=139653&a=23&mime=application/zip')
u = urlopen(url, context=ssl._create_unverified_context())
localFile = open('L5bPCmodelsEH.zip', 'wb')
localFile.write(u.read())
localFile.close()
# unzip:
myzip = zipfile.ZipFile('L5bPCmodelsEH.zip', 'r')
myzip.extractall('.')
myzip.close()
os.system('git clone https://github.com/ModelDBRepository/139653.git')

# compile mod files every time, because of incompatibility with Mainen96 files:
if "win32" in sys.platform:
pth = "L5bPCmodelsEH/mod/"
pth = "139653/mod/"
warn("no autompile of NMODL (.mod) files on Windows."
+ "Run mknrndll from NEURON bash in the folder "
+ "L5bPCmodelsEH/mod and rerun example script")
+ "139653/mod and rerun example script")
if pth not in neuron.nrn_dll_loaded:
neuron.h.nrn_load_dll(pth + "nrnmech.dll")
neuron.nrn_dll_loaded.append(pth)
else:
os.system('''
cd L5bPCmodelsEH/mod/
cd 139653/mod/
nrnivmodl
''')
neuron.load_mechanisms('L5bPCmodelsEH/mod/')
neuron.load_mechanisms('139653/mod/')

# remove cells from previous script executions
neuron.h('forall delete_section()')
Expand All @@ -84,11 +69,11 @@
# 'templateargs'!
# Reason is LFPy looks for a default rotation .rot-file.
cellParams = {
'morphology': 'L5bPCmodelsEH/morphologies/cell1.asc',
'templatefile': ['L5bPCmodelsEH/models/L5PCbiophys3.hoc',
'L5bPCmodelsEH/models/L5PCtemplate.hoc'],
'morphology': '139653/morphologies/cell1.asc',
'templatefile': ['139653/models/L5PCbiophys3.hoc',
'139653/models/L5PCtemplate.hoc'],
'templatename': 'L5PCtemplate',
'templateargs': 'L5bPCmodelsEH/morphologies/cell1.asc',
'templateargs': '139653/morphologies/cell1.asc',
'nsegs_method': None,
'v_init': -80,
'tstart': 0,
Expand Down
31 changes: 8 additions & 23 deletions examples/example_mpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,6 @@
from LFPy.inputgenerators import get_activation_times_from_distribution
import neuron
import sys
if sys.version < '3':
from urllib2 import urlopen
else:
from urllib.request import urlopen
import zipfile
import ssl
from warnings import warn
from mpi4py import MPI

Expand All @@ -54,37 +48,27 @@
RANK = COMM.Get_rank()

# Fetch Mainen&Sejnowski 1996 model files
if not os.path.isfile(join('cells', 'cells', 'j4a.hoc')) and RANK == 0:

if not os.path.isfile(join('2488', 'cells', 'j4a.hoc')) and RANK == 0:
# get the model files:
url = '{}{}'.format('http://senselab.med.yale.edu/ModelDB/eavBinDown.asp',
'?o=2488&a=23&mime=application/zip')
u = urlopen(url, context=ssl._create_unverified_context())
localFile = open('patdemo.zip', 'w')
localFile.write(u.read())
localFile.close()
# unzip:
myzip = zipfile.ZipFile('patdemo.zip', 'r')
myzip.extractall('.')
myzip.close()
os.system('git clone https://github.com/ModelDBRepository/2488.git')

# compile mod files every time, because of incompatibility with Hay2011 files:
if "win32" in sys.platform:
pth = "cells"
pth = "2488" # path to folder
warn("no autompile of NMODL (.mod) files on Windows. "
+ "Run mknrndll from NEURON bash in the folder cells and "
+ "Run mknrndll from NEURON bash in the folder 2488 and "
+ "rerun example script")
if pth not in neuron.nrn_dll_loaded:
neuron.h.nrn_load_dll(pth + "/nrnmech.dll")
neuron.nrn_dll_loaded.append(pth)
else:
if RANK == 0:
os.system('''
cd cells
cd 2488
nrnivmodl
''')
COMM.Barrier()
neuron.load_mechanisms('cells')
neuron.load_mechanisms('2488')


# set one global seed, ensure all randomizations are set on RANK 0 in script!
Expand Down Expand Up @@ -199,7 +183,8 @@ def drawRandCellPositions(self):
return COMM.bcast(cellPositions, root=0)

def drawRandCellRotations(self):
'''draw and distribute random cell rotations for all cells in population
'''draw and distribute random cell rotations
for all cells in population
'''
if RANK == 0:
cellRotations = np.random.rand(self.POPULATION_SIZE) * np.pi * 2
Expand Down
24 changes: 4 additions & 20 deletions examples/example_mpi_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,6 @@
from matplotlib.collections import LineCollection
import os
from os.path import join
import sys
if sys.version < '3':
from urllib2 import urlopen
else:
from urllib.request import urlopen
import zipfile
import ssl
import LFPy
from mpi4py import MPI

Expand Down Expand Up @@ -67,25 +60,16 @@ def stationary_poisson(nsyn, lambd, tstart, tstop):


# Fetch Mainen&Sejnowski 1996 model files
if not os.path.isfile(join('cells', 'cells', 'j4a.hoc')) and RANK == 0:
if not os.path.isfile(join('2488', 'cells', 'j4a.hoc')) and RANK == 0:
# get the model files:
url = '{}{}'.format('http://senselab.med.yale.edu/ModelDB/eavBinDown.asp',
'?o=2488&a=23&mime=application/zip')
u = urlopen(url, context=ssl._create_unverified_context())
localFile = open('patdemo.zip', 'w')
localFile.write(u.read())
localFile.close()
# unzip:
myzip = zipfile.ZipFile('patdemo.zip', 'r')
myzip.extractall('.')
myzip.close()
os.system('git clone https://github.com/ModelDBRepository/2488.git')

# resync MPI threads
COMM.Barrier()

# Define cell parameters
cell_parameters = { # various cell parameters,
'morphology': join('cells', 'cells', 'j4a.hoc'), # Mainen&Sejnowski, 1996
'morphology': join('2488', 'cells', 'j4a.hoc'), # Mainen&Sejnowski, 1996
'cm': 1.0, # membrane capacitance
'Ra': 150, # axial resistance
'v_init': -65., # initial crossmembrane potential
Expand Down Expand Up @@ -229,7 +213,7 @@ def stationary_poisson(nsyn, lambd, tstart, tstop):
plt.axis('off')

for i_cell in range(n_cells):
cell = LFPy.Cell(join('cells', 'cells', 'j4a.hoc'),
cell = LFPy.Cell(join('2488', 'cells', 'j4a.hoc'),
nsegs_method='lambda_f',
lambda_f=5)
cell.set_rotation(z=z_rotation[i_cell], **xy_rotations)
Expand Down