utils Module#

Utilities for checking generated code

neuroml.utils.add_all_to_document(nml_doc_src: NeuroMLDocument, nml_doc_tgt: NeuroMLDocument, verbose: bool = False) None#

Add all members of the source NeuroML document to the target NeuroML document.

Parameters:
  • nml_doc_src (NeuroMLDocument) – source NeuroML document to copy from

  • nml_doc_tgt (NeuroMLDocument) – target NeuroML document to copy to

  • verbose (bool) – control verbosity of working

Raises:

Exception – if a member could not be copied.

neuroml.utils.append_to_element(parent, child)#

Append a child element to a parent Component

Parameters:
  • parent (Object) – parent NeuroML component to add element to

  • child (Object) – child NeuroML component to be added to parent

Raises:

Exception – when the child could not be added to the parent

neuroml.utils.component_factory(component_type: str | type, validate: bool = True, **kwargs: Any) Any#

Factory function to create a NeuroML Component object.

Wrapper around the component_factory method that is present in each NeuroML component type class.

Please see GeneratedsSuperSuper.component_factory for more information.

neuroml.utils.ctinfo(component_type)#

Provide information on any neuroml Component Type class.

This creates a new object (component) of the component type and call its info() method.

Parameters:

component_type (str or type) – component type to print information for, either a string (the name) or the class itself

Returns:

informatin string

Return type:

str

neuroml.utils.ctparentinfo(component_type)#

Provide information on the parentage of any NeuroML Component Type class.

This creates a new object (component) of the component type and call its parentinfo() method.

Parameters:

component_type (str or type) – component type to print information for, either a string (the name) or the class itself

Returns:

information string

Return type:

str

neuroml.utils.fix_external_morphs_biophys_in_cell(nml2_doc: NeuroMLDocument, overwrite: bool = True, load_morphology: bool = True, load_biophysical_properties: bool = True) NeuroMLDocument#

Handle externally referenced morphologies and biophysics in cells.

This is only used in the case where a cell element has a morphology (or biophysicalProperties) attribute, as opposed to a subelement morphology/biophysicalProperties. This will substitute the external element into the cell element for ease of access

The referenced morphologies can be included in the same document directly, or in other documents included using the “IncludeType”. This function will load the included documents and attempt to read referenced bits from them.

Note that if a cell already includes Morphology and BiophysicalProperties, we just use those. Any references to other Morphology/BiophysicalProperties elements will be ignored.

Parameters:
  • nml2_doc (neuroml.NeuroMLDocument) – NeuroML document

  • overwrite (bool) – toggle whether the document is overwritten or a deep copy created

  • load_morphology (bool) – whether morphologies should be loaded

  • load_biophysical_properties (bool) – whether biophysical_properties should be loaded

Returns:

neuroml document

Raises:

KeyError – if referenced morphologies/biophysics cannot be found

neuroml.utils.get_hier_graph_networkx(graph: DiGraph, hier: Dict[str, Any])#

Get a networkx graph of the NeuroML hierarchy

Parameters:
  • graph – graph object to populate

  • hier – component type hierarchy obtained from get_class_hierarchy and get_nml2_class_hierarchy methods

Returns:

None

neuroml.utils.get_relative_component_path(src: str, dest: str, root: ~typing.Type = <class 'neuroml.nml.nml.NeuroMLDocument'>, graph: ~networkx.classes.digraph.DiGraph | None = None)#

Construct a path from src component to dest in a neuroml document.

Useful when referring to components in other components Note that

Parameters:
  • src – source component

  • dest – destination component

  • root – root component of the hierarchy

  • graph – a networkx digraph of the NeuroML hierarchy if available if not, one is constructed

Returns:

calculated path and networkx digraph for future use

neuroml.utils.get_summary(nml_file_name: str) str#

Get a summary of the given NeuroML file.

Parameters:

nml_file_name (str) – name of NeuroML file to get summary of

Returns:

summary of provided file

Return type:

str

neuroml.utils.has_segment_fraction_info(connections: list) bool#

Check if connections include fraction information

Parameters:

connections (list) – list of connection objects

Returns:

True if connections include fragment information, otherwise False

Return type:

Boolean

neuroml.utils.is_valid_neuroml2(file_name: str) None#

Check if a file is valid NeuroML2.

Parameters:

file_name (str) – name of NeuroML file to check

Returns:

True if file is valid, False if not.

Return type:

Boolean

neuroml.utils.main()#
neuroml.utils.print_hierarchy(tree, indent=4, current_ind=0)#

Print the hierarchy tree generated by get_class_hierarchy

Reference: https://stackoverflow.com/a/75161393/375067

neuroml.utils.print_summary(nml_file_name: str) None#

Print a summary of the NeuroML model in the given file.

Parameters:

nml_file_name (str) – name of NeuroML file to print summary of

neuroml.utils.validate_neuroml2(file_name: str) None#

Validate a NeuroML document against the NeuroML schema specification.

Parameters:

file_name (str) – name of NeuroML file to validate.

Raises:

ValueError – if document is invalid