コード例 #1
0
ファイル: biosimulator.py プロジェクト: chaitanyagoswami/bmtk
    def from_config(cls, config, network, set_recordings=True):
        # TODO: convert from json to sonata config if necessary

        #The network must be built before initializing the simulator because
        #gap junctions must be set up before the simulation is initialized.
        network.io.log_info('Building cells.')
        network.build_nodes()

        network.io.log_info('Building recurrent connections')
        network.build_recurrent_edges()

        sim = cls(network=network,
                  dt=config.dt,
                  tstop=config.tstop,
                  v_init=config.v_init,
                  celsius=config.celsius,
                  nsteps_block=config.block_step)

        # TODO: Need to create a gid selector
        for sim_input in inputs.from_config(config):
            try:
                network.get_node_set(sim_input.node_set)
            except:
                print(
                    "Parameter node_set must be given in inputs module of simulation_config file. If unsure of what node_set should be, set it to 'all'."
                )
            node_set = network.get_node_set(sim_input.node_set)
            if sim_input.input_type == 'spikes':
                io.log_info('Building virtual cell stimulations for {}'.format(
                    sim_input.name))
                path = sim_input.params['input_file']
                spikes = SpikeTrains.load(path=path,
                                          file_type=sim_input.module,
                                          **sim_input.params)
                network.add_spike_trains(spikes, node_set)

            elif sim_input.module == "FileIClamp":
                sim.attach_file_current_clamp(sim_input.params["input_file"])

            elif sim_input.module == 'IClamp':
                # TODO: Parse from csv file
                try:
                    len(sim_input.params['amp'])
                except:
                    sim_input.params['amp'] = [float(sim_input.params['amp'])]
                if len(sim_input.params['amp']) > 1:
                    sim_input.params['amp'] = [
                        float(i) for i in sim_input.params['amp']
                    ]

                try:
                    len(sim_input.params['delay'])
                except:
                    sim_input.params['delay'] = [
                        float(sim_input.params['delay'])
                    ]
                if len(sim_input.params['delay']) > 1:
                    sim_input.params['delay'] = [
                        float(i) for i in sim_input.params['delay']
                    ]

                try:
                    len(sim_input.params['duration'])
                except:
                    sim_input.params['duration'] = [
                        float(sim_input.params['duration'])
                    ]
                if len(sim_input.params['duration']) > 1:
                    sim_input.params['duration'] = [
                        float(i) for i in sim_input.params['duration']
                    ]

                amplitude = sim_input.params['amp']
                delay = sim_input.params['delay']
                duration = sim_input.params['duration']

                try:
                    sim_input.params['gids']
                except:
                    sim_input.params['gids'] = None
                if sim_input.params['gids'] is not None:
                    gids = sim_input.params['gids']
                else:
                    gids = list(node_set.gids())

                sim.attach_current_clamp(amplitude, delay, duration, gids)

            elif sim_input.module == "SEClamp":
                try:
                    len(sim_input.params['amps'])
                except:
                    sim_input.params['amps'] = [
                        float(sim_input.params['amps'])
                    ]

                try:
                    len(sim_input.params['durations'])
                except:
                    sim_input.params['durations'] = [
                        float(sim_input.params['durations'])
                    ]

                amplitudes = sim_input.params['amps']
                durations = sim_input.params['durations']
                rs = None

                if "rs" in sim_input.params.keys():
                    try:
                        len(sim_input.params['rs'])
                    except:
                        sim_input.params['rs'] = [
                            float(sim_input.params['rs'])
                        ]
                    if len(sim_input.params['rs']) > 1:
                        sim_input.params['rs'] = [
                            float(i) for i in sim_input.params['rs']
                        ]
                    rs = sim_input.params["rs"]

                try:
                    sim_input.params['gids']
                except:
                    sim_input.params['gids'] = None
                if sim_input.params['gids'] is not None:
                    gids = sim_input.params['gids']
                else:
                    gids = list(node_set.gids())

                sim.attach_se_voltage_clamp(amplitudes, durations, gids, rs)

            elif sim_input.module == 'xstim':
                sim.add_mod(mods.XStimMod(**sim_input.params))

            else:
                io.log_exception('Can not parse input format {}'.format(
                    sim_input.name))

        # Parse the "reports" section of the config and load an associated output module for each report
        sim_reports = reports.from_config(config)
        for report in sim_reports:
            if isinstance(report, reports.SpikesReport):
                mod = mods.SpikesMod(**report.params)

            elif report.module == 'netcon_report':
                mod = mods.NetconReport(**report.params)

            elif isinstance(report, reports.MembraneReport):
                if report.params['sections'] == 'soma':
                    mod = mods.SomaReport(**report.params)

                else:
                    mod = mods.MembraneReport(**report.params)
            elif isinstance(report, reports.ClampReport):
                mod = mods.ClampReport(**report.params)

            elif isinstance(report, reports.ECPReport):
                mod = mods.EcpMod(**report.params)
                # Set up the ability for ecp on all relevant cells
                # TODO: According to spec we need to allow a different subset other than only biophysical cells
                for gid, cell in network.cell_type_maps('biophysical').items():
                    cell.setup_ecp()

            elif report.module == 'save_synapses':
                mod = mods.SaveSynapses(**report.params)

            else:
                # TODO: Allow users to register customized modules using pymodules
                io.log_warning('Unrecognized module {}, skipping.'.format(
                    report.module))
                continue

            sim.add_mod(mod)

        return sim
コード例 #2
0
ファイル: biosimulator.py プロジェクト: VBaratham/bmtk
    def from_config(cls, config, network, set_recordings=True):
        # TODO: convert from json to sonata config if necessary

        sim = cls(network=network,
                  dt=config.dt,
                  tstop=config.tstop,
                  v_init=config.v_init,
                  celsius=config.celsius,
                  cao0=config.cao0,
                  optocell=config.optocell,
                  nsteps_block=config.block_step)

        network.io.log_info('Building cells.')
        network.build_nodes()

        network.io.log_info('Building recurrent connections')
        network.build_recurrent_edges()

        # TODO: Need to create a gid selector
        for sim_input in inputs.from_config(config):
            node_set = network.get_node_set(sim_input.node_set)
            if sim_input.input_type == 'spikes':
                spikes = spike_trains.SpikesInput.load(
                    name=sim_input.name,
                    module=sim_input.module,
                    input_type=sim_input.input_type,
                    params=sim_input.params)
                io.log_info('Build virtual cell stimulations for {}'.format(
                    sim_input.name))
                network.add_spike_trains(spikes, node_set)

            elif sim_input.module == 'IClamp':
                # TODO: Parse from csv file
                amplitude = sim_input.params['amp']
                delay = sim_input.params['delay']
                duration = sim_input.params['duration']
                gids = sim_input.params['node_set']
                sim.attach_current_clamp(amplitude, delay, duration, node_set)

            elif sim_input.module == 'xstim':
                sim.add_mod(mods.XStimMod(**sim_input.params))

            else:
                io.log_exception('Can not parse input format {}'.format(
                    sim_input.name))

        if config.calc_ecp:
            for gid, cell in network.cell_type_maps('biophysical').items():
                cell.setup_ecp()
            sim.h.cvode.use_fast_imem(1)

        # Parse the "reports" section of the config and load an associated output module for each report
        sim_reports = reports.from_config(config)
        for report in sim_reports:
            if isinstance(report, reports.SpikesReport):
                mod = mods.SpikesMod(**report.params)

            elif isinstance(report, reports.SectionReport):
                mod = mods.SectionReport(**report.params)

            elif isinstance(report, reports.MembraneReport):
                if report.params['sections'] == 'soma':
                    mod = mods.SomaReport(**report.params)

                else:
                    mod = mods.MembraneReport(**report.params)

            elif isinstance(report, reports.ECPReport):
                assert config.calc_ecp
                mod = mods.EcpMod(**report.params)
                # Set up the ability for ecp on all relevant cells
                # TODO: According to spec we need to allow a different subset other than only biophysical cells
                # for gid, cell in network.cell_type_maps('biophysical').items():
                #     cell.setup_ecp()

            elif report.module == 'save_synapses':
                mod = mods.SaveSynapses(**report.params)

            else:
                # TODO: Allow users to register customized modules using pymodules
                io.log_warning('Unrecognized module {}, skipping.'.format(
                    report.module))
                continue

            sim.add_mod(mod)

        return sim
コード例 #3
0
ファイル: biosimulator.py プロジェクト: shixnya/bmtk
    def from_config(cls, config, network, set_recordings=True):
        simulation_inputs = inputs.from_config(config)

        # Special case for setting synapses to spontaneously (for a given set of pre-synaptic cell-types). Using this
        # input will change the way the network builds cells/connections and thus needs to be set first.
        for sim_input in simulation_inputs:
            if sim_input.input_type == 'syn_activity':
                network.set_spont_syn_activity(
                    precell_filter=sim_input.params['precell_filter'],
                    timestamps=sim_input.params['timestamps']
                )

        # The network must be built before initializing the simulator because
        # gap junctions must be set up before the simulation is initialized.
        network.io.log_info('Building cells.')
        network.build_nodes()

        network.io.log_info('Building recurrent connections')
        network.build_recurrent_edges()

        sim = cls(network=network,
                  dt=config.dt,
                  tstop=config.tstop,
                  v_init=config.v_init,
                  celsius=config.celsius,
                  nsteps_block=config.block_step)

        # TODO: Need to create a gid selector
        for sim_input in inputs.from_config(config):
            try:
                network.get_node_set(sim_input.node_set)
            except:
                print("Parameter node_set must be given in inputs module of simulation_config file. If unsure of what node_set should be, set it to 'all'.")
            node_set = network.get_node_set(sim_input.node_set)
            if sim_input.input_type == 'spikes':
                io.log_info('Building virtual cell stimulations for {}'.format(sim_input.name))
                path = sim_input.params['input_file']
                spikes = SpikeTrains.load(path=path, file_type=sim_input.module, **sim_input.params)
                network.add_spike_trains(spikes, node_set)

            elif sim_input.module == "FileIClamp":
                sim.attach_file_current_clamp(sim_input.params["input_file"])

            elif sim_input.module == 'IClamp':
                # TODO: Parse from csv file
                try: 
                    len(sim_input.params['amp'])
                except:
                    sim_input.params['amp']=[float(sim_input.params['amp'])]
                if len(sim_input.params['amp'])>1:
                    sim_input.params['amp']=[float(i) for i in sim_input.params['amp']]

                try: 
                    len(sim_input.params['delay'])
                except:
                    sim_input.params['delay']=[float(sim_input.params['delay'])]
                if len(sim_input.params['delay'])>1:
                    sim_input.params['delay']=[float(i) for i in sim_input.params['delay']]
                
                try: 
                    len(sim_input.params['duration'])
                except:
                    sim_input.params['duration']=[float(sim_input.params['duration'])]
                if len(sim_input.params['duration'])>1:
                    sim_input.params['duration']=[float(i) for i in sim_input.params['duration']]
                    
                amplitude = sim_input.params['amp']
                delay = sim_input.params['delay']
                duration = sim_input.params['duration']

                # specificed for location to place iclamp hobj.<section_name>[<section_index>](<section_dist>). The
                # default is hobj.soma[0](0.5), the center of the soma
                section_name = sim_input.params.get('section_name', 'soma')
                section_index = sim_input.params.get('section_index', 0)
                section_dist = sim_input.params.get('section_dist', 0.5)

                # section_name = section_name if isinstance(section_name, (list, tuple)) else [section_name]
                # section_index = section_index if isinstance(section_index, (list, tuple)) else [section_index]
                # section_dist = section_dist if isinstance(section_dist, (list, tuple)) else [section_dist]

                try:
                    sim_input.params['gids']
                except:
                    sim_input.params['gids'] = None
                if sim_input.params['gids'] is not None:
                    gids = sim_input.params['gids']
                else:
                    gids = list(node_set.gids())

                sim.attach_current_clamp(amplitude, delay, duration, gids, section_name, section_index, section_dist)

            elif sim_input.module == "SEClamp":
                try: 
                    len(sim_input.params['amps'])
                except:
                    sim_input.params['amps']=[float(sim_input.params['amps'])]
                
                try: 
                    len(sim_input.params['durations'])
                except:
                    sim_input.params['durations']=[float(sim_input.params['durations'])]
                    
                amplitudes = sim_input.params['amps']
                durations = sim_input.params['durations']
                rs = None

                if "rs" in sim_input.params.keys():
                    try: 
                        len(sim_input.params['rs'])
                    except:
                        sim_input.params['rs']=[float(sim_input.params['rs'])]
                    if len(sim_input.params['rs'])>1:
                        sim_input.params['rs']=[float(i) for i in sim_input.params['rs']]
                    rs = sim_input.params["rs"]
                                   
                try:
                    sim_input.params['gids']
                except:
                    sim_input.params['gids'] = None
                if sim_input.params['gids'] is not None:
                    gids = sim_input.params['gids']
                else:
                    gids = list(node_set.gids())

                sim.attach_se_voltage_clamp(amplitudes, durations, gids, rs)

            elif sim_input.module == 'xstim':
                sim.add_mod(mods.XStimMod(**sim_input.params))

            elif sim_input.module == 'syn_activity':
                pass

            else:
                io.log_exception('Can not parse input format {}'.format(sim_input.name))

        # Parse the "reports" section of the config and load an associated output module for each report
        sim_reports = reports.from_config(config)
        for report in sim_reports:
            if isinstance(report, reports.SpikesReport):
                mod = mods.SpikesMod(**report.params)

            elif report.module == 'netcon_report':
                mod = mods.NetconReport(**report.params)

            elif isinstance(report, reports.MembraneReport):
                if report.params['sections'] == 'soma':
                    mod = mods.SomaReport(**report.params)

                else:
                    mod = mods.MembraneReport(**report.params)
            elif isinstance(report, reports.ClampReport):
                mod = mods.ClampReport(**report.params)

            elif isinstance(report, reports.ECPReport):
                mod = mods.EcpMod(**report.params)
                # Set up the ability for ecp on all relevant cells
                # TODO: According to spec we need to allow a different subset other than only biophysical cells
                for gid, cell in network.cell_type_maps('biophysical').items():
                    cell.setup_ecp()

            elif report.module == 'save_synapses':
                mod = mods.SaveSynapses(**report.params)

            else:
                # TODO: Allow users to register customized modules using pymodules
                io.log_warning('Unrecognized module {}, skipping.'.format(report.module))
                continue

            sim.add_mod(mod)

        return sim