From: <ha...@us...> - 2010-05-27 15:37:19
|
Revision: 13234 http://jmol.svn.sourceforge.net/jmol/?rev=13234&view=rev Author: hansonr Date: 2010-05-27 15:37:12 +0000 (Thu, 27 May 2010) Log Message: ----------- Modified Paths: -------------- trunk/Jmol/src/org/jmol/minimize/Minimizer.java trunk/Jmol/src/org/jmol/minimize/forcefield/ForceField.java trunk/Jmol/src/org/jmol/modelkit/modelKitPopupResourceBundle.java trunk/Jmol/src/org/jmol/modelset/ModelCollection.java trunk/Jmol/src/org/jmol/viewer/ActionManager.java trunk/Jmol/src/org/jmol/viewer/MouseManager14.java trunk/Jmol/src/org/jmol/viewer/Viewer.java Modified: trunk/Jmol/src/org/jmol/minimize/Minimizer.java =================================================================== --- trunk/Jmol/src/org/jmol/minimize/Minimizer.java 2010-05-27 13:34:22 UTC (rev 13233) +++ trunk/Jmol/src/org/jmol/minimize/Minimizer.java 2010-05-27 15:37:12 UTC (rev 13234) @@ -69,16 +69,17 @@ private String ff = "UFF"; private BitSet bsTaint, bsSelected, bsAtoms; private BitSet bsFixed; + private BitSet bsAromatic; public Vector constraints; private boolean isSilent; public Minimizer() { + System.out.println("minimi"); } public void setProperty(String propertyName, Object value) { - //System.out.println("minimizer: set " + propertyName + " = " + value); if (propertyName.equals("cancel")) { stopMinimization(false); return; @@ -149,6 +150,7 @@ setMinimizationOn(false); atomCount = 0; bondCount = 0; + bsAromatic = null; atoms = null; minAtoms = null; minBonds = null; @@ -201,13 +203,21 @@ atoms = viewer.getModelSet().atoms; } bsAtoms = BitSetUtil.copy(bsSelected); + if (bsFixed != null) + bsAtoms.or(bsFixed); atomCount = BitSetUtil.cardinalityOf(bsAtoms); if (atomCount == 0) { Logger.error(GT._("No atoms selected -- nothing to do!")); return false; } - if ((!BitSetUtil.areEqual(bsSelected, this.bsSelected) + boolean sameAtoms = BitSetUtil.areEqual(bsSelected, this.bsSelected); + System.out.println(sameAtoms); + System.out.println(Escape.escape(bsSelected) + "\n" + Escape.escape(this.bsSelected)); + this.bsSelected = bsSelected; + if (!sameAtoms) + bsAromatic = null; + if ((!sameAtoms || !BitSetUtil.areEqual(bsFixed, this.bsFixed)) && !setupMinimization()) { clear(); @@ -221,7 +231,6 @@ if (bsFixed != null) this.bsFixed = bsFixed; setAtomPositions(); - this.bsSelected = bsSelected; if (constraints != null) { for (int i = constraints.size(); --i >= 0;) { @@ -256,6 +265,7 @@ // add all atoms + coordSaved = null; atomMap = new int[atomCountFull]; minAtoms = new MinAtom[atomCount]; int elemnoMax = 0; @@ -382,13 +392,13 @@ //////////////// atom type support ////////////////// - final static int TOKEN_ELEMENT_ONLY = 0; - final static int TOKEN_ELEMENT_CHARGED = 1; - final static int TOKEN_ELEMENT_CONNECTED = 2; - final static int TOKEN_ELEMENT_AROMATIC = 3; - final static int TOKEN_ELEMENT_SP = 4; - final static int TOKEN_ELEMENT_SP2 = 5; - final static int TOKEN_ELEMENT_ALLYLIC = 6; + private final static int TOKEN_ELEMENT_ONLY = 0; + private final static int TOKEN_ELEMENT_CHARGED = 1; + private final static int TOKEN_ELEMENT_CONNECTED = 2; + private final static int TOKEN_AROMATIC = 3; + private final static int TOKEN_ELEMENT_SP = 4; + private final static int TOKEN_ELEMENT_SP2 = 5; + private final static int TOKEN_ELEMENT_ALLYLIC = 6; /* Token[keyword(0x80064) value="expressionBegin"] @@ -401,11 +411,11 @@ Token[keyword(0x880001) value=")"] */ - final static int PT_ELEMENT = 2; - final static int PT_CHARGE = 5; - final static int PT_CONNECT = 6; + private final static int PT_ELEMENT = 2; + private final static int PT_CHARGE = 5; + private final static int PT_CONNECT = 6; - final static Token[][] tokenTypes = new Token[][] { + private final static Token[][] tokenTypes = new Token[][] { /*0*/ new Token[]{ Token.tokenExpressionBegin, new Token(Token.opEQ, Token.elemno), @@ -429,11 +439,8 @@ Token.intToken(0), // 6 Token.tokenRightParen, Token.tokenExpressionEnd}, - /*3*/ new Token[]{ + /*3*/ new Token[]{ // not used this way Token.tokenExpressionBegin, - new Token(Token.opEQ, Token.elemno), - Token.intToken(0), //2 - Token.tokenAnd, new Token(Token.identifier, "flatring"), Token.tokenExpressionEnd}, /*4*/ new Token[]{ //sp == connected(1,"triple") or connected(2, "double") @@ -525,13 +532,14 @@ int elemNo = 0; if (n >= 10) n = 0; + boolean isAromatic = false; if (smarts.charAt(1) == '#') { elemNo = Parser.parseInt(smarts.substring(2, len - 1)); } else { String s = smarts.substring(1, (n > 0 ? len - 3 : len - 1)); if (s.equals(s.toLowerCase())) { s = s.toUpperCase(); - search = tokenTypes[TOKEN_ELEMENT_AROMATIC]; + isAromatic = true; } elemNo = Elements.elementNumberFromSymbol(s, false); } @@ -565,7 +573,15 @@ Object v = viewer.evaluateExpression(search); if (Logger.debugging && !v.toString().equals("{}")) Logger.debug(smarts + " minimize atoms=" + v.toString()); - return (v instanceof BitSet ? (BitSet) v : null); + if (!(v instanceof BitSet)) + return null; + BitSet bs = (BitSet) v; + if (isAromatic && bs.cardinality() > 0) { + if (bsAromatic == null) + bsAromatic = (BitSet) viewer.evaluateExpression(tokenTypes[TOKEN_AROMATIC]); + bs.and(bsAromatic); + } + return bs; } public void getAngles() { @@ -708,7 +724,7 @@ } public boolean startMinimization() { - try { + try { Logger.info("minimizer: startMinimization"); viewer.setIntProperty("_minimizationStep", 0); viewer.setStringProperty("_minimizationStatus", "starting"); @@ -837,7 +853,7 @@ } while (minimizationOn && !isInterrupted()); } catch (Exception e) { if (minimizationOn) - Logger.debug(" minimization thread interrupted"); + Logger.error(e.getMessage()); } } } Modified: trunk/Jmol/src/org/jmol/minimize/forcefield/ForceField.java =================================================================== --- trunk/Jmol/src/org/jmol/minimize/forcefield/ForceField.java 2010-05-27 13:34:22 UTC (rev 13233) +++ trunk/Jmol/src/org/jmol/minimize/forcefield/ForceField.java 2010-05-27 15:37:12 UTC (rev 13234) @@ -92,6 +92,7 @@ public void setConstraints(Minimizer m) { this.bsFixed = m.bsMinFixed; calc.setConstraints(m.constraints); + coordSaved = null; } public boolean setup() { Modified: trunk/Jmol/src/org/jmol/modelkit/modelKitPopupResourceBundle.java =================================================================== --- trunk/Jmol/src/org/jmol/modelkit/modelKitPopupResourceBundle.java 2010-05-27 13:34:22 UTC (rev 13233) +++ trunk/Jmol/src/org/jmol/modelkit/modelKitPopupResourceBundle.java 2010-05-27 15:37:12 UTC (rev 13234) @@ -41,7 +41,7 @@ private static String[][] menuContents = { { "modelkitMenu", "atomMenu bondMenu optionsMenu" }, { "optionsMenu", "new center addh minimize hmin " + - "- saveFileSIGNED saveStateSIGNED exit" }, + " - undo redo - SIGNEDsaveFile SIGNEDsaveState exit" }, { "atomMenu" , "assignAtom_XP!CB assignAtom_XxP!CB dragAtomP!CB dragMinimizeP!CB dragMoleculeP!CB dragMinimizeMoleculeP!CB " + "- assignAtom_CP!CB assignAtom_HP!CB assignAtom_NP!CB assignAtom_OP!CB " + "_??P!CB _??P!CB _??P!CB " + @@ -56,9 +56,11 @@ { "addh" , "calculate hydrogens {model=_lastframe}" }, { "minimize" , "minimize" }, { "hmin" , "delete hydrogens and model=_lastframe; minimize addhydrogens" }, - { "saveFileSIGNED", "select visible;write COORD '?jmol.mol'" }, - { "saveStateSIGNED", "write '?jmol.jpg'" }, + { "SIGNEDsaveFile", "select visible;write COORD '?jmol.mol'" }, + { "SIGNEDsaveState", "write '?jmol.jpg'" }, { "clearQ", "clearQ" }, + { "undo" , "!UNDO" }, + { "redo" , "!REDO" }, { "exit", "set modelkitMode false" }, }; @@ -73,13 +75,15 @@ "bondMenu", "<bonds.png>",//GT._("bonds"), "optionsMenu", "<dotdotdot.png>",//GT._("atoms"), "new", GT._("new"), + "undo", GT._("undo (CTRL-Z)"), + "redo", GT._("redo (CTRL-Y)"), "center", GT._("center"), "addh", GT._("add hydrogens"), "minimize", GT._("minimize"), "hmin", GT._("fix hydrogens and minimize"), "clearQ", GT._("clear"), - "saveFileSIGNED", GT._("save file"), - "saveStateSIGNED", GT._("save state"), + "SIGNEDsaveFile", GT._("save file"), + "SIGNEDsaveState", GT._("save state"), "assignAtom_XP!CB" , GT._("delete atom"), "assignAtom_XxP!CB" , GT._("drag to bond"), "dragAtomP!CB" , GT._("drag atom"), Modified: trunk/Jmol/src/org/jmol/modelset/ModelCollection.java =================================================================== --- trunk/Jmol/src/org/jmol/modelset/ModelCollection.java 2010-05-27 13:34:22 UTC (rev 13233) +++ trunk/Jmol/src/org/jmol/modelset/ModelCollection.java 2010-05-27 15:37:12 UTC (rev 13234) @@ -3896,11 +3896,11 @@ } public boolean isAtomPDB(int i) { - return models[atoms[i].modelIndex].isPDB; + return i >= 0 && models[atoms[i].modelIndex].isPDB; } public boolean isAtomAssignable(int i) { - return !isAtomPDB(i) && atoms[i].modelIndex == modelCount - 1; + return i >= 0 && !isAtomPDB(i) && atoms[i].modelIndex == modelCount - 1; } Modified: trunk/Jmol/src/org/jmol/viewer/ActionManager.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/ActionManager.java 2010-05-27 13:34:22 UTC (rev 13233) +++ trunk/Jmol/src/org/jmol/viewer/ActionManager.java 2010-05-27 15:37:12 UTC (rev 13234) @@ -39,6 +39,7 @@ import org.jmol.modelset.MeasurementPending; import org.jmol.script.ScriptEvaluator; import org.jmol.script.Token; +import org.jmol.util.BitSetUtil; import org.jmol.util.Escape; import org.jmol.util.Logger; import org.jmol.util.Point3fi; @@ -753,7 +754,8 @@ isBound = isBound(action, ACTION_dragMinimize); break; case PICKING_DRAG_MINIMIZE_MOLECULE: - isBound = isBound(action, ACTION_dragMinimizeMolecule); + isBound = isBound(action, ACTION_dragMinimizeMolecule) || isBound(action, + ACTION_rotateBranch); break; } if (isBound) { @@ -817,10 +819,10 @@ dragGesture.add(action, x, y, time); if (dragRelease) viewer.setRotateBondIndex(Integer.MIN_VALUE); - if (dragAtomIndex >= 0 - && (atomPickingMode == PICKING_DRAG_MINIMIZE || atomPickingMode == PICKING_DRAG_MINIMIZE_MOLECULE)) - minimize(); - + if (dragAtomIndex >= 0) { + if (atomPickingMode == PICKING_DRAG_MINIMIZE || atomPickingMode == PICKING_DRAG_MINIMIZE_MOLECULE) + minimize(true); + } if (atomPickingMode == PICKING_ASSIGN_ATOM && isBound(action, ACTION_assignNew)) { if (measurementPending == null || dragAtomIndex < 0) @@ -912,12 +914,12 @@ } } - private void minimize() { - BitSet bs = new BitSet(); - bs.set(dragAtomIndex); + private void minimize(boolean dragDone) { + BitSet bs = BitSetUtil.setBit(dragAtomIndex); + if (dragDone) + dragAtomIndex = -1; bs = viewer.getAtomBits((viewer.isAtomPDB(dragAtomIndex) ? Token.group : Token.molecule), bs); - dragAtomIndex = -1; viewer.stopMinimization(); float range = (atomPickingMode == PICKING_DRAG_MINIMIZE_MOLECULE ? JmolConstants.MINIMIZE_FIXED_RANGE : 0); @@ -1015,23 +1017,21 @@ viewer.undoAction(true, dragAtomIndex, AtomCollection.TAINT_COORD); checkMotion(Viewer.CURSOR_MOVE); if (isBound(action, ACTION_rotateBranch)) { - BitSet bs = new BitSet(); - bs.set(dragAtomIndex); - bs = viewer.getAtomBits(Token.molecule, bs); - viewer.rotateMolecule(getDegrees(deltaX, 0), getDegrees(deltaY, 1), bs); - return; + BitSet bs = viewer.getAtomBits(Token.molecule, BitSetUtil.setBit(dragAtomIndex)); + viewer.rotateMolecule(getDegrees(deltaX, 0), getDegrees(deltaY, 1), + bs); + } else { + BitSet bs = null; + switch (atomPickingMode) { + case PICKING_DRAG_MOLECULE: + case PICKING_DRAG_MINIMIZE_MOLECULE: + bs = viewer.getAtomBits(Token.molecule, BitSetUtil.setBit(dragAtomIndex)); + break; + } + viewer.moveAtomWithHydrogens(dragAtomIndex, deltaX, deltaY, bs); } - BitSet bs = null; - switch (atomPickingMode) { - case PICKING_DRAG_MOLECULE: - case PICKING_DRAG_MINIMIZE_MOLECULE: - bs = new BitSet(); - bs.set(dragAtomIndex); - bs = viewer.getAtomBits(Token.molecule, bs); - break; - } - - viewer.moveAtomWithHydrogens(dragAtomIndex, deltaX, deltaY, bs); + // NAH! if (atomPickingMode == PICKING_DRAG_MINIMIZE_MOLECULE && (dragGesture.getPointCount() % 5 == 0)) + // minimize(false); return; } } @@ -1307,9 +1307,7 @@ viewer.setRotateBondIndex(nearestPoint.index); break; default: - BitSet bs = new BitSet(); - bs.set(nearestPoint.index); - viewer.deleteBonds(bs); + viewer.deleteBonds(BitSetUtil.setBit(nearestPoint.index)); } return false; } Modified: trunk/Jmol/src/org/jmol/viewer/MouseManager14.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/MouseManager14.java 2010-05-27 13:34:22 UTC (rev 13233) +++ trunk/Jmol/src/org/jmol/viewer/MouseManager14.java 2010-05-27 15:37:12 UTC (rev 13234) @@ -148,11 +148,11 @@ case 'z': // undo switch (modifiers) { case Binding.CTRL: - viewer.undoAction(false, 0, 0); + viewer.undoAction(false, 0, 1); } break; case 25: - case 'y': // undo + case 'y': // redo switch (modifiers) { case Binding.CTRL: viewer.undoAction(false, 0, -1); Modified: trunk/Jmol/src/org/jmol/viewer/Viewer.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/Viewer.java 2010-05-27 13:34:22 UTC (rev 13233) +++ trunk/Jmol/src/org/jmol/viewer/Viewer.java 2010-05-27 15:37:12 UTC (rev 13234) @@ -213,7 +213,6 @@ void stopMinimization() { if (minimizer != null) { minimizer.setProperty("stop", null); - minimizer = null; } } @@ -489,7 +488,7 @@ + (isSignedApplet ? " (signed)" : ""))); } - zap(false, false); // here to allow echos + zap(false, true); // here to allow echos global.setParameterValue("language", GT.getLanguage()); } @@ -1810,7 +1809,7 @@ * @return null or error message */ public String openReader(String fullPathName, String fileName, Reader reader) { - zap(true, false); + zap(true, true); Object atomSetCollection = fileManager.createAtomSetCollectionFromReader( fullPathName, fileName, reader, setLoadParameters(null)); return createModelSetAndReturnError(atomSetCollection, false, null); @@ -1865,7 +1864,7 @@ */ public String openDOM(Object DOMNode) { // applet.loadDOMNode - zap(true, false); + zap(true, true); long timeBegin = System.currentTimeMillis(); Object atomSetCollection = fileManager.createAtomSetCollectionFromDOM( DOMNode, setLoadParameters(null)); @@ -1897,7 +1896,7 @@ if (arrayData == null || arrayData.size() == 0) return null; if (!isAppend) - zap(true, false); + zap(true, true); Object atomSetCollection = fileManager.createAtomSeCollectionFromArrayData( arrayData, setLoadParameters(null), isAppend); return createModelSetAndReturnError(atomSetCollection, isAppend, null); @@ -1998,13 +1997,13 @@ } if (strModel != null) { if (!isAppend) - zap(true, false); + zap(true, true); atomSetCollection = fileManager.createAtomSetCollectionFromString( strModel, loadScript, htParams, isAppend, isLoadVariable || haveFileData && !isString); } else { if (!isAppend && fileName.charAt(0) != '?') - zap(false, false); + zap(false, true); atomSetCollection = fileManager.createAtomSetCollectionFromFile(fileName, htParams, loadScript, isAppend); } @@ -2016,7 +2015,7 @@ Hashtable htParams, StringBuffer loadScript) { if (!isAppend) - zap(false, false); + zap(false, true); return fileManager.createAtomSetCollectionFromFiles(fileNames, loadScript, setLoadParameters(htParams), isAppend); } @@ -2117,7 +2116,7 @@ } if (!isAppend) - zap(true, false); + zap(true, true); StringBuffer loadScript = new StringBuffer(); Object atomSetCollection = fileManager.createAtomSetCollectionFromString( strModel, loadScript, setLoadParameters(htParams), isAppend, false); @@ -2128,7 +2127,7 @@ boolean isAppend) { // loadInline if (!isAppend) - zap(true, false); + zap(true, true); StringBuffer loadScript = new StringBuffer(); Object atomSetCollection = fileManager.createAtomSeCollectionFromStrings( arrayModels, loadScript, setLoadParameters(htParams), isAppend); @@ -2378,6 +2377,7 @@ if (resetUndo) { actionStates.clear(); actionStatesRedo.clear(); + lastUndoRedo = 0; } if (haveDisplay) { mouseManager.clear(); @@ -2401,7 +2401,7 @@ } private void zap(String msg) { - zap(true, false); + zap(true, true); echoMessage(msg); } @@ -3941,9 +3941,21 @@ return "script processing stepped"; if (checkHalt(str, isInterrupt)) return "script execution halted"; + if (checkUndo(str)) + return "OK - " + str; return null; } + private boolean checkUndo(String str) { + if (str.equalsIgnoreCase("redo")) + undoAction(false, 0, -1); + else if (str.equalsIgnoreCase("undo")) + undoAction(false, 0, 1); + else + return false; + return true; + } + public boolean usingScriptQueue() { return global.useScriptQueue; } @@ -8496,7 +8508,6 @@ if (rangeFixed > 0) { bsFixed = getAtomsWithin(rangeFixed, bsSelected, true); bsFixed.andNot(bsSelected); - bsSelected.or(bsFixed); } try { getMinimizer(true).minimize(steps, crit, bsSelected, bsFixed, isSilent); @@ -8724,17 +8735,28 @@ private final static int MAX_ACTION_UNDO = 25; private final Vector actionStates = new Vector(); private final Vector actionStatesRedo = new Vector(); - + private int lastUndoRedo = 0; + void undoAction(boolean isSave, int taintedAtom, int type) { - //System.out.println("REDO:" + actionStatesRedo.size()); - //System.out.println("UNDO:" + actionStates.size()); + System.out.println("REDO:" + actionStatesRedo.size()); + System.out.println("UNDO:" + actionStates.size()); if (!isSave) { + stopMinimization(); String s; + System.out.println(type + " " + lastUndoRedo); + if (lastUndoRedo != 0 && lastUndoRedo != type) { + if (type == -1) + actionStates.add(0, actionStatesRedo.remove(0)); + else + actionStatesRedo.add(0, actionStates.remove(0)); + } + lastUndoRedo = type; if (type == -1) { if (actionStatesRedo.size() == 0) return; s = (String) actionStatesRedo.remove(0); + actionStates.add(0, s); } else if (actionStates.size()== 0) { return; } else { @@ -8744,6 +8766,7 @@ evalStringQuiet(s); return; } + lastUndoRedo = 0; actionStatesRedo.clear(); BitSet bs; StringBuffer sb = new StringBuffer(); @@ -8803,7 +8826,7 @@ void moveAtomWithHydrogens(int atomIndex, int deltaX, int deltaY, BitSet bsAtoms) { - clearModelDependentObjects(); + stopMinimization(); Atom atom = modelSet.atoms[atomIndex]; if (bsAtoms == null) { bsAtoms = BitSetUtil.setBit(atomIndex); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |