Formation of metallic hydrides and nitrides and their significance in the synthesis of ammonia