Exemplo n.º 1
0
  /** Starts enumeration of the combinatorial library. */
  public void run() {
    // enumeration starts
    if (startEnumeration) {

      // start time
      long start = System.nanoTime();

      // if GUI mode is used, some statistics are shown
      if (useGui) {
        smiFrame.setStatistics(
            compAdmin.getNumberOfScaffolds(),
            compAdmin.getNumberOfLinkers(),
            compAdmin.getNumberOfBuildingBlocks());
      }

      // start enumeration
      try {
        this.enumerateLibrary();
      } catch (Throwable thr) {
        handleException(thr);
      }

      // end time
      long end = System.nanoTime();

      // formats time
      DecimalFormat df = new DecimalFormat("###,###,###,##0.000000000###");

      // message of end of enumeration is shown in command line/GUI - NOT if library is printed to
      // command line
      if (useGui) {
        smiFrame.setTime(start, end);
        smiFrame.showEndMessage(start, end);
      } else if (!printToCommandLine) {
        // total time is printed out
        if (compoundCounter == 1) {
          System.out.println(
              compoundCounter
                  + " compound synthesized in "
                  + df.format((double) (end - start) / 1000000000)
                  + " seconds");
        } else {
          System.out.println(
              compoundCounter
                  + " compounds synthesized in "
                  + df.format((double) (end - start) / 1000000000)
                  + " seconds");
        }
      }
    }
  }
Exemplo n.º 2
0
  /**
   * Creates a new instance of SmiLibRunner, used when programm is started in GUI mode.
   *
   * @param scaffolds array of source scaffold (with ID)
   * @param linkers array of source linkers (with ID)
   * @param bBlocks array of source building block (with ID)
   * @param useReactionScheme use reaction scheme true/false
   * @param reactionScheme reactionScheme as array
   * @param targetTextArea text area where library will be written in
   * @param showLibrary show library in GUI true/false
   * @param saveAsFile save library as file true/false
   * @param saveAsSDF save file as SD file true/false
   * @param addHydrogens add implicit hydrogens when building the SD file true/false
   * @param path path/name of file where library will be saved
   * @param frame main frame of GUI
   * @param checkSmiles check smiles for SmiLib conformity true/false
   */
  public SmiLibRunner(
      String[] scaffolds,
      String[] linkers,
      String[] bBlocks,
      boolean useReactionScheme,
      String[] reactionScheme,
      JTextArea targetTextArea,
      boolean showLibrary,
      boolean saveAsFile,
      boolean saveAsSDF,
      boolean addHydrogens,
      String path,
      SmiLibFrame frame,
      boolean checkSmiles) {

    this.smiFrame = frame;
    this.useGui = true;

    // load source SMILES
    try {
      compAdmin = new ComponentAdministrator(scaffolds, linkers, bBlocks, checkSmiles);
      if (!useReactionScheme) {
        this.iterator =
            new FullCombinationIterator(
                compAdmin.getNumbersOfRGroups(),
                compAdmin.getNumberOfLinkers(),
                compAdmin.getNumberOfBuildingBlocks());
      } else {
        this.iterator =
            new PartialCombinationIterator(
                reactionScheme,
                compAdmin.getNumbersOfRGroups(),
                compAdmin.getNumberOfLinkers(),
                compAdmin.getNumberOfBuildingBlocks());
      }
      smiFrame.setIterator(iterator);
      smiWri =
          new SmilesGuiWriter(
              targetTextArea, showLibrary, saveAsFile, saveAsSDF, addHydrogens, path, smiFrame);

    } catch (Exception exc) {
      handleException(exc);
    }
  }
Exemplo n.º 3
0
  /**
   * Centralised Exception handling. Thread ist stopped and a message for each different kind of
   * message is shown/printed.
   *
   * @param thr cause of Error/Exception
   */
  public void handleException(Throwable thr) {
    startEnumeration = false;

    // GUI: show JOptionpane; else: print errormessage
    if (useGui) {
      smiFrame.emergencyShutdown();
      javax.swing.JOptionPane messageBox = new javax.swing.JOptionPane();

      if (thr instanceof SmiLibConformityException) {
        messageBox.showMessageDialog(
            smiFrame, thr.getMessage(), "Error", javax.swing.JOptionPane.ERROR_MESSAGE);
      } else if (thr instanceof ReactionSchemeException) {
        messageBox.showMessageDialog(
            smiFrame, thr.getMessage(), "Error", javax.swing.JOptionPane.ERROR_MESSAGE);
      } else if (thr instanceof SmiLibIOException) {
        messageBox.showMessageDialog(
            smiFrame, thr.getMessage(), "Error", javax.swing.JOptionPane.ERROR_MESSAGE);
      } else if (thr instanceof StringIndexOutOfBoundsException) {
        messageBox.showMessageDialog(
            smiFrame, thr.getMessage(), "Error", javax.swing.JOptionPane.ERROR_MESSAGE);
      } else if (thr instanceof NumberFormatException) {
        messageBox.showMessageDialog(
            smiFrame,
            "Invalid reaction scheme.\nPlease check reaction scheme and/or use SmiLib help!",
            "Error",
            javax.swing.JOptionPane.ERROR_MESSAGE);
      } else if (thr instanceof java.lang.OutOfMemoryError) {
        messageBox.showMessageDialog(
            smiFrame,
            "Java heap size overflow.\nRestart program with access to more memory!",
            "Error",
            javax.swing.JOptionPane.ERROR_MESSAGE);
        System.exit(1);
      } else if (thr instanceof SmiLibSdfException) {
        messageBox.showMessageDialog(
            smiFrame,
            "An error occured converting SMILES to SDF.\n" + thr.getMessage(),
            "Error",
            javax.swing.JOptionPane.ERROR_MESSAGE);
      } else {
        messageBox.showMessageDialog(
            smiFrame, thr.toString(), "Error", javax.swing.JOptionPane.ERROR_MESSAGE);
      }
    } else {
      if (thr instanceof SmiLibConformityException) {
        System.err.println(thr.getMessage());
        System.err.println("An error occured. Program halted.");
      } else if (thr instanceof ReactionSchemeException) {
        System.err.println(thr.getMessage());
        System.err.println("An error occured. Program halted.");
      } else if (thr instanceof SmiLibIOException) {
        System.err.println(thr.getMessage());
        System.err.println("An error occured. Program halted.");
      } else if (thr instanceof StringIndexOutOfBoundsException) {
        System.err.println(thr.getMessage());
        System.err.println("An error occured. Program halted.");
      } else if (thr instanceof NumberFormatException) {
        System.err.println(
            "Invalid reaction scheme.\nPlease check reaction scheme and/or use SmiLib help!");
        System.err.println("An error occured. Program halted.");
      } else if (thr instanceof java.lang.OutOfMemoryError) {
        System.err.println("Java heap size overflow.\nRestart program with access to more memory!");
        System.err.println("An error occured. Program halted.");
        System.exit(1);
      } else if (thr instanceof SmiLibSdfException) {
        System.err.println("An error occured converting SMILES to SDF.");
        System.err.println(thr.getMessage());
        System.err.println("An error occured. Program halted.");
      } else {
        System.err.println(thr.getMessage());
        System.err.println("An error occured. Program halted.");
      }
    }
  }