#NEWLINE# def make_clique_bipartite( G , fpos = None , create_using = None , name = None ) : #NEWLINE# #INDENT# 'Create a bipartite clique graph from a graph G.\n\n    Nodes of G are retained as the "bottom nodes" of B and\n    cliques of G become "top nodes" of B.\n    Edges are present if a bottom node belongs to the clique\n    represented by the top node.\n\n    Returns a Graph with additional attribute dict B.node_type\n    which is keyed by nodes to "Bottom" or "Top" appropriately.\n\n    if fpos is not None, a second additional attribute dict B.pos\n    is created to hold the position tuple of each node for viewing\n    the bipartite graph.\n    ' #NEWLINE# cliq = list ( find_cliques ( G ) ) #NEWLINE# if create_using : #NEWLINE# #INDENT# B = create_using #NEWLINE# B . clear ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# B = networkx . Graph ( ) #NEWLINE# #UNINDENT# if ( name is not None ) : #NEWLINE# #INDENT# B . name = name #NEWLINE# #UNINDENT# B . add_nodes_from ( G ) #NEWLINE# B . node_type = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for n in B : #NEWLINE# #INDENT# B . node_type [ n ] = 'Bottom' #NEWLINE# #UNINDENT# if fpos : #NEWLINE# #INDENT# B . pos = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# delta_cpos = ( 1.0 / len ( cliq ) ) #NEWLINE# delta_ppos = ( 1.0 / G . order ( ) ) #NEWLINE# cpos = 0.0 #NEWLINE# ppos = 0.0 #NEWLINE# #UNINDENT# for ( i , cl ) in enumerate ( cliq ) : #NEWLINE# #INDENT# name = ( ( - i ) - 1 ) #NEWLINE# B . add_node ( name ) #NEWLINE# B . node_type [ name ] = 'Top' #NEWLINE# if fpos : #NEWLINE# #INDENT# if ( name not in B . pos ) : #NEWLINE# #INDENT# B . pos [ name ] = ( 0.2 , cpos ) #NEWLINE# cpos += delta_cpos #NEWLINE# #UNINDENT# #UNINDENT# for v in cl : #NEWLINE# #INDENT# B . add_edge ( name , v ) #NEWLINE# if ( fpos is not None ) : #NEWLINE# #INDENT# if ( v not in B . pos ) : #NEWLINE# #INDENT# B . pos [ v ] = ( 0.8 , ppos ) #NEWLINE# ppos += delta_cpos #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# return B