예제 #1
0
파일: _reac.py 프로젝트: avcopan/autochem
    def key_map(self, rev=False):
        """ get the key map taking atoms from the reactant into atoms from the
        product
        """
        iso_dct = automol.graph.full_isomorphism(
            ts.reverse(self.forward_ts_graph), self.backward_ts_graph)
        if rev:
            iso_dct = dict(map(reversed, iso_dct.items()))

        return iso_dct
예제 #2
0
파일: _reac.py 프로젝트: avcopan/autochem
def atom_mapping(rxn, rev=False):
    """ Determine the (/a) mapping from reaction atoms to product atoms.

        :param rxn: the reaction object
        :type rxn: Reaction
        :param rev: parameter to toggle reaction direction
        :type rev: bool
        :returns: the mapping from reactant atoms to product atoms
        :rtype: dict
    """
    tsg1 = rxn.forward_ts_graph
    tsg2 = ts.reverse(rxn.backward_ts_graph)

    iso_dct = automol.graph.isomorphism(tsg1, tsg2, stereo=False, dummy=False)

    if rev:
        iso_dct = dict(map(reversed, iso_dct.items()))

    return iso_dct
예제 #3
0
파일: _reac.py 프로젝트: avcopan/autochem
    def __init__(self, rxn_cls, forw_tsg, back_tsg, rcts_keys, prds_keys):
        """ constructor
        """
        rcts_keys = tuple(map(tuple, map(sorted, rcts_keys)))
        prds_keys = tuple(map(tuple, map(sorted, prds_keys)))

        # Check the reaction class
        assert par.is_reaction_class(rxn_cls), (
            "{} is not a reaction class".format(rxn_cls))

        # Check the reactant keys and the forward transition state graph
        all_rcts_keys = set(itertools.chain(*rcts_keys))
        forw_keys = automol.graph.atom_keys(forw_tsg)
        assert all_rcts_keys == forw_keys, ("{} != {}".format(
            str(all_rcts_keys), str(forw_keys)))

        # Check the product keys and the backward transition state graph
        all_prds_keys = set(itertools.chain(*prds_keys))
        back_keys = automol.graph.atom_keys(back_tsg)
        assert all_prds_keys == back_keys, ("{} != {}".format(
            str(all_prds_keys), str(back_keys)))

        # Check that the reactants and products are consistent
        forw_tsg_comp = automol.graph.without_dummy_atoms(
            automol.graph.without_stereo_parities(forw_tsg))
        back_tsg_comp = automol.graph.without_dummy_atoms(
            automol.graph.without_stereo_parities(back_tsg))
        assert automol.graph.full_isomorphism(ts.reverse(forw_tsg_comp),
                                              back_tsg_comp)

        # Set attributes
        self.class_ = rxn_cls
        self.reactants_keys = rcts_keys
        self.products_keys = prds_keys
        self.forward_ts_graph = forw_tsg
        self.backward_ts_graph = back_tsg
예제 #4
0
def hydrogen_migrations(rct_gras, prd_gras):
    """ find hydrogen migrations consistent with these reactants and products

    :param rct_gras: reactant graphs (must have non-overlapping keys)
    :param prd_gras: product graphs (must have non-overlapping keys)

    Hydrogen migrations are identified by adding a hydrogen to an unsaturated
    site of the reactant and adding a hydrogen to an unsaturated site of the
    product and seeing if they match up. If so, we have a hydrogen migration
    between these two sites.
    """
    _assert_is_valid_reagent_graph_list(rct_gras)
    _assert_is_valid_reagent_graph_list(prd_gras)

    rxns = []

    if len(rct_gras) == 1 and len(prd_gras) == 1:
        rct_gra, = rct_gras
        prd_gra, = prd_gras

        # Find keys for reactant graph
        rct_h_key = max(atom_keys(rct_gra)) + 1
        rct_rad_keys = unsaturated_atom_keys(rct_gra)

        # Find keys for product graph
        prd_h_key = max(atom_keys(prd_gra)) + 1
        prd_rad_keys = unsaturated_atom_keys(prd_gra)

        for rct_rad_key, prd_rad_key in (itertools.product(
                rct_rad_keys, prd_rad_keys)):
            # Add hydrogens to each radical site and see if the result matches
            rct_h_gra = add_bonded_atom(rct_gra,
                                        'H',
                                        rct_rad_key,
                                        bnd_atm_key=rct_h_key)
            prd_h_gra = add_bonded_atom(prd_gra,
                                        'H',
                                        prd_rad_key,
                                        bnd_atm_key=prd_h_key)

            iso_dct = isomorphism(rct_h_gra, prd_h_gra)
            if iso_dct:
                inv_dct = dict(map(reversed, iso_dct.items()))

                rct_don_key = inv_dct[prd_rad_key]
                prd_don_key = iso_dct[rct_rad_key]

                # Check equivalent donor atoms for other possible TSs
                rct_don_keys = equivalent_atoms(rct_h_gra, rct_don_key)
                prd_don_keys = equivalent_atoms(prd_h_gra, prd_don_key)

                for rct_don_key, prd_don_key in (itertools.product(
                        rct_don_keys, prd_don_keys)):
                    rct_hyd_key = atom_neighbor_atom_key(rct_gra,
                                                         rct_don_key,
                                                         symbs_first=('H', ),
                                                         symbs_last=())
                    prd_hyd_key = atom_neighbor_atom_key(prd_gra,
                                                         prd_don_key,
                                                         symbs_first=('H', ),
                                                         symbs_last=())

                    forw_tsg = ts.graph(rct_gra,
                                        frm_bnd_keys=[(rct_rad_key,
                                                       rct_hyd_key)],
                                        brk_bnd_keys=[(rct_don_key,
                                                       rct_hyd_key)])

                    back_tsg = ts.graph(prd_gra,
                                        frm_bnd_keys=[(prd_rad_key,
                                                       prd_hyd_key)],
                                        brk_bnd_keys=[(prd_don_key,
                                                       prd_hyd_key)])

                    if isomorphism(forw_tsg, ts.reverse(back_tsg)):
                        rxns.append(
                            Reaction(
                                rxn_cls=par.ReactionClass.HYDROGEN_MIGRATION,
                                forw_tsg=forw_tsg,
                                back_tsg=back_tsg,
                                rcts_keys=[atom_keys(rct_gra)],
                                prds_keys=[atom_keys(prd_gra)],
                            ))

    return ts_unique(rxns)