allpy
view allpy/graph.py @ 481:b92cad794578
allpy/structure: remove Sequence.pdb_residues, add Monomer.pdb_residue
Information from aequence.pdb_residues[monomer] is
now available in monomer.pdb_residue
author | boris (netbook) <bnagaev@gmail.com> |
---|---|
date | Fri, 18 Feb 2011 18:48:37 +0300 |
parents | e4c4151b9dc3 |
children | 1f387f24c7c6 |
line source
5 pass
10 """ Undirected weighted graph
12 Data:
13 vertices -- set of elements
14 edges -- {edge: weight}.
15 edge is frozenset([e1, e2])
16 weight is float in (0, 1] or 1 (if all edges are equal)
18 >>> g = Graph(set([1,2,3]), {frozenset([1,2]): 1})
19 >>> g.fast_cliques()
20 Fast algorithm started
21 [frozenset([1, 2]), frozenset([3])]
22 >>> g = Graph(set([1,2,3]), {frozenset([1,2]): 1, frozenset([1,1]): 1})
23 >>> g.fast_cliques()
24 Fast algorithm started
25 [frozenset([1, 2]), frozenset([3])]
26 >>> g = Graph(set([1,2,3,4]), {frozenset([1,2]): 0.98,
27 ... frozenset([1,3]): 0.98, frozenset([2,3]): 0.1,
28 ... frozenset([1,1]): 1})
29 >>> g.fast_cliques()
30 Fast algorithm started
31 [frozenset([1, 2, 3]), frozenset([4])]
32 >>> g.fast_cliques(minsize=2)
33 Fast algorithm started
34 [frozenset([1, 2, 3])]
35 >>> g.bron_kerbosh()
36 Bron and Kerbosh algorithm started
37 [frozenset([1, 2, 3]), frozenset([4])]
38 >>> g.cliques()
39 Bron and Kerbosh algorithm started
40 [frozenset([1, 2, 3]), frozenset([4])]
41 >>> g.cliques(minsize=2)
42 Bron and Kerbosh algorithm started
43 [frozenset([1, 2, 3])]
44 >>> g.vertices
45 set([1, 2, 3, 4])
46 """
59 @staticmethod
61 """ Construct object, representing edge of graph """
65 """ if these two vertices of the graph are bounded with edge """
69 """ Returns number of connections of this vertex """
74 """ Returns sum of weights of all connections of this vertex """
79 """ Returns {vertex: number of connections of this vertex} """
88 """ Remove vertex and all involved edges """
94 """ Add vertex and corresponding edges from parent_graph
96 Added edges should be contained in self graph
97 (takes care of hanging edges)
98 """
106 """ Run drop_vertex for each of given vertices """
111 """ Bron and Kerboch algorithm implementation
113 returns list of cliques
114 clique is frozenset
115 if timeout=-1, it means infinity
116 if timeout has happened, raises TimeoutError
117 """
128 """ return vertex with max count (and weight) """
141 """ return some v from candidates """
145 """ if v from used connected with all from candidates """
149 break
155 """ process call and return list of recursive calls """
189 """ drop vertices untill self becomes a clique """
191 # drop vertices, while its is possible
193 break
199 break
206 break
209 """ add vertices untill self becomes a nonextendible clique """
211 # add vertices, while its is possible
221 break
228 """ returns list of cliques
230 clique is frozenset
231 """
239 break
246 break
251 """ returns length-sorted list of cliques
253 clique is frozenset
255 try to execute bron_kerbosh
256 if it raises TimeoutError, executes fast_cliques
257 """