def continue_ring_system(gra, keys_lst, vma, zma_keys): """ continue constructing a v-matrix for a ring system Exactly one atom in the ring system must already be in the v-matrix, and this atom must be in the starting ring of the decomposed ring system key list. """ # First, get the ring keys keys_lst = list(keys_lst) keys = keys_lst.pop(0) # Break the bonds joining the last pair of atoms in each arc gra = remove_bonds(gra, [(k[-1], k[-2]) for k in keys_lst]) # Start by constructing the v-matrix for the first ring vma, zma_keys = continue_ring(gra, keys, vma, zma_keys) # Now, complete the ring system by continuing the v-matrix along each arc for keys in keys_lst: # Note that the atoms on each end of the arc are already in the # v-matrix, so we ignore those vma, zma_keys = continue_chain(gra, keys[1:-1], vma, zma_keys, term_hydrogens=False) return vma, zma_keys
def ring_system(gra, keys_lst): """ generate a v-matrix for a ring system :param gra: the graph :param keys_lst: the first entry contains keys for a ring and each next one contains keys for an arc that starts and ends on atoms in the preceding entries """ # First, get the ring keys keys_lst = list(keys_lst) keys = keys_lst.pop(0) # Break the bonds joining the last pair of atoms in each arc gra = remove_bonds(gra, [(k[-1], k[-2]) for k in keys_lst]) # Start by constructing the v-matrix for the first ring vma, zma_keys = ring(gra, keys) # Now, complete the ring system by continuing the v-matrix along each arc for keys in keys_lst: # Note that the atoms on each end of the arc are already in the # v-matrix, so we ignore those vma, zma_keys = continue_chain(gra, keys[1:-1], vma, zma_keys) return vma, zma_keys
def ring(gra, keys): """ generate a v-matrix for a ring All neighboring atoms along the ring will be included :param gra: the graph :param keys: ring keys, in the order they should appear in the z-matrix """ # Break the bond between the first and last atoms to make this a chain gra = remove_bonds(gra, [(keys[0], keys[-1])]) # Now, construct a v-matrix for the chain vma, zma_keys = chain(gra, keys, term_hydrogens=True) return vma, zma_keys
def continue_ring(gra, keys, vma, zma_keys): """ continue constructing a v-matrix around a ring All neighboring atoms along the ring will be included Exactly one atom in the ring must already be in the v-matrix. """ # Find the connecting key key = next((k for k in keys if k in zma_keys), None) assert key is not None, ( "There must be a ring atom already in the v-matrix") # Cycle the connecting key to the front of the ring keys = cycle_ring_atom_key_to_front(keys, key) # Break the bond between the first and last atoms to make this a chain gra = remove_bonds(gra, [(keys[0], keys[-1])]) # Now, construct a v-matrix for the chain vma, zma_keys = continue_chain(gra, keys, vma, zma_keys) return vma, zma_keys