Calculation of site affinity constants and cooperativity coefficients for binding of ligands and/or protons to macromolecules. I. Generation of partition functions and mass balance equations