Exemplo n.º 1
0
    def build_cells(self):
        """Instantiate cells based on parameters provided in the InternalCell table and Internal CellModel table"""
        self._select_local_nodes()
        for node in self._local_nodes:
            gid = node.node_id

            if node.cell_type == CellTypes.Biophysical:
                self._cells[gid] = BioCell(node, self.spike_threshold, self.dL,
                                           self.calc_ecp,
                                           self._save_connections)
                self._local_biophys_gids.append(gid)

            elif node.cell_type == CellTypes.Point:
                self._cells[gid] = LIFCell(node)

            elif node.cell_type == CellTypes.Virtual:
                # Just in case, should never see
                continue

            else:
                io.print2log0('ERROR: not implemented class')
                # raise NotImplementedError('not implemented cell class')
                nrn.quit_execution()

            # TODO: Add ability to easily extend the Cell-Types without hardcoding into this loop!!
        pc.barrier()  # wait for all hosts to get to this point

        self.make_morphologies()
        self.set_seg_props()  # set segment properties by creating Morphologies
        # self.set_tar_segs()  # set target segments needed for computing the synaptic innervations
        self.calc_seg_coords()  # use for computing the ECP
        self._cells_built = True
Exemplo n.º 2
0
Arquivo: io.py Projeto: johnsonc/bmtk
def setup_output_dir(conf):
    start_from_state =False
    if start_from_state:  # starting from a previously saved state
        try:
            assert os.path.exists(conf["output"]["output_dir"])
            print2log0('Will run simulation from a previously saved state...')
        except:
            print('ERROR: directory with the initial state does not exist')
            nrn.quit_execution()

    elif not start_from_state:  # starting from a new (init) state
        if int(pc.id()) == 0:
            if os.path.exists(conf["output"]["output_dir"]):
                if conf["run"]['overwrite_output_dir']:
                    shutil.rmtree(conf["output"]["output_dir"])
                    print('Overwriting the output directory %s:' %conf["output"]["output_dir"]) # must print to stdout because the log file is not created yet
                else:
                    print('ERROR: Directory already exists')
                    print("To overwrite existing output_dir set 'overwrite_output_dir': True")
                    nrn.quit_execution()

            os.makedirs(conf["output"]["output_dir"])
            os.makedirs(conf["output"]["cell_vars_dir"])

            create_log(conf)
            config.copy(conf)

        pc.barrier()

    print2log0('Output directory: %s' % conf["output"]["output_dir"])
    print2log0('Config file: %s' % conf["config_path"])
Exemplo n.º 3
0
def run(config_file):
    conf = config.from_json(config_file)
    io.setup_output_dir(conf)
    nrn.load_neuron_modules(conf)
    graph = BioGraph.from_config(conf, property_schema=AIPropertySchema)
    net = BioNetwork.from_config(conf, graph)
    sim = Simulation.from_config(conf, network=net)
    sim.run()
    nrn.quit_execution()
Exemplo n.º 4
0
def load_csv(fullpath):
    """Load a csv file
    :param fullpath: path to the file name to be loaded
    :return: pandas dataframe
    """
    try:
        data = pd.read_csv(fullpath, sep=' ')
        return data
    except IOError:
        print2log0("ERROR: cannot open {}".format(fullpath))
        nrn.quit_execution()
Exemplo n.º 5
0
def load_h5(file_name):
    """load hdf5 file into memory
    :param file_name: full path to h5 file
    :return: file handle to hdf5 object
    """
    assert (os.path.exists(file_name))
    try:
        data_handle = h5py.File(file_name, 'r')
        return data_handle
    except IOError:
        print2log0("ERROR: cannot open {}".format(file_name))
        nrn.quit_execution()
Exemplo n.º 6
0
def load_json(fullpath):
    """Tries to load a json file
    :param fullpath: path to file name to be loaded
    :return: json dictionary object
    """
    try:
        with open(fullpath, 'r') as f:
            data = json.load(f)
            return data
    except IOError:
        print2log0("ERROR: cannot open {}".format(fullpath))
        nrn.quit_execution()
Exemplo n.º 7
0
def run(config_file):
    conf = config.from_json(config_file)  # build configuration
    io.setup_output_dir(conf)  # set up output directories
    nrn.load_neuron_modules(conf)  # load NEURON modules and mechanisms
    graph = BioGraph.from_config(conf,
                                 network_format=TabularNetwork_AI,
                                 property_schema=AIPropertySchema)

    net = BioNetwork.from_config(conf, graph)  # create network of in NEURON
    sim = Simulation(conf, network=net)  # initialize a simulation
    sim.attach_current_clamp()
    sim.set_recordings(
    )  # set recordings of relevant variables to be saved as an ouput
    sim.run()  # run simulation

    nrn.quit_execution()  # exit
Exemplo n.º 8
0
def run(config_file):
    conf = config.from_json(config_file)  # build configuration
    io.setup_output_dir(conf)  # set up output directories
    nrn.load_neuron_modules(conf)  # load NEURON modules and mechanisms
    nrn.load_py_modules(
        cell_models=set_cell_params,  # load custom Python modules
        syn_models=set_syn_params,
        syn_weights=set_weights)

    graph = BioGraph.from_config(
        conf,  # create network graph containing parameters of the model
        network_format=TabularNetwork_AI,
        property_schema=AIPropertySchema)

    net = BioNetwork.from_config(
        conf, graph
    )  # create netwosim = Simulation.from_config(conf, network=net)  rk of in NEURON
    sim = Simulation.from_config(conf, network=net)  # initialize a simulation
    sim.run()  # run simulation

    if MPI_RANK == 0:
        try:
            # Check spikes
            print2log0('Checking spike times')
            assert (os.path.exists(conf['output']['spikes_ascii_file']))
            assert (spike_files_equal(conf['output']['spikes_ascii_file'],
                                      'expected/spikes.txt'))
            print2log0('Spikes passed!')

            # Check extracellular recordings
            print2log0('Checking ECP output')
            check_ecp()
            print2log0('ECP passed!')

            # Check saved variables
            print2log0('Checking NEURON saved variables')
            for saved_gids in conf['node_id_selections']['save_cell_vars']:
                check_cellvars(saved_gids, conf)
            print2log0('variables passed!')
        except AssertionError:
            _, _, tb = sys.exc_info()
            traceback.print_tb(tb)

    pc.barrier()
    nrn.quit_execution()  # exit
Exemplo n.º 9
0
def run(config_file):
    conf = config.from_json(config_file)  # build configuration
    io.setup_output_dir(conf)  # set up output directories
    nrn.load_neuron_modules(conf)  # load NEURON modules and mechanisms
    nrn.load_py_modules(
        cell_models=set_cell_params,  # load custom Python modules
        syn_models=set_syn_params,
        syn_weights=set_weights)

    graph = BioGraph.from_config(
        conf)  # create network graph containing parameters of the model

    net = BioNetwork.from_config(conf, graph)  # create network of in NEURON
    sim = Simulation.from_config(conf, net)  # initialize a simulation
    # sim.set_recordings()                        # set recordings of relevant variables to be saved as an ouput
    sim.run()  # run simulation

    assert (os.path.exists(conf['output']['spikes_ascii_file']))
    assert (spike_files_equal(conf['output']['spikes_ascii_file'],
                              'expected/spikes.txt'))
    nrn.quit_execution()  # exit
Exemplo n.º 10
0
def run(config_file):
    conf = config.from_json(config_file)  # build configuration
    io.setup_output_dir(conf)  # set up output directories
    nrn.load_neuron_modules(conf)  # load NEURON modules and mechanisms
    nrn.load_py_modules(
        cell_models=set_cell_params,  # load custom Python modules
        syn_models=set_syn_params,
        syn_weights=set_weights)

    graph = BioGraph.from_config(
        conf,  # create network graph containing parameters of the model
        network_format=TabularNetwork_AI,
        property_schema=AIPropertySchema)

    net = BioNetwork.from_config(
        conf, graph
    )  # create netwosim = Simulation.from_config(conf, network=net)  rk of in NEURON
    sim = Simulation.from_config(conf, network=net)  # initialize a simulation
    # sim.set_recordings()                        # set recordings of relevant variables to be saved as an ouput
    sim.run()  # run simulation

    assert (os.path.exists(conf['output']['spikes_ascii_file']))
    assert (spike_files_equal(conf['output']['spikes_ascii_file'],
                              'expected/spikes.txt'))

    # Test the results of the ecp
    SAMPLE_SIZE = 100
    expected_h5 = h5py.File('expected/ecp.h5', 'r')
    nrows, ncols = expected_h5['ecp'].shape
    expected_mat = np.matrix(expected_h5['ecp'])
    results_h5 = h5py.File('output/ecp.h5', 'r')
    assert ('ecp' in results_h5.keys())
    results_mat = np.matrix(results_h5['ecp'][:])

    assert (results_h5['ecp'].shape == (nrows, ncols))
    for i, j in zip(randint(0, nrows, size=SAMPLE_SIZE),
                    randint(0, ncols, size=SAMPLE_SIZE)):
        assert (results_mat[i, j] == expected_mat[i, j])

    nrn.quit_execution()  # exit
Exemplo n.º 11
0
def run(config_file):
    conf = config.from_json(config_file)  # build configuration
    io.setup_output_dir(conf)  # set up output directories
    nrn.load_neuron_modules(conf)  # load NEURON modules and mechanisms
    nrn.load_py_modules(
        cell_models=set_cell_params,  # load custom Python modules
        syn_models=set_syn_params,
        syn_weights=set_weights)

    graph = BioGraph.from_config(
        conf,  # create network graph containing parameters of the model
        network_format=TabularNetwork_AI,
        property_schema=AIPropertySchema)

    net = BioNetwork.from_config(conf, graph)
    sim = Simulation.from_config(conf, network=net)
    sim.run()

    assert (os.path.exists(conf['output']['spikes_ascii_file']))
    assert (spike_files_equal(conf['output']['spikes_ascii_file'],
                              'expected/spikes.txt'))
    nrn.quit_execution()  # exit
Exemplo n.º 12
0
def run(config_file):
    conf = config.from_json(config_file)  # build configuration
    io.setup_output_dir(conf)  # set up output directories
    nrn.load_neuron_modules(conf)  # load NEURON modules and mechanisms
    nrn.load_py_modules(
        cell_models=set_cell_params,  # load custom Python modules
        syn_models=set_syn_params,
        syn_weights=set_weights)

    graph = BioGraph.from_config(
        conf,  # create network graph containing parameters of the model
        #network_format=TabularNetwork_AI,
        property_schema=AIPropertySchema)
    '''
    graph = BioGraph.from_config(conf)
    '''

    net = BioNetwork.from_config(conf, graph)  # create network of in NEURON
    sim = Simulation(conf, network=net)  # initialize a simulation
    sim.set_recordings(
    )  # set recordings of relevant variables to be saved as an ouput
    sim.run()  # run simulation

    nrn.quit_execution()  # exit