X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fext%2Fjmol%2FJalviewJmolBinding.java;h=dc18369aa2678804f1061b59b12552d9b3cc661b;hb=9f91642f99bc1a3f01d7c97a7a109d4694a88049;hp=54eb59975166a034d435e48395e109489a243be7;hpb=4f30214e8098748469c6a4269ac2ed6c5750e4b0;p=jalview.git diff --git a/src/jalview/ext/jmol/JalviewJmolBinding.java b/src/jalview/ext/jmol/JalviewJmolBinding.java index 54eb599..dc18369 100644 --- a/src/jalview/ext/jmol/JalviewJmolBinding.java +++ b/src/jalview/ext/jmol/JalviewJmolBinding.java @@ -31,6 +31,8 @@ import java.util.Map; import java.util.StringTokenizer; import java.util.Vector; +import javax.swing.SwingUtilities; + import org.jmol.adapter.smarter.SmarterJmolAdapter; import org.jmol.api.JmolAppConsoleInterface; import org.jmol.api.JmolSelectionListener; @@ -39,10 +41,14 @@ import org.jmol.api.JmolViewer; import org.jmol.c.CBK; import org.jmol.viewer.Viewer; +import jalview.api.AlignmentViewPanel; import jalview.api.FeatureRenderer; -import jalview.bin.Cache; +import jalview.api.FeatureSettingsModelI; +import jalview.api.SequenceRenderer; +import jalview.bin.Console; import jalview.datamodel.PDBEntry; import jalview.datamodel.SequenceI; +import jalview.gui.AppJmol; import jalview.gui.IProgressIndicator; import jalview.gui.StructureViewer.ViewerType; import jalview.io.DataSourceType; @@ -52,6 +58,8 @@ import jalview.structure.StructureCommand; import jalview.structure.StructureCommandI; import jalview.structure.StructureSelectionManager; import jalview.structures.models.AAStructureBindingModel; +import jalview.ws.dbsources.Pdb; +import javajs.util.BS; public abstract class JalviewJmolBinding extends AAStructureBindingModel implements JmolStatusListener, JmolSelectionListener, @@ -83,8 +91,8 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel setStructureCommands(new JmolCommands()); /* * viewer = JmolViewer.allocateViewer(renderPanel, new SmarterJmolAdapter(), - * "jalviewJmol", ap.av.applet .getDocumentBase(), - * ap.av.applet.getCodeBase(), "", this); + * "jalviewJmol", ap.av.applet .getDocumentBase(), ap.av.applet.getCodeBase(), + * "", this); * * jmolpopup = JmolPopup.newJmolPopup(viewer, true, "Jmol", true); */ @@ -114,9 +122,22 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel private String jmolScript(String script) { - Cache.log.debug(">>Jmol>> " + script); - String s = jmolViewer.evalStringQuiet(script); - Cache.log.debug("<>Jmol>> " + script); + String s; + if (useScriptWait) + { + s = jmolViewer.scriptWait(script); + } + else + { + s = jmolViewer.evalStringQuiet(script); // scriptWait(script); BH + } + Console.debug("< 0 + * defensive check for null as getModelFileName can return null even when model + * count ms.mc is > 0 */ filePath = jmolViewer.ms.getModelFileName(i); if (filePath != null && !mset.contains(filePath)) @@ -210,7 +231,10 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel mset.add(filePath); } } - modelFileNames = mset.toArray(new String[mset.size()]); + if (!mset.isEmpty()) + { + modelFileNames = mset.toArray(new String[mset.size()]); + } } return modelFileNames; @@ -248,26 +272,63 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel jmolScript(resetLastRes.toString()); resetLastRes.setLength(0); } + StringBuilder highlightCommands=null; for (AtomSpec atom : atoms) { - highlightAtom(atom.getAtomIndex(), atom.getPdbResNum(), + StringBuilder thisAtom = highlightAtom(atom.getAtomIndex(), atom.getPdbResNum(), atom.getChain(), atom.getPdbFile()); + if (thisAtom!=null) { + if (highlightCommands==null) + { + highlightCommands=thisAtom; + } else { + highlightCommands.append(thisAtom); + } + } } + 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, + 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)); @@ -284,15 +345,20 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel resetLastRes.append(selection).append(";wireframe 0;").append(selection) .append(" and not hetero; spacefill 0;"); - jmolScript(cmd.toString()); - 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) @@ -392,8 +458,8 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel } /* - * highlight position on alignment(s); if some text is returned, - * show this as a second line on the structure hover tooltip + * highlight position on alignment(s); if some text is returned, show this as a + * second line on the structure hover tooltip */ String label = getSsm().mouseOverStructure(pdbResNum, chainId, pdbfilename); @@ -421,7 +487,7 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel lastMessage = strInfo; if (data != null) { - System.err.println("Ignoring additional hover info: " + data + jalview.bin.Console.errPrintln("Ignoring additional hover info: " + data + " (other info: '" + strInfo + "' pos " + atomIndex + ")"); } mouseOverStructure(atomIndex, strInfo); @@ -429,8 +495,8 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel /* * { if (history != null && strStatus != null && - * !strStatus.equals("Script completed")) { history.append("\n" + strStatus); - * } } + * !strStatus.equals("Script completed")) { history.append("\n" + strStatus); } + * } */ public void notifyAtomPicked(int atomIndex, String strInfo, @@ -442,7 +508,7 @@ 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; @@ -491,6 +557,28 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel @Override public void notifyCallback(CBK type, Object[] data) { + /* + * ensure processed in AWT thread to avoid risk of deadlocks + */ + SwingUtilities.invokeLater(new Runnable() + { + + @Override + public void run() + { + processCallback(type, data); + } + }); + } + + /** + * Processes one callback notification from Jmol + * + * @param type + * @param data + */ + protected void processCallback(CBK type, Object[] data) + { try { switch (type) @@ -522,7 +610,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: @@ -532,13 +620,13 @@ 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(); } } @@ -592,6 +680,11 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel modelFileNames = null; boolean notifyLoaded = false; String[] modelfilenames = getStructureFiles(); + if (modelfilenames == null) + { + // Jmol is still loading files! + return; + } // first check if we've lost any structures if (oldmodels != null && oldmodels.length > 0) { @@ -734,7 +827,9 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel FeatureRenderer fr = getFeatureRenderer(null); if (fr != null) { - fr.featuresAdded(); + FeatureSettingsModelI colours = new Pdb().getFeatureColourScheme(); + ((AppJmol) getViewer()).getAlignmentPanel().av + .applyFeaturesStyle(colours); } refreshGUI(); loadNotifiesHandled++; @@ -763,8 +858,7 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel public abstract void sendConsoleEcho(String strEcho); /* * { showConsole(true); * - * history.append("\n" + - * strEcho); } + * history.append("\n" + strEcho); } */ // /End JmolStatusListener @@ -781,7 +875,7 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel public void setCallbackFunction(String callbackType, String callbackFunction) { - System.err.println("Ignoring set-callback request to associate " + jalview.bin.Console.errPrintln("Ignoring set-callback request to associate " + callbackType + " with function " + callbackFunction); } @@ -855,7 +949,7 @@ 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) { @@ -873,7 +967,7 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel console = createJmolConsole(consolePanel, buttonsToShow); } catch (Throwable e) { - System.err.println("Could not create Jmol application console. " + jalview.bin.Console.errPrintln("Could not create Jmol application console. " + e.getMessage()); e.printStackTrace(); } @@ -994,4 +1088,23 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel { return ".spt"; } + + @Override + public void selectionChanged(BS arg0) + { + // TODO Auto-generated method stub + + } + + @Override + public SequenceRenderer getSequenceRenderer(AlignmentViewPanel avp) + { + return new jalview.gui.SequenceRenderer(avp.getAlignViewport()); + } + + @Override + public String getHelpURL() + { + return "http://wiki.jmol.org"; // BH 2018 + } }