/** * Takes an object which subclasses IChemObject, e.g.Molecule, and will read this (from file, * database, internet etc). If the specific implementation does not support a specific IChemObject * it will throw an Exception. * * @param object The object that subclasses IChemObject * @return The IChemObject read * @exception CDKException */ public IChemObject read(IChemObject object) throws CDKException { if (object instanceof IReaction) { return (IChemObject) readReaction(object.getBuilder()); } else if (object instanceof IReactionSet) { IReactionSet reactionSet = object.getBuilder().newReactionSet(); reactionSet.addReaction(readReaction(object.getBuilder())); return reactionSet; } else if (object instanceof IChemModel) { IChemModel model = object.getBuilder().newChemModel(); IReactionSet reactionSet = object.getBuilder().newReactionSet(); reactionSet.addReaction(readReaction(object.getBuilder())); model.setReactionSet(reactionSet); return model; } else if (object instanceof IChemFile) { IChemFile chemFile = object.getBuilder().newChemFile(); IChemSequence sequence = object.getBuilder().newChemSequence(); sequence.addChemModel((IChemModel) read(object.getBuilder().newChemModel())); chemFile.addChemSequence(sequence); return chemFile; } else { throw new CDKException( "Only supported are Reaction and ChemModel, and not " + object.getClass().getName() + "."); } }
/** * Initiate process. It is needed to call the addExplicitHydrogensToSatisfyValency from the class * tools.HydrogenAdder. * * @param reactants reactants of the reaction * @param agents agents of the reaction (Must be in this case null) * @exception CDKException Description of the Exception */ @TestMethod("testInitiate_IMoleculeSet_IMoleculeSet") public IReactionSet initiate(IMoleculeSet reactants, IMoleculeSet agents) throws CDKException { logger.debug("initiate reaction: HeterolyticCleavagePBReaction"); if (reactants.getMoleculeCount() != 1) { throw new CDKException("HeterolyticCleavagePBReaction only expects one reactant"); } if (agents != null) { throw new CDKException("HeterolyticCleavagePBReaction don't expects agents"); } IReactionSet setOfReactions = DefaultChemObjectBuilder.getInstance().newInstance(IReactionSet.class); IMolecule reactant = reactants.getMolecule(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); Iterator<IBond> bondis = reactant.bonds().iterator(); while (bondis.hasNext()) { IBond bondi = bondis.next(); IAtom atom1 = bondi.getAtom(0); IAtom atom2 = bondi.getAtom(1); 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<IAtom>(); if (j == 0) { atomList.add(atom1); atomList.add(atom2); } else { atomList.add(atom2); atomList.add(atom1); } ArrayList<IBond> bondList = new ArrayList<IBond>(); bondList.add(bondi); IMoleculeSet moleculeSet = reactant.getBuilder().newInstance(IMoleculeSet.class); moleculeSet.addMolecule(reactant); IReaction reaction = mechanism.initiate(moleculeSet, atomList, bondList); if (reaction == null) continue; else setOfReactions.addReaction(reaction); } } } return setOfReactions; }
@TestMethod("testReadReactions1") public <T extends IChemObject> T read(T object) throws CDKException { if (object instanceof IReaction) { return (T) readReaction(object.getBuilder()); } else if (object instanceof IChemModel) { IChemModel model = object.getBuilder().newInstance(IChemModel.class); IReactionSet reactionSet = object.getBuilder().newInstance(IReactionSet.class); reactionSet.addReaction(readReaction(object.getBuilder())); model.setReactionSet(reactionSet); return (T) model; } else { throw new CDKException( "Only supported are Reaction and ChemModel, and not " + object.getClass().getName() + "."); } }
/** * 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). */ @TestMethod("testInitiate_IAtomContainerSet_IAtomContainerSet") public IReactionSet initiate(IAtomContainerSet reactants, IAtomContainerSet agents) throws CDKException { logger.debug("initiate reaction: RearrangementRadicalReaction"); if (reactants.getAtomContainerCount() != 1) { throw new CDKException("RearrangementRadicalReaction only expects one reactant"); } if (agents != null) { throw new CDKException("RearrangementRadicalReaction don't expects agents"); } IReactionSet setOfReactions = DefaultChemObjectBuilder.getInstance().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); Iterator<IAtom> atoms = reactants.getAtomContainer(0).atoms().iterator(); while (atoms.hasNext()) { IAtom atomi = atoms.next(); if (atomi.getFlag(CDKConstants.REACTIVE_CENTER) && reactant.getConnectedSingleElectronsCount(atomi) == 1) { Iterator<IBond> bondis = reactant.getConnectedBondsList(atomi).iterator(); while (bondis.hasNext()) { IBond bondi = bondis.next(); if (bondi.getFlag(CDKConstants.REACTIVE_CENTER) && bondi.getOrder() == IBond.Order.SINGLE) { IAtom atomj = bondi.getConnectedAtom(atomi); if (atomi.getFlag(CDKConstants.REACTIVE_CENTER) && (atomj.getFormalCharge() == CDKConstants.UNSET ? 0 : atomj.getFormalCharge()) == 0 && reactant.getConnectedSingleElectronsCount(atomj) == 0) { Iterator<IBond> bondjs = reactant.getConnectedBondsList(atomj).iterator(); while (bondjs.hasNext()) { IBond bondj = bondjs.next(); if (bondj.equals(bondi)) continue; if (bondj.getFlag(CDKConstants.REACTIVE_CENTER) && bondj.getOrder() == IBond.Order.DOUBLE) { IAtom atomk = bondj.getConnectedAtom(atomj); if (atomk.getFlag(CDKConstants.REACTIVE_CENTER) && (atomk.getFormalCharge() == CDKConstants.UNSET ? 0 : atomk.getFormalCharge()) == 0 && reactant.getConnectedSingleElectronsCount(atomk) == 0) { ArrayList<IAtom> atomList = new ArrayList<IAtom>(); atomList.add(atomi); atomList.add(atomj); atomList.add(atomk); ArrayList<IBond> bondList = new ArrayList<IBond>(); 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; }