a-r-j / graphein

Protein Graph Library
https://graphein.ai/
MIT License
1.02k stars 129 forks source link

Networkx to pyg conversion loses track or edge features #217

Open manonreau opened 1 year ago

manonreau commented 1 year ago

Describe the bug The conversion from a network to a pytorch geometric object is corrupted:

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']]
universvm commented 1 year ago

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..