コード例 #1
0
ファイル: SmilesGeneratorTest.java プロジェクト: jonalv/cdk
  /** 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
ファイル: HydrogenPlacer.java プロジェクト: slyrus/cdk
 /**
  * Place all hydrogens connected to atoms which have already been laid out.
  *
  * @param container atom container
  * @param bondLength bond length to user
  */
 @TestMethod("testBug933572,testH2")
 public void placeHydrogens2D(final IAtomContainer container, final double bondLength) {
   logger.debug("placing hydrogens on all atoms");
   for (IAtom atom : container.atoms()) {
     // only place hydrogens for atoms which have coordinates
     if (atom.getPoint2d() != null) {
       placeHydrogens2D(container, atom, bondLength);
     }
   }
   logger.debug("hydrogen placement complete");
 }
コード例 #3
0
ファイル: HydrogenPlacer.java プロジェクト: slyrus/cdk
 /**
  * Place hydrogens connected to the given atom using the average bond length in the container.
  *
  * @param container atom container of which <i>atom</i> is a member
  * @param atom the atom of which to place connected hydrogens
  * @throws IllegalArgumentException if the <i>atom</i> does not have 2d coordinates
  * @see #placeHydrogens2D(org.openscience.cdk.interfaces.IAtomContainer, double)
  */
 @TestMethod("testPlaceHydrogens2D")
 public void placeHydrogens2D(IAtomContainer container, IAtom atom) {
   double bondLength = GeometryTools.getBondLengthAverage(container);
   placeHydrogens2D(container, atom, bondLength);
 }
コード例 #4
0
ファイル: SmilesGeneratorTest.java プロジェクト: jonalv/cdk
  /** 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);
  }
コード例 #5
0
ファイル: SmilesGeneratorTest.java プロジェクト: jonalv/cdk
 /** 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);
 }
コード例 #6
0
ファイル: SmilesGeneratorTest.java プロジェクト: jonalv/cdk
 /** 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);
 }