Quantum-mechanical study of the effect of lattice defects in atomic and ionic crystals on the adsorption of hydrogen