def nonconserved_bond_stereo_keys(ste_tsg, check=True): """ Determine bond stereo centers which are not conserved by the reaction. This includes bonds which are stereogenic for the products but not for the reactants ("created" stereo centers) and bonds which are stereogenic for the reactants but not for the products ("destroyed" stereo centers). :param ste_tsg: The TS graph, with stereo assignments. :returns: Created and destroyed bond stereo centers, respectively. :rtype: (frozenset, frozenset) """ rcts_gra = reactants_graph(ste_tsg) prds_gra = products_graph(ste_tsg) if check: ste_atm_keys = stereogenic_atom_keys(rcts_gra) ste_bnd_keys = stereogenic_bond_keys(rcts_gra) assert not ste_atm_keys, ( "Unassigned atom stereo centers: {}".format(str(ste_atm_keys))) assert not ste_bnd_keys, ( "Unassigned bond stereo centers: {}".format(str(ste_bnd_keys))) keys1 = bond_stereo_keys(rcts_gra) keys2 = stereogenic_bond_keys(prds_gra, assigned=True) cre_ste_bnd_keys = frozenset(keys2 - keys1) des_ste_bnd_keys = frozenset(keys1 - keys2) return cre_ste_bnd_keys, des_ste_bnd_keys
def set_stereo_from_geometry(gra, geo, geo_idx_dct=None): """ set graph stereo from a geometry (coordinate distances need not match connectivity -- what matters is the relative positions at stereo sites) """ gra = without_stereo_parities(gra) last_gra = None atm_keys = sorted(atom_keys(gra)) geo_idx_dct = (geo_idx_dct if geo_idx_dct is not None else {atm_key: idx for idx, atm_key in enumerate(atm_keys)}) # set atom and bond stereo, iterating to self-consistency atm_keys = set() bnd_keys = set() while last_gra != gra: last_gra = gra atm_keys.update(stereogenic_atom_keys(gra)) bnd_keys.update(stereogenic_bond_keys(gra)) gra = _set_atom_stereo_from_geometry(gra, atm_keys, geo, geo_idx_dct) gra = _set_bond_stereo_from_geometry(gra, bnd_keys, geo, geo_idx_dct) return gra
def _stereo_corrected_geometry(sgr, geo, geo_idx_dct): """ correct the stereo parities of a geometry (works iterately to handle cases of higher-order stereo) """ assert sgr == explicit(sgr) gra = without_stereo_parities(sgr) if has_stereo(sgr): full_atm_ste_par_dct = atom_stereo_parities(sgr) full_bnd_ste_par_dct = bond_stereo_parities(sgr) atm_keys = set() bnd_keys = set() last_gra = None while last_gra != gra: last_gra = gra atm_keys.update(stereogenic_atom_keys(gra)) bnd_keys.update(stereogenic_bond_keys(gra)) atm_ste_par_dct = { atm_key: full_atm_ste_par_dct[atm_key] for atm_key in atm_keys } bnd_ste_par_dct = { bnd_key: full_bnd_ste_par_dct[bnd_key] for bnd_key in bnd_keys } geo, gra = _atom_stereo_corrected_geometry(gra, atm_ste_par_dct, geo, geo_idx_dct) geo, gra = _bond_stereo_corrected_geometry(gra, bnd_ste_par_dct, geo, geo_idx_dct) return geo