copying to personal repo

This commit is contained in:
Alan
2022-06-19 13:45:53 -05:00
commit bf2ffa7315
287 changed files with 54032 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:770319a9229c66e4796757854b0d1e341f5d376abf0284385360788c41c6d20b
size 11836

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:83554699cefe547a22eb959c83cf9a86d62383d858a1b8d78716eae16b382e43
size 6110

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:c812143a8582d423c7fababd2060bbbaa064b5b767f576cd117685af207c944e
size 11421

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:42d5eed880a498157400a9fdc442341e7e32c1ef1db8d398ac016e27fcbb6286
size 42555

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:6176f9cbf15f5f81d36a7cf64e0d9a72e0187a0d647642b838f72c0373a3349e
size 8867

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:e62835df05a9f859bbae3d48639bdb4456ca91a7ce62405f618e692494d5c92c
size 10586

View File

@@ -0,0 +1,190 @@
# -*- encoding: utf-8 -*-
from __future__ import print_function
import sys
import numpy as np
import pyqtgraph as pg
import neuron
import cnmodel
import cnmodel.cells as cells
from cnmodel.protocols import SynapseTest
from cnmodel.util import random_seed, reset
from cnmodel import data
"""
Check that sgc PSDs have correct AMPA and NMDA peak conductances / CV.
"""
def test_sgc_bushy_psd(plot=False):
sgc_psd_test(cells.Bushy, seed=23572385, tstop=4.0, plot=plot)
def test_sgc_tstellate_psd(plot=False):
sgc_psd_test(cells.TStellate, seed=34754398, plot=plot)
def test_sgc_dstellate_psd(plot=False):
sgc_psd_test(cells.DStellate, seed=54743998, plot=plot, n_syn=50)
def test_sgc_octopus_psd(plot=False):
sgc_psd_test(cells.Octopus, seed=54743998, plot=plot, n_syn=50)
def sgc_psd_test(cell_class, seed, plot=False, tstop=5.0, n_syn=20):
"""
Tests a multisite synapse from the SGC to a target cell.
The values returned from an actual set of runs of the synapse are compared
to the expected values in the synapses.py table. This is needed because
the maximal open probability of the receptor models is not 1, so the maximal
conductance per receptor needs to be adjusted empirically. If the measured current
does not match the expected current, then we print a message with the expected value,
and fail with an assert statment in the test.
The measurement itself is made in measure_gmax().
Parameters
----------
cell_class : an instance of the cell class
seed : int
random number seed for the call
plot : boolean (default False)
plot request, passed to measure_gmax
tstop : float (default 5.0 ms)
duration of run for measurement of gmax. Needs to be long enough to find the
maximum of the EPSC/IPSC.
n_syn : int (default 20)
number of synapses to instantiate for testing (to get an average value)
"""
celltyp = cell_class.__name__.lower()
random_seed.set_seed(seed)
reset(
raiseError=False
) # avoid failure because we cannot release NEURON objects completely.
tsc = cell_class.create(ttx=True)
(ampa_gmax, nmda_gmax, epsc_cv) = measure_gmax(
tsc, n_syn=n_syn, tstop=tstop, plot=plot
)
exp_ampa_gmax = data.get(
"sgc_synapse", species="mouse", post_type=celltyp, field="AMPA_gmax"
)[0]
exp_nmda_gmax = data.get(
"sgc_synapse", species="mouse", post_type=celltyp, field="NMDA_gmax"
)[0]
exp_epsc_cv = data.get(
"sgc_synapse", species="mouse", post_type=celltyp, field="EPSC_cv"
)
ampa_correct = np.allclose(exp_ampa_gmax, ampa_gmax)
if not ampa_correct:
AMPAR_gmax = data.get(
"sgc_synapse", species="mouse", post_type=celltyp, field="AMPAR_gmax"
)
ratio = exp_ampa_gmax / ampa_gmax
print(
"AMPA Receptor conductance in model should be %.16f (table is %.16f)"
% (AMPAR_gmax * ratio, AMPAR_gmax)
)
nmda_correct = np.allclose(exp_nmda_gmax, nmda_gmax)
if not nmda_correct:
NMDAR_gmax = data.get(
"sgc_synapse", species="mouse", post_type=celltyp, field="NMDAR_gmax"
)
ratio = exp_nmda_gmax / nmda_gmax
print("ratio: ", ratio, exp_nmda_gmax, nmda_gmax)
print(
"NMDA Receptor conductance in model should be %.16f (table is %.16f)"
% (NMDAR_gmax * ratio, NMDAR_gmax)
)
cv_correct = abs(exp_epsc_cv / epsc_cv - 1.0) < 0.1
print("cv_correct: ", cv_correct)
if not cv_correct:
ratio = exp_epsc_cv / epsc_cv
print(
"CV Receptor in synapses.py model should be %.6f (measured = %.6f; table = %.6f)"
% (epsc_cv * ratio, epsc_cv, exp_epsc_cv)
)
print((abs(exp_epsc_cv / (epsc_cv * ratio) - 1.0) < 0.1))
assert cv_correct
assert ampa_correct and nmda_correct
def measure_gmax(cell, n_syn=20, tstop=5.0, plot=False):
sgc = cells.SGC.create()
prot = SynapseTest()
# Connect 20 synapses and stimulate once each
# Temp is 33 C and vm=+40 to match Cao & Oertel 2010
prot.run(
sgc.soma,
cell.soma,
n_synapses=n_syn,
temp=33.0,
dt=0.025,
vclamp=40.0,
tstop=tstop,
stim_params={"NP": 1, "delay": 0.1},
)
# For each synapse:
# * Add up ampa and nmda conductances across all sites
# (although SGC-TS synapses currently have only 1 site)
# * Keep track of the maximum ampa and nmda conductance
if plot:
global plt
plt = pg.plot()
ampa_gmax = []
nmda_gmax = []
epsc_gmax = []
for syn in prot.synapses:
ampa = np.zeros_like(syn.psd.get_vector("ampa", "g"))
nmda = ampa.copy()
ampa_po = ampa.copy()
for i in range(syn.psd.n_psd):
ampa += (
syn.psd.get_vector("ampa", "g", i) * 1e-3
) # convert pS from mechanism to nS
nmda += syn.psd.get_vector("nmda", "g", i) * 1e-3
if nmda[-1] - nmda[-2] > 0.001:
raise Exception("Did not reach nmda gmax; need longer run.")
amax = ampa.max()
ampa_gmax.append(amax)
nmda_gmax.append(nmda.max())
epsc_gmax.append((ampa + nmda).max())
tb = np.linspace(0.0, len(ampa) * prot.dt, len(ampa))
if plot:
plt.plot(tb, ampa, pen="g")
plt.plot(tb, nmda, pen="y")
return (
np.mean(ampa_gmax),
np.mean(nmda_gmax),
np.std(epsc_gmax) / np.mean(epsc_gmax),
)
if __name__ == "__main__":
if len(sys.argv[0]) > 1:
testcell = sys.argv[1]
if testcell not in ["bushy", "tstellate", "dstellate", "octopus", "all"]:
print("PSD test for cell type %s is not yet supported." % testcell)
exit(1)
else:
if testcell in ["bushy"]:
test_sgc_bushy_psd(plot=True)
if testcell in ["tstellate"]:
test_sgc_tstellate_psd(plot=True)
if testcell in ["dstellate"]:
test_sgc_dstellate_psd(plot=True)
if testcell in ["octopus"]:
test_sgc_octopus_psd(plot=True)
if testcell in ["all"]:
test_sgc_bushy_psd(plot=True)
test_sgc_tstellate_psd(plot=True)
test_sgc_dstellate_psd(plot=True)
test_sgc_octopus(plot=True)
# pg.show()
if sys.flags.interactive == 0:
pg.QtGui.QApplication.exec_()

View File

@@ -0,0 +1,119 @@
"""
Create presynaptic and postsynaptic neurons, automatically connect them with
a synapse, stimulate the presynaptic cell, and analyze the resulting PSCs
in the postsynaptic cell.
"""
import faulthandler
faulthandler.enable()
import os, pickle, pprint
import numpy as np
import neuron
import cnmodel
import cnmodel.cells as cells
from cnmodel.util import UserTester
from cnmodel.protocols import SynapseTest
from cnmodel.util import reset
#
# Synapse tests
#
def test_sgc_bushy():
SynapseTester("sgc", "bushy")
def test_sgc_tstellate():
SynapseTester("sgc", "tstellate")
def test_sgc_tstellate2(): # again to test RNG stability
SynapseTester("sgc", "tstellate")
def test_sgc_dstellate():
SynapseTester("sgc", "dstellate")
def test_dstellate_bushy():
SynapseTester("dstellate", "bushy")
def test_dstellate_tstellate():
SynapseTester("dstellate", "tstellate")
def test_dstellate_dstellate():
SynapseTester("dstellate", "dstellate")
#
# Supporting functions
#
convergence = {
"sgc": {"bushy": 3, "tstellate": 6, "dstellate": 10, "dstellate_eager": 10},
"dstellate": {"bushy": 10, "tstellate": 15, "dstellate": 5},
}
def make_cell(typ):
if typ == "sgc":
cell = cells.SGC.create()
elif typ == "tstellate":
cell = cells.TStellate.create(debug=True, ttx=False)
elif (
typ == "dstellate"
): # Type I-II Rothman model, similiar excitability (Xie/Manis, unpublished)
cell = cells.DStellate.create(model="RM03", debug=True, ttx=False)
elif typ == "dstellate_eager": # From Eager et al.
cell = cells.DStellate.create(model="Eager", debug=True, ttx=False)
elif typ == "bushy":
cell = cells.Bushy.create(debug=True, ttx=False)
else:
raise ValueError("Unknown cell type '%s'" % typ)
return cell
class SynapseTester(UserTester):
def __init__(self, pre, post):
self.st = None
UserTester.__init__(self, "%s_%s" % (pre, post), pre, post)
def run_test(self, pre, post):
# Make sure no objects are left over from previous tests
reset(raiseError=False)
# seed random generator using the name of this test
seed = "%s_%s" % (pre, post)
pre_cell = make_cell(pre)
post_cell = make_cell(post)
n_term = convergence.get(pre, {}).get(post, None)
if n_term is None:
n_term = 1
st = SynapseTest()
st.run(pre_cell.soma, post_cell.soma, n_term, seed=seed)
if self.audit:
st.show_result()
info = dict(
rel_events=st.release_events(),
rel_timings=st.release_timings(),
open_prob=st.open_probability(),
event_analysis=st.analyze_events(),
)
self.st = st
# import weakref
# global last_syn
# last_syn = weakref.ref(st.synapses[0].terminal.relsi)
return info
def assert_test_info(self, *args, **kwds):
try:
super(SynapseTester, self).assert_test_info(*args, **kwds)
finally:
if self.st is not None:
self.st.hide()