Revision: 20241 http://sourceforge.net/p/jmol/code/20241 Author: hansonr Date: 2015-01-24 23:03:41 +0000 (Sat, 24 Jan 2015) Log Message: ----------- Jmol.___JmolVersion="14.3.12_2015.01.24"
new feature: load NBO CH3CH2CH3 -- retrieves the stucture of propane (in this case) from a local NBO server. -- including inorganics. For example: load nbo "Cr 3::acac" load nbo "Cr 2:::Bz" code: new interface for "services" that can provide valuable information to Jmol over ports or by running executable processes. -- currently just NBO bug fix: MOPAC reader loses two atoms in IRC calculation for MOPAC 2012 bug fix: _slabPlane and _depthPlane not set immediately when slab and depth are set Modified Paths: -------------- trunk/Jmol/src/org/jmol/adapter/readers/simple/MopacReader.java trunk/Jmol/src/org/jmol/c/CBK.java trunk/Jmol/src/org/jmol/console/GenericConsole.java trunk/Jmol/src/org/jmol/script/ScriptCompiler.java trunk/Jmol/src/org/jmol/script/ScriptEval.java trunk/Jmol/src/org/jmol/util/GenericApplet.java trunk/Jmol/src/org/jmol/viewer/Jmol.properties trunk/Jmol/src/org/jmol/viewer/StatusManager.java trunk/Jmol/src/org/jmol/viewer/TransformManager.java trunk/Jmol/src/org/jmol/viewer/Viewer.java trunk/Jmol/src/org/molecularplayground/MPJmolApp.java trunk/Jmol/src/org/openscience/jmol/app/jmolpanel/JmolPanel.java trunk/Jmol/src/org/openscience/jmol/app/jmolpanel/NBODialog.java trunk/Jmol/src/org/openscience/jmol/app/jmolpanel/StatusListener.java Added Paths: ----------- trunk/Jmol/src/org/openscience/jmol/app/nbo/ trunk/Jmol/src/org/openscience/jmol/app/nbo/NBOService.java Modified: trunk/Jmol/src/org/jmol/adapter/readers/simple/MopacReader.java =================================================================== --- trunk/Jmol/src/org/jmol/adapter/readers/simple/MopacReader.java 2015-01-23 04:14:38 UTC (rev 20240) +++ trunk/Jmol/src/org/jmol/adapter/readers/simple/MopacReader.java 2015-01-24 23:03:41 UTC (rev 20241) @@ -165,7 +165,6 @@ * @throws Exception */ void processCoordinates() throws Exception { - readLines(3); if (!chargesFound) { asc.newAtomSet(); baseAtomIndex = asc.ac; @@ -174,7 +173,10 @@ } Atom[] atoms = asc.atoms; int atomNumber; - while (rd() != null) { + while (rd().trim().length() == 0 || line.indexOf("ATOM") >= 0) { + // skip header lines + } + while (line != null) { String[] tokens = getTokens(); if (tokens.length == 0 || (atomNumber = parseIntStr(tokens[0])) == Integer.MIN_VALUE) @@ -189,6 +191,7 @@ if (atno != Integer.MIN_VALUE) elementSymbol = getElementSymbol(atno); atom.elementSymbol = elementSymbol; + rd(); } } /** Modified: trunk/Jmol/src/org/jmol/c/CBK.java =================================================================== --- trunk/Jmol/src/org/jmol/c/CBK.java 2015-01-23 04:14:38 UTC (rev 20240) +++ trunk/Jmol/src/org/jmol/c/CBK.java 2015-01-24 23:03:41 UTC (rev 20241) @@ -42,6 +42,7 @@ MEASURE, MESSAGE, MINIMIZATION, + SERVICE, PICK, RESIZE, SCRIPT, Modified: trunk/Jmol/src/org/jmol/console/GenericConsole.java =================================================================== --- trunk/Jmol/src/org/jmol/console/GenericConsole.java 2015-01-23 04:14:38 UTC (rev 20240) +++ trunk/Jmol/src/org/jmol/console/GenericConsole.java 2015-01-24 23:03:41 UTC (rev 20241) @@ -302,6 +302,7 @@ case HOVER: case LOADSTRUCT: case MINIMIZATION: + case SERVICE: case RESIZE: case SCRIPT: case SYNC: Modified: trunk/Jmol/src/org/jmol/script/ScriptCompiler.java =================================================================== --- trunk/Jmol/src/org/jmol/script/ScriptCompiler.java 2015-01-23 04:14:38 UTC (rev 20240) +++ trunk/Jmol/src/org/jmol/script/ScriptCompiler.java 2015-01-24 23:03:41 UTC (rev 20241) @@ -1079,6 +1079,7 @@ case T.orientation: case T.append: case T.history: + case T.nbo: if (nTokens != 1) return ERROR; //$FALL-THROUGH$ Modified: trunk/Jmol/src/org/jmol/script/ScriptEval.java =================================================================== --- trunk/Jmol/src/org/jmol/script/ScriptEval.java 2015-01-23 04:14:38 UTC (rev 20240) +++ trunk/Jmol/src/org/jmol/script/ScriptEval.java 2015-01-24 23:03:41 UTC (rev 20241) @@ -4110,17 +4110,32 @@ // load OCCUPANCY // load PARTIALCHARGE // load HISTORY + // load NBO switch (tok) { + case T.nbo: + case T.history: case T.menu: String m = paramAsStr(checkLast(2)); - if (!chk) - vwr.setMenu(m, true); + if (!chk) { + switch (tok) { + case T.nbo: + htParams.put("service", "nbo"); + htParams.put("mode", Integer.valueOf(1)); // MODEL + htParams.put("action", "load"); + htParams.put("value", m); + htParams.put("sync", Boolean.TRUE); + vwr.sm.processService(htParams); + vwr.loadInline((String) htParams.get("ret")); + break; + case T.history: + vwr.setHistory(m); + break; + case T.menu: + vwr.setMenu(m, true); + break; + } + } return; - case T.history: - String h = paramAsStr(checkLast(2)); - if (!chk) - vwr.setHistory(h); - return; case T.data: isData = true; loadScript.append(" /*data*/ data"); Modified: trunk/Jmol/src/org/jmol/util/GenericApplet.java =================================================================== --- trunk/Jmol/src/org/jmol/util/GenericApplet.java 2015-01-23 04:14:38 UTC (rev 20240) +++ trunk/Jmol/src/org/jmol/util/GenericApplet.java 2015-01-24 23:03:41 UTC (rev 20241) @@ -563,6 +563,8 @@ @Override public boolean notifyEnabled(CBK type) { switch (type) { + case SERVICE: + return false; case ECHO: case MESSAGE: case MEASURE: @@ -608,6 +610,7 @@ case EVAL: case HOVER: case MINIMIZATION: + case SERVICE: case RESIZE: case DRAGDROP: // just send it Modified: trunk/Jmol/src/org/jmol/viewer/Jmol.properties =================================================================== --- trunk/Jmol/src/org/jmol/viewer/Jmol.properties 2015-01-23 04:14:38 UTC (rev 20240) +++ trunk/Jmol/src/org/jmol/viewer/Jmol.properties 2015-01-24 23:03:41 UTC (rev 20241) @@ -17,8 +17,26 @@ TODO: add 2D graphics panel for Ramachandran and NBO-style 2D graphics -- send to browser as data uri? -Jmol.___JmolVersion="14.3.12_2015.01.22" +Jmol.___JmolVersion="14.3.12_2015.01.24" +new feature: load NBO CH3CH2CH3 + -- retrieves the stucture of propane (in this case) from a local NBO server. + -- including inorganics. For example: + + load nbo "Cr 3::acac" + load nbo "Cr 2:::Bz" + +code: new interface for "services" that can provide valuable information to Jmol + over ports or by running executable processes. + -- currently just NBO + + +bug fix: MOPAC reader loses two atoms in IRC calculation for MOPAC 2012 +bug fix: _slabPlane and _depthPlane not set immediately when slab and depth are set + +JmolVersion="14.3.12_2015.01.22" +released simultaneously with 14.2.12 + bug fix: color rockets amino fails bug fix: "color TRANSLUCENT -1" (screened translucency) restored; -- had been removed in 14.3.12_2015.01.20 because broken in jmol-11.7.27_02-27-09 Modified: trunk/Jmol/src/org/jmol/viewer/StatusManager.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/StatusManager.java 2015-01-23 04:14:38 UTC (rev 20240) +++ trunk/Jmol/src/org/jmol/viewer/StatusManager.java 2015-01-24 23:03:41 UTC (rev 20241) @@ -613,6 +613,12 @@ new Object[] { null, Integer.valueOf(mode), Integer.valueOf(atomIndex), Integer.valueOf(modelIndex), msg }); } + public void processService(Map<String, Object> info) { + if (notifyEnabled(CBK.SERVICE)) + cbl.notifyCallback(CBK.SERVICE, + new Object[] { null, info }); + } + public int getSyncMode() { return (!isSynced ? SYNC_OFF : drivingSync ? SYNC_DRIVER : SYNC_SLAVE); } Modified: trunk/Jmol/src/org/jmol/viewer/TransformManager.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/TransformManager.java 2015-01-23 04:14:38 UTC (rev 20240) +++ trunk/Jmol/src/org/jmol/viewer/TransformManager.java 2015-01-24 23:03:41 UTC (rev 20241) @@ -871,6 +871,7 @@ slabPlane = null; setSlabEnabled(false); setZShadeEnabled(false); + slabDepthChanged(); } public int getSlabPercentSetting() { @@ -888,6 +889,7 @@ private void slabDepthChanged() { vwr.g.setI("slab", slabPercentSetting); vwr.g.setI("depth", depthPercentSetting); + finalizeTransformParameters(); // also sets _slabPlane and _depthPlane } void depthByPercentagePoints(int percentage) { @@ -944,6 +946,7 @@ slabPlane = plane; slabPercentSetting = 100; } + slabDepthChanged(); } /** @@ -952,7 +955,6 @@ * @param isDepth */ public void setSlabDepthInternal(boolean isDepth) { - finalizeTransformParameters(); if (isDepth) depthPlane = null; else @@ -960,7 +962,7 @@ slabInternal(getSlabDepthPlane(isDepth), isDepth); } - P4 getSlabDepthPlane(boolean isDepth) { + private P4 getSlabDepthPlane(boolean isDepth) { // the third row of the matrix defines the Z coordinate, which is all we need // and, in fact, it defines the plane. How convenient! // eval "slab set" Modified: trunk/Jmol/src/org/jmol/viewer/Viewer.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/Viewer.java 2015-01-23 04:14:38 UTC (rev 20240) +++ trunk/Jmol/src/org/jmol/viewer/Viewer.java 2015-01-24 23:03:41 UTC (rev 20241) @@ -9172,4 +9172,5 @@ if (jmolpopup != null) jmolpopup.jpiUpdateComputedMenus(); } + } Modified: trunk/Jmol/src/org/molecularplayground/MPJmolApp.java =================================================================== --- trunk/Jmol/src/org/molecularplayground/MPJmolApp.java 2015-01-23 04:14:38 UTC (rev 20240) +++ trunk/Jmol/src/org/molecularplayground/MPJmolApp.java 2015-01-24 23:03:41 UTC (rev 20241) @@ -267,12 +267,13 @@ case LOADSTRUCT: case MEASURE: case MINIMIZATION: + case SERVICE: case PICK: case RESIZE: case SYNC: case STRUCTUREMODIFIED: case DRAGDROP: - break; + return false; } return false; } Modified: trunk/Jmol/src/org/openscience/jmol/app/jmolpanel/JmolPanel.java =================================================================== --- trunk/Jmol/src/org/openscience/jmol/app/jmolpanel/JmolPanel.java 2015-01-23 04:14:38 UTC (rev 20240) +++ trunk/Jmol/src/org/openscience/jmol/app/jmolpanel/JmolPanel.java 2015-01-24 23:03:41 UTC (rev 20241) @@ -38,6 +38,7 @@ import org.openscience.jmol.app.jsonkiosk.JsonNioClient; import org.openscience.jmol.app.jsonkiosk.JsonNioServer; import org.openscience.jmol.app.jsonkiosk.KioskFrame; +import org.openscience.jmol.app.nbo.NBOService; import org.openscience.jmol.app.surfacetool.SurfaceTool; import org.jmol.script.T; import org.jmol.util.Logger; @@ -105,7 +106,7 @@ public class JmolPanel extends JPanel implements SplashInterface, JsonNioClient { - static HistoryFile historyFile; + public static HistoryFile historyFile; public Viewer vwr; @@ -114,6 +115,7 @@ StatusBar status; int startupWidth, startupHeight; JsonNioServer serverService; + public NBOService nboService; protected String appletContext; protected PropertyChangeSupport pcs = new PropertyChangeSupport(this); @@ -1108,8 +1110,9 @@ @Override public void actionPerformed(ActionEvent e) { + getNBOService(); if (nboDialog == null) - nboDialog = new NBODialog(frame, vwr); + nboDialog = new NBODialog(frame, vwr, nboService); else nboDialog.setVisible(true); } @@ -1773,4 +1776,9 @@ vwr.syncScript(script, "~", 0); } + public NBOService getNBOService() { + return (nboService == null ? (nboService = new NBOService(vwr)) + : nboService); + } + } Modified: trunk/Jmol/src/org/openscience/jmol/app/jmolpanel/NBODialog.java =================================================================== --- trunk/Jmol/src/org/openscience/jmol/app/jmolpanel/NBODialog.java 2015-01-23 04:14:38 UTC (rev 20240) +++ trunk/Jmol/src/org/openscience/jmol/app/jmolpanel/NBODialog.java 2015-01-24 23:03:41 UTC (rev 20241) @@ -25,8 +25,7 @@ import org.jmol.viewer.Viewer; import org.jmol.i18n.GT; -import org.jmol.util.Logger; -import org.openscience.jmol.app.jmolpanel.JmolPanel; +import org.openscience.jmol.app.nbo.NBOService; import java.awt.BorderLayout; import java.awt.Component; @@ -54,12 +53,15 @@ import javax.swing.event.ChangeListener; import java.io.File; - +import java.util.Hashtable; +import java.util.Map; /** * A dialog for interacting with NBO-Server (experimental) */ public class NBODialog extends JDialog implements ChangeListener { + private static final int MODEL = 1; + private transient Viewer vwr; protected JButton nboPathButton; @@ -72,11 +74,11 @@ private JTextField workingPathLabel; - private JTextPane editArea1; + private JTextPane jmol_molfile; private JScrollPane editPane1; - private JTextPane editArea2; + private JTextPane nboOutput; private JScrollPane editPane2; @@ -88,45 +90,50 @@ private JTextField modelField; - + private NBOService nboService; + /** - * Creates a dialog for getting info related to output frames in - * nbo format. - * @param f The frame assosiated with the dialog - * @param vwr The interacting display we are reproducing (source of view angle info etc) + * Creates a dialog for getting info related to output frames in nbo format. + * + * @param f + * The frame assosiated with the dialog + * @param vwr + * The interacting display we are reproducing (source of view angle + * info etc) + * @param nboService */ - public NBODialog(JFrame f, Viewer vwr) { + public NBODialog(JFrame f, Viewer vwr, NBOService nboService) { super(f, GT._("NBO-Server Interface Setup"), false); this.vwr = vwr; - - - + this.nboService = nboService; + nboService.nboDialog = this; JPanel container = new JPanel(); - container.setPreferredSize(new Dimension(700,500)); - container.setLayout(new BoxLayout(container,BoxLayout.Y_AXIS)); - JPanel leftPanel = buildLeftPanel(); + container.setPreferredSize(new Dimension(700, 500)); + container.setLayout(new BoxLayout(container, BoxLayout.Y_AXIS)); + JPanel leftPanel = buildLeftPanel(); JPanel rightPanel = buildRightPanel(); JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftPanel, rightPanel); - splitPane.setOneTouchExpandable(true); + splitPane.setOneTouchExpandable(true); JPanel splitPanel = new JPanel(new BorderLayout()); splitPanel.add(splitPane, BorderLayout.CENTER); container.add(splitPanel); JPanel filePanel = buildFilePanel(); JPanel buttonPanel = buildButtonPanel(); - + JPanel gluePanel = new JPanel(new BorderLayout()); gluePanel.add(Box.createGlue(), BorderLayout.NORTH); gluePanel.add(filePanel, BorderLayout.SOUTH); container.add(gluePanel); container.add(buttonPanel); - getContentPane().add(container); - - getPathHistory(); + getContentPane().add(container); + pack(); centerDialog(); + getPathHistory(); + loadArea1(); setVisible(true); splitPane.setDividerLocation(0.5); } @@ -139,15 +146,24 @@ //GUI for panel with go, cancel and stop (etc) buttons Box buttonBox = Box.createHorizontalBox(); buttonBox.add(Box.createGlue()); - JButton closeButton = new JButton("Close"); - closeButton.addActionListener(new ActionListener() { + + JButton b = new JButton("Connect"); + b.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + connectPressed(); + } + }); + buttonBox.add(b); + b = new JButton("Close"); + b.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { closePressed(); } }); - buttonBox.add(closeButton); + buttonBox.add(b); buttonPanel.add(buttonBox); return buttonPanel; } @@ -195,32 +211,36 @@ return filePanel; } + private JPanel buildLeftPanel() { + + JPanel showPanel = new JPanel(new BorderLayout()); + inputTabs = new JTabbedPane(); + inputTabs.addTab("Model", null, modelPanel = getModelPanel()); + inputTabs.addTab("Run", null, runPanel = getRunPanel()); + inputTabs.setSelectedComponent(modelPanel); + inputTabs.addChangeListener(this); + showPanel.add(inputTabs, BorderLayout.CENTER); + return showPanel; + } + private JPanel buildRightPanel() { JPanel editPanel = new JPanel(); editPanel.setLayout(new BoxLayout(editPanel, BoxLayout.Y_AXIS)); TitledBorder editTitle = - BorderFactory.createTitledBorder("NBO Working File (temp)"); + BorderFactory.createTitledBorder("NBO Output"); editPanel.setBorder(editTitle); - editArea1 = new JTextPane(); - editArea1.setContentType("text/plain"); - editArea1.setFont(new Font("Monospaced", Font.PLAIN, 10)); - editPane1 = new JScrollPane(editArea1); + jmol_molfile = new JTextPane(); + jmol_molfile.setContentType("text/plain"); + jmol_molfile.setFont(new Font("Monospaced", Font.PLAIN, 10)); + editPane1 = new JScrollPane(jmol_molfile); editPanel.add(editPane1); - JButton goButton = new JButton("Execute"); - goButton.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - executeRaw(); - } - }); - editPanel.add(goButton); - editArea2 = new JTextPane(); - editArea2.setContentType("text/plain"); - editArea2.setFont(new Font("Monospaced", Font.PLAIN, 10)); - editPane2 = new JScrollPane(editArea2); + nboOutput = new JTextPane(); + nboOutput.setContentType("text/plain"); + nboOutput.setFont(new Font("Monospaced", Font.PLAIN, 10)); + editPane2 = new JScrollPane(nboOutput); //editPane2.setPreferredSize(new Dimension(500,100)); editPanel.add(editPane2); @@ -228,23 +248,6 @@ return editPanel; } - protected void executeRaw() { - goPressed("raw"); - - } - - private JPanel buildLeftPanel() { - - JPanel showPanel = new JPanel(new BorderLayout()); - inputTabs = new JTabbedPane(); - inputTabs.addTab("Model", null, modelPanel = getModelPanel()); - inputTabs.addTab("Run", null, runPanel = getRunPanel()); - inputTabs.setSelectedComponent(modelPanel); - inputTabs.addChangeListener(this); - showPanel.add(inputTabs, BorderLayout.CENTER); - return showPanel; - } - @Override public void stateChanged(ChangeEvent event) { if (event.getSource() == inputTabs) { @@ -283,35 +286,26 @@ } private Component getModelPanel() { + modelField = new JTextField("sh CH4"); + modelField.setPreferredSize(new Dimension(100, 10)); + modelField.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + modelCmd(); + }} + ); JPanel showPanel = new JPanel(new BorderLayout()); Box a = Box.createVerticalBox(); Box b = Box.createHorizontalBox(); - b.add(newLabel("Formula")); - b.add(modelField = new JTextField("CH4")); + b.add(newLabel("Model Command")); + b.add(modelField); a.add(b); a.add(Box.createVerticalGlue()); - b = Box.createHorizontalBox(); - b.add(Box.createHorizontalGlue()); - JButton goButton = new JButton("Load"); - goButton.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - loadModel(); - } - }); - b.add(goButton); - a.add(b); - showPanel.add(a, BorderLayout.NORTH); //showPanel.add(Box.createGlue(), BorderLayout.CENTER); return showPanel; } - protected void loadModel() { - goPressed("model"); - vwr.loadInline(editArea2.getText()); - } - private Component newLabel(String label) { JTextField t = new JTextField(label); t.setEditable(false); @@ -319,46 +313,52 @@ return t; } - private String lastText; - - void goPressed(String type) { + ///////////////////////////////////////////////////////// - String filename = "jmol_infile.txt"; - String workingPath = workingPathLabel.getText(); - File toNBOFile = new File(workingPath, filename); - String s; - if (type.equals("model")) { - editArea1.setText(" 1 1 1\nsh " + modelField.getText()); - } else if (type.equals("raw")) { + public void nboReport(String s) { + nboOutput.setText(s == null ? "" : nboOutput.getText() + s + "\n"); + } + protected void modelCmd() { + Map<String, Object> info = new Hashtable<String, Object>(); + info.put("mode", Integer.valueOf(NBOService.MODEL)); + info.put("sync", Boolean.FALSE); + String cmd = modelField.getText(); + if (cmd.startsWith("sh ")) { + info.put("action", "load"); + info.put("value", cmd.substring(3)); + } else { + info.put("action", "run"); + String fname = nboService.workingPath + File.separator + "jmol.orc"; + String orcData = vwr.getData("*", "orc"); + orcData = "%coords\ncoords" + orcData.substring(orcData.indexOf("\n\n") + 1) + "end\nend\n"; + vwr.writeTextFile(fname, orcData); + cmd = "xxxuse.orc " + fname + "\n" + cmd; } - try { - s = editArea1.getText(); - if (!s.equals(lastText)) { - vwr.writeTextFile(toNBOFile.getAbsolutePath(), lastText = s); - } - - String server = serverPathLabel.getText(); - File pathToExecutable = new File(server); - ProcessBuilder builder = new ProcessBuilder(server); - builder.directory(new File(pathToExecutable.getParent())); // this is where you set the root folder for the executable to run with - builder.redirectErrorStream(true); - Process proc = builder.start(); - //Process proc = Runtime.getRuntime().exec(commandLineArgs); - proc.waitFor(); - processResult(); - } catch (Exception e) { - Logger.errorEx("Caught IOException in NBO-Server exec", e); + info.put("value", cmd.substring(3)); + if (!nboService.processRequest(info)) { + clearInfo(); + nboReport("You must connect first."); } - //saveHistory(); - //dispose(); - } + } + + protected void connectPressed() { + nboService.closeProcess(); + clearInfo(); + String err = nboService.startProcess(true); // synchronous? + if (err == null) { + nboReport("listening..."); + } else { + nboReport(err); + } + } /** * Responds to cancel being press- or equivalent eg window closed. */ void closePressed() { - saveHistory(); + nboService.closeProcess(); + nboService.saveHistory(); setVisible(false); dispose(); } @@ -380,15 +380,17 @@ int button = myChooser.showDialog(this, GT._("Select")); if (button == JFileChooser.APPROVE_OPTION) { File newFile = myChooser.getSelectedFile(); - String savePath; + String path; if (newFile.isDirectory()) { - savePath = newFile.toString(); + path = newFile.toString(); } else { - savePath = newFile.getParent(); + path = newFile.getParent(); } - workingPathLabel.setText(savePath); + workingPathLabel.setText(path); loadArea1(); pack(); + nboService.workingPath = path; + nboService.saveHistory(); } } @@ -403,19 +405,15 @@ int button = myChooser.showDialog(this, GT._("Select")); if (button == JFileChooser.APPROVE_OPTION) { File newFile = myChooser.getSelectedFile(); - serverPathLabel.setText(newFile.toString()); + String path = newFile.toString(); + serverPathLabel.setText(path); pack(); + nboService.serverPath = path; + nboService.saveHistory(); } } /** - * Save INI file - * - * @return INI data - */ - - - /** * Centers the dialog on the screen. */ protected void centerDialog() { @@ -435,65 +433,23 @@ * Just recovers the path settings from last session. */ private void getPathHistory() { - - java.util.Properties props = JmolPanel.historyFile.getProperties(); - if (serverPathLabel != null) { - String nboPath = props.getProperty("nboServerPath", - System.getProperty("user.home")); - if (nboPath != null) { - serverPathLabel.setText(nboPath); - } - } - if (workingPathLabel != null) { - String savePath = props.getProperty("nboWorkingPath", - System.getProperty("user.home")); - if (savePath != null) { - workingPathLabel.setText(savePath); - loadArea1(); - } - } + serverPathLabel.setText(nboService.serverPath); + workingPathLabel.setText(nboService.workingPath); } - /** - * Just saves the path settings from this session. - */ - private void saveHistory() { - java.util.Properties props = new java.util.Properties(); - props.setProperty("nboServerPath", serverPathLabel.getText()); - props.setProperty("nboWorkingPath", workingPathLabel.getText()); - JmolPanel.historyFile.addProperties(props); + void clearInfo() { + jmol_molfile.setText(""); + nboOutput.setText(""); } - - String doubleQuoteIfContainsSpace(String str) { - for (int i = str.length(); --i >= 0; ) - if (str.charAt(i) == ' ') - return "\"" + str + "\""; - return str; - } - - String simpleQuoteIfContainsSpace(String str) { - for (int i = str.length(); --i >= 0; ) - if (str.charAt(i) == ' ') - return "\'" + str + "\'"; - return str; - } - void loadArea1() { String s = vwr.getFileAsString3(workingPathLabel.getText().replace('\\', '/') + "/jmol_infile.txt", true, "nbodialog"); - editArea1.setText(s); - lastText = s; - editArea2.setText(""); + jmol_molfile.setText(s); + nboOutput.setText(""); } - void processResult() { - loadArea1(); - loadArea2("jmol_molfile.txt"); + public void setModel(String s) { + jmol_molfile.setText(s); } - private void loadArea2(String fname) { - String s = vwr.getFileAsString3(workingPathLabel.getText().replace('\\', '/') + "/" + fname, true, "nbodialog"); - editArea2.setText(s); - } - - + } Modified: trunk/Jmol/src/org/openscience/jmol/app/jmolpanel/StatusListener.java =================================================================== --- trunk/Jmol/src/org/openscience/jmol/app/jmolpanel/StatusListener.java 2015-01-23 04:14:38 UTC (rev 20240) +++ trunk/Jmol/src/org/openscience/jmol/app/jmolpanel/StatusListener.java 2015-01-24 23:03:41 UTC (rev 20241) @@ -96,6 +96,7 @@ case STRUCTUREMODIFIED: case MEASURE: case MESSAGE: + case SERVICE: case PICK: case SCRIPT: case SYNC: @@ -115,16 +116,18 @@ return false; } + @SuppressWarnings("unchecked") @Override public void notifyCallback(CBK type, Object[] data) { String strInfo = (data == null || data[1] == null ? null : data[1] .toString()); + Map<String, Object> info; switch (type) { case LOADSTRUCT: notifyFileLoaded(strInfo, (String) data[2], (String) data[3], (String) data[4], (Boolean) data[8]); if (jmol.gaussianDialog != null) - jmol.gaussianDialog.updateModel(-2); + jmol.gaussianDialog.updateModel(-2); return; case ANIMFRAME: int[] iData = (int[]) data[1]; @@ -138,8 +141,8 @@ display.status.setStatus(1, menuName); if (jmol.frame != null) jmol.frame.setTitle(menuName); -// if (jSpecViewFrame != null) -// setJSpecView("", true); + // if (jSpecViewFrame != null) + // setJSpecView("", true); } return; case SCRIPT: @@ -164,17 +167,19 @@ break; case MESSAGE: break; - // case CLICK: - // x, y, action, int[] {action} - // the fourth parameter allows an application to change the action - // if (display.haveDisplay) - // display.status - // .setStatus(1, "(" + data[1] + "," + data[2] + ")"); - // break; + case SERVICE: + if (display == null) + return; + info = (Map<String, Object>) data[1]; + String service = (String) info.get("service"); + if ("nbo".equals(service)) { + display.jmolPanel.getNBOService().processRequest(info); + } + return; case PICK: notifyAtomPicked(strInfo); if (jmol.gaussianDialog != null) - jmol.gaussianDialog.updateModel(((Integer) data[2]).intValue()); + jmol.gaussianDialog.updateModel(((Integer) data[2]).intValue()); break; case STRUCTUREMODIFIED: // 0 DONE; 1 in process @@ -183,7 +188,7 @@ int modelIndexx = ((Integer) data[3]).intValue(); notifyStructureModified(atomIndex, modelIndexx, mode); if (jmol.gaussianDialog != null) - jmol.gaussianDialog.updateModel(-1); + jmol.gaussianDialog.updateModel(-1); break; case SYNC: if (strInfo != null && strInfo.toLowerCase().startsWith("jspecview")) { @@ -207,8 +212,8 @@ // cases that fail to return are sent to the console for processing if (jmol.service != null) jmol.service.scriptCallback(strInfo); - JmolCallbackListener appConsole = (JmolCallbackListener) vwr - .getProperty("DATA_API", "getAppConsole", null); + JmolCallbackListener appConsole = (JmolCallbackListener) vwr.getProperty( + "DATA_API", "getAppConsole", null); if (appConsole != null) appConsole.notifyCallback(type, data); } Added: trunk/Jmol/src/org/openscience/jmol/app/nbo/NBOService.java =================================================================== --- trunk/Jmol/src/org/openscience/jmol/app/nbo/NBOService.java (rev 0) +++ trunk/Jmol/src/org/openscience/jmol/app/nbo/NBOService.java 2015-01-24 23:03:41 UTC (rev 20241) @@ -0,0 +1,275 @@ +/* $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.openscience.jmol.app.nbo; + +import org.jmol.viewer.Viewer; +import org.openscience.jmol.app.jmolpanel.JmolPanel; +import org.openscience.jmol.app.jmolpanel.NBODialog; + +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.PrintWriter; +import java.util.Map; +import java.util.Scanner; + +import javajs.util.SB; + +/** + * A service for interacting with NBOServe (experimental) + * + * TODO: figure out how to manage time-consuming asynchronous requests + * + */ +public class NBOService { + + public static final int MODEL = 1; // do not change - referred to as "1" in org.jmol.script.ScriptEval.cmdLoad + + private transient Viewer vwr; + + public NBODialog nboDialog; + + private Process nboServer; + private Thread nboListener; + private InputStream stdout; + public Scanner nboScanner; + public BufferedReader nboReader; + private int nboMode; + private PrintWriter stdinWriter; + + private SB sbRet; + + private String nboAction; + + /** + * Manage communication between Jmol and NBOServer + * + * @param vwr The interacting display we are reproducing (source of view angle info etc) + */ + public NBOService(Viewer vwr) { + this.vwr = vwr; + java.util.Properties props = JmolPanel.historyFile.getProperties(); + serverPath = props.getProperty("nboServerPath", + System.getProperty("user.home")); + workingPath = props.getProperty("nboWorkingPath", + System.getProperty("user.home")); + } + + public boolean processRequest(Map<String, Object> info) { + boolean ok = false; + boolean sync = (info.get("sync") == Boolean.TRUE); + sbRet = (sync ? new SB() : null); + closeProcess(); + startProcess(sync); + nboMode = ((Integer) info.get("mode")).intValue(); + if (stdinWriter == null) { + closeProcess(); + sbRet.append("ERROR: Could not connect to NBOServe -- Use Tools...NBO... to set up NBOServe"); + nboMode = 0; + } + nboAction = (String) info.get("action"); + switch (nboMode) { + case MODEL: + String s = (String) info.get("value"); + if (nboAction.equals("load")) { + s = "sh " + s; + } else if (nboAction.equals("run")) { + // ok as is + } else { + s = null; + } + if (s != null) { + sendToNBO(MODEL, s, sync); + if (sync) { + try { + nboServer.waitFor(); + } catch (InterruptedException e) { + return false; + } + sbRet.append(getModel()); + } + ok = true; + } + break; + default: + if (sync) + sbRet.append("unknown mode"); + break; + } + if (sync) { + info.put("ret", sbRet.toString()); + } + return ok; + } + + /** + * temporary kludge to force exit + * + * @param mode + * @param s + * @param sync + */ + private void sendToNBO(int mode, String s, boolean sync) { + stdinWriter.println(mode + "\n" + s + "\n" + (true || sync ? "exit\nexit\n" : "")); + stdinWriter.flush(); + } + + public void nboReport(String nextLine) { + System.out.println(nextLine); + if (sbRet != null) + sbRet.append(nextLine + "\n"); + try { + if (nboDialog != null) + nboDialog.nboReport(nextLine); + } catch (Throwable t) { + // ignore + } + } + + public String serverPath; + public String workingPath; + + public String startProcess(boolean sync) { + try { + File pathToExecutable = new File(serverPath); + ProcessBuilder builder = new ProcessBuilder(serverPath); + builder.directory(new File(pathToExecutable.getParent())); // this is where you set the root folder for the executable to run with + builder.redirectErrorStream(true); + nboServer = builder.start(); + stdout = nboServer.getInputStream(); + nboReader = new BufferedReader(new InputStreamReader(stdout)); + nboListener = null; + if (!sync) { + nboListener = new Thread(new Runnable() { + @Override + public void run() { + while (true) { + String line; + try { + while ((line = nboReader.readLine()) != null) { + nboReport(line); + } + asyncCallback(); + } catch (Exception e1) { + } + break; + } + } + }); + nboListener.start(); + } + stdinWriter = new PrintWriter(nboServer.getOutputStream()); + } catch (IOException e) { + System.out.println(e.getMessage()); + return e.getMessage(); + } + return null; + } + + public void closeProcess() { +// try { +// stdout.close(); +// } catch (Exception e) { +// } + stdout = null; + try { + stdinWriter.close(); + } catch (Exception e) { + } + stdinWriter = null; + try { + nboScanner.close(); + } catch (Exception e) { + } + nboScanner = null; + try { + nboReader.close(); + } catch (Exception e) { + } + nboReader = null; + try { + nboListener.interrupt(); + } catch (Exception e) { + } + nboListener = null; + try { + nboServer.destroy(); + } catch (Exception e) { + } + nboServer = null; + } + + + /** + * process report from NBO -- asynchronous only + */ + public void asyncCallback() { + switch (nboMode) { + case MODEL: + if (nboAction.equals("load")) { + String s = getModel(); + nboDialog.setModel(s); + vwr.loadInline(s); + } else { + nboDialog.nboReport(null); + nboDialog.nboReport(getOutput()); + } + } + } + + /** + * temporary only + * + * @return model data + */ + private String getModel() { + return getNBOFile("jmol_molfile.txt"); + } + + /** + * temporary only + * + * @return output data + */ + private String getOutput() { + return getNBOFile("jmol_outfile.txt"); + } + + private String getNBOFile(String fname) { + return vwr.getFileAsString3(workingPath.replace('\\', '/') + "/" + fname, true, "nbodialog"); + } + + /** + * Just saves the path settings from this session. + */ + public void saveHistory() { + java.util.Properties props = new java.util.Properties(); + props.setProperty("nboServerPath", serverPath); + props.setProperty("nboWorkingPath", workingPath); + JmolPanel.historyFile.addProperties(props); + } + +} Property changes on: trunk/Jmol/src/org/openscience/jmol/app/nbo/NBOService.java ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ New Year. New Location. New Benefits. New Data Center in Ashburn, VA. GigeNET is offering a free month of service with a new server in Ashburn. Choose from 2 high performing configs, both with 100TB of bandwidth. Higher redundancy.Lower latency.Increased capacity.Completely compliant. http://p.sf.net/sfu/gigenet _______________________________________________ Jmol-commits mailing list Jmol-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jmol-commits