JAL-2089 patch broken merge to master for Release 2.10.0b1
[jalview.git] / src / jalview / gui / StructureViewer.java
index 2285765..189d490 100644 (file)
  */
 package jalview.gui;
 
-import java.awt.Rectangle;
-import java.util.ArrayList;
-import java.util.List;
-
 import jalview.api.structures.JalviewStructureDisplayI;
 import jalview.bin.Cache;
 import jalview.datamodel.PDBEntry;
@@ -31,6 +27,10 @@ import jalview.datamodel.SequenceI;
 import jalview.datamodel.StructureViewerModel;
 import jalview.structure.StructureSelectionManager;
 
+import java.awt.Rectangle;
+import java.util.ArrayList;
+import java.util.List;
+
 /**
  * proxy for handling structure viewers.
  * 
@@ -98,8 +98,7 @@ public class StructureViewer
    * @return
    */
   private JalviewStructureDisplayI onlyOnePdb(PDBEntry[] pdbs,
-          SequenceI[][] seqsForPdbs,
-          AlignmentPanel ap)
+          SequenceI[][] seqsForPdbs, AlignmentPanel ap)
   {
     List<SequenceI> seqs = new ArrayList<SequenceI>();
     if (pdbs == null || pdbs.length == 0)
@@ -137,14 +136,16 @@ public class StructureViewer
   protected JalviewStructureDisplayI viewStructures(ViewerType viewerType,
           PDBEntry[] pdbs, SequenceI[][] seqsForPdbs, AlignmentPanel ap)
   {
+    PDBEntry[] pdbsForFile = getUniquePdbFiles(pdbs);
     JalviewStructureDisplayI sview = null;
     if (viewerType.equals(ViewerType.JMOL))
     {
-      sview = new AppJmol(ap, pdbs, ap.av.collateForPDB(pdbs));
+      sview = new AppJmol(ap, pdbsForFile, ap.av.collateForPDB(pdbsForFile));
     }
     else if (viewerType.equals(ViewerType.CHIMERA))
     {
-      sview = new ChimeraViewFrame(pdbs, ap.av.collateForPDB(pdbs), ap);
+      sview = new ChimeraViewFrame(pdbsForFile,
+              ap.av.collateForPDB(pdbsForFile), ap);
     }
     else
     {
@@ -154,6 +155,36 @@ public class StructureViewer
     return sview;
   }
 
+  /**
+   * Convert the array of PDBEntry into an array with no filename repeated
+   * 
+   * @param pdbs
+   * @return
+   */
+  static PDBEntry[] getUniquePdbFiles(PDBEntry[] pdbs)
+  {
+    if (pdbs == null)
+    {
+      return null;
+    }
+    List<PDBEntry> uniques = new ArrayList<PDBEntry>();
+    List<String> filesSeen = new ArrayList<String>();
+    for (PDBEntry entry : pdbs)
+    {
+      String file = entry.getFile();
+      if (file == null)
+      {
+        uniques.add(entry);
+      }
+      else if (!filesSeen.contains(file))
+      {
+        uniques.add(entry);
+        filesSeen.add(file);
+      }
+    }
+    return uniques.toArray(new PDBEntry[uniques.size()]);
+  }
+
   protected JalviewStructureDisplayI viewStructures(ViewerType viewerType,
           PDBEntry pdb, SequenceI[] seqsForPdb, AlignmentPanel ap)
   {
@@ -190,8 +221,8 @@ public class StructureViewer
    */
   public JalviewStructureDisplayI createView(ViewerType type,
           String[] pdbf, String[] id, SequenceI[][] sq,
-          AlignmentPanel alignPanel, StructureViewerModel viewerData, String fileloc,
-          Rectangle rect, String vid)
+          AlignmentPanel alignPanel, StructureViewerModel viewerData,
+          String fileloc, Rectangle rect, String vid)
   {
     final boolean useinViewerSuperpos = viewerData.isAlignWithPanel();
     final boolean usetoColourbyseq = viewerData.isColourWithAlignPanel();