Example #1
0
 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)
Example #2
0
 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)
Example #3
0
 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 xrange(size)])
     CustomPattern.__init__(self, pattern_graph, criteria_sets, vertex_tags)
 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)
Example #5
0
 def check_next_match(self, match, new_relations, subject_graph, one_match):
     """Check if the (onset for a) match can be a valid (part of a) ring"""
     if not CustomPattern.check_next_match(self, match, new_relations, subject_graph, one_match):
         return False
     if self.strong:
         # can this ever become a strong ring?
         vertex1_start = match.forward[self.pattern_graph.central_vertex]
         for vertex1 in new_relations.itervalues():
             paths = list(subject_graph.iter_shortest_paths(vertex1, vertex1_start))
             if self.size % 2 == 0 and len(match) == self.size:
                 if len(paths) != 2:
                     #print "NRingPattern.check_next_match: not strong a.1"
                     return False
                 for path in paths:
                     if len(path) != len(match)/2+1:
                         #print "NRingPattern.check_next_match: not strong a.2"
                         return False
             else:
                 if len(paths) != 1:
                     #print "NRingPattern.check_next_match: not strong b.1"
                     return False
                 if len(paths[0]) != (len(match)+1)/2:
                     #print "NRingPattern.check_next_match: not strong b.2"
                     return False
         #print "RingPattern.check_next_match: no remarks"
     return True
Example #6
0
 def check_next_match(self, match, new_relations, subject_graph, one_match):
     """Check if the (onset for a) match can be a valid (part of a) ring"""
     if not CustomPattern.check_next_match(self, match, new_relations,
                                           subject_graph, one_match):
         return False
     if self.strong:
         # can this ever become a strong ring?
         vertex1_start = match.forward[self.pattern_graph.central_vertex]
         for vertex1 in new_relations.values():
             paths = list(
                 subject_graph.iter_shortest_paths(vertex1, vertex1_start))
             if self.size % 2 == 0 and len(match) == self.size:
                 if len(paths) != 2:
                     #print "NRingPattern.check_next_match: not strong a.1"
                     return False
                 for path in paths:
                     if len(path) != len(match) // 2 + 1:
                         #print "NRingPattern.check_next_match: not strong a.2"
                         return False
             else:
                 if len(paths) != 1:
                     #print "NRingPattern.check_next_match: not strong b.1"
                     return False
                 if len(paths[0]) != (len(match) + 1) // 2:
                     #print "NRingPattern.check_next_match: not strong b.2"
                     return False
         #print "RingPattern.check_next_match: no remarks"
     return True
Example #7
0
 def complete(self, match, subject_graph):
     """Check the completeness of the ring match"""
     if not CustomPattern.complete(self, match, subject_graph):
         return False
     if self.strong:
         # If the ring is not strong, return False
         if self.size % 2 == 0:
             # even ring
             for i in range(self.size // 2):
                 vertex1_start = match.forward[i]
                 vertex1_stop = match.forward[(i + self.size // 2) %
                                              self.size]
                 paths = list(
                     subject_graph.iter_shortest_paths(
                         vertex1_start, vertex1_stop))
                 if len(paths) != 2:
                     #print "Even ring must have two paths between opposite vertices"
                     return False
                 for path in paths:
                     if len(path) != self.size // 2 + 1:
                         #print "Paths between opposite vertices must half the size of the ring+1"
                         return False
         else:
             # odd ring
             for i in range(self.size // 2 + 1):
                 vertex1_start = match.forward[i]
                 vertex1_stop = match.forward[(i + self.size // 2) %
                                              self.size]
                 paths = list(
                     subject_graph.iter_shortest_paths(
                         vertex1_start, vertex1_stop))
                 if len(paths) > 1:
                     return False
                 if len(paths[0]) != self.size // 2 + 1:
                     return False
                 vertex1_stop = match.forward[(i + self.size // 2 + 1) %
                                              self.size]
                 paths = list(
                     subject_graph.iter_shortest_paths(
                         vertex1_start, vertex1_stop))
                 if len(paths) > 1:
                     return False
                 if len(paths[0]) != self.size // 2 + 1:
                     return False
     return True
Example #8
0
 def complete(self, match, subject_graph):
     """Check the completeness of the ring match"""
     if not CustomPattern.complete(self, match, subject_graph):
         return False
     if self.strong:
         # If the ring is not strong, return False
         if self.size % 2 == 0:
             # even ring
             for i in xrange(self.size/2):
                 vertex1_start = match.forward[i]
                 vertex1_stop = match.forward[i+self.size/2]
                 paths = list(subject_graph.iter_shortest_paths(vertex1_start, vertex1_stop))
                 if len(paths) != 2:
                     #print "Even ring must have two paths between opposite vertices"
                     return False
                 for path in paths:
                     if len(path) != self.size/2+1:
                         #print "Paths between opposite vertices must half the size of the ring+1"
                         return False
         else:
             # odd ring
             for i in xrange(self.size/2+1):
                 vertex1_start = match.forward[i]
                 vertex1_stop = match.forward[i+self.size/2]
                 paths = list(subject_graph.iter_shortest_paths(vertex1_start, vertex1_stop))
                 if len(paths) > 1:
                     return False
                 if len(paths[0]) != self.size/2+1:
                     return False
                 vertex1_stop = match.forward[i+self.size/2+1]
                 paths = list(subject_graph.iter_shortest_paths(vertex1_start, vertex1_stop))
                 if len(paths) > 1:
                     return False
                 if len(paths[0]) != self.size/2+1:
                     return False
     return True