code: public static IBond getClosestBond(double xPosition, double yPosition, IAtomContainer atomCon) {
          Point2d bondCenter;
          IBond closestBond = null;
  
          double smallestMouseDistance = -1;
          double mouseDistance;
          Iterator<IBond> bonds = atomCon.bonds().iterator();
          while (bonds.hasNext()) {
              IBond currentBond = (IBond) bonds.next();
              bondCenter = get2DCenter(currentBond.atoms());
              mouseDistance = Math.sqrt(Math.pow(bondCenter.x - xPosition, 2) + Math.pow(bondCenter.y - yPosition, 2));
              if (mouseDistance < smallestMouseDistance || smallestMouseDistance == -1) {
                  smallestMouseDistance = mouseDistance;
                  closestBond = currentBond;
              }
          }
          return closestBond;
      }
docs: Returns the bond of the given molecule that is closest to the given
  coordinates.
  See comment for center(IAtomContainer atomCon, Dimension areaDim, HashMap renderingCoordinates) for details on coordinate sets
  
  @param  xPosition  The x coordinate
  @param  yPosition  The y coordinate
  @param  atomCon    The molecule that is searched for the closest bond
  @return            The bond that is closest to the given coordinates