def fix_axon_perisomatic_directed(hobj): # io.log_info('Fixing Axon like perisomatic') all_sec_names = [] for sec in hobj.all: all_sec_names.append(sec.name().split(".")[1][:4]) if 'axon' not in all_sec_names: io.log_exception('There is no axonal recostruction in swc file.') else: beg1, end1, beg2, end2 = get_axon_direction(hobj) for sec in hobj.axon: h.delete_section(sec=sec) h.execute('create axon[2]', hobj) h.pt3dadd(beg1[0], beg1[1], beg1[2], 1, sec=hobj.axon[0]) h.pt3dadd(end1[0], end1[1], end1[2], 1, sec=hobj.axon[0]) hobj.all.append(sec=hobj.axon[0]) h.pt3dadd(beg2[0], beg2[1], beg2[2], 1, sec=hobj.axon[1]) h.pt3dadd(end2[0], end2[1], end2[2], 1, sec=hobj.axon[1]) hobj.all.append(sec=hobj.axon[1]) hobj.axon[0].connect(hobj.soma[0], 0.5, 0) hobj.axon[1].connect(hobj.axon[0], 1.0, 0) hobj.axon[0].L = 30.0 hobj.axon[1].L = 30.0 h.define_shape() for sec in hobj.axon: # print "sec.L:", sec.L if np.abs(30 - sec.L) > 0.0001: io.log_exception('Axon stub L is less than 30')
def _fix_axon(self): """Removes and refixes axon""" axon_diams = [self._hobj.axon[0].diam, self._hobj.axon[0].diam] axon_indices = [] for i, sec in enumerate(self._hobj.all): section_name = sec.name().split(".")[1][:4] if section_name == 'axon': axon_diams[1] = sec.diam axon_indices.append(i) for sec in self._hobj.axon: h.delete_section(sec=sec) h.execute('create axon[2]', self._hobj) for index, sec in enumerate(self._hobj.axon): sec.L = 30 sec.diam = 1 self._hobj.axonal.append(sec=sec) self._hobj.all.append(sec=sec) # need to remove this comment self._hobj.axon[0].connect(self._hobj.soma[0], 1.0, 0) self._hobj.axon[1].connect(self._hobj.axon[0], 1.0, 0) h.define_shape()
def fix_axon_allactive(hobj): """Replace reconstructed axon with a stub Parameters ---------- hobj: instance of a Biophysical template NEURON's cell object """ # find the start and end diameter of the original axon, this is different from the perisomatic cell model # where diameter == 1. axon_diams = [hobj.axon[0].diam, hobj.axon[0].diam] for sec in hobj.all: section_name = sec.name().split(".")[1][:4] if section_name == 'axon': axon_diams[1] = sec.diam for sec in hobj.axon: h.delete_section(sec=sec) h.execute('create axon[2]', hobj) for index, sec in enumerate(hobj.axon): sec.L = 30 print axon_diams[index] sec.diam = axon_diams[index] # 1 hobj.axonal.append(sec=sec) hobj.all.append(sec=sec) # need to remove this comment # original allen sdk: hobj.soma[0], 0.5, 0 hobj.axon[0].connect(hobj.soma[0], 1.0, 0) hobj.axon[1].connect(hobj.axon[0], 1, 0) h.define_shape()
def fix_axon(hobj): ''' Replace reconstructed axon with a stub Parameters ---------- hobj: instance of a Biophysical template NEURON's cell object ''' for sec in hobj.axon: h.delete_section(sec=sec) h.execute('create axon[2]', hobj) for sec in hobj.axon: sec.L = 30 sec.diam = 1 hobj.axonal.append(sec=sec) hobj.all.append(sec=sec) # need to remove this comment hobj.axon[0].connect(hobj.soma[0], 0.5, 0) hobj.axon[1].connect(hobj.axon[0], 1, 0) h.define_shape()
def fix_axon_allactive_granule(hobj): """Replace reconstructed axon with a stub Parameters ---------- hobj: instance of a Biophysical template NEURON's cell object """ # find the start and end diameter of the original axon, this is different from the perisomatic cell model # where diameter == 1. axon_diams = [hobj.axon[0].diam, hobj.axon[0].diam] h.distance(sec=hobj.soma[0]) # need this to set all distances relative to soma (not sure if from center?) for sec in hobj.all: section_name = sec.name().split(".")[1][:4] if section_name == 'axon': for seg in sec: if h.distance(seg.x) > 60: axon_diams[1] = sec.diam #if h.distance(0.5, sec) > 60: # axon_diams[1] = sec.diam for sec in hobj.axon: h.delete_section(sec=sec) h.execute('create axon[2]', hobj) for index, sec in enumerate(hobj.axon): sec.L = 30 sec.diam = axon_diams[index] # 1 hobj.axonal.append(sec=sec) hobj.all.append(sec=sec) # need to remove this comment hobj.axon[0].connect(hobj.soma[0], 1.0, 0) hobj.axon[1].connect(hobj.axon[0], 1.0, 0) h.define_shape()
def fill(self, channels, seed, n_trajectory): self.seed = seed self.channels = channels xmd = self.fitfun.xdat.c() ymd = h.List() for i in range(n_trajectory): seed2 = i ymd.append(self.datagen(self.channels, self.seed, seed2, xmd)) self.fitfun.set_data(xmd, ymd) h.execute("setxy()", self.fitfun)
def find_vrest(h, section_name): h.load_file("stdrun.hoc") tstop = 100 h.dt = dt = 0.1 soma, sec = fetch_soma_sec(section_name) h.init() h.cvode.re_init() t_vec, soma_vm, sec_vm = record(soma, sec) h.execute('tstop = 100') h.run() vrest = np.array(sec_vm)[-1] return vrest
def create_morph(swc_file, template): h.load_file("import3d.hoc") h.load_file("nrngui.hoc") h("objref cell, tobj") h.load_file(template + ".hoc") h.execute("cell = new " + template + "()") #replace nl = h.Import3d_SWC_read() nl.quiet = 1 nl.input(swc_file) imprt = h.Import3d_GUI(nl, 0) imprt.instantiate(h.cell) return h.cell
def create_model(model_name, morph_file): h("objref cell, tobj") morph_file = "../morphs/" + morph_file model_path = "../PassiveModels/" h.load_file(model_path + model_name + ".hoc") h.execute("cell = new " + model_name + "()") #replace? nl = h.Import3d_Neurolucida3() nl.quiet = 1 nl.input(morph_file) imprt = h.Import3d_GUI(nl, 0) imprt.instantiate(h.cell) cell = h.cell cell.geom_nseg() cell.delete_axon() cell.biophys() return cell
def fix_axon(hobj): """Replace reconstructed axon with a stub :param hobj: NEURON's cell object """ for sec in hobj.axon: h.delete_section(sec=sec) h.execute('create axon[2]', hobj) for sec in hobj.axon: sec.L = 30 sec.diam = 1 hobj.axonal.append(sec=sec) hobj.all.append(sec=sec) # need to remove this comment hobj.axon[0].connect(hobj.soma[0], 0.5, 0) hobj.axon[1].connect(hobj.axon[0], 1, 0) h.define_shape()
def run_sim(h, section_name, v_peak, tau_raise, tau_fall, onset=100): tstop = 500 h.dt = dt = 0.1 h.load_file("stdrun.hoc") soma, sec = fetch_soma_sec(section_name) v_rest = -75.711 # find_vrest(h, section_name) h.init() h.cvode.re_init() s_v, a_v = fetch_soma_apic_pots() vv = voltage_clamp(tstop, dt, v_rest, v_peak, tau_raise, tau_fall, onset) vc = h.SEClamp(sec(0.5)) vc.rs = 0.001 vc.dur1 = tstop vamp = h.Vector(vv) vamp.play(vc._ref_amp1, h.dt) t_vec, soma_vm, sec_vm = record(soma, sec) h.execute('tstop = ' + str(tstop)) h.run() diff_v = np.array(a_v) - np.array(s_v) return t_vec, soma_vm, sec_vm, diff_v, vv
def create_model(model_file, morph_file, model_path="../PassiveModels/", morph_path="../morphs/"): # creating the model h.load_file("import3d.hoc") h.load_file("nrngui.hoc") h("objref cell, tobj") h.load_file(model_path + model_file + ".hoc") h.execute("cell = new " + model_file + "()") nl = h.Import3d_Neurolucida3() nl.quiet = 1 nl.input(morph_path + morph_file) imprt = h.Import3d_GUI(nl, 0) imprt.instantiate(h.cell) HCell = h.cell HCell.geom_nseg() HCell.create_model() HCell.biophys() return HCell
def fix_axon_allactive_directed(hobj): all_sec_names = [] for sec in hobj.all: all_sec_names.append(sec.name().split(".")[1][:4]) if 'axon' not in all_sec_names: io.log_exception('There is no axonal recostruction in swc file.') else: beg1, end1, beg2, end2 = get_axon_direction(hobj) axon_diams = [hobj.axon[0].diam, hobj.axon[0].diam] for sec in hobj.all: section_name = sec.name().split(".")[1][:4] if section_name == 'axon': axon_diams[1] = sec.diam for sec in hobj.axon: h.delete_section(sec=sec) h.execute('create axon[2]', hobj) hobj.axon[0].connect(hobj.soma[0], 1.0, 0) hobj.axon[1].connect(hobj.axon[0], 1.0, 0) h.pt3dadd(beg1[0], beg1[1], beg1[2], axon_diams[0], sec=hobj.axon[0]) h.pt3dadd(end1[0], end1[1], end1[2], axon_diams[0], sec=hobj.axon[0]) hobj.all.append(sec=hobj.axon[0]) h.pt3dadd(beg2[0], beg2[1], beg2[2], axon_diams[1], sec=hobj.axon[1]) h.pt3dadd(end2[0], end2[1], end2[2], axon_diams[1], sec=hobj.axon[1]) hobj.all.append(sec=hobj.axon[1]) hobj.axon[0].L = 30.0 hobj.axon[1].L = 30.0 h.define_shape() for sec in hobj.axon: # io.log_info('sec.L: {}'.format(sec.L)) if np.abs(30 - sec.L) > 0.0001: io.log_exception('Axon stub L is less than 30')
segs.append(float(sys.argv[5 + 3 * i])) NUMBER_OF_SYNAPSES = len(trees) PARALLEL_ENV = 1 h.load_file("import3d.hoc") h.load_file("nrngui.hoc") h("objref cell, tobj") path = "../" morph_file = path + "Morphs/2013_03_06_cell08_876_H41_05_Cell2.ASC" model_file = "cell0603_08_model_cm_0_45" model_path = path + "PassiveModels/" print os.getcwd() h.load_file(model_path + model_file + ".hoc") h.execute("cell = new " + model_file + "()") #replace? nl = h.Import3d_Neurolucida3() nl.quiet = 1 nl.input(morph_file) imprt = h.Import3d_GUI(nl, 0) imprt.instantiate(h.cell) HCell = h.cell HCell.geom_nseg() HCell.create_model() HCell.biophys() T_DATA, V_DATA = read_epsp_file(PATH_exp + expname + ".dat") h.dt = T_DATA[1] - T_DATA[0] h.steps_per_ms = 1.0 / h.dt h.tstop = T_DATA[-1]
import scipy.optimize import pdb import math import progressbar import glob import peak_AMPA_cond_per_syn # creating the model h.load_file("import3d.hoc") h.load_file("nrngui.hoc") h("objref cell, tobj") morph_file = "../morphs/2013_03_06_cell08_876_H41_05_Cell2.ASC" model_file = "cell0603_08_model_cm_0_45" model_path = "../PassiveModels/" h.load_file(model_path + model_file + ".hoc") h.execute("cell = new " + model_file + "()") nl = h.Import3d_Neurolucida3() nl.quiet = 1 nl.input(morph_file) imprt = h.Import3d_GUI(nl, 0) imprt.instantiate(h.cell) HCell = h.cell HCell.geom_nseg() HCell.create_model() HCell.biophys() PATH_EPSP = 'ExpEPSP/Dat_Files/' EPSP_SUFFIX = '.dat' FIT_PREFIX_1_syn = 'fit_1_synapse/fit_1_syn_' FIT_PREFIX_5_syn = 'fit_5_synapses/fit_5_syn_' FIT_SUFFIX = '.txt'
import numpy as np import matplotlib.pyplot as plt import sys import math h.load_file("import3d.hoc") h.load_file("nrngui.hoc") h("objref cell, tobj") # create the model: morph_file = "../../morphs/2013_03_06_cell08_876_H41_05_Cell2.ASC" model_path = "../../ActiveModels/" model_name = 'model_0603_cell08_cm045' h.load_file(model_path + model_name + ".hoc") h.execute("cell = new " + model_name + "()") nl = h.Import3d_Neurolucida3() nl.quiet = 1 nl.input(morph_file) imprt = h.Import3d_GUI(nl, 0) imprt.instantiate(h.cell) cell = h.cell cell.geom_nseg() cell.delete_axon() cell.create_axon() cell.biophys() cell.active_biophys() # Measure distances along the axon L0 = cell.soma[0].L / 2 L1 = cell.axon[0].L
def run_RTHW(WRITE_TO_FILE=1, output_filename="rise_and_width_synapses_locations.txt"): # creating the model h.load_file("import3d.hoc") h.load_file("nrngui.hoc") h("objref cell, tobj") morph_file = "../morphs/2013_03_06_cell08_876_H41_05_Cell2.ASC" model_file = "cell0603_08_model_cm_0_45" model_path = "../PassiveModels/" h.load_file(model_path + model_file + ".hoc") h.execute("cell = new " + model_file + "()") nl = h.Import3d_Neurolucida3() nl.quiet = 1 nl.input(morph_file) imprt = h.Import3d_GUI(nl, 0) imprt.instantiate(h.cell) HCell = h.cell HCell.geom_nseg() HCell.create_model() HCell.biophys() PLOT_MODE = 0 TAU_1 = 0.3 TAU_2 = 1.8 E_SYN = 0 WEIGHT = 0.0003 E_PAS = -86 Spike_time = 10 DELAY = 0 NUM_OF_SYNAPSES = 1 DT = 0.01 h.tstop = 100 h.v_init = E_PAS h.steps_per_ms = 1.0 / DT h.dt = DT if WRITE_TO_FILE: f1 = open(output_filename, 'w+') Stim1 = h.NetStim() Stim1.interval = 10000 Stim1.start = Spike_time Stim1.noise = 0 Stim1.number = 1 # for a given synapse, this function run the simulation and calculate its shape index def calc_rise_and_width(PLOT_MODE=0): Vvec = h.Vector() Vvec.record(HCell.soma[0](0.5)._ref_v) h.init(h.v_init) h.run() np_v = np.array(Vvec) max_idx = np.argmax(np_v) rise_time = max_idx * DT - Stim1.start half_v = E_PAS + (np_v[max_idx] - E_PAS) / 2.0 for i in range(max_idx): if np_v[i] > half_v: rise_half = i * h.dt break for i in range(max_idx, np_v.size): if np_v[i] < half_v: decay_half = i * h.dt break half_width = decay_half - rise_half if PLOT_MODE: print "rise ,", rise_time, " half width ", half_width np_t = np.arange(0, h.tstop + h.dt, h.dt) print np_v.size, np_t.size plt.plot(np_t, np_v, 'b') plt.plot(np_t[max_idx], np_v[max_idx], 'b*') plt.plot(np.array([rise_half, decay_half]), np.array([half_v, half_v]), 'r') plt.show() return rise_time, half_width output_txt = "secanme\tx\tsoma_distance\trise_time\thalf_width\n" h.distance(sec=HCell.soma[0]) # run over all the electrical segments in the model. # in each one of them put a synapse and run the simulation. print "re-creating the theoretical_RTHW" num_secs = len([sec for sec in HCell.all]) bar = progressbar.ProgressBar(max_value=num_secs, widgets=[ ' [', progressbar.Timer(), '] ', progressbar.Bar(), ' (', progressbar.ETA(), ') ', ]) for ix, sec in enumerate(HCell.all): for seg in list(sec) + [sec(1)]: Syn1 = h.Exp2Syn(seg.x, sec=sec) Syn1.e = E_SYN Syn1.tau1 = TAU_1 Syn1.tau2 = TAU_2 Con1 = h.NetCon(Stim1, Syn1) Con1.weight[0] = WEIGHT Con1.delay = DELAY rise_time, half_width = calc_rise_and_width() output_txt += sec.name() + '\t' + str(seg.x) + '\t' + str( h.distance(seg.x, sec=sec)) + '\t' output_txt += str(rise_time) + '\t' + str(half_width) + '\n' bar.update(ix) if WRITE_TO_FILE: f1.write(output_txt) f1.close() return output_txt.strip().split("\n")