RearrangementRadicalReaction extends ReactionEngine implements IReactionProcess { @Override 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 = reactants.getBuilder().newInstance(IReactionSet.class); IAtomContainer reactant = reactants.getAtomContainer(0); 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.getOther(atomi); if (atomj.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.getOther(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; } RearrangementRadicalReaction(); @Override ReactionSpecification getSpecification(); @Override IReactionSet initiate(IAtomContainerSet reactants, IAtomContainerSet agents);  }
@Test @Override public void testInitiate_IAtomContainerSet_IAtomContainerSet() throws Exception { IReactionProcess type = new RearrangementRadicalReaction(); IAtomContainerSet setOfReactants = getExampleReactants(); List<IParameterReact> paramList = new ArrayList<IParameterReact>(); IParameterReact param = new SetReactionCenter(); param.setParameter(Boolean.FALSE); paramList.add(param); type.setParameterList(paramList); IReactionSet setOfReactions = type.initiate(setOfReactants, null); Assert.assertEquals(1, setOfReactions.getReactionCount()); Assert.assertEquals(1, setOfReactions.getReaction(0).getProductCount()); IAtomContainer product = setOfReactions.getReaction(0).getProducts().getAtomContainer(0); IAtomContainer molecule2 = getExpectedProducts().getAtomContainer(0); assertEquals(molecule2, product); }
@Test public void testManuallyCentreActive() throws Exception { IReactionProcess type = new RearrangementRadicalReaction(); IAtomContainerSet setOfReactants = getExampleReactants(); IAtomContainer molecule = setOfReactants.getAtomContainer(0); molecule.getAtom(0).setFlag(CDKConstants.REACTIVE_CENTER, true); molecule.getBond(0).setFlag(CDKConstants.REACTIVE_CENTER, true); molecule.getAtom(1).setFlag(CDKConstants.REACTIVE_CENTER, true); molecule.getBond(1).setFlag(CDKConstants.REACTIVE_CENTER, true); molecule.getAtom(2).setFlag(CDKConstants.REACTIVE_CENTER, true); List<IParameterReact> paramList = new ArrayList<IParameterReact>(); IParameterReact param = new SetReactionCenter(); param.setParameter(Boolean.TRUE); paramList.add(param); type.setParameterList(paramList); IReactionSet setOfReactions = type.initiate(setOfReactants, null); Assert.assertEquals(1, setOfReactions.getReactionCount()); Assert.assertEquals(1, setOfReactions.getReaction(0).getProductCount()); IAtomContainer product = setOfReactions.getReaction(0).getProducts().getAtomContainer(0); IAtomContainer molecule2 = getExpectedProducts().getAtomContainer(0); assertEquals(molecule2, product); }
@Test public void testCDKConstants_REACTIVE_CENTER() throws Exception { IReactionProcess type = new RearrangementRadicalReaction(); IAtomContainerSet setOfReactants = getExampleReactants(); IAtomContainer molecule = setOfReactants.getAtomContainer(0); molecule.getAtom(0).setFlag(CDKConstants.REACTIVE_CENTER, true); molecule.getAtom(1).setFlag(CDKConstants.REACTIVE_CENTER, true); molecule.getAtom(2).setFlag(CDKConstants.REACTIVE_CENTER, true); molecule.getBond(0).setFlag(CDKConstants.REACTIVE_CENTER, true); molecule.getBond(1).setFlag(CDKConstants.REACTIVE_CENTER, true); List<IParameterReact> paramList = new ArrayList<IParameterReact>(); IParameterReact param = new SetReactionCenter(); param.setParameter(Boolean.TRUE); paramList.add(param); type.setParameterList(paramList); IReactionSet setOfReactions = type.initiate(setOfReactants, null); IAtomContainer reactant = setOfReactions.getReaction(0).getReactants().getAtomContainer(0); Assert.assertTrue(molecule.getAtom(0).getFlag(CDKConstants.REACTIVE_CENTER)); Assert.assertTrue(reactant.getAtom(0).getFlag(CDKConstants.REACTIVE_CENTER)); Assert.assertTrue(molecule.getAtom(1).getFlag(CDKConstants.REACTIVE_CENTER)); Assert.assertTrue(reactant.getAtom(1).getFlag(CDKConstants.REACTIVE_CENTER)); Assert.assertTrue(molecule.getAtom(2).getFlag(CDKConstants.REACTIVE_CENTER)); Assert.assertTrue(reactant.getAtom(2).getFlag(CDKConstants.REACTIVE_CENTER)); Assert.assertTrue(molecule.getBond(0).getFlag(CDKConstants.REACTIVE_CENTER)); Assert.assertTrue(reactant.getBond(0).getFlag(CDKConstants.REACTIVE_CENTER)); Assert.assertTrue(molecule.getBond(1).getFlag(CDKConstants.REACTIVE_CENTER)); Assert.assertTrue(reactant.getBond(1).getFlag(CDKConstants.REACTIVE_CENTER)); }
@Test public void testMapping() throws Exception { IReactionProcess type = new RearrangementRadicalReaction(); IAtomContainerSet setOfReactants = getExampleReactants(); IAtomContainer molecule = setOfReactants.getAtomContainer(0); List<IParameterReact> paramList = new ArrayList<IParameterReact>(); IParameterReact param = new SetReactionCenter(); param.setParameter(Boolean.FALSE); paramList.add(param); type.setParameterList(paramList); IReactionSet setOfReactions = type.initiate(setOfReactants, null); IAtomContainer product = setOfReactions.getReaction(0).getProducts().getAtomContainer(0); Assert.assertEquals(11, setOfReactions.getReaction(0).getMappingCount()); IAtom mappedProductA1 = (IAtom) ReactionManipulator.getMappedChemObject(setOfReactions.getReaction(0), molecule.getAtom(0)); Assert.assertEquals(mappedProductA1, product.getAtom(0)); mappedProductA1 = (IAtom) ReactionManipulator.getMappedChemObject(setOfReactions.getReaction(0), molecule.getAtom(1)); Assert.assertEquals(mappedProductA1, product.getAtom(1)); mappedProductA1 = (IAtom) ReactionManipulator.getMappedChemObject(setOfReactions.getReaction(0), molecule.getAtom(2)); Assert.assertEquals(mappedProductA1, product.getAtom(2)); }