From: <ha...@us...> - 2013-07-01 18:38:30
|
Revision: 18392 http://sourceforge.net/p/jmol/code/18392 Author: hansonr Date: 2013-07-01 18:38:26 +0000 (Mon, 01 Jul 2013) Log Message: ----------- Modified Paths: -------------- trunk/Jmol/src/org/jmol/adapter/readers/xtal/MagResReader.java trunk/Jmol/src/org/jmol/script/ScriptMathProcessor.java trunk/Jmol/src/org/jmol/util/Matrix3f.java trunk/Jmol/src/org/jmol/util/Quaternion.java trunk/Jmol/src/org/jmol/util/Tensor.java Modified: trunk/Jmol/src/org/jmol/adapter/readers/xtal/MagResReader.java =================================================================== --- trunk/Jmol/src/org/jmol/adapter/readers/xtal/MagResReader.java 2013-07-01 15:45:20 UTC (rev 18391) +++ trunk/Jmol/src/org/jmol/adapter/readers/xtal/MagResReader.java 2013-07-01 18:38:26 UTC (rev 18392) @@ -86,11 +86,9 @@ private void readTensorNew() throws Exception { String[] tokens = getTokens(); String id = tokens[0]; - int pt = id.indexOf("_"); - String type = (pt < 0 ? id : id.substring(0, pt)); String atomName1 = getAtomName(tokens[1], tokens[2]); - pt = 3; - String atomName2 = (type.equals("isc") ? getAtomName(tokens[pt++], tokens[pt++]) : null); + int pt = 3; + String atomName2 = (id.startsWith("isc") ? getAtomName(tokens[pt++], tokens[pt++]) : null); // TODO: maxIso for isc? double[][] a = new double[3][3]; for (int i = 0; i < 3; i++) @@ -98,7 +96,7 @@ a[i][j] = Double.valueOf(tokens[pt++]).doubleValue(); int index1 = atomSetCollection.getAtomIndexFromName(atomName1); int index2; - Tensor t = Tensor.getTensorFromAsymmetricTensor(a, type); + Tensor t = Tensor.getTensorFromAsymmetricTensor(a, id); if (atomName2 == null) { index2 = -1; atomSetCollection.getAtoms()[index1].addTensor(t, null); @@ -106,12 +104,13 @@ } else { index2 = atomSetCollection.getAtomIndexFromName(atomName2); } - t.setAtomIndexes(index1, index2); - if (tensorTypes.indexOf(type) < 0) { - tensorTypes += type; - appendLoadNote("Ellipsoids set \"" + type + "\": " - + (type.equals("ms") ? "Magnetic Shielding" : - type.equals("efg") ? "Electric Field Gradient" : type.equals("isc") ? "Coupling" : "?")); + t.setAtomIndexes(index1, index2); + String key = ";" + id +";"; + if (tensorTypes.indexOf(key) < 0) { + tensorTypes += key; + appendLoadNote("Ellipsoids set \"" + id + "\": " + + (id.startsWith("ms") ? "Magnetic Shielding" : + id.startsWith("efg") ? "Electric Field Gradient" : id.startsWith("isc") ? "J-Coupling" : "?")); } } Modified: trunk/Jmol/src/org/jmol/script/ScriptMathProcessor.java =================================================================== --- trunk/Jmol/src/org/jmol/script/ScriptMathProcessor.java 2013-07-01 15:45:20 UTC (rev 18391) +++ trunk/Jmol/src/org/jmol/script/ScriptMathProcessor.java 2013-07-01 18:38:26 UTC (rev 18392) @@ -3374,6 +3374,7 @@ // q%-5 Matrix column 2 // q%-6 AxisAngle format // q%-9 Matrix format + // q%-10 EulerZXZ (degrees) case 0: return addXFloat(pt4.w); case 1: @@ -3382,24 +3383,31 @@ return addXFloat(pt4.y); case 3: return addXFloat(pt4.z); + } + Quaternion q = Quaternion.newP4(pt4); + switch(n) { case 4: - return addXPt(P3.newP((Quaternion.newP4(pt4)).getNormal())); + return addXPt(P3.newP(q.getNormal())); + case 5: + return addXAF(q.getEulerZXZ()); + case 6: + return addXAF(q.getEulerZXZ()); case -1: - return addXPt(P3.newP(Quaternion.newP4(pt4).getVector(-1))); + return addXPt(P3.newP(q.getVector(-1))); case -2: - return addXFloat((Quaternion.newP4(pt4)).getTheta()); + return addXFloat(q.getTheta()); case -3: - return addXPt(P3.newP((Quaternion.newP4(pt4)).getVector(0))); + return addXPt(P3.newP(q.getVector(0))); case -4: - return addXPt(P3.newP((Quaternion.newP4(pt4)).getVector(1))); + return addXPt(P3.newP(q.getVector(1))); case -5: - return addXPt(P3.newP((Quaternion.newP4(pt4)).getVector(2))); + return addXPt(P3.newP(q.getVector(2))); case -6: - AxisAngle4f ax = (Quaternion.newP4(pt4)).toAxisAngle4f(); + AxisAngle4f ax = q.toAxisAngle4f(); return addXPt4(P4.new4(ax.x, ax.y, ax.z, (float) (ax.angle * 180 / Math.PI))); case -9: - return addXM3((Quaternion.newP4(pt4)).getMatrix()); + return addXM3(q.getMatrix()); default: return addXPt4(pt4); } Modified: trunk/Jmol/src/org/jmol/util/Matrix3f.java =================================================================== --- trunk/Jmol/src/org/jmol/util/Matrix3f.java 2013-07-01 15:45:20 UTC (rev 18391) +++ trunk/Jmol/src/org/jmol/util/Matrix3f.java 2013-07-01 18:38:26 UTC (rev 18392) @@ -28,6 +28,8 @@ * additions by Bob Hanson ha...@st... 9/30/2012 for unique * constructor and method names for the optimization of compiled * JavaScript using Java2Script + * + * */ public class Matrix3f implements Serializable { Modified: trunk/Jmol/src/org/jmol/util/Quaternion.java =================================================================== --- trunk/Jmol/src/org/jmol/util/Quaternion.java 2013-07-01 15:45:20 UTC (rev 18391) +++ trunk/Jmol/src/org/jmol/util/Quaternion.java 2013-07-01 18:38:26 UTC (rev 18392) @@ -48,6 +48,7 @@ private Matrix3f mat; private final static P4 qZero = new P4(); + private static final double RAD_PER_DEG = Math.PI / 180; public Quaternion() { q0 = 1; @@ -136,9 +137,9 @@ q0 = 1; return; } - double fact = (Math.sin(theta / 2 * Math.PI / 180) / Math.sqrt(pt.x + double fact = (Math.sin(theta / 2 * RAD_PER_DEG) / Math.sqrt(pt.x * pt.x + pt.y * pt.y + pt.z * pt.z)); - q0 = (float) (Math.cos(theta / 2 * Math.PI / 180)); + q0 = (float) (Math.cos(theta / 2 * RAD_PER_DEG)); q1 = (float) (pt.x * fact); q2 = (float) (pt.y * fact); q3 = (float) (pt.z * fact); @@ -314,10 +315,10 @@ q3 *= -1; } - public static final Quaternion getQuaternionFrame(P3 center, Tuple3f x, Tuple3f xy) { + public static final Quaternion getQuaternionFrame(P3 center, Tuple3f x, Tuple3f y) { V3 vA = V3.newV(x); vA.sub(center); - V3 vB = V3.newV(xy); + V3 vB = V3.newV(y); vB.sub(center); return getQuaternionFrameV(vA, vB, null, false); } @@ -802,4 +803,19 @@ return (float) Math.sqrt(sum2 / (n - 1)); } + public float[] getEulerZYZ() { + return null; + } + + public float[] getEulerZXZ() { + // NOT http://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles + // http://www.swarthmore.edu/NatSci/mzucker1/e27/diebel2006attitude.pdf + double rA, rB, rG; + rG = Math.atan2( 2 * (q1 * q3 - q0 * q2), 2 * (q2 * q3 + q0 * q1)); + rB = Math.acos(q3 * q3 - q2 * q2 - q1 * q1 + q0 * q0); + rA = Math.atan2(2 * (q1 * q3 + q0 * q2), 2 * (q0 * q1 - q2 * q3 )); + return new float[] {(float) (rA / RAD_PER_DEG), (float) (rB / RAD_PER_DEG), (float) (rG / RAD_PER_DEG)}; + } + + } Modified: trunk/Jmol/src/org/jmol/util/Tensor.java =================================================================== --- trunk/Jmol/src/org/jmol/util/Tensor.java 2013-07-01 15:45:20 UTC (rev 18391) +++ trunk/Jmol/src/org/jmol/util/Tensor.java 2013-07-01 18:38:26 UTC (rev 18392) @@ -65,7 +65,10 @@ private static final String KNOWN_TYPES = ";iso....;adp....;tls-u..;tls-r..;ms.....;efg....;isc....;charge.;"; private static int getType(String type) { - int pt = KNOWN_TYPES.indexOf(";" + type.toLowerCase() + "."); + int pt = type.indexOf("_"); + if (pt >= 0) + type = type.substring(0, pt); + pt = KNOWN_TYPES.indexOf(";" + type.toLowerCase() + "."); return (pt < 0 ? TYPE_OTHER : pt / 8); } @@ -110,9 +113,8 @@ public int atomIndex2 = -1; /** - * returns an object of the specified type, including - * "eigenvalues", "eigenvectors", "asymmetric", - * "symmetric", "trace", "indices", and "type" + * returns an object of the specified type, including "eigenvalues", + * "eigenvectors", "asymmetric", "symmetric", "trace", "indices", and "type" * * @param infoType * @return Object or null @@ -120,18 +122,10 @@ public Object getInfo(String infoType) { if (infoType.charAt(0) != ';') infoType = ";" + infoType + "."; - switch ((";............." - + ";eigenvalues.." - + ";eigenvectors." - + ";asymmetric..." - + ";symmetric...." - + ";trace........" - + ";haeberlen...." - + ";eulerzyz....." - + ";eulerzxz....." - + ";indices......" - + ";type........." - ).indexOf(infoType) / 14) { + switch ((";............." + ";eigenvalues.." + ";eigenvectors." + + ";asymmetric..." + ";symmetric...." + ";trace........" + + ";haeberlen...." + ";eulerzyz....." + ";eulerzxz....." + + ";indices......" + ";type.........").indexOf(infoType) / 14) { case 1: return eigenValues; case 2: @@ -159,25 +153,23 @@ return Float.valueOf(eigenValues[0] + eigenValues[1] + eigenValues[2]); case 6: // haeberlen float[] haeb = new float[3]; - haeb[0] = ((eigenValues[0] + eigenValues[1] + eigenValues[2])/3.0f); - haeb[1] = (eigenValues[2] - (eigenValues[0]+eigenValues[1])/2.0f); - if (haeb[1] != 0.0f) - haeb[2] = ((eigenValues[1]-eigenValues[0])/(eigenValues[2]-haeb[0])); - else - haeb[2] = 0.0f; + haeb[0] = (eigenValues[0] + eigenValues[1] + eigenValues[2]) / 3; + haeb[1] = eigenValues[2] - (eigenValues[0] + eigenValues[1]) / 2; + haeb[2] = (haeb[1] == 0 ? 0 : (eigenValues[1] - eigenValues[0]) + / (eigenValues[2] - haeb[0])); return haeb; case 7: // eulerzyz - // TODO - return null; + return Quaternion.getQuaternionFrame(P3.new3(0, 0, 0), + eigenVectors[0], eigenVectors[1]).getEulerZYZ(); case 8: // eulerzxz - // TODO - return null; + return Quaternion.getQuaternionFrame(P3.new3(0, 0, 0), + eigenVectors[0], eigenVectors[1]).getEulerZXZ(); case 9: // - return new int[] {modelIndex, atomIndex1, atomIndex2}; + return new int[] { modelIndex, atomIndex1, atomIndex2 }; case 10: return type; default: - return null; + return null; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |