📄 moss.java
字号:
/*---------------------------------------------------------------------- File : MoSS.java Contents: graphical user interface for the MoSS program Author : Christian Borgelt History : 13.07.2006 file created from file PGView.java 18.07.2006 first version completed 09.08.2006 ignoring the atom type only in rings added 12.08.2006 adapted to new Notation classes 13.08.2006 atom types to exclude as seeds added----------------------------------------------------------------------*/package moss;import java.awt.BorderLayout;import java.awt.Component;import java.awt.Dimension;import java.awt.EventQueue;import java.awt.Font;import java.awt.GridBagConstraints;import java.awt.GridBagLayout;import java.awt.GridLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.io.BufferedReader;import java.io.File;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.IOException;import java.io.InputStreamReader;import java.io.PrintStream;import java.util.StringTokenizer;import javax.swing.AbstractAction;import javax.swing.BorderFactory;import javax.swing.JButton;import javax.swing.JCheckBox;import javax.swing.JComboBox;import javax.swing.JFileChooser;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JSpinner;import javax.swing.JTabbedPane;import javax.swing.JTextArea;import javax.swing.JTextField;import javax.swing.SpinnerNumberModel;import javax.swing.Timer;import javax.swing.event.ChangeEvent;import javax.swing.event.ChangeListener;/*--------------------------------------------------------------------*/public class MoSS extends JFrame implements Runnable, ChangeListener {/*--------------------------------------------------------------------*/ private static final String[] fmtnames = { "SMILES", "SLN" }; private static final String[] extnames = { "maximum source", "rightmost path" }; private static final String[] aromnames = { "extra type", "downgrade", "upgrade" }; private static final String[] typenames = { "never", "in rings", "always" }; private static final String[] pepnames = { "full", "partial", "none" }; private static final String[] ringnames = { "none", "full", "filter", "merge" }; /* --- fonts --- */ private static final Font font = new Font("Dialog", Font.BOLD, 12); private static final Font small = new Font("Dialog", Font.PLAIN, 10); /* --- files and format --- */ private JComboBox fmt_in; /* input format for molecules */ private JComboBox fmt_out; /* output format for substructures */ private JComboBox fmt_seed; /* seed format */ private JTextField fn_in; /* name of input file */ private JTextField fn_sub; /* name of substructure output file */ private JTextField fn_ids; /* name of molecule identifier file */ private JTextField seed; /* seed structure to start from */ /* --- basic parameters --- */ private JTextField thresh; /* threshold for split */ private JCheckBox invert; /* whether to invert the split */ private JTextField minsupp; /* minimal support in focus */ private JTextField maxsupp; /* maximal support in complement */ private JSpinner minsize; /* minimal size of a substructure */ private JSpinner maxsize; /* maximal size of a substructure */ /* --- matching --- */ private JComboBox bdarom; /* treatment of aromatic bonds */ private JComboBox bdtype; /* ignore the bond type */ private JComboBox attype; /* ignore the atom type */ private JCheckBox charge; /* match the atom charge */ private JCheckBox atarom; /* match the atom aromaticity */ private JTextField excl; /* excluded atom types */ private JTextField exseed; /* excluded atom types for seeds */ /* --- rings and chains --- */ private JCheckBox kekule; /* convert Kekule representations */ private JCheckBox rings; /* whether to mark rings */ private JSpinner minring; /* minimal size of a ring */ private JSpinner maxring; /* maximal size of a ring */ private JComboBox ringext; /* type of ring extensions */ private JCheckBox chains; /* variable length carbon chains */ private JLabel[] labels; /* labels that can be disabled */ /* --- miscellaneous --- */ private JComboBox exttype; /* extension type */ private JComboBox perfect; /* perfect extension pruning */ private JCheckBox equiv; /* equivalent sibling pruning */ private JCheckBox canonic; /* canonical form pruning */ private JSpinner maxemb; /* maximal embeddings */ private JCheckBox normal; /* normalize the output */ private JCheckBox verbose; /* verbose message output */ /* --- window and status line --- */ private JTabbedPane tab; /* pane for parameter tabs */ private JButton exec; /* execute/abort button */ private JTextField stat; /* status line */ /* --- other variables --- */ private Component owner = null; private boolean isprog = false; private JFileChooser chooser = null; private Thread thread = null; private Timer timer = null; private boolean running = false; private boolean stopped = true; private Miner miner = null; private long start; /*------------------------------------------------------------------*/ private JFileChooser createChooser () { /* --- create a file chooser */ JFileChooser fc = new JFileChooser(); fc.setFileSelectionMode(JFileChooser.FILES_ONLY); fc.setCurrentDirectory(new File(".")); fc.setFileHidingEnabled(true); fc.setAcceptAllFileFilterUsed(true); fc.setMultiSelectionEnabled(false); fc.setFileView(null); /* create a standard file chooser */ return fc; /* without customized filters */ } /* createChooser() */ /*------------------------------------------------------------------*/ private static String readLine (BufferedReader rdr) throws IOException { /* --- read a line of config. file */ String line = rdr.readLine(); if (line == null) throw new IOException("premature end of file"); return line; /* read and check next line */ } /* readLine() */ /*------------------------------------------------------------------*/ private static int getInt (StringTokenizer tok) throws IOException { /* --- get next integer value */ if (!tok.hasMoreTokens()) /* check for another field */ throw new IOException("too few fields in last line"); try { return Integer.parseInt(tok.nextToken()); } catch (Exception e) { return 0; } } /* getInt() */ /* decode and return the next field */ /*------------------------------------------------------------------*/ private void loadConfig (File file) { /* --- load configuration */ FileInputStream in; /* the configuration file */ BufferedReader rdr; /* reader for the configuration file */ StringTokenizer tok; /* tokenizer for the last line */ try { /* open the configuration file */ in = new FileInputStream(file); rdr = new BufferedReader(new InputStreamReader(in)); fn_in.setText (MoSS.readLine(rdr)); fn_sub.setText (MoSS.readLine(rdr)); fn_ids.setText (MoSS.readLine(rdr)); seed.setText (MoSS.readLine(rdr)); excl.setText (MoSS.readLine(rdr)); exseed.setText (MoSS.readLine(rdr)); thresh.setText (MoSS.readLine(rdr)); minsupp.setText(MoSS.readLine(rdr)); maxsupp.setText(MoSS.readLine(rdr)); tok = new StringTokenizer(MoSS.readLine(rdr), ","); minsize.setValue(new Integer(MoSS.getInt(tok))); maxsize.setValue(new Integer(MoSS.getInt(tok))); minring.setValue(new Integer(MoSS.getInt(tok))); maxring.setValue(new Integer(MoSS.getInt(tok))); maxemb.setValue (new Integer(MoSS.getInt(tok))); fmt_in.setSelectedIndex (MoSS.getInt(tok)); fmt_out.setSelectedIndex (MoSS.getInt(tok)); fmt_seed.setSelectedIndex(MoSS.getInt(tok)); bdarom.setSelectedIndex (MoSS.getInt(tok)); bdtype.setSelectedIndex (MoSS.getInt(tok)); attype.setSelectedIndex (MoSS.getInt(tok)); ringext.setSelectedIndex (MoSS.getInt(tok)); exttype.setSelectedIndex (MoSS.getInt(tok)); perfect.setSelectedIndex (MoSS.getInt(tok)); rings.setSelected (MoSS.getInt(tok) != 0); invert.setSelected (MoSS.getInt(tok) != 0); charge.setSelected (MoSS.getInt(tok) != 0); atarom.setSelected (MoSS.getInt(tok) != 0); kekule.setSelected (MoSS.getInt(tok) != 0); chains.setSelected (MoSS.getInt(tok) != 0); equiv.setSelected (MoSS.getInt(tok) != 0); canonic.setSelected(MoSS.getInt(tok) != 0); normal.setSelected (MoSS.getInt(tok) != 0); verbose.setSelected(MoSS.getInt(tok) != 0); this.stat.setText("configuration loaded: " +file.getName()); } catch (IOException ioe) { /* read the configuration values */ JOptionPane.showMessageDialog(this, "Error reading configuration file:\n" +ioe.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); } /* check for successful reading */ this.stateChanged(null); /* adapt state of rings tab */ } /* loadConfig() */ /*------------------------------------------------------------------*/ private void saveConfig (File file) { /* --- save configuration */ PrintStream s = null; /* to write the configuration file */ try { /* open the configuration file */ s = new PrintStream(new FileOutputStream(file)); s.println(fn_in.getText()); s.println(fn_sub.getText()); s.println(fn_ids.getText()); s.println(seed.getText()); s.println(excl.getText()); s.println(exseed.getText()); s.println(thresh.getText()); s.println(minsupp.getText()); s.println(maxsupp.getText()); s.print(((Integer)minsize.getValue()).intValue() +","); s.print(((Integer)maxsize.getValue()).intValue() +","); s.print(((Integer)minring.getValue()).intValue() +","); s.print(((Integer)maxring.getValue()).intValue() +","); s.print(((Integer)maxemb.getValue()).intValue() +","); s.print(fmt_in.getSelectedIndex() +","); s.print(fmt_out.getSelectedIndex() +","); s.print(fmt_seed.getSelectedIndex() +","); s.print(bdarom.getSelectedIndex() +","); s.print(bdtype.getSelectedIndex() +","); s.print(attype.getSelectedIndex() +","); s.print(ringext.getSelectedIndex() +","); s.print(exttype.getSelectedIndex() +","); s.print(perfect.getSelectedIndex() +","); s.print(rings.isSelected() ? "1," : "0,"); s.print(invert.isSelected() ? "1," : "0,"); s.print(charge.isSelected() ? "1," : "0,"); s.print(atarom.isSelected() ? "1," : "0,"); s.print(kekule.isSelected() ? "1," : "0,"); s.print(chains.isSelected() ? "1," : "0,"); s.print(equiv.isSelected() ? "1," : "0,"); s.print(canonic.isSelected() ? "1," : "0,"); s.print(normal.isSelected() ? "1," : "0,"); s.println(verbose.isSelected() ? "1" : "0"); } catch (IOException ioe) { /* write the configuration values */ JOptionPane.showMessageDialog(this, "Error writing configuration file:\n" +ioe.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); } /* check for successful writing */ if (s != null) s.close(); /* close the configuration file */ this.stat.setText("configuration saved: " +file.getName()); } /* saveConfig() */ /*------------------------------------------------------------------*/ private void result () { /* --- show result of computation */ int n; /* number of found substructures */ float t; /* execution time */ this.running = false; /* thread is no longer running */ this.exec.setText("Run"); /* reset the button text */ if (this.stopped) { /* if execution has been aborted */ this.miner = null; /* "delete" the miner */ this.stat.setText("substructure search aborted."); JOptionPane.showMessageDialog(this, "Substructure search aborted.", "Information", JOptionPane.INFORMATION_MESSAGE); return; /* show an abortion dialog */ } /* and abort the function */ this.miner.stats(); /* show search statistics */ n = this.miner.getCurrent(); t = (System.currentTimeMillis() -this.start) / 1000.0F; this.stat.setText(n +" substructure(s), " +"total search time: " +t +"s"); JOptionPane.showMessageDialog(this, "Found " +n +" substructure(s).\nTotal search time: " +t +"s.\n" +"(See terminal for more information.)", "Information", JOptionPane.INFORMATION_MESSAGE); this.miner = null; /* show a success message */ } /* result() */ /* and "delete" the miner */ /*------------------------------------------------------------------*/ private void update () { /* --- update the status text */ if (!this.running) return; /* check for a running search */ this.stat.setText(" searching ... " +this.miner.getCurrent() +" substructure(s)"); } /* update() */ /* display search statistics */ /*------------------------------------------------------------------*/ public void execute () { /* --- execute substructure search */ int mode; /* search mode */ String fmt; /* input/output format */ float spth = 0; /* threshold for split */ float supp = 0, comp = 0; /* support in focus and complement */ int matom, mbond; /* atom and bond masks outside rings */ int mrgat, mrgbd; /* atom and bond masks inside rings */ int min, max; /* minimum and maximum fragment size */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -