From: <ha...@us...> - 2009-05-22 18:57:06
|
Revision: 10892 http://jmol.svn.sourceforge.net/jmol/?rev=10892&view=rev Author: hansonr Date: 2009-05-22 18:56:13 +0000 (Fri, 22 May 2009) Log Message: ----------- 11.7.37 VERSION # new feature: load VIBRATION "filename" n ....... # --all features of the load command, but only loads the vibrational information # --applies {within(loadAtomDataTolerance,xyzcoord)}.vxyz = vibcoord, so to all unit cells # --optional n is just as for any load -- optional nth model # --operates on previously selected atoms only # --allows embedded jmolscript, just as for any load # --sets _vibrationName from file's atom set collection name # new feature: loadAtomDataTolerance (see above) Modified Paths: -------------- trunk/Jmol/src/org/jmol/modelset/Atom.java trunk/Jmol/src/org/jmol/modelset/AtomCollection.java trunk/Jmol/src/org/jmol/modelset/ModelCollection.java trunk/Jmol/src/org/jmol/modelset/ModelLoader.java trunk/Jmol/src/org/jmol/viewer/Compiler.java trunk/Jmol/src/org/jmol/viewer/Eval.java trunk/Jmol/src/org/jmol/viewer/FileManager.java trunk/Jmol/src/org/jmol/viewer/Jmol.properties trunk/Jmol/src/org/jmol/viewer/ModelManager.java trunk/Jmol/src/org/jmol/viewer/SelectionManager.java trunk/Jmol/src/org/jmol/viewer/StateManager.java trunk/Jmol/src/org/jmol/viewer/Token.java trunk/Jmol/src/org/jmol/viewer/Viewer.java Modified: trunk/Jmol/src/org/jmol/modelset/Atom.java =================================================================== --- trunk/Jmol/src/org/jmol/modelset/Atom.java 2009-05-21 22:29:27 UTC (rev 10891) +++ trunk/Jmol/src/org/jmol/modelset/Atom.java 2009-05-22 18:56:13 UTC (rev 10892) @@ -651,6 +651,17 @@ return pt; } + public float getFractionalUnitDistance(Point3f pt, Point3f ptTemp1, Point3f ptTemp2) { + SymmetryInterface[] c = group.chain.modelSet.unitCells; + if (c == null) + return distance(pt); + ptTemp1.set(this); + c[modelIndex].toUnitCell(ptTemp1, null); + ptTemp2.set(pt); + c[modelIndex].toUnitCell(ptTemp2, null); + return ptTemp1.distance(ptTemp2); + } + void setFractionalCoord(int tok, float fValue) { SymmetryInterface[] c = group.chain.modelSet.unitCells; if (c != null) Modified: trunk/Jmol/src/org/jmol/modelset/AtomCollection.java =================================================================== --- trunk/Jmol/src/org/jmol/modelset/AtomCollection.java 2009-05-21 22:29:27 UTC (rev 10891) +++ trunk/Jmol/src/org/jmol/modelset/AtomCollection.java 2009-05-22 18:56:13 UTC (rev 10892) @@ -572,7 +572,8 @@ } public Vector3f getVibrationVector(int atomIndex) { - return vibrationVectors == null ? null : vibrationVectors[atomIndex]; + Vector3f v = (vibrationVectors == null ? null : vibrationVectors[atomIndex]); + return (v == null ? new Vector3f() : v); } protected void setVibrationVector(int atomIndex, float x, float y, float z) { Modified: trunk/Jmol/src/org/jmol/modelset/ModelCollection.java =================================================================== --- trunk/Jmol/src/org/jmol/modelset/ModelCollection.java 2009-05-21 22:29:27 UTC (rev 10891) +++ trunk/Jmol/src/org/jmol/modelset/ModelCollection.java 2009-05-22 18:56:13 UTC (rev 10892) @@ -1703,7 +1703,8 @@ public void setAtomCoord(BitSet bs, int tokType, Object xyzValues) { super.setAtomCoord(bs, tokType, xyzValues); - recalculateLeadMidpointsAndWingVectors(-1); + if ((tokType & Token.vibflag) == 0) + recalculateLeadMidpointsAndWingVectors(-1); } public int getAtomCountInModel(int modelIndex) { @@ -1869,17 +1870,22 @@ return bsResult; } - public BitSet getAtomsWithin(float distance, Point3f coord, BitSet bsResult, int modelIndex) { + public BitSet getAtomsWithin(float distance, Point3f coord, BitSet bsResult, + int modelIndex) { - if (bsResult == null) bsResult = new BitSet(); - + if (bsResult == null) + bsResult = new BitSet(); + if (distance < 0) { // just check all unitCell distances distance = -distance; + final Point3f ptTemp1 = new Point3f(); + final Point3f ptTemp2 = new Point3f(); for (int i = atomCount; --i >= 0;) { Atom atom = atoms[i]; if (modelIndex >= 0 && atoms[i].modelIndex != modelIndex) continue; - if (!bsResult.get(i) && atom.getFractionalUnitCoord(true).distance(coord) <= distance) + if (!bsResult.get(i) + && atom.getFractionalUnitDistance(coord, ptTemp1, ptTemp2) <= distance) bsResult.set(atom.atomIndex); } return bsResult; @@ -1898,10 +1904,17 @@ && iterWithin.foundDistance2() <= d2) bsResult.set(iAtom); } - //System.out.println("modelCollection iter distance " + (System.currentTimeMillis() - timeBegin)); + // System.out.println("modelCollection iter distance " + + // (System.currentTimeMillis() - timeBegin)); return bsResult; } + protected void setVibration(BitSet bsSelected, Point3f pt, Point3f v, float tolerance) { + BitSet bs = getAtomsWithin(-tolerance, pt, null, -1); + bs.and(bsSelected); + setAtomCoord(bs,Token.vibXyz, v); + } + public BitSet getSequenceBits(String specInfo, BitSet bs) { //Logger.debug("withinSequence"); String sequence = ""; Modified: trunk/Jmol/src/org/jmol/modelset/ModelLoader.java =================================================================== --- trunk/Jmol/src/org/jmol/modelset/ModelLoader.java 2009-05-21 22:29:27 UTC (rev 10891) +++ trunk/Jmol/src/org/jmol/modelset/ModelLoader.java 2009-05-22 18:56:13 UTC (rev 10892) @@ -1161,4 +1161,30 @@ loadShape(JmolConstants.SHAPE_BBCAGE); loadShape(JmolConstants.SHAPE_UCCAGE); } + + public void createVibrationSet(Object atomSetCollection, BitSet bsSelected) { + if (atomSetCollection == null) + return; + JmolAdapter adapter = viewer.getModelAdapter(); + Point3f pt = new Point3f(); + Point3f v = new Point3f(); + float tol = ((Float) viewer.getParameter("loadAtomDataTolerance")).floatValue(); + for (JmolAdapter.AtomIterator iterAtom = adapter + .getAtomIterator(atomSetCollection); iterAtom.hasNext();) { + float x = iterAtom.getX(); + float y = iterAtom.getY(); + float z = iterAtom.getZ(); + float vx = iterAtom.getVectorX(); + float vy = iterAtom.getVectorY(); + float vz = iterAtom.getVectorZ(); + if (Float.isNaN(x + y + z + vx + vy + vz)) + continue; + pt.set(x, y, z); + v.set(vx, vy, vz); + if (Logger.debugging) + Logger.info("xyz: " + pt + " vib: " + v); + setVibration(bsSelected, pt, v, tol); + } + viewer.setStringProperty("_vibrationName", adapter.getAtomSetName(atomSetCollection, 0)); + } } Modified: trunk/Jmol/src/org/jmol/viewer/Compiler.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/Compiler.java 2009-05-21 22:29:27 UTC (rev 10891) +++ trunk/Jmol/src/org/jmol/viewer/Compiler.java 2009-05-22 18:56:13 UTC (rev 10892) @@ -492,7 +492,7 @@ String strFormat = script.substring(ichToken, ichToken + cchToken); strFormat = strFormat.toLowerCase(); if (Parser - .isOneOf(strFormat, "append;files;menu;trajectory;models")) + .isOneOf(strFormat, "append;vibration;files;menu;trajectory;models")) addTokenToPrefix(new Token(Token.identifier, strFormat)); else if (strFormat.indexOf("=") == 0) { addTokenToPrefix(new Token(Token.string, strFormat)); Modified: trunk/Jmol/src/org/jmol/viewer/Eval.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/Eval.java 2009-05-21 22:29:27 UTC (rev 10891) +++ trunk/Jmol/src/org/jmol/viewer/Eval.java 2009-05-22 18:56:13 UTC (rev 10892) @@ -4295,6 +4295,7 @@ int modelCount = viewer.getModelCount() - (viewer.getFileName().equals("zapped") ? 1 : 0); boolean appendNew = viewer.getAppendNew(); + boolean vibrationOnly = false; StringBuffer loadScript = new StringBuffer("load"); int nFiles = 1; Hashtable htParams = new Hashtable(); @@ -4318,8 +4319,13 @@ i = 2; loadScript.append(" " + modelName); isAppend = (modelName.equalsIgnoreCase("append")); - if (isAppend - && ((filename = optParameterAsString(2)) + vibrationOnly = (modelName.equalsIgnoreCase("vibration")); + if (vibrationOnly) { + htParams.put("vibrationOnly",Boolean.TRUE); + htParams.put("modelNumber", new Integer(1)); + isAppend = true; + } + if (isAppend && ((filename = optParameterAsString(2)) .equalsIgnoreCase("trajectory") || filename .equalsIgnoreCase("models"))) { modelName = filename; @@ -4398,12 +4404,14 @@ lattice = getPoint3f(i, false); i = iToken + 1; tok = tokAt(i); + sOptions += " " + Escape.escape(lattice); } if (tok == Token.identifier && parameterAsString(i).equalsIgnoreCase("packed")) { if (lattice == null) lattice = new Point3f(555,555,-1); htParams.put("packed", Boolean.TRUE); + sOptions += " PACKED"; } if (lattice != null) { i = iToken + 1; @@ -4543,10 +4551,15 @@ viewer.deallocateReaderThreads(); return; } - viewer.addLoadScript(loadScript.toString()); - String errMsg = viewer.createModelSetAndReturnError(isAppend); - // int millis = (int)(System.currentTimeMillis() - timeBegin); - // Logger.debug("!!!!!!!!! took " + millis + " ms"); + String errMsg = null; + if (vibrationOnly) { + errMsg = viewer.addVibrationDataAndReturnError(); + } else { + viewer.addLoadScript(loadScript.toString()); + errMsg = viewer.createModelSetAndReturnError(isAppend); + // int millis = (int)(System.currentTimeMillis() - timeBegin); + // Logger.debug("!!!!!!!!! took " + millis + " ms"); + } if (errMsg != null && !isScriptCheck) { if (errMsg.indexOf("file recognized as a script file:") >= 0) { viewer.addLoadScript("-"); @@ -7945,7 +7958,8 @@ float[] data = (tok == Token.property ? viewer .getDataFloat((String) opValue) : null); int count = 0; - + boolean isPt = (tok == Token.xyz || tok == Token.vibXyz || tok == Token.fracXyz + || tok == Token.unitXyz || tok == Token.color); if (isAtoms || ptAtom >= 0) { int iModel = -1; int nOps = 0; @@ -8215,7 +8229,7 @@ isInt = false; } } - if (tok == Token.xyz || tok == Token.fracXyz || tok == Token.unitXyz || tok == Token.color) + if (isPt) return (n == 0 ? pt : new Point3f(pt.x / n, pt.y / n, pt.z / n)); if (n == 0) return new Float(Float.NaN); Modified: trunk/Jmol/src/org/jmol/viewer/FileManager.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/FileManager.java 2009-05-21 22:29:27 UTC (rev 10891) +++ trunk/Jmol/src/org/jmol/viewer/FileManager.java 2009-05-22 18:56:13 UTC (rev 10892) @@ -180,7 +180,8 @@ */ void createAtomSetCollectionFromFile(String name, Hashtable htParams, String loadScript, boolean isAppend) { - setLoadScript(loadScript, isAppend); + if (htParams.get("vibrationOnly") == null) + setLoadScript(loadScript, isAppend); int pt = name.indexOf("::"); nameAsGiven = (pt >= 0 ? name.substring(pt + 2) : name); fileType = (pt >= 0 ? name.substring(0, pt) : null); Modified: trunk/Jmol/src/org/jmol/viewer/Jmol.properties =================================================================== --- trunk/Jmol/src/org/jmol/viewer/Jmol.properties 2009-05-21 22:29:27 UTC (rev 10891) +++ trunk/Jmol/src/org/jmol/viewer/Jmol.properties 2009-05-22 18:56:13 UTC (rev 10892) @@ -1,8 +1,17 @@ # Developers: to add a description of changes you have made, # add it on a line starting with # below the "version=..." line -version=11.7.37_dev +version=11.7.37 +# new feature: load VIBRATION "filename" n ....... +# --all features of the load command, but only loads the vibrational information +# --applies {within(loadAtomDataTolerance,xyzcoord)}.vxyz = vibcoord, so to all unit cells +# --optional n is just as for any load -- optional nth model +# --operates on previously selected atoms only +# --allows embedded jmolscript, just as for any load +# --sets _vibrationName from file's atom set collection name +# new feature: loadAtomDataTolerance (see above) +# bug fix: load {n n n} not saved in state # new feature: load {a b -c} packs a x b x c cells # new feature: select within(-0.1, {1/2 1/2 1/2}) -- negative distance within selects atoms based on unitcell coordinates # new feature: select within(-0.1, atomno=3) -- negative distance within selects atoms based on unitcell coordinates of all atoms involved Modified: trunk/Jmol/src/org/jmol/viewer/ModelManager.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/ModelManager.java 2009-05-21 22:29:27 UTC (rev 10891) +++ trunk/Jmol/src/org/jmol/viewer/ModelManager.java 2009-05-22 18:56:13 UTC (rev 10892) @@ -109,5 +109,4 @@ return fileName; } - } Modified: trunk/Jmol/src/org/jmol/viewer/SelectionManager.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/SelectionManager.java 2009-05-21 22:29:27 UTC (rev 10891) +++ trunk/Jmol/src/org/jmol/viewer/SelectionManager.java 2009-05-22 18:56:13 UTC (rev 10892) @@ -110,7 +110,7 @@ } boolean isSelected(int atomIndex) { - return bsSelection.get(atomIndex); + return (atomIndex >= 0 && bsSelection.get(atomIndex)); } void select(BitSet bs, boolean isQuiet) { Modified: trunk/Jmol/src/org/jmol/viewer/StateManager.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/StateManager.java 2009-05-21 22:29:27 UTC (rev 10891) +++ trunk/Jmol/src/org/jmol/viewer/StateManager.java 2009-05-22 18:56:13 UTC (rev 10892) @@ -705,6 +705,7 @@ boolean fontCaching = true; boolean hideNameInPopup = false; int hoverDelayMs = 500; + float loadAtomDataTolerance = 0.2f; boolean measurementLabels = true; boolean messageStyleChime = false; int pickingSpinRate = 10; @@ -1220,6 +1221,7 @@ setParameterValue("isosurfacePropertySmoothing", isosurfacePropertySmoothing); setParameterValue("justifyMeasurements", justifyMeasurements); + setParameterValue("loadAtomDataTolerance", loadAtomDataTolerance); setParameterValue("loadFormat", loadFormat); setParameterValue("measureAllModels", measureAllModels); setParameterValue("measurementLabels", measurementLabels = true); Modified: trunk/Jmol/src/org/jmol/viewer/Token.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/Token.java 2009-05-21 22:29:27 UTC (rev 10891) +++ trunk/Jmol/src/org/jmol/viewer/Token.java 2009-05-22 18:56:13 UTC (rev 10892) @@ -145,7 +145,7 @@ * xx atomproperty * xxx mathproperty * x x mathfunc - * xxxxx unique id + * xxxxx unique id 1 to 0x1F (31) * xx minmaxmask (all) * x min * x max @@ -455,6 +455,8 @@ // ___.xxx math properties and all atom properties + final public static int vibflag = 0x10; + final public static int atoms = 1 | mathproperty; final public static int bonds = 2 | mathproperty | setparam; final public static int color = 3 | mathproperty | command | setparam | settable; @@ -463,10 +465,10 @@ final static int lines = 6 | mathproperty; final static int size = 7 | mathproperty; final public static int type = 8 | mathproperty; - final public static int xyz = 9 | mathproperty | settable; - final public static int fracXyz =10 | mathproperty | settable; - final public static int vibXyz =11 | mathproperty | settable; - final public static int unitXyz =12 | mathproperty | settable; + final public static int xyz = 1 | mathproperty | settable; + final public static int fracXyz = 2 | mathproperty | settable; + final public static int unitXyz = 3 | mathproperty | settable; + final public static int vibXyz = 4 | mathproperty | settable | vibflag; final static int property =13 | mathproperty | setparam | settable; final public static int boundbox =14 | mathproperty | setparam | command | defaultON; final public static int adpmax =15 | mathproperty; @@ -507,12 +509,12 @@ final public static int straightness = atomproperty | comparefloatx100 | 9; final static int surfacedistance = atomproperty | comparefloatx100 |10; final public static int temperature = atomproperty | comparefloatx100 |11 | settable; - final public static int vibX = atomproperty | comparefloatx100 |12 | settable; - final public static int vibY = atomproperty | comparefloatx100 |13 | settable; - final public static int vibZ = atomproperty | comparefloatx100 |14 | settable; final public static int unitX = atomproperty | comparefloatx100 |15; final public static int unitY = atomproperty | comparefloatx100 |16; final public static int unitZ = atomproperty | comparefloatx100 |17; + final public static int vibX = atomproperty | comparefloatx100 |1 | settable | vibflag; + final public static int vibY = atomproperty | comparefloatx100 |2 | settable | vibflag; + final public static int vibZ = atomproperty | comparefloatx100 |3 | settable | vibflag; // mathfunc means x = somefunc(a,b,c) Modified: trunk/Jmol/src/org/jmol/viewer/Viewer.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/Viewer.java 2009-05-21 22:29:27 UTC (rev 10891) +++ trunk/Jmol/src/org/jmol/viewer/Viewer.java 2009-05-22 18:56:13 UTC (rev 10892) @@ -30,6 +30,7 @@ import org.jmol.modelset.AtomIndexIterator; import org.jmol.modelset.BoxInfo; import org.jmol.modelset.MeasurementPending; +import org.jmol.modelset.ModelLoader; import org.jmol.modelset.ModelSet; import org.jmol.adapter.smarter.SmarterJmolAdapter; @@ -1841,6 +1842,37 @@ return errMsg; } + String addVibrationDataAndReturnError() { + Object atomSetCollection = fileManager.getAtomSetCollectionOrError(); + fileManager.deallocateReaderThreads(); + String errMsg; + if (atomSetCollection instanceof String || atomSetCollection == null) { + errMsg = (String) atomSetCollection; + } else { + errMsg = createVibrationSet(atomSetCollection); + } + return errMsg; + } + + private String createVibrationSet(Object atomSetCollection) { + // maybe there needs to be a call to clear() + // or something like that here + // for when CdkEditBus calls this directly + // null fullPathName implies we are doing a merge + setErrorMessage(null); + try { + ((ModelLoader) modelSet).createVibrationSet(atomSetCollection, selectionManager.bsSelection); + setStatusFrameChanged(Integer.MIN_VALUE); + } catch (Error er) { + handleError(er, true); + String errMsg = getShapeErrorState(); + errMsg = ("ERROR adding vibrations: " + er + (errMsg.length() == 0 ? "" : "|" + errMsg)); + zap(errMsg); + setErrorMessage(errMsg); + } + return getErrorMessage(); + } + void deallocateReaderThreads() { fileManager.deallocateReaderThreads(); } @@ -2353,8 +2385,7 @@ } public boolean modelHasVibrationVectors(int modelIndex) { - return modelSetHasVibrationVectors() - && modelSet.modelHasVibrationVectors(modelIndex); + return modelSet.modelHasVibrationVectors(modelIndex); } public int getChainCount() { @@ -4128,8 +4159,13 @@ int prevFrame = Integer.MIN_VALUE; void setStatusFrameChanged(int frameNo) { + int modelIndex = repaintManager.currentModelIndex; + if (frameNo == Integer.MIN_VALUE) { + // force reset (reading vibrations) + prevFrame = Integer.MIN_VALUE; + frameNo = modelIndex; + } transformManager.setVibrationPeriod(Float.NaN); - int modelIndex = repaintManager.currentModelIndex; int firstIndex = repaintManager.firstModelIndex; int lastIndex = repaintManager.lastModelIndex; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |