Numerous experimental and computational studies have been carried out in recent years to understand the mechanisms governing the compaction of granular systems. Here the problem is further investigated from a different perspective. We compact spheres by a vibrational annealing method and show how the interactions between them and the walls determine the final structure. Dry spheres self-assemble only in body-centered-tetragonal structures, while cohesive ones surpass such density and reach the most compact face-centered-cubic phase. We argue that such polymorphism is due to a molecularlike behavior induced by a compensation mechanism between free and vibrational energies.