JAL-3390 first pass refactoring for JalviewJmolBinding.showStructures
[jalview.git] / src / jalview / ext / jmol / JalviewJmolBinding.java
index d317722..8cecf6e 100644 (file)
@@ -27,13 +27,13 @@ import jalview.datamodel.AlignmentI;
 import jalview.datamodel.HiddenColumns;
 import jalview.datamodel.PDBEntry;
 import jalview.datamodel.SequenceI;
+import jalview.ext.rbvi.chimera.AtomSpecModel;
 import jalview.gui.IProgressIndicator;
 import jalview.io.DataSourceType;
 import jalview.io.StructureFile;
 import jalview.schemes.ColourSchemeI;
 import jalview.schemes.ResidueProperties;
 import jalview.structure.AtomSpec;
-import jalview.structure.StructureMappingcommandSet;
 import jalview.structure.StructureSelectionManager;
 import jalview.structures.models.AAStructureBindingModel;
 import jalview.util.MessageManager;
@@ -476,14 +476,14 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel
   }
 
   Thread colourby = null;
+  
   /**
    * Sends a set of colour commands to the structure viewer
    * 
-   * @param colourBySequenceCommands
+   * @param commands
    */
   @Override
-  protected void colourBySequence(
-          final StructureMappingcommandSet[] colourBySequenceCommands)
+  protected void colourBySequence(final String[] commands)
   {
     if (colourby != null)
     {
@@ -495,12 +495,9 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel
       @Override
       public void run()
       {
-        for (StructureMappingcommandSet cpdbbyseq : colourBySequenceCommands)
+        for (String cmd : commands)
         {
-          for (String cbyseq : cpdbbyseq.commands)
-          {
-            executeWhenReady(cbyseq);
-          }
+          executeWhenReady(cmd);
         }
       }
     });
@@ -513,11 +510,12 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel
    * @return
    */
   @Override
-  protected StructureMappingcommandSet[] getColourBySequenceCommands(
+  protected String[] getColourBySequenceCommands(
           String[] files, AlignmentViewPanel viewPanel)
   {
-    return JmolCommands.getColourBySequenceCommand(getSsm(), files,
-            this, viewPanel);
+    Map<Object, AtomSpecModel> map = buildColoursMap(viewPanel);
+
+    return JmolCommands.getColourBySequenceCommand(map);
   }
 
   /**
@@ -1417,7 +1415,36 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel
   @Override
   public void showStructures(AlignViewportI av, boolean refocus)
   {
-    // TODO show Jmol structure optionally restricted to visible alignment
-    // and/or selected chains
+    StringBuilder cmd = new StringBuilder(128);
+
+    if (isShowAlignmentOnly())
+    {
+      cmd.append("hide *;");
+
+    AtomSpecModel model = getShownResidues(av);
+    String atomSpec = JmolCommands.getAtomSpec(model);
+
+    cmd.append("display ").append(atomSpec);
+    }
+    else
+    {
+      cmd.append("display *");
+    }
+    cmd.append("; cartoon");
+    if (refocus)
+    {
+      cmd.append("; zoom 100");
+    }
+    evalStateCommand(cmd.toString());
+  }
+
+  /**
+   * Answers a Jmol syntax style structure model specification. Model number 0, 1,
+   * 2... is formatted as "1.1", "2.1", "3.1" etc.
+   */
+  @Override
+  public String getModelSpec(int model)
+  {
+    return String.valueOf(model + 1) + ".1";
   }
 }