graphein
graphein copied to clipboard
Networkx to pyg conversion loses track or edge features
trafficstars
Describe the bug The conversion from a network to a pytorch geometric object is corrupted:
- The edge features is given as a list of string instead of a list of lists:
- When we have edges associated to different features/kind (ex kind= {‘aromatic’,’distance_threshold’}), we obtain graphs with more edge features than edges and we cannot associate any edge to its features anymore
ex:
Data(edge_index=[2, 40], node_id=[12], residue_name=[12], residue_number=[12], element_symbol=[12], coords=[1], kind=[62], node_type=[1], config=[1], num_nodes=12)
To Reproduce
def graph2pkl(g, fname):
"""
Save graphs as .pkl files
Args:
g (object): graph
"""
# Graphein data to save
d = ["config",
"coords",
"edge_index",
"element_symbol",
"kind",
"node_id",
"node_type",
"residue_name",
"residue_number"]
# Convert networkx graph to pytorch geometric object
format_convertor = GraphFormatConvertor('nx', 'pyg',
verbose = None,
columns = d)
g = format_convertor(g)
# FOrmat of some nodes and edge feature (ex: resname one hot encoding)
g = format_node_edge_features(g)
return g
g = graph2pkl(G, ('test'))
print(g)
g.kind
Expected behavior We expect the converter to keep track of all features assigned to one edge.
While we would expect this:
[['peptide_bond'],
['distance_threshold'],
['distance_threshold'],
['distance_threshold', 'ionic'],
['distance_threshold', 'aromatic']]
We have this:
[['peptide_bond'],
['distance_threshold'],
['distance_threshold'],
['distance_threshold'],
['ionic'],
['distance_threshold'],
['aromatic']]
Did you manage to solve the issue? I see that your pr was merged though I still have the same problems with all my edges not being carried through after the conversion..