Energetics of the coupled electronic–structural transition in the rare-earth nickelates