From: <ha...@us...> - 2007-10-30 18:33:31
|
Revision: 8545 http://jmol.svn.sourceforge.net/jmol/?rev=8545&view=rev Author: hansonr Date: 2007-10-30 11:33:29 -0700 (Tue, 30 Oct 2007) Log Message: ----------- version=11.3.40_dev # new feature: model-based parallel array calculations: # x = {atomno=3}.split() # a list, one element for each model # draw @{x.xyz.sub({1 0 0})} # a set of points, one per model Modified Paths: -------------- trunk/Jmol/src/org/jmol/shapespecial/Draw.java trunk/Jmol/src/org/jmol/util/Escape.java trunk/Jmol/src/org/jmol/viewer/Compiler.java trunk/Jmol/src/org/jmol/viewer/Eval.java trunk/Jmol/src/org/jmol/viewer/Jmol.properties trunk/Jmol/src/org/jmol/viewer/Token.java Modified: trunk/Jmol/src/org/jmol/shapespecial/Draw.java =================================================================== --- trunk/Jmol/src/org/jmol/shapespecial/Draw.java 2007-10-30 07:42:34 UTC (rev 8544) +++ trunk/Jmol/src/org/jmol/shapespecial/Draw.java 2007-10-30 18:33:29 UTC (rev 8545) @@ -38,6 +38,7 @@ import org.jmol.util.Logger; import org.jmol.viewer.JmolConstants; import org.jmol.viewer.MouseManager; +import org.jmol.viewer.Token; import org.jmol.g3d.Graphics3D; import org.jmol.shape.Mesh; import org.jmol.shape.MeshCollection; @@ -71,10 +72,12 @@ private boolean[] reversePoints = new boolean[MAX_POINTS]; private boolean[] useVertices = new boolean[MAX_POINTS]; private BitSet[] ptBitSets = new BitSet[MAX_POINTS]; - private BitSet bsAllAtoms = new BitSet(); + private String[][] modelBasedPoints; + private BitSet bsAllModels; private Vector3f offset = new Vector3f(); private int nPoints; private int nbitsets; + private int nModelBased; private int ncoord; private int nidentifiers; private int diameter; @@ -111,7 +114,8 @@ length = Float.MAX_VALUE; diameter = 0; modelVertices = null; - bsAllAtoms.clear(); + modelBasedPoints = null; + bsAllModels = null; indicatedModelIndex = -1; rgb = null; offset = new Vector3f(); @@ -251,10 +255,18 @@ if (BitSetUtil.cardinalityOf((BitSet) value) == 0) return; ptBitSets[nbitsets++] = (BitSet) value; - bsAllAtoms.or((BitSet) value); nPoints++; return; } + if ("modelBasedPoints" == propertyName) { + if (modelBasedPoints == null) { + modelBasedPoints = new String[MAX_POINTS][]; + nModelBased = 0; + } + modelBasedPoints[nModelBased++] = (String[]) value; + nPoints++; + return; + } if ("set" == propertyName) { if (thisMesh == null) { allocMesh(null); @@ -345,14 +357,14 @@ nPoly = setPolygons(nPoly); } else { // multiple copies, one for each model involved - BitSet bsAllModels = new BitSet(); - if (nbitsets > 0) - bsAllModels = viewer.getModelBitSet(bsAllAtoms); - else if (nidentifiers > 0) + if (nidentifiers > 0) { + bsAllModels = new BitSet(); for (int i = 0; i < nidentifiers; i++) for (int j = dmeshes[ptIdentifiers[i]].polygonCount; --j >= 0;) - bsAllModels.set(j); - else + if (dmeshes[ptIdentifiers[i]].polygonIndexes[j] != null) + bsAllModels.set(j); + } + if (bsAllModels == null && nbitsets == 0 && modelBasedPoints == null) bsAllModels = viewer.getVisibleFramesBitSet(); thisMesh.modelIndex = -1; thisMesh.setPolygonCount(modelCount); @@ -383,8 +395,7 @@ } else { for (int iModel = 0; iModel < modelCount; iModel++) { - if (bsAllModels.get(iModel)) { - addModelPoints(iModel); + if (addModelPoints(iModel)) { setPolygons(nPoly); thisMesh.setCenter(iModel); thisMesh.drawTypes[iModel] = thisMesh.drawType; @@ -414,49 +425,95 @@ nPoints = MAX_POINTS; } - private void addModelPoints(int iModel) { + private boolean addModelPoints(int iModel) { nPoints = ncoord; // {x,y,z} points are already defined in ptList // $drawID references may be fixed or not - for (int i = 0; i < nidentifiers; i++) { - DrawMesh m = dmeshes[ptIdentifiers[i]]; - if (isPlane || isPerpendicular || useVertices[i]) { - if (reversePoints[i]) { - if (iModel < 0 || iModel >= m.polygonCount) - for (int ipt = m.drawVertexCount; --ipt >= 0;) - addPoint(m.vertices[ipt]); - else - for (int ipt = m.drawVertexCounts[iModel]; --ipt >= 0;) - addPoint(m.vertices[m.polygonIndexes[iModel][ipt]]); + // Note that points are created in the order: + // 1) all {x,y,z} points + // 2) all $drawID points + // 3) all {atomExpression} points + // 4) all {atomExpression}.split() points + // Order is only important when there are four points, + // where they may become crossed, so + // we also provide a flag CROSSED to uncross them + if (nidentifiers > 0 && (iModel < 0 || bsAllModels.get(iModel))) + for (int i = 0; i < nidentifiers; i++) { + DrawMesh m = dmeshes[ptIdentifiers[i]]; + if (isPlane || isPerpendicular || useVertices[i]) { + if (reversePoints[i]) { + if (iModel < 0 || iModel >= m.polygonCount) + for (int ipt = m.drawVertexCount; --ipt >= 0;) + addPoint(m.vertices[ipt]); + else + for (int ipt = m.drawVertexCounts[iModel]; --ipt >= 0;) + addPoint(m.vertices[m.polygonIndexes[iModel][ipt]]); + } else { + if (iModel < 0 || iModel >= m.polygonCount) + for (int ipt = 0; ipt < m.drawVertexCount; ipt++) + addPoint(m.vertices[ipt]); + else + for (int ipt = m.drawVertexCounts[iModel]; --ipt >= 0;) + addPoint(m.vertices[m.polygonIndexes[iModel][ipt]]); + } } else { - if (iModel < 0 || iModel >= m.polygonCount) - for (int ipt = 0; ipt < m.drawVertexCount; ipt++) - addPoint(m.vertices[ipt]); + if (iModel < 0 || m.ptCenters == null || m.ptCenters[iModel] == null) + addPoint(m.ptCenter); else - for (int ipt = m.drawVertexCounts[iModel]; --ipt >= 0;) - addPoint(m.vertices[m.polygonIndexes[iModel][ipt]]); + addPoint(m.ptCenters[iModel]); } - } else { - if (iModel < 0 || m.ptCenters == null || m.ptCenters[iModel] == null) - addPoint(m.ptCenter); - else - addPoint(m.ptCenters[iModel]); } - } + // for just points, we make sure model is visible + if (nbitsets == 0 && modelBasedPoints == null) + return (nPoints > 0 && (iModel < 0 || bsAllModels.get(iModel))); // (atom set) references must be filtered for relevant model // note that if a model doesn't have a relevant point, one may // get a line instead of a plane, a point instead of a line, etc. - if (nbitsets == 0) - return; BitSet bsModel = (iModel < 0 ? null : viewer.getModelAtomBitSet(iModel)); - for (int i = 0; i < nbitsets; i++) { - BitSet bs = (BitSet) ptBitSets[i].clone(); - if (bsModel != null) - bs.and(bsModel); - if (BitSetUtil.cardinalityOf(bs) > 0) { - addPoint(viewer.getAtomSetCenter(bs)); + if (bsAllModels == null) + bsAllModels = new BitSet(); + if (nbitsets > 0) { + for (int i = 0; i < nbitsets; i++) { + BitSet bs = (BitSet) ptBitSets[i].clone(); + if (bsModel != null) + bs.and(bsModel); + if (BitSetUtil.cardinalityOf(bs) > 0) { + addPoint(viewer.getAtomSetCenter(bs)); + if (iModel < 0) + bsAllModels.or(viewer.getModelBitSet(bs)); + else + bsAllModels.set(iModel); + } } } + if (modelBasedPoints != null) { + for (int i = 0; i < nModelBased; i++) + for (int j = 0; j < modelBasedPoints[i].length; j++) + if (iModel < 0 || j == iModel) { + Object points = Escape + .unescapePointOrBitsetAsToken(modelBasedPoints[i][j]); + if (!(points instanceof Token)) + continue; + switch (((Token) points).tok) { + case Token.point3f: + addPoint((Point3f) ((Token) points).value); + bsAllModels.set(j); + break; + case Token.bitset: + BitSet bs = (BitSet) ((Token) points).value; + if (bsModel != null) + bs.and(bsModel); + if (BitSetUtil.cardinalityOf(bs) > 0) { + addPoint(viewer.getAtomSetCenter(bs)); + bsAllModels.set(j); + } + break; + default: + //ignored + } + } + } + return (nPoints > ncoord); } private int setPolygons(int nPoly) { @@ -844,7 +901,8 @@ } private String getDrawCommand(DrawMesh mesh, int iModel) { - if (mesh.drawType == JmolConstants.DRAW_NONE) + if (mesh.drawType == JmolConstants.DRAW_NONE + || mesh.drawVertexCount == 0 && mesh.drawVertexCounts == null) return ""; StringBuffer str = new StringBuffer(); if (!mesh.isFixed && iModel >= 0 && modelCount > 1) @@ -856,7 +914,8 @@ iModel = 0; if (mesh.diameter > 0) str.append(" diameter ").append(mesh.diameter); - int nVertices = mesh.drawVertexCount > 0 ? mesh.drawVertexCount : mesh.drawVertexCounts[0]; + int nVertices = mesh.drawVertexCount > 0 ? mesh.drawVertexCount + : mesh.drawVertexCounts[0]; switch (mesh.drawTypes == null ? mesh.drawType : mesh.drawTypes[iModel]) { case JmolConstants.DRAW_ARROW: str.append(" ARROW"); Modified: trunk/Jmol/src/org/jmol/util/Escape.java =================================================================== --- trunk/Jmol/src/org/jmol/util/Escape.java 2007-10-30 07:42:34 UTC (rev 8544) +++ trunk/Jmol/src/org/jmol/util/Escape.java 2007-10-30 18:33:29 UTC (rev 8545) @@ -133,9 +133,10 @@ Object v = s; if (s.charAt(0) == '{') v = Escape.unescapePoint(s); - else if (s.indexOf("({") == 0) + else if (s.indexOf("({") == 0 + && s.indexOf("({") == s.lastIndexOf("({")) v = Escape.unescapeBitset(s); - if (s.indexOf("[{") == 0) + else if (s.indexOf("[{") == 0) v = new BondSet(Escape.unescapeBitset(s)); if (v instanceof Point3f) return new Token(Token.point3f, v); Modified: trunk/Jmol/src/org/jmol/viewer/Compiler.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/Compiler.java 2007-10-30 07:42:34 UTC (rev 8544) +++ trunk/Jmol/src/org/jmol/viewer/Compiler.java 2007-10-30 18:33:29 UTC (rev 8545) @@ -492,8 +492,8 @@ cchToken = pt; } } - if (!(tokCommand == Token.script && iHaveQuotedString) - && tokAttr(tokCommand, Token.specialstring) + if (tokAttr(tokCommand, Token.specialstring) + && !(tokCommand == Token.script && iHaveQuotedString) && lookingAtSpecialString()) { String str = script.substring(ichToken, ichToken + cchToken); addTokenToPrefix(new Token(Token.string, str)); Modified: trunk/Jmol/src/org/jmol/viewer/Eval.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/Eval.java 2007-10-30 07:42:34 UTC (rev 8544) +++ trunk/Jmol/src/org/jmol/viewer/Eval.java 2007-10-30 18:33:29 UTC (rev 8545) @@ -724,12 +724,15 @@ if (val.size() == 0) invalidArgument(); i = iToken; - v = Token.oValue((Token) val.elementAt(0)); + Token t = (Token) val.elementAt(0); + v = (t.tok == Token.list ? t : Token.oValue(t)); } else { v = getParameter(var, false); } Object var_set; - if (v instanceof Boolean) { + if (v instanceof Token) + fixed[j] = (Token) v; + else if (v instanceof Boolean) { fixed[j] = (((Boolean) v).booleanValue() ? Token.tokenOn : Token.tokenOff); } else if (v instanceof Integer) { @@ -752,8 +755,8 @@ tok = (isClauseDefine ? Token.string : isExpression ? Token.define : s.indexOf(".") >= 0 || s.indexOf("=") >= 0 - || s.indexOf("[") >= 0 ? Token.string - : Token.identifier); + || s.indexOf("[") >= 0 || s.indexOf("{") >= 0 + ? Token.string : Token.identifier); fixed[j] = new Token(tok, s); } } else if (v instanceof BitSet){ @@ -8672,6 +8675,11 @@ i = iToken; havePoints = true; break; + case Token.list: + propertyName = "modelBasedPoints"; + propertyValue = theToken.value; + havePoints = true; + break; default: if (!setMeshDisplayProperty(JmolConstants.SHAPE_DRAW, i, theTok)) invalidArgument(); @@ -9256,6 +9264,8 @@ } private boolean listIsosurface(int iShape) throws ScriptException { + if (getToken(1).value instanceof String[]) // not just the word "list" + return false; checkLength2(); if (!isSyntaxCheck) showString((String) viewer.getShapeProperty(iShape, "list")); @@ -10057,11 +10067,16 @@ boolean useBraces = (Compiler.tokAttr(tok, Token.implicitExpression)); boolean inBrace = false; boolean inClauseDefine = false; + boolean setEquals = (tok == Token.set && ((String)statement[0].value) == ""); for (int i = 0; i < statementLength; ++i) { if (iToken == i - 1) sb.append(" <<"); if (i != 0) sb.append(' '); + if (i == 2 && setEquals) { + setEquals = false; + sb.append("= "); + } Token token = statement[i]; if (iToken == i && token.tok != Token.expressionEnd) sb.append(">> "); @@ -10854,14 +10869,27 @@ if (args.length > 1) return false; Token x = getX(); - String s = (tok == Token.trim && x.tok == Token.list ? null : Token - .sValue(x)); if (isSyntaxCheck) - return addX(s); + return addX(Token.sValue(x)); + String s = (tok == Token.split && x.tok == Token.bitset + || tok == Token.trim && x.tok == Token.list ? null + : Token.sValue(x)); String sArg = (args.length == 1 ? Token.sValue(args[0]) : tok == Token.trim ? "" : "\n"); switch (tok) { case Token.split: + if (x.tok == Token.bitset) { + BitSet bsSelected = Token.bsSelect(x); + sArg = "\n"; + int modelCount = viewer.getModelCount(); + s = ""; + for (int i = 0; i < modelCount; i++) { + s += (i == 0 ? "" : "\n"); + BitSet bs = viewer.getModelAtomBitSet(i); + bs.and(bsSelected); + s += Escape.escape(bs); + } + } return addX(TextFormat.split(s, sArg)); case Token.join: if (s.length() > 0 && s.charAt(s.length() - 1) == '\n') @@ -10891,30 +10919,67 @@ boolean isScalar = (x2.tok != Token.list && Token.sValue(x2) .indexOf("\n") < 0); - float factor = (isScalar ? Token.fValue(x2) : 0); - String sValue = (isScalar ? Token.sValue(x2) : ""); + float factor = (sValue.indexOf("{") >= 0 ? Float.NaN + : isScalar ? Token.fValue(x2) : 0); + + String[] sList1 = (x1.value instanceof String ? TextFormat.split( (String) x1.value, "\n") : (String[]) x1.value); + + String[] sList2 = (isScalar ? null + : x2.value instanceof String ? TextFormat.split((String) x2.value, + "\n") : (String[]) x2.value); + + int len = (isScalar ? sList1.length : Math.min(sList1.length, sList2.length)); + + String[] sList3 = new String[len]; + float[] list1 = new float[sList1.length]; Parser.parseFloatArray(sList1, list1); - String[] sList2 = (isScalar ? null - : x2.value instanceof String ? TextFormat.split((String) x2.value, - "\n") : (String[]) x2.value); float[] list2 = new float[(isScalar ? sList1.length : sList2.length)]; - int len = Math.min(list1.length, list2.length); if (isScalar) for (int i = len; --i >= 0;) list2[i] = factor; else Parser.parseFloatArray(sList2, list2); - String[] sList3 = new String[len]; - + Token token = null; switch (tok) { case Token.add: + token = Token.tokenPlus; + break; + case Token.sub: + token = Token.tokenMinus; + break; + case Token.mul: + token = Token.tokenTimes; + break; + case Token.div: + token = Token.tokenDivide; + break; + } + + for (int i = 0; i < len; i++) { + if (Float.isNaN(list1[i])) + addX(Escape.unescapePointOrBitsetAsToken(sList1[i])); + else + addX(list1[i]); + if (!Float.isNaN(list2[i])) + addX(list2[i]); + else if (isScalar) + addX(Escape.unescapePointOrBitsetAsToken(sValue)); + else + addX(Escape.unescapePointOrBitsetAsToken(sList2[i])); + if (!addOp(token) || !operate()) + return false; + sList3[i] = Token.sValue(xStack[xPt--]); + } +/* + switch (tok) { + case Token.add: if (Float.isNaN(factor)) { for (int i = len; --i >= 0;) sList3[i] = sList1[i] + (isScalar ? sValue : sList2[i]); @@ -10946,6 +11011,7 @@ } for (int i = len; --i >= 0;) sList3[i] = "" + list1[i]; +*/ return addX(sList3); } @@ -11246,33 +11312,13 @@ //handle bitset later } } - if (x2.tok == Token.point3f) { - switch (op.intValue) { - case Token.atomX: - return addX(((Point3f) x2.value).x); - case Token.atomY: - return addX(((Point3f) x2.value).y); - case Token.atomZ: - return addX(((Point3f) x2.value).z); - case Token.fracX: - case Token.fracY: - case Token.fracZ: - Point3f ptf = new Point3f((Point3f) x2.value); - viewer.toFractional(ptf); - return addX(op.intValue == Token.fracX ? ptf.x - : op.intValue == Token.fracY ? ptf.y : ptf.z); - } + if (x2.tok == Token.string) { + Object v = Escape.unescapePointOrBitsetAsToken(Token.sValue(x2)); + if (!(v instanceof Token)) + return false; + x2 = (Token) v; } - if (x2.tok != Token.bitset) - return false; - if (op.intValue == Token.bonds && x2.value instanceof BondSet) - return addX(x2); - Object val = getBitsetProperty(Token.bsSelect(x2), op.intValue, null, - null, x2.value, op.value, false); - if (op.intValue == Token.bonds) - return addX(new Token(Token.bitset, new BondSet((BitSet) val, - getAtomIndices(Token.bsSelect(x2))))); - return addX(val); + return evaluatePointOrBitsetOperation(op, x2); } //binary: @@ -11480,6 +11526,49 @@ } return true; } + + private boolean evaluatePointOrBitsetOperation(Token op, Token x2) + throws ScriptException { + switch (x2.tok) { + case Token.list: + String[] list = (String[])x2.value; + String[] list2 = new String[list.length]; + for (int i = 0; i < list.length; i++) { + Object v = Escape.unescapePointOrBitsetAsToken(list[i]); + if (!(v instanceof Token) || !evaluatePointOrBitsetOperation(op, (Token) v)) + return false; + list2[i] = Token.sValue(xStack[xPt--]); + } + return addX(list2); + case Token.point3f: + switch (op.intValue) { + case Token.atomX: + return addX(((Point3f) x2.value).x); + case Token.atomY: + return addX(((Point3f) x2.value).y); + case Token.atomZ: + return addX(((Point3f) x2.value).z); + case Token.fracX: + case Token.fracY: + case Token.fracZ: + Point3f ptf = new Point3f((Point3f) x2.value); + viewer.toFractional(ptf); + return addX(op.intValue == Token.fracX ? ptf.x + : op.intValue == Token.fracY ? ptf.y : ptf.z); + } + break; + case Token.bitset: + if (op.intValue == Token.bonds && x2.value instanceof BondSet) + return addX(x2); + Object val = getBitsetProperty(Token.bsSelect(x2), op.intValue, null, + null, x2.value, op.value, false); + if (op.intValue == Token.bonds) + return addX(new Token(Token.bitset, new BondSet((BitSet) val, + getAtomIndices(Token.bsSelect(x2))))); + return addX(val); + } + return false; + } Point3f ptValue(Token x) throws ScriptException { if (isSyntaxCheck) @@ -11491,7 +11580,8 @@ return (Point3f) getBitsetProperty(Token.bsSelect(x), Token.xyz, null, null, x.value, null, false); case Token.string: - Object pt = Escape.unescapePoint((String) x.value); + case Token.list: + Object pt = Escape.unescapePoint(Token.sValue(x)); if (pt instanceof Point3f) return (Point3f) pt; break; @@ -11506,8 +11596,9 @@ switch (x.tok) { case Token.point4f: return (Point4f) x.value; + case Token.list: case Token.string: - Object pt = Escape.unescapePoint((String) x.value); + Object pt = Escape.unescapePoint(Token.sValue(x)); return (pt instanceof Point4f ? (Point4f) pt : null); case Token.bitset: //ooooh, wouldn't THIS be nice! Modified: trunk/Jmol/src/org/jmol/viewer/Jmol.properties =================================================================== --- trunk/Jmol/src/org/jmol/viewer/Jmol.properties 2007-10-30 07:42:34 UTC (rev 8544) +++ trunk/Jmol/src/org/jmol/viewer/Jmol.properties 2007-10-30 18:33:29 UTC (rev 8545) @@ -1,5 +1,9 @@ version=11.3.40_dev +# new feature: model-based parallel array calculations: +# x = {atomno=3}.split() # a list, one element for each model +# draw @{x.xyz.sub({1 0 0})} # a set of points, one per model + # new feature: point3f in array(): # xlist = array({1,2,3}, {1,1,0});print xlist[1]+{1 0 0}; # bug fix: draw @{x - {1 0 0}} Modified: trunk/Jmol/src/org/jmol/viewer/Token.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/Token.java 2007-10-30 07:42:34 UTC (rev 8544) +++ trunk/Jmol/src/org/jmol/viewer/Token.java 2007-10-30 18:33:29 UTC (rev 8545) @@ -42,8 +42,8 @@ public class Token { - int tok; - Object value; + public int tok; + public Object value; int intValue = Integer.MAX_VALUE; Token(int tok, int intValue, Object value) { @@ -851,7 +851,11 @@ final static Token tokenAnd = new Token(opAnd, "and"); final static Token tokenOr = new Token(opOr, "or"); final static Token tokenComma = new Token(comma, ","); + final static Token tokenPlus = new Token(plus, "+"); final static Token tokenMinus = new Token(minus, "-"); + final static Token tokenTimes = new Token(times, "*"); + final static Token tokenDivide = new Token(divide, "/"); + final static Token tokenLeftParen = new Token(leftparen, "("); final static Token tokenArraySelector = new Token(leftsquare, "["); @@ -1086,7 +1090,6 @@ // atom expressions "(", tokenLeftParen, ")", new Token(rightparen), - "-", tokenMinus, "and", tokenAnd, "&", null, "&&", null, @@ -1111,7 +1114,6 @@ "<>", null, "/=", null, "within", new Token(within), - "+", new Token(plus), ".", new Token(dot), "[", new Token(leftsquare), "]", new Token(rightsquare), @@ -1119,10 +1121,12 @@ "}", new Token(rightbrace), "$", new Token(dollarsign), "%", new Token(percent), - "*", new Token(times), ":", new Token(colon), ";", new Token(semicolon), - "/", new Token(divide), + "+", tokenPlus, + "-", tokenMinus, + "*", tokenTimes, + "/", tokenDivide, "molecule", new Token(molecule), "molecules", null, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |