From: <ha...@us...> - 2011-01-19 05:58:41
|
Revision: 14993 http://jmol.svn.sourceforge.net/jmol/?rev=14993&view=rev Author: hansonr Date: 2011-01-19 05:58:35 +0000 (Wed, 19 Jan 2011) Log Message: ----------- version=12.1.31_dev # bug fix: Jmol 12.9.24+ will read states created by prior versions incorrectly # -- fixed by adding "legacyAutoBonding" setting Modified Paths: -------------- trunk/Jmol/src/org/jmol/modelset/ModelCollection.java trunk/Jmol/src/org/jmol/modelset/ModelLoader.java trunk/Jmol/src/org/jmol/script/ScriptCompiler.java trunk/Jmol/src/org/jmol/script/Token.java trunk/Jmol/src/org/jmol/viewer/Jmol.properties trunk/Jmol/src/org/jmol/viewer/StateManager.java trunk/Jmol/src/org/jmol/viewer/Viewer.java Modified: trunk/Jmol/src/org/jmol/modelset/ModelCollection.java =================================================================== --- trunk/Jmol/src/org/jmol/modelset/ModelCollection.java 2011-01-19 05:57:19 UTC (rev 14992) +++ trunk/Jmol/src/org/jmol/modelset/ModelCollection.java 2011-01-19 05:58:35 UTC (rev 14993) @@ -49,6 +49,7 @@ import org.jmol.api.JmolMolecule; import org.jmol.api.SymmetryInterface; import org.jmol.bspt.Bspf; +import org.jmol.bspt.CubeIterator; import org.jmol.util.ArrayUtil; import org.jmol.util.BitSetUtil; import org.jmol.util.Escape; @@ -2472,7 +2473,12 @@ } public int autoBond(BitSet bsA, BitSet bsB, BitSet bsExclude, BitSet bsBonds, - short mad) { + short mad, boolean preJmol11_9_24) { + // unfortunately, 11.9.24 changed the order with which atoms were processed + // for autobonding. This means that state script prior to that that use + // select BOND will be misread by later version. + if (preJmol11_9_24) + return autoBond_Pre_11_9_24(bsA, bsB, bsExclude, bsBonds, mad); if (atomCount == 0) return 0; if (mad == 0) @@ -2562,6 +2568,92 @@ return nNew; } + private int autoBond_Pre_11_9_24(BitSet bsA, BitSet bsB, BitSet bsExclude, BitSet bsBonds, short mad) { + if (atomCount == 0) + return 0; + if (mad == 0) + mad = 1; + // null values for bitsets means "all" + if (maxBondingRadius == Float.MIN_VALUE) + findMaxRadii(); + float bondTolerance = viewer.getBondTolerance(); + float minBondDistance = viewer.getMinBondDistance(); + float minBondDistance2 = minBondDistance * minBondDistance; + int nNew = 0; + initializeBspf(); + if (showRebondTimes && Logger.debugging) + Logger.startTimer(); + /* + * miguel 2006 04 02 + * note that the way that these loops + iterators are constructed, + * everything assumes that all possible pairs of atoms are going to + * be looked at. + * for example, the hemisphere iterator will only look at atom indexes + * that are >= (or <= ?) the specified atom. + * if we are going to allow arbitrary sets bsA and bsB, then this will + * not work. + * so, for now I will do it the ugly way. + * maybe enhance/improve in the future. + */ + int lastModelIndex = -1; + for (int i = atomCount; --i >= 0;) { + boolean isAtomInSetA = (bsA == null || bsA.get(i)); + boolean isAtomInSetB = (bsB == null || bsB.get(i)); + if (!isAtomInSetA && !isAtomInSetB) + //|| bsExclude != null && bsExclude.get(i)) + continue; + Atom atom = atoms[i]; + if (atom.isDeleted()) + continue; + int modelIndex = atom.modelIndex; + //no connections allowed in a data frame + if (modelIndex != lastModelIndex) { + lastModelIndex = modelIndex; + if (isJmolDataFrame(modelIndex)) { + for (; --i >= 0;) + if (atoms[i].modelIndex != modelIndex) + break; + i++; + continue; + } + } + // Covalent bonds + float myBondingRadius = atom.getBondingRadiusFloat(); + if (myBondingRadius == 0) + continue; + float searchRadius = myBondingRadius + maxBondingRadius + bondTolerance; + initializeBspt(modelIndex); + CubeIterator iter = bspf.getCubeIterator(modelIndex); + iter.initialize(atom, searchRadius, true); + while (iter.hasMoreElements()) { + Atom atomNear = (Atom) iter.nextElement(); + if (atomNear == atom || atomNear.isDeleted()) + continue; + int atomIndexNear = atomNear.index; + boolean isNearInSetA = (bsA == null || bsA.get(atomIndexNear)); + boolean isNearInSetB = (bsB == null || bsB.get(atomIndexNear)); + if (!isNearInSetA && !isNearInSetB + || bsExclude != null && bsExclude.get(atomIndexNear) + && bsExclude.get(i) //this line forces BOTH to be excluded in order to ignore bonding + ) + continue; + if (!(isAtomInSetA && isNearInSetB || isAtomInSetB && isNearInSetA)) + continue; + short order = getBondOrder(myBondingRadius, atomNear + .getBondingRadiusFloat(), iter.foundDistance2(), minBondDistance2, + bondTolerance); + if (order > 0) { + if (checkValencesAndBond(atom, atomNear, order, mad, bsBonds)) + nNew++; + } + } + iter.release(); + } + if (showRebondTimes && Logger.debugging) + Logger.checkTimer("Time to autoBond"); + return nNew; + } + private int[] autoBond(BitSet bsA, BitSet bsB, BitSet bsBonds, boolean isBonds, boolean matchHbond) { if (isBonds) { @@ -2575,7 +2667,7 @@ } return new int[] { matchHbond ? autoHbond(bsA, bsB) - : autoBond(bsA, bsB, null, bsBonds, viewer.getMadBond()), 0 }; + : autoBond(bsA, bsB, null, bsBonds, viewer.getMadBond(), false), 0 }; } private static float hbondMin = 2.5f; Modified: trunk/Jmol/src/org/jmol/modelset/ModelLoader.java =================================================================== --- trunk/Jmol/src/org/jmol/modelset/ModelLoader.java 2011-01-19 05:57:19 UTC (rev 14992) +++ trunk/Jmol/src/org/jmol/modelset/ModelLoader.java 2011-01-19 05:58:35 UTC (rev 14993) @@ -1002,7 +1002,7 @@ } } if (autoBonding) { - autoBond(bs, bs, bsExclude, null, defaultCovalentMad); + autoBond(bs, bs, bsExclude, null, defaultCovalentMad, viewer.checkAutoBondLegacy()); Logger .info("ModelSet: autobonding; use autobond=false to not generate bonds automatically"); } else { Modified: trunk/Jmol/src/org/jmol/script/ScriptCompiler.java =================================================================== --- trunk/Jmol/src/org/jmol/script/ScriptCompiler.java 2011-01-19 05:57:19 UTC (rev 14992) +++ trunk/Jmol/src/org/jmol/script/ScriptCompiler.java 2011-01-19 05:58:35 UTC (rev 14993) @@ -268,7 +268,14 @@ htUserFunctions = new Hashtable<String, Boolean>(); script = script.replace('\u201C', '"').replace('\u201D', '"'); script = cleanScriptComments(script); - isStateScript = (script.indexOf(Viewer.STATE_VERSION_STAMP) >= 0); + ichToken = script.indexOf(Viewer.STATE_VERSION_STAMP); + isStateScript = (ichToken >= 0); + if (isStateScript) { + ptSemi = script.indexOf(";", ichToken); + if (ptSemi >= ichToken) + viewer.setStateScriptVersion(script.substring( + ichToken + Viewer.STATE_VERSION_STAMP.length(), ptSemi).trim()); + } cchScript = this.script.length(); // these four will be returned: Modified: trunk/Jmol/src/org/jmol/script/Token.java =================================================================== --- trunk/Jmol/src/org/jmol/script/Token.java 2011-01-19 05:57:19 UTC (rev 14992) +++ trunk/Jmol/src/org/jmol/script/Token.java 2011-01-19 05:58:35 UTC (rev 14993) @@ -942,6 +942,7 @@ public final static int isosurfacepropertysmoothing = booleanparam | 94; public final static int justifymeasurements = booleanparam | 96; public final static int languagetranslation = booleanparam | 97; + public final static int legacyautobonding = booleanparam | 98;// new public final static int logcommands = booleanparam | 99; public final static int loggestures = booleanparam | 100; public final static int measureallmodels = booleanparam | 101; @@ -2214,6 +2215,7 @@ "isosurfacePropertySmoothingPower", new Token(isosurfacepropertysmoothingpower), "justifyMeasurements", new Token(justifymeasurements), "languageTranslation", new Token(languagetranslation), + "legacyAutoBonding", new Token(legacyautobonding), "logCommands", new Token(logcommands), "logGestures", new Token(loggestures), "measureAllModels", new Token(measureallmodels), Modified: trunk/Jmol/src/org/jmol/viewer/Jmol.properties =================================================================== --- trunk/Jmol/src/org/jmol/viewer/Jmol.properties 2011-01-19 05:57:19 UTC (rev 14992) +++ trunk/Jmol/src/org/jmol/viewer/Jmol.properties 2011-01-19 05:58:35 UTC (rev 14993) @@ -3,6 +3,8 @@ version=12.1.31_dev +# bug fix: Jmol 12.9.24+ will read states created by prior versions incorrectly +# -- fixed by adding "legacyAutoBonding" setting # new feature: load FILTER "*.CA,/=5" # -- every 5th alpha carbon # -- note comma before /= Modified: trunk/Jmol/src/org/jmol/viewer/StateManager.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/StateManager.java 2011-01-19 05:57:19 UTC (rev 14992) +++ trunk/Jmol/src/org/jmol/viewer/StateManager.java 2011-01-19 05:58:35 UTC (rev 14993) @@ -580,7 +580,8 @@ + ";axesposition;axesmolecular;axesorientationrasmol;axesunitcell;axeswindow;axis1color;axis2color" + ";axis3color;backgroundcolor;backgroundmodel;bondsymmetryatoms;boundboxcolor;cameradepth" + ";debug;debugscript;defaultlatttice;defaults;diffusepercent;exportdrivers" - + ";_filecaching;_filecache;fontcaching;fontscaling;language;" + + ";_filecaching;_filecache;fontcaching;fontscaling;language" + + ";legacyautobonding" + ";loglevel;logfile;loggestures;logcommands;measureStyleChime" + ";loadformat;smilesurlformat;edsurlformat;edsurlcutoff;multiprocessor;navigationmode;" + ";perspectivedepth;phongexponent;perspectivemodel;preservestate;refreshing;repaintwaitms;rotationradius" @@ -696,6 +697,7 @@ allowModelkit = g.allowModelkit; allowMultiTouch = g.allowMultiTouch; allowKeyStrokes = g.allowKeyStrokes; + legacyAutoBonding = g.legacyAutoBonding; useScriptQueue = g.useScriptQueue; useArcBall = g.useArcBall; } @@ -882,6 +884,7 @@ setParameterValue("isosurfacePropertySmoothingPower", isosurfacePropertySmoothingPower); setParameterValue("justifyMeasurements", justifyMeasurements); + setParameterValue("legacyAutoBonding", legacyAutoBonding); setParameterValue("loadAtomDataTolerance", loadAtomDataTolerance); setParameterValue("loadFormat", loadFormat); setParameterValue("logCommands", logCommands); @@ -1028,6 +1031,7 @@ int smallMoleculeMaxAtoms = 40000; boolean smartAromatic = true; boolean zeroBasedXyzRasmol = false; + boolean legacyAutoBonding = false; /** * these settings are determined when the file is loaded and are @@ -1076,6 +1080,7 @@ appendCmd(str, "#set edsUrlCutoff " + Escape.escape(edsUrlCutoff)); // if (autoLoadOrientation) // appendCmd(str, "set autoLoadOrientation true"); + appendCmd(str, "set legacyAutoBonding " + legacyAutoBonding); appendCmd(str, "set minBondDistance " + minBondDistance); // these next two might be part of a 2D->3D operation appendCmd(str, "set minimizationCriterion " + minimizationCriterion); Modified: trunk/Jmol/src/org/jmol/viewer/Viewer.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/Viewer.java 2011-01-19 05:57:19 UTC (rev 14992) +++ trunk/Jmol/src/org/jmol/viewer/Viewer.java 2011-01-19 05:58:35 UTC (rev 14993) @@ -4344,6 +4344,7 @@ scriptStatus("Jmol script terminated", strErrorMessage, 1, strErrorMessageUntranslated); } + setStateScriptVersion(null); // set by compiler if (strErrorMessage != null && autoExit) exitJmol(); if (isCmdLine_c_or_C_Option) { @@ -5765,7 +5766,7 @@ } setIntProperty(key, Token.getTokFromName(key.toLowerCase()), value); } - + public void setIntProperty(String key, int tok, int value) { boolean found = true; switch (tok) { @@ -5937,6 +5938,9 @@ boolean found = true; boolean doRepaint = true; switch (tok) { + case Token.legacyautobonding: + global.legacyAutoBonding = value; + break; case Token.defaultstructuredssp: global.defaultStructureDSSP = value; break; @@ -6931,7 +6935,7 @@ // Eval, PreferencesDialog clearModelDependentObjects(); modelSet.deleteAllBonds(); - modelSet.autoBond(null, null, null, null, getMadBond()); + modelSet.autoBond(null, null, null, null, getMadBond(), false); addStateScript("connect;", false, true); } @@ -6942,7 +6946,7 @@ BitSet bsExclude = new BitSet(); modelSet.setPdbConectBonding(0, 0, bsExclude); if (isAuto) { - modelSet.autoBond(null, null, bsExclude, null, getMadBond()); + modelSet.autoBond(null, null, bsExclude, null, getMadBond(), false); addStateScript("connect PDB AUTO;", false, true); return; } @@ -9516,4 +9520,36 @@ return modelSet.getModelAtomProperty(atom, text); } + private int stateScriptVersionInt; + + public void setStateScriptVersion(String version) { + if (version != null) { + try { + String[] tokens = Parser.getTokens(version.replace('.', ' ').replace( + '_', ' ')); + int main = Integer.valueOf(tokens[0]).intValue(); //11 + int sub = Integer.valueOf(tokens[1]).intValue(); //9 + int minor = Integer.valueOf(tokens[2]).intValue(); //24 + stateScriptVersionInt = main * 10000 + sub * 100 + minor; + // here's why: + global.legacyAutoBonding = (stateScriptVersionInt < 110924); + + return; + } catch (Exception e) { + // + } + } + global.legacyAutoBonding = false; + stateScriptVersionInt = Integer.MAX_VALUE; + } + + public boolean checkAutoBondLegacy() { + // aargh -- BitSet efficiencies in Jmol 11.9.24, 2/3/2010, meant that + // state files created before that that use select BONDS will select the + // wrong bonds. + return global.legacyAutoBonding; + // reset after a state script is read + } + + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |