AdductionProtonPBReaction extends ReactionEngine implements IReactionProcess { @Override public IReactionSet initiate(IAtomContainerSet reactants, IAtomContainerSet agents) throws CDKException { logger.debug("initiate reaction: AdductionProtonPBReaction"); if (reactants.getAtomContainerCount() != 1) { throw new CDKException("AdductionProtonPBReaction only expects one reactant"); } if (agents != null) { throw new CDKException("AdductionProtonPBReaction 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); if (AtomContainerManipulator.getTotalCharge(reactant) != 0) return setOfReactions; Iterator<IBond> bondis = reactant.bonds().iterator(); while (bondis.hasNext()) { IBond bondi = bondis.next(); if (bondi.getFlag(CDKConstants.REACTIVE_CENTER) && ((bondi.getOrder() == IBond.Order.DOUBLE) || (bondi.getOrder() == IBond.Order.TRIPLE)) && bondi.getBegin().getFlag(CDKConstants.REACTIVE_CENTER) && bondi.getEnd().getFlag(CDKConstants.REACTIVE_CENTER)) { int chargeAtom0 = bondi.getBegin().getFormalCharge() == null ? 0 : bondi.getBegin().getFormalCharge(); int chargeAtom1 = bondi.getEnd().getFormalCharge() == null ? 0 : bondi.getEnd().getFormalCharge(); if (chargeAtom0 >= 0 && chargeAtom1 >= 0 && reactant.getConnectedSingleElectronsCount(bondi.getBegin()) == 0 && reactant.getConnectedSingleElectronsCount(bondi.getEnd()) == 0 && reactant.getConnectedLonePairsCount(bondi.getBegin()) == 0 && reactant.getConnectedLonePairsCount(bondi.getEnd()) == 0) { for (int j = 0; j < 2; j++) { ArrayList<IAtom> atomList = new ArrayList<IAtom>(); if (j == 0) { atomList.add(bondi.getBegin()); atomList.add(bondi.getEnd()); } else { atomList.add(bondi.getEnd()); atomList.add(bondi.getBegin()); } IAtom atomH = reactant.getBuilder().newInstance(IAtom.class, "H"); atomH.setFormalCharge(1); atomList.add(atomH); ArrayList<IBond> bondList = new ArrayList<IBond>(); bondList.add(bondi); IAtomContainerSet moleculeSet = reactant.getBuilder().newInstance(IAtomContainerSet.class); moleculeSet.addAtomContainer(reactant); IAtomContainer adduct = reactant.getBuilder().newInstance(IAtomContainer.class); adduct.addAtom(atomH); moleculeSet.addAtomContainer(adduct); IReaction reaction = mechanism.initiate(moleculeSet, atomList, bondList); if (reaction == null) continue; else setOfReactions.addReaction(reaction); } } } } return setOfReactions; } AdductionProtonPBReaction(); @Override ReactionSpecification getSpecification(); @Override IReactionSet initiate(IAtomContainerSet reactants, IAtomContainerSet agents);  }
@Test @Override public void testInitiate_IAtomContainerSet_IAtomContainerSet() throws Exception { IReactionProcess type = new AdductionProtonPBReaction(); 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(2, setOfReactions.getReactionCount()); Assert.assertEquals(1, setOfReactions.getReaction(0).getProductCount()); IAtomContainer product = setOfReactions.getReaction(0).getProducts().getAtomContainer(0); IAtomContainer molecule2 = getExpectedProducts().getAtomContainer(0); IQueryAtomContainer queryAtom = QueryAtomContainerCreator.createSymbolAndChargeQueryContainer(product); Assert.assertTrue(new UniversalIsomorphismTester().isIsomorph(molecule2, queryAtom)); }
@Test public void testManuallyCentreActive() throws Exception { IReactionProcess type = new AdductionProtonPBReaction(); 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.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(2, setOfReactions.getReactionCount()); Assert.assertEquals(1, setOfReactions.getReaction(0).getProductCount()); IAtomContainer product = setOfReactions.getReaction(0).getProducts().getAtomContainer(0); IAtomContainer molecule2 = getExpectedProducts().getAtomContainer(0); IQueryAtomContainer queryAtom = QueryAtomContainerCreator.createSymbolAndChargeQueryContainer(product); Assert.assertTrue(new UniversalIsomorphismTester().isIsomorph(molecule2, queryAtom)); }
@Test public void testCDKConstants_REACTIVE_CENTER() throws Exception { IReactionProcess type = new AdductionProtonPBReaction(); 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.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 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.getBond(0).getFlag(CDKConstants.REACTIVE_CENTER)); Assert.assertTrue(reactant.getBond(0).getFlag(CDKConstants.REACTIVE_CENTER)); }
@Test public void testMapping() throws Exception { IReactionProcess type = new AdductionProtonPBReaction(); 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(7, 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)); }