code: def add_spin_by_element(self, spins):
          
          for site in self.sites:
              new_sp = {}
              for sp, occu in site.species.items():
                  sym = sp.symbol
                  oxi_state = getattr(sp, "oxi_state", None)
                  new_sp[Specie(sym, oxidation_state=oxi_state,
                                properties={'spin': spins.get(str(sp), spins.get(sym, None))})] = occu
              site.species = new_sp
docs: Add spin states to a structure.
  
          Args:
              spisn (dict): Dict of spins associated with
              elements or species, e.g. {"Ni":+5} or {"Ni2+":5}