Java Code Examples for org.openscience.cdk.interfaces.IAtomContainer#getID()

The following examples show how to use org.openscience.cdk.interfaces.IAtomContainer#getID() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MCSThread.java    From ReactionDecoder with GNU Lesser General Public License v3.0 6 votes vote down vote up
private synchronized IAtomContainer getNewContainerWithIDs(IAtomContainer mol)
        throws CDKException, CloneNotSupportedException {
    /*
     Generating SMILES speed ups the mapping process by n-FOLDS
     May be this is CDK inherent bug, which relies on the properties set by the SMILES
     */
    IAtomContainer ac;
    ac = mol.clone();
    for (int i = 0; i < ac.getAtomCount(); i++) {
        String atomID = mol.getAtom(i).getID() == null
                ? valueOf(i) : mol.getAtom(i).getID();
        ac.getAtom(i).setID(atomID);
    }
    String containerID = mol.getID() == null ? valueOf(nanoTime()) : mol.getID();
    ac.setID(containerID);

    return ac;
}
 
Example 2
Source File: SmilesMoleculeLabeller.java    From ReactionDecoder with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 *
 * @param container
 * @return
 */
@Override
public IAtomContainer getCanonicalMolecule(IAtomContainer container) {
    try {
        IAtomContainer clone = container.clone();
        for (IAtom a : container.atoms()) {
            if (a.getID() != null) {
                int index = container.indexOf(a);
                clone.getAtom(index).setID(a.getID());
            }
        }

        if (container.getID() != null) {
            clone.setID(container.getID());
        }

        int[] canonicalPermutation = getCanonicalPermutation(clone);
        getCanonicalPermutation(clone, canonicalPermutation);
        return clone;

    } catch (CloneNotSupportedException ex) {
        LOGGER.error(SEVERE, null, ex);
    }
    return null;
}
 
Example 3
Source File: InChiMoleculeLabeller.java    From ReactionDecoder with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 *
 * @param container
 * @return
 */
@Override
public IAtomContainer getCanonicalMolecule(IAtomContainer container) {
    int[] canonicalPermutation = getCanonicalPermutation(container);
    IAtomContainer permute = permute(
            canonicalPermutation, container);
    if (container.getID() != null) {
        permute.setID(container.getID());
    }

    for (int i : canonicalPermutation) {
        if (container.getAtom(i).getID() != null) {
            permute.getAtom(i).setID(container.getAtom(i).getID());
        }
    }
    return permute;
}
 
Example 4
Source File: SingleMoleculeLayout.java    From ReactionDecoder with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 *
 * @param atomContainer
 * @param axis
 * @return
 */
@Override
public BoundsTree layout(IAtomContainer atomContainer, Vector2d axis) {
    // XXX axis is used here to mean center point! :( bad design....
    Point2d center = new Point2d(axis);

    if (forceRelayout || !has2DCoordinates(atomContainer)) {
        sdg.setMolecule(new AtomContainer(atomContainer), false);
        try {
            if (isConnected(atomContainer)) {
                sdg.generateCoordinates();
            } else {
                err.println("Disconnected components needs to be layout separately");
            }
        } catch (CDKException e) {
            e.printStackTrace();
        }
    }
    double scale = getScaleFactor(atomContainer, params.bondLength);
    Rectangle2D bounds = getRectangle2D(atomContainer);
    scaleMolecule(atomContainer, scale);
    translateTo(atomContainer, center.x, center.y, bounds);
    String label = atomContainer.getID();
    return new BoundsTree(label, label, bounds);
}
 
Example 5
Source File: DirectReactionDrawer.java    From ReactionDecoder with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
     *
     * @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);
            }
        }
    }
 
Example 6
Source File: DirectReactionDrawer.java    From ReactionDecoder with GNU Lesser General Public License v3.0 6 votes vote down vote up
private BoundsTree shift(IAtomContainerSet reactants, String rootLabel,
            BoundsTree unshiftedMolSetTree,
            String label, double dx, double dy) {
        BoundsTree boundsTree = new BoundsTree(label);
        int counter = 0;
        for (IAtomContainer atomContainer : reactants.atomContainers()) {
            String fullLabel = rootLabel + "_" + label + "_" + atomContainer.getID() + ":" + counter;
            String subLabel = label + "_" + atomContainer.getID() + ":" + counter;
//            System.out.println(fullLabel);

//            System.out.println("Atoms From" + BoundsPrinter.toString(GeometryTools.getRectangle2D(atomContainer)));
            translate2D(atomContainer, dx, dy);
            Rectangle2D uBounds = unshiftedMolSetTree.get(fullLabel);
            Rectangle2D sBounds = new Rectangle2D.Double(uBounds.getMinX() + dx,
                    uBounds.getMinY() + dy,
                    uBounds.getWidth(),
                    uBounds.getHeight());
//            System.out.println("From " + BoundsPrinter.toString(uBounds));
//            System.out.println("To   " + BoundsPrinter.toString(sBounds));
//            System.out.println("Atoms To" + BoundsPrinter.toString(GeometryTools.getRectangle2D(atomContainer)));
            boundsTree.add(subLabel, sBounds);
            counter++;
        }
        return boundsTree;
    }
 
Example 7
Source File: AbstractAWTReactionLayout.java    From ReactionDecoder with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
     *
     * @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(GeometryTools.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(GeometryTools.getRectangle2D(molecule)));
            counter++;
        }
    }
 
Example 8
Source File: DirectMoleculeDrawer.java    From ReactionDecoder with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 *
 * @param atomContainer
 * @param g
 * @return
 */
public Rectangle2D drawMoleculeID(IAtomContainer atomContainer, Graphics2D g) {
    String id = atomContainer.getID();
    if (id == null) {
        return null;
    }
    Rectangle2D moleculeBounds = getRectangle2D(atomContainer);
    double labelCenterX = moleculeBounds.getCenterX();
    double labelCenterY = moleculeBounds.getMaxY() + params.labelYGap;
    Point2f textPoint = getTextPoint(g, id, labelCenterX, labelCenterY);
    g.setFont(moleculeIDFont);
    g.setColor(BLACK);
    g.drawString(id, textPoint.x, textPoint.y);
    Rectangle2D textBounds = getTextBounds(g, id);
    return new Rectangle2D.Double(
            labelCenterX - (textBounds.getWidth() / 2),
            labelCenterY - (textBounds.getHeight() / 2),
            textBounds.getWidth(),
            textBounds.getHeight());
}
 
Example 9
Source File: ExtAtomContainerManipulator.java    From ReactionDecoder with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Returns IAtomContainer without Hydrogen. If an GraphAtomContainer has
 * atom single atom which is atom Hydrogen then its not removed.
 *
 * @param atomContainer
 * @return IAtomContainer without Hydrogen. If an GraphAtomContainer has
 * atom single atom which is atom Hydrogen then its not removed.
 */
public static IAtomContainer convertExplicitToImplicitHydrogens(IAtomContainer atomContainer) {
    IAtomContainer mol = atomContainer.getBuilder().newInstance(IAtomContainer.class, atomContainer);
    if (mol.getAtomCount() > 1) {
        mol = removeHydrogensExceptSingleAndPreserveAtomID(mol);
    } else if (mol.getAtomCount() == 1 && !atomContainer.atoms().iterator().next().getSymbol().equalsIgnoreCase("H")) {
        /*
         * Pseudo-atoms and unconfigured atoms safetynet
         */
        convertImplicitToExplicitHydrogens(mol);
        mol = removeHydrogensExceptSingleAndPreserveAtomID(mol);
    } else if (mol.getAtomCount() == 1 && atomContainer.atoms().iterator().next().getSymbol().equalsIgnoreCase("H")) {
        LOGGER.warn("WARNING: single hydrogen atom removal not supported!");
    }
    mol.setProperties(atomContainer.getProperties());
    mol.setFlags(atomContainer.getFlags());
    if (atomContainer.getID() != null) {
        mol.setID(atomContainer.getID());
    }
    return mol;
}
 
Example 10
Source File: AbstractDirectReactionLayout.java    From ReactionDecoder with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 *
 * @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++;
    }
}
 
Example 11
Source File: Utility.java    From ReactionDecoder with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 *
 * @param atom
 * @param molset
 * @return
 */
protected static String getMoleculeID(IAtom atom, IAtomContainerSet molset) {
    for (IAtomContainer mol : molset.atomContainers()) {
        if (mol.contains(atom)) {
            return mol.getID();
        }
    }
    return null;
}
 
Example 12
Source File: SignatureMoleculeLabeller.java    From ReactionDecoder with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 *
 * @param container
 * @return
 */
@Override
public IAtomContainer getCanonicalMolecule(IAtomContainer container) {
    try {
        IAtomContainer permute = container.clone();

        if (container.getID() != null) {
            permute.setID(container.getID());
        }

        for (int i = 0; i < permute.getAtomCount(); i++) {
            if (container.getAtom(i).getID() != null) {
                permute.getAtom(i).setID(container.getAtom(i).getID());
            }
        }

        int[] canonicalPermutation = getCanonicalPermutation(permute);

        permuteWithoutClone(canonicalPermutation, permute);

        return permute;
    } catch (CloneNotSupportedException ex) {
        LOGGER.error(SEVERE, null, ex);
    }

    return null;
}
 
Example 13
Source File: Utility.java    From ReactionDecoder with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 *
 * @param bond
 * @param molset
 * @return
 */
protected static String getMoleculeID(IBond bond, IAtomContainerSet molset) {
    for (IAtomContainer mol : molset.atomContainers()) {
        if (mol.contains(bond)) {
            return mol.getID();
        }
    }
    return null;
}
 
Example 14
Source File: FilesystemMoleculeDataStore.java    From ReactionDecoder with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void store(IAtomContainer molecule) {
    String id = molecule.getID();
    File file = new File(moleculeDir, id + ".mol");
    try {
        FileWriter writer = new FileWriter(file);
        molWriter = new MDLV2000Writer(writer);
        molWriter.write(molecule);
        molWriter.close();
    } catch (CDKException | IOException e) {
        e.printStackTrace();
    }

}
 
Example 15
Source File: LinearAtomContainerSetLayout.java    From ReactionDecoder with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
     *
     * @param atomContainerSet
     * @param graphics
     * @return
     */
    @Override
    public BoundsTree layout(IAtomContainerSet atomContainerSet, Graphics2D graphics) {
        // TODO : plusBounds.getHeight() for T2B layout
        double molGap = 2 * params.plusGap;

        Font plusFont = new Font("ROMAN", PLAIN, params.plusFontSize);
        graphics.setFont(plusFont);

        if (atomContainerSet.getAtomContainerCount() > 1) {
            Rectangle2D plusBounds;
            plusBounds = super.getTextBounds(graphics, "+");
            molGap += (plusBounds.getWidth());
        }

        String atomContainerSetID = atomContainerSet.getID();
        boundsTree = new BoundsTree(atomContainerSetID);

        Point2d curr = new Point2d(0, 0);
        int moleculeCounter = 0;
        for (IAtomContainer molecule : atomContainerSet.atomContainers()) {
//            System.out.println("curr pos = " + curr.x + " " + curr.y);
            String label = molecule.getID();
            if (label == null || label.isEmpty()) {
                label = "mol" + valueOf(moleculeCounter);
            } else {
                label += ":" + valueOf(moleculeCounter);
            }

            BoundsTree molBounds = moleculeLayout.layout(molecule, label, graphics);

            double boundsWidth = molBounds.getWidth();
            double halfBoundsWidth = boundsWidth / 2;

            curr.scaleAdd(halfBoundsWidth, moleculeSetAxis, curr);
            translateTo(molecule, curr.x, curr.y, molBounds);
            curr.scaleAdd(halfBoundsWidth, moleculeSetAxis, curr);

            curr.scaleAdd(molGap, moleculeSetAxis, curr);

            boundsTree.add(atomContainerSetID, molBounds);
            moleculeCounter++;
        }

        return boundsTree;
    }
 
Example 16
Source File: Utility.java    From ReactionDecoder with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
     *
     * @param org_mol
     * @return cloned canonicalized molecule
     * @throws CloneNotSupportedException
     * @throws CDKException
     */
    public static IAtomContainer canonicalise(IAtomContainer org_mol) throws CloneNotSupportedException, CDKException {

        IAtomContainer cloneMolecule = cloneWithIDs(org_mol);

        int[] p = new int[cloneMolecule.getAtomCount()];
//        /*
//         Signature based canonical Permutations
//         */
//        p = new uk.ac.ebi.reactionblast.tools.labelling.
//        SignatureMoleculeLabeller().getCanonicalPermutation(cloneMolecule);

        /*
        Use the Canonical labelling from the SMILES
        IMP: Suggested by John May
         */
        try {
//            unique().create(cloneMolecule, p);
            SmilesGenerator smiles = new SmilesGenerator(
                    SmiFlavor.AtomAtomMap
                    | SmiFlavor.Unique
                    //                    | SmiFlavor.UseAromaticSymbols
                    | SmiFlavor.Stereo);

            String sm = smiles.create(cloneMolecule, p);
        } catch (Exception e) {
            e.printStackTrace();
            LOGGER.debug("Fragment not fit to canonicalise!");
        }

        permuteWithoutClone(p, cloneMolecule);

        /*
        Set the IDs to container
         */
        if (org_mol.getID() != null) {
            cloneMolecule.setID(org_mol.getID());
        }

        return cloneMolecule;
    }
 
Example 17
Source File: LinearMoleculeSetLayout.java    From ReactionDecoder with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 *
 * @param atomContainerSet
 * @param moleculeSetAxis
 * @return
 */
@Override
public BoundsTree layout(IAtomContainerSet atomContainerSet, Vector2d moleculeSetAxis) {
    int bondLength = params.bondLength;
    int molGap = 2 * params.plusGap;

    // if the molecules don't have labels, need to label them
    int molLabel = 0;

    String rootLabel = atomContainerSet.getID();
    boundsTree = new BoundsTree(rootLabel);
    Point2d curr = new Point2d(0, 0);
    int i = 0;
    for (IAtomContainer molecule : atomContainerSet.atomContainers()) {
        if (!has2DCoordinates(molecule)) {
            //Added by Asad for 3D to 2D

            StructureDiagramGenerator sdg
                    = new StructureDiagramGenerator(new AtomContainer(molecule));
            try {
                sdg.generateCoordinates();
            } catch (CDKException ex) {
                getLogger(LinearMoleculeSetLayout.class.getName()).log(SEVERE, null, ex);
            }
            molecule = sdg.getMolecule();

        }
        invert(molecule);
        if (params.alignMolecules && moleculeAxis != null) {
            align(molecule, moleculeAxis);
        }
        scaleMolecule(molecule,
                getScaleFactor(molecule, bondLength));
        Rectangle2D bounds = getRectangle2D(molecule);

        double boundsWidth = bounds.getWidth();
        double halfBoundsWidth = boundsWidth / 2;

        curr.scaleAdd(halfBoundsWidth, moleculeSetAxis, curr);
        translateTo(molecule, curr.x, curr.y, bounds);
        curr.scaleAdd(halfBoundsWidth, moleculeSetAxis, curr);
        curr.scaleAdd(molGap, moleculeSetAxis, curr);

        String moleculeLabel = molecule.getID();
        if (moleculeLabel == null || moleculeLabel.isEmpty()) {
            moleculeLabel = "mol" + valueOf(molLabel);
            molLabel++;
        } else {
            moleculeLabel += ":" + i;
        }

        boundsTree.add(rootLabel + "_" + moleculeLabel, bounds);
        i++;
        shouldInvert = true;
    }
    return boundsTree;
}