def _decompose_ring_system_atom_keys(rsy): """ decompose a ring system into a ring and a series of arcs """ # sort from smallest to largest rngs_pool = sorted(rings(rsy), key=lambda x: atom_count(x, with_implicit=False)) decomp = () decomp_bnd_keys = set({}) rng = rngs_pool.pop(0) bnd_keys = bond_keys(rng) atm_keys = sorted_ring_atom_keys_from_bond_keys(bnd_keys) decomp += (atm_keys, ) decomp_bnd_keys.update(bnd_keys) while rngs_pool: decomp_rsy = bond_induced_subgraph(rsy, decomp_bnd_keys) for idx, rng in enumerate(rngs_pool): arcs = ring_arc_complement_atom_keys(decomp_rsy, rng) if arcs: rngs_pool.pop(idx) decomp += arcs decomp_bnd_keys.update(bond_keys(rng)) return decomp
def rings(gra): """ rings in the graph (minimal basis) """ gras = [ bond_induced_subgraph(gra, bnd_keys) for bnd_keys in rings_bond_keys(gra) ] return tuple(sorted(gras, key=frozen))
def ring_systems(gra): """ polycyclic ring systems in the graph """ gras = [ bond_induced_subgraph(gra, bnd_keys, stereo=True) for bnd_keys in ring_systems_bond_keys(gra) ] return tuple(sorted(gras, key=frozen))
def branch(gra, atm_key, bnd_key): """ branch extending along `bnd_key` away from `atm_key` """ return bond_induced_subgraph(gra, branch_bond_keys(gra, atm_key, bnd_key), stereo=True)