Commit ac457974 authored by Benoit GAUZERE's avatar Benoit GAUZERE

Compatibility hack for labels of chemical files

parent 8ccedbcf
......@@ -28,16 +28,17 @@ def loadCT(filename):
else:
nb_nodes = int(tmp[0])
nb_edges = int(tmp[1])
# patch for compatibility : label will be removed later
for i in range(0, nb_nodes):
tmp = content[i + 2].split(" ")
tmp = [x for x in tmp if x != '']
g.add_node(i, atom=tmp[3])
g.add_node(i, atom=tmp[3], label=tmp[3])
for i in range(0, nb_edges):
tmp = content[i + g.number_of_nodes() + 2]
tmp = [tmp[i:i+3] for i in range(0, len(tmp), 3)]
g.add_edge(int(tmp[0]) - 1, int(tmp[1]) - 1, bond_type=tmp[3].strip())
g.add_edge(int(tmp[0]) - 1, int(tmp[1]) - 1,
bond_type=tmp[3].strip(), label=tmp[3].strip())
return g
......@@ -56,6 +57,8 @@ def loadGXL(filename):
labels = {}
for attr in node.iter('attr'):
labels[attr.attrib['name']] = attr[0].text
if 'chem' in labels:
labels['label'] = labels['chem']
g.add_node(index, **labels)
index += 1
......@@ -63,7 +66,8 @@ def loadGXL(filename):
labels = {}
for attr in edge.iter('attr'):
labels[attr.attrib['name']] = attr[0].text
if 'valence' in labels:
labels['label'] = labels['valence']
g.add_edge(dic[edge.attrib['from']], dic[edge.attrib['to']], **labels)
return g
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment