code: public void mapTemplates(IAtomContainer mol, int numberOfRingAtoms)
          throws CDKException, CloneNotSupportedException {
          if (templates.isEmpty())
              loadTemplates();
  
          IAtomContainer                best          = null;
          Map<IChemObject, IChemObject> bestMap       = null;
          IAtomContainer                secondBest    = null;
          Map<IChemObject, IChemObject> secondBestMap = null;
  
          for (int i = 0; i < templates.size(); i++) {
  
              IAtomContainer query = queries.get(i);
  
              //if the atom count is different, it can't be right anyway
              if (query.getAtomCount() != mol.getAtomCount()) {
                  continue;
              }
  
              Mappings mappings = patterns.get(i).matchAll(mol);
              for (Map<IChemObject, IChemObject> map : mappings.toAtomBondMap()) {
                  if (isExactMatch(query, map)) {
                      assignCoords(query, map);
                      return;
                  } else if (query.getBondCount() == mol.getBondCount()) {
                      best = query;
                      bestMap = new HashMap<>(map);
                  } else {
                      secondBest = query;
                      secondBestMap = new HashMap<>(map);
                  }
              }
          }
  
          if (best != null) {
              assignCoords(best, bestMap);
          } else if (secondBest != null) {
              assignCoords(secondBest, secondBestMap);
          } else {
              logger.warn("Maybe RingTemplateError!");
          }
      }
docs: Checks if one of the loaded templates is a substructure in the given
  Molecule. If so, it assigns the coordinates from the template to the
  respective atoms in the Molecule.
  
  @param mol               AtomContainer from the ring systems.
  @param numberOfRingAtoms Number of atoms in the specified ring
  @throws CloneNotSupportedException The atomcontainer cannot be cloned.