Theta series and magic numbers for diamond and certain ionic crystal structures