bluecellulab.cell.template

Module for handling NEURON hoc templates.

Functions

check_compliance_with_neuron(template_name)

Verify that a given name is compliant with the rules for a NEURON.

get_neuron_compliant_template_name(name)

Get template name that is compliant with NEURON based on given name.

public_hoc_cell(cell)

Retrieve the hoc cell to access public hoc functions/attributes.

shorten_and_hash_string(label[, ...])

Converts a string to a shorter string if required.

Classes

NeuronTemplate(template_filepath, ...)

Loads and manages a NEURON HOC cell template together with its morphology.

TemplateParams(template_filepath, ...)

class bluecellulab.cell.template.NeuronTemplate(template_filepath, morph_filepath, template_format, emodel_properties)[source]

Loads and manages a NEURON HOC cell template together with its morphology.

Supports four morphology path formats:

  • .asc / .swc: individual morphology files.

  • .h5 single file: an individual HDF5 morphology file.

  • .h5 container: a path of the form container.h5/cell_name where container.h5 is an HDF5 morphologies container and cell_name is the key of the morphology inside it (with or without a trailing .h5 suffix).

  • v5-style directory: a directory path passed directly to legacy HOC templates that locate the morphology file internally.

Parameters:
  • template_filepath (str | Path)

  • morph_filepath (str | Path)

  • template_format (str)

  • emodel_properties (Optional[EmodelProperties])

get_cell(gid)[source]

Returns the hoc object matching the template format.

Parameters:

gid (Optional[int])

Return type:

HocObject

load(template_filename)[source]

Read a cell template. If template name already exists, rename it.

Parameters:

template_filename (str) – path string containing template file.

Return type:

str

Returns:

resulting template name

class bluecellulab.cell.template.TemplateParams(template_filepath, morph_filepath, template_format, emodel_properties)[source]
emodel_properties: Optional[EmodelProperties]

Alias for field number 3

morph_filepath: str | Path

Alias for field number 1

template_filepath: str | Path

Alias for field number 0

template_format: str

Alias for field number 2

bluecellulab.cell.template.check_compliance_with_neuron(template_name)[source]

Verify that a given name is compliant with the rules for a NEURON.

A name should be a non-empty alphanumeric string, and start with a letter. Underscores are allowed. The length should not exceed 50 characters.

Parameters:

template_name (str)

Return type:

bool

bluecellulab.cell.template.get_neuron_compliant_template_name(name)[source]

Get template name that is compliant with NEURON based on given name.

Parameters:

name (str)

Return type:

str

bluecellulab.cell.template.public_hoc_cell(cell)[source]

Retrieve the hoc cell to access public hoc functions/attributes.

Parameters:

cell (HocObject)

Return type:

HocObject

bluecellulab.cell.template.shorten_and_hash_string(label, keep_length=40, hash_length=9)[source]

Converts a string to a shorter string if required.

Parameters:
  • label (str) – A string to be converted.

  • keep_length – Length of the original string to keep.

  • hash_length – Length of the hash to generate, should not be more than 20.

Return type:

str

Returns:

If the length of the original label is shorter than the sum of ‘keep_length’ and ‘hash_length’ plus one, the original string is returned. Otherwise, a string with structure <partial>_<hash> is returned, where <partial> is the first part of the original string with length equal to <keep_length> and the last part is a hash of ‘hash_length’ characters, based on the original string.