<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def add_oxidation_state_by_element(self, oxidation_states):
 """ Add oxidation states. Args: oxidation_states (dict):
 Dict of oxidation states. E.g., {"Li":1, "Fe":2, "P":5, "O":-2} """

        try:
            for site in self.sites:
                new_sp = {}
                for el, occu in site.species.items():
                    sym = el.symbol
                    new_sp[Specie(sym, oxidation_states[sym])] = occu
                site.species = new_sp
        except KeyError:
            raise ValueError("Oxidation state of all elements must be "
                             "specified in the dictionary.")