Search in sources :

Example 16 with IReaction

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

the class RadicalSiteInitiationReaction method initiate.

/**
 *  Initiate process.
 *
 *@exception  CDKException  Description of the Exception
 *
 * @param  reactants         reactants of the reaction.
 * @param  agents            agents of the reaction (Must be in this case null).
 */
@Override
public IReactionSet initiate(IAtomContainerSet reactants, IAtomContainerSet agents) throws CDKException {
    logger.debug("initiate reaction: RadicalSiteInitiationReaction");
    if (reactants.getAtomContainerCount() != 1) {
        throw new CDKException("RadicalSiteInitiationReaction only expects one reactant");
    }
    if (agents != null) {
        throw new CDKException("RadicalSiteInitiationReaction don't expects agents");
    }
    IReactionSet setOfReactions = reactants.getBuilder().newInstance(IReactionSet.class);
    IAtomContainer reactant = reactants.getAtomContainer(0);
    /*
         * if the parameter hasActiveCenter is not fixed yet, set the active
         * centers
         */
    IParameterReact ipr = super.getParameterClass(SetReactionCenter.class);
    if (ipr != null && !ipr.isSetParameter())
        setActiveCenters(reactant);
    for (IAtom atomi : reactants.getAtomContainer(0).atoms()) {
        if (atomi.getFlag(CDKConstants.REACTIVE_CENTER) && reactant.getConnectedSingleElectronsCount(atomi) == 1 && atomi.getFormalCharge() == 0) {
            for (IBond bondi : reactant.getConnectedBondsList(atomi)) {
                if (bondi.getFlag(CDKConstants.REACTIVE_CENTER) && bondi.getOrder() == IBond.Order.SINGLE) {
                    IAtom atomj = bondi.getOther(atomi);
                    if (atomj.getFlag(CDKConstants.REACTIVE_CENTER) && atomj.getFormalCharge() == 0) {
                        for (IBond bondj : reactant.getConnectedBondsList(atomj)) {
                            if (bondj.equals(bondi))
                                continue;
                            if (bondj.getFlag(CDKConstants.REACTIVE_CENTER) && bondj.getOrder() == IBond.Order.SINGLE) {
                                IAtom atomk = bondj.getOther(atomj);
                                if (atomk.getFlag(CDKConstants.REACTIVE_CENTER) && atomk.getAtomicNumber() == IElement.C && atomk.getFormalCharge() == 0) {
                                    ArrayList<IAtom> atomList = new ArrayList<>();
                                    atomList.add(atomi);
                                    atomList.add(atomj);
                                    atomList.add(atomk);
                                    ArrayList<IBond> bondList = new ArrayList<>();
                                    bondList.add(bondi);
                                    bondList.add(bondj);
                                    IAtomContainerSet moleculeSet = reactant.getBuilder().newInstance(IAtomContainerSet.class);
                                    moleculeSet.addAtomContainer(reactant);
                                    IReaction reaction = mechanism.initiate(moleculeSet, atomList, bondList);
                                    if (reaction == null)
                                        continue;
                                    else
                                        setOfReactions.addReaction(reaction);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return setOfReactions;
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) IReactionSet(org.openscience.cdk.interfaces.IReactionSet) CDKException(org.openscience.cdk.exception.CDKException) IAtomContainerSet(org.openscience.cdk.interfaces.IAtomContainerSet) IParameterReact(org.openscience.cdk.reaction.type.parameters.IParameterReact) IBond(org.openscience.cdk.interfaces.IBond) ArrayList(java.util.ArrayList) IReaction(org.openscience.cdk.interfaces.IReaction) IAtom(org.openscience.cdk.interfaces.IAtom)

Example 17 with IReaction

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

the class CarbonylEliminationReaction method initiate.

/**
 *  Initiate process.
 *
 *@exception  CDKException  Description of the Exception
 *
 * @param  reactants         reactants of the reaction
 * @param  agents            agents of the reaction (Must be in this case null)
 */
@Override
public IReactionSet initiate(IAtomContainerSet reactants, IAtomContainerSet agents) throws CDKException {
    logger.debug("initiate reaction: CarbonylEliminationReaction");
    if (reactants.getAtomContainerCount() != 1) {
        throw new CDKException("CarbonylEliminationReaction only expects one reactant");
    }
    if (agents != null) {
        throw new CDKException("CarbonylEliminationReaction don't expects agents");
    }
    IReactionSet setOfReactions = reactants.getBuilder().newInstance(IReactionSet.class);
    IAtomContainer reactant = reactants.getAtomContainer(0);
    /*
         * if the parameter hasActiveCenter is not fixed yet, set the active
         * centers
         */
    IParameterReact ipr = super.getParameterClass(SetReactionCenter.class);
    if (ipr != null && !ipr.isSetParameter())
        setActiveCenters(reactant);
    for (IAtom atomi : reactant.atoms()) {
        if (atomi.getFlag(CDKConstants.REACTIVE_CENTER) && atomi.getAtomicNumber() == IElement.O && atomi.getFormalCharge() == 1) {
            for (IBond bondi : reactant.getConnectedBondsList(atomi)) {
                if (bondi.getFlag(CDKConstants.REACTIVE_CENTER) && bondi.getOrder() == IBond.Order.TRIPLE) {
                    IAtom atomj = bondi.getOther(atomi);
                    if (atomj.getFlag(CDKConstants.REACTIVE_CENTER)) {
                        for (IBond bondj : reactant.getConnectedBondsList(atomj)) {
                            if (bondj.equals(bondi))
                                continue;
                            if (bondj.getFlag(CDKConstants.REACTIVE_CENTER) && bondj.getOrder() == IBond.Order.SINGLE) {
                                IAtom atomk = bondj.getOther(atomj);
                                if (atomk.getFlag(CDKConstants.REACTIVE_CENTER) && atomk.getFormalCharge() == 0) {
                                    ArrayList<IAtom> atomList = new ArrayList<>();
                                    atomList.add(atomk);
                                    atomList.add(atomj);
                                    ArrayList<IBond> bondList = new ArrayList<>();
                                    bondList.add(bondj);
                                    IAtomContainerSet moleculeSet = reactant.getBuilder().newInstance(IAtomContainerSet.class);
                                    moleculeSet.addAtomContainer(reactant);
                                    IReaction reaction = mechanism.initiate(moleculeSet, atomList, bondList);
                                    if (reaction == null)
                                        continue;
                                    else
                                        setOfReactions.addReaction(reaction);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return setOfReactions;
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) IReactionSet(org.openscience.cdk.interfaces.IReactionSet) CDKException(org.openscience.cdk.exception.CDKException) IAtomContainerSet(org.openscience.cdk.interfaces.IAtomContainerSet) IParameterReact(org.openscience.cdk.reaction.type.parameters.IParameterReact) IBond(org.openscience.cdk.interfaces.IBond) ArrayList(java.util.ArrayList) IReaction(org.openscience.cdk.interfaces.IReaction) IAtom(org.openscience.cdk.interfaces.IAtom)

Example 18 with IReaction

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

the class ElectronImpactSDBReaction method initiate.

/**
 *  Initiate process.
 *  It is needed to call the addExplicitHydrogensToSatisfyValency
 *  from the class tools.HydrogenAdder.
 *
 *@exception  CDKException  Description of the Exception
 *
 * @param  reactants         reactants of the reaction.
 * @param  agents            agents of the reaction (Must be in this case null).
 */
@Override
public IReactionSet initiate(IAtomContainerSet reactants, IAtomContainerSet agents) throws CDKException {
    logger.debug("initiate reaction: ElectronImpactSDBReaction");
    if (reactants.getAtomContainerCount() != 1) {
        throw new CDKException("ElectronImpactSDBReaction only expects one reactant");
    }
    if (agents != null) {
        throw new CDKException("ElectronImpactSDBReaction don't expects agents");
    }
    IReactionSet setOfReactions = reactants.getBuilder().newInstance(IReactionSet.class);
    IAtomContainer reactant = reactants.getAtomContainer(0);
    /*
         * if the parameter hasActiveCenter is not fixed yet, set the active
         * centers
         */
    IParameterReact ipr = super.getParameterClass(SetReactionCenter.class);
    if (ipr != null && !ipr.isSetParameter())
        setActiveCenters(reactant);
    for (IBond bondi : reactant.bonds()) {
        IAtom atom1 = bondi.getBegin();
        IAtom atom2 = bondi.getEnd();
        if (bondi.getFlag(CDKConstants.REACTIVE_CENTER) && bondi.getOrder() == IBond.Order.SINGLE && atom1.getFlag(CDKConstants.REACTIVE_CENTER) && atom2.getFlag(CDKConstants.REACTIVE_CENTER) && (atom1.getFormalCharge() == CDKConstants.UNSET ? 0 : atom1.getFormalCharge()) == 0 && (atom2.getFormalCharge() == CDKConstants.UNSET ? 0 : atom2.getFormalCharge()) == 0 && reactant.getConnectedSingleElectronsCount(atom1) == 0 && reactant.getConnectedSingleElectronsCount(atom2) == 0) {
            /**/
            for (int j = 0; j < 2; j++) {
                ArrayList<IAtom> atomList = new ArrayList<>();
                if (j == 0) {
                    atomList.add(atom1);
                    atomList.add(atom2);
                } else {
                    atomList.add(atom2);
                    atomList.add(atom1);
                }
                ArrayList<IBond> bondList = new ArrayList<>();
                bondList.add(bondi);
                IAtomContainerSet moleculeSet = reactant.getBuilder().newInstance(IAtomContainerSet.class);
                moleculeSet.addAtomContainer(reactant);
                IReaction reaction = mechanism.initiate(moleculeSet, atomList, bondList);
                if (reaction == null)
                    continue;
                else
                    setOfReactions.addReaction(reaction);
            }
        }
    }
    return setOfReactions;
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) IReactionSet(org.openscience.cdk.interfaces.IReactionSet) CDKException(org.openscience.cdk.exception.CDKException) IAtomContainerSet(org.openscience.cdk.interfaces.IAtomContainerSet) IParameterReact(org.openscience.cdk.reaction.type.parameters.IParameterReact) IBond(org.openscience.cdk.interfaces.IBond) ArrayList(java.util.ArrayList) IReaction(org.openscience.cdk.interfaces.IReaction) IAtom(org.openscience.cdk.interfaces.IAtom)

Example 19 with IReaction

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

the class HeterolyticCleavagePBReaction method initiate.

/**
 *  Initiate process.
 *  It is needed to call the addExplicitHydrogensToSatisfyValency
 *  from the class tools.HydrogenAdder.
 *
 *@exception  CDKException  Description of the Exception
 *
 * @param  reactants         reactants of the reaction
 * @param  agents            agents of the reaction (Must be in this case null)
 */
@Override
public IReactionSet initiate(IAtomContainerSet reactants, IAtomContainerSet agents) throws CDKException {
    logger.debug("initiate reaction: HeterolyticCleavagePBReaction");
    if (reactants.getAtomContainerCount() != 1) {
        throw new CDKException("HeterolyticCleavagePBReaction only expects one reactant");
    }
    if (agents != null) {
        throw new CDKException("HeterolyticCleavagePBReaction don't expects agents");
    }
    IReactionSet setOfReactions = reactants.getBuilder().newInstance(IReactionSet.class);
    IAtomContainer reactant = reactants.getAtomContainer(0);
    /*
         * if the parameter hasActiveCenter is not fixed yet, set the active
         * centers
         */
    IParameterReact ipr = super.getParameterClass(SetReactionCenter.class);
    if (ipr != null && !ipr.isSetParameter())
        setActiveCenters(reactant);
    for (IBond bondi : reactant.bonds()) {
        IAtom atom1 = bondi.getBegin();
        IAtom atom2 = bondi.getEnd();
        if (bondi.getFlag(CDKConstants.REACTIVE_CENTER) && bondi.getOrder() != IBond.Order.SINGLE && atom1.getFlag(CDKConstants.REACTIVE_CENTER) && atom2.getFlag(CDKConstants.REACTIVE_CENTER) && (atom1.getFormalCharge() == CDKConstants.UNSET ? 0 : atom1.getFormalCharge()) == 0 && (atom2.getFormalCharge() == CDKConstants.UNSET ? 0 : atom2.getFormalCharge()) == 0 && reactant.getConnectedSingleElectronsCount(atom1) == 0 && reactant.getConnectedSingleElectronsCount(atom2) == 0) {
            /**/
            for (int j = 0; j < 2; j++) {
                ArrayList<IAtom> atomList = new ArrayList<>();
                if (j == 0) {
                    atomList.add(atom1);
                    atomList.add(atom2);
                } else {
                    atomList.add(atom2);
                    atomList.add(atom1);
                }
                ArrayList<IBond> bondList = new ArrayList<>();
                bondList.add(bondi);
                IAtomContainerSet moleculeSet = reactant.getBuilder().newInstance(IAtomContainerSet.class);
                moleculeSet.addAtomContainer(reactant);
                IReaction reaction = mechanism.initiate(moleculeSet, atomList, bondList);
                if (reaction == null)
                    continue;
                else
                    setOfReactions.addReaction(reaction);
            }
        }
    }
    return setOfReactions;
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) IReactionSet(org.openscience.cdk.interfaces.IReactionSet) CDKException(org.openscience.cdk.exception.CDKException) IAtomContainerSet(org.openscience.cdk.interfaces.IAtomContainerSet) IParameterReact(org.openscience.cdk.reaction.type.parameters.IParameterReact) IBond(org.openscience.cdk.interfaces.IBond) ArrayList(java.util.ArrayList) IReaction(org.openscience.cdk.interfaces.IReaction) IAtom(org.openscience.cdk.interfaces.IAtom)

Example 20 with IReaction

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

the class RadicalChargeSiteInitiationHReaction method initiate.

/**
 *  Initiate process.
 *
 *@exception  CDKException  Description of the Exception
 *
 * @param  reactants         reactants of the reaction.
 * @param  agents            agents of the reaction (Must be in this case null).
 */
@Override
public IReactionSet initiate(IAtomContainerSet reactants, IAtomContainerSet agents) throws CDKException {
    logger.debug("initiate reaction: RadicalChargeSiteInitiationHReaction");
    if (reactants.getAtomContainerCount() != 1) {
        throw new CDKException("RadicalChargeSiteInitiationHReaction only expects one reactant");
    }
    if (agents != null) {
        throw new CDKException("RadicalChargeSiteInitiationHReaction don't expects agents");
    }
    IReactionSet setOfReactions = reactants.getBuilder().newInstance(IReactionSet.class);
    IAtomContainer reactant = reactants.getAtomContainer(0);
    /*
         * if the parameter hasActiveCenter is not fixed yet, set the active
         * centers
         */
    IParameterReact ipr = super.getParameterClass(SetReactionCenter.class);
    if (ipr != null && !ipr.isSetParameter())
        setActiveCenters(reactant);
    for (IAtom atomi : reactants.getAtomContainer(0).atoms()) {
        if (atomi.getFlag(CDKConstants.REACTIVE_CENTER) && reactant.getConnectedSingleElectronsCount(atomi) == 1 && atomi.getFormalCharge() == 1) {
            for (IBond bondi : reactant.getConnectedBondsList(atomi)) {
                if (bondi.getFlag(CDKConstants.REACTIVE_CENTER) && bondi.getOrder() == IBond.Order.SINGLE) {
                    IAtom atomj = bondi.getOther(atomi);
                    if (atomj.getFlag(CDKConstants.REACTIVE_CENTER) && atomj.getFormalCharge() == 0) {
                        for (IBond bondj : reactant.getConnectedBondsList(atomj)) {
                            if (bondj.equals(bondi))
                                continue;
                            if (bondj.getFlag(CDKConstants.REACTIVE_CENTER) && bondj.getOrder() == IBond.Order.SINGLE) {
                                IAtom atomk = bondj.getOther(atomj);
                                if (atomk.getFlag(CDKConstants.REACTIVE_CENTER) && atomk.getAtomicNumber() == IElement.H && atomk.getFormalCharge() == 0) {
                                    ArrayList<IAtom> atomList = new ArrayList<>();
                                    atomList.add(atomi);
                                    atomList.add(atomj);
                                    atomList.add(atomk);
                                    ArrayList<IBond> bondList = new ArrayList<>();
                                    bondList.add(bondi);
                                    bondList.add(bondj);
                                    IAtomContainerSet moleculeSet = reactant.getBuilder().newInstance(IAtomContainerSet.class);
                                    moleculeSet.addAtomContainer(reactant);
                                    IReaction reaction = mechanism.initiate(moleculeSet, atomList, bondList);
                                    if (reaction == null)
                                        continue;
                                    else
                                        setOfReactions.addReaction(reaction);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return setOfReactions;
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) IReactionSet(org.openscience.cdk.interfaces.IReactionSet) CDKException(org.openscience.cdk.exception.CDKException) IAtomContainerSet(org.openscience.cdk.interfaces.IAtomContainerSet) IParameterReact(org.openscience.cdk.reaction.type.parameters.IParameterReact) IBond(org.openscience.cdk.interfaces.IBond) ArrayList(java.util.ArrayList) IReaction(org.openscience.cdk.interfaces.IReaction) IAtom(org.openscience.cdk.interfaces.IAtom)

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