RadicalSiteRrBetaReaction extends ReactionEngine implements IReactionProcess { @Override public IReactionSet initiate(IAtomContainerSet reactants, IAtomContainerSet agents) throws CDKException { logger.debug("initiate reaction: RadicalSiteRrBetaReaction"); if (reactants.getAtomContainerCount() != 1) { throw new CDKException("RadicalSiteRrBetaReaction only expects one reactant"); } if (agents != null) { throw new CDKException("RadicalSiteRrBetaReaction 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); } } IParameterReact ipr = super.getParameterClass(SetReactionCenter.class); if (ipr != null && !ipr.isSetParameter()) setActiveCenters(reactant); HOSECodeGenerator hcg = new HOSECodeGenerator(); Iterator<IAtom> atomis = reactant.atoms().iterator(); while (atomis.hasNext()) { IAtom atomi = atomis.next(); if (atomi.getFlag(CDKConstants.REACTIVE_CENTER) && reactant.getConnectedSingleElectronsCount(atomi) == 1) { hcg.getSpheres(reactant, atomi, 2, true); List<IAtom> atom1s = hcg.getNodesInSphere(2); hcg.getSpheres(reactant, atomi, 3, true); Iterator<IAtom> atomls = hcg.getNodesInSphere(3).iterator(); while (atomls.hasNext()) { IAtom atoml = atomls.next(); if (atoml != null && atoml.getFlag(CDKConstants.REACTIVE_CENTER) && !atoml.getFlag(CDKConstants.ISINRING) && (atoml.getFormalCharge() == CDKConstants.UNSET ? 0 : atoml.getFormalCharge()) == 0 && !atoml.getSymbol().equals("H") && reactant.getMaximumBondOrder(atoml) == IBond.Order.SINGLE) { Iterator<IAtom> atomRs = reactant.getConnectedAtomsList(atoml).iterator(); while (atomRs.hasNext()) { IAtom atomR = atomRs.next(); if (atom1s.contains(atomR)) continue; if (reactant.getBond(atomR, atoml).getFlag(CDKConstants.REACTIVE_CENTER) && atomR.getFlag(CDKConstants.REACTIVE_CENTER) && (atomR.getFormalCharge() == CDKConstants.UNSET ? 0 : atomR.getFormalCharge()) == 0) { ArrayList<IAtom> atomList = new ArrayList<IAtom>(); atomList.add(atomR); atomList.add(atomi); atomList.add(atoml); ArrayList<IBond> bondList = new ArrayList<IBond>(); bondList.add(reactant.getBond(atomR, 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; } RadicalSiteRrBetaReaction(); @Override ReactionSpecification getSpecification(); @Override IReactionSet initiate(IAtomContainerSet reactants, IAtomContainerSet agents);  }
@Test @Override public void testInitiate_IAtomContainerSet_IAtomContainerSet() throws Exception { IReactionProcess type = new RadicalSiteRrBetaReaction(); 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(4).setFlag(CDKConstants.REACTIVE_CENTER, true); molecule.getBond(0).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 RadicalSiteRrBetaReaction(); 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(4).setFlag(CDKConstants.REACTIVE_CENTER, true); molecule.getBond(0).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()); 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(4).getFlag(CDKConstants.REACTIVE_CENTER)); Assert.assertTrue(reactant.getAtom(4).getFlag(CDKConstants.REACTIVE_CENTER)); Assert.assertTrue(molecule.getBond(0).getFlag(CDKConstants.REACTIVE_CENTER)); Assert.assertTrue(reactant.getBond(0).getFlag(CDKConstants.REACTIVE_CENTER)); }
@Test public void testMapping() throws Exception { IReactionProcess type = new RadicalSiteRrBetaReaction(); 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(4).setFlag(CDKConstants.REACTIVE_CENTER, true); molecule.getBond(0).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 product = setOfReactions.getReaction(0).getProducts().getAtomContainer(0); Assert.assertEquals(22, setOfReactions.getReaction(0).getMappingCount()); IAtom mappedProductA1 = (IAtom) ReactionManipulator.getMappedChemObject(setOfReactions.getReaction(0), molecule.getAtom(0)); Assert.assertEquals(mappedProductA1, product.getAtom(0)); IAtom mappedProductA2 = (IAtom) ReactionManipulator.getMappedChemObject(setOfReactions.getReaction(0), molecule.getAtom(1)); Assert.assertEquals(mappedProductA2, product.getAtom(1)); IAtom mappedProductA3 = (IAtom) ReactionManipulator.getMappedChemObject(setOfReactions.getReaction(0), molecule.getAtom(4)); Assert.assertEquals(mappedProductA3, product.getAtom(4)); }