From e739c2824d4d6a93c3e0f255780259c7daf2dc21 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Fri, 31 Jan 2020 16:11:21 +0000 Subject: [PATCH] JAL-2422 temporary hacks removed; use hex colours for Chimera[X] --- .../edu/ucsf/rbvi/strucviz2/ChimeraManager.java | 81 ++++++++++++-------- .../ext/rbvi/chimera/JalviewChimeraBinding.java | 40 ++-------- src/jalview/gui/AppJmol.java | 1 + src/jalview/gui/ChimeraViewFrame.java | 8 +- 4 files changed, 60 insertions(+), 70 deletions(-) diff --git a/src/ext/edu/ucsf/rbvi/strucviz2/ChimeraManager.java b/src/ext/edu/ucsf/rbvi/strucviz2/ChimeraManager.java index 216c06c..710ca95 100644 --- a/src/ext/edu/ucsf/rbvi/strucviz2/ChimeraManager.java +++ b/src/ext/edu/ucsf/rbvi/strucviz2/ChimeraManager.java @@ -348,14 +348,22 @@ public class ChimeraManager */ public void startListening(String uri) { + /* + * listen for model changes + */ String command = isChimeraX ? ("info notify start models prefix ModelChanged jalview url " - + uri - + "; info notify start selection jalview prefix SelectionChanged url " + uri) - : ("listen start models url " + uri - + ";listen start select prefix SelectionChanged url " - + uri); + : ("listen start models url " + uri); + sendChimeraCommand(command, false); + + /* + * listen for selection changes + */ + command = isChimeraX + ? ("info notify start selection jalview prefix SelectionChanged url " + + uri) + : ("listen start select prefix SelectionChanged url " + uri); sendChimeraCommand(command, false); } @@ -436,12 +444,13 @@ public class ChimeraManager */ if (isChimeraX) { - return selectedResidues; + // return selectedResidues; } // in fact 'listinfo' (undocumented) works in ChimeraX - String command = (isChimeraX ? "info" : "list") - + " selection level residue"; + String command = (isChimeraX + ? "view" /*"info selection level residue" */ + : "list selection level residue"); List chimeraReply = sendChimeraCommand(command, true); if (chimeraReply != null) { @@ -497,19 +506,24 @@ public class ChimeraManager public List getModelList() { List modelList = new ArrayList<>(); - modelList.add(new ChimeraModel("4zhp", ModelType.PDB_MODEL, 1, 0)); - return modelList; // ChimeraX doesn't have 'list models' command - // List list = sendChimeraCommand("list models type molecule", - // true); - // if (list != null) - // { - // for (String modelLine : list) - // { - // ChimeraModel chimeraModel = new ChimeraModel(modelLine); - // modelList.add(chimeraModel); - // } - // } - // return modelList; + String command = "list models type " + + (isChimeraX ? "AtomicStructure" : "molecule"); + List list = sendChimeraCommand(command, true); + if (list != null) + { + for (String modelLine : list) + { + try + { + ChimeraModel chimeraModel = new ChimeraModel(modelLine); + modelList.add(chimeraModel); + } catch (NullPointerException e) + { + // hack for now + } + } + } + return modelList; } /** @@ -868,24 +882,23 @@ public class ChimeraManager { String restUrl = "http://127.0.0.1:" + this.chimeraRestPort + "/run"; List commands = new ArrayList<>(1); - String encoded = command.replace(" ", "+").replace("#", "%23") - .replace("|", "%7C").replace(";", "%3B"); - commands.add(new BasicNameValuePair("command", encoded)); + String method = isChimeraX() ? "GET" : "POST"; + if ("GET".equals(method)) + { + command = command.replace(" ", "+").replace("#", "%23") + .replace("|", "%7C").replace(";", "%3B"); + } + commands.add(new BasicNameValuePair("command", command)); List reply = new ArrayList<>(); BufferedReader response = null; try { - if (isChimeraX()) - { - response = HttpClientUtils.doHttpGet(restUrl, commands, - CONNECTION_TIMEOUT_MS, REST_REPLY_TIMEOUT_MS); - } - else - { - response = HttpClientUtils.doHttpUrlPost(restUrl, commands, - CONNECTION_TIMEOUT_MS, REST_REPLY_TIMEOUT_MS); - } + response = "GET".equals(method) + ? HttpClientUtils.doHttpGet(restUrl, commands, + CONNECTION_TIMEOUT_MS, REST_REPLY_TIMEOUT_MS) + : HttpClientUtils.doHttpUrlPost(restUrl, commands, + CONNECTION_TIMEOUT_MS, REST_REPLY_TIMEOUT_MS); String line = ""; while ((line = response.readLine()) != null) { diff --git a/src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java b/src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java index 786fc6c..d0fa5ef 100644 --- a/src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java +++ b/src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java @@ -41,6 +41,7 @@ import jalview.structure.AtomSpec; import jalview.structure.StructureMappingcommandSet; import jalview.structure.StructureSelectionManager; import jalview.structures.models.AAStructureBindingModel; +import jalview.util.ColorUtils; import jalview.util.MessageManager; import java.awt.Color; @@ -137,8 +138,7 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel try { List modelsToMap = new ArrayList<>(); - List oldList = viewer.isChimeraX() ? new ArrayList<>() - : viewer.getModelList(); + List oldList = viewer.getModelList(); boolean alreadyOpen = false; /* @@ -1025,8 +1025,8 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel /* * concatenate colour commands, one per residue symbol - * Chimera format: color 0.000000,0.372549,0.627451 ::VAL - * ChimeraX format: color :VAL rgb(73,73,182) + * Chimera format: color colorCode ::VAL + * ChimeraX format: color :VAL colourCode */ boolean chimeraX = viewer.isChimeraX(); for (String resName : residueSet) @@ -1036,7 +1036,7 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel : resName.charAt(0); Color col = cs.findColour(res, 0, null, null, 0f); command.append("color "); - String colorSpec = getRgbDescriptor(col, chimeraX); + String colorSpec = ColorUtils.toTkCode(col); if (chimeraX) { command.append(":").append(resName).append(" ").append(colorSpec); @@ -1100,40 +1100,12 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel public void setBackgroundColour(Color col) { viewerCommandHistory(false); - String command = "set bgColor " - + getRgbDescriptor(col, viewer.isChimeraX()); + String command = "set bgColor " + ColorUtils.toTkCode(col); viewer.sendChimeraCommand(command, false); viewerCommandHistory(true); } /** - * Answers the Chimera/X format for RGB values of the given colour. - * - *
-   * Chimera: r,g,b with values scaled [0=1]
-   * ChimeraX: rgb(r,g,b) with values scaled 0-255
-   * 
- * - * @param col - * @param chimeraX - * @return - */ - private static String getRgbDescriptor(Color col, boolean chimeraX) - { - if (chimeraX) - { - return String.format("rgb(%d,%d,%d)", col.getRed(), col.getGreen(), - col.getBlue()); - } - else - { - double scale = 255D; - return String.format("%f,%f,%f", col.getRed() / scale, - col.getGreen() / scale, col.getBlue() / scale); - } - } - - /** * Ask Chimera to save its session to the given file. Returns true if * successful, else false. * diff --git a/src/jalview/gui/AppJmol.java b/src/jalview/gui/AppJmol.java index ea7fb6b..e9c5416 100644 --- a/src/jalview/gui/AppJmol.java +++ b/src/jalview/gui/AppJmol.java @@ -604,6 +604,7 @@ public class AppJmol extends StructureViewerBase .openURL("http://jmol.sourceforge.net/docs/JmolUserGuide/"); } catch (Exception ex) { + System.err.println("Show Jmol help failed with: " + ex.getMessage()); } } diff --git a/src/jalview/gui/ChimeraViewFrame.java b/src/jalview/gui/ChimeraViewFrame.java index 520b74d..183b475 100644 --- a/src/jalview/gui/ChimeraViewFrame.java +++ b/src/jalview/gui/ChimeraViewFrame.java @@ -710,10 +710,14 @@ public class ChimeraViewFrame extends StructureViewerBase { try { - BrowserLauncher - .openURL("https://www.cgl.ucsf.edu/chimera/docs/UsersGuide"); + String url = jmb.isChimeraX() + ? "http://www.rbvi.ucsf.edu/chimerax/docs/user/index.html" + : "https://www.cgl.ucsf.edu/chimera/docs/UsersGuide"; + BrowserLauncher.openURL(url); } catch (IOException ex) { + System.err + .println("Show Chimera help failed with: " + ex.getMessage()); } } -- 1.7.10.2