def test_get_largest_ring(self): """ Test that the Graph.get_polycycles() method returns only polycyclic rings. """ vertices = [Vertex() for _ in range(27)] bonds = [(0, 1), (1, 2), (2, 3), (3, 4), (4, 5), (5, 6), (6, 7), (9, 10), (10, 11), (11, 12), (12, 13), (13, 14), (14, 15), (12, 16), (10, 17), (17, 18), (18, 19), (9, 20), (20, 21), (6, 22), (22, 23), (22, 8), (8, 4), (23, 3), (23, 24), (24, 25), (25, 1)] edges = [] for bond in bonds: edges.append(Edge(vertices[bond[0]], vertices[bond[1]])) graph = Graph() for vertex in vertices: graph.add_vertex(vertex) for edge in edges: graph.add_edge(edge) graph.update_connectivity_values() rings = graph.get_polycycles() self.assertEqual(len(rings), 1) # ensure the last ring doesn't include vertex 8, since it isn't in the # longest ring. Try two different items since one might contain the vertex 8 long_ring = graph.get_largest_ring(rings[0][0]) long_ring2 = graph.get_largest_ring(rings[0][1]) if len(long_ring) > len(long_ring2): longest_ring = long_ring else: longest_ring = long_ring2 self.assertEqual(len(longest_ring), len(rings[0]) - 1)
def test_get_polycyclic_rings(self): """ Test that the Graph.get_polycycles() method returns only polycyclic rings. """ vertices = [Vertex() for _ in range(27)] bonds = [(0, 1), (1, 2), (2, 3), (3, 4), (4, 5), (5, 6), (6, 7), (7, 8), (8, 9), (9, 10), (10, 11), (11, 12), (12, 13), (13, 14), (14, 15), (14, 12), (12, 16), (16, 10), (10, 17), (17, 18), (18, 19), (9, 20), (20, 21), (21, 7), (6, 22), (22, 23), (22, 4), (23, 3), (23, 24), (24, 25), (25, 1)] edges = [] for bond in bonds: edges.append(Edge(vertices[bond[0]], vertices[bond[1]])) graph = Graph() for vertex in vertices: graph.add_vertex(vertex) for edge in edges: graph.add_edge(edge) graph.update_connectivity_values() sssr = graph.get_smallest_set_of_smallest_rings() self.assertEqual(len(sssr), 6) polycyclic_vertices = set(graph.get_all_polycyclic_vertices()) expected_polycyclic_vertices = set( [vertices[index] for index in [3, 23, 4, 22, 12]]) self.assertEqual(polycyclic_vertices, expected_polycyclic_vertices) continuous_rings = graph.get_polycycles() expected_continuous_rings = [ [vertices[index] for index in [1, 2, 3, 4, 5, 6, 22, 23, 24, 25]], # [vertices[index] for index in [7,8,9,21,20]], # This is a nonpolycyclic ring [vertices[index] for index in [10, 11, 12, 13, 14, 16]], ] # Convert to sets for comparison purposes continuous_rings = [set(ring) for ring in continuous_rings] expected_continuous_rings = [ set(ring) for ring in expected_continuous_rings ] for ring in expected_continuous_rings: self.assertTrue(ring in continuous_rings)