Skip to content

Commit

Permalink
various updates
Browse files Browse the repository at this point in the history
includes VideoReader.java (not used in this project)
And .rxyz business
  • Loading branch information
BobHanson committed Jan 14, 2025
1 parent 3a206a8 commit 9ade877
Show file tree
Hide file tree
Showing 20 changed files with 4,775 additions and 4,436 deletions.
Binary file modified jars/JME-SwingJS.jar
Binary file not shown.
Binary file modified libjs/JME-SwingJS.zip
Binary file not shown.
6 changes: 6 additions & 0 deletions src/javajs/util/MeasureD.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ public static T3d[] computeHelicalAxis(P3d a, P3d b, Qd dq) {
*
* a negative angle implies a left-handed axis (sheets)
*/

double theta = dq.getTheta();
V3d n = dq.getNormal();
double v_dot_n = vab.dot(n);
Expand All @@ -144,6 +145,8 @@ public static T3d[] computeHelicalAxis(P3d a, P3d b, Qd dq) {
va_prime_d.scale(theta == 0 ? 0 : (vda.length() / Math.tan(theta
/ 2 / 180 * Math.PI)));
V3d r = V3d.newV(va_prime_d);
System.out.println(a + " " + b + " theta=" + theta
+ "v.n=" +v_dot_n +" n=" + n + " " + vda);
if (theta != 0)
r.add(vda);
P3d pt_a_prime = P3d.newP(a);
Expand All @@ -155,12 +158,15 @@ public static T3d[] computeHelicalAxis(P3d a, P3d b, Qd dq) {
P3d pt_b_prime = P3d.newP(pt_a_prime);
pt_b_prime.add(n);
theta = computeTorsion(a, pt_a_prime, pt_b_prime, b, true);
System.out.println(a + " " + pt_a_prime + " " + pt_b_prime + " " + b + " theta=" + theta
);
if (Double.isNaN(theta) || r.length() < 0.0001)
theta = dq.getThetaDirectedV(n); // allow for r = 0
// anything else is an array
double residuesPerTurn = Math.abs(theta == 0 ? 0 : 360d / theta);
double pitch = Math.abs(v_dot_n == 2E-45 ? 0 : n.length()
* (theta == 0 ? 1 : 360.0 / theta));
System.out.println("rpt " + residuesPerTurn + " " + theta + " " + pitch);
return new T3d[] { pt_a_prime, n, r, P3d.new3(theta, pitch, residuesPerTurn), pt_b_prime };
}

Expand Down
5 changes: 5 additions & 0 deletions src/javajs/util/VideoReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ protected void readBlock(List<Map<String, Object>> contents) throws IOException
long pt = this.pt;
blockLen = readInt();
blockType = readString(4);
if (blockLen == 1) {
// special flag for long length not int
// presuming here it is not THAT large
blockLen = (int) is.readLong();
}
if (verbose)
System.out.println(blockType + "\t" + pt + "\t0x" + Long.toHexString(pt) + "\t" + blockLen);
Map<String, Object> map = new Hashtable<>();
Expand Down
2 changes: 1 addition & 1 deletion src/org/jmol/api/SymmetryInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ SymmetryInterface setPointGroup(

boolean checkPeriodic(P3d pt);

Object staticConvertOperation(String string, M4d matrix);
Object staticConvertOperation(String string, M4d matrix, boolean asRationalMatrix);

int getAdditionalOperationsCount();

Expand Down
6 changes: 6 additions & 0 deletions src/org/jmol/script/ScriptMathProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -1859,6 +1859,12 @@ private boolean getPointOrBitsetOperation(T op, SV x2)
return addXDouble(((P4d) x2.value).w);
}
break;
case T.matrix4f:
switch (op.intValue) {
case T.rxyz:
return addXStr((String) vwr.getSymStatic().staticConvertOperation(null, (M4d) x2.value, true));
}
break;
case T.bitset:
boolean isAtoms = (op.intValue != T.bonds);
if (!isAtoms && x2.value instanceof BondSet)
Expand Down
6 changes: 3 additions & 3 deletions src/org/jmol/script/T.java
Original file line number Diff line number Diff line change
Expand Up @@ -1040,7 +1040,7 @@ static int getMaxMathParams(int tokCommand) {
public final static int fontcaching = booleanparam | 70;
public final static int fontscaling = booleanparam | 71;
public final static int forceautobond = booleanparam | 72;
public final static int fractionalrelative = booleanparam | 73;
public final static int fractionalrelative = booleanparam | 73; // abandoned
// see shapecommand public final static int frank = booleanparam | 72;
public final static int greyscalerendering = booleanparam | 74;
public final static int hbondsbackbone = booleanparam | 76;
Expand Down Expand Up @@ -2642,7 +2642,7 @@ else if (tokenThis.value == null)
"fontCaching",
"fontScaling",
"forceAutoBond",
"fractionalRelative",
"fractionalRelative", // abandoned
// see commands "frank",
"greyscaleRendering",
"hbondsBackbone",
Expand Down Expand Up @@ -3726,7 +3726,7 @@ else if (tokenThis.value == null)
fontcaching, // "fontCaching"
fontscaling, // "fontScaling"
forceautobond, // "forceAutoBond"
fractionalrelative, // "fractionalRelative"
fractionalrelative, // abandoned // "fractionalRelative"
// see commands "frank"
greyscalerendering, // "greyscaleRendering"
hbondsbackbone, // "hbondsBackbone"
Expand Down
5 changes: 3 additions & 2 deletions src/org/jmol/scriptext/CmdExt.java
Original file line number Diff line number Diff line change
Expand Up @@ -5241,7 +5241,8 @@ private void show() throws ScriptException {
break;
}
ret[0] = null;
pt2 = eval.centerParameter(++eval.iToken, ret);
if (tokAt(eval.iToken + 1) != 0 && tokAt(eval.iToken + 1) != T.string)
pt2 = eval.centerParameter(++eval.iToken, ret);
if (ret[0] != null && ((BS) ret[0]).isEmpty()) {
len = slen;
break;
Expand All @@ -5251,7 +5252,7 @@ private void show() throws ScriptException {
}
String type = (eval.iToken > 1 && tokAt(eval.iToken + 1) == T.string
? stringParameter(++eval.iToken)
: null);
: pt1 == null && pt2 == null ? "label" : null);
checkLength((len = ++eval.iToken) + filterLen);
if (!chk) {
Object o = vwr.getSymmetryInfo(vwr.getAllAtoms().nextSetBit(0), xyz,
Expand Down
121 changes: 80 additions & 41 deletions src/org/jmol/scriptext/MathExt.java
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,8 @@ private boolean evaluateMatrix(ScriptMathProcessor mp, SV[] args) {
? (String) args[n - 1].value
: null);
boolean asABC = "abc".equalsIgnoreCase(retType);
boolean asXYZ = "xyz".equalsIgnoreCase(retType);
boolean asXYZ = !asABC && "xyz".equalsIgnoreCase(retType);
boolean asRXYZ = !asABC & !asXYZ && "rxyz".equalsIgnoreCase(retType);
double[] a = null;
if (retType != null || lst != null || map != null)
n--;
Expand All @@ -299,7 +300,7 @@ private boolean evaluateMatrix(ScriptMathProcessor mp, SV[] args) {
case T.string:
String s = (String) args[0].value;

// first check for "t1>>t2>>t3"
// first check for "t1>t2>t3"
if (s.equals("h") || s.equals("r")
|| s.indexOf(",") >= 0 && s.indexOf(":") < 0)
m4 = (M4d) vwr.getSymTemp().convertTransform(s, null);
Expand Down Expand Up @@ -397,13 +398,20 @@ private boolean evaluateMatrix(ScriptMathProcessor mp, SV[] args) {
}
}
return (m4 == null ? mp.addXStr("")
: asABC || asXYZ ? mp.addXStr(matToString(m4, asABC)) : mp.addXM4(m4));
: asRXYZ || asABC || asXYZ ? mp.addXStr(matToString(m4, asRXYZ ? 0x1 : asABC ? 0xABC : 0)) : mp.addXM4(m4));
}

private String matToString(M4d m4, boolean asABC) {
return (asABC ?
vwr.getSymStatic().staticGetTransformABC(m4, false)
: (String) vwr.getSymStatic().staticConvertOperation("", m4));
private String matToString(M4d m4, int mode) {
SymmetryInterface sym = vwr.getSymStatic();
switch (mode) {
case 0x1:
return (String) sym.staticConvertOperation(null, m4, true);
case 0xABC:
return sym.staticGetTransformABC(m4, false);
default:
case 0: // xyz
return (String) vwr.getSymStatic().staticConvertOperation("", m4, false);
}
}

/**
Expand Down Expand Up @@ -513,10 +521,10 @@ private boolean evaluateSpacegroup(ScriptMathProcessor mp, SV[] args) {
: sym.getSpaceGroupJSON(vwr, xyzList.toLowerCase(), null,
Integer.MIN_VALUE));
}
if (xyzList.toUpperCase().startsWith("AFLOW/")) {
if (xyzList.toUpperCase().startsWith("AFLOWLIB/")) {
// "15" or "15.1"
return mp.addXObj(vwr.getSymTemp().getSpaceGroupJSON(vwr, "AFLOW",
xyzList.substring(6), 0));
return mp.addXObj(vwr.getSymTemp().getSpaceGroupJSON(vwr, "AFLOWLIB",
xyzList.substring(9), 0));
}
if (xyzList.startsWith("Hall:") || xyzList.indexOf("x") >= 0
|| ucParams != null) {
Expand Down Expand Up @@ -554,8 +562,10 @@ private boolean evaluateSpacegroup(ScriptMathProcessor mp, SV[] args) {
System.out.println("MathExt " + ret);
// "jmol" used will return the Jmol group if that was to be returned
@SuppressWarnings("unchecked")
String s = "" + ((Map<String, Object>) ret).get("itaIndex");
ret = vwr.getSymTemp().getSpaceGroupJSON(vwr, "ITA", s, 0);
Object o = ((Map<String, Object>) ret).get("itaIndex");
if (o != null) {
ret = vwr.getSymTemp().getSpaceGroupJSON(vwr, "ITA", o.toString(), 0);
}
}
return mp.addXObj(ret);
}
Expand Down Expand Up @@ -2745,7 +2755,7 @@ private boolean evaluateFormat(ScriptMathProcessor mp, int intValue,
break;
case SV.FORMAT_XYZ:
case SV.FORMAT_ABC:
return (x.tok == T.matrix4f && mp.addXStr(matToString((M4d) x.value, pt == SV.FORMAT_ABC)));
return (x.tok == T.matrix4f && mp.addXStr(matToString((M4d) x.value, pt == SV.FORMAT_ABC ? 0xABC : 0)));
default:
// case SV.FORMAT_JSON:
// case SV.FORMAT_BYTEARRAY:
Expand Down Expand Up @@ -4293,6 +4303,7 @@ private boolean evaluateSymop(ScriptMathProcessor mp, SV[] args,
// "matrix",
// "plane",
// "point",
// "rxyz",
// "rotationAngle",
// "timeReversal",
// "type",
Expand Down Expand Up @@ -4366,20 +4377,42 @@ private boolean evaluateSymop(ScriptMathProcessor mp, SV[] args,
}

@SuppressWarnings("unchecked")
private Object getSymopInfo(ScriptMathProcessor mp, SV x1, SV[] args, int index, boolean isProperty) throws ScriptException {
private Object getSymopInfo(ScriptMathProcessor mp, SV x1, SV[] args,
int index, boolean isProperty)
throws ScriptException {

// static calls in SymmetryOperation
Object o = null;

int narg = args.length;
if (narg == 2 && args[0].tok == T.string && args[1].tok == T.string
&& ((String) args[1].value).equalsIgnoreCase("matrix")) {
return vwr.getSymStatic().staticConvertOperation((String) args[0].value, null);
}
if (narg == 2 && args[0].tok == T.matrix4f && args[1].tok == T.string
&& ((String) args[1].value).equalsIgnoreCase("xyz")) {
return vwr.getSymStatic().staticConvertOperation("", (M4d) args[0].value);
String str1 = (narg == 2 && args[1].tok == T.string
? ((String) args[1].value).toLowerCase()
: null);
boolean isrxyz = "rxyz".equals(str1);
if (str1 != null) {
M4d m = null;
String xyz = null;
switch (args[0].tok) {
case T.string:
switch (str1) {
case "rxyz":
case "matrix":
xyz = (String) args[0].value;
}
break;
case T.matrix4f:
switch (str1) {
case "rxyz":
case "xyz":
m = (M4d) args[0].value;
break;
}
break;
}
if (m != null || xyz != null)
return vwr.getSymStatic().staticConvertOperation(xyz, m, isrxyz);
}

boolean isPoint = false;
if (x1 != null && x1.tok != T.bitset && !(isPoint = (x1.tok == T.point3f)))
return null;
Expand All @@ -4405,14 +4438,16 @@ private Object getSymopInfo(ScriptMathProcessor mp, SV x1, SV[] args, int index,
int apt = 0;
P3d pt2 = null;
BS bs1 = null;
boolean isWyckoff = false;
boolean isWyckoff = false;
switch (args[0].tok) {
case T.string:
xyz = SV.sValue(args[0]);
switch (xyz == null ? "" : xyz.toLowerCase()) {
case "count":
SymmetryInterface sym = vwr.getOperativeSymmetry();
return (narg != 1 ? null : Integer.valueOf(sym == null ? 0 : sym.getSpaceGroupOperationCount()));
case "count":
SymmetryInterface sym = vwr.getOperativeSymmetry();
return (narg != 1 ? null
: Integer
.valueOf(sym == null ? 0 : sym.getSpaceGroupOperationCount()));
case "":
tok = T.nada;
break;
Expand Down Expand Up @@ -4558,14 +4593,18 @@ private Object getSymopInfo(ScriptMathProcessor mp, SV x1, SV[] args, int index,
String desc = (narg == apt
? (isWyckoff ? ""
: tok == T.var ? "id"
: pt2 != null ? "all" : pt1 != null ? "point" : "matrix")
: pt2 != null || pt1 == null ? "matrix" : "point")
: SV.sValue(args[apt++]));
boolean haveAtom = ((!isWyckoff || isProperty) && bsAtoms != null && !bsAtoms.isEmpty());
if (narg > 2)
isrxyz = "rxyz".equals(desc);

boolean haveAtom = ((!isWyckoff || isProperty) && bsAtoms != null
&& !bsAtoms.isEmpty());
int iatom = (haveAtom ? bsAtoms.nextSetBit(0) : -1);
if (isWyckoff) {
P3d pt = (haveAtom ? vwr.ms.getAtom(iatom) : pt1);
while (desc.length() > 0 && PT.isDigit(desc.charAt(0)))
desc = desc.substring(1);
desc = desc.substring(1);
if (pt == null) {
switch (desc) {
case "":
Expand All @@ -4576,21 +4615,19 @@ private Object getSymopInfo(ScriptMathProcessor mp, SV x1, SV[] args, int index,
if (desc.length() == 1)
desc += "*";
else
return null;
return null;
}
}
if (desc.length() == 0 || desc.equalsIgnoreCase("label"))
desc = null;
String letter = (desc == null ? (tok == T.wyckoffm ? "" : null)
: desc.endsWith("*")
|| desc.equalsIgnoreCase("coord")
|| desc.equalsIgnoreCase("coords")? desc : desc.substring(0, 1));
SymmetryInterface sym = vwr.getOperativeSymmetry();
return (sym == null ? null
: sym.getWyckoffPosition(vwr, pt,
(letter == null ?
(tok == T.wyckoffm ? "M" : null)
: (tok == T.wyckoffm ? "M" :"") + letter)));
String letter = (desc == null ? (tok == T.wyckoffm ? "" : null)
: desc.endsWith("*") || desc.equalsIgnoreCase("coord")
|| desc.equalsIgnoreCase("coords") ? desc : desc.substring(0, 1));
SymmetryInterface sym = vwr.getOperativeSymmetry();
return (sym == null ? null
: sym.getWyckoffPosition(vwr, pt,
(letter == null ? (tok == T.wyckoffm ? "M" : null)
: (tok == T.wyckoffm ? "M" : "") + letter)));
}
desc = desc.toLowerCase();
if (tok == T.var || desc.equals(JC.MODELKIT_INVARIANT) && isProperty) {
Expand Down Expand Up @@ -4622,8 +4659,10 @@ private Object getSymopInfo(ScriptMathProcessor mp, SV x1, SV[] args, int index,
}
return ret;
}
return (apt == args.length ? vwr.getSymmetryInfo(iatom, xyz,
index > 0 ? index : iOp, trans, pt1, pt2, T.array, desc, 0, nth, 0, null) : null);
return(apt == args.length
? vwr.getSymmetryInfo(iatom, xyz, index > 0 ? index : iOp, trans, pt1,
pt2, T.array, desc, 0, nth, 0, null)
: null);
}

private boolean evaluateTensor(ScriptMathProcessor mp, SV[] args)
Expand Down
21 changes: 13 additions & 8 deletions src/org/jmol/symmetry/CLEG.java
Original file line number Diff line number Diff line change
Expand Up @@ -333,9 +333,13 @@ private void init(ClegData data, String name) {
return;
}
hallSymbol = name.substring(1, pt);
pt = name.indexOf(":", pt);
if (pt > 0)
hallTrm = name.substring(pt + 1);
pt = hallSymbol.indexOf("(");
if (pt > 0) {
hallTrm = hallSymbol.substring(pt + 1, hallSymbol.length() - 1) + " ";
hallSymbol = hallSymbol.substring(0, pt).trim();
hallTrm = PT.rep(hallTrm, " ", "/12,");
hallTrm = "a,b,c;" + hallTrm.substring(0, hallTrm.length() - 1);
}
name = "Hall:" + hallSymbol;
} else if (name.startsWith("HM:")) {
// not sure this is still useful; ok, leave this this way
Expand Down Expand Up @@ -384,9 +388,10 @@ private void init(ClegData data, String name) {
if (myTrm.equals("a,b,c")) {
myTrm = hallTrm;
} else {
data.errString = "Non-reference Hall symbol cannot also contain a setting: "
+ name + "!";
return;
myTrm += ">" + hallTrm;
// data.errString = "Non-reference Hall symbol cannot also contain a setting: "
// + name + "!";
// return;
}
}
}
Expand Down Expand Up @@ -492,7 +497,7 @@ public boolean update(ClegData data) {
if (!disabled)
data.addSGTransform(myTrm, "myTrm");
calculated = data.calculate(trm0);
System.out.println("calculated is " + calculated);
System.out.println("calculated is " + calculated + (data.retMap == null ? "" : " for the path " + data.retMap.get("indexPath")));
return true;
}

Expand Down Expand Up @@ -645,7 +650,7 @@ public static void standardizeTokens(String[] tokens, boolean isEnd) {
}

public static String cleanCleg000(String t) {
return (t.endsWith(";0,0,0") ? t.substring(t.length() - 6) : t);
return (t.endsWith(";0,0,0") ? t.substring(0, t.length() - 6) : t);
}

/**
Expand Down
Loading

0 comments on commit 9ade877

Please sign in to comment.