Ejemplo n.º 1
0
    def test_getLargestRing(self):
        """
        Test that the Graph.getPolycyclicRings() method returns only polycyclic rings.
        """
        vertices = [Vertex() for i 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.addVertex(vertex)
        for edge in edges:
            graph.addEdge(edge)
        graph.updateConnectivityValues()

        rings = graph.getPolycyclicRings()
        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.getLargestRing(rings[0][0])
        long_ring2 = graph.getLargestRing(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)
Ejemplo n.º 2
0
    def test_getLargestRing(self):
        """
        Test that the Graph.getPolycyclicRings() method returns only polycyclic rings.
        """
        vertices = [Vertex() for i 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.addVertex(vertex)
        for edge in edges: graph.addEdge(edge)
        graph.updateConnectivityValues()
        
        rings = graph.getPolycyclicRings()
        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.getLargestRing(rings[0][0])
        long_ring2 = graph.getLargestRing(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)
Ejemplo n.º 3
0
    def test_getPolycyclicRings(self):
        """
        Test that the Graph.getPolycyclicRings() method returns only polycyclic rings.
        """
        vertices = [Vertex() for i 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.addVertex(vertex)
        for edge in edges:
            graph.addEdge(edge)
        graph.updateConnectivityValues()

        SSSR = graph.getSmallestSetOfSmallestRings()
        self.assertEqual(len(SSSR), 6)
        polycyclicVertices = set(graph.getAllPolycyclicVertices())
        expectedPolycyclicVertices = set(
            [vertices[index] for index in [3, 23, 4, 22, 12]])

        self.assertEqual(polycyclicVertices, expectedPolycyclicVertices)

        continuousRings = graph.getPolycyclicRings()
        expectedContinuousRings = [
            [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
        continuousRings = [set(ring) for ring in continuousRings]
        expectedContinuousRings = [
            set(ring) for ring in expectedContinuousRings
        ]
        for ring in expectedContinuousRings:
            self.assertTrue(ring in continuousRings)
Ejemplo n.º 4
0
    def test_getPolycyclicRings(self):
        """
        Test that the Graph.getPolycyclicRings() method returns only polycyclic rings.
        """
        vertices = [Vertex() for i 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.addVertex(vertex)
        for edge in edges: graph.addEdge(edge)
        graph.updateConnectivityValues()
        
        SSSR = graph.getSmallestSetOfSmallestRings()
        self.assertEqual(len(SSSR),6)
        polycyclicVertices = set(graph.getAllPolycyclicVertices())
        expectedPolycyclicVertices = set([vertices[index] for index in [3,23,4,22,12]])
        
        self.assertEqual(polycyclicVertices, expectedPolycyclicVertices)
        
        continuousRings = graph.getPolycyclicRings()
        expectedContinuousRings = [[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
        continuousRings = [set(ring) for ring in continuousRings]
        expectedContinuousRings = [set(ring) for ring in expectedContinuousRings]
        for ring in expectedContinuousRings:
            self.assertTrue(ring in continuousRings)