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.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