Search in sources :

Example 11 with IReaction

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

the class RadicalSiteRearrangementMechanism method initiate.

/**
 * Initiates the process for the given mechanism. The atoms to apply are mapped between
 * reactants and products.
 *
 * @param atomContainerSet
 * @param atomList    The list of atoms taking part in the mechanism. Only allowed two atoms.
 *                    The first atom is the atom which must be moved and the second
 *                    is the atom which receives the atom1 and the third is the atom which loss
 *                    the first atom
 * @param bondList    The list of bonds taking part in the mechanism. Only allowed one bond.
 * 					  It is the bond which is moved
 * @return            The Reaction mechanism
 */
@Override
public IReaction initiate(IAtomContainerSet atomContainerSet, ArrayList<IAtom> atomList, ArrayList<IBond> bondList) throws CDKException {
    CDKAtomTypeMatcher atMatcher = CDKAtomTypeMatcher.getInstance(atomContainerSet.getBuilder());
    if (atomContainerSet.getAtomContainerCount() != 1) {
        throw new CDKException("RadicalSiteRearrangementMechanism only expects one IAtomContainer");
    }
    if (atomList.size() != 3) {
        throw new CDKException("RadicalSiteRearrangementMechanism expects three atoms in the ArrayList");
    }
    if (bondList.size() != 1) {
        throw new CDKException("RadicalSiteRearrangementMechanism only expect one bond in the ArrayList");
    }
    IAtomContainer molecule = atomContainerSet.getAtomContainer(0);
    IAtomContainer reactantCloned;
    try {
        reactantCloned = molecule.clone();
    } catch (CloneNotSupportedException e) {
        throw new CDKException("Could not clone IAtomContainer!", e);
    }
    // Atom to be moved
    IAtom atom1 = atomList.get(0);
    IAtom atom1C = reactantCloned.getAtom(molecule.indexOf(atom1));
    // Atom to receive the new bonding with a ISingleElectron
    IAtom atom2 = atomList.get(1);
    IAtom atom2C = reactantCloned.getAtom(molecule.indexOf(atom2));
    // Atom which loss the atom
    IAtom atom3 = atomList.get(2);
    IAtom atom3C = reactantCloned.getAtom(molecule.indexOf(atom3));
    // Bond to move
    IBond bond1 = bondList.get(0);
    int posBond1 = molecule.indexOf(bond1);
    reactantCloned.removeBond(reactantCloned.getBond(posBond1));
    IBond newBond = atom1.getBuilder().newInstance(IBond.class, atom1C, atom2C, IBond.Order.SINGLE);
    reactantCloned.addBond(newBond);
    List<ISingleElectron> selectron = reactantCloned.getConnectedSingleElectronsList(atom2C);
    reactantCloned.removeSingleElectron(selectron.get(selectron.size() - 1));
    atom2C.setHybridization(null);
    AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(reactantCloned);
    IAtomType type = atMatcher.findMatchingAtomType(reactantCloned, atom2C);
    if (type == null || type.getAtomTypeName().equals("X"))
        return null;
    reactantCloned.addSingleElectron(atom2C.getBuilder().newInstance(ISingleElectron.class, atom3C));
    atom3C.setHybridization(null);
    AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(reactantCloned);
    type = atMatcher.findMatchingAtomType(reactantCloned, atom3C);
    if (type == null || type.getAtomTypeName().equals("X"))
        return null;
    IReaction reaction = atom2C.getBuilder().newInstance(IReaction.class);
    reaction.addReactant(molecule);
    /* mapping */
    for (IAtom atom : molecule.atoms()) {
        IMapping mapping = atom2C.getBuilder().newInstance(IMapping.class, atom, reactantCloned.getAtom(molecule.indexOf(atom)));
        reaction.addMapping(mapping);
    }
    reaction.addProduct(reactantCloned);
    return reaction;
}
Also used : IAtomType(org.openscience.cdk.interfaces.IAtomType) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) ISingleElectron(org.openscience.cdk.interfaces.ISingleElectron) CDKException(org.openscience.cdk.exception.CDKException) IBond(org.openscience.cdk.interfaces.IBond) IReaction(org.openscience.cdk.interfaces.IReaction) CDKAtomTypeMatcher(org.openscience.cdk.atomtype.CDKAtomTypeMatcher) IAtom(org.openscience.cdk.interfaces.IAtom) IMapping(org.openscience.cdk.interfaces.IMapping)

Example 12 with IReaction

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

the class RemovingSEofBMechanism method initiate.

/**
 * Initiates the process for the given mechanism. The atoms to apply are mapped between
 * reactants and products.
 *
 * @param atomContainerSet
 * @param atomList    The list of atoms taking part in the mechanism. Only allowed two atoms.
 *                    The first atom receives the charge and the second the single electron
 * @param bondList    The list of bonds taking part in the mechanism. Only allowed one bond
 * @return            The Reaction mechanism
 */
@Override
public IReaction initiate(IAtomContainerSet atomContainerSet, ArrayList<IAtom> atomList, ArrayList<IBond> bondList) throws CDKException {
    CDKAtomTypeMatcher atMatcher = CDKAtomTypeMatcher.getInstance(atomContainerSet.getBuilder(), CDKAtomTypeMatcher.REQUIRE_EXPLICIT_HYDROGENS);
    if (atomContainerSet.getAtomContainerCount() != 1) {
        throw new CDKException("RemovingSEofBMechanism only expects one IAtomContainer");
    }
    if (atomList.size() != 2) {
        throw new CDKException("RemovingSEofBMechanism expects two atoms in the ArrayList");
    }
    if (bondList.size() != 1) {
        throw new CDKException("RemovingSEofBMechanism only expects one bond in the ArrayList");
    }
    IAtomContainer molecule = atomContainerSet.getAtomContainer(0);
    IAtomContainer reactantCloned;
    try {
        reactantCloned = molecule.clone();
    } catch (CloneNotSupportedException e) {
        throw new CDKException("Could not clone IAtomContainer!", e);
    }
    IAtom atom1 = atomList.get(0);
    IAtom atom1C = reactantCloned.getAtom(molecule.indexOf(atom1));
    IAtom atom2 = atomList.get(1);
    IAtom atom2C = reactantCloned.getAtom(molecule.indexOf(atom2));
    IBond bond1 = bondList.get(0);
    int posBond1 = molecule.indexOf(bond1);
    if (bond1.getOrder() == IBond.Order.SINGLE)
        reactantCloned.removeBond(reactantCloned.getBond(posBond1));
    else
        BondManipulator.decreaseBondOrder(reactantCloned.getBond(posBond1));
    int charge = atom1C.getFormalCharge();
    atom1C.setFormalCharge(charge + 1);
    reactantCloned.addSingleElectron(atom1C.getBuilder().newInstance(ISingleElectron.class, atom2C));
    // check if resulting atom type is reasonable
    atom1C.setHybridization(null);
    AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(reactantCloned);
    IAtomType type = atMatcher.findMatchingAtomType(reactantCloned, atom1C);
    if (type == null || type.getAtomTypeName().equals("X"))
        return null;
    atom2C.setHybridization(null);
    AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(reactantCloned);
    type = atMatcher.findMatchingAtomType(reactantCloned, atom2C);
    if (type == null || type.getAtomTypeName().equals("X"))
        return null;
    IReaction reaction = atom1C.getBuilder().newInstance(IReaction.class);
    reaction.addReactant(molecule);
    /* mapping */
    for (IAtom atom : molecule.atoms()) {
        IMapping mapping = atom1C.getBuilder().newInstance(IMapping.class, atom, reactantCloned.getAtom(molecule.indexOf(atom)));
        reaction.addMapping(mapping);
    }
    if (bond1.getOrder() != IBond.Order.SINGLE) {
        reaction.addProduct(reactantCloned);
    } else {
        IAtomContainerSet moleculeSetP = ConnectivityChecker.partitionIntoMolecules(reactantCloned);
        for (int z = 0; z < moleculeSetP.getAtomContainerCount(); z++) {
            reaction.addProduct(moleculeSetP.getAtomContainer(z));
        }
    }
    return reaction;
}
Also used : IAtomType(org.openscience.cdk.interfaces.IAtomType) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) ISingleElectron(org.openscience.cdk.interfaces.ISingleElectron) CDKException(org.openscience.cdk.exception.CDKException) IAtomContainerSet(org.openscience.cdk.interfaces.IAtomContainerSet) IBond(org.openscience.cdk.interfaces.IBond) IReaction(org.openscience.cdk.interfaces.IReaction) CDKAtomTypeMatcher(org.openscience.cdk.atomtype.CDKAtomTypeMatcher) IAtom(org.openscience.cdk.interfaces.IAtom) IMapping(org.openscience.cdk.interfaces.IMapping)

Example 13 with IReaction

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

the class TautomerizationMechanism method initiate.

/**
 * Initiates the process for the given mechanism. The atoms and bonds to apply are mapped between
 * reactants and products.
 *
 * @param atomContainerSet
 * @param atomList    The list of atoms taking part in the mechanism. Only allowed fourth atoms.
 * @param bondList    The list of bonds taking part in the mechanism. Only allowed two bond.
 * 					  The first bond is the bond to decrease the order and the second is the bond
 * 				      to increase the order
 * 					  It is the bond which is moved
 * @return            The Reaction mechanism
 */
@Override
public IReaction initiate(IAtomContainerSet atomContainerSet, ArrayList<IAtom> atomList, ArrayList<IBond> bondList) throws CDKException {
    CDKAtomTypeMatcher atMatcher = CDKAtomTypeMatcher.getInstance(atomContainerSet.getBuilder());
    if (atomContainerSet.getAtomContainerCount() != 1) {
        throw new CDKException("TautomerizationMechanism only expects one IAtomContainer");
    }
    if (atomList.size() != 4) {
        throw new CDKException("TautomerizationMechanism expects four atoms in the ArrayList");
    }
    if (bondList.size() != 3) {
        throw new CDKException("TautomerizationMechanism expects three bonds in the ArrayList");
    }
    IAtomContainer molecule = atomContainerSet.getAtomContainer(0);
    IAtomContainer reactantCloned;
    try {
        reactantCloned = molecule.clone();
    } catch (CloneNotSupportedException e) {
        throw new CDKException("Could not clone IAtomContainer!", e);
    }
    // Atom to be added the hydrogen
    IAtom atom1 = atomList.get(0);
    IAtom atom1C = reactantCloned.getAtom(molecule.indexOf(atom1));
    // Atom 2
    IAtom atom2 = atomList.get(1);
    IAtom atom2C = reactantCloned.getAtom(molecule.indexOf(atom2));
    // Atom 3
    IAtom atom3 = atomList.get(2);
    IAtom atom3C = reactantCloned.getAtom(molecule.indexOf(atom3));
    // hydrogen Atom
    IAtom atom4 = atomList.get(3);
    IAtom atom4C = reactantCloned.getAtom(molecule.indexOf(atom4));
    // Bond with double bond
    IBond bond1 = bondList.get(0);
    int posBond1 = molecule.indexOf(bond1);
    // Bond with single bond
    IBond bond2 = bondList.get(1);
    int posBond2 = molecule.indexOf(bond2);
    // Bond to be removed
    IBond bond3 = bondList.get(2);
    int posBond3 = molecule.indexOf(bond3);
    BondManipulator.decreaseBondOrder(reactantCloned.getBond(posBond1));
    BondManipulator.increaseBondOrder(reactantCloned.getBond(posBond2));
    reactantCloned.removeBond(reactantCloned.getBond(posBond3));
    IBond newBond = molecule.getBuilder().newInstance(IBond.class, atom1C, atom4C, IBond.Order.SINGLE);
    reactantCloned.addBond(newBond);
    atom1C.setHybridization(null);
    AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(reactantCloned);
    IAtomType type = atMatcher.findMatchingAtomType(reactantCloned, atom1C);
    if (type == null || type.getAtomTypeName().equals("X"))
        return null;
    atom3C.setHybridization(null);
    AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(reactantCloned);
    type = atMatcher.findMatchingAtomType(reactantCloned, atom3C);
    if (type == null || type.getAtomTypeName().equals("X"))
        return null;
    IReaction reaction = atom2C.getBuilder().newInstance(IReaction.class);
    reaction.addReactant(molecule);
    /* mapping */
    for (IAtom atom : molecule.atoms()) {
        IMapping mapping = atom2C.getBuilder().newInstance(IMapping.class, atom, reactantCloned.getAtom(molecule.indexOf(atom)));
        reaction.addMapping(mapping);
    }
    reaction.addProduct(reactantCloned);
    return reaction;
}
Also used : IAtomType(org.openscience.cdk.interfaces.IAtomType) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) CDKException(org.openscience.cdk.exception.CDKException) IBond(org.openscience.cdk.interfaces.IBond) IReaction(org.openscience.cdk.interfaces.IReaction) CDKAtomTypeMatcher(org.openscience.cdk.atomtype.CDKAtomTypeMatcher) IAtom(org.openscience.cdk.interfaces.IAtom) IMapping(org.openscience.cdk.interfaces.IMapping)

Example 14 with IReaction

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

the class RadicalSiteHrAlphaReaction 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: RadicalSiteHrAlphaReaction");
    if (reactants.getAtomContainerCount() != 1) {
        throw new CDKException("RadicalSiteHrAlphaReaction only expects one reactant");
    }
    if (agents != null) {
        throw new CDKException("RadicalSiteHrAlphaReaction don't expects agents");
    }
    IReactionSet setOfReactions = reactants.getBuilder().newInstance(IReactionSet.class);
    IAtomContainer reactant = reactants.getAtomContainer(0);
    AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(reactant);
    Aromaticity.cdkLegacy().apply(reactant);
    AllRingsFinder arf = new AllRingsFinder();
    IRingSet ringSet = arf.findAllRings(reactant);
    for (int ir = 0; ir < ringSet.getAtomContainerCount(); ir++) {
        IRing ring = (IRing) ringSet.getAtomContainer(ir);
        for (int jr = 0; jr < ring.getAtomCount(); jr++) {
            IAtom aring = ring.getAtom(jr);
            aring.setFlag(CDKConstants.ISINRING, true);
        }
    }
    /*
         * 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);
    HOSECodeGenerator hcg = new HOSECodeGenerator();
    for (IAtom atomi : reactant.atoms()) {
        if (atomi.getFlag(CDKConstants.REACTIVE_CENTER) && reactant.getConnectedSingleElectronsCount(atomi) == 1) {
            hcg.getSpheres(reactant, atomi, 2, true);
            for (IAtom atoml : hcg.getNodesInSphere(2)) {
                if (atoml != null && atoml.getFlag(CDKConstants.REACTIVE_CENTER) && !atoml.getFlag(CDKConstants.ISINRING) && (atoml.getFormalCharge() == CDKConstants.UNSET ? 0 : atoml.getFormalCharge()) == 0 && atoml.getAtomicNumber() != IElement.H && reactant.getMaximumBondOrder(atoml) == IBond.Order.SINGLE) {
                    for (IAtom atomh : reactant.getConnectedAtomsList(atoml)) {
                        if (reactant.getBond(atomh, atoml).getFlag(CDKConstants.REACTIVE_CENTER) && atomh.getFlag(CDKConstants.REACTIVE_CENTER) && atomh.getAtomicNumber() == IElement.H) {
                            ArrayList<IAtom> atomList = new ArrayList<>();
                            atomList.add(atomh);
                            atomList.add(atomi);
                            atomList.add(atoml);
                            ArrayList<IBond> bondList = new ArrayList<>();
                            bondList.add(reactant.getBond(atomh, atoml));
                            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) ArrayList(java.util.ArrayList) IBond(org.openscience.cdk.interfaces.IBond) AllRingsFinder(org.openscience.cdk.ringsearch.AllRingsFinder) HOSECodeGenerator(org.openscience.cdk.tools.HOSECodeGenerator) IRing(org.openscience.cdk.interfaces.IRing) IRingSet(org.openscience.cdk.interfaces.IRingSet) IAtomContainerSet(org.openscience.cdk.interfaces.IAtomContainerSet) IParameterReact(org.openscience.cdk.reaction.type.parameters.IParameterReact) IReaction(org.openscience.cdk.interfaces.IReaction) IAtom(org.openscience.cdk.interfaces.IAtom)

Example 15 with IReaction

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

the class RadicalSiteHrDeltaReaction 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: RadicalSiteHrDeltaReaction");
    if (reactants.getAtomContainerCount() != 1) {
        throw new CDKException("RadicalSiteHrDeltaReaction only expects one reactant");
    }
    if (agents != null) {
        throw new CDKException("RadicalSiteHrDeltaReaction don't expects agents");
    }
    IReactionSet setOfReactions = reactants.getBuilder().newInstance(IReactionSet.class);
    IAtomContainer reactant = reactants.getAtomContainer(0);
    AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(reactant);
    Aromaticity.cdkLegacy().apply(reactant);
    AllRingsFinder arf = new AllRingsFinder();
    IRingSet ringSet = arf.findAllRings(reactant);
    for (int ir = 0; ir < ringSet.getAtomContainerCount(); ir++) {
        IRing ring = (IRing) ringSet.getAtomContainer(ir);
        for (int jr = 0; jr < ring.getAtomCount(); jr++) {
            IAtom aring = ring.getAtom(jr);
            aring.setFlag(CDKConstants.ISINRING, true);
        }
    }
    /*
         * 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);
    HOSECodeGenerator hcg = new HOSECodeGenerator();
    for (IAtom atomi : reactant.atoms()) {
        if (atomi.getFlag(CDKConstants.REACTIVE_CENTER) && reactant.getConnectedSingleElectronsCount(atomi) == 1) {
            hcg.getSpheres(reactant, atomi, 5, true);
            for (IAtom atoml : hcg.getNodesInSphere(5)) {
                if (atoml != null && atoml.getFlag(CDKConstants.REACTIVE_CENTER) && !atoml.getFlag(CDKConstants.ISINRING) && (atoml.getFormalCharge() == CDKConstants.UNSET ? 0 : atoml.getFormalCharge()) == 0 && atoml.getAtomicNumber() != IElement.H && reactant.getMaximumBondOrder(atoml) == IBond.Order.SINGLE) {
                    for (IAtom atomh : reactant.getConnectedAtomsList(atoml)) {
                        if (reactant.getBond(atomh, atoml).getFlag(CDKConstants.REACTIVE_CENTER) && atomh.getFlag(CDKConstants.REACTIVE_CENTER) && atomh.getAtomicNumber() == IElement.H) {
                            ArrayList<IAtom> atomList = new ArrayList<>();
                            atomList.add(atomh);
                            atomList.add(atomi);
                            atomList.add(atoml);
                            ArrayList<IBond> bondList = new ArrayList<>();
                            bondList.add(reactant.getBond(atomh, atoml));
                            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) ArrayList(java.util.ArrayList) IBond(org.openscience.cdk.interfaces.IBond) AllRingsFinder(org.openscience.cdk.ringsearch.AllRingsFinder) HOSECodeGenerator(org.openscience.cdk.tools.HOSECodeGenerator) IRing(org.openscience.cdk.interfaces.IRing) IRingSet(org.openscience.cdk.interfaces.IRingSet) IAtomContainerSet(org.openscience.cdk.interfaces.IAtomContainerSet) IParameterReact(org.openscience.cdk.reaction.type.parameters.IParameterReact) 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