Interplay between magnetism and structure in atomic-size Pd contacts: Ab initio studies