Arrange stereo wedge direction from spine to terminal atom

def spine_to_terminal_wedge(mol):
    """Arrange stereo wedge direction from spine to terminal atom
    """
    for i, a in mol.atoms_iter():
        if mol.neighbor_count(i) == 1:
            ni, nb = list(mol.neighbors(i).items())[0]
            if nb.order == 1 and nb.type in (1, 2) \
                    and ni > i != nb.is_lower_first:
                nb.is_lower_first = not nb.is_lower_first
                nb.type = {1: 2, 2: 1}[nb.type]