NetworkX

class NetworkX[source]

Bases: openpnm.io.GenericIO.GenericIO

NetworkX is a common tool for dealing with network structures

This class actually handles dealing with live NetworkX objects rather than saved files. NetworkX has a number of export formats, so converting OpenPNM data to a NetworkX object, then using NetworkX to exprt might be an option for file formats not supported by OpenPNM yet.

Notes

1. Each node in a NetworkX object (i.e. G) can be assigned properties using syntax like G.node[n]['diameter'] = 0.5 where n is the node number. There is no need to precede the property name with any indication that it is pore data such as 'pore_'. OpenPNM will prepend 'pore.' to each property name.

2. Since 'pore.coords' is so central to OpenPNM it should be specified in the NetworkX object as 'coords', and the [X, Y, Z] coordinates of each node should be a 1x3 list.

3. Edges in a NetworkX object are accessed using the index numbers of the two nodes it connects, such as G.adj[2][3]['length'] = 0.1 indicating the edge that connects nodes 2 and 3. There is no need to precede the property name with any indication that it is throat data such as 'throat_'. OpenPNM will prepend 'throat.' to each property name.

4. The 'throat.conns' property is essential to OpenPNM, but this does NOT need to be specified explicitly as a property in NetworkX. The connectivity is embedded into the network representation and is extracted by OpenPNM.

classmethod export_data(network)[source]

Write OpenPNM Network to a NetworkX object.

Parameters

network (OpenPNM Network Object) – The OpenPNM Network to be converted to a NetworkX object

Returns

Return type

A NetworkX object with all pore/throat properties attached to it

classmethod import_data(G, project=None)[source]

Add data to an OpenPNM Network from a undirected NetworkX graph object.

Parameters
  • G (networkx.classes.graph.Graph Object) – The NetworkX graph. G should be undirected. The numbering of nodes should be numeric (int’s), zero-based and should not contain any gaps, i.e. G.nodes() = [0,1,3,4,5] is not allowed and should be mapped to G.nodes() = [0,1,2,3,4].

  • project (OpenPNM Project object) – A GenericNetwork is created and added to the specified Project. If no Project is supplied then one will be created and returned.

Returns

  • An OpenPNM Project containing a GenericNetwork with all the data from

  • the NetworkX object.