A thermodynamic definition of protein domains