a-r-j / graphein

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

Converting Networkx graph to PyG #77

Closed diamondspark closed 2 years ago

diamondspark commented 2 years ago

Thank you for this excellent work. I am trying to convert the graphs out of the high-level API g = construct_graph(config=config, pdb_code="3eiy")

I try to convert g further to pyG but get an error from torch_geometric.utils import from_networkx data = from_networkx(g)

Error: ~/anaconda3/envs/graphein_dev/lib/python3.8/site-packages/torch_geometric/utils/convert.py in from_networkx(G, group_node_attrs, group_edge_attrs) 162 for key, value in data.items(): 163 try: --> 164 data[key] = torch.tensor(value) 165 except ValueError: 166 pass

RuntimeError: Could not infer dtype of set

diamondspark commented 2 years ago

@a-r-j Any pointers to this?

a-r-j commented 2 years ago

Hi @diamondspark, apologies, will check this out by the end of the week. Looks like a bug to me. @kexinhuang12345 do you have bandwidth?

kexinhuang12345 commented 2 years ago

Sure, I will take a look

kexinhuang12345 commented 2 years ago

Hi, it seems like you are using pytorch geometric converter from networkx. Please use the graphein converter to get the PyG object:

from graphein.ml.conversion import GraphFormatConvertor

format_convertor = GraphFormatConvertor('nx', 'pyg', 
                                        verbose = 'gnn', 
                                        columns = None)

data = format_convertor(g)
a-r-j commented 2 years ago

Thanks, @kexinhuang12345 ! @diamondspark , can you kindly confirm if you're all good on this front so I can close the issue.