code: def sort(self, key=None, reverse=False):
          
  
          old_molecule = self.molecule.copy()
  
          # sort Molecule
          self.molecule._sites = sorted(self.molecule._sites, key=key, reverse=reverse)
  
          # apply Molecule ordering to graph
          mapping = {idx: self.molecule.index(site) for idx, site in enumerate(old_molecule)}
          self.graph = nx.relabel_nodes(self.graph, mapping, copy=True)
  
          # normalize directions of edges
          edges_to_remove = []
          edges_to_add = []
          for u, v, k, d in self.graph.edges(keys=True, data=True):
              if v < u:
                  new_v, new_u, new_d = u, v, d.copy()
                  new_d['to_jimage'] = (0, 0, 0)
                  edges_to_remove.append((u, v, k))
                  edges_to_add.append((new_u, new_v, new_d))
  
          # add/delete marked edges
          for edges_to_remove in edges_to_remove:
              self.graph.remove_edge(*edges_to_remove)
          for (u, v, d) in edges_to_add:
              self.graph.add_edge(u, v, **d)
docs: Same as Molecule.sort(), also remaps nodes in graph.
          :param key:
          :param reverse:
          :return: