GeometryTools { public static double getBondLengthMedian(final IAtomContainer container) { if (container.getBondCount() == 0) throw new IllegalArgumentException("Container has no bonds."); double[] lengths = new double[container.getBondCount()]; for (int i = 0; i < container.getBondCount(); i++) { final IBond bond = container.getBond(i); final IAtom atom1 = bond.getBegin(); final IAtom atom2 = bond.getEnd(); if (atom1.getPoint2d() == null || atom2.getPoint2d() == null) throw new IllegalArgumentException("An atom has no 2D coordinates."); lengths[i] = getLength2D(bond); } Arrays.sort(lengths); return lengths[lengths.length / 2]; }  static void translateAllPositive(IAtomContainer atomCon); static void translate2D(IAtomContainer atomCon, double transX, double transY); static void scaleMolecule(IAtomContainer atomCon, Dimension areaDim, double fillFactor); static void scaleMolecule(IAtomContainer atomCon, double scaleFactor); static void center(IAtomContainer atomCon, Dimension areaDim); static void translate2D(IAtomContainer atomCon, Vector2d vector); static void rotate(IAtomContainer atomCon, Point2d center, double angle); static void rotate(IAtom atom, Point3d p1, Point3d p2, double angle); static void normalize(Point3d point); static Dimension get2DDimension(IAtomContainer atomCon); static Rectangle2D getRectangle2D(IAtomContainer container); static double[] getMinMax(IAtomContainer container); static void translate2DCentreOfMassTo(IAtomContainer atomCon, Point2d p); static Point2d get2DCenter(Iterable<IAtom> atoms); static Point2d get2DCenter(Iterator<IAtom> atoms); static Point2d get2DCenter(IRingSet ringSet); static Point2d get2DCentreOfMass(IAtomContainer ac); static Point2d get2DCenter(IAtomContainer container); static void translate2DCenterTo(IAtomContainer container, Point2d p); static Point3d get3DCentreOfMass(IAtomContainer ac); static Point3d get3DCenter(IAtomContainer ac); static double getAngle(double xDiff, double yDiff); static int[] distanceCalculator(int[] coords, double dist); static double[] distanceCalculator(double[] coords, double dist); static int[] getBondCoordinates(IBond bond); static IAtom getClosestAtom(int xPosition, int yPosition, IAtomContainer atomCon); static IAtom getClosestAtom(IAtomContainer atomCon, IAtom atom); static IAtom getClosestAtom(double xPosition, double yPosition, IAtomContainer atomCon, IAtom toignore); static IAtom getClosestAtom(double xPosition, double yPosition, IAtomContainer atomCon); static IBond getClosestBond(int xPosition, int yPosition, IAtomContainer atomCon); static IBond getClosestBond(double xPosition, double yPosition, IAtomContainer atomCon); static void sortBy2DDistance(IAtom[] atoms, Point2d point); static double getScaleFactor(IAtomContainer container, double bondLength); static double getBondLengthAverage(IAtomContainer container); static double getBondLengthMedian(final IAtomContainer container); static double getLength2D(IBond bond); static boolean has2DCoordinates(IAtomContainer container); static CoordinateCoverage get2DCoordinateCoverage(IAtomContainer container); @Deprecated static int has2DCoordinatesNew(IAtomContainer container); static boolean has2DCoordinates(IAtom atom); static boolean has2DCoordinates(IBond bond); static boolean has3DCoordinates(IAtomContainer container); static CoordinateCoverage get3DCoordinateCoverage(IAtomContainer container); static Vector2d calculatePerpendicularUnitVector(Point2d point1, Point2d point2); static double getNormalizationFactor(IAtomContainer container); static int getBestAlignmentForLabel(IAtomContainer container, IAtom atom); static int getBestAlignmentForLabelXY(IAtomContainer container, IAtom atom); static List<IAtom> findClosestInSpace(IAtomContainer container, IAtom startAtom, int max); static Map<Integer, Integer> mapAtomsOfAlignedStructures(IAtomContainer firstAtomContainer,
            IAtomContainer secondAtomContainer, double searchRadius, Map<Integer, Integer> mappedAtoms); static double getBondLengthRMSD(IAtomContainer firstAtomContainer, IAtomContainer secondAtomContainer,
            Map<Integer, Integer> mappedAtoms, boolean Coords3d); static double getAngleRMSD(IAtomContainer firstAtomContainer, IAtomContainer secondAtomContainer,
            Map<Integer, Integer> mappedAtoms); static double getAllAtomRMSD(IAtomContainer firstAtomContainer, IAtomContainer secondAtomContainer,
            Map<Integer, Integer> mappedAtoms, boolean Coords3d); static double getHeavyAtomRMSD(IAtomContainer firstAtomContainer, IAtomContainer secondAtomContainer,
            Map<Integer, Integer> mappedAtoms, boolean hetAtomOnly, boolean Coords3d); static double getBondLengthAverage3D(IAtomContainer container); static Rectangle2D shiftContainer(IAtomContainer container, Rectangle2D bounds, Rectangle2D last, double gap); static double getBondLengthAverage(IReaction reaction); static boolean has3DCoordinates(IChemModel chemModel); static Rectangle2D shiftReactionVertical(IReaction reaction, Rectangle2D bounds, Rectangle2D last, double gap);  }
@Test public void medianBondLength() { IAtomContainer container = new AtomContainer(); container.addAtom(atomAt(new Point2d(0, 0))); container.addAtom(atomAt(new Point2d(0, 1.5))); container.addAtom(atomAt(new Point2d(0, -1.5))); container.addAtom(atomAt(new Point2d(0, 5))); container.addBond(0, 1, IBond.Order.SINGLE); container.addBond(0, 2, IBond.Order.SINGLE); container.addBond(0, 3, IBond.Order.SINGLE); assertThat(GeometryTools.getBondLengthMedian(container), is(1.5)); }
@Test(expected = IllegalArgumentException.class) public void medianBondLengthNoBonds() { IAtomContainer container = new AtomContainer(); container.addAtom(atomAt(new Point2d(0, 0))); container.addAtom(atomAt(new Point2d(0, 1.5))); container.addAtom(atomAt(new Point2d(0, -1.5))); container.addAtom(atomAt(new Point2d(0, 5))); GeometryTools.getBondLengthMedian(container); }
@Test(expected = IllegalArgumentException.class) public void medianBondLengthNoPoints() { IAtomContainer container = new AtomContainer(); container.addAtom(atomAt(new Point2d(0, 0))); container.addAtom(atomAt(new Point2d(0, 1.5))); container.addAtom(atomAt(null)); container.addAtom(atomAt(new Point2d(0, 5))); container.addBond(0, 1, IBond.Order.SINGLE); container.addBond(0, 2, IBond.Order.SINGLE); container.addBond(0, 3, IBond.Order.SINGLE); GeometryTools.getBondLengthMedian(container); }
@Test public void medianBondLengthOneBond() { IAtomContainer container = new AtomContainer(); container.addAtom(atomAt(new Point2d(0, 0))); container.addAtom(atomAt(new Point2d(0, 1.5))); container.addBond(0, 1, IBond.Order.SINGLE); assertThat(GeometryTools.getBondLengthMedian(container), is(1.5)); }