예제 #1
0
 def test_cell_distort_geometry_01(self):
     cell0 = LFPy.TemplateCell(
         morphology=os.path.join(LFPy.__path__[0], 'test',
                                 'ball_and_sticks_w_lists.hoc'),
         templatefile=os.path.join(LFPy.__path__[0], 'test',
                                   'ball_and_stick_template.hoc'),
         templatename='ball_and_stick_template',
         templateargs=None,
     )
     factors = [-0.2, 0.1, 0., 0.1, 0.2]
     nus = [-0.5, 0., 0.5]
     for factor in factors:
         for nu in nus:
             for axis in 'xyz':
                 cell1 = LFPy.TemplateCell(
                     morphology=os.path.join(LFPy.__path__[0], 'test',
                                             'ball_and_sticks_w_lists.hoc'),
                     templatefile=os.path.join(
                         LFPy.__path__[0], 'test',
                         'ball_and_stick_template.hoc'),
                     templatename='ball_and_stick_template',
                     templateargs=None,
                 )
                 cell1.distort_geometry(factor=factor, nu=nu, axis=axis)
                 for attr in ['start', 'mid', 'end']:
                     for ax in 'xyz'.replace(axis, ''):
                         np.testing.assert_allclose(
                             getattr(cell0, ax + attr) * (1 + factor * nu),
                             getattr(cell1, ax + attr))
                     np.testing.assert_allclose(
                         getattr(cell0, axis + attr) * (1 - factor),
                         getattr(cell1, axis + attr))
예제 #2
0
def generate_LFP_for_single_neuron(electrode, cell_name, params):
    cwd = os.getcwd()
    neuron.h.load_file('stdrun.hoc')
    neuron.h.load_file('import3d.hoc')

    #Loading the neuron models of interest
    neuron_model = '/home/baran/Desktop/neuron_models/' + cell_name

    load_mechanisms_from_neuron_model(cell_name)
    templatename = load_cell_properties(cell_name)
    os.chdir(neuron_model)
    morphologyfile = glob(os.path.join('morphology', '*'))[0]
    add_synapses = False

    cell = LFPy.TemplateCell(morphology=morphologyfile,
                             templatefile=(os.path.join(
                                 neuron_model, 'template.hoc')),
                             templatename=templatename,
                             templateargs=1 if add_synapses else 0,
                             tstop=params['tstop'],
                             dt=params['dt'],
                             nsegs_method=None,
                             pt3d=True,
                             verbose=True)

    #Add stimulation electrode
    pointProcess = LFPy.StimIntElectrode(cell, **params['PointProcParams'])

    cell.simulate(electrode=electrode)
    os.chdir(cwd)
    return electrode, cell
예제 #3
0
    def test_cell_chiral_morphology_02(self):
        '''test LFPy.TemplateCell.chiral_morphology()'''
        cell = LFPy.TemplateCell(
            morphology=os.path.join(LFPy.__path__[0], 'test',
                                    'ball_and_sticks_w_lists.hoc'),
            templatefile=os.path.join(LFPy.__path__[0], 'test',
                                      'ball_and_stick_template.hoc'),
            templatename='ball_and_stick_template',
            templateargs=None,
        )

        xstarts = cell.xstart.copy()
        xmids = cell.xmid.copy()
        xends = cell.xend.copy()
        ystarts = cell.ystart.copy()
        ymids = cell.ymid.copy()
        yends = cell.yend.copy()
        zstarts = cell.zstart.copy()
        zmids = cell.zmid.copy()
        zends = cell.zend.copy()
        # test rotation 180 deg around z-axis
        cell.chiral_morphology(axis='z')
        # assert that y- and z-coordinates are inverted, using absolute

        # tolerances
        np.testing.assert_allclose(cell.xstart, xstarts, atol=1e-07)
        np.testing.assert_allclose(cell.xmid, xmids, atol=1e-07)
        np.testing.assert_allclose(cell.xend, xends, atol=1e-07)
        np.testing.assert_allclose(cell.ystart, ystarts, atol=1e-07)
        np.testing.assert_allclose(cell.ymid, ymids, atol=1e-07)
        np.testing.assert_allclose(cell.yend, yends, atol=1e-07)
        np.testing.assert_allclose(cell.zstart, -zstarts, atol=1e-07)
        np.testing.assert_allclose(cell.zmid, -zmids, atol=1e-07)
        np.testing.assert_allclose(cell.zend, -zends, atol=1e-07)
예제 #4
0
    def return_cell(self):

        self.model_path = join(root_path+'TC_neuron')
        neuron.load_mechanisms(self.model_path)

        cell_parameters = {
            'morphology': join(self.model_path, 'soma.hoc'),
            'passive':False,
            'v_init' : -60,
            'extracellular':False,
            'nsegs_method': 'none',
            # 'timeres_NEURON':0.1,
            # 'timeres_python':0.1,
            'dt' : 0.1,
            'tstop':2000,
            'tstart':0,
            'templatefile': join(self.model_path, 'TC_GH2.hoc'),
            'templatename':'sTC',
            'templateargs':None,
            'delete_sections':False
        }

        cell = LFPy.TemplateCell(**cell_parameters)

        return cell
예제 #5
0
    def test_cell_set_rotation_05(self):
        '''test LFPy.TemplateCell.set_rotation()'''
        cell = LFPy.TemplateCell(
            morphology=os.path.join(LFPy.__path__[0], 'test',
                                    'ball_and_sticks_w_lists.hoc'),
            templatefile=os.path.join(LFPy.__path__[0], 'test',
                                      'ball_and_stick_template.hoc'),
            templatename='ball_and_stick_template',
            templateargs=None,
            pt3d=True)

        xstarts = cell.xstart.copy()
        xmids = cell.xmid.copy()
        xends = cell.xend.copy()
        ystarts = cell.ystart.copy()
        ymids = cell.ymid.copy()
        yends = cell.yend.copy()
        # test rotation 180 deg around z-axis
        cell.set_rotation(z=np.pi)
        # assert that y- and z-coordinates are inverted, using absolute
        # tolerances
        np.testing.assert_allclose(cell.xstart, -xstarts, atol=1e-07)
        np.testing.assert_allclose(cell.xmid, -xmids, atol=1e-07)
        np.testing.assert_allclose(cell.xend, -xends, atol=1e-07)
        np.testing.assert_allclose(cell.ystart, -ystarts, atol=1e-07)
        np.testing.assert_allclose(cell.ymid, -ymids, atol=1e-07)
        np.testing.assert_allclose(cell.yend, -yends, atol=1e-07)
예제 #6
0
    def return_cell(self):

        self.model_path = join(root_path+'cortex_neurons')
        neuron.load_mechanisms(self.model_path)

        cell_parameters = {
            'morphology': join(self.model_path, 'soma.hoc'),
            'passive':False,
            'v_init' : -70,
            'extracellular':False,
            'nsegs_method': 'lambda_f',
            'lambda_f': 50,
            #'timeres_NEURON':0.1,
            #'timeres_python':0.1,
            'dt' : 0.1,
            'tstop':2000,
            'tstart':0,
            'templatefile': join(self.model_path, 'sPY_template'),
            'templatename':'sPY',
            'templateargs':None,
            'custom_fun': None,
            'delete_sections':False
        }

        cell = LFPy.TemplateCell(**cell_parameters)
        cell.set_rotation(x=-1.57, y=0.0, z=0.0)

        return cell
예제 #7
0
def simulate(cell_parameters, synapse_parameters, grid_electrode_parameters, syninds, x_rot=0, y_rot=0, z_rot=0, active=False):
    """set synapse location. simulate cell, synapse and electrodes for input synapse location"""

    # create cell with parameters in dictionary
    if not active:
        cell = LFPy.Cell(**cell_parameters)
    else:
        cell = LFPy.TemplateCell(**cell_parameters)

    # rotate cell
    cell.set_rotation(x=x_rot)
    cell.set_rotation(y=y_rot)
    cell.set_rotation(z=z_rot)

    # insert synapses
    if type(syninds) == int:
        syninds = [syninds]
    for idx in syninds:
        synapse_parameters['idx'] = idx
        synapse = LFPy.Synapse(cell, **synapse_parameters)
        synapse.set_spike_times(np.array([20.]))

    # simulate cell
    cell.simulate(rec_imem = True,
                  rec_vmem = True,
                  rec_current_dipole_moment=True)

    #create grid electrodes
    grid_electrode = LFPy.RecExtElectrode(cell, **grid_electrode_parameters)
    grid_electrode.calc_lfp()

    return cell, synapse, grid_electrode
예제 #8
0
 def test_cell_set_pos_00(self):
     '''test LFPy.TemplateCell.set_pos'''
     cell = LFPy.TemplateCell(
         morphology=os.path.join(LFPy.__path__[0], 'test',
                                 'ball_and_sticks_w_lists.hoc'),
         templatefile=os.path.join(LFPy.__path__[0], 'test',
                                   'ball_and_stick_template.hoc'),
         templatename='ball_and_stick_template',
         templateargs=None,
     )
     np.testing.assert_allclose(cell.somapos, [0, 0, 0])
예제 #9
0
def create_cell(cell_parameters, active=False, x_rot=0, y_rot=0, z_rot=0):
    # create cell with parameters in dictionary
    if not active:
        cell = LFPy.Cell(**cell_parameters)
    else:
        cell = LFPy.TemplateCell(**cell_parameters)

    cell.set_rotation(x=x_rot)
    cell.set_rotation(y=y_rot)
    cell.set_rotation(z=z_rot)

    return cell
예제 #10
0
 def test_cell_get_rand_prob_area_norm_from_idx_00(self):
     '''test LFPy.TemplateCell.get_rand_prob_area_norm()'''
     cell = LFPy.TemplateCell(
         morphology=os.path.join(LFPy.__path__[0], 'test',
                                 'ball_and_sticks_w_lists.hoc'),
         templatefile=os.path.join(LFPy.__path__[0], 'test',
                                   'ball_and_stick_template.hoc'),
         templatename='ball_and_stick_template',
         templateargs=None,
     )
     p = cell.get_rand_prob_area_norm_from_idx(idx=np.array([0]))
     np.testing.assert_equal(p, np.array([1.]))
예제 #11
0
 def test_cell_get_idx_parent_children_00(self):
     cell = LFPy.TemplateCell(
         morphology=os.path.join(LFPy.__path__[0], 'test',
                                 'ball_and_sticks_w_lists.hoc'),
         templatefile=os.path.join(LFPy.__path__[0], 'test',
                                   'ball_and_stick_template.hoc'),
         templatename='ball_and_stick_template',
         templateargs=None,
     )
     np.testing.assert_array_equal(
         cell.get_idx_parent_children(parent='soma[0]'),
         cell.get_idx(section=['soma[0]', 'dend[0]']))
예제 #12
0
def stickSimulationTesttvec(**kwargs):
    stick = LFPy.TemplateCell(morphology=os.path.join(LFPy.__path__[0], 'test',
                                                      'stick.hoc'),
                              verbose=False,
                              templatefile=os.path.join(
                                  LFPy.__path__[0], 'test',
                                  'stick_template.hoc'),
                              templatename='stick_template',
                              templateargs=None,
                              **kwargs)
    stick.simulate(rec_imem=False)
    return stick.tvec
예제 #13
0
    def test_cell_simulate_current_dipole_moment_01(self):
        stickParams = {
            'morphology':
            os.path.join(LFPy.__path__[0], 'test', 'stick.hoc'),
            'templatefile':
            os.path.join(LFPy.__path__[0], 'test', 'stick_template.hoc'),
            'templatename':
            'stick_template',
            'templateargs':
            None,
            'cm':
            1,
            'Ra':
            150,
            'v_init':
            -65,
            'passive':
            True,
            'passive_parameters': {
                'g_pas': 1. / 30000,
                'e_pas': -65
            },
            'tstart':
            -100,
            'tstop':
            100,
            'dt':
            2**-4,
            'nsegs_method':
            'lambda_f',
            'lambda_f':
            100,
        }

        stimParams = {
            'pptype': 'SinSyn',
            'delay': 0.,
            'dur': 1000.,
            'pkamp': 1.,
            'freq': 100.,
            'phase': 0,
            'bias': 0.,
            'record_current': False
        }

        for idx in range(31):  #31 segments
            if idx != 15:  # no net dipole moment because of stick symmetry
                stick = LFPy.TemplateCell(**stickParams)
                synapse = LFPy.StimIntElectrode(stick, idx=idx, **stimParams)
                stick.simulate(rec_imem=True, rec_current_dipole_moment=True)
                p = np.dot(stick.imem.T, np.c_[stick.xmid, stick.ymid,
                                               stick.zmid])
                np.testing.assert_allclose(p, stick.current_dipole_moment)
예제 #14
0
 def test_cell_strip_hoc_objects_00(self):
     cell = LFPy.TemplateCell(
         morphology=os.path.join(LFPy.__path__[0], 'test',
                                 'ball_and_sticks_w_lists.hoc'),
         templatefile=os.path.join(LFPy.__path__[0], 'test',
                                   'ball_and_stick_template.hoc'),
         templatename='ball_and_stick_template',
         templateargs=None,
     )
     cell.strip_hoc_objects()
     for attribute in dir(cell):
         self.assertNotEqual(str(type(getattr(cell, attribute))),
                             'hoc.HocObject')
예제 #15
0
 def test_cell_get_rand_prob_area_norm_from_idx(self):
     cell = LFPy.TemplateCell(
         morphology=os.path.join(LFPy.__path__[0], 'test',
                                 'ball_and_sticks_w_lists.hoc'),
         templatefile=os.path.join(LFPy.__path__[0], 'test',
                                   'ball_and_stick_template.hoc'),
         templatename='ball_and_stick_template',
         templateargs=None,
     )
     p = cell.get_rand_prob_area_norm_from_idx(idx=cell.get_idx(
         section='allsec'))
     self.assertListEqual(cell.get_rand_prob_area_norm().tolist(),
                          p.tolist())
예제 #16
0
 def test_cell_get_idx_name_00(self):
     cell = LFPy.TemplateCell(
         morphology=os.path.join(LFPy.__path__[0], 'test',
                                 'ball_and_sticks_w_lists.hoc'),
         templatefile=os.path.join(LFPy.__path__[0], 'test',
                                   'ball_and_stick_template.hoc'),
         templatename='ball_and_stick_template',
         templateargs=None,
     )
     np.testing.assert_array_equal(
         cell.get_idx_name(idx=np.array([0])),
         np.array([[0, 'ball_and_stick_template[0].soma[0]', 0.5]],
                  dtype=object))
예제 #17
0
    def test_cell_simulate_current_dipole_moment_02(self):
        stickParams = {
            'morphology':
            os.path.join(LFPy.__path__[0], 'test', 'stick.hoc'),
            'templatefile':
            os.path.join(LFPy.__path__[0], 'test', 'stick_template.hoc'),
            'templatename':
            'stick_template',
            'templateargs':
            None,
            'cm':
            1,
            'Ra':
            150,
            'v_init':
            -65,
            'passive':
            True,
            'passive_parameters': {
                'g_pas': 1. / 30000,
                'e_pas': -65
            },
            'tstart':
            -100,
            'tstop':
            100,
            'dt':
            2**-4,
            'nsegs_method':
            'lambda_f',
            'lambda_f':
            100,
        }

        stimParams = {
            'e': 0,  # reversal potential
            'syntype': 'Exp2Syn',  # synapse type
            'tau1': 0.1,  # syn. time constant
            'tau2': 2.,  # syn. time constant
            'weight': 0.01,
        }

        for idx in range(31):  #31 segments
            if idx != 15:  # no net dipole moment because of stick symmetry
                stick = LFPy.TemplateCell(**stickParams)
                synapse = LFPy.Synapse(stick, idx=idx, **stimParams)
                synapse.set_spike_times(np.array([10., 20., 30., 40., 50.]))
                stick.simulate(rec_imem=True, rec_current_dipole_moment=True)
                p = np.dot(stick.imem.T, np.c_[stick.xmid, stick.ymid,
                                               stick.zmid])
                np.testing.assert_allclose(p, stick.current_dipole_moment)
예제 #18
0
    def test_cell_get_closest_idx_00(self):
        cell = LFPy.TemplateCell(
            morphology=os.path.join(LFPy.__path__[0], 'test',
                                    'ball_and_sticks_w_lists.hoc'),
            templatefile=os.path.join(LFPy.__path__[0], 'test',
                                      'ball_and_stick_template.hoc'),
            templatename='ball_and_stick_template',
            templateargs=None,
            nsegs_method=None)
        self.assertEqual(cell.get_closest_idx(x=0, y=0, z=0),
                         cell.get_idx(section='soma')[0])

        self.assertEqual(cell.get_closest_idx(x=-25, y=0, z=175),
                         cell.get_idx(section='dend[1]')[0])
예제 #19
0
 def test_cell_get_rand_prob_area_norm_00(self):
     '''test LFPy.TemplateCell.get_rand_prob_area_norm()'''
     cell = LFPy.TemplateCell(
         morphology=os.path.join(LFPy.__path__[0], 'test',
                                 'ball_and_sticks_w_lists.hoc'),
         templatefile=os.path.join(LFPy.__path__[0], 'test',
                                   'ball_and_stick_template.hoc'),
         templatename='ball_and_stick_template',
         templateargs=None,
     )
     p = cell.get_rand_prob_area_norm()
     self.assertAlmostEqual(p.sum(), 1.)
     self.assertTrue(p.min() >= 0.)
     self.assertTrue(p.max() <= 1.)
예제 #20
0
    def test_cell_get_intersegment_distance_00(self):
        cell = LFPy.TemplateCell(
            morphology=os.path.join(LFPy.__path__[0], 'test',
                                    'ball_and_sticks_w_lists.hoc'),
            templatefile=os.path.join(LFPy.__path__[0], 'test',
                                      'ball_and_stick_template.hoc'),
            templatename='ball_and_stick_template',
            templateargs=None,
        )
        idx0 = 0
        idx1 = 1
        distance = cell.get_intersegment_distance(idx0=idx0, idx1=idx1)
        vector = cell.get_intersegment_vector(idx0=idx0, idx1=idx1)

        self.assertEqual(np.sqrt(np.array(vector)**2).sum(), distance)
예제 #21
0
def cellsim_w_HH(stim_I=0.2,
                 gnabar_hh=0.12,
                 gkbar_hh=0.036,
                 gl_hh=0.0003,
                 el_hh=-54.3):
    #LFPy.TemplateCell params
    cell_params = dict(
        morphology='soma.hoc',
        templatefile='LFPyCellTemplate.hoc',
        templatename='LFPyCellTemplate',
        passive=False,
        nsegs_method=None,
        tstartms=0,
        tstopms=1000,
        extracellular=False,
    )

    #LFPy.StimIntElectrode params
    stim_params = {
        'idx': 0,
        'pptype': 'IClamp',
        'delay': 100.,
        'dur': 800.,
        'amp': stim_I,
    }

    #Why templatecell - Hay2011 is one, see LFPy examples using it.
    cell = LFPy.TemplateCell(**cell_params)

    #throw on some HH channels
    for sec in cell.allseclist:
        sec.insert('hh')
        #These are important, basically the DOFs were attempting to fit
        for seg in sec:
            seg.hh.gnabar = gnabar_hh
            seg.hh.gkbar = gkbar_hh
            seg.hh.gl = gl_hh
            seg.hh.el = el_hh

    #set stimulus
    stim = LFPy.StimIntElectrode(cell, **stim_params)

    #run the sim
    cell.simulate()

    #return data
    return cell.tvec, cell.somav
예제 #22
0
    def test_cell_get_intersegment_vector_00(self):
        cell = LFPy.TemplateCell(
            morphology=os.path.join(LFPy.__path__[0], 'test',
                                    'ball_and_sticks_w_lists.hoc'),
            templatefile=os.path.join(LFPy.__path__[0], 'test',
                                      'ball_and_stick_template.hoc'),
            templatename='ball_and_stick_template',
            templateargs=None,
        )
        idx0 = 0
        idx1 = 1
        vector = cell.get_intersegment_vector(idx0=idx0, idx1=idx1)

        self.assertListEqual(vector, [
            cell.xmid[idx1] - cell.xmid[idx0], cell.ymid[idx1] -
            cell.ymid[idx0], cell.zmid[idx1] - cell.zmid[idx0]
        ])
예제 #23
0
 def test_cell_set_point_process_00(self):
     cell = LFPy.TemplateCell(
         morphology=os.path.join(LFPy.__path__[0], 'test',
                                 'ball_and_sticks_w_lists.hoc'),
         templatefile=os.path.join(LFPy.__path__[0], 'test',
                                   'ball_and_stick_template.hoc'),
         templatename='ball_and_stick_template',
         templateargs=None,
     )
     cell.set_point_process(idx=0,
                            pptype='IClamp',
                            record_current=False,
                            **dict(delay=1., amp=1.))
     self.assertEqual(cell.stimlist[0].hname(), 'IClamp[0]')
     self.assertEqual(len(cell.stimlist), 1)
     self.assertEqual(cell.stimlist[0].delay, 1.)
     self.assertEqual(cell.stimlist[0].amp, 1.)
예제 #24
0
    def test_cell_cellpickler_00(self):
        cell = LFPy.TemplateCell(
            morphology=os.path.join(LFPy.__path__[0], 'test',
                                    'ball_and_sticks_w_lists.hoc'),
            templatefile=os.path.join(LFPy.__path__[0], 'test',
                                      'ball_and_stick_template.hoc'),
            templatename='ball_and_stick_template',
            templateargs=None,
        )
        cell_pickle = cell.cellpickler(filename=None, pickler=pickle.dumps)
        pickled_cell = pickle.loads(cell_pickle)

        for attribute in dir(cell):
            if attribute.startswith('__') or attribute.startswith('_'):
                pass
            else:
                self.assertEqual(type(getattr(cell, attribute)),
                                 type(getattr(pickled_cell, attribute)))
예제 #25
0
 def test_cell_get_idx_00(self):
     cell = LFPy.TemplateCell(
         morphology=os.path.join(LFPy.__path__[0], 'test',
                                 'ball_and_sticks_w_lists.hoc'),
         templatefile=os.path.join(LFPy.__path__[0], 'test',
                                   'ball_and_stick_template.hoc'),
         templatename='ball_and_stick_template',
         templateargs=None,
         nsegs_method=None)
     self.assertListEqual(cell.get_idx(section='soma').tolist(), [0])
     self.assertListEqual(cell.get_idx(section='soma[0]').tolist(), [0])
     self.assertListEqual(cell.get_idx(section='dend[0]').tolist(), [1])
     self.assertListEqual(cell.get_idx(section='dend[1]').tolist(), [2])
     self.assertListEqual(cell.get_idx(section='dend[2]').tolist(), [3])
     self.assertListEqual(cell.get_idx(section='dend').tolist(), [1, 2, 3])
     self.assertListEqual(
         cell.get_idx(section='allsec').tolist(), [0, 1, 2, 3])
     self.assertListEqual(
         cell.get_idx(section=['soma', 'dend']).tolist(), [0, 1, 2, 3])
     self.assertListEqual(cell.get_idx(section='apic').tolist(), [])
예제 #26
0
    def return_cell(self):

        self.model_path = join(root_path+'Geir2011')
        neuron.load_mechanisms(self.model_path)

        cell_parameters = {
            # 5 dendrites
            #'morphology': join(self.model_path, 'ballnsticks.hoc'),
            # 4 dendrites
            'morphology': join(self.model_path, 'ballnsticks2.hoc'),
            'passive':True,
            'v_init' : -63,
            'extracellular':False,
            'nsegs_method': 'lambda_f',
            'lambda_f': 50,
            # 'timeres_NEURON':0.1,
            # 'timeres_python':0.1,
            'dt':0.1,
            'tstop':2000,
            'tstart':0,
            'templatefile': join(self.model_path, 'LFPyCellTemplate.hoc'),
            'templatename':'LFPyCellTemplate',
            'templateargs':None,
            'custom_fun': [insertChannels.active_declarations],
            'custom_fun_args': [{'arg1': 'arg1'}],
            'delete_sections':False,

            # passive mechanisms
            # 'passive_parameters': dict(g_pas=1/22000, e_pas=-67.5, Ra=113, cm=1.1)
            'passive_parameters':dict(g_pas=1/22000, e_pas=-67.5, Ra = 113, cm = 1.1)
            # 'e_pas' : -67.5,
            # 'Ra' : 113,
            # 'rm' : 22000,
            # 'cm' : 1.1
        }

        cell = LFPy.TemplateCell(**cell_parameters)
        cell.set_rotation(x=-1.57, y=0.0, z=0.0)
        # self.cell = cell

        return cell
예제 #27
0
    def test_cell_set_synapse_00(self):
        cell = LFPy.TemplateCell(
            morphology=os.path.join(LFPy.__path__[0], 'test',
                                    'ball_and_sticks_w_lists.hoc'),
            templatefile=os.path.join(LFPy.__path__[0], 'test',
                                      'ball_and_stick_template.hoc'),
            templatename='ball_and_stick_template',
            templateargs=None,
        )
        cell.set_synapse(idx=0,
                         syntype='ExpSyn',
                         record_curret=False,
                         record_potential=False,
                         weight=1.,
                         **dict(e=10., tau=2.))

        self.assertTrue('ExpSyn' in cell.synlist[0].hname())
        self.assertEqual(len(cell.synlist), 1)
        self.assertEqual(len(cell.netconlist), 1)
        self.assertEqual(len(cell.netstimlist), 1)
        self.assertEqual(cell.synlist[0].e, 10.)
        self.assertEqual(cell.synlist[0].tau, 2.)
        self.assertEqual(cell.netconlist[0].weight[0], 1.)
예제 #28
0
    def test_cell_set_rotation_06(self):
        '''test LFPy.TemplateCell.set_rotation()'''
        cell = LFPy.TemplateCell(
            morphology=os.path.join(LFPy.__path__[0], 'test', 'stick.hoc'),
            templatefile=os.path.join(LFPy.__path__[0], 'test',
                                      'ball_and_stick_template.hoc'),
            templatename='ball_and_stick_template',
            templateargs=None,
        )

        xstarts = cell.xstart.copy()
        xmids = cell.xmid.copy()
        xends = cell.xend.copy()
        ystarts = cell.ystart.copy()
        ymids = cell.ymid.copy()
        yends = cell.yend.copy()
        zstarts = cell.zstart.copy()
        zmids = cell.zmid.copy()
        zends = cell.zend.copy()
        # test rotation: 90 deg around x-axis, 90 deg around y-axis, 90 deg around z-axis
        cell.set_rotation(x=np.pi / 2., y=np.pi, z=np.pi / 4.)
        # revert rotation: -90 deg around x-axis, -90 deg around y-axis, -90 deg around z-axis, rotation_order='zyx'
        cell.set_rotation(x=-np.pi / 2.,
                          y=-np.pi,
                          z=-np.pi / 4.,
                          rotation_order='zyx')
        # assert that x-, y- and z-coordinates are same as beginning, using absolute
        # tolerances
        np.testing.assert_allclose(cell.xstart, xstarts, atol=1e-07)
        np.testing.assert_allclose(cell.xmid, xmids, atol=1e-07)
        np.testing.assert_allclose(cell.xend, xends, atol=1e-07)
        np.testing.assert_allclose(cell.ystart, ystarts, atol=1e-07)
        np.testing.assert_allclose(cell.ymid, ymids, atol=1e-07)
        np.testing.assert_allclose(cell.yend, yends, atol=1e-07)
        np.testing.assert_allclose(cell.zstart, zstarts, atol=1e-07)
        np.testing.assert_allclose(cell.zmid, zmids, atol=1e-07)
        np.testing.assert_allclose(cell.zend, zends, atol=1e-07)
예제 #29
0
    def test_cell_get_rand_idx_area_norm_00(self):
        cell = LFPy.TemplateCell(
            morphology=os.path.join(LFPy.__path__[0], 'test',
                                    'ball_and_sticks_w_lists.hoc'),
            templatefile=os.path.join(LFPy.__path__[0], 'test',
                                      'ball_and_stick_template.hoc'),
            templatename='ball_and_stick_template',
            templateargs=None,
        )
        idx = cell.get_rand_idx_area_norm(nidx=1000000)

        # compute histogram and correlate with segment area
        bins = np.arange(cell.totnsegs + 1)
        hist, bin_edges = np.histogram(idx, bins=bins)

        # compute Pearson correlation coefficients between area and histogram
        # reporting success if within 5 decimal places
        self.assertAlmostEqual(np.corrcoef(cell.area, hist)[0, 1],
                               1.,
                               places=5)

        # check if min and max is in the range of segment indices
        self.assertEqual(idx.min(), 0)
        self.assertEqual(idx.max(), cell.totnsegs - 1)
예제 #30
0
    print("biophysics loaded")
if not hasattr(neuron.h, templatename):
    # Load main cell template
    neuron.h.load_file(1, "template.hoc")

add_synapses = False

morphologyfile = glob(os.path.join('morphology', '*'))

LFPy.cell.neuron.init()

cell = LFPy.TemplateCell(morphology=morphologyfile[0],
                         templatefile=posixpth(
                             os.path.join(NRN, 'template.hoc')),
                         templatename=templatename,
                         templateargs=1 if add_synapses else 0,
                         tstop=tstop,
                         dt=dt,
                         extracellular=True,
                         nsegs_method=None,
                         passive=False)

# Set Position and Rotation
cell.set_rotation(x=np.pi / 2, z=np.pi / 2)

if np.max(cell.zend) > 0:
    cell.set_pos(z=-np.max(cell.zend) - 50)

source_amps = bisc.currents

positions_x = np.zeros(
    bisc.get_electrodes_number())  # to replace, use in built mea function