예제 #1
0
def main(gid, pop_name, config_file, template_paths, hoc_lib_path, dataset_prefix, config_prefix, mech_file,
         load_edges, load_weights, correct_for_spines, verbose):
    """

    :param gid: int
    :param pop_name: str
    :param config_file: str; model configuration file name
    :param template_paths: str; colon-separated list of paths to directories containing hoc cell templates
    :param hoc_lib_path: str; path to directory containing required hoc libraries
    :param dataset_prefix: str; path to directory containing required neuroh5 data files
    :param config_prefix: str; path to directory containing network and cell mechanism config files
    :param mech_file: str; cell mechanism config file name
    :param load_edges: bool; whether to attempt to load connections from a neuroh5 file
    :param load_weights: bool; whether to attempt to load connections from a neuroh5 file
    :param correct_for_spines: bool
    :param verbose: bool
    """
    utils.config_logging(verbose)
    logger = utils.get_script_logger(os.path.basename(__file__))

    comm = MPI.COMM_WORLD
    np.seterr(all='raise')
    env = Env(comm=comm, config_file=config_file, template_paths=template_paths, hoc_lib_path=hoc_lib_path,
              dataset_prefix=dataset_prefix, config_prefix=config_prefix, verbose=verbose)
    configure_hoc_env(env)

    mech_file_path = config_prefix + '/' + mech_file
    template_name = env.celltypes[pop_name]['template']
    if template_name.lower() == 'izhikevich':
        cell = make_izhikevich_cell(env, pop_name=pop_name, gid=gid,
                                    load_synapses=True, load_connections=True,
                                    load_edges=load_edges, load_weights=load_weights,
                                    mech_file_path=mech_file_path)
    elif template_name.lower() == 'pr_nrn':
        cell = make_PR_cell(env, pop_name=pop_name, gid=gid,
                            load_synapses=True, load_connections=True,
                            load_edges=load_edges, load_weights=load_weights,
                            mech_file_path=mech_file_path)
    else:
        cell = make_biophys_cell(env, pop_name=pop_name, gid=gid,
                                 load_synapses=True, load_connections=True,
                                 load_edges=load_edges, load_weights=load_weights,
                                 mech_file_path=mech_file_path)
    context.update(locals())

    init_biophysics(cell, reset_cable=True, correct_cm=correct_for_spines, correct_g_pas=correct_for_spines,
                    env=env, verbose=verbose)

    init_syn_mech_attrs(cell, env)
    config_biophys_cell_syns(env, gid, pop_name, insert=True, insert_netcons=True, insert_vecstims=True,
                             verbose=verbose)

    if verbose:
        for sec in list(cell.hoc_cell.all if hasattr(cell, 'hoc_cell') else cell.all):
            h.psection(sec=sec)
        report_topology(cell, env)
예제 #2
0
def main(config_file, population, gid, template_paths, dataset_prefix, config_prefix, load_synapses, syn_types, syn_sources, syn_source_threshold, font_size, bgcolor, colormap, verbose):

    utils.config_logging(verbose)
    logger = utils.get_script_logger(script_name)

    params = dict(locals())
    env = Env(**params)
    configure_hoc_env(env)

    ## Determine if a mechanism configuration file exists for this cell type
    if 'mech_file_path' in env.celltypes[population]:
        mech_file_path = env.celltypes[population]['mech_file_path']
    else:
        mech_file_path = None

    logger.info('loading cell %i' % gid)

    load_weights = False
    biophys_cell = make_biophys_cell(env, population, gid, 
                                     load_synapses=load_synapses,
                                     load_weights=load_weights, 
                                     load_edges=load_synapses,
                                     mech_file_path=mech_file_path)

    if len(syn_types) == 0:
        syn_types = None
    else:
        syn_types = list(syn_types)
    if len(syn_sources) == 0:
        syn_sources = None
    else:
        syn_sources = list(syn_sources)
        
    plot.plot_biophys_cell_tree (env, biophys_cell, saveFig=True,
                                 syn_source_threshold=syn_source_threshold,
                                 synapse_filters={'syn_types': syn_types, 'sources': syn_sources},
                                 bgcolor=bgcolor, colormap=colormap)
예제 #3
0
def init_biophys_cell(env,
                      pop_name,
                      gid,
                      load_weights=True,
                      load_connections=True,
                      register_cell=True,
                      write_cell=False,
                      validate_tree=True,
                      cell_dict={}):
    """
    Instantiates a BiophysCell instance and all its synapses.

    :param env: an instance of env.Env
    :param pop_name: population name
    :param gid: gid
    :param load_connections: bool
    :param register_cell: bool
    :param validate_tree: bool
    :param write_cell: bool
    :param cell_dict: dict

    Environment can be instantiated as:
    env = Env(config_file, template_paths, dataset_prefix, config_prefix)
    :param template_paths: str; colon-separated list of paths to directories containing hoc cell templates
    :param dataset_prefix: str; path to directory containing required neuroh5 data files
    :param config_prefix: str; path to directory containing network and cell mechanism config files
    """

    rank = int(env.pc.id())

    ## Determine template name for this cell type
    template_name = env.celltypes[pop_name]['template']

    ## Determine if a mechanism configuration file exists for this cell type
    if 'mech_file_path' in env.celltypes[pop_name]:
        mech_dict = env.celltypes[pop_name]['mech_dict']
    else:
        mech_dict = None

    ## Determine if correct_for_spines flag has been specified for this cell type
    synapse_config = env.celltypes[pop_name]['synapses']
    if 'correct_for_spines' in synapse_config:
        correct_for_spines_flag = synapse_config['correct_for_spines']
    else:
        correct_for_spines_flag = False

    ## Load cell gid and its synaptic attributes and connection data
    if template_name.lower() == 'izhikevich':
        cell = cells.make_izhikevich_cell(
            env,
            pop_name,
            gid,
            tree_dict=cell_dict.get('morph', None),
            synapses_dict=cell_dict.get('synapse', None),
            connection_graph=cell_dict.get('connectivity', None),
            weight_dict=cell_dict.get('weight', None),
            mech_dict=mech_dict,
            load_synapses=True,
            load_weights=load_weights,
            load_edges=load_connections)
    elif template_name.lower() == 'pr_nrn':
        cell = cells.make_PR_cell(env,
                                  pop_name,
                                  gid,
                                  tree_dict=cell_dict.get('morph', None),
                                  synapses_dict=cell_dict.get('synapse', None),
                                  connection_graph=cell_dict.get(
                                      'connectivity', None),
                                  weight_dict=cell_dict.get('weight', None),
                                  mech_dict=mech_dict,
                                  load_synapses=True,
                                  load_weights=load_weights,
                                  load_edges=load_connections)
    else:
        cell = cells.make_biophys_cell(
            env,
            pop_name,
            gid,
            tree_dict=cell_dict.get('morph', None),
            synapses_dict=cell_dict.get('synapse', None),
            connection_graph=cell_dict.get('connectivity', None),
            weight_dict=cell_dict.get('weight', None),
            mech_dict=mech_dict,
            load_synapses=True,
            load_weights=load_weights,
            load_edges=load_connections,
            validate_tree=validate_tree)

    cells.init_biophysics(cell,
                          reset_cable=True,
                          correct_cm=correct_for_spines_flag,
                          correct_g_pas=correct_for_spines_flag,
                          env=env)
    synapses.init_syn_mech_attrs(cell, env)

    if register_cell:
        cells.register_cell(env, pop_name, gid, cell)

    is_reduced = False
    if hasattr(cell, 'is_reduced'):
        is_reduced = cell.is_reduced
    if not is_reduced:
        cells.report_topology(cell, env)

    env.cell_selection[pop_name] = [gid]

    if is_interactive:
        context.update(locals())

    if write_cell:
        write_selection_file_path = "%s/%s_%d.h5" % (env.results_path,
                                                     env.modelName, gid)
        if rank == 0:
            io_utils.mkout(env, write_selection_file_path)
        env.comm.barrier()
        io_utils.write_cell_selection(env, write_selection_file_path)
        if load_connections:
            io_utils.write_connection_selection(env, write_selection_file_path)

    return cell
예제 #4
0
def main(config_file, population, gid, template_paths, dataset_prefix,
         config_prefix, data_file, load_synapses, syn_types, syn_sources,
         syn_source_threshold, font_size, bgcolor, colormap, verbose):

    utils.config_logging(verbose)
    logger = utils.get_script_logger(script_name)

    if dataset_prefix is None and data_file is None:
        raise RuntimeError(
            'Either --dataset-prefix or --data-file must be provided.')

    params = dict(locals())
    env = Env(**params)
    configure_hoc_env(env)

    if env.data_file_path is None:
        env.data_file_path = data_file
        env.load_celltypes()

    ## Determine if a mechanism configuration file exists for this cell type
    if 'mech_file_path' in env.celltypes[population]:
        mech_file_path = env.celltypes[population]['mech_file_path']
    else:
        mech_file_path = None

    ## Determine if correct_for_spines flag has been specified for this cell type
    synapse_config = env.celltypes[population]['synapses']
    if 'correct_for_spines' in synapse_config:
        correct_for_spines_flag = synapse_config['correct_for_spines']
    else:
        correct_for_spines_flag = False

    logger.info('loading cell %i' % gid)

    load_weights = False
    biophys_cell = make_biophys_cell(env,
                                     population,
                                     gid,
                                     load_synapses=load_synapses,
                                     load_weights=load_weights,
                                     load_edges=load_synapses,
                                     mech_file_path=mech_file_path)

    init_biophysics(biophys_cell,
                    reset_cable=True,
                    correct_cm=correct_for_spines_flag,
                    correct_g_pas=correct_for_spines_flag,
                    env=env)
    report_topology(biophys_cell, env)

    if len(syn_types) == 0:
        syn_types = None
    else:
        syn_types = list(syn_types)
    if len(syn_sources) == 0:
        syn_sources = None
    else:
        syn_sources = list(syn_sources)

    plot.plot_biophys_cell_tree(env,
                                biophys_cell,
                                saveFig=True,
                                syn_source_threshold=syn_source_threshold,
                                synapse_filters={
                                    'syn_types': syn_types,
                                    'sources': syn_sources
                                },
                                bgcolor=bgcolor,
                                colormap=colormap)