From: <ha...@us...> - 2008-07-04 18:54:44
|
Revision: 9554 http://jmol.svn.sourceforge.net/jmol/?rev=9554&view=rev Author: hansonr Date: 2008-07-04 11:54:31 -0700 (Fri, 04 Jul 2008) Log Message: ----------- version=11.5.45_dev bug fixes for math and quaternion frame "n" # bug fix: local assignment var x = array() followed by x[n] = ... does not work # bug fix: f(x[i],x[j]) selects only x[j], not both x[i] and x[j] # bug fix: quaternion frame "n" recognizes file-based H atoms on N for frame definition Modified Paths: -------------- trunk/Jmol/src/org/jmol/modelsetbio/AminoMonomer.java trunk/Jmol/src/org/jmol/modelsetbio/BioPolymer.java trunk/Jmol/src/org/jmol/modelsetbio/Monomer.java trunk/Jmol/src/org/jmol/util/Quaternion.java trunk/Jmol/src/org/jmol/viewer/Eval.java trunk/Jmol/src/org/jmol/viewer/Jmol.properties trunk/Jmol/src/org/jmol/viewer/ScriptManager.java trunk/Jmol/src/org/jmol/viewer/Viewer.java Modified: trunk/Jmol/src/org/jmol/modelsetbio/AminoMonomer.java =================================================================== --- trunk/Jmol/src/org/jmol/modelsetbio/AminoMonomer.java 2008-07-04 03:56:31 UTC (rev 9553) +++ trunk/Jmol/src/org/jmol/modelsetbio/AminoMonomer.java 2008-07-04 18:54:31 UTC (rev 9554) @@ -26,6 +26,7 @@ import javax.vecmath.Point3f; import org.jmol.modelset.Atom; +import org.jmol.modelset.Bond; import org.jmol.modelset.Chain; import org.jmol.viewer.JmolConstants; @@ -177,6 +178,17 @@ } Point3f getNitrogenHydrogenPoint() { + if (nitrogenHydrogenPoint == null && !nhChecked) { + Atom nitrogen = getNitrogenAtom(); + Atom h = null; + Bond[] bonds = nitrogen.getBonds(); + nhChecked = true; + for (int i = 0; i < bonds.length; i++) + if ((h = bonds[i].getOtherAtom(nitrogen)).getElementNumber() == 1) { + nitrogenHydrogenPoint = h; + break; + } + } return nitrogenHydrogenPoint; } } Modified: trunk/Jmol/src/org/jmol/modelsetbio/BioPolymer.java =================================================================== --- trunk/Jmol/src/org/jmol/modelsetbio/BioPolymer.java 2008-07-04 03:56:31 UTC (rev 9553) +++ trunk/Jmol/src/org/jmol/modelsetbio/BioPolymer.java 2008-07-04 18:54:31 UTC (rev 9554) @@ -197,15 +197,16 @@ //calculateStructures(); } - public void recalculateLeadMidpointsAndWingVectors() { + public void recalculateLeadMidpointsAndWingVectors() { leadAtomIndices = null; sheetPoints = null; getLeadAtomIndices(); ProteinStructure ps; ProteinStructure psLast = null; - for (int i = 0; i < monomerCount; i++) - if ((ps = getProteinStructure(i)) != null && ps != psLast) { - (psLast = ps).resetAxes(); + for (int i = 0; i < monomerCount; i++) { + if ((ps = getProteinStructure(i)) != null && ps != psLast) + (psLast = ps).resetAxes(); + monomers[i].nhChecked = false; } calcLeadMidpointsAndWingVectors(false); } Modified: trunk/Jmol/src/org/jmol/modelsetbio/Monomer.java =================================================================== --- trunk/Jmol/src/org/jmol/modelsetbio/Monomer.java 2008-07-04 03:56:31 UTC (rev 9553) +++ trunk/Jmol/src/org/jmol/modelsetbio/Monomer.java 2008-07-04 18:54:31 UTC (rev 9554) @@ -39,6 +39,8 @@ protected final byte[] offsets; + boolean nhChecked = false; + protected Monomer(Chain chain, String group3, int seqcode, int firstAtomIndex, int lastAtomIndex, byte[] interestingAtomOffsets) { @@ -46,7 +48,7 @@ offsets = interestingAtomOffsets; } - int monomerIndex; + protected int monomerIndex; void setBioPolymer(BioPolymer polymer, int index) { this.bioPolymer = polymer; Modified: trunk/Jmol/src/org/jmol/util/Quaternion.java =================================================================== --- trunk/Jmol/src/org/jmol/util/Quaternion.java 2008-07-04 03:56:31 UTC (rev 9553) +++ trunk/Jmol/src/org/jmol/util/Quaternion.java 2008-07-04 18:54:31 UTC (rev 9554) @@ -51,11 +51,11 @@ * */ - public class Quaternion { public float q0, q1, q2, q3; public Matrix3f mat; + // create a new object with the given components private Quaternion(float q0, float q1, float q2, float q3) { this.q0 = q0; @@ -66,7 +66,7 @@ } public Quaternion(Point4f pt) { - float factor = pt.distance(new Point4f(0,0,0,0)); + float factor = pt.distance(new Point4f(0, 0, 0, 0)); if (factor == 0) { q0 = 1; return; @@ -76,21 +76,22 @@ q2 = pt.y / factor; q3 = pt.z / factor; fixQ(); -} + } public Quaternion(Tuple3f pt, float theta) { if (pt.x == 0 && pt.y == 0 && pt.z == 0) { q0 = 1; return; } - float fact = (float)(Math.sin(theta/2*Math.PI/180)/Math.sqrt(pt.x * pt.x + pt.y * pt.y + pt.z * pt.z)); - q0 = (float) (Math.cos(theta/2 * Math.PI/180)); + float fact = (float) (Math.sin(theta / 2 * Math.PI / 180) / Math.sqrt(pt.x + * pt.x + pt.y * pt.y + pt.z * pt.z)); + q0 = (float) (Math.cos(theta / 2 * Math.PI / 180)); q1 = pt.x * fact; q2 = pt.y * fact; q3 = pt.z * fact; fixQ(); } - + private Quaternion fixQ() { if (q0 < 0) { q0 = -q0; @@ -143,15 +144,16 @@ q[j] = (m[i][j] + m[j][i]) * s; q[k] = (m[i][k] + m[k][i]) * s; q0 = (m[k][j] - m[j][k]) * s; - q1 = q[0]; // x - q2 = q[1]; // y - q3 = q[2]; // z + q1 = q[0]; // x + q2 = q[1]; // y + q3 = q[2]; // z } fixQ(); } - - public static final Quaternion getQuaternionFrame(Vector3f vA, Vector3f vB, Vector3f vC) { - if (vC == null) { + + public static final Quaternion getQuaternionFrame(Vector3f vA, Vector3f vB, + Vector3f vC) { + if (vC == null) { vC = new Vector3f(); vC.cross(vA, vB); } @@ -164,40 +166,40 @@ mat.setColumn(0, vA); mat.setColumn(1, vBprime); mat.setColumn(2, vC); - + /* * * Verification tests using Quat4f and AngleAxis4f: * - System.out.println("quaternion frame matrix: " + mat); - - Point3f pt2 = new Point3f(); - mat.transform(new Point3f(1, 0, 0), pt2); - System.out.println("vA=" + vA + " M(100)=" + pt2); - mat.transform(new Point3f(0, 1, 0), pt2); - System.out.println("vB'=" + vBprime + " M(010)=" + pt2); - mat.transform(new Point3f(0, 0, 1), pt2); - System.out.println("vC=" + vC + " M(001)=" + pt2); - Quat4f q4 = new Quat4f(); - q4.set(mat); - System.out.println("----"); - System.out.println("Quat4f: {" + q4.w + " " + q4.x + " " + q4.y + " " + q4.z + "}"); - System.out.println("Quat4f: 2xy + 2wz = m10: " + (2 * q4.x * q4.y + 2 * q4.w * q4.z) + " = " + mat.m10); - + System.out.println("quaternion frame matrix: " + mat); + + Point3f pt2 = new Point3f(); + mat.transform(new Point3f(1, 0, 0), pt2); + System.out.println("vA=" + vA + " M(100)=" + pt2); + mat.transform(new Point3f(0, 1, 0), pt2); + System.out.println("vB'=" + vBprime + " M(010)=" + pt2); + mat.transform(new Point3f(0, 0, 1), pt2); + System.out.println("vC=" + vC + " M(001)=" + pt2); + Quat4f q4 = new Quat4f(); + q4.set(mat); + System.out.println("----"); + System.out.println("Quat4f: {" + q4.w + " " + q4.x + " " + q4.y + " " + q4.z + "}"); + System.out.println("Quat4f: 2xy + 2wz = m10: " + (2 * q4.x * q4.y + 2 * q4.w * q4.z) + " = " + mat.m10); + */ - + Quaternion q = new Quaternion(mat); - + /* - System.out.println("Quaternion mat from q \n" + q.getMatrix()); - System.out.println("Quaternion: " + q.getNormal() + " " + q.getTheta()); - AxisAngle4f a = new AxisAngle4f(); - a.set(mat); - Vector3f v = new Vector3f(a.x, a.y, a.z); - v.normalize(); - System.out.println("angleAxis: " + v + " "+(a.angle/Math.PI * 180)); - */ - + System.out.println("Quaternion mat from q \n" + q.getMatrix()); + System.out.println("Quaternion: " + q.getNormal() + " " + q.getTheta()); + AxisAngle4f a = new AxisAngle4f(); + a.set(mat); + Vector3f v = new Vector3f(a.x, a.y, a.z); + v.normalize(); + System.out.println("angleAxis: " + v + " "+(a.angle/Math.PI * 180)); + */ + return q; } @@ -206,7 +208,7 @@ setMatrix(); return mat; } - + private void setMatrix() { mat = new Matrix3f(); // q0 = w, q1 = x, q2 = y, q3 = z @@ -220,7 +222,7 @@ mat.m21 = 2 * q2 * q3 + 2 * q0 * q1; mat.m22 = q0 * q0 - q1 * q1 - q2 * q2 + q3 * q3; } - + public Quaternion add(float x) { // UNIT addition return new Quaternion(getNormal(), getTheta() + x); @@ -228,63 +230,64 @@ public Quaternion mul(float x) { // UNIT multiplication - if (x == 1 || x == -1) - return new Quaternion(q0 * x, q1 * x, q2 * x, q3 * x); + if (x == 1) + return new Quaternion(q0, q1, q2, q3); return new Quaternion(getNormal(), getTheta() * x); } - + public Quaternion mul(Quaternion p) { - return new Quaternion( - q0 * p.q0 - q1 * p.q1 - q2 * p.q2 - q3 * p.q3, - q0 * p.q1 + q1 * p.q0 + q2 * p.q3 - q3 * p.q2, - q0 * p.q2 + q2 * p.q0 + q3 * p.q1 - q1 * p.q3, - q0 * p.q3 + q3 * p.q0 + q1 * p.q2 - q2 * p.q1 - ); + return new Quaternion(q0 * p.q0 - q1 * p.q1 - q2 * p.q2 - q3 * p.q3, q0 + * p.q1 + q1 * p.q0 + q2 * p.q3 - q3 * p.q2, q0 * p.q2 + q2 * p.q0 + q3 + * p.q1 - q1 * p.q3, q0 * p.q3 + q3 * p.q0 + q1 * p.q2 - q2 * p.q1); } - + public Quaternion div(Quaternion p) { // unit quaternions assumed -- otherwise would scale by 1/p.dot(p) return mul(p.inv()); } - + public Quaternion divLeft(Quaternion p) { // unit quaternions assumed -- otherwise would scale by 1/p.dot(p) - return p.inv().mul(this); + return this.inv().mul(p); } - + public float dot(Quaternion q) { - return this.q0*q.q0 + this.q1*q.q1 + this.q2*q.q2 + this.q3*q.q3; + return this.q0 * q.q0 + this.q1 * q.q1 + this.q2 * q.q2 + this.q3 * q.q3; } - + public Quaternion inv() { return new Quaternion(q0, -q1, -q2, -q3); } - + public String toString() { fixQ(); return "{" + q0 + " " + q1 + " " + q2 + " " + q3 + "}"; } - + public Vector3f getVector(int i) { + if (i == -1) { + fixQ(); + return new Vector3f(q1, q2, q3); + } if (mat == null) setMatrix(); Vector3f v = new Vector3f(); mat.getColumn(i, v); return v; } - + public Vector3f getNormal() { fixQ(); Vector3f v = new Vector3f(q1, q2, q3); v.normalize(); return v; } - + public float getTheta() { fixQ(); - return (float) (Math.acos(q0) * 2 * 180/Math.PI); + return (float) (Math.acos(q0) * 2 * 180 / Math.PI); } - + public void getThetaDirected(Point4f axisAngle) { //fills in .w; float theta = getTheta(); @@ -295,12 +298,12 @@ } axisAngle.set(v.x, v.y, v.z, theta); } - + public Point4f toPoint4f() { fixQ(); return new Point4f(q1, q2, q3, q0); } - + public Point3f transform(Point3f pt) { if (mat == null) setMatrix(); @@ -317,4 +320,4 @@ return vNew; } -} \ No newline at end of file +} Modified: trunk/Jmol/src/org/jmol/viewer/Eval.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/Eval.java 2008-07-04 03:56:31 UTC (rev 9553) +++ trunk/Jmol/src/org/jmol/viewer/Eval.java 2008-07-04 18:54:31 UTC (rev 9554) @@ -395,7 +395,7 @@ return true; } - private Function getFunction(String name, int tok) { + private Function getFunction(String name) { if (name == null) return null; Function function = (Function) (name.indexOf("_") == 0 ? compiler.localFunctions @@ -403,8 +403,8 @@ return (function == null || function.aatoken == null ? null : function); } - private boolean loadFunction(String name, Vector params, int tok) { - Function function = getFunction(name, tok); + private boolean loadFunction(String name, Vector params) { + Function function = getFunction(name); if (function == null) return false; aatoken = function.aatoken; @@ -422,7 +422,7 @@ Token getFunctionReturn(String name, Vector params) throws ScriptException { pushContext(null); - loadFunction(name, params, Token.function); + loadFunction(name, params); instructionDispatchLoop(false); Token token = getContextVariableAsToken("_retval"); popContext(); @@ -972,7 +972,7 @@ script(token.tok == Token.javascript); break; case Token.function: - function(token.tok); + function(); break; case Token.sync: sync(); @@ -5137,11 +5137,11 @@ isScriptCheck = wasScriptCheck; } - private void function(int tokType) throws ScriptException { + private void function() throws ScriptException { if (isSyntaxCheck && !isScriptCheck) return; String name = (String) getToken(0).value; - if (getFunction(name, tokType) == null) + if (getFunction(name) == null) evalError(GT._("command expected")); Vector params = (statementLength == 1 || statementLength == 3 && tokAt(1) == Token.leftparen && tokAt(2) == Token.rightparen ? null @@ -5149,7 +5149,7 @@ if (isSyntaxCheck) return; pushContext(null); - loadFunction(name, params, tokType); + loadFunction(name, params); instructionDispatchLoop(false); popContext(); } @@ -7437,14 +7437,20 @@ private boolean insertArrayValue(String key, Token result) { int selector = result.intValue; + boolean isLocalArray = false; if (selector == Integer.MAX_VALUE) return false; result.intValue = Integer.MAX_VALUE; String s = Token.sValue(result); Object v = getParameter(key, false); - if (!(v instanceof String)) + if (v instanceof String[]) { + v = getParameter(key, true); + isLocalArray = true; + } else if (!(v instanceof String)) { return false; - v = getStringObjectAsToken((String) v, key); + } else { + v = getStringObjectAsToken((String) v, key); + } if (v instanceof Token) { Token token = (Token) v; if (token.tok != Token.list) @@ -7456,7 +7462,8 @@ selector = 0; if (array.length > selector) { array[selector] = s; - viewer.setListVariable(key, token); + if (!isLocalArray) + viewer.setListVariable(key, token); return true; } String[] arrayNew = ArrayUtil.ensureLength(array, selector + 1); @@ -7464,7 +7471,8 @@ arrayNew[i] = ""; arrayNew[selector] = s; token.value = arrayNew; - viewer.setListVariable(key, token); + if (!isLocalArray) + viewer.setListVariable(key, token); return true; } else if (v instanceof String) { String str = (String) v; @@ -11500,7 +11508,7 @@ oStack = new Token[maxLevel]; xStack = new Token[maxLevel]; if (logMessages) - Logger.info("initialize RPN on " + getScript()); + Logger.info("initialize RPN"); } Token getResult(boolean allowUnderflow, String key) throws ScriptException { @@ -11718,16 +11726,15 @@ if (logMessages) { dumpStacks(); Logger.info("\noperating, oPt=" + oPt + " isLeftOp=" + isLeftOp - + " oStack[oPt]=" + Token.nameOf(oStack[oPt].tok) + "/" - + Token.prec(oStack[oPt].tok) + " op=" + Token.nameOf(op.tok) - + "/" + Token.prec(op.tok)); + + " oStack[oPt]=" + Token.nameOf(oStack[oPt].tok) + " prec=" + + Token.prec(oStack[oPt].tok) + " pending op=" + Token.nameOf(op.tok) + + " prec=" + Token.prec(op.tok)); } // ) and ] must wait until matching ( or [ is found if (op.tok == Token.rightparen && oStack[oPt].tok == Token.leftparen) { // (x[2]) finalizes the selection - if (xPt < 0) - return false; - xStack[xPt] = Token.selectItem(xStack[xPt]); + if (xPt >= 0) + xStack[xPt] = Token.selectItem(xStack[xPt]); break; } @@ -11822,7 +11829,7 @@ } void dumpStacks() { - Logger.info("RPN stacks: for " + getScript()); + Logger.info("RPN stacks:"); for (int i = 0; i <= xPt; i++) Logger.info("x[" + i + "]: " + xStack[i]); Logger.info("\n"); @@ -11852,7 +11859,7 @@ return false; Token[] args = new Token[nParam]; for (int i = nParam; --i >= 0;) - args[i] = getX(); + args[i] = Token.selectItem(getX()); xPt--; //no script checking of functions because //we cannot know what variables are real @@ -12971,8 +12978,10 @@ return addX(q.y); case 3: return addX(q.z); + case 4: + return addX((new Quaternion(q)).getNormal()); case -1: - return addX(new Point3f(q.x, q.y, q.z)); + return addX(new Quaternion(q).getVector(-1)); case -2: return addX((new Quaternion(q)).getTheta()); case -3: Modified: trunk/Jmol/src/org/jmol/viewer/Jmol.properties =================================================================== --- trunk/Jmol/src/org/jmol/viewer/Jmol.properties 2008-07-04 03:56:31 UTC (rev 9553) +++ trunk/Jmol/src/org/jmol/viewer/Jmol.properties 2008-07-04 18:54:31 UTC (rev 9554) @@ -3,6 +3,10 @@ version=11.5.45_dev +# bug fix: local assignment var x = array() followed by x[n] = ... does not work +# bug fix: f(x[i],x[j]) selects only x[j], not both x[i] and x[j] +# bug fix: quaternion frame "n" recognizes file-based H atoms on N for frame definition + # ----------------------------------------------------------------------------- #version=11.5.44 Modified: trunk/Jmol/src/org/jmol/viewer/ScriptManager.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/ScriptManager.java 2008-07-04 03:56:31 UTC (rev 9553) +++ trunk/Jmol/src/org/jmol/viewer/ScriptManager.java 2008-07-04 18:54:31 UTC (rev 9554) @@ -205,7 +205,7 @@ String statusList, boolean isScriptFile, boolean isQuiet) { viewer.evalStringWaitStatus(returnType, strScript, statusList, - isScriptFile, isQuiet); + isScriptFile, isQuiet, true); } } Modified: trunk/Jmol/src/org/jmol/viewer/Viewer.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/Viewer.java 2008-07-04 03:56:31 UTC (rev 9553) +++ trunk/Jmol/src/org/jmol/viewer/Viewer.java 2008-07-04 18:54:31 UTC (rev 9554) @@ -3289,10 +3289,10 @@ public String evalFile(String strFilename) { //app -s flag - int ptWait = strFilename.indexOf(" -nowait"); + int ptWait = strFilename.indexOf(" -noqueue"); // for TestScripts.java if (ptWait >= 0) { return (String) evalStringWaitStatus("String", strFilename.substring(0, - ptWait), "", true, false); + ptWait), "", true, false, false); } return scriptManager.addScript(strFilename, true, false); } @@ -3399,7 +3399,7 @@ GT.setDoTranslate(false); String str = (String) evalStringWaitStatus("JSON", strScript, "+scriptStarted,+scriptStatus,+scriptEcho,+scriptTerminated", false, - false); + false, false); GT.setDoTranslate(doTranslateTemp); return str; } @@ -3409,7 +3409,7 @@ boolean doTranslateTemp = GT.getDoTranslate(); GT.setDoTranslate(false); Object ret = evalStringWaitStatus("object", strScript, statusList, false, - false); + false, false); GT.setDoTranslate(doTranslateTemp); return ret; } @@ -3417,14 +3417,14 @@ public Object evalStringWaitStatus(String returnType, String strScript, String statusList) { scriptManager.waitForQueue(); - return evalStringWaitStatus(returnType, strScript, statusList, false, false); + return evalStringWaitStatus(returnType, strScript, statusList, false, false, false); } int scriptIndex; synchronized Object evalStringWaitStatus(String returnType, String strScript, String statusList, - boolean isScriptFile, boolean isQuiet) { + boolean isScriptFile, boolean isQuiet, boolean isQueued) { // from the scriptManager only! if (checkResume(strScript)) return "script processing resumed"; //be very odd if this fired @@ -3443,6 +3443,7 @@ boolean historyDisabled = (strScript.indexOf(")") == 0); if (historyDisabled) strScript = strScript.substring(1); + historyDisabled = historyDisabled || !isQueued; //no history for scriptWait 11.5.45 boolean isOK = (isScriptFile ? eval.loadScriptFile(strScript, isQuiet) : eval.loadScriptString(strScript, isQuiet)); String strErrorMessage = eval.getErrorMessage(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |