Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
"""
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