Revision: 18411 http://sourceforge.net/p/jmol/code/18411 Author: hansonr Date: 2013-07-03 22:30:23 +0000 (Wed, 03 Jul 2013) Log Message: ----------- preliminary "unique" tensor implementation:
load "x.magres" {444 666 1} unique = {*}.tensor("unique") display unique -- won't work if the only tensors present are isc. -- needs testing. Modified Paths: -------------- trunk/Jmol/src/org/jmol/adapter/smarter/AtomSetCollection.java trunk/Jmol/src/org/jmol/modelset/ModelCollection.java trunk/Jmol/src/org/jmol/renderspecial/EllipsoidsRenderer.java trunk/Jmol/src/org/jmol/script/ScriptEvaluator.java trunk/Jmol/src/org/jmol/script/ScriptMathProcessor.java trunk/Jmol/src/org/jmol/script/T.java trunk/Jmol/src/org/jmol/util/Tensor.java Modified: trunk/Jmol/src/org/jmol/adapter/smarter/AtomSetCollection.java =================================================================== --- trunk/Jmol/src/org/jmol/adapter/smarter/AtomSetCollection.java 2013-07-02 16:57:05 UTC (rev 18410) +++ trunk/Jmol/src/org/jmol/adapter/smarter/AtomSetCollection.java 2013-07-03 22:30:23 UTC (rev 18411) @@ -1343,6 +1343,7 @@ if (addCartesian) cartesians[pt++] = cartesian; if (atoms[i].tensors != null) { + atom1.tensors = null; for (int j = atoms[i].tensors.size(); --j >= 0;) { Tensor t = atoms[i].tensors.get(j); if (t == null) Modified: trunk/Jmol/src/org/jmol/modelset/ModelCollection.java =================================================================== --- trunk/Jmol/src/org/jmol/modelset/ModelCollection.java 2013-07-02 16:57:05 UTC (rev 18410) +++ trunk/Jmol/src/org/jmol/modelset/ModelCollection.java 2013-07-03 22:30:23 UTC (rev 18411) @@ -3447,5 +3447,51 @@ return list; } + public BS getUniqueTensorSet(BS bsAtoms) { + BS bs = new BS(); + for (int i = modelCount; --i >= 0;) { + BS bsModelAtoms = getModelAtomBitSetIncludingDeleted(i, true); + bsModelAtoms.and(bsAtoms); + // exclude any models without symmetry + if (viewer.getModelUnitCell(i) == null) + continue; + // exclude any symmetry- + for (int j = bsModelAtoms.nextSetBit(0); j >= 0; j = bsModelAtoms + .nextSetBit(j + 1)) + if (atoms[j].atomSite != atoms[j].index + 1) + bsModelAtoms.clear(j); + bs.or(bsModelAtoms); + // march through all the atoms in the model... + for (int j = bsModelAtoms.nextSetBit(0); j >= 0; j = bsModelAtoms + .nextSetBit(j + 1)) { + Tensor[] ta = atoms[j].getTensors(); + if (ta == null) + continue; + // go through all this atom's tensors... + for (int jj = ta.length; --jj >= 0;) { + Tensor t = ta[jj]; + if (t == null) + continue; + // for each tensor in A, go through all atoms after the first-selected one... + for (int k = bsModelAtoms.nextSetBit(j + 1); k >= 0; k = bsModelAtoms + .nextSetBit(k + 1)) { + Tensor[] tb = atoms[k].getTensors(); + if (tb == null) + continue; + // for each tensor in B, go through all this atom's tensors... + for (int kk = tb.length; --kk >= 0;) { + // if equivalent, reject it. + if (t.isEquiv(tb[kk])) { + bsModelAtoms.clear(k); + bs.clear(k); + break; + } + } + } + } + } + } + return bs; + } } Modified: trunk/Jmol/src/org/jmol/renderspecial/EllipsoidsRenderer.java =================================================================== --- trunk/Jmol/src/org/jmol/renderspecial/EllipsoidsRenderer.java 2013-07-02 16:57:05 UTC (rev 18410) +++ trunk/Jmol/src/org/jmol/renderspecial/EllipsoidsRenderer.java 2013-07-03 22:30:23 UTC (rev 18411) @@ -96,8 +96,6 @@ private final P3i s1 = new P3i(); private final P3i s2 = new P3i(); - private float maxLength; - private final static float toRadians = (float) Math.PI/180f; private final static float[] cossin = new float[36]; @@ -223,18 +221,12 @@ private void renderOne(Ellipsoid e) { center = e.center; - maxLength = 0; - for (int i = 3; --i >= 0;) { - float f = e.getLength(i); - if (f < 0.02f) - f = 0.02f; // for extremely flat ellipsoids, we need at least some length - if (f > maxLength) - maxLength = f; - factoredLengths[i] = f; - } + // for extremely flat ellipsoids, we need at least some length + for (int i = 3; --i >= 0;) + factoredLengths[i] = Math.max(e.getLength(i), 0.02f); axes = e.tensor.eigenVectors; setMatrices(); - setAxes(); + setAxes(e.tensor.maxPt); if (g3d.isClippedXY(dx + dx, s0.x, s0.y)) return; eigenSignMask = e.tensor.eigenSignMask; @@ -316,7 +308,7 @@ 4, 1, 2 //arc }; - private void setAxes() { + private void setAxes(int maxPt) { for (int i = 0; i < 6; i++) { int iAxis = axisPoints[i]; int i012 = Math.abs(iAxis) - 1; @@ -326,13 +318,15 @@ //pt1.scale(f); matEllipsoidToScreen.transform(pt1); - screens[i].set(Math.round (s0.x + pt1.x * perspectiveFactor), - Math.round (s0.y + pt1.y * perspectiveFactor), Math.round(pt1.z + s0.z)); - screens[i + 32].set(Math.round (s0.x + pt1.x * perspectiveFactor * 1.05f), - Math.round (s0.y + pt1.y * perspectiveFactor * 1.05f), Math.round(pt1.z * 1.05f + s0.z)); + screens[i].set(Math.round(s0.x + pt1.x * perspectiveFactor), Math + .round(s0.y + pt1.y * perspectiveFactor), Math.round(pt1.z + s0.z)); + screens[i + 32].set(Math.round(s0.x + pt1.x * perspectiveFactor * 1.05f), + Math.round(s0.y + pt1.y * perspectiveFactor * 1.05f), Math + .round(pt1.z * 1.05f + s0.z)); } - dx = 2 + (int) viewer.scaleToScreen(s0.z, - Math.round((Float.isNaN(maxLength) ? 1.0f : maxLength) * 1000)); + dx = 2 + (int) viewer.scaleToScreen(s0.z, Math + .round((Float.isNaN(factoredLengths[maxPt]) ? 1.0f + : factoredLengths[maxPt]) * 1000)); } private void renderBall() { Modified: trunk/Jmol/src/org/jmol/script/ScriptEvaluator.java =================================================================== --- trunk/Jmol/src/org/jmol/script/ScriptEvaluator.java 2013-07-02 16:57:05 UTC (rev 18410) +++ trunk/Jmol/src/org/jmol/script/ScriptEvaluator.java 2013-07-03 22:30:23 UTC (rev 18411) @@ -3817,6 +3817,7 @@ case T.spec_alternate: case T.specialposition: case T.symmetry: + case T.nonequivalent: case T.unitcell: rpn.addXBs(getAtomBits(instruction.tok, value)); break; Modified: trunk/Jmol/src/org/jmol/script/ScriptMathProcessor.java =================================================================== --- trunk/Jmol/src/org/jmol/script/ScriptMathProcessor.java 2013-07-02 16:57:05 UTC (rev 18410) +++ trunk/Jmol/src/org/jmol/script/ScriptMathProcessor.java 2013-07-03 22:30:23 UTC (rev 18411) @@ -844,6 +844,8 @@ String tensorType = SV.sValue(args[0]).toLowerCase(); String infoType = ";" + (args.length == 1 ? "all" : SV.sValue(args[1]).toLowerCase()) + "."; JmolList<Object> data = new JmolList<Object>(); + if (tensorType.equals("unique")) + return addXBs(viewer.modelSet.getUniqueTensorSet(bs)); if (tensorType.equals("isc")) { JmolList<Tensor> list = viewer.modelSet.getInteractionTensorList("isc", bs); Modified: trunk/Jmol/src/org/jmol/script/T.java =================================================================== --- trunk/Jmol/src/org/jmol/script/T.java 2013-07-02 16:57:05 UTC (rev 18410) +++ trunk/Jmol/src/org/jmol/script/T.java 2013-07-03 22:30:23 UTC (rev 18411) @@ -450,6 +450,7 @@ public final static int specialposition = predefinedset | 44; final static int visible = predefinedset | 46; final static int basemodel = predefinedset | 48; + final static int nonequivalent = predefinedset | 50; static int getPrecedence(int tokOperator) { @@ -1903,6 +1904,7 @@ "inherit", null, "normal", T.t(normal), "noContourLines", T.t(nocontourlines), + "nonequivalent", T.t(nonequivalent), "notFrontOnly", T.t(notfrontonly), "noTriangles", T.t(notriangles), "now", T.t(now), Modified: trunk/Jmol/src/org/jmol/util/Tensor.java =================================================================== --- trunk/Jmol/src/org/jmol/util/Tensor.java 2013-07-02 16:57:05 UTC (rev 18410) +++ trunk/Jmol/src/org/jmol/util/Tensor.java 2013-07-03 22:30:23 UTC (rev 18411) @@ -49,6 +49,7 @@ public String type; public int iType = TYPE_OTHER; + public int maxPt = 2; // type is an identifier that the reader/creator delivers: // @@ -447,19 +448,21 @@ } /** - * The expression: + * The expression: * * |sigma_3 - sigma_iso| >= |sigma_1 - sigma_iso| >= |sigma_2 - sigma_iso| * * simply sorts the values from largest to smallest or smallest to largest, * depending upon the direction of the asymmetry, always setting the last - * value to be the farthest from the mean. + * value to be the farthest from the mean. We use a simpler form here: * + * |sigma_3 - sigma_1| >= |sigma_3 - sigma_2| >= |sigma_2 - sigma_1| + * + * which amounts to the same thing and is prettier. (Think about it!) + * */ private void sortAndNormalize() { // first sorted 3 2 1, then check for iso-sorting - V3 vTemp = eigenVectors[0]; // will throw this away after the sort anyway - // might as well use it! Object[][] o = new Object[][] { new Object[] { V3.newV(eigenVectors[0]), Float.valueOf(eigenValues[0]) }, new Object[] { V3.newV(eigenVectors[1]), Float.valueOf(eigenValues[1]) }, @@ -470,21 +473,29 @@ eigenVectors[i] = (V3) o[pt][0]; eigenValues[i] = ((Float) o[pt][1]).floatValue(); } - if (sortIso) { - float f = (eigenValues[0] + eigenValues[1] + eigenValues[2]) / 3f; - if (eigenValues[2] - f < f - eigenValues[0]) { - vTemp = eigenVectors[0]; - eigenVectors[0] = eigenVectors[2]; - eigenVectors[2] = vTemp; - f = eigenValues[0]; - eigenValues[0] = eigenValues[2]; - eigenValues[2] = f; - } + if (sortIso + && eigenValues[2] - eigenValues[1] < eigenValues[1] - eigenValues[0]) { + maxPt = 0; + V3 vTemp = eigenVectors[0]; + eigenVectors[0] = eigenVectors[2]; + eigenVectors[2] = vTemp; + float f = eigenValues[0]; + eigenValues[0] = eigenValues[2]; + eigenValues[2] = f; } for (int i = 0; i < 3; i++) eigenVectors[i].normalize(); } + public boolean isEquiv(Tensor t) { + if (t.iType != iType) + return false; + float f = Math.abs(eigenValues[0] + eigenValues[1] + eigenValues[2]); + for (int i = 0; i < 3; i++) + if (Math.abs(t.eigenValues[i] - eigenValues[i]) / f > 0.0003f) + return false; + return true; + } private static Comparator<? super Object[]> getEigenSort() { return (tSort == null ? (tSort = new EigenSort()) : tSort); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ This SF.net email is sponsored by Windows: Build for Windows Store. http://p.sf.net/sfu/windows-dev2dev _______________________________________________ Jmol-commits mailing list Jmol-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jmol-commits