/**
   * Test for SF bug #1309731.
   *
   * @cdk.bug 1309731
   */
  @Test
  public void testModelBuilder3D_keepChemObjectIDs() throws Exception {
    ModelBuilder3D mb3d = ModelBuilder3D.getInstance();

    IMolecule methanol = new org.openscience.cdk.Molecule();
    IChemObjectBuilder builder = methanol.getBuilder();

    IAtom carbon1 = builder.newInstance(IAtom.class, "C");
    carbon1.setID("carbon1");
    methanol.addAtom(carbon1);
    for (int i = 0; i < 3; i++) {
      IAtom hydrogen = builder.newInstance(IAtom.class, "H");
      methanol.addAtom(hydrogen);
      methanol.addBond(builder.newInstance(IBond.class, carbon1, hydrogen, IBond.Order.SINGLE));
    }
    IAtom oxygen1 = builder.newInstance(IAtom.class, "O");
    oxygen1.setID("oxygen1");
    methanol.addAtom(oxygen1);
    methanol.addBond(builder.newInstance(IBond.class, carbon1, oxygen1, IBond.Order.SINGLE));
    IAtom hydrogen = builder.newInstance(IAtom.class, "H");
    methanol.addAtom(hydrogen);
    methanol.addBond(builder.newInstance(IBond.class, hydrogen, oxygen1, IBond.Order.SINGLE));

    Assert.assertEquals(6, methanol.getAtomCount());
    Assert.assertEquals(5, methanol.getBondCount());

    mb3d.generate3DCoordinates(methanol, false);

    checkAverageBondLength(methanol);
    Assert.assertEquals("carbon1", carbon1.getID());
    Assert.assertEquals("oxygen1", oxygen1.getID());
  }
  /** A unit test for JUnit with ethoxyethane */
  @Test
  public void testPartialTotalChargeDescriptor_Ethoxyethane()
      throws ClassNotFoundException, CDKException, java.lang.Exception {
    double[] testResult = {
      0.28, -0.56, 0.28,
    }; /* from Merck Molecular Force Field. II. Thomas A. Halgren*/
    IAtomicDescriptor descriptor = new PartialTChargeMMFF94Descriptor();

    //		IMolecule mol = sp.parseSmiles("COC");
    IMolecule mol = builder.newInstance(IMolecule.class);
    IAtom carbon = builder.newInstance(IAtom.class, Elements.CARBON);
    IAtom oxygen = builder.newInstance(IAtom.class, Elements.OXYGEN);
    IAtom carbon2 = builder.newInstance(IAtom.class, Elements.CARBON);
    // making sure the order matches the test results
    mol.addAtom(carbon);
    mol.addAtom(oxygen);
    mol.addAtom(carbon2);
    mol.addBond(builder.newInstance(IBond.class, carbon, oxygen, CDKConstants.BONDORDER_SINGLE));
    mol.addBond(builder.newInstance(IBond.class, carbon2, oxygen, CDKConstants.BONDORDER_SINGLE));
    addExplicitHydrogens(mol);

    for (int i = 0; i < 3; i++) {
      double result =
          ((DoubleResult) descriptor.calculate(mol.getAtom(i), mol).getValue()).doubleValue();
      Assert.assertEquals(testResult[i], result, METHOD_ERROR);
    }
  }
  /**
   * Get the Ethene structure.
   *
   * @return The IMolecule
   * @throws CDKException
   */
  private IMolecule getEthene() throws Exception {
    IMolecule molecule = builder.newMolecule();
    molecule.addAtom(builder.newAtom("C"));
    molecule.addAtom(builder.newAtom("C"));
    molecule.addBond(0, 1, IBond.Order.DOUBLE);
    molecule.addAtom(builder.newAtom("H"));
    molecule.addAtom(builder.newAtom("H"));
    molecule.addAtom(builder.newAtom("H"));
    molecule.addAtom(builder.newAtom("H"));
    molecule.addBond(0, 2, IBond.Order.SINGLE);
    molecule.addBond(0, 3, IBond.Order.SINGLE);
    molecule.addBond(1, 4, IBond.Order.SINGLE);
    molecule.addBond(1, 5, IBond.Order.SINGLE);
    AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(molecule);

    LonePairElectronChecker lpcheck = new LonePairElectronChecker();
    lpcheck.saturate(molecule);
    return molecule;
  }
  /** A unit test for JUnit with Benzene */
  @Test
  public void testPartialTotalChargeDescriptor_Benzene()
      throws ClassNotFoundException, CDKException, java.lang.Exception {
    double[] testResult = {
      -0.15, -0.15, -0.15, -0.15, -0.15, -0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15
    }; /* from Merck Molecular Force Field. II. Thomas A. Halgren*/
    IAtomicDescriptor descriptor = new PartialTChargeMMFF94Descriptor();

    //		IMolecule mol = sp.parseSmiles("c1ccccc1");
    IMolecule mol = builder.newInstance(IMolecule.class);
    for (int i = 0; i < 6; i++) {
      IAtom carbon = builder.newInstance(IAtom.class, Elements.CARBON);
      carbon.setFlag(CDKConstants.ISAROMATIC, true);
      // making sure the order matches the test results
      mol.addAtom(carbon);
    }
    IBond ringBond =
        builder.newInstance(
            IBond.class, mol.getAtom(0), mol.getAtom(1), CDKConstants.BONDORDER_DOUBLE);
    ringBond.setFlag(CDKConstants.ISAROMATIC, true);
    mol.addBond(ringBond);
    ringBond =
        builder.newInstance(
            IBond.class, mol.getAtom(1), mol.getAtom(2), CDKConstants.BONDORDER_SINGLE);
    ringBond.setFlag(CDKConstants.ISAROMATIC, true);
    mol.addBond(ringBond);
    ringBond =
        builder.newInstance(
            IBond.class, mol.getAtom(2), mol.getAtom(3), CDKConstants.BONDORDER_DOUBLE);
    ringBond.setFlag(CDKConstants.ISAROMATIC, true);
    mol.addBond(ringBond);
    ringBond =
        builder.newInstance(
            IBond.class, mol.getAtom(3), mol.getAtom(4), CDKConstants.BONDORDER_SINGLE);
    ringBond.setFlag(CDKConstants.ISAROMATIC, true);
    mol.addBond(ringBond);
    ringBond =
        builder.newInstance(
            IBond.class, mol.getAtom(4), mol.getAtom(5), CDKConstants.BONDORDER_DOUBLE);
    ringBond.setFlag(CDKConstants.ISAROMATIC, true);
    mol.addBond(ringBond);
    ringBond =
        builder.newInstance(
            IBond.class, mol.getAtom(5), mol.getAtom(0), CDKConstants.BONDORDER_SINGLE);
    ringBond.setFlag(CDKConstants.ISAROMATIC, true);
    mol.addBond(ringBond);
    addExplicitHydrogens(mol);

    for (int i = 0; i < 12; i++) {
      double result =
          ((DoubleResult) descriptor.calculate(mol.getAtom(i), mol).getValue()).doubleValue();
      Assert.assertEquals(testResult[i], result, METHOD_ERROR);
    }
  }
  /** A unit test for JUnit with Water */
  @Test
  public void testPartialTotalChargeDescriptor_Water()
      throws ClassNotFoundException, CDKException, java.lang.Exception {
    double[] testResult = {
      -0.86, 0.43, 0.43
    }; /* from Merck Molecular Force Field. II. Thomas A. Halgren*/
    IAtomicDescriptor descriptor = new PartialTChargeMMFF94Descriptor();

    IMolecule mol = builder.newInstance(IMolecule.class);
    IAtom oxygen = builder.newInstance(IAtom.class, Elements.OXYGEN);
    // making sure the order matches the test results
    mol.addAtom(oxygen);
    addExplicitHydrogens(mol);

    for (int i = 0; i < 3; i++) {
      double result =
          ((DoubleResult) descriptor.calculate(mol.getAtom(i), mol).getValue()).doubleValue();
      Assert.assertEquals(testResult[i], result, METHOD_ERROR);
    }
  }