Several years ago we embarked on a project to calculate optimal crystal-packing and crystal-structure parameters based on potential functions from energy-partitioned ab-initio intermolecular SCF calculations plus calculations of dispersion energy contributions. Our approach, aimed at evaluating the intermolecular interactions, such as in polymer propagation and in molecular crystals, and at analyzing the optimal crystal packing, is based on nonempirical ab-initio calculations for smaller molecular aggregates (monomers, dimers, trimers, etc.), partitioning the total SCF interaction energies into the different components, and then fitting these components individually to functional forms or when necessary recalculating or estimating explicitly for certain interaction components for each different unit cell dimension change. We derived and implemented a complete program, including higher order terms and special features necessary only for calculations on crystals. We also derived and implemented a complete CRYSTAL program which, given the crystal symmetry, allows us to vary and optimize the crystal-structure parameters. We carried out test crystal optimization calculations on N2 and on CO2 both to check out the entire CRYSTAL program package and to explore the extensive programs written for various ab-initio based methods for calculating reliable intermolecular interactions. We investigated such aspects as the comparison of the various intermolecular interaction terms calculated from the potential functions compared with those calculated by ab-initio wave functions. We also investigated for the CRYSTAL program how many surrounding unit cells had to be included for energy convergence. We investigated the crystal CH3NO2. We calculated the intermolecular interactions at more than 50 geometries, partitioned the interaction energies, and fit these to functional forms. The agreement of our calculated unit cell dimensions with experiment was excellent, within 1 to 2.8%. Furthermore, our method fits the partitioned ΔESCF results to atom-class-atom-class potential functions, which enables a general library of such potential functions to be built up for the molecular classes of interest.