patch for JAL-655
[jalview.git] / src / jalview / ext / jmol / JalviewJmolBinding.java
index 09303c7..67b688c 100644 (file)
@@ -1,5 +1,5 @@
 /*
 /*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.5)
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6)
  * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
  * 
  * This file is part of Jalview.
  * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
  * 
  * This file is part of Jalview.
@@ -43,7 +43,8 @@ import org.jmol.viewer.Viewer;
 import jalview.schemes.*;
 
 public abstract class JalviewJmolBinding implements StructureListener,
 import jalview.schemes.*;
 
 public abstract class JalviewJmolBinding implements StructureListener,
-        JmolStatusListener, SequenceStructureBinding, JmolSelectionListener, ComponentListener
+        JmolStatusListener, SequenceStructureBinding,
+        JmolSelectionListener, ComponentListener
 
 {
   /**
 
 {
   /**
@@ -80,6 +81,8 @@ public abstract class JalviewJmolBinding implements StructureListener,
 
   public Vector chainNames;
 
 
   public Vector chainNames;
 
+  Hashtable chainFile;
+
   /**
    * array of target chains for seuqences - tied to pdbentry and sequence[]
    */
   /**
    * array of target chains for seuqences - tied to pdbentry and sequence[]
    */
@@ -113,7 +116,7 @@ public abstract class JalviewJmolBinding implements StructureListener,
   public PDBEntry[] pdbentry;
 
   /**
   public PDBEntry[] pdbentry;
 
   /**
-   * datasource protocol for access to PDBEntry
+   * datasource protocol for access to PDBEntrylatest
    */
   String protocol = null;
 
    */
   String protocol = null;
 
@@ -210,8 +213,9 @@ public abstract class JalviewJmolBinding implements StructureListener,
         p = mlength;
         mlength = lbl.indexOf(":", p);
       } while (p < mlength && mlength < (lbl.length() - 2));
         p = mlength;
         mlength = lbl.indexOf(":", p);
       } while (p < mlength && mlength < (lbl.length() - 2));
+      // TODO: lookup each pdb id and recover proper model number for it.
       cmd.append(":" + lbl.substring(mlength + 1) + " /"
       cmd.append(":" + lbl.substring(mlength + 1) + " /"
-              + getModelNum(lbl.substring(0, mlength)) + " or ");
+              + (1 + getModelNum((String) chainFile.get(lbl))) + " or ");
     }
     if (cmd.length() > 0)
       cmd.setLength(cmd.length() - 4);
     }
     if (cmd.length() > 0)
       cmd.setLength(cmd.length() - 4);
@@ -229,8 +233,15 @@ public abstract class JalviewJmolBinding implements StructureListener,
     viewer.setJmolStatusListener(null);
     lastCommand = null;
     viewer = null;
     viewer.setJmolStatusListener(null);
     lastCommand = null;
     viewer = null;
+    releaseUIResources();
   }
 
   }
 
+  /**
+   * called by JalviewJmolbinding after closeViewer is called - release any
+   * resources and references so they can be garbage collected.
+   */
+  protected abstract void releaseUIResources();
+
   public void colourByChain()
   {
     colourBySequence = false;
   public void colourByChain()
   {
     colourBySequence = false;
@@ -306,6 +317,7 @@ public abstract class JalviewJmolBinding implements StructureListener,
     String isel[] = new String[files.length];
     // reference structure - all others are superposed in it
     String[] targetC = new String[files.length];
     String isel[] = new String[files.length];
     // reference structure - all others are superposed in it
     String[] targetC = new String[files.length];
+    String[] chainNames = new String[files.length];
     for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++)
     {
       StructureMapping[] mapping = ssm.getMapping(files[pdbfnum]);
     for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++)
     {
       StructureMapping[] mapping = ssm.getMapping(files[pdbfnum]);
@@ -368,6 +380,7 @@ public abstract class JalviewJmolBinding implements StructureListener,
             {
               targetC[pdbfnum] = ":" + mapping[m].getChain();
             }
             {
               targetC[pdbfnum] = ":" + mapping[m].getChain();
             }
+            chainNames[pdbfnum] = mapping[m].getPdbId()+targetC[pdbfnum];
             // move on to next pdb file
             s = sequence[pdbfnum].length;
             break;
             // move on to next pdb file
             s = sequence[pdbfnum].length;
             break;
@@ -450,7 +463,12 @@ public abstract class JalviewJmolBinding implements StructureListener,
       {
         continue;
       }
       {
         continue;
       }
-      command.append("compare ");
+      command.append("echo ");
+      command.append("\"Superposing (");
+      command.append(chainNames[pdbfnum]);
+      command.append(") against reference (");
+      command.append(chainNames[refStructure]);
+      command.append(")\";\ncompare ");
       command.append("{");
       command.append(1 + pdbfnum);
       command.append(".1} {");
       command.append("{");
       command.append(1 + pdbfnum);
       command.append(".1} {");
@@ -543,7 +561,7 @@ public abstract class JalviewJmolBinding implements StructureListener,
 
               Color col = sr.getResidueBoxColour(sequence[pdbfnum][s], r);
 
 
               Color col = sr.getResidueBoxColour(sequence[pdbfnum][s], r);
 
-              if (showFeatures)
+              if (showFeatures && fr != null)
                 col = fr.findFeatureColour(col, sequence[pdbfnum][s], r);
               String newSelcom = (mapping[m].getChain() != " " ? ":"
                       + mapping[m].getChain() : "")
                 col = fr.findFeatureColour(col, sequence[pdbfnum][s], r);
               String newSelcom = (mapping[m].getChain() != " " ? ":"
                       + mapping[m].getChain() : "")
@@ -1051,6 +1069,7 @@ public abstract class JalviewJmolBinding implements StructureListener,
     String[] oldmodels = modelFileNames;
     modelFileNames = null;
     chainNames = new Vector();
     String[] oldmodels = modelFileNames;
     modelFileNames = null;
     chainNames = new Vector();
+    chainFile = new Hashtable();
     boolean notifyLoaded = false;
     String[] modelfilenames = getPdbFile();
     ssm = StructureSelectionManager.getStructureSelectionManager();
     boolean notifyLoaded = false;
     String[] modelfilenames = getPdbFile();
     ssm = StructureSelectionManager.getStructureSelectionManager();
@@ -1160,8 +1179,10 @@ public abstract class JalviewJmolBinding implements StructureListener,
             // add an entry for every chain in the model
             for (int i = 0; i < pdb.chains.size(); i++)
             {
             // add an entry for every chain in the model
             for (int i = 0; i < pdb.chains.size(); i++)
             {
-              chainNames.addElement(new String(pdb.id + ":"
-                      + ((MCview.PDBChain) pdb.chains.elementAt(i)).id));
+              String chid = new String(pdb.id + ":"
+                      + ((MCview.PDBChain) pdb.chains.elementAt(i)).id);
+              chainFile.put(chid, pdbentry[pe].getFile());
+              chainNames.addElement(chid);
             }
             notifyLoaded = true;
           }
             }
             notifyLoaded = true;
           }
@@ -1314,7 +1335,7 @@ public abstract class JalviewJmolBinding implements StructureListener,
    * @param codeBase
    * @param commandOptions
    */
    * @param codeBase
    * @param commandOptions
    */
-  public void allocateViewer(Component renderPanel, boolean jmolfileio,
+  public void allocateViewer(Container renderPanel, boolean jmolfileio,
           String htmlName, URL documentBase, URL codeBase,
           String commandOptions)
   {
           String htmlName, URL documentBase, URL codeBase,
           String commandOptions)
   {
@@ -1337,7 +1358,7 @@ public abstract class JalviewJmolBinding implements StructureListener,
    * @param buttonsToShow
    *          - buttons to show on the console, in ordr
    */
    * @param buttonsToShow
    *          - buttons to show on the console, in ordr
    */
-  public void allocateViewer(Component renderPanel, boolean jmolfileio,
+  public void allocateViewer(Container renderPanel, boolean jmolfileio,
           String htmlName, URL documentBase, URL codeBase,
           String commandOptions, final Container consolePanel,
           String buttonsToShow)
           String htmlName, URL documentBase, URL codeBase,
           String commandOptions, final Container consolePanel,
           String buttonsToShow)
@@ -1351,9 +1372,8 @@ public abstract class JalviewJmolBinding implements StructureListener,
     if (consolePanel != null)
     {
       consolePanel.addComponentListener(this);
     if (consolePanel != null)
     {
       consolePanel.addComponentListener(this);
-      
-    }
 
 
+    }
 
   }
 
 
   }
 
@@ -1362,30 +1382,25 @@ public abstract class JalviewJmolBinding implements StructureListener,
 
   protected org.jmol.api.JmolAppConsoleInterface console = null;
 
 
   protected org.jmol.api.JmolAppConsoleInterface console = null;
 
-@Override
-public void componentResized(ComponentEvent e)
-{
-  
-}
+  public void componentResized(ComponentEvent e)
+  {
 
 
-@Override
-public void componentMoved(ComponentEvent e)
-{
-  
-}
+  }
 
 
-@Override
-public void componentShown(ComponentEvent e)
-{
-  showConsole(true);
-}
+  public void componentMoved(ComponentEvent e)
+  {
 
 
-@Override
-public void componentHidden(ComponentEvent e)
-{
-  showConsole(false);
-}
+  }
 
 
+  public void componentShown(ComponentEvent e)
+  {
+    showConsole(true);
+  }
+
+  public void componentHidden(ComponentEvent e)
+  {
+    showConsole(false);
+  }
 
   public void setLoadingFromArchive(boolean loadingFromArchive)
   {
 
   public void setLoadingFromArchive(boolean loadingFromArchive)
   {