def atom_idx_from_bonds(topology, idx):
    """Finds indices of atoms bonded to a given atom.

    Simply loops over all bonds in topology and checks whether atom with given
    index is involved. Returns a list of indeces of all atoms bonded to the
    atom with given index.
    """

    # list of indeces of bonded atoms:
    idx_bonded = []

    # check all bonds:
    for bond in topology.bonds():

        if idx == bond.atom1.index:
            idx_bonded.append(bond.atom2.index)

        if idx == bond.atom2.index:
            idx_bonded.append(bond.atom1.index)

    # return indeces of bonded atoms:
    return(idx_bonded)