JAL-2422 restore saved ChimeraX session from project
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Mon, 11 May 2020 08:32:57 +0000 (09:32 +0100)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Mon, 11 May 2020 08:32:57 +0000 (09:32 +0100)
src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java
src/jalview/gui/ChimeraXViewFrame.java
src/jalview/gui/JalviewChimeraXBindingModel.java
src/jalview/project/Jalview2XML.java

index 732fb16..476a933 100644 (file)
@@ -56,6 +56,8 @@ import jalview.structures.models.AAStructureBindingModel;
 
 public abstract class JalviewChimeraBinding extends AAStructureBindingModel
 {
+  public static final String CHIMERA_SESSION_EXTENSION = ".py";
+
   public static final String CHIMERA_FEATURE_GROUP = "Chimera";
 
   // Chimera clause to exclude alternate locations in atom selection
@@ -870,7 +872,7 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel
   @Override
   public String getSessionFileExtension()
   {
-    return ".py";
+    return CHIMERA_SESSION_EXTENSION;
   }
 
   public String getHelpURL()
index 56b2fe1..d0353f3 100644 (file)
@@ -27,6 +27,26 @@ public class ChimeraXViewFrame extends ChimeraViewFrame
     super(pdbsForFile, superposeAdded, theSeqs, ap);
   }
 
+  /**
+   * Constructor given a session file to be loaded
+   * 
+   * @param chimeraSessionFile
+   * @param alignPanel
+   * @param pdbArray
+   * @param seqsArray
+   * @param colourByChimera
+   * @param colourBySequence
+   * @param newViewId
+   */
+  public ChimeraXViewFrame(String chimeraSessionFile,
+          AlignmentPanel alignPanel, PDBEntry[] pdbArray,
+          SequenceI[][] seqsArray, boolean colourByChimera,
+          boolean colourBySequence, String newViewId)
+  {
+    super(chimeraSessionFile, alignPanel, pdbArray, seqsArray,
+            colourByChimera, colourBySequence, newViewId);
+  }
+
   @Override
   public ViewerType getViewerType()
   {
index d7b5a94..c685f0f 100644 (file)
@@ -16,6 +16,8 @@ import jalview.structure.StructureSelectionManager;
 public class JalviewChimeraXBindingModel extends JalviewChimeraBindingModel
 {
 
+  public static final String CHIMERAX_SESSION_EXTENSION = ".cxs";
+
   public JalviewChimeraXBindingModel(ChimeraViewFrame chimeraViewFrame,
           StructureSelectionManager ssm, PDBEntry[] pdbentry,
           SequenceI[][] sequenceIs, DataSourceType protocol)
@@ -65,7 +67,7 @@ public class JalviewChimeraXBindingModel extends JalviewChimeraBindingModel
   @Override
   public String getSessionFileExtension()
   {
-    return ".cxs";
+    return CHIMERAX_SESSION_EXTENSION;
   }
 
   @Override
index e7af837..b6295d9 100644 (file)
@@ -102,13 +102,16 @@ import jalview.datamodel.features.FeatureMatcher;
 import jalview.datamodel.features.FeatureMatcherI;
 import jalview.datamodel.features.FeatureMatcherSet;
 import jalview.datamodel.features.FeatureMatcherSetI;
+import jalview.ext.rbvi.chimera.JalviewChimeraBinding;
 import jalview.ext.varna.RnaModel;
 import jalview.gui.AlignFrame;
 import jalview.gui.AlignViewport;
 import jalview.gui.AlignmentPanel;
 import jalview.gui.AppVarna;
 import jalview.gui.ChimeraViewFrame;
+import jalview.gui.ChimeraXViewFrame;
 import jalview.gui.Desktop;
+import jalview.gui.JalviewChimeraXBindingModel;
 import jalview.gui.JvOptionPane;
 import jalview.gui.OOMWarning;
 import jalview.gui.PCAPanel;
@@ -4400,34 +4403,41 @@ public class Jalview2XML
      * From 2.9: stateData.type contains JMOL or CHIMERA, data is in jar entry
      * "viewer_"+stateData.viewId
      */
-    String viewerType = stateData.getType();
-    if (ViewerType.CHIMERA.toString().equals(viewerType))
-    {
-      createChimeraViewer(viewerData, af, jprovider);
-    }
-    if (ViewerType.PYMOL.toString().equals(viewerType))
+    ViewerType viewerType = ViewerType.valueOf(stateData.getType());
+    try
     {
-      createPymolViewer(viewerData, af, jprovider);
-    }
-    else
+      switch (viewerType)
+      {
+      case CHIMERA:
+        createChimeraViewer(viewerData, af, jprovider, false);
+        break;
+      case CHIMERAX:
+        createChimeraViewer(viewerData, af, jprovider, true);
+        break;
+      case PYMOL:
+        createPymolViewer(viewerData, af, jprovider);
+        break;
+      case JMOL:
+        createJmolViewer(viewerData, af, jprovider);
+      }
+    } catch (IllegalArgumentException | NullPointerException e)
     {
-      /*
-       * else Jmol (if pre-2.9, stateData contains JMOL state string)
-       */
-      createJmolViewer(viewerData, af, jprovider);
+      Cache.log.error(
+              "Invalid structure viewer type: " + stateData.getType());
     }
   }
 
   /**
-   * Create a new Chimera viewer.
+   * Create a new Chimera or ChimeraX viewer
    * 
    * @param data
    * @param af
    * @param jprovider
+   * @param isChimeraX
    */
   protected void createChimeraViewer(
           Entry<String, StructureViewerModel> viewerData, AlignFrame af,
-          jarInputStreamProvider jprovider)
+          jarInputStreamProvider jprovider, boolean isChimeraX)
   {
     StructureViewerModel data = viewerData.getValue();
     String chimeraSessionFile = data.getStateData();
@@ -4439,8 +4449,11 @@ public class Jalview2XML
      * 'uniquified' sviewid used to reconstruct the viewer here
      */
     String viewerJarEntryName = getViewerJarEntryName(data.getViewId());
+    String extension = isChimeraX
+            ? JalviewChimeraXBindingModel.CHIMERAX_SESSION_EXTENSION
+            : JalviewChimeraBinding.CHIMERA_SESSION_EXTENSION;
     chimeraSessionFile = copyJarEntry(jprovider, viewerJarEntryName,
-            "chimera", ".py");
+            "chimera", extension);
 
     Set<Entry<File, StructureData>> fileData = data.getFileData()
             .entrySet();
@@ -4466,9 +4479,13 @@ public class Jalview2XML
             .toArray(new SequenceI[allseqs.size()][]);
     String newViewId = viewerData.getKey();
 
-    ChimeraViewFrame cvf = new ChimeraViewFrame(chimeraSessionFile,
-            af.alignPanel, pdbArray, seqsArray, colourByChimera,
-            colourBySequence, newViewId);
+    ChimeraViewFrame cvf = isChimeraX
+            ? new ChimeraXViewFrame(chimeraSessionFile, af.alignPanel,
+                    pdbArray, seqsArray, colourByChimera, colourBySequence,
+                    newViewId)
+            : new ChimeraViewFrame(chimeraSessionFile, af.alignPanel,
+                    pdbArray, seqsArray, colourByChimera, colourBySequence,
+                    newViewId);
     cvf.setSize(data.getWidth(), data.getHeight());
     cvf.setLocation(data.getX(), data.getY());
   }