/**
   * 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 for Ethene. Reaction: O=C-C-H => O(H)-C=C. Manually putting for
   * active center.
   *
   * @cdk.inchi InChI=1/C2H4/c1-2/h1-2H2
   * @return The test suite
   */
  @Test
  public void testManuallyCentreActive() throws Exception {
    IReactionProcess type = new AdductionProtonPBReaction();
    IMolecule molecule = getEthene();

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

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

    /* initiate */
    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());
    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));
  }
示例#3
0
  @Test
  public void testReading() throws Exception {
    String filename = "data/asn/pubchem/cid1145.xml";
    logger.info("Testing: " + filename);
    InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename);
    PCCompoundXMLReader reader = new PCCompoundXMLReader(ins);
    IMolecule molecule = (IMolecule) reader.read(new Molecule());
    Assert.assertNotNull(molecule);

    // check atom stuff
    Assert.assertEquals(14, molecule.getAtomCount());
    Assert.assertEquals("O", molecule.getAtom(0).getSymbol());
    Assert.assertEquals(Integer.valueOf(-1), molecule.getAtom(0).getFormalCharge());
    Assert.assertEquals("N", molecule.getAtom(1).getSymbol());
    Assert.assertEquals(Integer.valueOf(1), molecule.getAtom(1).getFormalCharge());

    // check bond stuff
    Assert.assertEquals(13, molecule.getBondCount());
    Assert.assertNotNull(molecule.getBond(3));

    // coordinates
    Assert.assertNull(molecule.getAtom(0).getPoint3d());
    Point2d point = molecule.getAtom(0).getPoint2d();
    Assert.assertNotNull(point);
    Assert.assertEquals(3.7320508956909, point.x, 0.00000001);
    Assert.assertEquals(0.5, point.y, 0.00000001);
  }
  @Test
  public void testBond5() throws Exception {
    String cmlString =
        "<molecule id='m1'><atomArray atomID='a1 a2 a3'/><bondArray atomRef1='a1 a1' atomRef2='a2 a3' order='1 1'/></molecule>";

    IChemFile chemFile = parseCMLString(cmlString);
    IMolecule mol = checkForSingleMoleculeFile(chemFile);

    Assert.assertEquals(3, mol.getAtomCount());
    Assert.assertEquals(2, mol.getBondCount());
    org.openscience.cdk.interfaces.IBond bond = mol.getBond(0);
    Assert.assertEquals(2, bond.getAtomCount());
    Assert.assertEquals(IBond.Order.SINGLE, bond.getOrder());
    bond = mol.getBond(1);
    Assert.assertEquals(2, bond.getAtomCount());
    Assert.assertEquals(IBond.Order.SINGLE, bond.getOrder());
  }
  @Test
  public void testBond4() throws Exception {
    String cmlString =
        "<molecule id='m1'><atomArray atomID='a1 a2 a3'/><bondArray atomRef1='a1 a1' atomRef2='a2 a3' bondID='b1 b2'/></molecule>";

    IChemFile chemFile = parseCMLString(cmlString);
    IMolecule mol = checkForSingleMoleculeFile(chemFile);

    Assert.assertEquals(3, mol.getAtomCount());
    Assert.assertEquals(2, mol.getBondCount());
    org.openscience.cdk.interfaces.IBond bond = mol.getBond(0);
    Assert.assertEquals(2, bond.getAtomCount());
    IAtom atom1 = bond.getAtom(0);
    IAtom atom2 = bond.getAtom(1);
    Assert.assertEquals("a1", atom1.getID());
    Assert.assertEquals("a2", atom2.getID());
    Assert.assertEquals("b2", mol.getBond(1).getID());
  }
  @Test
  public void testBondStereo() throws Exception {
    String cmlString =
        "<molecule id='m1'><atomArray><atom id='a1'/><atom id='a2'/></atomArray><bondArray><bond id='b1' atomRefs2='a1 a2'><bondStereo dictRef='cml:H'/></bond></bondArray></molecule>";
    IChemFile chemFile = parseCMLString(cmlString);
    IMolecule mol = checkForSingleMoleculeFile(chemFile);

    Assert.assertEquals(2, mol.getAtomCount());
    Assert.assertEquals(1, mol.getBondCount());
    IBond bond = mol.getBond(0);
    Assert.assertEquals(IBond.Stereo.DOWN, bond.getStereo());
  }
  /**
   * 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));
  }
  @Test
  public void testBondAromatic2() throws Exception {
    String cmlString =
        "<molecule id='m1'><atomArray atomID='a1 a2'/><bondArray><bond atomRefs='a1 a2' order='2'><bondType dictRef='cdk:aromaticBond'/></bond></bondArray></molecule>";
    IChemFile chemFile = parseCMLString(cmlString);
    IMolecule mol = checkForSingleMoleculeFile(chemFile);

    Assert.assertEquals(2, mol.getAtomCount());
    Assert.assertEquals(1, mol.getBondCount());
    org.openscience.cdk.interfaces.IBond bond = mol.getBond(0);
    Assert.assertEquals(CDKConstants.BONDORDER_DOUBLE, bond.getOrder());
    Assert.assertTrue(bond.getFlag(CDKConstants.ISAROMATIC));
  }
  @Test
  public void testBondId() throws Exception {
    String cmlString =
        "<molecule id='m1'><atomArray><atom id='a1'/><atom id='a2'/></atomArray><bondArray><bond id='b1' atomRefs2='a1 a2'/></bondArray></molecule>";

    IChemFile chemFile = parseCMLString(cmlString);
    IMolecule mol = checkForSingleMoleculeFile(chemFile);

    Assert.assertEquals(2, mol.getAtomCount());
    Assert.assertEquals(1, mol.getBondCount());
    org.openscience.cdk.interfaces.IBond bond = mol.getBond(0);
    Assert.assertEquals("b1", bond.getID());
  }
  /**
   * Choose any possible quadruple of the set of atoms in ac and establish all of the possible
   * bonding schemes according to Faulon's equations.
   */
  public static List sample(IMolecule ac) {
    logger.debug("RandomGenerator->mutate() Start");
    List structures = new ArrayList();

    int nrOfAtoms = ac.getAtomCount();
    double a11 = 0, a12 = 0, a22 = 0, a21 = 0;
    double b11 = 0, lowerborder = 0, upperborder = 0;
    double b12 = 0;
    double b21 = 0;
    double b22 = 0;
    double[] cmax = new double[4];
    double[] cmin = new double[4];
    IAtomContainer newAc = null;

    IAtom ax1 = null, ax2 = null, ay1 = null, ay2 = null;
    IBond b1 = null, b2 = null, b3 = null, b4 = null;
    // int[] choices = new int[3];
    /* We need at least two non-zero bonds in order to be successful */
    int nonZeroBondsCounter = 0;
    for (int x1 = 0; x1 < nrOfAtoms; x1++) {
      for (int x2 = x1 + 1; x2 < nrOfAtoms; x2++) {
        for (int y1 = x2 + 1; y1 < nrOfAtoms; y1++) {
          for (int y2 = y1 + 1; y2 < nrOfAtoms; y2++) {
            nonZeroBondsCounter = 0;
            ax1 = ac.getAtom(x1);
            ay1 = ac.getAtom(y1);
            ax2 = ac.getAtom(x2);
            ay2 = ac.getAtom(y2);

            /* Get four bonds for these four atoms */

            b1 = ac.getBond(ax1, ay1);
            if (b1 != null) {
              a11 = BondManipulator.destroyBondOrder(b1.getOrder());
              nonZeroBondsCounter++;
            } else {
              a11 = 0;
            }

            b2 = ac.getBond(ax1, ay2);
            if (b2 != null) {
              a12 = BondManipulator.destroyBondOrder(b2.getOrder());
              nonZeroBondsCounter++;
            } else {
              a12 = 0;
            }

            b3 = ac.getBond(ax2, ay1);
            if (b3 != null) {
              a21 = BondManipulator.destroyBondOrder(b3.getOrder());
              nonZeroBondsCounter++;
            } else {
              a21 = 0;
            }

            b4 = ac.getBond(ax2, ay2);
            if (b4 != null) {
              a22 = BondManipulator.destroyBondOrder(b4.getOrder());
              nonZeroBondsCounter++;
            } else {
              a22 = 0;
            }
            if (nonZeroBondsCounter > 1) {
              /* Compute the range for b11 (see Faulons formulae for details) */

              cmax[0] = 0;
              cmax[1] = a11 - a22;
              cmax[2] = a11 + a12 - 3;
              cmax[3] = a11 + a21 - 3;
              cmin[0] = 3;
              cmin[1] = a11 + a12;
              cmin[2] = a11 + a21;
              cmin[3] = a11 - a22 + 3;
              lowerborder = MathTools.max(cmax);
              upperborder = MathTools.min(cmin);
              for (b11 = lowerborder; b11 <= upperborder; b11++) {
                if (b11 != a11) {

                  b12 = a11 + a12 - b11;
                  b21 = a11 + a21 - b11;
                  b22 = a22 - a11 + b11;
                  logger.debug("Trying atom combination : " + x1 + ":" + x2 + ":" + y1 + ":" + y2);
                  try {
                    newAc = (IAtomContainer) ac.clone();
                    change(newAc, x1, y1, x2, y2, b11, b12, b21, b22);
                    if (ConnectivityChecker.isConnected(newAc)) {
                      structures.add(newAc);
                    } else {
                      logger.debug("not connected");
                    }
                  } catch (CloneNotSupportedException e) {
                    logger.error("Cloning exception: " + e.getMessage());
                    logger.debug(e);
                  }
                }
              }
            }
          }
        }
      }
    }
    return structures;
  }
  /**
   * Get the container which is found resonance from a IMolecule. It is based on looking if the
   * order of the bond changes.
   *
   * @param molecule The IMolecule to analyze
   * @return The different containers
   */
  @TestMethod("testGetContainers_IMolecule")
  public IAtomContainerSet getContainers(IMolecule molecule) {
    IAtomContainerSet setOfCont = molecule.getBuilder().newAtomContainerSet();
    IMoleculeSet setOfMol = getStructures(molecule);

    if (setOfMol.getMoleculeCount() == 0) return setOfCont;

    /*extraction of all bonds which has been produced a changes of order*/
    List<IBond> bondList = new ArrayList<IBond>();
    for (int i = 1; i < setOfMol.getMoleculeCount(); i++) {
      IMolecule mol = setOfMol.getMolecule(i);
      for (int j = 0; j < mol.getBondCount(); j++) {
        IBond bond = molecule.getBond(j);
        if (!mol.getBond(j).getOrder().equals(bond.getOrder())) {
          if (!bondList.contains(bond)) bondList.add(bond);
        }
      }
    }

    if (bondList.size() == 0) return null;

    int[] flagBelonging = new int[bondList.size()];
    for (int i = 0; i < flagBelonging.length; i++) flagBelonging[i] = 0;
    int[] position = new int[bondList.size()];
    int maxGroup = 1;

    /*Analysis if the bond are linked together*/
    List<IBond> newBondList = new ArrayList<IBond>();
    newBondList.add(bondList.get(0));

    int pos = 0;
    for (int i = 0; i < newBondList.size(); i++) {

      if (i == 0) flagBelonging[i] = maxGroup;
      else {
        if (flagBelonging[position[i]] == 0) {
          maxGroup++;
          flagBelonging[position[i]] = maxGroup;
        }
      }

      IBond bondA = newBondList.get(i);
      for (int ato = 0; ato < 2; ato++) {
        IAtom atomA1 = bondA.getAtom(ato);
        List<IBond> bondA1s = molecule.getConnectedBondsList(atomA1);
        for (int j = 0; j < bondA1s.size(); j++) {
          IBond bondB = bondA1s.get(j);
          if (!newBondList.contains(bondB))
            for (int k = 0; k < bondList.size(); k++)
              if (bondList.get(k).equals(bondB))
                if (flagBelonging[k] == 0) {
                  flagBelonging[k] = maxGroup;
                  pos++;
                  newBondList.add(bondB);
                  position[pos] = k;
                }
        }
      }
      // if it is final size and not all are added
      if (newBondList.size() - 1 == i)
        for (int k = 0; k < bondList.size(); k++)
          if (!newBondList.contains(bondList.get(k))) {
            newBondList.add(bondList.get(k));
            position[i + 1] = k;
            break;
          }
    }
    /*creating containers according groups*/
    for (int i = 0; i < maxGroup; i++) {
      IAtomContainer container = molecule.getBuilder().newAtomContainer();
      for (int j = 0; j < bondList.size(); j++) {
        if (flagBelonging[j] != i + 1) continue;
        IBond bond = bondList.get(j);
        IAtom atomA1 = bond.getAtom(0);
        IAtom atomA2 = bond.getAtom(1);
        if (!container.contains(atomA1)) container.addAtom(atomA1);
        if (!container.contains(atomA2)) container.addAtom(atomA2);
        container.addBond(bond);
      }
      setOfCont.addAtomContainer(container);
    }
    return setOfCont;
  }