public static List<String> getAllIDs(IAtomContainerSet set) { List<String> idList = new ArrayList<String>(); if (set != null) { if (set.getID() != null) idList.add(set.getID()); for (int i = 0; i < set.getAtomContainerCount(); i++) { idList.addAll(AtomContainerManipulator.getAllIDs(set.getAtomContainer(i))); } } return idList; }
private CMLMoleculeList cdkAtomContainerSetToCMLList(IAtomContainerSet moleculeSet, boolean setIDs) { CMLMoleculeList cmlList = new CMLMoleculeList(); cmlList.setConvention("cdk:moleculeSet"); if (useCMLIDs && setIDs) { IDCreator.createIDs(moleculeSet); } if (moleculeSet.getID() != null && !moleculeSet.getID().equals("")) cmlList.setId(moleculeSet.getID()); for (int i = 0; i < moleculeSet.getAtomContainerCount(); i++) { IAtomContainer container = moleculeSet.getAtomContainer(i); cmlList.appendChild(cdkAtomContainerToCMLMolecule(container, false, false)); } return cmlList; }
private CMLMoleculeList cdkAtomContainerSetToCMLList(IAtomContainerSet moleculeSet, boolean setIDs) { CMLMoleculeList cmlList = new CMLMoleculeList(); cmlList.setConvention("cdk:moleculeSet"); if (useCMLIDs && setIDs) { IDCreator.createIDs(moleculeSet); } if (moleculeSet.getID() != null && !moleculeSet.getID().equals("")) cmlList.setId(moleculeSet.getID()); for (int i = 0; i < moleculeSet.getAtomContainerCount(); i++) { IAtomContainer container = moleculeSet.getAtomContainer(i); cmlList.appendChild(cdkAtomContainerToCMLMolecule(container, false, false)); } return cmlList; }
/** * Labels the Atom's and Bond's in each AtomContainer using the a1, a2, b1, b2 * scheme often used in CML. It will also set id's for all AtomContainers, naming * them m1, m2, etc. * It will not the AtomContainerSet itself. */ private static void createIDsForAtomContainerSet(IAtomContainerSet containerSet, List<String> tabuList) { if (tabuList == null) tabuList = AtomContainerSetManipulator.getAllIDs(containerSet); if (null == containerSet.getID()) { atomContainerSetCount = setID(ATOMCONTAINERSET_PREFIX, atomContainerSetCount, containerSet, tabuList); } if (policy == OBJECT_UNIQUE_POLICY) { // start atom and bond indices within a container set always from 1 atomCount = 0; bondCount = 0; } Iterator<IAtomContainer> acs = containerSet.atomContainers().iterator(); while (acs.hasNext()) { createIDsForAtomContainer((IAtomContainer) acs.next(), tabuList); } }
/** * * @param molSet * @param molSetBoundsTree * @param dx * @param dy */ public void shiftMoleculeSet(IAtomContainerSet molSet, BoundsTree molSetBoundsTree, double dx, double dy) { // System.out.println(molSetBoundsTree); int counter = 0; for (IAtomContainer molecule : molSet.atomContainers()) { String molLabel = molSet.getID() + "_" + molecule.getID() + ":" + counter; // System.out.println("shifting " + molLabel + " from " + BoundsPrinter.toString(GeometryUtil.getRectangle2D(molecule))); Rectangle2D bounds = molSetBoundsTree.get(molLabel); bounds.setFrame(bounds.getMinX() + dx, bounds.getMinY() + dy, bounds.getWidth(), bounds.getHeight()); translate2D(molecule, dx, dy); // System.out.println("shifting " + molecule.getID() + " to " + BoundsPrinter.toString(GeometryUtil.getRectangle2D(molecule))); counter++; } }
/** * * @param molSet * @param molSetBoundsTree * @param dx * @param dy */ public void shiftMoleculeSet(IAtomContainerSet molSet, BoundsTree molSetBoundsTree, double dx, double dy) { int counter = 0; String rootLabel = molSet.getID(); for (IAtomContainer molecule : molSet.atomContainers()) { String label = rootLabel + "_" + molecule.getID() + ":" + counter; Rectangle2D bounds = molSetBoundsTree.get(label); bounds.setFrame(bounds.getCenterX() + dx, bounds.getCenterY() + dy, bounds.getWidth(), bounds.getHeight()); translate2D(molecule, dx, dy); counter++; } }
@Override public BoundsTree layout(IAtomContainerSet atomContainerSet, Graphics2D graphics) { Font plusFont = new Font("ROMAN", 0, this.params.plusFontSize); graphics.setFont(plusFont); Rectangle2D plusBounds = super.getTextBounds(graphics, "+"); double molGap = (double)(2 * this.params.plusGap) + plusBounds.getWidth(); String atomContainerSetID = atomContainerSet.getID(); this.boundsTree = new BoundsTree(atomContainerSetID); Point2d curr = new Point2d(0.0, 0.0); int moleculeCounter = 0; for (IAtomContainer molecule : atomContainerSet.atomContainers()) { String label = molecule.getID(); label = label == null || label.equals("") ? "mol" + String.valueOf(moleculeCounter) : label + ":" + String.valueOf(moleculeCounter); BoundsTree molBounds = this.moleculeLayout.layout(molecule, label, graphics); double boundsWidth = molBounds.getWidth(); double halfBoundsWidth = boundsWidth / 2.0; curr.scaleAdd(halfBoundsWidth, (Tuple2d)this.moleculeSetAxis, (Tuple2d)curr); this.translateTo(molecule, curr.x, curr.y, molBounds); curr.scaleAdd(halfBoundsWidth, (Tuple2d)this.moleculeSetAxis, (Tuple2d)curr); curr.scaleAdd(molGap, (Tuple2d)this.moleculeSetAxis, (Tuple2d)curr); this.boundsTree.add(atomContainerSetID, molBounds); ++moleculeCounter; } return this.boundsTree; }
String atomContainerSetID = atomContainerSet.getID(); boundsTree = new BoundsTree(atomContainerSetID);
String rootLabel = reaction.getID(); String reactantID = reactants.getID(); BoundsTree reactantTree = unshiftedTree.getSubtree(rootLabel + "_" + reactantID); BoundsTree rBoundsTree = shift(reactants, rootLabel, reactantTree, reactantID, dx, dy); String productID = products.getID(); BoundsTree productTree = unshiftedTree.getSubtree(rootLabel + "_" + productID); BoundsTree pBoundsTree = shift(products, rootLabel, productTree, products.getID(), dx, dy);
int molGap = 2 * this.params.plusGap; int molLabel = 0; String rootLabel = atomContainerSet.getID(); this.boundsTree = new BoundsTree(rootLabel); Point2d curr = new Point2d(0.0, 0.0);
/** * * @param reactants * @param reactionID * @param yAxis * @param boundsTree * @param g */ public void drawMoleculeSet(IAtomContainerSet reactants, String reactionID, double yAxis, BoundsTree boundsTree, Graphics2D g) { if (params.layoutLeftToRight) { params.moleculeLabelFontSize = params.leftToRightMoleculeLabelFontSize; } else { params.moleculeLabelFontSize = params.topToBottomMoleculeLabelFontSize; } for (int i = 0; i < reactants.getAtomContainerCount(); i++) { IAtomContainer current = reactants.getAtomContainer(i); if (i > 0) { IAtomContainer previous = reactants.getAtomContainer(i - 1); String previousLabel = reactionID + "_" + reactants.getID() + "_" + previous.getID() + ":" + (i - 1); // System.out.println("getting " + previousLabel); drawPlus(previous, previousLabel, yAxis, boundsTree, g); moleculeDrawer.drawMolecule(current, g); } else { moleculeDrawer.drawMolecule(current, g); } } }
String rootLabel = atomContainerSet.getID(); boundsTree = new BoundsTree(rootLabel); Point2d curr = new Point2d(0, 0);
IAtomContainer lastReactant = reaction.getReactants().getAtomContainer(index); String reactantsID = reaction.getReactants().getID(); String boundsID = reactionID + "_" + reactantsID + "_" + lastReactant.getID() + ":" + index;