Closed avivko closed 2 years ago
Hi @avivko this is not a problem with Graphein (or nx, really) but rather with the graph. This particular method fails when there are multiple largest eigenvalues. You can try with: nx.eigenvector_centrality_numpy
, I believe. If that works out, would you be able to let me know & I can update Graphein to use this method for the centrality measure?
@a-r-j Thanks for responding. This seems to happen with all the PDB-based graphs I was trying to work with. Using the Numpy method that you suggested does solve this:
import importlib
import sys
def modify_and_import(module_name, package, modification_func):
spec = importlib.util.find_spec(module_name, package)
source = spec.loader.get_source(module_name)
new_source = modification_func(source)
module = importlib.util.module_from_spec(spec)
codeobj = compile(new_source, module.__spec__.origin, 'exec')
exec(codeobj, module.__dict__)
sys.modules[module_name] = module
return module
modified_analysis = modify_and_import("graphein.protein.analysis", "graphein", lambda src: src.replace("nx.eigenvector_centrality(G)", "nx.eigenvector_centrality_numpy(G)"))
modified_analysis.graph_summary(g)
Results in the expected Pandas DataFrame being returned (as expected)
So I'd recommend replacing the method in Graphein's source code :)
This has now been changed in 1.4.0 :)
Describe the bug graph summary: nx.eigenvector_centrality seems to throw an error.
To Reproduce
Results in:
Desktop (please complete the following information):