From: <ha...@us...> - 2010-04-20 12:25:28
|
Revision: 12896 http://jmol.svn.sourceforge.net/jmol/?rev=12896&view=rev Author: hansonr Date: 2010-04-20 12:25:20 +0000 (Tue, 20 Apr 2010) Log Message: ----------- version=12.0.RC7_dev # new feature: drag-and-drop defaults for map files and PDB files # bug fix: VRML exporter fails to remove duplicate spheres if not same color Modified Paths: -------------- trunk/Jmol/src/org/jmol/adapter/smarter/AtomSetCollectionReader.java trunk/Jmol/src/org/jmol/adapter/smarter/Resolver.java trunk/Jmol/src/org/jmol/adapter/smarter/SmarterJmolAdapter.java trunk/Jmol/src/org/jmol/export/JmolFileDropper.java trunk/Jmol/src/org/jmol/export/_VrmlExporter.java trunk/Jmol/src/org/jmol/jvxl/readers/PmeshReader.java trunk/Jmol/src/org/jmol/jvxl/readers/SurfaceFileReader.java trunk/Jmol/src/org/jmol/jvxl/readers/SurfaceGenerator.java trunk/Jmol/src/org/jmol/jvxl/readers/SurfaceReader.java trunk/Jmol/src/org/jmol/script/ScriptEvaluator.java trunk/Jmol/src/org/jmol/script/ScriptFunction.java trunk/Jmol/src/org/jmol/shape/MeshCollection.java trunk/Jmol/src/org/jmol/viewer/Jmol.properties trunk/Jmol/src/org/jmol/viewer/Viewer.java trunk/Jmol/src/org/openscience/jmol/app/JmolApp.java Added Paths: ----------- trunk/Jmol/src/org/jmol/util/SurfaceFileTyper.java Modified: trunk/Jmol/src/org/jmol/adapter/smarter/AtomSetCollectionReader.java =================================================================== --- trunk/Jmol/src/org/jmol/adapter/smarter/AtomSetCollectionReader.java 2010-04-19 13:09:07 UTC (rev 12895) +++ trunk/Jmol/src/org/jmol/adapter/smarter/AtomSetCollectionReader.java 2010-04-20 12:25:20 UTC (rev 12896) @@ -684,12 +684,12 @@ String groups = (String) htSite.get("groups"); if (groups.length() == 0) continue; - addJmolScript("@site_" + name + " " + groups); + addSiteScript("@site_" + name + " " + groups); //addJmolScript("@" + seqNum + " " + groups); - addJmolScript("site_" + name + " = \"" + groups + "\".split(\",\")"); + addSiteScript("site_" + name + " = \"" + groups + "\".split(\",\")"); sites += (sites == "" ? "" : ",") + "site_" + name; } - addJmolScript("site_list = \"" + sites + "\".split(\",\")"); + addSiteScript("site_list = \"" + sites + "\".split(\",\")"); } public void applySymmetryAndSetTrajectory() throws Exception { @@ -946,6 +946,17 @@ previousScript); } + private String siteScript; + protected void addSiteScript(String script) { + if (siteScript == null) + siteScript = ""; + else if (!siteScript.endsWith(";")) + siteScript += ";"; + siteScript += script; + atomSetCollection.setAtomSetCollectionAuxiliaryInfo("sitescript", + siteScript); + } + public String readLine() throws Exception { prevline = line; line = reader.readLine(); Modified: trunk/Jmol/src/org/jmol/adapter/smarter/Resolver.java =================================================================== --- trunk/Jmol/src/org/jmol/adapter/smarter/Resolver.java 2010-04-19 13:09:07 UTC (rev 12895) +++ trunk/Jmol/src/org/jmol/adapter/smarter/Resolver.java 2010-04-20 12:25:20 UTC (rev 12896) @@ -913,7 +913,7 @@ private final static String[] pdbLineStartRecords = { "Pdb", "HEADER", "OBSLTE", "TITLE ", "CAVEAT", "COMPND", "SOURCE", "KEYWDS", - "EXPDTA", "AUTHOR", "REVDAT", "SPRSDE", "JRNL ", "REMARK", + "EXPDTA", "AUTHOR", "REVDAT", "SPRSDE", "JRNL ", "REMARK ", "DBREF ", "SEQADV", "SEQRES", "MODRES", "HELIX ", "SHEET ", "TURN ", "CRYST1", "ORIGX1", "ORIGX2", "ORIGX3", "SCALE1", "SCALE2", "SCALE3", Modified: trunk/Jmol/src/org/jmol/adapter/smarter/SmarterJmolAdapter.java =================================================================== --- trunk/Jmol/src/org/jmol/adapter/smarter/SmarterJmolAdapter.java 2010-04-19 13:09:07 UTC (rev 12895) +++ trunk/Jmol/src/org/jmol/adapter/smarter/SmarterJmolAdapter.java 2010-04-20 12:25:20 UTC (rev 12896) @@ -378,16 +378,10 @@ } public String getFileTypeName(Object atomSetCollectionOrReader) { - return staticGetFileTypeName(atomSetCollectionOrReader); - } - - private static String staticGetFileTypeName(Object atomSetCollectionOrReader) { - if (atomSetCollectionOrReader == null) - return null; - if (atomSetCollectionOrReader instanceof BufferedReader) - return Resolver.getFileType((BufferedReader)atomSetCollectionOrReader); if (atomSetCollectionOrReader instanceof AtomSetCollection) return ((AtomSetCollection)atomSetCollectionOrReader).getFileTypeName(); + if (atomSetCollectionOrReader instanceof BufferedReader) + return Resolver.getFileType((BufferedReader)atomSetCollectionOrReader); return null; } Modified: trunk/Jmol/src/org/jmol/export/JmolFileDropper.java =================================================================== --- trunk/Jmol/src/org/jmol/export/JmolFileDropper.java 2010-04-19 13:09:07 UTC (rev 12895) +++ trunk/Jmol/src/org/jmol/export/JmolFileDropper.java 2010-04-20 12:25:20 UTC (rev 12896) @@ -89,10 +89,7 @@ private void loadFile(String fname) { if (fname.indexOf("://") < 0) fname = (fname.startsWith("/") ? "file://" : "file:///") + fname; - if (fname.endsWith(".jvxl") || fname.endsWith(".xjvxl")) - viewer.script("isosurface " + Escape.escape(fname)); - else - viewer.script("load " + Escape.escape(fname)); + viewer.openFileAsynchronously(fname); } private void loadFiles(List fileList) { Modified: trunk/Jmol/src/org/jmol/export/_VrmlExporter.java =================================================================== --- trunk/Jmol/src/org/jmol/export/_VrmlExporter.java 2010-04-19 13:09:07 UTC (rev 12895) +++ trunk/Jmol/src/org/jmol/export/_VrmlExporter.java 2010-04-20 12:25:20 UTC (rev 12896) @@ -350,8 +350,9 @@ Hashtable htSpheresRendered = new Hashtable(); protected void outputSphere(Point3f center, float radius, short colix) { - String child = useTable.getDef("S" + colix + "_" + (int) (radius * 100)); - String check = child + " " + center; + int iRad = (int) (radius * 100); + String child = useTable.getDef("S" + colix + "_" + iRad); + String check = round(center) + " " + iRad; if (htSpheresRendered.get(check) != null) return; htSpheresRendered.put(check, Boolean.TRUE); Modified: trunk/Jmol/src/org/jmol/jvxl/readers/PmeshReader.java =================================================================== --- trunk/Jmol/src/org/jmol/jvxl/readers/PmeshReader.java 2010-04-19 13:09:07 UTC (rev 12895) +++ trunk/Jmol/src/org/jmol/jvxl/readers/PmeshReader.java 2010-04-20 12:25:20 UTC (rev 12896) @@ -30,6 +30,7 @@ import org.jmol.jvxl.data.JvxlCoder; import org.jmol.util.BinaryDocument; import org.jmol.util.Logger; +import org.jmol.util.SurfaceFileTyper; /* * @@ -87,7 +88,7 @@ private int nPolygons; private boolean isBinary; - final static String PMESH_BINARY_MAGIC_NUMBER = "PM" + '\1' + '\0'; + final static String PMESH_BINARY_MAGIC_NUMBER = SurfaceFileTyper.PMESH_BINARY_MAGIC_NUMBER; String pmeshError; PmeshReader(SurfaceGenerator sg, String fileName, BufferedReader br) { Modified: trunk/Jmol/src/org/jmol/jvxl/readers/SurfaceFileReader.java =================================================================== --- trunk/Jmol/src/org/jmol/jvxl/readers/SurfaceFileReader.java 2010-04-19 13:09:07 UTC (rev 12895) +++ trunk/Jmol/src/org/jmol/jvxl/readers/SurfaceFileReader.java 2010-04-20 12:25:20 UTC (rev 12896) @@ -66,73 +66,6 @@ binarydoc.close(); } - static String determineFileType(BufferedReader bufferedReader) { - // JVXL should be on the FIRST line of the file, but it may be - // after comments or missing. - - // Apbs, Jvxl, or Cube, also efvet - - String line; - LimitedLineReader br = new LimitedLineReader(bufferedReader, 16000); - //sure bets, but not REQUIRED: - if ((line = br.info()).length() == 0) - return "UNKNOWN"; - if (line.indexOf("<jvxl") >= 0 && line.indexOf("<?xml") >= 0) - return "JvxlXML"; - if (line.indexOf("#JVXL+") >= 0) - return "Jvxl+"; - if (line.indexOf("#JVXL") >= 0) - return "Jvxl"; - if (line.indexOf("&plot") == 0) - return "Jaguar"; - if (line.indexOf("MAP ") == 208) - return "MRC" + (line.charAt(67) == '\0' ? "L" : "B"); - if (line.indexOf("<efvet ") >= 0) - return "Efvet"; - if (line.indexOf(PmeshReader.PMESH_BINARY_MAGIC_NUMBER) == 0) - return "Pmesh"; - if ("\n\r".indexOf(line.charAt(0)) >= 0 && line.indexOf("ZYX") >= 0) - return "Xplor"; - if (line.length() > 37 && line.charAt(36) == 0 && line.charAt(37) == 100) - return "DSN6B"; - if (line.length() > 37 && line.charAt(37) == 100 && line.charAt(36) == 0) - return "DSN6L"; - - // Apbs, Jvxl, or Cube, maybe formatted Plt - - line = br.readNonCommentLine(); - if (line.indexOf("object 1 class gridpositions counts") == 0) - return "Apbs"; - - String[] tokens = Parser.getTokens(line); - line = br.readNonCommentLine();// second line - if (tokens.length == 2 - && Parser.parseInt(tokens[0]) == 3 - && Parser.parseInt(tokens[1])!= Integer.MIN_VALUE) { - tokens = Parser.getTokens(line); - if (tokens.length == 3 - && Parser.parseInt(tokens[0])!= Integer.MIN_VALUE - && Parser.parseInt(tokens[1])!= Integer.MIN_VALUE - && Parser.parseInt(tokens[2])!= Integer.MIN_VALUE) - return "PltFormatted"; - } - line = br.readNonCommentLine(); // third line - //next line should be the atom line - int nAtoms = Parser.parseInt(line); - if (nAtoms == Integer.MIN_VALUE) - return (line.indexOf("+") == 0 ? "Jvxl+" : "UNKNOWN"); - if (nAtoms >= 0) - return "Cube"; //Can't be a Jvxl file - nAtoms = -nAtoms; - for (int i = 4 + nAtoms; --i >=0;) - if ((line = br.readNonCommentLine()) == null) - return "UNKNOWN"; - int nSurfaces = Parser.parseInt(line); - if (nSurfaces == Integer.MIN_VALUE) - return "UNKNOWN"; - return (nSurfaces < 0 ? "Jvxl" : "Cube"); //Final test looks at surface definition line - } - void discardTempData(boolean discardAll) { closeReader(); super.discardTempData(discardAll); @@ -203,43 +136,3 @@ } } -class LimitedLineReader { - //from Resolver - private char[] buf; - private int cchBuf; - private int ichCurrent; - - LimitedLineReader(BufferedReader bufferedReader, int readLimit) { - buf = new char[readLimit]; - try { - bufferedReader.mark(readLimit); - cchBuf = bufferedReader.read(buf); - ichCurrent = 0; - bufferedReader.reset(); - } catch (Exception e) { - } - } - - protected String info() { - return new String(buf); - } - - protected String readNonCommentLine() { - while (ichCurrent < cchBuf) { - int ichBeginningOfLine = ichCurrent; - char ch = 0; - while (ichCurrent < cchBuf && - (ch = buf[ichCurrent++]) != '\r' && ch != '\n') { - } - int cchLine = ichCurrent - ichBeginningOfLine; - if (ch == '\r' && ichCurrent < cchBuf && buf[ichCurrent] == '\n') - ++ichCurrent; - if (buf[ichBeginningOfLine] == '#') // flush comment lines; - continue; - StringBuffer sb = new StringBuffer(cchLine); - sb.append(buf, ichBeginningOfLine, cchLine); - return sb.toString(); - } - return ""; - } -} Modified: trunk/Jmol/src/org/jmol/jvxl/readers/SurfaceGenerator.java =================================================================== --- trunk/Jmol/src/org/jmol/jvxl/readers/SurfaceGenerator.java 2010-04-19 13:09:07 UTC (rev 12895) +++ trunk/Jmol/src/org/jmol/jvxl/readers/SurfaceGenerator.java 2010-04-20 12:25:20 UTC (rev 12896) @@ -1086,7 +1086,9 @@ } BufferedReader br = (BufferedReader) value; if (fileType == null) - fileType = SurfaceFileReader.determineFileType(br); + fileType = SurfaceFileTyper.determineSurfaceFileType(br); + if (fileType == null) + fileType = "UNKNOWN"; Logger.info("data file type was determined to be " + fileType); if (fileType.equals("Jvxl+")) return new JvxlReader(this, br); Modified: trunk/Jmol/src/org/jmol/jvxl/readers/SurfaceReader.java =================================================================== --- trunk/Jmol/src/org/jmol/jvxl/readers/SurfaceReader.java 2010-04-19 13:09:07 UTC (rev 12895) +++ trunk/Jmol/src/org/jmol/jvxl/readers/SurfaceReader.java 2010-04-20 12:25:20 UTC (rev 12896) @@ -323,8 +323,8 @@ if (!readAndSetVolumeParameters()) return false; if (!justForPlane && params.sigma != Float.MAX_VALUE && !allowSigma) { - Logger.error("Reader does not support SIGMA option"); - return false; + Logger.error("Reader does not support SIGMA option -- using cutoff 1.6"); + params.cutoff = 1.6f; } nPointsX = voxelCounts[0]; nPointsY = voxelCounts[1]; Modified: trunk/Jmol/src/org/jmol/script/ScriptEvaluator.java =================================================================== --- trunk/Jmol/src/org/jmol/script/ScriptEvaluator.java 2010-04-19 13:09:07 UTC (rev 12895) +++ trunk/Jmol/src/org/jmol/script/ScriptEvaluator.java 2010-04-20 12:25:20 UTC (rev 12896) @@ -67,6 +67,7 @@ import org.jmol.util.Parser; import org.jmol.util.Point3fi; import org.jmol.util.Quaternion; +import org.jmol.util.SurfaceFileTyper; import org.jmol.util.TextFormat; import org.jmol.modelset.TickInfo; import org.jmol.viewer.ActionManager; @@ -1937,6 +1938,8 @@ BitSetUtil.deleteBits((BitSet) value, bsDeleted); } } + + //Hashtable thisCommandVariables; /** * provides support for @x and @{....} in statements. The compiler passes on @@ -1950,6 +1953,7 @@ private boolean setStatement(int pc) throws ScriptException { statement = aatoken[pc]; statementLength = statement.length; + //thisCommandVariables = null; if (statementLength == 0) return true; Token[] fixed; @@ -1969,6 +1973,7 @@ fixed[0] = statement[0]; boolean isExpression = false; int j = 1; + //thisCommandVariables = new Hashtable(); for (i = 1; i < statementLength; i++) { if (statement[i] == null) continue; @@ -1986,8 +1991,10 @@ i = iToken; ScriptVariable vt = (ScriptVariable) val.elementAt(0); v = (vt.tok == Token.list ? vt : ScriptVariable.oValue(vt)); +// thisCommandVariables.put("v", v); } else { v = getParameter(var, false); +// thisCommandVariables.put(var, v); } tok = tokAt(0); boolean forceString = (Token.tokAttr(tok, Token.implicitStringCommand) @@ -4801,7 +4808,7 @@ invertSelected(); break; case Token.javascript: - script(Token.javascript); + script(Token.javascript, null); break; case Token.load: load(); @@ -4868,7 +4875,7 @@ set(); break; case Token.script: - script(Token.script); + script(Token.script, null); break; case Token.select: select(1); @@ -7218,16 +7225,14 @@ } else { modelName = parameterAsString(i); tok = tokAt(i); - /* I have no idea what this was about. - if (modelName.equalsIgnoreCase("data")) { - modelName = stringParameter(++i); - if (!isSyntaxCheck) - htParams.put("parameterData", viewer.getFileAsString(modelName)); - loadScript.append(" data / *file* /").append(Escape.escape(modelName)); - tok = tokAt(++i); - modelName = parameterAsString(i); - } - */ + /* + * I have no idea what this was about. if + * (modelName.equalsIgnoreCase("data")) { modelName = + * stringParameter(++i); if (!isSyntaxCheck) htParams.put("parameterData", + * viewer.getFileAsString(modelName)); + * loadScript.append(" data / *file* /").append(Escape.escape(modelName)); + * tok = tokAt(++i); modelName = parameterAsString(i); } + */ if (tok == Token.identifier || modelName.equalsIgnoreCase("fileset")) { if (modelName.equals("menu")) { String m = parameterAsString(checkLast(2)); @@ -7253,8 +7258,9 @@ } if (isAppend && ((filename = optParameterAsString(i)) - .equalsIgnoreCase("trajectory") || filename - .equalsIgnoreCase("models") || filename.equalsIgnoreCase("inline"))) { + .equalsIgnoreCase("trajectory") + || filename.equalsIgnoreCase("models") || filename + .equalsIgnoreCase("inline"))) { modelName = filename; loadScript.append(" " + modelName); i++; @@ -7280,7 +7286,7 @@ htParams.put("firstLastStep", new int[] { 0, -1, 1 }); } } - } else if (modelName.equalsIgnoreCase("inline")){ + } else if (modelName.equalsIgnoreCase("inline")) { } else { modelName = "fileset"; } @@ -7538,11 +7544,19 @@ // but there could state problems here because then we don't have the // option to save load options with that... Hmm. if (errMsg != null && !isCmdLine_c_or_C_Option) { - if (errMsg.indexOf("NOTE: file recognized as a script file:") == 0) { - viewer.addLoadScript("-"); - errMsg = TextFormat.trim(errMsg, "\n"); - runScript("script \"" + errMsg.substring(40) + "\""); - return; + if (statementLength == 2) { + if (errMsg.indexOf("NOTE: file recognized as a script file:") == 0) { + viewer.addLoadScript("-"); + script(0, filename); + return; + } + String surfaceType = SurfaceFileTyper.determineSurfaceFileType(viewer + .getBufferedInputStream(filename)); + if (surfaceType != null) { + viewer.addLoadScript("-"); + runScript("isosurface " + Escape.escape(filename)); + return; + } } evalError(errMsg, null); } @@ -7552,23 +7566,28 @@ } if (logMessages) scriptStatusOrBuffer("Successfully loaded:" + modelName); - String defaultScript = viewer.getDefaultLoadScript(); + String script = viewer.getDefaultLoadScript(); String msg = ""; - if (defaultScript.length() > 0) - msg += "\nUsing defaultLoadScript: " + defaultScript; - String script = (String) viewer.getModelSetAuxiliaryInfo("jmolscript"); + if (script.length() > 0) + msg += "\nUsing defaultLoadScript: " + script; + String embeddedScript = (String) viewer.getModelSetAuxiliaryInfo("jmolscript"); viewer.getModelSetAuxiliaryInfo().remove("jmolscript"); - if (script != null && viewer.getAllowEmbeddedScripts()) { - msg += "\nAdding embedded #jmolscript: " + script; - defaultScript += ";" + script; - defaultScript = "allowEmbeddedScripts = false;" + defaultScript + if (embeddedScript != null && viewer.getAllowEmbeddedScripts()) { + msg += "\nAdding embedded #jmolscript: " + embeddedScript; + script += ";" + embeddedScript; + viewer.setStringProperty("_loadScript", script); + script = "allowEmbeddedScripts = false;" + script + ";allowEmbeddedScripts = true;"; } if (msg.length() > 0) Logger.info(msg); - if (defaultScript.length() > 0 && !isCmdLine_c_or_C_Option) + String siteScript = (String) viewer.getModelSetAuxiliaryInfo("sitescript"); + viewer.getModelSetAuxiliaryInfo().remove("sitescript"); + if (siteScript != null) + script = siteScript + ";" + script; + if (script.length() > 0 && !isCmdLine_c_or_C_Option) // NOT checking embedded scripts in some cases - runScript(defaultScript); + runScript(script); } private String getFullPathName() throws ScriptException { @@ -8378,7 +8397,7 @@ data) ? (Vector3f) data[2] : null); } - private void script(int tok) throws ScriptException { + private void script(int tok, String filename) throws ScriptException { boolean loadCheck = true; boolean isCheck = false; boolean doStep = false; @@ -8388,7 +8407,6 @@ int pcEnd = 0; int i = 2; String theScript = parameterAsString(1); - String filename = null; String localPath = null; String remotePath = null; String scriptPath = null; @@ -8398,78 +8416,83 @@ viewer.jsEval(theScript); return; } - tok = tokAt(1); - if (tok != Token.string) - error(ERROR_filenameExpected); - filename = parameterAsString(1); - if (filename.equalsIgnoreCase("applet")) { - // script APPLET x "....." - String appID = parameterAsString(2); - theScript = parameterExpression(3, 0, "_script", false).toString(); - checkLast(iToken); - if (isSyntaxCheck) - return; - if (appID.length() == 0 || appID.equals("all")) - appID = "*"; - if (!appID.equals(".")) { - viewer.jsEval(appID + "\1" + theScript); - if (!appID.equals("*")) + if (filename == null) { + tok = tokAt(1); + if (tok != Token.string) + error(ERROR_filenameExpected); + filename = parameterAsString(1); + if (filename.equalsIgnoreCase("applet")) { + // script APPLET x "....." + String appID = parameterAsString(2); + theScript = parameterExpression(3, 0, "_script", false).toString(); + checkLast(iToken); + if (isSyntaxCheck) return; - } - } else { - theScript = null; - tok = tokAt(statementLength - 1); - doStep = (tok == Token.step); - if (filename.equalsIgnoreCase("inline")) { - theScript = parameterExpression(2, (doStep ? statementLength - 1 : 0), - "_script", false).toString(); - i = iToken + 1; - } - while (filename.equalsIgnoreCase("localPath") - || filename.equalsIgnoreCase("remotePath") - || filename.equalsIgnoreCase("scriptPath")) { - if (filename.equalsIgnoreCase("localPath")) - localPath = parameterAsString(i++); - else if (filename.equalsIgnoreCase("scriptPath")) - scriptPath = parameterAsString(i++); - else - remotePath = parameterAsString(i++); - filename = parameterAsString(i++); - } - if ((tok = tokAt(i)) == Token.check) { - isCheck = true; - tok = tokAt(++i); - } - if (tok == Token.noload) { - loadCheck = false; - tok = tokAt(++i); - } - if (tok == Token.line || tok == Token.lines) { - i++; - lineEnd = lineNumber = Math.max(intParameter(i++), 0); - if (checkToken(i)) { - if (getToken(i).tok == Token.minus) - lineEnd = (checkToken(++i) ? intParameter(i++) : 0); - else - lineEnd = -intParameter(i++); - if (lineEnd <= 0) - error(ERROR_invalidArgument); + if (appID.length() == 0 || appID.equals("all")) + appID = "*"; + if (!appID.equals(".")) { + viewer.jsEval(appID + "\1" + theScript); + if (!appID.equals("*")) + return; } - } else if (tok == Token.command || tok == Token.commands) { - i++; - pc = Math.max(intParameter(i++) - 1, 0); - pcEnd = pc + 1; - if (checkToken(i)) { - if (getToken(i).tok == Token.minus) - pcEnd = (checkToken(++i) ? intParameter(i++) : 0); + } else { + theScript = null; + tok = tokAt(statementLength - 1); + doStep = (tok == Token.step); + if (filename.equalsIgnoreCase("inline")) { + theScript = parameterExpression(2, + (doStep ? statementLength - 1 : 0), "_script", false).toString(); + i = iToken + 1; + } + while (filename.equalsIgnoreCase("localPath") + || filename.equalsIgnoreCase("remotePath") + || filename.equalsIgnoreCase("scriptPath")) { + if (filename.equalsIgnoreCase("localPath")) + localPath = parameterAsString(i++); + else if (filename.equalsIgnoreCase("scriptPath")) + scriptPath = parameterAsString(i++); else - pcEnd = -intParameter(i++); - if (pcEnd <= 0) - error(ERROR_invalidArgument); + remotePath = parameterAsString(i++); + filename = parameterAsString(i++); } + if ((tok = tokAt(i)) == Token.check) { + isCheck = true; + tok = tokAt(++i); + } + if (tok == Token.noload) { + loadCheck = false; + tok = tokAt(++i); + } + if (tok == Token.line || tok == Token.lines) { + i++; + lineEnd = lineNumber = Math.max(intParameter(i++), 0); + if (checkToken(i)) { + if (getToken(i).tok == Token.minus) + lineEnd = (checkToken(++i) ? intParameter(i++) : 0); + else + lineEnd = -intParameter(i++); + if (lineEnd <= 0) + error(ERROR_invalidArgument); + } + } else if (tok == Token.command || tok == Token.commands) { + i++; + pc = Math.max(intParameter(i++) - 1, 0); + pcEnd = pc + 1; + if (checkToken(i)) { + if (getToken(i).tok == Token.minus) + pcEnd = (checkToken(++i) ? intParameter(i++) : 0); + else + pcEnd = -intParameter(i++); + if (pcEnd <= 0) + error(ERROR_invalidArgument); + } + } + checkLength(doStep ? i + 1 : i); } - checkLength(doStep ? i + 1 : i); } + + // processing + if (isSyntaxCheck && !isCmdLine_c_or_C_Option) return; if (isCmdLine_c_or_C_Option) @@ -13669,6 +13692,7 @@ int nFiles = 0; int nX, nY, nZ, ptX, ptY; int ptSigma = 0; + int ptCutoff = 0; BitSet bs; Vector v; Point3f[] pts; @@ -13883,6 +13907,8 @@ propertyValue = new Float(floatParameter(i)); if (colorRangeStage > 0) ++colorRangeStage; + else + ptCutoff = i; break; case Token.ionic: case Token.vanderwaals: @@ -14392,6 +14418,11 @@ propertyValue = data; break; case Token.string: + if (!surfaceObjectSeen && !planeSeen + && viewer.getParameter("_fileType").equals("Pdb") && ptSigma == 0 + && ptCutoff == 0) { + addShapeProperty(propertyList, "sigma", new Float(1)); + } propertyName = surfaceObjectSeen || planeSeen ? "mapColor" : "readFile"; /* * a file name, optionally followed by an integer file index. OR empty. @@ -14534,6 +14565,8 @@ new Object[] { colorScheme, isColorSchemeTranslucent ? Boolean.TRUE : Boolean.FALSE }); + // TODO: addShapeProperty(propertyList, "variables", thisCommandVariables); + // OK, now send them all setShapeProperty(iShape, "setProperties", propertyList); @@ -14571,8 +14604,7 @@ float cutoff = ((Float) getShapeProperty(iShape, "cutoff")) .floatValue(); if (Float.isNaN(cutoff) && ptSigma > 0) { - iToken = ptSigma; - error(ERROR_invalidArgument); + Logger.error("sigma not supported"); } s += " created with cutoff=" + cutoff; float[] minMax = (float[]) getShapeProperty(iShape, "minMaxInfo"); Modified: trunk/Jmol/src/org/jmol/script/ScriptFunction.java =================================================================== --- trunk/Jmol/src/org/jmol/script/ScriptFunction.java 2010-04-19 13:09:07 UTC (rev 12895) +++ trunk/Jmol/src/org/jmol/script/ScriptFunction.java 2010-04-20 12:25:20 UTC (rev 12896) @@ -119,7 +119,7 @@ for (int i = 0; i < nCommands; i++) { function.lineNumbers[i] = (short) (lineNumbers[cmdpt0 + i] - line0); function.lineIndices[i] = new int[] {lineIndices[cmdpt0 + i][0] - chpt0, lineIndices[cmdpt0 + i][1] - chpt0 }; - System.out.println("Line " + i + ": " + function.script.substring(function.lineIndices[i][0], function.lineIndices[i][1])); + //System.out.println("Line " + i + ": " + function.script.substring(function.lineIndices[i][0], function.lineIndices[i][1])); aatoken[i] = (Token[]) lltoken.get(cmdpt0 + i); if (aatoken[i].length > 0) { Token tokenCommand = aatoken[i][0]; Modified: trunk/Jmol/src/org/jmol/shape/MeshCollection.java =================================================================== --- trunk/Jmol/src/org/jmol/shape/MeshCollection.java 2010-04-19 13:09:07 UTC (rev 12895) +++ trunk/Jmol/src/org/jmol/shape/MeshCollection.java 2010-04-20 12:25:20 UTC (rev 12896) @@ -26,6 +26,7 @@ import org.jmol.g3d.*; import org.jmol.viewer.JmolConstants; +import org.jmol.viewer.StateManager; import org.jmol.script.Token; import java.util.BitSet; @@ -58,7 +59,7 @@ protected int modelIndex; protected boolean allowContourLines; protected boolean haveContours = false; - + public String[] title; protected boolean allowMesh = true; @@ -145,6 +146,11 @@ return; } + if ("variables" == propertyName) { + if (currentMesh != null && currentMesh.scriptCommand != null && !currentMesh.scriptCommand.startsWith("{")) + currentMesh.scriptCommand = "{\n" + StateManager.getVariableList((Hashtable) value, 0, false) + "\n" + currentMesh.scriptCommand; + return; + } if ("commandOption" == propertyName) { String s = "# " + (String) value; if (script.indexOf(s) < 0) @@ -599,6 +605,9 @@ cmd = encapsulateData(cmd, mesh.data2, "2"); if (mesh.modelIndex >= 0 && modelCount > 1) appendCmd(sb, "frame " + viewer.getModelNumberDotted(mesh.modelIndex)); + + if (cmd.charAt(0) == '{' && !cmd.endsWith("}")) + cmd += "\n}\n"; appendCmd(sb, cmd); if (mesh.ptOffset != null) appendCmd(sb, myType + " ID " + Escape.escape(mesh.thisID) + " offset " + Escape.escape(mesh.ptOffset)); Added: trunk/Jmol/src/org/jmol/util/SurfaceFileTyper.java =================================================================== --- trunk/Jmol/src/org/jmol/util/SurfaceFileTyper.java (rev 0) +++ trunk/Jmol/src/org/jmol/util/SurfaceFileTyper.java 2010-04-20 12:25:20 UTC (rev 12896) @@ -0,0 +1,154 @@ +/* $RCSfile$ + * $Author: hansonr $ + * $Date: 2007-04-05 09:07:28 -0500 (Thu, 05 Apr 2007) $ + * $Revision: 7326 $ + * + * Copyright (C) 2003-2005 The Jmol Development Team + * + * Contact: jmo...@li... + * + * 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.jmol.util; + +import java.io.BufferedInputStream; +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; + +public class SurfaceFileTyper { + + /* moved to util because drag-drop can then determine an isosurface file + * type and automatically load the file + */ + + public final static String PMESH_BINARY_MAGIC_NUMBER = "PM" + '\1' + '\0'; + + public static String determineSurfaceFileType(InputStream is) { + BufferedReader br = new BufferedReader(new InputStreamReader( + new BufferedInputStream((InputStream) is, 8192))); + return SurfaceFileTyper.determineSurfaceFileType(br); + } + + public static String determineSurfaceFileType(BufferedReader bufferedReader) { + // JVXL should be on the FIRST line of the file, but it may be + // after comments or missing. + + // Apbs, Jvxl, or Cube, also efvet + + String line; + LimitedLineReader br = new LimitedLineReader(bufferedReader, 16000); + //sure bets, but not REQUIRED: + if ((line = br.info()).length() == 0) + return null; + if (line.indexOf("<jvxl") >= 0 && line.indexOf("<?xml") >= 0) + return "JvxlXML"; + if (line.indexOf("#JVXL+") >= 0) + return "Jvxl+"; + if (line.indexOf("#JVXL") >= 0) + return "Jvxl"; + if (line.indexOf("&plot") == 0) + return "Jaguar"; + if (line.indexOf("MAP ") == 208) + return "MRC" + (line.charAt(67) == '\0' ? "L" : "B"); + if (line.indexOf("<efvet ") >= 0) + return "Efvet"; + if (line.indexOf(PMESH_BINARY_MAGIC_NUMBER) == 0) + return "Pmesh"; + if ("\n\r".indexOf(line.charAt(0)) >= 0 && line.indexOf("ZYX") >= 0) + return "Xplor"; + if (line.length() > 37 && line.charAt(36) == 0 && line.charAt(37) == 100) + return "DSN6B"; + if (line.length() > 37 && line.charAt(37) == 100 && line.charAt(36) == 0) + return "DSN6L"; + + // Apbs, Jvxl, or Cube, maybe formatted Plt + + line = br.readNonCommentLine(); + if (line.indexOf("object 1 class gridpositions counts") == 0) + return "Apbs"; + + String[] tokens = Parser.getTokens(line); + line = br.readNonCommentLine();// second line + if (tokens.length == 2 + && Parser.parseInt(tokens[0]) == 3 + && Parser.parseInt(tokens[1])!= Integer.MIN_VALUE) { + tokens = Parser.getTokens(line); + if (tokens.length == 3 + && Parser.parseInt(tokens[0])!= Integer.MIN_VALUE + && Parser.parseInt(tokens[1])!= Integer.MIN_VALUE + && Parser.parseInt(tokens[2])!= Integer.MIN_VALUE) + return "PltFormatted"; + } + line = br.readNonCommentLine(); // third line + //next line should be the atom line + int nAtoms = Parser.parseInt(line); + if (nAtoms == Integer.MIN_VALUE) + return (line.indexOf("+") == 0 ? "Jvxl+" : null); + if (nAtoms >= 0) + return "Cube"; //Can't be a Jvxl file + nAtoms = -nAtoms; + for (int i = 4 + nAtoms; --i >=0;) + if ((line = br.readNonCommentLine()) == null) + return null; + int nSurfaces = Parser.parseInt(line); + if (nSurfaces == Integer.MIN_VALUE) + return null; + return (nSurfaces < 0 ? "Jvxl" : "Cube"); //Final test looks at surface definition line + } + +} + +class LimitedLineReader { + //from Resolver + private char[] buf; + private int cchBuf; + private int ichCurrent; + + LimitedLineReader(BufferedReader bufferedReader, int readLimit) { + buf = new char[readLimit]; + try { + bufferedReader.mark(readLimit); + cchBuf = bufferedReader.read(buf); + ichCurrent = 0; + bufferedReader.reset(); + } catch (Exception e) { + } + } + + protected String info() { + return new String(buf); + } + + protected String readNonCommentLine() { + while (ichCurrent < cchBuf) { + int ichBeginningOfLine = ichCurrent; + char ch = 0; + while (ichCurrent < cchBuf && + (ch = buf[ichCurrent++]) != '\r' && ch != '\n') { + } + int cchLine = ichCurrent - ichBeginningOfLine; + if (ch == '\r' && ichCurrent < cchBuf && buf[ichCurrent] == '\n') + ++ichCurrent; + if (buf[ichBeginningOfLine] == '#') // flush comment lines; + continue; + StringBuffer sb = new StringBuffer(cchLine); + sb.append(buf, ichBeginningOfLine, cchLine); + return sb.toString(); + } + return ""; + } +} + Property changes on: trunk/Jmol/src/org/jmol/util/SurfaceFileTyper.java ___________________________________________________________________ Added: svn:mime-type + text/plain Modified: trunk/Jmol/src/org/jmol/viewer/Jmol.properties =================================================================== --- trunk/Jmol/src/org/jmol/viewer/Jmol.properties 2010-04-19 13:09:07 UTC (rev 12895) +++ trunk/Jmol/src/org/jmol/viewer/Jmol.properties 2010-04-20 12:25:20 UTC (rev 12896) @@ -3,6 +3,8 @@ version=12.0.RC7_dev +# new feature: drag-and-drop defaults for map files and PDB files +# bug fix: VRML exporter fails to remove duplicate spheres if not same color # bug fix: states not saving correct path to isosurface files # new feature: spacefill, halos, stars -x.y is "ONLY" as for other shapes # bug fix: _atomPicked not updated for centering or other non-identify actions Modified: trunk/Jmol/src/org/jmol/viewer/Viewer.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/Viewer.java 2010-04-19 13:09:07 UTC (rev 12895) +++ trunk/Jmol/src/org/jmol/viewer/Viewer.java 2010-04-20 12:25:20 UTC (rev 12896) @@ -55,6 +55,7 @@ import org.jmol.util.Escape; import org.jmol.util.JpegEncoder; import org.jmol.util.OutputStringBuffer; +import org.jmol.util.SurfaceFileTyper; import org.jmol.util.Logger; import org.jmol.util.Measure; @@ -1717,28 +1718,42 @@ private final static int FILE_STATUS_MODELSET_CREATED = 3; private final static int FILE_STATUS_MODELS_DELETED = 5; + /** + * opens a file as a model, a script, or a surface via the creation of a + * script that is queued \t at the beginning disallows script option + * + * @param fileName + */ public void openFileAsynchronously(String fileName) { - // not really asynchronously -- put on the queue just like any other file - // Jmol app file dropper, main, OpenUrlAction, RecentFilesAction - if (fileName.indexOf(".jvxl") >= 0 || fileName.indexOf(".xjvxl") >= 0) { - evalString("isosurface " + Escape.escape(fileName)); - return; - } boolean allowScript = (!fileName.startsWith("\t")); if (!allowScript) fileName = fileName.substring(1); fileName = fileName.replace('\\', '/'); if (isApplet && fileName.indexOf("://") < 0) fileName = "file://" + (fileName.startsWith("/") ? "" : "/") + fileName; - String type = fileManager.getFileTypeName(fileName); - // checkHalt("exit", true); - // assumes a Jmol script file if no other file type - allowScript &= (type == null); - if (scriptEditorVisible && allowScript) + + String cmd = null; + if (fileName.endsWith("jvxl")) + cmd = "isosurface "; + else if (!fileName.endsWith(".spt")) { + String type = fileManager.getFileTypeName(fileName); + if (type == null) { + type = SurfaceFileTyper + .determineSurfaceFileType(getBufferedInputStream(fileName)); + if (type != null) { + evalString("if (_filetype == 'Pdb') { isosurface sigma 1.0 within 2.0 {*} " + Escape.escape(fileName) + " mesh nofill }; else; { isosurface " + Escape.escape(fileName) + "}"); + return; + } + } else if (!type.equals("spt")) { + evalString("zap; load " + Escape.escape(fileName) + + ";if (_loadScript = '' && defaultLoadScript == '' && _filetype == 'Pdb') { select protein or nucleic;cartoons Only;color structure; select * }" ); + return; + } + } + if (allowScript && scriptEditorVisible && cmd == null) showEditor(new String[] { fileName, getFileAsString(fileName) }); else - evalString((allowScript ? "script " : "zap;load ") - + Escape.escape(fileName)); + evalString((cmd == null ? "script " : cmd) + Escape.escape(fileName)); } /** Modified: trunk/Jmol/src/org/openscience/jmol/app/JmolApp.java =================================================================== --- trunk/Jmol/src/org/openscience/jmol/app/JmolApp.java 2010-04-19 13:09:07 UTC (rev 12895) +++ trunk/Jmol/src/org/openscience/jmol/app/JmolApp.java 2010-04-20 12:25:20 UTC (rev 12896) @@ -453,7 +453,7 @@ // Open a file if one is given as an argument -- note, this CAN be a // script file if (modelFilename != null) { - viewer.openFileAsynchronously(modelFilename); + viewer.openFile(modelFilename); } // OK, by now it is time to execute the script This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |