Exemple #1
0
 /** A unit test for JUnit */
 @Test
 public void testPartitioning() {
   String smiles = "";
   IAtomContainer molecule = new AtomContainer();
   SmilesGenerator sg = new SmilesGenerator();
   Atom sodium = new Atom("Na");
   sodium.setFormalCharge(+1);
   Atom hydroxyl = new Atom("O");
   hydroxyl.setImplicitHydrogenCount(1);
   hydroxyl.setFormalCharge(-1);
   molecule.addAtom(sodium);
   molecule.addAtom(hydroxyl);
   try {
     smiles = sg.createSMILES(molecule);
   } catch (Exception exc) {
     System.out.println(exc);
     if (!standAlone) {
       Assert.fail();
     }
   }
   if (standAlone) {
     System.err.println("SMILES: " + smiles);
   }
   Assert.assertTrue(smiles.indexOf(".") != -1);
 }
Exemple #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);
 }
  /**
   * create the compound
   *
   * @return The IAtomContainerSet
   */
  private IAtomContainerSet getExampleReactants() {
    IAtomContainerSet setOfReactants =
        DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainerSet.class);

    IAtomContainer molecule = builder.newInstance(IAtomContainer.class);
    molecule.addAtom(builder.newInstance(IAtom.class, "C"));
    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.getAtom(3).setFormalCharge(1);
    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(3).setFormalCharge(0);
    molecule.addSingleElectron(new SingleElectron(molecule.getAtom(3)));

    try {
      AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(molecule);
      makeSureAtomTypesAreRecognized(molecule);
    } catch (CDKException e) {
      e.printStackTrace();
    }
    setOfReactants.addAtomContainer(molecule);
    return setOfReactants;
  }
Exemple #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]"));
  }
Exemple #5
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);
 }
Exemple #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]"));
    }
  }
Exemple #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());
    ;
  }
Exemple #8
0
 /**
  * Partition the bonding partners of a given atom into ring atoms and non-ring atoms
  *
  * @param atom The atom whose bonding partners are to be partitioned
  * @param ring The ring against which the bonding partners are checked
  * @param ringAtoms An AtomContainer to store the ring bonding partners
  * @param nonRingAtoms An AtomContainer to store the non-ring bonding partners
  */
 public void partitionNonRingPartners(
     IAtom atom, IRing ring, IAtomContainer ringAtoms, IAtomContainer nonRingAtoms) {
   java.util.List atoms = molecule.getConnectedAtomsList(atom);
   for (int i = 0; i < atoms.size(); i++) {
     IAtom curAtom = (IAtom) atoms.get(i);
     if (!ring.contains(curAtom)) {
       nonRingAtoms.addAtom(curAtom);
     } else {
       ringAtoms.addAtom(curAtom);
     }
   }
 }
Exemple #9
0
 /** Test of getOverLaps method, of class SingleMapping. */
 @Test
 public void testGetOverLaps() throws CDKException {
   //////// System.out.println("getOverLaps");
   IAtom atomSource = new Atom("R");
   IAtom atomTarget = new Atom("R");
   IAtomContainer source = new AtomContainer();
   source.addAtom(atomSource);
   IAtomContainer target = new AtomContainer();
   target.addAtom(atomTarget);
   SingleMapping instance = new SingleMapping();
   Assert.assertNotNull(instance.getOverLaps(source, target));
 }
Exemple #10
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]"));
 }
Exemple #11
0
  /**
   * Place hydrogens connected to the provided atom <i>atom</i> using the specified
   * <i>bondLength</i>.
   *
   * @param container atom container
   * @param bondLength bond length to user
   * @throws IllegalArgumentException thrown if the <i>atom</i> or <i>container</i> was null or the
   *     atom has connected atoms which have not been placed.
   */
  @TestMethod("testNoConnections,testNullContainer,unplacedNonHydrogen")
  public void placeHydrogens2D(IAtomContainer container, IAtom atom, double bondLength) {

    if (container == null)
      throw new IllegalArgumentException("cannot place hydrogens, no container provided");
    if (atom.getPoint2d() == null)
      throw new IllegalArgumentException("cannot place hydrogens on atom without coordinates");

    logger.debug(
        "placing hydrogens connected to atom ", atom.getSymbol(),
        ": ", atom.getPoint2d());
    logger.debug("bond length", bondLength);

    AtomPlacer atomPlacer = new AtomPlacer();
    atomPlacer.setMolecule(container);

    List<IAtom> connected = container.getConnectedAtomsList(atom);
    IAtomContainer placed = container.getBuilder().newInstance(IAtomContainer.class);
    IAtomContainer unplaced = container.getBuilder().newInstance(IAtomContainer.class);

    // divide connected atoms into those which are have and haven't been placed
    for (final IAtom conAtom : connected) {
      if (conAtom.getPoint2d() == null) {
        if (conAtom.getSymbol().equals("H")) {
          unplaced.addAtom(conAtom);
        } else {
          throw new IllegalArgumentException(
              "cannot place hydrogens, atom has connected" + " non-hydrogens without coordinates");
        }
      } else {
        placed.addAtom(conAtom);
      }
    }

    logger.debug("Atom placement before procedure:");
    logger.debug("Centre atom ", atom.getSymbol(), ": ", atom.getPoint2d());
    for (int i = 0; i < unplaced.getAtomCount(); i++) {
      logger.debug("H-" + i, ": ", unplaced.getAtom(i).getPoint2d());
    }

    Point2d centerPlacedAtoms = GeometryTools.get2DCenter(placed);
    atomPlacer.distributePartners(atom, placed, centerPlacedAtoms, unplaced, bondLength);

    logger.debug("Atom placement after procedure:");
    logger.debug("Centre atom ", atom.getSymbol(), ": ", atom.getPoint2d());
    for (int i = 0; i < unplaced.getAtomCount(); i++) {
      logger.debug("H-" + i, ": ", unplaced.getAtom(i).getPoint2d());
    }
  }
 /**
  * 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 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));
   }
 }
  @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());
  }
  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;
  }
 @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)
       };
 }
  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;
  }
Exemple #18
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"));
  }
  @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);
  }
Exemple #20
0
 /** Tests whether the saturation checker gets a proton right. */
 @Test
 public void testIsSaturated_Proton() throws Exception {
   // test H+
   IAtomContainer m = new AtomContainer();
   Atom h = new Atom("H");
   h.setFormalCharge(+1);
   m.addAtom(h);
   Assert.assertTrue(satcheck.isSaturated(h, m));
 }
 @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);
 }
Exemple #22
0
 @Test
 public void azanium() throws Exception {
   IAtomContainer ac = new AtomContainer();
   IAtom a = new Atom("N");
   a.setFormalCharge(+1);
   ac.addAtom(a);
   Graph g = convert(ac);
   assertThat(g.atom(0).charge(), is(+1));
   assertThat(g.toSmiles(), is("[NH4+]"));
 }
Exemple #23
0
 @Test
 public void C13_nonIsomeric() throws Exception {
   IAtomContainer ac = new AtomContainer();
   IAtom a = new Atom("C");
   a.setMassNumber(13);
   ac.addAtom(a);
   Graph g = convert(ac, false, false); // non-isomeric
   assertThat(g.atom(0).isotope(), is(-1));
   assertThat(g.toSmiles(), is("C"));
 }
Exemple #24
0
 @Test
 public void C13_isomeric() throws Exception {
   IAtomContainer ac = new AtomContainer();
   IAtom a = new Atom("C");
   a.setMassNumber(13);
   ac.addAtom(a);
   Graph g = convert(ac);
   assertThat(g.atom(0).isotope(), is(13));
   assertThat(g.toSmiles(), is("[13CH4]"));
 }
 private void processAtomsBlock(int lineCount, IAtomContainer container) throws IOException {
   for (int i = 0; i < lineCount; i++) {
     String line = input.readLine();
     int atomicNumber = Integer.parseInt(line.substring(7, 10).trim());
     IAtom atom = container.getBuilder().newAtom();
     atom.setAtomicNumber(atomicNumber);
     atom.setSymbol(Symbols.byAtomicNumber[atomicNumber]);
     container.addAtom(atom);
   }
 }
Exemple #26
0
 @Test
 public void oxidandiide() throws Exception {
   IAtomContainer ac = new AtomContainer();
   IAtom a = new Atom("O");
   a.setFormalCharge(-2);
   ac.addAtom(a);
   Graph g = convert(ac);
   assertThat(g.atom(0).charge(), is(-2));
   assertThat(g.toSmiles(), is("[O-2]"));
 }
Exemple #27
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"));
  }
Exemple #28
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());
 }
  /**
   * Method that actually does the work of convert the IMolecularFormula to IAtomContainer given a
   * IAtomContainer.
   *
   * <p>The hydrogens must be implicit.
   *
   * @param formula IMolecularFormula object
   * @param atomContainer IAtomContainer to put the new Elements
   * @return the filled AtomContainer
   * @see #getAtomContainer(IMolecularFormula)
   */
  public static IAtomContainer getAtomContainer(
      IMolecularFormula formula, IAtomContainer atomContainer) {

    for (IIsotope isotope : formula.isotopes()) {
      int occur = formula.getIsotopeCount(isotope);
      for (int i = 0; i < occur; i++) {
        IAtom atom = formula.getBuilder().newInstance(IAtom.class, isotope);
        atomContainer.addAtom(atom);
      }
    }
    return atomContainer;
  }
Exemple #30
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);
  }