From: Jim Procter Date: Wed, 17 Nov 2021 13:39:31 +0000 (+0000) Subject: JAL-3922 convert selection events in Jmol to highlights in Jalview - still need to... X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=refs%2Fheads%2Ffeatures%2Fr2_11_2%2FJAL-3922_jmolSelectionHighlighting;p=jalview.git JAL-3922 convert selection events in Jmol to highlights in Jalview - still need to ignore selection events performed as part of Jalview manipulating Jmol. --- diff --git a/src/jalview/ext/jmol/JalviewJmolBinding.java b/src/jalview/ext/jmol/JalviewJmolBinding.java index 903d9b7..6ee0fa7 100644 --- a/src/jalview/ext/jmol/JalviewJmolBinding.java +++ b/src/jalview/ext/jmol/JalviewJmolBinding.java @@ -39,6 +39,8 @@ import org.jmol.api.JmolSelectionListener; import org.jmol.api.JmolStatusListener; import org.jmol.api.JmolViewer; import org.jmol.c.CBK; +import org.jmol.modelset.Atom; +import org.jmol.modelset.Model; import org.jmol.viewer.Viewer; import jalview.api.AlignmentViewPanel; @@ -246,6 +248,8 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel // jmolpopup.jpiShow(x, y); } + private List lastHighlight = new ArrayList(); + private List resetLastHighlight = new ArrayList(); /** * Highlight zero, one or more atoms on the structure */ @@ -254,6 +258,11 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel { if (atoms != null) { + // make sure we ignore the next few selection events for these + lastHighlight.addAll(resetLastHighlight); + lastHighlight.addAll(atoms); + resetLastHighlight.clear(); + resetLastHighlight.addAll(atoms); if (resetLastRes.length() > 0) { jmolScript(resetLastRes.toString()); @@ -281,6 +290,8 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel StringBuilder selection = new StringBuilder(32); StringBuilder cmd = new StringBuilder(64); + // save existing selection. + // display halo selection.append("select ").append(String.valueOf(pdbResNum)); selection.append(":"); if (!chain.equals(" ")) @@ -906,7 +917,29 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel commandOptions, this); jmolViewer.setJmolStatusListener(this); // extends JmolCallbackListener - + + jmolViewer.addSelectionListener(new JmolSelectionListener() + { + + @Override + public void selectionChanged(BS arg0) + { + if (!isLoadingFinished()) + { + return; + } + List lastH = lastHighlight; + lastHighlight = new ArrayList(); + final AtomSpec[] lastHighlighted = lastH.toArray(new AtomSpec[0]); // copy of the int[] array + SwingUtilities.invokeLater(new Runnable() { + + public void run() { + + processselectionChanged(arg0, lastHighlighted); + } + }); + } + }); try { console = createJmolConsole(consolePanel, buttonsToShow); @@ -924,6 +957,53 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel } + protected void processselectionChanged(BS arg0, AtomSpec[] lastHighlighted) + { + int atom = arg0.nextSetBit(0); + int modelNo=-1,resNo=-1; + String chainCode="NOCHAIN"; + List toSelect = new ArrayList(); + while (atom>-1 && arg0.get(atom)){ + // + Model atomModel = jmolViewer.getModelForAtomIndex(atom); + Atom firstAtom = atomModel.ms.getAtom(atom); + String chcode = firstAtom.getChainIDStr(); + if (atomModel.modelIndex!=modelNo || resNo != firstAtom.getResno() || !chainCode.equals(chcode)) + { + resNo = firstAtom.getResno(); + modelNo = atomModel.modelIndex; + chainCode = chcode; + boolean ignore=false; + String modelFile = getPdbEntry(modelNo).getFile(); + if (lastHighlighted!=null) + { + + for (AtomSpec hgh:lastHighlighted) + { + if (hgh.getPdbResNum() == resNo && chainCode.equals(hgh.getChain()) && hgh.getPdbFile().equals(modelFile)) + { + ignore=true; + break; + } + } + } + if (!ignore) + { + AtomSpec atomspec = new AtomSpec(modelFile, chainCode, resNo, atomModel.firstAtomIndex); + toSelect.add(atomspec); + } + } + // look for next selected atom + atom = arg0.nextSetBit(++atom); + } + if (toSelect.size()>0 || arg0.isEmpty()) + { + // if we have ignored everything we don't clear the existing highlight + getSsm().mouseOverStructure(toSelect); + } + } + + protected abstract JmolAppConsoleInterface createJmolConsole( Container consolePanel, String buttonsToShow); diff --git a/src/jalview/gui/AppJmolBinding.java b/src/jalview/gui/AppJmolBinding.java index 6b06e56..c581317 100644 --- a/src/jalview/gui/AppJmolBinding.java +++ b/src/jalview/gui/AppJmolBinding.java @@ -27,8 +27,12 @@ import java.util.List; import java.util.Map; import javax.swing.JComponent; +import javax.swing.SwingUtilities; +import org.jmol.api.AtomIndexIterator; import org.jmol.api.JmolAppConsoleInterface; +import org.jmol.modelset.Atom; +import org.jmol.modelset.Model; import org.openscience.jmol.app.jmolpanel.console.AppConsole; import jalview.api.AlignmentViewPanel; @@ -39,6 +43,7 @@ import jalview.datamodel.PDBEntry; import jalview.datamodel.SequenceI; import jalview.ext.jmol.JalviewJmolBinding; import jalview.io.DataSourceType; +import jalview.structure.AtomSpec; import jalview.structure.StructureSelectionManager; import jalview.util.MessageManager; import jalview.util.Platform; @@ -142,8 +147,12 @@ public class AppJmolBinding extends JalviewJmolBinding @Override public void selectionChanged(BS arg0) { + SwingUtilities.invokeLater(new Runnable() { + public void run() { + } + }); } - + @Override public void showConsole(boolean b) {