AdductionProtonLPReaction extends ReactionEngine implements IReactionProcess { @Override public IReactionSet initiate(IAtomContainerSet reactants, IAtomContainerSet agents) throws CDKException { logger.debug("initiate reaction: AdductionProtonLPReaction"); if (reactants.getAtomContainerCount() != 1) { throw new CDKException("AdductionProtonLPReaction only expects one reactant"); } if (agents != null) { throw new CDKException("AdductionProtonLPReaction 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<IAtom> atoms = reactant.atoms().iterator(); while (atoms.hasNext()) { IAtom atomi = atoms.next(); if (atomi.getFlag(CDKConstants.REACTIVE_CENTER) && (atomi.getFormalCharge() == CDKConstants.UNSET ? 0 : atomi.getFormalCharge()) <= 0 && reactant.getConnectedLonePairsCount(atomi) > 0 && reactant.getConnectedSingleElectronsCount(atomi) == 0) { ArrayList<IAtom> atomList = new ArrayList<IAtom>(); atomList.add(atomi); IAtom atomH = reactant.getBuilder().newInstance(IAtom.class, "H"); atomH.setFormalCharge(1); atomList.add(atomH); 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, null); if (reaction == null) continue; else setOfReactions.addReaction(reaction); } } return setOfReactions; } AdductionProtonLPReaction(); @Override ReactionSpecification getSpecification(); @Override IReactionSet initiate(IAtomContainerSet reactants, IAtomContainerSet agents);  }
@Test @Override public void testInitiate_IAtomContainerSet_IAtomContainerSet() throws Exception { IReactionProcess type = new AdductionProtonLPReaction(); List<IParameterReact> paramList = new ArrayList<IParameterReact>(); IParameterReact param = new SetReactionCenter(); param.setParameter(Boolean.FALSE); paramList.add(param); type.setParameterList(paramList); IReactionSet setOfReactions = type.initiate(getExampleReactants(), 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); IQueryAtomContainer queryAtom = QueryAtomContainerCreator.createSymbolAndChargeQueryContainer(product); Assert.assertTrue(uiTester.isIsomorph(molecule2, queryAtom)); }
@Test public void testManuallyCentreActive() throws Exception { IReactionProcess type = new AdductionProtonLPReaction(); IAtomContainerSet setOfReactants = getExampleReactants(); setOfReactants.getAtomContainer(0).getAtom(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); IQueryAtomContainer queryAtom = QueryAtomContainerCreator.createSymbolAndChargeQueryContainer(product); Assert.assertTrue(uiTester.isIsomorph(molecule2, queryAtom)); }
@Test public void testCDKConstants_REACTIVE_CENTER() throws Exception { IReactionProcess type = new AdductionProtonLPReaction(); 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.getAtom(4).setFlag(CDKConstants.REACTIVE_CENTER, true); molecule.getBond(0).setFlag(CDKConstants.REACTIVE_CENTER, true); molecule.getBond(1).setFlag(CDKConstants.REACTIVE_CENTER, true); molecule.getBond(3).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.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)); Assert.assertTrue(molecule.getBond(1).getFlag(CDKConstants.REACTIVE_CENTER)); Assert.assertTrue(reactant.getBond(1).getFlag(CDKConstants.REACTIVE_CENTER)); Assert.assertTrue(molecule.getBond(3).getFlag(CDKConstants.REACTIVE_CENTER)); Assert.assertTrue(reactant.getBond(3).getFlag(CDKConstants.REACTIVE_CENTER)); }
@Test public void testMapping() throws Exception { IReactionProcess type = new AdductionProtonLPReaction(); List<IParameterReact> paramList = new ArrayList<IParameterReact>(); IParameterReact param = new SetReactionCenter(); param.setParameter(Boolean.FALSE); paramList.add(param); type.setParameterList(paramList); IAtomContainerSet setOfReactants = getExampleReactants(); IAtomContainer molecule = setOfReactants.getAtomContainer(0); IReactionSet setOfReactions = type.initiate(setOfReactants, null); IAtomContainer product = setOfReactions.getReaction(0).getProducts().getAtomContainer(0); Assert.assertEquals(8, setOfReactions.getReaction(0).getMappingCount()); IAtom mappedProductA0 = (IAtom) ReactionManipulator.getMappedChemObject(setOfReactions.getReaction(0), molecule.getAtom(0)); Assert.assertEquals(mappedProductA0, product.getAtom(0)); }