當前位置: 首頁>>代碼示例>>Python>>正文


Python Graph.getAllCyclesOfSize方法代碼示例

本文整理匯總了Python中rmgpy.molecule.graph.Graph.getAllCyclesOfSize方法的典型用法代碼示例。如果您正苦於以下問題:Python Graph.getAllCyclesOfSize方法的具體用法?Python Graph.getAllCyclesOfSize怎麽用?Python Graph.getAllCyclesOfSize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在rmgpy.molecule.graph.Graph的用法示例。


在下文中一共展示了Graph.getAllCyclesOfSize方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: TestGraph

# 需要導入模塊: from rmgpy.molecule.graph import Graph [as 別名]
# 或者: from rmgpy.molecule.graph.Graph import getAllCyclesOfSize [as 別名]

#.........這裏部分代碼省略.........
        self.assertEqual(len(self.graph.getAllCyclicVertices()), 4)
        
    def test_getAllPolycylicVertices(self):        
        edge = Edge(self.graph.vertices[0], self.graph.vertices[3])
        self.graph.addEdge(edge) # To create a cycle        
        self.assertListEqual(self.graph.getAllPolycyclicVertices(), []) 
        edge2 = Edge(self.graph.vertices[0], self.graph.vertices[5])
        self.graph.addEdge(edge2) # Create another cycle to generate two fused cycles 
        self.assertEqual(len(self.graph.getAllPolycyclicVertices()), 2)
        # Add new vertices and edges to generate a spirocyclic cycle      
        vertices = [Vertex() for i in range(2)]        
        for vertex in vertices: self.graph.addVertex(vertex)
        edges = [
                 Edge(self.graph.vertices[5], self.graph.vertices[6]),
                 Edge(self.graph.vertices[6], self.graph.vertices[7]),
                 Edge(self.graph.vertices[5], self.graph.vertices[7]),
                 ]
        for edge in edges: self.graph.addEdge(edge)        
        self.assertEqual(len(self.graph.getAllPolycyclicVertices()), 3)
                      
    def test_getAllCycles(self):
        """
        Test the Graph.getAllCycles() method.
        """
        cycleList = self.graph.getAllCycles(self.graph.vertices[0])
        self.assertEqual(len(cycleList), 0)
        edge = Edge(self.graph.vertices[0], self.graph.vertices[3])
        self.graph.addEdge(edge) # To create a cycle
        cycleList = self.graph.getAllCycles(self.graph.vertices[0])
        self.assertEqual(len(cycleList), 2)
        self.assertEqual(len(cycleList[0]), 4)
        self.assertEqual(len(cycleList[1]), 4)

    def test_getAllCyclesOfSize(self):
        """
        Test the Graph.getRingsOfSize() method
        """
        cycleList = self.graph.getAllCyclesOfSize(6)
        self.assertEqual(len(cycleList), 0)
        edge = Edge(self.graph.vertices[0], self.graph.vertices[3])
        self.graph.addEdge(edge) # To create a cycle of length 4
        edge = Edge(self.graph.vertices[0], self.graph.vertices[5])
        self.graph.addEdge(edge) # To create a cycle of length 6 and another cycle of length 4
        cycleList = self.graph.getAllCyclesOfSize(4)
        self.assertEqual(len(cycleList), 2)
        self.assertEqual(len(cycleList[0]), 4)
        self.assertEqual(len(cycleList[1]), 4)
        
    def test_getSmallestSetOfSmallestRings(self):
        """
        Test the Graph.getSmallestSetOfSmallestRings() method.
        """
        cycleList = self.graph.getSmallestSetOfSmallestRings()
        self.assertEqual(len(cycleList), 0)
        edge = Edge(self.graph.vertices[0], self.graph.vertices[3])
        self.graph.addEdge(edge) # To create a cycle
        cycleList = self.graph.getSmallestSetOfSmallestRings()
        self.assertEqual(len(cycleList), 1)
        self.assertEqual(len(cycleList[0]), 4)

    def test_getPolycyclicRings(self):
        """
        Test that the Graph.getPolycyclicRings() method returns only polycyclic rings.
        """
        vertices = [Vertex() for i in range(27)]
        bonds = [
開發者ID:connie,項目名稱:RMG-Py,代碼行數:70,代碼來源:graphTest.py

示例2: TestGraph

# 需要導入模塊: from rmgpy.molecule.graph import Graph [as 別名]
# 或者: from rmgpy.molecule.graph.Graph import getAllCyclesOfSize [as 別名]

#.........這裏部分代碼省略.........
        self.assertEqual(len(self.graph.getAllCyclicVertices()), 4)
        
    def test_getAllPolycylicVertices(self):        
        edge = Edge(self.graph.vertices[0], self.graph.vertices[3])
        self.graph.addEdge(edge) # To create a cycle        
        self.assertListEqual(self.graph.getAllPolycyclicVertices(), []) 
        edge2 = Edge(self.graph.vertices[0], self.graph.vertices[5])
        self.graph.addEdge(edge2) # Create another cycle to generate two fused cycles 
        self.assertEqual(len(self.graph.getAllPolycyclicVertices()), 2)
        # Add new vertices and edges to generate a spirocyclic cycle      
        vertices = [Vertex() for i in range(2)]        
        for vertex in vertices: self.graph.addVertex(vertex)
        edges = [
                 Edge(self.graph.vertices[5], self.graph.vertices[6]),
                 Edge(self.graph.vertices[6], self.graph.vertices[7]),
                 Edge(self.graph.vertices[5], self.graph.vertices[7]),
                 ]
        for edge in edges: self.graph.addEdge(edge)        
        self.assertEqual(len(self.graph.getAllPolycyclicVertices()), 3)
                      
    def test_getAllCycles(self):
        """
        Test the Graph.getAllCycles() method.
        """
        cycleList = self.graph.getAllCycles(self.graph.vertices[0])
        self.assertEqual(len(cycleList), 0)
        edge = Edge(self.graph.vertices[0], self.graph.vertices[3])
        self.graph.addEdge(edge) # To create a cycle
        cycleList = self.graph.getAllCycles(self.graph.vertices[0])
        self.assertEqual(len(cycleList), 2)
        self.assertEqual(len(cycleList[0]), 4)
        self.assertEqual(len(cycleList[1]), 4)

    def test_getAllCyclesOfSize(self):
        """
        Test the Graph.getRingsOfSize() method
        """
        cycleList = self.graph.getAllCyclesOfSize(6)
        self.assertEqual(len(cycleList), 0)
        edge = Edge(self.graph.vertices[0], self.graph.vertices[3])
        self.graph.addEdge(edge) # To create a cycle of length 4
        edge = Edge(self.graph.vertices[0], self.graph.vertices[5])
        self.graph.addEdge(edge) # To create a cycle of length 6 and another cycle of length 4
        cycleList = self.graph.getAllCyclesOfSize(4)
        self.assertEqual(len(cycleList), 2)
        self.assertEqual(len(cycleList[0]), 4)
        self.assertEqual(len(cycleList[1]), 4)
        
    def test_getAllSimpleCyclesOfSize(self):
        """
        Test the Graph.getAllSimpleCyclesOfSize() method.
        """
        cycleList = self.graph.getAllCyclesOfSize(6)
        self.assertEqual(len(cycleList), 0)
        edge = Edge(self.graph.vertices[0], self.graph.vertices[3])
        self.graph.addEdge(edge)  # To create a cycle of length 4
        edge = Edge(self.graph.vertices[0], self.graph.vertices[5])
        self.graph.addEdge(edge)  # To create a cycle of length 6 and another cycle of length 4
        cycleList = self.graph.getAllSimpleCyclesOfSize(4)
        self.assertEqual(len(cycleList), 2)
        self.assertEqual(len(cycleList[0]), 4)
        self.assertEqual(len(cycleList[1]), 4)
        cycleList = self.graph.getAllSimpleCyclesOfSize(6)
        self.assertEqual(len(cycleList), 0)

    def test_getSmallestSetOfSmallestRings(self):
開發者ID:ReactionMechanismGenerator,項目名稱:RMG-Py,代碼行數:70,代碼來源:graphTest.py


注:本文中的rmgpy.molecule.graph.Graph.getAllCyclesOfSize方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。