JAL-3518 basic refactoring / pull up of superposeStructures; to tidy!
[jalview.git] / src / jalview / ext / rbvi / chimera / JalviewChimeraBinding.java
index be1de5a..731ffea 100644 (file)
@@ -30,11 +30,11 @@ 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.structure.AtomSpec;
+import jalview.structure.StructureCommandsI.SuperposeData;
 import jalview.structure.StructureSelectionManager;
 import jalview.structures.models.AAStructureBindingModel;
 import jalview.util.MessageManager;
@@ -184,11 +184,16 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel
   {
     super(ssm, pdbentry, sequenceIs, protocol);
     chimeraManager = new ChimeraManager(new StructureManager(true));
-    String viewerType = Cache.getProperty(Preferences.STRUCTURE_DISPLAY);
-    chimeraManager.setChimeraX(ViewerType.CHIMERAX.name().equals(viewerType));
+    chimeraManager.setChimeraX(ViewerType.CHIMERAX.equals(getViewerType()));
     setStructureCommands(new ChimeraCommands());
   }
 
+  @Override
+  protected ViewerType getViewerType()
+  {
+    return ViewerType.CHIMERA;
+  }
+
   /**
    * Starts a thread that waits for the Chimera process to finish, so that we can
    * then close the associated resources. This avoids leaving orphaned Chimera
@@ -265,7 +270,6 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel
   /**
    * {@inheritDoc}
    */
-  @Override
   public String superposeStructures(AlignmentI[] _alignment,
           int[] _refStructure, HiddenColumns[] _hiddenCols)
   {
@@ -309,7 +313,7 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel
       SuperposeData[] structures = new SuperposeData[files.length];
       for (int f = 0; f < files.length; f++)
       {
-        structures[f] = new SuperposeData(alignment.getWidth());
+        structures[f] = new SuperposeData(alignment.getWidth(), f);
       }
 
       /*
@@ -519,8 +523,8 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel
       }
       else
       {
-        allComs.append("chain @CA|P; ribbon ; focus");
-        allComs.append(selectioncom.toString());
+        allComs.append("chain @CA|P; ribbon ");
+        allComs.append(selectioncom.toString()).append("; focus");
       }
       // allComs.append("; ~display all; chain @CA|P; ribbon ")
       // .append(selectioncom.toString()).append("; focus");
@@ -647,16 +651,6 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel
   }
 
   /**
-   * Send a Chimera command asynchronously in a new thread. If the progress
-   * message is not null, display this message while the command is executing.
-   * 
-   * @param command
-   * @param progressMsg
-   */
-  protected abstract void sendAsynchronousCommand(String command,
-          String progressMsg);
-
-  /**
    * @param command
    */
   protected void executeWhenReady(String command)
@@ -862,7 +856,7 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel
        * Chimera:  https://www.cgl.ucsf.edu/chimera/current/docs/UsersGuide/midas/save.html
        * ChimeraX: https://www.cgl.ucsf.edu/chimerax/docs/user/commands/save.html
        */
-      String command = getSaveSessionCommand(filepath);
+      String command = getCommandGenerator().saveSession(filepath);
       List<String> reply = chimeraManager.sendChimeraCommand(command, true);
       if (reply.contains("Session written"))
       {
@@ -878,17 +872,6 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel
   }
 
   /**
-   * Returns the command to save the viewer session to the given file path
-   * 
-   * @param filepath
-   * @return
-   */
-  protected String getSaveSessionCommand(String filepath)
-  {
-    return "save " + filepath;
-  }
-
-  /**
    * Ask Chimera to open a session file. Returns true if successful, else false.
    * The filename must have a .py (Chimera) or .cxs (ChimeraX) extension for
    * this command to work.
@@ -988,7 +971,7 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel
       out.flush();
       out.close();
       String path = tmp.getAbsolutePath();
-      String command = getOpenCommandFileCommand(path);
+      String command = getCommandGenerator().openCommandFile(path);
       sendAsynchronousCommand(command, null);
     } catch (IOException e)
     {
@@ -998,18 +981,6 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel
   }
 
   /**
-   * Returns the command for the structure viewer to open a file of commands at
-   * the given file path
-   * 
-   * @param path
-   * @return
-   */
-  protected String getOpenCommandFileCommand(String path)
-  {
-    return "open cmd:" + path;
-  }
-
-  /**
    * Returns the file extension required for a file of commands to be read by
    * the structure viewer
    * @return