A thermodynamic approach to accurately determine the flexibility and loss of crystallinity in metal-organic frameworks