Probability, thermodynamics, and dispersion space for a statistical model of equilibria in solution. 1. Quantum levels and thermodynamic functions in grand canonical and canonical ensembles