opencortex build Package

Utility functions for OpenCortex. See opencortex.core for the main module for user interaction with OpenCortex.

opencortex.build Package

opencortex.build.add_advanced_inputs_to_population(net, id, population, input_id_list, seg_length_dict, subset_dict, universal_target_segment, universal_fraction_along, all_cells=False, only_cells=None, weight_dict=None)

Do not use. Subject to change!!!

This method distributes the poisson input synapses on the specific segment groups of target cells. Input arguments to this method:

net- libNeuroML network object;

id - unique string that tags the input group created by the method;

population - libNeuroML population object of a target population;

input_id_list - this is a list that stores lists of poisson synapse ids or pulse generator ids; if len(input_id_list)== (num of target cells) then each target cell, specified by only_cells or all_cells, has a unique list input components; if len(input_id_list != num, then add_advanced_inputs_to_population assumes that all cells share the same list of input components and thus uses input_id_list[0]. Note that all of the input components (e.g. differing in delays) per given list of input components are mapped on the same membrane point on the target segment of a given cell.

seg_length_dict - a dictionary whose keys are the ids of target segment groups and the values are the segment length dictionaries in the format returned by make_target_dict();

subset_dict - a dictionary whose keys are the ids of target segment groups and the corresponding dictionary values define the desired number of synaptic connections per target segment group per each postsynaptic cell;

universal_target_segment - this should be set to None if subset_dict and seg_length_dict are used; alternatively, universal_target_segment specifies a single target segment on all of the target cells for all input components; then seg_length_dict and subset_dict must be set to None.

universal_fraction_along - this should be set to None if subset_dict and seg_length_dict are used; alternatively, universal_target_fraction specifies a single value of fraction along on all of the target segments for all target cells and all input components; then seg_length_dict and subset_dict must bet set to None;

all_cells - default value is set to False; if all_cells==True then all cells in a given population will receive the inputs;

only_cells - optional variable which stores the list of ids of specific target cells; cannot be set together with all_cells.

weight_dict - id of cell vs weight for each connection

opencortex.build.add_chem_spatial_projection(net, proj_array, presynaptic_population, postsynaptic_population, targeting_mode, synapse_list, pre_seg_target_dict, post_seg_target_dict, subset_dict, distance_rule, pre_cell_positions, post_cell_positions, delays_dict, weights_dict)

This method adds the divergent distance-dependent chemical projection. The input arguments are as follows:

net - the network object created using libNeuroML API ( neuroml.Network() );

proj_array - list which stores the projections of class neuroml.Projection; each projection has unique synapse component (e.g. AMPA , NMDA or GABA); thus for each projection the list position in the proj_array must be identical to the list position of the corresponding synapse id in the synapse_list;

presynaptic_population - object corresponding to the presynaptic population in the network;

postsynaptic_population - object corresponding to the postsynaptic population in the network;

targeting_mode - a string that specifies the targeting mode: ‘convergent’ or ‘divergent’;

synapse_list - the list of synapse ids that correspond to the individual receptor components on the physical synapse, e.g. the first element is the id of the AMPA synapse and the second element is the id of the NMDA synapse; these synapse components will be mapped onto the same location of the target segment;

pre_seg_target_dict - a dictionary whose keys are the ids of presynaptic segment groups and the values are dictionaries in the format returned by make_target_dict();

post_seg_target_dict - a dictionary whose keys are the ids of target segment groups and the values are dictionaries in the format returned by make_target_dict();

subset_dict - a dictionary whose keys are the ids of target segment groups; interpretation of the corresponding dictionary values depends on the targeting mode:

Case I, targeting mode = ‘divergent’ - the desired number of synaptic connections made by each presynaptic cell per given target segment group of postsynaptic cells;

Case II, targeting mode = ‘convergent’ - the desired number of synaptic connections per target segment group per each postsynaptic cell;

alternatively, subset_dict can be a number that specifies the total number of synaptic connections (either divergent or convergent) irrespective of target segment groups.

Note: the chemical connection is made only if distance-dependent probability is higher than some random number random.random(); thus, the actual numbers of connections made

according to the distance-dependent rule might be smaller than the numbers of connections specified by subset_dict; subset_dict defines the upper bound for the

number of connections.

distance_rule - string which defines the distance dependent rule of connectivity - soma to soma distance must be represented by the string character ‘r’;

pre_cell_positions- array specifying the cell positions for the presynaptic population; the format is an array of [ x coordinate, y coordinate, z coordinate];

post_cell_positions- array specifying the cell positions for the postsynaptic population; the format is an array of [ x coordinate, y coordinate, z coordinate];

delays_dict - optional dictionary that specifies the delays (in ms) for individual synapse components, e.g. {‘NMDA’:5.0} or {‘AMPA’:3.0,’NMDA’:5};

weights_dict - optional dictionary that specifies the weights for individual synapse components, e.g. {‘NMDA’:1} or {‘NMDA’:1,’AMPA’:2}.

opencortex.build.add_elect_connection(projection, id, presynaptic_population, pre_cell_id, pre_seg_id, postsynaptic_population, post_cell_id, post_seg_id, gap_junction_id, pre_fraction=0.5, post_fraction=0.5)

Add a single electrical connection (via a gap junction) to a projection between presynaptic_population and postsynaptic_population

opencortex.build.add_elect_spatial_projection(net, proj_array, presynaptic_population, postsynaptic_population, targeting_mode, synapse_list, pre_seg_target_dict, post_seg_target_dict, subset_dict, distance_rule, pre_cell_positions, post_cell_positions)

This method adds the divergent or convergent electrical projection depending on the input argument targeting_mode. The input arguments are as follows:

net - the network object created using libNeuroML API ( neuroml.Network() );

proj_array - dictionary which stores the projections of class neuroml.ElectricalProjection; each projection has unique gap junction component; thus for each projection the list position in the proj_array must be identical to the list position of the corresponding gap junction id in the synapse_list;

presynaptic_population - object corresponding to the presynaptic population in the network;

postsynaptic_population - object corresponding to the postsynaptic population in the network;

targeting_mode - a string that specifies the targeting mode: ‘convergent’ or ‘divergent’;

synapse_list - the list of gap junction (synapse) ids that correspond to the individual gap junction components on the physical contact; these components will be mapped onto the same location of the target segment;

pre_seg_target_dict - a dictionary whose keys are the ids of presynaptic segment groups and the values are dictionaries in the format returned by make_target_dict();

post_seg_target_dict - a dictionary whose keys are the ids of target segment groups and the values are dictionaries in the format returned by make_target_dict();

subset_dict - a dictionary whose keys are the ids of target segment groups; interpretation of the corresponding dictionary values depends on the targeting mode:

Case I, targeting mode = ‘divergent’ - the number of synaptic connections made by each presynaptic cell per given target segment group of postsynaptic cells;

Case II, targeting mode = ‘convergent’ - the number of synaptic connections per target segment group per each postsynaptic cell;

alternatively, subset_dict can be a number that specifies the total number of synaptic connections (either divergent or convergent) irrespective of target segment groups.

Note: the electrical connection is made only if distance-dependent probability is higher than some random number random.random(); thus, the actual numbers of connections made

according to the distance-dependent rule might be smaller than the numbers of connections specified by subset_dict; subset_dict defines the upper bound for the

number of connections.

distance_rule - string which defines the distance dependent rule of connectivity - soma to soma distance must be represented by the string character ‘r’;

pre_cell_positions- array specifying the cell positions for the presynaptic population; the format is an array of [ x coordinate, y coordinate, z coordinate];

post_cell_positions- array specifying the cell positions for the postsynaptic population; the format is an array of [ x coordinate, y coordinate, z coordinate];

opencortex.build.add_population_in_cylindrical_region(net, pop_id, cell_id, size, cyl_radius, lower_bound_dim3, upper_bound_dim3, base_dim1='x', base_dim2='z', cell_bodies_overlap=True, store_soma=False, population_dictionary=None, cell_diameter_dict=None, num_of_polygon_sides=None, positions_of_vertices=None, constants_of_sides=None, color=None)

Method which create a cell population in the NeuroML2 network and distributes these cells in the cylindrical region. Input arguments are as follows:

net - reference to the libNeuroML network object;

pop_id - population id;

cell_id - cell component id;

size - size of a population;

cyl_radius - radius of a cylindrical column in which cells will be distributed;

lower_bound_dim3 - lower bound of the cortical column height;

upper_bound_dim3 - upper bound of the cortical column height;

base_dim1 - specifies which of the ‘x’, ‘y’ and ‘z’ axis corresponds to the first dimension of the transverse plane of the cortical column;

base_dim2 - specifies which of the ‘x’, ‘y’ and ‘z’ axis corresponds to the second dimension of the transverse plane of the cortical column;

cell_bodies_overlap - boolean value which defines whether cell somata can overlap; default is set to True;

store_soma -boolean value which specifies whether soma positions have to be stored in the output array; default is set to False;

population_dictionary - optional argument in the format returned by add_populations_in_rectangular_layers; default value is None but it must be specified when cell_bodies_overlap is set to False;

cell_diameter_dict - optional argument in the format {‘cell_id1’: soma diameter of type ‘float’, ‘cell_id2’: soma diameter of type ‘float’}; default is None but it must be specified when cell_bodies_overlap is set to False.

num_of_polygon_sides - optional argument which specifies the number of sides of regular polygon which is inscribed in the cylindrical column of a given radius; default value
is None, thus cylindrical but not polygonal shape is built.

positions_of_vertices - optional argument which specifies the list of coordinates [dim1, dim2] of vertices of a regular polygon; must be specified if num_of_polygon_sides is not None; automatic generation of this list is wrapped inside the utils method add_populations_in_cylindrical_layers();

constants_of_sides - optional argument which specifies the list of y=ax +b coefficients [a, b] which define the lines between vertices of a regular polygon; if y= b for all values then list element should specify as [None, b]; if x= b for all values of y then list element should specify as [b, None]; Note that constants_of_sides must be specified if num_of_polygon_sides is not None; automatic generation of this list is wrapped inside the utils method add_populations_in_cylindrical_layers();

color - optional color, default is None.

opencortex.build.add_probabilistic_projection_list(net, presynaptic_population, postsynaptic_population, synapse_list, connection_probability, delay=0, weight=1, presynaptic_population_list=True, postsynaptic_population_list=True, clipped_distributions=True, std_delay=None, std_weight=None)

Modification of the method add_probabilistic_projection() to allow multiple synaptic components per physical projection; specifically works for networks containing single-compartment neuronal models. This method also allows gaussian variation in synaptic weight and delay; it also accepts populations that do not necessarily have the type attribute in <population> set to populationList .

opencortex.build.add_projection_based_inputs(net, id, population, input_id_list, weight_list, synapse_id, seg_length_dict, subset_dict, universal_target_segment, universal_fraction_along, all_cells=False, only_cells=None)

This method builds input projections between the input components and target population. Input arguments to this method:

net- libNeuroML network object;

id - unique string that tags the input group created by the method;

population - libNeuroML population object of a target population;

input_id_list - this is a list that stores lists of instance ids of SpikeSourcePoisson component types;

if len(input_id_list)== (num of target cells) then each target cell, specified by only_cells or all_cells, has a unique list input components; if len(input_id_list != num, then add_advanced_inputs_to_population assumes that all cells share the same list of input components and thus uses input_id_list[0]. Note that all of the input components (e.g. differing in delays) per given list of input components are mapped on the same membrane point on the target segment of a given cell.

weight_list - lists of connection weights for the input components specified by input_id_list; it must take the same format as input_id_list;

synapse_id - unique synapse id for all input components specified in input_id_list;

seg_length_dict - a dictionary whose keys are the ids of target segment groups and the values are the segment length dictionaries in the format returned by make_target_dict();

subset_dict - a dictionary whose keys are the ids of target segment groups and the corresponding dictionary values define the desired number of synaptic connections per target segment group per each postsynaptic cell;

universal_target_segment - this should be set to None if subset_dict and seg_length_dict are used; alternatively, universal_target_segment specifies a single target segment on all of the target cells for all input components; then seg_length_dict and subset_dict must be set to None.

universal_fraction_along - this should be set to None if subset_dict and seg_length_dict are used; alternatively, universal_target_fraction specifies a single value of fraction along on all of the target segments for all target cells and all input components; then seg_length_dict and subset_dict must bet set to None;

all_cells - default value is set to False; if all_cells==True then all cells in a given population will receive the inputs;

only_cells - optional variable which stores the list of ids of specific target cells; cannot be set together with all_cells.

opencortex.build.add_synapses(nml_doc, nml2_path, synapse_list, synapse_tag=True)
opencortex.build.add_targeted_projection_by_dicts(net, proj_array, presynaptic_population, postsynaptic_population, targeting_mode, synapse_list, pre_seg_target_dict, post_seg_target_dict, subset_dict, delays_dict=None, weights_dict=None)

This method adds the divergent or convergent chemical projection depending on the input argument targeting_mode. The input arguments are as follows:

net - the network object created using libNeuroML API ( neuroml.Network() );

proj_array - list which stores the projections of class neuroml.Projection; each projection has unique synapse component (e.g. AMPA , NMDA or GABA); thus for each projection the list position in the proj_array must be identical to the list position of the corresponding synapse id in the synapse_list;

presynaptic_population - object corresponding to the presynaptic population in the network;

postsynaptic_population - object corresponding to the postsynaptic population in the network;

targeting_mode - a string that specifies the targeting mode: ‘convergent’ or ‘divergent’;

synapse_list - the list of synapse ids that correspond to the individual receptor components on the physical synapse, e.g. the first element is the id of the AMPA synapse and the second element is the id of the NMDA synapse; these synapse components will be mapped onto the same location of the target segment;

pre_seg_target_dict - a dictionary whose keys are the ids of presynaptic segment groups and the values are dictionaries in the format returned by make_target_dict();

post_seg_target_dict - a dictionary whose keys are the ids of target segment groups and the values are dictionaries in the format returned by make_target_dict();

subset_dict - a dictionary whose keys are the ids of target segment groups; interpretation of the corresponding dictionary values depends on the targeting mode:

Case I, targeting mode = ‘divergent’ - the number of synaptic connections made by each presynaptic cell per given target segment group of postsynaptic cells;

Case II, targeting mode = ‘convergent’ - the number of synaptic connections per target segment group per each postsynaptic cell;

alternatively, subset_dict can be a number that specifies the total number of synaptic connections (either divergent or convergent) irrespective of target segment groups.

delays_dict - optional dictionary that specifies the delays (in ms) for individual synapse components, e.g. {‘NMDA’:5.0} or {‘AMPA’:3.0,’NMDA’:5};

weights_dict - optional dictionary that specifies the weights for individual synapse components, e.g. {‘NMDA’:1} or {‘NMDA’:1,’AMPA’:2}.

opencortex.build.copy_nml2_source(dir_to_project_nml2, primary_nml2_dir, electrical_synapse_tags, chemical_synapse_tags, extra_channel_tags=[])

This method copies the individual NeuroML2 model components from the primary source dir to corresponding component folders in the target dir: “synapses”, “gapJunctions”,

“channels” and “cells” are created in the dir_to_project_nml2.

opencortex.build.distance(p, q)
opencortex.build.extract_seg_ids(cell_object, target_compartment_array, targeting_mode)

This method extracts the segment ids that map on the target segment groups or individual segments. cell_object is the loaded cell object using neuroml.loaders.NeuroMLLoader, target_compartment_array is an array of target compartment names (e.g. segment group ids or individual segment names) and targeting_mode is one of the strings: “segments” or “segGroups”.

opencortex.build.find_constrained_cell_position(num_of_polygon_sides, cyl_radius, lower_bound_dim3, upper_bound_dim3, positions_of_vertices, constants_of_sides)

Method to find a constrained position of the cell; used inside the method add_population_in_cylindrical_region().

opencortex.build.get_pre_and_post_segment_ids(proj)

This method extracts the lists of pre and post segment ids per given projection. Can be used when substituting the cell types from one NeuroML2 network to the other.

return pre_segment_ids, post_segment_ids

opencortex.build.get_seg_lengths(cell_object, target_segments)

This method constructs the cumulative distribution of target segments and the corresponding list of target segment ids. Input arguments: cell_object - object created using libNeuroML API which corresponds to the target cell; target_segments - the list of target segment ids.

opencortex.build.get_soma_diameter(cell_name, cell_type=None, dir_to_cell=None)

Method to obtain a diameter of a cell soma.

opencortex.build.get_target_cells(population, fraction_to_target, list_of_xvectors=None, list_of_yvectors=None, list_of_zvectors=None)

This method returns the list of target cells according to which fraction of randomly selected cells is targeted and whether these cells are localized in the specific rectangular regions of the network. These regions are specified by list_of_xvectors, list_of_yvectors and list_of_zvectors. These lists must have the same length.

The input variable list_of_xvectors stores the lists whose elements define the left and right margins of the target rectangular regions along the x dimension.

Similarly, the input variables list_of_yvectors and list_of_zvectors store the lists whose elements define the left and right margins of the target rectangular regions along the y and z dimensions, respectively.

opencortex.build.get_target_segments(seg_specifications, subset_dict)

This method generates the list of target segments and target fractions per cell according to two types of input dictionaries: seg_specifications - a dictionary in the format returned by make_target_dict(); keys are target group names or individual segment names and the corresponding values are dictionaries with keys ‘LengthDist’ and ‘SegList’, as returned by the get_seg_lengths; subset_dict - a dictionary whose keys are target group names or individual segment names; each key stores the corresponding number of connections per target group.

opencortex.build.make_target_dict(cell_object, target_segs)

This method constructs the dictionary whose keys are the names of target segment groups or individual segments and the corresponding values are dictionaries with keys ‘LengthDist’ and ‘SegList’, as returned by the get_seg_lengths. Input arguments are as follows:

cell_object - object created using libNeuroML API which corresponds to the target cell; target_segs - a dictionary in the format returned by the method extract_seg_ids(); the keys are the ids of target segment groups or names of individual segments and the values are lists of corresponding target segment ids.

opencortex.build.remove_component_dirs(dir_to_project_nml2, list_of_cell_ids, extra_channel_tags=None)

This method removes the sufolder strings of NeuroML2 component types (if they exist) from the ‘includes’ of each NeuroML2 cell in the target dir.

Target directory is specified by the input argument dir_to_project_nml2.