sbCommand.append(" pmesh");
continue;
case Token.within:
ptWithin = i;
float distance;
Point3f ptc = null;
bs = null;
boolean havePt = false;
if (tokAt(i + 1) == Token.expressionBegin) {
// within ( x.x , .... )
distance = floatParameter(i + 3);
if (isPoint3f(i + 4)) {
ptc = centerParameter(i + 4);
havePt = true;
iToken = iToken + 2;
} else if (isPoint3f(i + 5)) {
ptc = centerParameter(i + 5);
havePt = true;
iToken = iToken + 2;
} else {
bs = atomExpression(statement, i + 5, statementLength, true, false,
false, true);
if (bs == null)
error(ERROR_invalidArgument);
}
} else {
distance = floatParameter(++i);
ptc = centerParameter(++i);
}
i = iToken;
if (fullCommand.indexOf("# WITHIN=") >= 0)
bs = Escape.unescapeBitset(extractCommandOption("# WITHIN"));
else if (!havePt)
bs = (expressionResult instanceof BitSet ? (BitSet) expressionResult
: null);
if (!isSyntaxCheck) {
if (bs != null)
bs.and(viewer.getModelUndeletedAtomsBitSet(modelIndex));
if (ptc == null)
ptc = viewer.getAtomSetCenter(bs);
getWithinDistanceVector(propertyList, distance, ptc, bs);
sbCommand.append(" within ").append(distance).append(" ").append(
bs == null ? Escape.escape(ptc) : Escape.escape(bs));
}
continue;
case Token.isosurfacepropertysmoothing:
smoothing = (getToken(++i).tok == Token.on ? Boolean.TRUE
: theTok == Token.off ? Boolean.FALSE : null);
if (smoothing == null)
error(ERROR_invalidArgument);
continue;
case Token.property:
case Token.variable:
if (modelIndex < 0)
error(ERROR_multipleModelsDisplayedNotOK, "ISOSURFACE "
+ theToken.value);
//if (isCavity)
//error(ERROR_invalidArgument);
boolean isVariable = (theTok == Token.variable);
if (dataUse == null) { // not mlp or mep
if (!surfaceObjectSeen && !planeSeen) {
surfaceObjectSeen = true;
addShapeProperty(propertyList, "sasurface", new Float(0));
sbCommand.append(" vdw");
}
propertyName = "property";
if (smoothing == null)
smoothing = viewer.getIsosurfacePropertySmoothing() ? Boolean.TRUE
: Boolean.FALSE;
addShapeProperty(propertyList, "propertySmoothing", smoothing);
sbCommand.append(" isosurfacePropertySmoothing " + smoothing);
if (viewer.isRangeSelected())
addShapeProperty(propertyList, "rangeSelected", Boolean.TRUE);
} else {
propertyName = dataUse;
}
str = parameterAsString(i);
sbCommand.append(" ").append(str);
if (str.toLowerCase().indexOf("property_") == 0) {
data = new float[viewer.getAtomCount()];
if (isSyntaxCheck)
continue;
data = viewer.getDataFloat(str);
if (data == null)
error(ERROR_invalidArgument);
addShapeProperty(propertyList, propertyName, data);
continue;
}
int atomCount = viewer.getAtomCount();
data = new float[atomCount];
if (isVariable) {
String vname = parameterAsString(++i);
if (vname.length() == 0) {
data = floatParameterSet(i, atomCount, atomCount);
} else {
data = new float[atomCount];
if (!isSyntaxCheck)
Parser.parseStringInfestedFloatArray(""
+ getParameter(vname, Token.string), null, data);
}
if (!isSyntaxCheck)
sbCommand.append(" \"\" ").append(Escape.escape(data));
} else {
int tokProperty = getToken(++i).tok;
if (!isSyntaxCheck) {
sbCommand.append(" " + theToken.value);
Atom[] atoms = viewer.getModelSet().atoms;
viewer.autoCalculate(tokProperty);
for (int iAtom = atomCount; --iAtom >= 0;)
data[iAtom] = Atom.atomPropertyFloat(viewer, atoms[iAtom],
tokProperty);
}
if (tokProperty == Token.color)
colorScheme = "colorRGB";
if (tokAt(i + 1) == Token.within) {
float d = floatParameter(i = i + 2);
sbCommand.append(" within " + d);
addShapeProperty(propertyList, "propertyDistanceMax", Float.valueOf(d));
}
}
propertyValue = data;
break;
case Token.model:
if (surfaceObjectSeen)
error(ERROR_invalidArgument);
modelIndex = modelNumberParameter(++i);
sbCommand.append(" model " + modelIndex);
if (modelIndex < 0) {
propertyName = "fixed";
propertyValue = Boolean.TRUE;
break;
}
propertyName = "modelIndex";
propertyValue = new Integer(modelIndex);
break;
case Token.select:
propertyName = "select";
BitSet bs1 = atomExpression(++i);
propertyValue = bs1;
i = iToken;
if (surfaceObjectSeen || isMapped) {
sbCommand.append(" select " + Escape.escape(propertyValue));
} else {
bsSelect = (BitSet) propertyValue;
if (modelIndex < 0 && bsSelect.nextSetBit(0) >= 0)
modelIndex = viewer.getAtomModelIndex(bsSelect.nextSetBit(0));
}
break;
case Token.set:
thisSetNumber = intParameter(++i);
sbCommand.append(" set " + thisSetNumber);
break;
case Token.offset:
propertyName = "offset";
propertyValue = centerParameter(++i);
i = iToken;
sbCommand.append(" offset " + Escape.escape((Point3f) propertyValue));
break;
case Token.center:
propertyName = "center";
propertyValue = centerParameter(++i);
sbCommand.append(" center " + Escape.escape((Point3f) propertyValue));
i = iToken;
break;
case Token.sign:
case Token.color:
int color;
idSeen = true;
sbCommand.append(" " + theToken.value);
boolean isSign = (theTok == Token.sign);
if (isSign) {
addShapeProperty(propertyList, "sign", Boolean.TRUE);
} else {
if (tokAt(i + 1) == Token.density) {
i++;
propertyName = "colorDensity";
sbCommand.append(" density");
break;
}
/*
* "color" now is just used as an equivalent to "sign" and as an
* introduction to "absolute" any other use is superfluous; it has
* been replaced with MAP for indicating "use the current surface"
* because the term COLOR is too general.
*/
if (getToken(i + 1).tok == Token.string) {
colorScheme = parameterAsString(++i);
sbCommand.append(" ").append(Escape.escape(colorScheme));
if (colorScheme.indexOf(" ") > 0) {
discreteColixes = Graphics3D.getColixArray(colorScheme);
if (discreteColixes == null)
error(ERROR_badRGBColor);
}
} else if (theTok == Token.mesh) {
i++;
sbCommand.append(" mesh");
color = getArgbParam(++i);
addShapeProperty(propertyList, "meshcolor", new Integer(color));
sbCommand.append(" ").append(Escape.escapeColor(color));
i = iToken;
continue;
}
if ((theTok = tokAt(i + 1)) == Token.translucent
|| theTok == Token.opaque) {
translucency = setColorOptions(sbCommand, i + 1,
JmolConstants.SHAPE_ISOSURFACE, -2);
i = iToken;
continue;
}
switch (tokAt(i + 1)) {
case Token.absolute:
case Token.range:
getToken(++i);
sbCommand.append(" range");
addShapeProperty(propertyList, "rangeAll", null);
if (tokAt(i + 1) == Token.all) {
i++;
sbCommand.append(" all");
continue;
}
float min = floatParameter(++i);
float max = floatParameter(++i);
addShapeProperty(propertyList, "red", new Float(min));
addShapeProperty(propertyList, "blue", new Float(max));
sbCommand.append(" ").append(min).append(" ").append(max);
continue;
}
}
if (isColorParam(i + 1)) {
color = getArgbParam(++i);
addShapeProperty(propertyList, "colorRGB", new Integer(color));
sbCommand.append(" ").append(Escape.escapeColor(color));
i = iToken;
idSeen = true;
if (isColorParam(i + 1)) {
color = getArgbParam(++i);
i = iToken;
addShapeProperty(propertyList, "colorRGB", new Integer(color));
sbCommand.append(" ").append(Escape.escapeColor(color));
} else if (isSign) {
error(ERROR_invalidParameterOrder);
}
} else if (!isSign && discreteColixes == null) {
error(ERROR_invalidParameterOrder);
}
continue;
case Token.file:
continue;
case Token.ionic:
case Token.vanderwaals:
sbCommand.append(" ").append(theToken.value);
RadiusData rd = encodeRadiusParameter(i, false);
sbCommand.append(" ").append(rd);
if (Float.isNaN(rd.value))
rd.value = 100;
propertyValue = rd;
propertyName = "radius";
haveRadius = true;
if (isMapped)
surfaceObjectSeen = false;
i = iToken;
break;
case Token.plane:
// plane {X, Y, Z, W}
planeSeen = true;
propertyName = "plane";
propertyValue = planeParameter(++i);
i = iToken;
sbCommand.append(" plane ").append(
Escape.escape((Point4f) propertyValue));
break;
case Token.scale3d:
propertyName = "scale3d";
propertyValue = new Float(floatParameter(++i));
sbCommand.append(" scale3d ").append(propertyValue);
break;
case Token.scale:
propertyName = "scale";
propertyValue = new Float(floatParameter(++i));
sbCommand.append(" scale ").append(propertyValue);
break;
case Token.all:
if (idSeen)
error(ERROR_invalidArgument);
propertyName = "thisID";
break;
case Token.ellipsoid:
// ellipsoid {xc yc zc f} where a = b and f = a/c
// OR ellipsoid {u11 u22 u33 u12 u13 u23}
surfaceObjectSeen = true;
++i;
try {
propertyValue = getPoint4f(i);
propertyName = "ellipsoid";
i = iToken;
sbCommand.append(" ellipsoid ").append(
Escape.escape((Point4f) propertyValue));
break;
} catch (ScriptException e) {
}
try {
propertyName = "ellipsoid";
propertyValue = floatParameterSet(i, 6, 6);
i = iToken;
sbCommand.append(" ellipsoid ").append(
Escape.escape((float[]) propertyValue));
break;
} catch (ScriptException e) {
}
bs = atomExpression(i);
sbCommand.append(" ellipsoid ").append(Escape.escape(bs));
int iAtom = bs.nextSetBit(0);
Atom[] atoms = viewer.getModelSet().atoms;
if (iAtom >= 0)
propertyValue = atoms[iAtom].getEllipsoid();
if (propertyValue == null)
return;
i = iToken;
propertyName = "ellipsoid";
if (!isSyntaxCheck)
addShapeProperty(propertyList, "center", viewer.getAtomPoint3f(iAtom));
break;
case Token.hkl:
// miller indices hkl
planeSeen = true;
propertyName = "plane";
propertyValue = hklParameter(++i);
i = iToken;
sbCommand.append(" plane ").append(
Escape.escape((Point4f) propertyValue));
break;
case Token.lcaocartoon:
surfaceObjectSeen = true;
String lcaoType = parameterAsString(++i);
addShapeProperty(propertyList, "lcaoType", lcaoType);
sbCommand.append(" lcaocartoon ").append(Escape.escape(lcaoType));
switch (getToken(++i).tok) {
case Token.bitset:
case Token.expressionBegin:
propertyName = "lcaoCartoon";
bs = atomExpression(i);
sbCommand.append(" ").append(Escape.escape(bs));
i = iToken;
int atomIndex = bs.nextSetBit(0);
modelIndex = 0;
Point3f pt;
if (atomIndex < 0) {
if (!isSyntaxCheck)
error(ERROR_expressionExpected);
pt = new Point3f();
} else {
modelIndex = viewer.getAtomModelIndex(atomIndex);
pt = viewer.getAtomPoint3f(atomIndex);
}
addShapeProperty(propertyList, "modelIndex", new Integer(modelIndex));
Vector3f[] axes = { new Vector3f(), new Vector3f(), new Vector3f(pt),
new Vector3f() };
if (!isSyntaxCheck
&& !lcaoType.equalsIgnoreCase("s")
&& viewer.getHybridizationAndAxes(atomIndex, axes[0], axes[1],
lcaoType) == null)
return;
propertyValue = axes;
break;
default:
error(ERROR_expressionExpected);
}
break;
case Token.mo:
// mo 1-based-index
int moNumber = Integer.MAX_VALUE;
int offset = Integer.MAX_VALUE;
switch (tokAt(++i)) {
case Token.nada:
error(ERROR_badArgumentCount);
case Token.homo:
case Token.lumo:
offset = moOffset(i);
moNumber = 0;
i = iToken;
sbCommand.append(" mo HOMO ");
if (offset > 0)
sbCommand.append("+");
if (offset != 0)
sbCommand.append(offset);
break;
case Token.integer:
moNumber = intParameter(i);
sbCommand.append(" mo ").append(moNumber);
break;
}
setMoData(propertyList, moNumber, offset, modelIndex, null);
surfaceObjectSeen = true;
continue;
case Token.mep:
case Token.mlp:
boolean isMep = (theTok == Token.mep);
propertyName = (isMep ? "mep" : "mlp");
sbCommand.append(" " + propertyName);
String fname = null;
int calcType = -1;
surfaceObjectSeen = true;
if (tokAt(i + 1) == Token.integer) {
calcType = intParameter(++i);
sbCommand.append(" " + calcType);
addShapeProperty(propertyList, "mepCalcType", new Integer(calcType));
}
if (tokAt(i + 1) == Token.string) {
fname = stringParameter(++i);
sbCommand.append(" /*file*/" + Escape.escape(fname));
} else if (tokAt(i + 1) == Token.property) {
dataUse = propertyName;
continue;
}
if (!isSyntaxCheck)
try {
data = (fname == null && isMep ? viewer.getPartialCharges()
: viewer.getAtomicPotentials(isMep, bsSelect, bsIgnore, fname));
} catch (Exception e) {
// ignore
}
if (!isSyntaxCheck && data == null)
error(ERROR_noPartialCharges);
propertyValue = data;
break;
case Token.volume:
doCalcVolume = !isSyntaxCheck;
sbCommand.append(" volume");
break;
case Token.id:
setShapeId(iShape, ++i, idSeen);
isWild = (getShapeProperty(iShape, "ID") == null);
i = iToken;
break;
case Token.colorscheme:
// either order NOT OK -- documented for TRANSLUCENT "rwb"
if (tokAt(i + 1) == Token.translucent) {
isColorSchemeTranslucent = true;
i++;
}
colorScheme = parameterAsString(++i);
sbCommand.append(" colorScheme");
if (isColorSchemeTranslucent)
sbCommand.append(" translucent");
sbCommand.append(" ").append(Escape.escape(colorScheme));
break;
case Token.addhydrogens:
propertyName = "addHydrogens";
propertyValue = Boolean.TRUE;
sbCommand.append(" addHydrogens");
break;
case Token.angstroms:
propertyName = "angstroms";
sbCommand.append(" angstroms");
break;
case Token.anisotropy:
propertyName = "anisotropy";
propertyValue = getPoint3f(++i, false);
sbCommand.append(" anisotropy").append(
Escape.escape((Point3f) propertyValue));
i = iToken;
break;
case Token.area:
doCalcArea = !isSyntaxCheck;
sbCommand.append(" area");
break;
case Token.atomicorbital:
case Token.orbital:
surfaceObjectSeen = true;
nlmZ[0] = intParameter(++i);
nlmZ[1] = intParameter(++i);
nlmZ[2] = intParameter(++i);
nlmZ[3] = (isFloatParameter(i + 1) ? floatParameter(++i) : 6f);
sbCommand.append(" atomicOrbital ").append((int) nlmZ[0]).append(" ")
.append((int) nlmZ[1]).append(" ").append((int) nlmZ[2])
.append(" ").append(nlmZ[3]);
propertyName = "hydrogenOrbital";
propertyValue = nlmZ;
break;
case Token.binary:
sbCommand.append(" binary");
// for PMESH, specifically
// ignore for now
continue;
case Token.blockdata:
sbCommand.append(" blockData");
propertyName = "blockData";
propertyValue = Boolean.TRUE;
break;
case Token.cap:
case Token.slab:
propertyName = (String) theToken.value;
propertyValue = getCapSlabObject(sbCommand, i);
i = iToken;
break;
case Token.cavity:
if (!isIsosurface)
error(ERROR_invalidArgument);
isCavity = true;
if (isSyntaxCheck)
continue;
float cavityRadius = (isFloatParameter(i + 1) ? floatParameter(++i)
: 1.2f);
float envelopeRadius = (isFloatParameter(i + 1) ? floatParameter(++i)
: 10f);
if (envelopeRadius > 10f)
integerOutOfRange(0, 10);
sbCommand.append(" cavity ").append(cavityRadius).append(" ").append(
envelopeRadius);
addShapeProperty(propertyList, "envelopeRadius", new Float(
envelopeRadius));
addShapeProperty(propertyList, "cavityRadius", new Float(cavityRadius));
propertyName = "cavity";
break;
case Token.contour:
case Token.contours:
propertyName = "contour";
sbCommand.append(" contour");
switch (tokAt(i + 1)) {
case Token.discrete:
propertyValue = floatParameterSet(i + 2, 1, Integer.MAX_VALUE);
sbCommand.append(" discrete ").append(Escape.escape(propertyValue));
i = iToken;
break;
case Token.increment:
Point3f pt = getPoint3f(i + 2, false);
if (pt.z <= 0 || pt.y < pt.x)
error(ERROR_invalidArgument); // from to step
if (pt.z == (int) pt.z && pt.z > (pt.y - pt.x))
pt.z = (pt.y - pt.x) / pt.z;
propertyValue = pt;
i = iToken;
sbCommand.append(" increment ").append(Escape.escape(pt));
break;
default:
propertyValue = new Integer(
tokAt(i + 1) == Token.integer ? intParameter(++i) : 0);
sbCommand.append(" ").append(propertyValue);
}
break;
case Token.decimal:
case Token.integer:
case Token.plus:
case Token.cutoff:
sbCommand.append(" cutoff ");
if (theTok == Token.cutoff)
i++;
if (tokAt(i) == Token.plus) {
propertyName = "cutoffPositive";
propertyValue = new Float(cutoff = floatParameter(++i));
sbCommand.append("+").append(propertyValue);
} else {
propertyName = "cutoff";
propertyValue = new Float(cutoff = floatParameter(i));
sbCommand.append(propertyValue);
}
break;
case Token.downsample:
propertyName = "downsample";
propertyValue = new Integer(intParameter(++i));
sbCommand.append(" downsample ").append(propertyValue);
break;
case Token.eccentricity:
propertyName = "eccentricity";
propertyValue = getPoint4f(++i);
sbCommand.append(" eccentricity ").append(
Escape.escape((Point4f) propertyValue));
i = iToken;
break;
case Token.ed:
sbCommand.append(" ed");
// electron density - never documented
setMoData(propertyList, -1, 0, modelIndex, null);
surfaceObjectSeen = true;
continue;
case Token.debug:
case Token.nodebug:
sbCommand.append(" ").append(theToken.value);
propertyName = "debug";
propertyValue = (theTok == Token.debug ? Boolean.TRUE : Boolean.FALSE);
break;
case Token.fixed:
sbCommand.append(" fixed");
propertyName = "fixed";
propertyValue = Boolean.TRUE;
break;
case Token.fullplane:
sbCommand.append(" fullPlane");
propertyName = "fullPlane";
propertyValue = Boolean.TRUE;
break;
case Token.functionxy:
case Token.functionxyz:
boolean isFxyz = (theTok == Token.functionxyz);
propertyName = "" + theToken.value;
// isosurface functionXY "functionName"|"data2d_xxxxx"
// isosurface functionXYZ "functionName"|"data3d_xxxxx"
// {origin} {ni ix iy iz} {nj jx jy jz} {nk kx ky kz}
List vxy = new ArrayList();
i++;
String name = parameterAsString(i++);
// override of function or data name when saved as a state
String dName = extractCommandOption("# DATA" + (isFxy ? "2" : ""));
if (dName == null)
dName = "inline";
else
name = dName;
sbCommand.append(" ").append(propertyName).append(" inline");
boolean isXYZ = (name.indexOf("data2d_") == 0);
boolean isXYZV = (name.indexOf("data3d_") == 0);
boolean isInline = name.equals("inline");
vxy.add(name); // (0) = name
Point3f pt3 = getPoint3f(i, false);
sbCommand.append(" ").append(Escape.escape(pt3));
vxy.add(pt3); // (1) = {origin}
Point4f pt4;
ptX = ++iToken;
vxy.add(pt4 = getPoint4f(ptX)); // (2) = {ni ix iy iz}