How to use the nml.Pattern function in nml

To help you get started, we’ve selected a few nml examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github neurokernel / neurokernel / neurokernel / neuroml / utils.py View on Github external
Parameters
    ----------
    g : networkx.DiGraph
        Directed graph containing the pattern's ports (nodes) and connections
        (edges).
    id : str
        Pattern identifier.

    Returns
    -------
    pattern : neurokernel.neuroml.Pattern
        pattern instance.
    """

    pattern = Pattern(id=id)
    interface = Interface()
    for p in g.nodes():
        attr_dict = g.node[p]
        port = Port(identifier=attr_dict['identifier'],
                    interface=attr_dict['interface'],
                    io=attr_dict['io'],
                    type=attr_dict['type'])
        interface.ports.append(port)

    pattern.interface = interface
    for c in g.edges():
        connection = PatternConnection(from_=c[0], to=c[1])
        pattern.connections.append(connection)

    return pattern
github neurokernel / neurokernel / neurokernel / neuroml / utils.py View on Github external
"""
    Convert a pattern expressed in Neurokernel NeuroML into a NetworkX graph.

    Parameters
    ----------
    pattern : neurokernel.neuroml.Pattern
        Pattern instance.

    Returns
    -------
    g : networkx.DiGraph
        Directed graph containing the pattern's ports (nodes) and connections
        (edges).
    """

    assert isinstance(pattern, Pattern)

    g = nx.DiGraph()
    for p in pattern.interface.ports:
        g.add_node(p.identifier)
        g.node[p.identifier] = {
            'interface': int(p.interface),
            'io': p.io,
            'type': p.type
            }

    for c in pattern.connections:
        g.add_edge(c.from_, c.to)

    return g