ALLEN INSTITUTE

# bmtk.simulator.bionet package

## Subpackages

- bmtk.simulator.bionet.default_setters package
  - Submodules
  - bmtk.simulator.bionet.default_setters.cell_models module
    - `Biophys1()`
    - `Biophys1_dict()`
    - `Biophys1_nml()`
    - `IntFire1()`
    - `NMLLoad()`
    - `aibs_allactive()`
    - `aibs_allactive_directed()`
    - `aibs_perisomatic()`
    - `aibs_perisomatic_directed()`
    - `fix_axon_allactive()`
    - `fix_axon_allactive_directed()`
    - `fix_axon_peri()`
    - `fix_axon_perisomatic_directed()`
    - `get_axon_direction()`
    - `loadHOC()`
    - `set_extracellular()`
    - `set_params_allactive()`
    - `set_params_peri()`
  - bmtk.simulator.bionet.default_setters.synapse_models module
    - `Exp2Syn()`
    - `exp1isyn()`
    - `exp1syn()`
    - `exp2syn()`
    - `expsyn()`
    - `stp1syn()`
    - `stp2syn()`
    - `stp3syn()`
    - `stp4syn()`
    - `stp5isyn()`
    - `stp5syn()`
    - `tmgsyn()`
  - bmtk.simulator.bionet.default_setters.synaptic_weights module
    - `default_weight_fnc()`
    - `gaussianLL()`
    - `wmax()`
  - Module contents
- bmtk.simulator.bionet.modules package
  - Submodules
  - bmtk.simulator.bionet.modules.comsol module
    - `ComsolMod`
      - `ComsolMod.initialize()`
      - `ComsolMod.load_comsol()`
      - `ComsolMod.step()`
  - bmtk.simulator.bionet.modules.ecephys_module module
    - `BioECEphysUnitsModule`
      - `BioECEphysUnitsModule.initialize()`
  - bmtk.simulator.bionet.modules.ecp module
    - `EcpMod`
      - `EcpMod.block()`
      - `EcpMod.finalize()`
      - `EcpMod.initialize()`
      - `EcpMod.step()`
    - `RecXElectrode`
      - `RecXElectrode.calc_transfer_resistance()`
      - `RecXElectrode.drift()`
      - `RecXElectrode.get_transfer_resistance()`
  - bmtk.simulator.bionet.modules.iclamp module
    - `AmpsReaderNRN`
      - `AmpsReaderNRN.create_clamps()`
    - `CSVAmpReaderNRN`
      - `CSVAmpReaderNRN.create_clamps()`
    - `IClampMod`
      - `IClampMod.initialize()`
      - `IClampMod.input2reader_map`
    - `NWBReaderNRN`
      - `NWBReaderNRN.create_clamps()`
  - bmtk.simulator.bionet.modules.record_cellvars module
    - `MembraneReport`
      - `MembraneReport.block()`
      - `MembraneReport.finalize()`
      - `MembraneReport.initialize()`
      - `MembraneReport.step()`
    - `SomaReport`
      - `SomaReport.initialize()`
      - `SomaReport.step()`
    - `first_element()`
  - bmtk.simulator.bionet.modules.record_clamp module
    - `ClampReport`
      - `ClampReport.block()`
      - `ClampReport.finalize()`
      - `ClampReport.initialize()`
      - `ClampReport.merge()`
      - `ClampReport.step()`
      - `ClampReport.variable`
  - bmtk.simulator.bionet.modules.record_netcons module
    - `NetconReport`
      - `NetconReport.block()`
      - `NetconReport.finalize()`
      - `NetconReport.initialize()`
      - `NetconReport.step()`
  - bmtk.simulator.bionet.modules.record_spikes module
    - `SpikesMod`
      - `SpikesMod.block()`
      - `SpikesMod.finalize()`
      - `SpikesMod.initialize()`
  - bmtk.simulator.bionet.modules.save_synapses module
    - `ConnectionWriter`
      - `ConnectionWriter.H5Index`
      - `ConnectionWriter.add_bio_conn()`
      - `ConnectionWriter.add_point_conn()`
      - `ConnectionWriter.close()`
    - `H5Merger`
    - `SaveSynapses`
      - `SaveSynapses.initialize()`
  - bmtk.simulator.bionet.modules.seclamp module
    - `SEClamp`
      - `SEClamp.create_clamp()`
      - `SEClamp.initialize()`
      - `SEClamp.step()`
  - bmtk.simulator.bionet.modules.sim_module module
    - `SimulatorMod`
      - `SimulatorMod.block()`
      - `SimulatorMod.finalize()`
      - `SimulatorMod.initialize()`
      - `SimulatorMod.step()`
  - bmtk.simulator.bionet.modules.xstim module
    - `StimXElectrode`
      - `StimXElectrode.calculate_waveforms()`
      - `StimXElectrode.get_vext()`
      - `StimXElectrode.place_the_electrodes()`
      - `StimXElectrode.read_electrode_mesh()`
      - `StimXElectrode.rotate_the_electrodes()`
      - `StimXElectrode.set_transfer_resistance()`
    - `XStimMod`
      - `XStimMod.initialize()`
      - `XStimMod.step()`
  - bmtk.simulator.bionet.modules.xstim_waveforms module
    - `BaseWaveform`
      - `BaseWaveform.calculate()`
    - `BaseWaveformType`
      - `BaseWaveformType.is_active()`
    - `ComplexWaveform`
      - `ComplexWaveform.calculate()`
    - `WaveformCustom`
      - `WaveformCustom.calculate()`
    - `WaveformTypeDC`
      - `WaveformTypeDC.calculate()`
    - `WaveformTypeSin`
      - `WaveformTypeSin.calculate()`
    - `iclamp_waveform_factory()`
    - `stimx_waveform_factory()`
  - Module contents

## Submodules

## bmtk.simulator.bionet.biocell module

class bmtk.simulator.bionet.biocell.BioCell(node, population_name, bionetwork)

  Bases: `Cell`

  Implemntation of a morphologically and biophysically detailed type cell.

  build_morphology()
  connections()
  get_connection_info()
  get_im()

    Gather membrane currents from PtrVector into imVec (does not need a loop!)

  get_section(sec_id)
  get_sections()
  get_sections_id()
  init_connections()
  property morphology

    The actual Morphology object instanstiation

  property morphology_file

    Value that’s stored in SONATA morphology column

  print_synapses()
  property seg_coords

    Coordinates for segments/sections of the morphology, need to make public for ecp, xstim, and other functionality that needs to compute the soma/dendritic coordinates of each cell

  set_e_extracellular(vext)
  set_im_ptr()

    Set PtrVector to point to the _ref_i_membrane_ parameter

  set_ptr2e_extracellular()
  set_sec_array()

    Arrange sections in an array to be access by index

  set_spike_detector(spike_threshold)
  set_syn_connection(edge_prop, src_node, stim=None, gj_ids=None)
  setup_ecp()
  setup_xstim(set_nrn_mechanism=True)
  property soma

class bmtk.simulator.bionet.biocell.BioCellSpontSyn(node, population_name, bionetwork)

  Bases: `BioCell`

  Special class that allows certain synapses to spontaneously fire (without spiking) at a specific time.

class bmtk.simulator.bionet.biocell.ConnectionStruct(edge_prop, src_node, syn, connector, is_virtual=False, is_gap_junc=False)

  Bases: `object`

  property is_gap_junc
  property is_virtual
  property source_node
  property syn_weight

## bmtk.simulator.bionet.bionetwork module

class bmtk.simulator.bionet.bionetwork.BioNetwork

  Bases: `SimNetwork`

  add_nodes(node_population)
  add_spike_trains(spike_trains, node_set, spikes_generator=None, sim=None)
  build_nodes()
  build_recurrent_edges()
  build_replay_inputs(spike_trains, edges_path, edge_types_path, source_node_set, target_node_set)
  cell_type_maps(model_type)
  find_edges(source_nodes=None, target_nodes=None)
  get_cell_gid(gid)
  get_cell_node_id(population, node_id)
  get_disconnected_cell(population, node_id, spike_trains)
  get_gj_id(network, src_nid, trg_nid, source_gap)

    Returns the gap junction id for the given nodes on a given network.

    Parameters:

      source_gap – whether to return the id of the gap junction on the source node or the target node.

  get_local_cells()
  get_node_id(population, node_id)
  get_virtual_cells(population, node_id, spike_trains, spikes_generator=None, sim=None)
  property gid_pool
  property local_gids
  model_type_col = 'model_type'
  property py_function_caches
  set_spont_syn_activity(precell_filter, postcell_filter, timestamps)

## bmtk.simulator.bionet.biosimulator module

class bmtk.simulator.bionet.biosimulator.BioSimulator(network, dt, tstop, v_init, celsius, nsteps_block, start_from_state=False)

  Bases: `Simulator`

  Includes methods to run and control the simulation

  add_mod(module)
  attach_se_voltage_clamp(amplitudes, durations, gids, rs)
  property biophysical_gids
  property cell_var_output
  property cell_variables
  property celsius
  property dt
  classmethod from_config(config, network, set_recordings=True)
  property h
  property local_gids
  property n_steps
  property nsteps_block
  post_fadvance()

    Runs after every execution of fadvance (see advance.hoc) Called after every time step to perform computation and save data to memory block or to disk. The initial condition tstep=0 is not being saved

  report_load_balance()
  run()

    Run the simulation: if beginning from a blank state, then will use h.run(), if continuing from the saved state, then will use h.continuerun()

  set_spikes_recording()
  simulation_time(units='ms')
  property spikes_table
  property tstop
  property v_init

## bmtk.simulator.bionet.cell module

class bmtk.simulator.bionet.cell.Cell(node, population_name, network=None)

  Bases: `object`

  A abstract base class for any cell object.

  A base class for implementation of a cell-type objects like biophysical cells, LIF cells, etc. Do not instantiate a Cell object directly. Cell classes act as wrapper around HOC cell object with extra functionality for setting positions, synapses, and other parameters depending on the desired cell class.

  get_connection_info()
  get_section(sec_name, sec_index)
  property gid
  property group_id
  property hobj
  init_connections()
  property netcons
  property network_name
  property node
  property node_id
  scale_weights(factor)
  set_soma_position()
  set_syn_connections(edge_prop, src_node, stim=None)
  property soma_position

## bmtk.simulator.bionet.config module

class bmtk.simulator.bionet.config.Config(*args, **kwargs)

  Bases: `SimulationConfig`

  build_env()

    Creates the folder(s) set in ‘output’ section, sets up logging and copies over the configuration

  create_output_dir()
  load_nrn_modules()

## bmtk.simulator.bionet.gids module

class bmtk.simulator.bionet.gids.GidPool

  Bases: `object`

  add_pool(name, n_nodes)
  get_gid(name, node_id)
  get_pool_id(gid)

class bmtk.simulator.bionet.gids.PopulationID(node_id, population)

  Bases: `tuple`

  node_id

    Alias for field number 0

  population

    Alias for field number 1

## bmtk.simulator.bionet.iclamp module

class bmtk.simulator.bionet.iclamp.FileIClamp(amplitudes, dt, section_name='soma', section_index=0, section_dist=0.5)

  Bases: `object`

  attach_current(cell)

class bmtk.simulator.bionet.iclamp.IClamp(amplitude, delay, duration, section_name='soma', section_index=0, section_dist=0.5)

  Bases: `object`

  attach_current(cell)

## bmtk.simulator.bionet.io_tools module

class bmtk.simulator.bionet.io_tools.NEURONIOUtils

  Bases: `IOUtils`

  barrier()

    MPI Barrier call

## bmtk.simulator.bionet.morphology module

class bmtk.simulator.bionet.morphology.Morphology(hobj, rng_seed=None, swc_path=None)

  Bases: `object`

  choose_sections(section_names, distance_range, n_sections=1, cache=True)

    Similar to find_sections, but will only N=n_section number of sections_ids/x values randomly selected (may return less if there aren’t as many sections

    Parameters:

      - section_names – ‘soma’, ‘dend’, ‘apic’, ‘axon’

      - distance_range – [float, float]: distance range of sections from the soma, in um.

      - n_sections – int: maximum number of sections to select

      - cache – caches the segments + probs so that next time the same section_names/distance_range values are called it will return the same values without recalculating. default True.

    Returns:

      [int], [float]: A list of all section_ids and a list of all segment_x values (as defined by NEURON) that meet the given critera.

  find_sections(section_names, distance_range, cache=True)

    Retrieves a list of sections ids and section x’s given a section name/type (eg axon, soma, apic, dend) and the distance from the soma.

    Parameters:

      - section_names – A list of sections to target, ‘soma’, ‘dend’, ‘apic’, ‘axon’

      - distance_range – [float, float]: distance range of sections from the soma, in um.

      - cache – caches the segments + probs so that next time the same section_names/distance_range values are called it will return the same values without recalculating. default True.

    Returns:

      [float], [float]: A list of all section_ids and a list of all segment_x values (as defined by NEURON) that meet the given critera.

  get_coords(sec_id, sec_x)
  get_section(section_idx)
  get_swc_id(sec_id, sec_x)
  classmethod load(hobj=None, morphology_file=None, rng_seed=None, cache_seg_props=True)

    Factory method, perfered way to create a Morphology object

    Parameters:

      - hobj

      - morphology_file

      - rng_seed

      - cache_seg_props

    Returns:

  move_and_rotate(soma_coords=None, rotation_angles=None, inplace=False)
  property n_sections
  property nseg
  sec_type_swc = {'apic': 4, 'apical': 4, 'axon': 2, 'axonal': 2, 'basal': 3, 'dend': 3, 'soma': 1, 'somatic': 1}
  property sections
  property seg_coords

    Get the coordinates of all segments of the cells. Each segment is defined by three values, the beginning of the segment (seg_coords.p0), the middle of the segment(seg_coords.p05), and the end (seg_coords.p1).

  property seg_props
  property segments
  set_segment_dl(dl)

    Define number of segments in a cell

  property soma
  property soma_position
  property swc_map

bmtk.simulator.bionet.morphology.rotation_matrix(axis, theta)

  Return the rotation matrix associated with counterclockwise rotation about the given axis by theta radians.

## bmtk.simulator.bionet.nml_reader module

class bmtk.simulator.bionet.nml_reader.ChannelDensity(nml_element)

  Bases: `NMLElement`

  static element_tag()

class bmtk.simulator.bionet.nml_reader.ChannelDensityNernst(nml_element)

  Bases: `ChannelDensity`

  static element_tag()

class bmtk.simulator.bionet.nml_reader.ConcentrationModel(nml_element)

  Bases: `NMLElement`

  static element_tag()

class bmtk.simulator.bionet.nml_reader.NMLElement(nml_element)

  Bases: `object`

  static element_tag()

class bmtk.simulator.bionet.nml_reader.NMLTree(nml_path)

  Bases: `object`

  static common_name(elem)
  element_registry = {'{http://www.neuroml.org/schema/neuroml2}channelDensity': <class 'bmtk.simulator.bionet.nml_reader.ChannelDensity'>, '{http://www.neuroml.org/schema/neuroml2}channelDensityNernst': <class 'bmtk.simulator.bionet.nml_reader.ChannelDensityNernst'>, '{http://www.neuroml.org/schema/neuroml2}concentrationModel': <class 'bmtk.simulator.bionet.nml_reader.ConcentrationModel'>, '{http://www.neuroml.org/schema/neuroml2}resistivity': <class 'bmtk.simulator.bionet.nml_reader.Resistivity'>, '{http://www.neuroml.org/schema/neuroml2}specificCapacitance': <class 'bmtk.simulator.bionet.nml_reader.SpecificCapacitance'>}
  nml_ns = '{http://www.neuroml.org/schema/neuroml2}'
  classmethod ns_name(name)
  static parse_value(value)
  classmethod register_module(element_cls)

class bmtk.simulator.bionet.nml_reader.Resistivity(nml_element)

  Bases: `NMLElement`

  static element_tag()

class bmtk.simulator.bionet.nml_reader.SpecificCapacitance(nml_element)

  Bases: `NMLElement`

  static element_tag()

## bmtk.simulator.bionet.nrn module

bmtk.simulator.bionet.nrn.clear_gids()

bmtk.simulator.bionet.nrn.load_neuron_modules(mechanisms_dir, templates_dir, default_templates=True, use_old_import3d=False)
  Parameters:

    - mechanisms_dir

    - templates_dir

    - default_templates

bmtk.simulator.bionet.nrn.load_templates(templates)

  Load all templates to be available in the hoc namespace for instantiating cells

bmtk.simulator.bionet.nrn.quit_execution()

bmtk.simulator.bionet.nrn.reset()

## bmtk.simulator.bionet.pointprocesscell module

class bmtk.simulator.bionet.pointprocesscell.ConnectionStruct(edge_prop, src_node, nc, is_virtual=False)

  Bases: `object`

  property is_virtual
  property source_node
  property syn_weight

class bmtk.simulator.bionet.pointprocesscell.PointProcessCell(node, population_name, bionetwork)

  Bases: `Cell`

  Implimentation of a Leaky Integrate-and-file neuron type cell.

  connections()
  get_connection_info()
  print_synapses()
  set_im_ptr()
  set_spike_detector()
  set_syn_connection(edge_prop, src_node, stim=None)

class bmtk.simulator.bionet.pointprocesscell.PointProcessCellSpontSyns(node, population_name, bionetwork)

  Bases: `PointProcessCell`

  Special class that allows certain synapses to spontaneously fire (without spiking) at a specific time.

  set_syn_connection(edge_prop, src_node, stim=None)

## bmtk.simulator.bionet.pointsomacell module

class bmtk.simulator.bionet.pointsomacell.PointSomaCell

  Bases: `Cell`

  Used to represent single compartment cells with neural mechanisms

## bmtk.simulator.bionet.pyfunction_cache module

## bmtk.simulator.bionet.seclamp module

class bmtk.simulator.bionet.seclamp.SEClamp(amplitudes, durations, rs=None)

  Bases: `object`

  attach_current(cell)

## bmtk.simulator.bionet.sonata_adaptors module

class bmtk.simulator.bionet.sonata_adaptors.BioEdge(sonata_edge, edge_adaptor)

  Bases: `SonataBaseEdge`

  property afferent_section_id
  property afferent_section_pos
  load_synapses(section_x, section_id)

class bmtk.simulator.bionet.sonata_adaptors.BioEdgeAdaptor(network)

  Bases: `EdgeAdaptor`

  get_edge(sonata_edge)
  classmethod patch_adaptor(adaptor, edge_group)

class bmtk.simulator.bionet.sonata_adaptors.BioNode(node, prop_adaptor)

  Bases: `SonataBaseNode`

  load_cell()
  property morphology_file
  property position
  property rotation_angle_xaxis
  property rotation_angle_yaxis
  property rotation_angle_zaxis
  property rotations
  property rotations_quaternion

class bmtk.simulator.bionet.sonata_adaptors.BioNodeAdaptor(network)

  Bases: `NodeAdaptor`

  get_node(sonata_node)
  classmethod patch_adaptor(adaptor, node_group, network)

bmtk.simulator.bionet.sonata_adaptors.aff_sec_id(self, edge)

bmtk.simulator.bionet.sonata_adaptors.aff_sec_id_old(self, edge)

bmtk.simulator.bionet.sonata_adaptors.aff_sec_pos(self, edge)

bmtk.simulator.bionet.sonata_adaptors.aff_sec_pos_old(self, edge)

bmtk.simulator.bionet.sonata_adaptors.position(self, node)

bmtk.simulator.bionet.sonata_adaptors.position_x(self, node)

bmtk.simulator.bionet.sonata_adaptors.position_xy(self, node)

bmtk.simulator.bionet.sonata_adaptors.position_xyz(self, node)

bmtk.simulator.bionet.sonata_adaptors.positions(self, node)

bmtk.simulator.bionet.sonata_adaptors.positions_default(self, node)

bmtk.simulator.bionet.sonata_adaptors.ret_none_function(self, edge)

bmtk.simulator.bionet.sonata_adaptors.rotation_angle_default(self, node)

bmtk.simulator.bionet.sonata_adaptors.rotation_angle_x(self, node)

bmtk.simulator.bionet.sonata_adaptors.rotation_angle_y(self, node)

bmtk.simulator.bionet.sonata_adaptors.rotation_angle_z(self, node)

bmtk.simulator.bionet.sonata_adaptors.rotations(self, node)

bmtk.simulator.bionet.sonata_adaptors.value_none(self, node)

## bmtk.simulator.bionet.utils module

bmtk.simulator.bionet.utils.edge_converter_csv(output_dir, csv_file)

  urrently being used by BioNetwork.write_connections(), need to refactor

  Parameters:

    - output_dir

    - csv_file

  Returns:

bmtk.simulator.bionet.utils.rotation_matrix(axis, theta)

  Return the rotation matrix associated with counterclockwise rotation about the given axis by theta radians.

## bmtk.simulator.bionet.virtualcell module

class bmtk.simulator.bionet.virtualcell.VirtualCell(node, population, spike_train_dataset, spikes_generator=None, sim=None)

  Bases: `object`

  Representation of a Virtual/External node

  property hobj
  property node_id
  set_stim(stim_prop, spike_train)

    Gets the spike trains for each individual cell.

  set_stim_from_generator(node, spikes_generator)

## Module contents