Java Code Examples for org.openscience.cdk.layout.StructureDiagramGenerator#getMolecule()

The following examples show how to use org.openscience.cdk.layout.StructureDiagramGenerator#getMolecule() . 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: LayoutCheck.java    From ReactionDecoder with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 *
 * @param mol
 * @return
 */
public static IChemModel getChemModelWithMoleculeWithLayoutCheck(IAtomContainer mol) {
    IChemModel chemModel = new ChemModel();
    chemModel.setMoleculeSet(partitionIntoMolecules(mol));
    for (IAtomContainer molecule : getAllAtomContainers(chemModel.getMoleculeSet())) {
        if (has2DCoordinates(molecule)) {
            try {
                StructureDiagramGenerator sdg = new StructureDiagramGenerator(new AtomContainer(molecule));
                sdg.generateCoordinates();
                chemModel = (IChemModel) sdg.getMolecule();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    return chemModel;
}
 
Example 2
Source File: MDLFileReader.java    From ReactionDecoder with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Returns molecule with new layout
 *
 * @return cleaned model
 */
public IChemModel getChemModelWithMoleculeWithLayoutCheck() {
    IChemModel chemModel = new ChemModel();
    chemModel.setMoleculeSet(partitionIntoMolecules(molecule));
    for (IAtomContainer ac : getAllAtomContainers(chemModel.getMoleculeSet())) {
        if (!has2DCoordinates(ac)) {
            try {
                IAtomContainer mol = ac.getBuilder().newInstance(IAtomContainer.class, ac);
                percieveAtomTypesAndConfigureAtoms(mol);
                StructureDiagramGenerator sdg = new StructureDiagramGenerator(new AtomContainer(mol));
                sdg.generateCoordinates();
                ac = sdg.getMolecule();
            } catch (IllegalArgumentException | CDKException e) {
                e.printStackTrace();
            }
        }
    }
    return chemModel;
}
 
Example 3
Source File: FingerprintGenerator.java    From ReactionDecoder with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 *
 * @param mol
 * @return
 * @throws CDKException
 */
@Override
public synchronized BitSet getFingerprint(IAtomContainer mol) throws CDKException {
    if (!has2DCoordinates(mol)) {
        StructureDiagramGenerator structureDiagramGenerator = new StructureDiagramGenerator();
        structureDiagramGenerator.setMolecule(mol, true);
        if (isConnected(mol)) {
            structureDiagramGenerator.generateCoordinates();
            mol = structureDiagramGenerator.getMolecule();
        } else {
            LOGGER.debug("Disconnected components needs to be layout separately");
        }
    }
    return fingerprinter.getBitFingerprint(mol).asBitSet();
}
 
Example 4
Source File: LayoutCheck.java    From ReactionDecoder with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 *
 * @param mol
 * @return
 */
public static IAtomContainer getMoleculeWithLayoutCheck(IAtomContainer mol) {
    if (!has2DCoordinates(mol)) {
        try {
            StructureDiagramGenerator sdg = new StructureDiagramGenerator(new AtomContainer(mol));
            sdg.generateCoordinates();
            mol = sdg.getMolecule();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    return mol;
}
 
Example 5
Source File: MDLFileReader.java    From ReactionDecoder with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Returns moecule with cleaned Layout
 *
 * @return cleaned Layout molecule
 */
public IAtomContainer getMoleculeWithLayoutCheck() {
    if (!has2DCoordinates(molecule)) {
        try {
            StructureDiagramGenerator sdg = new StructureDiagramGenerator(new AtomContainer(molecule));
            sdg.generateCoordinates();
            molecule = sdg.getMolecule();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    return molecule;
}
 
Example 6
Source File: TestUtility.java    From ReactionDecoder with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 *
 * @param AtomContainer
 * @return
 */
protected IAtomContainer layout(IAtomContainer AtomContainer) {
    try {
        StructureDiagramGenerator sdg = new StructureDiagramGenerator();
        sdg.setMolecule(AtomContainer, true);
        sdg.generateCoordinates();
        return sdg.getMolecule();
    } catch (CDKException e) {
        return AtomContainer;
    }
}
 
Example 7
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;
}