Пример #1
0
 private void setProp(Ellipsoid e, int mode, Object value) {
   // "ax ce co de eq mo on op sc tr"
   //  0  1  2  3  4  5  6  7  8  9
   switch (mode) {
     case 0: // axes
       e.setTensor(
           ((Tensor) Interface.getUtil("Tensor", vwr, "script")).setFromAxes((V3[]) value));
       return;
     case 1: // center
       e.setCenter((P3) value);
       return;
     case 2: // color
       e.colix = C.getColixO(value);
       return;
     case 3: // delete
       simpleEllipsoids.remove(e.id);
       return;
     case 4: // equation
       e.setTensor(
           ((Tensor) Interface.getUtil("Tensor", vwr, "script"))
               .setFromThermalEquation((double[]) value, null));
       return;
     case 5: // modelindex
       e.tensor.modelIndex = ((Integer) value).intValue();
       return;
     case 6: // on
       e.isOn = ((Boolean) value).booleanValue();
       return;
     case 7: // options
       e.options = ((String) value).toLowerCase();
       return;
     case 8: // scale
       e.setScale(((Float) value).floatValue(), false);
       return;
     case 9: // translucency
       e.colix = C.getColixTranslucent3(e.colix, value.equals("translucent"), translucentLevel);
       return;
   }
   return;
 }
Пример #2
0
 protected void jvxlDecodeContourData(JvxlData jvxlData, String data) throws Exception {
   List<List<Object>> vs = new List<List<Object>>();
   SB values = new SB();
   SB colors = new SB();
   int pt = -1;
   jvxlData.vContours = null;
   if (data == null) return;
   while ((pt = data.indexOf("<jvxlContour", pt + 1)) >= 0) {
     List<Object> v = new List<Object>();
     String s = xr.getXmlData("jvxlContour", data.substring(pt), true, false);
     float value = parseFloatStr(XmlReader.getXmlAttrib(s, "value"));
     values.append(" ").appendF(value);
     int color = getColor(XmlReader.getXmlAttrib(s, "color"));
     short colix = C.getColix(color);
     colors.append(" ").append(Escape.escapeColor(color));
     String fData = JvxlCoder.jvxlDecompressString(XmlReader.getXmlAttrib(s, "data"));
     BS bs = JvxlCoder.jvxlDecodeBitSet(xr.getXmlData("jvxlContour", s, false, false));
     int n = bs.length();
     IsosurfaceMesh.setContourVector(v, n, bs, value, colix, color, SB.newS(fData));
     vs.addLast(v);
   }
   int n = vs.size();
   if (n > 0) {
     jvxlData.vContours = AU.createArrayOfArrayList(n);
     // 3D contour values and colors
     jvxlData.contourColixes = params.contourColixes = new short[n];
     jvxlData.contourValues = params.contoursDiscrete = new float[n];
     for (int i = 0; i < n; i++) {
       jvxlData.vContours[i] = vs.get(i);
       jvxlData.contourValues[i] = ((Float) jvxlData.vContours[i].get(2)).floatValue();
       jvxlData.contourColixes[i] = ((short[]) jvxlData.vContours[i].get(3))[0];
     }
     jvxlData.contourColors = C.getHexCodes(jvxlData.contourColixes);
     Logger.info("JVXL read: " + n + " discrete contours");
     Logger.info("JVXL read: contour values: " + values);
     Logger.info("JVXL read: contour colors: " + colors);
   }
 }
Пример #3
0
 private void drawSegment(Atom atomA, Atom atomB, short colixA, short colixB, float max) {
   if (atomA.getNBackbonesDisplayed() == 0
       || atomB.getNBackbonesDisplayed() == 0
       || ms.isAtomHidden(atomB.i)
       || !isDataFrame && atomA.distanceSquared(atomB) > max) return;
   colixA = C.getColixInherited(colixA, atomA.colixAtom);
   colixB = C.getColixInherited(colixB, atomB.colixAtom);
   if (!isExport && !isPass2 && !setBioColix(colixA) && !setBioColix(colixB)) return;
   int xA = atomA.sX, yA = atomA.sY, zA = atomA.sZ;
   int xB = atomB.sX, yB = atomB.sY, zB = atomB.sZ;
   int mad = this.mad;
   if (max == 1000) mad = mad >> 1;
   if (mad < 0) {
     g3d.drawLine(colixA, colixB, xA, yA, zA, xB, yB, zB);
   } else {
     int width =
         (int)
             (exportType == GData.EXPORT_CARTESIAN
                 ? mad
                 : vwr.tm.scaleToScreen((zA + zB) / 2, mad));
     g3d.fillCylinderXYZ(colixA, colixB, GData.ENDCAPS_SPHERICAL, width, xA, yA, zA, xB, yB, zB);
   }
 }
Пример #4
0
  @Override
  protected String readColorData() {
    if (!jvxlDataIsColorMapped) return "";
    // overloads SurfaceReader
    // standard jvxl file read for color

    int vertexCount = jvxlData.vertexCount = meshData.vertexCount;
    // the problem is that the new way to read data in Marching Cubes
    // is to ignore all points that are NaN. But then we also have to
    // remove those points from the color string.

    short[] colixes = meshData.vertexColixes;
    float[] vertexValues = meshData.vertexValues;
    /*
     * haveReadColorData?
     = (isJvxl ? jvxlColorDataRead : "");
    if (isJvxl && strValueTemp.length() == 0) {
      Logger
          .error("You cannot use JVXL data to map onto OTHER data, because it only contains the data for one surface. Use ISOSURFACE \"file.jvxl\" not ISOSURFACE .... MAP \"file.jvxl\".");
      return "";
    }
    */

    if ("none".equals(jvxlColorEncodingRead)) {
      jvxlData.vertexColors = new int[vertexCount];
      int[] nextc = new int[1];
      int n = PT.parseIntNext(jvxlColorDataRead, nextc);
      n = Math.min(n, vertexCount);
      String[] tokens = PT.getTokens(jvxlColorDataRead.substring(nextc[0]));
      boolean haveTranslucent = false;
      float trans = jvxlData.translucency;
      int lastColor = 0;
      for (int i = 0; i < n; i++)
        // colix will be one of 8 shades of translucent if A in ARGB is not FF.
        try {
          int c = getColor(tokens[i]);
          if (c == 0) c = lastColor;
          else lastColor = c;
          colixes[i] = C.getColixTranslucent(jvxlData.vertexColors[i] = c);
          if (C.isColixTranslucent(colixes[i])) haveTranslucent = true;
          else if (trans != 0) colixes[i] = C.getColixTranslucent3(colixes[i], true, trans);
        } catch (Exception e) {
          Logger.info("JvxlXmlReader: Cannot interpret color code: " + tokens[i]);
          // ignore this color if parsing error
        }
      if (haveTranslucent && trans == 0) {
        // set to show in pass2
        jvxlData.translucency = 0.5f;
      }
      return "-";
    }
    if (params.colorEncoder == null) params.colorEncoder = new ColorEncoder(null);
    params.colorEncoder.setColorScheme(null, false);
    params.colorEncoder.setRange(
        params.valueMappedToRed, params.valueMappedToBlue, params.isColorReversed);
    Logger.info(
        "JVXL reading color data mapped min/max: "
            + params.mappedDataMin
            + "/"
            + params.mappedDataMax
            + " for "
            + vertexCount
            + " vertices."
            + " using encoding keys "
            + colorFractionBase
            + " "
            + colorFractionRange);
    Logger.info(
        "mapping red-->blue for "
            + params.valueMappedToRed
            + " to "
            + params.valueMappedToBlue
            + " colorPrecision:"
            + jvxlData.isJvxlPrecisionColor);
    boolean getValues = (Float.isNaN(valueMin));
    if (getValues) setValueMinMax();
    float contourPlaneMinimumValue = Float.MAX_VALUE;
    float contourPlaneMaximumValue = -Float.MAX_VALUE;
    if (colixes == null || colixes.length < vertexCount)
      meshData.vertexColixes = colixes = new short[vertexCount];
    // hasColorData = true;
    short colixNeg = 0, colixPos = 0;
    if (params.colorBySign) {
      colixPos = C.getColix(params.isColorReversed ? params.colorNeg : params.colorPos);
      colixNeg = C.getColix(params.isColorReversed ? params.colorPos : params.colorNeg);
    }
    int vertexIncrement = meshData.vertexIncrement;
    // here's the problem: we are assuming here that vertexCount == nPointsRead
    boolean needContourMinMax = (params.mappedDataMin == Float.MAX_VALUE);
    for (int i = 0; i < vertexCount; i += vertexIncrement) {
      float value;
      if (getValues) value = vertexValues[i] = getNextValue();
      else value = vertexValues[i];
      if (needContourMinMax) {
        if (value < contourPlaneMinimumValue) contourPlaneMinimumValue = value;
        if (value > contourPlaneMaximumValue) contourPlaneMaximumValue = value;
      }
    }
    if (needContourMinMax) {
      params.mappedDataMin = contourPlaneMinimumValue;
      params.mappedDataMax = contourPlaneMaximumValue;
    }
    if (jvxlData.colorScheme != null)
      for (int i = 0; i < vertexCount; i += vertexIncrement) {
        float value = vertexValues[i];
        // note: these are just default colorings
        // orbital color had a bug through 11.2.6/11.3.6
        if (marchingSquares != null && params.isContoured) {
          marchingSquares.setContourData(i, value);
          continue;
        }
        short colix =
            (!params.colorBySign
                ? params.colorEncoder.getColorIndex(value)
                : (params.isColorReversed ? value > 0 : value <= 0) ? colixNeg : colixPos);
        colixes[i] = C.getColixTranslucent3(colix, true, jvxlData.translucency);
      }
    return jvxlColorDataRead + "\n";
  }
Пример #5
0
  protected void jvxlReadSurfaceInfo() throws Exception {
    String s;
    String data = xr.getXmlData("jvxlSurfaceInfo", null, true, true);
    isXLowToHigh = XmlReader.getXmlAttrib(data, "isXLowToHigh").equals("true");
    jvxlCutoff = parseFloatStr(XmlReader.getXmlAttrib(data, "cutoff"));
    if (!Float.isNaN(jvxlCutoff)) Logger.info("JVXL read: cutoff " + jvxlCutoff);
    int nContourData = parseIntStr(XmlReader.getXmlAttrib(data, "nContourData"));
    haveContourData = (nContourData > 0);
    params.isContoured = XmlReader.getXmlAttrib(data, "contoured").equals("true");
    if (params.isContoured) {
      int nContoursRead = parseIntStr(XmlReader.getXmlAttrib(data, "nContours"));
      if (nContoursRead <= 0) {
        nContoursRead = 0;
      } else {
        s = XmlReader.getXmlAttrib(data, "contourValues");
        if (s.length() > 0) {
          jvxlData.contourValues = params.contoursDiscrete = parseFloatArrayStr(s);
          Logger.info("JVXL read: contourValues " + Escape.eAF(jvxlData.contourValues));
        }
        s = XmlReader.getXmlAttrib(data, "contourColors");
        if (s.length() > 0) {
          jvxlData.contourColixes = params.contourColixes = C.getColixArray(s);
          jvxlData.contourColors = C.getHexCodes(jvxlData.contourColixes);
          Logger.info("JVXL read: contourColixes " + C.getHexCodes(jvxlData.contourColixes));
        }
        params.contourFromZero = XmlReader.getXmlAttrib(data, "contourFromZero").equals("true");
      }
      params.nContours = (haveContourData ? nContourData : nContoursRead);
      // TODO ? params.contourFromZero = false; // MEP data to complete the plane
    }
    jvxlData.nVertexColors = parseIntStr(XmlReader.getXmlAttrib(data, "nVertexColors"));
    params.isBicolorMap = XmlReader.getXmlAttrib(data, "bicolorMap").equals("true");
    if (params.isBicolorMap) {
      // TODO -- not quite right, because
      s = XmlReader.getXmlAttrib(data, "colorPositive");
      if (s.length() > 0
          && params.colorRgb == Integer.MIN_VALUE
          && params.colorPos == Parameters.defaultColorPositive)
        params.colorPos = CU.getArgbFromString(s);
      s = XmlReader.getXmlAttrib(data, "colorNegative");
      if (s.length() > 0
          && params.colorRgb == Integer.MIN_VALUE
          && params.colorNeg == Parameters.defaultColorNegative)
        params.colorNeg = CU.getArgbFromString(s);
    }
    if (params.isBicolorMap || params.colorBySign) jvxlCutoff = 0;
    jvxlDataIsColorMapped =
        ((params.colorRgb == Integer.MIN_VALUE || params.colorRgb == Integer.MAX_VALUE)
            && (params.isBicolorMap || XmlReader.getXmlAttrib(data, "colorMapped").equals("true")));
    // isJvxlPrecisionColor is for information only -- will be superceded by encoding attribute of
    // jvxlColorData
    jvxlData.isJvxlPrecisionColor = XmlReader.getXmlAttrib(data, "precisionColor").equals("true");
    jvxlData.jvxlDataIsColorDensity =
        params.colorDensity =
            (params.colorRgb == Integer.MIN_VALUE
                && XmlReader.getXmlAttrib(data, "colorDensity").equals("true"));
    if (jvxlData.jvxlDataIsColorDensity && Float.isNaN(params.pointSize)) {
      s = XmlReader.getXmlAttrib(data, "pointSize");
      if (s.length() > 0) jvxlData.pointSize = params.pointSize = parseFloatStr(s);
    }
    s = XmlReader.getXmlAttrib(data, "allowVolumeRender");
    jvxlData.allowVolumeRender =
        params.allowVolumeRender = (s.length() == 0 || s.equalsIgnoreCase("true"));
    s = XmlReader.getXmlAttrib(data, "plane");
    if (s.indexOf("{") >= 0) {
      params.thePlane = null;
      params.mapLattice = null;
      try {
        params.thePlane = (P4) Escape.uP(s);
        s = XmlReader.getXmlAttrib(data, "maplattice");
        Logger.info("JVXL read: plane " + params.thePlane);
        if (s.indexOf("{") >= 0) {
          params.mapLattice = (P3) Escape.uP(s);
          Logger.info("JVXL read: mapLattice " + params.mapLattice);
        }
        if (params.scale3d == 0)
          params.scale3d = parseFloatStr(XmlReader.getXmlAttrib(data, "scale3d"));
        if (Float.isNaN(params.scale3d)) params.scale3d = 0;
      } catch (Exception e) {
        if (params.thePlane == null) {
          Logger.error("JVXL Error reading plane definition -- setting to 0 0 1 0  (z=0)");
          params.thePlane = P4.new4(0, 0, 1, 0);
        } else {
          Logger.error("JVXL Error reading mapLattice definition -- ignored");
        }
      }
      surfaceDataCount = 0;
      edgeDataCount = 0;
    } else {
      params.thePlane = null;
      surfaceDataCount = parseIntStr(XmlReader.getXmlAttrib(data, "nSurfaceInts"));
      edgeDataCount = parseIntStr(XmlReader.getXmlAttrib(data, "nBytesUncompressedEdgeData"));
    }
    excludedVertexCount = parseIntStr(XmlReader.getXmlAttrib(data, "nExcludedVertexes"));
    excludedTriangleCount = parseIntStr(XmlReader.getXmlAttrib(data, "nExcludedTriangles"));
    invalidatedVertexCount = parseIntStr(XmlReader.getXmlAttrib(data, "nInvalidatedVertexes"));
    s = XmlReader.getXmlAttrib(data, "slabInfo");
    if (s.length() > 0) jvxlData.slabInfo = s;
    colorDataCount =
        Math.max(0, parseIntStr(XmlReader.getXmlAttrib(data, "nBytesUncompressedColorData")));
    jvxlDataIs2dContour = (params.thePlane != null && jvxlDataIsColorMapped);

    // new Jmol 12.1.50
    jvxlData.color = XmlReader.getXmlAttrib(data, "color");
    if (jvxlData.color.length() == 0 || jvxlData.color.indexOf("null") >= 0)
      jvxlData.color = "orange";
    jvxlData.translucency = parseFloatStr(XmlReader.getXmlAttrib(data, "translucency"));
    if (Float.isNaN(jvxlData.translucency)) jvxlData.translucency = 0;
    s = XmlReader.getXmlAttrib(data, "meshColor");
    if (s.length() > 0) jvxlData.meshColor = s;
    s = XmlReader.getXmlAttrib(data, "rendering");
    if (s.length() > 0) jvxlData.rendering = s;
    jvxlData.colorScheme = XmlReader.getXmlAttrib(data, "colorScheme");
    if (jvxlData.colorScheme.length() == 0) jvxlData.colorScheme = null;
    if (jvxlData.thisSet < 0) {
      int n = parseIntStr(XmlReader.getXmlAttrib(data, "set"));
      if (n > 0) jvxlData.thisSet = n - 1;
    }
    jvxlData.slabValue = parseIntStr(XmlReader.getXmlAttrib(data, "slabValue"));
    jvxlData.isSlabbable = (XmlReader.getXmlAttrib(data, "slabbable").equalsIgnoreCase("true"));
    jvxlData.diameter = parseIntStr(XmlReader.getXmlAttrib(data, "diameter"));
    if (jvxlData.diameter == Integer.MIN_VALUE) jvxlData.diameter = 0;

    if (jvxlDataIs2dContour) params.isContoured = true;

    if (params.colorBySign) params.isBicolorMap = true;
    boolean insideOut = XmlReader.getXmlAttrib(data, "insideOut").equals("true");
    float dataMin = Float.NaN;
    float dataMax = Float.NaN;
    float red = Float.NaN;
    float blue = Float.NaN;
    if (jvxlDataIsColorMapped) {
      dataMin = parseFloatStr(XmlReader.getXmlAttrib(data, "dataMinimum"));
      dataMax = parseFloatStr(XmlReader.getXmlAttrib(data, "dataMaximum"));
      red = parseFloatStr(XmlReader.getXmlAttrib(data, "valueMappedToRed"));
      blue = parseFloatStr(XmlReader.getXmlAttrib(data, "valueMappedToBlue"));
      if (Float.isNaN(dataMin)) {
        dataMin = red = -1f;
        dataMax = blue = 1f;
      }
    }
    jvxlSetColorRanges(dataMin, dataMax, red, blue, insideOut);
  }
Пример #6
0
 protected short getLeadColix(int i) {
   return C.getColixInherited(colixes[i], monomers[i].getLeadAtom().colixAtom);
 }
Пример #7
0
  @Override
  public void setProperty(String propertyName, Object value, BS bs) {
    // System.out.println(propertyName + " " + value + " " + bs);
    if (propertyName == "thisID") {
      if (initEllipsoids(value) && ellipsoidSet.size() == 0) {
        String id = (String) value;
        Ellipsoid e = Ellipsoid.getEmptyEllipsoid(id, vwr.am.cmi);
        ellipsoidSet.addLast(e);
        simpleEllipsoids.put(id, e);
      }
      return;
    }

    if ("atoms" == propertyName) {
      selectedAtoms = (BS) value;
      return;
    }

    if (propertyName == "deleteModelAtoms") {
      int modelIndex = ((int[]) ((Object[]) value)[2])[0];
      Iterator<Ellipsoid> e = simpleEllipsoids.values().iterator();
      while (e.hasNext()) if (e.next().tensor.modelIndex == modelIndex) e.remove();
      e = atomEllipsoids.values().iterator();
      while (e.hasNext()) if (e.next().modelIndex == modelIndex) e.remove();
      ellipsoidSet.clear();
      return;
    }
    int mode = PROPERTY_MODES.indexOf((propertyName + "  ").substring(0, 2));
    if (ellipsoidSet.size() > 0) {
      if ("translucentLevel" == propertyName) {
        setPropS(propertyName, value, bs);
        return;
      }
      if (mode >= 0)
        for (int i = ellipsoidSet.size(); --i >= 0; ) setProp(ellipsoidSet.get(i), mode / 3, value);
      return;
    }

    if ("color" == propertyName) {
      short colix = C.getColixO(value);
      byte pid = PAL.pidOf(value);
      if (selectedAtoms != null) bs = selectedAtoms;
      for (Ellipsoid e : atomEllipsoids.values())
        if (e.tensor.type.equals(typeSelected) && e.tensor.isSelected(bs, -1)) {
          e.colix = getColixI(colix, pid, e.tensor.atomIndex1);
          e.pid = pid;
        }
      return;
    }

    if ("on" == propertyName) {
      boolean isOn = ((Boolean) value).booleanValue();
      if (selectedAtoms != null) bs = selectedAtoms;
      if (isOn) setSize(Integer.MAX_VALUE, bs);
      for (Ellipsoid e : atomEllipsoids.values()) {
        Tensor t = e.tensor;
        if ((t.type.equals(typeSelected) || typeSelected.equals(t.altType))
            && t.isSelected(bs, -1)) {
          e.isOn = isOn;
        }
      }
      return;
    }

    if ("options" == propertyName) {
      String options = ((String) value).toLowerCase().trim();
      if (options.length() == 0) options = null;
      if (selectedAtoms != null) bs = selectedAtoms;
      if (options != null) setSize(Integer.MAX_VALUE, bs);
      for (Ellipsoid e : atomEllipsoids.values())
        if (e.tensor.type.equals(typeSelected) && e.tensor.isSelected(bs, -1)) e.options = options;
      return;
    }

    if ("params" == propertyName) {
      Object[] data = (Object[]) value;
      data[2] = null; // Jmol does not allow setting sizes this way from PyMOL yet
      typeSelected = "0";
      setSize(50, bs);
      // onward...
    }

    if ("points" == propertyName) {
      // Object[] o = (Object[]) value;
      // setPoints((P3[]) o[1], (BS) o[2]);
      return;
    }

    if ("scale" == propertyName) {
      setSize((int) (((Float) value).floatValue() * 100), bs);
      return;
    }

    if ("select" == propertyName) {
      typeSelected = ((String) value).toLowerCase();
      return;
    }

    if ("translucency" == propertyName) {
      boolean isTranslucent = (value.equals("translucent"));
      for (Ellipsoid e : atomEllipsoids.values())
        if (e.tensor.type.equals(typeSelected) && e.tensor.isSelected(bs, -1))
          e.colix = C.getColixTranslucent3(e.colix, isTranslucent, translucentLevel);
      return;
    }
    setPropS(propertyName, value, bs);
  }
Пример #8
0
 short getColix2() {
   return C.getColixInherited(colix, atom2.colixAtom);
 }
Пример #9
0
 short getColix1() {
   return C.getColixInherited(colix, atom1.colixAtom);
 }
Пример #10
0
 public void setTranslucent(boolean isTranslucent, float translucentLevel) {
   colix = C.getColixTranslucent3(colix, isTranslucent, translucentLevel);
 }