Assign rotatable bonds (single and not terminal and not in ring)

def assign_rotatable(mol):
    """Assign rotatable bonds (single and not terminal and not in ring)"""
    mol.require("Valence")
    mol.require("Topology")
    bs = set([(u, v) for u, v, _ in mol.bonds_iter()])
    for r in mol.rings:
        for a, b in iterator.consecutive(r + [r[0]], 2):
            bs -= {(a, b)}
            bs -= {(b, a)}
    for u, v in bs:
        unc = mol.neighbor_count(u)
        vnc = mol.neighbor_count(v)
        bc = mol.bond(u, v).order
        if bc == 1 and (unc > 1 and vnc > 1):
            mol.bond(u, v).rotatable = True
    mol.descriptors.add("Rotatable")