private void invokePopupMenu(int x, int y) {
		selectedAnnotationHostAtom = getAnnotationHost(Attachment.ATOM_HOST, x, y);
		selectedAnnotationHostBond = getAnnotationHost(Attachment.BOND_HOST, x, y);
		if (selectedAnnotationHostAtom < 0 && selectedAnnotationHostBond < 0) {
			selectedAtom = findNearestAtomIndex(x, y);
			selectedBond = findNearestBondIndex(x, y);
			// when both selected
			if (selectedAtom >= 0 && selectedBond >= 0) {
				int[] bondPair = getBondAtoms(selectedBond);
				if (bondPair[0] == selectedAtom || bondPair[1] == selectedAtom) {
					// if the selected atom forms the selected bond, favor the selected atom
					selectedBond = -1;
				}
				else {
					// otherwise, compare the z-depth of the selected bond and the selected atom
					Point3i pAtom = getAtomScreen(selectedAtom);
					Point3i pBond = getBondCenterScreen(selectedBond);
					if (pAtom.z > pBond.z) {
						selectedAtom = -1;
					}
					else {
						selectedBond = -1;
					}
				}
			}
		}
		else {
			selectedAtom = -1;
			selectedBond = -1;
		}
		setClickedAtom(selectedAtom);
		setClickedBond(selectedBond);
		createPopupMenu();
		hidePopupText();
		popupMenu.show(popupMenu.getInvoker(), x + 5, y + 5);
	}