Ejemplo n.º 1
0
  /**
   * Gets the mol file from a specified KEGG ID.
   *
   * @param accessionID the accession id (e.g. C00509)
   * @return the string
   * @throws CDKException
   */
  public static IAtomContainer getMol(String accessionID, String keggPath, boolean getAll)
      throws CDKException {
    String ret = "";

    try {
      KEGGLocator locator = new KEGGLocator();
      KEGGPortType serv = locator.getKEGGPort();
      // get molecule by accession ID
      String str = "-f m cpd:" + accessionID;

      boolean webservice = false;
      String mol = "";

      try {
        // Open the file that is the first
        // command line parameter
        FileInputStream fstream = new FileInputStream(keggPath + accessionID + ".mol");
        // Get the object of DataInputStream
        DataInputStream in = new DataInputStream(fstream);
        BufferedReader br = new BufferedReader(new InputStreamReader(in));

        // Read File Line By Line
        String line;
        while ((line = br.readLine()) != null) {
          // Print the content on the console
          mol += line + "\n";
        }
        // Close the input stream
        in.close();

      } catch (FileNotFoundException e) {
        webservice = true;
      }

      // if this file is not found use webservice...otherwise use local molfile
      if (webservice) ret = serv.bget(str);
      else ret = mol;

    } catch (Exception e) {
      System.err.println(e.toString());
    }

    MDLReader reader;
    List<IAtomContainer> containersList;

    reader = new MDLReader(new StringReader(ret));
    ChemFile chemFile = (ChemFile) reader.read((ChemObject) new ChemFile());
    containersList = ChemFileManipulator.getAllAtomContainers(chemFile);
    IAtomContainer molecule = containersList.get(0);

    if (getAll) return molecule;
    if (!MolecularFormulaTools.isBiologicalCompound(molecule)) molecule = null;

    return molecule;
  }
Ejemplo n.º 2
0
 @Test
 public void testBug70() throws FileNotFoundException, CDKException {
   JPanelFixture jcppanel = applet.panel("appletframe");
   JChemPaintPanel panel = (JChemPaintPanel) jcppanel.target;
   applet.button("hexagon").click();
   applet.click();
   Point2d point = getAtomPoint(panel, 0);
   applet
       .panel("renderpanel")
       .robot
       .click(
           applet.panel("renderpanel").component(),
           new Point((int) point.x, (int) point.y),
           MouseButton.RIGHT_BUTTON,
           1);
   applet
       .panel("renderpanel")
       .robot
       .click(
           applet.panel("renderpanel").component(),
           new Point((int) point.x, (int) point.y),
           MouseButton.RIGHT_BUTTON,
           1);
   applet.menuItem("showACProperties").click();
   DialogFixture dialog = applet.dialog();
   JTextComponent textfield = dialog.robot.finder().find(JTextComponentMatcher.withName("Title"));
   textfield.setText("aaa");
   JButtonFixture okbutton =
       new JButtonFixture(
           dialog.robot, dialog.robot.finder().find(new ButtonTextComponentMatcher("OK")));
   okbutton.click();
   applet.menuItem("save").click();
   dialog = applet.dialog();
   File file = new File(System.getProperty("java.io.tmpdir") + File.separator + "test.mol");
   if (file.exists()) file.delete();
   JComboBox combobox =
       dialog
           .robot
           .finder()
           .find(new ComboBoxTextComponentMatcher("org.openscience.jchempaint.io.JCPFileFilter"));
   combobox.setSelectedItem(combobox.getItemAt(SAVE_AS_MOL_COMBOBOX_POS));
   JTextComponentFixture text = dialog.textBox();
   text.setText(file.toString());
   JButtonFixture savebutton =
       new JButtonFixture(
           dialog.robot, dialog.robot.finder().find(new ButtonTextComponentMatcher("Save")));
   savebutton.click();
   MDLReader reader = new MDLReader(new FileInputStream(file));
   IAtomContainer mol =
       (IAtomContainer)
           reader.read(DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainer.class));
   Assert.assertEquals("aaa", (String) mol.getProperty(CDKConstants.TITLE));
 }
Ejemplo n.º 3
0
 /** Test some sugars */
 @Test
 public void testSugarSMILES() {
   try {
     String filename = "data/mdl/D-mannose.mol";
     InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename);
     MDLReader reader = new MDLReader(ins, Mode.STRICT);
     IAtomContainer mol1 = reader.read(new AtomContainer());
     addExplicitHydrogens(mol1);
     new HydrogenPlacer().placeHydrogens2D(mol1, 1.0);
     filename = "data/mdl/D+-glucose.mol";
     ins = this.getClass().getClassLoader().getResourceAsStream(filename);
     reader = new MDLReader(ins, Mode.STRICT);
     IAtomContainer mol2 = reader.read(new AtomContainer());
     addExplicitHydrogens(mol2);
     new HydrogenPlacer().placeHydrogens2D(mol2, 1.0);
     SmilesGenerator sg = new SmilesGenerator();
     String smiles1 = sg.createChiralSMILES(mol1, new boolean[20]);
     String smiles2 = sg.createChiralSMILES(mol2, new boolean[20]);
     Assert.assertNotSame(smiles2, smiles1);
   } catch (Exception exc) {
     System.out.println(exc);
   }
 }