Skip to content

Commit d177753

Browse files
committed
Fixed bug in cycle detection algorithm caused by new graph format.
The getSmallestSetOfSmallestRings() method generates a copy of the graph before applying the SSSR algorithm so as to not modify the original. Before, this was safe because we could make a shallow copy and reuse the same Vertex and Edge objects, since we didn't store any information about the graph connectivity on these objects. Now that we are, we must make a deep copy of the graph to use for the SSSR algorithm. As a result, we also need to map the vertices of the copy back to those of the original graph before returning. This was causing the molecule drawing to fail for cyclic species; the problem should now be fixed.
1 parent 82b6a2b commit d177753

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

rmgpy/molecule/graph.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,11 +558,12 @@ def getSmallestSetOfSmallestRings(self):
558558
cython.declare(graph=Graph)
559559
cython.declare(done=cython.bint, found=cython.bint)
560560
cython.declare(cycleList=list, cycles=list, cycle=list, graphs=list, neighbors=list)
561-
cython.declare(verticesToRemove=list)
561+
cython.declare(verticesToRemove=list, vertices=list)
562562
cython.declare(vertex=Vertex, rootVertex=Vertex)
563563

564564
# Make a copy of the graph so we don't modify the original
565565
graph = self.copy(deep=True)
566+
vertices = graph.vertices[:]
566567

567568
# Step 1: Remove all terminal vertices
568569
done = False
@@ -630,6 +631,10 @@ def getSmallestSetOfSmallestRings(self):
630631
for vertex in verticesToRemove:
631632
graph.removeVertex(vertex)
632633

634+
# Map atoms in cycles back to atoms in original graph
635+
for i in range(len(cycleList)):
636+
cycleList[i] = [self.vertices[vertices.index(v)] for v in cycles[i]]
637+
633638
return cycleList
634639

635640
def isMappingValid(self, other, mapping):

0 commit comments

Comments
 (0)