From: <ha...@us...> - 2010-02-27 13:20:17
|
Revision: 12488 http://jmol.svn.sourceforge.net/jmol/?rev=12488&view=rev Author: hansonr Date: 2010-02-27 13:20:08 +0000 (Sat, 27 Feb 2010) Log Message: ----------- version=11.9.31_dev # new feature: isosurface map DNS6/O reader Modified Paths: -------------- trunk/Jmol/src/org/jmol/jvxl/data/JvxlData.java trunk/Jmol/src/org/jmol/jvxl/readers/ApbsReader.java trunk/Jmol/src/org/jmol/jvxl/readers/MapFileReader.java trunk/Jmol/src/org/jmol/jvxl/readers/MrcBinaryReader.java trunk/Jmol/src/org/jmol/jvxl/readers/Parameters.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/jvxl/readers/XplorReader.java trunk/Jmol/src/org/jmol/viewer/Jmol.properties Added Paths: ----------- trunk/Jmol/src/org/jmol/jvxl/readers/Dns6Reader.java Modified: trunk/Jmol/src/org/jmol/jvxl/data/JvxlData.java =================================================================== --- trunk/Jmol/src/org/jmol/jvxl/data/JvxlData.java 2010-02-26 22:39:27 UTC (rev 12487) +++ trunk/Jmol/src/org/jmol/jvxl/data/JvxlData.java 2010-02-27 13:20:08 UTC (rev 12488) @@ -102,6 +102,7 @@ public int colorFractionBase = JvxlCoder.defaultColorFractionBase; public int colorFractionRange = JvxlCoder.defaultColorFractionRange; + public boolean dataXYReversed; public boolean insideOut; public boolean isXLowToHigh; public boolean isContoured; Modified: trunk/Jmol/src/org/jmol/jvxl/readers/ApbsReader.java =================================================================== --- trunk/Jmol/src/org/jmol/jvxl/readers/ApbsReader.java 2010-02-26 22:39:27 UTC (rev 12487) +++ trunk/Jmol/src/org/jmol/jvxl/readers/ApbsReader.java 2010-02-27 13:20:08 UTC (rev 12488) @@ -32,7 +32,8 @@ ApbsReader(SurfaceGenerator sg, BufferedReader br) { super(sg, br); // data are HIGH on the inside and LOW on the outside - params.insideOut = !params.insideOut; + if (params.thePlane == null) + params.insideOut = !params.insideOut; isAngstroms = true; nSurfaces = 1; } Added: trunk/Jmol/src/org/jmol/jvxl/readers/Dns6Reader.java =================================================================== --- trunk/Jmol/src/org/jmol/jvxl/readers/Dns6Reader.java (rev 0) +++ trunk/Jmol/src/org/jmol/jvxl/readers/Dns6Reader.java 2010-02-27 13:20:08 UTC (rev 12488) @@ -0,0 +1,257 @@ +/* $RCSfile$ + * $Author: hansonr $ + * $Date: 2007-03-30 11:40:16 -0500 (Fri, 30 Mar 2007) $ + * $Revision: 7273 $ + * + * Copyright (C) 2007 Miguel, Bob, Jmol Development + * + * Contact: ha...@st... + * + * 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 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.jvxl.readers; + +import java.io.DataInputStream; +import java.io.StringBufferInputStream; + +import org.jmol.util.BinaryDocument; +import org.jmol.util.Logger; + +class Dns6BinaryReader extends MapFileReader { + + /* + * also referred to as "O" format + * + * see http://www.ks.uiuc.edu/Research/vmd/plugins/doxygen/dsn6plugin_8C-source.html + * + */ + + + Dns6BinaryReader(SurfaceGenerator sg, String fileName, String data) { + super(sg, null); + binarydoc = new BinaryDocument(); + if (data == null) + binarydoc.setStream(sg.getAtomDataServer().getBufferedInputStream(fileName), true); + else + binarydoc.setStream(new DataInputStream(new StringBufferInputStream(data))); + // data are HIGH on the inside and LOW on the outside + if (params.thePlane == null) + params.insideOut = !params.insideOut; + nSurfaces = 1; + } + + float byteFactor, byteOffset; + private int xyCount; + private int nBrickX, nBrickY; + private int brickLayerVoxelCount; + private int brickLayerByteCount; + private int brickRowByteCount; + private byte[] brickLayer; + private float dmin, dmax, drange; + + protected void readParameters() throws Exception { + + nxyzStart[0] = binarydoc.readShort(); + nxyzStart[1] = binarydoc.readShort(); + nxyzStart[2] = binarydoc.readShort(); + + nx = binarydoc.readShort(); // CCP4 "extent[0-2]" + ny = binarydoc.readShort(); + nz = binarydoc.readShort(); + + na = binarydoc.readShort(); // CCP4 "grid[0-2]" + nb = binarydoc.readShort(); + nc = binarydoc.readShort(); + + a = binarydoc.readShort(); + b = binarydoc.readShort(); + c = binarydoc.readShort(); + alpha = binarydoc.readShort(); + beta = binarydoc.readShort(); + gamma = binarydoc.readShort(); + + maps = 3; + mapr = 2; + mapc = 1; + + // range parameters are adjusted to be short integers + // + // original: byte range b from 3 to 253 for data values m to M + // [ref: http://www.uoxray.uoregon.edu/tnt/manual/node104.html] + // + // value = [ (b - 3) / 250 ] (M - m) + m + // = [ b - 3 ] * (M - m) / 250 + m + // = [ b - 3 + m * 250 / (M - m) ] * (M - m) / 250 + // = [ b - (3 (M - m) - 250 m) / (M - m) ] * (M - m) / 250 + // = [ b - (3M - 253m) / (M - m) ] * (M - m) / 250 + // = [ b - header17 ] * header19 / header16 + // + // where header16 = 100 * 250 / (M - m) + // and header17 = (3M - 253m) / (M - m) + // and header19 = 100 + // + // Comment: Perhaps, but what it is actually is simply this: + // [ref: empirical fit to CCP4 and XPLOR data from Uppsala server] + // + // value = [ b / 255 ] (M - m) + m + // + // That is, we are just scaling min to max allowing for a range of 255 byte values. + // So then what we REALLY have is this: + // + // value = [ b / 255 ] (M - m) + m + // = [ b ] * (M - m) / 255 + m + // = [ b + m * 255 / (M - m) ] * (M - m) / 255 + // = [ b - (-255 m) / (M - m) ] * (M - m) / 255 + // = [ b - header17 ] * header19 / header16 + // + // where header16 = 100 * 255 / (M - m) + // and header17 = -255m / (M - m) + // and header19 = 100 + // + // If you ask me, this is rather odd, because you + // then have restricted the resolution to only 255 possible values. + // Is the raw data really that low resolution? + // + // In any case, what we do here is simply to + // calculate min and max from headers 16, 17, and 19, + // and then just use: + // + // value = min + b * byteFactor + // + // where byteFactor = (M - m) / 255 + // + // Just seens simpler to me. Bob Hanson 2/2010 + + float header16 = binarydoc.readShort(); // 100 * 255 / (dmax - dmin) + float header17 = binarydoc.readShort(); // -255dmin / (dmax - dmin) + float scalingFactor = binarydoc.readShort(); + float header19 = binarydoc.readShort(); + dmin = (0 - header17) * header19 / header16; + dmax = (255 - header17) * header19 / header16; + drange = dmax - dmin; + byteFactor = drange / 255; + + Logger.info("DNS6 dmin,dmax = " + dmin + "," + dmax); + + a /= scalingFactor; + b /= scalingFactor; + c /= scalingFactor; + alpha /= scalingFactor; + beta /= scalingFactor; + gamma /= scalingFactor; + + binarydoc.seek(0x200); + + getVectorsAndOrigin(); + + if (params.thePlane == null && params.cutoffAutomatic) { + params.cutoff = (boundingBox == null ? 3.0f : 1.6f); + Logger.info("DNS6Reader: setting cutoff to default value of " + params.cutoff + (boundingBox == null ? " (no BOUNDBOX parameter)\n" : "\n")); + } + + xyCount = nx * ny; + brickLayerVoxelCount = xyCount * 8; + // byte blocks are 8 layers of 8x8 voxels, with remainders + nBrickX = (nx + 7) / 8; + nBrickY = (ny + 7) / 8; + brickRowByteCount = nBrickX * 512; + brickLayerByteCount = brickRowByteCount * nBrickY; + brickLayer = new byte[brickLayerByteCount]; + + jvxlFileHeaderBuffer = new StringBuffer(); + jvxlFileHeaderBuffer.append("DNS6/O progressive brick data reader\n"); + jvxlFileHeaderBuffer + .append("see http://www.uoxray.uoregon.edu/tnt/manual/node104.html\n"); + + } + + private int pt; + private void readBrickLayer() throws Exception { + /* + * Read one full layer of nBrickX*nBrickY 8x8x8 "bricks". + * + */ + binarydoc.readByteArray(brickLayer); + pt = 0; + nBytes = binarydoc.getPosition(); + } + + private float getBrickValue(int pt) { + /* + * pt runs from [0, n), where n is the number of voxels in a layer of bricks + * But we are running at a specific z through the xy plane, rapidly throuch x. + * You can think of the strips of data being laid out in this order: + * + * brick 0,0,0: + * z = 0, y = 0, x [0-7] + * ... + * z = 0, y = 7, x [0-7] + * z = 1, y = 0, x [0-7] + * ... + * z = 7, y = 7, x [0-7] + * + * brick 0,0,8: + * z = 0, y = 0, x [8-15] + * ... + * z = 0, y = 7, x [8-15] + * z = 1, y = 0, x [8-15] + * ... + * z = 7, y = 7, x [8-15] + * + * So we need to reconstruct from the pointer x, y, and z. + * + */ + + // within the data: + + int x = pt % nx; + int y = (pt / nx) % ny; + int z = pt / xyCount; + + // within the brick: + + int brickX = x % 8; + int brickY = y % 8; + int brickZ = z % 8; + + // brick pointers: + + int bX = x / 8; + int bY = y / 8; + // brick row brick col + int bPt = bY * 512 * nBrickX + bX * 512 + brickZ * 64 + brickY * 8 + brickX; + + // reversing byte order: + + if (bPt % 2 == 0) + bPt++; + else + bPt--; + // bytes read can be negative + float value = ((int) brickLayer[bPt] + 256) % 256; + return dmin + value * byteFactor; + } + + protected float nextVoxel() throws Exception { + if ((pt % brickLayerVoxelCount) == 0) + readBrickLayer(); + return getBrickValue(pt++); + } + + protected void skipData(int nPoints) throws Exception { + for (int i = 0; i < nPoints; i++) + binarydoc.readByte(); + } +} Property changes on: trunk/Jmol/src/org/jmol/jvxl/readers/Dns6Reader.java ___________________________________________________________________ Added: svn:mime-type + text/plain Modified: trunk/Jmol/src/org/jmol/jvxl/readers/MapFileReader.java =================================================================== --- trunk/Jmol/src/org/jmol/jvxl/readers/MapFileReader.java 2010-02-26 22:39:27 UTC (rev 12487) +++ trunk/Jmol/src/org/jmol/jvxl/readers/MapFileReader.java 2010-02-27 13:20:08 UTC (rev 12488) @@ -168,7 +168,7 @@ volumetricOrigin.set(origin); Logger.info("Jmol grid origin in Cartesian coordinates: " + origin); - Logger.info("Use isosurface OFFSET {x y z} if you want to shift it."); + Logger.info("Use isosurface OFFSET {x y z} if you want to shift it.\n"); /* example: Modified: trunk/Jmol/src/org/jmol/jvxl/readers/MrcBinaryReader.java =================================================================== --- trunk/Jmol/src/org/jmol/jvxl/readers/MrcBinaryReader.java 2010-02-26 22:39:27 UTC (rev 12487) +++ trunk/Jmol/src/org/jmol/jvxl/readers/MrcBinaryReader.java 2010-02-27 13:20:08 UTC (rev 12488) @@ -33,6 +33,10 @@ /* * also referred to as CCP4 format + * + * examples include the emd_1xxx..map electron microscopy files + * and xxxx.ccp4 files + * * */ @@ -45,9 +49,9 @@ else binarydoc.setStream(new DataInputStream(new StringBufferInputStream(data))); // data are HIGH on the inside and LOW on the outside + nSurfaces = 1; if (params.thePlane == null) params.insideOut = !params.insideOut; - nSurfaces = 1; allowSigma = true; } @@ -139,6 +143,9 @@ mapr = binarydoc.readInt(); maps = binarydoc.readInt(); + if (mapc != 1 && params.thePlane == null) + params.dataXYReversed = true; + dmin = binarydoc.readFloat(); dmax = binarydoc.readFloat(); dmean = binarydoc.readFloat(); @@ -197,20 +204,14 @@ // setting the cutoff to mean + 2 x RMS seems to work // reasonably well as a default. - if (params.thePlane == null) { - if (params.sigma != Float.MAX_VALUE) { - params.cutoff = rmsDeviation * params.sigma + dmean; - Logger.info("Cutoff set to (mean + rmsDeviation*" + params.sigma + ") = " + params.cutoff); - } else if (params.cutoffAutomatic) { - params.cutoff = rmsDeviation + dmean; - Logger.info("Cutoff set to sigma 1.0 or (mean + rmsDeviation) = " + params.cutoff); - } + getVectorsAndOrigin(); + + if (params.thePlane == null && (params.cutoffAutomatic || params.sigma != Float.MAX_VALUE)) { + float sigma = (params.sigma == Float.MAX_VALUE ? 1 : params.sigma); + params.cutoff = rmsDeviation * sigma + dmean; + Logger.info("Cutoff set to (mean + rmsDeviation*" + params.sigma + ")\n"); } - getVectorsAndOrigin(); - - Logger.info("\n"); - jvxlFileHeaderBuffer = new StringBuffer(); jvxlFileHeaderBuffer.append("MRC DATA ").append(labels[0]).append("\n"); jvxlFileHeaderBuffer.append("see http://ami.scripps.edu/software/mrctools/mrc_specification.php\n"); Modified: trunk/Jmol/src/org/jmol/jvxl/readers/Parameters.java =================================================================== --- trunk/Jmol/src/org/jmol/jvxl/readers/Parameters.java 2010-02-26 22:39:27 UTC (rev 12487) +++ trunk/Jmol/src/org/jmol/jvxl/readers/Parameters.java 2010-02-27 13:20:08 UTC (rev 12488) @@ -196,6 +196,7 @@ colorPosLCAO = defaultColorPositiveLCAO; cutoff = Float.MAX_VALUE; cutoffAutomatic = true; + dataXYReversed = false; distance = Float.MAX_VALUE; envelopeRadius = 10f; fileIndex = 1; @@ -690,6 +691,7 @@ public boolean isXLowToHigh; boolean insideOut; + boolean dataXYReversed; public float cutoff = Float.MAX_VALUE; public float sigma = Float.MAX_VALUE; // for MrcReader boolean cutoffAutomatic = true; Modified: trunk/Jmol/src/org/jmol/jvxl/readers/SurfaceFileReader.java =================================================================== --- trunk/Jmol/src/org/jmol/jvxl/readers/SurfaceFileReader.java 2010-02-26 22:39:27 UTC (rev 12487) +++ trunk/Jmol/src/org/jmol/jvxl/readers/SurfaceFileReader.java 2010-02-27 13:20:08 UTC (rev 12488) @@ -93,6 +93,8 @@ 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 "DNS6"; // Apbs, Jvxl, or Cube, maybe formatted Plt Modified: trunk/Jmol/src/org/jmol/jvxl/readers/SurfaceGenerator.java =================================================================== --- trunk/Jmol/src/org/jmol/jvxl/readers/SurfaceGenerator.java 2010-02-26 22:39:27 UTC (rev 12487) +++ trunk/Jmol/src/org/jmol/jvxl/readers/SurfaceGenerator.java 2010-02-27 13:20:08 UTC (rev 12488) @@ -293,7 +293,7 @@ } public boolean isInsideOut() { - return params.insideOut; + return params.insideOut != params.dataXYReversed; } public float getCutoff() { @@ -1109,6 +1109,15 @@ br = null; return new MrcBinaryReader(this, params.fileName, data, fileType.charAt(3) == '+'); } + if (fileType.equals("DNS6")) { + try { + br.close(); + } catch (IOException e) { + // ignore + } + br = null; + return new Dns6BinaryReader(this, params.fileName, data); + } if (fileType.equals("Efvet")) return new EfvetReader(this,br); if (fileType.equals("Pmesh")) Modified: trunk/Jmol/src/org/jmol/jvxl/readers/SurfaceReader.java =================================================================== --- trunk/Jmol/src/org/jmol/jvxl/readers/SurfaceReader.java 2010-02-26 22:39:27 UTC (rev 12487) +++ trunk/Jmol/src/org/jmol/jvxl/readers/SurfaceReader.java 2010-02-27 13:20:08 UTC (rev 12488) @@ -327,6 +327,7 @@ nPointsY = voxelCounts[1]; nPointsZ = voxelCounts[2]; jvxlData.insideOut = params.insideOut; + jvxlData.dataXYReversed = params.dataXYReversed; jvxlData.nPointsX = nPointsX; jvxlData.nPointsY = nPointsY; jvxlData.nPointsZ = nPointsZ; Modified: trunk/Jmol/src/org/jmol/jvxl/readers/XplorReader.java =================================================================== --- trunk/Jmol/src/org/jmol/jvxl/readers/XplorReader.java 2010-02-26 22:39:27 UTC (rev 12487) +++ trunk/Jmol/src/org/jmol/jvxl/readers/XplorReader.java 2010-02-27 13:20:08 UTC (rev 12488) @@ -96,7 +96,8 @@ XplorReader(SurfaceGenerator sg, BufferedReader br) { super(sg, br); - params.insideOut = !params.insideOut; + if (params.thePlane == null) + params.insideOut = !params.insideOut; nSurfaces = 1; } @@ -140,12 +141,12 @@ getVectorsAndOrigin(); - nBlock = voxelCounts[2] * voxelCounts[1]; - if (params.cutoffAutomatic && params.thePlane == null) { + if (params.thePlane == null && params.cutoffAutomatic) { params.cutoff = (boundingBox == null ? 3.0f : 1.6f); - Logger.info("XplorReader: setting cutoff to default value of " + params.cutoff + (boundingBox == null ? " (no BOUNDBOX parameter)" : "")); + Logger.info("XplorReader: setting cutoff to default value of " + params.cutoff + (boundingBox == null ? " (no BOUNDBOX parameter)\n" : "\n")); } + nBlock = voxelCounts[2] * voxelCounts[1]; } Modified: trunk/Jmol/src/org/jmol/viewer/Jmol.properties =================================================================== --- trunk/Jmol/src/org/jmol/viewer/Jmol.properties 2010-02-26 22:39:27 UTC (rev 12487) +++ trunk/Jmol/src/org/jmol/viewer/Jmol.properties 2010-02-27 13:20:08 UTC (rev 12488) @@ -3,6 +3,7 @@ version=11.9.31_dev +# new feature: isosurface map DNS6/O reader # bug fix: load models {(.....)} not preserved in state # code: simpler adapter class -- atomSetNames and atomSetProperties into atomSetAuxiliaryInfo # new feature: frame TITLE alone sets title to "@{_modelName}" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |