示例#1
0
  /** A unit test for JUnit */
  @Test
  public void testAlanin() throws Exception {
    HydrogenPlacer hydrogenPlacer = new HydrogenPlacer();
    IAtomContainer mol1 = new AtomContainer();
    SmilesGenerator sg = new SmilesGenerator();
    mol1.addAtom(new Atom("N", new Point2d(1, 0)));
    // 1
    mol1.addAtom(new Atom("C", new Point2d(1, 2)));
    // 2
    mol1.addAtom(new Atom("F", new Point2d(1, 2)));
    // 3
    mol1.addAtom(new Atom("C", new Point2d(0, 0)));
    // 4
    mol1.addAtom(new Atom("C", new Point2d(1, 4)));
    // 5
    mol1.addAtom(new Atom("O", new Point2d(1, 5)));
    // 6
    mol1.addAtom(new Atom("O", new Point2d(1, 6)));
    // 7
    mol1.addBond(0, 1, IBond.Order.SINGLE);
    // 1
    mol1.addBond(1, 2, IBond.Order.SINGLE, IBond.Stereo.UP);
    // 2
    mol1.addBond(1, 3, IBond.Order.SINGLE, IBond.Stereo.DOWN);
    // 3
    mol1.addBond(1, 4, IBond.Order.SINGLE);
    // 4
    mol1.addBond(4, 5, IBond.Order.SINGLE);
    // 5
    mol1.addBond(4, 6, IBond.Order.DOUBLE);
    // 6
    addExplicitHydrogens(mol1);
    hydrogenPlacer.placeHydrogens2D(mol1, 1.0);
    IsotopeFactory ifac = IsotopeFactory.getInstance(mol1.getBuilder());
    ifac.configureAtoms(mol1);

    String smiles1 = null;
    if (standAlone) {
      display(mol1);
    }
    smiles1 = sg.createSMILES(mol1, true, new boolean[mol1.getBondCount()]);
    if (standAlone) {
      System.err.println("SMILES 1: " + smiles1);
    }
    Assert.assertNotNull(smiles1);
    Assert.assertEquals("[H]OC(=O)[C@](F)(N([H])[H])C([H])([H])[H]", smiles1);
    mol1.getBond(1).setStereo(IBond.Stereo.DOWN);
    mol1.getBond(2).setStereo(IBond.Stereo.UP);
    smiles1 = sg.createSMILES(mol1, true, new boolean[mol1.getBondCount()]);
    if (standAlone) {
      System.err.println("SMILES 1: " + smiles1);
    }
    Assert.assertNotNull(smiles1);
    Assert.assertEquals("[H]OC(=O)[C@](F)(C([H])([H])[H])N([H])[H]", smiles1);
  }
示例#2
0
  /**
   * Constructs an AtomContainer with a copy of the atoms and electronContainers of another
   * AtomContainer (A shallow copy, i.e., with the same objects as in the original AtomContainer).
   *
   * @param container An AtomContainer to copy the atoms and electronContainers from
   */
  public AtomContainer(IAtomContainer container) {
    this.atomCount = container.getAtomCount();
    this.bondCount = container.getBondCount();
    this.lonePairCount = container.getLonePairCount();
    this.singleElectronCount = container.getSingleElectronCount();
    this.atoms = new IAtom[this.atomCount];
    this.bonds = new IBond[this.bondCount];
    this.lonePairs = new ILonePair[this.lonePairCount];
    this.singleElectrons = new ISingleElectron[this.singleElectronCount];

    stereoElements = new HashSet<IStereoElement>(atomCount / 2);

    for (IStereoElement element : container.stereoElements()) {
      addStereoElement(element);
    }

    for (int f = 0; f < container.getAtomCount(); f++) {
      atoms[f] = container.getAtom(f);
      container.getAtom(f).addListener(this);
    }
    for (int f = 0; f < this.bondCount; f++) {
      bonds[f] = container.getBond(f);
      container.getBond(f).addListener(this);
    }
    for (int f = 0; f < this.lonePairCount; f++) {
      lonePairs[f] = container.getLonePair(f);
      container.getLonePair(f).addListener(this);
    }
    for (int f = 0; f < this.singleElectronCount; f++) {
      singleElectrons[f] = container.getSingleElectron(f);
      container.getSingleElectron(f).addListener(this);
    }
  }
示例#3
0
  /**
   * Adds all atoms and electronContainers of a given atomcontainer to this container.
   *
   * @param atomContainer The atomcontainer to be added
   */
  public void add(IAtomContainer atomContainer) {
    for (int f = 0; f < atomContainer.getAtomCount(); f++) {
      if (!contains(atomContainer.getAtom(f))) {
        addAtom(atomContainer.getAtom(f));
      }
    }
    for (int f = 0; f < atomContainer.getBondCount(); f++) {
      if (!contains(atomContainer.getBond(f))) {
        addBond(atomContainer.getBond(f));
      }
    }
    for (int f = 0; f < atomContainer.getLonePairCount(); f++) {
      if (!contains(atomContainer.getLonePair(f))) {
        addLonePair(atomContainer.getLonePair(f));
      }
    }
    for (int f = 0; f < atomContainer.getSingleElectronCount(); f++) {
      if (!contains(atomContainer.getSingleElectron(f))) {
        addSingleElectron(atomContainer.getSingleElectron(f));
      }
    }

    for (IStereoElement se : atomContainer.stereoElements()) stereoElements.add(se);

    notifyChanged();
  }
示例#4
0
  @Test
  public void testMakeAtomContainer() {

    IChemObjectBuilder builder = SilentChemObjectBuilder.getInstance();

    IAtom atom = builder.newInstance(IAtom.class, "C");
    IAtom exclude = builder.newInstance(IAtom.class, "C");

    IAtom a1 = builder.newInstance(IAtom.class, "C");
    IAtom a2 = builder.newInstance(IAtom.class, "C");

    IBond[] bonds =
        new IBond[] {
          builder.newInstance(IBond.class, atom, exclude),
          builder.newInstance(IBond.class, a1, a2),
          builder.newInstance(IBond.class, a1, atom),
          builder.newInstance(IBond.class, a2, exclude)
        };

    IAtomContainer part = FragmentUtils.makeAtomContainer(atom, Arrays.asList(bonds), exclude);

    assertThat(part.getAtomCount(), is(3));
    assertThat(part.getBondCount(), is(2));

    Assert.assertTrue(part.contains(atom));
    Assert.assertTrue(part.contains(a1));
    Assert.assertTrue(part.contains(a2));
    Assert.assertFalse(part.contains(exclude));

    Assert.assertTrue(part.contains(bonds[1]));
    Assert.assertTrue(part.contains(bonds[2]));
  }
示例#5
0
  private boolean unMappedAtomsEqualsIndexJ(
      IAtomContainer target,
      int mappingSize,
      int atomIndex,
      int counter,
      List<Integer> mapped_atoms,
      Integer indexI,
      Integer indexJ,
      Integer order) {
    boolean normal_bond = true;
    for (int c = 0; c < mappingSize; c++) {
      if (mapped_atoms.get(c * 2 + 1).equals(indexI)) {
        setBondNeighbors(indexI, indexJ, order);
        if (cTab2Copy.get(atomIndex * 4 + 2).compareToIgnoreCase("X") == 0) {
          step3(atomIndex, counter);
          McGregorChecks.changeCharBonds(
              indexI, signArray[counter], target.getBondCount(), target, cTab2Copy);
          int cor_atom =
              McGregorChecks.searchCorrespondingAtom(mappingSize, indexI, 2, mapped_atoms);
          McGregorChecks.changeCharBonds(
              cor_atom, signArray[counter], newNeighborNumA, newINeighborsA, newCNeighborsA);
          //                                changeCharBonds(cor_atom, signArray[counter],
          // query.getBondCount(), query, cTab1Copy);
          counter++;
        } else {
          step4(atomIndex);
        }
        normal_bond = false;
        neighborBondNumB++;
      }
    }

    return normal_bond;
  }
示例#6
0
 /**
  * Helper method, used to help construct a configuration.
  *
  * @param bond
  * @param container
  * @return the array position of the bond in the container
  */
 private int getBondPosition(IBond bond, IAtomContainer container) {
   for (int i = 0; i < container.getBondCount(); i++) {
     if (bond.equals(container.getBond(i))) {
       return i;
     }
   }
   return -1;
 }
示例#7
0
 /**
  * Creates a bucky ball molecule.
  *
  * @return bucky ball molecule
  */
 private IAtomContainer createBuckyBall() throws CDKException {
   IAtomContainer molecule = null;
   String filename = "data/mdl/buckyball.mol";
   InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename);
   MDLV2000Reader reader = new MDLV2000Reader(ins, Mode.STRICT);
   molecule = (IAtomContainer) reader.read(new AtomContainer());
   Assert.assertTrue("Atom count is 60 ", molecule.getAtomCount() == 60);
   Assert.assertTrue("Bond count is 90 ", molecule.getBondCount() == 90);
   return molecule;
 }
 public static void checkAverageBondLength(IAtomContainer ac) {
   double avlength = GeometryTools.getBondLengthAverage3D(ac);
   for (int i = 0; i < ac.getBondCount(); i++) {
     double distance =
         ac.getBond(i).getAtom(0).getPoint3d().distance(ac.getBond(i).getAtom(1).getPoint3d());
     Assert.assertTrue(
         "Unreasonable bond length (" + distance + ") for bond " + i,
         distance >= avlength / 2 && distance <= avlength * 2);
   }
 }
示例#9
0
 /**
  * Removes all atoms and electronContainers of a given atomcontainer from this container.
  *
  * @param atomContainer The atomcontainer to be removed
  */
 public void remove(IAtomContainer atomContainer) {
   for (int f = 0; f < atomContainer.getAtomCount(); f++) {
     removeAtom(atomContainer.getAtom(f));
   }
   for (int f = 0; f < atomContainer.getBondCount(); f++) {
     removeBond(atomContainer.getBond(f));
   }
   for (int f = 0; f < atomContainer.getLonePairCount(); f++) {
     removeLonePair(atomContainer.getLonePair(f));
   }
   for (int f = 0; f < atomContainer.getSingleElectronCount(); f++) {
     removeSingleElectron(atomContainer.getSingleElectron(f));
   }
 }
示例#10
0
 /**
  * Prepare a collection of molecules for rendering. If coordinates are not present they are
  * generated, if coordinates exists they are scaled to be consistent (length=1.5).
  *
  * @param mols molecules
  * @return coordinates
  * @throws CDKException
  */
 private List<Double> prepareCoords(Iterable<IAtomContainer> mols) throws CDKException {
   List<Double> scaleFactors = new ArrayList<>();
   for (IAtomContainer mol : mols) {
     if (ensure2dLayout(mol)) {
       scaleFactors.add(Double.NaN);
     } else if (mol.getBondCount() > 0) {
       final double factor = GeometryUtil.getScaleFactor(mol, 1.5);
       GeometryUtil.scaleMolecule(mol, factor);
       scaleFactors.add(factor);
     } else {
       scaleFactors.add(1d); // no bonds
     }
   }
   return scaleFactors;
 }
示例#11
0
 private synchronized IQuery build(IAtomContainer queryMolecule) {
   VFQueryBuilder result = new VFQueryBuilder();
   for (IAtom atom : queryMolecule.atoms()) {
     AtomMatcher matcher = createAtomMatcher(queryMolecule, atom);
     if (matcher != null) {
       result.addNode(matcher, atom);
     }
   }
   for (int i = 0; i < queryMolecule.getBondCount(); i++) {
     IBond bond = queryMolecule.getBond(i);
     IAtom atomI = bond.getAtom(0);
     IAtom atomJ = bond.getAtom(1);
     result.connect(
         result.getNode(atomI), result.getNode(atomJ), createBondMatcher(queryMolecule, bond));
   }
   return result;
 }
示例#12
0
  public String getSMILES(IAtomContainer molecule) throws CDKException {

    String smiles = "";
    if (molecule.getAtomCount() == 0) {
      return smiles;
    }

    SmilesGenerator sg = new SmilesGenerator(true);
    AllRingsFinder arf = new AllRingsFinder();

    IRingSet findAllRings = arf.findAllRings(molecule);
    sg.setRings(findAllRings);

    sg.setRingFinder(arf);
    smiles = sg.createSMILES(molecule, false, new boolean[molecule.getBondCount()]);
    return smiles;
  }
示例#13
0
  @Test(timeout = 1000)
  public void testPyrrole_Silent() throws Exception {
    String smiles = "c2ccc3n([H])c1ccccc1c3(c2)";
    SmilesParser smilesParser = new SmilesParser(SilentChemObjectBuilder.getInstance());
    IAtomContainer molecule = smilesParser.parseSmiles(smiles);

    molecule = fbot.kekuliseAromaticRings(molecule);
    Assert.assertNotNull(molecule);

    molecule = (IAtomContainer) AtomContainerManipulator.removeHydrogens(molecule);
    int doubleBondCount = 0;
    for (int i = 0; i < molecule.getBondCount(); i++) {
      IBond bond = molecule.getBond(i);
      Assert.assertTrue(bond.getFlag(CDKConstants.ISAROMATIC));
      if (bond.getOrder() == Order.DOUBLE) doubleBondCount++;
    }
    Assert.assertEquals(6, doubleBondCount);
  }
示例#14
0
  protected void process(
      IAtomContainer target,
      List<Integer> unmapped_atoms_molB,
      int mappingSize,
      List<Integer> i_bond_setB,
      List<String> c_bond_setB,
      List<Integer> mapped_atoms,
      int counter) {

    int unmapped_numB = unmapped_atoms_molB.size();
    boolean bond_considered = false;
    boolean normal_bond = true;

    for (int atomIndex = 0; atomIndex < target.getBondCount(); atomIndex++) {

      Integer indexI = target.getAtomNumber(target.getBond(atomIndex).getAtom(0));
      Integer indexJ = target.getAtomNumber(target.getBond(atomIndex).getAtom(1));
      IBond bond = target.getBond(atomIndex);
      Integer order = (bond.getOrder().ordinal() + 1);

      for (int b = 0; b < unmapped_numB; b++) {
        if (unmapped_atoms_molB.get(b).equals(indexI)) {
          normal_bond =
              unMappedAtomsEqualsIndexI(
                  target, mappingSize, atomIndex, counter, mapped_atoms, indexI, indexJ, order);
          bond_considered = true;
        } else if (unmapped_atoms_molB.get(b) == indexJ) {
          normal_bond =
              unMappedAtomsEqualsIndexJ(
                  target, mappingSize, atomIndex, counter, mapped_atoms, indexI, indexJ, order);
          bond_considered = true;
        }

        if (normal_bond && bond_considered) {
          markNormalBonds(atomIndex, i_bond_setB, c_bond_setB, indexI, indexJ, order);
          normal_bond = true;
          break;
        }
      }
      bond_considered = false;
    }
  }
示例#15
0
  @Test
  public void testLargeRingSystem() throws Exception {
    String smiles = "O=C1Oc6ccccc6(C(O)C1C5c2ccccc2CC(c3ccc(cc3)c4ccccc4)C5)";
    SmilesParser smilesParser = new SmilesParser(DefaultChemObjectBuilder.getInstance());
    IAtomContainer molecule = smilesParser.parseSmiles(smiles);

    molecule = fbot.kekuliseAromaticRings(molecule);
    Assert.assertNotNull(molecule);

    molecule = (IAtomContainer) AtomContainerManipulator.removeHydrogens(molecule);
    Assert.assertEquals(34, molecule.getAtomCount());

    // we should have 14 double bonds
    int doubleBondCount = 0;
    for (int i = 0; i < molecule.getBondCount(); i++) {
      IBond bond = molecule.getBond(i);
      if (bond.getOrder() == Order.DOUBLE) doubleBondCount++;
    }
    Assert.assertEquals(13, doubleBondCount);
  }
示例#16
0
  /** @cdk.bug 3506770 */
  @Test
  public void testLargeBioclipseUseCase() throws Exception {
    String smiles =
        "COc1ccc2[C@@H]3[C@H](COc2c1)C(C)(C)OC4=C3C(=O)C(=O)C5=C4OC(C)(C)[C@@H]6COc7cc(OC)ccc7[C@H]56";
    SmilesParser smilesParser = new SmilesParser(DefaultChemObjectBuilder.getInstance());
    IAtomContainer molecule = smilesParser.parseSmiles(smiles);

    molecule = fbot.kekuliseAromaticRings(molecule);
    Assert.assertNotNull(molecule);

    molecule = (IAtomContainer) AtomContainerManipulator.removeHydrogens(molecule);
    Assert.assertEquals(40, molecule.getAtomCount());

    // we should have 14 double bonds
    int doubleBondCount = 0;
    for (int i = 0; i < molecule.getBondCount(); i++) {
      IBond bond = molecule.getBond(i);
      if (bond.getOrder() == Order.DOUBLE) doubleBondCount++;
    }
    Assert.assertEquals(10, doubleBondCount);
  }
示例#17
0
 @Test
 public void testSplit() throws CDKException {
   IAtomContainer mol = smilesParser.parseSmiles("C1CC1C2CCC2");
   SpanningTree st = new SpanningTree(mol);
   IRingSet rings = st.getAllRings();
   IBond splitBond = null;
   for (int i = 0; i < mol.getBondCount(); i++) {
     if (rings.getRings(mol.getBond(i)).getAtomContainerCount() == 0) {
       splitBond = mol.getBond(i);
       break;
     }
   }
   List<IAtomContainer> frags = FragmentUtils.splitMolecule(mol, splitBond);
   SmilesGenerator sg = new SmilesGenerator();
   Set<String> uniqueFrags = new HashSet<String>();
   for (IAtomContainer frag : frags) {
     uniqueFrags.add(sg.createSMILES(frag));
   }
   Assert.assertEquals(2, uniqueFrags.size());
   // You can put the fragments back together with a ring closure and dot
   // [CH]12CC1.[CH]12CCC1
   Assert.assertThat(uniqueFrags, hasItems("[CH]1CC1", "[CH]1CCC1"));
 }
示例#18
0
 /** A unit test for JUnit */
 @Test
 public void testCisResorcinol() throws Exception {
   HydrogenPlacer hydrogenPlacer = new HydrogenPlacer();
   IAtomContainer mol1 = new AtomContainer();
   SmilesGenerator sg = new SmilesGenerator();
   mol1.addAtom(new Atom("O", new Point2d(3, 1)));
   // 1
   mol1.addAtom(new Atom("H", new Point2d(2, 0)));
   // 2
   mol1.addAtom(new Atom("C", new Point2d(2, 1)));
   // 3
   mol1.addAtom(new Atom("C", new Point2d(1, 1)));
   // 4
   mol1.addAtom(new Atom("C", new Point2d(1, 4)));
   // 5
   mol1.addAtom(new Atom("C", new Point2d(1, 5)));
   // 6
   mol1.addAtom(new Atom("C", new Point2d(1, 2)));
   // 7
   mol1.addAtom(new Atom("C", new Point2d(2, 2)));
   // 1
   mol1.addAtom(new Atom("O", new Point2d(3, 2)));
   // 2
   mol1.addAtom(new Atom("H", new Point2d(2, 3)));
   // 3
   mol1.addBond(0, 2, IBond.Order.SINGLE, IBond.Stereo.DOWN);
   // 1
   mol1.addBond(1, 2, IBond.Order.SINGLE, IBond.Stereo.UP);
   // 2
   mol1.addBond(2, 3, IBond.Order.SINGLE);
   // 3
   mol1.addBond(3, 4, IBond.Order.SINGLE);
   // 4
   mol1.addBond(4, 5, IBond.Order.SINGLE);
   // 5
   mol1.addBond(5, 6, IBond.Order.SINGLE);
   // 6
   mol1.addBond(6, 7, IBond.Order.SINGLE);
   // 3
   mol1.addBond(7, 8, IBond.Order.SINGLE, IBond.Stereo.UP);
   // 4
   mol1.addBond(7, 9, IBond.Order.SINGLE, IBond.Stereo.DOWN);
   // 5
   mol1.addBond(7, 2, IBond.Order.SINGLE);
   // 6
   try {
     addExplicitHydrogens(mol1);
     hydrogenPlacer.placeHydrogens2D(mol1, 1.0);
     IsotopeFactory ifac = IsotopeFactory.getInstance(mol1.getBuilder());
     ifac.configureAtoms(mol1);
   } catch (IOException ex) {
   } catch (ClassNotFoundException ex) {
   }
   String smiles1 = null;
   if (standAlone) {
     display(mol1);
   }
   try {
     smiles1 = sg.createSMILES(mol1, true, new boolean[mol1.getBondCount()]);
   } catch (Exception exc) {
     System.out.println(exc);
     if (!standAlone) {
       Assert.fail();
     }
   }
   if (standAlone) {
     System.err.println("SMILES 1: " + smiles1);
   }
   Assert.assertNotNull(smiles1);
   Assert.assertEquals(
       "[H]O[C@]1(C([H])([H])C([H])([H])C([H])([H])C([H])([H])[C@]1(O[H])([H]))([H])", smiles1);
   mol1 = AtomContainerManipulator.removeHydrogens(mol1);
   try {
     smiles1 = sg.createSMILES(mol1);
   } catch (Exception exc) {
     System.out.println(exc);
     if (!standAlone) {
       Assert.fail();
     }
   }
   if (standAlone) {
     System.err.println("SMILES 1: " + smiles1);
   }
   Assert.assertNotNull(smiles1);
   Assert.assertEquals("OC1CCCCC1(O)", smiles1);
 }
示例#19
0
 /** A unit test for JUnit */
 @Test
 public void testCisTransDecalin() throws Exception {
   HydrogenPlacer hydrogenPlacer = new HydrogenPlacer();
   IAtomContainer mol1 = new AtomContainer();
   SmilesGenerator sg = new SmilesGenerator();
   mol1.addAtom(new Atom("H", new Point2d(1, 0)));
   // 1
   mol1.addAtom(new Atom("C", new Point2d(1, 2)));
   // 2
   mol1.addAtom(new Atom("C", new Point2d(1, 2)));
   // 3
   mol1.addAtom(new Atom("C", new Point2d(0, 0)));
   // 4
   mol1.addAtom(new Atom("C", new Point2d(1, 4)));
   // 5
   mol1.addAtom(new Atom("C", new Point2d(1, 5)));
   // 6
   mol1.addAtom(new Atom("C", new Point2d(1, 6)));
   // 7
   mol1.addAtom(new Atom("H", new Point2d(1, 0)));
   // 1
   mol1.addAtom(new Atom("C", new Point2d(1, 2)));
   // 2
   mol1.addAtom(new Atom("C", new Point2d(1, 2)));
   // 3
   mol1.addAtom(new Atom("C", new Point2d(1, 2)));
   // 2
   mol1.addAtom(new Atom("C", new Point2d(1, 2)));
   // 3
   mol1.addBond(0, 1, IBond.Order.SINGLE, IBond.Stereo.DOWN);
   // 1
   mol1.addBond(1, 2, IBond.Order.SINGLE);
   // 2
   mol1.addBond(2, 3, IBond.Order.SINGLE);
   // 3
   mol1.addBond(3, 4, IBond.Order.SINGLE);
   // 4
   mol1.addBond(4, 5, IBond.Order.SINGLE);
   // 5
   mol1.addBond(5, 6, IBond.Order.SINGLE);
   // 6
   mol1.addBond(6, 7, IBond.Order.SINGLE, IBond.Stereo.DOWN);
   // 3
   mol1.addBond(6, 8, IBond.Order.SINGLE);
   // 4
   mol1.addBond(8, 9, IBond.Order.SINGLE);
   // 5
   mol1.addBond(9, 10, IBond.Order.SINGLE);
   // 6
   mol1.addBond(10, 11, IBond.Order.SINGLE);
   // 6
   mol1.addBond(11, 1, IBond.Order.SINGLE);
   // 6
   mol1.addBond(1, 6, IBond.Order.SINGLE);
   // 6
   try {
     addExplicitHydrogens(mol1);
     hydrogenPlacer.placeHydrogens2D(mol1, 1.0);
     IsotopeFactory ifac = IsotopeFactory.getInstance(mol1.getBuilder());
     ifac.configureAtoms(mol1);
   } catch (IOException ex) {
   } catch (ClassNotFoundException ex) {
   }
   String smiles1 = null;
   if (standAlone) {
     display(mol1);
   }
   try {
     smiles1 = sg.createSMILES(mol1, true, new boolean[mol1.getBondCount()]);
   } catch (Exception exc) {
     System.out.println(exc);
     if (!standAlone) {
       Assert.fail();
     }
   }
   if (standAlone) {
     System.err.println("SMILES 1: " + smiles1);
   }
   Assert.assertNotNull(smiles1);
   Assert.assertEquals(
       "[H]C1([H])(C([H])([H])C([H])([H])C\\2([H])(C([H])([H])C([H])([H])C([H])([H])C([H])([H])C\\2([H])(C1([H])([H]))))",
       smiles1);
   mol1.getBond(6).setStereo(IBond.Stereo.UP);
   String smiles3 = null;
   try {
     smiles3 = sg.createSMILES(mol1, true, new boolean[mol1.getBondCount()]);
   } catch (Exception exc) {
     System.out.println(exc);
     if (!standAlone) {
       Assert.fail();
     }
   }
   Assert.assertNotSame(smiles3, smiles1);
 }
示例#20
0
  /** A unit test for JUnit */
  @Test
  public void testDoubleBondConfiguration() throws Exception {
    HydrogenPlacer hydrogenPlacer = new HydrogenPlacer();
    IAtomContainer mol1 = new AtomContainer();
    SmilesGenerator sg = new SmilesGenerator();
    mol1.addAtom(new Atom("S", new Point2d(0, 0)));
    // 1
    mol1.addAtom(new Atom("C", new Point2d(1, 1)));
    // 2
    mol1.addAtom(new Atom("F", new Point2d(2, 0)));
    // 3
    mol1.addAtom(new Atom("C", new Point2d(1, 2)));
    // 4
    mol1.addAtom(new Atom("F", new Point2d(2, 3)));
    // 5
    mol1.addAtom(new Atom("S", new Point2d(0, 3)));
    // 1

    mol1.addBond(0, 1, IBond.Order.SINGLE);
    // 1
    mol1.addBond(1, 2, IBond.Order.SINGLE);
    // 2
    mol1.addBond(1, 3, IBond.Order.DOUBLE);
    // 3
    mol1.addBond(3, 4, IBond.Order.SINGLE);
    // 4
    mol1.addBond(3, 5, IBond.Order.SINGLE);
    // 4
    try {
      IsotopeFactory ifac = IsotopeFactory.getInstance(mol1.getBuilder());
      ifac.configureAtoms(mol1);
    } catch (IOException ex) {
    }
    String smiles1 = null;
    if (standAlone) {
      display(mol1);
    }
    boolean[] bool = new boolean[mol1.getBondCount()];
    bool[2] = true;
    try {
      smiles1 = sg.createSMILES(mol1, true, bool);
    } catch (Exception exc) {
      System.out.println(exc);
      if (!standAlone) {
        Assert.fail();
      }
    }
    if (standAlone) {
      System.err.println("SMILES 1: " + smiles1);
    }
    Assert.assertNotNull(smiles1);
    Assert.assertEquals("F/C(=C/(F)S)S", smiles1);
    mol1.getAtom(4).setPoint2d(new Point2d(0, 3));
    mol1.getAtom(5).setPoint2d(new Point2d(2, 3));
    try {
      smiles1 = sg.createSMILES(mol1, true, bool);
    } catch (Exception exc) {
      System.out.println(exc);
      if (!standAlone) {
        Assert.fail();
      }
    }
    if (standAlone) {
      System.err.println("SMILES 1: " + smiles1);
    }
    Assert.assertNotNull(smiles1);
    Assert.assertEquals("F/C(=C\\(F)S)S", smiles1);
    try {
      addExplicitHydrogens(mol1);
      hydrogenPlacer.placeHydrogens2D(mol1, 1.0);
    } catch (IOException ex) {
    } catch (ClassNotFoundException ex) {
    }
    bool = new boolean[mol1.getBondCount()];
    bool[2] = true;
    try {
      smiles1 = sg.createSMILES(mol1, true, bool);
    } catch (Exception exc) {
      System.out.println(exc);
      if (!standAlone) {
        Assert.fail();
      }
    }
    Assert.assertEquals("[H]S/C(F)=C/(F)S[H]", smiles1);
    mol1.getAtom(5).setPoint2d(new Point2d(0, 3));
    mol1.getAtom(4).setPoint2d(new Point2d(2, 3));
    try {
      smiles1 = sg.createSMILES(mol1, true, bool);
    } catch (Exception exc) {
      System.out.println(exc);
      if (!standAlone) {
        Assert.fail();
      }
    }
    Assert.assertEquals("[H]S/C(F)=C\\(F)S[H]", smiles1);
  }