Revision: 21079 http://sourceforge.net/p/jmol/code/21079 Author: hansonr Date: 2016-04-30 13:34:51 +0000 (Sat, 30 Apr 2016) Log Message: ----------- JSpecView.jar for 13C Simulation
Modified Paths: -------------- branches/v14_4/Jmol/srcjsv/jspecview/application/AboutDialog.java branches/v14_4/Jmol/srcjsv/jspecview/application/AppToolBar.java branches/v14_4/Jmol/srcjsv/jspecview/application/ApplicationMenu.java branches/v14_4/Jmol/srcjsv/jspecview/application/MainFrame.java branches/v14_4/Jmol/srcjsv/jspecview/common/JSVFileManager.java branches/v14_4/Jmol/srcjsv/jspecview/common/JSViewer.java branches/v14_4/Jmol/srcjsv/jspecview/common/Spectrum.java branches/v14_4/Jmol/srcjsv/jspecview/java/AwtPlatform.java branches/v14_4/Jmol/srcjsv/jspecview/js2d/JsPlatform.java branches/v14_4/Jmol/srcjsv/jspecview/source/AnIMLReader.java branches/v14_4/Jmol/srcjsv/jspecview/source/JDXReader.java Modified: branches/v14_4/Jmol/srcjsv/jspecview/application/AboutDialog.java =================================================================== --- branches/v14_4/Jmol/srcjsv/jspecview/application/AboutDialog.java 2016-04-30 13:33:42 UTC (rev 21078) +++ branches/v14_4/Jmol/srcjsv/jspecview/application/AboutDialog.java 2016-04-30 13:34:51 UTC (rev 21079) @@ -1,4 +1,4 @@ -/* Copyright (c) 2002-2014 The University of the West Indies +/* Copyright (c) 2002-2016 The University of the West Indies * * Contact: robert.lancash...@uwimona.edu.jm * @@ -39,8 +39,8 @@ import jspecview.common.JSVersion; /** - * The <code>About Dialog</code> class is the <i>help | about</i> window for the - * JSpecView. + * The <code>About Dialog</code> class is the <i>help | about</i> window for JSpecView. + * @author Bob Hanson * @author Debbie-Ann Facey * @author Khari A. Bryan * @author Prof. Robert J. Lancashire @@ -120,7 +120,7 @@ txt = drawMessage(message, "Arial", Font.BOLD, 12); p.add(txt); - message = "Copyright (c) 2014, Department of Chemistry\nUniversity of the West Indies, Mona Campus\nJAMAICA"; + message = "Copyright (c) 2016, Department of Chemistry\nUniversity of the West Indies, Mona Campus\nJAMAICA"; txt = drawMessage(message, "Arial", Font.PLAIN, 12); p.add(txt); Modified: branches/v14_4/Jmol/srcjsv/jspecview/application/AppToolBar.java =================================================================== --- branches/v14_4/Jmol/srcjsv/jspecview/application/AppToolBar.java 2016-04-30 13:33:42 UTC (rev 21078) +++ branches/v14_4/Jmol/srcjsv/jspecview/application/AppToolBar.java 2016-04-30 13:34:51 UTC (rev 21079) @@ -114,7 +114,7 @@ @Override public void actionPerformed(ActionEvent e) { if (script.equals("open")) - vwr.openFileFromDialog(false, false, false, null); + vwr.openFileFromDialog(false, false, null, null); else if (script.equals("about")) new AboutDialog(mainFrame); else Modified: branches/v14_4/Jmol/srcjsv/jspecview/application/ApplicationMenu.java =================================================================== --- branches/v14_4/Jmol/srcjsv/jspecview/application/ApplicationMenu.java 2016-04-30 13:33:42 UTC (rev 21078) +++ branches/v14_4/Jmol/srcjsv/jspecview/application/ApplicationMenu.java 2016-04-30 13:34:51 UTC (rev 21079) @@ -125,21 +125,28 @@ InputEvent.CTRL_MASK, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - viewer.openFileFromDialog(true, false, false, null); + viewer.openFileFromDialog(true, false, null, null); } }); - JMenuItem openSimulationMenuItem = setMenuItem(null, 'I', "Add Simulation...", 73, + JMenuItem openSimulationH1MenuItem = setMenuItem(null, 'H', "Add H1 Simulation...", 72, InputEvent.CTRL_MASK, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - viewer.openFileFromDialog(true, false, true, null); + viewer.openFileFromDialog(true, false, "H1", null); } }); + JMenuItem openSimulationC13MenuItem = setMenuItem(null, 'C', "Add C13 Simulation...", 67, + InputEvent.CTRL_MASK, new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + viewer.openFileFromDialog(true, false, "C13", null); + } + }); JMenuItem openURLMenuItem = setMenuItem(null, 'U', "Add URL...", 85, InputEvent.CTRL_MASK, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - viewer.openFileFromDialog(true, true, false, null); + viewer.openFileFromDialog(true, true, null, null); } }); @@ -408,7 +415,8 @@ setProcessingMenu(processingMenu); fileMenu.add(openFileMenuItem); - fileMenu.add(openSimulationMenuItem); + fileMenu.add(openSimulationH1MenuItem); + fileMenu.add(openSimulationC13MenuItem); fileMenu.add(openURLMenuItem); fileMenu.add(openRecentMenu); // application does not need append Modified: branches/v14_4/Jmol/srcjsv/jspecview/application/MainFrame.java =================================================================== --- branches/v14_4/Jmol/srcjsv/jspecview/application/MainFrame.java 2016-04-30 13:33:42 UTC (rev 21078) +++ branches/v14_4/Jmol/srcjsv/jspecview/application/MainFrame.java 2016-04-30 13:34:51 UTC (rev 21079) @@ -1051,7 +1051,7 @@ @Override public void siSetLoaded(String fileName, String filePath) { appMenu.setCloseMenuItem(fileName); - setTitle("JSpecView - " + (filePath.startsWith(JSVFileManager.SIMULATION_PROTOCOL) ? "SIMULATION" : filePath)); + setTitle("JSpecView - " + (filePath.startsWith(JSVFileManager.SIMULATION_PROTOCOL) ? JSVFileManager.getSimulationType(filePath) + " SIMULATION" : filePath)); appMenu.setSourceEnabled(true); } Modified: branches/v14_4/Jmol/srcjsv/jspecview/common/JSVFileManager.java =================================================================== --- branches/v14_4/Jmol/srcjsv/jspecview/common/JSVFileManager.java 2016-04-30 13:33:42 UTC (rev 21078) +++ branches/v14_4/Jmol/srcjsv/jspecview/common/JSVFileManager.java 2016-04-30 13:34:51 UTC (rev 21079) @@ -46,7 +46,7 @@ // ALL STATIC METHODS public final static String SIMULATION_PROTOCOL = "http://SIMULATION/"; - // possibly http://SIMULATION/MOL=...\n....\n....\n.... + // possibly http://SIMULATION/H1/MOL=...\n....\n....\n.... public static URL appletDocumentBase; @@ -57,7 +57,6 @@ } public static String jsDocumentBase = ""; - public static Map<String, String> htCorrelationCache = new Hashtable<String, String>(); /** @@ -206,39 +205,55 @@ * involve mol=..., we want to abbreviate those names for display * * @param name actual path name to simulation + * @param type "H1" or "C13" * @return actual name or hashed name */ - public static String getAbbrSimulationFileName(String name) { - String filename = getAbbreviatedSimulationName(name, true); - if (name.indexOf("MOL=") >= 0) { - String data = htCorrelationCache.get(name); - if (data != null) - htCorrelationCache.put(filename, data); - } + public static String getAbbrSimulationFileName(String name, String type) { + if (type == null) + type = getSimulationType(name); + String filename = getAbbreviatedSimulationName(name, type, true); + if (name.indexOf("MOL=") >= 0) + cachePut(name, cacheGet(type + name)); return filename; } - static String getAbbreviatedSimulationName(String name, boolean addProtocol) { + static String getAbbreviatedSimulationName(String name, String type, boolean addProtocol) { return (name.indexOf("MOL=") >= 0 ? (addProtocol ? SIMULATION_PROTOCOL : "") + "MOL=" + getSimulationHash(name) : name); } private static String getSimulationHash(String name) { - return "" + Math.abs(name.substring(name.indexOf("V2000") + 1).hashCode()); + String code = "" + Math.abs(name.substring(name.indexOf("V2000") + 1).hashCode()); + if (Logger.debugging) + System.out.println("JSVFileManager hash for " + name + " = " + code); + return code; } - public static String getSimulationFileData(String name) { - return htCorrelationCache.get(name.startsWith("MOL=") ? name.substring(4) : - getAbbreviatedSimulationName(name, false)); + public static String getSimulationFileData(String name, String type) { + return cacheGet(name.startsWith("MOL=") ? name.substring(4) : + getAbbreviatedSimulationName(name, type, false)); } - private static BufferedReader getSimulationReader(String name) { - String data = htCorrelationCache.get(name); - if (data == null) { - data = getNMRSimulationJCampDX(name.substring(SIMULATION_PROTOCOL.length())); - if (data != null) - htCorrelationCache.put(name, data); - } + private static Map<String, String> htCorrelationCache = new Hashtable<String, String>(); + + public static void cachePut(String name, String data) { + if (Logger.debugging) + Logger.debug("JSVFileManager cachePut " + data + " for " + name); + if (data != null) + htCorrelationCache.put(name, data); + } + + public static String cacheGet(String key) { + String data = htCorrelationCache.get(key); + if (Logger.debugging) + Logger.info("JSVFileManager cacheGet " + data + " for " + key); + return data; + } + + private static BufferedReader getSimulationReader(String name) { + String data = cacheGet(name); + if (data == null) + cachePut(name, data = getNMRSimulationJCampDX(name.substring(SIMULATION_PROTOCOL.length()))); return getBufferedReaderForData(data); } @@ -399,8 +414,9 @@ } - private static String nciResolver = "http://cactus.nci.nih.gov/chemical/structure/%FILE/file?format=sdf&get3d=True"; - private static String nmrdbServer = "http://www.nmrdb.org/tools/jmol/predict.php?POST?molfile="; + private static String nciResolver = "https://cactus.nci.nih.gov/chemical/structure/%FILE/file?format=sdf&get3d=True"; + private static String nmrdbServerH1 = "http://www.nmrdb.org/tools/jmol/predict.php?POST?molfile="; + private static String nmrdbServerC13 = "http://www.nmrdb.org/service/jsmol13c?POST?molfile="; /** * Accepts either $chemicalname or MOL=molfiledata Queries NMRDB or NIH+NMRDB @@ -413,8 +429,12 @@ * @return jcamp data */ private static String getNMRSimulationJCampDX(String name) { + System.out.println("JSVFileManager getNMRSimulationJCampDX for " + name); String key = "" + getSimulationHash(name); - String jcamp = htCorrelationCache.get(key); + String type = getSimulationType(name); + if (name.startsWith(type)) + name = name.substring(type.length() + 1); + String jcamp = cacheGet(key); if (jcamp != null) return jcamp; boolean isInline = name.startsWith("MOL="); @@ -422,38 +442,48 @@ String src = (isInline ? null : PT.rep(nciResolver, "%FILE", PT.escapeUrl(name))); if ((molFile = (isInline ? PT.rep(name.substring(4), "\\n", "\n") - : getFileAsString(src))) == null) - Logger.info("no data returned"); - String json = getFileAsString(nmrdbServer + molFile); - htCorrelationCache.put("json", json); - Logger.debug(json); + : getFileAsString(src))) == null || molFile.indexOf("<html") >= 0) { + Logger.error("no MOL data returned by NCI"); + return null; + } + String url = (type.equals("H1") ? nmrdbServerH1 : nmrdbServerC13); + String json = getFileAsString(url + molFile); + cachePut("json", json); if (json.indexOf("\"error\":") >= 0) return null; json = PT.rep(json, "\\r\\n", "\n"); json = PT.rep(json, "\\t", "\t"); json = PT.rep(json, "\\n", "\n"); String jsonMolFile = getQuotedJSONAttribute(json, "molfile", null); - htCorrelationCache.put("mol", jsonMolFile); + if (jsonMolFile == null) { + System.out.println("JSVFileManager: no MOL file returned from EPFL"); + jsonMolFile = molFile; + } + cachePut("mol", jsonMolFile); /** * @j2sNative * - * if (!isInline) Jmol.Cache.put("http://SIMULATION/" + name + "#molfile", jsonMolFile.getBytes()); + * if (!isInline) Jmol.Cache.put("http://SIMULATION/" + type + "/" + name + "#molfile", jsonMolFile.getBytes()); * */ { // JAVA only + System.out.println("type/name: " + type + "/" + name); System.out.println("molFile is \n" + molFile); System.out.println("jsonMolFile is \n" + jsonMolFile); viewer.syncScript("JSVSTR:" + jsonMolFile); } String xml = getQuotedJSONAttribute(json, "xml", null); - xml = PT.rep(xml, "<Signals>", "<Signals src=" + PT.esc(PT.rep(nmrdbServer,"?POST?molfile=","")) + ">"); + xml = PT.rep(xml, "<Signals>", "<Signals src=" + PT.esc(PT.rep(nmrdbServerH1,"?POST?molfile=","")) + ">"); xml = PT.rep(xml, "</", "\n</"); xml = PT.rep(xml, "><", ">\n<"); xml = PT.rep(xml, "\\\"", "\""); - htCorrelationCache.put("xml", xml); + cachePut("xml", xml); jcamp = getQuotedJSONAttribute(json, "jcamp", null); - jcamp = "##TITLE=" + (isInline ? "JMOL SIMULATION" : name) + "\n" + if (jcamp.equals("value")) + jcamp = getQuotedJSONAttribute(json.substring(json.indexOf("jcamp") + 4), "value", null); + + jcamp = "##TITLE=" + (isInline ? "JMOL SIMULATION/" + type : name) + "\n" + jcamp.substring(jcamp.indexOf("\n##") + 1); int pt = molFile.indexOf("\n"); pt = molFile.indexOf("\n", pt + 1); @@ -462,7 +492,7 @@ + molFile.substring(pt + 1); pt = 0; pt = jcamp.indexOf("##."); - String id = getAbbreviatedSimulationName(name, false); + String id = getAbbreviatedSimulationName(name, type, false); int pt1 = id.indexOf("id='"); if (isInline && pt1 > 0) id = id.substring(pt1 + 4, (id + "'").indexOf("'", pt1 + 4)); @@ -470,8 +500,8 @@ + "<ModelData id=" + PT.esc(id) + " type=\"MOL\" src=" + PT.esc(src) + ">\n" + molFile + "</ModelData>\n</Models>\n" + "##$SIGNALS=\n" + xml + "\n" + jcamp.substring(pt); - htCorrelationCache.put("jcamp", jcamp); - htCorrelationCache.put(key, jcamp); + cachePut("jcamp", jcamp); + cachePut(key, jcamp); return jcamp; } @@ -537,7 +567,7 @@ if (isURL(fileName)) { try { if (fileName.startsWith(SIMULATION_PROTOCOL)) - return getAbbrSimulationFileName(fileName); + return getAbbrSimulationFileName(fileName, null); String name = (new URL((URL) null, fileName, null)).getFile(); return name.substring(name.lastIndexOf('/') + 1); } catch (IOException e) { @@ -564,6 +594,10 @@ appletDocumentBase = documentBase; } + public static String getSimulationType(String filePath) { + return (filePath.indexOf("C13/") >= 0 ? "C13" : "H1"); + } + } // a nice idea, but never implemented; not relevant to JavaScript Modified: branches/v14_4/Jmol/srcjsv/jspecview/common/JSViewer.java =================================================================== --- branches/v14_4/Jmol/srcjsv/jspecview/common/JSViewer.java 2016-04-30 13:33:42 UTC (rev 21078) +++ branches/v14_4/Jmol/srcjsv/jspecview/common/JSViewer.java 2016-04-30 13:34:51 UTC (rev 21079) @@ -972,7 +972,7 @@ } if (key != null && key.startsWith("DATA_")) { // mol, json, xml, jcamp -- most recent only - map.put(key, "" + JSVFileManager.htCorrelationCache.get(key.substring(5))); + map.put(key, "" + JSVFileManager.cacheGet(key.substring(5))); return map; } @@ -1361,20 +1361,25 @@ if (script == null) script = defaultLoadScript; if (filename.equals("?")) { - openFileFromDialog(isAppend, false, false, script); + openFileFromDialog(isAppend, false, null, script); return; } if (filename.equals("http://?")) { - openFileFromDialog(isAppend, true, false, null); + openFileFromDialog(isAppend, true, null, null); return; } - if (filename.equals("$?")) { - openFileFromDialog(isAppend, true, true, null); + if (filename.equals("$?") || filename.equals("$H1?")) { + openFileFromDialog(isAppend, true, "H1", null); return; } - boolean isMOL = filename.equalsIgnoreCase("MOL"); - if (isMOL) - filename = JSVFileManager.SIMULATION_PROTOCOL + "MOL=" + if (filename.equals("$C13?")) { + openFileFromDialog(isAppend, true, "C13", null); + return; + } + boolean isH1 = filename.equalsIgnoreCase("MOL") || filename.equalsIgnoreCase("H1"); + boolean isC13 = filename.equalsIgnoreCase("C13"); + if (isH1 || isC13) + filename = JSVFileManager.SIMULATION_PROTOCOL + (isH1 ? "H1/" : "C13/") + "MOL=" + PT.trimQuotes(tokens.get(++pt)); if (!isCheck && !isAppend) { if (filename.equals("\"\"") && currentSource != null) @@ -1383,7 +1388,8 @@ } filename = PT.trimQuotes(filename); if (filename.startsWith("$")) { - isMOL = true; + if (!filename.startsWith("$H1") && !filename.startsWith("$C13")) + filename = "$H1/" + filename.substring(3); filename = JSVFileManager.SIMULATION_PROTOCOL + filename.substring(1); } int firstSpec = (pt + 1 < tokens.size() ? Integer.valueOf(tokens.get(++pt)) @@ -1867,15 +1873,15 @@ } public void openFileFromDialog(boolean isAppend, boolean isURL, - boolean isSimulation, String script) { + String simulationType, String script) { String url = null; - if (isSimulation) { + if (simulationType != null) { url = fileHelper.getUrlFromDialog( "Enter the name or identifier of a compound", recentSimulation); if (url == null) return; recentSimulation = url; - load((isAppend ? "APPEND " : "") + "\"$" + url + "\"", script); + load((isAppend ? "APPEND " : "") + "\"$" + simulationType + "/" + url + "\"", script); } else if (isURL) { url = fileHelper.getUrlFromDialog("Enter the URL of a JCAMP-DX File", recentURL == null ? recentOpenURL : recentURL); Modified: branches/v14_4/Jmol/srcjsv/jspecview/common/Spectrum.java =================================================================== --- branches/v14_4/Jmol/srcjsv/jspecview/common/Spectrum.java 2016-04-30 13:33:42 UTC (rev 21078) +++ branches/v14_4/Jmol/srcjsv/jspecview/common/Spectrum.java 2016-04-30 13:34:51 UTC (rev 21079) @@ -242,6 +242,14 @@ String type = (peakList == null || peakList.size() == 0 ? getQualifiedDataType() : peakList.get(0).getType()); + if (type != null && type.startsWith("NMR")) { + if (nucleusY != null && !nucleusY.equals("?")) { + type = "2D" + type; + } else { + type = nucleusX + type; + } + + } return (type != null && type.length() > 0 ? type + " " : "") + getTitle(); } Modified: branches/v14_4/Jmol/srcjsv/jspecview/java/AwtPlatform.java =================================================================== --- branches/v14_4/Jmol/srcjsv/jspecview/java/AwtPlatform.java 2016-04-30 13:33:42 UTC (rev 21078) +++ branches/v14_4/Jmol/srcjsv/jspecview/java/AwtPlatform.java 2016-04-30 13:34:51 UTC (rev 21079) @@ -313,5 +313,10 @@ return null; } + @Override + public boolean forceAsyncLoad(String filename) { + return false; + } + } Modified: branches/v14_4/Jmol/srcjsv/jspecview/js2d/JsPlatform.java =================================================================== --- branches/v14_4/Jmol/srcjsv/jspecview/js2d/JsPlatform.java 2016-04-30 13:33:42 UTC (rev 21078) +++ branches/v14_4/Jmol/srcjsv/jspecview/js2d/JsPlatform.java 2016-04-30 13:34:51 UTC (rev 21079) @@ -75,8 +75,7 @@ * we must use Object[] here to hide [HTMLUnknownElement] and [Attribute] from Java2Script * @j2sNative * - * if (method == "localName")return jsObject[0]["nodeName"]; - * return (args == null ? jsObject[0][method] : jsObject[0][method](args[0])); + * return (method == null ? null : method == "localName" ? jsObject[0]["nodeName"] : args == null ? jsObject[0][method] : jsObject[0][method](args[0])); * * */ @@ -386,4 +385,10 @@ return null; } + @Override + public boolean forceAsyncLoad(String filename) { + // TODO Auto-generated method stub + return false; + } + } Modified: branches/v14_4/Jmol/srcjsv/jspecview/source/AnIMLReader.java =================================================================== --- branches/v14_4/Jmol/srcjsv/jspecview/source/AnIMLReader.java 2016-04-30 13:33:42 UTC (rev 21078) +++ branches/v14_4/Jmol/srcjsv/jspecview/source/AnIMLReader.java 2016-04-30 13:34:51 UTC (rev 21079) @@ -220,7 +220,6 @@ } private void getYValues() throws Exception { - BC bc = new BC(); String vectorType = parser.getAttrValueLC("type"); if (vectorType.length() == 0) vectorType = parser.getAttrValueLC("vectorType"); Modified: branches/v14_4/Jmol/srcjsv/jspecview/source/JDXReader.java =================================================================== --- branches/v14_4/Jmol/srcjsv/jspecview/source/JDXReader.java 2016-04-30 13:33:42 UTC (rev 21078) +++ branches/v14_4/Jmol/srcjsv/jspecview/source/JDXReader.java 2016-04-30 13:34:51 UTC (rev 21079) @@ -103,6 +103,7 @@ filePath = PT.trimQuotes(filePath); isSimulation = (filePath != null && filePath.startsWith(JSVFileManager.SIMULATION_PROTOCOL)); if (isSimulation) { + //TODO: H1 vs. C13 here? nmrMaxY = (Float.isNaN(nmrNormalization) ? 10000 : nmrNormalization); //filePath = JSVFileManager.getAbbrSimulationFileName(filePath); } @@ -301,7 +302,7 @@ } } if (acdMolFile != null) - JSVFileManager.htCorrelationCache.put("mol", acdMolFile); + JSVFileManager.cachePut("mol", acdMolFile); } if (!Float.isNaN(nmrMaxY)) spectrum.doNormalize(nmrMaxY); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Find and fix application performance issues faster with Applications Manager Applications Manager provides deep performance insights into multiple tiers of your business applications. It resolves application problems quickly and reduces your MTTR. Get your free trial! https://ad.doubleclick.net/ddm/clk/302982198;130105516;z _______________________________________________ Jmol-commits mailing list Jmol-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jmol-commits