示例#1
0
  @Test
  public void methyleneCyclopropeneTest() {
    IAtomContainer mol = builder.newInstance(IAtomContainer.class);
    AbstractSignatureTest.addCarbons(mol, 4);
    AbstractSignatureTest.addHydrogens(mol, 1, 2);
    AbstractSignatureTest.addHydrogens(mol, 2, 1);
    AbstractSignatureTest.addHydrogens(mol, 3, 1);
    mol.addBond(0, 1, IBond.Order.DOUBLE);
    mol.addBond(0, 2, IBond.Order.SINGLE);
    mol.addBond(0, 3, IBond.Order.SINGLE);
    mol.addBond(2, 3, IBond.Order.DOUBLE);
    MoleculeSignature molSig = new MoleculeSignature(mol);

    String sigFor2Height1 = molSig.signatureStringForVertex(2, 1);
    String sigFor3Height1 = molSig.signatureStringForVertex(3, 1);
    Assert.assertTrue(
        "Height 1 signatures for atoms 2 and 3" + " should be the same",
        sigFor2Height1.equals(sigFor3Height1));

    String sigFor2Height2 = molSig.signatureStringForVertex(2, 1);
    String sigFor3Height2 = molSig.signatureStringForVertex(3, 1);
    Assert.assertTrue(
        "Height 2 signatures for atoms 2 and 3" + " should be the same",
        sigFor2Height2.equals(sigFor3Height2));
  }
示例#2
0
 /** A unit test for JUnit */
 @Test
 public void testBug791091() {
   String smiles = "";
   IAtomContainer molecule = new AtomContainer();
   SmilesGenerator sg = new SmilesGenerator();
   molecule.addAtom(new Atom("C"));
   molecule.addAtom(new Atom("C"));
   molecule.addAtom(new Atom("C"));
   molecule.addAtom(new Atom("C"));
   molecule.addAtom(new Atom("N"));
   molecule.addBond(0, 1, IBond.Order.SINGLE);
   molecule.addBond(1, 2, IBond.Order.SINGLE);
   molecule.addBond(2, 4, IBond.Order.SINGLE);
   molecule.addBond(4, 0, IBond.Order.SINGLE);
   molecule.addBond(4, 3, IBond.Order.SINGLE);
   fixCarbonHCount(molecule);
   try {
     smiles = sg.createSMILES(molecule);
   } catch (Exception exc) {
     System.out.println(exc);
     if (!standAlone) {
       Assert.fail();
     }
   }
   if (standAlone) {
     System.err.println("SMILES: " + smiles);
   }
   Assert.assertEquals("N1(C)CCC1", smiles);
 }
示例#3
0
 /** A bug reported for JChemPaint. */
 @Test
 public void testSFBug956923() throws Exception {
   String smiles = "";
   IAtomContainer molecule = new AtomContainer();
   SmilesGenerator sg = new SmilesGenerator();
   Atom sp2CarbonWithOneHydrogen = new Atom("C");
   sp2CarbonWithOneHydrogen.setHybridization(Hybridization.SP2);
   sp2CarbonWithOneHydrogen.setImplicitHydrogenCount(1);
   molecule.addAtom(sp2CarbonWithOneHydrogen);
   molecule.addAtom((Atom) sp2CarbonWithOneHydrogen.clone());
   molecule.addAtom((Atom) sp2CarbonWithOneHydrogen.clone());
   molecule.addAtom((Atom) sp2CarbonWithOneHydrogen.clone());
   molecule.addAtom((Atom) sp2CarbonWithOneHydrogen.clone());
   molecule.addAtom((Atom) sp2CarbonWithOneHydrogen.clone());
   molecule.addBond(0, 1, IBond.Order.SINGLE);
   molecule.addBond(1, 2, IBond.Order.SINGLE);
   molecule.addBond(2, 3, IBond.Order.SINGLE);
   molecule.addBond(3, 4, IBond.Order.SINGLE);
   molecule.addBond(4, 5, IBond.Order.SINGLE);
   molecule.addBond(5, 0, IBond.Order.SINGLE);
   try {
     smiles = sg.createSMILES(molecule);
   } catch (Exception exc) {
     Assert.fail(exc.getMessage());
   }
   Assert.assertEquals("c1ccccc1", smiles);
 }
示例#4
0
  /**
   * (2S)-butan-2-ol
   *
   * @cdk.inchi InChI=1/C4H10O/c1-3-4(2)5/h4-5H,3H2,1-2H3/t4-/s2
   */
  @Test
  public void _2S_butan_2_ol() throws Exception {

    IAtomContainer ac = new AtomContainer();
    ac.addAtom(new Atom("C"));
    ac.addAtom(new Atom("C"));
    ac.addAtom(new Atom("C"));
    ac.addAtom(new Atom("C"));
    ac.addAtom(new Atom("O"));
    ac.addAtom(new Atom("H"));
    ac.addBond(0, 1, SINGLE);
    ac.addBond(1, 2, SINGLE);
    ac.addBond(2, 3, SINGLE);
    ac.addBond(2, 4, SINGLE);
    ac.addBond(2, 5, SINGLE);

    ac.addStereoElement(
        new TetrahedralChirality(
            ac.getAtom(2),
            new IAtom[] {
              ac.getAtom(1), // C-C
              ac.getAtom(3), // C
              ac.getAtom(4), // O
              ac.getAtom(5), // H
            },
            ANTI_CLOCKWISE));

    Graph g = convert(ac);
    assertThat(g.toSmiles(), is("CC[C@](C)(O)[H]"));
  }
  /**
   * Get the expected set of molecules.
   *
   * @return The IAtomContainerSet
   */
  private IAtomContainerSet getExpectedProducts() {
    IAtomContainerSet setOfProducts = builder.newInstance(IAtomContainerSet.class);

    IAtomContainer molecule = builder.newInstance(IAtomContainer.class);
    molecule.addAtom(builder.newInstance(IAtom.class, "C"));
    molecule.getAtom(0).setFormalCharge(1);
    molecule.addAtom(builder.newInstance(IAtom.class, "C"));
    molecule.addBond(0, 1, IBond.Order.SINGLE);
    molecule.addAtom(builder.newInstance(IAtom.class, "C"));
    molecule.addBond(1, 2, IBond.Order.SINGLE);
    molecule.addAtom(builder.newInstance(IAtom.class, "C"));
    molecule.addBond(2, 3, IBond.Order.SINGLE);
    molecule.addAtom(builder.newInstance(IAtom.class, "C"));
    molecule.addBond(3, 4, IBond.Order.SINGLE);
    molecule.addAtom(builder.newInstance(IAtom.class, "C"));
    molecule.addBond(4, 5, IBond.Order.SINGLE);
    try {
      addExplicitHydrogens(molecule);
    } catch (Exception e) {
      e.printStackTrace();
    }

    molecule.getAtom(0).setFormalCharge(0);
    molecule.addSingleElectron(new SingleElectron(molecule.getAtom(0)));

    try {
      AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(molecule);
      makeSureAtomTypesAreRecognized(molecule);
    } catch (CDKException e) {
      e.printStackTrace();
    }
    setOfProducts.addAtomContainer(molecule);
    return setOfProducts;
  }
示例#6
0
  @Test
  public void s_penta_2_3_diene_expl_h() throws Exception {
    IAtomContainer m = new AtomContainer(5, 4, 0, 0);
    m.addAtom(new Atom("C"));
    m.addAtom(new Atom("C"));
    m.addAtom(new Atom("C"));
    m.addAtom(new Atom("C"));
    m.addAtom(new Atom("C"));
    m.addAtom(new Atom("H"));
    m.addAtom(new Atom("H"));
    m.addBond(0, 1, IBond.Order.SINGLE);
    m.addBond(1, 2, IBond.Order.DOUBLE);
    m.addBond(2, 3, IBond.Order.DOUBLE);
    m.addBond(3, 4, IBond.Order.SINGLE);
    m.addBond(1, 5, IBond.Order.SINGLE);
    m.addBond(3, 6, IBond.Order.SINGLE);

    int[][] atoms =
        new int[][] {
          {0, 5, 6, 4},
          {5, 0, 6, 4},
          {5, 0, 4, 6},
          {0, 5, 4, 6},
          {4, 6, 5, 0},
          {4, 6, 0, 5},
          {6, 4, 0, 5},
          {6, 4, 5, 0},
        };
    Stereo[] stereos =
        new Stereo[] {
          Stereo.CLOCKWISE,
          Stereo.ANTI_CLOCKWISE,
          Stereo.CLOCKWISE,
          Stereo.ANTI_CLOCKWISE,
          Stereo.CLOCKWISE,
          Stereo.ANTI_CLOCKWISE,
          Stereo.CLOCKWISE,
          Stereo.ANTI_CLOCKWISE
        };

    for (int i = 0; i < atoms.length; i++) {

      IStereoElement element =
          new ExtendedTetrahedral(
              m.getAtom(2),
              new IAtom[] {
                m.getAtom(atoms[i][0]),
                m.getAtom(atoms[i][1]),
                m.getAtom(atoms[i][2]),
                m.getAtom(atoms[i][3])
              },
              stereos[i]);
      m.setStereoElements(Collections.singletonList(element));

      assertThat(convert(m).toSmiles(), is("CC(=[C@]=C(C)[H])[H]"));
    }
  }
示例#7
0
  /** @cdk.inchi InChI=1/C4H5N/c1-2-4-5-3-1/h1-5H */
  @Test
  public void xtestPyrrole() throws Exception {
    IAtomContainer enol = new AtomContainer();

    // atom block
    IAtom atom1 = new Atom(Elements.CARBON);
    atom1.setHybridization(Hybridization.SP2);
    IAtom atom2 = new Atom(Elements.CARBON);
    atom2.setHybridization(Hybridization.SP2);
    IAtom atom3 = new Atom(Elements.CARBON);
    atom3.setHybridization(Hybridization.SP2);
    IAtom atom4 = new Atom(Elements.CARBON);
    atom4.setHybridization(Hybridization.SP2);
    IAtom atom5 = new Atom(Elements.NITROGEN);
    atom5.setHybridization(Hybridization.SP2);
    atom5.setImplicitHydrogenCount(1);

    // bond block
    IBond bond1 = new Bond(atom1, atom2);
    IBond bond2 = new Bond(atom2, atom3);
    IBond bond3 = new Bond(atom3, atom4);
    IBond bond4 = new Bond(atom4, atom5);
    IBond bond5 = new Bond(atom5, atom1);

    enol.addAtom(atom1);
    enol.addAtom(atom2);
    enol.addAtom(atom3);
    enol.addAtom(atom4);
    enol.addAtom(atom5);
    enol.addBond(bond1);
    enol.addBond(bond2);
    enol.addBond(bond3);
    enol.addBond(bond4);
    enol.addBond(bond5);

    // perceive atom types
    AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(enol);

    // now have the algorithm have a go at it
    enol = fbot.kekuliseAromaticRings(enol);
    Assert.assertNotNull(enol);
    // Assert.assertTrue(fbot.isOK(enol));

    // now check whether it did the right thing
    Assert.assertEquals(CDKConstants.BONDORDER_DOUBLE, enol.getBond(0).getOrder());
    ;
    Assert.assertEquals(CDKConstants.BONDORDER_SINGLE, enol.getBond(1).getOrder());
    ;
    Assert.assertEquals(CDKConstants.BONDORDER_DOUBLE, enol.getBond(2).getOrder());
    ;
    Assert.assertEquals(CDKConstants.BONDORDER_SINGLE, enol.getBond(3).getOrder());
    ;
    Assert.assertEquals(CDKConstants.BONDORDER_SINGLE, enol.getBond(4).getOrder());
    ;
  }
示例#8
0
  @Test
  public void cyclobuteneTest() {
    String expectedA = "[C]([C]([C,0])=[C]([C,0]))";
    String expectedB = "[C]([C]([C,0])[C](=[C,0]))";
    IAtomContainer cyclobutene = builder.newInstance(IAtomContainer.class);
    AbstractSignatureTest.addCarbons(cyclobutene, 4);
    cyclobutene.addBond(0, 1, IBond.Order.SINGLE);
    cyclobutene.addBond(0, 2, IBond.Order.SINGLE);
    cyclobutene.addBond(1, 3, IBond.Order.DOUBLE);
    cyclobutene.addBond(2, 3, IBond.Order.SINGLE);
    Assert.assertEquals(expectedA, canonicalStringFromMolecule(cyclobutene));

    String expectedFullString = "2" + expectedA + " + 2" + expectedB;
    String actualFullString = fullStringFromMolecule(cyclobutene);
    Assert.assertEquals(expectedFullString, actualFullString);
  }
示例#9
0
 /**
  * Selects an optimum edge for elimination in structures without N2 nodes.
  *
  * <p>This might be severely broken! Would have helped if there was an explanation of how this
  * algorithm worked.
  *
  * @param ring
  * @param molecule
  */
 private IBond checkEdges(IRing ring, IAtomContainer molecule) {
   IRing r1, r2;
   IRingSet ringSet = ring.getBuilder().newInstance(IRingSet.class);
   IBond bond;
   int minMaxSize = Integer.MAX_VALUE;
   int minMax = 0;
   logger.debug("Molecule: " + molecule);
   Iterator<IBond> bonds = ring.bonds().iterator();
   while (bonds.hasNext()) {
     bond = (IBond) bonds.next();
     molecule.removeElectronContainer(bond);
     r1 = getRing(bond.getAtom(0), molecule);
     r2 = getRing(bond.getAtom(1), molecule);
     logger.debug("checkEdges: " + bond);
     if (r1.getAtomCount() > r2.getAtomCount()) {
       ringSet.addAtomContainer(r1);
     } else {
       ringSet.addAtomContainer(r2);
     }
     molecule.addBond(bond);
   }
   for (int i = 0; i < ringSet.getAtomContainerCount(); i++) {
     if (((IRing) ringSet.getAtomContainer(i)).getBondCount() < minMaxSize) {
       minMaxSize = ((IRing) ringSet.getAtomContainer(i)).getBondCount();
       minMax = i;
     }
   }
   return (IBond) ring.getElectronContainer(minMax);
 }
示例#10
0
 public void addHydrogens(IAtomContainer mol, IAtom atom, int n) {
   for (int i = 0; i < n; i++) {
     IAtom h = builder.newInstance(IAtom.class, "H");
     mol.addAtom(h);
     mol.addBond(builder.newInstance(IBond.class, atom, h));
   }
 }
 /**
  * Procedure required by the CDOInterface. This function is only supposed to be called by the JCFL
  * library
  */
 public void endObject(String objectType) {
   logger.debug("END: " + objectType);
   if (objectType.equals("Molecule")) {
     eventReader.fireFrameRead();
     clearData();
   } else if (objectType.equals("Atom")) {
     currentMolecule.addAtom(currentAtom);
   } else if (objectType.equals("Bond")) {
     logger.debug("Bond(" + bond_id + "): " + bond_a1 + ", " + bond_a2 + ", " + bond_order);
     if (bond_a1 > currentMolecule.getAtomCount() || bond_a2 > currentMolecule.getAtomCount()) {
       logger.error(
           "Cannot add bond between at least one non-existant atom: "
               + bond_a1
               + " and "
               + bond_a2);
     } else {
       IAtom a1 = currentMolecule.getAtom(bond_a1);
       IAtom a2 = currentMolecule.getAtom(bond_a2);
       IBond b = builder.newBond(a1, a2, bond_order);
       if (bond_id != null) b.setID(bond_id);
       if (bond_stereo != -99) {
         b.setStereo(bond_stereo);
       }
       currentMolecule.addBond(b);
     }
   }
 }
  public static IAtomContainer makeFragment4() {
    IAtomContainer mol = DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainer.class);
    mol.addAtom(new Atom("C")); // 0
    mol.addAtom(new Atom("C")); // 1

    mol.addBond(0, 1, IBond.Order.SINGLE); // 1
    return mol;
  }
示例#13
0
 @BeforeClass
 public static void setup() throws Exception {
   molecule = new AtomContainer();
   molecule.addAtom(new Atom("Cl"));
   molecule.addAtom(new Atom("C"));
   molecule.addAtom(new Atom("Br"));
   molecule.addAtom(new Atom("I"));
   molecule.addAtom(new Atom("H"));
   molecule.addBond(0, 1, Order.SINGLE);
   molecule.addBond(1, 2, Order.SINGLE);
   molecule.addBond(1, 3, Order.SINGLE);
   molecule.addBond(1, 4, Order.SINGLE);
   ligands =
       new IAtom[] {
         molecule.getAtom(4), molecule.getAtom(3), molecule.getAtom(2), molecule.getAtom(0)
       };
 }
示例#14
0
 @Test
 public void fusedSquareMultipleBondTest() {
   IAtomContainer mol = builder.newInstance(IAtomContainer.class);
   String expected = "[C]([C]([C,1])[C]([C,0])[C](=[C,1])[C](=[C,0]))";
   AbstractSignatureTest.addCarbons(mol, 7);
   mol.addBond(0, 1, IBond.Order.SINGLE);
   mol.addBond(0, 2, IBond.Order.SINGLE);
   mol.addBond(0, 3, IBond.Order.SINGLE);
   mol.addBond(0, 4, IBond.Order.SINGLE);
   mol.addBond(1, 5, IBond.Order.DOUBLE);
   mol.addBond(2, 5, IBond.Order.SINGLE);
   mol.addBond(3, 6, IBond.Order.SINGLE);
   mol.addBond(4, 6, IBond.Order.DOUBLE);
   MoleculeSignature molSig = new MoleculeSignature(mol);
   String sigFor0 = molSig.signatureStringForVertex(0);
   Assert.assertEquals(expected, sigFor0);
 }
  @Test
  public void testNotCharged() throws Exception {

    IAtomContainer mol = builder.newInstance(IAtomContainer.class);
    mol.addAtom(builder.newInstance(IAtom.class, "C"));
    mol.getAtom(0).setFormalCharge(-1);
    mol.addAtom(builder.newInstance(IAtom.class, "C"));
    mol.addBond(0, 1, Order.DOUBLE);
    mol.addAtom(builder.newInstance(IAtom.class, "F"));
    mol.addBond(1, 2, Order.SINGLE);

    addExplicitHydrogens(mol);
    lpcheck.saturate(mol);

    DoubleResult result = ((DoubleResult) descriptor.calculate(mol.getAtom(0), mol).getValue());

    Assert.assertEquals(0.0, result.doubleValue(), 0.00001);
  }
  public static IAtomContainer makeFragment3() {
    IAtomContainer mol = DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainer.class);
    mol.addAtom(new Atom("C")); // 0
    mol.addAtom(new Atom("C")); // 1
    mol.addAtom(new Atom("C")); // 2
    mol.addAtom(new Atom("C")); // 3
    mol.addAtom(new Atom("C")); // 4
    mol.addAtom(new Atom("C")); // 5
    mol.addAtom(new Atom("C")); // 6

    mol.addBond(0, 1, IBond.Order.SINGLE); // 1
    mol.addBond(0, 2, IBond.Order.SINGLE); // 2
    mol.addBond(0, 3, IBond.Order.SINGLE); // 3
    mol.addBond(0, 4, IBond.Order.SINGLE); // 4
    mol.addBond(3, 5, IBond.Order.DOUBLE); // 5
    mol.addBond(5, 6, IBond.Order.SINGLE); // 6
    return mol;
  }
示例#17
0
  /**
   * (Z)-1,2-difluoroethene
   *
   * @cdk.inchi InChI=1/C2H2F2/c3-1-2-4/h1-2H/b2-1-
   */
  @Test
  public void z_1_2_difluoroethene() throws Exception {

    IAtomContainer ac = new AtomContainer();
    ac.addAtom(new Atom("F"));
    ac.addAtom(new Atom("C"));
    ac.addAtom(new Atom("C"));
    ac.addAtom(new Atom("F"));
    ac.addBond(0, 1, SINGLE);
    ac.addBond(1, 2, DOUBLE);
    ac.addBond(2, 3, SINGLE);

    ac.addStereoElement(
        new DoubleBondStereochemistry(
            ac.getBond(1), new IBond[] {ac.getBond(0), ac.getBond(2)}, TOGETHER));
    Graph g = convert(ac);
    assertThat(g.toSmiles(), is("F/C=C\\F"));
  }
示例#18
0
 @Before
 public void setUp() {
   this.parser = new SmilesParser(DefaultChemObjectBuilder.getInstance());
   this.builder = DefaultChemObjectBuilder.getInstance();
   mol = builder.newInstance(IAtomContainer.class);
   mol.addAtom(builder.newInstance(IAtom.class, "C"));
   mol.addAtom(builder.newInstance(IAtom.class, "C"));
   mol.addBond(0, 1, IBond.Order.SINGLE);
   molSig = new MoleculeSignature(mol);
 }
示例#19
0
  /**
   * This is a mock test where we don't want aromatic bonds to have a configuration.
   * (Z)-1,2-difluoroethene is not aromatic but a 'real' example would be porphyrins.
   *
   * @cdk.inchi InChI=1/C2H2F2/c3-1-2-4/h1-2H/b2-1-
   */
  @Test
  public void z_1_2_difluoroethene_aromatic() throws Exception {

    IAtomContainer ac = new AtomContainer();
    ac.addAtom(new Atom("F"));
    ac.addAtom(new Atom("C"));
    ac.addAtom(new Atom("C"));
    ac.addAtom(new Atom("F"));
    ac.addBond(0, 1, SINGLE);
    ac.addBond(1, 2, DOUBLE);
    ac.addBond(2, 3, SINGLE);

    ac.getBond(1).setFlag(CDKConstants.ISAROMATIC, true);

    ac.addStereoElement(
        new DoubleBondStereochemistry(
            ac.getBond(1), new IBond[] {ac.getBond(0), ac.getBond(2)}, TOGETHER));
    Graph g = convert(ac);
    assertThat(g.toSmiles(), is("F[CH]:[CH]F"));
  }
示例#20
0
 /** Tests the method saturate(). */
 @Test
 public void testSaturate_NumberingProblem() throws Exception {
   IAtomContainer mol = new AtomContainer();
   Atom a1 = new Atom("C");
   mol.addAtom(a1);
   Atom a2 = new Atom("C");
   mol.addAtom(a2);
   Atom a3 = new Atom("C");
   mol.addAtom(a3);
   Atom a4 = new Atom("H");
   mol.addAtom(a4);
   Atom a5 = new Atom("C");
   mol.addAtom(a5);
   Atom a6 = new Atom("H");
   mol.addAtom(a6);
   Atom a7 = new Atom("S");
   mol.addAtom(a7);
   Atom a8 = new Atom("H");
   mol.addAtom(a8);
   Atom a9 = new Atom("H");
   mol.addAtom(a9);
   Bond b1 = new Bond(a1, a2, IBond.Order.SINGLE);
   mol.addBond(b1);
   Bond b2 = new Bond(a1, a3, IBond.Order.SINGLE);
   mol.addBond(b2);
   Bond b3 = new Bond(a1, a4, IBond.Order.SINGLE);
   mol.addBond(b3);
   Bond b4 = new Bond(a5, a2, IBond.Order.SINGLE);
   mol.addBond(b4);
   Bond b5 = new Bond(a2, a6, IBond.Order.SINGLE);
   mol.addBond(b5);
   Bond b6 = new Bond(a3, a7, IBond.Order.SINGLE);
   mol.addBond(b6);
   Bond b7 = new Bond(a3, a8, IBond.Order.SINGLE);
   mol.addBond(b7);
   Bond b8 = new Bond(a7, a5, IBond.Order.SINGLE);
   mol.addBond(b8);
   Bond b9 = new Bond(a5, a9, IBond.Order.SINGLE);
   mol.addBond(b9);
   satcheck.saturate(mol);
   Assert.assertEquals(IBond.Order.SINGLE, b1.getOrder());
   Assert.assertEquals(IBond.Order.DOUBLE, b2.getOrder());
   Assert.assertEquals(IBond.Order.SINGLE, b6.getOrder());
   Assert.assertEquals(IBond.Order.SINGLE, b8.getOrder());
   Assert.assertEquals(IBond.Order.DOUBLE, b4.getOrder());
 }
示例#21
0
  @Test
  public void testBenzeneWithDoubleBonds() {
    IAtomContainer benzene = builder.newInstance(IAtomContainer.class);
    AbstractSignatureTest.addCarbons(benzene, 6);
    for (int i = 0; i < 6; i++) {
      AbstractSignatureTest.addHydrogens(benzene, i, 1);
    }
    benzene.addBond(0, 1, IBond.Order.SINGLE);
    benzene.addBond(1, 2, IBond.Order.DOUBLE);
    benzene.addBond(2, 3, IBond.Order.SINGLE);
    benzene.addBond(3, 4, IBond.Order.DOUBLE);
    benzene.addBond(4, 5, IBond.Order.SINGLE);
    benzene.addBond(5, 0, IBond.Order.DOUBLE);

    MoleculeSignature signature = new MoleculeSignature(benzene);
    String carbonSignature = signature.signatureStringForVertex(0);
    for (int i = 1; i < 6; i++) {
      String carbonSignatureI = signature.signatureStringForVertex(i);
      Assert.assertEquals(carbonSignature, carbonSignatureI);
    }
  }
示例#22
0
  @Test
  public void napthaleneSkeletonHeightTest() {
    IAtomContainer napthalene = builder.newInstance(IAtomContainer.class);
    for (int i = 0; i < 10; i++) {
      napthalene.addAtom(builder.newInstance(IAtom.class, "C"));
    }
    napthalene.addBond(0, 1, IBond.Order.SINGLE);
    napthalene.addBond(0, 5, IBond.Order.SINGLE);
    napthalene.addBond(1, 2, IBond.Order.SINGLE);
    napthalene.addBond(1, 6, IBond.Order.SINGLE);
    napthalene.addBond(2, 3, IBond.Order.SINGLE);
    napthalene.addBond(2, 9, IBond.Order.SINGLE);
    napthalene.addBond(3, 4, IBond.Order.SINGLE);
    napthalene.addBond(4, 5, IBond.Order.SINGLE);
    napthalene.addBond(6, 7, IBond.Order.SINGLE);
    napthalene.addBond(7, 8, IBond.Order.SINGLE);
    napthalene.addBond(8, 9, IBond.Order.SINGLE);

    MoleculeSignature molSig = new MoleculeSignature(napthalene);
    int height = 2;
    Map<String, Orbit> orbits = new HashMap<String, Orbit>();
    for (int i = 0; i < napthalene.getAtomCount(); i++) {
      String signatureString = molSig.signatureStringForVertex(i, height);
      Orbit orbit;
      if (orbits.containsKey(signatureString)) {
        orbit = orbits.get(signatureString);
      } else {
        orbit = new Orbit(signatureString, height);
        orbits.put(signatureString, orbit);
      }
      orbit.addAtom(i);
    }
    Assert.assertEquals(3, orbits.size());
  }
示例#23
0
 @Test
 public void writeAtomClass() throws Exception {
   IAtomContainer ac = new AtomContainer();
   ac.addAtom(new Atom("C"));
   ac.addAtom(new Atom("C"));
   ac.addAtom(new Atom("O"));
   ac.addBond(0, 1, SINGLE);
   ac.addBond(1, 2, SINGLE);
   ac.getAtom(0).setProperty(CDKConstants.ATOM_ATOM_MAPPING, 3);
   ac.getAtom(1).setProperty(CDKConstants.ATOM_ATOM_MAPPING, 1);
   ac.getAtom(2).setProperty(CDKConstants.ATOM_ATOM_MAPPING, 2);
   assertThat(convert(ac).toSmiles(), is("[CH3:3][CH2:1][OH:2]"));
 }
示例#24
0
  @Test
  public void s_penta_2_3_diene_impl_h() throws Exception {
    IAtomContainer m = new AtomContainer(5, 4, 0, 0);
    m.addAtom(new Atom("C"));
    m.addAtom(new Atom("C"));
    m.addAtom(new Atom("C"));
    m.addAtom(new Atom("C"));
    m.addAtom(new Atom("C"));
    m.addBond(0, 1, IBond.Order.SINGLE);
    m.addBond(1, 2, IBond.Order.DOUBLE);
    m.addBond(2, 3, IBond.Order.DOUBLE);
    m.addBond(3, 4, IBond.Order.SINGLE);

    IStereoElement element =
        new ExtendedTetrahedral(
            m.getAtom(2),
            new IAtom[] {m.getAtom(0), m.getAtom(1), m.getAtom(3), m.getAtom(4)},
            CLOCKWISE);
    m.setStereoElements(Collections.singletonList(element));

    assertThat(convert(m).toSmiles(), is("CC=[C@@]=CC"));
  }
 private void processBondsBlock(int lineCount, IAtomContainer container) throws IOException {
   for (int i = 0; i < lineCount; i++) {
     String line = input.readLine();
     int atom1 = Integer.parseInt(line.substring(10, 13).trim()) - 1;
     int atom2 = Integer.parseInt(line.substring(16, 19).trim()) - 1;
     if (container.getBond(container.getAtom(atom1), container.getAtom(atom2)) == null) {
       IBond bond =
           container.getBuilder().newBond(container.getAtom(atom1), container.getAtom(atom2));
       int order = Integer.parseInt(line.substring(23).trim());
       bond.setOrder(BondManipulator.createBondOrder((double) order));
       container.addBond(bond);
     } // else: bond already present; CTX store the bonds twice
   }
 }
示例#26
0
  @Test
  public void testNNMolecule_IAtomContainer() {
    IAtomContainer acetone = new org.openscience.cdk.AtomContainer();
    IAtom c1 = acetone.getBuilder().newAtom("C");
    IAtom c2 = acetone.getBuilder().newAtom("C");
    IAtom o = acetone.getBuilder().newAtom("O");
    IAtom c3 = acetone.getBuilder().newAtom("C");
    acetone.addAtom(c1);
    acetone.addAtom(c2);
    acetone.addAtom(c3);
    acetone.addAtom(o);
    IBond b1 = acetone.getBuilder().newBond(c1, c2, IBond.Order.SINGLE);
    IBond b2 = acetone.getBuilder().newBond(c1, o, IBond.Order.DOUBLE);
    IBond b3 = acetone.getBuilder().newBond(c1, c3, IBond.Order.SINGLE);
    acetone.addBond(b1);
    acetone.addBond(b2);
    acetone.addBond(b3);

    IMolecule m = new NNMolecule(acetone);
    Assert.assertNotNull(m);
    Assert.assertEquals(4, m.getAtomCount());
    Assert.assertEquals(3, m.getBondCount());
  }
  public static IAtomContainer makePropylAmine() {
    IAtomContainer mol = DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainer.class);
    Atom atom = new Atom("C");
    atom.setID("0");
    mol.addAtom(atom); // 0

    atom = new Atom("C");
    atom.setID("1");
    mol.addAtom(atom); // 1

    atom = new Atom("C");
    atom.setID("2");
    mol.addAtom(atom); // 2

    atom = new Atom("N");
    atom.setID("3");
    mol.addAtom(atom); // 3

    mol.addBond(0, 1, IBond.Order.SINGLE); // 1
    mol.addBond(1, 2, IBond.Order.SINGLE); // 2
    mol.addBond(2, 3, IBond.Order.SINGLE); // 3

    return mol;
  }
示例#28
0
 /** A unit test for JUnit */
 @Test
 public void testBondPermutation() {
   IAtomContainer mol = new AtomContainer();
   mol.addAtom(new Atom("S"));
   mol.addAtom(new Atom("O"));
   mol.addAtom(new Atom("O"));
   mol.addAtom(new Atom("O"));
   mol.addAtom(new Atom("O"));
   mol.addBond(0, 1, IBond.Order.DOUBLE);
   mol.addBond(0, 2, IBond.Order.DOUBLE);
   mol.addBond(0, 3, IBond.Order.SINGLE);
   mol.addBond(0, 4, IBond.Order.SINGLE);
   mol.getAtom(3).setImplicitHydrogenCount(1);
   mol.getAtom(4).setImplicitHydrogenCount(1);
   AtomContainerBondPermutor acbp = new AtomContainerBondPermutor(mol);
   SmilesGenerator sg = new SmilesGenerator();
   String smiles = "";
   String oldSmiles = sg.createSMILES(mol);
   while (acbp.hasNext()) {
     smiles = sg.createSMILES(new AtomContainer((AtomContainer) acbp.next()));
     // logger.debug(smiles);
     Assert.assertEquals(oldSmiles, smiles);
   }
 }
示例#29
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);
  }
  /**
   * A unit test for JUnit
   *
   * @throws Exception
   */
  @Test
  public void testStabilizationComparative() throws Exception {

    IAtomContainer mol1 = builder.newInstance(IAtomContainer.class);
    mol1.addAtom(builder.newInstance(IAtom.class, "C"));
    mol1.addAtom(builder.newInstance(IAtom.class, "C"));
    mol1.getAtom(1).setFormalCharge(1);
    mol1.addBond(0, 1, Order.SINGLE);
    mol1.addAtom(builder.newInstance(IAtom.class, "C"));
    mol1.addBond(1, 2, Order.SINGLE);
    mol1.addAtom(builder.newInstance(IAtom.class, "O"));
    mol1.addBond(1, 3, Order.SINGLE);
    addExplicitHydrogens(mol1);
    lpcheck.saturate(mol1);

    DoubleResult result1 = ((DoubleResult) descriptor.calculate(mol1.getAtom(1), mol1).getValue());

    IAtomContainer mol2 = builder.newInstance(IAtomContainer.class);
    mol2.addAtom(builder.newInstance(IAtom.class, "C"));
    mol2.addAtom(builder.newInstance(IAtom.class, "C"));
    mol2.getAtom(1).setFormalCharge(1);
    mol2.addBond(0, 1, Order.SINGLE);
    mol2.addAtom(builder.newInstance(IAtom.class, "O"));
    mol2.addBond(1, 2, Order.SINGLE);
    addExplicitHydrogens(mol2);
    lpcheck.saturate(mol2);

    DoubleResult result2 = ((DoubleResult) descriptor.calculate(mol2.getAtom(1), mol2).getValue());

    IAtomContainer mol3 = builder.newInstance(IAtomContainer.class);
    mol3.addAtom(builder.newInstance(IAtom.class, "C"));
    mol3.addAtom(builder.newInstance(IAtom.class, "C"));
    mol3.getAtom(1).setFormalCharge(1);
    mol3.addBond(0, 1, Order.SINGLE);
    mol3.addAtom(builder.newInstance(IAtom.class, "C"));
    mol3.addBond(1, 2, Order.SINGLE);
    addExplicitHydrogens(mol3);
    lpcheck.saturate(mol3);

    DoubleResult result3 = ((DoubleResult) descriptor.calculate(mol3.getAtom(1), mol3).getValue());

    Assert.assertTrue(result3.doubleValue() < result2.doubleValue());
    Assert.assertTrue(result2.doubleValue() < result1.doubleValue());
  }