You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Disconnected graphs are usually not within the use case of spyrmsd, however they might appear with distance-based atom selections in some applications (for example selecting protein atoms within a certain distance of the ligand in the binding site).
When there is a disconnected node in the graph, using graph-tool for symmetry corrections results in the following error:
self = <VertexPropertyMap object with value type 'int16_t', for Graph 0x7fb9705cdee0, at 0x7fb9705cd1f0>
v = array([0, 1, 4])
def __set_array(self, v):
a = self.get_array()
if a is None:
raise TypeError("cannot set property map values from array for" +
" property map of type: " + self.value_type())
> a[:] = v
E ValueError: could not broadcast input array from shape (3,) into shape (2,)
To Reproduce
c=np.array([[0.0, 1.0, 2.0], [1.0, 2.0, 3.0], [2.0, 3.0, 4.0]])
a=np.array([0, 1, 4])
# Adjacency matrix with disconnected nodeA=np.array([[0, 1, 0], [1, 0, 0], [0, 0, 0]])
assertrmsd.symmrmsd(c, c, a, a, A, A) ==pytest.approx(0.0, abs=1e-5)
This only happens when using graph-tool.
Expected behavior
One should get the same behavior with networkx and graph-tool.
Support disconnected nodes with graph-tool as well
Add warning when there are disconnected nodes?
Environment
OS: macOS 11.6.2
Python: 3.8.10
Package Manager: conda
Additional Context
With graph-tool, a graph is built from the adjacency matrix as follows:
# Get upper triangular adjacency matrixadj=np.triu(adjacency_matrix)
G=gt.Graph(directed=False)
G.add_edge_list(np.transpose(adj.nonzero()))
The adj.nonzero() implies that if there are disconnected nodes, they are discarded (they have no non-zero entries in the adjacency matrix) and therefore the number of nodes will be inconsistent with the number of node properties.
In order to fix the issue, it is possible to explicitly define the number of vertices, instead of relying on the edges:
num_vertices=adjacency_matrix.shape[0]
# Get upper triangular adjacency matrixadj=np.triu(adjacency_matrix)
G.add_vertex(n=num_vertices)
G=gt.Graph(directed=False)
G.add_edge_list(np.transpose(adj.nonzero()))
The text was updated successfully, but these errors were encountered:
Describe the bug
Disconnected graphs are usually not within the use case of
spyrmsd
, however they might appear with distance-based atom selections in some applications (for example selecting protein atoms within a certain distance of the ligand in the binding site).When there is a disconnected node in the graph, using
graph-tool
for symmetry corrections results in the following error:To Reproduce
This only happens when using
graph-tool
.Expected behavior
One should get the same behavior with
networkx
andgraph-tool
.graph-tool
as wellEnvironment
conda
Additional Context
With
graph-tool
, a graph is built from the adjacency matrix as follows:The
adj.nonzero()
implies that if there are disconnected nodes, they are discarded (they have no non-zero entries in the adjacency matrix) and therefore the number of nodes will be inconsistent with the number of node properties.In order to fix the issue, it is possible to explicitly define the number of vertices, instead of relying on the edges:
The text was updated successfully, but these errors were encountered: