public int findNearestBondIndex(int x, int y) {
		if (modelManager.frame == null)
			return -1;
		Bond[] bonds = modelManager.frame.bonds;
		if (bonds == null)
			return -1;
		int bondCount = modelManager.frame.bondCount;
		if (bondCount <= 0)
			return -1;
		int xA, yA, zA, xB, yB, zB;
		double distSq;
		float width;
		Atom atom1, atom2;
		int zmin = Integer.MAX_VALUE;
		int zDepth;
		int foundIndex = -1;
		for (int i = 0; i < bondCount; i++) {
			atom1 = bonds[i].atom1;
			atom2 = bonds[i].atom2;
			xA = atom1.screenX;
			yA = atom1.screenY;
			zA = atom1.screenZ;
			xB = atom2.screenX;
			yB = atom2.screenY;
			zB = atom2.screenZ;
			distSq = Line2D.ptSegDistSq(xA, yA, xB, yB, x, y);
			if (distSq < 0.001) {
				zDepth = zA + zB;
				if (zDepth < zmin) {
					zmin = zDepth;
					foundIndex = i;
				}
			}
			else {
				width = scaleToScreen((zA + zB) >> 1, bonds[i].mad);
				if (distSq < 2 * width) {
					zDepth = zA + zB;
					if (zDepth < zmin) {
						zmin = zDepth;
						foundIndex = i;
					}
				}
			}
		}
		return foundIndex;
	}