2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import jalview.api.structures.JalviewStructureDisplayI;
24 import jalview.bin.Cache;
25 import jalview.datamodel.PDBEntry;
26 import jalview.datamodel.SequenceI;
27 import jalview.datamodel.StructureViewerModel;
28 import jalview.structure.StructureSelectionManager;
30 import java.awt.Rectangle;
31 import java.util.ArrayList;
32 import java.util.List;
35 * proxy for handling structure viewers.
37 * this allows new views to be created with the currently configured viewer, the
38 * preferred viewer to be set/read and existing views created previously with a
39 * particular viewer to be recovered
43 public class StructureViewer
45 StructureSelectionManager ssm;
47 public enum ViewerType
52 public ViewerType getViewerType()
54 String viewType = Cache.getDefault(Preferences.STRUCTURE_DISPLAY,
55 ViewerType.JMOL.name());
56 return ViewerType.valueOf(viewType);
59 public void setViewerType(ViewerType type)
61 Cache.setProperty(Preferences.STRUCTURE_DISPLAY, type.name());
64 public StructureViewer(StructureSelectionManager structureSelectionManager)
66 ssm = structureSelectionManager;
70 * View multiple PDB entries, each with associated sequences
77 public JalviewStructureDisplayI viewStructures(PDBEntry[] pdbs,
78 SequenceI[][] seqsForPdbs, AlignmentPanel ap)
80 JalviewStructureDisplayI viewer = onlyOnePdb(pdbs, seqsForPdbs, ap);
85 return viewStructures(getViewerType(), pdbs, seqsForPdbs, ap);
89 * A strictly temporary method pending JAL-1761 refactoring. Determines if all
90 * the passed PDB entries are the same (this is the case if selected sequences
91 * to view structure for are chains of the same structure). If so, calls the
92 * single-pdb version of viewStructures and returns the viewer, else returns
100 private JalviewStructureDisplayI onlyOnePdb(PDBEntry[] pdbs,
101 SequenceI[][] seqsForPdbs, AlignmentPanel ap)
103 List<SequenceI> seqs = new ArrayList<SequenceI>();
104 if (pdbs == null || pdbs.length == 0)
109 String firstFile = pdbs[0].getFile();
110 for (PDBEntry pdb : pdbs)
112 String pdbFile = pdb.getFile();
113 if (pdbFile == null || !pdbFile.equals(firstFile))
117 SequenceI[] pdbseqs = seqsForPdbs[i++];
120 for (SequenceI sq : pdbseqs)
126 return viewStructures(pdbs[0],
127 seqs.toArray(new SequenceI[seqs.size()]), ap);
130 public JalviewStructureDisplayI viewStructures(PDBEntry pdb,
131 SequenceI[] seqsForPdb, AlignmentPanel ap)
133 return viewStructures(getViewerType(), pdb, seqsForPdb, ap);
136 protected JalviewStructureDisplayI viewStructures(ViewerType viewerType,
137 PDBEntry[] pdbs, SequenceI[][] seqsForPdbs, AlignmentPanel ap)
139 PDBEntry[] pdbsForFile = getUniquePdbFiles(pdbs);
140 JalviewStructureDisplayI sview = null;
141 if (viewerType.equals(ViewerType.JMOL))
143 sview = new AppJmol(ap, pdbsForFile, ap.av.collateForPDB(pdbsForFile));
145 else if (viewerType.equals(ViewerType.CHIMERA))
147 sview = new ChimeraViewFrame(pdbsForFile,
148 ap.av.collateForPDB(pdbsForFile), ap);
152 Cache.log.error("Unknown structure viewer type "
153 + getViewerType().toString());
159 * Convert the array of PDBEntry into an array with no filename repeated
164 static PDBEntry[] getUniquePdbFiles(PDBEntry[] pdbs)
170 List<PDBEntry> uniques = new ArrayList<PDBEntry>();
171 List<String> filesSeen = new ArrayList<String>();
172 for (PDBEntry entry : pdbs)
174 String file = entry.getFile();
179 else if (!filesSeen.contains(file))
185 return uniques.toArray(new PDBEntry[uniques.size()]);
188 protected JalviewStructureDisplayI viewStructures(ViewerType viewerType,
189 PDBEntry pdb, SequenceI[] seqsForPdb, AlignmentPanel ap)
191 JalviewStructureDisplayI sview = null;
192 if (viewerType.equals(ViewerType.JMOL))
194 sview = new AppJmol(pdb, seqsForPdb, null, ap);
196 else if (viewerType.equals(ViewerType.CHIMERA))
198 sview = new ChimeraViewFrame(pdb, seqsForPdb, null, ap);
202 Cache.log.error("Unknown structure viewer type "
203 + getViewerType().toString());
209 * Create a new panel controlling a structure viewer.
222 public JalviewStructureDisplayI createView(ViewerType type,
223 String[] pdbf, String[] id, SequenceI[][] sq,
224 AlignmentPanel alignPanel, StructureViewerModel viewerData,
225 String fileloc, Rectangle rect, String vid)
227 final boolean useinViewerSuperpos = viewerData.isAlignWithPanel();
228 final boolean usetoColourbyseq = viewerData.isColourWithAlignPanel();
229 final boolean viewerColouring = viewerData.isColourByViewer();
231 JalviewStructureDisplayI sview = null;
235 sview = new AppJmol(pdbf, id, sq, alignPanel, usetoColourbyseq,
236 useinViewerSuperpos, viewerColouring, fileloc, rect, vid);
239 Cache.log.error("Unsupported structure viewer type "
243 Cache.log.error("Unknown structure viewer type " + type.toString());