/** * Select the best coordinates * * @param ps template points * @param coords best coordinates (updated by this method) * @param macrocycle the macrocycle * @param ringset rest of the ring system * @return offset into the coordinates */ private int selectCoords(Collection<Point2d[]> ps, Point2d[] coords, IRing macrocycle, IRingSet ringset) { assert ps.size() != 0; final int[] winding = new int[coords.length]; MacroScore best = null; for (Point2d[] p : ps) { final int wind = winding(p, winding); MacroScore score = bestScore(macrocycle, ringset, wind, winding); if (score.compareTo(best) < 0) { best = score; System.arraycopy(p, 0, coords, 0, p.length); } } // never null return best != null ? best.offset : 0; }
/** * Layout a macro cycle (the rest of the ring set is untouched). * * @param macrocycle the macrocycle * @param ringset the ring set the macrocycle belongs to (may only be it's self) * @return layout was successfully, if false caller fall-back to regular polygons */ boolean layout(IRing macrocycle, IRingSet ringset) { final IAtomContainer anon = roundUpIfNeeded(AtomContainerManipulator.anonymise(macrocycle)); final Collection<Point2d[]> coords = TEMPLATES.getCoordinates(anon); if (coords.isEmpty()) return false; Point2d[] best = new Point2d[anon.getAtomCount()]; int bestOffset = selectCoords(coords, best, macrocycle, ringset); for (int i = 0; i < macrocycle.getAtomCount(); i++) { macrocycle.getAtom(i).setPoint2d(best[(bestOffset + i) % macrocycle.getAtomCount()]); macrocycle.getAtom(i).setFlag(ISPLACED, true); macrocycle.getAtom(i).setProperty(MACROCYCLE_ATOM_HINT, true); } macrocycle.setFlag(ISPLACED, true); return true; }
ringPlacer.setMolecule(this.molecule); ringPlacer.setAtomPlacer(this.atomPlacer); macroPlacer = new MacroCycleLayout(mol); selectOrientation = afix.isEmpty();
/** * Determine the overall winding and the vertex of a ring template. * * @param coords ring coordinates * @param winding winding result for each atom (cw/ccw) * @return global winding */ private static int winding(final Point2d[] coords, final int[] winding) { int cw = 0, ccw = 0; Point2d prev = coords[coords.length - 1]; for (int i = 0; i < coords.length; i++) { Point2d curr = coords[i]; Point2d next = coords[(i + 1) % coords.length]; winding[i] = winding(prev, curr, next); if (winding[i] < 0) cw++; else if (winding[i] > 0) ccw++; else return 0; prev = curr; } if (cw == ccw) return 0; return cw > ccw ? CW : CCW; }
if (!macro || !macroPlacer.layout(first, rs)) {
ringAttachs.add(getAttachedInOrder(macrocycle, shared));
/** * Layout a macro cycle (the rest of the ring set is untouched). * * @param macrocycle the macrocycle * @param ringset the ring set the macrocycle belongs to (may only be it's self) * @return layout was successfully, if false caller fall-back to regular polygons */ boolean layout(IRing macrocycle, IRingSet ringset) { final IAtomContainer anon = roundUpIfNeeded(AtomContainerManipulator.anonymise(macrocycle)); final Collection<Point2d[]> coords = TEMPLATES.getCoordinates(anon); if (coords.isEmpty()) return false; Point2d[] best = new Point2d[anon.getAtomCount()]; int bestOffset = selectCoords(coords, best, macrocycle, ringset); for (int i = 0; i < macrocycle.getAtomCount(); i++) { macrocycle.getAtom(i).setPoint2d(best[(bestOffset + i) % macrocycle.getAtomCount()]); macrocycle.getAtom(i).setFlag(ISPLACED, true); macrocycle.getAtom(i).setProperty(MACROCYCLE_ATOM_HINT, true); } macrocycle.setFlag(ISPLACED, true); return true; }
ringPlacer.setMolecule(this.molecule); ringPlacer.setAtomPlacer(this.atomPlacer); macroPlacer = new MacroCycleLayout(mol); selectOrientation = afix.isEmpty();
/** * Determine the overall winding and the vertex of a ring template. * * @param coords ring coordinates * @param winding winding result for each atom (cw/ccw) * @return global winding */ private static int winding(final Point2d[] coords, final int[] winding) { int cw = 0, ccw = 0; Point2d prev = coords[coords.length - 1]; for (int i = 0; i < coords.length; i++) { Point2d curr = coords[i]; Point2d next = coords[(i + 1) % coords.length]; winding[i] = winding(prev, curr, next); if (winding[i] < 0) cw++; else if (winding[i] > 0) ccw++; else return 0; prev = curr; } if (cw == ccw) return 0; return cw > ccw ? CW : CCW; }
if (!macro || !macroPlacer.layout(first, rs)) {
ringAttachs.add(getAttachedInOrder(macrocycle, shared));
/** * Select the best coordinates * * @param ps template points * @param coords best coordinates (updated by this method) * @param macrocycle the macrocycle * @param ringset rest of the ring system * @return offset into the coordinates */ private int selectCoords(Collection<Point2d[]> ps, Point2d[] coords, IRing macrocycle, IRingSet ringset) { assert ps.size() != 0; final int[] winding = new int[coords.length]; MacroScore best = null; for (Point2d[] p : ps) { final int wind = winding(p, winding); MacroScore score = bestScore(macrocycle, ringset, wind, winding); if (score.compareTo(best) < 0) { best = score; System.arraycopy(p, 0, coords, 0, p.length); } } // never null return best != null ? best.offset : 0; }
atomPlacer.setMolecule(this.molecule); ringPlacer.setMolecule(this.molecule); macroPlacer = new MacroCycleLayout(this.molecule); return;
atomPlacer.setMolecule(this.molecule); ringPlacer.setMolecule(this.molecule); macroPlacer = new MacroCycleLayout(this.molecule); return;