Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Networkx to pyg conversion loses track or edge features #217

Open
manonreau opened this issue Oct 18, 2022 · 1 comment
Open

Networkx to pyg conversion loses track or edge features #217

manonreau opened this issue Oct 18, 2022 · 1 comment

Comments

@manonreau
Copy link
Contributor

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']]
@manonreau manonreau mentioned this issue Oct 18, 2022
5 tasks
@universvm
Copy link

universvm commented Nov 28, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants