PiBondingMovementReaction extends ReactionEngine implements IReactionProcess { @Override public IReactionSet initiate(IAtomContainerSet reactants, IAtomContainerSet agents) throws CDKException { logger.debug("initiate reaction: PiBondingMovementReaction"); if (reactants.getAtomContainerCount() != 1) { throw new CDKException("PiBondingMovementReaction only expects one reactant"); } if (agents != null) { throw new CDKException("PiBondingMovementReaction don't expects agents"); } IReactionSet setOfReactions = reactants.getBuilder().newInstance(IReactionSet.class); IAtomContainer reactant = reactants.getAtomContainer(0); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(reactant); IParameterReact ipr = super.getParameterClass(SetReactionCenter.class); if (ipr != null && !ipr.isSetParameter()) setActiveCenters(reactant); AllRingsFinder arf = new AllRingsFinder(); IRingSet ringSet = arf.findAllRings(reactant); for (int ir = 0; ir < ringSet.getAtomContainerCount(); ir++) { IRing ring = (IRing) ringSet.getAtomContainer(ir); int nrAtoms = ring.getAtomCount(); if (nrAtoms % 2 == 0) { int nrSingleBonds = 0; for (IBond iBond : ring.bonds()) { if (iBond.getOrder() == IBond.Order.SINGLE) nrSingleBonds++; } if (nrSingleBonds != 0 && nrAtoms / 2 == nrSingleBonds) { Iterator<IBond> bondfs = ring.bonds().iterator(); boolean ringCompletActive = false; while (bondfs.hasNext()) { if (bondfs.next().getFlag(CDKConstants.REACTIVE_CENTER)) ringCompletActive = true; else { ringCompletActive = false; break; } } if (!ringCompletActive) continue; IReaction reaction = reactants.getBuilder().newInstance(IReaction.class); reaction.addReactant(reactant); IAtomContainer reactantCloned; try { reactantCloned = reactant.clone(); } catch (CloneNotSupportedException e) { throw new CDKException("Could not clone IAtomContainer!", e); } for (IBond bondi : ring.bonds()) { int bondiP = reactant.indexOf(bondi); if (bondi.getOrder() == IBond.Order.SINGLE) BondManipulator.increaseBondOrder(reactantCloned.getBond(bondiP)); else BondManipulator.decreaseBondOrder(reactantCloned.getBond(bondiP)); } reaction.addProduct(reactantCloned); setOfReactions.addReaction(reaction); } } } return setOfReactions; } PiBondingMovementReaction(); @Override ReactionSpecification getSpecification(); @Override IReactionSet initiate(IAtomContainerSet reactants, IAtomContainerSet agents);  }
@Test @Override public void testInitiate_IAtomContainerSet_IAtomContainerSet() throws Exception { IReactionProcess type = new PiBondingMovementReaction(); IAtomContainer molecule = builder.newInstance(IAtomContainer.class); molecule.addAtom(builder.newInstance(IAtom.class, "C")); molecule.addAtom(builder.newInstance(IAtom.class, "C")); molecule.addBond(0, 1, IBond.Order.DOUBLE); molecule.addAtom(builder.newInstance(IAtom.class, "C")); molecule.addBond(1, 2, IBond.Order.SINGLE); molecule.addAtom(builder.newInstance(IAtom.class, "C")); molecule.addBond(2, 3, IBond.Order.DOUBLE); molecule.addAtom(builder.newInstance(IAtom.class, "C")); molecule.addBond(3, 4, IBond.Order.SINGLE); molecule.addAtom(builder.newInstance(IAtom.class, "C")); molecule.addBond(4, 5, IBond.Order.DOUBLE); molecule.addBond(5, 0, IBond.Order.SINGLE); addExplicitHydrogens(molecule); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(molecule); makeSureAtomTypesAreRecognized(molecule); IAtomContainerSet setOfReactants = DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainerSet.class); setOfReactants.addAtomContainer(molecule); List<IParameterReact> paramList = new ArrayList<>(); IParameterReact param = new SetReactionCenter(); param.setParameter(Boolean.FALSE); 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 product2 = setOfReactions.getReaction(0).getProducts().getAtomContainer(0); IQueryAtomContainer queryAtom = QueryAtomContainerCreator.createSymbolAndChargeQueryContainer(product2); Assert.assertTrue(new UniversalIsomorphismTester().isIsomorph(molecule, queryAtom)); }
@Test public void testAutomaticSearchCentreActiveExample1() throws Exception { IReactionProcess type = new PiBondingMovementReaction(); IAtomContainer molecule = builder.newInstance(IAtomContainer.class); molecule.addAtom(builder.newInstance(IAtom.class, "C")); molecule.addAtom(builder.newInstance(IAtom.class, "C")); molecule.addBond(0, 1, IBond.Order.DOUBLE); molecule.addAtom(builder.newInstance(IAtom.class, "C")); molecule.addBond(1, 2, IBond.Order.SINGLE); molecule.addAtom(builder.newInstance(IAtom.class, "C")); molecule.addBond(1, 3, IBond.Order.SINGLE); molecule.addAtom(builder.newInstance(IAtom.class, "C")); molecule.addBond(3, 4, IBond.Order.SINGLE); molecule.addAtom(builder.newInstance(IAtom.class, "C")); molecule.addBond(3, 5, IBond.Order.DOUBLE); molecule.addAtom(builder.newInstance(IAtom.class, "C")); molecule.addBond(5, 6, IBond.Order.SINGLE); molecule.addAtom(builder.newInstance(IAtom.class, "C")); molecule.addBond(6, 7, IBond.Order.DOUBLE); molecule.addBond(7, 0, IBond.Order.SINGLE); addExplicitHydrogens(molecule); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(molecule); makeSureAtomTypesAreRecognized(molecule); IAtomContainerSet setOfReactants = DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainerSet.class); setOfReactants.addAtomContainer(molecule); List<IParameterReact> paramList = new ArrayList<>(); IParameterReact param = new SetReactionCenter(); param.setParameter(Boolean.FALSE); 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 product2 = setOfReactions.getReaction(0).getProducts().getAtomContainer(0); IAtomContainer molecule2 = builder.newInstance(IAtomContainer.class); molecule2.addAtom(builder.newInstance(IAtom.class, "C")); molecule2.addAtom(builder.newInstance(IAtom.class, "C")); molecule2.addBond(0, 1, IBond.Order.SINGLE); molecule2.addAtom(builder.newInstance(IAtom.class, "C")); molecule2.addBond(0, 2, IBond.Order.DOUBLE); molecule2.addAtom(builder.newInstance(IAtom.class, "C")); molecule2.addBond(2, 3, IBond.Order.SINGLE); molecule2.addAtom(builder.newInstance(IAtom.class, "C")); molecule2.addBond(2, 4, IBond.Order.SINGLE); molecule2.addAtom(builder.newInstance(IAtom.class, "C")); molecule2.addBond(4, 5, IBond.Order.DOUBLE); molecule2.addAtom(builder.newInstance(IAtom.class, "C")); molecule2.addBond(5, 6, IBond.Order.SINGLE); molecule2.addAtom(builder.newInstance(IAtom.class, "C")); molecule2.addBond(6, 7, IBond.Order.DOUBLE); molecule2.addBond(7, 0, IBond.Order.SINGLE); addExplicitHydrogens(molecule2); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(molecule2); makeSureAtomTypesAreRecognized(molecule2); IQueryAtomContainer queryAtom = QueryAtomContainerCreator.createSymbolAndChargeQueryContainer(product2); Assert.assertTrue(new UniversalIsomorphismTester().isIsomorph(molecule2, queryAtom)); }
@Test public void testDoubleRingConjugated() throws Exception { IReactionProcess type = new PiBondingMovementReaction(); IAtomContainerSet setOfReactants = getExampleReactants(); List<IParameterReact> paramList = new ArrayList<>(); 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 product1 = setOfReactions.getReaction(0).getProducts().getAtomContainer(0); IAtomContainer molecule1 = getExpectedProducts().getAtomContainer(0); Assert.assertEquals(1, setOfReactions.getReaction(1).getProductCount()); IAtomContainer product2 = setOfReactions.getReaction(1).getProducts().getAtomContainer(0); IAtomContainer molecule2 = builder.newInstance(IAtomContainer.class); molecule2.addAtom(builder.newInstance(IAtom.class, "C")); molecule2.addAtom(builder.newInstance(IAtom.class, "C")); molecule2.addBond(0, 1, IBond.Order.SINGLE); molecule2.addAtom(builder.newInstance(IAtom.class, "C")); molecule2.addBond(1, 2, IBond.Order.SINGLE); molecule2.addAtom(builder.newInstance(IAtom.class, "C")); molecule2.addBond(2, 3, IBond.Order.DOUBLE); molecule2.addAtom(builder.newInstance(IAtom.class, "C")); molecule2.addBond(3, 4, IBond.Order.SINGLE); molecule2.addAtom(builder.newInstance(IAtom.class, "C")); molecule2.addBond(4, 5, IBond.Order.DOUBLE); molecule2.addAtom(builder.newInstance(IAtom.class, "C")); molecule2.addBond(5, 6, IBond.Order.SINGLE); molecule2.addAtom(builder.newInstance(IAtom.class, "C")); molecule2.addBond(6, 7, IBond.Order.DOUBLE); molecule2.addAtom(builder.newInstance(IAtom.class, "C")); molecule2.addBond(7, 8, IBond.Order.SINGLE); molecule2.addAtom(builder.newInstance(IAtom.class, "C")); molecule2.addBond(8, 9, IBond.Order.DOUBLE); molecule2.addAtom(builder.newInstance(IAtom.class, "C")); molecule2.addBond(9, 10, IBond.Order.SINGLE); molecule2.addBond(10, 1, IBond.Order.DOUBLE); molecule2.addBond(9, 4, IBond.Order.SINGLE); addExplicitHydrogens(molecule2); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(molecule2); makeSureAtomTypesAreRecognized(molecule2); Assert.assertTrue((matches(molecule2, product1) && matches(molecule1, product2)) || (matches(molecule1, product1) && matches(molecule2, product2))); }
@Test public void testDoubleRingConjugated2() throws Exception { IReactionProcess type = new PiBondingMovementReaction(); IAtomContainerSet setOfReactants = getExampleReactants(); IAtomContainer molecule = setOfReactants.getAtomContainer(0); molecule.getBond(1).setFlag(CDKConstants.REACTIVE_CENTER, true); molecule.getBond(2).setFlag(CDKConstants.REACTIVE_CENTER, true); molecule.getBond(3).setFlag(CDKConstants.REACTIVE_CENTER, true); molecule.getBond(9).setFlag(CDKConstants.REACTIVE_CENTER, true); molecule.getBond(10).setFlag(CDKConstants.REACTIVE_CENTER, true); molecule.getBond(11).setFlag(CDKConstants.REACTIVE_CENTER, true); List<IParameterReact> paramList = new ArrayList<>(); 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 product2 = setOfReactions.getReaction(0).getProducts().getAtomContainer(0); IAtomContainer molecule2 = getExpectedProducts().getAtomContainer(0); IQueryAtomContainer queryAtom = QueryAtomContainerCreator.createSymbolAndChargeQueryContainer(product2); Assert.assertTrue(new UniversalIsomorphismTester().isIsomorph(molecule2, queryAtom)); }