Thermodynamics of structure