ALLEN INSTITUTE

# bmtk.simulator.bionet.modules package

## Submodules

## bmtk.simulator.bionet.modules.comsol module

class bmtk.simulator.bionet.modules.comsol.ComsolMod(comsol_files, waveforms=None, amplitudes=1, cells=None, set_nrn_mechanisms=True, node_set=None)

  Bases: `SimulatorMod`

  This module takes extracellular potentials that were calculated in COMSOL and imposes them on a biophysically detailed network. It is similar to BioNet’s xstim module, but offers the additional flexibility of FEM, instead of relying on simplified analytical solutions. As such, this module allows to use BMTK as a part of the hybrid modelling approach, where extracellular potentials are calculated using FEM in a first step and then imposed on a model of a neuronal network in a second step.

  initialize(sim)

    Checks if a waveform argument was passed which determines how to comsol.txt and waveform.csv should be treated. If no waveform is specified:

    > Loads COMSOL output Sets up nearest neighbour interpolation object (for spatial interpolation) Performs temporal interpolation so COMSOL and BMTK timings match.

    If one or more waveforms are specified:
      Iterates over COMSOL outputs:

        Loads COMSOL output Iterates over cells:

        > Retrieves potentials at each segment via spatial interpolation

    Parameters:

      sim – Simulation object

  load_comsol(comsol_file)

    Extracts data and headers from comsol.txt. Returns pandas DataFrame. The first three columns are the x-, y-, and z-coordinates of the solution nodes. For a stationary comsol study, the potentials are stored in the fourth column. For a time-dependent study, each subsequent column stores the potentials at one timepoints.

    Parameters:

      comsol_file – (str) “/path/to/comsol.txt”

    Returns:

      (pd DataFrame) Potentials extracted from comsol.txt

  step(sim, tstep)

    Checks if a waveform argument was passed which determines how potentials should be retrieved. Iterates over all cells:

    > If no waveform is specified:

    >   Retrieves nearest neighbour with interpolator Looks up potentials (for each segment of the cell) in comsol data at current time

    > If one or more waveforms are specified:

    >   Initialises extracellular potential v_ext at 0 Iterates over COMSOL outputs (thus making a linear combination of several FEM solutions):

    >   > Calls interpolated potentials Multiplies by corresponding waveform value at current time and by corresponding amplitude Adds to v_ext

    Parameters:

      - sim – Simulation object

      - tstep – (int) timestep

## bmtk.simulator.bionet.modules.ecephys_module module

class bmtk.simulator.bionet.modules.ecephys_module.BioECEphysUnitsModule(name, **kwargs)

  Bases: `ECEphysUnitsModule`

  initialize(sim)

    Will be called once at the beginning of the simulation run, after the network and simulation parameters have all been finalized.

    Parameters:

      sim – Simulation object

## bmtk.simulator.bionet.modules.ecp module

class bmtk.simulator.bionet.modules.ecp.EcpMod(tmp_dir, file_name, electrode_positions, contributions_dir=None, cells=None, variable_name='v', electrode_channels=None, cell_bounds=None, minimum_distance=None)

  Bases: `SimulatorMod`

  block(sim, block_interval)

    This method is called once after every block of time, as specified by the configuration.

    Unlike the step method which is called during every time-step, the block method will typically be called only a few times over the entire simulation. The block method is preferable for accessing and saving to the disk, summing up existing data, or similar functionality

    Parameters:

      - sim – Simulation object

      - block_interval – The time interval (tstep_start, tstep_end) for which the block is being called on.

  finalize(sim)

    Call once at the very end of the simulation.

    Parameters:

      sim – Simulation object

  initialize(sim)

    Will be called once at the beginning of the simulation run, after the network and simulation parameters have all been finalized.

    Parameters:

      sim – Simulation object

  step(sim, tstep)

    Called on every single time step (dt).

    The step method is used for anything that should be recorded or changed continously. dt is determined during the setup, and the sim parameter can be used to access simulation, network and individual cell properties

    Parameters:

      - sim – Simulation object.

      - tstep – The decrete time-step

class bmtk.simulator.bionet.modules.ecp.RecXElectrode(positions, minimum_distance)

  Bases: `object`

  Extracellular electrode

  calc_transfer_resistance(gid, seg_coords)

    Precompute mapping from segment to electrode locations

  drift()
  get_transfer_resistance(gid)

## bmtk.simulator.bionet.modules.iclamp module

class bmtk.simulator.bionet.modules.iclamp.AmpsReaderNRN(**args)

  Bases: `AmpsReader`

  create_clamps(hobj)

class bmtk.simulator.bionet.modules.iclamp.CSVAmpReaderNRN(**args)

  Bases: `CSVAmpReader`

  create_clamps(hobj)

class bmtk.simulator.bionet.modules.iclamp.IClampMod(input_type, **mod_args)

  Bases: `IClampMod`

  initialize(sim)

    Will be called once at the beginning of the simulation run, after the network and simulation parameters have all been finalized.

    Parameters:

      sim – Simulation object

  property input2reader_map

class bmtk.simulator.bionet.modules.iclamp.NWBReaderNRN(**args)

  Bases: `NWBReader`

  create_clamps(hobj)

## bmtk.simulator.bionet.modules.record_cellvars module

class bmtk.simulator.bionet.modules.record_cellvars.MembraneReport(tmp_dir, file_name, variable_name, cells=None, gids=None, sections='all', buffer_data=True, transform={}, **kwargs)

  Bases: `SimulatorMod`

  block(sim, block_interval)

    This method is called once after every block of time, as specified by the configuration.

    Unlike the step method which is called during every time-step, the block method will typically be called only a few times over the entire simulation. The block method is preferable for accessing and saving to the disk, summing up existing data, or similar functionality

    Parameters:

      - sim – Simulation object

      - block_interval – The time interval (tstep_start, tstep_end) for which the block is being called on.

  finalize(sim)

    Call once at the very end of the simulation.

    Parameters:

      sim – Simulation object

  initialize(sim)

    Will be called once at the beginning of the simulation run, after the network and simulation parameters have all been finalized.

    Parameters:

      sim – Simulation object

  step(sim, tstep)

    Called on every single time step (dt).

    The step method is used for anything that should be recorded or changed continously. dt is determined during the setup, and the sim parameter can be used to access simulation, network and individual cell properties

    Parameters:

      - sim – Simulation object.

      - tstep – The decrete time-step

class bmtk.simulator.bionet.modules.record_cellvars.SomaReport(tmp_dir, file_name, variable_name, cells, sections='soma', buffer_data=True, transform={}, **kwargs)

  Bases: `MembraneReport`

  Special case for when only needing to save the soma variable

  initialize(sim)

    Will be called once at the beginning of the simulation run, after the network and simulation parameters have all been finalized.

    Parameters:

      sim – Simulation object

  step(sim, tstep, rel_time=0.0)

    Called on every single time step (dt).

    The step method is used for anything that should be recorded or changed continously. dt is determined during the setup, and the sim parameter can be used to access simulation, network and individual cell properties

    Parameters:

      - sim – Simulation object.

      - tstep – The decrete time-step

bmtk.simulator.bionet.modules.record_cellvars.first_element(lst)

## bmtk.simulator.bionet.modules.record_clamp module

class bmtk.simulator.bionet.modules.record_clamp.ClampReport(tmp_dir, file_name, variable_name, buffer_data=True, **kwargs)

  Bases: `SimulatorMod`

  block(sim, block_interval)

    This method is called once after every block of time, as specified by the configuration.

    Unlike the step method which is called during every time-step, the block method will typically be called only a few times over the entire simulation. The block method is preferable for accessing and saving to the disk, summing up existing data, or similar functionality

    Parameters:

      - sim – Simulation object

      - block_interval – The time interval (tstep_start, tstep_end) for which the block is being called on.

  finalize(sim)

    Call once at the very end of the simulation.

    Parameters:

      sim – Simulation object

  initialize(sim, clamps)

    Will be called once at the beginning of the simulation run, after the network and simulation parameters have all been finalized.

    Parameters:

      sim – Simulation object

  merge()
  step(sim, tstep)

    Called on every single time step (dt).

    The step method is used for anything that should be recorded or changed continously. dt is determined during the setup, and the sim parameter can be used to access simulation, network and individual cell properties

    Parameters:

      - sim – Simulation object.

      - tstep – The decrete time-step

  property variable

## bmtk.simulator.bionet.modules.record_netcons module

class bmtk.simulator.bionet.modules.record_netcons.NetconReport(tmp_dir, file_name, variable_name, cells, sections='all', syn_type='Exp2Syn', buffer_data=True, transform={}, **kwargs)

  Bases: `SimulatorMod`

  block(sim, block_interval)

    This method is called once after every block of time, as specified by the configuration.

    Unlike the step method which is called during every time-step, the block method will typically be called only a few times over the entire simulation. The block method is preferable for accessing and saving to the disk, summing up existing data, or similar functionality

    Parameters:

      - sim – Simulation object

      - block_interval – The time interval (tstep_start, tstep_end) for which the block is being called on.

  finalize(sim)

    Call once at the very end of the simulation.

    Parameters:

      sim – Simulation object

  initialize(sim)

    Will be called once at the beginning of the simulation run, after the network and simulation parameters have all been finalized.

    Parameters:

      sim – Simulation object

  step(sim, tstep)

    Called on every single time step (dt).

    The step method is used for anything that should be recorded or changed continously. dt is determined during the setup, and the sim parameter can be used to access simulation, network and individual cell properties

    Parameters:

      - sim – Simulation object.

      - tstep – The decrete time-step

## bmtk.simulator.bionet.modules.record_spikes module

class bmtk.simulator.bionet.modules.record_spikes.SpikesMod(tmp_dir, spikes_file_csv=None, spikes_file=None, spikes_file_nwb=None, cache_to_disk=True, spikes_sort_order=None, mode='a', compression='gzip')

  Bases: `SimulatorMod`

  Module use for saving spikes

  block(sim, block_interval)

    This method is called once after every block of time, as specified by the configuration.

    Unlike the step method which is called during every time-step, the block method will typically be called only a few times over the entire simulation. The block method is preferable for accessing and saving to the disk, summing up existing data, or similar functionality

    Parameters:

      - sim – Simulation object

      - block_interval – The time interval (tstep_start, tstep_end) for which the block is being called on.

  finalize(sim)

    Call once at the very end of the simulation.

    Parameters:

      sim – Simulation object

  initialize(sim)

    Will be called once at the beginning of the simulation run, after the network and simulation parameters have all been finalized.

    Parameters:

      sim – Simulation object

## bmtk.simulator.bionet.modules.save_synapses module

class bmtk.simulator.bionet.modules.save_synapses.ConnectionWriter(network_dir)

  Bases: `object`

  class H5Index(file_path, src_pop, trg_pop)

    Bases: `object`

    add_bio_conn(edge_type_id, src_id, trg_id, syn_weight, sec_id, sec_x)
    add_point_conn(edge_type_id, src_id, trg_id, syn_weight)
    clean_ends()
    close_h5()
  add_bio_conn(edge_type_id, src_id, src_pop, trg_id, trg_pop, syn_weight, sec_id, sec_x)
  add_point_conn(edge_type_id, src_id, src_pop, trg_id, trg_pop, syn_weight)
  close()

class bmtk.simulator.bionet.modules.save_synapses.H5Merger(network_dir, grp_keys)

  Bases: `object`

class bmtk.simulator.bionet.modules.save_synapses.SaveSynapses(network_dir, single_file=False, **params)

  Bases: `SimulatorMod`

  initialize(sim)

    Will be called once at the beginning of the simulation run, after the network and simulation parameters have all been finalized.

    Parameters:

      sim – Simulation object

## bmtk.simulator.bionet.modules.seclamp module

class bmtk.simulator.bionet.modules.seclamp.SEClamp(input_type, **mod_args)

  Bases: `SimulatorMod`

  create_clamp(hobj)
  initialize(sim)

    Will be called once at the beginning of the simulation run, after the network and simulation parameters have all been finalized.

    Parameters:

      sim – Simulation object

  step(sim, tstep)

    Called on every single time step (dt).

    The step method is used for anything that should be recorded or changed continously. dt is determined during the setup, and the sim parameter can be used to access simulation, network and individual cell properties

    Parameters:

      - sim – Simulation object.

      - tstep – The decrete time-step

## bmtk.simulator.bionet.modules.sim_module module

class bmtk.simulator.bionet.modules.sim_module.SimulatorMod

  Bases: `object`

  Class for writing custom bionet functions that will be called during the simulation. To use overwrite one or more of the following methods in a subclass, and bionet will call the function at the appropiate time.

  To call during a simulation:

    … sim = Simulation(…) mymod = MyModule(…) sim.add_mod(mymod) sim.run()

  block(sim, block_interval)

    This method is called once after every block of time, as specified by the configuration.

    Unlike the step method which is called during every time-step, the block method will typically be called only a few times over the entire simulation. The block method is preferable for accessing and saving to the disk, summing up existing data, or similar functionality

    Parameters:

      - sim – Simulation object

      - block_interval – The time interval (tstep_start, tstep_end) for which the block is being called on.

  finalize(sim)

    Call once at the very end of the simulation.

    Parameters:

      sim – Simulation object

  initialize(sim)

    Will be called once at the beginning of the simulation run, after the network and simulation parameters have all been finalized.

    Parameters:

      sim – Simulation object

  step(sim, tstep)

    Called on every single time step (dt).

    The step method is used for anything that should be recorded or changed continously. dt is determined during the setup, and the sim parameter can be used to access simulation, network and individual cell properties

    Parameters:

      - sim – Simulation object.

      - tstep – The decrete time-step

## bmtk.simulator.bionet.modules.xstim module

class bmtk.simulator.bionet.modules.xstim.StimXElectrode(positions_file, waveform, mesh_files_dir, dt)

  Bases: `object`

  Extracellular Stimulating electrode

  calculate_waveforms(tstep)
  get_vext(gid)
  place_the_electrodes()
  read_electrode_mesh()
  rotate_the_electrodes()
  set_transfer_resistance(gid, seg_coords, rho=300.0)

class bmtk.simulator.bionet.modules.xstim.XStimMod(positions_file, waveform, mesh_files_dir=None, cells=None, set_nrn_mechanisms=True, resistance=300.0, node_set=None)

  Bases: `SimulatorMod`

  initialize(sim)

    Will be called once at the beginning of the simulation run, after the network and simulation parameters have all been finalized.

    Parameters:

      sim – Simulation object

  step(sim, tstep)

    Called on every single time step (dt).

    The step method is used for anything that should be recorded or changed continously. dt is determined during the setup, and the sim parameter can be used to access simulation, network and individual cell properties

    Parameters:

      - sim – Simulation object.

      - tstep – The decrete time-step

## bmtk.simulator.bionet.modules.xstim_waveforms module

class bmtk.simulator.bionet.modules.xstim_waveforms.BaseWaveform

  Bases: `object`

  Abstraction of waveform class to ensure calculate method is implemented

  calculate(simulation_time)

class bmtk.simulator.bionet.modules.xstim_waveforms.BaseWaveformType(waveform_config)

  Bases: `object`

  Specific waveform type

  is_active(simulation_time)

class bmtk.simulator.bionet.modules.xstim_waveforms.ComplexWaveform(el_collection)

  Bases: `BaseWaveform`

  Superposition of simple waveforms

  calculate(t)

class bmtk.simulator.bionet.modules.xstim_waveforms.WaveformCustom(waveform_file)

  Bases: `BaseWaveform`

  Custom waveform defined by csv file

  calculate(t)

class bmtk.simulator.bionet.modules.xstim_waveforms.WaveformTypeDC(waveform_config)

  Bases: `BaseWaveformType`, `BaseWaveform`

  DC (step) waveform

  calculate(t)

class bmtk.simulator.bionet.modules.xstim_waveforms.WaveformTypeSin(waveform_config)

  Bases: `BaseWaveformType`, `BaseWaveform`

  Sinusoidal waveform

  calculate(t)

bmtk.simulator.bionet.modules.xstim_waveforms.iclamp_waveform_factory(conf)

  Factory to create correct waveform class based on conf. Supports json config in conf as well as string pointer to a file. :rtype: BaseWaveformType

bmtk.simulator.bionet.modules.xstim_waveforms.stimx_waveform_factory(waveform)

  Factory to create correct waveform class based on conf. Supports json config in conf as well as string pointer to a file. :rtype: BaseWaveformType

## Module contents