⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 moss.java

📁 A program to find frequent molecular substructures and discriminative fragments in a database of mol
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
    int    rgmin, rgmax;        /* minimum and maximum ring size */    if (this.running) {         /* if running, stop computations */      if (this.stopped) return; /* if already stopped, abort */      this.stat.setText("aborting search ...");      this.stopped = true; this.miner.stop(); return;    }                           /* stop the miner and abort */    this.running = true;        /* set the status to running */    this.stopped = false;       /* and not stopped */    this.exec.setText("Abort"); /* change the button text */    this.start = System.currentTimeMillis();    this.miner = new Miner();   /* create a substructure miner */    try {                       /* and try to initialize it */      fmt = fmtnames[fmt_seed.getSelectedIndex()];      this.miner.setSeed    (fmt, seed.getText());      this.miner.setExcluded(fmt, excl.getText(), exseed.getText());      try { spth = Float.parseFloat(thresh.getText()); }      catch (Exception e) { spth = 0.5F; }      thresh.setText("" +spth); /* get the threshold value */      fmt = fmtnames[fmt_in.getSelectedIndex()];      this.miner.setInput(fmt, fn_in.getText(), spth,                          invert.isSelected());      if (kekule.isSelected())  /* set the input data set and */        this.miner.aromatize(); /* convert Kekul\'e representations */      fmt = fmtnames[fmt_out.getSelectedIndex()];      this.miner.setOutput(fmt, fn_sub.getText(), fn_ids.getText());      mode = Miner.BONDEXT;     /* set default search mode */      if (exttype.getSelectedIndex() > 0) mode |= Miner.RIGHTEXT;      if (chains.isSelected())            mode |= Miner.CHAINEXT;      if (canonic.isSelected())           mode |= Miner.PR_CANONIC;      if (equiv.isSelected())             mode |= Miner.PR_EQUIV;      if (normal.isSelected())            mode |= Miner.NORMFORM;      if (verbose.isSelected())           mode |= Miner.VERBOSE;      switch (perfect.getSelectedIndex()) {        case 0: mode |= Miner.PR_PERFECT; break;        case 1: mode |= Miner.PR_PARTIAL; break;      }                         /* set pruning and other flags */      try { supp = Float.parseFloat(minsupp.getText()); }      catch (Exception e) { supp = 10.0F; }      minsupp.setText(""+supp); /* get minimal support in focus */      try { comp = Float.parseFloat(maxsupp.getText()); }      catch (Exception e) { supp = 2.0F; }      maxsupp.setText(""+comp); /* get maximal support in complement */      if (supp >= 0) supp *= 0.01F;  /* change support values from */      if (comp >= 0) comp *= 0.01F;  /* percentages to fractions */      min = ((Integer)minsize.getValue()).intValue();      max = ((Integer)maxsize.getValue()).intValue();      if (!rings.isSelected())  /* if not to distinguish ring bonds, */        rgmin = rgmax = 0;      /* clear the range of ring sizes */      else {                    /* if to distinguish ring bonds */        switch (ringext.getSelectedIndex()) {          case 1: mode |= Miner.RINGEXT;                     break;          case 2: mode |= Miner.CLOSERINGS|Miner.PR_UNCLOSE; break;          case 3: mode |= Miner.RINGEXT   |Miner.MERGERINGS                       |  Miner.CLOSERINGS|Miner.PR_UNCLOSE; break;        }                       /* set ring extension flags */        rgmin = ((Integer)minring.getValue()).intValue();        rgmax = ((Integer)maxring.getValue()).intValue();      }                         /* get ring sizes */      this.miner.setParams(mode, supp, comp, min, max, rgmin, rgmax);      matom = mrgat = Atom.TYPEMASK; /* set default masks */      mbond = mrgbd = Bond.TYPEMASK|Bond.RINGBOND;      switch (bdarom.getSelectedIndex()) {        case 1: mbond &= Bond.DOWNGRADE;                mrgbd &= Bond.DOWNGRADE; break;        case 2: mbond &= Bond.UPGRADE;                mrgbd &= Bond.UPGRADE;   break;      }                         /* treatment of aromatic bonds */      switch (bdtype.getSelectedIndex()) {        case 1: mrgbd &= ~Bond.TYPEMASK; break;        case 2: mbond &= ~Bond.TYPEMASK;                mrgbd &= ~Bond.TYPEMASK; break;      }                         /* where to ignore the bond type */      switch (attype.getSelectedIndex()) {        case 1: mrgat &= ~Atom.TYPEMASK; break;        case 2: matom &= ~Atom.TYPEMASK;                mrgat &= ~Atom.TYPEMASK; break;      }                         /* where to ignore the atom type */      if (charge.isSelected()) matom |= Atom.CHARGEMASK;      if (atarom.isSelected()) matom |= Atom.AROMATIC;      this.miner.setMasks(matom, mbond, mrgat, mrgbd);      this.miner.setMaxEmbs(((Integer)maxemb.getValue()).intValue()); }    catch (IOException ioe) {   /* check successful initialization */      System.out.println("\nerror: " +ioe.getMessage());      JOptionPane.showMessageDialog(this,        "Initialization failed:\n" +ioe.getMessage(),        "Error", JOptionPane.ERROR_MESSAGE);      this.exec.setText("Run"); /* reset the button text */      this.running = false;     /* if the initialization failed, */      this.miner   = null;      /* show an error message, */      return;                   /* set the status to not running, */    }                           /* and "delete" the miner */    this.thread = new Thread(this.miner);    this.thread.start();        /* start computations as a thread */    this.timer = new Timer(200, new ActionListener () {      private int cnt = 0;      /* counter for status text update */      public void actionPerformed (ActionEvent e) {        if (!MoSS.this.thread.isAlive()) {          MoSS.this.timer.stop(); MoSS.this.result();          return;               /* stop the status update timer */        }                       /* and show the computation result */        if (--this.cnt <= 0) {  /* on every 5th check (once a second) */          this.cnt = 5; MoSS.this.update(); }      } } );                    /* update the status text */    this.timer.start();         /* start the status update timer */  }  /* execute() */  /*------------------------------------------------------------------*/  public void stateChanged (ChangeEvent e)  {                             /* --- handle change of checkbox */    boolean state = this.rings.isSelected();    this.minring.setEnabled(state);    this.maxring.setEnabled(state);    this.ringext.setEnabled(state);    for (int i = 3; --i >= 0; )      this.labels[i].setEnabled(state);  }  /* stateChanged() */  /*------------------------------------------------------------------*/  public void run ()  {                             /* --- create toolbox dialog */    GridBagLayout      g  = new GridBagLayout();    GridBagConstraints lc = new GridBagConstraints();    GridBagConstraints rc = new GridBagConstraints();    JPanel             grid;    JPanel             bbar;    JLabel             lbl;    JTextArea          help;    JButton            btn;    this.tab = new JTabbedPane(JTabbedPane.TOP,                               JTabbedPane.SCROLL_TAB_LAYOUT);    lc.fill      =              /* fill fields in both directions */    rc.fill      = GridBagConstraints.HORIZONTAL;    rc.weightx   = 1.0;         /* resize only the input fields, */    lc.weightx   = 0.0;         /* but not the labels */    lc.ipadx     = 10;          /* gap between labels and inputs */    lc.ipady     = 10;          /* make all lines of the same height */    rc.gridwidth = GridBagConstraints.REMAINDER;    /* --- files and formats --- */    grid = new JPanel(g);    grid.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));    tab.addTab("Formats and Files", null, grid, null);    lbl = new JLabel("Molecule input format:");    g.setConstraints(lbl, lc);         grid.add(lbl);    fmt_in = new JComboBox(fmtnames);  fmt_in.setFont(font);    g.setConstraints(fmt_in, rc);      grid.add(fmt_in);     lbl = new JLabel("Substructure output format:       ");    g.setConstraints(lbl, lc);         grid.add(lbl);    fmt_out = new JComboBox(fmtnames); fmt_out.setFont(font);    g.setConstraints(fmt_out, rc);     grid.add(fmt_out);     lbl = new JLabel("Seed format:");    g.setConstraints(lbl, lc);          grid.add(lbl);    fmt_seed = new JComboBox(fmtnames); fmt_seed.setFont(font);    g.setConstraints(fmt_seed, rc);     grid.add(fmt_seed);     lbl   = new JLabel("Input data file:");    g.setConstraints(lbl,   lc); grid.add(lbl);    btn   = new JButton("Browse...");    g.setConstraints(btn,   rc); grid.add(btn);    fn_in = new JTextField("moss.dat");    g.setConstraints(fn_in, rc); grid.add(fn_in);    btn.addActionListener(new AbstractAction () {      public void actionPerformed (ActionEvent e) {        if (chooser == null) chooser = createChooser();        chooser.setDialogType(JFileChooser.OPEN_DIALOG);        chooser.setDialogTitle("Choose Input Data File");        int r = chooser.showDialog(MoSS.this, null);        if (r == JFileChooser.APPROVE_OPTION)          fn_in.setText(chooser.getSelectedFile().getPath());      } } );    lbl    = new JLabel("Substructure output file:");    g.setConstraints(lbl,   lc); grid.add(lbl);    btn    = new JButton("Browse...");    g.setConstraints(btn,   rc); grid.add(btn);    fn_sub = new JTextField("moss.sub");    g.setConstraints(fn_sub, rc); grid.add(fn_sub);    btn.addActionListener(new AbstractAction () {      public void actionPerformed (ActionEvent e) {        if (chooser == null) chooser = createChooser();        chooser.setDialogType(JFileChooser.OPEN_DIALOG);        chooser.setDialogTitle("Choose Substructure Output File");        int r = chooser.showDialog(MoSS.this, null);        if (r == JFileChooser.APPROVE_OPTION)          fn_sub.setText(chooser.getSelectedFile().getPath());      } } );    lbl    = new JLabel("Molecule identifier output file:");    g.setConstraints(lbl,   lc); grid.add(lbl);    btn    = new JButton("Browse...");    g.setConstraints(btn,   rc); grid.add(btn);    fn_ids = new JTextField("");    g.setConstraints(fn_ids, rc); grid.add(fn_ids);    btn.addActionListener(new AbstractAction () {      public void actionPerformed (ActionEvent e) {        if (chooser == null) chooser = createChooser();        chooser.setDialogType(JFileChooser.OPEN_DIALOG);        chooser.setDialogTitle("Choose Molecule Identifier File");        int r = chooser.showDialog(MoSS.this, null);        if (r == JFileChooser.APPROVE_OPTION)          fn_ids.setText(chooser.getSelectedFile().getPath());      } } );    lbl = new JLabel("Seed description:");    g.setConstraints(lbl, rc);          grid.add(lbl);    seed = new JTextField("*");         seed.setFont(font);    g.setConstraints(seed, rc);         grid.add(seed);    help = new JTextArea(       "The seed is a substructure from which to start the search.\n"      +"A star (*) represents an empty seed (no restriction).");    help.setFont(small);    help.setBackground(this.getBackground());    g.setConstraints(help, rc); grid.add(help);    help = new JTextArea((String)null);    help.setFont(small);    help.setBackground(this.getBackground());    help.setPreferredSize(new Dimension(0,0));    rc.weighty = 1.0;    g.setConstraints(help, rc); grid.add(help);    rc.weighty = 0.0;    /* --- basic parameters --- */    grid = new JPanel(g);    grid.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));    tab.addTab("Basic Parameters", null, grid, null);    lbl = new JLabel("Threshold for split:");    g.setConstraints(lbl, lc);          grid.add(lbl);    thresh = new JTextField("0.5");     thresh.setFont(font);    g.setConstraints(thresh, rc);       grid.add(thresh);    lbl = new JLabel("Invert split:");    g.setConstraints(lbl, lc);          grid.add(lbl);    invert = new JCheckBox("", false);    g.setConstraints(invert, rc);       grid.add(invert);    help = new JTextArea(       "The molecules in the input file are split "      +"into a focus set and\nits complement. "      +"By default molecules with a value less than\n"      +"or equal to the threshold are in the focus, "      +"all other molecules\nare in the complement. "      +"If the split is inverted, focus set and\n"      +"complement are exchanged.");    help.setFont(small);    help.setBackground(this.getBackground());    g.setConstraints(help, rc); grid.add(help);    lbl = new JLabel("Minimal support in focus:");    g.setConstraints(lbl, lc);          grid.add(lbl);    minsupp = new JTextField("10.0");   minsupp.setFont(font);    g.setConstraints(minsupp, rc);      grid.add(minsupp);    lbl = new JLabel("Maximal support in complement:");    g.setConstraints(lbl, lc);          grid.add(lbl);    maxsupp = new JTextField("2.0");    maxsupp.setFont(font);    g.setConstraints(maxsupp, rc);      grid.add(maxsupp);    help = new JTextArea(       "The support of a substructure is measured "      +"in percent of the\nsize (number of molecules) "      +"of the corresponding subset.");    help.setFont(small);    help.setBackground(this.getBackground());    g.setConstraints(help, rc); grid.add(help);    lbl = new JLabel("Minimal substructure size:");    g.setConstraints(lbl, lc);          grid.add(lbl);    minsize = new JSpinner(new SpinnerNumberModel(1, 1, 999999, 1));    g.setConstraints(minsize, rc);      grid.add(minsize);    lbl = new JLabel("Maximal substructure size:");    g.setConstraints(lbl, lc);          grid.add(lbl);    maxsize = new JSpinner(new SpinnerNumberModel(0, 0, 999999, 1));    g.setConstraints(maxsize, rc);      grid.add(maxsize);    help = new JTextArea(       "The size of a substructure is measured "      +"as the number of atoms.\n"      +"A maximal size of zero means "      +"that there is no size limit.");    help.setFont(small);    help.setBackground(this.getBackground());    g.setConstraints(help, rc); grid.add(help);    help = new JTextArea((String)null);    help.setFont(small);    help.setBackground(this.getBackground());    help.setPreferredSize(new Dimension(0,0));    rc.weighty = 1.0;    g.setConstraints(help, rc); grid.add(help);    rc.weighty = 0.0;    /* --- matching --- */    grid = new JPanel(g);    grid.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));    tab.addTab("Matching", null, grid, null);    lbl = new JLabel("Aromatic bonds:");    g.setConstraints(lbl, lc);         grid.add(lbl);    bdarom = new JComboBox(aromnames); bdarom.setFont(font);    g.setConstraints(bdarom, rc);      grid.add(bdarom);     help = new JTextArea(       "Downgrading aromatic bonds means treating them as single,\n"      +"upgrading means treating them as double bonds.");    help.setFont(small);    help.setBackground(this.getBackground());    g.setConstraints(help, rc); grid.add(help);    lbl = new JLabel("Ignore type of bonds:");    g.setConstraints(lbl, lc);         grid.add(lbl);    bdtype = new JComboBox(typenames);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -