code: public static int getBestAlignmentForLabelXY(IAtomContainer container, IAtom atom) {
          double overallDiffX = 0;
          double overallDiffY = 0;
          for (IAtom connectedAtom : container.getConnectedAtomsList(atom)) {
              overallDiffX += connectedAtom.getPoint2d().x - atom.getPoint2d().x;
              overallDiffY += connectedAtom.getPoint2d().y - atom.getPoint2d().y;
          }
          if (Math.abs(overallDiffY) > Math.abs(overallDiffX)) {
              if (overallDiffY < 0)
                  return 2;
              else
                  return -2;
          } else {
              if (overallDiffX <= 0)
                  return 1;
              else
                  return -1;
          }
      }
docs: Determines the best alignment for the label of an atom in 2D space. It
  returns 1 if right (=default) aligned, and -1 if left aligned.
  returns 2 if top aligned, and -2 if H is aligned below the atom
  See comment for center(IAtomContainer atomCon, Dimension areaDim, HashMap renderingCoordinates) for details on coordinate sets
  
  @param  container  Description of the Parameter
  @param  atom       Description of the Parameter
  @return            The bestAlignmentForLabel value