ElectronImpactPDBReaction extends ReactionEngine implements IReactionProcess { @Override public IReactionSet initiate(IAtomContainerSet reactants, IAtomContainerSet agents) throws CDKException { logger.debug("initiate reaction: ElectronImpactPDBReaction"); if (reactants.getAtomContainerCount() != 1) { throw new CDKException("ElectronImpactPDBReaction only expects one reactant"); } if (agents != null) { throw new CDKException("ElectronImpactPDBReaction 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.DOUBLE || bondi.getOrder() == IBond.Order.TRIPLE) && 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; } ElectronImpactPDBReaction(); @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); 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.DOUBLE && 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); } } IAtomContainerSet setOfReactants = DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainerSet.class); setOfReactants.addAtomContainer(reactant); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(reactant); makeSureAtomTypesAreRecognized(reactant); IReactionProcess type = new ElectronImpactPDBReaction(); 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()); IAtomContainer molecule = setOfReactions.getReaction(0).getProducts().getAtomContainer(0); Assert.assertEquals(1, molecule.getAtom(0).getFormalCharge().intValue()); Assert.assertEquals(1, molecule.getConnectedSingleElectronsCount(molecule.getAtom(1))); Assert.assertEquals(1, molecule.getSingleElectronCount()); molecule = setOfReactions.getReaction(1).getProducts().getAtomContainer(0); Assert.assertEquals(1, molecule.getAtom(1).getFormalCharge().intValue()); Assert.assertEquals(1, molecule.getConnectedSingleElectronsCount(molecule.getAtom(0))); Assert.assertEquals(1, molecule.getSingleElectronCount()); Assert.assertEquals(17, setOfReactions.getReaction(0).getMappingCount()); }
@Test public void testAutomatic_Set_Active_Bond() 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.addBond(0, 1, IBond.Order.DOUBLE); reactant.addBond(1, 2, IBond.Order.SINGLE); addExplicitHydrogens(reactant); IAtomContainerSet setOfReactants = DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainerSet.class); setOfReactants.addAtomContainer(reactant); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(reactant); makeSureAtomTypesAreRecognized(reactant); IReactionProcess type = new ElectronImpactPDBReaction(); IReactionSet setOfReactions = type.initiate(setOfReactants, null); Assert.assertEquals(2, setOfReactions.getReactionCount()); IAtomContainer molecule = setOfReactions.getReaction(0).getProducts().getAtomContainer(0); Assert.assertEquals(1, molecule.getAtom(0).getFormalCharge().intValue()); Assert.assertEquals(1, molecule.getConnectedSingleElectronsCount(molecule.getAtom(1))); molecule = setOfReactions.getReaction(1).getProducts().getAtomContainer(0); Assert.assertEquals(1, molecule.getAtom(1).getFormalCharge().intValue()); Assert.assertEquals(1, molecule.getConnectedSingleElectronsCount(molecule.getAtom(0))); }
@Test public void testAutomatic_Set_Active_Bond2() 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); IAtomContainerSet setOfReactants = DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainerSet.class); setOfReactants.addAtomContainer(reactant); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(reactant); makeSureAtomTypesAreRecognized(reactant); IReactionProcess type = new ElectronImpactPDBReaction(); 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(3, setOfReactions.getReactionCount()); IAtomContainer molecule = setOfReactions.getReaction(0).getProducts().getAtomContainer(0); Assert.assertEquals(1, molecule.getAtom(0).getFormalCharge().intValue()); Assert.assertEquals(1, molecule.getConnectedSingleElectronsCount(molecule.getAtom(1))); molecule = setOfReactions.getReaction(1).getProducts().getAtomContainer(0); Assert.assertEquals(1, molecule.getAtom(1).getFormalCharge().intValue()); Assert.assertEquals(1, molecule.getConnectedSingleElectronsCount(molecule.getAtom(0))); Assert.assertEquals(17, setOfReactions.getReaction(0).getMappingCount()); }
@Test public void testCDKConstants_REACTIVE_CENTER() throws Exception { IReactionProcess type = new ElectronImpactPDBReaction(); 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); makeSureAtomTypesAreRecognized(molecule); IReactionSet setOfReactions = type.initiate(setOfReactants, null); Assert.assertEquals(2, setOfReactions.getReactionCount()); Assert.assertEquals(1, setOfReactions.getReaction(0).getProductCount()); 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 ElectronImpactPDBReaction(); 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(9, 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)); }