Revision: 20816 http://sourceforge.net/p/jmol/code/20816 Author: hansonr Date: 2015-10-10 16:49:59 +0000 (Sat, 10 Oct 2015) Log Message: ----------- new feature: unitcell() function // optional last parameter: scale // unitcell() // unitcell(uc) // unitcell(uc, "reciprocal") // unitcell(ucconv, "primitive","BCC"|"FCC") // unitcell(ucprim, "conventional","BCC"|"FCC"|...?) //not yet implemented // unitcell(origin, [va, vb, vc]) // unitcell(origin, pta, ptb, ptc)
Modified Paths: -------------- trunk/Jmol/src/org/jmol/adapter/readers/cif/Subsystem.java trunk/Jmol/src/org/jmol/api/SymmetryInterface.java trunk/Jmol/src/org/jmol/script/T.java trunk/Jmol/src/org/jmol/scriptext/MathExt.java trunk/Jmol/src/org/jmol/symmetry/Symmetry.java trunk/Jmol/src/org/jmol/symmetry/UnitCell.java trunk/Jmol/src/org/jmol/util/SimpleUnitCell.java trunk/Jmol/src/org/jmol/viewer/Jmol.properties Modified: trunk/Jmol/src/org/jmol/adapter/readers/cif/Subsystem.java =================================================================== --- trunk/Jmol/src/org/jmol/adapter/readers/cif/Subsystem.java 2015-10-09 23:01:06 UTC (rev 20815) +++ trunk/Jmol/src/org/jmol/adapter/readers/cif/Subsystem.java 2015-10-10 16:49:59 UTC (rev 20816) @@ -5,11 +5,13 @@ import javajs.util.Lst; import javajs.util.M4; import javajs.util.Matrix; +import javajs.util.T3; import javajs.util.V3; import org.jmol.api.SymmetryInterface; import org.jmol.symmetry.Symmetry; import org.jmol.util.Logger; +import org.jmol.util.SimpleUnitCell; class Subsystem { @@ -72,8 +74,8 @@ // Part 2: Get the new unit cell and symmetry operators SymmetryInterface s0 = msRdr.cr.asc.getSymmetry(); - V3[] vu43 = s0.getUnitCellVectors(); - V3[] vr43 = reciprocalsOf(vu43); + T3[] vu43 = s0.getUnitCellVectors(); + T3[] vr43 = SimpleUnitCell.getReciprocal(vu43); // using full matrix math here: // @@ -96,11 +98,11 @@ // back to vector notation and direct lattice - V3[] uc_nu = new V3[4]; + T3[] uc_nu = new T3[4]; uc_nu[0] = vu43[0]; // origin for (int i = 0; i < 3; i++) uc_nu[i + 1] = V3.new3((float) a[i][0], (float) a[i][1], (float) a[i][2]); - uc_nu = reciprocalsOf(uc_nu); + uc_nu = SimpleUnitCell.getReciprocal(uc_nu); symmetry = ((Symmetry) msRdr.cr.getInterface("org.jmol.symmetry.Symmetry")).getUnitCell(uc_nu, false, null); modMatrices = new Matrix[] { sigma_nu, tFactor }; if (!setOperators) @@ -160,17 +162,6 @@ return false; } - private V3[] reciprocalsOf(V3[] abc) { - V3[] rabc = new V3[4]; - rabc[0] = abc[0]; // origin - for (int i = 0; i < 3; i++) { - rabc[i + 1] = new V3(); - rabc[i + 1].cross(abc[((i + 1) % 3) + 1], abc[((i + 2) % 3) + 1]); - rabc[i + 1].scale(1/abc[i + 1].dot(rabc[i + 1])); - } - return rabc; - } - @Override public String toString() { return "Subsystem " + code + "\n" + w; Modified: trunk/Jmol/src/org/jmol/api/SymmetryInterface.java =================================================================== --- trunk/Jmol/src/org/jmol/api/SymmetryInterface.java 2015-10-09 23:01:06 UTC (rev 20815) +++ trunk/Jmol/src/org/jmol/api/SymmetryInterface.java 2015-10-10 16:49:59 UTC (rev 20816) @@ -112,7 +112,7 @@ public String getUnitCellState(); - public V3[] getUnitCellVectors(); + public P3[] getUnitCellVectors(); public P3[] getUnitCellVerticesNoOffset(); Modified: trunk/Jmol/src/org/jmol/script/T.java =================================================================== --- trunk/Jmol/src/org/jmol/script/T.java 2015-10-09 23:01:06 UTC (rev 20815) +++ trunk/Jmol/src/org/jmol/script/T.java 2015-10-10 16:49:59 UTC (rev 20816) @@ -271,13 +271,13 @@ public final static int throwcmd = 6 | mathExpressionCommand; //public final static int prompt see mathfunc - public final static int echo = 1 /* must be odd */ | implicitStringCommand | shapeCommand | setparam; + public final static int echo = 1 /* must be odd */ | implicitStringCommand | shapeCommand | setparam; public final static int help = 2 /* must be even */ | implicitStringCommand; - public final static int hover = 3 /* must be odd */ | implicitStringCommand | defaultON; + public final static int hover = 3 /* must be odd */ | implicitStringCommand | defaultON; //public final static int javascript see mathfunc //public final static int label see mathfunc public final static int message = 5 /* must be odd */ | implicitStringCommand; - public final static int pause = 7 /* must be odd */ | implicitStringCommand; + public final static int pause = 7 /* must be odd */ | implicitStringCommand; //these commands control flow //sorry about GOTO! @@ -389,10 +389,10 @@ public final static int nbo = shapeCommand | 19 | misc; public final static int pmesh = shapeCommand | 20; public final static int plot3d = shapeCommand | 22; -// public final static int polyhedra = shapeCommand | 24 | predefinedset; - //public final static int spacefill see floatproperty + // public final static int polyhedra see mathfunc + // public final static int spacefill see floatproperty public final static int struts = shapeCommand | 26 | defaultON; - public final static int unitcell = shapeCommand | 28 | deprecatedparam | predefinedset | defaultON; + // public final static int unitcell see mathfunc public final static int vector = shapeCommand | 30; public final static int wireframe = shapeCommand | 32 | defaultON; @@ -657,7 +657,8 @@ // // maximum number of parameters is set by the << 9 shift // the min/max mask requires that the first number here must not exceed 63 - // the only other requirement is that these numbers be unique + // the only other requirement is that these numbers be unique, so the initial + // number can be duplicated if necessary, as long as other flags are different static int getMaxMathParams(int tokCommand) { @@ -669,41 +670,40 @@ // xxx(a,b,c,d,e,...) - public final static int in = 1 | 0 << 9 | mathfunc | mathproperty; public final static int angle = 1 | 0 << 9 | mathfunc; public final static int array = 2 | 0 << 9 | mathfunc | mathproperty; public final static int axisangle = 3 | 0 << 9 | mathfunc; - public final static int bin = 3 | 0 << 9 | mathfunc | mathproperty; - public final static int color = 4 | 0 << 9 | mathfunc | intproperty | scriptCommand | deprecatedparam | settable; - public final static int compare = 5 | 0 << 9 | mathfunc | scriptCommand; - public final static int connected = 6 | 0 << 9 | mathfunc; - public final static int polyhedra = 7 | 0 << 9 | mathfunc | mathproperty | shapeCommand; + public final static int bin = 4 | 0 << 9 | mathfunc | mathproperty; + public final static int cache = 5 | 0 << 9 | mathfunc | scriptCommand; // new in Jmol 13.1.2 + public final static int color = 6 | 0 << 9 | mathfunc | intproperty | scriptCommand | deprecatedparam | settable; + public final static int compare = 7 | 0 << 9 | mathfunc | scriptCommand; + public final static int connected = 8 | 0 << 9 | mathfunc; + public final static int count = 9 | 0 << 9 | mathfunc | mathproperty; + public final static int data = 10 | 0 << 9 | mathfunc | scriptCommand; + public final static int find = 11 | 0 << 9 | mathfunc | mathproperty; + public final static int format = 12 | 0 << 9 | mathfunc | mathproperty | strproperty | settable; + public final static int function = 13 | 0 << 9 | mathfunc | flowCommand; + public final static int getproperty = 14 | 0 << 9 | mathfunc | mathproperty | scriptCommand; + public final static int helix = 15 | 0 << 9 | mathfunc | predefinedset; + public final static int in = 16 | 0 << 9 | mathfunc | mathproperty; + public final static int label = 18 /* must NOT be odd */| 0 << 9 | mathfunc | mathproperty | strproperty | settable | implicitStringCommand | shapeCommand | defaultON | deprecatedparam; + public final static int measure = 19 | 0 << 9| mathfunc | shapeCommand | deprecatedparam | defaultON; + public final static int modulation = 20 | 0 << 9 | mathfunc | mathproperty | scriptCommand; + public final static int now = 21 | 0 << 9 | mathfunc; + public final static int plane = 22 | 0 << 9 | mathfunc; + public final static int point = 23 | 0 << 9 | mathfunc; + public final static int polyhedra = 24 | 0 << 9 | mathfunc | mathproperty | shapeCommand; + public final static int pop = 25 | 0 << 9 | mathfunc | mathproperty | scriptCommand | noArgs; //internal only; + public final static int quaternion = 26 | 0 << 9 | mathfunc | scriptCommand; + public final static int replace = 27 | 0 << 9 | mathfunc | mathproperty; + public final static int sort = 28 | 0 << 9 | mathfunc | mathproperty; + public final static int tensor = 29 | 0 << 9 | mathfunc | mathproperty; + public final static int unitcell = 30 | 0 << 9 | mathfunc | shapeCommand | deprecatedparam | predefinedset | defaultON; + public final static int within = 31 | 0 << 9 | mathfunc; + public final static int write = 32 | 0 << 9 | mathfunc | scriptCommand; + public final static int _ = 33 | 0 << 9 | mathfunc | mathproperty; // same as getProperty - public final static int data = 8 | 0 << 9 | mathfunc | scriptCommand; - public final static int format = 7 | 0 << 9 | mathfunc | mathproperty | strproperty | settable; - public final static int function = 9 | 0 << 9 | mathfunc | flowCommand; - public final static int getproperty = 10 | 0 << 9 | mathfunc | mathproperty | scriptCommand; - public final static int helix = 11 | 0 << 9 | mathfunc | predefinedset; - public final static int label = 12 /* must NOT be odd */| 0 << 9 | mathfunc | mathproperty | strproperty | settable | implicitStringCommand | shapeCommand | defaultON | deprecatedparam; - public final static int measure = 13 | 0 << 9| mathfunc | shapeCommand | deprecatedparam | defaultON; - public final static int now = 14 | 0 << 9 | mathfunc; - public final static int plane = 15 | 0 << 9 | mathfunc; - public final static int point = 16 | 0 << 9 | mathfunc; - public final static int pop = 17 | 0 << 9 | mathfunc | mathproperty | scriptCommand | noArgs; //internal only; - public final static int quaternion = 18 | 0 << 9 | mathfunc | scriptCommand; - public final static int sort = 19 | 0 << 9 | mathfunc | mathproperty; - public final static int count = 20 | 0 << 9 | mathfunc | mathproperty; - public final static int within = 21 | 0 << 9 | mathfunc; - public final static int write = 22 | 0 << 9 | mathfunc | scriptCommand; - public final static int cache = 23 | 0 << 9 | mathfunc | scriptCommand; // new in Jmol 13.1.2 - public final static int tensor = 24 | 0 << 9 | mathfunc | mathproperty; - public final static int modulation = 25 | 0 << 9 | mathfunc | mathproperty | scriptCommand; - public final static int _ = 26 | 0 << 9 | mathfunc | mathproperty; // same as getProperty - public final static int find = 27 | 0 << 9 | mathfunc | mathproperty; - public final static int replace = 28 | 0 << 9 | mathfunc | mathproperty; - - // xxx(a) public final static int acos = 2 | 1 << 9 | mathfunc; @@ -725,22 +725,22 @@ // two parameters and it CAN be a dot-function (but not both together) public final static int div = 0 | 1 << 9 | mathfunc | mathproperty; - public final static int mul = 3 | 1 << 9 | mathfunc | mathproperty; - public final static int mul3 = 4 | 1 << 9 | mathfunc | mathproperty; - public final static int sub = 7 | 1 << 9 | mathfunc | mathproperty; - public final static int trim = 8 | 1 << 9 | mathfunc | mathproperty; - public final static int volume = 9 | 1 << 9 | mathfunc | mathproperty | floatproperty; - public final static int col = 10 | 1 << 9 | mathfunc | mathproperty; - public final static int row = 11 | 1 << 9 | mathfunc | mathproperty; + public final static int mul = 1 | 1 << 9 | mathfunc | mathproperty; + public final static int mul3 = 2 | 1 << 9 | mathfunc | mathproperty; + public final static int sub = 3 | 1 << 9 | mathfunc | mathproperty; + public final static int trim = 4 | 1 << 9 | mathfunc | mathproperty; + public final static int volume = 5 | 1 << 9 | mathfunc | mathproperty | floatproperty; + public final static int col = 6 | 1 << 9 | mathfunc | mathproperty; + public final static int row = 7 | 1 << 9 | mathfunc | mathproperty; // xxx(a,b) - public final static int load = 3 | 2 << 9 | mathfunc | scriptCommand; - public final static int script = 5 | 2 << 9 | mathfunc | scriptCommand; - public final static int substructure = 6 | 2 << 9 | mathfunc | intproperty | strproperty; - public final static int search = 7 | 2 << 9 | mathfunc; - public final static int smiles = 8 | 2 << 9 | mathfunc; - public final static int contact = 9 | 2 << 9 | mathfunc | shapeCommand; + public final static int load = 1 | 2 << 9 | mathfunc | scriptCommand; + public final static int script = 2 | 2 << 9 | mathfunc | scriptCommand; + public final static int substructure = 3 | 2 << 9 | mathfunc | intproperty | strproperty; + public final static int search = 4 | 2 << 9 | mathfunc; + public final static int smiles = 5 | 2 << 9 | mathfunc; + public final static int contact = 6 | 2 << 9 | mathfunc | shapeCommand; // ___.xxx(a,b) Modified: trunk/Jmol/src/org/jmol/scriptext/MathExt.java =================================================================== --- trunk/Jmol/src/org/jmol/scriptext/MathExt.java 2015-10-09 23:01:06 UTC (rev 20815) +++ trunk/Jmol/src/org/jmol/scriptext/MathExt.java 2015-10-10 16:49:59 UTC (rev 20816) @@ -35,6 +35,7 @@ import org.jmol.api.JmolDataManager; import org.jmol.api.JmolNMRInterface; import org.jmol.api.JmolPatternMatcher; +import org.jmol.api.SymmetryInterface; import org.jmol.atomdata.RadiusData; import org.jmol.atomdata.RadiusData.EnumType; import org.jmol.bspt.Bspt; @@ -58,6 +59,7 @@ import org.jmol.util.Edge; import org.jmol.util.Parser; import org.jmol.util.Point3fi; +import org.jmol.util.SimpleUnitCell; import javajs.util.AU; import javajs.util.Lst; @@ -140,6 +142,8 @@ case T.connected: case T.polyhedra: return evaluateConnected(mp, args, tok); + case T.unitcell: + return evaluateUnitCell(mp, args); case T.contact: return evaluateContact(mp, args); case T.data: @@ -217,6 +221,93 @@ return false; } + private boolean evaluateUnitCell(ScriptMathProcessor mp, SV[] args) { + // optional last parameter: scale + // unitcell() + // unitcell(uc) + // unitcell(uc, "reciprocal") + // unitcell(ucconv, "primitive","BCC"|"FCC") + // unitcell(ucprim, "conventional","BCC"|"FCC"|...?) //not yet implemented + // unitcell(origin, [va, vb, vc]) + // unitcell(origin, pta, ptb, ptc) + int lastParam = args.length - 1; + float scale = 1; + switch (lastParam < 0 ? T.nada : args[lastParam].tok) { + case T.integer: + case T.decimal: + scale = args[lastParam].asFloat(); + lastParam--; + break; + } + int tok0 = (lastParam < 0 ? T.nada : args[0].tok); + Lst<SV> uc = (tok0 == T.varray ? args[0].getList() : null); + SymmetryInterface u = null; + boolean haveUC = (uc != null); + if (haveUC && uc.size() < 4) + return false; + int ptParam = (haveUC ? 1 : 0); + T3[] ucnew = null; + if (!haveUC && tok0 != T.point3f) { + u = vwr.getCurrentUnitCell(); + ucnew = (u == null ? new P3[] { P3.new3(0, 0, 0), P3.new3(1, 0, 0), + P3.new3(0, 1, 0), P3.new3(0, 0, 1) } : u.getUnitCellVectors()); + } + if (ucnew == null) { + ucnew = new P3[4]; + if (haveUC) { + ucnew[0] = P3.newP(SV.ptValue(uc.get(0))); + for (int i = 1; i < 4; i++) + ucnew[i] = P3.newP(SV.ptValue(uc.get(i))); + } else { + ucnew[0] = SV.ptValue(args[0]); + switch (lastParam) { + case 3: + // unitcell(origin, pa, pb, pc) + for (int i = 1; i < 4; i++) + (ucnew[i] = P3.newP(SV.ptValue(args[i]))).sub(ucnew[0]); + break; + case 1: + // unitcell(origin, [va, vb, vc]) + Lst<SV> l = args[1].getList(); + if (l != null && l.size() == 3) { + for (int i = 0; i < 3; i++) + ucnew[i + 1] = SV.ptValue(l.get(i)); + break; + } + //$FALL-THROUGH$ + default: + return false; + } + } + } + String op = (ptParam <= lastParam ? args[ptParam++].asString() : null); + if ("reciprocal".equalsIgnoreCase(op)) { + ucnew = SimpleUnitCell.getReciprocal(ucnew); + } else if ("primitive".equalsIgnoreCase(op)) { + String type = args[ptParam].asString(); + float[] f = null; + if (type.equalsIgnoreCase("BCC")) + f = new float[] { .5f, .5f, -.5f, -.5f, .5f, .5f, .5f, -.5f, .5f }; + else if (type.equalsIgnoreCase("FCC")) + f = new float[] { .5f, .5f, 0, 0, .5f, .5f, .5f, 0, .5f }; + if (f == null) + return false; + P3[] b = new P3[3]; + for (int i = 0, p = 0; i < 3; i++) { + b[i] = new P3(); + for (int j = 1; j < 4; j++) + b[i].scaleAdd2(f[p++], ucnew[j], b[i]); + } + for (int i = 0; i < 3; i++) + ucnew[i + 1] = b[i]; + + } + if (scale != 1) + for (int i = 1; i < 4; i++) + ucnew[i].scale(scale); + return mp.addXObj(ucnew); + } + @SuppressWarnings("unchecked") private boolean evaluateArray(ScriptMathProcessor mp, SV[] args, boolean isSelector) throws ScriptException { if (isSelector) { Modified: trunk/Jmol/src/org/jmol/symmetry/Symmetry.java =================================================================== --- trunk/Jmol/src/org/jmol/symmetry/Symmetry.java 2015-10-09 23:01:06 UTC (rev 20815) +++ trunk/Jmol/src/org/jmol/symmetry/Symmetry.java 2015-10-10 16:49:59 UTC (rev 20816) @@ -521,7 +521,7 @@ } @Override - public V3[] getUnitCellVectors() { + public P3[] getUnitCellVectors() { return unitCell.getUnitCellVectors(); } Modified: trunk/Jmol/src/org/jmol/symmetry/UnitCell.java =================================================================== --- trunk/Jmol/src/org/jmol/symmetry/UnitCell.java 2015-10-09 23:01:06 UTC (rev 20815) +++ trunk/Jmol/src/org/jmol/symmetry/UnitCell.java 2015-10-10 16:49:59 UTC (rev 20816) @@ -478,13 +478,13 @@ return unitCellMultiplier; } - public V3[] getUnitCellVectors() { + public P3[] getUnitCellVectors() { M4 m = matrixFractionalToCartesian; - return new V3[] { - V3.newV(cartesianOffset), - V3.new3(fix(m.m00), fix(m.m10), fix(m.m20)), - V3.new3(fix(m.m01), fix(m.m11), fix(m.m21)), - V3.new3(fix(m.m02), fix(m.m12), fix(m.m22)) }; + return new P3[] { + P3.newP(cartesianOffset), + P3.new3(fix(m.m00), fix(m.m10), fix(m.m20)), + P3.new3(fix(m.m01), fix(m.m11), fix(m.m21)), + P3.new3(fix(m.m02), fix(m.m12), fix(m.m22)) }; } private float fix(float x) { Modified: trunk/Jmol/src/org/jmol/util/SimpleUnitCell.java =================================================================== --- trunk/Jmol/src/org/jmol/util/SimpleUnitCell.java 2015-10-09 23:01:06 UTC (rev 20815) +++ trunk/Jmol/src/org/jmol/util/SimpleUnitCell.java 2015-10-10 16:49:59 UTC (rev 20816) @@ -388,4 +388,16 @@ f /= 2; return f; } + + public static P3[] getReciprocal(T3[] abc) { + P3[] rabc = new P3[4]; + int off = (abc.length == 4 ? 1 : 0); + rabc[0] = (off == 1 ? P3.newP(abc[0]) : new P3()); // origin + for (int i = 0; i < 3; i++) { + rabc[i + 1] = new P3(); + rabc[i + 1].cross(abc[((i + off) % 3) + off], abc[((i + off + 1) % 3) + off]); + rabc[i + 1].scale(1/abc[i + off].dot(rabc[i + 1])); + } + return rabc; + } } Modified: trunk/Jmol/src/org/jmol/viewer/Jmol.properties =================================================================== --- trunk/Jmol/src/org/jmol/viewer/Jmol.properties 2015-10-09 23:01:06 UTC (rev 20815) +++ trunk/Jmol/src/org/jmol/viewer/Jmol.properties 2015-10-10 16:49:59 UTC (rev 20816) @@ -62,8 +62,21 @@ TODO: consider if models with no atoms will cause issues in relation to model.firstAtomIndex + Jmol.___JmolVersion="14.3.16_2015.10.09" +new feature: unitcell() function + // optional last parameter: scale + // unitcell() + // unitcell(uc) + // unitcell(uc, "reciprocal") + // unitcell(ucconv, "primitive","BCC"|"FCC") + // unitcell(ucprim, "conventional","BCC"|"FCC"|...?) //not yet implemented + // unitcell(origin, [va, vb, vc]) + // unitcell(origin, pta, ptb, ptc) + +JmolVersion="14.3.16_2015.10.09" + bug fix: print 'CCC'.find("SMILES") should throw a ScriptException, not a Java exception new feature: Gaussian log file reader reads spin density scalars as property_spin This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ _______________________________________________ Jmol-commits mailing list Jmol-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jmol-commits