本文整理匯總了Python中rmgpy.molecule.graph.Graph.getSmallestSetOfSmallestRings方法的典型用法代碼示例。如果您正苦於以下問題:Python Graph.getSmallestSetOfSmallestRings方法的具體用法?Python Graph.getSmallestSetOfSmallestRings怎麽用?Python Graph.getSmallestSetOfSmallestRings使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類rmgpy.molecule.graph.Graph
的用法示例。
在下文中一共展示了Graph.getSmallestSetOfSmallestRings方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: TestGraph
# 需要導入模塊: from rmgpy.molecule.graph import Graph [as 別名]
# 或者: from rmgpy.molecule.graph.Graph import getSmallestSetOfSmallestRings [as 別名]
#.........這裏部分代碼省略.........
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 = [
(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),
示例2: TestGraph
# 需要導入模塊: from rmgpy.molecule.graph import Graph [as 別名]
# 或者: from rmgpy.molecule.graph.Graph import getSmallestSetOfSmallestRings [as 別名]
#.........這裏部分代碼省略.........
import cPickle
graph = cPickle.loads(cPickle.dumps(graph0))
self.assertEqual(len(graph0.vertices), len(graph.vertices))
for v1, v2 in zip(graph0.vertices, graph.vertices):
self.assertEqual(v1.connectivity, v2.connectivity)
self.assertEqual(v1.sortingLabel, v2.sortingLabel)
self.assertEqual(len(v1.edges), len(v2.edges))
self.assertTrue(graph0.isIsomorphic(graph))
self.assertTrue(graph.isIsomorphic(graph0))
def test_isCyclic(self):
"""
Test the Graph.isCyclic() method.
"""
self.assertFalse(self.graph.isCyclic())
edge = Edge(self.graph.vertices[0], self.graph.vertices[3])
self.graph.addEdge(edge) # To create a cycle
self.assertTrue(self.graph.isCyclic())
def test_isVertexInCycle(self):
"""
Test the Graph.isVertexInCycle() method.
"""
for vertex in self.graph.vertices:
self.assertFalse(self.graph.isVertexInCycle(vertex))
edge = Edge(self.graph.vertices[0], self.graph.vertices[3])
self.graph.addEdge(edge) # To create a cycle
for vertex in self.graph.vertices[0:4]:
self.assertTrue(self.graph.isVertexInCycle(vertex))
for vertex in self.graph.vertices[4:]:
self.assertFalse(self.graph.isVertexInCycle(vertex))
def test_isEdgeInCycle(self):
"""
Test the Graph.isEdgeInCycle() method.
"""
for vertex1 in self.graph.vertices:
for vertex2, edge in vertex1.edges.items():
self.assertFalse(self.graph.isEdgeInCycle(edge))
edge = Edge(self.graph.vertices[0], self.graph.vertices[3])
self.graph.addEdge(edge) # To create a cycle
for vertex1 in self.graph.vertices:
for vertex2, edge in vertex1.edges.items():
if self.graph.vertices.index(vertex1) < 4 and self.graph.vertices.index(vertex2) < 4:
self.assertTrue(self.graph.isEdgeInCycle(edge))
else:
self.assertFalse(self.graph.isEdgeInCycle(edge))
def test_getAllCyclicVertices(self):
self.assertListEqual(self.graph.getAllCyclicVertices(), [])
edge = Edge(self.graph.vertices[0], self.graph.vertices[3])
self.graph.addEdge(edge) # To create a cycle
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_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)
示例3: test_getPolycyclicRings
# 需要導入模塊: from rmgpy.molecule.graph import Graph [as 別名]
# 或者: from rmgpy.molecule.graph.Graph import getSmallestSetOfSmallestRings [as 別名]
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)
示例4: TestGraph
# 需要導入模塊: from rmgpy.molecule.graph import Graph [as 別名]
# 或者: from rmgpy.molecule.graph.Graph import getSmallestSetOfSmallestRings [as 別名]
#.........這裏部分代碼省略.........
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):
"""
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_getRelevantCycles(self):
"""
Test the Graph.getRelevantCycles() method.
"""
cycleList = self.graph.getRelevantCycles()
self.assertEqual(len(cycleList), 0)
# Create a cycle of length 4
edge = Edge(self.graph.vertices[0], self.graph.vertices[3])
self.graph.addEdge(edge)
# Create a second cycle of length 4
edge = Edge(self.graph.vertices[0], self.graph.vertices[5])
self.graph.addEdge(edge)
# Create a bridge forming multiple cycles of length 4
edge = Edge(self.graph.vertices[1], self.graph.vertices[4])
self.graph.addEdge(edge)
# SSSR should be 3 cycles of length 4
cycleList = self.graph.getSmallestSetOfSmallestRings()
self.assertEqual(len(cycleList), 3)
sizeList = sorted([len(cycle) for cycle in cycleList])
self.assertEqual(sizeList, [4, 4, 4])