code: private void cloneAndSortMappings(IReaction reaction, IReaction copyOfReaction,
              Map<IAtomContainer, int[]> permutationMap) {
  
          // make a lookup for the indices of the atoms in the copy
          final Map<IChemObject, Integer> indexMap = new HashMap<IChemObject, Integer>();
          List<IAtomContainer> all = ReactionManipulator.getAllAtomContainers(copyOfReaction);
          int globalIndex = 0;
          for (IAtomContainer ac : all) {
              for (IAtom atom : ac.atoms()) {
                  indexMap.put(atom, globalIndex);
                  globalIndex++;
              }
          }
  
          Map<IAtom, IAtom> atomAtomMap = atomAtomMap(reaction, copyOfReaction, permutationMap);
          List<IMapping> map = cloneMappings(reaction, atomAtomMap);
  
          Comparator<IMapping> mappingSorter = new Comparator<IMapping>() {
  
              /**
               * {@inheritDoc}
               */
              @Override
              public int compare(IMapping o1, IMapping o2) {
                  IChemObject o10 = o1.getChemObject(0);
                  IChemObject o20 = o2.getChemObject(0);
                  return indexMap.get(o10).compareTo(indexMap.get(o20));
              }
  
          };
          Collections.sort(map, mappingSorter);
          int mappingIndex = 0;
          for (IMapping mapping : map) {
              mapping.getChemObject(0).setProperty(CDKConstants.ATOM_ATOM_MAPPING, mappingIndex);
              mapping.getChemObject(1).setProperty(CDKConstants.ATOM_ATOM_MAPPING, mappingIndex);
              copyOfReaction.addMapping(mapping);
              mappingIndex++;
          }
  
      }
docs: Clone and Sort the mappings based on the order of the first object
  in the mapping (which is assumed to be the reactant).
  
  @param reaction