/**
   * A unit test suite for JUnit for Ethene. Reaction: O=C-C-H => O(H)-C=C. Automatic looking for
   * active center.
   *
   * @cdk.inchi InChI=1/C2H4/c1-2/h1-2H2
   * @return The test suite
   */
  @Test
  public void testInitiate_IMoleculeSet_IMoleculeSet() throws Exception {

    IReactionProcess type = new AdductionProtonPBReaction();

    IMolecule molecule = getEthene();

    IMoleculeSet setOfReactants = DefaultChemObjectBuilder.getInstance().newMoleculeSet();
    setOfReactants.addMolecule(molecule);

    /* initiate */
    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());

    IMolecule product = setOfReactions.getReaction(0).getProducts().getMolecule(0);

    IMolecule molecule2 = getExpected();

    IQueryAtomContainer queryAtom =
        QueryAtomContainerCreator.createSymbolAndChargeQueryContainer(product);
    Assert.assertTrue(UniversalIsomorphismTester.isIsomorph(molecule2, queryAtom));
  }
  /**
   * A unit test suite for JUnit.
   *
   * @cdk.inchi InChI=1/C2H4/c1-2/h1-2H2
   * @return The test suite
   */
  @Test
  public void testCDKConstants_REACTIVE_CENTER() throws Exception {
    IReactionProcess type = new AdductionProtonPBReaction();
    IMoleculeSet setOfReactants = builder.newMoleculeSet();
    IMolecule molecule = getEthene();

    /*manually putting the active center*/
    molecule.getAtom(0).setFlag(CDKConstants.REACTIVE_CENTER, true);
    molecule.getAtom(1).setFlag(CDKConstants.REACTIVE_CENTER, true);
    molecule.getBond(0).setFlag(CDKConstants.REACTIVE_CENTER, true);

    setOfReactants.addMolecule(molecule);
    List<IParameterReact> paramList = new ArrayList<IParameterReact>();
    IParameterReact param = new SetReactionCenter();
    param.setParameter(Boolean.TRUE);
    paramList.add(param);
    type.setParameterList(paramList);

    /* initiate */
    IReactionSet setOfReactions = type.initiate(setOfReactants, null);

    IMolecule reactant = setOfReactions.getReaction(0).getReactants().getMolecule(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));
  }
  /**
   * A unit test suite for JUnit. Reaction:
   *
   * @return The test suite
   */
  @Test
  @Override
  public void testInitiate_IAtomContainerSet_IAtomContainerSet() throws Exception {
    IReactionProcess type = new RadicalSiteHrBetaReaction();

    IAtomContainerSet setOfReactants = getExampleReactants();

    /* initiate */

    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());
    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));
  }
  /**
   * A unit test suite for JUnit.
   *
   * @return The test suite
   */
  @Test
  public void testCDKConstants_REACTIVE_CENTER() throws Exception {
    IReactionProcess type = new RadicalSiteHrBetaReaction();

    IAtomContainerSet setOfReactants = getExampleReactants();
    IAtomContainer molecule = setOfReactants.getAtomContainer(0);

    /* manually put the reactive center */
    molecule.getAtom(3).setFlag(CDKConstants.REACTIVE_CENTER, true);
    molecule.getAtom(0).setFlag(CDKConstants.REACTIVE_CENTER, true);
    molecule.getAtom(6).setFlag(CDKConstants.REACTIVE_CENTER, true);
    molecule.getBond(5).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);

    /* initiate */
    IReactionSet setOfReactions = type.initiate(setOfReactants, null);

    IAtomContainer reactant = setOfReactions.getReaction(0).getReactants().getAtomContainer(0);
    Assert.assertTrue(molecule.getAtom(6).getFlag(CDKConstants.REACTIVE_CENTER));
    Assert.assertTrue(reactant.getAtom(6).getFlag(CDKConstants.REACTIVE_CENTER));
    Assert.assertTrue(molecule.getAtom(0).getFlag(CDKConstants.REACTIVE_CENTER));
    Assert.assertTrue(reactant.getAtom(0).getFlag(CDKConstants.REACTIVE_CENTER));
    Assert.assertTrue(molecule.getAtom(3).getFlag(CDKConstants.REACTIVE_CENTER));
    Assert.assertTrue(reactant.getAtom(3).getFlag(CDKConstants.REACTIVE_CENTER));
    Assert.assertTrue(molecule.getBond(5).getFlag(CDKConstants.REACTIVE_CENTER));
    Assert.assertTrue(reactant.getBond(5).getFlag(CDKConstants.REACTIVE_CENTER));
  }
  /**
   * Get the resonance structures from an IMolecule.
   *
   * @param molecule The IMolecule to analyze
   * @return The different resonance structures
   */
  @TestMethod("testGetStructures_IMolecule")
  public IMoleculeSet getStructures(IMolecule molecule) {
    int countStructure = 0;
    IMoleculeSet setOfMol = molecule.getBuilder().newMoleculeSet();
    setOfMol.addMolecule(molecule);

    for (int i = 0; i < setOfMol.getMoleculeCount(); i++) {
      IMolecule mol = setOfMol.getMolecule(i);
      for (IReactionProcess aReactionsList : reactionsList) {
        IReactionProcess reaction = aReactionsList;
        IMoleculeSet setOfReactants = molecule.getBuilder().newMoleculeSet();
        setOfReactants.addMolecule(mol);
        try {
          IReactionSet setOfReactions = reaction.initiate(setOfReactants, null);
          if (setOfReactions.getReactionCount() != 0)
            for (int k = 0; k < setOfReactions.getReactionCount(); k++)
              for (int j = 0;
                  j < setOfReactions.getReaction(k).getProducts().getAtomContainerCount();
                  j++) {
                IMolecule product = setOfReactions.getReaction(k).getProducts().getMolecule(j);
                if (!existAC(setOfMol, product)) {
                  setOfMol.addMolecule(product);
                  countStructure++;
                  if (countStructure > maxStructures) return setOfMol;
                }
              }
        } catch (CDKException e) {
          e.printStackTrace();
        }
      }
    }
    return setOfMol;
  }
  private void callDefaultReactions() {
    List<IParameterReact> paramList = new ArrayList<IParameterReact>();
    IParameterReact param = new SetReactionCenter();
    param.setParameter(Boolean.FALSE);
    paramList.add(param);

    IReactionProcess type = new SharingLonePairReaction();
    try {
      type.setParameterList(paramList);
    } catch (CDKException e) {
      e.printStackTrace();
    }
    reactionsList.add(type);

    type = new PiBondingMovementReaction();
    List<IParameterReact> paramList2 = new ArrayList<IParameterReact>();
    IParameterReact param2 = new SetReactionCenter();
    param2.setParameter(Boolean.FALSE);
    paramList2.add(param2);
    try {
      type.setParameterList(paramList2);
    } catch (CDKException e) {
      e.printStackTrace();
    }
    reactionsList.add(type);

    type = new RearrangementAnionReaction();
    try {
      type.setParameterList(paramList);
    } catch (CDKException e) {
      e.printStackTrace();
    }
    reactionsList.add(type);

    type = new RearrangementCationReaction();
    try {
      type.setParameterList(paramList);
    } catch (CDKException e) {
      e.printStackTrace();
    }
    reactionsList.add(type);

    type = new RearrangementLonePairReaction();
    try {
      type.setParameterList(paramList);
    } catch (CDKException e) {
      e.printStackTrace();
    }
    reactionsList.add(type);

    type = new RearrangementRadicalReaction();
    try {
      type.setParameterList(paramList);
    } catch (CDKException e) {
      e.printStackTrace();
    }
    reactionsList.add(type);
  }
  /**
   * A unit test suite for JUnit.
   *
   * @cdk.inchi InChI=1/C2H4/c1-2/h1-2H2
   * @return The test suite
   */
  @Test
  public void testMapping() throws Exception {
    IReactionProcess type = new AdductionProtonPBReaction();

    IMoleculeSet setOfReactants = DefaultChemObjectBuilder.getInstance().newMoleculeSet();
    IMolecule molecule = getEthene();

    setOfReactants.addMolecule(molecule);

    /*automatic looking for active center*/
    List<IParameterReact> paramList = new ArrayList<IParameterReact>();
    IParameterReact param = new SetReactionCenter();
    param.setParameter(Boolean.FALSE);
    paramList.add(param);
    type.setParameterList(paramList);

    /* initiate */

    IReactionSet setOfReactions = type.initiate(setOfReactants, null);

    IMolecule product = setOfReactions.getReaction(0).getProducts().getMolecule(0);

    Assert.assertEquals(3, 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));
    IBond mappedProductB1 =
        (IBond)
            ReactionManipulator.getMappedChemObject(
                setOfReactions.getReaction(0), molecule.getBond(0));
    Assert.assertEquals(mappedProductB1, product.getBond(0));
  }
  /**
   * A unit test suite for JUnit.
   *
   * @return The test suite
   */
  @Test
  public void testMapping() throws Exception {
    IReactionProcess type = new RadicalSiteHrBetaReaction();

    IAtomContainerSet setOfReactants = getExampleReactants();
    IAtomContainer molecule = setOfReactants.getAtomContainer(0);

    /* automatic search of the center active */
    List<IParameterReact> paramList = new ArrayList<IParameterReact>();
    IParameterReact param = new SetReactionCenter();
    param.setParameter(Boolean.FALSE);
    paramList.add(param);
    type.setParameterList(paramList);

    /* initiate */
    IReactionSet setOfReactions = type.initiate(setOfReactants, null);

    IAtomContainer product = setOfReactions.getReaction(0).getProducts().getAtomContainer(0);

    Assert.assertEquals(19, 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(6));
    Assert.assertEquals(mappedProductA2, product.getAtom(6));
    IAtom mappedProductA3 =
        (IAtom)
            ReactionManipulator.getMappedChemObject(
                setOfReactions.getReaction(0), molecule.getAtom(3));
    Assert.assertEquals(mappedProductA3, product.getAtom(3));
  }