def draw_graph(mst, mst_a, mol_names, dir_names, method):
import networkx as nx
G = nx.from_scipy_sparse_matrix(mst)
if method == 'mcs':
corr = 1
else:
corr = 0
for i, j in zip(mst.nonzero()[0], mst.nonzero()[1]):
G.edge[i][j]['label'] = '%.1f' % (mst_a[i][j] - corr)
G.edge[i][j]['len'] = '3.0'
for n in G.nodes():
G.node[n]['shape'] = 'box'
G.node[n]['label'] = ('<'
'<table border="0" cellspacing="-20" cellborder="0">'
'<tr><td><img src="%s"/></td></tr>'
'<tr><td bgcolor="#F0F0F0">%s</td></tr>'
'</table>>' % (os.path.join(dir_names[n],
mol_names[n] + os.extsep + 'svg'),
mol_names[n]) )
print('Writing networkx graph pickle file %s...' % GPICKLE_FILE)
nx.write_gpickle(G, GPICKLE_FILE)
print('Writing DOT file %s...' % DOT_FILE)
nx.write_dot(G, DOT_FILE)
评论列表
文章目录