def testCountYields4(self):
     adj = dok_matrix((10, 10), dtype=np.float32)
     adj_dict = {
         (0, 1): 8.0,
         (1, 0): 8.0,
         (1, 2): 4.0,
         (2, 1): 8.0,
         (2, 3): 4.0,
         (3, 2): 8.0,
         (3, 4): 5.0,
         (4, 3): 8.0,
         (5, 4): 8.0,
         (4, 5): 5.0,
         (5, 6): 4.0,
         (6, 5): 8.0,
         (7, 8): 8.0,
         (8, 7): 8.0,
         (0, 8): 4.0,
         (8, 0): 5.0,
         (8, 9): 4.0,
         (9, 8): 8.0
     }
     for key, val in adj_dict.items():
         adj[key] = val
     olig_len_dict, olig_monos_dict, olig_branch_dict, olig_branch_coeff_dict = count_oligomer_yields(
         adj)
     good_olig_len_dict = {10: 1}
     good_olig_monos_dict = {10: 10}
     good_olig_branch_dict = {10: 1}
     good_olig_branch_coeff_dict = {10: 0.1}
     self.assertTrue(olig_len_dict == good_olig_len_dict)
     self.assertTrue(olig_monos_dict == good_olig_monos_dict)
     self.assertTrue(olig_branch_dict == good_olig_branch_dict)
     self.assertTrue(olig_branch_coeff_dict == good_olig_branch_coeff_dict)
 def testCountYields3(self):
     olig_len_dict, olig_monos_dict, olig_branch_dict, olig_branch_coeff_dict = count_oligomer_yields(ADJ3)
     good_olig_len_dict = {1: 2, 3: 1}
     good_olig_monos_dict = {1: 2, 3: 3}
     good_olig_branch_dict = {1: 0, 3: 0}
     good_olig_branch_coeff_dict = {1: 0, 3: 0}
     self.assertTrue(olig_len_dict == good_olig_len_dict)
     self.assertTrue(olig_monos_dict == good_olig_monos_dict)
     self.assertTrue(olig_branch_dict == good_olig_branch_dict)
     self.assertTrue(olig_branch_coeff_dict == good_olig_branch_coeff_dict)
 def testCountYields2(self):
     olig_len_dict, olig_monos_dict, olig_branch_dict, olig_branch_coeff_dict = count_oligomer_yields(ADJ2)
     good_olig_len_dict = {1: 1, 2: 2}
     good_olig_monos_dict = {1: 1, 2: 4}
     good_olig_branch_dict = {1: 0, 2: 0}
     good_olig_branch_coeff_dict = {1: 0, 2: 0}
     self.assertTrue(olig_len_dict == good_olig_len_dict)
     self.assertTrue(olig_monos_dict == good_olig_monos_dict)
     self.assertTrue(olig_branch_dict == good_olig_branch_dict)
     self.assertTrue(olig_branch_coeff_dict == good_olig_branch_coeff_dict)
 def testCountYieldsAllMonomers(self):
     good_olig_len_dict = {1: 5}
     good_olig_monos_dict = {1: 5}
     good_olig_branch_dict = {1: 0}
     good_olig_branch_coeff_dict = {1: 0}
     olig_len_dict, olig_monos_dict, olig_branch_dict, olig_branch_coeff_dict = count_oligomer_yields(ADJ_ZEROS)
     self.assertTrue(olig_len_dict == good_olig_len_dict)
     self.assertTrue(olig_monos_dict == good_olig_monos_dict)
     self.assertTrue(olig_branch_dict == good_olig_branch_dict)
     self.assertTrue(olig_branch_coeff_dict == good_olig_branch_coeff_dict)
 def testCountYields1(self):
     adj_1 = dok_matrix([[0, 4, 0, 0, 0], [8, 0, 0, 0, 0], [0, 0, 0, 0, 0],
                         [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]])
     good_olig_len_dict = {1: 3, 2: 1}
     good_olig_monos_dict = {1: 3, 2: 2}
     good_olig_branch_dict = {1: 0, 2: 0}
     good_olig_branch_coeff_dict = {1: 0, 2: 0}
     olig_len_dict, olig_monos_dict, olig_branch_dict, olig_branch_coeff_dict = count_oligomer_yields(
         adj_1)
     self.assertTrue(olig_len_dict == good_olig_len_dict)
     self.assertTrue(olig_monos_dict == good_olig_monos_dict)
     self.assertTrue(olig_branch_dict == good_olig_branch_dict)
     self.assertTrue(olig_branch_coeff_dict == good_olig_branch_coeff_dict)
Пример #6
0
def get_bond_type_v_time_dict(adj_list, sum_len_larger_than=None):
    """
    given a list of adjs (one per timestep), flip nesting so have dictionaries of lists of type val vs. time
    for graphing, also created a 10+ list
    :param adj_list: list of adj dok_matrices
    :param sum_len_larger_than: None or an integer; if an integer, make a val_list that sums all lens >= that value
    :return: two dict of dicts
    """
    bond_type_dict = defaultdict(list)
    # a little more work for olig_len_monos_dict, since each timestep does not contain all possible keys
    olig_len_monos_dict = defaultdict(list)
    olig_len_count_dict = defaultdict(list)
    olig_count_dict_list = []
    frag_count_dict_list = []  # first make list of dicts to get max bond_length
    for adj in adj_list:  # loop over each timestep
        # this is keys = timestep  values
        count_bonds_list = count_bonds(adj)
        for bond_type in count_bonds_list:
            bond_type_dict[bond_type].append(count_bonds_list[bond_type])
        olig_yield_dict, olig_monos_dict, olig_branch_dict, olig_branch_coeff_dict = count_oligomer_yields(adj)
        olig_count_dict_list.append(olig_yield_dict)
        frag_count_dict_list.append(olig_monos_dict)
    # since breaking bonds is not allowed, the longest oligomer will be from the last step; ordered, so last len
    max_olig_len = list(frag_count_dict_list[-1].keys())[-1]
    # can now get the dict of lists from list of dicts
    for frag_count_list, olig_count_list in zip(frag_count_dict_list, olig_count_dict_list):
        for olig_len in range(1, max_olig_len + 1):
            olig_len_monos_dict[olig_len].append(frag_count_list.get(olig_len, 0))
            olig_len_count_dict[olig_len].append(olig_count_list.get(olig_len, 0))
    # now make a list of all values greater than a number, if given
    # first initialize as None so something can be returned, even if we are not summing over a particular number
    len_monos_plus_list = None
    len_count_plus_list = None
    if sum_len_larger_than:
        num_time_steps = len(adj_list)
        len_monos_plus_list = np.zeros(num_time_steps)
        len_count_plus_list = np.zeros(num_time_steps)
        # both dicts have same keys, so no worries
        for olig_len, val_list in olig_len_monos_dict.items():
            if olig_len >= sum_len_larger_than:
                len_monos_plus_list = np.add(len_monos_plus_list, val_list)
                len_count_plus_list = np.add(len_count_plus_list, olig_len_count_dict[olig_len])
    return bond_type_dict, olig_len_monos_dict, len_monos_plus_list, olig_len_count_dict, len_count_plus_list