Search in sources :

Example 26 with IReaction

use of org.openscience.cdk.interfaces.IReaction in project cdk by cdk.

the class ReactionSchemeManipulator method setScheme.

/**
 * Create a IReactionScheme given as a top a IReaction. If it doesn't exist any subsequent reaction
 * return null;
 *
 * @param reaction       The IReaction as a top
 * @param reactionSet    The IReactionSet to extract a IReactionScheme
 * @return               The IReactionScheme
 */
private static IReactionScheme setScheme(IReaction reaction, IReactionSet reactionSet) {
    IReactionScheme reactionScheme = reaction.getBuilder().newInstance(IReactionScheme.class);
    IReactionSet reactConSet = extractSubsequentReaction(reaction, reactionSet);
    if (reactConSet.getReactionCount() != 0) {
        for (IReaction reactionInt : reactConSet.reactions()) {
            reactionScheme.addReaction(reactionInt);
            IReactionScheme newRScheme = setScheme(reactionInt, reactionSet);
            if (newRScheme.getReactionCount() != 0 || newRScheme.getReactionSchemeCount() != 0) {
                reactionScheme.add(newRScheme);
            }
        }
    }
    return reactionScheme;
}
Also used : IReactionSet(org.openscience.cdk.interfaces.IReactionSet) IReactionScheme(org.openscience.cdk.interfaces.IReactionScheme) IReaction(org.openscience.cdk.interfaces.IReaction)

Example 27 with IReaction

use of org.openscience.cdk.interfaces.IReaction in project cdk by cdk.

the class ReactionSchemeManipulator method extractTopReactions.

/**
 * Extract a set of Reactions which are in top of a IReactionScheme. The top reactions are those
 * which any of their reactants are participating in other reactions as a products.
 *
 * @param reactionScheme  The IReactionScheme
 * @return                The set of top reactions
 */
public static IReactionSet extractTopReactions(IReactionScheme reactionScheme) {
    IReactionSet reactionSet = reactionScheme.getBuilder().newInstance(IReactionSet.class);
    IReactionSet allSet = getAllReactions(reactionScheme);
    for (IReaction reaction : allSet.reactions()) {
        IReactionSet precuSet = extractPrecursorReaction(reaction, allSet);
        if (precuSet.getReactionCount() == 0) {
            boolean found = false;
            for (IReaction reactIn : reactionSet.reactions()) {
                if (reactIn.equals(reaction))
                    found = true;
            }
            if (!found)
                reactionSet.addReaction(reaction);
        }
    }
    return reactionSet;
}
Also used : IReactionSet(org.openscience.cdk.interfaces.IReactionSet) IReaction(org.openscience.cdk.interfaces.IReaction)

Example 28 with IReaction

use of org.openscience.cdk.interfaces.IReaction in project cdk by cdk.

the class ReactionSetManipulator method getAllChemObjects.

public static List<IChemObject> getAllChemObjects(IReactionSet set) {
    ArrayList<IChemObject> list = new ArrayList<>();
    list.add(set);
    for (IReaction reaction : set.reactions()) {
        list.addAll(ReactionManipulator.getAllChemObjects(reaction));
    }
    return list;
}
Also used : IChemObject(org.openscience.cdk.interfaces.IChemObject) ArrayList(java.util.ArrayList) IReaction(org.openscience.cdk.interfaces.IReaction)

Example 29 with IReaction

use of org.openscience.cdk.interfaces.IReaction in project cdk by cdk.

the class ReactionSetManipulator method getRelevantReactions.

/**
 * Get all Reactions object containing a Molecule from a set of Reactions.
 *
 * @param reactSet The set of reaction to inspect
 * @param molecule The molecule to find
 * @return         The IReactionSet
 */
public static IReactionSet getRelevantReactions(IReactionSet reactSet, IAtomContainer molecule) {
    IReactionSet newReactSet = reactSet.getBuilder().newInstance(IReactionSet.class);
    IReactionSet reactSetProd = getRelevantReactionsAsProduct(reactSet, molecule);
    for (IReaction reaction : reactSetProd.reactions()) newReactSet.addReaction(reaction);
    IReactionSet reactSetReact = getRelevantReactionsAsReactant(reactSet, molecule);
    for (IReaction reaction : reactSetReact.reactions()) newReactSet.addReaction(reaction);
    return newReactSet;
}
Also used : IReactionSet(org.openscience.cdk.interfaces.IReactionSet) IReaction(org.openscience.cdk.interfaces.IReaction)

Example 30 with IReaction

use of org.openscience.cdk.interfaces.IReaction in project cdk by cdk.

the class ChemFileManipulator method getAllReactions.

/**
 * Get a list of all IReaction inside an IChemFile.
 *
 * @param file  The IChemFile object.
 * @return      The List of IReaction objects inside.
 */
public static List<IReaction> getAllReactions(IChemFile file) {
    List<IReaction> reactonList = new ArrayList<>();
    List<IChemModel> chemModel = getAllChemModels(file);
    for (IChemModel iChemModel : chemModel) {
        for (IReaction reaction : iChemModel.getReactionSet().reactions()) {
            reactonList.add(reaction);
        }
    }
    return reactonList;
}
Also used : ArrayList(java.util.ArrayList) IChemModel(org.openscience.cdk.interfaces.IChemModel) IReaction(org.openscience.cdk.interfaces.IReaction)

Aggregations

IReaction (org.openscience.cdk.interfaces.IReaction)228 Test (org.junit.Test)152 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)138 IAtom (org.openscience.cdk.interfaces.IAtom)83 IReactionSet (org.openscience.cdk.interfaces.IReactionSet)72 IAtomContainerSet (org.openscience.cdk.interfaces.IAtomContainerSet)58 CDKException (org.openscience.cdk.exception.CDKException)51 IBond (org.openscience.cdk.interfaces.IBond)48 ArrayList (java.util.ArrayList)39 IParameterReact (org.openscience.cdk.reaction.type.parameters.IParameterReact)33 IMapping (org.openscience.cdk.interfaces.IMapping)23 Reaction (org.openscience.cdk.Reaction)21 IChemModel (org.openscience.cdk.interfaces.IChemModel)19 IReactionScheme (org.openscience.cdk.interfaces.IReactionScheme)19 InputStream (java.io.InputStream)18 IChemFile (org.openscience.cdk.interfaces.IChemFile)15 IChemSequence (org.openscience.cdk.interfaces.IChemSequence)13 Atom (org.openscience.cdk.Atom)11 AtomContainer (org.openscience.cdk.AtomContainer)11 CDKAtomTypeMatcher (org.openscience.cdk.atomtype.CDKAtomTypeMatcher)11