JAL-2422 ChimeraX added to Preferences
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Tue, 28 Jan 2020 12:00:35 +0000 (12:00 +0000)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Tue, 28 Jan 2020 12:00:35 +0000 (12:00 +0000)
resources/lang/Messages.properties
src/ext/edu/ucsf/rbvi/strucviz2/ChimeraManager.java
src/ext/edu/ucsf/rbvi/strucviz2/StructureManager.java
src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java
src/jalview/gui/Preferences.java
src/jalview/gui/StructureViewer.java
src/jalview/jbgui/GPreferences.java
test/jalview/ext/rbvi/chimera/ChimeraConnect.java

index fdd15cd..3ead942 100644 (file)
@@ -265,7 +265,7 @@ label.autoadd_secstr = Add secondary structure annotation to alignment
 label.autoadd_temp = Add Temperature Factor annotation to alignment
 label.structure_viewer = Default structure viewer
 label.double_click_to_browse = Double-click to browse for file
-label.chimera_path = Path to Chimera program
+label.chimera_path = Path to Chimera(X) program
 label.chimera_path_tip = Jalview will first try any path entered here, else standard installation locations.<br>Double-click to browse for file.
 label.invalid_chimera_path = Chimera path not found or not executable
 label.chimera_missing = Chimera structure viewer not found.<br/>Please enter the path to Chimera (if installed),<br/>or download and install UCSF Chimera.
index 1a8bd76..216c06c 100644 (file)
@@ -432,7 +432,7 @@ public class ChimeraManager
     List<String> selectedResidues = new ArrayList<>();
 
     /*
-     * skip for now if ChimeraX - times out
+     * skip for now if ChimeraX - request times out
      */
     if (isChimeraX)
     {
@@ -962,4 +962,9 @@ public class ChimeraManager
   {
     return isChimeraX;
   }
+
+  public void setChimeraX(boolean b)
+  {
+    isChimeraX = b;
+  }
 }
index 22c9098..b7ea4ad 100644 (file)
@@ -896,7 +896,7 @@ public class StructureManager
   StructureSettings defaultSettings = null;
 
   // TODO: [Optional] Change priority of Chimera paths
-  public static List<String> getChimeraPaths()
+  public static List<String> getChimeraPaths(boolean isChimeraX)
   {
     List<String> pathList = new ArrayList<>();
 
@@ -918,20 +918,25 @@ public class StructureManager
     /*
      * Jalview addition: check if path set in user preferences.
      */
-    String userPath = Cache.getDefault(Preferences.CHIMERA_PATH, null);
+    String userPath = Cache
+            .getDefault(isChimeraX ? Preferences.CHIMERAX_PATH
+                    : Preferences.CHIMERA_PATH, null);
     if (userPath != null)
     {
       pathList.add(0, userPath);
     }
 
+    // FIXME get an updated StructureManager for code for ChimeraX paths
+    String chimera = isChimeraX ? "ChimeraX" : "chimera";
+
     // Add default installation paths
     String os = System.getProperty("os.name");
     if (os.startsWith("Linux"))
     {
-      pathList.add("/usr/local/chimera/bin/chimera");
-      pathList.add("/usr/local/bin/chimera");
-      pathList.add("/usr/bin/chimera");
-      pathList.add(System.getProperty("user.home") + "/opt/bin/chimera");
+      pathList.add("/usr/local/chimera/bin/" + chimera);
+      pathList.add("/usr/local/bin/" + chimera);
+      pathList.add("/usr/bin/" + chimera);
+      pathList.add(System.getProperty("user.home") + "/opt/bin/" + chimera);
     }
     else if (os.startsWith("Windows"))
     {
@@ -942,15 +947,16 @@ public class StructureManager
         for (String version : new String[] { "1.11", "1.11.1", "1.11.2",
             "1.12", "1.12.1", "1.12.2", "1.13" })
         {
-          pathList.add(root + "\\Chimera " + version + "\\bin\\chimera");
+          pathList.add(root + "\\Chimera " + version + "\\bin\\" + chimera);
           pathList.add(
-                  root + "\\Chimera " + version + "\\bin\\chimera.exe");
+                  root + "\\Chimera " + version + "\\bin\\" + chimera
+                          + ".exe");
         }
       }
     }
     else if (os.startsWith("Mac"))
     {
-      pathList.add("/Applications/Chimera.app/Contents/MacOS/chimera");
+      pathList.add("/Applications/Chimera.app/Contents/MacOS/" + chimera);
     }
     return pathList;
   }
index 6e02efe..5d61b86 100644 (file)
@@ -31,6 +31,8 @@ import jalview.datamodel.SearchResultMatchI;
 import jalview.datamodel.SearchResultsI;
 import jalview.datamodel.SequenceFeature;
 import jalview.datamodel.SequenceI;
+import jalview.gui.Preferences;
+import jalview.gui.StructureViewer.ViewerType;
 import jalview.httpserver.AbstractRequestHandler;
 import jalview.io.DataSourceType;
 import jalview.schemes.ColourSchemeI;
@@ -218,6 +220,9 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel
   {
     super(ssm, pdbentry, sequenceIs, protocol);
     viewer = new ChimeraManager(new StructureManager(true));
+    String viewerType = Cache.getProperty(Preferences.STRUCTURE_DISPLAY);
+    viewer.setChimeraX(ViewerType.CHIMERAX.name().equals(viewerType));
+
   }
 
   /**
@@ -676,8 +681,8 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel
       return true;
     }
 
-    boolean launched = viewer
-            .launchChimera(StructureManager.getChimeraPaths());
+    boolean launched = viewer.launchChimera(
+            StructureManager.getChimeraPaths(viewer.isChimeraX()));
     if (launched)
     {
       startChimeraProcessMonitor();
index 9754e0d..abe175b 100755 (executable)
@@ -105,6 +105,8 @@ public class Preferences extends GPreferences
 
   public static final String CHIMERA_PATH = "CHIMERA_PATH";
 
+  public static final String CHIMERAX_PATH = "CHIMERAX_PATH";
+
   public static final String SORT_ANNOTATIONS = "SORT_ANNOTATIONS";
 
   public static final String SHOW_AUTOCALC_ABOVE = "SHOW_AUTOCALC_ABOVE";
@@ -340,15 +342,30 @@ public class Preferences extends GPreferences
     addSecondaryStructure.setEnabled(structSelected);
     addTempFactor.setSelected(Cache.getDefault(ADD_TEMPFACT_ANN, false));
     addTempFactor.setEnabled(structSelected);
-    structViewer.setSelectedItem(
-            Cache.getDefault(STRUCTURE_DISPLAY, ViewerType.JMOL.name()));
-    chimeraPath.setText(Cache.getDefault(CHIMERA_PATH, ""));
+    String viewerType = Cache.getDefault(STRUCTURE_DISPLAY, ViewerType.JMOL.name());
+    structViewer.setSelectedItem(viewerType);
+    boolean isChimeraX = viewerType.equals(ViewerType.CHIMERAX.name());
+    if (viewerType.equals(ViewerType.JMOL.name()))
+    {
+      chimeraPath.setText("");
+    }
+    else
+    {
+      chimeraPath.setText(Cache
+              .getDefault(isChimeraX ? CHIMERAX_PATH : CHIMERA_PATH, ""));
+    }
     chimeraPath.addActionListener(new ActionListener()
     {
       @Override
       public void actionPerformed(ActionEvent e)
       {
-        validateChimeraPath();
+        if (validateChimeraPath())
+        {
+          Cache.setProperty(structViewer.getSelectedItem()
+                  .equals(ViewerType.CHIMERAX.name())
+                  ? CHIMERAX_PATH
+                  : CHIMERA_PATH, chimeraPath.getText());
+        }
       }
     });
 
@@ -401,7 +418,7 @@ public class Preferences extends GPreferences
     doReset.addActionListener(onReset);
 
     // filter to display only custom urls
-    final RowFilter<TableModel, Object> customUrlFilter = new RowFilter<TableModel, Object>()
+    final RowFilter<TableModel, Object> customUrlFilter = new RowFilter<>()
     {
       @Override
       public boolean include(
@@ -682,7 +699,10 @@ public class Preferences extends GPreferences
             Boolean.toString(structFromPdb.isSelected()));
     Cache.applicationProperties.setProperty(STRUCTURE_DISPLAY,
             structViewer.getSelectedItem().toString());
-    Cache.setOrRemove(CHIMERA_PATH, chimeraPath.getText());
+    boolean isChimeraX = structViewer.getSelectedItem().toString()
+            .equals(ViewerType.CHIMERAX.name());
+    Cache.setOrRemove(isChimeraX ? CHIMERAX_PATH : CHIMERA_PATH,
+            chimeraPath.getText());
     Cache.applicationProperties.setProperty("MAP_WITH_SIFTS",
             Boolean.toString(siftsMapping.isSelected()));
     SiftsSettings.setMapWithSifts(siftsMapping.isSelected());
@@ -1208,22 +1228,28 @@ public class Preferences extends GPreferences
   }
 
   /**
-   * If Chimera is selected, check it can be found on default or user-specified
-   * path, if not show a warning/help dialog.
+   * If Chimera or ChimeraX is selected, check it can be found on default or
+   * user-specified path, if not show a warning/help dialog.
    */
   @Override
   protected void structureViewer_actionPerformed(String selectedItem)
   {
-    if (!selectedItem.equals(ViewerType.CHIMERA.name()))
+    if (selectedItem.equals(ViewerType.JMOL.name()))
     {
+      chimeraPath.setEnabled(false);
       return;
     }
     boolean found = false;
+    chimeraPath.setEnabled(true);
 
     /*
      * Try user-specified and standard paths for Chimera executable.
      */
-    List<String> paths = StructureManager.getChimeraPaths();
+    boolean isChimeraX = selectedItem.equals(ViewerType.CHIMERAX.name());
+    chimeraPath.setText(Cache
+            .getDefault(isChimeraX ? CHIMERAX_PATH : CHIMERA_PATH, ""));
+
+    List<String> paths = StructureManager.getChimeraPaths(isChimeraX);
     paths.add(0, chimeraPath.getText());
     for (String path : paths)
     {
index 0c8354b..c8012a6 100644 (file)
@@ -56,7 +56,7 @@ public class StructureViewer
 
   public enum ViewerType
   {
-    JMOL, CHIMERA
+    JMOL, CHIMERA, CHIMERAX
   };
 
   /**
@@ -160,7 +160,8 @@ public class StructureViewer
     {
       sview = new AppJmol(ap, superposeAdded, pdbsForFile, theSeqs);
     }
-    else if (viewerType.equals(ViewerType.CHIMERA))
+    else if (viewerType.equals(ViewerType.CHIMERA)
+            || viewerType.equals(ViewerType.CHIMERAX))
     {
       sview = new ChimeraViewFrame(pdbsForFile, superposeAdded, theSeqs,
               ap);
@@ -301,7 +302,8 @@ public class StructureViewer
     {
       sview = new AppJmol(pdb, seqsForPdb, null, ap);
     }
-    else if (viewerType.equals(ViewerType.CHIMERA))
+    else if (viewerType.equals(ViewerType.CHIMERA)
+            || viewerType.equals(ViewerType.CHIMERAX))
     {
       sview = new ChimeraViewFrame(pdb, seqsForPdb, null, ap);
     }
index 0bc5d28..5456935 100755 (executable)
@@ -1195,7 +1195,7 @@ public class GPreferences extends JPanel
     structureTab.setBorder(new TitledBorder(
             MessageManager.getString("label.structure_options")));
     structureTab.setLayout(null);
-    final int width = 400;
+    final int width = 420;
     final int height = 22;
     final int lineSpacing = 25;
     int ypos = 15;
@@ -1243,13 +1243,14 @@ public class GPreferences extends JPanel
     viewerLabel.setFont(LABEL_FONT);
     viewerLabel.setHorizontalAlignment(SwingConstants.LEFT);
     viewerLabel.setText(MessageManager.getString("label.structure_viewer"));
-    viewerLabel.setBounds(new Rectangle(10, ypos, 200, height));
+    viewerLabel.setBounds(new Rectangle(10, ypos, 220, height));
     structureTab.add(viewerLabel);
 
     structViewer.setFont(LABEL_FONT);
-    structViewer.setBounds(new Rectangle(160, ypos, 120, height));
+    structViewer.setBounds(new Rectangle(180, ypos, 120, height));
     structViewer.addItem(ViewerType.JMOL.name());
     structViewer.addItem(ViewerType.CHIMERA.name());
+    structViewer.addItem(ViewerType.CHIMERAX.name());
     structViewer.addActionListener(new ActionListener()
     {
       @Override
@@ -1266,7 +1267,7 @@ public class GPreferences extends JPanel
     pathLabel.setFont(new java.awt.Font("SansSerif", 0, 11));
     pathLabel.setHorizontalAlignment(SwingConstants.LEFT);
     pathLabel.setText(MessageManager.getString("label.chimera_path"));
-    pathLabel.setBounds(new Rectangle(10, ypos, 140, height));
+    pathLabel.setBounds(new Rectangle(10, ypos, 160, height));
     structureTab.add(pathLabel);
 
     chimeraPath.setFont(LABEL_FONT);
@@ -1274,7 +1275,7 @@ public class GPreferences extends JPanel
     final String tooltip = JvSwingUtils.wrapTooltip(true,
             MessageManager.getString("label.chimera_path_tip"));
     chimeraPath.setToolTipText(tooltip);
-    chimeraPath.setBounds(new Rectangle(160, ypos, 300, height));
+    chimeraPath.setBounds(new Rectangle(180, ypos, 300, height));
     chimeraPath.addMouseListener(new MouseAdapter()
     {
       @Override
@@ -1305,7 +1306,7 @@ public class GPreferences extends JPanel
             MessageManager.getString("label.mapping_method"));
     mmTitledBorder.setTitleFont(LABEL_FONT);
     mappingPanel.setBorder(mmTitledBorder);
-    mappingPanel.setBounds(new Rectangle(10, ypos, 452, 45));
+    mappingPanel.setBounds(new Rectangle(10, ypos, 472, 45));
     // GridLayout mappingLayout = new GridLayout();
     mappingPanel.setLayout(new GridLayout());
     mappingPanel.add(nwMapping);
@@ -1316,7 +1317,7 @@ public class GPreferences extends JPanel
     ypos += lineSpacing;
     FTSDataColumnPreferences docFieldPref = new FTSDataColumnPreferences(
             PreferenceSource.PREFERENCES, PDBFTSRestClient.getInstance());
-    docFieldPref.setBounds(new Rectangle(10, ypos, 450, 120));
+    docFieldPref.setBounds(new Rectangle(10, ypos, 470, 120));
     structureTab.add(docFieldPref);
 
     return structureTab;
index 99394dc..b07a622 100644 (file)
@@ -47,7 +47,7 @@ public class ChimeraConnect
     final StructureManager structureManager = new StructureManager(true);
     ChimeraManager cm = new ChimeraManager(structureManager);
     assertTrue("Couldn't launch chimera",
-            cm.launchChimera(StructureManager.getChimeraPaths()));
+            cm.launchChimera(StructureManager.getChimeraPaths(false)));
     assertTrue(cm.isChimeraLaunched()); // Chimera process is alive
     // int n=0;
     // not sure of the point of this is unless the tester is loading models