本文整理匯總了Python中rmgpy.molecule.graph.Graph.isCyclic方法的典型用法代碼示例。如果您正苦於以下問題:Python Graph.isCyclic方法的具體用法?Python Graph.isCyclic怎麽用?Python Graph.isCyclic使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類rmgpy.molecule.graph.Graph
的用法示例。
在下文中一共展示了Graph.isCyclic方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: TestGraph
# 需要導入模塊: from rmgpy.molecule.graph import Graph [as 別名]
# 或者: from rmgpy.molecule.graph.Graph import isCyclic [as 別名]
#.........這裏部分代碼省略.........
"""
Test that a Graph object can be successfully pickled and unpickled
with no loss of information.
"""
vertices = [Vertex() for i in range(6)]
edges = [
Edge(vertices[0], vertices[1]),
Edge(vertices[1], vertices[2]),
Edge(vertices[2], vertices[3]),
Edge(vertices[3], vertices[4]),
Edge(vertices[4], vertices[5]),
]
graph0 = Graph()
for vertex in vertices:
graph0.addVertex(vertex)
for edge in edges:
graph0.addEdge(edge)
graph0.updateConnectivityValues()
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():
示例2: TestGraph
# 需要導入模塊: from rmgpy.molecule.graph import Graph [as 別名]
# 或者: from rmgpy.molecule.graph.Graph import isCyclic [as 別名]
#.........這裏部分代碼省略.........
def test_pickle(self):
"""
Test that a Graph object can be successfully pickled and unpickled
with no loss of information.
"""
vertices = [Vertex() for i in range(6)]
edges = [
Edge(vertices[0], vertices[1]),
Edge(vertices[1], vertices[2]),
Edge(vertices[2], vertices[3]),
Edge(vertices[3], vertices[4]),
Edge(vertices[4], vertices[5]),
]
graph0 = Graph()
for vertex in vertices: graph0.addVertex(vertex)
for edge in edges: graph0.addEdge(edge)
graph0.updateConnectivityValues()
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.connectivity1, v2.connectivity1)
self.assertEqual(v1.connectivity2, v2.connectivity2)
self.assertEqual(v1.connectivity3, v2.connectivity3)
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():
示例3: TestGraph
# 需要導入模塊: from rmgpy.molecule.graph import Graph [as 別名]
# 或者: from rmgpy.molecule.graph.Graph import isCyclic [as 別名]
#.........這裏部分代碼省略.........
def test_pickle(self):
"""
Test that a Graph object can be successfully pickled and unpickled
with no loss of information.
"""
vertices = [Vertex() for i in range(6)]
edges = [
Edge(vertices[0], vertices[1]),
Edge(vertices[1], vertices[2]),
Edge(vertices[2], vertices[3]),
Edge(vertices[3], vertices[4]),
Edge(vertices[4], vertices[5]),
]
graph0 = Graph()
for vertex in vertices: graph0.addVertex(vertex)
for edge in edges: graph0.addEdge(edge)
graph0.updateConnectivityValues()
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.connectivity1, v2.connectivity1)
self.assertEqual(v1.connectivity2, v2.connectivity2)
self.assertEqual(v1.connectivity3, v2.connectivity3)
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():