Ejemplo n.º 1
0
def test_nrntest_test_2():
    h = hoc.HocObject()

    h('''
    create axon, soma, dend[3]
    connect axon(0), soma(0)
    for i=0, 2 connect dend[i](0), soma(1)
    axon { nseg = 5  L=100 diam = 1 insert hh }
    forsec "dend" { nseg = 3 L=50 diam = 2 insert pas e_pas = -65 }
    soma { L=10 diam=10 insert hh }
    ''')

    assert h.axon.name() == "axon"
    assert str(h.dend) == "dend[?]"
    assert str(h.dend[1]) == "dend[1]"
    assert str(h.dend[1].name()) == "dend[1]"

    def e(stmt):
        try:
            exec(stmt)
        except Exception:
            assert (str(sys.exc_info()[0]) + ': ' + str(
                sys.exc_info()[1]) == "<class 'TypeError'>: not assignable")

    e('h.axon = 1')
    e('h.dend[1] = 1')

    assert str(h) == "<TopLevelHocInterpreter>"
    assert str(h.axon) == "axon"
    assert str(h.axon.name()) == "axon"
    assert str(h.axon(0.5)) == "axon(0.5)"
    assert str(h.axon(0.5).hh) == "hh"
    assert str(h.axon(0.5).hh.name()) == "hh"
    assert h.axon(0.5).hh.gnabar == 0.12
Ejemplo n.º 2
0
def test_nrntest_test_2():
    h = hoc.HocObject()

    h(
        '''
    create axon, soma, dend[3]
    connect axon(0), soma(0)
    for i=0, 2 connect dend[i](0), soma(1)
    axon { nseg = 5  L=100 diam = 1 insert hh }
    forsec "dend" { nseg = 3 L=50 diam = 2 insert pas e_pas = -65 }
    soma { L=10 diam=10 insert hh }
    '''
    )

    assert h.axon.name() == "axon"
    assert str(h.dend) == "dend[?]"
    assert str(h.dend[1]) == "dend[1]"
    assert str(h.dend[1].name()) == "dend[1]"

    def e(stmt):
        err = 0
        try:
            exec(stmt, globals(), locals())
        except Exception:
            assert ('not assignable' in str(sys.exc_info()[1]))
            err = 1
        assert(err == 1)

    e('h.axon = 1')
    e('h.dend[1] = 1')

    assert str(h) == "<TopLevelHocInterpreter>"
    assert str(h.axon) == "axon"
    assert str(h.axon.name()) == "axon"
    assert str(h.axon(0.5)) == "axon(0.5)"
    assert str(h.axon(0.5).hh) == "hh"
    assert str(h.axon(0.5).hh.name()) == "hh"
    assert h.axon(0.5).hh.gnabar == 0.12
    assert h.axon(0.5) in h.axon
    assert h.axon(0.5) not in h.soma
Ejemplo n.º 3
0
from neuron import h, gui
h('create axon')
import __main__
import sys
def e(stmt) :
  try:
    print stmt
    exec stmt in __main__.__dict__
  except:
    print sys.exc_info()[0], ': ', sys.exc_info()[1]

e('print h.axon.i_membrane_')
e('print h.axon(.5).i_membrane_')

h.delete_section()

h.load_file("imemaxon2.hoc")
for seg in h.axon:
  print seg.x, seg.i_membrane*seg.area()*(0.01), seg.i_membrane_
for seg in h.axon.allseg():
  print seg.x, seg._ref_i_membrane_[0], seg.i_membrane_

print h.axon.i_membrane, h.axon(.5).i_membrane
print h.axon.i_membrane_


def get_trace(file_name,
              synapse_type=0,
              synapse_numbers=(10, 10),
              hz=None,
              space_plot=False,
              vm=-65.0,
              cli=5.0,
              ldend_diam=0.5):
    """
    Get the voltage trace and cli trace from running a hoc file.

    Optionally, specify space_plot to get the cli along the entire neuron (nseg dependent).

    `vm` and `cli` should be specified by running `get_base_vm_cli` beforehand and passing in those values.

    :param file_name: hoc-specified neuron to load (from hoc_files/cells)
    :type file_name: str
    :param synapse_type: 0 if 'f-in' NETSTIM synapses. 1 if 'persistetnt' fluctuating conductance synapses.
    :type synapse_type: int
    :param synapse_numbers: Number of (E,I) synapses.
    :type synapse_numbers: tuple of int
    :param hz: Input to the synapses. Keys used are 'in' and 'ex'.
        Either frequency-based (`synapse_type` is `0`) or relative conductance (`synapse_type` is `1`).
    :type hz: dict of str
    :param space_plot: Compute cli at every location.
    :type space_plot: bool
    :param vm: Initial membrane potential
    :type vm: float
    :param cli: Initial chloride ion concentration
    :type cli: float
    :param ldend_diam: Diameter of distal dendrite.
    :type ldend_diam: float
    :return: Time array, voltage array, chloride array,
        space plot dict data of form `{distance from soma: chloride array}`
    :rtype: tuple[h.Vector, h.Vector, h.Vector, dict of float:h.Vector]
    """
    if hz is None:
        hz = {'in': 5, 'ex': 5}
    load_file(file_name)

    h.changeSynapseType(synapse_type)
    h.newSynapses(synapse_numbers[0], synapse_numbers[1])
    if synapse_type == 0:
        h.inPy(hz['in'], 1, 1)
        h.ex(hz['ex'], 1, 1)
    else:
        h.inPy(hz['in'])
        h.ex(hz['ex'])
    if "distal" in file_name:
        compartment = h.ldend
    elif "proximal" in file_name:
        compartment = h.bdend
    else:
        compartment = h.soma

    h("forall {" + "cli={} ".format(cli) + "cli0_KCC2={}".format(cli) + "}")
    for sec in h.allsec:
        for seg in sec:
            seg.cli = cli
    h.cli0_cl_ion = cli
    h.ldend.diam = ldend_diam
    # sort on key
    data = {}
    if space_plot:
        h.distance(0, 1, sec=h.soma)
        for sec in h.allsec:
            for seg in sec:
                # label = f"{sec.name()}({seg.x:.5f})"
                label = h.distance(seg.x, sec=sec)
                if 'dend' in sec.name():
                    label *= -1
                data[label] = h.Vector()
                data[label].record(sec(seg.x)._ref_cli)

    h.tstop = 1000.0
    time_past = current_time('ms')
    logger.info("running {}...".format(file_name))
    h.v_init = vm
    h.finitialize(vm)
    t_vec = h.Vector()
    t_vec.record(h._ref_t)
    v_vec = h.Vector()
    v_vec.record(h.axon(0.5)._ref_v)
    cli_vec = h.Vector()
    cli_vec.record(compartment(0.5)._ref_cli)

    h.run()

    logger.info("time taken: {}ms".format(current_time('ms') - time_past))
    logger.info("no. spikes = {}".format(h.apc.n))

    return t_vec, v_vec, cli_vec, data