本文整理匯總了Python中rmgpy.molecule.graph.Graph.updateConnectivityValues方法的典型用法代碼示例。如果您正苦於以下問題:Python Graph.updateConnectivityValues方法的具體用法?Python Graph.updateConnectivityValues怎麽用?Python Graph.updateConnectivityValues使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類rmgpy.molecule.graph.Graph
的用法示例。
在下文中一共展示了Graph.updateConnectivityValues方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_pickle
# 需要導入模塊: from rmgpy.molecule.graph import Graph [as 別名]
# 或者: from rmgpy.molecule.graph.Graph import updateConnectivityValues [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))
示例2: test_vertex_connectivity_values
# 需要導入模塊: from rmgpy.molecule.graph import Graph [as 別名]
# 或者: from rmgpy.molecule.graph.Graph import updateConnectivityValues [as 別名]
def test_vertex_connectivity_values(self):
"""
Tests the vertex connectivity values as introduced by Morgan (1965).
Graph: Expected (and tested) values:
0-1-2-3-4 1-3-2-2-1 3-4-5-3-2 4-11-7-7-3
| | | |
5 1 3 4
# = 3 # = 4 # = 4
*selected*
"""
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[1], vertices[5]),
]
graph = Graph()
for vertex in vertices:
graph.addVertex(vertex)
for edge in edges:
graph.addEdge(edge)
graph.updateConnectivityValues()
for i, cv_ in enumerate([11, 15, 18, 10, 7, 11]):
cv = vertices[i].connectivity
self.assertEqual(cv, cv_, "On vertex {0:d} got connectivity[0]={1:d} but expected {2:d}".format(i, cv, cv_))
示例3: test_getLargestRing
# 需要導入模塊: from rmgpy.molecule.graph import Graph [as 別名]
# 或者: from rmgpy.molecule.graph.Graph import updateConnectivityValues [as 別名]
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)
示例4: test_vertex_connectivity_values
# 需要導入模塊: from rmgpy.molecule.graph import Graph [as 別名]
# 或者: from rmgpy.molecule.graph.Graph import updateConnectivityValues [as 別名]
def test_vertex_connectivity_values(self):
"""
Tests the vertex connectivity values as introduced by Morgan (1965).
First CV1 is the number of neighbours
CV2 is the sum of neighbouring CV1 values
CV3 is the sum of neighbouring CV2 values
Graph: Expected (and tested) values:
0-1-2-3-4 1-3-2-2-1 3-4-5-3-2 4-11-7-7-3
| | | |
5 1 3 4
"""
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[1], vertices[5]),
]
graph = Graph()
for vertex in vertices: graph.addVertex(vertex)
for edge in edges: graph.addEdge(edge)
graph.updateConnectivityValues()
for i,cv_ in enumerate([1,3,2,2,1,1]):
cv = vertices[i].connectivity1
self.assertEqual(cv, cv_, "On vertex {0:d} got connectivity[0]={1:d} but expected {2:d}".format(i,cv,cv_))
for i,cv_ in enumerate([3,4,5,3,2,3]):
cv = vertices[i].connectivity2
self.assertEqual(cv, cv_, "On vertex {0:d} got connectivity[0]={1:d} but expected {2:d}".format(i,cv,cv_))
for i,cv_ in enumerate([4,11,7,7,3,4]):
cv = vertices[i].connectivity3
self.assertEqual(cv, cv_, "On vertex {0:d} got connectivity[0]={1:d} but expected {2:d}".format(i,cv,cv_))
示例5: TestGraph
# 需要導入模塊: from rmgpy.molecule.graph import Graph [as 別名]
# 或者: from rmgpy.molecule.graph.Graph import updateConnectivityValues [as 別名]
#.........這裏部分代碼省略.........
]
graph1 = Graph()
for vertex in vertices1: graph1.addVertex(vertex)
for edge in edges1: graph1.addEdge(edge)
graph2 = Graph()
for vertex in vertices2: graph2.addVertex(vertex)
for edge in edges2: graph2.addEdge(edge)
graph = graph1.merge(graph2)
self.assertTrue(len(graph1.vertices) + len(graph2.vertices) == len(graph.vertices))
for vertex1 in vertices1:
self.assertTrue(vertex1 in graph.vertices)
for vertex2 in vertex1.edges:
self.assertTrue(vertex2 in graph.vertices)
for vertex2 in vertices2:
self.assertTrue(vertex2 in graph.vertices)
for vertex1 in vertex2.edges:
self.assertTrue(vertex1 in vertex2.edges)
def test_resetConnectivityValues(self):
"""
Test the Graph.resetConnectivityValues() method.
"""
self.graph.resetConnectivityValues()
for vertex in self.graph.vertices:
self.assertEqual(vertex.connectivity1, -1)
self.assertEqual(vertex.connectivity2, -1)
self.assertEqual(vertex.connectivity3, -1)
self.assertEqual(vertex.sortingLabel, -1)
def test_updateConnectivityValues(self):
"""
Test the Graph.updateConnectivityValues() method.
"""
self.graph.updateConnectivityValues()
self.assertEqual(self.graph.vertices[0].connectivity1, 1)
self.assertEqual(self.graph.vertices[0].connectivity2, 2)
self.assertEqual(self.graph.vertices[0].connectivity3, 3)
self.assertEqual(self.graph.vertices[0].sortingLabel, -1)
self.assertEqual(self.graph.vertices[1].connectivity1, 2)
self.assertEqual(self.graph.vertices[1].connectivity2, 3)
self.assertEqual(self.graph.vertices[1].connectivity3, 6)
self.assertEqual(self.graph.vertices[1].sortingLabel, -1)
self.assertEqual(self.graph.vertices[2].connectivity1, 2)
self.assertEqual(self.graph.vertices[2].connectivity2, 4)
self.assertEqual(self.graph.vertices[2].connectivity3, 7)
self.assertEqual(self.graph.vertices[2].sortingLabel, -1)
self.assertEqual(self.graph.vertices[3].connectivity1, 2)
self.assertEqual(self.graph.vertices[3].connectivity2, 4)
self.assertEqual(self.graph.vertices[3].connectivity3, 7)
self.assertEqual(self.graph.vertices[3].sortingLabel, -1)
self.assertEqual(self.graph.vertices[4].connectivity1, 2)
self.assertEqual(self.graph.vertices[4].connectivity2, 3)
self.assertEqual(self.graph.vertices[4].connectivity3, 6)
self.assertEqual(self.graph.vertices[4].sortingLabel, -1)
self.assertEqual(self.graph.vertices[5].connectivity1, 1)
self.assertEqual(self.graph.vertices[5].connectivity2, 2)
self.assertEqual(self.graph.vertices[5].connectivity3, 3)
self.assertEqual(self.graph.vertices[5].sortingLabel, -1)
def test_sortVertices(self):
"""
Test the Graph.sortVertices() method.
示例6: test_getPolycyclicRings
# 需要導入模塊: from rmgpy.molecule.graph import Graph [as 別名]
# 或者: from rmgpy.molecule.graph.Graph import updateConnectivityValues [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)
示例7: TestGraph
# 需要導入模塊: from rmgpy.molecule.graph import Graph [as 別名]
# 或者: from rmgpy.molecule.graph.Graph import updateConnectivityValues [as 別名]
#.........這裏部分代碼省略.........
graph1 = Graph()
for vertex in vertices1:
graph1.addVertex(vertex)
for edge in edges1:
graph1.addEdge(edge)
graph2 = Graph()
for vertex in vertices2:
graph2.addVertex(vertex)
for edge in edges2:
graph2.addEdge(edge)
graph = graph1.merge(graph2)
self.assertTrue(len(graph1.vertices) + len(graph2.vertices) == len(graph.vertices))
for vertex1 in vertices1:
self.assertTrue(vertex1 in graph.vertices)
for vertex2 in vertex1.edges:
self.assertTrue(vertex2 in graph.vertices)
for vertex2 in vertices2:
self.assertTrue(vertex2 in graph.vertices)
for vertex1 in vertex2.edges:
self.assertTrue(vertex1 in vertex2.edges)
def test_resetConnectivityValues(self):
"""
Test the Graph.resetConnectivityValues() method.
"""
self.graph.resetConnectivityValues()
for vertex in self.graph.vertices:
self.assertEqual(vertex.connectivity, -1)
self.assertEqual(vertex.sortingLabel, -1)
def test_updateConnectivityValues(self):
"""
Test the Graph.updateConnectivityValues() method.
"""
self.graph.updateConnectivityValues()
self.assertEqual(self.graph.vertices[0].connectivity, 10)
self.assertEqual(self.graph.vertices[0].sortingLabel, -1)
self.assertEqual(self.graph.vertices[1].connectivity, 19)
self.assertEqual(self.graph.vertices[1].sortingLabel, -1)
self.assertEqual(self.graph.vertices[2].connectivity, 23)
self.assertEqual(self.graph.vertices[2].sortingLabel, -1)
self.assertEqual(self.graph.vertices[3].connectivity, 23)
self.assertEqual(self.graph.vertices[3].sortingLabel, -1)
self.assertEqual(self.graph.vertices[4].connectivity, 19)
self.assertEqual(self.graph.vertices[4].sortingLabel, -1)
self.assertEqual(self.graph.vertices[5].connectivity, 10)
self.assertEqual(self.graph.vertices[5].sortingLabel, -1)
def test_sortVertices(self):
"""
Test the Graph.sortVertices() method.
"""
self.graph.updateConnectivityValues()
self.graph.sortVertices()
for vertex1, vertex2 in zip(self.graph.vertices[:-1], self.graph.vertices[1:]):
self.assertTrue(vertex1.sortingLabel < vertex2.sortingLabel)
self.assertTrue(vertex1.connectivity >= vertex2.connectivity)
def test_vertex_connectivity_values(self):
"""
Tests the vertex connectivity values as introduced by Morgan (1965).
Graph: Expected (and tested) values:
示例8: TestGraph
# 需要導入模塊: from rmgpy.molecule.graph import Graph [as 別名]
# 或者: from rmgpy.molecule.graph.Graph import updateConnectivityValues [as 別名]
#.........這裏部分代碼省略.........
]
graph1 = Graph()
for vertex in vertices1: graph1.addVertex(vertex)
for edge in edges1: graph1.addEdge(edge)
graph2 = Graph()
for vertex in vertices2: graph2.addVertex(vertex)
for edge in edges2: graph2.addEdge(edge)
graph = graph1.merge(graph2)
self.assertTrue(len(graph1.vertices) + len(graph2.vertices) == len(graph.vertices))
for vertex1 in vertices1:
self.assertTrue(vertex1 in graph.vertices)
for vertex2 in vertex1.edges:
self.assertTrue(vertex2 in graph.vertices)
for vertex2 in vertices2:
self.assertTrue(vertex2 in graph.vertices)
for vertex1 in vertex2.edges:
self.assertTrue(vertex1 in vertex2.edges)
def test_resetConnectivityValues(self):
"""
Test the Graph.resetConnectivityValues() method.
"""
self.graph.resetConnectivityValues()
for vertex in self.graph.vertices:
self.assertEqual(vertex.connectivity1, -1)
self.assertEqual(vertex.connectivity2, -1)
self.assertEqual(vertex.connectivity3, -1)
self.assertEqual(vertex.sortingLabel, -1)
def test_updateConnectivityValues(self):
"""
Test the Graph.updateConnectivityValues() method.
"""
self.graph.updateConnectivityValues()
self.assertEqual(self.graph.vertices[0].connectivity1, 1)
self.assertEqual(self.graph.vertices[0].connectivity2, 2)
self.assertEqual(self.graph.vertices[0].connectivity3, 3)
self.assertEqual(self.graph.vertices[0].sortingLabel, -1)
self.assertEqual(self.graph.vertices[1].connectivity1, 2)
self.assertEqual(self.graph.vertices[1].connectivity2, 3)
self.assertEqual(self.graph.vertices[1].connectivity3, 6)
self.assertEqual(self.graph.vertices[1].sortingLabel, -1)
self.assertEqual(self.graph.vertices[2].connectivity1, 2)
self.assertEqual(self.graph.vertices[2].connectivity2, 4)
self.assertEqual(self.graph.vertices[2].connectivity3, 7)
self.assertEqual(self.graph.vertices[2].sortingLabel, -1)
self.assertEqual(self.graph.vertices[3].connectivity1, 2)
self.assertEqual(self.graph.vertices[3].connectivity2, 4)
self.assertEqual(self.graph.vertices[3].connectivity3, 7)
self.assertEqual(self.graph.vertices[3].sortingLabel, -1)
self.assertEqual(self.graph.vertices[4].connectivity1, 2)
self.assertEqual(self.graph.vertices[4].connectivity2, 3)
self.assertEqual(self.graph.vertices[4].connectivity3, 6)
self.assertEqual(self.graph.vertices[4].sortingLabel, -1)
self.assertEqual(self.graph.vertices[5].connectivity1, 1)
self.assertEqual(self.graph.vertices[5].connectivity2, 2)
self.assertEqual(self.graph.vertices[5].connectivity3, 3)
self.assertEqual(self.graph.vertices[5].sortingLabel, -1)
def test_sortVertices(self):
"""
Test the Graph.sortVertices() method.