public static IAtom getClosestAtom(int xPosition, int yPosition, IAtomContainer atomCon) {
        IAtom closestAtom = null;
        IAtom currentAtom;
        double smallestMouseDistance = -1;
        double mouseDistance;
        double atomX;
        double atomY;
        for (int i = 0; i < atomCon.getAtomCount(); i++) {
            currentAtom = atomCon.getAtom(i);
            atomX = currentAtom.getPoint2d().x;
            atomY = currentAtom.getPoint2d().y;
            mouseDistance = Math.sqrt(Math.pow(atomX - xPosition, 2) + Math.pow(atomY - yPosition, 2));
            if (mouseDistance < smallestMouseDistance || smallestMouseDistance == -1) {
                smallestMouseDistance = mouseDistance;
                closestAtom = currentAtom;
            }
        }
        return closestAtom;
    }
public static IAtom getClosestAtom ( int xPosition , int yPosition , IAtomContainer atomCon ) { IAtom closestAtom = null ; IAtom currentAtom ; double smallestMouseDistance = - 1 ; double mouseDistance ; double atomX ; double atomY ; for ( int i = 0 ; i < atomCon . getAtomCount ( ) ; i ++ ) { currentAtom = atomCon . getAtom ( i ) ; atomX = currentAtom . getPoint2d ( ) . x ; atomY = currentAtom . getPoint2d ( ) . y ; mouseDistance = Math . sqrt ( Math . pow ( atomX - xPosition , 2 ) + Math . pow ( atomY - yPosition , 2 ) ) ; if ( mouseDistance < smallestMouseDistance || smallestMouseDistance == - 1 ) { smallestMouseDistance = mouseDistance ; closestAtom = currentAtom ; } } return closestAtom ; }
Returns the atom 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 atom
@return            The atom that is closest to the given coordinates