code: public static List<IAtom> findClosestInSpace(IAtomContainer container, IAtom startAtom, int max)
              throws CDKException {
          Point3d originalPoint = startAtom.getPoint3d();
          if (originalPoint == null) {
              throw new CDKException("No point3d, but findClosestInSpace is working on point3ds");
          }
          Map<Double, IAtom> atomsByDistance = new TreeMap<Double, IAtom>();
          for (IAtom atom : container.atoms()) {
              if (!atom.equals(startAtom)) {
                  if (atom.getPoint3d() == null) {
                      throw new CDKException("No point3d, but findClosestInSpace is working on point3ds");
                  }
                  double distance = atom.getPoint3d().distance(originalPoint);
                  atomsByDistance.put(distance, atom);
              }
          }
          // FIXME: should there not be some sort here??
          Set<Double> keySet = atomsByDistance.keySet();
          Iterator<Double> keyIter = keySet.iterator();
          List<IAtom> returnValue = new ArrayList<IAtom>();
          int i = 0;
          while (keyIter.hasNext() && i < max) {
              returnValue.add(atomsByDistance.get(keyIter.next()));
              i++;
          }
          return (returnValue);
      }
docs: Returns the atoms which are closes to an atom in an AtomContainer by
  distance in 3d.
  
  @param  container         The AtomContainer to examine
  @param  startAtom         the atom to start from
  @param  max               the number of neighbours to return
  @return                   the average bond length
  @exception  CDKException  Description of the Exception