Revision: 21346 http://sourceforge.net/p/jmol/code/21346 Author: hansonr Date: 2017-01-25 20:52:14 +0000 (Wed, 25 Jan 2017) Log Message: ----------- adding NBOPlugin and JmolPlugin
Modified Paths: -------------- trunk/Jmol/src/org/gennbo/NBODialog.java trunk/Jmol/src/org/gennbo/NBODialogConfig.java trunk/Jmol/src/org/gennbo/NBODialogRun.java trunk/Jmol/src/org/gennbo/NBODialogSearch.java trunk/Jmol/src/org/gennbo/NBODialogView.java trunk/Jmol/src/org/gennbo/NBOFileHandler.java trunk/Jmol/src/org/gennbo/NBOService.java trunk/Jmol/src/org/openscience/jmol/app/jmolpanel/JmolPanel.java trunk/Jmol/src/org/openscience/jmol/app/jmolpanel/StatusListener.java Added Paths: ----------- trunk/Jmol/src/org/gennbo/NBOPlugin.java trunk/Jmol/src/org/openscience/jmol/app/JmolPlugin.java Modified: trunk/Jmol/src/org/gennbo/NBODialog.java =================================================================== --- trunk/Jmol/src/org/gennbo/NBODialog.java 2017-01-25 18:12:49 UTC (rev 21345) +++ trunk/Jmol/src/org/gennbo/NBODialog.java 2017-01-25 20:52:14 UTC (rev 21346) @@ -45,7 +45,6 @@ import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; -import java.net.URL; import javajs.swing.SwingConstants; import javajs.util.PT; @@ -109,8 +108,6 @@ private JPanel topPanel; protected JButton modelButton, runButton, viewButton, searchButton; - protected JPanel settingsPanel; - private JPanel homePanel; boolean isJmolNBO; @@ -119,6 +116,8 @@ protected JLabel statusLab; protected JPanel nboOutput; + + private NBOPlugin nboPlugin; static final char DIALOG_CONFIG = 'c'; static final char DIALOG_MODEL = 'm'; @@ -137,19 +136,20 @@ * @param vwr * The interacting display we are reproducing (source of view angle * info etc) + * @param plugin */ - public NBODialog(JFrame jmolFrame, Viewer vwr) { + public NBODialog(NBOPlugin plugin, JFrame jmolFrame, Viewer vwr) { super(jmolFrame); - setTitle("NBOPro6@Jmol"); + setTitle("NBOPro6@Jmol " + plugin.getVersion()); + nboPlugin = plugin; this.vwr = vwr; - this.nboService = new NBOService(vwr); + this.nboService = new NBOService(this, vwr); this.setIconImage(getIcon("nbo6logo20x20").getImage()); this.setLayout(new BorderLayout()); sendDefaultScript(); + //get saved properties - nboService.nboDialog = this; - createDialog(jmolFrame.getBounds()); } @@ -171,14 +171,10 @@ addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { - //TODO -// nboService.manager.clearQueue(); -// //nboService.manager. -// nboService.closeProcess(); + nboService.closeProcess(); close(); } }); - //final NBODialog dialog = this; placeNBODialog(this); helpBtn = new HelpBtn(""){ @@ -225,11 +221,12 @@ //centerPanel.setLeftComponent(mainPage()); this.dialogMode = DIALOG_HOME; this.getContentPane().add(topPanel,BorderLayout.NORTH); - settingsPanel = buildSettingsPanel(); settingsDialog = new JDialog(this,"Settings"); - settingsDialog.add(settingsPanel); settingsDialog.setSize(new Dimension(350,400)); settingsDialog.setLocation(this.getX() + 100,this.getY()+100); + settingsPanel = new JPanel(); + buildSettingsPanel(settingsPanel); + settingsDialog.add(settingsPanel); this.setVisible(true); if (nboService.isOffLine()) settingsDialog.setVisible(true); @@ -643,7 +640,7 @@ runScriptNow("mo delete; nbo delete; select off"); break; } - nboService.jobQueue.clear(); + nboService.clearQueue(); nboService.isWorking = false; this.settingsBox.setVisible(false); if (!checkEnabled()) @@ -840,5 +837,4 @@ else loadModelFileQueued(file, false, false); } - } Modified: trunk/Jmol/src/org/gennbo/NBODialogConfig.java =================================================================== --- trunk/Jmol/src/org/gennbo/NBODialogConfig.java 2017-01-25 18:12:49 UTC (rev 21345) +++ trunk/Jmol/src/org/gennbo/NBODialogConfig.java 2017-01-25 20:52:14 UTC (rev 21346) @@ -33,10 +33,7 @@ import java.awt.Rectangle; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import java.io.BufferedReader; import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileReader; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; @@ -64,7 +61,6 @@ import javax.swing.ListCellRenderer; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; -import javax.swing.filechooser.FileNameExtensionFilter; import javax.swing.plaf.basic.BasicComboPopup; import javax.swing.plaf.basic.ComboPopup; import javax.swing.plaf.metal.MetalComboBoxUI; @@ -111,7 +107,11 @@ protected JTextPane jpNBOLog; protected JSlider opacity = new JSlider(); + protected JPanel settingsPanel; + protected JComboBox<Color> colorBox1, colorBox2; + protected JCheckBox jCheckAtomNum, jCheckSelHalo, jCheckDebugVerbose, jCheckNboView, jCheckWireMesh; + protected String bodyText = ""; protected boolean showAtNum, nboView, useWireMesh; @@ -149,22 +149,33 @@ /** * Creates a dialog for getting info related to output frames in nbo format. + * @param settingsPanel * * @return settings panel */ @SuppressWarnings("unchecked") - protected JPanel buildSettingsPanel() { + protected JPanel buildSettingsPanel(JPanel settingsPanel) { + settingsPanel.removeAll(); checkNBOStatus(); String viewOpts = getOrbitalDisplayOptions(); - JPanel filePanel = new JPanel(); - filePanel.setLayout(new BoxLayout(filePanel, BoxLayout.Y_AXIS)); - addPathSetting(filePanel, MODE_PATH_SERVICE); - addPathSetting(filePanel, MODE_PATH_WORKING); + settingsPanel.setLayout(new BoxLayout(settingsPanel, BoxLayout.Y_AXIS)); + addPathSetting(settingsPanel, MODE_PATH_SERVICE); + addPathSetting(settingsPanel, MODE_PATH_WORKING); //Settings - filePanel.add(createTitleBox(" Settings ", null)); - JCheckBox jCheckAtomNum = new JCheckBox("Show Atom Numbers");//.setAlignmentX(0.5f); + + JButton jbDefaults = new JButton("Set Defaults"); + jbDefaults.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + setDefaults(); + } + + }); + settingsPanel.add(createTitleBox(" Settings ", jbDefaults)); + jCheckAtomNum = new JCheckBox("Show Atom Numbers");//.setAlignmentX(0.5f); jCheckAtomNum.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { @@ -176,22 +187,18 @@ jCheckAtomNum.setSelected(true); Box settingsBox = createBorderBox(true); settingsBox.add(jCheckAtomNum); - - JCheckBox jCheckSelHalo = new JCheckBox("Show selection halos on atoms"); + + jCheckSelHalo = new JCheckBox("Show selection halos on atoms"); jCheckSelHalo.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - runScriptNow("select " + ((JCheckBox) e.getSource()).isSelected()); + runScriptNow("select " + jCheckSelHalo.isSelected()); } }); jCheckSelHalo.doClick(); settingsBox.add(jCheckSelHalo); - color1 = "[" + orbColor1.getRed() + " " + orbColor1.getGreen() + " " - + orbColor1.getBlue() + "]"; - color2 = "[" + orbColor2.getRed() + " " + orbColor2.getGreen() + " " - + orbColor2.getBlue() + "]"; - final JCheckBox jCheckWireMesh = new JCheckBox( + jCheckWireMesh = new JCheckBox( "Use wire mesh for orbital display"); settingsBox.add(jCheckWireMesh); @@ -199,8 +206,9 @@ Color.cyan, Color.blue, Color.magenta, }; JPanel displayOps = new JPanel(new GridLayout(1, 4)); - displayOps.add(new JLabel("(+) color: ")); - final JComboBox<Color> colorBox1 = new JComboBox<Color>(colors); + JLabel label = new JLabel(" (+) color: "); + displayOps.add(label); + colorBox1 = new JComboBox<Color>(colors); colorBox1.setRenderer(new ColorRenderer()); colorBox1.setSelectedItem(orbColor1); displayOps.add(colorBox1); @@ -208,20 +216,16 @@ @Override public void actionPerformed(ActionEvent e) { orbColor1 = ((Color) colorBox1.getSelectedItem()); - color1 = "[" + orbColor1.getRed() + " " + orbColor1.getGreen() + " " - + orbColor1.getBlue() + "]"; setOrbitalDisplayOptions(); } }); - displayOps.add(new JLabel(" (-) color: ")); - final JComboBox<Color> colorBox2 = new JComboBox<Color>(colors); + displayOps.add(new JLabel(" (-) color: ")); + colorBox2 = new JComboBox<Color>(colors); colorBox2.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { orbColor2 = ((Color) colorBox2.getSelectedItem()); - color2 = "[" + orbColor2.getRed() + " " + orbColor2.getGreen() + " " - + orbColor2.getBlue() + "]"; setOrbitalDisplayOptions(); } }); @@ -266,7 +270,8 @@ }); if (useWireMesh) jCheckWireMesh.setSelected(true); - JCheckBox jCheckNboView = new JCheckBox("Emulate NBO View"); + + jCheckNboView = new JCheckBox("Emulate NBO View"); settingsBox.add(jCheckNboView); jCheckNboView.addActionListener(new ActionListener() { @Override @@ -278,14 +283,15 @@ if (jCheckWireMesh.isSelected()) jCheckWireMesh.doClick(); opacity.setValue(3); - } else - resetColorScheme(); - + } else { + setDefaults(); + runScriptNow("background black;set defaultcolors Jmol;refresh;"); + } } }); - JCheckBox jb = new JCheckBox("Verbose Debugging"); - settingsBox.add(jb); - jb.addActionListener(new ActionListener() { + jCheckDebugVerbose = new JCheckBox("Verbose Debugging"); + settingsBox.add(jCheckDebugVerbose); + jCheckDebugVerbose.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { debugVerbose = ((JCheckBox) e.getSource()).isSelected(); @@ -297,11 +303,35 @@ opacity.setValue((int) (opacityOp * 10)); } settingsBox.setBorder(BorderFactory.createLineBorder(Color.black)); - filePanel.add(settingsBox); - return filePanel; + settingsPanel.add(settingsBox); + return settingsPanel; } + protected void setDefaults() { + + nboService.setNBOProperty("orbitalDisplayOptions", "default"); + getOrbitalDisplayOptions(); + opacity.setValue((int) (opacityOp * 10)); + colorBox1.setSelectedItem(orbColor1); + colorBox2.setSelectedItem(orbColor2); + + jCheckWireMesh.setSelected(useWireMesh); + //jCheckWireMesh.doClick(); + jCheckAtomNum.setSelected(true); + //jCheckAtomNum.doClick(); + jCheckSelHalo.setSelected(true); + //jCheckSelHalo.doClick(); + jCheckDebugVerbose.setSelected(false); + //jCheckDebugVerbose.doClick(); + jCheckNboView.setSelected(false); + //jCheckNboView.doClick(); + } + protected void setOrbitalDisplayOptions() { + color1 = "[" + orbColor1.getRed() + " " + orbColor1.getGreen() + " " + + orbColor1.getBlue() + "]"; + color2 = "[" + orbColor2.getRed() + " " + orbColor2.getGreen() + " " + + orbColor2.getBlue() + "]"; String script = "nbo color " + color2 + " " + color1 + ";mo color " + color2 + " " + color1 + ";"; script += (useWireMesh ? "nbo nofill mesh;mo nofill mesh" @@ -314,8 +344,8 @@ } private String getOrbitalDisplayOptions() { - String options = nboService.getNBOProperty("orbitalDisplayOptions", null); - if (options == null) { + String options = nboService.getNBOProperty("orbitalDisplayOptions", "default"); + if (options.equals("default")) { orbColor1 = Color.blue; orbColor2 = Color.red; opacityOp = 0; @@ -336,7 +366,7 @@ return options; } - private void addPathSetting(JPanel filePanel, final int mode) { + private void addPathSetting(JPanel panel, final int mode) { //GUI for NBO path selection String title = ""; String path = ""; @@ -359,11 +389,11 @@ } }); - filePanel.add(createTitleBox(title, null)); + panel.add(createTitleBox(title, null)); Box serverBox = createBorderBox(true); serverBox.add(createPathBox(tfPath, mode)); serverBox.setMaximumSize(new Dimension(350, 50)); - filePanel.add(serverBox); + panel.add(serverBox); //Job files // @@ -499,25 +529,16 @@ * Sets color scheme to emulate look of NBO view */ protected void setNBOColorScheme() { - nboView = true; - String atomColors = ""; - String fname = "org/openscience/jmol/app/nbo/help/atomColors.txt"; try { - atomColors = GuiMap.getResourceString(this, fname); + String atomColors = ""; + atomColors = GuiMap.getResourceString(this, "org/gennbo/help/atomColors.txt"); + runScriptNow(atomColors + ";refresh"); + nboView = true; } catch (IOException e) { alertError("Atom colors not found"); } - runScriptNow(atomColors + ";refresh"); } - /** - * Resets Jmol look and feel - */ - protected void resetColorScheme() { - nboView = false; - runScriptNow("background black;set defaultcolors Jmol;refresh;"); - } - // /** // * sets components visible recursively // * @param c @@ -539,7 +560,7 @@ */ protected void showAtomNums(boolean alpha) { if (!showAtNum) { - runScriptNow("select {*};label off; select remove {*}"); + runScriptNow("select {*};label off; select none"); return; } SB sb = new SB(); @@ -550,7 +571,7 @@ sb.append("select {*};color labels white;"); sb.append("select {H*};color labels " + color + ";" - + "set labeloffset 0 0 {*}; select remove {*};"); + + "set labeloffset 0 0 {*}; select none;"); runScriptNow(sb.toString()); } @@ -617,8 +638,7 @@ * p, b, r ("red"), i, etc. */ protected synchronized void log(String line, char chFormat) { - if (line.trim().equals("") || jpNBOLog == null || !debugVerbose - && "b|r".indexOf("" + chFormat) < 0) + if (dontLog(line, chFormat)) return; if (line.trim().length() >= 1) { line = PT.rep(line.trim(), "<", "<"); @@ -640,6 +660,13 @@ jpNBOLog.setCaretPosition(jpNBOLog.getDocument().getLength()); } + private boolean dontLog(String line, char chFormat) { + return (jpNBOLog == null + || line.trim().equals("") + || line.indexOf("read/unit=5/attempt to read past end") >= 0 + || !debugVerbose && "b|r".indexOf("" + chFormat) < 0); + } + protected void alertError(String line) { log(line, 'r'); vwr.alert(line); Modified: trunk/Jmol/src/org/gennbo/NBODialogRun.java =================================================================== --- trunk/Jmol/src/org/gennbo/NBODialogRun.java 2017-01-25 18:12:49 UTC (rev 21345) +++ trunk/Jmol/src/org/gennbo/NBODialogRun.java 2017-01-25 20:52:14 UTC (rev 21346) @@ -331,6 +331,44 @@ // return true; // } + + /** + * gets a valid $CHOOSE list from nbo file if it exists and corrects the bonds + * in the Jmol model + * + * + * @return false if output contains error + */ + protected boolean getChooseList() { + File f = NBOFileHandler.newNBOFile(inputFileHandler.inputFile, "nbo"); + if (!f.exists() || f.length() == 0) + return false; + String fdata = inputFileHandler.getFileData(f.toString()); + String[] tokens = PT.split(fdata, "\n $CHOOSE"); + int i = 1; + if (tokens.length < 2) { + logInfo("$CHOOSE record was not found in " + f, + Logger.LEVEL_INFO); + return false; + } + if (tokens[1].trim().startsWith("keylist")) { + if (!tokens[1].contains("Structure accepted:")) { + if (tokens[1].contains("missing END?")) { + logInfo("Plot files not found. Have you used RUN yet?", + Logger.LEVEL_ERROR); + return false; + } else if (tokens[2].contains("ignoring")) { + System.out.println("Ignoring $CHOOSE list"); + } else { + return false; + } + } + i = 3; + } + setChooseList(tokens[i].substring(0, tokens[i].indexOf("$END"))); + return true; + } + protected void setChooseList(String data) { chooseList = new ChooseList(); String[] tokens = PT.split(data, "END"); @@ -652,15 +690,10 @@ fileData = inputFileHandler.read47File(); nboKeywords = cleanNBOKeylist(fileData[1]); - if (inputFileHandler.useExt.equals("47")) { - if (!inputFileHandler.getChooseList()) { - File f = NBOFileHandler.newNBOFile(inputFileHandler.inputFile, "nbo"); - if (f.exists()) - logInfo("Error reading $CHOOSE list", Logger.LEVEL_ERROR); - } else - setBonds(true); - } + if (inputFileHandler.useExt.equals("47")) + getChooseList(); showAtomNums(true); + setBonds(true); addNBOKeylist(); for (Component c : panel.getComponents()) c.setVisible(true); Modified: trunk/Jmol/src/org/gennbo/NBODialogSearch.java =================================================================== --- trunk/Jmol/src/org/gennbo/NBODialogSearch.java 2017-01-25 18:12:49 UTC (rev 21345) +++ trunk/Jmol/src/org/gennbo/NBODialogSearch.java 2017-01-25 20:52:14 UTC (rev 21346) @@ -1000,7 +1000,7 @@ if (list.equals(list3)) { changeKey(nrt); //Parsing RS list here ensures RS list will be in .nbo file - parseRsList(inputFileHandler.getRSList()); + parseRsList(getRSList()); unit.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { @@ -1046,6 +1046,29 @@ } } + protected String[] getRSList() { + String data = inputFileHandler.getInputFile("nbo"); + String[] toks = PT.split(data, + "TOPO matrix for the leading resonance structure:\n"); + if (toks.length < 2) { + if (toks[0].contains("0 candidate reference structure(s)")) + alertError("0 candidate reference structure(s) calculated by SR LEWIS" + + "Candidate reference structure taken from NBO search"); + return null; + } + String[] toks2 = PT + .split(toks[1], + "---------------------------------------------------------------------------"); + String[] rsList = new String[2]; + rsList[0] = toks2[0].substring(toks2[0].lastIndexOf('-'), + toks2[0].indexOf("Res")).trim(); + rsList[0] = rsList[0].replace("-\n", ""); + rsList[1] = toks2[1]; + return rsList; + } + + + /** * Takes two strings from .nbo file and parses RS list information toks[0] = * primary rs matrix toks[1] = change list using accountants notation @@ -1361,8 +1384,8 @@ alphaSpin.setVisible(false); betaSpin.setVisible(false); } - if (!inputFileHandler.getChooseList()) - alertError("Error reading $CHOOSE list"); + + getChooseList(); showAtomNums(true); setBonds(true); Modified: trunk/Jmol/src/org/gennbo/NBODialogView.java =================================================================== --- trunk/Jmol/src/org/gennbo/NBODialogView.java 2017-01-25 18:12:49 UTC (rev 21345) +++ trunk/Jmol/src/org/gennbo/NBODialogView.java 2017-01-25 20:52:14 UTC (rev 21346) @@ -481,6 +481,7 @@ protected void setOrbitalColors(char plusMinus) { currSign = plusMinus; + // just for one orbital? runScriptNow("nbo color " + (plusMinus == '+' ? color2 + " " + color1 : color1 + " " + color2)); } @@ -1427,10 +1428,7 @@ resetValues(); settingsBox.setVisible(true); - // for(int i = 0; i < 5; i++) - // panel.getComponents()[i].setVisible(true); - if (!inputFileHandler.getChooseList()) - logInfo("Error reading $CHOOSE list", Logger.LEVEL_ERROR); + getChooseList(); showAtomNums(true); colorMeshes(); alphaSpin.setVisible(isOpenShell); Modified: trunk/Jmol/src/org/gennbo/NBOFileHandler.java =================================================================== --- trunk/Jmol/src/org/gennbo/NBOFileHandler.java 2017-01-25 18:12:49 UTC (rev 21345) +++ trunk/Jmol/src/org/gennbo/NBOFileHandler.java 2017-01-25 20:52:14 UTC (rev 21346) @@ -153,6 +153,8 @@ //return false; if (dialog.dialogMode == NBODialog.DIALOG_MODEL) return true; + // DP? if(!inputFile.getAbsolutePath().endsWith(".47")) + // DP? inputFile = newNBOFile(inputFile, "47"); if (!useExt.equals("47")) { jobStem = NBOFileHandler.getJobStem(inputFile); dialog.loadModelFromNBO(fileDir, jobStem, useExt); @@ -287,67 +289,6 @@ return false; } - /** - * gets a valid $CHOOSE list from nbo file if it exists and corrects the bonds - * in the jmol model - * - * @return false if output contains error - */ - protected boolean getChooseList() { - File f = newNBOFile(inputFile, "nbo"); - if (!f.exists() || f.length() == 0) - return false; - String fdata = getFileData(f.toString()); - String[] tokens = PT.split(fdata, "\n $CHOOSE"); - int i = 1; - if (tokens.length < 2) { - dialog.logInfo("$CHOOSE record was not found in " + f, - Logger.LEVEL_INFO); - return false; - } - if (tokens[1].trim().startsWith("keylist")) { - if (!tokens[1].contains("Structure accepted:")) { - if (tokens[1].contains("missing END?")) { - dialog.logInfo("Plot files not found. Have you used RUN yet?", - Logger.LEVEL_ERROR); - return false; - } else if (tokens[2].contains("ignoring")) { - dialog.alert("Ignoring $CHOOSE list"); - } else { - return false; - } - } - i = 3; - } - String data = tokens[i].substring(0, tokens[i].indexOf("$END")); - - dialog.setChooseList(data); - - return true; - } - - protected String[] getRSList() { - String data = getFileData(newNBOFile(inputFile, "nbo").toString()); - String[] toks = PT.split(data, - "TOPO matrix for the leading resonance structure:\n"); - if (toks.length < 2) { - if (toks[0].contains("0 candidate reference structure(s)")) - dialog - .alertError("0 candidate reference structure(s) calculated by SR LEWIS" - + "Candidate reference structure taken from NBO search"); - return null; - } - String[] toks2 = PT - .split(toks[1], - "---------------------------------------------------------------------------"); - String[] rsList = new String[2]; - rsList[0] = toks2[0].substring(toks2[0].lastIndexOf('-'), - toks2[0].indexOf("Res")).trim(); - rsList[0] = rsList[0].replace("-\n", ""); - rsList[1] = toks2[1]; - return rsList; - } - public void clear() { tfName.setText(""); tfExt.setText(""); @@ -412,4 +353,8 @@ btnBrowse.setEnabled(b); } + public String getInputFile(String name) { + return getFileData(newNBOFile(inputFile, name).toString()); + } + } Added: trunk/Jmol/src/org/gennbo/NBOPlugin.java =================================================================== --- trunk/Jmol/src/org/gennbo/NBOPlugin.java (rev 0) +++ trunk/Jmol/src/org/gennbo/NBOPlugin.java 2017-01-25 20:52:14 UTC (rev 21346) @@ -0,0 +1,78 @@ +/* $RCSfile$ + * $Author: hansonr $ + * $Date: 2014-12-13 22:43:17 -0600 (Sat, 13 Dec 2014) $ + * $Revision: 20162 $ + * + * Copyright (C) 2002-2005 The Jmol Development Team + * + * Contact: jmol-develop...@lists.sf.net + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + */ +package org.gennbo; + +import javax.swing.JFrame; + +import org.jmol.c.CBK; +import org.jmol.viewer.Viewer; +import org.openscience.jmol.app.JmolPlugin; + +public class NBOPlugin implements JmolPlugin { + + protected NBODialog nboDialog; + protected Viewer vwr; + + public final static String version = "0.1.1"; + + @Override + public void start(JFrame frame, Viewer vwr) { + this.vwr = vwr; + nboDialog = new NBODialog(this, frame, vwr); + System.out.println("NBO Plugin started."); + } + + @Override + public String getName() { + return "NBO"; + } + + @Override + public String getVersion() { + return version; + } + + @Override + public void setVisible(boolean b) { + if (nboDialog == null) + return; + nboDialog.setVisible(b); + } + + @Override + public void destroy() { + if (nboDialog == null) + return; + nboDialog.close(); + nboDialog = null; + } + + @Override + public void notifyCallback(CBK type, Object[] data) { + if (nboDialog == null) + return; + nboDialog.notifyCallback(type, data); + } + +} Property changes on: trunk/Jmol/src/org/gennbo/NBOPlugin.java ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Modified: trunk/Jmol/src/org/gennbo/NBOService.java =================================================================== --- trunk/Jmol/src/org/gennbo/NBOService.java 2017-01-25 18:12:49 UTC (rev 21345) +++ trunk/Jmol/src/org/gennbo/NBOService.java 2017-01-25 20:52:14 UTC (rev 21346) @@ -82,7 +82,7 @@ // 1 1 2 // // jmol_outfile.txt is: - + // DATA " " // 1 1 2 // NBOServe: NATURAL BOND ORBITAL PROGRAM SUITE @@ -128,21 +128,18 @@ // GLOBAL C_PATH C:\temp // GLOBAL C_JOBSTEM ch3nh2 // CMD VIEW 1 - - - + // modes of operation - + // NOTE: There was a problem in that View and Raw were both 4 here - + static final int MODE_ERROR = -1; static final int MODE_RAW = 0;// leave this 0; it is referred to that in StatusListener - // these are for panel state static final int MODE_MODEL = 1; // don't change this number -- it is used for LOAD NBO static final int MODE_RUN = 20; - + // these are for rawCmdNew only static final int MODE_VALUE = 45; static final int MODE_LIST = 46; @@ -153,44 +150,44 @@ //static final int MODE_VALUE_M = 60; static final int MODE_GETRS = 61; static final int MODE_LABEL_BONDS = 62; + protected int count; + protected boolean isWorking; protected Viewer vwr; - - NBODialog nboDialog; - protected Process nboServer; protected Thread nboListener; - private InputStream stdout; protected BufferedReader nboReader; + protected NBODialog nboDialog; + protected NBOJob currJob; + protected Object lock; + protected Queue<NBOJob> jobQueue; + private PrintWriter stdinWriter; + private InputStream stdout; private SB sbRet; - private boolean inData; - protected boolean isWorking; + private boolean cantStartServer; private String serverPath; - private String serverDir; private String nboModel; - - NBOJob currJob; - Queue<NBOJob> jobQueue; - protected Object lock; - private boolean cantStartServer; + private String exeName = "NBOServe.exe"; - + /** * Manage communication between Jmol and NBOServer + * @param nboDialog * * @param vwr * The interacting display we are reproducing (source of view angle * info etc) */ - public NBOService(Viewer vwr) { + public NBOService(NBODialog nboDialog, Viewer vwr) { + this.nboDialog = nboDialog; this.vwr = vwr; sbRet = new SB(); - setServerPath(getNBOProperty("serverPath", - System.getProperty("user.home") + "/NBOServe")); + setServerPath(getNBOProperty("serverPath", System.getProperty("user.home") + + "/NBOServe")); jobQueue = new ArrayDeque<NBOJob>(); lock = new Object(); } @@ -198,11 +195,12 @@ boolean isOffLine() { return cantStartServer; } - + /** * Return path to NBOServe directory. * - * @param fileName or null for path itself, without slash + * @param fileName + * or null for path itself, without slash * * @return path */ @@ -224,7 +222,6 @@ return serverPath != null; } - protected String getNBOProperty(String name, String defaultValue) { return JmolPanel.getPluginOption("NBO", name, defaultValue); } @@ -234,14 +231,14 @@ JmolPanel.setPluginOption("NBO", name, option); } - /** * @param job */ protected void sendToNBO(NBOJob job) { String s = "<" + job.cmd + ">"; currJob = job; - nboDialog.inputFileHandler.writeToFile(serverDir + "/" + job.cmd, job.sb.toString()); + nboDialog.inputFileHandler.writeToFile(getServerPath(job.cmd), + job.sb.toString()); nboDialog.setStatus(job.statusInfo + " (sending job.cmd)"); sendCmd(s); } @@ -249,7 +246,7 @@ private void sendCmd(String s) { count = 1; System.out.println("sending " + s); - if(stdinWriter == null) + if (stdinWriter == null) restart(); stdinWriter.println(s); stdinWriter.flush(); @@ -294,13 +291,13 @@ int pt = line.indexOf("\n"); return (pt < 0 ? line + s : line.substring(0, pt) + s + line.substring(pt)); } - + String startProcess(boolean sync, @SuppressWarnings("unused") final int mode) { try { System.out.println("starting NBO process sync=" + sync); - File pathToExecutable = new File(serverPath + "/" + exeName ); - ProcessBuilder builder = new ProcessBuilder(serverPath + "/" + exeName); - builder.directory(new File(pathToExecutable.getParent())); // this is where you set the root folder for the executable to run with + String path = getServerPath(exeName); + ProcessBuilder builder = new ProcessBuilder(path); + builder.directory(new File(new File(path).getParent())); // root folder for executable builder.redirectErrorStream(true); nboServer = builder.start(); stdout = nboServer.getInputStream(); @@ -427,13 +424,13 @@ nboAddModelLine(line); } break; -// case MODE_VALUE_M: -// if (line.indexOf("DATA") >= 0) -// isWorking = inRequest = false; -// if (inRequest && isWorking) -// nboDialog.processModelLine(line); -// break; -// + // case MODE_VALUE_M: + // if (line.indexOf("DATA") >= 0) + // isWorking = inRequest = false; + // if (inRequest && isWorking) + // nboDialog.processModelLine(line); + // break; + // case MODE_GETRS: if (inRequest && isWorking) { int cnt = Integer.parseInt(line.trim()); @@ -469,14 +466,15 @@ } private int lineNo = 0; + protected void logServerLine(String line) { - nboDialog.logInfo((++lineNo) + "< " + line, isFortranError(line) ? Logger.LEVEL_ERROR : Logger.LEVEL_DEBUG); - } - + nboDialog.logInfo((++lineNo) + "< " + line, + isFortranError(line) ? Logger.LEVEL_ERROR : Logger.LEVEL_DEBUG); + } + protected boolean isFortranError(String line) { return line.indexOf("Permission denied") >= 0 - || line.indexOf("PGFIO-F") >= 0 - || line.indexOf("Invalid command") >= 0; + || line.indexOf("PGFIO-F") >= 0 || line.indexOf("Invalid command") >= 0; } public void closeProcess() { @@ -493,7 +491,7 @@ } nboReader = null; try { - nboListener.interrupt(); + nboListener.interrupt(); } catch (Exception e) { System.out.println("can't interrupt"); } @@ -515,46 +513,44 @@ startProcess(false, MODE_RAW); return (nboServer != null); } - /** * The interface for ALL communication with NBOServe from NBODialog. + * * @param cmd * @param data - * @param dialogMode - * @param list - * @param status + * @param dialogMode + * @param list + * @param status */ protected void rawCmdNew(String cmd, SB data, int dialogMode, DefaultComboBoxModel<String> list, String status) { - if(dialogMode == MODE_LABEL){ - nboDialog.runScriptNow("mo delete; nbo delete"); + if (dialogMode == MODE_LABEL) { + nboDialog.runScriptNow("mo delete; nbo delete"); + } + String fname = null; + synchronized (lock) { + if (data == null) { + nboDialog.logInfo("> " + cmd, Logger.LEVEL_DEBUG); + } else { + fname = cmd + "_cmd.txt"; + nboDialog.logInfo("> " + fname + "\n" + data, Logger.LEVEL_DEBUG); + cmd = "<" + fname + ">"; + isWorking = true; } - String fname = null; - synchronized(lock){ - if (data == null) { - nboDialog.logInfo("> " + cmd, Logger.LEVEL_DEBUG); - } else { - fname = cmd + "_cmd.txt"; - nboDialog.logInfo("> " + fname + "\n" + data, Logger.LEVEL_DEBUG); - cmd = "<" + fname + ">"; - isWorking = true; - } - if(jobQueue.isEmpty()){ - currJob = new NBOJob(fname,data, status, list); - jobQueue.add(currJob); - currJob.dialogMode = dialogMode; - sendToNBO(currJob); - } - else{ - NBOJob j = new NBOJob(fname,data, status, list); - j.dialogMode = dialogMode; - jobQueue.add(j); - } - } + if (jobQueue.isEmpty()) { + currJob = new NBOJob(fname, data, status, list); + jobQueue.add(currJob); + currJob.dialogMode = dialogMode; + sendToNBO(currJob); + } else { + NBOJob j = new NBOJob(fname, data, status, list); + j.dialogMode = dialogMode; + jobQueue.add(j); + } + } } - class NBOJob { String cmd; String statusInfo; @@ -577,7 +573,8 @@ String arch = System.getenv("PROCESSOR_ARCHITECTURE"); File f = new File(getServerPath("gennbo.bat")); if (!f.exists()) { - vwr.alert(f + " not found, make sure gennbo.bat is in same directory as " + exeName); + vwr.alert(f + " not found, make sure gennbo.bat is in same directory as " + + exeName); return false; } String wow64Arch = System.getenv("PROCESSOR_ARCHITEW6432"); @@ -603,6 +600,8 @@ return true; } + public void clearQueue() { + jobQueue.clear(); + } - -} \ No newline at end of file +} Added: trunk/Jmol/src/org/openscience/jmol/app/JmolPlugin.java =================================================================== --- trunk/Jmol/src/org/openscience/jmol/app/JmolPlugin.java (rev 0) +++ trunk/Jmol/src/org/openscience/jmol/app/JmolPlugin.java 2017-01-25 20:52:14 UTC (rev 21346) @@ -0,0 +1,15 @@ +package org.openscience.jmol.app; + +import javax.swing.JFrame; + +import org.jmol.c.CBK; +import org.jmol.viewer.Viewer; + +public interface JmolPlugin { + void start(JFrame frame, Viewer viewer); + void destroy(); + String getVersion(); + String getName(); + void setVisible(boolean b); + void notifyCallback(CBK type, Object[] data); +} Property changes on: trunk/Jmol/src/org/openscience/jmol/app/JmolPlugin.java ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Modified: trunk/Jmol/src/org/openscience/jmol/app/jmolpanel/JmolPanel.java =================================================================== --- trunk/Jmol/src/org/openscience/jmol/app/jmolpanel/JmolPanel.java 2017-01-25 18:12:49 UTC (rev 21345) +++ trunk/Jmol/src/org/openscience/jmol/app/jmolpanel/JmolPanel.java 2017-01-25 20:52:14 UTC (rev 21346) @@ -52,8 +52,10 @@ import java.util.Hashtable; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.Properties; +import javajs.util.Lst; import javajs.util.PT; import javax.swing.AbstractAction; @@ -94,6 +96,7 @@ import org.openscience.jmol.app.HistoryFile; import org.openscience.jmol.app.Jmol; import org.openscience.jmol.app.JmolApp; +import org.openscience.jmol.app.JmolPlugin; import org.openscience.jmol.app.SplashInterface; import org.openscience.jmol.app.jmolpanel.console.AppConsole; import org.openscience.jmol.app.jmolpanel.console.ConsoleTextArea; @@ -118,19 +121,13 @@ StatusBar status; int startupWidth, startupHeight; JsonNioServer serverService; - public NBOService nboService; // Called by NBODialog - public void setNBOService(NBOService service) { - this.nboService = service; - } - protected String appletContext; protected PropertyChangeSupport pcs = new PropertyChangeSupport(this); protected DisplayPanel display; protected GaussianDialog gaussianDialog; - protected NBODialog nboDialog; protected RecentFilesDialog recentFiles; protected AtomSetChooser atomSetChooser; public JFrame frame; @@ -285,23 +282,6 @@ say(GT._("Initializing Script Window...")); vwr.getProperty("DATA_API", "getAppConsole", Boolean.TRUE); - // Setup Plugin system - // say(GT._("Loading plugins...")); - // pluginManager = new CDKPluginManager( - // System.getProperty("user.home") + System.getProperty("file.separator") - // + ".jmol", new JmolEditBus(vwr) - // ); - // pluginManager.loadPlugin("org.openscience.cdkplugin.dirbrowser.DirBrowserPlugin"); - // pluginManager.loadPlugin("org.openscience.cdkplugin.dirbrowser.DadmlBrowserPlugin"); - // pluginManager.loadPlugins( - // System.getProperty("user.home") + System.getProperty("file.separator") - // + ".jmol/plugins" - // ); - // feature to allow for globally installed plugins - // if (System.getProperty("plugin.dir") != null) { - // pluginManager.loadPlugins(System.getProperty("plugin.dir")); - // } - // install the command table say(GT._("Building Command Hooks...")); commands = new Hashtable<String, Action>(); @@ -608,6 +588,8 @@ dispose(frame, saveSize); return true; } + + Map<String, JmolPlugin> plugins = new Hashtable<String, JmolPlugin>(); void dispose(JFrame f, boolean saveSize) { // Save window positions and status in the history @@ -623,14 +605,16 @@ serverService.close(); serverService = null; } - if(nboDialog != null){ - nboDialog.close(); - nboDialog = null; + + for (Entry<String, JmolPlugin> e : plugins.entrySet()) { + try { + e.getValue().destroy(); + } catch (Throwable err) { + // ignore + } } - if(nboService != null){ - nboService.closeProcess(); - nboService = null; - } + plugins.clear(); + if (numWindows <= 1) { // Close Jmol report(GT._("Closing Jmol...")); @@ -1173,19 +1157,24 @@ */ void startNBO(String type) { - String nboServerPath = historyFile.getProperty("nboServerPath", null); + String nboServerPath = getPluginOption("NBO", "serverPath", null); if (nboServerPath == null) { vwr.alert("NBOServe.exe has not been installed. See http://nbo6.chem.wisc.edu/new6_css.htm for additional information"); - return; } + showPlugin("NBO", "org.gennbo.NBOPlugin"); + } - if (nboDialog == null) - nboDialog = (NBODialog) getInstanceWithParams("org.gennbo.NBODialog", - new Class[] { JFrame.class, Viewer.class }, frame, vwr ); - if (nboDialog == null) { - vwr.alert("The NBODialog class could not be found."); - } else { - nboDialog.setVisible(true); + private void showPlugin(String name, String path) { + try { + JmolPlugin p = plugins.get(name); + if (p == null) { + plugins.put(name, p = (JmolPlugin) Interface.getInterface(path, vwr, + "plugin")); + p.start(frame, vwr); + } + p.setVisible(true); + } catch (Throwable e) { + System.out.println("Error creating plugin " + name); } } @@ -1708,10 +1697,8 @@ gaussianDialog.dispose(); gaussianDialog = null; } - if (nboDialog != null) { - nboDialog.dispose(); - nboDialog = null; - } + + boolean doTranslate = GT.setDoTranslate(true); getDialogs(); GT.setDoTranslate(doTranslate); Modified: trunk/Jmol/src/org/openscience/jmol/app/jmolpanel/StatusListener.java =================================================================== --- trunk/Jmol/src/org/openscience/jmol/app/jmolpanel/StatusListener.java 2017-01-25 18:12:49 UTC (rev 21345) +++ trunk/Jmol/src/org/openscience/jmol/app/jmolpanel/StatusListener.java 2017-01-25 20:52:14 UTC (rev 21346) @@ -43,6 +43,7 @@ import org.jmol.dialog.Dialog; import org.jmol.util.Logger; import org.jmol.viewer.Viewer; +import org.openscience.jmol.app.JmolPlugin; import org.openscience.jmol.app.jmolpanel.console.AppConsole; import org.openscience.jmol.app.webexport.WebExport; @@ -122,8 +123,9 @@ @SuppressWarnings("unchecked") @Override public void notifyCallback(CBK type, Object[] data) { - if (jmol.nboDialog != null) - jmol.nboDialog.notifyCallback(type, data); + if (!jmol.plugins.isEmpty()) + for (JmolPlugin p : jmol.plugins.values()) + p.notifyCallback(type, data); String strInfo = (data == null || data[1] == null ? null : data[1] .toString()); Map<String, Object> info; @@ -149,10 +151,10 @@ if (jmol.frame != null) { //Font f = jmol.frame.getFont(); //if (f != null) { - //int m = jmol.frame.getFontMetrics(f).stringWidth("M"); - //int n = jmol.frame.getWidth() / m; - //if (n < menuName.length()) - //menuName = menuName.substring(0, n) + "..."; + //int m = jmol.frame.getFontMetrics(f).stringWidth("M"); + //int n = jmol.frame.getWidth() / m; + //if (n < menuName.length()) + //menuName = menuName.substring(0, n) + "..."; //} jmol.frame.setTitle(menuName); } @@ -190,7 +192,7 @@ String service = (String) info.get("service"); if ("nbo".equals(service)) { if ("showPanel".equals(info.get("action"))) - jmol.startNBO(null); + jmol.startNBO(null); //else //jmol.getNBOService().processRequest(info, 0); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot _______________________________________________ Jmol-commits mailing list Jmol-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jmol-commits