Revision: 21400 http://sourceforge.net/p/jmol/code/21400 Author: hansonr Date: 2017-02-07 02:21:14 +0000 (Tue, 07 Feb 2017) Log Message: ----------- Jmol.___JmolVersion="14.8.2-beta-2017-02-06"
new feature: Viewer.runScriptCautiously(String) replacement name for older Viewer.runScript(String) bug fix: Viewer.runScript(String) now uses evaluateExpression(T[]) bug fix: NBO plugin fixes - huge success! Lesson learned: Never mix viewer.runScript() and viewer.runScriptQueued() calls. What will happen is that the unqueued calls will corrupt the queued calls. However, if you use viewer.evaluateExpression("script('....')"), that is also synchronous, and it uses a new ScriptEval() to isolate it from the script being queued. You still have the problem that the scripts could mess up each other, but at least it will not cause catastrophic failure. Modified Paths: -------------- trunk/Jmol/src/org/gennbo/NBODialog.java trunk/Jmol/src/org/gennbo/NBODialogConfig.java trunk/Jmol/src/org/gennbo/NBODialogModel.java trunk/Jmol/src/org/gennbo/NBODialogSearch.java trunk/Jmol/src/org/gennbo/NBODialogView.java trunk/Jmol/src/org/gennbo/NBOService.java trunk/Jmol/src/org/jmol/adapter/readers/pymol/JmolObject.java trunk/Jmol/src/org/jmol/adapter/readers/quantum/NBOParser.java trunk/Jmol/src/org/jmol/api/JmolViewer.java trunk/Jmol/src/org/jmol/script/ScriptParam.java trunk/Jmol/src/org/jmol/shapesurface/Isosurface.java trunk/Jmol/src/org/jmol/viewer/Jmol.properties trunk/Jmol/src/org/jmol/viewer/PropertyManager.java trunk/Jmol/src/org/jmol/viewer/Viewer.java Modified: trunk/Jmol/src/org/gennbo/NBODialog.java =================================================================== --- trunk/Jmol/src/org/gennbo/NBODialog.java 2017-02-06 21:26:16 UTC (rev 21399) +++ trunk/Jmol/src/org/gennbo/NBODialog.java 2017-02-07 02:21:14 UTC (rev 21400) @@ -697,6 +697,7 @@ */ @SuppressWarnings("incomplete-switch") public void notifyCallback(CBK type, Object[] data) { + System.out.println(type + "" + data[1]); if (!isVisible()) return; switch (type) { @@ -730,7 +731,7 @@ if (vwr.ms.ac == 0) return; String f = runScriptNow("print _modelFile"); - if (!f.equals("null") && !iAmLoading) { + if (!iAmLoading) { if (!f.endsWith(".47")) { if (dialogMode != DIALOG_MODEL) { doOpenPanel(DIALOG_MODEL); Modified: trunk/Jmol/src/org/gennbo/NBODialogConfig.java =================================================================== --- trunk/Jmol/src/org/gennbo/NBODialogConfig.java 2017-02-06 21:26:16 UTC (rev 21399) +++ trunk/Jmol/src/org/gennbo/NBODialogConfig.java 2017-02-07 02:21:14 UTC (rev 21400) @@ -226,6 +226,7 @@ private static final int MODE_PATH_WORKING = 1; final static protected Color titleColor = Color.blue; + private static final String NBOPROPERTY_DISPLAY_OPTIONS = "displayOptions"; protected Viewer vwr; protected NBOService nboService; @@ -491,7 +492,7 @@ } protected void doSetDefaults(boolean isJmol) { - nboPlugin.setNBOProperty("orbitalDisplayOptions", "default"); + nboPlugin.setNBOProperty(NBOPROPERTY_DISPLAY_OPTIONS, "default"); getOrbitalDisplayOptions(); opacity.setValue((int) (opacityOp * 10)); colorBox1.setSelectedItem(orbColor1); @@ -516,7 +517,7 @@ jCheckWireMesh.doClick(); colorBox1.setSelectedItem(Color.cyan); colorBox2.setSelectedItem(Color.yellow); - opacity.setValue(3); + opacity.setValue(7); try { String atomColors = ""; atomColors = GuiMap.getResourceString(this, @@ -535,24 +536,25 @@ + orbColor1.getBlue() + "]"; orbColorJmol2 = "[" + orbColor2.getRed() + " " + orbColor2.getGreen() + " " + orbColor2.getBlue() + "]"; - colorMeshes(); + //colorMeshes(); + updatePanelSettings(); // new if (!nboView) - nboPlugin.setNBOProperty("orbitalDisplayOptions", orbColor1.getRGB() + nboPlugin.setNBOProperty(NBOPROPERTY_DISPLAY_OPTIONS, orbColor1.getRGB() + "," + orbColor2.getRGB() + "," + opacityOp + "," + useWireMesh); } private String getOrbitalDisplayOptions() { - String options = (jmolOptionNONBO ? "jmol" : nboPlugin.getNBOProperty("orbitalDisplayOptions", + String options = (jmolOptionNONBO ? "jmol" : nboPlugin.getNBOProperty(NBOPROPERTY_DISPLAY_OPTIONS, "default")); if (options.equals("default") || options.equals("nboView")) { orbColor1 = Color.cyan; orbColor2 = Color.yellow; - opacityOp = 0.3f; + opacityOp = 0.7f; useWireMesh = false; } else if (options.equals("jmol")){ orbColor1 = Color.blue; orbColor2 = Color.red; - opacityOp = 0f; + opacityOp = 1f; useWireMesh = true; } else { // color1, color2, useMesh @@ -805,21 +807,35 @@ synchronized protected String runScriptNow(String script) { logInfo("!$ " + script, Logger.LEVEL_DEBUG); - return PT.trim(vwr.runScript(script), "\n"); +// return PT.trim(vwr.runScript(script), "\n"); + return PT.trim("" + vwr.evaluateExpression("script(\"" + script.replace('"', '\'') + "\")"), "\n"); + } protected boolean iAmLoading; protected void loadModelFileQueued(File f, boolean saveOrientation) { iAmLoading = true; - String s = "load \"" + f.getAbsolutePath() + "\"" + JMOL_FONT_SCRIPT ; + String s = "load \"" + f.getAbsolutePath().replace('\\', '/') + "\"" + JMOL_FONT_SCRIPT ; if (saveOrientation) s = "save orientation o1;" + s + ";restore orientation o1"; runScriptQueued(s); } + /** + * Uses the LOAD DATA option to load data from NBO; + * just getting all the "load xxx" methods in the same place. + * + * + * @param s + */ + protected void loadModelDataQueued(String s) { + iAmLoading = true; + runScriptQueued(s); + } + protected String loadModelFileNow(String s) { iAmLoading = true; - return runScriptNow("load " + s); + return runScriptNow("load " + s.replace('\\', '/')); } private boolean connect() { @@ -959,7 +975,7 @@ } protected void colorMeshes() { - updatePanelSettings(); + // yeiks! causes file load again! updatePanelSettings(); } protected void getNewInputFileHandler(int mode) { @@ -1005,7 +1021,7 @@ */ protected void doSearchSetResStruct(String type, int rsNum) { if (!showAtNum) { - runScriptNow("measurements off;select visible;label off; select none;refresh"); + runScriptNow("measurements off;isosurface off;select visible;label off; select none;refresh"); return; } // boolean atomsOnly = (type == null); @@ -1015,7 +1031,7 @@ rsTypeLast = type; } SB sb = new SB(); - sb.append("measurements off;select visible;label %a;"); + sb.append("measurements off;isosurface off;select visible;label %a;"); String color = (nboView) ? "black" : "gray"; sb.append("select visible;color labels white;" + "select visible & _H;color labels " + color + ";" @@ -1026,7 +1042,7 @@ runScriptNow(sb.toString()); return; } - sb.append(s); + //sb.append(s); if (nboView) { sb.append("select add {*}.bonds;color bonds lightgrey;" + "wireframe 0.1;"); Modified: trunk/Jmol/src/org/gennbo/NBODialogModel.java =================================================================== --- trunk/Jmol/src/org/gennbo/NBODialogModel.java 2017-02-06 21:26:16 UTC (rev 21399) +++ trunk/Jmol/src/org/gennbo/NBODialogModel.java 2017-02-07 02:21:14 UTC (rev 21400) @@ -1305,15 +1305,13 @@ break; case NBOService.MODE_MODEL_NEW: case NBOService.MODE_MODEL_EDIT: - if (s.contains("\\")) - s = s.replaceAll("\\\\", ""); s += JMOL_FONT_SCRIPT; if (mode == NBOService.MODE_MODEL_EDIT) s = "set refreshing off;save orientation o4;load " + s + ";restore orientation o4;set refreshing on"; else - s = "load " + s; - runScriptQueued(s); + s = ";load " + s; + loadModelDataQueued(s); break; case NBOService.MODE_MODEL_SAVE: break; @@ -1325,16 +1323,16 @@ s = PT.rep(s.substring(s.indexOf("\n") + 1), "\"\n", "\" NBO\n"); s = "set refreshing false;load " + s + JMOL_FONT_SCRIPT + ";set refreshing true"; - runScriptQueued(s); + loadModelDataQueued(s); break; case NBOService.MODE_MODEL_TO_NBO: s = "load " + s + JMOL_FONT_SCRIPT + ";set refreshing true;"; // s = "set refreshing off;save orientation o3;load " + s // + ";restore orientation o3;set refreshing on"; - runScriptQueued(s); + loadModelDataQueued(s); break; case NBOService.MODE_MODEL_UNDO_REDO: - runScriptQueued("set refreshing false;load " + s + JMOL_FONT_SCRIPT + loadModelDataQueued("set refreshing false;load " + s + JMOL_FONT_SCRIPT + ";restore orientation o2;set refreshing true"); break; case NBOService.MODE_MODEL_VALUE: @@ -1344,4 +1342,5 @@ break; } } + } Modified: trunk/Jmol/src/org/gennbo/NBODialogSearch.java =================================================================== --- trunk/Jmol/src/org/gennbo/NBODialogSearch.java 2017-02-06 21:26:16 UTC (rev 21399) +++ trunk/Jmol/src/org/gennbo/NBODialogSearch.java 2017-02-07 02:21:14 UTC (rev 21400) @@ -393,11 +393,11 @@ } protected void doSearchCMOSelectNBO() { - showOrbJmol("PNBO", comboSearchOrb1.getSelectedIndex(), "NBO"); + showOrbJmol("PNBO", comboSearchOrb1.getSelectedIndex(), "cmo"); } protected void doSearchCMOSelectMO() { - showOrbJmol("MO", comboSearchOrb2.getSelectedIndex(), "MO"); + showOrbJmol("MO", comboSearchOrb2.getSelectedIndex(), "cmo"); } protected void doComboBasisOperationAction() { @@ -488,7 +488,13 @@ break; case KEYWD_CMO: postListRequest("n", comboSearchOrb1); + if (radioOrbMO.isSelected()) + radioOrbMO.doClick(); break; + case KEYWD_OPBAS: + case KEYWD_BAS1BAS2: + doSetBasis(); + break; } } @@ -1201,12 +1207,13 @@ * @param id */ protected void showOrbJmol(String type, int i, String id) { - if (i <= 0) + if (i <= 0) { + runScriptQueued("select visible;isosurface delete"); + logError("Select an orbital."); return; + } id = fixID(id); - runScriptQueued("select visible;isosurface ID \"" - + id - + "\" delete;" + runScriptQueued("select visible;isosurface delete;" + getJmolIsosurfaceScript(id, peeify(type), i, betaSpin.isSelected(), false)); } @@ -1508,14 +1515,19 @@ ////////////////////////// SEARCH POSTS TO NBO /////////////////// - private void postListRequest(String get, JComboBox<String> cb) { + /** + * + * @param cmd_basis a possibly space-separated set of CMD and + * @param cb + */ + private void postListRequest(String cmd_basis, JComboBox<String> cb) { int mode = NBOService.MODE_SEARCH_LIST; SB sb = getMetaHeader(false); String cmd; int metaKey = keywordID; - if (metaKey >= KEYWD_OPBAS) { + if (keywordID == KEYWD_OPBAS || keywordID == KEYWD_BAS1BAS2) { cmd = "o"; - JComboBox<String> tmpBas = ((get.startsWith("c") && metaKey == KEYWD_BAS1BAS2) ? comboBasis2 + JComboBox<String> tmpBas = ((cmd_basis.startsWith("c") && metaKey == KEYWD_BAS1BAS2) ? comboBasis2 : comboBasis1); switch (tmpBas.getSelectedIndex()) { case BASIS_AO: @@ -1542,11 +1554,11 @@ postAddGlobalI(sb, "BAS_1", 1, tmpBas); } else { postAddGlobalI(sb, "BAS_1", 1, comboBasis1); - cmd = get.split(" ")[0]; + cmd = cmd_basis.split(" ")[0]; } postAddGlobalI(sb, "KEYWORD", metaKey, null); postAddCmd(sb, cmd); - if (get.equals("c") && keywordID == KEYWD_CMO) + if (keywordID == KEYWD_CMO && cmd_basis.equals("c_cmo")) mode = NBOService.MODE_SEARCH_LIST_MO; postNBO_s(sb, mode, cb, "Getting list " + cmd); } @@ -1630,7 +1642,7 @@ if (isLabel ? !processLabel(sb, lines[i], pt) : !processLabelBonds(sb, lines[i])) break; - runScriptQueued(sb.toString() + ";select none;"); + runScriptQueued(sb.toString() + JMOL_FONT_SCRIPT + ";select none;"); break; } } Modified: trunk/Jmol/src/org/gennbo/NBODialogView.java =================================================================== --- trunk/Jmol/src/org/gennbo/NBODialogView.java 2017-02-06 21:26:16 UTC (rev 21399) +++ trunk/Jmol/src/org/gennbo/NBODialogView.java 2017-02-07 02:21:14 UTC (rev 21400) @@ -1413,18 +1413,18 @@ */ protected String getJmolIsosurfaceScript(String id, String type, int orbitalNumber, boolean isBeta, boolean isNegative) { - return ";select visible;isosurface " + return ";select visible;isosurface ID \"" + id - + " color " + + "\" color " + (isNegative ? orbColorJmol1 + " " + orbColorJmol2 : orbColorJmol2 + " " + orbColorJmol1) + " cutoff 0.0316 NBO " + type + " " + orbitalNumber - + (isBeta ? " beta" : "") + + (isBeta && !type.equals("MO") ? " beta" : "") // AO? + " frontonly " + (useWireMesh ? " mesh nofill" : " nomesh fill translucent " - + opacityOp) + ";select none;"; + + (1 - opacityOp)) + ";select none;"; } class OrbitalList extends JList<String> implements ListSelectionListener, Modified: trunk/Jmol/src/org/gennbo/NBOService.java =================================================================== --- trunk/Jmol/src/org/gennbo/NBOService.java 2017-02-06 21:26:16 UTC (rev 21399) +++ trunk/Jmol/src/org/gennbo/NBOService.java 2017-02-07 02:21:14 UTC (rev 21400) @@ -189,6 +189,7 @@ byte[] buffer = new byte[1024]; String cachedReply = ""; + protected boolean destroyed; /** * Start the ProcessBuilder for NBOServe and listen to its stdout (Fortran LFN @@ -222,6 +223,7 @@ */ String startProcess() { try { + destroyed = false; cantStartServer = true; if (!doConnect) return null; @@ -250,7 +252,7 @@ String s; - while (!Thread.currentThread().isInterrupted()) { + while (!destroyed && !Thread.currentThread().isInterrupted()) { try { Thread.sleep(1); @@ -280,8 +282,17 @@ } } + if (destroyed) + closeProcess(); } - }); + }) { + + @Override + public void interrupt() { + destroyed = true; + } + + }; nboListener.setName("NBOServiceThread" + System.currentTimeMillis()); nboListener.start(); @@ -290,8 +301,12 @@ nboIn = new PrintWriter(nboServer.getOutputStream()); } catch (IOException e) { - dialog.logInfo(e.getMessage(), Logger.LEVEL_ERROR); - return e.getMessage(); + String s = e.getMessage(); + System.out.println(s); + if (s.contains("error=1455")) + s = "Jmol can't do that - low on memory"; + dialog.logError(s); + return s; } cantStartServer = false; return null; @@ -320,6 +335,8 @@ setReady(true); int m = 0; do { + if (destroyed) + return null; n = m; Thread.sleep(10); if (nboOut == null) Modified: trunk/Jmol/src/org/jmol/adapter/readers/pymol/JmolObject.java =================================================================== --- trunk/Jmol/src/org/jmol/adapter/readers/pymol/JmolObject.java 2017-02-06 21:26:16 UTC (rev 21399) +++ trunk/Jmol/src/org/jmol/adapter/readers/pymol/JmolObject.java 2017-02-07 02:21:14 UTC (rev 21400) @@ -362,7 +362,7 @@ } if (sb != null) { //System.out.println("jmolobject " + sb); - sm.vwr.runScript(sb.toString()); + sm.vwr.runScriptCautiously(sb.toString()); return; } // cartoon, trace, etc. Modified: trunk/Jmol/src/org/jmol/adapter/readers/quantum/NBOParser.java =================================================================== --- trunk/Jmol/src/org/jmol/adapter/readers/quantum/NBOParser.java 2017-02-06 21:26:16 UTC (rev 21399) +++ trunk/Jmol/src/org/jmol/adapter/readers/quantum/NBOParser.java 2017-02-07 02:21:14 UTC (rev 21400) @@ -184,7 +184,7 @@ for (int i = 0; i < structureList.size(); i++) { Map<String, Object> map = (Map<String, Object>) structureList.get(i); if (spin.equals(map.get("spin")) && type.equals(map.get("type")) - && (index < 0 || i == ((Integer) map.get("index")).intValue())) { + && (index < 0 || index == ((Integer) map.get("index")).intValue())) { return map; } } Modified: trunk/Jmol/src/org/jmol/api/JmolViewer.java =================================================================== --- trunk/Jmol/src/org/jmol/api/JmolViewer.java 2017-02-06 21:26:16 UTC (rev 21399) +++ trunk/Jmol/src/org/jmol/api/JmolViewer.java 2017-02-07 02:21:14 UTC (rev 21400) @@ -541,13 +541,24 @@ abstract public int[] resizeInnerPanel(int width, int height); /** + * starting with 14.8.2-beta-2017-02-06, uses script(xxxx) function; + * see runScriptCautiously for the older version + * + * @param script + * @return string from ScriptEvaluator#outputBuffer + */ + abstract public String runScript(String script); + + /** + * Formerly runScript(script). + * * run a script immediately and return output buffer string * Jmol 13.1.15 * * @param script * @return string from ScriptEvaluator#outputBuffer */ - abstract public String runScript(String script); + public String runScriptCautiously(String script){return null;} abstract public String extractMolData(String what); Modified: trunk/Jmol/src/org/jmol/script/ScriptParam.java =================================================================== --- trunk/Jmol/src/org/jmol/script/ScriptParam.java 2017-02-06 21:26:16 UTC (rev 21399) +++ trunk/Jmol/src/org/jmol/script/ScriptParam.java 2017-02-07 02:21:14 UTC (rev 21400) @@ -58,7 +58,6 @@ } protected boolean checkToken(int i) { - System.out.println("iToken,i,slen" + iToken + " "+ i + " " + slen); return (iToken = i) < slen; } Modified: trunk/Jmol/src/org/jmol/shapesurface/Isosurface.java =================================================================== --- trunk/Jmol/src/org/jmol/shapesurface/Isosurface.java 2017-02-06 21:26:16 UTC (rev 21399) +++ trunk/Jmol/src/org/jmol/shapesurface/Isosurface.java 2017-02-07 02:21:14 UTC (rev 21400) @@ -1514,7 +1514,7 @@ thisMesh.jvxlData.allowVolumeRender = false; thisMesh.setColorsFromJvxlData(sg.params.colorRgb); if (thisMesh.jvxlData.slabInfo != null) - vwr.runScript("isosurface " + thisMesh.jvxlData.slabInfo); + vwr.runScriptCautiously("isosurface " + thisMesh.jvxlData.slabInfo); if (sg.params.psi_monteCarloCount > 0) thisMesh.diameter = -1; // use set DOTSCALE Modified: trunk/Jmol/src/org/jmol/viewer/Jmol.properties =================================================================== --- trunk/Jmol/src/org/jmol/viewer/Jmol.properties 2017-02-06 21:26:16 UTC (rev 21399) +++ trunk/Jmol/src/org/jmol/viewer/Jmol.properties 2017-02-07 02:21:14 UTC (rev 21400) @@ -49,11 +49,22 @@ # 10. Run jmol/tools build-release.xml # -Jmol.___JmolVersion="14.8.2-beta-2017-02-05" +Jmol.___JmolVersion="14.8.2-beta-2017-02-06" +new feature: Viewer.runScriptCautiously(String) replacement name for older Viewer.runScript(String) + +bug fix: Viewer.runScript(String) now uses evaluateExpression(T[]) -bug fix: NBO plugin fixes +bug fix: NBO plugin fixes - huge success! +Lesson learned: Never mix viewer.runScript() and viewer.runScriptQueued() calls. + What will happen is that the unqueued calls will corrupt the + queued calls. However, if you use viewer.evaluateExpression("script('....')"), + that is also synchronous, and it uses a new ScriptEval() to isolate it from + the script being queued. You still have the problem that the scripts could + mess up each other, but at least it will not cause catastrophic failure. + + noting undocumented set fontscaling true; font label 10 arial plain 0.020 Modified: trunk/Jmol/src/org/jmol/viewer/PropertyManager.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/PropertyManager.java 2017-02-06 21:26:16 UTC (rev 21399) +++ trunk/Jmol/src/org/jmol/viewer/PropertyManager.java 2017-02-07 02:21:14 UTC (rev 21400) @@ -1123,7 +1123,7 @@ if (exp.startsWith("print")) { if (!atomExpression.equals("selected")) exp = PT.rep(exp, "selected", atomExpression.substring(1, atomExpression.length() - 1)); - return vwr.runScript(exp); + return vwr.runScriptCautiously(exp); } if (exp.indexOf("label") < 0) exp = atomExpression + ".label(\"" + exp + "\").lines"; Modified: trunk/Jmol/src/org/jmol/viewer/Viewer.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/Viewer.java 2017-02-06 21:26:16 UTC (rev 21399) +++ trunk/Jmol/src/org/jmol/viewer/Viewer.java 2017-02-07 02:21:14 UTC (rev 21400) @@ -2276,7 +2276,7 @@ switch (tokType) { case T.xyz: if (script != null) - runScript(script); + runScriptCautiously(script); break; case T.vibration: setStatusFrameChanged(true, false); @@ -8923,9 +8923,22 @@ pickedList.pushPop(SV.newV(T.bitset, BSUtil.newAndSetBit(atomIndex)), null); } + + @Override + public String runScript(String script) { + return (String) evaluateExpression(new T[] { T.t(T.script), T.t(T.leftparen), SV.newS(script), T.t(T.rightparen) }); + } + /** + * formerly runScript(), this method really can ONLY be called by + * the viewer being run from an already-running script. If it is + * invoked by a separate thread, it can wreak havoc on any queued + * thread, since they are not thread safe. + * @param script + * @return output of the script. + */ @Override - public String runScript(String script) { + public String runScriptCautiously(String script) { // from isosurface reading JVXL file with slab SB outputBuffer = new SB(); try { 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