def __init__(self, pg_low, pg_high, enforce_point_group=True, as_xyz=False): # It is rather import (i think) to make sure # that point groups are supplied. This might prevent later surprises. # hopefully. self.as_xyz = as_xyz low_point_group_check = (pg_low == pg_low.build_derived_point_group()) if enforce_point_group: if not low_point_group_check: raise Sorry("Input spacegroup not a point group") high_point_group_check = ( pg_high == pg_high.build_derived_point_group()) if enforce_point_group: if not high_point_group_check: raise Sorry("Input spacegroup not a point group") self.assert_pg = enforce_point_group self.graph = graph_tools.graph() self.pg_low = pg_low self.pg_high = pg_high self.queue = [] # the queue used in building the space_group self.build_it() del self.queue # you have no business looking at this object, # so I delete it .. ;-) self.graph.assert_is_clean()
def __init__(self, pg_low, pg_high, enforce_point_group=True, as_xyz = False): # It is rather import (i think) to make sure # that point groups are supplied. This might prevent later surprises. # hopefully. self.as_xyz = as_xyz low_point_group_check = (pg_low == pg_low.build_derived_point_group()) if enforce_point_group: if not low_point_group_check: raise Sorry("Input spacegroup not a point group") high_point_group_check = (pg_high == pg_high.build_derived_point_group()) if enforce_point_group: if not high_point_group_check: raise Sorry("Input spacegroup not a point group") self.assert_pg = enforce_point_group self.graph = graph_tools.graph() self.pg_low = pg_low self.pg_high = pg_high self.queue = [] # the queue used in building the space_group self.build_it() del self.queue # you have no business looking at this object, # so I delete it .. ;-) self.graph.assert_is_clean()
def tst_graph(): ll = gt.graph() ll.insert_node( name = 'a', node_object = 'ploep_a', edge_object = { 'b': 'a_to_b', 'c': 'a_to_c' } ) ll.insert_node( name = 'b', node_object = 'ploep_b', edge_object = { 'c': 'b_to_c' } ) ll.insert_node( name = 'c', node_object = 'ploep_c', edge_object = { } ) path_found = ll.find_all_paths('a', 'c') path_possible = [['a', 'c'], ['a', 'b', 'c']] for path in path_possible: assert (path in path_found) shortest = ll.find_shortest_path('a', 'c') assert (shortest == ['a','c']) assert ( (ll.o == { 'a':['b','c'], 'b':['c'],'c':[] }) or (ll.o == { 'a':['c','b'], 'b':['c'],'c':[] }) ) kk = gt.graph() kk.insert_node( name = 'a', node_object = 'ploep_a', edge_object = { 'b': 'a_to_b', 'c': 'a_to_c' } ) kk.insert_node( name = 'b', node_object = 'ploep_b', edge_object = { 'c': 'b_to_c' } ) kk.insert_node( name = 'c', node_object = 'ploep_c', edge_object = { } ) assert ll.is_equivalent_to( kk ) kk.insert_node( name = 'b', node_object=None, edge_object={ 'a': 'b_to_a'} ) assert ll.is_contained_in( kk ) assert not kk.is_contained_in( ll ) ll.assert_is_clean() kk.assert_is_clean() kk.remove_node( 'b' ) kk.assert_is_clean() kk.insert_node( name = 'a', node_object = 'ploep_a', edge_object = { 'b': 'a_to_b', 'c': 'a_to_c' } ) kk.insert_node( name = 'b', node_object = 'ploep_b', edge_object = { 'c': 'b_to_c' } ) kk.insert_node( name = 'd', node_object = 'ploep_a', edge_object = { 'b': 'd_to_b', 'c': 'd_to_c' } ) kk.insert_node( name = 'e', node_object = 'ploep_b', edge_object = { 'd': 'e_to_d' } ) kk.insert_node( name = 'c', node_object = 'ploep_b', edge_object = { 'd': 'c_to_d' } ) a_paths = [['a', 'c', 'd'], ['a', 'b', 'c']] c_paths = [['c', 'd', 'b']] b_paths = [['b', 'c', 'd']] e_paths = [['e', 'd', 'c'], ['e', 'd', 'b']] d_paths = [['d', 'b', 'c']] for ps, solution in [('a', a_paths), ('b', b_paths), ('c', c_paths), ('d', d_paths), ('e', e_paths)]: for p in kk.find_paths_of_length(ps, 3): assert p in solution
def tst_graph(): ll = gt.graph() ll.insert_node( name = 'a', node_object = 'ploep_a', edge_object = { 'b': 'a_to_b', 'c': 'a_to_c' } ) ll.insert_node( name = 'b', node_object = 'ploep_b', edge_object = { 'c': 'b_to_c' } ) ll.insert_node( name = 'c', node_object = 'ploep_c', edge_object = { } ) path_found = ll.find_all_paths('a', 'c') path_possible = [['a', 'c'], ['a', 'b', 'c']] for path in path_possible: assert (path in path_found) shortest = ll.find_shortest_path('a', 'c') assert (shortest == ['a','c']) assert ( (ll.o == { 'a':['b','c'], 'b':['c'],'c':[] }) or (ll.o == { 'a':['c','b'], 'b':['c'],'c':[] }) ) kk = gt.graph() kk.insert_node( name = 'a', node_object = 'ploep_a', edge_object = { 'b': 'a_to_b', 'c': 'a_to_c' } ) kk.insert_node( name = 'b', node_object = 'ploep_b', edge_object = { 'c': 'b_to_c' } ) kk.insert_node( name = 'c', node_object = 'ploep_c', edge_object = { } ) assert ll.is_equivalent_to( kk ) kk.insert_node( name = 'b', node_object=None, edge_object={ 'a': 'b_to_a'} ) assert ll.is_contained_in( kk ) assert not kk.is_contained_in( ll ) ll.assert_is_clean() kk.assert_is_clean() kk.remove_node( 'b' ) kk.assert_is_clean() kk.insert_node( name = 'a', node_object = 'ploep_a', edge_object = { 'b': 'a_to_b', 'c': 'a_to_c' } ) kk.insert_node( name = 'b', node_object = 'ploep_b', edge_object = { 'c': 'b_to_c' } ) kk.insert_node( name = 'd', node_object = 'ploep_a', edge_object = { 'b': 'd_to_b', 'c': 'd_to_c' } ) kk.insert_node( name = 'e', node_object = 'ploep_b', edge_object = { 'd': 'e_to_d' } ) kk.insert_node( name = 'c', node_object = 'ploep_b', edge_object = { 'd': 'c_to_d' } ) a_paths = [['a', 'c', 'd'], ['a', 'b', 'c']] c_paths = [['c', 'd', 'b']] b_paths = [['b', 'c', 'd']] e_paths = [['e', 'd', 'c'], ['e', 'd', 'b']] d_paths = [['d', 'b', 'c']] assert kk.find_paths_of_length( 'a' , 3 ) == a_paths assert kk.find_paths_of_length( 'b' , 3 ) == b_paths assert kk.find_paths_of_length( 'c' , 3 ) == c_paths assert kk.find_paths_of_length( 'd' , 3 ) == d_paths assert kk.find_paths_of_length( 'e' , 3 ) == e_paths