ElectronImpactNBEReaction extends ReactionEngine implements IReactionProcess { @Override public IReactionSet initiate(IAtomContainerSet reactants, IAtomContainerSet agents) throws CDKException { logger.debug("initiate reaction: ElectronImpactNBEReaction"); if (reactants.getAtomContainerCount() != 1) { throw new CDKException("ElectronImpactNBEReaction only expects one reactant"); } if (agents != null) { throw new CDKException("ElectronImpactNBEReaction 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 = reactant.atoms().iterator(); while (atoms.hasNext()) { IAtom atom = atoms.next(); if (atom.getFlag(CDKConstants.REACTIVE_CENTER) && reactant.getConnectedLonePairsCount(atom) > 0 && reactant.getConnectedSingleElectronsCount(atom) == 0) { ArrayList<IAtom> atomList = new ArrayList<IAtom>(); atomList.add(atom); IAtomContainerSet moleculeSet = reactant.getBuilder().newInstance(IAtomContainerSet.class); moleculeSet.addAtomContainer(reactant); IReaction reaction = mechanism.initiate(moleculeSet, atomList, null); if (reaction == null) continue; else setOfReactions.addReaction(reaction); } } return setOfReactions; } ElectronImpactNBEReaction(); @Override ReactionSpecification getSpecification(); @Override IReactionSet initiate(IAtomContainerSet reactants, IAtomContainerSet agents);  }
@Test @Override public void testInitiate_IAtomContainerSet_IAtomContainerSet() throws Exception { IAtomContainer reactant = builder.newInstance(IAtomContainer.class); reactant.addAtom(builder.newInstance(IAtom.class, "C")); reactant.addAtom(builder.newInstance(IAtom.class, "C")); reactant.addAtom(builder.newInstance(IAtom.class, "C")); reactant.addAtom(builder.newInstance(IAtom.class, "C")); reactant.addAtom(builder.newInstance(IAtom.class, "O")); reactant.addAtom(builder.newInstance(IAtom.class, "C")); reactant.addAtom(builder.newInstance(IAtom.class, "C")); reactant.addBond(0, 1, IBond.Order.DOUBLE); reactant.addBond(1, 2, IBond.Order.SINGLE); reactant.addBond(2, 3, IBond.Order.SINGLE); reactant.addBond(3, 4, IBond.Order.DOUBLE); reactant.addBond(3, 5, IBond.Order.SINGLE); reactant.addBond(5, 6, IBond.Order.SINGLE); addExplicitHydrogens(reactant); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(reactant); lpcheck.saturate(reactant); Iterator<IAtom> atoms = reactant.atoms().iterator(); while (atoms.hasNext()) { IAtom atom = (IAtom) atoms.next(); if (reactant.getConnectedLonePairsCount(atom) > 0) { atom.setFlag(CDKConstants.REACTIVE_CENTER, true); } } IAtomContainerSet setOfReactants = DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainerSet.class); setOfReactants.addAtomContainer(reactant); makeSureAtomTypesAreRecognized(reactant); IReactionProcess type = new ElectronImpactNBEReaction(); 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 molecule = setOfReactions.getReaction(0).getProducts().getAtomContainer(0); Assert.assertEquals(1, molecule.getAtom(4).getFormalCharge().intValue()); Assert.assertEquals(1, molecule.getConnectedSingleElectronsCount(molecule.getAtom(4))); Assert.assertTrue(setOfReactions.getReaction(0).mappings().iterator().hasNext()); }
@Test public void testAutomatic_Set_Active_Atom() throws Exception { IAtomContainer reactant = builder.newInstance(IAtomContainer.class); reactant.addAtom(builder.newInstance(IAtom.class, "C")); reactant.addAtom(builder.newInstance(IAtom.class, "C")); reactant.addAtom(builder.newInstance(IAtom.class, "C")); reactant.addAtom(builder.newInstance(IAtom.class, "C")); reactant.addAtom(builder.newInstance(IAtom.class, "O")); reactant.addAtom(builder.newInstance(IAtom.class, "C")); reactant.addAtom(builder.newInstance(IAtom.class, "C")); reactant.addBond(0, 1, IBond.Order.DOUBLE); reactant.addBond(1, 2, IBond.Order.SINGLE); reactant.addBond(2, 3, IBond.Order.SINGLE); reactant.addBond(3, 4, IBond.Order.DOUBLE); reactant.addBond(3, 5, IBond.Order.SINGLE); reactant.addBond(5, 6, IBond.Order.SINGLE); addExplicitHydrogens(reactant); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(reactant); lpcheck.saturate(reactant); IAtomContainerSet setOfReactants = DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainerSet.class); setOfReactants.addAtomContainer(reactant); makeSureAtomTypesAreRecognized(reactant); IReactionProcess type = new ElectronImpactNBEReaction(); IReactionSet setOfReactions = type.initiate(setOfReactants, null); Assert.assertEquals(1, setOfReactions.getReactionCount()); Assert.assertEquals(1, setOfReactions.getReaction(0).getProductCount()); IAtomContainer molecule = setOfReactions.getReaction(0).getProducts().getAtomContainer(0); Assert.assertEquals(1, molecule.getAtom(4).getFormalCharge().intValue()); Assert.assertEquals(1, molecule.getConnectedSingleElectronsCount(molecule.getAtom(4))); }
@Test public void testNsp3SingleB() throws Exception { IAtomContainer molecule = builder.newInstance(IAtomContainer.class); molecule.addAtom(builder.newInstance(IAtom.class, "C")); molecule.addAtom(builder.newInstance(IAtom.class, "N")); molecule.addBond(0, 1, IBond.Order.SINGLE); molecule.addAtom(builder.newInstance(IAtom.class, "H")); molecule.addAtom(builder.newInstance(IAtom.class, "H")); molecule.addAtom(builder.newInstance(IAtom.class, "H")); molecule.addAtom(builder.newInstance(IAtom.class, "H")); molecule.addAtom(builder.newInstance(IAtom.class, "H")); molecule.addBond(0, 2, IBond.Order.SINGLE); molecule.addBond(0, 3, IBond.Order.SINGLE); molecule.addBond(0, 4, IBond.Order.SINGLE); molecule.addBond(1, 5, IBond.Order.SINGLE); molecule.addBond(1, 6, IBond.Order.SINGLE); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(molecule); lpcheck.saturate(molecule); molecule.getAtom(1).setFlag(CDKConstants.REACTIVE_CENTER, true); IAtomContainerSet setOfReactants = DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainerSet.class); setOfReactants.addAtomContainer(molecule); IReactionProcess type = new ElectronImpactNBEReaction(); 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 expected1 = builder.newInstance(IAtomContainer.class); expected1.addAtom(builder.newInstance(IAtom.class, "C")); expected1.addAtom(builder.newInstance(IAtom.class, "N")); expected1.getAtom(1).setFormalCharge(+1); expected1.addSingleElectron(builder.newInstance(ISingleElectron.class, expected1.getAtom(1))); expected1.addBond(0, 1, IBond.Order.SINGLE); expected1.addAtom(builder.newInstance(IAtom.class, "H")); expected1.addAtom(builder.newInstance(IAtom.class, "H")); expected1.addAtom(builder.newInstance(IAtom.class, "H")); expected1.addAtom(builder.newInstance(IAtom.class, "H")); expected1.addAtom(builder.newInstance(IAtom.class, "H")); expected1.addBond(0, 2, IBond.Order.SINGLE); expected1.addBond(0, 3, IBond.Order.SINGLE); expected1.addBond(0, 4, IBond.Order.SINGLE); expected1.addBond(1, 5, IBond.Order.SINGLE); expected1.addBond(1, 6, IBond.Order.SINGLE); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(expected1); lpcheck.saturate(expected1); IAtomContainer product1 = setOfReactions.getReaction(0).getProducts().getAtomContainer(0); QueryAtomContainer queryAtom = QueryAtomContainerCreator.createSymbolAndChargeQueryContainer(expected1); Assert.assertTrue(new UniversalIsomorphismTester().isIsomorph(product1, queryAtom)); }
@Test public void testNsp2SingleB() throws Exception { IAtomContainer molecule = builder.newInstance(IAtomContainer.class); molecule.addAtom(builder.newInstance(IAtom.class, "N")); molecule.addAtom(builder.newInstance(IAtom.class, "C")); molecule.addBond(0, 1, IBond.Order.DOUBLE); molecule.addAtom(builder.newInstance(IAtom.class, "H")); molecule.addAtom(builder.newInstance(IAtom.class, "H")); molecule.addAtom(builder.newInstance(IAtom.class, "H")); molecule.addBond(0, 2, IBond.Order.SINGLE); molecule.addBond(1, 3, IBond.Order.SINGLE); molecule.addBond(1, 4, IBond.Order.SINGLE); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(molecule); lpcheck.saturate(molecule); molecule.getAtom(0).setFlag(CDKConstants.REACTIVE_CENTER, true); IAtomContainerSet setOfReactants = DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainerSet.class); setOfReactants.addAtomContainer(molecule); IReactionProcess type = new ElectronImpactNBEReaction(); 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 expected1 = builder.newInstance(IAtomContainer.class); expected1.addAtom(builder.newInstance(IAtom.class, "N")); expected1.getAtom(0).setFormalCharge(1); expected1.addSingleElectron(builder.newInstance(ISingleElectron.class, expected1.getAtom(0))); expected1.addAtom(builder.newInstance(IAtom.class, "C")); expected1.addBond(0, 1, IBond.Order.DOUBLE); expected1.addAtom(builder.newInstance(IAtom.class, "H")); expected1.addAtom(builder.newInstance(IAtom.class, "H")); expected1.addAtom(builder.newInstance(IAtom.class, "H")); expected1.addBond(0, 2, IBond.Order.SINGLE); expected1.addBond(1, 3, IBond.Order.SINGLE); expected1.addBond(1, 4, IBond.Order.SINGLE); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(expected1); lpcheck.saturate(expected1); IAtomContainer product1 = setOfReactions.getReaction(0).getProducts().getAtomContainer(0); QueryAtomContainer queryAtom = QueryAtomContainerCreator.createSymbolAndChargeQueryContainer(expected1); Assert.assertTrue(new UniversalIsomorphismTester().isIsomorph(product1, queryAtom)); }
@Test public void testFspSingleB() throws Exception { IAtomContainer molecule = builder.newInstance(IAtomContainer.class); molecule.addAtom(builder.newInstance(IAtom.class, "F")); molecule.addAtom(builder.newInstance(IAtom.class, "C")); molecule.addBond(0, 1, IBond.Order.SINGLE); molecule.addAtom(builder.newInstance(IAtom.class, "H")); molecule.addAtom(builder.newInstance(IAtom.class, "H")); molecule.addAtom(builder.newInstance(IAtom.class, "H")); molecule.addBond(1, 2, IBond.Order.SINGLE); molecule.addBond(1, 3, IBond.Order.SINGLE); molecule.addBond(1, 4, IBond.Order.SINGLE); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(molecule); lpcheck.saturate(molecule); molecule.getAtom(0).setFlag(CDKConstants.REACTIVE_CENTER, true); IAtomContainerSet setOfReactants = DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainerSet.class); setOfReactants.addAtomContainer(molecule); IReactionProcess type = new ElectronImpactNBEReaction(); 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 expected1 = builder.newInstance(IAtomContainer.class); expected1.addAtom(builder.newInstance(IAtom.class, "F")); expected1.getAtom(0).setFormalCharge(1); expected1.addSingleElectron(builder.newInstance(ISingleElectron.class, expected1.getAtom(0))); expected1.addAtom(builder.newInstance(IAtom.class, "C")); expected1.addBond(0, 1, IBond.Order.SINGLE); expected1.addAtom(builder.newInstance(IAtom.class, "H")); expected1.addAtom(builder.newInstance(IAtom.class, "H")); expected1.addAtom(builder.newInstance(IAtom.class, "H")); expected1.addBond(1, 2, IBond.Order.SINGLE); expected1.addBond(1, 3, IBond.Order.SINGLE); expected1.addBond(1, 4, IBond.Order.SINGLE); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(expected1); lpcheck.saturate(expected1); IAtomContainer product1 = setOfReactions.getReaction(0).getProducts().getAtomContainer(0); QueryAtomContainer queryAtom = QueryAtomContainerCreator.createSymbolAndChargeQueryContainer(expected1); Assert.assertTrue(new UniversalIsomorphismTester().isIsomorph(product1, queryAtom)); }
@Test public void testCDKConstants_REACTIVE_CENTER() throws Exception { IReactionProcess type = new ElectronImpactNBEReaction(); IAtomContainerSet setOfReactants = getExampleReactants(); IAtomContainer molecule = setOfReactants.getAtomContainer(0); molecule.getAtom(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); Assert.assertEquals(1, setOfReactions.getReactionCount()); Assert.assertEquals(1, setOfReactions.getReaction(0).getProductCount()); IAtomContainer reactant = setOfReactions.getReaction(0).getReactants().getAtomContainer(0); Assert.assertTrue(molecule.getAtom(1).getFlag(CDKConstants.REACTIVE_CENTER)); Assert.assertTrue(reactant.getAtom(1).getFlag(CDKConstants.REACTIVE_CENTER)); }
@Test public void testMapping() throws Exception { IReactionProcess type = new ElectronImpactNBEReaction(); 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(4, setOfReactions.getReaction(0).getMappingCount()); IAtom mappedProductA1 = (IAtom) ReactionManipulator.getMappedChemObject(setOfReactions.getReaction(0), molecule.getAtom(1)); Assert.assertEquals(mappedProductA1, product.getAtom(1)); }