X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fext%2Fjmol%2FJalviewJmolBinding.java;h=b0a7b0cd409ba3d40ef5e7e5969bcb064ed249c6;hb=cb628aab46f9027e71b71203b322f96710e09990;hp=41bc116a224bab9bc4004d7f2dffb1baa9f4020d;hpb=14193747f3831242bc7dfac12394eb20eb0ba480;p=jalview.git diff --git a/src/jalview/ext/jmol/JalviewJmolBinding.java b/src/jalview/ext/jmol/JalviewJmolBinding.java index 41bc116..b0a7b0c 100644 --- a/src/jalview/ext/jmol/JalviewJmolBinding.java +++ b/src/jalview/ext/jmol/JalviewJmolBinding.java @@ -20,38 +20,22 @@ */ package jalview.ext.jmol; -import jalview.api.AlignmentViewPanel; -import jalview.api.FeatureRenderer; -import jalview.api.SequenceRenderer; -import jalview.datamodel.AlignmentI; -import jalview.datamodel.HiddenColumns; -import jalview.datamodel.PDBEntry; -import jalview.datamodel.SequenceI; -import jalview.gui.IProgressIndicator; -import jalview.io.DataSourceType; -import jalview.io.StructureFile; -import jalview.schemes.ColourSchemeI; -import jalview.schemes.ResidueProperties; -import jalview.structure.AtomSpec; -import jalview.structure.StructureMappingcommandSet; -import jalview.structure.StructureSelectionManager; -import jalview.structures.models.AAStructureBindingModel; -import jalview.util.MessageManager; - import java.awt.Color; import java.awt.Container; import java.awt.event.ComponentEvent; import java.awt.event.ComponentListener; import java.io.File; import java.net.URL; -import java.security.AccessControlException; import java.util.ArrayList; import java.util.BitSet; import java.util.Hashtable; import java.util.List; 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; @@ -61,10 +45,33 @@ import org.jmol.c.CBK; import org.jmol.script.T; import org.jmol.viewer.Viewer; +import jalview.api.AlignmentViewPanel; +import jalview.api.FeatureRenderer; +import jalview.api.FeatureSettingsModelI; +import jalview.api.SequenceRenderer; +import jalview.datamodel.AlignmentI; +import jalview.datamodel.HiddenColumns; +import jalview.datamodel.PDBEntry; +import jalview.datamodel.SequenceI; +import jalview.gui.AppJmol; +import jalview.gui.IProgressIndicator; +import jalview.io.DataSourceType; +import jalview.io.StructureFile; +import jalview.schemes.ColourSchemeI; +import jalview.schemes.ResidueProperties; +import jalview.structure.AtomSpec; +import jalview.structure.StructureMappingcommandSet; +import jalview.structure.StructureSelectionManager; +import jalview.structures.models.AAStructureBindingModel; +import jalview.util.MessageManager; +import jalview.ws.dbsources.Pdb; + public abstract class JalviewJmolBinding extends AAStructureBindingModel implements JmolStatusListener, JmolSelectionListener, ComponentListener { + private String lastMessage; + boolean allChainsSelected = false; /* @@ -89,8 +96,6 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel String lastCommand; - String lastMessage; - boolean loadedInline; StringBuffer resetLastRes = new StringBuffer(); @@ -478,6 +483,8 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel lastCommand = command; } + Thread colourby = null; + /** * Sends a set of colour commands to the structure viewer * @@ -485,15 +492,28 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel */ @Override protected void colourBySequence( - StructureMappingcommandSet[] colourBySequenceCommands) + final StructureMappingcommandSet[] colourBySequenceCommands) { - for (StructureMappingcommandSet cpdbbyseq : colourBySequenceCommands) + if (colourby != null) { - for (String cbyseq : cpdbbyseq.commands) + colourby.interrupt(); + colourby = null; + } + colourby = new Thread(new Runnable() + { + @Override + public void run() { - executeWhenReady(cbyseq); + for (StructureMappingcommandSet cpdbbyseq : colourBySequenceCommands) + { + for (String cbyseq : cpdbbyseq.commands) + { + executeWhenReady(cbyseq); + } + } } - } + }); + colourby.start(); } /** @@ -600,74 +620,6 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel */ private int _modelFileNameMap[]; - // //////////////////////////////// - // /StructureListener - // @Override - public synchronized String[] getPdbFilex() - { - if (viewer == null) - { - return new String[0]; - } - if (modelFileNames == null) - { - List mset = new ArrayList<>(); - _modelFileNameMap = new int[viewer.ms.mc]; - String m = viewer.ms.getModelFileName(0); - if (m != null) - { - String filePath = m; - try - { - filePath = new File(m).getAbsolutePath(); - } catch (AccessControlException x) - { - // usually not allowed to do this in applet - System.err.println( - "jmolBinding: Using local file string from Jmol: " + m); - } - if (filePath.indexOf("/file:") != -1) - { - // applet path with docroot - discard as format won't match pdbfile - filePath = m; - } - mset.add(filePath); - _modelFileNameMap[0] = 0; // filename index for first model is always 0. - } - int j = 1; - for (int i = 1; i < viewer.ms.mc; i++) - { - m = viewer.ms.getModelFileName(i); - String filePath = m; - if (m != null) - { - try - { - filePath = new File(m).getAbsolutePath(); - } catch (AccessControlException x) - { - // usually not allowed to do this in applet, so keep raw handle - // System.err.println("jmolBinding: Using local file string from - // Jmol: "+m); - } - } - - /* - * add this model unless it is read from a structure file we have - * already seen (example: 2MJW is an NMR structure with 10 models) - */ - if (!mset.contains(filePath)) - { - mset.add(filePath); - _modelFileNameMap[j] = i; // record the model index for the filename - j++; - } - } - modelFileNames = mset.toArray(new String[mset.size()]); - } - return modelFileNames; - } - @Override public synchronized String[] getStructureFiles() { @@ -808,7 +760,7 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel viewer.openStringInline(string); } - public void mouseOverStructure(int atomIndex, String strInfo) + protected void mouseOverStructure(int atomIndex, final String strInfo) { int pdbResNum; int alocsep = strInfo.indexOf("^"); @@ -862,34 +814,63 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel try { // recover PDB filename for the model hovered over. - int _mp = _modelFileNameMap.length - 1, - mnumber = new Integer(mdlId).intValue() - 1; - while (mnumber < _modelFileNameMap[_mp]) + int mnumber = Integer.valueOf(mdlId).intValue() - 1; + if (_modelFileNameMap != null) { - _mp--; + int _mp = _modelFileNameMap.length - 1; + + while (mnumber < _modelFileNameMap[_mp]) + { + _mp--; + } + pdbfilename = modelFileNames[_mp]; } - pdbfilename = modelFileNames[_mp]; - if (pdbfilename == null) + else { - pdbfilename = new File(viewer.ms.getModelFileName(mnumber)) - .getAbsolutePath(); - } + if (mnumber >= 0 && mnumber < modelFileNames.length) + { + pdbfilename = modelFileNames[mnumber]; + } + if (pdbfilename == null) + { + pdbfilename = new File(viewer.ms.getModelFileName(mnumber)) + .getAbsolutePath(); + } + } } catch (Exception e) { } - ; } - if (lastMessage == null || !lastMessage.equals(strInfo)) + + /* + * 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); + if (label != null) { - getSsm().mouseOverStructure(pdbResNum, chainId, pdbfilename); + // change comma to pipe separator (newline token for Jmol) + label = label.replace(',', '|'); + StringTokenizer toks = new StringTokenizer(strInfo, " "); + StringBuilder sb = new StringBuilder(); + sb.append("select ").append(String.valueOf(pdbResNum)).append(":") + .append(chainId).append("/1"); + sb.append(";set hoverLabel \"").append(toks.nextToken()).append(" ") + .append(toks.nextToken()); + sb.append("|").append(label).append("\""); + evalStateCommand(sb.toString()); } - - lastMessage = strInfo; } public void notifyAtomHovered(int atomIndex, String strInfo, String data) { + if (strInfo.equals(lastMessage)) + { + return; + } + lastMessage = strInfo; if (data != null) { System.err.println("Ignoring additional hover info: " + data @@ -962,6 +943,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) @@ -1128,8 +1131,7 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel // see JAL-623 - need method of matching pasted data up { pdb = getSsm().setMapping(getSequence()[pe], getChains()[pe], - pdbfile, DataSourceType.PASTE, - getIProgressIndicator()); + pdbfile, DataSourceType.PASTE, getIProgressIndicator()); getPdbEntry(modelnum).setFile("INLINE" + pdb.getId()); matches = true; foundEntry = true; @@ -1215,7 +1217,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++; @@ -1229,7 +1233,10 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel return chainNames; } - protected abstract IProgressIndicator getIProgressIndicator(); + protected IProgressIndicator getIProgressIndicator() + { + return null; + } public void notifyNewPickingModeMeasurement(int iatom, String strMeasure) {