ElectronImpactSDBReaction extends ReactionEngine implements IReactionProcess { @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); IParameterReact ipr = super.getParameterClass(SetReactionCenter.class); if (ipr != null && !ipr.isSetParameter()) setActiveCenters(reactant); Iterator<IBond> bonds = reactant.bonds().iterator(); while (bonds.hasNext()) { IBond bondi = bonds.next(); 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<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); 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; } ElectronImpactSDBReaction(); @Override ReactionSpecification getSpecification(); @Override IReactionSet initiate(IAtomContainerSet reactants, IAtomContainerSet agents);  }
@Test @Override public void testInitiate_IAtomContainerSet_IAtomContainerSet() throws Exception { IAtomContainerSet setOfReactants = getExampleReactants(); IAtomContainer reactant = setOfReactants.getAtomContainer(0); Iterator<IBond> bonds = reactant.bonds().iterator(); while (bonds.hasNext()) { IBond bond = (IBond) bonds.next(); IAtom atom1 = bond.getBegin(); IAtom atom2 = bond.getEnd(); if (bond.getOrder() == IBond.Order.SINGLE && atom1.getSymbol().equals("C") && atom2.getSymbol().equals("C")) { bond.setFlag(CDKConstants.REACTIVE_CENTER, true); atom1.setFlag(CDKConstants.REACTIVE_CENTER, true); atom2.setFlag(CDKConstants.REACTIVE_CENTER, true); } } Assert.assertEquals(0, reactant.getSingleElectronCount()); IReactionProcess type = new ElectronImpactSDBReaction(); 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(2, setOfReactions.getReactionCount()); Assert.assertEquals(2, setOfReactions.getReaction(0).getProductCount()); IAtomContainer molecule1 = setOfReactions.getReaction(0).getProducts().getAtomContainer(0); Assert.assertEquals(1, molecule1.getAtom(1).getFormalCharge().intValue()); Assert.assertEquals(0, molecule1.getSingleElectronCount()); IAtomContainer molecule2 = setOfReactions.getReaction(0).getProducts().getAtomContainer(1); Assert.assertEquals(1, molecule2.getSingleElectronCount()); Assert.assertEquals(1, molecule2.getConnectedSingleElectronsCount(molecule2.getAtom(0))); Assert.assertTrue(setOfReactions.getReaction(0).mappings().iterator().hasNext()); Assert.assertEquals(2, setOfReactions.getReaction(1).getProductCount()); molecule1 = setOfReactions.getReaction(1).getProducts().getAtomContainer(0); Assert.assertEquals(1, molecule1.getConnectedSingleElectronsCount(molecule1.getAtom(1))); molecule2 = setOfReactions.getReaction(1).getProducts().getAtomContainer(1); Assert.assertEquals(0, molecule2.getSingleElectronCount()); Assert.assertEquals(1, molecule2.getAtom(0).getFormalCharge().intValue()); }