def parser(g): for node in g.nodes(): g.nodes[node]['charge'] = int(lit_ev(g.nodes[node]['charge'])) g.nodes[node]['chem'] = int(lit_ev(g.nodes[node]['chem'])) g.nodes[node]['symbol'] = lit_ev(g.nodes[node]['symbol']).strip() real_2Dcoords = [ float(lit_ev(g.nodes[node]['x'])), float(lit_ev(g.nodes[node]['y'])) ] g.nodes[node]['coords'] = numpy.reshape(numpy.asarray(real_2Dcoords), (2, )) {g.nodes[node].pop(k) for k in ['y', 'x']}
def parser(g): for node in g.nodes(): # list_labels = list(map(lambda x: lit_ev(x), g.nodes[node].values())) g.nodes[node]['charge'] = int(lit_ev(g.nodes[node]['charge'])) g.nodes[node]['chem'] = int(lit_ev(g.nodes[node]['chem'])) g.nodes[node]['symbol'] = lit_ev(g.nodes[node]['symbol']).strip() real_2Dcoords = [ float(lit_ev(g.nodes[node]['x'])), float(lit_ev(g.nodes[node]['y'])) ] # g.nodes[node]['coords'] = reshape(asarray(real_2Dcoords), (1, 2)) ? g.nodes[node]['coords'] = reshape(asarray(real_2Dcoords), (2, )) {g.nodes[node].pop(k) for k in ['y', 'x']}
def parser(g): for node in g.nodes(): list_labels = list( map(lambda x: float(lit_ev(x)), g.nodes[node].values())) g.nodes[node]['coords'] = reshape(asarray(list_labels), (1, 2)) {g.nodes[node].pop(k) for k in ['y', 'x']}
def parser(g): # GREC has particular attributes on edges which are not common to all graphs in dataset. # In order to manage this issue, when an attribute is not found, it will be added to the graph # with empty strings or 0's depending on its type. # Since NetworkX edges/nodes are dict structure a try/except workaround is employed, then when # missing key (KeyError) error occurs, the parser manages the exception adding the key to the edge labels # Vertex Attributes: # -type(string) # -coords (x,y real values) # Edge attributes: # -frequency (real) # -type0,1 (strings) # -angle0,1 (real) for node in g.nodes(): g.nodes[node]['type'] = g.nodes[node]['type'] real_2Dcoords = [ float(lit_ev(g.nodes[node]['x'])), float(lit_ev(g.nodes[node]['y'])) ] g.nodes[node]['coords'] = reshape(asarray(real_2Dcoords), (2, )) {g.nodes[node].pop(k) for k in ['y', 'x']} for edge in g.edges(): u = edge[0] v = edge[1] try: g.edges[u, v]['angle0'] = float(lit_ev(g.edges[u, v]['angle0'])) except KeyError: g.edges[u, v]['angle0'] = 0 try: g.edges[u, v]['angle1'] = float(lit_ev(g.edges[u, v]['angle1'])) except KeyError: g.edges[u, v]['angle1'] = 0 try: g.edges[u, v]['type0'] = g.edges[u, v]['type0'] except KeyError: g.edges[u, v]['type0'] = "" try: g.edges[u, v]['type1'] = g.edges[u, v]['type1'] except KeyError: g.edges[u, v]['type1'] = "" g.edges[u, v]['frequency'] = float(lit_ev(g.edges[u, v]['frequency']))
def parser(g): # Vertex Attributes: # -aaLength - (unsigned int) # -sequence - (string) # -type - (unsigned int) # Edge attributes: # -distance0 (real) # -distance1 (real) # -frequency (unsigned inte) # -type0 (strings) # -type1 (strings) for node in g.nodes(): # temp- they can still be strings g.nodes[node]['type'] = int(g.nodes[node]['type']) g.nodes[node]['sequence'] = g.nodes[node]['sequence'] # g.nodes[node]['aaLength']=int(g.nodes[node]['aaLength']) for edge in g.edges(): u = edge[0] v = edge[1] try: g.edges[u, v]['distance0'] = float(lit_ev(g.edges[u, v]['distance0'])) except KeyError: g.edges[u, v]['distance0'] = 0 try: g.edges[u, v]['distance1'] = float(lit_ev(g.edges[u, v]['distance1'])) except KeyError: g.edges[u, v]['distance1'] = 0 try: g.edges[u, v]['type0'] = g.edges[u, v]['type0'] except KeyError: g.edges[u, v]['type0'] = "" try: g.edges[u, v]['type1'] = g.edges[u, v]['type1'] except KeyError: g.edges[u, v]['type1'] = "" g.edges[u, v]['frequency'] = int(g.edges[u, v]['frequency'])
g.addEdge(0, 4) g.addEdge(1, 0) g.addEdge(1, 2) g.addEdge(2, 3) g.addEdge(3, 2) g.addEdge(3, 4) g.addEdge(4, 3) placeA = sys.argv[1] placeB = sys.argv[2] indexA = df.loc[df['place'] == placeA].index[0] indexB = df.loc[df['place'] == placeB].index[0] g.printAllPaths(indexA, indexB) paths = [lit_ev(path) for path in g.paths] distances = [] routes = [] for path in paths: dist = 0 route = [] for a, b in zip(path[:-1], path[1:]): A = df.iloc[a]['place'] B = df.iloc[b]['place'] d = distance(A, B) dist += d route.append(A) distances.append(dist) route.append(placeB) routes.append(route)