Search in sources :

Example 1 with IMoleculeSet

use of org.openscience.cdk.interfaces.IMoleculeSet in project Smiles2Monomers by yoann-dufresne.

the class MolTreeWidth method calculateTreeWidth.

public int calculateTreeWidth(IMolecule m) {
    NGraph<InputData> g;
    AtomContainerToNgraph converter = new AtomContainerToNgraph();
    IAtomContainer mol = m;
    if (!ConnectivityChecker.isConnected(mol)) {
        IMoleculeSet comps = ConnectivityChecker.partitionIntoMolecules(mol);
        int maxIndex = 0;
        int maxCount = -9999;
        for (int i = 0; i < comps.getAtomContainerCount(); i++) {
            if (comps.getAtomContainer(i).getAtomCount() > maxCount) {
                maxCount = comps.getAtomContainer(i).getAtomCount();
                maxIndex = i;
            }
        }
        mol = comps.getAtomContainer(maxIndex);
    }
    g = converter.convert(mol);
    Stopwatch stopwatch = new Stopwatch(new JavaNanoTime());
    Permutation<InputData> p = new LexBFS<InputData>();
    PermutationToTreeDecomposition<InputData> pttd = new PermutationToTreeDecomposition<InputData>(p);
    stopwatch.reset();
    stopwatch.start();
    pttd.setInput(g);
    pttd.run();
    stopwatch.stop();
    return pttd.getUpperBound();
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) IMoleculeSet(org.openscience.cdk.interfaces.IMoleculeSet) LexBFS(nl.uu.cs.treewidth.algorithm.LexBFS) Stopwatch(nl.uu.cs.treewidth.timing.Stopwatch) JavaNanoTime(nl.uu.cs.treewidth.timing.JavaNanoTime) PermutationToTreeDecomposition(nl.uu.cs.treewidth.algorithm.PermutationToTreeDecomposition) InputData(nl.uu.cs.treewidth.input.GraphInput.InputData)

Example 2 with IMoleculeSet

use of org.openscience.cdk.interfaces.IMoleculeSet in project Smiles2Monomers by yoann-dufresne.

the class SmilesGenerator method createSMILES.

/**
 *  Generate canonical SMILES from the <code>molecule</code>. This method
 *  canonicaly lables the molecule but dose not perform any checks on the
 *  chemical validity of the molecule. This method also takes care of multiple
 *  molecules.
 *  IMPORTANT: A precomputed Set of All Rings (SAR) can be passed to this
 *  SmilesGenerator in order to avoid recomputing it. Use setRings() to
 *  assign the SAR.
 *
 * @param  molecule                 The molecule to evaluate.
 * @param  chiral                   true=SMILES will be chiral, false=SMILES.
 *      will not be chiral.
 * @param  doubleBondConfiguration  Should E/Z configurations be read at these positions? If the flag at position X is set to true,
 *                                  an E/Z configuration will be written from coordinates around bond X, if false, it will be ignored.
 *                                  If flag is true for a bond which does not constitute a valid double bond configuration, it will be
 *                                  ignored (meaning setting all to true will create E/Z indication will be pu in the smiles wherever
 *                                  possible, but note the coordinates might be arbitrary).
 * @exception CDKException          At least one atom has no Point2D;
 *      coordinates are needed for crating the chiral smiles. This excpetion
 *      can only be thrown if chiral smiles is created, ignore it if you want a
 *      non-chiral smiles (createSMILES(AtomContainer) does not throw an
 *      exception).
 * @see                             org.openscience.cdk.graph.invariant.CanonicalLabeler#canonLabel(IAtomContainer)
 * @return the SMILES representation of the molecule
 */
public synchronized String createSMILES(IAtomContainer molecule, boolean chiral, boolean[] doubleBondConfiguration) throws CDKException {
    IMoleculeSet moleculeSet = ConnectivityChecker.partitionIntoMolecules(molecule);
    if (moleculeSet.getMoleculeCount() > 1) {
        StringBuffer fullSMILES = new StringBuffer();
        for (int i = 0; i < moleculeSet.getAtomContainerCount(); i++) {
            IMolecule molPart = moleculeSet.getMolecule(i);
            fullSMILES.append(createSMILESWithoutCheckForMultipleMolecules(molPart, chiral, doubleBondConfiguration));
            if (i < (moleculeSet.getAtomContainerCount() - 1)) {
                // are there more molecules?
                fullSMILES.append('.');
            }
        }
        return fullSMILES.toString();
    } else {
        return (createSMILESWithoutCheckForMultipleMolecules(molecule, chiral, doubleBondConfiguration));
    }
}
Also used : IMoleculeSet(org.openscience.cdk.interfaces.IMoleculeSet) IMolecule(org.openscience.cdk.interfaces.IMolecule)

Example 3 with IMoleculeSet

use of org.openscience.cdk.interfaces.IMoleculeSet in project Smiles2Monomers by yoann-dufresne.

the class SmilesGenerator method createSMILES.

/**
 *  Generate a SMILES for the given <code>Reaction</code>.
 * @param reaction the reaction in question
 * @return the SMILES representation of the reaction
 * @throws org.openscience.cdk.exception.CDKException if there is an error during SMILES generation
 */
public synchronized String createSMILES(IReaction reaction) throws CDKException {
    StringBuffer reactionSMILES = new StringBuffer();
    IMoleculeSet reactants = reaction.getReactants();
    for (int i = 0; i < reactants.getAtomContainerCount(); i++) {
        reactionSMILES.append(createSMILES(reactants.getMolecule(i)));
        if (i + 1 < reactants.getAtomContainerCount()) {
            reactionSMILES.append('.');
        }
    }
    reactionSMILES.append('>');
    IMoleculeSet agents = reaction.getAgents();
    for (int i = 0; i < agents.getAtomContainerCount(); i++) {
        reactionSMILES.append(createSMILES(agents.getMolecule(i)));
        if (i + 1 < agents.getAtomContainerCount()) {
            reactionSMILES.append('.');
        }
    }
    reactionSMILES.append('>');
    IMoleculeSet products = reaction.getProducts();
    for (int i = 0; i < products.getAtomContainerCount(); i++) {
        reactionSMILES.append(createSMILES(products.getMolecule(i)));
        if (i + 1 < products.getAtomContainerCount()) {
            reactionSMILES.append('.');
        }
    }
    return reactionSMILES.toString();
}
Also used : IMoleculeSet(org.openscience.cdk.interfaces.IMoleculeSet)

Aggregations

IMoleculeSet (org.openscience.cdk.interfaces.IMoleculeSet)3 LexBFS (nl.uu.cs.treewidth.algorithm.LexBFS)1 PermutationToTreeDecomposition (nl.uu.cs.treewidth.algorithm.PermutationToTreeDecomposition)1 InputData (nl.uu.cs.treewidth.input.GraphInput.InputData)1 JavaNanoTime (nl.uu.cs.treewidth.timing.JavaNanoTime)1 Stopwatch (nl.uu.cs.treewidth.timing.Stopwatch)1 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)1 IMolecule (org.openscience.cdk.interfaces.IMolecule)1