Exemple #1
0
def test_HocObject_no_deferred_unref():
    #previous tests should really destroy the model they created
    for sec in h.allsec():
        h.delete_section(sec=sec)

    sl = h.SectionList()
    cell = h.Cell()
    assert (len(list(cell.all)) == 2)

    del cell

    # When deferred deletion was in effect, following for loop  would segfault
    # because actual deletion of the HOC Cell object would not occur til the next
    # h.functioncall(). I.e. the first call to sl.append below would destroy
    # the HOC Cell which would destroy the two Sections and invalidate the
    # iterator causing a segfault.
    for sec in h.allsec():
        print(sec)
        sl.append(sec=sec)
    assert (len([s for s in sl]) == 0)
Exemple #2
0
  soma {
    nseg=1
    diam = 10
    L = 100/(PI*diam)
    insert pas
    g_pas = .001
    e_pas = -65
  }
}
endtemplate Cell
''')

ncell = 2
cells = {}
for gid in range(rank, ncell, nhost):
    cells[gid] = h.Cell()

imp = h.Impedance()
if 0 in cells: imp.loc(.5, sec=cells[0].soma)


def foo(freq):
    if rank == 0: print("impedance")
    # all ranks must participate in the compute
    imp.compute(freq, 1)

    for gid in cells:
        print("cell[%d].soma transfer %g" %
              (gid, imp.transfer(.5, sec=cells[gid].soma)))

Exemple #3
0
def test_natrans():
    gids = [gid for gid in range(rank, ncell, nhost)]
    cells = []
    for gid in range(rank, ncell, nhost):
        pc.set_gid2node(gid, rank)
        cells.append(h.Cell())
        pc.cell(gid,
                h.NetCon(cells[-1].soma(0.5)._ref_v, None, sec=cells[-1].soma))

    r = h.Random()
    r.Random123(1, 1, 0)

    # nsrc unique random sgids in range(ncell). Sample without replacement.
    sgids = []
    v = list(range(ncell))
    for i in range(nsrc):
        x = int(r.discunif(0, len(v) - 1))
        sgids.append(v[x])
        v.pop(x)
    del v

    for sgid in sgids:
        if pc.gid_exists(sgid) == 3:
            sec = pc.gid2cell(sgid).soma
            pc.source_var(sec(0.5)._ref_nai, sgid, sec=sec)

    # ntarget randomly chosen cells are targets for the nsrc sgids
    # ntarget NaTrans are created
    targets = []
    for itar in range(ntarget):
        gid = int(r.discunif(0, ncell - 1))
        sgid = sgids[int(r.discunif(0, nsrc - 1))]
        if pc.gid_exists(gid) == 3:
            sec = pc.gid2cell(gid).soma
            target = h.NaTrans(sec(0.5))
            targets.append(target)
            pc.target_var(target, target._ref_napre, sgid)
            target.sgid = sgid

    cvode = h.CVode()
    cvode.cache_efficient(1)

    pc.set_maxstep(10)
    pc.setup_transfer()

    h.dt = 0.1
    tstop = 0.1

    def run():
        h.finitialize(-65)
        for sgid in sgids:
            if pc.gid_exists(sgid) == 3:
                sec = pc.gid2cell(sgid).soma
                sec(0.5).nai = float(sgid) / 100.0 + 0.001
        tars = h.List("NaTrans")
        for tar in tars:
            tar.napre = 0.0001  # correct values don't carryover from previous sim
        pc.psolve(tstop)
        for tar in tars:
            x = (tar.sgid / 100.0 + 0.001) if tar.sgid >= 0.0 else 0.0
            differ = ("differ") if abs(tar.napre - x) > 1e-10 else ""
            if differ != "":
                print("%d %s %g %g %g %s" %
                      (rank, tar.hname(), tar.sgid, tar.napre, x, differ))
            assert differ == ""

    run()  # NEURON: Fails if tar.napre not what is expected

    from neuron import coreneuron

    coreneuron.available = True
    if coreneuron.available:
        coreneuron.enable = True
        coreneuron.cell_permute = 0
        run()  # Fails if CoreNEURON does not copy expected tar.napre to NEURON

    return cells, gids, sgids, targets
Exemple #4
0
begintemplate Cell
public soma, dend
create soma, dend

proc init() {
  connect dend(0), soma(1)
  soma { L=10  diam= 10 insert hh }
  dend { L=20  diam=1   insert pas  g_pas = .001  e_pas = -65 }
}
endtemplate Cell

""")

# 1 cell for each rank
cell = h.Cell()

# rank 0 cell uses multisplit. Works if rank = 1
if rank == 0:
    h.disconnect(sec=cell.dend)
    pc.multisplit(0.0, rank, sec=cell.dend)
    pc.multisplit(1.0, rank, sec=cell.soma)

# gap junction between soma of rank i and rank (i+1)%nhost
# use sids of 2*i and 2*i + 1 for the source voltages
halfgaps = []


def mkgap(i):
    if rank == i:
        gap = h.HalfGap(cell.soma(0.5))