code: def replace_species(self, species_mapping):
          
  
          species_mapping = {get_el_sp(k): v
                             for k, v in species_mapping.items()}
          sp_to_replace = set(species_mapping.keys())
          sp_in_structure = set(self.composition.keys())
          if not sp_in_structure.issuperset(sp_to_replace):
              warnings.warn(
                  "Some species to be substituted are not present in "
                  "structure. Pls check your input. Species to be "
                  "substituted = %s; Species in structure = %s"
                  % (sp_to_replace, sp_in_structure))
  
          for site in self._sites:
              if sp_to_replace.intersection(site.species):
                  c = Composition()
                  for sp, amt in site.species.items():
                      new_sp = species_mapping.get(sp, sp)
                      try:
                          c += Composition(new_sp) * amt
                      except Exception:
                          c += {new_sp: amt}
                  site.species = c
docs: Swap species.
  
          Args:
              species_mapping (dict): dict of species to swap. Species can be
                  elements too. E.g., {Element("Li"): Element("Na")} performs
                  a Li for Na substitution. The second species can be a
                  sp_and_occu dict. For example, a site with 0.5 Si that is
                  passed the mapping {Element('Si): {Element('Ge'):0.75,
                  Element('C'):0.25} } will have .375 Ge and .125 C.