X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fext%2Fjmol%2FJalviewJmolBinding.java;h=93a56334ec0176d7e5506fb10595ad5ddeeb76ec;hb=4a28fee3e0c129a01268d26e1396b045bd893fb8;hp=a529fae5e827d81ddca27ea721b725ec4656e34e;hpb=d1cf4609268fb7fbae0716b6e699a130eea02647;p=jalview.git diff --git a/src/jalview/ext/jmol/JalviewJmolBinding.java b/src/jalview/ext/jmol/JalviewJmolBinding.java index a529fae..93a5633 100644 --- a/src/jalview/ext/jmol/JalviewJmolBinding.java +++ b/src/jalview/ext/jmol/JalviewJmolBinding.java @@ -26,6 +26,8 @@ import java.awt.event.ComponentListener; import java.io.File; import java.net.URL; import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.StringTokenizer; @@ -83,8 +85,6 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel public Viewer jmolViewer; - private boolean globalUseScriptWait = false; - public JalviewJmolBinding(StructureSelectionManager ssm, PDBEntry[] pdbentry, SequenceI[][] sequenceIs, DataSourceType protocol) @@ -131,7 +131,7 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel { Console.debug(">>Jmol>> " + script); String s; - if (globalUseScriptWait || useScriptWait) + if (useScriptWait) { s = jmolViewer.scriptWait(script); } @@ -156,7 +156,7 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel jmolHistory(false); if (lastCommand == null || !lastCommand.equals(cmd)) { - jmolScript(cmd + "\n"); + jmolScript(cmd + "\n", command.isWaitNeeded()); } jmolHistory(true); lastCommand = cmd; @@ -165,21 +165,21 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel public void createImage(String file, String type, int quality) { - System.out.println("JMOL CREATE IMAGE"); + jalview.bin.Console.outPrintln("JMOL CREATE IMAGE"); } @Override public String createImage(String fileName, String type, Object textOrBytes, int quality) { - System.out.println("JMOL CREATE IMAGE"); + jalview.bin.Console.outPrintln("JMOL CREATE IMAGE"); return null; } @Override public String eval(String strEval) { - // System.out.println(strEval); + // jalview.bin.Console.outPrintln(strEval); // "# 'eval' is implemented only for the applet."; return null; } @@ -187,6 +187,27 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel // End StructureListener // ////////////////////////// + //////////////////////////// + // HETATM get + // + + @Override + public Map getHetatmNames() + { + HashMap hetlist = new HashMap(); + for (int mc = 0; mc < jmolViewer.ms.mc; mc++) + { + Map hets = jmolViewer.ms.getHeteroList(mc); + if (hets != null) + { + hetlist.putAll(hets); + } + } + return hetlist; + } + // + //////////////////////////// + @Override public float[][] functionXY(String functionName, int x, int y) { @@ -269,39 +290,71 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel { if (atoms != null) { - // we set the globalUseScriptWait (and reset to previous value) only if - // we're going to use it here - boolean useScriptWait = atoms.size() > 1; - boolean prevUseScriptWait = false; - if (useScriptWait) - prevUseScriptWait = setGlobalUseScriptWait(useScriptWait); if (resetLastRes.length() > 0) { - jmolScript(resetLastRes.toString(), useScriptWait); + jmolScript(resetLastRes.toString()); resetLastRes.setLength(0); } + StringBuilder highlightCommands = null; for (AtomSpec atom : atoms) { - highlightAtom(atom.getAtomIndex(), atom.getPdbResNum(), - atom.getChain(), atom.getPdbFile(), useScriptWait); + StringBuilder thisAtom = highlightAtom(atom.getAtomIndex(), + atom.getPdbResNum(), atom.getChain(), atom.getPdbFile()); + if (thisAtom != null) + { + if (highlightCommands == null) + { + highlightCommands = thisAtom; + } + else + { + highlightCommands.append(thisAtom); + } + } } - if (useScriptWait) - setGlobalUseScriptWait(prevUseScriptWait); + if (highlightCommands != null) + { + jmolHistory(false); + jmolScript(highlightCommands.toString()); + jmolHistory(true); + } + // Highlight distances between atoms with a 'measure' command - not yet + // working + // if (atoms.size() >= 2) + // { + // StringBuilder sb = new StringBuilder(); + // for (int a = 0; a < atoms.size(); a++) + // { + // AtomSpec speca = atoms.get(a); + // String a_model = getModelIdForFile(speca.getPdbFile()); + // for (int b = a + 1; b < atoms.size(); b++) + // { + // AtomSpec specb = atoms.get(b); + // String b_model = getModelIdForFile(speca.getPdbFile()); + // sb.append("measure ALL (" + speca.getAtomIndex() + " and */" + // + a_model + ") (" + specb.getAtomIndex() + " and */" + // + b_model + ");"); + // } + // } + // jmolHistory(false, useScriptWait); + // jmolScript(sb.toString(), useScriptWait); + // jmolHistory(true, useScriptWait); + // } + } + } // jmol/ssm only - public void highlightAtom(int atomIndex, int pdbResNum, String chain, - String pdbfile, boolean useScriptWait) + private StringBuilder highlightAtom(int atomIndex, int pdbResNum, + String chain, String pdbfile) { String modelId = getModelIdForFile(pdbfile); if (modelId.isEmpty()) { - return; + return null; } - jmolHistory(false); - StringBuilder selection = new StringBuilder(32); StringBuilder cmd = new StringBuilder(64); selection.append("select ").append(String.valueOf(pdbResNum)); @@ -318,15 +371,20 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel resetLastRes.append(selection).append(";wireframe 0;").append(selection) .append(" and not hetero; spacefill 0;"); - jmolScript(cmd.toString(), useScriptWait); - jmolHistory(true); + return cmd; } private boolean debug = true; private void jmolHistory(boolean enable) { - jmolScript("History " + ((debug || enable) ? "on" : "off")); + jmolHistory(enable, false); + } + + private void jmolHistory(boolean enable, boolean useScriptWait) + { + jmolScript("History " + ((debug || enable) ? "on" : "off"), + useScriptWait); } public void loadInline(String string) @@ -455,8 +513,9 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel lastMessage = strInfo; if (data != null) { - System.err.println("Ignoring additional hover info: " + data - + " (other info: '" + strInfo + "' pos " + atomIndex + ")"); + jalview.bin.Console.errPrintln( + "Ignoring additional hover info: " + data + " (other info: '" + + strInfo + "' pos " + atomIndex + ")"); } mouseOverStructure(atomIndex, strInfo); } @@ -476,7 +535,8 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel */ if (strData != null) { - System.err.println("Ignoring additional pick data string " + strData); + jalview.bin.Console.errPrintln( + "Ignoring additional pick data string " + strData); } int chainSeparator = strInfo.indexOf(":"); int p = 0; @@ -578,7 +638,7 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel (data == null) ? ((String) null) : (String) data[1]); break; case ERROR: - // System.err.println("Ignoring error callback."); + // jalview.bin.Console.errPrintln("Ignoring error callback."); break; case SYNC: case RESIZE: @@ -588,13 +648,14 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel case CLICK: default: - System.err.println( + jalview.bin.Console.errPrintln( "Unhandled callback " + type + " " + data[1].toString()); break; } } catch (Exception e) { - System.err.println("Squashed Jmol callback handler error:"); + jalview.bin.Console + .errPrintln("Squashed Jmol callback handler error:"); e.printStackTrace(); } } @@ -843,8 +904,9 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel public void setCallbackFunction(String callbackType, String callbackFunction) { - System.err.println("Ignoring set-callback request to associate " - + callbackType + " with function " + callbackFunction); + jalview.bin.Console + .errPrintln("Ignoring set-callback request to associate " + + callbackType + " with function " + callbackFunction); } @@ -917,7 +979,8 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel String buttonsToShow) { - System.err.println("Allocating Jmol Viewer: " + commandOptions); + jalview.bin.Console + .errPrintln("Allocating Jmol Viewer: " + commandOptions); if (commandOptions == null) { @@ -935,8 +998,9 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel console = createJmolConsole(consolePanel, buttonsToShow); } catch (Throwable e) { - System.err.println("Could not create Jmol application console. " - + e.getMessage()); + jalview.bin.Console + .errPrintln("Could not create Jmol application console. " + + e.getMessage()); e.printStackTrace(); } if (consolePanel != null) @@ -1075,11 +1139,4 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel { return "http://wiki.jmol.org"; // BH 2018 } - - private boolean setGlobalUseScriptWait(boolean b) - { - boolean prev = globalUseScriptWait; - globalUseScriptWait = b; - return prev; - } }