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(
65 StructureSelectionManager structureSelectionManager)
67 ssm = structureSelectionManager;
71 * View multiple PDB entries, each with associated sequences
78 public JalviewStructureDisplayI viewStructures(PDBEntry[] pdbs,
79 SequenceI[][] seqsForPdbs, AlignmentPanel ap)
81 JalviewStructureDisplayI viewer = onlyOnePdb(pdbs, seqsForPdbs, ap);
86 return viewStructures(getViewerType(), pdbs, seqsForPdbs, ap);
90 * A strictly temporary method pending JAL-1761 refactoring. Determines if all
91 * the passed PDB entries are the same (this is the case if selected sequences
92 * to view structure for are chains of the same structure). If so, calls the
93 * single-pdb version of viewStructures and returns the viewer, else returns
101 private JalviewStructureDisplayI onlyOnePdb(PDBEntry[] pdbs,
102 SequenceI[][] seqsForPdbs, AlignmentPanel ap)
104 List<SequenceI> seqs = new ArrayList<SequenceI>();
105 if (pdbs == null || pdbs.length == 0)
110 String firstFile = pdbs[0].getFile();
111 for (PDBEntry pdb : pdbs)
113 String pdbFile = pdb.getFile();
114 if (pdbFile == null || !pdbFile.equals(firstFile))
118 SequenceI[] pdbseqs = seqsForPdbs[i++];
121 for (SequenceI sq : pdbseqs)
127 return viewStructures(pdbs[0], seqs.toArray(new SequenceI[seqs.size()]),
131 public JalviewStructureDisplayI viewStructures(PDBEntry pdb,
132 SequenceI[] seqsForPdb, AlignmentPanel ap)
134 return viewStructures(getViewerType(), pdb, seqsForPdb, ap);
137 protected JalviewStructureDisplayI viewStructures(ViewerType viewerType,
138 PDBEntry[] pdbs, SequenceI[][] seqsForPdbs, AlignmentPanel ap)
140 PDBEntry[] pdbsForFile = getUniquePdbFiles(pdbs);
141 JalviewStructureDisplayI sview = null;
142 if (viewerType.equals(ViewerType.JMOL))
144 sview = new AppJmol(ap, pdbsForFile,
145 ap.av.collateForPDB(pdbsForFile));
147 else if (viewerType.equals(ViewerType.CHIMERA))
149 sview = new ChimeraViewFrame(pdbsForFile,
150 ap.av.collateForPDB(pdbsForFile), ap);
154 Cache.log.error("Unknown structure viewer type "
155 + getViewerType().toString());
161 * Convert the array of PDBEntry into an array with no filename repeated
166 static PDBEntry[] getUniquePdbFiles(PDBEntry[] pdbs)
172 List<PDBEntry> uniques = new ArrayList<PDBEntry>();
173 List<String> filesSeen = new ArrayList<String>();
174 for (PDBEntry entry : pdbs)
176 String file = entry.getFile();
181 else if (!filesSeen.contains(file))
187 return uniques.toArray(new PDBEntry[uniques.size()]);
190 protected JalviewStructureDisplayI viewStructures(ViewerType viewerType,
191 PDBEntry pdb, SequenceI[] seqsForPdb, AlignmentPanel ap)
193 JalviewStructureDisplayI sview = null;
194 if (viewerType.equals(ViewerType.JMOL))
196 sview = new AppJmol(pdb, seqsForPdb, null, ap);
198 else if (viewerType.equals(ViewerType.CHIMERA))
200 sview = new ChimeraViewFrame(pdb, seqsForPdb, null, ap);
204 Cache.log.error("Unknown structure viewer type "
205 + getViewerType().toString());
211 * Create a new panel controlling a structure viewer.
224 public JalviewStructureDisplayI createView(ViewerType type, String[] pdbf,
225 String[] id, SequenceI[][] sq, AlignmentPanel alignPanel,
226 StructureViewerModel viewerData, String fileloc, Rectangle rect,
229 final boolean useinViewerSuperpos = viewerData.isAlignWithPanel();
230 final boolean usetoColourbyseq = viewerData.isColourWithAlignPanel();
231 final boolean viewerColouring = viewerData.isColourByViewer();
233 JalviewStructureDisplayI sview = null;
237 sview = new AppJmol(pdbf, id, sq, alignPanel, usetoColourbyseq,
238 useinViewerSuperpos, viewerColouring, fileloc, rect, vid);
242 "Unsupported structure viewer type " + type.toString());
245 Cache.log.error("Unknown structure viewer type " + type.toString());