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 java.awt.Rectangle;
24 import java.util.ArrayList;
25 import java.util.List;
27 import jalview.api.structures.JalviewStructureDisplayI;
28 import jalview.bin.Cache;
29 import jalview.datamodel.PDBEntry;
30 import jalview.datamodel.SequenceI;
31 import jalview.datamodel.StructureViewerModel;
32 import jalview.structure.StructureSelectionManager;
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,
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],
128 seqs.toArray(new SequenceI[seqs.size()]), ap);
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 JalviewStructureDisplayI sview = null;
141 if (viewerType.equals(ViewerType.JMOL))
143 sview = new AppJmol(ap, pdbs, ap.av.collateForPDB(pdbs));
145 else if (viewerType.equals(ViewerType.CHIMERA))
147 sview = new ChimeraViewFrame(pdbs, ap.av.collateForPDB(pdbs), ap);
151 Cache.log.error("Unknown structure viewer type "
152 + getViewerType().toString());
157 protected JalviewStructureDisplayI viewStructures(ViewerType viewerType,
158 PDBEntry pdb, SequenceI[] seqsForPdb, AlignmentPanel ap)
160 JalviewStructureDisplayI sview = null;
161 if (viewerType.equals(ViewerType.JMOL))
163 sview = new AppJmol(pdb, seqsForPdb, null, ap);
165 else if (viewerType.equals(ViewerType.CHIMERA))
167 sview = new ChimeraViewFrame(pdb, seqsForPdb, null, ap);
171 Cache.log.error("Unknown structure viewer type "
172 + getViewerType().toString());
178 * Create a new panel controlling a structure viewer.
191 public JalviewStructureDisplayI createView(ViewerType type,
192 String[] pdbf, String[] id, SequenceI[][] sq,
193 AlignmentPanel alignPanel, StructureViewerModel viewerData, String fileloc,
194 Rectangle rect, String vid)
196 final boolean useinViewerSuperpos = viewerData.isAlignWithPanel();
197 final boolean usetoColourbyseq = viewerData.isColourWithAlignPanel();
198 final boolean viewerColouring = viewerData.isColourByViewer();
200 JalviewStructureDisplayI sview = null;
204 sview = new AppJmol(pdbf, id, sq, alignPanel, usetoColourbyseq,
205 useinViewerSuperpos, viewerColouring, fileloc, rect, vid);
208 Cache.log.error("Unsupported structure viewer type "
212 Cache.log.error("Unknown structure viewer type " + type.toString());