The study of the chemical and molecular basis of the immune system and its interactions with pathogens.