示例#1
0
def _unique_gras(gra_lst):
    """ Determine all of the unique gras deals with gras with multiple components
    """

    uni_gras = tuple()
    if gra_lst:

        # Initialize list with first element
        uni_gras += (gra_lst[0], )

        # Test if the del_gra is isomorphic to any of the uni_del_gras
        for gra in gra_lst[1:]:
            new_uni = True
            for uni_gra in uni_gras:
                if len(gra) == 1:
                    isodct = full_isomorphism(gra[0], uni_gra[0])
                else:
                    isodct = full_isomorphism(union(*gra), union(*uni_gra))
                if isodct:
                    new_uni = False
                    break

            # Add graph and idx to lst if del gra is unique
            if new_uni:
                uni_gras += (gra, )

    return uni_gras
示例#2
0
def prod_addition(x_gra, y_gra):
    """ products of addition
    """

    prod_gras = tuple()

    shift = len(automol.graph.atoms(x_gra))
    y_gra = automol.graph.transform_keys(y_gra, lambda x: x + shift)

    x_keys = unsaturated_atom_keys(x_gra)
    y_keys = unsaturated_atom_keys(y_gra)

    for x_key, y_key in itertools.product(x_keys, y_keys):
        xy_gra = add_bonds(union(x_gra, y_gra), [{x_key, y_key}])
        prod_gras += ((xy_gra, ), )

    return _unique_gras(prod_gras)
示例#3
0
def addition(rct_gras, prd_gras):
    """ find an addition transformation

    Additions are identified by joining an unsaturated site on one reactant to
    an unsaturated site on the other. If the result matches the products, this
    is an addition reaction.
    """
    _assert_is_valid_reagent_graph_list(rct_gras)
    _assert_is_valid_reagent_graph_list(prd_gras)

    tras = []
    rct_idxs = None
    prd_idxs = None

    is_triv = is_trivial_reaction(rct_gras, prd_gras)

    if len(rct_gras) == 2 and len(prd_gras) == 1 and not is_triv:
        x_gra, y_gra = rct_gras
        prd_gra, = prd_gras
        x_atm_keys = unsaturated_atom_keys(x_gra)
        y_atm_keys = unsaturated_atom_keys(y_gra)

        for x_atm_key, y_atm_key in itertools.product(x_atm_keys, y_atm_keys):
            xy_gra = add_bonds(union(x_gra, y_gra), [{x_atm_key, y_atm_key}])

            atm_key_dct = full_isomorphism(xy_gra, prd_gra)
            if atm_key_dct:
                tra = trans.from_data(rxn_class=par.REACTION_CLASS.ADDITION,
                                      frm_bnd_keys=[{x_atm_key, y_atm_key}],
                                      brk_bnd_keys=[])
                tras.append(tra)

                # sort the reactants so that the largest species is first
                rct_idxs = _argsort_reactants(rct_gras)
                prd_idxs = (0, )

    tras = tuple(tras)
    return tras, rct_idxs, prd_idxs