def __init__(self, edges, numbers, orders=None, symbols=None, num_vertices=None): """ Arguments: | ``edges`` -- See base class (Graph) documentation | ``numbers`` -- consecutive atom numbers Optional arguments: | ``orders`` -- bond orders | ``symbols`` -- atomic symbols | ``num_vertices`` -- must be the same as the number of atoms or None When the nature of an atom or a bond is unclear ambiguous, set the corresponding integer to zero. This means the nature of the atom or bond is unspecified. When the bond orders are not given, they are all set to zero. If you want to use 'special' atom types, use negative numbers. The same for bond orders. e.g. a nice choice for the bond order of a hybrid bond is -1. """ if num_vertices is not None and num_vertices != len(numbers): raise ValueError( 'The number of vertices must be the same as the number of atoms.' ) if orders is None: orders = np.ones(len(edges), float) Graph.__init__(self, edges, len(numbers)) self.numbers = numbers self.orders = orders self.symbols = symbols
def __init__(self, edges, numbers, orders=None, symbols=None, num_vertices=None): """ Arguments: | ``edges`` -- See base class (Graph) documentation | ``numbers`` -- consecutive atom numbers Optional arguments: | ``orders`` -- bond orders | ``symbols`` -- atomic symbols | ``num_vertices`` -- must be the same as the number of atoms or None When the nature of an atom or a bond is unclear ambiguous, set the corresponding integer to zero. This means the nature of the atom or bond is unspecified. When the bond orders are not given, they are all set to zero. If you want to use 'special' atom types, use negative numbers. The same for bond orders. e.g. a nice choice for the bond order of a hybrid bond is -1. """ if num_vertices is not None and num_vertices != len(numbers): raise ValueError('The number of vertices must be the same as the number of atoms.') if orders is None: orders = numpy.ones(len(edges), float) Graph.__init__(self, edges, len(numbers)) self.numbers = numbers self.orders = orders self.symbols = symbols
def __init__(self, pairs, numbers, orders=None): """Initialize a molecular graph Arguments: pairs -- See base class (Graph) documentation numbers -- consecutive atom numbers orders -- bond orders When the nature of an atom or a bond is unclear ambiguous, set the corresponding integer to zero. This means the nature of the atom or bond is unspecified. When the bond orders are not given, they are all set to zero. If you want to use 'special' atom types, use negative numbers. The same for bond orders. e.g. a nice choice for the bond order of a hybrid bond is -1. """ if orders is None: orders = numpy.zeros(len(pairs), dtype=int) elif len(orders) != len(pairs): raise ValueError("The number of (bond) orders must be equal to the number of pairs") Graph.__init__(self, pairs, len(numbers)) self._numbers = numpy.array(numbers) self._numbers.setflags(write=False) self._orders = numpy.array(orders) self._orders.setflags(write=False)
def get_node_string(self, i): number = self.numbers[i] if number == 0: return Graph.get_node_string(self, i) else: # pad with zeros to make sure that string sort is identical to number sort return "%03i" % number
def get_subgraph(self, subvertices, normalize=False): """Creates a subgraph of the current graph See :meth:`molmod.graphs.Graph.get_subgraph` for more information. """ graph = Graph.get_subgraph(self, subvertices, normalize) if normalize: new_numbers = self.numbers[ graph._old_vertex_indexes] # vertices do change else: new_numbers = self.numbers # vertices don't change! if self.symbols is None: new_symbols = None elif normalize: new_symbols = tuple(self.symbols[i] for i in graph._old_vertex_indexes) else: new_symbols = self.symbols new_orders = self.orders[graph._old_edge_indexes] result = MolecularGraph(graph.edges, new_numbers, new_orders, new_symbols) if normalize: result._old_vertex_indexes = graph._old_vertex_indexes result._old_edge_indexes = graph._old_edge_indexes return result
def get_pair_string(self, i): order = self.orders[i] if order == 0: return Graph.get_pair_string(self, i) else: # pad with zeros to make sure that string sort is identical to number sort return "%03i" % order
def get_vertex_string(self, i): """Return a string based on the atom number""" number = self.numbers[i] if number == 0: return Graph.get_vertex_string(self, i) else: # pad with zeros to make sure that string sort is identical to number sort return "%03i" % number
def __init__(self, criteria_sets=None, vertex_tags=None): """ Arguments: see :class:`molmod.graphs.CustomPattern` """ if vertex_tags is None: vertex_tags = {} pattern_graph = Graph([(0, 1), (0, 2), (0, 3), (0, 4)]) CustomPattern.__init__(self, pattern_graph, criteria_sets, vertex_tags)
def get_edge_string(self, i): """Return a string based on the bond order""" order = self.orders[i] if order == 0: return Graph.get_edge_string(self, i) else: # pad with zeros to make sure that string sort is identical to number sort return "%03i" % order
def __init__(self, size, criteria_sets=None, vertex_tags=None, strong=False): """ Argument: | ``size`` -- the size of the ring """ if vertex_tags is None: vertex_tags = {} self.size = size self.strong = strong pattern_graph = Graph([(i, (i+1)%size) for i in range(size)]) CustomPattern.__init__(self, pattern_graph, criteria_sets, vertex_tags)
def __mul__(self, repeat): result = Graph.__mul__(self, repeat) result.__class__ = MolecularGraph # copy numbers numbers = numpy.zeros((repeat, len(self.numbers)), int) numbers[:] = self.numbers result._numbers = numbers.ravel() result._numbers.setflags(write=False) # copy orders orders = numpy.zeros((repeat, len(self.orders)), int) orders[:] = self.orders result._orders = orders.ravel() result._orders.setflags(write=False) return result
def make_graph_distance_matrix(system): """Return a bond graph distance matrix. Parameters ---------- system : System Molecule (with bonds) for which the graph distances must be computed. The graph distance is used for comparison because it allows the pattern matching to make optimal choices of which pairs of atoms to compare next, i.e. both bonded or nearby the last matched pair. """ from molmod.graphs import Graph return Graph(system.bonds, system.natom).distances
def get_subgraph(self, subnodes, normalize=False): """Creates a subgraph of the current graph. See help(Graph.get_subgraph) for more information. """ result = Graph.get_subgraph(self, subnodes, normalize) result.__class__ = MolecularGraph if normalize: result._numbers = self.numbers[result.old_node_indexes] # nodes do change result._numbers.setflags(write=False) else: result._numbers = self.numbers # nodes don't change! result._orders = self.orders[result.old_pair_indexes] result._orders.setflags(write=False) return result
def get_subgraph(self, subvertices, normalize=False): """Creates a subgraph of the current graph See :meth:`molmod.graphs.Graph.get_subgraph` for more information. """ graph = Graph.get_subgraph(self, subvertices, normalize) if normalize: new_numbers = self.numbers[graph._old_vertex_indexes] # vertices do change else: new_numbers = self.numbers # vertices don't change! if self.symbols is None: new_symbols = None elif normalize: new_symbols = tuple(self.symbols[i] for i in graph._old_vertex_indexes) else: new_symbols = self.symbols new_orders = self.orders[graph._old_edge_indexes] result = MolecularGraph(graph.edges, new_numbers, new_orders, new_symbols) if normalize: result._old_vertex_indexes = graph._old_vertex_indexes result._old_edge_indexes = graph._old_edge_indexes return result
def get_graph(self): """Return the bond graph represented by the data structure""" return Graph(self.bonds)
def get_graph(self): return Graph(self.bonds)
def __init__(self, criteria_sets=None, node_tags={}): subgraph = Graph([(0, 1), (0, 2), (0, 3), (0, 4)]) SubgraphPattern.__init__(self, subgraph, criteria_sets, node_tags)
def __init__(self, size, criteria_sets=None, node_tags={}, strong=False): self.size = size self.strong = strong subgraph = Graph([(i,(i+1)%size) for i in xrange(size)]) SubgraphPattern.__init__(self, subgraph, criteria_sets, node_tags)